viem 2.55.5 → 2.55.8
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/CHANGELOG.md +32 -0
- package/_cjs/errors/version.js +1 -1
- package/_cjs/tempo/Abis.js +1809 -1
- package/_cjs/tempo/Abis.js.map +1 -1
- package/_cjs/tempo/Decorator.js +25 -2
- package/_cjs/tempo/Decorator.js.map +1 -1
- package/_cjs/tempo/actions/earn.js +1368 -0
- package/_cjs/tempo/actions/earn.js.map +1 -0
- package/_cjs/tempo/actions/index.js +2 -1
- package/_cjs/tempo/actions/index.js.map +1 -1
- package/_cjs/tempo/actions/zone.js +47 -61
- package/_cjs/tempo/actions/zone.js.map +1 -1
- package/_cjs/tempo/chainConfig.js +3 -1
- package/_cjs/tempo/chainConfig.js.map +1 -1
- package/_cjs/tempo/errors.js +28 -4
- package/_cjs/tempo/errors.js.map +1 -1
- package/_cjs/tempo/index.js +2 -1
- package/_cjs/tempo/index.js.map +1 -1
- package/_cjs/tempo/internal/WithdrawalSenderTag.js +9 -0
- package/_cjs/tempo/internal/WithdrawalSenderTag.js.map +1 -0
- package/_cjs/tempo/zones/Abis.js +46 -0
- package/_cjs/tempo/zones/Abis.js.map +1 -1
- package/_cjs/tempo/zones/Addresses.js +17 -0
- package/_cjs/tempo/zones/Addresses.js.map +1 -0
- package/_cjs/tempo/zones/index.js +2 -2
- package/_cjs/tempo/zones/index.js.map +1 -1
- package/_cjs/tempo/zones/zone.js +30 -16
- package/_cjs/tempo/zones/zone.js.map +1 -1
- package/_cjs/utils/blob/fromBlobs.js +5 -2
- package/_cjs/utils/blob/fromBlobs.js.map +1 -1
- package/_cjs/utils/encoding/fromBytes.js +2 -2
- package/_cjs/utils/encoding/fromBytes.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/tempo/Abis.js +1810 -0
- package/_esm/tempo/Abis.js.map +1 -1
- package/_esm/tempo/Decorator.js +25 -2
- package/_esm/tempo/Decorator.js.map +1 -1
- package/_esm/tempo/actions/earn.js +2100 -0
- package/_esm/tempo/actions/earn.js.map +1 -0
- package/_esm/tempo/actions/index.js +1 -0
- package/_esm/tempo/actions/index.js.map +1 -1
- package/_esm/tempo/actions/zone.js +104 -119
- package/_esm/tempo/actions/zone.js.map +1 -1
- package/_esm/tempo/chainConfig.js +4 -1
- package/_esm/tempo/chainConfig.js.map +1 -1
- package/_esm/tempo/errors.js +25 -2
- package/_esm/tempo/errors.js.map +1 -1
- package/_esm/tempo/index.js +1 -1
- package/_esm/tempo/index.js.map +1 -1
- package/_esm/tempo/internal/WithdrawalSenderTag.js +7 -0
- package/_esm/tempo/internal/WithdrawalSenderTag.js.map +1 -0
- package/_esm/tempo/zones/Abis.js +46 -0
- package/_esm/tempo/zones/Abis.js.map +1 -1
- package/_esm/tempo/zones/Addresses.js +14 -0
- package/_esm/tempo/zones/Addresses.js.map +1 -0
- package/_esm/tempo/zones/index.js +2 -1
- package/_esm/tempo/zones/index.js.map +1 -1
- package/_esm/tempo/zones/zone.js +29 -15
- package/_esm/tempo/zones/zone.js.map +1 -1
- package/_esm/utils/blob/fromBlobs.js +6 -2
- package/_esm/utils/blob/fromBlobs.js.map +1 -1
- package/_esm/utils/encoding/fromBytes.js +2 -2
- package/_esm/utils/encoding/fromBytes.js.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/tempo/Abis.d.ts +2880 -0
- package/_types/tempo/Abis.d.ts.map +1 -1
- package/_types/tempo/Decorator.d.ts +499 -41
- package/_types/tempo/Decorator.d.ts.map +1 -1
- package/_types/tempo/actions/earn.d.ts +7549 -0
- package/_types/tempo/actions/earn.d.ts.map +1 -0
- package/_types/tempo/actions/index.d.ts +1 -0
- package/_types/tempo/actions/index.d.ts.map +1 -1
- package/_types/tempo/actions/zone.d.ts +86 -109
- package/_types/tempo/actions/zone.d.ts.map +1 -1
- package/_types/tempo/chainConfig.d.ts.map +1 -1
- package/_types/tempo/errors.d.ts +33 -3
- package/_types/tempo/errors.d.ts.map +1 -1
- package/_types/tempo/index.d.ts +1 -1
- package/_types/tempo/index.d.ts.map +1 -1
- package/_types/tempo/internal/WithdrawalSenderTag.d.ts +11 -0
- package/_types/tempo/internal/WithdrawalSenderTag.d.ts.map +1 -0
- package/_types/tempo/zones/Abis.d.ts +87 -0
- package/_types/tempo/zones/Abis.d.ts.map +1 -1
- package/_types/tempo/zones/Addresses.d.ts +13 -0
- package/_types/tempo/zones/Addresses.d.ts.map +1 -0
- package/_types/tempo/zones/index.d.ts +2 -1
- package/_types/tempo/zones/index.d.ts.map +1 -1
- package/_types/tempo/zones/zone.d.ts +14 -33
- package/_types/tempo/zones/zone.d.ts.map +1 -1
- package/_types/utils/blob/fromBlobs.d.ts.map +1 -1
- package/errors/version.ts +1 -1
- package/package.json +2 -2
- package/tempo/Abis.ts +1822 -0
- package/tempo/Decorator.ts +572 -47
- package/tempo/actions/earn.ts +3319 -0
- package/tempo/actions/index.ts +1 -0
- package/tempo/actions/zone.ts +183 -230
- package/tempo/chainConfig.ts +7 -1
- package/tempo/errors.ts +54 -6
- package/tempo/index.ts +1 -0
- package/tempo/internal/WithdrawalSenderTag.ts +20 -0
- package/tempo/zones/Abis.ts +46 -0
- package/tempo/zones/Addresses.ts +15 -0
- package/tempo/zones/index.ts +1 -1
- package/tempo/zones/zone.ts +38 -17
- package/utils/blob/fromBlobs.ts +6 -2
- package/utils/encoding/fromBytes.ts +2 -2
|
@@ -0,0 +1,1368 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.alwaysAllowPolicyId = void 0;
|
|
4
|
+
exports.configureExitSafePolicy = configureExitSafePolicy;
|
|
5
|
+
exports.validateExitSafePolicy = validateExitSafePolicy;
|
|
6
|
+
exports.deposit = deposit;
|
|
7
|
+
exports.depositSync = depositSync;
|
|
8
|
+
exports.depositShares = depositShares;
|
|
9
|
+
exports.depositSharesSync = depositSharesSync;
|
|
10
|
+
exports.privateDeposit = privateDeposit;
|
|
11
|
+
exports.privateDepositSync = privateDepositSync;
|
|
12
|
+
exports.waitForPrivateDeposit = waitForPrivateDeposit;
|
|
13
|
+
exports.getFeeState = getFeeState;
|
|
14
|
+
exports.getPosition = getPosition;
|
|
15
|
+
exports.getRedeemQuote = getRedeemQuote;
|
|
16
|
+
exports.getVault = getVault;
|
|
17
|
+
exports.getWithdrawQuote = getWithdrawQuote;
|
|
18
|
+
exports.redeem = redeem;
|
|
19
|
+
exports.redeemSync = redeemSync;
|
|
20
|
+
exports.privateRedeem = privateRedeem;
|
|
21
|
+
exports.privateRedeemSync = privateRedeemSync;
|
|
22
|
+
exports.waitForPrivateRedeem = waitForPrivateRedeem;
|
|
23
|
+
exports.withdrawExact = withdrawExact;
|
|
24
|
+
exports.withdrawExactSync = withdrawExactSync;
|
|
25
|
+
const ox_1 = require("ox");
|
|
26
|
+
const tempo_1 = require("ox/tempo");
|
|
27
|
+
const parseAccount_js_1 = require("../../accounts/utils/parseAccount.js");
|
|
28
|
+
const estimateContractGas_js_1 = require("../../actions/public/estimateContractGas.js");
|
|
29
|
+
const getBlockNumber_js_1 = require("../../actions/public/getBlockNumber.js");
|
|
30
|
+
const getLogs_js_1 = require("../../actions/public/getLogs.js");
|
|
31
|
+
const multicall_js_1 = require("../../actions/public/multicall.js");
|
|
32
|
+
const readContract_js_1 = require("../../actions/public/readContract.js");
|
|
33
|
+
const simulateContract_js_1 = require("../../actions/public/simulateContract.js");
|
|
34
|
+
const internal_Token = require("../../actions/token/internal.js");
|
|
35
|
+
const sendTransaction_js_1 = require("../../actions/wallet/sendTransaction.js");
|
|
36
|
+
const sendTransactionSync_js_1 = require("../../actions/wallet/sendTransactionSync.js");
|
|
37
|
+
const writeContractSync_js_1 = require("../../actions/wallet/writeContractSync.js");
|
|
38
|
+
const account_js_1 = require("../../errors/account.js");
|
|
39
|
+
const encodeAbiParameters_js_1 = require("../../utils/abi/encodeAbiParameters.js");
|
|
40
|
+
const getAbiItem_js_1 = require("../../utils/abi/getAbiItem.js");
|
|
41
|
+
const parseEventLogs_js_1 = require("../../utils/abi/parseEventLogs.js");
|
|
42
|
+
const getAddress_js_1 = require("../../utils/address/getAddress.js");
|
|
43
|
+
const isAddressEqual_js_1 = require("../../utils/address/isAddressEqual.js");
|
|
44
|
+
const observe_js_1 = require("../../utils/observe.js");
|
|
45
|
+
const poll_js_1 = require("../../utils/poll.js");
|
|
46
|
+
const withResolvers_js_1 = require("../../utils/promise/withResolvers.js");
|
|
47
|
+
const stringify_js_1 = require("../../utils/stringify.js");
|
|
48
|
+
const Abis = require("../Abis.js");
|
|
49
|
+
const Addresses = require("../Addresses.js");
|
|
50
|
+
const errors_js_1 = require("../errors.js");
|
|
51
|
+
const utils_js_1 = require("../internal/utils.js");
|
|
52
|
+
const policyActions = require("./policy.js");
|
|
53
|
+
const tokenActions = require("./token.js");
|
|
54
|
+
const zoneActions = require("./zone.js");
|
|
55
|
+
exports.alwaysAllowPolicyId = 1n;
|
|
56
|
+
async function configureExitSafePolicy(client, parameters) {
|
|
57
|
+
const account_ = parameters.account ?? client.account;
|
|
58
|
+
if (!account_)
|
|
59
|
+
throw new account_js_1.AccountNotFoundError();
|
|
60
|
+
const account = (0, parseAccount_js_1.parseAccount)(account_);
|
|
61
|
+
const initialMembers = [
|
|
62
|
+
...new Set(parameters.initialMembers.map((member) => (0, getAddress_js_1.getAddress)(member))),
|
|
63
|
+
];
|
|
64
|
+
if (initialMembers.length === 0)
|
|
65
|
+
throw new Error('At least one initial policy member is required.');
|
|
66
|
+
const eligibility = await policyActions.createSync(client, {
|
|
67
|
+
account,
|
|
68
|
+
addresses: initialMembers,
|
|
69
|
+
chain: client.chain,
|
|
70
|
+
type: 'whitelist',
|
|
71
|
+
});
|
|
72
|
+
const compoundPolicy = await (0, writeContractSync_js_1.writeContractSync)(client, {
|
|
73
|
+
account,
|
|
74
|
+
abi: Abis.tip403Registry,
|
|
75
|
+
address: Addresses.tip403Registry,
|
|
76
|
+
args: [exports.alwaysAllowPolicyId, eligibility.policyId, eligibility.policyId],
|
|
77
|
+
chain: client.chain,
|
|
78
|
+
functionName: 'createCompoundPolicy',
|
|
79
|
+
throwOnReceiptRevert: true,
|
|
80
|
+
});
|
|
81
|
+
const [compoundEvent] = (0, parseEventLogs_js_1.parseEventLogs)({
|
|
82
|
+
abi: Abis.tip403Registry,
|
|
83
|
+
eventName: 'CompoundPolicyCreated',
|
|
84
|
+
logs: compoundPolicy.logs,
|
|
85
|
+
strict: true,
|
|
86
|
+
});
|
|
87
|
+
if (!compoundEvent)
|
|
88
|
+
throw new Error('`CompoundPolicyCreated` event not found.');
|
|
89
|
+
const tokenPolicy = await tokenActions.changeTransferPolicySync(client, {
|
|
90
|
+
account,
|
|
91
|
+
chain: client.chain,
|
|
92
|
+
policyId: compoundEvent.args.policyId,
|
|
93
|
+
token: parameters.shareToken,
|
|
94
|
+
});
|
|
95
|
+
const policyAdmin = (0, isAddressEqual_js_1.isAddressEqual)(parameters.accessAdministrator, account.address)
|
|
96
|
+
? undefined
|
|
97
|
+
: await policyActions.setAdminSync(client, {
|
|
98
|
+
account,
|
|
99
|
+
admin: parameters.accessAdministrator,
|
|
100
|
+
chain: client.chain,
|
|
101
|
+
policyId: eligibility.policyId,
|
|
102
|
+
});
|
|
103
|
+
return {
|
|
104
|
+
policy: {
|
|
105
|
+
transferPolicyId: compoundEvent.args.policyId,
|
|
106
|
+
senderPolicyId: exports.alwaysAllowPolicyId,
|
|
107
|
+
recipientPolicyId: eligibility.policyId,
|
|
108
|
+
mintRecipientPolicyId: eligibility.policyId,
|
|
109
|
+
},
|
|
110
|
+
receipts: {
|
|
111
|
+
eligibilityPolicy: eligibility.receipt,
|
|
112
|
+
compoundPolicy,
|
|
113
|
+
tokenPolicy: tokenPolicy.receipt,
|
|
114
|
+
policyAdmin: policyAdmin?.receipt,
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
async function validateExitSafePolicy(client, parameters) {
|
|
119
|
+
const { accessAdministrator, policy, requiredMembers, shareToken, ...rest } = parameters;
|
|
120
|
+
const [tokenPolicyId, compound, simplePolicy, memberResults] = await Promise.all([
|
|
121
|
+
(0, readContract_js_1.readContract)(client, {
|
|
122
|
+
...rest,
|
|
123
|
+
abi: Abis.tip20,
|
|
124
|
+
address: shareToken,
|
|
125
|
+
functionName: 'transferPolicyId',
|
|
126
|
+
}),
|
|
127
|
+
(0, readContract_js_1.readContract)(client, {
|
|
128
|
+
...rest,
|
|
129
|
+
abi: Abis.tip403Registry,
|
|
130
|
+
address: Addresses.tip403Registry,
|
|
131
|
+
args: [policy.transferPolicyId],
|
|
132
|
+
functionName: 'compoundPolicyData',
|
|
133
|
+
}),
|
|
134
|
+
(0, readContract_js_1.readContract)(client, {
|
|
135
|
+
...rest,
|
|
136
|
+
abi: Abis.tip403Registry,
|
|
137
|
+
address: Addresses.tip403Registry,
|
|
138
|
+
args: [policy.recipientPolicyId],
|
|
139
|
+
functionName: 'policyData',
|
|
140
|
+
}),
|
|
141
|
+
Promise.all(requiredMembers.map(async (member) => {
|
|
142
|
+
const [recipient, mintRecipient] = await Promise.all([
|
|
143
|
+
(0, readContract_js_1.readContract)(client, {
|
|
144
|
+
...rest,
|
|
145
|
+
abi: Abis.tip403Registry,
|
|
146
|
+
address: Addresses.tip403Registry,
|
|
147
|
+
args: [policy.transferPolicyId, member],
|
|
148
|
+
functionName: 'isAuthorizedRecipient',
|
|
149
|
+
}),
|
|
150
|
+
(0, readContract_js_1.readContract)(client, {
|
|
151
|
+
...rest,
|
|
152
|
+
abi: Abis.tip403Registry,
|
|
153
|
+
address: Addresses.tip403Registry,
|
|
154
|
+
args: [policy.transferPolicyId, member],
|
|
155
|
+
functionName: 'isAuthorizedMintRecipient',
|
|
156
|
+
}),
|
|
157
|
+
]);
|
|
158
|
+
return { member, mintRecipient, recipient };
|
|
159
|
+
})),
|
|
160
|
+
]);
|
|
161
|
+
if (tokenPolicyId !== policy.transferPolicyId)
|
|
162
|
+
throw new Error('Earn vault share token transfer policy mismatch.');
|
|
163
|
+
if (compound[0] !== policy.senderPolicyId ||
|
|
164
|
+
compound[1] !== policy.recipientPolicyId ||
|
|
165
|
+
compound[2] !== policy.mintRecipientPolicyId)
|
|
166
|
+
throw new Error('TIP-403 compound policy components mismatch.');
|
|
167
|
+
if (policy.senderPolicyId !== exports.alwaysAllowPolicyId)
|
|
168
|
+
throw new Error('TIP-403 sender policy is not always allow.');
|
|
169
|
+
if (policy.recipientPolicyId !== policy.mintRecipientPolicyId)
|
|
170
|
+
throw new Error('TIP-403 recipient and mint-recipient policies must match.');
|
|
171
|
+
if (simplePolicy[0] !== 0)
|
|
172
|
+
throw new Error('TIP-403 eligibility policy is not a whitelist.');
|
|
173
|
+
if (!(0, isAddressEqual_js_1.isAddressEqual)(simplePolicy[1], accessAdministrator))
|
|
174
|
+
throw new Error('TIP-403 access administrator mismatch.');
|
|
175
|
+
const unauthorized = memberResults.find((result) => !result.recipient || !result.mintRecipient);
|
|
176
|
+
if (unauthorized)
|
|
177
|
+
throw new Error(`Required TIP-403 member is unauthorized: ${unauthorized.member}`);
|
|
178
|
+
}
|
|
179
|
+
async function deposit(client, parameters) {
|
|
180
|
+
return deposit.inner(sendTransaction_js_1.sendTransaction, client, parameters);
|
|
181
|
+
}
|
|
182
|
+
(function (deposit) {
|
|
183
|
+
async function inner(action, client, parameters) {
|
|
184
|
+
const [args, assetToken] = await Promise.all([
|
|
185
|
+
toDepositArgs(client, parameters),
|
|
186
|
+
(0, readContract_js_1.readContract)(client, {
|
|
187
|
+
abi: Abis.vaultAdapter,
|
|
188
|
+
address: parameters.vault,
|
|
189
|
+
functionName: 'asset',
|
|
190
|
+
}),
|
|
191
|
+
]);
|
|
192
|
+
return (await action(client, {
|
|
193
|
+
...parameters,
|
|
194
|
+
calls: deposit.calls({ ...args, assetToken }),
|
|
195
|
+
}));
|
|
196
|
+
}
|
|
197
|
+
deposit.inner = inner;
|
|
198
|
+
function call(...parameters) {
|
|
199
|
+
const [, args] = (0, utils_js_1.resolveCallParameters)(parameters);
|
|
200
|
+
const { recipient, vault } = args;
|
|
201
|
+
const shareAmountMin = (() => {
|
|
202
|
+
if (args.shareAmountMin !== undefined)
|
|
203
|
+
return args.shareAmountMin;
|
|
204
|
+
return tempo_1.EarnShares.minimumOutput(args.shareAmount, args.slippageBps);
|
|
205
|
+
})();
|
|
206
|
+
return (0, utils_js_1.defineCall)({
|
|
207
|
+
address: vault,
|
|
208
|
+
abi: Abis.vaultAdapter,
|
|
209
|
+
functionName: 'deposit',
|
|
210
|
+
args: [
|
|
211
|
+
internal_Token.toBaseUnits(args.assetAmount, undefined),
|
|
212
|
+
recipient,
|
|
213
|
+
shareAmountMin,
|
|
214
|
+
],
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
deposit.call = call;
|
|
218
|
+
function calls(args) {
|
|
219
|
+
const { assetToken, vault } = args;
|
|
220
|
+
const assetAmount = internal_Token.toBaseUnits(args.assetAmount, undefined);
|
|
221
|
+
return [
|
|
222
|
+
(0, utils_js_1.defineCall)({
|
|
223
|
+
address: tempo_1.TokenId.toAddress(assetToken),
|
|
224
|
+
abi: Abis.tip20,
|
|
225
|
+
functionName: 'approve',
|
|
226
|
+
args: [vault, assetAmount],
|
|
227
|
+
}),
|
|
228
|
+
deposit.call({ ...args, assetAmount }),
|
|
229
|
+
];
|
|
230
|
+
}
|
|
231
|
+
deposit.calls = calls;
|
|
232
|
+
function extractEvent(logs, parameters) {
|
|
233
|
+
const { vault } = parameters;
|
|
234
|
+
const [log] = (0, parseEventLogs_js_1.parseEventLogs)({
|
|
235
|
+
abi: Abis.vaultAdapter,
|
|
236
|
+
eventName: 'Deposited',
|
|
237
|
+
logs: logs.filter((log) => (0, isAddressEqual_js_1.isAddressEqual)(log.address, vault)),
|
|
238
|
+
});
|
|
239
|
+
if (!log)
|
|
240
|
+
throw new Error('`Deposited` event not found.');
|
|
241
|
+
return log;
|
|
242
|
+
}
|
|
243
|
+
deposit.extractEvent = extractEvent;
|
|
244
|
+
async function estimateGas(client, parameters) {
|
|
245
|
+
return (0, estimateContractGas_js_1.estimateContractGas)(client, {
|
|
246
|
+
...(0, utils_js_1.pickWriteParameters)(parameters),
|
|
247
|
+
...deposit.call(await toDepositArgs(client, parameters)),
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
deposit.estimateGas = estimateGas;
|
|
251
|
+
async function simulate(client, parameters) {
|
|
252
|
+
return (0, simulateContract_js_1.simulateContract)(client, {
|
|
253
|
+
...(0, utils_js_1.pickWriteParameters)(parameters),
|
|
254
|
+
...deposit.call(await toDepositArgs(client, parameters)),
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
deposit.simulate = simulate;
|
|
258
|
+
})(deposit || (exports.deposit = deposit = {}));
|
|
259
|
+
async function depositSync(client, parameters) {
|
|
260
|
+
const { throwOnReceiptRevert = true, vault } = parameters;
|
|
261
|
+
const receipt = await deposit.inner(sendTransactionSync_js_1.sendTransactionSync, client, {
|
|
262
|
+
...parameters,
|
|
263
|
+
throwOnReceiptRevert,
|
|
264
|
+
});
|
|
265
|
+
const { args } = deposit.extractEvent(receipt.logs, { vault });
|
|
266
|
+
return {
|
|
267
|
+
assetAmount: args.assets,
|
|
268
|
+
caller: args.caller,
|
|
269
|
+
receipt,
|
|
270
|
+
recipient: args.receiver,
|
|
271
|
+
shareAmount: args.shares,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
async function depositShares(client, parameters) {
|
|
275
|
+
return depositShares.inner(sendTransaction_js_1.sendTransaction, client, parameters);
|
|
276
|
+
}
|
|
277
|
+
(function (depositShares) {
|
|
278
|
+
async function inner(action, client, parameters) {
|
|
279
|
+
const engine = await (0, readContract_js_1.readContract)(client, {
|
|
280
|
+
abi: Abis.vaultAdapter,
|
|
281
|
+
address: parameters.vault,
|
|
282
|
+
functionName: 'engine',
|
|
283
|
+
});
|
|
284
|
+
return (await action(client, {
|
|
285
|
+
...parameters,
|
|
286
|
+
calls: depositShares.calls({
|
|
287
|
+
...toDepositSharesArgs(client, parameters),
|
|
288
|
+
engine,
|
|
289
|
+
venueShareToken: parameters.venueShareToken,
|
|
290
|
+
}),
|
|
291
|
+
}));
|
|
292
|
+
}
|
|
293
|
+
depositShares.inner = inner;
|
|
294
|
+
function call(...parameters) {
|
|
295
|
+
const [, args] = (0, utils_js_1.resolveCallParameters)(parameters);
|
|
296
|
+
const { recipient, vault, venueShareAmount } = args;
|
|
297
|
+
const earnShareAmountMin = (() => {
|
|
298
|
+
if (args.earnShareAmountMin !== undefined)
|
|
299
|
+
return args.earnShareAmountMin;
|
|
300
|
+
return tempo_1.EarnShares.minimumOutput(args.earnShareAmount, args.slippageBps);
|
|
301
|
+
})();
|
|
302
|
+
return (0, utils_js_1.defineCall)({
|
|
303
|
+
address: vault,
|
|
304
|
+
abi: Abis.vaultAdapter,
|
|
305
|
+
functionName: 'depositShares',
|
|
306
|
+
args: [venueShareAmount, recipient, earnShareAmountMin],
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
depositShares.call = call;
|
|
310
|
+
function calls(args) {
|
|
311
|
+
const { engine, venueShareAmount, venueShareToken } = args;
|
|
312
|
+
return [
|
|
313
|
+
(0, utils_js_1.defineCall)({
|
|
314
|
+
address: venueShareToken,
|
|
315
|
+
abi: Abis.tip20,
|
|
316
|
+
functionName: 'approve',
|
|
317
|
+
args: [engine, venueShareAmount],
|
|
318
|
+
}),
|
|
319
|
+
depositShares.call(args),
|
|
320
|
+
];
|
|
321
|
+
}
|
|
322
|
+
depositShares.calls = calls;
|
|
323
|
+
function extractEvent(logs, parameters) {
|
|
324
|
+
const { vault } = parameters;
|
|
325
|
+
const [log] = (0, parseEventLogs_js_1.parseEventLogs)({
|
|
326
|
+
abi: Abis.vaultAdapter,
|
|
327
|
+
eventName: 'VenueSharesDeposited',
|
|
328
|
+
logs: logs.filter((log) => (0, isAddressEqual_js_1.isAddressEqual)(log.address, vault)),
|
|
329
|
+
});
|
|
330
|
+
if (!log)
|
|
331
|
+
throw new Error('`VenueSharesDeposited` event not found.');
|
|
332
|
+
return log;
|
|
333
|
+
}
|
|
334
|
+
depositShares.extractEvent = extractEvent;
|
|
335
|
+
async function estimateGas(client, parameters) {
|
|
336
|
+
return (0, estimateContractGas_js_1.estimateContractGas)(client, {
|
|
337
|
+
...(0, utils_js_1.pickWriteParameters)(parameters),
|
|
338
|
+
...depositShares.call(toDepositSharesArgs(client, parameters)),
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
depositShares.estimateGas = estimateGas;
|
|
342
|
+
async function simulate(client, parameters) {
|
|
343
|
+
return (0, simulateContract_js_1.simulateContract)(client, {
|
|
344
|
+
...(0, utils_js_1.pickWriteParameters)(parameters),
|
|
345
|
+
...depositShares.call(toDepositSharesArgs(client, parameters)),
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
depositShares.simulate = simulate;
|
|
349
|
+
})(depositShares || (exports.depositShares = depositShares = {}));
|
|
350
|
+
async function depositSharesSync(client, parameters) {
|
|
351
|
+
const { throwOnReceiptRevert = true, vault } = parameters;
|
|
352
|
+
const receipt = await depositShares.inner(sendTransactionSync_js_1.sendTransactionSync, client, {
|
|
353
|
+
...parameters,
|
|
354
|
+
throwOnReceiptRevert,
|
|
355
|
+
});
|
|
356
|
+
const { args } = depositShares.extractEvent(receipt.logs, { vault });
|
|
357
|
+
return {
|
|
358
|
+
caller: args.caller,
|
|
359
|
+
earnShareAmount: args.earnShares,
|
|
360
|
+
receipt,
|
|
361
|
+
receivedVenueShareAmount: args.receivedVenueShares,
|
|
362
|
+
recipient: args.receiver,
|
|
363
|
+
venueShareAmount: args.requestedVenueShares,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
async function privateDeposit(client, parameters) {
|
|
367
|
+
await assertPreparedZoneRequestChain(client, parameters);
|
|
368
|
+
return zoneActions.requestWithdrawal(client, parameters);
|
|
369
|
+
}
|
|
370
|
+
(function (privateDeposit) {
|
|
371
|
+
async function prepare(client, parameters) {
|
|
372
|
+
const chainId = client.chain?.id;
|
|
373
|
+
if (!chainId)
|
|
374
|
+
throw new Error('`chain` is required.');
|
|
375
|
+
const { actionId = ox_1.Hex.random(32), assetAmount, callbackGas = zoneGatewayCallbackGas, fallbackRecipient = parameters.recoveryRecipient, gateway, recipient, recoveryRecipient, returnMemo, withdrawalMemo, } = parameters;
|
|
376
|
+
const readParameters = pickReadParameters(parameters);
|
|
377
|
+
const [fromBlock, config] = await Promise.all([
|
|
378
|
+
(0, getBlockNumber_js_1.getBlockNumber)(client, { cacheTime: 0 }),
|
|
379
|
+
getZoneGatewayConfig(client, { ...readParameters, gateway }),
|
|
380
|
+
]);
|
|
381
|
+
const assetToken = parameters.assetToken ?? config.vaultAsset;
|
|
382
|
+
const { encrypted, keyIndex } = await zoneActions.encryptedDeposit.prepareRecipient(client, {
|
|
383
|
+
...readParameters,
|
|
384
|
+
memo: returnMemo,
|
|
385
|
+
portalAddress: config.zonePortal,
|
|
386
|
+
recipient,
|
|
387
|
+
zoneId: config.zoneId,
|
|
388
|
+
});
|
|
389
|
+
const shareAmountMin = resolveMinimumShareAmount(parameters);
|
|
390
|
+
const direct = (0, isAddressEqual_js_1.isAddressEqual)(assetToken, config.vaultAsset);
|
|
391
|
+
const data = (0, encodeAbiParameters_js_1.encodeAbiParameters)(Abis.zoneGatewayCallbackData, [
|
|
392
|
+
{
|
|
393
|
+
flow: 0,
|
|
394
|
+
outputToken: config.shareToken,
|
|
395
|
+
keyIndex,
|
|
396
|
+
encrypted,
|
|
397
|
+
minVaultAssets: direct
|
|
398
|
+
? assetAmount
|
|
399
|
+
: (parameters.vaultAssetAmountMin ?? 0n),
|
|
400
|
+
minVaultShares: shareAmountMin,
|
|
401
|
+
minOutputAmount: 0n,
|
|
402
|
+
actionId,
|
|
403
|
+
refundRecipient: recoveryRecipient,
|
|
404
|
+
},
|
|
405
|
+
]);
|
|
406
|
+
return {
|
|
407
|
+
actionId,
|
|
408
|
+
amount: assetAmount,
|
|
409
|
+
callbackGas,
|
|
410
|
+
chainId,
|
|
411
|
+
data,
|
|
412
|
+
fallbackRecipient,
|
|
413
|
+
fromBlock,
|
|
414
|
+
memo: withdrawalMemo,
|
|
415
|
+
to: gateway,
|
|
416
|
+
token: assetToken,
|
|
417
|
+
zoneId: config.zoneId,
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
privateDeposit.prepare = prepare;
|
|
421
|
+
function calls(args) {
|
|
422
|
+
return zoneActions.requestWithdrawal.calls(args);
|
|
423
|
+
}
|
|
424
|
+
privateDeposit.calls = calls;
|
|
425
|
+
})(privateDeposit || (exports.privateDeposit = privateDeposit = {}));
|
|
426
|
+
async function privateDepositSync(client, parameters) {
|
|
427
|
+
await assertPreparedZoneRequestChain(client, parameters);
|
|
428
|
+
return zoneActions.requestWithdrawalSync(client, parameters);
|
|
429
|
+
}
|
|
430
|
+
async function waitForPrivateDeposit(client, parameters) {
|
|
431
|
+
const { actionId, fromBlock, gateway, pollingInterval = client.pollingInterval, timeout = 60_000, } = parameters;
|
|
432
|
+
const event = (0, getAbiItem_js_1.getAbiItem)({
|
|
433
|
+
abi: Abis.zoneGateway,
|
|
434
|
+
name: 'EarnDeposit',
|
|
435
|
+
});
|
|
436
|
+
const observerId = (0, stringify_js_1.stringify)([
|
|
437
|
+
'waitForPrivateDeposit',
|
|
438
|
+
client.uid,
|
|
439
|
+
gateway,
|
|
440
|
+
actionId,
|
|
441
|
+
fromBlock,
|
|
442
|
+
]);
|
|
443
|
+
const { promise, reject, resolve } = (0, withResolvers_js_1.withResolvers)();
|
|
444
|
+
let timer;
|
|
445
|
+
let unobserve;
|
|
446
|
+
const cleanup = () => {
|
|
447
|
+
clearTimeout(timer);
|
|
448
|
+
unobserve();
|
|
449
|
+
};
|
|
450
|
+
const resolve_ = (result) => {
|
|
451
|
+
cleanup();
|
|
452
|
+
resolve(result);
|
|
453
|
+
};
|
|
454
|
+
const reject_ = (error) => {
|
|
455
|
+
cleanup();
|
|
456
|
+
reject(error);
|
|
457
|
+
};
|
|
458
|
+
unobserve = (0, observe_js_1.observe)(observerId, { reject: reject_, resolve: resolve_ }, (emit) => {
|
|
459
|
+
const unpoll = (0, poll_js_1.poll)(async () => {
|
|
460
|
+
try {
|
|
461
|
+
const [log] = await (0, getLogs_js_1.getLogs)(client, {
|
|
462
|
+
address: gateway,
|
|
463
|
+
args: { actionId },
|
|
464
|
+
event,
|
|
465
|
+
fromBlock,
|
|
466
|
+
strict: true,
|
|
467
|
+
toBlock: 'latest',
|
|
468
|
+
});
|
|
469
|
+
if (!log)
|
|
470
|
+
return;
|
|
471
|
+
unpoll();
|
|
472
|
+
emit.resolve({
|
|
473
|
+
actionId: log.args.actionId,
|
|
474
|
+
inputAmount: log.args.inputAmount,
|
|
475
|
+
inputToken: log.args.inputToken,
|
|
476
|
+
shares: log.args.shares,
|
|
477
|
+
tempoBlockNumber: log.blockNumber,
|
|
478
|
+
vaultAssets: log.args.vaultAssets,
|
|
479
|
+
zoneDepositHash: log.args.zoneDepositHash,
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
catch (error) {
|
|
483
|
+
unpoll();
|
|
484
|
+
emit.reject(error);
|
|
485
|
+
}
|
|
486
|
+
}, { emitOnBegin: true, interval: pollingInterval });
|
|
487
|
+
return unpoll;
|
|
488
|
+
});
|
|
489
|
+
timer = timeout
|
|
490
|
+
? setTimeout(() => {
|
|
491
|
+
reject_(new errors_js_1.WaitForPrivateDepositTimeoutError({ actionId, gateway }));
|
|
492
|
+
}, timeout)
|
|
493
|
+
: undefined;
|
|
494
|
+
return await promise;
|
|
495
|
+
}
|
|
496
|
+
async function getFeeState(client, parameters) {
|
|
497
|
+
const { recipient, vault, ...rest } = parameters;
|
|
498
|
+
const contracts = [
|
|
499
|
+
(0, utils_js_1.defineCall)({
|
|
500
|
+
address: vault,
|
|
501
|
+
abi: Abis.vaultAdapter,
|
|
502
|
+
functionName: 'currentFeeConfigId',
|
|
503
|
+
}),
|
|
504
|
+
(0, utils_js_1.defineCall)({
|
|
505
|
+
address: vault,
|
|
506
|
+
abi: Abis.vaultAdapter,
|
|
507
|
+
functionName: 'feesActive',
|
|
508
|
+
}),
|
|
509
|
+
(0, utils_js_1.defineCall)({
|
|
510
|
+
address: vault,
|
|
511
|
+
abi: Abis.vaultAdapter,
|
|
512
|
+
functionName: 'highWaterMark',
|
|
513
|
+
}),
|
|
514
|
+
(0, utils_js_1.defineCall)({
|
|
515
|
+
address: vault,
|
|
516
|
+
abi: Abis.vaultAdapter,
|
|
517
|
+
functionName: 'previewAccruedFees',
|
|
518
|
+
}),
|
|
519
|
+
(0, utils_js_1.defineCall)({
|
|
520
|
+
address: vault,
|
|
521
|
+
abi: Abis.vaultAdapter,
|
|
522
|
+
functionName: 'targetBase',
|
|
523
|
+
}),
|
|
524
|
+
];
|
|
525
|
+
const feeConfig = async (configId) => toFeeConfig(await (0, readContract_js_1.readContract)(client, {
|
|
526
|
+
...rest,
|
|
527
|
+
abi: Abis.vaultAdapter,
|
|
528
|
+
address: vault,
|
|
529
|
+
functionName: 'feeConfig',
|
|
530
|
+
args: [configId],
|
|
531
|
+
}));
|
|
532
|
+
if (recipient !== undefined) {
|
|
533
|
+
const [configId, feesActive, highWaterMark, preview, targetBase, shares] = await (0, multicall_js_1.multicall)(client, {
|
|
534
|
+
...rest,
|
|
535
|
+
allowFailure: false,
|
|
536
|
+
contracts: [
|
|
537
|
+
...contracts,
|
|
538
|
+
(0, utils_js_1.defineCall)({
|
|
539
|
+
address: vault,
|
|
540
|
+
abi: Abis.vaultAdapter,
|
|
541
|
+
functionName: 'claimableFeeShares',
|
|
542
|
+
args: [recipient],
|
|
543
|
+
}),
|
|
544
|
+
],
|
|
545
|
+
deployless: true,
|
|
546
|
+
});
|
|
547
|
+
return {
|
|
548
|
+
claimableShares: shares,
|
|
549
|
+
config: await feeConfig(configId),
|
|
550
|
+
configId,
|
|
551
|
+
feesActive,
|
|
552
|
+
highWaterMark,
|
|
553
|
+
preview: toFeePreview(preview),
|
|
554
|
+
targetBase,
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
const [configId, feesActive, highWaterMark, preview, targetBase] = await (0, multicall_js_1.multicall)(client, {
|
|
558
|
+
...rest,
|
|
559
|
+
allowFailure: false,
|
|
560
|
+
contracts,
|
|
561
|
+
deployless: true,
|
|
562
|
+
});
|
|
563
|
+
return {
|
|
564
|
+
config: await feeConfig(configId),
|
|
565
|
+
configId,
|
|
566
|
+
feesActive,
|
|
567
|
+
highWaterMark,
|
|
568
|
+
preview: toFeePreview(preview),
|
|
569
|
+
targetBase,
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
async function getPosition(client, parameters) {
|
|
573
|
+
const { account: account_ = client.account, vault, ...rest } = parameters;
|
|
574
|
+
if (!account_)
|
|
575
|
+
throw new account_js_1.AccountNotFoundError();
|
|
576
|
+
const account = (0, parseAccount_js_1.parseAccount)(account_).address;
|
|
577
|
+
const [assetToken, shareToken] = await (0, multicall_js_1.multicall)(client, {
|
|
578
|
+
...rest,
|
|
579
|
+
allowFailure: false,
|
|
580
|
+
contracts: [
|
|
581
|
+
(0, utils_js_1.defineCall)({
|
|
582
|
+
address: vault,
|
|
583
|
+
abi: Abis.vaultAdapter,
|
|
584
|
+
functionName: 'asset',
|
|
585
|
+
}),
|
|
586
|
+
(0, utils_js_1.defineCall)({
|
|
587
|
+
address: vault,
|
|
588
|
+
abi: Abis.vaultAdapter,
|
|
589
|
+
functionName: 'shareToken',
|
|
590
|
+
}),
|
|
591
|
+
],
|
|
592
|
+
deployless: true,
|
|
593
|
+
});
|
|
594
|
+
const [assetAllowance, assetBalance, shareAllowance, shareBalance] = await (0, multicall_js_1.multicall)(client, {
|
|
595
|
+
...rest,
|
|
596
|
+
allowFailure: false,
|
|
597
|
+
contracts: [
|
|
598
|
+
(0, utils_js_1.defineCall)({
|
|
599
|
+
address: assetToken,
|
|
600
|
+
abi: Abis.tip20,
|
|
601
|
+
functionName: 'allowance',
|
|
602
|
+
args: [account, vault],
|
|
603
|
+
}),
|
|
604
|
+
(0, utils_js_1.defineCall)({
|
|
605
|
+
address: assetToken,
|
|
606
|
+
abi: Abis.tip20,
|
|
607
|
+
functionName: 'balanceOf',
|
|
608
|
+
args: [account],
|
|
609
|
+
}),
|
|
610
|
+
(0, utils_js_1.defineCall)({
|
|
611
|
+
address: shareToken,
|
|
612
|
+
abi: Abis.tip20,
|
|
613
|
+
functionName: 'allowance',
|
|
614
|
+
args: [account, vault],
|
|
615
|
+
}),
|
|
616
|
+
(0, utils_js_1.defineCall)({
|
|
617
|
+
address: shareToken,
|
|
618
|
+
abi: Abis.tip20,
|
|
619
|
+
functionName: 'balanceOf',
|
|
620
|
+
args: [account],
|
|
621
|
+
}),
|
|
622
|
+
],
|
|
623
|
+
deployless: true,
|
|
624
|
+
});
|
|
625
|
+
const value = await (0, readContract_js_1.readContract)(client, {
|
|
626
|
+
...rest,
|
|
627
|
+
abi: Abis.vaultAdapter,
|
|
628
|
+
address: vault,
|
|
629
|
+
args: [shareBalance],
|
|
630
|
+
functionName: 'previewRedeem',
|
|
631
|
+
});
|
|
632
|
+
return {
|
|
633
|
+
assetAllowance,
|
|
634
|
+
assetBalance,
|
|
635
|
+
assetToken,
|
|
636
|
+
shareAllowance,
|
|
637
|
+
shareBalance,
|
|
638
|
+
shareToken,
|
|
639
|
+
value,
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
async function getRedeemQuote(client, parameters) {
|
|
643
|
+
const { shareAmount, vault, ...rest } = parameters;
|
|
644
|
+
return (0, readContract_js_1.readContract)(client, {
|
|
645
|
+
...rest,
|
|
646
|
+
...getRedeemQuote.call({ shareAmount, vault }),
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
(function (getRedeemQuote) {
|
|
650
|
+
function call(args) {
|
|
651
|
+
const { shareAmount, vault } = args;
|
|
652
|
+
return (0, utils_js_1.defineCall)({
|
|
653
|
+
address: vault,
|
|
654
|
+
abi: Abis.vaultAdapter,
|
|
655
|
+
args: [shareAmount],
|
|
656
|
+
functionName: 'previewRedeem',
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
getRedeemQuote.call = call;
|
|
660
|
+
})(getRedeemQuote || (exports.getRedeemQuote = getRedeemQuote = {}));
|
|
661
|
+
async function getVault(client, parameters) {
|
|
662
|
+
const { vault, ...rest } = parameters;
|
|
663
|
+
const engine = await (0, readContract_js_1.readContract)(client, {
|
|
664
|
+
...rest,
|
|
665
|
+
abi: Abis.vaultAdapter,
|
|
666
|
+
address: vault,
|
|
667
|
+
functionName: 'engine',
|
|
668
|
+
});
|
|
669
|
+
const [assetToken, engine_, shareToken, operator, emergencyGuardian, asyncJanitor, engineMigrationMode, depositsPaused, engineShares, shareSupply, isSynced, pendingRedeemCount, feesActive, totalAssets, name, symbol, asyncRedeem, exactWithdraw, inKindDeposit, syncRedeem,] = await (0, multicall_js_1.multicall)(client, {
|
|
670
|
+
...rest,
|
|
671
|
+
allowFailure: false,
|
|
672
|
+
contracts: getVault.calls({ engine, vault }),
|
|
673
|
+
deployless: true,
|
|
674
|
+
});
|
|
675
|
+
if (!(0, isAddressEqual_js_1.isAddressEqual)(engine, engine_))
|
|
676
|
+
throw new errors_js_1.GetVaultEngineChangedError({ vault });
|
|
677
|
+
return {
|
|
678
|
+
assetToken,
|
|
679
|
+
asyncJanitor,
|
|
680
|
+
capabilities: { asyncRedeem, exactWithdraw, inKindDeposit, syncRedeem },
|
|
681
|
+
depositsPaused,
|
|
682
|
+
emergencyGuardian,
|
|
683
|
+
engine: { address: engine_, name, symbol, totalAssets },
|
|
684
|
+
engineMigrationMode: engineMigrationMode === 0 ? 'userOnly' : 'operatorEnabled',
|
|
685
|
+
engineShares,
|
|
686
|
+
feesActive,
|
|
687
|
+
isSynced,
|
|
688
|
+
operator,
|
|
689
|
+
pendingRedeemCount,
|
|
690
|
+
shareSupply,
|
|
691
|
+
shareToken,
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
(function (getVault) {
|
|
695
|
+
function calls(args) {
|
|
696
|
+
const { engine, vault } = args;
|
|
697
|
+
return [
|
|
698
|
+
(0, utils_js_1.defineCall)({
|
|
699
|
+
address: vault,
|
|
700
|
+
abi: Abis.vaultAdapter,
|
|
701
|
+
functionName: 'asset',
|
|
702
|
+
}),
|
|
703
|
+
(0, utils_js_1.defineCall)({
|
|
704
|
+
address: vault,
|
|
705
|
+
abi: Abis.vaultAdapter,
|
|
706
|
+
functionName: 'engine',
|
|
707
|
+
}),
|
|
708
|
+
(0, utils_js_1.defineCall)({
|
|
709
|
+
address: vault,
|
|
710
|
+
abi: Abis.vaultAdapter,
|
|
711
|
+
functionName: 'shareToken',
|
|
712
|
+
}),
|
|
713
|
+
(0, utils_js_1.defineCall)({
|
|
714
|
+
address: vault,
|
|
715
|
+
abi: Abis.vaultAdapter,
|
|
716
|
+
functionName: 'operator',
|
|
717
|
+
}),
|
|
718
|
+
(0, utils_js_1.defineCall)({
|
|
719
|
+
address: vault,
|
|
720
|
+
abi: Abis.vaultAdapter,
|
|
721
|
+
functionName: 'emergencyGuardian',
|
|
722
|
+
}),
|
|
723
|
+
(0, utils_js_1.defineCall)({
|
|
724
|
+
address: vault,
|
|
725
|
+
abi: Abis.vaultAdapter,
|
|
726
|
+
functionName: 'asyncJanitor',
|
|
727
|
+
}),
|
|
728
|
+
(0, utils_js_1.defineCall)({
|
|
729
|
+
address: vault,
|
|
730
|
+
abi: Abis.vaultAdapter,
|
|
731
|
+
functionName: 'engineMigrationMode',
|
|
732
|
+
}),
|
|
733
|
+
(0, utils_js_1.defineCall)({
|
|
734
|
+
address: vault,
|
|
735
|
+
abi: Abis.vaultAdapter,
|
|
736
|
+
functionName: 'depositsPaused',
|
|
737
|
+
}),
|
|
738
|
+
(0, utils_js_1.defineCall)({
|
|
739
|
+
address: vault,
|
|
740
|
+
abi: Abis.vaultAdapter,
|
|
741
|
+
functionName: 'engineShares',
|
|
742
|
+
}),
|
|
743
|
+
(0, utils_js_1.defineCall)({
|
|
744
|
+
address: vault,
|
|
745
|
+
abi: Abis.vaultAdapter,
|
|
746
|
+
functionName: 'shareSupply',
|
|
747
|
+
}),
|
|
748
|
+
(0, utils_js_1.defineCall)({
|
|
749
|
+
address: vault,
|
|
750
|
+
abi: Abis.vaultAdapter,
|
|
751
|
+
functionName: 'isSynced',
|
|
752
|
+
}),
|
|
753
|
+
(0, utils_js_1.defineCall)({
|
|
754
|
+
address: vault,
|
|
755
|
+
abi: Abis.vaultAdapter,
|
|
756
|
+
functionName: 'pendingRedeemCount',
|
|
757
|
+
}),
|
|
758
|
+
(0, utils_js_1.defineCall)({
|
|
759
|
+
address: vault,
|
|
760
|
+
abi: Abis.vaultAdapter,
|
|
761
|
+
functionName: 'feesActive',
|
|
762
|
+
}),
|
|
763
|
+
(0, utils_js_1.defineCall)({
|
|
764
|
+
address: engine,
|
|
765
|
+
abi: Abis.vaultEngine,
|
|
766
|
+
functionName: 'totalAssets',
|
|
767
|
+
}),
|
|
768
|
+
(0, utils_js_1.defineCall)({
|
|
769
|
+
address: engine,
|
|
770
|
+
abi: Abis.vaultEngine,
|
|
771
|
+
functionName: 'name',
|
|
772
|
+
}),
|
|
773
|
+
(0, utils_js_1.defineCall)({
|
|
774
|
+
address: engine,
|
|
775
|
+
abi: Abis.vaultEngine,
|
|
776
|
+
functionName: 'symbol',
|
|
777
|
+
}),
|
|
778
|
+
(0, utils_js_1.defineCall)({
|
|
779
|
+
address: engine,
|
|
780
|
+
abi: Abis.vaultEngine,
|
|
781
|
+
functionName: 'supportsInterface',
|
|
782
|
+
args: [interfaceIds.asyncRedeem],
|
|
783
|
+
}),
|
|
784
|
+
(0, utils_js_1.defineCall)({
|
|
785
|
+
address: engine,
|
|
786
|
+
abi: Abis.vaultEngine,
|
|
787
|
+
functionName: 'supportsInterface',
|
|
788
|
+
args: [interfaceIds.exactWithdraw],
|
|
789
|
+
}),
|
|
790
|
+
(0, utils_js_1.defineCall)({
|
|
791
|
+
address: engine,
|
|
792
|
+
abi: Abis.vaultEngine,
|
|
793
|
+
functionName: 'supportsInterface',
|
|
794
|
+
args: [interfaceIds.inKindDeposit],
|
|
795
|
+
}),
|
|
796
|
+
(0, utils_js_1.defineCall)({
|
|
797
|
+
address: engine,
|
|
798
|
+
abi: Abis.vaultEngine,
|
|
799
|
+
functionName: 'supportsInterface',
|
|
800
|
+
args: [interfaceIds.syncRedeem],
|
|
801
|
+
}),
|
|
802
|
+
];
|
|
803
|
+
}
|
|
804
|
+
getVault.calls = calls;
|
|
805
|
+
})(getVault || (exports.getVault = getVault = {}));
|
|
806
|
+
async function getWithdrawQuote(client, parameters) {
|
|
807
|
+
const { assetAmount, vault, ...rest } = parameters;
|
|
808
|
+
return (0, readContract_js_1.readContract)(client, {
|
|
809
|
+
...rest,
|
|
810
|
+
...getWithdrawQuote.call({ assetAmount, vault }),
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
(function (getWithdrawQuote) {
|
|
814
|
+
function call(args) {
|
|
815
|
+
const { assetAmount, vault } = args;
|
|
816
|
+
return (0, utils_js_1.defineCall)({
|
|
817
|
+
address: vault,
|
|
818
|
+
abi: Abis.vaultAdapter,
|
|
819
|
+
args: [assetAmount],
|
|
820
|
+
functionName: 'previewWithdraw',
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
getWithdrawQuote.call = call;
|
|
824
|
+
})(getWithdrawQuote || (exports.getWithdrawQuote = getWithdrawQuote = {}));
|
|
825
|
+
async function redeem(client, parameters) {
|
|
826
|
+
return redeem.inner(sendTransaction_js_1.sendTransaction, client, parameters);
|
|
827
|
+
}
|
|
828
|
+
(function (redeem) {
|
|
829
|
+
async function inner(action, client, parameters) {
|
|
830
|
+
const [args, shareToken] = await Promise.all([
|
|
831
|
+
toRedeemArgs(client, parameters),
|
|
832
|
+
(0, readContract_js_1.readContract)(client, {
|
|
833
|
+
abi: Abis.vaultAdapter,
|
|
834
|
+
address: parameters.vault,
|
|
835
|
+
functionName: 'shareToken',
|
|
836
|
+
}),
|
|
837
|
+
]);
|
|
838
|
+
return (await action(client, {
|
|
839
|
+
...parameters,
|
|
840
|
+
calls: redeem.calls({ ...args, shareToken }),
|
|
841
|
+
}));
|
|
842
|
+
}
|
|
843
|
+
redeem.inner = inner;
|
|
844
|
+
function call(...parameters) {
|
|
845
|
+
const [, args] = (0, utils_js_1.resolveCallParameters)(parameters);
|
|
846
|
+
const { recipient, vault } = args;
|
|
847
|
+
const assetAmountMin = (() => {
|
|
848
|
+
if (args.assetAmountMin !== undefined)
|
|
849
|
+
return args.assetAmountMin;
|
|
850
|
+
return tempo_1.EarnShares.minimumOutput(args.assetAmount, args.slippageBps);
|
|
851
|
+
})();
|
|
852
|
+
return (0, utils_js_1.defineCall)({
|
|
853
|
+
address: vault,
|
|
854
|
+
abi: Abis.vaultAdapter,
|
|
855
|
+
functionName: 'redeem',
|
|
856
|
+
args: [
|
|
857
|
+
internal_Token.toBaseUnits(args.shareAmount, undefined),
|
|
858
|
+
recipient,
|
|
859
|
+
assetAmountMin,
|
|
860
|
+
],
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
redeem.call = call;
|
|
864
|
+
function calls(args) {
|
|
865
|
+
const { shareToken, vault } = args;
|
|
866
|
+
const shareAmount = internal_Token.toBaseUnits(args.shareAmount, undefined);
|
|
867
|
+
return [
|
|
868
|
+
(0, utils_js_1.defineCall)({
|
|
869
|
+
address: shareToken,
|
|
870
|
+
abi: Abis.tip20,
|
|
871
|
+
functionName: 'approve',
|
|
872
|
+
args: [vault, shareAmount],
|
|
873
|
+
}),
|
|
874
|
+
redeem.call({ ...args, shareAmount }),
|
|
875
|
+
];
|
|
876
|
+
}
|
|
877
|
+
redeem.calls = calls;
|
|
878
|
+
function extractEvent(logs, parameters) {
|
|
879
|
+
const { vault } = parameters;
|
|
880
|
+
const [log] = (0, parseEventLogs_js_1.parseEventLogs)({
|
|
881
|
+
abi: Abis.vaultAdapter,
|
|
882
|
+
eventName: 'Redeemed',
|
|
883
|
+
logs: logs.filter((log) => (0, isAddressEqual_js_1.isAddressEqual)(log.address, vault)),
|
|
884
|
+
});
|
|
885
|
+
if (!log)
|
|
886
|
+
throw new Error('`Redeemed` event not found.');
|
|
887
|
+
return log;
|
|
888
|
+
}
|
|
889
|
+
redeem.extractEvent = extractEvent;
|
|
890
|
+
async function estimateGas(client, parameters) {
|
|
891
|
+
return (0, estimateContractGas_js_1.estimateContractGas)(client, {
|
|
892
|
+
...(0, utils_js_1.pickWriteParameters)(parameters),
|
|
893
|
+
...redeem.call(await toRedeemArgs(client, parameters)),
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
redeem.estimateGas = estimateGas;
|
|
897
|
+
async function simulate(client, parameters) {
|
|
898
|
+
return (0, simulateContract_js_1.simulateContract)(client, {
|
|
899
|
+
...(0, utils_js_1.pickWriteParameters)(parameters),
|
|
900
|
+
...redeem.call(await toRedeemArgs(client, parameters)),
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
redeem.simulate = simulate;
|
|
904
|
+
})(redeem || (exports.redeem = redeem = {}));
|
|
905
|
+
async function redeemSync(client, parameters) {
|
|
906
|
+
const { throwOnReceiptRevert = true, vault } = parameters;
|
|
907
|
+
const receipt = await redeem.inner(sendTransactionSync_js_1.sendTransactionSync, client, {
|
|
908
|
+
...parameters,
|
|
909
|
+
throwOnReceiptRevert,
|
|
910
|
+
});
|
|
911
|
+
const { args } = redeem.extractEvent(receipt.logs, { vault });
|
|
912
|
+
return {
|
|
913
|
+
assetAmount: args.assets,
|
|
914
|
+
caller: args.caller,
|
|
915
|
+
receipt,
|
|
916
|
+
recipient: args.receiver,
|
|
917
|
+
shareAmount: args.shares,
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
async function privateRedeem(client, parameters) {
|
|
921
|
+
await assertPreparedZoneRequestChain(client, parameters);
|
|
922
|
+
return zoneActions.requestWithdrawal(client, parameters);
|
|
923
|
+
}
|
|
924
|
+
(function (privateRedeem) {
|
|
925
|
+
async function prepare(client, parameters) {
|
|
926
|
+
const chainId = client.chain?.id;
|
|
927
|
+
if (!chainId)
|
|
928
|
+
throw new Error('`chain` is required.');
|
|
929
|
+
const { actionId = ox_1.Hex.random(32), callbackGas = zoneGatewayCallbackGas, fallbackRecipient = parameters.recoveryRecipient, gateway, recipient, recoveryRecipient, returnMemo, shareAmount, withdrawalMemo, } = parameters;
|
|
930
|
+
const readParameters = pickReadParameters(parameters);
|
|
931
|
+
const [fromBlock, config] = await Promise.all([
|
|
932
|
+
(0, getBlockNumber_js_1.getBlockNumber)(client, { cacheTime: 0 }),
|
|
933
|
+
getZoneGatewayConfig(client, { ...readParameters, gateway }),
|
|
934
|
+
]);
|
|
935
|
+
const assetToken = parameters.assetToken ?? config.vaultAsset;
|
|
936
|
+
if ((0, isAddressEqual_js_1.isAddressEqual)(assetToken, config.shareToken))
|
|
937
|
+
throw new Error('`assetToken` cannot be the gateway vault share token.');
|
|
938
|
+
const [{ encrypted, keyIndex }, assetAmountMin] = await Promise.all([
|
|
939
|
+
zoneActions.encryptedDeposit.prepareRecipient(client, {
|
|
940
|
+
...readParameters,
|
|
941
|
+
memo: returnMemo,
|
|
942
|
+
portalAddress: config.zonePortal,
|
|
943
|
+
recipient,
|
|
944
|
+
zoneId: config.zoneId,
|
|
945
|
+
}),
|
|
946
|
+
(async () => {
|
|
947
|
+
if (parameters.assetAmountMin !== undefined)
|
|
948
|
+
return tempo_1.EarnShares.minimumOutput(parameters.assetAmountMin, 0);
|
|
949
|
+
if (parameters.assetAmount !== undefined)
|
|
950
|
+
return tempo_1.EarnShares.minimumOutput(parameters.assetAmount, parameters.slippageBps);
|
|
951
|
+
const assetAmount = await getRedeemQuote(client, {
|
|
952
|
+
...readParameters,
|
|
953
|
+
shareAmount,
|
|
954
|
+
vault: config.vaultAdapter,
|
|
955
|
+
});
|
|
956
|
+
return tempo_1.EarnShares.minimumOutput(assetAmount, parameters.slippageBps);
|
|
957
|
+
})(),
|
|
958
|
+
]);
|
|
959
|
+
const direct = (0, isAddressEqual_js_1.isAddressEqual)(assetToken, config.vaultAsset);
|
|
960
|
+
const data = (0, encodeAbiParameters_js_1.encodeAbiParameters)(Abis.zoneGatewayCallbackData, [
|
|
961
|
+
{
|
|
962
|
+
flow: 1,
|
|
963
|
+
outputToken: assetToken,
|
|
964
|
+
keyIndex,
|
|
965
|
+
encrypted,
|
|
966
|
+
minVaultAssets: direct ? assetAmountMin : 1n,
|
|
967
|
+
minVaultShares: 0n,
|
|
968
|
+
minOutputAmount: direct ? 0n : assetAmountMin,
|
|
969
|
+
actionId,
|
|
970
|
+
refundRecipient: recoveryRecipient,
|
|
971
|
+
},
|
|
972
|
+
]);
|
|
973
|
+
return {
|
|
974
|
+
actionId,
|
|
975
|
+
amount: shareAmount,
|
|
976
|
+
callbackGas,
|
|
977
|
+
chainId,
|
|
978
|
+
data,
|
|
979
|
+
fallbackRecipient,
|
|
980
|
+
fromBlock,
|
|
981
|
+
memo: withdrawalMemo,
|
|
982
|
+
to: gateway,
|
|
983
|
+
token: config.shareToken,
|
|
984
|
+
zoneId: config.zoneId,
|
|
985
|
+
};
|
|
986
|
+
}
|
|
987
|
+
privateRedeem.prepare = prepare;
|
|
988
|
+
function calls(args) {
|
|
989
|
+
return zoneActions.requestWithdrawal.calls(args);
|
|
990
|
+
}
|
|
991
|
+
privateRedeem.calls = calls;
|
|
992
|
+
})(privateRedeem || (exports.privateRedeem = privateRedeem = {}));
|
|
993
|
+
async function privateRedeemSync(client, parameters) {
|
|
994
|
+
await assertPreparedZoneRequestChain(client, parameters);
|
|
995
|
+
return zoneActions.requestWithdrawalSync(client, parameters);
|
|
996
|
+
}
|
|
997
|
+
async function waitForPrivateRedeem(client, parameters) {
|
|
998
|
+
const { actionId, fromBlock, gateway, pollingInterval = client.pollingInterval, timeout = 60_000, } = parameters;
|
|
999
|
+
const event = (0, getAbiItem_js_1.getAbiItem)({
|
|
1000
|
+
abi: Abis.zoneGateway,
|
|
1001
|
+
name: 'EarnRedeem',
|
|
1002
|
+
});
|
|
1003
|
+
const observerId = (0, stringify_js_1.stringify)([
|
|
1004
|
+
'waitForPrivateRedeem',
|
|
1005
|
+
client.uid,
|
|
1006
|
+
gateway,
|
|
1007
|
+
actionId,
|
|
1008
|
+
fromBlock,
|
|
1009
|
+
]);
|
|
1010
|
+
const { promise, reject, resolve } = (0, withResolvers_js_1.withResolvers)();
|
|
1011
|
+
let timer;
|
|
1012
|
+
let unobserve;
|
|
1013
|
+
const cleanup = () => {
|
|
1014
|
+
clearTimeout(timer);
|
|
1015
|
+
unobserve();
|
|
1016
|
+
};
|
|
1017
|
+
const resolve_ = (result) => {
|
|
1018
|
+
cleanup();
|
|
1019
|
+
resolve(result);
|
|
1020
|
+
};
|
|
1021
|
+
const reject_ = (error) => {
|
|
1022
|
+
cleanup();
|
|
1023
|
+
reject(error);
|
|
1024
|
+
};
|
|
1025
|
+
unobserve = (0, observe_js_1.observe)(observerId, { reject: reject_, resolve: resolve_ }, (emit) => {
|
|
1026
|
+
const unpoll = (0, poll_js_1.poll)(async () => {
|
|
1027
|
+
try {
|
|
1028
|
+
const [log] = await (0, getLogs_js_1.getLogs)(client, {
|
|
1029
|
+
address: gateway,
|
|
1030
|
+
args: { actionId },
|
|
1031
|
+
event,
|
|
1032
|
+
fromBlock,
|
|
1033
|
+
strict: true,
|
|
1034
|
+
toBlock: 'latest',
|
|
1035
|
+
});
|
|
1036
|
+
if (!log)
|
|
1037
|
+
return;
|
|
1038
|
+
unpoll();
|
|
1039
|
+
emit.resolve({
|
|
1040
|
+
actionId: log.args.actionId,
|
|
1041
|
+
outputAmount: log.args.outputAmount,
|
|
1042
|
+
outputToken: log.args.outputToken,
|
|
1043
|
+
shares: log.args.shares,
|
|
1044
|
+
tempoBlockNumber: log.blockNumber,
|
|
1045
|
+
vaultAssets: log.args.vaultAssets,
|
|
1046
|
+
zoneDepositHash: log.args.zoneDepositHash,
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
catch (error) {
|
|
1050
|
+
unpoll();
|
|
1051
|
+
emit.reject(error);
|
|
1052
|
+
}
|
|
1053
|
+
}, { emitOnBegin: true, interval: pollingInterval });
|
|
1054
|
+
return unpoll;
|
|
1055
|
+
});
|
|
1056
|
+
timer = timeout
|
|
1057
|
+
? setTimeout(() => {
|
|
1058
|
+
reject_(new errors_js_1.WaitForPrivateRedeemTimeoutError({ actionId, gateway }));
|
|
1059
|
+
}, timeout)
|
|
1060
|
+
: undefined;
|
|
1061
|
+
return await promise;
|
|
1062
|
+
}
|
|
1063
|
+
async function withdrawExact(client, parameters) {
|
|
1064
|
+
return withdrawExact.inner(sendTransaction_js_1.sendTransaction, client, parameters);
|
|
1065
|
+
}
|
|
1066
|
+
(function (withdrawExact) {
|
|
1067
|
+
async function inner(action, client, parameters) {
|
|
1068
|
+
const [args, shareToken] = await Promise.all([
|
|
1069
|
+
toWithdrawExactArgs(client, parameters),
|
|
1070
|
+
(0, readContract_js_1.readContract)(client, {
|
|
1071
|
+
abi: Abis.vaultAdapter,
|
|
1072
|
+
address: parameters.vault,
|
|
1073
|
+
functionName: 'shareToken',
|
|
1074
|
+
}),
|
|
1075
|
+
]);
|
|
1076
|
+
return (await action(client, {
|
|
1077
|
+
...parameters,
|
|
1078
|
+
calls: withdrawExact.calls({ ...args, shareToken }),
|
|
1079
|
+
}));
|
|
1080
|
+
}
|
|
1081
|
+
withdrawExact.inner = inner;
|
|
1082
|
+
function call(...parameters) {
|
|
1083
|
+
const [, args] = (0, utils_js_1.resolveCallParameters)(parameters);
|
|
1084
|
+
const { recipient, vault } = args;
|
|
1085
|
+
const shareAmountMax = (() => {
|
|
1086
|
+
if (args.shareAmountMax !== undefined)
|
|
1087
|
+
return args.shareAmountMax;
|
|
1088
|
+
return maximumInput(args.shareAmount, args.slippageBps);
|
|
1089
|
+
})();
|
|
1090
|
+
return (0, utils_js_1.defineCall)({
|
|
1091
|
+
address: vault,
|
|
1092
|
+
abi: Abis.vaultAdapter,
|
|
1093
|
+
functionName: 'withdrawExact',
|
|
1094
|
+
args: [
|
|
1095
|
+
internal_Token.toBaseUnits(args.assetAmount, undefined),
|
|
1096
|
+
recipient,
|
|
1097
|
+
shareAmountMax,
|
|
1098
|
+
],
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
withdrawExact.call = call;
|
|
1102
|
+
function calls(args) {
|
|
1103
|
+
const { shareToken, vault } = args;
|
|
1104
|
+
const assetAmount = internal_Token.toBaseUnits(args.assetAmount, undefined);
|
|
1105
|
+
const call = withdrawExact.call({ ...args, assetAmount });
|
|
1106
|
+
const [, , shareAmountMax] = call.args;
|
|
1107
|
+
return [
|
|
1108
|
+
(0, utils_js_1.defineCall)({
|
|
1109
|
+
address: shareToken,
|
|
1110
|
+
abi: Abis.tip20,
|
|
1111
|
+
functionName: 'approve',
|
|
1112
|
+
args: [vault, shareAmountMax],
|
|
1113
|
+
}),
|
|
1114
|
+
call,
|
|
1115
|
+
];
|
|
1116
|
+
}
|
|
1117
|
+
withdrawExact.calls = calls;
|
|
1118
|
+
function extractEvent(logs, parameters) {
|
|
1119
|
+
const { vault } = parameters;
|
|
1120
|
+
const [log] = (0, parseEventLogs_js_1.parseEventLogs)({
|
|
1121
|
+
abi: Abis.vaultAdapter,
|
|
1122
|
+
eventName: 'WithdrewExact',
|
|
1123
|
+
logs: logs.filter((log) => (0, isAddressEqual_js_1.isAddressEqual)(log.address, vault)),
|
|
1124
|
+
});
|
|
1125
|
+
if (!log)
|
|
1126
|
+
throw new Error('`WithdrewExact` event not found.');
|
|
1127
|
+
return log;
|
|
1128
|
+
}
|
|
1129
|
+
withdrawExact.extractEvent = extractEvent;
|
|
1130
|
+
async function estimateGas(client, parameters) {
|
|
1131
|
+
return (0, estimateContractGas_js_1.estimateContractGas)(client, {
|
|
1132
|
+
...(0, utils_js_1.pickWriteParameters)(parameters),
|
|
1133
|
+
...withdrawExact.call(await toWithdrawExactArgs(client, parameters)),
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
withdrawExact.estimateGas = estimateGas;
|
|
1137
|
+
async function simulate(client, parameters) {
|
|
1138
|
+
return (0, simulateContract_js_1.simulateContract)(client, {
|
|
1139
|
+
...(0, utils_js_1.pickWriteParameters)(parameters),
|
|
1140
|
+
...withdrawExact.call(await toWithdrawExactArgs(client, parameters)),
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
1143
|
+
withdrawExact.simulate = simulate;
|
|
1144
|
+
})(withdrawExact || (exports.withdrawExact = withdrawExact = {}));
|
|
1145
|
+
async function withdrawExactSync(client, parameters) {
|
|
1146
|
+
const { throwOnReceiptRevert = true, vault } = parameters;
|
|
1147
|
+
const receipt = await withdrawExact.inner(sendTransactionSync_js_1.sendTransactionSync, client, {
|
|
1148
|
+
...parameters,
|
|
1149
|
+
throwOnReceiptRevert,
|
|
1150
|
+
});
|
|
1151
|
+
const { args } = withdrawExact.extractEvent(receipt.logs, { vault });
|
|
1152
|
+
return {
|
|
1153
|
+
assetAmount: args.assets,
|
|
1154
|
+
caller: args.caller,
|
|
1155
|
+
receipt,
|
|
1156
|
+
recipient: args.receiver,
|
|
1157
|
+
shareAmount: args.sharesBurned,
|
|
1158
|
+
};
|
|
1159
|
+
}
|
|
1160
|
+
const zoneGatewayCallbackGas = 10000000n;
|
|
1161
|
+
function resolveMinimumShareAmount(parameters) {
|
|
1162
|
+
if (parameters.shareAmountMin !== undefined)
|
|
1163
|
+
return tempo_1.EarnShares.minimumOutput(parameters.shareAmountMin, 0);
|
|
1164
|
+
return tempo_1.EarnShares.minimumOutput(parameters.shareAmount, parameters.slippageBps);
|
|
1165
|
+
}
|
|
1166
|
+
async function assertPreparedZoneRequestChain(client, parameters) {
|
|
1167
|
+
const chain = client.chain;
|
|
1168
|
+
if (!chain)
|
|
1169
|
+
throw new Error('`chain` is required.');
|
|
1170
|
+
if (chain.sourceId !== parameters.chainId)
|
|
1171
|
+
throw new Error('Prepared Zone request parent chain ID does not match client chain.');
|
|
1172
|
+
const { zoneId } = await zoneActions.getZoneInfo(client);
|
|
1173
|
+
if (zoneId !== parameters.zoneId)
|
|
1174
|
+
throw new Error('Prepared Zone request Zone ID does not match client chain.');
|
|
1175
|
+
}
|
|
1176
|
+
function pickReadParameters(parameters) {
|
|
1177
|
+
const { blockOverrides, stateOverride } = parameters;
|
|
1178
|
+
if (parameters.blockNumber !== undefined)
|
|
1179
|
+
return {
|
|
1180
|
+
blockNumber: parameters.blockNumber,
|
|
1181
|
+
blockOverrides,
|
|
1182
|
+
stateOverride,
|
|
1183
|
+
};
|
|
1184
|
+
return { blockOverrides, blockTag: parameters.blockTag, stateOverride };
|
|
1185
|
+
}
|
|
1186
|
+
async function getZoneGatewayConfig(client, parameters) {
|
|
1187
|
+
const { gateway, ...rest } = parameters;
|
|
1188
|
+
const [vaultAdapter, vaultAsset, shareToken, zoneId, zonePortal, supportsAsyncFlow,] = await (0, multicall_js_1.multicall)(client, {
|
|
1189
|
+
...rest,
|
|
1190
|
+
allowFailure: false,
|
|
1191
|
+
contracts: [
|
|
1192
|
+
{
|
|
1193
|
+
abi: Abis.zoneGateway,
|
|
1194
|
+
address: gateway,
|
|
1195
|
+
functionName: 'vaultAdapter',
|
|
1196
|
+
},
|
|
1197
|
+
{
|
|
1198
|
+
abi: Abis.zoneGateway,
|
|
1199
|
+
address: gateway,
|
|
1200
|
+
functionName: 'vaultAsset',
|
|
1201
|
+
},
|
|
1202
|
+
{
|
|
1203
|
+
abi: Abis.zoneGateway,
|
|
1204
|
+
address: gateway,
|
|
1205
|
+
functionName: 'shareToken',
|
|
1206
|
+
},
|
|
1207
|
+
{
|
|
1208
|
+
abi: Abis.zoneGateway,
|
|
1209
|
+
address: gateway,
|
|
1210
|
+
functionName: 'zoneId',
|
|
1211
|
+
},
|
|
1212
|
+
{
|
|
1213
|
+
abi: Abis.zoneGateway,
|
|
1214
|
+
address: gateway,
|
|
1215
|
+
functionName: 'zonePortal',
|
|
1216
|
+
},
|
|
1217
|
+
{
|
|
1218
|
+
abi: Abis.zoneGateway,
|
|
1219
|
+
address: gateway,
|
|
1220
|
+
args: [2],
|
|
1221
|
+
functionName: 'supportsFlow',
|
|
1222
|
+
},
|
|
1223
|
+
],
|
|
1224
|
+
deployless: true,
|
|
1225
|
+
});
|
|
1226
|
+
if (supportsAsyncFlow)
|
|
1227
|
+
throw new Error('Async Zone gateways are not supported.');
|
|
1228
|
+
return { shareToken, vaultAdapter, vaultAsset, zoneId, zonePortal };
|
|
1229
|
+
}
|
|
1230
|
+
const interfaceIds = {
|
|
1231
|
+
asyncRedeem: '0xa1a6a1d7',
|
|
1232
|
+
exactWithdraw: '0x0adfb0b9',
|
|
1233
|
+
inKindDeposit: '0x7d28a2f2',
|
|
1234
|
+
syncRedeem: '0x370457f4',
|
|
1235
|
+
};
|
|
1236
|
+
function toFeeConfig(config) {
|
|
1237
|
+
return {
|
|
1238
|
+
excess: config.excess,
|
|
1239
|
+
fixedFees: config.fixedFees.slice(0, config.fixedFeeCount),
|
|
1240
|
+
};
|
|
1241
|
+
}
|
|
1242
|
+
function toFeePreview(preview) {
|
|
1243
|
+
const { allocationCount, allocations, ...rest } = preview;
|
|
1244
|
+
return { ...rest, allocations: allocations.slice(0, allocationCount) };
|
|
1245
|
+
}
|
|
1246
|
+
async function toDepositArgs(client, parameters) {
|
|
1247
|
+
const { vault } = parameters;
|
|
1248
|
+
const assetAmount = await toBaseUnitsLive(client, {
|
|
1249
|
+
amount: parameters.assetAmount,
|
|
1250
|
+
token: 'asset',
|
|
1251
|
+
vault,
|
|
1252
|
+
});
|
|
1253
|
+
const args = {
|
|
1254
|
+
assetAmount,
|
|
1255
|
+
recipient: resolveRecipient(client, parameters),
|
|
1256
|
+
vault,
|
|
1257
|
+
};
|
|
1258
|
+
if (parameters.shareAmountMin !== undefined)
|
|
1259
|
+
return { ...args, shareAmountMin: parameters.shareAmountMin };
|
|
1260
|
+
return {
|
|
1261
|
+
...args,
|
|
1262
|
+
shareAmount: parameters.shareAmount,
|
|
1263
|
+
slippageBps: parameters.slippageBps,
|
|
1264
|
+
};
|
|
1265
|
+
}
|
|
1266
|
+
function toDepositSharesArgs(client, parameters) {
|
|
1267
|
+
const { vault, venueShareAmount } = parameters;
|
|
1268
|
+
const args = {
|
|
1269
|
+
recipient: resolveRecipient(client, parameters),
|
|
1270
|
+
vault,
|
|
1271
|
+
venueShareAmount,
|
|
1272
|
+
};
|
|
1273
|
+
if (parameters.earnShareAmountMin !== undefined)
|
|
1274
|
+
return { ...args, earnShareAmountMin: parameters.earnShareAmountMin };
|
|
1275
|
+
return {
|
|
1276
|
+
...args,
|
|
1277
|
+
earnShareAmount: parameters.earnShareAmount,
|
|
1278
|
+
slippageBps: parameters.slippageBps,
|
|
1279
|
+
};
|
|
1280
|
+
}
|
|
1281
|
+
async function toRedeemArgs(client, parameters) {
|
|
1282
|
+
const { vault } = parameters;
|
|
1283
|
+
const shareAmount = await toBaseUnitsLive(client, {
|
|
1284
|
+
amount: parameters.shareAmount,
|
|
1285
|
+
token: 'shareToken',
|
|
1286
|
+
vault,
|
|
1287
|
+
});
|
|
1288
|
+
const args = {
|
|
1289
|
+
recipient: resolveRecipient(client, parameters),
|
|
1290
|
+
shareAmount,
|
|
1291
|
+
vault,
|
|
1292
|
+
};
|
|
1293
|
+
if (parameters.assetAmountMin !== undefined)
|
|
1294
|
+
return { ...args, assetAmountMin: parameters.assetAmountMin };
|
|
1295
|
+
const assetAmount = await (async () => {
|
|
1296
|
+
if (parameters.assetAmount !== undefined)
|
|
1297
|
+
return parameters.assetAmount;
|
|
1298
|
+
return getRedeemQuote(client, { shareAmount, vault });
|
|
1299
|
+
})();
|
|
1300
|
+
return {
|
|
1301
|
+
...args,
|
|
1302
|
+
assetAmount,
|
|
1303
|
+
slippageBps: parameters.slippageBps,
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1306
|
+
async function toWithdrawExactArgs(client, parameters) {
|
|
1307
|
+
const { vault } = parameters;
|
|
1308
|
+
const assetAmount = await toBaseUnitsLive(client, {
|
|
1309
|
+
amount: parameters.assetAmount,
|
|
1310
|
+
token: 'asset',
|
|
1311
|
+
vault,
|
|
1312
|
+
});
|
|
1313
|
+
const args = {
|
|
1314
|
+
assetAmount,
|
|
1315
|
+
recipient: resolveRecipient(client, parameters),
|
|
1316
|
+
vault,
|
|
1317
|
+
};
|
|
1318
|
+
if (parameters.shareAmountMax !== undefined)
|
|
1319
|
+
return { ...args, shareAmountMax: parameters.shareAmountMax };
|
|
1320
|
+
const shareAmount = await (async () => {
|
|
1321
|
+
if (parameters.shareAmount !== undefined)
|
|
1322
|
+
return parameters.shareAmount;
|
|
1323
|
+
return getWithdrawQuote(client, { assetAmount, vault });
|
|
1324
|
+
})();
|
|
1325
|
+
return {
|
|
1326
|
+
...args,
|
|
1327
|
+
shareAmount,
|
|
1328
|
+
slippageBps: parameters.slippageBps,
|
|
1329
|
+
};
|
|
1330
|
+
}
|
|
1331
|
+
function maximumInput(shareAmount, slippageBps) {
|
|
1332
|
+
if (shareAmount <= 0n)
|
|
1333
|
+
throw new tempo_1.EarnShares.InvalidExpectedOutputError({
|
|
1334
|
+
expectedAmount: shareAmount,
|
|
1335
|
+
});
|
|
1336
|
+
if (!Number.isInteger(slippageBps) ||
|
|
1337
|
+
slippageBps < 0 ||
|
|
1338
|
+
slippageBps >= tempo_1.EarnShares.basisPointScale)
|
|
1339
|
+
throw new tempo_1.EarnShares.InvalidSlippageError({ slippageBps });
|
|
1340
|
+
const scale = BigInt(tempo_1.EarnShares.basisPointScale);
|
|
1341
|
+
const numerator = shareAmount * (scale + BigInt(slippageBps));
|
|
1342
|
+
return (numerator + scale - 1n) / scale;
|
|
1343
|
+
}
|
|
1344
|
+
async function toBaseUnitsLive(client, options) {
|
|
1345
|
+
const { amount, token, vault } = options;
|
|
1346
|
+
if (typeof amount === 'bigint')
|
|
1347
|
+
return amount;
|
|
1348
|
+
if (amount.decimals !== undefined)
|
|
1349
|
+
return internal_Token.toBaseUnits(amount, amount.decimals);
|
|
1350
|
+
const address = await (0, readContract_js_1.readContract)(client, {
|
|
1351
|
+
abi: Abis.vaultAdapter,
|
|
1352
|
+
address: vault,
|
|
1353
|
+
functionName: token,
|
|
1354
|
+
});
|
|
1355
|
+
const { decimals } = await (0, utils_js_1.resolveTokenWithDecimals)(client, {
|
|
1356
|
+
token: address,
|
|
1357
|
+
});
|
|
1358
|
+
return internal_Token.toBaseUnits(amount, decimals);
|
|
1359
|
+
}
|
|
1360
|
+
function resolveRecipient(client, parameters) {
|
|
1361
|
+
if (parameters.recipient)
|
|
1362
|
+
return parameters.recipient;
|
|
1363
|
+
const account = parameters.account ?? client.account;
|
|
1364
|
+
if (!account)
|
|
1365
|
+
throw new account_js_1.AccountNotFoundError();
|
|
1366
|
+
return (0, parseAccount_js_1.parseAccount)(account).address;
|
|
1367
|
+
}
|
|
1368
|
+
//# sourceMappingURL=earn.js.map
|