diff --git a/package.json b/package.json index 6a207287..c055402f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@across-protocol/sdk-v2", "author": "UMA Team", - "version": "0.15.24", + "version": "0.16.0", "license": "AGPL-3.0", "main": "dist/index.js", "typings": "dist/index.d.ts", diff --git a/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts b/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts index 33fe69ab..acf859ab 100644 --- a/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts +++ b/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts @@ -22,8 +22,6 @@ import { Contract, BigNumber, Event } from "ethers"; import winston from "winston"; import { - L1TokenTransferThreshold, - L1TokenTransferThresholdStringified, TokenConfig, GlobalConfigUpdate, ParsedTokenConfig, @@ -72,7 +70,6 @@ export class AcrossConfigStoreClient extends BaseAbstractClient { public cumulativeRateModelUpdates: across.rateModel.RateModelEvent[] = []; public ubaConfigUpdates: UBAConfigUpdates[] = []; public cumulativeRouteRateModelUpdates: RouteRateModelUpdate[] = []; - public cumulativeTokenTransferUpdates: L1TokenTransferThreshold[] = []; public cumulativeMaxRefundCountUpdates: GlobalConfigUpdate[] = []; public cumulativeMaxL1TokenCountUpdates: GlobalConfigUpdate[] = []; public chainIdIndicesUpdates: GlobalConfigUpdate[] = []; @@ -163,16 +160,6 @@ export class AcrossConfigStoreClient extends BaseAbstractClient { return chainIdIndices ?? this.implicitChainIdIndices(this.chainId); } - getTokenTransferThresholdForBlock(l1Token: string, blockNumber: number = Number.MAX_SAFE_INTEGER): BigNumber { - const config = (sortEventsDescending(this.cumulativeTokenTransferUpdates) as L1TokenTransferThreshold[]).find( - (config) => config.blockNumber <= blockNumber && config.l1Token === l1Token - ); - if (!config) { - throw new Error(`Could not find TransferThreshold for L1 token ${l1Token} before block ${blockNumber}`); - } - return config.transferThreshold; - } - getSpokeTargetBalancesForBlock( l1Token: string, chainId: number, @@ -391,15 +378,6 @@ export class AcrossConfigStoreClient extends BaseAbstractClient { const rateModelForToken = JSON.stringify(parsedValue.rateModel); this.cumulativeRateModelUpdates.push({ ...passedArgs, rateModel: rateModelForToken, l1Token }); - if (parsedValue?.transferThreshold !== undefined) { - const transferThresholdForToken = parsedValue.transferThreshold; - this.cumulativeTokenTransferUpdates.push({ - ...passedArgs, - transferThreshold: toBN(transferThresholdForToken), - l1Token, - }); - } - // Store spokeTargetBalances if (parsedValue?.spokeTargetBalances) { // Note: cast is required because fromEntries always produces string keys, despite the function returning a @@ -607,7 +585,6 @@ export class AcrossConfigStoreClient extends BaseAbstractClient { hasLatestConfigStoreVersion = this.hasLatestConfigStoreVersion, latestBlockNumber = this.latestBlockNumber, ubaConfigUpdates, - cumulativeTokenTransferUpdates, cumulativeSpokeTargetBalanceUpdates, } = configStoreClientState; @@ -621,14 +598,6 @@ export class AcrossConfigStoreClient extends BaseAbstractClient { }) : this.ubaConfigUpdates; this.cumulativeRouteRateModelUpdates = cumulativeRouteRateModelUpdates; - this.cumulativeTokenTransferUpdates = cumulativeTokenTransferUpdates - ? cumulativeTokenTransferUpdates.map((update) => { - return { - ...update, - transferThreshold: BigNumber.from(update.transferThreshold), - }; - }) - : this.cumulativeTokenTransferUpdates; this.cumulativeMaxRefundCountUpdates = cumulativeMaxRefundCountUpdates; this.cumulativeMaxL1TokenCountUpdates = cumulativeMaxL1TokenCountUpdates; this.cumulativeSpokeTargetBalanceUpdates = cumulativeSpokeTargetBalanceUpdates @@ -664,9 +633,6 @@ export class AcrossConfigStoreClient extends BaseAbstractClient { stringifyJSONWithNumericString(this.ubaConfigUpdates) ) as UBASerializedConfigUpdates[], cumulativeRouteRateModelUpdates: this.cumulativeRouteRateModelUpdates, - cumulativeTokenTransferUpdates: JSON.parse( - stringifyJSONWithNumericString(this.cumulativeTokenTransferUpdates) - ) as L1TokenTransferThresholdStringified[], cumulativeMaxRefundCountUpdates: this.cumulativeMaxRefundCountUpdates, cumulativeMaxL1TokenCountUpdates: this.cumulativeMaxL1TokenCountUpdates, cumulativeSpokeTargetBalanceUpdates: JSON.parse( diff --git a/src/clients/AcrossConfigStoreClient/ConfigStoreParsingUtilities/ConfigStoreParsingUtilities.test.ts b/src/clients/AcrossConfigStoreClient/ConfigStoreParsingUtilities/ConfigStoreParsingUtilities.test.ts index 4920ba5f..abd6be97 100644 --- a/src/clients/AcrossConfigStoreClient/ConfigStoreParsingUtilities/ConfigStoreParsingUtilities.test.ts +++ b/src/clients/AcrossConfigStoreClient/ConfigStoreParsingUtilities/ConfigStoreParsingUtilities.test.ts @@ -6,7 +6,7 @@ const validConfigStore: { reason: string; value: unknown }[] = [ reason: "realistic config", value: ( parseJSONWithNumericString( - '{"rateModel":{"UBar":"750000000000000000","R0":"21000000000000000","R1":"0","R2":"600000000000000000"},"routeRateModel":{"1-10":{"UBar":"0","R0":"0","R1":"0","R2":"0"},"1-137":{"UBar":"0","R0":"0","R1":"0","R2":"0"},"1-288":{"UBar":"0","R0":"0","R1":"0","R2":"0"},"1-42161":{"UBar":"0","R0":"0","R1":"0","R2":"0"}},"transferThreshold":"0","spokeTargetBalances":{"10":{"threshold":"500000000000000000000","target":"350000000000000000000"},"137":{"target":"0","threshold":"10000000000000000000"},"42161":{"threshold":"600000000000000000000","target":"400000000000000000000"}},"uba":{"incentivePoolAdjustment": {}, "ubaRewardMultiplier": {}, "alpha":{"default":200000000000000,"1-10":0,"1-137":0,"1-42161":0},"gamma":{"default":[[500000000000000000,0],[650000000000000000,500000000000000],[750000000000000000,1000000000000000],[850000000000000000,2500000000000000],[900000000000000000,5000000000000000],[950000000000000000,50000000000000000]]},"omega":{"10":[[0,0]],"137":[[0,0]],"42161":[[0,0]],"default":[[0,0]]},"rebalance":{"10":{"threshold_lower":0,"target_lower":0,"threshold_upper":500000000000000000000,"target_upper":350000000000000000000},"137":{"threshold_lower":0,"target_lower":0,"threshold_upper":25000000000000000000,"target_upper":15000000000000000000},"42161":{"threshold_lower":0,"target_lower":0,"threshold_upper":600000000000000000000,"target_upper":400000000000000000000},"default":{"threshold_lower":0,"target_lower":0,"threshold_upper":0,"target_upper":0}}}}' + '{"rateModel":{"UBar":"750000000000000000","R0":"21000000000000000","R1":"0","R2":"600000000000000000"},"routeRateModel":{"1-10":{"UBar":"0","R0":"0","R1":"0","R2":"0"},"1-137":{"UBar":"0","R0":"0","R1":"0","R2":"0"},"1-288":{"UBar":"0","R0":"0","R1":"0","R2":"0"},"1-42161":{"UBar":"0","R0":"0","R1":"0","R2":"0"}},"spokeTargetBalances":{"10":{"threshold":"500000000000000000000","target":"350000000000000000000"},"137":{"target":"0","threshold":"10000000000000000000"},"42161":{"threshold":"600000000000000000000","target":"400000000000000000000"}},"uba":{"incentivePoolAdjustment": {}, "ubaRewardMultiplier": {}, "alpha":{"default":200000000000000,"1-10":0,"1-137":0,"1-42161":0},"gamma":{"default":[[500000000000000000,0],[650000000000000000,500000000000000],[750000000000000000,1000000000000000],[850000000000000000,2500000000000000],[900000000000000000,5000000000000000],[950000000000000000,50000000000000000]]},"omega":{"10":[[0,0]],"137":[[0,0]],"42161":[[0,0]],"default":[[0,0]]},"rebalance":{"10":{"threshold_lower":0,"target_lower":0,"threshold_upper":500000000000000000000,"target_upper":350000000000000000000},"137":{"threshold_lower":0,"target_lower":0,"threshold_upper":25000000000000000000,"target_upper":15000000000000000000},"42161":{"threshold_lower":0,"target_lower":0,"threshold_upper":600000000000000000000,"target_upper":400000000000000000000},"default":{"threshold_lower":0,"target_lower":0,"threshold_upper":0,"target_upper":0}}}}' ) as Record )["uba"], }, diff --git a/src/constants.ts b/src/constants.ts index 78aa0ba2..7fc2408c 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -13,6 +13,9 @@ export const SECONDS_PER_YEAR = 31557600; // 365.25 days per year. */ export const HUBPOOL_CHAIN_ID = 1; +// List of versions where certain UMIP features were deprecated +export const TRANSFER_THRESHOLD_MAX_CONFIG_STORE_VERSION = 2; + /** * A default list of chain Ids that the protocol supports. This is outlined * in the UMIP (https://github.com/UMAprotocol/UMIPs/pull/590) and is used diff --git a/src/contracts/acrossConfigStore.e2e.ts b/src/contracts/acrossConfigStore.e2e.ts index 4f084184..a1502bc0 100644 --- a/src/contracts/acrossConfigStore.e2e.ts +++ b/src/contracts/acrossConfigStore.e2e.ts @@ -17,7 +17,7 @@ describe("AcrossConfigStore", function () { }); test("getL1TokenConfig", async function () { const result = await client.getL1TokenConfig(wethAddress); - assert.ok(result.transferThreshold); + assert.ok(result.rateModel); }); test("getRateModel", async function () { // This test works because we know the L1-->L2 route for WETH has a rate model with all properties set to 0 and diff --git a/src/contracts/acrossConfigStore.test.ts b/src/contracts/acrossConfigStore.test.ts index 644d1dc6..cf2c37dc 100644 --- a/src/contracts/acrossConfigStore.test.ts +++ b/src/contracts/acrossConfigStore.test.ts @@ -4,7 +4,6 @@ jest.useFakeTimers(); describe("Contracts Config Store", () => { const BASE_TRUTH = { rateModel: { UBar: "750000000000000000", R0: "21000000000000000", R1: "0", R2: "600000000000000000" }, - transferThreshold: "0", }; it("should parse parseL1TokenConfig correctly with exactly the right data", () => { const structure = BASE_TRUTH; @@ -13,18 +12,30 @@ describe("Contracts Config Store", () => { it("should parse parseL1TokenConfig correctly with additional unneeded params", () => { const structure = { rateModel: { UBar: "750000000000000000", R0: "21000000000000000", R1: "0", R2: "600000000000000000" }, - transferThreshold: "0", spokeTargetBalances: { "10": { threshold: "50000000000000000000", target: "20000000000000000000" }, "42161": { threshold: "100000000000000000000", target: "20000000000000000000" }, }, + extraKey: "x", }; expect(Client.parseL1TokenConfig(JSON.stringify(structure))).toEqual(BASE_TRUTH); }); it("should fail to parse the data to parseL1TokenConfig with malformed input", () => { - const structure = { - rateModel: { UBar: "750000000000000000", R0: "21000000000000000", R1: "0", R2: "600000000000000000" }, - }; - expect(() => Client.parseL1TokenConfig(JSON.stringify(structure))).toThrow(); + const invalidStructures = [ + { + rateModel: "x", + }, + { + // Invalid rate model keys + rateModel: { ubar: "123" }, + }, + { + // Invalid rate model values + rateModel: { UBar: "x" }, + }, + ]; + invalidStructures.forEach((structure) => { + expect(() => Client.parseL1TokenConfig(JSON.stringify(structure))).toThrow(); + }); }); }); diff --git a/src/contracts/acrossConfigStore.ts b/src/contracts/acrossConfigStore.ts index 1435954e..edee3ebb 100644 --- a/src/contracts/acrossConfigStore.ts +++ b/src/contracts/acrossConfigStore.ts @@ -12,7 +12,6 @@ const RateModelSs = object({ const L1TokenConfigSs = object({ rateModel: RateModelSs, routeRateModel: optional(record(string(), RateModelSs)), - transferThreshold: string(), }); export type RateModel = Infer; export type L1TokenConfig = Infer; diff --git a/src/interfaces/ConfigStore.ts b/src/interfaces/ConfigStore.ts index 43ceefd0..6b680f09 100644 --- a/src/interfaces/ConfigStore.ts +++ b/src/interfaces/ConfigStore.ts @@ -3,7 +3,6 @@ import { RateModelDictionary } from "../lpFeeCalculator/rateModel"; import { SortableEvent } from "./Common"; export interface ParsedTokenConfig { - transferThreshold: string; rateModel: RateModelDictionary; routeRateModel?: { [path: string]: RateModelDictionary; @@ -17,15 +16,6 @@ export interface ParsedTokenConfig { }; } -export interface L1TokenTransferThreshold extends SortableEvent { - transferThreshold: BigNumber; - l1Token: string; -} - -export type L1TokenTransferThresholdStringified = Omit & { - transferThreshold: string; -}; - export interface SpokePoolTargetBalance { target: BigNumber; threshold: BigNumber;