@typus/typus-perp-sdk 1.1.31-testnet → 1.1.32-codegen

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 (249) hide show
  1. package/dist/src/api/sentio.js +604 -538
  2. package/dist/src/client.d.ts +27 -0
  3. package/dist/src/client.js +108 -0
  4. package/dist/src/fetch.d.ts +161 -34
  5. package/dist/src/fetch.js +365 -665
  6. package/dist/src/generated/typus_perp/admin.d.ts +117 -0
  7. package/dist/src/generated/typus_perp/admin.js +110 -0
  8. package/dist/src/generated/typus_perp/competition.d.ts +22 -0
  9. package/dist/src/generated/typus_perp/competition.js +58 -0
  10. package/dist/src/generated/typus_perp/deps/std/type_name.d.ts +17 -0
  11. package/dist/src/generated/typus_perp/deps/std/type_name.js +25 -0
  12. package/dist/src/generated/typus_perp/deps/sui/balance.d.ts +12 -0
  13. package/dist/src/generated/typus_perp/deps/sui/balance.js +20 -0
  14. package/dist/src/generated/typus_perp/deps/sui/object.d.ts +8 -0
  15. package/dist/src/generated/typus_perp/deps/sui/object.js +16 -0
  16. package/dist/src/generated/typus_perp/deps/sui/object_table.d.ts +19 -0
  17. package/dist/src/generated/typus_perp/deps/sui/object_table.js +59 -0
  18. package/dist/src/generated/typus_perp/deps/sui/vec_set.d.ts +18 -0
  19. package/dist/src/generated/typus_perp/deps/sui/vec_set.js +25 -0
  20. package/dist/src/generated/typus_perp/deps/typus/keyed_big_vector.d.ts +30 -0
  21. package/dist/src/generated/typus_perp/deps/typus/keyed_big_vector.js +67 -0
  22. package/dist/src/generated/typus_perp/deps/typus/linked_object_table.d.ts +32 -0
  23. package/dist/src/generated/typus_perp/deps/typus/linked_object_table.js +71 -0
  24. package/dist/src/generated/typus_perp/deps/typus_framework/vault.d.ts +23 -0
  25. package/dist/src/generated/typus_perp/deps/typus_framework/vault.js +61 -0
  26. package/dist/src/generated/typus_perp/escrow.d.ts +59 -0
  27. package/dist/src/generated/typus_perp/escrow.js +76 -0
  28. package/dist/src/generated/typus_perp/lending.d.ts +47 -0
  29. package/dist/src/generated/typus_perp/lending.js +50 -0
  30. package/dist/src/generated/typus_perp/lp_pool.d.ts +2327 -0
  31. package/dist/src/generated/typus_perp/lp_pool.js +1956 -0
  32. package/dist/src/generated/typus_perp/math.d.ts +95 -0
  33. package/dist/src/generated/typus_perp/math.js +97 -0
  34. package/dist/src/generated/typus_perp/position.d.ts +234 -0
  35. package/dist/src/generated/typus_perp/position.js +204 -0
  36. package/dist/src/generated/typus_perp/symbol.d.ts +18 -0
  37. package/dist/src/generated/typus_perp/symbol.js +55 -0
  38. package/dist/src/generated/typus_perp/tlp.d.ts +13 -0
  39. package/dist/src/generated/typus_perp/tlp.js +56 -0
  40. package/dist/src/generated/typus_perp/trading.d.ts +2486 -0
  41. package/dist/src/generated/typus_perp/trading.js +2476 -0
  42. package/dist/src/generated/typus_perp/treasury_caps.d.ts +13 -0
  43. package/dist/src/{_framework/init-loader.js → generated/typus_perp/treasury_caps.js} +17 -10
  44. package/dist/src/generated/typus_perp/user_account.d.ts +40 -0
  45. package/dist/src/generated/typus_perp/user_account.js +72 -0
  46. package/dist/src/generated/typus_stake_pool/admin.d.ts +100 -0
  47. package/dist/src/generated/typus_stake_pool/admin.js +91 -0
  48. package/dist/src/generated/typus_stake_pool/deps/std/type_name.d.ts +17 -0
  49. package/dist/src/generated/typus_stake_pool/deps/std/type_name.js +25 -0
  50. package/dist/src/generated/typus_stake_pool/deps/sui/object.d.ts +8 -0
  51. package/dist/src/generated/typus_stake_pool/deps/sui/object.js +16 -0
  52. package/dist/src/generated/typus_stake_pool/deps/sui/vec_map.d.ts +30 -0
  53. package/dist/src/generated/typus_stake_pool/deps/sui/vec_map.js +37 -0
  54. package/dist/src/generated/typus_stake_pool/deps/sui/vec_set.d.ts +18 -0
  55. package/dist/src/generated/typus_stake_pool/deps/sui/vec_set.js +25 -0
  56. package/dist/src/generated/typus_stake_pool/stake_pool.d.ts +1023 -0
  57. package/dist/src/generated/typus_stake_pool/stake_pool.js +918 -0
  58. package/dist/src/generated/utils/index.d.ts +12 -0
  59. package/dist/src/generated/utils/index.js +135 -0
  60. package/dist/src/grpc/graphql.d.ts +26 -0
  61. package/dist/src/grpc/graphql.js +126 -0
  62. package/dist/src/grpc/grpc.d.ts +1 -0
  63. package/dist/src/grpc/grpc.js +38 -0
  64. package/dist/src/grpc/ledgerService.js +64 -0
  65. package/dist/src/grpc/liveDataService.d.ts +0 -0
  66. package/dist/src/grpc/liveDataService.js +49 -0
  67. package/dist/src/index.d.ts +0 -4
  68. package/dist/src/index.js +20 -39
  69. package/dist/src/user/history.js +611 -680
  70. package/dist/src/user/order.d.ts +11 -11
  71. package/dist/src/user/order.js +171 -302
  72. package/dist/src/user/orderWithBidReceipt.d.ts +8 -6
  73. package/dist/src/user/orderWithBidReceipt.js +127 -226
  74. package/dist/src/user/tlp.d.ts +32 -23
  75. package/dist/src/user/tlp.js +316 -468
  76. package/package.json +44 -36
  77. package/dist/src/_dependencies/source/0x1/ascii/structs.d.ts +0 -88
  78. package/dist/src/_dependencies/source/0x1/ascii/structs.js +0 -398
  79. package/dist/src/_dependencies/source/0x1/index.d.ts +0 -3
  80. package/dist/src/_dependencies/source/0x1/index.js +0 -6
  81. package/dist/src/_dependencies/source/0x1/option/structs.d.ts +0 -50
  82. package/dist/src/_dependencies/source/0x1/option/structs.js +0 -271
  83. package/dist/src/_dependencies/source/0x1/string/structs.d.ts +0 -48
  84. package/dist/src/_dependencies/source/0x1/string/structs.js +0 -256
  85. package/dist/src/_dependencies/source/0x1/type-name/structs.d.ts +0 -49
  86. package/dist/src/_dependencies/source/0x1/type-name/structs.js +0 -223
  87. package/dist/src/_dependencies/source/0x2/bag/structs.d.ts +0 -54
  88. package/dist/src/_dependencies/source/0x2/bag/structs.js +0 -229
  89. package/dist/src/_dependencies/source/0x2/balance/structs.d.ts +0 -84
  90. package/dist/src/_dependencies/source/0x2/balance/structs.js +0 -386
  91. package/dist/src/_dependencies/source/0x2/coin/structs.d.ts +0 -406
  92. package/dist/src/_dependencies/source/0x2/coin/structs.js +0 -1247
  93. package/dist/src/_dependencies/source/0x2/index.d.ts +0 -3
  94. package/dist/src/_dependencies/source/0x2/index.js +0 -6
  95. package/dist/src/_dependencies/source/0x2/linked-table/structs.d.ts +0 -132
  96. package/dist/src/_dependencies/source/0x2/linked-table/structs.js +0 -438
  97. package/dist/src/_dependencies/source/0x2/object/structs.d.ts +0 -86
  98. package/dist/src/_dependencies/source/0x2/object/structs.js +0 -364
  99. package/dist/src/_dependencies/source/0x2/object-table/structs.d.ts +0 -54
  100. package/dist/src/_dependencies/source/0x2/object-table/structs.js +0 -248
  101. package/dist/src/_dependencies/source/0x2/sui/structs.d.ts +0 -44
  102. package/dist/src/_dependencies/source/0x2/sui/structs.js +0 -222
  103. package/dist/src/_dependencies/source/0x2/table/structs.d.ts +0 -54
  104. package/dist/src/_dependencies/source/0x2/table/structs.js +0 -248
  105. package/dist/src/_dependencies/source/0x2/table-vec/structs.d.ts +0 -59
  106. package/dist/src/_dependencies/source/0x2/table-vec/structs.js +0 -274
  107. package/dist/src/_dependencies/source/0x2/token/structs.d.ts +0 -421
  108. package/dist/src/_dependencies/source/0x2/token/structs.js +0 -1095
  109. package/dist/src/_dependencies/source/0x2/transfer-policy/structs.d.ts +0 -348
  110. package/dist/src/_dependencies/source/0x2/transfer-policy/structs.js +0 -1091
  111. package/dist/src/_dependencies/source/0x2/url/structs.d.ts +0 -49
  112. package/dist/src/_dependencies/source/0x2/url/structs.js +0 -223
  113. package/dist/src/_dependencies/source/0x2/vec-map/structs.d.ts +0 -106
  114. package/dist/src/_dependencies/source/0x2/vec-map/structs.js +0 -446
  115. package/dist/src/_dependencies/source/0x2/vec-set/structs.d.ts +0 -49
  116. package/dist/src/_dependencies/source/0x2/vec-set/structs.js +0 -270
  117. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/airdrop/structs.d.ts +0 -422
  118. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/airdrop/structs.js +0 -1084
  119. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/big-vector/structs.d.ts +0 -130
  120. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/big-vector/structs.js +0 -456
  121. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/critbit/structs.d.ts +0 -208
  122. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/critbit/structs.js +0 -653
  123. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/ecosystem/structs.d.ts +0 -362
  124. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/ecosystem/structs.js +0 -899
  125. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/index.d.ts +0 -8
  126. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/index.js +0 -11
  127. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/init.d.ts +0 -2
  128. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/init.js +0 -102
  129. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/keyed-big-vector/structs.d.ts +0 -202
  130. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/keyed-big-vector/structs.js +0 -632
  131. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/leaderboard/structs.d.ts +0 -600
  132. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/leaderboard/structs.js +0 -1459
  133. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/linked-object-table/structs.d.ts +0 -136
  134. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/linked-object-table/structs.js +0 -438
  135. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/linked-set/structs.d.ts +0 -127
  136. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/linked-set/structs.js +0 -430
  137. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/tails-staking/structs.d.ts +0 -957
  138. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/tails-staking/structs.js +0 -2261
  139. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/tgld/structs.d.ts +0 -244
  140. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/tgld/structs.js +0 -733
  141. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/user/structs.d.ts +0 -294
  142. package/dist/src/_dependencies/source/0x4b0f4ee1a40ce37ec81c987cc4e76a665419e74b863319492fc7d26f708b835a/user/structs.js +0 -892
  143. package/dist/src/_dependencies/source/0xb4f25230ba74837d8299e92951306100c4a532e8c48cc3d8828abe9b91c8b274/authority/structs.d.ts +0 -73
  144. package/dist/src/_dependencies/source/0xb4f25230ba74837d8299e92951306100c4a532e8c48cc3d8828abe9b91c8b274/authority/structs.js +0 -263
  145. package/dist/src/_dependencies/source/0xb4f25230ba74837d8299e92951306100c4a532e8c48cc3d8828abe9b91c8b274/balance-pool/structs.d.ts +0 -294
  146. package/dist/src/_dependencies/source/0xb4f25230ba74837d8299e92951306100c4a532e8c48cc3d8828abe9b91c8b274/balance-pool/structs.js +0 -591
  147. package/dist/src/_dependencies/source/0xb4f25230ba74837d8299e92951306100c4a532e8c48cc3d8828abe9b91c8b274/big-vector/structs.d.ts +0 -64
  148. package/dist/src/_dependencies/source/0xb4f25230ba74837d8299e92951306100c4a532e8c48cc3d8828abe9b91c8b274/big-vector/structs.js +0 -258
  149. package/dist/src/_dependencies/source/0xb4f25230ba74837d8299e92951306100c4a532e8c48cc3d8828abe9b91c8b274/dutch/structs.d.ts +0 -756
  150. package/dist/src/_dependencies/source/0xb4f25230ba74837d8299e92951306100c4a532e8c48cc3d8828abe9b91c8b274/dutch/structs.js +0 -1721
  151. package/dist/src/_dependencies/source/0xb4f25230ba74837d8299e92951306100c4a532e8c48cc3d8828abe9b91c8b274/i64/structs.d.ts +0 -44
  152. package/dist/src/_dependencies/source/0xb4f25230ba74837d8299e92951306100c4a532e8c48cc3d8828abe9b91c8b274/i64/structs.js +0 -222
  153. package/dist/src/_dependencies/source/0xb4f25230ba74837d8299e92951306100c4a532e8c48cc3d8828abe9b91c8b274/index.d.ts +0 -3
  154. package/dist/src/_dependencies/source/0xb4f25230ba74837d8299e92951306100c4a532e8c48cc3d8828abe9b91c8b274/index.js +0 -6
  155. package/dist/src/_dependencies/source/0xb4f25230ba74837d8299e92951306100c4a532e8c48cc3d8828abe9b91c8b274/init.d.ts +0 -2
  156. package/dist/src/_dependencies/source/0xb4f25230ba74837d8299e92951306100c4a532e8c48cc3d8828abe9b91c8b274/init.js +0 -89
  157. package/dist/src/_dependencies/source/0xb4f25230ba74837d8299e92951306100c4a532e8c48cc3d8828abe9b91c8b274/linked-list/structs.d.ts +0 -135
  158. package/dist/src/_dependencies/source/0xb4f25230ba74837d8299e92951306100c4a532e8c48cc3d8828abe9b91c8b274/linked-list/structs.js +0 -444
  159. package/dist/src/_dependencies/source/0xb4f25230ba74837d8299e92951306100c4a532e8c48cc3d8828abe9b91c8b274/vault/structs.d.ts +0 -2106
  160. package/dist/src/_dependencies/source/0xb4f25230ba74837d8299e92951306100c4a532e8c48cc3d8828abe9b91c8b274/vault/structs.js +0 -4952
  161. package/dist/src/_dependencies/source/0xbd147bc7f12f38f175d78947a61364e8e077b9b188b00e7094bc0c3623162196/discount-mint/structs.d.ts +0 -390
  162. package/dist/src/_dependencies/source/0xbd147bc7f12f38f175d78947a61364e8e077b9b188b00e7094bc0c3623162196/discount-mint/structs.js +0 -844
  163. package/dist/src/_dependencies/source/0xbd147bc7f12f38f175d78947a61364e8e077b9b188b00e7094bc0c3623162196/index.d.ts +0 -6
  164. package/dist/src/_dependencies/source/0xbd147bc7f12f38f175d78947a61364e8e077b9b188b00e7094bc0c3623162196/index.js +0 -9
  165. package/dist/src/_dependencies/source/0xbd147bc7f12f38f175d78947a61364e8e077b9b188b00e7094bc0c3623162196/init.d.ts +0 -2
  166. package/dist/src/_dependencies/source/0xbd147bc7f12f38f175d78947a61364e8e077b9b188b00e7094bc0c3623162196/init.js +0 -69
  167. package/dist/src/_dependencies/source/0xbd147bc7f12f38f175d78947a61364e8e077b9b188b00e7094bc0c3623162196/royalty-rule/structs.d.ts +0 -89
  168. package/dist/src/_dependencies/source/0xbd147bc7f12f38f175d78947a61364e8e077b9b188b00e7094bc0c3623162196/royalty-rule/structs.js +0 -376
  169. package/dist/src/_dependencies/source/0xbd147bc7f12f38f175d78947a61364e8e077b9b188b00e7094bc0c3623162196/staking/structs.d.ts +0 -386
  170. package/dist/src/_dependencies/source/0xbd147bc7f12f38f175d78947a61364e8e077b9b188b00e7094bc0c3623162196/staking/structs.js +0 -881
  171. package/dist/src/_dependencies/source/0xbd147bc7f12f38f175d78947a61364e8e077b9b188b00e7094bc0c3623162196/table-vec/structs.d.ts +0 -59
  172. package/dist/src/_dependencies/source/0xbd147bc7f12f38f175d78947a61364e8e077b9b188b00e7094bc0c3623162196/table-vec/structs.js +0 -274
  173. package/dist/src/_dependencies/source/0xbd147bc7f12f38f175d78947a61364e8e077b9b188b00e7094bc0c3623162196/typus-nft/structs.d.ts +0 -974
  174. package/dist/src/_dependencies/source/0xbd147bc7f12f38f175d78947a61364e8e077b9b188b00e7094bc0c3623162196/typus-nft/structs.js +0 -2387
  175. package/dist/src/_framework/init-loader.d.ts +0 -2
  176. package/dist/src/_framework/loader.d.ts +0 -17
  177. package/dist/src/_framework/loader.js +0 -108
  178. package/dist/src/_framework/reified.d.ts +0 -108
  179. package/dist/src/_framework/reified.js +0 -237
  180. package/dist/src/_framework/util.d.ts +0 -35
  181. package/dist/src/_framework/util.js +0 -396
  182. package/dist/src/_framework/vector.d.ts +0 -42
  183. package/dist/src/_framework/vector.js +0 -112
  184. package/dist/src/pyth.js +0 -1
  185. package/dist/src/typus_perp/admin/functions.d.ts +0 -59
  186. package/dist/src/typus_perp/admin/functions.js +0 -122
  187. package/dist/src/typus_perp/admin/structs.d.ts +0 -467
  188. package/dist/src/typus_perp/admin/structs.js +0 -1065
  189. package/dist/src/typus_perp/competition/functions.d.ts +0 -24
  190. package/dist/src/typus_perp/competition/functions.js +0 -38
  191. package/dist/src/typus_perp/competition/structs.d.ts +0 -80
  192. package/dist/src/typus_perp/competition/structs.js +0 -288
  193. package/dist/src/typus_perp/error/functions.d.ts +0 -73
  194. package/dist/src/typus_perp/error/functions.js +0 -363
  195. package/dist/src/typus_perp/escrow/functions.d.ts +0 -17
  196. package/dist/src/typus_perp/escrow/functions.js +0 -36
  197. package/dist/src/typus_perp/escrow/structs.d.ts +0 -160
  198. package/dist/src/typus_perp/escrow/structs.js +0 -324
  199. package/dist/src/typus_perp/index.d.ts +0 -1
  200. package/dist/src/typus_perp/index.js +0 -7
  201. package/dist/src/typus_perp/init.d.ts +0 -2
  202. package/dist/src/typus_perp/init.js +0 -118
  203. package/dist/src/typus_perp/lending/functions.d.ts +0 -15
  204. package/dist/src/typus_perp/lending/functions.js +0 -22
  205. package/dist/src/typus_perp/lp-pool/functions.d.ts +0 -460
  206. package/dist/src/typus_perp/lp-pool/functions.js +0 -732
  207. package/dist/src/typus_perp/lp-pool/structs.d.ts +0 -3705
  208. package/dist/src/typus_perp/lp-pool/structs.js +0 -6789
  209. package/dist/src/typus_perp/math/functions.d.ts +0 -29
  210. package/dist/src/typus_perp/math/functions.js +0 -61
  211. package/dist/src/typus_perp/position/functions.d.ts +0 -379
  212. package/dist/src/typus_perp/position/functions.js +0 -713
  213. package/dist/src/typus_perp/position/structs.d.ts +0 -905
  214. package/dist/src/typus_perp/position/structs.js +0 -1450
  215. package/dist/src/typus_perp/symbol/functions.d.ts +0 -9
  216. package/dist/src/typus_perp/symbol/functions.js +0 -24
  217. package/dist/src/typus_perp/symbol/structs.d.ts +0 -70
  218. package/dist/src/typus_perp/symbol/structs.js +0 -235
  219. package/dist/src/typus_perp/tlp/functions.d.ts +0 -19
  220. package/dist/src/typus_perp/tlp/functions.js +0 -40
  221. package/dist/src/typus_perp/tlp/structs.d.ts +0 -89
  222. package/dist/src/typus_perp/tlp/structs.js +0 -365
  223. package/dist/src/typus_perp/token-interface/functions.d.ts +0 -11
  224. package/dist/src/typus_perp/token-interface/functions.js +0 -22
  225. package/dist/src/typus_perp/trading/functions.d.ts +0 -812
  226. package/dist/src/typus_perp/trading/functions.js +0 -1218
  227. package/dist/src/typus_perp/trading/structs.d.ts +0 -3060
  228. package/dist/src/typus_perp/trading/structs.js +0 -5813
  229. package/dist/src/typus_perp/treasury-caps/functions.d.ts +0 -9
  230. package/dist/src/typus_perp/treasury-caps/functions.js +0 -36
  231. package/dist/src/typus_perp/treasury-caps/structs.d.ts +0 -49
  232. package/dist/src/typus_perp/treasury-caps/structs.js +0 -223
  233. package/dist/src/typus_perp/user-account/functions.d.ts +0 -36
  234. package/dist/src/typus_perp/user-account/functions.js +0 -70
  235. package/dist/src/typus_perp/user-account/structs.d.ts +0 -148
  236. package/dist/src/typus_perp/user-account/structs.js +0 -448
  237. package/dist/src/typus_stake_pool/admin/functions.d.ts +0 -49
  238. package/dist/src/typus_stake_pool/admin/functions.js +0 -105
  239. package/dist/src/typus_stake_pool/admin/structs.d.ts +0 -365
  240. package/dist/src/typus_stake_pool/admin/structs.js +0 -789
  241. package/dist/src/typus_stake_pool/index.d.ts +0 -1
  242. package/dist/src/typus_stake_pool/index.js +0 -7
  243. package/dist/src/typus_stake_pool/init.d.ts +0 -2
  244. package/dist/src/typus_stake_pool/init.js +0 -69
  245. package/dist/src/typus_stake_pool/stake-pool/functions.d.ts +0 -229
  246. package/dist/src/typus_stake_pool/stake-pool/functions.js +0 -380
  247. package/dist/src/typus_stake_pool/stake-pool/structs.d.ts +0 -2199
  248. package/dist/src/typus_stake_pool/stake-pool/structs.js +0 -4653
  249. /package/dist/src/{pyth.d.ts → grpc/ledgerService.d.ts} +0 -0
