@strkfarm/sdk 2.0.0-dev.13 → 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 +345 -328
- package/dist/index.browser.mjs +807 -790
- package/dist/index.d.ts +19 -1
- package/dist/index.js +353 -334
- package/dist/index.mjs +807 -790
- 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/dist/index.js
CHANGED
|
@@ -43,6 +43,7 @@ __export(index_exports, {
|
|
|
43
43
|
AssetOperationStatus: () => AssetOperationStatus,
|
|
44
44
|
AssetOperationType: () => AssetOperationType,
|
|
45
45
|
AutoCompounderSTRK: () => AutoCompounderSTRK,
|
|
46
|
+
AvnuAdapter: () => AvnuAdapter,
|
|
46
47
|
AvnuWrapper: () => AvnuWrapper,
|
|
47
48
|
BaseAdapter: () => BaseAdapter,
|
|
48
49
|
BaseStrategy: () => BaseStrategy,
|
|
@@ -126,6 +127,7 @@ __export(index_exports, {
|
|
|
126
127
|
calculateExtendedLevergae: () => calculateExtendedLevergae,
|
|
127
128
|
calculateVesUPositionSizeGivenExtended: () => calculateVesUPositionSizeGivenExtended,
|
|
128
129
|
calculateVesuLeverage: () => calculateVesuLeverage,
|
|
130
|
+
calculateWBTCAmountToMaintainLTV: () => calculateWBTCAmountToMaintainLTV,
|
|
129
131
|
extensionMap: () => extensionMap,
|
|
130
132
|
getAPIUsingHeadlessBrowser: () => getAPIUsingHeadlessBrowser,
|
|
131
133
|
getContractDetails: () => getContractDetails,
|
|
@@ -28351,6 +28353,21 @@ var calculateAmountDepositOnExtendedWhenIncurringLosses = async (client) => {
|
|
|
28351
28353
|
return null;
|
|
28352
28354
|
}
|
|
28353
28355
|
};
|
|
28356
|
+
var calculateWBTCAmountToMaintainLTV = (collateralAmount, debtAmount, debtPrice, maxLtv = MAX_LIQUIDATION_RATIO, collateralPrice, targetHF = TARGET_HF) => {
|
|
28357
|
+
try {
|
|
28358
|
+
const numerator1 = collateralAmount.multipliedBy(collateralPrice).multipliedBy(maxLtv);
|
|
28359
|
+
const numerator2 = debtAmount.multipliedBy(debtPrice).multipliedBy(targetHF);
|
|
28360
|
+
const denominator = maxLtv;
|
|
28361
|
+
const collateralAmountToMaintainLTV = numerator2.minus(numerator1).dividedBy(denominator);
|
|
28362
|
+
let deltaCollateralAmountUnits = new Web3Number(
|
|
28363
|
+
collateralAmountToMaintainLTV.dividedBy(collateralPrice).toFixed(WBTC_TOKEN_DECIMALS),
|
|
28364
|
+
WBTC_TOKEN_DECIMALS
|
|
28365
|
+
);
|
|
28366
|
+
return { deltaCollateralAmountUnits };
|
|
28367
|
+
} catch (err) {
|
|
28368
|
+
return { deltaCollateralAmountUnits: null };
|
|
28369
|
+
}
|
|
28370
|
+
};
|
|
28354
28371
|
var calculateExposureDelta = (exposure_extended, exposure_vesu) => {
|
|
28355
28372
|
const exposure_delta = new Web3Number(exposure_extended - exposure_vesu, 2);
|
|
28356
28373
|
return exposure_delta.absoluteValue().toNumber();
|
|
@@ -30632,6 +30649,336 @@ var UnusedBalanceAdapter = class _UnusedBalanceAdapter extends BaseAdapter {
|
|
|
30632
30649
|
}
|
|
30633
30650
|
};
|
|
30634
30651
|
|
|
30652
|
+
// src/strategies/universal-adapters/avnu-adapter.ts
|
|
30653
|
+
var import_starknet23 = require("starknet");
|
|
30654
|
+
var import_axios9 = __toESM(require("axios"));
|
|
30655
|
+
var AvnuAdapter = class _AvnuAdapter extends BaseAdapter {
|
|
30656
|
+
constructor(config) {
|
|
30657
|
+
super(config, _AvnuAdapter.name, Protocols.AVNU);
|
|
30658
|
+
this.config = config;
|
|
30659
|
+
this.avnuWrapper = new AvnuWrapper();
|
|
30660
|
+
}
|
|
30661
|
+
//abstract means the method has no implementation in this class; instead, child classes must implement it.
|
|
30662
|
+
async getAPY(supportedPosition) {
|
|
30663
|
+
return Promise.resolve({ apy: 0, type: "base" /* BASE */ });
|
|
30664
|
+
}
|
|
30665
|
+
async getPosition(supportedPosition) {
|
|
30666
|
+
return Promise.resolve({ amount: new Web3Number(0, 0), remarks: "" });
|
|
30667
|
+
}
|
|
30668
|
+
async maxDeposit(amount) {
|
|
30669
|
+
return Promise.resolve({
|
|
30670
|
+
tokenInfo: this.config.baseToken,
|
|
30671
|
+
amount: new Web3Number(0, 0),
|
|
30672
|
+
usdValue: 0,
|
|
30673
|
+
apy: { apy: 0, type: "base" /* BASE */ },
|
|
30674
|
+
protocol: Protocols.AVNU,
|
|
30675
|
+
remarks: ""
|
|
30676
|
+
});
|
|
30677
|
+
}
|
|
30678
|
+
async maxWithdraw() {
|
|
30679
|
+
return Promise.resolve({
|
|
30680
|
+
tokenInfo: this.config.baseToken,
|
|
30681
|
+
amount: new Web3Number(0, 0),
|
|
30682
|
+
usdValue: 0,
|
|
30683
|
+
apy: { apy: 0, type: "base" /* BASE */ },
|
|
30684
|
+
protocol: Protocols.AVNU,
|
|
30685
|
+
remarks: ""
|
|
30686
|
+
});
|
|
30687
|
+
}
|
|
30688
|
+
_getDepositLeaf() {
|
|
30689
|
+
const vaultAllocator = ContractAddr.from(
|
|
30690
|
+
this.config.vaultAllocator.address
|
|
30691
|
+
);
|
|
30692
|
+
return [
|
|
30693
|
+
{
|
|
30694
|
+
target: this.config.supportedPositions[0].asset.address,
|
|
30695
|
+
method: "approve",
|
|
30696
|
+
packedArguments: [
|
|
30697
|
+
AVNU_EXCHANGE.toBigInt()
|
|
30698
|
+
],
|
|
30699
|
+
sanitizer: SIMPLE_SANITIZER,
|
|
30700
|
+
id: `approve_${this.config.supportedPositions[0].asset.symbol}`
|
|
30701
|
+
},
|
|
30702
|
+
{
|
|
30703
|
+
target: AVNU_EXCHANGE,
|
|
30704
|
+
method: "multi_route_swap",
|
|
30705
|
+
packedArguments: [
|
|
30706
|
+
this.config.supportedPositions[0].asset.address.toBigInt(),
|
|
30707
|
+
//usdc
|
|
30708
|
+
this.config.supportedPositions[1].asset.address.toBigInt(),
|
|
30709
|
+
//wbtc
|
|
30710
|
+
vaultAllocator.toBigInt()
|
|
30711
|
+
],
|
|
30712
|
+
sanitizer: SIMPLE_SANITIZER,
|
|
30713
|
+
id: `asutb_${this.config.supportedPositions[0].asset.symbol}_${this.config.supportedPositions[1].asset.symbol}`
|
|
30714
|
+
}
|
|
30715
|
+
];
|
|
30716
|
+
}
|
|
30717
|
+
_getWithdrawLeaf() {
|
|
30718
|
+
const vaultAllocator = ContractAddr.from(
|
|
30719
|
+
this.config.vaultAllocator.address
|
|
30720
|
+
);
|
|
30721
|
+
const toToken = this.config.supportedPositions[0].asset;
|
|
30722
|
+
const fromToken = this.config.supportedPositions[1].asset;
|
|
30723
|
+
return [
|
|
30724
|
+
{
|
|
30725
|
+
target: fromToken.address,
|
|
30726
|
+
method: "approve",
|
|
30727
|
+
packedArguments: [
|
|
30728
|
+
AVNU_EXCHANGE.toBigInt()
|
|
30729
|
+
],
|
|
30730
|
+
sanitizer: SIMPLE_SANITIZER,
|
|
30731
|
+
id: `approve_${fromToken.symbol}`
|
|
30732
|
+
},
|
|
30733
|
+
{
|
|
30734
|
+
target: AVNU_EXCHANGE,
|
|
30735
|
+
method: "multi_route_swap",
|
|
30736
|
+
packedArguments: [
|
|
30737
|
+
fromToken.address.toBigInt(),
|
|
30738
|
+
//wbtc
|
|
30739
|
+
toToken.address.toBigInt(),
|
|
30740
|
+
//usdc
|
|
30741
|
+
vaultAllocator.toBigInt()
|
|
30742
|
+
],
|
|
30743
|
+
sanitizer: SIMPLE_SANITIZER,
|
|
30744
|
+
id: `asbtu_${fromToken.symbol}_${fromToken.symbol}`
|
|
30745
|
+
}
|
|
30746
|
+
];
|
|
30747
|
+
}
|
|
30748
|
+
_getLegacySwapLeaf() {
|
|
30749
|
+
return [];
|
|
30750
|
+
}
|
|
30751
|
+
async getDepositCall(params) {
|
|
30752
|
+
try {
|
|
30753
|
+
const fromToken = this.config.supportedPositions[0].asset;
|
|
30754
|
+
const toToken = this.config.supportedPositions[1].asset;
|
|
30755
|
+
const vaultAllocator = ContractAddr.from(
|
|
30756
|
+
this.config.vaultAllocator.address
|
|
30757
|
+
);
|
|
30758
|
+
const quote = await this.getQuotesAvnu(
|
|
30759
|
+
fromToken.address.toString(),
|
|
30760
|
+
toToken.address.toString(),
|
|
30761
|
+
params.amount.toNumber(),
|
|
30762
|
+
vaultAllocator.address.toString(),
|
|
30763
|
+
toToken.decimals,
|
|
30764
|
+
true
|
|
30765
|
+
);
|
|
30766
|
+
if (!quote) {
|
|
30767
|
+
logger.error("error getting quote from avnu");
|
|
30768
|
+
return [];
|
|
30769
|
+
}
|
|
30770
|
+
const getCalldata = await this.avnuWrapper.getSwapCallData(
|
|
30771
|
+
quote,
|
|
30772
|
+
vaultAllocator.address
|
|
30773
|
+
);
|
|
30774
|
+
const swapCallData = getCalldata[0];
|
|
30775
|
+
const amount = import_starknet23.uint256.bnToUint256(quote.sellAmountInUsd * 10 ** 7);
|
|
30776
|
+
return [
|
|
30777
|
+
{
|
|
30778
|
+
sanitizer: SIMPLE_SANITIZER,
|
|
30779
|
+
call: {
|
|
30780
|
+
contractAddress: fromToken.address,
|
|
30781
|
+
selector: import_starknet23.hash.getSelectorFromName("approve"),
|
|
30782
|
+
calldata: [
|
|
30783
|
+
AVNU_EXCHANGE.toBigInt(),
|
|
30784
|
+
toBigInt(amount.low.toString()),
|
|
30785
|
+
// amount low
|
|
30786
|
+
toBigInt(amount.high.toString())
|
|
30787
|
+
// amount high
|
|
30788
|
+
]
|
|
30789
|
+
}
|
|
30790
|
+
},
|
|
30791
|
+
{
|
|
30792
|
+
sanitizer: SIMPLE_SANITIZER,
|
|
30793
|
+
call: {
|
|
30794
|
+
contractAddress: AVNU_EXCHANGE,
|
|
30795
|
+
selector: import_starknet23.hash.getSelectorFromName("multi_route_swap"),
|
|
30796
|
+
calldata: swapCallData
|
|
30797
|
+
}
|
|
30798
|
+
}
|
|
30799
|
+
];
|
|
30800
|
+
} catch (error) {
|
|
30801
|
+
logger.error(`Error getting Avnu quote: ${error}`);
|
|
30802
|
+
return [];
|
|
30803
|
+
}
|
|
30804
|
+
}
|
|
30805
|
+
//Swap wbtc to usdc
|
|
30806
|
+
async getWithdrawCall(params) {
|
|
30807
|
+
try {
|
|
30808
|
+
const toToken = this.config.supportedPositions[0].asset;
|
|
30809
|
+
const fromToken = this.config.supportedPositions[1].asset;
|
|
30810
|
+
const vaultAllocator = ContractAddr.from(
|
|
30811
|
+
this.config.vaultAllocator.address
|
|
30812
|
+
);
|
|
30813
|
+
const quote = await this.getQuotesAvnu(
|
|
30814
|
+
fromToken.address.toString(),
|
|
30815
|
+
toToken.address.toString(),
|
|
30816
|
+
params.amount.toNumber(),
|
|
30817
|
+
vaultAllocator.address.toString(),
|
|
30818
|
+
fromToken.decimals,
|
|
30819
|
+
false
|
|
30820
|
+
);
|
|
30821
|
+
if (!quote) {
|
|
30822
|
+
logger.error("No quotes available for this swap, error in quotes avnu");
|
|
30823
|
+
return [];
|
|
30824
|
+
}
|
|
30825
|
+
const getCalldata = await this.avnuWrapper.getSwapCallData(
|
|
30826
|
+
quote,
|
|
30827
|
+
vaultAllocator.address
|
|
30828
|
+
);
|
|
30829
|
+
const swapCallData = getCalldata[0];
|
|
30830
|
+
const amount = import_starknet23.uint256.bnToUint256(params.amount.toWei());
|
|
30831
|
+
return [
|
|
30832
|
+
{
|
|
30833
|
+
sanitizer: SIMPLE_SANITIZER,
|
|
30834
|
+
call: {
|
|
30835
|
+
contractAddress: fromToken.address,
|
|
30836
|
+
selector: import_starknet23.hash.getSelectorFromName("approve"),
|
|
30837
|
+
calldata: [
|
|
30838
|
+
AVNU_EXCHANGE.toBigInt(),
|
|
30839
|
+
toBigInt(amount.low.toString()),
|
|
30840
|
+
// amount low
|
|
30841
|
+
toBigInt(amount.high.toString())
|
|
30842
|
+
// amount high
|
|
30843
|
+
]
|
|
30844
|
+
}
|
|
30845
|
+
},
|
|
30846
|
+
{
|
|
30847
|
+
sanitizer: SIMPLE_SANITIZER,
|
|
30848
|
+
call: {
|
|
30849
|
+
contractAddress: AVNU_EXCHANGE,
|
|
30850
|
+
selector: import_starknet23.hash.getSelectorFromName("multi_route_swap"),
|
|
30851
|
+
calldata: swapCallData
|
|
30852
|
+
}
|
|
30853
|
+
}
|
|
30854
|
+
];
|
|
30855
|
+
} catch (error) {
|
|
30856
|
+
logger.error(`Error getting Avnu quote: ${error}`);
|
|
30857
|
+
return [];
|
|
30858
|
+
}
|
|
30859
|
+
}
|
|
30860
|
+
async getSwapCallData(quote) {
|
|
30861
|
+
return await this.avnuWrapper.getSwapCallData(quote, this.config.vaultAllocator.address);
|
|
30862
|
+
}
|
|
30863
|
+
async getHealthFactor() {
|
|
30864
|
+
return Promise.resolve(1);
|
|
30865
|
+
}
|
|
30866
|
+
async fetchQuoteWithRetry(params, retries = 5) {
|
|
30867
|
+
for (let attempt = 0; attempt < retries; attempt++) {
|
|
30868
|
+
try {
|
|
30869
|
+
const response = await import_axios9.default.get(this.config.baseUrl, { params });
|
|
30870
|
+
if (response.data && response.data.length > 0) {
|
|
30871
|
+
return response;
|
|
30872
|
+
}
|
|
30873
|
+
throw new Error("Empty response data");
|
|
30874
|
+
} catch (err) {
|
|
30875
|
+
logger.error(`Error fetching quote with retry: ${err}`);
|
|
30876
|
+
if (attempt === retries - 1) {
|
|
30877
|
+
throw err;
|
|
30878
|
+
}
|
|
30879
|
+
await new Promise((resolve) => setTimeout(resolve, MAX_DELAY));
|
|
30880
|
+
}
|
|
30881
|
+
}
|
|
30882
|
+
throw new Error("Failed to fetch quote after retries");
|
|
30883
|
+
}
|
|
30884
|
+
async getQuotesAvnu(from_token_address, to_token_address, amount, takerAddress, toTokenDecimals, usdcToBtc, maxIterations = 5, tolerance = 5e3) {
|
|
30885
|
+
try {
|
|
30886
|
+
const fromToken = this.config.supportedPositions[0].asset;
|
|
30887
|
+
const toToken = this.config.supportedPositions[1].asset;
|
|
30888
|
+
if (!usdcToBtc) {
|
|
30889
|
+
const sellAmount2 = returnFormattedAmount(amount, toTokenDecimals);
|
|
30890
|
+
const params2 = {
|
|
30891
|
+
sellTokenAddress: from_token_address,
|
|
30892
|
+
buyTokenAddress: to_token_address,
|
|
30893
|
+
takerAddress,
|
|
30894
|
+
sellAmount: sellAmount2
|
|
30895
|
+
};
|
|
30896
|
+
const finalQuote2 = await this.fetchQuoteWithRetry(params2);
|
|
30897
|
+
if (!finalQuote2.data.length) {
|
|
30898
|
+
logger.error("No quotes available for this swap, error in quotes avnu");
|
|
30899
|
+
return null;
|
|
30900
|
+
}
|
|
30901
|
+
const dataObject2 = finalQuote2.data[0];
|
|
30902
|
+
return dataObject2;
|
|
30903
|
+
}
|
|
30904
|
+
const btcPrice = await this.getPriceOfToken(toToken.address.toString());
|
|
30905
|
+
if (!btcPrice) {
|
|
30906
|
+
logger.error(`error getting btc price: ${btcPrice}`);
|
|
30907
|
+
return null;
|
|
30908
|
+
}
|
|
30909
|
+
const estimatedUsdcAmount = Math.floor(amount * btcPrice);
|
|
30910
|
+
const targetBtcBig = BigInt(returnFormattedAmount(amount, toTokenDecimals));
|
|
30911
|
+
let low = BigInt(
|
|
30912
|
+
Math.floor(
|
|
30913
|
+
estimatedUsdcAmount * 10 ** fromToken.decimals * 0.9
|
|
30914
|
+
)
|
|
30915
|
+
);
|
|
30916
|
+
let high = BigInt(
|
|
30917
|
+
Math.floor(
|
|
30918
|
+
estimatedUsdcAmount * 10 ** fromToken.decimals * 1.1
|
|
30919
|
+
)
|
|
30920
|
+
);
|
|
30921
|
+
let mid = 0n;
|
|
30922
|
+
for (let i = 0; i < maxIterations; i++) {
|
|
30923
|
+
mid = (low + high) / 2n;
|
|
30924
|
+
const sellAmount2 = returnFormattedAmount(Number(mid), 0);
|
|
30925
|
+
const quote = await this.fetchQuoteWithRetry({
|
|
30926
|
+
sellTokenAddress: from_token_address,
|
|
30927
|
+
buyTokenAddress: to_token_address,
|
|
30928
|
+
takerAddress,
|
|
30929
|
+
sellAmount: sellAmount2
|
|
30930
|
+
});
|
|
30931
|
+
const gotBtc = BigInt(quote.data[0].buyAmount);
|
|
30932
|
+
if (gotBtc === targetBtcBig) return quote.data[0];
|
|
30933
|
+
if (gotBtc > targetBtcBig) {
|
|
30934
|
+
high = mid;
|
|
30935
|
+
} else {
|
|
30936
|
+
low = mid;
|
|
30937
|
+
}
|
|
30938
|
+
if (gotBtc >= targetBtcBig && gotBtc <= targetBtcBig + BigInt(tolerance)) {
|
|
30939
|
+
return quote.data[0];
|
|
30940
|
+
}
|
|
30941
|
+
}
|
|
30942
|
+
let sellAmount = returnFormattedAmount(
|
|
30943
|
+
Number(mid),
|
|
30944
|
+
0
|
|
30945
|
+
);
|
|
30946
|
+
const params = {
|
|
30947
|
+
sellTokenAddress: from_token_address,
|
|
30948
|
+
buyTokenAddress: to_token_address,
|
|
30949
|
+
takerAddress,
|
|
30950
|
+
sellAmount
|
|
30951
|
+
};
|
|
30952
|
+
const finalQuote = await this.fetchQuoteWithRetry(params);
|
|
30953
|
+
if (!finalQuote.data.length) {
|
|
30954
|
+
logger.error("No quotes available for this swap, error in quotes avnu");
|
|
30955
|
+
return null;
|
|
30956
|
+
}
|
|
30957
|
+
const dataObject = finalQuote.data[0];
|
|
30958
|
+
return dataObject;
|
|
30959
|
+
} catch (err) {
|
|
30960
|
+
logger.error(`No quotes available for this swap: ${err}`);
|
|
30961
|
+
return null;
|
|
30962
|
+
}
|
|
30963
|
+
}
|
|
30964
|
+
async getPriceOfToken(tokenAddress, retries = MAX_RETRIES) {
|
|
30965
|
+
try {
|
|
30966
|
+
const url = `https://starknet.impulse.avnu.fi/v1/tokens/${tokenAddress}/prices/line`;
|
|
30967
|
+
const response = await import_axios9.default.get(url);
|
|
30968
|
+
const length = response.data.length;
|
|
30969
|
+
return response.data[length - 1].value;
|
|
30970
|
+
} catch (err) {
|
|
30971
|
+
if (retries > 0) {
|
|
30972
|
+
await new Promise((resolve) => setTimeout(resolve, MAX_DELAY));
|
|
30973
|
+
return this.getPriceOfToken(tokenAddress, retries - 1);
|
|
30974
|
+
} else {
|
|
30975
|
+
logger.error(`Failed to fetch price for ${tokenAddress} after ${MAX_RETRIES} attempts`);
|
|
30976
|
+
return null;
|
|
30977
|
+
}
|
|
30978
|
+
}
|
|
30979
|
+
}
|
|
30980
|
+
};
|
|
30981
|
+
|
|
30635
30982
|
// src/strategies/universal-strategy.tsx
|
|
30636
30983
|
var AUMTypes = /* @__PURE__ */ ((AUMTypes2) => {
|
|
30637
30984
|
AUMTypes2["FINALISED"] = "finalised";
|
|
@@ -30670,7 +31017,7 @@ function getContractDetails(settings) {
|
|
|
30670
31017
|
}
|
|
30671
31018
|
|
|
30672
31019
|
// src/strategies/svk-strategy.ts
|
|
30673
|
-
var
|
|
31020
|
+
var import_starknet24 = require("starknet");
|
|
30674
31021
|
|
|
30675
31022
|
// src/data/universal-vault.abi.json
|
|
30676
31023
|
var universal_vault_abi_default = [
|
|
@@ -32997,12 +33344,12 @@ var SVKStrategy = class extends BaseStrategy {
|
|
|
32997
33344
|
this.pricer = pricer;
|
|
32998
33345
|
this.metadata = metadata;
|
|
32999
33346
|
this.address = metadata.address;
|
|
33000
|
-
this.contract = new
|
|
33347
|
+
this.contract = new import_starknet24.Contract({
|
|
33001
33348
|
abi: universal_vault_abi_default,
|
|
33002
33349
|
address: this.address.address,
|
|
33003
33350
|
providerOrAccount: this.config.provider
|
|
33004
33351
|
});
|
|
33005
|
-
this.managerContract = new
|
|
33352
|
+
this.managerContract = new import_starknet24.Contract({
|
|
33006
33353
|
abi: vault_manager_abi_default,
|
|
33007
33354
|
address: this.metadata.additionalInfo.manager.address,
|
|
33008
33355
|
providerOrAccount: this.config.provider
|
|
@@ -33115,7 +33462,7 @@ var SVKStrategy = class extends BaseStrategy {
|
|
|
33115
33462
|
getSetManagerCall(strategist, root = this.getMerkleRoot()) {
|
|
33116
33463
|
return this.managerContract.populate("set_manage_root", [
|
|
33117
33464
|
strategist.address,
|
|
33118
|
-
|
|
33465
|
+
import_starknet24.num.getHexString(root)
|
|
33119
33466
|
]);
|
|
33120
33467
|
}
|
|
33121
33468
|
/**
|
|
@@ -34053,336 +34400,6 @@ var HyperLSTStrategies = [
|
|
|
34053
34400
|
getStrategySettings("mRe7YIELD", "mRe7YIELD", hypermRe7YIELD, false, false)
|
|
34054
34401
|
];
|
|
34055
34402
|
|
|
34056
|
-
// src/strategies/universal-adapters/avnu-adapter.ts
|
|
34057
|
-
var import_starknet24 = require("starknet");
|
|
34058
|
-
var import_axios9 = __toESM(require("axios"));
|
|
34059
|
-
var AvnuAdapter = class _AvnuAdapter extends BaseAdapter {
|
|
34060
|
-
constructor(config) {
|
|
34061
|
-
super(config, _AvnuAdapter.name, Protocols.AVNU);
|
|
34062
|
-
this.config = config;
|
|
34063
|
-
this.avnuWrapper = new AvnuWrapper();
|
|
34064
|
-
}
|
|
34065
|
-
//abstract means the method has no implementation in this class; instead, child classes must implement it.
|
|
34066
|
-
async getAPY(supportedPosition) {
|
|
34067
|
-
return Promise.resolve({ apy: 0, type: "base" /* BASE */ });
|
|
34068
|
-
}
|
|
34069
|
-
async getPosition(supportedPosition) {
|
|
34070
|
-
return Promise.resolve({ amount: new Web3Number(0, 0), remarks: "" });
|
|
34071
|
-
}
|
|
34072
|
-
async maxDeposit(amount) {
|
|
34073
|
-
return Promise.resolve({
|
|
34074
|
-
tokenInfo: this.config.baseToken,
|
|
34075
|
-
amount: new Web3Number(0, 0),
|
|
34076
|
-
usdValue: 0,
|
|
34077
|
-
apy: { apy: 0, type: "base" /* BASE */ },
|
|
34078
|
-
protocol: Protocols.AVNU,
|
|
34079
|
-
remarks: ""
|
|
34080
|
-
});
|
|
34081
|
-
}
|
|
34082
|
-
async maxWithdraw() {
|
|
34083
|
-
return Promise.resolve({
|
|
34084
|
-
tokenInfo: this.config.baseToken,
|
|
34085
|
-
amount: new Web3Number(0, 0),
|
|
34086
|
-
usdValue: 0,
|
|
34087
|
-
apy: { apy: 0, type: "base" /* BASE */ },
|
|
34088
|
-
protocol: Protocols.AVNU,
|
|
34089
|
-
remarks: ""
|
|
34090
|
-
});
|
|
34091
|
-
}
|
|
34092
|
-
_getDepositLeaf() {
|
|
34093
|
-
const vaultAllocator = ContractAddr.from(
|
|
34094
|
-
this.config.vaultAllocator.address
|
|
34095
|
-
);
|
|
34096
|
-
return [
|
|
34097
|
-
{
|
|
34098
|
-
target: this.config.supportedPositions[0].asset.address,
|
|
34099
|
-
method: "approve",
|
|
34100
|
-
packedArguments: [
|
|
34101
|
-
AVNU_EXCHANGE.toBigInt()
|
|
34102
|
-
],
|
|
34103
|
-
sanitizer: SIMPLE_SANITIZER,
|
|
34104
|
-
id: `approve_${this.config.supportedPositions[0].asset.symbol}`
|
|
34105
|
-
},
|
|
34106
|
-
{
|
|
34107
|
-
target: AVNU_EXCHANGE,
|
|
34108
|
-
method: "multi_route_swap",
|
|
34109
|
-
packedArguments: [
|
|
34110
|
-
this.config.supportedPositions[0].asset.address.toBigInt(),
|
|
34111
|
-
//usdc
|
|
34112
|
-
this.config.supportedPositions[1].asset.address.toBigInt(),
|
|
34113
|
-
//wbtc
|
|
34114
|
-
vaultAllocator.toBigInt()
|
|
34115
|
-
],
|
|
34116
|
-
sanitizer: SIMPLE_SANITIZER,
|
|
34117
|
-
id: `asutb_${this.config.supportedPositions[0].asset.symbol}_${this.config.supportedPositions[1].asset.symbol}`
|
|
34118
|
-
}
|
|
34119
|
-
];
|
|
34120
|
-
}
|
|
34121
|
-
_getWithdrawLeaf() {
|
|
34122
|
-
const vaultAllocator = ContractAddr.from(
|
|
34123
|
-
this.config.vaultAllocator.address
|
|
34124
|
-
);
|
|
34125
|
-
const toToken = this.config.supportedPositions[0].asset;
|
|
34126
|
-
const fromToken = this.config.supportedPositions[1].asset;
|
|
34127
|
-
return [
|
|
34128
|
-
{
|
|
34129
|
-
target: fromToken.address,
|
|
34130
|
-
method: "approve",
|
|
34131
|
-
packedArguments: [
|
|
34132
|
-
AVNU_EXCHANGE.toBigInt()
|
|
34133
|
-
],
|
|
34134
|
-
sanitizer: SIMPLE_SANITIZER,
|
|
34135
|
-
id: `approve_${fromToken.symbol}`
|
|
34136
|
-
},
|
|
34137
|
-
{
|
|
34138
|
-
target: AVNU_EXCHANGE,
|
|
34139
|
-
method: "multi_route_swap",
|
|
34140
|
-
packedArguments: [
|
|
34141
|
-
fromToken.address.toBigInt(),
|
|
34142
|
-
//wbtc
|
|
34143
|
-
toToken.address.toBigInt(),
|
|
34144
|
-
//usdc
|
|
34145
|
-
vaultAllocator.toBigInt()
|
|
34146
|
-
],
|
|
34147
|
-
sanitizer: SIMPLE_SANITIZER,
|
|
34148
|
-
id: `asbtu_${fromToken.symbol}_${fromToken.symbol}`
|
|
34149
|
-
}
|
|
34150
|
-
];
|
|
34151
|
-
}
|
|
34152
|
-
_getLegacySwapLeaf() {
|
|
34153
|
-
return [];
|
|
34154
|
-
}
|
|
34155
|
-
async getDepositCall(params) {
|
|
34156
|
-
try {
|
|
34157
|
-
const fromToken = this.config.supportedPositions[0].asset;
|
|
34158
|
-
const toToken = this.config.supportedPositions[1].asset;
|
|
34159
|
-
const vaultAllocator = ContractAddr.from(
|
|
34160
|
-
this.config.vaultAllocator.address
|
|
34161
|
-
);
|
|
34162
|
-
const quote = await this.getQuotesAvnu(
|
|
34163
|
-
fromToken.address.toString(),
|
|
34164
|
-
toToken.address.toString(),
|
|
34165
|
-
params.amount.toNumber(),
|
|
34166
|
-
vaultAllocator.address.toString(),
|
|
34167
|
-
toToken.decimals,
|
|
34168
|
-
true
|
|
34169
|
-
);
|
|
34170
|
-
if (!quote) {
|
|
34171
|
-
logger.error("error getting quote from avnu");
|
|
34172
|
-
return [];
|
|
34173
|
-
}
|
|
34174
|
-
const getCalldata = await this.avnuWrapper.getSwapCallData(
|
|
34175
|
-
quote,
|
|
34176
|
-
vaultAllocator.address
|
|
34177
|
-
);
|
|
34178
|
-
const swapCallData = getCalldata[0];
|
|
34179
|
-
const amount = import_starknet24.uint256.bnToUint256(quote.sellAmountInUsd * 10 ** 7);
|
|
34180
|
-
return [
|
|
34181
|
-
{
|
|
34182
|
-
sanitizer: SIMPLE_SANITIZER,
|
|
34183
|
-
call: {
|
|
34184
|
-
contractAddress: fromToken.address,
|
|
34185
|
-
selector: import_starknet24.hash.getSelectorFromName("approve"),
|
|
34186
|
-
calldata: [
|
|
34187
|
-
AVNU_EXCHANGE.toBigInt(),
|
|
34188
|
-
toBigInt(amount.low.toString()),
|
|
34189
|
-
// amount low
|
|
34190
|
-
toBigInt(amount.high.toString())
|
|
34191
|
-
// amount high
|
|
34192
|
-
]
|
|
34193
|
-
}
|
|
34194
|
-
},
|
|
34195
|
-
{
|
|
34196
|
-
sanitizer: SIMPLE_SANITIZER,
|
|
34197
|
-
call: {
|
|
34198
|
-
contractAddress: AVNU_EXCHANGE,
|
|
34199
|
-
selector: import_starknet24.hash.getSelectorFromName("multi_route_swap"),
|
|
34200
|
-
calldata: swapCallData
|
|
34201
|
-
}
|
|
34202
|
-
}
|
|
34203
|
-
];
|
|
34204
|
-
} catch (error) {
|
|
34205
|
-
logger.error(`Error getting Avnu quote: ${error}`);
|
|
34206
|
-
return [];
|
|
34207
|
-
}
|
|
34208
|
-
}
|
|
34209
|
-
//Swap wbtc to usdc
|
|
34210
|
-
async getWithdrawCall(params) {
|
|
34211
|
-
try {
|
|
34212
|
-
const toToken = this.config.supportedPositions[0].asset;
|
|
34213
|
-
const fromToken = this.config.supportedPositions[1].asset;
|
|
34214
|
-
const vaultAllocator = ContractAddr.from(
|
|
34215
|
-
this.config.vaultAllocator.address
|
|
34216
|
-
);
|
|
34217
|
-
const quote = await this.getQuotesAvnu(
|
|
34218
|
-
fromToken.address.toString(),
|
|
34219
|
-
toToken.address.toString(),
|
|
34220
|
-
params.amount.toNumber(),
|
|
34221
|
-
vaultAllocator.address.toString(),
|
|
34222
|
-
fromToken.decimals,
|
|
34223
|
-
false
|
|
34224
|
-
);
|
|
34225
|
-
if (!quote) {
|
|
34226
|
-
logger.error("No quotes available for this swap, error in quotes avnu");
|
|
34227
|
-
return [];
|
|
34228
|
-
}
|
|
34229
|
-
const getCalldata = await this.avnuWrapper.getSwapCallData(
|
|
34230
|
-
quote,
|
|
34231
|
-
vaultAllocator.address
|
|
34232
|
-
);
|
|
34233
|
-
const swapCallData = getCalldata[0];
|
|
34234
|
-
const amount = import_starknet24.uint256.bnToUint256(params.amount.toWei());
|
|
34235
|
-
return [
|
|
34236
|
-
{
|
|
34237
|
-
sanitizer: SIMPLE_SANITIZER,
|
|
34238
|
-
call: {
|
|
34239
|
-
contractAddress: fromToken.address,
|
|
34240
|
-
selector: import_starknet24.hash.getSelectorFromName("approve"),
|
|
34241
|
-
calldata: [
|
|
34242
|
-
AVNU_EXCHANGE.toBigInt(),
|
|
34243
|
-
toBigInt(amount.low.toString()),
|
|
34244
|
-
// amount low
|
|
34245
|
-
toBigInt(amount.high.toString())
|
|
34246
|
-
// amount high
|
|
34247
|
-
]
|
|
34248
|
-
}
|
|
34249
|
-
},
|
|
34250
|
-
{
|
|
34251
|
-
sanitizer: SIMPLE_SANITIZER,
|
|
34252
|
-
call: {
|
|
34253
|
-
contractAddress: AVNU_EXCHANGE,
|
|
34254
|
-
selector: import_starknet24.hash.getSelectorFromName("multi_route_swap"),
|
|
34255
|
-
calldata: swapCallData
|
|
34256
|
-
}
|
|
34257
|
-
}
|
|
34258
|
-
];
|
|
34259
|
-
} catch (error) {
|
|
34260
|
-
logger.error(`Error getting Avnu quote: ${error}`);
|
|
34261
|
-
return [];
|
|
34262
|
-
}
|
|
34263
|
-
}
|
|
34264
|
-
async getSwapCallData(quote) {
|
|
34265
|
-
return await this.avnuWrapper.getSwapCallData(quote, this.config.vaultAllocator.address);
|
|
34266
|
-
}
|
|
34267
|
-
async getHealthFactor() {
|
|
34268
|
-
return Promise.resolve(1);
|
|
34269
|
-
}
|
|
34270
|
-
async fetchQuoteWithRetry(params, retries = 5) {
|
|
34271
|
-
for (let attempt = 0; attempt < retries; attempt++) {
|
|
34272
|
-
try {
|
|
34273
|
-
const response = await import_axios9.default.get(this.config.baseUrl, { params });
|
|
34274
|
-
if (response.data && response.data.length > 0) {
|
|
34275
|
-
return response;
|
|
34276
|
-
}
|
|
34277
|
-
throw new Error("Empty response data");
|
|
34278
|
-
} catch (err) {
|
|
34279
|
-
logger.error(`Error fetching quote with retry: ${err}`);
|
|
34280
|
-
if (attempt === retries - 1) {
|
|
34281
|
-
throw err;
|
|
34282
|
-
}
|
|
34283
|
-
await new Promise((resolve) => setTimeout(resolve, MAX_DELAY));
|
|
34284
|
-
}
|
|
34285
|
-
}
|
|
34286
|
-
throw new Error("Failed to fetch quote after retries");
|
|
34287
|
-
}
|
|
34288
|
-
async getQuotesAvnu(from_token_address, to_token_address, amount, takerAddress, toTokenDecimals, usdcToBtc, maxIterations = 5, tolerance = 5e3) {
|
|
34289
|
-
try {
|
|
34290
|
-
const fromToken = this.config.supportedPositions[0].asset;
|
|
34291
|
-
const toToken = this.config.supportedPositions[1].asset;
|
|
34292
|
-
if (!usdcToBtc) {
|
|
34293
|
-
const sellAmount2 = returnFormattedAmount(amount, toTokenDecimals);
|
|
34294
|
-
const params2 = {
|
|
34295
|
-
sellTokenAddress: from_token_address,
|
|
34296
|
-
buyTokenAddress: to_token_address,
|
|
34297
|
-
takerAddress,
|
|
34298
|
-
sellAmount: sellAmount2
|
|
34299
|
-
};
|
|
34300
|
-
const finalQuote2 = await this.fetchQuoteWithRetry(params2);
|
|
34301
|
-
if (!finalQuote2.data.length) {
|
|
34302
|
-
logger.error("No quotes available for this swap, error in quotes avnu");
|
|
34303
|
-
return null;
|
|
34304
|
-
}
|
|
34305
|
-
const dataObject2 = finalQuote2.data[0];
|
|
34306
|
-
return dataObject2;
|
|
34307
|
-
}
|
|
34308
|
-
const btcPrice = await this.getPriceOfToken(toToken.address.toString());
|
|
34309
|
-
if (!btcPrice) {
|
|
34310
|
-
logger.error(`error getting btc price: ${btcPrice}`);
|
|
34311
|
-
return null;
|
|
34312
|
-
}
|
|
34313
|
-
const estimatedUsdcAmount = Math.floor(amount * btcPrice);
|
|
34314
|
-
const targetBtcBig = BigInt(returnFormattedAmount(amount, toTokenDecimals));
|
|
34315
|
-
let low = BigInt(
|
|
34316
|
-
Math.floor(
|
|
34317
|
-
estimatedUsdcAmount * 10 ** fromToken.decimals * 0.9
|
|
34318
|
-
)
|
|
34319
|
-
);
|
|
34320
|
-
let high = BigInt(
|
|
34321
|
-
Math.floor(
|
|
34322
|
-
estimatedUsdcAmount * 10 ** fromToken.decimals * 1.1
|
|
34323
|
-
)
|
|
34324
|
-
);
|
|
34325
|
-
let mid = 0n;
|
|
34326
|
-
for (let i = 0; i < maxIterations; i++) {
|
|
34327
|
-
mid = (low + high) / 2n;
|
|
34328
|
-
const sellAmount2 = returnFormattedAmount(Number(mid), 0);
|
|
34329
|
-
const quote = await this.fetchQuoteWithRetry({
|
|
34330
|
-
sellTokenAddress: from_token_address,
|
|
34331
|
-
buyTokenAddress: to_token_address,
|
|
34332
|
-
takerAddress,
|
|
34333
|
-
sellAmount: sellAmount2
|
|
34334
|
-
});
|
|
34335
|
-
const gotBtc = BigInt(quote.data[0].buyAmount);
|
|
34336
|
-
if (gotBtc === targetBtcBig) return quote.data[0];
|
|
34337
|
-
if (gotBtc > targetBtcBig) {
|
|
34338
|
-
high = mid;
|
|
34339
|
-
} else {
|
|
34340
|
-
low = mid;
|
|
34341
|
-
}
|
|
34342
|
-
if (gotBtc >= targetBtcBig && gotBtc <= targetBtcBig + BigInt(tolerance)) {
|
|
34343
|
-
return quote.data[0];
|
|
34344
|
-
}
|
|
34345
|
-
}
|
|
34346
|
-
let sellAmount = returnFormattedAmount(
|
|
34347
|
-
Number(mid),
|
|
34348
|
-
0
|
|
34349
|
-
);
|
|
34350
|
-
const params = {
|
|
34351
|
-
sellTokenAddress: from_token_address,
|
|
34352
|
-
buyTokenAddress: to_token_address,
|
|
34353
|
-
takerAddress,
|
|
34354
|
-
sellAmount
|
|
34355
|
-
};
|
|
34356
|
-
const finalQuote = await this.fetchQuoteWithRetry(params);
|
|
34357
|
-
if (!finalQuote.data.length) {
|
|
34358
|
-
logger.error("No quotes available for this swap, error in quotes avnu");
|
|
34359
|
-
return null;
|
|
34360
|
-
}
|
|
34361
|
-
const dataObject = finalQuote.data[0];
|
|
34362
|
-
return dataObject;
|
|
34363
|
-
} catch (err) {
|
|
34364
|
-
logger.error(`No quotes available for this swap: ${err}`);
|
|
34365
|
-
return null;
|
|
34366
|
-
}
|
|
34367
|
-
}
|
|
34368
|
-
async getPriceOfToken(tokenAddress, retries = MAX_RETRIES) {
|
|
34369
|
-
try {
|
|
34370
|
-
const url = `https://starknet.impulse.avnu.fi/v1/tokens/${tokenAddress}/prices/line`;
|
|
34371
|
-
const response = await import_axios9.default.get(url);
|
|
34372
|
-
const length = response.data.length;
|
|
34373
|
-
return response.data[length - 1].value;
|
|
34374
|
-
} catch (err) {
|
|
34375
|
-
if (retries > 0) {
|
|
34376
|
-
await new Promise((resolve) => setTimeout(resolve, MAX_DELAY));
|
|
34377
|
-
return this.getPriceOfToken(tokenAddress, retries - 1);
|
|
34378
|
-
} else {
|
|
34379
|
-
logger.error(`Failed to fetch price for ${tokenAddress} after ${MAX_RETRIES} attempts`);
|
|
34380
|
-
return null;
|
|
34381
|
-
}
|
|
34382
|
-
}
|
|
34383
|
-
}
|
|
34384
|
-
};
|
|
34385
|
-
|
|
34386
34403
|
// src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx
|
|
34387
34404
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
34388
34405
|
var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy extends SVKStrategy {
|
|
@@ -39800,6 +39817,7 @@ var deployer_default = Deployer;
|
|
|
39800
39817
|
AssetOperationStatus,
|
|
39801
39818
|
AssetOperationType,
|
|
39802
39819
|
AutoCompounderSTRK,
|
|
39820
|
+
AvnuAdapter,
|
|
39803
39821
|
AvnuWrapper,
|
|
39804
39822
|
BaseAdapter,
|
|
39805
39823
|
BaseStrategy,
|
|
@@ -39883,6 +39901,7 @@ var deployer_default = Deployer;
|
|
|
39883
39901
|
calculateExtendedLevergae,
|
|
39884
39902
|
calculateVesUPositionSizeGivenExtended,
|
|
39885
39903
|
calculateVesuLeverage,
|
|
39904
|
+
calculateWBTCAmountToMaintainLTV,
|
|
39886
39905
|
extensionMap,
|
|
39887
39906
|
getAPIUsingHeadlessBrowser,
|
|
39888
39907
|
getContractDetails,
|