@gearbox-protocol/sdk 12.6.0-next.5 → 12.6.1

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.
@@ -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;
@@ -79,7 +79,7 @@ class AdaptersPlugin extends import_sdk.BasePlugin {
79
79
  return new import_InfinifiUnwindingGatewayAdapterContract.InfinifiUnwindingGatewayAdapterContract(this.sdk, args);
80
80
  case "ADAPTER::INFRARED_VAULT":
81
81
  return new import_contracts.InfraredVaultAdapterContract(this.sdk, args);
82
- case "ADAPTER::KELP_DEPOSIT_POOL_POOL":
82
+ case "ADAPTER::KELP_DEPOSIT_POOL":
83
83
  return new import_contracts.KelpLRTDepositPoolAdapterContract(this.sdk, args);
84
84
  case "ADAPTER::KELP_WITHDRAWAL":
85
85
  return new import_contracts.KelpLRTWithdrawalManagerAdapterContract(this.sdk, args);
@@ -315,7 +315,7 @@ class GearboxSDK extends import_base.ChainContractsRegister {
315
315
  stateHuman(raw = true) {
316
316
  return {
317
317
  block: Number(this.currentBlock),
318
- timestamp: Number(this.timestamp),
318
+ timestamp: (0, import_utils.formatTimestamp)(Number(this.timestamp), raw),
319
319
  core: {
320
320
  addressProviderV3: this.addressProvider.stateHuman(raw),
321
321
  botList: this.botListContract?.stateHuman(raw),
@@ -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
- tokenTo;
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
- this.tokenTo = opts.tokenTo ? opts.tokensList[opts.tokenTo] : void 0;
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.tokenTo && this.amountTo) {
244
- const { title: toSymbol, decimals: toDecimals = 18 } = this.tokenTo;
245
- toPart = ` \u21D2 ${(0, import_utils.formatBN)(this.amountTo, toDecimals)} ${toSymbol}`;
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}`;
@@ -122,11 +122,12 @@ function formatDuration(seconds, raw = true) {
122
122
  function formatNumberToString_(value) {
123
123
  return value.toLocaleString("en-US", { minimumIntegerDigits: 1, useGrouping: true }).replaceAll(",", "_");
124
124
  }
125
- function formatTimestamp(timestamp) {
126
- return new Date(timestamp * 1e3).toLocaleString("en-GB", {
125
+ function formatTimestamp(timestamp, raw = true) {
126
+ const result = new Date(timestamp * 1e3).toLocaleString("en-GB", {
127
127
  dateStyle: "short",
128
128
  timeStyle: "short"
129
129
  });
130
+ return raw ? `${result} [${timestamp}]` : result;
130
131
  }
131
132
  // Annotate the CommonJS export names for ESM import in node:
132
133
  0 && (module.exports = {
@@ -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;
@@ -97,7 +97,7 @@ class AdaptersPlugin extends BasePlugin {
97
97
  return new InfinifiUnwindingGatewayAdapterContract(this.sdk, args);
98
98
  case "ADAPTER::INFRARED_VAULT":
99
99
  return new InfraredVaultAdapterContract(this.sdk, args);
100
- case "ADAPTER::KELP_DEPOSIT_POOL_POOL":
100
+ case "ADAPTER::KELP_DEPOSIT_POOL":
101
101
  return new KelpLRTDepositPoolAdapterContract(this.sdk, args);
102
102
  case "ADAPTER::KELP_WITHDRAWAL":
103
103
  return new KelpLRTWithdrawalManagerAdapterContract(this.sdk, args);
@@ -30,7 +30,7 @@ import {
30
30
  PluginStateVersionError
31
31
  } from "./plugins/index.js";
32
32
  import { createRouter } from "./router/index.js";
33
- import { TypedObjectUtils, toAddress } from "./utils/index.js";
33
+ import { formatTimestamp, TypedObjectUtils, toAddress } from "./utils/index.js";
34
34
  import { Hooks } from "./utils/internal/index.js";
35
35
  import { getLogsSafe } from "./utils/viem/index.js";
36
36
  const ERR_NOT_ATTACHED = new Error("Gearbox SDK not attached");
@@ -314,7 +314,7 @@ class GearboxSDK extends ChainContractsRegister {
314
314
  stateHuman(raw = true) {
315
315
  return {
316
316
  block: Number(this.currentBlock),
317
- timestamp: Number(this.timestamp),
317
+ timestamp: formatTimestamp(Number(this.timestamp), raw),
318
318
  core: {
319
319
  addressProviderV3: this.addressProvider.stateHuman(raw),
320
320
  botList: this.botListContract?.stateHuman(raw),
@@ -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
- tokenTo;
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
- this.tokenTo = opts.tokenTo ? opts.tokensList[opts.tokenTo] : void 0;
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.tokenTo && this.amountTo) {
194
- const { title: toSymbol, decimals: toDecimals = 18 } = this.tokenTo;
195
- toPart = ` \u21D2 ${formatBN(this.amountTo, toDecimals)} ${toSymbol}`;
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}`;
@@ -91,11 +91,12 @@ function formatDuration(seconds, raw = true) {
91
91
  function formatNumberToString_(value) {
92
92
  return value.toLocaleString("en-US", { minimumIntegerDigits: 1, useGrouping: true }).replaceAll(",", "_");
93
93
  }
94
- function formatTimestamp(timestamp) {
95
- return new Date(timestamp * 1e3).toLocaleString("en-GB", {
94
+ function formatTimestamp(timestamp, raw = true) {
95
+ const result = new Date(timestamp * 1e3).toLocaleString("en-GB", {
96
96
  dateStyle: "short",
97
97
  timeStyle: "short"
98
98
  });
99
+ return raw ? `${result} [${timestamp}]` : result;
99
100
  }
100
101
  export {
101
102
  fmtBinaryMask,
@@ -29,4 +29,5 @@ export interface Deployment {
29
29
  }
30
30
  export interface DeploymentExtended extends Deployment {
31
31
  bytecodeHash: Hex;
32
+ constructorParams?: Hex;
32
33
  }
@@ -1,7 +1,7 @@
1
1
  import type { AbiParameter } from "viem";
2
2
  export type VersionedAbi = Record<number, readonly AbiParameter[]>;
3
3
  export type AdapterContractTypeLegacy = "AD_AAVE_V3_LENDING_POOL" | "AD_BALANCER_VAULT" | "AD_CAMELOT_V3_ROUTER" | "AD_CONVEX_L2_BOOSTER" | "AD_CONVEX_L2_REWARD_POOL" | "AD_CONVEX_V1_BASE_REWARD_POOL" | "AD_CONVEX_V1_BOOSTER" | "AD_CURVE_STABLE_NG" | "AD_CURVE_V1_2ASSETS" | "AD_CURVE_V1_3ASSETS" | "AD_CURVE_V1_4ASSETS" | "AD_CURVE_V1_EXCHANGE_ONLY" | "AD_CURVE_V1_STECRV_POOL" | "AD_CURVE_V1_WRAPPER" | "AD_DAI_USDS_EXCHANGE" | "AD_EQUALIZER_ROUTER" | "AD_ERC4626_VAULT" | "AD_LIDO_V1" | "AD_LIDO_WSTETH_V1" | "AD_MELLOW_ERC4626_VAULT" | "AD_MELLOW_LRT_VAULT" | "AD_PENDLE_ROUTER" | "AD_STAKING_REWARDS" | "AD_SYMBIOTIC_DEFAULT_COLLATERAL" | "AD_UNISWAP_V2_ROUTER" | "AD_UNISWAP_V3_ROUTER" | "AD_VELODROME_V2_ROUTER" | "AD_YEARN_V2" | "AD_ZIRCUIT_POOL";
4
- export type AdapterContractType = "ADAPTER::ACCOUNT_MIGRATOR" | "ADAPTER::BALANCER_V3_ROUTER" | "ADAPTER::BALANCER_V3_WRAPPER" | "ADAPTER::BALANCER_VAULT" | "ADAPTER::CAMELOT_V3_ROUTER" | "ADAPTER::CURVE_STABLE_NG" | "ADAPTER::CURVE_V1_2ASSETS" | "ADAPTER::CURVE_V1_3ASSETS" | "ADAPTER::CURVE_V1_4ASSETS" | "ADAPTER::CURVE_V1_STECRV_POOL" | "ADAPTER::CURVE_V1_WRAPPER" | "ADAPTER::CVX_V1_BASE_REWARD_POOL" | "ADAPTER::CVX_V1_BOOSTER" | "ADAPTER::DAI_USDS_EXCHANGE" | "ADAPTER::EQUALIZER_ROUTER" | "ADAPTER::ERC4626_VAULT" | "ADAPTER::ERC4626_VAULT_REFERRAL" | "ADAPTER::FLUID_DEX" | "ADAPTER::INFINIFI_GATEWAY" | "ADAPTER::INFINIFI_UNWINDING" | "ADAPTER::INFRARED_VAULT" | "ADAPTER::KELP_DEPOSIT_POOL_POOL" | "ADAPTER::KELP_WITHDRAWAL" | "ADAPTER::KODIAK_ISLAND_GATEWAY" | "ADAPTER::LIDO_V1" | "ADAPTER::LIDO_WSTETH_V1" | "ADAPTER::MELLOW_CLAIMER" | "ADAPTER::MELLOW_DVV" | "ADAPTER::MELLOW_ERC4626_VAULT" | "ADAPTER::MELLOW_LRT_VAULT" | "ADAPTER::MELLOW_WRAPPER" | "ADAPTER::MELLOW_DEPOSIT_QUEUE_QUEUE" | "ADAPTER::MELLOW_REDEEM_QUEUE_QUEUE" | "ADAPTER::MIDAS_ISSUANCE_VAULT" | "ADAPTER::MIDAS_REDEMPTION_VAULT" | "ADAPTER::PENDLE_ROUTER" | "ADAPTER::STAKING_REWARDS" | "ADAPTER::TRADERJOE_ROUTER" | "ADAPTER::UNISWAP_V2_ROUTER" | "ADAPTER::UNISWAP_V3_ROUTER" | "ADAPTER::UNISWAP_V4_GATEWAY" | "ADAPTER::UPSHIFT_VAULT" | "ADAPTER::VELODROME_V2_ROUTER" | "ADAPTER::YEARN_V2";
4
+ export type AdapterContractType = "ADAPTER::ACCOUNT_MIGRATOR" | "ADAPTER::BALANCER_V3_ROUTER" | "ADAPTER::BALANCER_V3_WRAPPER" | "ADAPTER::BALANCER_VAULT" | "ADAPTER::CAMELOT_V3_ROUTER" | "ADAPTER::CURVE_STABLE_NG" | "ADAPTER::CURVE_V1_2ASSETS" | "ADAPTER::CURVE_V1_3ASSETS" | "ADAPTER::CURVE_V1_4ASSETS" | "ADAPTER::CURVE_V1_STECRV_POOL" | "ADAPTER::CURVE_V1_WRAPPER" | "ADAPTER::CVX_V1_BASE_REWARD_POOL" | "ADAPTER::CVX_V1_BOOSTER" | "ADAPTER::DAI_USDS_EXCHANGE" | "ADAPTER::EQUALIZER_ROUTER" | "ADAPTER::ERC4626_VAULT" | "ADAPTER::ERC4626_VAULT_REFERRAL" | "ADAPTER::FLUID_DEX" | "ADAPTER::INFINIFI_GATEWAY" | "ADAPTER::INFINIFI_UNWINDING" | "ADAPTER::INFRARED_VAULT" | "ADAPTER::KELP_DEPOSIT_POOL" | "ADAPTER::KELP_WITHDRAWAL" | "ADAPTER::KODIAK_ISLAND_GATEWAY" | "ADAPTER::LIDO_V1" | "ADAPTER::LIDO_WSTETH_V1" | "ADAPTER::MELLOW_CLAIMER" | "ADAPTER::MELLOW_DVV" | "ADAPTER::MELLOW_ERC4626_VAULT" | "ADAPTER::MELLOW_LRT_VAULT" | "ADAPTER::MELLOW_WRAPPER" | "ADAPTER::MELLOW_DEPOSIT_QUEUE_QUEUE" | "ADAPTER::MELLOW_REDEEM_QUEUE_QUEUE" | "ADAPTER::MIDAS_ISSUANCE_VAULT" | "ADAPTER::MIDAS_REDEMPTION_VAULT" | "ADAPTER::PENDLE_ROUTER" | "ADAPTER::STAKING_REWARDS" | "ADAPTER::TRADERJOE_ROUTER" | "ADAPTER::UNISWAP_V2_ROUTER" | "ADAPTER::UNISWAP_V3_ROUTER" | "ADAPTER::UNISWAP_V4_GATEWAY" | "ADAPTER::UPSHIFT_VAULT" | "ADAPTER::VELODROME_V2_ROUTER" | "ADAPTER::YEARN_V2";
5
5
  export declare enum AdapterType {
6
6
  ACCOUNT_MIGRATOR = "ACCOUNT_MIGRATOR",
7
7
  BALANCER_V3_ROUTER = "BALANCER_V3_ROUTER",
@@ -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 tokenTo?: TokenData;
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;
@@ -196,7 +196,7 @@ export interface MarketStateHuman {
196
196
  }
197
197
  export interface GearboxStateHuman {
198
198
  block: number;
199
- timestamp: number;
199
+ timestamp: string;
200
200
  core: CoreStateHuman;
201
201
  markets: MarketStateHuman[];
202
202
  plugins: Record<string, unknown>;
@@ -9,4 +9,4 @@ export declare function fmtBinaryMask(mask: bigint): string;
9
9
  export declare function numberWithCommas(x: number | bigint): string;
10
10
  export declare function formatDuration(seconds: number, raw?: boolean): string;
11
11
  export declare function formatNumberToString_(value: bigint | number): string;
12
- export declare function formatTimestamp(timestamp: number): string;
12
+ export declare function formatTimestamp(timestamp: number, raw?: boolean): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "12.6.0-next.5",
3
+ "version": "12.6.1",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",
@@ -63,25 +63,25 @@
63
63
  "date-fns": "^4.1.0",
64
64
  "decimal.js-light": "^2.5.1",
65
65
  "viem": ">=2.23.15 <3.0.0",
66
- "zod": "^4.3.5"
66
+ "zod": "^4.3.6"
67
67
  },
68
68
  "devDependencies": {
69
- "@biomejs/biome": "^2.3.11",
70
- "@commitlint/cli": "^20.3.0",
71
- "@commitlint/config-conventional": "^20.3.0",
72
- "@gearbox-protocol/biome-config": "^1.0.17",
69
+ "@biomejs/biome": "^2.3.13",
70
+ "@commitlint/cli": "^20.3.1",
71
+ "@commitlint/config-conventional": "^20.3.1",
72
+ "@gearbox-protocol/biome-config": "^1.0.19",
73
73
  "@types/cross-spawn": "^6.0.6",
74
- "axios": "^1.13.2",
74
+ "axios": "^1.13.3",
75
75
  "cross-spawn": "^7.0.6",
76
76
  "husky": "^9.1.7",
77
77
  "lint-staged": "^16.2.7",
78
- "pino": "^10.1.0",
78
+ "pino": "^10.3.0",
79
79
  "pino-pretty": "^13.1.3",
80
80
  "tsup": "^8.5.1",
81
81
  "tsx": "^4.21.0",
82
82
  "typescript": "^5.9.3",
83
83
  "viem-deal": "^2.0.4",
84
- "vitest": "^4.0.16"
84
+ "vitest": "^4.0.18"
85
85
  },
86
86
  "peerDependencies": {
87
87
  "axios": "^1.0.0",