@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
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.signPermit = signPermit;
|
|
37
|
+
exports.getPermitVersion = getPermitVersion;
|
|
38
|
+
exports.getPermitNonce = getPermitNonce;
|
|
39
|
+
exports.signPermitSimple = signPermitSimple;
|
|
40
|
+
/**
|
|
41
|
+
* Signs an EIP-2612 permit message
|
|
42
|
+
*
|
|
43
|
+
* This creates an off-chain signature that authorizes a spender (vault) to spend
|
|
44
|
+
* tokens on behalf of the owner without requiring a separate approval transaction.
|
|
45
|
+
*
|
|
46
|
+
* @param signer The ethers.js signer
|
|
47
|
+
* @param tokenAddress The address of the ERC20 token (must support EIP-2612)
|
|
48
|
+
* @param tokenName The name of the token (for domain separator)
|
|
49
|
+
* @param spender The address authorized to spend (usually the vault address)
|
|
50
|
+
* @param value The amount of tokens to approve
|
|
51
|
+
* @param deadline The deadline timestamp (in seconds) for the permit
|
|
52
|
+
* @param nonce The current permit nonce for the owner (fetch from token.nonces(owner))
|
|
53
|
+
* @param chainId The chain ID
|
|
54
|
+
* @param version Optional version string for the domain separator (fetched from token if not provided)
|
|
55
|
+
* @returns The permit signature components
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* import { signPermit } from "@ember-finance/sdk";
|
|
60
|
+
*
|
|
61
|
+
* const deadline = Math.floor(Date.now() / 1000) + 3600; // 1 hour from now
|
|
62
|
+
* const tokenContract = new ethers.Contract(tokenAddress, erc20Abi, provider);
|
|
63
|
+
* const nonce = await tokenContract.nonces(await signer.getAddress());
|
|
64
|
+
*
|
|
65
|
+
* const permitSig = await signPermit(
|
|
66
|
+
* signer,
|
|
67
|
+
* tokenAddress,
|
|
68
|
+
* "USD Coin", // token name
|
|
69
|
+
* vaultAddress,
|
|
70
|
+
* amount,
|
|
71
|
+
* BigInt(deadline),
|
|
72
|
+
* nonce,
|
|
73
|
+
* BigInt(1) // Ethereum mainnet
|
|
74
|
+
* );
|
|
75
|
+
*
|
|
76
|
+
* // Use with depositWithPermit
|
|
77
|
+
* await userCalls.depositWithPermit(vaultAddress, amount, permitSig);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
async function signPermit(signer, tokenAddress, tokenName, spender, value, deadline, nonce, chainId, version) {
|
|
81
|
+
const owner = await signer.getAddress();
|
|
82
|
+
// If version not provided, fetch it from the token contract
|
|
83
|
+
let permitVersion = version;
|
|
84
|
+
if (!permitVersion) {
|
|
85
|
+
const provider = signer.provider;
|
|
86
|
+
if (!provider) {
|
|
87
|
+
throw new Error("Signer must be connected to a provider to fetch version");
|
|
88
|
+
}
|
|
89
|
+
permitVersion = await getPermitVersion(tokenAddress, provider);
|
|
90
|
+
}
|
|
91
|
+
// EIP-2612 domain
|
|
92
|
+
const domain = {
|
|
93
|
+
name: tokenName,
|
|
94
|
+
version: permitVersion,
|
|
95
|
+
chainId: chainId,
|
|
96
|
+
verifyingContract: tokenAddress
|
|
97
|
+
};
|
|
98
|
+
// EIP-2612 Permit type
|
|
99
|
+
const types = {
|
|
100
|
+
Permit: [
|
|
101
|
+
{ name: "owner", type: "address" },
|
|
102
|
+
{ name: "spender", type: "address" },
|
|
103
|
+
{ name: "value", type: "uint256" },
|
|
104
|
+
{ name: "nonce", type: "uint256" },
|
|
105
|
+
{ name: "deadline", type: "uint256" }
|
|
106
|
+
]
|
|
107
|
+
};
|
|
108
|
+
// Permit message
|
|
109
|
+
const message = {
|
|
110
|
+
owner,
|
|
111
|
+
spender,
|
|
112
|
+
value: BigInt(value),
|
|
113
|
+
nonce,
|
|
114
|
+
deadline
|
|
115
|
+
};
|
|
116
|
+
// Sign the typed data
|
|
117
|
+
const signature = await signer.signTypedData(domain, types, message);
|
|
118
|
+
// Split signature into v, r, s components
|
|
119
|
+
const r = signature.slice(0, 66);
|
|
120
|
+
const s = "0x" + signature.slice(66, 130);
|
|
121
|
+
const v = parseInt(signature.slice(130, 132), 16);
|
|
122
|
+
return {
|
|
123
|
+
deadline,
|
|
124
|
+
v,
|
|
125
|
+
r,
|
|
126
|
+
s
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Helper function to get the permit version from an EIP-2612 token
|
|
131
|
+
*
|
|
132
|
+
* @param tokenAddress The address of the ERC20 token
|
|
133
|
+
* @param provider An ethers.js provider
|
|
134
|
+
* @returns The version string (e.g., "1", "2"), defaults to "1" if version() not implemented
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* import { getPermitVersion } from "@ember-finance/sdk";
|
|
139
|
+
*
|
|
140
|
+
* const version = await getPermitVersion(tokenAddress, provider);
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
async function getPermitVersion(tokenAddress, provider) {
|
|
144
|
+
try {
|
|
145
|
+
const { Contract } = await Promise.resolve().then(() => __importStar(require("ethers")));
|
|
146
|
+
const tokenContract = new Contract(tokenAddress, ["function version() view returns (string)"], provider);
|
|
147
|
+
return await tokenContract.version();
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
// TODO: change this to "1" when we have a token that supports version "1"
|
|
151
|
+
// If version() is not implemented, default to "2"
|
|
152
|
+
// Most EIP-2612 tokens use version "2" unless specified otherwise
|
|
153
|
+
return "2";
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Helper function to get the current nonce for a user from an EIP-2612 token
|
|
158
|
+
*
|
|
159
|
+
* @param tokenAddress The address of the ERC20 token
|
|
160
|
+
* @param ownerAddress The address of the token owner
|
|
161
|
+
* @param provider An ethers.js provider
|
|
162
|
+
* @returns The current nonce
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* import { getPermitNonce } from "@ember-finance/sdk";
|
|
167
|
+
*
|
|
168
|
+
* const nonce = await getPermitNonce(
|
|
169
|
+
* tokenAddress,
|
|
170
|
+
* await signer.getAddress(),
|
|
171
|
+
* provider
|
|
172
|
+
* );
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
async function getPermitNonce(tokenAddress, ownerAddress, provider) {
|
|
176
|
+
const { Contract } = await Promise.resolve().then(() => __importStar(require("ethers")));
|
|
177
|
+
const tokenContract = new Contract(tokenAddress, ["function nonces(address owner) view returns (uint256)"], provider);
|
|
178
|
+
return await tokenContract.nonces(ownerAddress);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Helper function to create a permit signature with sensible defaults
|
|
182
|
+
*
|
|
183
|
+
* This is a convenience function that:
|
|
184
|
+
* - Fetches the current nonce automatically
|
|
185
|
+
* - Fetches the version from the token contract
|
|
186
|
+
* - Sets a deadline of 1 hour from now
|
|
187
|
+
* - Gets the chain ID from the signer
|
|
188
|
+
*
|
|
189
|
+
* @param signer The ethers.js signer (must be connected to a provider)
|
|
190
|
+
* @param tokenAddress The address of the ERC20 token (must support EIP-2612)
|
|
191
|
+
* @param tokenName The name of the token (for domain separator)
|
|
192
|
+
* @param spender The address authorized to spend (usually the vault address)
|
|
193
|
+
* @param value The amount of tokens to approve
|
|
194
|
+
* @returns The permit signature components
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```typescript
|
|
198
|
+
* import { signPermitSimple } from "@ember-finance/sdk";
|
|
199
|
+
*
|
|
200
|
+
* // Simplified permit signing (fetches nonce, version, sets 1 hour deadline automatically)
|
|
201
|
+
* const permitSig = await signPermitSimple(
|
|
202
|
+
* signer,
|
|
203
|
+
* tokenAddress,
|
|
204
|
+
* "USD Coin",
|
|
205
|
+
* vaultAddress,
|
|
206
|
+
* amount
|
|
207
|
+
* );
|
|
208
|
+
*
|
|
209
|
+
* await userCalls.depositWithPermit(vaultAddress, amount, permitSig);
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
async function signPermitSimple(signer, tokenAddress, tokenName, spender, value) {
|
|
213
|
+
const provider = signer.provider;
|
|
214
|
+
if (!provider) {
|
|
215
|
+
throw new Error("Signer must be connected to a provider");
|
|
216
|
+
}
|
|
217
|
+
const ownerAddress = await signer.getAddress();
|
|
218
|
+
const network = await provider.getNetwork();
|
|
219
|
+
const chainId = network.chainId;
|
|
220
|
+
// Get current nonce and version from token contract
|
|
221
|
+
const nonce = await getPermitNonce(tokenAddress, ownerAddress, provider);
|
|
222
|
+
const version = await getPermitVersion(tokenAddress, provider);
|
|
223
|
+
// Set deadline to 1 hour from now
|
|
224
|
+
const deadline = BigInt(Math.floor(Date.now() / 1000) + 3600);
|
|
225
|
+
return signPermit(signer, tokenAddress, tokenName, spender, value, deadline, nonce, chainId, version);
|
|
226
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare const BcsUpdateVaultStrategyRequest: import("@mysten/bcs").
|
|
2
|
-
vaultId: string
|
|
3
|
-
strategies: {
|
|
1
|
+
export declare const BcsUpdateVaultStrategyRequest: import("@mysten/bcs").BcsStruct<{
|
|
2
|
+
vaultId: import("@mysten/bcs").BcsType<string, string, "string">;
|
|
3
|
+
strategies: import("@mysten/bcs").BcsType<{
|
|
4
4
|
platformName: string;
|
|
5
5
|
strategistAddress: string;
|
|
6
6
|
strategyType: string;
|
|
@@ -8,14 +8,7 @@ export declare const BcsUpdateVaultStrategyRequest: import("@mysten/bcs").BcsTyp
|
|
|
8
8
|
apyE9: string;
|
|
9
9
|
pointsApyE9: string;
|
|
10
10
|
snapshotAt: string;
|
|
11
|
-
}[]
|
|
12
|
-
targetApyE9: string;
|
|
13
|
-
supplyApyE9: string;
|
|
14
|
-
reportedApyE9: string;
|
|
15
|
-
signedAt: string;
|
|
16
|
-
}, {
|
|
17
|
-
vaultId: string;
|
|
18
|
-
strategies: Iterable<{
|
|
11
|
+
}[], Iterable<{
|
|
19
12
|
platformName: string;
|
|
20
13
|
strategistAddress: string;
|
|
21
14
|
strategyType: string;
|
|
@@ -25,9 +18,9 @@ export declare const BcsUpdateVaultStrategyRequest: import("@mysten/bcs").BcsTyp
|
|
|
25
18
|
snapshotAt: string | number | bigint;
|
|
26
19
|
}> & {
|
|
27
20
|
length: number;
|
|
28
|
-
}
|
|
29
|
-
targetApyE9: string
|
|
30
|
-
supplyApyE9: string
|
|
31
|
-
reportedApyE9: string
|
|
32
|
-
signedAt: string | number | bigint
|
|
33
|
-
}>;
|
|
21
|
+
}, string>;
|
|
22
|
+
targetApyE9: import("@mysten/bcs").BcsType<string, string, "string">;
|
|
23
|
+
supplyApyE9: import("@mysten/bcs").BcsType<string, string, "string">;
|
|
24
|
+
reportedApyE9: import("@mysten/bcs").BcsType<string, string, "string">;
|
|
25
|
+
signedAt: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
26
|
+
}, string>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ember-finance/sdk",
|
|
3
3
|
"description": "Ember Protocol SDK",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.2.0",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -42,6 +42,11 @@
|
|
|
42
42
|
"types": "./dist/src/abis/index.d.ts",
|
|
43
43
|
"import": "./dist/src/abis/index.js",
|
|
44
44
|
"require": "./dist/src/abis/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./index": {
|
|
47
|
+
"types": "./dist/src/index.d.ts",
|
|
48
|
+
"import": "./dist/src/index.js",
|
|
49
|
+
"require": "./dist/src/index.js"
|
|
45
50
|
}
|
|
46
51
|
},
|
|
47
52
|
"scripts": {
|
|
@@ -66,7 +71,7 @@
|
|
|
66
71
|
"test": "tests"
|
|
67
72
|
},
|
|
68
73
|
"dependencies": {
|
|
69
|
-
"@firefly-exchange/library-sui": "^2.
|
|
74
|
+
"@firefly-exchange/library-sui": "^2.12.1",
|
|
70
75
|
"axios": "1.12.2",
|
|
71
76
|
"ethers": "^6.13.4",
|
|
72
77
|
"yarn": "^1.22.19"
|