@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,248 @@
1
+ /**
2
+ * Serialize raw GraphQL query result into MarketStrategy type
3
+ */
4
+ export function serializeMarketStrategy(data) {
5
+ return {
6
+ id: String(data.id),
7
+ finalFDV: BigInt(data.finalFDV ?? 0),
8
+ deadline: BigInt(data.deadline ?? 0),
9
+ bandPrecision: BigInt(data.bandPrecision ?? 0),
10
+ collateralPerBandPrecision: BigInt(data.collateralPerBandPrecision ?? 0),
11
+ premiumRate: BigInt(data.premiumRate ?? 0),
12
+ depositFeeRate: BigInt(data.depositFeeRate ?? 0),
13
+ purchaseFeeRate: BigInt(data.purchaseFeeRate ?? 0),
14
+ settlementFeeRate: BigInt(data.settlementFeeRate ?? 0),
15
+ collateralToken: data.collateralToken,
16
+ };
17
+ }
18
+ /**
19
+ * Serialize raw GraphQL query result into OptionParams type
20
+ */
21
+ export function serializeOptionParams(data) {
22
+ return {
23
+ id: String(data.id),
24
+ marketId: BigInt(data.marketId ?? 0),
25
+ strikeLowerLimit: BigInt(data.strikeLowerLimit ?? 0),
26
+ strikeUpperLimit: BigInt(data.strikeUpperLimit ?? 0),
27
+ isPut: Boolean(data.isPut),
28
+ collateralPerShare: data.collateralPerShare != null ? BigInt(data.collateralPerShare) : undefined,
29
+ };
30
+ }
31
+ /**
32
+ * Serialize raw GraphQL query result into OptionMarket type
33
+ */
34
+ export function serializeOptionMarket(data) {
35
+ return {
36
+ id: String(data.id),
37
+ callToken: data.callToken,
38
+ putToken: data.putToken,
39
+ expiry: BigInt(data.expiry ?? 0),
40
+ maxTTL: BigInt(data.maxTTL ?? 0),
41
+ strategy: serializeMarketStrategy(data.strategy),
42
+ collateralToken: data.collateralToken,
43
+ totalCollateral: BigInt(data.totalCollateral ?? 0),
44
+ totalCollateralAmount: BigInt(data.totalCollateralAmount ?? 0),
45
+ protocolFees: BigInt(data.protocolFees ?? 0),
46
+ };
47
+ }
48
+ /**
49
+ * Serialize raw GraphQL query result into HourlyVolume type
50
+ */
51
+ export function serializeHourlyVolume(data) {
52
+ return {
53
+ id: String(data.id),
54
+ marketId: BigInt(data.marketId ?? 0),
55
+ optionId: String(data.optionId ?? ""),
56
+ hourTimestamp: BigInt(data.hourTimestamp ?? 0),
57
+ depositVolume: BigInt(data.depositVolume ?? 0),
58
+ tradeVolume: BigInt(data.tradeVolume ?? 0),
59
+ unwindVolume: BigInt(data.unwindVolume ?? 0),
60
+ withdrawVolume: BigInt(data.withdrawVolume ?? 0),
61
+ exerciseVolume: BigInt(data.exerciseVolume ?? 0),
62
+ totalVolume: BigInt(data.totalVolume ?? 0),
63
+ tradeCount: Number(data.tradeCount ?? 0),
64
+ };
65
+ }
66
+ /**
67
+ * Serialize raw GraphQL query result into CollateralPosition type
68
+ */
69
+ export function serializeCollateralPosition(data) {
70
+ return {
71
+ id: String(data.id),
72
+ optionId: String(data.optionId ?? ""),
73
+ optionMarketId: String(data.optionMarketId ?? ""),
74
+ totalCollateral: BigInt(data.totalCollateral ?? 0),
75
+ optionsMinted: BigInt(data.optionsMinted ?? 0),
76
+ optionsExercised: BigInt(data.optionsExercised ?? 0),
77
+ premiumEarned: BigInt(data.premiumEarned ?? 0),
78
+ fee: BigInt(data.fee ?? 0),
79
+ settled: Boolean(data.settled),
80
+ updatedAt: BigInt(data.updatedAt ?? 0),
81
+ updatedAtBlock: BigInt(data.updatedAtBlock ?? 0),
82
+ optionMarket: data.optionMarket
83
+ ? serializeOptionMarket(data.optionMarket)
84
+ : undefined,
85
+ optionParams: data.optionParams
86
+ ? serializeOptionParams(data.optionParams)
87
+ : undefined,
88
+ };
89
+ }
90
+ /**
91
+ * Serialize raw GraphQL query result into OptionPosition type
92
+ */
93
+ export function serializeOptionPosition(data) {
94
+ return {
95
+ id: String(data.id),
96
+ tokenId: BigInt(data.tokenId ?? 0),
97
+ address: data.address,
98
+ optionId: String(data.optionId ?? ""),
99
+ optionMarketId: String(data.optionMarketId ?? ""),
100
+ premium: BigInt(data.premium ?? 0),
101
+ fee: BigInt(data.fee ?? 0),
102
+ profit: BigInt(data.profit ?? 0),
103
+ amount: BigInt(data.amount ?? 0),
104
+ averagePrice: BigInt(data.averagePrice ?? 0),
105
+ updatedAt: BigInt(data.updatedAt ?? 0),
106
+ updatedAtBlock: BigInt(data.updatedAtBlock ?? 0),
107
+ optionMarket: data.optionMarket
108
+ ? serializeOptionMarket(data.optionMarket)
109
+ : undefined,
110
+ optionParams: data.optionParams
111
+ ? serializeOptionParams(data.optionParams)
112
+ : undefined,
113
+ };
114
+ }
115
+ /**
116
+ * Serialize raw GraphQL query result into DepositHistory type
117
+ */
118
+ export function serializeDepositHistory(data) {
119
+ return {
120
+ id: String(data.id),
121
+ optionId: String(data.optionId ?? ""),
122
+ marketId: BigInt(data.marketId ?? 0),
123
+ receiver: data.receiver,
124
+ amount: BigInt(data.amount ?? 0),
125
+ collateralAmount: BigInt(data.collateralAmount ?? 0),
126
+ fee: BigInt(data.fee ?? 0),
127
+ transactionHash: data.transactionHash,
128
+ blockNumber: BigInt(data.blockNumber ?? 0),
129
+ timestamp: BigInt(data.timestamp ?? 0),
130
+ };
131
+ }
132
+ /**
133
+ * Serialize raw GraphQL query result into TransferDepositHistory type
134
+ */
135
+ export function serializeTransferDepositHistory(data) {
136
+ return {
137
+ id: String(data.id),
138
+ optionId: String(data.optionId ?? ""),
139
+ marketId: BigInt(data.marketId ?? 0),
140
+ amount: BigInt(data.amount ?? 0),
141
+ collateralAmount: BigInt(data.collateralAmount ?? 0),
142
+ fee: BigInt(data.fee ?? 0),
143
+ transactionHash: data.transactionHash,
144
+ blockNumber: BigInt(data.blockNumber ?? 0),
145
+ timestamp: BigInt(data.timestamp ?? 0),
146
+ };
147
+ }
148
+ /**
149
+ * Serialize raw GraphQL query result into PurchaseHistory type
150
+ */
151
+ export function serializePurchaseHistory(data) {
152
+ return {
153
+ id: String(data.id),
154
+ optionId: String(data.optionId ?? ""),
155
+ purchaser: data.purchaser,
156
+ amount: BigInt(data.amount ?? 0),
157
+ premiumAmount: BigInt(data.premiumAmount ?? 0),
158
+ fee: BigInt(data.fee ?? 0),
159
+ optionShares: BigInt(data.optionShares ?? 0),
160
+ sharesUtilized: BigInt(data.sharesUtilized ?? 0),
161
+ transactionHash: data.transactionHash,
162
+ blockNumber: BigInt(data.blockNumber ?? 0),
163
+ timestamp: BigInt(data.timestamp ?? 0),
164
+ };
165
+ }
166
+ /**
167
+ * Serialize raw GraphQL query result into TransferPositionHistory type
168
+ */
169
+ export function serializeTransferPositionHistory(data) {
170
+ return {
171
+ id: String(data.id),
172
+ optionId: String(data.optionId ?? ""),
173
+ purchaser: data.purchaser,
174
+ amount: BigInt(data.amount ?? 0),
175
+ premiumAmount: BigInt(data.premiumAmount ?? 0),
176
+ fee: BigInt(data.fee ?? 0),
177
+ optionShares: BigInt(data.optionShares ?? 0),
178
+ sharesUtilized: BigInt(data.sharesUtilized ?? 0),
179
+ transactionHash: data.transactionHash,
180
+ blockNumber: BigInt(data.blockNumber ?? 0),
181
+ timestamp: BigInt(data.timestamp ?? 0),
182
+ };
183
+ }
184
+ /**
185
+ * Serialize raw GraphQL query result into ExerciseHistory type
186
+ */
187
+ export function serializeExerciseHistory(data) {
188
+ return {
189
+ id: String(data.id),
190
+ optionId: String(data.optionId ?? ""),
191
+ exerciser: data.exerciser,
192
+ amount: BigInt(data.amount ?? 0),
193
+ profitAmount: BigInt(data.profitAmount ?? 0),
194
+ fee: BigInt(data.fee ?? 0),
195
+ optionTokensBurnt: BigInt(data.optionTokensBurnt ?? 0),
196
+ sharesUnutilized: BigInt(data.sharesUnutilized ?? 0),
197
+ makerLoss: data.makerLoss != null ? BigInt(data.makerLoss) : null,
198
+ purchaserProfit: data.purchaserProfit != null ? BigInt(data.purchaserProfit) : null,
199
+ transactionHash: data.transactionHash,
200
+ blockNumber: BigInt(data.blockNumber ?? 0),
201
+ timestamp: BigInt(data.timestamp ?? 0),
202
+ };
203
+ }
204
+ /**
205
+ * Serialize raw GraphQL query result into UnwindHistory type
206
+ */
207
+ export function serializeUnwindHistory(data) {
208
+ return {
209
+ id: String(data.id),
210
+ optionId: String(data.optionId ?? ""),
211
+ marketId: BigInt(data.marketId ?? 0),
212
+ amount: BigInt(data.amount ?? 0),
213
+ collateralTokensToReturn: BigInt(data.collateralTokensToReturn ?? 0),
214
+ collateralSharesToBurn: BigInt(data.collateralSharesToBurn ?? 0),
215
+ optionSharesToBurn: BigInt(data.optionSharesToBurn ?? 0),
216
+ transactionHash: data.transactionHash,
217
+ blockNumber: BigInt(data.blockNumber ?? 0),
218
+ timestamp: BigInt(data.timestamp ?? 0),
219
+ };
220
+ }
221
+ /**
222
+ * Serialize raw GraphQL query result into SettlementHistory type
223
+ */
224
+ export function serializeSettlementHistory(data) {
225
+ return {
226
+ id: String(data.id),
227
+ optionId: String(data.optionId ?? ""),
228
+ optionMarketId: String(data.optionMarketId ?? ""),
229
+ totalCollateralSettled: BigInt(data.totalCollateralSettled ?? 0),
230
+ transactionHash: data.transactionHash,
231
+ blockNumber: BigInt(data.blockNumber ?? 0),
232
+ timestamp: BigInt(data.timestamp ?? 0),
233
+ };
234
+ }
235
+ /**
236
+ * Serialize raw GraphQL query result into UserHistories type
237
+ */
238
+ export function serializeUserHistories(data) {
239
+ return {
240
+ depositHistory: (data.depositHistory || []).map(serializeDepositHistory),
241
+ transferDepositHistory: (data.transferDepositHistory || []).map(serializeTransferDepositHistory),
242
+ purchaseHistory: (data.purchaseHistory || []).map(serializePurchaseHistory),
243
+ transferPositionHistory: (data.transferPositionHistory || []).map(serializeTransferPositionHistory),
244
+ exerciseHistory: (data.exerciseHistory || []).map(serializeExerciseHistory),
245
+ unwindHistory: (data.unwindHistory || []).map(serializeUnwindHistory),
246
+ settlementHistory: (data.settlementHistory || []).map(serializeSettlementHistory),
247
+ };
248
+ }
@@ -0,0 +1,5 @@
1
+ export interface User {
2
+ id: string;
3
+ updatedAt: bigint;
4
+ updatedAtBlock: bigint;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare function convertBigIntFields<T>(obj: T): T;
@@ -0,0 +1,32 @@
1
+ export function convertBigIntFields(obj) {
2
+ if (Array.isArray(obj)) {
3
+ return obj.map((item) => typeof item === "object" && item !== null
4
+ ? convertBigIntFields(item)
5
+ : item);
6
+ }
7
+ if (typeof obj !== "object" || obj === null) {
8
+ return obj;
9
+ }
10
+ const result = { ...obj };
11
+ for (const key in result) {
12
+ if (typeof result[key] === "string" && /^\d+$/.test(result[key])) {
13
+ try {
14
+ result[key] = BigInt(result[key]);
15
+ }
16
+ catch {
17
+ // Not a valid bigint string, leave as is
18
+ }
19
+ }
20
+ else if (typeof result[key] === "object" && result[key] !== null) {
21
+ if (Array.isArray(result[key])) {
22
+ result[key] = result[key].map((item) => typeof item === "object" && item !== null
23
+ ? convertBigIntFields(item)
24
+ : item);
25
+ }
26
+ else {
27
+ result[key] = convertBigIntFields(result[key]);
28
+ }
29
+ }
30
+ }
31
+ return result;
32
+ }
@@ -0,0 +1,18 @@
1
+ import type { QueryGenqlSelection, Query } from './schema';
2
+ import { type FieldsSelection, type GraphqlOperation, type ClientOptions, GenqlError } from './runtime';
3
+ export type { FieldsSelection } from './runtime';
4
+ export { GenqlError };
5
+ export * from './schema';
6
+ export interface Client {
7
+ query<R extends QueryGenqlSelection>(request: R & {
8
+ __name?: string;
9
+ }): Promise<FieldsSelection<Query, R>>;
10
+ }
11
+ export declare const createClient: (options?: ClientOptions) => Client;
12
+ export declare const everything: {
13
+ __scalar: boolean;
14
+ };
15
+ export type QueryResult<fields extends QueryGenqlSelection> = FieldsSelection<Query, fields>;
16
+ export declare const generateQueryOp: (fields: QueryGenqlSelection & {
17
+ __name?: string;
18
+ }) => GraphqlOperation;
@@ -0,0 +1,20 @@
1
+ import { linkTypeMap, createClient as createClientOriginal, generateGraphqlOperation, GenqlError, } from './runtime';
2
+ export { GenqlError };
3
+ import types from './types';
4
+ export * from './schema';
5
+ const typeMap = linkTypeMap(types);
6
+ export const createClient = function (options) {
7
+ return createClientOriginal({
8
+ url: undefined,
9
+ ...options,
10
+ queryRoot: typeMap.Query,
11
+ mutationRoot: typeMap.Mutation,
12
+ subscriptionRoot: typeMap.Subscription,
13
+ });
14
+ };
15
+ export const everything = {
16
+ __scalar: true,
17
+ };
18
+ export const generateQueryOp = function (fields) {
19
+ return generateGraphqlOperation('query', typeMap.Query, fields);
20
+ };
@@ -0,0 +1,105 @@
1
+ import type { GraphqlOperation } from './generateGraphqlOperation';
2
+ type Variables = Record<string, any>;
3
+ type QueryError = Error & {
4
+ message: string;
5
+ locations?: Array<{
6
+ line: number;
7
+ column: number;
8
+ }>;
9
+ path?: any;
10
+ rid: string;
11
+ details?: Record<string, any>;
12
+ };
13
+ type Result = {
14
+ data: Record<string, any>;
15
+ errors: Array<QueryError>;
16
+ };
17
+ type Fetcher = (batchedQuery: GraphqlOperation | Array<GraphqlOperation>) => Promise<Array<Result>>;
18
+ type Options = {
19
+ batchInterval?: number;
20
+ shouldBatch?: boolean;
21
+ maxBatchSize?: number;
22
+ };
23
+ type Queue = Array<{
24
+ request: GraphqlOperation;
25
+ resolve: (...args: Array<any>) => any;
26
+ reject: (...args: Array<any>) => any;
27
+ }>;
28
+ /**
29
+ * Create a batcher client.
30
+ * @param {Fetcher} fetcher - A function that can handle the network requests to graphql endpoint
31
+ * @param {Options} options - the options to be used by client
32
+ * @param {boolean} options.shouldBatch - should the client batch requests. (default true)
33
+ * @param {integer} options.batchInterval - duration (in MS) of each batch window. (default 6)
34
+ * @param {integer} options.maxBatchSize - max number of requests in a batch. (default 0)
35
+ * @param {boolean} options.defaultHeaders - default headers to include with every request
36
+ *
37
+ * @example
38
+ * const fetcher = batchedQuery => fetch('path/to/graphql', {
39
+ * method: 'post',
40
+ * headers: {
41
+ * Accept: 'application/json',
42
+ * 'Content-Type': 'application/json',
43
+ * },
44
+ * body: JSON.stringify(batchedQuery),
45
+ * credentials: 'include',
46
+ * })
47
+ * .then(response => response.json())
48
+ *
49
+ * const client = new QueryBatcher(fetcher, { maxBatchSize: 10 })
50
+ */
51
+ export declare class QueryBatcher {
52
+ fetcher: Fetcher;
53
+ _options: Options;
54
+ _queue: Queue;
55
+ constructor(fetcher: Fetcher, { batchInterval, shouldBatch, maxBatchSize, }?: Options);
56
+ /**
57
+ * Fetch will send a graphql request and return the parsed json.
58
+ * @param {string} query - the graphql query.
59
+ * @param {Variables} variables - any variables you wish to inject as key/value pairs.
60
+ * @param {[string]} operationName - the graphql operationName.
61
+ * @param {Options} overrides - the client options overrides.
62
+ *
63
+ * @return {promise} resolves to parsed json of server response
64
+ *
65
+ * @example
66
+ * client.fetch(`
67
+ * query getHuman($id: ID!) {
68
+ * human(id: $id) {
69
+ * name
70
+ * height
71
+ * }
72
+ * }
73
+ * `, { id: "1001" }, 'getHuman')
74
+ * .then(human => {
75
+ * // do something with human
76
+ * console.log(human);
77
+ * });
78
+ */
79
+ fetch(query: string, variables?: Variables, operationName?: string, overrides?: Options): Promise<Result>;
80
+ /**
81
+ * Fetch will send a graphql request and return the parsed json.
82
+ * @param {string} query - the graphql query.
83
+ * @param {Variables} variables - any variables you wish to inject as key/value pairs.
84
+ * @param {[string]} operationName - the graphql operationName.
85
+ * @param {Options} overrides - the client options overrides.
86
+ *
87
+ * @return {Promise<Array<Result>>} resolves to parsed json of server response
88
+ *
89
+ * @example
90
+ * client.forceFetch(`
91
+ * query getHuman($id: ID!) {
92
+ * human(id: $id) {
93
+ * name
94
+ * height
95
+ * }
96
+ * }
97
+ * `, { id: "1001" }, 'getHuman')
98
+ * .then(human => {
99
+ * // do something with human
100
+ * console.log(human);
101
+ * });
102
+ */
103
+ forceFetch(query: string, variables?: Variables, operationName?: string, overrides?: Options): Promise<Result>;
104
+ }
105
+ export {};
@@ -0,0 +1,188 @@
1
+ import { GenqlError } from './error';
2
+ /**
3
+ * takes a list of requests (queue) and batches them into a single server request.
4
+ * It will then resolve each individual requests promise with the appropriate data.
5
+ * @private
6
+ * @param {QueryBatcher} client - the client to use
7
+ * @param {Queue} queue - the list of requests to batch
8
+ */
9
+ function dispatchQueueBatch(client, queue) {
10
+ let batchedQuery = queue.map((item) => item.request);
11
+ if (batchedQuery.length === 1) {
12
+ batchedQuery = batchedQuery[0];
13
+ }
14
+ client.fetcher(batchedQuery).then((responses) => {
15
+ if (queue.length === 1 && !Array.isArray(responses)) {
16
+ if (responses.errors && responses.errors.length) {
17
+ queue[0].reject(new GenqlError(responses.errors, responses.data));
18
+ return;
19
+ }
20
+ queue[0].resolve(responses);
21
+ return;
22
+ }
23
+ else if (responses.length !== queue.length) {
24
+ throw new Error('response length did not match query length');
25
+ }
26
+ for (let i = 0; i < queue.length; i++) {
27
+ if (responses[i].errors && responses[i].errors.length) {
28
+ queue[i].reject(new GenqlError(responses[i].errors, responses[i].data));
29
+ }
30
+ else {
31
+ queue[i].resolve(responses[i]);
32
+ }
33
+ }
34
+ });
35
+ }
36
+ /**
37
+ * creates a list of requests to batch according to max batch size.
38
+ * @private
39
+ * @param {QueryBatcher} client - the client to create list of requests from from
40
+ * @param {Options} options - the options for the batch
41
+ */
42
+ function dispatchQueue(client, options) {
43
+ const queue = client._queue;
44
+ const maxBatchSize = options.maxBatchSize || 0;
45
+ client._queue = [];
46
+ if (maxBatchSize > 0 && maxBatchSize < queue.length) {
47
+ for (let i = 0; i < queue.length / maxBatchSize; i++) {
48
+ dispatchQueueBatch(client, queue.slice(i * maxBatchSize, (i + 1) * maxBatchSize));
49
+ }
50
+ }
51
+ else {
52
+ dispatchQueueBatch(client, queue);
53
+ }
54
+ }
55
+ /**
56
+ * Create a batcher client.
57
+ * @param {Fetcher} fetcher - A function that can handle the network requests to graphql endpoint
58
+ * @param {Options} options - the options to be used by client
59
+ * @param {boolean} options.shouldBatch - should the client batch requests. (default true)
60
+ * @param {integer} options.batchInterval - duration (in MS) of each batch window. (default 6)
61
+ * @param {integer} options.maxBatchSize - max number of requests in a batch. (default 0)
62
+ * @param {boolean} options.defaultHeaders - default headers to include with every request
63
+ *
64
+ * @example
65
+ * const fetcher = batchedQuery => fetch('path/to/graphql', {
66
+ * method: 'post',
67
+ * headers: {
68
+ * Accept: 'application/json',
69
+ * 'Content-Type': 'application/json',
70
+ * },
71
+ * body: JSON.stringify(batchedQuery),
72
+ * credentials: 'include',
73
+ * })
74
+ * .then(response => response.json())
75
+ *
76
+ * const client = new QueryBatcher(fetcher, { maxBatchSize: 10 })
77
+ */
78
+ export class QueryBatcher {
79
+ constructor(fetcher, { batchInterval = 6, shouldBatch = true, maxBatchSize = 0, } = {}) {
80
+ this.fetcher = fetcher;
81
+ this._options = {
82
+ batchInterval,
83
+ shouldBatch,
84
+ maxBatchSize,
85
+ };
86
+ this._queue = [];
87
+ }
88
+ /**
89
+ * Fetch will send a graphql request and return the parsed json.
90
+ * @param {string} query - the graphql query.
91
+ * @param {Variables} variables - any variables you wish to inject as key/value pairs.
92
+ * @param {[string]} operationName - the graphql operationName.
93
+ * @param {Options} overrides - the client options overrides.
94
+ *
95
+ * @return {promise} resolves to parsed json of server response
96
+ *
97
+ * @example
98
+ * client.fetch(`
99
+ * query getHuman($id: ID!) {
100
+ * human(id: $id) {
101
+ * name
102
+ * height
103
+ * }
104
+ * }
105
+ * `, { id: "1001" }, 'getHuman')
106
+ * .then(human => {
107
+ * // do something with human
108
+ * console.log(human);
109
+ * });
110
+ */
111
+ fetch(query, variables, operationName, overrides = {}) {
112
+ const request = {
113
+ query,
114
+ };
115
+ const options = Object.assign({}, this._options, overrides);
116
+ if (variables) {
117
+ request.variables = variables;
118
+ }
119
+ if (operationName) {
120
+ request.operationName = operationName;
121
+ }
122
+ const promise = new Promise((resolve, reject) => {
123
+ this._queue.push({
124
+ request,
125
+ resolve,
126
+ reject,
127
+ });
128
+ if (this._queue.length === 1) {
129
+ if (options.shouldBatch) {
130
+ setTimeout(() => dispatchQueue(this, options), options.batchInterval);
131
+ }
132
+ else {
133
+ dispatchQueue(this, options);
134
+ }
135
+ }
136
+ });
137
+ return promise;
138
+ }
139
+ /**
140
+ * Fetch will send a graphql request and return the parsed json.
141
+ * @param {string} query - the graphql query.
142
+ * @param {Variables} variables - any variables you wish to inject as key/value pairs.
143
+ * @param {[string]} operationName - the graphql operationName.
144
+ * @param {Options} overrides - the client options overrides.
145
+ *
146
+ * @return {Promise<Array<Result>>} resolves to parsed json of server response
147
+ *
148
+ * @example
149
+ * client.forceFetch(`
150
+ * query getHuman($id: ID!) {
151
+ * human(id: $id) {
152
+ * name
153
+ * height
154
+ * }
155
+ * }
156
+ * `, { id: "1001" }, 'getHuman')
157
+ * .then(human => {
158
+ * // do something with human
159
+ * console.log(human);
160
+ * });
161
+ */
162
+ forceFetch(query, variables, operationName, overrides = {}) {
163
+ const request = {
164
+ query,
165
+ };
166
+ const options = Object.assign({}, this._options, overrides, {
167
+ shouldBatch: false,
168
+ });
169
+ if (variables) {
170
+ request.variables = variables;
171
+ }
172
+ if (operationName) {
173
+ request.operationName = operationName;
174
+ }
175
+ const promise = new Promise((resolve, reject) => {
176
+ const client = new QueryBatcher(this.fetcher, this._options);
177
+ client._queue = [
178
+ {
179
+ request,
180
+ resolve,
181
+ reject,
182
+ },
183
+ ];
184
+ dispatchQueue(client, options);
185
+ });
186
+ return promise;
187
+ }
188
+ }
@@ -0,0 +1,17 @@
1
+ import { type BatchOptions } from './fetcher';
2
+ import type { ExecutionResult, LinkedType } from './types';
3
+ import { type GraphqlOperation } from './generateGraphqlOperation';
4
+ export type Headers = HeadersInit | (() => HeadersInit) | (() => Promise<HeadersInit>);
5
+ export type BaseFetcher = (operation: GraphqlOperation | GraphqlOperation[]) => Promise<ExecutionResult | ExecutionResult[]>;
6
+ export type ClientOptions = Omit<RequestInit, 'body' | 'headers'> & {
7
+ url?: string;
8
+ batch?: BatchOptions | boolean;
9
+ fetcher?: BaseFetcher;
10
+ fetch?: Function;
11
+ headers?: Headers;
12
+ };
13
+ export declare const createClient: ({ queryRoot, mutationRoot, subscriptionRoot, ...options }: ClientOptions & {
14
+ queryRoot?: LinkedType;
15
+ mutationRoot?: LinkedType;
16
+ subscriptionRoot?: LinkedType;
17
+ }) => any;
@@ -0,0 +1,24 @@
1
+ // @ts-nocheck
2
+ import { createFetcher } from './fetcher';
3
+ import { generateGraphqlOperation, } from './generateGraphqlOperation';
4
+ export const createClient = ({ queryRoot, mutationRoot, subscriptionRoot, ...options }) => {
5
+ const fetcher = createFetcher(options);
6
+ const client = {};
7
+ if (queryRoot) {
8
+ client.query = (request) => {
9
+ if (!queryRoot)
10
+ throw new Error('queryRoot argument is missing');
11
+ const resultPromise = fetcher(generateGraphqlOperation('query', queryRoot, request));
12
+ return resultPromise;
13
+ };
14
+ }
15
+ if (mutationRoot) {
16
+ client.mutation = (request) => {
17
+ if (!mutationRoot)
18
+ throw new Error('mutationRoot argument is missing');
19
+ const resultPromise = fetcher(generateGraphqlOperation('mutation', mutationRoot, request));
20
+ return resultPromise;
21
+ };
22
+ }
23
+ return client;
24
+ };
@@ -0,0 +1,18 @@
1
+ export declare class GenqlError extends Error {
2
+ errors: Array<GraphqlError>;
3
+ /**
4
+ * Partial data returned by the server
5
+ */
6
+ data?: any;
7
+ constructor(errors: any[], data: any);
8
+ }
9
+ interface GraphqlError {
10
+ message: string;
11
+ locations?: Array<{
12
+ line: number;
13
+ column: number;
14
+ }>;
15
+ path?: string[];
16
+ extensions?: Record<string, any>;
17
+ }
18
+ export {};