tempo.ts 0.11.1 → 0.12.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/CHANGELOG.md +67 -4
- package/README.md +3 -34
- package/dist/server/Handler.d.ts +14 -14
- package/dist/server/Handler.d.ts.map +1 -1
- package/dist/server/Handler.js +16 -17
- package/dist/server/Handler.js.map +1 -1
- package/dist/wagmi/Actions/amm.d.ts +51 -51
- package/dist/wagmi/Actions/amm.d.ts.map +1 -1
- package/dist/wagmi/Actions/amm.js +37 -37
- package/dist/wagmi/Actions/amm.js.map +1 -1
- package/dist/wagmi/Actions/dex.d.ts +129 -129
- package/dist/wagmi/Actions/dex.d.ts.map +1 -1
- package/dist/wagmi/Actions/dex.js +73 -73
- package/dist/wagmi/Actions/dex.js.map +1 -1
- package/dist/wagmi/Actions/faucet.d.ts +9 -9
- package/dist/wagmi/Actions/faucet.d.ts.map +1 -1
- package/dist/wagmi/Actions/faucet.js +7 -7
- package/dist/wagmi/Actions/faucet.js.map +1 -1
- package/dist/wagmi/Actions/fee.d.ts +17 -17
- package/dist/wagmi/Actions/fee.d.ts.map +1 -1
- package/dist/wagmi/Actions/fee.js +10 -10
- package/dist/wagmi/Actions/fee.js.map +1 -1
- package/dist/wagmi/Actions/nonce.d.ts +9 -79
- package/dist/wagmi/Actions/nonce.d.ts.map +1 -1
- package/dist/wagmi/Actions/nonce.js +7 -89
- package/dist/wagmi/Actions/nonce.js.map +1 -1
- package/dist/wagmi/Actions/policy.d.ts +69 -70
- package/dist/wagmi/Actions/policy.d.ts.map +1 -1
- package/dist/wagmi/Actions/policy.js +43 -43
- package/dist/wagmi/Actions/policy.js.map +1 -1
- package/dist/wagmi/Actions/reward.d.ts +51 -51
- package/dist/wagmi/Actions/reward.d.ts.map +1 -1
- package/dist/wagmi/Actions/reward.js +31 -31
- package/dist/wagmi/Actions/reward.js.map +1 -1
- package/dist/wagmi/Actions/token.d.ts +238 -238
- package/dist/wagmi/Actions/token.d.ts.map +1 -1
- package/dist/wagmi/Actions/token.js +136 -136
- package/dist/wagmi/Actions/token.js.map +1 -1
- package/dist/wagmi/Connector.d.ts +2 -1
- package/dist/wagmi/Connector.d.ts.map +1 -1
- package/dist/wagmi/Connector.js +83 -22
- package/dist/wagmi/Connector.js.map +1 -1
- package/dist/wagmi/Hooks/nonce.d.ts +1 -52
- package/dist/wagmi/Hooks/nonce.d.ts.map +1 -1
- package/dist/wagmi/Hooks/nonce.js +1 -70
- package/dist/wagmi/Hooks/nonce.js.map +1 -1
- package/dist/wagmi/Hooks/policy.d.ts +0 -1
- package/dist/wagmi/Hooks/policy.d.ts.map +1 -1
- package/dist/wagmi/Hooks/policy.js.map +1 -1
- package/dist/wagmi/KeyManager.d.ts +6 -3
- package/dist/wagmi/KeyManager.d.ts.map +1 -1
- package/dist/wagmi/KeyManager.js +9 -4
- package/dist/wagmi/KeyManager.js.map +1 -1
- package/package.json +3 -13
- package/src/server/Handler.test.ts +2 -2
- package/src/server/Handler.ts +16 -17
- package/src/wagmi/Actions/amm.ts +63 -63
- package/src/wagmi/Actions/dex.test.ts +1 -1
- package/src/wagmi/Actions/dex.ts +153 -153
- package/src/wagmi/Actions/faucet.ts +11 -11
- package/src/wagmi/Actions/fee.ts +20 -20
- package/src/wagmi/Actions/nonce.test.ts +1 -64
- package/src/wagmi/Actions/nonce.ts +10 -142
- package/src/wagmi/Actions/policy.ts +83 -85
- package/src/wagmi/Actions/reward.ts +64 -61
- package/src/wagmi/Actions/token.ts +287 -283
- package/src/wagmi/Connector.ts +105 -31
- package/src/wagmi/Hooks/dex.test.ts +1 -1
- package/src/wagmi/Hooks/fee.test.ts +0 -6
- package/src/wagmi/Hooks/nonce.test.ts +1 -66
- package/src/wagmi/Hooks/nonce.ts +1 -114
- package/src/wagmi/Hooks/policy.ts +0 -2
- package/src/wagmi/KeyManager.ts +18 -5
- package/dist/chains.d.ts +0 -73
- package/dist/chains.d.ts.map +0 -1
- package/dist/chains.js +0 -51
- package/dist/chains.js.map +0 -1
- package/dist/viem/Abis.d.ts +0 -2649
- package/dist/viem/Abis.d.ts.map +0 -1
- package/dist/viem/Abis.js +0 -1677
- package/dist/viem/Abis.js.map +0 -1
- package/dist/viem/Account.d.ts +0 -244
- package/dist/viem/Account.d.ts.map +0 -1
- package/dist/viem/Account.js +0 -382
- package/dist/viem/Account.js.map +0 -1
- package/dist/viem/Actions/account.d.ts +0 -40
- package/dist/viem/Actions/account.d.ts.map +0 -1
- package/dist/viem/Actions/account.js +0 -86
- package/dist/viem/Actions/account.js.map +0 -1
- package/dist/viem/Actions/amm.d.ts +0 -1991
- package/dist/viem/Actions/amm.d.ts.map +0 -1
- package/dist/viem/Actions/amm.js +0 -814
- package/dist/viem/Actions/amm.js.map +0 -1
- package/dist/viem/Actions/dex.d.ts +0 -3900
- package/dist/viem/Actions/dex.d.ts.map +0 -1
- package/dist/viem/Actions/dex.js +0 -1414
- package/dist/viem/Actions/dex.js.map +0 -1
- package/dist/viem/Actions/faucet.d.ts +0 -69
- package/dist/viem/Actions/faucet.d.ts.map +0 -1
- package/dist/viem/Actions/faucet.js +0 -73
- package/dist/viem/Actions/faucet.js.map +0 -1
- package/dist/viem/Actions/fee.d.ts +0 -360
- package/dist/viem/Actions/fee.d.ts.map +0 -1
- package/dist/viem/Actions/fee.js +0 -237
- package/dist/viem/Actions/fee.js.map +0 -1
- package/dist/viem/Actions/index.d.ts +0 -10
- package/dist/viem/Actions/index.d.ts.map +0 -1
- package/dist/viem/Actions/index.js +0 -10
- package/dist/viem/Actions/index.js.map +0 -1
- package/dist/viem/Actions/nonce.d.ts +0 -257
- package/dist/viem/Actions/nonce.d.ts.map +0 -1
- package/dist/viem/Actions/nonce.js +0 -228
- package/dist/viem/Actions/nonce.js.map +0 -1
- package/dist/viem/Actions/policy.d.ts +0 -1680
- package/dist/viem/Actions/policy.d.ts.map +0 -1
- package/dist/viem/Actions/policy.js +0 -875
- package/dist/viem/Actions/policy.js.map +0 -1
- package/dist/viem/Actions/reward.d.ts +0 -2422
- package/dist/viem/Actions/reward.d.ts.map +0 -1
- package/dist/viem/Actions/reward.js +0 -651
- package/dist/viem/Actions/reward.js.map +0 -1
- package/dist/viem/Actions/token.d.ts +0 -16007
- package/dist/viem/Actions/token.d.ts.map +0 -1
- package/dist/viem/Actions/token.js +0 -2936
- package/dist/viem/Actions/token.js.map +0 -1
- package/dist/viem/Addresses.d.ts +0 -9
- package/dist/viem/Addresses.d.ts.map +0 -1
- package/dist/viem/Addresses.js +0 -9
- package/dist/viem/Addresses.js.map +0 -1
- package/dist/viem/Chain.d.ts +0 -451
- package/dist/viem/Chain.d.ts.map +0 -1
- package/dist/viem/Chain.js +0 -96
- package/dist/viem/Chain.js.map +0 -1
- package/dist/viem/Decorator.d.ts +0 -2783
- package/dist/viem/Decorator.d.ts.map +0 -1
- package/dist/viem/Decorator.js +0 -137
- package/dist/viem/Decorator.js.map +0 -1
- package/dist/viem/Formatters.d.ts +0 -10
- package/dist/viem/Formatters.d.ts.map +0 -1
- package/dist/viem/Formatters.js +0 -104
- package/dist/viem/Formatters.js.map +0 -1
- package/dist/viem/P256.d.ts +0 -2
- package/dist/viem/P256.d.ts.map +0 -1
- package/dist/viem/P256.js +0 -2
- package/dist/viem/P256.js.map +0 -1
- package/dist/viem/Secp256k1.d.ts +0 -2
- package/dist/viem/Secp256k1.d.ts.map +0 -1
- package/dist/viem/Secp256k1.js +0 -2
- package/dist/viem/Secp256k1.js.map +0 -1
- package/dist/viem/Storage.d.ts +0 -24
- package/dist/viem/Storage.d.ts.map +0 -1
- package/dist/viem/Storage.js +0 -68
- package/dist/viem/Storage.js.map +0 -1
- package/dist/viem/TokenIds.d.ts +0 -2
- package/dist/viem/TokenIds.d.ts.map +0 -1
- package/dist/viem/TokenIds.js +0 -2
- package/dist/viem/TokenIds.js.map +0 -1
- package/dist/viem/Transaction.d.ts +0 -76
- package/dist/viem/Transaction.d.ts.map +0 -1
- package/dist/viem/Transaction.js +0 -176
- package/dist/viem/Transaction.js.map +0 -1
- package/dist/viem/Transport.d.ts +0 -33
- package/dist/viem/Transport.d.ts.map +0 -1
- package/dist/viem/Transport.js +0 -138
- package/dist/viem/Transport.js.map +0 -1
- package/dist/viem/WebAuthnP256.d.ts +0 -82
- package/dist/viem/WebAuthnP256.d.ts.map +0 -1
- package/dist/viem/WebAuthnP256.js +0 -97
- package/dist/viem/WebAuthnP256.js.map +0 -1
- package/dist/viem/WebCryptoP256.d.ts +0 -2
- package/dist/viem/WebCryptoP256.d.ts.map +0 -1
- package/dist/viem/WebCryptoP256.js +0 -2
- package/dist/viem/WebCryptoP256.js.map +0 -1
- package/dist/viem/index.d.ts +0 -26
- package/dist/viem/index.d.ts.map +0 -1
- package/dist/viem/index.js +0 -17
- package/dist/viem/index.js.map +0 -1
- package/dist/viem/internal/types.d.ts +0 -20
- package/dist/viem/internal/types.d.ts.map +0 -1
- package/dist/viem/internal/types.js +0 -2
- package/dist/viem/internal/types.js.map +0 -1
- package/dist/viem/internal/utils.d.ts +0 -14
- package/dist/viem/internal/utils.d.ts.map +0 -1
- package/dist/viem/internal/utils.js +0 -33
- package/dist/viem/internal/utils.js.map +0 -1
- package/src/chains.ts +0 -54
- package/src/viem/Abis.ts +0 -1688
- package/src/viem/Account.test.ts +0 -444
- package/src/viem/Account.ts +0 -601
- package/src/viem/Actions/account.test.ts +0 -414
- package/src/viem/Actions/account.ts +0 -106
- package/src/viem/Actions/amm.test.ts +0 -381
- package/src/viem/Actions/amm.ts +0 -1227
- package/src/viem/Actions/dex.test.ts +0 -1549
- package/src/viem/Actions/dex.ts +0 -2150
- package/src/viem/Actions/faucet.ts +0 -121
- package/src/viem/Actions/fee.test.ts +0 -259
- package/src/viem/Actions/fee.ts +0 -372
- package/src/viem/Actions/index.ts +0 -9
- package/src/viem/Actions/nonce.test.ts +0 -206
- package/src/viem/Actions/nonce.ts +0 -347
- package/src/viem/Actions/policy.test.ts +0 -534
- package/src/viem/Actions/policy.ts +0 -1335
- package/src/viem/Actions/reward.test.ts +0 -434
- package/src/viem/Actions/reward.ts +0 -944
- package/src/viem/Actions/token.test.ts +0 -3029
- package/src/viem/Actions/token.ts +0 -4458
- package/src/viem/Addresses.ts +0 -9
- package/src/viem/Chain.bench-d.ts +0 -12
- package/src/viem/Chain.test.ts +0 -168
- package/src/viem/Chain.ts +0 -157
- package/src/viem/Decorator.bench-d.ts +0 -11
- package/src/viem/Decorator.test.ts +0 -39
- package/src/viem/Decorator.ts +0 -3179
- package/src/viem/Formatters.ts +0 -164
- package/src/viem/P256.ts +0 -1
- package/src/viem/Secp256k1.ts +0 -1
- package/src/viem/Storage.ts +0 -110
- package/src/viem/TokenIds.ts +0 -1
- package/src/viem/Transaction.ts +0 -382
- package/src/viem/Transport.ts +0 -191
- package/src/viem/WebAuthnP256.ts +0 -146
- package/src/viem/WebCryptoP256.ts +0 -1
- package/src/viem/e2e.test.ts +0 -1602
- package/src/viem/index.ts +0 -30
- package/src/viem/internal/types.ts +0 -69
- package/src/viem/internal/utils.ts +0 -58
- package/src/wagmi/internal/types.ts +0 -16
|
@@ -1,381 +0,0 @@
|
|
|
1
|
-
import { setTimeout } from 'node:timers/promises'
|
|
2
|
-
import { Abis, Actions } from 'tempo.ts/viem'
|
|
3
|
-
import { parseUnits } from 'viem'
|
|
4
|
-
import { writeContractSync } from 'viem/actions'
|
|
5
|
-
import { describe, expect, test } from 'vitest'
|
|
6
|
-
import {
|
|
7
|
-
accounts,
|
|
8
|
-
clientWithAccount,
|
|
9
|
-
setupPoolWithLiquidity,
|
|
10
|
-
} from '../../../test/viem/config.js'
|
|
11
|
-
|
|
12
|
-
const account = accounts[0]
|
|
13
|
-
const account2 = accounts[1]
|
|
14
|
-
|
|
15
|
-
describe('getPool', () => {
|
|
16
|
-
test('default', async () => {
|
|
17
|
-
const pool = await Actions.amm.getPool(clientWithAccount, {
|
|
18
|
-
userToken: 1n,
|
|
19
|
-
validatorToken: '0x20c0000000000000000000000000000000000001',
|
|
20
|
-
})
|
|
21
|
-
expect(pool).toMatchInlineSnapshot(`
|
|
22
|
-
{
|
|
23
|
-
"reserveUserToken": 0n,
|
|
24
|
-
"reserveValidatorToken": 0n,
|
|
25
|
-
"totalSupply": 0n,
|
|
26
|
-
}
|
|
27
|
-
`)
|
|
28
|
-
})
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
describe('getLiquidityBalance', () => {
|
|
32
|
-
test('default', async () => {
|
|
33
|
-
const balance = await Actions.amm.getLiquidityBalance(clientWithAccount, {
|
|
34
|
-
address: account.address,
|
|
35
|
-
userToken: 1n,
|
|
36
|
-
validatorToken: '0x20c0000000000000000000000000000000000001',
|
|
37
|
-
})
|
|
38
|
-
expect(typeof balance).toBe('bigint')
|
|
39
|
-
})
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
describe('mint', () => {
|
|
43
|
-
test('default', async () => {
|
|
44
|
-
// Create a new token for testing
|
|
45
|
-
const { token } = await Actions.token.createSync(clientWithAccount, {
|
|
46
|
-
name: 'Test Token 2',
|
|
47
|
-
symbol: 'TEST2',
|
|
48
|
-
currency: 'USD',
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
// Grant issuer role to mint tokens
|
|
52
|
-
await Actions.token.grantRolesSync(clientWithAccount, {
|
|
53
|
-
token,
|
|
54
|
-
roles: ['issuer'],
|
|
55
|
-
to: clientWithAccount.account.address,
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
// Mint some tokens to account
|
|
59
|
-
await Actions.token.mintSync(clientWithAccount, {
|
|
60
|
-
to: account.address,
|
|
61
|
-
amount: parseUnits('1000', 6),
|
|
62
|
-
token,
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
// First, establish initial liquidity with two-sided mint
|
|
66
|
-
await Actions.amm.mintSync(clientWithAccount, {
|
|
67
|
-
to: account.address,
|
|
68
|
-
userTokenAddress: token,
|
|
69
|
-
validatorTokenAddress: 1n,
|
|
70
|
-
validatorTokenAmount: parseUnits('100', 6),
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
// Get initial pool state
|
|
74
|
-
const poolBefore = await Actions.amm.getPool(clientWithAccount, {
|
|
75
|
-
userToken: token,
|
|
76
|
-
validatorToken: 1n,
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
// Add single-sided liquidity (only validatorToken)
|
|
80
|
-
const { receipt: mintReceipt, ...mintResult } = await Actions.amm.mintSync(
|
|
81
|
-
clientWithAccount,
|
|
82
|
-
{
|
|
83
|
-
userTokenAddress: token,
|
|
84
|
-
validatorTokenAddress: 1n,
|
|
85
|
-
validatorTokenAmount: parseUnits('50', 6),
|
|
86
|
-
to: account.address,
|
|
87
|
-
},
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
expect(mintReceipt).toBeDefined()
|
|
91
|
-
// amountUserToken should be 0 for single-sided mint
|
|
92
|
-
expect(mintResult.amountUserToken).toBe(0n)
|
|
93
|
-
expect(mintResult.amountValidatorToken).toBe(parseUnits('50', 6))
|
|
94
|
-
expect(mintResult.liquidity).toBeGreaterThan(0n)
|
|
95
|
-
|
|
96
|
-
// Verify pool reserves - only validatorToken should increase
|
|
97
|
-
const poolAfter = await Actions.amm.getPool(clientWithAccount, {
|
|
98
|
-
userToken: token,
|
|
99
|
-
validatorToken: 1n,
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
expect(poolAfter.reserveUserToken).toBe(poolBefore.reserveUserToken)
|
|
103
|
-
expect(poolAfter.reserveValidatorToken).toBe(
|
|
104
|
-
poolBefore.reserveValidatorToken + parseUnits('50', 6),
|
|
105
|
-
)
|
|
106
|
-
expect(poolAfter.totalSupply).toBeGreaterThan(poolBefore.totalSupply)
|
|
107
|
-
})
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
describe.skip('burn', () => {
|
|
111
|
-
test('default', async () => {
|
|
112
|
-
const { tokenAddress } = await setupPoolWithLiquidity(clientWithAccount)
|
|
113
|
-
|
|
114
|
-
// Get LP balance before burn
|
|
115
|
-
const lpBalanceBefore = await Actions.amm.getLiquidityBalance(
|
|
116
|
-
clientWithAccount,
|
|
117
|
-
{
|
|
118
|
-
address: account.address,
|
|
119
|
-
userToken: tokenAddress,
|
|
120
|
-
validatorToken: 1n,
|
|
121
|
-
},
|
|
122
|
-
)
|
|
123
|
-
|
|
124
|
-
// TODO(TEMPO-1183): Remove this janky fix to get some user token in the pool
|
|
125
|
-
await Actions.token.transferSync(clientWithAccount, {
|
|
126
|
-
to: '0x30D861999070Ae03B9548501DBd573E11A9f59Ee',
|
|
127
|
-
amount: 600n,
|
|
128
|
-
token: tokenAddress,
|
|
129
|
-
feeToken: tokenAddress,
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
// Burn half of LP tokens
|
|
133
|
-
const {
|
|
134
|
-
receipt: burnReceipt,
|
|
135
|
-
userToken,
|
|
136
|
-
...burnResult
|
|
137
|
-
} = await Actions.amm.burnSync(clientWithAccount, {
|
|
138
|
-
userToken: tokenAddress,
|
|
139
|
-
validatorToken: 1n,
|
|
140
|
-
liquidity: lpBalanceBefore / 2n,
|
|
141
|
-
to: account2.address,
|
|
142
|
-
})
|
|
143
|
-
const { sender, to, ...rest } = burnResult
|
|
144
|
-
|
|
145
|
-
expect(burnReceipt).toBeDefined()
|
|
146
|
-
expect(userToken).toBe(tokenAddress)
|
|
147
|
-
expect(sender).toBe(account.address)
|
|
148
|
-
expect(to).toBe(account2.address)
|
|
149
|
-
expect(rest).toMatchInlineSnapshot(`
|
|
150
|
-
{
|
|
151
|
-
"amountUserToken": 337n,
|
|
152
|
-
"amountValidatorToken": 49998664n,
|
|
153
|
-
"liquidity": 24999500n,
|
|
154
|
-
"validatorToken": "0x20C0000000000000000000000000000000000001",
|
|
155
|
-
}
|
|
156
|
-
`)
|
|
157
|
-
|
|
158
|
-
// Verify LP balance decreased
|
|
159
|
-
const lpBalanceAfter = await Actions.amm.getLiquidityBalance(
|
|
160
|
-
clientWithAccount,
|
|
161
|
-
{
|
|
162
|
-
address: account.address,
|
|
163
|
-
userToken: tokenAddress,
|
|
164
|
-
validatorToken: 1n,
|
|
165
|
-
},
|
|
166
|
-
)
|
|
167
|
-
expect(lpBalanceAfter).toBeLessThan(lpBalanceBefore)
|
|
168
|
-
expect(lpBalanceAfter).toBe(lpBalanceBefore / 2n)
|
|
169
|
-
|
|
170
|
-
// Verify pool reserves decreased
|
|
171
|
-
const pool = await Actions.amm.getPool(clientWithAccount, {
|
|
172
|
-
userToken: tokenAddress,
|
|
173
|
-
validatorToken: 1n,
|
|
174
|
-
})
|
|
175
|
-
expect(pool).toMatchInlineSnapshot(`
|
|
176
|
-
{
|
|
177
|
-
"reserveUserToken": 338n,
|
|
178
|
-
"reserveValidatorToken": 50000664n,
|
|
179
|
-
"totalSupply": 25000500n,
|
|
180
|
-
}
|
|
181
|
-
`)
|
|
182
|
-
})
|
|
183
|
-
})
|
|
184
|
-
|
|
185
|
-
describe.skip('rebalanceSwap', () => {
|
|
186
|
-
test('default', async () => {
|
|
187
|
-
const { tokenAddress } = await setupPoolWithLiquidity(clientWithAccount)
|
|
188
|
-
|
|
189
|
-
// TODO(TEMPO-1183): Remove this janky fix to get some user token in the pool
|
|
190
|
-
await Actions.token.transferSync(clientWithAccount, {
|
|
191
|
-
to: '0x30D861999070Ae03B9548501DBd573E11A9f59Ee',
|
|
192
|
-
amount: 600n,
|
|
193
|
-
token: tokenAddress,
|
|
194
|
-
feeToken: tokenAddress,
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
// Get balance before swap
|
|
198
|
-
const balanceBefore = await Actions.token.getBalance(clientWithAccount, {
|
|
199
|
-
token: tokenAddress,
|
|
200
|
-
account: account2.address,
|
|
201
|
-
})
|
|
202
|
-
|
|
203
|
-
// Perform rebalance swap
|
|
204
|
-
const {
|
|
205
|
-
receipt: swapReceipt,
|
|
206
|
-
swapper,
|
|
207
|
-
userToken,
|
|
208
|
-
...swapResult
|
|
209
|
-
} = await Actions.amm.rebalanceSwapSync(clientWithAccount, {
|
|
210
|
-
userToken: tokenAddress,
|
|
211
|
-
validatorToken: 1n,
|
|
212
|
-
amountOut: 100n,
|
|
213
|
-
to: account2.address,
|
|
214
|
-
account: account,
|
|
215
|
-
})
|
|
216
|
-
expect(swapReceipt).toBeDefined()
|
|
217
|
-
expect(userToken).toBe(tokenAddress)
|
|
218
|
-
expect(swapper).toBe(account.address)
|
|
219
|
-
expect(swapResult).toMatchInlineSnapshot(`
|
|
220
|
-
{
|
|
221
|
-
"amountIn": 100n,
|
|
222
|
-
"amountOut": 100n,
|
|
223
|
-
"validatorToken": "0x20C0000000000000000000000000000000000001",
|
|
224
|
-
}
|
|
225
|
-
`)
|
|
226
|
-
|
|
227
|
-
// Verify balance increased
|
|
228
|
-
const balanceAfter = await Actions.token.getBalance(clientWithAccount, {
|
|
229
|
-
token: tokenAddress,
|
|
230
|
-
account: account2.address,
|
|
231
|
-
})
|
|
232
|
-
expect(balanceAfter).toBe(balanceBefore + 100n)
|
|
233
|
-
})
|
|
234
|
-
})
|
|
235
|
-
|
|
236
|
-
describe.skip('watchRebalanceSwap', () => {
|
|
237
|
-
test('default', async () => {
|
|
238
|
-
const { tokenAddress } = await setupPoolWithLiquidity(clientWithAccount)
|
|
239
|
-
|
|
240
|
-
// TODO(TEMPO-1183): Remove this janky fix to get some user token in the pool
|
|
241
|
-
await Actions.token.transferSync(clientWithAccount, {
|
|
242
|
-
to: '0x30D861999070Ae03B9548501DBd573E11A9f59Ee',
|
|
243
|
-
amount: 600n,
|
|
244
|
-
token: tokenAddress,
|
|
245
|
-
feeToken: tokenAddress,
|
|
246
|
-
})
|
|
247
|
-
|
|
248
|
-
let eventArgs: any = null
|
|
249
|
-
const unwatch = Actions.amm.watchRebalanceSwap(clientWithAccount, {
|
|
250
|
-
onRebalanceSwap: (args) => {
|
|
251
|
-
eventArgs = args
|
|
252
|
-
},
|
|
253
|
-
})
|
|
254
|
-
|
|
255
|
-
// Perform rebalance swap
|
|
256
|
-
await Actions.amm.rebalanceSwapSync(clientWithAccount, {
|
|
257
|
-
userToken: tokenAddress,
|
|
258
|
-
validatorToken: 1n,
|
|
259
|
-
amountOut: 100n,
|
|
260
|
-
to: account2.address,
|
|
261
|
-
account: account,
|
|
262
|
-
})
|
|
263
|
-
|
|
264
|
-
await setTimeout(1000)
|
|
265
|
-
|
|
266
|
-
expect(eventArgs).toBeDefined()
|
|
267
|
-
expect(eventArgs.userToken.toLowerCase()).toBe(tokenAddress.toLowerCase())
|
|
268
|
-
expect(eventArgs.validatorToken.toLowerCase()).toBe(
|
|
269
|
-
'0x20c0000000000000000000000000000000000001',
|
|
270
|
-
)
|
|
271
|
-
expect(eventArgs.amountOut).toBe(100n)
|
|
272
|
-
|
|
273
|
-
unwatch()
|
|
274
|
-
})
|
|
275
|
-
})
|
|
276
|
-
|
|
277
|
-
describe('watchMint', () => {
|
|
278
|
-
test('default', async () => {
|
|
279
|
-
// Create a new token for testing
|
|
280
|
-
const { token } = await Actions.token.createSync(clientWithAccount, {
|
|
281
|
-
name: 'Test Token 2',
|
|
282
|
-
symbol: 'TEST2',
|
|
283
|
-
currency: 'USD',
|
|
284
|
-
})
|
|
285
|
-
|
|
286
|
-
// Grant issuer role to mint tokens
|
|
287
|
-
await Actions.token.grantRolesSync(clientWithAccount, {
|
|
288
|
-
token,
|
|
289
|
-
roles: ['issuer'],
|
|
290
|
-
to: clientWithAccount.account.address,
|
|
291
|
-
})
|
|
292
|
-
|
|
293
|
-
// Mint some tokens to account
|
|
294
|
-
await Actions.token.mintSync(clientWithAccount, {
|
|
295
|
-
to: account.address,
|
|
296
|
-
amount: parseUnits('1000', 6),
|
|
297
|
-
token,
|
|
298
|
-
})
|
|
299
|
-
|
|
300
|
-
// Mint USD to account
|
|
301
|
-
await writeContractSync(clientWithAccount, {
|
|
302
|
-
abi: Abis.tip20,
|
|
303
|
-
address: '0x20c0000000000000000000000000000000000001',
|
|
304
|
-
functionName: 'transfer',
|
|
305
|
-
args: [account.address, parseUnits('1000', 6)],
|
|
306
|
-
})
|
|
307
|
-
|
|
308
|
-
let eventArgs: any = null
|
|
309
|
-
const unwatch = Actions.amm.watchMint(clientWithAccount, {
|
|
310
|
-
onMint: (args) => {
|
|
311
|
-
eventArgs = args
|
|
312
|
-
},
|
|
313
|
-
})
|
|
314
|
-
|
|
315
|
-
// Add liquidity to pool
|
|
316
|
-
await Actions.amm.mintSync(clientWithAccount, {
|
|
317
|
-
userTokenAddress: token,
|
|
318
|
-
validatorTokenAddress: 1n,
|
|
319
|
-
validatorTokenAmount: parseUnits('100', 6),
|
|
320
|
-
to: account.address,
|
|
321
|
-
})
|
|
322
|
-
|
|
323
|
-
await setTimeout(1000)
|
|
324
|
-
|
|
325
|
-
expect(eventArgs).toBeDefined()
|
|
326
|
-
expect(eventArgs.userToken.address.toLowerCase()).toBe(token.toLowerCase())
|
|
327
|
-
expect(eventArgs.validatorToken.address.toLowerCase()).toBe(
|
|
328
|
-
'0x20c0000000000000000000000000000000000001',
|
|
329
|
-
)
|
|
330
|
-
expect(eventArgs.validatorToken.amount).toBe(parseUnits('100', 6))
|
|
331
|
-
|
|
332
|
-
unwatch()
|
|
333
|
-
})
|
|
334
|
-
})
|
|
335
|
-
|
|
336
|
-
describe.skip('watchBurn', () => {
|
|
337
|
-
test('default', async () => {
|
|
338
|
-
const { tokenAddress } = await setupPoolWithLiquidity(clientWithAccount)
|
|
339
|
-
|
|
340
|
-
// Get LP balance
|
|
341
|
-
const lpBalance = await Actions.amm.getLiquidityBalance(clientWithAccount, {
|
|
342
|
-
userToken: tokenAddress,
|
|
343
|
-
validatorToken: 1n,
|
|
344
|
-
address: account.address,
|
|
345
|
-
})
|
|
346
|
-
|
|
347
|
-
// TODO(TEMPO-1183): Remove this janky fix to get some user token in the pool
|
|
348
|
-
await Actions.token.transferSync(clientWithAccount, {
|
|
349
|
-
to: '0x30D861999070Ae03B9548501DBd573E11A9f59Ee',
|
|
350
|
-
amount: 600n,
|
|
351
|
-
token: tokenAddress,
|
|
352
|
-
feeToken: tokenAddress,
|
|
353
|
-
})
|
|
354
|
-
|
|
355
|
-
let eventArgs: any = null
|
|
356
|
-
const unwatch = Actions.amm.watchBurn(clientWithAccount, {
|
|
357
|
-
onBurn: (args) => {
|
|
358
|
-
eventArgs = args
|
|
359
|
-
},
|
|
360
|
-
})
|
|
361
|
-
|
|
362
|
-
// Burn LP tokens
|
|
363
|
-
await Actions.amm.burnSync(clientWithAccount, {
|
|
364
|
-
userToken: tokenAddress,
|
|
365
|
-
validatorToken: 1n,
|
|
366
|
-
liquidity: lpBalance / 2n,
|
|
367
|
-
to: account.address,
|
|
368
|
-
})
|
|
369
|
-
|
|
370
|
-
await setTimeout(1000)
|
|
371
|
-
|
|
372
|
-
expect(eventArgs).toBeDefined()
|
|
373
|
-
expect(eventArgs.userToken.toLowerCase()).toBe(tokenAddress.toLowerCase())
|
|
374
|
-
expect(eventArgs.validatorToken.toLowerCase()).toBe(
|
|
375
|
-
'0x20c0000000000000000000000000000000000001',
|
|
376
|
-
)
|
|
377
|
-
expect(eventArgs.liquidity).toBe(lpBalance / 2n)
|
|
378
|
-
|
|
379
|
-
unwatch()
|
|
380
|
-
})
|
|
381
|
-
})
|