@gearbox-protocol/sdk 12.5.1 → 12.5.3
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/cjs/permissionless/bindings/bytecode-repository.js +2 -1
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV300.js +188 -0
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +6 -0
- package/dist/cjs/sdk/sdk-legacy/core/transactions.js +12 -7
- package/dist/esm/permissionless/bindings/bytecode-repository.js +2 -1
- package/dist/esm/sdk/accounts/CreditAccountsServiceV300.js +188 -0
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +6 -0
- package/dist/esm/sdk/sdk-legacy/core/transactions.js +12 -7
- package/dist/types/permissionless/core/bytecode.d.ts +1 -0
- package/dist/types/sdk/accounts/CreditAccountsServiceV300.d.ts +8 -1
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +3 -1
- package/dist/types/sdk/accounts/types.d.ts +41 -0
- package/dist/types/sdk/sdk-legacy/core/transactions.d.ts +6 -3
- package/package.json +1 -1
|
@@ -115,7 +115,8 @@ class BytecodeRepositoryContract extends import_sdk.BaseContract {
|
|
|
115
115
|
// BigInt(this.client.chain!.id!),
|
|
116
116
|
txHash: e.transactionHash,
|
|
117
117
|
blockNumber: Number(e.blockNumber),
|
|
118
|
-
bytecodeHash: e.args.bytecodeHash
|
|
118
|
+
bytecodeHash: e.args.bytecodeHash,
|
|
119
|
+
constructorParams: e.args.constructorParams
|
|
119
120
|
});
|
|
120
121
|
}
|
|
121
122
|
return result;
|
|
@@ -21,8 +21,10 @@ __export(CreditAccountsServiceV300_exports, {
|
|
|
21
21
|
CreditAccountServiceV300: () => CreditAccountServiceV300
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(CreditAccountsServiceV300_exports);
|
|
24
|
+
var import_integrations_v3 = require("@gearbox-protocol/integrations-v3");
|
|
24
25
|
var import_abitype = require("abitype");
|
|
25
26
|
var import_viem = require("viem");
|
|
27
|
+
var import_iBaseRewardPool = require("../../abi/iBaseRewardPool.js");
|
|
26
28
|
var import_addresses = require("../constants/addresses.js");
|
|
27
29
|
var import_math = require("../constants/math.js");
|
|
28
30
|
var import_sdk_gov_legacy = require("../sdk-gov-legacy/index.js");
|
|
@@ -179,6 +181,192 @@ class CreditAccountServiceV300 extends import_AbstractCreditAccountsService.Abst
|
|
|
179
181
|
const tx = cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
180
182
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
181
183
|
}
|
|
184
|
+
async previewWithdrawLlamathenaProportionally({
|
|
185
|
+
llamathena
|
|
186
|
+
}) {
|
|
187
|
+
const LLAMATHENA_CURVE_POOL = "0xd29f8980852c2c76fc3f6e96a7aa06e0bedcc1b1".toLowerCase();
|
|
188
|
+
const SCRVUSD = "0x0655977FEb2f289A4aB78af67BAB0d17aAb84367".toLowerCase();
|
|
189
|
+
const SUSDE = "0x9D39A5DE30e57443BfF2A8307A4256c8797A3497".toLowerCase();
|
|
190
|
+
const llamathenaBalance = llamathena.balance;
|
|
191
|
+
if (llamathenaBalance === 0n)
|
|
192
|
+
return {
|
|
193
|
+
scrvusdDelta: 0n,
|
|
194
|
+
scrvusdAddress: SCRVUSD,
|
|
195
|
+
susdeDelta: 0n,
|
|
196
|
+
susdeAddress: SUSDE,
|
|
197
|
+
llamathena: [llamathena],
|
|
198
|
+
assets: [
|
|
199
|
+
{
|
|
200
|
+
token: SCRVUSD,
|
|
201
|
+
balance: 0n
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
token: SUSDE,
|
|
205
|
+
balance: 0n
|
|
206
|
+
}
|
|
207
|
+
]
|
|
208
|
+
};
|
|
209
|
+
const llamathenaAbi = [
|
|
210
|
+
{
|
|
211
|
+
type: "function",
|
|
212
|
+
inputs: [],
|
|
213
|
+
name: "get_balances",
|
|
214
|
+
outputs: [
|
|
215
|
+
{
|
|
216
|
+
name: "",
|
|
217
|
+
internalType: "uint256[]",
|
|
218
|
+
type: "uint256[]"
|
|
219
|
+
}
|
|
220
|
+
],
|
|
221
|
+
stateMutability: "view"
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
type: "function",
|
|
225
|
+
inputs: [],
|
|
226
|
+
name: "totalSupply",
|
|
227
|
+
outputs: [
|
|
228
|
+
{
|
|
229
|
+
name: "",
|
|
230
|
+
internalType: "uint256",
|
|
231
|
+
type: "uint256"
|
|
232
|
+
}
|
|
233
|
+
],
|
|
234
|
+
stateMutability: "view"
|
|
235
|
+
}
|
|
236
|
+
];
|
|
237
|
+
const [poolBalances, totalSupply] = await this.client.multicall({
|
|
238
|
+
batchSize: 0,
|
|
239
|
+
allowFailure: false,
|
|
240
|
+
contracts: [
|
|
241
|
+
{
|
|
242
|
+
address: LLAMATHENA_CURVE_POOL,
|
|
243
|
+
abi: llamathenaAbi,
|
|
244
|
+
functionName: "get_balances"
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
address: LLAMATHENA_CURVE_POOL,
|
|
248
|
+
abi: llamathenaAbi,
|
|
249
|
+
functionName: "totalSupply"
|
|
250
|
+
}
|
|
251
|
+
]
|
|
252
|
+
});
|
|
253
|
+
if (totalSupply === 0n)
|
|
254
|
+
return {
|
|
255
|
+
scrvusdDelta: 0n,
|
|
256
|
+
scrvusdAddress: SCRVUSD,
|
|
257
|
+
susdeDelta: 0n,
|
|
258
|
+
susdeAddress: SUSDE,
|
|
259
|
+
llamathena: [llamathena],
|
|
260
|
+
assets: [
|
|
261
|
+
{
|
|
262
|
+
token: SCRVUSD,
|
|
263
|
+
balance: 0n
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
token: SUSDE,
|
|
267
|
+
balance: 0n
|
|
268
|
+
}
|
|
269
|
+
]
|
|
270
|
+
};
|
|
271
|
+
const [scrvusdBalance = 0n, susdeBalance = 0n] = poolBalances;
|
|
272
|
+
const scrvusdDelta = scrvusdBalance * llamathenaBalance / totalSupply;
|
|
273
|
+
const susdeDelta = susdeBalance * llamathenaBalance / totalSupply;
|
|
274
|
+
return {
|
|
275
|
+
scrvusdDelta,
|
|
276
|
+
scrvusdAddress: SCRVUSD,
|
|
277
|
+
susdeDelta,
|
|
278
|
+
susdeAddress: SUSDE,
|
|
279
|
+
llamathena: [llamathena],
|
|
280
|
+
assets: [
|
|
281
|
+
{
|
|
282
|
+
token: SCRVUSD,
|
|
283
|
+
balance: scrvusdDelta
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
token: SUSDE,
|
|
287
|
+
balance: susdeDelta
|
|
288
|
+
}
|
|
289
|
+
]
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
async withdrawLlamathenaProportionally({
|
|
293
|
+
preview,
|
|
294
|
+
creditAccount: ca,
|
|
295
|
+
minQuota,
|
|
296
|
+
averageQuota
|
|
297
|
+
}) {
|
|
298
|
+
const LLAMATHENA_BASE_REWARD_POOL = "0x11fd8801a051b296e337a3e1168839fb346d5940";
|
|
299
|
+
const LLAMATHENA_POOL = "0xd29f8980852c2c76fc3f6e96a7aa06e0bedcc1b1";
|
|
300
|
+
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
301
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
302
|
+
creditManager: ca.creditManager,
|
|
303
|
+
creditAccount: ca,
|
|
304
|
+
desiredQuotas: averageQuota
|
|
305
|
+
});
|
|
306
|
+
const baseRewardPoolAdapter = cm.creditManager.adapters.get(
|
|
307
|
+
LLAMATHENA_BASE_REWARD_POOL
|
|
308
|
+
);
|
|
309
|
+
if (!baseRewardPoolAdapter) {
|
|
310
|
+
throw new Error("BaseRewardPool adapter for llamathena is missing");
|
|
311
|
+
}
|
|
312
|
+
const curvePoolAdapter = cm.creditManager.adapters.get(LLAMATHENA_POOL);
|
|
313
|
+
if (!curvePoolAdapter) {
|
|
314
|
+
throw new Error("Curve pool adapter for llamathena is missing");
|
|
315
|
+
}
|
|
316
|
+
const storeExpectedBalances = {
|
|
317
|
+
target: cm.creditFacade.address,
|
|
318
|
+
callData: (0, import_viem.encodeFunctionData)({
|
|
319
|
+
abi: cm.creditFacade.abi,
|
|
320
|
+
functionName: "storeExpectedBalances",
|
|
321
|
+
args: [
|
|
322
|
+
[
|
|
323
|
+
{ token: preview.scrvusdAddress, amount: preview.scrvusdDelta },
|
|
324
|
+
{ token: preview.susdeAddress, amount: preview.susdeDelta }
|
|
325
|
+
]
|
|
326
|
+
]
|
|
327
|
+
})
|
|
328
|
+
};
|
|
329
|
+
const withdrawAndUnwrapCall = {
|
|
330
|
+
target: baseRewardPoolAdapter.address,
|
|
331
|
+
callData: (0, import_viem.encodeFunctionData)({
|
|
332
|
+
abi: import_iBaseRewardPool.iBaseRewardPoolAbi,
|
|
333
|
+
functionName: "withdrawAndUnwrap",
|
|
334
|
+
args: [preview.llamathena[0].balance, false]
|
|
335
|
+
})
|
|
336
|
+
};
|
|
337
|
+
const removeLiquidityCall = {
|
|
338
|
+
target: curvePoolAdapter.address,
|
|
339
|
+
callData: (0, import_viem.encodeFunctionData)({
|
|
340
|
+
abi: import_integrations_v3.iCurveV1_2AssetsAdapterAbi,
|
|
341
|
+
functionName: "remove_liquidity",
|
|
342
|
+
args: [preview.llamathena[0].balance, [0n, 0n]]
|
|
343
|
+
})
|
|
344
|
+
};
|
|
345
|
+
const compareBalances = {
|
|
346
|
+
target: cm.creditFacade.address,
|
|
347
|
+
callData: (0, import_viem.encodeFunctionData)({
|
|
348
|
+
abi: cm.creditFacade.abi,
|
|
349
|
+
functionName: "compareBalances",
|
|
350
|
+
args: []
|
|
351
|
+
})
|
|
352
|
+
};
|
|
353
|
+
const swapCalls = [
|
|
354
|
+
storeExpectedBalances,
|
|
355
|
+
withdrawAndUnwrapCall,
|
|
356
|
+
removeLiquidityCall,
|
|
357
|
+
compareBalances
|
|
358
|
+
];
|
|
359
|
+
const calls = [
|
|
360
|
+
...priceUpdatesCalls,
|
|
361
|
+
...swapCalls,
|
|
362
|
+
...this.prepareUpdateQuotas(ca.creditFacade, {
|
|
363
|
+
minQuota,
|
|
364
|
+
averageQuota
|
|
365
|
+
})
|
|
366
|
+
];
|
|
367
|
+
const tx = cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
368
|
+
return { tx, calls, creditFacade: cm.creditFacade };
|
|
369
|
+
}
|
|
182
370
|
/**
|
|
183
371
|
* unwraps staked tokens and optionally claims associated rewards; Should be remove after transition to 3.1
|
|
184
372
|
* @param acc
|
|
@@ -212,6 +212,12 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
212
212
|
const tx = cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
213
213
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
214
214
|
}
|
|
215
|
+
async previewWithdrawLlamathenaProportionally(_) {
|
|
216
|
+
throw new Error("Not implemented in v310");
|
|
217
|
+
}
|
|
218
|
+
async withdrawLlamathenaProportionally(_) {
|
|
219
|
+
throw new Error("Not implemented in v310");
|
|
220
|
+
}
|
|
215
221
|
}
|
|
216
222
|
// Annotate the CommonJS export names for ESM import in node:
|
|
217
223
|
0 && (module.exports = {
|
|
@@ -225,24 +225,29 @@ class TxUnstakeDiesel extends import_eventOrTx.EVMTx {
|
|
|
225
225
|
class TXSwap extends import_eventOrTx.EVMTx {
|
|
226
226
|
operation;
|
|
227
227
|
amountFrom;
|
|
228
|
-
amountTo;
|
|
229
228
|
tokenFrom;
|
|
230
|
-
|
|
229
|
+
to;
|
|
231
230
|
creditManagerName;
|
|
232
231
|
constructor(opts) {
|
|
233
232
|
super(opts);
|
|
234
233
|
this.operation = opts.operation;
|
|
235
234
|
this.amountFrom = opts.amountFrom;
|
|
236
|
-
this.amountTo = opts.amountTo;
|
|
237
235
|
this.tokenFrom = opts.tokensList[opts.tokenFrom];
|
|
238
|
-
|
|
236
|
+
const list = opts.to ? opts.to : opts.amountTo && opts.tokenTo ? [{ balance: opts.amountTo, token: opts.tokenTo }] : void 0;
|
|
237
|
+
this.to = list?.map(({ token, balance }) => ({
|
|
238
|
+
token: opts.tokensList[token],
|
|
239
|
+
balance
|
|
240
|
+
}));
|
|
239
241
|
this.creditManagerName = opts.creditManagerName;
|
|
240
242
|
}
|
|
241
243
|
_toString() {
|
|
242
244
|
let toPart = "";
|
|
243
|
-
if (this.
|
|
244
|
-
const {
|
|
245
|
-
|
|
245
|
+
if (this.to) {
|
|
246
|
+
const str = this.to.map(({ token, balance }) => {
|
|
247
|
+
const { title: tokenSymbol, decimals: tokenDecimals = 18 } = token;
|
|
248
|
+
return `${(0, import_utils.formatBN)(balance, tokenDecimals)} ${tokenSymbol}`;
|
|
249
|
+
}).join(", ");
|
|
250
|
+
toPart = ` \u21D2 ${str}`;
|
|
246
251
|
}
|
|
247
252
|
const { title: fromSymbol, decimals: fromDecimals = 18 } = this.tokenFrom;
|
|
248
253
|
return `Credit Account ${this.creditManagerName}: ${this.operation} ${(0, import_utils.formatBN)(this.amountFrom, fromDecimals)} ${fromSymbol} ${toPart}`;
|
|
@@ -98,7 +98,8 @@ class BytecodeRepositoryContract extends BaseContract {
|
|
|
98
98
|
// BigInt(this.client.chain!.id!),
|
|
99
99
|
txHash: e.transactionHash,
|
|
100
100
|
blockNumber: Number(e.blockNumber),
|
|
101
|
-
bytecodeHash: e.args.bytecodeHash
|
|
101
|
+
bytecodeHash: e.args.bytecodeHash,
|
|
102
|
+
constructorParams: e.args.constructorParams
|
|
102
103
|
});
|
|
103
104
|
}
|
|
104
105
|
return result;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { iCurveV1_2AssetsAdapterAbi } from "@gearbox-protocol/integrations-v3";
|
|
1
2
|
import { parseAbi } from "abitype";
|
|
2
3
|
import { encodeFunctionData } from "viem";
|
|
4
|
+
import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
|
|
3
5
|
import { NOT_DEPLOYED } from "../constants/addresses.js";
|
|
4
6
|
import { MAX_UINT256 } from "../constants/math.js";
|
|
5
7
|
import {
|
|
@@ -168,6 +170,192 @@ class CreditAccountServiceV300 extends AbstractCreditAccountService {
|
|
|
168
170
|
const tx = cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
169
171
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
170
172
|
}
|
|
173
|
+
async previewWithdrawLlamathenaProportionally({
|
|
174
|
+
llamathena
|
|
175
|
+
}) {
|
|
176
|
+
const LLAMATHENA_CURVE_POOL = "0xd29f8980852c2c76fc3f6e96a7aa06e0bedcc1b1".toLowerCase();
|
|
177
|
+
const SCRVUSD = "0x0655977FEb2f289A4aB78af67BAB0d17aAb84367".toLowerCase();
|
|
178
|
+
const SUSDE = "0x9D39A5DE30e57443BfF2A8307A4256c8797A3497".toLowerCase();
|
|
179
|
+
const llamathenaBalance = llamathena.balance;
|
|
180
|
+
if (llamathenaBalance === 0n)
|
|
181
|
+
return {
|
|
182
|
+
scrvusdDelta: 0n,
|
|
183
|
+
scrvusdAddress: SCRVUSD,
|
|
184
|
+
susdeDelta: 0n,
|
|
185
|
+
susdeAddress: SUSDE,
|
|
186
|
+
llamathena: [llamathena],
|
|
187
|
+
assets: [
|
|
188
|
+
{
|
|
189
|
+
token: SCRVUSD,
|
|
190
|
+
balance: 0n
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
token: SUSDE,
|
|
194
|
+
balance: 0n
|
|
195
|
+
}
|
|
196
|
+
]
|
|
197
|
+
};
|
|
198
|
+
const llamathenaAbi = [
|
|
199
|
+
{
|
|
200
|
+
type: "function",
|
|
201
|
+
inputs: [],
|
|
202
|
+
name: "get_balances",
|
|
203
|
+
outputs: [
|
|
204
|
+
{
|
|
205
|
+
name: "",
|
|
206
|
+
internalType: "uint256[]",
|
|
207
|
+
type: "uint256[]"
|
|
208
|
+
}
|
|
209
|
+
],
|
|
210
|
+
stateMutability: "view"
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
type: "function",
|
|
214
|
+
inputs: [],
|
|
215
|
+
name: "totalSupply",
|
|
216
|
+
outputs: [
|
|
217
|
+
{
|
|
218
|
+
name: "",
|
|
219
|
+
internalType: "uint256",
|
|
220
|
+
type: "uint256"
|
|
221
|
+
}
|
|
222
|
+
],
|
|
223
|
+
stateMutability: "view"
|
|
224
|
+
}
|
|
225
|
+
];
|
|
226
|
+
const [poolBalances, totalSupply] = await this.client.multicall({
|
|
227
|
+
batchSize: 0,
|
|
228
|
+
allowFailure: false,
|
|
229
|
+
contracts: [
|
|
230
|
+
{
|
|
231
|
+
address: LLAMATHENA_CURVE_POOL,
|
|
232
|
+
abi: llamathenaAbi,
|
|
233
|
+
functionName: "get_balances"
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
address: LLAMATHENA_CURVE_POOL,
|
|
237
|
+
abi: llamathenaAbi,
|
|
238
|
+
functionName: "totalSupply"
|
|
239
|
+
}
|
|
240
|
+
]
|
|
241
|
+
});
|
|
242
|
+
if (totalSupply === 0n)
|
|
243
|
+
return {
|
|
244
|
+
scrvusdDelta: 0n,
|
|
245
|
+
scrvusdAddress: SCRVUSD,
|
|
246
|
+
susdeDelta: 0n,
|
|
247
|
+
susdeAddress: SUSDE,
|
|
248
|
+
llamathena: [llamathena],
|
|
249
|
+
assets: [
|
|
250
|
+
{
|
|
251
|
+
token: SCRVUSD,
|
|
252
|
+
balance: 0n
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
token: SUSDE,
|
|
256
|
+
balance: 0n
|
|
257
|
+
}
|
|
258
|
+
]
|
|
259
|
+
};
|
|
260
|
+
const [scrvusdBalance = 0n, susdeBalance = 0n] = poolBalances;
|
|
261
|
+
const scrvusdDelta = scrvusdBalance * llamathenaBalance / totalSupply;
|
|
262
|
+
const susdeDelta = susdeBalance * llamathenaBalance / totalSupply;
|
|
263
|
+
return {
|
|
264
|
+
scrvusdDelta,
|
|
265
|
+
scrvusdAddress: SCRVUSD,
|
|
266
|
+
susdeDelta,
|
|
267
|
+
susdeAddress: SUSDE,
|
|
268
|
+
llamathena: [llamathena],
|
|
269
|
+
assets: [
|
|
270
|
+
{
|
|
271
|
+
token: SCRVUSD,
|
|
272
|
+
balance: scrvusdDelta
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
token: SUSDE,
|
|
276
|
+
balance: susdeDelta
|
|
277
|
+
}
|
|
278
|
+
]
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
async withdrawLlamathenaProportionally({
|
|
282
|
+
preview,
|
|
283
|
+
creditAccount: ca,
|
|
284
|
+
minQuota,
|
|
285
|
+
averageQuota
|
|
286
|
+
}) {
|
|
287
|
+
const LLAMATHENA_BASE_REWARD_POOL = "0x11fd8801a051b296e337a3e1168839fb346d5940";
|
|
288
|
+
const LLAMATHENA_POOL = "0xd29f8980852c2c76fc3f6e96a7aa06e0bedcc1b1";
|
|
289
|
+
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
290
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
291
|
+
creditManager: ca.creditManager,
|
|
292
|
+
creditAccount: ca,
|
|
293
|
+
desiredQuotas: averageQuota
|
|
294
|
+
});
|
|
295
|
+
const baseRewardPoolAdapter = cm.creditManager.adapters.get(
|
|
296
|
+
LLAMATHENA_BASE_REWARD_POOL
|
|
297
|
+
);
|
|
298
|
+
if (!baseRewardPoolAdapter) {
|
|
299
|
+
throw new Error("BaseRewardPool adapter for llamathena is missing");
|
|
300
|
+
}
|
|
301
|
+
const curvePoolAdapter = cm.creditManager.adapters.get(LLAMATHENA_POOL);
|
|
302
|
+
if (!curvePoolAdapter) {
|
|
303
|
+
throw new Error("Curve pool adapter for llamathena is missing");
|
|
304
|
+
}
|
|
305
|
+
const storeExpectedBalances = {
|
|
306
|
+
target: cm.creditFacade.address,
|
|
307
|
+
callData: encodeFunctionData({
|
|
308
|
+
abi: cm.creditFacade.abi,
|
|
309
|
+
functionName: "storeExpectedBalances",
|
|
310
|
+
args: [
|
|
311
|
+
[
|
|
312
|
+
{ token: preview.scrvusdAddress, amount: preview.scrvusdDelta },
|
|
313
|
+
{ token: preview.susdeAddress, amount: preview.susdeDelta }
|
|
314
|
+
]
|
|
315
|
+
]
|
|
316
|
+
})
|
|
317
|
+
};
|
|
318
|
+
const withdrawAndUnwrapCall = {
|
|
319
|
+
target: baseRewardPoolAdapter.address,
|
|
320
|
+
callData: encodeFunctionData({
|
|
321
|
+
abi: iBaseRewardPoolAbi,
|
|
322
|
+
functionName: "withdrawAndUnwrap",
|
|
323
|
+
args: [preview.llamathena[0].balance, false]
|
|
324
|
+
})
|
|
325
|
+
};
|
|
326
|
+
const removeLiquidityCall = {
|
|
327
|
+
target: curvePoolAdapter.address,
|
|
328
|
+
callData: encodeFunctionData({
|
|
329
|
+
abi: iCurveV1_2AssetsAdapterAbi,
|
|
330
|
+
functionName: "remove_liquidity",
|
|
331
|
+
args: [preview.llamathena[0].balance, [0n, 0n]]
|
|
332
|
+
})
|
|
333
|
+
};
|
|
334
|
+
const compareBalances = {
|
|
335
|
+
target: cm.creditFacade.address,
|
|
336
|
+
callData: encodeFunctionData({
|
|
337
|
+
abi: cm.creditFacade.abi,
|
|
338
|
+
functionName: "compareBalances",
|
|
339
|
+
args: []
|
|
340
|
+
})
|
|
341
|
+
};
|
|
342
|
+
const swapCalls = [
|
|
343
|
+
storeExpectedBalances,
|
|
344
|
+
withdrawAndUnwrapCall,
|
|
345
|
+
removeLiquidityCall,
|
|
346
|
+
compareBalances
|
|
347
|
+
];
|
|
348
|
+
const calls = [
|
|
349
|
+
...priceUpdatesCalls,
|
|
350
|
+
...swapCalls,
|
|
351
|
+
...this.prepareUpdateQuotas(ca.creditFacade, {
|
|
352
|
+
minQuota,
|
|
353
|
+
averageQuota
|
|
354
|
+
})
|
|
355
|
+
];
|
|
356
|
+
const tx = cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
357
|
+
return { tx, calls, creditFacade: cm.creditFacade };
|
|
358
|
+
}
|
|
171
359
|
/**
|
|
172
360
|
* unwraps staked tokens and optionally claims associated rewards; Should be remove after transition to 3.1
|
|
173
361
|
* @param acc
|
|
@@ -189,6 +189,12 @@ class CreditAccountServiceV310 extends AbstractCreditAccountService {
|
|
|
189
189
|
const tx = cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
190
190
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
191
191
|
}
|
|
192
|
+
async previewWithdrawLlamathenaProportionally(_) {
|
|
193
|
+
throw new Error("Not implemented in v310");
|
|
194
|
+
}
|
|
195
|
+
async withdrawLlamathenaProportionally(_) {
|
|
196
|
+
throw new Error("Not implemented in v310");
|
|
197
|
+
}
|
|
192
198
|
}
|
|
193
199
|
export {
|
|
194
200
|
CreditAccountServiceV310
|
|
@@ -175,24 +175,29 @@ class TxUnstakeDiesel extends EVMTx {
|
|
|
175
175
|
class TXSwap extends EVMTx {
|
|
176
176
|
operation;
|
|
177
177
|
amountFrom;
|
|
178
|
-
amountTo;
|
|
179
178
|
tokenFrom;
|
|
180
|
-
|
|
179
|
+
to;
|
|
181
180
|
creditManagerName;
|
|
182
181
|
constructor(opts) {
|
|
183
182
|
super(opts);
|
|
184
183
|
this.operation = opts.operation;
|
|
185
184
|
this.amountFrom = opts.amountFrom;
|
|
186
|
-
this.amountTo = opts.amountTo;
|
|
187
185
|
this.tokenFrom = opts.tokensList[opts.tokenFrom];
|
|
188
|
-
|
|
186
|
+
const list = opts.to ? opts.to : opts.amountTo && opts.tokenTo ? [{ balance: opts.amountTo, token: opts.tokenTo }] : void 0;
|
|
187
|
+
this.to = list?.map(({ token, balance }) => ({
|
|
188
|
+
token: opts.tokensList[token],
|
|
189
|
+
balance
|
|
190
|
+
}));
|
|
189
191
|
this.creditManagerName = opts.creditManagerName;
|
|
190
192
|
}
|
|
191
193
|
_toString() {
|
|
192
194
|
let toPart = "";
|
|
193
|
-
if (this.
|
|
194
|
-
const {
|
|
195
|
-
|
|
195
|
+
if (this.to) {
|
|
196
|
+
const str = this.to.map(({ token, balance }) => {
|
|
197
|
+
const { title: tokenSymbol, decimals: tokenDecimals = 18 } = token;
|
|
198
|
+
return `${formatBN(balance, tokenDecimals)} ${tokenSymbol}`;
|
|
199
|
+
}).join(", ");
|
|
200
|
+
toPart = ` \u21D2 ${str}`;
|
|
196
201
|
}
|
|
197
202
|
const { title: fromSymbol, decimals: fromDecimals = 18 } = this.tokenFrom;
|
|
198
203
|
return `Credit Account ${this.creditManagerName}: ${this.operation} ${formatBN(this.amountFrom, fromDecimals)} ${fromSymbol} ${toPart}`;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { MultiCall } from "../types/transactions.js";
|
|
1
2
|
import { AbstractCreditAccountService } from "./AbstractCreditAccountsService.js";
|
|
2
|
-
import type { ClaimFarmRewardsProps, CreditAccountOperationResult, ICreditAccountsService, RepayAndLiquidateCreditAccountProps, RepayCreditAccountProps, SetBotProps, WithdrawCollateralProps } from "./types.js";
|
|
3
|
+
import type { ClaimFarmRewardsProps, CreditAccountOperationResult, ICreditAccountsService, LlamathenaProportionalWithdrawProps, PreviewWithdrawLlamathenaProportionallyProps, PreviewWithdrawLlamathenaProportionallyResult, RepayAndLiquidateCreditAccountProps, RepayCreditAccountProps, SetBotProps, WithdrawCollateralProps } from "./types.js";
|
|
3
4
|
export declare class CreditAccountServiceV300 extends AbstractCreditAccountService implements ICreditAccountsService {
|
|
4
5
|
#private;
|
|
5
6
|
/**
|
|
@@ -22,4 +23,10 @@ export declare class CreditAccountServiceV300 extends AbstractCreditAccountServi
|
|
|
22
23
|
* Implements {@link ICreditAccountsService.claimFarmRewards}
|
|
23
24
|
*/
|
|
24
25
|
claimFarmRewards({ tokensToDisable, calls: claimCalls, creditAccount: ca, minQuota, averageQuota, }: ClaimFarmRewardsProps): Promise<CreditAccountOperationResult>;
|
|
26
|
+
previewWithdrawLlamathenaProportionally({ llamathena, }: PreviewWithdrawLlamathenaProportionallyProps): Promise<PreviewWithdrawLlamathenaProportionallyResult>;
|
|
27
|
+
withdrawLlamathenaProportionally({ preview, creditAccount: ca, minQuota, averageQuota, }: LlamathenaProportionalWithdrawProps): Promise<{
|
|
28
|
+
tx: import("../index.js").RawTx;
|
|
29
|
+
calls: MultiCall[];
|
|
30
|
+
creditFacade: import("../index.js").CreditFacadeContract;
|
|
31
|
+
}>;
|
|
25
32
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbstractCreditAccountService } from "./AbstractCreditAccountsService.js";
|
|
2
|
-
import type { ClaimFarmRewardsProps, CreditAccountOperationResult, CreditManagerOperationResult, ICreditAccountsService, RepayAndLiquidateCreditAccountProps, RepayCreditAccountProps, SetBotProps, WithdrawCollateralProps } from "./types.js";
|
|
2
|
+
import type { ClaimFarmRewardsProps, CreditAccountOperationResult, CreditManagerOperationResult, ICreditAccountsService, LlamathenaProportionalWithdrawProps, PreviewWithdrawLlamathenaProportionallyProps, PreviewWithdrawLlamathenaProportionallyResult, RepayAndLiquidateCreditAccountProps, RepayCreditAccountProps, SetBotProps, WithdrawCollateralProps } from "./types.js";
|
|
3
3
|
export declare class CreditAccountServiceV310 extends AbstractCreditAccountService implements ICreditAccountsService {
|
|
4
4
|
/**
|
|
5
5
|
* Implements {@link ICreditAccountsService.setBot}
|
|
@@ -21,4 +21,6 @@ export declare class CreditAccountServiceV310 extends AbstractCreditAccountServi
|
|
|
21
21
|
* Implements {@link ICreditAccountsService.claimFarmRewards}
|
|
22
22
|
*/
|
|
23
23
|
claimFarmRewards({ calls: legacyCalls, creditAccount: ca, minQuota, averageQuota, tokensToClaim, forceCalls, }: ClaimFarmRewardsProps): Promise<CreditAccountOperationResult>;
|
|
24
|
+
previewWithdrawLlamathenaProportionally(_: PreviewWithdrawLlamathenaProportionallyProps): Promise<PreviewWithdrawLlamathenaProportionallyResult>;
|
|
25
|
+
withdrawLlamathenaProportionally(_: LlamathenaProportionalWithdrawProps): Promise<CreditAccountOperationResult>;
|
|
24
26
|
}
|
|
@@ -411,6 +411,45 @@ export type GetConnectedMigrationBotsResult = {
|
|
|
411
411
|
})[];
|
|
412
412
|
botAddress: Address;
|
|
413
413
|
} | undefined;
|
|
414
|
+
export interface PreviewWithdrawLlamathenaProportionallyProps {
|
|
415
|
+
llamathena: Asset;
|
|
416
|
+
}
|
|
417
|
+
export interface PreviewWithdrawLlamathenaProportionallyResult {
|
|
418
|
+
/**
|
|
419
|
+
* Assets to get
|
|
420
|
+
*/
|
|
421
|
+
assets: Array<Asset>;
|
|
422
|
+
/**
|
|
423
|
+
* Address of SCRVUSD token
|
|
424
|
+
*/
|
|
425
|
+
scrvusdAddress: Address;
|
|
426
|
+
/**
|
|
427
|
+
* Address of SUSDE token
|
|
428
|
+
*/
|
|
429
|
+
susdeAddress: Address;
|
|
430
|
+
/**
|
|
431
|
+
* Llamathena asset
|
|
432
|
+
*/
|
|
433
|
+
llamathena: [Asset];
|
|
434
|
+
/**
|
|
435
|
+
* Amount of SCRVUSD to get
|
|
436
|
+
*/
|
|
437
|
+
scrvusdDelta: bigint;
|
|
438
|
+
/**
|
|
439
|
+
* Amount of SUSDE to get
|
|
440
|
+
*/
|
|
441
|
+
susdeDelta: bigint;
|
|
442
|
+
}
|
|
443
|
+
export interface LlamathenaProportionalWithdrawProps extends PrepareUpdateQuotasProps {
|
|
444
|
+
/**
|
|
445
|
+
* Preview of the withdrawal
|
|
446
|
+
*/
|
|
447
|
+
preview: PreviewWithdrawLlamathenaProportionallyResult;
|
|
448
|
+
/**
|
|
449
|
+
* minimal credit account data on which operation is performed on which operation is performed
|
|
450
|
+
*/
|
|
451
|
+
creditAccount: RouterCASlice;
|
|
452
|
+
}
|
|
414
453
|
export interface ICreditAccountsService extends Construct {
|
|
415
454
|
sdk: GearboxSDK;
|
|
416
455
|
/**
|
|
@@ -611,5 +650,7 @@ export interface ICreditAccountsService extends Construct {
|
|
|
611
650
|
* @return All necessary data to execute the transaction (call, credit facade)
|
|
612
651
|
*/
|
|
613
652
|
claimFarmRewards(props: ClaimFarmRewardsProps): Promise<CreditAccountOperationResult>;
|
|
653
|
+
previewWithdrawLlamathenaProportionally(props: PreviewWithdrawLlamathenaProportionallyProps): Promise<PreviewWithdrawLlamathenaProportionallyResult>;
|
|
654
|
+
withdrawLlamathenaProportionally(props: LlamathenaProportionalWithdrawProps): Promise<CreditAccountOperationResult>;
|
|
614
655
|
}
|
|
615
656
|
export {};
|
|
@@ -68,18 +68,21 @@ export declare class TxUnstakeDiesel extends EVMTx {
|
|
|
68
68
|
interface SwapProps extends EVMTxProps {
|
|
69
69
|
operation: string;
|
|
70
70
|
amountFrom: bigint;
|
|
71
|
-
amountTo?: bigint;
|
|
72
71
|
tokenFrom: Address;
|
|
72
|
+
amountTo?: bigint;
|
|
73
73
|
tokenTo?: Address;
|
|
74
|
+
to?: Array<Asset>;
|
|
74
75
|
creditManagerName: string;
|
|
75
76
|
tokensList: Record<Address, TokenData>;
|
|
76
77
|
}
|
|
77
78
|
export declare class TXSwap extends EVMTx {
|
|
78
79
|
readonly operation: string;
|
|
79
80
|
readonly amountFrom: bigint;
|
|
80
|
-
readonly amountTo?: bigint;
|
|
81
81
|
readonly tokenFrom: TokenData;
|
|
82
|
-
readonly
|
|
82
|
+
readonly to?: Array<{
|
|
83
|
+
balance: bigint;
|
|
84
|
+
token: TokenData;
|
|
85
|
+
}>;
|
|
83
86
|
readonly creditManagerName: string;
|
|
84
87
|
constructor(opts: SwapProps);
|
|
85
88
|
_toString(): string;
|