@chainlink/ccip-sdk 0.0.0 → 0.90.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/LICENSE +21 -0
- package/README.md +109 -0
- package/dist/aptos/exec.d.ts +18 -0
- package/dist/aptos/exec.d.ts.map +1 -0
- package/dist/aptos/exec.js +55 -0
- package/dist/aptos/exec.js.map +1 -0
- package/dist/aptos/hasher.d.ts +11 -0
- package/dist/aptos/hasher.d.ts.map +1 -0
- package/dist/aptos/hasher.js +62 -0
- package/dist/aptos/hasher.js.map +1 -0
- package/dist/aptos/index.d.ts +92 -0
- package/dist/aptos/index.d.ts.map +1 -0
- package/dist/aptos/index.js +482 -0
- package/dist/aptos/index.js.map +1 -0
- package/dist/aptos/logs.d.ts +9 -0
- package/dist/aptos/logs.d.ts.map +1 -0
- package/dist/aptos/logs.js +167 -0
- package/dist/aptos/logs.js.map +1 -0
- package/dist/aptos/send.d.ts +11 -0
- package/dist/aptos/send.d.ts.map +1 -0
- package/dist/aptos/send.js +78 -0
- package/dist/aptos/send.js.map +1 -0
- package/dist/aptos/token.d.ts +4 -0
- package/dist/aptos/token.d.ts.map +1 -0
- package/dist/aptos/token.js +134 -0
- package/dist/aptos/token.js.map +1 -0
- package/dist/aptos/types.d.ts +78 -0
- package/dist/aptos/types.d.ts.map +1 -0
- package/dist/aptos/types.js +60 -0
- package/dist/aptos/types.js.map +1 -0
- package/dist/aptos/utils.d.ts +12 -0
- package/dist/aptos/utils.d.ts.map +1 -0
- package/dist/aptos/utils.js +15 -0
- package/dist/aptos/utils.js.map +1 -0
- package/dist/chain.d.ts +344 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +41 -0
- package/dist/chain.js.map +1 -0
- package/dist/commits.d.ts +25 -0
- package/dist/commits.d.ts.map +1 -0
- package/dist/commits.js +29 -0
- package/dist/commits.js.map +1 -0
- package/dist/evm/abi/BurnMintERC677Token.d.ts +602 -0
- package/dist/evm/abi/BurnMintERC677Token.d.ts.map +1 -0
- package/dist/evm/abi/BurnMintERC677Token.js +488 -0
- package/dist/evm/abi/BurnMintERC677Token.js.map +1 -0
- package/dist/evm/abi/CommitStore_1_2.d.ts +688 -0
- package/dist/evm/abi/CommitStore_1_2.d.ts.map +1 -0
- package/dist/evm/abi/CommitStore_1_2.js +638 -0
- package/dist/evm/abi/CommitStore_1_2.js.map +1 -0
- package/dist/evm/abi/CommitStore_1_5.d.ts +708 -0
- package/dist/evm/abi/CommitStore_1_5.d.ts.map +1 -0
- package/dist/evm/abi/CommitStore_1_5.js +675 -0
- package/dist/evm/abi/CommitStore_1_5.js.map +1 -0
- package/dist/evm/abi/FeeQuoter_1_6.d.ts +1770 -0
- package/dist/evm/abi/FeeQuoter_1_6.d.ts.map +1 -0
- package/dist/evm/abi/FeeQuoter_1_6.js +1904 -0
- package/dist/evm/abi/FeeQuoter_1_6.js.map +1 -0
- package/dist/evm/abi/LockReleaseTokenPool_1_5.d.ts +1116 -0
- package/dist/evm/abi/LockReleaseTokenPool_1_5.d.ts.map +1 -0
- package/dist/evm/abi/LockReleaseTokenPool_1_5.js +1096 -0
- package/dist/evm/abi/LockReleaseTokenPool_1_5.js.map +1 -0
- package/dist/evm/abi/LockReleaseTokenPool_1_5_1.d.ts +1306 -0
- package/dist/evm/abi/LockReleaseTokenPool_1_5_1.d.ts.map +1 -0
- package/dist/evm/abi/LockReleaseTokenPool_1_5_1.js +1278 -0
- package/dist/evm/abi/LockReleaseTokenPool_1_5_1.js.map +1 -0
- package/dist/evm/abi/LockReleaseTokenPool_1_6_1.d.ts +1290 -0
- package/dist/evm/abi/LockReleaseTokenPool_1_6_1.d.ts.map +1 -0
- package/dist/evm/abi/LockReleaseTokenPool_1_6_1.js +1288 -0
- package/dist/evm/abi/LockReleaseTokenPool_1_6_1.js.map +1 -0
- package/dist/evm/abi/OffRamp_1_2.d.ts +1217 -0
- package/dist/evm/abi/OffRamp_1_2.d.ts.map +1 -0
- package/dist/evm/abi/OffRamp_1_2.js +1204 -0
- package/dist/evm/abi/OffRamp_1_2.js.map +1 -0
- package/dist/evm/abi/OffRamp_1_5.d.ts +1271 -0
- package/dist/evm/abi/OffRamp_1_5.d.ts.map +1 -0
- package/dist/evm/abi/OffRamp_1_5.js +1273 -0
- package/dist/evm/abi/OffRamp_1_5.js.map +1 -0
- package/dist/evm/abi/OffRamp_1_6.d.ts +1472 -0
- package/dist/evm/abi/OffRamp_1_6.d.ts.map +1 -0
- package/dist/evm/abi/OffRamp_1_6.js +1529 -0
- package/dist/evm/abi/OffRamp_1_6.js.map +1 -0
- package/dist/evm/abi/OnRamp_1_2.d.ts +1391 -0
- package/dist/evm/abi/OnRamp_1_2.d.ts.map +1 -0
- package/dist/evm/abi/OnRamp_1_2.js +1343 -0
- package/dist/evm/abi/OnRamp_1_2.js.map +1 -0
- package/dist/evm/abi/OnRamp_1_5.d.ts +1443 -0
- package/dist/evm/abi/OnRamp_1_5.d.ts.map +1 -0
- package/dist/evm/abi/OnRamp_1_5.js +1427 -0
- package/dist/evm/abi/OnRamp_1_5.js.map +1 -0
- package/dist/evm/abi/OnRamp_1_6.d.ts +796 -0
- package/dist/evm/abi/OnRamp_1_6.d.ts.map +1 -0
- package/dist/evm/abi/OnRamp_1_6.js +880 -0
- package/dist/evm/abi/OnRamp_1_6.js.map +1 -0
- package/dist/evm/abi/Router.d.ts +541 -0
- package/dist/evm/abi/Router.d.ts.map +1 -0
- package/dist/evm/abi/Router.js +508 -0
- package/dist/evm/abi/Router.js.map +1 -0
- package/dist/evm/abi/TokenAdminRegistry_1_5.d.ts +373 -0
- package/dist/evm/abi/TokenAdminRegistry_1_5.d.ts.map +1 -0
- package/dist/evm/abi/TokenAdminRegistry_1_5.js +333 -0
- package/dist/evm/abi/TokenAdminRegistry_1_5.js.map +1 -0
- package/dist/evm/const.d.ts +27 -0
- package/dist/evm/const.d.ts.map +1 -0
- package/dist/evm/const.js +63 -0
- package/dist/evm/const.js.map +1 -0
- package/dist/evm/errors.d.ts +36 -0
- package/dist/evm/errors.d.ts.map +1 -0
- package/dist/evm/errors.js +192 -0
- package/dist/evm/errors.js.map +1 -0
- package/dist/evm/hasher.d.ts +5 -0
- package/dist/evm/hasher.d.ts.map +1 -0
- package/dist/evm/hasher.js +116 -0
- package/dist/evm/hasher.js.map +1 -0
- package/dist/evm/index.d.ts +121 -0
- package/dist/evm/index.d.ts.map +1 -0
- package/dist/evm/index.js +904 -0
- package/dist/evm/index.js.map +1 -0
- package/dist/evm/messages.d.ts +35 -0
- package/dist/evm/messages.d.ts.map +1 -0
- package/dist/evm/messages.js +11 -0
- package/dist/evm/messages.js.map +1 -0
- package/dist/evm/offchain.d.ts +16 -0
- package/dist/evm/offchain.d.ts.map +1 -0
- package/dist/evm/offchain.js +142 -0
- package/dist/evm/offchain.js.map +1 -0
- package/dist/execution.d.ts +80 -0
- package/dist/execution.d.ts.map +1 -0
- package/dist/execution.js +91 -0
- package/dist/execution.js.map +1 -0
- package/dist/extra-args.d.ts +45 -0
- package/dist/extra-args.d.ts.map +1 -0
- package/dist/extra-args.js +44 -0
- package/dist/extra-args.js.map +1 -0
- package/dist/gas.d.ts +27 -0
- package/dist/gas.d.ts.map +1 -0
- package/dist/gas.js +80 -0
- package/dist/gas.js.map +1 -0
- package/dist/hasher/common.d.ts +12 -0
- package/dist/hasher/common.d.ts.map +1 -0
- package/dist/hasher/common.js +19 -0
- package/dist/hasher/common.js.map +1 -0
- package/dist/hasher/hasher.d.ts +4 -0
- package/dist/hasher/hasher.d.ts.map +1 -0
- package/dist/hasher/hasher.js +11 -0
- package/dist/hasher/hasher.js.map +1 -0
- package/dist/hasher/index.d.ts +4 -0
- package/dist/hasher/index.d.ts.map +1 -0
- package/dist/hasher/index.js +4 -0
- package/dist/hasher/index.js.map +1 -0
- package/dist/hasher/merklemulti.d.ts +58 -0
- package/dist/hasher/merklemulti.d.ts.map +1 -0
- package/dist/hasher/merklemulti.js +257 -0
- package/dist/hasher/merklemulti.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/offchain.d.ts +20 -0
- package/dist/offchain.d.ts.map +1 -0
- package/dist/offchain.js +59 -0
- package/dist/offchain.js.map +1 -0
- package/dist/requests.d.ts +48 -0
- package/dist/requests.d.ts.map +1 -0
- package/dist/requests.js +286 -0
- package/dist/requests.js.map +1 -0
- package/dist/selectors.d.ts +9 -0
- package/dist/selectors.d.ts.map +1 -0
- package/dist/selectors.js +1330 -0
- package/dist/selectors.js.map +1 -0
- package/dist/solana/cleanup.d.ts +15 -0
- package/dist/solana/cleanup.d.ts.map +1 -0
- package/dist/solana/cleanup.js +159 -0
- package/dist/solana/cleanup.js.map +1 -0
- package/dist/solana/exec.d.ts +15 -0
- package/dist/solana/exec.d.ts.map +1 -0
- package/dist/solana/exec.js +417 -0
- package/dist/solana/exec.js.map +1 -0
- package/dist/solana/hasher.d.ts +4 -0
- package/dist/solana/hasher.d.ts.map +1 -0
- package/dist/solana/hasher.js +81 -0
- package/dist/solana/hasher.js.map +1 -0
- package/dist/solana/idl/1.6.0/BASE_TOKEN_POOL.d.ts +866 -0
- package/dist/solana/idl/1.6.0/BASE_TOKEN_POOL.d.ts.map +1 -0
- package/dist/solana/idl/1.6.0/BASE_TOKEN_POOL.js +866 -0
- package/dist/solana/idl/1.6.0/BASE_TOKEN_POOL.js.map +1 -0
- package/dist/solana/idl/1.6.0/BURN_MINT_TOKEN_POOL.d.ts +949 -0
- package/dist/solana/idl/1.6.0/BURN_MINT_TOKEN_POOL.d.ts.map +1 -0
- package/dist/solana/idl/1.6.0/BURN_MINT_TOKEN_POOL.js +949 -0
- package/dist/solana/idl/1.6.0/BURN_MINT_TOKEN_POOL.js.map +1 -0
- package/dist/solana/idl/1.6.0/CCIP_CCTP_TOKEN_POOL.d.ts +1374 -0
- package/dist/solana/idl/1.6.0/CCIP_CCTP_TOKEN_POOL.d.ts.map +1 -0
- package/dist/solana/idl/1.6.0/CCIP_CCTP_TOKEN_POOL.js +1374 -0
- package/dist/solana/idl/1.6.0/CCIP_CCTP_TOKEN_POOL.js.map +1 -0
- package/dist/solana/idl/1.6.0/CCIP_COMMON.d.ts +104 -0
- package/dist/solana/idl/1.6.0/CCIP_COMMON.d.ts.map +1 -0
- package/dist/solana/idl/1.6.0/CCIP_COMMON.js +104 -0
- package/dist/solana/idl/1.6.0/CCIP_COMMON.js.map +1 -0
- package/dist/solana/idl/1.6.0/CCIP_OFFRAMP.d.ts +2746 -0
- package/dist/solana/idl/1.6.0/CCIP_OFFRAMP.d.ts.map +1 -0
- package/dist/solana/idl/1.6.0/CCIP_OFFRAMP.js +2746 -0
- package/dist/solana/idl/1.6.0/CCIP_OFFRAMP.js.map +1 -0
- package/dist/solana/idl/1.6.0/CCIP_ROUTER.d.ts +2332 -0
- package/dist/solana/idl/1.6.0/CCIP_ROUTER.d.ts.map +1 -0
- package/dist/solana/idl/1.6.0/CCIP_ROUTER.js +2332 -0
- package/dist/solana/idl/1.6.0/CCIP_ROUTER.js.map +1 -0
- package/dist/solana/index.d.ts +205 -0
- package/dist/solana/index.d.ts.map +1 -0
- package/dist/solana/index.js +1085 -0
- package/dist/solana/index.js.map +1 -0
- package/dist/solana/offchain.d.ts +31 -0
- package/dist/solana/offchain.d.ts.map +1 -0
- package/dist/solana/offchain.js +152 -0
- package/dist/solana/offchain.js.map +1 -0
- package/dist/solana/patchBorsh.d.ts +2 -0
- package/dist/solana/patchBorsh.d.ts.map +1 -0
- package/dist/solana/patchBorsh.js +60 -0
- package/dist/solana/patchBorsh.js.map +1 -0
- package/dist/solana/send.d.ts +14 -0
- package/dist/solana/send.d.ts.map +1 -0
- package/dist/solana/send.js +272 -0
- package/dist/solana/send.js.map +1 -0
- package/dist/solana/types.d.ts +4 -0
- package/dist/solana/types.d.ts.map +1 -0
- package/dist/solana/types.js +2 -0
- package/dist/solana/types.js.map +1 -0
- package/dist/solana/utils.d.ts +58 -0
- package/dist/solana/utils.d.ts.map +1 -0
- package/dist/solana/utils.js +211 -0
- package/dist/solana/utils.js.map +1 -0
- package/dist/sui/hasher.d.ts +12 -0
- package/dist/sui/hasher.d.ts.map +1 -0
- package/dist/sui/hasher.js +63 -0
- package/dist/sui/hasher.js.map +1 -0
- package/dist/sui/index.d.ts +72 -0
- package/dist/sui/index.d.ts.map +1 -0
- package/dist/sui/index.js +128 -0
- package/dist/sui/index.js.map +1 -0
- package/dist/sui/types.d.ts +17 -0
- package/dist/sui/types.d.ts.map +1 -0
- package/dist/sui/types.js +17 -0
- package/dist/sui/types.js.map +1 -0
- package/dist/supported-chains.d.ts +5 -0
- package/dist/supported-chains.d.ts.map +1 -0
- package/dist/supported-chains.js +3 -0
- package/dist/supported-chains.js.map +1 -0
- package/dist/types.d.ts +118 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +11 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +117 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +336 -0
- package/dist/utils.js.map +1 -0
- package/package.json +66 -8
- package/src/aptos/exec.ts +69 -0
- package/src/aptos/hasher.ts +92 -0
- package/src/aptos/index.ts +660 -0
- package/src/aptos/logs.ts +210 -0
- package/src/aptos/send.ts +120 -0
- package/src/aptos/token.ts +150 -0
- package/src/aptos/types.ts +85 -0
- package/src/aptos/utils.ts +24 -0
- package/src/chain.ts +398 -0
- package/src/commits.ts +44 -0
- package/src/evm/abi/BurnMintERC677Token.ts +487 -0
- package/src/evm/abi/CommitStore_1_2.ts +637 -0
- package/src/evm/abi/CommitStore_1_5.ts +674 -0
- package/src/evm/abi/FeeQuoter_1_6.ts +1903 -0
- package/src/evm/abi/LockReleaseTokenPool_1_5.ts +1095 -0
- package/src/evm/abi/LockReleaseTokenPool_1_5_1.ts +1277 -0
- package/src/evm/abi/LockReleaseTokenPool_1_6_1.ts +1287 -0
- package/src/evm/abi/OffRamp_1_2.ts +1203 -0
- package/src/evm/abi/OffRamp_1_5.ts +1272 -0
- package/src/evm/abi/OffRamp_1_6.ts +1528 -0
- package/src/evm/abi/OnRamp_1_2.ts +1342 -0
- package/src/evm/abi/OnRamp_1_5.ts +1426 -0
- package/src/evm/abi/OnRamp_1_6.ts +879 -0
- package/src/evm/abi/Router.ts +507 -0
- package/src/evm/abi/TokenAdminRegistry_1_5.ts +332 -0
- package/src/evm/const.ts +69 -0
- package/src/evm/errors.ts +212 -0
- package/src/evm/hasher.ts +166 -0
- package/src/evm/index.ts +1262 -0
- package/src/evm/messages.ts +73 -0
- package/src/evm/offchain.ts +189 -0
- package/src/execution.ts +131 -0
- package/src/extra-args.ts +71 -0
- package/src/gas.ts +135 -0
- package/src/hasher/common.ts +23 -0
- package/src/hasher/hasher.ts +12 -0
- package/src/hasher/index.ts +3 -0
- package/src/hasher/merklemulti.ts +309 -0
- package/src/index.ts +51 -0
- package/src/offchain.ts +86 -0
- package/src/requests.ts +339 -0
- package/src/selectors.ts +1340 -0
- package/src/solana/cleanup.ts +216 -0
- package/src/solana/exec.ts +645 -0
- package/src/solana/hasher.ts +104 -0
- package/src/solana/idl/1.6.0/BASE_TOKEN_POOL.ts +1734 -0
- package/src/solana/idl/1.6.0/BURN_MINT_TOKEN_POOL.ts +1900 -0
- package/src/solana/idl/1.6.0/CCIP_CCTP_TOKEN_POOL.ts +2750 -0
- package/src/solana/idl/1.6.0/CCIP_COMMON.ts +210 -0
- package/src/solana/idl/1.6.0/CCIP_OFFRAMP.ts +5494 -0
- package/src/solana/idl/1.6.0/CCIP_ROUTER.ts +4671 -0
- package/src/solana/index.ts +1454 -0
- package/src/solana/offchain.ts +209 -0
- package/src/solana/patchBorsh.ts +67 -0
- package/src/solana/send.ts +436 -0
- package/src/solana/types.ts +6 -0
- package/src/solana/utils.ts +272 -0
- package/src/sui/hasher.ts +90 -0
- package/src/sui/index.ts +198 -0
- package/src/sui/types.ts +22 -0
- package/src/supported-chains.ts +4 -0
- package/src/types.ts +153 -0
- package/src/utils.ts +405 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gas.d.ts","sourceRoot":"","sources":["../src/gas.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,EAWf,MAAM,QAAQ,CAAA;AAGf,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAIvC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAE9C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAetC;;;;;;;;IAQI;AACJ,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,KAAK,EACb,IAAI,EAAE,QAAQ,EACd,OAAO,EAAE;IACP,IAAI,EAAE,IAAI,CAAA;IACV,OAAO,EAAE;QACP,MAAM,EAAE,MAAM,CAAA;QACd,QAAQ,EAAE,MAAM,CAAA;QAChB,IAAI,EAAE,SAAS,CAAA;QACf,YAAY,EAAE,SAAS;YACrB,iBAAiB,EAAE,MAAM,CAAA;YACzB,gBAAgB,EAAE,MAAM,CAAA;YACxB,MAAM,EAAE,MAAM,CAAA;SACf,EAAE,CAAA;KACJ,CAAA;CACF,mBA0EF"}
|
package/dist/gas.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Contract, FunctionFragment, concat, formatUnits, getNumber, hexlify, randomBytes, solidityPackedKeccak256, toBeHex, zeroPadValue, } from 'ethers';
|
|
2
|
+
import TokenABI from "./evm/abi/BurnMintERC677Token.js";
|
|
3
|
+
import RouterABI from "./evm/abi/Router.js";
|
|
4
|
+
import { defaultAbiCoder } from "./evm/const.js";
|
|
5
|
+
import { discoverOffRamp } from "./execution.js";
|
|
6
|
+
const BALANCES_SLOT = 0;
|
|
7
|
+
const ccipReceive = FunctionFragment.from({
|
|
8
|
+
type: 'function',
|
|
9
|
+
name: 'ccipReceive',
|
|
10
|
+
stateMutability: 'nonpayable',
|
|
11
|
+
inputs: RouterABI.find((v) => v.type === 'function' && v.name === 'routeMessage').inputs.slice(0, 1),
|
|
12
|
+
outputs: [],
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* Estimate CCIP gasLimit needed to execute a request on a contract receiver
|
|
16
|
+
*
|
|
17
|
+
* @param dest - Provider for the destination chain
|
|
18
|
+
* @param request - CCIP request info
|
|
19
|
+
* @param request.lane - Lane info
|
|
20
|
+
* @param request.message - Message info
|
|
21
|
+
* @returns estimated gasLimit as bigint
|
|
22
|
+
**/
|
|
23
|
+
export async function estimateExecGasForRequest(source, dest, request) {
|
|
24
|
+
const offRamp = await discoverOffRamp(source, dest, request.lane.onRamp);
|
|
25
|
+
const destRouter = await dest.getRouterForOffRamp(offRamp, request.lane.sourceChainSelector);
|
|
26
|
+
const destTokenAmounts = await Promise.all(request.message.tokenAmounts.map(async (ta) => {
|
|
27
|
+
if (!('destTokenAddress' in ta))
|
|
28
|
+
throw new Error('legacy <1.5 tokenPools not supported');
|
|
29
|
+
const [{ decimals: sourceDecimals }, { decimals: destDecimals }] = await Promise.all([
|
|
30
|
+
source
|
|
31
|
+
.getTokenForTokenPool(ta.sourcePoolAddress)
|
|
32
|
+
.then((token) => source.getTokenInfo(token)),
|
|
33
|
+
dest.getTokenInfo(ta.destTokenAddress),
|
|
34
|
+
]);
|
|
35
|
+
const destAmount = (ta.amount * 10n ** BigInt(destDecimals - sourceDecimals + 36)) / 10n ** 36n;
|
|
36
|
+
if (destAmount === 0n)
|
|
37
|
+
throw new Error(`not enough decimals=${destDecimals} for token=${ta.destTokenAddress} on dest=${dest.network.name} to express ${formatUnits(ta.amount, sourceDecimals)}`);
|
|
38
|
+
return { token: ta.destTokenAddress, amount: destAmount };
|
|
39
|
+
}));
|
|
40
|
+
const message = {
|
|
41
|
+
messageId: hexlify(randomBytes(32)),
|
|
42
|
+
sender: zeroPadValue(request.message.sender, 32),
|
|
43
|
+
data: hexlify(request.message.data),
|
|
44
|
+
sourceChainSelector: request.lane.sourceChainSelector,
|
|
45
|
+
destTokenAmounts,
|
|
46
|
+
};
|
|
47
|
+
// we need to override the state, increasing receiver's balance for each token, to simulate the
|
|
48
|
+
// state after tokens were transferred by the offRamp just before calling `ccipReceive`
|
|
49
|
+
const destAmounts = {};
|
|
50
|
+
const stateOverrides = {};
|
|
51
|
+
for (const { token, amount } of destTokenAmounts) {
|
|
52
|
+
if (!(token in destAmounts)) {
|
|
53
|
+
const tokenContract = new Contract(token, TokenABI, dest);
|
|
54
|
+
const currentBalance = await tokenContract.balanceOf(request.message.receiver);
|
|
55
|
+
destAmounts[token] = currentBalance;
|
|
56
|
+
}
|
|
57
|
+
destAmounts[token] += amount;
|
|
58
|
+
stateOverrides[token] = {
|
|
59
|
+
stateDiff: {
|
|
60
|
+
[solidityPackedKeccak256(['uint256', 'uint256'], [request.message.receiver, BALANCES_SLOT])]: toBeHex(destAmounts[token], 32),
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const calldata = concat([
|
|
65
|
+
ccipReceive.selector,
|
|
66
|
+
defaultAbiCoder.encode(ccipReceive.inputs, [message]),
|
|
67
|
+
]);
|
|
68
|
+
return (getNumber((await dest.provider.send('eth_estimateGas', [
|
|
69
|
+
{
|
|
70
|
+
from: destRouter,
|
|
71
|
+
to: request.message.receiver,
|
|
72
|
+
data: calldata,
|
|
73
|
+
},
|
|
74
|
+
'latest',
|
|
75
|
+
...(Object.keys(stateOverrides).length ? [stateOverrides] : []),
|
|
76
|
+
]))) -
|
|
77
|
+
(21_000 - 700) // 21k is the base gas cost for a transaction, 700 is the gas cost of the call
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=gas.js.map
|
package/dist/gas.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gas.js","sourceRoot":"","sources":["../src/gas.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EACR,gBAAgB,EAChB,MAAM,EACN,WAAW,EACX,SAAS,EACT,OAAO,EACP,W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AG,CAAC,CAAC,8EAA8E;KAC9F,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CCIPMessage, CCIPVersion } from '../types.ts';
|
|
2
|
+
export type LeafHasher<V extends CCIPVersion = CCIPVersion> = (message: CCIPMessage<V>) => string;
|
|
3
|
+
export declare const LEAF_DOMAIN_SEPARATOR = "0x00";
|
|
4
|
+
export declare const ZERO_HASH: string;
|
|
5
|
+
/**
|
|
6
|
+
* Computes the Keccak-256 hash of the concatenation of two hash values.
|
|
7
|
+
* @param a The first hash as a Hash type.
|
|
8
|
+
* @param b The second hash as a Hash type.
|
|
9
|
+
* @returns The Keccak-256 hash result as a Hash type.
|
|
10
|
+
*/
|
|
11
|
+
export declare function hashInternal(a: string, b: string): string;
|
|
12
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/hasher/common.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE3D,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,MAAM,CAAA;AAGjG,eAAO,MAAM,qBAAqB,SAAS,CAAA;AAC3C,eAAO,MAAM,SAAS,QAAyC,CAAA;AAE/D;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAMzD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { concat, hexlify, keccak256, toBeHex } from 'ethers';
|
|
2
|
+
const INTERNAL_DOMAIN_SEPARATOR = toBeHex(1, 32);
|
|
3
|
+
export const LEAF_DOMAIN_SEPARATOR = '0x00';
|
|
4
|
+
export const ZERO_HASH = hexlify(new Uint8Array(32).fill(0xff));
|
|
5
|
+
/**
|
|
6
|
+
* Computes the Keccak-256 hash of the concatenation of two hash values.
|
|
7
|
+
* @param a The first hash as a Hash type.
|
|
8
|
+
* @param b The second hash as a Hash type.
|
|
9
|
+
* @returns The Keccak-256 hash result as a Hash type.
|
|
10
|
+
*/
|
|
11
|
+
export function hashInternal(a, b) {
|
|
12
|
+
if (a > b) {
|
|
13
|
+
;
|
|
14
|
+
[a, b] = [b, a];
|
|
15
|
+
}
|
|
16
|
+
const combinedData = concat([INTERNAL_DOMAIN_SEPARATOR, a, b]);
|
|
17
|
+
return keccak256(combinedData);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/hasher/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAM5D,MAAM,yBAAyB,GAAG,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;AAChD,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAA;AAC3C,MAAM,CAAC,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;AAE/D;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,CAAS,EAAE,CAAS;IAC/C,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACV,CAAC;QAAA,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAClB,CAAC;IACD,MAAM,YAAY,GAAG,MAAM,CAAC,CAAC,yBAAyB,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAC9D,OAAO,SAAS,CAAC,YAAY,CAAC,CAAA;AAChC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasher.d.ts","sourceRoot":"","sources":["../../src/hasher/hasher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAEpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAG7C,wBAAgB,aAAa,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAK/F"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { supportedChains } from "../supported-chains.js";
|
|
2
|
+
import { networkInfo } from "../utils.js";
|
|
3
|
+
// Factory function that returns the right encoder based on the version of the lane
|
|
4
|
+
export function getLeafHasher(lane) {
|
|
5
|
+
const destFamily = networkInfo(lane.destChainSelector).family;
|
|
6
|
+
const chain = supportedChains[destFamily];
|
|
7
|
+
if (!chain)
|
|
8
|
+
throw new Error(`Unsupported chain family: ${destFamily}`);
|
|
9
|
+
return chain.getDestLeafHasher(lane);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=hasher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasher.js","sourceRoot":"","sources":["../../src/hasher/hasher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAExD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAGzC,mFAAmF;AACnF,MAAM,UAAU,aAAa,CAAsC,IAAa;IAC9E,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAA;IAC7D,MAAM,KAAK,GAAG,eAAe,CAAC,UAAU,CAAC,CAAA;IACzC,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,UAAU,EAAE,CAAC,CAAA;IACtE,OAAO,KAAK,CAAC,iBAAiB,CAAC,IAAI,CAAkB,CAAA;AACvD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hasher/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AACtE,OAAO,EAAE,sBAAsB,EAAE,IAAI,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpG,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hasher/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AACtE,OAAO,EAAE,sBAAsB,EAAE,IAAI,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpG,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export declare const MAX_NUMBER_TREE_LEAVES = 256;
|
|
2
|
+
type Hash = string;
|
|
3
|
+
/**
|
|
4
|
+
* Proof represents a proof data structure with hashes and source flags.
|
|
5
|
+
* @template Hash The hash type.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Proof {
|
|
8
|
+
hashes: Hash[];
|
|
9
|
+
sourceFlags: boolean[];
|
|
10
|
+
constructor(hashes?: Hash[], sourceFlags?: boolean[]);
|
|
11
|
+
/**
|
|
12
|
+
* Counts the number of source flags that match the given boolean value.
|
|
13
|
+
* @param b The boolean value to count.
|
|
14
|
+
* @returns The count of source flags matching the provided boolean value.
|
|
15
|
+
*/
|
|
16
|
+
countSourceFlags(b: boolean): number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Represents a Merkle Tree data structure.
|
|
20
|
+
* @typeparam Hash The type of hash used in the tree.
|
|
21
|
+
*/
|
|
22
|
+
export declare class Tree {
|
|
23
|
+
layers: Hash[][];
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new Merkle Tree using the provided context and leaf hashes.
|
|
26
|
+
* @param leafHashes An array of leaf hashes to construct the tree.
|
|
27
|
+
* @returns A new Merkle Tree instance.
|
|
28
|
+
* @throws Error if there are no leaf hashes provided.
|
|
29
|
+
*/
|
|
30
|
+
constructor(leafHashes: Hash[]);
|
|
31
|
+
/**
|
|
32
|
+
* Returns the root hash of the Merkle Tree.
|
|
33
|
+
* @returns The root hash.
|
|
34
|
+
*/
|
|
35
|
+
root(): Hash;
|
|
36
|
+
/**
|
|
37
|
+
* Generates a Merkle proof for a set of indices in the tree.
|
|
38
|
+
* @param indices The indices for which to generate the proof.
|
|
39
|
+
* @returns A proof object containing hashes and source flags.
|
|
40
|
+
*/
|
|
41
|
+
prove(indices: number[]): Proof;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Converts an array of boolean proof flags to a BigNumber where each flag represents a bit.
|
|
45
|
+
* @param proofFlags An array of boolean proof flags.
|
|
46
|
+
* @returns A BigNumber representing the encoded flags.
|
|
47
|
+
*/
|
|
48
|
+
export declare function proofFlagsToBits(proofFlags: boolean[]): bigint;
|
|
49
|
+
/**
|
|
50
|
+
* Verifies and computes the Merkle root hash based on provided leaf hashes and a Merkle proof.
|
|
51
|
+
* @param ctx The Merkle context.
|
|
52
|
+
* @param leafHashes An array of leaf hashes.
|
|
53
|
+
* @param proof The Merkle proof containing hashes and source flags.
|
|
54
|
+
* @returns The computed Merkle root hash.
|
|
55
|
+
*/
|
|
56
|
+
export declare function verifyComputeRoot(leafHashes: Hash[], proof: Proof): Hash;
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=merklemulti.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merklemulti.d.ts","sourceRoot":"","sources":["../../src/hasher/merklemulti.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,sBAAsB,MAAM,CAAA;AAEzC,KAAK,IAAI,GAAG,MAAM,CAAA;AAQlB;;;GAGG;AACH,qBAAa,KAAK;IAChB,MAAM,EAAE,IAAI,EAAE,CAAK;IACnB,WAAW,EAAE,OAAO,EAAE,CAAK;gBAEf,MAAM,GAAE,IAAI,EAAO,EAAE,WAAW,GAAE,OAAO,EAAO;IAK5D;;;;OAIG;IACH,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM;CAGrC;AAiGD;;;GAGG;AACH,qBAAa,IAAI;IACf,MAAM,EAAE,IAAI,EAAE,EAAE,CAAA;IAEhB;;;;;OAKG;gBACS,UAAU,EAAE,IAAI,EAAE;IAyB9B;;;OAGG;IACH,IAAI,IAAI,IAAI;IAIZ;;;;OAIG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,KAAK;CAahC;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,OAAO,EAAE,GAAG,MAAM,CAY9D;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAqFxE"}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
// For reference implementation, see https://github.com/smartcontractkit/ccip/blob/ccip-develop/core/services/ocr2/plugins/ccip/merklemulti/merkle_multi.go
|
|
2
|
+
import { ZERO_HASH, hashInternal } from "./common.js";
|
|
3
|
+
export const MAX_NUMBER_TREE_LEAVES = 256;
|
|
4
|
+
/**
|
|
5
|
+
* Proof represents a proof data structure with hashes and source flags.
|
|
6
|
+
* @template Hash The hash type.
|
|
7
|
+
*/
|
|
8
|
+
export class Proof {
|
|
9
|
+
hashes = [];
|
|
10
|
+
sourceFlags = [];
|
|
11
|
+
constructor(hashes = [], sourceFlags = []) {
|
|
12
|
+
this.hashes = hashes;
|
|
13
|
+
this.sourceFlags = sourceFlags;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Counts the number of source flags that match the given boolean value.
|
|
17
|
+
* @param b The boolean value to count.
|
|
18
|
+
* @returns The count of source flags matching the provided boolean value.
|
|
19
|
+
*/
|
|
20
|
+
countSourceFlags(b) {
|
|
21
|
+
return this.sourceFlags.filter((flag) => flag === b).length;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Computes the next layer of a binary tree structure represented as an array of hash values.
|
|
26
|
+
*
|
|
27
|
+
* This function takes a context `ctx` and an array `layer` containing hash values as input.
|
|
28
|
+
* It processes the `layer` to generate the next layer of hash values, pairing adjacent values
|
|
29
|
+
* and applying the hashing function provided by the context.
|
|
30
|
+
*
|
|
31
|
+
* @template Hash - Generic type parameter representing the hash type.
|
|
32
|
+
* @param {Hash[]} layer - An array of hash values representing the current layer of the binary tree.
|
|
33
|
+
* @returns {[Hash[], Hash[]]} A tuple containing two arrays:
|
|
34
|
+
* - The first array contains the original input layer.
|
|
35
|
+
* - The second array contains the next layer of hash values generated by combining pairs of hashes.
|
|
36
|
+
*/
|
|
37
|
+
function computeNextLayer(layer) {
|
|
38
|
+
if (layer.length === 1) {
|
|
39
|
+
return [layer, layer];
|
|
40
|
+
}
|
|
41
|
+
if (layer.length % 2 !== 0) {
|
|
42
|
+
layer.push(ZERO_HASH);
|
|
43
|
+
}
|
|
44
|
+
const nextLayer = [];
|
|
45
|
+
for (let i = 0; i < layer.length; i += 2) {
|
|
46
|
+
nextLayer.push(hashInternal(layer[i], layer[i + 1]));
|
|
47
|
+
}
|
|
48
|
+
return [layer, nextLayer];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Calculates the parent index of a given index in a binary tree.
|
|
52
|
+
* @param idx The index for which to calculate the parent index.
|
|
53
|
+
* @returns The parent index.
|
|
54
|
+
*/
|
|
55
|
+
function parentIndex(idx) {
|
|
56
|
+
return Math.floor(idx / 2);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Calculates the sibling index of a given index in a binary tree.
|
|
60
|
+
* @param idx The index for which to calculate the sibling index.
|
|
61
|
+
* @returns The sibling index.
|
|
62
|
+
*/
|
|
63
|
+
function siblingIndex(idx) {
|
|
64
|
+
return idx ^ 1;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Generates a single-layer Merkle proof for a given set of indices within a layer.
|
|
68
|
+
* @param layer The layer of data for which to generate the proof.
|
|
69
|
+
* @param indices The indices within the layer for which to generate the proof.
|
|
70
|
+
* @returns A single-layer proof object containing nextIndices, subProof, and sourceFlags.
|
|
71
|
+
*/
|
|
72
|
+
function proveSingleLayer(layer, indices) {
|
|
73
|
+
const authIndices = [];
|
|
74
|
+
const nextIndices = [];
|
|
75
|
+
const sourceFlags = [];
|
|
76
|
+
let j = 0;
|
|
77
|
+
while (j < indices.length) {
|
|
78
|
+
const x = indices[j];
|
|
79
|
+
// Calculate the parent index for the current index and add it to the nextIndices array.
|
|
80
|
+
nextIndices.push(parentIndex(x));
|
|
81
|
+
// Check if there is a sibling index following the current index.
|
|
82
|
+
if (j + 1 < indices.length && indices[j + 1] === siblingIndex(x)) {
|
|
83
|
+
// If a sibling index is found, mark it as a source of the proof (sourceFlag = true).
|
|
84
|
+
j++;
|
|
85
|
+
sourceFlags.push(true);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
// If there is no sibling index, add the sibling index to the authentication indices.
|
|
89
|
+
authIndices.push(siblingIndex(x));
|
|
90
|
+
// Mark it as not a source of the proof (sourceFlag = false).
|
|
91
|
+
sourceFlags.push(false);
|
|
92
|
+
}
|
|
93
|
+
j++;
|
|
94
|
+
}
|
|
95
|
+
// Initialize an array to store the subproof.
|
|
96
|
+
const subProof = [];
|
|
97
|
+
for (const i of authIndices) {
|
|
98
|
+
// Populate the subproof array with the values from the authentication indices in the layer.
|
|
99
|
+
subProof.push(layer[i]);
|
|
100
|
+
}
|
|
101
|
+
// Return the single-layer proof object containing nextIndices, subProof, and sourceFlags.
|
|
102
|
+
return {
|
|
103
|
+
nextIndices,
|
|
104
|
+
subProof,
|
|
105
|
+
sourceFlags,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Represents a Merkle Tree data structure.
|
|
110
|
+
* @typeparam Hash The type of hash used in the tree.
|
|
111
|
+
*/
|
|
112
|
+
export class Tree {
|
|
113
|
+
layers;
|
|
114
|
+
/**
|
|
115
|
+
* Creates a new Merkle Tree using the provided context and leaf hashes.
|
|
116
|
+
* @param leafHashes An array of leaf hashes to construct the tree.
|
|
117
|
+
* @returns A new Merkle Tree instance.
|
|
118
|
+
* @throws Error if there are no leaf hashes provided.
|
|
119
|
+
*/
|
|
120
|
+
constructor(leafHashes) {
|
|
121
|
+
if (leafHashes.length === 0) {
|
|
122
|
+
throw new Error('Cannot construct a tree without leaves');
|
|
123
|
+
}
|
|
124
|
+
// Initialize the first layer with leaf hashes.
|
|
125
|
+
let layer = [...leafHashes];
|
|
126
|
+
// Initialize an array to store layers.
|
|
127
|
+
const layers = [layer];
|
|
128
|
+
let curr = 0;
|
|
129
|
+
// Continue building layers until there is only one hash remaining.
|
|
130
|
+
while (layer.length > 1) {
|
|
131
|
+
const [paddedLayer, nextLayer] = computeNextLayer(layer);
|
|
132
|
+
layers[curr] = paddedLayer;
|
|
133
|
+
curr++;
|
|
134
|
+
layers.push(nextLayer);
|
|
135
|
+
layer = nextLayer;
|
|
136
|
+
}
|
|
137
|
+
this.layers = layers;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Returns the root hash of the Merkle Tree.
|
|
141
|
+
* @returns The root hash.
|
|
142
|
+
*/
|
|
143
|
+
root() {
|
|
144
|
+
return this.layers[this.layers.length - 1][0];
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Generates a Merkle proof for a set of indices in the tree.
|
|
148
|
+
* @param indices The indices for which to generate the proof.
|
|
149
|
+
* @returns A proof object containing hashes and source flags.
|
|
150
|
+
*/
|
|
151
|
+
prove(indices) {
|
|
152
|
+
const proof = new Proof([], []);
|
|
153
|
+
for (const layer of this.layers.slice(0, this.layers.length - 1)) {
|
|
154
|
+
const res = proveSingleLayer(layer, indices);
|
|
155
|
+
indices = res.nextIndices;
|
|
156
|
+
proof.hashes.push(...res.subProof);
|
|
157
|
+
proof.sourceFlags.push(...res.sourceFlags);
|
|
158
|
+
}
|
|
159
|
+
return proof;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Converts an array of boolean proof flags to a BigNumber where each flag represents a bit.
|
|
164
|
+
* @param proofFlags An array of boolean proof flags.
|
|
165
|
+
* @returns A BigNumber representing the encoded flags.
|
|
166
|
+
*/
|
|
167
|
+
export function proofFlagsToBits(proofFlags) {
|
|
168
|
+
let encodedFlags = 0n;
|
|
169
|
+
// Iterate through the proof flags to encode them into bits.
|
|
170
|
+
for (let i = 0; i < proofFlags.length; i++) {
|
|
171
|
+
if (proofFlags[i]) {
|
|
172
|
+
// If the current flag is true, set the corresponding bit to 1 using bitwise OR.
|
|
173
|
+
encodedFlags |= 1n << BigInt(i);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
// Return the final BigNumber representing the encoded flags.
|
|
177
|
+
return encodedFlags;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Verifies and computes the Merkle root hash based on provided leaf hashes and a Merkle proof.
|
|
181
|
+
* @param ctx The Merkle context.
|
|
182
|
+
* @param leafHashes An array of leaf hashes.
|
|
183
|
+
* @param proof The Merkle proof containing hashes and source flags.
|
|
184
|
+
* @returns The computed Merkle root hash.
|
|
185
|
+
*/
|
|
186
|
+
export function verifyComputeRoot(leafHashes, proof) {
|
|
187
|
+
const leavesLength = leafHashes.length;
|
|
188
|
+
const proofsLength = proof.hashes.length;
|
|
189
|
+
if (leavesLength === 0 && proofsLength === 0) {
|
|
190
|
+
throw new Error('leaves and proofs are empty');
|
|
191
|
+
}
|
|
192
|
+
if (leavesLength > MAX_NUMBER_TREE_LEAVES + 1 || proofsLength > MAX_NUMBER_TREE_LEAVES + 1) {
|
|
193
|
+
throw new Error(`leaves or proofs length beyond the limit of ${MAX_NUMBER_TREE_LEAVES}`);
|
|
194
|
+
}
|
|
195
|
+
const totalHashes = leavesLength + proofsLength - 1;
|
|
196
|
+
if (totalHashes > MAX_NUMBER_TREE_LEAVES) {
|
|
197
|
+
throw new Error(`total hashes length cannot be larger than ${MAX_NUMBER_TREE_LEAVES}`);
|
|
198
|
+
}
|
|
199
|
+
if (totalHashes !== proof.sourceFlags.length) {
|
|
200
|
+
throw new Error(`hashes ${totalHashes} != sourceFlags ${proof.sourceFlags.length}`);
|
|
201
|
+
}
|
|
202
|
+
// If there are no hashes, return the first leaf hash.
|
|
203
|
+
if (totalHashes === 0) {
|
|
204
|
+
return leafHashes[0];
|
|
205
|
+
}
|
|
206
|
+
// Count the number of source flags pointing to proofs.
|
|
207
|
+
const sourceProofCount = proof.countSourceFlags(false);
|
|
208
|
+
if (sourceProofCount !== proofsLength) {
|
|
209
|
+
throw new Error(`proof source flags ${sourceProofCount} != proof hashes ${proofsLength}`);
|
|
210
|
+
}
|
|
211
|
+
const hashes = new Array(totalHashes);
|
|
212
|
+
for (let i = 0; i < totalHashes; i++) {
|
|
213
|
+
// Initialize the hashes array with the first leaf hash.
|
|
214
|
+
hashes.push(leafHashes[0]);
|
|
215
|
+
}
|
|
216
|
+
let leafPos = 0;
|
|
217
|
+
let hashPos = 0;
|
|
218
|
+
let proofPos = 0;
|
|
219
|
+
for (let i = 0; i < totalHashes; i++) {
|
|
220
|
+
let a = undefined;
|
|
221
|
+
let b = undefined;
|
|
222
|
+
if (proof.sourceFlags[i] === true) {
|
|
223
|
+
if (leafPos < leavesLength) {
|
|
224
|
+
a = leafHashes[leafPos];
|
|
225
|
+
leafPos++;
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
a = hashes[hashPos];
|
|
229
|
+
hashPos++;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
else if (proof.sourceFlags[i] === false) {
|
|
233
|
+
a = proof.hashes[proofPos];
|
|
234
|
+
proofPos++;
|
|
235
|
+
}
|
|
236
|
+
if (leafPos < leavesLength) {
|
|
237
|
+
b = leafHashes[leafPos];
|
|
238
|
+
leafPos++;
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
b = hashes[hashPos];
|
|
242
|
+
hashPos++;
|
|
243
|
+
}
|
|
244
|
+
if (a === undefined || b === undefined) {
|
|
245
|
+
throw new Error('a or b is undefined');
|
|
246
|
+
}
|
|
247
|
+
// Compute the hash of a and b and store it in the hashes array.
|
|
248
|
+
hashes[i] = hashInternal(a, b);
|
|
249
|
+
}
|
|
250
|
+
// Check if all proofs were used during processing.
|
|
251
|
+
if (hashPos !== totalHashes - 1 || leafPos !== leavesLength || proofPos !== proofsLength) {
|
|
252
|
+
throw new Error('not all proofs used during processing');
|
|
253
|
+
}
|
|
254
|
+
// Return the computed Merkle root hash.
|
|
255
|
+
return hashes[totalHashes - 1];
|
|
256
|
+
}
|
|
257
|
+
//# sourceMappingURL=merklemulti.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merklemulti.js","sourceRoot":"","sources":["../../src/hasher/merklemulti.ts"],"names":[],"mappings":"AAAA,2JAA2J;AAC3J,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAErD,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,CAAA;AAUzC;;;GAGG;AACH,MAAM,OAAO,KAAK;IAChB,MAAM,GAAW,EAAE,CAAA;IACnB,WAAW,GAAc,EAAE,CAAA;IAE3B,YAAY,SAAiB,EAAE,EAAE,cAAyB,EAAE;QAC1D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;IAChC,CAAC;IAED;;;;OAIG;IACH,gBAAgB,CAAC,CAAU;QACzB,OAAO,IAAI,CA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AAY,EAAE,CAAC;YAC3B,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;YACvB,OAAO,EAAE,CAAA;QACX,CAAC;aAAM,CAAC;YACN,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;YACnB,OAAO,EAAE,CAAA;QACX,CAAC;QAED,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;QACxC,CAAC;QAED,gEAAgE;QAChE,MAAM,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAChC,CAAC;IAED,mDAAmD;IACnD,IAAI,OAAO,KAAK,WAAW,GAAG,CAAC,IAAI,OAAO,KAAK,YAAY,IAAI,QAAQ,KAAK,YAAY,EAAE,CAAC;QACzF,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAA;IAC1D,CAAC;IAED,wCAAwC;IACxC,OAAO,MAAM,CAAC,WAAW,GAAG,CAAC,CAAC,CAAA;AAChC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { AptosChain } from './aptos/index.ts';
|
|
2
|
+
export { type Chain, type ChainGetter, type ChainStatic, type ChainTransaction, type LogFilter, type RateLimiterState, type TokenInfo, type TokenPoolRemote, ChainFamily, } from './chain.ts';
|
|
3
|
+
export { EVMChain } from './evm/index.ts';
|
|
4
|
+
export { calculateManualExecProof, discoverOffRamp } from './execution.ts';
|
|
5
|
+
export { type EVMExtraArgsV1, type EVMExtraArgsV2, type ExtraArgs, type SVMExtraArgsV1, type SuiExtraArgsV1, decodeExtraArgs, encodeExtraArgs, } from './extra-args.ts';
|
|
6
|
+
export { estimateExecGasForRequest } from './gas.ts';
|
|
7
|
+
export { decodeMessage, fetchAllMessagesInBatch, fetchCCIPMessageById, fetchCCIPRequestsInTx, fetchRequestsForSender, sourceToDestTokenAmounts, } from './requests.ts';
|
|
8
|
+
export { SolanaChain } from './solana/index.ts';
|
|
9
|
+
export { SuiChain } from './sui/index.ts';
|
|
10
|
+
export { supportedChains } from './supported-chains.ts';
|
|
11
|
+
export { type AnyMessage, type CCIPCommit, type CCIPExecution, type CCIPMessage, type CCIPRequest, type CommitReport, type ExecutionReceipt, type ExecutionReport, type Lane, type NetworkInfo, type OffchainTokenData, CCIPVersion, ExecutionState, } from './types.ts';
|
|
12
|
+
export { bigIntReplacer, bigIntReviver, decodeAddress, getDataBytes, networkInfo } from './utils.ts';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EACL,KAAK,KAAK,EACV,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,WAAW,GACZ,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,wBAAwB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAC1E,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,eAAe,EACf,eAAe,GAChB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAA;AACpD,OAAO,EACL,aAAa,EACb,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EACL,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,IAAI,EACT,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,WAAW,EACX,cAAc,GACf,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { AptosChain } from "./aptos/index.js";
|
|
2
|
+
export { ChainFamily, } from "./chain.js";
|
|
3
|
+
export { EVMChain } from "./evm/index.js";
|
|
4
|
+
export { calculateManualExecProof, discoverOffRamp } from "./execution.js";
|
|
5
|
+
export { decodeExtraArgs, encodeExtraArgs, } from "./extra-args.js";
|
|
6
|
+
export { estimateExecGasForRequest } from "./gas.js";
|
|
7
|
+
export { decodeMessage, fetchAllMessagesInBatch, fetchCCIPMessageById, fetchCCIPRequestsInTx, fetchRequestsForSender, sourceToDestTokenAmounts, } from "./requests.js";
|
|
8
|
+
export { SolanaChain } from "./solana/index.js";
|
|
9
|
+
export { SuiChain } from "./sui/index.js";
|
|
10
|
+
export { supportedChains } from "./supported-chains.js";
|
|
11
|
+
export { CCIPVersion, ExecutionState, } from "./types.js";
|
|
12
|
+
export { bigIntReplacer, bigIntReviver, decodeAddress, getDataBytes, networkInfo } from "./utils.js";
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EASL,WAAW,GACZ,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,wBAAwB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAC1E,OAAO,EAML,eAAe,EACf,eAAe,GAChB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAA;AACpD,OAAO,EACL,aAAa,EACb,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAYL,WAAW,EACX,cAAc,GACf,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the USDC attestation for a given MessageSent Log
|
|
3
|
+
* https://developers.circle.com/stablecoins/reference/getattestation
|
|
4
|
+
*
|
|
5
|
+
* @param message - payload of USDC MessageSent(bytes message) event
|
|
6
|
+
* @param isTestnet - true if this was from a testnet
|
|
7
|
+
* @returns USDC/CCTP attestation bytes
|
|
8
|
+
*/
|
|
9
|
+
export declare function getUsdcAttestation(message: string, isTestnet: boolean): Promise<string>;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the LBTC attestation for a given payload hash
|
|
12
|
+
*
|
|
13
|
+
* @param payloadHash - hash of the payload of the LBTC transfer
|
|
14
|
+
* @param isTestnet - true if this was from a testnet
|
|
15
|
+
* @returns LBTC attestation bytes
|
|
16
|
+
*/
|
|
17
|
+
export declare function getLbtcAttestation(payloadHash: string, isTestnet: boolean): Promise<{
|
|
18
|
+
attestation: string;
|
|
19
|
+
}>;
|
|
20
|
+
//# sourceMappingURL=offchain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"offchain.d.ts","sourceRoot":"","sources":["../src/offchain.ts"],"names":[],"mappings":"AAsBA;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAU7F;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CACtC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,OAAO,GACjB,OAAO,CAAC;IACT,WAAW,EAAE,MAAM,CAAA;CACpB,CAAC,CA+BD"}
|
package/dist/offchain.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { keccak256 } from 'ethers';
|
|
2
|
+
const CIRCLE_API_URL = {
|
|
3
|
+
mainnet: 'https://iris-api.circle.com/v1',
|
|
4
|
+
testnet: 'https://iris-api-sandbox.circle.com/v1',
|
|
5
|
+
};
|
|
6
|
+
const LOMBARD_API_URL = {
|
|
7
|
+
mainnet: 'https://mainnet.prod.lombard.finance',
|
|
8
|
+
testnet: 'https://gastald-testnet.prod.lombard.finance',
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Returns the USDC attestation for a given MessageSent Log
|
|
12
|
+
* https://developers.circle.com/stablecoins/reference/getattestation
|
|
13
|
+
*
|
|
14
|
+
* @param message - payload of USDC MessageSent(bytes message) event
|
|
15
|
+
* @param isTestnet - true if this was from a testnet
|
|
16
|
+
* @returns USDC/CCTP attestation bytes
|
|
17
|
+
*/
|
|
18
|
+
export async function getUsdcAttestation(message, isTestnet) {
|
|
19
|
+
const msgHash = keccak256(message);
|
|
20
|
+
const circleApiBaseUrl = isTestnet ? CIRCLE_API_URL.testnet : CIRCLE_API_URL.mainnet;
|
|
21
|
+
const res = await fetch(`${circleApiBaseUrl}/attestations/${msgHash}`);
|
|
22
|
+
const json = (await res.json());
|
|
23
|
+
if (!('status' in json) || json.status !== 'complete' || !json.attestation) {
|
|
24
|
+
throw new Error('Could not fetch USDC attestation. Response: ' + JSON.stringify(json, null, 2));
|
|
25
|
+
}
|
|
26
|
+
return json.attestation;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns the LBTC attestation for a given payload hash
|
|
30
|
+
*
|
|
31
|
+
* @param payloadHash - hash of the payload of the LBTC transfer
|
|
32
|
+
* @param isTestnet - true if this was from a testnet
|
|
33
|
+
* @returns LBTC attestation bytes
|
|
34
|
+
*/
|
|
35
|
+
export async function getLbtcAttestation(payloadHash, isTestnet) {
|
|
36
|
+
const lbtcApiBaseUrl = isTestnet ? LOMBARD_API_URL.testnet : LOMBARD_API_URL.mainnet;
|
|
37
|
+
const res = await fetch(`${lbtcApiBaseUrl}/api/bridge/v1/deposits/getByHash`, {
|
|
38
|
+
method: 'POST',
|
|
39
|
+
body: JSON.stringify({ messageHash: [payloadHash] }),
|
|
40
|
+
});
|
|
41
|
+
const response = (await res.json());
|
|
42
|
+
if (response == null || !('attestations' in response)) {
|
|
43
|
+
throw new Error('Error while fetching LBTC attestation. Response: ' + JSON.stringify(response, null, 2));
|
|
44
|
+
}
|
|
45
|
+
const attestation = response.attestations.find((att) => att.message_hash === payloadHash);
|
|
46
|
+
if (attestation == null) {
|
|
47
|
+
throw new Error('Could not find requested LBTC attestation with hash:' +
|
|
48
|
+
payloadHash +
|
|
49
|
+
' in response: ' +
|
|
50
|
+
JSON.stringify(response, null, 2));
|
|
51
|
+
}
|
|
52
|
+
if (attestation.status !== 'NOTARIZATION_STATUS_SESSION_APPROVED' ||
|
|
53
|
+
!('attestation' in attestation)) {
|
|
54
|
+
throw new Error('LBTC attestation is not approved or invalid. Response: ' +
|
|
55
|
+
JSON.stringify(attestation, null, 2));
|
|
56
|
+
}
|
|
57
|
+
return attestation;
|
|
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