@strkfarm/sdk 2.0.0-dev.3 → 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 +395 -159
- package/dist/index.browser.mjs +395 -159
- package/dist/index.js +395 -159
- package/dist/index.mjs +395 -159
- 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/utils/helper.ts +4 -4
- package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +1 -1
package/dist/index.js
CHANGED
|
@@ -28343,11 +28343,12 @@ var calculateAmountDepositOnExtendedWhenIncurringLosses = async (client) => {
|
|
|
28343
28343
|
logger.error(`error getting extended position: extendedHoldings=${extendedHoldings}, latestPosition=${latestPosition}`);
|
|
28344
28344
|
return null;
|
|
28345
28345
|
}
|
|
28346
|
-
const positionValueInUSD = latestPosition.value;
|
|
28346
|
+
const positionValueInUSD = new Web3Number(latestPosition.value, USDC_TOKEN_DECIMALS);
|
|
28347
28347
|
const equity = extendedHoldings.data.equity;
|
|
28348
|
-
const deposit =
|
|
28349
|
-
return new Web3Number(
|
|
28348
|
+
const deposit = positionValueInUSD.dividedBy(extended_leverage).minus(equity).toFixed(2);
|
|
28349
|
+
return new Web3Number(deposit, USDC_TOKEN_DECIMALS);
|
|
28350
28350
|
} catch (err) {
|
|
28351
|
+
logger.error(`error calculating amount deposit on extended when incurring losses: ${err}`);
|
|
28351
28352
|
return null;
|
|
28352
28353
|
}
|
|
28353
28354
|
};
|
|
@@ -28425,21 +28426,35 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28425
28426
|
vaultAllocator: config.vaultAllocator,
|
|
28426
28427
|
id: ""
|
|
28427
28428
|
});
|
|
28428
|
-
this.tokenMarketData = new TokenMarketData(
|
|
28429
|
+
this.tokenMarketData = new TokenMarketData(
|
|
28430
|
+
this.config.pricer,
|
|
28431
|
+
this.config.networkConfig
|
|
28432
|
+
);
|
|
28429
28433
|
}
|
|
28430
28434
|
async getAPY(supportedPosition) {
|
|
28431
28435
|
const CACHE_KEY = `apy_${this.config.poolId.address}_${supportedPosition.asset.symbol}`;
|
|
28432
28436
|
const cacheData = this.getCache(CACHE_KEY);
|
|
28433
|
-
console.log(
|
|
28437
|
+
console.log(
|
|
28438
|
+
`${_VesuMultiplyAdapter.name}::getAPY cacheData: ${JSON.stringify(
|
|
28439
|
+
cacheData
|
|
28440
|
+
)}`,
|
|
28441
|
+
this.vesuAdapter.config.poolId.shortString(),
|
|
28442
|
+
this.vesuAdapter.config.collateral.symbol,
|
|
28443
|
+
this.vesuAdapter.config.debt.symbol
|
|
28444
|
+
);
|
|
28434
28445
|
if (cacheData) {
|
|
28435
28446
|
return cacheData;
|
|
28436
28447
|
}
|
|
28437
28448
|
try {
|
|
28438
28449
|
const allVesuPools = await VesuAdapter.getVesuPools();
|
|
28439
28450
|
const asset = supportedPosition.asset;
|
|
28440
|
-
const pool = allVesuPools.pools.find(
|
|
28451
|
+
const pool = allVesuPools.pools.find(
|
|
28452
|
+
(p) => this.vesuAdapter.config.poolId.eqString(import_starknet21.num.getHexString(p.id))
|
|
28453
|
+
);
|
|
28441
28454
|
if (!pool) {
|
|
28442
|
-
logger.warn(
|
|
28455
|
+
logger.warn(
|
|
28456
|
+
`VesuMultiplyAdapter: Pool not found for token ${asset.symbol}`
|
|
28457
|
+
);
|
|
28443
28458
|
return {
|
|
28444
28459
|
apy: 0,
|
|
28445
28460
|
type: "base" /* BASE */
|
|
@@ -28449,7 +28464,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28449
28464
|
(a) => a.symbol.toLowerCase() === asset.symbol.toLowerCase()
|
|
28450
28465
|
)?.stats;
|
|
28451
28466
|
if (!assetStats) {
|
|
28452
|
-
logger.warn(
|
|
28467
|
+
logger.warn(
|
|
28468
|
+
`VesuMultiplyAdapter: Asset stats not found for token ${asset.symbol}`
|
|
28469
|
+
);
|
|
28453
28470
|
return {
|
|
28454
28471
|
apy: 0,
|
|
28455
28472
|
type: "base" /* BASE */
|
|
@@ -28460,7 +28477,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28460
28477
|
apy = Number(assetStats.borrowApr?.value || 0) / 1e18;
|
|
28461
28478
|
} else {
|
|
28462
28479
|
const isAssetBTC = asset.symbol.toLowerCase().includes("btc");
|
|
28463
|
-
const baseAPY = Number(
|
|
28480
|
+
const baseAPY = Number(
|
|
28481
|
+
isAssetBTC ? assetStats.btcFiSupplyApr?.value + assetStats.supplyApy?.value : assetStats.supplyApy?.value || 0
|
|
28482
|
+
) / 1e18;
|
|
28464
28483
|
const rewardAPY = Number(assetStats.defiSpringSupplyApr?.value || "0") / 1e18;
|
|
28465
28484
|
const isSupported = this.tokenMarketData.isAPYSupported(asset);
|
|
28466
28485
|
apy = baseAPY + rewardAPY;
|
|
@@ -28476,7 +28495,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28476
28495
|
this.setCache(CACHE_KEY, result, 3e5);
|
|
28477
28496
|
return result;
|
|
28478
28497
|
} catch (error) {
|
|
28479
|
-
logger.error(
|
|
28498
|
+
logger.error(
|
|
28499
|
+
`VesuMultiplyAdapter: Error getting APY for ${supportedPosition.asset.symbol}:`,
|
|
28500
|
+
error
|
|
28501
|
+
);
|
|
28480
28502
|
throw error;
|
|
28481
28503
|
}
|
|
28482
28504
|
}
|
|
@@ -28489,12 +28511,16 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28489
28511
|
try {
|
|
28490
28512
|
this.vesuAdapter.networkConfig = this.config.networkConfig;
|
|
28491
28513
|
this.vesuAdapter.pricer = this.config.pricer;
|
|
28492
|
-
const positions = await this.vesuAdapter.getPositions(
|
|
28514
|
+
const positions = await this.vesuAdapter.getPositions(
|
|
28515
|
+
this.config.networkConfig
|
|
28516
|
+
);
|
|
28493
28517
|
let position = positions.find(
|
|
28494
28518
|
(p) => p.token.address.eq(supportedPosition.asset.address)
|
|
28495
28519
|
);
|
|
28496
28520
|
if (!position) {
|
|
28497
|
-
logger.warn(
|
|
28521
|
+
logger.warn(
|
|
28522
|
+
`VesuMultiplyAdapter: Position not found for token ${supportedPosition.asset.symbol}`
|
|
28523
|
+
);
|
|
28498
28524
|
return {
|
|
28499
28525
|
amount: new Web3Number("0", supportedPosition.asset.decimals),
|
|
28500
28526
|
remarks: "Position not found"
|
|
@@ -28507,12 +28533,18 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28507
28533
|
this.setCache(CACHE_KEY, position, 6e4);
|
|
28508
28534
|
return position;
|
|
28509
28535
|
} catch (error) {
|
|
28510
|
-
logger.error(
|
|
28536
|
+
logger.error(
|
|
28537
|
+
`VesuMultiplyAdapter: Error getting position for ${supportedPosition.asset.symbol}:`,
|
|
28538
|
+
error
|
|
28539
|
+
);
|
|
28511
28540
|
throw error;
|
|
28512
28541
|
}
|
|
28513
28542
|
}
|
|
28514
28543
|
async maxBorrowableAPY() {
|
|
28515
|
-
const collateralAPY = await this.getAPY({
|
|
28544
|
+
const collateralAPY = await this.getAPY({
|
|
28545
|
+
asset: this.config.collateral,
|
|
28546
|
+
isDebt: false
|
|
28547
|
+
});
|
|
28516
28548
|
const apy = collateralAPY.apy * 0.8;
|
|
28517
28549
|
return apy;
|
|
28518
28550
|
}
|
|
@@ -28522,9 +28554,15 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28522
28554
|
try {
|
|
28523
28555
|
this.vesuAdapter.networkConfig = this.config.networkConfig;
|
|
28524
28556
|
this.vesuAdapter.pricer = this.config.pricer;
|
|
28525
|
-
const positions = await this.vesuAdapter.getPositions(
|
|
28526
|
-
|
|
28527
|
-
|
|
28557
|
+
const positions = await this.vesuAdapter.getPositions(
|
|
28558
|
+
this.config.networkConfig
|
|
28559
|
+
);
|
|
28560
|
+
const collateralPosition = positions.find(
|
|
28561
|
+
(p) => p.token.address.eq(collateral.address)
|
|
28562
|
+
);
|
|
28563
|
+
const debtPosition = positions.find(
|
|
28564
|
+
(p) => p.token.address.eq(debt.address)
|
|
28565
|
+
);
|
|
28528
28566
|
if (!collateralPosition || !debtPosition) {
|
|
28529
28567
|
throw new Error("Could not find current positions");
|
|
28530
28568
|
}
|
|
@@ -28534,13 +28572,23 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28534
28572
|
debt,
|
|
28535
28573
|
maxBorrowableAPY
|
|
28536
28574
|
);
|
|
28537
|
-
logger.verbose(
|
|
28538
|
-
|
|
28575
|
+
logger.verbose(
|
|
28576
|
+
`VesuMultiplyAdapter: Max borrowable: ${maxBorrowable.toNumber()}`
|
|
28577
|
+
);
|
|
28578
|
+
const debtCap = await this.vesuAdapter.getDebtCap(
|
|
28579
|
+
this.config.networkConfig
|
|
28580
|
+
);
|
|
28539
28581
|
logger.verbose(`VesuMultiplyAdapter: Debt cap: ${debtCap.toNumber()}`);
|
|
28540
28582
|
const actualMaxBorrowable = maxBorrowable.minimum(debtCap);
|
|
28541
|
-
logger.verbose(
|
|
28542
|
-
|
|
28543
|
-
|
|
28583
|
+
logger.verbose(
|
|
28584
|
+
`VesuMultiplyAdapter: Actual max borrowable: ${actualMaxBorrowable.toNumber()}`
|
|
28585
|
+
);
|
|
28586
|
+
const maxLTV = await this.vesuAdapter.getLTVConfig(
|
|
28587
|
+
this.config.networkConfig
|
|
28588
|
+
);
|
|
28589
|
+
const collateralPrice = await this.config.pricer.getPrice(
|
|
28590
|
+
collateral.symbol
|
|
28591
|
+
);
|
|
28544
28592
|
if (collateralPrice.price === 0) {
|
|
28545
28593
|
throw new Error("Collateral price is 0");
|
|
28546
28594
|
}
|
|
@@ -28558,14 +28606,25 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28558
28606
|
);
|
|
28559
28607
|
const maxDepositAmount = amount ? amount.minimum(maxCollateralFromDebt) : maxCollateralFromDebt;
|
|
28560
28608
|
const usdValue = await this.getUSDValue(collateral, maxDepositAmount);
|
|
28561
|
-
logger.verbose(
|
|
28562
|
-
|
|
28563
|
-
|
|
28609
|
+
logger.verbose(
|
|
28610
|
+
`VesuMultiplyAdapter: Max deposit::USD value: ${usdValue}, amount: ${maxDepositAmount.toNumber()}`
|
|
28611
|
+
);
|
|
28612
|
+
const apys = await Promise.all([
|
|
28613
|
+
this.getAPY({ asset: collateral, isDebt: false }),
|
|
28614
|
+
this.getAPY({ asset: debt, isDebt: true })
|
|
28615
|
+
]);
|
|
28616
|
+
logger.verbose(
|
|
28617
|
+
`VesuMultiplyAdapter: Apys: ${apys[0].apy}, ${apys[1].apy}`
|
|
28618
|
+
);
|
|
28564
28619
|
const borrowAmountUSD = actualMaxBorrowable.multipliedBy(debtPrice.price);
|
|
28565
|
-
logger.verbose(
|
|
28620
|
+
logger.verbose(
|
|
28621
|
+
`VesuMultiplyAdapter: Borrow amount: ${actualMaxBorrowable.toNumber()}, borrow amount USD: ${borrowAmountUSD.toNumber()}`
|
|
28622
|
+
);
|
|
28566
28623
|
const netCollateralUSD = usdValue + borrowAmountUSD.toNumber();
|
|
28567
28624
|
const netAPY = (apys[0].apy * netCollateralUSD + apys[1].apy * borrowAmountUSD.toNumber()) / usdValue;
|
|
28568
|
-
logger.verbose(
|
|
28625
|
+
logger.verbose(
|
|
28626
|
+
`VesuMultiplyAdapter: Max deposit amount: ${maxDepositAmount.toNumber()}, netAPY: ${netAPY}`
|
|
28627
|
+
);
|
|
28569
28628
|
return {
|
|
28570
28629
|
tokenInfo: collateral,
|
|
28571
28630
|
amount: maxDepositAmount,
|
|
@@ -28578,7 +28637,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28578
28637
|
protocol: this.protocol
|
|
28579
28638
|
};
|
|
28580
28639
|
} catch (error) {
|
|
28581
|
-
logger.error(
|
|
28640
|
+
logger.error(
|
|
28641
|
+
`VesuMultiplyAdapter: Error calculating max deposit:`,
|
|
28642
|
+
error
|
|
28643
|
+
);
|
|
28582
28644
|
throw error;
|
|
28583
28645
|
}
|
|
28584
28646
|
}
|
|
@@ -28588,9 +28650,15 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28588
28650
|
try {
|
|
28589
28651
|
this.vesuAdapter.networkConfig = this.config.networkConfig;
|
|
28590
28652
|
this.vesuAdapter.pricer = this.config.pricer;
|
|
28591
|
-
const positions = await this.vesuAdapter.getPositions(
|
|
28592
|
-
|
|
28593
|
-
|
|
28653
|
+
const positions = await this.vesuAdapter.getPositions(
|
|
28654
|
+
this.config.networkConfig
|
|
28655
|
+
);
|
|
28656
|
+
const collateralPosition = positions.find(
|
|
28657
|
+
(p) => p.token.address.eq(collateral.address)
|
|
28658
|
+
);
|
|
28659
|
+
const debtPosition = positions.find(
|
|
28660
|
+
(p) => p.token.address.eq(this.config.debt.address)
|
|
28661
|
+
);
|
|
28594
28662
|
if (!collateralPosition || !debtPosition) {
|
|
28595
28663
|
throw new Error("Could not find current positions");
|
|
28596
28664
|
}
|
|
@@ -28600,11 +28668,20 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28600
28668
|
const result = maxWithdrawable.greaterThan(0) ? maxWithdrawable : new Web3Number("0", collateral.decimals);
|
|
28601
28669
|
const usdValue = await this.getUSDValue(collateral, result);
|
|
28602
28670
|
const debtUSD = debtPosition.usdValue;
|
|
28603
|
-
logger.verbose(
|
|
28604
|
-
|
|
28605
|
-
|
|
28671
|
+
logger.verbose(
|
|
28672
|
+
`VesuMultiplyAdapter: Debt USD: ${debtUSD}, collateral USD: ${usdValue}`
|
|
28673
|
+
);
|
|
28674
|
+
const apys = await Promise.all([
|
|
28675
|
+
this.getAPY({ asset: collateral, isDebt: false }),
|
|
28676
|
+
this.getAPY({ asset: debt, isDebt: true })
|
|
28677
|
+
]);
|
|
28678
|
+
logger.verbose(
|
|
28679
|
+
`VesuMultiplyAdapter: Apys: ${apys[0].apy}, ${apys[1].apy}`
|
|
28680
|
+
);
|
|
28606
28681
|
const netAPY = usdValue - debtUSD > 0 ? (apys[0].apy * usdValue + apys[1].apy * debtUSD) / (usdValue - debtUSD) : 0;
|
|
28607
|
-
logger.verbose(
|
|
28682
|
+
logger.verbose(
|
|
28683
|
+
`VesuMultiplyAdapter: Max withdraw amount: ${result.toNumber()}, netAPY: ${netAPY}`
|
|
28684
|
+
);
|
|
28608
28685
|
return {
|
|
28609
28686
|
tokenInfo: collateral,
|
|
28610
28687
|
amount: result,
|
|
@@ -28617,14 +28694,19 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28617
28694
|
protocol: this.protocol
|
|
28618
28695
|
};
|
|
28619
28696
|
} catch (error) {
|
|
28620
|
-
logger.error(
|
|
28697
|
+
logger.error(
|
|
28698
|
+
`VesuMultiplyAdapter: Error calculating max withdraw:`,
|
|
28699
|
+
error
|
|
28700
|
+
);
|
|
28621
28701
|
throw error;
|
|
28622
28702
|
}
|
|
28623
28703
|
}
|
|
28624
28704
|
_getDepositLeaf() {
|
|
28625
28705
|
const collateral = this.config.collateral;
|
|
28626
28706
|
const debt = this.config.debt;
|
|
28627
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28707
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28708
|
+
this.config.poolId
|
|
28709
|
+
);
|
|
28628
28710
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
28629
28711
|
return [
|
|
28630
28712
|
// Approval step for collateral
|
|
@@ -28688,7 +28770,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28688
28770
|
];
|
|
28689
28771
|
}
|
|
28690
28772
|
_getWithdrawLeaf() {
|
|
28691
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28773
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28774
|
+
this.config.poolId
|
|
28775
|
+
);
|
|
28692
28776
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
28693
28777
|
const collateral = this.config.collateral;
|
|
28694
28778
|
const debt = this.config.debt;
|
|
@@ -28745,33 +28829,51 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28745
28829
|
const leafConfigs = this._getDepositLeaf();
|
|
28746
28830
|
const leaves = leafConfigs.map((config) => {
|
|
28747
28831
|
const { target, method, packedArguments, sanitizer, id } = config;
|
|
28748
|
-
const leaf = this.constructSimpleLeafData(
|
|
28749
|
-
|
|
28750
|
-
|
|
28751
|
-
|
|
28752
|
-
|
|
28753
|
-
|
|
28832
|
+
const leaf = this.constructSimpleLeafData(
|
|
28833
|
+
{
|
|
28834
|
+
id,
|
|
28835
|
+
target,
|
|
28836
|
+
method,
|
|
28837
|
+
packedArguments
|
|
28838
|
+
},
|
|
28839
|
+
sanitizer
|
|
28840
|
+
);
|
|
28754
28841
|
return leaf;
|
|
28755
28842
|
});
|
|
28756
|
-
return {
|
|
28843
|
+
return {
|
|
28844
|
+
leaves,
|
|
28845
|
+
callConstructor: this.getDepositCall.bind(
|
|
28846
|
+
this
|
|
28847
|
+
)
|
|
28848
|
+
};
|
|
28757
28849
|
}
|
|
28758
28850
|
getWithdrawAdapter() {
|
|
28759
28851
|
const leafConfigs = this._getWithdrawLeaf();
|
|
28760
28852
|
const leaves = leafConfigs.map((config) => {
|
|
28761
28853
|
const { target, method, packedArguments, sanitizer, id } = config;
|
|
28762
|
-
const leaf = this.constructSimpleLeafData(
|
|
28763
|
-
|
|
28764
|
-
|
|
28765
|
-
|
|
28766
|
-
|
|
28767
|
-
|
|
28854
|
+
const leaf = this.constructSimpleLeafData(
|
|
28855
|
+
{
|
|
28856
|
+
id,
|
|
28857
|
+
target,
|
|
28858
|
+
method,
|
|
28859
|
+
packedArguments
|
|
28860
|
+
},
|
|
28861
|
+
sanitizer
|
|
28862
|
+
);
|
|
28768
28863
|
return leaf;
|
|
28769
28864
|
});
|
|
28770
|
-
return {
|
|
28865
|
+
return {
|
|
28866
|
+
leaves,
|
|
28867
|
+
callConstructor: this.getWithdrawCall.bind(
|
|
28868
|
+
this
|
|
28869
|
+
)
|
|
28870
|
+
};
|
|
28771
28871
|
}
|
|
28772
28872
|
async getDepositCall(params) {
|
|
28773
28873
|
const collateral = this.config.collateral;
|
|
28774
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28874
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28875
|
+
this.config.poolId
|
|
28876
|
+
);
|
|
28775
28877
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
28776
28878
|
const uint256MarginAmount = import_starknet21.uint256.bnToUint256(params.amount.toWei());
|
|
28777
28879
|
return [
|
|
@@ -28843,7 +28945,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28843
28945
|
];
|
|
28844
28946
|
}
|
|
28845
28947
|
async getWithdrawCall(params) {
|
|
28846
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28948
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28949
|
+
this.config.poolId
|
|
28950
|
+
);
|
|
28847
28951
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
28848
28952
|
return [
|
|
28849
28953
|
// Switch delegation on
|
|
@@ -28898,7 +29002,11 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28898
29002
|
];
|
|
28899
29003
|
}
|
|
28900
29004
|
async getMultiplyCallCalldata(params, isDeposit) {
|
|
28901
|
-
logger.verbose(
|
|
29005
|
+
logger.verbose(
|
|
29006
|
+
`${_VesuMultiplyAdapter.name}::getMultiplyCallCalldata params: ${JSON.stringify(
|
|
29007
|
+
params
|
|
29008
|
+
)}, isDeposit: ${isDeposit}, collateral: ${this.config.collateral.symbol}, debt: ${this.config.debt.symbol}`
|
|
29009
|
+
);
|
|
28902
29010
|
const { isV2 } = getVesuSingletonAddress(this.config.poolId);
|
|
28903
29011
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
28904
29012
|
const multiplyContract = new import_starknet21.Contract({
|
|
@@ -28908,42 +29016,83 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28908
29016
|
});
|
|
28909
29017
|
let leverSwap = [];
|
|
28910
29018
|
let leverSwapLimitAmount = Web3Number.fromWei(0, this.config.debt.decimals);
|
|
28911
|
-
const existingPositions = await this.vesuAdapter.getPositions(
|
|
28912
|
-
|
|
29019
|
+
const existingPositions = await this.vesuAdapter.getPositions(
|
|
29020
|
+
this.config.networkConfig
|
|
29021
|
+
);
|
|
29022
|
+
const collateralisation = await this.vesuAdapter.getCollateralization(
|
|
29023
|
+
this.config.networkConfig
|
|
29024
|
+
);
|
|
28913
29025
|
const existingCollateralInfo = existingPositions[0];
|
|
28914
29026
|
const existingDebtInfo = existingPositions[1];
|
|
28915
29027
|
const isDexPriceRequired = existingDebtInfo.token.symbol !== "USDC";
|
|
28916
|
-
logger.debug(`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall existingCollateralInfo: ${JSON.stringify(
|
|
28917
|
-
|
|
29028
|
+
logger.debug(`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall existingCollateralInfo: ${JSON.stringify(
|
|
29029
|
+
existingCollateralInfo
|
|
29030
|
+
)},
|
|
29031
|
+
existingDebtInfo: ${JSON.stringify(
|
|
29032
|
+
existingDebtInfo
|
|
29033
|
+
)}, collateralisation: ${JSON.stringify(collateralisation)}`);
|
|
28918
29034
|
const collateralPrice = collateralisation[0].usdValue > 0 ? collateralisation[0].usdValue / existingCollateralInfo.amount.toNumber() : (await this.config.pricer.getPrice(this.config.collateral.symbol)).price;
|
|
28919
29035
|
const debtPrice = collateralisation[1].usdValue > 0 ? collateralisation[1].usdValue / existingDebtInfo.amount.toNumber() : (await this.config.pricer.getPrice(this.config.debt.symbol)).price;
|
|
28920
|
-
logger.debug(
|
|
28921
|
-
|
|
28922
|
-
|
|
28923
|
-
const
|
|
28924
|
-
|
|
29036
|
+
logger.debug(
|
|
29037
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall collateralPrice: ${collateralPrice}, debtPrice: ${debtPrice}`
|
|
29038
|
+
);
|
|
29039
|
+
const legLTV = await this.vesuAdapter.getLTVConfig(
|
|
29040
|
+
this.config.networkConfig
|
|
29041
|
+
);
|
|
29042
|
+
const ekuboQuoter = new EkuboQuoter(
|
|
29043
|
+
this.config.networkConfig,
|
|
29044
|
+
this.config.pricer
|
|
29045
|
+
);
|
|
29046
|
+
const dexPrice = isDexPriceRequired ? await ekuboQuoter.getDexPrice(
|
|
29047
|
+
this.config.collateral,
|
|
29048
|
+
this.config.debt,
|
|
29049
|
+
this.config.quoteAmountToFetchPrice
|
|
29050
|
+
) : 1;
|
|
29051
|
+
logger.verbose(
|
|
29052
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall dexPrice: ${dexPrice}, ltv: ${legLTV}`
|
|
29053
|
+
);
|
|
28925
29054
|
const addedCollateral = params.amount.multipliedBy(isDeposit ? 1 : -1);
|
|
28926
|
-
logger.verbose(
|
|
29055
|
+
logger.verbose(
|
|
29056
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall addedCollateral: ${addedCollateral}`
|
|
29057
|
+
);
|
|
28927
29058
|
const numeratorPart1 = existingCollateralInfo.amount.plus(addedCollateral).multipliedBy(collateralPrice).multipliedBy(legLTV);
|
|
28928
|
-
logger.verbose(
|
|
29059
|
+
logger.verbose(
|
|
29060
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart1: ${numeratorPart1}`
|
|
29061
|
+
);
|
|
28929
29062
|
const numeratorPart2 = existingDebtInfo.amount.multipliedBy(debtPrice).multipliedBy(this.config.targetHealthFactor);
|
|
28930
|
-
logger.verbose(
|
|
29063
|
+
logger.verbose(
|
|
29064
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart2: ${numeratorPart2}`
|
|
29065
|
+
);
|
|
28931
29066
|
const denominatorPart = this.config.targetHealthFactor - legLTV / dexPrice;
|
|
28932
|
-
logger.verbose(
|
|
29067
|
+
logger.verbose(
|
|
29068
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall denominatorPart: ${denominatorPart}`
|
|
29069
|
+
);
|
|
28933
29070
|
const x_debt_usd = numeratorPart1.minus(numeratorPart2).dividedBy(denominatorPart);
|
|
28934
|
-
logger.verbose(
|
|
28935
|
-
|
|
28936
|
-
|
|
29071
|
+
logger.verbose(
|
|
29072
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall x_debt_usd: ${x_debt_usd}`
|
|
29073
|
+
);
|
|
29074
|
+
logger.debug(
|
|
29075
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart1: ${numeratorPart1}, numeratorPart2: ${numeratorPart2}, denominatorPart: ${denominatorPart}`
|
|
29076
|
+
);
|
|
29077
|
+
let debtAmount = new Web3Number(
|
|
29078
|
+
x_debt_usd.dividedBy(debtPrice).toFixed(this.config.debt.decimals),
|
|
29079
|
+
this.config.debt.decimals
|
|
29080
|
+
);
|
|
28937
29081
|
const marginAmount = addedCollateral;
|
|
28938
29082
|
const collateralToken = this.config.collateral;
|
|
28939
29083
|
const debtToken = this.config.debt;
|
|
28940
|
-
const debtAmountInCollateralUnits = new Web3Number(
|
|
29084
|
+
const debtAmountInCollateralUnits = new Web3Number(
|
|
29085
|
+
debtAmount.multipliedBy(debtPrice).dividedBy(collateralPrice).multipliedBy(10 ** collateralToken.decimals).toFixed(0),
|
|
29086
|
+
collateralToken.decimals
|
|
29087
|
+
);
|
|
28941
29088
|
const isIncrease = debtAmount.greaterThanOrEqualTo(0);
|
|
28942
29089
|
if (isIncrease && debtAmount.lessThan(0)) {
|
|
28943
29090
|
} else if (!isIncrease && debtAmount.greaterThan(0)) {
|
|
28944
29091
|
debtAmount = Web3Number.fromWei(0, this.config.debt.decimals);
|
|
28945
29092
|
}
|
|
28946
|
-
logger.verbose(
|
|
29093
|
+
logger.verbose(
|
|
29094
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall debtAmount: ${debtAmount}, marginAmount: ${marginAmount}`
|
|
29095
|
+
);
|
|
28947
29096
|
if (!debtAmount.isZero()) {
|
|
28948
29097
|
try {
|
|
28949
29098
|
const swapQuote = await ekuboQuoter.getQuote(
|
|
@@ -28953,26 +29102,49 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28953
29102
|
// negative for exact amount out
|
|
28954
29103
|
);
|
|
28955
29104
|
if (swapQuote.price_impact < 0.01) {
|
|
28956
|
-
leverSwap = ekuboQuoter.getVesuMultiplyQuote(
|
|
29105
|
+
leverSwap = debtAmount.isNegative() ? ekuboQuoter.getVesuMultiplyQuote(
|
|
29106
|
+
swapQuote,
|
|
29107
|
+
collateralToken,
|
|
29108
|
+
debtToken
|
|
29109
|
+
) : ekuboQuoter.getVesuMultiplyQuote(
|
|
29110
|
+
swapQuote,
|
|
29111
|
+
debtToken,
|
|
29112
|
+
collateralToken
|
|
29113
|
+
);
|
|
28957
29114
|
const MAX_SLIPPAGE = 2e-3;
|
|
28958
29115
|
if (debtAmount.greaterThan(0)) {
|
|
28959
29116
|
leverSwapLimitAmount = debtAmount.multipliedBy(1 + MAX_SLIPPAGE);
|
|
28960
29117
|
} else if (debtAmount.lessThan(0)) {
|
|
28961
29118
|
leverSwapLimitAmount = debtAmount.abs().multipliedBy(1 - MAX_SLIPPAGE);
|
|
28962
29119
|
} else {
|
|
28963
|
-
leverSwapLimitAmount = Web3Number.fromWei(
|
|
29120
|
+
leverSwapLimitAmount = Web3Number.fromWei(
|
|
29121
|
+
0,
|
|
29122
|
+
this.config.debt.decimals
|
|
29123
|
+
);
|
|
28964
29124
|
}
|
|
28965
29125
|
await new Promise((resolve) => setTimeout(resolve, 1e4));
|
|
28966
29126
|
} else {
|
|
28967
|
-
throw new Error(
|
|
29127
|
+
throw new Error(
|
|
29128
|
+
`VesuMultiplyAdapter: Price impact too high (${swapQuote.price_impact}), skipping swap`
|
|
29129
|
+
);
|
|
28968
29130
|
}
|
|
28969
29131
|
} catch (error) {
|
|
28970
|
-
throw new Error(
|
|
29132
|
+
throw new Error(
|
|
29133
|
+
`VesuMultiplyAdapter: Failed to get swap quote: ${error}`
|
|
29134
|
+
);
|
|
28971
29135
|
}
|
|
28972
29136
|
}
|
|
28973
|
-
const multiplyParams = await this.getLeverParams(
|
|
29137
|
+
const multiplyParams = await this.getLeverParams(
|
|
29138
|
+
isIncrease,
|
|
29139
|
+
params,
|
|
29140
|
+
leverSwap,
|
|
29141
|
+
leverSwapLimitAmount
|
|
29142
|
+
);
|
|
28974
29143
|
const call = multiplyContract.populate("modify_lever", {
|
|
28975
|
-
modify_lever_params: this.formatMultiplyParams(
|
|
29144
|
+
modify_lever_params: this.formatMultiplyParams(
|
|
29145
|
+
isIncrease,
|
|
29146
|
+
multiplyParams
|
|
29147
|
+
)
|
|
28976
29148
|
});
|
|
28977
29149
|
return call.calldata;
|
|
28978
29150
|
}
|
|
@@ -28986,7 +29158,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28986
29158
|
add_margin: params.amount,
|
|
28987
29159
|
// multiplied by collateral decimals in format
|
|
28988
29160
|
margin_swap: [],
|
|
28989
|
-
margin_swap_limit_amount: Web3Number.fromWei(
|
|
29161
|
+
margin_swap_limit_amount: Web3Number.fromWei(
|
|
29162
|
+
0,
|
|
29163
|
+
this.config.collateral.decimals
|
|
29164
|
+
),
|
|
28990
29165
|
lever_swap: leverSwap,
|
|
28991
29166
|
lever_swap_limit_amount: leverSwapLimitAmount
|
|
28992
29167
|
} : {
|
|
@@ -29000,7 +29175,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29000
29175
|
lever_swap_limit_amount: leverSwapLimitAmount,
|
|
29001
29176
|
lever_swap_weights: [],
|
|
29002
29177
|
withdraw_swap: [],
|
|
29003
|
-
withdraw_swap_limit_amount: Web3Number.fromWei(
|
|
29178
|
+
withdraw_swap_limit_amount: Web3Number.fromWei(
|
|
29179
|
+
0,
|
|
29180
|
+
this.config.collateral.decimals
|
|
29181
|
+
),
|
|
29004
29182
|
withdraw_swap_weights: [],
|
|
29005
29183
|
close_position: false
|
|
29006
29184
|
};
|
|
@@ -29016,12 +29194,16 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29016
29194
|
});
|
|
29017
29195
|
let leverSwap = [];
|
|
29018
29196
|
let leverSwapLimitAmount = Web3Number.fromWei(0, this.config.debt.decimals);
|
|
29019
|
-
const existingPositions = await this.vesuAdapter.getPositions(
|
|
29197
|
+
const existingPositions = await this.vesuAdapter.getPositions(
|
|
29198
|
+
this.config.networkConfig
|
|
29199
|
+
);
|
|
29020
29200
|
const existingCollateralInfo = existingPositions[0];
|
|
29021
29201
|
const existingDebtInfo = existingPositions[1];
|
|
29022
29202
|
const collateralToken = this.config.collateral;
|
|
29023
29203
|
const debtToken = this.config.debt;
|
|
29024
|
-
const collateralPrice = await this.config.pricer.getPrice(
|
|
29204
|
+
const collateralPrice = await this.config.pricer.getPrice(
|
|
29205
|
+
collateralToken.symbol
|
|
29206
|
+
);
|
|
29025
29207
|
const debtPrice = await this.config.pricer.getPrice(debtToken.symbol);
|
|
29026
29208
|
const { deltadebtAmountUnits: debtAmountToRepay } = calculateDebtReductionAmountForWithdrawal(
|
|
29027
29209
|
existingDebtInfo.amount,
|
|
@@ -29035,8 +29217,14 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29035
29217
|
if (!debtAmountToRepay) {
|
|
29036
29218
|
throw new Error("error calculating debt amount to repay");
|
|
29037
29219
|
}
|
|
29038
|
-
const ekuboQuoter = new EkuboQuoter(
|
|
29039
|
-
|
|
29220
|
+
const ekuboQuoter = new EkuboQuoter(
|
|
29221
|
+
this.config.networkConfig,
|
|
29222
|
+
this.config.pricer
|
|
29223
|
+
);
|
|
29224
|
+
const debtInDebtUnits = new Web3Number(
|
|
29225
|
+
debtAmountToRepay,
|
|
29226
|
+
debtToken.decimals
|
|
29227
|
+
).dividedBy(debtPrice.price).multipliedBy(10 ** debtToken.decimals);
|
|
29040
29228
|
const swapQuote = await ekuboQuoter.getQuote(
|
|
29041
29229
|
debtToken.address.address,
|
|
29042
29230
|
collateralToken.address.address,
|
|
@@ -29044,12 +29232,23 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29044
29232
|
);
|
|
29045
29233
|
const MAX_SLIPPAGE = 2e-3;
|
|
29046
29234
|
if (swapQuote.price_impact < 25e-4) {
|
|
29047
|
-
leverSwap = ekuboQuoter.getVesuMultiplyQuote(
|
|
29235
|
+
leverSwap = ekuboQuoter.getVesuMultiplyQuote(
|
|
29236
|
+
swapQuote,
|
|
29237
|
+
collateralToken,
|
|
29238
|
+
debtToken
|
|
29239
|
+
);
|
|
29048
29240
|
} else {
|
|
29049
|
-
logger.error(
|
|
29241
|
+
logger.error(
|
|
29242
|
+
`VesuMultiplyAdapter: Price impact too high (${swapQuote.price_impact}), skipping swap`
|
|
29243
|
+
);
|
|
29050
29244
|
}
|
|
29051
29245
|
leverSwapLimitAmount = new Web3Number(debtAmountToRepay, debtToken.decimals).abs().multipliedBy(1 + MAX_SLIPPAGE);
|
|
29052
|
-
const multiplyParams = await this.getLeverParams(
|
|
29246
|
+
const multiplyParams = await this.getLeverParams(
|
|
29247
|
+
false,
|
|
29248
|
+
params,
|
|
29249
|
+
leverSwap,
|
|
29250
|
+
leverSwapLimitAmount
|
|
29251
|
+
);
|
|
29053
29252
|
const call = multiplyContract.populate("modify_lever", {
|
|
29054
29253
|
modify_lever_params: this.formatMultiplyParams(false, multiplyParams)
|
|
29055
29254
|
});
|
|
@@ -29059,100 +29258,132 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29059
29258
|
if (isIncrease) {
|
|
29060
29259
|
const _params2 = params;
|
|
29061
29260
|
return {
|
|
29062
|
-
action: new import_starknet21.CairoCustomEnum({
|
|
29063
|
-
|
|
29064
|
-
|
|
29065
|
-
|
|
29066
|
-
|
|
29067
|
-
|
|
29068
|
-
|
|
29261
|
+
action: new import_starknet21.CairoCustomEnum({
|
|
29262
|
+
IncreaseLever: {
|
|
29263
|
+
pool_id: _params2.pool_id.toBigInt(),
|
|
29264
|
+
collateral_asset: _params2.collateral_asset.toBigInt(),
|
|
29265
|
+
debt_asset: _params2.debt_asset.toBigInt(),
|
|
29266
|
+
user: _params2.user.toBigInt(),
|
|
29267
|
+
add_margin: BigInt(_params2.add_margin.toWei()),
|
|
29268
|
+
margin_swap: _params2.margin_swap.map((swap) => ({
|
|
29269
|
+
route: swap.route.map((route) => ({
|
|
29270
|
+
pool_key: {
|
|
29271
|
+
token0: route.pool_key.token0.toBigInt(),
|
|
29272
|
+
token1: route.pool_key.token1.toBigInt(),
|
|
29273
|
+
fee: route.pool_key.fee,
|
|
29274
|
+
tick_spacing: route.pool_key.tick_spacing,
|
|
29275
|
+
extension: BigInt(
|
|
29276
|
+
import_starknet21.num.hexToDecimalString(route.pool_key.extension)
|
|
29277
|
+
)
|
|
29278
|
+
},
|
|
29279
|
+
sqrt_ratio_limit: import_starknet21.uint256.bnToUint256(
|
|
29280
|
+
route.sqrt_ratio_limit.toWei()
|
|
29281
|
+
),
|
|
29282
|
+
skip_ahead: BigInt(100)
|
|
29283
|
+
})),
|
|
29284
|
+
token_amount: {
|
|
29285
|
+
token: swap.token_amount.token.toBigInt(),
|
|
29286
|
+
amount: swap.token_amount.amount.toI129()
|
|
29287
|
+
}
|
|
29288
|
+
})),
|
|
29289
|
+
margin_swap_limit_amount: BigInt(
|
|
29290
|
+
_params2.margin_swap_limit_amount.toWei()
|
|
29291
|
+
),
|
|
29292
|
+
lever_swap: _params2.lever_swap.map((swap) => ({
|
|
29293
|
+
route: swap.route.map((route) => ({
|
|
29294
|
+
pool_key: {
|
|
29295
|
+
token0: route.pool_key.token0.toBigInt(),
|
|
29296
|
+
token1: route.pool_key.token1.toBigInt(),
|
|
29297
|
+
fee: route.pool_key.fee,
|
|
29298
|
+
tick_spacing: route.pool_key.tick_spacing,
|
|
29299
|
+
extension: BigInt(
|
|
29300
|
+
import_starknet21.num.hexToDecimalString(route.pool_key.extension)
|
|
29301
|
+
)
|
|
29302
|
+
},
|
|
29303
|
+
sqrt_ratio_limit: import_starknet21.uint256.bnToUint256(
|
|
29304
|
+
route.sqrt_ratio_limit.toWei()
|
|
29305
|
+
),
|
|
29306
|
+
skip_ahead: BigInt(0)
|
|
29307
|
+
})),
|
|
29308
|
+
token_amount: {
|
|
29309
|
+
token: swap.token_amount.token.toBigInt(),
|
|
29310
|
+
amount: swap.token_amount.amount.toI129()
|
|
29311
|
+
}
|
|
29312
|
+
})),
|
|
29313
|
+
lever_swap_limit_amount: BigInt(
|
|
29314
|
+
_params2.lever_swap_limit_amount.toWei()
|
|
29315
|
+
)
|
|
29316
|
+
}
|
|
29317
|
+
})
|
|
29318
|
+
};
|
|
29319
|
+
}
|
|
29320
|
+
const _params = params;
|
|
29321
|
+
return {
|
|
29322
|
+
action: new import_starknet21.CairoCustomEnum({
|
|
29323
|
+
DecreaseLever: {
|
|
29324
|
+
pool_id: _params.pool_id.toBigInt(),
|
|
29325
|
+
collateral_asset: _params.collateral_asset.toBigInt(),
|
|
29326
|
+
debt_asset: _params.debt_asset.toBigInt(),
|
|
29327
|
+
user: _params.user.toBigInt(),
|
|
29328
|
+
sub_margin: BigInt(_params.sub_margin.toWei()),
|
|
29329
|
+
recipient: _params.recipient.toBigInt(),
|
|
29330
|
+
lever_swap: _params.lever_swap.map((swap) => ({
|
|
29069
29331
|
route: swap.route.map((route) => ({
|
|
29070
29332
|
pool_key: {
|
|
29071
29333
|
token0: route.pool_key.token0.toBigInt(),
|
|
29072
29334
|
token1: route.pool_key.token1.toBigInt(),
|
|
29073
29335
|
fee: route.pool_key.fee,
|
|
29074
29336
|
tick_spacing: route.pool_key.tick_spacing,
|
|
29075
|
-
extension:
|
|
29337
|
+
extension: ContractAddr.from(
|
|
29338
|
+
route.pool_key.extension
|
|
29339
|
+
).toBigInt()
|
|
29076
29340
|
},
|
|
29077
|
-
sqrt_ratio_limit: import_starknet21.uint256.bnToUint256(
|
|
29078
|
-
|
|
29341
|
+
sqrt_ratio_limit: import_starknet21.uint256.bnToUint256(
|
|
29342
|
+
route.sqrt_ratio_limit.toWei()
|
|
29343
|
+
),
|
|
29344
|
+
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
29079
29345
|
})),
|
|
29080
29346
|
token_amount: {
|
|
29081
29347
|
token: swap.token_amount.token.toBigInt(),
|
|
29082
29348
|
amount: swap.token_amount.amount.toI129()
|
|
29083
29349
|
}
|
|
29084
29350
|
})),
|
|
29085
|
-
|
|
29086
|
-
|
|
29351
|
+
lever_swap_limit_amount: BigInt(
|
|
29352
|
+
_params.lever_swap_limit_amount.toWei()
|
|
29353
|
+
),
|
|
29354
|
+
lever_swap_weights: _params.lever_swap_weights.map(
|
|
29355
|
+
(weight) => BigInt(weight.toWei())
|
|
29356
|
+
),
|
|
29357
|
+
withdraw_swap: _params.withdraw_swap.map((swap) => ({
|
|
29087
29358
|
route: swap.route.map((route) => ({
|
|
29088
29359
|
pool_key: {
|
|
29089
29360
|
token0: route.pool_key.token0.toBigInt(),
|
|
29090
29361
|
token1: route.pool_key.token1.toBigInt(),
|
|
29091
29362
|
fee: route.pool_key.fee,
|
|
29092
29363
|
tick_spacing: route.pool_key.tick_spacing,
|
|
29093
|
-
extension:
|
|
29364
|
+
extension: ContractAddr.from(
|
|
29365
|
+
route.pool_key.extension
|
|
29366
|
+
).toBigInt()
|
|
29094
29367
|
},
|
|
29095
|
-
sqrt_ratio_limit: import_starknet21.uint256.bnToUint256(
|
|
29096
|
-
|
|
29368
|
+
sqrt_ratio_limit: import_starknet21.uint256.bnToUint256(
|
|
29369
|
+
route.sqrt_ratio_limit.toWei()
|
|
29370
|
+
),
|
|
29371
|
+
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
29097
29372
|
})),
|
|
29098
29373
|
token_amount: {
|
|
29099
29374
|
token: swap.token_amount.token.toBigInt(),
|
|
29100
29375
|
amount: swap.token_amount.amount.toI129()
|
|
29101
29376
|
}
|
|
29102
29377
|
})),
|
|
29103
|
-
|
|
29104
|
-
|
|
29105
|
-
|
|
29106
|
-
|
|
29107
|
-
|
|
29108
|
-
|
|
29109
|
-
|
|
29110
|
-
|
|
29111
|
-
|
|
29112
|
-
debt_asset: _params.debt_asset.toBigInt(),
|
|
29113
|
-
user: _params.user.toBigInt(),
|
|
29114
|
-
sub_margin: BigInt(_params.sub_margin.toWei()),
|
|
29115
|
-
recipient: _params.recipient.toBigInt(),
|
|
29116
|
-
lever_swap: _params.lever_swap.map((swap) => ({
|
|
29117
|
-
route: swap.route.map((route) => ({
|
|
29118
|
-
pool_key: {
|
|
29119
|
-
token0: route.pool_key.token0.toBigInt(),
|
|
29120
|
-
token1: route.pool_key.token1.toBigInt(),
|
|
29121
|
-
fee: route.pool_key.fee,
|
|
29122
|
-
tick_spacing: route.pool_key.tick_spacing,
|
|
29123
|
-
extension: ContractAddr.from(route.pool_key.extension).toBigInt()
|
|
29124
|
-
},
|
|
29125
|
-
sqrt_ratio_limit: import_starknet21.uint256.bnToUint256(route.sqrt_ratio_limit.toWei()),
|
|
29126
|
-
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
29127
|
-
})),
|
|
29128
|
-
token_amount: {
|
|
29129
|
-
token: swap.token_amount.token.toBigInt(),
|
|
29130
|
-
amount: swap.token_amount.amount.toI129()
|
|
29131
|
-
}
|
|
29132
|
-
})),
|
|
29133
|
-
lever_swap_limit_amount: BigInt(_params.lever_swap_limit_amount.toWei()),
|
|
29134
|
-
lever_swap_weights: _params.lever_swap_weights.map((weight) => BigInt(weight.toWei())),
|
|
29135
|
-
withdraw_swap: _params.withdraw_swap.map((swap) => ({
|
|
29136
|
-
route: swap.route.map((route) => ({
|
|
29137
|
-
pool_key: {
|
|
29138
|
-
token0: route.pool_key.token0.toBigInt(),
|
|
29139
|
-
token1: route.pool_key.token1.toBigInt(),
|
|
29140
|
-
fee: route.pool_key.fee,
|
|
29141
|
-
tick_spacing: route.pool_key.tick_spacing,
|
|
29142
|
-
extension: ContractAddr.from(route.pool_key.extension).toBigInt()
|
|
29143
|
-
},
|
|
29144
|
-
sqrt_ratio_limit: import_starknet21.uint256.bnToUint256(route.sqrt_ratio_limit.toWei()),
|
|
29145
|
-
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
29146
|
-
})),
|
|
29147
|
-
token_amount: {
|
|
29148
|
-
token: swap.token_amount.token.toBigInt(),
|
|
29149
|
-
amount: swap.token_amount.amount.toI129()
|
|
29150
|
-
}
|
|
29151
|
-
})),
|
|
29152
|
-
withdraw_swap_limit_amount: BigInt(_params.withdraw_swap_limit_amount.toWei()),
|
|
29153
|
-
withdraw_swap_weights: _params.withdraw_swap_weights.map((weight) => BigInt(weight.toWei())),
|
|
29154
|
-
close_position: _params.close_position
|
|
29155
|
-
} })
|
|
29378
|
+
withdraw_swap_limit_amount: BigInt(
|
|
29379
|
+
_params.withdraw_swap_limit_amount.toWei()
|
|
29380
|
+
),
|
|
29381
|
+
withdraw_swap_weights: _params.withdraw_swap_weights.map(
|
|
29382
|
+
(weight) => BigInt(weight.toWei())
|
|
29383
|
+
),
|
|
29384
|
+
close_position: _params.close_position
|
|
29385
|
+
}
|
|
29386
|
+
})
|
|
29156
29387
|
};
|
|
29157
29388
|
}
|
|
29158
29389
|
async getHealthFactor() {
|
|
@@ -29161,11 +29392,15 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29161
29392
|
}
|
|
29162
29393
|
async getNetAPY() {
|
|
29163
29394
|
const positions = await this.getPositions();
|
|
29164
|
-
logger.verbose(
|
|
29395
|
+
logger.verbose(
|
|
29396
|
+
`${this.name}::getNetAPY: positions: ${JSON.stringify(positions)}`
|
|
29397
|
+
);
|
|
29165
29398
|
const allZero = positions.every((p) => p.usdValue === 0);
|
|
29166
29399
|
if (allZero) {
|
|
29167
29400
|
const collateralUSD = 1e3;
|
|
29168
|
-
const maxLTV = await this.vesuAdapter.getLTVConfig(
|
|
29401
|
+
const maxLTV = await this.vesuAdapter.getLTVConfig(
|
|
29402
|
+
this.config.networkConfig
|
|
29403
|
+
);
|
|
29169
29404
|
const targetHF = this.config.targetHealthFactor;
|
|
29170
29405
|
const maxDebt = HealthFactorMath.getMaxDebtAmountOnLooping(
|
|
29171
29406
|
new Web3Number(collateralUSD, this.config.collateral.decimals),
|
|
@@ -29891,6 +30126,7 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29891
30126
|
logger.error("error initializing client");
|
|
29892
30127
|
return null;
|
|
29893
30128
|
}
|
|
30129
|
+
await new Promise((resolve) => setTimeout(resolve, 5e3));
|
|
29894
30130
|
const orderhistory = await this.getOrderHistory(marketName);
|
|
29895
30131
|
if (!orderhistory || orderhistory.length === 0) {
|
|
29896
30132
|
logger.error(`error getting order: ${orderId}`);
|
|
@@ -34271,7 +34507,7 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34271
34507
|
const withdrawalFromExtended = await extendedAdapter.withdrawFromExtended(params.amount);
|
|
34272
34508
|
if (withdrawalFromExtended) {
|
|
34273
34509
|
const extendedHoldings2 = await extendedAdapter.getExtendedDepositAmount();
|
|
34274
|
-
logger.info(`extendedHoldings after withdrawal ${extendedHoldings2}`);
|
|
34510
|
+
logger.info(`extendedHoldings after withdrawal ${extendedHoldings2?.availableForWithdrawal}`);
|
|
34275
34511
|
await new Promise((resolve) => setTimeout(resolve, 1e4));
|
|
34276
34512
|
const calls = await this.moveAssetsToVaultAllocator(params.amount, extendedAdapter);
|
|
34277
34513
|
if (calls.length > 0) {
|