tempo.ts 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (276) hide show
  1. package/README.md +33 -2
  2. package/dist/chains.d.ts +509 -115
  3. package/dist/chains.d.ts.map +1 -1
  4. package/dist/chains.js +18 -9
  5. package/dist/chains.js.map +1 -1
  6. package/dist/ox/Order.d.ts +92 -0
  7. package/dist/ox/Order.d.ts.map +1 -0
  8. package/dist/ox/Order.js +88 -0
  9. package/dist/ox/Order.js.map +1 -0
  10. package/dist/ox/OrdersFilters.d.ts +72 -0
  11. package/dist/ox/OrdersFilters.d.ts.map +1 -0
  12. package/dist/ox/OrdersFilters.js +100 -0
  13. package/dist/ox/OrdersFilters.js.map +1 -0
  14. package/dist/ox/Pagination.d.ts +128 -0
  15. package/dist/ox/Pagination.d.ts.map +1 -0
  16. package/dist/ox/Pagination.js +78 -0
  17. package/dist/ox/Pagination.js.map +1 -0
  18. package/dist/ox/PoolId.d.ts +18 -0
  19. package/dist/ox/PoolId.d.ts.map +1 -0
  20. package/dist/ox/PoolId.js +13 -0
  21. package/dist/ox/PoolId.js.map +1 -0
  22. package/dist/ox/RpcSchema.d.ts +32 -0
  23. package/dist/ox/RpcSchema.d.ts.map +1 -0
  24. package/dist/ox/RpcSchema.js +2 -0
  25. package/dist/ox/RpcSchema.js.map +1 -0
  26. package/dist/ox/SignatureEnvelope.d.ts +1 -1
  27. package/dist/ox/SignatureEnvelope.d.ts.map +1 -1
  28. package/dist/ox/SignatureEnvelope.js.map +1 -1
  29. package/dist/{viem → ox}/Tick.d.ts +4 -0
  30. package/dist/ox/Tick.d.ts.map +1 -0
  31. package/dist/ox/Tick.js.map +1 -0
  32. package/dist/ox/Transaction.d.ts.map +1 -1
  33. package/dist/ox/Transaction.js +2 -1
  34. package/dist/ox/Transaction.js.map +1 -1
  35. package/dist/ox/TransactionEnvelopeAA.d.ts +6 -6
  36. package/dist/ox/TransactionEnvelopeAA.d.ts.map +1 -1
  37. package/dist/ox/TransactionEnvelopeAA.js +4 -2
  38. package/dist/ox/TransactionEnvelopeAA.js.map +1 -1
  39. package/dist/ox/TransactionRequest.d.ts +4 -0
  40. package/dist/ox/TransactionRequest.d.ts.map +1 -1
  41. package/dist/ox/TransactionRequest.js.map +1 -1
  42. package/dist/ox/index.d.ts +6 -0
  43. package/dist/ox/index.d.ts.map +1 -1
  44. package/dist/ox/index.js +6 -0
  45. package/dist/ox/index.js.map +1 -1
  46. package/dist/prool/Instance.d.ts.map +1 -1
  47. package/dist/prool/Instance.js +20 -4
  48. package/dist/prool/Instance.js.map +1 -1
  49. package/dist/viem/Abis.d.ts +1469 -1082
  50. package/dist/viem/Abis.d.ts.map +1 -1
  51. package/dist/viem/Abis.js +932 -671
  52. package/dist/viem/Abis.js.map +1 -1
  53. package/dist/viem/Account.d.ts +150 -0
  54. package/dist/viem/Account.d.ts.map +1 -0
  55. package/dist/viem/Account.js +221 -0
  56. package/dist/viem/Account.js.map +1 -0
  57. package/dist/viem/Actions/amm.d.ts +80 -118
  58. package/dist/viem/Actions/amm.d.ts.map +1 -1
  59. package/dist/viem/Actions/amm.js +47 -116
  60. package/dist/viem/Actions/amm.js.map +1 -1
  61. package/dist/viem/Actions/dex.d.ts +889 -633
  62. package/dist/viem/Actions/dex.d.ts.map +1 -1
  63. package/dist/viem/Actions/dex.js +99 -0
  64. package/dist/viem/Actions/dex.js.map +1 -1
  65. package/dist/viem/Actions/fee.d.ts +3 -17
  66. package/dist/viem/Actions/fee.d.ts.map +1 -1
  67. package/dist/viem/Actions/fee.js.map +1 -1
  68. package/dist/viem/Actions/index.d.ts +1 -0
  69. package/dist/viem/Actions/index.d.ts.map +1 -1
  70. package/dist/viem/Actions/index.js +1 -0
  71. package/dist/viem/Actions/index.js.map +1 -1
  72. package/dist/viem/Actions/reward.d.ts +3236 -0
  73. package/dist/viem/Actions/reward.d.ts.map +1 -0
  74. package/dist/viem/Actions/reward.js +725 -0
  75. package/dist/viem/Actions/reward.js.map +1 -0
  76. package/dist/viem/Actions/token.d.ts +4295 -2646
  77. package/dist/viem/Actions/token.d.ts.map +1 -1
  78. package/dist/viem/Actions/token.js +214 -335
  79. package/dist/viem/Actions/token.js.map +1 -1
  80. package/dist/viem/Addresses.d.ts +1 -2
  81. package/dist/viem/Addresses.d.ts.map +1 -1
  82. package/dist/viem/Addresses.js +1 -2
  83. package/dist/viem/Addresses.js.map +1 -1
  84. package/dist/viem/Chain.d.ts +38 -12
  85. package/dist/viem/Chain.d.ts.map +1 -1
  86. package/dist/viem/Chain.js +27 -18
  87. package/dist/viem/Chain.js.map +1 -1
  88. package/dist/viem/Decorator.d.ts +959 -405
  89. package/dist/viem/Decorator.d.ts.map +1 -1
  90. package/dist/viem/Decorator.js +13 -5
  91. package/dist/viem/Decorator.js.map +1 -1
  92. package/dist/viem/Formatters.d.ts +8 -1
  93. package/dist/viem/Formatters.d.ts.map +1 -1
  94. package/dist/viem/Formatters.js +17 -0
  95. package/dist/viem/Formatters.js.map +1 -1
  96. package/dist/viem/P256.d.ts +2 -0
  97. package/dist/viem/P256.d.ts.map +1 -0
  98. package/dist/viem/P256.js +2 -0
  99. package/dist/viem/P256.js.map +1 -0
  100. package/dist/viem/Secp256k1.d.ts +2 -0
  101. package/dist/viem/Secp256k1.d.ts.map +1 -0
  102. package/dist/viem/Secp256k1.js +2 -0
  103. package/dist/viem/Secp256k1.js.map +1 -0
  104. package/dist/viem/TokenIds.d.ts +1 -2
  105. package/dist/viem/TokenIds.d.ts.map +1 -1
  106. package/dist/viem/TokenIds.js +1 -2
  107. package/dist/viem/TokenIds.js.map +1 -1
  108. package/dist/viem/Transaction.d.ts +1 -1
  109. package/dist/viem/Transaction.d.ts.map +1 -1
  110. package/dist/viem/Transaction.js +46 -5
  111. package/dist/viem/Transaction.js.map +1 -1
  112. package/dist/viem/WebAuthnP256.d.ts +79 -0
  113. package/dist/viem/WebAuthnP256.d.ts.map +1 -0
  114. package/dist/viem/WebAuthnP256.js +95 -0
  115. package/dist/viem/WebAuthnP256.js.map +1 -0
  116. package/dist/viem/WebCryptoP256.d.ts +2 -0
  117. package/dist/viem/WebCryptoP256.d.ts.map +1 -0
  118. package/dist/viem/WebCryptoP256.js +2 -0
  119. package/dist/viem/WebCryptoP256.js.map +1 -0
  120. package/dist/viem/index.d.ts +6 -3
  121. package/dist/viem/index.d.ts.map +1 -1
  122. package/dist/viem/index.js +6 -3
  123. package/dist/viem/index.js.map +1 -1
  124. package/dist/viem/internal/account.d.ts +24 -0
  125. package/dist/viem/internal/account.d.ts.map +1 -0
  126. package/dist/viem/internal/account.js +68 -0
  127. package/dist/viem/internal/account.js.map +1 -0
  128. package/dist/viem/internal/types.d.ts +10 -0
  129. package/dist/viem/internal/types.d.ts.map +1 -1
  130. package/dist/wagmi/Actions/amm.d.ts +428 -0
  131. package/dist/wagmi/Actions/amm.d.ts.map +1 -0
  132. package/dist/wagmi/Actions/amm.js +472 -0
  133. package/dist/wagmi/Actions/amm.js.map +1 -0
  134. package/dist/wagmi/Actions/dex.d.ts +908 -0
  135. package/dist/wagmi/Actions/dex.d.ts.map +1 -0
  136. package/dist/wagmi/Actions/dex.js +1023 -0
  137. package/dist/wagmi/Actions/dex.js.map +1 -0
  138. package/dist/wagmi/Actions/fee.d.ts +111 -0
  139. package/dist/wagmi/Actions/fee.d.ts.map +1 -0
  140. package/dist/wagmi/Actions/fee.js +126 -0
  141. package/dist/wagmi/Actions/fee.js.map +1 -0
  142. package/dist/wagmi/Actions/index.d.ts +6 -0
  143. package/dist/wagmi/Actions/index.d.ts.map +1 -0
  144. package/dist/wagmi/Actions/index.js +6 -0
  145. package/dist/wagmi/Actions/index.js.map +1 -0
  146. package/dist/wagmi/Actions/reward.d.ts +348 -0
  147. package/dist/wagmi/Actions/reward.d.ts.map +1 -0
  148. package/dist/wagmi/Actions/reward.js +388 -0
  149. package/dist/wagmi/Actions/reward.js.map +1 -0
  150. package/dist/wagmi/Actions/token.d.ts +1546 -0
  151. package/dist/wagmi/Actions/token.d.ts.map +1 -0
  152. package/dist/wagmi/Actions/token.js +1712 -0
  153. package/dist/wagmi/Actions/token.js.map +1 -0
  154. package/dist/wagmi/Connector.d.ts +73 -0
  155. package/dist/wagmi/Connector.d.ts.map +1 -0
  156. package/dist/wagmi/Connector.js +249 -0
  157. package/dist/wagmi/Connector.js.map +1 -0
  158. package/dist/wagmi/Hooks/amm.d.ts +421 -0
  159. package/dist/wagmi/Hooks/amm.d.ts.map +1 -0
  160. package/dist/wagmi/Hooks/amm.js +504 -0
  161. package/dist/wagmi/Hooks/amm.js.map +1 -0
  162. package/dist/wagmi/Hooks/dex.d.ts +816 -0
  163. package/dist/wagmi/Hooks/dex.d.ts.map +1 -0
  164. package/dist/wagmi/Hooks/dex.js +973 -0
  165. package/dist/wagmi/Hooks/dex.js.map +1 -0
  166. package/dist/wagmi/Hooks/fee.d.ts +97 -0
  167. package/dist/wagmi/Hooks/fee.d.ts.map +1 -0
  168. package/dist/wagmi/Hooks/fee.js +109 -0
  169. package/dist/wagmi/Hooks/fee.js.map +1 -0
  170. package/dist/wagmi/Hooks/index.d.ts +6 -0
  171. package/dist/wagmi/Hooks/index.d.ts.map +1 -0
  172. package/dist/wagmi/Hooks/index.js +6 -0
  173. package/dist/wagmi/Hooks/index.js.map +1 -0
  174. package/dist/wagmi/Hooks/reward.d.ts +307 -0
  175. package/dist/wagmi/Hooks/reward.d.ts.map +1 -0
  176. package/dist/wagmi/Hooks/reward.js +349 -0
  177. package/dist/wagmi/Hooks/reward.js.map +1 -0
  178. package/dist/wagmi/Hooks/token.d.ts +1388 -0
  179. package/dist/wagmi/Hooks/token.d.ts.map +1 -0
  180. package/dist/wagmi/Hooks/token.js +1657 -0
  181. package/dist/wagmi/Hooks/token.js.map +1 -0
  182. package/dist/wagmi/index.d.ts +4 -0
  183. package/dist/wagmi/index.d.ts.map +1 -0
  184. package/dist/wagmi/index.js +4 -0
  185. package/dist/wagmi/index.js.map +1 -0
  186. package/package.json +54 -10
  187. package/src/chains.ts +19 -9
  188. package/src/ox/Order.test.ts +78 -0
  189. package/src/ox/Order.ts +125 -0
  190. package/src/ox/OrdersFilters.test.ts +182 -0
  191. package/src/ox/OrdersFilters.ts +125 -0
  192. package/src/ox/Pagination.test.ts +162 -0
  193. package/src/ox/Pagination.ts +164 -0
  194. package/src/ox/PoolId.test.ts +33 -0
  195. package/src/ox/PoolId.ts +27 -0
  196. package/src/ox/RpcSchema.ts +35 -0
  197. package/src/ox/SignatureEnvelope.ts +3 -1
  198. package/src/{viem → ox}/Tick.test.ts +1 -1
  199. package/src/{viem → ox}/Tick.ts +5 -0
  200. package/src/ox/Transaction.test.ts +1 -1
  201. package/src/ox/Transaction.ts +2 -1
  202. package/src/ox/TransactionEnvelopeAA.test.ts +239 -96
  203. package/src/ox/TransactionEnvelopeAA.ts +9 -7
  204. package/src/ox/TransactionRequest.ts +4 -0
  205. package/src/ox/index.ts +6 -0
  206. package/src/prool/Instance.ts +51 -37
  207. package/src/prool/internal/chain.json +104 -52
  208. package/src/tsconfig.json +9 -0
  209. package/src/viem/Abis.ts +972 -710
  210. package/src/viem/Account.ts +279 -0
  211. package/src/viem/Actions/__snapshots__/dex.test.ts.snap +850 -0
  212. package/src/viem/Actions/amm.test.ts +98 -169
  213. package/src/viem/Actions/amm.ts +68 -155
  214. package/src/viem/Actions/dex.test.ts +563 -484
  215. package/src/viem/Actions/dex.ts +173 -0
  216. package/src/viem/Actions/fee.test.ts +23 -34
  217. package/src/viem/Actions/fee.ts +7 -0
  218. package/src/viem/Actions/index.ts +1 -0
  219. package/src/viem/Actions/policy.test.ts +19 -33
  220. package/src/viem/Actions/reward.test.ts +457 -0
  221. package/src/viem/Actions/reward.ts +999 -0
  222. package/src/viem/Actions/token.test.ts +453 -287
  223. package/src/viem/Actions/token.ts +452 -540
  224. package/src/viem/Addresses.ts +1 -2
  225. package/src/viem/Chain.ts +70 -20
  226. package/src/viem/Decorator.test.ts +2 -1
  227. package/src/viem/Decorator.ts +996 -421
  228. package/src/viem/Formatters.ts +31 -5
  229. package/src/viem/P256.ts +1 -0
  230. package/src/viem/Secp256k1.ts +1 -0
  231. package/src/viem/TokenIds.ts +1 -2
  232. package/src/viem/Transaction.ts +53 -7
  233. package/src/viem/WebAuthnP256.ts +140 -0
  234. package/src/viem/WebCryptoP256.ts +1 -0
  235. package/src/viem/e2e.test.ts +1126 -297
  236. package/src/viem/index.ts +6 -3
  237. package/src/viem/internal/account.ts +107 -0
  238. package/src/viem/internal/types.ts +9 -0
  239. package/src/wagmi/Actions/__snapshots__/dex.test.ts.snap +310 -0
  240. package/src/wagmi/Actions/amm.test.ts +198 -0
  241. package/src/wagmi/Actions/amm.ts +691 -0
  242. package/src/wagmi/Actions/dex.test.ts +1507 -0
  243. package/src/wagmi/Actions/dex.ts +1640 -0
  244. package/src/wagmi/Actions/fee.test.ts +63 -0
  245. package/src/wagmi/Actions/fee.ts +208 -0
  246. package/src/wagmi/Actions/index.ts +5 -0
  247. package/src/wagmi/Actions/reward.test.ts +210 -0
  248. package/src/wagmi/Actions/reward.ts +632 -0
  249. package/src/wagmi/Actions/token.test.ts +1308 -0
  250. package/src/wagmi/Actions/token.ts +2613 -0
  251. package/src/wagmi/Connector.test.ts +53 -0
  252. package/src/wagmi/Connector.ts +367 -0
  253. package/src/wagmi/Hooks/__snapshots__/dex.test.ts.snap +457 -0
  254. package/src/wagmi/Hooks/amm.test.ts +424 -0
  255. package/src/wagmi/Hooks/amm.ts +806 -0
  256. package/src/wagmi/Hooks/dex.test.ts +1017 -0
  257. package/src/wagmi/Hooks/dex.ts +1685 -0
  258. package/src/wagmi/Hooks/fee.test.ts +166 -0
  259. package/src/wagmi/Hooks/fee.ts +206 -0
  260. package/src/wagmi/Hooks/index.ts +5 -0
  261. package/src/wagmi/Hooks/reward.test.ts +219 -0
  262. package/src/wagmi/Hooks/reward.ts +672 -0
  263. package/src/wagmi/Hooks/token.test.ts +1670 -0
  264. package/src/wagmi/Hooks/token.ts +2906 -0
  265. package/src/wagmi/index.ts +3 -0
  266. package/src/wagmi/internal/types.ts +16 -0
  267. package/dist/viem/Client.d.ts +0 -27
  268. package/dist/viem/Client.d.ts.map +0 -1
  269. package/dist/viem/Client.js +0 -28
  270. package/dist/viem/Client.js.map +0 -1
  271. package/dist/viem/Tick.d.ts.map +0 -1
  272. package/dist/viem/Tick.js.map +0 -1
  273. package/src/viem/Client.bench-d.ts +0 -8
  274. package/src/viem/Client.test.ts +0 -178
  275. package/src/viem/Client.ts +0 -91
  276. /package/dist/{viem → ox}/Tick.js +0 -0
