aftermath-ts-sdk 1.3.28 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (410) hide show
  1. package/dist/index.d.ts +16828 -5
  2. package/dist/index.js +22695 -19
  3. package/dist/index.js.map +1 -0
  4. package/package.json +69 -60
  5. package/dist/general/apiHelpers/dynamicFieldsApiHelpers.d.ts +0 -41
  6. package/dist/general/apiHelpers/dynamicFieldsApiHelpers.d.ts.map +0 -1
  7. package/dist/general/apiHelpers/dynamicFieldsApiHelpers.js +0 -110
  8. package/dist/general/apiHelpers/eventsApiHelpers.d.ts +0 -43
  9. package/dist/general/apiHelpers/eventsApiHelpers.d.ts.map +0 -1
  10. package/dist/general/apiHelpers/eventsApiHelpers.js +0 -170
  11. package/dist/general/apiHelpers/inspectionsApiHelpers.d.ts +0 -28
  12. package/dist/general/apiHelpers/inspectionsApiHelpers.d.ts.map +0 -1
  13. package/dist/general/apiHelpers/inspectionsApiHelpers.js +0 -58
  14. package/dist/general/apiHelpers/objectsApiHelpers.d.ts +0 -77
  15. package/dist/general/apiHelpers/objectsApiHelpers.d.ts.map +0 -1
  16. package/dist/general/apiHelpers/objectsApiHelpers.js +0 -197
  17. package/dist/general/apiHelpers/transactionsApiHelpers.d.ts +0 -50
  18. package/dist/general/apiHelpers/transactionsApiHelpers.d.ts.map +0 -1
  19. package/dist/general/apiHelpers/transactionsApiHelpers.js +0 -256
  20. package/dist/general/dynamicGas/dynamicGas.d.ts +0 -48
  21. package/dist/general/dynamicGas/dynamicGas.d.ts.map +0 -1
  22. package/dist/general/dynamicGas/dynamicGas.js +0 -69
  23. package/dist/general/dynamicGas/dynamicGasTypes.d.ts +0 -37
  24. package/dist/general/dynamicGas/dynamicGasTypes.d.ts.map +0 -1
  25. package/dist/general/dynamicGas/dynamicGasTypes.js +0 -2
  26. package/dist/general/nfts/nftsApi.d.ts +0 -35
  27. package/dist/general/nfts/nftsApi.d.ts.map +0 -1
  28. package/dist/general/nfts/nftsApi.js +0 -124
  29. package/dist/general/nfts/nftsApiCasting.d.ts +0 -11
  30. package/dist/general/nfts/nftsApiCasting.d.ts.map +0 -1
  31. package/dist/general/nfts/nftsApiCasting.js +0 -115
  32. package/dist/general/nfts/nftsTypes.d.ts +0 -31
  33. package/dist/general/nfts/nftsTypes.d.ts.map +0 -1
  34. package/dist/general/nfts/nftsTypes.js +0 -2
  35. package/dist/general/priceFeeds/priceFeeds.d.ts +0 -3
  36. package/dist/general/priceFeeds/priceFeeds.d.ts.map +0 -1
  37. package/dist/general/priceFeeds/priceFeeds.js +0 -26
  38. package/dist/general/priceFeeds/priceFeedsApi.d.ts +0 -3
  39. package/dist/general/priceFeeds/priceFeedsApi.d.ts.map +0 -1
  40. package/dist/general/priceFeeds/priceFeedsApi.js +0 -33
  41. package/dist/general/priceFeeds/priceFeedsTypes.d.ts +0 -3
  42. package/dist/general/priceFeeds/priceFeedsTypes.d.ts.map +0 -1
  43. package/dist/general/priceFeeds/priceFeedsTypes.js +0 -7
  44. package/dist/general/prices/coinGeckoTypes.d.ts +0 -16
  45. package/dist/general/prices/coinGeckoTypes.d.ts.map +0 -1
  46. package/dist/general/prices/coinGeckoTypes.js +0 -2
  47. package/dist/general/prices/prices.d.ts +0 -92
  48. package/dist/general/prices/prices.d.ts.map +0 -1
  49. package/dist/general/prices/prices.js +0 -124
  50. package/dist/general/providers/aftermath.d.ts +0 -200
  51. package/dist/general/providers/aftermath.d.ts.map +0 -1
  52. package/dist/general/providers/aftermath.js +0 -258
  53. package/dist/general/providers/aftermathApi.d.ts +0 -197
  54. package/dist/general/providers/aftermathApi.d.ts.map +0 -1
  55. package/dist/general/providers/aftermathApi.js +0 -255
  56. package/dist/general/providers/index.d.ts +0 -3
  57. package/dist/general/providers/index.d.ts.map +0 -1
  58. package/dist/general/providers/index.js +0 -18
  59. package/dist/general/types/castingTypes.d.ts +0 -51
  60. package/dist/general/types/castingTypes.d.ts.map +0 -1
  61. package/dist/general/types/castingTypes.js +0 -8
  62. package/dist/general/types/configTypes.d.ts +0 -187
  63. package/dist/general/types/configTypes.d.ts.map +0 -1
  64. package/dist/general/types/configTypes.js +0 -2
  65. package/dist/general/types/generalTypes.d.ts +0 -349
  66. package/dist/general/types/generalTypes.d.ts.map +0 -1
  67. package/dist/general/types/generalTypes.js +0 -2
  68. package/dist/general/types/index.d.ts +0 -7
  69. package/dist/general/types/index.d.ts.map +0 -1
  70. package/dist/general/types/index.js +0 -22
  71. package/dist/general/types/moveErrorsInterface.d.ts +0 -6
  72. package/dist/general/types/moveErrorsInterface.d.ts.map +0 -1
  73. package/dist/general/types/moveErrorsInterface.js +0 -2
  74. package/dist/general/types/suiTypes.d.ts +0 -2
  75. package/dist/general/types/suiTypes.d.ts.map +0 -1
  76. package/dist/general/types/suiTypes.js +0 -5
  77. package/dist/general/utils/caller.d.ts +0 -58
  78. package/dist/general/utils/caller.d.ts.map +0 -1
  79. package/dist/general/utils/caller.js +0 -231
  80. package/dist/general/utils/casting.d.ts +0 -212
  81. package/dist/general/utils/casting.d.ts.map +0 -1
  82. package/dist/general/utils/casting.js +0 -273
  83. package/dist/general/utils/fixedUtils.d.ts +0 -109
  84. package/dist/general/utils/fixedUtils.d.ts.map +0 -1
  85. package/dist/general/utils/fixedUtils.js +0 -100
  86. package/dist/general/utils/helpers.d.ts +0 -408
  87. package/dist/general/utils/helpers.d.ts.map +0 -1
  88. package/dist/general/utils/helpers.js +0 -725
  89. package/dist/general/utils/iFixedUtils.d.ts +0 -78
  90. package/dist/general/utils/iFixedUtils.d.ts.map +0 -1
  91. package/dist/general/utils/iFixedUtils.js +0 -109
  92. package/dist/general/utils/index.d.ts +0 -3
  93. package/dist/general/utils/index.d.ts.map +0 -1
  94. package/dist/general/utils/index.js +0 -18
  95. package/dist/general/wallet/wallet.d.ts +0 -89
  96. package/dist/general/wallet/wallet.d.ts.map +0 -1
  97. package/dist/general/wallet/wallet.js +0 -120
  98. package/dist/general/wallet/walletApi.d.ts +0 -20
  99. package/dist/general/wallet/walletApi.d.ts.map +0 -1
  100. package/dist/general/wallet/walletApi.js +0 -66
  101. package/dist/index.d.ts.map +0 -1
  102. package/dist/packages/auth/auth.d.ts +0 -135
  103. package/dist/packages/auth/auth.d.ts.map +0 -1
  104. package/dist/packages/auth/auth.js +0 -289
  105. package/dist/packages/auth/authTypes.d.ts +0 -102
  106. package/dist/packages/auth/authTypes.d.ts.map +0 -1
  107. package/dist/packages/auth/authTypes.js +0 -2
  108. package/dist/packages/auth/index.d.ts +0 -2
  109. package/dist/packages/auth/index.d.ts.map +0 -1
  110. package/dist/packages/auth/index.js +0 -17
  111. package/dist/packages/coin/api/coinApi.d.ts +0 -33
  112. package/dist/packages/coin/api/coinApi.d.ts.map +0 -1
  113. package/dist/packages/coin/api/coinApi.js +0 -167
  114. package/dist/packages/coin/coin.d.ts +0 -320
  115. package/dist/packages/coin/coin.d.ts.map +0 -1
  116. package/dist/packages/coin/coin.js +0 -467
  117. package/dist/packages/coin/coinTypes.d.ts +0 -139
  118. package/dist/packages/coin/coinTypes.d.ts.map +0 -1
  119. package/dist/packages/coin/coinTypes.js +0 -2
  120. package/dist/packages/coin/index.d.ts +0 -2
  121. package/dist/packages/coin/index.d.ts.map +0 -1
  122. package/dist/packages/coin/index.js +0 -17
  123. package/dist/packages/dca/api/dcaApi.d.ts +0 -26
  124. package/dist/packages/dca/api/dcaApi.d.ts.map +0 -1
  125. package/dist/packages/dca/api/dcaApi.js +0 -60
  126. package/dist/packages/dca/dca.d.ts +0 -174
  127. package/dist/packages/dca/dca.d.ts.map +0 -1
  128. package/dist/packages/dca/dca.js +0 -230
  129. package/dist/packages/dca/dcaTypes.d.ts +0 -319
  130. package/dist/packages/dca/dcaTypes.d.ts.map +0 -1
  131. package/dist/packages/dca/dcaTypes.js +0 -2
  132. package/dist/packages/dca/index.d.ts +0 -2
  133. package/dist/packages/dca/index.d.ts.map +0 -1
  134. package/dist/packages/dca/index.js +0 -17
  135. package/dist/packages/farms/api/farmsApi.d.ts +0 -996
  136. package/dist/packages/farms/api/farmsApi.d.ts.map +0 -1
  137. package/dist/packages/farms/api/farmsApi.js +0 -1826
  138. package/dist/packages/farms/api/farmsApiCasting.d.ts +0 -39
  139. package/dist/packages/farms/api/farmsApiCasting.d.ts.map +0 -1
  140. package/dist/packages/farms/api/farmsApiCasting.js +0 -427
  141. package/dist/packages/farms/api/farmsApiCastingTypes.d.ts +0 -235
  142. package/dist/packages/farms/api/farmsApiCastingTypes.d.ts.map +0 -1
  143. package/dist/packages/farms/api/farmsApiCastingTypes.js +0 -2
  144. package/dist/packages/farms/farms.d.ts +0 -221
  145. package/dist/packages/farms/farms.d.ts.map +0 -1
  146. package/dist/packages/farms/farms.js +0 -302
  147. package/dist/packages/farms/farmsStakedPosition.d.ts +0 -229
  148. package/dist/packages/farms/farmsStakedPosition.d.ts.map +0 -1
  149. package/dist/packages/farms/farmsStakedPosition.js +0 -473
  150. package/dist/packages/farms/farmsStakingPool.d.ts +0 -285
  151. package/dist/packages/farms/farmsStakingPool.d.ts.map +0 -1
  152. package/dist/packages/farms/farmsStakingPool.js +0 -488
  153. package/dist/packages/farms/farmsTypes.d.ts +0 -571
  154. package/dist/packages/farms/farmsTypes.d.ts.map +0 -1
  155. package/dist/packages/farms/farmsTypes.js +0 -49
  156. package/dist/packages/farms/index.d.ts +0 -4
  157. package/dist/packages/farms/index.d.ts.map +0 -1
  158. package/dist/packages/farms/index.js +0 -19
  159. package/dist/packages/faucet/api/faucetApi.d.ts +0 -37
  160. package/dist/packages/faucet/api/faucetApi.d.ts.map +0 -1
  161. package/dist/packages/faucet/api/faucetApi.js +0 -145
  162. package/dist/packages/faucet/api/faucetApiCasting.d.ts +0 -7
  163. package/dist/packages/faucet/api/faucetApiCasting.d.ts.map +0 -1
  164. package/dist/packages/faucet/api/faucetApiCasting.js +0 -33
  165. package/dist/packages/faucet/api/faucetApiCastingTypes.d.ts +0 -10
  166. package/dist/packages/faucet/api/faucetApiCastingTypes.d.ts.map +0 -1
  167. package/dist/packages/faucet/api/faucetApiCastingTypes.js +0 -2
  168. package/dist/packages/faucet/faucet.d.ts +0 -16
  169. package/dist/packages/faucet/faucet.d.ts.map +0 -1
  170. package/dist/packages/faucet/faucet.js +0 -64
  171. package/dist/packages/faucet/faucetTypes.d.ts +0 -20
  172. package/dist/packages/faucet/faucetTypes.d.ts.map +0 -1
  173. package/dist/packages/faucet/faucetTypes.js +0 -2
  174. package/dist/packages/faucet/index.d.ts +0 -2
  175. package/dist/packages/faucet/index.d.ts.map +0 -1
  176. package/dist/packages/faucet/index.js +0 -17
  177. package/dist/packages/index.d.ts +0 -14
  178. package/dist/packages/index.d.ts.map +0 -1
  179. package/dist/packages/index.js +0 -29
  180. package/dist/packages/leveragedStaking/api/leveragedStakingApi.d.ts +0 -202
  181. package/dist/packages/leveragedStaking/api/leveragedStakingApi.d.ts.map +0 -1
  182. package/dist/packages/leveragedStaking/api/leveragedStakingApi.js +0 -1104
  183. package/dist/packages/leveragedStaking/api/leveragedStakingApiCasting.d.ts +0 -12
  184. package/dist/packages/leveragedStaking/api/leveragedStakingApiCasting.d.ts.map +0 -1
  185. package/dist/packages/leveragedStaking/api/leveragedStakingApiCasting.js +0 -69
  186. package/dist/packages/leveragedStaking/api/leveragedStakingApiCastingTypes.d.ts +0 -39
  187. package/dist/packages/leveragedStaking/api/leveragedStakingApiCastingTypes.d.ts.map +0 -1
  188. package/dist/packages/leveragedStaking/api/leveragedStakingApiCastingTypes.js +0 -2
  189. package/dist/packages/leveragedStaking/index.d.ts +0 -2
  190. package/dist/packages/leveragedStaking/index.d.ts.map +0 -1
  191. package/dist/packages/leveragedStaking/index.js +0 -17
  192. package/dist/packages/leveragedStaking/leveragedStaking.d.ts +0 -68
  193. package/dist/packages/leveragedStaking/leveragedStaking.d.ts.map +0 -1
  194. package/dist/packages/leveragedStaking/leveragedStaking.js +0 -154
  195. package/dist/packages/leveragedStaking/leveragedStakingTypes.d.ts +0 -48
  196. package/dist/packages/leveragedStaking/leveragedStakingTypes.d.ts.map +0 -1
  197. package/dist/packages/leveragedStaking/leveragedStakingTypes.js +0 -16
  198. package/dist/packages/limitOrders/api/limitOrdersApi.d.ts +0 -12
  199. package/dist/packages/limitOrders/api/limitOrdersApi.d.ts.map +0 -1
  200. package/dist/packages/limitOrders/api/limitOrdersApi.js +0 -25
  201. package/dist/packages/limitOrders/index.d.ts +0 -2
  202. package/dist/packages/limitOrders/index.d.ts.map +0 -1
  203. package/dist/packages/limitOrders/index.js +0 -17
  204. package/dist/packages/limitOrders/limitOrders.d.ts +0 -143
  205. package/dist/packages/limitOrders/limitOrders.d.ts.map +0 -1
  206. package/dist/packages/limitOrders/limitOrders.js +0 -190
  207. package/dist/packages/limitOrders/limitOrdersTypes.d.ts +0 -211
  208. package/dist/packages/limitOrders/limitOrdersTypes.d.ts.map +0 -1
  209. package/dist/packages/limitOrders/limitOrdersTypes.js +0 -2
  210. package/dist/packages/multisig/api/multisigApi.d.ts +0 -10
  211. package/dist/packages/multisig/api/multisigApi.d.ts.map +0 -1
  212. package/dist/packages/multisig/api/multisigApi.js +0 -39
  213. package/dist/packages/multisig/index.d.ts +0 -2
  214. package/dist/packages/multisig/index.d.ts.map +0 -1
  215. package/dist/packages/multisig/index.js +0 -17
  216. package/dist/packages/multisig/multisig.d.ts +0 -46
  217. package/dist/packages/multisig/multisig.d.ts.map +0 -1
  218. package/dist/packages/multisig/multisig.js +0 -65
  219. package/dist/packages/multisig/multisigTypes.d.ts +0 -26
  220. package/dist/packages/multisig/multisigTypes.d.ts.map +0 -1
  221. package/dist/packages/multisig/multisigTypes.js +0 -2
  222. package/dist/packages/nftAmm/api/nftAmmApi.d.ts +0 -93
  223. package/dist/packages/nftAmm/api/nftAmmApi.d.ts.map +0 -1
  224. package/dist/packages/nftAmm/api/nftAmmApi.js +0 -250
  225. package/dist/packages/nftAmm/api/nftAmmApiCasting.d.ts +0 -6
  226. package/dist/packages/nftAmm/api/nftAmmApiCasting.d.ts.map +0 -1
  227. package/dist/packages/nftAmm/api/nftAmmApiCasting.js +0 -43
  228. package/dist/packages/nftAmm/api/nftAmmApiCastingTypes.d.ts +0 -10
  229. package/dist/packages/nftAmm/api/nftAmmApiCastingTypes.d.ts.map +0 -1
  230. package/dist/packages/nftAmm/api/nftAmmApiCastingTypes.js +0 -2
  231. package/dist/packages/nftAmm/index.d.ts +0 -2
  232. package/dist/packages/nftAmm/index.d.ts.map +0 -1
  233. package/dist/packages/nftAmm/index.js +0 -17
  234. package/dist/packages/nftAmm/nftAmm.d.ts +0 -18
  235. package/dist/packages/nftAmm/nftAmm.d.ts.map +0 -1
  236. package/dist/packages/nftAmm/nftAmm.js +0 -73
  237. package/dist/packages/nftAmm/nftAmmMarket.d.ts +0 -54
  238. package/dist/packages/nftAmm/nftAmmMarket.d.ts.map +0 -1
  239. package/dist/packages/nftAmm/nftAmmMarket.js +0 -154
  240. package/dist/packages/nftAmm/nftAmmTypes.d.ts +0 -51
  241. package/dist/packages/nftAmm/nftAmmTypes.d.ts.map +0 -1
  242. package/dist/packages/nftAmm/nftAmmTypes.js +0 -2
  243. package/dist/packages/perpetuals/api/perpetualsApi.d.ts +0 -44
  244. package/dist/packages/perpetuals/api/perpetualsApi.d.ts.map +0 -1
  245. package/dist/packages/perpetuals/api/perpetualsApi.js +0 -1420
  246. package/dist/packages/perpetuals/api/perpetualsApiCasting.d.ts +0 -27
  247. package/dist/packages/perpetuals/api/perpetualsApiCasting.d.ts.map +0 -1
  248. package/dist/packages/perpetuals/api/perpetualsApiCasting.js +0 -463
  249. package/dist/packages/perpetuals/index.d.ts +0 -5
  250. package/dist/packages/perpetuals/index.d.ts.map +0 -1
  251. package/dist/packages/perpetuals/index.js +0 -20
  252. package/dist/packages/perpetuals/perpetuals.d.ts +0 -860
  253. package/dist/packages/perpetuals/perpetuals.d.ts.map +0 -1
  254. package/dist/packages/perpetuals/perpetuals.js +0 -1102
  255. package/dist/packages/perpetuals/perpetualsAccount.d.ts +0 -780
  256. package/dist/packages/perpetuals/perpetualsAccount.d.ts.map +0 -1
  257. package/dist/packages/perpetuals/perpetualsAccount.js +0 -1406
  258. package/dist/packages/perpetuals/perpetualsCastingTypes.d.ts +0 -170
  259. package/dist/packages/perpetuals/perpetualsCastingTypes.d.ts.map +0 -1
  260. package/dist/packages/perpetuals/perpetualsCastingTypes.js +0 -2
  261. package/dist/packages/perpetuals/perpetualsMarket.d.ts +0 -360
  262. package/dist/packages/perpetuals/perpetualsMarket.d.ts.map +0 -1
  263. package/dist/packages/perpetuals/perpetualsMarket.js +0 -475
  264. package/dist/packages/perpetuals/perpetualsTypes.d.ts +0 -2968
  265. package/dist/packages/perpetuals/perpetualsTypes.d.ts.map +0 -1
  266. package/dist/packages/perpetuals/perpetualsTypes.js +0 -165
  267. package/dist/packages/perpetuals/perpetualsVault.d.ts +0 -438
  268. package/dist/packages/perpetuals/perpetualsVault.d.ts.map +0 -1
  269. package/dist/packages/perpetuals/perpetualsVault.js +0 -601
  270. package/dist/packages/perpetuals/utils/index.d.ts +0 -2
  271. package/dist/packages/perpetuals/utils/index.d.ts.map +0 -1
  272. package/dist/packages/perpetuals/utils/index.js +0 -17
  273. package/dist/packages/perpetuals/utils/perpetualsOrderUtils.d.ts +0 -12
  274. package/dist/packages/perpetuals/utils/perpetualsOrderUtils.d.ts.map +0 -1
  275. package/dist/packages/perpetuals/utils/perpetualsOrderUtils.js +0 -60
  276. package/dist/packages/pools/api/poolsApi.d.ts +0 -342
  277. package/dist/packages/pools/api/poolsApi.d.ts.map +0 -1
  278. package/dist/packages/pools/api/poolsApi.js +0 -857
  279. package/dist/packages/pools/api/poolsApiCasting.d.ts +0 -13
  280. package/dist/packages/pools/api/poolsApiCasting.d.ts.map +0 -1
  281. package/dist/packages/pools/api/poolsApiCasting.js +0 -91
  282. package/dist/packages/pools/api/poolsApiCastingTypes.d.ts +0 -64
  283. package/dist/packages/pools/api/poolsApiCastingTypes.d.ts.map +0 -1
  284. package/dist/packages/pools/api/poolsApiCastingTypes.js +0 -2
  285. package/dist/packages/pools/index.d.ts +0 -3
  286. package/dist/packages/pools/index.d.ts.map +0 -1
  287. package/dist/packages/pools/index.js +0 -18
  288. package/dist/packages/pools/pool.d.ts +0 -459
  289. package/dist/packages/pools/pool.d.ts.map +0 -1
  290. package/dist/packages/pools/pool.js +0 -647
  291. package/dist/packages/pools/pools.d.ts +0 -405
  292. package/dist/packages/pools/pools.d.ts.map +0 -1
  293. package/dist/packages/pools/pools.js +0 -533
  294. package/dist/packages/pools/poolsTypes.d.ts +0 -469
  295. package/dist/packages/pools/poolsTypes.d.ts.map +0 -1
  296. package/dist/packages/pools/poolsTypes.js +0 -2
  297. package/dist/packages/pools/utils/cmmmCalculations.d.ts +0 -42
  298. package/dist/packages/pools/utils/cmmmCalculations.d.ts.map +0 -1
  299. package/dist/packages/pools/utils/cmmmCalculations.js +0 -1380
  300. package/dist/packages/referralVault/api/referralVaultApi.d.ts +0 -39
  301. package/dist/packages/referralVault/api/referralVaultApi.d.ts.map +0 -1
  302. package/dist/packages/referralVault/api/referralVaultApi.js +0 -125
  303. package/dist/packages/referralVault/index.d.ts +0 -2
  304. package/dist/packages/referralVault/index.d.ts.map +0 -1
  305. package/dist/packages/referralVault/index.js +0 -17
  306. package/dist/packages/referralVault/referralVault.d.ts +0 -47
  307. package/dist/packages/referralVault/referralVault.d.ts.map +0 -1
  308. package/dist/packages/referralVault/referralVault.js +0 -71
  309. package/dist/packages/referralVault/referralVaultTypes.d.ts +0 -2
  310. package/dist/packages/referralVault/referralVaultTypes.d.ts.map +0 -1
  311. package/dist/packages/referralVault/referralVaultTypes.js +0 -2
  312. package/dist/packages/referrals/index.d.ts +0 -2
  313. package/dist/packages/referrals/index.d.ts.map +0 -1
  314. package/dist/packages/referrals/index.js +0 -17
  315. package/dist/packages/referrals/referrals.d.ts +0 -27
  316. package/dist/packages/referrals/referrals.d.ts.map +0 -1
  317. package/dist/packages/referrals/referrals.js +0 -95
  318. package/dist/packages/referrals/referralsTypes.d.ts +0 -166
  319. package/dist/packages/referrals/referralsTypes.d.ts.map +0 -1
  320. package/dist/packages/referrals/referralsTypes.js +0 -2
  321. package/dist/packages/rewards/index.d.ts +0 -2
  322. package/dist/packages/rewards/index.d.ts.map +0 -1
  323. package/dist/packages/rewards/index.js +0 -17
  324. package/dist/packages/rewards/rewards.d.ts +0 -21
  325. package/dist/packages/rewards/rewards.d.ts.map +0 -1
  326. package/dist/packages/rewards/rewards.js +0 -65
  327. package/dist/packages/rewards/rewardsTypes.d.ts +0 -169
  328. package/dist/packages/rewards/rewardsTypes.d.ts.map +0 -1
  329. package/dist/packages/rewards/rewardsTypes.js +0 -2
  330. package/dist/packages/router/api/routerApi.d.ts +0 -35
  331. package/dist/packages/router/api/routerApi.d.ts.map +0 -1
  332. package/dist/packages/router/api/routerApi.js +0 -88
  333. package/dist/packages/router/api/routerApiCasting.d.ts +0 -6
  334. package/dist/packages/router/api/routerApiCasting.d.ts.map +0 -1
  335. package/dist/packages/router/api/routerApiCasting.js +0 -22
  336. package/dist/packages/router/api/routerApiCastingTypes.d.ts +0 -12
  337. package/dist/packages/router/api/routerApiCastingTypes.d.ts.map +0 -1
  338. package/dist/packages/router/api/routerApiCastingTypes.js +0 -2
  339. package/dist/packages/router/index.d.ts +0 -2
  340. package/dist/packages/router/index.d.ts.map +0 -1
  341. package/dist/packages/router/index.js +0 -17
  342. package/dist/packages/router/router.d.ts +0 -224
  343. package/dist/packages/router/router.d.ts.map +0 -1
  344. package/dist/packages/router/router.js +0 -283
  345. package/dist/packages/router/routerTypes.d.ts +0 -300
  346. package/dist/packages/router/routerTypes.d.ts.map +0 -1
  347. package/dist/packages/router/routerTypes.js +0 -2
  348. package/dist/packages/staking/api/stakingApi.d.ts +0 -129
  349. package/dist/packages/staking/api/stakingApi.d.ts.map +0 -1
  350. package/dist/packages/staking/api/stakingApi.js +0 -487
  351. package/dist/packages/staking/api/stakingApiCasting.d.ts +0 -11
  352. package/dist/packages/staking/api/stakingApiCasting.d.ts.map +0 -1
  353. package/dist/packages/staking/api/stakingApiCasting.js +0 -87
  354. package/dist/packages/staking/api/stakingApiCastingTypes.d.ts +0 -97
  355. package/dist/packages/staking/api/stakingApiCastingTypes.d.ts.map +0 -1
  356. package/dist/packages/staking/api/stakingApiCastingTypes.js +0 -2
  357. package/dist/packages/staking/index.d.ts +0 -2
  358. package/dist/packages/staking/index.d.ts.map +0 -1
  359. package/dist/packages/staking/index.js +0 -17
  360. package/dist/packages/staking/staking.d.ts +0 -385
  361. package/dist/packages/staking/staking.d.ts.map +0 -1
  362. package/dist/packages/staking/staking.js +0 -501
  363. package/dist/packages/staking/stakingTypes.d.ts +0 -575
  364. package/dist/packages/staking/stakingTypes.d.ts.map +0 -1
  365. package/dist/packages/staking/stakingTypes.js +0 -45
  366. package/dist/packages/sui/api/suiApi.d.ts +0 -21
  367. package/dist/packages/sui/api/suiApi.d.ts.map +0 -1
  368. package/dist/packages/sui/api/suiApi.js +0 -46
  369. package/dist/packages/sui/index.d.ts +0 -2
  370. package/dist/packages/sui/index.d.ts.map +0 -1
  371. package/dist/packages/sui/index.js +0 -17
  372. package/dist/packages/sui/sui.d.ts +0 -53
  373. package/dist/packages/sui/sui.d.ts.map +0 -1
  374. package/dist/packages/sui/sui.js +0 -77
  375. package/dist/packages/suiFrens/api/suiFrensApi.d.ts +0 -204
  376. package/dist/packages/suiFrens/api/suiFrensApi.d.ts.map +0 -1
  377. package/dist/packages/suiFrens/api/suiFrensApi.js +0 -756
  378. package/dist/packages/suiFrens/api/suiFrensApiCasting.d.ts +0 -21
  379. package/dist/packages/suiFrens/api/suiFrensApiCasting.d.ts.map +0 -1
  380. package/dist/packages/suiFrens/api/suiFrensApiCasting.js +0 -181
  381. package/dist/packages/suiFrens/api/suiFrensApiCastingTypes.d.ts +0 -77
  382. package/dist/packages/suiFrens/api/suiFrensApiCastingTypes.d.ts.map +0 -1
  383. package/dist/packages/suiFrens/api/suiFrensApiCastingTypes.js +0 -2
  384. package/dist/packages/suiFrens/index.d.ts +0 -4
  385. package/dist/packages/suiFrens/index.d.ts.map +0 -1
  386. package/dist/packages/suiFrens/index.js +0 -19
  387. package/dist/packages/suiFrens/stakedSuiFren.d.ts +0 -31
  388. package/dist/packages/suiFrens/stakedSuiFren.d.ts.map +0 -1
  389. package/dist/packages/suiFrens/stakedSuiFren.js +0 -90
  390. package/dist/packages/suiFrens/suiFren.d.ts +0 -32
  391. package/dist/packages/suiFrens/suiFren.d.ts.map +0 -1
  392. package/dist/packages/suiFrens/suiFren.js +0 -150
  393. package/dist/packages/suiFrens/suiFrens.d.ts +0 -56
  394. package/dist/packages/suiFrens/suiFrens.d.ts.map +0 -1
  395. package/dist/packages/suiFrens/suiFrens.js +0 -218
  396. package/dist/packages/suiFrens/suiFrensTypes.d.ts +0 -148
  397. package/dist/packages/suiFrens/suiFrensTypes.d.ts.map +0 -1
  398. package/dist/packages/suiFrens/suiFrensTypes.js +0 -8
  399. package/dist/packages/userData/index.d.ts +0 -2
  400. package/dist/packages/userData/index.d.ts.map +0 -1
  401. package/dist/packages/userData/index.js +0 -17
  402. package/dist/packages/userData/userData.d.ts +0 -89
  403. package/dist/packages/userData/userData.d.ts.map +0 -1
  404. package/dist/packages/userData/userData.js +0 -119
  405. package/dist/packages/userData/userDataTypes.d.ts +0 -29
  406. package/dist/packages/userData/userDataTypes.d.ts.map +0 -1
  407. package/dist/packages/userData/userDataTypes.js +0 -2
  408. package/dist/types.d.ts +0 -15
  409. package/dist/types.d.ts.map +0 -1
  410. package/dist/types.js +0 -31
