@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,278 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculatePositionSizeFromCollateral = calculatePositionSizeFromCollateral;
|
|
4
|
+
exports.calculatePositionValue = calculatePositionValue;
|
|
5
|
+
exports.calculateCollateralFromSize = calculateCollateralFromSize;
|
|
6
|
+
exports.calculateLeverageFromSizeAndCollateral = calculateLeverageFromSizeAndCollateral;
|
|
7
|
+
exports.usdToTokens = usdToTokens;
|
|
8
|
+
exports.tokensToUSD = tokensToUSD;
|
|
9
|
+
exports.leverageToWei = leverageToWei;
|
|
10
|
+
exports.leverageFromWei = leverageFromWei;
|
|
11
|
+
exports.calculatePnLPercent = calculatePnLPercent;
|
|
12
|
+
exports.calculatePnLAmount = calculatePnLAmount;
|
|
13
|
+
exports.calculateLiquidationPriceFromLeverage = calculateLiquidationPriceFromLeverage;
|
|
14
|
+
exports.calculateRequiredMargin = calculateRequiredMargin;
|
|
15
|
+
exports.calculateMaxPositionSize = calculateMaxPositionSize;
|
|
16
|
+
const viem_1 = require("viem");
|
|
17
|
+
/**
|
|
18
|
+
* Position calculation utilities for Alpha Futures protocol
|
|
19
|
+
* Supports both collateral-first and size-first paradigms
|
|
20
|
+
* All calculations use 18 decimal precision (wei format in contracts)
|
|
21
|
+
*/
|
|
22
|
+
// ============================================================================
|
|
23
|
+
// COLLATERAL-FIRST PARADIGM (NEW - Primary UX)
|
|
24
|
+
// ============================================================================
|
|
25
|
+
/**
|
|
26
|
+
* Calculate position size in tokens from collateral and leverage
|
|
27
|
+
* @param collateralUSD - Collateral amount in USD (as number, e.g., 100 for $100)
|
|
28
|
+
* @param leverage - Leverage multiplier (as number, e.g., 3.5 for 3.5x)
|
|
29
|
+
* @param tokenPriceUSD - Token price in USD (as number, e.g., 0.019)
|
|
30
|
+
* @returns Position size as bigint in wei (18 decimals)
|
|
31
|
+
* @example
|
|
32
|
+
* // $100 collateral, 3.5x leverage, $0.019 token price
|
|
33
|
+
* // = (100 * 3.5) / 0.019 = 18,421 tokens
|
|
34
|
+
* calculatePositionSizeFromCollateral(100, 3.5, 0.019)
|
|
35
|
+
* // Returns: 18421052631578947368421n (18421.05... * 1e18)
|
|
36
|
+
*/
|
|
37
|
+
function calculatePositionSizeFromCollateral(collateralUSD, leverage, tokenPriceUSD) {
|
|
38
|
+
if (tokenPriceUSD <= 0) {
|
|
39
|
+
throw new Error('Token price must be greater than 0');
|
|
40
|
+
}
|
|
41
|
+
if (leverage <= 0) {
|
|
42
|
+
throw new Error('Leverage must be greater than 0');
|
|
43
|
+
}
|
|
44
|
+
if (collateralUSD < 0) {
|
|
45
|
+
throw new Error('Collateral must be non-negative');
|
|
46
|
+
}
|
|
47
|
+
const positionSizeInTokens = (collateralUSD * leverage) / tokenPriceUSD;
|
|
48
|
+
return (0, viem_1.parseEther)(positionSizeInTokens.toString());
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Calculate position value in USD from collateral and leverage
|
|
52
|
+
* @param collateralUSD - Collateral amount in USD
|
|
53
|
+
* @param leverage - Leverage multiplier
|
|
54
|
+
* @returns Position value in USD
|
|
55
|
+
* @example
|
|
56
|
+
* // $100 collateral, 3.5x leverage
|
|
57
|
+
* calculatePositionValue(100, 3.5) // Returns: 350
|
|
58
|
+
*/
|
|
59
|
+
function calculatePositionValue(collateralUSD, leverage) {
|
|
60
|
+
if (leverage <= 0) {
|
|
61
|
+
throw new Error('Leverage must be greater than 0');
|
|
62
|
+
}
|
|
63
|
+
if (collateralUSD < 0) {
|
|
64
|
+
throw new Error('Collateral must be non-negative');
|
|
65
|
+
}
|
|
66
|
+
return collateralUSD * leverage;
|
|
67
|
+
}
|
|
68
|
+
// ============================================================================
|
|
69
|
+
// SIZE-FIRST PARADIGM (OLD - Backward Compatibility)
|
|
70
|
+
// ============================================================================
|
|
71
|
+
/**
|
|
72
|
+
* Calculate required collateral from position size and leverage
|
|
73
|
+
* @param positionSizeUSD - Position size in USD
|
|
74
|
+
* @param leverage - Leverage multiplier
|
|
75
|
+
* @returns Required collateral in USD
|
|
76
|
+
* @example
|
|
77
|
+
* // $30 position size, 3x leverage
|
|
78
|
+
* // = 30 / 3 = $10 collateral required
|
|
79
|
+
* calculateCollateralFromSize(30, 3) // Returns: 10
|
|
80
|
+
*/
|
|
81
|
+
function calculateCollateralFromSize(positionSizeUSD, leverage) {
|
|
82
|
+
if (leverage <= 0) {
|
|
83
|
+
throw new Error('Leverage must be greater than 0');
|
|
84
|
+
}
|
|
85
|
+
if (positionSizeUSD < 0) {
|
|
86
|
+
throw new Error('Position size must be non-negative');
|
|
87
|
+
}
|
|
88
|
+
return positionSizeUSD / leverage;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Calculate leverage from position size and collateral
|
|
92
|
+
* @param positionSizeUSD - Position size in USD
|
|
93
|
+
* @param collateralUSD - Collateral amount in USD
|
|
94
|
+
* @returns Calculated leverage
|
|
95
|
+
* @example
|
|
96
|
+
* calculateLeverageFromSizeAndCollateral(30, 10) // Returns: 3
|
|
97
|
+
*/
|
|
98
|
+
function calculateLeverageFromSizeAndCollateral(positionSizeUSD, collateralUSD) {
|
|
99
|
+
if (collateralUSD <= 0) {
|
|
100
|
+
throw new Error('Collateral must be greater than 0');
|
|
101
|
+
}
|
|
102
|
+
if (positionSizeUSD < 0) {
|
|
103
|
+
throw new Error('Position size must be non-negative');
|
|
104
|
+
}
|
|
105
|
+
return positionSizeUSD / collateralUSD;
|
|
106
|
+
}
|
|
107
|
+
// ============================================================================
|
|
108
|
+
// CONVERSION UTILITIES
|
|
109
|
+
// ============================================================================
|
|
110
|
+
/**
|
|
111
|
+
* Convert USD amount to token amount using price
|
|
112
|
+
* @param amountUSD - Amount in USD
|
|
113
|
+
* @param tokenPriceUSD - Token price in USD
|
|
114
|
+
* @returns Token amount as bigint in wei
|
|
115
|
+
* @example
|
|
116
|
+
* // $100 USD at $0.019 per token
|
|
117
|
+
* usdToTokens(100, 0.019) // Returns: ~5263157894736842105263n (5263.16 * 1e18)
|
|
118
|
+
*/
|
|
119
|
+
function usdToTokens(amountUSD, tokenPriceUSD) {
|
|
120
|
+
if (tokenPriceUSD <= 0) {
|
|
121
|
+
throw new Error('Token price must be greater than 0');
|
|
122
|
+
}
|
|
123
|
+
if (amountUSD < 0) {
|
|
124
|
+
throw new Error('Amount must be non-negative');
|
|
125
|
+
}
|
|
126
|
+
const tokens = amountUSD / tokenPriceUSD;
|
|
127
|
+
return (0, viem_1.parseEther)(tokens.toString());
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Convert token amount to USD using price
|
|
131
|
+
* @param tokenAmount - Token amount as bigint in wei
|
|
132
|
+
* @param tokenPriceUSD - Token price in USD
|
|
133
|
+
* @returns Amount in USD
|
|
134
|
+
* @example
|
|
135
|
+
* // 1000 tokens at $0.019 per token
|
|
136
|
+
* tokensToUSD(parseEther('1000'), 0.019) // Returns: 19
|
|
137
|
+
*/
|
|
138
|
+
function tokensToUSD(tokenAmount, tokenPriceUSD) {
|
|
139
|
+
if (tokenPriceUSD < 0) {
|
|
140
|
+
throw new Error('Token price must be non-negative');
|
|
141
|
+
}
|
|
142
|
+
const tokens = parseFloat((0, viem_1.formatEther)(tokenAmount));
|
|
143
|
+
return tokens * tokenPriceUSD;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Convert leverage number to wei format (1e18 precision)
|
|
147
|
+
* @param leverage - Leverage as number (e.g., 3.5)
|
|
148
|
+
* @returns Leverage as bigint in wei (e.g., 3.5e18)
|
|
149
|
+
* @example
|
|
150
|
+
* leverageToWei(3.5) // Returns: 3500000000000000000n
|
|
151
|
+
*/
|
|
152
|
+
function leverageToWei(leverage) {
|
|
153
|
+
if (leverage < 0) {
|
|
154
|
+
throw new Error('Leverage must be non-negative');
|
|
155
|
+
}
|
|
156
|
+
return (0, viem_1.parseEther)(leverage.toString());
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Convert leverage wei format to number
|
|
160
|
+
* @param leverageWei - Leverage as bigint in wei
|
|
161
|
+
* @returns Leverage as number
|
|
162
|
+
* @example
|
|
163
|
+
* leverageFromWei(3500000000000000000n) // Returns: 3.5
|
|
164
|
+
*/
|
|
165
|
+
function leverageFromWei(leverageWei) {
|
|
166
|
+
return parseFloat((0, viem_1.formatEther)(leverageWei));
|
|
167
|
+
}
|
|
168
|
+
// ============================================================================
|
|
169
|
+
// PROFIT/LOSS CALCULATIONS
|
|
170
|
+
// ============================================================================
|
|
171
|
+
/**
|
|
172
|
+
* Calculate P&L percentage from price movement and leverage
|
|
173
|
+
* @param priceChangePercent - Price change in percentage (e.g., 10 for +10%)
|
|
174
|
+
* @param leverage - Leverage multiplier
|
|
175
|
+
* @param isLong - True for long position, false for short
|
|
176
|
+
* @returns P&L percentage
|
|
177
|
+
* @example
|
|
178
|
+
* // Long position, 10x leverage, +10% price move
|
|
179
|
+
* calculatePnLPercent(10, 10, true) // Returns: 100 (100% gain)
|
|
180
|
+
*
|
|
181
|
+
* // Short position, 5x leverage, +10% price move
|
|
182
|
+
* calculatePnLPercent(10, 5, false) // Returns: -50 (50% loss)
|
|
183
|
+
*/
|
|
184
|
+
function calculatePnLPercent(priceChangePercent, leverage, isLong) {
|
|
185
|
+
if (leverage < 0) {
|
|
186
|
+
throw new Error('Leverage must be non-negative');
|
|
187
|
+
}
|
|
188
|
+
const direction = isLong ? 1 : -1;
|
|
189
|
+
return priceChangePercent * leverage * direction;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Calculate absolute P&L amount in USD from price movement
|
|
193
|
+
* @param collateralUSD - Collateral amount in USD
|
|
194
|
+
* @param leverage - Leverage multiplier
|
|
195
|
+
* @param priceChangePercent - Price change in percentage
|
|
196
|
+
* @param isLong - True for long position, false for short
|
|
197
|
+
* @returns P&L amount in USD
|
|
198
|
+
* @example
|
|
199
|
+
* // $100 collateral, 3x leverage, +10% price move, long
|
|
200
|
+
* calculatePnLAmount(100, 3, 10, true) // Returns: 30 (30% of $100)
|
|
201
|
+
*/
|
|
202
|
+
function calculatePnLAmount(collateralUSD, leverage, priceChangePercent, isLong) {
|
|
203
|
+
if (leverage <= 0) {
|
|
204
|
+
throw new Error('Leverage must be greater than 0');
|
|
205
|
+
}
|
|
206
|
+
if (collateralUSD < 0) {
|
|
207
|
+
throw new Error('Collateral must be non-negative');
|
|
208
|
+
}
|
|
209
|
+
const pnlPercent = calculatePnLPercent(priceChangePercent, leverage, isLong);
|
|
210
|
+
return (collateralUSD * pnlPercent) / 100;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Calculate liquidation price from entry price and leverage
|
|
214
|
+
* @param entryPrice - Entry price of the position
|
|
215
|
+
* @param leverage - Leverage multiplier
|
|
216
|
+
* @param isLong - True for long position, false for short
|
|
217
|
+
* @param maintenanceMarginPercent - Maintenance margin percentage (default 20%)
|
|
218
|
+
* @returns Liquidation price
|
|
219
|
+
* @example
|
|
220
|
+
* // Long position at $100, 3x leverage, 20% maintenance margin
|
|
221
|
+
* // Liquidation at ~26.67% loss from entry (80% / 3)
|
|
222
|
+
* calculateLiquidationPriceFromLeverage(100, 3, true) // Returns: ~73.33
|
|
223
|
+
*/
|
|
224
|
+
function calculateLiquidationPriceFromLeverage(entryPrice, leverage, isLong, maintenanceMarginPercent = 20) {
|
|
225
|
+
if (entryPrice <= 0) {
|
|
226
|
+
throw new Error('Entry price must be greater than 0');
|
|
227
|
+
}
|
|
228
|
+
if (leverage <= 0) {
|
|
229
|
+
throw new Error('Leverage must be greater than 0');
|
|
230
|
+
}
|
|
231
|
+
if (maintenanceMarginPercent < 0 || maintenanceMarginPercent >= 100) {
|
|
232
|
+
throw new Error('Maintenance margin must be between 0 and 100');
|
|
233
|
+
}
|
|
234
|
+
// Initial margin % = 100 / leverage
|
|
235
|
+
// Max loss before liquidation = (initial margin % - maintenance margin %)
|
|
236
|
+
// For long: liquidation = entry * (1 - maxLossPercent / 100)
|
|
237
|
+
// For short: liquidation = entry * (1 + maxLossPercent / 100)
|
|
238
|
+
const initialMarginPercent = 100 / leverage;
|
|
239
|
+
const maxLossPercent = initialMarginPercent - maintenanceMarginPercent;
|
|
240
|
+
if (isLong) {
|
|
241
|
+
return entryPrice * (1 - maxLossPercent / 100);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
return entryPrice * (1 + maxLossPercent / 100);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Calculate required margin for a position size and leverage
|
|
249
|
+
* @param positionValueUSD - Position value in USD
|
|
250
|
+
* @param leverage - Leverage multiplier
|
|
251
|
+
* @returns Required margin in USD
|
|
252
|
+
* @example
|
|
253
|
+
* calculateRequiredMargin(350, 3.5) // Returns: 100
|
|
254
|
+
*/
|
|
255
|
+
function calculateRequiredMargin(positionValueUSD, leverage) {
|
|
256
|
+
if (leverage <= 0) {
|
|
257
|
+
throw new Error('Leverage must be greater than 0');
|
|
258
|
+
}
|
|
259
|
+
if (positionValueUSD < 0) {
|
|
260
|
+
throw new Error('Position value must be non-negative');
|
|
261
|
+
}
|
|
262
|
+
return positionValueUSD / leverage;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Calculate maximum position size from available collateral
|
|
266
|
+
* @param collateralUSD - Available collateral in USD
|
|
267
|
+
* @param leverage - Desired leverage
|
|
268
|
+
* @param tokenPriceUSD - Token price in USD
|
|
269
|
+
* @returns Maximum position size in tokens (as bigint in wei)
|
|
270
|
+
* @example
|
|
271
|
+
* // $100 collateral, 3x leverage, $0.019 token price
|
|
272
|
+
* calculateMaxPositionSize(100, 3, 0.019)
|
|
273
|
+
* // Returns: 15789473684210526315789n (~15789.47 tokens)
|
|
274
|
+
*/
|
|
275
|
+
function calculateMaxPositionSize(collateralUSD, leverage, tokenPriceUSD) {
|
|
276
|
+
return calculatePositionSizeFromCollateral(collateralUSD, leverage, tokenPriceUSD);
|
|
277
|
+
}
|
|
278
|
+
//# sourceMappingURL=positionCalculations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"positionCalculations.js","sourceRoot":"","sources":["../../src/utils/positionCalculations.ts"],"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Q,CAAC;AACrC,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,wBAAwB,CACtC,aAAqB,EACrB,QAAgB,EAChB,aAAqB;IAErB,OAAO,mCAAmC,CAAC,aAAa,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC;AACrF,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation utilities
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Validate Ethereum address
|
|
6
|
+
*/
|
|
7
|
+
export declare function validateAddress(address: string, fieldName?: string): void;
|
|
8
|
+
/**
|
|
9
|
+
* Validate position size
|
|
10
|
+
*/
|
|
11
|
+
export declare function validatePositionSize(size: bigint): void;
|
|
12
|
+
/**
|
|
13
|
+
* Validate leverage
|
|
14
|
+
*/
|
|
15
|
+
export declare function validateLeverage(leverage: bigint): void;
|
|
16
|
+
/**
|
|
17
|
+
* Validate positive amount
|
|
18
|
+
*/
|
|
19
|
+
export declare function validatePositiveAmount(amount: bigint, fieldName?: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Validate asset symbol
|
|
22
|
+
*/
|
|
23
|
+
export declare function validateAsset(asset: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Validate margin amount
|
|
26
|
+
*/
|
|
27
|
+
export declare function validateMargin(margin: bigint, requiredMargin: bigint): void;
|
|
28
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,GAAE,MAAkB,GAAG,IAAI,CAIpF;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAOvD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAIvD;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,GAAE,MAAiB,GAAG,IAAI,CAIzF;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAajD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,IAAI,CAO3E"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Validation utilities
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validateAddress = validateAddress;
|
|
7
|
+
exports.validatePositionSize = validatePositionSize;
|
|
8
|
+
exports.validateLeverage = validateLeverage;
|
|
9
|
+
exports.validatePositiveAmount = validatePositiveAmount;
|
|
10
|
+
exports.validateAsset = validateAsset;
|
|
11
|
+
exports.validateMargin = validateMargin;
|
|
12
|
+
const viem_1 = require("viem");
|
|
13
|
+
const errors_1 = require("../errors");
|
|
14
|
+
const constants_1 = require("../constants");
|
|
15
|
+
/**
|
|
16
|
+
* Validate Ethereum address
|
|
17
|
+
*/
|
|
18
|
+
function validateAddress(address, fieldName = 'address') {
|
|
19
|
+
if (!(0, viem_1.isAddress)(address)) {
|
|
20
|
+
throw new errors_1.ValidationError(`Invalid Ethereum address: ${address}`, fieldName);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Validate position size
|
|
25
|
+
*/
|
|
26
|
+
function validatePositionSize(size) {
|
|
27
|
+
if (size < constants_1.MIN_POSITION_SIZE) {
|
|
28
|
+
throw new errors_1.ValidationError(`Position size must be at least ${constants_1.MIN_POSITION_SIZE / constants_1.PRECISION} TAO`, 'size');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Validate leverage
|
|
33
|
+
*/
|
|
34
|
+
function validateLeverage(leverage) {
|
|
35
|
+
if (leverage < 1n || leverage > constants_1.MAX_LEVERAGE) {
|
|
36
|
+
throw new errors_1.ValidationError(`Leverage must be between 1 and ${constants_1.MAX_LEVERAGE}`, 'leverage');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Validate positive amount
|
|
41
|
+
*/
|
|
42
|
+
function validatePositiveAmount(amount, fieldName = 'amount') {
|
|
43
|
+
if (amount <= 0n) {
|
|
44
|
+
throw new errors_1.ValidationError(`${fieldName} must be positive`, fieldName);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Validate asset symbol
|
|
49
|
+
*/
|
|
50
|
+
function validateAsset(asset) {
|
|
51
|
+
if (!asset || asset.trim().length === 0) {
|
|
52
|
+
throw new errors_1.ValidationError('Asset symbol cannot be empty', 'asset');
|
|
53
|
+
}
|
|
54
|
+
// Basic validation for asset symbol format
|
|
55
|
+
const assetRegex = /^[A-Z0-9]{2,10}$/;
|
|
56
|
+
if (!assetRegex.test(asset)) {
|
|
57
|
+
throw new errors_1.ValidationError('Asset symbol must be 2-10 uppercase alphanumeric characters', 'asset');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Validate margin amount
|
|
62
|
+
*/
|
|
63
|
+
function validateMargin(margin, requiredMargin) {
|
|
64
|
+
if (margin < requiredMargin) {
|
|
65
|
+
throw new errors_1.ValidationError(`Insufficient margin. Required: ${requiredMargin}, Provided: ${margin}`, 'margin');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":";AAAA;;GAEG;;AASH,0CAIC;AAKD,oDAOC;AAKD,4CAIC;AAKD,wDAIC;AAKD,sCAaC;AAKD,wCAOC;A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,MAAM,IAAI,wBAAe,CACvB,6DAA6D,EAC7D,OAAO,CACR,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,MAAc,EAAE,cAAsB;IACnE,IAAI,MAAM,GAAG,cAAc,EAAE,CAAC;QAC5B,MAAM,IAAI,wBAAe,CACvB,kCAAkC,cAAc,eAAe,MAAM,EAAE,EACvE,QAAQ,CACT,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Alpha Futures SDK Documentation
|
|
2
|
+
|
|
3
|
+
Welcome to the Alpha Futures SDK documentation. This directory contains comprehensive guides, references, and integration documentation for working with the Alpha Futures protocol.
|
|
4
|
+
|
|
5
|
+
## Documentation Structure
|
|
6
|
+
|
|
7
|
+
### 📘 [API Reference](./api/)
|
|
8
|
+
- [API.md](./api/API.md) - Complete API reference for the Alpha Futures SDK
|
|
9
|
+
|
|
10
|
+
### 📚 [Guides](./guides/)
|
|
11
|
+
- [GETTING_STARTED.md](./guides/GETTING_STARTED.md) - Quick start guide for new users
|
|
12
|
+
- [TRADING_GUIDE.md](./guides/TRADING_GUIDE.md) - Comprehensive trading guide with examples
|
|
13
|
+
|
|
14
|
+
### 🔧 [Integration](./integration/)
|
|
15
|
+
- [INTEGRATION_GUIDE.md](./integration/INTEGRATION_GUIDE.md) - SDK integration guide for developers
|
|
16
|
+
- [VIEM_INTEGRATION.md](./integration/VIEM_INTEGRATION.md) - Guide for integrating with viem library
|
|
17
|
+
|
|
18
|
+
### 📋 [Reference](./reference/)
|
|
19
|
+
- [CLI_QUICK_REFERENCE.md](./reference/CLI_QUICK_REFERENCE.md) - Quick reference for CLI commands
|
|
20
|
+
- [TROUBLESHOOTING.md](./reference/TROUBLESHOOTING.md) - Common issues and solutions
|
|
21
|
+
|
|
22
|
+
## Quick Links
|
|
23
|
+
|
|
24
|
+
### For Traders
|
|
25
|
+
- Start with the [Getting Started Guide](./guides/GETTING_STARTED.md)
|
|
26
|
+
- Learn advanced trading strategies in the [Trading Guide](./guides/TRADING_GUIDE.md)
|
|
27
|
+
- Reference CLI commands in the [CLI Quick Reference](./reference/CLI_QUICK_REFERENCE.md)
|
|
28
|
+
|
|
29
|
+
### For Developers
|
|
30
|
+
- Integrate the SDK using the [Integration Guide](./integration/INTEGRATION_GUIDE.md)
|
|
31
|
+
- Use viem with the [Viem Integration Guide](./integration/VIEM_INTEGRATION.md)
|
|
32
|
+
- Explore the complete [API Reference](./api/API.md)
|
|
33
|
+
|
|
34
|
+
### Need Help?
|
|
35
|
+
- Check the [Troubleshooting Guide](./reference/TROUBLESHOOTING.md) for common issues
|
|
36
|
+
- Visit our [GitHub repository](https://github.com/alpha-futures/sdk) for support
|
|
37
|
+
|
|
38
|
+
## Contributing
|
|
39
|
+
|
|
40
|
+
We welcome contributions to improve our documentation. Please submit pull requests or open issues on our GitHub repository.
|