tempo.ts 0.0.5 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chains.d.ts +244 -541
- package/dist/chains.d.ts.map +1 -1
- package/dist/chains.js +10 -23
- package/dist/chains.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/ox/SignatureEnvelope.d.ts +245 -0
- package/dist/ox/SignatureEnvelope.d.ts.map +1 -0
- package/dist/ox/SignatureEnvelope.js +437 -0
- package/dist/ox/SignatureEnvelope.js.map +1 -0
- package/dist/ox/Transaction.d.ts +61 -24
- package/dist/ox/Transaction.d.ts.map +1 -1
- package/dist/ox/Transaction.js +63 -18
- package/dist/ox/Transaction.js.map +1 -1
- package/dist/ox/TransactionEnvelopeAA.d.ts +461 -0
- package/dist/ox/TransactionEnvelopeAA.d.ts.map +1 -0
- package/dist/ox/TransactionEnvelopeAA.js +528 -0
- package/dist/ox/TransactionEnvelopeAA.js.map +1 -0
- package/dist/ox/TransactionRequest.d.ts +7 -5
- package/dist/ox/TransactionRequest.d.ts.map +1 -1
- package/dist/ox/TransactionRequest.js +21 -12
- package/dist/ox/TransactionRequest.js.map +1 -1
- package/dist/ox/index.d.ts +5 -4
- package/dist/ox/index.d.ts.map +1 -1
- package/dist/ox/index.js +5 -4
- package/dist/ox/index.js.map +1 -1
- package/dist/prool/Instance.d.ts +0 -4
- package/dist/prool/Instance.d.ts.map +1 -1
- package/dist/prool/Instance.js +7 -7
- package/dist/prool/Instance.js.map +1 -1
- package/dist/prool/index.d.ts +1 -1
- package/dist/prool/index.d.ts.map +1 -1
- package/dist/prool/index.js +1 -1
- package/dist/prool/index.js.map +1 -1
- package/dist/viem/{abis.d.ts → Abis.d.ts} +523 -9
- package/dist/viem/Abis.d.ts.map +1 -0
- package/dist/viem/{abis.js → Abis.js} +321 -9
- package/dist/viem/Abis.js.map +1 -0
- package/dist/viem/{actions → Actions}/amm.d.ts +21 -21
- package/dist/viem/Actions/amm.d.ts.map +1 -0
- package/dist/viem/{actions → Actions}/amm.js +55 -43
- package/dist/viem/Actions/amm.js.map +1 -0
- package/dist/viem/Actions/dex.d.ts +3263 -0
- package/dist/viem/Actions/dex.d.ts.map +1 -0
- package/dist/viem/Actions/dex.js +1357 -0
- package/dist/viem/Actions/dex.js.map +1 -0
- package/dist/viem/{actions → Actions}/fee.d.ts +8 -8
- package/dist/viem/Actions/fee.d.ts.map +1 -0
- package/dist/viem/{actions → Actions}/fee.js +14 -13
- package/dist/viem/Actions/fee.js.map +1 -0
- package/dist/viem/Actions/index.d.ts +6 -0
- package/dist/viem/Actions/index.d.ts.map +1 -0
- package/dist/viem/Actions/index.js +6 -0
- package/dist/viem/Actions/index.js.map +1 -0
- package/dist/viem/{actions → Actions}/policy.d.ts +19 -19
- package/dist/viem/Actions/policy.d.ts.map +1 -0
- package/dist/viem/{actions → Actions}/policy.js +59 -46
- package/dist/viem/Actions/policy.js.map +1 -0
- package/dist/viem/{actions → Actions}/token.d.ts +3251 -707
- package/dist/viem/Actions/token.d.ts.map +1 -0
- package/dist/viem/{actions → Actions}/token.js +420 -88
- package/dist/viem/Actions/token.js.map +1 -0
- package/dist/viem/Addresses.d.ts +9 -0
- package/dist/viem/Addresses.d.ts.map +1 -0
- package/dist/viem/Addresses.js +9 -0
- package/dist/viem/Addresses.js.map +1 -0
- package/dist/viem/{chain.d.ts → Chain.d.ts} +81 -57
- package/dist/viem/Chain.d.ts.map +1 -0
- package/dist/viem/{chain.js → Chain.js} +7 -7
- package/dist/viem/Chain.js.map +1 -0
- package/dist/viem/{client.d.ts → Client.d.ts} +4 -4
- package/dist/viem/Client.d.ts.map +1 -0
- package/dist/viem/{client.js → Client.js} +3 -3
- package/dist/viem/Client.js.map +1 -0
- package/dist/viem/{decorator.d.ts → Decorator.d.ts} +507 -5
- package/dist/viem/Decorator.d.ts.map +1 -0
- package/dist/viem/{decorator.js → Decorator.js} +31 -5
- package/dist/viem/Decorator.js.map +1 -0
- package/dist/viem/{formatters.d.ts → Formatters.d.ts} +2 -2
- package/dist/viem/Formatters.d.ts.map +1 -0
- package/dist/viem/{formatters.js → Formatters.js} +24 -17
- package/dist/viem/Formatters.js.map +1 -0
- package/dist/viem/Tick.d.ts +111 -0
- package/dist/viem/Tick.d.ts.map +1 -0
- package/dist/viem/Tick.js +127 -0
- package/dist/viem/Tick.js.map +1 -0
- package/dist/viem/TokenIds.d.ts +3 -0
- package/dist/viem/TokenIds.d.ts.map +1 -0
- package/dist/viem/TokenIds.js +3 -0
- package/dist/viem/TokenIds.js.map +1 -0
- package/dist/viem/Transaction.d.ts +57 -0
- package/dist/viem/Transaction.d.ts.map +1 -0
- package/dist/viem/Transaction.js +137 -0
- package/dist/viem/Transaction.js.map +1 -0
- package/dist/viem/{transport.d.ts → Transport.d.ts} +3 -3
- package/dist/viem/Transport.d.ts.map +1 -0
- package/dist/viem/{transport.js → Transport.js} +3 -3
- package/dist/viem/Transport.js.map +1 -0
- package/dist/viem/index.d.ts +13 -9
- package/dist/viem/index.d.ts.map +1 -1
- package/dist/viem/index.js +13 -9
- package/dist/viem/index.js.map +1 -1
- package/dist/viem/{types.d.ts → internal/types.d.ts} +3 -3
- package/dist/viem/internal/types.d.ts.map +1 -0
- package/dist/viem/{types.js.map → internal/types.js.map} +1 -1
- package/dist/viem/internal/utils.d.ts.map +1 -0
- package/dist/viem/internal/utils.js.map +1 -0
- package/package.json +87 -101
- package/src/chains.ts +10 -24
- package/src/ox/SignatureEnvelope.test.ts +1252 -0
- package/src/ox/SignatureEnvelope.ts +709 -0
- package/src/ox/Transaction.test.ts +144 -89
- package/src/ox/Transaction.ts +104 -29
- package/src/ox/TransactionEnvelopeAA.test.ts +1533 -0
- package/src/ox/TransactionEnvelopeAA.ts +858 -0
- package/src/ox/TransactionRequest.ts +25 -17
- package/src/ox/index.ts +2 -1
- package/src/prool/Instance.ts +6 -14
- package/src/prool/internal/chain.json +101 -27
- package/src/viem/{abis.ts → Abis.ts} +322 -8
- package/src/viem/{actions → Actions}/amm.test.ts +65 -68
- package/src/viem/{actions → Actions}/amm.ts +72 -60
- package/src/viem/Actions/dex.test.ts +1608 -0
- package/src/viem/Actions/dex.ts +2026 -0
- package/src/viem/{actions → Actions}/fee.test.ts +34 -36
- package/src/viem/{actions → Actions}/fee.ts +18 -17
- package/src/viem/{actions → Actions}/index.ts +1 -0
- package/src/viem/{actions → Actions}/policy.test.ts +2 -2
- package/src/viem/{actions → Actions}/policy.ts +77 -64
- package/src/viem/{actions → Actions}/token.test.ts +406 -67
- package/src/viem/{actions → Actions}/token.ts +675 -144
- package/src/viem/Addresses.ts +9 -0
- package/src/viem/{chain.ts → Chain.ts} +6 -6
- package/src/viem/{client.bench-d.ts → Client.bench-d.ts} +2 -2
- package/src/viem/{client.test.ts → Client.test.ts} +31 -6
- package/src/viem/{client.ts → Client.ts} +1 -1
- package/src/viem/{decorator.bench-d.ts → Decorator.bench-d.ts} +2 -2
- package/src/viem/{decorator.test.ts → Decorator.test.ts} +1 -0
- package/src/viem/{decorator.ts → Decorator.ts} +586 -4
- package/src/viem/{formatters.ts → Formatters.ts} +31 -20
- package/src/viem/Tick.test.ts +281 -0
- package/src/viem/Tick.ts +176 -0
- package/src/viem/TokenIds.ts +2 -0
- package/src/viem/Transaction.ts +303 -0
- package/src/viem/{transport.ts → Transport.ts} +5 -5
- package/src/viem/e2e.test.ts +153 -78
- package/src/viem/index.ts +13 -9
- package/src/viem/{types.ts → internal/types.ts} +3 -3
- package/dist/ox/TransactionEnvelopeFeeToken.d.ts +0 -393
- package/dist/ox/TransactionEnvelopeFeeToken.d.ts.map +0 -1
- package/dist/ox/TransactionEnvelopeFeeToken.js +0 -452
- package/dist/ox/TransactionEnvelopeFeeToken.js.map +0 -1
- package/dist/viem/abis.d.ts.map +0 -1
- package/dist/viem/abis.js.map +0 -1
- package/dist/viem/actions/amm.d.ts.map +0 -1
- package/dist/viem/actions/amm.js.map +0 -1
- package/dist/viem/actions/fee.d.ts.map +0 -1
- package/dist/viem/actions/fee.js.map +0 -1
- package/dist/viem/actions/index.d.ts +0 -5
- package/dist/viem/actions/index.d.ts.map +0 -1
- package/dist/viem/actions/index.js +0 -5
- package/dist/viem/actions/index.js.map +0 -1
- package/dist/viem/actions/policy.d.ts.map +0 -1
- package/dist/viem/actions/policy.js.map +0 -1
- package/dist/viem/actions/token.d.ts.map +0 -1
- package/dist/viem/actions/token.js.map +0 -1
- package/dist/viem/addresses.d.ts +0 -8
- package/dist/viem/addresses.d.ts.map +0 -1
- package/dist/viem/addresses.js +0 -8
- package/dist/viem/addresses.js.map +0 -1
- package/dist/viem/chain.d.ts.map +0 -1
- package/dist/viem/chain.js.map +0 -1
- package/dist/viem/client.d.ts.map +0 -1
- package/dist/viem/client.js.map +0 -1
- package/dist/viem/decorator.d.ts.map +0 -1
- package/dist/viem/decorator.js.map +0 -1
- package/dist/viem/formatters.d.ts.map +0 -1
- package/dist/viem/formatters.js.map +0 -1
- package/dist/viem/transaction.d.ts +0 -54
- package/dist/viem/transaction.d.ts.map +0 -1
- package/dist/viem/transaction.js +0 -108
- package/dist/viem/transaction.js.map +0 -1
- package/dist/viem/transport.d.ts.map +0 -1
- package/dist/viem/transport.js.map +0 -1
- package/dist/viem/types.d.ts.map +0 -1
- package/dist/viem/utils.d.ts.map +0 -1
- package/dist/viem/utils.js.map +0 -1
- package/src/ox/TransactionEnvelopeFeeToken.test.ts +0 -1119
- package/src/ox/TransactionEnvelopeFeeToken.ts +0 -717
- package/src/prool/internal/consensus.toml +0 -32
- package/src/viem/addresses.ts +0 -10
- package/src/viem/transaction.ts +0 -253
- /package/dist/viem/{types.js → internal/types.js} +0 -0
- /package/dist/viem/{utils.d.ts → internal/utils.d.ts} +0 -0
- /package/dist/viem/{utils.js → internal/utils.js} +0 -0
- /package/src/viem/{utils.ts → internal/utils.ts} +0 -0
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { setTimeout } from 'node:timers/promises'
|
|
2
|
-
import
|
|
2
|
+
import { Abis, Actions, Addresses, createTempoClient } from 'tempo.ts/viem'
|
|
3
3
|
import { parseEther, publicActions } from 'viem'
|
|
4
4
|
import { mnemonicToAccount } from 'viem/accounts'
|
|
5
5
|
import { writeContractSync } from 'viem/actions'
|
|
6
6
|
import { describe, expect, test } from 'vitest'
|
|
7
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
8
|
|
|
12
9
|
const account = mnemonicToAccount(
|
|
13
10
|
'test test test test test test test test test test test junk',
|
|
@@ -25,34 +22,34 @@ const client = createTempoClient({
|
|
|
25
22
|
|
|
26
23
|
async function setupPoolWithLiquidity() {
|
|
27
24
|
// Create a new token for testing
|
|
28
|
-
const { token } = await
|
|
25
|
+
const { token } = await Actions.token.createSync(client, {
|
|
29
26
|
name: 'Test Token',
|
|
30
27
|
symbol: 'TEST',
|
|
31
28
|
currency: 'USD',
|
|
32
29
|
})
|
|
33
30
|
|
|
34
31
|
// Grant issuer role to mint tokens
|
|
35
|
-
await
|
|
32
|
+
await Actions.token.grantRolesSync(client, {
|
|
36
33
|
token,
|
|
37
34
|
roles: ['issuer'],
|
|
38
35
|
to: client.account.address,
|
|
39
36
|
})
|
|
40
37
|
|
|
41
38
|
// Mint some tokens to account
|
|
42
|
-
await
|
|
39
|
+
await Actions.token.mintSync(client, {
|
|
43
40
|
to: account.address,
|
|
44
41
|
amount: parseEther('1000'),
|
|
45
42
|
token,
|
|
46
43
|
})
|
|
47
44
|
|
|
48
45
|
// Add liquidity to pool
|
|
49
|
-
await
|
|
46
|
+
await Actions.amm.mintSync(client, {
|
|
50
47
|
userToken: {
|
|
51
48
|
address: token,
|
|
52
49
|
amount: parseEther('100'),
|
|
53
50
|
},
|
|
54
51
|
validatorToken: {
|
|
55
|
-
address:
|
|
52
|
+
address: Addresses.defaultFeeToken,
|
|
56
53
|
amount: parseEther('100'),
|
|
57
54
|
},
|
|
58
55
|
to: account.address,
|
|
@@ -63,8 +60,8 @@ async function setupPoolWithLiquidity() {
|
|
|
63
60
|
|
|
64
61
|
describe('getPoolId', () => {
|
|
65
62
|
test('default', async () => {
|
|
66
|
-
const poolId = await
|
|
67
|
-
userToken:
|
|
63
|
+
const poolId = await Actions.amm.getPoolId(client, {
|
|
64
|
+
userToken: Addresses.defaultFeeToken,
|
|
68
65
|
validatorToken: '0x20c0000000000000000000000000000000000001',
|
|
69
66
|
})
|
|
70
67
|
expect(poolId).toBeDefined()
|
|
@@ -72,7 +69,7 @@ describe('getPoolId', () => {
|
|
|
72
69
|
})
|
|
73
70
|
|
|
74
71
|
test('behavior: token id', async () => {
|
|
75
|
-
const poolId = await
|
|
72
|
+
const poolId = await Actions.amm.getPoolId(client, {
|
|
76
73
|
userToken: 0n,
|
|
77
74
|
validatorToken: 1n,
|
|
78
75
|
})
|
|
@@ -83,8 +80,8 @@ describe('getPoolId', () => {
|
|
|
83
80
|
|
|
84
81
|
describe('getPool', () => {
|
|
85
82
|
test('default', async () => {
|
|
86
|
-
const pool = await
|
|
87
|
-
userToken:
|
|
83
|
+
const pool = await Actions.amm.getPool(client, {
|
|
84
|
+
userToken: Addresses.defaultFeeToken,
|
|
88
85
|
validatorToken: '0x20c0000000000000000000000000000000000001',
|
|
89
86
|
})
|
|
90
87
|
expect(pool).toMatchObject({
|
|
@@ -96,22 +93,22 @@ describe('getPool', () => {
|
|
|
96
93
|
|
|
97
94
|
describe('getTotalSupply', () => {
|
|
98
95
|
test('default', async () => {
|
|
99
|
-
const poolId = await
|
|
100
|
-
userToken:
|
|
96
|
+
const poolId = await Actions.amm.getPoolId(client, {
|
|
97
|
+
userToken: Addresses.defaultFeeToken,
|
|
101
98
|
validatorToken: '0x20c0000000000000000000000000000000000001',
|
|
102
99
|
})
|
|
103
|
-
const totalSupply = await
|
|
100
|
+
const totalSupply = await Actions.amm.getTotalSupply(client, { poolId })
|
|
104
101
|
expect(typeof totalSupply).toBe('bigint')
|
|
105
102
|
})
|
|
106
103
|
})
|
|
107
104
|
|
|
108
105
|
describe('getLiquidityBalance', () => {
|
|
109
106
|
test('default', async () => {
|
|
110
|
-
const poolId = await
|
|
111
|
-
userToken:
|
|
107
|
+
const poolId = await Actions.amm.getPoolId(client, {
|
|
108
|
+
userToken: Addresses.defaultFeeToken,
|
|
112
109
|
validatorToken: '0x20c0000000000000000000000000000000000001',
|
|
113
110
|
})
|
|
114
|
-
const balance = await
|
|
111
|
+
const balance = await Actions.amm.getLiquidityBalance(client, {
|
|
115
112
|
poolId,
|
|
116
113
|
address: account.address,
|
|
117
114
|
})
|
|
@@ -122,28 +119,28 @@ describe('getLiquidityBalance', () => {
|
|
|
122
119
|
describe('mint', () => {
|
|
123
120
|
test('default', async () => {
|
|
124
121
|
// Create a new token for testing
|
|
125
|
-
const { token } = await
|
|
122
|
+
const { token } = await Actions.token.createSync(client, {
|
|
126
123
|
name: 'Test Token',
|
|
127
124
|
symbol: 'TEST',
|
|
128
125
|
currency: 'USD',
|
|
129
126
|
})
|
|
130
127
|
|
|
131
128
|
// Grant issuer role to mint tokens
|
|
132
|
-
await
|
|
129
|
+
await Actions.token.grantRolesSync(client, {
|
|
133
130
|
token,
|
|
134
131
|
roles: ['issuer'],
|
|
135
132
|
to: client.account.address,
|
|
136
133
|
})
|
|
137
134
|
|
|
138
135
|
// Mint some tokens to account
|
|
139
|
-
await
|
|
136
|
+
await Actions.token.mintSync(client, {
|
|
140
137
|
to: account.address,
|
|
141
138
|
amount: parseEther('1000'),
|
|
142
139
|
token,
|
|
143
140
|
})
|
|
144
141
|
|
|
145
142
|
// Add liquidity to pool
|
|
146
|
-
const { receipt: mintReceipt, ...mintResult } = await
|
|
143
|
+
const { receipt: mintReceipt, ...mintResult } = await Actions.amm.mintSync(
|
|
147
144
|
client,
|
|
148
145
|
{
|
|
149
146
|
userToken: {
|
|
@@ -151,7 +148,7 @@ describe('mint', () => {
|
|
|
151
148
|
amount: parseEther('100'),
|
|
152
149
|
},
|
|
153
150
|
validatorToken: {
|
|
154
|
-
address:
|
|
151
|
+
address: Addresses.defaultFeeToken,
|
|
155
152
|
amount: parseEther('100'),
|
|
156
153
|
},
|
|
157
154
|
to: account.address,
|
|
@@ -164,25 +161,25 @@ describe('mint', () => {
|
|
|
164
161
|
"amountValidatorToken": 100000000000000000000n,
|
|
165
162
|
"liquidity": 4999999999999999999999999999999999999000n,
|
|
166
163
|
"sender": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
167
|
-
"userToken": "
|
|
168
|
-
"validatorToken": "
|
|
164
|
+
"userToken": "0x20C0000000000000000000000000000000000004",
|
|
165
|
+
"validatorToken": "0x20C0000000000000000000000000000000000001",
|
|
169
166
|
}
|
|
170
167
|
`)
|
|
171
168
|
|
|
172
169
|
// Verify pool reserves
|
|
173
|
-
const pool = await
|
|
170
|
+
const pool = await Actions.amm.getPool(client, {
|
|
174
171
|
userToken: token,
|
|
175
|
-
validatorToken:
|
|
172
|
+
validatorToken: Addresses.defaultFeeToken,
|
|
176
173
|
})
|
|
177
174
|
expect(pool.reserveUserToken).toBe(parseEther('100'))
|
|
178
175
|
expect(pool.reserveValidatorToken).toBe(parseEther('100'))
|
|
179
176
|
|
|
180
177
|
// Verify LP token balance
|
|
181
|
-
const poolId = await
|
|
178
|
+
const poolId = await Actions.amm.getPoolId(client, {
|
|
182
179
|
userToken: token,
|
|
183
|
-
validatorToken:
|
|
180
|
+
validatorToken: Addresses.defaultFeeToken,
|
|
184
181
|
})
|
|
185
|
-
const lpBalance = await
|
|
182
|
+
const lpBalance = await Actions.amm.getLiquidityBalance(client, {
|
|
186
183
|
poolId,
|
|
187
184
|
address: account.address,
|
|
188
185
|
})
|
|
@@ -195,21 +192,21 @@ describe('burn', () => {
|
|
|
195
192
|
const { tokenAddress } = await setupPoolWithLiquidity()
|
|
196
193
|
|
|
197
194
|
// Get LP balance before burn
|
|
198
|
-
const poolId = await
|
|
195
|
+
const poolId = await Actions.amm.getPoolId(client, {
|
|
199
196
|
userToken: tokenAddress,
|
|
200
|
-
validatorToken:
|
|
197
|
+
validatorToken: Addresses.defaultFeeToken,
|
|
201
198
|
})
|
|
202
|
-
const lpBalanceBefore = await
|
|
199
|
+
const lpBalanceBefore = await Actions.amm.getLiquidityBalance(client, {
|
|
203
200
|
poolId,
|
|
204
201
|
address: account.address,
|
|
205
202
|
})
|
|
206
203
|
|
|
207
204
|
// Burn half of LP tokens
|
|
208
|
-
const { receipt: burnReceipt, ...burnResult } = await
|
|
205
|
+
const { receipt: burnReceipt, ...burnResult } = await Actions.amm.burnSync(
|
|
209
206
|
client,
|
|
210
207
|
{
|
|
211
208
|
userToken: tokenAddress,
|
|
212
|
-
validatorToken:
|
|
209
|
+
validatorToken: Addresses.defaultFeeToken,
|
|
213
210
|
liquidity: lpBalanceBefore / 2n,
|
|
214
211
|
to: account.address,
|
|
215
212
|
},
|
|
@@ -222,13 +219,13 @@ describe('burn', () => {
|
|
|
222
219
|
"liquidity": 2499999999999999999999999999999999999500n,
|
|
223
220
|
"sender": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
224
221
|
"to": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
225
|
-
"userToken": "
|
|
226
|
-
"validatorToken": "
|
|
222
|
+
"userToken": "0x20C0000000000000000000000000000000000004",
|
|
223
|
+
"validatorToken": "0x20C0000000000000000000000000000000000001",
|
|
227
224
|
}
|
|
228
225
|
`)
|
|
229
226
|
|
|
230
227
|
// Verify LP balance decreased
|
|
231
|
-
const lpBalanceAfter = await
|
|
228
|
+
const lpBalanceAfter = await Actions.amm.getLiquidityBalance(client, {
|
|
232
229
|
poolId,
|
|
233
230
|
address: account.address,
|
|
234
231
|
})
|
|
@@ -236,9 +233,9 @@ describe('burn', () => {
|
|
|
236
233
|
expect(lpBalanceAfter).toBe(lpBalanceBefore / 2n)
|
|
237
234
|
|
|
238
235
|
// Verify pool reserves decreased
|
|
239
|
-
const pool = await
|
|
236
|
+
const pool = await Actions.amm.getPool(client, {
|
|
240
237
|
userToken: tokenAddress,
|
|
241
|
-
validatorToken:
|
|
238
|
+
validatorToken: Addresses.defaultFeeToken,
|
|
242
239
|
})
|
|
243
240
|
expect(pool.reserveUserToken).toBeLessThan(parseEther('100'))
|
|
244
241
|
expect(pool.reserveValidatorToken).toBeLessThan(parseEther('100'))
|
|
@@ -250,16 +247,16 @@ describe('rebalanceSwap', () => {
|
|
|
250
247
|
const { tokenAddress } = await setupPoolWithLiquidity()
|
|
251
248
|
|
|
252
249
|
// Get balance before swap
|
|
253
|
-
const balanceBefore = await
|
|
250
|
+
const balanceBefore = await Actions.token.getBalance(client, {
|
|
254
251
|
token: tokenAddress,
|
|
255
252
|
account: account2.address,
|
|
256
253
|
})
|
|
257
254
|
|
|
258
255
|
// Perform rebalance swap
|
|
259
256
|
const { receipt: swapReceipt, ...swapResult } =
|
|
260
|
-
await
|
|
257
|
+
await Actions.amm.rebalanceSwapSync(client, {
|
|
261
258
|
userToken: tokenAddress,
|
|
262
|
-
validatorToken:
|
|
259
|
+
validatorToken: Addresses.defaultFeeToken,
|
|
263
260
|
amountOut: parseEther('10'),
|
|
264
261
|
to: account2.address,
|
|
265
262
|
account: account,
|
|
@@ -270,13 +267,13 @@ describe('rebalanceSwap', () => {
|
|
|
270
267
|
"amountIn": 9985000000000000001n,
|
|
271
268
|
"amountOut": 10000000000000000000n,
|
|
272
269
|
"swapper": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
273
|
-
"userToken": "
|
|
274
|
-
"validatorToken": "
|
|
270
|
+
"userToken": "0x20C0000000000000000000000000000000000004",
|
|
271
|
+
"validatorToken": "0x20C0000000000000000000000000000000000001",
|
|
275
272
|
}
|
|
276
273
|
`)
|
|
277
274
|
|
|
278
275
|
// Verify balance increased
|
|
279
|
-
const balanceAfter = await
|
|
276
|
+
const balanceAfter = await Actions.token.getBalance(client, {
|
|
280
277
|
token: tokenAddress,
|
|
281
278
|
account: account2.address,
|
|
282
279
|
})
|
|
@@ -289,16 +286,16 @@ describe('watchRebalanceSwap', () => {
|
|
|
289
286
|
const { tokenAddress } = await setupPoolWithLiquidity()
|
|
290
287
|
|
|
291
288
|
let eventArgs: any = null
|
|
292
|
-
const unwatch =
|
|
289
|
+
const unwatch = Actions.amm.watchRebalanceSwap(client, {
|
|
293
290
|
onRebalanceSwap: (args) => {
|
|
294
291
|
eventArgs = args
|
|
295
292
|
},
|
|
296
293
|
})
|
|
297
294
|
|
|
298
295
|
// Perform rebalance swap
|
|
299
|
-
await
|
|
296
|
+
await Actions.amm.rebalanceSwapSync(client, {
|
|
300
297
|
userToken: tokenAddress,
|
|
301
|
-
validatorToken:
|
|
298
|
+
validatorToken: Addresses.defaultFeeToken,
|
|
302
299
|
amountOut: parseEther('10'),
|
|
303
300
|
to: account2.address,
|
|
304
301
|
account: account,
|
|
@@ -309,7 +306,7 @@ describe('watchRebalanceSwap', () => {
|
|
|
309
306
|
expect(eventArgs).toBeDefined()
|
|
310
307
|
expect(eventArgs.userToken.toLowerCase()).toBe(tokenAddress.toLowerCase())
|
|
311
308
|
expect(eventArgs.validatorToken.toLowerCase()).toBe(
|
|
312
|
-
|
|
309
|
+
Addresses.defaultFeeToken.toLowerCase(),
|
|
313
310
|
)
|
|
314
311
|
expect(eventArgs.amountOut).toBe(parseEther('10'))
|
|
315
312
|
|
|
@@ -320,21 +317,21 @@ describe('watchRebalanceSwap', () => {
|
|
|
320
317
|
describe('watchMint', () => {
|
|
321
318
|
test('default', async () => {
|
|
322
319
|
// Create a new token for testing
|
|
323
|
-
const { token } = await
|
|
320
|
+
const { token } = await Actions.token.createSync(client, {
|
|
324
321
|
name: 'Test Token 2',
|
|
325
322
|
symbol: 'TEST2',
|
|
326
323
|
currency: 'USD',
|
|
327
324
|
})
|
|
328
325
|
|
|
329
326
|
// Grant issuer role to mint tokens
|
|
330
|
-
await
|
|
327
|
+
await Actions.token.grantRolesSync(client, {
|
|
331
328
|
token,
|
|
332
329
|
roles: ['issuer'],
|
|
333
330
|
to: client.account.address,
|
|
334
331
|
})
|
|
335
332
|
|
|
336
333
|
// Mint some tokens to account
|
|
337
|
-
await
|
|
334
|
+
await Actions.token.mintSync(client, {
|
|
338
335
|
to: account.address,
|
|
339
336
|
amount: parseEther('1000'),
|
|
340
337
|
token,
|
|
@@ -342,27 +339,27 @@ describe('watchMint', () => {
|
|
|
342
339
|
|
|
343
340
|
// Mint USD to account
|
|
344
341
|
await writeContractSync(client, {
|
|
345
|
-
abi:
|
|
346
|
-
address:
|
|
342
|
+
abi: Abis.tip20,
|
|
343
|
+
address: Addresses.defaultFeeToken,
|
|
347
344
|
functionName: 'transfer',
|
|
348
345
|
args: [account.address, parseEther('1000')],
|
|
349
346
|
})
|
|
350
347
|
|
|
351
348
|
let eventArgs: any = null
|
|
352
|
-
const unwatch =
|
|
349
|
+
const unwatch = Actions.amm.watchMint(client, {
|
|
353
350
|
onMint: (args) => {
|
|
354
351
|
eventArgs = args
|
|
355
352
|
},
|
|
356
353
|
})
|
|
357
354
|
|
|
358
355
|
// Add liquidity to pool
|
|
359
|
-
await
|
|
356
|
+
await Actions.amm.mintSync(client, {
|
|
360
357
|
userToken: {
|
|
361
358
|
address: token,
|
|
362
359
|
amount: parseEther('100'),
|
|
363
360
|
},
|
|
364
361
|
validatorToken: {
|
|
365
|
-
address:
|
|
362
|
+
address: Addresses.defaultFeeToken,
|
|
366
363
|
amount: parseEther('100'),
|
|
367
364
|
},
|
|
368
365
|
to: account.address,
|
|
@@ -373,7 +370,7 @@ describe('watchMint', () => {
|
|
|
373
370
|
expect(eventArgs).toBeDefined()
|
|
374
371
|
expect(eventArgs.userToken.address.toLowerCase()).toBe(token.toLowerCase())
|
|
375
372
|
expect(eventArgs.validatorToken.address.toLowerCase()).toBe(
|
|
376
|
-
|
|
373
|
+
Addresses.defaultFeeToken.toLowerCase(),
|
|
377
374
|
)
|
|
378
375
|
expect(eventArgs.userToken.amount).toBe(parseEther('100'))
|
|
379
376
|
expect(eventArgs.validatorToken.amount).toBe(parseEther('100'))
|
|
@@ -387,26 +384,26 @@ describe('watchBurn', () => {
|
|
|
387
384
|
const { tokenAddress } = await setupPoolWithLiquidity()
|
|
388
385
|
|
|
389
386
|
// Get LP balance
|
|
390
|
-
const poolId = await
|
|
387
|
+
const poolId = await Actions.amm.getPoolId(client, {
|
|
391
388
|
userToken: tokenAddress,
|
|
392
|
-
validatorToken:
|
|
389
|
+
validatorToken: Addresses.defaultFeeToken,
|
|
393
390
|
})
|
|
394
|
-
const lpBalance = await
|
|
391
|
+
const lpBalance = await Actions.amm.getLiquidityBalance(client, {
|
|
395
392
|
poolId,
|
|
396
393
|
address: account.address,
|
|
397
394
|
})
|
|
398
395
|
|
|
399
396
|
let eventArgs: any = null
|
|
400
|
-
const unwatch =
|
|
397
|
+
const unwatch = Actions.amm.watchBurn(client, {
|
|
401
398
|
onBurn: (args) => {
|
|
402
399
|
eventArgs = args
|
|
403
400
|
},
|
|
404
401
|
})
|
|
405
402
|
|
|
406
403
|
// Burn LP tokens
|
|
407
|
-
await
|
|
404
|
+
await Actions.amm.burnSync(client, {
|
|
408
405
|
userToken: tokenAddress,
|
|
409
|
-
validatorToken:
|
|
406
|
+
validatorToken: Addresses.defaultFeeToken,
|
|
410
407
|
liquidity: lpBalance / 2n,
|
|
411
408
|
to: account.address,
|
|
412
409
|
})
|
|
@@ -416,7 +413,7 @@ describe('watchBurn', () => {
|
|
|
416
413
|
expect(eventArgs).toBeDefined()
|
|
417
414
|
expect(eventArgs.userToken.toLowerCase()).toBe(tokenAddress.toLowerCase())
|
|
418
415
|
expect(eventArgs.validatorToken.toLowerCase()).toBe(
|
|
419
|
-
|
|
416
|
+
Addresses.defaultFeeToken.toLowerCase(),
|
|
420
417
|
)
|
|
421
418
|
expect(eventArgs.liquidity).toBe(lpBalance / 2n)
|
|
422
419
|
|