tempo.ts 0.1.4 → 0.2.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/README.md +33 -2
- package/dist/chains.d.ts +509 -115
- package/dist/chains.d.ts.map +1 -1
- package/dist/chains.js +18 -9
- package/dist/chains.js.map +1 -1
- package/dist/ox/Order.d.ts +92 -0
- package/dist/ox/Order.d.ts.map +1 -0
- package/dist/ox/Order.js +88 -0
- package/dist/ox/Order.js.map +1 -0
- package/dist/ox/OrdersFilters.d.ts +72 -0
- package/dist/ox/OrdersFilters.d.ts.map +1 -0
- package/dist/ox/OrdersFilters.js +100 -0
- package/dist/ox/OrdersFilters.js.map +1 -0
- package/dist/ox/Pagination.d.ts +128 -0
- package/dist/ox/Pagination.d.ts.map +1 -0
- package/dist/ox/Pagination.js +78 -0
- package/dist/ox/Pagination.js.map +1 -0
- package/dist/ox/PoolId.d.ts +18 -0
- package/dist/ox/PoolId.d.ts.map +1 -0
- package/dist/ox/PoolId.js +13 -0
- package/dist/ox/PoolId.js.map +1 -0
- package/dist/ox/RpcSchema.d.ts +32 -0
- package/dist/ox/RpcSchema.d.ts.map +1 -0
- package/dist/ox/RpcSchema.js +2 -0
- package/dist/ox/RpcSchema.js.map +1 -0
- package/dist/ox/SignatureEnvelope.d.ts +1 -1
- package/dist/ox/SignatureEnvelope.d.ts.map +1 -1
- package/dist/ox/SignatureEnvelope.js.map +1 -1
- package/dist/{viem → ox}/Tick.d.ts +4 -0
- package/dist/ox/Tick.d.ts.map +1 -0
- package/dist/ox/Tick.js.map +1 -0
- package/dist/ox/Transaction.d.ts.map +1 -1
- package/dist/ox/Transaction.js +2 -1
- package/dist/ox/Transaction.js.map +1 -1
- package/dist/ox/TransactionEnvelopeAA.d.ts +6 -6
- package/dist/ox/TransactionEnvelopeAA.d.ts.map +1 -1
- package/dist/ox/TransactionEnvelopeAA.js +4 -2
- package/dist/ox/TransactionEnvelopeAA.js.map +1 -1
- package/dist/ox/TransactionRequest.d.ts +4 -0
- package/dist/ox/TransactionRequest.d.ts.map +1 -1
- package/dist/ox/TransactionRequest.js.map +1 -1
- package/dist/ox/index.d.ts +6 -0
- package/dist/ox/index.d.ts.map +1 -1
- package/dist/ox/index.js +6 -0
- package/dist/ox/index.js.map +1 -1
- package/dist/prool/Instance.d.ts +5 -0
- package/dist/prool/Instance.d.ts.map +1 -1
- package/dist/prool/Instance.js +32 -8
- package/dist/prool/Instance.js.map +1 -1
- package/dist/viem/Abis.d.ts +1469 -1082
- package/dist/viem/Abis.d.ts.map +1 -1
- package/dist/viem/Abis.js +932 -671
- package/dist/viem/Abis.js.map +1 -1
- package/dist/viem/Account.d.ts +150 -0
- package/dist/viem/Account.d.ts.map +1 -0
- package/dist/viem/Account.js +221 -0
- package/dist/viem/Account.js.map +1 -0
- package/dist/viem/Actions/amm.d.ts +80 -118
- package/dist/viem/Actions/amm.d.ts.map +1 -1
- package/dist/viem/Actions/amm.js +47 -116
- package/dist/viem/Actions/amm.js.map +1 -1
- package/dist/viem/Actions/dex.d.ts +889 -633
- package/dist/viem/Actions/dex.d.ts.map +1 -1
- package/dist/viem/Actions/dex.js +99 -0
- package/dist/viem/Actions/dex.js.map +1 -1
- package/dist/viem/Actions/fee.d.ts +3 -17
- package/dist/viem/Actions/fee.d.ts.map +1 -1
- package/dist/viem/Actions/fee.js.map +1 -1
- package/dist/viem/Actions/index.d.ts +1 -0
- package/dist/viem/Actions/index.d.ts.map +1 -1
- package/dist/viem/Actions/index.js +1 -0
- package/dist/viem/Actions/index.js.map +1 -1
- package/dist/viem/Actions/reward.d.ts +3236 -0
- package/dist/viem/Actions/reward.d.ts.map +1 -0
- package/dist/viem/Actions/reward.js +725 -0
- package/dist/viem/Actions/reward.js.map +1 -0
- package/dist/viem/Actions/token.d.ts +4295 -2646
- package/dist/viem/Actions/token.d.ts.map +1 -1
- package/dist/viem/Actions/token.js +214 -335
- package/dist/viem/Actions/token.js.map +1 -1
- package/dist/viem/Addresses.d.ts +1 -2
- package/dist/viem/Addresses.d.ts.map +1 -1
- package/dist/viem/Addresses.js +1 -2
- package/dist/viem/Addresses.js.map +1 -1
- package/dist/viem/Chain.d.ts +38 -12
- package/dist/viem/Chain.d.ts.map +1 -1
- package/dist/viem/Chain.js +27 -18
- package/dist/viem/Chain.js.map +1 -1
- package/dist/viem/Decorator.d.ts +959 -405
- package/dist/viem/Decorator.d.ts.map +1 -1
- package/dist/viem/Decorator.js +13 -5
- package/dist/viem/Decorator.js.map +1 -1
- package/dist/viem/Formatters.d.ts +8 -1
- package/dist/viem/Formatters.d.ts.map +1 -1
- package/dist/viem/Formatters.js +17 -0
- package/dist/viem/Formatters.js.map +1 -1
- package/dist/viem/P256.d.ts +2 -0
- package/dist/viem/P256.d.ts.map +1 -0
- package/dist/viem/P256.js +2 -0
- package/dist/viem/P256.js.map +1 -0
- package/dist/viem/Secp256k1.d.ts +2 -0
- package/dist/viem/Secp256k1.d.ts.map +1 -0
- package/dist/viem/Secp256k1.js +2 -0
- package/dist/viem/Secp256k1.js.map +1 -0
- package/dist/viem/TokenIds.d.ts +1 -2
- package/dist/viem/TokenIds.d.ts.map +1 -1
- package/dist/viem/TokenIds.js +1 -2
- package/dist/viem/TokenIds.js.map +1 -1
- package/dist/viem/Transaction.d.ts +1 -1
- package/dist/viem/Transaction.d.ts.map +1 -1
- package/dist/viem/Transaction.js +46 -5
- package/dist/viem/Transaction.js.map +1 -1
- package/dist/viem/WebAuthnP256.d.ts +79 -0
- package/dist/viem/WebAuthnP256.d.ts.map +1 -0
- package/dist/viem/WebAuthnP256.js +95 -0
- package/dist/viem/WebAuthnP256.js.map +1 -0
- package/dist/viem/WebCryptoP256.d.ts +2 -0
- package/dist/viem/WebCryptoP256.d.ts.map +1 -0
- package/dist/viem/WebCryptoP256.js +2 -0
- package/dist/viem/WebCryptoP256.js.map +1 -0
- package/dist/viem/index.d.ts +6 -3
- package/dist/viem/index.d.ts.map +1 -1
- package/dist/viem/index.js +6 -3
- package/dist/viem/index.js.map +1 -1
- package/dist/viem/internal/account.d.ts +24 -0
- package/dist/viem/internal/account.d.ts.map +1 -0
- package/dist/viem/internal/account.js +68 -0
- package/dist/viem/internal/account.js.map +1 -0
- package/dist/viem/internal/types.d.ts +10 -0
- package/dist/viem/internal/types.d.ts.map +1 -1
- package/dist/wagmi/Actions/amm.d.ts +428 -0
- package/dist/wagmi/Actions/amm.d.ts.map +1 -0
- package/dist/wagmi/Actions/amm.js +472 -0
- package/dist/wagmi/Actions/amm.js.map +1 -0
- package/dist/wagmi/Actions/dex.d.ts +908 -0
- package/dist/wagmi/Actions/dex.d.ts.map +1 -0
- package/dist/wagmi/Actions/dex.js +1023 -0
- package/dist/wagmi/Actions/dex.js.map +1 -0
- package/dist/wagmi/Actions/fee.d.ts +111 -0
- package/dist/wagmi/Actions/fee.d.ts.map +1 -0
- package/dist/wagmi/Actions/fee.js +126 -0
- package/dist/wagmi/Actions/fee.js.map +1 -0
- package/dist/wagmi/Actions/index.d.ts +6 -0
- package/dist/wagmi/Actions/index.d.ts.map +1 -0
- package/dist/wagmi/Actions/index.js +6 -0
- package/dist/wagmi/Actions/index.js.map +1 -0
- package/dist/wagmi/Actions/reward.d.ts +348 -0
- package/dist/wagmi/Actions/reward.d.ts.map +1 -0
- package/dist/wagmi/Actions/reward.js +388 -0
- package/dist/wagmi/Actions/reward.js.map +1 -0
- package/dist/wagmi/Actions/token.d.ts +1546 -0
- package/dist/wagmi/Actions/token.d.ts.map +1 -0
- package/dist/wagmi/Actions/token.js +1712 -0
- package/dist/wagmi/Actions/token.js.map +1 -0
- package/dist/wagmi/Connector.d.ts +73 -0
- package/dist/wagmi/Connector.d.ts.map +1 -0
- package/dist/wagmi/Connector.js +249 -0
- package/dist/wagmi/Connector.js.map +1 -0
- package/dist/wagmi/Hooks/amm.d.ts +421 -0
- package/dist/wagmi/Hooks/amm.d.ts.map +1 -0
- package/dist/wagmi/Hooks/amm.js +504 -0
- package/dist/wagmi/Hooks/amm.js.map +1 -0
- package/dist/wagmi/Hooks/dex.d.ts +816 -0
- package/dist/wagmi/Hooks/dex.d.ts.map +1 -0
- package/dist/wagmi/Hooks/dex.js +973 -0
- package/dist/wagmi/Hooks/dex.js.map +1 -0
- package/dist/wagmi/Hooks/fee.d.ts +97 -0
- package/dist/wagmi/Hooks/fee.d.ts.map +1 -0
- package/dist/wagmi/Hooks/fee.js +109 -0
- package/dist/wagmi/Hooks/fee.js.map +1 -0
- package/dist/wagmi/Hooks/index.d.ts +6 -0
- package/dist/wagmi/Hooks/index.d.ts.map +1 -0
- package/dist/wagmi/Hooks/index.js +6 -0
- package/dist/wagmi/Hooks/index.js.map +1 -0
- package/dist/wagmi/Hooks/reward.d.ts +307 -0
- package/dist/wagmi/Hooks/reward.d.ts.map +1 -0
- package/dist/wagmi/Hooks/reward.js +349 -0
- package/dist/wagmi/Hooks/reward.js.map +1 -0
- package/dist/wagmi/Hooks/token.d.ts +1388 -0
- package/dist/wagmi/Hooks/token.d.ts.map +1 -0
- package/dist/wagmi/Hooks/token.js +1657 -0
- package/dist/wagmi/Hooks/token.js.map +1 -0
- package/dist/wagmi/index.d.ts +4 -0
- package/dist/wagmi/index.d.ts.map +1 -0
- package/dist/wagmi/index.js +4 -0
- package/dist/wagmi/index.js.map +1 -0
- package/package.json +54 -10
- package/src/chains.ts +19 -9
- package/src/ox/Order.test.ts +78 -0
- package/src/ox/Order.ts +125 -0
- package/src/ox/OrdersFilters.test.ts +182 -0
- package/src/ox/OrdersFilters.ts +125 -0
- package/src/ox/Pagination.test.ts +162 -0
- package/src/ox/Pagination.ts +164 -0
- package/src/ox/PoolId.test.ts +33 -0
- package/src/ox/PoolId.ts +27 -0
- package/src/ox/RpcSchema.ts +35 -0
- package/src/ox/SignatureEnvelope.ts +3 -1
- package/src/{viem → ox}/Tick.test.ts +1 -1
- package/src/{viem → ox}/Tick.ts +5 -0
- package/src/ox/Transaction.test.ts +1 -1
- package/src/ox/Transaction.ts +2 -1
- package/src/ox/TransactionEnvelopeAA.test.ts +239 -96
- package/src/ox/TransactionEnvelopeAA.ts +9 -7
- package/src/ox/TransactionRequest.ts +4 -0
- package/src/ox/index.ts +6 -0
- package/src/prool/Instance.ts +75 -38
- package/src/prool/internal/chain.json +104 -52
- package/src/tsconfig.json +9 -0
- package/src/viem/Abis.ts +972 -710
- package/src/viem/Account.ts +279 -0
- package/src/viem/Actions/__snapshots__/dex.test.ts.snap +850 -0
- package/src/viem/Actions/amm.test.ts +98 -169
- package/src/viem/Actions/amm.ts +68 -155
- package/src/viem/Actions/dex.test.ts +563 -484
- package/src/viem/Actions/dex.ts +173 -0
- package/src/viem/Actions/fee.test.ts +23 -34
- package/src/viem/Actions/fee.ts +7 -0
- package/src/viem/Actions/index.ts +1 -0
- package/src/viem/Actions/policy.test.ts +19 -33
- package/src/viem/Actions/reward.test.ts +457 -0
- package/src/viem/Actions/reward.ts +999 -0
- package/src/viem/Actions/token.test.ts +453 -287
- package/src/viem/Actions/token.ts +452 -540
- package/src/viem/Addresses.ts +1 -2
- package/src/viem/Chain.ts +70 -20
- package/src/viem/Decorator.test.ts +2 -1
- package/src/viem/Decorator.ts +996 -421
- package/src/viem/Formatters.ts +31 -5
- package/src/viem/P256.ts +1 -0
- package/src/viem/Secp256k1.ts +1 -0
- package/src/viem/TokenIds.ts +1 -2
- package/src/viem/Transaction.ts +53 -7
- package/src/viem/WebAuthnP256.ts +140 -0
- package/src/viem/WebCryptoP256.ts +1 -0
- package/src/viem/e2e.test.ts +1126 -297
- package/src/viem/index.ts +6 -3
- package/src/viem/internal/account.ts +107 -0
- package/src/viem/internal/types.ts +9 -0
- package/src/wagmi/Actions/__snapshots__/dex.test.ts.snap +310 -0
- package/src/wagmi/Actions/amm.test.ts +198 -0
- package/src/wagmi/Actions/amm.ts +691 -0
- package/src/wagmi/Actions/dex.test.ts +1507 -0
- package/src/wagmi/Actions/dex.ts +1640 -0
- package/src/wagmi/Actions/fee.test.ts +63 -0
- package/src/wagmi/Actions/fee.ts +208 -0
- package/src/wagmi/Actions/index.ts +5 -0
- package/src/wagmi/Actions/reward.test.ts +210 -0
- package/src/wagmi/Actions/reward.ts +632 -0
- package/src/wagmi/Actions/token.test.ts +1308 -0
- package/src/wagmi/Actions/token.ts +2613 -0
- package/src/wagmi/Connector.test.ts +53 -0
- package/src/wagmi/Connector.ts +367 -0
- package/src/wagmi/Hooks/__snapshots__/dex.test.ts.snap +457 -0
- package/src/wagmi/Hooks/amm.test.ts +424 -0
- package/src/wagmi/Hooks/amm.ts +806 -0
- package/src/wagmi/Hooks/dex.test.ts +1017 -0
- package/src/wagmi/Hooks/dex.ts +1685 -0
- package/src/wagmi/Hooks/fee.test.ts +166 -0
- package/src/wagmi/Hooks/fee.ts +206 -0
- package/src/wagmi/Hooks/index.ts +5 -0
- package/src/wagmi/Hooks/reward.test.ts +219 -0
- package/src/wagmi/Hooks/reward.ts +672 -0
- package/src/wagmi/Hooks/token.test.ts +1670 -0
- package/src/wagmi/Hooks/token.ts +2906 -0
- package/src/wagmi/index.ts +3 -0
- package/src/wagmi/internal/types.ts +16 -0
- package/dist/viem/Client.d.ts +0 -27
- package/dist/viem/Client.d.ts.map +0 -1
- package/dist/viem/Client.js +0 -28
- package/dist/viem/Client.js.map +0 -1
- package/dist/viem/Tick.d.ts.map +0 -1
- package/dist/viem/Tick.js.map +0 -1
- package/src/viem/Client.bench-d.ts +0 -8
- package/src/viem/Client.test.ts +0 -178
- package/src/viem/Client.ts +0 -91
- /package/dist/{viem → ox}/Tick.js +0 -0
|
@@ -1,116 +1,39 @@
|
|
|
1
1
|
import { setTimeout } from 'node:timers/promises'
|
|
2
|
-
import { Abis, Actions
|
|
3
|
-
import {
|
|
4
|
-
import { mnemonicToAccount } from 'viem/accounts'
|
|
2
|
+
import { Abis, Actions } from 'tempo.ts/viem'
|
|
3
|
+
import { parseUnits } from 'viem'
|
|
5
4
|
import { writeContractSync } from 'viem/actions'
|
|
6
5
|
import { describe, expect, test } from 'vitest'
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const account2 = mnemonicToAccount(
|
|
13
|
-
'test test test test test test test test test test test junk',
|
|
14
|
-
{ accountIndex: 1 },
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
const client = createTempoClient({
|
|
18
|
-
account,
|
|
19
|
-
chain: tempoTest,
|
|
20
|
-
pollingInterval: 100,
|
|
21
|
-
}).extend(publicActions)
|
|
22
|
-
|
|
23
|
-
async function setupPoolWithLiquidity() {
|
|
24
|
-
// Create a new token for testing
|
|
25
|
-
const { token } = await Actions.token.createSync(client, {
|
|
26
|
-
name: 'Test Token',
|
|
27
|
-
symbol: 'TEST',
|
|
28
|
-
currency: 'USD',
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
// Grant issuer role to mint tokens
|
|
32
|
-
await Actions.token.grantRolesSync(client, {
|
|
33
|
-
token,
|
|
34
|
-
roles: ['issuer'],
|
|
35
|
-
to: client.account.address,
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
// Mint some tokens to account
|
|
39
|
-
await Actions.token.mintSync(client, {
|
|
40
|
-
to: account.address,
|
|
41
|
-
amount: parseEther('1000'),
|
|
42
|
-
token,
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
// Add liquidity to pool
|
|
46
|
-
await Actions.amm.mintSync(client, {
|
|
47
|
-
userToken: {
|
|
48
|
-
address: token,
|
|
49
|
-
amount: parseEther('100'),
|
|
50
|
-
},
|
|
51
|
-
validatorToken: {
|
|
52
|
-
address: Addresses.defaultFeeToken,
|
|
53
|
-
amount: parseEther('100'),
|
|
54
|
-
},
|
|
55
|
-
to: account.address,
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
return { tokenAddress: token }
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
describe('getPoolId', () => {
|
|
62
|
-
test('default', async () => {
|
|
63
|
-
const poolId = await Actions.amm.getPoolId(client, {
|
|
64
|
-
userToken: Addresses.defaultFeeToken,
|
|
65
|
-
validatorToken: '0x20c0000000000000000000000000000000000001',
|
|
66
|
-
})
|
|
67
|
-
expect(poolId).toBeDefined()
|
|
68
|
-
expect(typeof poolId).toBe('string')
|
|
69
|
-
})
|
|
6
|
+
import {
|
|
7
|
+
accounts,
|
|
8
|
+
client,
|
|
9
|
+
setupPoolWithLiquidity,
|
|
10
|
+
} from '../../../test/viem/config.js'
|
|
70
11
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
userToken: 0n,
|
|
74
|
-
validatorToken: 1n,
|
|
75
|
-
})
|
|
76
|
-
expect(poolId).toBeDefined()
|
|
77
|
-
expect(typeof poolId).toBe('string')
|
|
78
|
-
})
|
|
79
|
-
})
|
|
12
|
+
const account = accounts[0]
|
|
13
|
+
const account2 = accounts[1]
|
|
80
14
|
|
|
81
15
|
describe('getPool', () => {
|
|
82
16
|
test('default', async () => {
|
|
83
17
|
const pool = await Actions.amm.getPool(client, {
|
|
84
|
-
userToken:
|
|
18
|
+
userToken: 1n,
|
|
85
19
|
validatorToken: '0x20c0000000000000000000000000000000000001',
|
|
86
20
|
})
|
|
87
|
-
expect(pool).
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
describe('getTotalSupply', () => {
|
|
95
|
-
test('default', async () => {
|
|
96
|
-
const poolId = await Actions.amm.getPoolId(client, {
|
|
97
|
-
userToken: Addresses.defaultFeeToken,
|
|
98
|
-
validatorToken: '0x20c0000000000000000000000000000000000001',
|
|
99
|
-
})
|
|
100
|
-
const totalSupply = await Actions.amm.getTotalSupply(client, { poolId })
|
|
101
|
-
expect(typeof totalSupply).toBe('bigint')
|
|
21
|
+
expect(pool).toMatchInlineSnapshot(`
|
|
22
|
+
{
|
|
23
|
+
"reserveUserToken": 0n,
|
|
24
|
+
"reserveValidatorToken": 0n,
|
|
25
|
+
"totalSupply": 0n,
|
|
26
|
+
}
|
|
27
|
+
`)
|
|
102
28
|
})
|
|
103
29
|
})
|
|
104
30
|
|
|
105
31
|
describe('getLiquidityBalance', () => {
|
|
106
32
|
test('default', async () => {
|
|
107
|
-
const poolId = await Actions.amm.getPoolId(client, {
|
|
108
|
-
userToken: Addresses.defaultFeeToken,
|
|
109
|
-
validatorToken: '0x20c0000000000000000000000000000000000001',
|
|
110
|
-
})
|
|
111
33
|
const balance = await Actions.amm.getLiquidityBalance(client, {
|
|
112
|
-
poolId,
|
|
113
34
|
address: account.address,
|
|
35
|
+
userToken: 1n,
|
|
36
|
+
validatorToken: '0x20c0000000000000000000000000000000000001',
|
|
114
37
|
})
|
|
115
38
|
expect(typeof balance).toBe('bigint')
|
|
116
39
|
})
|
|
@@ -135,7 +58,7 @@ describe('mint', () => {
|
|
|
135
58
|
// Mint some tokens to account
|
|
136
59
|
await Actions.token.mintSync(client, {
|
|
137
60
|
to: account.address,
|
|
138
|
-
amount:
|
|
61
|
+
amount: parseUnits('1000', 6),
|
|
139
62
|
token,
|
|
140
63
|
})
|
|
141
64
|
|
|
@@ -145,11 +68,11 @@ describe('mint', () => {
|
|
|
145
68
|
{
|
|
146
69
|
userToken: {
|
|
147
70
|
address: token,
|
|
148
|
-
amount:
|
|
71
|
+
amount: parseUnits('100', 6),
|
|
149
72
|
},
|
|
150
73
|
validatorToken: {
|
|
151
|
-
address:
|
|
152
|
-
amount:
|
|
74
|
+
address: 1n,
|
|
75
|
+
amount: parseUnits('100', 6),
|
|
153
76
|
},
|
|
154
77
|
to: account.address,
|
|
155
78
|
},
|
|
@@ -157,9 +80,9 @@ describe('mint', () => {
|
|
|
157
80
|
expect(mintReceipt).toBeDefined()
|
|
158
81
|
expect(mintResult).toMatchInlineSnapshot(`
|
|
159
82
|
{
|
|
160
|
-
"amountUserToken":
|
|
161
|
-
"amountValidatorToken":
|
|
162
|
-
"liquidity":
|
|
83
|
+
"amountUserToken": 100000000n,
|
|
84
|
+
"amountValidatorToken": 100000000n,
|
|
85
|
+
"liquidity": 4999999999999000n,
|
|
163
86
|
"sender": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
164
87
|
"userToken": "0x20C0000000000000000000000000000000000004",
|
|
165
88
|
"validatorToken": "0x20C0000000000000000000000000000000000001",
|
|
@@ -169,19 +92,21 @@ describe('mint', () => {
|
|
|
169
92
|
// Verify pool reserves
|
|
170
93
|
const pool = await Actions.amm.getPool(client, {
|
|
171
94
|
userToken: token,
|
|
172
|
-
validatorToken:
|
|
95
|
+
validatorToken: 1n,
|
|
173
96
|
})
|
|
174
|
-
expect(pool
|
|
175
|
-
|
|
97
|
+
expect(pool).toMatchInlineSnapshot(`
|
|
98
|
+
{
|
|
99
|
+
"reserveUserToken": 100000000n,
|
|
100
|
+
"reserveValidatorToken": 100000000n,
|
|
101
|
+
"totalSupply": 5000000000000000n,
|
|
102
|
+
}
|
|
103
|
+
`)
|
|
176
104
|
|
|
177
105
|
// Verify LP token balance
|
|
178
|
-
const poolId = await Actions.amm.getPoolId(client, {
|
|
179
|
-
userToken: token,
|
|
180
|
-
validatorToken: Addresses.defaultFeeToken,
|
|
181
|
-
})
|
|
182
106
|
const lpBalance = await Actions.amm.getLiquidityBalance(client, {
|
|
183
|
-
poolId,
|
|
184
107
|
address: account.address,
|
|
108
|
+
userToken: token,
|
|
109
|
+
validatorToken: 1n,
|
|
185
110
|
})
|
|
186
111
|
expect(lpBalance).toBeGreaterThan(0n)
|
|
187
112
|
})
|
|
@@ -189,45 +114,44 @@ describe('mint', () => {
|
|
|
189
114
|
|
|
190
115
|
describe('burn', () => {
|
|
191
116
|
test('default', async () => {
|
|
192
|
-
const { tokenAddress } = await setupPoolWithLiquidity()
|
|
117
|
+
const { tokenAddress } = await setupPoolWithLiquidity(client)
|
|
193
118
|
|
|
194
119
|
// Get LP balance before burn
|
|
195
|
-
const poolId = await Actions.amm.getPoolId(client, {
|
|
196
|
-
userToken: tokenAddress,
|
|
197
|
-
validatorToken: Addresses.defaultFeeToken,
|
|
198
|
-
})
|
|
199
120
|
const lpBalanceBefore = await Actions.amm.getLiquidityBalance(client, {
|
|
200
|
-
poolId,
|
|
201
121
|
address: account.address,
|
|
122
|
+
userToken: tokenAddress,
|
|
123
|
+
validatorToken: 1n,
|
|
202
124
|
})
|
|
203
125
|
|
|
204
126
|
// Burn half of LP tokens
|
|
205
|
-
const {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
127
|
+
const {
|
|
128
|
+
receipt: burnReceipt,
|
|
129
|
+
userToken,
|
|
130
|
+
...burnResult
|
|
131
|
+
} = await Actions.amm.burnSync(client, {
|
|
132
|
+
userToken: tokenAddress,
|
|
133
|
+
validatorToken: 1n,
|
|
134
|
+
liquidity: lpBalanceBefore / 2n,
|
|
135
|
+
to: account.address,
|
|
136
|
+
})
|
|
214
137
|
expect(burnReceipt).toBeDefined()
|
|
138
|
+
expect(userToken).toBe(tokenAddress)
|
|
215
139
|
expect(burnResult).toMatchInlineSnapshot(`
|
|
216
140
|
{
|
|
217
|
-
"amountUserToken":
|
|
218
|
-
"amountValidatorToken":
|
|
219
|
-
"liquidity":
|
|
141
|
+
"amountUserToken": 49999999n,
|
|
142
|
+
"amountValidatorToken": 49999999n,
|
|
143
|
+
"liquidity": 2499999999999500n,
|
|
220
144
|
"sender": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
221
145
|
"to": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
222
|
-
"userToken": "0x20C0000000000000000000000000000000000004",
|
|
223
146
|
"validatorToken": "0x20C0000000000000000000000000000000000001",
|
|
224
147
|
}
|
|
225
148
|
`)
|
|
226
149
|
|
|
227
150
|
// Verify LP balance decreased
|
|
228
151
|
const lpBalanceAfter = await Actions.amm.getLiquidityBalance(client, {
|
|
229
|
-
poolId,
|
|
230
152
|
address: account.address,
|
|
153
|
+
userToken: tokenAddress,
|
|
154
|
+
validatorToken: 1n,
|
|
231
155
|
})
|
|
232
156
|
expect(lpBalanceAfter).toBeLessThan(lpBalanceBefore)
|
|
233
157
|
expect(lpBalanceAfter).toBe(lpBalanceBefore / 2n)
|
|
@@ -235,16 +159,21 @@ describe('burn', () => {
|
|
|
235
159
|
// Verify pool reserves decreased
|
|
236
160
|
const pool = await Actions.amm.getPool(client, {
|
|
237
161
|
userToken: tokenAddress,
|
|
238
|
-
validatorToken:
|
|
162
|
+
validatorToken: 1n,
|
|
239
163
|
})
|
|
240
|
-
expect(pool
|
|
241
|
-
|
|
164
|
+
expect(pool).toMatchInlineSnapshot(`
|
|
165
|
+
{
|
|
166
|
+
"reserveUserToken": 50000001n,
|
|
167
|
+
"reserveValidatorToken": 50000001n,
|
|
168
|
+
"totalSupply": 2500000000000500n,
|
|
169
|
+
}
|
|
170
|
+
`)
|
|
242
171
|
})
|
|
243
172
|
})
|
|
244
173
|
|
|
245
174
|
describe('rebalanceSwap', () => {
|
|
246
175
|
test('default', async () => {
|
|
247
|
-
const { tokenAddress } = await setupPoolWithLiquidity()
|
|
176
|
+
const { tokenAddress } = await setupPoolWithLiquidity(client)
|
|
248
177
|
|
|
249
178
|
// Get balance before swap
|
|
250
179
|
const balanceBefore = await Actions.token.getBalance(client, {
|
|
@@ -253,21 +182,24 @@ describe('rebalanceSwap', () => {
|
|
|
253
182
|
})
|
|
254
183
|
|
|
255
184
|
// Perform rebalance swap
|
|
256
|
-
const {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
185
|
+
const {
|
|
186
|
+
receipt: swapReceipt,
|
|
187
|
+
userToken,
|
|
188
|
+
...swapResult
|
|
189
|
+
} = await Actions.amm.rebalanceSwapSync(client, {
|
|
190
|
+
userToken: tokenAddress,
|
|
191
|
+
validatorToken: 1n,
|
|
192
|
+
amountOut: parseUnits('10', 6),
|
|
193
|
+
to: account2.address,
|
|
194
|
+
account: account,
|
|
195
|
+
})
|
|
264
196
|
expect(swapReceipt).toBeDefined()
|
|
197
|
+
expect(userToken).toBe(tokenAddress)
|
|
265
198
|
expect(swapResult).toMatchInlineSnapshot(`
|
|
266
199
|
{
|
|
267
|
-
"amountIn":
|
|
268
|
-
"amountOut":
|
|
200
|
+
"amountIn": 9985001n,
|
|
201
|
+
"amountOut": 10000000n,
|
|
269
202
|
"swapper": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
270
|
-
"userToken": "0x20C0000000000000000000000000000000000004",
|
|
271
203
|
"validatorToken": "0x20C0000000000000000000000000000000000001",
|
|
272
204
|
}
|
|
273
205
|
`)
|
|
@@ -277,13 +209,13 @@ describe('rebalanceSwap', () => {
|
|
|
277
209
|
token: tokenAddress,
|
|
278
210
|
account: account2.address,
|
|
279
211
|
})
|
|
280
|
-
expect(balanceAfter).toBe(balanceBefore +
|
|
212
|
+
expect(balanceAfter).toBe(balanceBefore + parseUnits('10', 6))
|
|
281
213
|
})
|
|
282
214
|
})
|
|
283
215
|
|
|
284
216
|
describe('watchRebalanceSwap', () => {
|
|
285
217
|
test('default', async () => {
|
|
286
|
-
const { tokenAddress } = await setupPoolWithLiquidity()
|
|
218
|
+
const { tokenAddress } = await setupPoolWithLiquidity(client)
|
|
287
219
|
|
|
288
220
|
let eventArgs: any = null
|
|
289
221
|
const unwatch = Actions.amm.watchRebalanceSwap(client, {
|
|
@@ -295,8 +227,8 @@ describe('watchRebalanceSwap', () => {
|
|
|
295
227
|
// Perform rebalance swap
|
|
296
228
|
await Actions.amm.rebalanceSwapSync(client, {
|
|
297
229
|
userToken: tokenAddress,
|
|
298
|
-
validatorToken:
|
|
299
|
-
amountOut:
|
|
230
|
+
validatorToken: 1n,
|
|
231
|
+
amountOut: parseUnits('10', 6),
|
|
300
232
|
to: account2.address,
|
|
301
233
|
account: account,
|
|
302
234
|
})
|
|
@@ -306,9 +238,9 @@ describe('watchRebalanceSwap', () => {
|
|
|
306
238
|
expect(eventArgs).toBeDefined()
|
|
307
239
|
expect(eventArgs.userToken.toLowerCase()).toBe(tokenAddress.toLowerCase())
|
|
308
240
|
expect(eventArgs.validatorToken.toLowerCase()).toBe(
|
|
309
|
-
|
|
241
|
+
'0x20c0000000000000000000000000000000000001',
|
|
310
242
|
)
|
|
311
|
-
expect(eventArgs.amountOut).toBe(
|
|
243
|
+
expect(eventArgs.amountOut).toBe(parseUnits('10', 6))
|
|
312
244
|
|
|
313
245
|
unwatch()
|
|
314
246
|
})
|
|
@@ -333,16 +265,16 @@ describe('watchMint', () => {
|
|
|
333
265
|
// Mint some tokens to account
|
|
334
266
|
await Actions.token.mintSync(client, {
|
|
335
267
|
to: account.address,
|
|
336
|
-
amount:
|
|
268
|
+
amount: parseUnits('1000', 6),
|
|
337
269
|
token,
|
|
338
270
|
})
|
|
339
271
|
|
|
340
272
|
// Mint USD to account
|
|
341
273
|
await writeContractSync(client, {
|
|
342
274
|
abi: Abis.tip20,
|
|
343
|
-
address:
|
|
275
|
+
address: '0x20c0000000000000000000000000000000000001',
|
|
344
276
|
functionName: 'transfer',
|
|
345
|
-
args: [account.address,
|
|
277
|
+
args: [account.address, parseUnits('1000', 6)],
|
|
346
278
|
})
|
|
347
279
|
|
|
348
280
|
let eventArgs: any = null
|
|
@@ -356,11 +288,11 @@ describe('watchMint', () => {
|
|
|
356
288
|
await Actions.amm.mintSync(client, {
|
|
357
289
|
userToken: {
|
|
358
290
|
address: token,
|
|
359
|
-
amount:
|
|
291
|
+
amount: parseUnits('100', 6),
|
|
360
292
|
},
|
|
361
293
|
validatorToken: {
|
|
362
|
-
address:
|
|
363
|
-
amount:
|
|
294
|
+
address: 1n,
|
|
295
|
+
amount: parseUnits('100', 6),
|
|
364
296
|
},
|
|
365
297
|
to: account.address,
|
|
366
298
|
})
|
|
@@ -370,10 +302,10 @@ describe('watchMint', () => {
|
|
|
370
302
|
expect(eventArgs).toBeDefined()
|
|
371
303
|
expect(eventArgs.userToken.address.toLowerCase()).toBe(token.toLowerCase())
|
|
372
304
|
expect(eventArgs.validatorToken.address.toLowerCase()).toBe(
|
|
373
|
-
|
|
305
|
+
'0x20c0000000000000000000000000000000000001',
|
|
374
306
|
)
|
|
375
|
-
expect(eventArgs.userToken.amount).toBe(
|
|
376
|
-
expect(eventArgs.validatorToken.amount).toBe(
|
|
307
|
+
expect(eventArgs.userToken.amount).toBe(parseUnits('100', 6))
|
|
308
|
+
expect(eventArgs.validatorToken.amount).toBe(parseUnits('100', 6))
|
|
377
309
|
|
|
378
310
|
unwatch()
|
|
379
311
|
})
|
|
@@ -381,15 +313,12 @@ describe('watchMint', () => {
|
|
|
381
313
|
|
|
382
314
|
describe('watchBurn', () => {
|
|
383
315
|
test('default', async () => {
|
|
384
|
-
const { tokenAddress } = await setupPoolWithLiquidity()
|
|
316
|
+
const { tokenAddress } = await setupPoolWithLiquidity(client)
|
|
385
317
|
|
|
386
318
|
// Get LP balance
|
|
387
|
-
const poolId = await Actions.amm.getPoolId(client, {
|
|
388
|
-
userToken: tokenAddress,
|
|
389
|
-
validatorToken: Addresses.defaultFeeToken,
|
|
390
|
-
})
|
|
391
319
|
const lpBalance = await Actions.amm.getLiquidityBalance(client, {
|
|
392
|
-
|
|
320
|
+
userToken: tokenAddress,
|
|
321
|
+
validatorToken: 1n,
|
|
393
322
|
address: account.address,
|
|
394
323
|
})
|
|
395
324
|
|
|
@@ -403,7 +332,7 @@ describe('watchBurn', () => {
|
|
|
403
332
|
// Burn LP tokens
|
|
404
333
|
await Actions.amm.burnSync(client, {
|
|
405
334
|
userToken: tokenAddress,
|
|
406
|
-
validatorToken:
|
|
335
|
+
validatorToken: 1n,
|
|
407
336
|
liquidity: lpBalance / 2n,
|
|
408
337
|
to: account.address,
|
|
409
338
|
})
|
|
@@ -413,7 +342,7 @@ describe('watchBurn', () => {
|
|
|
413
342
|
expect(eventArgs).toBeDefined()
|
|
414
343
|
expect(eventArgs.userToken.toLowerCase()).toBe(tokenAddress.toLowerCase())
|
|
415
344
|
expect(eventArgs.validatorToken.toLowerCase()).toBe(
|
|
416
|
-
|
|
345
|
+
'0x20c0000000000000000000000000000000000001',
|
|
417
346
|
)
|
|
418
347
|
expect(eventArgs.liquidity).toBe(lpBalance / 2n)
|
|
419
348
|
|