@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
|
@@ -1,34 +1,56 @@
|
|
|
1
1
|
import { Web3Number } from "@/dataTypes";
|
|
2
|
-
import { TokenInfo } from "@/interfaces";
|
|
3
2
|
import { ExtendedAdapter } from "@/strategies/universal-adapters/extended-adapter";
|
|
4
3
|
import { VesuMultiplyAdapter } from "../../universal-adapters/vesu-multiply-adapter";
|
|
5
|
-
import {
|
|
4
|
+
import { CycleType, TransactionResult } from "../types/transaction-metadata";
|
|
5
|
+
|
|
6
|
+
/** Planned asset routing between protocols (concrete `Operations` subclasses define shape). */
|
|
7
|
+
export interface AssetMovementPlan {}
|
|
8
|
+
|
|
6
9
|
export abstract class Operations {
|
|
10
|
+
|
|
11
|
+
abstract computeAssetMovements(
|
|
12
|
+
extendedAmount: Web3Number,
|
|
13
|
+
vesuAmount: Web3Number
|
|
14
|
+
): Promise<AssetMovementPlan | null>;
|
|
15
|
+
|
|
16
|
+
abstract executeAssetMovements(
|
|
17
|
+
plan: AssetMovementPlan
|
|
18
|
+
): Promise<TransactionResult[]>;
|
|
19
|
+
|
|
7
20
|
abstract shouldMoveAssets(
|
|
8
21
|
extendedAmount: Web3Number,
|
|
9
22
|
vesuAmount: Web3Number
|
|
10
|
-
): Promise<
|
|
23
|
+
): Promise<TransactionResult[]>;
|
|
24
|
+
|
|
25
|
+
|
|
11
26
|
abstract shouldInvest(): Promise<{
|
|
12
27
|
shouldInvest: boolean;
|
|
13
28
|
vesuAmount: Web3Number;
|
|
14
29
|
extendedAmount: Web3Number;
|
|
15
30
|
extendedLeverage: number;
|
|
16
31
|
vesuLeverage: number;
|
|
32
|
+
debtAmountToBeRepaid: Web3Number;
|
|
17
33
|
}>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Move assets between protocols.
|
|
37
|
+
* Returns transaction calls and metadata for DB tracking.
|
|
38
|
+
*/
|
|
18
39
|
abstract moveAssets(
|
|
19
|
-
params: { from: string; to: string; amount: Web3Number },
|
|
40
|
+
params: { from: string; to: string; amount: Web3Number, cycleType: CycleType },
|
|
20
41
|
extendedAdapter: ExtendedAdapter,
|
|
21
|
-
vesuAdapter: VesuMultiplyAdapter
|
|
22
|
-
): Promise<
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
42
|
+
vesuAdapter: VesuMultiplyAdapter,
|
|
43
|
+
): Promise<TransactionResult>;
|
|
44
|
+
/**
|
|
45
|
+
* Handle deposit operation.
|
|
46
|
+
* Returns transaction calls and metadata for DB tracking.
|
|
47
|
+
*/
|
|
48
|
+
abstract handleDeposit(): Promise<TransactionResult<{
|
|
27
49
|
extendedAmountInBTC: Web3Number;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
50
|
+
}>>;
|
|
51
|
+
/**
|
|
52
|
+
* Handle withdrawal operation.
|
|
53
|
+
* Returns transaction calls and metadata for DB tracking.
|
|
54
|
+
*/
|
|
55
|
+
abstract handleWithdraw(amount: Web3Number): Promise<TransactionResult[]>;
|
|
34
56
|
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Call } from "starknet";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Transaction metadata that SDK generates and risk engine stores in DB.
|
|
5
|
+
* This metadata is used to track transaction lifecycle without coupling SDK to DB.
|
|
6
|
+
*/
|
|
7
|
+
export interface TransactionMetadata {
|
|
8
|
+
protocolFrom: string;
|
|
9
|
+
protocolTo: string;
|
|
10
|
+
transactionType: 'DEPOSIT' | 'WITHDRAWAL' | 'NONE';
|
|
11
|
+
usdAmount: string;
|
|
12
|
+
status: 'COMPLETED' | 'FAILED' | 'PENDING';
|
|
13
|
+
cycleType: CycleType;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
export enum CycleType {
|
|
18
|
+
INVESTMENT = 'INVESTMENT',
|
|
19
|
+
REBALANCE_PRICE_DROP = 'REBALANCE_PRICE_DROP',
|
|
20
|
+
REBALANCE_PRICE_RISE = 'REBALANCE_PRICE_RISE',
|
|
21
|
+
WITHDRAWAL = 'WITHDRAWAL',
|
|
22
|
+
DELTA_NEUTRAL_ADJUSTMENT = 'DELTA_NEUTRAL_ADJUSTMENT',
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Enhanced return type for operations that generate transactions.
|
|
27
|
+
* Includes both the calls (for execution) and metadata (for DB storage).
|
|
28
|
+
*/
|
|
29
|
+
export interface TransactionResult<T = any> {
|
|
30
|
+
calls: Call[];
|
|
31
|
+
status: boolean;
|
|
32
|
+
transactionMetadata: TransactionMetadata;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ─── Execution Lifecycle Events ─────────────────────────────────────────────
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Key lifecycle event types emitted during execution.
|
|
39
|
+
* Used by callers (e.g. risk engine) to hook into the execution pipeline
|
|
40
|
+
* and persist state to DB, send alerts, etc.
|
|
41
|
+
*/
|
|
42
|
+
export enum ExecutionEventType {
|
|
43
|
+
/** Execution started — tx sent on-chain or order placed on exchange */
|
|
44
|
+
INITIATED = 'INITIATED',
|
|
45
|
+
/** Execution completed successfully — tx confirmed / order filled */
|
|
46
|
+
SUCCESS = 'SUCCESS',
|
|
47
|
+
/** Execution failed — tx reverted / order rejected / timeout */
|
|
48
|
+
FAILURE = 'FAILURE',
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Metadata payload accompanying each execution lifecycle event.
|
|
53
|
+
* Contains relevant identifiers, prices, and contextual information.
|
|
54
|
+
*/
|
|
55
|
+
export interface ExecutionEventMetadata {
|
|
56
|
+
/** Route type string (e.g. RouteType value) */
|
|
57
|
+
routeType?: string;
|
|
58
|
+
/** Human-readable route summary */
|
|
59
|
+
routeSummary?: string;
|
|
60
|
+
/** On-chain transaction hash (when available) */
|
|
61
|
+
txHash?: string;
|
|
62
|
+
/** Exchange order ID (for off-chain orders) */
|
|
63
|
+
orderId?: string;
|
|
64
|
+
/** Amount involved in the operation */
|
|
65
|
+
amount?: string;
|
|
66
|
+
/** Protocol name */
|
|
67
|
+
protocol?: string;
|
|
68
|
+
/** Actual execution price (for exchange orders) */
|
|
69
|
+
executionPrice?: number;
|
|
70
|
+
/** Limit price that was set */
|
|
71
|
+
limitPrice?: number;
|
|
72
|
+
/** Error message on failure */
|
|
73
|
+
error?: string;
|
|
74
|
+
/** On-chain calls that were built */
|
|
75
|
+
calls?: Call[];
|
|
76
|
+
/** Extensible: any extra metadata */
|
|
77
|
+
[key: string]: any;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Callback invoked on key execution lifecycle events.
|
|
82
|
+
* Callers can use this to save to DB, send notifications, log, etc.
|
|
83
|
+
*/
|
|
84
|
+
export type ExecutionCallback = (
|
|
85
|
+
eventType: ExecutionEventType,
|
|
86
|
+
metadata: ExecutionEventMetadata,
|
|
87
|
+
) => void | Promise<void>;
|
|
88
|
+
|
|
@@ -12,17 +12,16 @@ export const MAX_LTV_BTC_USDC = 0.8428;
|
|
|
12
12
|
export const MAX_LIQUIDATION_RATIO = 0.86;
|
|
13
13
|
export const VAULT_ID_EXTENDED= process.env.VAULT_ID_EXTENDED ?? 220774;
|
|
14
14
|
export const WALLET_ADDRESS =
|
|
15
|
-
process.env.WALLET_ADDRESS ?? "
|
|
16
|
-
export const TESTNET_WALLET_ADDRESS =
|
|
17
|
-
process.env.TESTNET_WALLET_ADDRESS ?? "0x07b84bb6E87588BdAde0bfe6173A615b3C220F9C3803456aE183C50EA1d15Ba1";
|
|
18
|
-
export const TEST_WALLET_2 =
|
|
19
|
-
process.env.TEST_WALLET_2 ?? "0x004C1bdC61DAc7947F3C93d0163d660012E2aB0521567f7155fcf502848791A7";
|
|
15
|
+
process.env.WALLET_ADDRESS ?? "0x007E24592287427aaE9d291770B17d582E8A45f3aE54228F998793Ec769B7D13";
|
|
20
16
|
export const STRK_API_TEST_RPC = process.env.STRK_API_TEST_RPC ?? "https://sepolia.starknet.a5a.ch";
|
|
21
17
|
export const STRK_API_RPC = process.env.STRK_API_RPC ?? "https://mainnet.starknet.a5a.ch";
|
|
22
18
|
export const MAX_RETRIES = Number(process.env.MAX_RETRIES ?? 3);
|
|
23
19
|
export const MAX_DELAY = Number(process.env.MAX_DELAY ?? 100);
|
|
24
20
|
export const EXTEND_MARKET_NAME = "BTC-USD";
|
|
25
|
-
|
|
21
|
+
|
|
22
|
+
// factor of balance to keep as buffer (0.05 = 5%)
|
|
23
|
+
export const LIMIT_BALANCE = Number(process.env.LIMIT_BALANCE ?? 0.05);
|
|
24
|
+
export const LIMIT_BALANCE_VALUE=20;
|
|
26
25
|
export const REBALANCER_INTERVAL = Number(process.env.REBALANCER_INTERVAL ?? 180000); //3 mins
|
|
27
26
|
export const WITHDRAWAL_INTERVAL = Number(process.env.WITHDRAWAL_INTERVAL ?? 18000000); //5 hours
|
|
28
27
|
export const INVESTING_INTERVAL = Number(process.env.INVESTING_INTERVAL ?? 180000); //3 mins
|