viem 2.56.7 → 2.56.9

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 (297) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +0 -1
  3. package/_cjs/actions/index.js +5 -3
  4. package/_cjs/actions/index.js.map +1 -1
  5. package/_cjs/actions/public/getStorageValues.js +17 -0
  6. package/_cjs/actions/public/getStorageValues.js.map +1 -0
  7. package/_cjs/actions/public/simulateBlocks.js +2 -0
  8. package/_cjs/actions/public/simulateBlocks.js.map +1 -1
  9. package/_cjs/chains/definitions/rabbitChainTestnet.js +24 -0
  10. package/_cjs/chains/definitions/rabbitChainTestnet.js.map +1 -0
  11. package/_cjs/chains/index.js +7 -5
  12. package/_cjs/chains/index.js.map +1 -1
  13. package/_cjs/clients/decorators/public.js +2 -0
  14. package/_cjs/clients/decorators/public.js.map +1 -1
  15. package/_cjs/errors/version.js +1 -1
  16. package/_cjs/index.js.map +1 -1
  17. package/_cjs/tempo/Abis.js +1211 -32
  18. package/_cjs/tempo/Abis.js.map +1 -1
  19. package/_cjs/tempo/Addresses.js +2 -1
  20. package/_cjs/tempo/Addresses.js.map +1 -1
  21. package/_cjs/tempo/Decorator.js +12 -0
  22. package/_cjs/tempo/Decorator.js.map +1 -1
  23. package/_cjs/tempo/Selectors.js +7 -4
  24. package/_cjs/tempo/Selectors.js.map +1 -1
  25. package/_cjs/tempo/actions/index.js +2 -1
  26. package/_cjs/tempo/actions/index.js.map +1 -1
  27. package/_cjs/tempo/actions/propAmm.js +349 -0
  28. package/_cjs/tempo/actions/propAmm.js.map +1 -0
  29. package/_cjs/tokens/definitions/eurc.js +1 -0
  30. package/_cjs/tokens/definitions/eurc.js.map +1 -1
  31. package/_cjs/tokens/definitions/usdc.js +1 -0
  32. package/_cjs/tokens/definitions/usdc.js.map +1 -1
  33. package/_cjs/utils/formatters/formatter.js.map +1 -1
  34. package/_esm/actions/index.js +1 -0
  35. package/_esm/actions/index.js.map +1 -1
  36. package/_esm/actions/public/getStorageValues.js +39 -0
  37. package/_esm/actions/public/getStorageValues.js.map +1 -0
  38. package/_esm/actions/public/simulateBlocks.js +4 -0
  39. package/_esm/actions/public/simulateBlocks.js.map +1 -1
  40. package/_esm/chains/definitions/rabbitChainTestnet.js +21 -0
  41. package/_esm/chains/definitions/rabbitChainTestnet.js.map +1 -0
  42. package/_esm/chains/index.js +1 -0
  43. package/_esm/chains/index.js.map +1 -1
  44. package/_esm/clients/decorators/public.js +2 -0
  45. package/_esm/clients/decorators/public.js.map +1 -1
  46. package/_esm/errors/version.js +1 -1
  47. package/_esm/index.js.map +1 -1
  48. package/_esm/tempo/Abis.js +1214 -34
  49. package/_esm/tempo/Abis.js.map +1 -1
  50. package/_esm/tempo/Addresses.js +2 -0
  51. package/_esm/tempo/Addresses.js.map +1 -1
  52. package/_esm/tempo/Decorator.js +12 -0
  53. package/_esm/tempo/Decorator.js.map +1 -1
  54. package/_esm/tempo/Selectors.js +6 -3
  55. package/_esm/tempo/Selectors.js.map +1 -1
  56. package/_esm/tempo/actions/index.js +1 -0
  57. package/_esm/tempo/actions/index.js.map +1 -1
  58. package/_esm/tempo/actions/propAmm.js +539 -0
  59. package/_esm/tempo/actions/propAmm.js.map +1 -0
  60. package/_esm/tokens/definitions/eurc.js +1 -0
  61. package/_esm/tokens/definitions/eurc.js.map +1 -1
  62. package/_esm/tokens/definitions/usdc.js +1 -0
  63. package/_esm/tokens/definitions/usdc.js.map +1 -1
  64. package/_esm/utils/formatters/formatter.js +1 -0
  65. package/_esm/utils/formatters/formatter.js.map +1 -1
  66. package/_types/actions/index.d.ts +1 -0
  67. package/_types/actions/index.d.ts.map +1 -1
  68. package/_types/actions/public/getStorageValues.d.ts +59 -0
  69. package/_types/actions/public/getStorageValues.d.ts.map +1 -0
  70. package/_types/actions/public/simulateBlocks.d.ts +8 -0
  71. package/_types/actions/public/simulateBlocks.d.ts.map +1 -1
  72. package/_types/celo/chainConfig.d.ts +6 -840
  73. package/_types/celo/chainConfig.d.ts.map +1 -1
  74. package/_types/celo/formatters.d.ts +4 -421
  75. package/_types/celo/formatters.d.ts.map +1 -1
  76. package/_types/chains/definitions/abstract.d.ts +4 -371
  77. package/_types/chains/definitions/abstract.d.ts.map +1 -1
  78. package/_types/chains/definitions/abstractTestnet.d.ts +4 -371
  79. package/_types/chains/definitions/abstractTestnet.d.ts.map +1 -1
  80. package/_types/chains/definitions/ancient8.d.ts +3 -226
  81. package/_types/chains/definitions/ancient8.d.ts.map +1 -1
  82. package/_types/chains/definitions/ancient8Sepolia.d.ts +3 -226
  83. package/_types/chains/definitions/ancient8Sepolia.d.ts.map +1 -1
  84. package/_types/chains/definitions/base.d.ts +6 -452
  85. package/_types/chains/definitions/base.d.ts.map +1 -1
  86. package/_types/chains/definitions/baseGoerli.d.ts +3 -226
  87. package/_types/chains/definitions/baseGoerli.d.ts.map +1 -1
  88. package/_types/chains/definitions/baseSepolia.d.ts +6 -452
  89. package/_types/chains/definitions/baseSepolia.d.ts.map +1 -1
  90. package/_types/chains/definitions/battlechain.d.ts +4 -371
  91. package/_types/chains/definitions/battlechain.d.ts.map +1 -1
  92. package/_types/chains/definitions/battlechainTestnet.d.ts +4 -371
  93. package/_types/chains/definitions/battlechainTestnet.d.ts.map +1 -1
  94. package/_types/chains/definitions/blast.d.ts +3 -226
  95. package/_types/chains/definitions/blast.d.ts.map +1 -1
  96. package/_types/chains/definitions/bob.d.ts +3 -226
  97. package/_types/chains/definitions/bob.d.ts.map +1 -1
  98. package/_types/chains/definitions/bobSepolia.d.ts +3 -226
  99. package/_types/chains/definitions/bobSepolia.d.ts.map +1 -1
  100. package/_types/chains/definitions/celo.d.ts +6 -840
  101. package/_types/chains/definitions/celo.d.ts.map +1 -1
  102. package/_types/chains/definitions/celoAlfajores.d.ts +6 -840
  103. package/_types/chains/definitions/celoAlfajores.d.ts.map +1 -1
  104. package/_types/chains/definitions/celoSepolia.d.ts +6 -840
  105. package/_types/chains/definitions/celoSepolia.d.ts.map +1 -1
  106. package/_types/chains/definitions/codex.d.ts +3 -226
  107. package/_types/chains/definitions/codex.d.ts.map +1 -1
  108. package/_types/chains/definitions/codexTestnet.d.ts +3 -226
  109. package/_types/chains/definitions/codexTestnet.d.ts.map +1 -1
  110. package/_types/chains/definitions/dchain.d.ts +3 -226
  111. package/_types/chains/definitions/dchain.d.ts.map +1 -1
  112. package/_types/chains/definitions/dchainTestnet.d.ts +3 -226
  113. package/_types/chains/definitions/dchainTestnet.d.ts.map +1 -1
  114. package/_types/chains/definitions/elysiumTestnet.d.ts +3 -226
  115. package/_types/chains/definitions/elysiumTestnet.d.ts.map +1 -1
  116. package/_types/chains/definitions/fraxtal.d.ts +3 -226
  117. package/_types/chains/definitions/fraxtal.d.ts.map +1 -1
  118. package/_types/chains/definitions/fraxtalTestnet.d.ts +3 -226
  119. package/_types/chains/definitions/fraxtalTestnet.d.ts.map +1 -1
  120. package/_types/chains/definitions/funkiMainnet.d.ts +3 -226
  121. package/_types/chains/definitions/funkiMainnet.d.ts.map +1 -1
  122. package/_types/chains/definitions/funkiSepolia.d.ts +3 -226
  123. package/_types/chains/definitions/funkiSepolia.d.ts.map +1 -1
  124. package/_types/chains/definitions/garnet.d.ts +3 -226
  125. package/_types/chains/definitions/garnet.d.ts.map +1 -1
  126. package/_types/chains/definitions/giwaSepolia.d.ts +6 -452
  127. package/_types/chains/definitions/giwaSepolia.d.ts.map +1 -1
  128. package/_types/chains/definitions/ink.d.ts +3 -226
  129. package/_types/chains/definitions/ink.d.ts.map +1 -1
  130. package/_types/chains/definitions/inkSepolia.d.ts +3 -226
  131. package/_types/chains/definitions/inkSepolia.d.ts.map +1 -1
  132. package/_types/chains/definitions/lisk.d.ts +3 -226
  133. package/_types/chains/definitions/lisk.d.ts.map +1 -1
  134. package/_types/chains/definitions/liskSepolia.d.ts +3 -226
  135. package/_types/chains/definitions/liskSepolia.d.ts.map +1 -1
  136. package/_types/chains/definitions/megaeth.d.ts +3 -226
  137. package/_types/chains/definitions/megaeth.d.ts.map +1 -1
  138. package/_types/chains/definitions/metalL2.d.ts +3 -226
  139. package/_types/chains/definitions/metalL2.d.ts.map +1 -1
  140. package/_types/chains/definitions/mode.d.ts +3 -226
  141. package/_types/chains/definitions/mode.d.ts.map +1 -1
  142. package/_types/chains/definitions/modeTestnet.d.ts +3 -226
  143. package/_types/chains/definitions/modeTestnet.d.ts.map +1 -1
  144. package/_types/chains/definitions/optimism.d.ts +3 -226
  145. package/_types/chains/definitions/optimism.d.ts.map +1 -1
  146. package/_types/chains/definitions/optimismGoerli.d.ts +3 -226
  147. package/_types/chains/definitions/optimismGoerli.d.ts.map +1 -1
  148. package/_types/chains/definitions/optimismSepolia.d.ts +3 -226
  149. package/_types/chains/definitions/optimismSepolia.d.ts.map +1 -1
  150. package/_types/chains/definitions/pgn.d.ts +3 -226
  151. package/_types/chains/definitions/pgn.d.ts.map +1 -1
  152. package/_types/chains/definitions/pgnTestnet.d.ts +3 -226
  153. package/_types/chains/definitions/pgnTestnet.d.ts.map +1 -1
  154. package/_types/chains/definitions/playfiAlbireo.d.ts +4 -371
  155. package/_types/chains/definitions/playfiAlbireo.d.ts.map +1 -1
  156. package/_types/chains/definitions/pyrope.d.ts +3 -226
  157. package/_types/chains/definitions/pyrope.d.ts.map +1 -1
  158. package/_types/chains/definitions/rabbitChainTestnet.d.ts +51 -0
  159. package/_types/chains/definitions/rabbitChainTestnet.d.ts.map +1 -0
  160. package/_types/chains/definitions/redstone.d.ts +3 -226
  161. package/_types/chains/definitions/redstone.d.ts.map +1 -1
  162. package/_types/chains/definitions/rss3.d.ts +3 -226
  163. package/_types/chains/definitions/rss3.d.ts.map +1 -1
  164. package/_types/chains/definitions/rss3Sepolia.d.ts +3 -226
  165. package/_types/chains/definitions/rss3Sepolia.d.ts.map +1 -1
  166. package/_types/chains/definitions/shape.d.ts +3 -226
  167. package/_types/chains/definitions/shape.d.ts.map +1 -1
  168. package/_types/chains/definitions/shapeSepolia.d.ts +3 -226
  169. package/_types/chains/definitions/shapeSepolia.d.ts.map +1 -1
  170. package/_types/chains/definitions/snax.d.ts +3 -226
  171. package/_types/chains/definitions/snax.d.ts.map +1 -1
  172. package/_types/chains/definitions/snaxTestnet.d.ts +3 -226
  173. package/_types/chains/definitions/snaxTestnet.d.ts.map +1 -1
  174. package/_types/chains/definitions/soneium.d.ts +3 -226
  175. package/_types/chains/definitions/soneium.d.ts.map +1 -1
  176. package/_types/chains/definitions/soneiumMinato.d.ts +3 -226
  177. package/_types/chains/definitions/soneiumMinato.d.ts.map +1 -1
  178. package/_types/chains/definitions/sophon.d.ts +4 -371
  179. package/_types/chains/definitions/sophon.d.ts.map +1 -1
  180. package/_types/chains/definitions/sophonTestnet.d.ts +4 -371
  181. package/_types/chains/definitions/sophonTestnet.d.ts.map +1 -1
  182. package/_types/chains/definitions/superseed.d.ts +3 -226
  183. package/_types/chains/definitions/superseed.d.ts.map +1 -1
  184. package/_types/chains/definitions/superseedSepolia.d.ts +3 -226
  185. package/_types/chains/definitions/superseedSepolia.d.ts.map +1 -1
  186. package/_types/chains/definitions/swellchain.d.ts +3 -226
  187. package/_types/chains/definitions/swellchain.d.ts.map +1 -1
  188. package/_types/chains/definitions/swellchainTestnet.d.ts +3 -226
  189. package/_types/chains/definitions/swellchainTestnet.d.ts.map +1 -1
  190. package/_types/chains/definitions/tempo.d.ts +6 -910
  191. package/_types/chains/definitions/tempo.d.ts.map +1 -1
  192. package/_types/chains/definitions/tempoDevnet.d.ts +6 -910
  193. package/_types/chains/definitions/tempoDevnet.d.ts.map +1 -1
  194. package/_types/chains/definitions/tempoLocalnet.d.ts +6 -910
  195. package/_types/chains/definitions/tempoLocalnet.d.ts.map +1 -1
  196. package/_types/chains/definitions/tempoModerato.d.ts +6 -910
  197. package/_types/chains/definitions/tempoModerato.d.ts.map +1 -1
  198. package/_types/chains/definitions/treasure.d.ts +4 -371
  199. package/_types/chains/definitions/treasure.d.ts.map +1 -1
  200. package/_types/chains/definitions/treasureTopaz.d.ts +4 -371
  201. package/_types/chains/definitions/treasureTopaz.d.ts.map +1 -1
  202. package/_types/chains/definitions/unichain.d.ts +3 -226
  203. package/_types/chains/definitions/unichain.d.ts.map +1 -1
  204. package/_types/chains/definitions/unichainSepolia.d.ts +3 -226
  205. package/_types/chains/definitions/unichainSepolia.d.ts.map +1 -1
  206. package/_types/chains/definitions/whitechainSepolia.d.ts +3 -226
  207. package/_types/chains/definitions/whitechainSepolia.d.ts.map +1 -1
  208. package/_types/chains/definitions/worldchain.d.ts +3 -226
  209. package/_types/chains/definitions/worldchain.d.ts.map +1 -1
  210. package/_types/chains/definitions/worldchainSepolia.d.ts +3 -226
  211. package/_types/chains/definitions/worldchainSepolia.d.ts.map +1 -1
  212. package/_types/chains/definitions/zircuit.d.ts +3 -226
  213. package/_types/chains/definitions/zircuit.d.ts.map +1 -1
  214. package/_types/chains/definitions/zircuitGarfieldTestnet.d.ts +3 -226
  215. package/_types/chains/definitions/zircuitGarfieldTestnet.d.ts.map +1 -1
  216. package/_types/chains/definitions/zksync.d.ts +4 -371
  217. package/_types/chains/definitions/zksync.d.ts.map +1 -1
  218. package/_types/chains/definitions/zksyncInMemoryNode.d.ts +4 -371
  219. package/_types/chains/definitions/zksyncInMemoryNode.d.ts.map +1 -1
  220. package/_types/chains/definitions/zksyncLocalCustomHyperchain.d.ts +4 -371
  221. package/_types/chains/definitions/zksyncLocalCustomHyperchain.d.ts.map +1 -1
  222. package/_types/chains/definitions/zksyncLocalHyperchain.d.ts +4 -371
  223. package/_types/chains/definitions/zksyncLocalHyperchain.d.ts.map +1 -1
  224. package/_types/chains/definitions/zksyncLocalNode.d.ts +4 -371
  225. package/_types/chains/definitions/zksyncLocalNode.d.ts.map +1 -1
  226. package/_types/chains/definitions/zksyncSepoliaTestnet.d.ts +4 -371
  227. package/_types/chains/definitions/zksyncSepoliaTestnet.d.ts.map +1 -1
  228. package/_types/chains/definitions/zora.d.ts +3 -226
  229. package/_types/chains/definitions/zora.d.ts.map +1 -1
  230. package/_types/chains/definitions/zoraSepolia.d.ts +3 -226
  231. package/_types/chains/definitions/zoraSepolia.d.ts.map +1 -1
  232. package/_types/chains/definitions/zoraTestnet.d.ts +3 -226
  233. package/_types/chains/definitions/zoraTestnet.d.ts.map +1 -1
  234. package/_types/chains/index.d.ts +1 -0
  235. package/_types/chains/index.d.ts.map +1 -1
  236. package/_types/clients/decorators/public.d.ts +11 -0
  237. package/_types/clients/decorators/public.d.ts.map +1 -1
  238. package/_types/errors/version.d.ts +1 -1
  239. package/_types/index.d.ts +1 -0
  240. package/_types/index.d.ts.map +1 -1
  241. package/_types/op-stack/chainConfig.d.ts +3 -226
  242. package/_types/op-stack/chainConfig.d.ts.map +1 -1
  243. package/_types/op-stack/formatters.d.ts +5 -228
  244. package/_types/op-stack/formatters.d.ts.map +1 -1
  245. package/_types/tempo/Abis.d.ts +14686 -9568
  246. package/_types/tempo/Abis.d.ts.map +1 -1
  247. package/_types/tempo/Addresses.d.ts +2 -0
  248. package/_types/tempo/Addresses.d.ts.map +1 -1
  249. package/_types/tempo/Decorator.d.ts +205 -1
  250. package/_types/tempo/Decorator.d.ts.map +1 -1
  251. package/_types/tempo/Selectors.d.ts +6 -3
  252. package/_types/tempo/Selectors.d.ts.map +1 -1
  253. package/_types/tempo/actions/earn.d.ts +621 -1
  254. package/_types/tempo/actions/earn.d.ts.map +1 -1
  255. package/_types/tempo/actions/index.d.ts +1 -0
  256. package/_types/tempo/actions/index.d.ts.map +1 -1
  257. package/_types/tempo/actions/propAmm.d.ts +2228 -0
  258. package/_types/tempo/actions/propAmm.d.ts.map +1 -0
  259. package/_types/tempo/chainConfig.d.ts +4 -457
  260. package/_types/tempo/chainConfig.d.ts.map +1 -1
  261. package/_types/tokens/definitions/eurc.d.ts +1 -0
  262. package/_types/tokens/definitions/eurc.d.ts.map +1 -1
  263. package/_types/tokens/definitions/usdc.d.ts +1 -0
  264. package/_types/tokens/definitions/usdc.d.ts.map +1 -1
  265. package/_types/tokens/sets.d.ts +3 -0
  266. package/_types/tokens/sets.d.ts.map +1 -1
  267. package/_types/types/eip1193.d.ts +20 -0
  268. package/_types/types/eip1193.d.ts.map +1 -1
  269. package/_types/utils/formatters/block.d.ts +1 -1
  270. package/_types/utils/formatters/formatter.d.ts +1 -2
  271. package/_types/utils/formatters/formatter.d.ts.map +1 -1
  272. package/_types/utils/formatters/transaction.d.ts +1 -1
  273. package/_types/utils/formatters/transactionReceipt.d.ts +1 -1
  274. package/_types/utils/formatters/transactionRequest.d.ts +1 -1
  275. package/_types/zksync/chainConfig.d.ts +4 -371
  276. package/_types/zksync/chainConfig.d.ts.map +1 -1
  277. package/_types/zksync/formatters.d.ts +6 -374
  278. package/_types/zksync/formatters.d.ts.map +1 -1
  279. package/actions/index.ts +6 -0
  280. package/actions/public/getStorageValues.ts +93 -0
  281. package/actions/public/simulateBlocks.ts +13 -0
  282. package/chains/definitions/rabbitChainTestnet.ts +21 -0
  283. package/chains/index.ts +1 -0
  284. package/clients/decorators/public.ts +18 -0
  285. package/errors/version.ts +1 -1
  286. package/index.ts +5 -0
  287. package/package.json +1 -1
  288. package/tempo/Abis.ts +1218 -34
  289. package/tempo/Addresses.ts +2 -0
  290. package/tempo/Decorator.ts +239 -3
  291. package/tempo/Selectors.ts +10 -4
  292. package/tempo/actions/index.ts +1 -0
  293. package/tempo/actions/propAmm.ts +998 -0
  294. package/tokens/definitions/eurc.ts +1 -0
  295. package/tokens/definitions/usdc.ts +1 -0
  296. package/types/eip1193.ts +20 -0
  297. package/utils/formatters/formatter.ts +4 -4
