@ember-finance/sdk 1.1.3 → 1.2.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/README.md +169 -2
- package/dist/src/abis/ERC20Token.json +196 -2
- package/dist/src/abis/EmberVault.json +90 -7
- package/dist/src/api/v2/models/chain-vault-details.d.ts +6 -0
- package/dist/src/api/v2/models/vault-slice.d.ts +6 -0
- package/dist/src/ember-vaults.d.ts +9 -0
- package/dist/src/ember-vaults.js +28 -8
- package/dist/src/evm-vaults/interfaces/index.d.ts +13 -0
- package/dist/src/evm-vaults/on-chain-calls/tx-builder.d.ts +19 -1
- package/dist/src/evm-vaults/on-chain-calls/tx-builder.js +50 -0
- package/dist/src/evm-vaults/on-chain-calls/user.d.ts +74 -4
- package/dist/src/evm-vaults/on-chain-calls/user.js +81 -3
- package/dist/src/evm-vaults/utils/index.d.ts +1 -0
- package/dist/src/evm-vaults/utils/index.js +1 -0
- package/dist/src/evm-vaults/utils/permit-utils.d.ts +112 -0
- package/dist/src/evm-vaults/utils/permit-utils.js +226 -0
- package/dist/src/sui-vaults/interfaces/bcs.d.ts +10 -17
- package/package.json +7 -2
package/dist/src/ember-vaults.js
CHANGED
|
@@ -13,8 +13,10 @@ const operator_2 = require("./evm-vaults/on-chain-calls/operator");
|
|
|
13
13
|
const user_2 = require("./evm-vaults/on-chain-calls/user");
|
|
14
14
|
const vault_admin_2 = require("./evm-vaults/on-chain-calls/vault-admin");
|
|
15
15
|
const deployment_parser_2 = require("./evm-vaults/utils/deployment-parser");
|
|
16
|
+
const vault_reader_1 = require("./evm-vaults/on-chain-calls/vault-reader");
|
|
16
17
|
// API imports
|
|
17
18
|
const api_1 = require("./api");
|
|
19
|
+
const v2_1 = require("./api/v2");
|
|
18
20
|
const environmentConfig = {
|
|
19
21
|
prod: {
|
|
20
22
|
apiHost: "https://vaults.api.sui-prod.bluefin.io"
|
|
@@ -54,11 +56,14 @@ const environmentConfig = {
|
|
|
54
56
|
class EmberVaults {
|
|
55
57
|
constructor(options) {
|
|
56
58
|
this.chainType = options.chainType;
|
|
59
|
+
this._chainIdentifier = options.chainIdentifier;
|
|
57
60
|
this._walletAddress = options.walletAddress;
|
|
58
61
|
const environment = options.environment ?? "prod";
|
|
59
62
|
this.apiHost = options.basePath || environmentConfig[environment].apiHost;
|
|
60
63
|
this.api = new api_1.AccountsApi(new api_1.Configuration({ basePath: this.apiHost }));
|
|
61
64
|
this.vaultsApi = new api_1.VaultsApi(new api_1.Configuration({ basePath: this.apiHost }));
|
|
65
|
+
this.accountsV2Api = new v2_1.AccountsApi(new v2_1.Configuration({ basePath: this.apiHost }));
|
|
66
|
+
this.vaultsV2Api = new v2_1.VaultsApi(new v2_1.Configuration({ basePath: this.apiHost }));
|
|
62
67
|
if (options.chainType === "sui") {
|
|
63
68
|
this._initSui(options);
|
|
64
69
|
}
|
|
@@ -89,18 +94,31 @@ class EmberVaults {
|
|
|
89
94
|
this._evmOperator = new operator_2.EVMOperatorCalls(this._evmDeployment, options.signer, options.provider, options.walletAddress);
|
|
90
95
|
this._evmVaultAdmin = new vault_admin_2.EVMVaultAdminCalls(this._evmDeployment, options.signer, options.provider, options.walletAddress);
|
|
91
96
|
this._evmUser = new user_2.EVMUserCalls(this._evmDeployment, options.signer, options.provider, options.walletAddress);
|
|
97
|
+
this._evmVaultReader = new vault_reader_1.EVMVaultReader(this._evmDeployment, options.provider);
|
|
92
98
|
}
|
|
93
99
|
/**
|
|
94
100
|
* Initialize by fetching deployment from API (SUI only currently)
|
|
95
101
|
*/
|
|
96
102
|
async init() {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
const deployment = await this.vaultsV2Api.getVaultsProtocolInfo();
|
|
104
|
+
if (this.chainType === "sui") {
|
|
105
|
+
const deploymentData = deployment.data.find(d => d.chainType === "sui");
|
|
106
|
+
if (deploymentData) {
|
|
107
|
+
this.updateDeployment(deploymentData.config);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
throw new Error(`Deployment data not found for chain ${this._chainIdentifier}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
const deploymentData = deployment.data.find(d => d.chainType === "evm" && d.chain === this._chainIdentifier);
|
|
115
|
+
if (deploymentData) {
|
|
116
|
+
this.updateDeployment(deploymentData.config);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
throw new Error(`Deployment data not found for chain ${this._chainIdentifier}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
104
122
|
}
|
|
105
123
|
/**
|
|
106
124
|
* Updates the deployment configuration
|
|
@@ -126,6 +144,7 @@ class EmberVaults {
|
|
|
126
144
|
this._evmOperator?.updateDeployment(evmDeployment);
|
|
127
145
|
this._evmVaultAdmin?.updateDeployment(evmDeployment);
|
|
128
146
|
this._evmUser?.updateDeployment(evmDeployment);
|
|
147
|
+
this._evmVaultReader?.updateDeployment(evmDeployment);
|
|
129
148
|
}
|
|
130
149
|
}
|
|
131
150
|
// ============================================
|
|
@@ -232,7 +251,8 @@ class EmberVaults {
|
|
|
232
251
|
operator: this._evmOperator,
|
|
233
252
|
vaultAdmin: this._evmVaultAdmin,
|
|
234
253
|
user: this._evmUser,
|
|
235
|
-
deployment: this._evmDeployment
|
|
254
|
+
deployment: this._evmDeployment,
|
|
255
|
+
reader: this._evmVaultReader
|
|
236
256
|
};
|
|
237
257
|
}
|
|
238
258
|
}
|
|
@@ -124,6 +124,19 @@ export interface IUserCallOptions extends IEvmCallOptions {
|
|
|
124
124
|
/** Receiver address for shares/funds. Defaults to the caller's address if not provided */
|
|
125
125
|
receiver?: string;
|
|
126
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* EIP-2612 Permit signature components
|
|
129
|
+
*/
|
|
130
|
+
export interface IPermitSignature {
|
|
131
|
+
/** Deadline timestamp for the permit (in seconds) */
|
|
132
|
+
deadline: bigint;
|
|
133
|
+
/** v component of the signature */
|
|
134
|
+
v: number;
|
|
135
|
+
/** r component of the signature */
|
|
136
|
+
r: string;
|
|
137
|
+
/** s component of the signature */
|
|
138
|
+
s: string;
|
|
139
|
+
}
|
|
127
140
|
/**
|
|
128
141
|
* Parsed event from a transaction
|
|
129
142
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EVMDeploymentParser } from "../utils";
|
|
2
|
-
import { IEvmDeployment, VaultPauseOperation, ITransactionCall } from "../interfaces";
|
|
2
|
+
import { IEvmDeployment, VaultPauseOperation, ITransactionCall, IPermitSignature } from "../interfaces";
|
|
3
3
|
import { NumStr } from "../../common/types";
|
|
4
4
|
/**
|
|
5
5
|
* EVM Transaction Builder for Ember Protocol (ERC-4626 Compatible)
|
|
@@ -204,6 +204,15 @@ export declare class EVMTxBuilder {
|
|
|
204
204
|
* @returns Transaction call object
|
|
205
205
|
*/
|
|
206
206
|
deposit(vaultAddress: string, assets: NumStr, receiver: string): ITransactionCall;
|
|
207
|
+
/**
|
|
208
|
+
* Deposits assets to a vault using EIP-2612 permit (no separate approval needed)
|
|
209
|
+
* @param vaultAddress Address of the vault
|
|
210
|
+
* @param assets Amount of assets to deposit
|
|
211
|
+
* @param receiver Address to receive the shares
|
|
212
|
+
* @param permitSignature The EIP-2612 permit signature
|
|
213
|
+
* @returns Transaction call object
|
|
214
|
+
*/
|
|
215
|
+
depositWithPermit(vaultAddress: string, assets: NumStr, receiver: string, permitSignature: IPermitSignature): ITransactionCall;
|
|
207
216
|
/**
|
|
208
217
|
* Mints a specific number of shares by depositing assets (ERC-4626 standard)
|
|
209
218
|
* @param vaultAddress Address of the vault
|
|
@@ -212,6 +221,15 @@ export declare class EVMTxBuilder {
|
|
|
212
221
|
* @returns Transaction call object
|
|
213
222
|
*/
|
|
214
223
|
mint(vaultAddress: string, shares: NumStr, receiver: string): ITransactionCall;
|
|
224
|
+
/**
|
|
225
|
+
* Mints a specific number of shares using EIP-2612 permit (no separate approval needed)
|
|
226
|
+
* @param vaultAddress Address of the vault
|
|
227
|
+
* @param shares Amount of shares to mint
|
|
228
|
+
* @param receiver Address to receive the shares
|
|
229
|
+
* @param permitSignature The EIP-2612 permit signature
|
|
230
|
+
* @returns Transaction call object
|
|
231
|
+
*/
|
|
232
|
+
mintWithPermit(vaultAddress: string, shares: NumStr, receiver: string, permitSignature: IPermitSignature): ITransactionCall;
|
|
215
233
|
/**
|
|
216
234
|
* Redeems shares to initiate a withdrawal request
|
|
217
235
|
* @param vaultAddress Address of the vault
|
|
@@ -447,6 +447,31 @@ class EVMTxBuilder {
|
|
|
447
447
|
chainId: this.getChainId()
|
|
448
448
|
};
|
|
449
449
|
}
|
|
450
|
+
/**
|
|
451
|
+
* Deposits assets to a vault using EIP-2612 permit (no separate approval needed)
|
|
452
|
+
* @param vaultAddress Address of the vault
|
|
453
|
+
* @param assets Amount of assets to deposit
|
|
454
|
+
* @param receiver Address to receive the shares
|
|
455
|
+
* @param permitSignature The EIP-2612 permit signature
|
|
456
|
+
* @returns Transaction call object
|
|
457
|
+
*/
|
|
458
|
+
depositWithPermit(vaultAddress, assets, receiver, permitSignature) {
|
|
459
|
+
return {
|
|
460
|
+
to: vaultAddress,
|
|
461
|
+
functionName: "depositWithPermit",
|
|
462
|
+
args: [
|
|
463
|
+
BigInt(assets),
|
|
464
|
+
receiver,
|
|
465
|
+
BigInt(permitSignature.deadline),
|
|
466
|
+
permitSignature.v,
|
|
467
|
+
permitSignature.r,
|
|
468
|
+
permitSignature.s
|
|
469
|
+
],
|
|
470
|
+
abi: EmberVault_json_1.default.abi,
|
|
471
|
+
value: 0n,
|
|
472
|
+
chainId: this.getChainId()
|
|
473
|
+
};
|
|
474
|
+
}
|
|
450
475
|
/**
|
|
451
476
|
* Mints a specific number of shares by depositing assets (ERC-4626 standard)
|
|
452
477
|
* @param vaultAddress Address of the vault
|
|
@@ -464,6 +489,31 @@ class EVMTxBuilder {
|
|
|
464
489
|
chainId: this.getChainId()
|
|
465
490
|
};
|
|
466
491
|
}
|
|
492
|
+
/**
|
|
493
|
+
* Mints a specific number of shares using EIP-2612 permit (no separate approval needed)
|
|
494
|
+
* @param vaultAddress Address of the vault
|
|
495
|
+
* @param shares Amount of shares to mint
|
|
496
|
+
* @param receiver Address to receive the shares
|
|
497
|
+
* @param permitSignature The EIP-2612 permit signature
|
|
498
|
+
* @returns Transaction call object
|
|
499
|
+
*/
|
|
500
|
+
mintWithPermit(vaultAddress, shares, receiver, permitSignature) {
|
|
501
|
+
return {
|
|
502
|
+
to: vaultAddress,
|
|
503
|
+
functionName: "mintWithPermit",
|
|
504
|
+
args: [
|
|
505
|
+
BigInt(shares),
|
|
506
|
+
receiver,
|
|
507
|
+
BigInt(permitSignature.deadline),
|
|
508
|
+
permitSignature.v,
|
|
509
|
+
permitSignature.r,
|
|
510
|
+
permitSignature.s
|
|
511
|
+
],
|
|
512
|
+
abi: EmberVault_json_1.default.abi,
|
|
513
|
+
value: 0n,
|
|
514
|
+
chainId: this.getChainId()
|
|
515
|
+
};
|
|
516
|
+
}
|
|
467
517
|
/**
|
|
468
518
|
* Redeems shares to initiate a withdrawal request
|
|
469
519
|
* @param vaultAddress Address of the vault
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Signer, Provider } from "ethers";
|
|
2
2
|
import { EVMOnChainCalls } from "./onchain-calls";
|
|
3
|
-
import { IEvmDeployment, IUserCallOptions, IEvmCallOptions, EvmOnChainCallResponse } from "../interfaces";
|
|
3
|
+
import { IEvmDeployment, IUserCallOptions, IEvmCallOptions, EvmOnChainCallResponse, IPermitSignature } from "../interfaces";
|
|
4
4
|
import { NumStr } from "../../common/types";
|
|
5
5
|
/**
|
|
6
6
|
* User Calls for Ember Protocol on EVM (ERC-4626 Compatible)
|
|
@@ -10,7 +10,9 @@ import { NumStr } from "../../common/types";
|
|
|
10
10
|
*
|
|
11
11
|
* Users can:
|
|
12
12
|
* - deposit: Deposit assets and receive shares (ERC-4626)
|
|
13
|
+
* - depositWithPermit: Deposit assets using EIP-2612 permit (no separate approval needed)
|
|
13
14
|
* - mint: Mint a specific number of shares by depositing assets (ERC-4626)
|
|
15
|
+
* - mintWithPermit: Mint shares using EIP-2612 permit (no separate approval needed)
|
|
14
16
|
* - redeemShares: Initiate a withdrawal request by redeeming shares
|
|
15
17
|
* - cancelPendingWithdrawalRequest: Cancel a pending withdrawal
|
|
16
18
|
*
|
|
@@ -28,12 +30,14 @@ import { NumStr } from "../../common/types";
|
|
|
28
30
|
*
|
|
29
31
|
* const userCalls = new EVMUserCalls(deployment, signer, provider);
|
|
30
32
|
*
|
|
31
|
-
* // Approve token spending first
|
|
33
|
+
* // Traditional approach: Approve token spending first, then deposit
|
|
32
34
|
* await userCalls.approveToken(underlyingAsset, vaultAddress, amount);
|
|
33
|
-
*
|
|
34
|
-
* // Deposit assets (receiver defaults to caller)
|
|
35
35
|
* await userCalls.deposit(vaultAddress, amount);
|
|
36
36
|
*
|
|
37
|
+
* // New approach: Use permit to deposit in single transaction (no approval needed)
|
|
38
|
+
* const permitSig = await signPermit(signer, tokenAddress, vaultAddress, amount, deadline);
|
|
39
|
+
* await userCalls.depositWithPermit(vaultAddress, amount, permitSig);
|
|
40
|
+
*
|
|
37
41
|
* // Deposit assets to a different receiver
|
|
38
42
|
* await userCalls.deposit(vaultAddress, amount, { receiver: otherAddress });
|
|
39
43
|
*
|
|
@@ -58,6 +62,39 @@ export declare class EVMUserCalls extends EVMOnChainCalls {
|
|
|
58
62
|
* @returns EvmOnChainCallResponse
|
|
59
63
|
*/
|
|
60
64
|
deposit(vaultAddress: string, assets: NumStr, options?: IUserCallOptions): Promise<EvmOnChainCallResponse>;
|
|
65
|
+
/**
|
|
66
|
+
* Deposit assets into a vault using EIP-2612 permit (no separate approval needed)
|
|
67
|
+
*
|
|
68
|
+
* This method allows depositing in a single transaction by including a permit signature.
|
|
69
|
+
* The permit signature authorizes the vault to spend the underlying asset without requiring
|
|
70
|
+
* a separate approve transaction.
|
|
71
|
+
*
|
|
72
|
+
* @param vaultAddress The address of the vault
|
|
73
|
+
* @param assets The amount of assets to deposit
|
|
74
|
+
* @param permitSignature The EIP-2612 permit signature components
|
|
75
|
+
* @param options Optional tx execution params (includes optional receiver, defaults to caller)
|
|
76
|
+
* @returns EvmOnChainCallResponse
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* // Generate permit signature (see signPermit utility)
|
|
81
|
+
* const permitSig = await signPermit(
|
|
82
|
+
* signer,
|
|
83
|
+
* tokenAddress,
|
|
84
|
+
* vaultAddress,
|
|
85
|
+
* amount,
|
|
86
|
+
* deadline
|
|
87
|
+
* );
|
|
88
|
+
*
|
|
89
|
+
* // Deposit with permit in single transaction
|
|
90
|
+
* await userCalls.depositWithPermit(
|
|
91
|
+
* vaultAddress,
|
|
92
|
+
* amount,
|
|
93
|
+
* permitSig
|
|
94
|
+
* );
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
depositWithPermit(vaultAddress: string, assets: NumStr, permitSignature: IPermitSignature, options?: IUserCallOptions): Promise<EvmOnChainCallResponse>;
|
|
61
98
|
/**
|
|
62
99
|
* Mint a specific number of shares by depositing assets (ERC-4626 standard)
|
|
63
100
|
*
|
|
@@ -70,6 +107,39 @@ export declare class EVMUserCalls extends EVMOnChainCalls {
|
|
|
70
107
|
* @returns EvmOnChainCallResponse
|
|
71
108
|
*/
|
|
72
109
|
mint(vaultAddress: string, shares: NumStr, options?: IUserCallOptions): Promise<EvmOnChainCallResponse>;
|
|
110
|
+
/**
|
|
111
|
+
* Mint a specific number of shares using EIP-2612 permit (no separate approval needed)
|
|
112
|
+
*
|
|
113
|
+
* This method allows minting shares in a single transaction by including a permit signature.
|
|
114
|
+
* The permit signature authorizes the vault to spend the required underlying assets without
|
|
115
|
+
* requiring a separate approve transaction.
|
|
116
|
+
*
|
|
117
|
+
* @param vaultAddress The address of the vault
|
|
118
|
+
* @param shares The number of shares to mint
|
|
119
|
+
* @param permitSignature The EIP-2612 permit signature components
|
|
120
|
+
* @param options Optional tx execution params (includes optional receiver, defaults to caller)
|
|
121
|
+
* @returns EvmOnChainCallResponse
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* // Generate permit signature (see signPermit utility)
|
|
126
|
+
* const permitSig = await signPermit(
|
|
127
|
+
* signer,
|
|
128
|
+
* tokenAddress,
|
|
129
|
+
* vaultAddress,
|
|
130
|
+
* maxAmount, // Use high amount or max for mint since exact amount is calculated by vault
|
|
131
|
+
* deadline
|
|
132
|
+
* );
|
|
133
|
+
*
|
|
134
|
+
* // Mint shares with permit in single transaction
|
|
135
|
+
* await userCalls.mintWithPermit(
|
|
136
|
+
* vaultAddress,
|
|
137
|
+
* shares,
|
|
138
|
+
* permitSig
|
|
139
|
+
* );
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
mintWithPermit(vaultAddress: string, shares: NumStr, permitSignature: IPermitSignature, options?: IUserCallOptions): Promise<EvmOnChainCallResponse>;
|
|
73
143
|
/**
|
|
74
144
|
* Redeem shares to initiate a withdrawal request
|
|
75
145
|
*
|
|
@@ -15,7 +15,9 @@ const EmberVault_json_1 = __importDefault(require("../../abis/EmberVault.json"))
|
|
|
15
15
|
*
|
|
16
16
|
* Users can:
|
|
17
17
|
* - deposit: Deposit assets and receive shares (ERC-4626)
|
|
18
|
+
* - depositWithPermit: Deposit assets using EIP-2612 permit (no separate approval needed)
|
|
18
19
|
* - mint: Mint a specific number of shares by depositing assets (ERC-4626)
|
|
20
|
+
* - mintWithPermit: Mint shares using EIP-2612 permit (no separate approval needed)
|
|
19
21
|
* - redeemShares: Initiate a withdrawal request by redeeming shares
|
|
20
22
|
* - cancelPendingWithdrawalRequest: Cancel a pending withdrawal
|
|
21
23
|
*
|
|
@@ -33,12 +35,14 @@ const EmberVault_json_1 = __importDefault(require("../../abis/EmberVault.json"))
|
|
|
33
35
|
*
|
|
34
36
|
* const userCalls = new EVMUserCalls(deployment, signer, provider);
|
|
35
37
|
*
|
|
36
|
-
* // Approve token spending first
|
|
38
|
+
* // Traditional approach: Approve token spending first, then deposit
|
|
37
39
|
* await userCalls.approveToken(underlyingAsset, vaultAddress, amount);
|
|
38
|
-
*
|
|
39
|
-
* // Deposit assets (receiver defaults to caller)
|
|
40
40
|
* await userCalls.deposit(vaultAddress, amount);
|
|
41
41
|
*
|
|
42
|
+
* // New approach: Use permit to deposit in single transaction (no approval needed)
|
|
43
|
+
* const permitSig = await signPermit(signer, tokenAddress, vaultAddress, amount, deadline);
|
|
44
|
+
* await userCalls.depositWithPermit(vaultAddress, amount, permitSig);
|
|
45
|
+
*
|
|
42
46
|
* // Deposit assets to a different receiver
|
|
43
47
|
* await userCalls.deposit(vaultAddress, amount, { receiver: otherAddress });
|
|
44
48
|
*
|
|
@@ -72,6 +76,43 @@ class EVMUserCalls extends onchain_calls_1.EVMOnChainCalls {
|
|
|
72
76
|
const txCall = this.txBuilder.deposit(vaultAddress, assets, receiver);
|
|
73
77
|
return this.execCall(txCall, options);
|
|
74
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Deposit assets into a vault using EIP-2612 permit (no separate approval needed)
|
|
81
|
+
*
|
|
82
|
+
* This method allows depositing in a single transaction by including a permit signature.
|
|
83
|
+
* The permit signature authorizes the vault to spend the underlying asset without requiring
|
|
84
|
+
* a separate approve transaction.
|
|
85
|
+
*
|
|
86
|
+
* @param vaultAddress The address of the vault
|
|
87
|
+
* @param assets The amount of assets to deposit
|
|
88
|
+
* @param permitSignature The EIP-2612 permit signature components
|
|
89
|
+
* @param options Optional tx execution params (includes optional receiver, defaults to caller)
|
|
90
|
+
* @returns EvmOnChainCallResponse
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* // Generate permit signature (see signPermit utility)
|
|
95
|
+
* const permitSig = await signPermit(
|
|
96
|
+
* signer,
|
|
97
|
+
* tokenAddress,
|
|
98
|
+
* vaultAddress,
|
|
99
|
+
* amount,
|
|
100
|
+
* deadline
|
|
101
|
+
* );
|
|
102
|
+
*
|
|
103
|
+
* // Deposit with permit in single transaction
|
|
104
|
+
* await userCalls.depositWithPermit(
|
|
105
|
+
* vaultAddress,
|
|
106
|
+
* amount,
|
|
107
|
+
* permitSig
|
|
108
|
+
* );
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
async depositWithPermit(vaultAddress, assets, permitSignature, options) {
|
|
112
|
+
const receiver = options?.receiver ?? (await this.getWalletAddress());
|
|
113
|
+
const txCall = this.txBuilder.depositWithPermit(vaultAddress, assets, receiver, permitSignature);
|
|
114
|
+
return this.execCall(txCall, options);
|
|
115
|
+
}
|
|
75
116
|
// ============================================
|
|
76
117
|
// Mint Methods (ERC-4626)
|
|
77
118
|
// ============================================
|
|
@@ -91,6 +132,43 @@ class EVMUserCalls extends onchain_calls_1.EVMOnChainCalls {
|
|
|
91
132
|
const txCall = this.txBuilder.mint(vaultAddress, shares, receiver);
|
|
92
133
|
return this.execCall(txCall, options);
|
|
93
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Mint a specific number of shares using EIP-2612 permit (no separate approval needed)
|
|
137
|
+
*
|
|
138
|
+
* This method allows minting shares in a single transaction by including a permit signature.
|
|
139
|
+
* The permit signature authorizes the vault to spend the required underlying assets without
|
|
140
|
+
* requiring a separate approve transaction.
|
|
141
|
+
*
|
|
142
|
+
* @param vaultAddress The address of the vault
|
|
143
|
+
* @param shares The number of shares to mint
|
|
144
|
+
* @param permitSignature The EIP-2612 permit signature components
|
|
145
|
+
* @param options Optional tx execution params (includes optional receiver, defaults to caller)
|
|
146
|
+
* @returns EvmOnChainCallResponse
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* // Generate permit signature (see signPermit utility)
|
|
151
|
+
* const permitSig = await signPermit(
|
|
152
|
+
* signer,
|
|
153
|
+
* tokenAddress,
|
|
154
|
+
* vaultAddress,
|
|
155
|
+
* maxAmount, // Use high amount or max for mint since exact amount is calculated by vault
|
|
156
|
+
* deadline
|
|
157
|
+
* );
|
|
158
|
+
*
|
|
159
|
+
* // Mint shares with permit in single transaction
|
|
160
|
+
* await userCalls.mintWithPermit(
|
|
161
|
+
* vaultAddress,
|
|
162
|
+
* shares,
|
|
163
|
+
* permitSig
|
|
164
|
+
* );
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
async mintWithPermit(vaultAddress, shares, permitSignature, options) {
|
|
168
|
+
const receiver = options?.receiver ?? (await this.getWalletAddress());
|
|
169
|
+
const txCall = this.txBuilder.mintWithPermit(vaultAddress, shares, receiver, permitSignature);
|
|
170
|
+
return this.execCall(txCall, options);
|
|
171
|
+
}
|
|
94
172
|
// ============================================
|
|
95
173
|
// Redemption Methods
|
|
96
174
|
// ============================================
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Signer } from "ethers";
|
|
2
|
+
import { IPermitSignature } from "../interfaces";
|
|
3
|
+
import { NumStr } from "../../common/types";
|
|
4
|
+
/**
|
|
5
|
+
* Signs an EIP-2612 permit message
|
|
6
|
+
*
|
|
7
|
+
* This creates an off-chain signature that authorizes a spender (vault) to spend
|
|
8
|
+
* tokens on behalf of the owner without requiring a separate approval transaction.
|
|
9
|
+
*
|
|
10
|
+
* @param signer The ethers.js signer
|
|
11
|
+
* @param tokenAddress The address of the ERC20 token (must support EIP-2612)
|
|
12
|
+
* @param tokenName The name of the token (for domain separator)
|
|
13
|
+
* @param spender The address authorized to spend (usually the vault address)
|
|
14
|
+
* @param value The amount of tokens to approve
|
|
15
|
+
* @param deadline The deadline timestamp (in seconds) for the permit
|
|
16
|
+
* @param nonce The current permit nonce for the owner (fetch from token.nonces(owner))
|
|
17
|
+
* @param chainId The chain ID
|
|
18
|
+
* @param version Optional version string for the domain separator (fetched from token if not provided)
|
|
19
|
+
* @returns The permit signature components
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { signPermit } from "@ember-finance/sdk";
|
|
24
|
+
*
|
|
25
|
+
* const deadline = Math.floor(Date.now() / 1000) + 3600; // 1 hour from now
|
|
26
|
+
* const tokenContract = new ethers.Contract(tokenAddress, erc20Abi, provider);
|
|
27
|
+
* const nonce = await tokenContract.nonces(await signer.getAddress());
|
|
28
|
+
*
|
|
29
|
+
* const permitSig = await signPermit(
|
|
30
|
+
* signer,
|
|
31
|
+
* tokenAddress,
|
|
32
|
+
* "USD Coin", // token name
|
|
33
|
+
* vaultAddress,
|
|
34
|
+
* amount,
|
|
35
|
+
* BigInt(deadline),
|
|
36
|
+
* nonce,
|
|
37
|
+
* BigInt(1) // Ethereum mainnet
|
|
38
|
+
* );
|
|
39
|
+
*
|
|
40
|
+
* // Use with depositWithPermit
|
|
41
|
+
* await userCalls.depositWithPermit(vaultAddress, amount, permitSig);
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function signPermit(signer: Signer, tokenAddress: string, tokenName: string, spender: string, value: NumStr, deadline: bigint, nonce: bigint, chainId: bigint, version?: string): Promise<IPermitSignature>;
|
|
45
|
+
/**
|
|
46
|
+
* Helper function to get the permit version from an EIP-2612 token
|
|
47
|
+
*
|
|
48
|
+
* @param tokenAddress The address of the ERC20 token
|
|
49
|
+
* @param provider An ethers.js provider
|
|
50
|
+
* @returns The version string (e.g., "1", "2"), defaults to "1" if version() not implemented
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* import { getPermitVersion } from "@ember-finance/sdk";
|
|
55
|
+
*
|
|
56
|
+
* const version = await getPermitVersion(tokenAddress, provider);
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function getPermitVersion(tokenAddress: string, provider: import("ethers").Provider): Promise<string>;
|
|
60
|
+
/**
|
|
61
|
+
* Helper function to get the current nonce for a user from an EIP-2612 token
|
|
62
|
+
*
|
|
63
|
+
* @param tokenAddress The address of the ERC20 token
|
|
64
|
+
* @param ownerAddress The address of the token owner
|
|
65
|
+
* @param provider An ethers.js provider
|
|
66
|
+
* @returns The current nonce
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* import { getPermitNonce } from "@ember-finance/sdk";
|
|
71
|
+
*
|
|
72
|
+
* const nonce = await getPermitNonce(
|
|
73
|
+
* tokenAddress,
|
|
74
|
+
* await signer.getAddress(),
|
|
75
|
+
* provider
|
|
76
|
+
* );
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function getPermitNonce(tokenAddress: string, ownerAddress: string, provider: import("ethers").Provider): Promise<bigint>;
|
|
80
|
+
/**
|
|
81
|
+
* Helper function to create a permit signature with sensible defaults
|
|
82
|
+
*
|
|
83
|
+
* This is a convenience function that:
|
|
84
|
+
* - Fetches the current nonce automatically
|
|
85
|
+
* - Fetches the version from the token contract
|
|
86
|
+
* - Sets a deadline of 1 hour from now
|
|
87
|
+
* - Gets the chain ID from the signer
|
|
88
|
+
*
|
|
89
|
+
* @param signer The ethers.js signer (must be connected to a provider)
|
|
90
|
+
* @param tokenAddress The address of the ERC20 token (must support EIP-2612)
|
|
91
|
+
* @param tokenName The name of the token (for domain separator)
|
|
92
|
+
* @param spender The address authorized to spend (usually the vault address)
|
|
93
|
+
* @param value The amount of tokens to approve
|
|
94
|
+
* @returns The permit signature components
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* import { signPermitSimple } from "@ember-finance/sdk";
|
|
99
|
+
*
|
|
100
|
+
* // Simplified permit signing (fetches nonce, version, sets 1 hour deadline automatically)
|
|
101
|
+
* const permitSig = await signPermitSimple(
|
|
102
|
+
* signer,
|
|
103
|
+
* tokenAddress,
|
|
104
|
+
* "USD Coin",
|
|
105
|
+
* vaultAddress,
|
|
106
|
+
* amount
|
|
107
|
+
* );
|
|
108
|
+
*
|
|
109
|
+
* await userCalls.depositWithPermit(vaultAddress, amount, permitSig);
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export declare function signPermitSimple(signer: Signer, tokenAddress: string, tokenName: string, spender: string, value: NumStr): Promise<IPermitSignature>;
|