Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve(ConfigStoreClient): Remove deprecated transferThreshold variable from config store #388

Merged
merged 6 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
34 changes: 0 additions & 34 deletions src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import { Contract, BigNumber, Event } from "ethers";
import winston from "winston";

import {
L1TokenTransferThreshold,
L1TokenTransferThresholdStringified,
TokenConfig,
GlobalConfigUpdate,
ParsedTokenConfig,
Expand Down Expand Up @@ -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<number[]>[] = [];
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -607,7 +585,6 @@ export class AcrossConfigStoreClient extends BaseAbstractClient {
hasLatestConfigStoreVersion = this.hasLatestConfigStoreVersion,
latestBlockNumber = this.latestBlockNumber,
ubaConfigUpdates,
cumulativeTokenTransferUpdates,
cumulativeSpokeTargetBalanceUpdates,
} = configStoreClientState;

Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>
)["uba"],
},
Expand Down
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/acrossConfigStore.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 17 additions & 6 deletions src/contracts/acrossConfigStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
});
});
});
1 change: 0 additions & 1 deletion src/contracts/acrossConfigStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const RateModelSs = object({
const L1TokenConfigSs = object({
rateModel: RateModelSs,
routeRateModel: optional(record(string(), RateModelSs)),
transferThreshold: string(),
});
export type RateModel = Infer<typeof RateModelSs>;
export type L1TokenConfig = Infer<typeof L1TokenConfigSs>;
Expand Down
10 changes: 0 additions & 10 deletions src/interfaces/ConfigStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { RateModelDictionary } from "../lpFeeCalculator/rateModel";
import { SortableEvent } from "./Common";

export interface ParsedTokenConfig {
transferThreshold: string;
rateModel: RateModelDictionary;
routeRateModel?: {
[path: string]: RateModelDictionary;
Expand All @@ -17,15 +16,6 @@ export interface ParsedTokenConfig {
};
}

export interface L1TokenTransferThreshold extends SortableEvent {
transferThreshold: BigNumber;
l1Token: string;
}

export type L1TokenTransferThresholdStringified = Omit<L1TokenTransferThreshold, "transferThreshold"> & {
transferThreshold: string;
};

export interface SpokePoolTargetBalance {
target: BigNumber;
threshold: BigNumber;
Expand Down