@typus/typus-sdk 1.4.3-c → 1.4.3-e

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 (248) hide show
  1. package/package.json +10 -2
  2. package/src/_dependencies/source/0x1/ascii/structs.ts +135 -0
  3. package/src/_dependencies/source/0x1/bit-vector/structs.ts +70 -0
  4. package/src/_dependencies/source/0x1/fixed-point32/structs.ts +69 -0
  5. package/src/_dependencies/source/0x1/index.ts +1 -0
  6. package/src/_dependencies/source/0x1/init.ts +16 -0
  7. package/src/_dependencies/source/0x1/option/structs.ts +74 -0
  8. package/src/_dependencies/source/0x1/string/structs.ts +70 -0
  9. package/src/_dependencies/source/0x1/type-name/structs.ts +70 -0
  10. package/src/_dependencies/source/0x1d17058789bd1e1e79f1a92424519a88146f191f58a06cc4d9ab23d17d46ab73/index.ts +1 -0
  11. package/src/_dependencies/source/0x1d17058789bd1e1e79f1a92424519a88146f191f58a06cc4d9ab23d17d46ab73/init.ts +14 -0
  12. package/src/_dependencies/source/0x1d17058789bd1e1e79f1a92424519a88146f191f58a06cc4d9ab23d17d46ab73/oracle/structs.ts +203 -0
  13. package/src/_dependencies/source/0x1d17058789bd1e1e79f1a92424519a88146f191f58a06cc4d9ab23d17d46ab73/pyth-parser/structs.ts +317 -0
  14. package/src/_dependencies/source/0x1d17058789bd1e1e79f1a92424519a88146f191f58a06cc4d9ab23d17d46ab73/supra/structs.ts +69 -0
  15. package/src/_dependencies/source/0x1d17058789bd1e1e79f1a92424519a88146f191f58a06cc4d9ab23d17d46ab73/switchboard-feed-parser/structs.ts +69 -0
  16. package/src/_dependencies/source/0x2/authenticator-state/structs.ts +332 -0
  17. package/src/_dependencies/source/0x2/bag/structs.ts +70 -0
  18. package/src/_dependencies/source/0x2/balance/structs.ts +134 -0
  19. package/src/_dependencies/source/0x2/bcs/structs.ts +70 -0
  20. package/src/_dependencies/source/0x2/bls12381/structs.ts +264 -0
  21. package/src/_dependencies/source/0x2/borrow/structs.ts +138 -0
  22. package/src/_dependencies/source/0x2/clock/structs.ts +70 -0
  23. package/src/_dependencies/source/0x2/coin/structs.ts +400 -0
  24. package/src/_dependencies/source/0x2/deny-list/structs.ts +139 -0
  25. package/src/_dependencies/source/0x2/display/structs.ts +202 -0
  26. package/src/_dependencies/source/0x2/dynamic-field/structs.ts +70 -0
  27. package/src/_dependencies/source/0x2/dynamic-object-field/structs.ts +71 -0
  28. package/src/_dependencies/source/0x2/groth16/structs.ts +265 -0
  29. package/src/_dependencies/source/0x2/group-ops/structs.ts +70 -0
  30. package/src/_dependencies/source/0x2/index.ts +1 -0
  31. package/src/_dependencies/source/0x2/init.ts +125 -0
  32. package/src/_dependencies/source/0x2/kiosk/structs.ts +658 -0
  33. package/src/_dependencies/source/0x2/kiosk-extension/structs.ts +135 -0
  34. package/src/_dependencies/source/0x2/linked-table/structs.ts +136 -0
  35. package/src/_dependencies/source/0x2/object/structs.ts +134 -0
  36. package/src/_dependencies/source/0x2/object-bag/structs.ts +70 -0
  37. package/src/_dependencies/source/0x2/object-table/structs.ts +70 -0
  38. package/src/_dependencies/source/0x2/package/structs.ts +267 -0
  39. package/src/_dependencies/source/0x2/priority-queue/structs.ts +139 -0
  40. package/src/_dependencies/source/0x2/random/structs.ts +202 -0
  41. package/src/_dependencies/source/0x2/sui/structs.ts +69 -0
  42. package/src/_dependencies/source/0x2/table/structs.ts +70 -0
  43. package/src/_dependencies/source/0x2/table-vec/structs.ts +71 -0
  44. package/src/_dependencies/source/0x2/token/structs.ts +401 -0
  45. package/src/_dependencies/source/0x2/transfer/structs.ts +70 -0
  46. package/src/_dependencies/source/0x2/transfer-policy/structs.ts +400 -0
  47. package/src/_dependencies/source/0x2/tx-context/structs.ts +70 -0
  48. package/src/_dependencies/source/0x2/url/structs.ts +70 -0
  49. package/src/_dependencies/source/0x2/vec-map/structs.ts +135 -0
  50. package/src/_dependencies/source/0x2/vec-set/structs.ts +72 -0
  51. package/src/_dependencies/source/0x2/versioned/structs.ts +135 -0
  52. package/src/_dependencies/source/0x2/zklogin-verified-id/structs.ts +71 -0
  53. package/src/_dependencies/source/0x2/zklogin-verified-issuer/structs.ts +71 -0
  54. package/src/_dependencies/source/0x277f90d256d1015a78cad646db091bec451c5bbab834b9fb70bace7885b5c698/index.ts +1 -0
  55. package/src/_dependencies/source/0x277f90d256d1015a78cad646db091bec451c5bbab834b9fb70bace7885b5c698/init.ts +5 -0
  56. package/src/_dependencies/source/0x277f90d256d1015a78cad646db091bec451c5bbab834b9fb70bace7885b5c698/validator/structs.ts +70 -0
  57. package/src/_dependencies/source/0x2fdff17b86e34ab722c8ba5e63f0da070d9a4163705b3fdc6a95802cab40a72a/index.ts +1 -0
  58. package/src/_dependencies/source/0x2fdff17b86e34ab722c8ba5e63f0da070d9a4163705b3fdc6a95802cab40a72a/init.ts +8 -0
  59. package/src/_dependencies/source/0x2fdff17b86e34ab722c8ba5e63f0da070d9a4163705b3fdc6a95802cab40a72a/price-data-pull/structs.ts +69 -0
  60. package/src/_dependencies/source/0x2fdff17b86e34ab722c8ba5e63f0da070d9a4163705b3fdc6a95802cab40a72a/suprasvaluefeed/structs.ts +135 -0
  61. package/src/_dependencies/source/0x4213e12a2220f15f1837a76897110d2260786558169bd8d0847f21e9b551f277/airdrop/structs.ts +400 -0
  62. package/src/_dependencies/source/0x4213e12a2220f15f1837a76897110d2260786558169bd8d0847f21e9b551f277/big-vector/structs.ts +372 -0
  63. package/src/_dependencies/source/0x4213e12a2220f15f1837a76897110d2260786558169bd8d0847f21e9b551f277/critbit/structs.ts +205 -0
  64. package/src/_dependencies/source/0x4213e12a2220f15f1837a76897110d2260786558169bd8d0847f21e9b551f277/ecosystem/structs.ts +333 -0
  65. package/src/_dependencies/source/0x4213e12a2220f15f1837a76897110d2260786558169bd8d0847f21e9b551f277/index.ts +1 -0
  66. package/src/_dependencies/source/0x4213e12a2220f15f1837a76897110d2260786558169bd8d0847f21e9b551f277/init.ts +48 -0
  67. package/src/_dependencies/source/0x4213e12a2220f15f1837a76897110d2260786558169bd8d0847f21e9b551f277/leaderboard/structs.ts +465 -0
  68. package/src/_dependencies/source/0x4213e12a2220f15f1837a76897110d2260786558169bd8d0847f21e9b551f277/linked-object-table/structs.ts +136 -0
  69. package/src/_dependencies/source/0x4213e12a2220f15f1837a76897110d2260786558169bd8d0847f21e9b551f277/linked-set/structs.ts +140 -0
  70. package/src/_dependencies/source/0x4213e12a2220f15f1837a76897110d2260786558169bd8d0847f21e9b551f277/tgld/structs.ts +268 -0
  71. package/src/_dependencies/source/0x4213e12a2220f15f1837a76897110d2260786558169bd8d0847f21e9b551f277/user/structs.ts +332 -0
  72. package/src/_dependencies/source/0x5cfd0819411be98034cba544cbffab192c2c35674a05ff57f4f1c5042875b828/discount-mint/structs.ts +466 -0
  73. package/src/_dependencies/source/0x5cfd0819411be98034cba544cbffab192c2c35674a05ff57f4f1c5042875b828/index.ts +1 -0
  74. package/src/_dependencies/source/0x5cfd0819411be98034cba544cbffab192c2c35674a05ff57f4f1c5042875b828/init.ts +36 -0
  75. package/src/_dependencies/source/0x5cfd0819411be98034cba544cbffab192c2c35674a05ff57f4f1c5042875b828/royalty-rule/structs.ts +134 -0
  76. package/src/_dependencies/source/0x5cfd0819411be98034cba544cbffab192c2c35674a05ff57f4f1c5042875b828/staking/structs.ts +333 -0
  77. package/src/_dependencies/source/0x5cfd0819411be98034cba544cbffab192c2c35674a05ff57f4f1c5042875b828/table-vec/structs.ts +71 -0
  78. package/src/_dependencies/source/0x5cfd0819411be98034cba544cbffab192c2c35674a05ff57f4f1c5042875b828/typus-nft/structs.ts +856 -0
  79. package/src/_dependencies/source/0x6c9a394a43844fc09d9617bc8a8e775a4521f0e28e83de1da780d043a498671f/auto-bid/structs.ts +1049 -0
  80. package/src/_dependencies/source/0x6c9a394a43844fc09d9617bc8a8e775a4521f0e28e83de1da780d043a498671f/index.ts +1 -0
  81. package/src/_dependencies/source/0x6c9a394a43844fc09d9617bc8a8e775a4521f0e28e83de1da780d043a498671f/init.ts +104 -0
  82. package/src/_dependencies/source/0x6c9a394a43844fc09d9617bc8a8e775a4521f0e28e83de1da780d043a498671f/tails-staking/structs.ts +1054 -0
  83. package/src/_dependencies/source/0x6c9a394a43844fc09d9617bc8a8e775a4521f0e28e83de1da780d043a498671f/tds-authorized-entry/structs.ts +592 -0
  84. package/src/_dependencies/source/0x6c9a394a43844fc09d9617bc8a8e775a4521f0e28e83de1da780d043a498671f/tds-fee-pool-entry/structs.ts +461 -0
  85. package/src/_dependencies/source/0x6c9a394a43844fc09d9617bc8a8e775a4521f0e28e83de1da780d043a498671f/tds-registry-authorized-entry/structs.ts +592 -0
  86. package/src/_dependencies/source/0x6c9a394a43844fc09d9617bc8a8e775a4521f0e28e83de1da780d043a498671f/tds-view-function/structs.ts +69 -0
  87. package/src/_dependencies/source/0x6c9a394a43844fc09d9617bc8a8e775a4521f0e28e83de1da780d043a498671f/typus-dov-single/structs.ts +2351 -0
  88. package/src/_dependencies/source/0x7237ec8436ef7e927c45470db6db3a834dd84cf903aedee3844e847fe4805399/index.ts +1 -0
  89. package/src/_dependencies/source/0x7237ec8436ef7e927c45470db6db3a834dd84cf903aedee3844e847fe4805399/init.ts +3 -0
  90. package/src/_dependencies/source/0x908a10789a1a6953e0b73a997c10e3552f7ce4e2907afd00a334ed74bd973ded/authority/structs.ts +71 -0
  91. package/src/_dependencies/source/0x908a10789a1a6953e0b73a997c10e3552f7ce4e2907afd00a334ed74bd973ded/balance-pool/structs.ts +203 -0
  92. package/src/_dependencies/source/0x908a10789a1a6953e0b73a997c10e3552f7ce4e2907afd00a334ed74bd973ded/big-vector/structs.ts +70 -0
  93. package/src/_dependencies/source/0x908a10789a1a6953e0b73a997c10e3552f7ce4e2907afd00a334ed74bd973ded/dutch/structs.ts +528 -0
  94. package/src/_dependencies/source/0x908a10789a1a6953e0b73a997c10e3552f7ce4e2907afd00a334ed74bd973ded/i64/structs.ts +69 -0
  95. package/src/_dependencies/source/0x908a10789a1a6953e0b73a997c10e3552f7ce4e2907afd00a334ed74bd973ded/index.ts +1 -0
  96. package/src/_dependencies/source/0x908a10789a1a6953e0b73a997c10e3552f7ce4e2907afd00a334ed74bd973ded/init.ts +54 -0
  97. package/src/_dependencies/source/0x908a10789a1a6953e0b73a997c10e3552f7ce4e2907afd00a334ed74bd973ded/linked-list/structs.ts +136 -0
  98. package/src/_dependencies/source/0x908a10789a1a6953e0b73a997c10e3552f7ce4e2907afd00a334ed74bd973ded/vault/structs.ts +1829 -0
  99. package/src/_dependencies/source/0x98670585b87e06628ef2d7f7cb1e7bee8ada65b43b82997935225a7e6e21d18e/aggregator/structs.ts +398 -0
  100. package/src/_dependencies/source/0x98670585b87e06628ef2d7f7cb1e7bee8ada65b43b82997935225a7e6e21d18e/index.ts +1 -0
  101. package/src/_dependencies/source/0x98670585b87e06628ef2d7f7cb1e7bee8ada65b43b82997935225a7e6e21d18e/init.ts +18 -0
  102. package/src/_dependencies/source/0x98670585b87e06628ef2d7f7cb1e7bee8ada65b43b82997935225a7e6e21d18e/job/structs.ts +71 -0
  103. package/src/_dependencies/source/0x98670585b87e06628ef2d7f7cb1e7bee8ada65b43b82997935225a7e6e21d18e/math/structs.ts +69 -0
  104. package/src/_dependencies/source/0x98670585b87e06628ef2d7f7cb1e7bee8ada65b43b82997935225a7e6e21d18e/quote/structs.ts +71 -0
  105. package/src/_dependencies/source/0x98670585b87e06628ef2d7f7cb1e7bee8ada65b43b82997935225a7e6e21d18e/switchboard/structs.ts +70 -0
  106. package/src/_dependencies/source/0xbd8fc1947cf119350184107a3087e2dc27efefa0dd82e25a1f699069fe81a585/index.ts +1 -0
  107. package/src/_dependencies/source/0xbd8fc1947cf119350184107a3087e2dc27efefa0dd82e25a1f699069fe81a585/init.ts +11 -0
  108. package/src/_dependencies/source/0xbd8fc1947cf119350184107a3087e2dc27efefa0dd82e25a1f699069fe81a585/kiosk-lock-rule/structs.ts +134 -0
  109. package/src/_dependencies/source/0xbd8fc1947cf119350184107a3087e2dc27efefa0dd82e25a1f699069fe81a585/royalty-rule/structs.ts +134 -0
  110. package/src/_dependencies/source/0xbd8fc1947cf119350184107a3087e2dc27efefa0dd82e25a1f699069fe81a585/witness-rule/structs.ts +69 -0
  111. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/bytes20/structs.ts +70 -0
  112. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/bytes32/structs.ts +70 -0
  113. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/consumed-vaas/structs.ts +72 -0
  114. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/cursor/structs.ts +72 -0
  115. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/emitter/structs.ts +200 -0
  116. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/external-address/structs.ts +70 -0
  117. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/fee-collector/structs.ts +72 -0
  118. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/governance-message/structs.ts +137 -0
  119. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/guardian/structs.ts +70 -0
  120. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/guardian-set/structs.ts +71 -0
  121. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/guardian-signature/structs.ts +70 -0
  122. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/index.ts +1 -0
  123. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/init.ts +65 -0
  124. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/migrate/structs.ts +70 -0
  125. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/package-utils/structs.ts +266 -0
  126. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/publish-message/structs.ts +136 -0
  127. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/set/structs.ts +136 -0
  128. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/set-fee/structs.ts +134 -0
  129. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/setup/structs.ts +70 -0
  130. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/state/structs.ts +142 -0
  131. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/transfer-fee/structs.ts +134 -0
  132. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/update-guardian-set/structs.ts +201 -0
  133. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/upgrade-contract/structs.ts +201 -0
  134. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/vaa/structs.ts +72 -0
  135. package/src/_dependencies/source/0xcc029e2810f17f9f43f52262f40026a71fbdca40ed3803ad2884994361910b7e/version-control/structs.ts +134 -0
  136. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/batch-price-attestation/structs.ts +136 -0
  137. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/contract-upgrade/structs.ts +136 -0
  138. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/data-source/structs.ts +70 -0
  139. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/event/structs.ts +135 -0
  140. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/governance/structs.ts +71 -0
  141. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/governance-action/structs.ts +69 -0
  142. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/governance-instruction/structs.ts +71 -0
  143. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/hot-potato-vector/structs.ts +72 -0
  144. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/i64/structs.ts +69 -0
  145. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/index.ts +1 -0
  146. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/init.ts +59 -0
  147. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/migrate/structs.ts +70 -0
  148. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/price/structs.ts +70 -0
  149. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/price-feed/structs.ts +71 -0
  150. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/price-identifier/structs.ts +70 -0
  151. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/price-info/structs.ts +136 -0
  152. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/price-status/structs.ts +69 -0
  153. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/set/structs.ts +138 -0
  154. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/set-data-sources/structs.ts +71 -0
  155. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/set-fee-recipient/structs.ts +69 -0
  156. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/set-governance-data-source/structs.ts +70 -0
  157. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/set-stale-price-threshold/structs.ts +69 -0
  158. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/set-update-fee/structs.ts +69 -0
  159. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/setup/structs.ts +70 -0
  160. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/state/structs.ts +203 -0
  161. package/src/_dependencies/source/0xe76d8a37d4132278a7a752183e90e04890b9e7d0f6657eadb68821609a2a56a3/version-control/structs.ts +134 -0
  162. package/src/_framework/init-source.ts +39 -0
  163. package/src/_framework/loader.ts +69 -0
  164. package/src/_framework/reified.ts +442 -0
  165. package/src/_framework/util.ts +265 -0
  166. package/src/airdrop/authority-entry.ts +101 -0
  167. package/src/airdrop/index.ts +3 -0
  168. package/src/airdrop/user-entry.ts +24 -0
  169. package/src/airdrop/view-function.ts +36 -0
  170. package/src/auto-bid/index.ts +2 -0
  171. package/src/auto-bid/user-entry.ts +256 -0
  172. package/src/auto-bid/view-function.ts +285 -0
  173. package/src/constants/constant.ts +32 -0
  174. package/src/constants/index.ts +2 -0
  175. package/src/constants/token.ts +194 -0
  176. package/src/index.ts +11 -0
  177. package/src/leaderboard/authority-entry.ts +63 -0
  178. package/src/leaderboard/index.ts +2 -0
  179. package/src/leaderboard/view-function.ts +66 -0
  180. package/src/tails-exp-dice/api.ts +46 -0
  181. package/src/tails-exp-dice/fetch.ts +347 -0
  182. package/src/tails-exp-dice/index.ts +4 -0
  183. package/src/tails-exp-dice/user-entry.ts +241 -0
  184. package/src/tails-exp-dice/view-function.ts +111 -0
  185. package/src/tails-staking/authority-entry.ts +333 -0
  186. package/src/tails-staking/index.ts +3 -0
  187. package/src/tails-staking/user-entry.ts +401 -0
  188. package/src/tails-staking/view-function.ts +86 -0
  189. package/src/typus-dov-single-v2/entry/authority-entry.ts +171 -0
  190. package/src/typus-dov-single-v2/entry/index.ts +3 -0
  191. package/src/typus-dov-single-v2/entry/mfud-user-entry.ts +591 -0
  192. package/src/typus-dov-single-v2/entry/user-entry.ts +573 -0
  193. package/src/typus-dov-single-v2/function/bidding.ts +823 -0
  194. package/src/typus-dov-single-v2/function/index.ts +3 -0
  195. package/src/typus-dov-single-v2/function/token.ts +38 -0
  196. package/src/typus-dov-single-v2/function/vault.ts +24 -0
  197. package/src/typus-dov-single-v2/history/index.ts +2 -0
  198. package/src/typus-dov-single-v2/history/user-history.ts +929 -0
  199. package/src/typus-dov-single-v2/history/vault-history.ts +452 -0
  200. package/src/typus-dov-single-v2/index.ts +4 -0
  201. package/src/typus-dov-single-v2/view-function.ts +705 -0
  202. package/src/typus-nft/fetch.ts +428 -0
  203. package/src/typus-nft/index.ts +2 -0
  204. package/src/typus-nft/user-entry.ts +113 -0
  205. package/src/typus-perp/admin/functions.ts +141 -0
  206. package/src/typus-perp/admin/structs.ts +793 -0
  207. package/src/typus-perp/fetch.ts +253 -0
  208. package/src/typus-perp/index.ts +9 -0
  209. package/src/typus-perp/init.ts +96 -0
  210. package/src/typus-perp/lp-pool/functions.ts +694 -0
  211. package/src/typus-perp/lp-pool/structs.ts +3884 -0
  212. package/src/typus-perp/math/functions.ts +53 -0
  213. package/src/typus-perp/oracle/functions.ts +32 -0
  214. package/src/typus-perp/oracle/structs.ts +317 -0
  215. package/src/typus-perp/position/functions.ts +887 -0
  216. package/src/typus-perp/position/structs.ts +1637 -0
  217. package/src/typus-perp/readVec.ts +118 -0
  218. package/src/typus-perp/stake-pool/functions.ts +421 -0
  219. package/src/typus-perp/stake-pool/structs.ts +3873 -0
  220. package/src/typus-perp/symbol/functions.ts +24 -0
  221. package/src/typus-perp/symbol/structs.ts +165 -0
  222. package/src/typus-perp/tlp/functions.ts +50 -0
  223. package/src/typus-perp/tlp/structs.ts +287 -0
  224. package/src/typus-perp/token-interface/functions.ts +29 -0
  225. package/src/typus-perp/trading/functions.ts +1046 -0
  226. package/src/typus-perp/trading/structs.ts +4541 -0
  227. package/src/typus-perp/treasury-caps/functions.ts +36 -0
  228. package/src/typus-perp/treasury-caps/structs.ts +151 -0
  229. package/src/typus-perp/user/order.ts +221 -0
  230. package/src/typus-perp/user/orderWithBidReceipt.ts +176 -0
  231. package/src/typus-perp/user/tlp.ts +234 -0
  232. package/src/user/index.ts +1 -0
  233. package/src/user/view-function.ts +33 -0
  234. package/src/utils/.DS_Store +0 -0
  235. package/src/utils/api/defillama/index.ts +1 -0
  236. package/src/utils/api/defillama/tvl.ts +11 -0
  237. package/src/utils/api/index.ts +3 -0
  238. package/src/utils/api/price.ts +101 -0
  239. package/src/utils/api/sentio/index.ts +2 -0
  240. package/src/utils/api/sentio/leader-board.ts +259 -0
  241. package/src/utils/api/sentio/reward-generated.ts +392 -0
  242. package/src/utils/index.ts +5 -0
  243. package/src/utils/load_env.ts +5 -0
  244. package/src/utils/mint.ts +16 -0
  245. package/src/utils/pyth/constant.ts +71 -0
  246. package/src/utils/pyth/index.ts +2 -0
  247. package/src/utils/pyth/pythClient.ts +52 -0
  248. package/src/utils/tools.ts +38 -0
