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,425 @@
|
|
|
1
|
+
import { setTimeout } from 'node:timers/promises'
|
|
2
|
+
import * as actions from 'tempo.ts/viem/actions'
|
|
3
|
+
import { parseEther, publicActions } from 'viem'
|
|
4
|
+
import { mnemonicToAccount } from 'viem/accounts'
|
|
5
|
+
import { writeContractSync } from 'viem/actions'
|
|
6
|
+
import { describe, expect, test } from 'vitest'
|
|
7
|
+
import { tempoTest } from '../../../test/viem/config.js'
|
|
8
|
+
import { tip20Abi } from '../abis.js'
|
|
9
|
+
import { usdAddress } from '../addresses.js'
|
|
10
|
+
import { createTempoClient } from '../client.js'
|
|
11
|
+
|
|
12
|
+
const account = mnemonicToAccount(
|
|
13
|
+
'test test test test test test test test test test test junk',
|
|
14
|
+
)
|
|
15
|
+
const account2 = mnemonicToAccount(
|
|
16
|
+
'test test test test test test test test test test test junk',
|
|
17
|
+
{ accountIndex: 1 },
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
const client = createTempoClient({
|
|
21
|
+
account,
|
|
22
|
+
chain: tempoTest,
|
|
23
|
+
pollingInterval: 100,
|
|
24
|
+
}).extend(publicActions)
|
|
25
|
+
|
|
26
|
+
async function setupPoolWithLiquidity() {
|
|
27
|
+
// Create a new token for testing
|
|
28
|
+
const { token } = await actions.token.createSync(client, {
|
|
29
|
+
name: 'Test Token',
|
|
30
|
+
symbol: 'TEST',
|
|
31
|
+
currency: 'USD',
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
// Grant issuer role to mint tokens
|
|
35
|
+
await actions.token.grantRolesSync(client, {
|
|
36
|
+
token,
|
|
37
|
+
roles: ['issuer'],
|
|
38
|
+
to: client.account.address,
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
// Mint some tokens to account
|
|
42
|
+
await actions.token.mintSync(client, {
|
|
43
|
+
to: account.address,
|
|
44
|
+
amount: parseEther('1000'),
|
|
45
|
+
token,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
// Add liquidity to pool
|
|
49
|
+
await actions.amm.mintSync(client, {
|
|
50
|
+
userToken: {
|
|
51
|
+
address: token,
|
|
52
|
+
amount: parseEther('100'),
|
|
53
|
+
},
|
|
54
|
+
validatorToken: {
|
|
55
|
+
address: usdAddress,
|
|
56
|
+
amount: parseEther('100'),
|
|
57
|
+
},
|
|
58
|
+
to: account.address,
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
return { tokenAddress: token }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
describe('getPoolId', () => {
|
|
65
|
+
test('default', async () => {
|
|
66
|
+
const poolId = await actions.amm.getPoolId(client, {
|
|
67
|
+
userToken: usdAddress,
|
|
68
|
+
validatorToken: '0x20c0000000000000000000000000000000000001',
|
|
69
|
+
})
|
|
70
|
+
expect(poolId).toBeDefined()
|
|
71
|
+
expect(typeof poolId).toBe('string')
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('behavior: token id', async () => {
|
|
75
|
+
const poolId = await actions.amm.getPoolId(client, {
|
|
76
|
+
userToken: 0n,
|
|
77
|
+
validatorToken: 1n,
|
|
78
|
+
})
|
|
79
|
+
expect(poolId).toBeDefined()
|
|
80
|
+
expect(typeof poolId).toBe('string')
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
describe('getPool', () => {
|
|
85
|
+
test('default', async () => {
|
|
86
|
+
const pool = await actions.amm.getPool(client, {
|
|
87
|
+
userToken: usdAddress,
|
|
88
|
+
validatorToken: '0x20c0000000000000000000000000000000000001',
|
|
89
|
+
})
|
|
90
|
+
expect(pool).toMatchObject({
|
|
91
|
+
reserveUserToken: expect.any(BigInt),
|
|
92
|
+
reserveValidatorToken: expect.any(BigInt),
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
describe('getTotalSupply', () => {
|
|
98
|
+
test('default', async () => {
|
|
99
|
+
const poolId = await actions.amm.getPoolId(client, {
|
|
100
|
+
userToken: usdAddress,
|
|
101
|
+
validatorToken: '0x20c0000000000000000000000000000000000001',
|
|
102
|
+
})
|
|
103
|
+
const totalSupply = await actions.amm.getTotalSupply(client, { poolId })
|
|
104
|
+
expect(typeof totalSupply).toBe('bigint')
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
describe('getLiquidityBalance', () => {
|
|
109
|
+
test('default', async () => {
|
|
110
|
+
const poolId = await actions.amm.getPoolId(client, {
|
|
111
|
+
userToken: usdAddress,
|
|
112
|
+
validatorToken: '0x20c0000000000000000000000000000000000001',
|
|
113
|
+
})
|
|
114
|
+
const balance = await actions.amm.getLiquidityBalance(client, {
|
|
115
|
+
poolId,
|
|
116
|
+
address: account.address,
|
|
117
|
+
})
|
|
118
|
+
expect(typeof balance).toBe('bigint')
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
describe('mint', () => {
|
|
123
|
+
test('default', async () => {
|
|
124
|
+
// Create a new token for testing
|
|
125
|
+
const { token } = await actions.token.createSync(client, {
|
|
126
|
+
name: 'Test Token',
|
|
127
|
+
symbol: 'TEST',
|
|
128
|
+
currency: 'USD',
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
// Grant issuer role to mint tokens
|
|
132
|
+
await actions.token.grantRolesSync(client, {
|
|
133
|
+
token,
|
|
134
|
+
roles: ['issuer'],
|
|
135
|
+
to: client.account.address,
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
// Mint some tokens to account
|
|
139
|
+
await actions.token.mintSync(client, {
|
|
140
|
+
to: account.address,
|
|
141
|
+
amount: parseEther('1000'),
|
|
142
|
+
token,
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
// Add liquidity to pool
|
|
146
|
+
const { receipt: mintReceipt, ...mintResult } = await actions.amm.mintSync(
|
|
147
|
+
client,
|
|
148
|
+
{
|
|
149
|
+
userToken: {
|
|
150
|
+
address: token,
|
|
151
|
+
amount: parseEther('100'),
|
|
152
|
+
},
|
|
153
|
+
validatorToken: {
|
|
154
|
+
address: usdAddress,
|
|
155
|
+
amount: parseEther('100'),
|
|
156
|
+
},
|
|
157
|
+
to: account.address,
|
|
158
|
+
},
|
|
159
|
+
)
|
|
160
|
+
expect(mintReceipt).toBeDefined()
|
|
161
|
+
expect(mintResult).toMatchInlineSnapshot(`
|
|
162
|
+
{
|
|
163
|
+
"amountUserToken": 100000000000000000000n,
|
|
164
|
+
"amountValidatorToken": 100000000000000000000n,
|
|
165
|
+
"liquidity": 4999999999999999999999999999999999999000n,
|
|
166
|
+
"sender": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
167
|
+
"userToken": "0x20C0000000000000000000000000000000000001",
|
|
168
|
+
"validatorToken": "0x20C0000000000000000000000000000000000000",
|
|
169
|
+
}
|
|
170
|
+
`)
|
|
171
|
+
|
|
172
|
+
// Verify pool reserves
|
|
173
|
+
const pool = await actions.amm.getPool(client, {
|
|
174
|
+
userToken: token,
|
|
175
|
+
validatorToken: usdAddress,
|
|
176
|
+
})
|
|
177
|
+
expect(pool.reserveUserToken).toBe(parseEther('100'))
|
|
178
|
+
expect(pool.reserveValidatorToken).toBe(parseEther('100'))
|
|
179
|
+
|
|
180
|
+
// Verify LP token balance
|
|
181
|
+
const poolId = await actions.amm.getPoolId(client, {
|
|
182
|
+
userToken: token,
|
|
183
|
+
validatorToken: usdAddress,
|
|
184
|
+
})
|
|
185
|
+
const lpBalance = await actions.amm.getLiquidityBalance(client, {
|
|
186
|
+
poolId,
|
|
187
|
+
address: account.address,
|
|
188
|
+
})
|
|
189
|
+
expect(lpBalance).toBeGreaterThan(0n)
|
|
190
|
+
})
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
describe('burn', () => {
|
|
194
|
+
test('default', async () => {
|
|
195
|
+
const { tokenAddress } = await setupPoolWithLiquidity()
|
|
196
|
+
|
|
197
|
+
// Get LP balance before burn
|
|
198
|
+
const poolId = await actions.amm.getPoolId(client, {
|
|
199
|
+
userToken: tokenAddress,
|
|
200
|
+
validatorToken: usdAddress,
|
|
201
|
+
})
|
|
202
|
+
const lpBalanceBefore = await actions.amm.getLiquidityBalance(client, {
|
|
203
|
+
poolId,
|
|
204
|
+
address: account.address,
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
// Burn half of LP tokens
|
|
208
|
+
const { receipt: burnReceipt, ...burnResult } = await actions.amm.burnSync(
|
|
209
|
+
client,
|
|
210
|
+
{
|
|
211
|
+
userToken: tokenAddress,
|
|
212
|
+
validatorToken: usdAddress,
|
|
213
|
+
liquidity: lpBalanceBefore / 2n,
|
|
214
|
+
to: account.address,
|
|
215
|
+
},
|
|
216
|
+
)
|
|
217
|
+
expect(burnReceipt).toBeDefined()
|
|
218
|
+
expect(burnResult).toMatchInlineSnapshot(`
|
|
219
|
+
{
|
|
220
|
+
"amountUserToken": 49999999999999999999n,
|
|
221
|
+
"amountValidatorToken": 49999999999999999999n,
|
|
222
|
+
"liquidity": 2499999999999999999999999999999999999500n,
|
|
223
|
+
"sender": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
224
|
+
"to": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
225
|
+
"userToken": "0x20C0000000000000000000000000000000000001",
|
|
226
|
+
"validatorToken": "0x20C0000000000000000000000000000000000000",
|
|
227
|
+
}
|
|
228
|
+
`)
|
|
229
|
+
|
|
230
|
+
// Verify LP balance decreased
|
|
231
|
+
const lpBalanceAfter = await actions.amm.getLiquidityBalance(client, {
|
|
232
|
+
poolId,
|
|
233
|
+
address: account.address,
|
|
234
|
+
})
|
|
235
|
+
expect(lpBalanceAfter).toBeLessThan(lpBalanceBefore)
|
|
236
|
+
expect(lpBalanceAfter).toBe(lpBalanceBefore / 2n)
|
|
237
|
+
|
|
238
|
+
// Verify pool reserves decreased
|
|
239
|
+
const pool = await actions.amm.getPool(client, {
|
|
240
|
+
userToken: tokenAddress,
|
|
241
|
+
validatorToken: usdAddress,
|
|
242
|
+
})
|
|
243
|
+
expect(pool.reserveUserToken).toBeLessThan(parseEther('100'))
|
|
244
|
+
expect(pool.reserveValidatorToken).toBeLessThan(parseEther('100'))
|
|
245
|
+
})
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
describe('rebalanceSwap', () => {
|
|
249
|
+
test('default', async () => {
|
|
250
|
+
const { tokenAddress } = await setupPoolWithLiquidity()
|
|
251
|
+
|
|
252
|
+
// Get balance before swap
|
|
253
|
+
const balanceBefore = await actions.token.getBalance(client, {
|
|
254
|
+
token: tokenAddress,
|
|
255
|
+
account: account2.address,
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
// Perform rebalance swap
|
|
259
|
+
const { receipt: swapReceipt, ...swapResult } =
|
|
260
|
+
await actions.amm.rebalanceSwapSync(client, {
|
|
261
|
+
userToken: tokenAddress,
|
|
262
|
+
validatorToken: usdAddress,
|
|
263
|
+
amountOut: parseEther('10'),
|
|
264
|
+
to: account2.address,
|
|
265
|
+
account: account,
|
|
266
|
+
})
|
|
267
|
+
expect(swapReceipt).toBeDefined()
|
|
268
|
+
expect(swapResult).toMatchInlineSnapshot(`
|
|
269
|
+
{
|
|
270
|
+
"amountIn": 9985000000000000001n,
|
|
271
|
+
"amountOut": 10000000000000000000n,
|
|
272
|
+
"swapper": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
273
|
+
"userToken": "0x20C0000000000000000000000000000000000001",
|
|
274
|
+
"validatorToken": "0x20C0000000000000000000000000000000000000",
|
|
275
|
+
}
|
|
276
|
+
`)
|
|
277
|
+
|
|
278
|
+
// Verify balance increased
|
|
279
|
+
const balanceAfter = await actions.token.getBalance(client, {
|
|
280
|
+
token: tokenAddress,
|
|
281
|
+
account: account2.address,
|
|
282
|
+
})
|
|
283
|
+
expect(balanceAfter).toBe(balanceBefore + parseEther('10'))
|
|
284
|
+
})
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
describe('watchRebalanceSwap', () => {
|
|
288
|
+
test('default', async () => {
|
|
289
|
+
const { tokenAddress } = await setupPoolWithLiquidity()
|
|
290
|
+
|
|
291
|
+
let eventArgs: any = null
|
|
292
|
+
const unwatch = actions.amm.watchRebalanceSwap(client, {
|
|
293
|
+
onRebalanceSwap: (args) => {
|
|
294
|
+
eventArgs = args
|
|
295
|
+
},
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
// Perform rebalance swap
|
|
299
|
+
await actions.amm.rebalanceSwapSync(client, {
|
|
300
|
+
userToken: tokenAddress,
|
|
301
|
+
validatorToken: usdAddress,
|
|
302
|
+
amountOut: parseEther('10'),
|
|
303
|
+
to: account2.address,
|
|
304
|
+
account: account,
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
await setTimeout(1000)
|
|
308
|
+
|
|
309
|
+
expect(eventArgs).toBeDefined()
|
|
310
|
+
expect(eventArgs.userToken.toLowerCase()).toBe(tokenAddress.toLowerCase())
|
|
311
|
+
expect(eventArgs.validatorToken.toLowerCase()).toBe(
|
|
312
|
+
usdAddress.toLowerCase(),
|
|
313
|
+
)
|
|
314
|
+
expect(eventArgs.amountOut).toBe(parseEther('10'))
|
|
315
|
+
|
|
316
|
+
unwatch()
|
|
317
|
+
})
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
describe('watchMint', () => {
|
|
321
|
+
test('default', async () => {
|
|
322
|
+
// Create a new token for testing
|
|
323
|
+
const { token } = await actions.token.createSync(client, {
|
|
324
|
+
name: 'Test Token 2',
|
|
325
|
+
symbol: 'TEST2',
|
|
326
|
+
currency: 'USD',
|
|
327
|
+
})
|
|
328
|
+
|
|
329
|
+
// Grant issuer role to mint tokens
|
|
330
|
+
await actions.token.grantRolesSync(client, {
|
|
331
|
+
token,
|
|
332
|
+
roles: ['issuer'],
|
|
333
|
+
to: client.account.address,
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
// Mint some tokens to account
|
|
337
|
+
await actions.token.mintSync(client, {
|
|
338
|
+
to: account.address,
|
|
339
|
+
amount: parseEther('1000'),
|
|
340
|
+
token,
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
// Mint USD to account
|
|
344
|
+
await writeContractSync(client, {
|
|
345
|
+
abi: tip20Abi,
|
|
346
|
+
address: usdAddress,
|
|
347
|
+
functionName: 'transfer',
|
|
348
|
+
args: [account.address, parseEther('1000')],
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
let eventArgs: any = null
|
|
352
|
+
const unwatch = actions.amm.watchMint(client, {
|
|
353
|
+
onMint: (args) => {
|
|
354
|
+
eventArgs = args
|
|
355
|
+
},
|
|
356
|
+
})
|
|
357
|
+
|
|
358
|
+
// Add liquidity to pool
|
|
359
|
+
await actions.amm.mintSync(client, {
|
|
360
|
+
userToken: {
|
|
361
|
+
address: token,
|
|
362
|
+
amount: parseEther('100'),
|
|
363
|
+
},
|
|
364
|
+
validatorToken: {
|
|
365
|
+
address: usdAddress,
|
|
366
|
+
amount: parseEther('100'),
|
|
367
|
+
},
|
|
368
|
+
to: account.address,
|
|
369
|
+
})
|
|
370
|
+
|
|
371
|
+
await setTimeout(1000)
|
|
372
|
+
|
|
373
|
+
expect(eventArgs).toBeDefined()
|
|
374
|
+
expect(eventArgs.userToken.address.toLowerCase()).toBe(token.toLowerCase())
|
|
375
|
+
expect(eventArgs.validatorToken.address.toLowerCase()).toBe(
|
|
376
|
+
usdAddress.toLowerCase(),
|
|
377
|
+
)
|
|
378
|
+
expect(eventArgs.userToken.amount).toBe(parseEther('100'))
|
|
379
|
+
expect(eventArgs.validatorToken.amount).toBe(parseEther('100'))
|
|
380
|
+
|
|
381
|
+
unwatch()
|
|
382
|
+
})
|
|
383
|
+
})
|
|
384
|
+
|
|
385
|
+
describe('watchBurn', () => {
|
|
386
|
+
test('default', async () => {
|
|
387
|
+
const { tokenAddress } = await setupPoolWithLiquidity()
|
|
388
|
+
|
|
389
|
+
// Get LP balance
|
|
390
|
+
const poolId = await actions.amm.getPoolId(client, {
|
|
391
|
+
userToken: tokenAddress,
|
|
392
|
+
validatorToken: usdAddress,
|
|
393
|
+
})
|
|
394
|
+
const lpBalance = await actions.amm.getLiquidityBalance(client, {
|
|
395
|
+
poolId,
|
|
396
|
+
address: account.address,
|
|
397
|
+
})
|
|
398
|
+
|
|
399
|
+
let eventArgs: any = null
|
|
400
|
+
const unwatch = actions.amm.watchBurn(client, {
|
|
401
|
+
onBurn: (args) => {
|
|
402
|
+
eventArgs = args
|
|
403
|
+
},
|
|
404
|
+
})
|
|
405
|
+
|
|
406
|
+
// Burn LP tokens
|
|
407
|
+
await actions.amm.burnSync(client, {
|
|
408
|
+
userToken: tokenAddress,
|
|
409
|
+
validatorToken: usdAddress,
|
|
410
|
+
liquidity: lpBalance / 2n,
|
|
411
|
+
to: account.address,
|
|
412
|
+
})
|
|
413
|
+
|
|
414
|
+
await setTimeout(1000)
|
|
415
|
+
|
|
416
|
+
expect(eventArgs).toBeDefined()
|
|
417
|
+
expect(eventArgs.userToken.toLowerCase()).toBe(tokenAddress.toLowerCase())
|
|
418
|
+
expect(eventArgs.validatorToken.toLowerCase()).toBe(
|
|
419
|
+
usdAddress.toLowerCase(),
|
|
420
|
+
)
|
|
421
|
+
expect(eventArgs.liquidity).toBe(lpBalance / 2n)
|
|
422
|
+
|
|
423
|
+
unwatch()
|
|
424
|
+
})
|
|
425
|
+
})
|