@@ -1,1406 +0,0 @@
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 __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.PerpetualsAccount = void 0;
24
- const caller_1 = require("../../general/utils/caller");
25
- const utils_1 = require("../../general/utils");
26
- const perpetuals_1 = require("./perpetuals");
27
- const transactions_1 = require("@mysten/sui/transactions");
28
- /**
29
- * Note on “refreshing” account state:
30
- *
31
- * This class is a thin wrapper around a snapshot of {@link PerpetualsAccountObject}
32
- * that is typically fetched via {@link Perpetuals.getAccount}. The transaction builders
33
- * use the current snapshot to derive fields like `hasPosition` and to construct
34
- * SL/TP helpers that depend on the position side.
35
- *
36
- * If your app is long-lived, you may want to periodically re-fetch the account
37
- * (and recreate this wrapper) to avoid stale local position/order state. For example:
38
- * - After placing/canceling orders
39
- * - After fills/liquidations/funding settlements
40
- * - After switching markets or wallets
41
- */
42
- /**
43
- * High-level wrapper around a single Perpetuals account or vault account.
44
- *
45
- * This class encapsulates:
46
- *
47
- * - Transaction builders for:
48
- * - Collateral actions (deposit, withdraw, allocate, deallocate, transfer)
49
- * - Orders (market/limit, cancel, stop orders, SL/TP, set leverage)
50
- * - Read-only account helpers:
51
- * - Stop-order message signing
52
- * - Order & stop-order metadata
53
- * - Collateral & trade history
54
- * - Convenience helpers to:
55
- * - Fetch and categorize SL/TP stop orders
56
- * - Resolve account/vault identifiers and owner addresses
57
- *
58
- * You typically do not construct `PerpetualsAccount` directly. Instead, use
59
- * {@link Perpetuals.getAccount} or {@link Perpetuals.getAccounts}, which
60
- * fetch all required on-chain data and wrap it for you:
61
- *
62
- * ```ts
63
- * const afSdk = new Aftermath("MAINNET");
64
- * await afSdk.init();
65
- *
66
- * const perps = afSdk.Perpetuals();
67
- * const [accountCap] = await perps.getOwnedAccountCaps({
68
- * walletAddress: "0x...",
69
- * });
70
- *
71
- * const account = await perps.getAccount({ accountCap });
72
- *
73
- * // Build a deposit transaction
74
- * const depositTx = await account.getDepositCollateralTx({
75
- * depositAmount: BigInt("1000000000"),
76
- * });
77
- * ```
78
- */
79
- class PerpetualsAccount extends caller_1.Caller {
80
- // =========================================================================
81
- // Constructor
82
- // =========================================================================
83
- /**
84
- * Create a new {@link PerpetualsAccount} wrapper.
85
- *
86
- * @param account - Raw account object with positions and equity data.
87
- * @param accountCap - Account cap or partial vault cap object containing
88
- * ownership and collateral metadata.
89
- * @param config - Optional {@link CallerConfig} (network, auth, etc.).
90
- * @param Provider - Optional shared {@link AftermathApi} provider instance
91
- * used to derive serialized transaction kinds (`txKind`) from
92
- * {@link Transaction} objects.
93
- */
94
- constructor(account, accountCap, config, Provider) {
95
- const vaultId = "vaultId" in accountCap ? accountCap.vaultId : undefined;
96
- super(config, "perpetuals");
97
- this.account = account;
98
- this.accountCap = accountCap;
99
- this.Provider = Provider;
100
- this.vaultId = vaultId;
101
- }
102
- // =========================================================================
103
- // Transactions
104
- // =========================================================================
105
- // =========================================================================
106
- // Collateral Txs
107
- // =========================================================================
108
- /**
109
- * Build a `deposit-collateral` transaction for this account.
110
- *
111
- * For non-vault accounts, this endpoint constructs a transaction that:
112
- * - Optionally extends an existing {@link Transaction}, and
113
- * - Deposits collateral into the Perpetuals account.
114
- *
115
- * **Note:** Vault accounts are currently not supported and will throw.
116
- *
117
- * @param inputs.tx - Optional existing transaction to extend. If omitted,
118
- * a new {@link Transaction} is created under the hood.
119
- * @param inputs.isSponsoredTx - Optional flag indicating whether the
120
- * transaction is gas-sponsored.
121
- * @param inputs.depositAmount - Amount of collateral to deposit, if paying
122
- * directly from the wallet.
123
- * @param inputs.depositCoinArg - Transaction object argument referencing a
124
- * coin to deposit (mutually exclusive with `depositAmount`).
125
- *
126
- * @returns Transaction response containing a `tx`.
127
- *
128
- * @example
129
- * ```ts
130
- * const { tx } = await account.getDepositCollateralTx({
131
- * depositAmount: BigInt("1000000000"),
132
- * });
133
- * ```
134
- */
135
- getDepositCollateralTx(inputs) {
136
- return __awaiter(this, void 0, void 0, function* () {
137
- var _a;
138
- const { tx } = inputs, otherInputs = __rest(inputs, ["tx"]);
139
- if ("vaultId" in this.accountCap)
140
- throw new Error("`getDepositCollateralTx` not supported by vault accounts, please use method `getAdminDepositTx` on class `PerpetualsVault` instead");
141
- return this.fetchApiTxObject("account/transactions/deposit-collateral", Object.assign(Object.assign({}, otherInputs), { walletAddress: this.ownerAddress(), collateralCoinType: this.accountCap.collateralCoinType, accountId: this.accountCap.accountId, accountCapId: this.accountCap.objectId, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({
142
- tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction(),
143
- })) }), undefined, {
144
- txKind: true,
145
- });
146
- });
147
- }
148
- /**
149
- * Build a `withdraw-collateral` transaction for this account.
150
- *
151
- * For non-vault accounts, this endpoint constructs a transaction to:
152
- * - Withdraw collateral from the Perpetuals account, and
153
- * - Optionally transfer it to a `recipientAddress` (otherwise coin is left
154
- * as a transaction argument).
155
- *
156
- * **Note:** Vault accounts are currently not supported and will throw.
157
- *
158
- * @param inputs.withdrawAmount - Amount of collateral to withdraw.
159
- * @param inputs.recipientAddress - Optional address to receive the withdrawn
160
- * coins directly.
161
- * @param inputs.tx - Optional transaction to extend (defaults to new `Transaction()`).
162
- *
163
- * @returns A response containing `tx` and the `coinOutArg` where the
164
- * withdrawn coins end up if `recipientAddress` is not used.
165
- *
166
- * @example
167
- * ```ts
168
- * const { tx, coinOutArg } = await account.getWithdrawCollateralTx({
169
- * withdrawAmount: BigInt("1000000000"),
170
- * });
171
- * ```
172
- */
173
- getWithdrawCollateralTx(inputs) {
174
- return __awaiter(this, void 0, void 0, function* () {
175
- var _a;
176
- const { withdrawAmount, recipientAddress, tx: txFromInputs } = inputs;
177
- if (this.vaultId)
178
- throw new Error("this method is not supported for vaults, please use method `getAdminWithdrawTx` on class `PerpetualsVault` instead");
179
- return this.fetchApiTxObject("account/transactions/withdraw-collateral", {
180
- withdrawAmount,
181
- recipientAddress,
182
- walletAddress: this.ownerAddress(),
183
- accountId: this.accountCap.accountId,
184
- txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({
185
- tx: txFromInputs !== null && txFromInputs !== void 0 ? txFromInputs : new transactions_1.Transaction(),
186
- })),
187
- }, undefined, {
188
- txKind: true,
189
- });
190
- });
191
- }
192
- /**
193
- * Build an `allocate-collateral` transaction, moving collateral from this
194
- * account into a specific market (clearing house).
195
- *
196
- * Works for both account-backed and vault-backed accounts.
197
- *
198
- * @param inputs.marketId - Market to allocate collateral to.
199
- * @param inputs.allocateAmount - Amount of collateral to allocate.
200
- * @param inputs.tx - Optional transaction to extend.
201
- *
202
- * @returns Transaction response containing a `tx`.
203
- */
204
- getAllocateCollateralTx(inputs) {
205
- return __awaiter(this, void 0, void 0, function* () {
206
- var _a;
207
- const { tx, allocateAmount, marketId } = inputs;
208
- return this.fetchApiTxObject(`${this.vaultId ? "vault" : "account"}/` +
209
- "transactions/allocate-collateral", Object.assign(Object.assign({ marketId,
210
- allocateAmount }, ("vaultId" in this.accountCap
211
- ? {
212
- vaultId: this.accountCap.vaultId,
213
- accountId: undefined,
214
- }
215
- : {
216
- accountId: this.accountCap.accountId,
217
- accountCapId: this.accountCap.objectId,
218
- vaultId: undefined,
219
- })), { walletAddress: this.ownerAddress(), txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction() })) }), undefined, {
220
- txKind: true,
221
- });
222
- });
223
- }
224
- /**
225
- * Build a `deallocate-collateral` transaction, moving collateral from a
226
- * specific market back to this account.
227
- *
228
- * Works for both account-backed and vault-backed accounts.
229
- *
230
- * @param inputs.marketId - Market to deallocate collateral from.
231
- * @param inputs.deallocateAmount - Amount of collateral to deallocate.
232
- * @param inputs.tx - Optional transaction to extend.
233
- *
234
- * @returns Transaction response containing a `tx`.
235
- */
236
- getDeallocateCollateralTx(inputs) {
237
- return __awaiter(this, void 0, void 0, function* () {
238
- var _a;
239
- const { tx, deallocateAmount, marketId } = inputs;
240
- return this.fetchApiTxObject(`${this.vaultId ? "vault" : "account"}/` +
241
- "transactions/deallocate-collateral", Object.assign(Object.assign({ marketId,
242
- deallocateAmount }, ("vaultId" in this.accountCap
243
- ? {
244
- vaultId: this.accountCap.vaultId,
245
- accountId: undefined,
246
- }
247
- : {
248
- accountId: this.accountCap.accountId,
249
- accountCapId: this.accountCap.objectId,
250
- vaultId: undefined,
251
- })), { walletAddress: this.ownerAddress(), txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction() })) }), undefined, {
252
- txKind: true,
253
- });
254
- });
255
- }
256
- /**
257
- * Build a `transfer-collateral` transaction between two Perpetuals accounts.
258
- *
259
- * Only supported for direct accounts, **not** vault-backed accounts.
260
- *
261
- * @param inputs.transferAmount - Amount of collateral to transfer.
262
- * @param inputs.toAccountId - Destination account ID.
263
- * @param inputs.tx - Optional transaction to extend.
264
- *
265
- * @returns Transaction response containing a `tx`.
266
- */
267
- getTransferCollateralTx(inputs) {
268
- return __awaiter(this, void 0, void 0, function* () {
269
- var _a;
270
- const { transferAmount, toAccountId, toAccountCapId, tx } = inputs;
271
- if ("vaultId" in this.accountCap)
272
- throw new Error("`getTransferCollateralTx` not supported by vault accounts");
273
- return this.fetchApiTxObject(`${this.vaultId ? "vault" : "account"}/` +
274
- "transactions/transfer-collateral", {
275
- transferAmount,
276
- toAccountId,
277
- toAccountCapId,
278
- walletAddress: this.ownerAddress(),
279
- fromAccountId: this.accountCap.accountId,
280
- fromAccountCapId: this.accountCap.objectId,
281
- txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction() })),
282
- }, undefined, {
283
- txKind: true,
284
- });
285
- });
286
- }
287
- // =========================================================================
288
- // Order Txs
289
- // =========================================================================
290
- /**
291
- * Build a `place-market-order` transaction for this account.
292
- *
293
- * This is the primary entrypoint for opening/closing positions via market orders.
294
- * It automatically:
295
- * - Injects the account/vault identity into the payload.
296
- * - Derives `hasPosition` based on the current account state for the given market.
297
- * - Optionally attaches SL/TP stop orders via the `slTp` input.
298
- *
299
- * Important behavioral notes:
300
- * - `hasPosition` is derived from the local {@link PerpetualsAccountObject} snapshot.
301
- * If the snapshot is stale, consider re-fetching the account first.
302
- * - For vault-backed accounts, the API routes to `/perpetuals/vault/...` and uses
303
- * `vaultId` as the identity discriminator. For direct accounts, it uses `accountId`.
304
- *
305
- * @param inputs - See {@link SdkPerpetualsPlaceMarketOrderInputs} for details.
306
- * Notably:
307
- * - `marketId`, `side`, `size`, `collateralChange`, `reduceOnly`
308
- * - Optional `leverage`
309
- * - Optional `slTp` params
310
- * - Optional `tx` to extend
311
- *
312
- * @returns Transaction response containing `tx`.
313
- *
314
- * @example
315
- * ```ts
316
- * const { tx } = await account.getPlaceMarketOrderTx({
317
- * marketId: "0x...",
318
- * side: PerpetualsOrderSide.Bid,
319
- * size: BigInt("1000000000"),
320
- * collateralChange: 10,
321
- * reduceOnly: false,
322
- * });
323
- * ```
324
- */
325
- getPlaceMarketOrderTx(inputs) {
326
- return __awaiter(this, void 0, void 0, function* () {
327
- var _a;
328
- const { tx: txFromInputs } = inputs, otherInputs = __rest(inputs, ["tx"]);
329
- const tx = txFromInputs !== null && txFromInputs !== void 0 ? txFromInputs : new transactions_1.Transaction();
330
- // tx.setSender(this.ownerAddress());
331
- return this.fetchApiTxObject(`${this.vaultId ? "vault" : "account"}/` +
332
- "transactions/place-market-order", Object.assign(Object.assign(Object.assign({}, otherInputs), { txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })), walletAddress: this.ownerAddress() }), ("vaultId" in this.accountCap
333
- ? {
334
- vaultId: this.accountCap.vaultId,
335
- accountId: undefined,
336
- }
337
- : {
338
- accountId: this.accountCap.accountId,
339
- accountCapId: this.accountCap.objectId,
340
- vaultId: undefined,
341
- })), undefined, {
342
- txKind: true,
343
- });
344
- });
345
- }
346
- /**
347
- * Build a `place-limit-order` transaction for this account.
348
- *
349
- * Similar to {@link getPlaceMarketOrderTx}, but uses limit order semantics:
350
- * - Requires `price` and `orderType`.
351
- * - Supports reduce-only flags, expiry, optional leverage, and SL/TP stop orders.
352
- *
353
- * Notes:
354
- * - `hasPosition` is derived from local account state; refresh the account if needed.
355
- * - This method does not validate tick/lot sizing locally; the API/on-chain
356
- * will enforce market constraints.
357
- *
358
- * @param inputs - See {@link SdkPerpetualsPlaceLimitOrderInputs}.
359
- *
360
- * @returns Transaction response containing `tx`.
361
- */
362
- getPlaceLimitOrderTx(inputs) {
363
- return __awaiter(this, void 0, void 0, function* () {
364
- var _a;
365
- const { tx: txFromInputs } = inputs, otherInputs = __rest(inputs, ["tx"]);
366
- const tx = txFromInputs !== null && txFromInputs !== void 0 ? txFromInputs : new transactions_1.Transaction();
367
- // tx.setSender(this.ownerAddress());
368
- return this.fetchApiTxObject(`${this.vaultId ? "vault" : "account"}/` +
369
- "transactions/place-limit-order", Object.assign(Object.assign(Object.assign({}, otherInputs), { txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })), walletAddress: this.ownerAddress() }), ("vaultId" in this.accountCap
370
- ? {
371
- vaultId: this.accountCap.vaultId,
372
- accountId: undefined,
373
- }
374
- : {
375
- accountId: this.accountCap.accountId,
376
- accountCapId: this.accountCap.objectId,
377
- vaultId: undefined,
378
- })), undefined, {
379
- txKind: true,
380
- });
381
- });
382
- }
383
- /**
384
- * Build a `cancel-orders` transaction for this account.
385
- *
386
- * Each market in `marketIdsToData` supplies:
387
- * - `orderIds`: the orders to cancel in that market
388
- * - `collateralChange`: collateral adjustment to apply alongside cancellation
389
- * - `leverage`: leverage context used for estimating/validating constraints server-side
390
- *
391
- * Notes:
392
- * - Cancels are applied per market; some markets may succeed while others fail
393
- * depending on API/on-chain validation (returned as a transaction failure at execution).
394
- * - If you need to understand the effect prior to building a tx, use
395
- * {@link getCancelOrdersPreview}.
396
- *
397
- * @param inputs.tx - Optional transaction to extend.
398
- * @param inputs.marketIdsToData - Mapping from market IDs to cancel payloads.
399
- *
400
- * @returns Transaction response containing `tx`.
401
- */
402
- getCancelOrdersTx(inputs) {
403
- return __awaiter(this, void 0, void 0, function* () {
404
- var _a;
405
- const { tx } = inputs, otherInputs = __rest(inputs, ["tx"]);
406
- return this.fetchApiTxObject(`${this.vaultId ? "vault" : "account"}/` +
407
- "transactions/cancel-orders", Object.assign(Object.assign(Object.assign({}, otherInputs), { txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })), walletAddress: this.ownerAddress() }), ("vaultId" in this.accountCap
408
- ? {
409
- vaultId: this.accountCap.vaultId,
410
- accountId: undefined,
411
- }
412
- : {
413
- accountId: this.accountCap.accountId,
414
- accountCapId: this.accountCap.objectId,
415
- vaultId: undefined,
416
- })), undefined, {
417
- txKind: true,
418
- });
419
- });
420
- }
421
- /**
422
- * Build a `cancel-stop-orders` transaction for this account.
423
- *
424
- * This cancels stop-order *objects/tickets* by their object IDs. These IDs are
425
- * returned by stop-order query endpoints (see {@link getStopOrderDatas}).
426
- *
427
- * @param inputs.tx - Optional transaction to extend.
428
- * @param inputs.stopOrderIds - Array of stop-order ticket IDs to cancel.
429
- *
430
- * @returns Transaction response containing `tx`.
431
- */
432
- getCancelStopOrdersTx(inputs) {
433
- return __awaiter(this, void 0, void 0, function* () {
434
- var _a;
435
- const { tx } = inputs, otherInputs = __rest(inputs, ["tx"]);
436
- return this.fetchApiTxObject(`${this.vaultId ? "vault" : "account"}/` +
437
- "transactions/cancel-stop-orders", Object.assign(Object.assign(Object.assign({}, otherInputs), { txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })), walletAddress: this.ownerAddress() }), ("vaultId" in this.accountCap
438
- ? {
439
- vaultId: this.accountCap.vaultId,
440
- accountId: undefined,
441
- }
442
- : {
443
- accountId: this.accountCap.accountId,
444
- accountCapId: this.accountCap.objectId,
445
- vaultId: undefined,
446
- })), undefined, {
447
- txKind: true,
448
- });
449
- });
450
- }
451
- /**
452
- * Build a `place-stop-orders` transaction for this account.
453
- *
454
- * This allows placing one or more stop orders in a single transaction,
455
- * optionally with a dedicated gas coin and a sponsored gas flag.
456
- *
457
- * Typical usage:
458
- * - Construct stop order payload(s) client-side
459
- * - Call this method to build a transaction kind
460
- * - Sign/execute the transaction via Sui
461
- *
462
- * @param inputs - See {@link SdkPerpetualsPlaceStopOrdersInputs}.
463
- *
464
- * @returns Transaction response containing `tx`.
465
- */
466
- getPlaceStopOrdersTx(inputs) {
467
- return __awaiter(this, void 0, void 0, function* () {
468
- var _a;
469
- const { tx: txFromInputs, isSponsoredTx, stopOrders, gasCoinArg, } = inputs;
470
- const tx = txFromInputs !== null && txFromInputs !== void 0 ? txFromInputs : new transactions_1.Transaction();
471
- // tx.setSender(this.ownerAddress());
472
- return this.fetchApiTxObject(`${this.vaultId ? "vault" : "account"}/` +
473
- "transactions/place-stop-orders", Object.assign({ stopOrders,
474
- gasCoinArg,
475
- isSponsoredTx, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })), walletAddress: this.ownerAddress() }, ("vaultId" in this.accountCap
476
- ? {
477
- vaultId: this.accountCap.vaultId,
478
- accountId: undefined,
479
- }
480
- : {
481
- accountId: this.accountCap.accountId,
482
- accountCapId: this.accountCap.objectId,
483
- vaultId: undefined,
484
- })), undefined, {
485
- txKind: true,
486
- });
487
- });
488
- }
489
- /**
490
- * Build a `place-sl-tp-orders` transaction for this account.
491
- *
492
- * This helper constructs SL/TP stop orders for an **existing** position
493
- * in a given market. If the account has no position for `marketId`, this
494
- * throws an error.
495
- *
496
- * Implementation details:
497
- * - Determines the current position side from the account snapshot.
498
- * - Sets `positionSide` for the API so SL/TP orders are bound to closing logic
499
- * (i.e. they should trigger on the opposite side of the open position).
500
- *
501
- * @param inputs - See {@link SdkPerpetualsPlaceSlTpOrdersInputs}.
502
- *
503
- * @returns Transaction response containing `tx`.
504
- */
505
- getPlaceSlTpOrdersTx(inputs) {
506
- return __awaiter(this, void 0, void 0, function* () {
507
- var _a;
508
- const { tx: txFromInputs, isSponsoredTx, marketId } = inputs, slTpInputs = __rest(inputs, ["tx", "isSponsoredTx", "marketId"]);
509
- const position = this.positionForMarketId({ marketId });
510
- if (!position)
511
- throw new Error("you have no position for this market");
512
- const tx = txFromInputs !== null && txFromInputs !== void 0 ? txFromInputs : new transactions_1.Transaction();
513
- // tx.setSender(this.ownerAddress());
514
- return this.fetchApiTxObject(`${this.vaultId ? "vault" : "account"}/` +
515
- "transactions/place-sl-tp-orders", Object.assign(Object.assign(Object.assign(Object.assign({}, slTpInputs), { marketId, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })), walletAddress: this.ownerAddress() }), ("vaultId" in this.accountCap
516
- ? {
517
- vaultId: this.accountCap.vaultId,
518
- accountId: undefined,
519
- }
520
- : {
521
- accountId: this.accountCap.accountId,
522
- accountCapId: this.accountCap.objectId,
523
- vaultId: undefined,
524
- })), { positionSide: perpetuals_1.Perpetuals.positionSide({
525
- baseAssetAmount: position.baseAssetAmount,
526
- }) }), undefined, {
527
- txKind: true,
528
- });
529
- });
530
- }
531
- /**
532
- * Build an `edit-stop-orders` transaction for this account.
533
- *
534
- * This endpoint lets you update existing stop orders in batch.
535
- *
536
- * Notes:
537
- * - You must provide the full updated stop-order objects (including object IDs).
538
- * - This is typically used to adjust trigger prices, sizes, expiries, or the
539
- * embedded limit-order parameters.
540
- *
541
- * @param inputs.stopOrders - Full updated stop-order payloads to apply.
542
- * @param inputs.tx - Optional transaction to extend.
543
- *
544
- * @returns Transaction response containing `tx`.
545
- */
546
- getEditStopOrdersTx(inputs) {
547
- return __awaiter(this, void 0, void 0, function* () {
548
- var _a;
549
- const { tx: txFromInputs, stopOrders } = inputs;
550
- const tx = txFromInputs !== null && txFromInputs !== void 0 ? txFromInputs : new transactions_1.Transaction();
551
- // tx.setSender(this.ownerAddress());
552
- return this.fetchApiTxObject(`${this.vaultId ? "vault" : "account"}/` +
553
- "transactions/edit-stop-orders", Object.assign({ stopOrders, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })), walletAddress: this.ownerAddress() }, ("vaultId" in this.accountCap
554
- ? {
555
- vaultId: this.accountCap.vaultId,
556
- accountId: undefined,
557
- }
558
- : {
559
- accountId: this.accountCap.accountId,
560
- accountCapId: this.accountCap.objectId,
561
- vaultId: undefined,
562
- })), undefined, {
563
- txKind: true,
564
- });
565
- });
566
- }
567
- // public async getReduceOrderTx(inputs: {
568
- // tx?: Transaction;
569
- // collateralChange: number;
570
- // marketId: PerpetualsMarketId;
571
- // orderId: PerpetualsOrderId;
572
- // sizeToSubtract: bigint;
573
- // leverage?: number;
574
- // }) {
575
- // const { tx, ...otherInputs } = inputs;
576
- // return this.fetchApiTxObject<
577
- // ApiPerpetualsReduceOrderBody,
578
- // ApiTransactionResponse
579
- // >(
580
- // `${this.vaultId ? "vault" : "account"}/` +
581
- // "transactions/reduce-order",
582
- // {
583
- // ...otherInputs,
584
- // txKind: await this.Provider?.Transactions().fetchBase64TxKindFromTx(
585
- // { tx }
586
- // ),
587
- // walletAddress: this.ownerAddress(),
588
- // ...("vaultId" in this.accountCap
589
- // ? {
590
- // vaultId: this.accountCap.vaultId,
591
- // accountId: undefined,
592
- // }
593
- // : {
594
- // accountId: this.accountCap.accountId,
595
- // vaultId: undefined,
596
- // }),
597
- // },
598
- // undefined,
599
- // {
600
- // txKind: true,
601
- // }
602
- // );
603
- // }
604
- /**
605
- * Build a `set-leverage` transaction for a given market.
606
- *
607
- * This updates the effective leverage for the position (or potential position)
608
- * in `marketId`, and optionally adjusts collateral in tandem.
609
- *
610
- * Notes:
611
- * - Leverage changes may be constrained by protocol risk limits and current
612
- * position state.
613
- * - If you want to understand the effect first, use {@link getSetLeveragePreview}.
614
- *
615
- * @param inputs.tx - Optional transaction to extend.
616
- * @param inputs.leverage - Target leverage value.
617
- * @param inputs.collateralChange - Net collateral change to apply alongside
618
- * the leverage update.
619
- * @param inputs.marketId - Market whose leverage to adjust.
620
- *
621
- * @returns Transaction response containing `tx`.
622
- */
623
- getSetLeverageTx(inputs) {
624
- return __awaiter(this, void 0, void 0, function* () {
625
- var _a;
626
- const { leverage, tx, collateralChange, marketId } = inputs;
627
- return this.fetchApiTxObject(`${this.vaultId ? "vault" : "account"}/` +
628
- "transactions/set-leverage", Object.assign({ leverage,
629
- marketId,
630
- collateralChange, txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({ tx })), walletAddress: this.ownerAddress() }, ("vaultId" in this.accountCap
631
- ? {
632
- vaultId: this.accountCap.vaultId,
633
- accountId: undefined,
634
- }
635
- : {
636
- accountId: this.accountCap.accountId,
637
- accountCapId: this.accountCap.objectId,
638
- vaultId: undefined,
639
- })), undefined, {
640
- txKind: true,
641
- });
642
- });
643
- }
644
- // =========================================================================
645
- // Position Txs
646
- // =========================================================================
647
- // public async getClosePositionTx(inputs: {
648
- // size: bigint;
649
- // market: PerpetualsMarket;
650
- // orderDatas: PerpetualsOrderData[];
651
- // indexPrice: number;
652
- // collateralPrice: number;
653
- // }) {
654
- // throw new Error("TODO");
655
- // // return this.getPlaceMarketOrderTx({
656
- // // ...this.closePositionTxInputs(inputs),
657
- // // });
658
- // }
659
- // =========================================================================
660
- // Interactions
661
- // =========================================================================
662
- /**
663
- * Build a deterministic message payload to sign when querying stop orders
664
- * from the backend.
665
- *
666
- * This payload is intended to be signed off-chain and then submitted to
667
- * `getStopOrderDatas` as a proof of account ownership.
668
- *
669
- * Important:
670
- * - The returned payload is *not* a Sui transaction; it is an off-chain
671
- * “authentication” message.
672
- * - The backend expects `account_id` to be a decimal string. This code
673
- * normalizes the bigint `accountId` by stripping the trailing `n`.
674
- *
675
- * @param inputs.marketIds - Optional list of market IDs to scope the query.
676
- *
677
- * @returns An object describing the action and account/market IDs, suitable
678
- * for message signing.
679
- *
680
- * @example
681
- * ```ts
682
- * const message = account.getStopOrdersMessageToSign({ marketIds: ["0x..."] });
683
- * const { signature } = await wallet.signMessage({
684
- * message: new TextEncoder().encode(JSON.stringify(message)),
685
- * });
686
- * ```
687
- */
688
- getStopOrdersMessageToSign(inputs) {
689
- var _a;
690
- return {
691
- action: "GET_STOP_ORDERS",
692
- account_id: this.accountCap.accountId
693
- .toString()
694
- .replaceAll("n", ""),
695
- clearing_house_ids: (_a = inputs === null || inputs === void 0 ? void 0 : inputs.marketIds) !== null && _a !== void 0 ? _a : [],
696
- };
697
- }
698
- // public async getPlaceOrderPreview(
699
- // inputs: SdkPerpetualsPlaceOrderPreviewInputs,
700
- // abortSignal?: AbortSignal
701
- // ): Promise<
702
- // | {
703
- // error: string;
704
- // }
705
- // | {
706
- // updatedPosition: PerpetualsPosition;
707
- // priceSlippage: number;
708
- // percentSlippage: Percentage;
709
- // filledSize: number;
710
- // filledSizeUsd: number;
711
- // postedSize: number;
712
- // postedSizeUsd: number;
713
- // collateralChange: number;
714
- // executionPrice: number;
715
- // }
716
- // > {
717
- // return this.fetchApi<
718
- // ApiPerpetualsPreviewOrderResponse,
719
- // ApiPerpetualsPreviewOrderBody
720
- // >(
721
- // `${this.vaultId ? "vault" : "account"}/` +"previews/place-order",
722
- // {
723
- // ...inputs,
724
- // accountId: this.accountCap.accountId,
725
- // collateralCoinType: this.accountCap.collateralCoinType,
726
- // },
727
- // abortSignal
728
- // );
729
- // }
730
- /**
731
- * Preview the effects of placing a market order (without building a tx).
732
- *
733
- * This is a read-only API call that runs the protocol’s pricing / margin /
734
- * slippage logic against the current market state and your account/vault context.
735
- *
736
- * @param inputs - See {@link SdkPerpetualsPlaceMarketOrderPreviewInputs}.
737
- * @param abortSignal - Optional `AbortSignal` to cancel the request.
738
- *
739
- * @returns Either an error message or a preview including:
740
- * - `updatedPosition`
741
- * - `priceSlippage`, `percentSlippage`
742
- * - `filledSize`, `filledSizeUsd`
743
- * - `postedSize`, `postedSizeUsd`
744
- * - `collateralChange`
745
- * - `executionPrice`
746
- */
747
- getPlaceMarketOrderPreview(inputs, abortSignal) {
748
- return __awaiter(this, void 0, void 0, function* () {
749
- return this.fetchApi(`${this.vaultId ? "vault" : "account"}/` +
750
- "previews/place-market-order", Object.assign(Object.assign({}, inputs), ("vaultId" in this.accountCap
751
- ? {
752
- vaultId: this.accountCap.vaultId,
753
- accountId: undefined,
754
- }
755
- : {
756
- accountId: this.accountCap.accountId,
757
- accountCapId: this.accountCap.objectId,
758
- vaultId: undefined,
759
- })), abortSignal);
760
- });
761
- }
762
- /**
763
- * Preview the effects of placing a limit order (without building a tx).
764
- *
765
- * The preview simulates:
766
- * - How much size would execute immediately vs post to the book
767
- * - Expected slippage and execution price
768
- * - Resulting position and margin impact
769
- *
770
- * @param inputs - See {@link SdkPerpetualsPlaceLimitOrderPreviewInputs}.
771
- * @param abortSignal - Optional `AbortSignal` to cancel the request.
772
- *
773
- * @returns Either an error message or a preview object similar to
774
- * {@link getPlaceMarketOrderPreview}.
775
- */
776
- getPlaceLimitOrderPreview(inputs, abortSignal) {
777
- return __awaiter(this, void 0, void 0, function* () {
778
- return this.fetchApi(`${this.vaultId ? "vault" : "account"}/` +
779
- "previews/place-limit-order", Object.assign(Object.assign({}, inputs), ("vaultId" in this.accountCap
780
- ? {
781
- vaultId: this.accountCap.vaultId,
782
- accountId: undefined,
783
- }
784
- : {
785
- accountId: this.accountCap.accountId,
786
- accountCapId: this.accountCap.objectId,
787
- vaultId: undefined,
788
- })), abortSignal);
789
- });
790
- }
791
- /**
792
- * Preview the effects of canceling orders across one or more markets.
793
- *
794
- * This is commonly used to:
795
- * - Validate that cancels are allowed under current margin constraints
796
- * - Estimate how collateral/margin would change after canceling (and applying
797
- * the associated `collateralChange` values)
798
- *
799
- * If `marketIdsToData` is empty, this returns a trivial preview with:
800
- * - `marketIdsToData: {}`
801
- *
802
- * @param inputs - See {@link SdkPerpetualsCancelOrdersPreviewInputs}.
803
- * @param abortSignal - Optional `AbortSignal` to cancel the request.
804
- *
805
- * @returns Either:
806
- * - `{ marketIdsToData }`, or
807
- * - `{ error }`.
808
- */
809
- getCancelOrdersPreview(inputs, abortSignal) {
810
- return __awaiter(this, void 0, void 0, function* () {
811
- // NOTE: should this case return an error instead ?
812
- if (Object.keys(inputs.marketIdsToData).length <= 0)
813
- return {
814
- marketIdsToData: {},
815
- };
816
- return this.fetchApi(`${this.vaultId ? "vault" : "account"}/` + "previews/cancel-orders", Object.assign(Object.assign({}, inputs), ("vaultId" in this.accountCap
817
- ? {
818
- vaultId: this.accountCap.vaultId,
819
- accountId: undefined,
820
- }
821
- : {
822
- accountId: this.accountCap.accountId,
823
- accountCapId: this.accountCap.objectId,
824
- vaultId: undefined,
825
- })), abortSignal);
826
- });
827
- }
828
- // public async getReduceOrderPreview(
829
- // inputs: {
830
- // marketId: PerpetualsMarketId;
831
- // orderId: PerpetualsOrderId;
832
- // sizeToSubtract: bigint;
833
- // leverage?: number;
834
- // },
835
- // abortSignal?: AbortSignal
836
- // ): Promise<
837
- // | {
838
- // positionAfterReduceOrder: PerpetualsPosition;
839
- // collateralChange: number;
840
- // }
841
- // | {
842
- // error: string;
843
- // }
844
- // > {
845
- // return this.fetchApi<
846
- // ApiPerpetualsPreviewReduceOrderResponse,
847
- // ApiPerpetualsPreviewReduceOrderBody
848
- // >(
849
- // `${this.vaultId ? "vault" : "account"}/` + "previews/reduce-order",
850
- // {
851
- // ...inputs,
852
- // ...("vaultId" in this.accountCap
853
- // ? {
854
- // vaultId: this.accountCap.vaultId,
855
- // accountId: undefined,
856
- // }
857
- // : {
858
- // accountId: this.accountCap.accountId,
859
- // vaultId: undefined,
860
- // }),
861
- // },
862
- // abortSignal
863
- // );
864
- // }
865
- /**
866
- * Preview the effects of setting leverage for a given market.
867
- *
868
- * The preview returns:
869
- * - The position after the leverage change (`updatedPosition`)
870
- * - The collateral delta required/produced (`collateralChange`)
871
- *
872
- * @param inputs.marketId - Market whose leverage you want to adjust.
873
- * @param inputs.leverage - Target leverage value.
874
- * @param abortSignal - Optional `AbortSignal` to cancel the request.
875
- *
876
- * @returns Either:
877
- * - `{ updatedPosition, collateralChange }`, or
878
- * - `{ error }`.
879
- */
880
- getSetLeveragePreview(inputs, abortSignal) {
881
- return __awaiter(this, void 0, void 0, function* () {
882
- const { marketId, leverage } = inputs;
883
- return this.fetchApi(`${this.vaultId ? "vault" : "account"}/` + "previews/set-leverage", Object.assign({ marketId,
884
- leverage }, ("vaultId" in this.accountCap
885
- ? {
886
- vaultId: this.accountCap.vaultId,
887
- accountId: undefined,
888
- }
889
- : {
890
- accountId: this.accountCap.accountId,
891
- accountCapId: this.accountCap.objectId,
892
- vaultId: undefined,
893
- })), abortSignal);
894
- });
895
- }
896
- /**
897
- * Preview the effects of allocating/deallocating collateral for the position in
898
- * a given market.
899
- *
900
- * Semantics:
901
- * - Positive `collateralChange` previews allocation (moving collateral into the market).
902
- * - Negative `collateralChange` previews deallocation (moving collateral out of the market).
903
- *
904
- * @param inputs.marketId - Market of whose position you want to allocate/deallocate
905
- * collateral to/from.
906
- * @param inputs.collateralChange - The target collateral change (a positive number
907
- * for allocating collateral, negative for deallocating collateral).
908
- * @param abortSignal - Optional `AbortSignal` to cancel the request.
909
- *
910
- * @returns Either:
911
- * - `{ updatedPosition, collateralChange }`, or
912
- * - `{ error }`.
913
- */
914
- getEditCollateralPreview(inputs, abortSignal) {
915
- return __awaiter(this, void 0, void 0, function* () {
916
- const { marketId, collateralChange } = inputs;
917
- return this.fetchApi(`${this.vaultId ? "vault" : "account"}/` +
918
- "previews/edit-collateral", Object.assign({ marketId,
919
- collateralChange }, ("vaultId" in this.accountCap
920
- ? {
921
- vaultId: this.accountCap.vaultId,
922
- accountId: undefined,
923
- }
924
- : {
925
- accountId: this.accountCap.accountId,
926
- accountCapId: this.accountCap.objectId,
927
- vaultId: undefined,
928
- })), abortSignal);
929
- });
930
- }
931
- // public getPlaceClosePositionOrderPreview = async (
932
- // inputs: {
933
- // size: bigint;
934
- // marketId: PerpetualsMarketId;
935
- // leverage?: number;
936
- // } & (
937
- // | {
938
- // accountId: PerpetualsAccountId;
939
- // }
940
- // | {
941
- // vaultId: ObjectId;
942
- // }
943
- // ),
944
- // abortSignal?: AbortSignal
945
- // ): Promise<ReturnType<PerpetualsAccount["getPlaceMarketOrderPreview"]>> => {
946
- // // TODO: make this fetch instead ?
947
- // const position = this.positionForMarketId({
948
- // marketId: inputs.marketId,
949
- // });
950
- // if (!position)
951
- // throw new Error(
952
- // `Account has no position for market id: ${inputs.marketId}`
953
- // );
954
- // return this.getPlaceMarketOrderPreview(
955
- // {
956
- // ...inputs,
957
- // reduceOnly: true,
958
- // side:
959
- // Perpetuals.positionSide(position) ===
960
- // PerpetualsOrderSide.Ask
961
- // ? PerpetualsOrderSide.Bid
962
- // : PerpetualsOrderSide.Ask,
963
- // },
964
- // abortSignal
965
- // );
966
- // };
967
- /**
968
- * Fetch stop-order ticket data for this account, using an off-chain signed
969
- * payload.
970
- *
971
- * Typical flow:
972
- * 1) Call {@link getStopOrdersMessageToSign} to construct a deterministic payload
973
- * 2) Sign the payload with the wallet
974
- * 3) Provide the signed payload to this method to fetch stop order data
975
- *
976
- * @param inputs.bytes - Serialized message that was signed (e.g. JSON string).
977
- * @param inputs.signature - Signature over `bytes`.
978
- * @param inputs.marketIds - Optional subset of markets to filter results by.
979
- *
980
- * @returns {@link ApiPerpetualsStopOrderDatasResponse} containing `stopOrderDatas`.
981
- */
982
- getStopOrderDatas(inputs) {
983
- return __awaiter(this, void 0, void 0, function* () {
984
- const { bytes, signature, marketIds } = inputs;
985
- return this.fetchApi(`${this.vaultId ? "vault" : "account"}/` + "stop-order-datas", Object.assign({ bytes,
986
- signature, walletAddress: this.ownerAddress(), marketIds: marketIds !== null && marketIds !== void 0 ? marketIds : [] }, ("vaultId" in this.accountCap
987
- ? {
988
- vaultId: this.accountCap.vaultId,
989
- accountId: undefined,
990
- }
991
- : {
992
- accountId: this.accountCap.accountId,
993
- accountCapId: this.accountCap.objectId,
994
- vaultId: undefined,
995
- })));
996
- });
997
- }
998
- /**
999
- * Fetch paginated collateral-change history for this account, including
1000
- * deposits, withdrawals, funding settlements, liquidations, etc.
1001
- *
1002
- * Pagination:
1003
- * - Use `beforeTimestampCursor` to fetch older entries.
1004
- * - The API returns a `nextBeforeTimestampCursor` to continue pagination.
1005
- *
1006
- * @param inputs.beforeTimestampCursor - Optional cursor for pagination.
1007
- * @param inputs.limit - Optional limit per page.
1008
- *
1009
- * @returns {@link ApiPerpetualsAccountCollateralHistoryResponse} containing
1010
- * an array of changes and a `nextBeforeTimestampCursor`.
1011
- */
1012
- getCollateralHistory(inputs) {
1013
- return __awaiter(this, void 0, void 0, function* () {
1014
- return this.fetchApi("account/collateral-history", Object.assign(Object.assign({}, inputs), { accountId: this.accountCap.accountId }));
1015
- });
1016
- }
1017
- /**
1018
- * Fetch paginated order history for this account.
1019
- *
1020
- * This endpoint is distinct from {@link getOrderDatas}:
1021
- * - `getOrderDatas` resolves current/pending orders based on the snapshot.
1022
- * - `getOrderHistory` returns historical order events (fills, cancels, etc.)
1023
- * over time with cursor-based pagination.
1024
- *
1025
- * @param inputs.beforeTimestampCursor - Optional cursor for pagination.
1026
- * @param inputs.limit - Optional limit per page.
1027
- *
1028
- * @returns {@link ApiPerpetualsAccountOrderHistoryResponse} containing a list of
1029
- * orders and a `nextBeforeTimestampCursor`.
1030
- */
1031
- getOrderHistory(inputs) {
1032
- return __awaiter(this, void 0, void 0, function* () {
1033
- return this.fetchApi("account/order-history", Object.assign(Object.assign({}, inputs), { accountId: this.accountCap.accountId }));
1034
- });
1035
- }
1036
- /**
1037
- * Fetch historical margin snapshots for this account over a time range.
1038
- *
1039
- * This endpoint returns time-series margin data suitable for charting UI
1040
- * such as equity and available collateral over time.
1041
- *
1042
- * Notes:
1043
- * - This is an account-level view (aggregated across markets).
1044
- *
1045
- * @param inputs - {@link ApiPerpetualsAccountMarginHistoryBody} without `accountId`.
1046
- * @returns {@link ApiPerpetualsAccountMarginHistoryResponse} containing `marginHistoryDatas`.
1047
- */
1048
- getMarginHistory(inputs) {
1049
- return __awaiter(this, void 0, void 0, function* () {
1050
- return this.fetchApi("account/margin-history", Object.assign(Object.assign({}, inputs), { accountId: this.accountCap.accountId }));
1051
- });
1052
- }
1053
- // public async getOwnedWithdrawRequests() {
1054
- // return new Perpetuals(
1055
- // this.config,
1056
- // this.Provider
1057
- // ).getOwnedWithdrawRequests({
1058
- // walletAddress: this.ownerAddress(),
1059
- // });
1060
- // }
1061
- /**
1062
- * Build a transaction that grants an Agent Wallet (assistant permissions) for this perpetuals account.
1063
- *
1064
- * The returned transaction must be signed and submitted by the **account admin** wallet.
1065
- * After execution, `recipientAddress` can execute supported trading actions on behalf of this account.
1066
- *
1067
- * Agent wallets can perform all supported actions **except**:
1068
- * - withdrawing collateral, and
1069
- * - granting or revoking other agent wallets.
1070
- *
1071
- * @param inputs.recipientAddress Wallet address to receive agent permissions.
1072
- * @param inputs.tx Optional existing {@link Transaction} to append to. If omitted, a new Transaction is used.
1073
- * @throws If this instance represents a vault account (agent wallets are account-only).
1074
- */
1075
- getGrantAgentWalletTx(inputs) {
1076
- return __awaiter(this, void 0, void 0, function* () {
1077
- var _a;
1078
- const { tx, recipientAddress } = inputs;
1079
- if ("vaultId" in this.accountCap)
1080
- throw new Error("`getGrantAgentWalletTx` not supported by vault accounts");
1081
- return this.fetchApiTxObject("account/transactions/grant-agent-wallet", {
1082
- recipientAddress,
1083
- accountId: this.accountCap.accountId,
1084
- txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({
1085
- tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction(),
1086
- })),
1087
- }, undefined, {
1088
- txKind: true,
1089
- });
1090
- });
1091
- }
1092
- /**
1093
- * Build a transaction that revokes an Agent Wallet (assistant capability) from this perpetuals account.
1094
- *
1095
- * The returned transaction must be signed and submitted by the **account admin** wallet.
1096
- * After execution, the revoked wallet immediately loses its delegated permissions.
1097
- *
1098
- * @param inputs.accountCapId Object ID of the assistant capability to revoke.
1099
- * @param inputs.tx Optional existing {@link Transaction} to append to. If omitted, a new Transaction is used.
1100
- * @throws If this instance represents a vault account (agent wallets are account-only).
1101
- */
1102
- getRevokeAgentWalletTx(inputs) {
1103
- return __awaiter(this, void 0, void 0, function* () {
1104
- var _a;
1105
- const { tx, accountCapId } = inputs;
1106
- if ("vaultId" in this.accountCap)
1107
- throw new Error("`getRevokeAgentWalletTx` not supported by vault accounts");
1108
- return this.fetchApiTxObject("account/transactions/revoke-agent-wallet", {
1109
- accountCapId,
1110
- accountId: this.accountCap.accountId,
1111
- txKind: yield ((_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Transactions().fetchBase64TxKindFromTx({
1112
- tx: tx !== null && tx !== void 0 ? tx : new transactions_1.Transaction(),
1113
- })),
1114
- }, undefined, {
1115
- txKind: true,
1116
- });
1117
- });
1118
- }
1119
- // =========================================================================
1120
- // Helpers
1121
- // =========================================================================
1122
- /**
1123
- * Find the current position for a given market ID, if any.
1124
- *
1125
- * @param inputs.marketId - Market ID to search for.
1126
- * @returns {@link PerpetualsPosition} if found, otherwise `undefined`.
1127
- */
1128
- positionForMarketId(inputs) {
1129
- try {
1130
- return this.account.positions.find((pos) => pos.marketId === inputs.marketId);
1131
- }
1132
- catch (e) {
1133
- return undefined;
1134
- }
1135
- }
1136
- /**
1137
- * Filter a list of stop orders to only include non-SL/TP orders.
1138
- *
1139
- * A stop order is considered SL/TP if it appears in the combined set of
1140
- * SL/TP orders across **all** markets (see {@link slTpStopOrderDatas}).
1141
- *
1142
- * Note:
1143
- * - This implementation uses JSON string equality to compare objects.
1144
- * This is pragmatic but assumes stable field ordering and identical shapes.
1145
- *
1146
- * @param inputs.stopOrderDatas - Full array of stop-order ticket data.
1147
- * @returns An array of non-SL/TP stop orders, or `undefined` if none exist.
1148
- */
1149
- nonSlTpStopOrderDatas(inputs) {
1150
- const { stopOrderDatas } = inputs;
1151
- const slTpOrders = this.slTpStopOrderDatas(inputs);
1152
- const stopOrders = stopOrderDatas.filter((stopOrder) => !(slTpOrders !== null && slTpOrders !== void 0 ? slTpOrders : [])
1153
- .map((slTpOrder) => JSON.stringify(slTpOrder))
1154
- .includes(JSON.stringify(stopOrder)));
1155
- return stopOrders.length <= 0 ? undefined : stopOrders;
1156
- }
1157
- /**
1158
- * Extract all SL/TP-style stop orders across **all** markets for this
1159
- * account.
1160
- *
1161
- * SL/TP orders are stop orders which:
1162
- * - Have an `slTp` payload, and
1163
- * - Target the opposite side of the current position.
1164
- *
1165
- * This combines:
1166
- * - "Full" SL/TP orders (size >= `i64MaxBigInt`)
1167
- * - "Partial" SL/TP orders (size < `i64MaxBigInt`)
1168
- *
1169
- * The "full vs partial" distinction is a protocol convention: some systems
1170
- * encode “close entire position” using a sentinel max size.
1171
- *
1172
- * @param inputs.stopOrderDatas - Full list of stop-order tickets.
1173
- * @returns Array of SL/TP stop orders, or `undefined` if none exist.
1174
- */
1175
- slTpStopOrderDatas(inputs) {
1176
- const { stopOrderDatas } = inputs;
1177
- let slTpOrders = [];
1178
- for (const { marketId } of this.account.positions) {
1179
- const { fullSlTpOrder, partialSlTpOrders } = this.slTpStopOrderDatasForPosition({
1180
- marketId,
1181
- stopOrderDatas,
1182
- });
1183
- slTpOrders = [
1184
- ...slTpOrders,
1185
- ...(fullSlTpOrder ? [fullSlTpOrder] : []),
1186
- ...(partialSlTpOrders !== null && partialSlTpOrders !== void 0 ? partialSlTpOrders : []),
1187
- ];
1188
- }
1189
- for (const limitOrderId of utils_1.Helpers.uniqueArray(stopOrderDatas.map((stopOrder) => { var _a; return (_a = stopOrder.slTp) === null || _a === void 0 ? void 0 : _a.limitOrderId; }))) {
1190
- if (limitOrderId === undefined)
1191
- continue;
1192
- const { fullSlTpOrder, partialSlTpOrders } = this.slTpStopOrderDatasForLimitOrder({
1193
- limitOrderId,
1194
- stopOrderDatas,
1195
- });
1196
- slTpOrders = [
1197
- ...slTpOrders,
1198
- ...(fullSlTpOrder ? [fullSlTpOrder] : []),
1199
- ...(partialSlTpOrders !== null && partialSlTpOrders !== void 0 ? partialSlTpOrders : []),
1200
- ];
1201
- }
1202
- return slTpOrders.length <= 0 ? undefined : slTpOrders;
1203
- }
1204
- /**
1205
- * Filter stop orders for a single market to only include non-SL/TP orders.
1206
- *
1207
- * Uses {@link slTpStopOrderDatasForPosition} under the hood.
1208
- *
1209
- * @param inputs.marketId - Market ID to filter for.
1210
- * @param inputs.stopOrderDatas - Full list of stop orders.
1211
- * @returns Non-SL/TP stop orders for the given market, or `undefined` if none exist.
1212
- */
1213
- nonSlTpStopOrderDatasForPosition(inputs) {
1214
- const { marketId, stopOrderDatas } = inputs;
1215
- const position = this.positionForMarketId({ marketId });
1216
- if (!position)
1217
- return undefined;
1218
- const { fullSlTpOrder, partialSlTpOrders } = this.slTpStopOrderDatasForPosition(inputs);
1219
- const stopOrders = stopOrderDatas.filter((stopOrder) => !stopOrder.limitOrder &&
1220
- ![
1221
- ...(fullSlTpOrder ? [fullSlTpOrder] : []),
1222
- ...(partialSlTpOrders !== null && partialSlTpOrders !== void 0 ? partialSlTpOrders : []),
1223
- ]
1224
- .map((slTpOrder) => JSON.stringify(slTpOrder))
1225
- .includes(JSON.stringify(stopOrder)));
1226
- return stopOrders.length <= 0 ? undefined : stopOrders;
1227
- }
1228
- /**
1229
- * Categorize stop orders for a specific market into:
1230
- * - A "full" SL/TP order (size >= `i64MaxBigInt`) if any.
1231
- * - A set of "partial" SL/TP orders (size < `i64MaxBigInt`).
1232
- *
1233
- * SL/TP stop orders are defined as:
1234
- * - Market ID matches the input market.
1235
- * - `slTp` field is present.
1236
- * - Order side is opposite of the position side.
1237
- * - At least a `stopLossIndexPrice` or `takeProfitIndexPrice` is set.
1238
- *
1239
- * Notes on matching:
1240
- * - The side comparison uses the current position side derived from the account snapshot.
1241
- * - If `baseAssetAmount === 0` (no effective position), the method returns no SL/TP orders.
1242
- *
1243
- * @param inputs.marketId - Market to categorize stop orders for.
1244
- * @param inputs.stopOrderDatas - Full list of stop orders.
1245
- *
1246
- * @returns Object containing:
1247
- * - `fullSlTpOrder` (if any)
1248
- * - `partialSlTpOrders` (if any, otherwise `undefined`)
1249
- */
1250
- slTpStopOrderDatasForPosition(inputs) {
1251
- const { marketId, stopOrderDatas } = inputs;
1252
- const position = this.positionForMarketId({ marketId });
1253
- if (!position || position.baseAssetAmount === 0) {
1254
- return {
1255
- fullSlTpOrder: undefined,
1256
- partialSlTpOrders: undefined,
1257
- };
1258
- }
1259
- const side = !position ? undefined : perpetuals_1.Perpetuals.positionSide(position);
1260
- /**
1261
- * Implementation note:
1262
- *
1263
- * This method uses a pair of predicates that differ only by the `size` threshold
1264
- * to split “full close” SL/TP from “partial close” SL/TP. The sentinel threshold
1265
- * is {@link Casting.i64MaxBigInt}. Keeping the logic explicit (rather than
1266
- * abstracting into helpers) makes it easier to reason about protocol conventions.
1267
- */
1268
- const fullSlTpOrder = stopOrderDatas.find((order) => order.marketId === marketId &&
1269
- order.slTp &&
1270
- order.side !== side &&
1271
- (order.slTp.stopLossIndexPrice ||
1272
- order.slTp.takeProfitIndexPrice) &&
1273
- order.size >= utils_1.Casting.i64MaxBigInt &&
1274
- !order.limitOrder);
1275
- const partialSlTpOrders = stopOrderDatas.filter((order) => order.marketId === marketId &&
1276
- order.slTp &&
1277
- order.side !== side &&
1278
- (order.slTp.stopLossIndexPrice ||
1279
- order.slTp.takeProfitIndexPrice) &&
1280
- order.size < utils_1.Casting.i64MaxBigInt &&
1281
- !order.limitOrder);
1282
- return {
1283
- fullSlTpOrder,
1284
- partialSlTpOrders: partialSlTpOrders.length <= 0 ? undefined : partialSlTpOrders,
1285
- };
1286
- }
1287
- slTpStopOrderDatasForLimitOrder(inputs) {
1288
- const { stopOrderDatas, limitOrderId } = inputs;
1289
- /**
1290
- * Implementation note:
1291
- *
1292
- * This method uses a pair of predicates that differ only by the `size` threshold
1293
- * to split “full close” SL/TP from “partial close” SL/TP. The sentinel threshold
1294
- * is {@link Casting.i64MaxBigInt}. Keeping the logic explicit (rather than
1295
- * abstracting into helpers) makes it easier to reason about protocol conventions.
1296
- */
1297
- const fullSlTpOrder = stopOrderDatas.find((order) => order.slTp &&
1298
- order.slTp.limitOrderId === limitOrderId &&
1299
- (order.slTp.stopLossIndexPrice ||
1300
- order.slTp.takeProfitIndexPrice) &&
1301
- order.size >= utils_1.Casting.i64MaxBigInt);
1302
- const partialSlTpOrders = stopOrderDatas.filter((order) => order.slTp &&
1303
- order.slTp.limitOrderId === limitOrderId &&
1304
- (order.slTp.stopLossIndexPrice ||
1305
- order.slTp.takeProfitIndexPrice) &&
1306
- order.size < utils_1.Casting.i64MaxBigInt);
1307
- return {
1308
- fullSlTpOrder,
1309
- partialSlTpOrders: partialSlTpOrders.length <= 0 ? undefined : partialSlTpOrders,
1310
- };
1311
- }
1312
- orderDatas() {
1313
- return this.account.positions.reduce((acc, position) => [
1314
- ...acc,
1315
- ...position.pendingOrders.map((order) => ({
1316
- orderId: order.orderId,
1317
- currentSize: order.currentSize,
1318
- initialSize: order.initialSize,
1319
- side: perpetuals_1.Perpetuals.orderIdToSide(order.orderId),
1320
- marketId: position.marketId,
1321
- })),
1322
- ], []);
1323
- }
1324
- /**
1325
- * Convenience accessor for the account's available collateral (in coin units).
1326
- *
1327
- * This is the amount of collateral not currently locked/allocated across markets,
1328
- * as represented by the backend response.
1329
- *
1330
- * @returns Available collateral as a `number`.
1331
- */
1332
- collateral() {
1333
- return this.account.availableCollateral;
1334
- }
1335
- // public collateralDecimals(): CoinDecimal {
1336
- // return this.accountCap.collateralDecimals;
1337
- // }
1338
- // public collateralBalance(): Balance {
1339
- // return Coin.normalizeBalance(
1340
- // this.collateral(),
1341
- // this.collateralDecimals()
1342
- // );
1343
- // }
1344
- /**
1345
- * Check whether this {@link PerpetualsAccount} is vault-backed.
1346
- *
1347
- * @returns `true` if the underlying `accountCap` is a vault cap; otherwise `false`.
1348
- */
1349
- isVault() {
1350
- return "vaultId" in this.accountCap;
1351
- }
1352
- /**
1353
- * Resolve the owner wallet address of this account or vault.
1354
- *
1355
- * - For direct accounts, returns the cap's `walletAddress` field.
1356
- * - For vault-backed accounts, returns the vault cap's `ownerAddress`.
1357
- *
1358
- * Naming note:
1359
- * - Some types use `walletAddress` for direct ownership. For vault-backed accounts
1360
- * the analogous field is `ownerAddress`.
1361
- *
1362
- * @returns Owner wallet {@link SuiAddress}.
1363
- */
1364
- ownerAddress() {
1365
- return "walletAddress" in this.accountCap
1366
- ? // NOTE: direct accounts expose `walletAddress`; vault accounts expose `ownerAddress`.
1367
- this.accountCap.walletAddress
1368
- : this.accountCap.ownerAddress;
1369
- }
1370
- /**
1371
- * Get the underlying account object ID.
1372
- *
1373
- * This is the on-chain object that holds the account's state and positions.
1374
- *
1375
- * @returns {@link ObjectId} of the account object.
1376
- */
1377
- accountObjectId() {
1378
- return this.accountCap.accountObjectId;
1379
- }
1380
- /**
1381
- * Get the numeric perpetuals account ID.
1382
- *
1383
- * This is the protocol-level identifier (bigint-derived) used across API calls.
1384
- *
1385
- * @returns {@link PerpetualsAccountId} for this account.
1386
- */
1387
- accountId() {
1388
- return this.accountCap.accountId;
1389
- }
1390
- /**
1391
- * Get the account cap object ID, if this is a direct account.
1392
- *
1393
- * Direct accounts are controlled via an on-chain “cap” object. Vault-backed
1394
- * accounts are controlled via vault caps and do not expose a direct account-cap ID.
1395
- *
1396
- * @throws If called for a vault-backed account.
1397
- *
1398
- * @returns {@link ObjectId} of the account cap.
1399
- */
1400
- accountCapId() {
1401
- if ("vaultId" in this.accountCap)
1402
- throw new Error("not account cap id present on vault owned account");
1403
- return this.accountCap.objectId;
1404
- }
1405
- }
1406
- exports.PerpetualsAccount = PerpetualsAccount;