@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.
Files changed (228) hide show
  1. package/.env.example +37 -0
  2. package/CHANGELOG.md +19 -0
  3. package/README.md +199 -0
  4. package/bin/alf +4 -0
  5. package/cli/README.md +198 -0
  6. package/cli/TEST_MANUAL.md +577 -0
  7. package/cli/commands/account.ts +545 -0
  8. package/cli/commands/funding.ts +481 -0
  9. package/cli/commands/liquidation.ts +523 -0
  10. package/cli/commands/market.ts +590 -0
  11. package/cli/commands/orders.ts +395 -0
  12. package/cli/commands/position.ts +1085 -0
  13. package/cli/commands/shared/positionUtils.ts +239 -0
  14. package/cli/commands/trading.ts +483 -0
  15. package/cli/commands/utils.ts +281 -0
  16. package/cli/commands/vault.ts +522 -0
  17. package/cli/index.ts +169 -0
  18. package/cli/interactive.ts +530 -0
  19. package/cli/utils/client.ts +457 -0
  20. package/cli/utils/config.ts +226 -0
  21. package/cli/utils/display.ts +258 -0
  22. package/cli/utils/index.ts +10 -0
  23. package/cli/utils/prompts.ts +364 -0
  24. package/config.example.json +23 -0
  25. package/dist/AlphaFuturesClient.d.ts +36 -0
  26. package/dist/AlphaFuturesClient.d.ts.map +1 -0
  27. package/dist/AlphaFuturesClient.js +116 -0
  28. package/dist/AlphaFuturesClient.js.map +1 -0
  29. package/dist/abi/Alpha.json +5987 -0
  30. package/dist/abi/abis.d.ts +319 -0
  31. package/dist/abi/abis.d.ts.map +1 -0
  32. package/dist/abi/abis.js +128 -0
  33. package/dist/abi/abis.js.map +1 -0
  34. package/dist/abi/index.d.ts +11 -0
  35. package/dist/abi/index.d.ts.map +1 -0
  36. package/dist/abi/index.js +15 -0
  37. package/dist/abi/index.js.map +1 -0
  38. package/dist/config/contracts.config.d.ts +70 -0
  39. package/dist/config/contracts.config.d.ts.map +1 -0
  40. package/dist/config/contracts.config.js +137 -0
  41. package/dist/config/contracts.config.js.map +1 -0
  42. package/dist/config/environments/alpha.config.d.ts +17 -0
  43. package/dist/config/environments/alpha.config.d.ts.map +1 -0
  44. package/dist/config/environments/alpha.config.js +140 -0
  45. package/dist/config/environments/alpha.config.js.map +1 -0
  46. package/dist/config/environments/beta.config.d.ts +16 -0
  47. package/dist/config/environments/beta.config.d.ts.map +1 -0
  48. package/dist/config/environments/beta.config.js +131 -0
  49. package/dist/config/environments/beta.config.js.map +1 -0
  50. package/dist/config/environments/dev.config.d.ts +13 -0
  51. package/dist/config/environments/dev.config.d.ts.map +1 -0
  52. package/dist/config/environments/dev.config.js +123 -0
  53. package/dist/config/environments/dev.config.js.map +1 -0
  54. package/dist/config/environments/index.d.ts +48 -0
  55. package/dist/config/environments/index.d.ts.map +1 -0
  56. package/dist/config/environments/index.js +81 -0
  57. package/dist/config/environments/index.js.map +1 -0
  58. package/dist/config/environments/localhost.config.d.ts +16 -0
  59. package/dist/config/environments/localhost.config.d.ts.map +1 -0
  60. package/dist/config/environments/localhost.config.js +152 -0
  61. package/dist/config/environments/localhost.config.js.map +1 -0
  62. package/dist/config/environments/prod.config.d.ts +20 -0
  63. package/dist/config/environments/prod.config.d.ts.map +1 -0
  64. package/dist/config/environments/prod.config.js +143 -0
  65. package/dist/config/environments/prod.config.js.map +1 -0
  66. package/dist/config/index.d.ts +7 -0
  67. package/dist/config/index.d.ts.map +1 -0
  68. package/dist/config/index.js +41 -0
  69. package/dist/config/index.js.map +1 -0
  70. package/dist/constants/assets.d.ts +76 -0
  71. package/dist/constants/assets.d.ts.map +1 -0
  72. package/dist/constants/assets.js +277 -0
  73. package/dist/constants/assets.js.map +1 -0
  74. package/dist/constants/contracts.d.ts +41 -0
  75. package/dist/constants/contracts.d.ts.map +1 -0
  76. package/dist/constants/contracts.js +57 -0
  77. package/dist/constants/contracts.js.map +1 -0
  78. package/dist/constants/index.d.ts +36 -0
  79. package/dist/constants/index.d.ts.map +1 -0
  80. package/dist/constants/index.js +75 -0
  81. package/dist/constants/index.js.map +1 -0
  82. package/dist/constants/networks.d.ts +32 -0
  83. package/dist/constants/networks.d.ts.map +1 -0
  84. package/dist/constants/networks.js +174 -0
  85. package/dist/constants/networks.js.map +1 -0
  86. package/dist/contracts/index.d.ts +5 -0
  87. package/dist/contracts/index.d.ts.map +1 -0
  88. package/dist/contracts/index.js +21 -0
  89. package/dist/contracts/index.js.map +1 -0
  90. package/dist/contracts/viem/AlphaViem.d.ts +518 -0
  91. package/dist/contracts/viem/AlphaViem.d.ts.map +1 -0
  92. package/dist/contracts/viem/AlphaViem.js +1287 -0
  93. package/dist/contracts/viem/AlphaViem.js.map +1 -0
  94. package/dist/contracts/viem/PriceOracleViem.d.ts +71 -0
  95. package/dist/contracts/viem/PriceOracleViem.d.ts.map +1 -0
  96. package/dist/contracts/viem/PriceOracleViem.js +212 -0
  97. package/dist/contracts/viem/PriceOracleViem.js.map +1 -0
  98. package/dist/contracts/viem/index.d.ts +9 -0
  99. package/dist/contracts/viem/index.d.ts.map +1 -0
  100. package/dist/contracts/viem/index.js +17 -0
  101. package/dist/contracts/viem/index.js.map +1 -0
  102. package/dist/errors/index.d.ts +44 -0
  103. package/dist/errors/index.d.ts.map +1 -0
  104. package/dist/errors/index.js +83 -0
  105. package/dist/errors/index.js.map +1 -0
  106. package/dist/index.d.ts +19 -0
  107. package/dist/index.d.ts.map +1 -0
  108. package/dist/index.js +60 -0
  109. package/dist/index.js.map +1 -0
  110. package/dist/types/alpha.d.ts +299 -0
  111. package/dist/types/alpha.d.ts.map +1 -0
  112. package/dist/types/alpha.js +6 -0
  113. package/dist/types/alpha.js.map +1 -0
  114. package/dist/types/client.d.ts +24 -0
  115. package/dist/types/client.d.ts.map +1 -0
  116. package/dist/types/client.js +13 -0
  117. package/dist/types/client.js.map +1 -0
  118. package/dist/types/contracts.d.ts +48 -0
  119. package/dist/types/contracts.d.ts.map +1 -0
  120. package/dist/types/contracts.js +6 -0
  121. package/dist/types/contracts.js.map +1 -0
  122. package/dist/types/funding.d.ts +27 -0
  123. package/dist/types/funding.d.ts.map +1 -0
  124. package/dist/types/funding.js +6 -0
  125. package/dist/types/funding.js.map +1 -0
  126. package/dist/types/index.d.ts +92 -0
  127. package/dist/types/index.d.ts.map +1 -0
  128. package/dist/types/index.js +47 -0
  129. package/dist/types/index.js.map +1 -0
  130. package/dist/types/liquidation.d.ts +20 -0
  131. package/dist/types/liquidation.d.ts.map +1 -0
  132. package/dist/types/liquidation.js +6 -0
  133. package/dist/types/liquidation.js.map +1 -0
  134. package/dist/types/margin.d.ts +29 -0
  135. package/dist/types/margin.d.ts.map +1 -0
  136. package/dist/types/margin.js +6 -0
  137. package/dist/types/margin.js.map +1 -0
  138. package/dist/types/oracle.d.ts +21 -0
  139. package/dist/types/oracle.d.ts.map +1 -0
  140. package/dist/types/oracle.js +6 -0
  141. package/dist/types/oracle.js.map +1 -0
  142. package/dist/types/positions.d.ts +43 -0
  143. package/dist/types/positions.d.ts.map +1 -0
  144. package/dist/types/positions.js +13 -0
  145. package/dist/types/positions.js.map +1 -0
  146. package/dist/utils/calculations.d.ts +84 -0
  147. package/dist/utils/calculations.d.ts.map +1 -0
  148. package/dist/utils/calculations.js +155 -0
  149. package/dist/utils/calculations.js.map +1 -0
  150. package/dist/utils/errors.d.ts +24 -0
  151. package/dist/utils/errors.d.ts.map +1 -0
  152. package/dist/utils/errors.js +129 -0
  153. package/dist/utils/errors.js.map +1 -0
  154. package/dist/utils/events.d.ts +40 -0
  155. package/dist/utils/events.d.ts.map +1 -0
  156. package/dist/utils/events.js +73 -0
  157. package/dist/utils/events.js.map +1 -0
  158. package/dist/utils/format.d.ts +40 -0
  159. package/dist/utils/format.d.ts.map +1 -0
  160. package/dist/utils/format.js +86 -0
  161. package/dist/utils/format.js.map +1 -0
  162. package/dist/utils/index.d.ts +10 -0
  163. package/dist/utils/index.d.ts.map +1 -0
  164. package/dist/utils/index.js +26 -0
  165. package/dist/utils/index.js.map +1 -0
  166. package/dist/utils/network.d.ts +52 -0
  167. package/dist/utils/network.d.ts.map +1 -0
  168. package/dist/utils/network.js +192 -0
  169. package/dist/utils/network.js.map +1 -0
  170. package/dist/utils/positionCalculations.d.ts +145 -0
  171. package/dist/utils/positionCalculations.d.ts.map +1 -0
  172. package/dist/utils/positionCalculations.js +278 -0
  173. package/dist/utils/positionCalculations.js.map +1 -0
  174. package/dist/utils/validation.d.ts +28 -0
  175. package/dist/utils/validation.d.ts.map +1 -0
  176. package/dist/utils/validation.js +68 -0
  177. package/dist/utils/validation.js.map +1 -0
  178. package/docs/README.md +40 -0
  179. package/docs/api/API.md +831 -0
  180. package/docs/guides/GETTING_STARTED.md +316 -0
  181. package/docs/guides/TRADING_GUIDE.md +677 -0
  182. package/docs/integration/INTEGRATION_GUIDE.md +1679 -0
  183. package/docs/integration/VIEM_INTEGRATION.md +294 -0
  184. package/docs/reference/CLI_QUICK_REFERENCE.md +197 -0
  185. package/docs/reference/TROUBLESHOOTING.md +922 -0
  186. package/package.json +113 -0
  187. package/src/AlphaFuturesClient.ts +158 -0
  188. package/src/abi/.gitkeep +1 -0
  189. package/src/abi/Alpha.json +5987 -0
  190. package/src/abi/README.md +99 -0
  191. package/src/abi/abis.ts +131 -0
  192. package/src/abi/index.ts +13 -0
  193. package/src/config/contracts.config.ts +186 -0
  194. package/src/config/environments/alpha.config.ts +139 -0
  195. package/src/config/environments/beta.config.ts +130 -0
  196. package/src/config/environments/dev.config.ts +122 -0
  197. package/src/config/environments/index.ts +87 -0
  198. package/src/config/environments/localhost.config.ts +153 -0
  199. package/src/config/environments/prod.config.ts +142 -0
  200. package/src/config/index.ts +29 -0
  201. package/src/constants/assets.ts +299 -0
  202. package/src/constants/contracts.ts +64 -0
  203. package/src/constants/index.ts +69 -0
  204. package/src/constants/networks.ts +182 -0
  205. package/src/contracts/index.ts +5 -0
  206. package/src/contracts/viem/AlphaViem.ts +1615 -0
  207. package/src/contracts/viem/PriceOracleViem.ts +272 -0
  208. package/src/contracts/viem/index.ts +11 -0
  209. package/src/errors/index.ts +87 -0
  210. package/src/index.ts +59 -0
  211. package/src/types/VIEM_TYPES_README.md +70 -0
  212. package/src/types/alpha.ts +358 -0
  213. package/src/types/client.ts +27 -0
  214. package/src/types/contracts.ts +74 -0
  215. package/src/types/funding.ts +31 -0
  216. package/src/types/index.ts +108 -0
  217. package/src/types/liquidation.ts +23 -0
  218. package/src/types/margin.ts +34 -0
  219. package/src/types/oracle.ts +24 -0
  220. package/src/types/positions.ts +48 -0
  221. package/src/utils/calculations.ts +175 -0
  222. package/src/utils/errors.ts +147 -0
  223. package/src/utils/events.ts +98 -0
  224. package/src/utils/format.ts +84 -0
  225. package/src/utils/index.ts +10 -0
  226. package/src/utils/network.ts +212 -0
  227. package/src/utils/positionCalculations.ts +317 -0
  228. package/src/utils/validation.ts +76 -0
