@strkfarm/sdk 2.0.0-dev.1 → 2.0.0-dev.11
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 +1338 -391
- package/dist/index.browser.mjs +1338 -391
- package/dist/index.d.ts +53 -12
- package/dist/index.js +1339 -391
- package/dist/index.mjs +1338 -391
- package/package.json +1 -1
- package/src/dataTypes/address.ts +1 -1
- package/src/modules/ExtendedWrapperSDk/types.ts +1 -1
- package/src/modules/ExtendedWrapperSDk/wrapper.ts +32 -5
- package/src/modules/ekubo-quoter.ts +1 -12
- package/src/strategies/universal-adapters/avnu-adapter.ts +11 -14
- package/src/strategies/universal-adapters/extended-adapter.ts +514 -86
- package/src/strategies/universal-adapters/vesu-multiply-adapter.ts +790 -408
- package/src/strategies/universal-lst-muliplier-strategy.tsx +2 -1
- package/src/strategies/universal-strategy.tsx +5 -0
- package/src/strategies/vesu-extended-strategy/services/operationService.ts +8 -2
- package/src/strategies/vesu-extended-strategy/utils/constants.ts +3 -1
- package/src/strategies/vesu-extended-strategy/utils/helper.ts +21 -25
- package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +539 -122
package/dist/index.browser.mjs
CHANGED
|
@@ -4269,20 +4269,13 @@ var EkuboQuoter = class _EkuboQuoter {
|
|
|
4269
4269
|
async getDexPrice(baseToken, quoteToken, amount) {
|
|
4270
4270
|
const lstTokenInfo = baseToken;
|
|
4271
4271
|
const lstUnderlyingTokenInfo = quoteToken;
|
|
4272
|
-
console.log("lstTokenInfo", lstTokenInfo);
|
|
4273
|
-
console.log("lstUnderlyingTokenInfo", lstUnderlyingTokenInfo);
|
|
4274
|
-
console.log("amount", amount);
|
|
4275
4272
|
const quote = await this.getQuote(
|
|
4276
4273
|
lstTokenInfo.address.address,
|
|
4277
4274
|
lstUnderlyingTokenInfo.address.address,
|
|
4278
4275
|
amount
|
|
4279
4276
|
);
|
|
4280
|
-
console.log("quote", quote);
|
|
4281
4277
|
const outputAmount = Web3Number.fromWei(quote.total_calculated, lstUnderlyingTokenInfo.decimals);
|
|
4282
|
-
console.log("outputAmount", outputAmount);
|
|
4283
|
-
console.log("amount", amount);
|
|
4284
4278
|
const price = outputAmount.toNumber() / amount.toNumber();
|
|
4285
|
-
console.log("price", price);
|
|
4286
4279
|
logger.verbose(`${_EkuboQuoter.name}:: LST Dex Price: ${price}`);
|
|
4287
4280
|
return price;
|
|
4288
4281
|
}
|
|
@@ -4301,16 +4294,12 @@ var EkuboQuoter = class _EkuboQuoter {
|
|
|
4301
4294
|
// debt collateral
|
|
4302
4295
|
async getSwapLimitAmount(fromToken, toToken, amount, max_slippage = 2e-3) {
|
|
4303
4296
|
const isExactAmountIn = amount.greaterThanOrEqualTo(0);
|
|
4304
|
-
console.log("isExactAmountIn", isExactAmountIn);
|
|
4305
4297
|
logger.verbose(`${_EkuboQuoter.name}::getSwapLimitAmount isExactAmountIn: ${isExactAmountIn}, fromToken: ${fromToken.symbol}, toToken: ${toToken.symbol}, amount: ${amount}`);
|
|
4306
4298
|
const isYieldToken = this.tokenMarketData.isAPYSupported(toToken);
|
|
4307
4299
|
console.log("isYieldToken", isYieldToken);
|
|
4308
4300
|
const baseToken = isExactAmountIn ? toToken : fromToken;
|
|
4309
4301
|
const quoteToken = isExactAmountIn ? fromToken : toToken;
|
|
4310
|
-
console.log("baseToken", baseToken);
|
|
4311
|
-
console.log("quoteToken", quoteToken);
|
|
4312
4302
|
const dexPrice = await this.getDexPrice(baseToken, quoteToken, amount);
|
|
4313
|
-
console.log("dexPrice", dexPrice);
|
|
4314
4303
|
const trueExchangeRate = isYieldToken ? await this.tokenMarketData.getTruePrice(baseToken) : dexPrice;
|
|
4315
4304
|
console.log("trueExchangeRate", trueExchangeRate);
|
|
4316
4305
|
if (isExactAmountIn) {
|
|
@@ -4531,7 +4520,22 @@ var ExtendedWrapper = class {
|
|
|
4531
4520
|
`HTTP ${response.status}: ${errorData.detail || response.statusText}`
|
|
4532
4521
|
);
|
|
4533
4522
|
}
|
|
4534
|
-
const
|
|
4523
|
+
const text = await response.text();
|
|
4524
|
+
const MAX_SAFE_INTEGER_STR = "9007199254740991";
|
|
4525
|
+
const largeIntegerRegex = /"data"\s*:\s*(\d{16,})/g;
|
|
4526
|
+
const modifiedText = text.replace(largeIntegerRegex, (match, largeInt) => {
|
|
4527
|
+
if (largeInt.length > MAX_SAFE_INTEGER_STR.length || largeInt.length === MAX_SAFE_INTEGER_STR.length && largeInt > MAX_SAFE_INTEGER_STR) {
|
|
4528
|
+
return `"data":"${largeInt}"`;
|
|
4529
|
+
}
|
|
4530
|
+
return match;
|
|
4531
|
+
});
|
|
4532
|
+
const data = JSON.parse(modifiedText);
|
|
4533
|
+
if (data && typeof data.data === "string" && /^\d+$/.test(data.data)) {
|
|
4534
|
+
const numValue = Number(data.data);
|
|
4535
|
+
if (Number.isSafeInteger(numValue)) {
|
|
4536
|
+
data.data = numValue;
|
|
4537
|
+
}
|
|
4538
|
+
}
|
|
4535
4539
|
return data;
|
|
4536
4540
|
} catch (error) {
|
|
4537
4541
|
lastError = error;
|
|
@@ -4591,6 +4595,7 @@ var ExtendedWrapper = class {
|
|
|
4591
4595
|
}
|
|
4592
4596
|
/**
|
|
4593
4597
|
* Initiate a withdrawal from Extended Exchange
|
|
4598
|
+
* Returns data as number | string to preserve precision for large integers
|
|
4594
4599
|
*/
|
|
4595
4600
|
async withdraw(request) {
|
|
4596
4601
|
return this.makeRequest("/api/v1/withdraw", {
|
|
@@ -4729,6 +4734,7 @@ var ExtendedWrapper = class {
|
|
|
4729
4734
|
}
|
|
4730
4735
|
/**
|
|
4731
4736
|
* Withdraw USDC (convenience method)
|
|
4737
|
+
* Returns data as number | string to preserve precision for large integers
|
|
4732
4738
|
*/
|
|
4733
4739
|
async withdrawUSDC(amount) {
|
|
4734
4740
|
return this.withdraw({ amount, asset: "USDC" });
|
|
@@ -28346,6 +28352,7 @@ var vesu_multiple_abi_default = [
|
|
|
28346
28352
|
var AVNU_API = "https://starknet.api.avnu.fi/swap/v2/quotes";
|
|
28347
28353
|
var USDC_TOKEN_DECIMALS = 6;
|
|
28348
28354
|
var USDC_TOKEN_ADDRESS = "0x053C91253BC9682c04929cA02ED00b3E423f6710D2ee7e0D5EBB06F3eCF368A8";
|
|
28355
|
+
var BUFFER_USDC_IN_WITHDRAWAL = 5;
|
|
28349
28356
|
var WBTC_TOKEN_ADDRESS = "0x3fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac";
|
|
28350
28357
|
var WBTC_TOKEN_DECIMALS = 8;
|
|
28351
28358
|
var MAINTENANCE_MARGIN = 0.01;
|
|
@@ -28361,7 +28368,8 @@ var STRK_API_RPC = process.env.STRK_API_RPC ?? "https://mainnet.starknet.a5a.ch"
|
|
|
28361
28368
|
var MAX_RETRIES = Number(process.env.MAX_RETRIES ?? 3);
|
|
28362
28369
|
var MAX_DELAY = Number(process.env.MAX_DELAY ?? 100);
|
|
28363
28370
|
var EXTEND_MARKET_NAME = "BTC-USD";
|
|
28364
|
-
var LIMIT_BALANCE = Number(process.env.LIMIT_BALANCE ??
|
|
28371
|
+
var LIMIT_BALANCE = Number(process.env.LIMIT_BALANCE ?? 0.05);
|
|
28372
|
+
var LIMIT_BALANCE_VALUE = 10;
|
|
28365
28373
|
var REBALANCER_INTERVAL = Number(process.env.REBALANCER_INTERVAL ?? 18e4);
|
|
28366
28374
|
var WITHDRAWAL_INTERVAL = Number(process.env.WITHDRAWAL_INTERVAL ?? 18e6);
|
|
28367
28375
|
var INVESTING_INTERVAL = Number(process.env.INVESTING_INTERVAL ?? 18e4);
|
|
@@ -28379,8 +28387,6 @@ var PRICE_MAX_SLIPPAGE_EKUBO = Number(process.env.PRICE_MAX_SLIPPAGE_EKUBO ?? 5e
|
|
|
28379
28387
|
var MINIMUM_DEBT_AMOUNT_VESU_FOR_REBALANCING = Number(process.env.MINIMUM_DEBT_AMOUNT_VESU_FOR_REBALANCING ?? 1);
|
|
28380
28388
|
var MINIMUM_EXTENDED_POSITION_SIZE = 1e-4;
|
|
28381
28389
|
var MINIMUM_WBTC_DIFFERENCE_FOR_AVNU_SWAP = 1e-5;
|
|
28382
|
-
var MAX_PRICE_DIFFERENCE_BETWEEN_AVNU_AND_EXTENDED = 700;
|
|
28383
|
-
var MIN_PRICE_DIFFERENCE_BETWEEN_AVNU_AND_EXTENDED = -100;
|
|
28384
28390
|
|
|
28385
28391
|
// src/strategies/vesu-extended-strategy/utils/helper.ts
|
|
28386
28392
|
var returnFormattedAmount = (amount, toTokenDecimals) => {
|
|
@@ -28400,8 +28406,7 @@ var calculateAmountDistribution = async (amount, client, marketName, collateralP
|
|
|
28400
28406
|
vesu_leverage: 0
|
|
28401
28407
|
};
|
|
28402
28408
|
}
|
|
28403
|
-
const
|
|
28404
|
-
const extendedExposureUSD = extendedBTCExposure.multipliedBy(collateralPrice);
|
|
28409
|
+
const extendedExposureUSD = extendedPosition.length > 0 ? new Web3Number(extendedPosition[0].value, WBTC_TOKEN_DECIMALS) : new Web3Number(0, WBTC_TOKEN_DECIMALS);
|
|
28405
28410
|
const vesuBTCExposureUSD = collateralUnits.multipliedBy(collateralPrice);
|
|
28406
28411
|
const numerator1 = vesu_leverage * amount + vesuBTCExposureUSD.toNumber();
|
|
28407
28412
|
const numerator2 = extendedExposureUSD.toNumber();
|
|
@@ -28437,8 +28442,7 @@ var calculateAmountDistributionForWithdrawal = async (amountInUsdc, collateralPr
|
|
|
28437
28442
|
logger.error("error getting extended positions");
|
|
28438
28443
|
return null;
|
|
28439
28444
|
}
|
|
28440
|
-
const
|
|
28441
|
-
const extendedExposureUSD = extendedBTCExposure.multipliedBy(collateralPrice);
|
|
28445
|
+
const extendedExposureUSD = extendedPosition.length > 0 ? new Web3Number(extendedPosition[0].value, USDC_TOKEN_DECIMALS) : new Web3Number(0, USDC_TOKEN_DECIMALS);
|
|
28442
28446
|
const vesuExposureUSD = collateralUnits.multipliedBy(collateralPrice);
|
|
28443
28447
|
if (vesuExposureUSD.lessThan(0)) {
|
|
28444
28448
|
return {
|
|
@@ -28456,9 +28460,14 @@ var calculateAmountDistributionForWithdrawal = async (amountInUsdc, collateralPr
|
|
|
28456
28460
|
vesu_leverage
|
|
28457
28461
|
};
|
|
28458
28462
|
}
|
|
28463
|
+
console.log("the vesu exposure usd is", vesuExposureUSD.toNumber());
|
|
28464
|
+
console.log("the extended exposure usd is", extendedExposureUSD.toNumber());
|
|
28465
|
+
console.log("the amount in usdc is", amountInUsdc.toNumber());
|
|
28466
|
+
console.log("the extended leverage is", extended_leverage);
|
|
28467
|
+
console.log("the vesu leverage is", vesu_leverage);
|
|
28459
28468
|
const numerator1 = amountInUsdc.multipliedBy(extended_leverage);
|
|
28460
|
-
const numerator2 = vesuExposureUSD
|
|
28461
|
-
const numerator3 = extendedExposureUSD.multipliedBy(
|
|
28469
|
+
const numerator2 = vesuExposureUSD;
|
|
28470
|
+
const numerator3 = extendedExposureUSD.multipliedBy(-1);
|
|
28462
28471
|
const finalNumerator = numerator1.plus(numerator2).plus(numerator3);
|
|
28463
28472
|
const denominator = extended_leverage + vesu_leverage;
|
|
28464
28473
|
const vesuAmountInUSDC = finalNumerator.dividedBy(denominator);
|
|
@@ -28468,6 +28477,7 @@ var calculateAmountDistributionForWithdrawal = async (amountInUsdc, collateralPr
|
|
|
28468
28477
|
"the extended amount in usdc is",
|
|
28469
28478
|
extendedAmountInUSDC.toNumber()
|
|
28470
28479
|
);
|
|
28480
|
+
await new Promise((resolve) => setTimeout(resolve, 1e4));
|
|
28471
28481
|
return {
|
|
28472
28482
|
vesu_amount: vesuAmountInUSDC,
|
|
28473
28483
|
extended_amount: extendedAmountInUSDC,
|
|
@@ -28489,10 +28499,10 @@ var calculateExtendedLevergae = () => {
|
|
|
28489
28499
|
const extended_leverage_max = 1 / (MAINTENANCE_MARGIN + MAX_PRICE_DROP_PERCENTAGE);
|
|
28490
28500
|
return Math.floor(extended_leverage_max);
|
|
28491
28501
|
};
|
|
28492
|
-
var calculateDebtAmount = (collateralAmount, debtAmount, debtPrice, maxLtv =
|
|
28502
|
+
var calculateDebtAmount = (collateralAmount, debtAmount, debtPrice, maxLtv = MAX_LIQUIDATION_RATIO, addedAmount, collateralPrice, isDeposit) => {
|
|
28493
28503
|
try {
|
|
28494
|
-
const
|
|
28495
|
-
const numerator1 = collateralAmount.plus(
|
|
28504
|
+
const addedCollateral = addedAmount.multipliedBy(isDeposit ? 1 : -1);
|
|
28505
|
+
const numerator1 = collateralAmount.plus(addedCollateral).multipliedBy(collateralPrice).multipliedBy(maxLtv);
|
|
28496
28506
|
const numerator2 = debtAmount.multipliedBy(debtPrice).multipliedBy(TARGET_HF);
|
|
28497
28507
|
const denominator = TARGET_HF - maxLtv;
|
|
28498
28508
|
const x_debt_usd = numerator1.minus(numerator2).dividedBy(denominator);
|
|
@@ -28527,16 +28537,16 @@ var calculateAmountDepositOnExtendedWhenIncurringLosses = async (client) => {
|
|
|
28527
28537
|
const extendedHoldings = await client.getHoldings();
|
|
28528
28538
|
const extended_leverage = calculateExtendedLevergae();
|
|
28529
28539
|
const latestPosition = (await client.getPositions()).data.pop();
|
|
28530
|
-
console.log("the latest position is", latestPosition, extendedHoldings);
|
|
28531
28540
|
if (!extendedHoldings || !latestPosition) {
|
|
28532
28541
|
logger.error(`error getting extended position: extendedHoldings=${extendedHoldings}, latestPosition=${latestPosition}`);
|
|
28533
28542
|
return null;
|
|
28534
28543
|
}
|
|
28535
|
-
const positionValueInUSD = latestPosition.value;
|
|
28544
|
+
const positionValueInUSD = new Web3Number(latestPosition.value, USDC_TOKEN_DECIMALS);
|
|
28536
28545
|
const equity = extendedHoldings.data.equity;
|
|
28537
|
-
const deposit =
|
|
28538
|
-
return new Web3Number(
|
|
28546
|
+
const deposit = positionValueInUSD.dividedBy(extended_leverage).minus(equity).toFixed(2);
|
|
28547
|
+
return new Web3Number(deposit, USDC_TOKEN_DECIMALS);
|
|
28539
28548
|
} catch (err) {
|
|
28549
|
+
logger.error(`error calculating amount deposit on extended when incurring losses: ${err}`);
|
|
28540
28550
|
return null;
|
|
28541
28551
|
}
|
|
28542
28552
|
};
|
|
@@ -28614,21 +28624,36 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28614
28624
|
vaultAllocator: config.vaultAllocator,
|
|
28615
28625
|
id: ""
|
|
28616
28626
|
});
|
|
28617
|
-
this.
|
|
28627
|
+
this.minimumVesuMovementAmount = config.minimumVesuMovementAmount ?? 5;
|
|
28628
|
+
this.tokenMarketData = new TokenMarketData(
|
|
28629
|
+
this.config.pricer,
|
|
28630
|
+
this.config.networkConfig
|
|
28631
|
+
);
|
|
28618
28632
|
}
|
|
28619
28633
|
async getAPY(supportedPosition) {
|
|
28620
28634
|
const CACHE_KEY = `apy_${this.config.poolId.address}_${supportedPosition.asset.symbol}`;
|
|
28621
28635
|
const cacheData = this.getCache(CACHE_KEY);
|
|
28622
|
-
console.log(
|
|
28636
|
+
console.log(
|
|
28637
|
+
`${_VesuMultiplyAdapter.name}::getAPY cacheData: ${JSON.stringify(
|
|
28638
|
+
cacheData
|
|
28639
|
+
)}`,
|
|
28640
|
+
this.vesuAdapter.config.poolId.shortString(),
|
|
28641
|
+
this.vesuAdapter.config.collateral.symbol,
|
|
28642
|
+
this.vesuAdapter.config.debt.symbol
|
|
28643
|
+
);
|
|
28623
28644
|
if (cacheData) {
|
|
28624
28645
|
return cacheData;
|
|
28625
28646
|
}
|
|
28626
28647
|
try {
|
|
28627
28648
|
const allVesuPools = await VesuAdapter.getVesuPools();
|
|
28628
28649
|
const asset = supportedPosition.asset;
|
|
28629
|
-
const pool = allVesuPools.pools.find(
|
|
28650
|
+
const pool = allVesuPools.pools.find(
|
|
28651
|
+
(p) => this.vesuAdapter.config.poolId.eqString(num9.getHexString(p.id))
|
|
28652
|
+
);
|
|
28630
28653
|
if (!pool) {
|
|
28631
|
-
logger.warn(
|
|
28654
|
+
logger.warn(
|
|
28655
|
+
`VesuMultiplyAdapter: Pool not found for token ${asset.symbol}`
|
|
28656
|
+
);
|
|
28632
28657
|
return {
|
|
28633
28658
|
apy: 0,
|
|
28634
28659
|
type: "base" /* BASE */
|
|
@@ -28638,7 +28663,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28638
28663
|
(a) => a.symbol.toLowerCase() === asset.symbol.toLowerCase()
|
|
28639
28664
|
)?.stats;
|
|
28640
28665
|
if (!assetStats) {
|
|
28641
|
-
logger.warn(
|
|
28666
|
+
logger.warn(
|
|
28667
|
+
`VesuMultiplyAdapter: Asset stats not found for token ${asset.symbol}`
|
|
28668
|
+
);
|
|
28642
28669
|
return {
|
|
28643
28670
|
apy: 0,
|
|
28644
28671
|
type: "base" /* BASE */
|
|
@@ -28649,7 +28676,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28649
28676
|
apy = Number(assetStats.borrowApr?.value || 0) / 1e18;
|
|
28650
28677
|
} else {
|
|
28651
28678
|
const isAssetBTC = asset.symbol.toLowerCase().includes("btc");
|
|
28652
|
-
const baseAPY = Number(
|
|
28679
|
+
const baseAPY = Number(
|
|
28680
|
+
isAssetBTC ? assetStats.btcFiSupplyApr?.value + assetStats.supplyApy?.value : assetStats.supplyApy?.value || 0
|
|
28681
|
+
) / 1e18;
|
|
28653
28682
|
const rewardAPY = Number(assetStats.defiSpringSupplyApr?.value || "0") / 1e18;
|
|
28654
28683
|
const isSupported = this.tokenMarketData.isAPYSupported(asset);
|
|
28655
28684
|
apy = baseAPY + rewardAPY;
|
|
@@ -28665,7 +28694,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28665
28694
|
this.setCache(CACHE_KEY, result, 3e5);
|
|
28666
28695
|
return result;
|
|
28667
28696
|
} catch (error) {
|
|
28668
|
-
logger.error(
|
|
28697
|
+
logger.error(
|
|
28698
|
+
`VesuMultiplyAdapter: Error getting APY for ${supportedPosition.asset.symbol}:`,
|
|
28699
|
+
error
|
|
28700
|
+
);
|
|
28669
28701
|
throw error;
|
|
28670
28702
|
}
|
|
28671
28703
|
}
|
|
@@ -28678,12 +28710,16 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28678
28710
|
try {
|
|
28679
28711
|
this.vesuAdapter.networkConfig = this.config.networkConfig;
|
|
28680
28712
|
this.vesuAdapter.pricer = this.config.pricer;
|
|
28681
|
-
const positions = await this.vesuAdapter.getPositions(
|
|
28713
|
+
const positions = await this.vesuAdapter.getPositions(
|
|
28714
|
+
this.config.networkConfig
|
|
28715
|
+
);
|
|
28682
28716
|
let position = positions.find(
|
|
28683
28717
|
(p) => p.token.address.eq(supportedPosition.asset.address)
|
|
28684
28718
|
);
|
|
28685
28719
|
if (!position) {
|
|
28686
|
-
logger.warn(
|
|
28720
|
+
logger.warn(
|
|
28721
|
+
`VesuMultiplyAdapter: Position not found for token ${supportedPosition.asset.symbol}`
|
|
28722
|
+
);
|
|
28687
28723
|
return {
|
|
28688
28724
|
amount: new Web3Number("0", supportedPosition.asset.decimals),
|
|
28689
28725
|
remarks: "Position not found"
|
|
@@ -28696,12 +28732,18 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28696
28732
|
this.setCache(CACHE_KEY, position, 6e4);
|
|
28697
28733
|
return position;
|
|
28698
28734
|
} catch (error) {
|
|
28699
|
-
logger.error(
|
|
28735
|
+
logger.error(
|
|
28736
|
+
`VesuMultiplyAdapter: Error getting position for ${supportedPosition.asset.symbol}:`,
|
|
28737
|
+
error
|
|
28738
|
+
);
|
|
28700
28739
|
throw error;
|
|
28701
28740
|
}
|
|
28702
28741
|
}
|
|
28703
28742
|
async maxBorrowableAPY() {
|
|
28704
|
-
const collateralAPY = await this.getAPY({
|
|
28743
|
+
const collateralAPY = await this.getAPY({
|
|
28744
|
+
asset: this.config.collateral,
|
|
28745
|
+
isDebt: false
|
|
28746
|
+
});
|
|
28705
28747
|
const apy = collateralAPY.apy * 0.8;
|
|
28706
28748
|
return apy;
|
|
28707
28749
|
}
|
|
@@ -28711,9 +28753,15 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28711
28753
|
try {
|
|
28712
28754
|
this.vesuAdapter.networkConfig = this.config.networkConfig;
|
|
28713
28755
|
this.vesuAdapter.pricer = this.config.pricer;
|
|
28714
|
-
const positions = await this.vesuAdapter.getPositions(
|
|
28715
|
-
|
|
28716
|
-
|
|
28756
|
+
const positions = await this.vesuAdapter.getPositions(
|
|
28757
|
+
this.config.networkConfig
|
|
28758
|
+
);
|
|
28759
|
+
const collateralPosition = positions.find(
|
|
28760
|
+
(p) => p.token.address.eq(collateral.address)
|
|
28761
|
+
);
|
|
28762
|
+
const debtPosition = positions.find(
|
|
28763
|
+
(p) => p.token.address.eq(debt.address)
|
|
28764
|
+
);
|
|
28717
28765
|
if (!collateralPosition || !debtPosition) {
|
|
28718
28766
|
throw new Error("Could not find current positions");
|
|
28719
28767
|
}
|
|
@@ -28723,13 +28771,23 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28723
28771
|
debt,
|
|
28724
28772
|
maxBorrowableAPY
|
|
28725
28773
|
);
|
|
28726
|
-
logger.verbose(
|
|
28727
|
-
|
|
28774
|
+
logger.verbose(
|
|
28775
|
+
`VesuMultiplyAdapter: Max borrowable: ${maxBorrowable.toNumber()}`
|
|
28776
|
+
);
|
|
28777
|
+
const debtCap = await this.vesuAdapter.getDebtCap(
|
|
28778
|
+
this.config.networkConfig
|
|
28779
|
+
);
|
|
28728
28780
|
logger.verbose(`VesuMultiplyAdapter: Debt cap: ${debtCap.toNumber()}`);
|
|
28729
28781
|
const actualMaxBorrowable = maxBorrowable.minimum(debtCap);
|
|
28730
|
-
logger.verbose(
|
|
28731
|
-
|
|
28732
|
-
|
|
28782
|
+
logger.verbose(
|
|
28783
|
+
`VesuMultiplyAdapter: Actual max borrowable: ${actualMaxBorrowable.toNumber()}`
|
|
28784
|
+
);
|
|
28785
|
+
const maxLTV = await this.vesuAdapter.getLTVConfig(
|
|
28786
|
+
this.config.networkConfig
|
|
28787
|
+
);
|
|
28788
|
+
const collateralPrice = await this.config.pricer.getPrice(
|
|
28789
|
+
collateral.symbol
|
|
28790
|
+
);
|
|
28733
28791
|
if (collateralPrice.price === 0) {
|
|
28734
28792
|
throw new Error("Collateral price is 0");
|
|
28735
28793
|
}
|
|
@@ -28747,14 +28805,25 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28747
28805
|
);
|
|
28748
28806
|
const maxDepositAmount = amount ? amount.minimum(maxCollateralFromDebt) : maxCollateralFromDebt;
|
|
28749
28807
|
const usdValue = await this.getUSDValue(collateral, maxDepositAmount);
|
|
28750
|
-
logger.verbose(
|
|
28751
|
-
|
|
28752
|
-
|
|
28808
|
+
logger.verbose(
|
|
28809
|
+
`VesuMultiplyAdapter: Max deposit::USD value: ${usdValue}, amount: ${maxDepositAmount.toNumber()}`
|
|
28810
|
+
);
|
|
28811
|
+
const apys = await Promise.all([
|
|
28812
|
+
this.getAPY({ asset: collateral, isDebt: false }),
|
|
28813
|
+
this.getAPY({ asset: debt, isDebt: true })
|
|
28814
|
+
]);
|
|
28815
|
+
logger.verbose(
|
|
28816
|
+
`VesuMultiplyAdapter: Apys: ${apys[0].apy}, ${apys[1].apy}`
|
|
28817
|
+
);
|
|
28753
28818
|
const borrowAmountUSD = actualMaxBorrowable.multipliedBy(debtPrice.price);
|
|
28754
|
-
logger.verbose(
|
|
28819
|
+
logger.verbose(
|
|
28820
|
+
`VesuMultiplyAdapter: Borrow amount: ${actualMaxBorrowable.toNumber()}, borrow amount USD: ${borrowAmountUSD.toNumber()}`
|
|
28821
|
+
);
|
|
28755
28822
|
const netCollateralUSD = usdValue + borrowAmountUSD.toNumber();
|
|
28756
28823
|
const netAPY = (apys[0].apy * netCollateralUSD + apys[1].apy * borrowAmountUSD.toNumber()) / usdValue;
|
|
28757
|
-
logger.verbose(
|
|
28824
|
+
logger.verbose(
|
|
28825
|
+
`VesuMultiplyAdapter: Max deposit amount: ${maxDepositAmount.toNumber()}, netAPY: ${netAPY}`
|
|
28826
|
+
);
|
|
28758
28827
|
return {
|
|
28759
28828
|
tokenInfo: collateral,
|
|
28760
28829
|
amount: maxDepositAmount,
|
|
@@ -28767,7 +28836,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28767
28836
|
protocol: this.protocol
|
|
28768
28837
|
};
|
|
28769
28838
|
} catch (error) {
|
|
28770
|
-
logger.error(
|
|
28839
|
+
logger.error(
|
|
28840
|
+
`VesuMultiplyAdapter: Error calculating max deposit:`,
|
|
28841
|
+
error
|
|
28842
|
+
);
|
|
28771
28843
|
throw error;
|
|
28772
28844
|
}
|
|
28773
28845
|
}
|
|
@@ -28777,9 +28849,15 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28777
28849
|
try {
|
|
28778
28850
|
this.vesuAdapter.networkConfig = this.config.networkConfig;
|
|
28779
28851
|
this.vesuAdapter.pricer = this.config.pricer;
|
|
28780
|
-
const positions = await this.vesuAdapter.getPositions(
|
|
28781
|
-
|
|
28782
|
-
|
|
28852
|
+
const positions = await this.vesuAdapter.getPositions(
|
|
28853
|
+
this.config.networkConfig
|
|
28854
|
+
);
|
|
28855
|
+
const collateralPosition = positions.find(
|
|
28856
|
+
(p) => p.token.address.eq(collateral.address)
|
|
28857
|
+
);
|
|
28858
|
+
const debtPosition = positions.find(
|
|
28859
|
+
(p) => p.token.address.eq(this.config.debt.address)
|
|
28860
|
+
);
|
|
28783
28861
|
if (!collateralPosition || !debtPosition) {
|
|
28784
28862
|
throw new Error("Could not find current positions");
|
|
28785
28863
|
}
|
|
@@ -28789,11 +28867,20 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28789
28867
|
const result = maxWithdrawable.greaterThan(0) ? maxWithdrawable : new Web3Number("0", collateral.decimals);
|
|
28790
28868
|
const usdValue = await this.getUSDValue(collateral, result);
|
|
28791
28869
|
const debtUSD = debtPosition.usdValue;
|
|
28792
|
-
logger.verbose(
|
|
28793
|
-
|
|
28794
|
-
|
|
28870
|
+
logger.verbose(
|
|
28871
|
+
`VesuMultiplyAdapter: Debt USD: ${debtUSD}, collateral USD: ${usdValue}`
|
|
28872
|
+
);
|
|
28873
|
+
const apys = await Promise.all([
|
|
28874
|
+
this.getAPY({ asset: collateral, isDebt: false }),
|
|
28875
|
+
this.getAPY({ asset: debt, isDebt: true })
|
|
28876
|
+
]);
|
|
28877
|
+
logger.verbose(
|
|
28878
|
+
`VesuMultiplyAdapter: Apys: ${apys[0].apy}, ${apys[1].apy}`
|
|
28879
|
+
);
|
|
28795
28880
|
const netAPY = usdValue - debtUSD > 0 ? (apys[0].apy * usdValue + apys[1].apy * debtUSD) / (usdValue - debtUSD) : 0;
|
|
28796
|
-
logger.verbose(
|
|
28881
|
+
logger.verbose(
|
|
28882
|
+
`VesuMultiplyAdapter: Max withdraw amount: ${result.toNumber()}, netAPY: ${netAPY}`
|
|
28883
|
+
);
|
|
28797
28884
|
return {
|
|
28798
28885
|
tokenInfo: collateral,
|
|
28799
28886
|
amount: result,
|
|
@@ -28806,14 +28893,19 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28806
28893
|
protocol: this.protocol
|
|
28807
28894
|
};
|
|
28808
28895
|
} catch (error) {
|
|
28809
|
-
logger.error(
|
|
28896
|
+
logger.error(
|
|
28897
|
+
`VesuMultiplyAdapter: Error calculating max withdraw:`,
|
|
28898
|
+
error
|
|
28899
|
+
);
|
|
28810
28900
|
throw error;
|
|
28811
28901
|
}
|
|
28812
28902
|
}
|
|
28813
28903
|
_getDepositLeaf() {
|
|
28814
28904
|
const collateral = this.config.collateral;
|
|
28815
28905
|
const debt = this.config.debt;
|
|
28816
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28906
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28907
|
+
this.config.poolId
|
|
28908
|
+
);
|
|
28817
28909
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
28818
28910
|
return [
|
|
28819
28911
|
// Approval step for collateral
|
|
@@ -28877,7 +28969,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28877
28969
|
];
|
|
28878
28970
|
}
|
|
28879
28971
|
_getWithdrawLeaf() {
|
|
28880
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28972
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
28973
|
+
this.config.poolId
|
|
28974
|
+
);
|
|
28881
28975
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
28882
28976
|
const collateral = this.config.collateral;
|
|
28883
28977
|
const debt = this.config.debt;
|
|
@@ -28908,7 +29002,7 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28908
29002
|
this.config.debt.address.toBigInt(),
|
|
28909
29003
|
this.config.vaultAllocator.toBigInt()
|
|
28910
29004
|
],
|
|
28911
|
-
sanitizer: SIMPLE_SANITIZER_V2,
|
|
29005
|
+
sanitizer: isV2 ? SIMPLE_SANITIZER_V2 : SIMPLE_SANITIZER,
|
|
28912
29006
|
// vmw = vesu multiply withdraw
|
|
28913
29007
|
id: `vmw_${this.config.poolId.shortString()}_${collateral.symbol}_${debt.symbol}`
|
|
28914
29008
|
},
|
|
@@ -28934,33 +29028,51 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
28934
29028
|
const leafConfigs = this._getDepositLeaf();
|
|
28935
29029
|
const leaves = leafConfigs.map((config) => {
|
|
28936
29030
|
const { target, method, packedArguments, sanitizer, id } = config;
|
|
28937
|
-
const leaf = this.constructSimpleLeafData(
|
|
28938
|
-
|
|
28939
|
-
|
|
28940
|
-
|
|
28941
|
-
|
|
28942
|
-
|
|
29031
|
+
const leaf = this.constructSimpleLeafData(
|
|
29032
|
+
{
|
|
29033
|
+
id,
|
|
29034
|
+
target,
|
|
29035
|
+
method,
|
|
29036
|
+
packedArguments
|
|
29037
|
+
},
|
|
29038
|
+
sanitizer
|
|
29039
|
+
);
|
|
28943
29040
|
return leaf;
|
|
28944
29041
|
});
|
|
28945
|
-
return {
|
|
29042
|
+
return {
|
|
29043
|
+
leaves,
|
|
29044
|
+
callConstructor: this.getDepositCall.bind(
|
|
29045
|
+
this
|
|
29046
|
+
)
|
|
29047
|
+
};
|
|
28946
29048
|
}
|
|
28947
29049
|
getWithdrawAdapter() {
|
|
28948
29050
|
const leafConfigs = this._getWithdrawLeaf();
|
|
28949
29051
|
const leaves = leafConfigs.map((config) => {
|
|
28950
29052
|
const { target, method, packedArguments, sanitizer, id } = config;
|
|
28951
|
-
const leaf = this.constructSimpleLeafData(
|
|
28952
|
-
|
|
28953
|
-
|
|
28954
|
-
|
|
28955
|
-
|
|
28956
|
-
|
|
29053
|
+
const leaf = this.constructSimpleLeafData(
|
|
29054
|
+
{
|
|
29055
|
+
id,
|
|
29056
|
+
target,
|
|
29057
|
+
method,
|
|
29058
|
+
packedArguments
|
|
29059
|
+
},
|
|
29060
|
+
sanitizer
|
|
29061
|
+
);
|
|
28957
29062
|
return leaf;
|
|
28958
29063
|
});
|
|
28959
|
-
return {
|
|
29064
|
+
return {
|
|
29065
|
+
leaves,
|
|
29066
|
+
callConstructor: this.getWithdrawCall.bind(
|
|
29067
|
+
this
|
|
29068
|
+
)
|
|
29069
|
+
};
|
|
28960
29070
|
}
|
|
28961
29071
|
async getDepositCall(params) {
|
|
28962
29072
|
const collateral = this.config.collateral;
|
|
28963
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
29073
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
29074
|
+
this.config.poolId
|
|
29075
|
+
);
|
|
28964
29076
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
28965
29077
|
const uint256MarginAmount = uint25612.bnToUint256(params.amount.toWei());
|
|
28966
29078
|
return [
|
|
@@ -29032,7 +29144,9 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29032
29144
|
];
|
|
29033
29145
|
}
|
|
29034
29146
|
async getWithdrawCall(params) {
|
|
29035
|
-
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
29147
|
+
const { addr: vesuSingleton, isV2 } = getVesuSingletonAddress(
|
|
29148
|
+
this.config.poolId
|
|
29149
|
+
);
|
|
29036
29150
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
29037
29151
|
return [
|
|
29038
29152
|
// Switch delegation on
|
|
@@ -29057,7 +29171,7 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29057
29171
|
},
|
|
29058
29172
|
// Vesu multiply call
|
|
29059
29173
|
{
|
|
29060
|
-
sanitizer: SIMPLE_SANITIZER_V2,
|
|
29174
|
+
sanitizer: isV2 ? SIMPLE_SANITIZER_V2 : SIMPLE_SANITIZER,
|
|
29061
29175
|
call: {
|
|
29062
29176
|
contractAddress: vesuMultiply,
|
|
29063
29177
|
selector: hash5.getSelectorFromName("modify_lever"),
|
|
@@ -29087,7 +29201,11 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29087
29201
|
];
|
|
29088
29202
|
}
|
|
29089
29203
|
async getMultiplyCallCalldata(params, isDeposit) {
|
|
29090
|
-
logger.verbose(
|
|
29204
|
+
logger.verbose(
|
|
29205
|
+
`${_VesuMultiplyAdapter.name}::getMultiplyCallCalldata params: ${JSON.stringify(
|
|
29206
|
+
params
|
|
29207
|
+
)}, isDeposit: ${isDeposit}, collateral: ${this.config.collateral.symbol}, debt: ${this.config.debt.symbol}`
|
|
29208
|
+
);
|
|
29091
29209
|
const { isV2 } = getVesuSingletonAddress(this.config.poolId);
|
|
29092
29210
|
const vesuMultiply = isV2 ? this.vesuAdapter.VESU_MULTIPLY : this.vesuAdapter.VESU_MULTIPLY_V1;
|
|
29093
29211
|
const multiplyContract = new Contract12({
|
|
@@ -29097,42 +29215,83 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29097
29215
|
});
|
|
29098
29216
|
let leverSwap = [];
|
|
29099
29217
|
let leverSwapLimitAmount = Web3Number.fromWei(0, this.config.debt.decimals);
|
|
29100
|
-
const existingPositions = await this.vesuAdapter.getPositions(
|
|
29101
|
-
|
|
29218
|
+
const existingPositions = await this.vesuAdapter.getPositions(
|
|
29219
|
+
this.config.networkConfig
|
|
29220
|
+
);
|
|
29221
|
+
const collateralisation = await this.vesuAdapter.getCollateralization(
|
|
29222
|
+
this.config.networkConfig
|
|
29223
|
+
);
|
|
29102
29224
|
const existingCollateralInfo = existingPositions[0];
|
|
29103
29225
|
const existingDebtInfo = existingPositions[1];
|
|
29104
29226
|
const isDexPriceRequired = existingDebtInfo.token.symbol !== "USDC";
|
|
29105
|
-
logger.debug(`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall existingCollateralInfo: ${JSON.stringify(
|
|
29106
|
-
|
|
29227
|
+
logger.debug(`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall existingCollateralInfo: ${JSON.stringify(
|
|
29228
|
+
existingCollateralInfo
|
|
29229
|
+
)},
|
|
29230
|
+
existingDebtInfo: ${JSON.stringify(
|
|
29231
|
+
existingDebtInfo
|
|
29232
|
+
)}, collateralisation: ${JSON.stringify(collateralisation)}`);
|
|
29107
29233
|
const collateralPrice = collateralisation[0].usdValue > 0 ? collateralisation[0].usdValue / existingCollateralInfo.amount.toNumber() : (await this.config.pricer.getPrice(this.config.collateral.symbol)).price;
|
|
29108
29234
|
const debtPrice = collateralisation[1].usdValue > 0 ? collateralisation[1].usdValue / existingDebtInfo.amount.toNumber() : (await this.config.pricer.getPrice(this.config.debt.symbol)).price;
|
|
29109
|
-
logger.debug(
|
|
29110
|
-
|
|
29111
|
-
|
|
29112
|
-
const
|
|
29113
|
-
|
|
29235
|
+
logger.debug(
|
|
29236
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall collateralPrice: ${collateralPrice}, debtPrice: ${debtPrice}`
|
|
29237
|
+
);
|
|
29238
|
+
const legLTV = await this.vesuAdapter.getLTVConfig(
|
|
29239
|
+
this.config.networkConfig
|
|
29240
|
+
);
|
|
29241
|
+
const ekuboQuoter = new EkuboQuoter(
|
|
29242
|
+
this.config.networkConfig,
|
|
29243
|
+
this.config.pricer
|
|
29244
|
+
);
|
|
29245
|
+
const dexPrice = isDexPriceRequired ? await ekuboQuoter.getDexPrice(
|
|
29246
|
+
this.config.collateral,
|
|
29247
|
+
this.config.debt,
|
|
29248
|
+
this.config.quoteAmountToFetchPrice
|
|
29249
|
+
) : 1;
|
|
29250
|
+
logger.verbose(
|
|
29251
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall dexPrice: ${dexPrice}, ltv: ${legLTV}`
|
|
29252
|
+
);
|
|
29114
29253
|
const addedCollateral = params.amount.multipliedBy(isDeposit ? 1 : -1);
|
|
29115
|
-
logger.verbose(
|
|
29254
|
+
logger.verbose(
|
|
29255
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall addedCollateral: ${addedCollateral}`
|
|
29256
|
+
);
|
|
29116
29257
|
const numeratorPart1 = existingCollateralInfo.amount.plus(addedCollateral).multipliedBy(collateralPrice).multipliedBy(legLTV);
|
|
29117
|
-
logger.verbose(
|
|
29258
|
+
logger.verbose(
|
|
29259
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart1: ${numeratorPart1}`
|
|
29260
|
+
);
|
|
29118
29261
|
const numeratorPart2 = existingDebtInfo.amount.multipliedBy(debtPrice).multipliedBy(this.config.targetHealthFactor);
|
|
29119
|
-
logger.verbose(
|
|
29262
|
+
logger.verbose(
|
|
29263
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart2: ${numeratorPart2}`
|
|
29264
|
+
);
|
|
29120
29265
|
const denominatorPart = this.config.targetHealthFactor - legLTV / dexPrice;
|
|
29121
|
-
logger.verbose(
|
|
29266
|
+
logger.verbose(
|
|
29267
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall denominatorPart: ${denominatorPart}`
|
|
29268
|
+
);
|
|
29122
29269
|
const x_debt_usd = numeratorPart1.minus(numeratorPart2).dividedBy(denominatorPart);
|
|
29123
|
-
logger.verbose(
|
|
29124
|
-
|
|
29125
|
-
|
|
29270
|
+
logger.verbose(
|
|
29271
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall x_debt_usd: ${x_debt_usd}`
|
|
29272
|
+
);
|
|
29273
|
+
logger.debug(
|
|
29274
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall numeratorPart1: ${numeratorPart1}, numeratorPart2: ${numeratorPart2}, denominatorPart: ${denominatorPart}`
|
|
29275
|
+
);
|
|
29276
|
+
let debtAmount = new Web3Number(
|
|
29277
|
+
x_debt_usd.dividedBy(debtPrice).toFixed(this.config.debt.decimals),
|
|
29278
|
+
this.config.debt.decimals
|
|
29279
|
+
);
|
|
29126
29280
|
const marginAmount = addedCollateral;
|
|
29127
29281
|
const collateralToken = this.config.collateral;
|
|
29128
29282
|
const debtToken = this.config.debt;
|
|
29129
|
-
const debtAmountInCollateralUnits = new Web3Number(
|
|
29283
|
+
const debtAmountInCollateralUnits = new Web3Number(
|
|
29284
|
+
debtAmount.multipliedBy(debtPrice).dividedBy(collateralPrice).multipliedBy(10 ** collateralToken.decimals).toFixed(0),
|
|
29285
|
+
collateralToken.decimals
|
|
29286
|
+
);
|
|
29130
29287
|
const isIncrease = debtAmount.greaterThanOrEqualTo(0);
|
|
29131
29288
|
if (isIncrease && debtAmount.lessThan(0)) {
|
|
29132
29289
|
} else if (!isIncrease && debtAmount.greaterThan(0)) {
|
|
29133
29290
|
debtAmount = Web3Number.fromWei(0, this.config.debt.decimals);
|
|
29134
29291
|
}
|
|
29135
|
-
logger.verbose(
|
|
29292
|
+
logger.verbose(
|
|
29293
|
+
`${_VesuMultiplyAdapter.name}::getVesuMultiplyCall debtAmount: ${debtAmount}, marginAmount: ${marginAmount}`
|
|
29294
|
+
);
|
|
29136
29295
|
if (!debtAmount.isZero()) {
|
|
29137
29296
|
try {
|
|
29138
29297
|
const swapQuote = await ekuboQuoter.getQuote(
|
|
@@ -29142,32 +29301,49 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29142
29301
|
// negative for exact amount out
|
|
29143
29302
|
);
|
|
29144
29303
|
if (swapQuote.price_impact < 0.01) {
|
|
29145
|
-
leverSwap = ekuboQuoter.getVesuMultiplyQuote(
|
|
29304
|
+
leverSwap = debtAmount.isNegative() ? ekuboQuoter.getVesuMultiplyQuote(
|
|
29305
|
+
swapQuote,
|
|
29306
|
+
collateralToken,
|
|
29307
|
+
debtToken
|
|
29308
|
+
) : ekuboQuoter.getVesuMultiplyQuote(
|
|
29309
|
+
swapQuote,
|
|
29310
|
+
debtToken,
|
|
29311
|
+
collateralToken
|
|
29312
|
+
);
|
|
29146
29313
|
const MAX_SLIPPAGE = 2e-3;
|
|
29147
29314
|
if (debtAmount.greaterThan(0)) {
|
|
29148
|
-
|
|
29149
|
-
leverSwapLimitAmount = await ekuboQuoter.getSwapLimitAmount(debtToken, collateralToken, debtAmount, MAX_SLIPPAGE);
|
|
29150
|
-
const anotherleverSwapLimitAmount = debtAmount.multipliedBy(1 + MAX_SLIPPAGE);
|
|
29151
|
-
console.log("anotherleverSwapLimitAmount", anotherleverSwapLimitAmount, leverSwapLimitAmount);
|
|
29315
|
+
leverSwapLimitAmount = debtAmount.multipliedBy(1 + MAX_SLIPPAGE);
|
|
29152
29316
|
} else if (debtAmount.lessThan(0)) {
|
|
29153
|
-
leverSwapLimitAmount =
|
|
29154
|
-
const anotherleverSwapLimitAmount = debtAmount.abs().multipliedBy(1 - MAX_SLIPPAGE);
|
|
29155
|
-
console.log("anotherleverSwapLimitAmount", anotherleverSwapLimitAmount, leverSwapLimitAmount);
|
|
29317
|
+
leverSwapLimitAmount = debtAmount.abs().multipliedBy(1 - MAX_SLIPPAGE);
|
|
29156
29318
|
} else {
|
|
29157
|
-
leverSwapLimitAmount = Web3Number.fromWei(
|
|
29319
|
+
leverSwapLimitAmount = Web3Number.fromWei(
|
|
29320
|
+
0,
|
|
29321
|
+
this.config.debt.decimals
|
|
29322
|
+
);
|
|
29158
29323
|
}
|
|
29159
29324
|
await new Promise((resolve) => setTimeout(resolve, 1e4));
|
|
29160
|
-
console.log("leverSwapLimitAmount", leverSwapLimitAmount);
|
|
29161
29325
|
} else {
|
|
29162
|
-
throw new Error(
|
|
29326
|
+
throw new Error(
|
|
29327
|
+
`VesuMultiplyAdapter: Price impact too high (${swapQuote.price_impact}), skipping swap`
|
|
29328
|
+
);
|
|
29163
29329
|
}
|
|
29164
29330
|
} catch (error) {
|
|
29165
|
-
throw new Error(
|
|
29331
|
+
throw new Error(
|
|
29332
|
+
`VesuMultiplyAdapter: Failed to get swap quote: ${error}`
|
|
29333
|
+
);
|
|
29166
29334
|
}
|
|
29167
29335
|
}
|
|
29168
|
-
const multiplyParams = await this.getLeverParams(
|
|
29336
|
+
const multiplyParams = await this.getLeverParams(
|
|
29337
|
+
isIncrease,
|
|
29338
|
+
params,
|
|
29339
|
+
leverSwap,
|
|
29340
|
+
leverSwapLimitAmount
|
|
29341
|
+
);
|
|
29169
29342
|
const call = multiplyContract.populate("modify_lever", {
|
|
29170
|
-
modify_lever_params: this.formatMultiplyParams(
|
|
29343
|
+
modify_lever_params: this.formatMultiplyParams(
|
|
29344
|
+
isIncrease,
|
|
29345
|
+
multiplyParams
|
|
29346
|
+
)
|
|
29171
29347
|
});
|
|
29172
29348
|
return call.calldata;
|
|
29173
29349
|
}
|
|
@@ -29181,7 +29357,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29181
29357
|
add_margin: params.amount,
|
|
29182
29358
|
// multiplied by collateral decimals in format
|
|
29183
29359
|
margin_swap: [],
|
|
29184
|
-
margin_swap_limit_amount: Web3Number.fromWei(
|
|
29360
|
+
margin_swap_limit_amount: Web3Number.fromWei(
|
|
29361
|
+
0,
|
|
29362
|
+
this.config.collateral.decimals
|
|
29363
|
+
),
|
|
29185
29364
|
lever_swap: leverSwap,
|
|
29186
29365
|
lever_swap_limit_amount: leverSwapLimitAmount
|
|
29187
29366
|
} : {
|
|
@@ -29195,7 +29374,10 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29195
29374
|
lever_swap_limit_amount: leverSwapLimitAmount,
|
|
29196
29375
|
lever_swap_weights: [],
|
|
29197
29376
|
withdraw_swap: [],
|
|
29198
|
-
withdraw_swap_limit_amount: Web3Number.fromWei(
|
|
29377
|
+
withdraw_swap_limit_amount: Web3Number.fromWei(
|
|
29378
|
+
0,
|
|
29379
|
+
this.config.collateral.decimals
|
|
29380
|
+
),
|
|
29199
29381
|
withdraw_swap_weights: [],
|
|
29200
29382
|
close_position: false
|
|
29201
29383
|
};
|
|
@@ -29211,12 +29393,16 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29211
29393
|
});
|
|
29212
29394
|
let leverSwap = [];
|
|
29213
29395
|
let leverSwapLimitAmount = Web3Number.fromWei(0, this.config.debt.decimals);
|
|
29214
|
-
const existingPositions = await this.vesuAdapter.getPositions(
|
|
29396
|
+
const existingPositions = await this.vesuAdapter.getPositions(
|
|
29397
|
+
this.config.networkConfig
|
|
29398
|
+
);
|
|
29215
29399
|
const existingCollateralInfo = existingPositions[0];
|
|
29216
29400
|
const existingDebtInfo = existingPositions[1];
|
|
29217
29401
|
const collateralToken = this.config.collateral;
|
|
29218
29402
|
const debtToken = this.config.debt;
|
|
29219
|
-
const collateralPrice = await this.config.pricer.getPrice(
|
|
29403
|
+
const collateralPrice = await this.config.pricer.getPrice(
|
|
29404
|
+
collateralToken.symbol
|
|
29405
|
+
);
|
|
29220
29406
|
const debtPrice = await this.config.pricer.getPrice(debtToken.symbol);
|
|
29221
29407
|
const { deltadebtAmountUnits: debtAmountToRepay } = calculateDebtReductionAmountForWithdrawal(
|
|
29222
29408
|
existingDebtInfo.amount,
|
|
@@ -29227,27 +29413,41 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29227
29413
|
debtPrice.price,
|
|
29228
29414
|
debtToken.decimals
|
|
29229
29415
|
);
|
|
29230
|
-
console.log("debtAmountToRepay", debtAmountToRepay);
|
|
29231
29416
|
if (!debtAmountToRepay) {
|
|
29232
29417
|
throw new Error("error calculating debt amount to repay");
|
|
29233
29418
|
}
|
|
29234
|
-
const ekuboQuoter = new EkuboQuoter(
|
|
29235
|
-
|
|
29236
|
-
|
|
29419
|
+
const ekuboQuoter = new EkuboQuoter(
|
|
29420
|
+
this.config.networkConfig,
|
|
29421
|
+
this.config.pricer
|
|
29422
|
+
);
|
|
29423
|
+
const debtInDebtUnits = new Web3Number(
|
|
29424
|
+
debtAmountToRepay,
|
|
29425
|
+
debtToken.decimals
|
|
29426
|
+
).dividedBy(debtPrice.price).multipliedBy(10 ** debtToken.decimals);
|
|
29237
29427
|
const swapQuote = await ekuboQuoter.getQuote(
|
|
29238
29428
|
debtToken.address.address,
|
|
29239
29429
|
collateralToken.address.address,
|
|
29240
29430
|
debtInDebtUnits
|
|
29241
29431
|
);
|
|
29242
29432
|
const MAX_SLIPPAGE = 2e-3;
|
|
29243
|
-
if (swapQuote.price_impact <
|
|
29244
|
-
leverSwap = ekuboQuoter.getVesuMultiplyQuote(
|
|
29433
|
+
if (swapQuote.price_impact < 25e-4) {
|
|
29434
|
+
leverSwap = ekuboQuoter.getVesuMultiplyQuote(
|
|
29435
|
+
swapQuote,
|
|
29436
|
+
collateralToken,
|
|
29437
|
+
debtToken
|
|
29438
|
+
);
|
|
29245
29439
|
} else {
|
|
29246
|
-
logger.error(
|
|
29440
|
+
logger.error(
|
|
29441
|
+
`VesuMultiplyAdapter: Price impact too high (${swapQuote.price_impact}), skipping swap`
|
|
29442
|
+
);
|
|
29247
29443
|
}
|
|
29248
|
-
|
|
29249
|
-
|
|
29250
|
-
|
|
29444
|
+
leverSwapLimitAmount = new Web3Number(debtAmountToRepay, debtToken.decimals).abs().multipliedBy(1 + MAX_SLIPPAGE);
|
|
29445
|
+
const multiplyParams = await this.getLeverParams(
|
|
29446
|
+
false,
|
|
29447
|
+
params,
|
|
29448
|
+
leverSwap,
|
|
29449
|
+
leverSwapLimitAmount
|
|
29450
|
+
);
|
|
29251
29451
|
const call = multiplyContract.populate("modify_lever", {
|
|
29252
29452
|
modify_lever_params: this.formatMultiplyParams(false, multiplyParams)
|
|
29253
29453
|
});
|
|
@@ -29257,100 +29457,132 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29257
29457
|
if (isIncrease) {
|
|
29258
29458
|
const _params2 = params;
|
|
29259
29459
|
return {
|
|
29260
|
-
action: new CairoCustomEnum3({
|
|
29261
|
-
|
|
29262
|
-
|
|
29263
|
-
|
|
29264
|
-
|
|
29265
|
-
|
|
29266
|
-
|
|
29460
|
+
action: new CairoCustomEnum3({
|
|
29461
|
+
IncreaseLever: {
|
|
29462
|
+
pool_id: _params2.pool_id.toBigInt(),
|
|
29463
|
+
collateral_asset: _params2.collateral_asset.toBigInt(),
|
|
29464
|
+
debt_asset: _params2.debt_asset.toBigInt(),
|
|
29465
|
+
user: _params2.user.toBigInt(),
|
|
29466
|
+
add_margin: BigInt(_params2.add_margin.toWei()),
|
|
29467
|
+
margin_swap: _params2.margin_swap.map((swap) => ({
|
|
29468
|
+
route: swap.route.map((route) => ({
|
|
29469
|
+
pool_key: {
|
|
29470
|
+
token0: route.pool_key.token0.toBigInt(),
|
|
29471
|
+
token1: route.pool_key.token1.toBigInt(),
|
|
29472
|
+
fee: route.pool_key.fee,
|
|
29473
|
+
tick_spacing: route.pool_key.tick_spacing,
|
|
29474
|
+
extension: BigInt(
|
|
29475
|
+
num9.hexToDecimalString(route.pool_key.extension)
|
|
29476
|
+
)
|
|
29477
|
+
},
|
|
29478
|
+
sqrt_ratio_limit: uint25612.bnToUint256(
|
|
29479
|
+
route.sqrt_ratio_limit.toWei()
|
|
29480
|
+
),
|
|
29481
|
+
skip_ahead: BigInt(100)
|
|
29482
|
+
})),
|
|
29483
|
+
token_amount: {
|
|
29484
|
+
token: swap.token_amount.token.toBigInt(),
|
|
29485
|
+
amount: swap.token_amount.amount.toI129()
|
|
29486
|
+
}
|
|
29487
|
+
})),
|
|
29488
|
+
margin_swap_limit_amount: BigInt(
|
|
29489
|
+
_params2.margin_swap_limit_amount.toWei()
|
|
29490
|
+
),
|
|
29491
|
+
lever_swap: _params2.lever_swap.map((swap) => ({
|
|
29492
|
+
route: swap.route.map((route) => ({
|
|
29493
|
+
pool_key: {
|
|
29494
|
+
token0: route.pool_key.token0.toBigInt(),
|
|
29495
|
+
token1: route.pool_key.token1.toBigInt(),
|
|
29496
|
+
fee: route.pool_key.fee,
|
|
29497
|
+
tick_spacing: route.pool_key.tick_spacing,
|
|
29498
|
+
extension: BigInt(
|
|
29499
|
+
num9.hexToDecimalString(route.pool_key.extension)
|
|
29500
|
+
)
|
|
29501
|
+
},
|
|
29502
|
+
sqrt_ratio_limit: uint25612.bnToUint256(
|
|
29503
|
+
route.sqrt_ratio_limit.toWei()
|
|
29504
|
+
),
|
|
29505
|
+
skip_ahead: BigInt(0)
|
|
29506
|
+
})),
|
|
29507
|
+
token_amount: {
|
|
29508
|
+
token: swap.token_amount.token.toBigInt(),
|
|
29509
|
+
amount: swap.token_amount.amount.toI129()
|
|
29510
|
+
}
|
|
29511
|
+
})),
|
|
29512
|
+
lever_swap_limit_amount: BigInt(
|
|
29513
|
+
_params2.lever_swap_limit_amount.toWei()
|
|
29514
|
+
)
|
|
29515
|
+
}
|
|
29516
|
+
})
|
|
29517
|
+
};
|
|
29518
|
+
}
|
|
29519
|
+
const _params = params;
|
|
29520
|
+
return {
|
|
29521
|
+
action: new CairoCustomEnum3({
|
|
29522
|
+
DecreaseLever: {
|
|
29523
|
+
pool_id: _params.pool_id.toBigInt(),
|
|
29524
|
+
collateral_asset: _params.collateral_asset.toBigInt(),
|
|
29525
|
+
debt_asset: _params.debt_asset.toBigInt(),
|
|
29526
|
+
user: _params.user.toBigInt(),
|
|
29527
|
+
sub_margin: BigInt(_params.sub_margin.toWei()),
|
|
29528
|
+
recipient: _params.recipient.toBigInt(),
|
|
29529
|
+
lever_swap: _params.lever_swap.map((swap) => ({
|
|
29267
29530
|
route: swap.route.map((route) => ({
|
|
29268
29531
|
pool_key: {
|
|
29269
29532
|
token0: route.pool_key.token0.toBigInt(),
|
|
29270
29533
|
token1: route.pool_key.token1.toBigInt(),
|
|
29271
29534
|
fee: route.pool_key.fee,
|
|
29272
29535
|
tick_spacing: route.pool_key.tick_spacing,
|
|
29273
|
-
extension:
|
|
29536
|
+
extension: ContractAddr.from(
|
|
29537
|
+
route.pool_key.extension
|
|
29538
|
+
).toBigInt()
|
|
29274
29539
|
},
|
|
29275
|
-
sqrt_ratio_limit: uint25612.bnToUint256(
|
|
29276
|
-
|
|
29540
|
+
sqrt_ratio_limit: uint25612.bnToUint256(
|
|
29541
|
+
route.sqrt_ratio_limit.toWei()
|
|
29542
|
+
),
|
|
29543
|
+
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
29277
29544
|
})),
|
|
29278
29545
|
token_amount: {
|
|
29279
29546
|
token: swap.token_amount.token.toBigInt(),
|
|
29280
29547
|
amount: swap.token_amount.amount.toI129()
|
|
29281
29548
|
}
|
|
29282
29549
|
})),
|
|
29283
|
-
|
|
29284
|
-
|
|
29550
|
+
lever_swap_limit_amount: BigInt(
|
|
29551
|
+
_params.lever_swap_limit_amount.toWei()
|
|
29552
|
+
),
|
|
29553
|
+
lever_swap_weights: _params.lever_swap_weights.map(
|
|
29554
|
+
(weight) => BigInt(weight.toWei())
|
|
29555
|
+
),
|
|
29556
|
+
withdraw_swap: _params.withdraw_swap.map((swap) => ({
|
|
29285
29557
|
route: swap.route.map((route) => ({
|
|
29286
29558
|
pool_key: {
|
|
29287
29559
|
token0: route.pool_key.token0.toBigInt(),
|
|
29288
29560
|
token1: route.pool_key.token1.toBigInt(),
|
|
29289
29561
|
fee: route.pool_key.fee,
|
|
29290
29562
|
tick_spacing: route.pool_key.tick_spacing,
|
|
29291
|
-
extension:
|
|
29563
|
+
extension: ContractAddr.from(
|
|
29564
|
+
route.pool_key.extension
|
|
29565
|
+
).toBigInt()
|
|
29292
29566
|
},
|
|
29293
|
-
sqrt_ratio_limit: uint25612.bnToUint256(
|
|
29294
|
-
|
|
29567
|
+
sqrt_ratio_limit: uint25612.bnToUint256(
|
|
29568
|
+
route.sqrt_ratio_limit.toWei()
|
|
29569
|
+
),
|
|
29570
|
+
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
29295
29571
|
})),
|
|
29296
29572
|
token_amount: {
|
|
29297
29573
|
token: swap.token_amount.token.toBigInt(),
|
|
29298
29574
|
amount: swap.token_amount.amount.toI129()
|
|
29299
29575
|
}
|
|
29300
29576
|
})),
|
|
29301
|
-
|
|
29302
|
-
|
|
29303
|
-
|
|
29304
|
-
|
|
29305
|
-
|
|
29306
|
-
|
|
29307
|
-
|
|
29308
|
-
|
|
29309
|
-
|
|
29310
|
-
debt_asset: _params.debt_asset.toBigInt(),
|
|
29311
|
-
user: _params.user.toBigInt(),
|
|
29312
|
-
sub_margin: BigInt(_params.sub_margin.toWei()),
|
|
29313
|
-
recipient: _params.recipient.toBigInt(),
|
|
29314
|
-
lever_swap: _params.lever_swap.map((swap) => ({
|
|
29315
|
-
route: swap.route.map((route) => ({
|
|
29316
|
-
pool_key: {
|
|
29317
|
-
token0: route.pool_key.token0.toBigInt(),
|
|
29318
|
-
token1: route.pool_key.token1.toBigInt(),
|
|
29319
|
-
fee: route.pool_key.fee,
|
|
29320
|
-
tick_spacing: route.pool_key.tick_spacing,
|
|
29321
|
-
extension: ContractAddr.from(route.pool_key.extension).toBigInt()
|
|
29322
|
-
},
|
|
29323
|
-
sqrt_ratio_limit: uint25612.bnToUint256(route.sqrt_ratio_limit.toWei()),
|
|
29324
|
-
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
29325
|
-
})),
|
|
29326
|
-
token_amount: {
|
|
29327
|
-
token: swap.token_amount.token.toBigInt(),
|
|
29328
|
-
amount: swap.token_amount.amount.toI129()
|
|
29329
|
-
}
|
|
29330
|
-
})),
|
|
29331
|
-
lever_swap_limit_amount: BigInt(_params.lever_swap_limit_amount.toWei()),
|
|
29332
|
-
lever_swap_weights: _params.lever_swap_weights.map((weight) => BigInt(weight.toWei())),
|
|
29333
|
-
withdraw_swap: _params.withdraw_swap.map((swap) => ({
|
|
29334
|
-
route: swap.route.map((route) => ({
|
|
29335
|
-
pool_key: {
|
|
29336
|
-
token0: route.pool_key.token0.toBigInt(),
|
|
29337
|
-
token1: route.pool_key.token1.toBigInt(),
|
|
29338
|
-
fee: route.pool_key.fee,
|
|
29339
|
-
tick_spacing: route.pool_key.tick_spacing,
|
|
29340
|
-
extension: ContractAddr.from(route.pool_key.extension).toBigInt()
|
|
29341
|
-
},
|
|
29342
|
-
sqrt_ratio_limit: uint25612.bnToUint256(route.sqrt_ratio_limit.toWei()),
|
|
29343
|
-
skip_ahead: BigInt(route.skip_ahead.toWei())
|
|
29344
|
-
})),
|
|
29345
|
-
token_amount: {
|
|
29346
|
-
token: swap.token_amount.token.toBigInt(),
|
|
29347
|
-
amount: swap.token_amount.amount.toI129()
|
|
29348
|
-
}
|
|
29349
|
-
})),
|
|
29350
|
-
withdraw_swap_limit_amount: BigInt(_params.withdraw_swap_limit_amount.toWei()),
|
|
29351
|
-
withdraw_swap_weights: _params.withdraw_swap_weights.map((weight) => BigInt(weight.toWei())),
|
|
29352
|
-
close_position: _params.close_position
|
|
29353
|
-
} })
|
|
29577
|
+
withdraw_swap_limit_amount: BigInt(
|
|
29578
|
+
_params.withdraw_swap_limit_amount.toWei()
|
|
29579
|
+
),
|
|
29580
|
+
withdraw_swap_weights: _params.withdraw_swap_weights.map(
|
|
29581
|
+
(weight) => BigInt(weight.toWei())
|
|
29582
|
+
),
|
|
29583
|
+
close_position: _params.close_position
|
|
29584
|
+
}
|
|
29585
|
+
})
|
|
29354
29586
|
};
|
|
29355
29587
|
}
|
|
29356
29588
|
async getHealthFactor() {
|
|
@@ -29359,11 +29591,15 @@ var VesuMultiplyAdapter = class _VesuMultiplyAdapter extends BaseAdapter {
|
|
|
29359
29591
|
}
|
|
29360
29592
|
async getNetAPY() {
|
|
29361
29593
|
const positions = await this.getPositions();
|
|
29362
|
-
logger.verbose(
|
|
29594
|
+
logger.verbose(
|
|
29595
|
+
`${this.name}::getNetAPY: positions: ${JSON.stringify(positions)}`
|
|
29596
|
+
);
|
|
29363
29597
|
const allZero = positions.every((p) => p.usdValue === 0);
|
|
29364
29598
|
if (allZero) {
|
|
29365
29599
|
const collateralUSD = 1e3;
|
|
29366
|
-
const maxLTV = await this.vesuAdapter.getLTVConfig(
|
|
29600
|
+
const maxLTV = await this.vesuAdapter.getLTVConfig(
|
|
29601
|
+
this.config.networkConfig
|
|
29602
|
+
);
|
|
29367
29603
|
const targetHF = this.config.targetHealthFactor;
|
|
29368
29604
|
const maxDebt = HealthFactorMath.getMaxDebtAmountOnLooping(
|
|
29369
29605
|
new Web3Number(collateralUSD, this.config.collateral.decimals),
|
|
@@ -29399,12 +29635,17 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29399
29635
|
timeout: this.config.extendedTimeout,
|
|
29400
29636
|
retries: this.config.extendedRetries
|
|
29401
29637
|
});
|
|
29638
|
+
this.minimumExtendedMovementAmount = this.config.minimumExtendedMovementAmount ?? 5;
|
|
29402
29639
|
this.client = client;
|
|
29640
|
+
this.retryDelayForOrderStatus = this.config.retryDelayForOrderStatus ?? 3e3;
|
|
29403
29641
|
}
|
|
29404
29642
|
//abstract means the method has no implementation in this class; instead, child classes must implement it.
|
|
29405
29643
|
async getAPY(supportedPosition) {
|
|
29406
29644
|
const side = supportedPosition.isDebt ? "LONG" : "SHORT";
|
|
29407
|
-
const fundingRates = await this.client.getFundingRates(
|
|
29645
|
+
const fundingRates = await this.client.getFundingRates(
|
|
29646
|
+
this.config.extendedMarketName,
|
|
29647
|
+
side
|
|
29648
|
+
);
|
|
29408
29649
|
if (fundingRates.status !== "OK") {
|
|
29409
29650
|
logger.error("error getting funding rates", fundingRates);
|
|
29410
29651
|
return { apy: 0, type: "base" /* BASE */ };
|
|
@@ -29448,14 +29689,14 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29448
29689
|
});
|
|
29449
29690
|
}
|
|
29450
29691
|
_getDepositLeaf() {
|
|
29451
|
-
const usdceToken = Global.getDefaultTokens().find(
|
|
29692
|
+
const usdceToken = Global.getDefaultTokens().find(
|
|
29693
|
+
(token) => token.symbol === "USDCe"
|
|
29694
|
+
);
|
|
29452
29695
|
return [
|
|
29453
29696
|
{
|
|
29454
29697
|
target: this.config.supportedPositions[0].asset.address,
|
|
29455
29698
|
method: "approve",
|
|
29456
|
-
packedArguments: [
|
|
29457
|
-
AVNU_EXCHANGE_FOR_LEGACY_USDC.toBigInt()
|
|
29458
|
-
],
|
|
29699
|
+
packedArguments: [AVNU_EXCHANGE_FOR_LEGACY_USDC.toBigInt()],
|
|
29459
29700
|
id: `extended_approve_${this.config.supportedPositions[0].asset.symbol}`,
|
|
29460
29701
|
sanitizer: AVNU_LEGACY_SANITIZER
|
|
29461
29702
|
},
|
|
@@ -29482,17 +29723,62 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29482
29723
|
}
|
|
29483
29724
|
];
|
|
29484
29725
|
}
|
|
29726
|
+
getSwapFromLegacyLeaf() {
|
|
29727
|
+
const leafConfigs = this._getSwapFromLegacyLeaf();
|
|
29728
|
+
const leaves = leafConfigs.map((config) => {
|
|
29729
|
+
const { target, method, packedArguments, sanitizer, id } = config;
|
|
29730
|
+
const leaf = this.constructSimpleLeafData(
|
|
29731
|
+
{
|
|
29732
|
+
id,
|
|
29733
|
+
target,
|
|
29734
|
+
method,
|
|
29735
|
+
packedArguments
|
|
29736
|
+
},
|
|
29737
|
+
sanitizer
|
|
29738
|
+
);
|
|
29739
|
+
return leaf;
|
|
29740
|
+
});
|
|
29741
|
+
return {
|
|
29742
|
+
leaves,
|
|
29743
|
+
callConstructor: this.getSwapFromLegacyCall.bind(
|
|
29744
|
+
this
|
|
29745
|
+
)
|
|
29746
|
+
};
|
|
29747
|
+
}
|
|
29748
|
+
_getSwapFromLegacyLeaf() {
|
|
29749
|
+
const usdceToken = Global.getDefaultTokens().find(
|
|
29750
|
+
(token) => token.symbol === "USDCe"
|
|
29751
|
+
);
|
|
29752
|
+
return [
|
|
29753
|
+
{
|
|
29754
|
+
target: usdceToken.address,
|
|
29755
|
+
method: "approve",
|
|
29756
|
+
packedArguments: [AVNU_EXCHANGE_FOR_LEGACY_USDC.toBigInt()],
|
|
29757
|
+
id: `extendedswaplegacyapprove_${usdceToken.symbol}`,
|
|
29758
|
+
sanitizer: AVNU_LEGACY_SANITIZER
|
|
29759
|
+
},
|
|
29760
|
+
{
|
|
29761
|
+
target: AVNU_EXCHANGE_FOR_LEGACY_USDC,
|
|
29762
|
+
method: "swap_to_new",
|
|
29763
|
+
packedArguments: [],
|
|
29764
|
+
id: `extended_swap_to_new_${usdceToken.symbol}`,
|
|
29765
|
+
sanitizer: AVNU_LEGACY_SANITIZER
|
|
29766
|
+
}
|
|
29767
|
+
];
|
|
29768
|
+
}
|
|
29485
29769
|
_getWithdrawLeaf() {
|
|
29486
29770
|
return [];
|
|
29487
29771
|
}
|
|
29488
29772
|
async getDepositCall(params) {
|
|
29489
29773
|
try {
|
|
29490
29774
|
const usdcToken = this.config.supportedPositions[0].asset;
|
|
29491
|
-
const usdceToken = Global.getDefaultTokens().find(
|
|
29492
|
-
|
|
29493
|
-
|
|
29775
|
+
const usdceToken = Global.getDefaultTokens().find(
|
|
29776
|
+
(token) => token.symbol === "USDCe"
|
|
29777
|
+
);
|
|
29778
|
+
const salt = Math.floor(Math.random() * 10 ** usdcToken.decimals);
|
|
29779
|
+
const amount = uint25613.bnToUint256(
|
|
29780
|
+
params.amount.multipliedBy(10).toWei()
|
|
29494
29781
|
);
|
|
29495
|
-
const amount = uint25613.bnToUint256(params.amount.multipliedBy(10).toWei());
|
|
29496
29782
|
const quotes = await this.config.avnuAdapter.getQuotesAvnu(
|
|
29497
29783
|
usdcToken.address.toString(),
|
|
29498
29784
|
usdceToken.address.toString(),
|
|
@@ -29505,7 +29791,9 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29505
29791
|
logger.error("error getting quotes from avnu");
|
|
29506
29792
|
return [];
|
|
29507
29793
|
}
|
|
29508
|
-
const getCalldata = await this.config.avnuAdapter.getSwapCallData(
|
|
29794
|
+
const getCalldata = await this.config.avnuAdapter.getSwapCallData(
|
|
29795
|
+
quotes
|
|
29796
|
+
);
|
|
29509
29797
|
const swapCallData = getCalldata[0];
|
|
29510
29798
|
return [
|
|
29511
29799
|
{
|
|
@@ -29562,6 +29850,76 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29562
29850
|
return [];
|
|
29563
29851
|
}
|
|
29564
29852
|
}
|
|
29853
|
+
getProofsForFromLegacySwap(tree) {
|
|
29854
|
+
let proofGroups = [];
|
|
29855
|
+
const ids = this.getSwapFromLegacyLeaf().leaves.map((l) => l.readableId);
|
|
29856
|
+
for (const [i, v] of tree.entries()) {
|
|
29857
|
+
if (ids.includes(v.readableId)) {
|
|
29858
|
+
proofGroups.push(tree.getProof(i));
|
|
29859
|
+
}
|
|
29860
|
+
}
|
|
29861
|
+
if (proofGroups.length != ids.length) {
|
|
29862
|
+
throw new Error(`Not all proofs found for IDs: ${ids.join(", ")}`);
|
|
29863
|
+
}
|
|
29864
|
+
return {
|
|
29865
|
+
proofs: proofGroups,
|
|
29866
|
+
callConstructor: this.getSwapFromLegacyCall.bind(this)
|
|
29867
|
+
};
|
|
29868
|
+
}
|
|
29869
|
+
async getSwapFromLegacyCall(params) {
|
|
29870
|
+
try {
|
|
29871
|
+
const usdcToken = this.config.supportedPositions[0].asset;
|
|
29872
|
+
const usdceToken = Global.getDefaultTokens().find(
|
|
29873
|
+
(token) => token.symbol === "USDCe"
|
|
29874
|
+
);
|
|
29875
|
+
const amount = uint25613.bnToUint256(
|
|
29876
|
+
params.amount.multipliedBy(10).toWei()
|
|
29877
|
+
);
|
|
29878
|
+
const quotes = await this.config.avnuAdapter.getQuotesAvnu(
|
|
29879
|
+
usdceToken.address.toString(),
|
|
29880
|
+
usdcToken.address.toString(),
|
|
29881
|
+
params.amount.toNumber(),
|
|
29882
|
+
this.config.avnuAdapter.config.vaultAllocator.address.toString(),
|
|
29883
|
+
usdcToken.decimals,
|
|
29884
|
+
false
|
|
29885
|
+
);
|
|
29886
|
+
if (!quotes) {
|
|
29887
|
+
logger.error("error getting quotes from avnu");
|
|
29888
|
+
return [];
|
|
29889
|
+
}
|
|
29890
|
+
const getCalldata = await this.config.avnuAdapter.getSwapCallData(
|
|
29891
|
+
quotes
|
|
29892
|
+
);
|
|
29893
|
+
const swapCallData = getCalldata[0];
|
|
29894
|
+
return [
|
|
29895
|
+
{
|
|
29896
|
+
sanitizer: AVNU_LEGACY_SANITIZER,
|
|
29897
|
+
call: {
|
|
29898
|
+
contractAddress: usdceToken.address,
|
|
29899
|
+
selector: hash6.getSelectorFromName("approve"),
|
|
29900
|
+
calldata: [
|
|
29901
|
+
AVNU_EXCHANGE_FOR_LEGACY_USDC.toBigInt(),
|
|
29902
|
+
toBigInt(amount.low.toString()),
|
|
29903
|
+
// amount low
|
|
29904
|
+
toBigInt(amount.high.toString())
|
|
29905
|
+
// amount high
|
|
29906
|
+
]
|
|
29907
|
+
}
|
|
29908
|
+
},
|
|
29909
|
+
{
|
|
29910
|
+
sanitizer: AVNU_LEGACY_SANITIZER,
|
|
29911
|
+
call: {
|
|
29912
|
+
contractAddress: AVNU_EXCHANGE_FOR_LEGACY_USDC,
|
|
29913
|
+
selector: hash6.getSelectorFromName("swap_to_new"),
|
|
29914
|
+
calldata: swapCallData
|
|
29915
|
+
}
|
|
29916
|
+
}
|
|
29917
|
+
];
|
|
29918
|
+
} catch (error) {
|
|
29919
|
+
logger.error(`Error creating Deposit Call: ${error}`);
|
|
29920
|
+
return [];
|
|
29921
|
+
}
|
|
29922
|
+
}
|
|
29565
29923
|
//Swap wbtc to usdc
|
|
29566
29924
|
async getWithdrawCall(params) {
|
|
29567
29925
|
try {
|
|
@@ -29577,13 +29935,60 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29577
29935
|
async withdrawFromExtended(amount) {
|
|
29578
29936
|
try {
|
|
29579
29937
|
if (!this.client) {
|
|
29580
|
-
|
|
29938
|
+
logger.error("Client not initialized");
|
|
29939
|
+
return false;
|
|
29581
29940
|
}
|
|
29582
|
-
|
|
29583
|
-
|
|
29584
|
-
|
|
29585
|
-
|
|
29941
|
+
if (amount.lessThanOrEqualTo(0)) {
|
|
29942
|
+
logger.error(
|
|
29943
|
+
`Invalid withdrawal amount: ${amount.toNumber()}. Amount must be positive.`
|
|
29944
|
+
);
|
|
29945
|
+
return false;
|
|
29946
|
+
}
|
|
29947
|
+
if (amount.lessThanOrEqualTo(this.minimumExtendedMovementAmount)) {
|
|
29948
|
+
logger.warn(
|
|
29949
|
+
`Withdrawal amount ${amount.toNumber()} is below minimum Extended movement amount ${this.minimumExtendedMovementAmount}. Skipping withdrawal.`
|
|
29950
|
+
);
|
|
29951
|
+
return false;
|
|
29952
|
+
}
|
|
29953
|
+
const holdings = await this.getExtendedDepositAmount();
|
|
29954
|
+
if (!holdings) {
|
|
29955
|
+
logger.error(
|
|
29956
|
+
"Cannot get holdings - unable to validate withdrawal amount"
|
|
29957
|
+
);
|
|
29958
|
+
return false;
|
|
29959
|
+
}
|
|
29960
|
+
const availableForWithdrawal = parseFloat(
|
|
29961
|
+
holdings.availableForWithdrawal
|
|
29962
|
+
);
|
|
29963
|
+
if (!Number.isFinite(availableForWithdrawal) || availableForWithdrawal < 0) {
|
|
29964
|
+
logger.error(
|
|
29965
|
+
`Invalid availableForWithdrawal: ${holdings.availableForWithdrawal}. Expected a finite, non-negative number.`
|
|
29966
|
+
);
|
|
29967
|
+
return false;
|
|
29968
|
+
}
|
|
29969
|
+
const withdrawalAmount = amount.toNumber();
|
|
29970
|
+
if (withdrawalAmount > availableForWithdrawal) {
|
|
29971
|
+
logger.error(
|
|
29972
|
+
`Withdrawal amount ${withdrawalAmount} exceeds available balance ${availableForWithdrawal}`
|
|
29973
|
+
);
|
|
29974
|
+
return false;
|
|
29975
|
+
}
|
|
29976
|
+
logger.info(
|
|
29977
|
+
`Withdrawing ${withdrawalAmount} from Extended. Available balance: ${availableForWithdrawal}`
|
|
29978
|
+
);
|
|
29979
|
+
const withdrawalRequest = await this.client.withdrawUSDC(
|
|
29980
|
+
amount.toFixed(2)
|
|
29981
|
+
);
|
|
29982
|
+
if (withdrawalRequest.status === "OK") {
|
|
29983
|
+
const withdrawalStatus = await this.getDepositOrWithdrawalStatus(
|
|
29984
|
+
withdrawalRequest.data,
|
|
29985
|
+
"WITHDRAWAL" /* WITHDRAWAL */
|
|
29986
|
+
);
|
|
29987
|
+
return withdrawalStatus;
|
|
29586
29988
|
}
|
|
29989
|
+
logger.error(
|
|
29990
|
+
`Withdrawal request failed with status: ${withdrawalRequest.status}`
|
|
29991
|
+
);
|
|
29587
29992
|
return false;
|
|
29588
29993
|
} catch (error) {
|
|
29589
29994
|
logger.error(`Error creating Withdraw Call: ${error}`);
|
|
@@ -29594,21 +29999,44 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29594
29999
|
return Promise.resolve(1);
|
|
29595
30000
|
}
|
|
29596
30001
|
async getExtendedDepositAmount() {
|
|
29597
|
-
|
|
29598
|
-
|
|
29599
|
-
|
|
29600
|
-
|
|
29601
|
-
|
|
29602
|
-
|
|
29603
|
-
|
|
29604
|
-
|
|
29605
|
-
|
|
29606
|
-
|
|
29607
|
-
|
|
29608
|
-
|
|
30002
|
+
try {
|
|
30003
|
+
if (this.client === null) {
|
|
30004
|
+
logger.error("error initializing client - client is null");
|
|
30005
|
+
return void 0;
|
|
30006
|
+
}
|
|
30007
|
+
const result = await this.client.getHoldings();
|
|
30008
|
+
if (!result) {
|
|
30009
|
+
logger.error("error getting holdings - API returned null/undefined");
|
|
30010
|
+
return void 0;
|
|
30011
|
+
}
|
|
30012
|
+
if (result.status && result.status !== "OK") {
|
|
30013
|
+
logger.error(
|
|
30014
|
+
`error getting holdings - API returned status: ${result.status}`
|
|
30015
|
+
);
|
|
30016
|
+
return void 0;
|
|
30017
|
+
}
|
|
30018
|
+
const holdings = result.data;
|
|
30019
|
+
if (!holdings) {
|
|
30020
|
+
logger.warn(
|
|
30021
|
+
"holdings data is null/undefined - treating as zero balance"
|
|
30022
|
+
);
|
|
30023
|
+
return {
|
|
30024
|
+
collateral_name: "",
|
|
30025
|
+
balance: "0",
|
|
30026
|
+
equity: "0",
|
|
30027
|
+
availableForTrade: "0",
|
|
30028
|
+
availableForWithdrawal: "0",
|
|
30029
|
+
unrealisedPnl: "0",
|
|
30030
|
+
initialMargin: "0",
|
|
30031
|
+
marginRatio: "0",
|
|
30032
|
+
updatedTime: Date.now()
|
|
30033
|
+
};
|
|
30034
|
+
}
|
|
30035
|
+
return holdings;
|
|
30036
|
+
} catch (error) {
|
|
30037
|
+
logger.error(`error getting holdings - exception: ${error}`);
|
|
29609
30038
|
return void 0;
|
|
29610
30039
|
}
|
|
29611
|
-
return holdings;
|
|
29612
30040
|
}
|
|
29613
30041
|
async setLeverage(leverage, marketName) {
|
|
29614
30042
|
if (this.client === null) {
|
|
@@ -29650,21 +30078,24 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29650
30078
|
return result.data;
|
|
29651
30079
|
}
|
|
29652
30080
|
async getOrderStatus(orderId, marketName) {
|
|
29653
|
-
|
|
29654
|
-
|
|
29655
|
-
|
|
29656
|
-
|
|
29657
|
-
|
|
29658
|
-
|
|
29659
|
-
|
|
30081
|
+
try {
|
|
30082
|
+
if (this.client === null) {
|
|
30083
|
+
logger.error("error initializing client");
|
|
30084
|
+
return null;
|
|
30085
|
+
}
|
|
30086
|
+
const orderhistory = await this.getOrderHistory(marketName);
|
|
30087
|
+
if (!orderhistory || orderhistory.length === 0) {
|
|
30088
|
+
return null;
|
|
30089
|
+
}
|
|
30090
|
+
const order = orderhistory.slice(0, 20).find((order2) => order2.id.toString() === orderId);
|
|
30091
|
+
if (order) {
|
|
30092
|
+
return order;
|
|
30093
|
+
}
|
|
29660
30094
|
return null;
|
|
29661
|
-
}
|
|
29662
|
-
|
|
29663
|
-
if (!order) {
|
|
29664
|
-
logger.error(`error getting order: ${order}`);
|
|
30095
|
+
} catch (error) {
|
|
30096
|
+
logger.error(`error getting order status: ${error}`);
|
|
29665
30097
|
return null;
|
|
29666
30098
|
}
|
|
29667
|
-
return order;
|
|
29668
30099
|
}
|
|
29669
30100
|
async fetchOrderBookBTCUSDC() {
|
|
29670
30101
|
try {
|
|
@@ -29715,14 +30146,40 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29715
30146
|
logger.error("error depositing or setting leverage");
|
|
29716
30147
|
return null;
|
|
29717
30148
|
}
|
|
29718
|
-
const
|
|
29719
|
-
if (
|
|
30149
|
+
const { ask, bid } = await this.fetchOrderBookBTCUSDC();
|
|
30150
|
+
if (!ask || !bid || ask.lessThanOrEqualTo(0) || bid.lessThanOrEqualTo(0)) {
|
|
30151
|
+
logger.error(
|
|
30152
|
+
`Invalid orderbook prices: ask=${ask?.toNumber()}, bid=${bid?.toNumber()}`
|
|
30153
|
+
);
|
|
29720
30154
|
return null;
|
|
29721
30155
|
}
|
|
29722
|
-
const { ask, bid } = await this.fetchOrderBookBTCUSDC();
|
|
29723
30156
|
const spread = ask.minus(bid);
|
|
29724
|
-
|
|
29725
|
-
|
|
30157
|
+
const midPrice = ask.plus(bid).div(2);
|
|
30158
|
+
const MAX_PRICE_DEVIATION_MULTIPLIER = 0.5;
|
|
30159
|
+
const priceAdjustmentMultiplier = Math.min(
|
|
30160
|
+
0.2 * attempt,
|
|
30161
|
+
MAX_PRICE_DEVIATION_MULTIPLIER
|
|
30162
|
+
);
|
|
30163
|
+
const priceAdjustment = spread.times(priceAdjustmentMultiplier);
|
|
30164
|
+
let price = midPrice;
|
|
30165
|
+
if (side === "SELL" /* SELL */) {
|
|
30166
|
+
price = midPrice.minus(priceAdjustment);
|
|
30167
|
+
} else {
|
|
30168
|
+
price = midPrice.plus(priceAdjustment);
|
|
30169
|
+
}
|
|
30170
|
+
const maxDeviation = midPrice.times(0.5);
|
|
30171
|
+
if (price.minus(midPrice).abs().greaterThan(maxDeviation)) {
|
|
30172
|
+
logger.error(
|
|
30173
|
+
`Price deviation too large on attempt ${attempt}: price=${price.toNumber()}, midPrice=${midPrice.toNumber()}, deviation=${price.minus(midPrice).abs().toNumber()}`
|
|
30174
|
+
);
|
|
30175
|
+
if (attempt >= maxAttempts) {
|
|
30176
|
+
return null;
|
|
30177
|
+
}
|
|
30178
|
+
price = side === "SELL" /* SELL */ ? midPrice.minus(maxDeviation) : midPrice.plus(maxDeviation);
|
|
30179
|
+
}
|
|
30180
|
+
logger.info(
|
|
30181
|
+
`createOrder attempt ${attempt}/${maxAttempts}: side=${side}, midPrice=${midPrice.toNumber()}, adjustedPrice=${price.toNumber()}, adjustment=${priceAdjustmentMultiplier * 100}%`
|
|
30182
|
+
);
|
|
29726
30183
|
const amount_in_token = (btcAmount * parseInt(leverage)).toFixed(
|
|
29727
30184
|
this.config.extendedPrecision
|
|
29728
30185
|
);
|
|
@@ -29733,14 +30190,57 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29733
30190
|
price.toFixed(0),
|
|
29734
30191
|
side
|
|
29735
30192
|
);
|
|
29736
|
-
if (!result) {
|
|
30193
|
+
if (!result || !result.position_id) {
|
|
30194
|
+
logger.error("Failed to create order - no position_id returned");
|
|
29737
30195
|
return null;
|
|
29738
30196
|
}
|
|
29739
|
-
|
|
29740
|
-
|
|
29741
|
-
|
|
30197
|
+
const positionId = result.position_id;
|
|
30198
|
+
logger.info(
|
|
30199
|
+
`Order created with position_id: ${positionId}. Waiting for API to update...`
|
|
30200
|
+
);
|
|
30201
|
+
let openOrder = await this.getOrderStatus(
|
|
30202
|
+
positionId,
|
|
30203
|
+
this.config.extendedMarketName
|
|
30204
|
+
);
|
|
30205
|
+
const maxStatusRetries = 3;
|
|
30206
|
+
const statusRetryDelay = 5e3;
|
|
30207
|
+
if (!openOrder) {
|
|
30208
|
+
logger.warn(
|
|
30209
|
+
`Order ${positionId} not found in API yet. Retrying status fetch (max ${maxStatusRetries} times)...`
|
|
30210
|
+
);
|
|
30211
|
+
for (let statusRetry = 1; statusRetry <= maxStatusRetries; statusRetry++) {
|
|
30212
|
+
await new Promise((resolve) => setTimeout(resolve, statusRetryDelay));
|
|
30213
|
+
openOrder = await this.getOrderStatus(
|
|
30214
|
+
positionId,
|
|
30215
|
+
this.config.extendedMarketName
|
|
30216
|
+
);
|
|
30217
|
+
if (openOrder) {
|
|
30218
|
+
logger.info(
|
|
30219
|
+
`Order ${positionId} found after ${statusRetry} status retry(ies)`
|
|
30220
|
+
);
|
|
30221
|
+
break;
|
|
30222
|
+
}
|
|
30223
|
+
logger.warn(
|
|
30224
|
+
`Order ${positionId} still not found after ${statusRetry}/${maxStatusRetries} status retries`
|
|
30225
|
+
);
|
|
30226
|
+
}
|
|
30227
|
+
}
|
|
30228
|
+
if (openOrder && openOrder.status === "FILLED" /* FILLED */) {
|
|
30229
|
+
logger.info(
|
|
30230
|
+
`Order ${positionId} successfully filled with quantity ${openOrder.qty}`
|
|
30231
|
+
);
|
|
30232
|
+
return {
|
|
30233
|
+
position_id: positionId,
|
|
30234
|
+
btc_exposure: openOrder.qty
|
|
30235
|
+
};
|
|
30236
|
+
} else if (openOrder && openOrder.status !== "FILLED" /* FILLED */) {
|
|
30237
|
+
logger.warn(
|
|
30238
|
+
`Order ${positionId} found but status is ${openOrder.status}, not FILLED. Retrying order creation...`
|
|
30239
|
+
);
|
|
29742
30240
|
if (attempt >= maxAttempts) {
|
|
29743
|
-
logger.error(
|
|
30241
|
+
logger.error(
|
|
30242
|
+
`Max retries reached \u2014 order ${positionId} status is ${openOrder.status}, not FILLED`
|
|
30243
|
+
);
|
|
29744
30244
|
return null;
|
|
29745
30245
|
} else {
|
|
29746
30246
|
const backoff = 2e3 * attempt;
|
|
@@ -29754,16 +30254,21 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29754
30254
|
);
|
|
29755
30255
|
}
|
|
29756
30256
|
} else {
|
|
30257
|
+
logger.warn(
|
|
30258
|
+
`Order ${positionId} not found in API after ${maxStatusRetries} status retries (API update delayed ~30s). We got position_id from creation, so order exists. Returning position_id - status will be checked in next loop iteration.`
|
|
30259
|
+
);
|
|
29757
30260
|
return {
|
|
29758
|
-
position_id:
|
|
29759
|
-
btc_exposure:
|
|
30261
|
+
position_id: positionId,
|
|
30262
|
+
btc_exposure: amount_in_token
|
|
29760
30263
|
};
|
|
29761
30264
|
}
|
|
29762
30265
|
} catch (err) {
|
|
29763
|
-
logger.error(
|
|
30266
|
+
logger.error(
|
|
30267
|
+
`createShortOrder failed on attempt ${attempt}: ${err.message}`
|
|
30268
|
+
);
|
|
29764
30269
|
if (attempt < maxAttempts) {
|
|
29765
30270
|
const backoff = 1200 * attempt;
|
|
29766
|
-
|
|
30271
|
+
logger.info(`Retrying after ${backoff}ms...`);
|
|
29767
30272
|
await new Promise((resolve) => setTimeout(resolve, backoff));
|
|
29768
30273
|
return this.createOrder(
|
|
29769
30274
|
leverage,
|
|
@@ -29794,34 +30299,106 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29794
30299
|
}
|
|
29795
30300
|
return null;
|
|
29796
30301
|
} catch (err) {
|
|
29797
|
-
|
|
30302
|
+
logger.error(`Error opening short extended position, ${err}`);
|
|
29798
30303
|
return null;
|
|
29799
30304
|
}
|
|
29800
30305
|
}
|
|
29801
30306
|
async getDepositOrWithdrawalStatus(orderId, operationsType) {
|
|
29802
|
-
|
|
29803
|
-
|
|
29804
|
-
|
|
29805
|
-
|
|
29806
|
-
|
|
29807
|
-
|
|
29808
|
-
|
|
29809
|
-
|
|
29810
|
-
if (
|
|
29811
|
-
|
|
30307
|
+
const maxAttempts = 15;
|
|
30308
|
+
const retryDelayMs = 3e4;
|
|
30309
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
30310
|
+
try {
|
|
30311
|
+
let transferHistory = await this.client.getAssetOperations({
|
|
30312
|
+
operationsType: [operationsType],
|
|
30313
|
+
operationsStatus: ["COMPLETED" /* COMPLETED */]
|
|
30314
|
+
});
|
|
30315
|
+
if (operationsType === "DEPOSIT" /* DEPOSIT */) {
|
|
30316
|
+
const myTransferStatus = transferHistory.data.find(
|
|
30317
|
+
(operation) => operation.transactionHash === orderId
|
|
30318
|
+
);
|
|
30319
|
+
if (!myTransferStatus) {
|
|
30320
|
+
if (attempt < maxAttempts) {
|
|
30321
|
+
logger.info(
|
|
30322
|
+
`Deposit operation not found for transactionHash ${orderId}, retrying (attempt ${attempt}/${maxAttempts})...`
|
|
30323
|
+
);
|
|
30324
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
|
|
30325
|
+
continue;
|
|
30326
|
+
}
|
|
30327
|
+
logger.warn(
|
|
30328
|
+
`Deposit operation not found for transactionHash ${orderId} after ${maxAttempts} attempts`
|
|
30329
|
+
);
|
|
30330
|
+
return false;
|
|
30331
|
+
}
|
|
30332
|
+
if (myTransferStatus.status === "COMPLETED" /* COMPLETED */) {
|
|
30333
|
+
logger.info(
|
|
30334
|
+
`Deposit operation ${orderId} completed successfully`
|
|
30335
|
+
);
|
|
30336
|
+
return true;
|
|
30337
|
+
} else {
|
|
30338
|
+
if (attempt < maxAttempts) {
|
|
30339
|
+
logger.info(
|
|
30340
|
+
`Deposit operation ${orderId} found but status is ${myTransferStatus.status}, not COMPLETED. Retrying (attempt ${attempt}/${maxAttempts})...`
|
|
30341
|
+
);
|
|
30342
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
|
|
30343
|
+
continue;
|
|
30344
|
+
}
|
|
30345
|
+
logger.warn(
|
|
30346
|
+
`Deposit operation ${orderId} status is ${myTransferStatus.status} after ${maxAttempts} attempts, expected COMPLETED`
|
|
30347
|
+
);
|
|
30348
|
+
return false;
|
|
30349
|
+
}
|
|
30350
|
+
} else {
|
|
30351
|
+
const myTransferStatus = transferHistory.data.find(
|
|
30352
|
+
(operation) => operation.id === orderId.toString()
|
|
30353
|
+
);
|
|
30354
|
+
if (!myTransferStatus) {
|
|
30355
|
+
if (attempt < maxAttempts) {
|
|
30356
|
+
logger.info(
|
|
30357
|
+
`Withdrawal status not found for orderId ${orderId} in completed operations, retrying (attempt ${attempt}/${maxAttempts})...`
|
|
30358
|
+
);
|
|
30359
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
|
|
30360
|
+
continue;
|
|
30361
|
+
}
|
|
30362
|
+
logger.warn(
|
|
30363
|
+
`Withdrawal operation not found for orderId ${orderId} after ${maxAttempts} attempts`
|
|
30364
|
+
);
|
|
30365
|
+
return false;
|
|
30366
|
+
}
|
|
30367
|
+
if (myTransferStatus.status === "COMPLETED" /* COMPLETED */) {
|
|
30368
|
+
logger.info(
|
|
30369
|
+
`Withdrawal operation ${orderId} completed successfully`
|
|
30370
|
+
);
|
|
30371
|
+
return true;
|
|
30372
|
+
} else {
|
|
30373
|
+
if (attempt < maxAttempts) {
|
|
30374
|
+
logger.info(
|
|
30375
|
+
`Withdrawal operation ${orderId} found but status is ${myTransferStatus.status}, not COMPLETED. Retrying (attempt ${attempt}/${maxAttempts})...`
|
|
30376
|
+
);
|
|
30377
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
|
|
30378
|
+
continue;
|
|
30379
|
+
}
|
|
30380
|
+
logger.warn(
|
|
30381
|
+
`Withdrawal operation ${orderId} status is ${myTransferStatus.status} after ${maxAttempts} attempts, expected COMPLETED`
|
|
30382
|
+
);
|
|
30383
|
+
return false;
|
|
30384
|
+
}
|
|
29812
30385
|
}
|
|
29813
|
-
|
|
29814
|
-
|
|
29815
|
-
|
|
29816
|
-
|
|
29817
|
-
|
|
30386
|
+
} catch (err) {
|
|
30387
|
+
logger.error(
|
|
30388
|
+
`error getting deposit or withdrawal status (attempt ${attempt}/${maxAttempts}): ${err}`
|
|
30389
|
+
);
|
|
30390
|
+
if (attempt < maxAttempts) {
|
|
30391
|
+
logger.info(`Retrying after ${retryDelayMs}ms...`);
|
|
30392
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
|
|
30393
|
+
continue;
|
|
29818
30394
|
}
|
|
29819
|
-
|
|
30395
|
+
logger.error(
|
|
30396
|
+
`Max retry attempts reached for getDepositOrWithdrawalStatus`
|
|
30397
|
+
);
|
|
30398
|
+
return false;
|
|
29820
30399
|
}
|
|
29821
|
-
} catch (err) {
|
|
29822
|
-
logger.error(`error getting deposit or withdrawal status: ${err}`);
|
|
29823
|
-
return false;
|
|
29824
30400
|
}
|
|
30401
|
+
return false;
|
|
29825
30402
|
}
|
|
29826
30403
|
};
|
|
29827
30404
|
|
|
@@ -29907,6 +30484,11 @@ var AUMTypes = /* @__PURE__ */ ((AUMTypes2) => {
|
|
|
29907
30484
|
AUMTypes2["DEFISPRING"] = "defispring";
|
|
29908
30485
|
return AUMTypes2;
|
|
29909
30486
|
})(AUMTypes || {});
|
|
30487
|
+
var PositionTypeAvnuExtended = /* @__PURE__ */ ((PositionTypeAvnuExtended2) => {
|
|
30488
|
+
PositionTypeAvnuExtended2["OPEN"] = "open";
|
|
30489
|
+
PositionTypeAvnuExtended2["CLOSE"] = "close";
|
|
30490
|
+
return PositionTypeAvnuExtended2;
|
|
30491
|
+
})(PositionTypeAvnuExtended || {});
|
|
29910
30492
|
var UNIVERSAL_MANAGE_IDS = /* @__PURE__ */ ((UNIVERSAL_MANAGE_IDS2) => {
|
|
29911
30493
|
UNIVERSAL_MANAGE_IDS2["FLASH_LOAN"] = "flash_loan_init";
|
|
29912
30494
|
UNIVERSAL_MANAGE_IDS2["VESU_LEG1"] = "vesu_leg1";
|
|
@@ -33087,7 +33669,8 @@ function getLooperSettings(lstSymbol, underlyingSymbol, vaultSettings, pool1) {
|
|
|
33087
33669
|
minHealthFactor: vaultSettings.minHealthFactor,
|
|
33088
33670
|
quoteAmountToFetchPrice: vaultSettings.quoteAmountToFetchPrice,
|
|
33089
33671
|
...baseAdapterConfig,
|
|
33090
|
-
supportedPositions: [{ asset: lstToken, isDebt: false }, { asset: Global.getDefaultTokens().find((token) => token.symbol === position), isDebt: true }]
|
|
33672
|
+
supportedPositions: [{ asset: lstToken, isDebt: false }, { asset: Global.getDefaultTokens().find((token) => token.symbol === position), isDebt: true }],
|
|
33673
|
+
minimumVesuMovementAmount: 0
|
|
33091
33674
|
}));
|
|
33092
33675
|
const unusedBalanceAdapter = new UnusedBalanceAdapter({
|
|
33093
33676
|
...baseAdapterConfig
|
|
@@ -33403,7 +33986,7 @@ var AvnuAdapter = class _AvnuAdapter extends BaseAdapter {
|
|
|
33403
33986
|
packedArguments: [
|
|
33404
33987
|
fromToken.address.toBigInt(),
|
|
33405
33988
|
//wbtc
|
|
33406
|
-
|
|
33989
|
+
toToken.address.toBigInt(),
|
|
33407
33990
|
//usdc
|
|
33408
33991
|
vaultAllocator.toBigInt()
|
|
33409
33992
|
],
|
|
@@ -33417,13 +34000,11 @@ var AvnuAdapter = class _AvnuAdapter extends BaseAdapter {
|
|
|
33417
34000
|
}
|
|
33418
34001
|
async getDepositCall(params) {
|
|
33419
34002
|
try {
|
|
33420
|
-
console.log("params.amount", params.amount);
|
|
33421
34003
|
const fromToken = this.config.supportedPositions[0].asset;
|
|
33422
34004
|
const toToken = this.config.supportedPositions[1].asset;
|
|
33423
34005
|
const vaultAllocator = ContractAddr.from(
|
|
33424
34006
|
this.config.vaultAllocator.address
|
|
33425
34007
|
);
|
|
33426
|
-
console.log("vaultAllocator", vaultAllocator);
|
|
33427
34008
|
const quote = await this.getQuotesAvnu(
|
|
33428
34009
|
fromToken.address.toString(),
|
|
33429
34010
|
toToken.address.toString(),
|
|
@@ -33479,7 +34060,6 @@ var AvnuAdapter = class _AvnuAdapter extends BaseAdapter {
|
|
|
33479
34060
|
const vaultAllocator = ContractAddr.from(
|
|
33480
34061
|
this.config.vaultAllocator.address
|
|
33481
34062
|
);
|
|
33482
|
-
console.log("params.amount", params.amount);
|
|
33483
34063
|
const quote = await this.getQuotesAvnu(
|
|
33484
34064
|
fromToken.address.toString(),
|
|
33485
34065
|
toToken.address.toString(),
|
|
@@ -33498,8 +34078,6 @@ var AvnuAdapter = class _AvnuAdapter extends BaseAdapter {
|
|
|
33498
34078
|
);
|
|
33499
34079
|
const swapCallData = getCalldata[0];
|
|
33500
34080
|
const amount = uint25614.bnToUint256(params.amount.toWei());
|
|
33501
|
-
console.log("amount", amount);
|
|
33502
|
-
console.log("swapCallData", swapCallData);
|
|
33503
34081
|
return [
|
|
33504
34082
|
{
|
|
33505
34083
|
sanitizer: SIMPLE_SANITIZER,
|
|
@@ -33553,7 +34131,7 @@ var AvnuAdapter = class _AvnuAdapter extends BaseAdapter {
|
|
|
33553
34131
|
}
|
|
33554
34132
|
throw new Error("Failed to fetch quote after retries");
|
|
33555
34133
|
}
|
|
33556
|
-
async getQuotesAvnu(from_token_address, to_token_address, amount, takerAddress, toTokenDecimals, usdcToBtc, maxIterations = 5, tolerance =
|
|
34134
|
+
async getQuotesAvnu(from_token_address, to_token_address, amount, takerAddress, toTokenDecimals, usdcToBtc, maxIterations = 5, tolerance = 5e3) {
|
|
33557
34135
|
try {
|
|
33558
34136
|
const fromToken = this.config.supportedPositions[0].asset;
|
|
33559
34137
|
const toToken = this.config.supportedPositions[1].asset;
|
|
@@ -33574,14 +34152,12 @@ var AvnuAdapter = class _AvnuAdapter extends BaseAdapter {
|
|
|
33574
34152
|
return dataObject2;
|
|
33575
34153
|
}
|
|
33576
34154
|
const btcPrice = await this.getPriceOfToken(toToken.address.toString());
|
|
33577
|
-
console.log("btcPrice", btcPrice);
|
|
33578
34155
|
if (!btcPrice) {
|
|
33579
34156
|
logger.error(`error getting btc price: ${btcPrice}`);
|
|
33580
34157
|
return null;
|
|
33581
34158
|
}
|
|
33582
34159
|
const estimatedUsdcAmount = Math.floor(amount * btcPrice);
|
|
33583
34160
|
const targetBtcBig = BigInt(returnFormattedAmount(amount, toTokenDecimals));
|
|
33584
|
-
console.log("targetBtcBig", targetBtcBig);
|
|
33585
34161
|
let low = BigInt(
|
|
33586
34162
|
Math.floor(
|
|
33587
34163
|
estimatedUsdcAmount * 10 ** fromToken.decimals * 0.9
|
|
@@ -33684,6 +34260,23 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
33684
34260
|
debtPrice
|
|
33685
34261
|
};
|
|
33686
34262
|
}
|
|
34263
|
+
async getUnusedBalanceUSDCE() {
|
|
34264
|
+
const usdceToken = Global.getDefaultTokens().find(
|
|
34265
|
+
(token) => token.symbol === "USDCe"
|
|
34266
|
+
);
|
|
34267
|
+
const balance = await new ERC20(this.config).balanceOf(
|
|
34268
|
+
usdceToken.address,
|
|
34269
|
+
WALLET_ADDRESS,
|
|
34270
|
+
usdceToken.decimals
|
|
34271
|
+
);
|
|
34272
|
+
const price = await this.pricer.getPrice(usdceToken.symbol);
|
|
34273
|
+
const usdValue = Number(balance.toFixed(usdceToken.decimals)) * price.price;
|
|
34274
|
+
return {
|
|
34275
|
+
tokenInfo: usdceToken,
|
|
34276
|
+
amount: balance,
|
|
34277
|
+
usdValue
|
|
34278
|
+
};
|
|
34279
|
+
}
|
|
33687
34280
|
async getUnusedBalanceWBTC() {
|
|
33688
34281
|
const collateralToken = this.metadata.additionalInfo.borrowable_assets[0];
|
|
33689
34282
|
const balance = await new ERC20(this.config).balanceOf(
|
|
@@ -33729,22 +34322,30 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
33729
34322
|
}
|
|
33730
34323
|
return extendedAdapter.adapter;
|
|
33731
34324
|
}
|
|
33732
|
-
async moveAssetsToVaultAllocator(amount) {
|
|
34325
|
+
async moveAssetsToVaultAllocator(amount, extendedAdapter) {
|
|
33733
34326
|
try {
|
|
33734
|
-
const
|
|
33735
|
-
(token) => token.symbol === "
|
|
34327
|
+
const usdceToken = Global.getDefaultTokens().find(
|
|
34328
|
+
(token) => token.symbol === "USDCe"
|
|
33736
34329
|
);
|
|
33737
34330
|
const approveCall = new ERC20(this.config).approve(
|
|
33738
|
-
|
|
34331
|
+
usdceToken.address,
|
|
33739
34332
|
this.metadata.additionalInfo.vaultAllocator,
|
|
33740
34333
|
amount
|
|
33741
34334
|
);
|
|
33742
34335
|
const transferCall = new ERC20(this.config).transfer(
|
|
33743
|
-
|
|
34336
|
+
usdceToken.address,
|
|
33744
34337
|
this.metadata.additionalInfo.vaultAllocator,
|
|
33745
34338
|
amount
|
|
33746
34339
|
);
|
|
33747
|
-
|
|
34340
|
+
const proofsInfo = extendedAdapter.getProofsForFromLegacySwap(
|
|
34341
|
+
this.getMerkleTree()
|
|
34342
|
+
);
|
|
34343
|
+
const proofGroups = proofsInfo.proofs;
|
|
34344
|
+
const call = this.getManageCall(
|
|
34345
|
+
proofGroups,
|
|
34346
|
+
await proofsInfo.callConstructor({ amount })
|
|
34347
|
+
);
|
|
34348
|
+
return [approveCall, transferCall, call];
|
|
33748
34349
|
} catch (err) {
|
|
33749
34350
|
logger.error(`error moving assets to vault allocator: ${err}`);
|
|
33750
34351
|
return [];
|
|
@@ -33752,11 +34353,13 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
33752
34353
|
}
|
|
33753
34354
|
async shouldInvest() {
|
|
33754
34355
|
try {
|
|
34356
|
+
logger.info(`${_VesuExtendedMultiplierStrategy.name}::shouldInvest starting`);
|
|
33755
34357
|
const vesuAdapter = await this.getVesuAdapter();
|
|
33756
34358
|
const extendedAdapter = await this.getExtendedAdapter();
|
|
33757
|
-
|
|
34359
|
+
logger.info(`${_VesuExtendedMultiplierStrategy.name}::shouldInvest adapters fetched: vesuAdapter=${!!vesuAdapter}, extendedAdapter=${!!extendedAdapter}, extendedAdapter.client=${!!extendedAdapter?.client}`);
|
|
34360
|
+
if (!vesuAdapter) {
|
|
33758
34361
|
logger.error(
|
|
33759
|
-
`
|
|
34362
|
+
`Vesu adapter not configured in metadata. This is a configuration issue, not a temporary failure.`
|
|
33760
34363
|
);
|
|
33761
34364
|
return {
|
|
33762
34365
|
shouldInvest: false,
|
|
@@ -33768,10 +34371,87 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
33768
34371
|
vesuLeverage: 0
|
|
33769
34372
|
};
|
|
33770
34373
|
}
|
|
34374
|
+
if (!extendedAdapter) {
|
|
34375
|
+
logger.error(
|
|
34376
|
+
`Extended adapter not configured in metadata. This is a configuration issue, not a temporary failure.`
|
|
34377
|
+
);
|
|
34378
|
+
return {
|
|
34379
|
+
shouldInvest: false,
|
|
34380
|
+
vesuAmount: new Web3Number(0, 0),
|
|
34381
|
+
extendedAmount: new Web3Number(0, 0),
|
|
34382
|
+
extendedLeverage: 0,
|
|
34383
|
+
collateralPrice: 0,
|
|
34384
|
+
debtPrice: 0,
|
|
34385
|
+
vesuLeverage: 0
|
|
34386
|
+
};
|
|
34387
|
+
}
|
|
34388
|
+
if (!extendedAdapter.client) {
|
|
34389
|
+
logger.error(
|
|
34390
|
+
`Extended adapter client not initialized. This may be a temporary initialization failure - check network connectivity and API availability.`
|
|
34391
|
+
);
|
|
34392
|
+
return {
|
|
34393
|
+
shouldInvest: false,
|
|
34394
|
+
vesuAmount: new Web3Number(0, 0),
|
|
34395
|
+
extendedAmount: new Web3Number(0, 0),
|
|
34396
|
+
extendedLeverage: 0,
|
|
34397
|
+
collateralPrice: 0,
|
|
34398
|
+
debtPrice: 0,
|
|
34399
|
+
vesuLeverage: 0
|
|
34400
|
+
};
|
|
34401
|
+
}
|
|
34402
|
+
logger.info(`${_VesuExtendedMultiplierStrategy.name}::shouldInvest calling getUnusedBalance`);
|
|
33771
34403
|
const balance = await this.getUnusedBalance();
|
|
34404
|
+
if (!Number.isFinite(balance.usdValue) || balance.usdValue < 0) {
|
|
34405
|
+
logger.error(
|
|
34406
|
+
`Invalid balance.usdValue: ${balance.usdValue}. Expected a finite, non-negative number.`
|
|
34407
|
+
);
|
|
34408
|
+
return {
|
|
34409
|
+
shouldInvest: false,
|
|
34410
|
+
vesuAmount: new Web3Number(0, 0),
|
|
34411
|
+
extendedAmount: new Web3Number(0, 0),
|
|
34412
|
+
extendedLeverage: 0,
|
|
34413
|
+
collateralPrice: 0,
|
|
34414
|
+
debtPrice: 0,
|
|
34415
|
+
vesuLeverage: 0
|
|
34416
|
+
};
|
|
34417
|
+
}
|
|
34418
|
+
logger.info(`${_VesuExtendedMultiplierStrategy.name}::shouldInvest balance: ${balance.usdValue}`);
|
|
33772
34419
|
const usdcBalanceOnExtended = await extendedAdapter.getExtendedDepositAmount();
|
|
33773
|
-
|
|
33774
|
-
|
|
34420
|
+
if (usdcBalanceOnExtended) {
|
|
34421
|
+
const availableForWithdrawal = parseFloat(usdcBalanceOnExtended.availableForWithdrawal);
|
|
34422
|
+
if (!Number.isFinite(availableForWithdrawal) || availableForWithdrawal < 0) {
|
|
34423
|
+
logger.error(
|
|
34424
|
+
`Invalid usdcBalanceOnExtended.availableForWithdrawal: ${usdcBalanceOnExtended.availableForWithdrawal}. Expected a finite, non-negative number.`
|
|
34425
|
+
);
|
|
34426
|
+
return {
|
|
34427
|
+
shouldInvest: false,
|
|
34428
|
+
vesuAmount: new Web3Number(0, 0),
|
|
34429
|
+
extendedAmount: new Web3Number(0, 0),
|
|
34430
|
+
extendedLeverage: 0,
|
|
34431
|
+
collateralPrice: 0,
|
|
34432
|
+
debtPrice: 0,
|
|
34433
|
+
vesuLeverage: 0
|
|
34434
|
+
};
|
|
34435
|
+
}
|
|
34436
|
+
}
|
|
34437
|
+
const amountToInvest = new Web3Number(balance.usdValue, USDC_TOKEN_DECIMALS).plus(usdcBalanceOnExtended?.availableForWithdrawal ?? 0).multipliedBy(1 - LIMIT_BALANCE);
|
|
34438
|
+
const amountToInvestNumber = amountToInvest.toNumber();
|
|
34439
|
+
if (!Number.isFinite(amountToInvestNumber)) {
|
|
34440
|
+
logger.error(
|
|
34441
|
+
`Invalid amountToInvest calculation result: ${amountToInvestNumber}. Calculation may have produced NaN or Infinity.`
|
|
34442
|
+
);
|
|
34443
|
+
return {
|
|
34444
|
+
shouldInvest: false,
|
|
34445
|
+
vesuAmount: new Web3Number(0, 0),
|
|
34446
|
+
extendedAmount: new Web3Number(0, 0),
|
|
34447
|
+
extendedLeverage: 0,
|
|
34448
|
+
collateralPrice: 0,
|
|
34449
|
+
debtPrice: 0,
|
|
34450
|
+
vesuLeverage: 0
|
|
34451
|
+
};
|
|
34452
|
+
}
|
|
34453
|
+
logger.info(`${_VesuExtendedMultiplierStrategy.name}::shouldInvest amountToInvest: ${amountToInvestNumber}`);
|
|
34454
|
+
if (amountToInvest.lessThan(LIMIT_BALANCE_VALUE)) {
|
|
33775
34455
|
return {
|
|
33776
34456
|
shouldInvest: false,
|
|
33777
34457
|
vesuAmount: new Web3Number(0, 0),
|
|
@@ -33800,6 +34480,34 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
33800
34480
|
collateralPrice,
|
|
33801
34481
|
debtPrice
|
|
33802
34482
|
} = await this.getAssetPrices();
|
|
34483
|
+
if (!Number.isFinite(collateralPrice.price) || collateralPrice.price <= 0) {
|
|
34484
|
+
logger.error(
|
|
34485
|
+
`Invalid collateralPrice: ${collateralPrice.price}. Expected a finite, positive number.`
|
|
34486
|
+
);
|
|
34487
|
+
return {
|
|
34488
|
+
shouldInvest: false,
|
|
34489
|
+
vesuAmount: new Web3Number(0, 0),
|
|
34490
|
+
extendedAmount: new Web3Number(0, 0),
|
|
34491
|
+
extendedLeverage: 0,
|
|
34492
|
+
collateralPrice: 0,
|
|
34493
|
+
debtPrice: 0,
|
|
34494
|
+
vesuLeverage: 0
|
|
34495
|
+
};
|
|
34496
|
+
}
|
|
34497
|
+
if (!Number.isFinite(debtPrice.price) || debtPrice.price <= 0) {
|
|
34498
|
+
logger.error(
|
|
34499
|
+
`Invalid debtPrice: ${debtPrice.price}. Expected a finite, positive number.`
|
|
34500
|
+
);
|
|
34501
|
+
return {
|
|
34502
|
+
shouldInvest: false,
|
|
34503
|
+
vesuAmount: new Web3Number(0, 0),
|
|
34504
|
+
extendedAmount: new Web3Number(0, 0),
|
|
34505
|
+
extendedLeverage: 0,
|
|
34506
|
+
collateralPrice: 0,
|
|
34507
|
+
debtPrice: 0,
|
|
34508
|
+
vesuLeverage: 0
|
|
34509
|
+
};
|
|
34510
|
+
}
|
|
33803
34511
|
const { vesu_amount, extended_amount, extended_leverage, vesu_leverage } = await calculateAmountDistribution(
|
|
33804
34512
|
amountToInvest.toNumber(),
|
|
33805
34513
|
extendedAdapter.client,
|
|
@@ -33823,6 +34531,7 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
33823
34531
|
vesuLeverage: 0
|
|
33824
34532
|
};
|
|
33825
34533
|
}
|
|
34534
|
+
logger.info(`${_VesuExtendedMultiplierStrategy.name}::shouldInvest vesu_amount: ${vesu_amount.toNumber()}, extended_amount: ${extended_amount.toNumber()}`);
|
|
33826
34535
|
return {
|
|
33827
34536
|
shouldInvest: true,
|
|
33828
34537
|
vesuAmount: vesu_amount,
|
|
@@ -33849,18 +34558,48 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
33849
34558
|
try {
|
|
33850
34559
|
const vesuAdapter = await this.getVesuAdapter();
|
|
33851
34560
|
const extendedAdapter = await this.getExtendedAdapter();
|
|
33852
|
-
let calls = [];
|
|
33853
34561
|
if (!vesuAdapter || !extendedAdapter || !extendedAdapter.client) {
|
|
33854
34562
|
logger.error(
|
|
33855
34563
|
`vesu or extended adapter not found: vesuAdapter=${vesuAdapter}, extendedAdapter=${extendedAdapter}`
|
|
33856
34564
|
);
|
|
33857
|
-
return
|
|
34565
|
+
return [];
|
|
34566
|
+
}
|
|
34567
|
+
const extendedHoldings = await extendedAdapter.getExtendedDepositAmount();
|
|
34568
|
+
if (!extendedHoldings) {
|
|
34569
|
+
logger.error(`error getting extended holdings: ${extendedHoldings}`);
|
|
34570
|
+
return [];
|
|
33858
34571
|
}
|
|
33859
|
-
|
|
33860
|
-
|
|
33861
|
-
|
|
34572
|
+
const usdcAmountInWallet = (await this.getUnusedBalance()).amount;
|
|
34573
|
+
const usdcAmountOnExtendedAvailableForWithdrawal = parseFloat(
|
|
34574
|
+
extendedHoldings.availableForWithdrawal
|
|
34575
|
+
);
|
|
34576
|
+
logger.info(`${_VesuExtendedMultiplierStrategy.name}::shouldMoveAssets calculating movements - Extended current: ${usdcAmountOnExtendedAvailableForWithdrawal}, Wallet: ${usdcAmountInWallet.toNumber()}, Target Extended: ${extendedAmount.toNumber()}, Target Vesu: ${vesuAmount.toNumber()}`);
|
|
34577
|
+
let totalExtendedWithdrawal = new Web3Number(0, USDC_TOKEN_DECIMALS);
|
|
34578
|
+
let totalExtendedDeposit = new Web3Number(0, USDC_TOKEN_DECIMALS);
|
|
34579
|
+
if (extendedAmount.isNegative() && extendedAmount.abs().greaterThan(extendedAdapter.minimumExtendedMovementAmount)) {
|
|
34580
|
+
totalExtendedWithdrawal = totalExtendedWithdrawal.plus(extendedAmount.abs());
|
|
34581
|
+
}
|
|
34582
|
+
const extendedTargetAmount = extendedAmount.abs();
|
|
34583
|
+
let projectedExtendedBalance = usdcAmountOnExtendedAvailableForWithdrawal;
|
|
34584
|
+
if (extendedAmount.isNegative()) {
|
|
34585
|
+
projectedExtendedBalance = projectedExtendedBalance - extendedAmount.abs().toNumber();
|
|
34586
|
+
}
|
|
34587
|
+
const extendedAmountDifference = extendedTargetAmount.minus(projectedExtendedBalance);
|
|
34588
|
+
const extendedAmountDifferenceAbs = extendedAmountDifference.abs();
|
|
34589
|
+
if (extendedAmountDifference.lessThan(0)) {
|
|
34590
|
+
totalExtendedWithdrawal = totalExtendedWithdrawal.plus(extendedAmountDifferenceAbs);
|
|
34591
|
+
} else if (extendedAmountDifference.greaterThan(0)) {
|
|
34592
|
+
totalExtendedDeposit = totalExtendedDeposit.plus(extendedAmountDifference);
|
|
34593
|
+
}
|
|
34594
|
+
const vesuTargetAmount = vesuAmount.abs();
|
|
34595
|
+
const projectedWalletBalance = usdcAmountInWallet.plus(totalExtendedWithdrawal).minus(totalExtendedDeposit);
|
|
34596
|
+
let vesuAmountDifference = vesuTargetAmount.minus(projectedWalletBalance);
|
|
34597
|
+
const vesuAmountDifferenceAbs = vesuAmountDifference.abs();
|
|
34598
|
+
logger.info(`${_VesuExtendedMultiplierStrategy.name}::shouldMoveAssets calculated movements - Extended withdrawal: ${totalExtendedWithdrawal.toNumber()}, Extended deposit: ${totalExtendedDeposit.toNumber()}, Extended diff: ${extendedAmountDifference.toNumber()}, Projected wallet: ${projectedWalletBalance.toNumber()}, Vesu diff: ${vesuAmountDifference.toNumber()}`);
|
|
34599
|
+
let calls = [];
|
|
34600
|
+
if (extendedAmount.isNegative() && extendedAmount.abs().greaterThan(extendedAdapter.minimumExtendedMovementAmount)) {
|
|
33862
34601
|
try {
|
|
33863
|
-
const extendedCalls = await this.moveAssets(
|
|
34602
|
+
const { calls: extendedCalls, status: extendedStatus } = await this.moveAssets(
|
|
33864
34603
|
{
|
|
33865
34604
|
to: Protocols.VAULT.name,
|
|
33866
34605
|
from: Protocols.EXTENDED.name,
|
|
@@ -33869,14 +34608,18 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
33869
34608
|
extendedAdapter,
|
|
33870
34609
|
vesuAdapter
|
|
33871
34610
|
);
|
|
33872
|
-
|
|
34611
|
+
if (extendedStatus) {
|
|
34612
|
+
calls.push(...extendedCalls);
|
|
34613
|
+
} else {
|
|
34614
|
+
return [];
|
|
34615
|
+
}
|
|
33873
34616
|
} catch (err) {
|
|
33874
34617
|
logger.error(`Failed moving assets to vault: ${err}`);
|
|
33875
34618
|
}
|
|
33876
34619
|
}
|
|
33877
|
-
if (vesuAmount.
|
|
34620
|
+
if (vesuAmount.isNegative() && vesuAmount.abs().greaterThan(vesuAdapter.minimumVesuMovementAmount)) {
|
|
33878
34621
|
try {
|
|
33879
|
-
const vesuCalls = await this.moveAssets(
|
|
34622
|
+
const { calls: vesuCalls, status: vesuStatus } = await this.moveAssets(
|
|
33880
34623
|
{
|
|
33881
34624
|
to: Protocols.EXTENDED.name,
|
|
33882
34625
|
from: Protocols.VESU.name,
|
|
@@ -33886,49 +34629,83 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
33886
34629
|
vesuAdapter
|
|
33887
34630
|
);
|
|
33888
34631
|
calls.push(...vesuCalls);
|
|
34632
|
+
if (!vesuStatus) {
|
|
34633
|
+
return [];
|
|
34634
|
+
}
|
|
33889
34635
|
} catch (err) {
|
|
33890
34636
|
logger.error(`Failed moving assets to vault: ${err}`);
|
|
33891
34637
|
}
|
|
33892
34638
|
}
|
|
33893
|
-
|
|
33894
|
-
|
|
33895
|
-
|
|
33896
|
-
|
|
33897
|
-
|
|
33898
|
-
|
|
33899
|
-
|
|
33900
|
-
|
|
33901
|
-
|
|
33902
|
-
|
|
33903
|
-
|
|
33904
|
-
|
|
33905
|
-
{
|
|
33906
|
-
|
|
33907
|
-
|
|
33908
|
-
|
|
33909
|
-
|
|
33910
|
-
|
|
33911
|
-
|
|
33912
|
-
|
|
33913
|
-
|
|
33914
|
-
|
|
33915
|
-
|
|
34639
|
+
if (extendedAmountDifferenceAbs.greaterThan(extendedAdapter.minimumExtendedMovementAmount)) {
|
|
34640
|
+
if (extendedAmountDifference.greaterThan(0)) {
|
|
34641
|
+
try {
|
|
34642
|
+
const { calls: extendedCalls, status: extendedStatus } = await this.moveAssets(
|
|
34643
|
+
{
|
|
34644
|
+
to: Protocols.EXTENDED.name,
|
|
34645
|
+
from: Protocols.VAULT.name,
|
|
34646
|
+
amount: extendedAmountDifference
|
|
34647
|
+
},
|
|
34648
|
+
extendedAdapter,
|
|
34649
|
+
vesuAdapter
|
|
34650
|
+
);
|
|
34651
|
+
if (extendedStatus) {
|
|
34652
|
+
calls.push(...extendedCalls);
|
|
34653
|
+
} else {
|
|
34654
|
+
logger.error(`Failed to move assets to extended - operation returned false status`);
|
|
34655
|
+
return [];
|
|
34656
|
+
}
|
|
34657
|
+
} catch (err) {
|
|
34658
|
+
logger.error(`Failed moving assets to extended: ${err}`);
|
|
34659
|
+
return [];
|
|
34660
|
+
}
|
|
34661
|
+
} else if (extendedAmountDifference.lessThan(0)) {
|
|
34662
|
+
try {
|
|
34663
|
+
const { calls: extendedCalls, status: extendedStatus } = await this.moveAssets(
|
|
34664
|
+
{
|
|
34665
|
+
to: Protocols.VAULT.name,
|
|
34666
|
+
from: Protocols.EXTENDED.name,
|
|
34667
|
+
amount: extendedAmountDifferenceAbs
|
|
34668
|
+
},
|
|
34669
|
+
extendedAdapter,
|
|
34670
|
+
vesuAdapter
|
|
34671
|
+
);
|
|
34672
|
+
if (extendedStatus) {
|
|
34673
|
+
calls.push(...extendedCalls);
|
|
34674
|
+
} else {
|
|
34675
|
+
logger.error(`Failed to withdraw from extended - operation returned false status`);
|
|
34676
|
+
return [];
|
|
34677
|
+
}
|
|
34678
|
+
} catch (err) {
|
|
34679
|
+
logger.error(`Failed moving assets from extended to vault: ${err}`);
|
|
34680
|
+
return [];
|
|
34681
|
+
}
|
|
33916
34682
|
}
|
|
33917
34683
|
}
|
|
33918
|
-
if (
|
|
33919
|
-
|
|
33920
|
-
|
|
33921
|
-
{
|
|
33922
|
-
to: Protocols.VESU.name,
|
|
33923
|
-
from: Protocols.EXTENDED.name,
|
|
33924
|
-
amount: vesuAmount.minus(usdcAmountInWallet)
|
|
33925
|
-
},
|
|
33926
|
-
extendedAdapter,
|
|
33927
|
-
vesuAdapter
|
|
34684
|
+
if (vesuAmountDifferenceAbs.greaterThan(vesuAdapter.minimumVesuMovementAmount)) {
|
|
34685
|
+
if (vesuAmountDifference.lessThanOrEqualTo(0)) {
|
|
34686
|
+
logger.warn(
|
|
34687
|
+
`Vesu amount difference is negative or zero: ${vesuAmountDifference.toNumber()}. Skipping operation.`
|
|
33928
34688
|
);
|
|
33929
|
-
|
|
33930
|
-
|
|
33931
|
-
|
|
34689
|
+
} else {
|
|
34690
|
+
try {
|
|
34691
|
+
const { calls: vesuCalls, status: vesuStatus } = await this.moveAssets(
|
|
34692
|
+
{
|
|
34693
|
+
to: Protocols.VAULT.name,
|
|
34694
|
+
from: Protocols.EXTENDED.name,
|
|
34695
|
+
amount: vesuAmountDifference
|
|
34696
|
+
},
|
|
34697
|
+
extendedAdapter,
|
|
34698
|
+
vesuAdapter
|
|
34699
|
+
);
|
|
34700
|
+
if (!vesuStatus) {
|
|
34701
|
+
logger.error(`Failed to move assets to vesu - operation returned false status`);
|
|
34702
|
+
return [];
|
|
34703
|
+
}
|
|
34704
|
+
calls.push(...vesuCalls);
|
|
34705
|
+
} catch (err) {
|
|
34706
|
+
logger.error(`Failed moving assets to vault: ${err}`);
|
|
34707
|
+
return [];
|
|
34708
|
+
}
|
|
33932
34709
|
}
|
|
33933
34710
|
}
|
|
33934
34711
|
return calls;
|
|
@@ -33939,12 +34716,47 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
33939
34716
|
}
|
|
33940
34717
|
async moveAssets(params, extendedAdapter, vesuAdapter) {
|
|
33941
34718
|
try {
|
|
34719
|
+
if (params.amount.lessThanOrEqualTo(0)) {
|
|
34720
|
+
logger.error(
|
|
34721
|
+
`Invalid amount for moveAssets: ${params.amount.toNumber()}. Amount must be positive.`
|
|
34722
|
+
);
|
|
34723
|
+
return {
|
|
34724
|
+
calls: [],
|
|
34725
|
+
status: false
|
|
34726
|
+
};
|
|
34727
|
+
}
|
|
34728
|
+
const amountAbs = params.amount.abs();
|
|
34729
|
+
if (params.from === Protocols.EXTENDED.name || params.to === Protocols.EXTENDED.name) {
|
|
34730
|
+
if (amountAbs.lessThanOrEqualTo(extendedAdapter.minimumExtendedMovementAmount)) {
|
|
34731
|
+
logger.warn(
|
|
34732
|
+
`Amount ${amountAbs.toNumber()} is below minimum Extended movement amount ${extendedAdapter.minimumExtendedMovementAmount}. Skipping operation.`
|
|
34733
|
+
);
|
|
34734
|
+
return {
|
|
34735
|
+
calls: [],
|
|
34736
|
+
status: false
|
|
34737
|
+
};
|
|
34738
|
+
}
|
|
34739
|
+
}
|
|
34740
|
+
if (params.from === Protocols.VESU.name || params.to === Protocols.VESU.name) {
|
|
34741
|
+
if (amountAbs.lessThanOrEqualTo(vesuAdapter.minimumVesuMovementAmount)) {
|
|
34742
|
+
logger.warn(
|
|
34743
|
+
`Amount ${amountAbs.toNumber()} is below minimum Vesu movement amount ${vesuAdapter.minimumVesuMovementAmount}. Skipping operation.`
|
|
34744
|
+
);
|
|
34745
|
+
return {
|
|
34746
|
+
calls: [],
|
|
34747
|
+
status: false
|
|
34748
|
+
};
|
|
34749
|
+
}
|
|
34750
|
+
}
|
|
33942
34751
|
const avnuAdapter = await this.getAvnuAdapter();
|
|
33943
34752
|
if (!avnuAdapter) {
|
|
33944
34753
|
logger.error(`avnu adapter not found: ${avnuAdapter}`);
|
|
33945
|
-
return
|
|
34754
|
+
return {
|
|
34755
|
+
calls: [],
|
|
34756
|
+
status: false
|
|
34757
|
+
};
|
|
33946
34758
|
}
|
|
33947
|
-
logger.info(
|
|
34759
|
+
logger.info(`moveAssets params, ${JSON.stringify(params)}`);
|
|
33948
34760
|
const collateralToken = vesuAdapter.config.supportedPositions[0].asset;
|
|
33949
34761
|
const {
|
|
33950
34762
|
collateralPrice
|
|
@@ -33961,21 +34773,78 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
33961
34773
|
await proofsInfo.callConstructor({ amount: params.amount })
|
|
33962
34774
|
);
|
|
33963
34775
|
calls.push(call);
|
|
33964
|
-
return
|
|
34776
|
+
return {
|
|
34777
|
+
calls: [call],
|
|
34778
|
+
status: true
|
|
34779
|
+
};
|
|
33965
34780
|
} else if (params.to === Protocols.VAULT.name && params.from === Protocols.EXTENDED.name) {
|
|
34781
|
+
const extendedLeverage = calculateExtendedLevergae();
|
|
34782
|
+
const extendedHoldings = await extendedAdapter.getExtendedDepositAmount();
|
|
34783
|
+
if (!extendedHoldings) {
|
|
34784
|
+
logger.error(`error getting extended holdings: ${extendedHoldings}`);
|
|
34785
|
+
return {
|
|
34786
|
+
calls: [],
|
|
34787
|
+
status: false
|
|
34788
|
+
};
|
|
34789
|
+
}
|
|
34790
|
+
const extendedHoldingAmount = new Web3Number(
|
|
34791
|
+
extendedHoldings.availableForWithdrawal,
|
|
34792
|
+
USDC_TOKEN_DECIMALS
|
|
34793
|
+
);
|
|
34794
|
+
logger.info(`${_VesuExtendedMultiplierStrategy.name}::moveAssets extendedHoldingAmount: ${extendedHoldingAmount.toNumber()}`);
|
|
34795
|
+
if (params.amount.abs().greaterThan(extendedHoldingAmount)) {
|
|
34796
|
+
const leftAmountAfterWithdrawalAmountInAccount = params.amount.abs().minus(extendedHoldingAmount);
|
|
34797
|
+
logger.info(`${_VesuExtendedMultiplierStrategy.name}::moveAssets leftAmountAfterWithdrawalAmountInAccount: ${leftAmountAfterWithdrawalAmountInAccount.toNumber()}`);
|
|
34798
|
+
const btcAmount = leftAmountAfterWithdrawalAmountInAccount.dividedBy(collateralPrice.price);
|
|
34799
|
+
const openLongPosition = btcAmount.multipliedBy(3).greaterThan(MINIMUM_EXTENDED_POSITION_SIZE) ? await extendedAdapter.createOrder(
|
|
34800
|
+
extendedLeverage.toString(),
|
|
34801
|
+
btcAmount.toNumber(),
|
|
34802
|
+
"BUY" /* BUY */
|
|
34803
|
+
) : await extendedAdapter.createOrder(
|
|
34804
|
+
extendedLeverage.toString(),
|
|
34805
|
+
35e-6,
|
|
34806
|
+
// just in case amount falls short then we need to create a withdrawal
|
|
34807
|
+
"BUY" /* BUY */
|
|
34808
|
+
);
|
|
34809
|
+
if (!openLongPosition) {
|
|
34810
|
+
logger.error(`error opening long position: ${openLongPosition}`);
|
|
34811
|
+
}
|
|
34812
|
+
const updatedHoldings = await extendedAdapter.getExtendedDepositAmount();
|
|
34813
|
+
if (!updatedHoldings || new Web3Number(updatedHoldings.availableForWithdrawal, USDC_TOKEN_DECIMALS).lessThan(params.amount.abs())) {
|
|
34814
|
+
logger.error(`Insufficient balance after opening position. Available: ${updatedHoldings?.availableForWithdrawal}, Needed: ${params.amount.abs()}`);
|
|
34815
|
+
return { calls: [], status: false };
|
|
34816
|
+
}
|
|
34817
|
+
}
|
|
33966
34818
|
const withdrawalFromExtended = await extendedAdapter.withdrawFromExtended(params.amount);
|
|
33967
34819
|
if (withdrawalFromExtended) {
|
|
33968
|
-
const
|
|
34820
|
+
const extendedHoldings2 = await extendedAdapter.getExtendedDepositAmount();
|
|
34821
|
+
logger.info(`extendedHoldings after withdrawal ${extendedHoldings2?.availableForWithdrawal}`);
|
|
34822
|
+
await new Promise((resolve) => setTimeout(resolve, 5e3));
|
|
34823
|
+
const calls = await this.moveAssetsToVaultAllocator(params.amount, extendedAdapter);
|
|
33969
34824
|
if (calls.length > 0) {
|
|
33970
|
-
return
|
|
34825
|
+
return {
|
|
34826
|
+
calls,
|
|
34827
|
+
status: true
|
|
34828
|
+
};
|
|
33971
34829
|
}
|
|
33972
34830
|
} else {
|
|
33973
34831
|
logger.error("withdrawal from extended failed");
|
|
34832
|
+
return {
|
|
34833
|
+
calls: [],
|
|
34834
|
+
status: false
|
|
34835
|
+
};
|
|
33974
34836
|
}
|
|
33975
|
-
return [];
|
|
33976
34837
|
} else if (params.to === Protocols.VAULT.name && params.from === Protocols.VESU.name) {
|
|
34838
|
+
const isPriceDifferenceBetweenAvnuAndExtended = await this.checkPriceDifferenceBetweenAvnuAndExtended(extendedAdapter, vesuAdapter, avnuAdapter, "close" /* CLOSE */);
|
|
34839
|
+
if (!isPriceDifferenceBetweenAvnuAndExtended) {
|
|
34840
|
+
logger.warn(`price difference between avnu and extended doesn't fit the range for close position, ${avnuAdapter.config.maximumExtendedPriceDifferenceForSwapClosing}`);
|
|
34841
|
+
return {
|
|
34842
|
+
calls: [],
|
|
34843
|
+
status: false
|
|
34844
|
+
};
|
|
34845
|
+
}
|
|
33977
34846
|
const vesuAmountInBTC = new Web3Number(
|
|
33978
|
-
params.amount.dividedBy(collateralPrice.price).
|
|
34847
|
+
params.amount.dividedBy(collateralPrice.price).toFixed(WBTC_TOKEN_DECIMALS),
|
|
33979
34848
|
collateralToken.decimals
|
|
33980
34849
|
);
|
|
33981
34850
|
const proofsInfo = vesuAdapter.getProofs(false, this.getMerkleTree());
|
|
@@ -33993,8 +34862,19 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
33993
34862
|
await swapProofsInfo.callConstructor({ amount: vesuAmountInBTC })
|
|
33994
34863
|
);
|
|
33995
34864
|
calls.push(swapCall);
|
|
33996
|
-
return
|
|
34865
|
+
return {
|
|
34866
|
+
calls,
|
|
34867
|
+
status: true
|
|
34868
|
+
};
|
|
33997
34869
|
} else if (params.to === Protocols.EXTENDED.name && params.from === Protocols.VESU.name) {
|
|
34870
|
+
const isPriceDifferenceBetweenAvnuAndExtended = await this.checkPriceDifferenceBetweenAvnuAndExtended(extendedAdapter, vesuAdapter, avnuAdapter, "close" /* CLOSE */);
|
|
34871
|
+
if (!isPriceDifferenceBetweenAvnuAndExtended) {
|
|
34872
|
+
logger.warn(`price difference between avnu and extended doesn't fit the range for close position, ${avnuAdapter.config.maximumExtendedPriceDifferenceForSwapClosing}`);
|
|
34873
|
+
return {
|
|
34874
|
+
calls: [],
|
|
34875
|
+
status: false
|
|
34876
|
+
};
|
|
34877
|
+
}
|
|
33998
34878
|
const vesuAmountInBTC = new Web3Number(
|
|
33999
34879
|
params.amount.dividedBy(collateralPrice.price).toNumber(),
|
|
34000
34880
|
collateralToken.decimals
|
|
@@ -34024,13 +34904,21 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34024
34904
|
await proofsInfoDeposit.callConstructor({ amount: params.amount })
|
|
34025
34905
|
);
|
|
34026
34906
|
calls.push(callDeposit);
|
|
34027
|
-
return
|
|
34907
|
+
return {
|
|
34908
|
+
calls,
|
|
34909
|
+
status: true
|
|
34910
|
+
};
|
|
34028
34911
|
}
|
|
34029
|
-
|
|
34030
|
-
|
|
34912
|
+
return {
|
|
34913
|
+
calls: [],
|
|
34914
|
+
status: false
|
|
34915
|
+
};
|
|
34031
34916
|
} catch (err) {
|
|
34032
34917
|
logger.error(`error moving assets: ${err}`);
|
|
34033
|
-
return
|
|
34918
|
+
return {
|
|
34919
|
+
calls: [],
|
|
34920
|
+
status: false
|
|
34921
|
+
};
|
|
34034
34922
|
}
|
|
34035
34923
|
}
|
|
34036
34924
|
async handleDeposit() {
|
|
@@ -34050,7 +34938,7 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34050
34938
|
};
|
|
34051
34939
|
}
|
|
34052
34940
|
const extendedLeverage = calculateExtendedLevergae();
|
|
34053
|
-
const isPriceDifferenceBetweenAvnuAndExtended = await this.checkPriceDifferenceBetweenAvnuAndExtended(extendedAdapter, vesuAdapter, avnuAdapter);
|
|
34941
|
+
const isPriceDifferenceBetweenAvnuAndExtended = await this.checkPriceDifferenceBetweenAvnuAndExtended(extendedAdapter, vesuAdapter, avnuAdapter, "open" /* OPEN */);
|
|
34054
34942
|
if (!isPriceDifferenceBetweenAvnuAndExtended) {
|
|
34055
34943
|
logger.error("price difference between avnu and extended doesn't fit the range");
|
|
34056
34944
|
return {
|
|
@@ -34067,6 +34955,7 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34067
34955
|
};
|
|
34068
34956
|
}
|
|
34069
34957
|
const extendedPositionValue = position.length > 0 ? parseFloat(position[0].value) : 0;
|
|
34958
|
+
const BUFFER_AMOUNT_IN_AVAILABLE_FOR_TRADE = BUFFER_USDC_IN_WITHDRAWAL;
|
|
34070
34959
|
const extendedHoldings = await extendedAdapter.getExtendedDepositAmount();
|
|
34071
34960
|
if (!extendedHoldings) {
|
|
34072
34961
|
logger.error(`error getting extended holdings: ${extendedHoldings}`);
|
|
@@ -34085,12 +34974,11 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34085
34974
|
const { collateralPrice } = await this.getAssetPrices();
|
|
34086
34975
|
const { vesuAmountInBTC, extendedAmountInBTC } = calculateVesUPositionSizeGivenExtended(
|
|
34087
34976
|
extendedPositionValue,
|
|
34088
|
-
extendedHoldingAmount,
|
|
34977
|
+
extendedHoldingAmount.minus(BUFFER_AMOUNT_IN_AVAILABLE_FOR_TRADE),
|
|
34089
34978
|
collateralTokenAmount,
|
|
34090
34979
|
collateralPrice.price
|
|
34091
34980
|
);
|
|
34092
|
-
|
|
34093
|
-
console.log("extendedAmountInBTC", extendedAmountInBTC);
|
|
34981
|
+
logger.info(`vesuAmountInBTC ${vesuAmountInBTC}, extendedAmountInBTC ${extendedAmountInBTC}`);
|
|
34094
34982
|
let calls = [];
|
|
34095
34983
|
if (vesuAmountInBTC.greaterThan(MINIMUM_EXTENDED_POSITION_SIZE)) {
|
|
34096
34984
|
const proofsInfo = vesuAdapter.getProofs(true, this.getMerkleTree());
|
|
@@ -34103,7 +34991,6 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34103
34991
|
);
|
|
34104
34992
|
const { amount: wbtcAmountInVaultAllocator } = await this.getUnusedBalanceWBTC();
|
|
34105
34993
|
if (wbtcAmountInVaultAllocator.lessThan(vesuAmountInBTC)) {
|
|
34106
|
-
console.log("error wbtc amount in vault allocator is less than vesu amount in btc", wbtcAmountInVaultAllocator, vesuAmountInBTC);
|
|
34107
34994
|
const swapProofsInfo = avnuAdapter.getProofs(true, this.getMerkleTree());
|
|
34108
34995
|
const swapProofGroups = swapProofsInfo.proofs;
|
|
34109
34996
|
const swapCall = this.getManageCall(
|
|
@@ -34138,68 +35025,98 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34138
35025
|
extendedAmountInBTC: new Web3Number(0, 0),
|
|
34139
35026
|
calls: []
|
|
34140
35027
|
};
|
|
34141
|
-
;
|
|
34142
35028
|
}
|
|
34143
35029
|
}
|
|
34144
|
-
async checkPriceDifferenceBetweenAvnuAndExtended(extendedAdapter, vesuAdapter, avnuAdapter) {
|
|
35030
|
+
async checkPriceDifferenceBetweenAvnuAndExtended(extendedAdapter, vesuAdapter, avnuAdapter, positionType) {
|
|
34145
35031
|
const {
|
|
34146
35032
|
ask,
|
|
34147
35033
|
bid
|
|
34148
35034
|
} = await extendedAdapter.fetchOrderBookBTCUSDC();
|
|
34149
35035
|
const price = ask.plus(bid).dividedBy(2);
|
|
34150
|
-
const btcToken = vesuAdapter.config.supportedPositions[
|
|
35036
|
+
const btcToken = vesuAdapter.config.supportedPositions[0].asset;
|
|
34151
35037
|
const btcPriceAvnu = await avnuAdapter.getPriceOfToken(btcToken.address.toString());
|
|
34152
35038
|
if (!btcPriceAvnu) {
|
|
34153
35039
|
logger.error(`error getting btc price avnu: ${btcPriceAvnu}`);
|
|
34154
35040
|
return false;
|
|
34155
35041
|
}
|
|
34156
|
-
const priceDifference = price.minus(btcPriceAvnu).
|
|
34157
|
-
if (priceDifference
|
|
34158
|
-
return
|
|
35042
|
+
const priceDifference = new Web3Number(price.minus(btcPriceAvnu).toFixed(2), 0);
|
|
35043
|
+
if (priceDifference.isNegative()) {
|
|
35044
|
+
return false;
|
|
35045
|
+
}
|
|
35046
|
+
if (positionType === "open" /* OPEN */) {
|
|
35047
|
+
logger.info(`price difference between avnu and extended for open position: ${priceDifference.toNumber()}, minimumExtendedPriceDifferenceForSwapOpen: ${avnuAdapter.config.minimumExtendedPriceDifferenceForSwapOpen}`);
|
|
35048
|
+
const result = priceDifference.greaterThanOrEqualTo(avnuAdapter.config.minimumExtendedPriceDifferenceForSwapOpen);
|
|
35049
|
+
logger.info(`result: ${result}`);
|
|
35050
|
+
return result;
|
|
35051
|
+
} else {
|
|
35052
|
+
logger.info(`price difference between avnu and extended for close position: ${priceDifference.toNumber()}, maximumExtendedPriceDifferenceForSwapClosing: ${avnuAdapter.config.maximumExtendedPriceDifferenceForSwapClosing}`);
|
|
35053
|
+
const result = priceDifference.lessThanOrEqualTo(avnuAdapter.config.maximumExtendedPriceDifferenceForSwapClosing);
|
|
35054
|
+
logger.info(`result: ${result}`);
|
|
35055
|
+
return result;
|
|
34159
35056
|
}
|
|
34160
|
-
logger.error(`price difference between avnu and extended doesn't fit the range, priceDifference: ${priceDifference}`);
|
|
34161
|
-
return false;
|
|
34162
35057
|
}
|
|
34163
35058
|
async handleWithdraw(amount) {
|
|
34164
35059
|
try {
|
|
34165
35060
|
const usdcBalanceVaultAllocator = await this.getUnusedBalance();
|
|
34166
|
-
const usdcBalanceDifference = amount.minus(usdcBalanceVaultAllocator.usdValue);
|
|
35061
|
+
const usdcBalanceDifference = amount.plus(BUFFER_USDC_IN_WITHDRAWAL).minus(usdcBalanceVaultAllocator.usdValue);
|
|
34167
35062
|
logger.info(`usdcBalanceDifference, ${usdcBalanceDifference.toNumber()}`);
|
|
35063
|
+
let calls = [];
|
|
35064
|
+
let status = true;
|
|
34168
35065
|
if (usdcBalanceDifference.lessThan(0)) {
|
|
34169
|
-
const
|
|
34170
|
-
amount
|
|
35066
|
+
const withdrawCall2 = await this.getBringLiquidityCall({
|
|
35067
|
+
amount: usdcBalanceVaultAllocator.amount
|
|
34171
35068
|
});
|
|
34172
|
-
logger.info("withdraw call",
|
|
34173
|
-
|
|
35069
|
+
logger.info("withdraw call", withdrawCall2);
|
|
35070
|
+
calls.push(withdrawCall2);
|
|
35071
|
+
return {
|
|
35072
|
+
calls,
|
|
35073
|
+
status: true
|
|
35074
|
+
};
|
|
34174
35075
|
}
|
|
34175
35076
|
const vesuAdapter = await this.getVesuAdapter();
|
|
34176
35077
|
const extendedAdapter = await this.getExtendedAdapter();
|
|
34177
35078
|
if (!vesuAdapter || !extendedAdapter || !extendedAdapter.client) {
|
|
35079
|
+
status = false;
|
|
34178
35080
|
logger.error(
|
|
34179
35081
|
`vesu or extended adapter not found: vesuAdapter=${vesuAdapter}, extendedAdapter=${extendedAdapter}`
|
|
34180
35082
|
);
|
|
34181
|
-
return
|
|
35083
|
+
return {
|
|
35084
|
+
calls,
|
|
35085
|
+
status
|
|
35086
|
+
};
|
|
34182
35087
|
}
|
|
34183
35088
|
const { collateralTokenAmount } = await vesuAdapter.vesuAdapter.getAssetPrices();
|
|
34184
35089
|
const {
|
|
34185
35090
|
collateralPrice
|
|
34186
35091
|
} = await this.getAssetPrices();
|
|
34187
35092
|
const extendedPositon = await extendedAdapter.getAllOpenPositions();
|
|
35093
|
+
if (!extendedPositon) {
|
|
35094
|
+
status = false;
|
|
35095
|
+
logger.error("error getting extended position", extendedPositon);
|
|
35096
|
+
return {
|
|
35097
|
+
calls,
|
|
35098
|
+
status
|
|
35099
|
+
};
|
|
35100
|
+
}
|
|
34188
35101
|
const amountDistributionForWithdrawal = await calculateAmountDistributionForWithdrawal(
|
|
34189
|
-
|
|
35102
|
+
usdcBalanceDifference,
|
|
34190
35103
|
collateralPrice.price,
|
|
34191
35104
|
collateralTokenAmount,
|
|
34192
35105
|
extendedPositon
|
|
34193
35106
|
);
|
|
34194
35107
|
if (!amountDistributionForWithdrawal) {
|
|
35108
|
+
status = false;
|
|
34195
35109
|
logger.error(
|
|
34196
35110
|
`error calculating amount distribution for withdrawal: ${amountDistributionForWithdrawal}`
|
|
34197
35111
|
);
|
|
34198
|
-
return
|
|
35112
|
+
return {
|
|
35113
|
+
calls,
|
|
35114
|
+
status
|
|
35115
|
+
};
|
|
34199
35116
|
}
|
|
34200
35117
|
const { vesu_amount, extended_amount } = amountDistributionForWithdrawal;
|
|
34201
|
-
if (vesu_amount.greaterThan(0)) {
|
|
34202
|
-
const
|
|
35118
|
+
if (status && vesu_amount.greaterThan(0)) {
|
|
35119
|
+
const { calls: vesuCalls, status: vesuStatus } = await this.moveAssets(
|
|
34203
35120
|
{
|
|
34204
35121
|
amount: vesu_amount,
|
|
34205
35122
|
from: Protocols.VESU.name,
|
|
@@ -34208,10 +35125,11 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34208
35125
|
extendedAdapter,
|
|
34209
35126
|
vesuAdapter
|
|
34210
35127
|
);
|
|
34211
|
-
|
|
35128
|
+
status = vesuStatus;
|
|
35129
|
+
calls.push(...vesuCalls);
|
|
34212
35130
|
}
|
|
34213
|
-
if (extended_amount.greaterThan(0)) {
|
|
34214
|
-
const
|
|
35131
|
+
if (status && extended_amount.greaterThan(0)) {
|
|
35132
|
+
const { calls: extendedCalls, status: extendedStatus } = await this.moveAssets(
|
|
34215
35133
|
{
|
|
34216
35134
|
amount: extended_amount,
|
|
34217
35135
|
from: Protocols.EXTENDED.name,
|
|
@@ -34220,12 +35138,32 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34220
35138
|
extendedAdapter,
|
|
34221
35139
|
vesuAdapter
|
|
34222
35140
|
);
|
|
34223
|
-
|
|
35141
|
+
status = extendedStatus;
|
|
35142
|
+
if (status) {
|
|
35143
|
+
calls.push(...extendedCalls);
|
|
35144
|
+
} else {
|
|
35145
|
+
logger.error("error moving assets to vault: extendedStatus: ${extendedStatus}");
|
|
35146
|
+
return {
|
|
35147
|
+
calls: [],
|
|
35148
|
+
status
|
|
35149
|
+
};
|
|
35150
|
+
}
|
|
34224
35151
|
}
|
|
34225
|
-
|
|
35152
|
+
const withdrawCall = await this.getBringLiquidityCall({
|
|
35153
|
+
amount
|
|
35154
|
+
});
|
|
35155
|
+
logger.info("withdraw call", withdrawCall);
|
|
35156
|
+
calls.push(withdrawCall);
|
|
35157
|
+
return {
|
|
35158
|
+
calls,
|
|
35159
|
+
status
|
|
35160
|
+
};
|
|
34226
35161
|
} catch (err) {
|
|
34227
35162
|
logger.error(`error handling withdrawal: ${err}`);
|
|
34228
|
-
return
|
|
35163
|
+
return {
|
|
35164
|
+
calls: [],
|
|
35165
|
+
status: false
|
|
35166
|
+
};
|
|
34229
35167
|
}
|
|
34230
35168
|
}
|
|
34231
35169
|
async getAUM() {
|
|
@@ -34273,7 +35211,7 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34273
35211
|
};
|
|
34274
35212
|
}
|
|
34275
35213
|
};
|
|
34276
|
-
function getLooperSettings2(lstSymbol, underlyingSymbol, vaultSettings, pool1, extendedBackendUrl, extendedApiKey, vaultIdExtended) {
|
|
35214
|
+
function getLooperSettings2(lstSymbol, underlyingSymbol, vaultSettings, pool1, extendedBackendUrl, extendedApiKey, vaultIdExtended, minimumExtendedMovementAmount, minimumVesuMovementAmount, minimumExtendedRetriesDelayForOrderStatus, minimumExtendedPriceDifferenceForSwapOpen, maximumExtendedPriceDifferenceForSwapClosing) {
|
|
34277
35215
|
vaultSettings.leafAdapters = [];
|
|
34278
35216
|
const wbtcToken = Global.getDefaultTokens().find(
|
|
34279
35217
|
(token) => token.symbol === lstSymbol
|
|
@@ -34297,7 +35235,9 @@ function getLooperSettings2(lstSymbol, underlyingSymbol, vaultSettings, pool1, e
|
|
|
34297
35235
|
...baseAdapterConfig,
|
|
34298
35236
|
avnuContract: AVNU_MIDDLEWARE,
|
|
34299
35237
|
slippage: 0.01,
|
|
34300
|
-
baseUrl: AVNU_QUOTE_URL
|
|
35238
|
+
baseUrl: AVNU_QUOTE_URL,
|
|
35239
|
+
minimumExtendedPriceDifferenceForSwapOpen,
|
|
35240
|
+
maximumExtendedPriceDifferenceForSwapClosing
|
|
34301
35241
|
});
|
|
34302
35242
|
const extendedAdapter = new ExtendedAdapter({
|
|
34303
35243
|
...baseAdapterConfig,
|
|
@@ -34313,7 +35253,10 @@ function getLooperSettings2(lstSymbol, underlyingSymbol, vaultSettings, pool1, e
|
|
|
34313
35253
|
extendedBaseUrl: "https://api.starknet.extended.exchange",
|
|
34314
35254
|
extendedMarketName: "BTC-USD",
|
|
34315
35255
|
extendedPrecision: 5,
|
|
34316
|
-
avnuAdapter
|
|
35256
|
+
avnuAdapter,
|
|
35257
|
+
retryDelayForOrderStatus: minimumExtendedRetriesDelayForOrderStatus ?? 3e3,
|
|
35258
|
+
minimumExtendedMovementAmount: minimumExtendedMovementAmount ?? 5
|
|
35259
|
+
//5 usdcs
|
|
34317
35260
|
});
|
|
34318
35261
|
const vesuMultiplyAdapter = new VesuMultiplyAdapter({
|
|
34319
35262
|
poolId: pool1,
|
|
@@ -34326,7 +35269,9 @@ function getLooperSettings2(lstSymbol, underlyingSymbol, vaultSettings, pool1, e
|
|
|
34326
35269
|
supportedPositions: [
|
|
34327
35270
|
{ asset: wbtcToken, isDebt: false },
|
|
34328
35271
|
{ asset: usdcToken, isDebt: true }
|
|
34329
|
-
]
|
|
35272
|
+
],
|
|
35273
|
+
minimumVesuMovementAmount: minimumVesuMovementAmount ?? 5
|
|
35274
|
+
//5 usdc
|
|
34330
35275
|
});
|
|
34331
35276
|
const unusedBalanceAdapter = new UnusedBalanceAdapter({
|
|
34332
35277
|
...baseAdapterConfig
|
|
@@ -34359,6 +35304,7 @@ function getLooperSettings2(lstSymbol, underlyingSymbol, vaultSettings, pool1, e
|
|
|
34359
35304
|
() => vesuMultiplyAdapter.getWithdrawLeaf()
|
|
34360
35305
|
);
|
|
34361
35306
|
vaultSettings.leafAdapters.push(() => extendedAdapter.getDepositLeaf());
|
|
35307
|
+
vaultSettings.leafAdapters.push(() => extendedAdapter.getSwapFromLegacyLeaf());
|
|
34362
35308
|
vaultSettings.leafAdapters.push(() => avnuAdapter.getDepositLeaf());
|
|
34363
35309
|
vaultSettings.leafAdapters.push(() => avnuAdapter.getWithdrawLeaf());
|
|
34364
35310
|
vaultSettings.leafAdapters.push(
|
|
@@ -34421,11 +35367,11 @@ function VaultDescription2(lstSymbol, underlyingSymbol) {
|
|
|
34421
35367
|
] });
|
|
34422
35368
|
}
|
|
34423
35369
|
var re7UsdcPrimeDevansh = {
|
|
34424
|
-
vaultAddress: ContractAddr.from("
|
|
34425
|
-
manager: ContractAddr.from("
|
|
34426
|
-
vaultAllocator: ContractAddr.from("
|
|
34427
|
-
redeemRequestNFT: ContractAddr.from("
|
|
34428
|
-
aumOracle: ContractAddr.from("
|
|
35370
|
+
vaultAddress: ContractAddr.from("0x7efaff77601813ca674c1ffe0479fc0361c0f5099f64a67d4793b80382750c2"),
|
|
35371
|
+
manager: ContractAddr.from("0x2579342f53fbf2f775b0c71d24f162aaf1d3e466edea09a6c51e77a95bd986d"),
|
|
35372
|
+
vaultAllocator: ContractAddr.from("0x46ee6073484a669631e8f88b9f357b0b073cee1bc47752fc32453dd6c1efd7b"),
|
|
35373
|
+
redeemRequestNFT: ContractAddr.from("0x1d66120b0a76068454ea36276d9f404b0a980083dcaebbf6d9f4ad154a79dbe"),
|
|
35374
|
+
aumOracle: ContractAddr.from("0x419a5e8b5a1fe5b2586e64409d5cfdb1712791aaa9361264730227563d4e140"),
|
|
34429
35375
|
leafAdapters: [],
|
|
34430
35376
|
adapters: [],
|
|
34431
35377
|
targetHealthFactor: 1.4,
|
|
@@ -34440,12 +35386,12 @@ var re7UsdcPrimeDevansh = {
|
|
|
34440
35386
|
borrowable_assets: [Global.getDefaultTokens().find((token) => token.symbol === "WBTC")],
|
|
34441
35387
|
minimumWBTCDifferenceForAvnuSwap: MINIMUM_WBTC_DIFFERENCE_FOR_AVNU_SWAP
|
|
34442
35388
|
};
|
|
34443
|
-
var VesuExtendedTestStrategies = (extendedBackendUrl, extendedApiKey, vaultIdExtended) => {
|
|
35389
|
+
var VesuExtendedTestStrategies = (extendedBackendUrl, extendedApiKey, vaultIdExtended, minimumExtendedMovementAmount, minimumVesuMovementAmount, minimumExtendedRetriesDelayForOrderStatus, minimumExtendedPriceDifferenceForSwapOpen, maximumExtendedPriceDifferenceForSwapClosing) => {
|
|
34444
35390
|
return [
|
|
34445
|
-
getStrategySettingsVesuExtended("WBTC", "USDC", re7UsdcPrimeDevansh, false, false, extendedBackendUrl, extendedApiKey, vaultIdExtended)
|
|
35391
|
+
getStrategySettingsVesuExtended("WBTC", "USDC", re7UsdcPrimeDevansh, false, false, extendedBackendUrl, extendedApiKey, vaultIdExtended, minimumExtendedMovementAmount, minimumVesuMovementAmount, minimumExtendedRetriesDelayForOrderStatus, minimumExtendedPriceDifferenceForSwapOpen, maximumExtendedPriceDifferenceForSwapClosing)
|
|
34446
35392
|
];
|
|
34447
35393
|
};
|
|
34448
|
-
function getStrategySettingsVesuExtended(lstSymbol, underlyingSymbol, addresses, isPreview = false, isLST, extendedBackendUrl, extendedApiKey, vaultIdExtended) {
|
|
35394
|
+
function getStrategySettingsVesuExtended(lstSymbol, underlyingSymbol, addresses, isPreview = false, isLST, extendedBackendUrl, extendedApiKey, vaultIdExtended, minimumExtendedMovementAmount, minimumVesuMovementAmount, minimumExtendedRetriesDelayForOrderStatus, minimumExtendedPriceDifferenceForSwapOpen, maximumExtendedPriceDifferenceForSwapClosing) {
|
|
34449
35395
|
return {
|
|
34450
35396
|
name: `Extended Test ${underlyingSymbol}`,
|
|
34451
35397
|
description: getDescription2(lstSymbol, underlyingSymbol),
|
|
@@ -34453,7 +35399,7 @@ function getStrategySettingsVesuExtended(lstSymbol, underlyingSymbol, addresses,
|
|
|
34453
35399
|
launchBlock: 0,
|
|
34454
35400
|
type: "Other",
|
|
34455
35401
|
depositTokens: [Global.getDefaultTokens().find((token) => token.symbol === underlyingSymbol)],
|
|
34456
|
-
additionalInfo: getLooperSettings2(lstSymbol, underlyingSymbol, addresses, VesuPools.Re7USDCPrime, extendedBackendUrl, extendedApiKey, vaultIdExtended),
|
|
35402
|
+
additionalInfo: getLooperSettings2(lstSymbol, underlyingSymbol, addresses, VesuPools.Re7USDCPrime, extendedBackendUrl, extendedApiKey, vaultIdExtended, minimumExtendedMovementAmount, minimumVesuMovementAmount, minimumExtendedRetriesDelayForOrderStatus, minimumExtendedPriceDifferenceForSwapOpen, maximumExtendedPriceDifferenceForSwapClosing),
|
|
34457
35403
|
risk: {
|
|
34458
35404
|
riskFactor: _riskFactor3,
|
|
34459
35405
|
netRisk: _riskFactor3.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor3.reduce((acc, curr) => acc + curr.weight, 0),
|
|
@@ -38169,6 +39115,7 @@ export {
|
|
|
38169
39115
|
OrderType,
|
|
38170
39116
|
PRICE_ROUTER,
|
|
38171
39117
|
PositionSide,
|
|
39118
|
+
PositionTypeAvnuExtended,
|
|
38172
39119
|
Pragma,
|
|
38173
39120
|
Pricer,
|
|
38174
39121
|
PricerBase,
|