@@ -0,0 +1,998 @@
1
+ import type { Address } from 'abitype'
2
+ import * as Hex from 'ox/Hex'
3
+ import type { Account } from '../../accounts/types.js'
4
+ import { parseAccount } from '../../accounts/utils/parseAccount.js'
5
+ import { estimateGas as core_estimateGas } from '../../actions/public/estimateGas.js'
6
+ import type { ReadContractReturnType } from '../../actions/public/readContract.js'
7
+ import { readContract } from '../../actions/public/readContract.js'
8
+ import {
9
+ type SendTransactionReturnType,
10
+ sendTransaction,
11
+ } from '../../actions/wallet/sendTransaction.js'
12
+ import { sendTransactionSync } from '../../actions/wallet/sendTransactionSync.js'
13
+ import type { Client } from '../../clients/createClient.js'
14
+ import type { Transport } from '../../clients/transports/createTransport.js'
15
+ import { AccountNotFoundError } from '../../errors/account.js'
16
+ import type { BaseErrorType } from '../../errors/base.js'
17
+ import type { Chain } from '../../types/chain.js'
18
+ import type { GetEventArgs } from '../../types/contract.js'
19
+ import type { Log } from '../../types/log.js'
20
+ import type { Compute, UnionOmit } from '../../types/utils.js'
21
+ import { parseEventLogs } from '../../utils/abi/parseEventLogs.js'
22
+ import { isAddressEqual } from '../../utils/address/isAddressEqual.js'
23
+ import { pad } from '../../utils/data/pad.js'
24
+ import * as Abis from '../Abis.js'
25
+ import * as Expiry from '../Expiry.js'
26
+ import type { ReadParameters, WriteParameters } from '../internal/types.js'
27
+ import { defineCall, pickWriteParameters } from '../internal/utils.js'
28
+ import type { TransactionReceipt } from '../Transaction.js'
29
+ import * as simulateActions from './simulate.js'
30
+ import * as tokenActions from './token.js'
31
+
32
+ /**
33
+ * Reads the base token of a propAMM pool.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * import { createClient, http } from 'viem'
38
+ * import { tempo } from 'viem/chains'
39
+ * import { Actions } from 'viem/tempo'
40
+ *
41
+ * const client = createClient({ chain: tempo, transport: http() })
42
+ *
43
+ * const token = await Actions.propAmm.baseToken(client, { pool: '0x...' })
44
+ * ```
45
+ *
46
+ * @param client - Client.
47
+ * @param parameters - Pool and read options.
48
+ * @returns Base token address.
49
+ */
50
+ export async function baseToken<chain extends Chain | undefined>(
51
+ client: Client<Transport, chain>,
52
+ parameters: baseToken.Parameters,
53
+ ): Promise<baseToken.ReturnValue> {
54
+ const { pool, ...rest } = parameters
55
+ return readContract(client, { ...rest, ...baseToken.call({ pool }) })
56
+ }
57
+
58
+ export namespace baseToken {
59
+ export type Args = {
60
+ /** Pool address. */
61
+ pool: Address
62
+ }
63
+
64
+ export type Parameters = ReadParameters & Args
65
+
66
+ export type ReturnValue = ReadContractReturnType<
67
+ typeof Abis.directPropAmm,
68
+ 'baseToken'
69
+ >
70
+
71
+ /**
72
+ * Defines the pool's `baseToken` call.
73
+ */
74
+ export function call({ pool }: Args) {
75
+ return defineCall({
76
+ abi: Abis.directPropAmm,
77
+ address: pool,
78
+ functionName: 'baseToken',
79
+ })
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Reads the quote token of a propAMM pool.
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * import { createClient, http } from 'viem'
89
+ * import { tempo } from 'viem/chains'
90
+ * import { Actions } from 'viem/tempo'
91
+ *
92
+ * const client = createClient({ chain: tempo, transport: http() })
93
+ *
94
+ * const token = await Actions.propAmm.quoteToken(client, { pool: '0x...' })
95
+ * ```
96
+ *
97
+ * @param client - Client.
98
+ * @param parameters - Pool and read options.
99
+ * @returns Quote token address.
100
+ */
101
+ export async function quoteToken<chain extends Chain | undefined>(
102
+ client: Client<Transport, chain>,
103
+ parameters: quoteToken.Parameters,
104
+ ): Promise<quoteToken.ReturnValue> {
105
+ const { pool, ...rest } = parameters
106
+ return readContract(client, { ...rest, ...quoteToken.call({ pool }) })
107
+ }
108
+
109
+ export namespace quoteToken {
110
+ export type Args = {
111
+ /** Pool address. */
112
+ pool: Address
113
+ }
114
+
115
+ export type Parameters = ReadParameters & Args
116
+
117
+ export type ReturnValue = ReadContractReturnType<
118
+ typeof Abis.directPropAmm,
119
+ 'quoteToken'
120
+ >
121
+
122
+ /**
123
+ * Defines the pool's `quoteToken` call.
124
+ */
125
+ export function call({ pool }: Args) {
126
+ return defineCall({
127
+ abi: Abis.directPropAmm,
128
+ address: pool,
129
+ functionName: 'quoteToken',
130
+ })
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Reads whether a propAMM pool is paused.
136
+ *
137
+ * @example
138
+ * ```ts
139
+ * import { createClient, http } from 'viem'
140
+ * import { tempo } from 'viem/chains'
141
+ * import { Actions } from 'viem/tempo'
142
+ *
143
+ * const client = createClient({ chain: tempo, transport: http() })
144
+ *
145
+ * const isPaused = await Actions.propAmm.paused(client, { pool: '0x...' })
146
+ * ```
147
+ *
148
+ * @param client - Client.
149
+ * @param parameters - Pool and read options.
150
+ * @returns Whether swaps are paused.
151
+ */
152
+ export async function paused<chain extends Chain | undefined>(
153
+ client: Client<Transport, chain>,
154
+ parameters: paused.Parameters,
155
+ ): Promise<paused.ReturnValue> {
156
+ const { pool, ...rest } = parameters
157
+ return readContract(client, { ...rest, ...paused.call({ pool }) })
158
+ }
159
+
160
+ export namespace paused {
161
+ export type Args = {
162
+ /** Pool address. */
163
+ pool: Address
164
+ }
165
+
166
+ export type Parameters = ReadParameters & Args
167
+
168
+ export type ReturnValue = ReadContractReturnType<
169
+ typeof Abis.directPropAmm,
170
+ 'paused'
171
+ >
172
+
173
+ /**
174
+ * Defines the pool's `paused` call.
175
+ */
176
+ export function call({ pool }: Args) {
177
+ return defineCall({
178
+ abi: Abis.directPropAmm,
179
+ address: pool,
180
+ functionName: 'paused',
181
+ })
182
+ }
183
+ }
184
+
185
+ /**
186
+ * Reads whether an address may call swaps on a pool.
187
+ *
188
+ * @example
189
+ * ```ts
190
+ * import { createClient, http } from 'viem'
191
+ * import { tempo } from 'viem/chains'
192
+ * import { Actions } from 'viem/tempo'
193
+ *
194
+ * const client = createClient({ chain: tempo, transport: http() })
195
+ *
196
+ * const allowed = await Actions.propAmm.takerAllowed(client, { pool: '0x...', taker: '0x...' })
197
+ * ```
198
+ *
199
+ * @param client - Client.
200
+ * @param parameters - Pool, taker, and read options.
201
+ * @returns Whether the taker is allowed.
202
+ */
203
+ export async function takerAllowed<chain extends Chain | undefined>(
204
+ client: Client<Transport, chain>,
205
+ parameters: takerAllowed.Parameters,
206
+ ): Promise<takerAllowed.ReturnValue> {
207
+ const { pool, taker, ...rest } = parameters
208
+ return readContract(client, {
209
+ ...rest,
210
+ ...takerAllowed.call({ pool, taker }),
211
+ })
212
+ }
213
+
214
+ export namespace takerAllowed {
215
+ export type Args = {
216
+ /** Pool address. */
217
+ pool: Address
218
+ /** Address that calls the swap. */
219
+ taker: Address
220
+ }
221
+
222
+ export type Parameters = ReadParameters & Args
223
+
224
+ export type ReturnValue = ReadContractReturnType<
225
+ typeof Abis.directPropAmm,
226
+ 'takerAllowed'
227
+ >
228
+
229
+ /**
230
+ * Defines the pool's `takerAllowed` call.
231
+ */
232
+ export function call({ pool, taker }: Args) {
233
+ return defineCall({
234
+ abi: Abis.directPropAmm,
235
+ address: pool,
236
+ args: [taker],
237
+ functionName: 'takerAllowed',
238
+ })
239
+ }
240
+ }
241
+
242
+ /**
243
+ * Reads whether a resolved address may receive swap output.
244
+ *
245
+ * @example
246
+ * ```ts
247
+ * import { createClient, http } from 'viem'
248
+ * import { tempo } from 'viem/chains'
249
+ * import { Actions } from 'viem/tempo'
250
+ *
251
+ * const client = createClient({ chain: tempo, transport: http() })
252
+ *
253
+ * const allowed = await Actions.propAmm.recipientAllowed(client, { pool: '0x...', recipient: '0x...' })
254
+ * ```
255
+ *
256
+ * @param client - Client.
257
+ * @param parameters - Pool, resolved recipient, and read options.
258
+ * @returns Whether the resolved recipient is allowed.
259
+ */
260
+ export async function recipientAllowed<chain extends Chain | undefined>(
261
+ client: Client<Transport, chain>,
262
+ parameters: recipientAllowed.Parameters,
263
+ ): Promise<recipientAllowed.ReturnValue> {
264
+ const { pool, recipient, ...rest } = parameters
265
+ return readContract(client, {
266
+ ...rest,
267
+ ...recipientAllowed.call({ pool, recipient }),
268
+ })
269
+ }
270
+
271
+ export namespace recipientAllowed {
272
+ export type Args = {
273
+ /** Pool address. */
274
+ pool: Address
275
+ /** Resolved address to check. */
276
+ recipient: Address
277
+ }
278
+
279
+ export type Parameters = ReadParameters & Args
280
+
281
+ export type ReturnValue = ReadContractReturnType<
282
+ typeof Abis.directPropAmm,
283
+ 'recipientAllowed'
284
+ >
285
+
286
+ /**
287
+ * Defines the pool's `recipientAllowed` call.
288
+ */
289
+ export function call({ pool, recipient }: Args) {
290
+ return defineCall({
291
+ abi: Abis.directPropAmm,
292
+ address: pool,
293
+ args: [recipient],
294
+ functionName: 'recipientAllowed',
295
+ })
296
+ }
297
+ }
298
+
299
+ /**
300
+ * Resolves a Tempo recipient to the address checked by the pool's allowlist.
301
+ *
302
+ * @example
303
+ * ```ts
304
+ * import { createClient, http } from 'viem'
305
+ * import { tempo } from 'viem/chains'
306
+ * import { Actions } from 'viem/tempo'
307
+ *
308
+ * const client = createClient({ chain: tempo, transport: http() })
309
+ *
310
+ * const resolved = await Actions.propAmm.resolveRecipient(client, { pool: '0x...', recipient: '0x...' })
311
+ * ```
312
+ *
313
+ * @param client - Client.
314
+ * @param parameters - Pool, recipient, and read options.
315
+ * @returns Resolved recipient address.
316
+ */
317
+ export async function resolveRecipient<chain extends Chain | undefined>(
318
+ client: Client<Transport, chain>,
319
+ parameters: resolveRecipient.Parameters,
320
+ ): Promise<resolveRecipient.ReturnValue> {
321
+ const { pool, recipient, ...rest } = parameters
322
+ return readContract(client, {
323
+ ...rest,
324
+ ...resolveRecipient.call({ pool, recipient }),
325
+ })
326
+ }
327
+
328
+ export namespace resolveRecipient {
329
+ export type Args = {
330
+ /** Pool address. */
331
+ pool: Address
332
+ /** Destination provided to the swap. */
333
+ recipient: Address
334
+ }
335
+
336
+ export type Parameters = ReadParameters & Args
337
+
338
+ export type ReturnValue = ReadContractReturnType<
339
+ typeof Abis.directPropAmm,
340
+ 'resolveRecipient'
341
+ >
342
+
343
+ /**
344
+ * Defines the pool's `resolveRecipient` call.
345
+ */
346
+ export function call({ pool, recipient }: Args) {
347
+ return defineCall({
348
+ abi: Abis.directPropAmm,
349
+ address: pool,
350
+ args: [recipient],
351
+ functionName: 'resolveRecipient',
352
+ })
353
+ }
354
+ }
355
+
356
+ /**
357
+ * Quotes an exact input or exact output for a caller, recipient, and customer route.
358
+ *
359
+ * @example
360
+ * ```ts
361
+ * import { createClient, http } from 'viem'
362
+ * import { tempo } from 'viem/chains'
363
+ * import { Actions } from 'viem/tempo'
364
+ *
365
+ * const client = createClient({ chain: tempo, transport: http() })
366
+ *
367
+ * const { amountOut, price, updatedAt } = await Actions.propAmm.getSwapQuote(client, {
368
+ * pool: '0x...',
369
+ * taker: '0x...',
370
+ * recipient: '0x...',
371
+ * mode: 'exactInput',
372
+ * amountIn: 1_000_000n,
373
+ * })
374
+ * ```
375
+ *
376
+ * @param client - Client.
377
+ * @param parameters - Route, swap mode, amount, and read options. Taker defaults to the read or client account.
378
+ * @returns Quoted amount, oracle observation, rounding credit, and swap request.
379
+ */
380
+ export async function getSwapQuote<
381
+ chain extends Chain | undefined,
382
+ const parameters extends getSwapQuote.Parameters,
383
+ >(
384
+ client: Client<Transport, chain>,
385
+ parameters: parameters,
386
+ ): Promise<getSwapQuote.ReturnValue<parameters>>
387
+ export async function getSwapQuote(
388
+ client: Client,
389
+ parameters: getSwapQuote.Parameters,
390
+ ): Promise<getSwapQuote.ReturnValue> {
391
+ const account = parameters.account ?? client.account
392
+ const taker = parameters.taker ?? (account && parseAccount(account).address)
393
+ if (!taker) throw new Error('A taker or client account is required to quote.')
394
+ const recipient =
395
+ parameters.recipient ?? (account && parseAccount(account).address)
396
+ if (!recipient) throw new AccountNotFoundError()
397
+ const baseToQuote = parameters.baseToQuote ?? true
398
+ const customerId = parameters.customerId ?? pad(taker, { size: 32 })
399
+ const [amount, price, updatedAt, creditAfter] = await (readContract(client, {
400
+ ...parameters,
401
+ ...getSwapQuote.call({
402
+ ...parameters,
403
+ baseToQuote,
404
+ customerId,
405
+ recipient,
406
+ taker,
407
+ }),
408
+ } as never) as Promise<
409
+ ReadContractReturnType<typeof Abis.directPropAmm, 'quoteExactInputFor'>
410
+ >)
411
+ const request = {
412
+ baseToQuote,
413
+ customerId,
414
+ expectedOraclePrice: price,
415
+ minimumOracleUpdatedAt: updatedAt,
416
+ oraclePriceToleranceBps: 0n,
417
+ pool: parameters.pool,
418
+ recipient,
419
+ }
420
+ if (parameters.mode === 'exactInput')
421
+ return {
422
+ amountOut: amount,
423
+ price,
424
+ updatedAt,
425
+ creditAfter,
426
+ request: {
427
+ ...request,
428
+ amountIn: parameters.amountIn,
429
+ minAmountOut: amount,
430
+ mode: parameters.mode,
431
+ },
432
+ }
433
+ return {
434
+ amountIn: amount,
435
+ price,
436
+ updatedAt,
437
+ creditAfter,
438
+ request: {
439
+ ...request,
440
+ amountOut: parameters.amountOut,
441
+ maxAmountIn: amount,
442
+ mode: parameters.mode,
443
+ },
444
+ }
445
+ }
446
+
447
+ export namespace getSwapQuote {
448
+ export type Args = {
449
+ /** True sends base and receives quote; false sends quote and receives base. */
450
+ baseToQuote: boolean
451
+ /** Nonzero attribution and rounding-route identifier. */
452
+ customerId: Hex.Hex
453
+ /** Pool address. */
454
+ pool: Address
455
+ /** Destination of the output token. */
456
+ recipient: Address
457
+ /** Address that will call the swap. */
458
+ taker: Address
459
+ } & (
460
+ | {
461
+ /** Exact-input quote. */
462
+ mode: 'exactInput'
463
+ /** Input amount in token base units. */
464
+ amountIn: bigint
465
+ }
466
+ | {
467
+ /** Exact-output quote. */
468
+ mode: 'exactOutput'
469
+ /** Output amount in token base units. */
470
+ amountOut: bigint
471
+ }
472
+ )
473
+
474
+ export type Parameters = ReadParameters &
475
+ UnionOmit<Args, 'baseToQuote' | 'customerId' | 'recipient' | 'taker'> & {
476
+ /** True sends base and receives quote. Defaults to true. */
477
+ baseToQuote?: boolean | undefined
478
+ /** Route identifier. Defaults to the taker address left-padded to 32 bytes. */
479
+ customerId?: Hex.Hex | undefined
480
+ /** Output destination. Defaults to the read account or client account. */
481
+ recipient?: Address | undefined
482
+ /** Address that will call the swap. Defaults to the read account or client account. */
483
+ taker?: Address | undefined
484
+ }
485
+
486
+ /** Quoted amount, oracle observation, rounding credit, and swap request. */
487
+
488
+ export type ReturnValue<parameters extends Parameters = Parameters> = Compute<
489
+ {
490
+ /** Oracle price used for the quote. */
491
+ price: bigint
492
+ /** Oracle observation timestamp. */
493
+ updatedAt: bigint
494
+ /** Route's remaining rounding credit. */
495
+ creditAfter: bigint
496
+ } & (parameters extends { mode: 'exactInput' }
497
+ ? {
498
+ /** Quoted output amount in token base units. */
499
+ amountOut: bigint
500
+ /** Swap inputs bound to this quote. */
501
+ request: Omit<
502
+ Extract<swap.Args, { mode: 'exactInput' }>,
503
+ 'deadline' | 'tradeId'
504
+ >
505
+ }
506
+ : {
507
+ /** Required input amount in token base units. */
508
+ amountIn: bigint
509
+ /** Swap inputs bound to this quote. */
510
+ request: Omit<
511
+ Extract<swap.Args, { mode: 'exactOutput' }>,
512
+ 'deadline' | 'tradeId'
513
+ >
514
+ })
515
+ >
516
+
517
+ /**
518
+ * Defines a route-aware quote call.
519
+ */
520
+ export function call(
521
+ parameters: Extract<Args, { mode: 'exactInput' }>,
522
+ ): ReturnType<typeof quoteExactInputCall>
523
+ export function call(
524
+ parameters: Extract<Args, { mode: 'exactOutput' }>,
525
+ ): ReturnType<typeof quoteExactOutputCall>
526
+ export function call(
527
+ parameters: Args,
528
+ ):
529
+ | ReturnType<typeof quoteExactInputCall>
530
+ | ReturnType<typeof quoteExactOutputCall>
531
+ export function call(parameters: Args) {
532
+ if (parameters.mode === 'exactInput') return quoteExactInputCall(parameters)
533
+ return quoteExactOutputCall(parameters)
534
+ }
535
+ }
536
+
537
+ function quoteExactInputCall(
538
+ parameters: Extract<getSwapQuote.Args, { mode: 'exactInput' }>,
539
+ ) {
540
+ const { amountIn, baseToQuote, customerId, pool, recipient, taker } =
541
+ parameters
542
+ return defineCall({
543
+ abi: Abis.directPropAmm,
544
+ address: pool,
545
+ args: [taker, recipient, customerId, baseToQuote, amountIn],
546
+ functionName: 'quoteExactInputFor',
547
+ })
548
+ }
549
+
550
+ function quoteExactOutputCall(
551
+ parameters: Extract<getSwapQuote.Args, { mode: 'exactOutput' }>,
552
+ ) {
553
+ const { amountOut, baseToQuote, customerId, pool, recipient, taker } =
554
+ parameters
555
+ return defineCall({
556
+ abi: Abis.directPropAmm,
557
+ address: pool,
558
+ args: [taker, recipient, customerId, baseToQuote, amountOut],
559
+ functionName: 'quoteExactOutputFor',
560
+ })
561
+ }
562
+
563
+ /**
564
+ * Internal exact-input contract call.
565
+ */
566
+ namespace exactInput {
567
+ export type Args = {
568
+ amountIn: bigint
569
+ baseToQuote: boolean
570
+ customerId: Hex.Hex
571
+ deadline: bigint
572
+ expectedOraclePrice: bigint
573
+ minAmountOut: bigint
574
+ minimumOracleUpdatedAt: bigint
575
+ oraclePriceToleranceBps: bigint
576
+ pool: Address
577
+ recipient: Address
578
+ tradeId: Hex.Hex
579
+ }
580
+
581
+ export function call({
582
+ amountIn,
583
+ baseToQuote,
584
+ customerId,
585
+ deadline,
586
+ expectedOraclePrice,
587
+ minAmountOut,
588
+ minimumOracleUpdatedAt,
589
+ oraclePriceToleranceBps,
590
+ pool,
591
+ recipient,
592
+ tradeId,
593
+ }: Args) {
594
+ return defineCall({
595
+ abi: Abis.directPropAmm,
596
+ address: pool,
597
+ args: [
598
+ baseToQuote,
599
+ amountIn,
600
+ minAmountOut,
601
+ recipient,
602
+ customerId,
603
+ tradeId,
604
+ deadline,
605
+ expectedOraclePrice,
606
+ oraclePriceToleranceBps,
607
+ minimumOracleUpdatedAt,
608
+ ],
609
+ functionName: 'swapExactInput',
610
+ })
611
+ }
612
+ }
613
+
614
+ /**
615
+ * Internal exact-output contract call.
616
+ */
617
+ namespace exactOutput {
618
+ export type Args = {
619
+ amountOut: bigint
620
+ baseToQuote: boolean
621
+ customerId: Hex.Hex
622
+ deadline: bigint
623
+ expectedOraclePrice: bigint
624
+ maxAmountIn: bigint
625
+ minimumOracleUpdatedAt: bigint
626
+ oraclePriceToleranceBps: bigint
627
+ pool: Address
628
+ recipient: Address
629
+ tradeId: Hex.Hex
630
+ }
631
+
632
+ export function call({
633
+ amountOut,
634
+ baseToQuote,
635
+ customerId,
636
+ deadline,
637
+ expectedOraclePrice,
638
+ maxAmountIn,
639
+ minimumOracleUpdatedAt,
640
+ oraclePriceToleranceBps,
641
+ pool,
642
+ recipient,
643
+ tradeId,
644
+ }: Args) {
645
+ return defineCall({
646
+ abi: Abis.directPropAmm,
647
+ address: pool,
648
+ args: [
649
+ baseToQuote,
650
+ amountOut,
651
+ maxAmountIn,
652
+ recipient,
653
+ customerId,
654
+ tradeId,
655
+ deadline,
656
+ expectedOraclePrice,
657
+ oraclePriceToleranceBps,
658
+ minimumOracleUpdatedAt,
659
+ ],
660
+ functionName: 'swapExactOutput',
661
+ })
662
+ }
663
+ }
664
+
665
+ /**
666
+ * Approves the input token and swaps through an allowed propAMM pool in one transaction.
667
+ *
668
+ * @example
669
+ * ```ts
670
+ * import { createClient, http } from 'viem'
671
+ * import { tempo } from 'viem/chains'
672
+ * import { Actions } from 'viem/tempo'
673
+ *
674
+ * const client = createClient({ chain: tempo, transport: http(), account: '0x...' })
675
+ *
676
+ * const hash = await Actions.propAmm.swap(client, {
677
+ * pool: '0x...',
678
+ * mode: 'exactInput',
679
+ * amountIn: 1_000_000n,
680
+ * minAmountOut: 1_000_000n,
681
+ * expectedOraclePrice: 1_000_000_000_000_000_000n,
682
+ * minimumOracleUpdatedAt: 1_799_999_000n,
683
+ * })
684
+ * ```
685
+ *
686
+ * @param client - Client.
687
+ * @param parameters - Swap and transaction options.
688
+ * @returns Transaction hash.
689
+ */
690
+ export async function swap<
691
+ chain extends Chain | undefined,
692
+ account extends Account | undefined,
693
+ >(
694
+ client: Client<Transport, chain, account>,
695
+ parameters: swap.Parameters<chain, account>,
696
+ ): Promise<swap.ReturnValue> {
697
+ return swap.inner(sendTransaction, client, parameters)
698
+ }
699
+
700
+ export namespace swap {
701
+ export type Args = {
702
+ /** True sends base and receives quote; false sends quote and receives base. */
703
+ baseToQuote: boolean
704
+ /** Nonzero attribution and rounding-route identifier. */
705
+ customerId: Hex.Hex
706
+ /** Last accepted execution timestamp in seconds. */
707
+ deadline: bigint
708
+ /** Oracle price returned by the quote. */
709
+ expectedOraclePrice: bigint
710
+ /** Earliest accepted oracle observation timestamp. */
711
+ minimumOracleUpdatedAt: bigint
712
+ /** Accepted oracle-price movement in basis points. Zero binds exactly. */
713
+ oraclePriceToleranceBps: bigint
714
+ /** Pool address. */
715
+ pool: Address
716
+ /** Destination of the output token. */
717
+ recipient: Address
718
+ /** Trade attribution value, not replay protection. */
719
+ tradeId: Hex.Hex
720
+ } & (
721
+ | {
722
+ /** Exact-input swap. */
723
+ mode: 'exactInput'
724
+ /** Exact input amount in token base units. */
725
+ amountIn: bigint
726
+ /** Lowest accepted output in token base units. */
727
+ minAmountOut: bigint
728
+ }
729
+ | {
730
+ /** Exact-output swap. */
731
+ mode: 'exactOutput'
732
+ /** Exact output amount in token base units. */
733
+ amountOut: bigint
734
+ /** Highest accepted input in token base units; unused approval remains. */
735
+ maxAmountIn: bigint
736
+ }
737
+ )
738
+
739
+ export type InputArgs = UnionOmit<
740
+ Args,
741
+ | 'baseToQuote'
742
+ | 'customerId'
743
+ | 'deadline'
744
+ | 'oraclePriceToleranceBps'
745
+ | 'recipient'
746
+ | 'tradeId'
747
+ > & {
748
+ /** True sends base and receives quote. Defaults to true. */
749
+ baseToQuote?: boolean | undefined
750
+ /** Route identifier. Defaults to the sender address left-padded to 32 bytes. */
751
+ customerId?: Hex.Hex | undefined
752
+ /** Last accepted execution timestamp. Defaults to five minutes from now. */
753
+ deadline?: bigint | undefined
754
+ /** Output destination. Defaults to the sending account. */
755
+ recipient?: Address | undefined
756
+ /** Accepted oracle-price movement in basis points. Defaults to zero. */
757
+ oraclePriceToleranceBps?: bigint | undefined
758
+ /** Trade attribution value. Defaults to a random 32-byte value per swap. */
759
+ tradeId?: Hex.Hex | undefined
760
+ }
761
+
762
+ export type Parameters<
763
+ chain extends Chain | undefined = Chain | undefined,
764
+ account extends Account | undefined = Account | undefined,
765
+ > = WriteParameters<chain, account> & InputArgs
766
+
767
+ export type ReturnValue = SendTransactionReturnType
768
+
769
+ export type ErrorType = BaseErrorType
770
+
771
+ /** @internal */
772
+ export async function inner<
773
+ action extends typeof sendTransaction | typeof sendTransactionSync,
774
+ chain extends Chain | undefined,
775
+ account extends Account | undefined,
776
+ >(
777
+ action: action,
778
+ client: Client<Transport, chain, account>,
779
+ parameters: Parameters<chain, account>,
780
+ ): Promise<ReturnType<action>> {
781
+ return (await action(client, {
782
+ ...parameters,
783
+ calls: await getCalls(client, parameters),
784
+ } as never)) as never
785
+ }
786
+
787
+ async function getCalls<
788
+ chain extends Chain | undefined,
789
+ account extends Account | undefined,
790
+ >(
791
+ client: Client<Transport, chain, account>,
792
+ parameters: InputArgs & { account?: Account | Address | null | undefined },
793
+ ) {
794
+ const account = parameters.account ?? client.account
795
+ const recipient =
796
+ parameters.recipient ?? (account && parseAccount(account).address)
797
+ if (!recipient) throw new AccountNotFoundError()
798
+ const customerId =
799
+ parameters.customerId ??
800
+ (account && pad(parseAccount(account).address, { size: 32 }))
801
+ if (!customerId) throw new AccountNotFoundError()
802
+ const baseToQuote = parameters.baseToQuote ?? true
803
+ const tokenIn = await (baseToQuote
804
+ ? baseToken(client, { pool: parameters.pool })
805
+ : quoteToken(client, { pool: parameters.pool }))
806
+ const amount =
807
+ parameters.mode === 'exactInput'
808
+ ? parameters.amountIn
809
+ : parameters.maxAmountIn
810
+ return [
811
+ tokenActions.approve.call(client, {
812
+ amount,
813
+ spender: parameters.pool,
814
+ token: tokenIn,
815
+ }),
816
+ swap.call({
817
+ ...parameters,
818
+ baseToQuote,
819
+ customerId,
820
+ deadline: parameters.deadline ?? BigInt(Expiry.minutes(5)),
821
+ tradeId: parameters.tradeId ?? Hex.random(32),
822
+ recipient,
823
+ oraclePriceToleranceBps: parameters.oraclePriceToleranceBps ?? 0n,
824
+ }),
825
+ ] as const
826
+ }
827
+
828
+ /**
829
+ * Estimates gas for the approval and swap transaction.
830
+ *
831
+ * @param client - Client.
832
+ * @param parameters - Swap and transaction options.
833
+ * @returns The gas estimate.
834
+ */
835
+ export async function estimateGas<
836
+ chain extends Chain | undefined,
837
+ account extends Account | undefined,
838
+ >(
839
+ client: Client<Transport, chain, account>,
840
+ parameters: Parameters<chain, account>,
841
+ ): Promise<bigint> {
842
+ return core_estimateGas(client, {
843
+ ...pickWriteParameters(parameters as never),
844
+ calls: await getCalls(client, parameters),
845
+ } as never)
846
+ }
847
+
848
+ /**
849
+ * Simulates the approval and swap calls without submitting a transaction.
850
+ *
851
+ * @param client - Client.
852
+ * @param parameters - Swap and simulation options.
853
+ * @returns The approval and swap simulation results.
854
+ */
855
+ export async function simulate<
856
+ chain extends Chain | undefined,
857
+ account extends Account | undefined,
858
+ >(
859
+ client: Client<Transport, chain, account>,
860
+ parameters: simulate.Parameters,
861
+ ) {
862
+ const {
863
+ blockNumber,
864
+ blockTag,
865
+ stateOverrides,
866
+ traceTransfers,
867
+ validation,
868
+ } = parameters
869
+ return simulateActions.simulateCalls(client, {
870
+ account: parameters.account ?? client.account,
871
+ blockNumber,
872
+ blockTag,
873
+ calls: await getCalls(client, parameters),
874
+ stateOverrides,
875
+ traceTransfers,
876
+ validation,
877
+ })
878
+ }
879
+
880
+ export namespace simulate {
881
+ /** Swap inputs and batch simulation options. */
882
+ export type Parameters = InputArgs &
883
+ Omit<simulateActions.simulateCalls.Parameters, 'calls'>
884
+ }
885
+
886
+ /**
887
+ * Defines the raw swap call without its input-token approval.
888
+ */
889
+ export function call(
890
+ parameters: Extract<Args, { mode: 'exactInput' }>,
891
+ ): ReturnType<typeof exactInput.call>
892
+ export function call(
893
+ parameters: Extract<Args, { mode: 'exactOutput' }>,
894
+ ): ReturnType<typeof exactOutput.call>
895
+ export function call(
896
+ parameters: Args,
897
+ ): ReturnType<typeof exactInput.call> | ReturnType<typeof exactOutput.call>
898
+ export function call(parameters: Args) {
899
+ if (parameters.mode === 'exactInput') return exactInput.call(parameters)
900
+ return exactOutput.call(parameters)
901
+ }
902
+
903
+ /**
904
+ * Extracts the unique matching trade event from a receipt.
905
+ */
906
+ export function extractEvent(
907
+ logs: Log[],
908
+ args: { pool: Address; tradeId: Hex.Hex },
909
+ ) {
910
+ const matching = parseEventLogs({
911
+ abi: Abis.directPropAmm,
912
+ logs,
913
+ eventName: 'TradeExecuted',
914
+ strict: true,
915
+ }).filter(
916
+ (log) =>
917
+ isAddressEqual(log.address, args.pool) &&
918
+ log.args.tradeId.toLowerCase() === args.tradeId.toLowerCase(),
919
+ )
920
+ if (matching.length !== 1)
921
+ throw new Error(
922
+ `Expected one TradeExecuted event for pool ${args.pool} and trade ${args.tradeId}; found ${matching.length}.`,
923
+ )
924
+ return matching[0]!
925
+ }
926
+ }
927
+
928
+ /**
929
+ * Approves the input token, swaps, and returns the confirmed trade and receipt.
930
+ *
931
+ * @example
932
+ * ```ts
933
+ * import { createClient, http } from 'viem'
934
+ * import { tempo } from 'viem/chains'
935
+ * import { Actions } from 'viem/tempo'
936
+ *
937
+ * const client = createClient({ chain: tempo, transport: http(), account: '0x...' })
938
+ *
939
+ * const trade = await Actions.propAmm.swapSync(client, {
940
+ * pool: '0x...',
941
+ * mode: 'exactInput',
942
+ * amountIn: 1_000_000n,
943
+ * minAmountOut: 1_000_000n,
944
+ * expectedOraclePrice: 1_000_000_000_000_000_000n,
945
+ * minimumOracleUpdatedAt: 1_799_999_000n,
946
+ * })
947
+ * console.log(trade.amountOut, trade.receipt.transactionHash)
948
+ * ```
949
+ *
950
+ * @param client - Client.
951
+ * @param parameters - Swap and transaction options.
952
+ * @returns Confirmed trade data and receipt.
953
+ */
954
+ export async function swapSync<
955
+ chain extends Chain | undefined,
956
+ account extends Account | undefined,
957
+ >(
958
+ client: Client<Transport, chain, account>,
959
+ parameters: swapSync.Parameters<chain, account>,
960
+ ): Promise<swapSync.ReturnValue> {
961
+ const {
962
+ tradeId = Hex.random(32),
963
+ throwOnReceiptRevert = true,
964
+ ...rest
965
+ } = parameters
966
+ const receipt = await swap.inner(sendTransactionSync, client, {
967
+ ...rest,
968
+ throwOnReceiptRevert,
969
+ tradeId,
970
+ } as never)
971
+ if ((receipt as TransactionReceipt).status === 'pending')
972
+ return { receipt } as never
973
+ const { args } = swap.extractEvent(receipt.logs, {
974
+ pool: parameters.pool,
975
+ tradeId,
976
+ })
977
+ return { ...args, receipt } as never
978
+ }
979
+
980
+ export namespace swapSync {
981
+ export type Args = swap.InputArgs
982
+
983
+ export type Parameters<
984
+ chain extends Chain | undefined = Chain | undefined,
985
+ account extends Account | undefined = Account | undefined,
986
+ > = swap.Parameters<chain, account>
987
+
988
+ export type ReturnValue = Compute<
989
+ GetEventArgs<
990
+ typeof Abis.directPropAmm,
991
+ 'TradeExecuted',
992
+ { IndexedOnly: false; Required: true }
993
+ > & {
994
+ /** Confirmed receipt. */
995
+ receipt: TransactionReceipt
996
+ }
997
+ >
998
+ }