@shogun-sdk/intents-sdk 1.0.0 → 1.0.2

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 (309) hide show
  1. package/dist/{_esm → esm}/chains.js +12 -9
  2. package/dist/esm/chains.js.map +1 -0
  3. package/dist/{_esm → esm}/constants.js +12 -1
  4. package/dist/esm/constants.js.map +1 -0
  5. package/dist/esm/core/evm/abi/permit2.js +395 -0
  6. package/dist/esm/core/evm/abi/permit2.js.map +1 -0
  7. package/dist/{_esm → esm}/core/evm/abi/source-chain-guard.js +2 -1
  8. package/dist/esm/core/evm/abi/source-chain-guard.js.map +1 -0
  9. package/dist/{_esm → esm}/core/evm/intent-provider.js.map +1 -1
  10. package/dist/{_esm → esm}/core/evm/order-signature.js +11 -0
  11. package/dist/esm/core/evm/order-signature.js.map +1 -0
  12. package/dist/esm/core/evm/sdk.js +154 -0
  13. package/dist/esm/core/evm/sdk.js.map +1 -0
  14. package/dist/{_esm → esm}/core/evm/viem-provider.js +27 -0
  15. package/dist/esm/core/evm/viem-provider.js.map +1 -0
  16. package/dist/{_esm → esm}/core/sdk.js +31 -7
  17. package/dist/esm/core/sdk.js.map +1 -0
  18. package/dist/{_esm → esm}/core/solana/order-instructions.js +10 -0
  19. package/dist/esm/core/solana/order-instructions.js.map +1 -0
  20. package/dist/{_esm → esm}/core/solana/sdk.js +11 -1
  21. package/dist/esm/core/solana/sdk.js.map +1 -0
  22. package/dist/{_esm → esm}/core/sui/order-transaction.js +10 -0
  23. package/dist/esm/core/sui/order-transaction.js.map +1 -0
  24. package/dist/{_esm → esm}/core/sui/sdk.js +3 -0
  25. package/dist/esm/core/sui/sdk.js.map +1 -0
  26. package/dist/{_esm → esm}/errors/index.js +6 -0
  27. package/dist/{_esm → esm}/errors/index.js.map +1 -1
  28. package/dist/esm/index.js +11 -0
  29. package/dist/esm/index.js.map +1 -0
  30. package/dist/esm/types/api.js +2 -0
  31. package/dist/esm/types/api.js.map +1 -0
  32. package/dist/esm/types/user-order.js +16 -0
  33. package/dist/esm/types/user-order.js.map +1 -0
  34. package/dist/esm/utils/defillama.js +115 -0
  35. package/dist/esm/utils/defillama.js.map +1 -0
  36. package/dist/{_esm → esm}/utils/order-validator.js +1 -1
  37. package/dist/{_esm → esm}/utils/order-validator.js.map +1 -1
  38. package/dist/esm/utils/parsers.js +51 -0
  39. package/dist/esm/utils/parsers.js.map +1 -0
  40. package/dist/{_types → types}/chains.d.ts +12 -21
  41. package/dist/types/chains.d.ts.map +1 -0
  42. package/dist/{_types → types}/constants.d.ts +5 -0
  43. package/dist/types/constants.d.ts.map +1 -0
  44. package/dist/types/core/evm/abi/permit2.d.ts +304 -0
  45. package/dist/types/core/evm/abi/permit2.d.ts.map +1 -0
  46. package/dist/{_types → types}/core/evm/abi/source-chain-guard.d.ts +1 -1
  47. package/dist/{_types → types}/core/evm/abi/source-chain-guard.d.ts.map +1 -1
  48. package/dist/{_types → types}/core/evm/intent-provider.d.ts +2 -1
  49. package/dist/{_types → types}/core/evm/intent-provider.d.ts.map +1 -1
  50. package/dist/{_types → types}/core/evm/order-signature.d.ts +6 -0
  51. package/dist/types/core/evm/order-signature.d.ts.map +1 -0
  52. package/dist/{_types → types}/core/evm/sdk.d.ts +4 -0
  53. package/dist/types/core/evm/sdk.d.ts.map +1 -0
  54. package/dist/types/core/evm/viem-provider.d.ts +19304 -0
  55. package/dist/{_types → types}/core/evm/viem-provider.d.ts.map +1 -1
  56. package/dist/{_types → types}/core/sdk.d.ts +7 -4
  57. package/dist/types/core/sdk.d.ts.map +1 -0
  58. package/dist/{_types → types}/core/solana/order-instructions.d.ts +5 -0
  59. package/dist/types/core/solana/order-instructions.d.ts.map +1 -0
  60. package/dist/{_types → types}/core/solana/sdk.d.ts +1 -0
  61. package/dist/{_types → types}/core/solana/sdk.d.ts.map +1 -1
  62. package/dist/{_types → types}/core/sui/order-transaction.d.ts +5 -0
  63. package/dist/types/core/sui/order-transaction.d.ts.map +1 -0
  64. package/dist/{_types → types}/core/sui/sdk.d.ts +1 -0
  65. package/dist/types/core/sui/sdk.d.ts.map +1 -0
  66. package/dist/{_types → types}/errors/index.d.ts +3 -0
  67. package/dist/{_types → types}/errors/index.d.ts.map +1 -1
  68. package/dist/types/index.d.ts +15 -0
  69. package/dist/types/index.d.ts.map +1 -0
  70. package/dist/types/types/api.d.ts +8 -0
  71. package/dist/types/types/api.d.ts.map +1 -0
  72. package/dist/{_types → types}/types/intent.d.ts +2 -2
  73. package/dist/types/types/intent.d.ts.map +1 -0
  74. package/dist/types/types/user-order.d.ts +37 -0
  75. package/dist/types/types/user-order.d.ts.map +1 -0
  76. package/dist/types/utils/defillama.d.ts +61 -0
  77. package/dist/types/utils/defillama.d.ts.map +1 -0
  78. package/dist/types/utils/parsers.d.ts +19 -0
  79. package/dist/types/utils/parsers.d.ts.map +1 -0
  80. package/package.json +10 -11
  81. package/src/chains.ts +16 -23
  82. package/src/constants.ts +16 -1
  83. package/src/core/evm/abi/permit2.ts +394 -0
  84. package/src/core/evm/abi/source-chain-guard.ts +2 -1
  85. package/src/core/evm/intent-provider.ts +1 -1
  86. package/src/core/evm/order-signature.ts +23 -0
  87. package/src/core/evm/sdk.ts +96 -0
  88. package/src/core/evm/viem-provider.ts +29 -0
  89. package/src/core/sdk.ts +41 -9
  90. package/src/core/solana/order-instructions.ts +20 -0
  91. package/src/core/solana/sdk.ts +14 -0
  92. package/src/core/sui/order-transaction.ts +20 -0
  93. package/src/core/sui/sdk.ts +4 -0
  94. package/src/errors/index.ts +7 -0
  95. package/src/index.ts +13 -2
  96. package/src/types/api.ts +9 -0
  97. package/src/types/intent.ts +2 -2
  98. package/src/types/user-order.ts +74 -0
  99. package/src/utils/defillama.ts +179 -0
  100. package/src/utils/order-validator.ts +1 -1
  101. package/src/utils/parsers.ts +47 -0
  102. package/dist/_esm/chains.js.map +0 -1
  103. package/dist/_esm/constants.js.map +0 -1
  104. package/dist/_esm/core/evm/abi/source-chain-guard.js.map +0 -1
  105. package/dist/_esm/core/evm/order-signature.js.map +0 -1
  106. package/dist/_esm/core/evm/sdk.js +0 -79
  107. package/dist/_esm/core/evm/sdk.js.map +0 -1
  108. package/dist/_esm/core/evm/viem-provider.js.map +0 -1
  109. package/dist/_esm/core/sdk.js.map +0 -1
  110. package/dist/_esm/core/solana/order-instructions.js.map +0 -1
  111. package/dist/_esm/core/solana/sdk.js.map +0 -1
  112. package/dist/_esm/core/sui/order-transaction.js.map +0 -1
  113. package/dist/_esm/core/sui/sdk.js.map +0 -1
  114. package/dist/_esm/index.js +0 -7
  115. package/dist/_esm/index.js.map +0 -1
  116. package/dist/_esm/package.json +0 -1
  117. package/dist/_esm/utils/parsers.js +0 -10
  118. package/dist/_esm/utils/parsers.js.map +0 -1
  119. package/dist/_types/chains.d.ts.map +0 -1
  120. package/dist/_types/constants.d.ts.map +0 -1
  121. package/dist/_types/core/evm/order-signature.d.ts.map +0 -1
  122. package/dist/_types/core/evm/sdk.d.ts.map +0 -1
  123. package/dist/_types/core/evm/viem-provider.d.ts +0 -9657
  124. package/dist/_types/core/sdk.d.ts.map +0 -1
  125. package/dist/_types/core/solana/order-instructions.d.ts.map +0 -1
  126. package/dist/_types/core/sui/order-transaction.d.ts.map +0 -1
  127. package/dist/_types/core/sui/sdk.d.ts.map +0 -1
  128. package/dist/_types/index.d.ts +0 -10
  129. package/dist/_types/index.d.ts.map +0 -1
  130. package/dist/_types/types/intent.d.ts.map +0 -1
  131. package/dist/_types/utils/parsers.d.ts +0 -4
  132. package/dist/_types/utils/parsers.d.ts.map +0 -1
  133. /package/dist/{_esm → esm}/config.js +0 -0
  134. /package/dist/{_esm → esm}/config.js.map +0 -0
  135. /package/dist/{_esm → esm}/core/evm/abi/erc20.js +0 -0
  136. /package/dist/{_esm → esm}/core/evm/abi/erc20.js.map +0 -0
  137. /package/dist/{_esm → esm}/core/evm/intent-provider.js +0 -0
  138. /package/dist/{_esm → esm}/core/evm/permit2.js +0 -0
  139. /package/dist/{_esm → esm}/core/evm/permit2.js.map +0 -0
  140. /package/dist/{_esm → esm}/core/evm/validator.js +0 -0
  141. /package/dist/{_esm → esm}/core/evm/validator.js.map +0 -0
  142. /package/dist/{_esm → esm}/core/order.js +0 -0
  143. /package/dist/{_esm → esm}/core/order.js.map +0 -0
  144. /package/dist/{_esm → esm}/core/solana/client.js +0 -0
  145. /package/dist/{_esm → esm}/core/solana/client.js.map +0 -0
  146. /package/dist/{_esm → esm}/core/solana/generated/accounts/adminSingleton.js +0 -0
  147. /package/dist/{_esm → esm}/core/solana/generated/accounts/adminSingleton.js.map +0 -0
  148. /package/dist/{_esm → esm}/core/solana/generated/accounts/guard.js +0 -0
  149. /package/dist/{_esm → esm}/core/solana/generated/accounts/guard.js.map +0 -0
  150. /package/dist/{_esm → esm}/core/solana/generated/accounts/index.js +0 -0
  151. /package/dist/{_esm → esm}/core/solana/generated/accounts/index.js.map +0 -0
  152. /package/dist/{_esm → esm}/core/solana/generated/accounts/order.js +0 -0
  153. /package/dist/{_esm → esm}/core/solana/generated/accounts/order.js.map +0 -0
  154. /package/dist/{_esm → esm}/core/solana/generated/errors/index.js +0 -0
  155. /package/dist/{_esm → esm}/core/solana/generated/errors/index.js.map +0 -0
  156. /package/dist/{_esm → esm}/core/solana/generated/errors/sourceChainGuard.js +0 -0
  157. /package/dist/{_esm → esm}/core/solana/generated/errors/sourceChainGuard.js.map +0 -0
  158. /package/dist/{_esm → esm}/core/solana/generated/index.js +0 -0
  159. /package/dist/{_esm → esm}/core/solana/generated/index.js.map +0 -0
  160. /package/dist/{_esm → esm}/core/solana/generated/instructions/cancelOrder.js +0 -0
  161. /package/dist/{_esm → esm}/core/solana/generated/instructions/cancelOrder.js.map +0 -0
  162. /package/dist/{_esm → esm}/core/solana/generated/instructions/claimTokens.js +0 -0
  163. /package/dist/{_esm → esm}/core/solana/generated/instructions/claimTokens.js.map +0 -0
  164. /package/dist/{_esm → esm}/core/solana/generated/instructions/collectProtocolFees.js +0 -0
  165. /package/dist/{_esm → esm}/core/solana/generated/instructions/collectProtocolFees.js.map +0 -0
  166. /package/dist/{_esm → esm}/core/solana/generated/instructions/createGuard.js +0 -0
  167. /package/dist/{_esm → esm}/core/solana/generated/instructions/createGuard.js.map +0 -0
  168. /package/dist/{_esm → esm}/core/solana/generated/instructions/createOrder.js +0 -0
  169. /package/dist/{_esm → esm}/core/solana/generated/instructions/createOrder.js.map +0 -0
  170. /package/dist/{_esm → esm}/core/solana/generated/instructions/index.js +0 -0
  171. /package/dist/{_esm → esm}/core/solana/generated/instructions/index.js.map +0 -0
  172. /package/dist/{_esm → esm}/core/solana/generated/instructions/initialize.js +0 -0
  173. /package/dist/{_esm → esm}/core/solana/generated/instructions/initialize.js.map +0 -0
  174. /package/dist/{_esm → esm}/core/solana/generated/instructions/preStartOrderExecution.js +0 -0
  175. /package/dist/{_esm → esm}/core/solana/generated/instructions/preStartOrderExecution.js.map +0 -0
  176. /package/dist/{_esm → esm}/core/solana/generated/instructions/setAdmin.js +0 -0
  177. /package/dist/{_esm → esm}/core/solana/generated/instructions/setAdmin.js.map +0 -0
  178. /package/dist/{_esm → esm}/core/solana/generated/instructions/setAuctioneerPubKey.js +0 -0
  179. /package/dist/{_esm → esm}/core/solana/generated/instructions/setAuctioneerPubKey.js.map +0 -0
  180. /package/dist/{_esm → esm}/core/solana/generated/instructions/startOrderExecution.js +0 -0
  181. /package/dist/{_esm → esm}/core/solana/generated/instructions/startOrderExecution.js.map +0 -0
  182. /package/dist/{_esm → esm}/core/solana/generated/instructions/startOrderExecutionAfterSwap.js +0 -0
  183. /package/dist/{_esm → esm}/core/solana/generated/instructions/startOrderExecutionAfterSwap.js.map +0 -0
  184. /package/dist/{_esm → esm}/core/solana/generated/programs/index.js +0 -0
  185. /package/dist/{_esm → esm}/core/solana/generated/programs/index.js.map +0 -0
  186. /package/dist/{_esm → esm}/core/solana/generated/programs/sourceChainGuard.js +0 -0
  187. /package/dist/{_esm → esm}/core/solana/generated/programs/sourceChainGuard.js.map +0 -0
  188. /package/dist/{_esm → esm}/core/solana/generated/shared/index.js +0 -0
  189. /package/dist/{_esm → esm}/core/solana/generated/shared/index.js.map +0 -0
  190. /package/dist/{_esm → esm}/core/solana/generated/types/adminUpdated.js +0 -0
  191. /package/dist/{_esm → esm}/core/solana/generated/types/adminUpdated.js.map +0 -0
  192. /package/dist/{_esm → esm}/core/solana/generated/types/auctioneerPubkeyUpdated.js +0 -0
  193. /package/dist/{_esm → esm}/core/solana/generated/types/auctioneerPubkeyUpdated.js.map +0 -0
  194. /package/dist/{_esm → esm}/core/solana/generated/types/executionStarted.js +0 -0
  195. /package/dist/{_esm → esm}/core/solana/generated/types/executionStarted.js.map +0 -0
  196. /package/dist/{_esm → esm}/core/solana/generated/types/guardCreated.js +0 -0
  197. /package/dist/{_esm → esm}/core/solana/generated/types/guardCreated.js.map +0 -0
  198. /package/dist/{_esm → esm}/core/solana/generated/types/index.js +0 -0
  199. /package/dist/{_esm → esm}/core/solana/generated/types/index.js.map +0 -0
  200. /package/dist/{_esm → esm}/core/solana/generated/types/orderCancelled.js +0 -0
  201. /package/dist/{_esm → esm}/core/solana/generated/types/orderCancelled.js.map +0 -0
  202. /package/dist/{_esm → esm}/core/solana/generated/types/orderCreated.js +0 -0
  203. /package/dist/{_esm → esm}/core/solana/generated/types/orderCreated.js.map +0 -0
  204. /package/dist/{_esm → esm}/core/solana/generated/types/orderFulfilled.js +0 -0
  205. /package/dist/{_esm → esm}/core/solana/generated/types/orderFulfilled.js.map +0 -0
  206. /package/dist/{_esm → esm}/core/solana/generated/types/tokenInSwapped.js +0 -0
  207. /package/dist/{_esm → esm}/core/solana/generated/types/tokenInSwapped.js.map +0 -0
  208. /package/dist/{_esm → esm}/core/solana/validator.js +0 -0
  209. /package/dist/{_esm → esm}/core/solana/validator.js.map +0 -0
  210. /package/dist/{_esm → esm}/core/sui/client.js +0 -0
  211. /package/dist/{_esm → esm}/core/sui/client.js.map +0 -0
  212. /package/dist/{_esm → esm}/core/sui/validator.js +0 -0
  213. /package/dist/{_esm → esm}/core/sui/validator.js.map +0 -0
  214. /package/dist/{_esm → esm}/types/intent.js +0 -0
  215. /package/dist/{_esm → esm}/types/intent.js.map +0 -0
  216. /package/dist/{_esm → esm}/utils/base-validator.js +0 -0
  217. /package/dist/{_esm → esm}/utils/base-validator.js.map +0 -0
  218. /package/dist/{_esm → esm}/utils/logger.js +0 -0
  219. /package/dist/{_esm → esm}/utils/logger.js.map +0 -0
  220. /package/dist/{_esm → esm}/utils/type-utils.js +0 -0
  221. /package/dist/{_esm → esm}/utils/type-utils.js.map +0 -0
  222. /package/dist/{_types → types}/config.d.ts +0 -0
  223. /package/dist/{_types → types}/config.d.ts.map +0 -0
  224. /package/dist/{_types → types}/core/evm/abi/erc20.d.ts +0 -0
  225. /package/dist/{_types → types}/core/evm/abi/erc20.d.ts.map +0 -0
  226. /package/dist/{_types → types}/core/evm/permit2.d.ts +0 -0
  227. /package/dist/{_types → types}/core/evm/permit2.d.ts.map +0 -0
  228. /package/dist/{_types → types}/core/evm/validator.d.ts +0 -0
  229. /package/dist/{_types → types}/core/evm/validator.d.ts.map +0 -0
  230. /package/dist/{_types → types}/core/order.d.ts +0 -0
  231. /package/dist/{_types → types}/core/order.d.ts.map +0 -0
  232. /package/dist/{_types → types}/core/solana/client.d.ts +0 -0
  233. /package/dist/{_types → types}/core/solana/client.d.ts.map +0 -0
  234. /package/dist/{_types → types}/core/solana/generated/accounts/adminSingleton.d.ts +0 -0
  235. /package/dist/{_types → types}/core/solana/generated/accounts/adminSingleton.d.ts.map +0 -0
  236. /package/dist/{_types → types}/core/solana/generated/accounts/guard.d.ts +0 -0
  237. /package/dist/{_types → types}/core/solana/generated/accounts/guard.d.ts.map +0 -0
  238. /package/dist/{_types → types}/core/solana/generated/accounts/index.d.ts +0 -0
  239. /package/dist/{_types → types}/core/solana/generated/accounts/index.d.ts.map +0 -0
  240. /package/dist/{_types → types}/core/solana/generated/accounts/order.d.ts +0 -0
  241. /package/dist/{_types → types}/core/solana/generated/accounts/order.d.ts.map +0 -0
  242. /package/dist/{_types → types}/core/solana/generated/errors/index.d.ts +0 -0
  243. /package/dist/{_types → types}/core/solana/generated/errors/index.d.ts.map +0 -0
  244. /package/dist/{_types → types}/core/solana/generated/errors/sourceChainGuard.d.ts +0 -0
  245. /package/dist/{_types → types}/core/solana/generated/errors/sourceChainGuard.d.ts.map +0 -0
  246. /package/dist/{_types → types}/core/solana/generated/index.d.ts +0 -0
  247. /package/dist/{_types → types}/core/solana/generated/index.d.ts.map +0 -0
  248. /package/dist/{_types → types}/core/solana/generated/instructions/cancelOrder.d.ts +0 -0
  249. /package/dist/{_types → types}/core/solana/generated/instructions/cancelOrder.d.ts.map +0 -0
  250. /package/dist/{_types → types}/core/solana/generated/instructions/claimTokens.d.ts +0 -0
  251. /package/dist/{_types → types}/core/solana/generated/instructions/claimTokens.d.ts.map +0 -0
  252. /package/dist/{_types → types}/core/solana/generated/instructions/collectProtocolFees.d.ts +0 -0
  253. /package/dist/{_types → types}/core/solana/generated/instructions/collectProtocolFees.d.ts.map +0 -0
  254. /package/dist/{_types → types}/core/solana/generated/instructions/createGuard.d.ts +0 -0
  255. /package/dist/{_types → types}/core/solana/generated/instructions/createGuard.d.ts.map +0 -0
  256. /package/dist/{_types → types}/core/solana/generated/instructions/createOrder.d.ts +0 -0
  257. /package/dist/{_types → types}/core/solana/generated/instructions/createOrder.d.ts.map +0 -0
  258. /package/dist/{_types → types}/core/solana/generated/instructions/index.d.ts +0 -0
  259. /package/dist/{_types → types}/core/solana/generated/instructions/index.d.ts.map +0 -0
  260. /package/dist/{_types → types}/core/solana/generated/instructions/initialize.d.ts +0 -0
  261. /package/dist/{_types → types}/core/solana/generated/instructions/initialize.d.ts.map +0 -0
  262. /package/dist/{_types → types}/core/solana/generated/instructions/preStartOrderExecution.d.ts +0 -0
  263. /package/dist/{_types → types}/core/solana/generated/instructions/preStartOrderExecution.d.ts.map +0 -0
  264. /package/dist/{_types → types}/core/solana/generated/instructions/setAdmin.d.ts +0 -0
  265. /package/dist/{_types → types}/core/solana/generated/instructions/setAdmin.d.ts.map +0 -0
  266. /package/dist/{_types → types}/core/solana/generated/instructions/setAuctioneerPubKey.d.ts +0 -0
  267. /package/dist/{_types → types}/core/solana/generated/instructions/setAuctioneerPubKey.d.ts.map +0 -0
  268. /package/dist/{_types → types}/core/solana/generated/instructions/startOrderExecution.d.ts +0 -0
  269. /package/dist/{_types → types}/core/solana/generated/instructions/startOrderExecution.d.ts.map +0 -0
  270. /package/dist/{_types → types}/core/solana/generated/instructions/startOrderExecutionAfterSwap.d.ts +0 -0
  271. /package/dist/{_types → types}/core/solana/generated/instructions/startOrderExecutionAfterSwap.d.ts.map +0 -0
  272. /package/dist/{_types → types}/core/solana/generated/programs/index.d.ts +0 -0
  273. /package/dist/{_types → types}/core/solana/generated/programs/index.d.ts.map +0 -0
  274. /package/dist/{_types → types}/core/solana/generated/programs/sourceChainGuard.d.ts +0 -0
  275. /package/dist/{_types → types}/core/solana/generated/programs/sourceChainGuard.d.ts.map +0 -0
  276. /package/dist/{_types → types}/core/solana/generated/shared/index.d.ts +0 -0
  277. /package/dist/{_types → types}/core/solana/generated/shared/index.d.ts.map +0 -0
  278. /package/dist/{_types → types}/core/solana/generated/types/adminUpdated.d.ts +0 -0
  279. /package/dist/{_types → types}/core/solana/generated/types/adminUpdated.d.ts.map +0 -0
  280. /package/dist/{_types → types}/core/solana/generated/types/auctioneerPubkeyUpdated.d.ts +0 -0
  281. /package/dist/{_types → types}/core/solana/generated/types/auctioneerPubkeyUpdated.d.ts.map +0 -0
  282. /package/dist/{_types → types}/core/solana/generated/types/executionStarted.d.ts +0 -0
  283. /package/dist/{_types → types}/core/solana/generated/types/executionStarted.d.ts.map +0 -0
  284. /package/dist/{_types → types}/core/solana/generated/types/guardCreated.d.ts +0 -0
  285. /package/dist/{_types → types}/core/solana/generated/types/guardCreated.d.ts.map +0 -0
  286. /package/dist/{_types → types}/core/solana/generated/types/index.d.ts +0 -0
  287. /package/dist/{_types → types}/core/solana/generated/types/index.d.ts.map +0 -0
  288. /package/dist/{_types → types}/core/solana/generated/types/orderCancelled.d.ts +0 -0
  289. /package/dist/{_types → types}/core/solana/generated/types/orderCancelled.d.ts.map +0 -0
  290. /package/dist/{_types → types}/core/solana/generated/types/orderCreated.d.ts +0 -0
  291. /package/dist/{_types → types}/core/solana/generated/types/orderCreated.d.ts.map +0 -0
  292. /package/dist/{_types → types}/core/solana/generated/types/orderFulfilled.d.ts +0 -0
  293. /package/dist/{_types → types}/core/solana/generated/types/orderFulfilled.d.ts.map +0 -0
  294. /package/dist/{_types → types}/core/solana/generated/types/tokenInSwapped.d.ts +0 -0
  295. /package/dist/{_types → types}/core/solana/generated/types/tokenInSwapped.d.ts.map +0 -0
  296. /package/dist/{_types → types}/core/solana/validator.d.ts +0 -0
  297. /package/dist/{_types → types}/core/solana/validator.d.ts.map +0 -0
  298. /package/dist/{_types → types}/core/sui/client.d.ts +0 -0
  299. /package/dist/{_types → types}/core/sui/client.d.ts.map +0 -0
  300. /package/dist/{_types → types}/core/sui/validator.d.ts +0 -0
  301. /package/dist/{_types → types}/core/sui/validator.d.ts.map +0 -0
  302. /package/dist/{_types → types}/utils/base-validator.d.ts +0 -0
  303. /package/dist/{_types → types}/utils/base-validator.d.ts.map +0 -0
  304. /package/dist/{_types → types}/utils/logger.d.ts +0 -0
  305. /package/dist/{_types → types}/utils/logger.d.ts.map +0 -0
  306. /package/dist/{_types → types}/utils/order-validator.d.ts +0 -0
  307. /package/dist/{_types → types}/utils/order-validator.d.ts.map +0 -0
  308. /package/dist/{_types → types}/utils/type-utils.d.ts +0 -0
  309. /package/dist/{_types → types}/utils/type-utils.d.ts.map +0 -0
