-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathContractService.ts
More file actions
242 lines (236 loc) · 8.88 KB
/
Copy pathContractService.ts
File metadata and controls
242 lines (236 loc) · 8.88 KB
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
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { CancelablePromise } from '../core/CancelablePromise';
import type { BaseHttpRequest } from '../core/BaseHttpRequest';
export class ContractService {
constructor(public readonly httpRequest: BaseHttpRequest) {}
/**
* Read from contract
* Call a read function on a contract.
* @param functionName The function to call on the contract. It is highly recommended to provide a full function signature, such as 'function balanceOf(address owner) view returns (uint256)', to avoid ambiguity and to skip ABI resolution
* @param chain A chain ID ("137") or slug ("polygon-amoy-testnet"). Chain ID is preferred.
* @param contractAddress Contract address
* @param args Arguments for the function. Comma Separated
* @param abi
* @returns any Default Response
* @throws ApiError
*/
public read(
functionName: string,
chain: string,
contractAddress: string,
args?: string,
abi?: Array<{
type: string;
name?: string;
inputs?: Array<{
type?: string;
name?: string;
internalType?: string;
stateMutability?: string;
components?: Array<{
type?: string;
name?: string;
internalType?: string;
}>;
}>;
outputs?: Array<{
type?: string;
name?: string;
internalType?: string;
stateMutability?: string;
components?: Array<{
type?: string;
name?: string;
internalType?: string;
}>;
}>;
stateMutability?: string;
}>,
): CancelablePromise<{
result: any;
}> {
return this.httpRequest.request({
method: 'GET',
url: '/contract/{chain}/{contractAddress}/read',
path: {
'chain': chain,
'contractAddress': contractAddress,
},
query: {
'functionName': functionName,
'args': args,
'abi': abi,
},
errors: {
400: `Bad Request`,
404: `Not Found`,
500: `Internal Server Error`,
},
});
}
/**
* Batch read from multiple contracts
* Execute multiple contract read operations in a single call using Multicall
* @param chain
* @param requestBody
* @returns any Default Response
* @throws ApiError
*/
public readBatch(
chain: string,
requestBody: {
calls: Array<{
contractAddress: string;
functionName: string;
functionAbi?: string;
args?: Array<any>;
}>;
/**
* Address of the multicall contract to use. If omitted, multicall3 contract will be used (0xcA11bde05977b3631167028862bE2a173976CA11).
*/
multicallAddress?: string;
},
): CancelablePromise<{
results: Array<{
success: boolean;
result: any;
}>;
}> {
return this.httpRequest.request({
method: 'POST',
url: '/contract/{chain}/read-batch',
path: {
'chain': chain,
},
body: requestBody,
mediaType: 'application/json',
errors: {
400: `Bad Request`,
404: `Not Found`,
500: `Internal Server Error`,
},
});
}
/**
* Write to contract
* Call a write function on a contract.
* @param chain A chain ID ("137") or slug ("polygon-amoy-testnet"). Chain ID is preferred.
* @param contractAddress Contract address
* @param xBackendWalletAddress Backend wallet address
* @param requestBody
* @param simulateTx Simulates the transaction before adding it to the queue, returning an error if it fails simulation. Note: This step is less performant and recommended only for debugging purposes.
* @param xIdempotencyKey Transactions submitted with the same idempotency key will be de-duplicated. Only the last 100000 transactions are compared.
* @param xTransactionMode Transaction mode to use for EOA transactions. Will be ignored if using a smart wallet. If omitted, defaults to regular EOA transactions.
* @param xAccountAddress Smart account address
* @param xAccountFactoryAddress Smart account factory address. If omitted, Engine will try to resolve it from the contract.
* @param xAccountSalt Smart account salt as string or hex. This is used to predict the smart account address. Useful when creating multiple accounts with the same admin and only needed when deploying the account as part of a userop.
* @returns any Default Response
* @throws ApiError
*/
public write(
chain: string,
contractAddress: string,
xBackendWalletAddress: string,
requestBody: {
/**
* The function to call on the contract. It is highly recommended to provide a full function signature, such as "function mintTo(address to, uint256 amount)", to avoid ambiguity and to skip ABI resolution.
*/
functionName: string;
/**
* An array of arguments to provide the function. Supports: numbers, strings, arrays, objects. Do not provide: BigNumber, bigint, Date objects
*/
args: Array<any>;
txOverrides?: {
/**
* Gas limit for the transaction
*/
gas?: string;
/**
* Gas price for the transaction. Do not use this if maxFeePerGas is set or if you want to use EIP-1559 type transactions. Only use this if you want to use legacy transactions.
*/
gasPrice?: string;
/**
* Maximum fee per gas
*/
maxFeePerGas?: string;
/**
* Maximum priority fee per gas
*/
maxPriorityFeePerGas?: string;
/**
* Maximum duration that a transaction is valid. If a transaction cannot be sent before the timeout, the transaction will be set to 'errored'. Default: no timeout
*/
timeoutSeconds?: number;
/**
* Amount of native currency in wei to send with this transaction. Used to transfer funds or pay a contract.
*/
value?: string;
};
abi?: Array<{
type: string;
name?: string;
inputs?: Array<{
type?: string;
name?: string;
internalType?: string;
stateMutability?: string;
components?: Array<{
type?: string;
name?: string;
internalType?: string;
}>;
}>;
outputs?: Array<{
type?: string;
name?: string;
internalType?: string;
stateMutability?: string;
components?: Array<{
type?: string;
name?: string;
internalType?: string;
}>;
}>;
stateMutability?: string;
}>;
},
simulateTx: boolean = false,
xIdempotencyKey?: string,
xTransactionMode?: 'sponsored',
xAccountAddress?: string,
xAccountFactoryAddress?: string,
xAccountSalt?: string,
): CancelablePromise<{
result: {
/**
* Queue ID
*/
queueId: string;
};
}> {
return this.httpRequest.request({
method: 'POST',
url: '/contract/{chain}/{contractAddress}/write',
path: {
'chain': chain,
'contractAddress': contractAddress,
},
headers: {
'x-backend-wallet-address': xBackendWalletAddress,
'x-idempotency-key': xIdempotencyKey,
'x-transaction-mode': xTransactionMode,
'x-account-address': xAccountAddress,
'x-account-factory-address': xAccountFactoryAddress,
'x-account-salt': xAccountSalt,
},
query: {
'simulateTx': simulateTx,
},
body: requestBody,
mediaType: 'application/json',
});
}
}