Skip to content

Commit

Permalink
fix: renterd pricepinning autopilot config structure
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Aug 16, 2024
1 parent f778164 commit 0987154
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 17 deletions.
7 changes: 7 additions & 0 deletions .changeset/hip-trees-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siafoundation/renterd-types': minor
'@siafoundation/renterd-js': minor
'@siafoundation/renterd-react': minor
---

Updated the pricepinning configuration structure to support multiple autopilots. Closes https://github.com/SiaFoundation/renterd/issues/1448
5 changes: 5 additions & 0 deletions .changeset/stupid-peaches-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

Fixed an issue where the pricepinning response was crashing the app. Closes https://github.com/SiaFoundation/renterd/issues/1448
17 changes: 11 additions & 6 deletions apps/renterd/contexts/config/transform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,11 @@ describe('tansforms', () => {
forexEndpointURL: '',
threshold: 0.01,
autopilots: {
allowance: {
pinned: true,
value: 1400,
autopilot: {
allowance: {
pinned: true,
value: 1400,
},
},
},
gougingSettingsPins: {
Expand Down Expand Up @@ -626,9 +628,12 @@ function buildAllResponses() {
},
},
autopilots: {
allowance: {
pinned: false,
value: 0,
// Update the default autopilot named 'autopilot'.
autopilot: {
allowance: {
pinned: false,
value: 0,
},
},
},
},
Expand Down
5 changes: 3 additions & 2 deletions apps/renterd/contexts/config/transformDown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,11 @@ export function transformDownPricePinning(
pinnedCurrency: p.currency,
forexEndpointURL: p.forexEndpointURL,
pinnedThreshold: new BigNumber(p.threshold).times(100),
shouldPinAllowance: p.autopilots?.allowance.pinned || false,
// Assume the default autopilot named 'autopilot'.
shouldPinAllowance: p.autopilots['autopilot']?.allowance.pinned || false,
allowanceMonthPinned: toFixedMaxBigNumber(
valuePerPeriodToPerMonth(
new BigNumber(p.autopilots?.allowance.value || 0),
new BigNumber(p.autopilots['autopilot']?.allowance.value || 0),
// If pinned allowance is non zero, the period value will be defined.
periodBlocks || weeksToBlocks(6)
),
Expand Down
19 changes: 11 additions & 8 deletions apps/renterd/contexts/config/transformUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,17 @@ export function transformUpPricePinning(
forexEndpointURL: values.forexEndpointURL,
threshold: values.pinnedThreshold.div(100).toNumber(),
autopilots: {
allowance: {
pinned: values.shouldPinAllowance,
value: valuePerMonthToPerPeriod(
values.allowanceMonthPinned,
// If autopilot is disabled the period value may be undefined,
// but in that case the pinned allowance is also unused.
values.periodWeeks || new BigNumber(6)
).toNumber(),
// Update the default autopilot named 'autopilot'.
autopilot: {
allowance: {
pinned: values.shouldPinAllowance,
value: valuePerMonthToPerPeriod(
values.allowanceMonthPinned,
// If autopilot is disabled the period value may be undefined,
// but in that case the pinned allowance is also unused.
values.periodWeeks || new BigNumber(6)
).toNumber(),
},
},
},
gougingSettingsPins: {
Expand Down
2 changes: 1 addition & 1 deletion libs/renterd-types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export type PricePinSettings = {
threshold: number

// Autopilots contains the pinned settings for every autopilot.
autopilots: AutopilotPins
autopilots: Record<string, AutopilotPins>

// GougingSettingsPins contains the pinned settings for the gouging
// settings.
Expand Down

0 comments on commit 0987154

Please sign in to comment.