tempo.ts 0.1.5 → 0.2.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 +33 -2
- package/dist/chains.d.ts +509 -115
- package/dist/chains.d.ts.map +1 -1
- package/dist/chains.js +20 -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.map +1 -1
- package/dist/prool/Instance.js +20 -4
- 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 +144 -161
- package/dist/viem/Actions/amm.d.ts.map +1 -1
- package/dist/viem/Actions/amm.js +109 -163
- package/dist/viem/Actions/amm.js.map +1 -1
- package/dist/viem/Actions/dex.d.ts +920 -664
- package/dist/viem/Actions/dex.d.ts.map +1 -1
- package/dist/viem/Actions/dex.js +129 -30
- package/dist/viem/Actions/dex.js.map +1 -1
- package/dist/viem/Actions/faucet.d.ts +34 -0
- package/dist/viem/Actions/faucet.d.ts.map +1 -0
- package/dist/viem/Actions/faucet.js +33 -0
- package/dist/viem/Actions/faucet.js.map +1 -0
- package/dist/viem/Actions/fee.d.ts +16 -30
- package/dist/viem/Actions/fee.d.ts.map +1 -1
- package/dist/viem/Actions/fee.js +13 -13
- package/dist/viem/Actions/fee.js.map +1 -1
- package/dist/viem/Actions/index.d.ts +2 -0
- package/dist/viem/Actions/index.d.ts.map +1 -1
- package/dist/viem/Actions/index.js +2 -0
- package/dist/viem/Actions/index.js.map +1 -1
- package/dist/viem/Actions/policy.d.ts +46 -46
- package/dist/viem/Actions/policy.js +46 -46
- 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 +4399 -2750
- package/dist/viem/Actions/token.d.ts.map +1 -1
- package/dist/viem/Actions/token.js +361 -482
- 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 +1009 -428
- package/dist/viem/Decorator.d.ts.map +1 -1
- package/dist/viem/Decorator.js +17 -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/faucet.d.ts +35 -0
- package/dist/wagmi/Actions/faucet.d.ts.map +1 -0
- package/dist/wagmi/Actions/faucet.js +33 -0
- package/dist/wagmi/Actions/faucet.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 +7 -0
- package/dist/wagmi/Actions/index.d.ts.map +1 -0
- package/dist/wagmi/Actions/index.js +7 -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 +81 -0
- package/dist/wagmi/Connector.d.ts.map +1 -0
- package/dist/wagmi/Connector.js +261 -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/faucet.d.ts +39 -0
- package/dist/wagmi/Hooks/faucet.d.ts.map +1 -0
- package/dist/wagmi/Hooks/faucet.js +40 -0
- package/dist/wagmi/Hooks/faucet.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 +7 -0
- package/dist/wagmi/Hooks/index.d.ts.map +1 -0
- package/dist/wagmi/Hooks/index.js +7 -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 +21 -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 +51 -37
- 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 +173 -169
- package/src/viem/Actions/amm.ts +131 -203
- package/src/viem/Actions/dex.test.ts +563 -484
- package/src/viem/Actions/dex.ts +203 -30
- package/src/viem/Actions/faucet.ts +50 -0
- package/src/viem/Actions/fee.test.ts +23 -34
- package/src/viem/Actions/fee.ts +20 -13
- package/src/viem/Actions/index.ts +2 -0
- package/src/viem/Actions/policy.test.ts +19 -33
- package/src/viem/Actions/policy.ts +46 -46
- 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 +605 -693
- package/src/viem/Addresses.ts +1 -2
- package/src/viem/Chain.bench-d.ts +12 -0
- package/src/viem/Chain.ts +70 -20
- package/src/viem/Decorator.bench-d.ts +1 -1
- package/src/viem/Decorator.test.ts +3 -1
- package/src/viem/Decorator.ts +1049 -442
- 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/faucet.ts +46 -0
- package/src/wagmi/Actions/fee.test.ts +63 -0
- package/src/wagmi/Actions/fee.ts +208 -0
- package/src/wagmi/Actions/index.ts +6 -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 +390 -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/faucet.ts +76 -0
- package/src/wagmi/Hooks/fee.test.ts +166 -0
- package/src/wagmi/Hooks/fee.ts +206 -0
- package/src/wagmi/Hooks/index.ts +6 -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
|
-
}
|
|
6
|
+
import {
|
|
7
|
+
accounts,
|
|
8
|
+
client,
|
|
9
|
+
setupPoolWithLiquidity,
|
|
10
|
+
} from '../../../test/viem/config.js'
|
|
60
11
|
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
})
|
|
70
|
-
|
|
71
|
-
test('behavior: token id', async () => {
|
|
72
|
-
const poolId = await Actions.amm.getPoolId(client, {
|
|
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:
|
|
85
|
-
validatorToken: '0x20c0000000000000000000000000000000000001',
|
|
86
|
-
})
|
|
87
|
-
expect(pool).toMatchObject({
|
|
88
|
-
reserveUserToken: expect.any(BigInt),
|
|
89
|
-
reserveValidatorToken: expect.any(BigInt),
|
|
90
|
-
})
|
|
91
|
-
})
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
describe('getTotalSupply', () => {
|
|
95
|
-
test('default', async () => {
|
|
96
|
-
const poolId = await Actions.amm.getPoolId(client, {
|
|
97
|
-
userToken: Addresses.defaultFeeToken,
|
|
18
|
+
userToken: 1n,
|
|
98
19
|
validatorToken: '0x20c0000000000000000000000000000000000001',
|
|
99
20
|
})
|
|
100
|
-
|
|
101
|
-
|
|
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,65 +92,141 @@ 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
|
})
|
|
113
|
+
|
|
114
|
+
test('behavior: single-sided mint (mintWithValidatorToken)', async () => {
|
|
115
|
+
// Create a new token for testing
|
|
116
|
+
const { token } = await Actions.token.createSync(client, {
|
|
117
|
+
name: 'Test Token 2',
|
|
118
|
+
symbol: 'TEST2',
|
|
119
|
+
currency: 'USD',
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
// Grant issuer role to mint tokens
|
|
123
|
+
await Actions.token.grantRolesSync(client, {
|
|
124
|
+
token,
|
|
125
|
+
roles: ['issuer'],
|
|
126
|
+
to: client.account.address,
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
// Mint some tokens to account
|
|
130
|
+
await Actions.token.mintSync(client, {
|
|
131
|
+
to: account.address,
|
|
132
|
+
amount: parseUnits('1000', 6),
|
|
133
|
+
token,
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
// First, establish initial liquidity with two-sided mint
|
|
137
|
+
await Actions.amm.mintSync(client, {
|
|
138
|
+
userToken: {
|
|
139
|
+
address: token,
|
|
140
|
+
amount: parseUnits('100', 6),
|
|
141
|
+
},
|
|
142
|
+
validatorToken: {
|
|
143
|
+
address: 1n,
|
|
144
|
+
amount: parseUnits('100', 6),
|
|
145
|
+
},
|
|
146
|
+
to: account.address,
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
// Get initial pool state
|
|
150
|
+
const poolBefore = await Actions.amm.getPool(client, {
|
|
151
|
+
userToken: token,
|
|
152
|
+
validatorToken: 1n,
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
// Add single-sided liquidity (only validatorToken)
|
|
156
|
+
const { receipt: mintReceipt, ...mintResult } = await Actions.amm.mintSync(
|
|
157
|
+
client,
|
|
158
|
+
{
|
|
159
|
+
userToken: {
|
|
160
|
+
address: token,
|
|
161
|
+
},
|
|
162
|
+
validatorToken: {
|
|
163
|
+
address: 1n,
|
|
164
|
+
amount: parseUnits('50', 6),
|
|
165
|
+
},
|
|
166
|
+
to: account.address,
|
|
167
|
+
},
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
expect(mintReceipt).toBeDefined()
|
|
171
|
+
// amountUserToken should be 0 for single-sided mint
|
|
172
|
+
expect(mintResult.amountUserToken).toBe(0n)
|
|
173
|
+
expect(mintResult.amountValidatorToken).toBe(parseUnits('50', 6))
|
|
174
|
+
expect(mintResult.liquidity).toBeGreaterThan(0n)
|
|
175
|
+
|
|
176
|
+
// Verify pool reserves - only validatorToken should increase
|
|
177
|
+
const poolAfter = await Actions.amm.getPool(client, {
|
|
178
|
+
userToken: token,
|
|
179
|
+
validatorToken: 1n,
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
expect(poolAfter.reserveUserToken).toBe(poolBefore.reserveUserToken)
|
|
183
|
+
expect(poolAfter.reserveValidatorToken).toBe(
|
|
184
|
+
poolBefore.reserveValidatorToken + parseUnits('50', 6),
|
|
185
|
+
)
|
|
186
|
+
expect(poolAfter.totalSupply).toBeGreaterThan(poolBefore.totalSupply)
|
|
187
|
+
})
|
|
188
188
|
})
|
|
189
189
|
|
|
190
190
|
describe('burn', () => {
|
|
191
191
|
test('default', async () => {
|
|
192
|
-
const { tokenAddress } = await setupPoolWithLiquidity()
|
|
192
|
+
const { tokenAddress } = await setupPoolWithLiquidity(client)
|
|
193
193
|
|
|
194
194
|
// Get LP balance before burn
|
|
195
|
-
const poolId = await Actions.amm.getPoolId(client, {
|
|
196
|
-
userToken: tokenAddress,
|
|
197
|
-
validatorToken: Addresses.defaultFeeToken,
|
|
198
|
-
})
|
|
199
195
|
const lpBalanceBefore = await Actions.amm.getLiquidityBalance(client, {
|
|
200
|
-
poolId,
|
|
201
196
|
address: account.address,
|
|
197
|
+
userToken: tokenAddress,
|
|
198
|
+
validatorToken: 1n,
|
|
202
199
|
})
|
|
203
200
|
|
|
204
201
|
// Burn half of LP tokens
|
|
205
|
-
const {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
202
|
+
const {
|
|
203
|
+
receipt: burnReceipt,
|
|
204
|
+
userToken,
|
|
205
|
+
...burnResult
|
|
206
|
+
} = await Actions.amm.burnSync(client, {
|
|
207
|
+
userToken: tokenAddress,
|
|
208
|
+
validatorToken: 1n,
|
|
209
|
+
liquidity: lpBalanceBefore / 2n,
|
|
210
|
+
to: account.address,
|
|
211
|
+
})
|
|
214
212
|
expect(burnReceipt).toBeDefined()
|
|
213
|
+
expect(userToken).toBe(tokenAddress)
|
|
215
214
|
expect(burnResult).toMatchInlineSnapshot(`
|
|
216
215
|
{
|
|
217
|
-
"amountUserToken":
|
|
218
|
-
"amountValidatorToken":
|
|
219
|
-
"liquidity":
|
|
216
|
+
"amountUserToken": 49999999n,
|
|
217
|
+
"amountValidatorToken": 49999999n,
|
|
218
|
+
"liquidity": 2499999999999500n,
|
|
220
219
|
"sender": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
221
220
|
"to": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
222
|
-
"userToken": "0x20C0000000000000000000000000000000000004",
|
|
223
221
|
"validatorToken": "0x20C0000000000000000000000000000000000001",
|
|
224
222
|
}
|
|
225
223
|
`)
|
|
226
224
|
|
|
227
225
|
// Verify LP balance decreased
|
|
228
226
|
const lpBalanceAfter = await Actions.amm.getLiquidityBalance(client, {
|
|
229
|
-
poolId,
|
|
230
227
|
address: account.address,
|
|
228
|
+
userToken: tokenAddress,
|
|
229
|
+
validatorToken: 1n,
|
|
231
230
|
})
|
|
232
231
|
expect(lpBalanceAfter).toBeLessThan(lpBalanceBefore)
|
|
233
232
|
expect(lpBalanceAfter).toBe(lpBalanceBefore / 2n)
|
|
@@ -235,16 +234,21 @@ describe('burn', () => {
|
|
|
235
234
|
// Verify pool reserves decreased
|
|
236
235
|
const pool = await Actions.amm.getPool(client, {
|
|
237
236
|
userToken: tokenAddress,
|
|
238
|
-
validatorToken:
|
|
237
|
+
validatorToken: 1n,
|
|
239
238
|
})
|
|
240
|
-
expect(pool
|
|
241
|
-
|
|
239
|
+
expect(pool).toMatchInlineSnapshot(`
|
|
240
|
+
{
|
|
241
|
+
"reserveUserToken": 50000001n,
|
|
242
|
+
"reserveValidatorToken": 50000001n,
|
|
243
|
+
"totalSupply": 2500000000000500n,
|
|
244
|
+
}
|
|
245
|
+
`)
|
|
242
246
|
})
|
|
243
247
|
})
|
|
244
248
|
|
|
245
249
|
describe('rebalanceSwap', () => {
|
|
246
250
|
test('default', async () => {
|
|
247
|
-
const { tokenAddress } = await setupPoolWithLiquidity()
|
|
251
|
+
const { tokenAddress } = await setupPoolWithLiquidity(client)
|
|
248
252
|
|
|
249
253
|
// Get balance before swap
|
|
250
254
|
const balanceBefore = await Actions.token.getBalance(client, {
|
|
@@ -253,21 +257,24 @@ describe('rebalanceSwap', () => {
|
|
|
253
257
|
})
|
|
254
258
|
|
|
255
259
|
// Perform rebalance swap
|
|
256
|
-
const {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
260
|
+
const {
|
|
261
|
+
receipt: swapReceipt,
|
|
262
|
+
userToken,
|
|
263
|
+
...swapResult
|
|
264
|
+
} = await Actions.amm.rebalanceSwapSync(client, {
|
|
265
|
+
userToken: tokenAddress,
|
|
266
|
+
validatorToken: 1n,
|
|
267
|
+
amountOut: parseUnits('10', 6),
|
|
268
|
+
to: account2.address,
|
|
269
|
+
account: account,
|
|
270
|
+
})
|
|
264
271
|
expect(swapReceipt).toBeDefined()
|
|
272
|
+
expect(userToken).toBe(tokenAddress)
|
|
265
273
|
expect(swapResult).toMatchInlineSnapshot(`
|
|
266
274
|
{
|
|
267
|
-
"amountIn":
|
|
268
|
-
"amountOut":
|
|
275
|
+
"amountIn": 9985001n,
|
|
276
|
+
"amountOut": 10000000n,
|
|
269
277
|
"swapper": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
270
|
-
"userToken": "0x20C0000000000000000000000000000000000004",
|
|
271
278
|
"validatorToken": "0x20C0000000000000000000000000000000000001",
|
|
272
279
|
}
|
|
273
280
|
`)
|
|
@@ -277,13 +284,13 @@ describe('rebalanceSwap', () => {
|
|
|
277
284
|
token: tokenAddress,
|
|
278
285
|
account: account2.address,
|
|
279
286
|
})
|
|
280
|
-
expect(balanceAfter).toBe(balanceBefore +
|
|
287
|
+
expect(balanceAfter).toBe(balanceBefore + parseUnits('10', 6))
|
|
281
288
|
})
|
|
282
289
|
})
|
|
283
290
|
|
|
284
291
|
describe('watchRebalanceSwap', () => {
|
|
285
292
|
test('default', async () => {
|
|
286
|
-
const { tokenAddress } = await setupPoolWithLiquidity()
|
|
293
|
+
const { tokenAddress } = await setupPoolWithLiquidity(client)
|
|
287
294
|
|
|
288
295
|
let eventArgs: any = null
|
|
289
296
|
const unwatch = Actions.amm.watchRebalanceSwap(client, {
|
|
@@ -295,8 +302,8 @@ describe('watchRebalanceSwap', () => {
|
|
|
295
302
|
// Perform rebalance swap
|
|
296
303
|
await Actions.amm.rebalanceSwapSync(client, {
|
|
297
304
|
userToken: tokenAddress,
|
|
298
|
-
validatorToken:
|
|
299
|
-
amountOut:
|
|
305
|
+
validatorToken: 1n,
|
|
306
|
+
amountOut: parseUnits('10', 6),
|
|
300
307
|
to: account2.address,
|
|
301
308
|
account: account,
|
|
302
309
|
})
|
|
@@ -306,9 +313,9 @@ describe('watchRebalanceSwap', () => {
|
|
|
306
313
|
expect(eventArgs).toBeDefined()
|
|
307
314
|
expect(eventArgs.userToken.toLowerCase()).toBe(tokenAddress.toLowerCase())
|
|
308
315
|
expect(eventArgs.validatorToken.toLowerCase()).toBe(
|
|
309
|
-
|
|
316
|
+
'0x20c0000000000000000000000000000000000001',
|
|
310
317
|
)
|
|
311
|
-
expect(eventArgs.amountOut).toBe(
|
|
318
|
+
expect(eventArgs.amountOut).toBe(parseUnits('10', 6))
|
|
312
319
|
|
|
313
320
|
unwatch()
|
|
314
321
|
})
|
|
@@ -333,16 +340,16 @@ describe('watchMint', () => {
|
|
|
333
340
|
// Mint some tokens to account
|
|
334
341
|
await Actions.token.mintSync(client, {
|
|
335
342
|
to: account.address,
|
|
336
|
-
amount:
|
|
343
|
+
amount: parseUnits('1000', 6),
|
|
337
344
|
token,
|
|
338
345
|
})
|
|
339
346
|
|
|
340
347
|
// Mint USD to account
|
|
341
348
|
await writeContractSync(client, {
|
|
342
349
|
abi: Abis.tip20,
|
|
343
|
-
address:
|
|
350
|
+
address: '0x20c0000000000000000000000000000000000001',
|
|
344
351
|
functionName: 'transfer',
|
|
345
|
-
args: [account.address,
|
|
352
|
+
args: [account.address, parseUnits('1000', 6)],
|
|
346
353
|
})
|
|
347
354
|
|
|
348
355
|
let eventArgs: any = null
|
|
@@ -356,11 +363,11 @@ describe('watchMint', () => {
|
|
|
356
363
|
await Actions.amm.mintSync(client, {
|
|
357
364
|
userToken: {
|
|
358
365
|
address: token,
|
|
359
|
-
amount:
|
|
366
|
+
amount: parseUnits('100', 6),
|
|
360
367
|
},
|
|
361
368
|
validatorToken: {
|
|
362
|
-
address:
|
|
363
|
-
amount:
|
|
369
|
+
address: 1n,
|
|
370
|
+
amount: parseUnits('100', 6),
|
|
364
371
|
},
|
|
365
372
|
to: account.address,
|
|
366
373
|
})
|
|
@@ -370,10 +377,10 @@ describe('watchMint', () => {
|
|
|
370
377
|
expect(eventArgs).toBeDefined()
|
|
371
378
|
expect(eventArgs.userToken.address.toLowerCase()).toBe(token.toLowerCase())
|
|
372
379
|
expect(eventArgs.validatorToken.address.toLowerCase()).toBe(
|
|
373
|
-
|
|
380
|
+
'0x20c0000000000000000000000000000000000001',
|
|
374
381
|
)
|
|
375
|
-
expect(eventArgs.userToken.amount).toBe(
|
|
376
|
-
expect(eventArgs.validatorToken.amount).toBe(
|
|
382
|
+
expect(eventArgs.userToken.amount).toBe(parseUnits('100', 6))
|
|
383
|
+
expect(eventArgs.validatorToken.amount).toBe(parseUnits('100', 6))
|
|
377
384
|
|
|
378
385
|
unwatch()
|
|
379
386
|
})
|
|
@@ -381,15 +388,12 @@ describe('watchMint', () => {
|
|
|
381
388
|
|
|
382
389
|
describe('watchBurn', () => {
|
|
383
390
|
test('default', async () => {
|
|
384
|
-
const { tokenAddress } = await setupPoolWithLiquidity()
|
|
391
|
+
const { tokenAddress } = await setupPoolWithLiquidity(client)
|
|
385
392
|
|
|
386
393
|
// Get LP balance
|
|
387
|
-
const poolId = await Actions.amm.getPoolId(client, {
|
|
388
|
-
userToken: tokenAddress,
|
|
389
|
-
validatorToken: Addresses.defaultFeeToken,
|
|
390
|
-
})
|
|
391
394
|
const lpBalance = await Actions.amm.getLiquidityBalance(client, {
|
|
392
|
-
|
|
395
|
+
userToken: tokenAddress,
|
|
396
|
+
validatorToken: 1n,
|
|
393
397
|
address: account.address,
|
|
394
398
|
})
|
|
395
399
|
|
|
@@ -403,7 +407,7 @@ describe('watchBurn', () => {
|
|
|
403
407
|
// Burn LP tokens
|
|
404
408
|
await Actions.amm.burnSync(client, {
|
|
405
409
|
userToken: tokenAddress,
|
|
406
|
-
validatorToken:
|
|
410
|
+
validatorToken: 1n,
|
|
407
411
|
liquidity: lpBalance / 2n,
|
|
408
412
|
to: account.address,
|
|
409
413
|
})
|
|
@@ -413,7 +417,7 @@ describe('watchBurn', () => {
|
|
|
413
417
|
expect(eventArgs).toBeDefined()
|
|
414
418
|
expect(eventArgs.userToken.toLowerCase()).toBe(tokenAddress.toLowerCase())
|
|
415
419
|
expect(eventArgs.validatorToken.toLowerCase()).toBe(
|
|
416
|
-
|
|
420
|
+
'0x20c0000000000000000000000000000000000001',
|
|
417
421
|
)
|
|
418
422
|
expect(eventArgs.liquidity).toBe(lpBalance / 2n)
|
|
419
423
|
|