@strkfarm/sdk 2.0.0-dev.12 → 2.0.0-dev.14
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 +350 -333
- package/dist/index.browser.mjs +812 -795
- package/dist/index.d.ts +19 -1
- package/dist/index.js +358 -339
- package/dist/index.mjs +812 -795
- package/package.json +1 -1
- package/src/strategies/universal-adapters/index.ts +2 -1
- package/src/strategies/vesu-extended-strategy/utils/helper.ts +40 -0
- package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +5 -5
|
@@ -28653,6 +28653,7 @@ ${r2}}` : "}", l2;
|
|
|
28653
28653
|
AssetOperationStatus: () => AssetOperationStatus,
|
|
28654
28654
|
AssetOperationType: () => AssetOperationType,
|
|
28655
28655
|
AutoCompounderSTRK: () => AutoCompounderSTRK,
|
|
28656
|
+
AvnuAdapter: () => AvnuAdapter,
|
|
28656
28657
|
AvnuWrapper: () => AvnuWrapper,
|
|
28657
28658
|
BaseAdapter: () => BaseAdapter,
|
|
28658
28659
|
BaseStrategy: () => BaseStrategy,
|
|
@@ -28728,6 +28729,7 @@ ${r2}}` : "}", l2;
|
|
|
28728
28729
|
calculateExtendedLevergae: () => calculateExtendedLevergae,
|
|
28729
28730
|
calculateVesUPositionSizeGivenExtended: () => calculateVesUPositionSizeGivenExtended,
|
|
28730
28731
|
calculateVesuLeverage: () => calculateVesuLeverage,
|
|
28732
|
+
calculateWBTCAmountToMaintainLTV: () => calculateWBTCAmountToMaintainLTV,
|
|
28731
28733
|
extensionMap: () => extensionMap,
|
|
28732
28734
|
getContractDetails: () => getContractDetails,
|
|
28733
28735
|
getFAQs: () => getFAQs,
|
|
@@ -92580,6 +92582,21 @@ spurious results.`);
|
|
|
92580
92582
|
return null;
|
|
92581
92583
|
}
|
|
92582
92584
|
};
|
|
92585
|
+
var calculateWBTCAmountToMaintainLTV = (collateralAmount, debtAmount, debtPrice, maxLtv = MAX_LIQUIDATION_RATIO, collateralPrice, targetHF = TARGET_HF) => {
|
|
92586
|
+
try {
|
|
92587
|
+
const numerator1 = collateralAmount.multipliedBy(collateralPrice).multipliedBy(maxLtv);
|
|
92588
|
+
const numerator2 = debtAmount.multipliedBy(debtPrice).multipliedBy(targetHF);
|
|
92589
|
+
const denominator = maxLtv;
|
|
92590
|
+
const collateralAmountToMaintainLTV = numerator2.minus(numerator1).dividedBy(denominator);
|
|
92591
|
+
let deltaCollateralAmountUnits = new Web3Number(
|
|
92592
|
+
collateralAmountToMaintainLTV.dividedBy(collateralPrice).toFixed(WBTC_TOKEN_DECIMALS),
|
|
92593
|
+
WBTC_TOKEN_DECIMALS
|
|
92594
|
+
);
|
|
92595
|
+
return { deltaCollateralAmountUnits };
|
|
92596
|
+
} catch (err2) {
|
|
92597
|
+
return { deltaCollateralAmountUnits: null };
|
|
92598
|
+
}
|
|
92599
|
+
};
|
|
92583
92600
|
var calculateExposureDelta = (exposure_extended, exposure_vesu) => {
|
|
92584
92601
|
const exposure_delta = new Web3Number(exposure_extended - exposure_vesu, 2);
|
|
92585
92602
|
return exposure_delta.absoluteValue().toNumber();
|
|
@@ -94506,6 +94523,334 @@ spurious results.`);
|
|
|
94506
94523
|
}
|
|
94507
94524
|
};
|
|
94508
94525
|
|
|
94526
|
+
// src/strategies/universal-adapters/avnu-adapter.ts
|
|
94527
|
+
var AvnuAdapter = class _AvnuAdapter extends BaseAdapter {
|
|
94528
|
+
constructor(config3) {
|
|
94529
|
+
super(config3, _AvnuAdapter.name, Protocols.AVNU);
|
|
94530
|
+
this.config = config3;
|
|
94531
|
+
this.avnuWrapper = new AvnuWrapper();
|
|
94532
|
+
}
|
|
94533
|
+
//abstract means the method has no implementation in this class; instead, child classes must implement it.
|
|
94534
|
+
async getAPY(supportedPosition) {
|
|
94535
|
+
return Promise.resolve({ apy: 0, type: "base" /* BASE */ });
|
|
94536
|
+
}
|
|
94537
|
+
async getPosition(supportedPosition) {
|
|
94538
|
+
return Promise.resolve({ amount: new Web3Number(0, 0), remarks: "" });
|
|
94539
|
+
}
|
|
94540
|
+
async maxDeposit(amount) {
|
|
94541
|
+
return Promise.resolve({
|
|
94542
|
+
tokenInfo: this.config.baseToken,
|
|
94543
|
+
amount: new Web3Number(0, 0),
|
|
94544
|
+
usdValue: 0,
|
|
94545
|
+
apy: { apy: 0, type: "base" /* BASE */ },
|
|
94546
|
+
protocol: Protocols.AVNU,
|
|
94547
|
+
remarks: ""
|
|
94548
|
+
});
|
|
94549
|
+
}
|
|
94550
|
+
async maxWithdraw() {
|
|
94551
|
+
return Promise.resolve({
|
|
94552
|
+
tokenInfo: this.config.baseToken,
|
|
94553
|
+
amount: new Web3Number(0, 0),
|
|
94554
|
+
usdValue: 0,
|
|
94555
|
+
apy: { apy: 0, type: "base" /* BASE */ },
|
|
94556
|
+
protocol: Protocols.AVNU,
|
|
94557
|
+
remarks: ""
|
|
94558
|
+
});
|
|
94559
|
+
}
|
|
94560
|
+
_getDepositLeaf() {
|
|
94561
|
+
const vaultAllocator = ContractAddr.from(
|
|
94562
|
+
this.config.vaultAllocator.address
|
|
94563
|
+
);
|
|
94564
|
+
return [
|
|
94565
|
+
{
|
|
94566
|
+
target: this.config.supportedPositions[0].asset.address,
|
|
94567
|
+
method: "approve",
|
|
94568
|
+
packedArguments: [
|
|
94569
|
+
AVNU_EXCHANGE.toBigInt()
|
|
94570
|
+
],
|
|
94571
|
+
sanitizer: SIMPLE_SANITIZER,
|
|
94572
|
+
id: `approve_${this.config.supportedPositions[0].asset.symbol}`
|
|
94573
|
+
},
|
|
94574
|
+
{
|
|
94575
|
+
target: AVNU_EXCHANGE,
|
|
94576
|
+
method: "multi_route_swap",
|
|
94577
|
+
packedArguments: [
|
|
94578
|
+
this.config.supportedPositions[0].asset.address.toBigInt(),
|
|
94579
|
+
//usdc
|
|
94580
|
+
this.config.supportedPositions[1].asset.address.toBigInt(),
|
|
94581
|
+
//wbtc
|
|
94582
|
+
vaultAllocator.toBigInt()
|
|
94583
|
+
],
|
|
94584
|
+
sanitizer: SIMPLE_SANITIZER,
|
|
94585
|
+
id: `asutb_${this.config.supportedPositions[0].asset.symbol}_${this.config.supportedPositions[1].asset.symbol}`
|
|
94586
|
+
}
|
|
94587
|
+
];
|
|
94588
|
+
}
|
|
94589
|
+
_getWithdrawLeaf() {
|
|
94590
|
+
const vaultAllocator = ContractAddr.from(
|
|
94591
|
+
this.config.vaultAllocator.address
|
|
94592
|
+
);
|
|
94593
|
+
const toToken = this.config.supportedPositions[0].asset;
|
|
94594
|
+
const fromToken = this.config.supportedPositions[1].asset;
|
|
94595
|
+
return [
|
|
94596
|
+
{
|
|
94597
|
+
target: fromToken.address,
|
|
94598
|
+
method: "approve",
|
|
94599
|
+
packedArguments: [
|
|
94600
|
+
AVNU_EXCHANGE.toBigInt()
|
|
94601
|
+
],
|
|
94602
|
+
sanitizer: SIMPLE_SANITIZER,
|
|
94603
|
+
id: `approve_${fromToken.symbol}`
|
|
94604
|
+
},
|
|
94605
|
+
{
|
|
94606
|
+
target: AVNU_EXCHANGE,
|
|
94607
|
+
method: "multi_route_swap",
|
|
94608
|
+
packedArguments: [
|
|
94609
|
+
fromToken.address.toBigInt(),
|
|
94610
|
+
//wbtc
|
|
94611
|
+
toToken.address.toBigInt(),
|
|
94612
|
+
//usdc
|
|
94613
|
+
vaultAllocator.toBigInt()
|
|
94614
|
+
],
|
|
94615
|
+
sanitizer: SIMPLE_SANITIZER,
|
|
94616
|
+
id: `asbtu_${fromToken.symbol}_${fromToken.symbol}`
|
|
94617
|
+
}
|
|
94618
|
+
];
|
|
94619
|
+
}
|
|
94620
|
+
_getLegacySwapLeaf() {
|
|
94621
|
+
return [];
|
|
94622
|
+
}
|
|
94623
|
+
async getDepositCall(params) {
|
|
94624
|
+
try {
|
|
94625
|
+
const fromToken = this.config.supportedPositions[0].asset;
|
|
94626
|
+
const toToken = this.config.supportedPositions[1].asset;
|
|
94627
|
+
const vaultAllocator = ContractAddr.from(
|
|
94628
|
+
this.config.vaultAllocator.address
|
|
94629
|
+
);
|
|
94630
|
+
const quote = await this.getQuotesAvnu(
|
|
94631
|
+
fromToken.address.toString(),
|
|
94632
|
+
toToken.address.toString(),
|
|
94633
|
+
params.amount.toNumber(),
|
|
94634
|
+
vaultAllocator.address.toString(),
|
|
94635
|
+
toToken.decimals,
|
|
94636
|
+
true
|
|
94637
|
+
);
|
|
94638
|
+
if (!quote) {
|
|
94639
|
+
logger2.error("error getting quote from avnu");
|
|
94640
|
+
return [];
|
|
94641
|
+
}
|
|
94642
|
+
const getCalldata = await this.avnuWrapper.getSwapCallData(
|
|
94643
|
+
quote,
|
|
94644
|
+
vaultAllocator.address
|
|
94645
|
+
);
|
|
94646
|
+
const swapCallData = getCalldata[0];
|
|
94647
|
+
const amount = uint256_exports.bnToUint256(quote.sellAmountInUsd * 10 ** 7);
|
|
94648
|
+
return [
|
|
94649
|
+
{
|
|
94650
|
+
sanitizer: SIMPLE_SANITIZER,
|
|
94651
|
+
call: {
|
|
94652
|
+
contractAddress: fromToken.address,
|
|
94653
|
+
selector: hash_exports.getSelectorFromName("approve"),
|
|
94654
|
+
calldata: [
|
|
94655
|
+
AVNU_EXCHANGE.toBigInt(),
|
|
94656
|
+
toBigInt3(amount.low.toString()),
|
|
94657
|
+
// amount low
|
|
94658
|
+
toBigInt3(amount.high.toString())
|
|
94659
|
+
// amount high
|
|
94660
|
+
]
|
|
94661
|
+
}
|
|
94662
|
+
},
|
|
94663
|
+
{
|
|
94664
|
+
sanitizer: SIMPLE_SANITIZER,
|
|
94665
|
+
call: {
|
|
94666
|
+
contractAddress: AVNU_EXCHANGE,
|
|
94667
|
+
selector: hash_exports.getSelectorFromName("multi_route_swap"),
|
|
94668
|
+
calldata: swapCallData
|
|
94669
|
+
}
|
|
94670
|
+
}
|
|
94671
|
+
];
|
|
94672
|
+
} catch (error2) {
|
|
94673
|
+
logger2.error(`Error getting Avnu quote: ${error2}`);
|
|
94674
|
+
return [];
|
|
94675
|
+
}
|
|
94676
|
+
}
|
|
94677
|
+
//Swap wbtc to usdc
|
|
94678
|
+
async getWithdrawCall(params) {
|
|
94679
|
+
try {
|
|
94680
|
+
const toToken = this.config.supportedPositions[0].asset;
|
|
94681
|
+
const fromToken = this.config.supportedPositions[1].asset;
|
|
94682
|
+
const vaultAllocator = ContractAddr.from(
|
|
94683
|
+
this.config.vaultAllocator.address
|
|
94684
|
+
);
|
|
94685
|
+
const quote = await this.getQuotesAvnu(
|
|
94686
|
+
fromToken.address.toString(),
|
|
94687
|
+
toToken.address.toString(),
|
|
94688
|
+
params.amount.toNumber(),
|
|
94689
|
+
vaultAllocator.address.toString(),
|
|
94690
|
+
fromToken.decimals,
|
|
94691
|
+
false
|
|
94692
|
+
);
|
|
94693
|
+
if (!quote) {
|
|
94694
|
+
logger2.error("No quotes available for this swap, error in quotes avnu");
|
|
94695
|
+
return [];
|
|
94696
|
+
}
|
|
94697
|
+
const getCalldata = await this.avnuWrapper.getSwapCallData(
|
|
94698
|
+
quote,
|
|
94699
|
+
vaultAllocator.address
|
|
94700
|
+
);
|
|
94701
|
+
const swapCallData = getCalldata[0];
|
|
94702
|
+
const amount = uint256_exports.bnToUint256(params.amount.toWei());
|
|
94703
|
+
return [
|
|
94704
|
+
{
|
|
94705
|
+
sanitizer: SIMPLE_SANITIZER,
|
|
94706
|
+
call: {
|
|
94707
|
+
contractAddress: fromToken.address,
|
|
94708
|
+
selector: hash_exports.getSelectorFromName("approve"),
|
|
94709
|
+
calldata: [
|
|
94710
|
+
AVNU_EXCHANGE.toBigInt(),
|
|
94711
|
+
toBigInt3(amount.low.toString()),
|
|
94712
|
+
// amount low
|
|
94713
|
+
toBigInt3(amount.high.toString())
|
|
94714
|
+
// amount high
|
|
94715
|
+
]
|
|
94716
|
+
}
|
|
94717
|
+
},
|
|
94718
|
+
{
|
|
94719
|
+
sanitizer: SIMPLE_SANITIZER,
|
|
94720
|
+
call: {
|
|
94721
|
+
contractAddress: AVNU_EXCHANGE,
|
|
94722
|
+
selector: hash_exports.getSelectorFromName("multi_route_swap"),
|
|
94723
|
+
calldata: swapCallData
|
|
94724
|
+
}
|
|
94725
|
+
}
|
|
94726
|
+
];
|
|
94727
|
+
} catch (error2) {
|
|
94728
|
+
logger2.error(`Error getting Avnu quote: ${error2}`);
|
|
94729
|
+
return [];
|
|
94730
|
+
}
|
|
94731
|
+
}
|
|
94732
|
+
async getSwapCallData(quote) {
|
|
94733
|
+
return await this.avnuWrapper.getSwapCallData(quote, this.config.vaultAllocator.address);
|
|
94734
|
+
}
|
|
94735
|
+
async getHealthFactor() {
|
|
94736
|
+
return Promise.resolve(1);
|
|
94737
|
+
}
|
|
94738
|
+
async fetchQuoteWithRetry(params, retries = 5) {
|
|
94739
|
+
for (let attempt = 0; attempt < retries; attempt++) {
|
|
94740
|
+
try {
|
|
94741
|
+
const response = await axios_default.get(this.config.baseUrl, { params });
|
|
94742
|
+
if (response.data && response.data.length > 0) {
|
|
94743
|
+
return response;
|
|
94744
|
+
}
|
|
94745
|
+
throw new Error("Empty response data");
|
|
94746
|
+
} catch (err2) {
|
|
94747
|
+
logger2.error(`Error fetching quote with retry: ${err2}`);
|
|
94748
|
+
if (attempt === retries - 1) {
|
|
94749
|
+
throw err2;
|
|
94750
|
+
}
|
|
94751
|
+
await new Promise((resolve) => setTimeout(resolve, MAX_DELAY));
|
|
94752
|
+
}
|
|
94753
|
+
}
|
|
94754
|
+
throw new Error("Failed to fetch quote after retries");
|
|
94755
|
+
}
|
|
94756
|
+
async getQuotesAvnu(from_token_address, to_token_address, amount, takerAddress, toTokenDecimals, usdcToBtc, maxIterations = 5, tolerance = 5e3) {
|
|
94757
|
+
try {
|
|
94758
|
+
const fromToken = this.config.supportedPositions[0].asset;
|
|
94759
|
+
const toToken = this.config.supportedPositions[1].asset;
|
|
94760
|
+
if (!usdcToBtc) {
|
|
94761
|
+
const sellAmount2 = returnFormattedAmount(amount, toTokenDecimals);
|
|
94762
|
+
const params2 = {
|
|
94763
|
+
sellTokenAddress: from_token_address,
|
|
94764
|
+
buyTokenAddress: to_token_address,
|
|
94765
|
+
takerAddress,
|
|
94766
|
+
sellAmount: sellAmount2
|
|
94767
|
+
};
|
|
94768
|
+
const finalQuote2 = await this.fetchQuoteWithRetry(params2);
|
|
94769
|
+
if (!finalQuote2.data.length) {
|
|
94770
|
+
logger2.error("No quotes available for this swap, error in quotes avnu");
|
|
94771
|
+
return null;
|
|
94772
|
+
}
|
|
94773
|
+
const dataObject2 = finalQuote2.data[0];
|
|
94774
|
+
return dataObject2;
|
|
94775
|
+
}
|
|
94776
|
+
const btcPrice = await this.getPriceOfToken(toToken.address.toString());
|
|
94777
|
+
if (!btcPrice) {
|
|
94778
|
+
logger2.error(`error getting btc price: ${btcPrice}`);
|
|
94779
|
+
return null;
|
|
94780
|
+
}
|
|
94781
|
+
const estimatedUsdcAmount = Math.floor(amount * btcPrice);
|
|
94782
|
+
const targetBtcBig = BigInt(returnFormattedAmount(amount, toTokenDecimals));
|
|
94783
|
+
let low = BigInt(
|
|
94784
|
+
Math.floor(
|
|
94785
|
+
estimatedUsdcAmount * 10 ** fromToken.decimals * 0.9
|
|
94786
|
+
)
|
|
94787
|
+
);
|
|
94788
|
+
let high = BigInt(
|
|
94789
|
+
Math.floor(
|
|
94790
|
+
estimatedUsdcAmount * 10 ** fromToken.decimals * 1.1
|
|
94791
|
+
)
|
|
94792
|
+
);
|
|
94793
|
+
let mid = 0n;
|
|
94794
|
+
for (let i = 0; i < maxIterations; i++) {
|
|
94795
|
+
mid = (low + high) / 2n;
|
|
94796
|
+
const sellAmount2 = returnFormattedAmount(Number(mid), 0);
|
|
94797
|
+
const quote = await this.fetchQuoteWithRetry({
|
|
94798
|
+
sellTokenAddress: from_token_address,
|
|
94799
|
+
buyTokenAddress: to_token_address,
|
|
94800
|
+
takerAddress,
|
|
94801
|
+
sellAmount: sellAmount2
|
|
94802
|
+
});
|
|
94803
|
+
const gotBtc = BigInt(quote.data[0].buyAmount);
|
|
94804
|
+
if (gotBtc === targetBtcBig) return quote.data[0];
|
|
94805
|
+
if (gotBtc > targetBtcBig) {
|
|
94806
|
+
high = mid;
|
|
94807
|
+
} else {
|
|
94808
|
+
low = mid;
|
|
94809
|
+
}
|
|
94810
|
+
if (gotBtc >= targetBtcBig && gotBtc <= targetBtcBig + BigInt(tolerance)) {
|
|
94811
|
+
return quote.data[0];
|
|
94812
|
+
}
|
|
94813
|
+
}
|
|
94814
|
+
let sellAmount = returnFormattedAmount(
|
|
94815
|
+
Number(mid),
|
|
94816
|
+
0
|
|
94817
|
+
);
|
|
94818
|
+
const params = {
|
|
94819
|
+
sellTokenAddress: from_token_address,
|
|
94820
|
+
buyTokenAddress: to_token_address,
|
|
94821
|
+
takerAddress,
|
|
94822
|
+
sellAmount
|
|
94823
|
+
};
|
|
94824
|
+
const finalQuote = await this.fetchQuoteWithRetry(params);
|
|
94825
|
+
if (!finalQuote.data.length) {
|
|
94826
|
+
logger2.error("No quotes available for this swap, error in quotes avnu");
|
|
94827
|
+
return null;
|
|
94828
|
+
}
|
|
94829
|
+
const dataObject = finalQuote.data[0];
|
|
94830
|
+
return dataObject;
|
|
94831
|
+
} catch (err2) {
|
|
94832
|
+
logger2.error(`No quotes available for this swap: ${err2}`);
|
|
94833
|
+
return null;
|
|
94834
|
+
}
|
|
94835
|
+
}
|
|
94836
|
+
async getPriceOfToken(tokenAddress, retries = MAX_RETRIES) {
|
|
94837
|
+
try {
|
|
94838
|
+
const url = `https://starknet.impulse.avnu.fi/v1/tokens/${tokenAddress}/prices/line`;
|
|
94839
|
+
const response = await axios_default.get(url);
|
|
94840
|
+
const length = response.data.length;
|
|
94841
|
+
return response.data[length - 1].value;
|
|
94842
|
+
} catch (err2) {
|
|
94843
|
+
if (retries > 0) {
|
|
94844
|
+
await new Promise((resolve) => setTimeout(resolve, MAX_DELAY));
|
|
94845
|
+
return this.getPriceOfToken(tokenAddress, retries - 1);
|
|
94846
|
+
} else {
|
|
94847
|
+
logger2.error(`Failed to fetch price for ${tokenAddress} after ${MAX_RETRIES} attempts`);
|
|
94848
|
+
return null;
|
|
94849
|
+
}
|
|
94850
|
+
}
|
|
94851
|
+
}
|
|
94852
|
+
};
|
|
94853
|
+
|
|
94509
94854
|
// src/strategies/universal-strategy.tsx
|
|
94510
94855
|
var AUMTypes = /* @__PURE__ */ ((AUMTypes2) => {
|
|
94511
94856
|
AUMTypes2["FINALISED"] = "finalised";
|
|
@@ -97924,334 +98269,6 @@ spurious results.`);
|
|
|
97924
98269
|
getStrategySettings("mRe7YIELD", "mRe7YIELD", hypermRe7YIELD, false, false)
|
|
97925
98270
|
];
|
|
97926
98271
|
|
|
97927
|
-
// src/strategies/universal-adapters/avnu-adapter.ts
|
|
97928
|
-
var AvnuAdapter = class _AvnuAdapter extends BaseAdapter {
|
|
97929
|
-
constructor(config3) {
|
|
97930
|
-
super(config3, _AvnuAdapter.name, Protocols.AVNU);
|
|
97931
|
-
this.config = config3;
|
|
97932
|
-
this.avnuWrapper = new AvnuWrapper();
|
|
97933
|
-
}
|
|
97934
|
-
//abstract means the method has no implementation in this class; instead, child classes must implement it.
|
|
97935
|
-
async getAPY(supportedPosition) {
|
|
97936
|
-
return Promise.resolve({ apy: 0, type: "base" /* BASE */ });
|
|
97937
|
-
}
|
|
97938
|
-
async getPosition(supportedPosition) {
|
|
97939
|
-
return Promise.resolve({ amount: new Web3Number(0, 0), remarks: "" });
|
|
97940
|
-
}
|
|
97941
|
-
async maxDeposit(amount) {
|
|
97942
|
-
return Promise.resolve({
|
|
97943
|
-
tokenInfo: this.config.baseToken,
|
|
97944
|
-
amount: new Web3Number(0, 0),
|
|
97945
|
-
usdValue: 0,
|
|
97946
|
-
apy: { apy: 0, type: "base" /* BASE */ },
|
|
97947
|
-
protocol: Protocols.AVNU,
|
|
97948
|
-
remarks: ""
|
|
97949
|
-
});
|
|
97950
|
-
}
|
|
97951
|
-
async maxWithdraw() {
|
|
97952
|
-
return Promise.resolve({
|
|
97953
|
-
tokenInfo: this.config.baseToken,
|
|
97954
|
-
amount: new Web3Number(0, 0),
|
|
97955
|
-
usdValue: 0,
|
|
97956
|
-
apy: { apy: 0, type: "base" /* BASE */ },
|
|
97957
|
-
protocol: Protocols.AVNU,
|
|
97958
|
-
remarks: ""
|
|
97959
|
-
});
|
|
97960
|
-
}
|
|
97961
|
-
_getDepositLeaf() {
|
|
97962
|
-
const vaultAllocator = ContractAddr.from(
|
|
97963
|
-
this.config.vaultAllocator.address
|
|
97964
|
-
);
|
|
97965
|
-
return [
|
|
97966
|
-
{
|
|
97967
|
-
target: this.config.supportedPositions[0].asset.address,
|
|
97968
|
-
method: "approve",
|
|
97969
|
-
packedArguments: [
|
|
97970
|
-
AVNU_EXCHANGE.toBigInt()
|
|
97971
|
-
],
|
|
97972
|
-
sanitizer: SIMPLE_SANITIZER,
|
|
97973
|
-
id: `approve_${this.config.supportedPositions[0].asset.symbol}`
|
|
97974
|
-
},
|
|
97975
|
-
{
|
|
97976
|
-
target: AVNU_EXCHANGE,
|
|
97977
|
-
method: "multi_route_swap",
|
|
97978
|
-
packedArguments: [
|
|
97979
|
-
this.config.supportedPositions[0].asset.address.toBigInt(),
|
|
97980
|
-
//usdc
|
|
97981
|
-
this.config.supportedPositions[1].asset.address.toBigInt(),
|
|
97982
|
-
//wbtc
|
|
97983
|
-
vaultAllocator.toBigInt()
|
|
97984
|
-
],
|
|
97985
|
-
sanitizer: SIMPLE_SANITIZER,
|
|
97986
|
-
id: `asutb_${this.config.supportedPositions[0].asset.symbol}_${this.config.supportedPositions[1].asset.symbol}`
|
|
97987
|
-
}
|
|
97988
|
-
];
|
|
97989
|
-
}
|
|
97990
|
-
_getWithdrawLeaf() {
|
|
97991
|
-
const vaultAllocator = ContractAddr.from(
|
|
97992
|
-
this.config.vaultAllocator.address
|
|
97993
|
-
);
|
|
97994
|
-
const toToken = this.config.supportedPositions[0].asset;
|
|
97995
|
-
const fromToken = this.config.supportedPositions[1].asset;
|
|
97996
|
-
return [
|
|
97997
|
-
{
|
|
97998
|
-
target: fromToken.address,
|
|
97999
|
-
method: "approve",
|
|
98000
|
-
packedArguments: [
|
|
98001
|
-
AVNU_EXCHANGE.toBigInt()
|
|
98002
|
-
],
|
|
98003
|
-
sanitizer: SIMPLE_SANITIZER,
|
|
98004
|
-
id: `approve_${fromToken.symbol}`
|
|
98005
|
-
},
|
|
98006
|
-
{
|
|
98007
|
-
target: AVNU_EXCHANGE,
|
|
98008
|
-
method: "multi_route_swap",
|
|
98009
|
-
packedArguments: [
|
|
98010
|
-
fromToken.address.toBigInt(),
|
|
98011
|
-
//wbtc
|
|
98012
|
-
toToken.address.toBigInt(),
|
|
98013
|
-
//usdc
|
|
98014
|
-
vaultAllocator.toBigInt()
|
|
98015
|
-
],
|
|
98016
|
-
sanitizer: SIMPLE_SANITIZER,
|
|
98017
|
-
id: `asbtu_${fromToken.symbol}_${fromToken.symbol}`
|
|
98018
|
-
}
|
|
98019
|
-
];
|
|
98020
|
-
}
|
|
98021
|
-
_getLegacySwapLeaf() {
|
|
98022
|
-
return [];
|
|
98023
|
-
}
|
|
98024
|
-
async getDepositCall(params) {
|
|
98025
|
-
try {
|
|
98026
|
-
const fromToken = this.config.supportedPositions[0].asset;
|
|
98027
|
-
const toToken = this.config.supportedPositions[1].asset;
|
|
98028
|
-
const vaultAllocator = ContractAddr.from(
|
|
98029
|
-
this.config.vaultAllocator.address
|
|
98030
|
-
);
|
|
98031
|
-
const quote = await this.getQuotesAvnu(
|
|
98032
|
-
fromToken.address.toString(),
|
|
98033
|
-
toToken.address.toString(),
|
|
98034
|
-
params.amount.toNumber(),
|
|
98035
|
-
vaultAllocator.address.toString(),
|
|
98036
|
-
toToken.decimals,
|
|
98037
|
-
true
|
|
98038
|
-
);
|
|
98039
|
-
if (!quote) {
|
|
98040
|
-
logger2.error("error getting quote from avnu");
|
|
98041
|
-
return [];
|
|
98042
|
-
}
|
|
98043
|
-
const getCalldata = await this.avnuWrapper.getSwapCallData(
|
|
98044
|
-
quote,
|
|
98045
|
-
vaultAllocator.address
|
|
98046
|
-
);
|
|
98047
|
-
const swapCallData = getCalldata[0];
|
|
98048
|
-
const amount = uint256_exports.bnToUint256(quote.sellAmountInUsd * 10 ** 7);
|
|
98049
|
-
return [
|
|
98050
|
-
{
|
|
98051
|
-
sanitizer: SIMPLE_SANITIZER,
|
|
98052
|
-
call: {
|
|
98053
|
-
contractAddress: fromToken.address,
|
|
98054
|
-
selector: hash_exports.getSelectorFromName("approve"),
|
|
98055
|
-
calldata: [
|
|
98056
|
-
AVNU_EXCHANGE.toBigInt(),
|
|
98057
|
-
toBigInt3(amount.low.toString()),
|
|
98058
|
-
// amount low
|
|
98059
|
-
toBigInt3(amount.high.toString())
|
|
98060
|
-
// amount high
|
|
98061
|
-
]
|
|
98062
|
-
}
|
|
98063
|
-
},
|
|
98064
|
-
{
|
|
98065
|
-
sanitizer: SIMPLE_SANITIZER,
|
|
98066
|
-
call: {
|
|
98067
|
-
contractAddress: AVNU_EXCHANGE,
|
|
98068
|
-
selector: hash_exports.getSelectorFromName("multi_route_swap"),
|
|
98069
|
-
calldata: swapCallData
|
|
98070
|
-
}
|
|
98071
|
-
}
|
|
98072
|
-
];
|
|
98073
|
-
} catch (error2) {
|
|
98074
|
-
logger2.error(`Error getting Avnu quote: ${error2}`);
|
|
98075
|
-
return [];
|
|
98076
|
-
}
|
|
98077
|
-
}
|
|
98078
|
-
//Swap wbtc to usdc
|
|
98079
|
-
async getWithdrawCall(params) {
|
|
98080
|
-
try {
|
|
98081
|
-
const toToken = this.config.supportedPositions[0].asset;
|
|
98082
|
-
const fromToken = this.config.supportedPositions[1].asset;
|
|
98083
|
-
const vaultAllocator = ContractAddr.from(
|
|
98084
|
-
this.config.vaultAllocator.address
|
|
98085
|
-
);
|
|
98086
|
-
const quote = await this.getQuotesAvnu(
|
|
98087
|
-
fromToken.address.toString(),
|
|
98088
|
-
toToken.address.toString(),
|
|
98089
|
-
params.amount.toNumber(),
|
|
98090
|
-
vaultAllocator.address.toString(),
|
|
98091
|
-
fromToken.decimals,
|
|
98092
|
-
false
|
|
98093
|
-
);
|
|
98094
|
-
if (!quote) {
|
|
98095
|
-
logger2.error("No quotes available for this swap, error in quotes avnu");
|
|
98096
|
-
return [];
|
|
98097
|
-
}
|
|
98098
|
-
const getCalldata = await this.avnuWrapper.getSwapCallData(
|
|
98099
|
-
quote,
|
|
98100
|
-
vaultAllocator.address
|
|
98101
|
-
);
|
|
98102
|
-
const swapCallData = getCalldata[0];
|
|
98103
|
-
const amount = uint256_exports.bnToUint256(params.amount.toWei());
|
|
98104
|
-
return [
|
|
98105
|
-
{
|
|
98106
|
-
sanitizer: SIMPLE_SANITIZER,
|
|
98107
|
-
call: {
|
|
98108
|
-
contractAddress: fromToken.address,
|
|
98109
|
-
selector: hash_exports.getSelectorFromName("approve"),
|
|
98110
|
-
calldata: [
|
|
98111
|
-
AVNU_EXCHANGE.toBigInt(),
|
|
98112
|
-
toBigInt3(amount.low.toString()),
|
|
98113
|
-
// amount low
|
|
98114
|
-
toBigInt3(amount.high.toString())
|
|
98115
|
-
// amount high
|
|
98116
|
-
]
|
|
98117
|
-
}
|
|
98118
|
-
},
|
|
98119
|
-
{
|
|
98120
|
-
sanitizer: SIMPLE_SANITIZER,
|
|
98121
|
-
call: {
|
|
98122
|
-
contractAddress: AVNU_EXCHANGE,
|
|
98123
|
-
selector: hash_exports.getSelectorFromName("multi_route_swap"),
|
|
98124
|
-
calldata: swapCallData
|
|
98125
|
-
}
|
|
98126
|
-
}
|
|
98127
|
-
];
|
|
98128
|
-
} catch (error2) {
|
|
98129
|
-
logger2.error(`Error getting Avnu quote: ${error2}`);
|
|
98130
|
-
return [];
|
|
98131
|
-
}
|
|
98132
|
-
}
|
|
98133
|
-
async getSwapCallData(quote) {
|
|
98134
|
-
return await this.avnuWrapper.getSwapCallData(quote, this.config.vaultAllocator.address);
|
|
98135
|
-
}
|
|
98136
|
-
async getHealthFactor() {
|
|
98137
|
-
return Promise.resolve(1);
|
|
98138
|
-
}
|
|
98139
|
-
async fetchQuoteWithRetry(params, retries = 5) {
|
|
98140
|
-
for (let attempt = 0; attempt < retries; attempt++) {
|
|
98141
|
-
try {
|
|
98142
|
-
const response = await axios_default.get(this.config.baseUrl, { params });
|
|
98143
|
-
if (response.data && response.data.length > 0) {
|
|
98144
|
-
return response;
|
|
98145
|
-
}
|
|
98146
|
-
throw new Error("Empty response data");
|
|
98147
|
-
} catch (err2) {
|
|
98148
|
-
logger2.error(`Error fetching quote with retry: ${err2}`);
|
|
98149
|
-
if (attempt === retries - 1) {
|
|
98150
|
-
throw err2;
|
|
98151
|
-
}
|
|
98152
|
-
await new Promise((resolve) => setTimeout(resolve, MAX_DELAY));
|
|
98153
|
-
}
|
|
98154
|
-
}
|
|
98155
|
-
throw new Error("Failed to fetch quote after retries");
|
|
98156
|
-
}
|
|
98157
|
-
async getQuotesAvnu(from_token_address, to_token_address, amount, takerAddress, toTokenDecimals, usdcToBtc, maxIterations = 5, tolerance = 5e3) {
|
|
98158
|
-
try {
|
|
98159
|
-
const fromToken = this.config.supportedPositions[0].asset;
|
|
98160
|
-
const toToken = this.config.supportedPositions[1].asset;
|
|
98161
|
-
if (!usdcToBtc) {
|
|
98162
|
-
const sellAmount2 = returnFormattedAmount(amount, toTokenDecimals);
|
|
98163
|
-
const params2 = {
|
|
98164
|
-
sellTokenAddress: from_token_address,
|
|
98165
|
-
buyTokenAddress: to_token_address,
|
|
98166
|
-
takerAddress,
|
|
98167
|
-
sellAmount: sellAmount2
|
|
98168
|
-
};
|
|
98169
|
-
const finalQuote2 = await this.fetchQuoteWithRetry(params2);
|
|
98170
|
-
if (!finalQuote2.data.length) {
|
|
98171
|
-
logger2.error("No quotes available for this swap, error in quotes avnu");
|
|
98172
|
-
return null;
|
|
98173
|
-
}
|
|
98174
|
-
const dataObject2 = finalQuote2.data[0];
|
|
98175
|
-
return dataObject2;
|
|
98176
|
-
}
|
|
98177
|
-
const btcPrice = await this.getPriceOfToken(toToken.address.toString());
|
|
98178
|
-
if (!btcPrice) {
|
|
98179
|
-
logger2.error(`error getting btc price: ${btcPrice}`);
|
|
98180
|
-
return null;
|
|
98181
|
-
}
|
|
98182
|
-
const estimatedUsdcAmount = Math.floor(amount * btcPrice);
|
|
98183
|
-
const targetBtcBig = BigInt(returnFormattedAmount(amount, toTokenDecimals));
|
|
98184
|
-
let low = BigInt(
|
|
98185
|
-
Math.floor(
|
|
98186
|
-
estimatedUsdcAmount * 10 ** fromToken.decimals * 0.9
|
|
98187
|
-
)
|
|
98188
|
-
);
|
|
98189
|
-
let high = BigInt(
|
|
98190
|
-
Math.floor(
|
|
98191
|
-
estimatedUsdcAmount * 10 ** fromToken.decimals * 1.1
|
|
98192
|
-
)
|
|
98193
|
-
);
|
|
98194
|
-
let mid = 0n;
|
|
98195
|
-
for (let i = 0; i < maxIterations; i++) {
|
|
98196
|
-
mid = (low + high) / 2n;
|
|
98197
|
-
const sellAmount2 = returnFormattedAmount(Number(mid), 0);
|
|
98198
|
-
const quote = await this.fetchQuoteWithRetry({
|
|
98199
|
-
sellTokenAddress: from_token_address,
|
|
98200
|
-
buyTokenAddress: to_token_address,
|
|
98201
|
-
takerAddress,
|
|
98202
|
-
sellAmount: sellAmount2
|
|
98203
|
-
});
|
|
98204
|
-
const gotBtc = BigInt(quote.data[0].buyAmount);
|
|
98205
|
-
if (gotBtc === targetBtcBig) return quote.data[0];
|
|
98206
|
-
if (gotBtc > targetBtcBig) {
|
|
98207
|
-
high = mid;
|
|
98208
|
-
} else {
|
|
98209
|
-
low = mid;
|
|
98210
|
-
}
|
|
98211
|
-
if (gotBtc >= targetBtcBig && gotBtc <= targetBtcBig + BigInt(tolerance)) {
|
|
98212
|
-
return quote.data[0];
|
|
98213
|
-
}
|
|
98214
|
-
}
|
|
98215
|
-
let sellAmount = returnFormattedAmount(
|
|
98216
|
-
Number(mid),
|
|
98217
|
-
0
|
|
98218
|
-
);
|
|
98219
|
-
const params = {
|
|
98220
|
-
sellTokenAddress: from_token_address,
|
|
98221
|
-
buyTokenAddress: to_token_address,
|
|
98222
|
-
takerAddress,
|
|
98223
|
-
sellAmount
|
|
98224
|
-
};
|
|
98225
|
-
const finalQuote = await this.fetchQuoteWithRetry(params);
|
|
98226
|
-
if (!finalQuote.data.length) {
|
|
98227
|
-
logger2.error("No quotes available for this swap, error in quotes avnu");
|
|
98228
|
-
return null;
|
|
98229
|
-
}
|
|
98230
|
-
const dataObject = finalQuote.data[0];
|
|
98231
|
-
return dataObject;
|
|
98232
|
-
} catch (err2) {
|
|
98233
|
-
logger2.error(`No quotes available for this swap: ${err2}`);
|
|
98234
|
-
return null;
|
|
98235
|
-
}
|
|
98236
|
-
}
|
|
98237
|
-
async getPriceOfToken(tokenAddress, retries = MAX_RETRIES) {
|
|
98238
|
-
try {
|
|
98239
|
-
const url = `https://starknet.impulse.avnu.fi/v1/tokens/${tokenAddress}/prices/line`;
|
|
98240
|
-
const response = await axios_default.get(url);
|
|
98241
|
-
const length = response.data.length;
|
|
98242
|
-
return response.data[length - 1].value;
|
|
98243
|
-
} catch (err2) {
|
|
98244
|
-
if (retries > 0) {
|
|
98245
|
-
await new Promise((resolve) => setTimeout(resolve, MAX_DELAY));
|
|
98246
|
-
return this.getPriceOfToken(tokenAddress, retries - 1);
|
|
98247
|
-
} else {
|
|
98248
|
-
logger2.error(`Failed to fetch price for ${tokenAddress} after ${MAX_RETRIES} attempts`);
|
|
98249
|
-
return null;
|
|
98250
|
-
}
|
|
98251
|
-
}
|
|
98252
|
-
}
|
|
98253
|
-
};
|
|
98254
|
-
|
|
98255
98272
|
// src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx
|
|
98256
98273
|
var import_jsx_runtime5 = __toESM(require_jsx_runtime());
|
|
98257
98274
|
var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy extends SVKStrategy {
|
|
@@ -99393,11 +99410,11 @@ spurious results.`);
|
|
|
99393
99410
|
] });
|
|
99394
99411
|
}
|
|
99395
99412
|
var re7UsdcPrimeDevansh = {
|
|
99396
|
-
vaultAddress: ContractAddr.from("
|
|
99397
|
-
manager: ContractAddr.from("
|
|
99398
|
-
vaultAllocator: ContractAddr.from("
|
|
99399
|
-
redeemRequestNFT: ContractAddr.from("
|
|
99400
|
-
aumOracle: ContractAddr.from("
|
|
99413
|
+
vaultAddress: ContractAddr.from("0x058905be22d6a81792df79425dc9641cf3e1b77f36748631b7d7e5d713a32b55"),
|
|
99414
|
+
manager: ContractAddr.from("0x02648d703783feb2d967cf0520314cb5aa800d69a9426f3e3b317395af44de16"),
|
|
99415
|
+
vaultAllocator: ContractAddr.from("0x07d533c838eab6a4d854dd3aea96a55993fccd35821921970d00bde946b63b6f"),
|
|
99416
|
+
redeemRequestNFT: ContractAddr.from("0x01ef91f08fb99729c00f82fc6e0ece37917bcc43952596c19996259dc8adbbba"),
|
|
99417
|
+
aumOracle: ContractAddr.from("0x030b6acfec162f5d6e72b8a4d2798aedce78fb39de78a8f549f7cd277ae8bc8d"),
|
|
99401
99418
|
leafAdapters: [],
|
|
99402
99419
|
adapters: [],
|
|
99403
99420
|
targetHealthFactor: 1.4,
|