@ember-finance/sdk 2.11.0 → 2.12.0-ccip.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/dist/src/abis/CcipRouter.json +58 -0
- package/dist/src/abis/index.d.ts +3 -1
- package/dist/src/abis/index.js +4 -1
- package/dist/src/api/v2/apis/vaults-api.d.ts +42 -0
- package/dist/src/api/v2/apis/vaults-api.js +87 -0
- package/dist/src/api/v2/models/chain.d.ts +6 -0
- package/dist/src/api/v2/models/coin-placement.d.ts +113 -0
- package/dist/src/api/v2/models/coin-placement.js +17 -0
- package/dist/src/api/v2/models/coin-placements-response.d.ts +25 -0
- package/dist/src/api/v2/models/coin-placements-response.js +14 -0
- package/dist/src/api/v2/models/evm-ccip-lane.d.ts +73 -0
- package/dist/src/api/v2/models/evm-ccip-lane.js +14 -0
- package/dist/src/api/v2/models/evm-ccip-rate-limits.d.ts +36 -0
- package/dist/src/api/v2/models/evm-ccip-rate-limits.js +14 -0
- package/dist/src/api/v2/models/evm-ccip-token-pool.d.ts +122 -0
- package/dist/src/api/v2/models/evm-ccip-token-pool.js +17 -0
- package/dist/src/api/v2/models/evm-contracts.d.ts +9 -0
- package/dist/src/api/v2/models/evm-oftadapter.d.ts +11 -0
- package/dist/src/api/v2/models/evm-oftadapter.js +4 -1
- package/dist/src/api/v2/models/evm-oftpeer.d.ts +12 -0
- package/dist/src/api/v2/models/index.d.ts +6 -0
- package/dist/src/api/v2/models/index.js +6 -0
- package/dist/src/api/v2/models/instant-withdraw-config.d.ts +21 -2
- package/dist/src/api/v2/models/poc-report-protocol-asset.d.ts +60 -0
- package/dist/src/api/v2/models/poc-report-protocol-asset.js +18 -0
- package/dist/src/api/v2/models/poc-report-protocol.d.ts +13 -0
- package/dist/src/api/v2/models/transparency-row.d.ts +1 -1
- package/dist/src/evm-vaults/interfaces/index.d.ts +39 -0
- package/dist/src/evm-vaults/on-chain-calls/tx-builder.d.ts +15 -1
- package/dist/src/evm-vaults/on-chain-calls/tx-builder.js +36 -0
- package/dist/src/evm-vaults/on-chain-calls/user.d.ts +33 -1
- package/dist/src/evm-vaults/on-chain-calls/user.js +61 -0
- package/dist/src/evm-vaults/on-chain-calls/vault-reader.d.ts +14 -1
- package/dist/src/evm-vaults/on-chain-calls/vault-reader.js +30 -0
- package/dist/src/evm-vaults/utils/ccip.d.ts +23 -0
- package/dist/src/evm-vaults/utils/ccip.js +32 -0
- package/dist/src/evm-vaults/utils/deployment-parser.d.ts +27 -1
- package/dist/src/evm-vaults/utils/deployment-parser.js +37 -0
- package/dist/src/evm-vaults/utils/index.d.ts +1 -0
- package/dist/src/evm-vaults/utils/index.js +1 -0
- package/package.json +1 -1
|
@@ -637,6 +637,67 @@ export class EVMUserCalls extends EVMOnChainCalls {
|
|
|
637
637
|
}, refundAddress);
|
|
638
638
|
return this.execCall(txCall, options);
|
|
639
639
|
}
|
|
640
|
+
/**
|
|
641
|
+
* Bridges a receipt token to a destination chain using the vault's CCIP pool.
|
|
642
|
+
*
|
|
643
|
+
* The counterpart to bridgeSendToken. Call getBridgeTransportForVault first
|
|
644
|
+
* and pick the matching method — a vault has exactly one active bridge, and
|
|
645
|
+
* calling the wrong one throws rather than silently doing nothing.
|
|
646
|
+
*
|
|
647
|
+
* Two differences from the LayerZero path worth knowing:
|
|
648
|
+
* - the allowance goes to the CCIP Router, not to the pool, because the
|
|
649
|
+
* Router is what pulls the tokens;
|
|
650
|
+
* - the destination is named by network, and the chain selector is read
|
|
651
|
+
* from the configured lane. An unconfigured route throws here rather
|
|
652
|
+
* than reverting on chain.
|
|
653
|
+
*
|
|
654
|
+
* @param destinationNetwork Destination network name, e.g. "atlantic"
|
|
655
|
+
* @param tokenAddress Receipt token address (also the vault identifier in EVM deployment data)
|
|
656
|
+
* @param amount Amount to bridge in local token decimals
|
|
657
|
+
* @param receiver Recipient wallet address on the destination chain
|
|
658
|
+
* @param feeQuote Fee quote returned by reader.getCcipFeeQuote
|
|
659
|
+
* @param options Optional bridge/send overrides
|
|
660
|
+
* @returns Transaction execution response
|
|
661
|
+
*/
|
|
662
|
+
async bridgeSendTokenViaCcip(destinationNetwork, tokenAddress, amount, receiver, feeQuote, options) {
|
|
663
|
+
if (!this.provider) {
|
|
664
|
+
throw new Error("Provider required for bridge send read operations and allowance checks");
|
|
665
|
+
}
|
|
666
|
+
const pool = this.parser.getCcipTokenPoolByVaultAddress(tokenAddress);
|
|
667
|
+
if (!pool?.router) {
|
|
668
|
+
throw new Error(`CCIP token pool not found for token address: ${tokenAddress}`);
|
|
669
|
+
}
|
|
670
|
+
const lane = this.parser.getCcipLaneByVaultAndNetwork(tokenAddress, destinationNetwork);
|
|
671
|
+
if (!lane?.remoteChainSelector) {
|
|
672
|
+
throw new Error(`No CCIP lane configured from this chain to "${destinationNetwork}" for token ${tokenAddress}`);
|
|
673
|
+
}
|
|
674
|
+
const amountBigInt = BigInt(amount);
|
|
675
|
+
// The Router moves the tokens, so it is the Router that needs approval.
|
|
676
|
+
const token = new ethers.Contract(tokenAddress, ["function allowance(address,address) view returns (uint256)"], this.provider);
|
|
677
|
+
const currentAllowance = await token.allowance(await this.getWalletAddress(), pool.router);
|
|
678
|
+
if (currentAllowance < amountBigInt) {
|
|
679
|
+
throw new Error(`Insufficient allowance for bridge transfer. Current allowance: ${currentAllowance}, required: ${amountBigInt}`);
|
|
680
|
+
}
|
|
681
|
+
const txCall = this.txBuilder.ccipSend(pool.router, {
|
|
682
|
+
destinationChainSelector: lane.remoteChainSelector,
|
|
683
|
+
receiver,
|
|
684
|
+
amount: amountBigInt,
|
|
685
|
+
feeToken: options?.feeToken,
|
|
686
|
+
destinationGasLimit: options?.destinationGasLimit
|
|
687
|
+
}, tokenAddress, feeQuote.fee);
|
|
688
|
+
return this.execCall(txCall, options);
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Reports which bridge a vault uses, or undefined if it has none.
|
|
692
|
+
*
|
|
693
|
+
* A vault has exactly one active bridge, but different vaults use different
|
|
694
|
+
* ones, so branch on this rather than assuming either transport.
|
|
695
|
+
*
|
|
696
|
+
* @param tokenAddress Receipt token address (also the vault identifier in EVM deployment data)
|
|
697
|
+
*/
|
|
698
|
+
getBridgeTransportForVault(tokenAddress) {
|
|
699
|
+
return this.parser.getBridgeTransportByVaultAddress(tokenAddress);
|
|
700
|
+
}
|
|
640
701
|
// ============================================
|
|
641
702
|
// Read-Only Methods
|
|
642
703
|
// ============================================
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Provider } from "ethers";
|
|
2
2
|
import { EVMDeploymentParser } from "../utils/deployment-parser.js";
|
|
3
|
-
import { EvmProtocolInfo, IOFTSendParam, IOFTFeeQuote, IOFTVaultSupportedChain, IParkingLotInfo } from "../interfaces/index.js";
|
|
3
|
+
import { EvmProtocolInfo, IOFTSendParam, IOFTFeeQuote, IOFTVaultSupportedChain, IParkingLotInfo, ICcipSendParam, ICcipFeeQuote } from "../interfaces/index.js";
|
|
4
4
|
import { NumStr } from "../../common/types.js";
|
|
5
5
|
import { Chain, VaultsApi } from "../../api/v2/index.js";
|
|
6
6
|
/**
|
|
@@ -524,4 +524,17 @@ export declare class EVMVaultReader {
|
|
|
524
524
|
* @returns Combined fee quote including native fee and expected amounts
|
|
525
525
|
*/
|
|
526
526
|
getOFTFeeQuote(vaultId: string, sendParam: IOFTSendParam, payInLzToken?: boolean): Promise<IOFTFeeQuote>;
|
|
527
|
+
/**
|
|
528
|
+
* Quotes what a CCIP bridge send will cost.
|
|
529
|
+
*
|
|
530
|
+
* The counterpart to getOFTFeeQuote. CCIP charges one fee rather than
|
|
531
|
+
* LayerZero's native/LZ-token pair, and quotes no received amount: a
|
|
532
|
+
* burn-and-mint pool mints exactly what it burned, so the amount received is
|
|
533
|
+
* the amount sent.
|
|
534
|
+
*
|
|
535
|
+
* @param vaultId The vault (receipt token) address on the source chain
|
|
536
|
+
* @param sendParam Destination, receiver and amount
|
|
537
|
+
* @returns The fee and the token it is charged in
|
|
538
|
+
*/
|
|
539
|
+
getCcipFeeQuote(vaultId: string, sendParam: ICcipSendParam): Promise<ICcipFeeQuote>;
|
|
527
540
|
}
|
|
@@ -4,6 +4,8 @@ import EmberVaultABI from "../../abis/EmberVault.json" with { type: "json" };
|
|
|
4
4
|
import EmberETHVaultABI from "../../abis/EmberETHVault.json" with { type: "json" };
|
|
5
5
|
import EmberProtocolConfigABI from "../../abis/EmberProtocolConfig.json" with { type: "json" };
|
|
6
6
|
import ERC20TokenABI from "../../abis/ERC20Token.json" with { type: "json" };
|
|
7
|
+
import CcipRouterABI from "../../abis/CcipRouter.json" with { type: "json" };
|
|
8
|
+
import { ZERO_ADDRESS, encodeCcipReceiver, encodeCcipExtraArgs } from "../utils/ccip.js";
|
|
7
9
|
import EmberVaultOFTAdapterABI from "../../abis/EmberVaultMintBurnOFTAdapter.json" with { type: "json" };
|
|
8
10
|
import EmberDepositParkingLotABI from "../../abis/EmberDepositParkingLot.json" with { type: "json" };
|
|
9
11
|
import { Configuration, VaultsApi } from "../../api/v2/index.js";
|
|
@@ -736,4 +738,32 @@ export class EVMVaultReader {
|
|
|
736
738
|
maxAmountLD: oftQuote.oftLimit.maxAmountLD
|
|
737
739
|
};
|
|
738
740
|
}
|
|
741
|
+
/**
|
|
742
|
+
* Quotes what a CCIP bridge send will cost.
|
|
743
|
+
*
|
|
744
|
+
* The counterpart to getOFTFeeQuote. CCIP charges one fee rather than
|
|
745
|
+
* LayerZero's native/LZ-token pair, and quotes no received amount: a
|
|
746
|
+
* burn-and-mint pool mints exactly what it burned, so the amount received is
|
|
747
|
+
* the amount sent.
|
|
748
|
+
*
|
|
749
|
+
* @param vaultId The vault (receipt token) address on the source chain
|
|
750
|
+
* @param sendParam Destination, receiver and amount
|
|
751
|
+
* @returns The fee and the token it is charged in
|
|
752
|
+
*/
|
|
753
|
+
async getCcipFeeQuote(vaultId, sendParam) {
|
|
754
|
+
const pool = this.parser.getCcipTokenPoolByVaultAddress(vaultId);
|
|
755
|
+
if (!pool?.router) {
|
|
756
|
+
throw new Error(`CCIP token pool not found for vault: ${vaultId}`);
|
|
757
|
+
}
|
|
758
|
+
const feeToken = sendParam.feeToken ?? ZERO_ADDRESS;
|
|
759
|
+
const router = new Contract(pool.router, CcipRouterABI.abi, this.provider);
|
|
760
|
+
const fee = await router.getFee(sendParam.destinationChainSelector, {
|
|
761
|
+
receiver: encodeCcipReceiver(sendParam.receiver),
|
|
762
|
+
data: "0x",
|
|
763
|
+
tokenAmounts: [{ token: vaultId, amount: sendParam.amount }],
|
|
764
|
+
feeToken,
|
|
765
|
+
extraArgs: encodeCcipExtraArgs(sendParam.destinationGasLimit)
|
|
766
|
+
});
|
|
767
|
+
return { fee, feeToken };
|
|
768
|
+
}
|
|
739
769
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** The native currency, as CCIP names it when no fee token is given. */
|
|
2
|
+
export declare const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
3
|
+
/**
|
|
4
|
+
* Encodes a receiver for a CCIP message.
|
|
5
|
+
*
|
|
6
|
+
* CCIP carries the receiver as `bytes` rather than `address`, because the far
|
|
7
|
+
* end of a lane need not be an EVM chain. On an EVM destination that is the
|
|
8
|
+
* address left-padded to 32 bytes, which is why the same account looks
|
|
9
|
+
* different on the two sides of a transfer.
|
|
10
|
+
*/
|
|
11
|
+
export declare const encodeCcipReceiver: (receiver: string) => string;
|
|
12
|
+
/**
|
|
13
|
+
* Encodes CCIP extraArgs.
|
|
14
|
+
*
|
|
15
|
+
* `allowOutOfOrderExecution` is true because a token transfer carries no
|
|
16
|
+
* message the destination has to apply in sequence; requiring ordering would
|
|
17
|
+
* make one stuck message block every later one on the lane.
|
|
18
|
+
*
|
|
19
|
+
* gasLimit is 0 by default: a plain token transfer runs no code on the
|
|
20
|
+
* destination beyond the pool's own mint, and paying for gas that is never used
|
|
21
|
+
* only raises the fee.
|
|
22
|
+
*/
|
|
23
|
+
export declare const encodeCcipExtraArgs: (destinationGasLimit?: bigint) => string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { AbiCoder, getAddress, zeroPadValue } from "ethers";
|
|
2
|
+
/** The native currency, as CCIP names it when no fee token is given. */
|
|
3
|
+
export const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
4
|
+
/**
|
|
5
|
+
* Tag for CCIP's EVMExtraArgsV2, the first four bytes of
|
|
6
|
+
* keccak256("CCIP EVMExtraArgsV2"). Verified against a deployed ramp.
|
|
7
|
+
*/
|
|
8
|
+
const EVM_EXTRA_ARGS_V2_TAG = "0x181dcf10";
|
|
9
|
+
/**
|
|
10
|
+
* Encodes a receiver for a CCIP message.
|
|
11
|
+
*
|
|
12
|
+
* CCIP carries the receiver as `bytes` rather than `address`, because the far
|
|
13
|
+
* end of a lane need not be an EVM chain. On an EVM destination that is the
|
|
14
|
+
* address left-padded to 32 bytes, which is why the same account looks
|
|
15
|
+
* different on the two sides of a transfer.
|
|
16
|
+
*/
|
|
17
|
+
export const encodeCcipReceiver = (receiver) => zeroPadValue(getAddress(receiver), 32);
|
|
18
|
+
/**
|
|
19
|
+
* Encodes CCIP extraArgs.
|
|
20
|
+
*
|
|
21
|
+
* `allowOutOfOrderExecution` is true because a token transfer carries no
|
|
22
|
+
* message the destination has to apply in sequence; requiring ordering would
|
|
23
|
+
* make one stuck message block every later one on the lane.
|
|
24
|
+
*
|
|
25
|
+
* gasLimit is 0 by default: a plain token transfer runs no code on the
|
|
26
|
+
* destination beyond the pool's own mint, and paying for gas that is never used
|
|
27
|
+
* only raises the fee.
|
|
28
|
+
*/
|
|
29
|
+
export const encodeCcipExtraArgs = (destinationGasLimit = 0n) => {
|
|
30
|
+
const encoded = AbiCoder.defaultAbiCoder().encode(["uint256", "bool"], [destinationGasLimit, true]);
|
|
31
|
+
return EVM_EXTRA_ARGS_V2_TAG + encoded.slice(2);
|
|
32
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EvmOFTAdapter } from "../../api/v2/index.js";
|
|
1
|
+
import { EvmCcipLane, EvmCcipTokenPool, EvmOFTAdapter } from "../../api/v2/index.js";
|
|
2
2
|
import { EvmProtocolInfo } from "../interfaces/index.js";
|
|
3
3
|
export declare class EVMDeploymentParser {
|
|
4
4
|
deployment: EvmProtocolInfo;
|
|
@@ -124,4 +124,30 @@ export declare class EVMDeploymentParser {
|
|
|
124
124
|
* @param vaultAddress The vault address (receipt token address in EVM deployment data)
|
|
125
125
|
*/
|
|
126
126
|
getOFTAdapterObjectByVaultAddress(vaultAddress: string): EvmOFTAdapter | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* Finds the CCIP token pool entry for a given vault address.
|
|
129
|
+
* @param vaultAddress The vault address (receipt token address in EVM deployment data)
|
|
130
|
+
*/
|
|
131
|
+
getCcipTokenPoolByVaultAddress(vaultAddress: string): EvmCcipTokenPool | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* Reports which bridge a vault uses, or undefined if it has none.
|
|
134
|
+
*
|
|
135
|
+
* A vault has exactly one active bridge, but different vaults use different
|
|
136
|
+
* ones, so call this before choosing between the LayerZero and CCIP send
|
|
137
|
+
* methods rather than assuming either.
|
|
138
|
+
*
|
|
139
|
+
* @param vaultAddress The vault address (receipt token address in EVM deployment data)
|
|
140
|
+
*/
|
|
141
|
+
getBridgeTransportByVaultAddress(vaultAddress: string): "LayerZero" | "CCIP" | undefined;
|
|
142
|
+
/**
|
|
143
|
+
* Finds the configured CCIP lane from a vault to a destination network.
|
|
144
|
+
*
|
|
145
|
+
* Lanes are keyed by the destination's CCIP chain selector, which nothing
|
|
146
|
+
* outside CCIP knows, so this looks the lane up by network name instead.
|
|
147
|
+
* A missing lane means the route is not configured — sending would revert.
|
|
148
|
+
*
|
|
149
|
+
* @param vaultAddress The vault address on the source chain
|
|
150
|
+
* @param destinationNetwork The destination network name, e.g. "atlantic"
|
|
151
|
+
*/
|
|
152
|
+
getCcipLaneByVaultAndNetwork(vaultAddress: string, destinationNetwork: string): EvmCcipLane | undefined;
|
|
127
153
|
}
|
|
@@ -206,4 +206,41 @@ export class EVMDeploymentParser {
|
|
|
206
206
|
}
|
|
207
207
|
return entry;
|
|
208
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* Finds the CCIP token pool entry for a given vault address.
|
|
211
|
+
* @param vaultAddress The vault address (receipt token address in EVM deployment data)
|
|
212
|
+
*/
|
|
213
|
+
getCcipTokenPoolByVaultAddress(vaultAddress) {
|
|
214
|
+
return Object.values(this.deployment.contracts?.ccipTokenPools ?? {}).find(pool => pool.vaultAddress?.toLowerCase() === vaultAddress.toLowerCase());
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Reports which bridge a vault uses, or undefined if it has none.
|
|
218
|
+
*
|
|
219
|
+
* A vault has exactly one active bridge, but different vaults use different
|
|
220
|
+
* ones, so call this before choosing between the LayerZero and CCIP send
|
|
221
|
+
* methods rather than assuming either.
|
|
222
|
+
*
|
|
223
|
+
* @param vaultAddress The vault address (receipt token address in EVM deployment data)
|
|
224
|
+
*/
|
|
225
|
+
getBridgeTransportByVaultAddress(vaultAddress) {
|
|
226
|
+
if (this.getCcipTokenPoolByVaultAddress(vaultAddress))
|
|
227
|
+
return "CCIP";
|
|
228
|
+
if (this.getOFTAdapterObjectByVaultAddress(vaultAddress))
|
|
229
|
+
return "LayerZero";
|
|
230
|
+
return undefined;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Finds the configured CCIP lane from a vault to a destination network.
|
|
234
|
+
*
|
|
235
|
+
* Lanes are keyed by the destination's CCIP chain selector, which nothing
|
|
236
|
+
* outside CCIP knows, so this looks the lane up by network name instead.
|
|
237
|
+
* A missing lane means the route is not configured — sending would revert.
|
|
238
|
+
*
|
|
239
|
+
* @param vaultAddress The vault address on the source chain
|
|
240
|
+
* @param destinationNetwork The destination network name, e.g. "atlantic"
|
|
241
|
+
*/
|
|
242
|
+
getCcipLaneByVaultAndNetwork(vaultAddress, destinationNetwork) {
|
|
243
|
+
const pool = this.getCcipTokenPoolByVaultAddress(vaultAddress);
|
|
244
|
+
return Object.values(pool?.lanes ?? {}).find(lane => lane.remoteNetwork?.toLowerCase() === destinationNetwork.toLowerCase());
|
|
245
|
+
}
|
|
209
246
|
}
|