@stryke-xyz/premarket-sdk 1.0.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 (189) hide show
  1. package/dist/abi/AggregationRouterV6.abi.json +1186 -0
  2. package/dist/abi/NativeOrderFactory.abi.json +291 -0
  3. package/dist/abi/NativeOrderImpl.abi.json +381 -0
  4. package/dist/abi/limitOrderProtocol.json +63 -0
  5. package/dist/address.d.ts +13 -0
  6. package/dist/address.js +32 -0
  7. package/dist/api/filler.d.ts +109 -0
  8. package/dist/api/filler.js +289 -0
  9. package/dist/api/index.d.ts +3 -0
  10. package/dist/api/index.js +3 -0
  11. package/dist/api/order-helper.d.ts +59 -0
  12. package/dist/api/order-helper.js +112 -0
  13. package/dist/api/orderbook-api.d.ts +36 -0
  14. package/dist/api/orderbook-api.js +69 -0
  15. package/dist/bps.d.ts +35 -0
  16. package/dist/bps.js +52 -0
  17. package/dist/config/chains.d.ts +50 -0
  18. package/dist/config/chains.js +21 -0
  19. package/dist/config/index.d.ts +25 -0
  20. package/dist/config/index.js +103 -0
  21. package/dist/config/markets.d.ts +53 -0
  22. package/dist/config/markets.js +125 -0
  23. package/dist/constants.d.ts +4 -0
  24. package/dist/constants.js +30 -0
  25. package/dist/index.d.ts +19 -0
  26. package/dist/index.js +21 -0
  27. package/dist/limit-order/amounts.d.ts +14 -0
  28. package/dist/limit-order/amounts.js +19 -0
  29. package/dist/limit-order/eip712/domain.d.ts +10 -0
  30. package/dist/limit-order/eip712/domain.js +18 -0
  31. package/dist/limit-order/eip712/eip712.types.d.ts +23 -0
  32. package/dist/limit-order/eip712/eip712.types.js +1 -0
  33. package/dist/limit-order/eip712/index.d.ts +3 -0
  34. package/dist/limit-order/eip712/index.js +3 -0
  35. package/dist/limit-order/eip712/order-typed-data-builder.d.ts +6 -0
  36. package/dist/limit-order/eip712/order-typed-data-builder.js +25 -0
  37. package/dist/limit-order/extensions/extension-builder.d.ts +35 -0
  38. package/dist/limit-order/extensions/extension-builder.js +83 -0
  39. package/dist/limit-order/extensions/extension.d.ts +45 -0
  40. package/dist/limit-order/extensions/extension.js +108 -0
  41. package/dist/limit-order/extensions/extension.spec.d.ts +1 -0
  42. package/dist/limit-order/extensions/extension.spec.js +17 -0
  43. package/dist/limit-order/extensions/fee-taker/errors.d.ts +2 -0
  44. package/dist/limit-order/extensions/fee-taker/errors.js +2 -0
  45. package/dist/limit-order/extensions/fee-taker/fee-calculator.d.ts +40 -0
  46. package/dist/limit-order/extensions/fee-taker/fee-calculator.js +83 -0
  47. package/dist/limit-order/extensions/fee-taker/fee-calculator.spec.d.ts +1 -0
  48. package/dist/limit-order/extensions/fee-taker/fee-calculator.spec.js +14 -0
  49. package/dist/limit-order/extensions/fee-taker/fee-taker.extension.d.ts +130 -0
  50. package/dist/limit-order/extensions/fee-taker/fee-taker.extension.js +249 -0
  51. package/dist/limit-order/extensions/fee-taker/fee-taker.extension.spec.d.ts +1 -0
  52. package/dist/limit-order/extensions/fee-taker/fee-taker.extension.spec.js +72 -0
  53. package/dist/limit-order/extensions/fee-taker/fees.d.ts +19 -0
  54. package/dist/limit-order/extensions/fee-taker/fees.js +36 -0
  55. package/dist/limit-order/extensions/fee-taker/index.d.ts +7 -0
  56. package/dist/limit-order/extensions/fee-taker/index.js +7 -0
  57. package/dist/limit-order/extensions/fee-taker/integrator-fee.d.ts +13 -0
  58. package/dist/limit-order/extensions/fee-taker/integrator-fee.js +28 -0
  59. package/dist/limit-order/extensions/fee-taker/resolver-fee.d.ts +19 -0
  60. package/dist/limit-order/extensions/fee-taker/resolver-fee.js +28 -0
  61. package/dist/limit-order/extensions/fee-taker/types.d.ts +4 -0
  62. package/dist/limit-order/extensions/fee-taker/types.js +1 -0
  63. package/dist/limit-order/extensions/fee-taker/whitelist-half-address.d.ts +18 -0
  64. package/dist/limit-order/extensions/fee-taker/whitelist-half-address.js +26 -0
  65. package/dist/limit-order/extensions/index.d.ts +3 -0
  66. package/dist/limit-order/extensions/index.js +3 -0
  67. package/dist/limit-order/index.d.ts +10 -0
  68. package/dist/limit-order/index.js +10 -0
  69. package/dist/limit-order/interaction.d.ts +16 -0
  70. package/dist/limit-order/interaction.js +25 -0
  71. package/dist/limit-order/interaction.spec.d.ts +1 -0
  72. package/dist/limit-order/interaction.spec.js +8 -0
  73. package/dist/limit-order/limit-order-with-fee.d.ts +59 -0
  74. package/dist/limit-order/limit-order-with-fee.js +94 -0
  75. package/dist/limit-order/limit-order-with-fee.spec.d.ts +1 -0
  76. package/dist/limit-order/limit-order-with-fee.spec.js +31 -0
  77. package/dist/limit-order/limit-order.d.ts +63 -0
  78. package/dist/limit-order/limit-order.js +211 -0
  79. package/dist/limit-order/limit-order.spec.d.ts +1 -0
  80. package/dist/limit-order/limit-order.spec.js +103 -0
  81. package/dist/limit-order/maker-traits.d.ts +200 -0
  82. package/dist/limit-order/maker-traits.js +309 -0
  83. package/dist/limit-order/maker-traits.spec.d.ts +1 -0
  84. package/dist/limit-order/maker-traits.spec.js +102 -0
  85. package/dist/limit-order/source-track.d.ts +1 -0
  86. package/dist/limit-order/source-track.js +22 -0
  87. package/dist/limit-order/taker-traits.d.ts +141 -0
  88. package/dist/limit-order/taker-traits.js +207 -0
  89. package/dist/limit-order/types.d.ts +24 -0
  90. package/dist/limit-order/types.js +1 -0
  91. package/dist/limit-order/verification.d.ts +16 -0
  92. package/dist/limit-order/verification.js +108 -0
  93. package/dist/limit-order-contract/index.d.ts +4 -0
  94. package/dist/limit-order-contract/index.js +4 -0
  95. package/dist/limit-order-contract/limit-order-contract.d.ts +34 -0
  96. package/dist/limit-order-contract/limit-order-contract.js +79 -0
  97. package/dist/limit-order-contract/native-order-factory.d.ts +10 -0
  98. package/dist/limit-order-contract/native-order-factory.js +22 -0
  99. package/dist/limit-order-contract/native-order-impl.d.ts +10 -0
  100. package/dist/limit-order-contract/native-order-impl.js +24 -0
  101. package/dist/limit-order-contract/proxy-factory.d.ts +20 -0
  102. package/dist/limit-order-contract/proxy-factory.js +32 -0
  103. package/dist/limit-order-contract/proxy-factory.spec.d.ts +1 -0
  104. package/dist/limit-order-contract/proxy-factory.spec.js +16 -0
  105. package/dist/limit-order-contract/types.d.ts +6 -0
  106. package/dist/limit-order-contract/types.js +1 -0
  107. package/dist/ponder/client/index.d.ts +23 -0
  108. package/dist/ponder/client/index.js +44 -0
  109. package/dist/ponder/client/queries/markets.d.ts +30 -0
  110. package/dist/ponder/client/queries/markets.js +200 -0
  111. package/dist/ponder/client/queries/positions.d.ts +13 -0
  112. package/dist/ponder/client/queries/positions.js +406 -0
  113. package/dist/ponder/client/types/history.d.ts +94 -0
  114. package/dist/ponder/client/types/history.js +1 -0
  115. package/dist/ponder/client/types/index.d.ts +5 -0
  116. package/dist/ponder/client/types/index.js +5 -0
  117. package/dist/ponder/client/types/market.d.ts +45 -0
  118. package/dist/ponder/client/types/market.js +1 -0
  119. package/dist/ponder/client/types/position.d.ts +32 -0
  120. package/dist/ponder/client/types/position.js +1 -0
  121. package/dist/ponder/client/types/serializers.d.ts +57 -0
  122. package/dist/ponder/client/types/serializers.js +248 -0
  123. package/dist/ponder/client/types/user.d.ts +5 -0
  124. package/dist/ponder/client/types/user.js +1 -0
  125. package/dist/ponder/client/utils.d.ts +1 -0
  126. package/dist/ponder/client/utils.js +32 -0
  127. package/dist/ponder/generated/index.d.ts +18 -0
  128. package/dist/ponder/generated/index.js +20 -0
  129. package/dist/ponder/generated/runtime/batcher.d.ts +105 -0
  130. package/dist/ponder/generated/runtime/batcher.js +188 -0
  131. package/dist/ponder/generated/runtime/createClient.d.ts +17 -0
  132. package/dist/ponder/generated/runtime/createClient.js +24 -0
  133. package/dist/ponder/generated/runtime/error.d.ts +18 -0
  134. package/dist/ponder/generated/runtime/error.js +15 -0
  135. package/dist/ponder/generated/runtime/fetcher.d.ts +10 -0
  136. package/dist/ponder/generated/runtime/fetcher.js +67 -0
  137. package/dist/ponder/generated/runtime/generateGraphqlOperation.d.ts +30 -0
  138. package/dist/ponder/generated/runtime/generateGraphqlOperation.js +128 -0
  139. package/dist/ponder/generated/runtime/index.d.ts +11 -0
  140. package/dist/ponder/generated/runtime/index.js +10 -0
  141. package/dist/ponder/generated/runtime/linkTypeMap.d.ts +9 -0
  142. package/dist/ponder/generated/runtime/linkTypeMap.js +83 -0
  143. package/dist/ponder/generated/runtime/typeSelection.d.ts +28 -0
  144. package/dist/ponder/generated/runtime/typeSelection.js +3 -0
  145. package/dist/ponder/generated/runtime/types.d.ts +55 -0
  146. package/dist/ponder/generated/runtime/types.js +2 -0
  147. package/dist/ponder/generated/schema.d.ts +3026 -0
  148. package/dist/ponder/generated/schema.js +222 -0
  149. package/dist/ponder/generated/types.d.ts +2393 -0
  150. package/dist/ponder/generated/types.js +6915 -0
  151. package/dist/ponder/index.d.ts +2 -0
  152. package/dist/ponder/index.js +2 -0
  153. package/dist/ponder/types.d.ts +3 -0
  154. package/dist/ponder/types.js +1 -0
  155. package/dist/rfq-order/index.d.ts +1 -0
  156. package/dist/rfq-order/index.js +1 -0
  157. package/dist/rfq-order/rfq-order.d.ts +21 -0
  158. package/dist/rfq-order/rfq-order.js +22 -0
  159. package/dist/rfq-order/rfq-order.spec.d.ts +1 -0
  160. package/dist/rfq-order/rfq-order.spec.js +27 -0
  161. package/dist/shared/index.d.ts +2 -0
  162. package/dist/shared/index.js +2 -0
  163. package/dist/shared/types.d.ts +79 -0
  164. package/dist/shared/types.js +12 -0
  165. package/dist/shared/utils.d.ts +7 -0
  166. package/dist/shared/utils.js +19 -0
  167. package/dist/sync/clients/balance-client.d.ts +41 -0
  168. package/dist/sync/clients/balance-client.js +139 -0
  169. package/dist/sync/clients/base-client.d.ts +47 -0
  170. package/dist/sync/clients/base-client.js +154 -0
  171. package/dist/sync/clients/order-client.d.ts +18 -0
  172. package/dist/sync/clients/order-client.js +151 -0
  173. package/dist/sync/index.d.ts +5 -0
  174. package/dist/sync/index.js +3 -0
  175. package/dist/sync/redis-ws-client.d.ts +18 -0
  176. package/dist/sync/redis-ws-client.js +88 -0
  177. package/dist/sync/types.d.ts +20 -0
  178. package/dist/sync/types.js +1 -0
  179. package/dist/utils/mul-div.d.ts +5 -0
  180. package/dist/utils/mul-div.js +13 -0
  181. package/dist/utils/orderUtils.d.ts +19 -0
  182. package/dist/utils/orderUtils.js +51 -0
  183. package/dist/utils/rand-bigint.d.ts +1 -0
  184. package/dist/utils/rand-bigint.js +13 -0
  185. package/dist/utils/rand-bigint.spec.d.ts +1 -0
  186. package/dist/utils/rand-bigint.spec.js +11 -0
  187. package/dist/validations.d.ts +1 -0
  188. package/dist/validations.js +3 -0
  189. package/package.json +60 -0
