Skip to content

Commit

Permalink
feat: renterd price pinning api
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Aug 2, 2024
1 parent f063efd commit 951a644
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .changeset/poor-seahorses-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siafoundation/renterd-js': minor
'@siafoundation/renterd-react': minor
'@siafoundation/renterd-types': minor
---

Add price pinning configuration API.
17 changes: 17 additions & 0 deletions libs/renterd-js/src/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ import {
ObjectsStatsParams,
ObjectsStatsPayload,
ObjectsStatsResponse,
PricePinSettings,
RedundancySettings,
S3AuthenticationSettings,
SettingParams,
Expand Down Expand Up @@ -658,6 +659,22 @@ export function Bus({ api, password }: { api: string; password?: string }) {
config,
})
},
settingPricePinning: ({ config }: { config?: AxiosRequestConfig } = {}) => {
return buildRequestHandler<
SettingParams,
SettingPayload,
SettingResponse<PricePinSettings>
>(
axios,
'get',
busSettingKeyRoute
)({
params: {
key: 'pricepinning',
},
config,
})
},
settingUpdate: buildRequestHandler<
SettingUpdateParams,
SettingUpdatePayload,
Expand Down
10 changes: 10 additions & 0 deletions libs/renterd-react/src/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ import {
ContractSizeParams,
ContractSizeResponse,
busContractIdSize,
PricePinSettings,
} from '@siafoundation/renterd-types'

// state
Expand Down Expand Up @@ -872,6 +873,15 @@ export function useSettingUploadPacking(
})
}

export function useSettingPricePinning(
args?: HookArgsSwr<void, PricePinSettings>
) {
return useSetting<PricePinSettings>({
...args,
params: { key: 'pricepinning' },
})
}

export function useSettingUpdate(
args?: HookArgsCallback<
SettingUpdateParams,
Expand Down
3 changes: 2 additions & 1 deletion libs/renterd-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
45 changes: 45 additions & 0 deletions libs/renterd-types/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CurrencyId } from '@siafoundation/react-core'
import {
ChainIndex,
FileContractRevision,
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit 951a644

Please sign in to comment.