@the-situation/sdk 0.1.0-alpha.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 (221) hide show
  1. package/dist/__integration__/setup/accounts.d.ts +38 -0
  2. package/dist/__integration__/setup/accounts.d.ts.map +1 -0
  3. package/dist/__integration__/setup/accounts.js +50 -0
  4. package/dist/__integration__/setup/accounts.js.map +1 -0
  5. package/dist/__integration__/setup/artifacts.d.ts +51 -0
  6. package/dist/__integration__/setup/artifacts.d.ts.map +1 -0
  7. package/dist/__integration__/setup/artifacts.js +72 -0
  8. package/dist/__integration__/setup/artifacts.js.map +1 -0
  9. package/dist/__integration__/setup/deploy.d.ts +152 -0
  10. package/dist/__integration__/setup/deploy.d.ts.map +1 -0
  11. package/dist/__integration__/setup/deploy.js +344 -0
  12. package/dist/__integration__/setup/deploy.js.map +1 -0
  13. package/dist/__integration__/setup/devnet.d.ts +44 -0
  14. package/dist/__integration__/setup/devnet.d.ts.map +1 -0
  15. package/dist/__integration__/setup/devnet.js +97 -0
  16. package/dist/__integration__/setup/devnet.js.map +1 -0
  17. package/dist/__integration__/setup/erc20.d.ts +58 -0
  18. package/dist/__integration__/setup/erc20.d.ts.map +1 -0
  19. package/dist/__integration__/setup/erc20.js +194 -0
  20. package/dist/__integration__/setup/erc20.js.map +1 -0
  21. package/dist/__integration__/setup/fixtures.d.ts +125 -0
  22. package/dist/__integration__/setup/fixtures.d.ts.map +1 -0
  23. package/dist/__integration__/setup/fixtures.js +206 -0
  24. package/dist/__integration__/setup/fixtures.js.map +1 -0
  25. package/dist/__integration__/setup/index.d.ts +12 -0
  26. package/dist/__integration__/setup/index.d.ts.map +1 -0
  27. package/dist/__integration__/setup/index.js +12 -0
  28. package/dist/__integration__/setup/index.js.map +1 -0
  29. package/dist/__integration__/utils/assertions.d.ts +117 -0
  30. package/dist/__integration__/utils/assertions.d.ts.map +1 -0
  31. package/dist/__integration__/utils/assertions.js +191 -0
  32. package/dist/__integration__/utils/assertions.js.map +1 -0
  33. package/dist/__integration__/utils/balance-tracker.d.ts +85 -0
  34. package/dist/__integration__/utils/balance-tracker.d.ts.map +1 -0
  35. package/dist/__integration__/utils/balance-tracker.js +139 -0
  36. package/dist/__integration__/utils/balance-tracker.js.map +1 -0
  37. package/dist/__integration__/utils/calldata.d.ts +74 -0
  38. package/dist/__integration__/utils/calldata.d.ts.map +1 -0
  39. package/dist/__integration__/utils/calldata.js +119 -0
  40. package/dist/__integration__/utils/calldata.js.map +1 -0
  41. package/dist/__integration__/utils/index.d.ts +11 -0
  42. package/dist/__integration__/utils/index.d.ts.map +1 -0
  43. package/dist/__integration__/utils/index.js +11 -0
  44. package/dist/__integration__/utils/index.js.map +1 -0
  45. package/dist/__integration__/utils/trading.d.ts +169 -0
  46. package/dist/__integration__/utils/trading.d.ts.map +1 -0
  47. package/dist/__integration__/utils/trading.js +253 -0
  48. package/dist/__integration__/utils/trading.js.map +1 -0
  49. package/dist/__integration__/utils/wait.d.ts +52 -0
  50. package/dist/__integration__/utils/wait.d.ts.map +1 -0
  51. package/dist/__integration__/utils/wait.js +88 -0
  52. package/dist/__integration__/utils/wait.js.map +1 -0
  53. package/dist/abi/amm.d.ts +96 -0
  54. package/dist/abi/amm.d.ts.map +1 -0
  55. package/dist/abi/amm.js +70 -0
  56. package/dist/abi/amm.js.map +1 -0
  57. package/dist/abi/common.d.ts +329 -0
  58. package/dist/abi/common.d.ts.map +1 -0
  59. package/dist/abi/common.js +99 -0
  60. package/dist/abi/common.js.map +1 -0
  61. package/dist/abi/factory.d.ts +69 -0
  62. package/dist/abi/factory.d.ts.map +1 -0
  63. package/dist/abi/factory.js +29 -0
  64. package/dist/abi/factory.js.map +1 -0
  65. package/dist/abi/index.d.ts +14 -0
  66. package/dist/abi/index.d.ts.map +1 -0
  67. package/dist/abi/index.js +21 -0
  68. package/dist/abi/index.js.map +1 -0
  69. package/dist/abi/math-library.d.ts +113 -0
  70. package/dist/abi/math-library.d.ts.map +1 -0
  71. package/dist/abi/math-library.js +24 -0
  72. package/dist/abi/math-library.js.map +1 -0
  73. package/dist/abi/oracle.d.ts +63 -0
  74. package/dist/abi/oracle.d.ts.map +1 -0
  75. package/dist/abi/oracle.js +26 -0
  76. package/dist/abi/oracle.js.map +1 -0
  77. package/dist/collateral/compute.d.ts +316 -0
  78. package/dist/collateral/compute.d.ts.map +1 -0
  79. package/dist/collateral/compute.js +739 -0
  80. package/dist/collateral/compute.js.map +1 -0
  81. package/dist/collateral/index.d.ts +32 -0
  82. package/dist/collateral/index.d.ts.map +1 -0
  83. package/dist/collateral/index.js +35 -0
  84. package/dist/collateral/index.js.map +1 -0
  85. package/dist/collateral/verify.d.ts +97 -0
  86. package/dist/collateral/verify.d.ts.map +1 -0
  87. package/dist/collateral/verify.js +155 -0
  88. package/dist/collateral/verify.js.map +1 -0
  89. package/dist/contracts/amm-types.d.ts +311 -0
  90. package/dist/contracts/amm-types.d.ts.map +1 -0
  91. package/dist/contracts/amm-types.js +51 -0
  92. package/dist/contracts/amm-types.js.map +1 -0
  93. package/dist/contracts/amm.d.ts +417 -0
  94. package/dist/contracts/amm.d.ts.map +1 -0
  95. package/dist/contracts/amm.js +799 -0
  96. package/dist/contracts/amm.js.map +1 -0
  97. package/dist/contracts/base.d.ts +118 -0
  98. package/dist/contracts/base.d.ts.map +1 -0
  99. package/dist/contracts/base.js +143 -0
  100. package/dist/contracts/base.js.map +1 -0
  101. package/dist/contracts/factory.d.ts +120 -0
  102. package/dist/contracts/factory.d.ts.map +1 -0
  103. package/dist/contracts/factory.js +121 -0
  104. package/dist/contracts/factory.js.map +1 -0
  105. package/dist/contracts/index.d.ts +11 -0
  106. package/dist/contracts/index.d.ts.map +1 -0
  107. package/dist/contracts/index.js +11 -0
  108. package/dist/contracts/index.js.map +1 -0
  109. package/dist/contracts/math-library.d.ts +123 -0
  110. package/dist/contracts/math-library.d.ts.map +1 -0
  111. package/dist/contracts/math-library.js +233 -0
  112. package/dist/contracts/math-library.js.map +1 -0
  113. package/dist/contracts/oracle.d.ts +137 -0
  114. package/dist/contracts/oracle.d.ts.map +1 -0
  115. package/dist/contracts/oracle.js +220 -0
  116. package/dist/contracts/oracle.js.map +1 -0
  117. package/dist/index.d.ts +15 -0
  118. package/dist/index.d.ts.map +1 -0
  119. package/dist/index.js +22 -0
  120. package/dist/index.js.map +1 -0
  121. package/dist/providers/account.d.ts +46 -0
  122. package/dist/providers/account.d.ts.map +1 -0
  123. package/dist/providers/account.js +57 -0
  124. package/dist/providers/account.js.map +1 -0
  125. package/dist/providers/base.d.ts +75 -0
  126. package/dist/providers/base.d.ts.map +1 -0
  127. package/dist/providers/base.js +92 -0
  128. package/dist/providers/base.js.map +1 -0
  129. package/dist/providers/index.d.ts +8 -0
  130. package/dist/providers/index.d.ts.map +1 -0
  131. package/dist/providers/index.js +8 -0
  132. package/dist/providers/index.js.map +1 -0
  133. package/dist/sdk/client.d.ts +176 -0
  134. package/dist/sdk/client.d.ts.map +1 -0
  135. package/dist/sdk/client.js +273 -0
  136. package/dist/sdk/client.js.map +1 -0
  137. package/dist/sdk/index.d.ts +14 -0
  138. package/dist/sdk/index.d.ts.map +1 -0
  139. package/dist/sdk/index.js +15 -0
  140. package/dist/sdk/index.js.map +1 -0
  141. package/dist/sdk/internal/conversion.d.ts +104 -0
  142. package/dist/sdk/internal/conversion.d.ts.map +1 -0
  143. package/dist/sdk/internal/conversion.js +201 -0
  144. package/dist/sdk/internal/conversion.js.map +1 -0
  145. package/dist/sdk/internal/position-utils.d.ts +76 -0
  146. package/dist/sdk/internal/position-utils.d.ts.map +1 -0
  147. package/dist/sdk/internal/position-utils.js +131 -0
  148. package/dist/sdk/internal/position-utils.js.map +1 -0
  149. package/dist/sdk/internal/trade-builder.d.ts +112 -0
  150. package/dist/sdk/internal/trade-builder.d.ts.map +1 -0
  151. package/dist/sdk/internal/trade-builder.js +112 -0
  152. package/dist/sdk/internal/trade-builder.js.map +1 -0
  153. package/dist/sdk/market-ops.d.ts +194 -0
  154. package/dist/sdk/market-ops.d.ts.map +1 -0
  155. package/dist/sdk/market-ops.js +250 -0
  156. package/dist/sdk/market-ops.js.map +1 -0
  157. package/dist/sdk/position-ops.d.ts +121 -0
  158. package/dist/sdk/position-ops.d.ts.map +1 -0
  159. package/dist/sdk/position-ops.js +163 -0
  160. package/dist/sdk/position-ops.js.map +1 -0
  161. package/dist/sdk/simple-market.d.ts +168 -0
  162. package/dist/sdk/simple-market.d.ts.map +1 -0
  163. package/dist/sdk/simple-market.js +468 -0
  164. package/dist/sdk/simple-market.js.map +1 -0
  165. package/dist/sdk/simple-position.d.ts +77 -0
  166. package/dist/sdk/simple-position.d.ts.map +1 -0
  167. package/dist/sdk/simple-position.js +125 -0
  168. package/dist/sdk/simple-position.js.map +1 -0
  169. package/dist/sdk/simple-types.d.ts +155 -0
  170. package/dist/sdk/simple-types.d.ts.map +1 -0
  171. package/dist/sdk/simple-types.js +9 -0
  172. package/dist/sdk/simple-types.js.map +1 -0
  173. package/dist/types/index.d.ts +10 -0
  174. package/dist/types/index.d.ts.map +1 -0
  175. package/dist/types/index.js +11 -0
  176. package/dist/types/index.js.map +1 -0
  177. package/dist/types/normal-distribution.d.ts +125 -0
  178. package/dist/types/normal-distribution.d.ts.map +1 -0
  179. package/dist/types/normal-distribution.js +310 -0
  180. package/dist/types/normal-distribution.js.map +1 -0
  181. package/dist/types/normal-sqrt-hints-raw.d.ts +18 -0
  182. package/dist/types/normal-sqrt-hints-raw.d.ts.map +1 -0
  183. package/dist/types/normal-sqrt-hints-raw.js +9 -0
  184. package/dist/types/normal-sqrt-hints-raw.js.map +1 -0
  185. package/dist/types/sq128-raw.d.ts +69 -0
  186. package/dist/types/sq128-raw.d.ts.map +1 -0
  187. package/dist/types/sq128-raw.js +84 -0
  188. package/dist/types/sq128-raw.js.map +1 -0
  189. package/dist/types/sq128.d.ts +191 -0
  190. package/dist/types/sq128.d.ts.map +1 -0
  191. package/dist/types/sq128.js +611 -0
  192. package/dist/types/sq128.js.map +1 -0
  193. package/dist/utils/abi-encode.d.ts +187 -0
  194. package/dist/utils/abi-encode.d.ts.map +1 -0
  195. package/dist/utils/abi-encode.js +278 -0
  196. package/dist/utils/abi-encode.js.map +1 -0
  197. package/dist/utils/cumulative.d.ts +77 -0
  198. package/dist/utils/cumulative.d.ts.map +1 -0
  199. package/dist/utils/cumulative.js +102 -0
  200. package/dist/utils/cumulative.js.map +1 -0
  201. package/dist/utils/decimal-scale.d.ts +63 -0
  202. package/dist/utils/decimal-scale.d.ts.map +1 -0
  203. package/dist/utils/decimal-scale.js +108 -0
  204. package/dist/utils/decimal-scale.js.map +1 -0
  205. package/dist/utils/hints.d.ts +78 -0
  206. package/dist/utils/hints.d.ts.map +1 -0
  207. package/dist/utils/hints.js +118 -0
  208. package/dist/utils/hints.js.map +1 -0
  209. package/dist/utils/index.d.ts +12 -0
  210. package/dist/utils/index.d.ts.map +1 -0
  211. package/dist/utils/index.js +12 -0
  212. package/dist/utils/index.js.map +1 -0
  213. package/dist/utils/math.d.ts +44 -0
  214. package/dist/utils/math.d.ts.map +1 -0
  215. package/dist/utils/math.js +85 -0
  216. package/dist/utils/math.js.map +1 -0
  217. package/dist/utils/normalize.d.ts +47 -0
  218. package/dist/utils/normalize.d.ts.map +1 -0
  219. package/dist/utils/normalize.js +69 -0
  220. package/dist/utils/normalize.js.map +1 -0
  221. package/package.json +59 -0
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Test personas from predeployed devnet accounts.
3
+ *
4
+ * @module
5
+ */
6
+ import { Account, type RpcProvider } from 'starknet';
7
+ import { type DevnetConfig } from './devnet';
8
+ /**
9
+ * A test persona with account and metadata.
10
+ */
11
+ export interface TestPersona {
12
+ readonly name: string;
13
+ readonly account: Account;
14
+ readonly address: string;
15
+ readonly privateKey: string;
16
+ readonly publicKey: string;
17
+ readonly initialBalance: bigint;
18
+ }
19
+ /**
20
+ * All test personas for the integration tests.
21
+ */
22
+ export interface TestPersonas {
23
+ readonly deployer: TestPersona;
24
+ readonly traderA: TestPersona;
25
+ readonly traderB: TestPersona;
26
+ readonly lpProvider: TestPersona;
27
+ readonly hybrid: TestPersona;
28
+ readonly all: TestPersona[];
29
+ }
30
+ /**
31
+ * Fetches predeployed accounts from devnet and creates test personas.
32
+ */
33
+ export declare function getTestPersonas(provider: RpcProvider, config?: Partial<DevnetConfig>): Promise<TestPersonas>;
34
+ /**
35
+ * Gets all addresses from personas for balance tracking.
36
+ */
37
+ export declare function getAllAddresses(personas: TestPersonas): string[];
38
+ //# sourceMappingURL=accounts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../../../src/__integration__/setup/accounts.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAiB,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,CAAC;CAC7B;AAgBD;;GAEG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,WAAW,EACrB,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAC7B,OAAO,CAAC,YAAY,CAAC,CA0BvB;AAkBD;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,YAAY,GAAG,MAAM,EAAE,CAEhE"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Test personas from predeployed devnet accounts.
3
+ *
4
+ * @module
5
+ */
6
+ import { Account } from 'starknet';
7
+ import { callDevnetRpc } from './devnet';
8
+ const PERSONA_NAMES = ['deployer', 'traderA', 'traderB', 'lpProvider', 'hybrid'];
9
+ /**
10
+ * Fetches predeployed accounts from devnet and creates test personas.
11
+ */
12
+ export async function getTestPersonas(provider, config) {
13
+ const accounts = await callDevnetRpc('devnet_getPredeployedAccounts', { with_balance: true }, config);
14
+ if (accounts.length < 5) {
15
+ throw new Error(`Need at least 5 predeployed accounts, got ${accounts.length}. ` +
16
+ 'Start devnet with: starknet-devnet --seed 0 --accounts 10');
17
+ }
18
+ const personas = accounts
19
+ .slice(0, 5)
20
+ .map((acc, i) => createPersona(acc, PERSONA_NAMES[i], provider));
21
+ return {
22
+ deployer: personas[0],
23
+ traderA: personas[1],
24
+ traderB: personas[2],
25
+ lpProvider: personas[3],
26
+ hybrid: personas[4],
27
+ all: personas,
28
+ };
29
+ }
30
+ /**
31
+ * Creates a TestPersona from a predeployed account.
32
+ */
33
+ function createPersona(acc, name, provider) {
34
+ const account = new Account({ provider, address: acc.address, signer: acc.private_key });
35
+ return {
36
+ name,
37
+ account,
38
+ address: acc.address,
39
+ privateKey: acc.private_key,
40
+ publicKey: acc.public_key,
41
+ initialBalance: BigInt(acc.initial_balance),
42
+ };
43
+ }
44
+ /**
45
+ * Gets all addresses from personas for balance tracking.
46
+ */
47
+ export function getAllAddresses(personas) {
48
+ return personas.all.map((p) => p.address);
49
+ }
50
+ //# sourceMappingURL=accounts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accounts.js","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,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;IAEzF,OAAO;QACL,IAAI;QACJ,OAAO;QACP,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,UAAU,EAAE,GAAG,CAAC,WAAW;QAC3B,SAAS,EAAE,GAAG,CAAC,UAAU;QACzB,cAAc,EAAE,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC;KAC5C,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,QAAsB;IACpD,OAAO,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Contract artifact loading utilities.
3
+ *
4
+ * Loads Sierra (contract class) and CASM (compiled contract class) files
5
+ * for declaring contracts on devnet.
6
+ *
7
+ * @module
8
+ */
9
+ import type { CairoAssembly, CompiledContract } from 'starknet';
10
+ /**
11
+ * Paths to contract artifacts.
12
+ */
13
+ export interface ArtifactPaths {
14
+ readonly sierra: string;
15
+ readonly casm: string;
16
+ }
17
+ /**
18
+ * Loaded contract artifacts.
19
+ */
20
+ export interface ContractArtifact {
21
+ readonly name: string;
22
+ readonly sierra: CompiledContract;
23
+ readonly casm: CairoAssembly;
24
+ }
25
+ /**
26
+ * All loaded contract artifacts.
27
+ */
28
+ export interface LoadedArtifacts {
29
+ readonly amm: ContractArtifact;
30
+ readonly factory: ContractArtifact;
31
+ readonly mathLibrary: ContractArtifact;
32
+ readonly oracle: ContractArtifact;
33
+ }
34
+ /**
35
+ * Options for loading artifacts.
36
+ */
37
+ export interface LoadArtifactsOptions {
38
+ /** Directory containing Sierra (.contract_class.json) files */
39
+ readonly sierraDir?: string;
40
+ /** Directory containing CASM (.compiled_contract_class.json) files */
41
+ readonly casmDir?: string;
42
+ }
43
+ /**
44
+ * Loads all contract artifacts needed for integration tests.
45
+ */
46
+ export declare function loadAllArtifacts(options?: LoadArtifactsOptions): LoadedArtifacts;
47
+ /**
48
+ * Gets the ABI from a loaded Sierra artifact.
49
+ */
50
+ export declare function getAbiFromArtifact(artifact: ContractArtifact): readonly unknown[];
51
+ //# sourceMappingURL=artifacts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"artifacts.d.ts","sourceRoot":"","sources":["../../../src/__integration__/setup/artifacts.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEhE;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAClC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,GAAG,EAAE,gBAAgB,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC;IACnC,QAAQ,CAAC,WAAW,EAAE,gBAAgB,CAAC;IACvC,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;CACnC;AA6BD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,+DAA+D;IAC/D,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,sEAAsE;IACtE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AA8BD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,eAAe,CAOhF;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,SAAS,OAAO,EAAE,CAEjF"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Contract artifact loading utilities.
3
+ *
4
+ * Loads Sierra (contract class) and CASM (compiled contract class) files
5
+ * for declaring contracts on devnet.
6
+ *
7
+ * @module
8
+ */
9
+ import { existsSync, readFileSync } from 'node:fs';
10
+ import { join } from 'node:path';
11
+ // Default artifact directories
12
+ // const SDK_ARTIFACTS_DIR = resolve(__dirname, '../../artifacts');
13
+ // v0.5.1 contracts with Library Dispatcher pattern and optimized contract sizes
14
+ const CONTRACTS_DEV_DIR = '/private/tmp/the-situation-contracts-v0.5.1';
15
+ /**
16
+ * Contract artifact file mappings.
17
+ */
18
+ const ARTIFACT_FILES = {
19
+ amm: {
20
+ sierra: 'the_situation_normal_amm.contract_class.json',
21
+ casm: 'the_situation_normal_amm.compiled_contract_class.json',
22
+ },
23
+ factory: {
24
+ sierra: 'the_situation_normal_factory.contract_class.json',
25
+ casm: 'the_situation_normal_factory.compiled_contract_class.json',
26
+ },
27
+ mathLibrary: {
28
+ sierra: 'the_situation_normal_math_library.contract_class.json',
29
+ casm: 'the_situation_normal_math_library.compiled_contract_class.json',
30
+ },
31
+ oracle: {
32
+ sierra: 'the_situation_oracle.contract_class.json',
33
+ casm: 'the_situation_oracle.compiled_contract_class.json',
34
+ },
35
+ };
36
+ /**
37
+ * Loads a single contract artifact.
38
+ */
39
+ function loadArtifact(name, files, options) {
40
+ // Use the same directory for both Sierra and CASM to ensure they match
41
+ const sierraDir = options?.sierraDir ?? CONTRACTS_DEV_DIR;
42
+ const casmDir = options?.casmDir ?? CONTRACTS_DEV_DIR;
43
+ const sierraPath = join(sierraDir, files.sierra);
44
+ const casmPath = join(casmDir, files.casm);
45
+ if (!existsSync(sierraPath)) {
46
+ throw new Error(`Sierra artifact not found: ${sierraPath}`);
47
+ }
48
+ if (!existsSync(casmPath)) {
49
+ throw new Error(`CASM artifact not found: ${casmPath}`);
50
+ }
51
+ const sierra = JSON.parse(readFileSync(sierraPath, 'utf-8'));
52
+ const casm = JSON.parse(readFileSync(casmPath, 'utf-8'));
53
+ return { name, sierra, casm };
54
+ }
55
+ /**
56
+ * Loads all contract artifacts needed for integration tests.
57
+ */
58
+ export function loadAllArtifacts(options) {
59
+ return {
60
+ amm: loadArtifact('AMM', ARTIFACT_FILES.amm, options),
61
+ factory: loadArtifact('Factory', ARTIFACT_FILES.factory, options),
62
+ mathLibrary: loadArtifact('MathLibrary', ARTIFACT_FILES.mathLibrary, options),
63
+ oracle: loadArtifact('Oracle', ARTIFACT_FILES.oracle, options),
64
+ };
65
+ }
66
+ /**
67
+ * Gets the ABI from a loaded Sierra artifact.
68
+ */
69
+ export function getAbiFromArtifact(artifact) {
70
+ return artifact.sierra.abi;
71
+ }
72
+ //# sourceMappingURL=artifacts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"artifacts.js","sourceRoot":"","sources":["../../../src/__integration__/setup/artifacts.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AA8BjC,+BAA+B;AAC/B,mEAAmE;AACnE,gFAAgF;AAChF,MAAM,iBAAiB,GAAG,6CAA6C,CAAC;AAExE;;GAEG;AACH,MAAM,cAAc,GAAG;IACrB,GAAG,EAAE;QACH,MAAM,EAAE,8CAA8C;QACtD,IAAI,EAAE,uDAAuD;KAC9D;IACD,OAAO,EAAE;QACP,MAAM,EAAE,kDAAkD;QAC1D,IAAI,EAAE,2DAA2D;KAClE;IACD,WAAW,EAAE;QACX,MAAM,EAAE,uDAAuD;QAC/D,IAAI,EAAE,gEAAgE;KACvE;IACD,MAAM,EAAE;QACN,MAAM,EAAE,0CAA0C;QAClD,IAAI,EAAE,mDAAmD;KAC1D;CACO,CAAC;AAYX;;GAEG;AACH,SAAS,YAAY,CACnB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,OAAO,CAAC;KAC/D,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAA0B;IAC3D,OAAO,QAAQ,CAAC,MAAM,CAAC,GAAgB,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Contract declaration and deployment helpers.
3
+ *
4
+ * @module
5
+ */
6
+ import { type Abi, type Account } from 'starknet';
7
+ import type { ContractArtifact, LoadedArtifacts } from './artifacts';
8
+ import type { MarketFixture } from './fixtures';
9
+ /**
10
+ * Declared contract class hashes.
11
+ */
12
+ export interface DeclaredContracts {
13
+ readonly mathLibraryClassHash: string;
14
+ readonly factoryClassHash: string;
15
+ readonly ammClassHash: string;
16
+ readonly oracleClassHash: string;
17
+ }
18
+ /**
19
+ * Devnet predeployed token addresses.
20
+ */
21
+ export declare const DEVNET_ETH_ADDRESS = "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7";
22
+ export declare const DEVNET_STRK_ADDRESS = "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d";
23
+ /**
24
+ * Deployed contract addresses.
25
+ */
26
+ export interface DeployedContracts {
27
+ readonly factoryAddress: string;
28
+ readonly tokenAddress: string;
29
+ readonly marketAddress?: string;
30
+ }
31
+ /**
32
+ * Declares a single contract class.
33
+ *
34
+ * Returns the class hash, or existing hash if already declared.
35
+ */
36
+ export declare function declareContract(account: Account, artifact: ContractArtifact): Promise<string>;
37
+ /**
38
+ * Declares all contract classes needed for integration tests.
39
+ *
40
+ * Declarations are done sequentially to avoid nonce conflicts.
41
+ */
42
+ export declare function declareAllContracts(account: Account, artifacts: LoadedArtifacts): Promise<DeclaredContracts>;
43
+ /**
44
+ * Deploys the factory contract.
45
+ *
46
+ * In v0.5.0+, the factory requires both AMM and MathLibrary class hashes.
47
+ * The MathLibrary is used via Library Dispatcher pattern (no deployed contract).
48
+ */
49
+ export declare function deployFactory(deployer: Account, factoryClassHash: string, ammClassHash: string, mathClassHash: string): Promise<string>;
50
+ /**
51
+ * Approves an extension contract for use with markets deployed by the factory.
52
+ *
53
+ * Extensions must be approved by the factory owner before they can be used
54
+ * when deploying new markets.
55
+ *
56
+ * @param deployer - Account to execute the approval (must be factory owner)
57
+ * @param factoryAddress - Factory contract address
58
+ * @param extensionAddress - Extension contract address to approve
59
+ */
60
+ export declare function approveExtension(deployer: Account, factoryAddress: string, extensionAddress: string): Promise<void>;
61
+ /**
62
+ * Options for building deploy market calldata.
63
+ */
64
+ export interface DeployMarketOptions {
65
+ /** Salt for deterministic address calculation */
66
+ readonly salt?: bigint;
67
+ /** Extension contract address (Oracle) - defaults to '0x0' */
68
+ readonly extension?: string;
69
+ /** Extension call points bitmask (v0.5.0+) - defaults to 0 */
70
+ readonly extensionCallPoints?: number;
71
+ }
72
+ /**
73
+ * Builds deploy_market calldata for the factory using ABI-aware encoding.
74
+ */
75
+ export declare function buildDeployMarketCalldata(deployer: Account, collateralToken: string, fixture: MarketFixture, factoryAbi: Abi, options?: DeployMarketOptions): string[];
76
+ /**
77
+ * Deploys a market via the factory.
78
+ */
79
+ export declare function deployMarket(deployer: Account, factoryAddress: string, collateralToken: string, fixture: MarketFixture, factoryAbi: Abi, options?: DeployMarketOptions): Promise<string>;
80
+ /**
81
+ * Deploys the Oracle contract as an extension for a market.
82
+ *
83
+ * In v0.2.0, Oracle is AMM-agnostic and has no constructor parameters.
84
+ * This eliminates the circular dependency between Oracle and AMM.
85
+ *
86
+ * @param deployer - Account to deploy with
87
+ * @param oracleClassHash - Declared Oracle class hash
88
+ * @returns Promise resolving to Oracle contract address
89
+ */
90
+ export declare function deployOracle(deployer: Account, oracleClassHash: string): Promise<string>;
91
+ /**
92
+ * Full deployment flow for integration tests.
93
+ *
94
+ * Uses devnet's predeployed ETH token as collateral.
95
+ */
96
+ export declare function deployAll(deployer: Account, artifacts: LoadedArtifacts, fixture: MarketFixture, collateralToken?: string): Promise<{
97
+ declared: DeclaredContracts;
98
+ deployed: DeployedContracts;
99
+ }>;
100
+ /**
101
+ * Calculates the Oracle contract address before deployment.
102
+ *
103
+ * When deploying via `account.deployContract`, the deployer address is 0
104
+ * (contracts are deployed to a deterministic address based on class hash,
105
+ * salt, and constructor calldata).
106
+ *
107
+ * In v0.2.0, Oracle has no constructor parameters (AMM-agnostic).
108
+ *
109
+ * @param oracleClassHash - Declared Oracle class hash
110
+ * @param salt - Salt for deterministic address
111
+ * @returns Calculated Oracle contract address
112
+ */
113
+ export declare function calculateOracleAddress(oracleClassHash: string, salt: bigint): string;
114
+ /**
115
+ * Builds AMM constructor calldata for address calculation.
116
+ *
117
+ * This is the raw constructor calldata passed to the AMM contract,
118
+ * NOT the deploy_market calldata passed to the factory.
119
+ *
120
+ * @param owner - Market owner address
121
+ * @param admin - Market admin address
122
+ * @param collateralToken - Collateral token address
123
+ * @param fixture - Market configuration fixture
124
+ * @param factoryAddress - Factory contract address
125
+ * @param extension - Extension contract address (Oracle)
126
+ * @returns Compiled constructor calldata as string array
127
+ */
128
+ export declare function buildAmmConstructorCalldata(owner: string, admin: string, collateralToken: string, fixture: MarketFixture, factoryAddress: string, extension: string): string[];
129
+ /**
130
+ * Calculates the Market address before deployment via factory.
131
+ *
132
+ * When deploying via factory's `deploy_syscall`, the deployer is the factory address.
133
+ *
134
+ * @param factoryAddress - Factory contract address
135
+ * @param ammClassHash - Declared AMM class hash
136
+ * @param ammConstructorCalldata - AMM constructor calldata
137
+ * @param salt - Salt for deterministic address
138
+ * @returns Calculated Market contract address
139
+ */
140
+ export declare function calculateMarketAddress(factoryAddress: string, ammClassHash: string, ammConstructorCalldata: string[], salt: bigint): string;
141
+ /**
142
+ * Deploys Oracle with specific salt for deterministic address.
143
+ *
144
+ * In v0.2.0, Oracle has no constructor parameters (AMM-agnostic).
145
+ *
146
+ * @param deployer - Account to deploy with
147
+ * @param oracleClassHash - Declared Oracle class hash
148
+ * @param salt - Salt for deterministic address (must match what was used in calculateOracleAddress)
149
+ * @returns Promise resolving to Oracle contract address
150
+ */
151
+ export declare function deployOracleWithSalt(deployer: Account, oracleClassHash: string, salt: bigint): Promise<string>;
152
+ //# sourceMappingURL=deploy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/__integration__/setup/deploy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,OAAO,EAAkB,MAAM,UAAU,CAAC;AAGlE,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;CAClC;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,uEACuC,CAAC;AACvE,eAAO,MAAM,mBAAmB,uEACsC,CAAC;AAEvE;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CACjC;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,MAAM,CAAC,CAqBjB;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,eAAe,GACzB,OAAO,CAAC,iBAAiB,CAAC,CAa5B;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,O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