@strkfarm/sdk 2.0.0-dev.22 → 2.0.0-dev.23
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 +867 -246
- package/dist/index.browser.mjs +793 -172
- package/dist/index.d.ts +15 -2
- package/dist/index.js +794 -172
- package/dist/index.mjs +793 -172
- package/package.json +1 -1
- package/src/strategies/universal-adapters/avnu-adapter.ts +2 -1
- package/src/strategies/vesu-extended-strategy/services/operationService.ts +1 -0
- package/src/strategies/vesu-extended-strategy/utils/helper.ts +32 -2
- package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +1101 -327
package/dist/index.browser.mjs
CHANGED
|
@@ -28566,14 +28566,14 @@ var calculateExposureDelta = (exposure_extended, exposure_vesu) => {
|
|
|
28566
28566
|
var calculateBTCPriceDelta = (btcPrice, lastBtcPrice) => {
|
|
28567
28567
|
return (btcPrice - lastBtcPrice) / lastBtcPrice * 100;
|
|
28568
28568
|
};
|
|
28569
|
-
var calculateVesUPositionSizeGivenExtended = (extendedPositonValue, extendedHoldingAmount, collateralAmount, collateralPrice) => {
|
|
28569
|
+
var calculateVesUPositionSizeGivenExtended = (extendedPositonValue, extendedHoldingAmount, collateralAmount, collateralPrice, vesuDebtAmountToBeRepaid) => {
|
|
28570
28570
|
const extendedLeverage = calculateExtendedLevergae();
|
|
28571
28571
|
const vesuLeverage = calculateVesuLeverage();
|
|
28572
28572
|
const extendedAmount = extendedHoldingAmount;
|
|
28573
28573
|
const extendedAmountInBTC = extendedAmount.dividedBy(collateralPrice);
|
|
28574
28574
|
const numerator1 = extendedAmount.multipliedBy(extendedLeverage).plus(extendedPositonValue);
|
|
28575
28575
|
const numerator2 = collateralAmount.multipliedBy(collateralPrice).multipliedBy(-1);
|
|
28576
|
-
const vesuAmountInUsd = numerator1.plus(numerator2).dividedBy(vesuLeverage);
|
|
28576
|
+
const vesuAmountInUsd = numerator1.plus(numerator2).dividedBy(vesuLeverage).plus(vesuDebtAmountToBeRepaid);
|
|
28577
28577
|
const vesuAmountInBTC = vesuAmountInUsd.dividedBy(collateralPrice).toFixed(WBTC_TOKEN_DECIMALS);
|
|
28578
28578
|
return {
|
|
28579
28579
|
vesuAmountInUsd: vesuAmountInUsd.toFixed(2),
|
|
@@ -28581,6 +28581,17 @@ var calculateVesUPositionSizeGivenExtended = (extendedPositonValue, extendedHold
|
|
|
28581
28581
|
extendedAmountInBTC
|
|
28582
28582
|
};
|
|
28583
28583
|
};
|
|
28584
|
+
var calculateDeltaDebtAmount = (maxLtv = MAX_LTV_BTC_USDC, existingVesuCollateral, existingVesuDebt, collateralPrice, debtPrice, targetHf = TARGET_HF) => {
|
|
28585
|
+
try {
|
|
28586
|
+
const term1 = existingVesuCollateral.multipliedBy(collateralPrice).multipliedBy(maxLtv).dividedBy(targetHf);
|
|
28587
|
+
const term2 = existingVesuDebt.multipliedBy(debtPrice).multipliedBy(targetHf).multipliedBy(-1);
|
|
28588
|
+
const debtAmountToBeRepaid = term1.plus(term2).dividedBy(targetHf);
|
|
28589
|
+
return debtAmountToBeRepaid;
|
|
28590
|
+
} catch (err) {
|
|
28591
|
+
logger.error(`error calculating delta position: ${err}`);
|
|
28592
|
+
return null;
|
|
28593
|
+
}
|
|
28594
|
+
};
|
|
28584
28595
|
|
|
28585
28596
|
// src/utils/health-factor-math.ts
|
|
28586
28597
|
var HealthFactorMath = class {
|
|
@@ -30648,6 +30659,8 @@ var AvnuAdapter = class _AvnuAdapter extends BaseAdapter {
|
|
|
30648
30659
|
quote,
|
|
30649
30660
|
vaultAllocator.address
|
|
30650
30661
|
);
|
|
30662
|
+
const dataObject = quote;
|
|
30663
|
+
logger.info(`${_AvnuAdapter.name}::getQuotesAvnu finalAmountOfWbtcOut : ${dataObject.avnuFees} ${parseInt(dataObject.buyAmount.toString(), 16)} ${parseInt(dataObject.sellAmount.toString(), 16)} ${parseInt(dataObject.sellAmount.toString(), 16)}`);
|
|
30651
30664
|
const swapCallData = getCalldata[0];
|
|
30652
30665
|
const amount = uint25614.bnToUint256(quote.sellAmountInUsd * 10 ** 7);
|
|
30653
30666
|
return [
|
|
@@ -34394,11 +34407,17 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34394
34407
|
WALLET_ADDRESS,
|
|
34395
34408
|
usdceToken.decimals
|
|
34396
34409
|
);
|
|
34397
|
-
logger.info(
|
|
34410
|
+
logger.info(
|
|
34411
|
+
`${_VesuExtendedMultiplierStrategy.name}::moveAssetsToVaultAllocator walletBalance: ${walletBalance}`
|
|
34412
|
+
);
|
|
34398
34413
|
const amountToBeTransferred = amount.minimum(walletBalance);
|
|
34399
|
-
logger.info(
|
|
34414
|
+
logger.info(
|
|
34415
|
+
`${_VesuExtendedMultiplierStrategy.name}::moveAssetsToVaultAllocator amountToBeTransferred: ${amountToBeTransferred.toNumber()}`
|
|
34416
|
+
);
|
|
34400
34417
|
if (amountToBeTransferred.lessThan(0)) {
|
|
34401
|
-
logger.error(
|
|
34418
|
+
logger.error(
|
|
34419
|
+
`${_VesuExtendedMultiplierStrategy.name}::moveAssetsToVaultAllocator amountToBeTransferred is less than 0: ${amountToBeTransferred.toNumber()}`
|
|
34420
|
+
);
|
|
34402
34421
|
return {
|
|
34403
34422
|
calls: [],
|
|
34404
34423
|
status: false
|
|
@@ -34436,10 +34455,14 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34436
34455
|
}
|
|
34437
34456
|
async shouldInvest() {
|
|
34438
34457
|
try {
|
|
34439
|
-
logger.info(
|
|
34458
|
+
logger.info(
|
|
34459
|
+
`${_VesuExtendedMultiplierStrategy.name}::shouldInvest starting`
|
|
34460
|
+
);
|
|
34440
34461
|
const vesuAdapter = await this.getVesuAdapter();
|
|
34441
34462
|
const extendedAdapter = await this.getExtendedAdapter();
|
|
34442
|
-
logger.info(
|
|
34463
|
+
logger.info(
|
|
34464
|
+
`${_VesuExtendedMultiplierStrategy.name}::shouldInvest adapters fetched: vesuAdapter=${!!vesuAdapter}, extendedAdapter=${!!extendedAdapter}, extendedAdapter.client=${!!extendedAdapter?.client}`
|
|
34465
|
+
);
|
|
34443
34466
|
if (!vesuAdapter) {
|
|
34444
34467
|
logger.error(
|
|
34445
34468
|
`Vesu adapter not configured in metadata. This is a configuration issue, not a temporary failure.`
|
|
@@ -34451,7 +34474,8 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34451
34474
|
extendedLeverage: 0,
|
|
34452
34475
|
collateralPrice: 0,
|
|
34453
34476
|
debtPrice: 0,
|
|
34454
|
-
vesuLeverage: 0
|
|
34477
|
+
vesuLeverage: 0,
|
|
34478
|
+
debtAmountToBeRepaid: new Web3Number(0, 0)
|
|
34455
34479
|
};
|
|
34456
34480
|
}
|
|
34457
34481
|
if (!extendedAdapter) {
|
|
@@ -34465,7 +34489,8 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34465
34489
|
extendedLeverage: 0,
|
|
34466
34490
|
collateralPrice: 0,
|
|
34467
34491
|
debtPrice: 0,
|
|
34468
|
-
vesuLeverage: 0
|
|
34492
|
+
vesuLeverage: 0,
|
|
34493
|
+
debtAmountToBeRepaid: new Web3Number(0, 0)
|
|
34469
34494
|
};
|
|
34470
34495
|
}
|
|
34471
34496
|
if (!extendedAdapter.client) {
|
|
@@ -34479,10 +34504,13 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34479
34504
|
extendedLeverage: 0,
|
|
34480
34505
|
collateralPrice: 0,
|
|
34481
34506
|
debtPrice: 0,
|
|
34482
|
-
vesuLeverage: 0
|
|
34507
|
+
vesuLeverage: 0,
|
|
34508
|
+
debtAmountToBeRepaid: new Web3Number(0, 0)
|
|
34483
34509
|
};
|
|
34484
34510
|
}
|
|
34485
|
-
logger.info(
|
|
34511
|
+
logger.info(
|
|
34512
|
+
`${_VesuExtendedMultiplierStrategy.name}::shouldInvest calling getUnusedBalance`
|
|
34513
|
+
);
|
|
34486
34514
|
const balance = await this.getUnusedBalance();
|
|
34487
34515
|
if (!Number.isFinite(balance.usdValue) || balance.usdValue < 0) {
|
|
34488
34516
|
logger.error(
|
|
@@ -34495,13 +34523,18 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34495
34523
|
extendedLeverage: 0,
|
|
34496
34524
|
collateralPrice: 0,
|
|
34497
34525
|
debtPrice: 0,
|
|
34498
|
-
vesuLeverage: 0
|
|
34526
|
+
vesuLeverage: 0,
|
|
34527
|
+
debtAmountToBeRepaid: new Web3Number(0, 0)
|
|
34499
34528
|
};
|
|
34500
34529
|
}
|
|
34501
|
-
logger.info(
|
|
34530
|
+
logger.info(
|
|
34531
|
+
`${_VesuExtendedMultiplierStrategy.name}::shouldInvest balance: ${balance.usdValue}`
|
|
34532
|
+
);
|
|
34502
34533
|
const usdcBalanceOnExtended = await extendedAdapter.getExtendedDepositAmount();
|
|
34503
34534
|
if (usdcBalanceOnExtended) {
|
|
34504
|
-
const availableForWithdrawal = parseFloat(
|
|
34535
|
+
const availableForWithdrawal = parseFloat(
|
|
34536
|
+
usdcBalanceOnExtended.availableForWithdrawal
|
|
34537
|
+
);
|
|
34505
34538
|
if (!Number.isFinite(availableForWithdrawal) || availableForWithdrawal < 0) {
|
|
34506
34539
|
logger.error(
|
|
34507
34540
|
`Invalid usdcBalanceOnExtended.availableForWithdrawal: ${usdcBalanceOnExtended.availableForWithdrawal}. Expected a finite, non-negative number.`
|
|
@@ -34513,11 +34546,15 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34513
34546
|
extendedLeverage: 0,
|
|
34514
34547
|
collateralPrice: 0,
|
|
34515
34548
|
debtPrice: 0,
|
|
34516
|
-
vesuLeverage: 0
|
|
34549
|
+
vesuLeverage: 0,
|
|
34550
|
+
debtAmountToBeRepaid: new Web3Number(0, 0)
|
|
34517
34551
|
};
|
|
34518
34552
|
}
|
|
34519
34553
|
}
|
|
34520
|
-
const amountToInvest = new Web3Number(
|
|
34554
|
+
const amountToInvest = new Web3Number(
|
|
34555
|
+
balance.usdValue,
|
|
34556
|
+
USDC_TOKEN_DECIMALS
|
|
34557
|
+
).plus(usdcBalanceOnExtended?.availableForTrade ?? 0).multipliedBy(1 - LIMIT_BALANCE);
|
|
34521
34558
|
const amountToInvestNumber = amountToInvest.toNumber();
|
|
34522
34559
|
if (!Number.isFinite(amountToInvestNumber)) {
|
|
34523
34560
|
logger.error(
|
|
@@ -34530,10 +34567,13 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34530
34567
|
extendedLeverage: 0,
|
|
34531
34568
|
collateralPrice: 0,
|
|
34532
34569
|
debtPrice: 0,
|
|
34533
|
-
vesuLeverage: 0
|
|
34570
|
+
vesuLeverage: 0,
|
|
34571
|
+
debtAmountToBeRepaid: new Web3Number(0, 0)
|
|
34534
34572
|
};
|
|
34535
34573
|
}
|
|
34536
|
-
logger.info(
|
|
34574
|
+
logger.info(
|
|
34575
|
+
`${_VesuExtendedMultiplierStrategy.name}::shouldInvest amountToInvest: ${amountToInvestNumber}`
|
|
34576
|
+
);
|
|
34537
34577
|
if (amountToInvest.lessThan(LIMIT_BALANCE_VALUE)) {
|
|
34538
34578
|
return {
|
|
34539
34579
|
shouldInvest: false,
|
|
@@ -34542,7 +34582,8 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34542
34582
|
extendedLeverage: 0,
|
|
34543
34583
|
collateralPrice: 0,
|
|
34544
34584
|
debtPrice: 0,
|
|
34545
|
-
vesuLeverage: 0
|
|
34585
|
+
vesuLeverage: 0,
|
|
34586
|
+
debtAmountToBeRepaid: new Web3Number(0, 0)
|
|
34546
34587
|
};
|
|
34547
34588
|
}
|
|
34548
34589
|
const extendedPositon = await extendedAdapter.getAllOpenPositions();
|
|
@@ -34555,14 +34596,12 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34555
34596
|
extendedLeverage: 0,
|
|
34556
34597
|
collateralPrice: 0,
|
|
34557
34598
|
debtPrice: 0,
|
|
34558
|
-
vesuLeverage: 0
|
|
34599
|
+
vesuLeverage: 0,
|
|
34600
|
+
debtAmountToBeRepaid: new Web3Number(0, 0)
|
|
34559
34601
|
};
|
|
34560
34602
|
}
|
|
34561
|
-
const { collateralTokenAmount } = await vesuAdapter.vesuAdapter.getAssetPrices();
|
|
34562
|
-
const {
|
|
34563
|
-
collateralPrice,
|
|
34564
|
-
debtPrice
|
|
34565
|
-
} = await this.getAssetPrices();
|
|
34603
|
+
const { collateralTokenAmount, debtTokenAmount } = await vesuAdapter.vesuAdapter.getAssetPrices();
|
|
34604
|
+
const { collateralPrice, debtPrice } = await this.getAssetPrices();
|
|
34566
34605
|
if (!Number.isFinite(collateralPrice.price) || collateralPrice.price <= 0) {
|
|
34567
34606
|
logger.error(
|
|
34568
34607
|
`Invalid collateralPrice: ${collateralPrice.price}. Expected a finite, positive number.`
|
|
@@ -34574,7 +34613,8 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34574
34613
|
extendedLeverage: 0,
|
|
34575
34614
|
collateralPrice: 0,
|
|
34576
34615
|
debtPrice: 0,
|
|
34577
|
-
vesuLeverage: 0
|
|
34616
|
+
vesuLeverage: 0,
|
|
34617
|
+
debtAmountToBeRepaid: new Web3Number(0, 0)
|
|
34578
34618
|
};
|
|
34579
34619
|
}
|
|
34580
34620
|
if (!Number.isFinite(debtPrice.price) || debtPrice.price <= 0) {
|
|
@@ -34588,11 +34628,34 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34588
34628
|
extendedLeverage: 0,
|
|
34589
34629
|
collateralPrice: 0,
|
|
34590
34630
|
debtPrice: 0,
|
|
34591
|
-
vesuLeverage: 0
|
|
34631
|
+
vesuLeverage: 0,
|
|
34632
|
+
debtAmountToBeRepaid: new Web3Number(0, 0)
|
|
34592
34633
|
};
|
|
34593
34634
|
}
|
|
34635
|
+
const debtAmountToBeRepaid = calculateDeltaDebtAmount(
|
|
34636
|
+
MAX_LTV_BTC_USDC,
|
|
34637
|
+
collateralTokenAmount,
|
|
34638
|
+
debtTokenAmount,
|
|
34639
|
+
collateralPrice.price,
|
|
34640
|
+
debtPrice.price,
|
|
34641
|
+
this.metadata.additionalInfo.targetHealthFactor
|
|
34642
|
+
);
|
|
34643
|
+
if (!debtAmountToBeRepaid) {
|
|
34644
|
+
logger.error("error calculating debt amount to be repaid");
|
|
34645
|
+
return {
|
|
34646
|
+
shouldInvest: false,
|
|
34647
|
+
vesuAmount: new Web3Number(0, 0),
|
|
34648
|
+
extendedAmount: new Web3Number(0, 0),
|
|
34649
|
+
extendedLeverage: 0,
|
|
34650
|
+
collateralPrice: 0,
|
|
34651
|
+
debtPrice: 0,
|
|
34652
|
+
vesuLeverage: 0,
|
|
34653
|
+
debtAmountToBeRepaid: new Web3Number(0, 0)
|
|
34654
|
+
};
|
|
34655
|
+
}
|
|
34656
|
+
const amountToInvestAfterRepayingDebt = amountToInvest.minus(debtAmountToBeRepaid);
|
|
34594
34657
|
const { vesu_amount, extended_amount, extended_leverage, vesu_leverage } = await calculateAmountDistribution(
|
|
34595
|
-
|
|
34658
|
+
amountToInvestAfterRepayingDebt.toNumber(),
|
|
34596
34659
|
extendedAdapter.client,
|
|
34597
34660
|
extendedAdapter.config.extendedMarketName,
|
|
34598
34661
|
collateralPrice.price,
|
|
@@ -34611,10 +34674,13 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34611
34674
|
extendedLeverage: 0,
|
|
34612
34675
|
collateralPrice: 0,
|
|
34613
34676
|
debtPrice: 0,
|
|
34614
|
-
vesuLeverage: 0
|
|
34677
|
+
vesuLeverage: 0,
|
|
34678
|
+
debtAmountToBeRepaid: new Web3Number(0, 0)
|
|
34615
34679
|
};
|
|
34616
34680
|
}
|
|
34617
|
-
logger.info(
|
|
34681
|
+
logger.info(
|
|
34682
|
+
`${_VesuExtendedMultiplierStrategy.name}::shouldInvest vesu_amount: ${vesu_amount.toNumber()}, extended_amount: ${extended_amount.toNumber()}`
|
|
34683
|
+
);
|
|
34618
34684
|
return {
|
|
34619
34685
|
shouldInvest: true,
|
|
34620
34686
|
vesuAmount: vesu_amount,
|
|
@@ -34622,7 +34688,8 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34622
34688
|
extendedLeverage: extended_leverage,
|
|
34623
34689
|
vesuLeverage: vesu_leverage,
|
|
34624
34690
|
collateralPrice: collateralPrice.price,
|
|
34625
|
-
debtPrice: debtPrice.price
|
|
34691
|
+
debtPrice: debtPrice.price,
|
|
34692
|
+
debtAmountToBeRepaid
|
|
34626
34693
|
};
|
|
34627
34694
|
} catch (err) {
|
|
34628
34695
|
logger.error(`error deciding invest: ${err}`);
|
|
@@ -34633,7 +34700,8 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34633
34700
|
extendedLeverage: 0,
|
|
34634
34701
|
collateralPrice: 0,
|
|
34635
34702
|
debtPrice: 0,
|
|
34636
|
-
vesuLeverage: 0
|
|
34703
|
+
vesuLeverage: 0,
|
|
34704
|
+
debtAmountToBeRepaid: new Web3Number(0, 0)
|
|
34637
34705
|
};
|
|
34638
34706
|
}
|
|
34639
34707
|
}
|
|
@@ -34656,33 +34724,49 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34656
34724
|
const usdcAmountOnExtendedAvailableForTrade = parseFloat(
|
|
34657
34725
|
extendedHoldings.availableForTrade
|
|
34658
34726
|
);
|
|
34659
|
-
logger.info(
|
|
34727
|
+
logger.info(
|
|
34728
|
+
`${_VesuExtendedMultiplierStrategy.name}::shouldMoveAssets calculating movements - Extended current: ${usdcAmountOnExtendedAvailableForTrade}, Wallet: ${usdcAmountInWallet.toNumber()}, Target Extended: ${extendedAmount.toNumber()}, Target Vesu: ${vesuAmount.toNumber()}`
|
|
34729
|
+
);
|
|
34660
34730
|
let totalExtendedWithdrawal = new Web3Number(0, USDC_TOKEN_DECIMALS);
|
|
34661
34731
|
let totalExtendedDeposit = new Web3Number(0, USDC_TOKEN_DECIMALS);
|
|
34662
34732
|
if (extendedAmount.isNegative() && extendedAmount.abs().greaterThan(extendedAdapter.minimumExtendedMovementAmount)) {
|
|
34663
|
-
totalExtendedWithdrawal = totalExtendedWithdrawal.plus(
|
|
34733
|
+
totalExtendedWithdrawal = totalExtendedWithdrawal.plus(
|
|
34734
|
+
extendedAmount.abs()
|
|
34735
|
+
);
|
|
34664
34736
|
}
|
|
34665
34737
|
const extendedTargetAmount = extendedAmount.abs();
|
|
34666
34738
|
let projectedExtendedBalance = usdcAmountOnExtendedAvailableForTrade;
|
|
34667
34739
|
if (extendedAmount.isNegative()) {
|
|
34668
34740
|
projectedExtendedBalance = projectedExtendedBalance - extendedAmount.abs().toNumber();
|
|
34669
34741
|
}
|
|
34670
|
-
const extendedAmountDifference = extendedTargetAmount.minus(
|
|
34742
|
+
const extendedAmountDifference = extendedTargetAmount.minus(
|
|
34743
|
+
projectedExtendedBalance
|
|
34744
|
+
);
|
|
34671
34745
|
const extendedAmountDifferenceAbs = extendedAmountDifference.abs();
|
|
34672
34746
|
if (extendedAmountDifference.lessThan(0)) {
|
|
34673
|
-
totalExtendedWithdrawal = totalExtendedWithdrawal.plus(
|
|
34747
|
+
totalExtendedWithdrawal = totalExtendedWithdrawal.plus(
|
|
34748
|
+
extendedAmountDifferenceAbs
|
|
34749
|
+
);
|
|
34674
34750
|
} else if (extendedAmountDifference.greaterThan(0)) {
|
|
34675
|
-
totalExtendedDeposit = totalExtendedDeposit.plus(
|
|
34751
|
+
totalExtendedDeposit = totalExtendedDeposit.plus(
|
|
34752
|
+
extendedAmountDifference
|
|
34753
|
+
);
|
|
34676
34754
|
}
|
|
34677
34755
|
const vesuTargetAmount = vesuAmount.abs();
|
|
34678
34756
|
const projectedWalletBalance = usdcAmountInWallet.plus(totalExtendedWithdrawal).minus(totalExtendedDeposit);
|
|
34679
34757
|
let vesuAmountDifference = vesuTargetAmount.minus(projectedWalletBalance);
|
|
34680
34758
|
const vesuAmountDifferenceAbs = vesuAmountDifference.abs();
|
|
34681
|
-
logger.info(
|
|
34759
|
+
logger.info(
|
|
34760
|
+
`${_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()}`
|
|
34761
|
+
);
|
|
34682
34762
|
let transactionResults = [];
|
|
34683
34763
|
if (extendedAmount.isNegative() && extendedAmount.abs().greaterThan(extendedAdapter.minimumExtendedMovementAmount)) {
|
|
34684
34764
|
try {
|
|
34685
|
-
const {
|
|
34765
|
+
const {
|
|
34766
|
+
calls: extendedCalls,
|
|
34767
|
+
status: extendedStatus,
|
|
34768
|
+
transactionMetadata: extendedTransactionMetadata
|
|
34769
|
+
} = await this.moveAssets(
|
|
34686
34770
|
{
|
|
34687
34771
|
to: Protocols.VAULT.name,
|
|
34688
34772
|
from: Protocols.EXTENDED.name,
|
|
@@ -34702,16 +34786,44 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34702
34786
|
}
|
|
34703
34787
|
});
|
|
34704
34788
|
} else {
|
|
34705
|
-
return [
|
|
34789
|
+
return [
|
|
34790
|
+
this.createTransactionResult(
|
|
34791
|
+
[],
|
|
34792
|
+
false,
|
|
34793
|
+
{
|
|
34794
|
+
from: Protocols.EXTENDED.name,
|
|
34795
|
+
to: Protocols.VAULT.name,
|
|
34796
|
+
amount: extendedAmount.abs()
|
|
34797
|
+
},
|
|
34798
|
+
"NONE",
|
|
34799
|
+
"INVESTMENT" /* INVESTMENT */
|
|
34800
|
+
)
|
|
34801
|
+
];
|
|
34706
34802
|
}
|
|
34707
34803
|
} catch (err) {
|
|
34708
34804
|
logger.error(`Failed moving assets to vault: ${err}`);
|
|
34709
|
-
return [
|
|
34805
|
+
return [
|
|
34806
|
+
this.createTransactionResult(
|
|
34807
|
+
[],
|
|
34808
|
+
false,
|
|
34809
|
+
{
|
|
34810
|
+
from: Protocols.EXTENDED.name,
|
|
34811
|
+
to: Protocols.VAULT.name,
|
|
34812
|
+
amount: extendedAmount.abs()
|
|
34813
|
+
},
|
|
34814
|
+
"NONE",
|
|
34815
|
+
"INVESTMENT" /* INVESTMENT */
|
|
34816
|
+
)
|
|
34817
|
+
];
|
|
34710
34818
|
}
|
|
34711
34819
|
}
|
|
34712
34820
|
if (vesuAmount.isNegative() && vesuAmount.abs().greaterThan(vesuAdapter.minimumVesuMovementAmount)) {
|
|
34713
34821
|
try {
|
|
34714
|
-
const {
|
|
34822
|
+
const {
|
|
34823
|
+
calls: vesuCalls,
|
|
34824
|
+
status: vesuStatus,
|
|
34825
|
+
transactionMetadata: vesuTransactionMetadata
|
|
34826
|
+
} = await this.moveAssets(
|
|
34715
34827
|
{
|
|
34716
34828
|
to: Protocols.EXTENDED.name,
|
|
34717
34829
|
from: Protocols.VESU.name,
|
|
@@ -34722,7 +34834,19 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34722
34834
|
vesuAdapter
|
|
34723
34835
|
);
|
|
34724
34836
|
if (!vesuStatus) {
|
|
34725
|
-
return [
|
|
34837
|
+
return [
|
|
34838
|
+
this.createTransactionResult(
|
|
34839
|
+
[],
|
|
34840
|
+
false,
|
|
34841
|
+
{
|
|
34842
|
+
from: Protocols.VESU.name,
|
|
34843
|
+
to: Protocols.EXTENDED.name,
|
|
34844
|
+
amount: vesuAmount.abs()
|
|
34845
|
+
},
|
|
34846
|
+
"NONE",
|
|
34847
|
+
"INVESTMENT" /* INVESTMENT */
|
|
34848
|
+
)
|
|
34849
|
+
];
|
|
34726
34850
|
}
|
|
34727
34851
|
transactionResults.push({
|
|
34728
34852
|
status: vesuStatus,
|
|
@@ -34733,14 +34857,34 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34733
34857
|
}
|
|
34734
34858
|
});
|
|
34735
34859
|
} catch (err) {
|
|
34736
|
-
logger.error(
|
|
34737
|
-
|
|
34860
|
+
logger.error(
|
|
34861
|
+
`Failed moving assets to extended via vault allocator: ${err}`
|
|
34862
|
+
);
|
|
34863
|
+
return [
|
|
34864
|
+
this.createTransactionResult(
|
|
34865
|
+
[],
|
|
34866
|
+
false,
|
|
34867
|
+
{
|
|
34868
|
+
from: Protocols.VESU.name,
|
|
34869
|
+
to: Protocols.EXTENDED.name,
|
|
34870
|
+
amount: vesuAmount.abs()
|
|
34871
|
+
},
|
|
34872
|
+
"NONE",
|
|
34873
|
+
"INVESTMENT" /* INVESTMENT */
|
|
34874
|
+
)
|
|
34875
|
+
];
|
|
34738
34876
|
}
|
|
34739
34877
|
}
|
|
34740
|
-
if (extendedAmountDifferenceAbs.greaterThan(
|
|
34878
|
+
if (extendedAmountDifferenceAbs.greaterThan(
|
|
34879
|
+
extendedAdapter.minimumExtendedMovementAmount
|
|
34880
|
+
)) {
|
|
34741
34881
|
if (extendedAmountDifference.greaterThan(0)) {
|
|
34742
34882
|
try {
|
|
34743
|
-
const {
|
|
34883
|
+
const {
|
|
34884
|
+
calls: extendedCalls,
|
|
34885
|
+
status: extendedStatus,
|
|
34886
|
+
transactionMetadata: extendedTransactionMetadata
|
|
34887
|
+
} = await this.moveAssets(
|
|
34744
34888
|
{
|
|
34745
34889
|
to: Protocols.EXTENDED.name,
|
|
34746
34890
|
from: Protocols.VAULT.name,
|
|
@@ -34757,16 +34901,46 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34757
34901
|
transactionMetadata: extendedTransactionMetadata
|
|
34758
34902
|
});
|
|
34759
34903
|
} else {
|
|
34760
|
-
logger.error(
|
|
34761
|
-
|
|
34904
|
+
logger.error(
|
|
34905
|
+
`Failed to move assets to extended - operation returned false status`
|
|
34906
|
+
);
|
|
34907
|
+
return [
|
|
34908
|
+
this.createTransactionResult(
|
|
34909
|
+
[],
|
|
34910
|
+
false,
|
|
34911
|
+
{
|
|
34912
|
+
from: Protocols.VAULT.name,
|
|
34913
|
+
to: Protocols.EXTENDED.name,
|
|
34914
|
+
amount: extendedAmountDifference
|
|
34915
|
+
},
|
|
34916
|
+
"NONE",
|
|
34917
|
+
"INVESTMENT" /* INVESTMENT */
|
|
34918
|
+
)
|
|
34919
|
+
];
|
|
34762
34920
|
}
|
|
34763
34921
|
} catch (err) {
|
|
34764
34922
|
logger.error(`Failed moving assets to extended: ${err}`);
|
|
34765
|
-
return [
|
|
34923
|
+
return [
|
|
34924
|
+
this.createTransactionResult(
|
|
34925
|
+
[],
|
|
34926
|
+
false,
|
|
34927
|
+
{
|
|
34928
|
+
from: Protocols.VAULT.name,
|
|
34929
|
+
to: Protocols.EXTENDED.name,
|
|
34930
|
+
amount: extendedAmountDifference
|
|
34931
|
+
},
|
|
34932
|
+
"NONE",
|
|
34933
|
+
"INVESTMENT" /* INVESTMENT */
|
|
34934
|
+
)
|
|
34935
|
+
];
|
|
34766
34936
|
}
|
|
34767
34937
|
} else if (extendedAmountDifference.lessThan(0)) {
|
|
34768
34938
|
try {
|
|
34769
|
-
const {
|
|
34939
|
+
const {
|
|
34940
|
+
calls: extendedCalls,
|
|
34941
|
+
status: extendedStatus,
|
|
34942
|
+
transactionMetadata: extendedTransactionMetadata
|
|
34943
|
+
} = await this.moveAssets(
|
|
34770
34944
|
{
|
|
34771
34945
|
to: Protocols.VAULT.name,
|
|
34772
34946
|
from: Protocols.EXTENDED.name,
|
|
@@ -34786,23 +34960,55 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34786
34960
|
}
|
|
34787
34961
|
});
|
|
34788
34962
|
} else {
|
|
34789
|
-
logger.error(
|
|
34790
|
-
|
|
34963
|
+
logger.error(
|
|
34964
|
+
`Failed to withdraw from extended - operation returned false status`
|
|
34965
|
+
);
|
|
34966
|
+
return [
|
|
34967
|
+
this.createTransactionResult(
|
|
34968
|
+
[],
|
|
34969
|
+
false,
|
|
34970
|
+
{
|
|
34971
|
+
from: Protocols.EXTENDED.name,
|
|
34972
|
+
to: Protocols.VAULT.name,
|
|
34973
|
+
amount: extendedAmountDifferenceAbs
|
|
34974
|
+
},
|
|
34975
|
+
"NONE",
|
|
34976
|
+
"INVESTMENT" /* INVESTMENT */
|
|
34977
|
+
)
|
|
34978
|
+
];
|
|
34791
34979
|
}
|
|
34792
34980
|
} catch (err) {
|
|
34793
34981
|
logger.error(`Failed moving assets from extended to vault: ${err}`);
|
|
34794
|
-
return [
|
|
34982
|
+
return [
|
|
34983
|
+
this.createTransactionResult(
|
|
34984
|
+
[],
|
|
34985
|
+
false,
|
|
34986
|
+
{
|
|
34987
|
+
from: Protocols.EXTENDED.name,
|
|
34988
|
+
to: Protocols.VAULT.name,
|
|
34989
|
+
amount: extendedAmountDifferenceAbs
|
|
34990
|
+
},
|
|
34991
|
+
"NONE",
|
|
34992
|
+
"INVESTMENT" /* INVESTMENT */
|
|
34993
|
+
)
|
|
34994
|
+
];
|
|
34795
34995
|
}
|
|
34796
34996
|
}
|
|
34797
34997
|
}
|
|
34798
|
-
if (vesuAmountDifferenceAbs.greaterThan(
|
|
34998
|
+
if (vesuAmountDifferenceAbs.greaterThan(
|
|
34999
|
+
vesuAdapter.minimumVesuMovementAmount
|
|
35000
|
+
)) {
|
|
34799
35001
|
if (vesuAmountDifference.lessThanOrEqualTo(0)) {
|
|
34800
35002
|
logger.warn(
|
|
34801
35003
|
`Vesu amount difference is negative or zero: ${vesuAmountDifference.toNumber()}. Skipping operation.`
|
|
34802
35004
|
);
|
|
34803
35005
|
} else {
|
|
34804
35006
|
try {
|
|
34805
|
-
const {
|
|
35007
|
+
const {
|
|
35008
|
+
calls: vesuCalls,
|
|
35009
|
+
status: vesuStatus,
|
|
35010
|
+
transactionMetadata: vesuTransactionMetadata
|
|
35011
|
+
} = await this.moveAssets(
|
|
34806
35012
|
{
|
|
34807
35013
|
to: Protocols.VAULT.name,
|
|
34808
35014
|
from: Protocols.EXTENDED.name,
|
|
@@ -34813,8 +35019,22 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34813
35019
|
vesuAdapter
|
|
34814
35020
|
);
|
|
34815
35021
|
if (!vesuStatus) {
|
|
34816
|
-
logger.error(
|
|
34817
|
-
|
|
35022
|
+
logger.error(
|
|
35023
|
+
`Failed to move assets to vesu - operation returned false status`
|
|
35024
|
+
);
|
|
35025
|
+
return [
|
|
35026
|
+
this.createTransactionResult(
|
|
35027
|
+
[],
|
|
35028
|
+
false,
|
|
35029
|
+
{
|
|
35030
|
+
from: Protocols.EXTENDED.name,
|
|
35031
|
+
to: Protocols.VAULT.name,
|
|
35032
|
+
amount: vesuAmountDifference
|
|
35033
|
+
},
|
|
35034
|
+
"NONE",
|
|
35035
|
+
"INVESTMENT" /* INVESTMENT */
|
|
35036
|
+
)
|
|
35037
|
+
];
|
|
34818
35038
|
}
|
|
34819
35039
|
transactionResults.push({
|
|
34820
35040
|
status: vesuStatus,
|
|
@@ -34826,14 +35046,38 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34826
35046
|
});
|
|
34827
35047
|
} catch (err) {
|
|
34828
35048
|
logger.error(`Failed moving assets to vault: ${err}`);
|
|
34829
|
-
return [
|
|
35049
|
+
return [
|
|
35050
|
+
this.createTransactionResult(
|
|
35051
|
+
[],
|
|
35052
|
+
false,
|
|
35053
|
+
{
|
|
35054
|
+
from: Protocols.EXTENDED.name,
|
|
35055
|
+
to: Protocols.VAULT.name,
|
|
35056
|
+
amount: vesuAmountDifference
|
|
35057
|
+
},
|
|
35058
|
+
"NONE",
|
|
35059
|
+
"INVESTMENT" /* INVESTMENT */
|
|
35060
|
+
)
|
|
35061
|
+
];
|
|
34830
35062
|
}
|
|
34831
35063
|
}
|
|
34832
35064
|
}
|
|
34833
35065
|
return transactionResults;
|
|
34834
35066
|
} catch (err) {
|
|
34835
35067
|
logger.error(`Failed moving assets to vesu: ${err}`);
|
|
34836
|
-
return [
|
|
35068
|
+
return [
|
|
35069
|
+
this.createTransactionResult(
|
|
35070
|
+
[],
|
|
35071
|
+
false,
|
|
35072
|
+
{
|
|
35073
|
+
from: Protocols.EXTENDED.name,
|
|
35074
|
+
to: Protocols.VAULT.name,
|
|
35075
|
+
amount: new Web3Number(0, USDC_TOKEN_DECIMALS)
|
|
35076
|
+
},
|
|
35077
|
+
"NONE",
|
|
35078
|
+
"INVESTMENT" /* INVESTMENT */
|
|
35079
|
+
)
|
|
35080
|
+
];
|
|
34837
35081
|
}
|
|
34838
35082
|
}
|
|
34839
35083
|
/**
|
|
@@ -34854,7 +35098,18 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34854
35098
|
}
|
|
34855
35099
|
};
|
|
34856
35100
|
}
|
|
34857
|
-
return {
|
|
35101
|
+
return {
|
|
35102
|
+
calls: [],
|
|
35103
|
+
status: false,
|
|
35104
|
+
transactionMetadata: {
|
|
35105
|
+
protocolFrom: "",
|
|
35106
|
+
protocolTo: "",
|
|
35107
|
+
transactionType: "DEPOSIT",
|
|
35108
|
+
usdAmount: "0",
|
|
35109
|
+
status: "FAILED",
|
|
35110
|
+
cycleType
|
|
35111
|
+
}
|
|
35112
|
+
};
|
|
34858
35113
|
}
|
|
34859
35114
|
/**
|
|
34860
35115
|
* This method is used to move assets between protocols
|
|
@@ -34862,7 +35117,7 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34862
35117
|
* @param extendedAdapter - The extended adapter
|
|
34863
35118
|
* @param vesuAdapter - The vesu adapter
|
|
34864
35119
|
* @returns The transaction result
|
|
34865
|
-
* If Extended amount is greater than amount of withdrawal from extended, then we need to open a long position
|
|
35120
|
+
* If Extended amount is greater than amount of withdrawal from extended, then we need to open a long position
|
|
34866
35121
|
* so that the amount of withdrawal from extended is fullfilled
|
|
34867
35122
|
*/
|
|
34868
35123
|
async moveAssets(params, extendedAdapter, vesuAdapter) {
|
|
@@ -34871,18 +35126,28 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34871
35126
|
logger.error(
|
|
34872
35127
|
`Invalid amount for moveAssets: ${params.amount.toNumber()}. Amount must be positive.`
|
|
34873
35128
|
);
|
|
34874
|
-
return this.createTransactionResult(
|
|
35129
|
+
return this.createTransactionResult(
|
|
35130
|
+
[],
|
|
35131
|
+
false,
|
|
35132
|
+
params,
|
|
35133
|
+
"NONE",
|
|
35134
|
+
params.cycleType
|
|
35135
|
+
);
|
|
34875
35136
|
}
|
|
34876
35137
|
const avnuAdapter = await this.getAvnuAdapter();
|
|
34877
35138
|
if (!avnuAdapter) {
|
|
34878
35139
|
logger.error(`avnu adapter not found: ${avnuAdapter}`);
|
|
34879
|
-
return this.createTransactionResult(
|
|
35140
|
+
return this.createTransactionResult(
|
|
35141
|
+
[],
|
|
35142
|
+
false,
|
|
35143
|
+
params,
|
|
35144
|
+
"NONE",
|
|
35145
|
+
params.cycleType
|
|
35146
|
+
);
|
|
34880
35147
|
}
|
|
34881
35148
|
logger.info(`moveAssets params, ${JSON.stringify(params)}`);
|
|
34882
35149
|
const collateralToken = vesuAdapter.config.supportedPositions[0].asset;
|
|
34883
|
-
const {
|
|
34884
|
-
collateralPrice
|
|
34885
|
-
} = await this.getAssetPrices();
|
|
35150
|
+
const { collateralPrice } = await this.getAssetPrices();
|
|
34886
35151
|
if (params.to === Protocols.EXTENDED.name && params.from === Protocols.VAULT.name) {
|
|
34887
35152
|
const proofsInfo = extendedAdapter.getProofs(
|
|
34888
35153
|
true,
|
|
@@ -34895,28 +35160,45 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34895
35160
|
await proofsInfo.callConstructor({ amount: params.amount })
|
|
34896
35161
|
);
|
|
34897
35162
|
calls.push(call);
|
|
34898
|
-
return this.createTransactionResult(
|
|
35163
|
+
return this.createTransactionResult(
|
|
35164
|
+
calls,
|
|
35165
|
+
true,
|
|
35166
|
+
params,
|
|
35167
|
+
"DEPOSIT",
|
|
35168
|
+
params.cycleType
|
|
35169
|
+
);
|
|
34899
35170
|
} else if (params.to === Protocols.VAULT.name && params.from === Protocols.EXTENDED.name) {
|
|
34900
35171
|
const extendedLeverage = calculateExtendedLevergae();
|
|
34901
35172
|
const extendedHoldings = await extendedAdapter.getExtendedDepositAmount();
|
|
34902
35173
|
if (!extendedHoldings) {
|
|
34903
35174
|
logger.error(`error getting extended holdings: ${extendedHoldings}`);
|
|
34904
|
-
return this.createTransactionResult(
|
|
35175
|
+
return this.createTransactionResult(
|
|
35176
|
+
[],
|
|
35177
|
+
false,
|
|
35178
|
+
params,
|
|
35179
|
+
"NONE",
|
|
35180
|
+
params.cycleType
|
|
35181
|
+
);
|
|
34905
35182
|
}
|
|
34906
35183
|
const extendedHoldingAmount = new Web3Number(
|
|
34907
35184
|
extendedHoldings.availableForWithdrawal,
|
|
34908
35185
|
USDC_TOKEN_DECIMALS
|
|
34909
35186
|
);
|
|
34910
|
-
logger.info(
|
|
35187
|
+
logger.info(
|
|
35188
|
+
`${_VesuExtendedMultiplierStrategy.name}::moveAssets extendedHoldingAmount: ${extendedHoldingAmount.toNumber()}`
|
|
35189
|
+
);
|
|
34911
35190
|
if (params.amount.abs().greaterThan(extendedHoldingAmount)) {
|
|
34912
|
-
const leftAmountAfterWithdrawalAmountInAccount = new Web3Number(
|
|
34913
|
-
|
|
35191
|
+
const leftAmountAfterWithdrawalAmountInAccount = new Web3Number(
|
|
35192
|
+
Math.ceil(
|
|
35193
|
+
params.amount.abs().minus(extendedHoldingAmount).toNumber()
|
|
35194
|
+
),
|
|
35195
|
+
USDC_TOKEN_DECIMALS
|
|
35196
|
+
);
|
|
35197
|
+
logger.info(
|
|
35198
|
+
`${_VesuExtendedMultiplierStrategy.name}::moveAssets leftAmountAfterWithdrawalAmountInAccount: ${leftAmountAfterWithdrawalAmountInAccount.toNumber()}`
|
|
35199
|
+
);
|
|
34914
35200
|
let priceOfBTC;
|
|
34915
|
-
const {
|
|
34916
|
-
ask,
|
|
34917
|
-
bid,
|
|
34918
|
-
status
|
|
34919
|
-
} = await extendedAdapter.fetchOrderBookBTCUSDC();
|
|
35201
|
+
const { ask, bid, status } = await extendedAdapter.fetchOrderBookBTCUSDC();
|
|
34920
35202
|
const price = ask.plus(bid).dividedBy(2);
|
|
34921
35203
|
if (status) {
|
|
34922
35204
|
priceOfBTC = price;
|
|
@@ -34939,38 +35221,95 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34939
35221
|
logger.error(`error opening long position: ${openLongPosition}`);
|
|
34940
35222
|
}
|
|
34941
35223
|
const updatedHoldings = await extendedAdapter.getExtendedDepositAmount();
|
|
34942
|
-
if (!updatedHoldings || new Web3Number(
|
|
34943
|
-
|
|
34944
|
-
|
|
35224
|
+
if (!updatedHoldings || new Web3Number(
|
|
35225
|
+
updatedHoldings.availableForWithdrawal,
|
|
35226
|
+
USDC_TOKEN_DECIMALS
|
|
35227
|
+
).lessThan(params.amount.abs())) {
|
|
35228
|
+
logger.error(
|
|
35229
|
+
`Insufficient balance after opening position. Available: ${updatedHoldings?.availableForWithdrawal}, Needed: ${params.amount.abs()}`
|
|
35230
|
+
);
|
|
35231
|
+
return this.createTransactionResult(
|
|
35232
|
+
[],
|
|
35233
|
+
false,
|
|
35234
|
+
params,
|
|
35235
|
+
"NONE",
|
|
35236
|
+
params.cycleType
|
|
35237
|
+
);
|
|
34945
35238
|
}
|
|
34946
35239
|
}
|
|
34947
35240
|
const {
|
|
34948
35241
|
status: withdrawalFromExtendedStatus,
|
|
34949
35242
|
receivedTxnHash: withdrawalFromExtendedTxnHash
|
|
34950
35243
|
} = await extendedAdapter.withdrawFromExtended(params.amount);
|
|
34951
|
-
logger.info(
|
|
35244
|
+
logger.info(
|
|
35245
|
+
`withdrawalFromExtendedStatus: ${withdrawalFromExtendedStatus}, withdrawalFromExtendedTxnHash: ${withdrawalFromExtendedTxnHash}`
|
|
35246
|
+
);
|
|
34952
35247
|
if (withdrawalFromExtendedStatus && withdrawalFromExtendedTxnHash) {
|
|
34953
35248
|
const extendedHoldings2 = await extendedAdapter.getExtendedDepositAmount();
|
|
34954
|
-
logger.info(
|
|
35249
|
+
logger.info(
|
|
35250
|
+
`extendedHoldings after withdrawal ${extendedHoldings2?.availableForWithdrawal}`
|
|
35251
|
+
);
|
|
34955
35252
|
await new Promise((resolve) => setTimeout(resolve, 5e3));
|
|
34956
|
-
const { calls, status } = await this.moveAssetsToVaultAllocator(
|
|
35253
|
+
const { calls, status } = await this.moveAssetsToVaultAllocator(
|
|
35254
|
+
params.amount,
|
|
35255
|
+
extendedAdapter
|
|
35256
|
+
);
|
|
34957
35257
|
if (calls.length > 0 && status) {
|
|
34958
|
-
return this.createTransactionResult(
|
|
35258
|
+
return this.createTransactionResult(
|
|
35259
|
+
calls,
|
|
35260
|
+
true,
|
|
35261
|
+
params,
|
|
35262
|
+
"WITHDRAWAL",
|
|
35263
|
+
params.cycleType
|
|
35264
|
+
);
|
|
34959
35265
|
} else {
|
|
34960
|
-
return this.createTransactionResult(
|
|
35266
|
+
return this.createTransactionResult(
|
|
35267
|
+
[],
|
|
35268
|
+
true,
|
|
35269
|
+
params,
|
|
35270
|
+
"WITHDRAWAL",
|
|
35271
|
+
params.cycleType
|
|
35272
|
+
);
|
|
34961
35273
|
}
|
|
34962
35274
|
} else if (withdrawalFromExtendedStatus && !withdrawalFromExtendedTxnHash) {
|
|
34963
|
-
logger.error(
|
|
34964
|
-
|
|
35275
|
+
logger.error(
|
|
35276
|
+
"withdrawal from extended successful, but funds didn't get transferred to the wallet"
|
|
35277
|
+
);
|
|
35278
|
+
return this.createTransactionResult(
|
|
35279
|
+
[],
|
|
35280
|
+
true,
|
|
35281
|
+
params,
|
|
35282
|
+
"WITHDRAWAL",
|
|
35283
|
+
params.cycleType
|
|
35284
|
+
);
|
|
34965
35285
|
} else {
|
|
34966
35286
|
logger.error("withdrawal from extended failed");
|
|
34967
|
-
return this.createTransactionResult(
|
|
35287
|
+
return this.createTransactionResult(
|
|
35288
|
+
[],
|
|
35289
|
+
false,
|
|
35290
|
+
params,
|
|
35291
|
+
"NONE",
|
|
35292
|
+
params.cycleType
|
|
35293
|
+
);
|
|
34968
35294
|
}
|
|
34969
35295
|
} else if (params.to === Protocols.VAULT.name && params.from === Protocols.VESU.name) {
|
|
34970
|
-
const isPriceDifferenceBetweenAvnuAndExtended = await this.checkPriceDifferenceBetweenAvnuAndExtended(
|
|
35296
|
+
const isPriceDifferenceBetweenAvnuAndExtended = await this.checkPriceDifferenceBetweenAvnuAndExtended(
|
|
35297
|
+
extendedAdapter,
|
|
35298
|
+
vesuAdapter,
|
|
35299
|
+
avnuAdapter,
|
|
35300
|
+
"close" /* CLOSE */
|
|
35301
|
+
);
|
|
34971
35302
|
if (!isPriceDifferenceBetweenAvnuAndExtended) {
|
|
34972
|
-
logger.warn(
|
|
34973
|
-
|
|
35303
|
+
logger.warn(
|
|
35304
|
+
`price difference between avnu and extended doesn't fit the range for close position, ${avnuAdapter.config.maximumExtendedPriceDifferenceForSwapClosing}`
|
|
35305
|
+
);
|
|
35306
|
+
return this.createTransactionResult(
|
|
35307
|
+
[],
|
|
35308
|
+
false,
|
|
35309
|
+
params,
|
|
35310
|
+
"NONE",
|
|
35311
|
+
params.cycleType
|
|
35312
|
+
);
|
|
34974
35313
|
}
|
|
34975
35314
|
const vesuAmountInBTC = new Web3Number(
|
|
34976
35315
|
params.amount.dividedBy(collateralPrice.price).toFixed(WBTC_TOKEN_DECIMALS),
|
|
@@ -34984,19 +35323,41 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34984
35323
|
await proofsInfo.callConstructor({ amount: vesuAmountInBTC })
|
|
34985
35324
|
);
|
|
34986
35325
|
calls.push(call);
|
|
34987
|
-
const swapProofsInfo = avnuAdapter.getProofs(
|
|
35326
|
+
const swapProofsInfo = avnuAdapter.getProofs(
|
|
35327
|
+
false,
|
|
35328
|
+
this.getMerkleTree()
|
|
35329
|
+
);
|
|
34988
35330
|
const swapProofGroups = swapProofsInfo.proofs;
|
|
34989
35331
|
const swapCall = this.getManageCall(
|
|
34990
35332
|
swapProofGroups,
|
|
34991
35333
|
await swapProofsInfo.callConstructor({ amount: vesuAmountInBTC })
|
|
34992
35334
|
);
|
|
34993
35335
|
calls.push(swapCall);
|
|
34994
|
-
return this.createTransactionResult(
|
|
35336
|
+
return this.createTransactionResult(
|
|
35337
|
+
calls,
|
|
35338
|
+
true,
|
|
35339
|
+
params,
|
|
35340
|
+
"WITHDRAWAL",
|
|
35341
|
+
params.cycleType
|
|
35342
|
+
);
|
|
34995
35343
|
} else if (params.to === Protocols.EXTENDED.name && params.from === Protocols.VESU.name) {
|
|
34996
|
-
const isPriceDifferenceBetweenAvnuAndExtended = await this.checkPriceDifferenceBetweenAvnuAndExtended(
|
|
35344
|
+
const isPriceDifferenceBetweenAvnuAndExtended = await this.checkPriceDifferenceBetweenAvnuAndExtended(
|
|
35345
|
+
extendedAdapter,
|
|
35346
|
+
vesuAdapter,
|
|
35347
|
+
avnuAdapter,
|
|
35348
|
+
"close" /* CLOSE */
|
|
35349
|
+
);
|
|
34997
35350
|
if (!isPriceDifferenceBetweenAvnuAndExtended) {
|
|
34998
|
-
logger.warn(
|
|
34999
|
-
|
|
35351
|
+
logger.warn(
|
|
35352
|
+
`price difference between avnu and extended doesn't fit the range for close position, ${avnuAdapter.config.maximumExtendedPriceDifferenceForSwapClosing}`
|
|
35353
|
+
);
|
|
35354
|
+
return this.createTransactionResult(
|
|
35355
|
+
[],
|
|
35356
|
+
false,
|
|
35357
|
+
params,
|
|
35358
|
+
"NONE",
|
|
35359
|
+
params.cycleType
|
|
35360
|
+
);
|
|
35000
35361
|
}
|
|
35001
35362
|
const vesuAmountInBTC = new Web3Number(
|
|
35002
35363
|
params.amount.dividedBy(collateralPrice.price).toNumber(),
|
|
@@ -35010,7 +35371,10 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
35010
35371
|
await proofsInfo.callConstructor({ amount: vesuAmountInBTC })
|
|
35011
35372
|
);
|
|
35012
35373
|
calls.push(call);
|
|
35013
|
-
const swapProofsInfo = avnuAdapter.getProofs(
|
|
35374
|
+
const swapProofsInfo = avnuAdapter.getProofs(
|
|
35375
|
+
false,
|
|
35376
|
+
this.getMerkleTree()
|
|
35377
|
+
);
|
|
35014
35378
|
const swapProofGroups = swapProofsInfo.proofs;
|
|
35015
35379
|
const swapCall = this.getManageCall(
|
|
35016
35380
|
swapProofGroups,
|
|
@@ -35027,21 +35391,61 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
35027
35391
|
await proofsInfoDeposit.callConstructor({ amount: params.amount })
|
|
35028
35392
|
);
|
|
35029
35393
|
calls.push(callDeposit);
|
|
35030
|
-
return this.createTransactionResult(
|
|
35394
|
+
return this.createTransactionResult(
|
|
35395
|
+
calls,
|
|
35396
|
+
true,
|
|
35397
|
+
params,
|
|
35398
|
+
"DEPOSIT",
|
|
35399
|
+
params.cycleType
|
|
35400
|
+
);
|
|
35031
35401
|
}
|
|
35032
|
-
logger.error(
|
|
35033
|
-
|
|
35402
|
+
logger.error(
|
|
35403
|
+
`Unsupported assets movement: ${params.from} to ${params.to}`
|
|
35404
|
+
);
|
|
35405
|
+
return this.createTransactionResult(
|
|
35406
|
+
[],
|
|
35407
|
+
false,
|
|
35408
|
+
params,
|
|
35409
|
+
"NONE",
|
|
35410
|
+
params.cycleType
|
|
35411
|
+
);
|
|
35034
35412
|
} catch (err) {
|
|
35035
35413
|
logger.error(`error moving assets: ${err}`);
|
|
35036
|
-
return this.createTransactionResult(
|
|
35414
|
+
return this.createTransactionResult(
|
|
35415
|
+
[],
|
|
35416
|
+
false,
|
|
35417
|
+
params,
|
|
35418
|
+
"NONE",
|
|
35419
|
+
params.cycleType
|
|
35420
|
+
);
|
|
35037
35421
|
}
|
|
35038
35422
|
}
|
|
35039
35423
|
async handleDeposit() {
|
|
35040
35424
|
try {
|
|
35041
|
-
return this.createTransactionResult(
|
|
35425
|
+
return this.createTransactionResult(
|
|
35426
|
+
[],
|
|
35427
|
+
false,
|
|
35428
|
+
{
|
|
35429
|
+
from: Protocols.VAULT.name,
|
|
35430
|
+
to: Protocols.VAULT.name,
|
|
35431
|
+
amount: new Web3Number(0, 0)
|
|
35432
|
+
},
|
|
35433
|
+
"NONE",
|
|
35434
|
+
"INVESTMENT" /* INVESTMENT */
|
|
35435
|
+
);
|
|
35042
35436
|
} catch (err) {
|
|
35043
35437
|
logger.error(`error handling deposit: ${err}`);
|
|
35044
|
-
return this.createTransactionResult(
|
|
35438
|
+
return this.createTransactionResult(
|
|
35439
|
+
[],
|
|
35440
|
+
false,
|
|
35441
|
+
{
|
|
35442
|
+
from: Protocols.VAULT.name,
|
|
35443
|
+
to: Protocols.VAULT.name,
|
|
35444
|
+
amount: new Web3Number(0, 0)
|
|
35445
|
+
},
|
|
35446
|
+
"NONE",
|
|
35447
|
+
"INVESTMENT" /* INVESTMENT */
|
|
35448
|
+
);
|
|
35045
35449
|
}
|
|
35046
35450
|
}
|
|
35047
35451
|
/**
|
|
@@ -35053,32 +35457,42 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
35053
35457
|
* @returns true if the price difference is within the acceptable range, false otherwise
|
|
35054
35458
|
*/
|
|
35055
35459
|
async checkPriceDifferenceBetweenAvnuAndExtended(extendedAdapter, vesuAdapter, avnuAdapter, positionType) {
|
|
35056
|
-
const {
|
|
35057
|
-
ask,
|
|
35058
|
-
bid
|
|
35059
|
-
} = await extendedAdapter.fetchOrderBookBTCUSDC();
|
|
35460
|
+
const { ask, bid } = await extendedAdapter.fetchOrderBookBTCUSDC();
|
|
35060
35461
|
const price = ask.plus(bid).dividedBy(2);
|
|
35061
35462
|
const btcToken = vesuAdapter.config.supportedPositions[0].asset;
|
|
35062
|
-
const btcPriceAvnu = await avnuAdapter.getPriceOfToken(
|
|
35463
|
+
const btcPriceAvnu = await avnuAdapter.getPriceOfToken(
|
|
35464
|
+
btcToken.address.toString()
|
|
35465
|
+
);
|
|
35063
35466
|
if (!btcPriceAvnu) {
|
|
35064
35467
|
logger.error(`error getting btc price avnu: ${btcPriceAvnu}`);
|
|
35065
35468
|
return false;
|
|
35066
35469
|
}
|
|
35067
35470
|
logger.info(`price: ${price}`);
|
|
35068
35471
|
logger.info(`btcPriceAvnu: ${btcPriceAvnu}`);
|
|
35069
|
-
const priceDifference = new Web3Number(
|
|
35472
|
+
const priceDifference = new Web3Number(
|
|
35473
|
+
price.minus(btcPriceAvnu).toFixed(2),
|
|
35474
|
+
0
|
|
35475
|
+
);
|
|
35070
35476
|
logger.info(`priceDifference: ${priceDifference}`);
|
|
35071
35477
|
if (priceDifference.isNegative()) {
|
|
35072
35478
|
return false;
|
|
35073
35479
|
}
|
|
35074
35480
|
if (positionType === "open" /* OPEN */) {
|
|
35075
|
-
logger.info(
|
|
35076
|
-
|
|
35481
|
+
logger.info(
|
|
35482
|
+
`price difference between avnu and extended for open position: ${priceDifference.toNumber()}, minimumExtendedPriceDifferenceForSwapOpen: ${avnuAdapter.config.minimumExtendedPriceDifferenceForSwapOpen}`
|
|
35483
|
+
);
|
|
35484
|
+
const result = priceDifference.greaterThanOrEqualTo(
|
|
35485
|
+
avnuAdapter.config.minimumExtendedPriceDifferenceForSwapOpen
|
|
35486
|
+
);
|
|
35077
35487
|
logger.info(`result: ${result}`);
|
|
35078
35488
|
return result;
|
|
35079
35489
|
} else {
|
|
35080
|
-
logger.info(
|
|
35081
|
-
|
|
35490
|
+
logger.info(
|
|
35491
|
+
`price difference between avnu and extended for close position: ${priceDifference.toNumber()}, maximumExtendedPriceDifferenceForSwapClosing: ${avnuAdapter.config.maximumExtendedPriceDifferenceForSwapClosing}`
|
|
35492
|
+
);
|
|
35493
|
+
const result = priceDifference.lessThanOrEqualTo(
|
|
35494
|
+
avnuAdapter.config.maximumExtendedPriceDifferenceForSwapClosing
|
|
35495
|
+
);
|
|
35082
35496
|
logger.info(`result: ${result}`);
|
|
35083
35497
|
return result;
|
|
35084
35498
|
}
|
|
@@ -35100,7 +35514,19 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
35100
35514
|
amount: usdcBalanceVaultAllocator.amount
|
|
35101
35515
|
});
|
|
35102
35516
|
calls.push(withdrawCall2);
|
|
35103
|
-
return [
|
|
35517
|
+
return [
|
|
35518
|
+
this.createTransactionResult(
|
|
35519
|
+
calls,
|
|
35520
|
+
true,
|
|
35521
|
+
{
|
|
35522
|
+
from: Protocols.VAULT.name,
|
|
35523
|
+
to: Protocols.NONE.name,
|
|
35524
|
+
amount
|
|
35525
|
+
},
|
|
35526
|
+
"WITHDRAWAL",
|
|
35527
|
+
"WITHDRAWAL" /* WITHDRAWAL */
|
|
35528
|
+
)
|
|
35529
|
+
];
|
|
35104
35530
|
}
|
|
35105
35531
|
const vesuAdapter = await this.getVesuAdapter();
|
|
35106
35532
|
const extendedAdapter = await this.getExtendedAdapter();
|
|
@@ -35109,18 +35535,40 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
35109
35535
|
logger.error(
|
|
35110
35536
|
`vesu or extended adapter not found: vesuAdapter=${vesuAdapter}, extendedAdapter=${extendedAdapter}`
|
|
35111
35537
|
);
|
|
35112
|
-
return [
|
|
35538
|
+
return [
|
|
35539
|
+
this.createTransactionResult(
|
|
35540
|
+
calls,
|
|
35541
|
+
status,
|
|
35542
|
+
{
|
|
35543
|
+
from: Protocols.VAULT.name,
|
|
35544
|
+
to: Protocols.NONE.name,
|
|
35545
|
+
amount
|
|
35546
|
+
},
|
|
35547
|
+
"NONE",
|
|
35548
|
+
"WITHDRAWAL" /* WITHDRAWAL */
|
|
35549
|
+
)
|
|
35550
|
+
];
|
|
35113
35551
|
}
|
|
35114
35552
|
let transactionResults = [];
|
|
35115
35553
|
const { collateralTokenAmount } = await vesuAdapter.vesuAdapter.getAssetPrices();
|
|
35116
|
-
const {
|
|
35117
|
-
collateralPrice
|
|
35118
|
-
} = await this.getAssetPrices();
|
|
35554
|
+
const { collateralPrice } = await this.getAssetPrices();
|
|
35119
35555
|
const extendedPositon = await extendedAdapter.getAllOpenPositions();
|
|
35120
35556
|
if (!extendedPositon) {
|
|
35121
35557
|
status = false;
|
|
35122
35558
|
logger.error("error getting extended position", extendedPositon);
|
|
35123
|
-
return [
|
|
35559
|
+
return [
|
|
35560
|
+
this.createTransactionResult(
|
|
35561
|
+
calls,
|
|
35562
|
+
status,
|
|
35563
|
+
{
|
|
35564
|
+
from: Protocols.VAULT.name,
|
|
35565
|
+
to: Protocols.NONE.name,
|
|
35566
|
+
amount
|
|
35567
|
+
},
|
|
35568
|
+
"NONE",
|
|
35569
|
+
"WITHDRAWAL" /* WITHDRAWAL */
|
|
35570
|
+
)
|
|
35571
|
+
];
|
|
35124
35572
|
}
|
|
35125
35573
|
const amountDistributionForWithdrawal = await calculateAmountDistributionForWithdrawal(
|
|
35126
35574
|
usdcBalanceDifference,
|
|
@@ -35133,11 +35581,27 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
35133
35581
|
logger.error(
|
|
35134
35582
|
`error calculating amount distribution for withdrawal: ${amountDistributionForWithdrawal}`
|
|
35135
35583
|
);
|
|
35136
|
-
return [
|
|
35584
|
+
return [
|
|
35585
|
+
this.createTransactionResult(
|
|
35586
|
+
calls,
|
|
35587
|
+
status,
|
|
35588
|
+
{
|
|
35589
|
+
from: Protocols.VAULT.name,
|
|
35590
|
+
to: Protocols.NONE.name,
|
|
35591
|
+
amount
|
|
35592
|
+
},
|
|
35593
|
+
"NONE",
|
|
35594
|
+
"WITHDRAWAL" /* WITHDRAWAL */
|
|
35595
|
+
)
|
|
35596
|
+
];
|
|
35137
35597
|
}
|
|
35138
35598
|
const { vesu_amount, extended_amount } = amountDistributionForWithdrawal;
|
|
35139
35599
|
if (status && vesu_amount.greaterThan(0)) {
|
|
35140
|
-
const {
|
|
35600
|
+
const {
|
|
35601
|
+
calls: vesuCalls,
|
|
35602
|
+
status: vesuStatus,
|
|
35603
|
+
transactionMetadata: vesuTransactionMetadata
|
|
35604
|
+
} = await this.moveAssets(
|
|
35141
35605
|
{
|
|
35142
35606
|
amount: vesu_amount,
|
|
35143
35607
|
from: Protocols.VESU.name,
|
|
@@ -35155,7 +35619,11 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
35155
35619
|
});
|
|
35156
35620
|
}
|
|
35157
35621
|
if (status && extended_amount.greaterThan(0)) {
|
|
35158
|
-
const {
|
|
35622
|
+
const {
|
|
35623
|
+
calls: extendedCalls,
|
|
35624
|
+
status: extendedStatus,
|
|
35625
|
+
transactionMetadata: extendedTransactionMetadata
|
|
35626
|
+
} = await this.moveAssets(
|
|
35159
35627
|
{
|
|
35160
35628
|
amount: extended_amount,
|
|
35161
35629
|
from: Protocols.EXTENDED.name,
|
|
@@ -35173,8 +35641,22 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
35173
35641
|
transactionMetadata: extendedTransactionMetadata
|
|
35174
35642
|
});
|
|
35175
35643
|
} else {
|
|
35176
|
-
logger.error(
|
|
35177
|
-
|
|
35644
|
+
logger.error(
|
|
35645
|
+
"error moving assets to vault: extendedStatus: ${extendedStatus}"
|
|
35646
|
+
);
|
|
35647
|
+
return [
|
|
35648
|
+
this.createTransactionResult(
|
|
35649
|
+
[],
|
|
35650
|
+
status,
|
|
35651
|
+
{
|
|
35652
|
+
from: Protocols.VAULT.name,
|
|
35653
|
+
to: Protocols.NONE.name,
|
|
35654
|
+
amount
|
|
35655
|
+
},
|
|
35656
|
+
"NONE",
|
|
35657
|
+
"WITHDRAWAL" /* WITHDRAWAL */
|
|
35658
|
+
)
|
|
35659
|
+
];
|
|
35178
35660
|
}
|
|
35179
35661
|
}
|
|
35180
35662
|
const withdrawCall = await this.getBringLiquidityCall({
|
|
@@ -35196,7 +35678,19 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
35196
35678
|
return transactionResults;
|
|
35197
35679
|
} catch (err) {
|
|
35198
35680
|
logger.error(`error handling withdrawal: ${err}`);
|
|
35199
|
-
return [
|
|
35681
|
+
return [
|
|
35682
|
+
this.createTransactionResult(
|
|
35683
|
+
[],
|
|
35684
|
+
false,
|
|
35685
|
+
{
|
|
35686
|
+
from: Protocols.VAULT.name,
|
|
35687
|
+
to: Protocols.NONE.name,
|
|
35688
|
+
amount
|
|
35689
|
+
},
|
|
35690
|
+
"NONE",
|
|
35691
|
+
"WITHDRAWAL" /* WITHDRAWAL */
|
|
35692
|
+
)
|
|
35693
|
+
];
|
|
35200
35694
|
}
|
|
35201
35695
|
}
|
|
35202
35696
|
async getAUM() {
|
|
@@ -35248,8 +35742,12 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
35248
35742
|
const txnsToBeExecuted = txnData.filter((txn) => {
|
|
35249
35743
|
return txn.transactionMetadata.transactionType !== "NONE" && txn.transactionMetadata.protocolFrom !== "" && txn.transactionMetadata.protocolTo !== "";
|
|
35250
35744
|
});
|
|
35251
|
-
const callsToBeExecutedFinal = txnsToBeExecuted.flatMap(
|
|
35252
|
-
|
|
35745
|
+
const callsToBeExecutedFinal = txnsToBeExecuted.flatMap(
|
|
35746
|
+
(txn) => txn.calls
|
|
35747
|
+
);
|
|
35748
|
+
const txnMetadata = txnsToBeExecuted.map(
|
|
35749
|
+
(txn) => txn.transactionMetadata
|
|
35750
|
+
);
|
|
35253
35751
|
return { callsToBeExecutedFinal, txnMetadata };
|
|
35254
35752
|
} catch (err) {
|
|
35255
35753
|
logger.error(`error processing transaction data from SDK: ${err}`);
|
|
@@ -35279,23 +35777,42 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
35279
35777
|
if (!vesuAdapter || !extendedAdapter) {
|
|
35280
35778
|
return new Web3Number(0, 0);
|
|
35281
35779
|
}
|
|
35282
|
-
const extendedFundingRate = new Web3Number(
|
|
35780
|
+
const extendedFundingRate = new Web3Number(
|
|
35781
|
+
(await extendedAdapter.getNetAPY()).toFixed(4),
|
|
35782
|
+
0
|
|
35783
|
+
);
|
|
35283
35784
|
const extendedPositions = await extendedAdapter.getAllOpenPositions();
|
|
35284
35785
|
if (!extendedPositions || extendedPositions.length === 0) {
|
|
35285
35786
|
logger.info(`no extended positions found`);
|
|
35286
35787
|
return new Web3Number(0, 0);
|
|
35287
35788
|
}
|
|
35288
|
-
const extendePositionSizeUSD = new Web3Number(
|
|
35789
|
+
const extendePositionSizeUSD = new Web3Number(
|
|
35790
|
+
extendedPositions[0].value || 0,
|
|
35791
|
+
0
|
|
35792
|
+
);
|
|
35289
35793
|
const vesuPositions = await vesuAdapter.getPositions();
|
|
35290
35794
|
const vesuSupplyApy = vesuPositions[0].apy.apy;
|
|
35291
|
-
const vesuCollateralSizeUSD = new Web3Number(
|
|
35292
|
-
|
|
35795
|
+
const vesuCollateralSizeUSD = new Web3Number(
|
|
35796
|
+
vesuPositions[0].usdValue.toFixed(USDC_TOKEN_DECIMALS),
|
|
35797
|
+
USDC_TOKEN_DECIMALS
|
|
35798
|
+
);
|
|
35799
|
+
const vesuDebtSizeUSD = new Web3Number(
|
|
35800
|
+
vesuPositions[1].usdValue.toFixed(USDC_TOKEN_DECIMALS),
|
|
35801
|
+
USDC_TOKEN_DECIMALS
|
|
35802
|
+
);
|
|
35293
35803
|
const num1 = extendePositionSizeUSD.multipliedBy(extendedFundingRate);
|
|
35294
35804
|
const num22 = vesuCollateralSizeUSD.multipliedBy(vesuSupplyApy);
|
|
35295
35805
|
const num32 = vesuDebtSizeUSD.abs();
|
|
35296
35806
|
const maxBorrowApy = num1.plus(num22).minus(0.1).dividedBy(num32);
|
|
35297
|
-
const vesuMaxBorrowableAmount = await vesuAdapter.vesuAdapter.getMaxBorrowableByInterestRate(
|
|
35298
|
-
|
|
35807
|
+
const vesuMaxBorrowableAmount = await vesuAdapter.vesuAdapter.getMaxBorrowableByInterestRate(
|
|
35808
|
+
this.config,
|
|
35809
|
+
vesuAdapter.config.debt,
|
|
35810
|
+
maxBorrowApy.toNumber()
|
|
35811
|
+
);
|
|
35812
|
+
return new Web3Number(
|
|
35813
|
+
vesuMaxBorrowableAmount.toFixed(USDC_TOKEN_DECIMALS),
|
|
35814
|
+
USDC_TOKEN_DECIMALS
|
|
35815
|
+
);
|
|
35299
35816
|
}
|
|
35300
35817
|
async getVesuHealthFactors() {
|
|
35301
35818
|
const vesuAdapter = await this.getVesuAdapter();
|
|
@@ -35304,18 +35821,33 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
35304
35821
|
return [0, 0];
|
|
35305
35822
|
}
|
|
35306
35823
|
const vesuPositions = await vesuAdapter.getPositions();
|
|
35307
|
-
const vesuCollateralSizeUSD = new Web3Number(
|
|
35308
|
-
|
|
35824
|
+
const vesuCollateralSizeUSD = new Web3Number(
|
|
35825
|
+
vesuPositions[0].usdValue.toFixed(USDC_TOKEN_DECIMALS),
|
|
35826
|
+
0
|
|
35827
|
+
);
|
|
35828
|
+
const vesuDebtSizeUSD = new Web3Number(
|
|
35829
|
+
vesuPositions[1].usdValue.toFixed(USDC_TOKEN_DECIMALS),
|
|
35830
|
+
0
|
|
35831
|
+
);
|
|
35309
35832
|
const actualLtv = vesuDebtSizeUSD.dividedBy(vesuCollateralSizeUSD).abs();
|
|
35310
35833
|
logger.info(`actualLtv: ${actualLtv.toNumber()}`);
|
|
35311
|
-
const maxLtv = new Web3Number(
|
|
35312
|
-
|
|
35834
|
+
const maxLtv = new Web3Number(
|
|
35835
|
+
await vesuAdapter.vesuAdapter.getLTVConfig(this.config),
|
|
35836
|
+
4
|
|
35837
|
+
);
|
|
35838
|
+
const healthFactor = new Web3Number(
|
|
35839
|
+
maxLtv.dividedBy(actualLtv).toFixed(4),
|
|
35840
|
+
4
|
|
35841
|
+
);
|
|
35313
35842
|
logger.info(`healthFactor: ${healthFactor.toNumber()}`);
|
|
35314
35843
|
const extendedBalance = await extendedAdapter.getExtendedDepositAmount();
|
|
35315
35844
|
if (!extendedBalance) {
|
|
35316
35845
|
return [0, 0];
|
|
35317
35846
|
}
|
|
35318
|
-
const extendedLeverage = new Web3Number(
|
|
35847
|
+
const extendedLeverage = new Web3Number(
|
|
35848
|
+
(Number(extendedBalance.marginRatio) * 100).toFixed(4),
|
|
35849
|
+
4
|
|
35850
|
+
);
|
|
35319
35851
|
logger.info(`extendedLeverage: ${extendedLeverage.toNumber()}`);
|
|
35320
35852
|
return [healthFactor.toNumber(), extendedLeverage.toNumber()];
|
|
35321
35853
|
}
|
|
@@ -35336,12 +35868,16 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
35336
35868
|
splits: []
|
|
35337
35869
|
};
|
|
35338
35870
|
}
|
|
35339
|
-
let vesuPositions = allPositions.filter(
|
|
35871
|
+
let vesuPositions = allPositions.filter(
|
|
35872
|
+
(item) => item.protocol === Protocols.VESU
|
|
35873
|
+
);
|
|
35340
35874
|
vesuPositions.map((item) => {
|
|
35341
35875
|
item.apy.apy = item.apy.apy * 0.1;
|
|
35342
35876
|
});
|
|
35343
35877
|
const extendedPositions = await extendedAdapter.getAllOpenPositions();
|
|
35344
|
-
const usdcToken = Global.getDefaultTokens().find(
|
|
35878
|
+
const usdcToken = Global.getDefaultTokens().find(
|
|
35879
|
+
(token) => token.symbol === "USDC"
|
|
35880
|
+
);
|
|
35345
35881
|
if (!extendedPositions || !usdcToken) {
|
|
35346
35882
|
return {
|
|
35347
35883
|
net: 0,
|
|
@@ -35354,7 +35890,10 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
35354
35890
|
const totalHoldingsUSDValue = allPositions.reduce((acc, curr) => acc + curr.usdValue, 0) + Number(extendedEquity);
|
|
35355
35891
|
console.log(totalHoldingsUSDValue);
|
|
35356
35892
|
const extendedPositionSizeMultipliedByApy = Number(extendedPosition.value) * extendedApy;
|
|
35357
|
-
let weightedAPYs = allPositions.reduce(
|
|
35893
|
+
let weightedAPYs = allPositions.reduce(
|
|
35894
|
+
(acc, curr) => acc + curr.apy.apy * curr.usdValue,
|
|
35895
|
+
0
|
|
35896
|
+
) + extendedPositionSizeMultipliedByApy;
|
|
35358
35897
|
console.log(weightedAPYs);
|
|
35359
35898
|
const netAPY = weightedAPYs / totalHoldingsUSDValue;
|
|
35360
35899
|
console.log(netAPY);
|
|
@@ -35368,13 +35907,22 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
35368
35907
|
});
|
|
35369
35908
|
return {
|
|
35370
35909
|
net: netAPY,
|
|
35371
|
-
splits: allPositions.map((p) => ({
|
|
35910
|
+
splits: allPositions.map((p) => ({
|
|
35911
|
+
apy: p.apy.apy,
|
|
35912
|
+
id: p.remarks ?? ""
|
|
35913
|
+
}))
|
|
35372
35914
|
};
|
|
35373
35915
|
}
|
|
35374
35916
|
async getWalletHoldings() {
|
|
35375
|
-
const usdceToken = Global.getDefaultTokens().find(
|
|
35376
|
-
|
|
35377
|
-
|
|
35917
|
+
const usdceToken = Global.getDefaultTokens().find(
|
|
35918
|
+
(token) => token.symbol === "USDCe"
|
|
35919
|
+
);
|
|
35920
|
+
const wbtcToken = Global.getDefaultTokens().find(
|
|
35921
|
+
(token) => token.symbol === "WBTC"
|
|
35922
|
+
);
|
|
35923
|
+
const usdcToken = Global.getDefaultTokens().find(
|
|
35924
|
+
(token) => token.symbol === "USDC"
|
|
35925
|
+
);
|
|
35378
35926
|
if (!usdceToken || !wbtcToken || !usdcToken) {
|
|
35379
35927
|
return [];
|
|
35380
35928
|
}
|
|
@@ -35448,9 +35996,7 @@ function getLooperSettings2(lstSymbol, underlyingSymbol, vaultSettings, pool1, e
|
|
|
35448
35996
|
});
|
|
35449
35997
|
const extendedAdapter = new ExtendedAdapter({
|
|
35450
35998
|
...baseAdapterConfig,
|
|
35451
|
-
supportedPositions: [
|
|
35452
|
-
{ asset: usdcToken, isDebt: true }
|
|
35453
|
-
],
|
|
35999
|
+
supportedPositions: [{ asset: usdcToken, isDebt: true }],
|
|
35454
36000
|
vaultIdExtended,
|
|
35455
36001
|
extendedContract: EXTENDED_CONTRACT,
|
|
35456
36002
|
extendedBackendWriteUrl,
|
|
@@ -35507,11 +36053,11 @@ function getLooperSettings2(lstSymbol, underlyingSymbol, vaultSettings, pool1, e
|
|
|
35507
36053
|
asset: wbtcToken.address
|
|
35508
36054
|
});
|
|
35509
36055
|
vaultSettings.leafAdapters.push(() => vesuMultiplyAdapter.getDepositLeaf());
|
|
36056
|
+
vaultSettings.leafAdapters.push(() => vesuMultiplyAdapter.getWithdrawLeaf());
|
|
36057
|
+
vaultSettings.leafAdapters.push(() => extendedAdapter.getDepositLeaf());
|
|
35510
36058
|
vaultSettings.leafAdapters.push(
|
|
35511
|
-
() =>
|
|
36059
|
+
() => extendedAdapter.getSwapFromLegacyLeaf()
|
|
35512
36060
|
);
|
|
35513
|
-
vaultSettings.leafAdapters.push(() => extendedAdapter.getDepositLeaf());
|
|
35514
|
-
vaultSettings.leafAdapters.push(() => extendedAdapter.getSwapFromLegacyLeaf());
|
|
35515
36061
|
vaultSettings.leafAdapters.push(() => avnuAdapter.getDepositLeaf());
|
|
35516
36062
|
vaultSettings.leafAdapters.push(() => avnuAdapter.getWithdrawLeaf());
|
|
35517
36063
|
vaultSettings.leafAdapters.push(
|
|
@@ -35556,29 +36102,70 @@ function VaultDescription2(lstSymbol, underlyingSymbol) {
|
|
|
35556
36102
|
" to create leverage. Depositors receive vault shares that represent a proportional claim on the underlying assets and accrued yield."
|
|
35557
36103
|
] }),
|
|
35558
36104
|
/* @__PURE__ */ jsxs4("p", { style: { fontSize: "14px", lineHeight: "1.5", marginBottom: "16px" }, children: [
|
|
35559
|
-
"This vault uses Vesu for lending and borrowing. The oracle used by this pool is a
|
|
35560
|
-
|
|
36105
|
+
"This vault uses Vesu for lending and borrowing. The oracle used by this pool is a",
|
|
36106
|
+
" ",
|
|
36107
|
+
highlightTextWithLinks("conversion rate oracle", [
|
|
36108
|
+
{
|
|
36109
|
+
highlight: "conversion rate oracle",
|
|
36110
|
+
link: "https://docs.pragma.build/starknet/development#conversion-rate"
|
|
36111
|
+
}
|
|
36112
|
+
]),
|
|
35561
36113
|
" ",
|
|
35562
36114
|
"which is resilient to liquidity issues and price volatility, hence reducing the risk of liquidation. However, overtime, if left un-monitored, debt can increase enough to trigger a liquidation. But no worries, our continuous monitoring systems look for situations with reduced health factor and balance collateral/debt to bring it back to safe levels. With Troves, you can have a peaceful sleep."
|
|
35563
36115
|
] }),
|
|
35564
|
-
/* @__PURE__ */ jsx5(
|
|
35565
|
-
|
|
35566
|
-
|
|
35567
|
-
|
|
35568
|
-
|
|
35569
|
-
|
|
35570
|
-
|
|
35571
|
-
|
|
35572
|
-
|
|
35573
|
-
|
|
36116
|
+
/* @__PURE__ */ jsx5(
|
|
36117
|
+
"div",
|
|
36118
|
+
{
|
|
36119
|
+
style: {
|
|
36120
|
+
backgroundColor: "#222",
|
|
36121
|
+
padding: "10px",
|
|
36122
|
+
borderRadius: "8px",
|
|
36123
|
+
marginBottom: "20px",
|
|
36124
|
+
border: "1px solid #444"
|
|
36125
|
+
},
|
|
36126
|
+
children: /* @__PURE__ */ jsxs4("p", { style: { fontSize: "13px", color: "#ccc" }, children: [
|
|
36127
|
+
/* @__PURE__ */ jsx5("strong", { children: "Withdrawals:" }),
|
|
36128
|
+
" Requests can take up to",
|
|
36129
|
+
" ",
|
|
36130
|
+
/* @__PURE__ */ jsx5("strong", { children: "1-2 hours" }),
|
|
36131
|
+
" to process as the vault unwinds and settles routing."
|
|
36132
|
+
] })
|
|
36133
|
+
}
|
|
36134
|
+
),
|
|
36135
|
+
/* @__PURE__ */ jsx5(
|
|
36136
|
+
"div",
|
|
36137
|
+
{
|
|
36138
|
+
style: {
|
|
36139
|
+
backgroundColor: "#222",
|
|
36140
|
+
padding: "10px",
|
|
36141
|
+
borderRadius: "8px",
|
|
36142
|
+
marginBottom: "20px",
|
|
36143
|
+
border: "1px solid #444"
|
|
36144
|
+
},
|
|
36145
|
+
children: /* @__PURE__ */ jsxs4("p", { style: { fontSize: "13px", color: "#ccc" }, children: [
|
|
36146
|
+
/* @__PURE__ */ jsx5("strong", { children: "Debt limits:" }),
|
|
36147
|
+
" Pools on Vesu have debt caps that are gradually increased over time. Until caps are raised, deposited Tokens remain in the vault, generating a shared net return for all depositors. There is no additional fee taken by Troves on Yield token's APY, its only on added gain."
|
|
36148
|
+
] })
|
|
36149
|
+
}
|
|
36150
|
+
)
|
|
35574
36151
|
] });
|
|
35575
36152
|
}
|
|
35576
36153
|
var re7UsdcPrimeDevansh = {
|
|
35577
|
-
vaultAddress: ContractAddr.from(
|
|
35578
|
-
|
|
35579
|
-
|
|
35580
|
-
|
|
35581
|
-
|
|
36154
|
+
vaultAddress: ContractAddr.from(
|
|
36155
|
+
"0x058905be22d6a81792df79425dc9641cf3e1b77f36748631b7d7e5d713a32b55"
|
|
36156
|
+
),
|
|
36157
|
+
manager: ContractAddr.from(
|
|
36158
|
+
"0x02648d703783feb2d967cf0520314cb5aa800d69a9426f3e3b317395af44de16"
|
|
36159
|
+
),
|
|
36160
|
+
vaultAllocator: ContractAddr.from(
|
|
36161
|
+
"0x07d533c838eab6a4d854dd3aea96a55993fccd35821921970d00bde946b63b6f"
|
|
36162
|
+
),
|
|
36163
|
+
redeemRequestNFT: ContractAddr.from(
|
|
36164
|
+
"0x01ef91f08fb99729c00f82fc6e0ece37917bcc43952596c19996259dc8adbbba"
|
|
36165
|
+
),
|
|
36166
|
+
aumOracle: ContractAddr.from(
|
|
36167
|
+
"0x030b6acfec162f5d6e72b8a4d2798aedce78fb39de78a8f549f7cd277ae8bc8d"
|
|
36168
|
+
),
|
|
35582
36169
|
leafAdapters: [],
|
|
35583
36170
|
adapters: [],
|
|
35584
36171
|
targetHealthFactor: 1.4,
|
|
@@ -35590,13 +36177,29 @@ var re7UsdcPrimeDevansh = {
|
|
|
35590
36177
|
"0.001",
|
|
35591
36178
|
Global.getDefaultTokens().find((token) => token.symbol === "WBTC").decimals
|
|
35592
36179
|
),
|
|
35593
|
-
borrowable_assets: [
|
|
36180
|
+
borrowable_assets: [
|
|
36181
|
+
Global.getDefaultTokens().find((token) => token.symbol === "WBTC")
|
|
36182
|
+
],
|
|
35594
36183
|
minimumWBTCDifferenceForAvnuSwap: MINIMUM_WBTC_DIFFERENCE_FOR_AVNU_SWAP,
|
|
35595
36184
|
walletAddress: WALLET_ADDRESS
|
|
35596
36185
|
};
|
|
35597
36186
|
var VesuExtendedTestStrategies = (extendedBackendReadUrl, extendedBackendWriteUrl, vaultIdExtended, minimumExtendedMovementAmount, minimumVesuMovementAmount, minimumExtendedRetriesDelayForOrderStatus, minimumExtendedPriceDifferenceForSwapOpen, maximumExtendedPriceDifferenceForSwapClosing) => {
|
|
35598
36187
|
return [
|
|
35599
|
-
getStrategySettingsVesuExtended(
|
|
36188
|
+
getStrategySettingsVesuExtended(
|
|
36189
|
+
"WBTC",
|
|
36190
|
+
"USDC",
|
|
36191
|
+
re7UsdcPrimeDevansh,
|
|
36192
|
+
false,
|
|
36193
|
+
false,
|
|
36194
|
+
extendedBackendReadUrl,
|
|
36195
|
+
extendedBackendWriteUrl,
|
|
36196
|
+
vaultIdExtended,
|
|
36197
|
+
minimumExtendedMovementAmount,
|
|
36198
|
+
minimumVesuMovementAmount,
|
|
36199
|
+
minimumExtendedRetriesDelayForOrderStatus,
|
|
36200
|
+
minimumExtendedPriceDifferenceForSwapOpen,
|
|
36201
|
+
maximumExtendedPriceDifferenceForSwapClosing
|
|
36202
|
+
)
|
|
35600
36203
|
];
|
|
35601
36204
|
};
|
|
35602
36205
|
function getStrategySettingsVesuExtended(lstSymbol, underlyingSymbol, addresses, isPreview = false, isLST, extendedBackendReadUrl, extendedBackendWriteUrl, vaultIdExtended, minimumExtendedMovementAmount, minimumVesuMovementAmount, minimumExtendedRetriesDelayForOrderStatus, minimumExtendedPriceDifferenceForSwapOpen, maximumExtendedPriceDifferenceForSwapClosing) {
|
|
@@ -35606,8 +36209,25 @@ function getStrategySettingsVesuExtended(lstSymbol, underlyingSymbol, addresses,
|
|
|
35606
36209
|
address: addresses.vaultAddress,
|
|
35607
36210
|
launchBlock: 0,
|
|
35608
36211
|
type: "Other",
|
|
35609
|
-
depositTokens: [
|
|
35610
|
-
|
|
36212
|
+
depositTokens: [
|
|
36213
|
+
Global.getDefaultTokens().find(
|
|
36214
|
+
(token) => token.symbol === underlyingSymbol
|
|
36215
|
+
)
|
|
36216
|
+
],
|
|
36217
|
+
additionalInfo: getLooperSettings2(
|
|
36218
|
+
lstSymbol,
|
|
36219
|
+
underlyingSymbol,
|
|
36220
|
+
addresses,
|
|
36221
|
+
VesuPools.Re7USDCPrime,
|
|
36222
|
+
extendedBackendReadUrl,
|
|
36223
|
+
extendedBackendWriteUrl,
|
|
36224
|
+
vaultIdExtended,
|
|
36225
|
+
minimumExtendedMovementAmount,
|
|
36226
|
+
minimumVesuMovementAmount,
|
|
36227
|
+
minimumExtendedRetriesDelayForOrderStatus,
|
|
36228
|
+
minimumExtendedPriceDifferenceForSwapOpen,
|
|
36229
|
+
maximumExtendedPriceDifferenceForSwapClosing
|
|
36230
|
+
),
|
|
35611
36231
|
risk: {
|
|
35612
36232
|
riskFactor: _riskFactor3,
|
|
35613
36233
|
netRisk: _riskFactor3.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor3.reduce((acc, curr) => acc + curr.weight, 0),
|
|
@@ -39365,6 +39985,7 @@ export {
|
|
|
39365
39985
|
calculateBTCPriceDelta,
|
|
39366
39986
|
calculateDebtAmount,
|
|
39367
39987
|
calculateDebtReductionAmountForWithdrawal,
|
|
39988
|
+
calculateDeltaDebtAmount,
|
|
39368
39989
|
calculateExposureDelta,
|
|
39369
39990
|
calculateExtendedLevergae,
|
|
39370
39991
|
calculateVesUPositionSizeGivenExtended,
|