@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.
Files changed (83) hide show
  1. package/.turbo/turbo-build.log +5 -0
  2. package/CHANGELOG.md +3926 -0
  3. package/LICENSE +0 -17
  4. package/README.md +1 -2
  5. package/dist/index.d.ts +4 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +3 -0
  8. package/dist/preconditions/codec.d.ts +12 -0
  9. package/dist/preconditions/codec.d.ts.map +1 -0
  10. package/dist/preconditions/codec.js +125 -0
  11. package/dist/preconditions/index.d.ts +4 -0
  12. package/dist/preconditions/index.d.ts.map +1 -0
  13. package/dist/preconditions/index.js +3 -0
  14. package/dist/preconditions/selectors.d.ts +7 -0
  15. package/dist/preconditions/selectors.d.ts.map +1 -0
  16. package/dist/preconditions/selectors.js +27 -0
  17. package/dist/preconditions/types.d.ts +70 -0
  18. package/dist/preconditions/types.d.ts.map +1 -0
  19. package/dist/preconditions/types.js +203 -0
  20. package/dist/relayer/index.d.ts +45 -0
  21. package/dist/relayer/index.d.ts.map +1 -0
  22. package/dist/relayer/index.js +3 -0
  23. package/dist/relayer/relayer.d.ts +26 -0
  24. package/dist/relayer/relayer.d.ts.map +1 -0
  25. package/dist/relayer/relayer.js +7 -0
  26. package/dist/relayer/rpc-relayer/index.d.ts +38 -0
  27. package/dist/relayer/rpc-relayer/index.d.ts.map +1 -0
  28. package/dist/relayer/rpc-relayer/index.js +375 -0
  29. package/dist/{declarations/src → relayer}/rpc-relayer/relayer.gen.d.ts +3 -2
  30. package/dist/relayer/rpc-relayer/relayer.gen.d.ts.map +1 -0
  31. package/dist/relayer/rpc-relayer/relayer.gen.js +1246 -0
  32. package/dist/relayer/standard/abi.d.ts +73 -0
  33. package/dist/relayer/standard/abi.d.ts.map +1 -0
  34. package/dist/relayer/standard/abi.js +10 -0
  35. package/dist/relayer/standard/eip6963.d.ts +31 -0
  36. package/dist/relayer/standard/eip6963.d.ts.map +1 -0
  37. package/dist/relayer/standard/eip6963.js +51 -0
  38. package/dist/relayer/standard/index.d.ts +5 -0
  39. package/dist/relayer/standard/index.d.ts.map +1 -0
  40. package/dist/relayer/standard/index.js +4 -0
  41. package/dist/relayer/standard/local.d.ts +60 -0
  42. package/dist/relayer/standard/local.d.ts.map +1 -0
  43. package/dist/relayer/standard/local.js +285 -0
  44. package/dist/relayer/standard/pk-relayer.d.ts +28 -0
  45. package/dist/relayer/standard/pk-relayer.d.ts.map +1 -0
  46. package/dist/relayer/standard/pk-relayer.js +112 -0
  47. package/dist/relayer/standard/sequence.d.ts +27 -0
  48. package/dist/relayer/standard/sequence.d.ts.map +1 -0
  49. package/dist/relayer/standard/sequence.js +84 -0
  50. package/package.json +28 -25
  51. package/src/index.ts +3 -111
  52. package/src/preconditions/codec.ts +190 -0
  53. package/src/preconditions/index.ts +3 -0
  54. package/src/preconditions/selectors.ts +38 -0
  55. package/src/preconditions/types.ts +201 -0
  56. package/src/relayer/index.ts +60 -0
  57. package/src/relayer/relayer.ts +37 -0
  58. package/src/relayer/rpc-relayer/index.ts +449 -0
  59. package/src/{rpc-relayer → relayer/rpc-relayer}/relayer.gen.ts +483 -258
  60. package/src/relayer/standard/abi.ts +13 -0
  61. package/src/relayer/standard/eip6963.ts +74 -0
  62. package/src/relayer/standard/index.ts +4 -0
  63. package/src/relayer/standard/local.ts +353 -0
  64. package/src/relayer/standard/pk-relayer.ts +138 -0
  65. package/src/relayer/standard/sequence.ts +110 -0
  66. package/test/preconditions/codec.test.ts +531 -0
  67. package/test/preconditions/preconditions.test.ts +283 -0
  68. package/test/preconditions/selectors.test.ts +415 -0
  69. package/test/preconditions/types.test.ts +443 -0
  70. package/test/relayer/relayer.test.ts +355 -0
  71. package/tsconfig.json +10 -0
  72. package/dist/0xsequence-relayer.cjs.d.ts +0 -2
  73. package/dist/0xsequence-relayer.cjs.dev.js +0 -1865
  74. package/dist/0xsequence-relayer.cjs.js +0 -7
  75. package/dist/0xsequence-relayer.cjs.prod.js +0 -1865
  76. package/dist/0xsequence-relayer.esm.js +0 -1852
  77. package/dist/declarations/src/index.d.ts +0 -42
  78. package/dist/declarations/src/local-relayer.d.ts +0 -35
  79. package/dist/declarations/src/provider-relayer.d.ts +0 -47
  80. package/dist/declarations/src/rpc-relayer/index.d.ts +0 -72
  81. package/src/local-relayer.ts +0 -125
  82. package/src/provider-relayer.ts +0 -284
  83. 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
+ }