From 2e13de18a7264bbe860455abeaa5c7af67458ffc Mon Sep 17 00:00:00 2001 From: Jackson Jessup Date: Wed, 4 Jan 2023 14:09:03 -0500 Subject: [PATCH] Fix variance threshold in Aggregator.setConfig --- javascript/solana.js/src/accounts/aggregatorAccount.ts | 8 ++++---- javascript/solana.js/test/aggregator.spec.ts | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/javascript/solana.js/src/accounts/aggregatorAccount.ts b/javascript/solana.js/src/accounts/aggregatorAccount.ts index 9585c62..ad5069a 100644 --- a/javascript/solana.js/src/accounts/aggregatorAccount.ts +++ b/javascript/solana.js/src/accounts/aggregatorAccount.ts @@ -32,6 +32,7 @@ import { AggregatorHistoryBuffer } from './aggregatorHistoryBuffer'; import { CrankAccount } from './crankAccount'; import assert from 'assert'; import { BN } from 'bn.js'; +import _ from 'lodash'; /** * Account type holding a data feed's update configuration, job accounts, and its current result. @@ -954,6 +955,7 @@ export class AggregatorAccount extends Account { }); } + const varianceThreshold = params.varianceThreshold ?? 0; const setConfigIxn = types.aggregatorSetConfig( this.program, { @@ -974,11 +976,9 @@ export class AggregatorAccount extends Account { minJobResults: params.minJobResults ?? null, forceReportPeriod: params.forceReportPeriod ?? null, varianceThreshold: - params.varianceThreshold && params.varianceThreshold >= 0 + varianceThreshold >= 0 ? new types.BorshDecimal( - types.SwitchboardDecimal.fromBig( - new Big(params.varianceThreshold) - ) + types.SwitchboardDecimal.fromBig(new Big(varianceThreshold)) ) : null, basePriorityFee: params.basePriorityFee ?? null, diff --git a/javascript/solana.js/test/aggregator.spec.ts b/javascript/solana.js/test/aggregator.spec.ts index 148f319..c16a17e 100644 --- a/javascript/solana.js/test/aggregator.spec.ts +++ b/javascript/solana.js/test/aggregator.spec.ts @@ -333,6 +333,7 @@ describe('Aggregator Tests', () => { minRequiredJobResults: 1, minUpdateDelaySeconds: 60, keypair: aggregatorKeypair, + varianceThreshold: 1, }); await aggregatorAccount.loadData(); @@ -372,11 +373,16 @@ describe('Aggregator Tests', () => { authority: aggregatorAuthority, minUpdateDelaySeconds: 300, force: true, // Bypass validation rules. + varianceThreshold: 0, }); const postUpdateAggregatorState = await aggregatorAccount.loadData(); assert( postUpdateAggregatorState.minUpdateDelaySeconds === 300, - `Failed to setConfig on aggregator` + `Failed to setConfig on aggregator (minUpdateDelaySeconds)` + ); + assert( + postUpdateAggregatorState.varianceThreshold.toBig().toNumber() === 0, + `Failed to setConfig on aggregator (varianceThreshold)` ); });