@typus/typus-perp-sdk 1.1.32-type-test → 1.1.33

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