tempo.ts 0.0.0 → 0.0.1
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/README.md +92 -0
- package/dist/chains.d.ts +1477 -0
- package/dist/chains.d.ts.map +1 -0
- package/dist/chains.js +43 -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/TokenId.d.ts +18 -0
- package/dist/ox/TokenId.d.ts.map +1 -0
- package/dist/ox/TokenId.js +29 -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 +161 -0
- package/dist/ox/Transaction.d.ts.map +1 -0
- package/dist/ox/Transaction.js +117 -0
- package/dist/ox/Transaction.js.map +1 -0
- package/dist/ox/TransactionEnvelopeFeeToken.d.ts +393 -0
- package/dist/ox/TransactionEnvelopeFeeToken.d.ts.map +1 -0
- package/dist/ox/TransactionEnvelopeFeeToken.js +452 -0
- package/dist/ox/TransactionEnvelopeFeeToken.js.map +1 -0
- package/dist/ox/TransactionRequest.d.ts +62 -0
- package/dist/ox/TransactionRequest.d.ts.map +1 -0
- package/dist/ox/TransactionRequest.js +66 -0
- package/dist/ox/TransactionRequest.js.map +1 -0
- package/dist/ox/index.d.ts +5 -0
- package/dist/ox/index.d.ts.map +1 -0
- package/dist/ox/index.js +5 -0
- package/dist/ox/index.js.map +1 -0
- package/dist/prool/Instance.d.ts +92 -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 +2058 -0
- package/dist/viem/abis.d.ts.map +1 -0
- package/dist/viem/abis.js +1599 -0
- package/dist/viem/abis.js.map +1 -0
- package/dist/viem/actions/amm.d.ts +2091 -0
- package/dist/viem/actions/amm.d.ts.map +1 -0
- package/dist/viem/actions/amm.js +876 -0
- package/dist/viem/actions/amm.js.map +1 -0
- package/dist/viem/actions/fee.d.ts +727 -0
- package/dist/viem/actions/fee.d.ts.map +1 -0
- package/dist/viem/actions/fee.js +230 -0
- package/dist/viem/actions/fee.js.map +1 -0
- package/dist/viem/actions/index.d.ts +5 -0
- package/dist/viem/actions/index.d.ts.map +1 -0
- package/dist/viem/actions/index.js +5 -0
- package/dist/viem/actions/index.js.map +1 -0
- package/dist/viem/actions/policy.d.ts +1900 -0
- package/dist/viem/actions/policy.d.ts.map +1 -0
- package/dist/viem/actions/policy.js +841 -0
- package/dist/viem/actions/policy.js.map +1 -0
- package/dist/viem/actions/token.d.ts +13759 -0
- package/dist/viem/actions/token.d.ts.map +1 -0
- package/dist/viem/actions/token.js +2579 -0
- package/dist/viem/actions/token.js.map +1 -0
- package/dist/viem/addresses.d.ts +8 -0
- package/dist/viem/addresses.d.ts.map +1 -0
- package/dist/viem/addresses.js +8 -0
- package/dist/viem/addresses.js.map +1 -0
- package/dist/viem/chain.d.ts +341 -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 +1636 -0
- package/dist/viem/decorator.d.ts.map +1 -0
- package/dist/viem/decorator.js +95 -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 +69 -0
- package/dist/viem/formatters.js.map +1 -0
- package/dist/viem/index.d.ts +9 -0
- package/dist/viem/index.d.ts.map +1 -0
- package/dist/viem/index.js +9 -0
- package/dist/viem/index.js.map +1 -0
- package/dist/viem/transaction.d.ts +54 -0
- package/dist/viem/transaction.d.ts.map +1 -0
- package/dist/viem/transaction.js +108 -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/types.d.ts +10 -0
- package/dist/viem/types.d.ts.map +1 -0
- package/dist/viem/types.js +2 -0
- package/dist/viem/types.js.map +1 -0
- package/dist/viem/utils.d.ts +8 -0
- package/dist/viem/utils.d.ts.map +1 -0
- package/dist/viem/utils.js +9 -0
- package/dist/viem/utils.js.map +1 -0
- package/package.json +100 -2
- package/src/chains.ts +46 -0
- package/src/index.ts +1 -0
- package/src/internal/types.ts +414 -0
- package/src/ox/TokenId.test.ts +29 -0
- package/src/ox/TokenId.ts +35 -0
- package/src/ox/TokenRole.test.ts +20 -0
- package/src/ox/TokenRole.ts +27 -0
- package/src/ox/Transaction.test.ts +257 -0
- package/src/ox/Transaction.ts +247 -0
- package/src/ox/TransactionEnvelopeFeeToken.test.ts +1215 -0
- package/src/ox/TransactionEnvelopeFeeToken.ts +717 -0
- package/src/ox/TransactionRequest.ts +100 -0
- package/src/ox/index.ts +4 -0
- package/src/prool/Instance.test.ts +43 -0
- package/src/prool/Instance.ts +190 -0
- package/src/prool/index.ts +1 -0
- package/src/prool/internal/chain.json +106 -0
- package/src/prool/internal/consensus.toml +32 -0
- package/src/viem/abis.ts +1606 -0
- package/src/viem/actions/amm.test.ts +425 -0
- package/src/viem/actions/amm.ts +1308 -0
- package/src/viem/actions/fee.test.ts +281 -0
- package/src/viem/actions/fee.ts +362 -0
- package/src/viem/actions/index.ts +4 -0
- package/src/viem/actions/policy.test.ts +514 -0
- package/src/viem/actions/policy.ts +1284 -0
- package/src/viem/actions/token.test.ts +2172 -0
- package/src/viem/actions/token.ts +3830 -0
- package/src/viem/addresses.ts +10 -0
- package/src/viem/chain.ts +27 -0
- package/src/viem/client.bench-d.ts +8 -0
- package/src/viem/client.test.ts +152 -0
- package/src/viem/client.ts +91 -0
- package/src/viem/decorator.bench-d.ts +11 -0
- package/src/viem/decorator.test.ts +35 -0
- package/src/viem/decorator.ts +1914 -0
- package/src/viem/e2e.test.ts +410 -0
- package/src/viem/formatters.ts +100 -0
- package/src/viem/index.ts +8 -0
- package/src/viem/transaction.ts +253 -0
- package/src/viem/transport.ts +47 -0
- package/src/viem/types.ts +55 -0
- package/src/viem/utils.ts +37 -0
|
@@ -0,0 +1,1308 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Account,
|
|
3
|
+
type Address,
|
|
4
|
+
type Chain,
|
|
5
|
+
type Client,
|
|
6
|
+
type ExtractAbiItem,
|
|
7
|
+
type GetEventArgs,
|
|
8
|
+
type Hex,
|
|
9
|
+
type Log,
|
|
10
|
+
parseEventLogs,
|
|
11
|
+
type ReadContractReturnType,
|
|
12
|
+
type TransactionReceipt,
|
|
13
|
+
type Transport,
|
|
14
|
+
type Log as viem_Log,
|
|
15
|
+
type WatchContractEventParameters,
|
|
16
|
+
type WriteContractReturnType,
|
|
17
|
+
} from 'viem'
|
|
18
|
+
import {
|
|
19
|
+
readContract,
|
|
20
|
+
watchContractEvent,
|
|
21
|
+
writeContract,
|
|
22
|
+
writeContractSync,
|
|
23
|
+
} from 'viem/actions'
|
|
24
|
+
import type { Compute, UnionOmit } from '../../internal/types.js'
|
|
25
|
+
import * as TokenId from '../../ox/TokenId.js'
|
|
26
|
+
import { feeAmmAbi } from '../abis.js'
|
|
27
|
+
import { feeManagerAddress } from '../addresses.js'
|
|
28
|
+
import type { ReadParameters, WriteParameters } from '../types.js'
|
|
29
|
+
import { defineCall } from '../utils.js'
|
|
30
|
+
|
|
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
|
+
return readContract(client, {
|
|
60
|
+
...parameters,
|
|
61
|
+
...getPoolId.call(parameters),
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export namespace getPoolId {
|
|
66
|
+
export type Parameters = ReadParameters & Args
|
|
67
|
+
|
|
68
|
+
export type Args = {
|
|
69
|
+
/** Address or ID of the user token. */
|
|
70
|
+
userToken: TokenId.TokenIdOrAddress
|
|
71
|
+
/** Address or ID of the validator token. */
|
|
72
|
+
validatorToken: TokenId.TokenIdOrAddress
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type ReturnValue = ReadContractReturnType<
|
|
76
|
+
typeof feeAmmAbi,
|
|
77
|
+
'getPoolId',
|
|
78
|
+
never
|
|
79
|
+
>
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Defines a call to the `getPoolId` function.
|
|
83
|
+
*
|
|
84
|
+
* @param args - Arguments.
|
|
85
|
+
* @returns The call.
|
|
86
|
+
*/
|
|
87
|
+
export function call(args: Args) {
|
|
88
|
+
const { userToken, validatorToken } = args
|
|
89
|
+
return defineCall({
|
|
90
|
+
address: feeManagerAddress,
|
|
91
|
+
abi: feeAmmAbi,
|
|
92
|
+
args: [TokenId.toAddress(userToken), TokenId.toAddress(validatorToken)],
|
|
93
|
+
functionName: 'getPoolId',
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Gets the reserves for a liquidity pool.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* import { createClient, http } from 'viem'
|
|
104
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
105
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
106
|
+
*
|
|
107
|
+
* const client = createClient({
|
|
108
|
+
* chain: tempo,
|
|
109
|
+
* transport: http(),
|
|
110
|
+
* })
|
|
111
|
+
*
|
|
112
|
+
* const pool = await actions.amm.getPool(client, {
|
|
113
|
+
* userToken: '0x...',
|
|
114
|
+
* validatorToken: '0x...',
|
|
115
|
+
* })
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @param client - Client.
|
|
119
|
+
* @param parameters - Parameters.
|
|
120
|
+
* @returns The pool reserves.
|
|
121
|
+
*/
|
|
122
|
+
export async function getPool<chain extends Chain | undefined>(
|
|
123
|
+
client: Client<Transport, chain>,
|
|
124
|
+
parameters: getPool.Parameters,
|
|
125
|
+
): Promise<getPool.ReturnValue> {
|
|
126
|
+
return readContract(client, {
|
|
127
|
+
...parameters,
|
|
128
|
+
...getPool.call(parameters),
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export namespace getPool {
|
|
133
|
+
export type Parameters = ReadParameters & Args
|
|
134
|
+
|
|
135
|
+
export type Args = {
|
|
136
|
+
/** Address or ID of the user token. */
|
|
137
|
+
userToken: TokenId.TokenIdOrAddress
|
|
138
|
+
/** Address or ID of the validator token. */
|
|
139
|
+
validatorToken: TokenId.TokenIdOrAddress
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export type ReturnValue = Compute<{
|
|
143
|
+
/** Reserve of user token. */
|
|
144
|
+
reserveUserToken: bigint
|
|
145
|
+
/** Reserve of validator token. */
|
|
146
|
+
reserveValidatorToken: bigint
|
|
147
|
+
}>
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Defines a call to the `getPool` function.
|
|
151
|
+
*
|
|
152
|
+
* @param args - Arguments.
|
|
153
|
+
* @returns The call.
|
|
154
|
+
*/
|
|
155
|
+
export function call(args: Args) {
|
|
156
|
+
const { userToken, validatorToken } = args
|
|
157
|
+
return defineCall({
|
|
158
|
+
address: feeManagerAddress,
|
|
159
|
+
abi: feeAmmAbi,
|
|
160
|
+
args: [TokenId.toAddress(userToken), TokenId.toAddress(validatorToken)],
|
|
161
|
+
functionName: 'getPool',
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Gets the total supply of LP tokens for a pool.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* import { createClient, http } from 'viem'
|
|
172
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
173
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
174
|
+
*
|
|
175
|
+
* const client = createClient({
|
|
176
|
+
* chain: tempo,
|
|
177
|
+
* transport: http(),
|
|
178
|
+
* })
|
|
179
|
+
*
|
|
180
|
+
* const poolId = await actions.amm.getPoolId(client, {
|
|
181
|
+
* userToken: '0x...',
|
|
182
|
+
* validatorToken: '0x...',
|
|
183
|
+
* })
|
|
184
|
+
*
|
|
185
|
+
* const totalSupply = await actions.amm.getTotalSupply(client, { poolId })
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* @param client - Client.
|
|
189
|
+
* @param parameters - Parameters.
|
|
190
|
+
* @returns The total supply of LP tokens.
|
|
191
|
+
*/
|
|
192
|
+
export async function getTotalSupply<chain extends Chain | undefined>(
|
|
193
|
+
client: Client<Transport, chain>,
|
|
194
|
+
parameters: getTotalSupply.Parameters,
|
|
195
|
+
): Promise<getTotalSupply.ReturnValue> {
|
|
196
|
+
return readContract(client, {
|
|
197
|
+
...parameters,
|
|
198
|
+
...getTotalSupply.call(parameters),
|
|
199
|
+
})
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export namespace getTotalSupply {
|
|
203
|
+
export type Parameters = ReadParameters & Args
|
|
204
|
+
|
|
205
|
+
export type Args = {
|
|
206
|
+
/** Pool ID. */
|
|
207
|
+
poolId: Hex
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export type ReturnValue = ReadContractReturnType<
|
|
211
|
+
typeof feeAmmAbi,
|
|
212
|
+
'totalSupply',
|
|
213
|
+
never
|
|
214
|
+
>
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Defines a call to the `totalSupply` function.
|
|
218
|
+
*
|
|
219
|
+
* @param args - Arguments.
|
|
220
|
+
* @returns The call.
|
|
221
|
+
*/
|
|
222
|
+
export function call(args: Args) {
|
|
223
|
+
const { poolId } = args
|
|
224
|
+
return defineCall({
|
|
225
|
+
address: feeManagerAddress,
|
|
226
|
+
abi: feeAmmAbi,
|
|
227
|
+
args: [poolId],
|
|
228
|
+
functionName: 'totalSupply',
|
|
229
|
+
})
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Gets the LP token balance for an account in a specific pool.
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* import { createClient, http } from 'viem'
|
|
239
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
240
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
241
|
+
*
|
|
242
|
+
* const client = createClient({
|
|
243
|
+
* chain: tempo,
|
|
244
|
+
* transport: http(),
|
|
245
|
+
* })
|
|
246
|
+
*
|
|
247
|
+
* const poolId = await actions.amm.getPoolId(client, {
|
|
248
|
+
* userToken: '0x...',
|
|
249
|
+
* validatorToken: '0x...',
|
|
250
|
+
* })
|
|
251
|
+
*
|
|
252
|
+
* const balance = await actions.amm.getLiquidityBalance(client, {
|
|
253
|
+
* poolId,
|
|
254
|
+
* address: '0x...',
|
|
255
|
+
* })
|
|
256
|
+
* ```
|
|
257
|
+
*
|
|
258
|
+
* @param client - Client.
|
|
259
|
+
* @param parameters - Parameters.
|
|
260
|
+
* @returns The LP token balance.
|
|
261
|
+
*/
|
|
262
|
+
export async function getLiquidityBalance<chain extends Chain | undefined>(
|
|
263
|
+
client: Client<Transport, chain>,
|
|
264
|
+
parameters: getLiquidityBalance.Parameters,
|
|
265
|
+
): Promise<getLiquidityBalance.ReturnValue> {
|
|
266
|
+
return readContract(client, {
|
|
267
|
+
...parameters,
|
|
268
|
+
...getLiquidityBalance.call(parameters),
|
|
269
|
+
})
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export namespace getLiquidityBalance {
|
|
273
|
+
export type Parameters = ReadParameters & Args
|
|
274
|
+
|
|
275
|
+
export type Args = {
|
|
276
|
+
/** Address to check balance for. */
|
|
277
|
+
address: Address
|
|
278
|
+
/** Pool ID. */
|
|
279
|
+
poolId: Hex
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export type ReturnValue = ReadContractReturnType<
|
|
283
|
+
typeof feeAmmAbi,
|
|
284
|
+
'liquidityBalances',
|
|
285
|
+
never
|
|
286
|
+
>
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Defines a call to the `liquidityBalances` function.
|
|
290
|
+
*
|
|
291
|
+
* @param args - Arguments.
|
|
292
|
+
* @returns The call.
|
|
293
|
+
*/
|
|
294
|
+
export function call(args: Args) {
|
|
295
|
+
const { address, poolId } = args
|
|
296
|
+
return defineCall({
|
|
297
|
+
address: feeManagerAddress,
|
|
298
|
+
abi: feeAmmAbi,
|
|
299
|
+
args: [poolId, address],
|
|
300
|
+
functionName: 'liquidityBalances',
|
|
301
|
+
})
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Performs a rebalance swap from validator token to user token.
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```ts
|
|
310
|
+
* import { createClient, http } from 'viem'
|
|
311
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
312
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
313
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
314
|
+
*
|
|
315
|
+
* const client = createClient({
|
|
316
|
+
* account: privateKeyToAccount('0x...'),
|
|
317
|
+
* chain: tempo,
|
|
318
|
+
* transport: http(),
|
|
319
|
+
* })
|
|
320
|
+
*
|
|
321
|
+
* const hash = await actions.amm.rebalanceSwap(client, {
|
|
322
|
+
* userToken: '0x...',
|
|
323
|
+
* validatorToken: '0x...',
|
|
324
|
+
* amountOut: 100n,
|
|
325
|
+
* to: '0x...',
|
|
326
|
+
* })
|
|
327
|
+
* ```
|
|
328
|
+
*
|
|
329
|
+
* @param client - Client.
|
|
330
|
+
* @param parameters - Parameters.
|
|
331
|
+
* @returns The transaction hash.
|
|
332
|
+
*/
|
|
333
|
+
export async function rebalanceSwap<
|
|
334
|
+
chain extends Chain | undefined,
|
|
335
|
+
account extends Account | undefined,
|
|
336
|
+
>(
|
|
337
|
+
client: Client<Transport, chain, account>,
|
|
338
|
+
parameters: rebalanceSwap.Parameters<chain, account>,
|
|
339
|
+
): Promise<rebalanceSwap.ReturnValue> {
|
|
340
|
+
return rebalanceSwap.inner(writeContract, client, parameters)
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export namespace rebalanceSwap {
|
|
344
|
+
export type Parameters<
|
|
345
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
346
|
+
account extends Account | undefined = Account | undefined,
|
|
347
|
+
> = WriteParameters<chain, account> & Args
|
|
348
|
+
|
|
349
|
+
export type Args = {
|
|
350
|
+
/** Amount of user token to receive. */
|
|
351
|
+
amountOut: bigint
|
|
352
|
+
/** Address to send the user token to. */
|
|
353
|
+
to: Address
|
|
354
|
+
/** Address or ID of the user token. */
|
|
355
|
+
userToken: TokenId.TokenIdOrAddress
|
|
356
|
+
/** Address or ID of the validator token. */
|
|
357
|
+
validatorToken: TokenId.TokenIdOrAddress
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export type ReturnValue = WriteContractReturnType
|
|
361
|
+
|
|
362
|
+
/** @internal */
|
|
363
|
+
export async function inner<
|
|
364
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
365
|
+
chain extends Chain | undefined,
|
|
366
|
+
account extends Account | undefined,
|
|
367
|
+
>(
|
|
368
|
+
action: action,
|
|
369
|
+
client: Client<Transport, chain, account>,
|
|
370
|
+
parameters: rebalanceSwap.Parameters<chain, account>,
|
|
371
|
+
): Promise<ReturnType<action>> {
|
|
372
|
+
const call = rebalanceSwap.call(parameters)
|
|
373
|
+
return (await action(client, {
|
|
374
|
+
...parameters,
|
|
375
|
+
...call,
|
|
376
|
+
} as never)) as never
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Defines a call to the `rebalanceSwap` function.
|
|
381
|
+
*
|
|
382
|
+
* Can be passed as a parameter to:
|
|
383
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
384
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
385
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```ts
|
|
389
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
390
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
391
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
392
|
+
*
|
|
393
|
+
* const client = createClient({
|
|
394
|
+
* chain: tempo,
|
|
395
|
+
* transport: http(),
|
|
396
|
+
* }).extend(walletActions)
|
|
397
|
+
*
|
|
398
|
+
* const { result } = await client.sendCalls({
|
|
399
|
+
* calls: [
|
|
400
|
+
* actions.amm.rebalanceSwap.call({
|
|
401
|
+
* userToken: '0x20c0...beef',
|
|
402
|
+
* validatorToken: '0x20c0...babe',
|
|
403
|
+
* amountOut: 100n,
|
|
404
|
+
* to: '0xfeed...fede',
|
|
405
|
+
* }),
|
|
406
|
+
* actions.amm.rebalanceSwap.call({
|
|
407
|
+
* userToken: '0x20c0...babe',
|
|
408
|
+
* validatorToken: '0x20c0...babe',
|
|
409
|
+
* amountOut: 100n,
|
|
410
|
+
* to: '0xfeed...fede',
|
|
411
|
+
* }),
|
|
412
|
+
* ]
|
|
413
|
+
* })
|
|
414
|
+
* ```
|
|
415
|
+
*
|
|
416
|
+
* @param args - Arguments.
|
|
417
|
+
* @returns The call.
|
|
418
|
+
*/
|
|
419
|
+
export function call(args: Args) {
|
|
420
|
+
const { userToken, validatorToken, amountOut, to } = args
|
|
421
|
+
return defineCall({
|
|
422
|
+
address: feeManagerAddress,
|
|
423
|
+
abi: feeAmmAbi,
|
|
424
|
+
functionName: 'rebalanceSwap',
|
|
425
|
+
args: [
|
|
426
|
+
TokenId.toAddress(userToken),
|
|
427
|
+
TokenId.toAddress(validatorToken),
|
|
428
|
+
amountOut,
|
|
429
|
+
to,
|
|
430
|
+
],
|
|
431
|
+
})
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Extracts the `RebalanceSwap` event from logs.
|
|
436
|
+
*
|
|
437
|
+
* @param logs - The logs.
|
|
438
|
+
* @returns The `RebalanceSwap` event.
|
|
439
|
+
*/
|
|
440
|
+
export function extractEvent(logs: Log[]) {
|
|
441
|
+
const [log] = parseEventLogs({
|
|
442
|
+
abi: feeAmmAbi,
|
|
443
|
+
logs,
|
|
444
|
+
eventName: 'RebalanceSwap',
|
|
445
|
+
strict: true,
|
|
446
|
+
})
|
|
447
|
+
if (!log) throw new Error('`RebalanceSwap` event not found.')
|
|
448
|
+
return log
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Performs a rebalance swap from validator token to user token.
|
|
454
|
+
*
|
|
455
|
+
* @example
|
|
456
|
+
* ```ts
|
|
457
|
+
* import { createClient, http } from 'viem'
|
|
458
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
459
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
460
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
461
|
+
*
|
|
462
|
+
* const client = createClient({
|
|
463
|
+
* account: privateKeyToAccount('0x...'),
|
|
464
|
+
* chain: tempo,
|
|
465
|
+
* transport: http(),
|
|
466
|
+
* })
|
|
467
|
+
*
|
|
468
|
+
* const result = await actions.amm.rebalanceSwapSync(client, {
|
|
469
|
+
* userToken: '0x...',
|
|
470
|
+
* validatorToken: '0x...',
|
|
471
|
+
* amountOut: 100n,
|
|
472
|
+
* to: '0x...',
|
|
473
|
+
* })
|
|
474
|
+
* ```
|
|
475
|
+
*
|
|
476
|
+
* @param client - Client.
|
|
477
|
+
* @param parameters - Parameters.
|
|
478
|
+
* @returns The transaction receipt and event data.
|
|
479
|
+
*/
|
|
480
|
+
export async function rebalanceSwapSync<
|
|
481
|
+
chain extends Chain | undefined,
|
|
482
|
+
account extends Account | undefined,
|
|
483
|
+
>(
|
|
484
|
+
client: Client<Transport, chain, account>,
|
|
485
|
+
parameters: rebalanceSwapSync.Parameters<chain, account>,
|
|
486
|
+
): Promise<rebalanceSwapSync.ReturnValue> {
|
|
487
|
+
const receipt = await rebalanceSwap.inner(
|
|
488
|
+
writeContractSync,
|
|
489
|
+
client,
|
|
490
|
+
parameters,
|
|
491
|
+
)
|
|
492
|
+
const { args } = rebalanceSwap.extractEvent(receipt.logs)
|
|
493
|
+
return {
|
|
494
|
+
...args,
|
|
495
|
+
receipt,
|
|
496
|
+
} as never
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
export namespace rebalanceSwapSync {
|
|
500
|
+
export type Parameters<
|
|
501
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
502
|
+
account extends Account | undefined = Account | undefined,
|
|
503
|
+
> = rebalanceSwap.Parameters<chain, account>
|
|
504
|
+
|
|
505
|
+
export type Args = rebalanceSwap.Args
|
|
506
|
+
|
|
507
|
+
export type ReturnValue = Compute<
|
|
508
|
+
GetEventArgs<
|
|
509
|
+
typeof feeAmmAbi,
|
|
510
|
+
'RebalanceSwap',
|
|
511
|
+
{ IndexedOnly: false; Required: true }
|
|
512
|
+
> & {
|
|
513
|
+
/** Transaction receipt. */
|
|
514
|
+
receipt: TransactionReceipt
|
|
515
|
+
}
|
|
516
|
+
>
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Adds liquidity to a pool.
|
|
521
|
+
*
|
|
522
|
+
* @example
|
|
523
|
+
* ```ts
|
|
524
|
+
* import { createClient, http } from 'viem'
|
|
525
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
526
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
527
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
528
|
+
*
|
|
529
|
+
* const client = createClient({
|
|
530
|
+
* account: privateKeyToAccount('0x...'),
|
|
531
|
+
* chain: tempo,
|
|
532
|
+
* transport: http(),
|
|
533
|
+
* })
|
|
534
|
+
*
|
|
535
|
+
* const hash = await actions.amm.mint(client, {
|
|
536
|
+
* userToken: {
|
|
537
|
+
* address: '0x20c0...beef',
|
|
538
|
+
* amount: 100n,
|
|
539
|
+
* },
|
|
540
|
+
* validatorToken: {
|
|
541
|
+
* address: '0x20c0...babe',
|
|
542
|
+
* amount: 100n,
|
|
543
|
+
* },
|
|
544
|
+
* to: '0xfeed...fede',
|
|
545
|
+
* })
|
|
546
|
+
* ```
|
|
547
|
+
*
|
|
548
|
+
* @param client - Client.
|
|
549
|
+
* @param parameters - Parameters.
|
|
550
|
+
* @returns The transaction hash.
|
|
551
|
+
*/
|
|
552
|
+
export async function mint<
|
|
553
|
+
chain extends Chain | undefined,
|
|
554
|
+
account extends Account | undefined,
|
|
555
|
+
>(
|
|
556
|
+
client: Client<Transport, chain, account>,
|
|
557
|
+
parameters: mint.Parameters<chain, account>,
|
|
558
|
+
): Promise<mint.ReturnValue> {
|
|
559
|
+
return mint.inner(writeContract, client, parameters)
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
export namespace mint {
|
|
563
|
+
export type Parameters<
|
|
564
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
565
|
+
account extends Account | undefined = Account | undefined,
|
|
566
|
+
> = WriteParameters<chain, account> & Args
|
|
567
|
+
|
|
568
|
+
export type Args = {
|
|
569
|
+
/** Address to mint LP tokens to. */
|
|
570
|
+
to: Address
|
|
571
|
+
/** User token address and amount. */
|
|
572
|
+
userToken: {
|
|
573
|
+
/** Address or ID of the user token. */
|
|
574
|
+
address: TokenId.TokenIdOrAddress
|
|
575
|
+
/** Amount of user token to add. */
|
|
576
|
+
amount: bigint
|
|
577
|
+
}
|
|
578
|
+
/** Validator token address and amount. */
|
|
579
|
+
validatorToken: {
|
|
580
|
+
/** Address or ID of the validator token. */
|
|
581
|
+
address: TokenId.TokenIdOrAddress
|
|
582
|
+
/** Amount of validator token to add. */
|
|
583
|
+
amount: bigint
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
export type ReturnValue = WriteContractReturnType
|
|
588
|
+
|
|
589
|
+
/** @internal */
|
|
590
|
+
export async function inner<
|
|
591
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
592
|
+
chain extends Chain | undefined,
|
|
593
|
+
account extends Account | undefined,
|
|
594
|
+
>(
|
|
595
|
+
action: action,
|
|
596
|
+
client: Client<Transport, chain, account>,
|
|
597
|
+
parameters: mint.Parameters<chain, account>,
|
|
598
|
+
): Promise<ReturnType<action>> {
|
|
599
|
+
const call = mint.call(parameters)
|
|
600
|
+
return (await action(client, {
|
|
601
|
+
...parameters,
|
|
602
|
+
...call,
|
|
603
|
+
} as never)) as never
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Defines a call to the `mint` function.
|
|
608
|
+
*
|
|
609
|
+
* Can be passed as a parameter to:
|
|
610
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
611
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
612
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
613
|
+
*
|
|
614
|
+
* @example
|
|
615
|
+
* ```ts
|
|
616
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
617
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
618
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
619
|
+
*
|
|
620
|
+
* const client = createClient({
|
|
621
|
+
* chain: tempo,
|
|
622
|
+
* transport: http(),
|
|
623
|
+
* }).extend(walletActions)
|
|
624
|
+
*
|
|
625
|
+
* const { result } = await client.sendCalls({
|
|
626
|
+
* calls: [
|
|
627
|
+
* actions.amm.mint.call({
|
|
628
|
+
* userToken: {
|
|
629
|
+
* address: '0x20c0...beef',
|
|
630
|
+
* amount: 100n,
|
|
631
|
+
* },
|
|
632
|
+
* validatorToken: {
|
|
633
|
+
* address: '0x20c0...babe',
|
|
634
|
+
* amount: 100n,
|
|
635
|
+
* },
|
|
636
|
+
* to: '0xfeed...fede',
|
|
637
|
+
* }),
|
|
638
|
+
* actions.amm.mint.call({
|
|
639
|
+
* userToken: {
|
|
640
|
+
* address: '0x20c0...babe',
|
|
641
|
+
* amount: 100n,
|
|
642
|
+
* },
|
|
643
|
+
* validatorToken: {
|
|
644
|
+
* address: '0x20c0...babe',
|
|
645
|
+
* amount: 100n,
|
|
646
|
+
* },
|
|
647
|
+
* to: '0xfeed...fede',
|
|
648
|
+
* }),
|
|
649
|
+
* ]
|
|
650
|
+
* })
|
|
651
|
+
* ```
|
|
652
|
+
*
|
|
653
|
+
* @param args - Arguments.
|
|
654
|
+
* @returns The call.
|
|
655
|
+
*/
|
|
656
|
+
export function call(args: Args) {
|
|
657
|
+
const { to, userToken, validatorToken } = args
|
|
658
|
+
return defineCall({
|
|
659
|
+
address: feeManagerAddress,
|
|
660
|
+
abi: feeAmmAbi,
|
|
661
|
+
functionName: 'mint',
|
|
662
|
+
args: [
|
|
663
|
+
TokenId.toAddress(userToken.address),
|
|
664
|
+
TokenId.toAddress(validatorToken.address),
|
|
665
|
+
userToken.amount,
|
|
666
|
+
validatorToken.amount,
|
|
667
|
+
to,
|
|
668
|
+
],
|
|
669
|
+
})
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* Extracts the `Mint` event from logs.
|
|
674
|
+
*
|
|
675
|
+
* @param logs - The logs.
|
|
676
|
+
* @returns The `Mint` event.
|
|
677
|
+
*/
|
|
678
|
+
export function extractEvent(logs: Log[]) {
|
|
679
|
+
const [log] = parseEventLogs({
|
|
680
|
+
abi: feeAmmAbi,
|
|
681
|
+
logs,
|
|
682
|
+
eventName: 'Mint',
|
|
683
|
+
strict: true,
|
|
684
|
+
})
|
|
685
|
+
if (!log) throw new Error('`Mint` event not found.')
|
|
686
|
+
return log
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* Adds liquidity to a pool.
|
|
692
|
+
*
|
|
693
|
+
* @example
|
|
694
|
+
* ```ts
|
|
695
|
+
* import { createClient, http } from 'viem'
|
|
696
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
697
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
698
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
699
|
+
*
|
|
700
|
+
* const client = createClient({
|
|
701
|
+
* account: privateKeyToAccount('0x...'),
|
|
702
|
+
* chain: tempo,
|
|
703
|
+
* transport: http(),
|
|
704
|
+
* })
|
|
705
|
+
*
|
|
706
|
+
* const hash = await actions.amm.mint(client, {
|
|
707
|
+
* userToken: {
|
|
708
|
+
* address: '0x20c0...beef',
|
|
709
|
+
* amount: 100n,
|
|
710
|
+
* },
|
|
711
|
+
* validatorToken: {
|
|
712
|
+
* address: '0x20c0...babe',
|
|
713
|
+
* amount: 100n,
|
|
714
|
+
* },
|
|
715
|
+
* to: '0xfeed...fede',
|
|
716
|
+
* })
|
|
717
|
+
* ```
|
|
718
|
+
*
|
|
719
|
+
* @param client - Client.
|
|
720
|
+
* @param parameters - Parameters.
|
|
721
|
+
* @returns The transaction receipt and event data.
|
|
722
|
+
*/
|
|
723
|
+
export async function mintSync<
|
|
724
|
+
chain extends Chain | undefined,
|
|
725
|
+
account extends Account | undefined,
|
|
726
|
+
>(
|
|
727
|
+
client: Client<Transport, chain, account>,
|
|
728
|
+
parameters: mintSync.Parameters<chain, account>,
|
|
729
|
+
): Promise<mintSync.ReturnValue> {
|
|
730
|
+
const receipt = await mint.inner(writeContractSync, client, parameters)
|
|
731
|
+
const { args } = mint.extractEvent(receipt.logs)
|
|
732
|
+
return {
|
|
733
|
+
...args,
|
|
734
|
+
receipt,
|
|
735
|
+
} as never
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
export namespace mintSync {
|
|
739
|
+
export type Parameters<
|
|
740
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
741
|
+
account extends Account | undefined = Account | undefined,
|
|
742
|
+
> = mint.Parameters<chain, account>
|
|
743
|
+
|
|
744
|
+
export type Args = mint.Args
|
|
745
|
+
|
|
746
|
+
export type ReturnValue = Compute<
|
|
747
|
+
GetEventArgs<
|
|
748
|
+
typeof feeAmmAbi,
|
|
749
|
+
'Mint',
|
|
750
|
+
{ IndexedOnly: false; Required: true }
|
|
751
|
+
> & {
|
|
752
|
+
/** Transaction receipt. */
|
|
753
|
+
receipt: TransactionReceipt
|
|
754
|
+
}
|
|
755
|
+
>
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* Removes liquidity from a pool.
|
|
760
|
+
*
|
|
761
|
+
* @example
|
|
762
|
+
* ```ts
|
|
763
|
+
* import { createClient, http } from 'viem'
|
|
764
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
765
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
766
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
767
|
+
*
|
|
768
|
+
* const client = createClient({
|
|
769
|
+
* account: privateKeyToAccount('0x...'),
|
|
770
|
+
* chain: tempo,
|
|
771
|
+
* transport: http(),
|
|
772
|
+
* })
|
|
773
|
+
*
|
|
774
|
+
* const hash = await actions.amm.burn(client, {
|
|
775
|
+
* userToken: '0x20c0...beef',
|
|
776
|
+
* validatorToken: '0x20c0...babe',
|
|
777
|
+
* liquidity: 50n,
|
|
778
|
+
* to: '0xfeed...fede',
|
|
779
|
+
* })
|
|
780
|
+
* ```
|
|
781
|
+
*
|
|
782
|
+
* @param client - Client.
|
|
783
|
+
* @param parameters - Parameters.
|
|
784
|
+
* @returns The transaction hash.
|
|
785
|
+
*/
|
|
786
|
+
export async function burn<
|
|
787
|
+
chain extends Chain | undefined,
|
|
788
|
+
account extends Account | undefined,
|
|
789
|
+
>(
|
|
790
|
+
client: Client<Transport, chain, account>,
|
|
791
|
+
parameters: burn.Parameters<chain, account>,
|
|
792
|
+
): Promise<burn.ReturnValue> {
|
|
793
|
+
return burn.inner(writeContract, client, parameters)
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
export namespace burn {
|
|
797
|
+
export type Parameters<
|
|
798
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
799
|
+
account extends Account | undefined = Account | undefined,
|
|
800
|
+
> = WriteParameters<chain, account> & Args
|
|
801
|
+
|
|
802
|
+
export type Args = {
|
|
803
|
+
/** Amount of LP tokens to burn. */
|
|
804
|
+
liquidity: bigint
|
|
805
|
+
/** Address to send tokens to. */
|
|
806
|
+
to: Address
|
|
807
|
+
/** Address or ID of the user token. */
|
|
808
|
+
userToken: TokenId.TokenIdOrAddress
|
|
809
|
+
/** Address or ID of the validator token. */
|
|
810
|
+
validatorToken: TokenId.TokenIdOrAddress
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
export type ReturnValue = WriteContractReturnType
|
|
814
|
+
|
|
815
|
+
/** @internal */
|
|
816
|
+
export async function inner<
|
|
817
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
818
|
+
chain extends Chain | undefined,
|
|
819
|
+
account extends Account | undefined,
|
|
820
|
+
>(
|
|
821
|
+
action: action,
|
|
822
|
+
client: Client<Transport, chain, account>,
|
|
823
|
+
parameters: burn.Parameters<chain, account>,
|
|
824
|
+
): Promise<ReturnType<action>> {
|
|
825
|
+
const call = burn.call(parameters)
|
|
826
|
+
return (await action(client, {
|
|
827
|
+
...parameters,
|
|
828
|
+
...call,
|
|
829
|
+
} as never)) as never
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* Defines a call to the `burn` function.
|
|
834
|
+
*
|
|
835
|
+
* Can be passed as a parameter to:
|
|
836
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
837
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
838
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
839
|
+
*
|
|
840
|
+
* @example
|
|
841
|
+
* ```ts
|
|
842
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
843
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
844
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
845
|
+
*
|
|
846
|
+
* const client = createClient({
|
|
847
|
+
* chain: tempo,
|
|
848
|
+
* transport: http(),
|
|
849
|
+
* }).extend(walletActions)
|
|
850
|
+
*
|
|
851
|
+
* const { result } = await client.sendCalls({
|
|
852
|
+
* calls: [
|
|
853
|
+
* actions.amm.burn.call({
|
|
854
|
+
* liquidity: 100n,
|
|
855
|
+
* to: '0xfeed...fede',
|
|
856
|
+
* userToken: '0x20c0...beef',
|
|
857
|
+
* validatorToken: '0x20c0...babe',
|
|
858
|
+
* }),
|
|
859
|
+
* actions.amm.burn.call({
|
|
860
|
+
* liquidity: 100n,
|
|
861
|
+
* to: '0xfeed...fede',
|
|
862
|
+
* userToken: '0x20c0...babe',
|
|
863
|
+
* validatorToken: '0x20c0...babe',
|
|
864
|
+
* }),
|
|
865
|
+
* ]
|
|
866
|
+
* })
|
|
867
|
+
* ```
|
|
868
|
+
*
|
|
869
|
+
* @param args - Arguments.
|
|
870
|
+
* @returns The call.
|
|
871
|
+
*/
|
|
872
|
+
export function call(args: Args) {
|
|
873
|
+
const { liquidity, to, userToken, validatorToken } = args
|
|
874
|
+
return defineCall({
|
|
875
|
+
address: feeManagerAddress,
|
|
876
|
+
abi: feeAmmAbi,
|
|
877
|
+
functionName: 'burn',
|
|
878
|
+
args: [
|
|
879
|
+
TokenId.toAddress(userToken),
|
|
880
|
+
TokenId.toAddress(validatorToken),
|
|
881
|
+
liquidity,
|
|
882
|
+
to,
|
|
883
|
+
],
|
|
884
|
+
})
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* Extracts the `Burn` event from logs.
|
|
889
|
+
*
|
|
890
|
+
* @param logs - The logs.
|
|
891
|
+
* @returns The `Burn` event.
|
|
892
|
+
*/
|
|
893
|
+
export function extractEvent(logs: Log[]) {
|
|
894
|
+
const [log] = parseEventLogs({
|
|
895
|
+
abi: feeAmmAbi,
|
|
896
|
+
logs,
|
|
897
|
+
eventName: 'Burn',
|
|
898
|
+
strict: true,
|
|
899
|
+
})
|
|
900
|
+
if (!log) throw new Error('`Burn` event not found.')
|
|
901
|
+
return log
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* Removes liquidity from a pool.
|
|
907
|
+
*
|
|
908
|
+
* @example
|
|
909
|
+
* ```ts
|
|
910
|
+
* import { createClient, http } from 'viem'
|
|
911
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
912
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
913
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
914
|
+
*
|
|
915
|
+
* const client = createClient({
|
|
916
|
+
* account: privateKeyToAccount('0x...'),
|
|
917
|
+
* chain: tempo,
|
|
918
|
+
* transport: http(),
|
|
919
|
+
* })
|
|
920
|
+
*
|
|
921
|
+
* const result = await actions.amm.burnSync(client, {
|
|
922
|
+
* userToken: '0x20c0...beef',
|
|
923
|
+
* validatorToken: '0x20c0...babe',
|
|
924
|
+
* liquidity: 50n,
|
|
925
|
+
* to: '0xfeed...fede',
|
|
926
|
+
* })
|
|
927
|
+
* ```
|
|
928
|
+
*
|
|
929
|
+
* @param client - Client.
|
|
930
|
+
* @param parameters - Parameters.
|
|
931
|
+
* @returns The transaction receipt and event data.
|
|
932
|
+
*/
|
|
933
|
+
export async function burnSync<
|
|
934
|
+
chain extends Chain | undefined,
|
|
935
|
+
account extends Account | undefined,
|
|
936
|
+
>(
|
|
937
|
+
client: Client<Transport, chain, account>,
|
|
938
|
+
parameters: burnSync.Parameters<chain, account>,
|
|
939
|
+
): Promise<burnSync.ReturnValue> {
|
|
940
|
+
const receipt = await burn.inner(writeContractSync, client, parameters)
|
|
941
|
+
const { args } = burn.extractEvent(receipt.logs)
|
|
942
|
+
return {
|
|
943
|
+
...args,
|
|
944
|
+
receipt,
|
|
945
|
+
} as never
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
export namespace burnSync {
|
|
949
|
+
export type Parameters<
|
|
950
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
951
|
+
account extends Account | undefined = Account | undefined,
|
|
952
|
+
> = burn.Parameters<chain, account>
|
|
953
|
+
|
|
954
|
+
export type Args = burn.Args
|
|
955
|
+
|
|
956
|
+
export type ReturnValue = Compute<
|
|
957
|
+
GetEventArgs<
|
|
958
|
+
typeof feeAmmAbi,
|
|
959
|
+
'Burn',
|
|
960
|
+
{ IndexedOnly: false; Required: true }
|
|
961
|
+
> & {
|
|
962
|
+
/** Transaction receipt. */
|
|
963
|
+
receipt: TransactionReceipt
|
|
964
|
+
}
|
|
965
|
+
>
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
/**
|
|
969
|
+
* Watches for rebalance swap events.
|
|
970
|
+
*
|
|
971
|
+
* @example
|
|
972
|
+
* ```ts
|
|
973
|
+
* import { createClient, http } from 'viem'
|
|
974
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
975
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
976
|
+
*
|
|
977
|
+
* const client = createClient({
|
|
978
|
+
* chain: tempo,
|
|
979
|
+
* transport: http(),
|
|
980
|
+
* })
|
|
981
|
+
*
|
|
982
|
+
* const unwatch = actions.amm.watchRebalanceSwap(client, {
|
|
983
|
+
* onRebalanceSwap: (args, log) => {
|
|
984
|
+
* console.log('Rebalance swap:', args)
|
|
985
|
+
* },
|
|
986
|
+
* })
|
|
987
|
+
* ```
|
|
988
|
+
*
|
|
989
|
+
* @param client - Client.
|
|
990
|
+
* @param parameters - Parameters.
|
|
991
|
+
* @returns A function to unsubscribe from the event.
|
|
992
|
+
*/
|
|
993
|
+
export function watchRebalanceSwap<
|
|
994
|
+
chain extends Chain | undefined,
|
|
995
|
+
account extends Account | undefined,
|
|
996
|
+
>(
|
|
997
|
+
client: Client<Transport, chain, account>,
|
|
998
|
+
parameters: watchRebalanceSwap.Parameters,
|
|
999
|
+
) {
|
|
1000
|
+
const { onRebalanceSwap, userToken, validatorToken, ...rest } = parameters
|
|
1001
|
+
return watchContractEvent(client, {
|
|
1002
|
+
...rest,
|
|
1003
|
+
address: feeManagerAddress,
|
|
1004
|
+
abi: feeAmmAbi,
|
|
1005
|
+
eventName: 'RebalanceSwap',
|
|
1006
|
+
args:
|
|
1007
|
+
userToken !== undefined && validatorToken !== undefined
|
|
1008
|
+
? {
|
|
1009
|
+
userToken: TokenId.toAddress(userToken),
|
|
1010
|
+
validatorToken: TokenId.toAddress(validatorToken),
|
|
1011
|
+
}
|
|
1012
|
+
: undefined,
|
|
1013
|
+
onLogs: (logs) => {
|
|
1014
|
+
for (const log of logs) onRebalanceSwap(log.args, log)
|
|
1015
|
+
},
|
|
1016
|
+
strict: true,
|
|
1017
|
+
})
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
export declare namespace watchRebalanceSwap {
|
|
1021
|
+
export type Args = GetEventArgs<
|
|
1022
|
+
typeof feeAmmAbi,
|
|
1023
|
+
'RebalanceSwap',
|
|
1024
|
+
{ IndexedOnly: false; Required: true }
|
|
1025
|
+
>
|
|
1026
|
+
|
|
1027
|
+
export type Log = viem_Log<
|
|
1028
|
+
bigint,
|
|
1029
|
+
number,
|
|
1030
|
+
false,
|
|
1031
|
+
ExtractAbiItem<typeof feeAmmAbi, 'RebalanceSwap'>,
|
|
1032
|
+
true
|
|
1033
|
+
>
|
|
1034
|
+
|
|
1035
|
+
export type Parameters = UnionOmit<
|
|
1036
|
+
WatchContractEventParameters<typeof feeAmmAbi, 'RebalanceSwap', true>,
|
|
1037
|
+
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
1038
|
+
> & {
|
|
1039
|
+
/** Callback to invoke when a rebalance swap occurs. */
|
|
1040
|
+
onRebalanceSwap: (args: Args, log: Log) => void
|
|
1041
|
+
/** Address or ID of the user token to filter events. */
|
|
1042
|
+
userToken?: TokenId.TokenIdOrAddress | undefined
|
|
1043
|
+
/** Address or ID of the validator token to filter events. */
|
|
1044
|
+
validatorToken?: TokenId.TokenIdOrAddress | undefined
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
/**
|
|
1049
|
+
* Watches for fee swap events.
|
|
1050
|
+
*
|
|
1051
|
+
* @example
|
|
1052
|
+
* ```ts
|
|
1053
|
+
* import { createClient, http } from 'viem'
|
|
1054
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
1055
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
1056
|
+
*
|
|
1057
|
+
* const client = createClient({
|
|
1058
|
+
* chain: tempo,
|
|
1059
|
+
* transport: http(),
|
|
1060
|
+
* })
|
|
1061
|
+
*
|
|
1062
|
+
* const unwatch = actions.amm.watchFeeSwap(client, {
|
|
1063
|
+
* onFeeSwap: (args, log) => {
|
|
1064
|
+
* console.log('Fee swap:', args)
|
|
1065
|
+
* },
|
|
1066
|
+
* })
|
|
1067
|
+
* ```
|
|
1068
|
+
*
|
|
1069
|
+
* @param client - Client.
|
|
1070
|
+
* @param parameters - Parameters.
|
|
1071
|
+
* @returns A function to unsubscribe from the event.
|
|
1072
|
+
*/
|
|
1073
|
+
export function watchFeeSwap<
|
|
1074
|
+
chain extends Chain | undefined,
|
|
1075
|
+
account extends Account | undefined,
|
|
1076
|
+
>(
|
|
1077
|
+
client: Client<Transport, chain, account>,
|
|
1078
|
+
parameters: watchFeeSwap.Parameters,
|
|
1079
|
+
) {
|
|
1080
|
+
const { onFeeSwap, userToken, validatorToken, ...rest } = parameters
|
|
1081
|
+
return watchContractEvent(client, {
|
|
1082
|
+
...rest,
|
|
1083
|
+
address: feeManagerAddress,
|
|
1084
|
+
abi: feeAmmAbi,
|
|
1085
|
+
eventName: 'FeeSwap',
|
|
1086
|
+
args:
|
|
1087
|
+
userToken !== undefined && validatorToken !== undefined
|
|
1088
|
+
? {
|
|
1089
|
+
userToken: TokenId.toAddress(userToken),
|
|
1090
|
+
validatorToken: TokenId.toAddress(validatorToken),
|
|
1091
|
+
}
|
|
1092
|
+
: undefined,
|
|
1093
|
+
onLogs: (logs) => {
|
|
1094
|
+
for (const log of logs) onFeeSwap(log.args, log)
|
|
1095
|
+
},
|
|
1096
|
+
strict: true,
|
|
1097
|
+
})
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
export declare namespace watchFeeSwap {
|
|
1101
|
+
export type Args = GetEventArgs<
|
|
1102
|
+
typeof feeAmmAbi,
|
|
1103
|
+
'FeeSwap',
|
|
1104
|
+
{ IndexedOnly: false; Required: true }
|
|
1105
|
+
>
|
|
1106
|
+
|
|
1107
|
+
export type Log = viem_Log<
|
|
1108
|
+
bigint,
|
|
1109
|
+
number,
|
|
1110
|
+
false,
|
|
1111
|
+
ExtractAbiItem<typeof feeAmmAbi, 'FeeSwap'>,
|
|
1112
|
+
true
|
|
1113
|
+
>
|
|
1114
|
+
|
|
1115
|
+
export type Parameters = UnionOmit<
|
|
1116
|
+
WatchContractEventParameters<typeof feeAmmAbi, 'FeeSwap', true>,
|
|
1117
|
+
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
1118
|
+
> & {
|
|
1119
|
+
/** Callback to invoke when a fee swap occurs. */
|
|
1120
|
+
onFeeSwap: (args: Args, log: Log) => void
|
|
1121
|
+
/** Address or ID of the user token to filter events. */
|
|
1122
|
+
userToken?: TokenId.TokenIdOrAddress | undefined
|
|
1123
|
+
/** Address or ID of the validator token to filter events. */
|
|
1124
|
+
validatorToken?: TokenId.TokenIdOrAddress | undefined
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
/**
|
|
1129
|
+
* Watches for liquidity mint events.
|
|
1130
|
+
*
|
|
1131
|
+
* @example
|
|
1132
|
+
* ```ts
|
|
1133
|
+
* import { createClient, http } from 'viem'
|
|
1134
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
1135
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
1136
|
+
*
|
|
1137
|
+
* const client = createClient({
|
|
1138
|
+
* chain: tempo,
|
|
1139
|
+
* transport: http(),
|
|
1140
|
+
* })
|
|
1141
|
+
*
|
|
1142
|
+
* const unwatch = actions.amm.watchMint(client, {
|
|
1143
|
+
* onMint: (args, log) => {
|
|
1144
|
+
* console.log('Liquidity added:', args)
|
|
1145
|
+
* },
|
|
1146
|
+
* })
|
|
1147
|
+
* ```
|
|
1148
|
+
*
|
|
1149
|
+
* @param client - Client.
|
|
1150
|
+
* @param parameters - Parameters.
|
|
1151
|
+
* @returns A function to unsubscribe from the event.
|
|
1152
|
+
*/
|
|
1153
|
+
export function watchMint<
|
|
1154
|
+
chain extends Chain | undefined,
|
|
1155
|
+
account extends Account | undefined,
|
|
1156
|
+
>(client: Client<Transport, chain, account>, parameters: watchMint.Parameters) {
|
|
1157
|
+
const { onMint, sender, userToken, validatorToken, ...rest } = parameters
|
|
1158
|
+
return watchContractEvent(client, {
|
|
1159
|
+
...rest,
|
|
1160
|
+
address: feeManagerAddress,
|
|
1161
|
+
abi: feeAmmAbi,
|
|
1162
|
+
eventName: 'Mint',
|
|
1163
|
+
args: {
|
|
1164
|
+
...(sender !== undefined && {
|
|
1165
|
+
sender: TokenId.toAddress(sender),
|
|
1166
|
+
}),
|
|
1167
|
+
...(userToken !== undefined && {
|
|
1168
|
+
userToken: TokenId.toAddress(userToken),
|
|
1169
|
+
}),
|
|
1170
|
+
...(validatorToken !== undefined && {
|
|
1171
|
+
validatorToken: TokenId.toAddress(validatorToken),
|
|
1172
|
+
}),
|
|
1173
|
+
},
|
|
1174
|
+
onLogs: (logs) => {
|
|
1175
|
+
for (const log of logs)
|
|
1176
|
+
onMint(
|
|
1177
|
+
{
|
|
1178
|
+
liquidity: log.args.liquidity,
|
|
1179
|
+
sender: log.args.sender,
|
|
1180
|
+
userToken: {
|
|
1181
|
+
address: log.args.userToken,
|
|
1182
|
+
amount: log.args.amountUserToken,
|
|
1183
|
+
},
|
|
1184
|
+
validatorToken: {
|
|
1185
|
+
address: log.args.validatorToken,
|
|
1186
|
+
amount: log.args.amountValidatorToken,
|
|
1187
|
+
},
|
|
1188
|
+
},
|
|
1189
|
+
log,
|
|
1190
|
+
)
|
|
1191
|
+
},
|
|
1192
|
+
strict: true,
|
|
1193
|
+
})
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
export declare namespace watchMint {
|
|
1197
|
+
export type Args = {
|
|
1198
|
+
liquidity: bigint
|
|
1199
|
+
sender: Address
|
|
1200
|
+
userToken: {
|
|
1201
|
+
address: Address
|
|
1202
|
+
amount: bigint
|
|
1203
|
+
}
|
|
1204
|
+
validatorToken: {
|
|
1205
|
+
address: Address
|
|
1206
|
+
amount: bigint
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
export type Log = viem_Log<
|
|
1211
|
+
bigint,
|
|
1212
|
+
number,
|
|
1213
|
+
false,
|
|
1214
|
+
ExtractAbiItem<typeof feeAmmAbi, 'Mint'>,
|
|
1215
|
+
true
|
|
1216
|
+
>
|
|
1217
|
+
|
|
1218
|
+
export type Parameters = UnionOmit<
|
|
1219
|
+
WatchContractEventParameters<typeof feeAmmAbi, 'Mint', true>,
|
|
1220
|
+
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
1221
|
+
> & {
|
|
1222
|
+
/** Callback to invoke when liquidity is added. */
|
|
1223
|
+
onMint: (args: Args, log: Log) => void
|
|
1224
|
+
/** Address or ID of the sender to filter events. */
|
|
1225
|
+
sender?: TokenId.TokenIdOrAddress | undefined
|
|
1226
|
+
/** Address or ID of the user token to filter events. */
|
|
1227
|
+
userToken?: TokenId.TokenIdOrAddress | undefined
|
|
1228
|
+
/** Address or ID of the validator token to filter events. */
|
|
1229
|
+
validatorToken?: TokenId.TokenIdOrAddress | undefined
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
/**
|
|
1234
|
+
* Watches for liquidity burn events.
|
|
1235
|
+
*
|
|
1236
|
+
* @example
|
|
1237
|
+
* ```ts
|
|
1238
|
+
* import { createClient, http } from 'viem'
|
|
1239
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
1240
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
1241
|
+
*
|
|
1242
|
+
* const client = createClient({
|
|
1243
|
+
* chain: tempo,
|
|
1244
|
+
* transport: http(),
|
|
1245
|
+
* })
|
|
1246
|
+
*
|
|
1247
|
+
* const unwatch = actions.amm.watchBurn(client, {
|
|
1248
|
+
* onBurn: (args, log) => {
|
|
1249
|
+
* console.log('Liquidity removed:', args)
|
|
1250
|
+
* },
|
|
1251
|
+
* })
|
|
1252
|
+
* ```
|
|
1253
|
+
*
|
|
1254
|
+
* @param client - Client.
|
|
1255
|
+
* @param parameters - Parameters.
|
|
1256
|
+
* @returns A function to unsubscribe from the event.
|
|
1257
|
+
*/
|
|
1258
|
+
export function watchBurn<
|
|
1259
|
+
chain extends Chain | undefined,
|
|
1260
|
+
account extends Account | undefined,
|
|
1261
|
+
>(client: Client<Transport, chain, account>, parameters: watchBurn.Parameters) {
|
|
1262
|
+
const { onBurn, userToken, validatorToken, ...rest } = parameters
|
|
1263
|
+
return watchContractEvent(client, {
|
|
1264
|
+
...rest,
|
|
1265
|
+
address: feeManagerAddress,
|
|
1266
|
+
abi: feeAmmAbi,
|
|
1267
|
+
eventName: 'Burn',
|
|
1268
|
+
args:
|
|
1269
|
+
userToken !== undefined && validatorToken !== undefined
|
|
1270
|
+
? {
|
|
1271
|
+
userToken: TokenId.toAddress(userToken),
|
|
1272
|
+
validatorToken: TokenId.toAddress(validatorToken),
|
|
1273
|
+
}
|
|
1274
|
+
: undefined,
|
|
1275
|
+
onLogs: (logs) => {
|
|
1276
|
+
for (const log of logs) onBurn(log.args, log)
|
|
1277
|
+
},
|
|
1278
|
+
strict: true,
|
|
1279
|
+
})
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
export declare namespace watchBurn {
|
|
1283
|
+
export type Args = GetEventArgs<
|
|
1284
|
+
typeof feeAmmAbi,
|
|
1285
|
+
'Burn',
|
|
1286
|
+
{ IndexedOnly: false; Required: true }
|
|
1287
|
+
>
|
|
1288
|
+
|
|
1289
|
+
export type Log = viem_Log<
|
|
1290
|
+
bigint,
|
|
1291
|
+
number,
|
|
1292
|
+
false,
|
|
1293
|
+
ExtractAbiItem<typeof feeAmmAbi, 'Burn'>,
|
|
1294
|
+
true
|
|
1295
|
+
>
|
|
1296
|
+
|
|
1297
|
+
export type Parameters = UnionOmit<
|
|
1298
|
+
WatchContractEventParameters<typeof feeAmmAbi, 'Burn', true>,
|
|
1299
|
+
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
1300
|
+
> & {
|
|
1301
|
+
/** Callback to invoke when liquidity is removed. */
|
|
1302
|
+
onBurn: (args: Args, log: Log) => void
|
|
1303
|
+
/** Address or ID of the user token to filter events. */
|
|
1304
|
+
userToken?: TokenId.TokenIdOrAddress | undefined
|
|
1305
|
+
/** Address or ID of the validator token to filter events. */
|
|
1306
|
+
validatorToken?: TokenId.TokenIdOrAddress | undefined
|
|
1307
|
+
}
|
|
1308
|
+
}
|