@strkfarm/sdk 1.1.47 → 1.1.49
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 +17 -8
- package/dist/index.browser.mjs +17 -8
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -8
- package/dist/index.mjs +17 -8
- package/package.json +1 -1
- package/src/modules/ekubo-quoter.ts +13 -4
- package/src/strategies/universal-lst-muliplier-strategy.tsx +4 -4
- package/src/modules/midas.ts +0 -159
- package/src/modules/token-market-data.ts +0 -202
|
@@ -53816,12 +53816,21 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
53816
53816
|
* @param amount Can be negative too, which would mean to get exact amount out
|
|
53817
53817
|
* @returns
|
|
53818
53818
|
*/
|
|
53819
|
-
async getQuote(fromToken, toToken, amount) {
|
|
53819
|
+
async getQuote(fromToken, toToken, amount, retry = 0) {
|
|
53820
53820
|
let _fromToken = amount.gt(0) ? fromToken : toToken;
|
|
53821
53821
|
let _toToken = amount.gt(0) ? toToken : fromToken;
|
|
53822
|
-
|
|
53823
|
-
|
|
53824
|
-
|
|
53822
|
+
try {
|
|
53823
|
+
const quote = await axios_default.get(this.ENDPOINT.replace("{{AMOUNT}}", amount.toWei()).replace("{{TOKEN_FROM_ADDRESS}}", _fromToken).replace("{{TOKEN_TO_ADDRESS}}", _toToken));
|
|
53824
|
+
console.log(`Ekubo quote from ${_fromToken} to ${_toToken} for ${amount.toString()}: ${JSON.stringify(quote.data)}`);
|
|
53825
|
+
return quote.data;
|
|
53826
|
+
} catch (error2) {
|
|
53827
|
+
console.error(error2.message, "dassf", error2.data);
|
|
53828
|
+
if (retry < 10) {
|
|
53829
|
+
await new Promise((resolve) => setTimeout(resolve, (retry + 1) * 5e3));
|
|
53830
|
+
return await this.getQuote(fromToken, toToken, amount, retry + 1);
|
|
53831
|
+
}
|
|
53832
|
+
throw error2;
|
|
53833
|
+
}
|
|
53825
53834
|
}
|
|
53826
53835
|
/**
|
|
53827
53836
|
* Formats Ekubo response for Vesu multiple use
|
|
@@ -94909,7 +94918,7 @@ spurious results.`);
|
|
|
94909
94918
|
* @param params
|
|
94910
94919
|
*/
|
|
94911
94920
|
async getVesuMultiplyCall(params) {
|
|
94912
|
-
const
|
|
94921
|
+
const vesuAdapter1 = this.getVesuSameTokenAdapter();
|
|
94913
94922
|
const legLTV = await vesuAdapter1.getLTVConfig(this.config);
|
|
94914
94923
|
logger2.verbose(`${this.getTag()}::getVesuMultiplyCall legLTV: ${legLTV}`);
|
|
94915
94924
|
if (!params.isDeposit) {
|
|
@@ -95385,7 +95394,7 @@ spurious results.`);
|
|
|
95385
95394
|
adapters: [],
|
|
95386
95395
|
targetHealthFactor: 1.1,
|
|
95387
95396
|
minHealthFactor: 1.05,
|
|
95388
|
-
borrowable_assets:
|
|
95397
|
+
borrowable_assets: Global.getDefaultTokens().filter((token) => token.symbol === "tBTC" || token.symbol === "WBTC"),
|
|
95389
95398
|
underlyingToken: Global.getDefaultTokens().find((token) => token.symbol === "tBTC")
|
|
95390
95399
|
};
|
|
95391
95400
|
var hyperxsBTC = {
|
|
@@ -95398,7 +95407,7 @@ spurious results.`);
|
|
|
95398
95407
|
adapters: [],
|
|
95399
95408
|
targetHealthFactor: 1.1,
|
|
95400
95409
|
minHealthFactor: 1.05,
|
|
95401
|
-
borrowable_assets:
|
|
95410
|
+
borrowable_assets: Global.getDefaultTokens().filter((token) => token.symbol === "solvBTC"),
|
|
95402
95411
|
underlyingToken: Global.getDefaultTokens().find((token) => token.symbol === "solvBTC")
|
|
95403
95412
|
};
|
|
95404
95413
|
var hyperxLBTC = {
|
|
@@ -95411,7 +95420,7 @@ spurious results.`);
|
|
|
95411
95420
|
adapters: [],
|
|
95412
95421
|
targetHealthFactor: 1.1,
|
|
95413
95422
|
minHealthFactor: 1.05,
|
|
95414
|
-
borrowable_assets:
|
|
95423
|
+
borrowable_assets: Global.getDefaultTokens().filter((token) => token.symbol === "LBTC"),
|
|
95415
95424
|
underlyingToken: Global.getDefaultTokens().find((token) => token.symbol === "LBTC")
|
|
95416
95425
|
};
|
|
95417
95426
|
function getInvestmentSteps(lstSymbol, underlyingSymbol) {
|
package/dist/index.browser.mjs
CHANGED
|
@@ -2208,12 +2208,21 @@ var EkuboQuoter = class {
|
|
|
2208
2208
|
* @param amount Can be negative too, which would mean to get exact amount out
|
|
2209
2209
|
* @returns
|
|
2210
2210
|
*/
|
|
2211
|
-
async getQuote(fromToken, toToken, amount) {
|
|
2211
|
+
async getQuote(fromToken, toToken, amount, retry = 0) {
|
|
2212
2212
|
let _fromToken = amount.gt(0) ? fromToken : toToken;
|
|
2213
2213
|
let _toToken = amount.gt(0) ? toToken : fromToken;
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2214
|
+
try {
|
|
2215
|
+
const quote = await axios5.get(this.ENDPOINT.replace("{{AMOUNT}}", amount.toWei()).replace("{{TOKEN_FROM_ADDRESS}}", _fromToken).replace("{{TOKEN_TO_ADDRESS}}", _toToken));
|
|
2216
|
+
console.log(`Ekubo quote from ${_fromToken} to ${_toToken} for ${amount.toString()}: ${JSON.stringify(quote.data)}`);
|
|
2217
|
+
return quote.data;
|
|
2218
|
+
} catch (error) {
|
|
2219
|
+
console.error(error.message, "dassf", error.data);
|
|
2220
|
+
if (retry < 10) {
|
|
2221
|
+
await new Promise((resolve) => setTimeout(resolve, (retry + 1) * 5e3));
|
|
2222
|
+
return await this.getQuote(fromToken, toToken, amount, retry + 1);
|
|
2223
|
+
}
|
|
2224
|
+
throw error;
|
|
2225
|
+
}
|
|
2217
2226
|
}
|
|
2218
2227
|
/**
|
|
2219
2228
|
* Formats Ekubo response for Vesu multiple use
|
|
@@ -31002,7 +31011,7 @@ var UniversalLstMultiplierStrategy = class _UniversalLstMultiplierStrategy exten
|
|
|
31002
31011
|
* @param params
|
|
31003
31012
|
*/
|
|
31004
31013
|
async getVesuMultiplyCall(params) {
|
|
31005
|
-
const
|
|
31014
|
+
const vesuAdapter1 = this.getVesuSameTokenAdapter();
|
|
31006
31015
|
const legLTV = await vesuAdapter1.getLTVConfig(this.config);
|
|
31007
31016
|
logger.verbose(`${this.getTag()}::getVesuMultiplyCall legLTV: ${legLTV}`);
|
|
31008
31017
|
if (!params.isDeposit) {
|
|
@@ -31478,7 +31487,7 @@ var hyperxtBTC = {
|
|
|
31478
31487
|
adapters: [],
|
|
31479
31488
|
targetHealthFactor: 1.1,
|
|
31480
31489
|
minHealthFactor: 1.05,
|
|
31481
|
-
borrowable_assets:
|
|
31490
|
+
borrowable_assets: Global.getDefaultTokens().filter((token) => token.symbol === "tBTC" || token.symbol === "WBTC"),
|
|
31482
31491
|
underlyingToken: Global.getDefaultTokens().find((token) => token.symbol === "tBTC")
|
|
31483
31492
|
};
|
|
31484
31493
|
var hyperxsBTC = {
|
|
@@ -31491,7 +31500,7 @@ var hyperxsBTC = {
|
|
|
31491
31500
|
adapters: [],
|
|
31492
31501
|
targetHealthFactor: 1.1,
|
|
31493
31502
|
minHealthFactor: 1.05,
|
|
31494
|
-
borrowable_assets:
|
|
31503
|
+
borrowable_assets: Global.getDefaultTokens().filter((token) => token.symbol === "solvBTC"),
|
|
31495
31504
|
underlyingToken: Global.getDefaultTokens().find((token) => token.symbol === "solvBTC")
|
|
31496
31505
|
};
|
|
31497
31506
|
var hyperxLBTC = {
|
|
@@ -31504,7 +31513,7 @@ var hyperxLBTC = {
|
|
|
31504
31513
|
adapters: [],
|
|
31505
31514
|
targetHealthFactor: 1.1,
|
|
31506
31515
|
minHealthFactor: 1.05,
|
|
31507
|
-
borrowable_assets:
|
|
31516
|
+
borrowable_assets: Global.getDefaultTokens().filter((token) => token.symbol === "LBTC"),
|
|
31508
31517
|
underlyingToken: Global.getDefaultTokens().find((token) => token.symbol === "LBTC")
|
|
31509
31518
|
};
|
|
31510
31519
|
function getInvestmentSteps(lstSymbol, underlyingSymbol) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1544,7 +1544,7 @@ declare class EkuboQuoter {
|
|
|
1544
1544
|
* @param amount Can be negative too, which would mean to get exact amount out
|
|
1545
1545
|
* @returns
|
|
1546
1546
|
*/
|
|
1547
|
-
getQuote(fromToken: string, toToken: string, amount: Web3Number): Promise<EkuboQuote>;
|
|
1547
|
+
getQuote(fromToken: string, toToken: string, amount: Web3Number, retry?: number): Promise<EkuboQuote>;
|
|
1548
1548
|
/**
|
|
1549
1549
|
* Formats Ekubo response for Vesu multiple use
|
|
1550
1550
|
* @param quote
|
package/dist/index.js
CHANGED
|
@@ -2363,12 +2363,21 @@ var EkuboQuoter = class {
|
|
|
2363
2363
|
* @param amount Can be negative too, which would mean to get exact amount out
|
|
2364
2364
|
* @returns
|
|
2365
2365
|
*/
|
|
2366
|
-
async getQuote(fromToken, toToken, amount) {
|
|
2366
|
+
async getQuote(fromToken, toToken, amount, retry = 0) {
|
|
2367
2367
|
let _fromToken = amount.gt(0) ? fromToken : toToken;
|
|
2368
2368
|
let _toToken = amount.gt(0) ? toToken : fromToken;
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2369
|
+
try {
|
|
2370
|
+
const quote = await import_axios5.default.get(this.ENDPOINT.replace("{{AMOUNT}}", amount.toWei()).replace("{{TOKEN_FROM_ADDRESS}}", _fromToken).replace("{{TOKEN_TO_ADDRESS}}", _toToken));
|
|
2371
|
+
console.log(`Ekubo quote from ${_fromToken} to ${_toToken} for ${amount.toString()}: ${JSON.stringify(quote.data)}`);
|
|
2372
|
+
return quote.data;
|
|
2373
|
+
} catch (error) {
|
|
2374
|
+
console.error(error.message, "dassf", error.data);
|
|
2375
|
+
if (retry < 10) {
|
|
2376
|
+
await new Promise((resolve) => setTimeout(resolve, (retry + 1) * 5e3));
|
|
2377
|
+
return await this.getQuote(fromToken, toToken, amount, retry + 1);
|
|
2378
|
+
}
|
|
2379
|
+
throw error;
|
|
2380
|
+
}
|
|
2372
2381
|
}
|
|
2373
2382
|
/**
|
|
2374
2383
|
* Formats Ekubo response for Vesu multiple use
|
|
@@ -31002,7 +31011,7 @@ var UniversalLstMultiplierStrategy = class _UniversalLstMultiplierStrategy exten
|
|
|
31002
31011
|
* @param params
|
|
31003
31012
|
*/
|
|
31004
31013
|
async getVesuMultiplyCall(params) {
|
|
31005
|
-
const
|
|
31014
|
+
const vesuAdapter1 = this.getVesuSameTokenAdapter();
|
|
31006
31015
|
const legLTV = await vesuAdapter1.getLTVConfig(this.config);
|
|
31007
31016
|
logger.verbose(`${this.getTag()}::getVesuMultiplyCall legLTV: ${legLTV}`);
|
|
31008
31017
|
if (!params.isDeposit) {
|
|
@@ -31478,7 +31487,7 @@ var hyperxtBTC = {
|
|
|
31478
31487
|
adapters: [],
|
|
31479
31488
|
targetHealthFactor: 1.1,
|
|
31480
31489
|
minHealthFactor: 1.05,
|
|
31481
|
-
borrowable_assets:
|
|
31490
|
+
borrowable_assets: Global.getDefaultTokens().filter((token) => token.symbol === "tBTC" || token.symbol === "WBTC"),
|
|
31482
31491
|
underlyingToken: Global.getDefaultTokens().find((token) => token.symbol === "tBTC")
|
|
31483
31492
|
};
|
|
31484
31493
|
var hyperxsBTC = {
|
|
@@ -31491,7 +31500,7 @@ var hyperxsBTC = {
|
|
|
31491
31500
|
adapters: [],
|
|
31492
31501
|
targetHealthFactor: 1.1,
|
|
31493
31502
|
minHealthFactor: 1.05,
|
|
31494
|
-
borrowable_assets:
|
|
31503
|
+
borrowable_assets: Global.getDefaultTokens().filter((token) => token.symbol === "solvBTC"),
|
|
31495
31504
|
underlyingToken: Global.getDefaultTokens().find((token) => token.symbol === "solvBTC")
|
|
31496
31505
|
};
|
|
31497
31506
|
var hyperxLBTC = {
|
|
@@ -31504,7 +31513,7 @@ var hyperxLBTC = {
|
|
|
31504
31513
|
adapters: [],
|
|
31505
31514
|
targetHealthFactor: 1.1,
|
|
31506
31515
|
minHealthFactor: 1.05,
|
|
31507
|
-
borrowable_assets:
|
|
31516
|
+
borrowable_assets: Global.getDefaultTokens().filter((token) => token.symbol === "LBTC"),
|
|
31508
31517
|
underlyingToken: Global.getDefaultTokens().find((token) => token.symbol === "LBTC")
|
|
31509
31518
|
};
|
|
31510
31519
|
function getInvestmentSteps(lstSymbol, underlyingSymbol) {
|
package/dist/index.mjs
CHANGED
|
@@ -2257,12 +2257,21 @@ var EkuboQuoter = class {
|
|
|
2257
2257
|
* @param amount Can be negative too, which would mean to get exact amount out
|
|
2258
2258
|
* @returns
|
|
2259
2259
|
*/
|
|
2260
|
-
async getQuote(fromToken, toToken, amount) {
|
|
2260
|
+
async getQuote(fromToken, toToken, amount, retry = 0) {
|
|
2261
2261
|
let _fromToken = amount.gt(0) ? fromToken : toToken;
|
|
2262
2262
|
let _toToken = amount.gt(0) ? toToken : fromToken;
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2263
|
+
try {
|
|
2264
|
+
const quote = await axios5.get(this.ENDPOINT.replace("{{AMOUNT}}", amount.toWei()).replace("{{TOKEN_FROM_ADDRESS}}", _fromToken).replace("{{TOKEN_TO_ADDRESS}}", _toToken));
|
|
2265
|
+
console.log(`Ekubo quote from ${_fromToken} to ${_toToken} for ${amount.toString()}: ${JSON.stringify(quote.data)}`);
|
|
2266
|
+
return quote.data;
|
|
2267
|
+
} catch (error) {
|
|
2268
|
+
console.error(error.message, "dassf", error.data);
|
|
2269
|
+
if (retry < 10) {
|
|
2270
|
+
await new Promise((resolve) => setTimeout(resolve, (retry + 1) * 5e3));
|
|
2271
|
+
return await this.getQuote(fromToken, toToken, amount, retry + 1);
|
|
2272
|
+
}
|
|
2273
|
+
throw error;
|
|
2274
|
+
}
|
|
2266
2275
|
}
|
|
2267
2276
|
/**
|
|
2268
2277
|
* Formats Ekubo response for Vesu multiple use
|
|
@@ -30900,7 +30909,7 @@ var UniversalLstMultiplierStrategy = class _UniversalLstMultiplierStrategy exten
|
|
|
30900
30909
|
* @param params
|
|
30901
30910
|
*/
|
|
30902
30911
|
async getVesuMultiplyCall(params) {
|
|
30903
|
-
const
|
|
30912
|
+
const vesuAdapter1 = this.getVesuSameTokenAdapter();
|
|
30904
30913
|
const legLTV = await vesuAdapter1.getLTVConfig(this.config);
|
|
30905
30914
|
logger.verbose(`${this.getTag()}::getVesuMultiplyCall legLTV: ${legLTV}`);
|
|
30906
30915
|
if (!params.isDeposit) {
|
|
@@ -31376,7 +31385,7 @@ var hyperxtBTC = {
|
|
|
31376
31385
|
adapters: [],
|
|
31377
31386
|
targetHealthFactor: 1.1,
|
|
31378
31387
|
minHealthFactor: 1.05,
|
|
31379
|
-
borrowable_assets:
|
|
31388
|
+
borrowable_assets: Global.getDefaultTokens().filter((token) => token.symbol === "tBTC" || token.symbol === "WBTC"),
|
|
31380
31389
|
underlyingToken: Global.getDefaultTokens().find((token) => token.symbol === "tBTC")
|
|
31381
31390
|
};
|
|
31382
31391
|
var hyperxsBTC = {
|
|
@@ -31389,7 +31398,7 @@ var hyperxsBTC = {
|
|
|
31389
31398
|
adapters: [],
|
|
31390
31399
|
targetHealthFactor: 1.1,
|
|
31391
31400
|
minHealthFactor: 1.05,
|
|
31392
|
-
borrowable_assets:
|
|
31401
|
+
borrowable_assets: Global.getDefaultTokens().filter((token) => token.symbol === "solvBTC"),
|
|
31393
31402
|
underlyingToken: Global.getDefaultTokens().find((token) => token.symbol === "solvBTC")
|
|
31394
31403
|
};
|
|
31395
31404
|
var hyperxLBTC = {
|
|
@@ -31402,7 +31411,7 @@ var hyperxLBTC = {
|
|
|
31402
31411
|
adapters: [],
|
|
31403
31412
|
targetHealthFactor: 1.1,
|
|
31404
31413
|
minHealthFactor: 1.05,
|
|
31405
|
-
borrowable_assets:
|
|
31414
|
+
borrowable_assets: Global.getDefaultTokens().filter((token) => token.symbol === "LBTC"),
|
|
31406
31415
|
underlyingToken: Global.getDefaultTokens().find((token) => token.symbol === "LBTC")
|
|
31407
31416
|
};
|
|
31408
31417
|
function getInvestmentSteps(lstSymbol, underlyingSymbol) {
|
package/package.json
CHANGED
|
@@ -39,13 +39,22 @@ export class EkuboQuoter {
|
|
|
39
39
|
* @param amount Can be negative too, which would mean to get exact amount out
|
|
40
40
|
* @returns
|
|
41
41
|
*/
|
|
42
|
-
async getQuote(fromToken: string, toToken: string, amount: Web3Number): Promise<EkuboQuote> {
|
|
42
|
+
async getQuote(fromToken: string, toToken: string, amount: Web3Number, retry = 0): Promise<EkuboQuote> {
|
|
43
43
|
let _fromToken = amount.gt(0) ? fromToken : toToken;
|
|
44
44
|
let _toToken = amount.gt(0) ? toToken : fromToken;
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
try {
|
|
47
|
+
const quote = await axios.get(this.ENDPOINT.replace("{{AMOUNT}}", amount.toWei()).replace("{{TOKEN_FROM_ADDRESS}}", _fromToken).replace("{{TOKEN_TO_ADDRESS}}", _toToken));
|
|
48
|
+
console.log(`Ekubo quote from ${_fromToken} to ${_toToken} for ${amount.toString()}: ${JSON.stringify(quote.data)}`);
|
|
49
|
+
return quote.data as EkuboQuote;
|
|
50
|
+
} catch (error: any) {
|
|
51
|
+
console.error(error.message, 'dassf', error.data);
|
|
52
|
+
if (retry < 10) {
|
|
53
|
+
await new Promise((resolve) => setTimeout(resolve, (retry + 1) * 5000));
|
|
54
|
+
return await this.getQuote(fromToken, toToken, amount, retry + 1);
|
|
55
|
+
}
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
49
58
|
}
|
|
50
59
|
|
|
51
60
|
/**
|
|
@@ -429,7 +429,7 @@ export class UniversalLstMultiplierStrategy extends UniversalStrategy<HyperLSTSt
|
|
|
429
429
|
isDeposit: boolean,
|
|
430
430
|
leg1DepositAmount: Web3Number
|
|
431
431
|
}) {
|
|
432
|
-
const
|
|
432
|
+
const vesuAdapter1 = this.getVesuSameTokenAdapter();
|
|
433
433
|
const legLTV = await vesuAdapter1.getLTVConfig(this.config);
|
|
434
434
|
logger.verbose(`${this.getTag()}::getVesuMultiplyCall legLTV: ${legLTV}`);
|
|
435
435
|
|
|
@@ -1046,7 +1046,7 @@ const hyperxtBTC: HyperLSTStrategySettings = {
|
|
|
1046
1046
|
adapters: [],
|
|
1047
1047
|
targetHealthFactor: 1.1,
|
|
1048
1048
|
minHealthFactor: 1.05,
|
|
1049
|
-
borrowable_assets:
|
|
1049
|
+
borrowable_assets: Global.getDefaultTokens().filter(token => token.symbol === 'tBTC' || token.symbol === 'WBTC'),
|
|
1050
1050
|
underlyingToken: Global.getDefaultTokens().find(token => token.symbol === 'tBTC')!,
|
|
1051
1051
|
}
|
|
1052
1052
|
|
|
@@ -1060,7 +1060,7 @@ const hyperxsBTC: HyperLSTStrategySettings = {
|
|
|
1060
1060
|
adapters: [],
|
|
1061
1061
|
targetHealthFactor: 1.1,
|
|
1062
1062
|
minHealthFactor: 1.05,
|
|
1063
|
-
borrowable_assets:
|
|
1063
|
+
borrowable_assets: Global.getDefaultTokens().filter(token => token.symbol === 'solvBTC'),
|
|
1064
1064
|
underlyingToken: Global.getDefaultTokens().find(token => token.symbol === 'solvBTC')!,
|
|
1065
1065
|
}
|
|
1066
1066
|
|
|
@@ -1074,7 +1074,7 @@ const hyperxLBTC: HyperLSTStrategySettings = {
|
|
|
1074
1074
|
adapters: [],
|
|
1075
1075
|
targetHealthFactor: 1.1,
|
|
1076
1076
|
minHealthFactor: 1.05,
|
|
1077
|
-
borrowable_assets:
|
|
1077
|
+
borrowable_assets: Global.getDefaultTokens().filter(token => token.symbol === 'LBTC'),
|
|
1078
1078
|
underlyingToken: Global.getDefaultTokens().find(token => token.symbol === 'LBTC')!,
|
|
1079
1079
|
}
|
|
1080
1080
|
|
package/src/modules/midas.ts
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
// import axios from 'axios';
|
|
2
|
-
// import { ContractAddr } from '../dataTypes';
|
|
3
|
-
// import { logger } from '../utils/logger';
|
|
4
|
-
|
|
5
|
-
// /**
|
|
6
|
-
// * Midas module for interacting with Midas API
|
|
7
|
-
// * Provides functions to get APY, price, and TVL data for Midas tokens
|
|
8
|
-
// */
|
|
9
|
-
// export class Midas {
|
|
10
|
-
// // Static mapping of contract addresses to Midas API symbols
|
|
11
|
-
// private static readonly CONTRACT_TO_SYMBOL: Record<string, string> = {
|
|
12
|
-
// '0x4e4fb1a9ca7e84bae609b9dc0078ad7719e49187ae7e425bb47d131710eddac': 'mre7btc', // mRe7BTC
|
|
13
|
-
// '0x4be8945e61dc3e19ebadd1579a6bd53b262f51ba89e6f8b0c4bc9a7e3c633fc': 'mre7', // mRe7YIELD
|
|
14
|
-
// };
|
|
15
|
-
|
|
16
|
-
// private static readonly BASE_URL = 'https://api-prod.midas.app/api/data';
|
|
17
|
-
|
|
18
|
-
// /**
|
|
19
|
-
// * Check if a contract address is supported by Midas
|
|
20
|
-
// * @param contractAddr The contract address to check
|
|
21
|
-
// * @returns True if the contract address is supported
|
|
22
|
-
// */
|
|
23
|
-
// static isSupported(contractAddr: ContractAddr): boolean {
|
|
24
|
-
// return contractAddr.address in Midas.CONTRACT_TO_SYMBOL;
|
|
25
|
-
// }
|
|
26
|
-
|
|
27
|
-
// /**
|
|
28
|
-
// * Get the Midas symbol for a given contract address
|
|
29
|
-
// * @param contractAddr The contract address to look up
|
|
30
|
-
// * @returns The Midas symbol for the contract
|
|
31
|
-
// * @throws Error if contract address is not found
|
|
32
|
-
// */
|
|
33
|
-
// static getSymbolFromContract(contractAddr: ContractAddr): string {
|
|
34
|
-
// const symbol = Midas.CONTRACT_TO_SYMBOL[contractAddr.address];
|
|
35
|
-
// if (!symbol) {
|
|
36
|
-
// throw new Error(`Contract address ${contractAddr.address} not found in Midas mapping`);
|
|
37
|
-
// }
|
|
38
|
-
// return symbol;
|
|
39
|
-
// }
|
|
40
|
-
|
|
41
|
-
// /**
|
|
42
|
-
// * Get APY data for all Midas tokens
|
|
43
|
-
// * @returns Object with token symbols as keys and APY values as numbers
|
|
44
|
-
// * @throws Error if API request fails
|
|
45
|
-
// */
|
|
46
|
-
// static async getAPYs(): Promise<Record<string, number>> {
|
|
47
|
-
// try {
|
|
48
|
-
// const response = await axios.get(`${Midas.BASE_URL}/apys`);
|
|
49
|
-
// return response.data;
|
|
50
|
-
// } catch (error) {
|
|
51
|
-
// logger.error('Failed to fetch APYs from Midas API:', error);
|
|
52
|
-
// throw new Error(`Failed to fetch APYs: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
53
|
-
// }
|
|
54
|
-
// }
|
|
55
|
-
|
|
56
|
-
// /**
|
|
57
|
-
// * Get APY for a specific token by contract address
|
|
58
|
-
// * @param contractAddr The contract address of the token
|
|
59
|
-
// * @returns The APY value for the token
|
|
60
|
-
// * @throws Error if contract address not found or API request fails
|
|
61
|
-
// */
|
|
62
|
-
// static async getAPY(contractAddr: ContractAddr): Promise<number> {
|
|
63
|
-
// const symbol = Midas.getSymbolFromContract(contractAddr);
|
|
64
|
-
// const apys = await Midas.getAPYs();
|
|
65
|
-
|
|
66
|
-
// if (!(symbol in apys)) {
|
|
67
|
-
// throw new Error(`Symbol ${symbol} not found in APY data`);
|
|
68
|
-
// }
|
|
69
|
-
|
|
70
|
-
// return apys[symbol];
|
|
71
|
-
// }
|
|
72
|
-
|
|
73
|
-
// /**
|
|
74
|
-
// * Get price data for a specific token
|
|
75
|
-
// * @param contractAddr The contract address of the token
|
|
76
|
-
// * @param timestampFrom Optional start timestamp (defaults to 30 days ago)
|
|
77
|
-
// * @param timestampTo Optional end timestamp (defaults to now)
|
|
78
|
-
// * @param environment Environment (defaults to 'mainnet')
|
|
79
|
-
// * @returns The latest price for the token
|
|
80
|
-
// * @throws Error if contract address not found or API request fails
|
|
81
|
-
// */
|
|
82
|
-
// static async getPrice(
|
|
83
|
-
// contractAddr: ContractAddr,
|
|
84
|
-
// timestampFrom?: number,
|
|
85
|
-
// timestampTo?: number,
|
|
86
|
-
// environment: string = 'mainnet'
|
|
87
|
-
// ): Promise<number> {
|
|
88
|
-
// const symbol = Midas.getSymbolFromContract(contractAddr);
|
|
89
|
-
|
|
90
|
-
// // Default to 30 days ago if not provided
|
|
91
|
-
// const from = timestampFrom ?? Math.floor(Date.now() / 1000) - (30 * 24 * 60 * 60);
|
|
92
|
-
// // Default to now if not provided
|
|
93
|
-
// const to = timestampTo ?? Math.floor(Date.now() / 1000);
|
|
94
|
-
|
|
95
|
-
// try {
|
|
96
|
-
// const response = await axios.get(`${Midas.BASE_URL}/${symbol}/price`, {
|
|
97
|
-
// params: {
|
|
98
|
-
// timestampFrom: from,
|
|
99
|
-
// timestampTo: to,
|
|
100
|
-
// environment
|
|
101
|
-
// }
|
|
102
|
-
// });
|
|
103
|
-
|
|
104
|
-
// const priceData = response.data;
|
|
105
|
-
// if (!Array.isArray(priceData) || priceData.length === 0) {
|
|
106
|
-
// throw new Error(`No price data found for ${symbol}`);
|
|
107
|
-
// }
|
|
108
|
-
|
|
109
|
-
// // Return the latest price (first item in the array)
|
|
110
|
-
// return priceData[0].price;
|
|
111
|
-
// } catch (error) {
|
|
112
|
-
// logger.error(`Failed to fetch price for ${symbol}:`, error);
|
|
113
|
-
// throw new Error(`Failed to fetch price for ${symbol}: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
114
|
-
// }
|
|
115
|
-
// }
|
|
116
|
-
|
|
117
|
-
// /**
|
|
118
|
-
// * Get TVL data for all tokens
|
|
119
|
-
// * @param environment Environment (defaults to 'mainnet')
|
|
120
|
-
// * @returns Object with TVL data including totalTvl and tokenTvl
|
|
121
|
-
// * @throws Error if API request fails
|
|
122
|
-
// */
|
|
123
|
-
// static async getTVLData(environment: string = 'mainnet'): Promise<{
|
|
124
|
-
// lastUpdatedAt: string;
|
|
125
|
-
// totalTvl: number;
|
|
126
|
-
// tokenTvl: Record<string, any>;
|
|
127
|
-
// }> {
|
|
128
|
-
// try {
|
|
129
|
-
// const response = await axios.get(`${Midas.BASE_URL}/tvl`, {
|
|
130
|
-
// params: { environment }
|
|
131
|
-
// });
|
|
132
|
-
// return response.data;
|
|
133
|
-
// } catch (error) {
|
|
134
|
-
// logger.error('Failed to fetch TVL data from Midas API:', error);
|
|
135
|
-
// throw new Error(`Failed to fetch TVL data: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
136
|
-
// }
|
|
137
|
-
// }
|
|
138
|
-
|
|
139
|
-
// /**
|
|
140
|
-
// * Get TVL for a specific token by contract address
|
|
141
|
-
// * @param contractAddr The contract address of the token
|
|
142
|
-
// * @param environment Environment (defaults to 'mainnet')
|
|
143
|
-
// * @returns The TVL data for the token (USD and native amounts)
|
|
144
|
-
// * @throws Error if contract address not found or API request fails
|
|
145
|
-
// */
|
|
146
|
-
// static async getTVL(
|
|
147
|
-
// contractAddr: ContractAddr,
|
|
148
|
-
// environment: string = 'mainnet'
|
|
149
|
-
// ): Promise<{ usd: number; native: number } | number> {
|
|
150
|
-
// const symbol = Midas.getSymbolFromContract(contractAddr);
|
|
151
|
-
// const tvlData = await Midas.getTVLData(environment);
|
|
152
|
-
|
|
153
|
-
// if (!(symbol in tvlData.tokenTvl)) {
|
|
154
|
-
// throw new Error(`Symbol ${symbol} not found in TVL data`);
|
|
155
|
-
// }
|
|
156
|
-
|
|
157
|
-
// return tvlData.tokenTvl[symbol];
|
|
158
|
-
// }
|
|
159
|
-
// }
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
// import { ContractAddr, Web3Number } from '../dataTypes';
|
|
2
|
-
// import { TokenInfo, IConfig } from '../interfaces';
|
|
3
|
-
// import { PricerBase } from './pricerBase';
|
|
4
|
-
// import { LSTAPRService } from './lst-apr';
|
|
5
|
-
// import { Midas } from './midas';
|
|
6
|
-
// import { SingleTokenInfo } from '../strategies/base-strategy';
|
|
7
|
-
// import { logger } from '../utils/logger';
|
|
8
|
-
// import { Contract } from 'starknet';
|
|
9
|
-
// import { uint256 } from 'starknet';
|
|
10
|
-
// import ERC4626Abi from '../data/erc4626.abi.json';
|
|
11
|
-
|
|
12
|
-
// /**
|
|
13
|
-
// * TokenMarketData class that combines LST APR and Midas modules
|
|
14
|
-
// * to provide unified APY, price, and TVL functions for tokens
|
|
15
|
-
// */
|
|
16
|
-
// export class TokenMarketData {
|
|
17
|
-
// private pricer: PricerBase;
|
|
18
|
-
// private config: IConfig;
|
|
19
|
-
|
|
20
|
-
// constructor(pricer: PricerBase, config: IConfig) {
|
|
21
|
-
// this.pricer = pricer;
|
|
22
|
-
// this.config = config;
|
|
23
|
-
// }
|
|
24
|
-
|
|
25
|
-
// /**
|
|
26
|
-
// * Get APY for a token
|
|
27
|
-
// * - If it's an LST token, returns LST APY
|
|
28
|
-
// * - If it's a Midas token, returns Midas APY
|
|
29
|
-
// * - Otherwise returns 0
|
|
30
|
-
// * @param tokenInfo The token to get APY for
|
|
31
|
-
// * @returns APY in absolute terms (not percentage)
|
|
32
|
-
// */
|
|
33
|
-
// async getAPY(tokenInfo: TokenInfo): Promise<number> {
|
|
34
|
-
// try {
|
|
35
|
-
// // Check if it's an LST token
|
|
36
|
-
// if (LSTAPRService.isLST(tokenInfo.address)) {
|
|
37
|
-
// const underlying = LSTAPRService.getUnderlyingFromLST(tokenInfo.address);
|
|
38
|
-
// const lstApr = await LSTAPRService.getLSTAPR(underlying.address);
|
|
39
|
-
// logger.verbose(`TokenMarketData: LST APY for ${tokenInfo.symbol}: ${lstApr}`);
|
|
40
|
-
// return lstApr;
|
|
41
|
-
// }
|
|
42
|
-
|
|
43
|
-
// // Check if it's a Midas token by trying to get symbol
|
|
44
|
-
// if (Midas.isSupported(tokenInfo.address)) {
|
|
45
|
-
// const midasApy = await Midas.getAPY(tokenInfo.address);
|
|
46
|
-
// logger.verbose(`TokenMarketData: Midas APY for ${tokenInfo.symbol}: ${midasApy}`);
|
|
47
|
-
// return midasApy;
|
|
48
|
-
// }
|
|
49
|
-
|
|
50
|
-
// // Default to 0 for unsupported tokens
|
|
51
|
-
// logger.verbose(`TokenMarketData: No APY data available for ${tokenInfo.symbol}, returning 0`);
|
|
52
|
-
// return 0;
|
|
53
|
-
// } catch (error) {
|
|
54
|
-
// logger.error(`TokenMarketData: Error getting APY for ${tokenInfo.symbol}:`, error);
|
|
55
|
-
// return 0;
|
|
56
|
-
// }
|
|
57
|
-
// }
|
|
58
|
-
|
|
59
|
-
// /**
|
|
60
|
-
// * Get price for a token using the pricer module
|
|
61
|
-
// * @param tokenInfo The token to get price for
|
|
62
|
-
// * @returns Price as a number
|
|
63
|
-
// * @throws Error if price is 0 or unavailable
|
|
64
|
-
// */
|
|
65
|
-
// async getPrice(tokenInfo: TokenInfo): Promise<number> {
|
|
66
|
-
// try {
|
|
67
|
-
// const priceInfo = await this.pricer.getPrice(tokenInfo.symbol);
|
|
68
|
-
|
|
69
|
-
// if (priceInfo.price === 0) {
|
|
70
|
-
// throw new Error(`Price is 0 for token ${tokenInfo.symbol}`);
|
|
71
|
-
// }
|
|
72
|
-
|
|
73
|
-
// logger.verbose(`TokenMarketData: Price for ${tokenInfo.symbol}: ${priceInfo.price}`);
|
|
74
|
-
// return priceInfo.price;
|
|
75
|
-
// } catch (error) {
|
|
76
|
-
// logger.error(`TokenMarketData: Error getting price for ${tokenInfo.symbol}:`, error);
|
|
77
|
-
// throw new Error(`Failed to get price for ${tokenInfo.symbol}: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
78
|
-
// }
|
|
79
|
-
// }
|
|
80
|
-
|
|
81
|
-
// /**
|
|
82
|
-
// * Get true price for a token
|
|
83
|
-
// * - For LST tokens: Uses convert_to_assets to get true exchange rate
|
|
84
|
-
// * - For Midas tokens: Uses Midas price API
|
|
85
|
-
// * - For other tokens: Falls back to regular pricer
|
|
86
|
-
// * @param tokenInfo The token to get true price for
|
|
87
|
-
// * @returns True price as a number
|
|
88
|
-
// * @throws Error if price is 0 or unavailable
|
|
89
|
-
// */
|
|
90
|
-
// async getTruePrice(tokenInfo: TokenInfo): Promise<number> {
|
|
91
|
-
// try {
|
|
92
|
-
// // For LST tokens, use convert_to_assets
|
|
93
|
-
// if (LSTAPRService.isLST(tokenInfo.address)) {
|
|
94
|
-
// const lstABI = new Contract({
|
|
95
|
-
// abi: ERC4626Abi,
|
|
96
|
-
// address: tokenInfo.address.address,
|
|
97
|
-
// providerOrAccount: this.config.provider
|
|
98
|
-
// });
|
|
99
|
-
|
|
100
|
-
// const price: any = await lstABI.call('convert_to_assets', [
|
|
101
|
-
// uint256.bnToUint256((new Web3Number(1, tokenInfo.decimals)).toWei())
|
|
102
|
-
// ]);
|
|
103
|
-
// const exchangeRate = Number(uint256.uint256ToBN(price).toString()) / Math.pow(10, tokenInfo.decimals);
|
|
104
|
-
|
|
105
|
-
// if (exchangeRate === 0) {
|
|
106
|
-
// throw new Error(`True price is 0 for LST token ${tokenInfo.symbol}`);
|
|
107
|
-
// }
|
|
108
|
-
|
|
109
|
-
// logger.verbose(`TokenMarketData: LST true price for ${tokenInfo.symbol}: ${exchangeRate}`);
|
|
110
|
-
// return exchangeRate;
|
|
111
|
-
// }
|
|
112
|
-
|
|
113
|
-
// // For Midas tokens, use Midas price API
|
|
114
|
-
// if (Midas.isSupported(tokenInfo.address)) {
|
|
115
|
-
// const midasPrice = await Midas.getPrice(tokenInfo.address);
|
|
116
|
-
|
|
117
|
-
// if (midasPrice === 0) {
|
|
118
|
-
// throw new Error(`True price is 0 for Midas token ${tokenInfo.symbol}`);
|
|
119
|
-
// }
|
|
120
|
-
|
|
121
|
-
// logger.verbose(`TokenMarketData: Midas true price for ${tokenInfo.symbol}: ${midasPrice}`);
|
|
122
|
-
// return midasPrice;
|
|
123
|
-
// }
|
|
124
|
-
|
|
125
|
-
// // For other tokens, fall back to regular pricer
|
|
126
|
-
// const price = await this.getPrice(tokenInfo);
|
|
127
|
-
|
|
128
|
-
// if (price === 0) {
|
|
129
|
-
// throw new Error(`True price is 0 for token ${tokenInfo.symbol}`);
|
|
130
|
-
// }
|
|
131
|
-
|
|
132
|
-
// logger.verbose(`TokenMarketData: Regular price for ${tokenInfo.symbol}: ${price}`);
|
|
133
|
-
// return price;
|
|
134
|
-
// } catch (error) {
|
|
135
|
-
// logger.error(`TokenMarketData: Error getting true price for ${tokenInfo.symbol}:`, error);
|
|
136
|
-
// throw new Error(`Failed to get true price for ${tokenInfo.symbol}: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
137
|
-
// }
|
|
138
|
-
// }
|
|
139
|
-
|
|
140
|
-
// /**
|
|
141
|
-
// * Get TVL for a token
|
|
142
|
-
// * - If it's a Midas token, returns Midas TVL data
|
|
143
|
-
// * - Otherwise returns 0
|
|
144
|
-
// * @param tokenInfo The token to get TVL for
|
|
145
|
-
// * @returns TVL as SingleTokenInfo or 0
|
|
146
|
-
// */
|
|
147
|
-
// async getTVL(tokenInfo: TokenInfo): Promise<SingleTokenInfo> {
|
|
148
|
-
// // Check if it's a Midas token by trying to get TVL
|
|
149
|
-
// if (Midas.isSupported(tokenInfo.address)) {
|
|
150
|
-
// const midasTvl = await Midas.getTVL(tokenInfo.address);
|
|
151
|
-
|
|
152
|
-
// // Handle different TVL response formats
|
|
153
|
-
// let usdValue: number;
|
|
154
|
-
// let nativeAmount: number;
|
|
155
|
-
|
|
156
|
-
// if (typeof midasTvl === 'number') {
|
|
157
|
-
// // Simple number format (e.g., mre7: 18193466)
|
|
158
|
-
// usdValue = midasTvl;
|
|
159
|
-
// nativeAmount = 0; // We don't have native amount in this format
|
|
160
|
-
// } else if (typeof midasTvl === 'object' && 'usd' in midasTvl && 'native' in midasTvl) {
|
|
161
|
-
// // Object format with usd and native (e.g., mre7btc: {usd: 998826, native: 9.3228})
|
|
162
|
-
// usdValue = midasTvl.usd;
|
|
163
|
-
// nativeAmount = midasTvl.native;
|
|
164
|
-
// } else {
|
|
165
|
-
// throw new Error(`Unexpected TVL format for ${tokenInfo.symbol}`);
|
|
166
|
-
// }
|
|
167
|
-
|
|
168
|
-
// const tvlInfo: SingleTokenInfo = {
|
|
169
|
-
// tokenInfo,
|
|
170
|
-
// amount: Web3Number.fromWei(nativeAmount, tokenInfo.decimals),
|
|
171
|
-
// usdValue
|
|
172
|
-
// };
|
|
173
|
-
|
|
174
|
-
// logger.verbose(`TokenMarketData: Midas TVL for ${tokenInfo.symbol}: USD=${usdValue}, Native=${nativeAmount}`);
|
|
175
|
-
// return tvlInfo;
|
|
176
|
-
// }
|
|
177
|
-
|
|
178
|
-
// return {
|
|
179
|
-
// tokenInfo,
|
|
180
|
-
// amount: Web3Number.fromWei('0', tokenInfo.decimals),
|
|
181
|
-
// usdValue: 0
|
|
182
|
-
// }
|
|
183
|
-
// }
|
|
184
|
-
|
|
185
|
-
// /**
|
|
186
|
-
// * Check if a token is supported for APY data
|
|
187
|
-
// * @param tokenInfo The token to check
|
|
188
|
-
// * @returns True if the token has APY data available
|
|
189
|
-
// */
|
|
190
|
-
// isAPYSupported(tokenInfo: TokenInfo): boolean {
|
|
191
|
-
// return LSTAPRService.isLST(tokenInfo.address) || Midas.isSupported(tokenInfo.address);
|
|
192
|
-
// }
|
|
193
|
-
|
|
194
|
-
// /**
|
|
195
|
-
// * Check if a token is supported for TVL data
|
|
196
|
-
// * @param tokenInfo The token to check
|
|
197
|
-
// * @returns True if the token has TVL data available
|
|
198
|
-
// */
|
|
199
|
-
// isTVLSupported(tokenInfo: TokenInfo): boolean {
|
|
200
|
-
// return Midas.isSupported(tokenInfo.address);
|
|
201
|
-
// }
|
|
202
|
-
// }
|