@@ -0,0 +1,823 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { Connection, PublicKey } from "@solana/web3.js";
3
+ import { PythHttpClient, getPythClusterApiUrl, getPythProgramKeyForCluster, PythCluster, PriceData } from "@pythnetwork/client";
4
+ import { orderBy } from "lodash";
5
+ import moment from "moment";
6
+ import { SuiClient } from "@mysten/sui.js/dist/cjs/client";
7
+ import { Auction, BidShare, Vault, getAuctions, getMyBids, getVaults } from "../view-function";
8
+ import { AbbrStrategyName, Period, parseAssets } from "./vault";
9
+ import { StableCoin, getTokenName } from "./token";
10
+ import { checkNumber, countFloating, insertAt } from "src/utils/tools";
11
+ import { getUserStrategies } from "src/auto-bid/view-function";
12
+ import { typeArgsToAssets } from "src/constants/token";
13
+ import { WrappedToken } from "./token";
14
+ import { getLatestPrice } from "src/utils/api/price";
15
+ import config from "../../../config.json";
16
+
17
+ const PriceDecimal = BigNumber(10).pow(8);
18
+
19
+ export const ASSET_INFO = {
20
+ BTC: {
21
+ product: new PublicKey("4aDoSXJ5o3AuvL7QFeR6h44jALQfTmUUCTVGDD6aoJTM"),
22
+ price: new PublicKey("GVXRSBjFk6e6J3NbVPXohDJetcTjaeeuykUpbQF8UoMU"),
23
+ },
24
+ ETH: {
25
+ product: new PublicKey("EMkxjGC1CQ7JLiutDbfYb7UKb3zm9SJcUmr1YicBsdpZ"),
26
+ price: new PublicKey("JBu1AL4obBcCMqKBBxhpWCNUt136ijcuMZLFvTP7iWdB"),
27
+ },
28
+ SUI: {
29
+ product: new PublicKey("2F8rfBf4z4SzNpeQstFTpLXTQQ7RNKsLFqPdbpybooCc"),
30
+ price: new PublicKey("3Qub3HaAJaa2xNY7SUqPKd3vVwTqDfDDkEUMPjXD2c1q"),
31
+ },
32
+ CETUS: {
33
+ product: new PublicKey("JDHPsM1zxsZ6TfDwpCVzo41DAZdRi6ZmhkzWU1iXvSQ"),
34
+ price: new PublicKey("GTeC2JfBFrHuYkBivDQcNdLY74X5FRDLEJntnxPKRQbY"),
35
+ },
36
+ SEI: {
37
+ product: new PublicKey("24bB1mRGsrrDVawJTCVYXrxbEz6ozztukPUKvcZCDcPz"),
38
+ price: new PublicKey("6cUuAyAX3eXoiWkjFF77RQBEUF15AAMQ7d1hm4EPd3tv"),
39
+ },
40
+ USDC: {
41
+ product: new PublicKey("8GWTTbNiXdmyZREXbjsZBmCRuzdPrW55dnZGDkTRjWvb"),
42
+ price: new PublicKey("Gnt27xtC473ZT2Mw5u8wZ68Z3gULkSTb5DuxJy7eJotD"),
43
+ },
44
+ USDT: {
45
+ product: new PublicKey("Av6XyAMJnyi68FdsKSPYgzfXGjYrrt6jcAMwtvzLCqaM"),
46
+ price: new PublicKey("3vxLXJqLqF3JG5TCbYycbKWRBbCJQLxQmBGCkyqEEefL"),
47
+ },
48
+ TURBOS: {
49
+ product: new PublicKey("8DZUgXNQo5Um1pqo4gzv9oWPUZpyKV9nXm51gysZFMef"),
50
+ price: new PublicKey("HoxttzPFzcPvpZhUY8LCLkFNn9keDnBrctno4wXEhpFk"),
51
+ },
52
+ APT: {
53
+ product: new PublicKey("6bQMDtuAmRgjvymdWk9w4tTc9YyuXcjMxF8MyPHXejsx"),
54
+ price: new PublicKey("FNNvb1AFDnDVPkocEri8mWbJ1952HQZtFLuwPiUjSJQ"),
55
+ },
56
+ SOL: {
57
+ product: new PublicKey("ALP8SdU9oARYVLgLR7LrqMNCYBnhtnQz1cj6bwgwQmgj"),
58
+ price: new PublicKey("H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG"),
59
+ },
60
+ INJ: {
61
+ product: new PublicKey("5Q5kyCVzssrGMd2BniSdVeRwjNWrGGrFhMrgGt4zURyA"),
62
+ price: new PublicKey("9EdtbaivHQYA4Nh3XzGR6DwRaoorqXYnmpfsnFhvwuVj"),
63
+ },
64
+ JUP: {
65
+ product: new PublicKey("AykbyeHZbUbEtEAPVpBLoPAMHBrUrDMtXJkPWZw4TRDX"),
66
+ price: new PublicKey("g6eRCbboSwK4tSWngn773RCMexr1APQr4uA9bGZBYfo"),
67
+ },
68
+ HASUI: {
69
+ product: new PublicKey("FGJutsZ3Hr9BaamiNUq369AamUEMArCxFeMnjZZ1u4oG"),
70
+ price: new PublicKey("7Y9jRRHvqig2wdSkjnACwt1SV1qocjY81C9nKKVJ6zJs"),
71
+ },
72
+ VSUI: {
73
+ product: new PublicKey("9L4zWUnRWEqHT9fvH5WkmQgXf7qrr97SGV4pofTSdK5k"),
74
+ price: new PublicKey("6vWPEigSDaAi6m6HuX24aK4fJGJxvQZ8TLQKADC65S2S"),
75
+ },
76
+ };
77
+
78
+ export const tokenOrder: { [key: string]: number } = {
79
+ // Basically it's a to z but put SUI at first
80
+ SUI: 0,
81
+ AFSUI: 1,
82
+ APT: 2,
83
+ WBTC: 3,
84
+ BTC: 3,
85
+ BUCK: 4,
86
+ CETUS: 5,
87
+ WETH: 6,
88
+ ETH: 6,
89
+ FUD: 7,
90
+ INJ: 8,
91
+ JUP: 9,
92
+ NAVX: 10,
93
+ SCA: 11,
94
+ SEI: 12,
95
+ WSOL: 13,
96
+ SOL: 14,
97
+ TURBOS: 15,
98
+ USDC: 16,
99
+ USDT: 17,
100
+ USDY: 18,
101
+ VSUI: 20,
102
+ };
103
+
104
+ export const optionTypeOrder: { [key: string]: number } = {
105
+ 0: 0,
106
+ 1: 2,
107
+ 2: 3,
108
+ 4: 4,
109
+ 6: 5,
110
+ 5: 6,
111
+ };
112
+
113
+ export const periodOrder: { [key: string]: number } = {
114
+ 0: 1,
115
+ 1: 2,
116
+ 2: 3,
117
+ 3: 0,
118
+ };
119
+
120
+ export type Receipt = {
121
+ id: string;
122
+ index: string;
123
+ name: string;
124
+ description: string;
125
+ vid: string;
126
+ };
127
+
128
+ export type TokenAmount = {
129
+ value: string;
130
+ token: string;
131
+ };
132
+
133
+ export type BidVaultInfo = { vaultInfo: Vault; receipt: Receipt };
134
+
135
+ export interface Bid {
136
+ vaultIndex: string;
137
+ expiry: string;
138
+ auctionName: string;
139
+ strikes: string[];
140
+ bidSize: TokenAmount;
141
+ breakEvenPrice: string;
142
+ estPnls: TokenAmount[];
143
+ receiptsId: string[];
144
+ receiptsVid: string[];
145
+ settlePrice: string;
146
+ isAutoBid: boolean;
147
+ }
148
+
149
+ export interface OrderBy {
150
+ tokenOrder: number;
151
+ optionTypeOrder: number;
152
+ periodOrder: number;
153
+ }
154
+
155
+ export interface CoinInfo {
156
+ price: string;
157
+ decimal: string;
158
+ quote: string;
159
+ }
160
+
161
+ export const IncentiveRateBp = 4;
162
+
163
+ const DefaultOracleDecimal: { [key: string]: string } = {
164
+ ETH: "8",
165
+ SUI: "8",
166
+ AFSUI: "8",
167
+ BTC: "8",
168
+ DOGE: "8",
169
+ APT: "8",
170
+ SOL: "8",
171
+ USDC: "8",
172
+ USDT: "8",
173
+ CETUS: "8",
174
+ TURBOS: "8",
175
+ NAVX: "8",
176
+ JUP: "8",
177
+ BUCK: "8",
178
+ USDY: "8",
179
+ SEI: "8",
180
+ FUD: "8",
181
+ MFUD: "8",
182
+ INJ: "8",
183
+ SCA: "8",
184
+ VSUI: "8",
185
+ HASUI: "8",
186
+ };
187
+
188
+ export const parsePythOracleData = (data: PriceData[], decimals: { [key: string]: string }) => {
189
+ const prices: { [key: string]: CoinInfo } = {};
190
+ Object.entries(ASSET_INFO).forEach((p) => {
191
+ const asset = p[0].toUpperCase();
192
+ const coinData = data.find((s) => {
193
+ return s.productAccountKey.equals(p[1].product);
194
+ });
195
+ const decimal = decimals[asset];
196
+ if (decimal && coinData) {
197
+ prices[asset.toLowerCase()] = {
198
+ price: BigNumber(coinData.price ?? 0)
199
+ .multipliedBy(BigNumber(10).pow(decimal))
200
+ .toString(),
201
+ decimal,
202
+ quote: "usd",
203
+ };
204
+ if (WrappedToken[asset]) {
205
+ prices[WrappedToken[asset].toLowerCase()] = {
206
+ price: BigNumber(coinData.price ?? 0)
207
+ .multipliedBy(BigNumber(10).pow(decimal))
208
+ .toString(),
209
+ decimal,
210
+ quote: "usd",
211
+ };
212
+ }
213
+ }
214
+ });
215
+ return prices;
216
+ };
217
+
218
+ export const fetchPrices = async (provider: SuiClient, network: string): Promise<{ [key: string]: CoinInfo }> => {
219
+ const coinObjects = await provider.multiGetObjects({
220
+ ids: Object.values(config[network.toUpperCase()].ORACLE),
221
+ options: { showContent: true },
222
+ });
223
+
224
+ const oracleDecimal: { [key: string]: string } = {
225
+ ...DefaultOracleDecimal,
226
+ };
227
+
228
+ coinObjects.forEach((c) => {
229
+ // @ts-ignore
230
+ oracleDecimal[c.data?.content.fields.base_token] =
231
+ // @ts-ignore
232
+ c.data?.content.fields.decimal;
233
+ });
234
+
235
+ const PYTHNET_CLUSTER_NAME: PythCluster = "pythnet";
236
+ const connection = new Connection(getPythClusterApiUrl(PYTHNET_CLUSTER_NAME));
237
+ const pythPublicKey = getPythProgramKeyForCluster(PYTHNET_CLUSTER_NAME);
238
+ const pythClient = new PythHttpClient(connection, pythPublicKey);
239
+ const priceData = await pythClient.getAssetPricesFromAccounts(Object.values(ASSET_INFO).map((a) => a.price));
240
+ const prices = parsePythOracleData(priceData, oracleDecimal);
241
+
242
+ const suiusd = BigNumber(prices["sui"]?.price ?? 0);
243
+
244
+ const suifud = await getLatestPrice("SUIFUD");
245
+ const fudusd = suifud == "0" ? BigNumber(0) : suiusd.div(suifud);
246
+
247
+ const suiafsui = await getLatestPrice("SUIAFSUI");
248
+ const afsuiusd = suiafsui == "0" ? BigNumber(0) : suiusd.div(suiafsui);
249
+
250
+ const suinavx = await getLatestPrice("SUINAVX");
251
+ const navxusd = suiusd.div(suinavx);
252
+
253
+ const suibuck = await getLatestPrice("SUIBUCK");
254
+ const buckusd = BigNumber(suibuck).lte(0) ? "0" : suiusd.div(suibuck);
255
+
256
+ const usdyusdc = await getLatestPrice("USDYUSDC");
257
+ const usdyusdcWithDecimal = BigNumber(usdyusdc).multipliedBy(BigNumber(10).pow(8));
258
+
259
+ const scasui = await getLatestPrice("SCASUI");
260
+ const scausd = suiusd.eq(0) ? BigNumber(0) : BigNumber(scasui).multipliedBy(suiusd);
261
+
262
+ return {
263
+ fud: { price: fudusd.toString(), decimal: "8", quote: "usd" },
264
+ mfud: { price: fudusd.multipliedBy(1000000).toString(), decimal: "8", quote: "usd" },
265
+ afsui: { price: afsuiusd.toString(), decimal: "8", quote: "usd" },
266
+ navx: { price: navxusd.toString(), decimal: "8", quote: "usd" },
267
+ buck: { price: buckusd.toString(), decimal: "8", quote: "usd" },
268
+ usdy: { price: usdyusdcWithDecimal.toString(), decimal: "8", quote: "usd" },
269
+ sca: { price: scausd.toString(), decimal: "8", quote: "usd" },
270
+ ...prices,
271
+ };
272
+ };
273
+
274
+ export const calcIncentiveRate = (incentiveBp) => {
275
+ const incentiveRateBp = BigNumber(incentiveBp).div(BigNumber(10).pow(IncentiveRateBp));
276
+ let incentiveRate = 1;
277
+ if (incentiveRateBp.gt(0)) {
278
+ incentiveRate = 1 - Number(incentiveRateBp);
279
+ }
280
+
281
+ return incentiveRate;
282
+ };
283
+
284
+ export const calcDeliveryPrice = (bidShare: BidShare, vaultInfo: Vault) => {
285
+ const {
286
+ info: { bTokenDecimal },
287
+ } = vaultInfo;
288
+ let deliveryPrice = BigNumber("0");
289
+ // check if bid has settled already
290
+ if (bidShare.bidVault.u64Padding[1]) {
291
+ deliveryPrice = BigNumber(bidShare.bidVault.u64Padding[1]);
292
+ } else {
293
+ const deliveryInfos = vaultInfo.info.deliveryInfos.deliveryInfo;
294
+ const deliveryInfo = deliveryInfos[deliveryInfos.length - 1];
295
+ deliveryPrice = deliveryInfo ? BigNumber(deliveryInfo.deliveryPrice) : BigNumber("0");
296
+ }
297
+ deliveryPrice = BigNumber(deliveryPrice).div(BigNumber(10).pow(BigNumber(bTokenDecimal)));
298
+
299
+ return deliveryPrice;
300
+ };
301
+
302
+ export const calcBreakEvenPrice = (
303
+ optionType: string,
304
+ period: string,
305
+ strikes: string[],
306
+ bToken: string,
307
+ price: string,
308
+ incentive: number
309
+ ) => {
310
+ let breakEvenPrice = 0;
311
+ switch (optionType) {
312
+ case "0":
313
+ if (StableCoin.includes(bToken)) {
314
+ breakEvenPrice = Number(strikes[0]) + Number(price) * 1.1 * incentive;
315
+ } else {
316
+ breakEvenPrice = Number(strikes[0]) / (1 - Number(price) * 1.1 * incentive);
317
+ }
318
+ break;
319
+ case "1":
320
+ if (StableCoin.includes(bToken)) {
321
+ breakEvenPrice = Number(strikes[0]) - Number(price) * 1.1 * incentive;
322
+ } else {
323
+ breakEvenPrice = Number(strikes[0]) / (1 + Number(price) * 1.1 * incentive);
324
+ }
325
+ break;
326
+ case "2":
327
+ // Calculate with the lower one
328
+ if (StableCoin.includes(bToken)) {
329
+ breakEvenPrice = Number(strikes[0]) + Number(price) * 1.1 * incentive;
330
+ } else {
331
+ breakEvenPrice = Number(strikes[0]) / (1 - Number(price) * 1.1 * incentive);
332
+ }
333
+ break;
334
+ case "4":
335
+ // Calculate with the lower one
336
+ if (StableCoin.includes(bToken)) {
337
+ breakEvenPrice = Number(strikes[0]) + Number(price) * 1.1 * incentive;
338
+ } else {
339
+ breakEvenPrice = Number(strikes[0]) / (1 - Number(price) * 1.1 * incentive);
340
+ }
341
+ break;
342
+ case "5":
343
+ if (StableCoin.includes(bToken)) {
344
+ breakEvenPrice = Number(strikes[1]) - Number(price) * 1.1 * incentive;
345
+ } else {
346
+ breakEvenPrice = Number(strikes[1]) / (1 + Number(price) * 1.1 * incentive);
347
+ }
348
+
349
+ break;
350
+ case "6":
351
+ // Calculate with the lower one
352
+ if (StableCoin.includes(bToken)) {
353
+ breakEvenPrice = Number(strikes[0]) + Number(price) * 1.1 * incentive;
354
+ } else {
355
+ breakEvenPrice = Number(strikes[0]) / (1 + Number(price) * 1.1 * incentive);
356
+ }
357
+
358
+ break;
359
+ }
360
+
361
+ return breakEvenPrice;
362
+ };
363
+
364
+ export const calcEstPnl = (
365
+ live: boolean,
366
+ incentive: number,
367
+ bidSize: string,
368
+ optionType: string,
369
+ assets: string[],
370
+ strikes: string[],
371
+ bidShare: BidShare,
372
+ deliveryPrice: string,
373
+ oTokenPrice: string
374
+ ) => {
375
+ let profit = "0";
376
+ let cost = "0";
377
+ const [dToken, bToken, oToken] = typeArgsToAssets(assets);
378
+ const dTokenWrappedName = getTokenName({ token: dToken, wrapped: true });
379
+ const bTokenWrappedName = getTokenName({ token: bToken, wrapped: true });
380
+ const estPnls: TokenAmount[] = [];
381
+ const referencePrice =
382
+ bidShare.bidVault.u64Padding.length > 0 ? BigNumber(bidShare.bidVault.u64Padding[0]).div(PriceDecimal) : BigNumber(oTokenPrice);
383
+
384
+ if (optionType === "0") {
385
+ profit = BigNumber.max(
386
+ 0,
387
+ BigNumber(referencePrice.minus(BigNumber(strikes[0])))
388
+ .div(referencePrice)
389
+ .multipliedBy(bidSize)
390
+ ).toString();
391
+ } else if (optionType === "1") {
392
+ profit = BigNumber.max(0, BigNumber(strikes[0]).minus(referencePrice).multipliedBy(bidSize)).toString();
393
+ } else if (optionType === "2" || optionType === "4") {
394
+ profit = BigNumber.max(
395
+ 0,
396
+ BigNumber(referencePrice.minus(BigNumber(strikes[0])))
397
+ .div(referencePrice)
398
+ .multipliedBy(bidSize)
399
+ )
400
+ .minus(
401
+ BigNumber.max(
402
+ 0,
403
+ BigNumber(referencePrice.minus(BigNumber(strikes[1])))
404
+ .div(referencePrice)
405
+ .multipliedBy(bidSize)
406
+ )
407
+ )
408
+ .toString();
409
+ } else if (optionType === "5") {
410
+ profit = BigNumber.max(0, BigNumber(BigNumber(strikes[1]).minus(referencePrice)).multipliedBy(bidSize))
411
+ .minus(BigNumber.max(0, BigNumber(BigNumber(strikes[0]).minus(BigNumber(referencePrice))).multipliedBy(bidSize)))
412
+ .toString();
413
+ } else if (optionType === "6") {
414
+ profit = BigNumber.max(0, BigNumber(referencePrice.minus(strikes[0])).multipliedBy(bidSize))
415
+ .minus(BigNumber.max(0, BigNumber(referencePrice.minus(strikes[1])).multipliedBy(bidSize)))
416
+ .toString();
417
+ }
418
+
419
+ cost = BigNumber(deliveryPrice).multipliedBy(bidSize).multipliedBy(1.1).multipliedBy(incentive).toString();
420
+
421
+ if (dToken === bToken) {
422
+ profit = BigNumber(profit).minus(cost).toString();
423
+ }
424
+
425
+ if (!live) {
426
+ estPnls.push({
427
+ value: profit,
428
+ token: assets[0],
429
+ });
430
+ if (dToken !== bToken) {
431
+ estPnls.push({ value: "-" + cost, token: assets[1] });
432
+ }
433
+ }
434
+
435
+ return estPnls;
436
+ };
437
+
438
+ export const parseStrikes = (period: string, optionType: string, metadata: string) => {
439
+ let strikes = [period === "3" ? metadata.split("-")[3] : metadata.split("-")[2]];
440
+ switch (optionType) {
441
+ case "0":
442
+ break;
443
+ case "1":
444
+ break;
445
+ case "2":
446
+ strikes = [metadata.split("-")[2], metadata.split("-")[3]];
447
+
448
+ break;
449
+ case "4":
450
+ strikes = [metadata.split("-")[2], metadata.split("-")[3]];
451
+ if (period == "3") {
452
+ strikes = [metadata.split("-")[3], metadata.split("-")[4]];
453
+ }
454
+
455
+ strikes = strikes.sort((a, b) => Number(a) - Number(b));
456
+
457
+ break;
458
+ case "5":
459
+ strikes = [metadata.split("-")[2], metadata.split("-")[3]];
460
+
461
+ if (period == "3") {
462
+ strikes = [metadata.split("-")[3], metadata.split("-")[4]];
463
+ }
464
+ strikes = strikes.sort((a, b) => Number(a) - Number(b));
465
+
466
+ break;
467
+ case "6":
468
+ strikes = [metadata.split("-")[2], metadata.split("-")[3]];
469
+ if (period == "3") {
470
+ strikes = [metadata.split("-")[3], metadata.split("-")[4]];
471
+ }
472
+ strikes = strikes.sort((a, b) => Number(a) - Number(b));
473
+
474
+ break;
475
+ }
476
+
477
+ strikes = checkNumber(strikes[0]) ? strikes : [];
478
+ strikes = strikes.sort((a, b) => Number(a) - Number(b));
479
+
480
+ return strikes;
481
+ };
482
+
483
+ export const parseBidReceipt = (vaults: Vault[], bidReceipts: { [key: string]: Receipt[] }) => {
484
+ let sortedBidReceipts: string[] = [];
485
+ let bidVaultsInfo: BidVaultInfo[] = [];
486
+ let vidMap = new Map();
487
+ vaults.forEach((v) => {
488
+ let curReceipts = bidReceipts![v.info.index];
489
+ if (curReceipts) {
490
+ curReceipts.map((receipt) => {
491
+ // ###### NOTE: #####
492
+ // Bid receipts need to be sorted and put together
493
+ // BY vid for SDK getMyBids to fetch the correct data.
494
+ // ###########
495
+
496
+ // Filer out autoBidReceiptsData receipts cuz it's wrapped in strategy and
497
+ // SDK getMyBids can't retrieve it!
498
+ const data = vidMap.get(receipt.vid);
499
+ if (!data) {
500
+ vidMap.set(receipt.vid, [receipt.id]);
501
+ } else {
502
+ data.push(receipt.id);
503
+ vidMap.set(receipt.vid, data);
504
+ }
505
+
506
+ bidVaultsInfo.push({ vaultInfo: v, receipt: receipt });
507
+ });
508
+ const values = Array.from(vidMap.values());
509
+
510
+ sortedBidReceipts = values.reduce(function (previousValue, currentValue, currentIndex, array) {
511
+ return previousValue.concat(currentValue);
512
+ }, []);
513
+ }
514
+ });
515
+ return { sortedBidReceipts, bidVaultsInfo };
516
+ };
517
+
518
+ export const parseBid = (
519
+ bidVaultInfo: BidVaultInfo,
520
+ bidShare: BidShare,
521
+ auction: Auction | null,
522
+ oTokenPrice: string,
523
+ isAutoBid: boolean
524
+ ): Bid & OrderBy => {
525
+ const {
526
+ vaultInfo,
527
+ vaultInfo: {
528
+ info,
529
+ info: { index, bTokenDecimal, oTokenDecimal, optionType, period, depositToken, bidToken, settlementBase },
530
+ config: { bidLotSize: lotSize, bidIncentiveBp, u64Padding },
531
+ },
532
+ receipt,
533
+ } = bidVaultInfo;
534
+
535
+ const incentiveRate = calcIncentiveRate(bidIncentiveBp);
536
+
537
+ const [dToken, bToken, oToken] = parseAssets(info);
538
+
539
+ const oTokenName = getTokenName({ token: oToken });
540
+ const dTokenWrappedName = getTokenName({ token: dToken, wrapped: true });
541
+ const bTokenWrappedName = getTokenName({ token: bToken, wrapped: true });
542
+
543
+ const metadata = bidShare.bidVault.metadata;
544
+
545
+ const tokenLabel = metadata.split("-")[0];
546
+ const periodLabel = Period[Number(period)].charAt(0).toUpperCase() + Period[Number(period)].slice(1);
547
+
548
+ const optionTypeLabel = AbbrStrategyName[optionType];
549
+
550
+ const bidsSize = Number(bidShare.share) / 10 ** Number(oTokenDecimal);
551
+
552
+ let expirationDate = moment(metadata.split("-")[1], "DDMMMYY").format("yyyy-MM-DD");
553
+
554
+ expirationDate = moment
555
+ .utc(period === "3" ? `${expirationDate} ${insertAt(metadata.split("-")[2], ":", 2)}` : `${expirationDate} 08:00`)
556
+ .local()
557
+ .format("DD MMM YY, HH:mm");
558
+
559
+ const live = !auction
560
+ ? false
561
+ : moment.unix(Number(auction.endTsMs) / 1000).isAfter(moment()) &&
562
+ moment.unix(Number(auction.startTsMs) / 1000).isBefore(moment()) &&
563
+ moment(expirationDate, "DD MMM YY, HH:mm").isAfter(moment.unix(Number(auction.endTsMs) / 1000));
564
+
565
+ const deliveryPrice = calcDeliveryPrice(bidShare, vaultInfo);
566
+
567
+ let initialPrice: any = auction?.initialPrice ?? 0;
568
+ initialPrice = BigNumber(initialPrice).div(BigNumber(10).pow(BigNumber(bTokenDecimal)));
569
+
570
+ const strikes = parseStrikes(period, optionType, metadata);
571
+
572
+ const breakEvenPriceReference = live ? initialPrice : deliveryPrice;
573
+ const breakEvenPrice = calcBreakEvenPrice(optionType, period, strikes, bToken, breakEvenPriceReference, incentiveRate);
574
+
575
+ const defaultMinBidSize = BigNumber(lotSize).div(BigNumber(10).pow(oTokenDecimal));
576
+ const bidSize = bidsSize.toFixed(countFloating(defaultMinBidSize.toNumber()));
577
+
578
+ const settlePrice = BigNumber(bidShare.bidVault.u64Padding[0] ?? "0").div(PriceDecimal);
579
+
580
+ const estPnls = calcEstPnl(
581
+ live,
582
+ incentiveRate,
583
+ bidSize,
584
+ optionType,
585
+ [depositToken, bidToken, settlementBase],
586
+ strikes,
587
+ bidShare,
588
+ deliveryPrice.toString(),
589
+ oTokenPrice
590
+ );
591
+
592
+ return {
593
+ vaultIndex: index,
594
+ auctionName: `${tokenLabel} ${periodLabel} ${optionTypeLabel}`,
595
+ expiry: expirationDate,
596
+ strikes: strikes.map((s) => {
597
+ if (tokenLabel === "MFUD") {
598
+ return BigNumber(s).div(1000000).toString();
599
+ }
600
+ return s;
601
+ }),
602
+ bidSize: {
603
+ value: BigNumber(bidSize)
604
+ .div(BigNumber(10).pow(oToken === "MFUD" ? 6 : 0))
605
+ .toString(),
606
+ token: settlementBase,
607
+ },
608
+ breakEvenPrice: BigNumber(breakEvenPrice)
609
+ .div(BigNumber(10).pow(oToken === "MFUD" ? 6 : 0))
610
+ .toString(),
611
+ settlePrice: BigNumber(settlePrice)
612
+ .div(BigNumber(10).pow(oToken === "MFUD" ? 6 : 0))
613
+ .toString(),
614
+ estPnls,
615
+ isAutoBid,
616
+ receiptsId: [receipt.id],
617
+ receiptsVid: [receipt.vid],
618
+ optionTypeOrder: optionTypeOrder[optionType],
619
+ periodOrder: periodOrder[period],
620
+ tokenOrder: tokenOrder[oToken.toUpperCase()],
621
+ };
622
+ };
623
+
624
+ export const getUserBidReceipts = async (provider: SuiClient, network: string, originFramworkAddress: string, userAddress: string) => {
625
+ const bidReceipts: { [key: string]: Receipt[] } = {};
626
+ let result = await provider.getOwnedObjects({ owner: userAddress, options: { showType: true, showContent: true } });
627
+
628
+ let hasNextPage = result.hasNextPage;
629
+ let data = result.data;
630
+ let nextCursor = result.nextCursor;
631
+ while (hasNextPage) {
632
+ result = await provider.getOwnedObjects({ owner: userAddress, cursor: nextCursor, options: { showType: true, showContent: true } });
633
+ data = [...data, ...result.data];
634
+ hasNextPage = result.hasNextPage;
635
+ nextCursor = result.nextCursor;
636
+ }
637
+
638
+ if (data.length === 0) {
639
+ return bidReceipts;
640
+ }
641
+
642
+ for (const object of data) {
643
+ try {
644
+ const { content } = object.data || {};
645
+ if (!content) continue;
646
+
647
+ const typeStringComponents = ((content as any).type || "").split("<");
648
+ const subtype = (typeStringComponents[1] || "").replace(/>/, "");
649
+ const typeComponents = typeStringComponents[0].split("::");
650
+ const type = typeComponents[typeComponents.length - 1];
651
+ const typePackage = typeComponents[0];
652
+
653
+ if (type === "TypusBidReceipt" && originFramworkAddress == typePackage) {
654
+ // @ts-ignore
655
+ const vaultIndex = content.fields.index;
656
+ const receipt = {
657
+ // @ts-ignore
658
+ id: content.fields.id.id,
659
+ // @ts-ignore
660
+ index: vaultIndex,
661
+ // @ts-ignore
662
+ name: content.fields.name,
663
+ // @ts-ignore
664
+ description: content.fields.description,
665
+ // @ts-ignore
666
+ vid: content.fields.vid,
667
+ // @ts-ignore
668
+ metadata: content.fields.metadata,
669
+ };
670
+ bidReceipts[vaultIndex] ||= [];
671
+ bidReceipts[vaultIndex].push(receipt);
672
+ }
673
+ } catch (e) {
674
+ console.log("Error retrieving object", object, e);
675
+ }
676
+ }
677
+ return bidReceipts;
678
+ };
679
+
680
+ /**
681
+ * Fetch user's bids info
682
+ *
683
+ * @param provider - Sui Client instance.
684
+ * @param network - network type in lowercase.
685
+ * @param packageAddress - Typus main package address.
686
+ * @param framworkAddress - Typus framwork package address.
687
+ * @param originFramworkAddress - Typus intial framwork package address.
688
+ * @param registryAddress - Typus registry package address.
689
+ * @param strategyPoolAddress - strategy pool package address.
690
+ * @param userAddress - user's wallet address.
691
+ * @param prices - tokens prices (usd pair on Pyth)
692
+ * @return User Bids.
693
+ */
694
+ export const fetchUserBids = async (
695
+ provider: SuiClient,
696
+ network: string,
697
+ packageAddress: string,
698
+ framworkAddress: string,
699
+ originFramworkAddress: string,
700
+ registryAddress: string,
701
+ strategyPoolAddress: string,
702
+ userAddress: string,
703
+ prices?: { [key: string]: CoinInfo }
704
+ ) => {
705
+ // Step 1: get user bid receipts, vaults info, user strategies, auction data, prices
706
+ const vaultsInfo = await getVaults(provider, packageAddress, registryAddress, []);
707
+ const userReceipts = await getUserBidReceipts(provider, network, originFramworkAddress, userAddress);
708
+ const userStrategies = await getUserStrategies(provider, packageAddress, registryAddress, strategyPoolAddress, userAddress);
709
+ const auctions = await getAuctions(provider, packageAddress, registryAddress, []);
710
+ if (typeof prices === "undefined") {
711
+ prices = await fetchPrices(provider, "testnet");
712
+ }
713
+ // Step 2: sort receipts and flat receipts
714
+ const { sortedBidReceipts, bidVaultsInfo } = parseBidReceipt(Object.values(vaultsInfo), userReceipts);
715
+
716
+ // Step 3: get bid shares info
717
+ const bidShares = await getMyBids(provider, framworkAddress, packageAddress, registryAddress, sortedBidReceipts);
718
+
719
+ // Step 4: parse bids from bid shares
720
+ const bidsFromBidShares: Bid[] = [];
721
+ for (let bidVaultInfo of bidVaultsInfo) {
722
+ const bidShare = bidShares[`${bidVaultInfo.receipt.index}-${bidVaultInfo.receipt.vid}`];
723
+ const auction = auctions ? auctions[bidVaultInfo.vaultInfo.info.index] : null;
724
+ const [dToken, bToken, oToken] = parseAssets(bidVaultInfo.vaultInfo.info);
725
+ if (bidShare) {
726
+ const price = BigNumber(prices[oToken.toLowerCase()].price)
727
+ .div(BigNumber(10).pow(prices[oToken.toLowerCase()].decimal))
728
+ .toString();
729
+ const data = parseBid(bidVaultInfo, bidShare, auction, price, false);
730
+ const checkExistVault = bidsFromBidShares.find(
731
+ (p) => p.vaultIndex === bidVaultInfo.vaultInfo.info.index && p.receiptsVid.includes(bidVaultInfo.receipt.vid)
732
+ );
733
+
734
+ if (checkExistVault) {
735
+ // Merge the bid receipts into the same vault
736
+ checkExistVault!.receiptsId = [...checkExistVault!.receiptsId, ...data.receiptsId];
737
+ } else {
738
+ bidsFromBidShares.push(data);
739
+ }
740
+ }
741
+ }
742
+
743
+ // Step 5: parse strategies to user receipt type
744
+ const autoBidsShares: { [key: string]: BidShare } = {};
745
+ const vaultAutoBidReceipts: {
746
+ [key: string]: Receipt[];
747
+ } = {};
748
+ for (let strategy of userStrategies) {
749
+ const receipts = strategy.receipts;
750
+ for (let receiptItem of receipts) {
751
+ const vaultIndex = receiptItem.index;
752
+ const receipt = {
753
+ id: receiptItem.id,
754
+ index: vaultIndex,
755
+ name: "",
756
+ description: "",
757
+ vid: receiptItem.vid,
758
+ metadata: receiptItem.metadata,
759
+ };
760
+
761
+ if (vaultAutoBidReceipts[vaultIndex]) {
762
+ vaultAutoBidReceipts[vaultIndex] = [...vaultAutoBidReceipts[vaultIndex], receipt];
763
+ } else {
764
+ vaultAutoBidReceipts[vaultIndex] = [receipt];
765
+ }
766
+
767
+ if (autoBidsShares[`${vaultIndex}-${receiptItem.vid}`]) {
768
+ autoBidsShares[`${vaultIndex}-${receiptItem.vid}`].share = (
769
+ Number(autoBidsShares[`${vaultIndex}-${receiptItem.vid}`].share) +
770
+ Number(strategy.my_bids[`${vaultIndex}-${receiptItem.vid}`].share)
771
+ ).toString();
772
+ } else {
773
+ autoBidsShares[`${vaultIndex}-${receiptItem.vid}`] = {
774
+ bidVault: strategy.my_bids[`${vaultIndex}-${receiptItem.vid}`].bidVault,
775
+ share: strategy.my_bids[`${vaultIndex}-${receiptItem.vid}`].share,
776
+ };
777
+ }
778
+ }
779
+ }
780
+
781
+ const autoBidVaultInfos: { vaultInfo: Vault; receipt: Receipt }[] = [];
782
+ Object.values(vaultsInfo).forEach((v) => {
783
+ let curReceipts = vaultAutoBidReceipts[v.info.index];
784
+
785
+ if (curReceipts) {
786
+ curReceipts.map((item) => {
787
+ autoBidVaultInfos.push({ vaultInfo: v, receipt: item });
788
+ });
789
+ }
790
+ });
791
+
792
+ const bidsFromStrategies: Bid[] = [];
793
+ for (let autoBidVaultInfo of autoBidVaultInfos) {
794
+ const bidShare = autoBidsShares[`${autoBidVaultInfo.receipt.index}-${autoBidVaultInfo.receipt.vid}`];
795
+ const auction = auctions ? auctions[autoBidVaultInfo.vaultInfo.info.index] : null;
796
+ const [dToken, bToken, oToken] = parseAssets(autoBidVaultInfo.vaultInfo.info);
797
+ if (bidShare) {
798
+ const price = BigNumber(prices[oToken.toLowerCase()].price)
799
+ .div(BigNumber(10).pow(prices[oToken.toLowerCase()].decimal))
800
+ .toString();
801
+ const data = parseBid(autoBidVaultInfo, bidShare, auction, price, false);
802
+ const checkExistVault = bidsFromStrategies.find(
803
+ (p) => p.vaultIndex === autoBidVaultInfo.vaultInfo.info.index && p.receiptsVid.includes(autoBidVaultInfo.receipt.vid)
804
+ );
805
+
806
+ if (checkExistVault) {
807
+ // Merge the bid receipts into the same vault
808
+ checkExistVault!.receiptsId = [...checkExistVault!.receiptsId, ...data.receiptsId];
809
+ } else {
810
+ bidsFromStrategies.push(data);
811
+ }
812
+ }
813
+ }
814
+
815
+ // Step 6: order bids
816
+ const byOrdered = orderBy(
817
+ [...bidsFromBidShares, ...bidsFromStrategies],
818
+ ["expiry", "tokenOrder", "periodOrder", "optionTypeOrder"],
819
+ ["asc", "asc", "asc", "asc"]
820
+ );
821
+
822
+ return byOrdered;
823
+ };