@strkfarm/sdk 2.0.0-dev.4 → 2.0.0-dev.6
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 +490 -203
- package/dist/index.browser.mjs +490 -203
- package/dist/index.js +490 -203
- package/dist/index.mjs +490 -203
- package/package.json +1 -1
- package/src/strategies/universal-adapters/avnu-adapter.ts +1 -1
- package/src/strategies/universal-adapters/extended-adapter.ts +150 -72
- package/src/strategies/universal-adapters/vesu-multiply-adapter.ts +775 -395
- package/src/strategies/vesu-extended-strategy/utils/helper.ts +2 -4
- package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +9 -8
package/dist/index.js
CHANGED
|
@@ -28207,8 +28207,7 @@ var calculateAmountDistribution = async (amount, client, marketName, collateralP
|
|
|
28207
28207
|
vesu_leverage: 0
|
|
28208
28208
|
};
|
|
28209
28209
|
}
|
|
28210
|
-
const
|
|
28211
|
-
const extendedExposureUSD = extendedBTCExposure.multipliedBy(collateralPrice);
|
|
28210
|
+
const extendedExposureUSD = extendedPosition.length > 0 ? new Web3Number(extendedPosition[0].value, WBTC_TOKEN_DECIMALS) : new Web3Number(0, WBTC_TOKEN_DECIMALS);
|
|
28212
28211
|
const vesuBTCExposureUSD = collateralUnits.multipliedBy(collateralPrice);
|
|
28213
28212
|
const numerator1 = vesu_leverage * amount + vesuBTCExposureUSD.toNumber();
|
|
28214
28213
|
const numerator2 = extendedExposureUSD.toNumber();
|
|
@@ -28426,21 +28425,35 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28426
28425
|
vaultAllocator: config.vaultAllocator,
|
|
28427
28426
|
id: ""
|
|
28428
28427
|
});
|
|
28429
|
-
this.tokenMarketData = new TokenMarketData(
|
|
28428
|
+
this.tokenMarketData = new TokenMarketData(
|
|
28429
|
+
this.config.pricer,
|
|
28430
|
+
this.config.networkConfig
|
|
28431
|
+
);
|
|
28430
28432
|
}
|
|
28431
28433
|
async getAPY(supportedPosition) {
|
|
28432
28434
|
const CACHE_KEY = `apy_${this.config.poolId.address}_${supportedPosition.asset.symbol}`;
|
|
28433
28435
|
const cacheData = this.getCache(CACHE_KEY);
|
|
28434
|
-
console.log(
|
|
28436
|
+
console.log(
|
|
28437
|
+
`${_VesuMultiplyAdapter.name}::getAPY cacheData: ${JSON.stringify(
|
|
28438
|
+
cacheData
|
|
28439
|
+
)}`,
|
|
28440
|
+
this.vesuAdapter.config.poolId.shortString(),
|
|
28441
|
+
this.vesuAdapter.config.collateral.symbol,
|
|
28442
|
+
this.vesuAdapter.config.debt.symbol
|
|
28443
|
+
);
|
|
28435
28444
|
if (cacheData) {
|
|
28436
28445
|
return cacheData;
|
|
28437
28446
|
}
|
|
28438
28447
|
try {
|
|
28439
28448
|
const allVesuPools = await VesuAdapter.getVesuPools();
|
|
28440
28449
|
const asset = supportedPosition.asset;
|
|
28441
|
-
const pool = allVesuPools.pools.find(
|
|
28450
|
+
const pool = allVesuPools.pools.find(
|
|
28451
|
+
(p) => this.vesuAdapter.config.poolId.eqString(import_starknet21.num.getHexString(p.id))
|
|
28452
|
+
);
|
|
28442
28453
|
if (!pool) {
|
|
28443
|
-
logger.warn(
|
|
28454
|
+
logger.warn(
|
|
28455
|
+
`VesuMultiplyAdapter: Pool not found for token ${asset.symbol}`
|
|
28456
|
+
);
|
|
28444
28457
|
return {
|
|
28445
28458
|
apy: 0,
|
|
28446
28459
|
type: "base" /* BASE */
|
|
@@ -28450,7 +28463,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28450
28463
|
(a) => a.symbol.toLowerCase() === asset.symbol.toLowerCase()
|
|
28451
28464
|
)?.stats;
|
|
28452
28465
|
if (!assetStats) {
|
|
28453
|
-
logger.warn(
|
|
28466
|
+
logger.warn(
|
|
28467
|
+
`VesuMultiplyAdapter: Asset stats not found for token ${asset.symbol}`
|
|
28468
|
+
);
|
|
28454
28469
|
return {
|
|
28455
28470
|
apy: 0,
|
|
28456
28471
|
type: "base" /* BASE */
|
|
@@ -28461,7 +28476,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28461
28476
|
apy = Number(assetStats.borrowApr?.value || 0) / 1e18;
|
|
28462
28477
|
} else {
|
|
28463
28478
|
const isAssetBTC = asset.symbol.toLowerCase().includes("btc");
|
|
28464
|
-
const baseAPY = Number(
|
|
28479
|
+
const baseAPY = Number(
|
|
28480
|
+
isAssetBTC ? assetStats.btcFiSupplyApr?.value + assetStats.supplyApy?.value : assetStats.supplyApy?.value || 0
|
|
28481
|
+
) / 1e18;
|
|
28465
28482
|
const rewardAPY = Number(assetStats.defiSpringSupplyApr?.value || "0") / 1e18;
|
|
28466
28483
|
const isSupported = this.tokenMarketData.isAPYSupported(asset);
|
|
28467
28484
|
apy = baseAPY + rewardAPY;
|
|
@@ -28477,7 +28494,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28477
28494
|
this.setCache(CACHE_KEY, result, 3e5);
|
|
28478
28495
|
return result;
|
|
28479
28496
|
} catch (error) {
|
|
28480
|
-
logger.error(
|
|
28497
|
+
logger.error(
|
|
28498
|
+
`VesuMultiplyAdapter: Error getting APY for ${supportedPosition.asset.symbol}:`,
|
|
28499
|
+
error
|
|
28500
|
+
);
|
|
28481
28501
|
throw error;
|
|
28482
28502
|
}
|
|
28483
28503
|
}
|
|
@@ -28490,12 +28510,16 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28490
28510
|
try {
|
|
28491
28511
|
this.vesuAdapter.networkConfig = this.config.networkConfig;
|
|
28492
28512
|
this.vesuAdapter.pricer = this.config.pricer;
|
|
28493
|
-
const positions = await this.vesuAdapter.getPositions(
|
|
28513
|
+
const positions = await this.vesuAdapter.getPositions(
|
|
28514
|
+
this.config.networkConfig
|
|
28515
|
+
);
|
|
28494
28516
|
let position = positions.find(
|
|
28495
28517
|
(p) => p.token.address.eq(supportedPosition.asset.address)
|
|
28496
28518
|
);
|
|
28497
28519
|
if (!position) {
|
|
28498
|
-
logger.warn(
|
|
28520
|
+
logger.warn(
|
|
28521
|
+
`VesuMultiplyAdapter: Position not found for token ${supportedPosition.asset.symbol}`
|
|
28522
|
+
);
|
|
28499
28523
|
return {
|
|
28500
28524
|
amount: new Web3Number("0", supportedPosition.asset.decimals),
|
|
28501
28525
|
remarks: "Position not found"
|
|
@@ -28508,12 +28532,18 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28508
28532
|
this.setCache(CACHE_KEY, position, 6e4);
|
|
28509
28533
|
return position;
|
|
28510
28534
|
} catch (error) {
|
|
28511
|
-
logger.error(
|
|
28535
|
+
logger.error(
|
|
28536
|
+
`VesuMultiplyAdapter: Error getting position for ${supportedPosition.asset.symbol}:`,
|
|
28537
|
+
error
|
|
28538
|
+
);
|
|
28512
28539
|
throw error;
|
|
28513
28540
|
}
|
|
28514
28541
|
}
|
|
28515
28542
|
async maxBorrowableAPY() {
|
|
28516
|
-
const collateralAPY = await this.getAPY({
|
|
28543
|
+
const collateralAPY = await this.getAPY({
|
|
28544
|
+
asset: this.config.collateral,
|
|
28545
|
+
isDebt: false
|
|
28546
|
+
});
|
|
28517
28547
|
const apy = collateralAPY.apy * 0.8;
|
|
28518
28548
|
return apy;
|
|
28519
28549
|
}
|
|
@@ -28523,9 +28553,15 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28523
28553
|
try {
|
|
28524
28554
|
this.vesuAdapter.networkConfig = this.config.networkConfig;
|
|
28525
28555
|
this.vesuAdapter.pricer = this.config.pricer;
|
|
28526
|
-
const positions = await this.vesuAdapter.getPositions(
|
|
28527
|
-
|
|
28528
|
-
|
|
28556
|
+
const positions = await this.vesuAdapter.getPositions(
|
|
28557
|
+
this.config.networkConfig
|
|
28558
|
+
);
|
|
28559
|
+
const collateralPosition = positions.find(
|
|
28560
|
+
(p) => p.token.address.eq(collateral.address)
|
|
28561
|
+
);
|
|
28562
|
+
const debtPosition = positions.find(
|
|
28563
|
+
(p) => p.token.address.eq(debt.address)
|
|
28564
|
+
);
|
|
28529
28565
|
if (!collateralPosition || !debtPosition) {
|
|
28530
28566
|
throw new Error("Could not find current positions");
|
|
28531
28567
|
}
|
|
@@ -28535,13 +28571,23 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28535
28571
|
debt,
|
|
28536
28572
|
maxBorrowableAPY
|
|
28537
28573
|
);
|
|
28538
|
-
logger.verbose(
|
|
28539
|
-
|
|
28574
|
+
logger.verbose(
|
|
28575
|
+
`VesuMultiplyAdapter: Max borrowable: ${maxBorrowable.toNumber()}`
|
|
28576
|
+
);
|
|
28577
|
+
const debtCap = await this.vesuAdapter.getDebtCap(
|
|
28578
|
+
this.config.networkConfig
|
|
28579
|
+
);
|
|
28540
28580
|
logger.verbose(`VesuMultiplyAdapter: Debt cap: ${debtCap.toNumber()}`);
|
|
28541
28581
|
const actualMaxBorrowable = maxBorrowable.minimum(debtCap);
|
|
28542
|
-
logger.verbose(
|
|
28543
|
-
|
|
28544
|
-
|
|
28582
|
+
logger.verbose(
|
|
28583
|
+
`VesuMultiplyAdapter: Actual max borrowable: ${actualMaxBorrowable.toNumber()}`
|
|
28584
|
+
);
|
|
28585
|
+
const maxLTV = await this.vesuAdapter.getLTVConfig(
|
|
28586
|
+
this.config.networkConfig
|
|
28587
|
+
);
|
|
28588
|
+
const collateralPrice = await this.config.pricer.getPrice(
|
|
28589
|
+
collateral.symbol
|
|
28590
|
+
);
|
|
28545
28591
|
if (collateralPrice.price === 0) {
|
|
28546
28592
|
throw new Error("Collateral price is 0");
|
|
28547
28593
|
}
|
|
@@ -28559,14 +28605,25 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28559
28605
|
);
|
|
28560
28606
|
const maxDepositAmount = amount ? amount.minimum(maxCollateralFromDebt) : maxCollateralFromDebt;
|
|
28561
28607
|
const usdValue = await this.getUSDValue(collateral, maxDepositAmount);
|
|
28562
|
-
logger.verbose(
|
|
28563
|
-
|
|
28564
|
-
|
|
28608
|
+
logger.verbose(
|
|
28609
|
+
`VesuMultiplyAdapter: Max deposit::USD value: ${usdValue}, amount: ${maxDepositAmount.toNumber()}`
|
|
28610
|
+
);
|
|
28611
|
+
const apys = await Promise.all([
|
|
28612
|
+
this.getAPY({ asset: collateral, isDebt: false }),
|
|
28613
|
+
this.getAPY({ asset: debt, isDebt: true })
|
|
28614
|
+
]);
|
|
28615
|
+
logger.verbose(
|
|
28616
|
+
`VesuMultiplyAdapter: Apys: ${apys[0].apy}, ${apys[1].apy}`
|
|
28617
|
+
);
|
|
28565
28618
|
const borrowAmountUSD = actualMaxBorrowable.multipliedBy(debtPrice.price);
|
|
28566
|
-
logger.verbose(
|
|
28619
|
+
logger.verbose(
|
|
28620
|
+
`VesuMultiplyAdapter: Borrow amount: ${actualMaxBorrowable.toNumber()}, borrow amount USD: ${borrowAmountUSD.toNumber()}`
|
|
28621
|
+
);
|
|
28567
28622
|
const netCollateralUSD = usdValue + borrowAmountUSD.toNumber();
|
|
28568
28623
|
const netAPY = (apys[0].apy * netCollateralUSD + apys[1].apy * borrowAmountUSD.toNumber()) / usdValue;
|
|
28569
|
-
logger.verbose(
|
|
28624
|
+
logger.verbose(
|
|
28625
|
+
`VesuMultiplyAdapter: Max deposit amount: ${maxDepositAmount.toNumber()}, netAPY: ${netAPY}`
|
|
28626
|
+
);
|
|
28570
28627
|
return {
|
|
28571
28628
|
tokenInfo: collateral,
|
|
28572
28629
|
amount: maxDepositAmount,
|
|
@@ -28579,7 +28636,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28579
28636
|
protocol: this.protocol
|
|
28580
28637
|
};
|
|
28581
28638
|
} catch (error) {
|
|
28582
|
-
logger.error(
|
|
28639
|
+
logger.error(
|
|
28640
|
+
`VesuMultiplyAdapter: Error calculating max deposit:`,
|
|
28641
|
+
error
|
|
28642
|
+
);
|
|
28583
28643
|
throw error;
|
|
28584
28644
|
}
|
|
28585
28645
|
}
|
|
@@ -28589,9 +28649,15 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28589
28649
|
try {
|
|
28590
28650
|
this.vesuAdapter.networkConfig = this.config.networkConfig;
|
|
28591
28651
|
this.vesuAdapter.pricer = this.config.pricer;
|
|
28592
|
-
const positions = await this.vesuAdapter.getPositions(
|
|
28593
|
-
|
|
28594
|
-
|
|
28652
|
+
const positions = await this.vesuAdapter.getPositions(
|
|
28653
|
+
this.config.networkConfig
|
|
28654
|
+
);
|
|
28655
|
+
const collateralPosition = positions.find(
|
|
28656
|
+
(p) => p.token.address.eq(collateral.address)
|
|
28657
|
+
);
|
|
28658
|
+
const debtPosition = positions.find(
|
|
28659
|
+
(p) => p.token.address.eq(this.config.debt.address)
|
|
28660
|
+
);
|
|
28595
28661
|
if (!collateralPosition || !debtPosition) {
|
|
28596
28662
|
throw new Error("Could not find current positions");
|
|
28597
28663
|
}
|
|
@@ -28601,11 +28667,20 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28601
28667
|
const result = maxWithdrawable.greaterThan(0) ? maxWithdrawable : new Web3Number("0", collateral.decimals);
|
|
28602
28668
|
const usdValue = await this.getUSDValue(collateral, result);
|
|
28603
28669
|
const debtUSD = debtPosition.usdValue;
|
|
28604
|
-
logger.verbose(
|
|
28605
|
-
|
|
28606
|
-
|
|
28670
|
+
logger.verbose(
|
|
28671
|
+
`VesuMultiplyAdapter: Debt USD: ${debtUSD}, collateral USD: ${usdValue}`
|
|
28672
|
+
);
|
|
28673
|
+
const apys = await Promise.all([
|
|
28674
|
+
this.getAPY({ asset: collateral, isDebt: false }),
|
|
28675
|
+
this.getAPY({ asset: debt, isDebt: true })
|
|
28676
|
+
]);
|
|
28677
|
+
logger.verbose(
|
|
28678
|
+
`VesuMultiplyAdapter: Apys: ${apys[0].apy}, ${apys[1].apy}`
|
|
28679
|
+
);
|
|
28607
28680
|
const netAPY = usdValue - debtUSD > 0 ? (apys[0].apy * usdValue + apys[1].apy * debtUSD) / (usdValue - debtUSD) : 0;
|
|
28608
|
-
logger.verbose(
|
|
28681
|
+
logger.verbose(
|
|
28682
|
+
`VesuMultiplyAdapter: Max withdraw amount: ${result.toNumber()}, netAPY: ${netAPY}`
|
|
28683
|
+
);
|
|
28609
28684
|
return {
|
|
28610
28685
|
tokenInfo: collateral,
|
|
28611
28686
|
amount: result,
|
|
@@ -28618,14 +28693,19 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28618
28693
|
protocol: this.protocol
|
|
28619
28694
|
};
|
|
28620
28695
|
} catch (error) {
|
|
28621
|
-
logger.error(
|
|
28696
|
+
logger.error(
|
|
28697
|
+
`VesuMultiplyAdapter: Error calculating max withdraw:`,
|
|
28698
|
+
error
|
|
28699
|
+
);
|
|
28622
28700
|
throw error;
|
|
28623
28701
|
}
|
|
28624
28702
|
}
|
|
28625
28703
|
_getDepositLeaf() {
|
|
28626
28704
|
const collateral = this.config.collateral;
|
|
28627
28705
|
const debt = this.config.debt;
|
|
28628
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28706
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28707
|
+
this.config.poolId
|
|
28708
|
+
);
|
|
28629
28709
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
28630
28710
|
return [
|
|
28631
28711
|
// Approval step for collateral
|
|
@@ -28689,7 +28769,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28689
28769
|
];
|
|
28690
28770
|
}
|
|
28691
28771
|
_getWithdrawLeaf() {
|
|
28692
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28772
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28773
|
+
this.config.poolId
|
|
28774
|
+
);
|
|
28693
28775
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
28694
28776
|
const collateral = this.config.collateral;
|
|
28695
28777
|
const debt = this.config.debt;
|
|
@@ -28746,33 +28828,51 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28746
28828
|
const leafConfigs = this._getDepositLeaf();
|
|
28747
28829
|
const leaves = leafConfigs.map((config) => {
|
|
28748
28830
|
const { target, method, packedArguments, sanitizer, id } = config;
|
|
28749
|
-
const leaf = this.constructSimpleLeafData(
|
|
28750
|
-
|
|
28751
|
-
|
|
28752
|
-
|
|
28753
|
-
|
|
28754
|
-
|
|
28831
|
+
const leaf = this.constructSimpleLeafData(
|
|
28832
|
+
{
|
|
28833
|
+
id,
|
|
28834
|
+
target,
|
|
28835
|
+
method,
|
|
28836
|
+
packedArguments
|
|
28837
|
+
},
|
|
28838
|
+
sanitizer
|
|
28839
|
+
);
|
|
28755
28840
|
return leaf;
|
|
28756
28841
|
});
|
|
28757
|
-
return {
|
|
28842
|
+
return {
|
|
28843
|
+
leaves,
|
|
28844
|
+
callConstructor: this.getDepositCall.bind(
|
|
28845
|
+
this
|
|
28846
|
+
)
|
|
28847
|
+
};
|
|
28758
28848
|
}
|
|
28759
28849
|
getWithdrawAdapter() {
|
|
28760
28850
|
const leafConfigs = this._getWithdrawLeaf();
|
|
28761
28851
|
const leaves = leafConfigs.map((config) => {
|
|
28762
28852
|
const { target, method, packedArguments, sanitizer, id } = config;
|
|
28763
|
-
const leaf = this.constructSimpleLeafData(
|
|
28764
|
-
|
|
28765
|
-
|
|
28766
|
-
|
|
28767
|
-
|
|
28768
|
-
|
|
28853
|
+
const leaf = this.constructSimpleLeafData(
|
|
28854
|
+
{
|
|
28855
|
+
id,
|
|
28856
|
+
target,
|
|
28857
|
+
method,
|
|
28858
|
+
packedArguments
|
|
28859
|
+
},
|
|
28860
|
+
sanitizer
|
|
28861
|
+
);
|
|
28769
28862
|
return leaf;
|
|
28770
28863
|
});
|
|
28771
|
-
return {
|
|
28864
|
+
return {
|
|
28865
|
+
leaves,
|
|
28866
|
+
callConstructor: this.getWithdrawCall.bind(
|
|
28867
|
+
this
|
|
28868
|
+
)
|
|
28869
|
+
};
|
|
28772
28870
|
}
|
|
28773
28871
|
async getDepositCall(params) {
|
|
28774
28872
|
const collateral = this.config.collateral;
|
|
28775
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28873
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28874
|
+
this.config.poolId
|
|
28875
|
+
);
|
|
28776
28876
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
28777
28877
|
const uint256MarginAmount = import_starknet21.uint256.bnToUint256(params.amount.toWei());
|
|
28778
28878
|
return [
|
|
@@ -28844,7 +28944,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28844
28944
|
];
|
|
28845
28945
|
}
|
|
28846
28946
|
async getWithdrawCall(params) {
|
|
28847
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28947
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28948
|
+
this.config.poolId
|
|
28949
|
+
);
|
|
28848
28950
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
28849
28951
|
return [
|
|
28850
28952
|
// Switch delegation on
|
|
@@ -28899,7 +29001,11 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28899
29001
|
];
|
|
28900
29002
|
}
|
|
28901
29003
|
async getMultiplyCallCalldata(params, isDeposit) {
|
|
28902
|
-
logger.verbose(
|
|
29004
|
+
logger.verbose(
|
|
29005
|
+
`${_VesuMultiplyAdapter.name}::getMultiplyCallCalldata params: ${JSON.stringify(
|
|
29006
|
+
params
|
|
29007
|
+
)}, isDeposit: ${isDeposit}, collateral: ${this.config.collateral.symbol}, debt: ${this.config.debt.symbol}`
|
|
29008
|
+
);
|
|
28903
29009
|
const { isV2 } = getVesuSingletonAddress(this.config.poolId);
|
|
28904
29010
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
28905
29011
|
const multiplyContract = new import_starknet21.Contract({
|
|
@@ -28909,42 +29015,83 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28909
29015
|
});
|
|
28910
29016
|
let leverSwap = [];
|
|
28911
29017
|
let leverSwapLimitAmount = Web3Number.fromWei(0, this.config.debt.decimals);
|
|
28912
|
-
const existingPositions = await this.vesuAdapter.getPositions(
|
|
28913
|
-
|
|
29018
|
+
const existingPositions = await this.vesuAdapter.getPositions(
|
|
29019
|
+
this.config.networkConfig
|
|
29020
|
+
);
|
|
29021
|
+
const collateralisation = await this.vesuAdapter.getCollateralization(
|
|
29022
|
+
this.config.networkConfig
|
|
29023
|
+
);
|
|
28914
29024
|
const existingCollateralInfo = existingPositions[0];
|
|
28915
29025
|
const existingDebtInfo = existingPositions[1];
|
|
28916
29026
|
const isDexPriceRequired = existingDebtInfo.token.symbol !== "USDC";
|
|
28917
|
-
logger.debug(`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall existingCollateralInfo: ${JSON.stringify(
|
|
28918
|
-
|
|
29027
|
+
logger.debug(`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall existingCollateralInfo: ${JSON.stringify(
|
|
29028
|
+
existingCollateralInfo
|
|
29029
|
+
)},
|
|
29030
|
+
existingDebtInfo: ${JSON.stringify(
|
|
29031
|
+
existingDebtInfo
|
|
29032
|
+
)}, collateralisation: ${JSON.stringify(collateralisation)}`);
|
|
28919
29033
|
const collateralPrice = collateralisation[0].usdValue > 0 ? collateralisation[0].usdValue / existingCollateralInfo.amount.toNumber() : (await this.config.pricer.getPrice(this.config.collateral.symbol)).price;
|
|
28920
29034
|
const debtPrice = collateralisation[1].usdValue > 0 ? collateralisation[1].usdValue / existingDebtInfo.amount.toNumber() : (await this.config.pricer.getPrice(this.config.debt.symbol)).price;
|
|
28921
|
-
logger.debug(
|
|
28922
|
-
|
|
28923
|
-
|
|
28924
|
-
const
|
|
28925
|
-
|
|
29035
|
+
logger.debug(
|
|
29036
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall collateralPrice: ${collateralPrice}, debtPrice: ${debtPrice}`
|
|
29037
|
+
);
|
|
29038
|
+
const legLTV = await this.vesuAdapter.getLTVConfig(
|
|
29039
|
+
this.config.networkConfig
|
|
29040
|
+
);
|
|
29041
|
+
const ekuboQuoter = new EkuboQuoter(
|
|
29042
|
+
this.config.networkConfig,
|
|
29043
|
+
this.config.pricer
|
|
29044
|
+
);
|
|
29045
|
+
const dexPrice = isDexPriceRequired ? await ekuboQuoter.getDexPrice(
|
|
29046
|
+
this.config.collateral,
|
|
29047
|
+
this.config.debt,
|
|
29048
|
+
this.config.quoteAmountToFetchPrice
|
|
29049
|
+
) : 1;
|
|
29050
|
+
logger.verbose(
|
|
29051
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall dexPrice: ${dexPrice}, ltv: ${legLTV}`
|
|
29052
|
+
);
|
|
28926
29053
|
const addedCollateral = params.amount.multipliedBy(isDeposit ? 1 : -1);
|
|
28927
|
-
logger.verbose(
|
|
29054
|
+
logger.verbose(
|
|
29055
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall addedCollateral: ${addedCollateral}`
|
|
29056
|
+
);
|
|
28928
29057
|
const numeratorPart1 = existingCollateralInfo.amount.plus(addedCollateral).multipliedBy(collateralPrice).multipliedBy(legLTV);
|
|
28929
|
-
logger.verbose(
|
|
29058
|
+
logger.verbose(
|
|
29059
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart1: ${numeratorPart1}`
|
|
29060
|
+
);
|
|
28930
29061
|
const numeratorPart2 = existingDebtInfo.amount.multipliedBy(debtPrice).multipliedBy(this.config.targetHealthFactor);
|
|
28931
|
-
logger.verbose(
|
|
29062
|
+
logger.verbose(
|
|
29063
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart2: ${numeratorPart2}`
|
|
29064
|
+
);
|
|
28932
29065
|
const denominatorPart = this.config.targetHealthFactor - legLTV / dexPrice;
|
|
28933
|
-
logger.verbose(
|
|
29066
|
+
logger.verbose(
|
|
29067
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall denominatorPart: ${denominatorPart}`
|
|
29068
|
+
);
|
|
28934
29069
|
const x_debt_usd = numeratorPart1.minus(numeratorPart2).dividedBy(denominatorPart);
|
|
28935
|
-
logger.verbose(
|
|
28936
|
-
|
|
28937
|
-
|
|
29070
|
+
logger.verbose(
|
|
29071
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall x_debt_usd: ${x_debt_usd}`
|
|
29072
|
+
);
|
|
29073
|
+
logger.debug(
|
|
29074
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart1: ${numeratorPart1}, numeratorPart2: ${numeratorPart2}, denominatorPart: ${denominatorPart}`
|
|
29075
|
+
);
|
|
29076
|
+
let debtAmount = new Web3Number(
|
|
29077
|
+
x_debt_usd.dividedBy(debtPrice).toFixed(this.config.debt.decimals),
|
|
29078
|
+
this.config.debt.decimals
|
|
29079
|
+
);
|
|
28938
29080
|
const marginAmount = addedCollateral;
|
|
28939
29081
|
const collateralToken = this.config.collateral;
|
|
28940
29082
|
const debtToken = this.config.debt;
|
|
28941
|
-
const debtAmountInCollateralUnits = new Web3Number(
|
|
29083
|
+
const debtAmountInCollateralUnits = new Web3Number(
|
|
29084
|
+
debtAmount.multipliedBy(debtPrice).dividedBy(collateralPrice).multipliedBy(10 ** collateralToken.decimals).toFixed(0),
|
|
29085
|
+
collateralToken.decimals
|
|
29086
|
+
);
|
|
28942
29087
|
const isIncrease = debtAmount.greaterThanOrEqualTo(0);
|
|
28943
29088
|
if (isIncrease && debtAmount.lessThan(0)) {
|
|
28944
29089
|
} else if (!isIncrease && debtAmount.greaterThan(0)) {
|
|
28945
29090
|
debtAmount = Web3Number.fromWei(0, this.config.debt.decimals);
|
|
28946
29091
|
}
|
|
28947
|
-
logger.verbose(
|
|
29092
|
+
logger.verbose(
|
|
29093
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall debtAmount: ${debtAmount}, marginAmount: ${marginAmount}`
|
|
29094
|
+
);
|
|
28948
29095
|
if (!debtAmount.isZero()) {
|
|
28949
29096
|
try {
|
|
28950
29097
|
const swapQuote = await ekuboQuoter.getQuote(
|
|
@@ -28954,26 +29101,49 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28954
29101
|
// negative for exact amount out
|
|
28955
29102
|
);
|
|
28956
29103
|
if (swapQuote.price_impact < 0.01) {
|
|
28957
|
-
leverSwap = ekuboQuoter.getVesuMultiplyQuote(
|
|
29104
|
+
leverSwap = debtAmount.isNegative() ? ekuboQuoter.getVesuMultiplyQuote(
|
|
29105
|
+
swapQuote,
|
|
29106
|
+
collateralToken,
|
|
29107
|
+
debtToken
|
|
29108
|
+
) : ekuboQuoter.getVesuMultiplyQuote(
|
|
29109
|
+
swapQuote,
|
|
29110
|
+
debtToken,
|
|
29111
|
+
collateralToken
|
|
29112
|
+
);
|
|
28958
29113
|
const MAX_SLIPPAGE = 2e-3;
|
|
28959
29114
|
if (debtAmount.greaterThan(0)) {
|
|
28960
29115
|
leverSwapLimitAmount = debtAmount.multipliedBy(1 + MAX_SLIPPAGE);
|
|
28961
29116
|
} else if (debtAmount.lessThan(0)) {
|
|
28962
29117
|
leverSwapLimitAmount = debtAmount.abs().multipliedBy(1 - MAX_SLIPPAGE);
|
|
28963
29118
|
} else {
|
|
28964
|
-
leverSwapLimitAmount = Web3Number.fromWei(
|
|
29119
|
+
leverSwapLimitAmount = Web3Number.fromWei(
|
|
29120
|
+
0,
|
|
29121
|
+
this.config.debt.decimals
|
|
29122
|
+
);
|
|
28965
29123
|
}
|
|
28966
29124
|
await new Promise((resolve) => setTimeout(resolve, 1e4));
|
|
28967
29125
|
} else {
|
|
28968
|
-
throw new Error(
|
|
29126
|
+
throw new Error(
|
|
29127
|
+
`VesuMultiplyAdapter: Price impact too high (${swapQuote.price_impact}), skipping swap`
|
|
29128
|
+
);
|
|
28969
29129
|
}
|
|
28970
29130
|
} catch (error) {
|
|
28971
|
-
throw new Error(
|
|
29131
|
+
throw new Error(
|
|
29132
|
+
`VesuMultiplyAdapter: Failed to get swap quote: ${error}`
|
|
29133
|
+
);
|
|
28972
29134
|
}
|
|
28973
29135
|
}
|
|
28974
|
-
const multiplyParams = await this.getLeverParams(
|
|
29136
|
+
const multiplyParams = await this.getLeverParams(
|
|
29137
|
+
isIncrease,
|
|
29138
|
+
params,
|
|
29139
|
+
leverSwap,
|
|
29140
|
+
leverSwapLimitAmount
|
|
29141
|
+
);
|
|
28975
29142
|
const call = multiplyContract.populate("modify_lever", {
|
|
28976
|
-
modify_lever_params: this.formatMultiplyParams(
|
|
29143
|
+
modify_lever_params: this.formatMultiplyParams(
|
|
29144
|
+
isIncrease,
|
|
29145
|
+
multiplyParams
|
|
29146
|
+
)
|
|
28977
29147
|
});
|
|
28978
29148
|
return call.calldata;
|
|
28979
29149
|
}
|
|
@@ -28987,7 +29157,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28987
29157
|
add_margin: params.amount,
|
|
28988
29158
|
// multiplied by collateral decimals in format
|
|
28989
29159
|
margin_swap: [],
|
|
28990
|
-
margin_swap_limit_amount: Web3Number.fromWei(
|
|
29160
|
+
margin_swap_limit_amount: Web3Number.fromWei(
|
|
29161
|
+
0,
|
|
29162
|
+
this.config.collateral.decimals
|
|
29163
|
+
),
|
|
28991
29164
|
lever_swap: leverSwap,
|
|
28992
29165
|
lever_swap_limit_amount: leverSwapLimitAmount
|
|
28993
29166
|
} : {
|
|
@@ -29001,7 +29174,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29001
29174
|
lever_swap_limit_amount: leverSwapLimitAmount,
|
|
29002
29175
|
lever_swap_weights: [],
|
|
29003
29176
|
withdraw_swap: [],
|
|
29004
|
-
withdraw_swap_limit_amount: Web3Number.fromWei(
|
|
29177
|
+
withdraw_swap_limit_amount: Web3Number.fromWei(
|
|
29178
|
+
0,
|
|
29179
|
+
this.config.collateral.decimals
|
|
29180
|
+
),
|
|
29005
29181
|
withdraw_swap_weights: [],
|
|
29006
29182
|
close_position: false
|
|
29007
29183
|
};
|
|
@@ -29017,12 +29193,16 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29017
29193
|
});
|
|
29018
29194
|
let leverSwap = [];
|
|
29019
29195
|
let leverSwapLimitAmount = Web3Number.fromWei(0, this.config.debt.decimals);
|
|
29020
|
-
const existingPositions = await this.vesuAdapter.getPositions(
|
|
29196
|
+
const existingPositions = await this.vesuAdapter.getPositions(
|
|
29197
|
+
this.config.networkConfig
|
|
29198
|
+
);
|
|
29021
29199
|
const existingCollateralInfo = existingPositions[0];
|
|
29022
29200
|
const existingDebtInfo = existingPositions[1];
|
|
29023
29201
|
const collateralToken = this.config.collateral;
|
|
29024
29202
|
const debtToken = this.config.debt;
|
|
29025
|
-
const collateralPrice = await this.config.pricer.getPrice(
|
|
29203
|
+
const collateralPrice = await this.config.pricer.getPrice(
|
|
29204
|
+
collateralToken.symbol
|
|
29205
|
+
);
|
|
29026
29206
|
const debtPrice = await this.config.pricer.getPrice(debtToken.symbol);
|
|
29027
29207
|
const { deltadebtAmountUnits: debtAmountToRepay } = calculateDebtReductionAmountForWithdrawal(
|
|
29028
29208
|
existingDebtInfo.amount,
|
|
@@ -29036,8 +29216,14 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29036
29216
|
if (!debtAmountToRepay) {
|
|
29037
29217
|
throw new Error("error calculating debt amount to repay");
|
|
29038
29218
|
}
|
|
29039
|
-
const ekuboQuoter = new EkuboQuoter(
|
|
29040
|
-
|
|
29219
|
+
const ekuboQuoter = new EkuboQuoter(
|
|
29220
|
+
this.config.networkConfig,
|
|
29221
|
+
this.config.pricer
|
|
29222
|
+
);
|
|
29223
|
+
const debtInDebtUnits = new Web3Number(
|
|
29224
|
+
debtAmountToRepay,
|
|
29225
|
+
debtToken.decimals
|
|
29226
|
+
).dividedBy(debtPrice.price).multipliedBy(10 ** debtToken.decimals);
|
|
29041
29227
|
const swapQuote = await ekuboQuoter.getQuote(
|
|
29042
29228
|
debtToken.address.address,
|
|
29043
29229
|
collateralToken.address.address,
|
|
@@ -29045,12 +29231,23 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29045
29231
|
);
|
|
29046
29232
|
const MAX_SLIPPAGE = 2e-3;
|
|
29047
29233
|
if (swapQuote.price_impact < 25e-4) {
|
|
29048
|
-
leverSwap = ekuboQuoter.getVesuMultiplyQuote(
|
|
29234
|
+
leverSwap = ekuboQuoter.getVesuMultiplyQuote(
|
|
29235
|
+
swapQuote,
|
|
29236
|
+
collateralToken,
|
|
29237
|
+
debtToken
|
|
29238
|
+
);
|
|
29049
29239
|
} else {
|
|
29050
|
-
logger.error(
|
|
29240
|
+
logger.error(
|
|
29241
|
+
`VesuMultiplyAdapter: Price impact too high (${swapQuote.price_impact}), skipping swap`
|
|
29242
|
+
);
|
|
29051
29243
|
}
|
|
29052
29244
|
leverSwapLimitAmount = new Web3Number(debtAmountToRepay, debtToken.decimals).abs().multipliedBy(1 + MAX_SLIPPAGE);
|
|
29053
|
-
const multiplyParams = await this.getLeverParams(
|
|
29245
|
+
const multiplyParams = await this.getLeverParams(
|
|
29246
|
+
false,
|
|
29247
|
+
params,
|
|
29248
|
+
leverSwap,
|
|
29249
|
+
leverSwapLimitAmount
|
|
29250
|
+
);
|
|
29054
29251
|
const call = multiplyContract.populate("modify_lever", {
|
|
29055
29252
|
modify_lever_params: this.formatMultiplyParams(false, multiplyParams)
|
|
29056
29253
|
});
|
|
@@ -29060,100 +29257,132 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29060
29257
|
if (isIncrease) {
|
|
29061
29258
|
const _params2 = params;
|
|
29062
29259
|
return {
|
|
29063
|
-
action: new import_starknet21.CairoCustomEnum({
|
|
29064
|
-
|
|
29065
|
-
|
|
29066
|
-
|
|
29067
|
-
|
|
29068
|
-
|
|
29069
|
-
|
|
29260
|
+
action: new import_starknet21.CairoCustomEnum({
|
|
29261
|
+
IncreaseLever: {
|
|
29262
|
+
pool_id: _params2.pool_id.toBigInt(),
|
|
29263
|
+
collateral_asset: _params2.collateral_asset.toBigInt(),
|
|
29264
|
+
debt_asset: _params2.debt_asset.toBigInt(),
|
|
29265
|
+
user: _params2.user.toBigInt(),
|
|
29266
|
+
add_margin: BigInt(_params2.add_margin.toWei()),
|
|
29267
|
+
margin_swap: _params2.margin_swap.map((swap) => ({
|
|
29268
|
+
route: swap.route.map((route) => ({
|
|
29269
|
+
pool_key: {
|
|
29270
|
+
token0: route.pool_key.token0.toBigInt(),
|
|
29271
|
+
token1: route.pool_key.token1.toBigInt(),
|
|
29272
|
+
fee: route.pool_key.fee,
|
|
29273
|
+
tick_spacing: route.pool_key.tick_spacing,
|
|
29274
|
+
extension: BigInt(
|
|
29275
|
+
import_starknet21.num.hexToDecimalString(route.pool_key.extension)
|
|
29276
|
+
)
|
|
29277
|
+
},
|
|
29278
|
+
sqrt_ratio_limit: import_starknet21.uint256.bnToUint256(
|
|
29279
|
+
route.sqrt_ratio_limit.toWei()
|
|
29280
|
+
),
|
|
29281
|
+
skip_ahead: BigInt(100)
|
|
29282
|
+
})),
|
|
29283
|
+
token_amount: {
|
|
29284
|
+
token: swap.token_amount.token.toBigInt(),
|
|
29285
|
+
amount: swap.token_amount.amount.toI129()
|
|
29286
|
+
}
|
|
29287
|
+
})),
|
|
29288
|
+
margin_swap_limit_amount: BigInt(
|
|
29289
|
+
_params2.margin_swap_limit_amount.toWei()
|
|
29290
|
+
),
|
|
29291
|
+
lever_swap: _params2.lever_swap.map((swap) => ({
|
|
29292
|
+
route: swap.route.map((route) => ({
|
|
29293
|
+
pool_key: {
|
|
29294
|
+
token0: route.pool_key.token0.toBigInt(),
|
|
29295
|
+
token1: route.pool_key.token1.toBigInt(),
|
|
29296
|
+
fee: route.pool_key.fee,
|
|
29297
|
+
tick_spacing: route.pool_key.tick_spacing,
|
|
29298
|
+
extension: BigInt(
|
|
29299
|
+
import_starknet21.num.hexToDecimalString(route.pool_key.extension)
|
|
29300
|
+
)
|
|
29301
|
+
},
|
|
29302
|
+
sqrt_ratio_limit: import_starknet21.uint256.bnToUint256(
|
|
29303
|
+
route.sqrt_ratio_limit.toWei()
|
|
29304
|
+
),
|
|
29305
|
+
skip_ahead: BigInt(0)
|
|
29306
|
+
})),
|
|
29307
|
+
token_amount: {
|
|
29308
|
+
token: swap.token_amount.token.toBigInt(),
|
|
29309
|
+
amount: swap.token_amount.amount.toI129()
|
|
29310
|
+
}
|
|
29311
|
+
})),
|
|
29312
|
+
lever_swap_limit_amount: BigInt(
|
|
29313
|
+
_params2.lever_swap_limit_amount.toWei()
|
|
29314
|
+
)
|
|
29315
|
+
}
|
|
29316
|
+
})
|
|
29317
|
+
};
|
|
29318
|
+
}
|
|
29319
|
+
const _params = params;
|
|
29320
|
+
return {
|
|
29321
|
+
action: new import_starknet21.CairoCustomEnum({
|
|
29322
|
+
DecreaseLever: {
|
|
29323
|
+
pool_id: _params.pool_id.toBigInt(),
|
|
29324
|
+
collateral_asset: _params.collateral_asset.toBigInt(),
|
|
29325
|
+
debt_asset: _params.debt_asset.toBigInt(),
|
|
29326
|
+
user: _params.user.toBigInt(),
|
|
29327
|
+
sub_margin: BigInt(_params.sub_margin.toWei()),
|
|
29328
|
+
recipient: _params.recipient.toBigInt(),
|
|
29329
|
+
lever_swap: _params.lever_swap.map((swap) => ({
|
|
29070
29330
|
route: swap.route.map((route) => ({
|
|
29071
29331
|
pool_key: {
|
|
29072
29332
|
token0: route.pool_key.token0.toBigInt(),
|
|
29073
29333
|
token1: route.pool_key.token1.toBigInt(),
|
|
29074
29334
|
fee: route.pool_key.fee,
|
|
29075
29335
|
tick_spacing: route.pool_key.tick_spacing,
|
|
29076
|
-
extension:
|
|
29336
|
+
extension: ContractAddr.from(
|
|
29337
|
+
route.pool_key.extension
|
|
29338
|
+
).toBigInt()
|
|
29077
29339
|
},
|
|
29078
|
-
sqrt_ratio_limit: import_starknet21.uint256.bnToUint256(
|
|
29079
|
-
|
|
29340
|
+
sqrt_ratio_limit: import_starknet21.uint256.bnToUint256(
|
|
29341
|
+
route.sqrt_ratio_limit.toWei()
|
|
29342
|
+
),
|
|
29343
|
+
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
29080
29344
|
})),
|
|
29081
29345
|
token_amount: {
|
|
29082
29346
|
token: swap.token_amount.token.toBigInt(),
|
|
29083
29347
|
amount: swap.token_amount.amount.toI129()
|
|
29084
29348
|
}
|
|
29085
29349
|
})),
|
|
29086
|
-
|
|
29087
|
-
|
|
29350
|
+
lever_swap_limit_amount: BigInt(
|
|
29351
|
+
_params.lever_swap_limit_amount.toWei()
|
|
29352
|
+
),
|
|
29353
|
+
lever_swap_weights: _params.lever_swap_weights.map(
|
|
29354
|
+
(weight) => BigInt(weight.toWei())
|
|
29355
|
+
),
|
|
29356
|
+
withdraw_swap: _params.withdraw_swap.map((swap) => ({
|
|
29088
29357
|
route: swap.route.map((route) => ({
|
|
29089
29358
|
pool_key: {
|
|
29090
29359
|
token0: route.pool_key.token0.toBigInt(),
|
|
29091
29360
|
token1: route.pool_key.token1.toBigInt(),
|
|
29092
29361
|
fee: route.pool_key.fee,
|
|
29093
29362
|
tick_spacing: route.pool_key.tick_spacing,
|
|
29094
|
-
extension:
|
|
29363
|
+
extension: ContractAddr.from(
|
|
29364
|
+
route.pool_key.extension
|
|
29365
|
+
).toBigInt()
|
|
29095
29366
|
},
|
|
29096
|
-
sqrt_ratio_limit: import_starknet21.uint256.bnToUint256(
|
|
29097
|
-
|
|
29367
|
+
sqrt_ratio_limit: import_starknet21.uint256.bnToUint256(
|
|
29368
|
+
route.sqrt_ratio_limit.toWei()
|
|
29369
|
+
),
|
|
29370
|
+
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
29098
29371
|
})),
|
|
29099
29372
|
token_amount: {
|
|
29100
29373
|
token: swap.token_amount.token.toBigInt(),
|
|
29101
29374
|
amount: swap.token_amount.amount.toI129()
|
|
29102
29375
|
}
|
|
29103
29376
|
})),
|
|
29104
|
-
|
|
29105
|
-
|
|
29106
|
-
|
|
29107
|
-
|
|
29108
|
-
|
|
29109
|
-
|
|
29110
|
-
|
|
29111
|
-
|
|
29112
|
-
|
|
29113
|
-
debt_asset: _params.debt_asset.toBigInt(),
|
|
29114
|
-
user: _params.user.toBigInt(),
|
|
29115
|
-
sub_margin: BigInt(_params.sub_margin.toWei()),
|
|
29116
|
-
recipient: _params.recipient.toBigInt(),
|
|
29117
|
-
lever_swap: _params.lever_swap.map((swap) => ({
|
|
29118
|
-
route: swap.route.map((route) => ({
|
|
29119
|
-
pool_key: {
|
|
29120
|
-
token0: route.pool_key.token0.toBigInt(),
|
|
29121
|
-
token1: route.pool_key.token1.toBigInt(),
|
|
29122
|
-
fee: route.pool_key.fee,
|
|
29123
|
-
tick_spacing: route.pool_key.tick_spacing,
|
|
29124
|
-
extension: ContractAddr.from(route.pool_key.extension).toBigInt()
|
|
29125
|
-
},
|
|
29126
|
-
sqrt_ratio_limit: import_starknet21.uint256.bnToUint256(route.sqrt_ratio_limit.toWei()),
|
|
29127
|
-
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
29128
|
-
})),
|
|
29129
|
-
token_amount: {
|
|
29130
|
-
token: swap.token_amount.token.toBigInt(),
|
|
29131
|
-
amount: swap.token_amount.amount.toI129()
|
|
29132
|
-
}
|
|
29133
|
-
})),
|
|
29134
|
-
lever_swap_limit_amount: BigInt(_params.lever_swap_limit_amount.toWei()),
|
|
29135
|
-
lever_swap_weights: _params.lever_swap_weights.map((weight) => BigInt(weight.toWei())),
|
|
29136
|
-
withdraw_swap: _params.withdraw_swap.map((swap) => ({
|
|
29137
|
-
route: swap.route.map((route) => ({
|
|
29138
|
-
pool_key: {
|
|
29139
|
-
token0: route.pool_key.token0.toBigInt(),
|
|
29140
|
-
token1: route.pool_key.token1.toBigInt(),
|
|
29141
|
-
fee: route.pool_key.fee,
|
|
29142
|
-
tick_spacing: route.pool_key.tick_spacing,
|
|
29143
|
-
extension: ContractAddr.from(route.pool_key.extension).toBigInt()
|
|
29144
|
-
},
|
|
29145
|
-
sqrt_ratio_limit: import_starknet21.uint256.bnToUint256(route.sqrt_ratio_limit.toWei()),
|
|
29146
|
-
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
29147
|
-
})),
|
|
29148
|
-
token_amount: {
|
|
29149
|
-
token: swap.token_amount.token.toBigInt(),
|
|
29150
|
-
amount: swap.token_amount.amount.toI129()
|
|
29151
|
-
}
|
|
29152
|
-
})),
|
|
29153
|
-
withdraw_swap_limit_amount: BigInt(_params.withdraw_swap_limit_amount.toWei()),
|
|
29154
|
-
withdraw_swap_weights: _params.withdraw_swap_weights.map((weight) => BigInt(weight.toWei())),
|
|
29155
|
-
close_position: _params.close_position
|
|
29156
|
-
} })
|
|
29377
|
+
withdraw_swap_limit_amount: BigInt(
|
|
29378
|
+
_params.withdraw_swap_limit_amount.toWei()
|
|
29379
|
+
),
|
|
29380
|
+
withdraw_swap_weights: _params.withdraw_swap_weights.map(
|
|
29381
|
+
(weight) => BigInt(weight.toWei())
|
|
29382
|
+
),
|
|
29383
|
+
close_position: _params.close_position
|
|
29384
|
+
}
|
|
29385
|
+
})
|
|
29157
29386
|
};
|
|
29158
29387
|
}
|
|
29159
29388
|
async getHealthFactor() {
|
|
@@ -29162,11 +29391,15 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29162
29391
|
}
|
|
29163
29392
|
async getNetAPY() {
|
|
29164
29393
|
const positions = await this.getPositions();
|
|
29165
|
-
logger.verbose(
|
|
29394
|
+
logger.verbose(
|
|
29395
|
+
`${this.name}::getNetAPY: positions: ${JSON.stringify(positions)}`
|
|
29396
|
+
);
|
|
29166
29397
|
const allZero = positions.every((p) => p.usdValue === 0);
|
|
29167
29398
|
if (allZero) {
|
|
29168
29399
|
const collateralUSD = 1e3;
|
|
29169
|
-
const maxLTV = await this.vesuAdapter.getLTVConfig(
|
|
29400
|
+
const maxLTV = await this.vesuAdapter.getLTVConfig(
|
|
29401
|
+
this.config.networkConfig
|
|
29402
|
+
);
|
|
29170
29403
|
const targetHF = this.config.targetHealthFactor;
|
|
29171
29404
|
const maxDebt = HealthFactorMath.getMaxDebtAmountOnLooping(
|
|
29172
29405
|
new Web3Number(collateralUSD, this.config.collateral.decimals),
|
|
@@ -29543,7 +29776,10 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29543
29776
|
//abstract means the method has no implementation in this class; instead, child classes must implement it.
|
|
29544
29777
|
async getAPY(supportedPosition) {
|
|
29545
29778
|
const side = supportedPosition.isDebt ? "LONG" : "SHORT";
|
|
29546
|
-
const fundingRates = await this.client.getFundingRates(
|
|
29779
|
+
const fundingRates = await this.client.getFundingRates(
|
|
29780
|
+
this.config.extendedMarketName,
|
|
29781
|
+
side
|
|
29782
|
+
);
|
|
29547
29783
|
if (fundingRates.status !== "OK") {
|
|
29548
29784
|
logger.error("error getting funding rates", fundingRates);
|
|
29549
29785
|
return { apy: 0, type: "base" /* BASE */ };
|
|
@@ -29587,14 +29823,14 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29587
29823
|
});
|
|
29588
29824
|
}
|
|
29589
29825
|
_getDepositLeaf() {
|
|
29590
|
-
const usdceToken = Global.getDefaultTokens().find(
|
|
29826
|
+
const usdceToken = Global.getDefaultTokens().find(
|
|
29827
|
+
(token) => token.symbol === "USDCe"
|
|
29828
|
+
);
|
|
29591
29829
|
return [
|
|
29592
29830
|
{
|
|
29593
29831
|
target: this.config.supportedPositions[0].asset.address,
|
|
29594
29832
|
method: "approve",
|
|
29595
|
-
packedArguments: [
|
|
29596
|
-
AVNU_EXCHANGE_FOR_LEGACY_USDC.toBigInt()
|
|
29597
|
-
],
|
|
29833
|
+
packedArguments: [AVNU_EXCHANGE_FOR_LEGACY_USDC.toBigInt()],
|
|
29598
29834
|
id: `extended_approve_${this.config.supportedPositions[0].asset.symbol}`,
|
|
29599
29835
|
sanitizer: AVNU_LEGACY_SANITIZER
|
|
29600
29836
|
},
|
|
@@ -29625,25 +29861,33 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29625
29861
|
const leafConfigs = this._getSwapFromLegacyLeaf();
|
|
29626
29862
|
const leaves = leafConfigs.map((config) => {
|
|
29627
29863
|
const { target, method, packedArguments, sanitizer, id } = config;
|
|
29628
|
-
const leaf = this.constructSimpleLeafData(
|
|
29629
|
-
|
|
29630
|
-
|
|
29631
|
-
|
|
29632
|
-
|
|
29633
|
-
|
|
29864
|
+
const leaf = this.constructSimpleLeafData(
|
|
29865
|
+
{
|
|
29866
|
+
id,
|
|
29867
|
+
target,
|
|
29868
|
+
method,
|
|
29869
|
+
packedArguments
|
|
29870
|
+
},
|
|
29871
|
+
sanitizer
|
|
29872
|
+
);
|
|
29634
29873
|
return leaf;
|
|
29635
29874
|
});
|
|
29636
|
-
return {
|
|
29875
|
+
return {
|
|
29876
|
+
leaves,
|
|
29877
|
+
callConstructor: this.getSwapFromLegacyCall.bind(
|
|
29878
|
+
this
|
|
29879
|
+
)
|
|
29880
|
+
};
|
|
29637
29881
|
}
|
|
29638
29882
|
_getSwapFromLegacyLeaf() {
|
|
29639
|
-
const usdceToken = Global.getDefaultTokens().find(
|
|
29883
|
+
const usdceToken = Global.getDefaultTokens().find(
|
|
29884
|
+
(token) => token.symbol === "USDCe"
|
|
29885
|
+
);
|
|
29640
29886
|
return [
|
|
29641
29887
|
{
|
|
29642
29888
|
target: usdceToken.address,
|
|
29643
29889
|
method: "approve",
|
|
29644
|
-
packedArguments: [
|
|
29645
|
-
AVNU_EXCHANGE_FOR_LEGACY_USDC.toBigInt()
|
|
29646
|
-
],
|
|
29890
|
+
packedArguments: [AVNU_EXCHANGE_FOR_LEGACY_USDC.toBigInt()],
|
|
29647
29891
|
id: `extendedswaplegacyapprove_${usdceToken.symbol}`,
|
|
29648
29892
|
sanitizer: AVNU_LEGACY_SANITIZER
|
|
29649
29893
|
},
|
|
@@ -29662,11 +29906,13 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29662
29906
|
async getDepositCall(params) {
|
|
29663
29907
|
try {
|
|
29664
29908
|
const usdcToken = this.config.supportedPositions[0].asset;
|
|
29665
|
-
const usdceToken = Global.getDefaultTokens().find(
|
|
29666
|
-
|
|
29667
|
-
|
|
29909
|
+
const usdceToken = Global.getDefaultTokens().find(
|
|
29910
|
+
(token) => token.symbol === "USDCe"
|
|
29911
|
+
);
|
|
29912
|
+
const salt = Math.floor(Math.random() * 10 ** usdcToken.decimals);
|
|
29913
|
+
const amount = import_starknet22.uint256.bnToUint256(
|
|
29914
|
+
params.amount.multipliedBy(10).toWei()
|
|
29668
29915
|
);
|
|
29669
|
-
const amount = import_starknet22.uint256.bnToUint256(params.amount.multipliedBy(10).toWei());
|
|
29670
29916
|
const quotes = await this.config.avnuAdapter.getQuotesAvnu(
|
|
29671
29917
|
usdcToken.address.toString(),
|
|
29672
29918
|
usdceToken.address.toString(),
|
|
@@ -29679,7 +29925,9 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29679
29925
|
logger.error("error getting quotes from avnu");
|
|
29680
29926
|
return [];
|
|
29681
29927
|
}
|
|
29682
|
-
const getCalldata = await this.config.avnuAdapter.getSwapCallData(
|
|
29928
|
+
const getCalldata = await this.config.avnuAdapter.getSwapCallData(
|
|
29929
|
+
quotes
|
|
29930
|
+
);
|
|
29683
29931
|
const swapCallData = getCalldata[0];
|
|
29684
29932
|
return [
|
|
29685
29933
|
{
|
|
@@ -29755,8 +30003,12 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29755
30003
|
async getSwapFromLegacyCall(params) {
|
|
29756
30004
|
try {
|
|
29757
30005
|
const usdcToken = this.config.supportedPositions[0].asset;
|
|
29758
|
-
const usdceToken = Global.getDefaultTokens().find(
|
|
29759
|
-
|
|
30006
|
+
const usdceToken = Global.getDefaultTokens().find(
|
|
30007
|
+
(token) => token.symbol === "USDCe"
|
|
30008
|
+
);
|
|
30009
|
+
const amount = import_starknet22.uint256.bnToUint256(
|
|
30010
|
+
params.amount.multipliedBy(10).toWei()
|
|
30011
|
+
);
|
|
29760
30012
|
const quotes = await this.config.avnuAdapter.getQuotesAvnu(
|
|
29761
30013
|
usdceToken.address.toString(),
|
|
29762
30014
|
usdcToken.address.toString(),
|
|
@@ -29769,7 +30021,9 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29769
30021
|
logger.error("error getting quotes from avnu");
|
|
29770
30022
|
return [];
|
|
29771
30023
|
}
|
|
29772
|
-
const getCalldata = await this.config.avnuAdapter.getSwapCallData(
|
|
30024
|
+
const getCalldata = await this.config.avnuAdapter.getSwapCallData(
|
|
30025
|
+
quotes
|
|
30026
|
+
);
|
|
29773
30027
|
const swapCallData = getCalldata[0];
|
|
29774
30028
|
return [
|
|
29775
30029
|
{
|
|
@@ -29817,9 +30071,14 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29817
30071
|
if (!this.client) {
|
|
29818
30072
|
throw new Error("Client not initialized");
|
|
29819
30073
|
}
|
|
29820
|
-
const withdrawalRequest = await this.client.withdrawUSDC(
|
|
30074
|
+
const withdrawalRequest = await this.client.withdrawUSDC(
|
|
30075
|
+
amount.toFixed(2)
|
|
30076
|
+
);
|
|
29821
30077
|
if (withdrawalRequest.status === "OK") {
|
|
29822
|
-
const withdrawalStatus = await this.getDepositOrWithdrawalStatus(
|
|
30078
|
+
const withdrawalStatus = await this.getDepositOrWithdrawalStatus(
|
|
30079
|
+
withdrawalRequest.data,
|
|
30080
|
+
"WITHDRAWAL" /* WITHDRAWAL */
|
|
30081
|
+
);
|
|
29823
30082
|
return withdrawalStatus;
|
|
29824
30083
|
}
|
|
29825
30084
|
return false;
|
|
@@ -29892,17 +30151,34 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29892
30151
|
logger.error("error initializing client");
|
|
29893
30152
|
return null;
|
|
29894
30153
|
}
|
|
29895
|
-
|
|
30154
|
+
let orderhistory = await this.getOrderHistory(marketName);
|
|
29896
30155
|
if (!orderhistory || orderhistory.length === 0) {
|
|
29897
|
-
logger.error(`error getting order: ${orderId}`);
|
|
29898
|
-
|
|
30156
|
+
logger.error(`error getting order history: ${orderId}`);
|
|
30157
|
+
} else {
|
|
30158
|
+
const order = orderhistory.slice(0, 5).find((order2) => order2.id.toString() === orderId);
|
|
30159
|
+
if (order) {
|
|
30160
|
+
return order;
|
|
30161
|
+
}
|
|
29899
30162
|
}
|
|
29900
|
-
|
|
29901
|
-
|
|
29902
|
-
|
|
29903
|
-
|
|
30163
|
+
for (let attempt = 1; attempt <= 3; attempt++) {
|
|
30164
|
+
await new Promise((resolve) => setTimeout(resolve, 3e3));
|
|
30165
|
+
orderhistory = await this.getOrderHistory(marketName);
|
|
30166
|
+
if (!orderhistory || orderhistory.length === 0) {
|
|
30167
|
+
logger.error(
|
|
30168
|
+
`error getting order history on retry ${attempt}: ${orderId}`
|
|
30169
|
+
);
|
|
30170
|
+
continue;
|
|
30171
|
+
}
|
|
30172
|
+
const order = orderhistory.slice(0, 5).find((order2) => order2.id.toString() === orderId);
|
|
30173
|
+
if (order) {
|
|
30174
|
+
return order;
|
|
30175
|
+
}
|
|
30176
|
+
logger.error(
|
|
30177
|
+
`order not found in top 5 entries on retry ${attempt}: ${orderId}`
|
|
30178
|
+
);
|
|
29904
30179
|
}
|
|
29905
|
-
|
|
30180
|
+
logger.error(`error getting order after all retries: ${orderId}`);
|
|
30181
|
+
return null;
|
|
29906
30182
|
}
|
|
29907
30183
|
async fetchOrderBookBTCUSDC() {
|
|
29908
30184
|
try {
|
|
@@ -29975,7 +30251,10 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29975
30251
|
return null;
|
|
29976
30252
|
}
|
|
29977
30253
|
await new Promise((resolve) => setTimeout(resolve, 5e3));
|
|
29978
|
-
const openOrder = await this.getOrderStatus(
|
|
30254
|
+
const openOrder = await this.getOrderStatus(
|
|
30255
|
+
result.position_id,
|
|
30256
|
+
this.config.extendedMarketName
|
|
30257
|
+
);
|
|
29979
30258
|
if (!openOrder || openOrder.status !== "FILLED" /* FILLED */) {
|
|
29980
30259
|
if (attempt >= maxAttempts) {
|
|
29981
30260
|
logger.error("Max retries reached \u2014 could not verify open position");
|
|
@@ -29998,7 +30277,9 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29998
30277
|
};
|
|
29999
30278
|
}
|
|
30000
30279
|
} catch (err) {
|
|
30001
|
-
logger.error(
|
|
30280
|
+
logger.error(
|
|
30281
|
+
`createShortOrder failed on attempt ${attempt}: ${err.message}`
|
|
30282
|
+
);
|
|
30002
30283
|
if (attempt < maxAttempts) {
|
|
30003
30284
|
const backoff = 1200 * attempt;
|
|
30004
30285
|
logger.info(`Retrying after ${backoff}ms...`);
|
|
@@ -30043,13 +30324,17 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
30043
30324
|
operationsStatus: ["COMPLETED" /* COMPLETED */]
|
|
30044
30325
|
});
|
|
30045
30326
|
if (operationsType === "DEPOSIT" /* DEPOSIT */) {
|
|
30046
|
-
const myTransferStatus = transferHistory.data.find(
|
|
30327
|
+
const myTransferStatus = transferHistory.data.find(
|
|
30328
|
+
(operation) => operation.transactionHash === orderId
|
|
30329
|
+
);
|
|
30047
30330
|
if (!myTransferStatus) {
|
|
30048
30331
|
return true;
|
|
30049
30332
|
}
|
|
30050
30333
|
return true;
|
|
30051
30334
|
} else {
|
|
30052
|
-
const myTransferStatus = transferHistory.data.find(
|
|
30335
|
+
const myTransferStatus = transferHistory.data.find(
|
|
30336
|
+
(operation) => operation.id.toString() === orderId.toString()
|
|
30337
|
+
);
|
|
30053
30338
|
if (!myTransferStatus) {
|
|
30054
30339
|
return true;
|
|
30055
30340
|
}
|
|
@@ -33667,6 +33952,7 @@ var AvnuAdapter = class _AvnuAdapter extends BaseAdapter {
|
|
|
33667
33952
|
toToken.decimals,
|
|
33668
33953
|
true
|
|
33669
33954
|
);
|
|
33955
|
+
console.log(`${_AvnuAdapter.name}::getDepositCall quote: ${quote?.sellAmountInUsd}`);
|
|
33670
33956
|
if (!quote) {
|
|
33671
33957
|
logger.error("error getting quote from avnu");
|
|
33672
33958
|
return [];
|
|
@@ -33785,7 +34071,7 @@ var AvnuAdapter = class _AvnuAdapter extends BaseAdapter {
|
|
|
33785
34071
|
}
|
|
33786
34072
|
throw new Error("Failed to fetch quote after retries");
|
|
33787
34073
|
}
|
|
33788
|
-
async getQuotesAvnu(from_token_address, to_token_address, amount, takerAddress, toTokenDecimals, usdcToBtc, maxIterations = 5, tolerance =
|
|
34074
|
+
async getQuotesAvnu(from_token_address, to_token_address, amount, takerAddress, toTokenDecimals, usdcToBtc, maxIterations = 5, tolerance = 5e3) {
|
|
33789
34075
|
try {
|
|
33790
34076
|
const fromToken = this.config.supportedPositions[0].asset;
|
|
33791
34077
|
const toToken = this.config.supportedPositions[1].asset;
|
|
@@ -34025,7 +34311,8 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34025
34311
|
}
|
|
34026
34312
|
const balance = await this.getUnusedBalance();
|
|
34027
34313
|
const usdcBalanceOnExtended = await extendedAdapter.getExtendedDepositAmount();
|
|
34028
|
-
const amountToInvest = balance.
|
|
34314
|
+
const amountToInvest = new Web3Number(balance.usdValue, USDC_TOKEN_DECIMALS).plus(usdcBalanceOnExtended?.availableForWithdrawal ?? 0).minus(LIMIT_BALANCE);
|
|
34315
|
+
logger.info(`${_VesuExtendedMultiplierStrategy.name}::shouldInvest amountToInvest: ${amountToInvest.toNumber()}`);
|
|
34029
34316
|
if (amountToInvest.lessThan(0)) {
|
|
34030
34317
|
return {
|
|
34031
34318
|
shouldInvest: false,
|
|
@@ -34078,6 +34365,7 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34078
34365
|
vesuLeverage: 0
|
|
34079
34366
|
};
|
|
34080
34367
|
}
|
|
34368
|
+
logger.info(`${_VesuExtendedMultiplierStrategy.name}::shouldInvest vesu_amount: ${vesu_amount.toNumber()}, extended_amount: ${extended_amount.toNumber()}`);
|
|
34081
34369
|
return {
|
|
34082
34370
|
shouldInvest: true,
|
|
34083
34371
|
vesuAmount: vesu_amount,
|
|
@@ -34157,15 +34445,15 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34157
34445
|
}
|
|
34158
34446
|
const usdcAmountInWallet = (await this.getUnusedBalance()).amount;
|
|
34159
34447
|
const usdcAmountOnExtended = parseFloat(
|
|
34160
|
-
extendedHoldings.
|
|
34448
|
+
extendedHoldings.availableForWithdrawal
|
|
34161
34449
|
);
|
|
34162
|
-
if (extendedAmount.
|
|
34450
|
+
if (extendedAmount.minus(usdcAmountOnExtended).greaterThan(0)) {
|
|
34163
34451
|
try {
|
|
34164
34452
|
const { calls: extendedCalls } = await this.moveAssets(
|
|
34165
34453
|
{
|
|
34166
34454
|
to: Protocols.EXTENDED.name,
|
|
34167
34455
|
from: Protocols.VAULT.name,
|
|
34168
|
-
amount: extendedAmount.
|
|
34456
|
+
amount: extendedAmount.minus(usdcAmountOnExtended)
|
|
34169
34457
|
},
|
|
34170
34458
|
extendedAdapter,
|
|
34171
34459
|
vesuAdapter
|
|
@@ -34272,7 +34560,7 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34272
34560
|
const withdrawalFromExtended = await extendedAdapter.withdrawFromExtended(params.amount);
|
|
34273
34561
|
if (withdrawalFromExtended) {
|
|
34274
34562
|
const extendedHoldings2 = await extendedAdapter.getExtendedDepositAmount();
|
|
34275
|
-
logger.info(`extendedHoldings after withdrawal ${extendedHoldings2}`);
|
|
34563
|
+
logger.info(`extendedHoldings after withdrawal ${extendedHoldings2?.availableForWithdrawal}`);
|
|
34276
34564
|
await new Promise((resolve) => setTimeout(resolve, 1e4));
|
|
34277
34565
|
const calls = await this.moveAssetsToVaultAllocator(params.amount, extendedAdapter);
|
|
34278
34566
|
if (calls.length > 0) {
|
|
@@ -34403,7 +34691,7 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34403
34691
|
};
|
|
34404
34692
|
}
|
|
34405
34693
|
const extendedHoldingAmount = new Web3Number(
|
|
34406
|
-
extendedHoldings.
|
|
34694
|
+
extendedHoldings.availableForWithdrawal,
|
|
34407
34695
|
USDC_TOKEN_DECIMALS
|
|
34408
34696
|
);
|
|
34409
34697
|
const {
|
|
@@ -34463,7 +34751,6 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34463
34751
|
extendedAmountInBTC: new Web3Number(0, 0),
|
|
34464
34752
|
calls: []
|
|
34465
34753
|
};
|
|
34466
|
-
;
|
|
34467
34754
|
}
|
|
34468
34755
|
}
|
|
34469
34756
|
async checkPriceDifferenceBetweenAvnuAndExtended(extendedAdapter, vesuAdapter, avnuAdapter) {
|