tempo.ts 0.7.5 → 0.7.6

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.
@@ -100,6 +100,66 @@ export type Decorator<
100
100
  getLiquidityBalance: (
101
101
  parameters: ammActions.getLiquidityBalance.Parameters,
102
102
  ) => Promise<ammActions.getLiquidityBalance.ReturnValue>
103
+ /**
104
+ * Removes liquidity from a pool.
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * import { createClient, http } from 'viem'
109
+ * import { privateKeyToAccount } from 'viem/accounts'
110
+ * import { tempo } from 'tempo.ts/chains'
111
+ * import { tempoActions } from 'tempo.ts/viem'
112
+ *
113
+ * const client = createClient({
114
+ * account: privateKeyToAccount('0x...'),
115
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
116
+ * transport: http(),
117
+ * }).extend(tempoActions())
118
+ *
119
+ * const hash = await client.amm.burn({
120
+ * userToken: '0x...',
121
+ * validatorToken: '0x...',
122
+ * liquidity: 50n,
123
+ * to: '0x...',
124
+ * })
125
+ * ```
126
+ *
127
+ * @param parameters - Parameters.
128
+ * @returns The transaction hash.
129
+ */
130
+ burn: (
131
+ parameters: ammActions.burn.Parameters<chain, account>,
132
+ ) => Promise<ammActions.burn.ReturnValue>
133
+ /**
134
+ * Removes liquidity from a pool and waits for confirmation.
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * import { createClient, http } from 'viem'
139
+ * import { privateKeyToAccount } from 'viem/accounts'
140
+ * import { tempo } from 'tempo.ts/chains'
141
+ * import { tempoActions } from 'tempo.ts/viem'
142
+ *
143
+ * const client = createClient({
144
+ * account: privateKeyToAccount('0x...'),
145
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
146
+ * transport: http(),
147
+ * }).extend(tempoActions())
148
+ *
149
+ * const { receipt, ...result } = await client.amm.burnSync({
150
+ * userToken: '0x...',
151
+ * validatorToken: '0x...',
152
+ * liquidity: 50n,
153
+ * to: '0x...',
154
+ * })
155
+ * ```
156
+ *
157
+ * @param parameters - Parameters.
158
+ * @returns The transaction receipt and event data.
159
+ */
160
+ burnSync: (
161
+ parameters: ammActions.burnSync.Parameters<chain, account>,
162
+ ) => Promise<ammActions.burnSync.ReturnValue>
103
163
  /**
104
164
  * Adds liquidity to a pool.
105
165
  *
@@ -117,14 +177,9 @@ export type Decorator<
117
177
  * }).extend(tempoActions())
118
178
  *
119
179
  * const hash = await client.amm.mint({
120
- * userToken: {
121
- * address: '0x...',
122
- * amount: 100n,
123
- * },
124
- * validatorToken: {
125
- * address: '0x...',
126
- * amount: 100n,
127
- * },
180
+ * userTokenAddress: '0x...',
181
+ * validatorTokenAddress: '0x...',
182
+ * validatorTokenAmount: 100n,
128
183
  * to: '0x...',
129
184
  * })
130
185
  * ```
@@ -152,14 +207,9 @@ export type Decorator<
152
207
  * }).extend(tempoActions())
153
208
  *
154
209
  * const result = await client.amm.mintSync({
155
- * userToken: {
156
- * address: '0x...',
157
- * amount: 100n,
158
- * },
159
- * validatorToken: {
160
- * address: '0x...',
161
- * amount: 100n,
162
- * },
210
+ * userTokenAddress: '0x...',
211
+ * validatorTokenAddress: '0x...',
212
+ * validatorTokenAmount: 100n,
163
213
  * to: '0x...',
164
214
  * })
165
215
  * ```
@@ -170,6 +220,116 @@ export type Decorator<
170
220
  mintSync: (
171
221
  parameters: ammActions.mintSync.Parameters<chain, account>,
172
222
  ) => Promise<ammActions.mintSync.ReturnValue>
223
+ /**
224
+ * Swaps tokens during a rebalance operation.
225
+ *
226
+ * @example
227
+ * ```ts
228
+ * import { createClient, http } from 'viem'
229
+ * import { privateKeyToAccount } from 'viem/accounts'
230
+ * import { tempo } from 'tempo.ts/chains'
231
+ * import { tempoActions } from 'tempo.ts/viem'
232
+ *
233
+ * const client = createClient({
234
+ * account: privateKeyToAccount('0x...'),
235
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
236
+ * transport: http(),
237
+ * }).extend(tempoActions())
238
+ *
239
+ * const hash = await client.amm.rebalanceSwap({
240
+ * userToken: '0x...',
241
+ * validatorToken: '0x...',
242
+ * amountOut: 100n,
243
+ * to: '0x...',
244
+ * })
245
+ * ```
246
+ *
247
+ * @param parameters - Parameters.
248
+ * @returns The transaction hash.
249
+ */
250
+ rebalanceSwap: (
251
+ parameters: ammActions.rebalanceSwap.Parameters<chain, account>,
252
+ ) => Promise<ammActions.rebalanceSwap.ReturnValue>
253
+ /**
254
+ * Swaps tokens during a rebalance operation and waits for confirmation.
255
+ *
256
+ * @example
257
+ * ```ts
258
+ * import { createClient, http } from 'viem'
259
+ * import { privateKeyToAccount } from 'viem/accounts'
260
+ * import { tempo } from 'tempo.ts/chains'
261
+ * import { tempoActions } from 'tempo.ts/viem'
262
+ *
263
+ * const client = createClient({
264
+ * account: privateKeyToAccount('0x...'),
265
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
266
+ * transport: http(),
267
+ * }).extend(tempoActions())
268
+ *
269
+ * const { receipt, ...result } = await client.amm.rebalanceSwapSync({
270
+ * userToken: '0x...',
271
+ * validatorToken: '0x...',
272
+ * amountOut: 100n,
273
+ * to: '0x...',
274
+ * })
275
+ * ```
276
+ *
277
+ * @param parameters - Parameters.
278
+ * @returns The transaction receipt and event data.
279
+ */
280
+ rebalanceSwapSync: (
281
+ parameters: ammActions.rebalanceSwapSync.Parameters<chain, account>,
282
+ ) => Promise<ammActions.rebalanceSwapSync.ReturnValue>
283
+ /**
284
+ * Watches for burn (liquidity removal) events.
285
+ *
286
+ * @example
287
+ * ```ts
288
+ * import { createClient, http } from 'viem'
289
+ * import { tempo } from 'tempo.ts/chains'
290
+ * import { tempoActions } from 'tempo.ts/viem'
291
+ *
292
+ * const client = createClient({
293
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
294
+ * transport: http(),
295
+ * }).extend(tempoActions())
296
+ *
297
+ * const unwatch = client.amm.watchBurn({
298
+ * onBurn: (args, log) => {
299
+ * console.log('Liquidity removed:', args)
300
+ * },
301
+ * })
302
+ * ```
303
+ *
304
+ * @param parameters - Parameters.
305
+ * @returns A function to unsubscribe from the event.
306
+ */
307
+ watchBurn: (parameters: ammActions.watchBurn.Parameters) => () => void
308
+ /**
309
+ * Watches for fee swap events.
310
+ *
311
+ * @example
312
+ * ```ts
313
+ * import { createClient, http } from 'viem'
314
+ * import { tempo } from 'tempo.ts/chains'
315
+ * import { tempoActions } from 'tempo.ts/viem'
316
+ *
317
+ * const client = createClient({
318
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
319
+ * transport: http(),
320
+ * }).extend(tempoActions())
321
+ *
322
+ * const unwatch = client.amm.watchFeeSwap({
323
+ * onFeeSwap: (args, log) => {
324
+ * console.log('Fee swap:', args)
325
+ * },
326
+ * })
327
+ * ```
328
+ *
329
+ * @param parameters - Parameters.
330
+ * @returns A function to unsubscribe from the event.
331
+ */
332
+ watchFeeSwap: (parameters: ammActions.watchFeeSwap.Parameters) => () => void
173
333
  /**
174
334
  * Watches for liquidity mint events.
175
335
  *
@@ -195,6 +355,33 @@ export type Decorator<
195
355
  * @returns A function to unsubscribe from the event.
196
356
  */
