-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathsdk.ts
85 lines (81 loc) · 2.45 KB
/
sdk.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { BigNumber, providers } from "ethers";
import { BlockFinder } from "@across-protocol/sdk/dist/esm/utils/BlockUtils";
import { toAddress as _toAddress } from "@across-protocol/sdk/dist/esm/utils/AddressUtils";
export { isDefined } from "@across-protocol/sdk/dist/esm/utils/TypeGuards";
export { isContractDeployedToAddress } from "@across-protocol/sdk/dist/esm/utils/AddressUtils";
export {
bnUint256Max,
bnUint32Max,
bnZero,
} from "@across-protocol/sdk/dist/esm/utils/BigNumberUtils";
export { mapAsync } from "@across-protocol/sdk/dist/esm/utils/ArrayUtils";
export { getCurrentTime } from "@across-protocol/sdk/dist/esm/utils/TimeUtils";
export {
isBridgedUsdc,
isStablecoin,
} from "@across-protocol/sdk/dist/esm/utils/TokenUtils";
export {
BRIDGED_USDC_SYMBOLS,
ZERO_ADDRESS,
} from "@across-protocol/sdk/dist/esm/constants";
export {
toBytes32,
compareAddressesSimple,
toAddress,
} from "@across-protocol/sdk/dist/esm/utils/AddressUtils";
export {
getNativeTokenSymbol,
chainIsLens,
} from "@across-protocol/sdk/dist/esm/utils/NetworkUtils";
export {
getMulticall3,
getMulticallAddress,
} from "@across-protocol/sdk/dist/esm/utils/Multicall";
export function getUpdateV3DepositTypedData(
depositId: number,
originChainId: number,
updatedOutputAmount: BigNumber,
updatedRecipient: string,
updatedMessage: string
) {
return {
types: {
UpdateDepositDetails: [
{ name: "depositId", type: "uint256" },
{ name: "originChainId", type: "uint256" },
{ name: "updatedOutputAmount", type: "uint256" },
{ name: "updatedRecipient", type: "address" },
{ name: "updatedMessage", type: "bytes" },
],
},
primaryType: "UpdateDepositDetails",
domain: {
name: "ACROSS-V2",
version: "1.0.0",
chainId: originChainId,
},
message: {
depositId: BigNumber.from(depositId),
originChainId: originChainId,
updatedOutputAmount: updatedOutputAmount,
updatedRecipient: updatedRecipient,
updatedMessage: updatedMessage,
},
};
}
export async function getBlockForTimestamp(
provider: providers.JsonRpcProvider,
timestamp: number
) {
const blockFinder = new BlockFinder(provider);
const { number: blockNumberForTimestamp } =
await blockFinder.getBlockForTimestamp(timestamp);
return blockNumberForTimestamp;
}
export function toAddressSafe(address: string) {
try {
return _toAddress(address);
} catch (e) {
return address;
}
}