@across-protocol/sdk 4.1.42 → 4.1.44
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/addressAggregator/adapters/abstract.d.ts +15 -0
- package/dist/cjs/addressAggregator/adapters/abstract.js +83 -0
- package/dist/cjs/addressAggregator/adapters/abstract.js.map +1 -0
- package/dist/cjs/addressAggregator/adapters/bybit.d.ts +5 -9
- package/dist/cjs/addressAggregator/adapters/bybit.js +11 -12
- package/dist/cjs/addressAggregator/adapters/bybit.js.map +1 -1
- package/dist/cjs/addressAggregator/adapters/env.d.ts +5 -7
- package/dist/cjs/addressAggregator/adapters/env.js +12 -11
- package/dist/cjs/addressAggregator/adapters/env.js.map +1 -1
- package/dist/cjs/addressAggregator/adapters/file.d.ts +5 -7
- package/dist/cjs/addressAggregator/adapters/file.js +13 -12
- package/dist/cjs/addressAggregator/adapters/file.js.map +1 -1
- package/dist/cjs/addressAggregator/adapters/risklabs.d.ts +5 -9
- package/dist/cjs/addressAggregator/adapters/risklabs.js +18 -14
- package/dist/cjs/addressAggregator/adapters/risklabs.js.map +1 -1
- package/dist/cjs/addressAggregator/index.js +2 -2
- package/dist/cjs/addressAggregator/index.js.map +1 -1
- package/dist/cjs/addressAggregator/types.d.ts +9 -1
- package/dist/cjs/addressAggregator/types.js.map +1 -1
- package/dist/cjs/arch/evm/SpokeUtils.d.ts +15 -0
- package/dist/cjs/arch/evm/SpokeUtils.js +312 -0
- package/dist/cjs/arch/evm/SpokeUtils.js.map +1 -0
- package/dist/cjs/arch/evm/index.d.ts +1 -1
- package/dist/cjs/arch/evm/index.js +2 -2
- package/dist/cjs/arch/evm/index.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +3 -2
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +8 -8
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.d.ts +3 -2
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js +11 -8
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.d.ts +2 -1
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
- package/dist/cjs/constants.d.ts +1 -0
- package/dist/cjs/constants.js +13 -1
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/providers/types.d.ts +2 -2
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +2 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/cjs/utils/DepositUtils.js +1 -1
- package/dist/cjs/utils/DepositUtils.js.map +1 -1
- package/dist/cjs/utils/SpokeUtils.d.ts +2 -14
- package/dist/cjs/utils/SpokeUtils.js +8 -313
- package/dist/cjs/utils/SpokeUtils.js.map +1 -1
- package/dist/cjs/utils/TokenUtils.d.ts +1 -0
- package/dist/cjs/utils/TokenUtils.js +5 -1
- package/dist/cjs/utils/TokenUtils.js.map +1 -1
- package/dist/esm/addressAggregator/adapters/abstract.d.ts +15 -0
- package/dist/esm/addressAggregator/adapters/abstract.js +80 -0
- package/dist/esm/addressAggregator/adapters/abstract.js.map +1 -0
- package/dist/esm/addressAggregator/adapters/bybit.d.ts +5 -9
- package/dist/esm/addressAggregator/adapters/bybit.js +12 -13
- package/dist/esm/addressAggregator/adapters/bybit.js.map +1 -1
- package/dist/esm/addressAggregator/adapters/env.d.ts +5 -7
- package/dist/esm/addressAggregator/adapters/env.js +12 -11
- package/dist/esm/addressAggregator/adapters/env.js.map +1 -1
- package/dist/esm/addressAggregator/adapters/file.d.ts +5 -7
- package/dist/esm/addressAggregator/adapters/file.js +14 -13
- package/dist/esm/addressAggregator/adapters/file.js.map +1 -1
- package/dist/esm/addressAggregator/adapters/risklabs.d.ts +5 -9
- package/dist/esm/addressAggregator/adapters/risklabs.js +19 -15
- package/dist/esm/addressAggregator/adapters/risklabs.js.map +1 -1
- package/dist/esm/addressAggregator/index.js +2 -2
- package/dist/esm/addressAggregator/index.js.map +1 -1
- package/dist/esm/addressAggregator/types.d.ts +9 -1
- package/dist/esm/addressAggregator/types.js.map +1 -1
- package/dist/esm/arch/evm/SpokeUtils.d.ts +58 -0
- package/dist/esm/arch/evm/SpokeUtils.js +345 -0
- package/dist/esm/arch/evm/SpokeUtils.js.map +1 -0
- package/dist/esm/arch/evm/index.d.ts +1 -1
- package/dist/esm/arch/evm/index.js +1 -1
- package/dist/esm/arch/evm/index.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js +3 -2
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +8 -8
- package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.d.ts +3 -2
- package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +7 -4
- package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.d.ts +9 -1
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
- package/dist/esm/constants.d.ts +1 -0
- package/dist/esm/constants.js +12 -0
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/providers/types.d.ts +2 -2
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +2 -1
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/esm/utils/DepositUtils.js +2 -1
- package/dist/esm/utils/DepositUtils.js.map +1 -1
- package/dist/esm/utils/SpokeUtils.d.ts +5 -55
- package/dist/esm/utils/SpokeUtils.js +11 -348
- package/dist/esm/utils/SpokeUtils.js.map +1 -1
- package/dist/esm/utils/TokenUtils.d.ts +1 -0
- package/dist/esm/utils/TokenUtils.js +3 -0
- package/dist/esm/utils/TokenUtils.js.map +1 -1
- package/dist/types/addressAggregator/adapters/abstract.d.ts +16 -0
- package/dist/types/addressAggregator/adapters/abstract.d.ts.map +1 -0
- package/dist/types/addressAggregator/adapters/bybit.d.ts +5 -9
- package/dist/types/addressAggregator/adapters/bybit.d.ts.map +1 -1
- package/dist/types/addressAggregator/adapters/env.d.ts +5 -7
- package/dist/types/addressAggregator/adapters/env.d.ts.map +1 -1
- package/dist/types/addressAggregator/adapters/file.d.ts +5 -7
- package/dist/types/addressAggregator/adapters/file.d.ts.map +1 -1
- package/dist/types/addressAggregator/adapters/risklabs.d.ts +5 -9
- package/dist/types/addressAggregator/adapters/risklabs.d.ts.map +1 -1
- package/dist/types/addressAggregator/types.d.ts +9 -1
- package/dist/types/addressAggregator/types.d.ts.map +1 -1
- package/dist/types/arch/evm/SpokeUtils.d.ts +59 -0
- package/dist/types/arch/evm/SpokeUtils.d.ts.map +1 -0
- package/dist/types/arch/evm/index.d.ts +1 -1
- package/dist/types/arch/evm/index.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +8 -8
- package/dist/types/clients/SpokePoolClient/EVMSpokePoolClient.d.ts +3 -2
- package/dist/types/clients/SpokePoolClient/EVMSpokePoolClient.d.ts.map +1 -1
- package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts +9 -1
- package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
- package/dist/types/constants.d.ts +1 -0
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/providers/types.d.ts +2 -2
- package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
- package/dist/types/utils/DepositUtils.d.ts.map +1 -1
- package/dist/types/utils/SpokeUtils.d.ts +5 -55
- package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
- package/dist/types/utils/TokenUtils.d.ts +1 -0
- package/dist/types/utils/TokenUtils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/addressAggregator/adapters/abstract.ts +74 -0
- package/src/addressAggregator/adapters/bybit.ts +10 -11
- package/src/addressAggregator/adapters/env.ts +10 -10
- package/src/addressAggregator/adapters/file.ts +11 -12
- package/src/addressAggregator/adapters/risklabs.ts +14 -13
- package/src/addressAggregator/index.ts +2 -2
- package/src/addressAggregator/types.ts +10 -1
- package/src/arch/evm/SpokeUtils.ts +324 -0
- package/src/arch/evm/index.ts +1 -1
- package/src/clients/BundleDataClient/BundleDataClient.ts +2 -3
- package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +27 -16
- package/src/clients/SpokePoolClient/SpokePoolClient.ts +13 -5
- package/src/constants.ts +13 -0
- package/src/index.ts +1 -0
- package/src/relayFeeCalculator/chain-queries/baseQuery.ts +1 -1
- package/src/utils/DepositUtils.ts +2 -1
- package/src/utils/SpokeUtils.ts +16 -314
- package/src/utils/TokenUtils.ts +6 -0
- package/dist/cjs/addressAggregator/adapters/util.d.ts +0 -4
- package/dist/cjs/addressAggregator/adapters/util.js +0 -66
- package/dist/cjs/addressAggregator/adapters/util.js.map +0 -1
- package/dist/esm/addressAggregator/adapters/util.d.ts +0 -4
- package/dist/esm/addressAggregator/adapters/util.js +0 -60
- package/dist/esm/addressAggregator/adapters/util.js.map +0 -1
- package/dist/types/addressAggregator/adapters/util.d.ts +0 -5
- package/dist/types/addressAggregator/adapters/util.d.ts.map +0 -1
- package/src/addressAggregator/adapters/util.ts +0 -47
package/src/utils/SpokeUtils.ts
CHANGED
|
@@ -1,31 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { chunk } from "./ArrayUtils";
|
|
6
|
-
import { bnUint32Max, BigNumber, toBN, bnZero } from "./BigNumberUtils";
|
|
1
|
+
import { utils as ethersUtils } from "ethers";
|
|
2
|
+
import { MAX_SAFE_DEPOSIT_ID, ZERO_ADDRESS, ZERO_BYTES } from "../constants";
|
|
3
|
+
import { Deposit, RelayData } from "../interfaces";
|
|
4
|
+
import { toBytes32 } from "./AddressUtils";
|
|
7
5
|
import { keccak256 } from "./common";
|
|
6
|
+
import { BigNumber } from "./BigNumberUtils";
|
|
8
7
|
import { isMessageEmpty } from "./DepositUtils";
|
|
9
|
-
import { isDefined } from "./TypeGuards";
|
|
10
|
-
import { getNetworkName } from "./NetworkUtils";
|
|
11
|
-
import { paginatedEventQuery, spreadEventWithBlockNumber } from "./EventUtils";
|
|
12
|
-
import { toBytes32 } from "./AddressUtils";
|
|
13
|
-
|
|
14
|
-
type BlockTag = providers.BlockTag;
|
|
15
8
|
|
|
16
9
|
/**
|
|
17
|
-
*
|
|
18
|
-
* @param deposit
|
|
19
|
-
* @
|
|
20
|
-
* @returns An Ethers UnsignedTransaction instance.
|
|
10
|
+
* Produce the RelayData for a Deposit.
|
|
11
|
+
* @param deposit Deposit instance.
|
|
12
|
+
* @returns The corresponding RelayData object.
|
|
21
13
|
*/
|
|
22
|
-
export function
|
|
23
|
-
|
|
24
|
-
deposit: Omit<Deposit, "messageHash">,
|
|
25
|
-
relayer: string,
|
|
26
|
-
repaymentChainId = deposit.destinationChainId
|
|
27
|
-
): Promise<PopulatedTransaction> {
|
|
28
|
-
const v3RelayData: RelayData = {
|
|
14
|
+
export function getDepositRelayData(deposit: Omit<Deposit, "messageHash">): RelayData {
|
|
15
|
+
return {
|
|
29
16
|
depositor: toBytes32(deposit.depositor),
|
|
30
17
|
recipient: toBytes32(deposit.recipient),
|
|
31
18
|
exclusiveRelayer: toBytes32(deposit.exclusiveRelayer),
|
|
@@ -39,77 +26,6 @@ export function populateV3Relay(
|
|
|
39
26
|
exclusivityDeadline: deposit.exclusivityDeadline,
|
|
40
27
|
message: deposit.message,
|
|
41
28
|
};
|
|
42
|
-
if (isDefined(deposit.speedUpSignature)) {
|
|
43
|
-
assert(isDefined(deposit.updatedRecipient) && !isZeroAddress(deposit.updatedRecipient));
|
|
44
|
-
assert(isDefined(deposit.updatedOutputAmount));
|
|
45
|
-
assert(isDefined(deposit.updatedMessage));
|
|
46
|
-
return spokePool.populateTransaction.fillRelayWithUpdatedDeposit(
|
|
47
|
-
v3RelayData,
|
|
48
|
-
repaymentChainId,
|
|
49
|
-
toBytes32(relayer),
|
|
50
|
-
deposit.updatedOutputAmount,
|
|
51
|
-
toBytes32(deposit.updatedRecipient),
|
|
52
|
-
deposit.updatedMessage,
|
|
53
|
-
deposit.speedUpSignature,
|
|
54
|
-
{ from: relayer }
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return spokePool.populateTransaction.fillRelay(v3RelayData, repaymentChainId, toBytes32(relayer), { from: relayer });
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Retrieves the time from the SpokePool contract at a particular block.
|
|
63
|
-
* @returns The time at the specified block tag.
|
|
64
|
-
*/
|
|
65
|
-
export async function getTimeAt(spokePool: Contract, blockNumber: number): Promise<number> {
|
|
66
|
-
const currentTime = await spokePool.getCurrentTime({ blockTag: blockNumber });
|
|
67
|
-
assert(BigNumber.isBigNumber(currentTime) && currentTime.lt(bnUint32Max));
|
|
68
|
-
return currentTime.toNumber();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Retrieves the chain time at a particular block.
|
|
73
|
-
* @note This should be the same as getTimeAt() but can differ in test. These two functions should be consolidated.
|
|
74
|
-
* @returns The chain time at the specified block tag.
|
|
75
|
-
*/
|
|
76
|
-
export async function getTimestampForBlock(provider: providers.Provider, blockNumber: number): Promise<number> {
|
|
77
|
-
const block = await provider.getBlock(blockNumber);
|
|
78
|
-
return block.timestamp;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Return maximum of fill deadline buffer at start and end of block range.
|
|
83
|
-
* @param spokePool SpokePool contract instance
|
|
84
|
-
* @param startBlock start block
|
|
85
|
-
* @param endBlock end block
|
|
86
|
-
* @returns maximum of fill deadline buffer at start and end block
|
|
87
|
-
*/
|
|
88
|
-
export async function getMaxFillDeadlineInRange(
|
|
89
|
-
spokePool: Contract,
|
|
90
|
-
startBlock: number,
|
|
91
|
-
endBlock: number
|
|
92
|
-
): Promise<number> {
|
|
93
|
-
const fillDeadlineBuffers = await Promise.all([
|
|
94
|
-
spokePool.fillDeadlineBuffer({ blockTag: startBlock }),
|
|
95
|
-
spokePool.fillDeadlineBuffer({ blockTag: endBlock }),
|
|
96
|
-
]);
|
|
97
|
-
return Math.max(fillDeadlineBuffers[0], fillDeadlineBuffers[1]);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Finds the deposit id at a specific block number.
|
|
102
|
-
* @param blockTag The block number to search for the deposit ID at.
|
|
103
|
-
* @returns The deposit ID.
|
|
104
|
-
*/
|
|
105
|
-
export async function getDepositIdAtBlock(contract: Contract, blockTag: number): Promise<BigNumber> {
|
|
106
|
-
const _depositIdAtBlock = await contract.numberOfDeposits({ blockTag });
|
|
107
|
-
const depositIdAtBlock = toBN(_depositIdAtBlock);
|
|
108
|
-
// Sanity check to ensure that the deposit ID is greater than or equal to zero.
|
|
109
|
-
if (depositIdAtBlock.lt(bnZero)) {
|
|
110
|
-
throw new Error("Invalid deposit count");
|
|
111
|
-
}
|
|
112
|
-
return depositIdAtBlock;
|
|
113
29
|
}
|
|
114
30
|
|
|
115
31
|
/**
|
|
@@ -121,13 +37,13 @@ export async function getDepositIdAtBlock(contract: Contract, blockTag: number):
|
|
|
121
37
|
export function getRelayDataHash(relayData: RelayData, destinationChainId: number): string {
|
|
122
38
|
const _relayData = {
|
|
123
39
|
...relayData,
|
|
124
|
-
depositor:
|
|
125
|
-
recipient:
|
|
126
|
-
inputToken:
|
|
127
|
-
outputToken:
|
|
128
|
-
exclusiveRelayer:
|
|
40
|
+
depositor: toBytes32(relayData.depositor),
|
|
41
|
+
recipient: toBytes32(relayData.recipient),
|
|
42
|
+
inputToken: toBytes32(relayData.inputToken),
|
|
43
|
+
outputToken: toBytes32(relayData.outputToken),
|
|
44
|
+
exclusiveRelayer: toBytes32(relayData.exclusiveRelayer),
|
|
129
45
|
};
|
|
130
|
-
return
|
|
46
|
+
return keccak256(
|
|
131
47
|
ethersUtils.defaultAbiCoder.encode(
|
|
132
48
|
[
|
|
133
49
|
"tuple(" +
|
|
@@ -155,47 +71,6 @@ export function getRelayHashFromEvent(e: RelayData & { destinationChainId: numbe
|
|
|
155
71
|
return getRelayDataHash(e, e.destinationChainId);
|
|
156
72
|
}
|
|
157
73
|
|
|
158
|
-
export async function findDepositBlock(
|
|
159
|
-
spokePool: Contract,
|
|
160
|
-
depositId: BigNumber,
|
|
161
|
-
lowBlock: number,
|
|
162
|
-
highBlock?: number
|
|
163
|
-
): Promise<number | undefined> {
|
|
164
|
-
// We can only perform this search when we have a safe deposit ID.
|
|
165
|
-
if (isUnsafeDepositId(depositId)) {
|
|
166
|
-
throw new Error(`Cannot binary search for depositId ${depositId}`);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
highBlock ??= await spokePool.provider.getBlockNumber();
|
|
170
|
-
assert(highBlock > lowBlock, `Block numbers out of range (${lowBlock} >= ${highBlock})`);
|
|
171
|
-
|
|
172
|
-
// Make sure the deposit occurred within the block range supplied by the caller.
|
|
173
|
-
const [nDepositsLow, nDepositsHigh] = (
|
|
174
|
-
await Promise.all([
|
|
175
|
-
spokePool.numberOfDeposits({ blockTag: lowBlock }),
|
|
176
|
-
spokePool.numberOfDeposits({ blockTag: highBlock }),
|
|
177
|
-
])
|
|
178
|
-
).map((n) => toBN(n));
|
|
179
|
-
|
|
180
|
-
if (nDepositsLow.gt(depositId) || nDepositsHigh.lte(depositId)) {
|
|
181
|
-
return undefined; // Deposit did not occur within the specified block range.
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// Find the lowest block number where numberOfDeposits is greater than the requested depositId.
|
|
185
|
-
do {
|
|
186
|
-
const midBlock = Math.floor((highBlock + lowBlock) / 2);
|
|
187
|
-
const nDeposits = toBN(await spokePool.numberOfDeposits({ blockTag: midBlock }));
|
|
188
|
-
|
|
189
|
-
if (nDeposits.gt(depositId)) {
|
|
190
|
-
highBlock = midBlock; // depositId occurred at or earlier than midBlock.
|
|
191
|
-
} else {
|
|
192
|
-
lowBlock = midBlock + 1; // depositId occurred later than midBlock.
|
|
193
|
-
}
|
|
194
|
-
} while (lowBlock < highBlock);
|
|
195
|
-
|
|
196
|
-
return lowBlock;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
74
|
export function isUnsafeDepositId(depositId: BigNumber): boolean {
|
|
200
75
|
// SpokePool.unsafeDepositV3() produces a uint256 depositId by hashing the msg.sender, depositor and input
|
|
201
76
|
// uint256 depositNonce. There is a possibility that this resultant uint256 is less than the maxSafeDepositId (i.e.
|
|
@@ -206,179 +81,6 @@ export function isUnsafeDepositId(depositId: BigNumber): boolean {
|
|
|
206
81
|
return maxSafeDepositId.lt(depositId);
|
|
207
82
|
}
|
|
208
83
|
|
|
209
|
-
/**
|
|
210
|
-
* Find the amount filled for a deposit at a particular block.
|
|
211
|
-
* @param spokePool SpokePool contract instance.
|
|
212
|
-
* @param relayData Deposit information that is used to complete a fill.
|
|
213
|
-
* @param blockTag Block tag (numeric or "latest") to query at.
|
|
214
|
-
* @returns The amount filled for the specified deposit at the requested block (or latest).
|
|
215
|
-
*/
|
|
216
|
-
export async function relayFillStatus(
|
|
217
|
-
spokePool: Contract,
|
|
218
|
-
relayData: RelayData,
|
|
219
|
-
blockTag?: number | "latest",
|
|
220
|
-
destinationChainId?: number
|
|
221
|
-
): Promise<FillStatus> {
|
|
222
|
-
destinationChainId ??= await spokePool.chainId();
|
|
223
|
-
assert(isDefined(destinationChainId));
|
|
224
|
-
|
|
225
|
-
const hash = getRelayDataHash(relayData, destinationChainId);
|
|
226
|
-
const _fillStatus = await spokePool.fillStatuses(hash, { blockTag });
|
|
227
|
-
const fillStatus = Number(_fillStatus);
|
|
228
|
-
|
|
229
|
-
if (![FillStatus.Unfilled, FillStatus.RequestedSlowFill, FillStatus.Filled].includes(fillStatus)) {
|
|
230
|
-
const { originChainId, depositId } = relayData;
|
|
231
|
-
throw new Error(
|
|
232
|
-
`relayFillStatus: Unexpected fillStatus for ${originChainId} deposit ${depositId.toString()} (${fillStatus})`
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
return fillStatus;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
export async function fillStatusArray(
|
|
240
|
-
spokePool: Contract,
|
|
241
|
-
relayData: RelayData[],
|
|
242
|
-
blockTag: BlockTag = "latest"
|
|
243
|
-
): Promise<(FillStatus | undefined)[]> {
|
|
244
|
-
const fillStatuses = "fillStatuses";
|
|
245
|
-
const destinationChainId = await spokePool.chainId();
|
|
246
|
-
|
|
247
|
-
const queries = relayData.map((relayData) => {
|
|
248
|
-
const hash = getRelayDataHash(relayData, destinationChainId);
|
|
249
|
-
return spokePool.interface.encodeFunctionData(fillStatuses, [hash]);
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
// Chunk the hashes into appropriate sizes to avoid death by rpc.
|
|
253
|
-
const chunkSize = 250;
|
|
254
|
-
const chunkedQueries = chunk(queries, chunkSize);
|
|
255
|
-
|
|
256
|
-
const multicalls = await Promise.all(
|
|
257
|
-
chunkedQueries.map((queries) => spokePool.callStatic.multicall(queries, { blockTag }))
|
|
258
|
-
);
|
|
259
|
-
const status = multicalls
|
|
260
|
-
.map((multicall: BytesLike[]) =>
|
|
261
|
-
multicall.map((result) => spokePool.interface.decodeFunctionResult(fillStatuses, result)[0])
|
|
262
|
-
)
|
|
263
|
-
.flat();
|
|
264
|
-
|
|
265
|
-
const bnUnfilled = toBN(FillStatus.Unfilled);
|
|
266
|
-
const bnFilled = toBN(FillStatus.Filled);
|
|
267
|
-
|
|
268
|
-
return status.map((status: unknown) => {
|
|
269
|
-
return BigNumber.isBigNumber(status) && status.gte(bnUnfilled) && status.lte(bnFilled)
|
|
270
|
-
? status.toNumber()
|
|
271
|
-
: undefined;
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Find the block at which a fill was completed.
|
|
277
|
-
* @todo After SpokePool upgrade, this function can be simplified to use the FillStatus enum.
|
|
278
|
-
* @param spokePool SpokePool contract instance.
|
|
279
|
-
* @param relayData Deposit information that is used to complete a fill.
|
|
280
|
-
* @param lowBlockNumber The lower bound of the search. Must be bounded by SpokePool deployment.
|
|
281
|
-
* @param highBlocknumber Optional upper bound for the search.
|
|
282
|
-
* @returns The block number at which the relay was completed, or undefined.
|
|
283
|
-
*/
|
|
284
|
-
export async function findFillBlock(
|
|
285
|
-
spokePool: Contract,
|
|
286
|
-
relayData: RelayData,
|
|
287
|
-
lowBlockNumber: number,
|
|
288
|
-
highBlockNumber?: number
|
|
289
|
-
): Promise<number | undefined> {
|
|
290
|
-
const { provider } = spokePool;
|
|
291
|
-
highBlockNumber ??= await provider.getBlockNumber();
|
|
292
|
-
assert(highBlockNumber > lowBlockNumber, `Block numbers out of range (${lowBlockNumber} >= ${highBlockNumber})`);
|
|
293
|
-
|
|
294
|
-
// In production the chainId returned from the provider matches 1:1 with the actual chainId. Querying the provider
|
|
295
|
-
// object saves an RPC query because the chainId is cached by StaticJsonRpcProvider instances. In hre, the SpokePool
|
|
296
|
-
// may be configured with a different chainId than what is returned by the provider.
|
|
297
|
-
const destinationChainId = Object.values(CHAIN_IDs).includes(relayData.originChainId)
|
|
298
|
-
? (await provider.getNetwork()).chainId
|
|
299
|
-
: Number(await spokePool.chainId());
|
|
300
|
-
assert(
|
|
301
|
-
relayData.originChainId !== destinationChainId,
|
|
302
|
-
`Origin & destination chain IDs must not be equal (${destinationChainId})`
|
|
303
|
-
);
|
|
304
|
-
|
|
305
|
-
// Make sure the relay was completed within the block range supplied by the caller.
|
|
306
|
-
const [initialFillStatus, finalFillStatus] = (
|
|
307
|
-
await Promise.all([
|
|
308
|
-
relayFillStatus(spokePool, relayData, lowBlockNumber, destinationChainId),
|
|
309
|
-
relayFillStatus(spokePool, relayData, highBlockNumber, destinationChainId),
|
|
310
|
-
])
|
|
311
|
-
).map(Number);
|
|
312
|
-
|
|
313
|
-
if (finalFillStatus !== FillStatus.Filled) {
|
|
314
|
-
return undefined; // Wasn't filled within the specified block range.
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// Was filled earlier than the specified lowBlock. This is an error by the caller.
|
|
318
|
-
if (initialFillStatus === FillStatus.Filled) {
|
|
319
|
-
const { depositId, originChainId } = relayData;
|
|
320
|
-
const [srcChain, dstChain] = [getNetworkName(originChainId), getNetworkName(destinationChainId)];
|
|
321
|
-
throw new Error(`${srcChain} deposit ${depositId.toString()} filled on ${dstChain} before block ${lowBlockNumber}`);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
// Find the leftmost block where filledAmount equals the deposit amount.
|
|
325
|
-
do {
|
|
326
|
-
const midBlockNumber = Math.floor((highBlockNumber + lowBlockNumber) / 2);
|
|
327
|
-
const fillStatus = await relayFillStatus(spokePool, relayData, midBlockNumber, destinationChainId);
|
|
328
|
-
|
|
329
|
-
if (fillStatus === FillStatus.Filled) {
|
|
330
|
-
highBlockNumber = midBlockNumber;
|
|
331
|
-
} else {
|
|
332
|
-
lowBlockNumber = midBlockNumber + 1;
|
|
333
|
-
}
|
|
334
|
-
} while (lowBlockNumber < highBlockNumber);
|
|
335
|
-
|
|
336
|
-
return lowBlockNumber;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
export async function findFillEvent(
|
|
340
|
-
spokePool: Contract,
|
|
341
|
-
relayData: RelayData,
|
|
342
|
-
lowBlockNumber: number,
|
|
343
|
-
highBlockNumber?: number
|
|
344
|
-
): Promise<FillWithBlock | undefined> {
|
|
345
|
-
const blockNumber = await findFillBlock(spokePool, relayData, lowBlockNumber, highBlockNumber);
|
|
346
|
-
if (!blockNumber) return undefined;
|
|
347
|
-
|
|
348
|
-
// We can hardcode this to 0 to instruct paginatedEventQuery to make a single request for the same block number.
|
|
349
|
-
const maxBlockLookBack = 0;
|
|
350
|
-
const [fromBlock, toBlock] = [blockNumber, blockNumber];
|
|
351
|
-
|
|
352
|
-
const query = (
|
|
353
|
-
await Promise.all([
|
|
354
|
-
paginatedEventQuery(
|
|
355
|
-
spokePool,
|
|
356
|
-
spokePool.filters.FilledRelay(null, null, null, null, null, relayData.originChainId, relayData.depositId),
|
|
357
|
-
{ fromBlock, toBlock, maxBlockLookBack }
|
|
358
|
-
),
|
|
359
|
-
paginatedEventQuery(
|
|
360
|
-
spokePool,
|
|
361
|
-
spokePool.filters.FilledV3Relay(null, null, null, null, null, relayData.originChainId, relayData.depositId),
|
|
362
|
-
{ fromBlock, toBlock, maxBlockLookBack }
|
|
363
|
-
),
|
|
364
|
-
])
|
|
365
|
-
).flat();
|
|
366
|
-
if (query.length === 0) throw new Error(`Failed to find fill event at block ${blockNumber}`);
|
|
367
|
-
const event = query[0];
|
|
368
|
-
// In production the chainId returned from the provider matches 1:1 with the actual chainId. Querying the provider
|
|
369
|
-
// object saves an RPC query because the chainId is cached by StaticJsonRpcProvider instances. In hre, the SpokePool
|
|
370
|
-
// may be configured with a different chainId than what is returned by the provider.
|
|
371
|
-
const destinationChainId = Object.values(CHAIN_IDs).includes(relayData.originChainId)
|
|
372
|
-
? (await spokePool.provider.getNetwork()).chainId
|
|
373
|
-
: Number(await spokePool.chainId());
|
|
374
|
-
const fill = {
|
|
375
|
-
...spreadEventWithBlockNumber(event),
|
|
376
|
-
destinationChainId,
|
|
377
|
-
messageHash: getMessageHash(event.args.message),
|
|
378
|
-
} as FillWithBlock;
|
|
379
|
-
return fill;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
84
|
// Determines if the input address (either a bytes32 or bytes20) is the zero address.
|
|
383
85
|
export function isZeroAddress(address: string): boolean {
|
|
384
86
|
return address === ZERO_ADDRESS || address === ZERO_BYTES;
|
package/src/utils/TokenUtils.ts
CHANGED
|
@@ -109,6 +109,12 @@ export function isBridgedUsdc(tokenSymbol: string): boolean {
|
|
|
109
109
|
);
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
export function isStablecoin(tokenSymbol: string): boolean {
|
|
113
|
+
return constants.STABLE_COIN_SYMBOLS.some(
|
|
114
|
+
(stablecoinSymbol) => stablecoinSymbol.toLowerCase() === tokenSymbol.toLowerCase()
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
112
118
|
export function getTokenInfo(l2TokenAddress: string, chainId: number): L1Token {
|
|
113
119
|
// @dev This might give false positives if tokens on different networks have the same address. I'm not sure how
|
|
114
120
|
// to get around this...
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { Logger } from "../../utils";
|
|
2
|
-
export { Logger } from "../../utils";
|
|
3
|
-
export declare function logError(name: string, error: unknown, logger?: Logger): Promise<string[]>;
|
|
4
|
-
export declare function fetch(name: string, url: string, timeout?: number, retries?: number): Promise<unknown>;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetch = exports.logError = exports.Logger = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var axios_1 = tslib_1.__importDefault(require("axios"));
|
|
6
|
-
var utils_1 = require("../../utils");
|
|
7
|
-
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return utils_1.Logger; } });
|
|
8
|
-
var _a = process.env.ACROSS_USER_AGENT, ACROSS_USER_AGENT = _a === void 0 ? "across-protocol" : _a;
|
|
9
|
-
function sleep(ms) {
|
|
10
|
-
return new Promise(function (r) { return setTimeout(r, ms); });
|
|
11
|
-
}
|
|
12
|
-
function logError(name, error, logger) {
|
|
13
|
-
var reason;
|
|
14
|
-
if (error instanceof Error) {
|
|
15
|
-
reason = error.message;
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
reason = typeof error === "string" ? error : "unknown error";
|
|
19
|
-
}
|
|
20
|
-
logger === null || logger === void 0 ? void 0 : logger.warn({
|
|
21
|
-
at: "".concat(name, "::update"),
|
|
22
|
-
message: "Failed to read addresses from ".concat(name, "."),
|
|
23
|
-
reason: reason,
|
|
24
|
-
});
|
|
25
|
-
return Promise.resolve([]);
|
|
26
|
-
}
|
|
27
|
-
exports.logError = logError;
|
|
28
|
-
function fetch(name, url, timeout, retries) {
|
|
29
|
-
if (timeout === void 0) { timeout = 2000; }
|
|
30
|
-
if (retries === void 0) { retries = 1; }
|
|
31
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
32
|
-
var args, errs, tries, err_1, errMsg;
|
|
33
|
-
return tslib_1.__generator(this, function (_a) {
|
|
34
|
-
switch (_a.label) {
|
|
35
|
-
case 0:
|
|
36
|
-
args = {
|
|
37
|
-
headers: { "User-Agent": ACROSS_USER_AGENT },
|
|
38
|
-
timeout: timeout,
|
|
39
|
-
};
|
|
40
|
-
errs = [];
|
|
41
|
-
tries = 0;
|
|
42
|
-
_a.label = 1;
|
|
43
|
-
case 1:
|
|
44
|
-
_a.trys.push([1, 3, , 6]);
|
|
45
|
-
return [4, (0, axios_1.default)(url, args)];
|
|
46
|
-
case 2: return [2, (_a.sent()).data];
|
|
47
|
-
case 3:
|
|
48
|
-
err_1 = _a.sent();
|
|
49
|
-
errMsg = axios_1.default.isAxiosError(err_1) || err_1 instanceof Error ? err_1.message : "unknown error";
|
|
50
|
-
errs.push(errMsg);
|
|
51
|
-
if (!(++tries <= retries)) return [3, 5];
|
|
52
|
-
return [4, sleep(Math.pow(1.5, tries) * 1000)];
|
|
53
|
-
case 4:
|
|
54
|
-
_a.sent();
|
|
55
|
-
_a.label = 5;
|
|
56
|
-
case 5: return [3, 6];
|
|
57
|
-
case 6:
|
|
58
|
-
if (tries <= retries) return [3, 1];
|
|
59
|
-
_a.label = 7;
|
|
60
|
-
case 7: throw new Error("".concat(name, " retrieval failure (").concat(errs.join(", "), ")"));
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
exports.fetch = fetch;
|
|
66
|
-
//# sourceMappingURL=util.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/addressAggregator/adapters/util.ts"],"names":[],"mappings":";;;;AAAA,wDAA0B;AAG1B,qCAAqC;AAA5B,+FAAA,MAAM,OAAA;AAEP,IAAA,KAA0C,OAAO,CAAC,GAAG,kBAAhB,EAArC,iBAAiB,mBAAG,iBAAiB,KAAA,CAAiB;AAE9D,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,UAAC,CAAC,IAAK,OAAA,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,EAAjB,CAAiB,CAAC,CAAC;AAC/C,CAAC;AAED,SAAgB,QAAQ,CAAC,IAAY,EAAE,KAAc,EAAE,MAAe;IACpE,IAAI,MAAc,CAAC;IACnB,IAAI,KAAK,YAAY,KAAK,EAAE;QAC1B,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC;KACxB;SAAM;QACL,MAAM,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,eAAe,CAAC;KAC9D;IAED,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,CAAC;QACX,EAAE,EAAE,UAAG,IAAI,aAAU;QACrB,OAAO,EAAE,wCAAiC,IAAI,MAAG;QACjD,MAAM,QAAA;KACP,CAAC,CAAC;IACH,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AAC7B,CAAC;AAdD,4BAcC;AAED,SAAsB,KAAK,CAAC,IAAY,EAAE,GAAW,EAAE,OAAc,EAAE,OAAW;IAA3B,wBAAA,EAAA,cAAc;IAAE,wBAAA,EAAA,WAAW;;;;;;oBAC1E,IAAI,GAAG;wBACX,OAAO,EAAE,EAAE,YAAY,EAAE,iBAAiB,EAAE;wBAC5C,OAAO,SAAA;qBACR,CAAC;oBAEI,IAAI,GAAa,EAAE,CAAC;oBACtB,KAAK,GAAG,CAAC,CAAC;;;;oBAGF,WAAM,IAAA,eAAK,EAAC,GAAG,EAAE,IAAI,CAAC,EAAA;wBAA9B,WAAO,CAAC,SAAsB,CAAC,CAAC,IAAI,EAAC;;;oBAE/B,MAAM,GAAG,eAAK,CAAC,YAAY,CAAC,KAAG,CAAC,IAAI,KAAG,YAAY,KAAK,CAAC,CAAC,CAAC,KAAG,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;oBAC/F,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;yBACd,CAAA,EAAE,KAAK,IAAI,OAAO,CAAA,EAAlB,cAAkB;oBAAE,WAAM,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC,EAAA;;oBAAxC,SAAwC,CAAC;;;;wBAE5D,KAAK,IAAI,OAAO;;wBAEzB,MAAM,IAAI,KAAK,CAAC,UAAG,IAAI,iCAAuB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAG,CAAC,CAAC;;;;CACnE;AAnBD,sBAmBC"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { Logger } from "../../utils";
|
|
2
|
-
export { Logger } from "../../utils";
|
|
3
|
-
export declare function logError(name: string, error: unknown, logger?: Logger): Promise<string[]>;
|
|
4
|
-
export declare function fetch(name: string, url: string, timeout?: number, retries?: number): Promise<unknown>;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { __awaiter, __generator } from "tslib";
|
|
2
|
-
import axios from "axios";
|
|
3
|
-
export { Logger } from "../../utils";
|
|
4
|
-
var _a = process.env.ACROSS_USER_AGENT, ACROSS_USER_AGENT = _a === void 0 ? "across-protocol" : _a;
|
|
5
|
-
function sleep(ms) {
|
|
6
|
-
return new Promise(function (r) { return setTimeout(r, ms); });
|
|
7
|
-
}
|
|
8
|
-
export function logError(name, error, logger) {
|
|
9
|
-
var reason;
|
|
10
|
-
if (error instanceof Error) {
|
|
11
|
-
reason = error.message;
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
reason = typeof error === "string" ? error : "unknown error";
|
|
15
|
-
}
|
|
16
|
-
logger === null || logger === void 0 ? void 0 : logger.warn({
|
|
17
|
-
at: "".concat(name, "::update"),
|
|
18
|
-
message: "Failed to read addresses from ".concat(name, "."),
|
|
19
|
-
reason: reason,
|
|
20
|
-
});
|
|
21
|
-
return Promise.resolve([]);
|
|
22
|
-
}
|
|
23
|
-
export function fetch(name, url, timeout, retries) {
|
|
24
|
-
if (timeout === void 0) { timeout = 2000; }
|
|
25
|
-
if (retries === void 0) { retries = 1; }
|
|
26
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
27
|
-
var args, errs, tries, err_1, errMsg;
|
|
28
|
-
return __generator(this, function (_a) {
|
|
29
|
-
switch (_a.label) {
|
|
30
|
-
case 0:
|
|
31
|
-
args = {
|
|
32
|
-
headers: { "User-Agent": ACROSS_USER_AGENT },
|
|
33
|
-
timeout: timeout,
|
|
34
|
-
};
|
|
35
|
-
errs = [];
|
|
36
|
-
tries = 0;
|
|
37
|
-
_a.label = 1;
|
|
38
|
-
case 1:
|
|
39
|
-
_a.trys.push([1, 3, , 6]);
|
|
40
|
-
return [4 /*yield*/, axios(url, args)];
|
|
41
|
-
case 2: return [2 /*return*/, (_a.sent()).data];
|
|
42
|
-
case 3:
|
|
43
|
-
err_1 = _a.sent();
|
|
44
|
-
errMsg = axios.isAxiosError(err_1) || err_1 instanceof Error ? err_1.message : "unknown error";
|
|
45
|
-
errs.push(errMsg);
|
|
46
|
-
if (!(++tries <= retries)) return [3 /*break*/, 5];
|
|
47
|
-
return [4 /*yield*/, sleep(Math.pow(1.5, tries) * 1000)];
|
|
48
|
-
case 4:
|
|
49
|
-
_a.sent(); // simple backoff
|
|
50
|
-
_a.label = 5;
|
|
51
|
-
case 5: return [3 /*break*/, 6];
|
|
52
|
-
case 6:
|
|
53
|
-
if (tries <= retries) return [3 /*break*/, 1];
|
|
54
|
-
_a.label = 7;
|
|
55
|
-
case 7: throw new Error("".concat(name, " retrieval failure (").concat(errs.join(", "), ")"));
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=util.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/addressAggregator/adapters/util.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE7B,IAAA,KAA0C,OAAO,CAAC,GAAG,kBAAhB,EAArC,iBAAiB,mBAAG,iBAAiB,KAAA,CAAiB;AAE9D,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,UAAC,CAAC,IAAK,OAAA,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,EAAjB,CAAiB,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,KAAc,EAAE,MAAe;IACpE,IAAI,MAAc,CAAC;IACnB,IAAI,KAAK,YAAY,KAAK,EAAE;QAC1B,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC;KACxB;SAAM;QACL,MAAM,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,eAAe,CAAC;KAC9D;IAED,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,CAAC;QACX,EAAE,EAAE,UAAG,IAAI,aAAU;QACrB,OAAO,EAAE,wCAAiC,IAAI,MAAG;QACjD,MAAM,QAAA;KACP,CAAC,CAAC;IACH,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAgB,KAAK,CAAC,IAAY,EAAE,GAAW,EAAE,OAAc,EAAE,OAAW;IAA3B,wBAAA,EAAA,cAAc;IAAE,wBAAA,EAAA,WAAW;;;;;;oBAC1E,IAAI,GAAG;wBACX,OAAO,EAAE,EAAE,YAAY,EAAE,iBAAiB,EAAE;wBAC5C,OAAO,SAAA;qBACR,CAAC;oBAEI,IAAI,GAAa,EAAE,CAAC;oBACtB,KAAK,GAAG,CAAC,CAAC;;;;oBAGF,qBAAM,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,EAAA;wBAA9B,sBAAO,CAAC,SAAsB,CAAC,CAAC,IAAI,EAAC;;;oBAE/B,MAAM,GAAG,KAAK,CAAC,YAAY,CAAC,KAAG,CAAC,IAAI,KAAG,YAAY,KAAK,CAAC,CAAC,CAAC,KAAG,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;oBAC/F,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;yBACd,CAAA,EAAE,KAAK,IAAI,OAAO,CAAA,EAAlB,wBAAkB;oBAAE,qBAAM,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC,EAAA;;oBAAxC,SAAwC,CAAC,CAAC,iBAAiB;;;;wBAE9E,KAAK,IAAI,OAAO;;wBAEzB,MAAM,IAAI,KAAK,CAAC,UAAG,IAAI,iCAAuB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAG,CAAC,CAAC;;;;CACnE"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Logger } from "../../utils";
|
|
2
|
-
export { Logger } from "../../utils";
|
|
3
|
-
export declare function logError(name: string, error: unknown, logger?: Logger): Promise<string[]>;
|
|
4
|
-
export declare function fetch(name: string, url: string, timeout?: number, retries?: number): Promise<unknown>;
|
|
5
|
-
//# sourceMappingURL=util.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../../src/addressAggregator/adapters/util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAQrC,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAczF;AAED,wBAAsB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,SAAO,EAAE,OAAO,SAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAmBpG"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import { Logger } from "../../utils";
|
|
3
|
-
|
|
4
|
-
export { Logger } from "../../utils";
|
|
5
|
-
|
|
6
|
-
const { ACROSS_USER_AGENT = "across-protocol" } = process.env;
|
|
7
|
-
|
|
8
|
-
function sleep(ms: number): Promise<void> {
|
|
9
|
-
return new Promise((r) => setTimeout(r, ms));
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function logError(name: string, error: unknown, logger?: Logger): Promise<string[]> {
|
|
13
|
-
let reason: string;
|
|
14
|
-
if (error instanceof Error) {
|
|
15
|
-
reason = error.message;
|
|
16
|
-
} else {
|
|
17
|
-
reason = typeof error === "string" ? error : "unknown error";
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
logger?.warn({
|
|
21
|
-
at: `${name}::update`,
|
|
22
|
-
message: `Failed to read addresses from ${name}.`,
|
|
23
|
-
reason,
|
|
24
|
-
});
|
|
25
|
-
return Promise.resolve([]);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export async function fetch(name: string, url: string, timeout = 2000, retries = 1): Promise<unknown> {
|
|
29
|
-
const args = {
|
|
30
|
-
headers: { "User-Agent": ACROSS_USER_AGENT },
|
|
31
|
-
timeout,
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const errs: string[] = [];
|
|
35
|
-
let tries = 0;
|
|
36
|
-
do {
|
|
37
|
-
try {
|
|
38
|
-
return (await axios(url, args)).data;
|
|
39
|
-
} catch (err) {
|
|
40
|
-
const errMsg = axios.isAxiosError(err) || err instanceof Error ? err.message : "unknown error";
|
|
41
|
-
errs.push(errMsg);
|
|
42
|
-
if (++tries <= retries) await sleep(Math.pow(1.5, tries) * 1000); // simple backoff
|
|
43
|
-
}
|
|
44
|
-
} while (tries <= retries);
|
|
45
|
-
|
|
46
|
-
throw new Error(`${name} retrieval failure (${errs.join(", ")})`);
|
|
47
|
-
}
|