@@ -0,0 +1,99 @@
1
+ # ABI Integration
2
+
3
+ This directory contains the Application Binary Interfaces (ABIs) for the Alpha Futures smart contracts.
4
+
5
+ ## Overview
6
+
7
+ ABIs are JSON representations of smart contract interfaces that enable the SDK to interact with deployed contracts on the blockchain. They define:
8
+ - Function signatures
9
+ - Event definitions
10
+ - Error types
11
+ - Data structures
12
+
13
+ ## Generating ABIs
14
+
15
+ ABIs are generated from the compiled contracts using the provided script:
16
+
17
+ ```bash
18
+ # Generate ABIs from compiled contracts
19
+ npm run generate:abis
20
+
21
+ # Or directly
22
+ npm run generate
23
+ ```
24
+
25
+ ## Prerequisites
26
+
27
+ Before generating ABIs, ensure that:
28
+ 1. The contracts are compiled: `forge build` (run from the root directory)
29
+ 2. The compiled artifacts exist in the `out/` directory
30
+
31
+ ## File Structure
32
+
33
+ ```
34
+ src/abi/
35
+ ├── README.md # This file
36
+ ├── index.ts # Main export file for all ABIs
37
+ ├── abis.ts # Type-safe ABI definitions for Viem
38
+ ├── MarginAccount.json # MarginAccount contract ABI
39
+ ├── PositionManager.json # PositionManager contract ABI
40
+ ├── FundingRateEngine.json # FundingRateEngine contract ABI
41
+ ├── LiquidationEngine.json # LiquidationEngine contract ABI
42
+ ├── ProtocolVault.json # ProtocolVault contract ABI
43
+ ├── AlphaFuturesOrderBook.json # OrderBook contract ABI
44
+ ├── AccessController.json # AccessController contract ABI
45
+ ├── ConditionalOrderManager.json # ConditionalOrderManager contract ABI
46
+ ├── MatchingEngineModule.json # MatchingEngine module ABI
47
+ ├── CommitRevealModule.json # CommitReveal module ABI
48
+ └── ... # Other contract ABIs
49
+ ```
50
+
51
+ ## Usage with Viem
52
+
53
+ The SDK uses Viem for automatic type inference from ABIs - no code generation needed:
54
+
55
+ ```typescript
56
+ import { getContract } from 'viem';
57
+ import { MarginAccountABI } from '../abi/abis';
58
+
59
+ const contract = getContract({
60
+ address: '0x...',
61
+ abi: MarginAccountABI,
62
+ client: publicClient
63
+ });
64
+
65
+ // Full type safety and autocomplete
66
+ const balance = await contract.read.getBalance(['0x...']);
67
+ ```
68
+
69
+ ## Type Safety
70
+
71
+ Viem provides automatic type inference directly from your ABI definitions:
72
+ - **Zero Code Generation**: Types are inferred at compile time
73
+ - **Always Up-to-Date**: Types automatically update when ABIs change
74
+ - **Full IntelliSense**: Complete autocomplete for all contract methods
75
+ - **Type-Safe Parameters**: Function arguments are fully typed
76
+
77
+ ## Adding New Contracts
78
+
79
+ To add a new contract to the ABI system:
80
+
81
+ 1. Add the contract name to the `CONTRACTS` array in `scripts/generate-abis.ts`
82
+ 2. Ensure the contract is compiled
83
+ 3. Run `npm run generate` to generate the ABI
84
+ 4. Update `ViemContractFactory.ts` to include the new contract
85
+ 5. Create a Viem wrapper class in `src/contracts/viem/` if needed
86
+
87
+ ## Manual ABI Updates
88
+
89
+ If you need to manually update an ABI:
90
+ 1. Place the ABI JSON file in this directory
91
+ 2. Update `index.ts` to export the new ABI
92
+ 3. Update `abis.ts` with the type-safe ABI definition
93
+
94
+ ## Important Notes
95
+
96
+ - ABIs are generated from compiled contracts, so always compile before generating
97
+ - The generated ABI files should be committed to version control
98
+ - If contract interfaces change, regenerate ABIs
99
+ - The SDK uses Viem's automatic type inference - no TypeChain generation needed
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Type-safe ABI definitions using Viem and ABIType
3
+ * This file provides properly typed ABIs that enable automatic type inference
4
+ *
5
+ * Alpha.json contains the complete monolithic contract ABI including:
6
+ * - Trading operations (open/close positions)
7
+ * - Margin management
8
+ * - Orderbook functionality
9
+ * - Position management
10
+ * - Vault operations
11
+ * - Admin functions
12
+ * - Price oracle integration
13
+ * - Access control
14
+ */
15
+
16
+ import { type Abi } from 'viem';
17
+ import AlphaABIJSON from './Alpha.json';
18
+
19
+ // ERC20 Token ABI (for TAO and other collateral tokens)
20
+ export const ERC20ABI = [
21
+ {
22
+ type: 'function',
23
+ name: 'transfer',
24
+ inputs: [
25
+ { name: 'to', type: 'address' },
26
+ { name: 'amount', type: 'uint256' },
27
+ ],
28
+ outputs: [{ name: 'success', type: 'bool' }],
29
+ stateMutability: 'nonpayable',
30
+ },
31
+ {
32
+ type: 'function',
33
+ name: 'transferFrom',
34
+ inputs: [
35
+ { name: 'from', type: 'address' },
36
+ { name: 'to', type: 'address' },
37
+ { name: 'amount', type: 'uint256' },
38
+ ],
39
+ outputs: [{ name: 'success', type: 'bool' }],
40
+ stateMutability: 'nonpayable',
41
+ },
42
+ {
43
+ type: 'function',
44
+ name: 'approve',
45
+ inputs: [
46
+ { name: 'spender', type: 'address' },
47
+ { name: 'amount', type: 'uint256' },
48
+ ],
49
+ outputs: [{ name: 'success', type: 'bool' }],
50
+ stateMutability: 'nonpayable',
51
+ },
52
+ {
53
+ type: 'function',
54
+ name: 'balanceOf',
55
+ inputs: [{ name: 'account', type: 'address' }],
56
+ outputs: [{ name: 'balance', type: 'uint256' }],
57
+ stateMutability: 'view',
58
+ },
59
+ {
60
+ type: 'function',
61
+ name: 'allowance',
62
+ inputs: [
63
+ { name: 'owner', type: 'address' },
64
+ { name: 'spender', type: 'address' },
65
+ ],
66
+ outputs: [{ name: 'remaining', type: 'uint256' }],
67
+ stateMutability: 'view',
68
+ },
69
+ {
70
+ type: 'function',
71
+ name: 'decimals',
72
+ inputs: [],
73
+ outputs: [{ name: '', type: 'uint8' }],
74
+ stateMutability: 'view',
75
+ },
76
+ {
77
+ type: 'function',
78
+ name: 'symbol',
79
+ inputs: [],
80
+ outputs: [{ name: '', type: 'string' }],
81
+ stateMutability: 'view',
82
+ },
83
+ {
84
+ type: 'function',
85
+ name: 'name',
86
+ inputs: [],
87
+ outputs: [{ name: '', type: 'string' }],
88
+ stateMutability: 'view',
89
+ },
90
+ {
91
+ type: 'event',
92
+ name: 'Transfer',
93
+ inputs: [
94
+ { name: 'from', type: 'address', indexed: true },
95
+ { name: 'to', type: 'address', indexed: true },
96
+ { name: 'value', type: 'uint256', indexed: false },
97
+ ],
98
+ },
99
+ {
100
+ type: 'event',
101
+ name: 'Approval',
102
+ inputs: [
103
+ { name: 'owner', type: 'address', indexed: true },
104
+ { name: 'spender', type: 'address', indexed: true },
105
+ { name: 'value', type: 'uint256', indexed: false },
106
+ ],
107
+ },
108
+ ] as const satisfies Abi;
109
+
110
+ // Price Oracle ABI (for standalone oracle contract)
111
+ export const PriceOracleABI = [
112
+ {
113
+ type: 'function',
114
+ name: 'calculatePriceFromReserves',
115
+ inputs: [{ name: 'netUid', type: 'uint16' }],
116
+ outputs: [{ name: '', type: 'uint256' }],
117
+ stateMutability: 'view',
118
+ },
119
+ ] as const satisfies Abi;
120
+
121
+ // Export all ABIs as a typed object
122
+ export const ABIs = {
123
+ Alpha: AlphaABIJSON as Abi,
124
+ ERC20: ERC20ABI,
125
+ PriceOracle: PriceOracleABI,
126
+ } as const;
127
+
128
+ // Type exports for better developer experience
129
+ export type ERC20ABI = typeof ERC20ABI;
130
+ export type PriceOracleABI = typeof PriceOracleABI;
131
+ export type AlphaABI = typeof AlphaABIJSON;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * ABI exports for Alpha Futures Protocol
3
+ *
4
+ * Alpha.json: Complete monolithic contract ABI
5
+ * ERC20ABI: Standard ERC20 token interface for TAO and collateral
6
+ * PriceOracleABI: Standalone price oracle contract interface
7
+ */
8
+
9
+ export { ABIs, ERC20ABI, PriceOracleABI } from './abis';
10
+ export type { ERC20ABI as ERC20ABIType, PriceOracleABI as PriceOracleABIType } from './abis';
11
+
12
+ // Export Alpha ABI type from abis.ts to avoid duplication
13
+ export type { AlphaABI } from './abis';
@@ -0,0 +1,186 @@
1
+ /**
2
+ * Contract configuration management for Alpha Futures SDK
3
+ * Handles loading and managing contract addresses across different networks
4
+ */
5
+
6
+ // Contract configuration management
7
+ import { NETWORK_CONFIGS, isValidNetwork } from '../constants/networks';
8
+
9
+ import { Address } from 'viem';
10
+
11
+ export interface ContractAddresses {
12
+ alpha: Address;
13
+ priceOracle: Address;
14
+ collateralToken: Address;
15
+ }
16
+
17
+ export interface DeploymentInfo {
18
+ network: string;
19
+ chainId: number;
20
+ deploymentDate: string;
21
+ deployer: string;
22
+ contracts: {
23
+ [contractName: string]: {
24
+ address: string;
25
+ transactionHash: string;
26
+ blockNumber: number;
27
+ constructorArguments?: unknown[];
28
+ };
29
+ };
30
+ configuration?: {
31
+ [key: string]: string | number;
32
+ };
33
+ }
34
+
35
+ export class ContractsConfig {
36
+ private static instance: ContractsConfig;
37
+ private deployments: Map<string, DeploymentInfo> = new Map();
38
+ private overrides: Map<string, Partial<ContractAddresses>> = new Map();
39
+
40
+ private constructor() {
41
+ // No filesystem loading - use static network configurations only
42
+ }
43
+
44
+ /**
45
+ * Gets the singleton instance
46
+ */
47
+ public static getInstance(): ContractsConfig {
48
+ if (!ContractsConfig.instance) {
49
+ ContractsConfig.instance = new ContractsConfig();
50
+ }
51
+ return ContractsConfig.instance;
52
+ }
53
+
54
+ /**
55
+ * Gets contract addresses for a network
56
+ */
57
+ public getContractAddresses(network: string): ContractAddresses {
58
+ if (!isValidNetwork(network)) {
59
+ throw new Error(`Invalid network: ${network}`);
60
+ }
61
+
62
+ // Start with default addresses from network config
63
+ const networkConfig = NETWORK_CONFIGS[network];
64
+ const addresses: ContractAddresses = {
65
+ alpha:
66
+ networkConfig.contracts.alpha || ('0x0000000000000000000000000000000000000000' as Address),
67
+ priceOracle:
68
+ networkConfig.contracts.priceOracle ||
69
+ ('0x0000000000000000000000000000000000000000' as Address),
70
+ collateralToken:
71
+ networkConfig.contracts.collateralToken ||
72
+ ('0x0000000000000000000000000000000000000000' as Address),
73
+ };
74
+
75
+ // Apply deployment addresses if available
76
+ const deployment = this.deployments.get(network);
77
+ if (deployment) {
78
+ for (const [contractName, contractData] of Object.entries(deployment.contracts)) {
79
+ const key = this.normalizeContractName(contractName);
80
+ if (key in addresses) {
81
+ (addresses as any)[key] = contractData.address;
82
+ }
83
+ }
84
+ }
85
+
86
+ // Apply any overrides
87
+ const overrides = this.overrides.get(network);
88
+ if (overrides) {
89
+ Object.assign(addresses, overrides);
90
+ }
91
+
92
+ return addresses;
93
+ }
94
+
95
+ /**
96
+ * Normalizes contract names to match the expected format
97
+ */
98
+ private normalizeContractName(name: string): string {
99
+ // Convert from PascalCase to camelCase
100
+ const camelCase = name.charAt(0).toLowerCase() + name.slice(1);
101
+
102
+ // Handle special cases
103
+ const mappings: { [key: string]: string } = {
104
+ collateralToken: 'collateralToken',
105
+ CollateralToken: 'collateralToken',
106
+ };
107
+
108
+ return mappings[camelCase] || camelCase;
109
+ }
110
+
111
+ /**
112
+ * Sets contract address overrides for a network
113
+ */
114
+ public setContractOverrides(network: string, overrides: Partial<ContractAddresses>): void {
115
+ if (!isValidNetwork(network)) {
116
+ throw new Error(`Invalid network: ${network}`);
117
+ }
118
+ this.overrides.set(network, overrides);
119
+ }
120
+
121
+ /**
122
+ * Clears contract address overrides for a network
123
+ */
124
+ public clearContractOverrides(network: string): void {
125
+ this.overrides.delete(network);
126
+ }
127
+
128
+ /**
129
+ * Gets deployment information for a network
130
+ */
131
+ public getDeploymentInfo(network: string): DeploymentInfo | undefined {
132
+ return this.deployments.get(network);
133
+ }
134
+
135
+ /**
136
+ * Updates contract configuration with new addresses
137
+ */
138
+ public updateNetworkConfig(network: string, addresses: ContractAddresses): void {
139
+ if (!isValidNetwork(network)) {
140
+ throw new Error(`Invalid network: ${network}`);
141
+ }
142
+
143
+ // Update the network config
144
+ NETWORK_CONFIGS[network].contracts = addresses;
145
+
146
+ // Also update in deployments if exists
147
+ const deployment = this.deployments.get(network);
148
+ if (deployment) {
149
+ for (const [key, address] of Object.entries(addresses)) {
150
+ const contractName = key.charAt(0).toUpperCase() + key.slice(1);
151
+ if (!deployment.contracts[contractName]) {
152
+ deployment.contracts[contractName] = {
153
+ address,
154
+ transactionHash: '0x0',
155
+ blockNumber: 0,
156
+ };
157
+ } else {
158
+ deployment.contracts[contractName].address = address;
159
+ }
160
+ }
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Validates that all required contracts are deployed for a network
166
+ */
167
+ public validateDeployment(network: string): { valid: boolean; missing: string[] } {
168
+ const addresses = this.getContractAddresses(network);
169
+ const required = ['alpha', 'priceOracle', 'collateralToken'];
170
+
171
+ const missing = required.filter(
172
+ (contract) =>
173
+ !addresses[contract as keyof ContractAddresses] ||
174
+ addresses[contract as keyof ContractAddresses] ===
175
+ '0x0000000000000000000000000000000000000000',
176
+ );
177
+
178
+ return {
179
+ valid: missing.length === 0,
180
+ missing,
181
+ };
182
+ }
183
+ }
184
+
185
+ // Export singleton instance
186
+ export const contractsConfig = ContractsConfig.getInstance();
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Alpha Environment Configuration (Bittensor Mainnet - Testing)
3
+ *
4
+ * Collateral: Mock wTAO with 18 decimals
5
+ * Markets: 12 Bittensor subnets
6
+ * Network: Bittensor Finney (Chain ID: 964)
7
+ *
8
+ * LAST SYNCED: 2026-02-13
9
+ * DEPLOYMENT: deployments/alpha/deployment.json
10
+ *
11
+ * NOTE: This environment is deployed on Bittensor mainnet.
12
+ * Deployment Timestamp: 1769197297 (January 2026)
13
+ * Deployer: 0xa3A00185748B64eDA4149745415080cBA720E720
14
+ */
15
+
16
+ import { NetworkConfig } from '../../types';
17
+
18
+ export const ALPHA_CONFIG: NetworkConfig = {
19
+ chainId: 964,
20
+ name: 'Alpha Futures - Bittensor Mainnet',
21
+ rpcUrl: 'https://bittensor-finney.api.onfinality.io/public', // Primary RPC
22
+ blockExplorer: 'https://evm.taostats.io/',
23
+ contracts: {
24
+ alpha: '0x5E29Ac73dFbc5906971343a191c1fc37C41286f7', // Alpha Futures Protocol (Proxy)
25
+ priceOracle: '0x30583DDB209128566A5433DA3384023d3575b20d',
26
+ collateralToken: '0x0000000000000000000000000000000000000000', // Mock wTAO Token
27
+ },
28
+ collateralTokenInfo: {
29
+ symbol: 'TAO',
30
+ decimals: 18,
31
+ name: 'TAO',
32
+ },
33
+ markets: [
34
+ {
35
+ id: 64,
36
+ name: 'Chutes',
37
+ marketAddress: '0x0000000000000000000000000000000000000040',
38
+ symbol: 'CHUTES',
39
+ displayName: 'Chutes (SN64)',
40
+ hasOraclePrice: true,
41
+ },
42
+ {
43
+ id: 51,
44
+ name: 'lium.io',
45
+ marketAddress: '0x0000000000000000000000000000000000000033',
46
+ symbol: 'LIUM',
47
+ displayName: 'lium.io (SN51)',
48
+ hasOraclePrice: true,
49
+ },
50
+ {
51
+ id: 62,
52
+ name: 'Ridges',
53
+ marketAddress: '0x000000000000000000000000000000000000003e',
54
+ symbol: 'RIDGES',
55
+ displayName: 'Ridges (SN62)',
56
+ hasOraclePrice: true,
57
+ },
58
+ {
59
+ id: 4,
60
+ name: 'Targon',
61
+ marketAddress: '0x0000000000000000000000000000000000000004',
62
+ symbol: 'TARGON',
63
+ displayName: 'Targon (SN4)',
64
+ hasOraclePrice: true,
65
+ },
66
+ {
67
+ id: 8,
68
+ name: 'Vanta',
69
+ marketAddress: '0x0000000000000000000000000000000000000008',
70
+ symbol: 'VANTA',
71
+ displayName: 'Vanta (SN8)',
72
+ hasOraclePrice: true,
73
+ },
74
+ {
75
+ id: 120,
76
+ name: 'Affine',
77
+ marketAddress: '0x0000000000000000000000000000000000000078',
78
+ symbol: 'AFFINE',
79
+ displayName: 'Affine (SN120)',
80
+ hasOraclePrice: true,
81
+ },
82
+ {
83
+ id: 3,
84
+ name: 'templar',
85
+ marketAddress: '0x0000000000000000000000000000000000000003',
86
+ symbol: 'TEMPLAR',
87
+ displayName: 'templar (SN3)',
88
+ hasOraclePrice: true,
89
+ },
90
+ {
91
+ id: 44,
92
+ name: 'Score',
93
+ marketAddress: '0x000000000000000000000000000000000000002c',
94
+ symbol: 'SCORE',
95
+ displayName: 'Score (SN44)',
96
+ hasOraclePrice: true,
97
+ },
98
+ {
99
+ id: 9,
100
+ name: 'iota',
101
+ marketAddress: '0x0000000000000000000000000000000000000009',
102
+ symbol: 'IOTA',
103
+ displayName: 'iota (SN9)',
104
+ hasOraclePrice: true,
105
+ },
106
+ {
107
+ id: 56,
108
+ name: 'Gradients',
109
+ marketAddress: '0x0000000000000000000000000000000000000038',
110
+ symbol: 'GRADIENTS',
111
+ displayName: 'Gradients (SN56)',
112
+ hasOraclePrice: true,
113
+ },
114
+ {
115
+ id: 75,
116
+ name: 'Hippius',
117
+ marketAddress: '0x000000000000000000000000000000000000004b',
118
+ symbol: 'HIPPIUS',
119
+ displayName: 'Hippius (SN75)',
120
+ hasOraclePrice: true,
121
+ },
122
+ {
123
+ id: 34,
124
+ name: 'BitMind',
125
+ marketAddress: '0x0000000000000000000000000000000000000022',
126
+ symbol: 'BITMIND',
127
+ displayName: 'BitMind (SN34)',
128
+ hasOraclePrice: true,
129
+ },
130
+ {
131
+ id: 65534,
132
+ name: 'MTSOS',
133
+ marketAddress: '0x000000000000000000000000000000000000FFFE',
134
+ symbol: 'MTSOS',
135
+ displayName: 'MegaTAO Sum-of-Subnets Index',
136
+ hasOraclePrice: true,
137
+ },
138
+ ],
139
+ };
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Beta Environment Configuration (Staging)
3
+ *
4
+ * Uses Mock USDC with 6 decimals
5
+ * 2 generic markets: ALPHA_BTC, ALPHA_ETH
6
+ * Initial vault: 1,000 USDC
7
+ *
8
+ * LAST SYNCED: 2025-12-09
9
+ * DEPLOYMENT: deployments/beta/deployment.json
10
+ *
11
+ * Deployed: 2025-12-08
12
+ * Same collateral/oracle as alpha environment
13
+ */
14
+
15
+ import { NetworkConfig } from '../../types';
16
+
17
+ export const BETA_CONFIG: NetworkConfig = {
18
+ chainId: 964,
19
+ name: 'Alpha Futures - Beta Staging',
20
+ rpcUrl: 'https://bittensor-finney.api.onfinality.io/public',
21
+ blockExplorer: 'https://evm.taostats.io/',
22
+ contracts: {
23
+ alpha: '0xa57D785194De368d8944c39b4c2d2F7A3F548132',
24
+ priceOracle: '0x6541318525de2FBB108a35Ecd57b14E9A5418fCC',
25
+ collateralToken: '0x26804e3F75e7ABA449FD0B46479E0a196417bFA6', // Mock USDC
26
+ },
27
+ collateralTokenInfo: {
28
+ symbol: 'USDC',
29
+ decimals: 6,
30
+ name: 'Mock USDC',
31
+ },
32
+ markets: [
33
+ {
34
+ id: 64,
35
+ name: 'Chutes',
36
+ marketAddress: '0x0000000000000000000000000000000000000040',
37
+ symbol: 'CHUTES',
38
+ displayName: 'Chutes (SN64)',
39
+ hasOraclePrice: true,
40
+ },
41
+ {
42
+ id: 51,
43
+ name: 'lium.io',
44
+ marketAddress: '0x0000000000000000000000000000000000000033',
45
+ symbol: 'LIUM',
46
+ displayName: 'lium.io (SN51)',
47
+ hasOraclePrice: true,
48
+ },
49
+ {
50
+ id: 62,
51
+ name: 'Ridges',
52
+ marketAddress: '0x000000000000000000000000000000000000003e',
53
+ symbol: 'RIDGES',
54
+ displayName: 'Ridges (SN62)',
55
+ hasOraclePrice: true,
56
+ },
57
+ {
58
+ id: 4,
59
+ name: 'Targon',
60
+ marketAddress: '0x0000000000000000000000000000000000000004',
61
+ symbol: 'TARGON',
62
+ displayName: 'Targon (SN4)',
63
+ hasOraclePrice: true,
64
+ },
65
+ {
66
+ id: 8,
67
+ name: 'Vanta',
68
+ marketAddress: '0x0000000000000000000000000000000000000008',
69
+ symbol: 'VANTA',
70
+ displayName: 'Vanta (SN8)',
71
+ hasOraclePrice: true,
72
+ },
73
+ {
74
+ id: 120,
75
+ name: 'Affine',
76
+ marketAddress: '0x0000000000000000000000000000000000000078',
77
+ symbol: 'AFFINE',
78
+ displayName: 'Affine (SN120)',
79
+ hasOraclePrice: true,
80
+ },
81
+ {
82
+ id: 3,
83
+ name: 'templar',
84
+ marketAddress: '0x0000000000000000000000000000000000000003',
85
+ symbol: 'TEMPLAR',
86
+ displayName: 'templar (SN3)',
87
+ hasOraclePrice: true,
88
+ },
89
+ {
90
+ id: 44,
91
+ name: 'Score',
92
+ marketAddress: '0x000000000000000000000000000000000000002c',
93
+ symbol: 'SCORE',
94
+ displayName: 'Score (SN44)',
95
+ hasOraclePrice: true,
96
+ },
97
+ {
98
+ id: 9,
99
+ name: 'iota',
100
+ marketAddress: '0x0000000000000000000000000000000000000009',
101
+ symbol: 'IOTA',
102
+ displayName: 'iota (SN9)',
103
+ hasOraclePrice: true,
104
+ },
105
+ {
106
+ id: 56,
107
+ name: 'Gradients',
108
+ marketAddress: '0x0000000000000000000000000000000000000038',
109
+ symbol: 'GRADIENTS',
110
+ displayName: 'Gradients (SN56)',
111
+ hasOraclePrice: true,
112
+ },
113
+ {
114
+ id: 75,
115
+ name: 'Hippius',
116
+ marketAddress: '0x000000000000000000000000000000000000004b',
117
+ symbol: 'HIPPIUS',
118
+ displayName: 'Hippius (SN75)',
119
+ hasOraclePrice: true,
120
+ },
121
+ {
122
+ id: 34,
123
+ name: 'BitMind',
124
+ marketAddress: '0x0000000000000000000000000000000000000022',
125
+ symbol: 'BITMIND',
126
+ displayName: 'BitMind (SN34)',
127
+ hasOraclePrice: true,
128
+ },
129
+ ],
130
+ };