@strkfarm/sdk 2.0.0-staging.1 → 2.0.0-staging.11
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/cli.js +10 -6
- package/dist/cli.mjs +10 -6
- package/dist/index.browser.global.js +53062 -28963
- package/dist/index.browser.mjs +2429 -1799
- package/dist/index.d.ts +188 -46
- package/dist/index.js +2122 -1479
- package/dist/index.mjs +2698 -2068
- package/package.json +79 -81
- package/src/dataTypes/index.ts +3 -2
- package/src/dataTypes/mynumber.ts +141 -0
- package/src/global.ts +27 -1
- package/src/index.browser.ts +2 -1
- package/src/interfaces/common.tsx +98 -13
- package/src/modules/ekubo-quoter.ts +1 -1
- package/src/modules/harvests.ts +17 -14
- package/src/modules/index.ts +0 -1
- package/src/modules/pricer-lst.ts +1 -1
- package/src/modules/pricer.ts +38 -3
- package/src/strategies/base-strategy.ts +25 -0
- package/src/strategies/ekubo-cl-vault.tsx +547 -269
- package/src/strategies/factory.ts +159 -0
- package/src/strategies/index.ts +1 -0
- package/src/strategies/registry.ts +50 -113
- package/src/strategies/sensei.ts +134 -7
- package/src/strategies/universal-adapters/vesu-adapter.ts +7 -5
- package/src/strategies/universal-lst-muliplier-strategy.tsx +279 -118
- package/src/strategies/universal-strategy.tsx +144 -144
- package/src/strategies/vesu-rebalance.tsx +95 -150
- package/src/utils/index.ts +1 -0
- package/src/utils/logger.node.ts +11 -4
- package/src/utils/strategy-utils.ts +57 -0
package/src/modules/pricer.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { IConfig } from "@/interfaces/common";
|
|
|
5
5
|
import { Web3Number } from "@/dataTypes";
|
|
6
6
|
import { PricerBase } from "./pricerBase";
|
|
7
7
|
import { logger } from "@/utils/logger";
|
|
8
|
+
import { AvnuWrapper } from "./avnu";
|
|
8
9
|
import { BlockIdentifier } from "starknet";
|
|
9
10
|
|
|
10
11
|
export interface PriceInfo {
|
|
@@ -22,13 +23,14 @@ export class Pricer extends PricerBase {
|
|
|
22
23
|
|
|
23
24
|
// code populates this map during runtime to determine which method to use for a given token
|
|
24
25
|
// The method set will be the first one to try after first attempt
|
|
25
|
-
protected methodToUse: {[tokenSymbol: string]: 'Ekubo' | 'Coinbase' | 'Coinmarketcap'} = {};
|
|
26
|
+
protected methodToUse: {[tokenSymbol: string]: 'Ekubo' | 'Coinbase' | 'Coinmarketcap' | 'Avnu'} = {};
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* TOKENA and TOKENB are the two token names to get price of TokenA in terms of TokenB
|
|
29
30
|
*/
|
|
31
|
+
// ! switch to USDC (new) later
|
|
30
32
|
protected PRICE_API = `https://api.coinbase.com/v2/prices/{{PRICER_KEY}}/buy`;
|
|
31
|
-
protected EKUBO_API = 'https://
|
|
33
|
+
protected EKUBO_API = 'https://prod-api-quoter.ekubo.org/23448594291968334/{{AMOUNT}}/{{TOKEN_ADDRESS}}/0x033068F6539f8e6e6b131e6B2B814e6c34A5224bC66947c47DaB9dFeE93b35fb'; // e.g. ETH/USDC
|
|
32
34
|
|
|
33
35
|
constructor(config: IConfig, tokens: TokenInfo[], refreshInterval = 30000, staleTime = 60000) {
|
|
34
36
|
super(config, tokens);
|
|
@@ -94,7 +96,7 @@ export class Pricer extends PricerBase {
|
|
|
94
96
|
let retry = 0;
|
|
95
97
|
while (retry < MAX_RETRIES) {
|
|
96
98
|
try {
|
|
97
|
-
if (token.symbol === 'USDT') {
|
|
99
|
+
if (token.symbol === 'USDT' || token.symbol === 'USDC') {
|
|
98
100
|
this.prices[token.symbol] = {
|
|
99
101
|
price: 1,
|
|
100
102
|
timestamp: new Date()
|
|
@@ -175,6 +177,15 @@ export class Pricer extends PricerBase {
|
|
|
175
177
|
console.warn(`Ekubo: price err [${token.symbol}]: `, Object.keys(error));
|
|
176
178
|
// do nothing, try next
|
|
177
179
|
}
|
|
180
|
+
case 'Avnu':
|
|
181
|
+
try {
|
|
182
|
+
const result = await this._getAvnuPrice(token, new Web3Number(token.priceCheckAmount ? token.priceCheckAmount : 1, token.decimals));
|
|
183
|
+
this.methodToUse[token.symbol] = 'Avnu';
|
|
184
|
+
return result;
|
|
185
|
+
} catch (error: any) {
|
|
186
|
+
console.warn(`Avnu: price err [${token.symbol}]: `, error.message);
|
|
187
|
+
console.warn(`Avnu: price err [${token.symbol}]: `, Object.keys(error));
|
|
188
|
+
}
|
|
178
189
|
}
|
|
179
190
|
|
|
180
191
|
// if methodToUse is the default one, pass Coinbase to try all from start
|
|
@@ -201,7 +212,31 @@ export class Pricer extends PricerBase {
|
|
|
201
212
|
throw new Error("Not implemented");
|
|
202
213
|
}
|
|
203
214
|
|
|
215
|
+
async _getAvnuPrice(token: TokenInfo, amountIn = new Web3Number(1, token.decimals), retry = 0): Promise<number> {
|
|
216
|
+
logger.verbose(`Getting price of ${token.symbol} using Ekubo, amountIn: ${amountIn.toWei()}`);
|
|
217
|
+
|
|
218
|
+
const avnuWrapper = new AvnuWrapper();
|
|
219
|
+
const usdcAddress = '0x033068F6539f8e6e6b131e6B2B814e6c34A5224bC66947c47DaB9dFeE93b35fb';
|
|
220
|
+
const quote = await avnuWrapper.getQuotes(token.address.toString(), usdcAddress, amountIn.toWei(), '0x1');
|
|
221
|
+
const multiplier = 1 / amountIn.toNumber();
|
|
222
|
+
const outputUSDC = Number(Web3Number.fromWei(quote.buyAmount.toString(), 6).toFixed(6)) * multiplier;
|
|
223
|
+
logger.verbose(`Avnu: ${token.symbol} -> USDC: ${outputUSDC}, retry: ${retry}`);
|
|
224
|
+
if (outputUSDC === 0 && retry < 3) {
|
|
225
|
+
// try again with a higher amount
|
|
226
|
+
const amountIn = new Web3Number(100, token.decimals); // 100 unit of token
|
|
227
|
+
return await this._getAvnuPrice(token, amountIn, retry + 1);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// if usdc depegs, it will not longer be 1 USD
|
|
231
|
+
// so we need to get the price of USDC in USD
|
|
232
|
+
// and then convert the outputUSDC to USD
|
|
233
|
+
const usdcPrice = 1; // (await this.getPrice('USDC')).price;
|
|
234
|
+
logger.verbose(`USDC Price: ${usdcPrice}`);
|
|
235
|
+
return outputUSDC * usdcPrice;
|
|
236
|
+
}
|
|
237
|
+
|
|
204
238
|
async _getPriceEkubo(token: TokenInfo, amountIn = new Web3Number(1, token.decimals), retry = 0): Promise<number> {
|
|
239
|
+
logger.verbose(`Getting price of ${token.symbol} using Ekubo, amountIn: ${amountIn.toWei()}`);
|
|
205
240
|
const url = this.EKUBO_API.replace("{{TOKEN_ADDRESS}}", token.address.toString()).replace("{{AMOUNT}}", amountIn.toWei());
|
|
206
241
|
const result = await axios.get(url);
|
|
207
242
|
const data: any = result.data;
|
|
@@ -23,6 +23,16 @@ export interface DualTokenInfo {
|
|
|
23
23
|
token1: SingleTokenInfo
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
export interface NetAPYSplit {
|
|
27
|
+
apy: number;
|
|
28
|
+
id: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface NetAPYDetails {
|
|
32
|
+
net: number;
|
|
33
|
+
splits: NetAPYSplit[];
|
|
34
|
+
}
|
|
35
|
+
|
|
26
36
|
interface CacheData {
|
|
27
37
|
timestamp: number;
|
|
28
38
|
ttl: number;
|
|
@@ -57,7 +67,22 @@ export class BaseStrategy<TVLInfo, ActionInfo> extends CacheClass {
|
|
|
57
67
|
throw new Error("Not implemented");
|
|
58
68
|
}
|
|
59
69
|
|
|
70
|
+
async netAPY(
|
|
71
|
+
blockIdentifier?: BlockIdentifier,
|
|
72
|
+
sinceBlocks?: number,
|
|
73
|
+
timeperiod?: "24h" | "7d" | "30d" | "3m"
|
|
74
|
+
): Promise<number | NetAPYDetails> {
|
|
75
|
+
throw new Error("Not implemented");
|
|
76
|
+
}
|
|
77
|
+
|
|
60
78
|
async getPendingRewards(): Promise<HarvestInfo[]> {
|
|
61
79
|
return [];
|
|
62
80
|
}
|
|
81
|
+
|
|
82
|
+
async getUserRealizedAPY(
|
|
83
|
+
blockIdentifier?: BlockIdentifier,
|
|
84
|
+
sinceBlocks?: number
|
|
85
|
+
): Promise<number> {
|
|
86
|
+
throw new Error("Not implemented");
|
|
87
|
+
}
|
|
63
88
|
}
|