@across-protocol/sdk 3.3.19 → 3.3.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +11 -8
  2. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +87 -54
  3. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  4. package/dist/cjs/contracts/acrossConfigStore.d.ts +5 -5
  5. package/dist/cjs/interfaces/ConfigStore.d.ts +7 -30
  6. package/dist/cjs/lpFeeCalculator/rateModel.d.ts +1 -27
  7. package/dist/cjs/lpFeeCalculator/rateModel.js +1 -77
  8. package/dist/cjs/lpFeeCalculator/rateModel.js.map +1 -1
  9. package/dist/cjs/pool/poolClient.js.map +1 -1
  10. package/dist/cjs/utils/index.d.ts +1 -0
  11. package/dist/cjs/utils/index.js +1 -0
  12. package/dist/cjs/utils/index.js.map +1 -1
  13. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +11 -16
  14. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +103 -77
  15. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  16. package/dist/esm/contracts/acrossConfigStore.d.ts +5 -5
  17. package/dist/esm/interfaces/ConfigStore.d.ts +7 -106
  18. package/dist/esm/lpFeeCalculator/rateModel.d.ts +1 -39
  19. package/dist/esm/lpFeeCalculator/rateModel.js +0 -109
  20. package/dist/esm/lpFeeCalculator/rateModel.js.map +1 -1
  21. package/dist/esm/pool/poolClient.js.map +1 -1
  22. package/dist/esm/utils/index.d.ts +1 -0
  23. package/dist/esm/utils/index.js +1 -0
  24. package/dist/esm/utils/index.js.map +1 -1
  25. package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +11 -16
  26. package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts.map +1 -1
  27. package/dist/types/contracts/acrossConfigStore.d.ts +5 -5
  28. package/dist/types/contracts/acrossConfigStore.d.ts.map +1 -1
  29. package/dist/types/interfaces/ConfigStore.d.ts +7 -106
  30. package/dist/types/interfaces/ConfigStore.d.ts.map +1 -1
  31. package/dist/types/lpFeeCalculator/rateModel.d.ts +1 -39
  32. package/dist/types/lpFeeCalculator/rateModel.d.ts.map +1 -1
  33. package/dist/types/utils/index.d.ts +1 -0
  34. package/dist/types/utils/index.d.ts.map +1 -1
  35. package/package.json +1 -1
  36. package/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts +126 -96
  37. package/src/contracts/acrossConfigStore.ts +5 -5
  38. package/src/interfaces/ConfigStore.ts +8 -112
  39. package/src/lpFeeCalculator/rateModel.ts +1 -144
  40. package/src/pool/poolClient.ts +3 -3
  41. package/src/utils/index.ts +1 -0
@@ -1,13 +1,12 @@
1
- import { RateModelDictionary } from "../lpFeeCalculator/rateModel";
1
+ import { RateModel } from "../lpFeeCalculator";
2
2
  import { BigNumber } from "../utils";
3
3
  import { SortableEvent } from "./Common";
4
4
 
