diff --git a/.changeset/poor-seahorses-matter.md b/.changeset/poor-seahorses-matter.md new file mode 100644 index 000000000..cfb7618b5 --- /dev/null +++ b/.changeset/poor-seahorses-matter.md @@ -0,0 +1,7 @@ +--- +'@siafoundation/renterd-js': minor +'@siafoundation/renterd-react': minor +'@siafoundation/renterd-types': minor +--- + +Add price pinning configuration API. diff --git a/libs/renterd-js/src/bus.ts b/libs/renterd-js/src/bus.ts index e6a9e96f0..56d4ee62c 100644 --- a/libs/renterd-js/src/bus.ts +++ b/libs/renterd-js/src/bus.ts @@ -145,6 +145,7 @@ import { ObjectsStatsParams, ObjectsStatsPayload, ObjectsStatsResponse, + PricePinSettings, RedundancySettings, S3AuthenticationSettings, SettingParams, @@ -658,6 +659,22 @@ export function Bus({ api, password }: { api: string; password?: string }) { config, }) }, + settingPricePinning: ({ config }: { config?: AxiosRequestConfig } = {}) => { + return buildRequestHandler< + SettingParams, + SettingPayload, + SettingResponse + >( + axios, + 'get', + busSettingKeyRoute + )({ + params: { + key: 'pricepinning', + }, + config, + }) + }, settingUpdate: buildRequestHandler< SettingUpdateParams, SettingUpdatePayload, diff --git a/libs/renterd-react/src/bus.ts b/libs/renterd-react/src/bus.ts index 9513113dc..32ba082aa 100644 --- a/libs/renterd-react/src/bus.ts +++ b/libs/renterd-react/src/bus.ts @@ -259,6 +259,7 @@ import { ContractSizeParams, ContractSizeResponse, busContractIdSize, + PricePinSettings, } from '@siafoundation/renterd-types' // state @@ -872,6 +873,15 @@ export function useSettingUploadPacking( }) } +export function useSettingPricePinning( + args?: HookArgsSwr +) { + return useSetting({ + ...args, + params: { key: 'pricepinning' }, + }) +} + export function useSettingUpdate( args?: HookArgsCallback< SettingUpdateParams, diff --git a/libs/renterd-types/package.json b/libs/renterd-types/package.json index fc6650bfe..b433fe495 100644 --- a/libs/renterd-types/package.json +++ b/libs/renterd-types/package.json @@ -4,7 +4,8 @@ "version": "0.3.0", "license": "MIT", "dependencies": { - "@siafoundation/types": "^0.4.0" + "@siafoundation/types": "^0.4.0", + "@siafoundation/react-core": "^1.2.1" }, "types": "./src/index.d.ts" } diff --git a/libs/renterd-types/src/types.ts b/libs/renterd-types/src/types.ts index e635cb7ee..f3cf781ed 100644 --- a/libs/renterd-types/src/types.ts +++ b/libs/renterd-types/src/types.ts @@ -1,3 +1,4 @@ +import { CurrencyId } from '@siafoundation/react-core' import { ChainIndex, FileContractRevision, @@ -156,6 +157,50 @@ export type S3AuthenticationSettings = { } } +export type Pin = { + pinned: boolean + value: number +} + +export type GougingSettingsPins = { + maxStorage: Pin + maxDownload: Pin + maxUpload: Pin + maxRPCPrice: Pin +} + +export type AutopilotPins = { + allowance: Pin +} + +// PricePinSettings holds the configuration for pinning certain settings to +// a specific currency (e.g., USD). It uses a Forex API to fetch the current +// exchange rate, allowing users to set prices in USD instead of SC. +export type PricePinSettings = { + // Enabled can be used to either enable or temporarily disable price + // pinning. If enabled, both the currency and the Forex endpoint URL + // must be valid. + enabled: boolean + + // Currency is the external three-letter currency code. + currency: CurrencyId | '' + + // ForexEndpointURL is the endpoint that returns the exchange rate for + // Siacoin against the underlying currency. + forexEndpointURL: string + + // Threshold is a percentage between 0 and 1 that determines when the + // pinned settings are updated based on the exchange rate at the time. + threshold: number + + // Autopilots contains the pinned settings for every autopilot. + autopilots?: AutopilotPins + + // GougingSettingsPins contains the pinned settings for the gouging + // settings. + gougingSettingsPins: GougingSettingsPins +} + export type ContractState = 'pending' | 'active' | 'complete' | 'failed' export type Contract = {