tempo.ts 0.11.0 → 0.12.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 (196) hide show
  1. package/CHANGELOG.md +67 -4
  2. package/README.md +3 -34
  3. package/dist/server/Handler.d.ts +14 -14
  4. package/dist/server/Handler.d.ts.map +1 -1
  5. package/dist/server/Handler.js +16 -17
  6. package/dist/server/Handler.js.map +1 -1
  7. package/dist/wagmi/Actions/amm.d.ts +51 -51
  8. package/dist/wagmi/Actions/amm.d.ts.map +1 -1
  9. package/dist/wagmi/Actions/amm.js +37 -37
  10. package/dist/wagmi/Actions/amm.js.map +1 -1
  11. package/dist/wagmi/Actions/dex.d.ts +129 -129
  12. package/dist/wagmi/Actions/dex.d.ts.map +1 -1
  13. package/dist/wagmi/Actions/dex.js +73 -73
  14. package/dist/wagmi/Actions/dex.js.map +1 -1
  15. package/dist/wagmi/Actions/faucet.d.ts +9 -9
  16. package/dist/wagmi/Actions/faucet.d.ts.map +1 -1
  17. package/dist/wagmi/Actions/faucet.js +7 -7
  18. package/dist/wagmi/Actions/faucet.js.map +1 -1
  19. package/dist/wagmi/Actions/fee.d.ts +17 -17
  20. package/dist/wagmi/Actions/fee.d.ts.map +1 -1
  21. package/dist/wagmi/Actions/fee.js +10 -10
  22. package/dist/wagmi/Actions/fee.js.map +1 -1
  23. package/dist/wagmi/Actions/nonce.d.ts +9 -79
  24. package/dist/wagmi/Actions/nonce.d.ts.map +1 -1
  25. package/dist/wagmi/Actions/nonce.js +7 -89
  26. package/dist/wagmi/Actions/nonce.js.map +1 -1
  27. package/dist/wagmi/Actions/policy.d.ts +69 -70
  28. package/dist/wagmi/Actions/policy.d.ts.map +1 -1
  29. package/dist/wagmi/Actions/policy.js +43 -43
  30. package/dist/wagmi/Actions/policy.js.map +1 -1
  31. package/dist/wagmi/Actions/reward.d.ts +51 -51
  32. package/dist/wagmi/Actions/reward.d.ts.map +1 -1
  33. package/dist/wagmi/Actions/reward.js +31 -31
  34. package/dist/wagmi/Actions/reward.js.map +1 -1
  35. package/dist/wagmi/Actions/token.d.ts +238 -238
  36. package/dist/wagmi/Actions/token.d.ts.map +1 -1
  37. package/dist/wagmi/Actions/token.js +136 -136
  38. package/dist/wagmi/Actions/token.js.map +1 -1
  39. package/dist/wagmi/Connector.d.ts +2 -1
  40. package/dist/wagmi/Connector.d.ts.map +1 -1
  41. package/dist/wagmi/Connector.js +83 -22
  42. package/dist/wagmi/Connector.js.map +1 -1
  43. package/dist/wagmi/Hooks/nonce.d.ts +1 -52
  44. package/dist/wagmi/Hooks/nonce.d.ts.map +1 -1
  45. package/dist/wagmi/Hooks/nonce.js +1 -70
  46. package/dist/wagmi/Hooks/nonce.js.map +1 -1
  47. package/dist/wagmi/Hooks/policy.d.ts +0 -1
  48. package/dist/wagmi/Hooks/policy.d.ts.map +1 -1
  49. package/dist/wagmi/Hooks/policy.js.map +1 -1
  50. package/dist/wagmi/KeyManager.d.ts +6 -3
  51. package/dist/wagmi/KeyManager.d.ts.map +1 -1
  52. package/dist/wagmi/KeyManager.js +9 -4
  53. package/dist/wagmi/KeyManager.js.map +1 -1
  54. package/package.json +2 -2
  55. package/src/server/Handler.test.ts +2 -2
  56. package/src/server/Handler.ts +16 -17
  57. package/src/wagmi/Actions/amm.ts +63 -63
  58. package/src/wagmi/Actions/dex.test.ts +1 -1
  59. package/src/wagmi/Actions/dex.ts +153 -153
  60. package/src/wagmi/Actions/faucet.ts +11 -11
  61. package/src/wagmi/Actions/fee.ts +20 -20
  62. package/src/wagmi/Actions/nonce.test.ts +1 -64
  63. package/src/wagmi/Actions/nonce.ts +10 -142
  64. package/src/wagmi/Actions/policy.ts +83 -85
  65. package/src/wagmi/Actions/reward.ts +64 -61
  66. package/src/wagmi/Actions/token.ts +287 -283
  67. package/src/wagmi/Connector.ts +105 -31
  68. package/src/wagmi/Hooks/dex.test.ts +1 -1
  69. package/src/wagmi/Hooks/fee.test.ts +0 -6
  70. package/src/wagmi/Hooks/nonce.test.ts +1 -66
  71. package/src/wagmi/Hooks/nonce.ts +1 -114
  72. package/src/wagmi/Hooks/policy.ts +0 -2
  73. package/src/wagmi/KeyManager.ts +18 -5
  74. package/dist/viem/Abis.d.ts +0 -2649
  75. package/dist/viem/Abis.d.ts.map +0 -1
  76. package/dist/viem/Abis.js +0 -1677
  77. package/dist/viem/Abis.js.map +0 -1
  78. package/dist/viem/Account.d.ts +0 -244
  79. package/dist/viem/Account.d.ts.map +0 -1
  80. package/dist/viem/Account.js +0 -382
  81. package/dist/viem/Account.js.map +0 -1
  82. package/dist/viem/Actions/amm.d.ts +0 -1991
  83. package/dist/viem/Actions/amm.d.ts.map +0 -1
  84. package/dist/viem/Actions/amm.js +0 -814
  85. package/dist/viem/Actions/amm.js.map +0 -1
  86. package/dist/viem/Actions/dex.d.ts +0 -3900
  87. package/dist/viem/Actions/dex.d.ts.map +0 -1
  88. package/dist/viem/Actions/dex.js +0 -1414
  89. package/dist/viem/Actions/dex.js.map +0 -1
  90. package/dist/viem/Actions/faucet.d.ts +0 -69
  91. package/dist/viem/Actions/faucet.d.ts.map +0 -1
  92. package/dist/viem/Actions/faucet.js +0 -73
  93. package/dist/viem/Actions/faucet.js.map +0 -1
  94. package/dist/viem/Actions/fee.d.ts +0 -360
  95. package/dist/viem/Actions/fee.d.ts.map +0 -1
  96. package/dist/viem/Actions/fee.js +0 -237
  97. package/dist/viem/Actions/fee.js.map +0 -1
  98. package/dist/viem/Actions/nonce.d.ts +0 -257
  99. package/dist/viem/Actions/nonce.d.ts.map +0 -1
  100. package/dist/viem/Actions/nonce.js +0 -228
  101. package/dist/viem/Actions/nonce.js.map +0 -1
  102. package/dist/viem/Actions/policy.d.ts +0 -1680
  103. package/dist/viem/Actions/policy.d.ts.map +0 -1
  104. package/dist/viem/Actions/policy.js +0 -875
  105. package/dist/viem/Actions/policy.js.map +0 -1
  106. package/dist/viem/Actions/reward.d.ts +0 -2422
  107. package/dist/viem/Actions/reward.d.ts.map +0 -1
  108. package/dist/viem/Actions/reward.js +0 -651
  109. package/dist/viem/Actions/reward.js.map +0 -1
  110. package/dist/viem/Actions/token.d.ts +0 -16007
  111. package/dist/viem/Actions/token.d.ts.map +0 -1
  112. package/dist/viem/Actions/token.js +0 -2936
  113. package/dist/viem/Actions/token.js.map +0 -1
  114. package/dist/viem/Addresses.d.ts +0 -9
  115. package/dist/viem/Addresses.d.ts.map +0 -1
  116. package/dist/viem/Addresses.js +0 -9
  117. package/dist/viem/Addresses.js.map +0 -1
  118. package/dist/viem/Chain.d.ts +0 -451
  119. package/dist/viem/Chain.d.ts.map +0 -1
  120. package/dist/viem/Chain.js +0 -96
  121. package/dist/viem/Chain.js.map +0 -1
  122. package/dist/viem/Formatters.d.ts +0 -10
  123. package/dist/viem/Formatters.d.ts.map +0 -1
  124. package/dist/viem/Formatters.js +0 -104
  125. package/dist/viem/Formatters.js.map +0 -1
  126. package/dist/viem/Storage.d.ts +0 -24
  127. package/dist/viem/Storage.d.ts.map +0 -1
  128. package/dist/viem/Storage.js +0 -68
  129. package/dist/viem/Storage.js.map +0 -1
  130. package/dist/viem/Transaction.d.ts +0 -76
  131. package/dist/viem/Transaction.d.ts.map +0 -1
  132. package/dist/viem/Transaction.js +0 -176
  133. package/dist/viem/Transaction.js.map +0 -1
  134. package/dist/viem/Transport.d.ts +0 -33
  135. package/dist/viem/Transport.d.ts.map +0 -1
  136. package/dist/viem/Transport.js +0 -138
  137. package/dist/viem/Transport.js.map +0 -1
  138. package/dist/viem/WebAuthnP256.d.ts +0 -82
  139. package/dist/viem/WebAuthnP256.d.ts.map +0 -1
  140. package/dist/viem/WebAuthnP256.js +0 -97
  141. package/dist/viem/WebAuthnP256.js.map +0 -1
  142. package/dist/viem/WebCryptoP256.d.ts +0 -2
  143. package/dist/viem/WebCryptoP256.d.ts.map +0 -1
  144. package/dist/viem/WebCryptoP256.js +0 -2
  145. package/dist/viem/WebCryptoP256.js.map +0 -1
  146. package/dist/viem/internal/types.d.ts +0 -20
  147. package/dist/viem/internal/types.d.ts.map +0 -1
  148. package/dist/viem/internal/types.js +0 -2
  149. package/dist/viem/internal/types.js.map +0 -1
  150. package/dist/viem/internal/utils.d.ts +0 -14
  151. package/dist/viem/internal/utils.d.ts.map +0 -1
  152. package/dist/viem/internal/utils.js +0 -33
  153. package/dist/viem/internal/utils.js.map +0 -1
  154. package/src/chains.ts +0 -54
  155. package/src/viem/Abis.ts +0 -1688
  156. package/src/viem/Account.test.ts +0 -444
  157. package/src/viem/Account.ts +0 -601
  158. package/src/viem/Actions/account.test.ts +0 -414
  159. package/src/viem/Actions/account.ts +0 -106
  160. package/src/viem/Actions/amm.test.ts +0 -381
  161. package/src/viem/Actions/amm.ts +0 -1227
  162. package/src/viem/Actions/dex.test.ts +0 -1549
  163. package/src/viem/Actions/dex.ts +0 -2150
  164. package/src/viem/Actions/faucet.ts +0 -121
  165. package/src/viem/Actions/fee.test.ts +0 -259
  166. package/src/viem/Actions/fee.ts +0 -372
  167. package/src/viem/Actions/index.ts +0 -9
  168. package/src/viem/Actions/nonce.test.ts +0 -206
  169. package/src/viem/Actions/nonce.ts +0 -347
  170. package/src/viem/Actions/policy.test.ts +0 -534
  171. package/src/viem/Actions/policy.ts +0 -1335
  172. package/src/viem/Actions/reward.test.ts +0 -434
  173. package/src/viem/Actions/reward.ts +0 -944
  174. package/src/viem/Actions/token.test.ts +0 -3029
  175. package/src/viem/Actions/token.ts +0 -4458
  176. package/src/viem/Addresses.ts +0 -9
  177. package/src/viem/Chain.bench-d.ts +0 -12
  178. package/src/viem/Chain.test.ts +0 -168
  179. package/src/viem/Chain.ts +0 -157
  180. package/src/viem/Decorator.bench-d.ts +0 -11
  181. package/src/viem/Decorator.test.ts +0 -39
  182. package/src/viem/Decorator.ts +0 -3179
  183. package/src/viem/Formatters.ts +0 -164
  184. package/src/viem/P256.ts +0 -1
  185. package/src/viem/Secp256k1.ts +0 -1
  186. package/src/viem/Storage.ts +0 -110
  187. package/src/viem/TokenIds.ts +0 -1
  188. package/src/viem/Transaction.ts +0 -382
  189. package/src/viem/Transport.ts +0 -191
  190. package/src/viem/WebAuthnP256.ts +0 -146
  191. package/src/viem/WebCryptoP256.ts +0 -1
  192. package/src/viem/e2e.test.ts +0 -1602
  193. package/src/viem/index.ts +0 -30
  194. package/src/viem/internal/types.ts +0 -69
  195. package/src/viem/internal/utils.ts +0 -58
  196. package/src/wagmi/internal/types.ts +0 -16
