mppx 0.3.11 → 0.3.13

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 (44) hide show
  1. package/dist/client/Mppx.d.ts +1 -1
  2. package/dist/client/Mppx.d.ts.map +1 -1
  3. package/dist/client/internal/Fetch.d.ts +1 -1
  4. package/dist/client/internal/Fetch.d.ts.map +1 -1
  5. package/dist/client/internal/Fetch.js +76 -11
  6. package/dist/client/internal/Fetch.js.map +1 -1
  7. package/dist/internal/constantTimeEqual.d.ts.map +1 -1
  8. package/dist/internal/constantTimeEqual.js +7 -4
  9. package/dist/internal/constantTimeEqual.js.map +1 -1
  10. package/dist/tempo/client/Charge.d.ts +10 -0
  11. package/dist/tempo/client/Charge.d.ts.map +1 -1
  12. package/dist/tempo/client/Charge.js +23 -9
  13. package/dist/tempo/client/Charge.js.map +1 -1
  14. package/dist/tempo/client/Methods.d.ts +1 -0
  15. package/dist/tempo/client/Methods.d.ts.map +1 -1
  16. package/dist/tempo/internal/auto-swap.d.ts +49 -0
  17. package/dist/tempo/internal/auto-swap.d.ts.map +1 -0
  18. package/dist/tempo/internal/auto-swap.js +89 -0
  19. package/dist/tempo/internal/auto-swap.js.map +1 -0
  20. package/dist/tempo/internal/fee-payer.d.ts +15 -0
  21. package/dist/tempo/internal/fee-payer.d.ts.map +1 -0
  22. package/dist/tempo/internal/fee-payer.js +41 -0
  23. package/dist/tempo/internal/fee-payer.js.map +1 -0
  24. package/dist/tempo/internal/selectors.d.ts +5 -0
  25. package/dist/tempo/internal/selectors.d.ts.map +1 -0
  26. package/dist/tempo/internal/selectors.js +7 -0
  27. package/dist/tempo/internal/selectors.js.map +1 -0
  28. package/dist/tempo/server/Charge.d.ts.map +1 -1
  29. package/dist/tempo/server/Charge.js +8 -6
  30. package/dist/tempo/server/Charge.js.map +1 -1
  31. package/package.json +1 -1
  32. package/src/client/Mppx.test-d.ts +28 -0
  33. package/src/client/Mppx.ts +3 -3
  34. package/src/client/internal/Fetch.test.ts +454 -0
  35. package/src/client/internal/Fetch.ts +89 -14
  36. package/src/internal/constantTimeEqual.ts +6 -4
  37. package/src/tempo/client/Charge.ts +40 -9
  38. package/src/tempo/internal/auto-swap.test.ts +113 -0
  39. package/src/tempo/internal/auto-swap.ts +141 -0
  40. package/src/tempo/internal/fee-payer.test.ts +223 -0
  41. package/src/tempo/internal/fee-payer.ts +53 -0
  42. package/src/tempo/internal/selectors.ts +10 -0
  43. package/src/tempo/server/Charge.test.ts +374 -3
  44. package/src/tempo/server/Charge.ts +9 -18
@@ -1,10 +1,4 @@
1
- import {
2
- decodeFunctionData,
3
- isAddressEqual,
4
- parseEventLogs,
5
- type TransactionReceipt,
6
- toFunctionSelector,
7
- } from 'viem'
1
+ import { decodeFunctionData, isAddressEqual, parseEventLogs, type TransactionReceipt } from 'viem'
8
2
  import {
9
3
  getTransactionReceipt,
10
4
  sendRawTransaction,
@@ -19,18 +13,12 @@ import * as Method from '../../Method.js'
19
13
  import * as Client from '../../viem/Client.js'
20
14
  import * as Account from '../internal/account.js'
21
15
  import * as defaults from '../internal/defaults.js'
16
+ import * as FeePayer from '../internal/fee-payer.js'
17
+ import * as Selectors from '../internal/selectors.js'
22
18
  import { simulateTransaction } from '../internal/simulate.js'
23
19
  import type * as types from '../internal/types.js'
24
20
  import * as Methods from '../Methods.js'
25
21
 
26
- const transferSelector = /*#__PURE__*/ toFunctionSelector(
27
- 'function transfer(address to, uint256 amount)',
28
- )
29
-
30
- const transferWithMemoSelector = /*#__PURE__*/ toFunctionSelector(
31
- 'function transferWithMemo(address to, uint256 amount, bytes32 memo)',
32
- )
33
-
34
22
  /**
35
23
  * Creates a Tempo charge method intent for usage on the server.
36
24
  *
@@ -202,7 +190,7 @@ export function charge<const parameters extends charge.Parameters>(
202
190
  const selector = call.data.slice(0, 10)
203
191
 
204
192
  if (memo) {
205
- if (selector !== transferWithMemoSelector) return false
193
+ if (selector !== Selectors.transferWithMemo) return false
206
194
  try {
207
195
  const { args } = decodeFunctionData({ abi: Abis.tip20, data: call.data })
208
196
  const [to, amount_, memo_] = args as [`0x${string}`, bigint, `0x${string}`]
@@ -216,7 +204,7 @@ export function charge<const parameters extends charge.Parameters>(
216
204
  }
217
205
  }
218
206
 
219
- if (selector === transferSelector) {
207
+ if (selector === Selectors.transfer) {
220
208
  try {
221
209
  const { args } = decodeFunctionData({ abi: Abis.tip20, data: call.data })
222
210
  const [to, amount_] = args as [`0x${string}`, bigint]
@@ -226,7 +214,7 @@ export function charge<const parameters extends charge.Parameters>(
226
214
  }
227
215
  }
228
216
 
229
- if (selector === transferWithMemoSelector) {
217
+ if (selector === Selectors.transferWithMemo) {
230
218
  try {
231
219
  const { args } = decodeFunctionData({ abi: Abis.tip20, data: call.data })
232
220
  const [to, amount_] = args as [`0x${string}`, bigint, `0x${string}`]
@@ -246,6 +234,9 @@ export function charge<const parameters extends charge.Parameters>(
246
234
  recipient,
247
235
  })
248
236
 
237
+ if (feePayer && methodDetails?.feePayer !== false)
238
+ FeePayer.validateCalls(calls, { amount, currency, recipient })
239
+
249
240
  const serializedTransaction_final = await (async () => {
250
241
  if (feePayer && methodDetails?.feePayer !== false) {
251
242
  return signTransaction(client, {