@ember-finance/sdk 2.0.1 → 2.0.2
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/EmberETHVault.json +343 -2
- package/dist/src/abis/EmberProtocolConfig.json +61 -2
- package/dist/src/abis/EmberVault.json +343 -2
- package/dist/src/abis/EmberVaultMintBurnOFTAdapter.json +1382 -0
- package/dist/src/abis/index.d.ts +3 -1
- package/dist/src/abis/index.js +3 -1
- package/dist/src/api/v2/models/chain.d.ts +6 -0
- package/dist/src/api/v2/models/evm-contracts.d.ts +9 -0
- package/dist/src/api/v2/models/evm-oftadapter.d.ts +93 -0
- package/dist/src/api/v2/models/evm-oftadapter.js +14 -0
- package/dist/src/api/v2/models/evm-oftpeer.d.ts +48 -0
- package/dist/src/api/v2/models/evm-oftpeer.js +14 -0
- package/dist/src/api/v2/models/evm-protocol-config.d.ts +6 -0
- package/dist/src/api/v2/models/evm-vault.d.ts +24 -0
- package/dist/src/api/v2/models/index.d.ts +2 -0
- package/dist/src/api/v2/models/index.js +2 -0
- package/dist/src/common/constants.d.ts +8 -0
- package/dist/src/common/constants.js +11 -0
- package/dist/src/ember-vaults.d.ts +7 -8
- package/dist/src/ember-vaults.js +2 -12
- package/dist/src/evm-vaults/index.d.ts +12 -0
- package/dist/src/evm-vaults/index.js +18 -0
- package/dist/src/evm-vaults/interfaces/index.d.ts +92 -47
- package/dist/src/evm-vaults/on-chain-calls/admin.d.ts +2 -2
- package/dist/src/evm-vaults/on-chain-calls/onchain-calls.d.ts +3 -3
- package/dist/src/evm-vaults/on-chain-calls/operator.d.ts +2 -2
- package/dist/src/evm-vaults/on-chain-calls/tx-builder.d.ts +22 -3
- package/dist/src/evm-vaults/on-chain-calls/tx-builder.js +49 -0
- package/dist/src/evm-vaults/on-chain-calls/user.d.ts +18 -2
- package/dist/src/evm-vaults/on-chain-calls/user.js +54 -1
- package/dist/src/evm-vaults/on-chain-calls/vault-admin.d.ts +2 -2
- package/dist/src/evm-vaults/on-chain-calls/vault-reader.d.ts +37 -3
- package/dist/src/evm-vaults/on-chain-calls/vault-reader.js +108 -2
- package/dist/src/evm-vaults/utils/deployment-parser.d.ts +14 -8
- package/dist/src/evm-vaults/utils/deployment-parser.js +21 -10
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EVMDeploymentParser } from "../utils/index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { EvmProtocolInfo, VaultPauseOperation, ITransactionCall, IPermitSignature, IOFTSendParam, IOFTMessagingFee } from "../interfaces/index.js";
|
|
3
3
|
import { NumStr } from "../../common/types.js";
|
|
4
4
|
/**
|
|
5
5
|
* EVM Transaction Builder for Ember Protocol (ERC-4626 Compatible)
|
|
@@ -38,12 +38,12 @@ import { NumStr } from "../../common/types.js";
|
|
|
38
38
|
*/
|
|
39
39
|
export declare class EVMTxBuilder {
|
|
40
40
|
parser: EVMDeploymentParser;
|
|
41
|
-
constructor(_deployment:
|
|
41
|
+
constructor(_deployment: EvmProtocolInfo);
|
|
42
42
|
/**
|
|
43
43
|
* Updates the deployment configuration
|
|
44
44
|
* @param newDeployment The new deployment configuration
|
|
45
45
|
*/
|
|
46
|
-
updateDeployment(newDeployment:
|
|
46
|
+
updateDeployment(newDeployment: EvmProtocolInfo): void;
|
|
47
47
|
/**
|
|
48
48
|
* Gets the chain ID from the deployment
|
|
49
49
|
*/
|
|
@@ -310,4 +310,23 @@ export declare class EVMTxBuilder {
|
|
|
310
310
|
* Gets the ERC20Token ABI
|
|
311
311
|
*/
|
|
312
312
|
static getERC20ABI(): unknown[];
|
|
313
|
+
/**
|
|
314
|
+
* Gets the EmberVaultOFTAdapter ABI
|
|
315
|
+
*/
|
|
316
|
+
static getOFTAdapterABI(): unknown[];
|
|
317
|
+
/**
|
|
318
|
+
* Builds the transaction to bridge receipt tokens to another chain via LayerZero OFT.
|
|
319
|
+
*
|
|
320
|
+
* The caller must first:
|
|
321
|
+
* 1. Approve the adapter to spend the receipt token (`approveToken`).
|
|
322
|
+
* 2. Obtain a fee quote (`EVMVaultReader.getOFTFeeQuote`) and pass the result as `fee`.
|
|
323
|
+
* Set `value` on the returned `ITransactionCall` to `fee.nativeFee`.
|
|
324
|
+
*
|
|
325
|
+
* @param adapterAddress The OFT adapter contract address
|
|
326
|
+
* @param sendParam The bridge send parameters (destination, recipient, amounts, options)
|
|
327
|
+
* @param fee The messaging fee (native + LZ token fee) obtained from a prior quote
|
|
328
|
+
* @param refundAddress Address to receive any excess native fee refund
|
|
329
|
+
* @returns Transaction call object
|
|
330
|
+
*/
|
|
331
|
+
bridgeSend(adapterAddress: string, sendParam: IOFTSendParam, fee: IOFTMessagingFee, refundAddress: string): ITransactionCall;
|
|
313
332
|
}
|
|
@@ -3,6 +3,7 @@ import EmberVaultABI from "../../abis/EmberVault.json" with { type: "json" };
|
|
|
3
3
|
import EmberETHVaultABI from "../../abis/EmberETHVault.json" with { type: "json" };
|
|
4
4
|
import EmberProtocolConfigABI from "../../abis/EmberProtocolConfig.json" with { type: "json" };
|
|
5
5
|
import ERC20TokenABI from "../../abis/ERC20Token.json" with { type: "json" };
|
|
6
|
+
import EmberVaultOFTAdapterABI from "../../abis/EmberVaultMintBurnOFTAdapter.json" with { type: "json" };
|
|
6
7
|
/**
|
|
7
8
|
* EVM Transaction Builder for Ember Protocol (ERC-4626 Compatible)
|
|
8
9
|
*
|
|
@@ -654,4 +655,52 @@ export class EVMTxBuilder {
|
|
|
654
655
|
static getERC20ABI() {
|
|
655
656
|
return ERC20TokenABI.abi;
|
|
656
657
|
}
|
|
658
|
+
/**
|
|
659
|
+
* Gets the EmberVaultOFTAdapter ABI
|
|
660
|
+
*/
|
|
661
|
+
static getOFTAdapterABI() {
|
|
662
|
+
return EmberVaultOFTAdapterABI.abi;
|
|
663
|
+
}
|
|
664
|
+
// ============================================
|
|
665
|
+
// Bridge / OFT Methods (LayerZero)
|
|
666
|
+
// ============================================
|
|
667
|
+
/**
|
|
668
|
+
* Builds the transaction to bridge receipt tokens to another chain via LayerZero OFT.
|
|
669
|
+
*
|
|
670
|
+
* The caller must first:
|
|
671
|
+
* 1. Approve the adapter to spend the receipt token (`approveToken`).
|
|
672
|
+
* 2. Obtain a fee quote (`EVMVaultReader.getOFTFeeQuote`) and pass the result as `fee`.
|
|
673
|
+
* Set `value` on the returned `ITransactionCall` to `fee.nativeFee`.
|
|
674
|
+
*
|
|
675
|
+
* @param adapterAddress The OFT adapter contract address
|
|
676
|
+
* @param sendParam The bridge send parameters (destination, recipient, amounts, options)
|
|
677
|
+
* @param fee The messaging fee (native + LZ token fee) obtained from a prior quote
|
|
678
|
+
* @param refundAddress Address to receive any excess native fee refund
|
|
679
|
+
* @returns Transaction call object
|
|
680
|
+
*/
|
|
681
|
+
bridgeSend(adapterAddress, sendParam, fee, refundAddress) {
|
|
682
|
+
return {
|
|
683
|
+
to: adapterAddress,
|
|
684
|
+
functionName: "send",
|
|
685
|
+
args: [
|
|
686
|
+
{
|
|
687
|
+
dstEid: sendParam.dstEid,
|
|
688
|
+
to: sendParam.to,
|
|
689
|
+
amountLD: sendParam.amountLD,
|
|
690
|
+
minAmountLD: sendParam.minAmountLD,
|
|
691
|
+
extraOptions: sendParam.extraOptions ?? "0x",
|
|
692
|
+
composeMsg: sendParam.composeMsg ?? "0x",
|
|
693
|
+
oftCmd: sendParam.oftCmd ?? "0x"
|
|
694
|
+
},
|
|
695
|
+
{
|
|
696
|
+
nativeFee: fee.nativeFee,
|
|
697
|
+
lzTokenFee: fee.lzTokenFee
|
|
698
|
+
},
|
|
699
|
+
refundAddress
|
|
700
|
+
],
|
|
701
|
+
abi: EmberVaultOFTAdapterABI.abi,
|
|
702
|
+
value: fee.nativeFee,
|
|
703
|
+
chainId: this.getChainId()
|
|
704
|
+
};
|
|
705
|
+
}
|
|
657
706
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Signer, Provider } from "ethers";
|
|
2
2
|
import { EVMOnChainCalls } from "./onchain-calls.js";
|
|
3
|
-
import {
|
|
3
|
+
import { EvmProtocolInfo, IUserCallOptions, IEvmCallOptions, EvmOnChainCallResponse, IPermitSignature, IETHDepositOptions, IBridgeSendOptions, IOFTFeeQuote } from "../interfaces/index.js";
|
|
4
4
|
import { NumStr } from "../../common/types.js";
|
|
5
|
+
import { Chain } from "../../api/v2/index.js";
|
|
5
6
|
/**
|
|
6
7
|
* User Calls for Ember Protocol on EVM (ERC-4626 Compatible)
|
|
7
8
|
*
|
|
@@ -49,7 +50,7 @@ import { NumStr } from "../../common/types.js";
|
|
|
49
50
|
* ```
|
|
50
51
|
*/
|
|
51
52
|
export declare class EVMUserCalls extends EVMOnChainCalls {
|
|
52
|
-
constructor(_deployment:
|
|
53
|
+
constructor(_deployment: EvmProtocolInfo, _signer?: Signer, _provider?: Provider, _walletAddress?: string);
|
|
53
54
|
/**
|
|
54
55
|
* Deposit assets into a vault (ERC-4626 standard)
|
|
55
56
|
*
|
|
@@ -225,6 +226,21 @@ export declare class EVMUserCalls extends EVMOnChainCalls {
|
|
|
225
226
|
* @returns EvmOnChainCallResponse
|
|
226
227
|
*/
|
|
227
228
|
approveTokenMax(tokenAddress: string, spender: string, options?: IEvmCallOptions): Promise<EvmOnChainCallResponse>;
|
|
229
|
+
/**
|
|
230
|
+
* Bridges a receipt token to a destination chain using the configured OFT adapter.
|
|
231
|
+
*
|
|
232
|
+
* This method validates allowance, builds the LayerZero send parameters,
|
|
233
|
+
* and executes the adapter send transaction.
|
|
234
|
+
*
|
|
235
|
+
* @param destinationChain Destination chain metadata (must include lzChainId)
|
|
236
|
+
* @param tokenAddress Receipt token address (also used as vault identifier in EVM deployment data)
|
|
237
|
+
* @param amount Amount to bridge in local token decimals
|
|
238
|
+
* @param receiver Recipient wallet address on destination chain
|
|
239
|
+
* @param feeQuote Fee quote returned by reader.getOFTFeeQuote
|
|
240
|
+
* @param options Optional bridge/send overrides
|
|
241
|
+
* @returns Transaction execution response
|
|
242
|
+
*/
|
|
243
|
+
bridgeSendToken(destinationChain: Chain, tokenAddress: string, amount: NumStr, receiver: string, feeQuote: IOFTFeeQuote, options?: IBridgeSendOptions): Promise<EvmOnChainCallResponse>;
|
|
228
244
|
/**
|
|
229
245
|
* Gets the vault contract instance for read operations
|
|
230
246
|
* @param vaultAddress The address of the vault
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Contract } from "ethers";
|
|
1
|
+
import { Contract, ethers } from "ethers";
|
|
2
2
|
import { EVMOnChainCalls } from "./onchain-calls.js";
|
|
3
3
|
import EmberVaultABI from "../../abis/EmberVault.json" with { type: "json" };
|
|
4
4
|
import EmberETHVaultABI from "../../abis/EmberETHVault.json" with { type: "json" };
|
|
5
|
+
import { addressToBytes32 } from "../index.js";
|
|
5
6
|
/**
|
|
6
7
|
* User Calls for Ember Protocol on EVM (ERC-4626 Compatible)
|
|
7
8
|
*
|
|
@@ -284,6 +285,58 @@ export class EVMUserCalls extends EVMOnChainCalls {
|
|
|
284
285
|
return this.approveToken(tokenAddress, spender, maxUint256, options);
|
|
285
286
|
}
|
|
286
287
|
// ============================================
|
|
288
|
+
// Bridge Methods
|
|
289
|
+
// ============================================
|
|
290
|
+
/**
|
|
291
|
+
* Bridges a receipt token to a destination chain using the configured OFT adapter.
|
|
292
|
+
*
|
|
293
|
+
* This method validates allowance, builds the LayerZero send parameters,
|
|
294
|
+
* and executes the adapter send transaction.
|
|
295
|
+
*
|
|
296
|
+
* @param destinationChain Destination chain metadata (must include lzChainId)
|
|
297
|
+
* @param tokenAddress Receipt token address (also used as vault identifier in EVM deployment data)
|
|
298
|
+
* @param amount Amount to bridge in local token decimals
|
|
299
|
+
* @param receiver Recipient wallet address on destination chain
|
|
300
|
+
* @param feeQuote Fee quote returned by reader.getOFTFeeQuote
|
|
301
|
+
* @param options Optional bridge/send overrides
|
|
302
|
+
* @returns Transaction execution response
|
|
303
|
+
*/
|
|
304
|
+
async bridgeSendToken(destinationChain, tokenAddress, amount, receiver, feeQuote, options) {
|
|
305
|
+
if (!this.provider) {
|
|
306
|
+
throw new Error("Provider required for bridge send read operations and allowance checks");
|
|
307
|
+
}
|
|
308
|
+
const adapter = this.parser.getOFTAdapterObjectByVaultId(tokenAddress);
|
|
309
|
+
if (!adapter?.address) {
|
|
310
|
+
throw new Error(`OFT adapter not found for token address: ${tokenAddress}`);
|
|
311
|
+
}
|
|
312
|
+
const refundAddress = options?.refundAddress ?? (await this.getWalletAddress());
|
|
313
|
+
if (destinationChain.lzChainId === undefined ||
|
|
314
|
+
destinationChain.lzChainId === null) {
|
|
315
|
+
throw new Error(`Destination chain "${destinationChain.name ?? destinationChain.identifier}" has no lzChainId — cannot construct sendParam.dstEid`);
|
|
316
|
+
}
|
|
317
|
+
const dstEid = destinationChain.lzChainId;
|
|
318
|
+
const amountBigInt = BigInt(amount);
|
|
319
|
+
const token = new ethers.Contract(tokenAddress, ["function allowance(address,address) view returns (uint256)"], this.provider);
|
|
320
|
+
const currentAllowance = await token.allowance(await this.getWalletAddress(), adapter.address);
|
|
321
|
+
if (currentAllowance < amountBigInt) {
|
|
322
|
+
throw new Error(`Insufficient allowance for bridge transfer. Current allowance: ${currentAllowance}, required: ${amountBigInt}`);
|
|
323
|
+
}
|
|
324
|
+
const sendParam = {
|
|
325
|
+
dstEid,
|
|
326
|
+
to: addressToBytes32(receiver),
|
|
327
|
+
amountLD: amountBigInt,
|
|
328
|
+
minAmountLD: options?.minAmount ?? amountBigInt,
|
|
329
|
+
extraOptions: options?.extraOptions,
|
|
330
|
+
composeMsg: options?.composeMsg,
|
|
331
|
+
oftCmd: options?.oftCmd
|
|
332
|
+
};
|
|
333
|
+
const txCall = this.txBuilder.bridgeSend(adapter.address, sendParam, {
|
|
334
|
+
nativeFee: feeQuote.nativeFee,
|
|
335
|
+
lzTokenFee: options?.payInLzToken ? feeQuote.lzTokenFee : 0n
|
|
336
|
+
}, refundAddress);
|
|
337
|
+
return this.execCall(txCall, options);
|
|
338
|
+
}
|
|
339
|
+
// ============================================
|
|
287
340
|
// Read-Only Methods
|
|
288
341
|
// ============================================
|
|
289
342
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Signer, Provider } from "ethers";
|
|
2
2
|
import { EVMOnChainCalls } from "./onchain-calls.js";
|
|
3
|
-
import {
|
|
3
|
+
import { EvmProtocolInfo, IEvmCallOptions, EvmOnChainCallResponse, VaultPauseOperation } from "../interfaces/index.js";
|
|
4
4
|
import { NumStr } from "../../common/types.js";
|
|
5
5
|
/**
|
|
6
6
|
* Vault Admin Calls for Ember Protocol on EVM
|
|
@@ -35,7 +35,7 @@ import { NumStr } from "../../common/types.js";
|
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
37
|
export declare class EVMVaultAdminCalls extends EVMOnChainCalls {
|
|
38
|
-
constructor(_deployment:
|
|
38
|
+
constructor(_deployment: EvmProtocolInfo, _signer?: Signer, _provider?: Provider, _walletAddress?: string);
|
|
39
39
|
/**
|
|
40
40
|
* Update the operator of a vault
|
|
41
41
|
* @param vaultAddress The address of the vault
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Provider } from "ethers";
|
|
2
2
|
import { EVMDeploymentParser } from "../utils/deployment-parser.js";
|
|
3
|
-
import {
|
|
3
|
+
import { EvmProtocolInfo, IOFTSendParam, IOFTFeeQuote, IOFTVaultSupportedChain } from "../interfaces/index.js";
|
|
4
4
|
import { NumStr } from "../../common/types.js";
|
|
5
|
+
import { Chain, VaultsApi } from "../../api/v2/index.js";
|
|
5
6
|
/**
|
|
6
7
|
* Vault state returned by getVaultState
|
|
7
8
|
*/
|
|
@@ -164,12 +165,15 @@ export interface IUserPosition {
|
|
|
164
165
|
export declare class EVMVaultReader {
|
|
165
166
|
parser: EVMDeploymentParser;
|
|
166
167
|
provider: Provider;
|
|
167
|
-
|
|
168
|
+
vaultsApi: VaultsApi;
|
|
169
|
+
constructor(_deployment: EvmProtocolInfo, _provider: Provider, options?: {
|
|
170
|
+
apiBaseUrl: string;
|
|
171
|
+
});
|
|
168
172
|
/**
|
|
169
173
|
* Updates the deployment configuration
|
|
170
174
|
* @param newDeployment The new deployment configuration
|
|
171
175
|
*/
|
|
172
|
-
updateDeployment(newDeployment:
|
|
176
|
+
updateDeployment(newDeployment: EvmProtocolInfo): void;
|
|
173
177
|
/**
|
|
174
178
|
* Creates an ethers Contract instance for a vault
|
|
175
179
|
* @param vaultAddress The vault address
|
|
@@ -460,4 +464,34 @@ export declare class EVMVaultReader {
|
|
|
460
464
|
* @returns Array of complete vault info for all vaults
|
|
461
465
|
*/
|
|
462
466
|
getAllVaultsInfo(): Promise<ICompleteVaultInfo[]>;
|
|
467
|
+
getOFTAdapterAddressByVaultId(vaultId: string): string | null;
|
|
468
|
+
/**
|
|
469
|
+
* Creates an ethers Contract instance for an OFT adapter
|
|
470
|
+
*/
|
|
471
|
+
private getOFTAdapterContract;
|
|
472
|
+
/**
|
|
473
|
+
* Resolves and instantiates the OFT adapter contract for a vault identifier.
|
|
474
|
+
*
|
|
475
|
+
* @param vaultId Vault identifier (receipt token address on EVM)
|
|
476
|
+
* @returns OFT adapter contract instance, or null if no adapter is configured
|
|
477
|
+
*/
|
|
478
|
+
private getOFTAdapterByVaultId;
|
|
479
|
+
/**
|
|
480
|
+
* Returns the list of destination chains that an OFT adapter has peers configured for.
|
|
481
|
+
*
|
|
482
|
+
* @param vaultId The vault identifier (receipt token address on EVM)
|
|
483
|
+
* @returns Destination chains enriched with OFT adapter and peer metadata
|
|
484
|
+
*/
|
|
485
|
+
getOFTSupportedChains(vaultId: string, supportedChains?: Chain[]): Promise<IOFTVaultSupportedChain[]>;
|
|
486
|
+
/**
|
|
487
|
+
* Gets a fee quote for bridging tokens to another chain via LayerZero OFT.
|
|
488
|
+
* Combines both the messaging fee (quoteSend) and the OFT transfer details
|
|
489
|
+
* (quoteOFT) into a single result.
|
|
490
|
+
*
|
|
491
|
+
* @param vaultId The vault identifier used to resolve the OFT adapter
|
|
492
|
+
* @param sendParam The bridge send parameters
|
|
493
|
+
* @param payInLzToken Whether to pay the fee in the LZ token (default false = pay in native)
|
|
494
|
+
* @returns Combined fee quote including native fee and expected amounts
|
|
495
|
+
*/
|
|
496
|
+
getOFTFeeQuote(vaultId: string, sendParam: IOFTSendParam, payInLzToken?: boolean): Promise<IOFTFeeQuote>;
|
|
463
497
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { Contract } from "ethers";
|
|
1
|
+
import { Contract, isAddress } from "ethers";
|
|
2
2
|
import { EVMDeploymentParser } from "../utils/deployment-parser.js";
|
|
3
3
|
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 EmberVaultOFTAdapterABI from "../../abis/EmberVaultMintBurnOFTAdapter.json" with { type: "json" };
|
|
8
|
+
import { Configuration, VaultsApi } from "../../api/v2/index.js";
|
|
9
|
+
import { environmentConfig } from "../../common/constants.js";
|
|
7
10
|
/**
|
|
8
11
|
* EVM Vault Reader - Read-only operations for Ember Vaults
|
|
9
12
|
*
|
|
@@ -28,9 +31,11 @@ import ERC20TokenABI from "../../abis/ERC20Token.json" with { type: "json" };
|
|
|
28
31
|
* ```
|
|
29
32
|
*/
|
|
30
33
|
export class EVMVaultReader {
|
|
31
|
-
constructor(_deployment, _provider) {
|
|
34
|
+
constructor(_deployment, _provider, options) {
|
|
32
35
|
this.parser = new EVMDeploymentParser(_deployment);
|
|
33
36
|
this.provider = _provider;
|
|
37
|
+
const baseUrl = options?.apiBaseUrl || environmentConfig.prod.apiHost;
|
|
38
|
+
this.vaultsApi = new VaultsApi(new Configuration({ basePath: baseUrl }));
|
|
34
39
|
}
|
|
35
40
|
/**
|
|
36
41
|
* Updates the deployment configuration
|
|
@@ -566,4 +571,105 @@ export class EVMVaultReader {
|
|
|
566
571
|
const addresses = this.getAllVaultAddresses();
|
|
567
572
|
return this.getMultipleVaultsInfo(addresses);
|
|
568
573
|
}
|
|
574
|
+
// ========== Bridge / OFT Methods ==========
|
|
575
|
+
getOFTAdapterAddressByVaultId(vaultId) {
|
|
576
|
+
const adapter = this.parser.getOFTAdapterObjectByVaultId(vaultId);
|
|
577
|
+
if (!adapter?.address) {
|
|
578
|
+
return null;
|
|
579
|
+
}
|
|
580
|
+
// Adapter address in generated models is optional, so validate before use.
|
|
581
|
+
if (!isAddress(adapter.address)) {
|
|
582
|
+
return null;
|
|
583
|
+
}
|
|
584
|
+
return adapter.address;
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Creates an ethers Contract instance for an OFT adapter
|
|
588
|
+
*/
|
|
589
|
+
getOFTAdapterContract(adapterAddress) {
|
|
590
|
+
return new Contract(adapterAddress, EmberVaultOFTAdapterABI.abi, this.provider);
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Resolves and instantiates the OFT adapter contract for a vault identifier.
|
|
594
|
+
*
|
|
595
|
+
* @param vaultId Vault identifier (receipt token address on EVM)
|
|
596
|
+
* @returns OFT adapter contract instance, or null if no adapter is configured
|
|
597
|
+
*/
|
|
598
|
+
getOFTAdapterByVaultId(vaultId) {
|
|
599
|
+
const adapterAddress = this.getOFTAdapterAddressByVaultId(vaultId);
|
|
600
|
+
if (!adapterAddress) {
|
|
601
|
+
return null;
|
|
602
|
+
}
|
|
603
|
+
return this.getOFTAdapterContract(adapterAddress);
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Returns the list of destination chains that an OFT adapter has peers configured for.
|
|
607
|
+
*
|
|
608
|
+
* @param vaultId The vault identifier (receipt token address on EVM)
|
|
609
|
+
* @returns Destination chains enriched with OFT adapter and peer metadata
|
|
610
|
+
*/
|
|
611
|
+
async getOFTSupportedChains(vaultId, supportedChains) {
|
|
612
|
+
const adapter = this.parser.getOFTAdapterObjectByVaultId(vaultId);
|
|
613
|
+
const adapterAddress = this.getOFTAdapterAddressByVaultId(vaultId);
|
|
614
|
+
if (!adapter || !adapterAddress) {
|
|
615
|
+
return [];
|
|
616
|
+
}
|
|
617
|
+
supportedChains =
|
|
618
|
+
supportedChains ?? (await this.vaultsApi.getSupportedChains()).data;
|
|
619
|
+
const chains = [];
|
|
620
|
+
Object.keys(adapter.peers ?? {}).forEach(key => {
|
|
621
|
+
const peer = adapter.peers?.[key];
|
|
622
|
+
const lzChainId = Number(key);
|
|
623
|
+
const chain = supportedChains.find(chain => chain.lzChainId === lzChainId);
|
|
624
|
+
if (!chain) {
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
chains.push({
|
|
628
|
+
...chain,
|
|
629
|
+
adapterAddress,
|
|
630
|
+
vaultId,
|
|
631
|
+
lzEndpointId: lzChainId,
|
|
632
|
+
chainIdentifier: chain.identifier,
|
|
633
|
+
peerAddress: peer.decodedAddress
|
|
634
|
+
});
|
|
635
|
+
});
|
|
636
|
+
return chains;
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Gets a fee quote for bridging tokens to another chain via LayerZero OFT.
|
|
640
|
+
* Combines both the messaging fee (quoteSend) and the OFT transfer details
|
|
641
|
+
* (quoteOFT) into a single result.
|
|
642
|
+
*
|
|
643
|
+
* @param vaultId The vault identifier used to resolve the OFT adapter
|
|
644
|
+
* @param sendParam The bridge send parameters
|
|
645
|
+
* @param payInLzToken Whether to pay the fee in the LZ token (default false = pay in native)
|
|
646
|
+
* @returns Combined fee quote including native fee and expected amounts
|
|
647
|
+
*/
|
|
648
|
+
async getOFTFeeQuote(vaultId, sendParam, payInLzToken = false) {
|
|
649
|
+
const adapter = this.getOFTAdapterByVaultId(vaultId);
|
|
650
|
+
if (!adapter) {
|
|
651
|
+
throw new Error(`OFT adapter not found for vault: ${vaultId}`);
|
|
652
|
+
}
|
|
653
|
+
const param = {
|
|
654
|
+
dstEid: sendParam.dstEid,
|
|
655
|
+
to: sendParam.to,
|
|
656
|
+
amountLD: sendParam.amountLD,
|
|
657
|
+
minAmountLD: sendParam.minAmountLD,
|
|
658
|
+
extraOptions: sendParam.extraOptions ?? "0x",
|
|
659
|
+
composeMsg: sendParam.composeMsg ?? "0x",
|
|
660
|
+
oftCmd: sendParam.oftCmd ?? "0x"
|
|
661
|
+
};
|
|
662
|
+
const [msgFee, oftQuote] = await Promise.all([
|
|
663
|
+
adapter.quoteSend(param, payInLzToken),
|
|
664
|
+
adapter.quoteOFT(param)
|
|
665
|
+
]);
|
|
666
|
+
return {
|
|
667
|
+
nativeFee: msgFee.nativeFee,
|
|
668
|
+
lzTokenFee: msgFee.lzTokenFee,
|
|
669
|
+
amountSentLD: oftQuote.oftReceipt.amountSentLD,
|
|
670
|
+
amountReceivedLD: oftQuote.oftReceipt.amountReceivedLD,
|
|
671
|
+
minAmountLD: oftQuote.oftLimit.minAmountLD,
|
|
672
|
+
maxAmountLD: oftQuote.oftLimit.maxAmountLD
|
|
673
|
+
};
|
|
674
|
+
}
|
|
569
675
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EvmOFTAdapter } from "../../api/v2/index.js";
|
|
2
|
+
import { EvmProtocolInfo } from "../interfaces/index.js";
|
|
2
3
|
export declare class EVMDeploymentParser {
|
|
3
|
-
deployment:
|
|
4
|
-
constructor(_deployment:
|
|
4
|
+
deployment: EvmProtocolInfo;
|
|
5
|
+
constructor(_deployment: EvmProtocolInfo);
|
|
5
6
|
/**
|
|
6
7
|
* Updates the deployment configuration
|
|
7
8
|
* @param newDeployment The new deployment configuration
|
|
8
9
|
*/
|
|
9
|
-
updateDeployment(newDeployment:
|
|
10
|
+
updateDeployment(newDeployment: EvmProtocolInfo): void;
|
|
10
11
|
/**
|
|
11
12
|
* Gets the network name (e.g., "sepolia", "mainnet")
|
|
12
13
|
*/
|
|
@@ -18,15 +19,15 @@ export declare class EVMDeploymentParser {
|
|
|
18
19
|
/**
|
|
19
20
|
* Gets the protocol config proxy address
|
|
20
21
|
*/
|
|
21
|
-
getProtocolConfigAddress(): string;
|
|
22
|
+
getProtocolConfigAddress(): string | undefined;
|
|
22
23
|
/**
|
|
23
24
|
* Gets the protocol config implementation address
|
|
24
25
|
*/
|
|
25
|
-
getProtocolConfigImplementationAddress(): string;
|
|
26
|
+
getProtocolConfigImplementationAddress(): string | undefined;
|
|
26
27
|
/**
|
|
27
28
|
* Gets the protocol config owner address
|
|
28
29
|
*/
|
|
29
|
-
getProtocolConfigOwner(): string;
|
|
30
|
+
getProtocolConfigOwner(): string | undefined;
|
|
30
31
|
/**
|
|
31
32
|
* Gets a receipt token address by its symbol
|
|
32
33
|
* @param symbol The receipt token symbol (e.g., "eUSDC")
|
|
@@ -46,7 +47,7 @@ export declare class EVMDeploymentParser {
|
|
|
46
47
|
* Gets vault info by its proxy address
|
|
47
48
|
* @param vaultAddress The vault's proxy address
|
|
48
49
|
*/
|
|
49
|
-
getVaultByAddress(vaultAddress: string):
|
|
50
|
+
getVaultByAddress(vaultAddress: string): EvmProtocolInfo["contracts"]["vaults"][string];
|
|
50
51
|
/**
|
|
51
52
|
* Gets the base token address for a vault
|
|
52
53
|
* @param vaultAddress The vault's proxy address
|
|
@@ -94,4 +95,9 @@ export declare class EVMDeploymentParser {
|
|
|
94
95
|
* Gets all receipt token symbols
|
|
95
96
|
*/
|
|
96
97
|
getReceiptTokenSymbols(): string[];
|
|
98
|
+
/**
|
|
99
|
+
* Finds the OFT adapter entry for a given vault address.
|
|
100
|
+
* @param vaultAddress The vault address (receipt token address in EVM deployment data)
|
|
101
|
+
*/
|
|
102
|
+
getOFTAdapterObjectByVaultId(vaultAddress: string): EvmOFTAdapter | undefined;
|
|
97
103
|
}
|
|
@@ -25,26 +25,26 @@ export class EVMDeploymentParser {
|
|
|
25
25
|
* Gets the protocol config proxy address
|
|
26
26
|
*/
|
|
27
27
|
getProtocolConfigAddress() {
|
|
28
|
-
return this.deployment.contracts
|
|
28
|
+
return this.deployment.contracts?.protocolConfig.proxyAddress;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
* Gets the protocol config implementation address
|
|
32
32
|
*/
|
|
33
33
|
getProtocolConfigImplementationAddress() {
|
|
34
|
-
return this.deployment.contracts
|
|
34
|
+
return this.deployment.contracts?.protocolConfig.implementationAddress;
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Gets the protocol config owner address
|
|
38
38
|
*/
|
|
39
39
|
getProtocolConfigOwner() {
|
|
40
|
-
return this.deployment.contracts
|
|
40
|
+
return this.deployment.contracts?.protocolConfig.ownerAddress;
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
43
|
* Gets a receipt token address by its symbol
|
|
44
44
|
* @param symbol The receipt token symbol (e.g., "eUSDC")
|
|
45
45
|
*/
|
|
46
46
|
getReceiptTokenAddress(symbol) {
|
|
47
|
-
const receiptToken = this.deployment.contracts
|
|
47
|
+
const receiptToken = this.deployment.contracts?.receiptTokens[symbol];
|
|
48
48
|
if (!receiptToken) {
|
|
49
49
|
throw new Error(`Receipt token not found for symbol: ${symbol}`);
|
|
50
50
|
}
|
|
@@ -55,7 +55,7 @@ export class EVMDeploymentParser {
|
|
|
55
55
|
* @param symbol The receipt token symbol (e.g., "eUSDC")
|
|
56
56
|
*/
|
|
57
57
|
getReceiptTokenDecimals(symbol) {
|
|
58
|
-
const receiptToken = this.deployment.contracts
|
|
58
|
+
const receiptToken = this.deployment.contracts?.receiptTokens[symbol];
|
|
59
59
|
if (!receiptToken) {
|
|
60
60
|
throw new Error(`Receipt token not found for symbol: ${symbol}`);
|
|
61
61
|
}
|
|
@@ -66,7 +66,7 @@ export class EVMDeploymentParser {
|
|
|
66
66
|
* @param vaultKey The vault key (e.g., "emberUsdcVault")
|
|
67
67
|
*/
|
|
68
68
|
getVaultAddress(vaultKey) {
|
|
69
|
-
const vault = this.deployment.contracts
|
|
69
|
+
const vault = this.deployment.contracts?.vaults[vaultKey];
|
|
70
70
|
if (!vault) {
|
|
71
71
|
throw new Error(`Vault not found for key: ${vaultKey}`);
|
|
72
72
|
}
|
|
@@ -77,7 +77,7 @@ export class EVMDeploymentParser {
|
|
|
77
77
|
* @param vaultAddress The vault's proxy address
|
|
78
78
|
*/
|
|
79
79
|
getVaultByAddress(vaultAddress) {
|
|
80
|
-
const vault = Object.values(this.deployment.contracts
|
|
80
|
+
const vault = Object.values(this.deployment.contracts?.vaults ?? {}).find(v => v.proxyAddress.toLowerCase() === vaultAddress.toLowerCase());
|
|
81
81
|
if (!vault) {
|
|
82
82
|
throw new Error(`Vault not found for address: ${vaultAddress}`);
|
|
83
83
|
}
|
|
@@ -143,18 +143,29 @@ export class EVMDeploymentParser {
|
|
|
143
143
|
* Gets all vault keys
|
|
144
144
|
*/
|
|
145
145
|
getVaultKeys() {
|
|
146
|
-
return Object.keys(this.deployment.contracts
|
|
146
|
+
return Object.keys(this.deployment.contracts?.vaults ?? {});
|
|
147
147
|
}
|
|
148
148
|
/**
|
|
149
149
|
* Gets all vault addresses
|
|
150
150
|
*/
|
|
151
151
|
getVaultAddresses() {
|
|
152
|
-
return Object.values(this.deployment.contracts
|
|
152
|
+
return Object.values(this.deployment.contracts?.vaults ?? {}).map(v => v.proxyAddress);
|
|
153
153
|
}
|
|
154
154
|
/**
|
|
155
155
|
* Gets all receipt token symbols
|
|
156
156
|
*/
|
|
157
157
|
getReceiptTokenSymbols() {
|
|
158
|
-
return Object.keys(this.deployment.contracts
|
|
158
|
+
return Object.keys(this.deployment.contracts?.receiptTokens ?? {});
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Finds the OFT adapter entry for a given vault address.
|
|
162
|
+
* @param vaultAddress The vault address (receipt token address in EVM deployment data)
|
|
163
|
+
*/
|
|
164
|
+
getOFTAdapterObjectByVaultId(vaultAddress) {
|
|
165
|
+
const entry = Object.values(this.deployment.contracts?.oftAdapters ?? {}).find(adapter => adapter.vaultAddress?.toLowerCase() === vaultAddress.toLowerCase());
|
|
166
|
+
if (!entry) {
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
return entry;
|
|
159
170
|
}
|
|
160
171
|
}
|