5
5
  export interface ParsedTokenConfig {
6
- rateModel: RateModelDictionary;
6
+ rateModel: RateModel;
7
7
  routeRateModel?: {
8
- [path: string]: RateModelDictionary;
8
+ [path: string]: RateModel;
9
9
  };
10
- uba?: UBAOnChainConfigType;
11
10
  spokeTargetBalances?: {
12
11
  [chainId: number]: {
13
12
  target: string;
@@ -47,6 +46,11 @@ export interface RouteRateModelUpdate extends SortableEvent {
47
46
  l1Token: string;
48
47
  }
49
48
 
49
+ export interface RateModelUpdate extends SortableEvent {
50
+ rateModel: string;
51
+ l1Token: string;
52
+ }
53
+
50
54
  export interface TokenConfig extends SortableEvent {
51
55
  key: string;
52
56
  value: string;
@@ -67,111 +71,3 @@ export interface DisabledChainsUpdate extends SortableEvent {
67
71
  export interface LiteChainsIdListUpdate<ValueStore = number[]> extends GlobalConfigUpdate<ValueStore> {
68
72
  timestamp: number;
69
73
  }
70
-
71
- /**
72
- * A generic type of a dictionary that has string keys and values of type T. This
73
- * record is enforced to have a default entry within the "default" key.
74
- * @type Value The type of the values in the dictionary.
75
- */
76
- type RecordWithDefaultEntry<Value> = Record<string, Value>;
77
-
78
- /**
79
- * A generic type for an array of tuples.
80
- * @type Value The type of the values in the array.
81
- */
82
- type ArrayOfTuples<Value> = [Value, Value][];
83
-
84
- /**
85
- * A type for the UBA config object stored both on and off chain.
86
- * @type T The type of the values in the config.
87
- * @note This is a dictionary of parameters that defines a fee curve for the token.
88
- * These parameters can be further subindexed by a route (e.g. using the key "1-10" or "42161-1")
89
- * to create a specific fee curve for a token per route. The subkeys are as followed:
90
- * - alpha: The alpha parameter of the fee curve.
91
- * - gamma: The gamma parameter of the fee curve.
92
- * - omega: The omega parameter of the fee curve.
93
- * - rebalance: The rebalance parameters of the fee curve.
94
- */
95
- type UBAAgnosticConfigType<T> = {
96
- /**
97
- * A DAO controlled variable to track any donations made to the incentivePool liquidity
98
- */
99
- incentivePoolAdjustment?: Record<string, T>;
100
- /**
101
- * Used to scale rewards when a fee is larger than the incentive balance
102
- */
103
- ubaRewardMultiplier?: Record<string, T>;
104
- /**
105
- * This is a scalar value that is a constant percentage of each transfer that is allocated for LPs.
106
- * This value can be determined by token and route-by-route.
107
- */
108
- alpha: RecordWithDefaultEntry<T>;
109
- /**
110
- * This is a piecewise linear function (defined by a vector of cut-off points and the values at
111
- * those points) that determine additional LP fees as a function of utilization. This piecewise
112
- * linear function can be determined by token and chain-by-chain.
113
- */
114
- gamma: RecordWithDefaultEntry<ArrayOfTuples<T>>;
115
- /**
116
- * This is a piecewise linear function (defined by a vector of cut-off points and the values at
117
- * those points) that determine the balancing fees (rewards) that are imposed on (paid to) a user
118
- * who makes a transfer involving a particular chain. There is a single piecewise linear function for
119
- * each token/chain combination. A transfer will incur a balancing fee on both the origin and destination
120
- * chains.
121
- */
122
- omega: RecordWithDefaultEntry<ArrayOfTuples<T>>;
123
- /**
124
- * This is a set of parameters that determine when a rebalance is triggered. A rebalance is triggered
125
- * when the utilization of a pool is outside of the range defined by the lower and upper thresholds.
126
- */
127
- rebalance: RecordWithDefaultEntry<{
128
- /**
129
- * For tokens/chains that have a supported bridge, these are the lower and upper threshold that trigger
130
- * the reallocation of funds. i.e. If the running balance on a chain moves below (above) threshold_lower
131
- * (threshold_upper) then the bridge moves funds from Ethereum to the chain (from the chain to Ethereum).
132
- */
133
- threshold_lower?: T;
134
- /**
135
- * For tokens/chains that have a supported bridge, these are the lower and upper threshold that trigger
136
- * the reallocation of funds. i.e. If the running balance on a chain moves below (above) threshold_lower
137
- * (threshold_upper) then the bridge moves funds from Ethereum to the chain (from the chain to Ethereum).
138
- */
139
- threshold_upper?: T;
140
- /**
141
- * For tokens/chains that have a supported bridge, these are the values that are targeted whenever funds
142
- * are reallocated.
143
- */
144
- target_lower?: T;
145
- /**
146
- * For tokens/chains that have a supported bridge, these are the values that are targeted whenever funds
147
- * are reallocated.
148
- */
149
- target_upper?: T;
150
- }>;
151
- };
152
-
153
- /**
154
- * A type for the UBA config object stored on chain.
155
- */
156
- export type UBAOnChainConfigType = UBAAgnosticConfigType<string>;
157
-
158
- /**
159
- * A type for the UBA config object after it has been parsed.
160
- */
161
- export type UBAParsedConfigType = UBAAgnosticConfigType<BigNumber>;
162
-
163
- /**
164
- * A type for UBAConfig Update events.
165
- */
166
- export type UBAConfigUpdates = SortableEvent & {
167
- config: UBAParsedConfigType;
168
- l1Token: string;
169
- };
170
-
171
- /**
172
- * A type for stringified UBAConfig Update events.
173
- */
174
- export type UBASerializedConfigUpdates = SortableEvent & {
175
- config: UBAOnChainConfigType;
176
- l1Token: string;
177
- };
@@ -1,109 +1,7 @@
1
- import { ethers } from "ethers";
2
- import { isDefined } from "../utils";
3
-
4
- // Each L1 token is mapped to an array of stringified rate models, ordered by the block height at which they were
5
- // published on-chain. This dictionary is used internally to fetch a rate model for a block height.
6
- type RateModelEventsDictionary = {
7
- [l1TokenAddress: string]: { blockNumber: number; rateModel: string }[];
8
- };
9
-
10
- // Events should be reformatted into this shape to be used as input into methods in this file.
11
- export type RateModelEvent = {
12
- blockNumber: number;
13
- transactionIndex: number;
14
- logIndex: number;
15
- rateModel: string;
16
- l1Token: string;
17
- };
18
-
19
- interface RateModel {
20
- UBar: string; // denote the utilization kink along the rate model where the slope of the interest rate model changes.
21
- R0: string; // is the interest rate charged at 0 utilization
22
- R1: string; // R_0+R_1 is the interest rate charged at UBar
23
- R2: string; // R_0+R_1+R_2 is the interest rate charged at 100% utilization
24
- }
1
+ import { RateModel } from "../lpFeeCalculator";
25
2
 
26
3
  const expectedRateModelKeys = ["UBar", "R0", "R1", "R2"];
27
4
 
28
- export class RateModelDictionary {
29
- public rateModelDictionary: RateModelEventsDictionary = {};
30
-
31
- private _throwIfNotInitialized() {
32
- if (Object.keys(this.rateModelDictionary).length == 0)
33
- throw new Error("RateModelUtility method called before updating rate model dictionary!");
34
- }
35
-
36
- updateWithEvents(rateModelEvents: RateModelEvent[]): void {
37
- this.rateModelDictionary = createRateModelEventDictionary(rateModelEvents);
38
- }
39
-
40
- /**
41
- * Return the rate model for L1 token set at the block height.
42
- * @param l1Token L1 token address to get rate model for.
43
- * @param blockNumber Block height to get rate model for.
44
- * @returns Rate model object.
45
- */
46
- getRateModelForBlockNumber(l1Token: string, blockNumber?: number): RateModel {
47
- this._throwIfNotInitialized();
48
-
49
- const l1TokenNormalized = ethers.utils.getAddress(l1Token);
50
-
51
- if (!this.rateModelDictionary[l1TokenNormalized] || this.rateModelDictionary[l1TokenNormalized].length === 0)
52
- throw new Error(`No updated rate model events for L1 token: ${l1TokenNormalized}`);
53
-
54
- if (!blockNumber) {
55
- // If block number is undefined, use latest updated rate model.
56
- return parseAndReturnRateModelFromString(this.rateModelDictionary[l1TokenNormalized].slice(-1)[0].rateModel);
57
- } else {
58
- const firstEventBlockNumber = this.rateModelDictionary[l1TokenNormalized][0].blockNumber;
59
- if (blockNumber < firstEventBlockNumber) {
60
- throw new Error(
61
- `Block number #${blockNumber} is before first UpdatedRateModel event block ${firstEventBlockNumber}`
62
- );
63
- }
64
-
65
- // We're looking for the latest rate model update that occurred at or before the block number.
66
- // Rate model events are inserted into the array from oldest at index 0 to newest at index length-1, so we'll
67
- // reverse the array so it goes from newest at index 0 to oldest at index length-1, and then find the first event
68
- // who's block number is less than or equal to the target block number.
69
- const rateModel = this.rateModelDictionary[l1TokenNormalized]
70
- .slice()
71
- .reverse() // reverse() modifies memory in place so create a copy first.
72
- .find((event) => event.blockNumber <= blockNumber);
73
-
74
- if (!rateModel)
75
- throw new Error(`No updated rate model events before block #${blockNumber} for L1 token: ${l1TokenNormalized}`);
76
- return parseAndReturnRateModelFromString(rateModel?.rateModel);
77
- }
78
- }
79
-
80
- /**
81
- * @notice Return all L1 tokens that had a rate model associated with it at the block number.
82
- * @param blockNumber Returns l1 tokens that were mapped to a rate model at this block height. If undefined,
83
- * this function will return all L1 tokens that have a block number as of the latest block height.
84
- * @returns array of L1 token addresses.
85
- */
86
- getL1TokensFromRateModel(blockNumber: number | undefined = undefined): string[] {
87
- this._throwIfNotInitialized();
88
-
89
- return Object.keys(this.rateModelDictionary)
90
- .map((l1Token) => {
91
- const l1TokenNormalized = ethers.utils.getAddress(l1Token);
92
-
93
- // Check that there is at least one UpdatedRateModel event before the provided block number, otherwise
94
- // this L1 token didn't exist in the RateModel at the block height and we shouldn't include it in the returned
95
- // array.
96
- if (
97
- !blockNumber ||
98
- this.rateModelDictionary[l1TokenNormalized].find((event) => event.blockNumber <= blockNumber)
99
- )
100
- return ethers.utils.getAddress(l1Token);
101
- else return null;
102
- })
103
- .filter(isDefined);
104
- }
105
- }
106
-
107
5
  /**
108
6
  * Helper method that returns parsed rate model from string, or throws.
109
7
  * @param rateModelString Stringified rate model to parse.
@@ -140,44 +38,3 @@ export const parseAndReturnRateModelFromString = (rateModelString: string): Rate
140
38
  R2: rateModelFromEvent.R2,
141
39
  };
142
40
  };
143
-
144
- /**
145
- * Given an unsorted array of updated rate model events, return a dictionary mapping token addresses to sorted
146
- * rate model events. This method is used internally to enforce chronological sorting of events and mapping rate models
147
- * to token addresses.
148
- * @param rateModelEvents Unsorted updated rate model events, each of which contains a token address, the stringified
149
- * rate model for that token, and the block height of the update.
150
- * @returns Dictionary mapping token addresses to chronologically sorted rate model updates.
151
- */
152
- const createRateModelEventDictionary = (rateModelEvents: RateModelEvent[]): RateModelEventsDictionary => {
153
- const updatedRateModelEventsForToken: RateModelEventsDictionary = {};
154
-
155
- // Sort events in-place from oldest to newest:
156
- rateModelEvents.sort((a, b) => {
157
- if (a.blockNumber !== b.blockNumber) {
158
- return a.blockNumber - b.blockNumber;
159
- }
160
-
161
- if (a.transactionIndex !== b.transactionIndex) {
162
- return a.transactionIndex - b.transactionIndex;
163
- }
164
-
165
- return a.logIndex - b.logIndex;
166
- });
167
-
168
- for (const updatedRateModelEvent of rateModelEvents) {
169
- // The contract enforces that all rate models are mapped to addresses, therefore we do not need to check that
170
- // `l1Token` is a valid address.
171
- const l1TokenNormalized = ethers.utils.getAddress(updatedRateModelEvent.l1Token);
172
- if (!updatedRateModelEventsForToken[l1TokenNormalized]) updatedRateModelEventsForToken[l1TokenNormalized] = [];
173
-
174
- // We assume that events are returned from oldest to newest, so we can simply push events into the array and
175
- // and maintain their time order.
176
- updatedRateModelEventsForToken[l1TokenNormalized].push({
177
- blockNumber: updatedRateModelEvent.blockNumber,
178
- rateModel: updatedRateModelEvent.rateModel,
179
- });
180
- }
181
-
182
- return updatedRateModelEventsForToken;
183
- };
@@ -17,7 +17,7 @@ import { Provider, Block } from "@ethersproject/providers";
17
17
  import set from "lodash/set";
18
18
  import get from "lodash/get";
19
19
  import has from "lodash/has";
20
- import { calculateInstantaneousRate } from "../lpFeeCalculator";
20
+ import { calculateInstantaneousRate, RateModel } from "../lpFeeCalculator";
21
21
  import { hubPool, acrossConfigStore } from "../contracts";
22
22
  import {
23
23
  AcceleratingDistributor,
@@ -385,7 +385,7 @@ function joinPoolState(
385
385
  poolState: Awaited<ReturnType<PoolState["read"]>>,
386
386
  latestBlock: Block,
387
387
  previousBlock: Block,
388
- rateModel?: acrossConfigStore.RateModel
388
+ rateModel?: RateModel
389
389
  ): Pool {
390
390
  const totalPoolSize = poolState.liquidReserves.add(poolState.utilizedReserves);
391
391
  const secondsElapsed = latestBlock.timestamp - previousBlock.timestamp;
@@ -807,7 +807,7 @@ export class Client {
807
807
  const previousBlock = await this.deps.provider.getBlock(latestBlock.number - blockDelta);
808
808
  const state = await pool.read(l1TokenAddress, latestBlock.number, previousBlock.number);
809
809
 
810
- let rateModel: acrossConfigStore.RateModel | undefined = undefined;
810
+ let rateModel: RateModel | undefined = undefined;
811
811
  try {
812
812
  // Use the default rate model (i.e. not any of the routeRateModels to project the Pool's APR). This assumes
813
813
  // that the default rate model is the most often used, but this may change in future if many different
@@ -20,6 +20,7 @@ export * from "./BlockExplorerUtils";
20
20
  export * from "./BigNumberUtils";
21
21
  export * from "./CachingUtils";
22
22
  export * from "./NetworkUtils";
23
+ export * from "./Profiler";
23
24
  export * from "./Multicall";
24
25
  export * from "./ReviverUtils";
25
26
  export * from "./DepositUtils";