@0xsequence/relayer 3.0.0-beta.8 → 3.0.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/.turbo/turbo-build.log +2 -2
- package/.turbo/turbo-lint.log +4 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/CHANGELOG.md +134 -0
- package/dist/preconditions/codec.d.ts.map +1 -1
- package/dist/preconditions/codec.js +55 -45
- package/dist/relayer/relayer.d.ts +2 -2
- package/dist/relayer/relayer.d.ts.map +1 -1
- package/dist/relayer/relayer.js +3 -1
- package/dist/relayer/rpc-relayer/index.d.ts +3 -3
- package/dist/relayer/rpc-relayer/index.d.ts.map +1 -1
- package/dist/relayer/rpc-relayer/index.js +26 -25
- package/dist/relayer/standard/eip6963.d.ts +2 -2
- package/dist/relayer/standard/eip6963.d.ts.map +1 -1
- package/dist/relayer/standard/eip6963.js +3 -3
- package/dist/relayer/standard/local.d.ts +2 -3
- package/dist/relayer/standard/local.d.ts.map +1 -1
- package/dist/relayer/standard/local.js +14 -30
- package/dist/relayer/standard/pk-relayer.d.ts +3 -3
- package/dist/relayer/standard/pk-relayer.d.ts.map +1 -1
- package/dist/relayer/standard/pk-relayer.js +3 -3
- package/dist/relayer/standard/sequence.d.ts +3 -3
- package/dist/relayer/standard/sequence.d.ts.map +1 -1
- package/dist/relayer/standard/sequence.js +2 -3
- package/eslint.config.js +4 -0
- package/package.json +9 -7
- package/src/preconditions/codec.ts +63 -39
- package/src/relayer/relayer.ts +4 -1
- package/src/relayer/rpc-relayer/index.ts +50 -33
- package/src/relayer/standard/eip6963.ts +4 -3
- package/src/relayer/standard/local.ts +37 -44
- package/src/relayer/standard/pk-relayer.ts +4 -3
- package/src/relayer/standard/sequence.ts +3 -3
- package/test/preconditions/codec.test.ts +11 -11
- package/test/preconditions/preconditions.test.ts +97 -138
- package/test/preconditions/selectors.test.ts +76 -254
- package/test/preconditions/types.test.ts +6 -6
- package/test/relayer/relayer.test.ts +4 -4
|
@@ -15,104 +15,71 @@ import {
|
|
|
15
15
|
} from '../../src/preconditions/types.js'
|
|
16
16
|
import { Network } from '@0xsequence/wallet-primitives'
|
|
17
17
|
|
|
18
|
-
// Test addresses
|
|
19
|
-
const TEST_ADDRESS =
|
|
20
|
-
const TOKEN_ADDRESS =
|
|
18
|
+
// Test addresses (strings for TransactionPrecondition)
|
|
19
|
+
const TEST_ADDRESS = '0x1234567890123456789012345678901234567890'
|
|
20
|
+
const TOKEN_ADDRESS = '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd'
|
|
21
|
+
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
|
|
22
|
+
|
|
23
|
+
function nativePrecondition(overrides: Partial<TransactionPrecondition> = {}): TransactionPrecondition {
|
|
24
|
+
return {
|
|
25
|
+
type: 'native-balance',
|
|
26
|
+
chainId: Network.ChainId.MAINNET,
|
|
27
|
+
ownerAddress: TEST_ADDRESS,
|
|
28
|
+
tokenAddress: ZERO_ADDRESS,
|
|
29
|
+
minAmount: 1000000000000000000n,
|
|
30
|
+
...overrides,
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function erc20Precondition(overrides: Partial<TransactionPrecondition> = {}): TransactionPrecondition {
|
|
35
|
+
return {
|
|
36
|
+
type: 'erc20-balance',
|
|
37
|
+
chainId: Network.ChainId.MAINNET,
|
|
38
|
+
ownerAddress: TEST_ADDRESS,
|
|
39
|
+
tokenAddress: TOKEN_ADDRESS,
|
|
40
|
+
minAmount: 1000000n,
|
|
41
|
+
...overrides,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function erc721OwnershipPrecondition(overrides: Partial<TransactionPrecondition> = {}): TransactionPrecondition {
|
|
46
|
+
return {
|
|
47
|
+
type: 'erc721-ownership',
|
|
48
|
+
chainId: Network.ChainId.MAINNET,
|
|
49
|
+
ownerAddress: TEST_ADDRESS,
|
|
50
|
+
tokenAddress: TOKEN_ADDRESS,
|
|
51
|
+
minAmount: 0n,
|
|
52
|
+
...overrides,
|
|
53
|
+
}
|
|
54
|
+
}
|
|
21
55
|
|
|
22
56
|
describe('Preconditions Selectors', () => {
|
|
23
57
|
describe('extractChainID', () => {
|
|
24
58
|
it('should extract chainID from valid precondition data', () => {
|
|
25
|
-
const precondition
|
|
26
|
-
type: 'native-balance',
|
|
27
|
-
data: JSON.stringify({
|
|
28
|
-
address: TEST_ADDRESS,
|
|
29
|
-
chainID: '1',
|
|
30
|
-
min: '1000000000000000000',
|
|
31
|
-
}),
|
|
32
|
-
}
|
|
33
|
-
|
|
59
|
+
const precondition = nativePrecondition({ chainId: Network.ChainId.MAINNET })
|
|
34
60
|
const chainId = extractChainID(precondition)
|
|
35
61
|
expect(chainId).toBe(Network.ChainId.MAINNET)
|
|
36
62
|
})
|
|
37
63
|
|
|
38
64
|
it('should extract large chainID values', () => {
|
|
39
|
-
const precondition
|
|
40
|
-
type: 'native-balance',
|
|
41
|
-
data: JSON.stringify({
|
|
42
|
-
address: TEST_ADDRESS,
|
|
43
|
-
chainID: '42161', // Arbitrum chainID
|
|
44
|
-
}),
|
|
45
|
-
}
|
|
46
|
-
|
|
65
|
+
const precondition = nativePrecondition({ chainId: Network.ChainId.ARBITRUM })
|
|
47
66
|
const chainId = extractChainID(precondition)
|
|
48
67
|
expect(chainId).toBe(Network.ChainId.ARBITRUM)
|
|
49
68
|
})
|
|
50
69
|
|
|
51
70
|
it('should return undefined when chainID is not present', () => {
|
|
52
|
-
const precondition:
|
|
53
|
-
type: 'native-balance',
|
|
54
|
-
data: JSON.stringify({
|
|
55
|
-
address: TEST_ADDRESS,
|
|
56
|
-
min: '1000000000000000000',
|
|
57
|
-
}),
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const chainId = extractChainID(precondition)
|
|
61
|
-
expect(chainId).toBeUndefined()
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
it('should return undefined when chainID is falsy', () => {
|
|
65
|
-
const precondition: TransactionPrecondition = {
|
|
66
|
-
type: 'native-balance',
|
|
67
|
-
data: JSON.stringify({
|
|
68
|
-
address: TEST_ADDRESS,
|
|
69
|
-
chainID: '',
|
|
70
|
-
min: '1000000000000000000',
|
|
71
|
-
}),
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const chainId = extractChainID(precondition)
|
|
75
|
-
expect(chainId).toBeUndefined()
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
it('should return undefined when chainID is null', () => {
|
|
79
|
-
const precondition: TransactionPrecondition = {
|
|
80
|
-
type: 'native-balance',
|
|
81
|
-
data: JSON.stringify({
|
|
82
|
-
address: TEST_ADDRESS,
|
|
83
|
-
chainID: null,
|
|
84
|
-
min: '1000000000000000000',
|
|
85
|
-
}),
|
|
86
|
-
}
|
|
87
|
-
|
|
71
|
+
const precondition = { type: 'native-balance', ownerAddress: TEST_ADDRESS, tokenAddress: ZERO_ADDRESS, minAmount: 1n } as TransactionPrecondition
|
|
88
72
|
const chainId = extractChainID(precondition)
|
|
89
73
|
expect(chainId).toBeUndefined()
|
|
90
74
|
})
|
|
91
75
|
|
|
92
76
|
it('should return undefined for null/undefined precondition', () => {
|
|
93
|
-
expect(extractChainID(null as
|
|
94
|
-
expect(extractChainID(undefined as
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
it('should return undefined for invalid JSON', () => {
|
|
98
|
-
const precondition: TransactionPrecondition = {
|
|
99
|
-
type: 'native-balance',
|
|
100
|
-
data: 'invalid json',
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const chainId = extractChainID(precondition)
|
|
104
|
-
expect(chainId).toBeUndefined()
|
|
77
|
+
expect(extractChainID(null as unknown as TransactionPrecondition)).toBeUndefined()
|
|
78
|
+
expect(extractChainID(undefined as unknown as TransactionPrecondition)).toBeUndefined()
|
|
105
79
|
})
|
|
106
80
|
|
|
107
81
|
it('should handle chainID with value 0', () => {
|
|
108
|
-
const precondition
|
|
109
|
-
type: 'native-balance',
|
|
110
|
-
data: JSON.stringify({
|
|
111
|
-
address: TEST_ADDRESS,
|
|
112
|
-
chainID: '0',
|
|
113
|
-
}),
|
|
114
|
-
}
|
|
115
|
-
|
|
82
|
+
const precondition = nativePrecondition({ chainId: 0 })
|
|
116
83
|
const chainId = extractChainID(precondition)
|
|
117
84
|
expect(chainId).toBe(0)
|
|
118
85
|
})
|
|
@@ -121,21 +88,8 @@ describe('Preconditions Selectors', () => {
|
|
|
121
88
|
describe('extractSupportedPreconditions', () => {
|
|
122
89
|
it('should extract valid preconditions', () => {
|
|
123
90
|
const intents: TransactionPrecondition[] = [
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
data: JSON.stringify({
|
|
127
|
-
address: TEST_ADDRESS,
|
|
128
|
-
min: '1000000000000000000',
|
|
129
|
-
}),
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
type: 'erc20-balance',
|
|
133
|
-
data: JSON.stringify({
|
|
134
|
-
address: TEST_ADDRESS,
|
|
135
|
-
token: TOKEN_ADDRESS,
|
|
136
|
-
min: '1000000',
|
|
137
|
-
}),
|
|
138
|
-
},
|
|
91
|
+
nativePrecondition(),
|
|
92
|
+
erc20Precondition(),
|
|
139
93
|
]
|
|
140
94
|
|
|
141
95
|
const results = extractSupportedPreconditions(intents)
|
|
@@ -146,21 +100,9 @@ describe('Preconditions Selectors', () => {
|
|
|
146
100
|
|
|
147
101
|
it('should filter out invalid preconditions', () => {
|
|
148
102
|
const intents: TransactionPrecondition[] = [
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
address: TEST_ADDRESS,
|
|
153
|
-
min: '1000000000000000000',
|
|
154
|
-
}),
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
type: 'unknown-type',
|
|
158
|
-
data: JSON.stringify({ address: TEST_ADDRESS }),
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
type: 'native-balance',
|
|
162
|
-
data: 'invalid json',
|
|
163
|
-
},
|
|
103
|
+
nativePrecondition(),
|
|
104
|
+
{ type: 'unknown-type', chainId: 1, ownerAddress: TEST_ADDRESS, tokenAddress: ZERO_ADDRESS, minAmount: 0n } as TransactionPrecondition,
|
|
105
|
+
nativePrecondition({ ownerAddress: '' }),
|
|
164
106
|
]
|
|
165
107
|
|
|
166
108
|
const results = extractSupportedPreconditions(intents)
|
|
@@ -169,8 +111,8 @@ describe('Preconditions Selectors', () => {
|
|
|
169
111
|
})
|
|
170
112
|
|
|
171
113
|
it('should return empty array for null/undefined input', () => {
|
|
172
|
-
expect(extractSupportedPreconditions(null as
|
|
173
|
-
expect(extractSupportedPreconditions(undefined as
|
|
114
|
+
expect(extractSupportedPreconditions(null as unknown as TransactionPrecondition[])).toEqual([])
|
|
115
|
+
expect(extractSupportedPreconditions(undefined as unknown as TransactionPrecondition[])).toEqual([])
|
|
174
116
|
})
|
|
175
117
|
|
|
176
118
|
it('should return empty array for empty input', () => {
|
|
@@ -180,25 +122,9 @@ describe('Preconditions Selectors', () => {
|
|
|
180
122
|
|
|
181
123
|
it('should handle mixed valid and invalid preconditions', () => {
|
|
182
124
|
const intents: TransactionPrecondition[] = [
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
address: TEST_ADDRESS,
|
|
187
|
-
min: '1000000000000000000',
|
|
188
|
-
}),
|
|
189
|
-
},
|
|
190
|
-
{
|
|
191
|
-
type: 'erc721-ownership',
|
|
192
|
-
data: JSON.stringify({
|
|
193
|
-
address: TEST_ADDRESS,
|
|
194
|
-
token: TOKEN_ADDRESS,
|
|
195
|
-
tokenId: '123',
|
|
196
|
-
}),
|
|
197
|
-
},
|
|
198
|
-
{
|
|
199
|
-
type: 'invalid-type',
|
|
200
|
-
data: JSON.stringify({ address: TEST_ADDRESS }),
|
|
201
|
-
},
|
|
125
|
+
nativePrecondition(),
|
|
126
|
+
erc721OwnershipPrecondition(),
|
|
127
|
+
{ type: 'invalid-type', chainId: 1, ownerAddress: TEST_ADDRESS, tokenAddress: ZERO_ADDRESS, minAmount: 0n } as TransactionPrecondition,
|
|
202
128
|
]
|
|
203
129
|
|
|
204
130
|
const results = extractSupportedPreconditions(intents)
|
|
@@ -211,58 +137,23 @@ describe('Preconditions Selectors', () => {
|
|
|
211
137
|
describe('extractNativeBalancePreconditions', () => {
|
|
212
138
|
it('should extract only native balance preconditions', () => {
|
|
213
139
|
const intents: TransactionPrecondition[] = [
|
|
214
|
-
{
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
address: TEST_ADDRESS,
|
|
218
|
-
min: '1000000000000000000',
|
|
219
|
-
}),
|
|
220
|
-
},
|
|
221
|
-
{
|
|
222
|
-
type: 'erc20-balance',
|
|
223
|
-
data: JSON.stringify({
|
|
224
|
-
address: TEST_ADDRESS,
|
|
225
|
-
token: TOKEN_ADDRESS,
|
|
226
|
-
min: '1000000',
|
|
227
|
-
}),
|
|
228
|
-
},
|
|
229
|
-
{
|
|
230
|
-
type: 'native-balance',
|
|
231
|
-
data: JSON.stringify({
|
|
232
|
-
address: TEST_ADDRESS,
|
|
233
|
-
max: '2000000000000000000',
|
|
234
|
-
}),
|
|
235
|
-
},
|
|
140
|
+
nativePrecondition({ minAmount: 1000000000000000000n }),
|
|
141
|
+
erc20Precondition(),
|
|
142
|
+
nativePrecondition({ minAmount: 2000000000000000000n }),
|
|
236
143
|
]
|
|
237
144
|
|
|
238
145
|
const results = extractNativeBalancePreconditions(intents)
|
|
239
146
|
expect(results).toHaveLength(2)
|
|
240
147
|
expect(results[0]).toBeInstanceOf(NativeBalancePrecondition)
|
|
241
148
|
expect(results[1]).toBeInstanceOf(NativeBalancePrecondition)
|
|
242
|
-
|
|
243
|
-
// Verify the specific properties
|
|
244
149
|
expect(results[0].min).toBe(1000000000000000000n)
|
|
245
|
-
expect(results[1].
|
|
150
|
+
expect(results[1].min).toBe(2000000000000000000n)
|
|
246
151
|
})
|
|
247
152
|
|
|
248
153
|
it('should return empty array when no native balance preconditions exist', () => {
|
|
249
154
|
const intents: TransactionPrecondition[] = [
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
data: JSON.stringify({
|
|
253
|
-
address: TEST_ADDRESS,
|
|
254
|
-
token: TOKEN_ADDRESS,
|
|
255
|
-
min: '1000000',
|
|
256
|
-
}),
|
|
257
|
-
},
|
|
258
|
-
{
|
|
259
|
-
type: 'erc721-ownership',
|
|
260
|
-
data: JSON.stringify({
|
|
261
|
-
address: TEST_ADDRESS,
|
|
262
|
-
token: TOKEN_ADDRESS,
|
|
263
|
-
tokenId: '123',
|
|
264
|
-
}),
|
|
265
|
-
},
|
|
155
|
+
erc20Precondition(),
|
|
156
|
+
erc721OwnershipPrecondition(),
|
|
266
157
|
]
|
|
267
158
|
|
|
268
159
|
const results = extractNativeBalancePreconditions(intents)
|
|
@@ -270,8 +161,8 @@ describe('Preconditions Selectors', () => {
|
|
|
270
161
|
})
|
|
271
162
|
|
|
272
163
|
it('should return empty array for null/undefined input', () => {
|
|
273
|
-
expect(extractNativeBalancePreconditions(null as
|
|
274
|
-
expect(extractNativeBalancePreconditions(undefined as
|
|
164
|
+
expect(extractNativeBalancePreconditions(null as unknown as TransactionPrecondition[])).toEqual([])
|
|
165
|
+
expect(extractNativeBalancePreconditions(undefined as unknown as TransactionPrecondition[])).toEqual([])
|
|
275
166
|
})
|
|
276
167
|
|
|
277
168
|
it('should return empty array for empty input', () => {
|
|
@@ -281,24 +172,8 @@ describe('Preconditions Selectors', () => {
|
|
|
281
172
|
|
|
282
173
|
it('should filter out invalid native balance preconditions', () => {
|
|
283
174
|
const intents: TransactionPrecondition[] = [
|
|
284
|
-
{
|
|
285
|
-
|
|
286
|
-
data: JSON.stringify({
|
|
287
|
-
address: TEST_ADDRESS,
|
|
288
|
-
min: '1000000000000000000',
|
|
289
|
-
}),
|
|
290
|
-
},
|
|
291
|
-
{
|
|
292
|
-
type: 'native-balance',
|
|
293
|
-
data: 'invalid json', // This will be filtered out
|
|
294
|
-
},
|
|
295
|
-
{
|
|
296
|
-
type: 'native-balance',
|
|
297
|
-
data: JSON.stringify({
|
|
298
|
-
// Missing address - this will be filtered out
|
|
299
|
-
min: '1000000000000000000',
|
|
300
|
-
}),
|
|
301
|
-
},
|
|
175
|
+
nativePrecondition({ minAmount: 1000000000000000000n }),
|
|
176
|
+
nativePrecondition({ ownerAddress: '' }),
|
|
302
177
|
]
|
|
303
178
|
|
|
304
179
|
const results = extractNativeBalancePreconditions(intents)
|
|
@@ -311,60 +186,25 @@ describe('Preconditions Selectors', () => {
|
|
|
311
186
|
describe('extractERC20BalancePreconditions', () => {
|
|
312
187
|
it('should extract only ERC20 balance preconditions', () => {
|
|
313
188
|
const intents: TransactionPrecondition[] = [
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
address: TEST_ADDRESS,
|
|
318
|
-
min: '1000000000000000000',
|
|
319
|
-
}),
|
|
320
|
-
},
|
|
321
|
-
{
|
|
322
|
-
type: 'erc20-balance',
|
|
323
|
-
data: JSON.stringify({
|
|
324
|
-
address: TEST_ADDRESS,
|
|
325
|
-
token: TOKEN_ADDRESS,
|
|
326
|
-
min: '1000000',
|
|
327
|
-
}),
|
|
328
|
-
},
|
|
329
|
-
{
|
|
330
|
-
type: 'erc20-balance',
|
|
331
|
-
data: JSON.stringify({
|
|
332
|
-
address: TEST_ADDRESS,
|
|
333
|
-
token: TOKEN_ADDRESS,
|
|
334
|
-
max: '2000000',
|
|
335
|
-
}),
|
|
336
|
-
},
|
|
189
|
+
nativePrecondition(),
|
|
190
|
+
erc20Precondition({ minAmount: 1000000n }),
|
|
191
|
+
erc20Precondition({ minAmount: 2000000n }),
|
|
337
192
|
]
|
|
338
193
|
|
|
339
194
|
const results = extractERC20BalancePreconditions(intents)
|
|
340
195
|
expect(results).toHaveLength(2)
|
|
341
196
|
expect(results[0]).toBeInstanceOf(Erc20BalancePrecondition)
|
|
342
197
|
expect(results[1]).toBeInstanceOf(Erc20BalancePrecondition)
|
|
343
|
-
|
|
344
|
-
// Verify the specific properties
|
|
345
198
|
expect(results[0].min).toBe(1000000n)
|
|
346
|
-
expect(results[1].
|
|
347
|
-
expect(results[0].token).
|
|
348
|
-
expect(results[1].token).
|
|
199
|
+
expect(results[1].min).toBe(2000000n)
|
|
200
|
+
expect(results[0].token).toEqual(Address.from(TOKEN_ADDRESS))
|
|
201
|
+
expect(results[1].token).toEqual(Address.from(TOKEN_ADDRESS))
|
|
349
202
|
})
|
|
350
203
|
|
|
351
204
|
it('should return empty array when no ERC20 balance preconditions exist', () => {
|
|
352
205
|
const intents: TransactionPrecondition[] = [
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
data: JSON.stringify({
|
|
356
|
-
address: TEST_ADDRESS,
|
|
357
|
-
min: '1000000000000000000',
|
|
358
|
-
}),
|
|
359
|
-
},
|
|
360
|
-
{
|
|
361
|
-
type: 'erc721-ownership',
|
|
362
|
-
data: JSON.stringify({
|
|
363
|
-
address: TEST_ADDRESS,
|
|
364
|
-
token: TOKEN_ADDRESS,
|
|
365
|
-
tokenId: '123',
|
|
366
|
-
}),
|
|
367
|
-
},
|
|
206
|
+
nativePrecondition(),
|
|
207
|
+
erc721OwnershipPrecondition(),
|
|
368
208
|
]
|
|
369
209
|
|
|
370
210
|
const results = extractERC20BalancePreconditions(intents)
|
|
@@ -372,8 +212,8 @@ describe('Preconditions Selectors', () => {
|
|
|
372
212
|
})
|
|
373
213
|
|
|
374
214
|
it('should return empty array for null/undefined input', () => {
|
|
375
|
-
expect(extractERC20BalancePreconditions(null as
|
|
376
|
-
expect(extractERC20BalancePreconditions(undefined as
|
|
215
|
+
expect(extractERC20BalancePreconditions(null as unknown as TransactionPrecondition[])).toEqual([])
|
|
216
|
+
expect(extractERC20BalancePreconditions(undefined as unknown as TransactionPrecondition[])).toEqual([])
|
|
377
217
|
})
|
|
378
218
|
|
|
379
219
|
it('should return empty array for empty input', () => {
|
|
@@ -383,33 +223,15 @@ describe('Preconditions Selectors', () => {
|
|
|
383
223
|
|
|
384
224
|
it('should filter out invalid ERC20 balance preconditions', () => {
|
|
385
225
|
const intents: TransactionPrecondition[] = [
|
|
386
|
-
{
|
|
387
|
-
|
|
388
|
-
data: JSON.stringify({
|
|
389
|
-
address: TEST_ADDRESS,
|
|
390
|
-
token: TOKEN_ADDRESS,
|
|
391
|
-
min: '1000000',
|
|
392
|
-
}),
|
|
393
|
-
},
|
|
394
|
-
{
|
|
395
|
-
type: 'erc20-balance',
|
|
396
|
-
data: 'invalid json', // This will be filtered out
|
|
397
|
-
},
|
|
398
|
-
{
|
|
399
|
-
type: 'erc20-balance',
|
|
400
|
-
data: JSON.stringify({
|
|
401
|
-
address: TEST_ADDRESS,
|
|
402
|
-
// Missing token address - this will be filtered out
|
|
403
|
-
min: '1000000',
|
|
404
|
-
}),
|
|
405
|
-
},
|
|
226
|
+
erc20Precondition({ minAmount: 1000000n }),
|
|
227
|
+
erc20Precondition({ tokenAddress: '' }),
|
|
406
228
|
]
|
|
407
229
|
|
|
408
230
|
const results = extractERC20BalancePreconditions(intents)
|
|
409
231
|
expect(results).toHaveLength(1)
|
|
410
232
|
expect(results[0]).toBeInstanceOf(Erc20BalancePrecondition)
|
|
411
233
|
expect(results[0].min).toBe(1000000n)
|
|
412
|
-
expect(results[0].token).
|
|
234
|
+
expect(results[0].token).toEqual(Address.from(TOKEN_ADDRESS))
|
|
413
235
|
})
|
|
414
236
|
})
|
|
415
237
|
})
|
|
@@ -179,7 +179,7 @@ describe('Preconditions Types', () => {
|
|
|
179
179
|
TEST_ADDRESS,
|
|
180
180
|
TOKEN_ADDRESS,
|
|
181
181
|
OPERATOR_ADDRESS,
|
|
182
|
-
undefined as
|
|
182
|
+
undefined as unknown as bigint,
|
|
183
183
|
)
|
|
184
184
|
|
|
185
185
|
const error = precondition.isValid()
|
|
@@ -224,7 +224,7 @@ describe('Preconditions Types', () => {
|
|
|
224
224
|
})
|
|
225
225
|
|
|
226
226
|
it('should validate tokenId is required', () => {
|
|
227
|
-
const precondition = new Erc721OwnershipPrecondition(TEST_ADDRESS, TOKEN_ADDRESS, undefined as
|
|
227
|
+
const precondition = new Erc721OwnershipPrecondition(TEST_ADDRESS, TOKEN_ADDRESS, undefined as unknown as bigint)
|
|
228
228
|
|
|
229
229
|
const error = precondition.isValid()
|
|
230
230
|
expect(error).toBeInstanceOf(Error)
|
|
@@ -271,7 +271,7 @@ describe('Preconditions Types', () => {
|
|
|
271
271
|
const precondition = new Erc721ApprovalPrecondition(
|
|
272
272
|
TEST_ADDRESS,
|
|
273
273
|
TOKEN_ADDRESS,
|
|
274
|
-
undefined as
|
|
274
|
+
undefined as unknown as bigint,
|
|
275
275
|
OPERATOR_ADDRESS,
|
|
276
276
|
)
|
|
277
277
|
|
|
@@ -319,7 +319,7 @@ describe('Preconditions Types', () => {
|
|
|
319
319
|
})
|
|
320
320
|
|
|
321
321
|
it('should validate tokenId is required', () => {
|
|
322
|
-
const precondition = new Erc1155BalancePrecondition(TEST_ADDRESS, TOKEN_ADDRESS, undefined as
|
|
322
|
+
const precondition = new Erc1155BalancePrecondition(TEST_ADDRESS, TOKEN_ADDRESS, undefined as unknown as bigint)
|
|
323
323
|
|
|
324
324
|
const error = precondition.isValid()
|
|
325
325
|
expect(error).toBeInstanceOf(Error)
|
|
@@ -402,7 +402,7 @@ describe('Preconditions Types', () => {
|
|
|
402
402
|
const precondition = new Erc1155ApprovalPrecondition(
|
|
403
403
|
TEST_ADDRESS,
|
|
404
404
|
TOKEN_ADDRESS,
|
|
405
|
-
undefined as
|
|
405
|
+
undefined as unknown as bigint,
|
|
406
406
|
OPERATOR_ADDRESS,
|
|
407
407
|
1000000n,
|
|
408
408
|
)
|
|
@@ -432,7 +432,7 @@ describe('Preconditions Types', () => {
|
|
|
432
432
|
TOKEN_ADDRESS,
|
|
433
433
|
123n,
|
|
434
434
|
OPERATOR_ADDRESS,
|
|
435
|
-
undefined as
|
|
435
|
+
undefined as unknown as bigint,
|
|
436
436
|
)
|
|
437
437
|
|
|
438
438
|
const error = precondition.isValid()
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it, vi, beforeEach } from 'vitest'
|
|
2
2
|
import { Address, Hex } from 'ox'
|
|
3
3
|
import { Network, Payload } from '@0xsequence/wallet-primitives'
|
|
4
|
-
import { Relayer,
|
|
4
|
+
import { Relayer, RpcRelayerGen } from '@0xsequence/relayer'
|
|
5
5
|
|
|
6
6
|
// Test addresses and data
|
|
7
7
|
const TEST_WALLET_ADDRESS = Address.from('0x1234567890123456789012345678901234567890')
|
|
@@ -127,7 +127,7 @@ describe('Relayer', () => {
|
|
|
127
127
|
symbol: 'ETH',
|
|
128
128
|
decimals: 18,
|
|
129
129
|
logoURL: 'https://example.com/eth.png',
|
|
130
|
-
type: 'NATIVE' as
|
|
130
|
+
type: 'NATIVE' as RpcRelayerGen.FeeTokenType,
|
|
131
131
|
contractAddress: undefined,
|
|
132
132
|
},
|
|
133
133
|
to: TEST_TO_ADDRESS,
|
|
@@ -310,7 +310,7 @@ describe('Relayer', () => {
|
|
|
310
310
|
const isAvailable = await mockRelayer.isAvailable(TEST_WALLET_ADDRESS, TEST_CHAIN_ID)
|
|
311
311
|
expect(isAvailable).toBe(true)
|
|
312
312
|
|
|
313
|
-
const feeOptions = await mockRelayer.feeOptions(TEST_WALLET_ADDRESS, TEST_CHAIN_ID, [])
|
|
313
|
+
const feeOptions = await mockRelayer.feeOptions(TEST_WALLET_ADDRESS, TEST_CHAIN_ID, TEST_TO_ADDRESS, [])
|
|
314
314
|
expect(feeOptions.options).toEqual([])
|
|
315
315
|
|
|
316
316
|
const relayResult = await mockRelayer.relay(TEST_TO_ADDRESS, TEST_DATA, TEST_CHAIN_ID)
|
|
@@ -319,7 +319,7 @@ describe('Relayer', () => {
|
|
|
319
319
|
const statusResult = await mockRelayer.status(TEST_OP_HASH, TEST_CHAIN_ID)
|
|
320
320
|
expect(statusResult.status).toBe('confirmed')
|
|
321
321
|
|
|
322
|
-
const preconditionResult = await mockRelayer.checkPrecondition({} as
|
|
322
|
+
const preconditionResult = await mockRelayer.checkPrecondition({} as { type: string })
|
|
323
323
|
expect(preconditionResult).toBe(true)
|
|
324
324
|
})
|
|
325
325
|
})
|