@strkfarm/sdk 2.0.0-dev.3 → 2.0.0-dev.30
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 +190 -36
- package/dist/cli.mjs +188 -34
- package/dist/index.browser.global.js +78478 -45620
- package/dist/index.browser.mjs +19583 -9901
- package/dist/index.d.ts +3763 -1424
- package/dist/index.js +20980 -11063
- package/dist/index.mjs +20948 -11087
- package/package.json +1 -1
- package/src/data/avnu.abi.json +840 -0
- package/src/data/ekubo-price-fethcer.abi.json +265 -0
- package/src/dataTypes/_bignumber.ts +13 -4
- package/src/dataTypes/bignumber.browser.ts +6 -1
- package/src/dataTypes/bignumber.node.ts +5 -1
- package/src/dataTypes/index.ts +3 -2
- package/src/dataTypes/mynumber.ts +141 -0
- package/src/global.ts +76 -41
- package/src/index.browser.ts +2 -1
- package/src/interfaces/common.tsx +175 -3
- package/src/modules/ExtendedWrapperSDk/types.ts +28 -5
- package/src/modules/ExtendedWrapperSDk/wrapper.ts +275 -59
- package/src/modules/apollo-client-config.ts +28 -0
- package/src/modules/avnu.ts +4 -4
- package/src/modules/ekubo-pricer.ts +79 -0
- package/src/modules/ekubo-quoter.ts +48 -30
- package/src/modules/erc20.ts +17 -0
- package/src/modules/harvests.ts +43 -29
- package/src/modules/pragma.ts +23 -8
- package/src/modules/pricer-from-api.ts +156 -15
- package/src/modules/pricer-lst.ts +1 -1
- package/src/modules/pricer.ts +40 -4
- package/src/modules/pricerBase.ts +2 -1
- package/src/node/deployer.ts +36 -1
- package/src/node/pricer-redis.ts +2 -1
- package/src/strategies/base-strategy.ts +78 -10
- package/src/strategies/ekubo-cl-vault.tsx +906 -347
- package/src/strategies/factory.ts +159 -0
- package/src/strategies/index.ts +7 -1
- package/src/strategies/registry.ts +239 -0
- package/src/strategies/sensei.ts +335 -7
- package/src/strategies/svk-strategy.ts +97 -27
- package/src/strategies/types.ts +4 -0
- package/src/strategies/universal-adapters/adapter-utils.ts +2 -1
- package/src/strategies/universal-adapters/avnu-adapter.ts +180 -265
- package/src/strategies/universal-adapters/baseAdapter.ts +263 -251
- package/src/strategies/universal-adapters/common-adapter.ts +206 -203
- package/src/strategies/universal-adapters/extended-adapter.ts +490 -316
- package/src/strategies/universal-adapters/index.ts +11 -8
- package/src/strategies/universal-adapters/svk-troves-adapter.ts +364 -0
- package/src/strategies/universal-adapters/token-transfer-adapter.ts +200 -0
- package/src/strategies/universal-adapters/usdc<>usdce-adapter.ts +200 -0
- package/src/strategies/universal-adapters/vesu-adapter.ts +120 -82
- package/src/strategies/universal-adapters/vesu-modify-position-adapter.ts +476 -0
- package/src/strategies/universal-adapters/vesu-multiply-adapter.ts +1067 -704
- package/src/strategies/universal-adapters/vesu-position-common.ts +251 -0
- package/src/strategies/universal-adapters/vesu-supply-only-adapter.ts +18 -3
- package/src/strategies/universal-lst-muliplier-strategy.tsx +397 -204
- package/src/strategies/universal-strategy.tsx +1426 -1173
- package/src/strategies/vesu-extended-strategy/services/executionService.ts +2233 -0
- package/src/strategies/vesu-extended-strategy/services/extended-vesu-state-manager.ts +4087 -0
- package/src/strategies/vesu-extended-strategy/services/ltv-imbalance-rebalance-math.ts +783 -0
- package/src/strategies/vesu-extended-strategy/services/operationService.ts +38 -16
- package/src/strategies/vesu-extended-strategy/types/transaction-metadata.ts +88 -0
- package/src/strategies/vesu-extended-strategy/utils/config.runtime.ts +1 -0
- package/src/strategies/vesu-extended-strategy/utils/constants.ts +5 -6
- package/src/strategies/vesu-extended-strategy/utils/helper.ts +259 -103
- package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +688 -817
- package/src/strategies/vesu-rebalance.tsx +255 -152
- package/src/utils/cacheClass.ts +11 -2
- package/src/utils/health-factor-math.ts +4 -1
- package/src/utils/index.ts +3 -1
- package/src/utils/logger.browser.ts +22 -4
- package/src/utils/logger.node.ts +259 -24
- package/src/utils/starknet-call-parser.ts +1036 -0
- package/src/utils/strategy-utils.ts +61 -0
- package/src/strategies/universal-adapters/unused-balance-adapter.ts +0 -109
package/src/node/deployer.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { readFileSync, existsSync, writeFileSync } from 'fs'
|
|
|
4
4
|
import { IConfig } from '../interfaces';
|
|
5
5
|
import { Store, getDefaultStoreConfig } from '../utils/store';
|
|
6
6
|
import { add } from 'winston';
|
|
7
|
+
import { logger } from '@/utils';
|
|
7
8
|
|
|
8
9
|
function getContracts() {
|
|
9
10
|
const PATH = './contracts.json'
|
|
@@ -207,13 +208,47 @@ async function executeTransactions(
|
|
|
207
208
|
return tx;
|
|
208
209
|
}
|
|
209
210
|
|
|
211
|
+
async function myWaitForTransaction(
|
|
212
|
+
transaction_hash: string,
|
|
213
|
+
provider: RpcProvider,
|
|
214
|
+
retry = 0
|
|
215
|
+
) {
|
|
216
|
+
const MAX_RETRIES = 60;
|
|
217
|
+
logger.verbose(`Waiting for transaction: ${transaction_hash}, retry: ${retry}`);
|
|
218
|
+
try {
|
|
219
|
+
const status = await provider.getTransactionStatus(transaction_hash);
|
|
220
|
+
logger.verbose(`Transaction status: ${JSON.stringify(status.execution_status)}`);
|
|
221
|
+
if (status.execution_status == TransactionExecutionStatus.SUCCEEDED) {
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
if (status.execution_status == TransactionExecutionStatus.REVERTED) {
|
|
225
|
+
throw new Error(`Transaction reverted: ${transaction_hash}`);
|
|
226
|
+
}
|
|
227
|
+
if (retry > MAX_RETRIES) {
|
|
228
|
+
throw new Error(`Transaction not found: ${transaction_hash}`);
|
|
229
|
+
}
|
|
230
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
231
|
+
return myWaitForTransaction(transaction_hash, provider, retry + 1);
|
|
232
|
+
} catch (error) {
|
|
233
|
+
if (error instanceof Error && error.message.includes('Transaction reverted')) {
|
|
234
|
+
throw new Error(`Transaction reverted: ${transaction_hash}`);
|
|
235
|
+
}
|
|
236
|
+
if (retry > MAX_RETRIES) {
|
|
237
|
+
throw error;
|
|
238
|
+
}
|
|
239
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
240
|
+
return myWaitForTransaction(transaction_hash, provider, retry + 1);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
210
244
|
const Deployer = {
|
|
211
245
|
getAccount,
|
|
212
246
|
myDeclare,
|
|
213
247
|
deployContract,
|
|
214
248
|
prepareMultiDeployContracts,
|
|
215
249
|
executeDeployCalls,
|
|
216
|
-
executeTransactions
|
|
250
|
+
executeTransactions,
|
|
251
|
+
myWaitForTransaction
|
|
217
252
|
}
|
|
218
253
|
|
|
219
254
|
export default Deployer;
|
package/src/node/pricer-redis.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { PriceInfo, Pricer } from '@/modules/pricer';
|
|
|
4
4
|
import { createClient } from 'redis';
|
|
5
5
|
import type { RedisClientType } from 'redis'
|
|
6
6
|
import { logger } from "@/utils/logger";
|
|
7
|
+
import { BlockIdentifier } from "starknet";
|
|
7
8
|
|
|
8
9
|
export class PricerRedis extends Pricer {
|
|
9
10
|
private redisClient: RedisClientType | null = null;
|
|
@@ -51,7 +52,7 @@ export class PricerRedis extends Pricer {
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
/** Returns price from redis */
|
|
54
|
-
async getPrice(tokenSymbol: string) {
|
|
55
|
+
async getPrice(tokenSymbol: string, blockNumber?: BlockIdentifier) {
|
|
55
56
|
const STALE_TIME = 60000;
|
|
56
57
|
if (!this.redisClient) {
|
|
57
58
|
throw new FatalError(`Redis client not initialised`);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ContractAddr, Web3Number } from "@/dataTypes";
|
|
2
2
|
import { IConfig, TokenInfo, VaultPosition } from "@/interfaces";
|
|
3
3
|
import { CacheClass } from "@/utils/cacheClass";
|
|
4
|
-
import { Call } from "starknet";
|
|
5
4
|
import { PositionInfo } from "./universal-adapters";
|
|
5
|
+
import { Call, BlockIdentifier } from "starknet";
|
|
6
|
+
import { HarvestInfo } from "@/modules/harvests";
|
|
6
7
|
|
|
7
8
|
export interface SingleActionAmount {
|
|
8
9
|
tokenInfo: TokenInfo,
|
|
@@ -28,6 +29,16 @@ export interface DualTokenInfo {
|
|
|
28
29
|
token1: SingleTokenInfo
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
export interface NetAPYSplit {
|
|
33
|
+
apy: number;
|
|
34
|
+
id: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface NetAPYDetails {
|
|
38
|
+
net: number;
|
|
39
|
+
splits: NetAPYSplit[];
|
|
40
|
+
}
|
|
41
|
+
|
|
31
42
|
interface CacheData {
|
|
32
43
|
timestamp: number;
|
|
33
44
|
ttl: number;
|
|
@@ -42,13 +53,13 @@ export class BaseStrategy<TVLInfo, ActionInfo> extends CacheClass {
|
|
|
42
53
|
this.config = config;
|
|
43
54
|
}
|
|
44
55
|
|
|
45
|
-
async getUserTVL(user: ContractAddr): Promise<TVLInfo> {
|
|
56
|
+
async getUserTVL(user: ContractAddr, blockIdentifier?: BlockIdentifier): Promise<TVLInfo> {
|
|
46
57
|
throw new Error("Not implemented");
|
|
47
58
|
}
|
|
48
59
|
|
|
49
60
|
async getTVL(): Promise<TVLInfo> {
|
|
50
61
|
throw new Error("Not implemented");
|
|
51
|
-
}
|
|
62
|
+
}
|
|
52
63
|
|
|
53
64
|
async depositCall(amountInfo: ActionInfo, receiver: ContractAddr): Promise<Call[]> {
|
|
54
65
|
throw new Error("Not implemented");
|
|
@@ -62,19 +73,76 @@ export class BaseStrategy<TVLInfo, ActionInfo> extends CacheClass {
|
|
|
62
73
|
throw new Error("Not implemented");
|
|
63
74
|
}
|
|
64
75
|
|
|
65
|
-
async
|
|
76
|
+
async netAPY(
|
|
77
|
+
blockIdentifier?: BlockIdentifier,
|
|
78
|
+
sinceBlocks?: number,
|
|
79
|
+
timeperiod?: "24h" | "7d" | "30d" | "3m"
|
|
80
|
+
): Promise<number | NetAPYDetails> {
|
|
66
81
|
throw new Error("Not implemented");
|
|
67
82
|
}
|
|
68
83
|
|
|
69
|
-
async
|
|
70
|
-
|
|
84
|
+
async getPendingRewards(): Promise<HarvestInfo[]> {
|
|
85
|
+
return [];
|
|
71
86
|
}
|
|
72
87
|
|
|
73
|
-
async
|
|
88
|
+
async getUserRealizedAPY(
|
|
89
|
+
blockIdentifier?: BlockIdentifier,
|
|
90
|
+
sinceBlocks?: number
|
|
91
|
+
): Promise<number> {
|
|
74
92
|
throw new Error("Not implemented");
|
|
75
93
|
}
|
|
76
94
|
|
|
77
|
-
|
|
78
|
-
|
|
95
|
+
/**
|
|
96
|
+
* Calculate lifetime earnings for a user based on provided data from client
|
|
97
|
+
* Formula: lifetimeEarnings = currentValue + totalWithdrawals - totalDeposits
|
|
98
|
+
*
|
|
99
|
+
* @param userTVL - The user's current TVL (SingleTokenInfo with amount, usdValue, tokenInfo)
|
|
100
|
+
* @param investmentFlows - Array of investment flow transactions from client
|
|
101
|
+
* @returns Object containing lifetime earnings, current value, and total deposits/withdrawals
|
|
102
|
+
*/
|
|
103
|
+
getLifetimeEarnings(
|
|
104
|
+
userTVL: SingleTokenInfo,
|
|
105
|
+
investmentFlows: Array<{ amount: string; type: string; timestamp: number; tx_hash: string }>
|
|
106
|
+
): {
|
|
107
|
+
tokenInfo: SingleTokenInfo;
|
|
108
|
+
lifetimeEarnings: Web3Number;
|
|
109
|
+
currentValue: Web3Number;
|
|
110
|
+
totalDeposits: Web3Number;
|
|
111
|
+
totalWithdrawals: Web3Number;
|
|
112
|
+
} {
|
|
113
|
+
// Get token decimals from userTVL
|
|
114
|
+
const tokenDecimals = userTVL.tokenInfo.decimals;
|
|
115
|
+
|
|
116
|
+
// Initialize totals
|
|
117
|
+
let totalDeposits = Web3Number.fromWei("0", tokenDecimals);
|
|
118
|
+
let totalWithdrawals = Web3Number.fromWei("0", tokenDecimals);
|
|
119
|
+
|
|
120
|
+
// Process investment flows
|
|
121
|
+
for (const flow of investmentFlows) {
|
|
122
|
+
const amount = Web3Number.fromWei(flow.amount, tokenDecimals);
|
|
123
|
+
|
|
124
|
+
if (flow.type === 'deposit') {
|
|
125
|
+
totalDeposits = totalDeposits.plus(amount);
|
|
126
|
+
} else if (flow.type === 'withdraw' || flow.type === 'redeem') {
|
|
127
|
+
totalWithdrawals = totalWithdrawals.plus(amount);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Calculate lifetime earnings: current value + withdrawals - deposits
|
|
132
|
+
const lifetimeEarnings = userTVL.amount
|
|
133
|
+
.plus(totalWithdrawals)
|
|
134
|
+
.minus(totalDeposits);
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
tokenInfo: {
|
|
138
|
+
tokenInfo: userTVL.tokenInfo,
|
|
139
|
+
amount: lifetimeEarnings,
|
|
140
|
+
usdValue: 0, // Lifetime earnings are not converted to USD
|
|
141
|
+
},
|
|
142
|
+
lifetimeEarnings,
|
|
143
|
+
currentValue: userTVL.amount,
|
|
144
|
+
totalDeposits,
|
|
145
|
+
totalWithdrawals,
|
|
146
|
+
};
|
|
79
147
|
}
|
|
80
|
-
}
|
|
148
|
+
}
|