@strkfarm/sdk 2.0.0-dev.3 → 2.0.0-dev.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.global.js +395 -159
- package/dist/index.browser.mjs +395 -159
- package/dist/index.js +395 -159
- package/dist/index.mjs +395 -159
- package/package.json +1 -1
- package/src/strategies/universal-adapters/extended-adapter.ts +1 -0
- package/src/strategies/universal-adapters/vesu-multiply-adapter.ts +775 -395
- package/src/strategies/vesu-extended-strategy/utils/helper.ts +4 -4
- package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +1 -1
package/dist/index.browser.mjs
CHANGED
|
@@ -28526,11 +28526,12 @@ var calculateAmountDepositOnExtendedWhenIncurringLosses = async (client) => {
|
|
|
28526
28526
|
logger.error(`error getting extended position: extendedHoldings=${extendedHoldings}, latestPosition=${latestPosition}`);
|
|
28527
28527
|
return null;
|
|
28528
28528
|
}
|
|
28529
|
-
const positionValueInUSD = latestPosition.value;
|
|
28529
|
+
const positionValueInUSD = new Web3Number(latestPosition.value, USDC_TOKEN_DECIMALS);
|
|
28530
28530
|
const equity = extendedHoldings.data.equity;
|
|
28531
|
-
const deposit =
|
|
28532
|
-
return new Web3Number(
|
|
28531
|
+
const deposit = positionValueInUSD.dividedBy(extended_leverage).minus(equity).toFixed(2);
|
|
28532
|
+
return new Web3Number(deposit, USDC_TOKEN_DECIMALS);
|
|
28533
28533
|
} catch (err) {
|
|
28534
|
+
logger.error(`error calculating amount deposit on extended when incurring losses: ${err}`);
|
|
28534
28535
|
return null;
|
|
28535
28536
|
}
|
|
28536
28537
|
};
|
|
@@ -28608,21 +28609,35 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28608
28609
|
vaultAllocator: config.vaultAllocator,
|
|
28609
28610
|
id: ""
|
|
28610
28611
|
});
|
|
28611
|
-
this.tokenMarketData = new TokenMarketData(
|
|
28612
|
+
this.tokenMarketData = new TokenMarketData(
|
|
28613
|
+
this.config.pricer,
|
|
28614
|
+
this.config.networkConfig
|
|
28615
|
+
);
|
|
28612
28616
|
}
|
|
28613
28617
|
async getAPY(supportedPosition) {
|
|
28614
28618
|
const CACHE_KEY = `apy_${this.config.poolId.address}_${supportedPosition.asset.symbol}`;
|
|
28615
28619
|
const cacheData = this.getCache(CACHE_KEY);
|
|
28616
|
-
console.log(
|
|
28620
|
+
console.log(
|
|
28621
|
+
`${_VesuMultiplyAdapter.name}::getAPY cacheData: ${JSON.stringify(
|
|
28622
|
+
cacheData
|
|
28623
|
+
)}`,
|
|
28624
|
+
this.vesuAdapter.config.poolId.shortString(),
|
|
28625
|
+
this.vesuAdapter.config.collateral.symbol,
|
|
28626
|
+
this.vesuAdapter.config.debt.symbol
|
|
28627
|
+
);
|
|
28617
28628
|
if (cacheData) {
|
|
28618
28629
|
return cacheData;
|
|
28619
28630
|
}
|
|
28620
28631
|
try {
|
|
28621
28632
|
const allVesuPools = await VesuAdapter.getVesuPools();
|
|
28622
28633
|
const asset = supportedPosition.asset;
|
|
28623
|
-
const pool = allVesuPools.pools.find(
|
|
28634
|
+
const pool = allVesuPools.pools.find(
|
|
28635
|
+
(p) => this.vesuAdapter.config.poolId.eqString(num9.getHexString(p.id))
|
|
28636
|
+
);
|
|
28624
28637
|
if (!pool) {
|
|
28625
|
-
logger.warn(
|
|
28638
|
+
logger.warn(
|
|
28639
|
+
`VesuMultiplyAdapter: Pool not found for token ${asset.symbol}`
|
|
28640
|
+
);
|
|
28626
28641
|
return {
|
|
28627
28642
|
apy: 0,
|
|
28628
28643
|
type: "base" /* BASE */
|
|
@@ -28632,7 +28647,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28632
28647
|
(a) => a.symbol.toLowerCase() === asset.symbol.toLowerCase()
|
|
28633
28648
|
)?.stats;
|
|
28634
28649
|
if (!assetStats) {
|
|
28635
|
-
logger.warn(
|
|
28650
|
+
logger.warn(
|
|
28651
|
+
`VesuMultiplyAdapter: Asset stats not found for token ${asset.symbol}`
|
|
28652
|
+
);
|
|
28636
28653
|
return {
|
|
28637
28654
|
apy: 0,
|
|
28638
28655
|
type: "base" /* BASE */
|
|
@@ -28643,7 +28660,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28643
28660
|
apy = Number(assetStats.borrowApr?.value || 0) / 1e18;
|
|
28644
28661
|
} else {
|
|
28645
28662
|
const isAssetBTC = asset.symbol.toLowerCase().includes("btc");
|
|
28646
|
-
const baseAPY = Number(
|
|
28663
|
+
const baseAPY = Number(
|
|
28664
|
+
isAssetBTC ? assetStats.btcFiSupplyApr?.value + assetStats.supplyApy?.value : assetStats.supplyApy?.value || 0
|
|
28665
|
+
) / 1e18;
|
|
28647
28666
|
const rewardAPY = Number(assetStats.defiSpringSupplyApr?.value || "0") / 1e18;
|
|
28648
28667
|
const isSupported = this.tokenMarketData.isAPYSupported(asset);
|
|
28649
28668
|
apy = baseAPY + rewardAPY;
|
|
@@ -28659,7 +28678,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28659
28678
|
this.setCache(CACHE_KEY, result, 3e5);
|
|
28660
28679
|
return result;
|
|
28661
28680
|
} catch (error) {
|
|
28662
|
-
logger.error(
|
|
28681
|
+
logger.error(
|
|
28682
|
+
`VesuMultiplyAdapter: Error getting APY for ${supportedPosition.asset.symbol}:`,
|
|
28683
|
+
error
|
|
28684
|
+
);
|
|
28663
28685
|
throw error;
|
|
28664
28686
|
}
|
|
28665
28687
|
}
|
|
@@ -28672,12 +28694,16 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28672
28694
|
try {
|
|
28673
28695
|
this.vesuAdapter.networkConfig = this.config.networkConfig;
|
|
28674
28696
|
this.vesuAdapter.pricer = this.config.pricer;
|
|
28675
|
-
const positions = await this.vesuAdapter.getPositions(
|
|
28697
|
+
const positions = await this.vesuAdapter.getPositions(
|
|
28698
|
+
this.config.networkConfig
|
|
28699
|
+
);
|
|
28676
28700
|
let position = positions.find(
|
|
28677
28701
|
(p) => p.token.address.eq(supportedPosition.asset.address)
|
|
28678
28702
|
);
|
|
28679
28703
|
if (!position) {
|
|
28680
|
-
logger.warn(
|
|
28704
|
+
logger.warn(
|
|
28705
|
+
`VesuMultiplyAdapter: Position not found for token ${supportedPosition.asset.symbol}`
|
|
28706
|
+
);
|
|
28681
28707
|
return {
|
|
28682
28708
|
amount: new Web3Number("0", supportedPosition.asset.decimals),
|
|
28683
28709
|
remarks: "Position not found"
|
|
@@ -28690,12 +28716,18 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28690
28716
|
this.setCache(CACHE_KEY, position, 6e4);
|
|
28691
28717
|
return position;
|
|
28692
28718
|
} catch (error) {
|
|
28693
|
-
logger.error(
|
|
28719
|
+
logger.error(
|
|
28720
|
+
`VesuMultiplyAdapter: Error getting position for ${supportedPosition.asset.symbol}:`,
|
|
28721
|
+
error
|
|
28722
|
+
);
|
|
28694
28723
|
throw error;
|
|
28695
28724
|
}
|
|
28696
28725
|
}
|
|
28697
28726
|
async maxBorrowableAPY() {
|
|
28698
|
-
const collateralAPY = await this.getAPY({
|
|
28727
|
+
const collateralAPY = await this.getAPY({
|
|
28728
|
+
asset: this.config.collateral,
|
|
28729
|
+
isDebt: false
|
|
28730
|
+
});
|
|
28699
28731
|
const apy = collateralAPY.apy * 0.8;
|
|
28700
28732
|
return apy;
|
|
28701
28733
|
}
|
|
@@ -28705,9 +28737,15 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28705
28737
|
try {
|
|
28706
28738
|
this.vesuAdapter.networkConfig = this.config.networkConfig;
|
|
28707
28739
|
this.vesuAdapter.pricer = this.config.pricer;
|
|
28708
|
-
const positions = await this.vesuAdapter.getPositions(
|
|
28709
|
-
|
|
28710
|
-
|
|
28740
|
+
const positions = await this.vesuAdapter.getPositions(
|
|
28741
|
+
this.config.networkConfig
|
|
28742
|
+
);
|
|
28743
|
+
const collateralPosition = positions.find(
|
|
28744
|
+
(p) => p.token.address.eq(collateral.address)
|
|
28745
|
+
);
|
|
28746
|
+
const debtPosition = positions.find(
|
|
28747
|
+
(p) => p.token.address.eq(debt.address)
|
|
28748
|
+
);
|
|
28711
28749
|
if (!collateralPosition || !debtPosition) {
|
|
28712
28750
|
throw new Error("Could not find current positions");
|
|
28713
28751
|
}
|
|
@@ -28717,13 +28755,23 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28717
28755
|
debt,
|
|
28718
28756
|
maxBorrowableAPY
|
|
28719
28757
|
);
|
|
28720
|
-
logger.verbose(
|
|
28721
|
-
|
|
28758
|
+
logger.verbose(
|
|
28759
|
+
`VesuMultiplyAdapter: Max borrowable: ${maxBorrowable.toNumber()}`
|
|
28760
|
+
);
|
|
28761
|
+
const debtCap = await this.vesuAdapter.getDebtCap(
|
|
28762
|
+
this.config.networkConfig
|
|
28763
|
+
);
|
|
28722
28764
|
logger.verbose(`VesuMultiplyAdapter: Debt cap: ${debtCap.toNumber()}`);
|
|
28723
28765
|
const actualMaxBorrowable = maxBorrowable.minimum(debtCap);
|
|
28724
|
-
logger.verbose(
|
|
28725
|
-
|
|
28726
|
-
|
|
28766
|
+
logger.verbose(
|
|
28767
|
+
`VesuMultiplyAdapter: Actual max borrowable: ${actualMaxBorrowable.toNumber()}`
|
|
28768
|
+
);
|
|
28769
|
+
const maxLTV = await this.vesuAdapter.getLTVConfig(
|
|
28770
|
+
this.config.networkConfig
|
|
28771
|
+
);
|
|
28772
|
+
const collateralPrice = await this.config.pricer.getPrice(
|
|
28773
|
+
collateral.symbol
|
|
28774
|
+
);
|
|
28727
28775
|
if (collateralPrice.price === 0) {
|
|
28728
28776
|
throw new Error("Collateral price is 0");
|
|
28729
28777
|
}
|
|
@@ -28741,14 +28789,25 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28741
28789
|
);
|
|
28742
28790
|
const maxDepositAmount = amount ? amount.minimum(maxCollateralFromDebt) : maxCollateralFromDebt;
|
|
28743
28791
|
const usdValue = await this.getUSDValue(collateral, maxDepositAmount);
|
|
28744
|
-
logger.verbose(
|
|
28745
|
-
|
|
28746
|
-
|
|
28792
|
+
logger.verbose(
|
|
28793
|
+
`VesuMultiplyAdapter: Max deposit::USD value: ${usdValue}, amount: ${maxDepositAmount.toNumber()}`
|
|
28794
|
+
);
|
|
28795
|
+
const apys = await Promise.all([
|
|
28796
|
+
this.getAPY({ asset: collateral, isDebt: false }),
|
|
28797
|
+
this.getAPY({ asset: debt, isDebt: true })
|
|
28798
|
+
]);
|
|
28799
|
+
logger.verbose(
|
|
28800
|
+
`VesuMultiplyAdapter: Apys: ${apys[0].apy}, ${apys[1].apy}`
|
|
28801
|
+
);
|
|
28747
28802
|
const borrowAmountUSD = actualMaxBorrowable.multipliedBy(debtPrice.price);
|
|
28748
|
-
logger.verbose(
|
|
28803
|
+
logger.verbose(
|
|
28804
|
+
`VesuMultiplyAdapter: Borrow amount: ${actualMaxBorrowable.toNumber()}, borrow amount USD: ${borrowAmountUSD.toNumber()}`
|
|
28805
|
+
);
|
|
28749
28806
|
const netCollateralUSD = usdValue + borrowAmountUSD.toNumber();
|
|
28750
28807
|
const netAPY = (apys[0].apy * netCollateralUSD + apys[1].apy * borrowAmountUSD.toNumber()) / usdValue;
|
|
28751
|
-
logger.verbose(
|
|
28808
|
+
logger.verbose(
|
|
28809
|
+
`VesuMultiplyAdapter: Max deposit amount: ${maxDepositAmount.toNumber()}, netAPY: ${netAPY}`
|
|
28810
|
+
);
|
|
28752
28811
|
return {
|
|
28753
28812
|
tokenInfo: collateral,
|
|
28754
28813
|
amount: maxDepositAmount,
|
|
@@ -28761,7 +28820,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28761
28820
|
protocol: this.protocol
|
|
28762
28821
|
};
|
|
28763
28822
|
} catch (error) {
|
|
28764
|
-
logger.error(
|
|
28823
|
+
logger.error(
|
|
28824
|
+
`VesuMultiplyAdapter: Error calculating max deposit:`,
|
|
28825
|
+
error
|
|
28826
|
+
);
|
|
28765
28827
|
throw error;
|
|
28766
28828
|
}
|
|
28767
28829
|
}
|
|
@@ -28771,9 +28833,15 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28771
28833
|
try {
|
|
28772
28834
|
this.vesuAdapter.networkConfig = this.config.networkConfig;
|
|
28773
28835
|
this.vesuAdapter.pricer = this.config.pricer;
|
|
28774
|
-
const positions = await this.vesuAdapter.getPositions(
|
|
28775
|
-
|
|
28776
|
-
|
|
28836
|
+
const positions = await this.vesuAdapter.getPositions(
|
|
28837
|
+
this.config.networkConfig
|
|
28838
|
+
);
|
|
28839
|
+
const collateralPosition = positions.find(
|
|
28840
|
+
(p) => p.token.address.eq(collateral.address)
|
|
28841
|
+
);
|
|
28842
|
+
const debtPosition = positions.find(
|
|
28843
|
+
(p) => p.token.address.eq(this.config.debt.address)
|
|
28844
|
+
);
|
|
28777
28845
|
if (!collateralPosition || !debtPosition) {
|
|
28778
28846
|
throw new Error("Could not find current positions");
|
|
28779
28847
|
}
|
|
@@ -28783,11 +28851,20 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28783
28851
|
const result = maxWithdrawable.greaterThan(0) ? maxWithdrawable : new Web3Number("0", collateral.decimals);
|
|
28784
28852
|
const usdValue = await this.getUSDValue(collateral, result);
|
|
28785
28853
|
const debtUSD = debtPosition.usdValue;
|
|
28786
|
-
logger.verbose(
|
|
28787
|
-
|
|
28788
|
-
|
|
28854
|
+
logger.verbose(
|
|
28855
|
+
`VesuMultiplyAdapter: Debt USD: ${debtUSD}, collateral USD: ${usdValue}`
|
|
28856
|
+
);
|
|
28857
|
+
const apys = await Promise.all([
|
|
28858
|
+
this.getAPY({ asset: collateral, isDebt: false }),
|
|
28859
|
+
this.getAPY({ asset: debt, isDebt: true })
|
|
28860
|
+
]);
|
|
28861
|
+
logger.verbose(
|
|
28862
|
+
`VesuMultiplyAdapter: Apys: ${apys[0].apy}, ${apys[1].apy}`
|
|
28863
|
+
);
|
|
28789
28864
|
const netAPY = usdValue - debtUSD > 0 ? (apys[0].apy * usdValue + apys[1].apy * debtUSD) / (usdValue - debtUSD) : 0;
|
|
28790
|
-
logger.verbose(
|
|
28865
|
+
logger.verbose(
|
|
28866
|
+
`VesuMultiplyAdapter: Max withdraw amount: ${result.toNumber()}, netAPY: ${netAPY}`
|
|
28867
|
+
);
|
|
28791
28868
|
return {
|
|
28792
28869
|
tokenInfo: collateral,
|
|
28793
28870
|
amount: result,
|
|
@@ -28800,14 +28877,19 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28800
28877
|
protocol: this.protocol
|
|
28801
28878
|
};
|
|
28802
28879
|
} catch (error) {
|
|
28803
|
-
logger.error(
|
|
28880
|
+
logger.error(
|
|
28881
|
+
`VesuMultiplyAdapter: Error calculating max withdraw:`,
|
|
28882
|
+
error
|
|
28883
|
+
);
|
|
28804
28884
|
throw error;
|
|
28805
28885
|
}
|
|
28806
28886
|
}
|
|
28807
28887
|
_getDepositLeaf() {
|
|
28808
28888
|
const collateral = this.config.collateral;
|
|
28809
28889
|
const debt = this.config.debt;
|
|
28810
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28890
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28891
|
+
this.config.poolId
|
|
28892
|
+
);
|
|
28811
28893
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
28812
28894
|
return [
|
|
28813
28895
|
// Approval step for collateral
|
|
@@ -28871,7 +28953,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28871
28953
|
];
|
|
28872
28954
|
}
|
|
28873
28955
|
_getWithdrawLeaf() {
|
|
28874
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28956
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28957
|
+
this.config.poolId
|
|
28958
|
+
);
|
|
28875
28959
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
28876
28960
|
const collateral = this.config.collateral;
|
|
28877
28961
|
const debt = this.config.debt;
|
|
@@ -28928,33 +29012,51 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28928
29012
|
const leafConfigs = this._getDepositLeaf();
|
|
28929
29013
|
const leaves = leafConfigs.map((config) => {
|
|
28930
29014
|
const { target, method, packedArguments, sanitizer, id } = config;
|
|
28931
|
-
const leaf = this.constructSimpleLeafData(
|
|
28932
|
-
|
|
28933
|
-
|
|
28934
|
-
|
|
28935
|
-
|
|
28936
|
-
|
|
29015
|
+
const leaf = this.constructSimpleLeafData(
|
|
29016
|
+
{
|
|
29017
|
+
id,
|
|
29018
|
+
target,
|
|
29019
|
+
method,
|
|
29020
|
+
packedArguments
|
|
29021
|
+
},
|
|
29022
|
+
sanitizer
|
|
29023
|
+
);
|
|
28937
29024
|
return leaf;
|
|
28938
29025
|
});
|
|
28939
|
-
return {
|
|
29026
|
+
return {
|
|
29027
|
+
leaves,
|
|
29028
|
+
callConstructor: this.getDepositCall.bind(
|
|
29029
|
+
this
|
|
29030
|
+
)
|
|
29031
|
+
};
|
|
28940
29032
|
}
|
|
28941
29033
|
getWithdrawAdapter() {
|
|
28942
29034
|
const leafConfigs = this._getWithdrawLeaf();
|
|
28943
29035
|
const leaves = leafConfigs.map((config) => {
|
|
28944
29036
|
const { target, method, packedArguments, sanitizer, id } = config;
|
|
28945
|
-
const leaf = this.constructSimpleLeafData(
|
|
28946
|
-
|
|
28947
|
-
|
|
28948
|
-
|
|
28949
|
-
|
|
28950
|
-
|
|
29037
|
+
const leaf = this.constructSimpleLeafData(
|
|
29038
|
+
{
|
|
29039
|
+
id,
|
|
29040
|
+
target,
|
|
29041
|
+
method,
|
|
29042
|
+
packedArguments
|
|
29043
|
+
},
|
|
29044
|
+
sanitizer
|
|
29045
|
+
);
|
|
28951
29046
|
return leaf;
|
|
28952
29047
|
});
|
|
28953
|
-
return {
|
|
29048
|
+
return {
|
|
29049
|
+
leaves,
|
|
29050
|
+
callConstructor: this.getWithdrawCall.bind(
|
|
29051
|
+
this
|
|
29052
|
+
)
|
|
29053
|
+
};
|
|
28954
29054
|
}
|
|
28955
29055
|
async getDepositCall(params) {
|
|
28956
29056
|
const collateral = this.config.collateral;
|
|
28957
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
29057
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
29058
|
+
this.config.poolId
|
|
29059
|
+
);
|
|
28958
29060
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
28959
29061
|
const uint256MarginAmount = uint25612.bnToUint256(params.amount.toWei());
|
|
28960
29062
|
return [
|
|
@@ -29026,7 +29128,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29026
29128
|
];
|
|
29027
29129
|
}
|
|
29028
29130
|
async getWithdrawCall(params) {
|
|
29029
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
29131
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
29132
|
+
this.config.poolId
|
|
29133
|
+
);
|
|
29030
29134
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
29031
29135
|
return [
|
|
29032
29136
|
// Switch delegation on
|
|
@@ -29081,7 +29185,11 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29081
29185
|
];
|
|
29082
29186
|
}
|
|
29083
29187
|
async getMultiplyCallCalldata(params, isDeposit) {
|
|
29084
|
-
logger.verbose(
|
|
29188
|
+
logger.verbose(
|
|
29189
|
+
`${_VesuMultiplyAdapter.name}::getMultiplyCallCalldata params: ${JSON.stringify(
|
|
29190
|
+
params
|
|
29191
|
+
)}, isDeposit: ${isDeposit}, collateral: ${this.config.collateral.symbol}, debt: ${this.config.debt.symbol}`
|
|
29192
|
+
);
|
|
29085
29193
|
const { isV2 } = getVesuSingletonAddress(this.config.poolId);
|
|
29086
29194
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
29087
29195
|
const multiplyContract = new Contract12({
|
|
@@ -29091,42 +29199,83 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29091
29199
|
});
|
|
29092
29200
|
let leverSwap = [];
|
|
29093
29201
|
let leverSwapLimitAmount = Web3Number.fromWei(0, this.config.debt.decimals);
|
|
29094
|
-
const existingPositions = await this.vesuAdapter.getPositions(
|
|
29095
|
-
|
|
29202
|
+
const existingPositions = await this.vesuAdapter.getPositions(
|
|
29203
|
+
this.config.networkConfig
|
|
29204
|
+
);
|
|
29205
|
+
const collateralisation = await this.vesuAdapter.getCollateralization(
|
|
29206
|
+
this.config.networkConfig
|
|
29207
|
+
);
|
|
29096
29208
|
const existingCollateralInfo = existingPositions[0];
|
|
29097
29209
|
const existingDebtInfo = existingPositions[1];
|
|
29098
29210
|
const isDexPriceRequired = existingDebtInfo.token.symbol !== "USDC";
|
|
29099
|
-
logger.debug(`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall existingCollateralInfo: ${JSON.stringify(
|
|
29100
|
-
|
|
29211
|
+
logger.debug(`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall existingCollateralInfo: ${JSON.stringify(
|
|
29212
|
+
existingCollateralInfo
|
|
29213
|
+
)},
|
|
29214
|
+
existingDebtInfo: ${JSON.stringify(
|
|
29215
|
+
existingDebtInfo
|
|
29216
|
+
)}, collateralisation: ${JSON.stringify(collateralisation)}`);
|
|
29101
29217
|
const collateralPrice = collateralisation[0].usdValue > 0 ? collateralisation[0].usdValue / existingCollateralInfo.amount.toNumber() : (await this.config.pricer.getPrice(this.config.collateral.symbol)).price;
|
|
29102
29218
|
const debtPrice = collateralisation[1].usdValue > 0 ? collateralisation[1].usdValue / existingDebtInfo.amount.toNumber() : (await this.config.pricer.getPrice(this.config.debt.symbol)).price;
|
|
29103
|
-
logger.debug(
|
|
29104
|
-
|
|
29105
|
-
|
|
29106
|
-
const
|
|
29107
|
-
|
|
29219
|
+
logger.debug(
|
|
29220
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall collateralPrice: ${collateralPrice}, debtPrice: ${debtPrice}`
|
|
29221
|
+
);
|
|
29222
|
+
const legLTV = await this.vesuAdapter.getLTVConfig(
|
|
29223
|
+
this.config.networkConfig
|
|
29224
|
+
);
|
|
29225
|
+
const ekuboQuoter = new EkuboQuoter(
|
|
29226
|
+
this.config.networkConfig,
|
|
29227
|
+
this.config.pricer
|
|
29228
|
+
);
|
|
29229
|
+
const dexPrice = isDexPriceRequired ? await ekuboQuoter.getDexPrice(
|
|
29230
|
+
this.config.collateral,
|
|
29231
|
+
this.config.debt,
|
|
29232
|
+
this.config.quoteAmountToFetchPrice
|
|
29233
|
+
) : 1;
|
|
29234
|
+
logger.verbose(
|
|
29235
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall dexPrice: ${dexPrice}, ltv: ${legLTV}`
|
|
29236
|
+
);
|
|
29108
29237
|
const addedCollateral = params.amount.multipliedBy(isDeposit ? 1 : -1);
|
|
29109
|
-
logger.verbose(
|
|
29238
|
+
logger.verbose(
|
|
29239
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall addedCollateral: ${addedCollateral}`
|
|
29240
|
+
);
|
|
29110
29241
|
const numeratorPart1 = existingCollateralInfo.amount.plus(addedCollateral).multipliedBy(collateralPrice).multipliedBy(legLTV);
|
|
29111
|
-
logger.verbose(
|
|
29242
|
+
logger.verbose(
|
|
29243
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart1: ${numeratorPart1}`
|
|
29244
|
+
);
|
|
29112
29245
|
const numeratorPart2 = existingDebtInfo.amount.multipliedBy(debtPrice).multipliedBy(this.config.targetHealthFactor);
|
|
29113
|
-
logger.verbose(
|
|
29246
|
+
logger.verbose(
|
|
29247
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart2: ${numeratorPart2}`
|
|
29248
|
+
);
|
|
29114
29249
|
const denominatorPart = this.config.targetHealthFactor - legLTV / dexPrice;
|
|
29115
|
-
logger.verbose(
|
|
29250
|
+
logger.verbose(
|
|
29251
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall denominatorPart: ${denominatorPart}`
|
|
29252
|
+
);
|
|
29116
29253
|
const x_debt_usd = numeratorPart1.minus(numeratorPart2).dividedBy(denominatorPart);
|
|
29117
|
-
logger.verbose(
|
|
29118
|
-
|
|
29119
|
-
|
|
29254
|
+
logger.verbose(
|
|
29255
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall x_debt_usd: ${x_debt_usd}`
|
|
29256
|
+
);
|
|
29257
|
+
logger.debug(
|
|
29258
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart1: ${numeratorPart1}, numeratorPart2: ${numeratorPart2}, denominatorPart: ${denominatorPart}`
|
|
29259
|
+
);
|
|
29260
|
+
let debtAmount = new Web3Number(
|
|
29261
|
+
x_debt_usd.dividedBy(debtPrice).toFixed(this.config.debt.decimals),
|
|
29262
|
+
this.config.debt.decimals
|
|
29263
|
+
);
|
|
29120
29264
|
const marginAmount = addedCollateral;
|
|
29121
29265
|
const collateralToken = this.config.collateral;
|
|
29122
29266
|
const debtToken = this.config.debt;
|
|
29123
|
-
const debtAmountInCollateralUnits = new Web3Number(
|
|
29267
|
+
const debtAmountInCollateralUnits = new Web3Number(
|
|
29268
|
+
debtAmount.multipliedBy(debtPrice).dividedBy(collateralPrice).multipliedBy(10 ** collateralToken.decimals).toFixed(0),
|
|
29269
|
+
collateralToken.decimals
|
|
29270
|
+
);
|
|
29124
29271
|
const isIncrease = debtAmount.greaterThanOrEqualTo(0);
|
|
29125
29272
|
if (isIncrease && debtAmount.lessThan(0)) {
|
|
29126
29273
|
} else if (!isIncrease && debtAmount.greaterThan(0)) {
|
|
29127
29274
|
debtAmount = Web3Number.fromWei(0, this.config.debt.decimals);
|
|
29128
29275
|
}
|
|
29129
|
-
logger.verbose(
|
|
29276
|
+
logger.verbose(
|
|
29277
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall debtAmount: ${debtAmount}, marginAmount: ${marginAmount}`
|
|
29278
|
+
);
|
|
29130
29279
|
if (!debtAmount.isZero()) {
|
|
29131
29280
|
try {
|
|
29132
29281
|
const swapQuote = await ekuboQuoter.getQuote(
|
|
@@ -29136,26 +29285,49 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29136
29285
|
// negative for exact amount out
|
|
29137
29286
|
);
|
|
29138
29287
|
if (swapQuote.price_impact < 0.01) {
|
|
29139
|
-
leverSwap = ekuboQuoter.getVesuMultiplyQuote(
|
|
29288
|
+
leverSwap = debtAmount.isNegative() ? ekuboQuoter.getVesuMultiplyQuote(
|
|
29289
|
+
swapQuote,
|
|
29290
|
+
collateralToken,
|
|
29291
|
+
debtToken
|
|
29292
|
+
) : ekuboQuoter.getVesuMultiplyQuote(
|
|
29293
|
+
swapQuote,
|
|
29294
|
+
debtToken,
|
|
29295
|
+
collateralToken
|
|
29296
|
+
);
|
|
29140
29297
|
const MAX_SLIPPAGE = 2e-3;
|
|
29141
29298
|
if (debtAmount.greaterThan(0)) {
|
|
29142
29299
|
leverSwapLimitAmount = debtAmount.multipliedBy(1 + MAX_SLIPPAGE);
|
|
29143
29300
|
} else if (debtAmount.lessThan(0)) {
|
|
29144
29301
|
leverSwapLimitAmount = debtAmount.abs().multipliedBy(1 - MAX_SLIPPAGE);
|
|
29145
29302
|
} else {
|
|
29146
|
-
leverSwapLimitAmount = Web3Number.fromWei(
|
|
29303
|
+
leverSwapLimitAmount = Web3Number.fromWei(
|
|
29304
|
+
0,
|
|
29305
|
+
this.config.debt.decimals
|
|
29306
|
+
);
|
|
29147
29307
|
}
|
|
29148
29308
|
await new Promise((resolve) => setTimeout(resolve, 1e4));
|
|
29149
29309
|
} else {
|
|
29150
|
-
throw new Error(
|
|
29310
|
+
throw new Error(
|
|
29311
|
+
`VesuMultiplyAdapter: Price impact too high (${swapQuote.price_impact}), skipping swap`
|
|
29312
|
+
);
|
|
29151
29313
|
}
|
|
29152
29314
|
} catch (error) {
|
|
29153
|
-
throw new Error(
|
|
29315
|
+
throw new Error(
|
|
29316
|
+
`VesuMultiplyAdapter: Failed to get swap quote: ${error}`
|
|
29317
|
+
);
|
|
29154
29318
|
}
|
|
29155
29319
|
}
|
|
29156
|
-
const multiplyParams = await this.getLeverParams(
|
|
29320
|
+
const multiplyParams = await this.getLeverParams(
|
|
29321
|
+
isIncrease,
|
|
29322
|
+
params,
|
|
29323
|
+
leverSwap,
|
|
29324
|
+
leverSwapLimitAmount
|
|
29325
|
+
);
|
|
29157
29326
|
const call = multiplyContract.populate("modify_lever", {
|
|
29158
|
-
modify_lever_params: this.formatMultiplyParams(
|
|
29327
|
+
modify_lever_params: this.formatMultiplyParams(
|
|
29328
|
+
isIncrease,
|
|
29329
|
+
multiplyParams
|
|
29330
|
+
)
|
|
29159
29331
|
});
|
|
29160
29332
|
return call.calldata;
|
|
29161
29333
|
}
|
|
@@ -29169,7 +29341,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29169
29341
|
add_margin: params.amount,
|
|
29170
29342
|
// multiplied by collateral decimals in format
|
|
29171
29343
|
margin_swap: [],
|
|
29172
|
-
margin_swap_limit_amount: Web3Number.fromWei(
|
|
29344
|
+
margin_swap_limit_amount: Web3Number.fromWei(
|
|
29345
|
+
0,
|
|
29346
|
+
this.config.collateral.decimals
|
|
29347
|
+
),
|
|
29173
29348
|
lever_swap: leverSwap,
|
|
29174
29349
|
lever_swap_limit_amount: leverSwapLimitAmount
|
|
29175
29350
|
} : {
|
|
@@ -29183,7 +29358,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29183
29358
|
lever_swap_limit_amount: leverSwapLimitAmount,
|
|
29184
29359
|
lever_swap_weights: [],
|
|
29185
29360
|
withdraw_swap: [],
|
|
29186
|
-
withdraw_swap_limit_amount: Web3Number.fromWei(
|
|
29361
|
+
withdraw_swap_limit_amount: Web3Number.fromWei(
|
|
29362
|
+
0,
|
|
29363
|
+
this.config.collateral.decimals
|
|
29364
|
+
),
|
|
29187
29365
|
withdraw_swap_weights: [],
|
|
29188
29366
|
close_position: false
|
|
29189
29367
|
};
|
|
@@ -29199,12 +29377,16 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29199
29377
|
});
|
|
29200
29378
|
let leverSwap = [];
|
|
29201
29379
|
let leverSwapLimitAmount = Web3Number.fromWei(0, this.config.debt.decimals);
|
|
29202
|
-
const existingPositions = await this.vesuAdapter.getPositions(
|
|
29380
|
+
const existingPositions = await this.vesuAdapter.getPositions(
|
|
29381
|
+
this.config.networkConfig
|
|
29382
|
+
);
|
|
29203
29383
|
const existingCollateralInfo = existingPositions[0];
|
|
29204
29384
|
const existingDebtInfo = existingPositions[1];
|
|
29205
29385
|
const collateralToken = this.config.collateral;
|
|
29206
29386
|
const debtToken = this.config.debt;
|
|
29207
|
-
const collateralPrice = await this.config.pricer.getPrice(
|
|
29387
|
+
const collateralPrice = await this.config.pricer.getPrice(
|
|
29388
|
+
collateralToken.symbol
|
|
29389
|
+
);
|
|
29208
29390
|
const debtPrice = await this.config.pricer.getPrice(debtToken.symbol);
|
|
29209
29391
|
const { deltadebtAmountUnits: debtAmountToRepay } = calculateDebtReductionAmountForWithdrawal(
|
|
29210
29392
|
existingDebtInfo.amount,
|
|
@@ -29218,8 +29400,14 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29218
29400
|
if (!debtAmountToRepay) {
|
|
29219
29401
|
throw new Error("error calculating debt amount to repay");
|
|
29220
29402
|
}
|
|
29221
|
-
const ekuboQuoter = new EkuboQuoter(
|
|
29222
|
-
|
|
29403
|
+
const ekuboQuoter = new EkuboQuoter(
|
|
29404
|
+
this.config.networkConfig,
|
|
29405
|
+
this.config.pricer
|
|
29406
|
+
);
|
|
29407
|
+
const debtInDebtUnits = new Web3Number(
|
|
29408
|
+
debtAmountToRepay,
|
|
29409
|
+
debtToken.decimals
|
|
29410
|
+
).dividedBy(debtPrice.price).multipliedBy(10 ** debtToken.decimals);
|
|
29223
29411
|
const swapQuote = await ekuboQuoter.getQuote(
|
|
29224
29412
|
debtToken.address.address,
|
|
29225
29413
|
collateralToken.address.address,
|
|
@@ -29227,12 +29415,23 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29227
29415
|
);
|
|
29228
29416
|
const MAX_SLIPPAGE = 2e-3;
|
|
29229
29417
|
if (swapQuote.price_impact < 25e-4) {
|
|
29230
|
-
leverSwap = ekuboQuoter.getVesuMultiplyQuote(
|
|
29418
|
+
leverSwap = ekuboQuoter.getVesuMultiplyQuote(
|
|
29419
|
+
swapQuote,
|
|
29420
|
+
collateralToken,
|
|
29421
|
+
debtToken
|
|
29422
|
+
);
|
|
29231
29423
|
} else {
|
|
29232
|
-
logger.error(
|
|
29424
|
+
logger.error(
|
|
29425
|
+
`VesuMultiplyAdapter: Price impact too high (${swapQuote.price_impact}), skipping swap`
|
|
29426
|
+
);
|
|
29233
29427
|
}
|
|
29234
29428
|
leverSwapLimitAmount = new Web3Number(debtAmountToRepay, debtToken.decimals).abs().multipliedBy(1 + MAX_SLIPPAGE);
|
|
29235
|
-
const multiplyParams = await this.getLeverParams(
|
|
29429
|
+
const multiplyParams = await this.getLeverParams(
|
|
29430
|
+
false,
|
|
29431
|
+
params,
|
|
29432
|
+
leverSwap,
|
|
29433
|
+
leverSwapLimitAmount
|
|
29434
|
+
);
|
|
29236
29435
|
const call = multiplyContract.populate("modify_lever", {
|
|
29237
29436
|
modify_lever_params: this.formatMultiplyParams(false, multiplyParams)
|
|
29238
29437
|
});
|
|
@@ -29242,100 +29441,132 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29242
29441
|
if (isIncrease) {
|
|
29243
29442
|
const _params2 = params;
|
|
29244
29443
|
return {
|
|
29245
|
-
action: new CairoCustomEnum3({
|
|
29246
|
-
|
|
29247
|
-
|
|
29248
|
-
|
|
29249
|
-
|
|
29250
|
-
|
|
29251
|
-
|
|
29444
|
+
action: new CairoCustomEnum3({
|
|
29445
|
+
IncreaseLever: {
|
|
29446
|
+
pool_id: _params2.pool_id.toBigInt(),
|
|
29447
|
+
collateral_asset: _params2.collateral_asset.toBigInt(),
|
|
29448
|
+
debt_asset: _params2.debt_asset.toBigInt(),
|
|
29449
|
+
user: _params2.user.toBigInt(),
|
|
29450
|
+
add_margin: BigInt(_params2.add_margin.toWei()),
|
|
29451
|
+
margin_swap: _params2.margin_swap.map((swap) => ({
|
|
29452
|
+
route: swap.route.map((route) => ({
|
|
29453
|
+
pool_key: {
|
|
29454
|
+
token0: route.pool_key.token0.toBigInt(),
|
|
29455
|
+
token1: route.pool_key.token1.toBigInt(),
|
|
29456
|
+
fee: route.pool_key.fee,
|
|
29457
|
+
tick_spacing: route.pool_key.tick_spacing,
|
|
29458
|
+
extension: BigInt(
|
|
29459
|
+
num9.hexToDecimalString(route.pool_key.extension)
|
|
29460
|
+
)
|
|
29461
|
+
},
|
|
29462
|
+
sqrt_ratio_limit: uint25612.bnToUint256(
|
|
29463
|
+
route.sqrt_ratio_limit.toWei()
|
|
29464
|
+
),
|
|
29465
|
+
skip_ahead: BigInt(100)
|
|
29466
|
+
})),
|
|
29467
|
+
token_amount: {
|
|
29468
|
+
token: swap.token_amount.token.toBigInt(),
|
|
29469
|
+
amount: swap.token_amount.amount.toI129()
|
|
29470
|
+
}
|
|
29471
|
+
})),
|
|
29472
|
+
margin_swap_limit_amount: BigInt(
|
|
29473
|
+
_params2.margin_swap_limit_amount.toWei()
|
|
29474
|
+
),
|
|
29475
|
+
lever_swap: _params2.lever_swap.map((swap) => ({
|
|
29476
|
+
route: swap.route.map((route) => ({
|
|
29477
|
+
pool_key: {
|
|
29478
|
+
token0: route.pool_key.token0.toBigInt(),
|
|
29479
|
+
token1: route.pool_key.token1.toBigInt(),
|
|
29480
|
+
fee: route.pool_key.fee,
|
|
29481
|
+
tick_spacing: route.pool_key.tick_spacing,
|
|
29482
|
+
extension: BigInt(
|
|
29483
|
+
num9.hexToDecimalString(route.pool_key.extension)
|
|
29484
|
+
)
|
|
29485
|
+
},
|
|
29486
|
+
sqrt_ratio_limit: uint25612.bnToUint256(
|
|
29487
|
+
route.sqrt_ratio_limit.toWei()
|
|
29488
|
+
),
|
|
29489
|
+
skip_ahead: BigInt(0)
|
|
29490
|
+
})),
|
|
29491
|
+
token_amount: {
|
|
29492
|
+
token: swap.token_amount.token.toBigInt(),
|
|
29493
|
+
amount: swap.token_amount.amount.toI129()
|
|
29494
|
+
}
|
|
29495
|
+
})),
|
|
29496
|
+
lever_swap_limit_amount: BigInt(
|
|
29497
|
+
_params2.lever_swap_limit_amount.toWei()
|
|
29498
|
+
)
|
|
29499
|
+
}
|
|
29500
|
+
})
|
|
29501
|
+
};
|
|
29502
|
+
}
|
|
29503
|
+
const _params = params;
|
|
29504
|
+
return {
|
|
29505
|
+
action: new CairoCustomEnum3({
|
|
29506
|
+
DecreaseLever: {
|
|
29507
|
+
pool_id: _params.pool_id.toBigInt(),
|
|
29508
|
+
collateral_asset: _params.collateral_asset.toBigInt(),
|
|
29509
|
+
debt_asset: _params.debt_asset.toBigInt(),
|
|
29510
|
+
user: _params.user.toBigInt(),
|
|
29511
|
+
sub_margin: BigInt(_params.sub_margin.toWei()),
|
|
29512
|
+
recipient: _params.recipient.toBigInt(),
|
|
29513
|
+
lever_swap: _params.lever_swap.map((swap) => ({
|
|
29252
29514
|
route: swap.route.map((route) => ({
|
|
29253
29515
|
pool_key: {
|
|
29254
29516
|
token0: route.pool_key.token0.toBigInt(),
|
|
29255
29517
|
token1: route.pool_key.token1.toBigInt(),
|
|
29256
29518
|
fee: route.pool_key.fee,
|
|
29257
29519
|
tick_spacing: route.pool_key.tick_spacing,
|
|
29258
|
-
extension:
|
|
29520
|
+
extension: ContractAddr.from(
|
|
29521
|
+
route.pool_key.extension
|
|
29522
|
+
).toBigInt()
|
|
29259
29523
|
},
|
|
29260
|
-
sqrt_ratio_limit: uint25612.bnToUint256(
|
|
29261
|
-
|
|
29524
|
+
sqrt_ratio_limit: uint25612.bnToUint256(
|
|
29525
|
+
route.sqrt_ratio_limit.toWei()
|
|
29526
|
+
),
|
|
29527
|
+
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
29262
29528
|
})),
|
|
29263
29529
|
token_amount: {
|
|
29264
29530
|
token: swap.token_amount.token.toBigInt(),
|
|
29265
29531
|
amount: swap.token_amount.amount.toI129()
|
|
29266
29532
|
}
|
|
29267
29533
|
})),
|
|
29268
|
-
|
|
29269
|
-
|
|
29534
|
+
lever_swap_limit_amount: BigInt(
|
|
29535
|
+
_params.lever_swap_limit_amount.toWei()
|
|
29536
|
+
),
|
|
29537
|
+
lever_swap_weights: _params.lever_swap_weights.map(
|
|
29538
|
+
(weight) => BigInt(weight.toWei())
|
|
29539
|
+
),
|
|
29540
|
+
withdraw_swap: _params.withdraw_swap.map((swap) => ({
|
|
29270
29541
|
route: swap.route.map((route) => ({
|
|
29271
29542
|
pool_key: {
|
|
29272
29543
|
token0: route.pool_key.token0.toBigInt(),
|
|
29273
29544
|
token1: route.pool_key.token1.toBigInt(),
|
|
29274
29545
|
fee: route.pool_key.fee,
|
|
29275
29546
|
tick_spacing: route.pool_key.tick_spacing,
|
|
29276
|
-
extension:
|
|
29547
|
+
extension: ContractAddr.from(
|
|
29548
|
+
route.pool_key.extension
|
|
29549
|
+
).toBigInt()
|
|
29277
29550
|
},
|
|
29278
|
-
sqrt_ratio_limit: uint25612.bnToUint256(
|
|
29279
|
-
|
|
29551
|
+
sqrt_ratio_limit: uint25612.bnToUint256(
|
|
29552
|
+
route.sqrt_ratio_limit.toWei()
|
|
29553
|
+
),
|
|
29554
|
+
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
29280
29555
|
})),
|
|
29281
29556
|
token_amount: {
|
|
29282
29557
|
token: swap.token_amount.token.toBigInt(),
|
|
29283
29558
|
amount: swap.token_amount.amount.toI129()
|
|
29284
29559
|
}
|
|
29285
29560
|
})),
|
|
29286
|
-
|
|
29287
|
-
|
|
29288
|
-
|
|
29289
|
-
|
|
29290
|
-
|
|
29291
|
-
|
|
29292
|
-
|
|
29293
|
-
|
|
29294
|
-
|
|
29295
|
-
debt_asset: _params.debt_asset.toBigInt(),
|
|
29296
|
-
user: _params.user.toBigInt(),
|
|
29297
|
-
sub_margin: BigInt(_params.sub_margin.toWei()),
|
|
29298
|
-
recipient: _params.recipient.toBigInt(),
|
|
29299
|
-
lever_swap: _params.lever_swap.map((swap) => ({
|
|
29300
|
-
route: swap.route.map((route) => ({
|
|
29301
|
-
pool_key: {
|
|
29302
|
-
token0: route.pool_key.token0.toBigInt(),
|
|
29303
|
-
token1: route.pool_key.token1.toBigInt(),
|
|
29304
|
-
fee: route.pool_key.fee,
|
|
29305
|
-
tick_spacing: route.pool_key.tick_spacing,
|
|
29306
|
-
extension: ContractAddr.from(route.pool_key.extension).toBigInt()
|
|
29307
|
-
},
|
|
29308
|
-
sqrt_ratio_limit: uint25612.bnToUint256(route.sqrt_ratio_limit.toWei()),
|
|
29309
|
-
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
29310
|
-
})),
|
|
29311
|
-
token_amount: {
|
|
29312
|
-
token: swap.token_amount.token.toBigInt(),
|
|
29313
|
-
amount: swap.token_amount.amount.toI129()
|
|
29314
|
-
}
|
|
29315
|
-
})),
|
|
29316
|
-
lever_swap_limit_amount: BigInt(_params.lever_swap_limit_amount.toWei()),
|
|
29317
|
-
lever_swap_weights: _params.lever_swap_weights.map((weight) => BigInt(weight.toWei())),
|
|
29318
|
-
withdraw_swap: _params.withdraw_swap.map((swap) => ({
|
|
29319
|
-
route: swap.route.map((route) => ({
|
|
29320
|
-
pool_key: {
|
|
29321
|
-
token0: route.pool_key.token0.toBigInt(),
|
|
29322
|
-
token1: route.pool_key.token1.toBigInt(),
|
|
29323
|
-
fee: route.pool_key.fee,
|
|
29324
|
-
tick_spacing: route.pool_key.tick_spacing,
|
|
29325
|
-
extension: ContractAddr.from(route.pool_key.extension).toBigInt()
|
|
29326
|
-
},
|
|
29327
|
-
sqrt_ratio_limit: uint25612.bnToUint256(route.sqrt_ratio_limit.toWei()),
|
|
29328
|
-
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
29329
|
-
})),
|
|
29330
|
-
token_amount: {
|
|
29331
|
-
token: swap.token_amount.token.toBigInt(),
|
|
29332
|
-
amount: swap.token_amount.amount.toI129()
|
|
29333
|
-
}
|
|
29334
|
-
})),
|
|
29335
|
-
withdraw_swap_limit_amount: BigInt(_params.withdraw_swap_limit_amount.toWei()),
|
|
29336
|
-
withdraw_swap_weights: _params.withdraw_swap_weights.map((weight) => BigInt(weight.toWei())),
|
|
29337
|
-
close_position: _params.close_position
|
|
29338
|
-
} })
|
|
29561
|
+
withdraw_swap_limit_amount: BigInt(
|
|
29562
|
+
_params.withdraw_swap_limit_amount.toWei()
|
|
29563
|
+
),
|
|
29564
|
+
withdraw_swap_weights: _params.withdraw_swap_weights.map(
|
|
29565
|
+
(weight) => BigInt(weight.toWei())
|
|
29566
|
+
),
|
|
29567
|
+
close_position: _params.close_position
|
|
29568
|
+
}
|
|
29569
|
+
})
|
|
29339
29570
|
};
|
|
29340
29571
|
}
|
|
29341
29572
|
async getHealthFactor() {
|
|
@@ -29344,11 +29575,15 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29344
29575
|
}
|
|
29345
29576
|
async getNetAPY() {
|
|
29346
29577
|
const positions = await this.getPositions();
|
|
29347
|
-
logger.verbose(
|
|
29578
|
+
logger.verbose(
|
|
29579
|
+
`${this.name}::getNetAPY: positions: ${JSON.stringify(positions)}`
|
|
29580
|
+
);
|
|
29348
29581
|
const allZero = positions.every((p) => p.usdValue === 0);
|
|
29349
29582
|
if (allZero) {
|
|
29350
29583
|
const collateralUSD = 1e3;
|
|
29351
|
-
const maxLTV = await this.vesuAdapter.getLTVConfig(
|
|
29584
|
+
const maxLTV = await this.vesuAdapter.getLTVConfig(
|
|
29585
|
+
this.config.networkConfig
|
|
29586
|
+
);
|
|
29352
29587
|
const targetHF = this.config.targetHealthFactor;
|
|
29353
29588
|
const maxDebt = HealthFactorMath.getMaxDebtAmountOnLooping(
|
|
29354
29589
|
new Web3Number(collateralUSD, this.config.collateral.decimals),
|
|
@@ -29738,6 +29973,7 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29738
29973
|
logger.error("error initializing client");
|
|
29739
29974
|
return null;
|
|
29740
29975
|
}
|
|
29976
|
+
await new Promise((resolve) => setTimeout(resolve, 5e3));
|
|
29741
29977
|
const orderhistory = await this.getOrderHistory(marketName);
|
|
29742
29978
|
if (!orderhistory || orderhistory.length === 0) {
|
|
29743
29979
|
logger.error(`error getting order: ${orderId}`);
|
|
@@ -34118,7 +34354,7 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34118
34354
|
const withdrawalFromExtended = await extendedAdapter.withdrawFromExtended(params.amount);
|
|
34119
34355
|
if (withdrawalFromExtended) {
|
|
34120
34356
|
const extendedHoldings2 = await extendedAdapter.getExtendedDepositAmount();
|
|
34121
|
-
logger.info(`extendedHoldings after withdrawal ${extendedHoldings2}`);
|
|
34357
|
+
logger.info(`extendedHoldings after withdrawal ${extendedHoldings2?.availableForWithdrawal}`);
|
|
34122
34358
|
await new Promise((resolve) => setTimeout(resolve, 1e4));
|
|
34123
34359
|
const calls = await this.moveAssetsToVaultAllocator(params.amount, extendedAdapter);
|
|
34124
34360
|
if (calls.length > 0) {
|