thirdweb 5.99.2 → 5.100.0-nightly-713ebe0a2d6d8a409e41ce0f0317fc34b1f221bb-20250520000414

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 (201) hide show
  1. package/dist/cjs/bridge/Buy.js +16 -12
  2. package/dist/cjs/bridge/Buy.js.map +1 -1
  3. package/dist/cjs/bridge/Chains.js +2 -2
  4. package/dist/cjs/bridge/Chains.js.map +1 -1
  5. package/dist/cjs/bridge/Routes.js +2 -2
  6. package/dist/cjs/bridge/Routes.js.map +1 -1
  7. package/dist/cjs/bridge/Sell.js +17 -13
  8. package/dist/cjs/bridge/Sell.js.map +1 -1
  9. package/dist/cjs/bridge/Status.js +15 -2
  10. package/dist/cjs/bridge/Status.js.map +1 -1
  11. package/dist/cjs/bridge/Transfer.js +229 -0
  12. package/dist/cjs/bridge/Transfer.js.map +1 -0
  13. package/dist/cjs/bridge/index.js +2 -1
  14. package/dist/cjs/bridge/index.js.map +1 -1
  15. package/dist/cjs/bridge/types/Token.js +3 -0
  16. package/dist/cjs/bridge/types/Token.js.map +1 -0
  17. package/dist/cjs/exports/wallets.js +3 -1
  18. package/dist/cjs/exports/wallets.js.map +1 -1
  19. package/dist/cjs/pay/buyWithCrypto/getQuote.js +159 -53
  20. package/dist/cjs/pay/buyWithCrypto/getQuote.js.map +1 -1
  21. package/dist/cjs/pay/buyWithCrypto/getStatus.js +160 -14
  22. package/dist/cjs/pay/buyWithCrypto/getStatus.js.map +1 -1
  23. package/dist/cjs/pay/buyWithCrypto/getTransfer.js +95 -37
  24. package/dist/cjs/pay/buyWithCrypto/getTransfer.js.map +1 -1
  25. package/dist/cjs/pay/utils/definitions.js +1 -31
  26. package/dist/cjs/pay/utils/definitions.js.map +1 -1
  27. package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js +23 -21
  28. package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  29. package/dist/cjs/react/web/ui/ConnectWallet/TransactionsScreen.js +2 -15
  30. package/dist/cjs/react/web/ui/ConnectWallet/TransactionsScreen.js.map +1 -1
  31. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +1 -1
  32. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
  33. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.js +0 -135
  34. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.js.map +1 -1
  35. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.js +3 -1
  36. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.js.map +1 -1
  37. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/fetchBalancesForWallet.js +1 -1
  38. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/fetchBalancesForWallet.js.map +1 -1
  39. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/pendingSwapTx.js +4 -4
  40. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/pendingSwapTx.js.map +1 -1
  41. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.js +83 -34
  42. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.js.map +1 -1
  43. package/dist/cjs/react/web/ui/TransactionButton/ExecutingScreen.js +2 -2
  44. package/dist/cjs/react/web/ui/TransactionButton/ExecutingScreen.js.map +1 -1
  45. package/dist/cjs/utils/any-evm/zksync/constants.js +1 -0
  46. package/dist/cjs/utils/any-evm/zksync/constants.js.map +1 -1
  47. package/dist/cjs/utils/domains.js +3 -0
  48. package/dist/cjs/utils/domains.js.map +1 -1
  49. package/dist/cjs/version.js +1 -1
  50. package/dist/cjs/version.js.map +1 -1
  51. package/dist/cjs/wallets/injected/mipdStore.js +12 -0
  52. package/dist/cjs/wallets/injected/mipdStore.js.map +1 -1
  53. package/dist/esm/bridge/Buy.js +16 -12
  54. package/dist/esm/bridge/Buy.js.map +1 -1
  55. package/dist/esm/bridge/Chains.js +2 -2
  56. package/dist/esm/bridge/Chains.js.map +1 -1
  57. package/dist/esm/bridge/Routes.js +2 -2
  58. package/dist/esm/bridge/Routes.js.map +1 -1
  59. package/dist/esm/bridge/Sell.js +17 -13
  60. package/dist/esm/bridge/Sell.js.map +1 -1
  61. package/dist/esm/bridge/Status.js +15 -2
  62. package/dist/esm/bridge/Status.js.map +1 -1
  63. package/dist/esm/bridge/Transfer.js +226 -0
  64. package/dist/esm/bridge/Transfer.js.map +1 -0
  65. package/dist/esm/bridge/index.js +1 -0
  66. package/dist/esm/bridge/index.js.map +1 -1
  67. package/dist/esm/bridge/types/Token.js +2 -0
  68. package/dist/esm/bridge/types/Token.js.map +1 -0
  69. package/dist/esm/exports/wallets.js +1 -0
  70. package/dist/esm/exports/wallets.js.map +1 -1
  71. package/dist/esm/pay/buyWithCrypto/getQuote.js +159 -53
  72. package/dist/esm/pay/buyWithCrypto/getQuote.js.map +1 -1
  73. package/dist/esm/pay/buyWithCrypto/getStatus.js +160 -14
  74. package/dist/esm/pay/buyWithCrypto/getStatus.js.map +1 -1
  75. package/dist/esm/pay/buyWithCrypto/getTransfer.js +95 -37
  76. package/dist/esm/pay/buyWithCrypto/getTransfer.js.map +1 -1
  77. package/dist/esm/pay/utils/definitions.js +0 -25
  78. package/dist/esm/pay/utils/definitions.js.map +1 -1
  79. package/dist/esm/react/core/hooks/transaction/useSendTransaction.js +23 -21
  80. package/dist/esm/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  81. package/dist/esm/react/web/ui/ConnectWallet/TransactionsScreen.js +2 -15
  82. package/dist/esm/react/web/ui/ConnectWallet/TransactionsScreen.js.map +1 -1
  83. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +1 -1
  84. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
  85. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.js +1 -134
  86. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.js.map +1 -1
  87. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.js +3 -1
  88. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.js.map +1 -1
  89. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/fetchBalancesForWallet.js +1 -1
  90. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/fetchBalancesForWallet.js.map +1 -1
  91. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/pendingSwapTx.js +1 -1
  92. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/pendingSwapTx.js.map +1 -1
  93. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.js +84 -34
  94. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.js.map +1 -1
  95. package/dist/esm/react/web/ui/TransactionButton/ExecutingScreen.js +2 -2
  96. package/dist/esm/react/web/ui/TransactionButton/ExecutingScreen.js.map +1 -1
  97. package/dist/esm/utils/any-evm/zksync/constants.js +1 -0
  98. package/dist/esm/utils/any-evm/zksync/constants.js.map +1 -1
  99. package/dist/esm/utils/domains.js +3 -0
  100. package/dist/esm/utils/domains.js.map +1 -1
  101. package/dist/esm/version.js +1 -1
  102. package/dist/esm/version.js.map +1 -1
  103. package/dist/esm/wallets/injected/mipdStore.js +11 -0
  104. package/dist/esm/wallets/injected/mipdStore.js.map +1 -1
  105. package/dist/types/bridge/Buy.d.ts +10 -8
  106. package/dist/types/bridge/Buy.d.ts.map +1 -1
  107. package/dist/types/bridge/Sell.d.ts +12 -10
  108. package/dist/types/bridge/Sell.d.ts.map +1 -1
  109. package/dist/types/bridge/Status.d.ts.map +1 -1
  110. package/dist/types/bridge/Transfer.d.ts +199 -0
  111. package/dist/types/bridge/Transfer.d.ts.map +1 -0
  112. package/dist/types/bridge/index.d.ts +1 -0
  113. package/dist/types/bridge/index.d.ts.map +1 -1
  114. package/dist/types/bridge/types/Route.d.ts +3 -17
  115. package/dist/types/bridge/types/Route.d.ts.map +1 -1
  116. package/dist/types/bridge/types/Status.d.ts +15 -0
  117. package/dist/types/bridge/types/Status.d.ts.map +1 -1
  118. package/dist/types/bridge/types/Token.d.ts +10 -0
  119. package/dist/types/bridge/types/Token.d.ts.map +1 -0
  120. package/dist/types/exports/wallets.d.ts +1 -0
  121. package/dist/types/exports/wallets.d.ts.map +1 -1
  122. package/dist/types/pay/buyWithCrypto/commonTypes.d.ts +0 -9
  123. package/dist/types/pay/buyWithCrypto/commonTypes.d.ts.map +1 -1
  124. package/dist/types/pay/buyWithCrypto/getQuote.d.ts.map +1 -1
  125. package/dist/types/pay/buyWithCrypto/getStatus.d.ts +1 -1
  126. package/dist/types/pay/buyWithCrypto/getStatus.d.ts.map +1 -1
  127. package/dist/types/pay/buyWithCrypto/getTransfer.d.ts.map +1 -1
  128. package/dist/types/pay/utils/definitions.d.ts +0 -25
  129. package/dist/types/pay/utils/definitions.d.ts.map +1 -1
  130. package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts.map +1 -1
  131. package/dist/types/react/web/ui/ConnectWallet/TransactionsScreen.d.ts.map +1 -1
  132. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.d.ts +2 -13
  133. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.d.ts.map +1 -1
  134. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.d.ts.map +1 -1
  135. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/pendingSwapTx.d.ts +0 -1
  136. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/pendingSwapTx.d.ts.map +1 -1
  137. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.d.ts +8 -4
  138. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.d.ts.map +1 -1
  139. package/dist/types/react/web/ui/MediaRenderer/MediaRenderer.d.ts +1 -1
  140. package/dist/types/react/web/ui/TransactionButton/ExecutingScreen.d.ts.map +1 -1
  141. package/dist/types/utils/any-evm/zksync/constants.d.ts.map +1 -1
  142. package/dist/types/utils/domains.d.ts +6 -0
  143. package/dist/types/utils/domains.d.ts.map +1 -1
  144. package/dist/types/version.d.ts +1 -1
  145. package/dist/types/version.d.ts.map +1 -1
  146. package/dist/types/wallets/injected/mipdStore.d.ts +7 -0
  147. package/dist/types/wallets/injected/mipdStore.d.ts.map +1 -1
  148. package/package.json +1 -1
  149. package/src/bridge/Buy.ts +18 -12
  150. package/src/bridge/Chains.ts +2 -2
  151. package/src/bridge/Routes.ts +2 -2
  152. package/src/bridge/Sell.ts +19 -13
  153. package/src/bridge/Status.ts +15 -2
  154. package/src/bridge/Transfer.test.ts +76 -0
  155. package/src/bridge/Transfer.ts +270 -0
  156. package/src/bridge/index.ts +1 -0
  157. package/src/bridge/types/Route.ts +3 -17
  158. package/src/bridge/types/Status.ts +15 -1
  159. package/src/bridge/types/Token.ts +10 -0
  160. package/src/exports/wallets.ts +1 -0
  161. package/src/extensions/prebuilts/deploy-modular-core.test.ts +2 -1
  162. package/src/pay/buyWithCrypto/commonTypes.ts +0 -10
  163. package/src/pay/buyWithCrypto/getQuote.ts +210 -100
  164. package/src/pay/buyWithCrypto/getStatus.ts +213 -20
  165. package/src/pay/buyWithCrypto/getTransfer.ts +129 -61
  166. package/src/pay/utils/definitions.ts +0 -34
  167. package/src/react/core/hooks/transaction/useSendTransaction.ts +27 -33
  168. package/src/react/web/ui/ConnectWallet/TransactionsScreen.tsx +29 -35
  169. package/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx +3 -1
  170. package/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.ts +2 -181
  171. package/src/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.tsx +3 -1
  172. package/src/react/web/ui/ConnectWallet/screens/Buy/swap/fetchBalancesForWallet.tsx +1 -1
  173. package/src/react/web/ui/ConnectWallet/screens/Buy/swap/pendingSwapTx.ts +1 -3
  174. package/src/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.ts +118 -63
  175. package/src/react/web/ui/TransactionButton/ExecutingScreen.tsx +0 -2
  176. package/src/utils/any-evm/zksync/constants.ts +1 -0
  177. package/src/utils/domain.test.ts +1 -0
  178. package/src/utils/domains.ts +8 -0
  179. package/src/version.ts +1 -1
  180. package/src/wallets/injected/mipdStore.ts +14 -0
  181. package/dist/cjs/bridge/constants.js +0 -5
  182. package/dist/cjs/bridge/constants.js.map +0 -1
  183. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.js +0 -54
  184. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.js.map +0 -1
  185. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistoryButton.js +0 -52
  186. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistoryButton.js.map +0 -1
  187. package/dist/esm/bridge/constants.js +0 -2
  188. package/dist/esm/bridge/constants.js.map +0 -1
  189. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.js +0 -51
  190. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.js.map +0 -1
  191. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistoryButton.js +0 -48
  192. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistoryButton.js.map +0 -1
  193. package/dist/types/bridge/constants.d.ts +0 -2
  194. package/dist/types/bridge/constants.d.ts.map +0 -1
  195. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.d.ts +0 -10
  196. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.d.ts.map +0 -1
  197. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistoryButton.d.ts +0 -9
  198. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistoryButton.d.ts.map +0 -1
  199. package/src/bridge/constants.ts +0 -1
  200. package/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.tsx +0 -163
  201. package/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistoryButton.tsx +0 -127