package/src/core/sdk.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { chainIdToChainTypeMap } from '../chains.js';
2
2
  import { AUCTIONEER_URL } from '../constants.js';
3
3
  import { NetworkError } from '../errors/index.js';
4
+ import type { ApiResponse } from '../types/api.js';
4
5
  import type { CreateOrderParams, PreparedOrder, UserIntentRequest } from '../types/intent.js';
6
+ import { calculateAmounts } from '../utils/defillama.js';
5
7
  import { Parsers } from '../utils/parsers.js';
6
8
  import { Order } from './order.js';
7
9
 
@@ -21,6 +23,8 @@ export abstract class BaseSDK {
21
23
  */
22
24
  public abstract getUserAddress(): Promise<string>;
23
25
 
26
+ protected abstract cancelOrderInternal(orderId: string): Promise<string>;
27
+
24
28
  /**
25
29
  * Prepares an order for submission with chain-specific logic
26
30
  *
@@ -52,24 +56,52 @@ export abstract class BaseSDK {
52
56
  public async createOrder(params: CreateOrderParams): Promise<PreparedOrder> {
53
57
  const userAddress = await this.getUserAddress();
54
58
 
59
+ let minStablecoinAmount: bigint;
60
+ let destinationTokenMinAmount: bigint;
61
+
62
+ if (!params.minStablecoinAmount || !params.destinationTokenMinAmount) {
63
+ // Calculate missing values using DefiLlama
64
+ const { amountOut: calculatedAmountOut, minStablecoinsAmount: calculatedMinStablecoins } = await calculateAmounts(
65
+ {
66
+ srcChainId: params.sourceChainId,
67
+ tokenIn: params.sourceTokenAddress,
68
+ amountIn: params.sourceTokenAmount,
69
+ destChainId: params.destinationChainId,
70
+ tokenOut: params.destinationTokenAddress,
71
+ },
72
+ );
73
+
74
+ // Use provided values if available, otherwise use calculated ones
75
+ minStablecoinAmount = params.minStablecoinAmount ?? calculatedMinStablecoins;
76
+ destinationTokenMinAmount = params.destinationTokenMinAmount ?? calculatedAmountOut;
77
+ } else {
78
+ // Both values provided, use them directly
79
+ minStablecoinAmount = params.minStablecoinAmount;
80
+ destinationTokenMinAmount = params.destinationTokenMinAmount;
81
+ }
82
+
55
83
  // Order is validated upon creation
56
84
  const order = await Order.create({
57
85
  user: userAddress,
58
86
  sourceChainId: params.sourceChainId,
59
87
  sourceTokenAddress: params.sourceTokenAddress,
60
88
  sourceTokenAmount: params.sourceTokenAmount,
61
- minStablecoinAmount: params.minStablecoinAmount,
89
+ minStablecoinAmount: minStablecoinAmount,
62
90
  deadline: params.deadline,
63
91
  destinationAddress: params.destinationAddress,
64
92
  destinationChainId: params.destinationChainId,
65
93
  destinationTokenAddress: params.destinationTokenAddress,
66
- destinationTokenMinAmount: params.destinationTokenMinAmount,
94
+ destinationTokenMinAmount: destinationTokenMinAmount,
67
95
  extraTransfers: params.extraTransfers,
68
96
  });
69
97
 
70
98
  return this.prepareOrder(order);
71
99
  }
72
100
 
101
+ public async cancelOrder(orderId: string): Promise<string> {
102
+ return this.cancelOrderInternal(orderId);
103
+ }
104
+
73
105
  /**
74
106
  * Creates an order and sends it to the auctioneer in a single call
75
107
  *
@@ -81,9 +113,9 @@ export abstract class BaseSDK {
81
113
  * @throws {OrderCreationError} If order creation fails
82
114
  * @throws {NetworkError} If order submission fails
83
115
  */
84
- public async createAndSendOrder(params: CreateOrderParams): Promise<Response> {
116
+ public async createAndSendOrder(params: CreateOrderParams): Promise<ApiResponse> {
85
117
  const preparedOrder = await this.createOrder(params);
86
- return this.sendOrder(preparedOrder);
118
+ return BaseSDK.sendOrder(preparedOrder);
87
119
  }
88
120
 
89
121
  /**
@@ -98,7 +130,7 @@ export abstract class BaseSDK {
98
130
  * @returns User intent request object ready for submission to the auctioneer
99
131
  * @throws {BaseError} If conversion fails
100
132
  */
101
- private getUserIntentRequest(preparedOrder: PreparedOrder): UserIntentRequest {
133
+ public static getUserIntentRequest(preparedOrder: PreparedOrder): UserIntentRequest {
102
134
  const sourceChain = preparedOrder.order.sourceChainId;
103
135
  const sourceChainType = chainIdToChainTypeMap[sourceChain];
104
136
  const executionDetails = preparedOrder.order.getExecutionDetails();
@@ -125,8 +157,8 @@ export abstract class BaseSDK {
125
157
  * @returns Promise resolving to the specific-chain tx hash
126
158
  * @throws {NetworkError} If the network request fails or returns an error
127
159
  */
128
- public async sendOrder(preparedOrder: PreparedOrder): Promise<Response> {
129
- const intentRequest = this.getUserIntentRequest(preparedOrder);
160
+ public static async sendOrder(preparedOrder: PreparedOrder): Promise<ApiResponse> {
161
+ const intentRequest = BaseSDK.getUserIntentRequest(preparedOrder);
130
162
  const body = JSON.stringify(intentRequest, Parsers.bigIntReplacer);
131
163
 
132
164
  const url = `${AUCTIONEER_URL}/user_intent`;
@@ -139,7 +171,7 @@ export abstract class BaseSDK {
139
171
  });
140
172
 
141
173
  if (!response.ok) {
142
- const errorJson = await response.json();
174
+ const errorJson: ApiResponse = await response.json();
143
175
 
144
176
  const extraErrorData = errorJson.extra_error_data;
145
177
  throw new NetworkError(`Server error`, {
@@ -149,6 +181,6 @@ export abstract class BaseSDK {
149
181
  });
150
182
  }
151
183
 
152
- return response;
184
+ return response.json();
153
185
  }
154
186
  }
@@ -21,6 +21,9 @@ import { NATIVE_SOLANA_TOKEN_ADDRESS, SRC_CHAIN_GUARD, WRAPPED_SOL_MINT_ADDRESS
21
21
  import type { Order } from '../order.js';
22
22
  import { getDefaultSolanaRPC } from './client.js';
23
23
  import { getCreateOrderInstruction } from './generated/index.js';
24
+ import type { ApiResponse } from '../../types/api.js';
25
+ import type { PreparedOrder } from '../../types/intent.js';
26
+ import { BaseSDK } from '../sdk.js';
24
27
 
25
28
  /**
26
29
  * Generates Solana order instructions for creating an order
@@ -129,3 +132,20 @@ export async function getSolanaOrderInstructions(order: Order): Promise<{
129
132
  orderKeyPair: orderSigner,
130
133
  };
131
134
  }
135
+
136
+ export async function sendSolanaRequest({
137
+ order,
138
+ orderPubkey,
139
+ }: {
140
+ order: Order;
141
+ orderPubkey: string;
142
+ }): Promise<ApiResponse> {
143
+ const preparedOrder: PreparedOrder = {
144
+ order,
145
+ preparedData: {
146
+ orderPubkey,
147
+ },
148
+ };
149
+
150
+ return BaseSDK.sendOrder(preparedOrder);
151
+ }
@@ -1,4 +1,5 @@
1
1
  import {
2
+ address,
2
3
  appendTransactionMessageInstructions,
3
4
  compileTransaction,
4
5
  createKeyPairFromBytes,
@@ -18,6 +19,7 @@ import { Order } from '../order.js';
18
19
  import { BaseSDK } from '../sdk.js';
19
20
  import { createSolanaClient, type SolanaClient } from './client.js';
20
21
  import { getSolanaOrderInstructions } from './order-instructions.js';
22
+ import { fetchMaybeOrder } from './generated/index.js';
21
23
 
22
24
  /**
23
25
  * Solana-specific SDK implementation
@@ -57,6 +59,18 @@ export class SolanaSDK extends BaseSDK {
57
59
  return signer.address;
58
60
  }
59
61
 
62
+ protected override async cancelOrderInternal(orderId: string): Promise<string> {
63
+ const rpc = this.client.rpc;
64
+ const orderAddress = address(orderId);
65
+ const orderData = await fetchMaybeOrder(rpc, orderAddress);
66
+
67
+ if (!orderData) {
68
+ throw new Error('Order not found');
69
+ }
70
+
71
+ throw new Error('Method not implemented.');
72
+ }
73
+
60
74
  /**
61
75
  * Creates a CryptoKeyPair from the user's private key
62
76
  *
@@ -11,6 +11,9 @@ import {
11
11
  import { ValidationError } from '../../errors/index.js';
12
12
  import type { Order } from '../order.js';
13
13
  import { createSuiClient } from './client.js';
14
+ import { BaseSDK } from '../sdk.js';
15
+ import type { ApiResponse } from '../../types/api.js';
16
+ import type { PreparedOrder } from '../../types/intent.js';
14
17
 
15
18
  /**
16
19
  * Generates Sui order transaction for creating an order
@@ -76,3 +79,20 @@ export async function getSuiOrderTransaction(order: Order): Promise<Transaction>
76
79
 
77
80
  return tx;
78
81
  }
82
+
83
+ export async function sendSuiRequest({
84
+ order,
85
+ transactionDigest,
86
+ }: {
87
+ order: Order;
88
+ transactionDigest: string;
89
+ }): Promise<ApiResponse> {
90
+ const preparedOrder: PreparedOrder = {
91
+ order,
92
+ preparedData: {
93
+ transactionHash: transactionDigest,
94
+ },
95
+ };
96
+
97
+ return BaseSDK.sendOrder(preparedOrder);
98
+ }
@@ -17,6 +17,10 @@ import { getSuiOrderTransaction } from './order-transaction.js';
17
17
  * Supports cross-chain swaps from Sui to other supported chains.
18
18
  */
19
19
  export class SuiSDK extends BaseSDK {
20
+ protected override cancelOrderInternal(): Promise<string> {
21
+ throw new Error('Method not implemented.');
22
+ }
23
+
20
24
  /** Configuration for Sui connection and authentication */
21
25
  private readonly config: SuiConfig;
22
26
  /** Client for Sui RPC interactions and transaction handling */
@@ -83,6 +83,13 @@ export class InsufficientBalanceError extends BaseError {
83
83
  }
84
84
  }
85
85
 
86
+ export class CalculateAmountError extends BaseError {
87
+ constructor(message: string, cause?: unknown) {
88
+ super(message, cause);
89
+ Object.setPrototypeOf(this, CalculateAmountError.prototype);
90
+ }
91
+ }
92
+
86
93
  export class InsufficientAllowanceError extends BaseError {
87
94
  constructor(message: string, cause?: unknown) {
88
95
  super(message, cause);
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
- export type { ChainID, ChainType } from './chains.js';
2
- export { SupportedChains } from './chains.js';
1
+ export { ChainID, ChainType, SupportedChains } from './chains.js';
2
+ export type { SupportedEvmChain } from './chains.js';
3
3
 
4
4
  export type { EVMConfig, SolanaConfig, SuiConfig } from './config.js';
5
5
  export { EVMSDK } from './core/evm/sdk.js';
@@ -7,4 +7,15 @@ export { Order } from './core/order.js';
7
7
  export { SolanaSDK } from './core/solana/sdk.js';
8
8
  export { SuiSDK } from './core/sui/sdk.js';
9
9
  export { ValidationError } from './errors/index.js';
10
+ export {
11
+ calculateAmounts,
12
+ chainIdToDefiLlamaChainMap,
13
+ createDefiLlamaCoinKey,
14
+ getCoinFromResponse,
15
+ getTokensData,
16
+ } from './utils/defillama.js';
17
+ export type { DefiLlamaCoinData, DefiLlamaTokensResponse } from './utils/defillama.js';
10
18
  export type { CreateOrderParams } from './types/intent.js';
19
+ export { getEvmOrderTypedData, sendEvmRequest } from './core/evm/order-signature.js';
20
+ export { getSolanaOrderInstructions, sendSolanaRequest } from './core/solana/order-instructions.js';
21
+ export { getSuiOrderTransaction, sendSuiRequest } from './core/sui/order-transaction.js';
@@ -0,0 +1,9 @@
1
+ export type ApiResponse = {
2
+ success: boolean;
3
+ code: number;
4
+
5
+ data?: unknown;
6
+
7
+ error?: unknown;
8
+ extra_error_data?: unknown;
9
+ };
@@ -18,12 +18,12 @@ export type CreateOrderParams = {
18
18
  /** Token address on the destination chain to receive */
19
19
  destinationTokenAddress: string;
20
20
  /** Minimum amount of destination tokens to receive, in smallest units */
21
- destinationTokenMinAmount: bigint;
21
+ destinationTokenMinAmount?: bigint;
22
22
  /** Recipient wallet address on the destination chain */
23
23
  destinationAddress: string;
24
24
 
25
25
  /** Minimum amount of stablecoins in the intermediate swap, in smallest units */
26
- minStablecoinAmount: bigint;
26
+ minStablecoinAmount?: bigint;
27
27
  /** Timestamp (in seconds) after which the order expires */
28
28
  deadline: number;
29
29
 
@@ -0,0 +1,74 @@
1
+ export enum OrderStatus {
2
+ // In auction stage, waiting for bids.
3
+ Auction = 'Auction',
4
+ // No bids were received for the order. Is set as limit order.
5
+ NoBids = 'NoBids',
6
+ // The order got a winner bid and the solver is going to execute it.
7
+ Executing = 'Executing',
8
+ // The order was correctly executed.
9
+ Fulfilled = 'Fulfilled',
10
+ // The order was cancelled before execution.
11
+ Cancelled = 'Cancelled',
12
+ // The order was not fulfilled before its deadline.
13
+ Outdated = 'Outdated',
14
+ }
15
+
16
+ export type UserOrder = {
17
+ // Order ID index
18
+ orderId: string;
19
+ // Order status
20
+ orderStatus: OrderStatus;
21
+
22
+ // User address initiating the intent
23
+ user: string;
24
+ // Destination address for the operation (e.g., recipient address)
25
+ destinationAddress: string;
26
+
27
+ // Source chain identifier (e.g., Ethereum, Solana)
28
+ srcChainId: number;
29
+ // Destination chain identifier
30
+ destChainId: number;
31
+
32
+ // The token being spent in the operation (e.g., "ETH", "BTC")
33
+ tokenIn: string;
34
+ // Token to be received after the operation (e.g., "USDT", "DAI")
35
+ tokenOut: string;
36
+
37
+ // The amount of the input token to be used in the operation
38
+ amountIn: string;
39
+ // The minimum amount of the output token to be received after the operation
40
+ amountOutMin: string;
41
+ // Minimum amount of stablecoins that Tokens IN may be swapped for
42
+ minStablecoinsAmount: string;
43
+ // Amount if stablecoins, that tokens IN were swapped into
44
+ lockedStablecoins: string;
45
+
46
+ // `true` - tokens IN were swapped into stablecoins
47
+ tokensInWereSwappedToStablecoins: false;
48
+
49
+ // `execution_details` JSON String
50
+ executionDetails: string;
51
+ // SHA-256 hash of `execution_details` JSON String (hex format)
52
+ executionDetailsHash: string;
53
+
54
+ // Deadline for the operation, in Unix timestamp format, in seconds
55
+ deadline: number;
56
+ // Order creation time, in Unix timestamp format, in seconds
57
+ orderCreationTime: number;
58
+
59
+ // Requested array of extra transfers with fixed amounts
60
+ extraTransfers?: {
61
+ amount: string;
62
+ receiver: string;
63
+ token: string;
64
+ }[];
65
+
66
+ // Permit2 nonce, user for EVM order
67
+ nonce?: string;
68
+ // Order fulfillment timestamp, in seconds
69
+ orderFulfillmentTimestamp?: number;
70
+ // Transaction hash of order execution
71
+ transactionHash?: string;
72
+ // The output amount
73
+ amountOut?: string;
74
+ };
@@ -0,0 +1,179 @@
1
+ import { ChainID, type SupportedChain } from '../chains.js';
2
+ import {
3
+ isNativeTokenEvmAddress,
4
+ NATIVE_SOLANA_TOKEN_ADDRESS,
5
+ REDUCTION_FACTOR,
6
+ STABLECOIN_DECIMALS,
7
+ WRAPPED_SOL_MINT_ADDRESS,
8
+ } from '../constants.js';
9
+ import { CalculateAmountError } from '../errors/index.js';
10
+ import { Parsers } from './parsers.js';
11
+
12
+ const TOKEN_PRICE_BASE_URL: string = 'https://coins.llama.fi/prices/current/';
13
+
14
+ /**
15
+ * Response structure from DefiLlama API for token prices
16
+ */
17
+ export interface DefiLlamaTokensResponse {
18
+ coins: Record<string, DefiLlamaCoinData>;
19
+ }
20
+
21
+ /**
22
+ * Individual token data from DefiLlama API
23
+ */
24
+ export interface DefiLlamaCoinData {
25
+ /** Number of decimal places for the token */
26
+ decimals: number;
27
+ /** Token symbol (e.g., "ETH", "USDC") */
28
+ symbol: string;
29
+ /** Current price in USD */
30
+ price: number;
31
+ /** Unix timestamp of the price data */
32
+ timestamp: number;
33
+ /** Confidence level of the price data (0-1) */
34
+ confidence: number;
35
+ }
36
+
37
+ /**
38
+ * Maps chain IDs to their corresponding chain types
39
+ * Used to determine which SDK implementation to use for a given chain
40
+ */
41
+ export const chainIdToDefiLlamaChainMap = {
42
+ [ChainID.Arbitrum]: 'arbitrum',
43
+ [ChainID.Base]: 'base',
44
+ [ChainID.Optimism]: 'optimism',
45
+ [ChainID.Solana]: 'solana',
46
+ [ChainID.Sui]: 'sui',
47
+ } as const;
48
+
49
+ /**
50
+ * Creates DefiLlama coin key from chain ID and token address
51
+ * Format: "chainName:tokenAddress"
52
+ */
53
+ export const createDefiLlamaCoinKey = (chainId: ChainID, tokenAddress: string): string => {
54
+ const chainName = chainIdToDefiLlamaChainMap[chainId];
55
+ if (!chainName) {
56
+ throw new CalculateAmountError(`Unsupported chain ID for DefiLlama: ${chainId}`);
57
+ }
58
+
59
+ return `${chainName}:${toDefiLlamaToken(tokenAddress)}`;
60
+ };
61
+
62
+ /**
63
+ * Retrieves token data from DefiLlama response by chain and address
64
+ */
65
+ export const getCoinFromResponse = (
66
+ response: DefiLlamaTokensResponse,
67
+ chainId: ChainID,
68
+ tokenAddress: string,
69
+ ): DefiLlamaCoinData => {
70
+ const key = createDefiLlamaCoinKey(chainId, tokenAddress);
71
+ const coin = response.coins[key];
72
+
73
+ if (!coin) {
74
+ throw new CalculateAmountError(`DefiLlama coin not found for ${key}`);
75
+ }
76
+
77
+ return coin;
78
+ };
79
+
80
+ /**
81
+ * Converts Solana native token address to wrapped SOL mint address
82
+ * DefiLlama uses wrapped SOL mint address for native SOL
83
+ *
84
+ * @param tokenAddress The token address to convert
85
+ * @returns The DefiLlama-compatible token address
86
+ */
87
+ function toDefiLlamaToken(tokenAddress: string): string {
88
+ if (isNativeTokenEvmAddress(tokenAddress)) {
89
+ return '0x0000000000000000000000000000000000000000';
90
+ }
91
+
92
+ if (tokenAddress === NATIVE_SOLANA_TOKEN_ADDRESS) {
93
+ return WRAPPED_SOL_MINT_ADDRESS;
94
+ }
95
+
96
+ return tokenAddress;
97
+ }
98
+
99
+ /**
100
+ * Builds a comma-separated query string for DefiLlama API token requests
101
+ *
102
+ * Converts an array of chain/token pairs into the format expected by DefiLlama's
103
+ * bulk price endpoint: "chain1:token1,chain2:token2,..."
104
+ *
105
+ * @param tokens - Array of [ChainID, token address] tuples to query
106
+ * @returns Comma-separated string of DefiLlama coin keys
107
+ *
108
+ * @throws {CalculateAmountError} When any chain ID is not supported by DefiLlama
109
+ */
110
+ function buildTokensQueryString(tokens: Array<[ChainID, string]>): string {
111
+ return tokens.map(([chainId, tokenAddress]) => createDefiLlamaCoinKey(chainId, tokenAddress)).join(',');
112
+ }
113
+
114
+ /**
115
+ * Fetch tokens data for array of coins
116
+ *
117
+ * @param tokens Array of [ChainID, Token Address] tuples
118
+ * @returns Promise resolving to DefiLlama tokens response
119
+ * @throws {CalculateAmountError} If the request fails or response is invalid
120
+ */
121
+ export async function getTokensData(tokens: Array<[ChainID, string]>): Promise<DefiLlamaTokensResponse> {
122
+ const tokensStr = buildTokensQueryString(tokens);
123
+
124
+ const url = `${TOKEN_PRICE_BASE_URL}${tokensStr}`;
125
+ const response = await fetch(url, {
126
+ method: 'GET',
127
+ headers: {
128
+ 'Content-Type': 'application/json',
129
+ },
130
+ });
131
+
132
+ if (!response.ok) {
133
+ throw new CalculateAmountError(`Failed to fetch token prices: ${response.status} ${response.statusText}`);
134
+ }
135
+
136
+ const data: DefiLlamaTokensResponse = await response.json();
137
+ return data;
138
+ }
139
+ export async function calculateAmounts({
140
+ srcChainId,
141
+ tokenIn,
142
+ amountIn,
143
+ destChainId,
144
+ tokenOut,
145
+ }: {
146
+ srcChainId: SupportedChain;
147
+ tokenIn: string;
148
+ amountIn: bigint;
149
+ destChainId: SupportedChain;
150
+ tokenOut: string;
151
+ }): Promise<{ amountOut: bigint; minStablecoinsAmount: bigint }> {
152
+ // Fetch token data from DefiLlama
153
+ const tokensResponse = await getTokensData([
154
+ [srcChainId, tokenIn],
155
+ [destChainId, tokenOut],
156
+ ]);
157
+
158
+ // Get token data for input token
159
+ const tokenInData = getCoinFromResponse(tokensResponse, srcChainId, tokenIn);
160
+ if (!tokenInData) {
161
+ throw new CalculateAmountError(`Token ${tokenIn} for chain ${srcChainId} not found in DefiLlama response`);
162
+ }
163
+
164
+ // Get token data for output token
165
+ const tokenOutData = getCoinFromResponse(tokensResponse, destChainId, tokenOut);
166
+ if (!tokenOutData) {
167
+ throw new CalculateAmountError(`Token ${tokenOut} for chain ${destChainId} not found in DefiLlama response`);
168
+ }
169
+
170
+ // Calculate 80% of the amount_in value as amount_out_min and min_stablecoins_amount
171
+ const tokenInUsdAmount = Parsers.bigintToFloat(amountIn, tokenInData.decimals) * tokenInData.price;
172
+ const amountInUsdReduced = tokenInUsdAmount * REDUCTION_FACTOR;
173
+ const amountOutReduced = amountInUsdReduced / tokenOutData.price;
174
+
175
+ const amountOut = Parsers.floatToBigint(amountOutReduced, tokenOutData.decimals);
176
+ const minStablecoinsAmount = Parsers.floatToBigint(amountInUsdReduced, STABLECOIN_DECIMALS);
177
+
178
+ return { amountOut, minStablecoinsAmount };
179
+ }
@@ -92,7 +92,7 @@ export class OrderValidator {
92
92
 
93
93
  await sourceValidator.validateSourceChain(order);
94
94
 
95
- this.commonValidator.validateCrossChain(order.sourceChainId, order.destinationChainId);
95
+ // this.commonValidator.validateCrossChain(order.sourceChainId, order.destinationChainId);
96
96
 
97
97
  const destinationValidator = ValidatorFactory.getValidatorForChain(order.destinationChainId);
98
98
 
@@ -1,8 +1,55 @@
1
1
  /* eslint-disable @typescript-eslint/no-namespace */
2
+ import { formatUnits, parseUnits } from 'viem';
3
+ import { CalculateAmountError } from '../errors/index.js';
2
4
 
3
5
  export namespace Parsers {
4
6
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
7
  export function bigIntReplacer(_key: string, value: any): any {
6
8
  return typeof value === 'bigint' ? value.toString() : value;
7
9
  }
10
+
11
+ /**
12
+ * Converts a bigint amount to a floating point USD value
13
+ * @param amount Amount in token's smallest unit
14
+ * @param decimals Number of decimal places for the token
15
+ * @returns USD value as number
16
+ */
17
+ export function bigintToFloat(amount: bigint, decimals: number): number {
18
+ const formatted = formatUnits(amount, decimals);
19
+ const result = parseFloat(formatted);
20
+
21
+ if (!Number.isFinite(result)) {
22
+ throw new CalculateAmountError(`Conversion resulted in invalid number: ${formatted}`);
23
+ }
24
+
25
+ return result;
26
+ }
27
+
28
+ /**
29
+ * Converts a floating point USD value to bigint amount
30
+ * Uses viem's parseUnits for consistency and reliability
31
+ * @param usdValue USD value as number
32
+ * @param decimals Number of decimal places for the token
33
+ * @returns Amount in token's smallest unit
34
+ */
35
+ export function floatToBigint(usdValue: number, decimals: number): bigint {
36
+ if (!Number.isFinite(usdValue) || usdValue < 0) {
37
+ throw new CalculateAmountError(`Invalid USD value: ${usdValue}`);
38
+ }
39
+
40
+ if (decimals < 0 || decimals > 77) {
41
+ throw new CalculateAmountError(`Invalid decimals: ${decimals}`);
42
+ }
43
+
44
+ // Convert to fixed-precision string to avoid floating point issues
45
+ const valueString = usdValue.toFixed(decimals);
46
+
47
+ try {
48
+ return parseUnits(valueString, decimals);
49
+ } catch (error) {
50
+ throw new CalculateAmountError(
51
+ `Failed to convert ${usdValue} to bigint with ${decimals} decimals: ${error instanceof Error ? error.message : 'Unknown error'}`,
52
+ );
53
+ }
54
+ }
8
55
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"chains.js","sourceRoot":"","sources":["../../src/chains.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,CAAN,IAAY,SAIX;AAJD,WAAY,SAAS;IACnB,wBAAW,CAAA;IACX,8BAAiB,CAAA;IACjB,wBAAW,CAAA;AACb,CAAC,EAJW,SAAS,KAAT,SAAS,QAIpB;AAED;;;;GAIG;AACH,MAAM,CAAN,IAAY,OAMX;AAND,WAAY,OAAO;IACjB,iDAAgB,CAAA;IAChB,8CAAa,CAAA;IACb,wCAAW,CAAA;IACX,+CAAgB,CAAA;IAChB,qCAAS,CAAA;AACX,CAAC,EANW,OAAO,KAAP,OAAO,QAMlB;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAU,CAAC;AA8BxH;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAA2B,EAAE,CAAC,eAAe,CAAC,QAAQ,CAAC,KAAe,CAAC,CAAC;AAEvH;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,GAAG;IACjC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,GAAG;IAC7B,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,GAAG;IACjC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,MAAM;IAClC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC,GAAG;CACpB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAiC,MAAM,aAAa,CAAC;AAGrE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,MAAM,CAAC,MAAM,eAAe,GAAuC;IACjE,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,4CAAuD;IAC3E,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,4CAAuD;IAC3E,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,4CAAuD;CACxE,CAAC;AAEF,gFAAgF;AAChF,iFAAiF;AACjF,iFAAiF;AACjF,6EAA6E;AAC7E,+EAA+E;AAC/E,mBAAmB;AACnB,4EAA4E;AAC5E,IAAI;AAEJ,MAAM,CAAC,MAAM,eAAe,GAAgD;IAC1E,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,4CAAuD;IAC3E,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,4CAAuD;IAC3E,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,4CAAuD;IACvE,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,8CAA8C,CAAC;IACzE,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,oEAAoE;CACpF,CAAC;AAEF,mFAAmF;AACnF,MAAM;AACN,mFAAmF;AACnF,mFAAmF;AACnF,+EAA+E;AAC/E,iFAAiF;AACjF,qBAAqB;AACrB,8EAA8E;AAC9E,MAAM;AAEN,MAAM,CAAC,MAAM,2BAA2B,GAAG,OAAO,CAAC,6CAA6C,CAAC,CAAC;AAElG,MAAM,CAAC,MAAM,wBAAwB,GAAG,OAAO,CAAC,6CAA6C,CAAC,CAAC;AAE/F,MAAM,CAAC,MAAM,cAAc,GAAG,oEAAoE,CAAC;AAEnG,0GAA0G;AAE1G,MAAM,CAAC,MAAM,yBAAyB,GACpC,gFAAgF,CAAC;AAEnF,MAAM,CAAC,MAAM,yBAAyB,GACpC,gFAAgF,CAAC;AAEnF;;GAEG;AACH,sFAAsF;AACtF,MAAM,CAAC,MAAM,cAAc,GAAG,uBAAuB,CAAC;AAEtD,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,IAAI,GAAG,GAAG,EAAE,CAAC;AAC1C,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,IAAI,IAAI,GAAG,EAAE,CAAC;AAC5C,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,IAAI,IAAI,GAAG,EAAE,CAAC"}