forked from aptos-labs/aptos-ts-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
303 lines (272 loc) · 8.98 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0
import { AptosConfig } from "../api/aptosConfig";
import { MoveOption, MoveString, MoveVector } from "../bcs/serializable/moveStructs";
import { Bool, U128, U16, U256, U32, U64, U8 } from "../bcs/serializable/movePrimitives";
import { FixedBytes } from "../bcs/serializable/fixedBytes";
import { AccountAddress } from "../core";
import { PublicKey } from "../core/crypto/asymmetricCrypto";
import {
MultiAgentRawTransaction,
FeePayerRawTransaction,
RawTransaction,
TransactionPayloadEntryFunction,
TransactionPayloadMultisig,
TransactionPayloadScript,
} from "./instances";
import { AnyNumber, HexInput, MoveFunctionGenericTypeParam, MoveStructType } from "../types";
import { TypeTag } from "./typeTag";
/**
* Entry function arguments to be used when building a raw transaction using remote ABI
*/
export type SimpleEntryFunctionArgumentTypes =
| boolean
| number
| bigint
| string
| null // To support optional empty
| undefined // To support optional empty
| Uint8Array
| Array<SimpleEntryFunctionArgumentTypes>;
/**
* Entry function arguments to be used when building a raw transaction using BCS serialized arguments
*/
export type EntryFunctionArgumentTypes =
| Bool
| U8
| U16
| U32
| U64
| U128
| U256
| AccountAddress
| MoveVector<EntryFunctionArgumentTypes>
| MoveOption<EntryFunctionArgumentTypes>
| MoveString
| FixedBytes;
/**
* Script function arguments to be used when building a raw transaction using BCS serialized arguments
*/
export type ScriptFunctionArgumentTypes =
| Bool
| U8
| U16
| U32
| U64
| U128
| U256
| AccountAddress
| MoveVector<U8>
| MoveString
| FixedBytes;
/**
* Type that holds all raw transaction instances Aptos SDK supports
*/
export type AnyRawTransactionInstance = RawTransaction | MultiAgentRawTransaction | FeePayerRawTransaction;
// TRANSACTION GENERATION TYPES //
/**
* Optional options to set when generating a transaction
*/
export type InputGenerateTransactionOptions = {
maxGasAmount?: AnyNumber;
gasUnitPrice?: AnyNumber;
expireTimestamp?: AnyNumber;
accountSequenceNumber?: AnyNumber;
};
/**
* The generated transaction payload type that was produces from `generateTransactionPayload()` function.
*/
export type AnyTransactionPayloadInstance =
| TransactionPayloadEntryFunction
| TransactionPayloadScript
| TransactionPayloadMultisig;
/**
* Unified type for the data needed to generate a transaction payload of types:
* Entry Function | Script | Multi Sig
*/
export type InputGenerateTransactionPayloadData = InputEntryFunctionData | InputScriptData | InputMultiSigData;
export type InputGenerateTransactionPayloadDataWithRemoteABI =
| (InputScriptData & { aptosConfig?: undefined })
| InputEntryFunctionDataWithRemoteABI
| InputMultiSigDataWithRemoteABI;
/**
* The data needed to generate an Entry Function payload
*/
export type InputEntryFunctionData = {
function: MoveStructType;
typeArguments?: Array<TypeTag>;
functionArguments: Array<EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes>;
};
export type InputEntryFunctionDataWithRemoteABI = InputEntryFunctionData & { aptosConfig: AptosConfig };
/**
* The data needed to generate a Multi Sig payload
*/
export type InputMultiSigData = {
multisigAddress: AccountAddress;
} & InputEntryFunctionData;
/**
* The data needed to generate a Multi Sig payload
*/
export type InputMultiSigDataWithRemoteABI = {
multisigAddress: AccountAddress | string;
} & InputEntryFunctionDataWithRemoteABI;
/**
* The data needed to generate a Script payload
*/
export type InputScriptData = {
bytecode: HexInput;
typeArguments?: Array<TypeTag>;
functionArguments: Array<ScriptFunctionArgumentTypes>;
};
/**
* Interface of an Entry function's ABI.
*
* This is used to provide type checking and simple input conversion on ABI based transaction submission.
*/
export type EntryFunctionABI = {
typeParameters: Array<MoveFunctionGenericTypeParam>;
parameters: Array<TypeTag>;
};
/**
* Interface of the arguments to generate a single signer transaction.
* Used to provide to `generateTransaction()` method in the transaction builder flow
*/
export interface InputGenerateSingleSignerRawTransactionArgs {
aptosConfig: AptosConfig;
sender: HexInput;
payload: AnyTransactionPayloadInstance;
feePayerAddress?: undefined;
secondarySignerAddresses?: undefined;
options?: InputGenerateTransactionOptions;
}
/**
* Interface of the arguments to generate a fee payer transaction.
* Used to provide to `generateTransaction()` method in the transaction builder flow
*/
export interface InputGenerateFeePayerRawTransactionArgs {
aptosConfig: AptosConfig;
sender: HexInput;
payload: AnyTransactionPayloadInstance;
feePayerAddress: HexInput;
secondarySignerAddresses?: HexInput[];
options?: InputGenerateTransactionOptions;
}
/**
* Interface of the arguments to generate a multi-agent transaction.
* Used to provide to `generateTransaction()` method in the transaction builder flow
*/
export interface InputGenerateMultiAgentRawTransactionArgs {
aptosConfig: AptosConfig;
sender: HexInput;
payload: AnyTransactionPayloadInstance;
secondarySignerAddresses: HexInput[];
feePayerAddress?: undefined;
options?: InputGenerateTransactionOptions;
}
/**
* Unified type that holds all the interfaces to generate different transaction types
*/
export type InputGenerateRawTransactionArgs =
| InputGenerateSingleSignerRawTransactionArgs
| InputGenerateFeePayerRawTransactionArgs
| InputGenerateMultiAgentRawTransactionArgs;
/**
* Interface that holds the return data when generating a single signer transaction
*
* @param rawTransaction a bcs serialized raw transaction
*/
export interface InputSingleSignerTransaction {
rawTransaction: Uint8Array;
feePayerAddress?: undefined;
secondarySignerAddresses?: undefined;
}
/**
* Interface that holds the return data when generating a fee payer transaction
*
* @param rawTransaction a bcs serialized raw transaction
* @param secondarySignerAddresses optional. secondary signer addresses for multi-agent transaction
* @param feePayerAddress fee payer address for a fee payer transaction (aka Sponsored Transaction)
*/
export interface InputFeePayerTransaction {
rawTransaction: Uint8Array;
feePayerAddress: AccountAddress;
secondarySignerAddresses?: AccountAddress[];
}
/**
* Interface that holds the return data when generating a multi-agent transaction.
*
* @param rawTransaction a bcs serialized raw transaction
* @param secondarySignerAddresses secondary signer addresses for multi-agent transaction
*/
export interface InputMultiAgentTransaction {
rawTransaction: Uint8Array;
secondarySignerAddresses: AccountAddress[];
feePayerAddress?: undefined;
}
/**
* Unified type that holds all the return interfaces when generating different transaction types
*/
export type AnyRawTransaction = InputSingleSignerTransaction | InputFeePayerTransaction | InputMultiAgentTransaction;
// TRANSACTION SIMULATION TYPES //
export type InputSimulateTransactionData = {
/**
* The transaction to simulate, probably generated by `generateTransaction()`
*/
transaction: AnyRawTransaction;
/**
* For a single signer transaction
*/
signerPublicKey: PublicKey;
/**
* For a fee payer or multi-agent transaction that requires additional signers in
*/
secondarySignersPublicKeys?: Array<PublicKey>;
/**
* For a fee payer transaction (aka Sponsored Transaction)
*/
feePayerPublicKey?: PublicKey;
options?: InputSimulateTransactionOptions;
};
export type InputSimulateTransactionOptions = {
estimateGasUnitPrice?: boolean;
estimateMaxGasAmount?: boolean;
estimatePrioritizedGasUnitPrice?: boolean;
};
// USER INPUT TYPES //
/**
* Interface that holds the user data input when generating a single signer transaction
*/
export interface InputGenerateSingleSignerRawTransactionData {
sender: HexInput;
feePayerAddress?: undefined;
secondarySignerAddresses?: undefined;
options?: InputGenerateTransactionOptions;
data: InputGenerateTransactionPayloadData;
}
/**
* Interface that holds the user data input when generating a fee payer transaction
*/
export interface InputGenerateFeePayerRawTransactionData {
sender: HexInput;
feePayerAddress: HexInput;
secondarySignerAddresses?: HexInput[];
options?: InputGenerateTransactionOptions;
data: InputGenerateTransactionPayloadData;
}
/**
* Interface that holds the user data input when generating a multi-agent transaction
*/
export interface InputGenerateMultiAgentRawTransactionData {
sender: HexInput;
secondarySignerAddresses: HexInput[];
feePayerAddress?: undefined;
options?: InputGenerateTransactionOptions;
data: InputGenerateTransactionPayloadData;
}
/**
* Unified type that holds all the user data input interfaces when generating different transaction types
*/
export type InputGenerateTransactionData =
| InputGenerateMultiAgentRawTransactionData
| InputGenerateFeePayerRawTransactionData
| InputGenerateSingleSignerRawTransactionData;