@layerzerolabs/gated-transaction 0.2.67 → 0.2.69
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/dist/{S7M4M3JS.js → AOTJAUDZ.js} +2 -2
- package/dist/AOTJAUDZ.js.map +1 -0
- package/dist/{VO5L7KKO.js → BXCZCZON.js} +9 -9
- package/dist/BXCZCZON.js.map +1 -0
- package/dist/{VE67DSPF.cjs → DOFQC7XF.cjs} +2 -2
- package/dist/DOFQC7XF.cjs.map +1 -0
- package/dist/{64Q22BPU.cjs → UHB3BVRF.cjs} +9 -9
- package/dist/UHB3BVRF.cjs.map +1 -0
- package/dist/gatedTx.cjs +5 -5
- package/dist/gatedTx.d.ts +8 -22
- package/dist/gatedTx.d.ts.map +1 -1
- package/dist/gatedTx.js +1 -1
- package/dist/index.cjs +19 -19
- package/dist/index.js +2 -2
- package/dist/schemata.cjs +14 -14
- package/dist/schemata.d.ts +40 -53
- package/dist/schemata.d.ts.map +1 -1
- package/dist/schemata.js +1 -1
- package/package.json +11 -8
- package/.turbo/turbo-build.log +0 -39
- package/.turbo/turbo-lint.log +0 -8
- package/.turbo/turbo-test.log +0 -16
- package/dist/64Q22BPU.cjs.map +0 -1
- package/dist/S7M4M3JS.js.map +0 -1
- package/dist/VE67DSPF.cjs.map +0 -1
- package/dist/VO5L7KKO.js.map +0 -1
- package/src/gatedTx.ts +0 -135
- package/src/index.ts +0 -2
- package/src/schemata.ts +0 -471
- package/tsconfig.json +0 -20
- package/tsup.config.ts +0 -8
package/src/gatedTx.ts
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import type { Transaction, TransactionWithResult } from '@layerzerolabs/common-chain-model';
|
|
2
|
-
import type { FunctionPointer } from '@layerzerolabs/function-pointer';
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
BaseGatedTransaction,
|
|
6
|
-
ContractArtifactPointers,
|
|
7
|
-
FunctionalGatedTransaction,
|
|
8
|
-
GatedTransactionBundleId,
|
|
9
|
-
GatedTransactionDependencies,
|
|
10
|
-
GatedTransactionId,
|
|
11
|
-
LiteralGatedTransaction,
|
|
12
|
-
OnChainDataComparison,
|
|
13
|
-
ResolvedGatedTransaction,
|
|
14
|
-
} from './schemata';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Builds a {@link GatedTransaction}
|
|
18
|
-
*/
|
|
19
|
-
export const constructGatedTransaction = <
|
|
20
|
-
const Name extends string,
|
|
21
|
-
TxType extends Transaction,
|
|
22
|
-
CheckOutput extends Promise<any>,
|
|
23
|
-
_Dependencies extends GatedTransactionDependencies,
|
|
24
|
-
>(gtx: {
|
|
25
|
-
name: Name;
|
|
26
|
-
description?: string;
|
|
27
|
-
chainName: string;
|
|
28
|
-
bundleName?: string;
|
|
29
|
-
metadata?: {
|
|
30
|
-
deployInfo?: {
|
|
31
|
-
contracts: { [contractName: string]: ContractArtifactPointers };
|
|
32
|
-
alwaysResolve?: boolean;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
check: {
|
|
36
|
-
functionPointer: FunctionPointer<[tx?: TransactionWithResult], CheckOutput>;
|
|
37
|
-
expectedResult: OnChainDataComparison<Awaited<CheckOutput>>;
|
|
38
|
-
};
|
|
39
|
-
uniqueIdKeys?: Record<string, string | number | boolean>;
|
|
40
|
-
cacheable?: boolean;
|
|
41
|
-
dependencies?: _Dependencies;
|
|
42
|
-
orderingDependencies?: GatedTransactionDependencies;
|
|
43
|
-
transaction: TxType;
|
|
44
|
-
}): LiteralGatedTransaction<Name, TxType, CheckOutput, _Dependencies> => {
|
|
45
|
-
const dependencies = gtx.dependencies ?? ([] as any);
|
|
46
|
-
return { ...gtx, transactionType: 'literal', dependencies };
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
type BuildDeps<Params extends ResolvedGatedTransaction[]> = Params extends []
|
|
50
|
-
? []
|
|
51
|
-
: Params extends readonly [
|
|
52
|
-
ResolvedGatedTransaction<infer Gtx>,
|
|
53
|
-
...infer Rest extends ResolvedGatedTransaction[],
|
|
54
|
-
]
|
|
55
|
-
? [Gtx, ...BuildDeps<[...Rest]>]
|
|
56
|
-
: Params extends Array<ResolvedGatedTransaction<infer Gtx>>
|
|
57
|
-
? Array<Gtx>
|
|
58
|
-
: never;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Builds a {@link GatedTransaction} from a pointer
|
|
62
|
-
*/
|
|
63
|
-
export const constructGatedTransactionFromPointer = <
|
|
64
|
-
const Name extends string,
|
|
65
|
-
TxType extends Transaction,
|
|
66
|
-
CheckOutput extends Promise<any>,
|
|
67
|
-
DepInput extends [...args: any[], txes: any],
|
|
68
|
-
>(gtx: {
|
|
69
|
-
name: Name;
|
|
70
|
-
description?: string;
|
|
71
|
-
chainName: string;
|
|
72
|
-
bundleName?: string;
|
|
73
|
-
metadata?: {
|
|
74
|
-
deployInfo?: {
|
|
75
|
-
contracts: { [contractName: string]: ContractArtifactPointers };
|
|
76
|
-
alwaysResolve?: boolean;
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
check: {
|
|
80
|
-
functionPointer: FunctionPointer<[tx?: TransactionWithResult], CheckOutput>;
|
|
81
|
-
expectedResult: OnChainDataComparison<Awaited<CheckOutput>>;
|
|
82
|
-
};
|
|
83
|
-
uniqueIdKeys?: Record<string, string | number | boolean>;
|
|
84
|
-
cacheable?: boolean;
|
|
85
|
-
dependencies: BuildDeps<
|
|
86
|
-
DepInput extends [...any, infer Tail extends readonly ResolvedGatedTransaction[]]
|
|
87
|
-
? Tail
|
|
88
|
-
: DepInput extends [...infer Tail extends readonly ResolvedGatedTransaction[]]
|
|
89
|
-
? Tail
|
|
90
|
-
: never
|
|
91
|
-
>;
|
|
92
|
-
orderingDependencies?: GatedTransactionDependencies;
|
|
93
|
-
getTransaction: {
|
|
94
|
-
functionPointer: FunctionPointer<DepInput, Promise<TxType>>;
|
|
95
|
-
};
|
|
96
|
-
}): FunctionalGatedTransaction<
|
|
97
|
-
Name,
|
|
98
|
-
TxType,
|
|
99
|
-
CheckOutput,
|
|
100
|
-
DepInput,
|
|
101
|
-
BuildDeps<
|
|
102
|
-
DepInput extends [...any, infer Tail extends readonly ResolvedGatedTransaction[]]
|
|
103
|
-
? Tail
|
|
104
|
-
: DepInput extends [...infer Tail extends readonly ResolvedGatedTransaction[]]
|
|
105
|
-
? Tail
|
|
106
|
-
: never
|
|
107
|
-
>
|
|
108
|
-
> => {
|
|
109
|
-
return {
|
|
110
|
-
...gtx,
|
|
111
|
-
transactionType: 'functional',
|
|
112
|
-
};
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
export const getIdForGatedTransaction = (gtx: BaseGatedTransaction): GatedTransactionId => {
|
|
116
|
-
const serializedUniqueIdKeys = gtx.uniqueIdKeys
|
|
117
|
-
? Object.entries(gtx.uniqueIdKeys)
|
|
118
|
-
.map(([k, v]) => `${k}:${v}`)
|
|
119
|
-
.join('-')
|
|
120
|
-
: '';
|
|
121
|
-
|
|
122
|
-
return `${gtx.name}-${gtx.chainName}-${serializedUniqueIdKeys}`;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
export const getBundleIdForGatedTransaction = (
|
|
126
|
-
gtx: BaseGatedTransaction,
|
|
127
|
-
): GatedTransactionBundleId => {
|
|
128
|
-
const serializedUniqueIdKeys = gtx.uniqueIdKeys
|
|
129
|
-
? Object.entries(gtx.uniqueIdKeys)
|
|
130
|
-
.map(([k, v]) => `${k}:${v}`)
|
|
131
|
-
.join('-')
|
|
132
|
-
: '';
|
|
133
|
-
|
|
134
|
-
return `${gtx.bundleName}-${gtx.chainName}-${serializedUniqueIdKeys}`;
|
|
135
|
-
};
|
package/src/index.ts
DELETED
package/src/schemata.ts
DELETED
|
@@ -1,471 +0,0 @@
|
|
|
1
|
-
import z from 'zod';
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
transactionSchema as _transactionSchema,
|
|
5
|
-
TransactionWithResult,
|
|
6
|
-
} from '@layerzerolabs/common-chain-model';
|
|
7
|
-
import {
|
|
8
|
-
type Transaction,
|
|
9
|
-
type TransactionWithResultFor,
|
|
10
|
-
transactionWithResultSchema as _transactionWithResultSchema,
|
|
11
|
-
} from '@layerzerolabs/common-chain-model';
|
|
12
|
-
import type { FunctionPointer } from '@layerzerolabs/function-pointer';
|
|
13
|
-
import type {
|
|
14
|
-
BrandedError,
|
|
15
|
-
BuildTuple,
|
|
16
|
-
DecimalString,
|
|
17
|
-
IsAny,
|
|
18
|
-
Or,
|
|
19
|
-
} from '@layerzerolabs/typescript-utils';
|
|
20
|
-
import type { InferredArray } from '@layerzerolabs/zod-utils';
|
|
21
|
-
import { customSchema, functionSchema } from '@layerzerolabs/zod-utils';
|
|
22
|
-
|
|
23
|
-
export type OnChainDataComparisonOperator<OnChainDataType> =
|
|
24
|
-
Or<
|
|
25
|
-
[OnChainDataType extends number | DecimalString ? true : false, IsAny<OnChainDataType>]
|
|
26
|
-
> extends true
|
|
27
|
-
? '<' | '<=' | '=' | '!=' | '>' | '>='
|
|
28
|
-
: OnChainDataType extends string | object | boolean
|
|
29
|
-
? '=' | '!='
|
|
30
|
-
: BrandedError<'Unsupported comparison type'>;
|
|
31
|
-
|
|
32
|
-
export type OnChainDataComparison<OnChainDataType extends string | number | boolean | object> = {
|
|
33
|
-
operator: OnChainDataComparisonOperator<OnChainDataType>;
|
|
34
|
-
comparisonValue: OnChainDataType;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export type GatedTransactionCheck<CheckOutput extends Promise<any> = Promise<any>> = {
|
|
38
|
-
functionPointer: FunctionPointer<[tx?: TransactionWithResult], CheckOutput>;
|
|
39
|
-
expectedResult: OnChainDataComparison<Awaited<CheckOutput>>;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
// Schema for gated transaction results
|
|
43
|
-
export const gatedTransactionResultSchema = <
|
|
44
|
-
TxWithResultSchema extends typeof _transactionWithResultSchema,
|
|
45
|
-
OnchainDataSchema extends z.ZodType,
|
|
46
|
-
>(
|
|
47
|
-
txWithResultSchema: TxWithResultSchema,
|
|
48
|
-
onchainDataSchema: OnchainDataSchema,
|
|
49
|
-
) =>
|
|
50
|
-
// TODO: use this schema as source of truth for GatedTransactionResult type
|
|
51
|
-
z.union([
|
|
52
|
-
z.object({
|
|
53
|
-
status: z.literal(GatedTransactionStatus.NO_OP),
|
|
54
|
-
}),
|
|
55
|
-
z.object({
|
|
56
|
-
status: z.literal(GatedTransactionStatus.SUCCESS),
|
|
57
|
-
submittedTransaction: txWithResultSchema,
|
|
58
|
-
}),
|
|
59
|
-
z.object({
|
|
60
|
-
status: z.literal(GatedTransactionStatus.TRANSACTION_FAILED),
|
|
61
|
-
transactionError: z.any(),
|
|
62
|
-
}),
|
|
63
|
-
z.object({
|
|
64
|
-
status: z.literal(GatedTransactionStatus.FINAL_CHECK_FAILED),
|
|
65
|
-
submittedTransaction: txWithResultSchema,
|
|
66
|
-
finalOnChainState: onchainDataSchema,
|
|
67
|
-
}),
|
|
68
|
-
z.object({
|
|
69
|
-
status: z.literal(GatedTransactionStatus.DEPENDENCY_FAILED),
|
|
70
|
-
}),
|
|
71
|
-
z.object({
|
|
72
|
-
status: z.literal(GatedTransactionStatus.DENIED),
|
|
73
|
-
}),
|
|
74
|
-
z.object({
|
|
75
|
-
status: z.literal(GatedTransactionStatus.DEFERRED_SUCCESS),
|
|
76
|
-
}),
|
|
77
|
-
]);
|
|
78
|
-
|
|
79
|
-
export type InferOnChainDataTypeFromCheck<Check> = Check extends (...args: any[]) => infer Ret
|
|
80
|
-
? Awaited<Ret>
|
|
81
|
-
: unknown;
|
|
82
|
-
export type InferOnChainDataTypeFromGatedTransaction<GatedTx extends GatedTransaction> =
|
|
83
|
-
InferOnChainDataTypeFromCheck<GatedTx['check']>;
|
|
84
|
-
|
|
85
|
-
export type GatedTransactionDependencies = GatedTransaction[];
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Pointer configuration for extracting a deployment artifact from a resolved GTX.
|
|
89
|
-
* - FunctionPointer: Custom pointer to activity factory function
|
|
90
|
-
* - 'DEFAULT': Use the default deployment activity factory function
|
|
91
|
-
* - null: Don't save this artifact
|
|
92
|
-
*/
|
|
93
|
-
export type DeploymentArtifactPointer = FunctionPointer | 'DEFAULT' | null;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Pointer configuration for extracting a verification artifact from a resolved GTX.
|
|
97
|
-
* - FunctionPointer: Custom pointer to activity factory function
|
|
98
|
-
* - null: Don't save this artifact
|
|
99
|
-
* Note: No 'DEFAULT' option - verification requires custom implementation per contract type.
|
|
100
|
-
*/
|
|
101
|
-
export type VerificationArtifactPointer = FunctionPointer | null;
|
|
102
|
-
|
|
103
|
-
// TODO: type FunctionPointer generics on DeploymentArtifactPointer/VerificationArtifactPointer (at least output types), consider converting ContractArtifactPointers to interface
|
|
104
|
-
export type ContractArtifactPointers = {
|
|
105
|
-
extractDeploymentArtifactPointer: DeploymentArtifactPointer;
|
|
106
|
-
extractVerificationArtifactPointer: VerificationArtifactPointer;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
export type BaseGatedTransaction<
|
|
110
|
-
Name extends string = string,
|
|
111
|
-
CheckOutput extends Promise<any> = Promise<any>,
|
|
112
|
-
_Dependencies extends GatedTransactionDependencies = GatedTransactionDependencies,
|
|
113
|
-
> = {
|
|
114
|
-
name: Name;
|
|
115
|
-
description?: string;
|
|
116
|
-
bundleName?: string;
|
|
117
|
-
metadata?: {
|
|
118
|
-
deployInfo?: {
|
|
119
|
-
contracts: { [contractName: string]: ContractArtifactPointers };
|
|
120
|
-
alwaysResolve?: boolean;
|
|
121
|
-
};
|
|
122
|
-
};
|
|
123
|
-
chainName: string;
|
|
124
|
-
check: GatedTransactionCheck<CheckOutput>;
|
|
125
|
-
dependencies: _Dependencies;
|
|
126
|
-
/**
|
|
127
|
-
* Ordering-only dependencies: this transaction must be executed after these transactions,
|
|
128
|
-
* but does not require their resolved output. If a transaction appears in both
|
|
129
|
-
* `dependencies` and `orderingDependencies`, the regular dependency semantics take precedence.
|
|
130
|
-
*/
|
|
131
|
-
orderingDependencies?: GatedTransactionDependencies;
|
|
132
|
-
cacheable?: boolean;
|
|
133
|
-
uniqueIdKeys?: Record<string, string | number | boolean>;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
export type LiteralGatedTransaction<
|
|
137
|
-
Name extends string = string,
|
|
138
|
-
TxType extends Transaction = Transaction,
|
|
139
|
-
CheckOutput extends Promise<any> = Promise<any>,
|
|
140
|
-
_Dependencies extends GatedTransactionDependencies = GatedTransactionDependencies,
|
|
141
|
-
> = BaseGatedTransaction<Name, CheckOutput, _Dependencies> & {
|
|
142
|
-
transactionType: 'literal';
|
|
143
|
-
transaction: TxType;
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
export type FunctionalGatedTransaction<
|
|
147
|
-
Name extends string = string,
|
|
148
|
-
TxType extends Transaction = Transaction,
|
|
149
|
-
CheckOutput extends Promise<any> = Promise<any>,
|
|
150
|
-
DepInput extends [...args: any[], txes: any] = [txes: any],
|
|
151
|
-
_Dependencies extends GatedTransactionDependencies = GatedTransactionDependencies,
|
|
152
|
-
> = BaseGatedTransaction<Name, CheckOutput, _Dependencies> & {
|
|
153
|
-
transactionType: 'functional';
|
|
154
|
-
getTransaction: {
|
|
155
|
-
functionPointer: FunctionPointer<DepInput, Promise<TxType>>;
|
|
156
|
-
};
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
export type GatedTransaction<
|
|
160
|
-
Name extends string = string,
|
|
161
|
-
TxType extends Transaction = Transaction,
|
|
162
|
-
CheckOutput extends Promise<any> = Promise<any>,
|
|
163
|
-
DepInput extends [...args: any[], txes: any] = [txes: any],
|
|
164
|
-
_Dependencies extends GatedTransactionDependencies = GatedTransactionDependencies,
|
|
165
|
-
> =
|
|
166
|
-
| LiteralGatedTransaction<Name, TxType, CheckOutput, _Dependencies>
|
|
167
|
-
| FunctionalGatedTransaction<Name, TxType, CheckOutput, DepInput, _Dependencies>;
|
|
168
|
-
|
|
169
|
-
export type BaseGatedTransactionFor<GatedTx extends GatedTransaction> =
|
|
170
|
-
GatedTx extends GatedTransaction<infer Name, any, infer CheckOutput, any, infer _Dependencies>
|
|
171
|
-
? BaseGatedTransaction<Name, CheckOutput, _Dependencies>
|
|
172
|
-
: never;
|
|
173
|
-
|
|
174
|
-
export enum GatedTransactionStatus {
|
|
175
|
-
// precheck passed, no need to send the tx
|
|
176
|
-
NO_OP = 'no_op',
|
|
177
|
-
// precheck failed, tx was sent, postcheck passed
|
|
178
|
-
SUCCESS = 'success',
|
|
179
|
-
// precheck failed, tx was sent but sender returned an error
|
|
180
|
-
TRANSACTION_FAILED = 'transaction_failed',
|
|
181
|
-
// precheck failed, tx was sent, postcheck failed
|
|
182
|
-
FINAL_CHECK_FAILED = 'final_check_failed',
|
|
183
|
-
// the tx couldn't be resolved because one of its dependencies resolved to a failed state
|
|
184
|
-
DEPENDENCY_FAILED = 'dependency_failed',
|
|
185
|
-
// approval to send the tx was explicitly denied
|
|
186
|
-
DENIED = 'denied',
|
|
187
|
-
// precheck failed, tx was sent but indeterminate, deferred execution passed on a recheck
|
|
188
|
-
DEFERRED_SUCCESS = 'deferred_success',
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
type NoOpGatedTransaction = {
|
|
192
|
-
status: GatedTransactionStatus.NO_OP;
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
export type SuccessfulGatedTransaction<TxType extends Transaction> = {
|
|
196
|
-
status: GatedTransactionStatus.SUCCESS;
|
|
197
|
-
submittedTransaction: TransactionWithResultFor<TxType>;
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
type TxFailedGatedTransaction = {
|
|
201
|
-
status: GatedTransactionStatus.TRANSACTION_FAILED;
|
|
202
|
-
transactionError: any;
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
type CheckFailedGatedTransaction<GatedTx extends GatedTransaction, TxType extends Transaction> = {
|
|
206
|
-
status: GatedTransactionStatus.FINAL_CHECK_FAILED;
|
|
207
|
-
submittedTransaction: TransactionWithResultFor<TxType>;
|
|
208
|
-
finalOnChainState: InferOnChainDataTypeFromGatedTransaction<GatedTx>;
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
type DependencyFailedGatedTransaction = {
|
|
212
|
-
status: GatedTransactionStatus.DEPENDENCY_FAILED;
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
type DeniedGatedTransaction = {
|
|
216
|
-
status: GatedTransactionStatus.DENIED;
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
type DeferredSuccessfulGatedTransaction = {
|
|
220
|
-
status: GatedTransactionStatus.DEFERRED_SUCCESS;
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
export type GatedTransactionResult<
|
|
224
|
-
GatedTx extends GatedTransaction = GatedTransaction,
|
|
225
|
-
TxType extends Transaction = Transaction,
|
|
226
|
-
> =
|
|
227
|
-
| NoOpGatedTransaction
|
|
228
|
-
| SuccessfulGatedTransaction<TxType>
|
|
229
|
-
| TxFailedGatedTransaction
|
|
230
|
-
| CheckFailedGatedTransaction<GatedTx, TxType>
|
|
231
|
-
| DependencyFailedGatedTransaction
|
|
232
|
-
| DeniedGatedTransaction
|
|
233
|
-
| DeferredSuccessfulGatedTransaction;
|
|
234
|
-
|
|
235
|
-
export type ResolvedGatedTransaction<
|
|
236
|
-
GatedTx extends GatedTransaction = GatedTransaction,
|
|
237
|
-
TxType extends Transaction = Transaction,
|
|
238
|
-
> = BaseGatedTransactionFor<GatedTx> & {
|
|
239
|
-
result: GatedTransactionResult<GatedTx, TxType>;
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
export const isResolvedGtx = (
|
|
243
|
-
gtx: GatedTransaction | ResolvedGatedTransaction,
|
|
244
|
-
): gtx is ResolvedGatedTransaction => !!(gtx as ResolvedGatedTransaction).result;
|
|
245
|
-
|
|
246
|
-
export const gatedTransactionSchema = <
|
|
247
|
-
Name extends z.ZodString | z.ZodLiteral<string> = z.ZodString,
|
|
248
|
-
TransactionSchema extends typeof _transactionSchema = typeof _transactionSchema,
|
|
249
|
-
>(_?: {
|
|
250
|
-
name?: Name;
|
|
251
|
-
transactionSchema?: TransactionSchema;
|
|
252
|
-
}) =>
|
|
253
|
-
customSchema<GatedTransaction<z.infer<Name>, z.infer<TransactionSchema>>>().meta({
|
|
254
|
-
title: 'Gated Transaction',
|
|
255
|
-
description: 'A schema for a gated transaction',
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
export const resolvedGatedTransactionSchema = <
|
|
259
|
-
Name extends z.ZodString | z.ZodLiteral<string> = z.ZodString,
|
|
260
|
-
TransactionSchema extends typeof _transactionSchema = typeof _transactionSchema,
|
|
261
|
-
>(_?: {
|
|
262
|
-
name?: Name;
|
|
263
|
-
transactionSchema?: TransactionSchema;
|
|
264
|
-
}) =>
|
|
265
|
-
customSchema<
|
|
266
|
-
ResolvedGatedTransaction<
|
|
267
|
-
GatedTransaction<z.infer<Name>, z.infer<TransactionSchema>>,
|
|
268
|
-
z.infer<TransactionSchema>
|
|
269
|
-
>
|
|
270
|
-
>().meta({
|
|
271
|
-
title: 'Resolved Gated Transaction',
|
|
272
|
-
description: 'A schema for a resolved gated transaction',
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
export const successfulGatedTransactionSchema = <
|
|
276
|
-
Name extends z.ZodString | z.ZodLiteral<string> = z.ZodString,
|
|
277
|
-
TransactionSchema extends typeof _transactionSchema = typeof _transactionSchema,
|
|
278
|
-
>(_?: {
|
|
279
|
-
name?: Name;
|
|
280
|
-
transactionSchema?: TransactionSchema;
|
|
281
|
-
}) =>
|
|
282
|
-
customSchema<
|
|
283
|
-
BaseGatedTransactionFor<GatedTransaction<z.infer<Name>, z.infer<TransactionSchema>>> & {
|
|
284
|
-
result: SuccessfulGatedTransaction<z.infer<TransactionSchema>>;
|
|
285
|
-
}
|
|
286
|
-
>().meta({
|
|
287
|
-
title: 'Successful Gated Transaction',
|
|
288
|
-
description: 'A schema for a successful gated transaction',
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Builds a schema for an activity that builds a transaction based on the results of other transactions
|
|
293
|
-
* @param transactionSchema The schema for the transaction to be built
|
|
294
|
-
* @param transactionWithResultSchema The schema for the results of the transactions you're building off of
|
|
295
|
-
* @param txNumber The number of transactions you're building off of
|
|
296
|
-
* @param extraArgs Additional arguments that must be passed to the function after the txes
|
|
297
|
-
* @returns A schema for the activity that builds the transaction
|
|
298
|
-
*/
|
|
299
|
-
export const createTxArrayDependentActivitySchema = <
|
|
300
|
-
TransactionSchema extends typeof _transactionSchema = typeof _transactionSchema,
|
|
301
|
-
ExtraArgs extends z.ZodTuple = z.ZodTuple<[]>,
|
|
302
|
-
>(
|
|
303
|
-
transactionSchema: TransactionSchema,
|
|
304
|
-
extraArgs?: ExtraArgs,
|
|
305
|
-
) => {
|
|
306
|
-
return functionSchema({
|
|
307
|
-
input: z.tuple([
|
|
308
|
-
...(extraArgs?.def?.items ?? []),
|
|
309
|
-
z.array(
|
|
310
|
-
resolvedGatedTransactionSchema({
|
|
311
|
-
transactionSchema,
|
|
312
|
-
}),
|
|
313
|
-
),
|
|
314
|
-
] as any),
|
|
315
|
-
output: z.promise(transactionSchema),
|
|
316
|
-
}) as unknown as z.ZodType<
|
|
317
|
-
[] extends z.infer<ExtraArgs>
|
|
318
|
-
? (
|
|
319
|
-
txs: ResolvedGatedTransaction<
|
|
320
|
-
GatedTransaction<string, z.infer<TransactionSchema>>
|
|
321
|
-
>[],
|
|
322
|
-
) => Promise<z.infer<TransactionSchema>>
|
|
323
|
-
: (
|
|
324
|
-
...args: [
|
|
325
|
-
...extraArgs: z.infer<ExtraArgs>,
|
|
326
|
-
txs: ResolvedGatedTransaction<
|
|
327
|
-
GatedTransaction<string, z.infer<TransactionSchema>>
|
|
328
|
-
>[],
|
|
329
|
-
]
|
|
330
|
-
) => Promise<z.infer<TransactionSchema>>
|
|
331
|
-
>;
|
|
332
|
-
};
|
|
333
|
-
/**
|
|
334
|
-
* Builds a schema for an activity that builds a transaction based on the results of other transactions
|
|
335
|
-
* @param transactionSchema The schema for the transaction to be built
|
|
336
|
-
* @param transactionWithResultSchema The schema for the results of the transactions you're building off of
|
|
337
|
-
* @param txNumber The number of transactions you're building off of
|
|
338
|
-
* @param extraArgs Additional arguments that must be passed to the function after the txes
|
|
339
|
-
* @returns A schema for the activity that builds the transaction
|
|
340
|
-
*/
|
|
341
|
-
export const createTxTupleDependentActivitySchema = <
|
|
342
|
-
TransactionSchema extends typeof _transactionSchema = typeof _transactionSchema,
|
|
343
|
-
const TxNumber extends number = 1,
|
|
344
|
-
ExtraArgs extends z.ZodTuple = z.ZodTuple<[]>,
|
|
345
|
-
>(
|
|
346
|
-
transactionSchema: TransactionSchema,
|
|
347
|
-
txNumber: TxNumber,
|
|
348
|
-
extraArgs?: ExtraArgs,
|
|
349
|
-
) => {
|
|
350
|
-
const txs = Array.from({ length: txNumber }, () =>
|
|
351
|
-
resolvedGatedTransactionSchema({
|
|
352
|
-
transactionSchema: transactionSchema,
|
|
353
|
-
}),
|
|
354
|
-
);
|
|
355
|
-
|
|
356
|
-
return functionSchema({
|
|
357
|
-
input: z.tuple([...(extraArgs?.def?.items ?? []), z.tuple(txs as any)] as any),
|
|
358
|
-
output: z.promise(transactionSchema),
|
|
359
|
-
}) as unknown as z.ZodType<
|
|
360
|
-
[] extends z.infer<ExtraArgs>
|
|
361
|
-
? (
|
|
362
|
-
txs: BuildTuple<
|
|
363
|
-
ResolvedGatedTransaction<
|
|
364
|
-
GatedTransaction<string, z.infer<TransactionSchema>>
|
|
365
|
-
>,
|
|
366
|
-
TxNumber
|
|
367
|
-
>,
|
|
368
|
-
) => Promise<z.infer<TransactionSchema>>
|
|
369
|
-
: (
|
|
370
|
-
...args: [
|
|
371
|
-
...extraArgs: z.infer<ExtraArgs>,
|
|
372
|
-
txs: BuildTuple<
|
|
373
|
-
ResolvedGatedTransaction<
|
|
374
|
-
GatedTransaction<string, z.infer<TransactionSchema>>
|
|
375
|
-
>,
|
|
376
|
-
TxNumber
|
|
377
|
-
>,
|
|
378
|
-
]
|
|
379
|
-
) => Promise<z.infer<TransactionSchema>>
|
|
380
|
-
>;
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
export const createGatedTxCheckActivitySchema = <
|
|
384
|
-
Output extends z.ZodType,
|
|
385
|
-
const Input extends z.ZodType[] = [],
|
|
386
|
-
TransactionWithResultSchema extends
|
|
387
|
-
typeof _transactionWithResultSchema = typeof _transactionWithResultSchema,
|
|
388
|
-
>({
|
|
389
|
-
input,
|
|
390
|
-
output,
|
|
391
|
-
transactionWithResultSchema,
|
|
392
|
-
}: {
|
|
393
|
-
input?: Input;
|
|
394
|
-
transactionWithResultSchema?: TransactionWithResultSchema;
|
|
395
|
-
output: Output;
|
|
396
|
-
}) => {
|
|
397
|
-
const txWithResultSchema = (
|
|
398
|
-
transactionWithResultSchema ?? _transactionWithResultSchema
|
|
399
|
-
).optional();
|
|
400
|
-
|
|
401
|
-
return functionSchema({
|
|
402
|
-
input: z.tuple([...(input ?? []), txWithResultSchema] as any),
|
|
403
|
-
output: z.promise(output),
|
|
404
|
-
}) as z.ZodType<
|
|
405
|
-
(
|
|
406
|
-
...args: [...InferredArray<Input>, z.infer<TransactionWithResultSchema>?]
|
|
407
|
-
) => Promise<z.infer<Output>>
|
|
408
|
-
>;
|
|
409
|
-
};
|
|
410
|
-
|
|
411
|
-
export type ResolvedGatedTransactionDependencies<GatedTx extends GatedTransaction> =
|
|
412
|
-
GatedTx extends GatedTransaction<any, any, any, any, infer _Dependencies>
|
|
413
|
-
? {
|
|
414
|
-
[K in keyof _Dependencies]?: ResolvedGatedTransaction<_Dependencies[K]>;
|
|
415
|
-
}
|
|
416
|
-
: never;
|
|
417
|
-
|
|
418
|
-
export interface GatedTxCheckResult {
|
|
419
|
-
expectationMet: boolean;
|
|
420
|
-
data: unknown;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
export const gatedTxCheckResultSchema = z.object({
|
|
424
|
-
expectationMet: z.boolean(),
|
|
425
|
-
data: z.any(),
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
export const isSuccessfulGatedTransaction = <
|
|
429
|
-
GatedTx extends GatedTransaction,
|
|
430
|
-
TxType extends Transaction,
|
|
431
|
-
>(
|
|
432
|
-
gtx: ResolvedGatedTransaction<GatedTx, TxType>,
|
|
433
|
-
): gtx is BaseGatedTransactionFor<GatedTx> & { result: SuccessfulGatedTransaction<TxType> } => {
|
|
434
|
-
return gtx.result.status === GatedTransactionStatus.SUCCESS;
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
export const gatedTransactionCacheSchema = z.object({
|
|
438
|
-
getCachedTxCheckData: functionSchema({
|
|
439
|
-
input: z.tuple([z.any()]),
|
|
440
|
-
output: z.promise(z.any()),
|
|
441
|
-
}) as z.ZodType<
|
|
442
|
-
<GatedTx extends GatedTransaction>(
|
|
443
|
-
gtx: GatedTx,
|
|
444
|
-
) => Promise<InferOnChainDataTypeFromGatedTransaction<GatedTx> | undefined>
|
|
445
|
-
>,
|
|
446
|
-
cacheSuccessfulTxCheckData: functionSchema({
|
|
447
|
-
input: z.tuple([z.any(), z.any()]),
|
|
448
|
-
output: z.promise(z.any()),
|
|
449
|
-
}) as z.ZodType<
|
|
450
|
-
<GatedTx extends GatedTransaction>(
|
|
451
|
-
gtx: GatedTx,
|
|
452
|
-
data: InferOnChainDataTypeFromGatedTransaction<GatedTx>,
|
|
453
|
-
) => Promise<void>
|
|
454
|
-
>,
|
|
455
|
-
});
|
|
456
|
-
|
|
457
|
-
export type IGatedTransactionCache = z.infer<typeof gatedTransactionCacheSchema>;
|
|
458
|
-
|
|
459
|
-
/**
|
|
460
|
-
* name-chain-uniqueIdKeys
|
|
461
|
-
*
|
|
462
|
-
* E.g., setDelegate-ethereum-oAppAddress:0xMY_OAPP
|
|
463
|
-
*/
|
|
464
|
-
export type GatedTransactionId = `${string}-${string}-${string}`;
|
|
465
|
-
|
|
466
|
-
/**
|
|
467
|
-
* bundleName-chain-uniqueIdKeys
|
|
468
|
-
*
|
|
469
|
-
* E.g., SetPeer-ton-oAppAddress:0xMY_OAPP
|
|
470
|
-
*/
|
|
471
|
-
export type GatedTransactionBundleId = `${string}-${string}-${string}`;
|
package/tsconfig.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@layerzerolabs/typescript-configuration/tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": "./src",
|
|
5
|
-
"outDir": "./dist",
|
|
6
|
-
"strictPropertyInitialization": false,
|
|
7
|
-
"noUnusedLocals": false,
|
|
8
|
-
"noUnusedParameters": false,
|
|
9
|
-
"jsx": "react-jsx"
|
|
10
|
-
},
|
|
11
|
-
"exclude": [
|
|
12
|
-
"node_modules",
|
|
13
|
-
"**/__mocks__/*",
|
|
14
|
-
"**/__tests__/*",
|
|
15
|
-
"**/*.spec.ts",
|
|
16
|
-
"**/*.test.ts",
|
|
17
|
-
"dist"
|
|
18
|
-
],
|
|
19
|
-
"include": ["src/**/*"]
|
|
20
|
-
}
|