tempo.ts 0.1.5 → 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.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 +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 +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 +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
package/src/viem/index.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
+
export * as Tick from '../ox/Tick.js'
|
|
1
2
|
export * as Abis from './Abis.js'
|
|
3
|
+
export * as Account from './Account.js'
|
|
2
4
|
export * as Actions from './Actions/index.js'
|
|
3
5
|
export * as Addresses from './Addresses.js'
|
|
4
6
|
export * as Chain from './Chain.js'
|
|
5
|
-
export * as Client from './Client.js'
|
|
6
|
-
export { createTempoClient } from './Client.js'
|
|
7
7
|
export {
|
|
8
8
|
type Decorator as TempoActions,
|
|
9
9
|
decorator as tempoActions,
|
|
10
10
|
} from './Decorator.js'
|
|
11
11
|
export * as Formatters from './Formatters.js'
|
|
12
|
-
export * as
|
|
12
|
+
export * as P256 from './P256.js'
|
|
13
|
+
export * as Secp256k1 from './Secp256k1.js'
|
|
13
14
|
export * as TokenIds from './TokenIds.js'
|
|
14
15
|
export * as Transaction from './Transaction.js'
|
|
15
16
|
export * as Transport from './Transport.js'
|
|
16
17
|
export { withFeePayer } from './Transport.js'
|
|
18
|
+
export * as WebAuthnP256 from './WebAuthnP256.js'
|
|
19
|
+
export * as WebCryptoP256 from './WebCryptoP256.js'
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import * as Hex from 'ox/Hex'
|
|
2
|
+
import * as PublicKey from 'ox/PublicKey'
|
|
3
|
+
import type { LocalAccount } from 'viem'
|
|
4
|
+
import {
|
|
5
|
+
hashAuthorization,
|
|
6
|
+
hashMessage,
|
|
7
|
+
hashTypedData,
|
|
8
|
+
keccak256,
|
|
9
|
+
} from 'viem/utils'
|
|
10
|
+
import type { RequiredBy } from '../../internal/types.js'
|
|
11
|
+
import * as SignatureEnvelope from '../../ox/SignatureEnvelope.js'
|
|
12
|
+
import * as Transaction from '../Transaction.js'
|
|
13
|
+
|
|
14
|
+
export type Account = RequiredBy<
|
|
15
|
+
Omit<LocalAccount, 'signTransaction'>,
|
|
16
|
+
'sign' | 'signAuthorization'
|
|
17
|
+
> & {
|
|
18
|
+
signTransaction: (
|
|
19
|
+
transaction: Transaction.TransactionSerializable,
|
|
20
|
+
) => Promise<Hex.Hex>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// TODO: this function will be redundant when Viem migrates to Ox.
|
|
24
|
+
/** @internal */
|
|
25
|
+
export function toPrivateKeyAccount(
|
|
26
|
+
parameters: toPrivateKeyAccount.Parameters,
|
|
27
|
+
): toPrivateKeyAccount.ReturnValue {
|
|
28
|
+
const { address, sign, source = 'privateKey' } = parameters
|
|
29
|
+
const publicKey = PublicKey.toHex(parameters.publicKey, {
|
|
30
|
+
includePrefix: false,
|
|
31
|
+
})
|
|
32
|
+
return {
|
|
33
|
+
address,
|
|
34
|
+
sign,
|
|
35
|
+
async signAuthorization(parameters) {
|
|
36
|
+
const { chainId, nonce } = parameters
|
|
37
|
+
const address = parameters.contractAddress ?? parameters.address
|
|
38
|
+
const signature = await sign({
|
|
39
|
+
hash: hashAuthorization({ address, chainId, nonce }),
|
|
40
|
+
})
|
|
41
|
+
const envelope = SignatureEnvelope.from(signature)
|
|
42
|
+
if (envelope.type !== 'secp256k1')
|
|
43
|
+
throw new Error(
|
|
44
|
+
'Unsupported signature type. Expected `secp256k1` but got `' +
|
|
45
|
+
envelope.type +
|
|
46
|
+
'`.',
|
|
47
|
+
)
|
|
48
|
+
const { r, s, yParity } = envelope.signature
|
|
49
|
+
return {
|
|
50
|
+
address,
|
|
51
|
+
chainId,
|
|
52
|
+
nonce,
|
|
53
|
+
r: Hex.fromNumber(r, { size: 32 }),
|
|
54
|
+
s: Hex.fromNumber(s, { size: 32 }),
|
|
55
|
+
yParity,
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
async signMessage(parameters) {
|
|
59
|
+
const { message } = parameters
|
|
60
|
+
const signature = await sign({ hash: hashMessage(message) })
|
|
61
|
+
const envelope = SignatureEnvelope.from(signature)
|
|
62
|
+
if (envelope.type !== 'secp256k1')
|
|
63
|
+
throw new Error(
|
|
64
|
+
'Unsupported signature type. Expected `secp256k1` but got `' +
|
|
65
|
+
envelope.type +
|
|
66
|
+
'`.',
|
|
67
|
+
)
|
|
68
|
+
return SignatureEnvelope.serialize(envelope)
|
|
69
|
+
},
|
|
70
|
+
async signTransaction(transaction) {
|
|
71
|
+
const signature = await sign({
|
|
72
|
+
hash: keccak256(await Transaction.serialize(transaction)),
|
|
73
|
+
})
|
|
74
|
+
const envelope = SignatureEnvelope.from(signature)
|
|
75
|
+
return await Transaction.serialize(transaction, envelope)
|
|
76
|
+
},
|
|
77
|
+
async signTypedData(typedData) {
|
|
78
|
+
const signature = await sign({ hash: hashTypedData(typedData) })
|
|
79
|
+
const envelope = SignatureEnvelope.from(signature)
|
|
80
|
+
if (envelope.type !== 'secp256k1')
|
|
81
|
+
throw new Error(
|
|
82
|
+
'Unsupported signature type. Expected `secp256k1` but got `' +
|
|
83
|
+
envelope.type +
|
|
84
|
+
'`.',
|
|
85
|
+
)
|
|
86
|
+
return SignatureEnvelope.serialize(envelope)
|
|
87
|
+
},
|
|
88
|
+
publicKey,
|
|
89
|
+
source,
|
|
90
|
+
type: 'local',
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export declare namespace toPrivateKeyAccount {
|
|
95
|
+
export type Parameters = {
|
|
96
|
+
/** Address. */
|
|
97
|
+
address: Hex.Hex
|
|
98
|
+
/** Public key. */
|
|
99
|
+
publicKey: PublicKey.PublicKey
|
|
100
|
+
/** Sign function. */
|
|
101
|
+
sign: NonNullable<LocalAccount['sign']>
|
|
102
|
+
/** Source. */
|
|
103
|
+
source?: string | undefined
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export type ReturnValue = Account
|
|
107
|
+
}
|
|
@@ -10,6 +10,7 @@ import type {
|
|
|
10
10
|
MaybeRequired,
|
|
11
11
|
UnionPick,
|
|
12
12
|
} from '../../internal/types.js'
|
|
13
|
+
import type * as TokenId from '../../ox/TokenId.js'
|
|
13
14
|
import type { TransactionRequestAA } from '../Transaction.js'
|
|
14
15
|
|
|
15
16
|
export type GetAccountParameter<
|
|
@@ -33,6 +34,14 @@ export type GetAccountParameter<
|
|
|
33
34
|
: false
|
|
34
35
|
>
|
|
35
36
|
|
|
37
|
+
export type GetFeeTokenParameter<
|
|
38
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
39
|
+
> = chain extends { feeToken: infer feeToken }
|
|
40
|
+
? IsUndefined<feeToken> extends true
|
|
41
|
+
? { feeToken: TokenId.TokenIdOrAddress | null }
|
|
42
|
+
: { feeToken?: TokenId.TokenIdOrAddress | null | undefined }
|
|
43
|
+
: { feeToken: TokenId.TokenIdOrAddress | null }
|
|
44
|
+
|
|
36
45
|
export type ReadParameters = Pick<
|
|
37
46
|
viem_ReadContractParameters<never, never, never>,
|
|
38
47
|
'account' | 'blockNumber' | 'blockOverrides' | 'blockTag' | 'stateOverride'
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`getOrders > default 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"nextCursor": "0x9",
|
|
6
|
+
"orders": [
|
|
7
|
+
{
|
|
8
|
+
"amount": 230000000n,
|
|
9
|
+
"baseToken": "0x20c0000000000000000000000000000000000005",
|
|
10
|
+
"flipTick": 0,
|
|
11
|
+
"isBid": true,
|
|
12
|
+
"isFlip": false,
|
|
13
|
+
"maker": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
14
|
+
"next": 39n,
|
|
15
|
+
"orderId": 19n,
|
|
16
|
+
"prev": 0n,
|
|
17
|
+
"quoteToken": "0x20c0000000000000000000000000000000000004",
|
|
18
|
+
"remaining": 230000000n,
|
|
19
|
+
"tick": 800,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"amount": 430000000n,
|
|
23
|
+
"baseToken": "0x20c0000000000000000000000000000000000005",
|
|
24
|
+
"flipTick": 0,
|
|
25
|
+
"isBid": true,
|
|
26
|
+
"isFlip": false,
|
|
27
|
+
"maker": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
28
|
+
"next": 0n,
|
|
29
|
+
"orderId": 39n,
|
|
30
|
+
"prev": 19n,
|
|
31
|
+
"quoteToken": "0x20c0000000000000000000000000000000000004",
|
|
32
|
+
"remaining": 430000000n,
|
|
33
|
+
"tick": 800,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"amount": 210000000n,
|
|
37
|
+
"baseToken": "0x20c0000000000000000000000000000000000005",
|
|
38
|
+
"flipTick": 0,
|
|
39
|
+
"isBid": true,
|
|
40
|
+
"isFlip": false,
|
|
41
|
+
"maker": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
42
|
+
"next": 37n,
|
|
43
|
+
"orderId": 17n,
|
|
44
|
+
"prev": 0n,
|
|
45
|
+
"quoteToken": "0x20c0000000000000000000000000000000000004",
|
|
46
|
+
"remaining": 210000000n,
|
|
47
|
+
"tick": 600,
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"amount": 410000000n,
|
|
51
|
+
"baseToken": "0x20c0000000000000000000000000000000000005",
|
|
52
|
+
"flipTick": 0,
|
|
53
|
+
"isBid": true,
|
|
54
|
+
"isFlip": false,
|
|
55
|
+
"maker": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
56
|
+
"next": 0n,
|
|
57
|
+
"orderId": 37n,
|
|
58
|
+
"prev": 17n,
|
|
59
|
+
"quoteToken": "0x20c0000000000000000000000000000000000004",
|
|
60
|
+
"remaining": 410000000n,
|
|
61
|
+
"tick": 600,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"amount": 190000000n,
|
|
65
|
+
"baseToken": "0x20c0000000000000000000000000000000000005",
|
|
66
|
+
"flipTick": 0,
|
|
67
|
+
"isBid": true,
|
|
68
|
+
"isFlip": false,
|
|
69
|
+
"maker": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
70
|
+
"next": 35n,
|
|
71
|
+
"orderId": 15n,
|
|
72
|
+
"prev": 0n,
|
|
73
|
+
"quoteToken": "0x20c0000000000000000000000000000000000004",
|
|
74
|
+
"remaining": 190000000n,
|
|
75
|
+
"tick": 400,
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"amount": 390000000n,
|
|
79
|
+
"baseToken": "0x20c0000000000000000000000000000000000005",
|
|
80
|
+
"flipTick": 0,
|
|
81
|
+
"isBid": true,
|
|
82
|
+
"isFlip": false,
|
|
83
|
+
"maker": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
84
|
+
"next": 0n,
|
|
85
|
+
"orderId": 35n,
|
|
86
|
+
"prev": 15n,
|
|
87
|
+
"quoteToken": "0x20c0000000000000000000000000000000000004",
|
|
88
|
+
"remaining": 390000000n,
|
|
89
|
+
"tick": 400,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"amount": 170000000n,
|
|
93
|
+
"baseToken": "0x20c0000000000000000000000000000000000005",
|
|
94
|
+
"flipTick": 0,
|
|
95
|
+
"isBid": true,
|
|
96
|
+
"isFlip": false,
|
|
97
|
+
"maker": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
98
|
+
"next": 33n,
|
|
99
|
+
"orderId": 13n,
|
|
100
|
+
"prev": 0n,
|
|
101
|
+
"quoteToken": "0x20c0000000000000000000000000000000000004",
|
|
102
|
+
"remaining": 170000000n,
|
|
103
|
+
"tick": 200,
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"amount": 370000000n,
|
|
107
|
+
"baseToken": "0x20c0000000000000000000000000000000000005",
|
|
108
|
+
"flipTick": 0,
|
|
109
|
+
"isBid": true,
|
|
110
|
+
"isFlip": false,
|
|
111
|
+
"maker": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
112
|
+
"next": 0n,
|
|
113
|
+
"orderId": 33n,
|
|
114
|
+
"prev": 13n,
|
|
115
|
+
"quoteToken": "0x20c0000000000000000000000000000000000004",
|
|
116
|
+
"remaining": 370000000n,
|
|
117
|
+
"tick": 200,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"amount": 150000000n,
|
|
121
|
+
"baseToken": "0x20c0000000000000000000000000000000000005",
|
|
122
|
+
"flipTick": 0,
|
|
123
|
+
"isBid": true,
|
|
124
|
+
"isFlip": false,
|
|
125
|
+
"maker": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
126
|
+
"next": 31n,
|
|
127
|
+
"orderId": 11n,
|
|
128
|
+
"prev": 0n,
|
|
129
|
+
"quoteToken": "0x20c0000000000000000000000000000000000004",
|
|
130
|
+
"remaining": 150000000n,
|
|
131
|
+
"tick": 0,
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"amount": 350000000n,
|
|
135
|
+
"baseToken": "0x20c0000000000000000000000000000000000005",
|
|
136
|
+
"flipTick": 0,
|
|
137
|
+
"isBid": true,
|
|
138
|
+
"isFlip": false,
|
|
139
|
+
"maker": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
140
|
+
"next": 0n,
|
|
141
|
+
"orderId": 31n,
|
|
142
|
+
"prev": 11n,
|
|
143
|
+
"quoteToken": "0x20c0000000000000000000000000000000000004",
|
|
144
|
+
"remaining": 350000000n,
|
|
145
|
+
"tick": 0,
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
}
|
|
149
|
+
`;
|
|
150
|
+
|
|
151
|
+
exports[`getOrders > infiniteQueryOptions > default 1`] = `
|
|
152
|
+
{
|
|
153
|
+
"pageParams": [
|
|
154
|
+
undefined,
|
|
155
|
+
"0x23",
|
|
156
|
+
],
|
|
157
|
+
"pages": [
|
|
158
|
+
{
|
|
159
|
+
"nextCursor": "0x23",
|
|
160
|
+
"orders": [
|
|
161
|
+
{
|
|
162
|
+
"amount": 230000000n,
|
|
163
|
+
"baseToken": "0x20c0000000000000000000000000000000000005",
|
|
164
|
+
"flipTick": 0,
|
|
165
|
+
"isBid": true,
|
|
166
|
+
"isFlip": false,
|
|
167
|
+
"maker": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
168
|
+
"next": 39n,
|
|
169
|
+
"orderId": 19n,
|
|
170
|
+
"prev": 0n,
|
|
171
|
+
"quoteToken": "0x20c0000000000000000000000000000000000004",
|
|
172
|
+
"remaining": 230000000n,
|
|
173
|
+
"tick": 800,
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
"amount": 430000000n,
|
|
177
|
+
"baseToken": "0x20c0000000000000000000000000000000000005",
|
|
178
|
+
"flipTick": 0,
|
|
179
|
+
"isBid": true,
|
|
180
|
+
"isFlip": false,
|
|
181
|
+
"maker": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
182
|
+
"next": 0n,
|
|
183
|
+
"orderId": 39n,
|
|
184
|
+
"prev": 19n,
|
|
185
|
+
"quoteToken": "0x20c0000000000000000000000000000000000004",
|
|
186
|
+
"remaining": 430000000n,
|
|
187
|
+
"tick": 800,
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
"amount": 210000000n,
|
|
191
|
+
"baseToken": "0x20c0000000000000000000000000000000000005",
|
|
192
|
+
"flipTick": 0,
|
|
193
|
+
"isBid": true,
|
|
194
|
+
"isFlip": false,
|
|
195
|
+
"maker": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
196
|
+
"next": 37n,
|
|
197
|
+
"orderId": 17n,
|
|
198
|
+
"prev": 0n,
|
|
199
|
+
"quoteToken": "0x20c0000000000000000000000000000000000004",
|
|
200
|
+
"remaining": 210000000n,
|
|
201
|
+
"tick": 600,
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
"amount": 410000000n,
|
|
205
|
+
"baseToken": "0x20c0000000000000000000000000000000000005",
|
|
206
|
+
"flipTick": 0,
|
|
207
|
+
"isBid": true,
|
|
208
|
+
"isFlip": false,
|
|
209
|
+
"maker": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
210
|
+
"next": 0n,
|
|
211
|
+
"orderId": 37n,
|
|
212
|
+
"prev": 17n,
|
|
213
|
+
"quoteToken": "0x20c0000000000000000000000000000000000004",
|
|
214
|
+
"remaining": 410000000n,
|
|
215
|
+
"tick": 600,
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
"amount": 190000000n,
|
|
219
|
+
"baseToken": "0x20c0000000000000000000000000000000000005",
|
|
220
|
+
"flipTick": 0,
|
|
221
|
+
"isBid": true,
|
|
222
|
+
"isFlip": false,
|
|
223
|
+
"maker": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
224
|
+
"next": 35n,
|
|
225
|
+
"orderId": 15n,
|
|
226
|
+
"prev": 0n,
|
|
227
|
+
"quoteToken": "0x20c0000000000000000000000000000000000004",
|
|
228
|
+
"remaining": 190000000n,
|
|
229
|
+
"tick": 400,
|
|
230
|
+
},
|
|
231
|
+
],
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
"nextCursor": "0x9",
|
|
235
|
+
"orders": [
|
|
236
|
+
{
|
|
237
|
+
"amount": 390000000n,
|
|
238
|
+
"baseToken": "0x20c0000000000000000000000000000000000005",
|
|
239
|
+
"flipTick": 0,
|
|
240
|
+
"isBid": true,
|
|
241
|
+
"isFlip": false,
|
|
242
|
+
"maker": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
243
|
+
"next": 0n,
|
|
244
|
+
"orderId": 35n,
|
|
245
|
+
"prev": 15n,
|
|
246
|
+
"quoteToken": "0x20c0000000000000000000000000000000000004",
|
|
247
|
+
"remaining": 390000000n,
|
|
248
|
+
"tick": 400,
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
"amount": 170000000n,
|
|
252
|
+
"baseToken": "0x20c0000000000000000000000000000000000005",
|
|
253
|
+
"flipTick": 0,
|
|
254
|
+
"isBid": true,
|
|
255
|
+
"isFlip": false,
|
|
256
|
+
"maker": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
257
|
+
"next": 33n,
|
|
258
|
+
"orderId": 13n,
|
|
259
|
+
"prev": 0n,
|
|
260
|
+
"quoteToken": "0x20c0000000000000000000000000000000000004",
|
|
261
|
+
"remaining": 170000000n,
|
|
262
|
+
"tick": 200,
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
"amount": 370000000n,
|
|
266
|
+
"baseToken": "0x20c0000000000000000000000000000000000005",
|
|
267
|
+
"flipTick": 0,
|
|
268
|
+
"isBid": true,
|
|
269
|
+
"isFlip": false,
|
|
270
|
+
"maker": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
271
|
+
"next": 0n,
|
|
272
|
+
"orderId": 33n,
|
|
273
|
+
"prev": 13n,
|
|
274
|
+
"quoteToken": "0x20c0000000000000000000000000000000000004",
|
|
275
|
+
"remaining": 370000000n,
|
|
276
|
+
"tick": 200,
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
"amount": 150000000n,
|
|
280
|
+
"baseToken": "0x20c0000000000000000000000000000000000005",
|
|
281
|
+
"flipTick": 0,
|
|
282
|
+
"isBid": true,
|
|
283
|
+
"isFlip": false,
|
|
284
|
+
"maker": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
285
|
+
"next": 31n,
|
|
286
|
+
"orderId": 11n,
|
|
287
|
+
"prev": 0n,
|
|
288
|
+
"quoteToken": "0x20c0000000000000000000000000000000000004",
|
|
289
|
+
"remaining": 150000000n,
|
|
290
|
+
"tick": 0,
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
"amount": 350000000n,
|
|
294
|
+
"baseToken": "0x20c0000000000000000000000000000000000005",
|
|
295
|
+
"flipTick": 0,
|
|
296
|
+
"isBid": true,
|
|
297
|
+
"isFlip": false,
|
|
298
|
+
"maker": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
299
|
+
"next": 0n,
|
|
300
|
+
"orderId": 31n,
|
|
301
|
+
"prev": 11n,
|
|
302
|
+
"quoteToken": "0x20c0000000000000000000000000000000000004",
|
|
303
|
+
"remaining": 350000000n,
|
|
304
|
+
"tick": 0,
|
|
305
|
+
},
|
|
306
|
+
],
|
|
307
|
+
},
|
|
308
|
+
],
|
|
309
|
+
}
|
|
310
|
+
`;
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { connect, getConnectorClient } from '@wagmi/core'
|
|
2
|
+
import { parseUnits } from 'viem'
|
|
3
|
+
import { describe, expect, test } from 'vitest'
|
|
4
|
+
import {
|
|
5
|
+
accounts,
|
|
6
|
+
addresses,
|
|
7
|
+
setupPoolWithLiquidity,
|
|
8
|
+
} from '../../../test/viem/config.js'
|
|
9
|
+
import { config, queryClient } from '../../../test/wagmi/config.js'
|
|
10
|
+
import * as ammActions from './amm.js'
|
|
11
|
+
import * as tokenActions from './token.js'
|
|
12
|
+
|
|
13
|
+
const account = accounts[0]
|
|
14
|
+
|
|
15
|
+
describe('getPool', () => {
|
|
16
|
+
test('default', async () => {
|
|
17
|
+
const pool = await ammActions.getPool(config, {
|
|
18
|
+
userToken: addresses.alphaUsd,
|
|
19
|
+
validatorToken: '0x20c0000000000000000000000000000000000001',
|
|
20
|
+
})
|
|
21
|
+
expect(pool).toMatchInlineSnapshot(`
|
|
22
|
+
{
|
|
23
|
+
"reserveUserToken": 0n,
|
|
24
|
+
"reserveValidatorToken": 0n,
|
|
25
|
+
"totalSupply": 0n,
|
|
26
|
+
}
|
|
27
|
+
`)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
describe('queryOptions', () => {
|
|
31
|
+
test('default', async () => {
|
|
32
|
+
const options = ammActions.getPool.queryOptions(config, {
|
|
33
|
+
userToken: addresses.alphaUsd,
|
|
34
|
+
validatorToken: '0x20c0000000000000000000000000000000000001',
|
|
35
|
+
})
|
|
36
|
+
const pool = await queryClient.fetchQuery(options)
|
|
37
|
+
expect(pool).toMatchInlineSnapshot(`
|
|
38
|
+
{
|
|
39
|
+
"reserveUserToken": 0n,
|
|
40
|
+
"reserveValidatorToken": 0n,
|
|
41
|
+
"totalSupply": 0n,
|
|
42
|
+
}
|
|
43
|
+
`)
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
describe('getLiquidityBalance', () => {
|
|
49
|
+
test('default', async () => {
|
|
50
|
+
const balance = await ammActions.getLiquidityBalance(config, {
|
|
51
|
+
userToken: addresses.alphaUsd,
|
|
52
|
+
validatorToken: '0x20c0000000000000000000000000000000000001',
|
|
53
|
+
address: account.address,
|
|
54
|
+
})
|
|
55
|
+
expect(balance).toMatchInlineSnapshot(`0n`)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
describe('queryOptions', () => {
|
|
59
|
+
test('default', async () => {
|
|
60
|
+
const options = ammActions.getLiquidityBalance.queryOptions(config, {
|
|
61
|
+
userToken: addresses.alphaUsd,
|
|
62
|
+
validatorToken: '0x20c0000000000000000000000000000000000001',
|
|
63
|
+
address: account.address,
|
|
64
|
+
})
|
|
65
|
+
const balance = await queryClient.fetchQuery(options)
|
|
66
|
+
expect(balance).toMatchInlineSnapshot(`0n`)
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
describe('mintSync', () => {
|
|
72
|
+
test('default', async () => {
|
|
73
|
+
await connect(config, {
|
|
74
|
+
connector: config.connectors[0]!,
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
// Create a new token for testing
|
|
78
|
+
const { token } = await tokenActions.createSync(config, {
|
|
79
|
+
name: 'Test Token',
|
|
80
|
+
symbol: 'TEST',
|
|
81
|
+
currency: 'USD',
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
// Grant issuer role to mint tokens
|
|
85
|
+
await tokenActions.grantRolesSync(config, {
|
|
86
|
+
token,
|
|
87
|
+
roles: ['issuer'],
|
|
88
|
+
to: account.address,
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
// Mint some tokens to account
|
|
92
|
+
await tokenActions.mintSync(config, {
|
|
93
|
+
to: account.address,
|
|
94
|
+
amount: parseUnits('1000', 6),
|
|
95
|
+
token,
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
// Add liquidity to pool
|
|
99
|
+
const { receipt: mintReceipt, ...mintResult } = await ammActions.mintSync(
|
|
100
|
+
config,
|
|
101
|
+
{
|
|
102
|
+
userToken: {
|
|
103
|
+
address: token,
|
|
104
|
+
amount: parseUnits('100', 6),
|
|
105
|
+
},
|
|
106
|
+
validatorToken: {
|
|
107
|
+
address: addresses.alphaUsd,
|
|
108
|
+
amount: parseUnits('100', 6),
|
|
109
|
+
},
|
|
110
|
+
to: account.address,
|
|
111
|
+
},
|
|
112
|
+
)
|
|
113
|
+
expect(mintReceipt).toBeDefined()
|
|
114
|
+
expect(mintResult).toMatchInlineSnapshot(`
|
|
115
|
+
{
|
|
116
|
+
"amountUserToken": 100000000n,
|
|
117
|
+
"amountValidatorToken": 100000000n,
|
|
118
|
+
"liquidity": 4999999999999000n,
|
|
119
|
+
"sender": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
120
|
+
"userToken": "0x20C0000000000000000000000000000000000004",
|
|
121
|
+
"validatorToken": "0x20C0000000000000000000000000000000000001",
|
|
122
|
+
}
|
|
123
|
+
`)
|
|
124
|
+
})
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
describe('burnSync', () => {
|
|
128
|
+
test('default', async () => {
|
|
129
|
+
await connect(config, {
|
|
130
|
+
connector: config.connectors[0]!,
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
const client = await getConnectorClient(config)
|
|
134
|
+
const { tokenAddress } = await setupPoolWithLiquidity(client)
|
|
135
|
+
|
|
136
|
+
// Get LP balance before burn
|
|
137
|
+
const lpBalanceBefore = await ammActions.getLiquidityBalance(config, {
|
|
138
|
+
userToken: tokenAddress,
|
|
139
|
+
validatorToken: addresses.alphaUsd,
|
|
140
|
+
address: account.address,
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
// Burn half of LP tokens
|
|
144
|
+
const { receipt: burnReceipt, ...burnResult } = await ammActions.burnSync(
|
|
145
|
+
config,
|
|
146
|
+
{
|
|
147
|
+
userToken: tokenAddress,
|
|
148
|
+
validatorToken: addresses.alphaUsd,
|
|
149
|
+
liquidity: lpBalanceBefore / 2n,
|
|
150
|
+
to: account.address,
|
|
151
|
+
},
|
|
152
|
+
)
|
|
153
|
+
expect(burnReceipt).toBeDefined()
|
|
154
|
+
expect(burnResult).toMatchInlineSnapshot(`
|
|
155
|
+
{
|
|
156
|
+
"amountUserToken": 49999999n,
|
|
157
|
+
"amountValidatorToken": 49999999n,
|
|
158
|
+
"liquidity": 2499999999999500n,
|
|
159
|
+
"sender": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
160
|
+
"to": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
161
|
+
"userToken": "0x20c0000000000000000000000000000000000005",
|
|
162
|
+
"validatorToken": "0x20C0000000000000000000000000000000000001",
|
|
163
|
+
}
|
|
164
|
+
`)
|
|
165
|
+
})
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
describe('rebalanceSwapSync', () => {
|
|
169
|
+
test('default', async () => {
|
|
170
|
+
await connect(config, {
|
|
171
|
+
connector: config.connectors[0]!,
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
const client = await getConnectorClient(config)
|
|
175
|
+
const { tokenAddress } = await setupPoolWithLiquidity(client)
|
|
176
|
+
|
|
177
|
+
const account2 = accounts[1]
|
|
178
|
+
|
|
179
|
+
// Perform rebalance swap
|
|
180
|
+
const { receipt: swapReceipt, ...swapResult } =
|
|
181
|
+
await ammActions.rebalanceSwapSync(config, {
|
|
182
|
+
userToken: tokenAddress,
|
|
183
|
+
validatorToken: addresses.alphaUsd,
|
|
184
|
+
amountOut: parseUnits('10', 6),
|
|
185
|
+
to: account2.address,
|
|
186
|
+
})
|
|
187
|
+
expect(swapReceipt).toBeDefined()
|
|
188
|
+
expect(swapResult).toMatchInlineSnapshot(`
|
|
189
|
+
{
|
|
190
|
+
"amountIn": 9985001n,
|
|
191
|
+
"amountOut": 10000000n,
|
|
192
|
+
"swapper": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
193
|
+
"userToken": "0x20C0000000000000000000000000000000000006",
|
|
194
|
+
"validatorToken": "0x20C0000000000000000000000000000000000001",
|
|
195
|
+
}
|
|
196
|
+
`)
|
|
197
|
+
})
|
|
198
|
+
})
|