@@ -1,40 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.getFromSentio = getFromSentio;
40
4
  exports.getRecentTradesFromSentio = getRecentTradesFromSentio;
@@ -47,90 +11,126 @@ exports.getTlpPriceFromSentio = getTlpPriceFromSentio;
47
11
  exports.getTlpComparisonFromSentio = getTlpComparisonFromSentio;
48
12
  exports.getUserPnlFromSentio = getUserPnlFromSentio;
49
13
  exports.getLeaderboardFromSentio = getLeaderboardFromSentio;
50
- var src_1 = require("../../src");
51
- var headers = {
14
+ const src_1 = require("../../src");
15
+ const headers = {
52
16
  "api-key": "ffJa6FwxeJNrQP8NZ5doEMXqdSA7XM6mT",
53
17
  "Content-Type": "application/json",
54
18
  };
55
- function getFromSentio(event, userAddress, startTimestamp, cranker) {
56
- return __awaiter(this, void 0, void 0, function () {
57
- var apiUrl, crankerFilter, requestData, jsonData, response, data;
58
- return __generator(this, function (_a) {
59
- switch (_a.label) {
60
- case 0:
61
- apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp_mainnet/sql/execute";
62
- crankerFilter = "";
63
- if (cranker) {
64
- crankerFilter = "AND is_cranker == true";
65
- }
66
- requestData = {
67
- sqlQuery: {
68
- sql: "\n SELECT *\n FROM ".concat(event, "\n WHERE distinct_id = '").concat(userAddress, "' AND timestamp >= ").concat(startTimestamp, " ").concat(crankerFilter, "\n ORDER BY timestamp DESC;\n "),
69
- size: 1000,
70
- },
71
- };
72
- jsonData = JSON.stringify(requestData);
73
- return [4 /*yield*/, fetch(apiUrl, {
74
- method: "POST",
75
- headers: headers,
76
- body: jsonData,
77
- })];
78
- case 1:
79
- response = _a.sent();
80
- return [4 /*yield*/, response.json()];
81
- case 2:
82
- data = _a.sent();
83
- // console.log(data);
84
- if (data.result) {
85
- return [2 /*return*/, data.result.rows];
86
- }
87
- else {
88
- return [2 /*return*/, []];
89
- }
90
- return [2 /*return*/];
91
- }
92
- });
19
+ async function getFromSentio(event, userAddress, startTimestamp, cranker) {
20
+ let apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp_mainnet/sql/execute";
21
+ // add cranker fileter
22
+ let crankerFilter = "";
23
+ if (cranker) {
24
+ crankerFilter = "AND is_cranker == true";
25
+ }
26
+ let requestData = {
27
+ sqlQuery: {
28
+ sql: `
29
+ SELECT *
30
+ FROM ${event}
31
+ WHERE distinct_id = '${userAddress}' AND timestamp >= ${startTimestamp} ${crankerFilter}
32
+ ORDER BY timestamp DESC;
33
+ `,
34
+ size: 1000,
35
+ },
36
+ };
37
+ let jsonData = JSON.stringify(requestData);
38
+ let response = await fetch(apiUrl, {
39
+ method: "POST",
40
+ headers,
41
+ body: jsonData,
93
42
  });
43
+ let data = await response.json();
44
+ // console.log(data);
45
+ if (data.result) {
46
+ return data.result.rows;
47
+ }
48
+ else {
49
+ return [];
50
+ }
94
51
  }
95
- function getRecentTradesFromSentio(base_token) {
96
- return __awaiter(this, void 0, void 0, function () {
97
- var apiUrl, tokenFilter, requestData, jsonData, response, data;
98
- return __generator(this, function (_a) {
99
- switch (_a.label) {
100
- case 0:
101
- apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp_mainnet/sql/execute";
102
- tokenFilter = "";
103
- if (base_token) {
104
- tokenFilter = "WHERE base_token = '".concat((0, src_1.toSentioToken)(base_token), "'");
105
- }
106
- requestData = {
107
- sqlQuery: {
108
- sql: "\n SELECT * FROM (\n WITH\n OpenOrder AS (\n SELECT\n PlaceOrder.collateral AS collateral,\n OrderFilled.position_id AS position_id,\n OrderFilled.base_token AS base_token,\n PlaceOrder.transaction_hash as transaction_hash\n FROM PlaceOrder\n JOIN OrderFilled ON OrderFilled.order_id == PlaceOrder.order_id AND OrderFilled.base_token == PlaceOrder.base_token\n WHERE OrderFilled.order_type == 'Open'\n )\n SELECT\n PlaceOrder.timestamp as timestamp,\n PlaceOrder.base_token as base_token,\n PlaceOrder.collateral_token as collateral_token,\n PlaceOrder.order_type as order_type,\n OrderFilled.order_type as status,\n PlaceOrder.side as side,\n PlaceOrder.distinct_id as distinct_id,\n price,\n size,\n realized_amount-realized_fee-RealizeFunding.realized_funding_fee as realized_pnl,\n OrderFilled.realized_pnl-RealizeFunding.realized_funding_fee_usd as realized_pnl_usd,\n OpenOrder.collateral as collateral,\n PlaceOrder.transaction_hash as transaction_hash\n FROM PlaceOrder\n LEFT JOIN OrderFilled ON OrderFilled.order_id == PlaceOrder.order_id AND OrderFilled.base_token == PlaceOrder.base_token\n LEFT JOIN RealizeFunding ON RealizeFunding.position_id == OrderFilled.position_id AND RealizeFunding.base_token == OrderFilled.base_token AND RealizeFunding.transaction_hash == OrderFilled.transaction_hash\n LEFT JOIN RealizeOption ON RealizeOption.position_id == OrderFilled.position_id AND RealizeOption.base_token == OrderFilled.base_token AND RealizeOption.transaction_hash == OrderFilled.transaction_hash\n LEFT JOIN RemovePosition ON RemovePosition.transaction_hash == OrderFilled.transaction_hash\n LEFT JOIN OpenOrder ON OpenOrder.position_id == OrderFilled.position_id AND OpenOrder.base_token == PlaceOrder.base_token\n ".concat(tokenFilter, "\n UNION ALL\n SELECT\n PlaceOrderWithBidReceipt.timestamp as timestamp,\n PlaceOrderWithBidReceipt.base_token as base_token,\n PlaceOrderWithBidReceipt.collateral_token as collateral_token,\n PlaceOrderWithBidReceipt.order_type as order_type,\n OrderFilled.order_type as status,\n PlaceOrderWithBidReceipt.side as side,\n PlaceOrderWithBidReceipt.distinct_id as distinct_id,\n price,\n size,\n realized_amount-realized_fee-RealizeFunding.realized_funding_fee as realized_pnl,\n OrderFilled.realized_pnl-RealizeFunding.realized_funding_fee_usd as realized_pnl_usd,\n RealizeOption.exercise_balance_value as collateral_amount,\n PlaceOrderWithBidReceipt.transaction_hash as transaction_hash\n FROM PlaceOrderWithBidReceipt\n JOIN OrderFilled ON OrderFilled.order_id == PlaceOrderWithBidReceipt.order_id AND OrderFilled.base_token == PlaceOrderWithBidReceipt.base_token\n LEFT JOIN RealizeFunding ON RealizeFunding.position_id == OrderFilled.position_id AND RealizeFunding.base_token == OrderFilled.base_token AND RealizeFunding.transaction_hash == OrderFilled.transaction_hash\n LEFT JOIN RealizeOption ON RealizeOption.position_id == OrderFilled.position_id AND RealizeOption.base_token == OrderFilled.base_token AND RealizeOption.transaction_hash == OrderFilled.transaction_hash\n ").concat(tokenFilter, "\n ) AS combined\n ORDER BY timestamp DESC\n "),
109
- size: 100,
110
- },
111
- };
112
- jsonData = JSON.stringify(requestData);
113
- return [4 /*yield*/, fetch(apiUrl, {
114
- method: "POST",
115
- headers: headers,
116
- body: jsonData,
117
- })];
118
- case 1:
119
- response = _a.sent();
120
- return [4 /*yield*/, response.json()];
121
- case 2:
122
- data = _a.sent();
123
- // console.log(data);
124
- if (data.result) {
125
- return [2 /*return*/, data.result.rows];
126
- }
127
- else {
128
- return [2 /*return*/, []];
129
- }
130
- return [2 /*return*/];
131
- }
132
- });
52
+ async function getRecentTradesFromSentio(base_token) {
53
+ let apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp_mainnet/sql/execute";
54
+ let tokenFilter = "";
55
+ if (base_token) {
56
+ tokenFilter = `WHERE base_token = '${(0, src_1.toSentioToken)(base_token)}'`;
57
+ }
58
+ let requestData = {
59
+ sqlQuery: {
60
+ sql: `
61
+ SELECT * FROM (
62
+ WITH
63
+ OpenOrder AS (
64
+ SELECT
65
+ PlaceOrder.collateral AS collateral,
66
+ OrderFilled.position_id AS position_id,
67
+ OrderFilled.base_token AS base_token,
68
+ PlaceOrder.transaction_hash as transaction_hash
69
+ FROM PlaceOrder
70
+ JOIN OrderFilled ON OrderFilled.order_id == PlaceOrder.order_id AND OrderFilled.base_token == PlaceOrder.base_token
71
+ WHERE OrderFilled.order_type == 'Open'
72
+ )
73
+ SELECT
74
+ PlaceOrder.timestamp as timestamp,
75
+ PlaceOrder.base_token as base_token,
76
+ PlaceOrder.collateral_token as collateral_token,
77
+ PlaceOrder.order_type as order_type,
78
+ OrderFilled.order_type as status,
79
+ PlaceOrder.side as side,
80
+ PlaceOrder.distinct_id as distinct_id,
81
+ price,
82
+ size,
83
+ realized_amount-realized_fee-RealizeFunding.realized_funding_fee as realized_pnl,
84
+ OrderFilled.realized_pnl-RealizeFunding.realized_funding_fee_usd as realized_pnl_usd,
85
+ OpenOrder.collateral as collateral,
86
+ PlaceOrder.transaction_hash as transaction_hash
87
+ FROM PlaceOrder
88
+ LEFT JOIN OrderFilled ON OrderFilled.order_id == PlaceOrder.order_id AND OrderFilled.base_token == PlaceOrder.base_token
89
+ LEFT JOIN RealizeFunding ON RealizeFunding.position_id == OrderFilled.position_id AND RealizeFunding.base_token == OrderFilled.base_token AND RealizeFunding.transaction_hash == OrderFilled.transaction_hash
90
+ LEFT JOIN RealizeOption ON RealizeOption.position_id == OrderFilled.position_id AND RealizeOption.base_token == OrderFilled.base_token AND RealizeOption.transaction_hash == OrderFilled.transaction_hash
91
+ LEFT JOIN RemovePosition ON RemovePosition.transaction_hash == OrderFilled.transaction_hash
92
+ LEFT JOIN OpenOrder ON OpenOrder.position_id == OrderFilled.position_id AND OpenOrder.base_token == PlaceOrder.base_token
93
+ ${tokenFilter}
94
+ UNION ALL
95
+ SELECT
96
+ PlaceOrderWithBidReceipt.timestamp as timestamp,
97
+ PlaceOrderWithBidReceipt.base_token as base_token,
98
+ PlaceOrderWithBidReceipt.collateral_token as collateral_token,
99
+ PlaceOrderWithBidReceipt.order_type as order_type,
100
+ OrderFilled.order_type as status,
101
+ PlaceOrderWithBidReceipt.side as side,
102
+ PlaceOrderWithBidReceipt.distinct_id as distinct_id,
103
+ price,
104
+ size,
105
+ realized_amount-realized_fee-RealizeFunding.realized_funding_fee as realized_pnl,
106
+ OrderFilled.realized_pnl-RealizeFunding.realized_funding_fee_usd as realized_pnl_usd,
107
+ RealizeOption.exercise_balance_value as collateral_amount,
108
+ PlaceOrderWithBidReceipt.transaction_hash as transaction_hash
109
+ FROM PlaceOrderWithBidReceipt
110
+ JOIN OrderFilled ON OrderFilled.order_id == PlaceOrderWithBidReceipt.order_id AND OrderFilled.base_token == PlaceOrderWithBidReceipt.base_token
111
+ LEFT JOIN RealizeFunding ON RealizeFunding.position_id == OrderFilled.position_id AND RealizeFunding.base_token == OrderFilled.base_token AND RealizeFunding.transaction_hash == OrderFilled.transaction_hash
112
+ LEFT JOIN RealizeOption ON RealizeOption.position_id == OrderFilled.position_id AND RealizeOption.base_token == OrderFilled.base_token AND RealizeOption.transaction_hash == OrderFilled.transaction_hash
113
+ ${tokenFilter}
114
+ ) AS combined
115
+ ORDER BY timestamp DESC
116
+ `,
117
+ size: 100,
118
+ },
119
+ };
120
+ let jsonData = JSON.stringify(requestData);
121
+ let response = await fetch(apiUrl, {
122
+ method: "POST",
123
+ headers,
124
+ body: jsonData,
133
125
  });
126
+ let data = await response.json();
127
+ // console.log(data);
128
+ if (data.result) {
129
+ return data.result.rows;
130
+ }
131
+ else {
132
+ return [];
133
+ }
134
134
  }
135
135
  /**
136
136
  * Inputs:
@@ -141,117 +141,100 @@ function getRecentTradesFromSentio(base_token) {
141
141
  * key: base_token {'APT','BTC','CETUS','DEEP','ETH','NAVX','NS','SOL','SUI','WAL'}
142
142
  * value: Volume[]
143
143
  */
144
- function getTradingVolumeFromSentio(fromTimestamp, interval, toTimestamp) {
145
- return __awaiter(this, void 0, void 0, function () {
146
- var apiUrl, requestData, jsonData, response, data, samples, map;
147
- return __generator(this, function (_a) {
148
- switch (_a.label) {
149
- case 0:
150
- apiUrl = "https://app.sentio.xyz/api/v1/insights/typus/typus_perp_mainnet/query";
151
- requestData = {
152
- timeRange: {
153
- start: "".concat(fromTimestamp),
154
- end: "".concat(toTimestamp !== null && toTimestamp !== void 0 ? toTimestamp : now()),
155
- step: 3600 * interval,
156
- },
157
- limit: 30 * 24,
158
- queries: [
159
- {
160
- metricsQuery: {
161
- query: "trading_volume_usd",
162
- alias: "",
163
- id: "a",
164
- labelSelector: {},
165
- aggregate: {
166
- op: "SUM",
167
- grouping: ["base_token"],
144
+ async function getTradingVolumeFromSentio(fromTimestamp, interval, toTimestamp) {
145
+ let apiUrl = "https://app.sentio.xyz/api/v1/insights/typus/typus_perp_mainnet/query";
146
+ let requestData = {
147
+ timeRange: {
148
+ start: `${fromTimestamp}`,
149
+ end: `${toTimestamp ?? now()}`,
150
+ step: 3600 * interval,
151
+ },
152
+ limit: 30 * 24,
153
+ queries: [
154
+ {
155
+ metricsQuery: {
156
+ query: "trading_volume_usd",
157
+ alias: "",
158
+ id: "a",
159
+ labelSelector: {},
160
+ aggregate: {
161
+ op: "SUM",
162
+ grouping: ["base_token"],
163
+ },
164
+ functions: [
165
+ {
166
+ name: "rollup_delta",
167
+ arguments: [
168
+ {
169
+ durationValue: {
170
+ value: interval,
171
+ unit: "h",
168
172
  },
169
- functions: [
170
- {
171
- name: "rollup_delta",
172
- arguments: [
173
- {
174
- durationValue: {
175
- value: interval,
176
- unit: "h",
177
- },
178
- },
179
- ],
180
- },
181
- ],
182
- color: "",
183
- disabled: false,
184
173
  },
185
- dataSource: "METRICS",
186
- sourceName: "",
187
- },
188
- ],
189
- formulas: [],
190
- };
191
- jsonData = JSON.stringify(requestData);
192
- return [4 /*yield*/, fetch(apiUrl, {
193
- method: "POST",
194
- headers: headers,
195
- body: jsonData,
196
- })];
197
- case 1:
198
- response = _a.sent();
199
- return [4 /*yield*/, response.json()];
200
- case 2:
201
- data = _a.sent();
202
- samples = data.results[0].matrix.samples;
203
- map = new Map();
204
- samples.forEach(function (sample) {
205
- // console.log(samples);
206
- var base_token = sample.metric.labels.base_token;
207
- var values = sample.values;
208
- // console.log(base_token);
209
- // console.log(values);
210
- map.set(base_token, values);
211
- });
212
- // console.log(map);
213
- // console.log(map.keys());
214
- // console.log(map.get("SUI")?.length);
215
- return [2 /*return*/, map];
216
- }
217
- });
174
+ ],
175
+ },
176
+ ],
177
+ color: "",
178
+ disabled: false,
179
+ },
180
+ dataSource: "METRICS",
181
+ sourceName: "",
182
+ },
183
+ ],
184
+ formulas: [],
185
+ };
186
+ let jsonData = JSON.stringify(requestData);
187
+ let response = await fetch(apiUrl, {
188
+ method: "POST",
189
+ headers,
190
+ body: jsonData,
218
191
  });
192
+ let data = await response.json();
193
+ let samples = data.results[0].matrix.samples;
194
+ let map = new Map();
195
+ samples.forEach((sample) => {
196
+ // console.log(samples);
197
+ let base_token = sample.metric.labels.base_token;
198
+ let values = sample.values;
199
+ // console.log(base_token);
200
+ // console.log(values);
201
+ map.set(base_token, values);
202
+ });
203
+ // console.log(map);
204
+ // console.log(map.keys());
205
+ // console.log(map.get("SUI")?.length);
206
+ return map;
219
207
  }
220
- function getMinuteTradingVolumeFromSentio(base_token, minute, size) {
221
- return __awaiter(this, void 0, void 0, function () {
222
- var apiUrl, requestData, jsonData, response, data;
223
- return __generator(this, function (_a) {
224
- switch (_a.label) {
225
- case 0:
226
- apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp_mainnet/sql/execute";
227
- requestData = {
228
- sqlQuery: {
229
- sql: "\n SELECT\n toDateTime(intDiv(toUnixTimestamp(timestamp), 60 * ".concat(minute, ") * 60 * ").concat(minute, ") as ts_start,\n sum(filled_size) AS total_filled_size\n FROM OrderFilled\n WHERE base_token = '").concat((0, src_1.toSentioToken)(base_token), "'\n GROUP BY ts_start\n ORDER BY ts_start DESC;\n "),
230
- size: size,
231
- },
232
- };
233
- jsonData = JSON.stringify(requestData);
234
- return [4 /*yield*/, fetch(apiUrl, {
235
- method: "POST",
236
- headers: headers,
237
- body: jsonData,
238
- })];
239
- case 1:
240
- response = _a.sent();
241
- return [4 /*yield*/, response.json()];
242
- case 2:
243
- data = _a.sent();
244
- // console.log(data);
245
- if (data.result) {
246
- return [2 /*return*/, data.result.rows];
247
- }
248
- else {
249
- return [2 /*return*/, []];
250
- }
251
- return [2 /*return*/];
252
- }
253
- });
208
+ async function getMinuteTradingVolumeFromSentio(base_token, minute, size) {
209
+ let apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp_mainnet/sql/execute";
210
+ let requestData = {
211
+ sqlQuery: {
212
+ sql: `
213
+ SELECT
214
+ toDateTime(intDiv(toUnixTimestamp(timestamp), 60 * ${minute}) * 60 * ${minute}) as ts_start,
215
+ sum(filled_size) AS total_filled_size
216
+ FROM OrderFilled
217
+ WHERE base_token = '${(0, src_1.toSentioToken)(base_token)}'
218
+ GROUP BY ts_start
219
+ ORDER BY ts_start DESC;
220
+ `,
221
+ size,
222
+ },
223
+ };
224
+ let jsonData = JSON.stringify(requestData);
225
+ let response = await fetch(apiUrl, {
226
+ method: "POST",
227
+ headers,
228
+ body: jsonData,
254
229
  });
230
+ let data = await response.json();
231
+ // console.log(data);
232
+ if (data.result) {
233
+ return data.result.rows;
234
+ }
235
+ else {
236
+ return [];
237
+ }
255
238
  }
256
239
  function now() {
257
240
  return Math.round(Date.now() / 1000);
@@ -259,176 +242,147 @@ function now() {
259
242
  function parseTimestamp(s) {
260
243
  return Math.round(Date.parse(s) / 1000);
261
244
  }
262
- function getTlpFeeFromSentio(fromTimestamp, toTimestamp) {
263
- return __awaiter(this, void 0, void 0, function () {
264
- var apiUrl, requestData, jsonData, response, data, first, last, initial_value, fee;
265
- return __generator(this, function (_a) {
266
- switch (_a.label) {
267
- case 0:
268
- apiUrl = "https://app.sentio.xyz/api/v1/insights/typus/typus_perp_mainnet/query";
269
- requestData = {
270
- timeRange: {
271
- start: "".concat(fromTimestamp !== null && fromTimestamp !== void 0 ? fromTimestamp : 0),
272
- end: "".concat(toTimestamp !== null && toTimestamp !== void 0 ? toTimestamp : now()),
273
- step: 3600,
274
- },
275
- limit: 20,
276
- queries: [
277
- {
278
- metricsQuery: {
279
- query: "tlp_fee_usd",
280
- alias: "",
281
- id: "a",
282
- labelSelector: {},
283
- aggregate: {
284
- op: "SUM",
285
- grouping: [],
286
- },
287
- functions: [],
288
- disabled: false,
289
- },
290
- dataSource: "METRICS",
291
- sourceName: "",
292
- },
293
- ],
294
- formulas: [],
295
- };
296
- jsonData = JSON.stringify(requestData);
297
- return [4 /*yield*/, fetch(apiUrl, {
298
- method: "POST",
299
- headers: headers,
300
- body: jsonData,
301
- })];
302
- case 1:
303
- response = _a.sent();
304
- return [4 /*yield*/, response.json()];
305
- case 2:
306
- data = _a.sent();
307
- first = data.results[0].matrix.samples[0].values[0];
308
- last = data.results[0].matrix.samples[0].values.at(-1);
309
- initial_value = fromTimestamp ? first.value : 0;
310
- fee = last.value - initial_value;
311
- // console.log(fee);
312
- return [2 /*return*/, fee];
313
- }
314
- });
245
+ async function getTlpFeeFromSentio(fromTimestamp, toTimestamp) {
246
+ let apiUrl = "https://app.sentio.xyz/api/v1/insights/typus/typus_perp_mainnet/query";
247
+ let requestData = {
248
+ timeRange: {
249
+ start: `${fromTimestamp ?? 0}`,
250
+ end: `${toTimestamp ?? now()}`,
251
+ step: 3600,
252
+ },
253
+ limit: 20,
254
+ queries: [
255
+ {
256
+ metricsQuery: {
257
+ query: "tlp_fee_usd",
258
+ alias: "",
259
+ id: "a",
260
+ labelSelector: {},
261
+ aggregate: {
262
+ op: "SUM",
263
+ grouping: [],
264
+ },
265
+ functions: [],
266
+ disabled: false,
267
+ },
268
+ dataSource: "METRICS",
269
+ sourceName: "",
270
+ },
271
+ ],
272
+ formulas: [],
273
+ };
274
+ let jsonData = JSON.stringify(requestData);
275
+ let response = await fetch(apiUrl, {
276
+ method: "POST",
277
+ headers,
278
+ body: jsonData,
315
279
  });
280
+ let data = await response.json();
281
+ // console.log(data);
282
+ // console.log(data.results[0].matrix.samples[0].values);
283
+ let first = data.results[0].matrix.samples[0].values[0];
284
+ let last = data.results[0].matrix.samples[0].values.at(-1);
285
+ // console.log(first, last);
286
+ let initial_value = fromTimestamp ? first.value : 0;
287
+ // console.log(initial_value);
288
+ let fee = last.value - initial_value;
289
+ // console.log(fee);
290
+ return fee;
316
291
  }
317
- function getTotalVolumeFromSentio(fromTimestamp, toTimestamp) {
318
- return __awaiter(this, void 0, void 0, function () {
319
- var apiUrl, requestData, jsonData, response, data, initial_value, result;
320
- return __generator(this, function (_a) {
321
- switch (_a.label) {
322
- case 0:
323
- apiUrl = "https://app.sentio.xyz/api/v1/insights/typus/typus_perp_mainnet/query";
324
- requestData = {
325
- timeRange: {
326
- start: "".concat(fromTimestamp !== null && fromTimestamp !== void 0 ? fromTimestamp : 0),
327
- end: "".concat(toTimestamp !== null && toTimestamp !== void 0 ? toTimestamp : now()),
328
- step: 3600,
329
- },
330
- limit: 1,
331
- queries: [
332
- {
333
- metricsQuery: {
334
- query: "trading_volume_usd",
335
- alias: "",
336
- id: "a",
337
- labelSelector: {},
338
- aggregate: {
339
- op: "SUM",
340
- grouping: [],
341
- },
342
- functions: [],
343
- color: "",
344
- disabled: false,
345
- },
346
- dataSource: "METRICS",
347
- sourceName: "",
348
- },
349
- ],
350
- formulas: [],
351
- };
352
- jsonData = JSON.stringify(requestData);
353
- return [4 /*yield*/, fetch(apiUrl, {
354
- method: "POST",
355
- headers: headers,
356
- body: jsonData,
357
- })];
358
- case 1:
359
- response = _a.sent();
360
- return [4 /*yield*/, response.json()];
361
- case 2:
362
- data = _a.sent();
363
- initial_value = fromTimestamp ? data.results[0].matrix.samples[0].values.at(0).value : 0;
364
- result = data.results[0].matrix.samples[0].values.at(-1).value - initial_value;
365
- // console.log(result);
366
- return [2 /*return*/, result];
367
- }
368
- });
292
+ async function getTotalVolumeFromSentio(fromTimestamp, toTimestamp) {
293
+ let apiUrl = "https://app.sentio.xyz/api/v1/insights/typus/typus_perp_mainnet/query";
294
+ let requestData = {
295
+ timeRange: {
296
+ start: `${fromTimestamp ?? 0}`,
297
+ end: `${toTimestamp ?? now()}`,
298
+ step: 3600,
299
+ },
300
+ limit: 1,
301
+ queries: [
302
+ {
303
+ metricsQuery: {
304
+ query: "trading_volume_usd",
305
+ alias: "",
306
+ id: "a",
307
+ labelSelector: {},
308
+ aggregate: {
309
+ op: "SUM",
310
+ grouping: [],
311
+ },
312
+ functions: [],
313
+ color: "",
314
+ disabled: false,
315
+ },
316
+ dataSource: "METRICS",
317
+ sourceName: "",
318
+ },
319
+ ],
320
+ formulas: [],
321
+ };
322
+ let jsonData = JSON.stringify(requestData);
323
+ let response = await fetch(apiUrl, {
324
+ method: "POST",
325
+ headers,
326
+ body: jsonData,
369
327
  });
328
+ let data = await response.json();
329
+ // console.log(data.results[0].matrix.samples[0].values);
330
+ let initial_value = fromTimestamp ? data.results[0].matrix.samples[0].values.at(0).value : 0;
331
+ // console.log(initial_value);
332
+ let result = data.results[0].matrix.samples[0].values.at(-1).value - initial_value;
333
+ // console.log(result);
334
+ return result;
370
335
  }
371
336
  /** Returns Accumulated Users */
372
- function getAccumulatedUser() {
373
- return __awaiter(this, void 0, void 0, function () {
374
- var apiUrl, requestData, jsonData, response, data, result;
375
- return __generator(this, function (_a) {
376
- switch (_a.label) {
377
- case 0:
378
- apiUrl = "https://app.sentio.xyz/api/v1/insights/typus/typus_perp_mainnet/query";
379
- requestData = {
380
- timeRange: {
381
- start: "now-1h",
382
- end: "now",
383
- step: 3600,
384
- timezone: "Asia/Taipei",
385
- },
386
- limit: 1,
387
- queries: [
388
- {
389
- eventsQuery: {
390
- resource: {
391
- name: "",
392
- type: "EVENTS",
393
- },
394
- alias: "",
395
- id: "a",
396
- aggregation: {
397
- countUnique: {
398
- duration: {
399
- value: 0,
400
- unit: "day",
401
- },
402
- },
403
- },
404
- groupBy: [],
405
- limit: 1,
406
- functions: [],
407
- disabled: false,
408
- },
409
- dataSource: "EVENTS",
410
- sourceName: "",
337
+ async function getAccumulatedUser() {
338
+ let apiUrl = "https://app.sentio.xyz/api/v1/insights/typus/typus_perp_mainnet/query";
339
+ let requestData = {
340
+ timeRange: {
341
+ start: "now-1h",
342
+ end: "now",
343
+ step: 3600,
344
+ timezone: "Asia/Taipei",
345
+ },
346
+ limit: 1,
347
+ queries: [
348
+ {
349
+ eventsQuery: {
350
+ resource: {
351
+ name: "",
352
+ type: "EVENTS",
353
+ },
354
+ alias: "",
355
+ id: "a",
356
+ aggregation: {
357
+ countUnique: {
358
+ duration: {
359
+ value: 0,
360
+ unit: "day",
411
361
  },
412
- ],
413
- formulas: [],
414
- };
415
- jsonData = JSON.stringify(requestData);
416
- return [4 /*yield*/, fetch(apiUrl, {
417
- method: "POST",
418
- headers: headers,
419
- body: jsonData,
420
- })];
421
- case 1:
422
- response = _a.sent();
423
- return [4 /*yield*/, response.json()];
424
- case 2:
425
- data = _a.sent();
426
- result = data.results[0].matrix.samples[0].values.at(-1).value;
427
- // console.log(result);
428
- return [2 /*return*/, result];
429
- }
430
- });
362
+ },
363
+ },
364
+ groupBy: [],
365
+ limit: 1,
366
+ functions: [],
367
+ disabled: false,
368
+ },
369
+ dataSource: "EVENTS",
370
+ sourceName: "",
371
+ },
372
+ ],
373
+ formulas: [],
374
+ };
375
+ let jsonData = JSON.stringify(requestData);
376
+ let response = await fetch(apiUrl, {
377
+ method: "POST",
378
+ headers,
379
+ body: jsonData,
431
380
  });
381
+ let data = await response.json();
382
+ // console.log(data.results[0].matrix.samples[0].values[0].value);
383
+ let result = data.results[0].matrix.samples[0].values.at(-1).value;
384
+ // console.log(result);
385
+ return result;
432
386
  }
433
387
  /**
434
388
  * Inputs:
@@ -437,168 +391,280 @@ function getAccumulatedUser() {
437
391
  * Returns
438
392
  * { timestamp: string, value: number }[]
439
393
  */
440
- function getTlpPriceFromSentio(fromTimestamp, toTimestamp) {
441
- return __awaiter(this, void 0, void 0, function () {
442
- var apiUrl, requestData, jsonData, response, data, samples;
443
- return __generator(this, function (_a) {
444
- switch (_a.label) {
445
- case 0:
446
- apiUrl = "https://app.sentio.xyz/api/v1/insights/typus/typus_perp_mainnet/query";
447
- requestData = {
448
- timeRange: {
449
- start: "".concat(fromTimestamp !== null && fromTimestamp !== void 0 ? fromTimestamp : 0),
450
- end: "".concat(toTimestamp !== null && toTimestamp !== void 0 ? toTimestamp : now()),
451
- step: 3600,
452
- },
453
- limit: 30 * 24,
454
- queries: [
455
- {
456
- metricsQuery: {
457
- query: "tlp_price",
458
- alias: "",
459
- id: "a",
460
- labelSelector: {},
461
- aggregate: null,
462
- functions: [],
463
- color: "",
464
- disabled: false,
465
- },
466
- dataSource: "METRICS",
467
- sourceName: "",
468
- },
469
- ],
470
- formulas: [],
471
- };
472
- jsonData = JSON.stringify(requestData);
473
- return [4 /*yield*/, fetch(apiUrl, {
474
- method: "POST",
475
- headers: headers,
476
- body: jsonData,
477
- })];
478
- case 1:
479
- response = _a.sent();
480
- return [4 /*yield*/, response.json()];
481
- case 2:
482
- data = _a.sent();
483
- samples = data.results[0].matrix.samples;
484
- // console.log(samples[0].values);
485
- return [2 /*return*/, samples[0].values];
486
- }
487
- });
394
+ async function getTlpPriceFromSentio(fromTimestamp, toTimestamp) {
395
+ let apiUrl = "https://app.sentio.xyz/api/v1/insights/typus/typus_perp_mainnet/query";
396
+ let requestData = {
397
+ timeRange: {
398
+ start: `${fromTimestamp ?? 0}`,
399
+ end: `${toTimestamp ?? now()}`,
400
+ step: 3600,
401
+ },
402
+ limit: 30 * 24,
403
+ queries: [
404
+ {
405
+ metricsQuery: {
406
+ query: "tlp_price",
407
+ alias: "",
408
+ id: "a",
409
+ labelSelector: {},
410
+ aggregate: null,
411
+ functions: [],
412
+ color: "",
413
+ disabled: false,
414
+ },
415
+ dataSource: "METRICS",
416
+ sourceName: "",
417
+ },
418
+ ],
419
+ formulas: [],
420
+ };
421
+ let jsonData = JSON.stringify(requestData);
422
+ let response = await fetch(apiUrl, {
423
+ method: "POST",
424
+ headers,
425
+ body: jsonData,
488
426
  });
427
+ let data = await response.json();
428
+ // console.log(data);
429
+ let samples = data.results[0].matrix.samples;
430
+ // console.log(samples[0].values);
431
+ return samples[0].values;
489
432
  }
490
- function getTlpComparisonFromSentio(startTimestamp, endTimestamp) {
491
- return __awaiter(this, void 0, void 0, function () {
492
- var apiUrl, requestData, jsonData, response, data;
493
- return __generator(this, function (_a) {
494
- switch (_a.label) {
495
- case 0:
496
- apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp_mainnet/sql/execute";
497
- requestData = {
498
- sqlQuery: {
499
- sql: "\n with\n tlp_hourly as (\n select\n toStartOfHour(timestamp + interval 30 minute) as hour,\n argMin(value, abs(toUnixTimestamp(timestamp) - toUnixTimestamp(toStartOfHour(timestamp + interval 30 minute)))) as tlp_price\n from tlp_price\n WHERE timestamp >= ".concat(startTimestamp, " and timestamp < ").concat(endTimestamp, "\n group by hour\n ),\n\n sui_hourly as (\n select\n toStartOfHour(time + interval 30 minute) as hour,\n argMin(price, abs(toUnixTimestamp(time) - toUnixTimestamp(toStartOfHour(time + interval 30 minute)))) as sui_price\n from 'token.prices'\n where symbol = 'sui'\n and time >= ").concat(startTimestamp, " and time < ").concat(endTimestamp, "\n group by hour\n ),\n\n merged as (\n select\n t.hour,\n t.tlp_price,\n s.sui_price\n from tlp_hourly t\n join sui_hourly s\n on t.hour = s.hour\n ),\n\n base as (\n select min(hour) as base_hour\n from merged\n ),\n base_prices as (\n select\n anyIf(m.tlp_price, m.hour = b.base_hour) as base_tlp,\n anyIf(m.sui_price, m.hour = b.base_hour) as base_sui\n from merged m\n cross join base b\n )\n\n select\n m.hour,\n m.tlp_price,\n m.sui_price,\n 100 * m.tlp_price / bp.base_tlp as tlp_value,\n 100 * m.sui_price / bp.base_sui as sui_value,\n 0.6 * (100 * m.sui_price / bp.base_sui) + 0.4 * 100 as portfolio_60sui_40usdc\n from merged m\n cross join base_prices bp\n order by m.hour;\n "),
500
- size: 10000,
501
- },
502
- };
503
- jsonData = JSON.stringify(requestData);
504
- return [4 /*yield*/, fetch(apiUrl, {
505
- method: "POST",
506
- headers: headers,
507
- body: jsonData,
508
- })];
509
- case 1:
510
- response = _a.sent();
511
- return [4 /*yield*/, response.json()];
512
- case 2:
513
- data = _a.sent();
514
- // console.log(data);
515
- if (data.result) {
516
- return [2 /*return*/, data.result.rows];
517
- }
518
- else {
519
- return [2 /*return*/, []];
520
- }
521
- return [2 /*return*/];
522
- }
523
- });
433
+ async function getTlpComparisonFromSentio(startTimestamp, endTimestamp) {
434
+ let apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp_mainnet/sql/execute";
435
+ let requestData = {
436
+ sqlQuery: {
437
+ sql: `
438
+ with
439
+ tlp_hourly as (
440
+ select
441
+ toStartOfHour(timestamp + interval 30 minute) as hour,
442
+ argMin(value, abs(toUnixTimestamp(timestamp) - toUnixTimestamp(toStartOfHour(timestamp + interval 30 minute)))) as tlp_price
443
+ from tlp_price
444
+ WHERE timestamp >= ${startTimestamp} and timestamp < ${endTimestamp}
445
+ group by hour
446
+ ),
447
+
448
+ sui_hourly as (
449
+ select
450
+ toStartOfHour(time + interval 30 minute) as hour,
451
+ argMin(price, abs(toUnixTimestamp(time) - toUnixTimestamp(toStartOfHour(time + interval 30 minute)))) as sui_price
452
+ from 'token.prices'
453
+ where symbol = 'sui'
454
+ and time >= ${startTimestamp} and time < ${endTimestamp}
455
+ group by hour
456
+ ),
457
+
458
+ merged as (
459
+ select
460
+ t.hour,
461
+ t.tlp_price,
462
+ s.sui_price
463
+ from tlp_hourly t
464
+ join sui_hourly s
465
+ on t.hour = s.hour
466
+ ),
467
+
468
+ base as (
469
+ select min(hour) as base_hour
470
+ from merged
471
+ ),
472
+ base_prices as (
473
+ select
474
+ anyIf(m.tlp_price, m.hour = b.base_hour) as base_tlp,
475
+ anyIf(m.sui_price, m.hour = b.base_hour) as base_sui
476
+ from merged m
477
+ cross join base b
478
+ )
479
+
480
+ select
481
+ m.hour,
482
+ m.tlp_price,
483
+ m.sui_price,
484
+ 100 * m.tlp_price / bp.base_tlp as tlp_value,
485
+ 100 * m.sui_price / bp.base_sui as sui_value,
486
+ 0.6 * (100 * m.sui_price / bp.base_sui) + 0.4 * 100 as portfolio_60sui_40usdc
487
+ from merged m
488
+ cross join base_prices bp
489
+ order by m.hour;
490
+ `,
491
+ size: 10000,
492
+ },
493
+ };
494
+ let jsonData = JSON.stringify(requestData);
495
+ let response = await fetch(apiUrl, {
496
+ method: "POST",
497
+ headers,
498
+ body: jsonData,
524
499
  });
500
+ let data = await response.json();
501
+ // console.log(data);
502
+ if (data.result) {
503
+ return data.result.rows;
504
+ }
505
+ else {
506
+ return [];
507
+ }
525
508
  }
526
- function getUserPnlFromSentio(startTimestamp, endTimestamp, userAddress) {
527
- return __awaiter(this, void 0, void 0, function () {
528
- var apiUrl, userFilter, requestData, jsonData, response, data;
529
- return __generator(this, function (_a) {
530
- switch (_a.label) {
531
- case 0:
532
- apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp_mainnet/sql/execute";
533
- userFilter = "";
534
- if (userAddress) {
535
- userFilter = "AND address == '".concat(userAddress, "'");
536
- }
537
- requestData = {
538
- sqlQuery: {
539
- sql: "\n WITH\n Pnl_history as (\n SELECT\n timestamp as time,\n CAST( realized_pnl AS Float64 ) as Trader_PnlUSD,\n filled_size * filled_price as volumeUSD,\n distinct_id as address\n from OrderFilled\n WHERE timestamp >= ".concat(startTimestamp, " and timestamp < ").concat(endTimestamp, "\n UNION ALL\n SELECT\n timestamp as time,\n CAST(value_for_lp_pool_usd + liquidator_fee_usd AS Float64) * (-1) as Trader_PnlUSD,\n 0 as volumeUSD,\n distinct_id as address\n from Liquidate -- collateral liquidate, liquidate fee\u4E0D\u7B97\n WHERE timestamp >= ").concat(startTimestamp, " and timestamp < ").concat(endTimestamp, "\n UNION ALL\n SELECT\n timestamp as time,\n CAST(realized_funding_fee_usd AS Float64) * (-1) as Trader_PnlUSD,\n 0 as volumeUSD,\n distinct_id as address\n from 'RealizeFunding' -- funding fee \u6B63\u7684\u662F user paid to pool\n WHERE timestamp >= ").concat(startTimestamp, " and timestamp < ").concat(endTimestamp, "\n UNION ALL\n SELECT\n timestamp as time,\n CAST(\n user_remaining_in_usd + (realized_loss_value - exercise_balance_value) * (user_remaining_in_usd / user_remaining_value) AS Float64\n ) as Trader_PnlUSD,\n 0 as volumeUSD,\n distinct_id as address\n from 'RealizeOption'\n WHERE timestamp >= ").concat(startTimestamp, " and timestamp < ").concat(endTimestamp, "\n ),\n sum_Trader_PnlUSD as (\n SELECT\n sum(Trader_PnlUSD) as Trader_PnlUSD,\n sum(volumeUSD) as volumeUSD,\n address\n from Pnl_history\n GROUP BY address\n )\n SELECT\n *\n from sum_Trader_PnlUSD\n where address not in (\n '0xc9ea1b9c3542551189cf26a08f5ca5ed7964aef34c14d06c888d30c8d91867e4',\n '0x83d2cb640ee252bae6b01bd6104c4afc69071e67b688db85a029ce452c61f11c',\n '0x39770d149a9bc9d9639314fca2c380e9061c0d230737635762c5bcc61dee13d0',\n '0x834d17f7b2e167cae224325a17b49babffe168182c418caa0c63a92d6f70b83a',\n '0xd35ae21660aee607ee21e104d093d03643d36efbf79df669092c4411308ed2e2',\n '0xe6cbba68c446f52cf8211c12ae79179233c8f9cec5e0b5008418ec339ca72fea'\n )\n ").concat(userFilter, "\n order by Trader_PnlUSD desc\n "),
540
- size: 100,
541
- },
542
- };
543
- jsonData = JSON.stringify(requestData);
544
- return [4 /*yield*/, fetch(apiUrl, {
545
- method: "POST",
546
- headers: headers,
547
- body: jsonData,
548
- })];
549
- case 1:
550
- response = _a.sent();
551
- return [4 /*yield*/, response.json()];
552
- case 2:
553
- data = _a.sent();
554
- // console.log(data);
555
- if (data.result) {
556
- return [2 /*return*/, data.result.rows];
557
- }
558
- else {
559
- return [2 /*return*/, []];
560
- }
561
- return [2 /*return*/];
562
- }
563
- });
509
+ async function getUserPnlFromSentio(startTimestamp, endTimestamp, userAddress) {
510
+ let apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp_mainnet/sql/execute";
511
+ let userFilter = "";
512
+ if (userAddress) {
513
+ userFilter = `AND address == '${userAddress}'`;
514
+ }
515
+ let requestData = {
516
+ sqlQuery: {
517
+ sql: `
518
+ WITH
519
+ Pnl_history as (
520
+ SELECT
521
+ timestamp as time,
522
+ CAST( realized_pnl AS Float64 ) as Trader_PnlUSD,
523
+ filled_size * filled_price as volumeUSD,
524
+ distinct_id as address
525
+ from OrderFilled
526
+ WHERE timestamp >= ${startTimestamp} and timestamp < ${endTimestamp}
527
+ UNION ALL
528
+ SELECT
529
+ timestamp as time,
530
+ CAST(value_for_lp_pool_usd + liquidator_fee_usd AS Float64) * (-1) as Trader_PnlUSD,
531
+ 0 as volumeUSD,
532
+ distinct_id as address
533
+ from Liquidate -- collateral liquidate, liquidate fee不算
534
+ WHERE timestamp >= ${startTimestamp} and timestamp < ${endTimestamp}
535
+ UNION ALL
536
+ SELECT
537
+ timestamp as time,
538
+ CAST(realized_funding_fee_usd AS Float64) * (-1) as Trader_PnlUSD,
539
+ 0 as volumeUSD,
540
+ distinct_id as address
541
+ from 'RealizeFunding' -- funding fee 正的是 user paid to pool
542
+ WHERE timestamp >= ${startTimestamp} and timestamp < ${endTimestamp}
543
+ UNION ALL
544
+ SELECT
545
+ timestamp as time,
546
+ CAST(
547
+ user_remaining_in_usd + (realized_loss_value - exercise_balance_value) * (user_remaining_in_usd / user_remaining_value) AS Float64
548
+ ) as Trader_PnlUSD,
549
+ 0 as volumeUSD,
550
+ distinct_id as address
551
+ from 'RealizeOption'
552
+ WHERE timestamp >= ${startTimestamp} and timestamp < ${endTimestamp}
553
+ ),
554
+ sum_Trader_PnlUSD as (
555
+ SELECT
556
+ sum(Trader_PnlUSD) as Trader_PnlUSD,
557
+ sum(volumeUSD) as volumeUSD,
558
+ address
559
+ from Pnl_history
560
+ GROUP BY address
561
+ )
562
+ SELECT
563
+ *
564
+ from sum_Trader_PnlUSD
565
+ where address not in (
566
+ '0xc9ea1b9c3542551189cf26a08f5ca5ed7964aef34c14d06c888d30c8d91867e4',
567
+ '0x83d2cb640ee252bae6b01bd6104c4afc69071e67b688db85a029ce452c61f11c',
568
+ '0x39770d149a9bc9d9639314fca2c380e9061c0d230737635762c5bcc61dee13d0',
569
+ '0x834d17f7b2e167cae224325a17b49babffe168182c418caa0c63a92d6f70b83a',
570
+ '0xd35ae21660aee607ee21e104d093d03643d36efbf79df669092c4411308ed2e2',
571
+ '0xe6cbba68c446f52cf8211c12ae79179233c8f9cec5e0b5008418ec339ca72fea'
572
+ )
573
+ ${userFilter}
574
+ order by Trader_PnlUSD desc
575
+ `,
576
+ size: 100,
577
+ },
578
+ };
579
+ let jsonData = JSON.stringify(requestData);
580
+ let response = await fetch(apiUrl, {
581
+ method: "POST",
582
+ headers,
583
+ body: jsonData,
564
584
  });
585
+ let data = await response.json();
586
+ // console.log(data);
587
+ if (data.result) {
588
+ return data.result.rows;
589
+ }
590
+ else {
591
+ return [];
592
+ }
565
593
  }
566
- function getLeaderboardFromSentio(startTs, endTs) {
567
- return __awaiter(this, void 0, void 0, function () {
568
- var apiUrl, size, requestData, jsonData, response, data;
569
- return __generator(this, function (_a) {
570
- switch (_a.label) {
571
- case 0:
572
- apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp_mainnet/sql/execute";
573
- size = (10 * (endTs - startTs)) / 60 / 60 / 24;
574
- requestData = {
575
- sqlQuery: {
576
- sql: "\n WITH\n event AS (\n SELECT\n timestamp,\n toDate(timestamp - INTERVAL 3 HOUR) AS logical_date,\n toDate(timestamp - INTERVAL 3 HOUR) AS date,\n score/power(10, 9) AS volume,\n distinct_id\n FROM Score\n ),\n sum_vol AS (\n SELECT\n logical_date,\n distinct_id,\n sum(volume) AS total_volume\n FROM event\n GROUP BY logical_date, distinct_id\n ),\n ranked AS (\n SELECT\n *,\n row_number() OVER (PARTITION BY logical_date ORDER BY total_volume DESC) AS rk\n FROM sum_vol\n ),\n top10 AS (\n SELECT *\n FROM ranked\n WHERE rk <= 10\n ),\n top10_sum AS (\n SELECT\n logical_date,\n sum(total_volume) AS top10_total_volume\n FROM top10\n GROUP BY logical_date\n )\n SELECT\n toDateTime(logical_date + INTERVAL 3 HOUR) AS Date,\n t.distinct_id as Address,\n t.total_volume as Trading_Vol,\n cast(t.total_volume AS Decimal256(18)) / cast(s.top10_total_volume AS Decimal256(18)) AS Volume_Share_Top10,\n Volume_Share_Top10 * 150 as PrizePool_Share\n FROM top10 t\n JOIN top10_sum s ON t.logical_date = s.logical_date\n WHERE Date >= ".concat(startTs, " AND Date < ").concat(endTs, "\n ORDER BY\n Date DESC,\n t.rk ASC,\n Volume_Share_Top10\n\n "),
577
- size: size,
578
- },
579
- };
580
- jsonData = JSON.stringify(requestData);
581
- return [4 /*yield*/, fetch(apiUrl, {
582
- method: "POST",
583
- headers: headers,
584
- body: jsonData,
585
- })];
586
- case 1:
587
- response = _a.sent();
588
- return [4 /*yield*/, response.json()];
589
- case 2:
590
- data = _a.sent();
591
- // console.log(data);
592
- if (data.result) {
593
- return [2 /*return*/, data.result.rows];
594
- }
595
- else {
596
- return [2 /*return*/, []];
597
- }
598
- return [2 /*return*/];
599
- }
600
- });
594
+ async function getLeaderboardFromSentio(startTs, endTs) {
595
+ let apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp_mainnet/sql/execute";
596
+ let size = (10 * (endTs - startTs)) / 60 / 60 / 24; // day * 10
597
+ let requestData = {
598
+ sqlQuery: {
599
+ sql: `
600
+ WITH
601
+ event AS (
602
+ SELECT
603
+ timestamp,
604
+ toDate(timestamp - INTERVAL 3 HOUR) AS logical_date,
605
+ toDate(timestamp - INTERVAL 3 HOUR) AS date,
606
+ score/power(10, 9) AS volume,
607
+ distinct_id
608
+ FROM Score
609
+ ),
610
+ sum_vol AS (
611
+ SELECT
612
+ logical_date,
613
+ distinct_id,
614
+ sum(volume) AS total_volume
615
+ FROM event
616
+ GROUP BY logical_date, distinct_id
617
+ ),
618
+ ranked AS (
619
+ SELECT
620
+ *,
621
+ row_number() OVER (PARTITION BY logical_date ORDER BY total_volume DESC) AS rk
622
+ FROM sum_vol
623
+ ),
624
+ top10 AS (
625
+ SELECT *
626
+ FROM ranked
627
+ WHERE rk <= 10
628
+ ),
629
+ top10_sum AS (
630
+ SELECT
631
+ logical_date,
632
+ sum(total_volume) AS top10_total_volume
633
+ FROM top10
634
+ GROUP BY logical_date
635
+ )
636
+ SELECT
637
+ toDateTime(logical_date + INTERVAL 3 HOUR) AS Date,
638
+ t.distinct_id as Address,
639
+ t.total_volume as Trading_Vol,
640
+ cast(t.total_volume AS Decimal256(18)) / cast(s.top10_total_volume AS Decimal256(18)) AS Volume_Share_Top10,
641
+ Volume_Share_Top10 * 150 as PrizePool_Share
642
+ FROM top10 t
643
+ JOIN top10_sum s ON t.logical_date = s.logical_date
644
+ WHERE Date >= ${startTs} AND Date < ${endTs}
645
+ ORDER BY
646
+ Date DESC,
647
+ t.rk ASC,
648
+ Volume_Share_Top10
649
+
650
+ `,
651
+ size,
652
+ },
653
+ };
654
+ let jsonData = JSON.stringify(requestData);
655
+ let response = await fetch(apiUrl, {
656
+ method: "POST",
657
+ headers,
658
+ body: jsonData,
601
659
  });
660
+ let data = await response.json();
661
+ // console.log(data);
662
+ if (data.result) {
663
+ return data.result.rows;
664
+ }
665
+ else {
666
+ return [];
667
+ }
602
668
  }
603
669
  // getRecentTradesFromSentio().then((x) => console.log(x));
604
670
  // getAccumulatedUser().then((x) => console.log(x));