@megatao/sdk 1.1.0
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/.env.example +37 -0
- package/CHANGELOG.md +19 -0
- package/README.md +199 -0
- package/bin/alf +4 -0
- package/cli/README.md +198 -0
- package/cli/TEST_MANUAL.md +577 -0
- package/cli/commands/account.ts +545 -0
- package/cli/commands/funding.ts +481 -0
- package/cli/commands/liquidation.ts +523 -0
- package/cli/commands/market.ts +590 -0
- package/cli/commands/orders.ts +395 -0
- package/cli/commands/position.ts +1085 -0
- package/cli/commands/shared/positionUtils.ts +239 -0
- package/cli/commands/trading.ts +483 -0
- package/cli/commands/utils.ts +281 -0
- package/cli/commands/vault.ts +522 -0
- package/cli/index.ts +169 -0
- package/cli/interactive.ts +530 -0
- package/cli/utils/client.ts +457 -0
- package/cli/utils/config.ts +226 -0
- package/cli/utils/display.ts +258 -0
- package/cli/utils/index.ts +10 -0
- package/cli/utils/prompts.ts +364 -0
- package/config.example.json +23 -0
- package/dist/AlphaFuturesClient.d.ts +36 -0
- package/dist/AlphaFuturesClient.d.ts.map +1 -0
- package/dist/AlphaFuturesClient.js +116 -0
- package/dist/AlphaFuturesClient.js.map +1 -0
- package/dist/abi/Alpha.json +5987 -0
- package/dist/abi/abis.d.ts +319 -0
- package/dist/abi/abis.d.ts.map +1 -0
- package/dist/abi/abis.js +128 -0
- package/dist/abi/abis.js.map +1 -0
- package/dist/abi/index.d.ts +11 -0
- package/dist/abi/index.d.ts.map +1 -0
- package/dist/abi/index.js +15 -0
- package/dist/abi/index.js.map +1 -0
- package/dist/config/contracts.config.d.ts +70 -0
- package/dist/config/contracts.config.d.ts.map +1 -0
- package/dist/config/contracts.config.js +137 -0
- package/dist/config/contracts.config.js.map +1 -0
- package/dist/config/environments/alpha.config.d.ts +17 -0
- package/dist/config/environments/alpha.config.d.ts.map +1 -0
- package/dist/config/environments/alpha.config.js +140 -0
- package/dist/config/environments/alpha.config.js.map +1 -0
- package/dist/config/environments/beta.config.d.ts +16 -0
- package/dist/config/environments/beta.config.d.ts.map +1 -0
- package/dist/config/environments/beta.config.js +131 -0
- package/dist/config/environments/beta.config.js.map +1 -0
- package/dist/config/environments/dev.config.d.ts +13 -0
- package/dist/config/environments/dev.config.d.ts.map +1 -0
- package/dist/config/environments/dev.config.js +123 -0
- package/dist/config/environments/dev.config.js.map +1 -0
- package/dist/config/environments/index.d.ts +48 -0
- package/dist/config/environments/index.d.ts.map +1 -0
- package/dist/config/environments/index.js +81 -0
- package/dist/config/environments/index.js.map +1 -0
- package/dist/config/environments/localhost.config.d.ts +16 -0
- package/dist/config/environments/localhost.config.d.ts.map +1 -0
- package/dist/config/environments/localhost.config.js +152 -0
- package/dist/config/environments/localhost.config.js.map +1 -0
- package/dist/config/environments/prod.config.d.ts +20 -0
- package/dist/config/environments/prod.config.d.ts.map +1 -0
- package/dist/config/environments/prod.config.js +143 -0
- package/dist/config/environments/prod.config.js.map +1 -0
- package/dist/config/index.d.ts +7 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +41 -0
- package/dist/config/index.js.map +1 -0
- package/dist/constants/assets.d.ts +76 -0
- package/dist/constants/assets.d.ts.map +1 -0
- package/dist/constants/assets.js +277 -0
- package/dist/constants/assets.js.map +1 -0
- package/dist/constants/contracts.d.ts +41 -0
- package/dist/constants/contracts.d.ts.map +1 -0
- package/dist/constants/contracts.js +57 -0
- package/dist/constants/contracts.js.map +1 -0
- package/dist/constants/index.d.ts +36 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +75 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/constants/networks.d.ts +32 -0
- package/dist/constants/networks.d.ts.map +1 -0
- package/dist/constants/networks.js +174 -0
- package/dist/constants/networks.js.map +1 -0
- package/dist/contracts/index.d.ts +5 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +21 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/contracts/viem/AlphaViem.d.ts +518 -0
- package/dist/contracts/viem/AlphaViem.d.ts.map +1 -0
- package/dist/contracts/viem/AlphaViem.js +1287 -0
- package/dist/contracts/viem/AlphaViem.js.map +1 -0
- package/dist/contracts/viem/PriceOracleViem.d.ts +71 -0
- package/dist/contracts/viem/PriceOracleViem.d.ts.map +1 -0
- package/dist/contracts/viem/PriceOracleViem.js +212 -0
- package/dist/contracts/viem/PriceOracleViem.js.map +1 -0
- package/dist/contracts/viem/index.d.ts +9 -0
- package/dist/contracts/viem/index.d.ts.map +1 -0
- package/dist/contracts/viem/index.js +17 -0
- package/dist/contracts/viem/index.js.map +1 -0
- package/dist/errors/index.d.ts +44 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +83 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/dist/types/alpha.d.ts +299 -0
- package/dist/types/alpha.d.ts.map +1 -0
- package/dist/types/alpha.js +6 -0
- package/dist/types/alpha.js.map +1 -0
- package/dist/types/client.d.ts +24 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/client.js +13 -0
- package/dist/types/client.js.map +1 -0
- package/dist/types/contracts.d.ts +48 -0
- package/dist/types/contracts.d.ts.map +1 -0
- package/dist/types/contracts.js +6 -0
- package/dist/types/contracts.js.map +1 -0
- package/dist/types/funding.d.ts +27 -0
- package/dist/types/funding.d.ts.map +1 -0
- package/dist/types/funding.js +6 -0
- package/dist/types/funding.js.map +1 -0
- package/dist/types/index.d.ts +92 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +47 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/liquidation.d.ts +20 -0
- package/dist/types/liquidation.d.ts.map +1 -0
- package/dist/types/liquidation.js +6 -0
- package/dist/types/liquidation.js.map +1 -0
- package/dist/types/margin.d.ts +29 -0
- package/dist/types/margin.d.ts.map +1 -0
- package/dist/types/margin.js +6 -0
- package/dist/types/margin.js.map +1 -0
- package/dist/types/oracle.d.ts +21 -0
- package/dist/types/oracle.d.ts.map +1 -0
- package/dist/types/oracle.js +6 -0
- package/dist/types/oracle.js.map +1 -0
- package/dist/types/positions.d.ts +43 -0
- package/dist/types/positions.d.ts.map +1 -0
- package/dist/types/positions.js +13 -0
- package/dist/types/positions.js.map +1 -0
- package/dist/utils/calculations.d.ts +84 -0
- package/dist/utils/calculations.d.ts.map +1 -0
- package/dist/utils/calculations.js +155 -0
- package/dist/utils/calculations.js.map +1 -0
- package/dist/utils/errors.d.ts +24 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +129 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/events.d.ts +40 -0
- package/dist/utils/events.d.ts.map +1 -0
- package/dist/utils/events.js +73 -0
- package/dist/utils/events.js.map +1 -0
- package/dist/utils/format.d.ts +40 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +86 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/index.d.ts +10 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +26 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/network.d.ts +52 -0
- package/dist/utils/network.d.ts.map +1 -0
- package/dist/utils/network.js +192 -0
- package/dist/utils/network.js.map +1 -0
- package/dist/utils/positionCalculations.d.ts +145 -0
- package/dist/utils/positionCalculations.d.ts.map +1 -0
- package/dist/utils/positionCalculations.js +278 -0
- package/dist/utils/positionCalculations.js.map +1 -0
- package/dist/utils/validation.d.ts +28 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +68 -0
- package/dist/utils/validation.js.map +1 -0
- package/docs/README.md +40 -0
- package/docs/api/API.md +831 -0
- package/docs/guides/GETTING_STARTED.md +316 -0
- package/docs/guides/TRADING_GUIDE.md +677 -0
- package/docs/integration/INTEGRATION_GUIDE.md +1679 -0
- package/docs/integration/VIEM_INTEGRATION.md +294 -0
- package/docs/reference/CLI_QUICK_REFERENCE.md +197 -0
- package/docs/reference/TROUBLESHOOTING.md +922 -0
- package/package.json +113 -0
- package/src/AlphaFuturesClient.ts +158 -0
- package/src/abi/.gitkeep +1 -0
- package/src/abi/Alpha.json +5987 -0
- package/src/abi/README.md +99 -0
- package/src/abi/abis.ts +131 -0
- package/src/abi/index.ts +13 -0
- package/src/config/contracts.config.ts +186 -0
- package/src/config/environments/alpha.config.ts +139 -0
- package/src/config/environments/beta.config.ts +130 -0
- package/src/config/environments/dev.config.ts +122 -0
- package/src/config/environments/index.ts +87 -0
- package/src/config/environments/localhost.config.ts +153 -0
- package/src/config/environments/prod.config.ts +142 -0
- package/src/config/index.ts +29 -0
- package/src/constants/assets.ts +299 -0
- package/src/constants/contracts.ts +64 -0
- package/src/constants/index.ts +69 -0
- package/src/constants/networks.ts +182 -0
- package/src/contracts/index.ts +5 -0
- package/src/contracts/viem/AlphaViem.ts +1615 -0
- package/src/contracts/viem/PriceOracleViem.ts +272 -0
- package/src/contracts/viem/index.ts +11 -0
- package/src/errors/index.ts +87 -0
- package/src/index.ts +59 -0
- package/src/types/VIEM_TYPES_README.md +70 -0
- package/src/types/alpha.ts +358 -0
- package/src/types/client.ts +27 -0
- package/src/types/contracts.ts +74 -0
- package/src/types/funding.ts +31 -0
- package/src/types/index.ts +108 -0
- package/src/types/liquidation.ts +23 -0
- package/src/types/margin.ts +34 -0
- package/src/types/oracle.ts +24 -0
- package/src/types/positions.ts +48 -0
- package/src/utils/calculations.ts +175 -0
- package/src/utils/errors.ts +147 -0
- package/src/utils/events.ts +98 -0
- package/src/utils/format.ts +84 -0
- package/src/utils/index.ts +10 -0
- package/src/utils/network.ts +212 -0
- package/src/utils/positionCalculations.ts +317 -0
- package/src/utils/validation.ts +76 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for AlphaFuturesMonolith contract
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Address } from 'viem';
|
|
6
|
+
|
|
7
|
+
// ============ Position and Order Types ============
|
|
8
|
+
|
|
9
|
+
export interface MonolithPosition {
|
|
10
|
+
notionalValue: bigint; // Position value in collateral terms
|
|
11
|
+
margin: bigint;
|
|
12
|
+
entryPrice: bigint;
|
|
13
|
+
isLong: boolean;
|
|
14
|
+
lastUpdated: bigint;
|
|
15
|
+
fundingIndex: bigint;
|
|
16
|
+
leverage: bigint;
|
|
17
|
+
liquidationPrice: bigint;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface MonolithOrder {
|
|
21
|
+
trader: Address;
|
|
22
|
+
notionalValue: bigint; // Order notional value in collateral terms
|
|
23
|
+
price: bigint;
|
|
24
|
+
isBuy: boolean;
|
|
25
|
+
margin: bigint;
|
|
26
|
+
timestamp: bigint;
|
|
27
|
+
leverage: bigint;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface MonolithMarket {
|
|
31
|
+
isActive: boolean;
|
|
32
|
+
maxLeverage: bigint;
|
|
33
|
+
maintenanceMargin: bigint;
|
|
34
|
+
liquidationFee: bigint;
|
|
35
|
+
lastFundingUpdate: bigint;
|
|
36
|
+
fundingIndex: bigint;
|
|
37
|
+
fundingRate: bigint;
|
|
38
|
+
longOpenInterest: bigint;
|
|
39
|
+
shortOpenInterest: bigint;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface OrderBook {
|
|
43
|
+
bestBid: `0x${string}`; // bytes16
|
|
44
|
+
bestAsk: `0x${string}`; // bytes16
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface DepthLevel {
|
|
48
|
+
price: bigint;
|
|
49
|
+
notionalValue: bigint; // Liquidity notional value at this price level
|
|
50
|
+
orderCount: bigint;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface VWAPResult {
|
|
54
|
+
vwap: bigint;
|
|
55
|
+
slippage: bigint;
|
|
56
|
+
totalNotional: bigint; // Changed from totalSize to match Solidity struct (IAlphaStorage.sol:222)
|
|
57
|
+
priceImpact: bigint;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface SpreadInfo {
|
|
61
|
+
bidPrice: bigint;
|
|
62
|
+
askPrice: bigint;
|
|
63
|
+
spread: bigint;
|
|
64
|
+
spreadPercent: bigint;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface OrderDetails {
|
|
68
|
+
trader: Address;
|
|
69
|
+
isLong: boolean;
|
|
70
|
+
notionalValue: bigint;
|
|
71
|
+
price: bigint;
|
|
72
|
+
reduceOnly: boolean;
|
|
73
|
+
next: Bytes16;
|
|
74
|
+
prev: Bytes16;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Position details returned by getPositionDetails
|
|
79
|
+
* Matches contract struct IAlphaStorage.PositionDetails
|
|
80
|
+
*/
|
|
81
|
+
export interface PositionDetails {
|
|
82
|
+
owner: Address;
|
|
83
|
+
market: Address;
|
|
84
|
+
isLong: boolean;
|
|
85
|
+
notionalValue: bigint;
|
|
86
|
+
margin: bigint;
|
|
87
|
+
entryPrice: bigint;
|
|
88
|
+
markPrice: bigint;
|
|
89
|
+
pricePnl: bigint; // Price movement P&L only (entry vs mark price)
|
|
90
|
+
fundingPayment: bigint;
|
|
91
|
+
interestPayment: bigint; // Interest fee owed (always negative)
|
|
92
|
+
marginRatio: bigint;
|
|
93
|
+
liquidationPrice: bigint;
|
|
94
|
+
liquidatable: boolean;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ============ Parameter Types ============
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Parameters for opening a market position
|
|
101
|
+
* UPDATED: Changed from asset-quantity model to collateral-based model
|
|
102
|
+
* - Previously: Specified token quantity (size) to trade
|
|
103
|
+
* - Now: Specify collateral amount (margin) to risk with leverage
|
|
104
|
+
*/
|
|
105
|
+
export interface MarketPositionParams {
|
|
106
|
+
market: Address;
|
|
107
|
+
isLong: boolean;
|
|
108
|
+
margin: bigint; // Collateral amount to risk
|
|
109
|
+
leverage: bigint; // 1e18 format (e.g., 3e18 for 3x)
|
|
110
|
+
maxSlippage: bigint;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface LimitOrderParams {
|
|
114
|
+
market: Address;
|
|
115
|
+
isBuy: boolean;
|
|
116
|
+
margin: bigint; // Collateral amount to risk
|
|
117
|
+
leverage: bigint; // 1e18 format (e.g., 3e18 for 3x)
|
|
118
|
+
price: bigint;
|
|
119
|
+
// reduceOnlyType: Uses OrderType enum values
|
|
120
|
+
// 0 = Normal: Regular limit order, placed on natural side (BUY→BID, SELL→ASK)
|
|
121
|
+
// 1 = TakeProfit: Reduce-only, natural side, triggers on favorable price
|
|
122
|
+
// 2 = StopLoss: Reduce-only, OPPOSITE side, triggers on adverse price (dual-trigger)
|
|
123
|
+
reduceOnlyType: number;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// ============ State Types ============
|
|
127
|
+
|
|
128
|
+
export interface VaultState {
|
|
129
|
+
totalReserves: bigint;
|
|
130
|
+
availableReserves: bigint;
|
|
131
|
+
totalExposure: bigint;
|
|
132
|
+
unrealizedPnl: bigint;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface FundingState {
|
|
136
|
+
fundingRate: bigint;
|
|
137
|
+
fundingIndex: bigint;
|
|
138
|
+
lastUpdateTime: bigint;
|
|
139
|
+
nextFundingTime: bigint;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// ============ Execution Types ============
|
|
143
|
+
|
|
144
|
+
export interface ExecutionPlan {
|
|
145
|
+
orderbookSize: bigint;
|
|
146
|
+
vaultSize: bigint;
|
|
147
|
+
totalSize: bigint;
|
|
148
|
+
expectedSlippage: bigint;
|
|
149
|
+
effectivePrice: bigint;
|
|
150
|
+
feasible: boolean;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface ExecutionStrategyAnalysis {
|
|
154
|
+
orderbookLiquidity: bigint;
|
|
155
|
+
vaultCapacity: bigint;
|
|
156
|
+
orderbookSlippage: bigint;
|
|
157
|
+
vaultSlippage: bigint;
|
|
158
|
+
hybridSlippage: bigint;
|
|
159
|
+
recommendedSplit: bigint;
|
|
160
|
+
recommendedStrategy: number;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export interface MarketLiquidityAnalysis {
|
|
164
|
+
totalBidLiquidity: bigint;
|
|
165
|
+
totalAskLiquidity: bigint;
|
|
166
|
+
bidDepth: bigint;
|
|
167
|
+
askDepth: bigint;
|
|
168
|
+
spreadPercent: bigint;
|
|
169
|
+
marketScore: bigint;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface SlippageBreakdown {
|
|
173
|
+
baseSlippage: bigint;
|
|
174
|
+
sizeImpact: bigint;
|
|
175
|
+
marketDepthFactor: bigint;
|
|
176
|
+
exposureEffect: bigint;
|
|
177
|
+
volatilityAdjustment: bigint;
|
|
178
|
+
totalSlippage: bigint;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ============ Event Types ============
|
|
182
|
+
|
|
183
|
+
export interface MarginDepositedEvent {
|
|
184
|
+
trader: Address;
|
|
185
|
+
amount: bigint;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export interface PositionOpenedEvent {
|
|
189
|
+
positionId: `0x${string}`; // bytes16
|
|
190
|
+
trader: Address;
|
|
191
|
+
market: Address;
|
|
192
|
+
isLong: boolean;
|
|
193
|
+
notionalValue: bigint;
|
|
194
|
+
margin: bigint;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export interface PositionClosedEvent {
|
|
198
|
+
positionId: `0x${string}`; // bytes16
|
|
199
|
+
trader: Address;
|
|
200
|
+
pnl: bigint;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export interface OrderPlacedEvent {
|
|
204
|
+
orderId: `0x${string}`; // bytes16
|
|
205
|
+
trader: Address;
|
|
206
|
+
market: Address;
|
|
207
|
+
isBuy: boolean;
|
|
208
|
+
notionalValue: bigint;
|
|
209
|
+
price: bigint;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export interface HybridOrderExecutedEvent {
|
|
213
|
+
trader: Address;
|
|
214
|
+
market: Address;
|
|
215
|
+
orderbookFilled: bigint;
|
|
216
|
+
vaultFilled: bigint;
|
|
217
|
+
avgPrice: bigint;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// ============ Helper Types ============
|
|
221
|
+
|
|
222
|
+
export type Bytes16 = `0x${string}`;
|
|
223
|
+
export type Bytes32 = `0x${string}`;
|
|
224
|
+
|
|
225
|
+
export interface MonolithConfig {
|
|
226
|
+
precision: bigint;
|
|
227
|
+
basisPoints: bigint;
|
|
228
|
+
maxLeverage: bigint;
|
|
229
|
+
defaultLeverage: bigint;
|
|
230
|
+
minPositionSize: bigint;
|
|
231
|
+
liquidationThreshold: bigint;
|
|
232
|
+
partialLiquidationThreshold: bigint;
|
|
233
|
+
liquidationFee: bigint;
|
|
234
|
+
fundingInterval: bigint;
|
|
235
|
+
maxFundingRate: bigint;
|
|
236
|
+
maxExposurePerAsset: bigint;
|
|
237
|
+
maxTotalUtilization: bigint;
|
|
238
|
+
criticalUtilizationBps: bigint;
|
|
239
|
+
maxLossRateBps: bigint;
|
|
240
|
+
maxLiquidationsPerBlock: bigint;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// ============ View Function Response Types ============
|
|
244
|
+
|
|
245
|
+
export interface MarketInfo {
|
|
246
|
+
isActive: boolean;
|
|
247
|
+
maxLeverage: bigint;
|
|
248
|
+
maintenanceMargin: bigint;
|
|
249
|
+
liquidationFee: bigint;
|
|
250
|
+
longOpenInterest: bigint;
|
|
251
|
+
shortOpenInterest: bigint;
|
|
252
|
+
fundingRate: bigint;
|
|
253
|
+
lastFundingUpdate: bigint;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export interface MarginInfo {
|
|
257
|
+
balance: bigint;
|
|
258
|
+
locked: bigint;
|
|
259
|
+
available: bigint;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export interface AccountSummary {
|
|
263
|
+
depositedBalance: bigint;
|
|
264
|
+
accountEquity: bigint;
|
|
265
|
+
unrealizedPnl: bigint;
|
|
266
|
+
lockedMargin: bigint;
|
|
267
|
+
availableMargin: bigint;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export interface PositionSummary {
|
|
271
|
+
totalPositions: bigint;
|
|
272
|
+
totalMargin: bigint;
|
|
273
|
+
totalUnrealizedPnl: bigint;
|
|
274
|
+
totalSize: bigint;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export interface VaultStats {
|
|
278
|
+
totalReserves: bigint;
|
|
279
|
+
availableReserves: bigint;
|
|
280
|
+
totalExposure: bigint;
|
|
281
|
+
unrealizedPnl: bigint;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export interface VaultExposure {
|
|
285
|
+
longExposure: bigint;
|
|
286
|
+
shortExposure: bigint;
|
|
287
|
+
netExposure: bigint;
|
|
288
|
+
utilizationRate: bigint;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export interface LiquidationStatus {
|
|
292
|
+
isLiquidatable: boolean;
|
|
293
|
+
marginRatio: bigint;
|
|
294
|
+
requiredMargin: bigint;
|
|
295
|
+
liquidationPrice: bigint;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export interface MarketStatistics {
|
|
299
|
+
totalOrders: bigint;
|
|
300
|
+
bidOrders: bigint;
|
|
301
|
+
askOrders: bigint;
|
|
302
|
+
averageOrderSize: bigint;
|
|
303
|
+
medianBidPrice: bigint;
|
|
304
|
+
medianAskPrice: bigint;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export interface ExecutionMetrics {
|
|
308
|
+
orderbookFilled: bigint;
|
|
309
|
+
vaultFilled: bigint;
|
|
310
|
+
avgPrice: bigint;
|
|
311
|
+
slippage: bigint;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export interface MarketLiquidationStats {
|
|
315
|
+
totalLiquidations: bigint;
|
|
316
|
+
totalLiquidationValue: bigint;
|
|
317
|
+
liquidationsLast24h: bigint;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export interface BadDebtInfo {
|
|
321
|
+
totalCovered: bigint;
|
|
322
|
+
eventCount: bigint;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export interface VaultFundingStats {
|
|
326
|
+
collected: bigint;
|
|
327
|
+
paid: bigint;
|
|
328
|
+
net: bigint;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export interface VaultFundingInfo {
|
|
332
|
+
fundingBalance: bigint;
|
|
333
|
+
vaultIndex: bigint;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export interface LiquidationCascadeRisk {
|
|
337
|
+
shouldTrigger: boolean;
|
|
338
|
+
severity: number;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export interface TopKeeperInfo {
|
|
342
|
+
keepers: Address[];
|
|
343
|
+
liquidationCounts: bigint[];
|
|
344
|
+
rewards: bigint[];
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export interface CumulativeDepthResult {
|
|
348
|
+
prices: bigint[];
|
|
349
|
+
cumulativeSizes: bigint[];
|
|
350
|
+
totalDepth: bigint;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export interface MarketImpactEstimate {
|
|
354
|
+
averagePrice: bigint;
|
|
355
|
+
worstPrice: bigint;
|
|
356
|
+
priceImpact: bigint;
|
|
357
|
+
filledFromOrderbook: bigint;
|
|
358
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-related type definitions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { PublicClient, WalletClient, Chain } from 'viem';
|
|
6
|
+
|
|
7
|
+
export interface AlphaFuturesConfig {
|
|
8
|
+
publicClient?: PublicClient;
|
|
9
|
+
walletClient?: WalletClient;
|
|
10
|
+
rpcUrl?: string;
|
|
11
|
+
privateKey?: string;
|
|
12
|
+
network?: 'mainnet' | 'testnet' | 'localhost';
|
|
13
|
+
customContracts?: ContractAddresses;
|
|
14
|
+
chain?: Chain;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ContractAddresses {
|
|
18
|
+
alpha: string;
|
|
19
|
+
priceOracle: string;
|
|
20
|
+
collateralToken: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export enum Network {
|
|
24
|
+
MAINNET = 'mainnet',
|
|
25
|
+
TESTNET = 'testnet',
|
|
26
|
+
LOCALHOST = 'localhost',
|
|
27
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract interface type definitions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Hash, Address } from 'viem';
|
|
6
|
+
import { TransactionOptions } from './index';
|
|
7
|
+
|
|
8
|
+
// Base contract interface
|
|
9
|
+
export interface BaseContract {
|
|
10
|
+
address: Address;
|
|
11
|
+
// Viem uses different connection patterns, removing connect method
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// MarginAccount contract interface
|
|
15
|
+
export interface IMarginAccount extends BaseContract {
|
|
16
|
+
deposit(amount: bigint, options?: TransactionOptions): Promise<Hash>;
|
|
17
|
+
withdraw(amount: bigint, options?: TransactionOptions): Promise<Hash>;
|
|
18
|
+
getBalance(user: Address): Promise<bigint>;
|
|
19
|
+
getAvailableBalance(user: Address): Promise<bigint>;
|
|
20
|
+
getLockedMargin(user: Address): Promise<bigint>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// PositionManager contract interface
|
|
24
|
+
export interface IPositionManager extends BaseContract {
|
|
25
|
+
openMarketPosition(
|
|
26
|
+
asset: Address,
|
|
27
|
+
isLong: boolean,
|
|
28
|
+
margin: bigint, // Collateral to risk, not asset size
|
|
29
|
+
leverage: bigint, // 1e18 format (e.g., 3e18 for 3x)
|
|
30
|
+
maxSlippage: bigint, // Max slippage in basis points (e.g., 100 = 1%)
|
|
31
|
+
options?: TransactionOptions,
|
|
32
|
+
): Promise<Hash>;
|
|
33
|
+
|
|
34
|
+
closePosition(
|
|
35
|
+
positionId: bigint,
|
|
36
|
+
notionalValue: bigint,
|
|
37
|
+
options?: TransactionOptions,
|
|
38
|
+
): Promise<Hash>; // Notional value to close
|
|
39
|
+
|
|
40
|
+
getPosition(positionId: bigint): Promise<any>;
|
|
41
|
+
getUserPositions(user: Address): Promise<bigint[]>;
|
|
42
|
+
getActivePositions(asset: Address): Promise<bigint[]>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// FundingRate contract interface
|
|
46
|
+
export interface IFundingRate extends BaseContract {
|
|
47
|
+
updateFundingRate(asset: Address, options?: TransactionOptions): Promise<Hash>;
|
|
48
|
+
getCurrentFundingRate(asset: Address): Promise<bigint>;
|
|
49
|
+
getFundingIndex(asset: Address): Promise<bigint>;
|
|
50
|
+
getNextFundingTime(asset: Address): Promise<bigint>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// LiquidationEngine contract interface
|
|
54
|
+
export interface ILiquidationEngine extends BaseContract {
|
|
55
|
+
liquidatePosition(positionId: bigint, options?: TransactionOptions): Promise<Hash>;
|
|
56
|
+
|
|
57
|
+
isLiquidatable(positionId: bigint): Promise<boolean>;
|
|
58
|
+
getLiquidationPrice(positionId: bigint): Promise<bigint>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ProtocolVault contract interface
|
|
62
|
+
export interface IProtocolVault extends BaseContract {
|
|
63
|
+
getTotalReserves(): Promise<bigint>;
|
|
64
|
+
getInsuranceFund(): Promise<bigint>;
|
|
65
|
+
getUnmatchedLongs(asset: Address): Promise<bigint>;
|
|
66
|
+
getUnmatchedShorts(asset: Address): Promise<bigint>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// PriceOracle contract interface
|
|
70
|
+
export interface IPriceOracle extends BaseContract {
|
|
71
|
+
getPrice(asset: Address): Promise<bigint>;
|
|
72
|
+
updatePrice(asset: Address, price: bigint, options?: TransactionOptions): Promise<Hash>;
|
|
73
|
+
getLatestPriceData(asset: Address): Promise<[bigint, bigint]>; // [price, timestamp]
|
|
74
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Funding rate related type definitions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Address } from 'viem';
|
|
6
|
+
|
|
7
|
+
export interface FundingRate {
|
|
8
|
+
rate: bigint;
|
|
9
|
+
timestamp: bigint;
|
|
10
|
+
longOpenInterest: bigint;
|
|
11
|
+
shortOpenInterest: bigint;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface FundingPayment {
|
|
15
|
+
positionId: bigint;
|
|
16
|
+
payment: bigint;
|
|
17
|
+
timestamp: bigint;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface FundingRateConfig {
|
|
21
|
+
baseRate: bigint;
|
|
22
|
+
maxRate: bigint;
|
|
23
|
+
fundingInterval: bigint;
|
|
24
|
+
skewScale: bigint;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface FundingIndex {
|
|
28
|
+
asset: Address;
|
|
29
|
+
index: bigint;
|
|
30
|
+
timestamp: bigint;
|
|
31
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for Alpha Futures SDK
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Address } from 'viem';
|
|
6
|
+
|
|
7
|
+
// Re-export all types
|
|
8
|
+
export * from './client';
|
|
9
|
+
export * from './contracts';
|
|
10
|
+
export * from './positions';
|
|
11
|
+
export * from './margin';
|
|
12
|
+
export * from './funding';
|
|
13
|
+
export * from './liquidation';
|
|
14
|
+
export * from './oracle';
|
|
15
|
+
|
|
16
|
+
// Common types used across the SDK
|
|
17
|
+
export interface TransactionOptions {
|
|
18
|
+
gas?: bigint;
|
|
19
|
+
gasPrice?: bigint;
|
|
20
|
+
maxFeePerGas?: bigint;
|
|
21
|
+
maxPriorityFeePerGas?: bigint;
|
|
22
|
+
nonce?: number;
|
|
23
|
+
value?: bigint;
|
|
24
|
+
waitForConfirmation?: boolean; // Custom SDK option, not passed to viem
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface CallOptions {
|
|
28
|
+
blockTag?: 'latest' | 'earliest' | 'pending' | 'safe' | 'finalized';
|
|
29
|
+
blockNumber?: bigint;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface EventFilter {
|
|
33
|
+
fromBlock?: bigint | 'latest' | 'earliest' | 'pending';
|
|
34
|
+
toBlock?: bigint | 'latest' | 'earliest' | 'pending';
|
|
35
|
+
address?: Address | Address[];
|
|
36
|
+
topics?: string[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Subnet market configuration for Alpha Futures protocol
|
|
41
|
+
*/
|
|
42
|
+
export interface SubnetMarket {
|
|
43
|
+
/** Subnet ID on the Bittensor network */
|
|
44
|
+
id: number;
|
|
45
|
+
/** Human-readable name of the subnet */
|
|
46
|
+
name: string;
|
|
47
|
+
/** Market contract address for this subnet */
|
|
48
|
+
marketAddress: `0x${string}`;
|
|
49
|
+
/** Whether oracle pricing is available */
|
|
50
|
+
hasOraclePrice: boolean;
|
|
51
|
+
/** Symbol used for trading */
|
|
52
|
+
symbol: string;
|
|
53
|
+
/** Full name for display */
|
|
54
|
+
displayName: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface NetworkConfig {
|
|
58
|
+
chainId: number;
|
|
59
|
+
name: string;
|
|
60
|
+
rpcUrl?: string;
|
|
61
|
+
contracts: {
|
|
62
|
+
alpha: Address;
|
|
63
|
+
priceOracle: Address;
|
|
64
|
+
collateralToken: Address;
|
|
65
|
+
};
|
|
66
|
+
markets?: SubnetMarket[];
|
|
67
|
+
collateralTokenInfo?: {
|
|
68
|
+
symbol: string;
|
|
69
|
+
decimals: number;
|
|
70
|
+
name: string;
|
|
71
|
+
};
|
|
72
|
+
blockExplorer?: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface ClientConfig {
|
|
76
|
+
rpcUrl?: string;
|
|
77
|
+
privateKey?: string;
|
|
78
|
+
network?: string;
|
|
79
|
+
networkConfig?: NetworkConfig;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Subnet market constants for trading (replaces legacy Alpha Token constants)
|
|
83
|
+
export const SubnetMarkets = {
|
|
84
|
+
BITMIND: '0x0000000000000000000000000000000000000022' as Address,
|
|
85
|
+
CHUTES: '0x0000000000000000000000000000000000000040' as Address,
|
|
86
|
+
AFFINE: '0x0000000000000000000000000000000000000078' as Address,
|
|
87
|
+
RIDGES: '0x0000000000000000000000000000000000000003E' as Address,
|
|
88
|
+
} as const;
|
|
89
|
+
|
|
90
|
+
// Legacy Alpha Token constants for backward compatibility
|
|
91
|
+
export const AlphaToken = {
|
|
92
|
+
ALPHA_BTC: '0x0000000000000000000000000000000000000001' as Address,
|
|
93
|
+
ALPHA_ETH: '0x0000000000000000000000000000000000000003' as Address,
|
|
94
|
+
ALPHA_SOL: '0x0000000000000000000000000000000000000004' as Address,
|
|
95
|
+
// New subnet markets
|
|
96
|
+
BITMIND: SubnetMarkets.BITMIND,
|
|
97
|
+
CHUTES: SubnetMarkets.CHUTES,
|
|
98
|
+
AFFINE: SubnetMarkets.AFFINE,
|
|
99
|
+
RIDGES: SubnetMarkets.RIDGES,
|
|
100
|
+
} as const;
|
|
101
|
+
|
|
102
|
+
// Additional type for backward compatibility
|
|
103
|
+
export interface AlphaTokenInfo {
|
|
104
|
+
symbol: string;
|
|
105
|
+
address: Address;
|
|
106
|
+
decimals: number;
|
|
107
|
+
name: string;
|
|
108
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Liquidation-related type definitions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Address } from 'viem';
|
|
6
|
+
|
|
7
|
+
export interface LiquidationParams {
|
|
8
|
+
positionId: bigint;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface LiquidationResult {
|
|
12
|
+
positionId: bigint;
|
|
13
|
+
liquidator: Address;
|
|
14
|
+
remainingMargin: bigint;
|
|
15
|
+
liquidationBonus: bigint;
|
|
16
|
+
timestamp: bigint;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface LiquidationConfig {
|
|
20
|
+
maintenanceMarginRatio: bigint;
|
|
21
|
+
liquidationBonus: bigint;
|
|
22
|
+
insuranceFundRatio: bigint;
|
|
23
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Margin-related type definitions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Address } from 'viem';
|
|
6
|
+
|
|
7
|
+
export interface MarginAccount {
|
|
8
|
+
balance: bigint;
|
|
9
|
+
lockedMargin: bigint;
|
|
10
|
+
availableBalance: bigint;
|
|
11
|
+
totalPositions: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface MarginRequirement {
|
|
15
|
+
initialMargin: bigint;
|
|
16
|
+
maintenanceMargin: bigint;
|
|
17
|
+
currentMargin: bigint;
|
|
18
|
+
marginRatio: bigint;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface DepositParams {
|
|
22
|
+
amount: bigint;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface WithdrawParams {
|
|
26
|
+
amount: bigint;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface MarginUpdateEvent {
|
|
30
|
+
user: Address;
|
|
31
|
+
amount: bigint;
|
|
32
|
+
isDeposit: boolean;
|
|
33
|
+
timestamp: bigint;
|
|
34
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Oracle-related type definitions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Address } from 'viem';
|
|
6
|
+
|
|
7
|
+
export interface PriceData {
|
|
8
|
+
asset: Address;
|
|
9
|
+
price: bigint;
|
|
10
|
+
timestamp: bigint;
|
|
11
|
+
confidence?: bigint;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface OracleConfig {
|
|
15
|
+
heartbeat: bigint;
|
|
16
|
+
deviation: bigint;
|
|
17
|
+
decimals: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface PriceFeed {
|
|
21
|
+
asset: Address;
|
|
22
|
+
oracle: Address;
|
|
23
|
+
isActive: boolean;
|
|
24
|
+
}
|