@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
|
@@ -92555,11 +92555,12 @@ spurious results.`);
|
|
|
92555
92555
|
logger2.error(`error getting extended position: extendedHoldings=${extendedHoldings}, latestPosition=${latestPosition}`);
|
|
92556
92556
|
return null;
|
|
92557
92557
|
}
|
|
92558
|
-
const positionValueInUSD = latestPosition.value;
|
|
92558
|
+
const positionValueInUSD = new Web3Number(latestPosition.value, USDC_TOKEN_DECIMALS);
|
|
92559
92559
|
const equity = extendedHoldings.data.equity;
|
|
92560
|
-
const deposit =
|
|
92561
|
-
return new Web3Number(
|
|
92560
|
+
const deposit = positionValueInUSD.dividedBy(extended_leverage).minus(equity).toFixed(2);
|
|
92561
|
+
return new Web3Number(deposit, USDC_TOKEN_DECIMALS);
|
|
92562
92562
|
} catch (err2) {
|
|
92563
|
+
logger2.error(`error calculating amount deposit on extended when incurring losses: ${err2}`);
|
|
92563
92564
|
return null;
|
|
92564
92565
|
}
|
|
92565
92566
|
};
|
|
@@ -92637,21 +92638,35 @@ spurious results.`);
|
|
|
92637
92638
|
vaultAllocator: config3.vaultAllocator,
|
|
92638
92639
|
id: ""
|
|
92639
92640
|
});
|
|
92640
|
-
this.tokenMarketData = new TokenMarketData(
|
|
92641
|
+
this.tokenMarketData = new TokenMarketData(
|
|
92642
|
+
this.config.pricer,
|
|
92643
|
+
this.config.networkConfig
|
|
92644
|
+
);
|
|
92641
92645
|
}
|
|
92642
92646
|
async getAPY(supportedPosition) {
|
|
92643
92647
|
const CACHE_KEY = `apy_${this.config.poolId.address}_${supportedPosition.asset.symbol}`;
|
|
92644
92648
|
const cacheData = this.getCache(CACHE_KEY);
|
|
92645
|
-
console.log(
|
|
92649
|
+
console.log(
|
|
92650
|
+
`${_VesuMultiplyAdapter.name}::getAPY cacheData: ${JSON.stringify(
|
|
92651
|
+
cacheData
|
|
92652
|
+
)}`,
|
|
92653
|
+
this.vesuAdapter.config.poolId.shortString(),
|
|
92654
|
+
this.vesuAdapter.config.collateral.symbol,
|
|
92655
|
+
this.vesuAdapter.config.debt.symbol
|
|
92656
|
+
);
|
|
92646
92657
|
if (cacheData) {
|
|
92647
92658
|
return cacheData;
|
|
92648
92659
|
}
|
|
92649
92660
|
try {
|
|
92650
92661
|
const allVesuPools = await VesuAdapter.getVesuPools();
|
|
92651
92662
|
const asset = supportedPosition.asset;
|
|
92652
|
-
const pool = allVesuPools.pools.find(
|
|
92663
|
+
const pool = allVesuPools.pools.find(
|
|
92664
|
+
(p) => this.vesuAdapter.config.poolId.eqString(num_exports.getHexString(p.id))
|
|
92665
|
+
);
|
|
92653
92666
|
if (!pool) {
|
|
92654
|
-
logger2.warn(
|
|
92667
|
+
logger2.warn(
|
|
92668
|
+
`VesuMultiplyAdapter: Pool not found for token ${asset.symbol}`
|
|
92669
|
+
);
|
|
92655
92670
|
return {
|
|
92656
92671
|
apy: 0,
|
|
92657
92672
|
type: "base" /* BASE */
|
|
@@ -92661,7 +92676,9 @@ spurious results.`);
|
|
|
92661
92676
|
(a) => a.symbol.toLowerCase() === asset.symbol.toLowerCase()
|
|
92662
92677
|
)?.stats;
|
|
92663
92678
|
if (!assetStats) {
|
|
92664
|
-
logger2.warn(
|
|
92679
|
+
logger2.warn(
|
|
92680
|
+
`VesuMultiplyAdapter: Asset stats not found for token ${asset.symbol}`
|
|
92681
|
+
);
|
|
92665
92682
|
return {
|
|
92666
92683
|
apy: 0,
|
|
92667
92684
|
type: "base" /* BASE */
|
|
@@ -92672,7 +92689,9 @@ spurious results.`);
|
|
|
92672
92689
|
apy = Number(assetStats.borrowApr?.value || 0) / 1e18;
|
|
92673
92690
|
} else {
|
|
92674
92691
|
const isAssetBTC = asset.symbol.toLowerCase().includes("btc");
|
|
92675
|
-
const baseAPY = Number(
|
|
92692
|
+
const baseAPY = Number(
|
|
92693
|
+
isAssetBTC ? assetStats.btcFiSupplyApr?.value + assetStats.supplyApy?.value : assetStats.supplyApy?.value || 0
|
|
92694
|
+
) / 1e18;
|
|
92676
92695
|
const rewardAPY = Number(assetStats.defiSpringSupplyApr?.value || "0") / 1e18;
|
|
92677
92696
|
const isSupported = this.tokenMarketData.isAPYSupported(asset);
|
|
92678
92697
|
apy = baseAPY + rewardAPY;
|
|
@@ -92688,7 +92707,10 @@ spurious results.`);
|
|
|
92688
92707
|
this.setCache(CACHE_KEY, result2, 3e5);
|
|
92689
92708
|
return result2;
|
|
92690
92709
|
} catch (error2) {
|
|
92691
|
-
logger2.error(
|
|
92710
|
+
logger2.error(
|
|
92711
|
+
`VesuMultiplyAdapter: Error getting APY for ${supportedPosition.asset.symbol}:`,
|
|
92712
|
+
error2
|
|
92713
|
+
);
|
|
92692
92714
|
throw error2;
|
|
92693
92715
|
}
|
|
92694
92716
|
}
|
|
@@ -92701,12 +92723,16 @@ spurious results.`);
|
|
|
92701
92723
|
try {
|
|
92702
92724
|
this.vesuAdapter.networkConfig = this.config.networkConfig;
|
|
92703
92725
|
this.vesuAdapter.pricer = this.config.pricer;
|
|
92704
|
-
const positions = await this.vesuAdapter.getPositions(
|
|
92726
|
+
const positions = await this.vesuAdapter.getPositions(
|
|
92727
|
+
this.config.networkConfig
|
|
92728
|
+
);
|
|
92705
92729
|
let position = positions.find(
|
|
92706
92730
|
(p) => p.token.address.eq(supportedPosition.asset.address)
|
|
92707
92731
|
);
|
|
92708
92732
|
if (!position) {
|
|
92709
|
-
logger2.warn(
|
|
92733
|
+
logger2.warn(
|
|
92734
|
+
`VesuMultiplyAdapter: Position not found for token ${supportedPosition.asset.symbol}`
|
|
92735
|
+
);
|
|
92710
92736
|
return {
|
|
92711
92737
|
amount: new Web3Number("0", supportedPosition.asset.decimals),
|
|
92712
92738
|
remarks: "Position not found"
|
|
@@ -92719,12 +92745,18 @@ spurious results.`);
|
|
|
92719
92745
|
this.setCache(CACHE_KEY, position, 6e4);
|
|
92720
92746
|
return position;
|
|
92721
92747
|
} catch (error2) {
|
|
92722
|
-
logger2.error(
|
|
92748
|
+
logger2.error(
|
|
92749
|
+
`VesuMultiplyAdapter: Error getting position for ${supportedPosition.asset.symbol}:`,
|
|
92750
|
+
error2
|
|
92751
|
+
);
|
|
92723
92752
|
throw error2;
|
|
92724
92753
|
}
|
|
92725
92754
|
}
|
|
92726
92755
|
async maxBorrowableAPY() {
|
|
92727
|
-
const collateralAPY = await this.getAPY({
|
|
92756
|
+
const collateralAPY = await this.getAPY({
|
|
92757
|
+
asset: this.config.collateral,
|
|
92758
|
+
isDebt: false
|
|
92759
|
+
});
|
|
92728
92760
|
const apy = collateralAPY.apy * 0.8;
|
|
92729
92761
|
return apy;
|
|
92730
92762
|
}
|
|
@@ -92734,9 +92766,15 @@ spurious results.`);
|
|
|
92734
92766
|
try {
|
|
92735
92767
|
this.vesuAdapter.networkConfig = this.config.networkConfig;
|
|
92736
92768
|
this.vesuAdapter.pricer = this.config.pricer;
|
|
92737
|
-
const positions = await this.vesuAdapter.getPositions(
|
|
92738
|
-
|
|
92739
|
-
|
|
92769
|
+
const positions = await this.vesuAdapter.getPositions(
|
|
92770
|
+
this.config.networkConfig
|
|
92771
|
+
);
|
|
92772
|
+
const collateralPosition = positions.find(
|
|
92773
|
+
(p) => p.token.address.eq(collateral.address)
|
|
92774
|
+
);
|
|
92775
|
+
const debtPosition = positions.find(
|
|
92776
|
+
(p) => p.token.address.eq(debt.address)
|
|
92777
|
+
);
|
|
92740
92778
|
if (!collateralPosition || !debtPosition) {
|
|
92741
92779
|
throw new Error("Could not find current positions");
|
|
92742
92780
|
}
|
|
@@ -92746,13 +92784,23 @@ spurious results.`);
|
|
|
92746
92784
|
debt,
|
|
92747
92785
|
maxBorrowableAPY
|
|
92748
92786
|
);
|
|
92749
|
-
logger2.verbose(
|
|
92750
|
-
|
|
92787
|
+
logger2.verbose(
|
|
92788
|
+
`VesuMultiplyAdapter: Max borrowable: ${maxBorrowable.toNumber()}`
|
|
92789
|
+
);
|
|
92790
|
+
const debtCap = await this.vesuAdapter.getDebtCap(
|
|
92791
|
+
this.config.networkConfig
|
|
92792
|
+
);
|
|
92751
92793
|
logger2.verbose(`VesuMultiplyAdapter: Debt cap: ${debtCap.toNumber()}`);
|
|
92752
92794
|
const actualMaxBorrowable = maxBorrowable.minimum(debtCap);
|
|
92753
|
-
logger2.verbose(
|
|
92754
|
-
|
|
92755
|
-
|
|
92795
|
+
logger2.verbose(
|
|
92796
|
+
`VesuMultiplyAdapter: Actual max borrowable: ${actualMaxBorrowable.toNumber()}`
|
|
92797
|
+
);
|
|
92798
|
+
const maxLTV = await this.vesuAdapter.getLTVConfig(
|
|
92799
|
+
this.config.networkConfig
|
|
92800
|
+
);
|
|
92801
|
+
const collateralPrice = await this.config.pricer.getPrice(
|
|
92802
|
+
collateral.symbol
|
|
92803
|
+
);
|
|
92756
92804
|
if (collateralPrice.price === 0) {
|
|
92757
92805
|
throw new Error("Collateral price is 0");
|
|
92758
92806
|
}
|
|
@@ -92770,14 +92818,25 @@ spurious results.`);
|
|
|
92770
92818
|
);
|
|
92771
92819
|
const maxDepositAmount = amount ? amount.minimum(maxCollateralFromDebt) : maxCollateralFromDebt;
|
|
92772
92820
|
const usdValue = await this.getUSDValue(collateral, maxDepositAmount);
|
|
92773
|
-
logger2.verbose(
|
|
92774
|
-
|
|
92775
|
-
|
|
92821
|
+
logger2.verbose(
|
|
92822
|
+
`VesuMultiplyAdapter: Max deposit::USD value: ${usdValue}, amount: ${maxDepositAmount.toNumber()}`
|
|
92823
|
+
);
|
|
92824
|
+
const apys = await Promise.all([
|
|
92825
|
+
this.getAPY({ asset: collateral, isDebt: false }),
|
|
92826
|
+
this.getAPY({ asset: debt, isDebt: true })
|
|
92827
|
+
]);
|
|
92828
|
+
logger2.verbose(
|
|
92829
|
+
`VesuMultiplyAdapter: Apys: ${apys[0].apy}, ${apys[1].apy}`
|
|
92830
|
+
);
|
|
92776
92831
|
const borrowAmountUSD = actualMaxBorrowable.multipliedBy(debtPrice.price);
|
|
92777
|
-
logger2.verbose(
|
|
92832
|
+
logger2.verbose(
|
|
92833
|
+
`VesuMultiplyAdapter: Borrow amount: ${actualMaxBorrowable.toNumber()}, borrow amount USD: ${borrowAmountUSD.toNumber()}`
|
|
92834
|
+
);
|
|
92778
92835
|
const netCollateralUSD = usdValue + borrowAmountUSD.toNumber();
|
|
92779
92836
|
const netAPY = (apys[0].apy * netCollateralUSD + apys[1].apy * borrowAmountUSD.toNumber()) / usdValue;
|
|
92780
|
-
logger2.verbose(
|
|
92837
|
+
logger2.verbose(
|
|
92838
|
+
`VesuMultiplyAdapter: Max deposit amount: ${maxDepositAmount.toNumber()}, netAPY: ${netAPY}`
|
|
92839
|
+
);
|
|
92781
92840
|
return {
|
|
92782
92841
|
tokenInfo: collateral,
|
|
92783
92842
|
amount: maxDepositAmount,
|
|
@@ -92790,7 +92849,10 @@ spurious results.`);
|
|
|
92790
92849
|
protocol: this.protocol
|
|
92791
92850
|
};
|
|
92792
92851
|
} catch (error2) {
|
|
92793
|
-
logger2.error(
|
|
92852
|
+
logger2.error(
|
|
92853
|
+
`VesuMultiplyAdapter: Error calculating max deposit:`,
|
|
92854
|
+
error2
|
|
92855
|
+
);
|
|
92794
92856
|
throw error2;
|
|
92795
92857
|
}
|
|
92796
92858
|
}
|
|
@@ -92800,9 +92862,15 @@ spurious results.`);
|
|
|
92800
92862
|
try {
|
|
92801
92863
|
this.vesuAdapter.networkConfig = this.config.networkConfig;
|
|
92802
92864
|
this.vesuAdapter.pricer = this.config.pricer;
|
|
92803
|
-
const positions = await this.vesuAdapter.getPositions(
|
|
92804
|
-
|
|
92805
|
-
|
|
92865
|
+
const positions = await this.vesuAdapter.getPositions(
|
|
92866
|
+
this.config.networkConfig
|
|
92867
|
+
);
|
|
92868
|
+
const collateralPosition = positions.find(
|
|
92869
|
+
(p) => p.token.address.eq(collateral.address)
|
|
92870
|
+
);
|
|
92871
|
+
const debtPosition = positions.find(
|
|
92872
|
+
(p) => p.token.address.eq(this.config.debt.address)
|
|
92873
|
+
);
|
|
92806
92874
|
if (!collateralPosition || !debtPosition) {
|
|
92807
92875
|
throw new Error("Could not find current positions");
|
|
92808
92876
|
}
|
|
@@ -92812,11 +92880,20 @@ spurious results.`);
|
|
|
92812
92880
|
const result2 = maxWithdrawable.greaterThan(0) ? maxWithdrawable : new Web3Number("0", collateral.decimals);
|
|
92813
92881
|
const usdValue = await this.getUSDValue(collateral, result2);
|
|
92814
92882
|
const debtUSD = debtPosition.usdValue;
|
|
92815
|
-
logger2.verbose(
|
|
92816
|
-
|
|
92817
|
-
|
|
92883
|
+
logger2.verbose(
|
|
92884
|
+
`VesuMultiplyAdapter: Debt USD: ${debtUSD}, collateral USD: ${usdValue}`
|
|
92885
|
+
);
|
|
92886
|
+
const apys = await Promise.all([
|
|
92887
|
+
this.getAPY({ asset: collateral, isDebt: false }),
|
|
92888
|
+
this.getAPY({ asset: debt, isDebt: true })
|
|
92889
|
+
]);
|
|
92890
|
+
logger2.verbose(
|
|
92891
|
+
`VesuMultiplyAdapter: Apys: ${apys[0].apy}, ${apys[1].apy}`
|
|
92892
|
+
);
|
|
92818
92893
|
const netAPY = usdValue - debtUSD > 0 ? (apys[0].apy * usdValue + apys[1].apy * debtUSD) / (usdValue - debtUSD) : 0;
|
|
92819
|
-
logger2.verbose(
|
|
92894
|
+
logger2.verbose(
|
|
92895
|
+
`VesuMultiplyAdapter: Max withdraw amount: ${result2.toNumber()}, netAPY: ${netAPY}`
|
|
92896
|
+
);
|
|
92820
92897
|
return {
|
|
92821
92898
|
tokenInfo: collateral,
|
|
92822
92899
|
amount: result2,
|
|
@@ -92829,14 +92906,19 @@ spurious results.`);
|
|
|
92829
92906
|
protocol: this.protocol
|
|
92830
92907
|
};
|
|
92831
92908
|
} catch (error2) {
|
|
92832
|
-
logger2.error(
|
|
92909
|
+
logger2.error(
|
|
92910
|
+
`VesuMultiplyAdapter: Error calculating max withdraw:`,
|
|
92911
|
+
error2
|
|
92912
|
+
);
|
|
92833
92913
|
throw error2;
|
|
92834
92914
|
}
|
|
92835
92915
|
}
|
|
92836
92916
|
_getDepositLeaf() {
|
|
92837
92917
|
const collateral = this.config.collateral;
|
|
92838
92918
|
const debt = this.config.debt;
|
|
92839
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
92919
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
92920
|
+
this.config.poolId
|
|
92921
|
+
);
|
|
92840
92922
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
92841
92923
|
return [
|
|
92842
92924
|
// Approval step for collateral
|
|
@@ -92900,7 +92982,9 @@ spurious results.`);
|
|
|
92900
92982
|
];
|
|
92901
92983
|
}
|
|
92902
92984
|
_getWithdrawLeaf() {
|
|
92903
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
92985
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
92986
|
+
this.config.poolId
|
|
92987
|
+
);
|
|
92904
92988
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
92905
92989
|
const collateral = this.config.collateral;
|
|
92906
92990
|
const debt = this.config.debt;
|
|
@@ -92957,33 +93041,51 @@ spurious results.`);
|
|
|
92957
93041
|
const leafConfigs = this._getDepositLeaf();
|
|
92958
93042
|
const leaves = leafConfigs.map((config3) => {
|
|
92959
93043
|
const { target, method, packedArguments, sanitizer, id } = config3;
|
|
92960
|
-
const leaf = this.constructSimpleLeafData(
|
|
92961
|
-
|
|
92962
|
-
|
|
92963
|
-
|
|
92964
|
-
|
|
92965
|
-
|
|
93044
|
+
const leaf = this.constructSimpleLeafData(
|
|
93045
|
+
{
|
|
93046
|
+
id,
|
|
93047
|
+
target,
|
|
93048
|
+
method,
|
|
93049
|
+
packedArguments
|
|
93050
|
+
},
|
|
93051
|
+
sanitizer
|
|
93052
|
+
);
|
|
92966
93053
|
return leaf;
|
|
92967
93054
|
});
|
|
92968
|
-
return {
|
|
93055
|
+
return {
|
|
93056
|
+
leaves,
|
|
93057
|
+
callConstructor: this.getDepositCall.bind(
|
|
93058
|
+
this
|
|
93059
|
+
)
|
|
93060
|
+
};
|
|
92969
93061
|
}
|
|
92970
93062
|
getWithdrawAdapter() {
|
|
92971
93063
|
const leafConfigs = this._getWithdrawLeaf();
|
|
92972
93064
|
const leaves = leafConfigs.map((config3) => {
|
|
92973
93065
|
const { target, method, packedArguments, sanitizer, id } = config3;
|
|
92974
|
-
const leaf = this.constructSimpleLeafData(
|
|
92975
|
-
|
|
92976
|
-
|
|
92977
|
-
|
|
92978
|
-
|
|
92979
|
-
|
|
93066
|
+
const leaf = this.constructSimpleLeafData(
|
|
93067
|
+
{
|
|
93068
|
+
id,
|
|
93069
|
+
target,
|
|
93070
|
+
method,
|
|
93071
|
+
packedArguments
|
|
93072
|
+
},
|
|
93073
|
+
sanitizer
|
|
93074
|
+
);
|
|
92980
93075
|
return leaf;
|
|
92981
93076
|
});
|
|
92982
|
-
return {
|
|
93077
|
+
return {
|
|
93078
|
+
leaves,
|
|
93079
|
+
callConstructor: this.getWithdrawCall.bind(
|
|
93080
|
+
this
|
|
93081
|
+
)
|
|
93082
|
+
};
|
|
92983
93083
|
}
|
|
92984
93084
|
async getDepositCall(params) {
|
|
92985
93085
|
const collateral = this.config.collateral;
|
|
92986
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
93086
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
93087
|
+
this.config.poolId
|
|
93088
|
+
);
|
|
92987
93089
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
92988
93090
|
const uint256MarginAmount = uint256_exports.bnToUint256(params.amount.toWei());
|
|
92989
93091
|
return [
|
|
@@ -93055,7 +93157,9 @@ spurious results.`);
|
|
|
93055
93157
|
];
|
|
93056
93158
|
}
|
|
93057
93159
|
async getWithdrawCall(params) {
|
|
93058
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
93160
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
93161
|
+
this.config.poolId
|
|
93162
|
+
);
|
|
93059
93163
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
93060
93164
|
return [
|
|
93061
93165
|
// Switch delegation on
|
|
@@ -93110,7 +93214,11 @@ spurious results.`);
|
|
|
93110
93214
|
];
|
|
93111
93215
|
}
|
|
93112
93216
|
async getMultiplyCallCalldata(params, isDeposit) {
|
|
93113
|
-
logger2.verbose(
|
|
93217
|
+
logger2.verbose(
|
|
93218
|
+
`${_VesuMultiplyAdapter.name}::getMultiplyCallCalldata params: ${JSON.stringify(
|
|
93219
|
+
params
|
|
93220
|
+
)}, isDeposit: ${isDeposit}, collateral: ${this.config.collateral.symbol}, debt: ${this.config.debt.symbol}`
|
|
93221
|
+
);
|
|
93114
93222
|
const { isV2 } = getVesuSingletonAddress(this.config.poolId);
|
|
93115
93223
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
93116
93224
|
const multiplyContract = new Contract({
|
|
@@ -93120,42 +93228,83 @@ spurious results.`);
|
|
|
93120
93228
|
});
|
|
93121
93229
|
let leverSwap = [];
|
|
93122
93230
|
let leverSwapLimitAmount = Web3Number.fromWei(0, this.config.debt.decimals);
|
|
93123
|
-
const existingPositions = await this.vesuAdapter.getPositions(
|
|
93124
|
-
|
|
93231
|
+
const existingPositions = await this.vesuAdapter.getPositions(
|
|
93232
|
+
this.config.networkConfig
|
|
93233
|
+
);
|
|
93234
|
+
const collateralisation = await this.vesuAdapter.getCollateralization(
|
|
93235
|
+
this.config.networkConfig
|
|
93236
|
+
);
|
|
93125
93237
|
const existingCollateralInfo = existingPositions[0];
|
|
93126
93238
|
const existingDebtInfo = existingPositions[1];
|
|
93127
93239
|
const isDexPriceRequired = existingDebtInfo.token.symbol !== "USDC";
|
|
93128
|
-
logger2.debug(`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall existingCollateralInfo: ${JSON.stringify(
|
|
93129
|
-
|
|
93240
|
+
logger2.debug(`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall existingCollateralInfo: ${JSON.stringify(
|
|
93241
|
+
existingCollateralInfo
|
|
93242
|
+
)},
|
|
93243
|
+
existingDebtInfo: ${JSON.stringify(
|
|
93244
|
+
existingDebtInfo
|
|
93245
|
+
)}, collateralisation: ${JSON.stringify(collateralisation)}`);
|
|
93130
93246
|
const collateralPrice = collateralisation[0].usdValue > 0 ? collateralisation[0].usdValue / existingCollateralInfo.amount.toNumber() : (await this.config.pricer.getPrice(this.config.collateral.symbol)).price;
|
|
93131
93247
|
const debtPrice = collateralisation[1].usdValue > 0 ? collateralisation[1].usdValue / existingDebtInfo.amount.toNumber() : (await this.config.pricer.getPrice(this.config.debt.symbol)).price;
|
|
93132
|
-
logger2.debug(
|
|
93133
|
-
|
|
93134
|
-
|
|
93135
|
-
const
|
|
93136
|
-
|
|
93248
|
+
logger2.debug(
|
|
93249
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall collateralPrice: ${collateralPrice}, debtPrice: ${debtPrice}`
|
|
93250
|
+
);
|
|
93251
|
+
const legLTV = await this.vesuAdapter.getLTVConfig(
|
|
93252
|
+
this.config.networkConfig
|
|
93253
|
+
);
|
|
93254
|
+
const ekuboQuoter = new EkuboQuoter(
|
|
93255
|
+
this.config.networkConfig,
|
|
93256
|
+
this.config.pricer
|
|
93257
|
+
);
|
|
93258
|
+
const dexPrice = isDexPriceRequired ? await ekuboQuoter.getDexPrice(
|
|
93259
|
+
this.config.collateral,
|
|
93260
|
+
this.config.debt,
|
|
93261
|
+
this.config.quoteAmountToFetchPrice
|
|
93262
|
+
) : 1;
|
|
93263
|
+
logger2.verbose(
|
|
93264
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall dexPrice: ${dexPrice}, ltv: ${legLTV}`
|
|
93265
|
+
);
|
|
93137
93266
|
const addedCollateral = params.amount.multipliedBy(isDeposit ? 1 : -1);
|
|
93138
|
-
logger2.verbose(
|
|
93267
|
+
logger2.verbose(
|
|
93268
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall addedCollateral: ${addedCollateral}`
|
|
93269
|
+
);
|
|
93139
93270
|
const numeratorPart1 = existingCollateralInfo.amount.plus(addedCollateral).multipliedBy(collateralPrice).multipliedBy(legLTV);
|
|
93140
|
-
logger2.verbose(
|
|
93271
|
+
logger2.verbose(
|
|
93272
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart1: ${numeratorPart1}`
|
|
93273
|
+
);
|
|
93141
93274
|
const numeratorPart2 = existingDebtInfo.amount.multipliedBy(debtPrice).multipliedBy(this.config.targetHealthFactor);
|
|
93142
|
-
logger2.verbose(
|
|
93275
|
+
logger2.verbose(
|
|
93276
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart2: ${numeratorPart2}`
|
|
93277
|
+
);
|
|
93143
93278
|
const denominatorPart = this.config.targetHealthFactor - legLTV / dexPrice;
|
|
93144
|
-
logger2.verbose(
|
|
93279
|
+
logger2.verbose(
|
|
93280
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall denominatorPart: ${denominatorPart}`
|
|
93281
|
+
);
|
|
93145
93282
|
const x_debt_usd = numeratorPart1.minus(numeratorPart2).dividedBy(denominatorPart);
|
|
93146
|
-
logger2.verbose(
|
|
93147
|
-
|
|
93148
|
-
|
|
93283
|
+
logger2.verbose(
|
|
93284
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall x_debt_usd: ${x_debt_usd}`
|
|
93285
|
+
);
|
|
93286
|
+
logger2.debug(
|
|
93287
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart1: ${numeratorPart1}, numeratorPart2: ${numeratorPart2}, denominatorPart: ${denominatorPart}`
|
|
93288
|
+
);
|
|
93289
|
+
let debtAmount = new Web3Number(
|
|
93290
|
+
x_debt_usd.dividedBy(debtPrice).toFixed(this.config.debt.decimals),
|
|
93291
|
+
this.config.debt.decimals
|
|
93292
|
+
);
|
|
93149
93293
|
const marginAmount = addedCollateral;
|
|
93150
93294
|
const collateralToken = this.config.collateral;
|
|
93151
93295
|
const debtToken = this.config.debt;
|
|
93152
|
-
const debtAmountInCollateralUnits = new Web3Number(
|
|
93296
|
+
const debtAmountInCollateralUnits = new Web3Number(
|
|
93297
|
+
debtAmount.multipliedBy(debtPrice).dividedBy(collateralPrice).multipliedBy(10 ** collateralToken.decimals).toFixed(0),
|
|
93298
|
+
collateralToken.decimals
|
|
93299
|
+
);
|
|
93153
93300
|
const isIncrease = debtAmount.greaterThanOrEqualTo(0);
|
|
93154
93301
|
if (isIncrease && debtAmount.lessThan(0)) {
|
|
93155
93302
|
} else if (!isIncrease && debtAmount.greaterThan(0)) {
|
|
93156
93303
|
debtAmount = Web3Number.fromWei(0, this.config.debt.decimals);
|
|
93157
93304
|
}
|
|
93158
|
-
logger2.verbose(
|
|
93305
|
+
logger2.verbose(
|
|
93306
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall debtAmount: ${debtAmount}, marginAmount: ${marginAmount}`
|
|
93307
|
+
);
|
|
93159
93308
|
if (!debtAmount.isZero()) {
|
|
93160
93309
|
try {
|
|
93161
93310
|
const swapQuote = await ekuboQuoter.getQuote(
|
|
@@ -93165,26 +93314,49 @@ spurious results.`);
|
|
|
93165
93314
|
// negative for exact amount out
|
|
93166
93315
|
);
|
|
93167
93316
|
if (swapQuote.price_impact < 0.01) {
|
|
93168
|
-
leverSwap = ekuboQuoter.getVesuMultiplyQuote(
|
|
93317
|
+
leverSwap = debtAmount.isNegative() ? ekuboQuoter.getVesuMultiplyQuote(
|
|
93318
|
+
swapQuote,
|
|
93319
|
+
collateralToken,
|
|
93320
|
+
debtToken
|
|
93321
|
+
) : ekuboQuoter.getVesuMultiplyQuote(
|
|
93322
|
+
swapQuote,
|
|
93323
|
+
debtToken,
|
|
93324
|
+
collateralToken
|
|
93325
|
+
);
|
|
93169
93326
|
const MAX_SLIPPAGE = 2e-3;
|
|
93170
93327
|
if (debtAmount.greaterThan(0)) {
|
|
93171
93328
|
leverSwapLimitAmount = debtAmount.multipliedBy(1 + MAX_SLIPPAGE);
|
|
93172
93329
|
} else if (debtAmount.lessThan(0)) {
|
|
93173
93330
|
leverSwapLimitAmount = debtAmount.abs().multipliedBy(1 - MAX_SLIPPAGE);
|
|
93174
93331
|
} else {
|
|
93175
|
-
leverSwapLimitAmount = Web3Number.fromWei(
|
|
93332
|
+
leverSwapLimitAmount = Web3Number.fromWei(
|
|
93333
|
+
0,
|
|
93334
|
+
this.config.debt.decimals
|
|
93335
|
+
);
|
|
93176
93336
|
}
|
|
93177
93337
|
await new Promise((resolve) => setTimeout(resolve, 1e4));
|
|
93178
93338
|
} else {
|
|
93179
|
-
throw new Error(
|
|
93339
|
+
throw new Error(
|
|
93340
|
+
`VesuMultiplyAdapter: Price impact too high (${swapQuote.price_impact}), skipping swap`
|
|
93341
|
+
);
|
|
93180
93342
|
}
|
|
93181
93343
|
} catch (error2) {
|
|
93182
|
-
throw new Error(
|
|
93344
|
+
throw new Error(
|
|
93345
|
+
`VesuMultiplyAdapter: Failed to get swap quote: ${error2}`
|
|
93346
|
+
);
|
|
93183
93347
|
}
|
|
93184
93348
|
}
|
|
93185
|
-
const multiplyParams = await this.getLeverParams(
|
|
93349
|
+
const multiplyParams = await this.getLeverParams(
|
|
93350
|
+
isIncrease,
|
|
93351
|
+
params,
|
|
93352
|
+
leverSwap,
|
|
93353
|
+
leverSwapLimitAmount
|
|
93354
|
+
);
|
|
93186
93355
|
const call = multiplyContract.populate("modify_lever", {
|
|
93187
|
-
modify_lever_params: this.formatMultiplyParams(
|
|
93356
|
+
modify_lever_params: this.formatMultiplyParams(
|
|
93357
|
+
isIncrease,
|
|
93358
|
+
multiplyParams
|
|
93359
|
+
)
|
|
93188
93360
|
});
|
|
93189
93361
|
return call.calldata;
|
|
93190
93362
|
}
|
|
@@ -93198,7 +93370,10 @@ spurious results.`);
|
|
|
93198
93370
|
add_margin: params.amount,
|
|
93199
93371
|
// multiplied by collateral decimals in format
|
|
93200
93372
|
margin_swap: [],
|
|
93201
|
-
margin_swap_limit_amount: Web3Number.fromWei(
|
|
93373
|
+
margin_swap_limit_amount: Web3Number.fromWei(
|
|
93374
|
+
0,
|
|
93375
|
+
this.config.collateral.decimals
|
|
93376
|
+
),
|
|
93202
93377
|
lever_swap: leverSwap,
|
|
93203
93378
|
lever_swap_limit_amount: leverSwapLimitAmount
|
|
93204
93379
|
} : {
|
|
@@ -93212,7 +93387,10 @@ spurious results.`);
|
|
|
93212
93387
|
lever_swap_limit_amount: leverSwapLimitAmount,
|
|
93213
93388
|
lever_swap_weights: [],
|
|
93214
93389
|
withdraw_swap: [],
|
|
93215
|
-
withdraw_swap_limit_amount: Web3Number.fromWei(
|
|
93390
|
+
withdraw_swap_limit_amount: Web3Number.fromWei(
|
|
93391
|
+
0,
|
|
93392
|
+
this.config.collateral.decimals
|
|
93393
|
+
),
|
|
93216
93394
|
withdraw_swap_weights: [],
|
|
93217
93395
|
close_position: false
|
|
93218
93396
|
};
|
|
@@ -93228,12 +93406,16 @@ spurious results.`);
|
|
|
93228
93406
|
});
|
|
93229
93407
|
let leverSwap = [];
|
|
93230
93408
|
let leverSwapLimitAmount = Web3Number.fromWei(0, this.config.debt.decimals);
|
|
93231
|
-
const existingPositions = await this.vesuAdapter.getPositions(
|
|
93409
|
+
const existingPositions = await this.vesuAdapter.getPositions(
|
|
93410
|
+
this.config.networkConfig
|
|
93411
|
+
);
|
|
93232
93412
|
const existingCollateralInfo = existingPositions[0];
|
|
93233
93413
|
const existingDebtInfo = existingPositions[1];
|
|
93234
93414
|
const collateralToken = this.config.collateral;
|
|
93235
93415
|
const debtToken = this.config.debt;
|
|
93236
|
-
const collateralPrice = await this.config.pricer.getPrice(
|
|
93416
|
+
const collateralPrice = await this.config.pricer.getPrice(
|
|
93417
|
+
collateralToken.symbol
|
|
93418
|
+
);
|
|
93237
93419
|
const debtPrice = await this.config.pricer.getPrice(debtToken.symbol);
|
|
93238
93420
|
const { deltadebtAmountUnits: debtAmountToRepay } = calculateDebtReductionAmountForWithdrawal(
|
|
93239
93421
|
existingDebtInfo.amount,
|
|
@@ -93247,8 +93429,14 @@ spurious results.`);
|
|
|
93247
93429
|
if (!debtAmountToRepay) {
|
|
93248
93430
|
throw new Error("error calculating debt amount to repay");
|
|
93249
93431
|
}
|
|
93250
|
-
const ekuboQuoter = new EkuboQuoter(
|
|
93251
|
-
|
|
93432
|
+
const ekuboQuoter = new EkuboQuoter(
|
|
93433
|
+
this.config.networkConfig,
|
|
93434
|
+
this.config.pricer
|
|
93435
|
+
);
|
|
93436
|
+
const debtInDebtUnits = new Web3Number(
|
|
93437
|
+
debtAmountToRepay,
|
|
93438
|
+
debtToken.decimals
|
|
93439
|
+
).dividedBy(debtPrice.price).multipliedBy(10 ** debtToken.decimals);
|
|
93252
93440
|
const swapQuote = await ekuboQuoter.getQuote(
|
|
93253
93441
|
debtToken.address.address,
|
|
93254
93442
|
collateralToken.address.address,
|
|
@@ -93256,12 +93444,23 @@ spurious results.`);
|
|
|
93256
93444
|
);
|
|
93257
93445
|
const MAX_SLIPPAGE = 2e-3;
|
|
93258
93446
|
if (swapQuote.price_impact < 25e-4) {
|
|
93259
|
-
leverSwap = ekuboQuoter.getVesuMultiplyQuote(
|
|
93447
|
+
leverSwap = ekuboQuoter.getVesuMultiplyQuote(
|
|
93448
|
+
swapQuote,
|
|
93449
|
+
collateralToken,
|
|
93450
|
+
debtToken
|
|
93451
|
+
);
|
|
93260
93452
|
} else {
|
|
93261
|
-
logger2.error(
|
|
93453
|
+
logger2.error(
|
|
93454
|
+
`VesuMultiplyAdapter: Price impact too high (${swapQuote.price_impact}), skipping swap`
|
|
93455
|
+
);
|
|
93262
93456
|
}
|
|
93263
93457
|
leverSwapLimitAmount = new Web3Number(debtAmountToRepay, debtToken.decimals).abs().multipliedBy(1 + MAX_SLIPPAGE);
|
|
93264
|
-
const multiplyParams = await this.getLeverParams(
|
|
93458
|
+
const multiplyParams = await this.getLeverParams(
|
|
93459
|
+
false,
|
|
93460
|
+
params,
|
|
93461
|
+
leverSwap,
|
|
93462
|
+
leverSwapLimitAmount
|
|
93463
|
+
);
|
|
93265
93464
|
const call = multiplyContract.populate("modify_lever", {
|
|
93266
93465
|
modify_lever_params: this.formatMultiplyParams(false, multiplyParams)
|
|
93267
93466
|
});
|
|
@@ -93271,100 +93470,132 @@ spurious results.`);
|
|
|
93271
93470
|
if (isIncrease) {
|
|
93272
93471
|
const _params2 = params;
|
|
93273
93472
|
return {
|
|
93274
|
-
action: new CairoCustomEnum({
|
|
93275
|
-
|
|
93276
|
-
|
|
93277
|
-
|
|
93278
|
-
|
|
93279
|
-
|
|
93280
|
-
|
|
93473
|
+
action: new CairoCustomEnum({
|
|
93474
|
+
IncreaseLever: {
|
|
93475
|
+
pool_id: _params2.pool_id.toBigInt(),
|
|
93476
|
+
collateral_asset: _params2.collateral_asset.toBigInt(),
|
|
93477
|
+
debt_asset: _params2.debt_asset.toBigInt(),
|
|
93478
|
+
user: _params2.user.toBigInt(),
|
|
93479
|
+
add_margin: BigInt(_params2.add_margin.toWei()),
|
|
93480
|
+
margin_swap: _params2.margin_swap.map((swap) => ({
|
|
93481
|
+
route: swap.route.map((route) => ({
|
|
93482
|
+
pool_key: {
|
|
93483
|
+
token0: route.pool_key.token0.toBigInt(),
|
|
93484
|
+
token1: route.pool_key.token1.toBigInt(),
|
|
93485
|
+
fee: route.pool_key.fee,
|
|
93486
|
+
tick_spacing: route.pool_key.tick_spacing,
|
|
93487
|
+
extension: BigInt(
|
|
93488
|
+
num_exports.hexToDecimalString(route.pool_key.extension)
|
|
93489
|
+
)
|
|
93490
|
+
},
|
|
93491
|
+
sqrt_ratio_limit: uint256_exports.bnToUint256(
|
|
93492
|
+
route.sqrt_ratio_limit.toWei()
|
|
93493
|
+
),
|
|
93494
|
+
skip_ahead: BigInt(100)
|
|
93495
|
+
})),
|
|
93496
|
+
token_amount: {
|
|
93497
|
+
token: swap.token_amount.token.toBigInt(),
|
|
93498
|
+
amount: swap.token_amount.amount.toI129()
|
|
93499
|
+
}
|
|
93500
|
+
})),
|
|
93501
|
+
margin_swap_limit_amount: BigInt(
|
|
93502
|
+
_params2.margin_swap_limit_amount.toWei()
|
|
93503
|
+
),
|
|
93504
|
+
lever_swap: _params2.lever_swap.map((swap) => ({
|
|
93505
|
+
route: swap.route.map((route) => ({
|
|
93506
|
+
pool_key: {
|
|
93507
|
+
token0: route.pool_key.token0.toBigInt(),
|
|
93508
|
+
token1: route.pool_key.token1.toBigInt(),
|
|
93509
|
+
fee: route.pool_key.fee,
|
|
93510
|
+
tick_spacing: route.pool_key.tick_spacing,
|
|
93511
|
+
extension: BigInt(
|
|
93512
|
+
num_exports.hexToDecimalString(route.pool_key.extension)
|
|
93513
|
+
)
|
|
93514
|
+
},
|
|
93515
|
+
sqrt_ratio_limit: uint256_exports.bnToUint256(
|
|
93516
|
+
route.sqrt_ratio_limit.toWei()
|
|
93517
|
+
),
|
|
93518
|
+
skip_ahead: BigInt(0)
|
|
93519
|
+
})),
|
|
93520
|
+
token_amount: {
|
|
93521
|
+
token: swap.token_amount.token.toBigInt(),
|
|
93522
|
+
amount: swap.token_amount.amount.toI129()
|
|
93523
|
+
}
|
|
93524
|
+
})),
|
|
93525
|
+
lever_swap_limit_amount: BigInt(
|
|
93526
|
+
_params2.lever_swap_limit_amount.toWei()
|
|
93527
|
+
)
|
|
93528
|
+
}
|
|
93529
|
+
})
|
|
93530
|
+
};
|
|
93531
|
+
}
|
|
93532
|
+
const _params = params;
|
|
93533
|
+
return {
|
|
93534
|
+
action: new CairoCustomEnum({
|
|
93535
|
+
DecreaseLever: {
|
|
93536
|
+
pool_id: _params.pool_id.toBigInt(),
|
|
93537
|
+
collateral_asset: _params.collateral_asset.toBigInt(),
|
|
93538
|
+
debt_asset: _params.debt_asset.toBigInt(),
|
|
93539
|
+
user: _params.user.toBigInt(),
|
|
93540
|
+
sub_margin: BigInt(_params.sub_margin.toWei()),
|
|
93541
|
+
recipient: _params.recipient.toBigInt(),
|
|
93542
|
+
lever_swap: _params.lever_swap.map((swap) => ({
|
|
93281
93543
|
route: swap.route.map((route) => ({
|
|
93282
93544
|
pool_key: {
|
|
93283
93545
|
token0: route.pool_key.token0.toBigInt(),
|
|
93284
93546
|
token1: route.pool_key.token1.toBigInt(),
|
|
93285
93547
|
fee: route.pool_key.fee,
|
|
93286
93548
|
tick_spacing: route.pool_key.tick_spacing,
|
|
93287
|
-
extension:
|
|
93549
|
+
extension: ContractAddr.from(
|
|
93550
|
+
route.pool_key.extension
|
|
93551
|
+
).toBigInt()
|
|
93288
93552
|
},
|
|
93289
|
-
sqrt_ratio_limit: uint256_exports.bnToUint256(
|
|
93290
|
-
|
|
93553
|
+
sqrt_ratio_limit: uint256_exports.bnToUint256(
|
|
93554
|
+
route.sqrt_ratio_limit.toWei()
|
|
93555
|
+
),
|
|
93556
|
+
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
93291
93557
|
})),
|
|
93292
93558
|
token_amount: {
|
|
93293
93559
|
token: swap.token_amount.token.toBigInt(),
|
|
93294
93560
|
amount: swap.token_amount.amount.toI129()
|
|
93295
93561
|
}
|
|
93296
93562
|
})),
|
|
93297
|
-
|
|
93298
|
-
|
|
93563
|
+
lever_swap_limit_amount: BigInt(
|
|
93564
|
+
_params.lever_swap_limit_amount.toWei()
|
|
93565
|
+
),
|
|
93566
|
+
lever_swap_weights: _params.lever_swap_weights.map(
|
|
93567
|
+
(weight) => BigInt(weight.toWei())
|
|
93568
|
+
),
|
|
93569
|
+
withdraw_swap: _params.withdraw_swap.map((swap) => ({
|
|
93299
93570
|
route: swap.route.map((route) => ({
|
|
93300
93571
|
pool_key: {
|
|
93301
93572
|
token0: route.pool_key.token0.toBigInt(),
|
|
93302
93573
|
token1: route.pool_key.token1.toBigInt(),
|
|
93303
93574
|
fee: route.pool_key.fee,
|
|
93304
93575
|
tick_spacing: route.pool_key.tick_spacing,
|
|
93305
|
-
extension:
|
|
93576
|
+
extension: ContractAddr.from(
|
|
93577
|
+
route.pool_key.extension
|
|
93578
|
+
).toBigInt()
|
|
93306
93579
|
},
|
|
93307
|
-
sqrt_ratio_limit: uint256_exports.bnToUint256(
|
|
93308
|
-
|
|
93580
|
+
sqrt_ratio_limit: uint256_exports.bnToUint256(
|
|
93581
|
+
route.sqrt_ratio_limit.toWei()
|
|
93582
|
+
),
|
|
93583
|
+
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
93309
93584
|
})),
|
|
93310
93585
|
token_amount: {
|
|
93311
93586
|
token: swap.token_amount.token.toBigInt(),
|
|
93312
93587
|
amount: swap.token_amount.amount.toI129()
|
|
93313
93588
|
}
|
|
93314
93589
|
})),
|
|
93315
|
-
|
|
93316
|
-
|
|
93317
|
-
|
|
93318
|
-
|
|
93319
|
-
|
|
93320
|
-
|
|
93321
|
-
|
|
93322
|
-
|
|
93323
|
-
|
|
93324
|
-
debt_asset: _params.debt_asset.toBigInt(),
|
|
93325
|
-
user: _params.user.toBigInt(),
|
|
93326
|
-
sub_margin: BigInt(_params.sub_margin.toWei()),
|
|
93327
|
-
recipient: _params.recipient.toBigInt(),
|
|
93328
|
-
lever_swap: _params.lever_swap.map((swap) => ({
|
|
93329
|
-
route: swap.route.map((route) => ({
|
|
93330
|
-
pool_key: {
|
|
93331
|
-
token0: route.pool_key.token0.toBigInt(),
|
|
93332
|
-
token1: route.pool_key.token1.toBigInt(),
|
|
93333
|
-
fee: route.pool_key.fee,
|
|
93334
|
-
tick_spacing: route.pool_key.tick_spacing,
|
|
93335
|
-
extension: ContractAddr.from(route.pool_key.extension).toBigInt()
|
|
93336
|
-
},
|
|
93337
|
-
sqrt_ratio_limit: uint256_exports.bnToUint256(route.sqrt_ratio_limit.toWei()),
|
|
93338
|
-
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
93339
|
-
})),
|
|
93340
|
-
token_amount: {
|
|
93341
|
-
token: swap.token_amount.token.toBigInt(),
|
|
93342
|
-
amount: swap.token_amount.amount.toI129()
|
|
93343
|
-
}
|
|
93344
|
-
})),
|
|
93345
|
-
lever_swap_limit_amount: BigInt(_params.lever_swap_limit_amount.toWei()),
|
|
93346
|
-
lever_swap_weights: _params.lever_swap_weights.map((weight) => BigInt(weight.toWei())),
|
|
93347
|
-
withdraw_swap: _params.withdraw_swap.map((swap) => ({
|
|
93348
|
-
route: swap.route.map((route) => ({
|
|
93349
|
-
pool_key: {
|
|
93350
|
-
token0: route.pool_key.token0.toBigInt(),
|
|
93351
|
-
token1: route.pool_key.token1.toBigInt(),
|
|
93352
|
-
fee: route.pool_key.fee,
|
|
93353
|
-
tick_spacing: route.pool_key.tick_spacing,
|
|
93354
|
-
extension: ContractAddr.from(route.pool_key.extension).toBigInt()
|
|
93355
|
-
},
|
|
93356
|
-
sqrt_ratio_limit: uint256_exports.bnToUint256(route.sqrt_ratio_limit.toWei()),
|
|
93357
|
-
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
93358
|
-
})),
|
|
93359
|
-
token_amount: {
|
|
93360
|
-
token: swap.token_amount.token.toBigInt(),
|
|
93361
|
-
amount: swap.token_amount.amount.toI129()
|
|
93362
|
-
}
|
|
93363
|
-
})),
|
|
93364
|
-
withdraw_swap_limit_amount: BigInt(_params.withdraw_swap_limit_amount.toWei()),
|
|
93365
|
-
withdraw_swap_weights: _params.withdraw_swap_weights.map((weight) => BigInt(weight.toWei())),
|
|
93366
|
-
close_position: _params.close_position
|
|
93367
|
-
} })
|
|
93590
|
+
withdraw_swap_limit_amount: BigInt(
|
|
93591
|
+
_params.withdraw_swap_limit_amount.toWei()
|
|
93592
|
+
),
|
|
93593
|
+
withdraw_swap_weights: _params.withdraw_swap_weights.map(
|
|
93594
|
+
(weight) => BigInt(weight.toWei())
|
|
93595
|
+
),
|
|
93596
|
+
close_position: _params.close_position
|
|
93597
|
+
}
|
|
93598
|
+
})
|
|
93368
93599
|
};
|
|
93369
93600
|
}
|
|
93370
93601
|
async getHealthFactor() {
|
|
@@ -93373,11 +93604,15 @@ spurious results.`);
|
|
|
93373
93604
|
}
|
|
93374
93605
|
async getNetAPY() {
|
|
93375
93606
|
const positions = await this.getPositions();
|
|
93376
|
-
logger2.verbose(
|
|
93607
|
+
logger2.verbose(
|
|
93608
|
+
`${this.name}::getNetAPY: positions: ${JSON.stringify(positions)}`
|
|
93609
|
+
);
|
|
93377
93610
|
const allZero = positions.every((p) => p.usdValue === 0);
|
|
93378
93611
|
if (allZero) {
|
|
93379
93612
|
const collateralUSD = 1e3;
|
|
93380
|
-
const maxLTV = await this.vesuAdapter.getLTVConfig(
|
|
93613
|
+
const maxLTV = await this.vesuAdapter.getLTVConfig(
|
|
93614
|
+
this.config.networkConfig
|
|
93615
|
+
);
|
|
93381
93616
|
const targetHF = this.config.targetHealthFactor;
|
|
93382
93617
|
const maxDebt = HealthFactorMath.getMaxDebtAmountOnLooping(
|
|
93383
93618
|
new Web3Number(collateralUSD, this.config.collateral.decimals),
|
|
@@ -93765,6 +94000,7 @@ spurious results.`);
|
|
|
93765
94000
|
logger2.error("error initializing client");
|
|
93766
94001
|
return null;
|
|
93767
94002
|
}
|
|
94003
|
+
await new Promise((resolve) => setTimeout(resolve, 5e3));
|
|
93768
94004
|
const orderhistory = await this.getOrderHistory(marketName);
|
|
93769
94005
|
if (!orderhistory || orderhistory.length === 0) {
|
|
93770
94006
|
logger2.error(`error getting order: ${orderId}`);
|
|
@@ -98140,7 +98376,7 @@ spurious results.`);
|
|
|
98140
98376
|
const withdrawalFromExtended = await extendedAdapter.withdrawFromExtended(params.amount);
|
|
98141
98377
|
if (withdrawalFromExtended) {
|
|
98142
98378
|
const extendedHoldings2 = await extendedAdapter.getExtendedDepositAmount();
|
|
98143
|
-
logger2.info(`extendedHoldings after withdrawal ${extendedHoldings2}`);
|
|
98379
|
+
logger2.info(`extendedHoldings after withdrawal ${extendedHoldings2?.availableForWithdrawal}`);
|
|
98144
98380
|
await new Promise((resolve) => setTimeout(resolve, 1e4));
|
|
98145
98381
|
const calls = await this.moveAssetsToVaultAllocator(params.amount, extendedAdapter);
|
|
98146
98382
|
if (calls.length > 0) {
|