@lendasat/lendaswap-sdk-pure 0.2.21-1 → 0.2.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.
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +4 -1
- package/dist/api/client.js.map +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js.map +1 -1
- package/dist/version.d.ts +4 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/package.json +4 -1
- package/dist/price-feed.d.ts +0 -124
- package/dist/price-feed.d.ts.map +0 -1
- package/dist/price-feed.js +0 -178
- package/dist/price-feed.js.map +0 -1
- package/dist/src/api/client.d.ts +0 -31
- package/dist/src/api/client.d.ts.map +0 -1
- package/dist/src/api/client.js +0 -12
- package/dist/src/api/client.js.map +0 -1
- package/dist/src/arkade.d.ts +0 -36
- package/dist/src/arkade.d.ts.map +0 -1
- package/dist/src/arkade.js +0 -68
- package/dist/src/arkade.js.map +0 -1
- package/dist/src/client.d.ts +0 -760
- package/dist/src/client.d.ts.map +0 -1
- package/dist/src/client.js +0 -2169
- package/dist/src/client.js.map +0 -1
- package/dist/src/create/arkade.d.ts +0 -34
- package/dist/src/create/arkade.d.ts.map +0 -1
- package/dist/src/create/arkade.js +0 -76
- package/dist/src/create/arkade.js.map +0 -1
- package/dist/src/create/bitcoin-to-arkade.d.ts +0 -36
- package/dist/src/create/bitcoin-to-arkade.d.ts.map +0 -1
- package/dist/src/create/bitcoin-to-arkade.js +0 -69
- package/dist/src/create/bitcoin-to-arkade.js.map +0 -1
- package/dist/src/create/bitcoin.d.ts +0 -31
- package/dist/src/create/bitcoin.d.ts.map +0 -1
- package/dist/src/create/bitcoin.js +0 -67
- package/dist/src/create/bitcoin.js.map +0 -1
- package/dist/src/create/evm-to-arkade.d.ts +0 -34
- package/dist/src/create/evm-to-arkade.d.ts.map +0 -1
- package/dist/src/create/evm-to-arkade.js +0 -69
- package/dist/src/create/evm-to-arkade.js.map +0 -1
- package/dist/src/create/evm-to-bitcoin.d.ts +0 -35
- package/dist/src/create/evm-to-bitcoin.d.ts.map +0 -1
- package/dist/src/create/evm-to-bitcoin.js +0 -71
- package/dist/src/create/evm-to-bitcoin.js.map +0 -1
- package/dist/src/create/evm-to-lightning.d.ts +0 -34
- package/dist/src/create/evm-to-lightning.d.ts.map +0 -1
- package/dist/src/create/evm-to-lightning.js +0 -66
- package/dist/src/create/evm-to-lightning.js.map +0 -1
- package/dist/src/create/index.d.ts +0 -19
- package/dist/src/create/index.d.ts.map +0 -1
- package/dist/src/create/index.js +0 -18
- package/dist/src/create/index.js.map +0 -1
- package/dist/src/create/lightning.d.ts +0 -31
- package/dist/src/create/lightning.d.ts.map +0 -1
- package/dist/src/create/lightning.js +0 -72
- package/dist/src/create/lightning.js.map +0 -1
- package/dist/src/create/types.d.ts +0 -247
- package/dist/src/create/types.d.ts.map +0 -1
- package/dist/src/create/types.js +0 -5
- package/dist/src/create/types.js.map +0 -1
- package/dist/src/delegate.d.ts +0 -62
- package/dist/src/delegate.d.ts.map +0 -1
- package/dist/src/delegate.js +0 -284
- package/dist/src/delegate.js.map +0 -1
- package/dist/src/esplora.d.ts +0 -41
- package/dist/src/esplora.d.ts.map +0 -1
- package/dist/src/esplora.js +0 -47
- package/dist/src/esplora.js.map +0 -1
- package/dist/src/evm/coordinator.d.ts +0 -247
- package/dist/src/evm/coordinator.d.ts.map +0 -1
- package/dist/src/evm/coordinator.js +0 -414
- package/dist/src/evm/coordinator.js.map +0 -1
- package/dist/src/evm/htlc.d.ts +0 -238
- package/dist/src/evm/htlc.d.ts.map +0 -1
- package/dist/src/evm/htlc.js +0 -278
- package/dist/src/evm/htlc.js.map +0 -1
- package/dist/src/evm/index.d.ts +0 -9
- package/dist/src/evm/index.d.ts.map +0 -1
- package/dist/src/evm/index.js +0 -9
- package/dist/src/evm/index.js.map +0 -1
- package/dist/src/evm/signing.d.ts +0 -30
- package/dist/src/evm/signing.d.ts.map +0 -1
- package/dist/src/evm/signing.js +0 -91
- package/dist/src/evm/signing.js.map +0 -1
- package/dist/src/generated/api.d.ts +0 -2736
- package/dist/src/generated/api.d.ts.map +0 -1
- package/dist/src/generated/api.js +0 -6
- package/dist/src/generated/api.js.map +0 -1
- package/dist/src/index.d.ts +0 -18
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -24
- package/dist/src/index.js.map +0 -1
- package/dist/src/node.d.ts +0 -19
- package/dist/src/node.d.ts.map +0 -1
- package/dist/src/node.js +0 -19
- package/dist/src/node.js.map +0 -1
- package/dist/src/price-calculations.d.ts +0 -109
- package/dist/src/price-calculations.d.ts.map +0 -1
- package/dist/src/price-calculations.js +0 -135
- package/dist/src/price-calculations.js.map +0 -1
- package/dist/src/redeem/arkade.d.ts +0 -65
- package/dist/src/redeem/arkade.d.ts.map +0 -1
- package/dist/src/redeem/arkade.js +0 -217
- package/dist/src/redeem/arkade.js.map +0 -1
- package/dist/src/redeem/ethereum.d.ts +0 -52
- package/dist/src/redeem/ethereum.d.ts.map +0 -1
- package/dist/src/redeem/ethereum.js +0 -206
- package/dist/src/redeem/ethereum.js.map +0 -1
- package/dist/src/redeem/gasless.d.ts +0 -41
- package/dist/src/redeem/gasless.d.ts.map +0 -1
- package/dist/src/redeem/gasless.js +0 -71
- package/dist/src/redeem/gasless.js.map +0 -1
- package/dist/src/redeem/index.d.ts +0 -49
- package/dist/src/redeem/index.d.ts.map +0 -1
- package/dist/src/redeem/index.js +0 -189
- package/dist/src/redeem/index.js.map +0 -1
- package/dist/src/redeem/types.d.ts +0 -126
- package/dist/src/redeem/types.d.ts.map +0 -1
- package/dist/src/redeem/types.js +0 -36
- package/dist/src/redeem/types.js.map +0 -1
- package/dist/src/refund/arkade.d.ts +0 -62
- package/dist/src/refund/arkade.d.ts.map +0 -1
- package/dist/src/refund/arkade.js +0 -212
- package/dist/src/refund/arkade.js.map +0 -1
- package/dist/src/refund/index.d.ts +0 -10
- package/dist/src/refund/index.d.ts.map +0 -1
- package/dist/src/refund/index.js +0 -10
- package/dist/src/refund/index.js.map +0 -1
- package/dist/src/refund/onchain.d.ts +0 -137
- package/dist/src/refund/onchain.d.ts.map +0 -1
- package/dist/src/refund/onchain.js +0 -366
- package/dist/src/refund/onchain.js.map +0 -1
- package/dist/src/signer/index.d.ts +0 -106
- package/dist/src/signer/index.d.ts.map +0 -1
- package/dist/src/signer/index.js +0 -179
- package/dist/src/signer/index.js.map +0 -1
- package/dist/src/storage/idb.d.ts +0 -70
- package/dist/src/storage/idb.d.ts.map +0 -1
- package/dist/src/storage/idb.js +0 -236
- package/dist/src/storage/idb.js.map +0 -1
- package/dist/src/storage/index.d.ts +0 -152
- package/dist/src/storage/index.d.ts.map +0 -1
- package/dist/src/storage/index.js +0 -98
- package/dist/src/storage/index.js.map +0 -1
- package/dist/src/storage/sqlite.d.ts +0 -95
- package/dist/src/storage/sqlite.d.ts.map +0 -1
- package/dist/src/storage/sqlite.js +0 -206
- package/dist/src/storage/sqlite.js.map +0 -1
- package/dist/src/storage/types.d.ts +0 -57
- package/dist/src/storage/types.d.ts.map +0 -1
- package/dist/src/storage/types.js +0 -9
- package/dist/src/storage/types.js.map +0 -1
- package/dist/src/tokens.d.ts +0 -29
- package/dist/src/tokens.d.ts.map +0 -1
- package/dist/src/tokens.js +0 -89
- package/dist/src/tokens.js.map +0 -1
- package/dist/src/usd-price.d.ts +0 -34
- package/dist/src/usd-price.d.ts.map +0 -1
- package/dist/src/usd-price.js +0 -83
- package/dist/src/usd-price.js.map +0 -1
- package/dist/tests/api-client.test.d.ts +0 -2
- package/dist/tests/api-client.test.d.ts.map +0 -1
- package/dist/tests/api-client.test.js +0 -86
- package/dist/tests/api-client.test.js.map +0 -1
- package/dist/tests/client.test.d.ts +0 -2
- package/dist/tests/client.test.d.ts.map +0 -1
- package/dist/tests/client.test.js +0 -150
- package/dist/tests/client.test.js.map +0 -1
- package/dist/tests/index.test.d.ts +0 -2
- package/dist/tests/index.test.d.ts.map +0 -1
- package/dist/tests/index.test.js +0 -8
- package/dist/tests/index.test.js.map +0 -1
- package/dist/tests/onchain-refund.test.d.ts +0 -2
- package/dist/tests/onchain-refund.test.d.ts.map +0 -1
- package/dist/tests/onchain-refund.test.js +0 -279
- package/dist/tests/onchain-refund.test.js.map +0 -1
- package/dist/tests/signer.test.d.ts +0 -2
- package/dist/tests/signer.test.d.ts.map +0 -1
- package/dist/tests/signer.test.js +0 -92
- package/dist/tests/signer.test.js.map +0 -1
- package/dist/tests/sqlite-storage.test.d.ts +0 -2
- package/dist/tests/sqlite-storage.test.d.ts.map +0 -1
- package/dist/tests/sqlite-storage.test.js +0 -160
- package/dist/tests/sqlite-storage.test.js.map +0 -1
- package/dist/tests/storage.test.d.ts +0 -2
- package/dist/tests/storage.test.d.ts.map +0 -1
- package/dist/tests/storage.test.js +0 -184
- package/dist/tests/storage.test.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/usdt0-bridge/bridge.d.ts +0 -82
- package/dist/usdt0-bridge/bridge.d.ts.map +0 -1
- package/dist/usdt0-bridge/bridge.js +0 -56
- package/dist/usdt0-bridge/bridge.js.map +0 -1
- package/dist/usdt0-bridge/chains.d.ts +0 -41
- package/dist/usdt0-bridge/chains.d.ts.map +0 -1
- package/dist/usdt0-bridge/chains.js +0 -117
- package/dist/usdt0-bridge/chains.js.map +0 -1
- package/dist/usdt0-bridge/layerzero-tracker.d.ts +0 -34
- package/dist/usdt0-bridge/layerzero-tracker.d.ts.map +0 -1
- package/dist/usdt0-bridge/layerzero-tracker.js +0 -86
- package/dist/usdt0-bridge/layerzero-tracker.js.map +0 -1
- package/dist/usdt0-bridge/oft-abi.d.ts +0 -145
- package/dist/usdt0-bridge/oft-abi.d.ts.map +0 -1
- package/dist/usdt0-bridge/oft-abi.js +0 -117
- package/dist/usdt0-bridge/oft-abi.js.map +0 -1
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTLCCoordinator contract utilities.
|
|
3
|
-
*
|
|
4
|
-
* Provides helpers for EIP-712 signing and encoding `redeemAndExecute` call data
|
|
5
|
-
* for the HTLCCoordinator contract used in Arkade-to-EVM swaps, and
|
|
6
|
-
* `executeAndCreate` / refund helpers for EVM-to-BTC coordinator swaps.
|
|
7
|
-
*/
|
|
8
|
-
/** A single call struct for the coordinator's calls array: (address target, uint256 value, bytes data) */
|
|
9
|
-
export interface CoordinatorCall {
|
|
10
|
-
/** Target contract address */
|
|
11
|
-
target: string;
|
|
12
|
-
/** ETH value to send (usually "0") */
|
|
13
|
-
value: bigint;
|
|
14
|
-
/** Encoded call data */
|
|
15
|
-
data: string;
|
|
16
|
-
}
|
|
17
|
-
/** Parameters for building the EIP-712 redeem digest */
|
|
18
|
-
export interface RedeemDigestParams {
|
|
19
|
-
/** HTLCErc20 contract address (verifyingContract) */
|
|
20
|
-
htlcAddress: string;
|
|
21
|
-
/** EVM chain ID */
|
|
22
|
-
chainId: number;
|
|
23
|
-
/** Preimage (32-byte hex with 0x prefix) */
|
|
24
|
-
preimage: string;
|
|
25
|
-
/** WBTC amount locked in the HTLC (in smallest unit) */
|
|
26
|
-
amount: bigint;
|
|
27
|
-
/** WBTC token address */
|
|
28
|
-
token: string;
|
|
29
|
-
/** HTLC sender (server's EVM address) */
|
|
30
|
-
sender: string;
|
|
31
|
-
/** HTLC timelock (unix timestamp) */
|
|
32
|
-
timelock: number;
|
|
33
|
-
/** Caller address (coordinator contract) */
|
|
34
|
-
caller: string;
|
|
35
|
-
/** Destination address where tokens are swept */
|
|
36
|
-
destination: string;
|
|
37
|
-
/** Token to sweep after calls (target token, or WBTC if no swap) */
|
|
38
|
-
sweepToken: string;
|
|
39
|
-
/** Minimum amount of sweepToken to receive (slippage protection) */
|
|
40
|
-
minAmountOut: bigint;
|
|
41
|
-
}
|
|
42
|
-
/** Parameters for encoding redeemAndExecute call data */
|
|
43
|
-
export interface RedeemAndExecuteParams {
|
|
44
|
-
/** Preimage (32-byte hex with 0x prefix) */
|
|
45
|
-
preimage: string;
|
|
46
|
-
/** WBTC amount locked in the HTLC */
|
|
47
|
-
amount: bigint;
|
|
48
|
-
/** WBTC token address */
|
|
49
|
-
token: string;
|
|
50
|
-
/** HTLC sender (server's EVM address) */
|
|
51
|
-
sender: string;
|
|
52
|
-
/** HTLC timelock */
|
|
53
|
-
timelock: number;
|
|
54
|
-
/** Array of calls to execute after redeem (approve + 1inch swap, or empty for WBTC) */
|
|
55
|
-
calls: CoordinatorCall[];
|
|
56
|
-
/** Token to sweep to the user after calls (target token, or WBTC if no swap) */
|
|
57
|
-
sweepToken: string;
|
|
58
|
-
/** Minimum amount of sweepToken to receive (slippage protection, 0 for no check) */
|
|
59
|
-
minAmountOut: bigint;
|
|
60
|
-
/** Destination address where tokens are swept */
|
|
61
|
-
destination: string;
|
|
62
|
-
/** EIP-712 signature v */
|
|
63
|
-
v: number;
|
|
64
|
-
/** EIP-712 signature r (32-byte hex with 0x prefix) */
|
|
65
|
-
r: string;
|
|
66
|
-
/** EIP-712 signature s (32-byte hex with 0x prefix) */
|
|
67
|
-
s: string;
|
|
68
|
-
}
|
|
69
|
-
/** Result of building redeemAndExecute call data */
|
|
70
|
-
export interface RedeemAndExecuteCallData {
|
|
71
|
-
/** The coordinator contract address */
|
|
72
|
-
to: string;
|
|
73
|
-
/** The encoded call data */
|
|
74
|
-
data: string;
|
|
75
|
-
/** Human-readable function signature */
|
|
76
|
-
functionSignature: string;
|
|
77
|
-
}
|
|
78
|
-
/** Parameters for encoding executeAndCreate call data */
|
|
79
|
-
export interface ExecuteAndCreateParams {
|
|
80
|
-
/** Array of calls to execute (approve + DEX swap) */
|
|
81
|
-
calls: CoordinatorCall[];
|
|
82
|
-
/** SHA256 hash of the preimage (32-byte hex with 0x prefix) */
|
|
83
|
-
preimageHash: string;
|
|
84
|
-
/** WBTC token address (token locked in the HTLC) */
|
|
85
|
-
token: string;
|
|
86
|
-
/** Claim address (server's EVM address that can claim) */
|
|
87
|
-
claimAddress: string;
|
|
88
|
-
/** HTLC timelock (unix timestamp) */
|
|
89
|
-
timelock: number;
|
|
90
|
-
}
|
|
91
|
-
/** Result of building executeAndCreate call data */
|
|
92
|
-
export interface ExecuteAndCreateCallData {
|
|
93
|
-
/** The coordinator contract address */
|
|
94
|
-
to: string;
|
|
95
|
-
/** The encoded call data */
|
|
96
|
-
data: string;
|
|
97
|
-
/** Human-readable function signature */
|
|
98
|
-
functionSignature: string;
|
|
99
|
-
}
|
|
100
|
-
/** Parameters for encoding refundAndExecute call data */
|
|
101
|
-
export interface RefundAndExecuteParams {
|
|
102
|
-
/** SHA256 hash of the preimage (32-byte hex with 0x prefix) */
|
|
103
|
-
preimageHash: string;
|
|
104
|
-
/** WBTC amount locked in the HTLC */
|
|
105
|
-
amount: bigint;
|
|
106
|
-
/** WBTC token address */
|
|
107
|
-
token: string;
|
|
108
|
-
/** Claim address (server's EVM address) */
|
|
109
|
-
claimAddress: string;
|
|
110
|
-
/** HTLC timelock (unix timestamp) */
|
|
111
|
-
timelock: number;
|
|
112
|
-
/** Array of calls to execute (approve + reverse DEX swap) */
|
|
113
|
-
calls: CoordinatorCall[];
|
|
114
|
-
/** Token to sweep after calls (source token) */
|
|
115
|
-
sweepToken: string;
|
|
116
|
-
/** Minimum amount of sweepToken to receive (slippage protection) */
|
|
117
|
-
minAmountOut: bigint;
|
|
118
|
-
}
|
|
119
|
-
/** Parameters for encoding refundTo call data */
|
|
120
|
-
export interface RefundToParams {
|
|
121
|
-
/** SHA256 hash of the preimage (32-byte hex with 0x prefix) */
|
|
122
|
-
preimageHash: string;
|
|
123
|
-
/** WBTC amount locked in the HTLC */
|
|
124
|
-
amount: bigint;
|
|
125
|
-
/** WBTC token address */
|
|
126
|
-
token: string;
|
|
127
|
-
/** Claim address (server's EVM address) */
|
|
128
|
-
claimAddress: string;
|
|
129
|
-
/** HTLC timelock (unix timestamp) */
|
|
130
|
-
timelock: number;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Computes keccak256 hash using @noble/hashes.
|
|
134
|
-
*
|
|
135
|
-
* @param input - Hex string (with or without 0x) or Uint8Array
|
|
136
|
-
* @returns 32-byte hex string with 0x prefix
|
|
137
|
-
*/
|
|
138
|
-
export declare function keccak256(input: string | Uint8Array): string;
|
|
139
|
-
/**
|
|
140
|
-
* Builds the EIP-712 digest that the user must sign to authorize
|
|
141
|
-
* the coordinator to call `HTLC.redeem` on their behalf.
|
|
142
|
-
*
|
|
143
|
-
* @param params - The redeem parameters
|
|
144
|
-
* @returns The 32-byte digest as hex string with 0x prefix
|
|
145
|
-
*
|
|
146
|
-
* @example
|
|
147
|
-
* ```ts
|
|
148
|
-
* const digest = buildRedeemDigest({
|
|
149
|
-
* htlcAddress: "0x...",
|
|
150
|
-
* chainId: 137,
|
|
151
|
-
* preimage: "0x...",
|
|
152
|
-
* amount: 100000n,
|
|
153
|
-
* token: "0x...", // WBTC
|
|
154
|
-
* sender: "0x...", // server
|
|
155
|
-
* timelock: 1700000000,
|
|
156
|
-
* caller: "0x...", // coordinator
|
|
157
|
-
* });
|
|
158
|
-
* // Sign `digest` with user's EVM wallet
|
|
159
|
-
* ```
|
|
160
|
-
*/
|
|
161
|
-
export declare function buildRedeemDigest(params: RedeemDigestParams): string;
|
|
162
|
-
/**
|
|
163
|
-
* Builds the calls array for `redeemAndExecute` based on 1inch calldata.
|
|
164
|
-
*
|
|
165
|
-
* - If `dexCallData` is provided: returns [approve WBTC to DEX, execute DEX swap]
|
|
166
|
-
* - If `dexCallData` is null/undefined (WBTC target): returns empty array
|
|
167
|
-
*
|
|
168
|
-
* @param wbtcAddress - WBTC token contract address
|
|
169
|
-
* @param amount - WBTC amount to approve
|
|
170
|
-
* @param dexCallData - DEX swap calldata from the creation response (optional)
|
|
171
|
-
* @returns Array of CoordinatorCall structs
|
|
172
|
-
*/
|
|
173
|
-
export declare function buildRedeemCalls(wbtcAddress: string, amount: bigint, dexCallData?: {
|
|
174
|
-
to: string;
|
|
175
|
-
data: string;
|
|
176
|
-
value: string;
|
|
177
|
-
} | null): CoordinatorCall[];
|
|
178
|
-
/**
|
|
179
|
-
* Encodes the call data for `coordinator.redeemAndExecute(...)`.
|
|
180
|
-
*
|
|
181
|
-
* @param coordinatorAddress - The HTLCCoordinator contract address
|
|
182
|
-
* @param params - All parameters for the call
|
|
183
|
-
* @returns The encoded call data
|
|
184
|
-
*
|
|
185
|
-
* @example
|
|
186
|
-
* ```ts
|
|
187
|
-
* const txData = encodeRedeemAndExecute("0xCoordinator...", {
|
|
188
|
-
* preimage: "0x...",
|
|
189
|
-
* amount: 100000n,
|
|
190
|
-
* token: "0xWBTC...",
|
|
191
|
-
* sender: "0xServer...",
|
|
192
|
-
* timelock: 1700000000,
|
|
193
|
-
* calls: buildRedeemCalls(wbtcAddr, amount, dexCallData),
|
|
194
|
-
* sweepToken: targetTokenAddr,
|
|
195
|
-
* minAmountOut: 0n,
|
|
196
|
-
* v: 27,
|
|
197
|
-
* r: "0x...",
|
|
198
|
-
* s: "0x...",
|
|
199
|
-
* });
|
|
200
|
-
* // Send transaction: { to: txData.to, data: txData.data }
|
|
201
|
-
* ```
|
|
202
|
-
*/
|
|
203
|
-
export declare function encodeRedeemAndExecute(coordinatorAddress: string, params: RedeemAndExecuteParams): RedeemAndExecuteCallData;
|
|
204
|
-
/**
|
|
205
|
-
* Builds the calls array for `executeAndCreate` — approve source token to DEX + execute swap.
|
|
206
|
-
*
|
|
207
|
-
* @param sourceToken - Source token contract address (e.g. USDC)
|
|
208
|
-
* @param sourceAmount - Amount of source token to approve
|
|
209
|
-
* @param dexCallData - DEX swap calldata (from 1inch)
|
|
210
|
-
* @returns Array of CoordinatorCall structs
|
|
211
|
-
*/
|
|
212
|
-
export declare function buildExecuteAndCreateCalls(sourceToken: string, sourceAmount: bigint, dexCallData: {
|
|
213
|
-
to: string;
|
|
214
|
-
data: string;
|
|
215
|
-
value?: string;
|
|
216
|
-
}): CoordinatorCall[];
|
|
217
|
-
/**
|
|
218
|
-
* Encodes the call data for `coordinator.executeAndCreate(...)`.
|
|
219
|
-
*
|
|
220
|
-
* Signature: executeAndCreate(Call[] calls, bytes32 preimageHash, address token, address claimAddress, uint256 timelock)
|
|
221
|
-
*
|
|
222
|
-
* @param coordinatorAddress - The HTLCCoordinator contract address
|
|
223
|
-
* @param params - All parameters for the call
|
|
224
|
-
* @returns The encoded call data
|
|
225
|
-
*/
|
|
226
|
-
export declare function encodeExecuteAndCreate(coordinatorAddress: string, params: ExecuteAndCreateParams): ExecuteAndCreateCallData;
|
|
227
|
-
/**
|
|
228
|
-
* Encodes the call data for `coordinator.refundAndExecute(...)`.
|
|
229
|
-
*
|
|
230
|
-
* Signature: refundAndExecute(bytes32 preimageHash, uint256 amount, address token, address claimAddress, uint256 timelock, Call[] calls, address sweepToken, uint256 minAmountOut)
|
|
231
|
-
*
|
|
232
|
-
* @param coordinatorAddress - The HTLCCoordinator contract address
|
|
233
|
-
* @param params - All parameters for the call
|
|
234
|
-
* @returns The encoded call data
|
|
235
|
-
*/
|
|
236
|
-
export declare function encodeRefundAndExecute(coordinatorAddress: string, params: RefundAndExecuteParams): ExecuteAndCreateCallData;
|
|
237
|
-
/**
|
|
238
|
-
* Encodes the call data for `coordinator.refundTo(...)`.
|
|
239
|
-
*
|
|
240
|
-
* Signature: refundTo(bytes32 preimageHash, uint256 amount, address token, address claimAddress, uint256 timelock)
|
|
241
|
-
*
|
|
242
|
-
* @param coordinatorAddress - The HTLCCoordinator contract address
|
|
243
|
-
* @param params - All parameters for the call
|
|
244
|
-
* @returns The encoded call data
|
|
245
|
-
*/
|
|
246
|
-
export declare function encodeRefundTo(coordinatorAddress: string, params: RefundToParams): ExecuteAndCreateCallData;
|
|
247
|
-
//# sourceMappingURL=coordinator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"coordinator.d.ts","sourceRoot":"","sources":["../../../src/evm/coordinator.ts"],"names":[],"mappings":"AAAA;;;;;;G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AQG;AACH,wBAAgB,cAAc,CAC5B,kBAAkB,EAAE,MAAM,EAC1B,MAAM,EAAE,cAAc,GACrB,wBAAwB,CAqB1B"}
|
|
@@ -1,414 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTLCCoordinator contract utilities.
|
|
3
|
-
*
|
|
4
|
-
* Provides helpers for EIP-712 signing and encoding `redeemAndExecute` call data
|
|
5
|
-
* for the HTLCCoordinator contract used in Arkade-to-EVM swaps, and
|
|
6
|
-
* `executeAndCreate` / refund helpers for EVM-to-BTC coordinator swaps.
|
|
7
|
-
*/
|
|
8
|
-
import { keccak_256 } from "@noble/hashes/sha3";
|
|
9
|
-
import { hexToBytes as nobleFromHex, bytesToHex as nobleToHex, } from "@noble/hashes/utils";
|
|
10
|
-
// ── EIP-712 constants ────────────────────────────────────────────────────────
|
|
11
|
-
// hardcoded so that we can potentially support multiple versions
|
|
12
|
-
const EIP712_DOMAIN_TYPEHASH = "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)";
|
|
13
|
-
const REDEEM_TYPEHASH = "Redeem(bytes32 preimage,uint256 amount,address token,address sender,uint256 timelock,address caller,address destination,address sweepToken,uint256 minAmountOut)";
|
|
14
|
-
const HTLC_NAME = "HTLCErc20";
|
|
15
|
-
const HTLC_VERSION = "2";
|
|
16
|
-
// ── redeemAndExecute selector ────────────────────────────────────────────────
|
|
17
|
-
// keccak256("redeemAndExecute(bytes32,uint256,address,address,uint256,(address,uint256,bytes)[],address,uint256,address,uint8,bytes32,bytes32)")
|
|
18
|
-
const REDEEM_AND_EXECUTE_SELECTOR = keccak256(stringToUtf8Bytes("redeemAndExecute(bytes32,uint256,address,address,uint256,(address,uint256,bytes)[],address,uint256,address,uint8,bytes32,bytes32)")).slice(0, 10);
|
|
19
|
-
// ── keccak256 ────────────────────────────────────────────────────────────────
|
|
20
|
-
/**
|
|
21
|
-
* Computes keccak256 hash using @noble/hashes.
|
|
22
|
-
*
|
|
23
|
-
* @param input - Hex string (with or without 0x) or Uint8Array
|
|
24
|
-
* @returns 32-byte hex string with 0x prefix
|
|
25
|
-
*/
|
|
26
|
-
export function keccak256(input) {
|
|
27
|
-
const data = typeof input === "string" ? hexToBytes(input) : input;
|
|
28
|
-
const hash = keccak_256(data);
|
|
29
|
-
return `0x${bytesToHex(hash)}`;
|
|
30
|
-
}
|
|
31
|
-
// ── EIP-712 digest ───────────────────────────────────────────────────────────
|
|
32
|
-
/**
|
|
33
|
-
* Builds the EIP-712 digest that the user must sign to authorize
|
|
34
|
-
* the coordinator to call `HTLC.redeem` on their behalf.
|
|
35
|
-
*
|
|
36
|
-
* @param params - The redeem parameters
|
|
37
|
-
* @returns The 32-byte digest as hex string with 0x prefix
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```ts
|
|
41
|
-
* const digest = buildRedeemDigest({
|
|
42
|
-
* htlcAddress: "0x...",
|
|
43
|
-
* chainId: 137,
|
|
44
|
-
* preimage: "0x...",
|
|
45
|
-
* amount: 100000n,
|
|
46
|
-
* token: "0x...", // WBTC
|
|
47
|
-
* sender: "0x...", // server
|
|
48
|
-
* timelock: 1700000000,
|
|
49
|
-
* caller: "0x...", // coordinator
|
|
50
|
-
* });
|
|
51
|
-
* // Sign `digest` with user's EVM wallet
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
export function buildRedeemDigest(params) {
|
|
55
|
-
console.log(params);
|
|
56
|
-
// Domain separator
|
|
57
|
-
const domainSeparator = keccak256(abiEncode([
|
|
58
|
-
{
|
|
59
|
-
type: "bytes32",
|
|
60
|
-
value: keccak256(stringToUtf8Bytes(EIP712_DOMAIN_TYPEHASH)),
|
|
61
|
-
},
|
|
62
|
-
{ type: "bytes32", value: keccak256(stringToUtf8Bytes(HTLC_NAME)) },
|
|
63
|
-
{ type: "bytes32", value: keccak256(stringToUtf8Bytes(HTLC_VERSION)) },
|
|
64
|
-
{ type: "uint256", value: BigInt(params.chainId) },
|
|
65
|
-
{ type: "address", value: params.htlcAddress },
|
|
66
|
-
]));
|
|
67
|
-
// Struct hash
|
|
68
|
-
const typeHash = keccak256(stringToUtf8Bytes(REDEEM_TYPEHASH));
|
|
69
|
-
const structHash = keccak256(abiEncode([
|
|
70
|
-
{ type: "bytes32", value: typeHash },
|
|
71
|
-
{ type: "bytes32", value: params.preimage },
|
|
72
|
-
{ type: "uint256", value: params.amount },
|
|
73
|
-
{ type: "address", value: params.token },
|
|
74
|
-
{ type: "address", value: params.sender },
|
|
75
|
-
{ type: "uint256", value: BigInt(params.timelock) },
|
|
76
|
-
{ type: "address", value: params.caller },
|
|
77
|
-
{ type: "address", value: params.destination },
|
|
78
|
-
{ type: "address", value: params.sweepToken },
|
|
79
|
-
{ type: "uint256", value: params.minAmountOut },
|
|
80
|
-
]));
|
|
81
|
-
// EIP-712 digest: \x19\x01 ‖ domainSeparator ‖ structHash
|
|
82
|
-
const prefix = new Uint8Array([0x19, 0x01]);
|
|
83
|
-
const domainBytes = hexToBytes(domainSeparator);
|
|
84
|
-
const structBytes = hexToBytes(structHash);
|
|
85
|
-
const message = new Uint8Array(prefix.length + domainBytes.length + structBytes.length);
|
|
86
|
-
message.set(prefix, 0);
|
|
87
|
-
message.set(domainBytes, prefix.length);
|
|
88
|
-
message.set(structBytes, prefix.length + domainBytes.length);
|
|
89
|
-
return keccak256(message);
|
|
90
|
-
}
|
|
91
|
-
// ── Calls builder ────────────────────────────────────────────────────────────
|
|
92
|
-
/**
|
|
93
|
-
* Builds the calls array for `redeemAndExecute` based on 1inch calldata.
|
|
94
|
-
*
|
|
95
|
-
* - If `dexCallData` is provided: returns [approve WBTC to DEX, execute DEX swap]
|
|
96
|
-
* - If `dexCallData` is null/undefined (WBTC target): returns empty array
|
|
97
|
-
*
|
|
98
|
-
* @param wbtcAddress - WBTC token contract address
|
|
99
|
-
* @param amount - WBTC amount to approve
|
|
100
|
-
* @param dexCallData - DEX swap calldata from the creation response (optional)
|
|
101
|
-
* @returns Array of CoordinatorCall structs
|
|
102
|
-
*/
|
|
103
|
-
export function buildRedeemCalls(wbtcAddress, amount, dexCallData) {
|
|
104
|
-
if (!dexCallData) {
|
|
105
|
-
return [];
|
|
106
|
-
}
|
|
107
|
-
// Build approve calldata: WBTC.approve(dex_router, amount)
|
|
108
|
-
const approveData = encodeApprove(dexCallData.to, amount);
|
|
109
|
-
return [
|
|
110
|
-
{
|
|
111
|
-
target: wbtcAddress,
|
|
112
|
-
value: 0n,
|
|
113
|
-
data: approveData,
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
target: dexCallData.to,
|
|
117
|
-
value: BigInt(dexCallData.value || "0"),
|
|
118
|
-
data: dexCallData.data,
|
|
119
|
-
},
|
|
120
|
-
];
|
|
121
|
-
}
|
|
122
|
-
// ── redeemAndExecute calldata ────────────────────────────────────────────────
|
|
123
|
-
/**
|
|
124
|
-
* Encodes the call data for `coordinator.redeemAndExecute(...)`.
|
|
125
|
-
*
|
|
126
|
-
* @param coordinatorAddress - The HTLCCoordinator contract address
|
|
127
|
-
* @param params - All parameters for the call
|
|
128
|
-
* @returns The encoded call data
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
* ```ts
|
|
132
|
-
* const txData = encodeRedeemAndExecute("0xCoordinator...", {
|
|
133
|
-
* preimage: "0x...",
|
|
134
|
-
* amount: 100000n,
|
|
135
|
-
* token: "0xWBTC...",
|
|
136
|
-
* sender: "0xServer...",
|
|
137
|
-
* timelock: 1700000000,
|
|
138
|
-
* calls: buildRedeemCalls(wbtcAddr, amount, dexCallData),
|
|
139
|
-
* sweepToken: targetTokenAddr,
|
|
140
|
-
* minAmountOut: 0n,
|
|
141
|
-
* v: 27,
|
|
142
|
-
* r: "0x...",
|
|
143
|
-
* s: "0x...",
|
|
144
|
-
* });
|
|
145
|
-
* // Send transaction: { to: txData.to, data: txData.data }
|
|
146
|
-
* ```
|
|
147
|
-
*/
|
|
148
|
-
export function encodeRedeemAndExecute(coordinatorAddress, params) {
|
|
149
|
-
// Fixed-length head: 12 slots of 32 bytes each
|
|
150
|
-
// preimage (bytes32), amount (uint256), token (address), sender (address),
|
|
151
|
-
// timelock (uint256), calls_offset (uint256), sweepToken (address),
|
|
152
|
-
// minAmountOut (uint256), destination (address), v (uint8), r (bytes32), s (bytes32)
|
|
153
|
-
const preimage = normalizeBytes32(params.preimage);
|
|
154
|
-
const amount = encodeUint256(params.amount);
|
|
155
|
-
const token = normalizeAddress(params.token);
|
|
156
|
-
const sender = normalizeAddress(params.sender);
|
|
157
|
-
const timelock = encodeUint256(BigInt(params.timelock));
|
|
158
|
-
// Calls is a dynamic type — offset points to where the array data starts.
|
|
159
|
-
// Head has 12 slots × 32 bytes = 384 = 0x180
|
|
160
|
-
const callsOffset = encodeUint256(12n * 32n);
|
|
161
|
-
const sweepToken = normalizeAddress(params.sweepToken);
|
|
162
|
-
const minAmountOut = encodeUint256(params.minAmountOut);
|
|
163
|
-
const destination = normalizeAddress(params.destination);
|
|
164
|
-
const v = encodeUint256(BigInt(params.v));
|
|
165
|
-
const r = normalizeBytes32(params.r);
|
|
166
|
-
const s = normalizeBytes32(params.s);
|
|
167
|
-
// Encode the calls array
|
|
168
|
-
const callsEncoded = encodeCalls(params.calls);
|
|
169
|
-
const data = [
|
|
170
|
-
REDEEM_AND_EXECUTE_SELECTOR,
|
|
171
|
-
preimage,
|
|
172
|
-
amount,
|
|
173
|
-
token,
|
|
174
|
-
sender,
|
|
175
|
-
timelock,
|
|
176
|
-
callsOffset,
|
|
177
|
-
sweepToken,
|
|
178
|
-
minAmountOut,
|
|
179
|
-
destination,
|
|
180
|
-
v,
|
|
181
|
-
r,
|
|
182
|
-
s,
|
|
183
|
-
callsEncoded,
|
|
184
|
-
].join("");
|
|
185
|
-
return {
|
|
186
|
-
to: coordinatorAddress,
|
|
187
|
-
data,
|
|
188
|
-
functionSignature: "redeemAndExecute(bytes32,uint256,address,address,uint256,(address,uint256,bytes)[],address,uint256,address,uint8,bytes32,bytes32)",
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
// ── executeAndCreate selector ────────────────────────────────────────────────
|
|
192
|
-
// keccak256("executeAndCreate((address,uint256,bytes)[],bytes32,address,address,uint256)")
|
|
193
|
-
const EXECUTE_AND_CREATE_SELECTOR = keccak256(stringToUtf8Bytes("executeAndCreate((address,uint256,bytes)[],bytes32,address,address,uint256)")).slice(0, 10);
|
|
194
|
-
// ── refundAndExecute selector ────────────────────────────────────────────────
|
|
195
|
-
// keccak256("refundAndExecute(bytes32,uint256,address,address,uint256,(address,uint256,bytes)[],address,uint256)")
|
|
196
|
-
const REFUND_AND_EXECUTE_SELECTOR = keccak256(stringToUtf8Bytes("refundAndExecute(bytes32,uint256,address,address,uint256,(address,uint256,bytes)[],address,uint256)")).slice(0, 10);
|
|
197
|
-
// ── refundTo selector ────────────────────────────────────────────────────────
|
|
198
|
-
// keccak256("refundTo(bytes32,uint256,address,address,uint256)")
|
|
199
|
-
const REFUND_TO_SELECTOR = keccak256(stringToUtf8Bytes("refundTo(bytes32,uint256,address,address,uint256)")).slice(0, 10);
|
|
200
|
-
// ── executeAndCreate calldata ────────────────────────────────────────────────
|
|
201
|
-
/**
|
|
202
|
-
* Builds the calls array for `executeAndCreate` — approve source token to DEX + execute swap.
|
|
203
|
-
*
|
|
204
|
-
* @param sourceToken - Source token contract address (e.g. USDC)
|
|
205
|
-
* @param sourceAmount - Amount of source token to approve
|
|
206
|
-
* @param dexCallData - DEX swap calldata (from 1inch)
|
|
207
|
-
* @returns Array of CoordinatorCall structs
|
|
208
|
-
*/
|
|
209
|
-
export function buildExecuteAndCreateCalls(sourceToken, sourceAmount, dexCallData) {
|
|
210
|
-
const approveData = encodeApprove(dexCallData.to, sourceAmount);
|
|
211
|
-
return [
|
|
212
|
-
{
|
|
213
|
-
target: sourceToken,
|
|
214
|
-
value: 0n,
|
|
215
|
-
data: approveData,
|
|
216
|
-
},
|
|
217
|
-
{
|
|
218
|
-
target: dexCallData.to,
|
|
219
|
-
value: BigInt(dexCallData.value || "0"),
|
|
220
|
-
data: dexCallData.data,
|
|
221
|
-
},
|
|
222
|
-
];
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Encodes the call data for `coordinator.executeAndCreate(...)`.
|
|
226
|
-
*
|
|
227
|
-
* Signature: executeAndCreate(Call[] calls, bytes32 preimageHash, address token, address claimAddress, uint256 timelock)
|
|
228
|
-
*
|
|
229
|
-
* @param coordinatorAddress - The HTLCCoordinator contract address
|
|
230
|
-
* @param params - All parameters for the call
|
|
231
|
-
* @returns The encoded call data
|
|
232
|
-
*/
|
|
233
|
-
export function encodeExecuteAndCreate(coordinatorAddress, params) {
|
|
234
|
-
// Head: calls_offset, preimageHash, token, claimAddress, timelock (5 slots)
|
|
235
|
-
const callsOffset = encodeUint256(5n * 32n);
|
|
236
|
-
const preimageHash = normalizeBytes32(params.preimageHash);
|
|
237
|
-
const token = normalizeAddress(params.token);
|
|
238
|
-
const claimAddress = normalizeAddress(params.claimAddress);
|
|
239
|
-
const timelock = encodeUint256(BigInt(params.timelock));
|
|
240
|
-
// Encode the calls array (tail)
|
|
241
|
-
const callsEncoded = encodeCalls(params.calls);
|
|
242
|
-
const data = [
|
|
243
|
-
EXECUTE_AND_CREATE_SELECTOR,
|
|
244
|
-
callsOffset,
|
|
245
|
-
preimageHash,
|
|
246
|
-
token,
|
|
247
|
-
claimAddress,
|
|
248
|
-
timelock,
|
|
249
|
-
callsEncoded,
|
|
250
|
-
].join("");
|
|
251
|
-
return {
|
|
252
|
-
to: coordinatorAddress,
|
|
253
|
-
data,
|
|
254
|
-
functionSignature: "executeAndCreate((address,uint256,bytes)[],bytes32,address,address,uint256)",
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Encodes the call data for `coordinator.refundAndExecute(...)`.
|
|
259
|
-
*
|
|
260
|
-
* Signature: refundAndExecute(bytes32 preimageHash, uint256 amount, address token, address claimAddress, uint256 timelock, Call[] calls, address sweepToken, uint256 minAmountOut)
|
|
261
|
-
*
|
|
262
|
-
* @param coordinatorAddress - The HTLCCoordinator contract address
|
|
263
|
-
* @param params - All parameters for the call
|
|
264
|
-
* @returns The encoded call data
|
|
265
|
-
*/
|
|
266
|
-
export function encodeRefundAndExecute(coordinatorAddress, params) {
|
|
267
|
-
// Head: preimageHash, amount, token, claimAddress, timelock, calls_offset, sweepToken, minAmountOut (8 slots)
|
|
268
|
-
const preimageHash = normalizeBytes32(params.preimageHash);
|
|
269
|
-
const amount = encodeUint256(params.amount);
|
|
270
|
-
const token = normalizeAddress(params.token);
|
|
271
|
-
const claimAddress = normalizeAddress(params.claimAddress);
|
|
272
|
-
const timelock = encodeUint256(BigInt(params.timelock));
|
|
273
|
-
const callsOffset = encodeUint256(8n * 32n);
|
|
274
|
-
const sweepToken = normalizeAddress(params.sweepToken);
|
|
275
|
-
const minAmountOut = encodeUint256(params.minAmountOut);
|
|
276
|
-
// Encode the calls array (tail)
|
|
277
|
-
const callsEncoded = encodeCalls(params.calls);
|
|
278
|
-
const data = [
|
|
279
|
-
REFUND_AND_EXECUTE_SELECTOR,
|
|
280
|
-
preimageHash,
|
|
281
|
-
amount,
|
|
282
|
-
token,
|
|
283
|
-
claimAddress,
|
|
284
|
-
timelock,
|
|
285
|
-
callsOffset,
|
|
286
|
-
sweepToken,
|
|
287
|
-
minAmountOut,
|
|
288
|
-
callsEncoded,
|
|
289
|
-
].join("");
|
|
290
|
-
return {
|
|
291
|
-
to: coordinatorAddress,
|
|
292
|
-
data,
|
|
293
|
-
functionSignature: "refundAndExecute(bytes32,uint256,address,address,uint256,(address,uint256,bytes)[],address,uint256)",
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Encodes the call data for `coordinator.refundTo(...)`.
|
|
298
|
-
*
|
|
299
|
-
* Signature: refundTo(bytes32 preimageHash, uint256 amount, address token, address claimAddress, uint256 timelock)
|
|
300
|
-
*
|
|
301
|
-
* @param coordinatorAddress - The HTLCCoordinator contract address
|
|
302
|
-
* @param params - All parameters for the call
|
|
303
|
-
* @returns The encoded call data
|
|
304
|
-
*/
|
|
305
|
-
export function encodeRefundTo(coordinatorAddress, params) {
|
|
306
|
-
const preimageHash = normalizeBytes32(params.preimageHash);
|
|
307
|
-
const amount = encodeUint256(params.amount);
|
|
308
|
-
const token = normalizeAddress(params.token);
|
|
309
|
-
const claimAddress = normalizeAddress(params.claimAddress);
|
|
310
|
-
const timelock = encodeUint256(BigInt(params.timelock));
|
|
311
|
-
const data = [
|
|
312
|
-
REFUND_TO_SELECTOR,
|
|
313
|
-
preimageHash,
|
|
314
|
-
amount,
|
|
315
|
-
token,
|
|
316
|
-
claimAddress,
|
|
317
|
-
timelock,
|
|
318
|
-
].join("");
|
|
319
|
-
return {
|
|
320
|
-
to: coordinatorAddress,
|
|
321
|
-
data,
|
|
322
|
-
functionSignature: "refundTo(bytes32,uint256,address,address,uint256)",
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
// ── Internal encoding helpers ────────────────────────────────────────────────
|
|
326
|
-
/** Encode ERC20 approve(address,uint256) call data */
|
|
327
|
-
function encodeApprove(spender, amount) {
|
|
328
|
-
const selector = "0x095ea7b3";
|
|
329
|
-
return `${selector}${normalizeAddress(spender)}${encodeUint256(amount)}`;
|
|
330
|
-
}
|
|
331
|
-
/** Encode the dynamic (address,uint256,bytes)[] array for ABI */
|
|
332
|
-
function encodeCalls(calls) {
|
|
333
|
-
// Array length
|
|
334
|
-
const length = encodeUint256(BigInt(calls.length));
|
|
335
|
-
if (calls.length === 0) {
|
|
336
|
-
return length;
|
|
337
|
-
}
|
|
338
|
-
// Each element is a tuple (address, uint256, bytes) — a dynamic type.
|
|
339
|
-
// We encode offsets first, then each element's data.
|
|
340
|
-
// Calculate offsets: each element offset is relative to the start of the array data
|
|
341
|
-
// (after the length word). First we have N offset words, then the actual data.
|
|
342
|
-
const elementDataParts = [];
|
|
343
|
-
const offsets = [];
|
|
344
|
-
// First pass: encode each element and compute sizes
|
|
345
|
-
for (const call of calls) {
|
|
346
|
-
const encoded = encodeSingleCall(call);
|
|
347
|
-
elementDataParts.push(encoded);
|
|
348
|
-
}
|
|
349
|
-
// Compute offsets: offset[0] = N * 32, offset[i] = offset[i-1] + size(element[i-1])
|
|
350
|
-
let currentOffset = BigInt(calls.length) * 32n;
|
|
351
|
-
for (let i = 0; i < calls.length; i++) {
|
|
352
|
-
offsets.push(currentOffset);
|
|
353
|
-
// Each encoded element is hex chars / 2 = bytes
|
|
354
|
-
currentOffset += BigInt(elementDataParts[i].length / 2);
|
|
355
|
-
}
|
|
356
|
-
const offsetsEncoded = offsets.map((o) => encodeUint256(o)).join("");
|
|
357
|
-
const dataEncoded = elementDataParts.join("");
|
|
358
|
-
return length + offsetsEncoded + dataEncoded;
|
|
359
|
-
}
|
|
360
|
-
/** Encode a single (address, uint256, bytes) tuple */
|
|
361
|
-
function encodeSingleCall(call) {
|
|
362
|
-
const target = normalizeAddress(call.target);
|
|
363
|
-
const value = encodeUint256(call.value);
|
|
364
|
-
// bytes is dynamic: offset (32 bytes) + length (32 bytes) + padded data
|
|
365
|
-
const bytesOffset = encodeUint256(3n * 32n); // offset after target, value, and this offset word
|
|
366
|
-
const callData = call.data.startsWith("0x") ? call.data.slice(2) : call.data;
|
|
367
|
-
const dataLength = callData.length / 2;
|
|
368
|
-
const bytesLength = encodeUint256(BigInt(dataLength));
|
|
369
|
-
// Pad data to 32-byte boundary
|
|
370
|
-
const paddedLength = Math.ceil(dataLength / 32) * 32;
|
|
371
|
-
const paddedData = callData.padEnd(paddedLength * 2, "0");
|
|
372
|
-
return target + value + bytesOffset + bytesLength + paddedData;
|
|
373
|
-
}
|
|
374
|
-
function abiEncode(values) {
|
|
375
|
-
return values
|
|
376
|
-
.map((v) => {
|
|
377
|
-
switch (v.type) {
|
|
378
|
-
case "bytes32":
|
|
379
|
-
return normalizeBytes32(v.value);
|
|
380
|
-
case "uint256":
|
|
381
|
-
return encodeUint256(v.value);
|
|
382
|
-
case "address":
|
|
383
|
-
return normalizeAddress(v.value);
|
|
384
|
-
default:
|
|
385
|
-
throw new Error(`Unknown ABI type: ${v.type}`);
|
|
386
|
-
}
|
|
387
|
-
})
|
|
388
|
-
.join("");
|
|
389
|
-
}
|
|
390
|
-
function normalizeBytes32(value) {
|
|
391
|
-
let clean = value.replace(/^0x/, "");
|
|
392
|
-
if (clean.length < 64) {
|
|
393
|
-
clean = clean.padStart(64, "0");
|
|
394
|
-
}
|
|
395
|
-
return clean.toLowerCase().slice(0, 64);
|
|
396
|
-
}
|
|
397
|
-
function normalizeAddress(address) {
|
|
398
|
-
const clean = address.replace(/^0x/, "").toLowerCase();
|
|
399
|
-
return clean.padStart(64, "0");
|
|
400
|
-
}
|
|
401
|
-
function encodeUint256(value) {
|
|
402
|
-
return value.toString(16).padStart(64, "0");
|
|
403
|
-
}
|
|
404
|
-
// ── Hex / bytes utilities ────────────────────────────────────────────────────
|
|
405
|
-
function hexToBytes(hex) {
|
|
406
|
-
return nobleFromHex(hex.replace(/^0x/, ""));
|
|
407
|
-
}
|
|
408
|
-
function bytesToHex(bytes) {
|
|
409
|
-
return nobleToHex(bytes);
|
|
410
|
-
}
|
|
411
|
-
function stringToUtf8Bytes(str) {
|
|
412
|
-
return new TextEncoder().encode(str);
|
|
413
|
-
}
|
|
414
|
-
//# sourceMappingURL=coordinator.js.map
|