@strkfarm/sdk 2.0.0-dev.28 → 2.0.0-dev.29
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 +1938 -771
- package/dist/index.browser.mjs +1960 -791
- package/dist/index.d.ts +343 -124
- package/dist/index.js +1971 -794
- package/dist/index.mjs +1963 -791
- package/package.json +1 -1
- package/src/dataTypes/bignumber.browser.ts +6 -1
- package/src/dataTypes/bignumber.node.ts +5 -1
- package/src/interfaces/common.tsx +8 -1
- package/src/strategies/universal-adapters/baseAdapter.ts +1 -1
- package/src/strategies/universal-adapters/extended-adapter.ts +7 -7
- package/src/strategies/universal-adapters/index.ts +2 -1
- package/src/strategies/universal-adapters/svk-troves-adapter.ts +364 -0
- package/src/strategies/universal-adapters/vesu-multiply-adapter.ts +88 -34
- package/src/strategies/vesu-extended-strategy/services/executionService.ts +36 -55
- package/src/strategies/vesu-extended-strategy/services/extended-vesu-state-manager.ts +1553 -538
- package/src/strategies/vesu-extended-strategy/services/ltv-imbalance-rebalance-math.ts +730 -0
- package/src/strategies/vesu-extended-strategy/services/operationService.ts +4 -3
- package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +27 -83
- package/src/utils/index.ts +1 -0
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
IncreaseLeverParams,
|
|
27
27
|
DecreaseLeverParams,
|
|
28
28
|
} from "./vesu-adapter";
|
|
29
|
-
import { logger } from "@/utils";
|
|
29
|
+
import { assert, logger } from "@/utils";
|
|
30
30
|
import VesuMultiplyAbi from "@/data/vesu-multiple.abi.json";
|
|
31
31
|
import { EkuboQuote, EkuboQuoter, TokenMarketData } from "@/modules";
|
|
32
32
|
import { calculateDebtReductionAmountForWithdrawal } from "../vesu-extended-strategy/utils/helper";
|
|
@@ -586,6 +586,7 @@ export class VesuMultiplyAdapter extends BaseAdapter<
|
|
|
586
586
|
const collateralToken = this.config.collateral;
|
|
587
587
|
const debtToken = this.config.debt;
|
|
588
588
|
const { contract: multiplyContract } = this._getMultiplyContract();
|
|
589
|
+
this.lastSwapPriceInfo = null;
|
|
589
590
|
|
|
590
591
|
const {
|
|
591
592
|
existingCollateralInfo,
|
|
@@ -628,11 +629,20 @@ export class VesuMultiplyAdapter extends BaseAdapter<
|
|
|
628
629
|
let marginSwapLimitAmount = Web3Number.fromWei(0, collateralToken.decimals);
|
|
629
630
|
let addedCollateral: Web3Number = params.amount;
|
|
630
631
|
let approveAmount: Web3Number = params.amount;
|
|
632
|
+
let aggregatedFromAmount = 0; // e.g. USDC
|
|
633
|
+
let aggregatedToAmount = 0; // e.g. BTC
|
|
634
|
+
let aggregatedFromSymbol: string = debtToken.symbol;
|
|
635
|
+
const aggregatedToSymbol = collateralToken.symbol;
|
|
636
|
+
let executedSwapCount = 0;
|
|
631
637
|
|
|
632
638
|
if (params.marginSwap) {
|
|
633
639
|
const marginToken = params.marginSwap.marginToken;
|
|
634
640
|
const requiredAmount = params.amount;
|
|
635
641
|
|
|
642
|
+
// bcz, last swap price is configured to be common between margin swap and lever swap,
|
|
643
|
+
// hence need same tokens in both
|
|
644
|
+
assert(marginToken.address.eq(debtToken.address), 'Margin token must be the same as debt token');
|
|
645
|
+
|
|
636
646
|
const marginSwapQuote = await ekuboQuoter.getQuoteExactOutput(
|
|
637
647
|
marginToken.address.address,
|
|
638
648
|
collateralToken.address.address,
|
|
@@ -649,6 +659,14 @@ export class VesuMultiplyAdapter extends BaseAdapter<
|
|
|
649
659
|
marginToken,
|
|
650
660
|
collateralToken
|
|
651
661
|
);
|
|
662
|
+
const marginSwapInputAmount = Web3Number
|
|
663
|
+
.fromWei(marginSwapQuote.total_calculated, marginToken.decimals)
|
|
664
|
+
.abs()
|
|
665
|
+
.toNumber();
|
|
666
|
+
const marginSwapOutputAmount = requiredAmount.abs().toNumber();
|
|
667
|
+
aggregatedFromAmount += marginSwapInputAmount;
|
|
668
|
+
aggregatedToAmount += marginSwapOutputAmount;
|
|
669
|
+
executedSwapCount += 1;
|
|
652
670
|
|
|
653
671
|
approveAmount = Web3Number
|
|
654
672
|
.fromWei(marginSwapQuote.total_calculated, marginToken.decimals)
|
|
@@ -680,13 +698,6 @@ export class VesuMultiplyAdapter extends BaseAdapter<
|
|
|
680
698
|
if (!debtAmount.isZero() && debtAmount.greaterThan(0)) {
|
|
681
699
|
try {
|
|
682
700
|
let swapQuote: EkuboQuote;
|
|
683
|
-
const debtAmountInCollateralUnits = new Web3Number(
|
|
684
|
-
debtAmount
|
|
685
|
-
.multipliedBy(debtPrice)
|
|
686
|
-
.dividedBy(collateralPrice)
|
|
687
|
-
.toFixed(6),
|
|
688
|
-
collateralToken.decimals
|
|
689
|
-
);
|
|
690
701
|
if (params.leverSwap?.exactOutput) {
|
|
691
702
|
swapQuote = await ekuboQuoter.getQuoteExactOutput(
|
|
692
703
|
debtToken.address.address,
|
|
@@ -715,19 +726,9 @@ export class VesuMultiplyAdapter extends BaseAdapter<
|
|
|
715
726
|
|
|
716
727
|
const inputAmt = debtAmount.abs().toNumber();
|
|
717
728
|
const outputAmt = quoteOutputAmount;
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
toTokenSymbol: collateralToken.symbol,
|
|
722
|
-
fromAmount: inputAmt,
|
|
723
|
-
toAmount: outputAmt,
|
|
724
|
-
effectivePrice: outputAmt !== 0 ? inputAmt / outputAmt : 0,
|
|
725
|
-
};
|
|
726
|
-
logger.verbose(
|
|
727
|
-
`${VesuMultiplyAdapter.name}::_getIncreaseCalldata stored price info: ` +
|
|
728
|
-
`${inputAmt} ${debtToken.symbol} → ${outputAmt} ${collateralToken.symbol}, ` +
|
|
729
|
-
`effectivePrice=${this.lastSwapPriceInfo.effectivePrice}`
|
|
730
|
-
);
|
|
729
|
+
aggregatedFromAmount += inputAmt;
|
|
730
|
+
aggregatedToAmount += outputAmt;
|
|
731
|
+
executedSwapCount += 1;
|
|
731
732
|
|
|
732
733
|
leverSwap = ekuboQuoter.getVesuMultiplyQuote(
|
|
733
734
|
swapQuote,
|
|
@@ -747,6 +748,22 @@ export class VesuMultiplyAdapter extends BaseAdapter<
|
|
|
747
748
|
}
|
|
748
749
|
}
|
|
749
750
|
|
|
751
|
+
if (executedSwapCount > 0) {
|
|
752
|
+
this.lastSwapPriceInfo = {
|
|
753
|
+
source: "ekubo",
|
|
754
|
+
fromTokenSymbol: aggregatedFromSymbol ?? debtToken.symbol,
|
|
755
|
+
toTokenSymbol: aggregatedToSymbol,
|
|
756
|
+
fromAmount: aggregatedFromAmount,
|
|
757
|
+
toAmount: aggregatedToAmount,
|
|
758
|
+
effectivePrice: aggregatedToAmount !== 0 ? aggregatedFromAmount / aggregatedToAmount : 0,
|
|
759
|
+
};
|
|
760
|
+
logger.verbose(
|
|
761
|
+
`${VesuMultiplyAdapter.name}::_getIncreaseCalldata stored aggregated price info: ` +
|
|
762
|
+
`${aggregatedFromAmount} ${this.lastSwapPriceInfo.fromTokenSymbol} → ${aggregatedToAmount} ${aggregatedToSymbol}, ` +
|
|
763
|
+
`effectivePrice=${this.lastSwapPriceInfo.effectivePrice}, swaps=${executedSwapCount}`
|
|
764
|
+
);
|
|
765
|
+
}
|
|
766
|
+
|
|
750
767
|
logger.verbose(
|
|
751
768
|
`${VesuMultiplyAdapter.name}::_getIncreaseCalldata leverSwapLimitAmount: ${leverSwapLimitAmount.toWei()}`
|
|
752
769
|
);
|
|
@@ -784,6 +801,17 @@ export class VesuMultiplyAdapter extends BaseAdapter<
|
|
|
784
801
|
};
|
|
785
802
|
}
|
|
786
803
|
|
|
804
|
+
// private _setLastSwapPriceAsNoSwap(): void {
|
|
805
|
+
// this.lastSwapPriceInfo = {
|
|
806
|
+
// source: "no-swap",
|
|
807
|
+
// fromTokenSymbol: this.config.collateral.symbol,
|
|
808
|
+
// toTokenSymbol: this.config.debt.symbol,
|
|
809
|
+
// fromAmount: 0,
|
|
810
|
+
// toAmount: 0,
|
|
811
|
+
// effectivePrice: 0,
|
|
812
|
+
// };
|
|
813
|
+
// }
|
|
814
|
+
|
|
787
815
|
private async _buildDecreaseLikeCalldata(params: {
|
|
788
816
|
subMargin: Web3Number;
|
|
789
817
|
debtToRepayAbs: Web3Number;
|
|
@@ -796,6 +824,7 @@ export class VesuMultiplyAdapter extends BaseAdapter<
|
|
|
796
824
|
const collateralToken = this.config.collateral;
|
|
797
825
|
const debtToken = this.config.debt;
|
|
798
826
|
const { contract: multiplyContract } = this._getMultiplyContract();
|
|
827
|
+
this.lastSwapPriceInfo = null;
|
|
799
828
|
const ekuboQuoter = new EkuboQuoter(
|
|
800
829
|
this.config.networkConfig,
|
|
801
830
|
this.config.pricer
|
|
@@ -805,6 +834,9 @@ export class VesuMultiplyAdapter extends BaseAdapter<
|
|
|
805
834
|
let leverSwapWeights: Web3Number[] = [];
|
|
806
835
|
let leverSwapLimitAmount = Web3Number.fromWei(0, collateralToken.decimals);
|
|
807
836
|
let leverCollateralUsed = Web3Number.fromWei(0, collateralToken.decimals);
|
|
837
|
+
let aggregatedFromAmount = 0; // collateral sold
|
|
838
|
+
let aggregatedToAmount = 0; // debt bought
|
|
839
|
+
let executedSwapCount = 0;
|
|
808
840
|
|
|
809
841
|
if (params.closePosition) {
|
|
810
842
|
const debtQuote = await ekuboQuoter.getQuoteExactOutput(
|
|
@@ -825,6 +857,10 @@ export class VesuMultiplyAdapter extends BaseAdapter<
|
|
|
825
857
|
collateralToken.decimals
|
|
826
858
|
).abs();
|
|
827
859
|
leverSwapLimitAmount = leverCollateralUsed.multipliedBy(1 + this.maxSlippage);
|
|
860
|
+
aggregatedFromAmount += leverCollateralUsed.toNumber();
|
|
861
|
+
aggregatedToAmount += params.debtToRepayAbs.abs().toNumber();
|
|
862
|
+
executedSwapCount += 1;
|
|
863
|
+
|
|
828
864
|
} else {
|
|
829
865
|
if (params.collateralPrice === undefined || params.debtPrice === undefined) {
|
|
830
866
|
throw new Error(
|
|
@@ -851,19 +887,9 @@ export class VesuMultiplyAdapter extends BaseAdapter<
|
|
|
851
887
|
)
|
|
852
888
|
.abs()
|
|
853
889
|
.toNumber();
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
toTokenSymbol: debtToken.symbol,
|
|
858
|
-
fromAmount: inputAmt,
|
|
859
|
-
toAmount: outputAmt,
|
|
860
|
-
effectivePrice: outputAmt !== 0 ? outputAmt / inputAmt : 0,
|
|
861
|
-
};
|
|
862
|
-
logger.verbose(
|
|
863
|
-
`${VesuMultiplyAdapter.name}::_buildDecreaseLikeCalldata stored price info: ` +
|
|
864
|
-
`${inputAmt} ${collateralToken.symbol} → ${outputAmt} ${debtToken.symbol}, ` +
|
|
865
|
-
`effectivePrice=${this.lastSwapPriceInfo.effectivePrice}`
|
|
866
|
-
);
|
|
890
|
+
aggregatedFromAmount += inputAmt;
|
|
891
|
+
aggregatedToAmount += outputAmt;
|
|
892
|
+
executedSwapCount += 1;
|
|
867
893
|
|
|
868
894
|
leverSwap = ekuboQuoter.getVesuMultiplyQuote(
|
|
869
895
|
leverSwapQuote,
|
|
@@ -893,6 +919,9 @@ export class VesuMultiplyAdapter extends BaseAdapter<
|
|
|
893
919
|
const withdrawSwapWeights: Web3Number[] = [];
|
|
894
920
|
|
|
895
921
|
if (params.outputToken && !params.outputToken.address.eq(collateralToken.address)) {
|
|
922
|
+
// bcz, last swap price is configured to be common between withdraw swap and lever swap,
|
|
923
|
+
// hence need same tokens in both
|
|
924
|
+
assert(params.outputToken.address.eq(debtToken.address), 'Withdraw output token must be the same as debt token');
|
|
896
925
|
const residualCollateral = params.closePosition
|
|
897
926
|
? params.existingCollateral.minus(leverCollateralUsed)
|
|
898
927
|
: params.subMargin;
|
|
@@ -911,6 +940,13 @@ export class VesuMultiplyAdapter extends BaseAdapter<
|
|
|
911
940
|
);
|
|
912
941
|
withdrawSwap = built.swaps;
|
|
913
942
|
withdrawSwapWeights.push(...built.weights);
|
|
943
|
+
const withdrawOutputAmount = Web3Number.fromWei(
|
|
944
|
+
withdrawQuote.total_calculated,
|
|
945
|
+
params.outputToken.decimals
|
|
946
|
+
).abs().toNumber();
|
|
947
|
+
aggregatedFromAmount += residualCollateral.toNumber();
|
|
948
|
+
aggregatedToAmount += withdrawOutputAmount;
|
|
949
|
+
executedSwapCount += 1;
|
|
914
950
|
const estimatedOutput = residualCollateral
|
|
915
951
|
.multipliedBy(params.collateralPrice)
|
|
916
952
|
.dividedBy(outputTokenPrice.price);
|
|
@@ -921,6 +957,24 @@ export class VesuMultiplyAdapter extends BaseAdapter<
|
|
|
921
957
|
}
|
|
922
958
|
}
|
|
923
959
|
|
|
960
|
+
if (executedSwapCount > 0) {
|
|
961
|
+
this.lastSwapPriceInfo = {
|
|
962
|
+
source: "ekubo",
|
|
963
|
+
fromTokenSymbol: collateralToken.symbol,
|
|
964
|
+
toTokenSymbol: debtToken.symbol,
|
|
965
|
+
fromAmount: aggregatedFromAmount,
|
|
966
|
+
toAmount: aggregatedToAmount,
|
|
967
|
+
effectivePrice: aggregatedFromAmount !== 0 ? aggregatedToAmount / aggregatedFromAmount : 0,
|
|
968
|
+
};
|
|
969
|
+
logger.verbose(
|
|
970
|
+
`${VesuMultiplyAdapter.name}::_buildDecreaseLikeCalldata stored aggregated price info: ` +
|
|
971
|
+
`${aggregatedFromAmount} ${collateralToken.symbol} → ${aggregatedToAmount} ${debtToken.symbol}, ` +
|
|
972
|
+
`effectivePrice=${this.lastSwapPriceInfo.effectivePrice}, swaps=${executedSwapCount}`
|
|
973
|
+
);
|
|
974
|
+
} else {
|
|
975
|
+
this.lastSwapPriceInfo = null;
|
|
976
|
+
}
|
|
977
|
+
|
|
924
978
|
logger.debug(
|
|
925
979
|
`${VesuMultiplyAdapter.name}::_buildDecreaseLikeCalldata leverSwapCount=${leverSwap.length}, withdrawSwapCount=${withdrawSwap.length}, withdrawSwapLimitAmount=${withdrawSwapLimitAmount.toNumber()}, subMargin=${params.subMargin.toNumber()}`,
|
|
926
980
|
);
|
|
@@ -3,7 +3,7 @@ import { ContractAddr, Web3Number } from "@/dataTypes";
|
|
|
3
3
|
import { IConfig, TokenInfo, Protocols } from "@/interfaces";
|
|
4
4
|
import { PricerBase } from "@/modules/pricerBase";
|
|
5
5
|
import { ERC20 } from "@/modules";
|
|
6
|
-
import { logger, StandardMerkleTree, StarknetCallParser } from "@/utils";
|
|
6
|
+
import { assert, logger, StandardMerkleTree, StarknetCallParser } from "@/utils";
|
|
7
7
|
import { ExtendedAdapter } from "../../universal-adapters/extended-adapter";
|
|
8
8
|
import { VesuMultiplyAdapter } from "../../universal-adapters/vesu-multiply-adapter";
|
|
9
9
|
import {
|
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
VesuModifyPositionWithdrawParams,
|
|
13
13
|
} from "../../universal-adapters/vesu-modify-position-adapter";
|
|
14
14
|
import { AvnuAdapter } from "../../universal-adapters/avnu-adapter";
|
|
15
|
-
import { UsdcToUsdceAdapter } from "../../universal-adapters/usdc<>usdce-adapter";
|
|
16
15
|
import { ManageCall, SwapPriceInfo } from "../../universal-adapters/baseAdapter";
|
|
17
16
|
import { OpenOrder, OrderSide, OrderStatus } from "@/modules/ExtendedWrapperSDk";
|
|
18
17
|
import {
|
|
@@ -71,17 +70,15 @@ const DEFAULT_EXTENDED_FILL_TIMEOUT_MS = 3000;
|
|
|
71
70
|
export interface ExecutionConfig {
|
|
72
71
|
networkConfig: IConfig;
|
|
73
72
|
pricer: PricerBase;
|
|
74
|
-
|
|
73
|
+
vesuMultiplyAdapter: VesuMultiplyAdapter;
|
|
75
74
|
vesuModifyPositionAdapter: VesuModifyPositionAdapter;
|
|
76
75
|
extendedAdapter: ExtendedAdapter;
|
|
77
76
|
avnuAdapter: AvnuAdapter;
|
|
78
|
-
|
|
79
|
-
usdceTransferAdapter: TokenTransferAdapter
|
|
77
|
+
usdcTransferAdapter: TokenTransferAdapter
|
|
80
78
|
vaultAllocator: ContractAddr;
|
|
81
79
|
walletAddress: string;
|
|
82
80
|
wbtcToken: TokenInfo;
|
|
83
81
|
usdcToken: TokenInfo;
|
|
84
|
-
usdceToken: TokenInfo;
|
|
85
82
|
|
|
86
83
|
/**
|
|
87
84
|
* Returns the strategy's merkle tree (built from all leaf adapters).
|
|
@@ -192,11 +189,10 @@ export class ExecutionService {
|
|
|
192
189
|
this._tokenSymbols = StarknetCallParser.buildTokenSymbolLookup([
|
|
193
190
|
config.wbtcToken,
|
|
194
191
|
config.usdcToken,
|
|
195
|
-
config.
|
|
196
|
-
config.
|
|
197
|
-
config.
|
|
198
|
-
config.
|
|
199
|
-
config.vesuAdapter.config.marginToken,
|
|
192
|
+
config.vesuMultiplyAdapter.config.baseToken,
|
|
193
|
+
config.vesuMultiplyAdapter.config.collateral,
|
|
194
|
+
config.vesuMultiplyAdapter.config.debt,
|
|
195
|
+
config.vesuMultiplyAdapter.config.marginToken,
|
|
200
196
|
config.vesuModifyPositionAdapter.config.collateral,
|
|
201
197
|
config.vesuModifyPositionAdapter.config.debt,
|
|
202
198
|
...avnuTokens,
|
|
@@ -204,19 +200,18 @@ export class ExecutionService {
|
|
|
204
200
|
this._tokenDecimals = StarknetCallParser.buildTokenDecimalsLookup([
|
|
205
201
|
config.wbtcToken,
|
|
206
202
|
config.usdcToken,
|
|
207
|
-
config.
|
|
208
|
-
config.
|
|
209
|
-
config.
|
|
210
|
-
config.
|
|
211
|
-
config.vesuAdapter.config.marginToken,
|
|
203
|
+
config.vesuMultiplyAdapter.config.baseToken,
|
|
204
|
+
config.vesuMultiplyAdapter.config.collateral,
|
|
205
|
+
config.vesuMultiplyAdapter.config.debt,
|
|
206
|
+
config.vesuMultiplyAdapter.config.marginToken,
|
|
212
207
|
config.vesuModifyPositionAdapter.config.collateral,
|
|
213
208
|
config.vesuModifyPositionAdapter.config.debt,
|
|
214
209
|
...avnuTokens,
|
|
215
210
|
]);
|
|
216
211
|
this._poolNames = StarknetCallParser.buildPoolNameLookup([
|
|
217
212
|
{
|
|
218
|
-
poolId: config.
|
|
219
|
-
name: `${config.
|
|
213
|
+
poolId: config.vesuMultiplyAdapter.config.poolId.toBigInt(),
|
|
214
|
+
name: `${config.vesuMultiplyAdapter.config.collateral.symbol}/${config.vesuMultiplyAdapter.config.debt.symbol}`,
|
|
220
215
|
},
|
|
221
216
|
{
|
|
222
217
|
poolId: config.vesuModifyPositionAdapter.config.poolId.toBigInt(),
|
|
@@ -810,14 +805,17 @@ export class ExecutionService {
|
|
|
810
805
|
*
|
|
811
806
|
* For deposit (USDC→BTC): price = sum(USDC sold) / sum(BTC bought)
|
|
812
807
|
* For withdraw (BTC→USDC): price = sum(USDC bought) / sum(BTC sold)
|
|
813
|
-
|
|
814
|
-
|
|
808
|
+
* @returns no-swap means, logic is fine and explicit no swap is needed
|
|
809
|
+
*/
|
|
810
|
+
private _getNetExecutionPrice(isDeposit: boolean): number | null { // | 'no-swap' {
|
|
815
811
|
const prices: SwapPriceInfo[] = [
|
|
816
812
|
this._config.avnuAdapter.lastSwapPriceInfo,
|
|
817
|
-
this._config.
|
|
813
|
+
this._config.vesuMultiplyAdapter.lastSwapPriceInfo,
|
|
818
814
|
].filter((p): p is SwapPriceInfo => p !== null);
|
|
819
815
|
|
|
816
|
+
assert(prices.length <= 1, 'Only one swap price info is allowed');
|
|
820
817
|
if (prices.length === 0) return null;
|
|
818
|
+
// if (prices[0].source === 'no-swap') return 'no-swap';
|
|
821
819
|
|
|
822
820
|
if (isDeposit) {
|
|
823
821
|
const totalUsdc = prices.reduce((s, p) => s + p.fromAmount, 0);
|
|
@@ -833,7 +831,7 @@ export class ExecutionService {
|
|
|
833
831
|
/** Clears cached swap price info on all adapters to prevent stale data across cycles. */
|
|
834
832
|
private _clearAdapterPriceInfo(): void {
|
|
835
833
|
this._config.avnuAdapter.lastSwapPriceInfo = null;
|
|
836
|
-
this._config.
|
|
834
|
+
this._config.vesuMultiplyAdapter.lastSwapPriceInfo = null;
|
|
837
835
|
}
|
|
838
836
|
|
|
839
837
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
@@ -1162,6 +1160,7 @@ export class ExecutionService {
|
|
|
1162
1160
|
r.type === RouteType.VESU_MULTIPLY_DECREASE_LEVER
|
|
1163
1161
|
);
|
|
1164
1162
|
const netExecutionPrice = this._getNetExecutionPrice(isIncrease);
|
|
1163
|
+
|
|
1165
1164
|
let executionPrice: number;
|
|
1166
1165
|
|
|
1167
1166
|
if (hasVesuSwapRoute) {
|
|
@@ -1354,7 +1353,7 @@ export class ExecutionService {
|
|
|
1354
1353
|
// ── Transfer routes ─────────────────────────────────────────────────────
|
|
1355
1354
|
|
|
1356
1355
|
/**
|
|
1357
|
-
* WALLET_TO_EXTENDED: Deposit USDC
|
|
1356
|
+
* WALLET_TO_EXTENDED: Deposit USDC from operator wallet directly to Extended.
|
|
1358
1357
|
*
|
|
1359
1358
|
* Builds raw approve + deposit calls (NOT through the manager/merkle system)
|
|
1360
1359
|
* because the wallet interacts with Extended directly, not via vault allocator.
|
|
@@ -1372,14 +1371,14 @@ export class ExecutionService {
|
|
|
1372
1371
|
return [];
|
|
1373
1372
|
}
|
|
1374
1373
|
|
|
1375
|
-
const {
|
|
1374
|
+
const { usdcToken, extendedAdapter } = this._config;
|
|
1376
1375
|
const extendedContract = extendedAdapter.config.extendedContract;
|
|
1377
1376
|
const vaultId = extendedAdapter.config.vaultIdExtended;
|
|
1378
|
-
const salt = Math.floor(Math.random() * 10 **
|
|
1377
|
+
const salt = Math.floor(Math.random() * 10 ** usdcToken.decimals);
|
|
1379
1378
|
const uint256Amount = uint256.bnToUint256(amount.toWei());
|
|
1380
1379
|
|
|
1381
1380
|
const approveCall: Call = {
|
|
1382
|
-
contractAddress:
|
|
1381
|
+
contractAddress: usdcToken.address.address,
|
|
1383
1382
|
entrypoint: "approve",
|
|
1384
1383
|
calldata: [
|
|
1385
1384
|
extendedContract.address,
|
|
@@ -1407,7 +1406,7 @@ export class ExecutionService {
|
|
|
1407
1406
|
}
|
|
1408
1407
|
|
|
1409
1408
|
/**
|
|
1410
|
-
* VA_TO_EXTENDED: Deposit USDC
|
|
1409
|
+
* VA_TO_EXTENDED: Deposit USDC from vault allocator to Extended.
|
|
1411
1410
|
*
|
|
1412
1411
|
* Uses the extended adapter's getDepositCall to build ManageCalls,
|
|
1413
1412
|
* then wraps them in a merkle-verified manage call through the manager contract.
|
|
@@ -1425,55 +1424,37 @@ export class ExecutionService {
|
|
|
1425
1424
|
return [];
|
|
1426
1425
|
}
|
|
1427
1426
|
|
|
1428
|
-
// swap call (usdc to usdce)
|
|
1429
|
-
const swapCall = await this._buildAdapterManageCall(
|
|
1430
|
-
this._config.usdcToUsdceAdapter,
|
|
1431
|
-
true,
|
|
1432
|
-
{ amount },
|
|
1433
|
-
);
|
|
1434
1427
|
const manageCall = await this._buildAdapterManageCall(
|
|
1435
1428
|
this._config.extendedAdapter,
|
|
1436
1429
|
true,
|
|
1437
1430
|
{ amount },
|
|
1438
1431
|
);
|
|
1439
|
-
return [
|
|
1432
|
+
return [manageCall];
|
|
1440
1433
|
}
|
|
1441
1434
|
|
|
1442
1435
|
/**
|
|
1443
|
-
* WALLET_TO_VA: Transfer USDC
|
|
1436
|
+
* WALLET_TO_VA: Transfer USDC from operator wallet to vault allocator.
|
|
1444
1437
|
* Caps amount by actual wallet balance.
|
|
1445
1438
|
*/
|
|
1446
1439
|
private async _buildWalletToVACalls(
|
|
1447
1440
|
route: TransferRoute,
|
|
1448
1441
|
): Promise<Call[]> {
|
|
1449
|
-
const erc20 = new ERC20(this._config.networkConfig);
|
|
1450
|
-
const { usdceToken, vaultAllocator, walletAddress } = this._config;
|
|
1451
|
-
|
|
1452
|
-
// checking balance could be unnecesary overhead. hence removed removed for now.
|
|
1453
|
-
|
|
1454
1442
|
const transferAmount = route.amount;
|
|
1455
1443
|
if (transferAmount.lessThanOrEqualTo(0)) {
|
|
1456
1444
|
logger.warn(
|
|
1457
|
-
`${this._tag}::_buildWalletToVACalls no USDC
|
|
1445
|
+
`${this._tag}::_buildWalletToVACalls no USDC in wallet to transfer`,
|
|
1458
1446
|
);
|
|
1459
1447
|
return [];
|
|
1460
1448
|
}
|
|
1461
1449
|
|
|
1462
|
-
// todo, give infinite approval to VA and extended contract
|
|
1463
|
-
// for USDC.e for wallet account.
|
|
1450
|
+
// todo, give infinite approval to VA and extended contract for wallet account.
|
|
1464
1451
|
|
|
1465
1452
|
const transferCall = await this._buildAdapterManageCall(
|
|
1466
|
-
this._config.
|
|
1467
|
-
false,
|
|
1468
|
-
{ amount: transferAmount },
|
|
1469
|
-
);
|
|
1470
|
-
// swap call (usdc to usdce)
|
|
1471
|
-
const swapCall = await this._buildAdapterManageCall(
|
|
1472
|
-
this._config.usdcToUsdceAdapter,
|
|
1453
|
+
this._config.usdcTransferAdapter,
|
|
1473
1454
|
false,
|
|
1474
1455
|
{ amount: transferAmount },
|
|
1475
1456
|
);
|
|
1476
|
-
return [transferCall
|
|
1457
|
+
return [transferCall];
|
|
1477
1458
|
}
|
|
1478
1459
|
|
|
1479
1460
|
// ── AVNU swap routes ────────────────────────────────────────────────────
|
|
@@ -1556,12 +1537,12 @@ export class ExecutionService {
|
|
|
1556
1537
|
// );
|
|
1557
1538
|
|
|
1558
1539
|
const depositManageCall = await this._buildAdapterManageCall(
|
|
1559
|
-
this._config.
|
|
1540
|
+
this._config.vesuMultiplyAdapter,
|
|
1560
1541
|
true,
|
|
1561
1542
|
{
|
|
1562
1543
|
amount: route.marginAmount,
|
|
1563
1544
|
marginSwap: {
|
|
1564
|
-
marginToken: this._config.
|
|
1545
|
+
marginToken: this._config.vesuMultiplyAdapter.config.marginToken, // todo, must be vault token
|
|
1565
1546
|
},
|
|
1566
1547
|
leverSwap: {
|
|
1567
1548
|
exactOutput: route.swappedCollateralAmount,
|
|
@@ -1584,11 +1565,11 @@ export class ExecutionService {
|
|
|
1584
1565
|
const collateralAmount = route.marginAmount.abs();
|
|
1585
1566
|
|
|
1586
1567
|
const withdrawManageCall = await this._buildAdapterManageCall(
|
|
1587
|
-
this._config.
|
|
1568
|
+
this._config.vesuMultiplyAdapter,
|
|
1588
1569
|
false,
|
|
1589
1570
|
{
|
|
1590
1571
|
amount: collateralAmount,
|
|
1591
|
-
withdrawSwap: { outputToken: this._config.
|
|
1572
|
+
withdrawSwap: { outputToken: this._config.vesuMultiplyAdapter.config.marginToken },
|
|
1592
1573
|
},
|
|
1593
1574
|
);
|
|
1594
1575
|
return [withdrawManageCall];
|