|
1 | | -import { utils as anchorUtils, BN, AnchorProvider } from "@coral-xyz/anchor"; |
2 | | -import { BigNumber, ethers } from "ethers"; |
| 1 | +import { BN } from "@coral-xyz/anchor"; |
3 | 2 | import { PublicKey } from "@solana/web3.js"; |
4 | 3 | import { MerkleTree } from "@uma/common"; |
5 | | -import { RelayerRefundLeafSolana, RelayerRefundLeafType } from "../../../src/types/svm"; |
| 4 | +import { BigNumber, ethers } from "ethers"; |
6 | 5 | import { relayerRefundHashFn } from "../../../src/svm"; |
| 6 | +import { RelayerRefundLeafSolana, RelayerRefundLeafType } from "../../../src/types/svm"; |
7 | 7 |
|
8 | 8 | export const requireEnv = (name: string): string => { |
9 | 9 | if (!process.env[name]) throw new Error(`Environment variable ${name} is not set`); |
10 | 10 | return process.env[name]; |
11 | 11 | }; |
12 | 12 |
|
13 | | -export const getSolanaChainId = (cluster: "devnet" | "mainnet"): BigNumber => { |
14 | | - return BigNumber.from( |
15 | | - BigInt(ethers.utils.keccak256(ethers.utils.toUtf8Bytes(`solana-${cluster}`))) & BigInt("0xFFFFFFFFFFFFFFFF") |
16 | | - ); |
17 | | -}; |
18 | | - |
19 | | -export const isSolanaDevnet = (provider: AnchorProvider): boolean => { |
20 | | - const solanaRpcEndpoint = provider.connection.rpcEndpoint; |
21 | | - if (solanaRpcEndpoint.includes("devnet")) return true; |
22 | | - else if (solanaRpcEndpoint.includes("mainnet")) return false; |
23 | | - else throw new Error(`Unsupported solanaCluster endpoint: ${solanaRpcEndpoint}`); |
24 | | -}; |
25 | | - |
26 | 13 | export const formatUsdc = (amount: BigNumber): string => { |
27 | 14 | return ethers.utils.formatUnits(amount, 6); |
28 | 15 | }; |
29 | 16 |
|
30 | | -export const fromBase58ToBytes32 = (input: string): string => { |
31 | | - const decodedBytes = anchorUtils.bytes.bs58.decode(input); |
32 | | - return "0x" + Buffer.from(decodedBytes).toString("hex"); |
33 | | -}; |
34 | | - |
35 | | -export const fromBytes32ToAddress = (input: string): string => { |
36 | | - // Remove the '0x' prefix if present |
37 | | - const hexString = input.startsWith("0x") ? input.slice(2) : input; |
38 | | - |
39 | | - // Ensure the input is 64 characters long (32 bytes) |
40 | | - if (hexString.length !== 64) { |
41 | | - throw new Error("Invalid bytes32 string"); |
42 | | - } |
43 | | - |
44 | | - // Get the last 40 characters (20 bytes) for the address |
45 | | - const address = hexString.slice(-40); |
46 | | - |
47 | | - return "0x" + address; |
48 | | -}; |
49 | | - |
50 | 17 | export function constructEmptyPoolRebalanceTree(chainId: BigNumber, groupIndex: number) { |
51 | 18 | const poolRebalanceLeaf = { |
52 | 19 | chainId, |
|
0 commit comments