197
357
  watchMint: (parameters: ammActions.watchMint.Parameters) => () => void
358
+ /**
359
+ * Watches for rebalance swap events.
360
+ *
361
+ * @example
362
+ * ```ts
363
+ * import { createClient, http } from 'viem'
364
+ * import { tempo } from 'tempo.ts/chains'
365
+ * import { tempoActions } from 'tempo.ts/viem'
366
+ *
367
+ * const client = createClient({
368
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
369
+ * transport: http(),
370
+ * }).extend(tempoActions())
371
+ *
372
+ * const unwatch = client.amm.watchRebalanceSwap({
373
+ * onRebalanceSwap: (args, log) => {
374
+ * console.log('Rebalance swap:', args)
375
+ * },
376
+ * })
377
+ * ```
378
+ *
379
+ * @param parameters - Parameters.
380
+ * @returns A function to unsubscribe from the event.
381
+ */
382
+ watchRebalanceSwap: (
383
+ parameters: ammActions.watchRebalanceSwap.Parameters,
384
+ ) => () => void
198
385
  }
199
386
  dex: {
200
387
  /**
@@ -2706,9 +2893,20 @@ export function decorator() {
2706
2893
  getPool: (parameters) => ammActions.getPool(client, parameters),
2707
2894
  getLiquidityBalance: (parameters) =>
2708
2895
  ammActions.getLiquidityBalance(client, parameters),
2896
+ burn: (parameters) => ammActions.burn(client, parameters),
2897
+ burnSync: (parameters) => ammActions.burnSync(client, parameters),
2709
2898
  mint: (parameters) => ammActions.mint(client, parameters),
2710
2899
  mintSync: (parameters) => ammActions.mintSync(client, parameters),
2900
+ rebalanceSwap: (parameters) =>
2901
+ ammActions.rebalanceSwap(client, parameters),
2902
+ rebalanceSwapSync: (parameters) =>
2903
+ ammActions.rebalanceSwapSync(client, parameters),
2904
+ watchBurn: (parameters) => ammActions.watchBurn(client, parameters),
2905
+ watchFeeSwap: (parameters) =>
2906
+ ammActions.watchFeeSwap(client, parameters),
2711
2907
  watchMint: (parameters) => ammActions.watchMint(client, parameters),
2908
+ watchRebalanceSwap: (parameters) =>
2909
+ ammActions.watchRebalanceSwap(client, parameters),
2712
2910
  },
2713
2911
  dex: {
2714
2912
  buy: (parameters) => dexActions.buy(client, parameters),
@@ -1,8 +1,8 @@
1
- import { connect } from '@wagmi/core'
1
+ import { connect, getConnectorClient } from '@wagmi/core'
2
2
  import { parseUnits } from 'viem'
3
3
  import { describe, expect, test } from 'vitest'
4
4
  import { addresses } from '../../../test/config.js'
5
- import { accounts } from '../../../test/viem/config.js'
5
+ import { accounts, setupPoolWithLiquidity } from '../../../test/viem/config.js'
6
6
  import { config, queryClient } from '../../../test/wagmi/config.js'
7
7
  import * as ammActions from './amm.js'
8
8
  import * as tokenActions from './token.js'
@@ -115,3 +115,94 @@ describe('mintSync', () => {
115
115
  `)
116
116
  })
117
117
  })
118
+
119
+ describe('burnSync', () => {
120
+ test('default', async () => {
121
+ await connect(config, {
122
+ connector: config.connectors[0]!,
123
+ })
124
+
125
+ const client = await getConnectorClient(config)
126
+ const { tokenAddress } = await setupPoolWithLiquidity(client)
127
+
128
+ const account2 = accounts[1]
129
+
130
+ // Get LP balance before burn
131
+ const lpBalanceBefore = await ammActions.getLiquidityBalance(config, {
132
+ userToken: tokenAddress,
133
+ validatorToken: addresses.alphaUsd,
134
+ address: account.address,
135
+ })
136
+
137
+ // TODO(TEMPO-1183): Remove this janky fix to get some user token in the pool
138
+ await tokenActions.transferSync(config, {
139
+ to: account2.address,
140
+ amount: 600n,
141
+ token: tokenAddress,
142
+ feeToken: tokenAddress,
143
+ })
144
+
145
+ // Burn half of LP tokens
146
+ const { receipt: burnReceipt, ...burnResult } = await ammActions.burnSync(
147
+ config,
148
+ {
149
+ userToken: tokenAddress,
150
+ validatorToken: addresses.alphaUsd,
151
+ liquidity: lpBalanceBefore / 2n,
152
+ to: account.address,
153
+ },
154
+ )
155
+ expect(burnReceipt).toBeDefined()
156
+ expect(burnResult).toMatchInlineSnapshot(`
157
+ {
158
+ "amountUserToken": 337n,
159
+ "amountValidatorToken": 49998664n,
160
+ "liquidity": 24999500n,
161
+ "sender": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
162
+ "to": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
163
+ "userToken": "0x20c0000000000000000000000000000000000005",
164
+ "validatorToken": "0x20C0000000000000000000000000000000000001",
165
+ }
166
+ `)
167
+ })
168
+ })
169
+
170
+ describe('rebalanceSwapSync', () => {
171
+ test('default', async () => {
172
+ await connect(config, {
173
+ connector: config.connectors[0]!,
174
+ })
175
+
176
+ const client = await getConnectorClient(config)
177
+ const { tokenAddress } = await setupPoolWithLiquidity(client)
178
+
179
+ const account2 = accounts[1]
180
+
181
+ // TODO(TEMPO-1183): Remove this janky fix to get some user token in the pool
182
+ await tokenActions.transferSync(config, {
183
+ to: account2.address,
184
+ amount: 600n,
185
+ token: tokenAddress,
186
+ feeToken: tokenAddress,
187
+ })
188
+
189
+ // Perform rebalance swap
190
+ const { receipt: swapReceipt, ...swapResult } =
191
+ await ammActions.rebalanceSwapSync(config, {
192
+ userToken: tokenAddress,
193
+ validatorToken: addresses.alphaUsd,
194
+ amountOut: 100n,
195
+ to: account2.address,
196
+ })
197
+ expect(swapReceipt).toBeDefined()
198
+ expect(swapResult).toMatchInlineSnapshot(`
199
+ {
200
+ "amountIn": 100n,
201
+ "amountOut": 100n,
202
+ "swapper": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
203
+ "userToken": "0x20C0000000000000000000000000000000000006",
204
+ "validatorToken": "0x20C0000000000000000000000000000000000001",
205
+ }
206
+ `)
207
+ })
208
+ })
@@ -322,14 +322,9 @@ export declare namespace rebalanceSwapSync {
322
322
  * })
323
323
  *
324
324
  * const hash = await Actions.amm.mint(config, {
325
- * userToken: {
326
- * address: '0x20c0...beef',
327
- * amount: 100n,
328
- * },
329
- * validatorToken: {
330
- * address: '0x20c0...babe',
331
- * amount: 100n,
332
- * },
325
+ * userTokenAddress: '0x20c0...beef',
326
+ * validatorTokenAddress: '0x20c0...babe',
327
+ * validatorTokenAmount: 100n,
333
328
  * to: '0xfeed...fede',
334
329
  * })
335
330
  * ```
@@ -382,14 +377,9 @@ export declare namespace mint {
382
377
  * })
383
378
  *
384
379
  * const result = await Actions.amm.mintSync(config, {
385
- * userToken: {
386
- * address: '0x20c0...beef',
387
- * amount: 100n,
388
- * },
389
- * validatorToken: {
390
- * address: '0x20c0...babe',
391
- * amount: 100n,
392
- * },
380
+ * userTokenAddress: '0x20c0...beef',
381
+ * validatorTokenAddress: '0x20c0...babe',
382
+ * validatorTokenAmount: 100n,
393
383
  * to: '0xfeed...fede',
394
384
  * })
395
385
  * ```