@@ -0,0 +1,112 @@
1
+ import { pad, toHex } from "viem";
2
+ import { LimitOrder, MakerTraits, ExtensionBuilder } from "../limit-order";
3
+ import { Address as OneInchAddress } from "../address";
4
+ import { randBigInt } from "../utils/rand-bigint";
5
+ import { buildMakerAssetSuffix } from "../utils/orderUtils";
6
+ import { calculateOptionTokenId as sharedCalculateOptionTokenId } from "../shared/utils.js";
7
+ const UINT_40_MAX = (1n << 40n) - 1n;
8
+ export class OrderHelper {
9
+ constructor(config) {
10
+ this.config = config;
11
+ }
12
+ /**
13
+ * Calculate option token ID from option parameters
14
+ * Delegates to shared utility function
15
+ */
16
+ calculateOptionTokenId(option) {
17
+ return sharedCalculateOptionTokenId(option);
18
+ }
19
+ /**
20
+ * Build sell options order
21
+ */
22
+ buildSellOptionsOrder(params) {
23
+ const optionTokenId = this.calculateOptionTokenId(params.option);
24
+ const makerAssetSuffix = buildMakerAssetSuffix(this.config.optionTokenFactoryAddress, optionTokenId);
25
+ const extension = new ExtensionBuilder()
26
+ .withMakerAssetSuffix(makerAssetSuffix)
27
+ .build();
28
+ const makerTraits = MakerTraits.default()
29
+ .withNonce(randBigInt(UINT_40_MAX))
30
+ .withExtension()
31
+ .allowPartialFills()
32
+ .allowMultipleFills();
33
+ if (params.expiresAt) {
34
+ makerTraits.withExpiration(params.expiresAt);
35
+ }
36
+ const order = new LimitOrder({
37
+ makerAsset: new OneInchAddress(params.makerProxyAddress),
38
+ takerAsset: new OneInchAddress(params.stableToken),
39
+ makingAmount: BigInt(params.optionAmount),
40
+ takingAmount: BigInt(params.stableAmount),
41
+ maker: new OneInchAddress(params.maker),
42
+ }, makerTraits, extension);
43
+ return {
44
+ order,
45
+ optionTokenId,
46
+ calldata: order.toCalldata(),
47
+ extensionEncoded: extension.encode(),
48
+ };
49
+ }
50
+ /**
51
+ * Build buy options order
52
+ * For buy orders:
53
+ * - Maker gives: USDC (ERC20) - no suffix needed
54
+ * - Maker receives: Options (ERC6909) - needs takerAssetSuffix
55
+ */
56
+ buildBuyOptionsOrder(params) {
57
+ const optionTokenId = this.calculateOptionTokenId(params.option);
58
+ // For buy orders, the taker asset is ERC6909 options, so we use takerAssetSuffix
59
+ const takerAssetSuffix = buildMakerAssetSuffix(this.config.optionTokenFactoryAddress, optionTokenId);
60
+ const extension = new ExtensionBuilder()
61
+ .withTakerAssetSuffix(takerAssetSuffix)
62
+ .build();
63
+ const makerTraits = MakerTraits.default()
64
+ .withNonce(randBigInt(UINT_40_MAX))
65
+ .withExtension()
66
+ .allowPartialFills()
67
+ .allowMultipleFills();
68
+ if (params.expiresAt) {
69
+ makerTraits.withExpiration(params.expiresAt);
70
+ }
71
+ const order = new LimitOrder({
72
+ makerAsset: new OneInchAddress(params.stableToken),
73
+ takerAsset: new OneInchAddress(params.makerProxyAddress),
74
+ makingAmount: BigInt(params.stableAmount),
75
+ takingAmount: BigInt(params.optionAmount),
76
+ maker: new OneInchAddress(params.maker),
77
+ }, makerTraits, extension);
78
+ return {
79
+ order,
80
+ optionTokenId,
81
+ calldata: order.toCalldata(),
82
+ extensionEncoded: extension.encode(),
83
+ };
84
+ }
85
+ /**
86
+ * Sign an order with wallet client
87
+ */
88
+ async signOrder(order, walletClient) {
89
+ const account = walletClient.account;
90
+ if (!account)
91
+ throw new Error("No account connected");
92
+ const typedData = order.getTypedData(this.config.chainId);
93
+ const signature = await walletClient.signTypedData({
94
+ account,
95
+ domain: typedData.domain,
96
+ types: { Order: typedData.types.Order },
97
+ primaryType: "Order",
98
+ message: typedData.message,
99
+ });
100
+ // Convert to r, vs format
101
+ const rHex = signature.slice(0, 66);
102
+ const r = pad(rHex, { size: 32 });
103
+ const sHex = `0x${signature.slice(66, 130)}`;
104
+ const vHex = signature.slice(130, 132);
105
+ const v = parseInt(vHex, 16);
106
+ const sBigInt = BigInt(sHex);
107
+ const vBit = v === 28 ? BigInt(1) << BigInt(255) : BigInt(0);
108
+ const vsBigInt = vBit | sBigInt;
109
+ const vs = pad(toHex(vsBigInt), { size: 32 });
110
+ return { r, vs };
111
+ }
112
+ }
@@ -0,0 +1,36 @@
1
+ import type { StoredOrder, CreateOrderParams, Option } from "../shared/types.js";
2
+ export type { StoredOrder, CreateOrderParams, Option };
3
+ export interface OrderbookApiConfig {
4
+ baseUrl: string;
5
+ }
6
+ /**
7
+ * Orderbook API client
8
+ */
9
+ export declare class OrderbookApi {
10
+ private readonly config;
11
+ constructor(config: OrderbookApiConfig);
12
+ /**
13
+ * Create a new order
14
+ */
15
+ createOrder(params: CreateOrderParams): Promise<StoredOrder>;
16
+ /**
17
+ * Get order by hash
18
+ */
19
+ getOrder(orderHash: string): Promise<StoredOrder | null>;
20
+ /**
21
+ * Get orders for a market
22
+ */
23
+ getOrdersByMarket(marketId: string): Promise<StoredOrder[]>;
24
+ /**
25
+ * Get orders by option token ID
26
+ */
27
+ getOrdersByOptionId(optionTokenId: string): Promise<StoredOrder[]>;
28
+ /**
29
+ * Get active orders
30
+ */
31
+ getActiveOrders(): Promise<StoredOrder[]>;
32
+ /**
33
+ * Cancel order
34
+ */
35
+ cancelOrder(orderHash: string, maker: string): Promise<void>;
36
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Orderbook API client
3
+ */
4
+ export class OrderbookApi {
5
+ constructor(config) {
6
+ this.config = config;
7
+ }
8
+ /**
9
+ * Create a new order
10
+ */
11
+ async createOrder(params) {
12
+ const response = await fetch(`${this.config.baseUrl}/api/orders`, {
13
+ method: "POST",
14
+ headers: { "Content-Type": "application/json" },
15
+ body: JSON.stringify(params),
16
+ });
17
+ const data = await response.json();
18
+ if (!data.success) {
19
+ throw new Error(data.error || "Failed to create order");
20
+ }
21
+ return data.data;
22
+ }
23
+ /**
24
+ * Get order by hash
25
+ */
26
+ async getOrder(orderHash) {
27
+ const response = await fetch(`${this.config.baseUrl}/api/orders/${orderHash}`);
28
+ const data = await response.json();
29
+ return data.success ? data.data : null;
30
+ }
31
+ /**
32
+ * Get orders for a market
33
+ */
34
+ async getOrdersByMarket(marketId) {
35
+ const response = await fetch(`${this.config.baseUrl}/api/orders?marketId=${marketId}`);
36
+ const data = await response.json();
37
+ return data.success ? data.data.orders : [];
38
+ }
39
+ /**
40
+ * Get orders by option token ID
41
+ */
42
+ async getOrdersByOptionId(optionTokenId) {
43
+ const response = await fetch(`${this.config.baseUrl}/api/orders?optionTokenId=${optionTokenId}`);
44
+ const data = await response.json();
45
+ return data.success ? data.data.orders : [];
46
+ }
47
+ /**
48
+ * Get active orders
49
+ */
50
+ async getActiveOrders() {
51
+ const response = await fetch(`${this.config.baseUrl}/api/orders/active`);
52
+ const data = await response.json();
53
+ return data.success ? data.data.orders : [];
54
+ }
55
+ /**
56
+ * Cancel order
57
+ */
58
+ async cancelOrder(orderHash, maker) {
59
+ const response = await fetch(`${this.config.baseUrl}/api/orders/${orderHash}/cancel`, {
60
+ method: "POST",
61
+ headers: { "Content-Type": "application/json" },
62
+ body: JSON.stringify({ maker }),
63
+ });
64
+ const data = await response.json();
65
+ if (!data.success) {
66
+ throw new Error(data.error || "Failed to cancel order");
67
+ }
68
+ }
69
+ }
package/dist/bps.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Basis point in range [0, 100]%
3
+ *
4
+ * 1bps = 0.01%
5
+ */
6
+ export declare class Bps {
7
+ readonly value: bigint;
8
+ static ZERO: Bps;
9
+ constructor(value: bigint);
10
+ /**
11
+ * Create BPS from percent value.
12
+ * If `value` has precision more than 1bps (with accounting to `base`), it will be rounded down
13
+ * @param val
14
+ * @param base what represents 100%
15
+ */
16
+ static fromPercent(val: number, base?: bigint): Bps;
17
+ /**
18
+ * Create BPS from fraction value.
19
+ * If `value` has precision more than 1bps (with accounting to `base`), it will be rounded down
20
+ * @param val
21
+ * @param base what represents 100%
22
+ */
23
+ static fromFraction(val: number, base?: bigint): Bps;
24
+ equal(other: Bps): boolean;
25
+ isZero(): boolean;
26
+ /**
27
+ * @param base what represents 100%
28
+ */
29
+ toPercent(base?: bigint): number;
30
+ /**
31
+ * @param base what represents 100%
32
+ */
33
+ toFraction(base?: bigint): number;
34
+ toString(): string;
35
+ }
package/dist/bps.js ADDED
@@ -0,0 +1,52 @@
1
+ import assert from 'assert';
2
+ /**
3
+ * Basis point in range [0, 100]%
4
+ *
5
+ * 1bps = 0.01%
6
+ */
7
+ export class Bps {
8
+ constructor(value) {
9
+ this.value = value;
10
+ assert(value >= 0 && value <= 10000, `invalid bps ${value}`);
11
+ }
12
+ /**
13
+ * Create BPS from percent value.
14
+ * If `value` has precision more than 1bps (with accounting to `base`), it will be rounded down
15
+ * @param val
16
+ * @param base what represents 100%
17
+ */
18
+ static fromPercent(val, base = 1n) {
19
+ return new Bps(BigInt(100 * val) / base);
20
+ }
21
+ /**
22
+ * Create BPS from fraction value.
23
+ * If `value` has precision more than 1bps (with accounting to `base`), it will be rounded down
24
+ * @param val
25
+ * @param base what represents 100%
26
+ */
27
+ static fromFraction(val, base = 1n) {
28
+ return new Bps(BigInt(10000 * val) / base);
29
+ }
30
+ equal(other) {
31
+ return this.value === other.value;
32
+ }
33
+ isZero() {
34
+ return this.value === 0n;
35
+ }
36
+ /**
37
+ * @param base what represents 100%
38
+ */
39
+ toPercent(base = 1n) {
40
+ return Number(this.value * base) / 100;
41
+ }
42
+ /**
43
+ * @param base what represents 100%
44
+ */
45
+ toFraction(base = 1n) {
46
+ return Number(this.value * base) / 10000;
47
+ }
48
+ toString() {
49
+ return this.value.toString();
50
+ }
51
+ }
52
+ Bps.ZERO = new Bps(0n);
@@ -0,0 +1,50 @@
1
+ export declare const megaETHTestnet: {
2
+ blockExplorers?: {
3
+ [key: string]: {
4
+ name: string;
5
+ url: string;
6
+ apiUrl?: string | undefined;
7
+ };
8
+ default: {
9
+ name: string;
10
+ url: string;
11
+ apiUrl?: string | undefined;
12
+ };
13
+ } | undefined | undefined;
14
+ blockTime?: number | undefined | undefined;
15
+ contracts: {
16
+ readonly multicall3: {
17
+ readonly address: "0xca11bde05977b3631167028862be2a173976ca11";
18
+ readonly blockCreated: 4549927;
19
+ };
20
+ };
21
+ ensTlds?: readonly string[] | undefined;
22
+ id: 6343;
23
+ name: "MegaETH Testnet";
24
+ nativeCurrency: {
25
+ readonly name: "Ethereum";
26
+ readonly symbol: "ETH";
27
+ readonly decimals: 18;
28
+ };
29
+ experimental_preconfirmationTime?: number | undefined | undefined;
30
+ rpcUrls: {
31
+ readonly default: {
32
+ readonly http: readonly ["https://carrot.megaeth.com/rpc"];
33
+ };
34
+ };
35
+ sourceId?: number | undefined | undefined;
36
+ testnet?: boolean | undefined | undefined;
37
+ custom?: Record<string, unknown> | undefined;
38
+ extendSchema?: Record<string, unknown> | undefined;
39
+ fees?: import("viem").ChainFees<undefined> | undefined;
40
+ formatters?: undefined;
41
+ prepareTransactionRequest?: ((args: import("viem").PrepareTransactionRequestParameters, options: {
42
+ phase: "beforeFillTransaction" | "beforeFillParameters" | "afterFillParameters";
43
+ }) => Promise<import("viem").PrepareTransactionRequestParameters>) | [fn: ((args: import("viem").PrepareTransactionRequestParameters, options: {
44
+ phase: "beforeFillTransaction" | "beforeFillParameters" | "afterFillParameters";
45
+ }) => Promise<import("viem").PrepareTransactionRequestParameters>) | undefined, options: {
46
+ runAt: readonly ("beforeFillTransaction" | "beforeFillParameters" | "afterFillParameters")[];
47
+ }] | undefined;
48
+ serializers?: import("viem").ChainSerializers<undefined, import("viem").TransactionSerializable> | undefined;
49
+ verifyHash?: ((client: import("viem").Client, parameters: import("viem").VerifyHashActionParameters) => Promise<import("viem").VerifyHashActionReturnType>) | undefined;
50
+ };
@@ -0,0 +1,21 @@
1
+ import { defineChain as defineChainViem } from "viem";
2
+ export const megaETHTestnet = defineChainViem({
3
+ id: 6343,
4
+ name: "MegaETH Testnet",
5
+ nativeCurrency: {
6
+ name: "Ethereum",
7
+ symbol: "ETH",
8
+ decimals: 18,
9
+ },
10
+ rpcUrls: {
11
+ default: {
12
+ http: ["https://carrot.megaeth.com/rpc"],
13
+ },
14
+ },
15
+ contracts: {
16
+ multicall3: {
17
+ address: '0xca11bde05977b3631167028862be2a173976ca11',
18
+ blockCreated: 4549927,
19
+ },
20
+ },
21
+ });
@@ -0,0 +1,25 @@
1
+ import { Chain } from "viem/chains";
2
+ import { SUPPORTED_CHAINS } from "./markets";
3
+ export interface Token {
4
+ name: string;
5
+ symbol: string;
6
+ address: `0x${string}`;
7
+ decimals: number;
8
+ logoURI?: string;
9
+ }
10
+ export declare const CHAIN_ID_TO_CHAIN: Record<number, Chain>;
11
+ export declare const ZERO_ADDRESS: "0x0000000000000000000000000000000000000000";
12
+ export declare const PERMIT2_ADDRESS: Record<SUPPORTED_CHAINS, `0x${string}`>;
13
+ export declare const WETH: Record<SUPPORTED_CHAINS, Token>;
14
+ export declare const TOKEN1: Record<SUPPORTED_CHAINS, Token>;
15
+ export declare const TOKEN2: Record<SUPPORTED_CHAINS, Token>;
16
+ export declare const USDC: Record<SUPPORTED_CHAINS, Token>;
17
+ export declare const LIMIT_ORDER_PROTOCOL: Record<SUPPORTED_CHAINS, `0x${string}`>;
18
+ export declare const COLLATERAL_TOKEN_FACTORY: Record<SUPPORTED_CHAINS, `0x${string}`>;
19
+ export declare const OPTION_TOKEN_FACTORY: Record<SUPPORTED_CHAINS, `0x${string}`>;
20
+ export declare const PRE_MARKET_OPTIONS_STRATEGY: Record<SUPPORTED_CHAINS, `0x${string}`>;
21
+ export declare const OPTION_MARKET: Record<SUPPORTED_CHAINS, `0x${string}`>;
22
+ export declare const ERC6909_PROXY: Record<SUPPORTED_CHAINS, `0x${string}`>;
23
+ export declare const ENTRY_POINT: Record<SUPPORTED_CHAINS, `0x${string}`>;
24
+ export declare const MOCK_PAYMASTER: Record<SUPPORTED_CHAINS, `0x${string}`>;
25
+ export declare const SIMPLE_ACCOUNT_FACTORY: Record<SUPPORTED_CHAINS, `0x${string}`>;
@@ -0,0 +1,103 @@
1
+ import { hardhat } from "viem/chains";
2
+ import { megaETHTestnet } from "./chains";
3
+ export const CHAIN_ID_TO_CHAIN = {
4
+ 31337: hardhat,
5
+ 6343: megaETHTestnet,
6
+ };
7
+ export const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
8
+ export const PERMIT2_ADDRESS = {
9
+ [hardhat.id]: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
10
+ [megaETHTestnet.id]: "0xd1739f41B25869c7457E502Db4E0eaad663535B7",
11
+ };
12
+ export const WETH = {
13
+ [hardhat.id]: {
14
+ name: "Wrapped Ether",
15
+ symbol: "WETH",
16
+ address: "0x5FbDB2315678afecb367f032d93F642f64180aa3",
17
+ decimals: 18,
18
+ },
19
+ [megaETHTestnet.id]: {
20
+ name: "Wrapped Ether",
21
+ symbol: "WETH",
22
+ address: "0x4200000000000000000000000000000000000006",
23
+ decimals: 18,
24
+ },
25
+ };
26
+ export const TOKEN1 = {
27
+ [hardhat.id]: {
28
+ name: "Token 1",
29
+ symbol: "USDAI",
30
+ address: "0x0B306BF915C4d645ff596e518fAf3F9669b97016",
31
+ decimals: 18,
32
+ },
33
+ [megaETHTestnet.id]: {
34
+ name: "Token 1",
35
+ symbol: "USDAI",
36
+ address: ZERO_ADDRESS,
37
+ decimals: 18,
38
+ },
39
+ };
40
+ export const TOKEN2 = {
41
+ [hardhat.id]: {
42
+ name: "Token 2",
43
+ symbol: "USDC",
44
+ address: "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1",
45
+ decimals: 6,
46
+ },
47
+ [megaETHTestnet.id]: {
48
+ name: "Token 2",
49
+ symbol: "USDC",
50
+ address: ZERO_ADDRESS,
51
+ decimals: 6,
52
+ },
53
+ };
54
+ export const USDC = {
55
+ [hardhat.id]: {
56
+ name: "USD Coin",
57
+ symbol: "USDC",
58
+ address: "0x851356ae760d987E095750cCeb3bC6014560891C",
59
+ decimals: 6,
60
+ },
61
+ [megaETHTestnet.id]: {
62
+ name: "USD Coin",
63
+ symbol: "USDC",
64
+ address: "0x31c9236db6D1280fb133F2bd7876721530049121",
65
+ decimals: 6,
66
+ },
67
+ };
68
+ export const LIMIT_ORDER_PROTOCOL = {
69
+ [hardhat.id]: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
70
+ [megaETHTestnet.id]: "0xa0b7722c3F6c64010eEF97F045e1aA9126cC3e62",
71
+ };
72
+ export const COLLATERAL_TOKEN_FACTORY = {
73
+ [hardhat.id]: "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
74
+ [megaETHTestnet.id]: "0x5Ee2E49C38F5976E27CC45C5A47817e140eBB69E",
75
+ };
76
+ export const OPTION_TOKEN_FACTORY = {
77
+ [hardhat.id]: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
78
+ [megaETHTestnet.id]: "0x405BF5630c60E6C0c36650ba25D7BdC9533a03C6",
79
+ };
80
+ export const PRE_MARKET_OPTIONS_STRATEGY = {
81
+ [hardhat.id]: "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",
82
+ [megaETHTestnet.id]: "0x32034F6889174f3ea32502Dfd27Da3A9C677d83c",
83
+ };
84
+ export const OPTION_MARKET = {
85
+ [hardhat.id]: "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707",
86
+ [megaETHTestnet.id]: "0xB583C8d8218BfFE30bd45DB9F0E19a944Cb1deBd",
87
+ };
88
+ export const ERC6909_PROXY = {
89
+ [hardhat.id]: "0xE6E340D132b5f46d1e472DebcD681B2aBc16e57E",
90
+ [megaETHTestnet.id]: "0xC7B997B7a113108dA08562Fe1Bc87BF1bF3424B2",
91
+ };
92
+ export const ENTRY_POINT = {
93
+ [hardhat.id]: "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6",
94
+ [megaETHTestnet.id]: "0x0000000071727De22E5E9d8BAf0edAc6f37da032",
95
+ };
96
+ export const MOCK_PAYMASTER = {
97
+ [hardhat.id]: "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318",
98
+ [megaETHTestnet.id]: ZERO_ADDRESS,
99
+ };
100
+ export const SIMPLE_ACCOUNT_FACTORY = {
101
+ [hardhat.id]: "0xA51c1fc2f0D1a1b8494Ed1FE312d7C3a78Ed91C0",
102
+ [megaETHTestnet.id]: "0xca98DA1cB523DBff9234145ecA1158110dDd40dC",
103
+ };
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Market type
3
+ */
4
+ export type MarketType = "PRE-TGE" | "PRE-IPO";
5
+ export type SUPPORTED_CHAINS = 31337 | 6343;
6
+ /**
7
+ * Band configuration with strike limits and token IDs
8
+ */
9
+ export interface Band {
10
+ strikeLowerLimit: bigint;
11
+ strikeUpperLimit: bigint;
12
+ strikeLowerDisplay: string;
13
+ strikeUpperDisplay: string;
14
+ callTokenId: string;
15
+ putTokenId: string;
16
+ }
17
+ /**
18
+ * Collateral token configuration
19
+ */
20
+ export interface CollateralToken {
21
+ address: `0x${string}`;
22
+ decimals: number;
23
+ symbol: string;
24
+ }
25
+ /**
26
+ * Market configuration
27
+ */
28
+ export interface MarketConfig {
29
+ marketKey: string;
30
+ id: string;
31
+ name: string;
32
+ type: MarketType;
33
+ bands: Band[];
34
+ icon?: string;
35
+ stableTokenDecimals?: number;
36
+ collateralToken: CollateralToken;
37
+ }
38
+ /**
39
+ * Market configurations per chain
40
+ */
41
+ export declare const CHAIN_MARKET_CONFIGS: Record<SUPPORTED_CHAINS, Record<string, MarketConfig>>;
42
+ /**
43
+ * Get market config by ID for a specific chain
44
+ */
45
+ export declare function getMarketConfig(marketId: string, chainId: SUPPORTED_CHAINS): MarketConfig | undefined;
46
+ /**
47
+ * Get all market configs as an array for a specific chain
48
+ */
49
+ export declare function getAllMarketConfigs(chainId: SUPPORTED_CHAINS): MarketConfig[];
50
+ /**
51
+ * Get the collateral token for a specific market on a specific chain
52
+ */
53
+ export declare function getMarketCollateralToken(marketId: string, chainId: SUPPORTED_CHAINS): CollateralToken | undefined;
@@ -0,0 +1,125 @@
1
+ import { hardhat } from "viem/chains";
2
+ import { calculateOptionTokenId } from "../shared/utils.js";
3
+ import { TOKEN1, TOKEN2, USDC } from "./index.js";
4
+ import { megaETHTestnet } from "./chains.js";
5
+ /**
6
+ * Helper function to format strike value for display
7
+ */
8
+ function formatStrikeValue(value) {
9
+ const num = Number(value);
10
+ if (num >= 1e9) {
11
+ return `${num / 1e9}B`;
12
+ }
13
+ if (num >= 1e6) {
14
+ return `${num / 1e6}M`;
15
+ }
16
+ if (num >= 1e3) {
17
+ return `${num / 1e3}K`;
18
+ }
19
+ return num.toString();
20
+ }
21
+ /**
22
+ * Helper function to create a band with calculated token IDs and display values
23
+ */
24
+ function createBand(marketId, strikeLowerLimit, strikeUpperLimit) {
25
+ return {
26
+ strikeLowerLimit,
27
+ strikeUpperLimit,
28
+ strikeLowerDisplay: formatStrikeValue(strikeLowerLimit),
29
+ strikeUpperDisplay: formatStrikeValue(strikeUpperLimit),
30
+ callTokenId: calculateOptionTokenId({
31
+ marketId,
32
+ strikeLowerLimit: strikeLowerLimit.toString(),
33
+ strikeUpperLimit: strikeUpperLimit.toString(),
34
+ isPut: false,
35
+ }),
36
+ putTokenId: calculateOptionTokenId({
37
+ marketId,
38
+ strikeLowerLimit: strikeLowerLimit.toString(),
39
+ strikeUpperLimit: strikeUpperLimit.toString(),
40
+ isPut: true,
41
+ }),
42
+ };
43
+ }
44
+ /**
45
+ * Market configurations per chain
46
+ */
47
+ export const CHAIN_MARKET_CONFIGS = {
48
+ [hardhat.id]: {
49
+ "1": {
50
+ marketKey: "market1",
51
+ id: "1",
52
+ name: "Market 1",
53
+ type: "PRE-TGE",
54
+ bands: [
55
+ createBand("1", 1000000000n, 2000000000n),
56
+ createBand("1", 2000000000n, 5000000000n),
57
+ createBand("1", 5000000000n, 10000000000n),
58
+ ],
59
+ icon: "/images/usdai-icon.png",
60
+ stableTokenDecimals: 18,
61
+ collateralToken: {
62
+ address: TOKEN1[hardhat.id].address,
63
+ decimals: TOKEN1[hardhat.id].decimals,
64
+ symbol: TOKEN1[hardhat.id].symbol,
65
+ },
66
+ },
67
+ "2": {
68
+ marketKey: "market2",
69
+ id: "2",
70
+ name: "Market 2",
71
+ type: "PRE-IPO",
72
+ bands: [
73
+ createBand("2", 1000000000n, 2000000000n),
74
+ createBand("2", 2000000000n, 5000000000n),
75
+ createBand("2", 5000000000n, 10000000000n),
76
+ ],
77
+ icon: "/images/usdai-icon.png",
78
+ stableTokenDecimals: 6,
79
+ collateralToken: {
80
+ address: TOKEN2[hardhat.id].address,
81
+ decimals: TOKEN2[hardhat.id].decimals,
82
+ symbol: TOKEN2[hardhat.id].symbol,
83
+ },
84
+ },
85
+ },
86
+ [megaETHTestnet.id]: {
87
+ "1": {
88
+ marketKey: "market1",
89
+ id: "1",
90
+ name: "USDAI ICO",
91
+ type: "PRE-TGE",
92
+ bands: [
93
+ createBand("1", 1000000000n, 2000000000n),
94
+ createBand("1", 2000000000n, 5000000000n),
95
+ createBand("1", 5000000000n, 10000000000n),
96
+ ],
97
+ icon: "/images/usdai-icon.png",
98
+ stableTokenDecimals: 6,
99
+ collateralToken: {
100
+ address: USDC[megaETHTestnet.id].address,
101
+ decimals: USDC[megaETHTestnet.id].decimals,
102
+ symbol: USDC[megaETHTestnet.id].symbol,
103
+ },
104
+ },
105
+ },
106
+ };
107
+ /**
108
+ * Get market config by ID for a specific chain
109
+ */
110
+ export function getMarketConfig(marketId, chainId) {
111
+ return CHAIN_MARKET_CONFIGS[chainId]?.[marketId];
112
+ }
113
+ /**
114
+ * Get all market configs as an array for a specific chain
115
+ */
116
+ export function getAllMarketConfigs(chainId) {
117
+ return Object.values(CHAIN_MARKET_CONFIGS[chainId] || {});
118
+ }
119
+ /**
120
+ * Get the collateral token for a specific market on a specific chain
121
+ */
122
+ export function getMarketCollateralToken(marketId, chainId) {
123
+ const config = getMarketConfig(marketId, chainId);
124
+ return config?.collateralToken;
125
+ }