@across-protocol/sdk 4.2.0 → 4.2.2-alpha.0
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.
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js +1 -1
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.d.ts +3 -1
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +5 -13
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSpokePoolClient.d.ts +5 -11
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js +18 -35
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/cjs/coingecko/Coingecko.d.ts +3 -2
- package/dist/cjs/coingecko/Coingecko.js +11 -3
- package/dist/cjs/coingecko/Coingecko.js.map +1 -1
- package/dist/cjs/gasPriceOracle/adapters/solana.js +1 -1
- package/dist/cjs/gasPriceOracle/adapters/solana.js.map +1 -1
- package/dist/cjs/interfaces/SpokePool.d.ts +1 -3
- package/dist/cjs/interfaces/SpokePool.js.map +1 -1
- package/dist/cjs/utils/TokenUtils.js +4 -1
- package/dist/cjs/utils/TokenUtils.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +1 -1
- package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.d.ts +3 -1
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +5 -13
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSpokePoolClient.d.ts +5 -11
- package/dist/esm/clients/mocks/MockSpokePoolClient.js +21 -38
- package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/esm/coingecko/Coingecko.d.ts +3 -2
- package/dist/esm/coingecko/Coingecko.js +12 -3
- package/dist/esm/coingecko/Coingecko.js.map +1 -1
- package/dist/esm/gasPriceOracle/adapters/solana.js +1 -1
- package/dist/esm/gasPriceOracle/adapters/solana.js.map +1 -1
- package/dist/esm/interfaces/SpokePool.d.ts +1 -3
- package/dist/esm/interfaces/SpokePool.js.map +1 -1
- package/dist/esm/utils/TokenUtils.d.ts +12 -0
- package/dist/esm/utils/TokenUtils.js +6 -3
- package/dist/esm/utils/TokenUtils.js.map +1 -1
- package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts +3 -1
- package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockSpokePoolClient.d.ts +5 -11
- package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
- package/dist/types/coingecko/Coingecko.d.ts +3 -2
- package/dist/types/coingecko/Coingecko.d.ts.map +1 -1
- package/dist/types/gasPriceOracle/adapters/solana.d.ts.map +1 -1
- package/dist/types/interfaces/SpokePool.d.ts +1 -3
- package/dist/types/interfaces/SpokePool.d.ts.map +1 -1
- package/dist/types/utils/TokenUtils.d.ts +12 -0
- package/dist/types/utils/TokenUtils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +1 -1
- package/src/clients/SpokePoolClient/SpokePoolClient.ts +8 -16
- package/src/clients/mocks/MockSpokePoolClient.ts +36 -66
- package/src/coingecko/Coingecko.ts +12 -3
- package/src/gasPriceOracle/adapters/solana.ts +3 -1
- package/src/interfaces/SpokePool.ts +1 -4
- package/src/utils/TokenUtils.ts +6 -3
|
@@ -25,7 +25,6 @@ import {
|
|
|
25
25
|
BigNumber,
|
|
26
26
|
bnZero,
|
|
27
27
|
bnOne,
|
|
28
|
-
toAddress,
|
|
29
28
|
toBytes32,
|
|
30
29
|
spreadEventWithBlockNumber,
|
|
31
30
|
} from "../../utils";
|
|
@@ -85,6 +84,7 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
|
|
|
85
84
|
lastDepositId = _depositIds[i];
|
|
86
85
|
}
|
|
87
86
|
}
|
|
87
|
+
|
|
88
88
|
_getDepositIdAtBlock(blockTag: number): Promise<BigNumber> {
|
|
89
89
|
return Promise.resolve(this.depositIdAtBlock[blockTag]);
|
|
90
90
|
}
|
|
@@ -129,10 +129,6 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
|
|
|
129
129
|
return this._deposit("FundsDeposited", deposit);
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
depositV3(deposit: Omit<Deposit, "messageHash"> & Partial<SortableEvent>): Log {
|
|
133
|
-
return this._deposit("V3FundsDeposited", deposit);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
132
|
protected _deposit(event: string, deposit: Omit<Deposit, "messageHash"> & Partial<SortableEvent>): Log {
|
|
137
133
|
const { blockNumber, txnIndex } = deposit;
|
|
138
134
|
let { depositId, destinationChainId, inputAmount, outputAmount } = deposit;
|
|
@@ -140,12 +136,11 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
|
|
|
140
136
|
this.numberOfDeposits = depositId.add(bnOne);
|
|
141
137
|
|
|
142
138
|
destinationChainId ??= random(1, 42161, false);
|
|
143
|
-
const
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
const
|
|
147
|
-
const
|
|
148
|
-
const exclusiveRelayer = addressModifier(deposit.exclusiveRelayer ?? ZERO_ADDRESS);
|
|
139
|
+
const depositor = toBytes32(deposit.depositor ?? randomAddress());
|
|
140
|
+
const recipient = toBytes32(deposit.recipient ?? depositor);
|
|
141
|
+
const inputToken = toBytes32(deposit.inputToken ?? randomAddress());
|
|
142
|
+
const outputToken = toBytes32(deposit.outputToken ?? inputToken);
|
|
143
|
+
const exclusiveRelayer = toBytes32(deposit.exclusiveRelayer ?? ZERO_ADDRESS);
|
|
149
144
|
|
|
150
145
|
inputAmount ??= toBNWei(random(1, 1000, false));
|
|
151
146
|
outputAmount ??= inputAmount.mul(toBN("0.95"));
|
|
@@ -180,17 +175,13 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
|
|
|
180
175
|
});
|
|
181
176
|
}
|
|
182
177
|
|
|
183
|
-
|
|
184
|
-
return this._fillRelay("FilledV3Relay", fill);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
fillRelay(fill: Omit<Fill, "messageHash"> & { message: string } & Partial<SortableEvent>): Log {
|
|
178
|
+
fillRelay(fill: Omit<Fill, "messageHash"> & { message?: string } & Partial<SortableEvent>): Log {
|
|
188
179
|
return this._fillRelay("FilledRelay", fill);
|
|
189
180
|
}
|
|
190
181
|
|
|
191
182
|
protected _fillRelay(
|
|
192
183
|
event: string,
|
|
193
|
-
fill: Omit<Fill, "messageHash"> & { message
|
|
184
|
+
fill: Omit<Fill, "messageHash"> & { message?: string } & Partial<SortableEvent>
|
|
194
185
|
): Log {
|
|
195
186
|
const { blockNumber, txnIndex } = fill;
|
|
196
187
|
let { originChainId, depositId, inputAmount, outputAmount, fillDeadline } = fill;
|
|
@@ -200,15 +191,14 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
|
|
|
200
191
|
outputAmount ??= inputAmount;
|
|
201
192
|
fillDeadline ??= getCurrentTime() + 60;
|
|
202
193
|
|
|
203
|
-
const
|
|
204
|
-
const
|
|
205
|
-
const
|
|
206
|
-
const
|
|
207
|
-
const
|
|
208
|
-
const
|
|
209
|
-
const relayer = addressModifier(fill.relayer ?? randomAddress());
|
|
194
|
+
const depositor = toBytes32(fill.depositor ?? randomAddress());
|
|
195
|
+
const recipient = toBytes32(fill.recipient ?? depositor);
|
|
196
|
+
const inputToken = toBytes32(fill.inputToken ?? randomAddress());
|
|
197
|
+
const outputToken = toBytes32(fill.outputToken ?? ZERO_ADDRESS);
|
|
198
|
+
const exclusiveRelayer = toBytes32(fill.exclusiveRelayer ?? ZERO_ADDRESS);
|
|
199
|
+
const relayer = toBytes32(fill.relayer ?? randomAddress());
|
|
210
200
|
|
|
211
|
-
const topics = [originChainId, depositId, relayer];
|
|
201
|
+
const topics = [originChainId, depositId, relayer];
|
|
212
202
|
const message = fill.message ?? EMPTY_MESSAGE;
|
|
213
203
|
const updatedMessage = fill.relayExecutionInfo?.updatedMessage ?? message;
|
|
214
204
|
|
|
@@ -239,25 +229,14 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
|
|
|
239
229
|
},
|
|
240
230
|
};
|
|
241
231
|
|
|
242
|
-
const args =
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
},
|
|
251
|
-
}
|
|
252
|
-
: {
|
|
253
|
-
// FilledV3Relay
|
|
254
|
-
..._args,
|
|
255
|
-
message,
|
|
256
|
-
relayExecutionInfo: {
|
|
257
|
-
...relayExecutionInfo,
|
|
258
|
-
updatedMessage,
|
|
259
|
-
},
|
|
260
|
-
};
|
|
232
|
+
const args = {
|
|
233
|
+
..._args,
|
|
234
|
+
messageHash: getMessageHash(message),
|
|
235
|
+
relayExecutionInfo: {
|
|
236
|
+
...relayExecutionInfo,
|
|
237
|
+
updatedMessageHash: getMessageHash(updatedMessage),
|
|
238
|
+
},
|
|
239
|
+
};
|
|
261
240
|
|
|
262
241
|
return this.eventManager.generateEvent({
|
|
263
242
|
event,
|
|
@@ -269,17 +248,12 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
|
|
|
269
248
|
});
|
|
270
249
|
}
|
|
271
250
|
|
|
272
|
-
speedUpV3Deposit(speedUp: SpeedUp): Log {
|
|
273
|
-
return this._speedUpDeposit("RequestedSpeedUpV3Deposit", speedUp);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
251
|
speedUpDeposit(speedUp: SpeedUp): Log {
|
|
277
252
|
return this._speedUpDeposit("RequestedSpeedUpDeposit", speedUp);
|
|
278
253
|
}
|
|
279
254
|
|
|
280
255
|
protected _speedUpDeposit(event: string, speedUp: SpeedUp): Log {
|
|
281
|
-
const
|
|
282
|
-
const depositor = addressModifier(speedUp.depositor);
|
|
256
|
+
const depositor = toBytes32(speedUp.depositor);
|
|
283
257
|
const topics = [speedUp.depositId, depositor];
|
|
284
258
|
const args = { ...speedUp };
|
|
285
259
|
|
|
@@ -290,7 +264,7 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
|
|
|
290
264
|
args: {
|
|
291
265
|
...args,
|
|
292
266
|
depositor,
|
|
293
|
-
updatedRecipient:
|
|
267
|
+
updatedRecipient: toBytes32(speedUp.updatedRecipient),
|
|
294
268
|
},
|
|
295
269
|
});
|
|
296
270
|
}
|
|
@@ -308,24 +282,19 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
|
|
|
308
282
|
});
|
|
309
283
|
}
|
|
310
284
|
|
|
311
|
-
|
|
312
|
-
return this._requestSlowFill("RequestedV3SlowFill", request);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
requestSlowFill(request: Omit<SlowFillRequest, "messageHash"> & Partial<SortableEvent>): Log {
|
|
285
|
+
requestSlowFill(request: Omit<SlowFillRequest, "destinationChainId"> & Partial<SortableEvent>): Log {
|
|
316
286
|
return this._requestSlowFill("RequestedSlowFill", request);
|
|
317
287
|
}
|
|
318
288
|
|
|
319
289
|
protected _requestSlowFill(
|
|
320
290
|
event: string,
|
|
321
|
-
request: Omit<SlowFillRequest, "
|
|
291
|
+
request: Omit<SlowFillRequest, "destinationChainId"> & Partial<SortableEvent>
|
|
322
292
|
): Log {
|
|
323
293
|
const { originChainId, depositId } = request;
|
|
324
294
|
const topics = [originChainId, depositId];
|
|
325
295
|
const args = { ...request };
|
|
326
296
|
|
|
327
|
-
const
|
|
328
|
-
const depositor = addressModifier(args.depositor ?? randomAddress());
|
|
297
|
+
const depositor = toBytes32(args.depositor ?? randomAddress());
|
|
329
298
|
|
|
330
299
|
return this.eventManager.generateEvent({
|
|
331
300
|
event,
|
|
@@ -333,20 +302,21 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
|
|
|
333
302
|
topics: topics.map((topic) => topic.toString()),
|
|
334
303
|
args: {
|
|
335
304
|
...args,
|
|
305
|
+
destinationChainId: this.chainId,
|
|
336
306
|
depositor,
|
|
337
|
-
recipient:
|
|
338
|
-
inputToken:
|
|
339
|
-
outputToken:
|
|
340
|
-
exclusiveRelayer:
|
|
307
|
+
recipient: toBytes32(args.recipient ?? depositor),
|
|
308
|
+
inputToken: toBytes32(args.inputToken ?? randomAddress()),
|
|
309
|
+
outputToken: toBytes32(args.outputToken ?? ZERO_ADDRESS),
|
|
310
|
+
exclusiveRelayer: toBytes32(args.exclusiveRelayer ?? ZERO_ADDRESS),
|
|
341
311
|
},
|
|
342
312
|
blockNumber: request.blockNumber,
|
|
343
313
|
transactionIndex: request.txnIndex,
|
|
344
314
|
});
|
|
345
315
|
}
|
|
346
316
|
|
|
347
|
-
// This is a simple wrapper around
|
|
317
|
+
// This is a simple wrapper around fillRelay().
|
|
348
318
|
// rootBundleId and proof are discarded here - we have no interest in verifying that.
|
|
349
|
-
|
|
319
|
+
executeSlowRelayLeaf(leaf: Omit<SlowFillLeaf, "messageHash">): Log {
|
|
350
320
|
const fill = {
|
|
351
321
|
...leaf.relayData,
|
|
352
322
|
destinationChainId: this.chainId,
|
|
@@ -361,7 +331,7 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
|
|
|
361
331
|
},
|
|
362
332
|
};
|
|
363
333
|
|
|
364
|
-
return this.
|
|
334
|
+
return this.fillRelay(fill);
|
|
365
335
|
}
|
|
366
336
|
|
|
367
337
|
executeRelayerRefundLeaf(refund: RelayerRefundExecution & Partial<SortableEvent>): Log {
|
|
@@ -70,13 +70,14 @@ export class Coingecko {
|
|
|
70
70
|
private platformIdMap = new Map<number, string>(); // chainId => platform_id (137 => "polygon-pos")
|
|
71
71
|
private tokenIdMap: Record<string, Record<string, string>> = {}; // coinGeckoId => { platform_id : "tokenAddress":}
|
|
72
72
|
|
|
73
|
-
public static get(logger: Logger, apiKey?: string) {
|
|
73
|
+
public static get(logger: Logger, apiKey?: string, customPlatformIdMap?: Record<number, string>) {
|
|
74
74
|
if (!this.instance)
|
|
75
75
|
this.instance = new Coingecko(
|
|
76
76
|
"https://api.coingecko.com/api/v3",
|
|
77
77
|
"https://pro-api.coingecko.com/api/v3",
|
|
78
78
|
logger,
|
|
79
|
-
apiKey
|
|
79
|
+
apiKey,
|
|
80
|
+
customPlatformIdMap
|
|
80
81
|
);
|
|
81
82
|
return this.instance;
|
|
82
83
|
}
|
|
@@ -98,7 +99,8 @@ export class Coingecko {
|
|
|
98
99
|
private readonly host: string,
|
|
99
100
|
private readonly proHost: string,
|
|
100
101
|
private readonly logger: Logger,
|
|
101
|
-
private readonly apiKey?: string
|
|
102
|
+
private readonly apiKey?: string,
|
|
103
|
+
private readonly customPlatformIdMap?: Record<number, string>
|
|
102
104
|
) {
|
|
103
105
|
this.prices = {};
|
|
104
106
|
}
|
|
@@ -115,6 +117,13 @@ export class Coingecko {
|
|
|
115
117
|
platforms.filter((chain) => Boolean(chain.chain_identifier)).map((chain) => [chain.chain_identifier, chain.id])
|
|
116
118
|
);
|
|
117
119
|
|
|
120
|
+
// Extend the platformIdMap with any custom platform ids
|
|
121
|
+
if (this.customPlatformIdMap) {
|
|
122
|
+
Object.entries(this.customPlatformIdMap).forEach(([chainId, platformId]) => {
|
|
123
|
+
this.platformIdMap.set(Number(chainId), platformId);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
118
127
|
id = this.platformIdMap.get(chainId);
|
|
119
128
|
if (!id) {
|
|
120
129
|
this.logger.error({
|
|
@@ -34,7 +34,9 @@ export async function messageFee(provider: SVMProvider, opts: GasPriceEstimateOp
|
|
|
34
34
|
|
|
35
35
|
// Optionally impose a minimum priority fee, denoted in microLamports/computeUnit.
|
|
36
36
|
const flooredPriorityFeePerGas = parseUnits(process.env[`MIN_PRIORITY_FEE_PER_GAS_${opts.chainId}`] || "0", 6);
|
|
37
|
-
let microLamportsPerComputeUnit = toBN(
|
|
37
|
+
let microLamportsPerComputeUnit = toBN(
|
|
38
|
+
totalPrioritizationFees / BigInt(Math.max(nonzeroPrioritizationFees.length, 1))
|
|
39
|
+
);
|
|
38
40
|
if (microLamportsPerComputeUnit.lt(flooredPriorityFeePerGas)) {
|
|
39
41
|
microLamportsPerComputeUnit = flooredPriorityFeePerGas;
|
|
40
42
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { SortableEvent } from "./Common";
|
|
2
|
-
import { FilledV3RelayEvent, V3FundsDepositedEvent } from "../typechain";
|
|
3
2
|
import { SpokePoolClient } from "../clients";
|
|
4
3
|
import { BigNumber } from "../utils";
|
|
5
4
|
import { RelayerRefundLeaf } from "./HubPool";
|
|
6
5
|
|
|
7
|
-
export type { FilledV3RelayEvent, V3FundsDepositedEvent };
|
|
8
|
-
|
|
9
6
|
export interface RelayData {
|
|
10
7
|
originChainId: number;
|
|
11
8
|
depositor: string;
|
|
@@ -93,7 +90,7 @@ export interface SpeedUp {
|
|
|
93
90
|
|
|
94
91
|
export interface SpeedUpWithBlock extends SpeedUp, SortableEvent {}
|
|
95
92
|
|
|
96
|
-
export interface SlowFillRequest extends RelayData {
|
|
93
|
+
export interface SlowFillRequest extends Omit<RelayData, "message"> {
|
|
97
94
|
messageHash: string;
|
|
98
95
|
destinationChainId: number;
|
|
99
96
|
}
|
package/src/utils/TokenUtils.ts
CHANGED
|
@@ -4,9 +4,9 @@ import * as constants from "../constants";
|
|
|
4
4
|
import { L1Token } from "../interfaces";
|
|
5
5
|
import { ERC20__factory } from "../typechain";
|
|
6
6
|
import { BigNumber } from "./BigNumberUtils";
|
|
7
|
-
import { getNetworkName, chainIsL1, chainIsProd } from "./NetworkUtils";
|
|
7
|
+
import { getNetworkName, chainIsL1, chainIsProd, chainIsSvm } from "./NetworkUtils";
|
|
8
8
|
import { isDefined } from "./TypeGuards";
|
|
9
|
-
import { compareAddressesSimple } from "./AddressUtils";
|
|
9
|
+
import { compareAddressesSimple, toAddressType } from "./AddressUtils";
|
|
10
10
|
const { TOKEN_SYMBOLS_MAP, CHAIN_IDs, TOKEN_EQUIVALENCE_REMAPPING } = constants;
|
|
11
11
|
|
|
12
12
|
type SignerOrProvider = providers.Provider | Signer;
|
|
@@ -112,9 +112,12 @@ export function isStablecoin(tokenSymbol: string): boolean {
|
|
|
112
112
|
* @returns
|
|
113
113
|
*/
|
|
114
114
|
export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMapping = TOKEN_SYMBOLS_MAP): L1Token {
|
|
115
|
+
const parsedAddress = chainIsSvm(chainId)
|
|
116
|
+
? toAddressType(l2TokenAddress).toBase58()
|
|
117
|
+
: toAddressType(l2TokenAddress).toEvmAddress();
|
|
115
118
|
// @dev This might give false positives if tokens on different networks have the same address. I'm not sure how
|
|
116
119
|
// to get around this...
|
|
117
|
-
let tokenObject = Object.values(tokenMapping).find(({ addresses }) => addresses[chainId] ===
|
|
120
|
+
let tokenObject = Object.values(tokenMapping).find(({ addresses }) => addresses[chainId] === parsedAddress);
|
|
118
121
|
if (!tokenObject) {
|
|
119
122
|
throw new Error(
|
|
120
123
|
`TokenUtils#getTokenInfo: Unable to resolve token in TOKEN_SYMBOLS_MAP for ${l2TokenAddress} on chain ${chainId}`
|