@strkfarm/sdk 2.0.0-dev.4 → 2.0.0-dev.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.global.js +391 -156
- package/dist/index.browser.mjs +391 -156
- package/dist/index.js +391 -156
- package/dist/index.mjs +391 -156
- package/package.json +1 -1
- package/src/strategies/universal-adapters/extended-adapter.ts +1 -0
- package/src/strategies/universal-adapters/vesu-multiply-adapter.ts +775 -395
- package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +1 -1
package/dist/index.mjs
CHANGED
|
@@ -28284,21 +28284,35 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28284
28284
|
vaultAllocator: config.vaultAllocator,
|
|
28285
28285
|
id: ""
|
|
28286
28286
|
});
|
|
28287
|
-
this.tokenMarketData = new TokenMarketData(
|
|
28287
|
+
this.tokenMarketData = new TokenMarketData(
|
|
28288
|
+
this.config.pricer,
|
|
28289
|
+
this.config.networkConfig
|
|
28290
|
+
);
|
|
28288
28291
|
}
|
|
28289
28292
|
async getAPY(supportedPosition) {
|
|
28290
28293
|
const CACHE_KEY = `apy_${this.config.poolId.address}_${supportedPosition.asset.symbol}`;
|
|
28291
28294
|
const cacheData = this.getCache(CACHE_KEY);
|
|
28292
|
-
console.log(
|
|
28295
|
+
console.log(
|
|
28296
|
+
`${_VesuMultiplyAdapter.name}::getAPY cacheData: ${JSON.stringify(
|
|
28297
|
+
cacheData
|
|
28298
|
+
)}`,
|
|
28299
|
+
this.vesuAdapter.config.poolId.shortString(),
|
|
28300
|
+
this.vesuAdapter.config.collateral.symbol,
|
|
28301
|
+
this.vesuAdapter.config.debt.symbol
|
|
28302
|
+
);
|
|
28293
28303
|
if (cacheData) {
|
|
28294
28304
|
return cacheData;
|
|
28295
28305
|
}
|
|
28296
28306
|
try {
|
|
28297
28307
|
const allVesuPools = await VesuAdapter.getVesuPools();
|
|
28298
28308
|
const asset = supportedPosition.asset;
|
|
28299
|
-
const pool = allVesuPools.pools.find(
|
|
28309
|
+
const pool = allVesuPools.pools.find(
|
|
28310
|
+
(p) => this.vesuAdapter.config.poolId.eqString(num9.getHexString(p.id))
|
|
28311
|
+
);
|
|
28300
28312
|
if (!pool) {
|
|
28301
|
-
logger.warn(
|
|
28313
|
+
logger.warn(
|
|
28314
|
+
`VesuMultiplyAdapter: Pool not found for token ${asset.symbol}`
|
|
28315
|
+
);
|
|
28302
28316
|
return {
|
|
28303
28317
|
apy: 0,
|
|
28304
28318
|
type: "base" /* BASE */
|
|
@@ -28308,7 +28322,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28308
28322
|
(a) => a.symbol.toLowerCase() === asset.symbol.toLowerCase()
|
|
28309
28323
|
)?.stats;
|
|
28310
28324
|
if (!assetStats) {
|
|
28311
|
-
logger.warn(
|
|
28325
|
+
logger.warn(
|
|
28326
|
+
`VesuMultiplyAdapter: Asset stats not found for token ${asset.symbol}`
|
|
28327
|
+
);
|
|
28312
28328
|
return {
|
|
28313
28329
|
apy: 0,
|
|
28314
28330
|
type: "base" /* BASE */
|
|
@@ -28319,7 +28335,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28319
28335
|
apy = Number(assetStats.borrowApr?.value || 0) / 1e18;
|
|
28320
28336
|
} else {
|
|
28321
28337
|
const isAssetBTC = asset.symbol.toLowerCase().includes("btc");
|
|
28322
|
-
const baseAPY = Number(
|
|
28338
|
+
const baseAPY = Number(
|
|
28339
|
+
isAssetBTC ? assetStats.btcFiSupplyApr?.value + assetStats.supplyApy?.value : assetStats.supplyApy?.value || 0
|
|
28340
|
+
) / 1e18;
|
|
28323
28341
|
const rewardAPY = Number(assetStats.defiSpringSupplyApr?.value || "0") / 1e18;
|
|
28324
28342
|
const isSupported = this.tokenMarketData.isAPYSupported(asset);
|
|
28325
28343
|
apy = baseAPY + rewardAPY;
|
|
@@ -28335,7 +28353,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28335
28353
|
this.setCache(CACHE_KEY, result, 3e5);
|
|
28336
28354
|
return result;
|
|
28337
28355
|
} catch (error) {
|
|
28338
|
-
logger.error(
|
|
28356
|
+
logger.error(
|
|
28357
|
+
`VesuMultiplyAdapter: Error getting APY for ${supportedPosition.asset.symbol}:`,
|
|
28358
|
+
error
|
|
28359
|
+
);
|
|
28339
28360
|
throw error;
|
|
28340
28361
|
}
|
|
28341
28362
|
}
|
|
@@ -28348,12 +28369,16 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28348
28369
|
try {
|
|
28349
28370
|
this.vesuAdapter.networkConfig = this.config.networkConfig;
|
|
28350
28371
|
this.vesuAdapter.pricer = this.config.pricer;
|
|
28351
|
-
const positions = await this.vesuAdapter.getPositions(
|
|
28372
|
+
const positions = await this.vesuAdapter.getPositions(
|
|
28373
|
+
this.config.networkConfig
|
|
28374
|
+
);
|
|
28352
28375
|
let position = positions.find(
|
|
28353
28376
|
(p) => p.token.address.eq(supportedPosition.asset.address)
|
|
28354
28377
|
);
|
|
28355
28378
|
if (!position) {
|
|
28356
|
-
logger.warn(
|
|
28379
|
+
logger.warn(
|
|
28380
|
+
`VesuMultiplyAdapter: Position not found for token ${supportedPosition.asset.symbol}`
|
|
28381
|
+
);
|
|
28357
28382
|
return {
|
|
28358
28383
|
amount: new Web3Number("0", supportedPosition.asset.decimals),
|
|
28359
28384
|
remarks: "Position not found"
|
|
@@ -28366,12 +28391,18 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28366
28391
|
this.setCache(CACHE_KEY, position, 6e4);
|
|
28367
28392
|
return position;
|
|
28368
28393
|
} catch (error) {
|
|
28369
|
-
logger.error(
|
|
28394
|
+
logger.error(
|
|
28395
|
+
`VesuMultiplyAdapter: Error getting position for ${supportedPosition.asset.symbol}:`,
|
|
28396
|
+
error
|
|
28397
|
+
);
|
|
28370
28398
|
throw error;
|
|
28371
28399
|
}
|
|
28372
28400
|
}
|
|
28373
28401
|
async maxBorrowableAPY() {
|
|
28374
|
-
const collateralAPY = await this.getAPY({
|
|
28402
|
+
const collateralAPY = await this.getAPY({
|
|
28403
|
+
asset: this.config.collateral,
|
|
28404
|
+
isDebt: false
|
|
28405
|
+
});
|
|
28375
28406
|
const apy = collateralAPY.apy * 0.8;
|
|
28376
28407
|
return apy;
|
|
28377
28408
|
}
|
|
@@ -28381,9 +28412,15 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28381
28412
|
try {
|
|
28382
28413
|
this.vesuAdapter.networkConfig = this.config.networkConfig;
|
|
28383
28414
|
this.vesuAdapter.pricer = this.config.pricer;
|
|
28384
|
-
const positions = await this.vesuAdapter.getPositions(
|
|
28385
|
-
|
|
28386
|
-
|
|
28415
|
+
const positions = await this.vesuAdapter.getPositions(
|
|
28416
|
+
this.config.networkConfig
|
|
28417
|
+
);
|
|
28418
|
+
const collateralPosition = positions.find(
|
|
28419
|
+
(p) => p.token.address.eq(collateral.address)
|
|
28420
|
+
);
|
|
28421
|
+
const debtPosition = positions.find(
|
|
28422
|
+
(p) => p.token.address.eq(debt.address)
|
|
28423
|
+
);
|
|
28387
28424
|
if (!collateralPosition || !debtPosition) {
|
|
28388
28425
|
throw new Error("Could not find current positions");
|
|
28389
28426
|
}
|
|
@@ -28393,13 +28430,23 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28393
28430
|
debt,
|
|
28394
28431
|
maxBorrowableAPY
|
|
28395
28432
|
);
|
|
28396
|
-
logger.verbose(
|
|
28397
|
-
|
|
28433
|
+
logger.verbose(
|
|
28434
|
+
`VesuMultiplyAdapter: Max borrowable: ${maxBorrowable.toNumber()}`
|
|
28435
|
+
);
|
|
28436
|
+
const debtCap = await this.vesuAdapter.getDebtCap(
|
|
28437
|
+
this.config.networkConfig
|
|
28438
|
+
);
|
|
28398
28439
|
logger.verbose(`VesuMultiplyAdapter: Debt cap: ${debtCap.toNumber()}`);
|
|
28399
28440
|
const actualMaxBorrowable = maxBorrowable.minimum(debtCap);
|
|
28400
|
-
logger.verbose(
|
|
28401
|
-
|
|
28402
|
-
|
|
28441
|
+
logger.verbose(
|
|
28442
|
+
`VesuMultiplyAdapter: Actual max borrowable: ${actualMaxBorrowable.toNumber()}`
|
|
28443
|
+
);
|
|
28444
|
+
const maxLTV = await this.vesuAdapter.getLTVConfig(
|
|
28445
|
+
this.config.networkConfig
|
|
28446
|
+
);
|
|
28447
|
+
const collateralPrice = await this.config.pricer.getPrice(
|
|
28448
|
+
collateral.symbol
|
|
28449
|
+
);
|
|
28403
28450
|
if (collateralPrice.price === 0) {
|
|
28404
28451
|
throw new Error("Collateral price is 0");
|
|
28405
28452
|
}
|
|
@@ -28417,14 +28464,25 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28417
28464
|
);
|
|
28418
28465
|
const maxDepositAmount = amount ? amount.minimum(maxCollateralFromDebt) : maxCollateralFromDebt;
|
|
28419
28466
|
const usdValue = await this.getUSDValue(collateral, maxDepositAmount);
|
|
28420
|
-
logger.verbose(
|
|
28421
|
-
|
|
28422
|
-
|
|
28467
|
+
logger.verbose(
|
|
28468
|
+
`VesuMultiplyAdapter: Max deposit::USD value: ${usdValue}, amount: ${maxDepositAmount.toNumber()}`
|
|
28469
|
+
);
|
|
28470
|
+
const apys = await Promise.all([
|
|
28471
|
+
this.getAPY({ asset: collateral, isDebt: false }),
|
|
28472
|
+
this.getAPY({ asset: debt, isDebt: true })
|
|
28473
|
+
]);
|
|
28474
|
+
logger.verbose(
|
|
28475
|
+
`VesuMultiplyAdapter: Apys: ${apys[0].apy}, ${apys[1].apy}`
|
|
28476
|
+
);
|
|
28423
28477
|
const borrowAmountUSD = actualMaxBorrowable.multipliedBy(debtPrice.price);
|
|
28424
|
-
logger.verbose(
|
|
28478
|
+
logger.verbose(
|
|
28479
|
+
`VesuMultiplyAdapter: Borrow amount: ${actualMaxBorrowable.toNumber()}, borrow amount USD: ${borrowAmountUSD.toNumber()}`
|
|
28480
|
+
);
|
|
28425
28481
|
const netCollateralUSD = usdValue + borrowAmountUSD.toNumber();
|
|
28426
28482
|
const netAPY = (apys[0].apy * netCollateralUSD + apys[1].apy * borrowAmountUSD.toNumber()) / usdValue;
|
|
28427
|
-
logger.verbose(
|
|
28483
|
+
logger.verbose(
|
|
28484
|
+
`VesuMultiplyAdapter: Max deposit amount: ${maxDepositAmount.toNumber()}, netAPY: ${netAPY}`
|
|
28485
|
+
);
|
|
28428
28486
|
return {
|
|
28429
28487
|
tokenInfo: collateral,
|
|
28430
28488
|
amount: maxDepositAmount,
|
|
@@ -28437,7 +28495,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28437
28495
|
protocol: this.protocol
|
|
28438
28496
|
};
|
|
28439
28497
|
} catch (error) {
|
|
28440
|
-
logger.error(
|
|
28498
|
+
logger.error(
|
|
28499
|
+
`VesuMultiplyAdapter: Error calculating max deposit:`,
|
|
28500
|
+
error
|
|
28501
|
+
);
|
|
28441
28502
|
throw error;
|
|
28442
28503
|
}
|
|
28443
28504
|
}
|
|
@@ -28447,9 +28508,15 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28447
28508
|
try {
|
|
28448
28509
|
this.vesuAdapter.networkConfig = this.config.networkConfig;
|
|
28449
28510
|
this.vesuAdapter.pricer = this.config.pricer;
|
|
28450
|
-
const positions = await this.vesuAdapter.getPositions(
|
|
28451
|
-
|
|
28452
|
-
|
|
28511
|
+
const positions = await this.vesuAdapter.getPositions(
|
|
28512
|
+
this.config.networkConfig
|
|
28513
|
+
);
|
|
28514
|
+
const collateralPosition = positions.find(
|
|
28515
|
+
(p) => p.token.address.eq(collateral.address)
|
|
28516
|
+
);
|
|
28517
|
+
const debtPosition = positions.find(
|
|
28518
|
+
(p) => p.token.address.eq(this.config.debt.address)
|
|
28519
|
+
);
|
|
28453
28520
|
if (!collateralPosition || !debtPosition) {
|
|
28454
28521
|
throw new Error("Could not find current positions");
|
|
28455
28522
|
}
|
|
@@ -28459,11 +28526,20 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28459
28526
|
const result = maxWithdrawable.greaterThan(0) ? maxWithdrawable : new Web3Number("0", collateral.decimals);
|
|
28460
28527
|
const usdValue = await this.getUSDValue(collateral, result);
|
|
28461
28528
|
const debtUSD = debtPosition.usdValue;
|
|
28462
|
-
logger.verbose(
|
|
28463
|
-
|
|
28464
|
-
|
|
28529
|
+
logger.verbose(
|
|
28530
|
+
`VesuMultiplyAdapter: Debt USD: ${debtUSD}, collateral USD: ${usdValue}`
|
|
28531
|
+
);
|
|
28532
|
+
const apys = await Promise.all([
|
|
28533
|
+
this.getAPY({ asset: collateral, isDebt: false }),
|
|
28534
|
+
this.getAPY({ asset: debt, isDebt: true })
|
|
28535
|
+
]);
|
|
28536
|
+
logger.verbose(
|
|
28537
|
+
`VesuMultiplyAdapter: Apys: ${apys[0].apy}, ${apys[1].apy}`
|
|
28538
|
+
);
|
|
28465
28539
|
const netAPY = usdValue - debtUSD > 0 ? (apys[0].apy * usdValue + apys[1].apy * debtUSD) / (usdValue - debtUSD) : 0;
|
|
28466
|
-
logger.verbose(
|
|
28540
|
+
logger.verbose(
|
|
28541
|
+
`VesuMultiplyAdapter: Max withdraw amount: ${result.toNumber()}, netAPY: ${netAPY}`
|
|
28542
|
+
);
|
|
28467
28543
|
return {
|
|
28468
28544
|
tokenInfo: collateral,
|
|
28469
28545
|
amount: result,
|
|
@@ -28476,14 +28552,19 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28476
28552
|
protocol: this.protocol
|
|
28477
28553
|
};
|
|
28478
28554
|
} catch (error) {
|
|
28479
|
-
logger.error(
|
|
28555
|
+
logger.error(
|
|
28556
|
+
`VesuMultiplyAdapter: Error calculating max withdraw:`,
|
|
28557
|
+
error
|
|
28558
|
+
);
|
|
28480
28559
|
throw error;
|
|
28481
28560
|
}
|
|
28482
28561
|
}
|
|
28483
28562
|
_getDepositLeaf() {
|
|
28484
28563
|
const collateral = this.config.collateral;
|
|
28485
28564
|
const debt = this.config.debt;
|
|
28486
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28565
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28566
|
+
this.config.poolId
|
|
28567
|
+
);
|
|
28487
28568
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
28488
28569
|
return [
|
|
28489
28570
|
// Approval step for collateral
|
|
@@ -28547,7 +28628,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28547
28628
|
];
|
|
28548
28629
|
}
|
|
28549
28630
|
_getWithdrawLeaf() {
|
|
28550
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28631
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28632
|
+
this.config.poolId
|
|
28633
|
+
);
|
|
28551
28634
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
28552
28635
|
const collateral = this.config.collateral;
|
|
28553
28636
|
const debt = this.config.debt;
|
|
@@ -28604,33 +28687,51 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28604
28687
|
const leafConfigs = this._getDepositLeaf();
|
|
28605
28688
|
const leaves = leafConfigs.map((config) => {
|
|
28606
28689
|
const { target, method, packedArguments, sanitizer, id } = config;
|
|
28607
|
-
const leaf = this.constructSimpleLeafData(
|
|
28608
|
-
|
|
28609
|
-
|
|
28610
|
-
|
|
28611
|
-
|
|
28612
|
-
|
|
28690
|
+
const leaf = this.constructSimpleLeafData(
|
|
28691
|
+
{
|
|
28692
|
+
id,
|
|
28693
|
+
target,
|
|
28694
|
+
method,
|
|
28695
|
+
packedArguments
|
|
28696
|
+
},
|
|
28697
|
+
sanitizer
|
|
28698
|
+
);
|
|
28613
28699
|
return leaf;
|
|
28614
28700
|
});
|
|
28615
|
-
return {
|
|
28701
|
+
return {
|
|
28702
|
+
leaves,
|
|
28703
|
+
callConstructor: this.getDepositCall.bind(
|
|
28704
|
+
this
|
|
28705
|
+
)
|
|
28706
|
+
};
|
|
28616
28707
|
}
|
|
28617
28708
|
getWithdrawAdapter() {
|
|
28618
28709
|
const leafConfigs = this._getWithdrawLeaf();
|
|
28619
28710
|
const leaves = leafConfigs.map((config) => {
|
|
28620
28711
|
const { target, method, packedArguments, sanitizer, id } = config;
|
|
28621
|
-
const leaf = this.constructSimpleLeafData(
|
|
28622
|
-
|
|
28623
|
-
|
|
28624
|
-
|
|
28625
|
-
|
|
28626
|
-
|
|
28712
|
+
const leaf = this.constructSimpleLeafData(
|
|
28713
|
+
{
|
|
28714
|
+
id,
|
|
28715
|
+
target,
|
|
28716
|
+
method,
|
|
28717
|
+
packedArguments
|
|
28718
|
+
},
|
|
28719
|
+
sanitizer
|
|
28720
|
+
);
|
|
28627
28721
|
return leaf;
|
|
28628
28722
|
});
|
|
28629
|
-
return {
|
|
28723
|
+
return {
|
|
28724
|
+
leaves,
|
|
28725
|
+
callConstructor: this.getWithdrawCall.bind(
|
|
28726
|
+
this
|
|
28727
|
+
)
|
|
28728
|
+
};
|
|
28630
28729
|
}
|
|
28631
28730
|
async getDepositCall(params) {
|
|
28632
28731
|
const collateral = this.config.collateral;
|
|
28633
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28732
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28733
|
+
this.config.poolId
|
|
28734
|
+
);
|
|
28634
28735
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
28635
28736
|
const uint256MarginAmount = uint25612.bnToUint256(params.amount.toWei());
|
|
28636
28737
|
return [
|
|
@@ -28702,7 +28803,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28702
28803
|
];
|
|
28703
28804
|
}
|
|
28704
28805
|
async getWithdrawCall(params) {
|
|
28705
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28806
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28807
|
+
this.config.poolId
|
|
28808
|
+
);
|
|
28706
28809
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
28707
28810
|
return [
|
|
28708
28811
|
// Switch delegation on
|
|
@@ -28757,7 +28860,11 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28757
28860
|
];
|
|
28758
28861
|
}
|
|
28759
28862
|
async getMultiplyCallCalldata(params, isDeposit) {
|
|
28760
|
-
logger.verbose(
|
|
28863
|
+
logger.verbose(
|
|
28864
|
+
`${_VesuMultiplyAdapter.name}::getMultiplyCallCalldata params: ${JSON.stringify(
|
|
28865
|
+
params
|
|
28866
|
+
)}, isDeposit: ${isDeposit}, collateral: ${this.config.collateral.symbol}, debt: ${this.config.debt.symbol}`
|
|
28867
|
+
);
|
|
28761
28868
|
const { isV2 } = getVesuSingletonAddress(this.config.poolId);
|
|
28762
28869
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
28763
28870
|
const multiplyContract = new Contract12({
|
|
@@ -28767,42 +28874,83 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28767
28874
|
});
|
|
28768
28875
|
let leverSwap = [];
|
|
28769
28876
|
let leverSwapLimitAmount = Web3Number.fromWei(0, this.config.debt.decimals);
|
|
28770
|
-
const existingPositions = await this.vesuAdapter.getPositions(
|
|
28771
|
-
|
|
28877
|
+
const existingPositions = await this.vesuAdapter.getPositions(
|
|
28878
|
+
this.config.networkConfig
|
|
28879
|
+
);
|
|
28880
|
+
const collateralisation = await this.vesuAdapter.getCollateralization(
|
|
28881
|
+
this.config.networkConfig
|
|
28882
|
+
);
|
|
28772
28883
|
const existingCollateralInfo = existingPositions[0];
|
|
28773
28884
|
const existingDebtInfo = existingPositions[1];
|
|
28774
28885
|
const isDexPriceRequired = existingDebtInfo.token.symbol !== "USDC";
|
|
28775
|
-
logger.debug(`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall existingCollateralInfo: ${JSON.stringify(
|
|
28776
|
-
|
|
28886
|
+
logger.debug(`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall existingCollateralInfo: ${JSON.stringify(
|
|
28887
|
+
existingCollateralInfo
|
|
28888
|
+
)},
|
|
28889
|
+
existingDebtInfo: ${JSON.stringify(
|
|
28890
|
+
existingDebtInfo
|
|
28891
|
+
)}, collateralisation: ${JSON.stringify(collateralisation)}`);
|
|
28777
28892
|
const collateralPrice = collateralisation[0].usdValue > 0 ? collateralisation[0].usdValue / existingCollateralInfo.amount.toNumber() : (await this.config.pricer.getPrice(this.config.collateral.symbol)).price;
|
|
28778
28893
|
const debtPrice = collateralisation[1].usdValue > 0 ? collateralisation[1].usdValue / existingDebtInfo.amount.toNumber() : (await this.config.pricer.getPrice(this.config.debt.symbol)).price;
|
|
28779
|
-
logger.debug(
|
|
28780
|
-
|
|
28781
|
-
|
|
28782
|
-
const
|
|
28783
|
-
|
|
28894
|
+
logger.debug(
|
|
28895
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall collateralPrice: ${collateralPrice}, debtPrice: ${debtPrice}`
|
|
28896
|
+
);
|
|
28897
|
+
const legLTV = await this.vesuAdapter.getLTVConfig(
|
|
28898
|
+
this.config.networkConfig
|
|
28899
|
+
);
|
|
28900
|
+
const ekuboQuoter = new EkuboQuoter(
|
|
28901
|
+
this.config.networkConfig,
|
|
28902
|
+
this.config.pricer
|
|
28903
|
+
);
|
|
28904
|
+
const dexPrice = isDexPriceRequired ? await ekuboQuoter.getDexPrice(
|
|
28905
|
+
this.config.collateral,
|
|
28906
|
+
this.config.debt,
|
|
28907
|
+
this.config.quoteAmountToFetchPrice
|
|
28908
|
+
) : 1;
|
|
28909
|
+
logger.verbose(
|
|
28910
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall dexPrice: ${dexPrice}, ltv: ${legLTV}`
|
|
28911
|
+
);
|
|
28784
28912
|
const addedCollateral = params.amount.multipliedBy(isDeposit ? 1 : -1);
|
|
28785
|
-
logger.verbose(
|
|
28913
|
+
logger.verbose(
|
|
28914
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall addedCollateral: ${addedCollateral}`
|
|
28915
|
+
);
|
|
28786
28916
|
const numeratorPart1 = existingCollateralInfo.amount.plus(addedCollateral).multipliedBy(collateralPrice).multipliedBy(legLTV);
|
|
28787
|
-
logger.verbose(
|
|
28917
|
+
logger.verbose(
|
|
28918
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart1: ${numeratorPart1}`
|
|
28919
|
+
);
|
|
28788
28920
|
const numeratorPart2 = existingDebtInfo.amount.multipliedBy(debtPrice).multipliedBy(this.config.targetHealthFactor);
|
|
28789
|
-
logger.verbose(
|
|
28921
|
+
logger.verbose(
|
|
28922
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart2: ${numeratorPart2}`
|
|
28923
|
+
);
|
|
28790
28924
|
const denominatorPart = this.config.targetHealthFactor - legLTV / dexPrice;
|
|
28791
|
-
logger.verbose(
|
|
28925
|
+
logger.verbose(
|
|
28926
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall denominatorPart: ${denominatorPart}`
|
|
28927
|
+
);
|
|
28792
28928
|
const x_debt_usd = numeratorPart1.minus(numeratorPart2).dividedBy(denominatorPart);
|
|
28793
|
-
logger.verbose(
|
|
28794
|
-
|
|
28795
|
-
|
|
28929
|
+
logger.verbose(
|
|
28930
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall x_debt_usd: ${x_debt_usd}`
|
|
28931
|
+
);
|
|
28932
|
+
logger.debug(
|
|
28933
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart1: ${numeratorPart1}, numeratorPart2: ${numeratorPart2}, denominatorPart: ${denominatorPart}`
|
|
28934
|
+
);
|
|
28935
|
+
let debtAmount = new Web3Number(
|
|
28936
|
+
x_debt_usd.dividedBy(debtPrice).toFixed(this.config.debt.decimals),
|
|
28937
|
+
this.config.debt.decimals
|
|
28938
|
+
);
|
|
28796
28939
|
const marginAmount = addedCollateral;
|
|
28797
28940
|
const collateralToken = this.config.collateral;
|
|
28798
28941
|
const debtToken = this.config.debt;
|
|
28799
|
-
const debtAmountInCollateralUnits = new Web3Number(
|
|
28942
|
+
const debtAmountInCollateralUnits = new Web3Number(
|
|
28943
|
+
debtAmount.multipliedBy(debtPrice).dividedBy(collateralPrice).multipliedBy(10 ** collateralToken.decimals).toFixed(0),
|
|
28944
|
+
collateralToken.decimals
|
|
28945
|
+
);
|
|
28800
28946
|
const isIncrease = debtAmount.greaterThanOrEqualTo(0);
|
|
28801
28947
|
if (isIncrease && debtAmount.lessThan(0)) {
|
|
28802
28948
|
} else if (!isIncrease && debtAmount.greaterThan(0)) {
|
|
28803
28949
|
debtAmount = Web3Number.fromWei(0, this.config.debt.decimals);
|
|
28804
28950
|
}
|
|
28805
|
-
logger.verbose(
|
|
28951
|
+
logger.verbose(
|
|
28952
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall debtAmount: ${debtAmount}, marginAmount: ${marginAmount}`
|
|
28953
|
+
);
|
|
28806
28954
|
if (!debtAmount.isZero()) {
|
|
28807
28955
|
try {
|
|
28808
28956
|
const swapQuote = await ekuboQuoter.getQuote(
|
|
@@ -28812,26 +28960,49 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28812
28960
|
// negative for exact amount out
|
|
28813
28961
|
);
|
|
28814
28962
|
if (swapQuote.price_impact < 0.01) {
|
|
28815
|
-
leverSwap = ekuboQuoter.getVesuMultiplyQuote(
|
|
28963
|
+
leverSwap = debtAmount.isNegative() ? ekuboQuoter.getVesuMultiplyQuote(
|
|
28964
|
+
swapQuote,
|
|
28965
|
+
collateralToken,
|
|
28966
|
+
debtToken
|
|
28967
|
+
) : ekuboQuoter.getVesuMultiplyQuote(
|
|
28968
|
+
swapQuote,
|
|
28969
|
+
debtToken,
|
|
28970
|
+
collateralToken
|
|
28971
|
+
);
|
|
28816
28972
|
const MAX_SLIPPAGE = 2e-3;
|
|
28817
28973
|
if (debtAmount.greaterThan(0)) {
|
|
28818
28974
|
leverSwapLimitAmount = debtAmount.multipliedBy(1 + MAX_SLIPPAGE);
|
|
28819
28975
|
} else if (debtAmount.lessThan(0)) {
|
|
28820
28976
|
leverSwapLimitAmount = debtAmount.abs().multipliedBy(1 - MAX_SLIPPAGE);
|
|
28821
28977
|
} else {
|
|
28822
|
-
leverSwapLimitAmount = Web3Number.fromWei(
|
|
28978
|
+
leverSwapLimitAmount = Web3Number.fromWei(
|
|
28979
|
+
0,
|
|
28980
|
+
this.config.debt.decimals
|
|
28981
|
+
);
|
|
28823
28982
|
}
|
|
28824
28983
|
await new Promise((resolve) => setTimeout(resolve, 1e4));
|
|
28825
28984
|
} else {
|
|
28826
|
-
throw new Error(
|
|
28985
|
+
throw new Error(
|
|
28986
|
+
`VesuMultiplyAdapter: Price impact too high (${swapQuote.price_impact}), skipping swap`
|
|
28987
|
+
);
|
|
28827
28988
|
}
|
|
28828
28989
|
} catch (error) {
|
|
28829
|
-
throw new Error(
|
|
28990
|
+
throw new Error(
|
|
28991
|
+
`VesuMultiplyAdapter: Failed to get swap quote: ${error}`
|
|
28992
|
+
);
|
|
28830
28993
|
}
|
|
28831
28994
|
}
|
|
28832
|
-
const multiplyParams = await this.getLeverParams(
|
|
28995
|
+
const multiplyParams = await this.getLeverParams(
|
|
28996
|
+
isIncrease,
|
|
28997
|
+
params,
|
|
28998
|
+
leverSwap,
|
|
28999
|
+
leverSwapLimitAmount
|
|
29000
|
+
);
|
|
28833
29001
|
const call = multiplyContract.populate("modify_lever", {
|
|
28834
|
-
modify_lever_params: this.formatMultiplyParams(
|
|
29002
|
+
modify_lever_params: this.formatMultiplyParams(
|
|
29003
|
+
isIncrease,
|
|
29004
|
+
multiplyParams
|
|
29005
|
+
)
|
|
28835
29006
|
});
|
|
28836
29007
|
return call.calldata;
|
|
28837
29008
|
}
|
|
@@ -28845,7 +29016,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28845
29016
|
add_margin: params.amount,
|
|
28846
29017
|
// multiplied by collateral decimals in format
|
|
28847
29018
|
margin_swap: [],
|
|
28848
|
-
margin_swap_limit_amount: Web3Number.fromWei(
|
|
29019
|
+
margin_swap_limit_amount: Web3Number.fromWei(
|
|
29020
|
+
0,
|
|
29021
|
+
this.config.collateral.decimals
|
|
29022
|
+
),
|
|
28849
29023
|
lever_swap: leverSwap,
|
|
28850
29024
|
lever_swap_limit_amount: leverSwapLimitAmount
|
|
28851
29025
|
} : {
|
|
@@ -28859,7 +29033,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28859
29033
|
lever_swap_limit_amount: leverSwapLimitAmount,
|
|
28860
29034
|
lever_swap_weights: [],
|
|
28861
29035
|
withdraw_swap: [],
|
|
28862
|
-
withdraw_swap_limit_amount: Web3Number.fromWei(
|
|
29036
|
+
withdraw_swap_limit_amount: Web3Number.fromWei(
|
|
29037
|
+
0,
|
|
29038
|
+
this.config.collateral.decimals
|
|
29039
|
+
),
|
|
28863
29040
|
withdraw_swap_weights: [],
|
|
28864
29041
|
close_position: false
|
|
28865
29042
|
};
|
|
@@ -28875,12 +29052,16 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28875
29052
|
});
|
|
28876
29053
|
let leverSwap = [];
|
|
28877
29054
|
let leverSwapLimitAmount = Web3Number.fromWei(0, this.config.debt.decimals);
|
|
28878
|
-
const existingPositions = await this.vesuAdapter.getPositions(
|
|
29055
|
+
const existingPositions = await this.vesuAdapter.getPositions(
|
|
29056
|
+
this.config.networkConfig
|
|
29057
|
+
);
|
|
28879
29058
|
const existingCollateralInfo = existingPositions[0];
|
|
28880
29059
|
const existingDebtInfo = existingPositions[1];
|
|
28881
29060
|
const collateralToken = this.config.collateral;
|
|
28882
29061
|
const debtToken = this.config.debt;
|
|
28883
|
-
const collateralPrice = await this.config.pricer.getPrice(
|
|
29062
|
+
const collateralPrice = await this.config.pricer.getPrice(
|
|
29063
|
+
collateralToken.symbol
|
|
29064
|
+
);
|
|
28884
29065
|
const debtPrice = await this.config.pricer.getPrice(debtToken.symbol);
|
|
28885
29066
|
const { deltadebtAmountUnits: debtAmountToRepay } = calculateDebtReductionAmountForWithdrawal(
|
|
28886
29067
|
existingDebtInfo.amount,
|
|
@@ -28894,8 +29075,14 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28894
29075
|
if (!debtAmountToRepay) {
|
|
28895
29076
|
throw new Error("error calculating debt amount to repay");
|
|
28896
29077
|
}
|
|
28897
|
-
const ekuboQuoter = new EkuboQuoter(
|
|
28898
|
-
|
|
29078
|
+
const ekuboQuoter = new EkuboQuoter(
|
|
29079
|
+
this.config.networkConfig,
|
|
29080
|
+
this.config.pricer
|
|
29081
|
+
);
|
|
29082
|
+
const debtInDebtUnits = new Web3Number(
|
|
29083
|
+
debtAmountToRepay,
|
|
29084
|
+
debtToken.decimals
|
|
29085
|
+
).dividedBy(debtPrice.price).multipliedBy(10 ** debtToken.decimals);
|
|
28899
29086
|
const swapQuote = await ekuboQuoter.getQuote(
|
|
28900
29087
|
debtToken.address.address,
|
|
28901
29088
|
collateralToken.address.address,
|
|
@@ -28903,12 +29090,23 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28903
29090
|
);
|
|
28904
29091
|
const MAX_SLIPPAGE = 2e-3;
|
|
28905
29092
|
if (swapQuote.price_impact < 25e-4) {
|
|
28906
|
-
leverSwap = ekuboQuoter.getVesuMultiplyQuote(
|
|
29093
|
+
leverSwap = ekuboQuoter.getVesuMultiplyQuote(
|
|
29094
|
+
swapQuote,
|
|
29095
|
+
collateralToken,
|
|
29096
|
+
debtToken
|
|
29097
|
+
);
|
|
28907
29098
|
} else {
|
|
28908
|
-
logger.error(
|
|
29099
|
+
logger.error(
|
|
29100
|
+
`VesuMultiplyAdapter: Price impact too high (${swapQuote.price_impact}), skipping swap`
|
|
29101
|
+
);
|
|
28909
29102
|
}
|
|
28910
29103
|
leverSwapLimitAmount = new Web3Number(debtAmountToRepay, debtToken.decimals).abs().multipliedBy(1 + MAX_SLIPPAGE);
|
|
28911
|
-
const multiplyParams = await this.getLeverParams(
|
|
29104
|
+
const multiplyParams = await this.getLeverParams(
|
|
29105
|
+
false,
|
|
29106
|
+
params,
|
|
29107
|
+
leverSwap,
|
|
29108
|
+
leverSwapLimitAmount
|
|
29109
|
+
);
|
|
28912
29110
|
const call = multiplyContract.populate("modify_lever", {
|
|
28913
29111
|
modify_lever_params: this.formatMultiplyParams(false, multiplyParams)
|
|
28914
29112
|
});
|
|
@@ -28918,100 +29116,132 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28918
29116
|
if (isIncrease) {
|
|
28919
29117
|
const _params2 = params;
|
|
28920
29118
|
return {
|
|
28921
|
-
action: new CairoCustomEnum3({
|
|
28922
|
-
|
|
28923
|
-
|
|
28924
|
-
|
|
28925
|
-
|
|
28926
|
-
|
|
28927
|
-
|
|
29119
|
+
action: new CairoCustomEnum3({
|
|
29120
|
+
IncreaseLever: {
|
|
29121
|
+
pool_id: _params2.pool_id.toBigInt(),
|
|
29122
|
+
collateral_asset: _params2.collateral_asset.toBigInt(),
|
|
29123
|
+
debt_asset: _params2.debt_asset.toBigInt(),
|
|
29124
|
+
user: _params2.user.toBigInt(),
|
|
29125
|
+
add_margin: BigInt(_params2.add_margin.toWei()),
|
|
29126
|
+
margin_swap: _params2.margin_swap.map((swap) => ({
|
|
29127
|
+
route: swap.route.map((route) => ({
|
|
29128
|
+
pool_key: {
|
|
29129
|
+
token0: route.pool_key.token0.toBigInt(),
|
|
29130
|
+
token1: route.pool_key.token1.toBigInt(),
|
|
29131
|
+
fee: route.pool_key.fee,
|
|
29132
|
+
tick_spacing: route.pool_key.tick_spacing,
|
|
29133
|
+
extension: BigInt(
|
|
29134
|
+
num9.hexToDecimalString(route.pool_key.extension)
|
|
29135
|
+
)
|
|
29136
|
+
},
|
|
29137
|
+
sqrt_ratio_limit: uint25612.bnToUint256(
|
|
29138
|
+
route.sqrt_ratio_limit.toWei()
|
|
29139
|
+
),
|
|
29140
|
+
skip_ahead: BigInt(100)
|
|
29141
|
+
})),
|
|
29142
|
+
token_amount: {
|
|
29143
|
+
token: swap.token_amount.token.toBigInt(),
|
|
29144
|
+
amount: swap.token_amount.amount.toI129()
|
|
29145
|
+
}
|
|
29146
|
+
})),
|
|
29147
|
+
margin_swap_limit_amount: BigInt(
|
|
29148
|
+
_params2.margin_swap_limit_amount.toWei()
|
|
29149
|
+
),
|
|
29150
|
+
lever_swap: _params2.lever_swap.map((swap) => ({
|
|
29151
|
+
route: swap.route.map((route) => ({
|
|
29152
|
+
pool_key: {
|
|
29153
|
+
token0: route.pool_key.token0.toBigInt(),
|
|
29154
|
+
token1: route.pool_key.token1.toBigInt(),
|
|
29155
|
+
fee: route.pool_key.fee,
|
|
29156
|
+
tick_spacing: route.pool_key.tick_spacing,
|
|
29157
|
+
extension: BigInt(
|
|
29158
|
+
num9.hexToDecimalString(route.pool_key.extension)
|
|
29159
|
+
)
|
|
29160
|
+
},
|
|
29161
|
+
sqrt_ratio_limit: uint25612.bnToUint256(
|
|
29162
|
+
route.sqrt_ratio_limit.toWei()
|
|
29163
|
+
),
|
|
29164
|
+
skip_ahead: BigInt(0)
|
|
29165
|
+
})),
|
|
29166
|
+
token_amount: {
|
|
29167
|
+
token: swap.token_amount.token.toBigInt(),
|
|
29168
|
+
amount: swap.token_amount.amount.toI129()
|
|
29169
|
+
}
|
|
29170
|
+
})),
|
|
29171
|
+
lever_swap_limit_amount: BigInt(
|
|
29172
|
+
_params2.lever_swap_limit_amount.toWei()
|
|
29173
|
+
)
|
|
29174
|
+
}
|
|
29175
|
+
})
|
|
29176
|
+
};
|
|
29177
|
+
}
|
|
29178
|
+
const _params = params;
|
|
29179
|
+
return {
|
|
29180
|
+
action: new CairoCustomEnum3({
|
|
29181
|
+
DecreaseLever: {
|
|
29182
|
+
pool_id: _params.pool_id.toBigInt(),
|
|
29183
|
+
collateral_asset: _params.collateral_asset.toBigInt(),
|
|
29184
|
+
debt_asset: _params.debt_asset.toBigInt(),
|
|
29185
|
+
user: _params.user.toBigInt(),
|
|
29186
|
+
sub_margin: BigInt(_params.sub_margin.toWei()),
|
|
29187
|
+
recipient: _params.recipient.toBigInt(),
|
|
29188
|
+
lever_swap: _params.lever_swap.map((swap) => ({
|
|
28928
29189
|
route: swap.route.map((route) => ({
|
|
28929
29190
|
pool_key: {
|
|
28930
29191
|
token0: route.pool_key.token0.toBigInt(),
|
|
28931
29192
|
token1: route.pool_key.token1.toBigInt(),
|
|
28932
29193
|
fee: route.pool_key.fee,
|
|
28933
29194
|
tick_spacing: route.pool_key.tick_spacing,
|
|
28934
|
-
extension:
|
|
29195
|
+
extension: ContractAddr.from(
|
|
29196
|
+
route.pool_key.extension
|
|
29197
|
+
).toBigInt()
|
|
28935
29198
|
},
|
|
28936
|
-
sqrt_ratio_limit: uint25612.bnToUint256(
|
|
28937
|
-
|
|
29199
|
+
sqrt_ratio_limit: uint25612.bnToUint256(
|
|
29200
|
+
route.sqrt_ratio_limit.toWei()
|
|
29201
|
+
),
|
|
29202
|
+
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
28938
29203
|
})),
|
|
28939
29204
|
token_amount: {
|
|
28940
29205
|
token: swap.token_amount.token.toBigInt(),
|
|
28941
29206
|
amount: swap.token_amount.amount.toI129()
|
|
28942
29207
|
}
|
|
28943
29208
|
})),
|
|
28944
|
-
|
|
28945
|
-
|
|
29209
|
+
lever_swap_limit_amount: BigInt(
|
|
29210
|
+
_params.lever_swap_limit_amount.toWei()
|
|
29211
|
+
),
|
|
29212
|
+
lever_swap_weights: _params.lever_swap_weights.map(
|
|
29213
|
+
(weight) => BigInt(weight.toWei())
|
|
29214
|
+
),
|
|
29215
|
+
withdraw_swap: _params.withdraw_swap.map((swap) => ({
|
|
28946
29216
|
route: swap.route.map((route) => ({
|
|
28947
29217
|
pool_key: {
|
|
28948
29218
|
token0: route.pool_key.token0.toBigInt(),
|
|
28949
29219
|
token1: route.pool_key.token1.toBigInt(),
|
|
28950
29220
|
fee: route.pool_key.fee,
|
|
28951
29221
|
tick_spacing: route.pool_key.tick_spacing,
|
|
28952
|
-
extension:
|
|
29222
|
+
extension: ContractAddr.from(
|
|
29223
|
+
route.pool_key.extension
|
|
29224
|
+
).toBigInt()
|
|
28953
29225
|
},
|
|
28954
|
-
sqrt_ratio_limit: uint25612.bnToUint256(
|
|
28955
|
-
|
|
29226
|
+
sqrt_ratio_limit: uint25612.bnToUint256(
|
|
29227
|
+
route.sqrt_ratio_limit.toWei()
|
|
29228
|
+
),
|
|
29229
|
+
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
28956
29230
|
})),
|
|
28957
29231
|
token_amount: {
|
|
28958
29232
|
token: swap.token_amount.token.toBigInt(),
|
|
28959
29233
|
amount: swap.token_amount.amount.toI129()
|
|
28960
29234
|
}
|
|
28961
29235
|
})),
|
|
28962
|
-
|
|
28963
|
-
|
|
28964
|
-
|
|
28965
|
-
|
|
28966
|
-
|
|
28967
|
-
|
|
28968
|
-
|
|
28969
|
-
|
|
28970
|
-
|
|
28971
|
-
debt_asset: _params.debt_asset.toBigInt(),
|
|
28972
|
-
user: _params.user.toBigInt(),
|
|
28973
|
-
sub_margin: BigInt(_params.sub_margin.toWei()),
|
|
28974
|
-
recipient: _params.recipient.toBigInt(),
|
|
28975
|
-
lever_swap: _params.lever_swap.map((swap) => ({
|
|
28976
|
-
route: swap.route.map((route) => ({
|
|
28977
|
-
pool_key: {
|
|
28978
|
-
token0: route.pool_key.token0.toBigInt(),
|
|
28979
|
-
token1: route.pool_key.token1.toBigInt(),
|
|
28980
|
-
fee: route.pool_key.fee,
|
|
28981
|
-
tick_spacing: route.pool_key.tick_spacing,
|
|
28982
|
-
extension: ContractAddr.from(route.pool_key.extension).toBigInt()
|
|
28983
|
-
},
|
|
28984
|
-
sqrt_ratio_limit: uint25612.bnToUint256(route.sqrt_ratio_limit.toWei()),
|
|
28985
|
-
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
28986
|
-
})),
|
|
28987
|
-
token_amount: {
|
|
28988
|
-
token: swap.token_amount.token.toBigInt(),
|
|
28989
|
-
amount: swap.token_amount.amount.toI129()
|
|
28990
|
-
}
|
|
28991
|
-
})),
|
|
28992
|
-
lever_swap_limit_amount: BigInt(_params.lever_swap_limit_amount.toWei()),
|
|
28993
|
-
lever_swap_weights: _params.lever_swap_weights.map((weight) => BigInt(weight.toWei())),
|
|
28994
|
-
withdraw_swap: _params.withdraw_swap.map((swap) => ({
|
|
28995
|
-
route: swap.route.map((route) => ({
|
|
28996
|
-
pool_key: {
|
|
28997
|
-
token0: route.pool_key.token0.toBigInt(),
|
|
28998
|
-
token1: route.pool_key.token1.toBigInt(),
|
|
28999
|
-
fee: route.pool_key.fee,
|
|
29000
|
-
tick_spacing: route.pool_key.tick_spacing,
|
|
29001
|
-
extension: ContractAddr.from(route.pool_key.extension).toBigInt()
|
|
29002
|
-
},
|
|
29003
|
-
sqrt_ratio_limit: uint25612.bnToUint256(route.sqrt_ratio_limit.toWei()),
|
|
29004
|
-
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
29005
|
-
})),
|
|
29006
|
-
token_amount: {
|
|
29007
|
-
token: swap.token_amount.token.toBigInt(),
|
|
29008
|
-
amount: swap.token_amount.amount.toI129()
|
|
29009
|
-
}
|
|
29010
|
-
})),
|
|
29011
|
-
withdraw_swap_limit_amount: BigInt(_params.withdraw_swap_limit_amount.toWei()),
|
|
29012
|
-
withdraw_swap_weights: _params.withdraw_swap_weights.map((weight) => BigInt(weight.toWei())),
|
|
29013
|
-
close_position: _params.close_position
|
|
29014
|
-
} })
|
|
29236
|
+
withdraw_swap_limit_amount: BigInt(
|
|
29237
|
+
_params.withdraw_swap_limit_amount.toWei()
|
|
29238
|
+
),
|
|
29239
|
+
withdraw_swap_weights: _params.withdraw_swap_weights.map(
|
|
29240
|
+
(weight) => BigInt(weight.toWei())
|
|
29241
|
+
),
|
|
29242
|
+
close_position: _params.close_position
|
|
29243
|
+
}
|
|
29244
|
+
})
|
|
29015
29245
|
};
|
|
29016
29246
|
}
|
|
29017
29247
|
async getHealthFactor() {
|
|
@@ -29020,11 +29250,15 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29020
29250
|
}
|
|
29021
29251
|
async getNetAPY() {
|
|
29022
29252
|
const positions = await this.getPositions();
|
|
29023
|
-
logger.verbose(
|
|
29253
|
+
logger.verbose(
|
|
29254
|
+
`${this.name}::getNetAPY: positions: ${JSON.stringify(positions)}`
|
|
29255
|
+
);
|
|
29024
29256
|
const allZero = positions.every((p) => p.usdValue === 0);
|
|
29025
29257
|
if (allZero) {
|
|
29026
29258
|
const collateralUSD = 1e3;
|
|
29027
|
-
const maxLTV = await this.vesuAdapter.getLTVConfig(
|
|
29259
|
+
const maxLTV = await this.vesuAdapter.getLTVConfig(
|
|
29260
|
+
this.config.networkConfig
|
|
29261
|
+
);
|
|
29028
29262
|
const targetHF = this.config.targetHealthFactor;
|
|
29029
29263
|
const maxDebt = HealthFactorMath.getMaxDebtAmountOnLooping(
|
|
29030
29264
|
new Web3Number(collateralUSD, this.config.collateral.decimals),
|
|
@@ -29750,6 +29984,7 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29750
29984
|
logger.error("error initializing client");
|
|
29751
29985
|
return null;
|
|
29752
29986
|
}
|
|
29987
|
+
await new Promise((resolve) => setTimeout(resolve, 5e3));
|
|
29753
29988
|
const orderhistory = await this.getOrderHistory(marketName);
|
|
29754
29989
|
if (!orderhistory || orderhistory.length === 0) {
|
|
29755
29990
|
logger.error(`error getting order: ${orderId}`);
|
|
@@ -34130,7 +34365,7 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34130
34365
|
const withdrawalFromExtended = await extendedAdapter.withdrawFromExtended(params.amount);
|
|
34131
34366
|
if (withdrawalFromExtended) {
|
|
34132
34367
|
const extendedHoldings2 = await extendedAdapter.getExtendedDepositAmount();
|
|
34133
|
-
logger.info(`extendedHoldings after withdrawal ${extendedHoldings2}`);
|
|
34368
|
+
logger.info(`extendedHoldings after withdrawal ${extendedHoldings2?.availableForWithdrawal}`);
|
|
34134
34369
|
await new Promise((resolve) => setTimeout(resolve, 1e4));
|
|
34135
34370
|
const calls = await this.moveAssetsToVaultAllocator(params.amount, extendedAdapter);
|
|
34136
34371
|
if (calls.length > 0) {
|