@strkfarm/sdk 2.0.0-dev.5 → 2.0.0-dev.6
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 +100 -48
- package/dist/index.browser.mjs +100 -48
- package/dist/index.js +100 -48
- package/dist/index.mjs +100 -48
- package/package.json +1 -1
- package/src/strategies/universal-adapters/avnu-adapter.ts +1 -1
- package/src/strategies/universal-adapters/extended-adapter.ts +150 -73
- package/src/strategies/vesu-extended-strategy/utils/helper.ts +2 -4
- package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +8 -7
|
@@ -92419,8 +92419,7 @@ spurious results.`);
|
|
|
92419
92419
|
vesu_leverage: 0
|
|
92420
92420
|
};
|
|
92421
92421
|
}
|
|
92422
|
-
const
|
|
92423
|
-
const extendedExposureUSD = extendedBTCExposure.multipliedBy(collateralPrice);
|
|
92422
|
+
const extendedExposureUSD = extendedPosition.length > 0 ? new Web3Number(extendedPosition[0].value, WBTC_TOKEN_DECIMALS) : new Web3Number(0, WBTC_TOKEN_DECIMALS);
|
|
92424
92423
|
const vesuBTCExposureUSD = collateralUnits.multipliedBy(collateralPrice);
|
|
92425
92424
|
const numerator1 = vesu_leverage * amount + vesuBTCExposureUSD.toNumber();
|
|
92426
92425
|
const numerator2 = extendedExposureUSD.toNumber();
|
|
@@ -93651,7 +93650,10 @@ spurious results.`);
|
|
|
93651
93650
|
//abstract means the method has no implementation in this class; instead, child classes must implement it.
|
|
93652
93651
|
async getAPY(supportedPosition) {
|
|
93653
93652
|
const side = supportedPosition.isDebt ? "LONG" : "SHORT";
|
|
93654
|
-
const fundingRates = await this.client.getFundingRates(
|
|
93653
|
+
const fundingRates = await this.client.getFundingRates(
|
|
93654
|
+
this.config.extendedMarketName,
|
|
93655
|
+
side
|
|
93656
|
+
);
|
|
93655
93657
|
if (fundingRates.status !== "OK") {
|
|
93656
93658
|
logger2.error("error getting funding rates", fundingRates);
|
|
93657
93659
|
return { apy: 0, type: "base" /* BASE */ };
|
|
@@ -93695,14 +93697,14 @@ spurious results.`);
|
|
|
93695
93697
|
});
|
|
93696
93698
|
}
|
|
93697
93699
|
_getDepositLeaf() {
|
|
93698
|
-
const usdceToken = Global.getDefaultTokens().find(
|
|
93700
|
+
const usdceToken = Global.getDefaultTokens().find(
|
|
93701
|
+
(token) => token.symbol === "USDCe"
|
|
93702
|
+
);
|
|
93699
93703
|
return [
|
|
93700
93704
|
{
|
|
93701
93705
|
target: this.config.supportedPositions[0].asset.address,
|
|
93702
93706
|
method: "approve",
|
|
93703
|
-
packedArguments: [
|
|
93704
|
-
AVNU_EXCHANGE_FOR_LEGACY_USDC.toBigInt()
|
|
93705
|
-
],
|
|
93707
|
+
packedArguments: [AVNU_EXCHANGE_FOR_LEGACY_USDC.toBigInt()],
|
|
93706
93708
|
id: `extended_approve_${this.config.supportedPositions[0].asset.symbol}`,
|
|
93707
93709
|
sanitizer: AVNU_LEGACY_SANITIZER
|
|
93708
93710
|
},
|
|
@@ -93733,25 +93735,33 @@ spurious results.`);
|
|
|
93733
93735
|
const leafConfigs = this._getSwapFromLegacyLeaf();
|
|
93734
93736
|
const leaves = leafConfigs.map((config3) => {
|
|
93735
93737
|
const { target, method, packedArguments, sanitizer, id } = config3;
|
|
93736
|
-
const leaf = this.constructSimpleLeafData(
|
|
93737
|
-
|
|
93738
|
-
|
|
93739
|
-
|
|
93740
|
-
|
|
93741
|
-
|
|
93738
|
+
const leaf = this.constructSimpleLeafData(
|
|
93739
|
+
{
|
|
93740
|
+
id,
|
|
93741
|
+
target,
|
|
93742
|
+
method,
|
|
93743
|
+
packedArguments
|
|
93744
|
+
},
|
|
93745
|
+
sanitizer
|
|
93746
|
+
);
|
|
93742
93747
|
return leaf;
|
|
93743
93748
|
});
|
|
93744
|
-
return {
|
|
93749
|
+
return {
|
|
93750
|
+
leaves,
|
|
93751
|
+
callConstructor: this.getSwapFromLegacyCall.bind(
|
|
93752
|
+
this
|
|
93753
|
+
)
|
|
93754
|
+
};
|
|
93745
93755
|
}
|
|
93746
93756
|
_getSwapFromLegacyLeaf() {
|
|
93747
|
-
const usdceToken = Global.getDefaultTokens().find(
|
|
93757
|
+
const usdceToken = Global.getDefaultTokens().find(
|
|
93758
|
+
(token) => token.symbol === "USDCe"
|
|
93759
|
+
);
|
|
93748
93760
|
return [
|
|
93749
93761
|
{
|
|
93750
93762
|
target: usdceToken.address,
|
|
93751
93763
|
method: "approve",
|
|
93752
|
-
packedArguments: [
|
|
93753
|
-
AVNU_EXCHANGE_FOR_LEGACY_USDC.toBigInt()
|
|
93754
|
-
],
|
|
93764
|
+
packedArguments: [AVNU_EXCHANGE_FOR_LEGACY_USDC.toBigInt()],
|
|
93755
93765
|
id: `extendedswaplegacyapprove_${usdceToken.symbol}`,
|
|
93756
93766
|
sanitizer: AVNU_LEGACY_SANITIZER
|
|
93757
93767
|
},
|
|
@@ -93770,11 +93780,13 @@ spurious results.`);
|
|
|
93770
93780
|
async getDepositCall(params) {
|
|
93771
93781
|
try {
|
|
93772
93782
|
const usdcToken = this.config.supportedPositions[0].asset;
|
|
93773
|
-
const usdceToken = Global.getDefaultTokens().find(
|
|
93774
|
-
|
|
93775
|
-
|
|
93783
|
+
const usdceToken = Global.getDefaultTokens().find(
|
|
93784
|
+
(token) => token.symbol === "USDCe"
|
|
93785
|
+
);
|
|
93786
|
+
const salt = Math.floor(Math.random() * 10 ** usdcToken.decimals);
|
|
93787
|
+
const amount = uint256_exports.bnToUint256(
|
|
93788
|
+
params.amount.multipliedBy(10).toWei()
|
|
93776
93789
|
);
|
|
93777
|
-
const amount = uint256_exports.bnToUint256(params.amount.multipliedBy(10).toWei());
|
|
93778
93790
|
const quotes = await this.config.avnuAdapter.getQuotesAvnu(
|
|
93779
93791
|
usdcToken.address.toString(),
|
|
93780
93792
|
usdceToken.address.toString(),
|
|
@@ -93787,7 +93799,9 @@ spurious results.`);
|
|
|
93787
93799
|
logger2.error("error getting quotes from avnu");
|
|
93788
93800
|
return [];
|
|
93789
93801
|
}
|
|
93790
|
-
const getCalldata = await this.config.avnuAdapter.getSwapCallData(
|
|
93802
|
+
const getCalldata = await this.config.avnuAdapter.getSwapCallData(
|
|
93803
|
+
quotes
|
|
93804
|
+
);
|
|
93791
93805
|
const swapCallData = getCalldata[0];
|
|
93792
93806
|
return [
|
|
93793
93807
|
{
|
|
@@ -93863,8 +93877,12 @@ spurious results.`);
|
|
|
93863
93877
|
async getSwapFromLegacyCall(params) {
|
|
93864
93878
|
try {
|
|
93865
93879
|
const usdcToken = this.config.supportedPositions[0].asset;
|
|
93866
|
-
const usdceToken = Global.getDefaultTokens().find(
|
|
93867
|
-
|
|
93880
|
+
const usdceToken = Global.getDefaultTokens().find(
|
|
93881
|
+
(token) => token.symbol === "USDCe"
|
|
93882
|
+
);
|
|
93883
|
+
const amount = uint256_exports.bnToUint256(
|
|
93884
|
+
params.amount.multipliedBy(10).toWei()
|
|
93885
|
+
);
|
|
93868
93886
|
const quotes = await this.config.avnuAdapter.getQuotesAvnu(
|
|
93869
93887
|
usdceToken.address.toString(),
|
|
93870
93888
|
usdcToken.address.toString(),
|
|
@@ -93877,7 +93895,9 @@ spurious results.`);
|
|
|
93877
93895
|
logger2.error("error getting quotes from avnu");
|
|
93878
93896
|
return [];
|
|
93879
93897
|
}
|
|
93880
|
-
const getCalldata = await this.config.avnuAdapter.getSwapCallData(
|
|
93898
|
+
const getCalldata = await this.config.avnuAdapter.getSwapCallData(
|
|
93899
|
+
quotes
|
|
93900
|
+
);
|
|
93881
93901
|
const swapCallData = getCalldata[0];
|
|
93882
93902
|
return [
|
|
93883
93903
|
{
|
|
@@ -93925,9 +93945,14 @@ spurious results.`);
|
|
|
93925
93945
|
if (!this.client) {
|
|
93926
93946
|
throw new Error("Client not initialized");
|
|
93927
93947
|
}
|
|
93928
|
-
const withdrawalRequest = await this.client.withdrawUSDC(
|
|
93948
|
+
const withdrawalRequest = await this.client.withdrawUSDC(
|
|
93949
|
+
amount.toFixed(2)
|
|
93950
|
+
);
|
|
93929
93951
|
if (withdrawalRequest.status === "OK") {
|
|
93930
|
-
const withdrawalStatus = await this.getDepositOrWithdrawalStatus(
|
|
93952
|
+
const withdrawalStatus = await this.getDepositOrWithdrawalStatus(
|
|
93953
|
+
withdrawalRequest.data,
|
|
93954
|
+
"WITHDRAWAL" /* WITHDRAWAL */
|
|
93955
|
+
);
|
|
93931
93956
|
return withdrawalStatus;
|
|
93932
93957
|
}
|
|
93933
93958
|
return false;
|
|
@@ -94000,18 +94025,34 @@ spurious results.`);
|
|
|
94000
94025
|
logger2.error("error initializing client");
|
|
94001
94026
|
return null;
|
|
94002
94027
|
}
|
|
94003
|
-
|
|
94004
|
-
const orderhistory = await this.getOrderHistory(marketName);
|
|
94028
|
+
let orderhistory = await this.getOrderHistory(marketName);
|
|
94005
94029
|
if (!orderhistory || orderhistory.length === 0) {
|
|
94006
|
-
logger2.error(`error getting order: ${orderId}`);
|
|
94007
|
-
|
|
94030
|
+
logger2.error(`error getting order history: ${orderId}`);
|
|
94031
|
+
} else {
|
|
94032
|
+
const order = orderhistory.slice(0, 5).find((order2) => order2.id.toString() === orderId);
|
|
94033
|
+
if (order) {
|
|
94034
|
+
return order;
|
|
94035
|
+
}
|
|
94008
94036
|
}
|
|
94009
|
-
|
|
94010
|
-
|
|
94011
|
-
|
|
94012
|
-
|
|
94037
|
+
for (let attempt = 1; attempt <= 3; attempt++) {
|
|
94038
|
+
await new Promise((resolve) => setTimeout(resolve, 3e3));
|
|
94039
|
+
orderhistory = await this.getOrderHistory(marketName);
|
|
94040
|
+
if (!orderhistory || orderhistory.length === 0) {
|
|
94041
|
+
logger2.error(
|
|
94042
|
+
`error getting order history on retry ${attempt}: ${orderId}`
|
|
94043
|
+
);
|
|
94044
|
+
continue;
|
|
94045
|
+
}
|
|
94046
|
+
const order = orderhistory.slice(0, 5).find((order2) => order2.id.toString() === orderId);
|
|
94047
|
+
if (order) {
|
|
94048
|
+
return order;
|
|
94049
|
+
}
|
|
94050
|
+
logger2.error(
|
|
94051
|
+
`order not found in top 5 entries on retry ${attempt}: ${orderId}`
|
|
94052
|
+
);
|
|
94013
94053
|
}
|
|
94014
|
-
|
|
94054
|
+
logger2.error(`error getting order after all retries: ${orderId}`);
|
|
94055
|
+
return null;
|
|
94015
94056
|
}
|
|
94016
94057
|
async fetchOrderBookBTCUSDC() {
|
|
94017
94058
|
try {
|
|
@@ -94084,7 +94125,10 @@ spurious results.`);
|
|
|
94084
94125
|
return null;
|
|
94085
94126
|
}
|
|
94086
94127
|
await new Promise((resolve) => setTimeout(resolve, 5e3));
|
|
94087
|
-
const openOrder = await this.getOrderStatus(
|
|
94128
|
+
const openOrder = await this.getOrderStatus(
|
|
94129
|
+
result2.position_id,
|
|
94130
|
+
this.config.extendedMarketName
|
|
94131
|
+
);
|
|
94088
94132
|
if (!openOrder || openOrder.status !== "FILLED" /* FILLED */) {
|
|
94089
94133
|
if (attempt >= maxAttempts) {
|
|
94090
94134
|
logger2.error("Max retries reached \u2014 could not verify open position");
|
|
@@ -94107,7 +94151,9 @@ spurious results.`);
|
|
|
94107
94151
|
};
|
|
94108
94152
|
}
|
|
94109
94153
|
} catch (err2) {
|
|
94110
|
-
logger2.error(
|
|
94154
|
+
logger2.error(
|
|
94155
|
+
`createShortOrder failed on attempt ${attempt}: ${err2.message}`
|
|
94156
|
+
);
|
|
94111
94157
|
if (attempt < maxAttempts) {
|
|
94112
94158
|
const backoff = 1200 * attempt;
|
|
94113
94159
|
logger2.info(`Retrying after ${backoff}ms...`);
|
|
@@ -94152,13 +94198,17 @@ spurious results.`);
|
|
|
94152
94198
|
operationsStatus: ["COMPLETED" /* COMPLETED */]
|
|
94153
94199
|
});
|
|
94154
94200
|
if (operationsType === "DEPOSIT" /* DEPOSIT */) {
|
|
94155
|
-
const myTransferStatus = transferHistory.data.find(
|
|
94201
|
+
const myTransferStatus = transferHistory.data.find(
|
|
94202
|
+
(operation) => operation.transactionHash === orderId
|
|
94203
|
+
);
|
|
94156
94204
|
if (!myTransferStatus) {
|
|
94157
94205
|
return true;
|
|
94158
94206
|
}
|
|
94159
94207
|
return true;
|
|
94160
94208
|
} else {
|
|
94161
|
-
const myTransferStatus = transferHistory.data.find(
|
|
94209
|
+
const myTransferStatus = transferHistory.data.find(
|
|
94210
|
+
(operation) => operation.id.toString() === orderId.toString()
|
|
94211
|
+
);
|
|
94162
94212
|
if (!myTransferStatus) {
|
|
94163
94213
|
return true;
|
|
94164
94214
|
}
|
|
@@ -97771,6 +97821,7 @@ spurious results.`);
|
|
|
97771
97821
|
toToken.decimals,
|
|
97772
97822
|
true
|
|
97773
97823
|
);
|
|
97824
|
+
console.log(`${_AvnuAdapter.name}::getDepositCall quote: ${quote?.sellAmountInUsd}`);
|
|
97774
97825
|
if (!quote) {
|
|
97775
97826
|
logger2.error("error getting quote from avnu");
|
|
97776
97827
|
return [];
|
|
@@ -97889,7 +97940,7 @@ spurious results.`);
|
|
|
97889
97940
|
}
|
|
97890
97941
|
throw new Error("Failed to fetch quote after retries");
|
|
97891
97942
|
}
|
|
97892
|
-
async getQuotesAvnu(from_token_address, to_token_address, amount, takerAddress, toTokenDecimals, usdcToBtc, maxIterations = 5, tolerance =
|
|
97943
|
+
async getQuotesAvnu(from_token_address, to_token_address, amount, takerAddress, toTokenDecimals, usdcToBtc, maxIterations = 5, tolerance = 5e3) {
|
|
97893
97944
|
try {
|
|
97894
97945
|
const fromToken = this.config.supportedPositions[0].asset;
|
|
97895
97946
|
const toToken = this.config.supportedPositions[1].asset;
|
|
@@ -98129,7 +98180,8 @@ spurious results.`);
|
|
|
98129
98180
|
}
|
|
98130
98181
|
const balance = await this.getUnusedBalance();
|
|
98131
98182
|
const usdcBalanceOnExtended = await extendedAdapter.getExtendedDepositAmount();
|
|
98132
|
-
const amountToInvest = balance.
|
|
98183
|
+
const amountToInvest = new Web3Number(balance.usdValue, USDC_TOKEN_DECIMALS).plus(usdcBalanceOnExtended?.availableForWithdrawal ?? 0).minus(LIMIT_BALANCE);
|
|
98184
|
+
logger2.info(`${_VesuExtendedMultiplierStrategy.name}::shouldInvest amountToInvest: ${amountToInvest.toNumber()}`);
|
|
98133
98185
|
if (amountToInvest.lessThan(0)) {
|
|
98134
98186
|
return {
|
|
98135
98187
|
shouldInvest: false,
|
|
@@ -98182,6 +98234,7 @@ spurious results.`);
|
|
|
98182
98234
|
vesuLeverage: 0
|
|
98183
98235
|
};
|
|
98184
98236
|
}
|
|
98237
|
+
logger2.info(`${_VesuExtendedMultiplierStrategy.name}::shouldInvest vesu_amount: ${vesu_amount.toNumber()}, extended_amount: ${extended_amount.toNumber()}`);
|
|
98185
98238
|
return {
|
|
98186
98239
|
shouldInvest: true,
|
|
98187
98240
|
vesuAmount: vesu_amount,
|
|
@@ -98261,15 +98314,15 @@ spurious results.`);
|
|
|
98261
98314
|
}
|
|
98262
98315
|
const usdcAmountInWallet = (await this.getUnusedBalance()).amount;
|
|
98263
98316
|
const usdcAmountOnExtended = parseFloat(
|
|
98264
|
-
extendedHoldings.
|
|
98317
|
+
extendedHoldings.availableForWithdrawal
|
|
98265
98318
|
);
|
|
98266
|
-
if (extendedAmount.
|
|
98319
|
+
if (extendedAmount.minus(usdcAmountOnExtended).greaterThan(0)) {
|
|
98267
98320
|
try {
|
|
98268
98321
|
const { calls: extendedCalls } = await this.moveAssets(
|
|
98269
98322
|
{
|
|
98270
98323
|
to: Protocols.EXTENDED.name,
|
|
98271
98324
|
from: Protocols.VAULT.name,
|
|
98272
|
-
amount: extendedAmount.
|
|
98325
|
+
amount: extendedAmount.minus(usdcAmountOnExtended)
|
|
98273
98326
|
},
|
|
98274
98327
|
extendedAdapter,
|
|
98275
98328
|
vesuAdapter
|
|
@@ -98507,7 +98560,7 @@ spurious results.`);
|
|
|
98507
98560
|
};
|
|
98508
98561
|
}
|
|
98509
98562
|
const extendedHoldingAmount = new Web3Number(
|
|
98510
|
-
extendedHoldings.
|
|
98563
|
+
extendedHoldings.availableForWithdrawal,
|
|
98511
98564
|
USDC_TOKEN_DECIMALS
|
|
98512
98565
|
);
|
|
98513
98566
|
const {
|
|
@@ -98567,7 +98620,6 @@ spurious results.`);
|
|
|
98567
98620
|
extendedAmountInBTC: new Web3Number(0, 0),
|
|
98568
98621
|
calls: []
|
|
98569
98622
|
};
|
|
98570
|
-
;
|
|
98571
98623
|
}
|
|
98572
98624
|
}
|
|
98573
98625
|
async checkPriceDifferenceBetweenAvnuAndExtended(extendedAdapter, vesuAdapter, avnuAdapter) {
|
package/dist/index.browser.mjs
CHANGED
|
@@ -28390,8 +28390,7 @@ var calculateAmountDistribution = async (amount, client, marketName, collateralP
|
|
|
28390
28390
|
vesu_leverage: 0
|
|
28391
28391
|
};
|
|
28392
28392
|
}
|
|
28393
|
-
const
|
|
28394
|
-
const extendedExposureUSD = extendedBTCExposure.multipliedBy(collateralPrice);
|
|
28393
|
+
const extendedExposureUSD = extendedPosition.length > 0 ? new Web3Number(extendedPosition[0].value, WBTC_TOKEN_DECIMALS) : new Web3Number(0, WBTC_TOKEN_DECIMALS);
|
|
28395
28394
|
const vesuBTCExposureUSD = collateralUnits.multipliedBy(collateralPrice);
|
|
28396
28395
|
const numerator1 = vesu_leverage * amount + vesuBTCExposureUSD.toNumber();
|
|
28397
28396
|
const numerator2 = extendedExposureUSD.toNumber();
|
|
@@ -29624,7 +29623,10 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29624
29623
|
//abstract means the method has no implementation in this class; instead, child classes must implement it.
|
|
29625
29624
|
async getAPY(supportedPosition) {
|
|
29626
29625
|
const side = supportedPosition.isDebt ? "LONG" : "SHORT";
|
|
29627
|
-
const fundingRates = await this.client.getFundingRates(
|
|
29626
|
+
const fundingRates = await this.client.getFundingRates(
|
|
29627
|
+
this.config.extendedMarketName,
|
|
29628
|
+
side
|
|
29629
|
+
);
|
|
29628
29630
|
if (fundingRates.status !== "OK") {
|
|
29629
29631
|
logger.error("error getting funding rates", fundingRates);
|
|
29630
29632
|
return { apy: 0, type: "base" /* BASE */ };
|
|
@@ -29668,14 +29670,14 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29668
29670
|
});
|
|
29669
29671
|
}
|
|
29670
29672
|
_getDepositLeaf() {
|
|
29671
|
-
const usdceToken = Global.getDefaultTokens().find(
|
|
29673
|
+
const usdceToken = Global.getDefaultTokens().find(
|
|
29674
|
+
(token) => token.symbol === "USDCe"
|
|
29675
|
+
);
|
|
29672
29676
|
return [
|
|
29673
29677
|
{
|
|
29674
29678
|
target: this.config.supportedPositions[0].asset.address,
|
|
29675
29679
|
method: "approve",
|
|
29676
|
-
packedArguments: [
|
|
29677
|
-
AVNU_EXCHANGE_FOR_LEGACY_USDC.toBigInt()
|
|
29678
|
-
],
|
|
29680
|
+
packedArguments: [AVNU_EXCHANGE_FOR_LEGACY_USDC.toBigInt()],
|
|
29679
29681
|
id: `extended_approve_${this.config.supportedPositions[0].asset.symbol}`,
|
|
29680
29682
|
sanitizer: AVNU_LEGACY_SANITIZER
|
|
29681
29683
|
},
|
|
@@ -29706,25 +29708,33 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29706
29708
|
const leafConfigs = this._getSwapFromLegacyLeaf();
|
|
29707
29709
|
const leaves = leafConfigs.map((config) => {
|
|
29708
29710
|
const { target, method, packedArguments, sanitizer, id } = config;
|
|
29709
|
-
const leaf = this.constructSimpleLeafData(
|
|
29710
|
-
|
|
29711
|
-
|
|
29712
|
-
|
|
29713
|
-
|
|
29714
|
-
|
|
29711
|
+
const leaf = this.constructSimpleLeafData(
|
|
29712
|
+
{
|
|
29713
|
+
id,
|
|
29714
|
+
target,
|
|
29715
|
+
method,
|
|
29716
|
+
packedArguments
|
|
29717
|
+
},
|
|
29718
|
+
sanitizer
|
|
29719
|
+
);
|
|
29715
29720
|
return leaf;
|
|
29716
29721
|
});
|
|
29717
|
-
return {
|
|
29722
|
+
return {
|
|
29723
|
+
leaves,
|
|
29724
|
+
callConstructor: this.getSwapFromLegacyCall.bind(
|
|
29725
|
+
this
|
|
29726
|
+
)
|
|
29727
|
+
};
|
|
29718
29728
|
}
|
|
29719
29729
|
_getSwapFromLegacyLeaf() {
|
|
29720
|
-
const usdceToken = Global.getDefaultTokens().find(
|
|
29730
|
+
const usdceToken = Global.getDefaultTokens().find(
|
|
29731
|
+
(token) => token.symbol === "USDCe"
|
|
29732
|
+
);
|
|
29721
29733
|
return [
|
|
29722
29734
|
{
|
|
29723
29735
|
target: usdceToken.address,
|
|
29724
29736
|
method: "approve",
|
|
29725
|
-
packedArguments: [
|
|
29726
|
-
AVNU_EXCHANGE_FOR_LEGACY_USDC.toBigInt()
|
|
29727
|
-
],
|
|
29737
|
+
packedArguments: [AVNU_EXCHANGE_FOR_LEGACY_USDC.toBigInt()],
|
|
29728
29738
|
id: `extendedswaplegacyapprove_${usdceToken.symbol}`,
|
|
29729
29739
|
sanitizer: AVNU_LEGACY_SANITIZER
|
|
29730
29740
|
},
|
|
@@ -29743,11 +29753,13 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29743
29753
|
async getDepositCall(params) {
|
|
29744
29754
|
try {
|
|
29745
29755
|
const usdcToken = this.config.supportedPositions[0].asset;
|
|
29746
|
-
const usdceToken = Global.getDefaultTokens().find(
|
|
29747
|
-
|
|
29748
|
-
|
|
29756
|
+
const usdceToken = Global.getDefaultTokens().find(
|
|
29757
|
+
(token) => token.symbol === "USDCe"
|
|
29758
|
+
);
|
|
29759
|
+
const salt = Math.floor(Math.random() * 10 ** usdcToken.decimals);
|
|
29760
|
+
const amount = uint25613.bnToUint256(
|
|
29761
|
+
params.amount.multipliedBy(10).toWei()
|
|
29749
29762
|
);
|
|
29750
|
-
const amount = uint25613.bnToUint256(params.amount.multipliedBy(10).toWei());
|
|
29751
29763
|
const quotes = await this.config.avnuAdapter.getQuotesAvnu(
|
|
29752
29764
|
usdcToken.address.toString(),
|
|
29753
29765
|
usdceToken.address.toString(),
|
|
@@ -29760,7 +29772,9 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29760
29772
|
logger.error("error getting quotes from avnu");
|
|
29761
29773
|
return [];
|
|
29762
29774
|
}
|
|
29763
|
-
const getCalldata = await this.config.avnuAdapter.getSwapCallData(
|
|
29775
|
+
const getCalldata = await this.config.avnuAdapter.getSwapCallData(
|
|
29776
|
+
quotes
|
|
29777
|
+
);
|
|
29764
29778
|
const swapCallData = getCalldata[0];
|
|
29765
29779
|
return [
|
|
29766
29780
|
{
|
|
@@ -29836,8 +29850,12 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29836
29850
|
async getSwapFromLegacyCall(params) {
|
|
29837
29851
|
try {
|
|
29838
29852
|
const usdcToken = this.config.supportedPositions[0].asset;
|
|
29839
|
-
const usdceToken = Global.getDefaultTokens().find(
|
|
29840
|
-
|
|
29853
|
+
const usdceToken = Global.getDefaultTokens().find(
|
|
29854
|
+
(token) => token.symbol === "USDCe"
|
|
29855
|
+
);
|
|
29856
|
+
const amount = uint25613.bnToUint256(
|
|
29857
|
+
params.amount.multipliedBy(10).toWei()
|
|
29858
|
+
);
|
|
29841
29859
|
const quotes = await this.config.avnuAdapter.getQuotesAvnu(
|
|
29842
29860
|
usdceToken.address.toString(),
|
|
29843
29861
|
usdcToken.address.toString(),
|
|
@@ -29850,7 +29868,9 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29850
29868
|
logger.error("error getting quotes from avnu");
|
|
29851
29869
|
return [];
|
|
29852
29870
|
}
|
|
29853
|
-
const getCalldata = await this.config.avnuAdapter.getSwapCallData(
|
|
29871
|
+
const getCalldata = await this.config.avnuAdapter.getSwapCallData(
|
|
29872
|
+
quotes
|
|
29873
|
+
);
|
|
29854
29874
|
const swapCallData = getCalldata[0];
|
|
29855
29875
|
return [
|
|
29856
29876
|
{
|
|
@@ -29898,9 +29918,14 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29898
29918
|
if (!this.client) {
|
|
29899
29919
|
throw new Error("Client not initialized");
|
|
29900
29920
|
}
|
|
29901
|
-
const withdrawalRequest = await this.client.withdrawUSDC(
|
|
29921
|
+
const withdrawalRequest = await this.client.withdrawUSDC(
|
|
29922
|
+
amount.toFixed(2)
|
|
29923
|
+
);
|
|
29902
29924
|
if (withdrawalRequest.status === "OK") {
|
|
29903
|
-
const withdrawalStatus = await this.getDepositOrWithdrawalStatus(
|
|
29925
|
+
const withdrawalStatus = await this.getDepositOrWithdrawalStatus(
|
|
29926
|
+
withdrawalRequest.data,
|
|
29927
|
+
"WITHDRAWAL" /* WITHDRAWAL */
|
|
29928
|
+
);
|
|
29904
29929
|
return withdrawalStatus;
|
|
29905
29930
|
}
|
|
29906
29931
|
return false;
|
|
@@ -29973,18 +29998,34 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
29973
29998
|
logger.error("error initializing client");
|
|
29974
29999
|
return null;
|
|
29975
30000
|
}
|
|
29976
|
-
|
|
29977
|
-
const orderhistory = await this.getOrderHistory(marketName);
|
|
30001
|
+
let orderhistory = await this.getOrderHistory(marketName);
|
|
29978
30002
|
if (!orderhistory || orderhistory.length === 0) {
|
|
29979
|
-
logger.error(`error getting order: ${orderId}`);
|
|
29980
|
-
|
|
30003
|
+
logger.error(`error getting order history: ${orderId}`);
|
|
30004
|
+
} else {
|
|
30005
|
+
const order = orderhistory.slice(0, 5).find((order2) => order2.id.toString() === orderId);
|
|
30006
|
+
if (order) {
|
|
30007
|
+
return order;
|
|
30008
|
+
}
|
|
29981
30009
|
}
|
|
29982
|
-
|
|
29983
|
-
|
|
29984
|
-
|
|
29985
|
-
|
|
30010
|
+
for (let attempt = 1; attempt <= 3; attempt++) {
|
|
30011
|
+
await new Promise((resolve) => setTimeout(resolve, 3e3));
|
|
30012
|
+
orderhistory = await this.getOrderHistory(marketName);
|
|
30013
|
+
if (!orderhistory || orderhistory.length === 0) {
|
|
30014
|
+
logger.error(
|
|
30015
|
+
`error getting order history on retry ${attempt}: ${orderId}`
|
|
30016
|
+
);
|
|
30017
|
+
continue;
|
|
30018
|
+
}
|
|
30019
|
+
const order = orderhistory.slice(0, 5).find((order2) => order2.id.toString() === orderId);
|
|
30020
|
+
if (order) {
|
|
30021
|
+
return order;
|
|
30022
|
+
}
|
|
30023
|
+
logger.error(
|
|
30024
|
+
`order not found in top 5 entries on retry ${attempt}: ${orderId}`
|
|
30025
|
+
);
|
|
29986
30026
|
}
|
|
29987
|
-
|
|
30027
|
+
logger.error(`error getting order after all retries: ${orderId}`);
|
|
30028
|
+
return null;
|
|
29988
30029
|
}
|
|
29989
30030
|
async fetchOrderBookBTCUSDC() {
|
|
29990
30031
|
try {
|
|
@@ -30057,7 +30098,10 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
30057
30098
|
return null;
|
|
30058
30099
|
}
|
|
30059
30100
|
await new Promise((resolve) => setTimeout(resolve, 5e3));
|
|
30060
|
-
const openOrder = await this.getOrderStatus(
|
|
30101
|
+
const openOrder = await this.getOrderStatus(
|
|
30102
|
+
result.position_id,
|
|
30103
|
+
this.config.extendedMarketName
|
|
30104
|
+
);
|
|
30061
30105
|
if (!openOrder || openOrder.status !== "FILLED" /* FILLED */) {
|
|
30062
30106
|
if (attempt >= maxAttempts) {
|
|
30063
30107
|
logger.error("Max retries reached \u2014 could not verify open position");
|
|
@@ -30080,7 +30124,9 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
30080
30124
|
};
|
|
30081
30125
|
}
|
|
30082
30126
|
} catch (err) {
|
|
30083
|
-
logger.error(
|
|
30127
|
+
logger.error(
|
|
30128
|
+
`createShortOrder failed on attempt ${attempt}: ${err.message}`
|
|
30129
|
+
);
|
|
30084
30130
|
if (attempt < maxAttempts) {
|
|
30085
30131
|
const backoff = 1200 * attempt;
|
|
30086
30132
|
logger.info(`Retrying after ${backoff}ms...`);
|
|
@@ -30125,13 +30171,17 @@ var ExtendedAdapter = class _ExtendedAdapter extends BaseAdapter {
|
|
|
30125
30171
|
operationsStatus: ["COMPLETED" /* COMPLETED */]
|
|
30126
30172
|
});
|
|
30127
30173
|
if (operationsType === "DEPOSIT" /* DEPOSIT */) {
|
|
30128
|
-
const myTransferStatus = transferHistory.data.find(
|
|
30174
|
+
const myTransferStatus = transferHistory.data.find(
|
|
30175
|
+
(operation) => operation.transactionHash === orderId
|
|
30176
|
+
);
|
|
30129
30177
|
if (!myTransferStatus) {
|
|
30130
30178
|
return true;
|
|
30131
30179
|
}
|
|
30132
30180
|
return true;
|
|
30133
30181
|
} else {
|
|
30134
|
-
const myTransferStatus = transferHistory.data.find(
|
|
30182
|
+
const myTransferStatus = transferHistory.data.find(
|
|
30183
|
+
(operation) => operation.id.toString() === orderId.toString()
|
|
30184
|
+
);
|
|
30135
30185
|
if (!myTransferStatus) {
|
|
30136
30186
|
return true;
|
|
30137
30187
|
}
|
|
@@ -33749,6 +33799,7 @@ var AvnuAdapter = class _AvnuAdapter extends BaseAdapter {
|
|
|
33749
33799
|
toToken.decimals,
|
|
33750
33800
|
true
|
|
33751
33801
|
);
|
|
33802
|
+
console.log(`${_AvnuAdapter.name}::getDepositCall quote: ${quote?.sellAmountInUsd}`);
|
|
33752
33803
|
if (!quote) {
|
|
33753
33804
|
logger.error("error getting quote from avnu");
|
|
33754
33805
|
return [];
|
|
@@ -33867,7 +33918,7 @@ var AvnuAdapter = class _AvnuAdapter extends BaseAdapter {
|
|
|
33867
33918
|
}
|
|
33868
33919
|
throw new Error("Failed to fetch quote after retries");
|
|
33869
33920
|
}
|
|
33870
|
-
async getQuotesAvnu(from_token_address, to_token_address, amount, takerAddress, toTokenDecimals, usdcToBtc, maxIterations = 5, tolerance =
|
|
33921
|
+
async getQuotesAvnu(from_token_address, to_token_address, amount, takerAddress, toTokenDecimals, usdcToBtc, maxIterations = 5, tolerance = 5e3) {
|
|
33871
33922
|
try {
|
|
33872
33923
|
const fromToken = this.config.supportedPositions[0].asset;
|
|
33873
33924
|
const toToken = this.config.supportedPositions[1].asset;
|
|
@@ -34107,7 +34158,8 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34107
34158
|
}
|
|
34108
34159
|
const balance = await this.getUnusedBalance();
|
|
34109
34160
|
const usdcBalanceOnExtended = await extendedAdapter.getExtendedDepositAmount();
|
|
34110
|
-
const amountToInvest = balance.
|
|
34161
|
+
const amountToInvest = new Web3Number(balance.usdValue, USDC_TOKEN_DECIMALS).plus(usdcBalanceOnExtended?.availableForWithdrawal ?? 0).minus(LIMIT_BALANCE);
|
|
34162
|
+
logger.info(`${_VesuExtendedMultiplierStrategy.name}::shouldInvest amountToInvest: ${amountToInvest.toNumber()}`);
|
|
34111
34163
|
if (amountToInvest.lessThan(0)) {
|
|
34112
34164
|
return {
|
|
34113
34165
|
shouldInvest: false,
|
|
@@ -34160,6 +34212,7 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34160
34212
|
vesuLeverage: 0
|
|
34161
34213
|
};
|
|
34162
34214
|
}
|
|
34215
|
+
logger.info(`${_VesuExtendedMultiplierStrategy.name}::shouldInvest vesu_amount: ${vesu_amount.toNumber()}, extended_amount: ${extended_amount.toNumber()}`);
|
|
34163
34216
|
return {
|
|
34164
34217
|
shouldInvest: true,
|
|
34165
34218
|
vesuAmount: vesu_amount,
|
|
@@ -34239,15 +34292,15 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34239
34292
|
}
|
|
34240
34293
|
const usdcAmountInWallet = (await this.getUnusedBalance()).amount;
|
|
34241
34294
|
const usdcAmountOnExtended = parseFloat(
|
|
34242
|
-
extendedHoldings.
|
|
34295
|
+
extendedHoldings.availableForWithdrawal
|
|
34243
34296
|
);
|
|
34244
|
-
if (extendedAmount.
|
|
34297
|
+
if (extendedAmount.minus(usdcAmountOnExtended).greaterThan(0)) {
|
|
34245
34298
|
try {
|
|
34246
34299
|
const { calls: extendedCalls } = await this.moveAssets(
|
|
34247
34300
|
{
|
|
34248
34301
|
to: Protocols.EXTENDED.name,
|
|
34249
34302
|
from: Protocols.VAULT.name,
|
|
34250
|
-
amount: extendedAmount.
|
|
34303
|
+
amount: extendedAmount.minus(usdcAmountOnExtended)
|
|
34251
34304
|
},
|
|
34252
34305
|
extendedAdapter,
|
|
34253
34306
|
vesuAdapter
|
|
@@ -34485,7 +34538,7 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34485
34538
|
};
|
|
34486
34539
|
}
|
|
34487
34540
|
const extendedHoldingAmount = new Web3Number(
|
|
34488
|
-
extendedHoldings.
|
|
34541
|
+
extendedHoldings.availableForWithdrawal,
|
|
34489
34542
|
USDC_TOKEN_DECIMALS
|
|
34490
34543
|
);
|
|
34491
34544
|
const {
|
|
@@ -34545,7 +34598,6 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
34545
34598
|
extendedAmountInBTC: new Web3Number(0, 0),
|
|
34546
34599
|
calls: []
|
|
34547
34600
|
};
|
|
34548
|
-
;
|
|
34549
34601
|
}
|
|
34550
34602
|
}
|
|
34551
34603
|
async checkPriceDifferenceBetweenAvnuAndExtended(extendedAdapter, vesuAdapter, avnuAdapter) {
|