@paxoslabs/amplify-sdk 0.5.2 → 1.0.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/index.d.mts +3158 -725
- package/dist/index.d.ts +3158 -725
- package/dist/index.js +15013 -171
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15067 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +25 -86
- package/CHANGELOG.md +0 -320
- package/LICENSE +0 -28
- package/README.md +0 -119
- package/dist/chain-utils-BdJecHBA.d.mts +0 -334
- package/dist/chain-utils-BdJecHBA.d.ts +0 -334
- package/dist/chunk-5OK753GA.js +0 -1989
- package/dist/chunk-5OK753GA.js.map +0 -1
- package/dist/chunk-6CU533DM.mjs +0 -39
- package/dist/chunk-6CU533DM.mjs.map +0 -1
- package/dist/chunk-7JQQ2TH4.mjs +0 -1231
- package/dist/chunk-7JQQ2TH4.mjs.map +0 -1
- package/dist/chunk-HU5CTL4C.mjs +0 -1962
- package/dist/chunk-HU5CTL4C.mjs.map +0 -1
- package/dist/chunk-NNDY5TID.js +0 -1143
- package/dist/chunk-NNDY5TID.js.map +0 -1
- package/dist/chunk-Q5FXJU5Y.mjs +0 -1133
- package/dist/chunk-Q5FXJU5Y.mjs.map +0 -1
- package/dist/chunk-QZHI2T7O.mjs +0 -457
- package/dist/chunk-QZHI2T7O.mjs.map +0 -1
- package/dist/chunk-SWUG4PTB.js +0 -464
- package/dist/chunk-SWUG4PTB.js.map +0 -1
- package/dist/chunk-TNL23CO2.js +0 -45
- package/dist/chunk-TNL23CO2.js.map +0 -1
- package/dist/chunk-WK7EJRBB.mjs +0 -1482
- package/dist/chunk-WK7EJRBB.mjs.map +0 -1
- package/dist/chunk-WYBYBPX5.js +0 -1518
- package/dist/chunk-WYBYBPX5.js.map +0 -1
- package/dist/chunk-ZKDXRGI5.js +0 -1239
- package/dist/chunk-ZKDXRGI5.js.map +0 -1
- package/dist/core.d.mts +0 -152
- package/dist/core.d.ts +0 -152
- package/dist/core.js +0 -1220
- package/dist/core.js.map +0 -1
- package/dist/core.mjs +0 -1194
- package/dist/core.mjs.map +0 -1
- package/dist/display.d.mts +0 -263
- package/dist/display.d.ts +0 -263
- package/dist/display.js +0 -36
- package/dist/display.js.map +0 -1
- package/dist/display.mjs +0 -7
- package/dist/display.mjs.map +0 -1
- package/dist/index-DXXA8gEA.d.mts +0 -5026
- package/dist/index-aE5lTOUH.d.ts +0 -5026
- package/dist/utils.d.mts +0 -112
- package/dist/utils.d.ts +0 -112
- package/dist/utils.js +0 -67
- package/dist/utils.js.map +0 -1
- package/dist/utils.mjs +0 -25
- package/dist/utils.mjs.map +0 -1
- package/dist/vaults.d.mts +0 -4
- package/dist/vaults.d.ts +0 -4
- package/dist/vaults.js +0 -96
- package/dist/vaults.js.map +0 -1
- package/dist/vaults.mjs +0 -7
- package/dist/vaults.mjs.map +0 -1
package/dist/chunk-5OK753GA.js
DELETED
|
@@ -1,1989 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var chunkZKDXRGI5_js = require('./chunk-ZKDXRGI5.js');
|
|
4
|
-
var chunkNNDY5TID_js = require('./chunk-NNDY5TID.js');
|
|
5
|
-
var chunkTNL23CO2_js = require('./chunk-TNL23CO2.js');
|
|
6
|
-
var chunkWYBYBPX5_js = require('./chunk-WYBYBPX5.js');
|
|
7
|
-
var viem = require('viem');
|
|
8
|
-
|
|
9
|
-
var isDepositSpendApproved = async ({
|
|
10
|
-
vaultName,
|
|
11
|
-
chainId,
|
|
12
|
-
depositAssetAddress,
|
|
13
|
-
recipientAddress
|
|
14
|
-
}) => {
|
|
15
|
-
try {
|
|
16
|
-
const normalizedChainId = chunkWYBYBPX5_js.toChainId(chainId);
|
|
17
|
-
const config = await chunkZKDXRGI5_js.resolveVault({
|
|
18
|
-
vaultName,
|
|
19
|
-
chainId: normalizedChainId,
|
|
20
|
-
assetAddress: depositAssetAddress,
|
|
21
|
-
callerEndpoint: "isDepositSpendApproved"
|
|
22
|
-
});
|
|
23
|
-
const communityCodeDepositorAddress = config.vault.communityCodeDepositorAddress;
|
|
24
|
-
if (!communityCodeDepositorAddress) {
|
|
25
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
26
|
-
`Community code depositor contract address not configured for vault ${config.id}`,
|
|
27
|
-
{
|
|
28
|
-
endpoint: "isDepositSpendApproved"
|
|
29
|
-
}
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
const {
|
|
33
|
-
decimals,
|
|
34
|
-
allowance,
|
|
35
|
-
supportsPermit,
|
|
36
|
-
nonce,
|
|
37
|
-
domainSeparator,
|
|
38
|
-
tokenName,
|
|
39
|
-
tokenVersion
|
|
40
|
-
} = await chunkNNDY5TID_js.getTokenPermitInfoWithAllowance({
|
|
41
|
-
chainId: normalizedChainId,
|
|
42
|
-
tokenAddress: depositAssetAddress,
|
|
43
|
-
owner: recipientAddress,
|
|
44
|
-
spender: communityCodeDepositorAddress
|
|
45
|
-
});
|
|
46
|
-
return {
|
|
47
|
-
isApproved: allowance > 0n,
|
|
48
|
-
allowance: viem.formatUnits(allowance, decimals),
|
|
49
|
-
allowanceAsBigInt: allowance.toString(),
|
|
50
|
-
decimals,
|
|
51
|
-
supportsPermit,
|
|
52
|
-
nonce,
|
|
53
|
-
domainSeparator,
|
|
54
|
-
tokenName,
|
|
55
|
-
tokenVersion,
|
|
56
|
-
error: null
|
|
57
|
-
};
|
|
58
|
-
} catch (error) {
|
|
59
|
-
if (error instanceof chunkWYBYBPX5_js.APIError) {
|
|
60
|
-
throw error;
|
|
61
|
-
}
|
|
62
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
63
|
-
`Failed to check deposit approval: ${error instanceof Error ? error.message : String(error)}`,
|
|
64
|
-
{
|
|
65
|
-
endpoint: "isDepositSpendApproved",
|
|
66
|
-
cause: error
|
|
67
|
-
}
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
var isWithdrawalSpendApproved = async ({
|
|
72
|
-
vaultName,
|
|
73
|
-
chainId,
|
|
74
|
-
wantAssetAddress,
|
|
75
|
-
recipientAddress
|
|
76
|
-
}) => {
|
|
77
|
-
try {
|
|
78
|
-
const normalizedChainId = chunkWYBYBPX5_js.toChainId(chainId);
|
|
79
|
-
const config = await chunkZKDXRGI5_js.resolveVault({
|
|
80
|
-
vaultName,
|
|
81
|
-
chainId: normalizedChainId,
|
|
82
|
-
assetAddress: wantAssetAddress,
|
|
83
|
-
callerEndpoint: "isWithdrawalSpendApproved"
|
|
84
|
-
});
|
|
85
|
-
const boringVaultAddress = config.vault.boringVaultAddress;
|
|
86
|
-
if (!boringVaultAddress) {
|
|
87
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
88
|
-
`BoringVault contract address not configured for vault ${config.id}`,
|
|
89
|
-
{
|
|
90
|
-
endpoint: "isWithdrawalSpendApproved"
|
|
91
|
-
}
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
const withdrawQueueAddress = config.vault.withdrawQueueAddress;
|
|
95
|
-
if (!withdrawQueueAddress) {
|
|
96
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
97
|
-
`WithdrawQueue contract address not configured for vault ${config.id}`,
|
|
98
|
-
{
|
|
99
|
-
endpoint: "isWithdrawalSpendApproved"
|
|
100
|
-
}
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
const [allowance, decimals] = await chunkNNDY5TID_js.getErc20AllowanceWithDecimals({
|
|
104
|
-
chainId: normalizedChainId,
|
|
105
|
-
tokenAddress: boringVaultAddress,
|
|
106
|
-
recipientAddress,
|
|
107
|
-
spenderAddress: withdrawQueueAddress
|
|
108
|
-
});
|
|
109
|
-
if (allowance.status === "failure" || decimals.status === "failure") {
|
|
110
|
-
return {
|
|
111
|
-
isApproved: false,
|
|
112
|
-
allowance: "0",
|
|
113
|
-
allowanceAsBigInt: "0",
|
|
114
|
-
decimals: "0",
|
|
115
|
-
error: allowance.error || decimals.error
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
return {
|
|
119
|
-
isApproved: allowance.result > 0n,
|
|
120
|
-
allowance: viem.formatUnits(allowance.result, decimals.result),
|
|
121
|
-
allowanceAsBigInt: allowance.result.toString(),
|
|
122
|
-
decimals: decimals.result,
|
|
123
|
-
error: null
|
|
124
|
-
};
|
|
125
|
-
} catch (error) {
|
|
126
|
-
if (error instanceof chunkWYBYBPX5_js.APIError) {
|
|
127
|
-
throw error;
|
|
128
|
-
}
|
|
129
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
130
|
-
`Failed to check withdrawal approval: ${error instanceof Error ? error.message : String(error)}`,
|
|
131
|
-
{ endpoint: "isWithdrawalSpendApproved", cause: error }
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
async function prepareApproveDepositTokenTxData({
|
|
136
|
-
vaultName,
|
|
137
|
-
depositAsset,
|
|
138
|
-
approvalAmount,
|
|
139
|
-
chainId
|
|
140
|
-
}) {
|
|
141
|
-
const normalizedChainId = chunkWYBYBPX5_js.toChainId(chainId);
|
|
142
|
-
try {
|
|
143
|
-
const config = await chunkZKDXRGI5_js.resolveVault({
|
|
144
|
-
vaultName,
|
|
145
|
-
assetAddress: depositAsset,
|
|
146
|
-
chainId: normalizedChainId,
|
|
147
|
-
callerEndpoint: "prepareApproveDepositToken"
|
|
148
|
-
});
|
|
149
|
-
const communityCodeDepositorAddress = config.vault.communityCodeDepositorAddress;
|
|
150
|
-
if (!communityCodeDepositorAddress) {
|
|
151
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
152
|
-
`Community Code Depositor contract address not configured for vault ${config.id}`,
|
|
153
|
-
{ endpoint: "prepareApproveDepositToken" }
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
const assets = await chunkWYBYBPX5_js.getSupportedAssets({ address: depositAsset });
|
|
157
|
-
if (assets.length === 0) {
|
|
158
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
159
|
-
`Asset metadata not found for token ${depositAsset} on chain ${normalizedChainId}`,
|
|
160
|
-
{ endpoint: "prepareApproveDepositToken" }
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
const verifiedAsset = assets.find(
|
|
164
|
-
(asset) => asset.address.toLowerCase() === depositAsset.toLowerCase() && asset.chains.includes(normalizedChainId)
|
|
165
|
-
);
|
|
166
|
-
if (!verifiedAsset) {
|
|
167
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
168
|
-
`Asset ${depositAsset} not verified on chain ${normalizedChainId}`,
|
|
169
|
-
{ endpoint: "prepareApproveDepositToken" }
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
const decimals = verifiedAsset.decimals;
|
|
173
|
-
const amount = approvalAmount ? viem.parseUnits(approvalAmount, decimals) : chunkWYBYBPX5_js.DEFAULT_APPROVAL_AMOUNT;
|
|
174
|
-
return {
|
|
175
|
-
abi: viem.erc20Abi,
|
|
176
|
-
address: depositAsset,
|
|
177
|
-
functionName: "approve",
|
|
178
|
-
args: [communityCodeDepositorAddress, amount]
|
|
179
|
-
};
|
|
180
|
-
} catch (error) {
|
|
181
|
-
if (error instanceof chunkWYBYBPX5_js.APIError) {
|
|
182
|
-
throw error;
|
|
183
|
-
}
|
|
184
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
185
|
-
`Failed to prepare approval transaction: ${error instanceof Error ? error.message : String(error)}`,
|
|
186
|
-
{
|
|
187
|
-
endpoint: "prepareApproveDepositToken",
|
|
188
|
-
cause: error
|
|
189
|
-
}
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// src/abi/distributor-code-depositor-abi-v0.ts
|
|
195
|
-
var DistributorCodeDepositorAbiV0 = [
|
|
196
|
-
{
|
|
197
|
-
inputs: [
|
|
198
|
-
{
|
|
199
|
-
internalType: "contract TellerWithMultiAssetSupport",
|
|
200
|
-
name: "_teller",
|
|
201
|
-
type: "address"
|
|
202
|
-
},
|
|
203
|
-
{
|
|
204
|
-
internalType: "contract INativeWrapper",
|
|
205
|
-
name: "_nativeWrapper",
|
|
206
|
-
type: "address"
|
|
207
|
-
},
|
|
208
|
-
{
|
|
209
|
-
internalType: "contract Authority",
|
|
210
|
-
name: "_rolesAuthority",
|
|
211
|
-
type: "address"
|
|
212
|
-
},
|
|
213
|
-
{ internalType: "bool", name: "_isNativeDepositSupported", type: "bool" },
|
|
214
|
-
{ internalType: "address", name: "_owner", type: "address" }
|
|
215
|
-
],
|
|
216
|
-
stateMutability: "nonpayable",
|
|
217
|
-
type: "constructor"
|
|
218
|
-
},
|
|
219
|
-
{ inputs: [], name: "IncorrectNativeDepositAmount", type: "error" },
|
|
220
|
-
{ inputs: [], name: "NativeDepositNotSupported", type: "error" },
|
|
221
|
-
{
|
|
222
|
-
inputs: [],
|
|
223
|
-
name: "NativeWrapperAccountantDecimalsMismatch",
|
|
224
|
-
type: "error"
|
|
225
|
-
},
|
|
226
|
-
{ inputs: [], name: "PermitFailedAndAllowanceTooLow", type: "error" },
|
|
227
|
-
{ inputs: [], name: "ZeroAddress", type: "error" },
|
|
228
|
-
{
|
|
229
|
-
anonymous: false,
|
|
230
|
-
inputs: [
|
|
231
|
-
{ indexed: true, internalType: "address", name: "user", type: "address" },
|
|
232
|
-
{
|
|
233
|
-
indexed: true,
|
|
234
|
-
internalType: "contract Authority",
|
|
235
|
-
name: "newAuthority",
|
|
236
|
-
type: "address"
|
|
237
|
-
}
|
|
238
|
-
],
|
|
239
|
-
name: "AuthorityUpdated",
|
|
240
|
-
type: "event"
|
|
241
|
-
},
|
|
242
|
-
{
|
|
243
|
-
anonymous: false,
|
|
244
|
-
inputs: [
|
|
245
|
-
{
|
|
246
|
-
indexed: true,
|
|
247
|
-
internalType: "address",
|
|
248
|
-
name: "depositor",
|
|
249
|
-
type: "address"
|
|
250
|
-
},
|
|
251
|
-
{
|
|
252
|
-
indexed: true,
|
|
253
|
-
internalType: "contract ERC20",
|
|
254
|
-
name: "depositAsset",
|
|
255
|
-
type: "address"
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
indexed: false,
|
|
259
|
-
internalType: "uint256",
|
|
260
|
-
name: "depositAmount",
|
|
261
|
-
type: "uint256"
|
|
262
|
-
},
|
|
263
|
-
{
|
|
264
|
-
indexed: false,
|
|
265
|
-
internalType: "uint256",
|
|
266
|
-
name: "minimumMint",
|
|
267
|
-
type: "uint256"
|
|
268
|
-
},
|
|
269
|
-
{ indexed: false, internalType: "address", name: "to", type: "address" },
|
|
270
|
-
{
|
|
271
|
-
indexed: false,
|
|
272
|
-
internalType: "bytes32",
|
|
273
|
-
name: "depositHash",
|
|
274
|
-
type: "bytes32"
|
|
275
|
-
},
|
|
276
|
-
{
|
|
277
|
-
indexed: true,
|
|
278
|
-
internalType: "bytes",
|
|
279
|
-
name: "distributorCode",
|
|
280
|
-
type: "bytes"
|
|
281
|
-
}
|
|
282
|
-
],
|
|
283
|
-
name: "DepositWithDistributorCode",
|
|
284
|
-
type: "event"
|
|
285
|
-
},
|
|
286
|
-
{
|
|
287
|
-
anonymous: false,
|
|
288
|
-
inputs: [
|
|
289
|
-
{ indexed: true, internalType: "address", name: "user", type: "address" },
|
|
290
|
-
{
|
|
291
|
-
indexed: true,
|
|
292
|
-
internalType: "address",
|
|
293
|
-
name: "newOwner",
|
|
294
|
-
type: "address"
|
|
295
|
-
}
|
|
296
|
-
],
|
|
297
|
-
name: "OwnershipTransferred",
|
|
298
|
-
type: "event"
|
|
299
|
-
},
|
|
300
|
-
{
|
|
301
|
-
inputs: [],
|
|
302
|
-
name: "authority",
|
|
303
|
-
outputs: [
|
|
304
|
-
{ internalType: "contract Authority", name: "", type: "address" }
|
|
305
|
-
],
|
|
306
|
-
stateMutability: "view",
|
|
307
|
-
type: "function"
|
|
308
|
-
},
|
|
309
|
-
{
|
|
310
|
-
inputs: [],
|
|
311
|
-
name: "boringVault",
|
|
312
|
-
outputs: [{ internalType: "address", name: "", type: "address" }],
|
|
313
|
-
stateMutability: "view",
|
|
314
|
-
type: "function"
|
|
315
|
-
},
|
|
316
|
-
{
|
|
317
|
-
inputs: [
|
|
318
|
-
{ internalType: "contract ERC20", name: "depositAsset", type: "address" },
|
|
319
|
-
{ internalType: "uint256", name: "depositAmount", type: "uint256" },
|
|
320
|
-
{ internalType: "uint256", name: "minimumMint", type: "uint256" },
|
|
321
|
-
{ internalType: "address", name: "to", type: "address" },
|
|
322
|
-
{ internalType: "bytes", name: "distributorCode", type: "bytes" }
|
|
323
|
-
],
|
|
324
|
-
name: "deposit",
|
|
325
|
-
outputs: [{ internalType: "uint256", name: "shares", type: "uint256" }],
|
|
326
|
-
stateMutability: "nonpayable",
|
|
327
|
-
type: "function"
|
|
328
|
-
},
|
|
329
|
-
{
|
|
330
|
-
inputs: [
|
|
331
|
-
{ internalType: "uint256", name: "depositAmount", type: "uint256" },
|
|
332
|
-
{ internalType: "uint256", name: "minimumMint", type: "uint256" },
|
|
333
|
-
{ internalType: "address", name: "to", type: "address" },
|
|
334
|
-
{ internalType: "bytes", name: "distributorCode", type: "bytes" }
|
|
335
|
-
],
|
|
336
|
-
name: "depositNative",
|
|
337
|
-
outputs: [{ internalType: "uint256", name: "shares", type: "uint256" }],
|
|
338
|
-
stateMutability: "payable",
|
|
339
|
-
type: "function"
|
|
340
|
-
},
|
|
341
|
-
{
|
|
342
|
-
inputs: [],
|
|
343
|
-
name: "depositNonce",
|
|
344
|
-
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
345
|
-
stateMutability: "view",
|
|
346
|
-
type: "function"
|
|
347
|
-
},
|
|
348
|
-
{
|
|
349
|
-
inputs: [
|
|
350
|
-
{ internalType: "contract ERC20", name: "depositAsset", type: "address" },
|
|
351
|
-
{ internalType: "uint256", name: "depositAmount", type: "uint256" },
|
|
352
|
-
{ internalType: "uint256", name: "minimumMint", type: "uint256" },
|
|
353
|
-
{ internalType: "address", name: "to", type: "address" },
|
|
354
|
-
{ internalType: "bytes", name: "distributorCode", type: "bytes" },
|
|
355
|
-
{ internalType: "uint256", name: "deadline", type: "uint256" },
|
|
356
|
-
{ internalType: "uint8", name: "v", type: "uint8" },
|
|
357
|
-
{ internalType: "bytes32", name: "r", type: "bytes32" },
|
|
358
|
-
{ internalType: "bytes32", name: "s", type: "bytes32" }
|
|
359
|
-
],
|
|
360
|
-
name: "depositWithPermit",
|
|
361
|
-
outputs: [{ internalType: "uint256", name: "shares", type: "uint256" }],
|
|
362
|
-
stateMutability: "nonpayable",
|
|
363
|
-
type: "function"
|
|
364
|
-
},
|
|
365
|
-
{
|
|
366
|
-
inputs: [],
|
|
367
|
-
name: "isNativeDepositSupported",
|
|
368
|
-
outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
|
369
|
-
stateMutability: "view",
|
|
370
|
-
type: "function"
|
|
371
|
-
},
|
|
372
|
-
{
|
|
373
|
-
inputs: [],
|
|
374
|
-
name: "nativeWrapper",
|
|
375
|
-
outputs: [
|
|
376
|
-
{ internalType: "contract INativeWrapper", name: "", type: "address" }
|
|
377
|
-
],
|
|
378
|
-
stateMutability: "view",
|
|
379
|
-
type: "function"
|
|
380
|
-
},
|
|
381
|
-
{
|
|
382
|
-
inputs: [],
|
|
383
|
-
name: "owner",
|
|
384
|
-
outputs: [{ internalType: "address", name: "", type: "address" }],
|
|
385
|
-
stateMutability: "view",
|
|
386
|
-
type: "function"
|
|
387
|
-
},
|
|
388
|
-
{
|
|
389
|
-
inputs: [
|
|
390
|
-
{
|
|
391
|
-
internalType: "contract Authority",
|
|
392
|
-
name: "newAuthority",
|
|
393
|
-
type: "address"
|
|
394
|
-
}
|
|
395
|
-
],
|
|
396
|
-
name: "setAuthority",
|
|
397
|
-
outputs: [],
|
|
398
|
-
stateMutability: "nonpayable",
|
|
399
|
-
type: "function"
|
|
400
|
-
},
|
|
401
|
-
{
|
|
402
|
-
inputs: [],
|
|
403
|
-
name: "teller",
|
|
404
|
-
outputs: [
|
|
405
|
-
{
|
|
406
|
-
internalType: "contract TellerWithMultiAssetSupport",
|
|
407
|
-
name: "",
|
|
408
|
-
type: "address"
|
|
409
|
-
}
|
|
410
|
-
],
|
|
411
|
-
stateMutability: "view",
|
|
412
|
-
type: "function"
|
|
413
|
-
},
|
|
414
|
-
{
|
|
415
|
-
inputs: [{ internalType: "address", name: "newOwner", type: "address" }],
|
|
416
|
-
name: "transferOwnership",
|
|
417
|
-
outputs: [],
|
|
418
|
-
stateMutability: "nonpayable",
|
|
419
|
-
type: "function"
|
|
420
|
-
}
|
|
421
|
-
];
|
|
422
|
-
|
|
423
|
-
// src/abi/distributor-code-depositor-abi-v1.ts
|
|
424
|
-
var DistributorCodeDepositorAbiV1 = [
|
|
425
|
-
{
|
|
426
|
-
inputs: [
|
|
427
|
-
{
|
|
428
|
-
internalType: "contract TellerWithMultiAssetSupport",
|
|
429
|
-
name: "_teller",
|
|
430
|
-
type: "address"
|
|
431
|
-
},
|
|
432
|
-
{
|
|
433
|
-
internalType: "contract INativeWrapper",
|
|
434
|
-
name: "_nativeWrapper",
|
|
435
|
-
type: "address"
|
|
436
|
-
},
|
|
437
|
-
{
|
|
438
|
-
internalType: "contract Authority",
|
|
439
|
-
name: "_rolesAuthority",
|
|
440
|
-
type: "address"
|
|
441
|
-
},
|
|
442
|
-
{ internalType: "bool", name: "_isNativeDepositSupported", type: "bool" },
|
|
443
|
-
{ internalType: "uint256", name: "_supplyCap", type: "uint256" },
|
|
444
|
-
{
|
|
445
|
-
internalType: "contract IFeeModule",
|
|
446
|
-
name: "_feeModule",
|
|
447
|
-
type: "address"
|
|
448
|
-
},
|
|
449
|
-
{ internalType: "address", name: "_feeRecipient", type: "address" },
|
|
450
|
-
{ internalType: "address", name: "_registry", type: "address" },
|
|
451
|
-
{ internalType: "string", name: "_policyID", type: "string" },
|
|
452
|
-
{ internalType: "address", name: "_owner", type: "address" }
|
|
453
|
-
],
|
|
454
|
-
stateMutability: "nonpayable",
|
|
455
|
-
type: "constructor"
|
|
456
|
-
},
|
|
457
|
-
{ inputs: [], name: "FeesExceedOrEqualAmount", type: "error" },
|
|
458
|
-
{ inputs: [], name: "IncorrectNativeDepositAmount", type: "error" },
|
|
459
|
-
{
|
|
460
|
-
inputs: [
|
|
461
|
-
{ internalType: "uint256", name: "actual", type: "uint256" },
|
|
462
|
-
{ internalType: "uint256", name: "minimum", type: "uint256" }
|
|
463
|
-
],
|
|
464
|
-
name: "InsufficientSharesAfterFees",
|
|
465
|
-
type: "error"
|
|
466
|
-
},
|
|
467
|
-
{ inputs: [], name: "NativeDepositNotSupported", type: "error" },
|
|
468
|
-
{
|
|
469
|
-
inputs: [],
|
|
470
|
-
name: "NativeWrapperAccountantDecimalsMismatch",
|
|
471
|
-
type: "error"
|
|
472
|
-
},
|
|
473
|
-
{
|
|
474
|
-
inputs: [
|
|
475
|
-
{ internalType: "address", name: "addressEmptyCode", type: "address" }
|
|
476
|
-
],
|
|
477
|
-
name: "NoCode",
|
|
478
|
-
type: "error"
|
|
479
|
-
},
|
|
480
|
-
{ inputs: [], name: "PermitFailedAndAllowanceTooLow", type: "error" },
|
|
481
|
-
{
|
|
482
|
-
inputs: [
|
|
483
|
-
{ internalType: "uint256", name: "resultingValue", type: "uint256" },
|
|
484
|
-
{ internalType: "uint256", name: "supplyCapInBase", type: "uint256" }
|
|
485
|
-
],
|
|
486
|
-
name: "SupplyCapInBaseError",
|
|
487
|
-
type: "error"
|
|
488
|
-
},
|
|
489
|
-
{ inputs: [], name: "UnauthorizedTransaction", type: "error" },
|
|
490
|
-
{ inputs: [], name: "ZeroAddress", type: "error" },
|
|
491
|
-
{
|
|
492
|
-
anonymous: false,
|
|
493
|
-
inputs: [
|
|
494
|
-
{ indexed: true, internalType: "address", name: "user", type: "address" },
|
|
495
|
-
{
|
|
496
|
-
indexed: true,
|
|
497
|
-
internalType: "contract Authority",
|
|
498
|
-
name: "newAuthority",
|
|
499
|
-
type: "address"
|
|
500
|
-
}
|
|
501
|
-
],
|
|
502
|
-
name: "AuthorityUpdated",
|
|
503
|
-
type: "event"
|
|
504
|
-
},
|
|
505
|
-
{
|
|
506
|
-
anonymous: false,
|
|
507
|
-
inputs: [
|
|
508
|
-
{
|
|
509
|
-
indexed: true,
|
|
510
|
-
internalType: "address",
|
|
511
|
-
name: "depositor",
|
|
512
|
-
type: "address"
|
|
513
|
-
},
|
|
514
|
-
{
|
|
515
|
-
indexed: true,
|
|
516
|
-
internalType: "contract ERC20",
|
|
517
|
-
name: "depositAsset",
|
|
518
|
-
type: "address"
|
|
519
|
-
},
|
|
520
|
-
{
|
|
521
|
-
indexed: false,
|
|
522
|
-
internalType: "uint256",
|
|
523
|
-
name: "depositAmount",
|
|
524
|
-
type: "uint256"
|
|
525
|
-
},
|
|
526
|
-
{
|
|
527
|
-
indexed: false,
|
|
528
|
-
internalType: "uint256",
|
|
529
|
-
name: "minimumMint",
|
|
530
|
-
type: "uint256"
|
|
531
|
-
},
|
|
532
|
-
{ indexed: false, internalType: "address", name: "to", type: "address" },
|
|
533
|
-
{
|
|
534
|
-
indexed: false,
|
|
535
|
-
internalType: "bytes32",
|
|
536
|
-
name: "depositHash",
|
|
537
|
-
type: "bytes32"
|
|
538
|
-
},
|
|
539
|
-
{
|
|
540
|
-
indexed: true,
|
|
541
|
-
internalType: "bytes",
|
|
542
|
-
name: "distributorCode",
|
|
543
|
-
type: "bytes"
|
|
544
|
-
}
|
|
545
|
-
],
|
|
546
|
-
name: "DepositWithDistributorCode",
|
|
547
|
-
type: "event"
|
|
548
|
-
},
|
|
549
|
-
{
|
|
550
|
-
anonymous: false,
|
|
551
|
-
inputs: [
|
|
552
|
-
{
|
|
553
|
-
indexed: true,
|
|
554
|
-
internalType: "contract IFeeModule",
|
|
555
|
-
name: "newFeeModule",
|
|
556
|
-
type: "address"
|
|
557
|
-
}
|
|
558
|
-
],
|
|
559
|
-
name: "FeeModuleUpdated",
|
|
560
|
-
type: "event"
|
|
561
|
-
},
|
|
562
|
-
{
|
|
563
|
-
anonymous: false,
|
|
564
|
-
inputs: [
|
|
565
|
-
{
|
|
566
|
-
indexed: true,
|
|
567
|
-
internalType: "address",
|
|
568
|
-
name: "newFeeRecipient",
|
|
569
|
-
type: "address"
|
|
570
|
-
}
|
|
571
|
-
],
|
|
572
|
-
name: "FeeRecipientUpdated",
|
|
573
|
-
type: "event"
|
|
574
|
-
},
|
|
575
|
-
{
|
|
576
|
-
anonymous: false,
|
|
577
|
-
inputs: [
|
|
578
|
-
{
|
|
579
|
-
indexed: true,
|
|
580
|
-
internalType: "contract ERC20",
|
|
581
|
-
name: "depositAsset",
|
|
582
|
-
type: "address"
|
|
583
|
-
},
|
|
584
|
-
{ indexed: true, internalType: "bool", name: "enabled", type: "bool" }
|
|
585
|
-
],
|
|
586
|
-
name: "KytStatusUpdated",
|
|
587
|
-
type: "event"
|
|
588
|
-
},
|
|
589
|
-
{
|
|
590
|
-
anonymous: false,
|
|
591
|
-
inputs: [
|
|
592
|
-
{ indexed: true, internalType: "address", name: "user", type: "address" },
|
|
593
|
-
{
|
|
594
|
-
indexed: true,
|
|
595
|
-
internalType: "address",
|
|
596
|
-
name: "newOwner",
|
|
597
|
-
type: "address"
|
|
598
|
-
}
|
|
599
|
-
],
|
|
600
|
-
name: "OwnershipTransferred",
|
|
601
|
-
type: "event"
|
|
602
|
-
},
|
|
603
|
-
{
|
|
604
|
-
anonymous: false,
|
|
605
|
-
inputs: [
|
|
606
|
-
{
|
|
607
|
-
indexed: false,
|
|
608
|
-
internalType: "string",
|
|
609
|
-
name: "oldPolicyID",
|
|
610
|
-
type: "string"
|
|
611
|
-
},
|
|
612
|
-
{
|
|
613
|
-
indexed: false,
|
|
614
|
-
internalType: "string",
|
|
615
|
-
name: "newPolicyID",
|
|
616
|
-
type: "string"
|
|
617
|
-
}
|
|
618
|
-
],
|
|
619
|
-
name: "PredicatePolicyIDUpdated",
|
|
620
|
-
type: "event"
|
|
621
|
-
},
|
|
622
|
-
{
|
|
623
|
-
anonymous: false,
|
|
624
|
-
inputs: [
|
|
625
|
-
{
|
|
626
|
-
indexed: true,
|
|
627
|
-
internalType: "address",
|
|
628
|
-
name: "oldRegistry",
|
|
629
|
-
type: "address"
|
|
630
|
-
},
|
|
631
|
-
{
|
|
632
|
-
indexed: true,
|
|
633
|
-
internalType: "address",
|
|
634
|
-
name: "newRegistry",
|
|
635
|
-
type: "address"
|
|
636
|
-
}
|
|
637
|
-
],
|
|
638
|
-
name: "PredicateRegistryUpdated",
|
|
639
|
-
type: "event"
|
|
640
|
-
},
|
|
641
|
-
{
|
|
642
|
-
anonymous: false,
|
|
643
|
-
inputs: [
|
|
644
|
-
{
|
|
645
|
-
indexed: false,
|
|
646
|
-
internalType: "uint256",
|
|
647
|
-
name: "newSupplyCapInBase",
|
|
648
|
-
type: "uint256"
|
|
649
|
-
}
|
|
650
|
-
],
|
|
651
|
-
name: "SupplyCapInBaseUpdated",
|
|
652
|
-
type: "event"
|
|
653
|
-
},
|
|
654
|
-
{
|
|
655
|
-
inputs: [],
|
|
656
|
-
name: "PREDICATE_DEPOSIT_SIGNATURE",
|
|
657
|
-
outputs: [{ internalType: "string", name: "", type: "string" }],
|
|
658
|
-
stateMutability: "view",
|
|
659
|
-
type: "function"
|
|
660
|
-
},
|
|
661
|
-
{
|
|
662
|
-
inputs: [],
|
|
663
|
-
name: "authority",
|
|
664
|
-
outputs: [
|
|
665
|
-
{ internalType: "contract Authority", name: "", type: "address" }
|
|
666
|
-
],
|
|
667
|
-
stateMutability: "view",
|
|
668
|
-
type: "function"
|
|
669
|
-
},
|
|
670
|
-
{
|
|
671
|
-
inputs: [],
|
|
672
|
-
name: "boringVault",
|
|
673
|
-
outputs: [{ internalType: "address", name: "", type: "address" }],
|
|
674
|
-
stateMutability: "view",
|
|
675
|
-
type: "function"
|
|
676
|
-
},
|
|
677
|
-
{
|
|
678
|
-
inputs: [
|
|
679
|
-
{ internalType: "contract ERC20", name: "depositAsset", type: "address" },
|
|
680
|
-
{ internalType: "uint256", name: "depositAmount", type: "uint256" },
|
|
681
|
-
{ internalType: "uint256", name: "minimumMint", type: "uint256" },
|
|
682
|
-
{ internalType: "address", name: "to", type: "address" },
|
|
683
|
-
{ internalType: "bytes", name: "distributorCode", type: "bytes" },
|
|
684
|
-
{
|
|
685
|
-
components: [
|
|
686
|
-
{ internalType: "string", name: "uuid", type: "string" },
|
|
687
|
-
{ internalType: "uint256", name: "expiration", type: "uint256" },
|
|
688
|
-
{ internalType: "address", name: "attester", type: "address" },
|
|
689
|
-
{ internalType: "bytes", name: "signature", type: "bytes" }
|
|
690
|
-
],
|
|
691
|
-
internalType: "struct Attestation",
|
|
692
|
-
name: "_attestation",
|
|
693
|
-
type: "tuple"
|
|
694
|
-
}
|
|
695
|
-
],
|
|
696
|
-
name: "deposit",
|
|
697
|
-
outputs: [{ internalType: "uint256", name: "shares", type: "uint256" }],
|
|
698
|
-
stateMutability: "nonpayable",
|
|
699
|
-
type: "function"
|
|
700
|
-
},
|
|
701
|
-
{
|
|
702
|
-
inputs: [
|
|
703
|
-
{ internalType: "uint256", name: "depositAmount", type: "uint256" },
|
|
704
|
-
{ internalType: "uint256", name: "minimumMint", type: "uint256" },
|
|
705
|
-
{ internalType: "address", name: "to", type: "address" },
|
|
706
|
-
{ internalType: "bytes", name: "distributorCode", type: "bytes" },
|
|
707
|
-
{
|
|
708
|
-
components: [
|
|
709
|
-
{ internalType: "string", name: "uuid", type: "string" },
|
|
710
|
-
{ internalType: "uint256", name: "expiration", type: "uint256" },
|
|
711
|
-
{ internalType: "address", name: "attester", type: "address" },
|
|
712
|
-
{ internalType: "bytes", name: "signature", type: "bytes" }
|
|
713
|
-
],
|
|
714
|
-
internalType: "struct Attestation",
|
|
715
|
-
name: "_attestation",
|
|
716
|
-
type: "tuple"
|
|
717
|
-
}
|
|
718
|
-
],
|
|
719
|
-
name: "depositNative",
|
|
720
|
-
outputs: [{ internalType: "uint256", name: "shares", type: "uint256" }],
|
|
721
|
-
stateMutability: "payable",
|
|
722
|
-
type: "function"
|
|
723
|
-
},
|
|
724
|
-
{
|
|
725
|
-
inputs: [],
|
|
726
|
-
name: "depositNonce",
|
|
727
|
-
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
728
|
-
stateMutability: "view",
|
|
729
|
-
type: "function"
|
|
730
|
-
},
|
|
731
|
-
{
|
|
732
|
-
inputs: [
|
|
733
|
-
{ internalType: "contract ERC20", name: "depositAsset", type: "address" },
|
|
734
|
-
{ internalType: "uint256", name: "depositAmount", type: "uint256" },
|
|
735
|
-
{ internalType: "uint256", name: "minimumMint", type: "uint256" },
|
|
736
|
-
{ internalType: "address", name: "to", type: "address" },
|
|
737
|
-
{ internalType: "bytes", name: "distributorCode", type: "bytes" },
|
|
738
|
-
{
|
|
739
|
-
components: [
|
|
740
|
-
{ internalType: "string", name: "uuid", type: "string" },
|
|
741
|
-
{ internalType: "uint256", name: "expiration", type: "uint256" },
|
|
742
|
-
{ internalType: "address", name: "attester", type: "address" },
|
|
743
|
-
{ internalType: "bytes", name: "signature", type: "bytes" }
|
|
744
|
-
],
|
|
745
|
-
internalType: "struct Attestation",
|
|
746
|
-
name: "_attestation",
|
|
747
|
-
type: "tuple"
|
|
748
|
-
},
|
|
749
|
-
{ internalType: "uint256", name: "deadline", type: "uint256" },
|
|
750
|
-
{ internalType: "uint8", name: "v", type: "uint8" },
|
|
751
|
-
{ internalType: "bytes32", name: "r", type: "bytes32" },
|
|
752
|
-
{ internalType: "bytes32", name: "s", type: "bytes32" }
|
|
753
|
-
],
|
|
754
|
-
name: "depositWithPermit",
|
|
755
|
-
outputs: [{ internalType: "uint256", name: "shares", type: "uint256" }],
|
|
756
|
-
stateMutability: "nonpayable",
|
|
757
|
-
type: "function"
|
|
758
|
-
},
|
|
759
|
-
{
|
|
760
|
-
inputs: [],
|
|
761
|
-
name: "feeModule",
|
|
762
|
-
outputs: [
|
|
763
|
-
{ internalType: "contract IFeeModule", name: "", type: "address" }
|
|
764
|
-
],
|
|
765
|
-
stateMutability: "view",
|
|
766
|
-
type: "function"
|
|
767
|
-
},
|
|
768
|
-
{
|
|
769
|
-
inputs: [],
|
|
770
|
-
name: "feeRecipient",
|
|
771
|
-
outputs: [{ internalType: "address", name: "", type: "address" }],
|
|
772
|
-
stateMutability: "view",
|
|
773
|
-
type: "function"
|
|
774
|
-
},
|
|
775
|
-
{
|
|
776
|
-
inputs: [],
|
|
777
|
-
name: "getPolicyID",
|
|
778
|
-
outputs: [{ internalType: "string", name: "policyID", type: "string" }],
|
|
779
|
-
stateMutability: "view",
|
|
780
|
-
type: "function"
|
|
781
|
-
},
|
|
782
|
-
{
|
|
783
|
-
inputs: [],
|
|
784
|
-
name: "getRegistry",
|
|
785
|
-
outputs: [{ internalType: "address", name: "", type: "address" }],
|
|
786
|
-
stateMutability: "view",
|
|
787
|
-
type: "function"
|
|
788
|
-
},
|
|
789
|
-
{
|
|
790
|
-
inputs: [],
|
|
791
|
-
name: "isNativeDepositSupported",
|
|
792
|
-
outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
|
793
|
-
stateMutability: "view",
|
|
794
|
-
type: "function"
|
|
795
|
-
},
|
|
796
|
-
{
|
|
797
|
-
inputs: [{ internalType: "contract ERC20", name: "", type: "address" }],
|
|
798
|
-
name: "kytEnabled",
|
|
799
|
-
outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
|
800
|
-
stateMutability: "view",
|
|
801
|
-
type: "function"
|
|
802
|
-
},
|
|
803
|
-
{
|
|
804
|
-
inputs: [],
|
|
805
|
-
name: "nativeWrapper",
|
|
806
|
-
outputs: [
|
|
807
|
-
{ internalType: "contract INativeWrapper", name: "", type: "address" }
|
|
808
|
-
],
|
|
809
|
-
stateMutability: "view",
|
|
810
|
-
type: "function"
|
|
811
|
-
},
|
|
812
|
-
{
|
|
813
|
-
inputs: [],
|
|
814
|
-
name: "owner",
|
|
815
|
-
outputs: [{ internalType: "address", name: "", type: "address" }],
|
|
816
|
-
stateMutability: "view",
|
|
817
|
-
type: "function"
|
|
818
|
-
},
|
|
819
|
-
{
|
|
820
|
-
inputs: [
|
|
821
|
-
{
|
|
822
|
-
internalType: "contract Authority",
|
|
823
|
-
name: "newAuthority",
|
|
824
|
-
type: "address"
|
|
825
|
-
}
|
|
826
|
-
],
|
|
827
|
-
name: "setAuthority",
|
|
828
|
-
outputs: [],
|
|
829
|
-
stateMutability: "nonpayable",
|
|
830
|
-
type: "function"
|
|
831
|
-
},
|
|
832
|
-
{
|
|
833
|
-
inputs: [{ internalType: "string", name: "_policyID", type: "string" }],
|
|
834
|
-
name: "setPolicyID",
|
|
835
|
-
outputs: [],
|
|
836
|
-
stateMutability: "nonpayable",
|
|
837
|
-
type: "function"
|
|
838
|
-
},
|
|
839
|
-
{
|
|
840
|
-
inputs: [{ internalType: "address", name: "_registry", type: "address" }],
|
|
841
|
-
name: "setRegistry",
|
|
842
|
-
outputs: [],
|
|
843
|
-
stateMutability: "nonpayable",
|
|
844
|
-
type: "function"
|
|
845
|
-
},
|
|
846
|
-
{
|
|
847
|
-
inputs: [],
|
|
848
|
-
name: "supplyCapInBase",
|
|
849
|
-
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
850
|
-
stateMutability: "view",
|
|
851
|
-
type: "function"
|
|
852
|
-
},
|
|
853
|
-
{
|
|
854
|
-
inputs: [],
|
|
855
|
-
name: "teller",
|
|
856
|
-
outputs: [
|
|
857
|
-
{
|
|
858
|
-
internalType: "contract TellerWithMultiAssetSupport",
|
|
859
|
-
name: "",
|
|
860
|
-
type: "address"
|
|
861
|
-
}
|
|
862
|
-
],
|
|
863
|
-
stateMutability: "view",
|
|
864
|
-
type: "function"
|
|
865
|
-
},
|
|
866
|
-
{
|
|
867
|
-
inputs: [{ internalType: "address", name: "newOwner", type: "address" }],
|
|
868
|
-
name: "transferOwnership",
|
|
869
|
-
outputs: [],
|
|
870
|
-
stateMutability: "nonpayable",
|
|
871
|
-
type: "function"
|
|
872
|
-
},
|
|
873
|
-
{
|
|
874
|
-
inputs: [
|
|
875
|
-
{
|
|
876
|
-
internalType: "contract IFeeModule",
|
|
877
|
-
name: "newFeeModule",
|
|
878
|
-
type: "address"
|
|
879
|
-
}
|
|
880
|
-
],
|
|
881
|
-
name: "updateFeeModule",
|
|
882
|
-
outputs: [],
|
|
883
|
-
stateMutability: "nonpayable",
|
|
884
|
-
type: "function"
|
|
885
|
-
},
|
|
886
|
-
{
|
|
887
|
-
inputs: [
|
|
888
|
-
{ internalType: "address", name: "newFeeRecipient", type: "address" }
|
|
889
|
-
],
|
|
890
|
-
name: "updateFeeRecipient",
|
|
891
|
-
outputs: [],
|
|
892
|
-
stateMutability: "nonpayable",
|
|
893
|
-
type: "function"
|
|
894
|
-
},
|
|
895
|
-
{
|
|
896
|
-
inputs: [
|
|
897
|
-
{ internalType: "contract ERC20", name: "depositAsset", type: "address" },
|
|
898
|
-
{ internalType: "bool", name: "enabled", type: "bool" }
|
|
899
|
-
],
|
|
900
|
-
name: "updateKytStatus",
|
|
901
|
-
outputs: [],
|
|
902
|
-
stateMutability: "nonpayable",
|
|
903
|
-
type: "function"
|
|
904
|
-
},
|
|
905
|
-
{
|
|
906
|
-
inputs: [
|
|
907
|
-
{ internalType: "uint256", name: "newSupplyCapInBase", type: "uint256" }
|
|
908
|
-
],
|
|
909
|
-
name: "updateSupplyCapInBase",
|
|
910
|
-
outputs: [],
|
|
911
|
-
stateMutability: "nonpayable",
|
|
912
|
-
type: "function"
|
|
913
|
-
}
|
|
914
|
-
];
|
|
915
|
-
|
|
916
|
-
// src/vaults/deposit/utils.ts
|
|
917
|
-
var calculateMinimumMint = (depositAmount, rate, vaultTokenDecimals, slippage) => {
|
|
918
|
-
const slippageValue = slippage ?? chunkWYBYBPX5_js.DEFAULT_SLIPPAGE_BPS;
|
|
919
|
-
const slippageAsBigInt = BigInt(slippageValue) * chunkTNL23CO2_js.WAD.bigint / BigInt(1e4);
|
|
920
|
-
const minimumMint = depositAmount * chunkTNL23CO2_js.WAD.bigint / rate;
|
|
921
|
-
const slippageAmount = minimumMint * slippageAsBigInt / chunkTNL23CO2_js.WAD.bigint;
|
|
922
|
-
if (vaultTokenDecimals > 18) {
|
|
923
|
-
return (minimumMint - slippageAmount) * BigInt(10) ** (BigInt(vaultTokenDecimals) - BigInt(18));
|
|
924
|
-
}
|
|
925
|
-
return (minimumMint - slippageAmount) / BigInt(10) ** (BigInt(18) - BigInt(vaultTokenDecimals));
|
|
926
|
-
};
|
|
927
|
-
|
|
928
|
-
// src/vaults/deposit/deposit.ts
|
|
929
|
-
var DepositType = {
|
|
930
|
-
STANDARD: "standard",
|
|
931
|
-
KYT: "kyt"
|
|
932
|
-
};
|
|
933
|
-
function isKytDeposit(data) {
|
|
934
|
-
return data.depositType === DepositType.KYT;
|
|
935
|
-
}
|
|
936
|
-
function isStandardDeposit(data) {
|
|
937
|
-
return data.depositType === DepositType.STANDARD;
|
|
938
|
-
}
|
|
939
|
-
async function prepareDepositTxData(params) {
|
|
940
|
-
const {
|
|
941
|
-
vaultName,
|
|
942
|
-
depositAsset,
|
|
943
|
-
depositAmount,
|
|
944
|
-
chainId,
|
|
945
|
-
slippage = chunkWYBYBPX5_js.DEFAULT_SLIPPAGE_BPS,
|
|
946
|
-
to,
|
|
947
|
-
distributorCode
|
|
948
|
-
} = params;
|
|
949
|
-
try {
|
|
950
|
-
const normalizedChainId = chunkWYBYBPX5_js.toChainId(chainId);
|
|
951
|
-
const vault = await chunkZKDXRGI5_js.resolveVault({
|
|
952
|
-
vaultName,
|
|
953
|
-
assetAddress: depositAsset,
|
|
954
|
-
chainId: normalizedChainId,
|
|
955
|
-
callerEndpoint: "prepareDepositTransactionData"
|
|
956
|
-
});
|
|
957
|
-
if (vault.inDeprecation) {
|
|
958
|
-
chunkWYBYBPX5_js.getLogger().warn(
|
|
959
|
-
`Vault "${vault.name}" is being deprecated. Please contact the Paxos Labs team for migration guidance.`
|
|
960
|
-
);
|
|
961
|
-
}
|
|
962
|
-
const assets = await chunkWYBYBPX5_js.getSupportedAssets({ address: depositAsset });
|
|
963
|
-
const asset = assets.find((a) => a.chains.includes(normalizedChainId)) || assets.find((a) => a.address.toLowerCase() === depositAsset.toLowerCase());
|
|
964
|
-
if (!asset) {
|
|
965
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
966
|
-
`Asset metadata not found for token ${depositAsset} on chain ${normalizedChainId}`,
|
|
967
|
-
{
|
|
968
|
-
endpoint: "prepareDepositTransactionData"
|
|
969
|
-
}
|
|
970
|
-
);
|
|
971
|
-
}
|
|
972
|
-
const communityCodeDepositorAddress = vault.vault.communityCodeDepositorAddress;
|
|
973
|
-
if (!communityCodeDepositorAddress) {
|
|
974
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
975
|
-
`Community Code Depositor contract address not found for vault ${vault.id}`,
|
|
976
|
-
{ endpoint: "prepareDepositTransactionData" }
|
|
977
|
-
);
|
|
978
|
-
}
|
|
979
|
-
const accountantAddress = vault.vault.accountantAddress;
|
|
980
|
-
if (!accountantAddress) {
|
|
981
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
982
|
-
`Accountant contract address not found for vault ${vault.id}`,
|
|
983
|
-
{ endpoint: "prepareDepositTransactionData" }
|
|
984
|
-
);
|
|
985
|
-
}
|
|
986
|
-
const depositAssetAddress = asset.address;
|
|
987
|
-
const [depositAssetDecimalsResult, rateInQuoteResult] = await chunkNNDY5TID_js.getRateInQuoteWithAssetDecimals({
|
|
988
|
-
assetAddress: depositAssetAddress,
|
|
989
|
-
accountantAddress,
|
|
990
|
-
chainId: normalizedChainId
|
|
991
|
-
});
|
|
992
|
-
if (depositAssetDecimalsResult.status === "failure") {
|
|
993
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
994
|
-
`Failed to get asset decimals: ${depositAssetDecimalsResult.error?.message || "Unknown error"}`,
|
|
995
|
-
{
|
|
996
|
-
endpoint: "prepareDepositTransactionData",
|
|
997
|
-
cause: depositAssetDecimalsResult.error
|
|
998
|
-
}
|
|
999
|
-
);
|
|
1000
|
-
}
|
|
1001
|
-
if (rateInQuoteResult.status === "failure") {
|
|
1002
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1003
|
-
`Failed to get exchange rate: ${rateInQuoteResult.error?.message || "Unknown error"}`,
|
|
1004
|
-
{
|
|
1005
|
-
endpoint: "prepareDepositTransactionData",
|
|
1006
|
-
cause: rateInQuoteResult.error
|
|
1007
|
-
}
|
|
1008
|
-
);
|
|
1009
|
-
}
|
|
1010
|
-
const depositAmountAsBigInt = viem.parseUnits(
|
|
1011
|
-
depositAmount,
|
|
1012
|
-
depositAssetDecimalsResult.result
|
|
1013
|
-
);
|
|
1014
|
-
const minimumMint = calculateMinimumMint(
|
|
1015
|
-
depositAmountAsBigInt,
|
|
1016
|
-
rateInQuoteResult.result,
|
|
1017
|
-
depositAssetDecimalsResult.result,
|
|
1018
|
-
slippage
|
|
1019
|
-
);
|
|
1020
|
-
const distributorCodeHex = viem.stringToHex(distributorCode || "");
|
|
1021
|
-
if (vault.enterpriseConfig?.predicatePolicyId != null) {
|
|
1022
|
-
const attestation = {
|
|
1023
|
-
uuid: "",
|
|
1024
|
-
expiration: 0n,
|
|
1025
|
-
attester: viem.zeroAddress,
|
|
1026
|
-
signature: "0x"
|
|
1027
|
-
};
|
|
1028
|
-
return {
|
|
1029
|
-
depositType: DepositType.KYT,
|
|
1030
|
-
address: communityCodeDepositorAddress,
|
|
1031
|
-
abi: DistributorCodeDepositorAbiV1,
|
|
1032
|
-
functionName: "deposit",
|
|
1033
|
-
args: [
|
|
1034
|
-
depositAssetAddress,
|
|
1035
|
-
depositAmountAsBigInt,
|
|
1036
|
-
minimumMint,
|
|
1037
|
-
to,
|
|
1038
|
-
distributorCodeHex,
|
|
1039
|
-
attestation
|
|
1040
|
-
],
|
|
1041
|
-
chainId: normalizedChainId
|
|
1042
|
-
};
|
|
1043
|
-
}
|
|
1044
|
-
return {
|
|
1045
|
-
depositType: DepositType.STANDARD,
|
|
1046
|
-
abi: DistributorCodeDepositorAbiV0,
|
|
1047
|
-
address: communityCodeDepositorAddress,
|
|
1048
|
-
functionName: "deposit",
|
|
1049
|
-
args: [
|
|
1050
|
-
depositAssetAddress,
|
|
1051
|
-
depositAmountAsBigInt,
|
|
1052
|
-
minimumMint,
|
|
1053
|
-
to,
|
|
1054
|
-
distributorCodeHex
|
|
1055
|
-
],
|
|
1056
|
-
chainId: normalizedChainId
|
|
1057
|
-
};
|
|
1058
|
-
} catch (error) {
|
|
1059
|
-
if (error instanceof chunkWYBYBPX5_js.APIError) {
|
|
1060
|
-
throw error;
|
|
1061
|
-
}
|
|
1062
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1063
|
-
`Failed to prepare deposit transaction: ${error instanceof Error ? error.message : String(error)}`,
|
|
1064
|
-
{
|
|
1065
|
-
endpoint: "prepareDepositTransactionData",
|
|
1066
|
-
cause: error
|
|
1067
|
-
}
|
|
1068
|
-
);
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
var PERMIT_TYPES = {
|
|
1072
|
-
Permit: [
|
|
1073
|
-
{ name: "owner", type: "address" },
|
|
1074
|
-
{ name: "spender", type: "address" },
|
|
1075
|
-
{ name: "value", type: "uint256" },
|
|
1076
|
-
{ name: "nonce", type: "uint256" },
|
|
1077
|
-
{ name: "deadline", type: "uint256" }
|
|
1078
|
-
]
|
|
1079
|
-
};
|
|
1080
|
-
var EIP712_DOMAIN_TYPE = [
|
|
1081
|
-
{ name: "name", type: "string" },
|
|
1082
|
-
{ name: "version", type: "string" },
|
|
1083
|
-
{ name: "chainId", type: "uint256" },
|
|
1084
|
-
{ name: "verifyingContract", type: "address" }
|
|
1085
|
-
];
|
|
1086
|
-
function toEthSignTypedDataV4(permitData) {
|
|
1087
|
-
return JSON.stringify({
|
|
1088
|
-
domain: permitData.domain,
|
|
1089
|
-
types: {
|
|
1090
|
-
EIP712Domain: EIP712_DOMAIN_TYPE,
|
|
1091
|
-
...permitData.types
|
|
1092
|
-
},
|
|
1093
|
-
primaryType: permitData.primaryType,
|
|
1094
|
-
message: {
|
|
1095
|
-
owner: permitData.message.owner,
|
|
1096
|
-
spender: permitData.message.spender,
|
|
1097
|
-
value: permitData.message.value.toString(),
|
|
1098
|
-
nonce: permitData.message.nonce.toString(),
|
|
1099
|
-
deadline: permitData.message.deadline.toString()
|
|
1100
|
-
}
|
|
1101
|
-
});
|
|
1102
|
-
}
|
|
1103
|
-
async function prepareDepositPermitSignature(params) {
|
|
1104
|
-
const {
|
|
1105
|
-
vaultName,
|
|
1106
|
-
depositAsset,
|
|
1107
|
-
depositAmount,
|
|
1108
|
-
to,
|
|
1109
|
-
chainId,
|
|
1110
|
-
deadline,
|
|
1111
|
-
// Optional pre-fetched data to skip RPC calls
|
|
1112
|
-
nonce: prefetchedNonce,
|
|
1113
|
-
decimals: prefetchedDecimals,
|
|
1114
|
-
tokenName: prefetchedTokenName,
|
|
1115
|
-
tokenVersion: prefetchedTokenVersion
|
|
1116
|
-
} = params;
|
|
1117
|
-
try {
|
|
1118
|
-
const normalizedChainId = chunkWYBYBPX5_js.toChainId(chainId);
|
|
1119
|
-
const vault = await chunkZKDXRGI5_js.resolveVault({
|
|
1120
|
-
vaultName,
|
|
1121
|
-
assetAddress: depositAsset,
|
|
1122
|
-
chainId: normalizedChainId,
|
|
1123
|
-
callerEndpoint: "prepareDepositPermitSignature"
|
|
1124
|
-
});
|
|
1125
|
-
const communityCodeDepositorAddress = vault.vault.communityCodeDepositorAddress;
|
|
1126
|
-
if (!communityCodeDepositorAddress) {
|
|
1127
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1128
|
-
`CommunityCodeDepositor contract address not found for vault ${vault.id}`,
|
|
1129
|
-
{ endpoint: "prepareDepositPermitSignature" }
|
|
1130
|
-
);
|
|
1131
|
-
}
|
|
1132
|
-
let resolvedTokenName;
|
|
1133
|
-
let resolvedTokenVersion;
|
|
1134
|
-
let resolvedNonce;
|
|
1135
|
-
const hasAllPrefetchedData = prefetchedTokenName !== void 0 && prefetchedTokenVersion !== void 0 && prefetchedNonce !== void 0;
|
|
1136
|
-
if (hasAllPrefetchedData) {
|
|
1137
|
-
resolvedTokenName = prefetchedTokenName;
|
|
1138
|
-
resolvedTokenVersion = prefetchedTokenVersion;
|
|
1139
|
-
resolvedNonce = prefetchedNonce;
|
|
1140
|
-
} else {
|
|
1141
|
-
const client = await chunkWYBYBPX5_js.getClient(normalizedChainId);
|
|
1142
|
-
try {
|
|
1143
|
-
const [nameResult, versionResult, nonceResult] = await client.multicall(
|
|
1144
|
-
{
|
|
1145
|
-
contracts: [
|
|
1146
|
-
{
|
|
1147
|
-
address: depositAsset,
|
|
1148
|
-
abi: chunkNNDY5TID_js.erc2612Abi,
|
|
1149
|
-
functionName: "name"
|
|
1150
|
-
},
|
|
1151
|
-
{
|
|
1152
|
-
address: depositAsset,
|
|
1153
|
-
abi: chunkNNDY5TID_js.erc2612Abi,
|
|
1154
|
-
functionName: "version"
|
|
1155
|
-
},
|
|
1156
|
-
{
|
|
1157
|
-
address: depositAsset,
|
|
1158
|
-
abi: chunkNNDY5TID_js.erc2612Abi,
|
|
1159
|
-
functionName: "nonces",
|
|
1160
|
-
args: [to]
|
|
1161
|
-
}
|
|
1162
|
-
]
|
|
1163
|
-
}
|
|
1164
|
-
);
|
|
1165
|
-
if (prefetchedTokenName !== void 0) {
|
|
1166
|
-
resolvedTokenName = prefetchedTokenName;
|
|
1167
|
-
} else if (nameResult.status === "success") {
|
|
1168
|
-
resolvedTokenName = nameResult.result;
|
|
1169
|
-
} else {
|
|
1170
|
-
throw new chunkWYBYBPX5_js.APIError(`Failed to read token name from ${depositAsset}`, {
|
|
1171
|
-
endpoint: "prepareDepositPermitSignature",
|
|
1172
|
-
cause: nameResult.error
|
|
1173
|
-
});
|
|
1174
|
-
}
|
|
1175
|
-
if (prefetchedTokenVersion !== void 0) {
|
|
1176
|
-
resolvedTokenVersion = prefetchedTokenVersion;
|
|
1177
|
-
} else if (versionResult.status === "success") {
|
|
1178
|
-
resolvedTokenVersion = versionResult.result;
|
|
1179
|
-
} else {
|
|
1180
|
-
resolvedTokenVersion = "1";
|
|
1181
|
-
}
|
|
1182
|
-
if (prefetchedNonce !== void 0) {
|
|
1183
|
-
resolvedNonce = prefetchedNonce;
|
|
1184
|
-
} else if (nonceResult.status === "success") {
|
|
1185
|
-
resolvedNonce = nonceResult.result;
|
|
1186
|
-
} else {
|
|
1187
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1188
|
-
`Token ${depositAsset} does not support EIP-2612 permit. Missing required function: nonces()`,
|
|
1189
|
-
{
|
|
1190
|
-
endpoint: "prepareDepositPermitSignature",
|
|
1191
|
-
cause: nonceResult.error
|
|
1192
|
-
}
|
|
1193
|
-
);
|
|
1194
|
-
}
|
|
1195
|
-
} catch (error) {
|
|
1196
|
-
if (error instanceof chunkWYBYBPX5_js.APIError) {
|
|
1197
|
-
throw error;
|
|
1198
|
-
}
|
|
1199
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1200
|
-
`Failed to read token metadata: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
1201
|
-
{
|
|
1202
|
-
endpoint: "prepareDepositPermitSignature",
|
|
1203
|
-
cause: error
|
|
1204
|
-
}
|
|
1205
|
-
);
|
|
1206
|
-
}
|
|
1207
|
-
}
|
|
1208
|
-
const permitDeadline = deadline ?? BigInt(Math.floor(Date.now() / 1e3) + 3600);
|
|
1209
|
-
let resolvedDecimals;
|
|
1210
|
-
if (prefetchedDecimals !== void 0) {
|
|
1211
|
-
resolvedDecimals = prefetchedDecimals;
|
|
1212
|
-
} else {
|
|
1213
|
-
resolvedDecimals = await chunkNNDY5TID_js.getErc20Decimals({
|
|
1214
|
-
tokenAddress: depositAsset,
|
|
1215
|
-
chainId: normalizedChainId
|
|
1216
|
-
});
|
|
1217
|
-
}
|
|
1218
|
-
const value = viem.parseUnits(depositAmount, resolvedDecimals);
|
|
1219
|
-
const domain = {
|
|
1220
|
-
name: resolvedTokenName,
|
|
1221
|
-
version: resolvedTokenVersion,
|
|
1222
|
-
chainId: normalizedChainId,
|
|
1223
|
-
verifyingContract: depositAsset
|
|
1224
|
-
};
|
|
1225
|
-
const message = {
|
|
1226
|
-
owner: to,
|
|
1227
|
-
spender: communityCodeDepositorAddress,
|
|
1228
|
-
value,
|
|
1229
|
-
nonce: resolvedNonce,
|
|
1230
|
-
deadline: permitDeadline
|
|
1231
|
-
};
|
|
1232
|
-
return {
|
|
1233
|
-
account: to,
|
|
1234
|
-
domain,
|
|
1235
|
-
types: PERMIT_TYPES,
|
|
1236
|
-
primaryType: "Permit",
|
|
1237
|
-
message
|
|
1238
|
-
};
|
|
1239
|
-
} catch (error) {
|
|
1240
|
-
if (error instanceof chunkWYBYBPX5_js.APIError) {
|
|
1241
|
-
throw error;
|
|
1242
|
-
}
|
|
1243
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1244
|
-
`Failed to prepare permit signature: ${error instanceof Error ? error.message : String(error)}`,
|
|
1245
|
-
{
|
|
1246
|
-
endpoint: "prepareDepositPermitSignature",
|
|
1247
|
-
cause: error
|
|
1248
|
-
}
|
|
1249
|
-
);
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
function parsePermitSignature(signature) {
|
|
1253
|
-
try {
|
|
1254
|
-
const parsed = viem.hexToSignature(signature);
|
|
1255
|
-
let v;
|
|
1256
|
-
if (parsed.v !== void 0) {
|
|
1257
|
-
v = Number(parsed.v);
|
|
1258
|
-
} else if (parsed.yParity !== void 0) {
|
|
1259
|
-
v = parsed.yParity + 27;
|
|
1260
|
-
} else {
|
|
1261
|
-
v = 27;
|
|
1262
|
-
}
|
|
1263
|
-
return {
|
|
1264
|
-
v,
|
|
1265
|
-
r: parsed.r,
|
|
1266
|
-
s: parsed.s
|
|
1267
|
-
};
|
|
1268
|
-
} catch (error) {
|
|
1269
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1270
|
-
`Invalid permit signature format. Expected hex string but received: ${signature}. ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
1271
|
-
{
|
|
1272
|
-
endpoint: "parsePermitSignature",
|
|
1273
|
-
cause: error
|
|
1274
|
-
}
|
|
1275
|
-
);
|
|
1276
|
-
}
|
|
1277
|
-
}
|
|
1278
|
-
async function prepareDepositWithPermitTxData(params) {
|
|
1279
|
-
const {
|
|
1280
|
-
vaultName,
|
|
1281
|
-
depositAsset,
|
|
1282
|
-
depositAmount,
|
|
1283
|
-
chainId,
|
|
1284
|
-
signature,
|
|
1285
|
-
deadline,
|
|
1286
|
-
slippage = chunkWYBYBPX5_js.DEFAULT_SLIPPAGE_BPS,
|
|
1287
|
-
to,
|
|
1288
|
-
distributorCode
|
|
1289
|
-
} = params;
|
|
1290
|
-
try {
|
|
1291
|
-
const { v, r, s } = parsePermitSignature(signature);
|
|
1292
|
-
if (slippage < 0 || slippage > 1e4) {
|
|
1293
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1294
|
-
`Invalid slippage value: ${slippage}. Slippage must be between 0 and 10000 basis points.`,
|
|
1295
|
-
{
|
|
1296
|
-
endpoint: "prepareDepositWithPermitTxData"
|
|
1297
|
-
}
|
|
1298
|
-
);
|
|
1299
|
-
}
|
|
1300
|
-
const normalizedChainId = chunkWYBYBPX5_js.toChainId(chainId);
|
|
1301
|
-
const vault = await chunkZKDXRGI5_js.resolveVault({
|
|
1302
|
-
vaultName,
|
|
1303
|
-
assetAddress: depositAsset,
|
|
1304
|
-
chainId: normalizedChainId,
|
|
1305
|
-
callerEndpoint: "prepareDepositWithPermitTxData"
|
|
1306
|
-
});
|
|
1307
|
-
if (vault.inDeprecation) {
|
|
1308
|
-
chunkWYBYBPX5_js.getLogger().warn(
|
|
1309
|
-
`Vault "${vault.name}" is being deprecated. Please contact the Paxos Labs team for migration guidance.`
|
|
1310
|
-
);
|
|
1311
|
-
}
|
|
1312
|
-
let asset = null;
|
|
1313
|
-
const assets = await chunkWYBYBPX5_js.getSupportedAssets({ address: depositAsset });
|
|
1314
|
-
if (assets.length > 0) {
|
|
1315
|
-
asset = assets.find((a) => a.chains.includes(normalizedChainId)) || assets[0] || null;
|
|
1316
|
-
}
|
|
1317
|
-
if (!asset) {
|
|
1318
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1319
|
-
`Asset metadata not found for token ${depositAsset} on chain ${normalizedChainId}`,
|
|
1320
|
-
{
|
|
1321
|
-
endpoint: "prepareDepositWithPermitTxData"
|
|
1322
|
-
}
|
|
1323
|
-
);
|
|
1324
|
-
}
|
|
1325
|
-
if (!asset.chains || !asset.chains.includes(normalizedChainId)) {
|
|
1326
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1327
|
-
`Token ${asset.symbol || depositAsset} not supported on chain ${normalizedChainId}`,
|
|
1328
|
-
{
|
|
1329
|
-
endpoint: "prepareDepositWithPermitTxData"
|
|
1330
|
-
}
|
|
1331
|
-
);
|
|
1332
|
-
}
|
|
1333
|
-
const communityCodeDepositorAddress = vault.vault.communityCodeDepositorAddress;
|
|
1334
|
-
const accountantAddress = vault.vault.accountantAddress;
|
|
1335
|
-
const depositAssetAddress = depositAsset;
|
|
1336
|
-
if (!communityCodeDepositorAddress) {
|
|
1337
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1338
|
-
`CommunityCodeDepositor contract address not found for vault ${vault.id}`,
|
|
1339
|
-
{ endpoint: "prepareDepositWithPermitTxData" }
|
|
1340
|
-
);
|
|
1341
|
-
}
|
|
1342
|
-
if (!accountantAddress) {
|
|
1343
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1344
|
-
`Accountant contract address not found for vault ${vault.id}`,
|
|
1345
|
-
{ endpoint: "prepareDepositWithPermitTxData" }
|
|
1346
|
-
);
|
|
1347
|
-
}
|
|
1348
|
-
const rateAndDecimalResults = await chunkNNDY5TID_js.getRateInQuoteWithAssetDecimals({
|
|
1349
|
-
assetAddress: depositAssetAddress,
|
|
1350
|
-
accountantAddress,
|
|
1351
|
-
chainId: normalizedChainId
|
|
1352
|
-
});
|
|
1353
|
-
const [depositAssetDecimalsResult, rateInQuoteResult] = rateAndDecimalResults;
|
|
1354
|
-
if (depositAssetDecimalsResult.status === "failure") {
|
|
1355
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1356
|
-
`Failed to get asset decimals: ${depositAssetDecimalsResult.error?.message || "Unknown error"}`,
|
|
1357
|
-
{
|
|
1358
|
-
endpoint: "prepareDepositWithPermitTxData",
|
|
1359
|
-
cause: depositAssetDecimalsResult.error
|
|
1360
|
-
}
|
|
1361
|
-
);
|
|
1362
|
-
}
|
|
1363
|
-
if (rateInQuoteResult.status === "failure") {
|
|
1364
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1365
|
-
`Failed to get exchange rate: ${rateInQuoteResult.error?.message || "Unknown error"}`,
|
|
1366
|
-
{
|
|
1367
|
-
endpoint: "prepareDepositWithPermitTxData",
|
|
1368
|
-
cause: rateInQuoteResult.error
|
|
1369
|
-
}
|
|
1370
|
-
);
|
|
1371
|
-
}
|
|
1372
|
-
const onChainDecimals = depositAssetDecimalsResult.result;
|
|
1373
|
-
const depositAmountAsBigInt = viem.parseUnits(depositAmount, onChainDecimals);
|
|
1374
|
-
const minimumMint = calculateMinimumMint(
|
|
1375
|
-
depositAmountAsBigInt,
|
|
1376
|
-
rateInQuoteResult.result,
|
|
1377
|
-
onChainDecimals,
|
|
1378
|
-
slippage
|
|
1379
|
-
);
|
|
1380
|
-
const distributorCodeHex = viem.stringToHex(distributorCode || "");
|
|
1381
|
-
if (vault.enterpriseConfig?.predicatePolicyId != null) {
|
|
1382
|
-
const attestation = {
|
|
1383
|
-
uuid: "",
|
|
1384
|
-
expiration: 0n,
|
|
1385
|
-
attester: viem.zeroAddress,
|
|
1386
|
-
signature: "0x"
|
|
1387
|
-
};
|
|
1388
|
-
return {
|
|
1389
|
-
depositType: DepositType.KYT,
|
|
1390
|
-
abi: DistributorCodeDepositorAbiV1,
|
|
1391
|
-
address: communityCodeDepositorAddress,
|
|
1392
|
-
functionName: "depositWithPermit",
|
|
1393
|
-
args: [
|
|
1394
|
-
depositAssetAddress,
|
|
1395
|
-
depositAmountAsBigInt,
|
|
1396
|
-
minimumMint,
|
|
1397
|
-
to,
|
|
1398
|
-
distributorCodeHex,
|
|
1399
|
-
attestation,
|
|
1400
|
-
deadline,
|
|
1401
|
-
v,
|
|
1402
|
-
r,
|
|
1403
|
-
s
|
|
1404
|
-
],
|
|
1405
|
-
chainId: normalizedChainId
|
|
1406
|
-
};
|
|
1407
|
-
}
|
|
1408
|
-
return {
|
|
1409
|
-
depositType: DepositType.STANDARD,
|
|
1410
|
-
abi: DistributorCodeDepositorAbiV0,
|
|
1411
|
-
address: communityCodeDepositorAddress,
|
|
1412
|
-
functionName: "depositWithPermit",
|
|
1413
|
-
args: [
|
|
1414
|
-
depositAssetAddress,
|
|
1415
|
-
depositAmountAsBigInt,
|
|
1416
|
-
minimumMint,
|
|
1417
|
-
to,
|
|
1418
|
-
distributorCodeHex,
|
|
1419
|
-
deadline,
|
|
1420
|
-
v,
|
|
1421
|
-
r,
|
|
1422
|
-
s
|
|
1423
|
-
],
|
|
1424
|
-
chainId: normalizedChainId
|
|
1425
|
-
};
|
|
1426
|
-
} catch (error) {
|
|
1427
|
-
if (error instanceof chunkWYBYBPX5_js.APIError) {
|
|
1428
|
-
throw error;
|
|
1429
|
-
}
|
|
1430
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1431
|
-
`Failed to prepare deposit with permit transaction: ${error instanceof Error ? error.message : String(error)}`,
|
|
1432
|
-
{
|
|
1433
|
-
endpoint: "prepareDepositWithPermitTxData",
|
|
1434
|
-
cause: error
|
|
1435
|
-
}
|
|
1436
|
-
);
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
|
|
1440
|
-
// src/utils/wallet.ts
|
|
1441
|
-
async function isSmartContractWallet(address, chainId) {
|
|
1442
|
-
const client = await chunkWYBYBPX5_js.getClient(chainId);
|
|
1443
|
-
const code = await client.getCode({ address });
|
|
1444
|
-
return !!code && code !== "0x";
|
|
1445
|
-
}
|
|
1446
|
-
|
|
1447
|
-
// src/vaults/deposit/index.ts
|
|
1448
|
-
var DepositAuthMethod = {
|
|
1449
|
-
PERMIT: "permit",
|
|
1450
|
-
APPROVAL: "approval",
|
|
1451
|
-
ALREADY_APPROVED: "already_approved"
|
|
1452
|
-
};
|
|
1453
|
-
function isPermitAuth(result) {
|
|
1454
|
-
return result.method === DepositAuthMethod.PERMIT;
|
|
1455
|
-
}
|
|
1456
|
-
function isApprovalAuth(result) {
|
|
1457
|
-
return result.method === DepositAuthMethod.APPROVAL;
|
|
1458
|
-
}
|
|
1459
|
-
function isAlreadyApprovedAuth(result) {
|
|
1460
|
-
return result.method === DepositAuthMethod.ALREADY_APPROVED;
|
|
1461
|
-
}
|
|
1462
|
-
async function prepareDepositAuthorization(params) {
|
|
1463
|
-
const {
|
|
1464
|
-
vaultName,
|
|
1465
|
-
depositAsset,
|
|
1466
|
-
depositAmount,
|
|
1467
|
-
to,
|
|
1468
|
-
chainId,
|
|
1469
|
-
deadline,
|
|
1470
|
-
forceMethod
|
|
1471
|
-
} = params;
|
|
1472
|
-
try {
|
|
1473
|
-
const normalizedChainId = chunkWYBYBPX5_js.toChainId(chainId);
|
|
1474
|
-
const vault = await chunkZKDXRGI5_js.resolveVault({
|
|
1475
|
-
vaultName,
|
|
1476
|
-
assetAddress: depositAsset,
|
|
1477
|
-
chainId: normalizedChainId,
|
|
1478
|
-
callerEndpoint: "prepareDepositAuthorization"
|
|
1479
|
-
});
|
|
1480
|
-
if (forceMethod === "approval") {
|
|
1481
|
-
const txData2 = await prepareApproveDepositTokenTxData({
|
|
1482
|
-
vaultName,
|
|
1483
|
-
depositAsset,
|
|
1484
|
-
approvalAmount: depositAmount,
|
|
1485
|
-
chainId: normalizedChainId
|
|
1486
|
-
});
|
|
1487
|
-
return {
|
|
1488
|
-
method: DepositAuthMethod.APPROVAL,
|
|
1489
|
-
txData: txData2
|
|
1490
|
-
};
|
|
1491
|
-
}
|
|
1492
|
-
if (forceMethod === "permit") {
|
|
1493
|
-
const tokenInfo2 = await isDepositSpendApproved({
|
|
1494
|
-
vaultName: vault.name,
|
|
1495
|
-
chainId: normalizedChainId,
|
|
1496
|
-
depositAssetAddress: depositAsset,
|
|
1497
|
-
recipientAddress: to
|
|
1498
|
-
});
|
|
1499
|
-
const permitData = await prepareDepositPermitSignature({
|
|
1500
|
-
vaultName,
|
|
1501
|
-
depositAsset,
|
|
1502
|
-
depositAmount,
|
|
1503
|
-
to,
|
|
1504
|
-
chainId: normalizedChainId,
|
|
1505
|
-
deadline,
|
|
1506
|
-
nonce: tokenInfo2.nonce ?? void 0,
|
|
1507
|
-
decimals: tokenInfo2.decimals,
|
|
1508
|
-
tokenName: tokenInfo2.tokenName,
|
|
1509
|
-
tokenVersion: tokenInfo2.tokenVersion
|
|
1510
|
-
});
|
|
1511
|
-
return {
|
|
1512
|
-
method: DepositAuthMethod.PERMIT,
|
|
1513
|
-
permitData
|
|
1514
|
-
};
|
|
1515
|
-
}
|
|
1516
|
-
const smartWallet = await isSmartContractWallet(to, normalizedChainId);
|
|
1517
|
-
if (smartWallet) {
|
|
1518
|
-
const txData2 = await prepareApproveDepositTokenTxData({
|
|
1519
|
-
vaultName,
|
|
1520
|
-
depositAsset,
|
|
1521
|
-
approvalAmount: depositAmount,
|
|
1522
|
-
chainId: normalizedChainId
|
|
1523
|
-
});
|
|
1524
|
-
return {
|
|
1525
|
-
method: DepositAuthMethod.APPROVAL,
|
|
1526
|
-
txData: txData2
|
|
1527
|
-
};
|
|
1528
|
-
}
|
|
1529
|
-
const tokenInfo = await isDepositSpendApproved({
|
|
1530
|
-
vaultName: vault.name,
|
|
1531
|
-
chainId: normalizedChainId,
|
|
1532
|
-
depositAssetAddress: depositAsset,
|
|
1533
|
-
recipientAddress: to
|
|
1534
|
-
});
|
|
1535
|
-
if (tokenInfo.supportsPermit) {
|
|
1536
|
-
const permitData = await prepareDepositPermitSignature({
|
|
1537
|
-
vaultName,
|
|
1538
|
-
depositAsset,
|
|
1539
|
-
depositAmount,
|
|
1540
|
-
to,
|
|
1541
|
-
chainId: normalizedChainId,
|
|
1542
|
-
deadline,
|
|
1543
|
-
nonce: tokenInfo.nonce ?? void 0,
|
|
1544
|
-
decimals: tokenInfo.decimals,
|
|
1545
|
-
tokenName: tokenInfo.tokenName,
|
|
1546
|
-
tokenVersion: tokenInfo.tokenVersion
|
|
1547
|
-
});
|
|
1548
|
-
return {
|
|
1549
|
-
method: DepositAuthMethod.PERMIT,
|
|
1550
|
-
permitData
|
|
1551
|
-
};
|
|
1552
|
-
}
|
|
1553
|
-
const depositAmountBigInt = viem.parseUnits(depositAmount, tokenInfo.decimals);
|
|
1554
|
-
const currentAllowanceBigInt = BigInt(tokenInfo.allowanceAsBigInt);
|
|
1555
|
-
if (tokenInfo.isApproved && currentAllowanceBigInt >= depositAmountBigInt) {
|
|
1556
|
-
return {
|
|
1557
|
-
method: DepositAuthMethod.ALREADY_APPROVED,
|
|
1558
|
-
allowance: tokenInfo.allowance,
|
|
1559
|
-
allowanceAsBigInt: tokenInfo.allowanceAsBigInt
|
|
1560
|
-
};
|
|
1561
|
-
}
|
|
1562
|
-
const txData = await prepareApproveDepositTokenTxData({
|
|
1563
|
-
vaultName,
|
|
1564
|
-
depositAsset,
|
|
1565
|
-
approvalAmount: depositAmount,
|
|
1566
|
-
chainId: normalizedChainId
|
|
1567
|
-
});
|
|
1568
|
-
return {
|
|
1569
|
-
method: DepositAuthMethod.APPROVAL,
|
|
1570
|
-
txData
|
|
1571
|
-
};
|
|
1572
|
-
} catch (error) {
|
|
1573
|
-
if (error instanceof chunkWYBYBPX5_js.APIError) {
|
|
1574
|
-
throw error;
|
|
1575
|
-
}
|
|
1576
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1577
|
-
`Failed to prepare deposit authorization: ${error instanceof Error ? error.message : String(error)}`,
|
|
1578
|
-
{
|
|
1579
|
-
endpoint: "prepareDepositAuthorization",
|
|
1580
|
-
cause: error
|
|
1581
|
-
}
|
|
1582
|
-
);
|
|
1583
|
-
}
|
|
1584
|
-
}
|
|
1585
|
-
async function prepareDeposit(params) {
|
|
1586
|
-
const {
|
|
1587
|
-
vaultName,
|
|
1588
|
-
depositAsset,
|
|
1589
|
-
depositAmount,
|
|
1590
|
-
to,
|
|
1591
|
-
chainId,
|
|
1592
|
-
slippage,
|
|
1593
|
-
distributorCode,
|
|
1594
|
-
signature,
|
|
1595
|
-
deadline,
|
|
1596
|
-
forceMethod
|
|
1597
|
-
} = params;
|
|
1598
|
-
try {
|
|
1599
|
-
if (forceMethod === "permit" && (!signature || deadline === void 0)) {
|
|
1600
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1601
|
-
"Permit deposit requires both signature and deadline parameters when forceMethod is 'permit'",
|
|
1602
|
-
{ endpoint: "prepareDeposit" }
|
|
1603
|
-
);
|
|
1604
|
-
}
|
|
1605
|
-
const usePermit = forceMethod === "permit" || forceMethod !== "approval" && signature !== void 0 && deadline !== void 0;
|
|
1606
|
-
if (usePermit) {
|
|
1607
|
-
if (!signature || deadline === void 0) {
|
|
1608
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1609
|
-
"Permit deposit requires both signature and deadline parameters",
|
|
1610
|
-
{ endpoint: "prepareDeposit" }
|
|
1611
|
-
);
|
|
1612
|
-
}
|
|
1613
|
-
const txData2 = await prepareDepositWithPermitTxData({
|
|
1614
|
-
vaultName,
|
|
1615
|
-
depositAsset,
|
|
1616
|
-
depositAmount,
|
|
1617
|
-
to,
|
|
1618
|
-
chainId,
|
|
1619
|
-
signature,
|
|
1620
|
-
deadline,
|
|
1621
|
-
slippage,
|
|
1622
|
-
distributorCode
|
|
1623
|
-
});
|
|
1624
|
-
return {
|
|
1625
|
-
method: DepositAuthMethod.PERMIT,
|
|
1626
|
-
txData: txData2
|
|
1627
|
-
};
|
|
1628
|
-
}
|
|
1629
|
-
const txData = await prepareDepositTxData({
|
|
1630
|
-
vaultName,
|
|
1631
|
-
depositAsset,
|
|
1632
|
-
depositAmount,
|
|
1633
|
-
to,
|
|
1634
|
-
chainId,
|
|
1635
|
-
slippage,
|
|
1636
|
-
distributorCode
|
|
1637
|
-
});
|
|
1638
|
-
return {
|
|
1639
|
-
method: DepositAuthMethod.APPROVAL,
|
|
1640
|
-
txData
|
|
1641
|
-
};
|
|
1642
|
-
} catch (error) {
|
|
1643
|
-
if (error instanceof chunkWYBYBPX5_js.APIError) {
|
|
1644
|
-
throw error;
|
|
1645
|
-
}
|
|
1646
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1647
|
-
`Failed to prepare deposit: ${error instanceof Error ? error.message : String(error)}`,
|
|
1648
|
-
{
|
|
1649
|
-
endpoint: "prepareDeposit",
|
|
1650
|
-
cause: error
|
|
1651
|
-
}
|
|
1652
|
-
);
|
|
1653
|
-
}
|
|
1654
|
-
}
|
|
1655
|
-
async function prepareApproveWithdrawOrderTxData({
|
|
1656
|
-
vaultName,
|
|
1657
|
-
wantAssetAddress,
|
|
1658
|
-
withdrawAmount,
|
|
1659
|
-
chainId,
|
|
1660
|
-
shareDecimals
|
|
1661
|
-
}) {
|
|
1662
|
-
try {
|
|
1663
|
-
const normalizedChainId = chunkWYBYBPX5_js.toChainId(chainId);
|
|
1664
|
-
const config = await chunkZKDXRGI5_js.resolveVault({
|
|
1665
|
-
vaultName,
|
|
1666
|
-
assetAddress: wantAssetAddress,
|
|
1667
|
-
chainId: normalizedChainId,
|
|
1668
|
-
callerEndpoint: "prepareApproveWithdrawOrderTxData"
|
|
1669
|
-
});
|
|
1670
|
-
if (!config.vault.boringVaultAddress) {
|
|
1671
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1672
|
-
`BoringVault contract address not configured for vault ${config.id}`,
|
|
1673
|
-
{ endpoint: "prepareApproveWithdrawOrderTxData" }
|
|
1674
|
-
);
|
|
1675
|
-
}
|
|
1676
|
-
if (!config.vault.withdrawQueueAddress) {
|
|
1677
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1678
|
-
`WithdrawQueue contract address not configured for vault ${config.id}`,
|
|
1679
|
-
{ endpoint: "prepareApproveWithdrawOrderTxData" }
|
|
1680
|
-
);
|
|
1681
|
-
}
|
|
1682
|
-
const boringVaultAddress = config.vault.boringVaultAddress;
|
|
1683
|
-
const withdrawQueueAddress = config.vault.withdrawQueueAddress;
|
|
1684
|
-
const decimals = shareDecimals ?? await chunkNNDY5TID_js.getErc20Decimals({
|
|
1685
|
-
tokenAddress: boringVaultAddress,
|
|
1686
|
-
chainId: normalizedChainId
|
|
1687
|
-
});
|
|
1688
|
-
const withdrawAmountAsBigInt = withdrawAmount ? viem.parseUnits(withdrawAmount, decimals) : chunkWYBYBPX5_js.DEFAULT_APPROVAL_AMOUNT;
|
|
1689
|
-
return {
|
|
1690
|
-
abi: chunkNNDY5TID_js.BoringVaultAbi,
|
|
1691
|
-
address: boringVaultAddress,
|
|
1692
|
-
functionName: "approve",
|
|
1693
|
-
args: [withdrawQueueAddress, withdrawAmountAsBigInt]
|
|
1694
|
-
};
|
|
1695
|
-
} catch (error) {
|
|
1696
|
-
if (error instanceof chunkWYBYBPX5_js.APIError) {
|
|
1697
|
-
throw error;
|
|
1698
|
-
}
|
|
1699
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1700
|
-
`Failed to prepare approval transaction: ${error instanceof Error ? error.message : String(error)}`,
|
|
1701
|
-
{
|
|
1702
|
-
endpoint: "prepareApproveWithdrawOrderTxData",
|
|
1703
|
-
cause: error
|
|
1704
|
-
}
|
|
1705
|
-
);
|
|
1706
|
-
}
|
|
1707
|
-
}
|
|
1708
|
-
|
|
1709
|
-
// src/vaults/withdraw/cancel-withdraw.ts
|
|
1710
|
-
var prepareCancelWithdrawOrderTxData = async ({
|
|
1711
|
-
vaultName,
|
|
1712
|
-
wantAsset,
|
|
1713
|
-
chainId,
|
|
1714
|
-
orderIndex
|
|
1715
|
-
}) => {
|
|
1716
|
-
try {
|
|
1717
|
-
const normalizedChainId = chunkWYBYBPX5_js.toChainId(chainId);
|
|
1718
|
-
const config = await chunkZKDXRGI5_js.resolveVault({
|
|
1719
|
-
vaultName,
|
|
1720
|
-
assetAddress: wantAsset,
|
|
1721
|
-
chainId: normalizedChainId,
|
|
1722
|
-
callerEndpoint: "prepareCancelWithdrawOrderTxData"
|
|
1723
|
-
});
|
|
1724
|
-
if (config.chainId !== normalizedChainId) {
|
|
1725
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1726
|
-
`Vault chain mismatch: vault is on chain ${config.chainId}, requested chain ${normalizedChainId}`,
|
|
1727
|
-
{ endpoint: "prepareCancelWithdrawOrderTxData" }
|
|
1728
|
-
);
|
|
1729
|
-
}
|
|
1730
|
-
if (!config.vault.withdrawQueueAddress) {
|
|
1731
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1732
|
-
`WithdrawQueue contract address not configured for vault ${config.id}`,
|
|
1733
|
-
{ endpoint: "prepareCancelWithdrawOrderTxData" }
|
|
1734
|
-
);
|
|
1735
|
-
}
|
|
1736
|
-
return {
|
|
1737
|
-
abi: chunkZKDXRGI5_js.WithdrawQueueAbi,
|
|
1738
|
-
address: config.vault.withdrawQueueAddress,
|
|
1739
|
-
functionName: "cancelOrder",
|
|
1740
|
-
args: [orderIndex],
|
|
1741
|
-
chainId: normalizedChainId
|
|
1742
|
-
};
|
|
1743
|
-
} catch (error) {
|
|
1744
|
-
if (error instanceof chunkWYBYBPX5_js.APIError) {
|
|
1745
|
-
throw error;
|
|
1746
|
-
}
|
|
1747
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1748
|
-
`Failed to prepare cancel order transaction: ${error instanceof Error ? error.message : String(error)}`,
|
|
1749
|
-
{
|
|
1750
|
-
endpoint: "prepareCancelWithdrawOrderTxData",
|
|
1751
|
-
cause: error
|
|
1752
|
-
}
|
|
1753
|
-
);
|
|
1754
|
-
}
|
|
1755
|
-
};
|
|
1756
|
-
var ApprovalMethod = {
|
|
1757
|
-
/** Standard ERC20 approve (user has pre-approved via approve()) */
|
|
1758
|
-
EIP20_APPROVE: 0};
|
|
1759
|
-
var EMPTY_SIGNATURE_PARAMS = {
|
|
1760
|
-
approvalMethod: ApprovalMethod.EIP20_APPROVE,
|
|
1761
|
-
approvalV: 0,
|
|
1762
|
-
approvalR: "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
1763
|
-
approvalS: "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
1764
|
-
submitWithSignature: false,
|
|
1765
|
-
deadline: 0n,
|
|
1766
|
-
eip2612Signature: "0x"
|
|
1767
|
-
};
|
|
1768
|
-
var prepareWithdrawOrderTxData = async ({
|
|
1769
|
-
vaultName,
|
|
1770
|
-
wantAsset,
|
|
1771
|
-
userAddress,
|
|
1772
|
-
chainId,
|
|
1773
|
-
amountOffer
|
|
1774
|
-
}) => {
|
|
1775
|
-
try {
|
|
1776
|
-
const normalizedChainId = chunkWYBYBPX5_js.toChainId(chainId);
|
|
1777
|
-
const config = await chunkZKDXRGI5_js.resolveVault({
|
|
1778
|
-
vaultName,
|
|
1779
|
-
assetAddress: wantAsset,
|
|
1780
|
-
chainId: normalizedChainId,
|
|
1781
|
-
callerEndpoint: "prepareWithdrawOrderTxData"
|
|
1782
|
-
});
|
|
1783
|
-
if (config.chainId !== normalizedChainId) {
|
|
1784
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1785
|
-
`Vault chain mismatch: vault is on chain ${config.chainId}, requested chain ${normalizedChainId}`,
|
|
1786
|
-
{ endpoint: "prepareWithdrawOrderTxData" }
|
|
1787
|
-
);
|
|
1788
|
-
}
|
|
1789
|
-
if (!config.vault.withdrawQueueAddress) {
|
|
1790
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1791
|
-
`WithdrawQueue contract address not configured for vault ${config.id}`,
|
|
1792
|
-
{ endpoint: "prepareWithdrawOrderTxData" }
|
|
1793
|
-
);
|
|
1794
|
-
}
|
|
1795
|
-
if (!config.vault.boringVaultAddress) {
|
|
1796
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1797
|
-
`BoringVault contract address not configured for vault ${config.id}`,
|
|
1798
|
-
{ endpoint: "prepareWithdrawOrderTxData" }
|
|
1799
|
-
);
|
|
1800
|
-
}
|
|
1801
|
-
const sharesDecimals = await chunkNNDY5TID_js.getErc20Decimals({
|
|
1802
|
-
tokenAddress: config.vault.boringVaultAddress,
|
|
1803
|
-
chainId: normalizedChainId
|
|
1804
|
-
});
|
|
1805
|
-
const formattedAmountOffer = viem.parseUnits(amountOffer, sharesDecimals);
|
|
1806
|
-
return {
|
|
1807
|
-
abi: chunkZKDXRGI5_js.WithdrawQueueAbi,
|
|
1808
|
-
address: config.vault.withdrawQueueAddress,
|
|
1809
|
-
functionName: "submitOrder",
|
|
1810
|
-
args: [
|
|
1811
|
-
{
|
|
1812
|
-
amountOffer: formattedAmountOffer,
|
|
1813
|
-
wantAsset,
|
|
1814
|
-
intendedDepositor: userAddress,
|
|
1815
|
-
receiver: userAddress,
|
|
1816
|
-
refundReceiver: userAddress,
|
|
1817
|
-
signatureParams: EMPTY_SIGNATURE_PARAMS
|
|
1818
|
-
}
|
|
1819
|
-
],
|
|
1820
|
-
chainId: normalizedChainId
|
|
1821
|
-
};
|
|
1822
|
-
} catch (error) {
|
|
1823
|
-
if (error instanceof chunkWYBYBPX5_js.APIError) {
|
|
1824
|
-
throw error;
|
|
1825
|
-
}
|
|
1826
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1827
|
-
`Failed to prepare withdraw order transaction: ${error instanceof Error ? error.message : String(error)}`,
|
|
1828
|
-
{
|
|
1829
|
-
endpoint: "prepareWithdrawOrderTxData",
|
|
1830
|
-
cause: error
|
|
1831
|
-
}
|
|
1832
|
-
);
|
|
1833
|
-
}
|
|
1834
|
-
};
|
|
1835
|
-
var WithdrawAuthMethod = {
|
|
1836
|
-
APPROVAL: "approval",
|
|
1837
|
-
ALREADY_APPROVED: "already_approved"
|
|
1838
|
-
};
|
|
1839
|
-
function isWithdrawApprovalAuth(result) {
|
|
1840
|
-
return result.method === WithdrawAuthMethod.APPROVAL;
|
|
1841
|
-
}
|
|
1842
|
-
function isWithdrawAlreadyApprovedAuth(result) {
|
|
1843
|
-
return result.method === WithdrawAuthMethod.ALREADY_APPROVED;
|
|
1844
|
-
}
|
|
1845
|
-
async function prepareWithdrawal(params) {
|
|
1846
|
-
const { vaultName, wantAsset, withdrawAmount, userAddress, chainId } = params;
|
|
1847
|
-
try {
|
|
1848
|
-
return await prepareWithdrawOrderTxData({
|
|
1849
|
-
vaultName,
|
|
1850
|
-
wantAsset,
|
|
1851
|
-
userAddress,
|
|
1852
|
-
chainId,
|
|
1853
|
-
amountOffer: withdrawAmount
|
|
1854
|
-
});
|
|
1855
|
-
} catch (error) {
|
|
1856
|
-
if (error instanceof chunkWYBYBPX5_js.APIError) {
|
|
1857
|
-
throw error;
|
|
1858
|
-
}
|
|
1859
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1860
|
-
`Failed to prepare withdrawal: ${error instanceof Error ? error.message : String(error)}`,
|
|
1861
|
-
{
|
|
1862
|
-
endpoint: "prepareWithdrawal",
|
|
1863
|
-
cause: error
|
|
1864
|
-
}
|
|
1865
|
-
);
|
|
1866
|
-
}
|
|
1867
|
-
}
|
|
1868
|
-
async function prepareWithdrawalAuthorization(params) {
|
|
1869
|
-
const {
|
|
1870
|
-
vaultName,
|
|
1871
|
-
wantAsset,
|
|
1872
|
-
withdrawAmount,
|
|
1873
|
-
userAddress,
|
|
1874
|
-
chainId,
|
|
1875
|
-
forceMethod
|
|
1876
|
-
} = params;
|
|
1877
|
-
try {
|
|
1878
|
-
const normalizedChainId = chunkWYBYBPX5_js.toChainId(chainId);
|
|
1879
|
-
const vault = await chunkZKDXRGI5_js.resolveVault({
|
|
1880
|
-
vaultName,
|
|
1881
|
-
assetAddress: wantAsset,
|
|
1882
|
-
chainId: normalizedChainId,
|
|
1883
|
-
callerEndpoint: "prepareWithdrawalAuthorization"
|
|
1884
|
-
});
|
|
1885
|
-
if (forceMethod === "approval") {
|
|
1886
|
-
const txData2 = await prepareApproveWithdrawOrderTxData({
|
|
1887
|
-
vaultName,
|
|
1888
|
-
wantAssetAddress: wantAsset,
|
|
1889
|
-
withdrawAmount,
|
|
1890
|
-
chainId: normalizedChainId
|
|
1891
|
-
});
|
|
1892
|
-
return {
|
|
1893
|
-
method: WithdrawAuthMethod.APPROVAL,
|
|
1894
|
-
txData: txData2
|
|
1895
|
-
};
|
|
1896
|
-
}
|
|
1897
|
-
if (forceMethod !== "allowance_check") {
|
|
1898
|
-
const smartWallet = await isSmartContractWallet(
|
|
1899
|
-
userAddress,
|
|
1900
|
-
normalizedChainId
|
|
1901
|
-
);
|
|
1902
|
-
if (smartWallet) {
|
|
1903
|
-
const txData2 = await prepareApproveWithdrawOrderTxData({
|
|
1904
|
-
vaultName,
|
|
1905
|
-
wantAssetAddress: wantAsset,
|
|
1906
|
-
withdrawAmount,
|
|
1907
|
-
chainId: normalizedChainId
|
|
1908
|
-
});
|
|
1909
|
-
return {
|
|
1910
|
-
method: WithdrawAuthMethod.APPROVAL,
|
|
1911
|
-
txData: txData2
|
|
1912
|
-
};
|
|
1913
|
-
}
|
|
1914
|
-
}
|
|
1915
|
-
const approvalInfo = await isWithdrawalSpendApproved({
|
|
1916
|
-
vaultName: vault.name,
|
|
1917
|
-
chainId: normalizedChainId,
|
|
1918
|
-
wantAssetAddress: wantAsset,
|
|
1919
|
-
recipientAddress: userAddress
|
|
1920
|
-
});
|
|
1921
|
-
if (approvalInfo.error) {
|
|
1922
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1923
|
-
`Failed to check withdrawal approval: ${approvalInfo.error}`,
|
|
1924
|
-
{ endpoint: "prepareWithdrawalAuthorization" }
|
|
1925
|
-
);
|
|
1926
|
-
}
|
|
1927
|
-
const decimals = typeof approvalInfo.decimals === "string" ? Number(approvalInfo.decimals) : approvalInfo.decimals;
|
|
1928
|
-
const withdrawAmountBigInt = viem.parseUnits(withdrawAmount, decimals);
|
|
1929
|
-
const currentAllowanceBigInt = BigInt(approvalInfo.allowanceAsBigInt);
|
|
1930
|
-
if (approvalInfo.isApproved && currentAllowanceBigInt >= withdrawAmountBigInt) {
|
|
1931
|
-
return {
|
|
1932
|
-
method: WithdrawAuthMethod.ALREADY_APPROVED,
|
|
1933
|
-
allowance: approvalInfo.allowance,
|
|
1934
|
-
allowanceAsBigInt: approvalInfo.allowanceAsBigInt
|
|
1935
|
-
};
|
|
1936
|
-
}
|
|
1937
|
-
const txData = await prepareApproveWithdrawOrderTxData({
|
|
1938
|
-
vaultName,
|
|
1939
|
-
wantAssetAddress: wantAsset,
|
|
1940
|
-
withdrawAmount,
|
|
1941
|
-
chainId: normalizedChainId,
|
|
1942
|
-
shareDecimals: decimals
|
|
1943
|
-
});
|
|
1944
|
-
return {
|
|
1945
|
-
method: WithdrawAuthMethod.APPROVAL,
|
|
1946
|
-
txData
|
|
1947
|
-
};
|
|
1948
|
-
} catch (error) {
|
|
1949
|
-
if (error instanceof chunkWYBYBPX5_js.APIError) {
|
|
1950
|
-
throw error;
|
|
1951
|
-
}
|
|
1952
|
-
throw new chunkWYBYBPX5_js.APIError(
|
|
1953
|
-
`Failed to prepare withdrawal authorization: ${error instanceof Error ? error.message : String(error)}`,
|
|
1954
|
-
{
|
|
1955
|
-
endpoint: "prepareWithdrawalAuthorization",
|
|
1956
|
-
cause: error
|
|
1957
|
-
}
|
|
1958
|
-
);
|
|
1959
|
-
}
|
|
1960
|
-
}
|
|
1961
|
-
|
|
1962
|
-
exports.DepositAuthMethod = DepositAuthMethod;
|
|
1963
|
-
exports.DepositType = DepositType;
|
|
1964
|
-
exports.PERMIT_TYPES = PERMIT_TYPES;
|
|
1965
|
-
exports.WithdrawAuthMethod = WithdrawAuthMethod;
|
|
1966
|
-
exports.isAlreadyApprovedAuth = isAlreadyApprovedAuth;
|
|
1967
|
-
exports.isApprovalAuth = isApprovalAuth;
|
|
1968
|
-
exports.isDepositSpendApproved = isDepositSpendApproved;
|
|
1969
|
-
exports.isKytDeposit = isKytDeposit;
|
|
1970
|
-
exports.isPermitAuth = isPermitAuth;
|
|
1971
|
-
exports.isStandardDeposit = isStandardDeposit;
|
|
1972
|
-
exports.isWithdrawAlreadyApprovedAuth = isWithdrawAlreadyApprovedAuth;
|
|
1973
|
-
exports.isWithdrawApprovalAuth = isWithdrawApprovalAuth;
|
|
1974
|
-
exports.isWithdrawalSpendApproved = isWithdrawalSpendApproved;
|
|
1975
|
-
exports.parsePermitSignature = parsePermitSignature;
|
|
1976
|
-
exports.prepareApproveDepositTokenTxData = prepareApproveDepositTokenTxData;
|
|
1977
|
-
exports.prepareApproveWithdrawOrderTxData = prepareApproveWithdrawOrderTxData;
|
|
1978
|
-
exports.prepareCancelWithdrawOrderTxData = prepareCancelWithdrawOrderTxData;
|
|
1979
|
-
exports.prepareDeposit = prepareDeposit;
|
|
1980
|
-
exports.prepareDepositAuthorization = prepareDepositAuthorization;
|
|
1981
|
-
exports.prepareDepositPermitSignature = prepareDepositPermitSignature;
|
|
1982
|
-
exports.prepareDepositTxData = prepareDepositTxData;
|
|
1983
|
-
exports.prepareDepositWithPermitTxData = prepareDepositWithPermitTxData;
|
|
1984
|
-
exports.prepareWithdrawOrderTxData = prepareWithdrawOrderTxData;
|
|
1985
|
-
exports.prepareWithdrawal = prepareWithdrawal;
|
|
1986
|
-
exports.prepareWithdrawalAuthorization = prepareWithdrawalAuthorization;
|
|
1987
|
-
exports.toEthSignTypedDataV4 = toEthSignTypedDataV4;
|
|
1988
|
-
//# sourceMappingURL=chunk-5OK753GA.js.map
|
|
1989
|
-
//# sourceMappingURL=chunk-5OK753GA.js.map
|