@@ -7,6 +7,7 @@ import {
7
7
  type GetEventArgs,
8
8
  type Hex,
9
9
  type Log,
10
+ type MulticallParameters,
10
11
  parseEventLogs,
11
12
  type ReadContractReturnType,
12
13
  type TransactionReceipt,
@@ -16,86 +17,20 @@ import {
16
17
  type WriteContractReturnType,
17
18
  } from 'viem'
18
19
  import {
20
+ multicall,
19
21
  readContract,
20
22
  watchContractEvent,
21
23
  writeContract,
22
24
  writeContractSync,
23
25
  } from 'viem/actions'
24
- import type { Compute, UnionOmit } from '../../internal/types.js'
26
+ import type { Compute, OneOf, UnionOmit } from '../../internal/types.js'
27
+ import * as PoolId from '../../ox/PoolId.js'
25
28
  import * as TokenId from '../../ox/TokenId.js'
26
29
  import * as Abis from '../Abis.js'
27
30
  import * as Addresses from '../Addresses.js'
28
31
  import type { ReadParameters, WriteParameters } from '../internal/types.js'
29
32
  import { defineCall } from '../internal/utils.js'
30
33
 
31
- /**
32
- * Gets the pool ID for a token pair.
33
- *
34
- * @example
35
- * ```ts
36
- * import { createClient, http } from 'viem'
37
- * import { tempo } from 'tempo.ts/chains'
38
- * import * as actions from 'tempo.ts/viem/actions'
39
- *
40
- * const client = createClient({
41
- * chain: tempo,
42
- * transport: http(),
43
- * })
44
- *
45
- * const poolId = await actions.amm.getPoolId(client, {
46
- * userToken: '0x...',
47
- * validatorToken: '0x...',
48
- * })
49
- * ```
50
- *
51
- * @param client - Client.
52
- * @param parameters - Parameters.
53
- * @returns The pool ID.
54
- */
55
- export async function getPoolId<chain extends Chain | undefined>(
56
- client: Client<Transport, chain>,
57
- parameters: getPoolId.Parameters,
58
- ): Promise<getPoolId.ReturnValue> {
59
- const { userToken, validatorToken, ...rest } = parameters
60
- return readContract(client, {
61
- ...rest,
62
- ...getPoolId.call({ userToken, validatorToken }),
63
- })
64
- }
65
-
66
- export namespace getPoolId {
67
- export type Parameters = ReadParameters & Args
68
-
69
- export type Args = {
70
- /** Address or ID of the user token. */
71
- userToken: TokenId.TokenIdOrAddress
72
- /** Address or ID of the validator token. */
73
- validatorToken: TokenId.TokenIdOrAddress
74
- }
75
-
76
- export type ReturnValue = ReadContractReturnType<
77
- typeof Abis.feeAmm,
78
- 'getPoolId',
79
- never
80
- >
81
-
82
- /**
83
- * Defines a call to the `getPoolId` function.
84
- *
85
- * @param args - Arguments.
86
- * @returns The call.
87
- */
88
- export function call(args: Args) {
89
- const { userToken, validatorToken } = args
90
- return defineCall({
91
- address: Addresses.feeManager,
92
- abi: Abis.feeAmm,
93
- args: [TokenId.toAddress(userToken), TokenId.toAddress(validatorToken)],
94
- functionName: 'getPoolId',
95
- })
96
- }
97
- }
98
-
99
34
  /**
100
35
  * Gets the reserves for a liquidity pool.
101
36
  *
@@ -125,14 +60,25 @@ export async function getPool<chain extends Chain | undefined>(
125
60
  parameters: getPool.Parameters,
126
61
  ): Promise<getPool.ReturnValue> {
127
62
  const { userToken, validatorToken, ...rest } = parameters
128
- return readContract(client, {
63
+ const [pool, totalSupply] = await multicall(client, {
129
64
  ...rest,
130
- ...getPool.call({ userToken, validatorToken }),
65
+ contracts: getPool.calls({ userToken, validatorToken }),
66
+ allowFailure: false,
67
+ deployless: true,
131
68
  })
69
+ return {
70
+ reserveUserToken: pool.reserveUserToken,
71
+ reserveValidatorToken: pool.reserveValidatorToken,
72
+ totalSupply,
73
+ }
132
74
  }
133
75
 
134
76
  export namespace getPool {
135
- export type Parameters = ReadParameters & Args
77
+ export type Parameters = UnionOmit<
78
+ MulticallParameters,
79
+ 'allowFailure' | 'contracts' | 'deployless'
80
+ > &
81
+ Args
136
82
 
137
83
  export type Args = {
138
84
  /** Address or ID of the user token. */
@@ -146,90 +92,32 @@ export namespace getPool {
146
92
  reserveUserToken: bigint
147
93
  /** Reserve of validator token. */
148
94
  reserveValidatorToken: bigint
95
+ /** Total supply of LP tokens. */
96
+ totalSupply: bigint
149
97
  }>
150
98
 
151
99
  /**
152
- * Defines a call to the `getPool` function.
100
+ * Defines calls to the `getPool` and `totalSupply` functions.
153
101
  *
154
102
  * @param args - Arguments.
155
- * @returns The call.
103
+ * @returns The calls.
156
104
  */
157
- export function call(args: Args) {
105
+ export function calls(args: Args) {
158
106
  const { userToken, validatorToken } = args
159
- return defineCall({
160
- address: Addresses.feeManager,
161
- abi: Abis.feeAmm,
162
- args: [TokenId.toAddress(userToken), TokenId.toAddress(validatorToken)],
163
- functionName: 'getPool',
164
- })
165
- }
166
- }
167
-
168
- /**
169
- * Gets the total supply of LP tokens for a pool.
170
- *
171
- * @example
172
- * ```ts
173
- * import { createClient, http } from 'viem'
174
- * import { tempo } from 'tempo.ts/chains'
175
- * import * as actions from 'tempo.ts/viem/actions'
176
- *
177
- * const client = createClient({
178
- * chain: tempo,
179
- * transport: http(),
180
- * })
181
- *
182
- * const poolId = await actions.amm.getPoolId(client, {
183
- * userToken: '0x...',
184
- * validatorToken: '0x...',
185
- * })
186
- *
187
- * const totalSupply = await actions.amm.getTotalSupply(client, { poolId })
188
- * ```
189
- *
190
- * @param client - Client.
191
- * @param parameters - Parameters.
192
- * @returns The total supply of LP tokens.
193
- */
194
- export async function getTotalSupply<chain extends Chain | undefined>(
195
- client: Client<Transport, chain>,
196
- parameters: getTotalSupply.Parameters,
197
- ): Promise<getTotalSupply.ReturnValue> {
198
- const { poolId, ...rest } = parameters
199
- return readContract(client, {
200
- ...rest,
201
- ...getTotalSupply.call({ poolId }),
202
- })
203
- }
204
-
205
- export namespace getTotalSupply {
206
- export type Parameters = ReadParameters & Args
207
-
208
- export type Args = {
209
- /** Pool ID. */
210
- poolId: Hex
211
- }
212
-
213
- export type ReturnValue = ReadContractReturnType<
214
- typeof Abis.feeAmm,
215
- 'totalSupply',
216
- never
217
- >
218
-
219
- /**
220
- * Defines a call to the `totalSupply` function.
221
- *
222
- * @param args - Arguments.
223
- * @returns The call.
224
- */
225
- export function call(args: Args) {
226
- const { poolId } = args
227
- return defineCall({
228
- address: Addresses.feeManager,
229
- abi: Abis.feeAmm,
230
- args: [poolId],
231
- functionName: 'totalSupply',
232
- })
107
+ return [
108
+ defineCall({
109
+ address: Addresses.feeManager,
110
+ abi: Abis.feeAmm,
111
+ args: [TokenId.toAddress(userToken), TokenId.toAddress(validatorToken)],
112
+ functionName: 'getPool',
113
+ }),
114
+ defineCall({
115
+ address: Addresses.feeManager,
116
+ abi: Abis.feeAmm,
117
+ args: [PoolId.from({ userToken, validatorToken })],
118
+ functionName: 'totalSupply',
119
+ }),
120
+ ] as const
233
121
  }
234
122
  }
235
123
 
@@ -266,10 +154,15 @@ export async function getLiquidityBalance<chain extends Chain | undefined>(
266
154
  client: Client<Transport, chain>,
267
155
  parameters: getLiquidityBalance.Parameters,
268
156
  ): Promise<getLiquidityBalance.ReturnValue> {
269
- const { address, poolId, ...rest } = parameters
157
+ const { address, poolId, userToken, validatorToken, ...rest } = parameters
270
158
  return readContract(client, {
271
159
  ...rest,
272
- ...getLiquidityBalance.call({ address, poolId }),
160
+ ...getLiquidityBalance.call({
161
+ address,
162
+ poolId,
163
+ userToken,
164
+ validatorToken,
165
+ } as never),
273
166
  })
274
167
  }
275
168
 
@@ -279,9 +172,18 @@ export namespace getLiquidityBalance {
279
172
  export type Args = {
280
173
  /** Address to check balance for. */
281
174
  address: Address
282
- /** Pool ID. */
283
- poolId: Hex
284
- }
175
+ } & OneOf<
176
+ | {
177
+ /** Pool ID. */
178
+ poolId: Hex
179
+ }
180
+ | {
181
+ /** User token. */
182
+ userToken: TokenId.TokenIdOrAddress
183
+ /** Validator token. */
184
+ validatorToken: TokenId.TokenIdOrAddress
185
+ }
186
+ >
285
187
 
286
188
  export type ReturnValue = ReadContractReturnType<
287
189
  typeof Abis.feeAmm,
@@ -296,7 +198,18 @@ export namespace getLiquidityBalance {
296
198
  * @returns The call.
297
199
  */
298
200
  export function call(args: Args) {
299
- const { address, poolId } = args
201
+ const { address } = args
202
+ const poolId = (() => {
203
+ if ('poolId' in args && args.poolId) return args.poolId!
204
+ if ('userToken' in args && 'validatorToken' in args)
205
+ return PoolId.from({
206
+ userToken: args.userToken,
207
+ validatorToken: args.validatorToken,
208
+ })
209
+ throw new Error(
210
+ '`poolId`, or `userToken` and `validatorToken` must be provided.',
211
+ )
212
+ })()
300
213
  return defineCall({
301
214
  address: Addresses.feeManager,
302
215
  abi: Abis.feeAmm,