@fatsolutions/privacy-pools-core-starknet-sdk 0.0.44 → 0.0.46
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/abis/ERC20.abi.js +145 -145
- package/dist/abis/EntryPoint.abi.d.ts +35 -12
- package/dist/abis/EntryPoint.abi.js +262 -230
- package/dist/abis/EntryPoint.abi.js.map +1 -1
- package/dist/abis/PrivacyPool.abi.d.ts +69 -8
- package/dist/abis/PrivacyPool.abi.js +228 -146
- package/dist/abis/PrivacyPool.abi.js.map +1 -1
- package/dist/account.service.d.ts +16 -0
- package/dist/account.service.js +31 -0
- package/dist/account.service.js.map +1 -0
- package/dist/auditor.d.ts +31 -0
- package/dist/auditor.js +146 -0
- package/dist/auditor.js.map +1 -0
- package/dist/contracts/contracts.service.d.ts +3 -3
- package/dist/contracts/contracts.service.js +71 -19
- package/dist/contracts/contracts.service.js.map +1 -1
- package/dist/contracts/index.js.map +1 -1
- package/dist/contracts/transactionHandler.d.ts +1 -1
- package/dist/contracts/transactionHandler.js +2 -4
- package/dist/contracts/transactionHandler.js.map +1 -1
- package/dist/data.service.d.ts +20 -6
- package/dist/data.service.js +50 -7
- package/dist/data.service.js.map +1 -1
- package/dist/errors/contracts.errors.js +1 -1
- package/dist/errors/index.js.map +1 -1
- package/dist/garaga.js +9 -3
- package/dist/garaga.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/sdk.js +4 -4
- package/dist/sdk.js.map +1 -1
- package/dist/types/conversions.js.map +1 -1
- package/dist/types/entrypoint.d.ts +2 -0
- package/dist/types/entrypoint.js +50 -30
- package/dist/types/entrypoint.js.map +1 -1
- package/dist/types/snarkjs.d.ts +7 -46
- package/dist/utils.d.ts +4 -1
- package/dist/utils.js +11 -2
- package/dist/utils.js.map +1 -1
- package/package.json +14 -3
- package/src/abis/ERC20.abi.ts +145 -145
- package/src/abis/EntryPoint.abi.ts +262 -230
- package/src/abis/PrivacyPool.abi.ts +228 -146
- package/src/abis/index.ts +1 -1
- package/src/account.service.ts +47 -0
- package/src/auditor.ts +219 -0
- package/src/contracts/contracts.service.ts +325 -73
- package/src/contracts/index.ts +2 -2
- package/src/contracts/transactionHandler.ts +16 -7
- package/src/data.service.ts +123 -146
- package/src/errors/contracts.errors.ts +6 -6
- package/src/errors/index.ts +18 -24
- package/src/garaga.ts +10 -4
- package/src/index.ts +17 -27
- package/src/sdk.ts +39 -26
- package/src/types/conversions.ts +11 -12
- package/src/types/entrypoint.ts +74 -41
- package/src/types/garaga.ts +32 -32
- package/src/types/index.ts +1 -1
- package/src/types/snarkjs.ts +8 -20
- package/src/utils.ts +33 -12
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { Hash } from "@0xbow/privacy-pools-core-sdk";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
AllowArray,
|
|
4
|
+
Call,
|
|
5
|
+
Contract,
|
|
6
|
+
InvokeFunctionResponse,
|
|
7
|
+
num,
|
|
8
|
+
RpcProvider,
|
|
9
|
+
SimulateTransaction,
|
|
10
|
+
Account as SNAccount,
|
|
11
|
+
TypedContractV2,
|
|
12
|
+
UniversalDetails,
|
|
13
|
+
} from "starknet";
|
|
3
14
|
|
|
4
15
|
import { EntryPointABI } from "../abis/EntryPoint.abi.js";
|
|
5
16
|
import { ERC20ABI } from "../abis/ERC20.abi.js";
|
|
@@ -8,7 +19,7 @@ import { ETH_ADDRESS } from "../constants.js";
|
|
|
8
19
|
import { SNContractError, SNPoolError, StarknetSDKError } from "../errors/index.js";
|
|
9
20
|
import { AssetConfig, Withdrawal } from "../types/entrypoint.js";
|
|
10
21
|
import { StarknetAddress } from "../types/starknet.js";
|
|
11
|
-
import { castBigInt, toAddress } from "../utils.js";
|
|
22
|
+
import { castBigInt, toAddress, toCairoOption } from "../utils.js";
|
|
12
23
|
import { executeIntent, simulateIntent } from "./transactionHandler.js";
|
|
13
24
|
|
|
14
25
|
/**
|
|
@@ -34,22 +45,28 @@ export const Mode = {
|
|
|
34
45
|
/** Simulate the transaction without executing it */
|
|
35
46
|
SIMULATE: "simulate",
|
|
36
47
|
/** Execute the transaction on-chain */
|
|
37
|
-
EXECUTE: "execute"
|
|
48
|
+
EXECUTE: "execute",
|
|
38
49
|
} as const;
|
|
39
50
|
|
|
40
|
-
export type Mode = typeof Mode[keyof typeof Mode];
|
|
51
|
+
export type Mode = (typeof Mode)[keyof typeof Mode];
|
|
41
52
|
|
|
42
53
|
/** Option type for simulation mode */
|
|
43
|
-
export type OptionSimulate =
|
|
54
|
+
export type OptionSimulate = object;
|
|
44
55
|
|
|
45
56
|
/** Option type for execution mode with optional transaction details */
|
|
46
|
-
export type OptionExecute = { details?: UniversalDetails
|
|
57
|
+
export type OptionExecute = { details?: UniversalDetails };
|
|
47
58
|
|
|
48
59
|
/** Option type for simulation mode */
|
|
49
|
-
export type OptionModeSimulate = {
|
|
60
|
+
export type OptionModeSimulate = {
|
|
61
|
+
mode: typeof Mode.SIMULATE;
|
|
62
|
+
modeOptions?: OptionSimulate;
|
|
63
|
+
};
|
|
50
64
|
|
|
51
65
|
/** Option type for execution mode with optional transaction details */
|
|
52
|
-
export type OptionModeExecute = {
|
|
66
|
+
export type OptionModeExecute = {
|
|
67
|
+
mode: typeof Mode.EXECUTE;
|
|
68
|
+
modeOptions?: OptionExecute;
|
|
69
|
+
};
|
|
53
70
|
|
|
54
71
|
type OptionModesMap = {
|
|
55
72
|
[Mode.EXECUTE]: OptionExecute;
|
|
@@ -60,18 +77,18 @@ type OptionModes = {
|
|
|
60
77
|
[K in keyof OptionModesMap]: {
|
|
61
78
|
mode: K;
|
|
62
79
|
modeOptions?: OptionModesMap[K];
|
|
63
|
-
}
|
|
80
|
+
};
|
|
64
81
|
}[keyof OptionModesMap];
|
|
65
82
|
|
|
66
83
|
/** Call options including account and execution mode */
|
|
67
|
-
type CallOptions = { account: SNAccount | RpcProvider
|
|
84
|
+
type CallOptions = { account: SNAccount | RpcProvider } & OptionModes;
|
|
68
85
|
|
|
69
86
|
/** Union type for all possible call results */
|
|
70
|
-
type CallResult = AllowArray<Call> | Omit<SimulateTransaction,
|
|
87
|
+
type CallResult = AllowArray<Call> | Omit<SimulateTransaction, "fee_estimation"> | TransactionResponse;
|
|
71
88
|
|
|
72
89
|
/** Helper function for asserting instances */
|
|
73
90
|
function _isAccount(x: SNAccount | RpcProvider): x is SNAccount {
|
|
74
|
-
return (
|
|
91
|
+
return (x as SNAccount).simulateTransaction !== undefined && (x as SNAccount).execute !== undefined;
|
|
75
92
|
}
|
|
76
93
|
|
|
77
94
|
/**
|
|
@@ -85,15 +102,12 @@ function _isAccount(x: SNAccount | RpcProvider): x is SNAccount {
|
|
|
85
102
|
function _intentOptionWrapper(calls: AllowArray<Call>, options?: CallOptions): Promise<CallResult> {
|
|
86
103
|
if (options === undefined || !_isAccount(options.account)) {
|
|
87
104
|
return Promise.resolve(calls);
|
|
88
|
-
}
|
|
89
|
-
else if (options.mode === Mode.SIMULATE) {
|
|
105
|
+
} else if (options.mode === Mode.SIMULATE) {
|
|
90
106
|
return simulateIntent(options.account, calls);
|
|
91
|
-
}
|
|
92
|
-
else if (options.mode === Mode.EXECUTE) {
|
|
107
|
+
} else if (options.mode === Mode.EXECUTE) {
|
|
93
108
|
const details = options.modeOptions?.details;
|
|
94
109
|
return executeIntent(options.account, calls, details);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
110
|
+
} else {
|
|
97
111
|
throw StarknetSDKError.unreachable();
|
|
98
112
|
}
|
|
99
113
|
}
|
|
@@ -125,7 +139,6 @@ function _intentOptionWrapper(calls: AllowArray<Call>, options?: CallOptions): P
|
|
|
125
139
|
* ```
|
|
126
140
|
*/
|
|
127
141
|
export class SNContractInteractionsService {
|
|
128
|
-
|
|
129
142
|
/** The typed EntryPoint contract instance */
|
|
130
143
|
entrypoint: EntryPointType;
|
|
131
144
|
|
|
@@ -137,9 +150,13 @@ export class SNContractInteractionsService {
|
|
|
137
150
|
*/
|
|
138
151
|
constructor(
|
|
139
152
|
entrypointAddress: StarknetAddress,
|
|
140
|
-
readonly providerOrAccount: SNAccount | RpcProvider
|
|
153
|
+
readonly providerOrAccount: SNAccount | RpcProvider
|
|
141
154
|
) {
|
|
142
|
-
this.entrypoint = new Contract({
|
|
155
|
+
this.entrypoint = new Contract({
|
|
156
|
+
abi: EntryPointABI,
|
|
157
|
+
address: entrypointAddress,
|
|
158
|
+
providerOrAccount: this.providerOrAccount,
|
|
159
|
+
}).typedv2(EntryPointABI);
|
|
143
160
|
}
|
|
144
161
|
|
|
145
162
|
/**
|
|
@@ -149,11 +166,19 @@ export class SNContractInteractionsService {
|
|
|
149
166
|
* @returns A typed contract instance for the PrivacyPool
|
|
150
167
|
*/
|
|
151
168
|
pool(address: StarknetAddress): PrivacyPoolType {
|
|
152
|
-
return new Contract({
|
|
169
|
+
return new Contract({
|
|
170
|
+
abi: PrivacyPoolABI,
|
|
171
|
+
address,
|
|
172
|
+
providerOrAccount: this.providerOrAccount,
|
|
173
|
+
}).typedv2(PrivacyPoolABI);
|
|
153
174
|
}
|
|
154
175
|
|
|
155
176
|
erc20(address: StarknetAddress): Erc20Type {
|
|
156
|
-
return new Contract({
|
|
177
|
+
return new Contract({
|
|
178
|
+
abi: ERC20ABI,
|
|
179
|
+
address,
|
|
180
|
+
providerOrAccount: this.providerOrAccount,
|
|
181
|
+
}).typedv2(ERC20ABI);
|
|
157
182
|
}
|
|
158
183
|
|
|
159
184
|
/**
|
|
@@ -174,7 +199,12 @@ export class SNContractInteractionsService {
|
|
|
174
199
|
* @param options - Simulation options
|
|
175
200
|
* @returns A simulated transaction result
|
|
176
201
|
*/
|
|
177
|
-
depositERC20(
|
|
202
|
+
depositERC20(
|
|
203
|
+
asset: StarknetAddress,
|
|
204
|
+
amount: bigint,
|
|
205
|
+
precommitment: bigint,
|
|
206
|
+
options: OptionModeSimulate
|
|
207
|
+
): Promise<SimulateTransaction>;
|
|
178
208
|
/**
|
|
179
209
|
* Deposits an ERC20 token into a privacy pool and executes the transaction.
|
|
180
210
|
*
|
|
@@ -184,8 +214,18 @@ export class SNContractInteractionsService {
|
|
|
184
214
|
* @param options - Execution options with optional transaction details
|
|
185
215
|
* @returns The transaction response
|
|
186
216
|
*/
|
|
187
|
-
depositERC20(
|
|
188
|
-
|
|
217
|
+
depositERC20(
|
|
218
|
+
asset: StarknetAddress,
|
|
219
|
+
amount: bigint,
|
|
220
|
+
precommitment: bigint,
|
|
221
|
+
options: OptionModeExecute
|
|
222
|
+
): Promise<InvokeFunctionResponse>;
|
|
223
|
+
depositERC20(
|
|
224
|
+
asset: StarknetAddress,
|
|
225
|
+
amount: bigint,
|
|
226
|
+
precommitment: bigint,
|
|
227
|
+
options?: OptionModes
|
|
228
|
+
): Promise<CallResult> {
|
|
189
229
|
const call = this.entrypoint.populate("deposit", [asset, amount, precommitment]);
|
|
190
230
|
return _intentOptionWrapper(call, options && { ...options, account: this.providerOrAccount });
|
|
191
231
|
}
|
|
@@ -239,7 +279,12 @@ export class SNContractInteractionsService {
|
|
|
239
279
|
* @param options - Simulation options
|
|
240
280
|
* @returns A simulated transaction result
|
|
241
281
|
*/
|
|
242
|
-
withdraw(
|
|
282
|
+
withdraw(
|
|
283
|
+
withdrawal: Withdrawal,
|
|
284
|
+
withdrawalProofGaraga: bigint[],
|
|
285
|
+
scope: Hash,
|
|
286
|
+
options: OptionModeSimulate
|
|
287
|
+
): Promise<SimulateTransaction>;
|
|
243
288
|
/**
|
|
244
289
|
* Withdraws funds from a privacy pool and executes the transaction.
|
|
245
290
|
*
|
|
@@ -249,10 +294,24 @@ export class SNContractInteractionsService {
|
|
|
249
294
|
* @param options - Execution options with optional transaction details
|
|
250
295
|
* @returns The transaction response
|
|
251
296
|
*/
|
|
252
|
-
withdraw(
|
|
253
|
-
|
|
297
|
+
withdraw(
|
|
298
|
+
withdrawal: Withdrawal,
|
|
299
|
+
withdrawalProofGaraga: bigint[],
|
|
300
|
+
scope: Hash,
|
|
301
|
+
options: OptionModeExecute
|
|
302
|
+
): Promise<InvokeFunctionResponse>;
|
|
303
|
+
async withdraw(
|
|
304
|
+
withdrawal: Withdrawal,
|
|
305
|
+
withdrawalProofGaraga: bigint[],
|
|
306
|
+
scope: Hash,
|
|
307
|
+
options?: OptionModes
|
|
308
|
+
): Promise<CallResult> {
|
|
309
|
+
const _withdrawal = {
|
|
310
|
+
...withdrawal,
|
|
311
|
+
auditorData: toCairoOption(withdrawal.auditorData),
|
|
312
|
+
};
|
|
254
313
|
const { poolAddress } = await this.getScopeData(scope);
|
|
255
|
-
const call = this.pool(poolAddress).populate("withdraw", [
|
|
314
|
+
const call = this.pool(poolAddress).populate("withdraw", [_withdrawal, { fullProof: withdrawalProofGaraga }]);
|
|
256
315
|
return _intentOptionWrapper(call, options && { ...options, account: this.providerOrAccount });
|
|
257
316
|
}
|
|
258
317
|
|
|
@@ -274,7 +333,12 @@ export class SNContractInteractionsService {
|
|
|
274
333
|
* @param options - Simulation options
|
|
275
334
|
* @returns A simulated transaction result
|
|
276
335
|
*/
|
|
277
|
-
relay(
|
|
336
|
+
relay(
|
|
337
|
+
withdrawal: Withdrawal,
|
|
338
|
+
withdrawalProofGaraga: bigint[],
|
|
339
|
+
scope: Hash,
|
|
340
|
+
options: OptionModeSimulate
|
|
341
|
+
): Promise<SimulateTransaction>;
|
|
278
342
|
/**
|
|
279
343
|
* Relays a withdrawal transaction through the EntryPoint contract and executes it.
|
|
280
344
|
*
|
|
@@ -284,9 +348,23 @@ export class SNContractInteractionsService {
|
|
|
284
348
|
* @param options - Execution options with optional transaction details
|
|
285
349
|
* @returns The transaction response
|
|
286
350
|
*/
|
|
287
|
-
relay(
|
|
288
|
-
|
|
289
|
-
|
|
351
|
+
relay(
|
|
352
|
+
withdrawal: Withdrawal,
|
|
353
|
+
withdrawalProofGaraga: bigint[],
|
|
354
|
+
scope: Hash,
|
|
355
|
+
options: OptionModeExecute
|
|
356
|
+
): Promise<InvokeFunctionResponse>;
|
|
357
|
+
relay(
|
|
358
|
+
withdrawal: Withdrawal,
|
|
359
|
+
withdrawalProofGaraga: bigint[],
|
|
360
|
+
scope: Hash,
|
|
361
|
+
options?: OptionModes
|
|
362
|
+
): Promise<CallResult> {
|
|
363
|
+
const _withdrawal = {
|
|
364
|
+
...withdrawal,
|
|
365
|
+
auditorData: toCairoOption(withdrawal.auditorData),
|
|
366
|
+
};
|
|
367
|
+
const call = this.entrypoint.populate("relay", [_withdrawal, scope, { fullProof: withdrawalProofGaraga }]);
|
|
290
368
|
return _intentOptionWrapper(call, options && { ...options, account: this.providerOrAccount });
|
|
291
369
|
}
|
|
292
370
|
|
|
@@ -306,7 +384,11 @@ export class SNContractInteractionsService {
|
|
|
306
384
|
* @param options - Simulation options
|
|
307
385
|
* @returns A simulated transaction result
|
|
308
386
|
*/
|
|
309
|
-
ragequit(
|
|
387
|
+
ragequit(
|
|
388
|
+
ragequitProofGaraga: bigint[],
|
|
389
|
+
privacyPoolAddress: StarknetAddress,
|
|
390
|
+
options: OptionModeSimulate
|
|
391
|
+
): Promise<SimulateTransaction>;
|
|
310
392
|
/**
|
|
311
393
|
* Performs a ragequit operation to exit a privacy pool and executes the transaction.
|
|
312
394
|
*
|
|
@@ -315,8 +397,16 @@ export class SNContractInteractionsService {
|
|
|
315
397
|
* @param options - Execution options with optional transaction details
|
|
316
398
|
* @returns The transaction response
|
|
317
399
|
*/
|
|
318
|
-
ragequit(
|
|
319
|
-
|
|
400
|
+
ragequit(
|
|
401
|
+
ragequitProofGaraga: bigint[],
|
|
402
|
+
privacyPoolAddress: StarknetAddress,
|
|
403
|
+
options: OptionModeExecute
|
|
404
|
+
): Promise<InvokeFunctionResponse>;
|
|
405
|
+
ragequit(
|
|
406
|
+
ragequitProofGaraga: bigint[],
|
|
407
|
+
privacyPoolAddress: StarknetAddress,
|
|
408
|
+
options?: OptionModes
|
|
409
|
+
): Promise<CallResult> {
|
|
320
410
|
const call = this.pool(privacyPoolAddress).populate("ragequit", [{ fullProof: ragequitProofGaraga }]);
|
|
321
411
|
return _intentOptionWrapper(call, options && { ...options, account: this.providerOrAccount });
|
|
322
412
|
}
|
|
@@ -367,16 +457,16 @@ export class SNContractInteractionsService {
|
|
|
367
457
|
* @param scope - The scope identifier
|
|
368
458
|
* @returns An object containing the pool address and asset address
|
|
369
459
|
*/
|
|
370
|
-
async getScopeData(scope: bigint): Promise<{ poolAddress: StarknetAddress; assetAddress: StarknetAddress
|
|
460
|
+
async getScopeData(scope: bigint): Promise<{ poolAddress: StarknetAddress; assetAddress: StarknetAddress }> {
|
|
371
461
|
const poolAddress = num.toHex64(await this.entrypoint.scopeToPool(scope)) as StarknetAddress;
|
|
372
462
|
const assetAddress = num.toHex64(await this.pool(poolAddress).asset()) as StarknetAddress;
|
|
373
463
|
return {
|
|
374
464
|
poolAddress,
|
|
375
|
-
assetAddress
|
|
465
|
+
assetAddress,
|
|
376
466
|
};
|
|
377
467
|
}
|
|
378
468
|
|
|
379
|
-
async getAssetConfig(asset: StarknetAddress): Promise<AssetConfig & { scope: bigint
|
|
469
|
+
async getAssetConfig(asset: StarknetAddress): Promise<AssetConfig & { scope: bigint }> {
|
|
380
470
|
const { pool, maxRelayFeeBPS, minimumDepositAmount, vettingFeeBPS } = await this.entrypoint.assetConfig(asset);
|
|
381
471
|
const scope = await this.getScope(toAddress(pool));
|
|
382
472
|
return {
|
|
@@ -407,17 +497,55 @@ export class SNContractInteractionsService {
|
|
|
407
497
|
* @todo Implement ERC20 approval functionality
|
|
408
498
|
*/
|
|
409
499
|
approveERC20(spenderAddress: StarknetAddress, tokenAddress: StarknetAddress, amount: bigint): Promise<Call>;
|
|
410
|
-
approveERC20(
|
|
411
|
-
|
|
412
|
-
|
|
500
|
+
approveERC20(
|
|
501
|
+
spenderAddress: StarknetAddress,
|
|
502
|
+
tokenAddress: StarknetAddress,
|
|
503
|
+
amount: bigint,
|
|
504
|
+
options: OptionModeSimulate
|
|
505
|
+
): Promise<SimulateTransaction>;
|
|
506
|
+
approveERC20(
|
|
507
|
+
spenderAddress: StarknetAddress,
|
|
508
|
+
tokenAddress: StarknetAddress,
|
|
509
|
+
amount: bigint,
|
|
510
|
+
options: OptionModeExecute
|
|
511
|
+
): Promise<TransactionResponse>;
|
|
512
|
+
approveERC20(
|
|
513
|
+
spenderAddress: StarknetAddress,
|
|
514
|
+
tokenAddress: StarknetAddress,
|
|
515
|
+
amount: bigint,
|
|
516
|
+
options?: OptionModes
|
|
517
|
+
): Promise<CallResult> {
|
|
413
518
|
const call = this.erc20(tokenAddress).populate("approve", [spenderAddress, amount]);
|
|
414
519
|
return _intentOptionWrapper(call, options && { ...options, account: this.providerOrAccount });
|
|
415
520
|
}
|
|
416
521
|
|
|
417
|
-
approveAndDeposit(
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
522
|
+
approveAndDeposit(
|
|
523
|
+
entrypointAddress: StarknetAddress,
|
|
524
|
+
tokenAddress: StarknetAddress,
|
|
525
|
+
amount: bigint,
|
|
526
|
+
precommitment: bigint
|
|
527
|
+
): Promise<CallResult>;
|
|
528
|
+
approveAndDeposit(
|
|
529
|
+
entrypointAddress: StarknetAddress,
|
|
530
|
+
tokenAddress: StarknetAddress,
|
|
531
|
+
amount: bigint,
|
|
532
|
+
precommitment: bigint,
|
|
533
|
+
options: OptionModeSimulate
|
|
534
|
+
): Promise<SimulateTransaction>;
|
|
535
|
+
approveAndDeposit(
|
|
536
|
+
entrypointAddress: StarknetAddress,
|
|
537
|
+
tokenAddress: StarknetAddress,
|
|
538
|
+
amount: bigint,
|
|
539
|
+
precommitment: bigint,
|
|
540
|
+
options: OptionModeExecute
|
|
541
|
+
): Promise<TransactionResponse>;
|
|
542
|
+
async approveAndDeposit(
|
|
543
|
+
entrypointAddress: StarknetAddress,
|
|
544
|
+
tokenAddress: StarknetAddress,
|
|
545
|
+
amount: bigint,
|
|
546
|
+
precommitment: bigint,
|
|
547
|
+
options?: OptionModes
|
|
548
|
+
): Promise<CallResult> {
|
|
421
549
|
const assetConfig = await this.entrypoint.assetConfig(tokenAddress);
|
|
422
550
|
const minimumDepositAmount = castBigInt(assetConfig.minimumDepositAmount);
|
|
423
551
|
if (amount < minimumDepositAmount) {
|
|
@@ -429,13 +557,27 @@ export class SNContractInteractionsService {
|
|
|
429
557
|
}
|
|
430
558
|
|
|
431
559
|
transferERC20(tokenAddress: StarknetAddress, to: StarknetAddress, amount: bigint): Promise<CallResult>;
|
|
432
|
-
transferERC20(
|
|
433
|
-
|
|
434
|
-
|
|
560
|
+
transferERC20(
|
|
561
|
+
tokenAddress: StarknetAddress,
|
|
562
|
+
to: StarknetAddress,
|
|
563
|
+
amount: bigint,
|
|
564
|
+
options: OptionModeSimulate
|
|
565
|
+
): Promise<SimulateTransaction>;
|
|
566
|
+
transferERC20(
|
|
567
|
+
tokenAddress: StarknetAddress,
|
|
568
|
+
to: StarknetAddress,
|
|
569
|
+
amount: bigint,
|
|
570
|
+
options: OptionModeExecute
|
|
571
|
+
): Promise<TransactionResponse>;
|
|
572
|
+
async transferERC20(
|
|
573
|
+
tokenAddress: StarknetAddress,
|
|
574
|
+
to: StarknetAddress,
|
|
575
|
+
amount: bigint,
|
|
576
|
+
options?: OptionModes
|
|
577
|
+
): Promise<CallResult> {
|
|
435
578
|
const callTransfer = this.erc20(tokenAddress).populate("transfer", [to, amount]);
|
|
436
579
|
return _intentOptionWrapper([callTransfer], options && { ...options, account: this.providerOrAccount });
|
|
437
580
|
}
|
|
438
|
-
|
|
439
581
|
}
|
|
440
582
|
|
|
441
583
|
export class AdminContractInteractions {
|
|
@@ -444,12 +586,51 @@ export class AdminContractInteractions {
|
|
|
444
586
|
this.entrypoint = contractService.entrypoint;
|
|
445
587
|
}
|
|
446
588
|
|
|
447
|
-
registerPool(
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
589
|
+
registerPool(
|
|
590
|
+
asset: StarknetAddress,
|
|
591
|
+
pool: StarknetAddress,
|
|
592
|
+
minimumDepositAmount: bigint,
|
|
593
|
+
vettingFeeBPS: bigint,
|
|
594
|
+
maxRelayFeeBPS: bigint
|
|
595
|
+
): Promise<Call>;
|
|
596
|
+
registerPool(
|
|
597
|
+
asset: StarknetAddress,
|
|
598
|
+
pool: StarknetAddress,
|
|
599
|
+
minimumDepositAmount: bigint,
|
|
600
|
+
vettingFeeBPS: bigint,
|
|
601
|
+
maxRelayFeeBPS: bigint,
|
|
602
|
+
options: OptionModeSimulate
|
|
603
|
+
): Promise<SimulateTransaction>;
|
|
604
|
+
registerPool(
|
|
605
|
+
asset: StarknetAddress,
|
|
606
|
+
pool: StarknetAddress,
|
|
607
|
+
minimumDepositAmount: bigint,
|
|
608
|
+
vettingFeeBPS: bigint,
|
|
609
|
+
maxRelayFeeBPS: bigint,
|
|
610
|
+
options: OptionModeExecute
|
|
611
|
+
): Promise<InvokeFunctionResponse>;
|
|
612
|
+
async registerPool(
|
|
613
|
+
asset: StarknetAddress,
|
|
614
|
+
pool: StarknetAddress,
|
|
615
|
+
minimumDepositAmount: bigint,
|
|
616
|
+
vettingFeeBPS: bigint,
|
|
617
|
+
maxRelayFeeBPS: bigint,
|
|
618
|
+
options?: OptionModes
|
|
619
|
+
) {
|
|
620
|
+
const call = this.entrypoint.populate("registerPool", [
|
|
621
|
+
asset,
|
|
622
|
+
pool,
|
|
623
|
+
minimumDepositAmount,
|
|
624
|
+
vettingFeeBPS,
|
|
625
|
+
maxRelayFeeBPS,
|
|
626
|
+
]);
|
|
627
|
+
return _intentOptionWrapper(
|
|
628
|
+
call,
|
|
629
|
+
options && {
|
|
630
|
+
...options,
|
|
631
|
+
account: this.contractService.providerOrAccount,
|
|
632
|
+
}
|
|
633
|
+
);
|
|
453
634
|
}
|
|
454
635
|
|
|
455
636
|
updateRoot(root: bigint, ipfsCID: string): Promise<Call>;
|
|
@@ -458,7 +639,13 @@ export class AdminContractInteractions {
|
|
|
458
639
|
async updateRoot(root: bigint, ipfsCID: string, options?: OptionModes) {
|
|
459
640
|
_assertIpfsCID(ipfsCID);
|
|
460
641
|
const call = this.entrypoint.populate("updateRoot", [root, ipfsCID]);
|
|
461
|
-
return _intentOptionWrapper(
|
|
642
|
+
return _intentOptionWrapper(
|
|
643
|
+
call,
|
|
644
|
+
options && {
|
|
645
|
+
...options,
|
|
646
|
+
account: this.contractService.providerOrAccount,
|
|
647
|
+
}
|
|
648
|
+
);
|
|
462
649
|
}
|
|
463
650
|
|
|
464
651
|
removePool(asset: StarknetAddress): Promise<Call>;
|
|
@@ -466,15 +653,55 @@ export class AdminContractInteractions {
|
|
|
466
653
|
removePool(asset: StarknetAddress, options: OptionModeExecute): Promise<InvokeFunctionResponse>;
|
|
467
654
|
async removePool(asset: StarknetAddress, options?: OptionModes) {
|
|
468
655
|
const call = this.entrypoint.populate("removePool", [asset]);
|
|
469
|
-
return _intentOptionWrapper(
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
656
|
+
return _intentOptionWrapper(
|
|
657
|
+
call,
|
|
658
|
+
options && {
|
|
659
|
+
...options,
|
|
660
|
+
account: this.contractService.providerOrAccount,
|
|
661
|
+
}
|
|
662
|
+
);
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
updatePoolConfiguration(
|
|
666
|
+
asset: StarknetAddress,
|
|
667
|
+
minimumDepositAmount: bigint,
|
|
668
|
+
vettingFeeBPS: bigint,
|
|
669
|
+
maxRelayFeeBPS: bigint
|
|
670
|
+
): Promise<Call>;
|
|
671
|
+
updatePoolConfiguration(
|
|
672
|
+
asset: StarknetAddress,
|
|
673
|
+
minimumDepositAmount: bigint,
|
|
674
|
+
vettingFeeBPS: bigint,
|
|
675
|
+
maxRelayFeeBPS: bigint,
|
|
676
|
+
options: OptionModeSimulate
|
|
677
|
+
): Promise<SimulateTransaction>;
|
|
678
|
+
updatePoolConfiguration(
|
|
679
|
+
asset: StarknetAddress,
|
|
680
|
+
minimumDepositAmount: bigint,
|
|
681
|
+
vettingFeeBPS: bigint,
|
|
682
|
+
maxRelayFeeBPS: bigint,
|
|
683
|
+
options: OptionModeExecute
|
|
684
|
+
): Promise<InvokeFunctionResponse>;
|
|
685
|
+
async updatePoolConfiguration(
|
|
686
|
+
asset: StarknetAddress,
|
|
687
|
+
minimumDepositAmount: bigint,
|
|
688
|
+
vettingFeeBPS: bigint,
|
|
689
|
+
maxRelayFeeBPS: bigint,
|
|
690
|
+
options?: OptionModes
|
|
691
|
+
) {
|
|
692
|
+
const call = this.entrypoint.populate("updatePoolConfiguration", [
|
|
693
|
+
asset,
|
|
694
|
+
minimumDepositAmount,
|
|
695
|
+
vettingFeeBPS,
|
|
696
|
+
maxRelayFeeBPS,
|
|
697
|
+
]);
|
|
698
|
+
return _intentOptionWrapper(
|
|
699
|
+
call,
|
|
700
|
+
options && {
|
|
701
|
+
...options,
|
|
702
|
+
account: this.contractService.providerOrAccount,
|
|
703
|
+
}
|
|
704
|
+
);
|
|
478
705
|
}
|
|
479
706
|
|
|
480
707
|
windDownPool(pool: StarknetAddress): Promise<Call>;
|
|
@@ -482,15 +709,35 @@ export class AdminContractInteractions {
|
|
|
482
709
|
windDownPool(pool: StarknetAddress, options: OptionModeExecute): Promise<InvokeFunctionResponse>;
|
|
483
710
|
async windDownPool(pool: StarknetAddress, options?: OptionModes) {
|
|
484
711
|
const call = this.entrypoint.populate("windDownPool", [pool]);
|
|
485
|
-
return _intentOptionWrapper(
|
|
712
|
+
return _intentOptionWrapper(
|
|
713
|
+
call,
|
|
714
|
+
options && {
|
|
715
|
+
...options,
|
|
716
|
+
account: this.contractService.providerOrAccount,
|
|
717
|
+
}
|
|
718
|
+
);
|
|
486
719
|
}
|
|
487
720
|
|
|
488
721
|
withdrawFees(asset: StarknetAddress, recipient: StarknetAddress): Promise<Call>;
|
|
489
|
-
withdrawFees(
|
|
490
|
-
|
|
722
|
+
withdrawFees(
|
|
723
|
+
asset: StarknetAddress,
|
|
724
|
+
recipient: StarknetAddress,
|
|
725
|
+
options: OptionModeSimulate
|
|
726
|
+
): Promise<SimulateTransaction>;
|
|
727
|
+
withdrawFees(
|
|
728
|
+
asset: StarknetAddress,
|
|
729
|
+
recipient: StarknetAddress,
|
|
730
|
+
options: OptionModeExecute
|
|
731
|
+
): Promise<InvokeFunctionResponse>;
|
|
491
732
|
async withdrawFees(asset: StarknetAddress, recipient: StarknetAddress, options?: OptionModes) {
|
|
492
733
|
const call = this.entrypoint.populate("withdrawFees", [asset, recipient]);
|
|
493
|
-
return _intentOptionWrapper(
|
|
734
|
+
return _intentOptionWrapper(
|
|
735
|
+
call,
|
|
736
|
+
options && {
|
|
737
|
+
...options,
|
|
738
|
+
account: this.contractService.providerOrAccount,
|
|
739
|
+
}
|
|
740
|
+
);
|
|
494
741
|
}
|
|
495
742
|
|
|
496
743
|
upgrade(newClassHash: string): Promise<Call>;
|
|
@@ -498,9 +745,14 @@ export class AdminContractInteractions {
|
|
|
498
745
|
upgrade(newClassHash: string, options: OptionModeExecute): Promise<InvokeFunctionResponse>;
|
|
499
746
|
async upgrade(newClassHash: string, options?: OptionModes) {
|
|
500
747
|
const call = this.entrypoint.populate("upgrade", [newClassHash]);
|
|
501
|
-
return _intentOptionWrapper(
|
|
748
|
+
return _intentOptionWrapper(
|
|
749
|
+
call,
|
|
750
|
+
options && {
|
|
751
|
+
...options,
|
|
752
|
+
account: this.contractService.providerOrAccount,
|
|
753
|
+
}
|
|
754
|
+
);
|
|
502
755
|
}
|
|
503
|
-
|
|
504
756
|
}
|
|
505
757
|
|
|
506
758
|
function _assertIpfsCID(ipfsCID: string) {
|
package/src/contracts/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./contracts.service.js"
|
|
2
|
-
export * from "./transactionHandler.js"
|
|
1
|
+
export * from "./contracts.service.js";
|
|
2
|
+
export * from "./transactionHandler.js";
|
|
@@ -1,20 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
AllowArray,
|
|
3
|
+
Call,
|
|
4
|
+
InvokeFunctionResponse,
|
|
5
|
+
Account as SNAccount,
|
|
6
|
+
SimulateTransaction,
|
|
7
|
+
TransactionType,
|
|
8
|
+
UniversalDetails,
|
|
9
|
+
} from "starknet";
|
|
2
10
|
import { SNContractError, StarknetSDKError } from "../errors/index.js";
|
|
3
11
|
import { parseContractError } from "../errors/contracts.errors.js";
|
|
4
12
|
|
|
5
13
|
export async function executeIntent(
|
|
6
|
-
account: SNAccount,
|
|
14
|
+
account: SNAccount,
|
|
15
|
+
calls: AllowArray<Call>,
|
|
16
|
+
transactionDetails?: UniversalDetails
|
|
7
17
|
): Promise<InvokeFunctionResponse> {
|
|
8
18
|
const sim = await simulateIntent(account, calls);
|
|
9
19
|
return account.execute(calls, { ...sim, ...(transactionDetails || {}) });
|
|
10
20
|
}
|
|
11
21
|
|
|
12
22
|
export async function simulateIntent(
|
|
13
|
-
account: SNAccount,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
]);
|
|
23
|
+
account: SNAccount,
|
|
24
|
+
calls: AllowArray<Call>
|
|
25
|
+
): Promise<Omit<SimulateTransaction, "fee_estimation">> {
|
|
26
|
+
const simRes = await account.simulateTransaction([{ type: TransactionType.INVOKE, payload: calls }]);
|
|
18
27
|
|
|
19
28
|
const sim = simRes[0];
|
|
20
29
|
|