@@ -1,7 +1,10 @@
1
+ import { Value } from "ox";
2
+ import * as ox__AbiFunction from "ox/AbiFunction";
3
+ import * as Bridge from "../../bridge/index.js";
1
4
  import { getCachedChain } from "../../chains/utils.js";
2
- import { getClientFetch } from "../../utils/fetch.js";
3
- import { stringify } from "../../utils/json.js";
4
- import { getPayBuyWithCryptoQuoteEndpoint } from "../utils/definitions.js";
5
+ import { NATIVE_TOKEN_ADDRESS } from "../../constants/addresses.js";
6
+ import { getContract } from "../../contract/contract.js";
7
+ import { decimals } from "../../extensions/erc20/read/decimals.js";
5
8
  /**
6
9
  * Get a quote of type [`BuyWithCryptoQuote`](https://portal.thirdweb.com/references/typescript/v5/BuyWithCryptoQuote) to buy any given token with crypto.
7
10
  * This quote contains the information about the swap such as token amounts, processing fees, estimated time etc.
@@ -32,65 +35,168 @@ import { getPayBuyWithCryptoQuoteEndpoint } from "../utils/definitions.js";
32
35
  */
33
36
  export async function getBuyWithCryptoQuote(params) {
34
37
  try {
35
- const clientFetch = getClientFetch(params.client);
36
- const response = await clientFetch(getPayBuyWithCryptoQuoteEndpoint(), {
37
- method: "POST",
38
- headers: {
39
- Accept: "application/json",
40
- "Content-Type": "application/json",
41
- },
42
- body: stringify({
43
- fromAddress: params.fromAddress,
44
- toAddress: params.toAddress,
45
- fromChainId: params.fromChainId.toString(),
46
- fromTokenAddress: params.fromTokenAddress,
47
- toChainId: params.toChainId.toString(),
48
- toTokenAddress: params.toTokenAddress,
49
- fromAmount: params.fromAmount,
50
- toAmount: params.toAmount,
51
- maxSlippageBPS: params.maxSlippageBPS,
52
- intentId: params.intentId,
53
- purchaseData: params.purchaseData,
54
- }),
55
- });
56
- // Assuming the response directly matches the SwapResponse interface
57
- if (!response.ok) {
58
- const errorObj = await response.json();
59
- if (errorObj && "error" in errorObj) {
60
- throw errorObj;
38
+ const quote = await (async () => {
39
+ if (params.toAmount) {
40
+ const destinationTokenContract = getContract({
41
+ address: params.toTokenAddress,
42
+ chain: getCachedChain(params.toChainId),
43
+ client: params.client,
44
+ });
45
+ const tokenDecimals = destinationTokenContract.address.toLowerCase() ===
46
+ NATIVE_TOKEN_ADDRESS
47
+ ? 18
48
+ : await decimals({
49
+ contract: destinationTokenContract,
50
+ });
51
+ const amount = Value.from(params.toAmount, tokenDecimals);
52
+ return Bridge.Buy.prepare({
53
+ sender: params.fromAddress,
54
+ receiver: params.toAddress,
55
+ originChainId: params.fromChainId,
56
+ originTokenAddress: params.fromTokenAddress,
57
+ destinationChainId: params.toChainId,
58
+ destinationTokenAddress: params.toTokenAddress,
59
+ amount: amount,
60
+ purchaseData: params.purchaseData,
61
+ client: params.client,
62
+ });
61
63
  }
62
- throw new Error(`HTTP error! status: ${response.status}`);
63
- }
64
- const data = (await response.json())
65
- .result;
64
+ else if (params.fromAmount) {
65
+ const originTokenContract = getContract({
66
+ address: params.fromTokenAddress,
67
+ chain: getCachedChain(params.fromChainId),
68
+ client: params.client,
69
+ });
70
+ const tokenDecimals = await decimals({
71
+ contract: originTokenContract,
72
+ });
73
+ const amount = Value.from(params.fromAmount, tokenDecimals);
74
+ return Bridge.Sell.prepare({
75
+ sender: params.fromAddress,
76
+ receiver: params.toAddress,
77
+ originChainId: params.fromChainId,
78
+ originTokenAddress: params.fromTokenAddress,
79
+ destinationChainId: params.toChainId,
80
+ destinationTokenAddress: params.toTokenAddress,
81
+ amount: amount,
82
+ purchaseData: params.purchaseData,
83
+ client: params.client,
84
+ });
85
+ }
86
+ throw new Error("Invalid quote request, must provide either `fromAmount` or `toAmount`");
87
+ })();
66
88
  // check if the fromAddress already has approval for the given amount
67
- const approvalData = data.approval;
89
+ const firstStep = quote.steps[0];
90
+ if (!firstStep) {
91
+ throw new Error("This quote is incompatible with getBuyWithCryptoQuote. Please use Bridge.Buy.prepare instead.");
92
+ }
93
+ const approvalTxs = firstStep.transactions.filter((tx) => tx.action === "approval");
94
+ if (approvalTxs.length > 1) {
95
+ throw new Error("This quote is incompatible with getBuyWithCryptoQuote. Please use Bridge.Buy.prepare instead.");
96
+ }
97
+ const approvalTx = approvalTxs[0];
98
+ const txs = firstStep.transactions.filter((tx) => tx.action !== "approval");
99
+ if (txs.length > 1) {
100
+ throw new Error("This quote is incompatible with getBuyWithCryptoQuote. Please use Bridge.Buy.prepare instead.");
101
+ }
102
+ const tx = txs[0];
103
+ if (!tx) {
104
+ throw new Error("This quote is incompatible with getBuyWithCryptoQuote. Please use Bridge.Buy.prepare instead.");
105
+ }
106
+ let approvalData;
107
+ if (approvalTx) {
108
+ const abiFunction = ox__AbiFunction.from([
109
+ "function approve(address spender, uint256 amount)",
110
+ ]);
111
+ const [spender, amount] = ox__AbiFunction.decodeData(abiFunction, approvalTx.data);
112
+ approvalData = {
113
+ chainId: firstStep.originToken.chainId,
114
+ tokenAddress: firstStep.originToken.address,
115
+ spenderAddress: spender,
116
+ amountWei: amount.toString(),
117
+ };
118
+ }
68
119
  const swapRoute = {
69
120
  transactionRequest: {
70
- chain: getCachedChain(data.transactionRequest.chainId),
71
- client: params.client,
72
- data: data.transactionRequest.data,
73
- to: data.transactionRequest.to,
74
- value: BigInt(data.transactionRequest.value),
121
+ ...tx,
75
122
  extraGas: 50000n, // extra gas buffer
76
123
  },
77
124
  approvalData,
78
125
  swapDetails: {
79
- fromAddress: data.fromAddress,
80
- toAddress: data.toAddress,
81
- fromToken: data.fromToken,
82
- toToken: data.toToken,
83
- fromAmount: data.fromAmount,
84
- fromAmountWei: data.fromAmountWei,
85
- toAmountMinWei: data.toAmountMinWei,
86
- toAmountMin: data.toAmountMin,
87
- toAmountWei: data.toAmountWei,
88
- toAmount: data.toAmount,
89
- estimated: data.estimated,
90
- maxSlippageBPS: data.maxSlippageBPS,
126
+ fromAddress: quote.intent.sender,
127
+ toAddress: quote.intent.receiver,
128
+ fromToken: {
129
+ tokenAddress: firstStep.originToken.address,
130
+ chainId: firstStep.originToken.chainId,
131
+ decimals: firstStep.originToken.decimals,
132
+ symbol: firstStep.originToken.symbol,
133
+ name: firstStep.originToken.name,
134
+ priceUSDCents: firstStep.originToken.priceUsd * 100,
135
+ },
136
+ toToken: {
137
+ tokenAddress: firstStep.destinationToken.address,
138
+ chainId: firstStep.destinationToken.chainId,
139
+ decimals: firstStep.destinationToken.decimals,
140
+ symbol: firstStep.destinationToken.symbol,
141
+ name: firstStep.destinationToken.name,
142
+ priceUSDCents: firstStep.destinationToken.priceUsd * 100,
143
+ },
144
+ fromAmount: Value.format(quote.originAmount, firstStep.originToken.decimals).toString(),
145
+ fromAmountWei: quote.originAmount.toString(),
146
+ toAmountMinWei: quote.destinationAmount.toString(),
147
+ toAmountMin: Value.format(quote.destinationAmount, firstStep.destinationToken.decimals).toString(),
148
+ toAmountWei: quote.destinationAmount.toString(),
149
+ toAmount: Value.format(quote.destinationAmount, firstStep.destinationToken.decimals).toString(),
150
+ estimated: {
151
+ fromAmountUSDCents: Number(Value.format(quote.originAmount, firstStep.originToken.decimals)) *
152
+ firstStep.originToken.priceUsd *
153
+ 100,
154
+ toAmountMinUSDCents: Number(Value.format(quote.destinationAmount, firstStep.destinationToken.decimals)) *
155
+ firstStep.destinationToken.priceUsd *
156
+ 100,
157
+ toAmountUSDCents: Number(Value.format(quote.destinationAmount, firstStep.destinationToken.decimals)) *
158
+ firstStep.destinationToken.priceUsd *
159
+ 100,
160
+ slippageBPS: 0,
161
+ feesUSDCents: 0,
162
+ gasCostUSDCents: 0,
163
+ durationSeconds: firstStep.estimatedExecutionTimeMs / 1000,
164
+ },
165
+ maxSlippageBPS: 0,
91
166
  },
92
- paymentTokens: data.paymentTokens,
93
- processingFees: data.processingFees,
167
+ paymentTokens: [
168
+ {
169
+ token: {
170
+ tokenAddress: firstStep.originToken.address,
171
+ chainId: firstStep.originToken.chainId,
172
+ decimals: firstStep.originToken.decimals,
173
+ symbol: firstStep.originToken.symbol,
174
+ name: firstStep.originToken.name,
175
+ priceUSDCents: firstStep.originToken.priceUsd * 100,
176
+ },
177
+ amountWei: quote.originAmount.toString(),
178
+ amount: Value.format(quote.originAmount, firstStep.originToken.decimals).toString(),
179
+ amountUSDCents: Number(Value.format(quote.originAmount, firstStep.originToken.decimals)) *
180
+ firstStep.originToken.priceUsd *
181
+ 100,
182
+ },
183
+ ],
184
+ // TODO (UB): add develope and platform fees in API
185
+ processingFees: [
186
+ {
187
+ token: {
188
+ tokenAddress: firstStep.originToken.address,
189
+ chainId: firstStep.originToken.chainId,
190
+ decimals: firstStep.originToken.decimals,
191
+ symbol: firstStep.originToken.symbol,
192
+ name: firstStep.originToken.name,
193
+ priceUSDCents: firstStep.originToken.priceUsd * 100,
194
+ },
195
+ amountUSDCents: 0,
196
+ amountWei: "0",
197
+ amount: "0",
198
+ },
199
+ ],
94
200
  client: params.client,
95
201
  };
96
202
  return swapRoute;
@@ -1 +1 @@
1
- {"version":3,"file":"getQuote.js","sourceRoot":"","sources":["../../../../src/pay/buyWithCrypto/getQuote.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGvD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,gCAAgC,EAAE,MAAM,yBAAyB,CAAC;AAmL3E;;;;;;;;;;;;;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H,CAAC"}
@@ -1,5 +1,5 @@
1
- import { getClientFetch } from "../../utils/fetch.js";
2
- import { getPayBuyWithCryptoStatusUrl } from "../utils/definitions.js";
1
+ import { status as bridgeStatus } from "../../bridge/index.js";
2
+ import { toTokens } from "../../utils/units.js";
3
3
  /**
4
4
  * Gets the status of a buy with crypto transaction
5
5
  * @param buyWithCryptoTransaction - Object of type [`BuyWithCryptoTransaction`](https://portal.thirdweb.com/references/typescript/v5/BuyWithCryptoTransaction)
@@ -37,7 +37,7 @@ import { getPayBuyWithCryptoStatusUrl } from "../utils/definitions.js";
37
37
  * }});
38
38
  * ```
39
39
  * @returns Object of type [`BuyWithCryptoStatus`](https://portal.thirdweb.com/references/typescript/v5/BuyWithCryptoStatus)
40
- * @deprecated
40
+ * @deprecated use Bridge.status instead
41
41
  * @buyCrypto
42
42
  */
43
43
  export async function getBuyWithCryptoStatus(buyWithCryptoTransaction) {
@@ -45,23 +45,169 @@ export async function getBuyWithCryptoStatus(buyWithCryptoTransaction) {
45
45
  if (!buyWithCryptoTransaction.transactionHash) {
46
46
  throw new Error("Transaction hash is required");
47
47
  }
48
- const queryString = new URLSearchParams({
48
+ const result = await bridgeStatus({
49
49
  transactionHash: buyWithCryptoTransaction.transactionHash,
50
- chainId: buyWithCryptoTransaction.chainId.toString(),
51
- }).toString();
52
- const url = `${getPayBuyWithCryptoStatusUrl()}?${queryString}`;
53
- const response = await getClientFetch(buyWithCryptoTransaction.client)(url);
54
- // Assuming the response directly matches the BuyWithCryptoStatus interface
55
- if (!response.ok) {
56
- const error = await response.text().catch(() => null);
57
- throw new Error(`HTTP error! status: ${response.status} - ${response.statusText}: ${error || "unknown error"}`);
50
+ chainId: buyWithCryptoTransaction.chainId,
51
+ client: buyWithCryptoTransaction.client,
52
+ });
53
+ switch (result.status) {
54
+ case "COMPLETED": {
55
+ const originTransaction = result.transactions?.find((tx) => tx.chainId === buyWithCryptoTransaction.chainId);
56
+ const destinationTransaction = result.transactions?.find((tx) => tx.chainId !== buyWithCryptoTransaction.chainId);
57
+ return toBuyWithCryptoStatus({
58
+ originTransaction,
59
+ destinationTransaction,
60
+ originAmount: result.originAmount,
61
+ destinationAmount: result.destinationAmount,
62
+ originTokenAddress: result.originTokenAddress,
63
+ destinationTokenAddress: result.destinationTokenAddress,
64
+ originChainId: result.originChainId,
65
+ destinationChainId: result.destinationChainId,
66
+ status: result.status,
67
+ sender: result.sender,
68
+ receiver: result.receiver,
69
+ paymentId: result.paymentId,
70
+ originToken: result.originToken,
71
+ destinationToken: result.destinationToken,
72
+ purchaseData: result.purchaseData,
73
+ });
74
+ }
75
+ case "PENDING": {
76
+ return toBuyWithCryptoStatus({
77
+ originAmount: result.originAmount,
78
+ originTokenAddress: result.originTokenAddress,
79
+ destinationTokenAddress: result.destinationTokenAddress,
80
+ originChainId: result.originChainId,
81
+ destinationChainId: result.destinationChainId,
82
+ status: result.status,
83
+ sender: result.sender,
84
+ receiver: result.receiver,
85
+ paymentId: result.paymentId,
86
+ originToken: result.originToken,
87
+ destinationToken: result.destinationToken,
88
+ purchaseData: result.purchaseData,
89
+ });
90
+ }
91
+ case "FAILED": {
92
+ const originTransaction = result.transactions?.find((tx) => tx.chainId === buyWithCryptoTransaction.chainId);
93
+ const destinationTransaction = result.transactions?.find((tx) => tx.chainId !== buyWithCryptoTransaction.chainId);
94
+ return toBuyWithCryptoStatus({
95
+ originTransaction,
96
+ destinationTransaction,
97
+ originAmount: BigInt(0), // TODO: get from API
98
+ originTokenAddress: "", // TODO: get from API
99
+ destinationTokenAddress: "", // TODO: get from API
100
+ originChainId: 0, // TODO: get from API
101
+ destinationChainId: 0, // TODO: get from API
102
+ status: result.status,
103
+ sender: "",
104
+ receiver: "",
105
+ paymentId: "",
106
+ originToken: undefined,
107
+ destinationToken: undefined,
108
+ purchaseData: result.purchaseData,
109
+ });
110
+ }
111
+ default: {
112
+ return {
113
+ status: "NOT_FOUND",
114
+ };
115
+ }
58
116
  }
59
- const data = (await response.json()).result;
60
- return data;
61
117
  }
62
118
  catch (error) {
63
119
  console.error("Fetch error:", error);
64
120
  throw new Error(`Fetch failed: ${error}`);
65
121
  }
66
122
  }
123
+ function toBuyWithCryptoStatus(args) {
124
+ const { originTransaction, destinationTransaction, status, purchaseData, originAmount, destinationAmount, originTokenAddress, destinationTokenAddress, originChainId, destinationChainId, sender, receiver, originToken, destinationToken, } = args;
125
+ return {
126
+ fromAddress: sender,
127
+ toAddress: receiver,
128
+ quote: {
129
+ createdAt: new Date().toISOString(),
130
+ estimated: {
131
+ fromAmountUSDCents: 0,
132
+ toAmountMinUSDCents: 0,
133
+ toAmountUSDCents: 0,
134
+ slippageBPS: 0,
135
+ feesUSDCents: 0,
136
+ gasCostUSDCents: 0,
137
+ durationSeconds: 0,
138
+ },
139
+ fromAmount: originToken
140
+ ? toTokens(originAmount, originToken.decimals).toString()
141
+ : "",
142
+ fromAmountWei: originAmount.toString(),
143
+ toAmount: destinationToken && destinationAmount
144
+ ? toTokens(destinationAmount, destinationToken.decimals).toString()
145
+ : "",
146
+ toAmountWei: destinationAmount ? destinationAmount.toString() : "",
147
+ toAmountMin: destinationToken
148
+ ? toTokens(destinationAmount ?? BigInt(0), destinationToken.decimals).toString()
149
+ : "",
150
+ toAmountMinWei: destinationAmount ? destinationAmount.toString() : "",
151
+ fromToken: {
152
+ tokenAddress: originTokenAddress,
153
+ chainId: originChainId,
154
+ decimals: originToken?.decimals ?? 18,
155
+ name: originToken?.name ?? "",
156
+ symbol: originToken?.symbol ?? "",
157
+ priceUSDCents: 0,
158
+ },
159
+ toToken: {
160
+ tokenAddress: destinationTokenAddress,
161
+ chainId: destinationChainId,
162
+ decimals: destinationToken?.decimals ?? 18,
163
+ name: destinationToken?.name ?? "",
164
+ symbol: destinationToken?.symbol ?? "",
165
+ priceUSDCents: 0,
166
+ },
167
+ },
168
+ swapType: originTransaction?.chainId === destinationTransaction?.chainId
169
+ ? "SAME_CHAIN"
170
+ : "CROSS_CHAIN", // TODO transfer type?
171
+ status: status,
172
+ subStatus: status === "COMPLETED" ? "SUCCESS" : "NONE",
173
+ purchaseData: purchaseData,
174
+ bridge: "STARPORT",
175
+ destination: {
176
+ amount: destinationToken
177
+ ? toTokens(destinationAmount ?? BigInt(0), destinationToken.decimals).toString()
178
+ : "",
179
+ amountWei: destinationAmount?.toString() ?? "",
180
+ token: {
181
+ tokenAddress: destinationTokenAddress,
182
+ chainId: destinationChainId,
183
+ decimals: destinationToken?.decimals ?? 18,
184
+ name: destinationToken?.name ?? "",
185
+ symbol: destinationToken?.symbol ?? "",
186
+ priceUSDCents: 0,
187
+ },
188
+ amountUSDCents: 0,
189
+ completedAt: new Date().toISOString(),
190
+ explorerLink: "",
191
+ transactionHash: destinationTransaction?.transactionHash ?? "",
192
+ },
193
+ source: {
194
+ amount: originToken
195
+ ? toTokens(originAmount, originToken.decimals).toString()
196
+ : "",
197
+ amountWei: originAmount.toString(),
198
+ token: {
199
+ tokenAddress: originTokenAddress,
200
+ chainId: originChainId,
201
+ decimals: originToken?.decimals ?? 18,
202
+ name: originToken?.name ?? "",
203
+ symbol: originToken?.symbol ?? "",
204
+ priceUSDCents: 0,
205
+ },
206
+ amountUSDCents: 0,
207
+ completedAt: new Date().toISOString(),
208
+ explorerLink: "",
209
+ transactionHash: originTransaction?.transactionHash ?? "",
210
+ },
211
+ };
212
+ }
67
213
  //# sourceMappingURL=getStatus.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getStatus.js","sourceRoot":"","sources":["../../../../src/pay/buyWithCrypto/getStatus.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAKtD,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AAkFvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,wBAAkD;IAElD,IAAI,CAAC;QACH,IAAI,CAAC,wBAAwB,CAAC,eAAe,EAAE,CAAC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,EAAE,QAAQ,IAAI,EAAE;gBACrC,IAAI,EAAE,WAAW,EAAE,IAAI,IAAI,EAAE;gBAC7B,MAAM,EAAE,WAAW,EAAE,MAAM,IAAI,EAAE;gBACjC,aAAa,EAAE,CAAC;aACjB;YACD,cAAc,EAAE,CAAC;YACjB,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACrC,YAAY,EAAE,EAAE;YAChB,eAAe,EAAE,iBAAiB,EAAE,eAAe,IAAI,EAAE;SAC1D;KACF,CAAC;AACJ,CAAC"}
@@ -1,7 +1,10 @@
1
+ import { Value } from "ox";
2
+ import * as ox__AbiFunction from "ox/AbiFunction";
3
+ import { Transfer } from "../../bridge/index.js";
1
4
  import { getCachedChain } from "../../chains/utils.js";
2
- import { getClientFetch } from "../../utils/fetch.js";
3
- import { stringify } from "../../utils/json.js";
4
- import { getPayBuyWithCryptoTransferEndpoint } from "../utils/definitions.js";
5
+ import { NATIVE_TOKEN_ADDRESS } from "../../constants/addresses.js";
6
+ import { getContract } from "../../contract/contract.js";
7
+ import { decimals } from "../../extensions/erc20/read/decimals.js";
5
8
  /**
6
9
  * Get a quote of type [`BuyWithCryptoTransfer`](https://portal.thirdweb.com/references/typescript/v5/BuyWithCryptoTransfer) to facilitate a token transfer transaction.
7
10
  * Using this instead of a native transfer allows you to receive status and webhooks about successful or failed payments.
@@ -31,46 +34,101 @@ import { getPayBuyWithCryptoTransferEndpoint } from "../utils/definitions.js";
31
34
  */
32
35
  export async function getBuyWithCryptoTransfer(params) {
33
36
  try {
34
- const clientFetch = getClientFetch(params.client);
35
- const response = await clientFetch(getPayBuyWithCryptoTransferEndpoint(), {
36
- method: "POST",
37
- headers: {
38
- Accept: "application/json",
39
- "Content-Type": "application/json",
40
- },
41
- body: stringify({
42
- fromAddress: params.fromAddress,
43
- toAddress: params.toAddress,
44
- chainId: params.chainId,
45
- tokenAddress: params.tokenAddress,
46
- amount: params.amount,
47
- purchaseData: params.purchaseData,
48
- feePayer: params.feePayer,
49
- }),
37
+ const tokenContract = getContract({
38
+ address: params.tokenAddress,
39
+ chain: getCachedChain(params.chainId),
40
+ client: params.client,
50
41
  });
51
- if (!response.ok) {
52
- const errorObj = await response.json();
53
- if (errorObj && "error" in errorObj) {
54
- throw errorObj;
55
- }
56
- throw new Error(`HTTP error! status: ${response.status}`);
42
+ const tokenDecimals = tokenContract.address.toLowerCase() === NATIVE_TOKEN_ADDRESS
43
+ ? 18
44
+ : await decimals({
45
+ contract: tokenContract,
46
+ });
47
+ const amount = Value.from(params.amount, tokenDecimals);
48
+ const quote = await Transfer.prepare({
49
+ chainId: params.chainId,
50
+ tokenAddress: params.tokenAddress,
51
+ amount,
52
+ sender: params.fromAddress,
53
+ receiver: params.toAddress,
54
+ client: params.client,
55
+ feePayer: params.feePayer,
56
+ });
57
+ const firstStep = quote.steps[0];
58
+ if (!firstStep) {
59
+ throw new Error("This quote is incompatible with getBuyWithCryptoTransfer. Please use Bridge.Transfer.prepare instead.");
60
+ }
61
+ const approvalTxs = firstStep.transactions.filter((tx) => tx.action === "approval");
62
+ if (approvalTxs.length > 1) {
63
+ throw new Error("This quote is incompatible with getBuyWithCryptoTransfer. Please use Bridge.Transfer.prepare instead.");
64
+ }
65
+ const approvalTx = approvalTxs[0];
66
+ let approvalData;
67
+ if (approvalTx) {
68
+ const abiFunction = ox__AbiFunction.from([
69
+ "function approve(address spender, uint256 amount)",
70
+ ]);
71
+ const [spender, amount] = ox__AbiFunction.decodeData(abiFunction, approvalTx.data);
72
+ approvalData = {
73
+ chainId: firstStep.originToken.chainId,
74
+ tokenAddress: firstStep.originToken.address,
75
+ spenderAddress: spender,
76
+ amountWei: amount.toString(),
77
+ };
78
+ }
79
+ const txs = firstStep.transactions.filter((tx) => tx.action !== "approval");
80
+ if (txs.length > 1) {
81
+ throw new Error("This quote is incompatible with getBuyWithCryptoTransfer. Please use Bridge.Transfer.prepare instead.");
82
+ }
83
+ const tx = txs[0];
84
+ if (!tx) {
85
+ throw new Error("This quote is incompatible with getBuyWithCryptoTransfer. Please use Bridge.Transfer.prepare instead.");
57
86
  }
58
- const data = (await response.json()).result;
59
87
  const transfer = {
60
88
  transactionRequest: {
61
- chain: getCachedChain(data.transactionRequest.chainId),
62
- client: params.client,
63
- data: data.transactionRequest.data,
64
- to: data.transactionRequest.to,
65
- value: BigInt(data.transactionRequest.value),
89
+ ...tx,
66
90
  extraGas: 50000n, // extra gas buffer
67
91
  },
68
- approvalData: data.approval,
69
- fromAddress: data.fromAddress,
70
- toAddress: data.toAddress,
71
- paymentToken: data.paymentToken,
72
- processingFee: data.processingFee,
73
- estimatedGasCostUSDCents: data.estimatedGasCostUSDCents,
92
+ approvalData,
93
+ fromAddress: params.fromAddress,
94
+ toAddress: params.toAddress,
95
+ paymentToken: {
96
+ token: {
97
+ tokenAddress: firstStep.originToken.address,
98
+ chainId: firstStep.originToken.chainId,
99
+ decimals: firstStep.originToken.decimals,
100
+ symbol: firstStep.originToken.symbol,
101
+ name: firstStep.originToken.name,
102
+ priceUSDCents: firstStep.originToken.priceUsd * 100,
103
+ },
104
+ amountWei: quote.originAmount.toString(),
105
+ amount: Value.format(quote.originAmount, firstStep.originToken.decimals).toString(),
106
+ amountUSDCents: Number(Value.format(quote.originAmount, firstStep.originToken.decimals)) *
107
+ firstStep.originToken.priceUsd *
108
+ 100,
109
+ },
110
+ processingFee: {
111
+ token: {
112
+ tokenAddress: firstStep.originToken.address,
113
+ chainId: firstStep.originToken.chainId,
114
+ decimals: firstStep.originToken.decimals,
115
+ symbol: firstStep.originToken.symbol,
116
+ name: firstStep.originToken.name,
117
+ priceUSDCents: firstStep.originToken.priceUsd * 100,
118
+ },
119
+ amountWei: params.feePayer === "sender"
120
+ ? (quote.originAmount - quote.destinationAmount).toString()
121
+ : "0",
122
+ amount: params.feePayer === "sender"
123
+ ? Value.format(quote.originAmount - quote.destinationAmount, firstStep.originToken.decimals).toString()
124
+ : "0",
125
+ amountUSDCents: params.feePayer === "sender"
126
+ ? Number(Value.format(quote.originAmount - quote.destinationAmount, firstStep.originToken.decimals)) *
127
+ firstStep.originToken.priceUsd *
128
+ 100
129
+ : 0,
130
+ },
131
+ estimatedGasCostUSDCents: 0,
74
132
  client: params.client,
75
133
  };
76
134
  return transfer;