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