@0xsequence/relayer 2.3.39 → 3.0.0-beta.10
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 +5 -0
- package/CHANGELOG.md +3926 -0
- package/LICENSE +0 -17
- package/README.md +1 -2
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/preconditions/codec.d.ts +12 -0
- package/dist/preconditions/codec.d.ts.map +1 -0
- package/dist/preconditions/codec.js +125 -0
- package/dist/preconditions/index.d.ts +4 -0
- package/dist/preconditions/index.d.ts.map +1 -0
- package/dist/preconditions/index.js +3 -0
- package/dist/preconditions/selectors.d.ts +7 -0
- package/dist/preconditions/selectors.d.ts.map +1 -0
- package/dist/preconditions/selectors.js +27 -0
- package/dist/preconditions/types.d.ts +70 -0
- package/dist/preconditions/types.d.ts.map +1 -0
- package/dist/preconditions/types.js +203 -0
- package/dist/relayer/index.d.ts +45 -0
- package/dist/relayer/index.d.ts.map +1 -0
- package/dist/relayer/index.js +3 -0
- package/dist/relayer/relayer.d.ts +26 -0
- package/dist/relayer/relayer.d.ts.map +1 -0
- package/dist/relayer/relayer.js +7 -0
- package/dist/relayer/rpc-relayer/index.d.ts +38 -0
- package/dist/relayer/rpc-relayer/index.d.ts.map +1 -0
- package/dist/relayer/rpc-relayer/index.js +375 -0
- package/dist/{declarations/src → relayer}/rpc-relayer/relayer.gen.d.ts +3 -2
- package/dist/relayer/rpc-relayer/relayer.gen.d.ts.map +1 -0
- package/dist/relayer/rpc-relayer/relayer.gen.js +1246 -0
- package/dist/relayer/standard/abi.d.ts +73 -0
- package/dist/relayer/standard/abi.d.ts.map +1 -0
- package/dist/relayer/standard/abi.js +10 -0
- package/dist/relayer/standard/eip6963.d.ts +31 -0
- package/dist/relayer/standard/eip6963.d.ts.map +1 -0
- package/dist/relayer/standard/eip6963.js +51 -0
- package/dist/relayer/standard/index.d.ts +5 -0
- package/dist/relayer/standard/index.d.ts.map +1 -0
- package/dist/relayer/standard/index.js +4 -0
- package/dist/relayer/standard/local.d.ts +60 -0
- package/dist/relayer/standard/local.d.ts.map +1 -0
- package/dist/relayer/standard/local.js +285 -0
- package/dist/relayer/standard/pk-relayer.d.ts +28 -0
- package/dist/relayer/standard/pk-relayer.d.ts.map +1 -0
- package/dist/relayer/standard/pk-relayer.js +112 -0
- package/dist/relayer/standard/sequence.d.ts +27 -0
- package/dist/relayer/standard/sequence.d.ts.map +1 -0
- package/dist/relayer/standard/sequence.js +84 -0
- package/package.json +28 -25
- package/src/index.ts +3 -111
- package/src/preconditions/codec.ts +190 -0
- package/src/preconditions/index.ts +3 -0
- package/src/preconditions/selectors.ts +38 -0
- package/src/preconditions/types.ts +201 -0
- package/src/relayer/index.ts +60 -0
- package/src/relayer/relayer.ts +37 -0
- package/src/relayer/rpc-relayer/index.ts +449 -0
- package/src/{rpc-relayer → relayer/rpc-relayer}/relayer.gen.ts +483 -258
- package/src/relayer/standard/abi.ts +13 -0
- package/src/relayer/standard/eip6963.ts +74 -0
- package/src/relayer/standard/index.ts +4 -0
- package/src/relayer/standard/local.ts +353 -0
- package/src/relayer/standard/pk-relayer.ts +138 -0
- package/src/relayer/standard/sequence.ts +110 -0
- package/test/preconditions/codec.test.ts +531 -0
- package/test/preconditions/preconditions.test.ts +283 -0
- package/test/preconditions/selectors.test.ts +415 -0
- package/test/preconditions/types.test.ts +443 -0
- package/test/relayer/relayer.test.ts +355 -0
- package/tsconfig.json +10 -0
- package/dist/0xsequence-relayer.cjs.d.ts +0 -2
- package/dist/0xsequence-relayer.cjs.dev.js +0 -1865
- package/dist/0xsequence-relayer.cjs.js +0 -7
- package/dist/0xsequence-relayer.cjs.prod.js +0 -1865
- package/dist/0xsequence-relayer.esm.js +0 -1852
- package/dist/declarations/src/index.d.ts +0 -42
- package/dist/declarations/src/local-relayer.d.ts +0 -35
- package/dist/declarations/src/provider-relayer.d.ts +0 -47
- package/dist/declarations/src/rpc-relayer/index.d.ts +0 -72
- package/src/local-relayer.ts +0 -125
- package/src/provider-relayer.ts +0 -284
- package/src/rpc-relayer/index.ts +0 -380
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { Address } from 'ox'
|
|
2
|
+
|
|
3
|
+
export interface Precondition {
|
|
4
|
+
type(): string
|
|
5
|
+
isValid(): Error | undefined
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class NativeBalancePrecondition implements Precondition {
|
|
9
|
+
constructor(
|
|
10
|
+
public readonly address: Address.Address,
|
|
11
|
+
public readonly min?: bigint,
|
|
12
|
+
public readonly max?: bigint,
|
|
13
|
+
) {}
|
|
14
|
+
|
|
15
|
+
type(): string {
|
|
16
|
+
return 'native-balance'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
isValid(): Error | undefined {
|
|
20
|
+
if (!this.address) {
|
|
21
|
+
return new Error('address is required')
|
|
22
|
+
}
|
|
23
|
+
if (this.min !== undefined && this.max !== undefined && this.min > this.max) {
|
|
24
|
+
return new Error('min balance cannot be greater than max balance')
|
|
25
|
+
}
|
|
26
|
+
return undefined
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class Erc20BalancePrecondition implements Precondition {
|
|
31
|
+
constructor(
|
|
32
|
+
public readonly address: Address.Address,
|
|
33
|
+
public readonly token: Address.Address,
|
|
34
|
+
public readonly min?: bigint,
|
|
35
|
+
public readonly max?: bigint,
|
|
36
|
+
) {}
|
|
37
|
+
|
|
38
|
+
type(): string {
|
|
39
|
+
return 'erc20-balance'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
isValid(): Error | undefined {
|
|
43
|
+
if (!this.address) {
|
|
44
|
+
return new Error('address is required')
|
|
45
|
+
}
|
|
46
|
+
if (!this.token) {
|
|
47
|
+
return new Error('token address is required')
|
|
48
|
+
}
|
|
49
|
+
if (this.min !== undefined && this.max !== undefined && this.min > this.max) {
|
|
50
|
+
return new Error('min balance cannot be greater than max balance')
|
|
51
|
+
}
|
|
52
|
+
return undefined
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export class Erc20ApprovalPrecondition implements Precondition {
|
|
57
|
+
constructor(
|
|
58
|
+
public readonly address: Address.Address,
|
|
59
|
+
public readonly token: Address.Address,
|
|
60
|
+
public readonly operator: Address.Address,
|
|
61
|
+
public readonly min: bigint,
|
|
62
|
+
) {}
|
|
63
|
+
|
|
64
|
+
type(): string {
|
|
65
|
+
return 'erc20-approval'
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
isValid(): Error | undefined {
|
|
69
|
+
if (!this.address) {
|
|
70
|
+
return new Error('address is required')
|
|
71
|
+
}
|
|
72
|
+
if (!this.token) {
|
|
73
|
+
return new Error('token address is required')
|
|
74
|
+
}
|
|
75
|
+
if (!this.operator) {
|
|
76
|
+
return new Error('operator address is required')
|
|
77
|
+
}
|
|
78
|
+
if (this.min === undefined) {
|
|
79
|
+
return new Error('min approval amount is required')
|
|
80
|
+
}
|
|
81
|
+
return undefined
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export class Erc721OwnershipPrecondition implements Precondition {
|
|
86
|
+
constructor(
|
|
87
|
+
public readonly address: Address.Address,
|
|
88
|
+
public readonly token: Address.Address,
|
|
89
|
+
public readonly tokenId: bigint,
|
|
90
|
+
public readonly owned?: boolean,
|
|
91
|
+
) {}
|
|
92
|
+
|
|
93
|
+
type(): string {
|
|
94
|
+
return 'erc721-ownership'
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
isValid(): Error | undefined {
|
|
98
|
+
if (!this.address) {
|
|
99
|
+
return new Error('address is required')
|
|
100
|
+
}
|
|
101
|
+
if (!this.token) {
|
|
102
|
+
return new Error('token address is required')
|
|
103
|
+
}
|
|
104
|
+
if (this.tokenId === undefined) {
|
|
105
|
+
return new Error('tokenId is required')
|
|
106
|
+
}
|
|
107
|
+
return undefined
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export class Erc721ApprovalPrecondition implements Precondition {
|
|
112
|
+
constructor(
|
|
113
|
+
public readonly address: Address.Address,
|
|
114
|
+
public readonly token: Address.Address,
|
|
115
|
+
public readonly tokenId: bigint,
|
|
116
|
+
public readonly operator: Address.Address,
|
|
117
|
+
) {}
|
|
118
|
+
|
|
119
|
+
type(): string {
|
|
120
|
+
return 'erc721-approval'
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
isValid(): Error | undefined {
|
|
124
|
+
if (!this.address) {
|
|
125
|
+
return new Error('address is required')
|
|
126
|
+
}
|
|
127
|
+
if (!this.token) {
|
|
128
|
+
return new Error('token address is required')
|
|
129
|
+
}
|
|
130
|
+
if (this.tokenId === undefined) {
|
|
131
|
+
return new Error('tokenId is required')
|
|
132
|
+
}
|
|
133
|
+
if (!this.operator) {
|
|
134
|
+
return new Error('operator address is required')
|
|
135
|
+
}
|
|
136
|
+
return undefined
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export class Erc1155BalancePrecondition implements Precondition {
|
|
141
|
+
constructor(
|
|
142
|
+
public readonly address: Address.Address,
|
|
143
|
+
public readonly token: Address.Address,
|
|
144
|
+
public readonly tokenId: bigint,
|
|
145
|
+
public readonly min?: bigint,
|
|
146
|
+
public readonly max?: bigint,
|
|
147
|
+
) {}
|
|
148
|
+
|
|
149
|
+
type(): string {
|
|
150
|
+
return 'erc1155-balance'
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
isValid(): Error | undefined {
|
|
154
|
+
if (!this.address) {
|
|
155
|
+
return new Error('address is required')
|
|
156
|
+
}
|
|
157
|
+
if (!this.token) {
|
|
158
|
+
return new Error('token address is required')
|
|
159
|
+
}
|
|
160
|
+
if (this.tokenId === undefined) {
|
|
161
|
+
return new Error('tokenId is required')
|
|
162
|
+
}
|
|
163
|
+
if (this.min !== undefined && this.max !== undefined && this.min > this.max) {
|
|
164
|
+
return new Error('min balance cannot be greater than max balance')
|
|
165
|
+
}
|
|
166
|
+
return undefined
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export class Erc1155ApprovalPrecondition implements Precondition {
|
|
171
|
+
constructor(
|
|
172
|
+
public readonly address: Address.Address,
|
|
173
|
+
public readonly token: Address.Address,
|
|
174
|
+
public readonly tokenId: bigint,
|
|
175
|
+
public readonly operator: Address.Address,
|
|
176
|
+
public readonly min: bigint,
|
|
177
|
+
) {}
|
|
178
|
+
|
|
179
|
+
type(): string {
|
|
180
|
+
return 'erc1155-approval'
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
isValid(): Error | undefined {
|
|
184
|
+
if (!this.address) {
|
|
185
|
+
return new Error('address is required')
|
|
186
|
+
}
|
|
187
|
+
if (!this.token) {
|
|
188
|
+
return new Error('token address is required')
|
|
189
|
+
}
|
|
190
|
+
if (this.tokenId === undefined) {
|
|
191
|
+
return new Error('tokenId is required')
|
|
192
|
+
}
|
|
193
|
+
if (!this.operator) {
|
|
194
|
+
return new Error('operator address is required')
|
|
195
|
+
}
|
|
196
|
+
if (this.min === undefined) {
|
|
197
|
+
return new Error('min approval amount is required')
|
|
198
|
+
}
|
|
199
|
+
return undefined
|
|
200
|
+
}
|
|
201
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Hex } from 'ox'
|
|
2
|
+
import type { FeeToken, GetMetaTxnReceiptReturn } from './rpc-relayer/relayer.gen.js'
|
|
3
|
+
|
|
4
|
+
export * from './rpc-relayer/index.js'
|
|
5
|
+
export * from './standard/index.js'
|
|
6
|
+
export * from './relayer.js'
|
|
7
|
+
export type { FeeToken } from './rpc-relayer/relayer.gen.js'
|
|
8
|
+
|
|
9
|
+
export interface FeeOption {
|
|
10
|
+
token: FeeToken
|
|
11
|
+
to: string
|
|
12
|
+
value: string
|
|
13
|
+
gasLimit: number
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface FeeQuote {
|
|
17
|
+
_tag: 'FeeQuote'
|
|
18
|
+
_quote: unknown
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type OperationUnknownStatus = {
|
|
22
|
+
status: 'unknown'
|
|
23
|
+
reason?: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type OperationQueuedStatus = {
|
|
27
|
+
status: 'queued'
|
|
28
|
+
reason?: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type OperationPendingStatus = {
|
|
32
|
+
status: 'pending'
|
|
33
|
+
reason?: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type OperationPendingPreconditionStatus = {
|
|
37
|
+
status: 'pending-precondition'
|
|
38
|
+
reason?: string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type OperationConfirmedStatus = {
|
|
42
|
+
status: 'confirmed'
|
|
43
|
+
transactionHash: Hex.Hex
|
|
44
|
+
data?: GetMetaTxnReceiptReturn
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type OperationFailedStatus = {
|
|
48
|
+
status: 'failed'
|
|
49
|
+
transactionHash?: Hex.Hex
|
|
50
|
+
reason: string
|
|
51
|
+
data?: GetMetaTxnReceiptReturn
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type OperationStatus =
|
|
55
|
+
| OperationUnknownStatus
|
|
56
|
+
| OperationQueuedStatus
|
|
57
|
+
| OperationPendingStatus
|
|
58
|
+
| OperationPendingPreconditionStatus
|
|
59
|
+
| OperationConfirmedStatus
|
|
60
|
+
| OperationFailedStatus
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Address, Hex } from 'ox'
|
|
2
|
+
import { FeeToken } from './rpc-relayer/relayer.gen.js'
|
|
3
|
+
import { FeeOption, FeeQuote, OperationStatus } from './index.js'
|
|
4
|
+
import { Payload, Precondition } from '@0xsequence/wallet-primitives'
|
|
5
|
+
|
|
6
|
+
export interface Relayer {
|
|
7
|
+
kind: 'relayer'
|
|
8
|
+
|
|
9
|
+
type: string
|
|
10
|
+
id: string
|
|
11
|
+
|
|
12
|
+
isAvailable(wallet: Address.Address, chainId: number): Promise<boolean>
|
|
13
|
+
|
|
14
|
+
feeTokens(): Promise<{ isFeeRequired: boolean; tokens?: FeeToken[]; paymentAddress?: Address.Address }>
|
|
15
|
+
|
|
16
|
+
feeOptions(
|
|
17
|
+
wallet: Address.Address,
|
|
18
|
+
chainId: number,
|
|
19
|
+
calls: Payload.Call[],
|
|
20
|
+
): Promise<{ options: FeeOption[]; quote?: FeeQuote }>
|
|
21
|
+
|
|
22
|
+
relay(to: Address.Address, data: Hex.Hex, chainId: number, quote?: FeeQuote): Promise<{ opHash: Hex.Hex }>
|
|
23
|
+
|
|
24
|
+
status(opHash: Hex.Hex, chainId: number): Promise<OperationStatus>
|
|
25
|
+
|
|
26
|
+
checkPrecondition(precondition: Precondition.Precondition): Promise<boolean>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function isRelayer(relayer: any): relayer is Relayer {
|
|
30
|
+
return (
|
|
31
|
+
'isAvailable' in relayer &&
|
|
32
|
+
'feeOptions' in relayer &&
|
|
33
|
+
'relay' in relayer &&
|
|
34
|
+
'status' in relayer &&
|
|
35
|
+
'checkPrecondition' in relayer
|
|
36
|
+
)
|
|
37
|
+
}
|