@@ -1,814 +0,0 @@
1
- import { PoolId, TokenId } from 'ox/tempo';
2
- import { parseEventLogs, } from 'viem';
3
- import { multicall, readContract, watchContractEvent, writeContract, writeContractSync, } from 'viem/actions';
4
- import * as Abis from '../Abis.js';
5
- import * as Addresses from '../Addresses.js';
6
- import { defineCall } from '../internal/utils.js';
7
- /**
8
- * Gets the reserves for a liquidity pool.
9
- *
10
- * @example
11
- * ```ts
12
- * import { createClient, http } from 'viem'
13
- * import { tempo } from 'tempo.ts/chains'
14
- * import { Actions } from 'tempo.ts/viem'
15
- *
16
- * const client = createClient({
17
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
18
- * transport: http(),
19
- * })
20
- *
21
- * const pool = await Actions.amm.getPool(client, {
22
- * userToken: '0x...',
23
- * validatorToken: '0x...',
24
- * })
25
- * ```
26
- *
27
- * @param client - Client.
28
- * @param parameters - Parameters.
29
- * @returns The pool reserves.
30
- */
31
- export async function getPool(client, parameters) {
32
- const { userToken, validatorToken, ...rest } = parameters;
33
- const [pool, totalSupply] = await multicall(client, {
34
- ...rest,
35
- contracts: getPool.calls({ userToken, validatorToken }),
36
- allowFailure: false,
37
- deployless: true,
38
- });
39
- return {
40
- reserveUserToken: pool.reserveUserToken,
41
- reserveValidatorToken: pool.reserveValidatorToken,
42
- totalSupply,
43
- };
44
- }
45
- (function (getPool) {
46
- /**
47
- * Defines calls to the `getPool` and `totalSupply` functions.
48
- *
49
- * @param args - Arguments.
50
- * @returns The calls.
51
- */
52
- function calls(args) {
53
- const { userToken, validatorToken } = args;
54
- return [
55
- defineCall({
56
- address: Addresses.feeManager,
57
- abi: Abis.feeAmm,
58
- args: [TokenId.toAddress(userToken), TokenId.toAddress(validatorToken)],
59
- functionName: 'getPool',
60
- }),
61
- defineCall({
62
- address: Addresses.feeManager,
63
- abi: Abis.feeAmm,
64
- args: [PoolId.from({ userToken, validatorToken })],
65
- functionName: 'totalSupply',
66
- }),
67
- ];
68
- }
69
- getPool.calls = calls;
70
- })(getPool || (getPool = {}));
71
- /**
72
- * Gets the LP token balance for an account in a specific pool.
73
- *
74
- * @example
75
- * ```ts
76
- * import { createClient, http } from 'viem'
77
- * import { tempo } from 'tempo.ts/chains'
78
- * import { Actions } from 'tempo.ts/viem'
79
- *
80
- * const client = createClient({
81
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
82
- * transport: http(),
83
- * })
84
- *
85
- * const poolId = await Actions.amm.getPoolId(client, {
86
- * userToken: '0x...',
87
- * validatorToken: '0x...',
88
- * })
89
- *
90
- * const balance = await Actions.amm.getLiquidityBalance(client, {
91
- * poolId,
92
- * address: '0x...',
93
- * })
94
- * ```
95
- *
96
- * @param client - Client.
97
- * @param parameters - Parameters.
98
- * @returns The LP token balance.
99
- */
100
- export async function getLiquidityBalance(client, parameters) {
101
- const { address, poolId, userToken, validatorToken, ...rest } = parameters;
102
- return readContract(client, {
103
- ...rest,
104
- ...getLiquidityBalance.call({
105
- address,
106
- poolId,
107
- userToken,
108
- validatorToken,
109
- }),
110
- });
111
- }
112
- (function (getLiquidityBalance) {
113
- /**
114
- * Defines a call to the `liquidityBalances` function.
115
- *
116
- * @param args - Arguments.
117
- * @returns The call.
118
- */
119
- function call(args) {
120
- const { address } = args;
121
- const poolId = (() => {
122
- if ('poolId' in args && args.poolId)
123
- return args.poolId;
124
- if ('userToken' in args && 'validatorToken' in args)
125
- return PoolId.from({
126
- userToken: args.userToken,
127
- validatorToken: args.validatorToken,
128
- });
129
- throw new Error('`poolId`, or `userToken` and `validatorToken` must be provided.');
130
- })();
131
- return defineCall({
132
- address: Addresses.feeManager,
133
- abi: Abis.feeAmm,
134
- args: [poolId, address],
135
- functionName: 'liquidityBalances',
136
- });
137
- }
138
- getLiquidityBalance.call = call;
139
- })(getLiquidityBalance || (getLiquidityBalance = {}));
140
- /**
141
- * Performs a rebalance swap from validator token to user token.
142
- *
143
- * @example
144
- * ```ts
145
- * import { createClient, http } from 'viem'
146
- * import { tempo } from 'tempo.ts/chains'
147
- * import { Actions } from 'tempo.ts/viem'
148
- * import { privateKeyToAccount } from 'viem/accounts'
149
- *
150
- * const client = createClient({
151
- * account: privateKeyToAccount('0x...'),
152
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
153
- * transport: http(),
154
- * })
155
- *
156
- * const hash = await Actions.amm.rebalanceSwap(client, {
157
- * userToken: '0x...',
158
- * validatorToken: '0x...',
159
- * amountOut: 100n,
160
- * to: '0x...',
161
- * })
162
- * ```
163
- *
164
- * @param client - Client.
165
- * @param parameters - Parameters.
166
- * @returns The transaction hash.
167
- */
168
- export async function rebalanceSwap(client, parameters) {
169
- return rebalanceSwap.inner(writeContract, client, parameters);
170
- }
171
- (function (rebalanceSwap) {
172
- /** @internal */
173
- async function inner(action, client, parameters) {
174
- const { userToken, validatorToken, amountOut, to, ...rest } = parameters;
175
- const call = rebalanceSwap.call({
176
- userToken,
177
- validatorToken,
178
- amountOut,
179
- to,
180
- });
181
- return (await action(client, {
182
- ...rest,
183
- ...call,
184
- }));
185
- }
186
- rebalanceSwap.inner = inner;
187
- /**
188
- * Defines a call to the `rebalanceSwap` function.
189
- *
190
- * Can be passed as a parameter to:
191
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
192
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
193
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
194
- *
195
- * @example
196
- * ```ts
197
- * import { createClient, http, walletActions } from 'viem'
198
- * import { tempo } from 'tempo.ts/chains'
199
- * import { Actions } from 'tempo.ts/viem'
200
- *
201
- * const client = createClient({
202
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
203
- * transport: http(),
204
- * }).extend(walletActions)
205
- *
206
- * const { result } = await client.sendCalls({
207
- * calls: [
208
- * actions.amm.rebalanceSwap.call({
209
- * userToken: '0x20c0...beef',
210
- * validatorToken: '0x20c0...babe',
211
- * amountOut: 100n,
212
- * to: '0xfeed...fede',
213
- * }),
214
- * actions.amm.rebalanceSwap.call({
215
- * userToken: '0x20c0...babe',
216
- * validatorToken: '0x20c0...babe',
217
- * amountOut: 100n,
218
- * to: '0xfeed...fede',
219
- * }),
220
- * ]
221
- * })
222
- * ```
223
- *
224
- * @param args - Arguments.
225
- * @returns The call.
226
- */
227
- function call(args) {
228
- const { userToken, validatorToken, amountOut, to } = args;
229
- return defineCall({
230
- address: Addresses.feeManager,
231
- abi: Abis.feeAmm,
232
- functionName: 'rebalanceSwap',
233
- args: [
234
- TokenId.toAddress(userToken),
235
- TokenId.toAddress(validatorToken),
236
- amountOut,
237
- to,
238
- ],
239
- });
240
- }
241
- rebalanceSwap.call = call;
242
- /**
243
- * Extracts the `RebalanceSwap` event from logs.
244
- *
245
- * @param logs - The logs.
246
- * @returns The `RebalanceSwap` event.
247
- */
248
- function extractEvent(logs) {
249
- const [log] = parseEventLogs({
250
- abi: Abis.feeAmm,
251
- logs,
252
- eventName: 'RebalanceSwap',
253
- strict: true,
254
- });
255
- if (!log)
256
- throw new Error('`RebalanceSwap` event not found.');
257
- return log;
258
- }
259
- rebalanceSwap.extractEvent = extractEvent;
260
- })(rebalanceSwap || (rebalanceSwap = {}));
261
- /**
262
- * Performs a rebalance swap from validator token to user token.
263
- *
264
- * @example
265
- * ```ts
266
- * import { createClient, http } from 'viem'
267
- * import { tempo } from 'tempo.ts/chains'
268
- * import { Actions } from 'tempo.ts/viem'
269
- * import { privateKeyToAccount } from 'viem/accounts'
270
- *
271
- * const client = createClient({
272
- * account: privateKeyToAccount('0x...'),
273
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
274
- * transport: http(),
275
- * })
276
- *
277
- * const result = await Actions.amm.rebalanceSwapSync(client, {
278
- * userToken: '0x...',
279
- * validatorToken: '0x...',
280
- * amountOut: 100n,
281
- * to: '0x...',
282
- * })
283
- * ```
284
- *
285
- * @param client - Client.
286
- * @param parameters - Parameters.
287
- * @returns The transaction receipt and event data.
288
- */
289
- export async function rebalanceSwapSync(client, parameters) {
290
- const { throwOnReceiptRevert = true, ...rest } = parameters;
291
- const receipt = await rebalanceSwap.inner(writeContractSync, client, {
292
- ...rest,
293
- throwOnReceiptRevert,
294
- });
295
- const { args } = rebalanceSwap.extractEvent(receipt.logs);
296
- return {
297
- ...args,
298
- receipt,
299
- };
300
- }
301
- /**
302
- * Adds liquidity to a pool.
303
- *
304
- * @example
305
- * ```ts
306
- * import { createClient, http } from 'viem'
307
- * import { tempo } from 'tempo.ts/chains'
308
- * import { Actions } from 'tempo.ts/viem'
309
- * import { privateKeyToAccount } from 'viem/accounts'
310
- *
311
- * const client = createClient({
312
- * account: privateKeyToAccount('0x...'),
313
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
314
- * transport: http(),
315
- * })
316
- *
317
- * const hash = await Actions.amm.mint(client, {
318
- * userTokenAddress: '0x20c0...beef',
319
- * validatorTokenAddress: '0x20c0...babe',
320
- * validatorTokenAmount: 100n,
321
- * to: '0xfeed...fede',
322
- * })
323
- * ```
324
- *
325
- * @param client - Client.
326
- * @param parameters - Parameters.
327
- * @returns The transaction hash.
328
- */
329
- export async function mint(client, parameters) {
330
- return mint.inner(writeContract, client, parameters);
331
- }
332
- (function (mint) {
333
- /** @internal */
334
- async function inner(action, client, parameters) {
335
- const { to, userTokenAddress, validatorTokenAddress, validatorTokenAmount, ...rest } = parameters;
336
- const call = mint.call({
337
- to,
338
- userTokenAddress,
339
- validatorTokenAddress,
340
- validatorTokenAmount,
341
- });
342
- return (await action(client, {
343
- ...rest,
344
- ...call,
345
- }));
346
- }
347
- mint.inner = inner;
348
- /**
349
- * Defines a call to the `mint` function.
350
- *
351
- * Can be passed as a parameter to:
352
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
353
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
354
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
355
- *
356
- * @example
357
- * ```ts
358
- * import { createClient, http, walletActions } from 'viem'
359
- * import { tempo } from 'tempo.ts/chains'
360
- * import { Actions } from 'tempo.ts/viem'
361
- *
362
- * const client = createClient({
363
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
364
- * transport: http(),
365
- * }).extend(walletActions)
366
- *
367
- * const { result } = await client.sendCalls({
368
- * calls: [
369
- * actions.amm.mint.call({
370
- * userTokenAddress: '0x20c0...beef',
371
- * validatorTokenAddress: '0x20c0...babe',
372
- * validatorTokenAmount: 100n,
373
- * to: '0xfeed...fede',
374
- * }),
375
- * actions.amm.mint.call({
376
- * userTokenAddress: '0x20c0...babe',
377
- * validatorTokenAddress: '0x20c0...babe',
378
- * validatorTokenAmount: 100n,
379
- * to: '0xfeed...fede',
380
- * }),
381
- * ]
382
- * })
383
- * ```
384
- *
385
- * @param args - Arguments.
386
- * @returns The call.
387
- */
388
- function call(args) {
389
- const { to, userTokenAddress, validatorTokenAddress, validatorTokenAmount, } = args;
390
- return defineCall({
391
- address: Addresses.feeManager,
392
- abi: Abis.feeAmm,
393
- functionName: 'mintWithValidatorToken',
394
- args: [
395
- TokenId.toAddress(userTokenAddress),
396
- TokenId.toAddress(validatorTokenAddress),
397
- validatorTokenAmount,
398
- to,
399
- ],
400
- });
401
- }
402
- mint.call = call;
403
- /**
404
- * Extracts the `Mint` event from logs.
405
- *
406
- * @param logs - The logs.
407
- * @returns The `Mint` event.
408
- */
409
- function extractEvent(logs) {
410
- const [log] = parseEventLogs({
411
- abi: Abis.feeAmm,
412
- logs,
413
- eventName: 'Mint',
414
- strict: true,
415
- });
416
- if (!log)
417
- throw new Error('`Mint` event not found.');
418
- return log;
419
- }
420
- mint.extractEvent = extractEvent;
421
- })(mint || (mint = {}));
422
- /**
423
- * Adds liquidity to a pool.
424
- *
425
- * @example
426
- * ```ts
427
- * import { createClient, http } from 'viem'
428
- * import { tempo } from 'tempo.ts/chains'
429
- * import { Actions } from 'tempo.ts/viem'
430
- * import { privateKeyToAccount } from 'viem/accounts'
431
- *
432
- * const client = createClient({
433
- * account: privateKeyToAccount('0x...'),
434
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
435
- * transport: http(),
436
- * })
437
- *
438
- * const hash = await Actions.amm.mint(client, {
439
- * userTokenAddress: '0x20c0...beef',
440
- * validatorTokenAddress: '0x20c0...babe',
441
- * validatorTokenAmount: 100n,
442
- * to: '0xfeed...fede',
443
- * })
444
- * ```
445
- *
446
- * @param client - Client.
447
- * @param parameters - Parameters.
448
- * @returns The transaction receipt and event data.
449
- */
450
- export async function mintSync(client, parameters) {
451
- const { throwOnReceiptRevert = true, ...rest } = parameters;
452
- const receipt = await mint.inner(writeContractSync, client, {
453
- ...rest,
454
- throwOnReceiptRevert,
455
- });
456
- const { args } = mint.extractEvent(receipt.logs);
457
- return {
458
- ...args,
459
- receipt,
460
- };
461
- }
462
- /**
463
- * Removes liquidity from a pool.
464
- *
465
- * @example
466
- * ```ts
467
- * import { createClient, http } from 'viem'
468
- * import { tempo } from 'tempo.ts/chains'
469
- * import { Actions } from 'tempo.ts/viem'
470
- * import { privateKeyToAccount } from 'viem/accounts'
471
- *
472
- * const client = createClient({
473
- * account: privateKeyToAccount('0x...'),
474
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
475
- * transport: http(),
476
- * })
477
- *
478
- * const hash = await Actions.amm.burn(client, {
479
- * userToken: '0x20c0...beef',
480
- * validatorToken: '0x20c0...babe',
481
- * liquidity: 50n,
482
- * to: '0xfeed...fede',
483
- * })
484
- * ```
485
- *
486
- * @param client - Client.
487
- * @param parameters - Parameters.
488
- * @returns The transaction hash.
489
- */
490
- export async function burn(client, parameters) {
491
- return burn.inner(writeContract, client, parameters);
492
- }
493
- (function (burn) {
494
- /** @internal */
495
- async function inner(action, client, parameters) {
496
- const { liquidity, to, userToken, validatorToken, ...rest } = parameters;
497
- const call = burn.call({ liquidity, to, userToken, validatorToken });
498
- return (await action(client, {
499
- ...rest,
500
- ...call,
501
- }));
502
- }
503
- burn.inner = inner;
504
- /**
505
- * Defines a call to the `burn` function.
506
- *
507
- * Can be passed as a parameter to:
508
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
509
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
510
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
511
- *
512
- * @example
513
- * ```ts
514
- * import { createClient, http, walletActions } from 'viem'
515
- * import { tempo } from 'tempo.ts/chains'
516
- * import { Actions } from 'tempo.ts/viem'
517
- *
518
- * const client = createClient({
519
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
520
- * transport: http(),
521
- * }).extend(walletActions)
522
- *
523
- * const { result } = await client.sendCalls({
524
- * calls: [
525
- * actions.amm.burn.call({
526
- * liquidity: 100n,
527
- * to: '0xfeed...fede',
528
- * userToken: '0x20c0...beef',
529
- * validatorToken: '0x20c0...babe',
530
- * }),
531
- * actions.amm.burn.call({
532
- * liquidity: 100n,
533
- * to: '0xfeed...fede',
534
- * userToken: '0x20c0...babe',
535
- * validatorToken: '0x20c0...babe',
536
- * }),
537
- * ]
538
- * })
539
- * ```
540
- *
541
- * @param args - Arguments.
542
- * @returns The call.
543
- */
544
- function call(args) {
545
- const { liquidity, to, userToken, validatorToken } = args;
546
- return defineCall({
547
- address: Addresses.feeManager,
548
- abi: Abis.feeAmm,
549
- functionName: 'burn',
550
- args: [
551
- TokenId.toAddress(userToken),
552
- TokenId.toAddress(validatorToken),
553
- liquidity,
554
- to,
555
- ],
556
- });
557
- }
558
- burn.call = call;
559
- /**
560
- * Extracts the `Burn` event from logs.
561
- *
562
- * @param logs - The logs.
563
- * @returns The `Burn` event.
564
- */
565
- function extractEvent(logs) {
566
- const [log] = parseEventLogs({
567
- abi: Abis.feeAmm,
568
- logs,
569
- eventName: 'Burn',
570
- strict: true,
571
- });
572
- if (!log)
573
- throw new Error('`Burn` event not found.');
574
- return log;
575
- }
576
- burn.extractEvent = extractEvent;
577
- })(burn || (burn = {}));
578
- /**
579
- * Removes liquidity from a pool.
580
- *
581
- * @example
582
- * ```ts
583
- * import { createClient, http } from 'viem'
584
- * import { tempo } from 'tempo.ts/chains'
585
- * import { Actions } from 'tempo.ts/viem'
586
- * import { privateKeyToAccount } from 'viem/accounts'
587
- *
588
- * const client = createClient({
589
- * account: privateKeyToAccount('0x...'),
590
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
591
- * transport: http(),
592
- * })
593
- *
594
- * const result = await Actions.amm.burnSync(client, {
595
- * userToken: '0x20c0...beef',
596
- * validatorToken: '0x20c0...babe',
597
- * liquidity: 50n,
598
- * to: '0xfeed...fede',
599
- * })
600
- * ```
601
- *
602
- * @param client - Client.
603
- * @param parameters - Parameters.
604
- * @returns The transaction receipt and event data.
605
- */
606
- export async function burnSync(client, parameters) {
607
- const { throwOnReceiptRevert = true, ...rest } = parameters;
608
- const receipt = await burn.inner(writeContractSync, client, {
609
- ...rest,
610
- throwOnReceiptRevert,
611
- });
612
- const { args } = burn.extractEvent(receipt.logs);
613
- return {
614
- ...args,
615
- receipt,
616
- };
617
- }
618
- /**
619
- * Watches for rebalance swap events.
620
- *
621
- * @example
622
- * ```ts
623
- * import { createClient, http } from 'viem'
624
- * import { tempo } from 'tempo.ts/chains'
625
- * import { Actions } from 'tempo.ts/viem'
626
- *
627
- * const client = createClient({
628
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
629
- * transport: http(),
630
- * })
631
- *
632
- * const unwatch = actions.amm.watchRebalanceSwap(client, {
633
- * onRebalanceSwap: (args, log) => {
634
- * console.log('Rebalance swap:', args)
635
- * },
636
- * })
637
- * ```
638
- *
639
- * @param client - Client.
640
- * @param parameters - Parameters.
641
- * @returns A function to unsubscribe from the event.
642
- */
643
- export function watchRebalanceSwap(client, parameters) {
644
- const { onRebalanceSwap, userToken, validatorToken, ...rest } = parameters;
645
- return watchContractEvent(client, {
646
- ...rest,
647
- address: Addresses.feeManager,
648
- abi: Abis.feeAmm,
649
- eventName: 'RebalanceSwap',
650
- args: userToken !== undefined && validatorToken !== undefined
651
- ? {
652
- userToken: TokenId.toAddress(userToken),
653
- validatorToken: TokenId.toAddress(validatorToken),
654
- }
655
- : undefined,
656
- onLogs: (logs) => {
657
- for (const log of logs)
658
- onRebalanceSwap(log.args, log);
659
- },
660
- strict: true,
661
- });
662
- }
663
- /**
664
- * Watches for fee swap events.
665
- *
666
- * @example
667
- * ```ts
668
- * import { createClient, http } from 'viem'
669
- * import { tempo } from 'tempo.ts/chains'
670
- * import { Actions } from 'tempo.ts/viem'
671
- *
672
- * const client = createClient({
673
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
674
- * transport: http(),
675
- * })
676
- *
677
- * const unwatch = actions.amm.watchFeeSwap(client, {
678
- * onFeeSwap: (args, log) => {
679
- * console.log('Fee swap:', args)
680
- * },
681
- * })
682
- * ```
683
- *
684
- * @param client - Client.
685
- * @param parameters - Parameters.
686
- * @returns A function to unsubscribe from the event.
687
- */
688
- export function watchFeeSwap(client, parameters) {
689
- const { onFeeSwap, userToken, validatorToken, ...rest } = parameters;
690
- return watchContractEvent(client, {
691
- ...rest,
692
- address: Addresses.feeManager,
693
- abi: Abis.feeAmm,
694
- eventName: 'FeeSwap',
695
- args: userToken !== undefined && validatorToken !== undefined
696
- ? {
697
- userToken: TokenId.toAddress(userToken),
698
- validatorToken: TokenId.toAddress(validatorToken),
699
- }
700
- : undefined,
701
- onLogs: (logs) => {
702
- for (const log of logs)
703
- onFeeSwap(log.args, log);
704
- },
705
- strict: true,
706
- });
707
- }
708
- /**
709
- * Watches for liquidity mint events.
710
- *
711
- * @example
712
- * ```ts
713
- * import { createClient, http } from 'viem'
714
- * import { tempo } from 'tempo.ts/chains'
715
- * import { Actions } from 'tempo.ts/viem'
716
- *
717
- * const client = createClient({
718
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
719
- * transport: http(),
720
- * })
721
- *
722
- * const unwatch = actions.amm.watchMint(client, {
723
- * onMint: (args, log) => {
724
- * console.log('Liquidity added:', args)
725
- * },
726
- * })
727
- * ```
728
- *
729
- * @param client - Client.
730
- * @param parameters - Parameters.
731
- * @returns A function to unsubscribe from the event.
732
- */
733
- export function watchMint(client, parameters) {
734
- const { onMint, sender, userToken, validatorToken, ...rest } = parameters;
735
- return watchContractEvent(client, {
736
- ...rest,
737
- address: Addresses.feeManager,
738
- abi: Abis.feeAmm,
739
- eventName: 'Mint',
740
- args: {
741
- ...(sender !== undefined && {
742
- sender: TokenId.toAddress(sender),
743
- }),
744
- ...(userToken !== undefined && {
745
- userToken: TokenId.toAddress(userToken),
746
- }),
747
- ...(validatorToken !== undefined && {
748
- validatorToken: TokenId.toAddress(validatorToken),
749
- }),
750
- },
751
- onLogs: (logs) => {
752
- for (const log of logs)
753
- onMint({
754
- liquidity: log.args.liquidity,
755
- sender: log.args.sender,
756
- userToken: {
757
- address: log.args.userToken,
758
- amount: log.args.amountUserToken,
759
- },
760
- validatorToken: {
761
- address: log.args.validatorToken,
762
- amount: log.args.amountValidatorToken,
763
- },
764
- }, log);
765
- },
766
- strict: true,
767
- });
768
- }
769
- /**
770
- * Watches for liquidity burn events.
771
- *
772
- * @example
773
- * ```ts
774
- * import { createClient, http } from 'viem'
775
- * import { tempo } from 'tempo.ts/chains'
776
- * import { Actions } from 'tempo.ts/viem'
777
- *
778
- * const client = createClient({
779
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
780
- * transport: http(),
781
- * })
782
- *
783
- * const unwatch = actions.amm.watchBurn(client, {
784
- * onBurn: (args, log) => {
785
- * console.log('Liquidity removed:', args)
786
- * },
787
- * })
788
- * ```
789
- *
790
- * @param client - Client.
791
- * @param parameters - Parameters.
792
- * @returns A function to unsubscribe from the event.
793
- */
794
- export function watchBurn(client, parameters) {
795
- const { onBurn, userToken, validatorToken, ...rest } = parameters;
796
- return watchContractEvent(client, {
797
- ...rest,
798
- address: Addresses.feeManager,
799
- abi: Abis.feeAmm,
800
- eventName: 'Burn',
801
- args: userToken !== undefined && validatorToken !== undefined
802
- ? {
803
- userToken: TokenId.toAddress(userToken),
804
- validatorToken: TokenId.toAddress(validatorToken),
805
- }
806
- : undefined,
807
- onLogs: (logs) => {
808
- for (const log of logs)
809
- onBurn(log.args, log);
810
- },
811
- strict: true,
812
- });
813
- }
814
- //# sourceMappingURL=amm.js.map