tempo.ts 0.4.4 → 0.5.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 +2 -3
- package/dist/chains.d.ts +15 -1
- package/dist/chains.d.ts.map +1 -1
- package/dist/chains.js +2 -1
- package/dist/chains.js.map +1 -1
- package/dist/prool/Instance.d.ts +12 -4
- package/dist/prool/Instance.d.ts.map +1 -1
- package/dist/prool/Instance.js +34 -18
- package/dist/prool/Instance.js.map +1 -1
- package/dist/viem/Actions/faucet.d.ts +34 -1
- package/dist/viem/Actions/faucet.d.ts.map +1 -1
- package/dist/viem/Actions/faucet.js +35 -0
- package/dist/viem/Actions/faucet.js.map +1 -1
- package/dist/viem/Chain.d.ts +6 -0
- package/dist/viem/Chain.d.ts.map +1 -1
- package/dist/viem/Chain.js +3 -1
- package/dist/viem/Chain.js.map +1 -1
- package/dist/viem/Formatters.js +1 -1
- package/dist/viem/Formatters.js.map +1 -1
- package/dist/viem/Transaction.d.ts +4 -1
- package/dist/viem/Transaction.d.ts.map +1 -1
- package/dist/viem/Transaction.js.map +1 -1
- package/package.json +1 -1
- package/src/chains.ts +2 -1
- package/src/ox/TransactionEnvelopeAA.test.ts +2 -663
- package/src/ox/e2e.test.ts +659 -0
- package/src/prool/Instance.ts +51 -23
- package/src/tsconfig.json +2 -2
- package/src/viem/Actions/amm.test.ts +68 -58
- package/src/viem/Actions/dex.test.ts +339 -283
- package/src/viem/Actions/faucet.ts +63 -1
- package/src/viem/Actions/fee.test.ts +34 -43
- package/src/viem/Actions/policy.test.ts +115 -81
- package/src/viem/Actions/reward.test.ts +92 -74
- package/src/viem/Actions/token.test.ts +691 -529
- package/src/viem/Chain.ts +3 -1
- package/src/viem/Formatters.ts +1 -1
- package/src/viem/Transaction.ts +4 -1
- package/src/viem/e2e.test.ts +451 -472
- package/src/wagmi/Actions/amm.test.ts +2 -5
- package/src/wagmi/Actions/dex.test.ts +2 -1
- package/src/wagmi/Actions/token.test.ts +2 -1
- package/src/wagmi/Hooks/amm.test.ts +2 -5
- package/src/wagmi/Hooks/dex.test.ts +2 -1
- package/src/wagmi/Hooks/token.test.ts +2 -1
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
Account,
|
|
3
|
+
Address,
|
|
4
|
+
Chain,
|
|
5
|
+
Client,
|
|
6
|
+
Hash,
|
|
7
|
+
TransactionReceipt,
|
|
8
|
+
Transport,
|
|
9
|
+
} from 'viem'
|
|
10
|
+
import { waitForTransactionReceipt } from 'viem/actions'
|
|
2
11
|
import { parseAccount } from 'viem/utils'
|
|
3
12
|
|
|
4
13
|
/**
|
|
@@ -48,3 +57,56 @@ export declare namespace fund {
|
|
|
48
57
|
|
|
49
58
|
export type ReturnValue = readonly Hash[]
|
|
50
59
|
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Funds an account with an initial amount of set token(s)
|
|
63
|
+
* on Tempo's testnet. Waits for the transactions to be included
|
|
64
|
+
* on a block before returning a response.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { createClient, http } from 'viem'
|
|
69
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
70
|
+
* import { Actions } from 'tempo.ts/viem'
|
|
71
|
+
*
|
|
72
|
+
* const client = createClient({
|
|
73
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
74
|
+
* transport: http(),
|
|
75
|
+
* })
|
|
76
|
+
*
|
|
77
|
+
* const hashes = await Actions.faucet.fundSync(client, {
|
|
78
|
+
* account: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
|
|
79
|
+
* })
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @param client - Client.
|
|
83
|
+
* @param parameters - Parameters.
|
|
84
|
+
* @returns The transaction hash.
|
|
85
|
+
*/
|
|
86
|
+
export async function fundSync<chain extends Chain | undefined>(
|
|
87
|
+
client: Client<Transport, chain>,
|
|
88
|
+
parameters: fundSync.Parameters,
|
|
89
|
+
): Promise<fundSync.ReturnValue> {
|
|
90
|
+
const account = parseAccount(parameters.account)
|
|
91
|
+
const hashes = await client.request<{
|
|
92
|
+
Method: 'tempo_fundAddress'
|
|
93
|
+
Parameters: [address: Address]
|
|
94
|
+
ReturnType: readonly Hash[]
|
|
95
|
+
}>({
|
|
96
|
+
method: 'tempo_fundAddress',
|
|
97
|
+
params: [account.address],
|
|
98
|
+
})
|
|
99
|
+
const receipts = await Promise.all(
|
|
100
|
+
hashes.map((hash) => waitForTransactionReceipt(client, { hash })),
|
|
101
|
+
)
|
|
102
|
+
return receipts
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export declare namespace fundSync {
|
|
106
|
+
export type Parameters = {
|
|
107
|
+
/** Account to fund. */
|
|
108
|
+
account: Account | Address
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export type ReturnValue = readonly TransactionReceipt[]
|
|
112
|
+
}
|
|
@@ -3,10 +3,14 @@ import { Abis } from 'tempo.ts/viem'
|
|
|
3
3
|
import { parseUnits } from 'viem'
|
|
4
4
|
import { writeContractSync } from 'viem/actions'
|
|
5
5
|
import { afterEach, describe, expect, test } from 'vitest'
|
|
6
|
-
import {
|
|
6
|
+
import { rpcUrl } from '../../../test/config.js'
|
|
7
|
+
import {
|
|
8
|
+
accounts,
|
|
9
|
+
clientWithAccount,
|
|
10
|
+
fundAddress,
|
|
11
|
+
} from '../../../test/viem/config.js'
|
|
7
12
|
import * as actions from './index.js'
|
|
8
13
|
|
|
9
|
-
const account = accounts[0]
|
|
10
14
|
const account2 = accounts[1]
|
|
11
15
|
const account3 = accounts[2]
|
|
12
16
|
|
|
@@ -17,42 +21,23 @@ afterEach(async () => {
|
|
|
17
21
|
describe('getUserToken', () => {
|
|
18
22
|
test('default', async () => {
|
|
19
23
|
// Fund accounts
|
|
20
|
-
await
|
|
21
|
-
|
|
22
|
-
address: '0x20c0000000000000000000000000000000000001',
|
|
23
|
-
functionName: 'transfer',
|
|
24
|
-
args: [account2.address, parseUnits('100', 6)],
|
|
25
|
-
})
|
|
26
|
-
await writeContractSync(client, {
|
|
27
|
-
abi: Abis.tip20,
|
|
28
|
-
address: '0x20c0000000000000000000000000000000000001',
|
|
29
|
-
functionName: 'transfer',
|
|
30
|
-
args: [account3.address, parseUnits('100', 6)],
|
|
31
|
-
})
|
|
24
|
+
await fundAddress(clientWithAccount, { address: account2.address })
|
|
25
|
+
await fundAddress(clientWithAccount, { address: account3.address })
|
|
32
26
|
|
|
33
27
|
// Set token (address)
|
|
34
|
-
await actions.fee.setUserTokenSync(
|
|
28
|
+
await actions.fee.setUserTokenSync(clientWithAccount, {
|
|
35
29
|
account: account2,
|
|
36
30
|
token: '0x20c0000000000000000000000000000000000001',
|
|
37
31
|
})
|
|
38
32
|
|
|
39
33
|
// Set another token (id)
|
|
40
|
-
await actions.fee.setUserTokenSync(
|
|
34
|
+
await actions.fee.setUserTokenSync(clientWithAccount, {
|
|
41
35
|
account: account3,
|
|
42
36
|
token: 2n,
|
|
43
37
|
})
|
|
44
38
|
|
|
45
|
-
// Assert that account (with default) & account2 (with custom) tokens are set correctly.
|
|
46
|
-
expect(
|
|
47
|
-
await actions.fee.getUserToken(client, { account }),
|
|
48
|
-
).toMatchInlineSnapshot(`
|
|
49
|
-
{
|
|
50
|
-
"address": "0x20C0000000000000000000000000000000000001",
|
|
51
|
-
"id": 1n,
|
|
52
|
-
}
|
|
53
|
-
`)
|
|
54
39
|
expect(
|
|
55
|
-
await actions.fee.getUserToken(
|
|
40
|
+
await actions.fee.getUserToken(clientWithAccount, { account: account2 }),
|
|
56
41
|
).toMatchInlineSnapshot(`
|
|
57
42
|
{
|
|
58
43
|
"address": "0x20C0000000000000000000000000000000000001",
|
|
@@ -60,7 +45,7 @@ describe('getUserToken', () => {
|
|
|
60
45
|
}
|
|
61
46
|
`)
|
|
62
47
|
expect(
|
|
63
|
-
await actions.fee.getUserToken(
|
|
48
|
+
await actions.fee.getUserToken(clientWithAccount, { account: account3 }),
|
|
64
49
|
).toMatchInlineSnapshot(`
|
|
65
50
|
{
|
|
66
51
|
"address": "0x20C0000000000000000000000000000000000002",
|
|
@@ -72,7 +57,9 @@ describe('getUserToken', () => {
|
|
|
72
57
|
|
|
73
58
|
describe('setUserToken', () => {
|
|
74
59
|
test('default', async () => {
|
|
75
|
-
expect(
|
|
60
|
+
expect(
|
|
61
|
+
await actions.fee.getUserToken(clientWithAccount),
|
|
62
|
+
).toMatchInlineSnapshot(
|
|
76
63
|
`
|
|
77
64
|
{
|
|
78
65
|
"address": "0x20C0000000000000000000000000000000000001",
|
|
@@ -82,7 +69,7 @@ describe('setUserToken', () => {
|
|
|
82
69
|
)
|
|
83
70
|
|
|
84
71
|
const { receipt: setReceipt, ...setResult } =
|
|
85
|
-
await actions.fee.setUserTokenSync(
|
|
72
|
+
await actions.fee.setUserTokenSync(clientWithAccount, {
|
|
86
73
|
token: 2n,
|
|
87
74
|
})
|
|
88
75
|
expect(setReceipt).toBeDefined()
|
|
@@ -93,7 +80,9 @@ describe('setUserToken', () => {
|
|
|
93
80
|
}
|
|
94
81
|
`)
|
|
95
82
|
|
|
96
|
-
expect(
|
|
83
|
+
expect(
|
|
84
|
+
await actions.fee.getUserToken(clientWithAccount, {}),
|
|
85
|
+
).toMatchInlineSnapshot(
|
|
97
86
|
`
|
|
98
87
|
{
|
|
99
88
|
"address": "0x20C0000000000000000000000000000000000002",
|
|
@@ -103,7 +92,7 @@ describe('setUserToken', () => {
|
|
|
103
92
|
)
|
|
104
93
|
|
|
105
94
|
const { receipt: resetReceipt, ...resetResult } =
|
|
106
|
-
await actions.fee.setUserTokenSync(
|
|
95
|
+
await actions.fee.setUserTokenSync(clientWithAccount, {
|
|
107
96
|
feeToken: 1n,
|
|
108
97
|
token: 1n,
|
|
109
98
|
})
|
|
@@ -115,7 +104,9 @@ describe('setUserToken', () => {
|
|
|
115
104
|
}
|
|
116
105
|
`)
|
|
117
106
|
|
|
118
|
-
expect(
|
|
107
|
+
expect(
|
|
108
|
+
await actions.fee.getUserToken(clientWithAccount, {}),
|
|
109
|
+
).toMatchInlineSnapshot(
|
|
119
110
|
`
|
|
120
111
|
{
|
|
121
112
|
"address": "0x20C0000000000000000000000000000000000001",
|
|
@@ -134,7 +125,7 @@ describe('watchSetUserToken', async () => {
|
|
|
134
125
|
}> = []
|
|
135
126
|
|
|
136
127
|
// Start watching for user token set events
|
|
137
|
-
const unwatch = actions.fee.watchSetUserToken(
|
|
128
|
+
const unwatch = actions.fee.watchSetUserToken(clientWithAccount, {
|
|
138
129
|
onUserTokenSet: (args, log) => {
|
|
139
130
|
receivedSets.push({ args, log })
|
|
140
131
|
},
|
|
@@ -142,27 +133,27 @@ describe('watchSetUserToken', async () => {
|
|
|
142
133
|
|
|
143
134
|
try {
|
|
144
135
|
// Set token for account2
|
|
145
|
-
await writeContractSync(
|
|
136
|
+
await writeContractSync(clientWithAccount, {
|
|
146
137
|
abi: Abis.tip20,
|
|
147
138
|
address: '0x20c0000000000000000000000000000000000001',
|
|
148
139
|
functionName: 'transfer',
|
|
149
140
|
args: [account2.address, parseUnits('1', 6)],
|
|
150
141
|
})
|
|
151
142
|
|
|
152
|
-
await actions.fee.setUserTokenSync(
|
|
143
|
+
await actions.fee.setUserTokenSync(clientWithAccount, {
|
|
153
144
|
account: account2,
|
|
154
145
|
token: '0x20c0000000000000000000000000000000000001',
|
|
155
146
|
})
|
|
156
147
|
|
|
157
148
|
// Set token for account3
|
|
158
|
-
await writeContractSync(
|
|
149
|
+
await writeContractSync(clientWithAccount, {
|
|
159
150
|
abi: Abis.tip20,
|
|
160
151
|
address: '0x20c0000000000000000000000000000000000001',
|
|
161
152
|
functionName: 'transfer',
|
|
162
153
|
args: [account3.address, parseUnits('1', 6)],
|
|
163
154
|
})
|
|
164
155
|
|
|
165
|
-
await actions.fee.setUserTokenSync(
|
|
156
|
+
await actions.fee.setUserTokenSync(clientWithAccount, {
|
|
166
157
|
account: account3,
|
|
167
158
|
token: '0x20c0000000000000000000000000000000000002',
|
|
168
159
|
})
|
|
@@ -195,7 +186,7 @@ describe('watchSetUserToken', async () => {
|
|
|
195
186
|
}> = []
|
|
196
187
|
|
|
197
188
|
// Start watching for user token set events only for account2
|
|
198
|
-
const unwatch = actions.fee.watchSetUserToken(
|
|
189
|
+
const unwatch = actions.fee.watchSetUserToken(clientWithAccount, {
|
|
199
190
|
args: {
|
|
200
191
|
user: account2.address,
|
|
201
192
|
},
|
|
@@ -206,14 +197,14 @@ describe('watchSetUserToken', async () => {
|
|
|
206
197
|
|
|
207
198
|
try {
|
|
208
199
|
// Transfer gas to accounts
|
|
209
|
-
await writeContractSync(
|
|
200
|
+
await writeContractSync(clientWithAccount, {
|
|
210
201
|
abi: Abis.tip20,
|
|
211
202
|
address: '0x20c0000000000000000000000000000000000001',
|
|
212
203
|
functionName: 'transfer',
|
|
213
204
|
args: [account2.address, parseUnits('1', 6)],
|
|
214
205
|
})
|
|
215
206
|
|
|
216
|
-
await writeContractSync(
|
|
207
|
+
await writeContractSync(clientWithAccount, {
|
|
217
208
|
abi: Abis.tip20,
|
|
218
209
|
address: '0x20c0000000000000000000000000000000000001',
|
|
219
210
|
functionName: 'transfer',
|
|
@@ -221,19 +212,19 @@ describe('watchSetUserToken', async () => {
|
|
|
221
212
|
})
|
|
222
213
|
|
|
223
214
|
// Set token for account2 (should be captured)
|
|
224
|
-
await actions.fee.setUserTokenSync(
|
|
215
|
+
await actions.fee.setUserTokenSync(clientWithAccount, {
|
|
225
216
|
account: account2,
|
|
226
217
|
token: '0x20c0000000000000000000000000000000000001',
|
|
227
218
|
})
|
|
228
219
|
|
|
229
220
|
// Set token for account3 (should NOT be captured)
|
|
230
|
-
await actions.fee.setUserTokenSync(
|
|
221
|
+
await actions.fee.setUserTokenSync(clientWithAccount, {
|
|
231
222
|
account: account3,
|
|
232
223
|
token: '0x20c0000000000000000000000000000000000002',
|
|
233
224
|
})
|
|
234
225
|
|
|
235
226
|
// Set token for account2 again (should be captured)
|
|
236
|
-
await actions.fee.setUserTokenSync(
|
|
227
|
+
await actions.fee.setUserTokenSync(clientWithAccount, {
|
|
237
228
|
account: account2,
|
|
238
229
|
feeToken: 1n,
|
|
239
230
|
token: 2n,
|