@fatsolutions/privacy-pools-core-starknet-sdk 0.0.44 → 0.0.45
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
package/src/data.service.ts
CHANGED
|
@@ -1,46 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
Hash,
|
|
4
|
-
PoolInfo,
|
|
5
|
-
RagequitEvent,
|
|
6
|
-
WithdrawalEvent,
|
|
7
|
-
} from "@0xbow/privacy-pools-core-sdk";
|
|
8
|
-
import {
|
|
9
|
-
AbiParser2,
|
|
10
|
-
EmittedEvent,
|
|
11
|
-
EventFilter,
|
|
12
|
-
RpcProvider,
|
|
13
|
-
events,
|
|
14
|
-
hash,
|
|
15
|
-
num,
|
|
16
|
-
} from "starknet";
|
|
1
|
+
import { DepositEvent, Hash, PoolInfo, RagequitEvent, WithdrawalEvent } from "@0xbow/privacy-pools-core-sdk";
|
|
2
|
+
import { AbiParser2, EventFilter, RPC, RpcProvider, events, hash, num } from "starknet";
|
|
17
3
|
import { PrivacyPoolABI } from "./abis/PrivacyPool.abi.js";
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
4
|
+
import { AuditEvent } from "./auditor.js";
|
|
5
|
+
import { SNBaseErrorCode, SNDataError, StarknetSDKError } from "./errors/index.js";
|
|
6
|
+
|
|
7
|
+
type StarknetEventChunk = RPC.RPCSPEC010.EVENTS_CHUNK;
|
|
8
|
+
type StarknetEmittedEvent = RPC.RPCSPEC010.EmittedEvent;
|
|
23
9
|
|
|
24
10
|
// Calculate event selectors using Starknet keccak
|
|
25
|
-
export const DEPOSIT_EVENT_SELECTOR = num.toHex(
|
|
26
|
-
|
|
27
|
-
); //
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
); // 0x36a4d15ab9e146faab90d4abc1c0cad17c4ded24551c781ba100392b5a70248
|
|
31
|
-
export const RAGEQUIT_EVENT_SELECTOR = num.toHex(
|
|
32
|
-
hash.starknetKeccak("RageQuit")
|
|
33
|
-
); // 0x2a2469e4569da9d3c3df9bc1a2ddece1e640a89b8ecd537da96f064d64c8183
|
|
11
|
+
export const DEPOSIT_EVENT_SELECTOR = num.toHex(hash.starknetKeccak("Deposited")); // 0x69105484e3b5f553164aa6de1f67321ea2757275a5e614365c90b9ed0a5e9b
|
|
12
|
+
export const WITHDRAWAL_EVENT_SELECTOR = num.toHex(hash.starknetKeccak("Withdrawn")); // 0x36a4d15ab9e146faab90d4abc1c0cad17c4ded24551c781ba100392b5a70248
|
|
13
|
+
export const RAGEQUIT_EVENT_SELECTOR = num.toHex(hash.starknetKeccak("RageQuit")); // 0x2a2469e4569da9d3c3df9bc1a2ddece1e640a89b8ecd537da96f064d64c8183
|
|
14
|
+
|
|
15
|
+
export const AUDIT_EVENT_SELECTOR = num.toHex(hash.starknetKeccak("AuditEvent"));
|
|
34
16
|
|
|
35
17
|
// ABI event names for direct selection
|
|
36
18
|
export const DEPOSIT_EVENT_ABI_NAME = "privacy_pools::interfaces::IPool::Deposited";
|
|
37
19
|
export const WITHDRAWAL_EVENT_ABI_NAME = "privacy_pools::interfaces::IPool::Withdrawn";
|
|
38
20
|
export const RAGEQUIT_EVENT_ABI_NAME = "privacy_pools::interfaces::IPool::RageQuit";
|
|
21
|
+
export const AUDIT_EVENT_ABI_NAME = "privacy_pools::interfaces::IPool::AuditEvent";
|
|
39
22
|
|
|
40
23
|
export const AbiEventName = {
|
|
41
24
|
Deposit: DEPOSIT_EVENT_ABI_NAME,
|
|
42
25
|
Withdraw: WITHDRAWAL_EVENT_ABI_NAME,
|
|
43
26
|
Ragequit: RAGEQUIT_EVENT_ABI_NAME,
|
|
27
|
+
Audit: AUDIT_EVENT_ABI_NAME,
|
|
44
28
|
} as const;
|
|
45
29
|
|
|
46
30
|
type AbiEventName = (typeof AbiEventName)[keyof typeof AbiEventName];
|
|
@@ -59,6 +43,7 @@ export interface StarknetWithdrawnEventData {
|
|
|
59
43
|
newCommitmentHash: bigint;
|
|
60
44
|
withdrawnValue: bigint;
|
|
61
45
|
existingNullifierHash: bigint;
|
|
46
|
+
auditorData: string;
|
|
62
47
|
}
|
|
63
48
|
|
|
64
49
|
export interface StarknetRageQuitEventData {
|
|
@@ -68,15 +53,24 @@ export interface StarknetRageQuitEventData {
|
|
|
68
53
|
value: bigint;
|
|
69
54
|
}
|
|
70
55
|
|
|
56
|
+
export interface StarknetAuditEventData {
|
|
57
|
+
tag: bigint;
|
|
58
|
+
ciphertext: string;
|
|
59
|
+
prevNullifierHash: bigint;
|
|
60
|
+
newCommitment: bigint;
|
|
61
|
+
}
|
|
62
|
+
|
|
71
63
|
type AbiToEvent = {
|
|
72
64
|
[AbiEventName.Deposit]: StarknetDepositedEventData;
|
|
73
65
|
[AbiEventName.Withdraw]: StarknetWithdrawnEventData;
|
|
74
66
|
[AbiEventName.Ragequit]: StarknetRageQuitEventData;
|
|
67
|
+
[AbiEventName.Audit]: StarknetAuditEventData;
|
|
75
68
|
};
|
|
76
69
|
|
|
77
70
|
export type StarknetEvent =
|
|
78
71
|
| StarknetDepositedEventData
|
|
79
72
|
| StarknetWithdrawnEventData
|
|
73
|
+
| StarknetAuditEventData
|
|
80
74
|
| StarknetRageQuitEventData;
|
|
81
75
|
|
|
82
76
|
/**
|
|
@@ -101,12 +95,12 @@ export class StarknetDataService {
|
|
|
101
95
|
}
|
|
102
96
|
|
|
103
97
|
private async getEvents(eventFilter: EventFilter) {
|
|
104
|
-
let { continuation_token, events } = await this.provider.getEvents(
|
|
105
|
-
eventFilter
|
|
106
|
-
);
|
|
98
|
+
let { continuation_token, events } = (await this.provider.getEvents(eventFilter)) as StarknetEventChunk;
|
|
107
99
|
while (continuation_token) {
|
|
108
|
-
const { continuation_token: newToken, events: newEvents } =
|
|
109
|
-
|
|
100
|
+
const { continuation_token: newToken, events: newEvents } = (await this.provider.getEvents({
|
|
101
|
+
...eventFilter,
|
|
102
|
+
continuation_token,
|
|
103
|
+
})) as StarknetEventChunk;
|
|
110
104
|
events = [...events, ...newEvents];
|
|
111
105
|
continuation_token = newToken;
|
|
112
106
|
}
|
|
@@ -121,58 +115,45 @@ export class StarknetDataService {
|
|
|
121
115
|
* @returns Array of deposit events compatible with AccountService interface
|
|
122
116
|
* @throws {StarknetSDKError} If provider is not configured or network error occurs
|
|
123
117
|
*/
|
|
124
|
-
async getDeposits(
|
|
125
|
-
pool: PoolInfo,
|
|
126
|
-
fromBlock: bigint = pool.deploymentBlock
|
|
127
|
-
): Promise<DepositEvent[]> {
|
|
118
|
+
async getDeposits(pool: PoolInfo, fromBlock: bigint = pool.deploymentBlock, label?: bigint): Promise<DepositEvent[]> {
|
|
128
119
|
try {
|
|
120
|
+
const keys = label ? [[DEPOSIT_EVENT_SELECTOR], [], [String(label)]] : [[DEPOSIT_EVENT_SELECTOR]];
|
|
129
121
|
// Fetch events using Starknet provider
|
|
130
122
|
const eventsResult = await this.getEvents({
|
|
131
123
|
from_block: { block_number: Number(fromBlock) },
|
|
132
124
|
to_block: "latest",
|
|
133
125
|
address: pool.address,
|
|
134
|
-
keys
|
|
126
|
+
keys, // Filter by deposit event selector
|
|
135
127
|
chunk_size: 1000, // Starknet pagination
|
|
136
128
|
});
|
|
137
129
|
|
|
138
130
|
// Parse all events at once using starknet.js event parser
|
|
139
131
|
const abiEvents = events.getAbiEvents(PrivacyPoolABI);
|
|
140
|
-
const parsedEvents = events.parseEvents(
|
|
141
|
-
eventsResult,
|
|
142
|
-
abiEvents,
|
|
143
|
-
{},
|
|
144
|
-
{},
|
|
145
|
-
this.abiParser
|
|
146
|
-
);
|
|
132
|
+
const parsedEvents = events.parseEvents(eventsResult, abiEvents, {}, {}, this.abiParser);
|
|
147
133
|
|
|
148
134
|
return parsedEvents
|
|
149
|
-
.filter(
|
|
150
|
-
(parsedEvent) => parsedEvent[DEPOSIT_EVENT_ABI_NAME] !== undefined
|
|
151
|
-
)
|
|
135
|
+
.filter((parsedEvent) => parsedEvent[DEPOSIT_EVENT_ABI_NAME] !== undefined)
|
|
152
136
|
.map((parsedEvent) => ({
|
|
153
|
-
eventData: parsedEvent[
|
|
154
|
-
DEPOSIT_EVENT_ABI_NAME
|
|
155
|
-
] as unknown as StarknetDepositedEventData,
|
|
137
|
+
eventData: parsedEvent[DEPOSIT_EVENT_ABI_NAME] as unknown as StarknetDepositedEventData,
|
|
156
138
|
blockNumber: parsedEvent.block_number,
|
|
157
139
|
transactionHash: parsedEvent.transaction_hash,
|
|
158
140
|
}))
|
|
159
141
|
.map(
|
|
160
142
|
({ eventData, blockNumber, transactionHash }) =>
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
143
|
+
({
|
|
144
|
+
depositor: num.toHex(eventData.depositor),
|
|
145
|
+
commitment: eventData.commitment as Hash,
|
|
146
|
+
label: eventData.label as Hash,
|
|
147
|
+
value: eventData.value,
|
|
148
|
+
precommitment: eventData.preCommitmentHash as Hash,
|
|
149
|
+
blockNumber: BigInt(blockNumber || 0),
|
|
150
|
+
transactionHash: transactionHash || "0x0",
|
|
151
|
+
}) as DepositEvent
|
|
170
152
|
);
|
|
171
153
|
} catch (error) {
|
|
172
154
|
if (error instanceof StarknetSDKError) throw error;
|
|
173
155
|
throw new StarknetSDKError(
|
|
174
|
-
`Failed to fetch deposits: ${error instanceof Error ? error.message : "Unknown error"
|
|
175
|
-
}`,
|
|
156
|
+
`Failed to fetch deposits: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
176
157
|
SNBaseErrorCode.UNKNOWN
|
|
177
158
|
);
|
|
178
159
|
}
|
|
@@ -186,10 +167,7 @@ export class StarknetDataService {
|
|
|
186
167
|
* @returns Array of withdrawal events compatible with AccountService interface
|
|
187
168
|
* @throws {StarknetSDKError} If provider is not configured or network error occurs
|
|
188
169
|
*/
|
|
189
|
-
async getWithdrawals(
|
|
190
|
-
pool: PoolInfo,
|
|
191
|
-
fromBlock: bigint = pool.deploymentBlock
|
|
192
|
-
): Promise<WithdrawalEvent[]> {
|
|
170
|
+
async getWithdrawals(pool: PoolInfo, fromBlock: bigint = pool.deploymentBlock): Promise<WithdrawalEvent[]> {
|
|
193
171
|
try {
|
|
194
172
|
const eventsResult = await this.getEvents({
|
|
195
173
|
from_block: { block_number: Number(fromBlock) },
|
|
@@ -201,40 +179,29 @@ export class StarknetDataService {
|
|
|
201
179
|
|
|
202
180
|
// Parse all events at once using starknet.js event parser
|
|
203
181
|
const abiEvents = events.getAbiEvents(PrivacyPoolABI);
|
|
204
|
-
const parsedEvents = events.parseEvents(
|
|
205
|
-
eventsResult,
|
|
206
|
-
abiEvents,
|
|
207
|
-
{},
|
|
208
|
-
{},
|
|
209
|
-
this.abiParser
|
|
210
|
-
);
|
|
182
|
+
const parsedEvents = events.parseEvents(eventsResult, abiEvents, {}, {}, this.abiParser);
|
|
211
183
|
|
|
212
184
|
return parsedEvents
|
|
213
|
-
.filter(
|
|
214
|
-
(parsedEvent) => parsedEvent[WITHDRAWAL_EVENT_ABI_NAME] !== undefined
|
|
215
|
-
)
|
|
185
|
+
.filter((parsedEvent) => parsedEvent[WITHDRAWAL_EVENT_ABI_NAME] !== undefined)
|
|
216
186
|
.map((parsedEvent) => ({
|
|
217
|
-
eventData: parsedEvent[
|
|
218
|
-
WITHDRAWAL_EVENT_ABI_NAME
|
|
219
|
-
] as unknown as StarknetWithdrawnEventData,
|
|
187
|
+
eventData: parsedEvent[WITHDRAWAL_EVENT_ABI_NAME] as unknown as StarknetWithdrawnEventData,
|
|
220
188
|
blockNumber: parsedEvent.block_number,
|
|
221
189
|
transactionHash: parsedEvent.transaction_hash,
|
|
222
190
|
}))
|
|
223
191
|
.map(
|
|
224
192
|
({ eventData, blockNumber, transactionHash }) =>
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
193
|
+
({
|
|
194
|
+
withdrawn: eventData.withdrawnValue,
|
|
195
|
+
spentNullifier: eventData.existingNullifierHash as Hash,
|
|
196
|
+
newCommitment: eventData.newCommitmentHash as Hash,
|
|
197
|
+
blockNumber: BigInt(blockNumber || 0),
|
|
198
|
+
transactionHash: transactionHash || "0x0",
|
|
199
|
+
}) as WithdrawalEvent
|
|
232
200
|
);
|
|
233
201
|
} catch (error) {
|
|
234
202
|
if (error instanceof StarknetSDKError) throw error;
|
|
235
203
|
throw new StarknetSDKError(
|
|
236
|
-
`Failed to fetch withdrawals: ${error instanceof Error ? error.message : "Unknown error"
|
|
237
|
-
}`,
|
|
204
|
+
`Failed to fetch withdrawals: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
238
205
|
SNBaseErrorCode.UNKNOWN
|
|
239
206
|
);
|
|
240
207
|
}
|
|
@@ -248,10 +215,7 @@ export class StarknetDataService {
|
|
|
248
215
|
* @returns Array of ragequit events compatible with AccountService interface
|
|
249
216
|
* @throws {StarknetSDKError} If provider is not configured or network error occurs
|
|
250
217
|
*/
|
|
251
|
-
async getRagequits(
|
|
252
|
-
pool: PoolInfo,
|
|
253
|
-
fromBlock: bigint = pool.deploymentBlock
|
|
254
|
-
): Promise<RagequitEvent[]> {
|
|
218
|
+
async getRagequits(pool: PoolInfo, fromBlock: bigint = pool.deploymentBlock): Promise<RagequitEvent[]> {
|
|
255
219
|
try {
|
|
256
220
|
const eventsResult = await this.getEvents({
|
|
257
221
|
from_block: { block_number: Number(fromBlock) },
|
|
@@ -263,41 +227,71 @@ export class StarknetDataService {
|
|
|
263
227
|
|
|
264
228
|
// Parse all events at once using starknet.js event parser
|
|
265
229
|
const abiEvents = events.getAbiEvents(PrivacyPoolABI);
|
|
266
|
-
const parsedEvents = events.parseEvents(
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
{
|
|
271
|
-
|
|
230
|
+
const parsedEvents = events.parseEvents(eventsResult, abiEvents, {}, {}, this.abiParser);
|
|
231
|
+
|
|
232
|
+
return parsedEvents
|
|
233
|
+
.filter((parsedEvent) => parsedEvent[RAGEQUIT_EVENT_ABI_NAME] !== undefined)
|
|
234
|
+
.map((parsedEvent) => ({
|
|
235
|
+
eventData: parsedEvent[RAGEQUIT_EVENT_ABI_NAME] as unknown as StarknetRageQuitEventData,
|
|
236
|
+
blockNumber: parsedEvent.block_number,
|
|
237
|
+
transactionHash: parsedEvent.transaction_hash,
|
|
238
|
+
}))
|
|
239
|
+
.map(
|
|
240
|
+
({ eventData, blockNumber, transactionHash }) =>
|
|
241
|
+
({
|
|
242
|
+
ragequitter: num.toHex(eventData.depositor),
|
|
243
|
+
commitment: eventData.commitment as Hash,
|
|
244
|
+
label: eventData.label as Hash,
|
|
245
|
+
value: eventData.value,
|
|
246
|
+
blockNumber: BigInt(blockNumber || 0),
|
|
247
|
+
transactionHash: transactionHash || "0x0",
|
|
248
|
+
}) as RagequitEvent
|
|
249
|
+
);
|
|
250
|
+
} catch (error) {
|
|
251
|
+
if (error instanceof StarknetSDKError) throw error;
|
|
252
|
+
throw new StarknetSDKError(
|
|
253
|
+
`Failed to fetch ragequits: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
254
|
+
SNBaseErrorCode.UNKNOWN
|
|
272
255
|
);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async getAuditEventForTag(tag: bigint, pool: PoolInfo, fromBlock: bigint = pool.deploymentBlock) {
|
|
260
|
+
try {
|
|
261
|
+
const eventsResult = await this.getEvents({
|
|
262
|
+
from_block: { block_number: Number(fromBlock) },
|
|
263
|
+
to_block: "latest",
|
|
264
|
+
address: pool.address,
|
|
265
|
+
keys: [[AUDIT_EVENT_SELECTOR], [String(tag)]],
|
|
266
|
+
chunk_size: 1000,
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
// Parse all events at once using starknet.js event parser
|
|
270
|
+
const abiEvents = events.getAbiEvents(PrivacyPoolABI);
|
|
271
|
+
const parsedEvents = events.parseEvents(eventsResult, abiEvents, {}, {}, this.abiParser);
|
|
273
272
|
|
|
274
273
|
return parsedEvents
|
|
275
|
-
.filter(
|
|
276
|
-
(parsedEvent) => parsedEvent[RAGEQUIT_EVENT_ABI_NAME] !== undefined
|
|
277
|
-
)
|
|
274
|
+
.filter((parsedEvent) => parsedEvent[AUDIT_EVENT_ABI_NAME] !== undefined)
|
|
278
275
|
.map((parsedEvent) => ({
|
|
279
|
-
eventData: parsedEvent[
|
|
280
|
-
RAGEQUIT_EVENT_ABI_NAME
|
|
281
|
-
] as unknown as StarknetRageQuitEventData,
|
|
276
|
+
eventData: parsedEvent[AUDIT_EVENT_ABI_NAME] as unknown as StarknetAuditEventData,
|
|
282
277
|
blockNumber: parsedEvent.block_number,
|
|
283
278
|
transactionHash: parsedEvent.transaction_hash,
|
|
284
279
|
}))
|
|
285
280
|
.map(
|
|
286
281
|
({ eventData, blockNumber, transactionHash }) =>
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
282
|
+
({
|
|
283
|
+
tag: eventData.tag as Hash,
|
|
284
|
+
ciphertext: eventData.ciphertext,
|
|
285
|
+
prevNullifierHash: eventData.prevNullifierHash as Hash,
|
|
286
|
+
newCommitment: eventData.newCommitment as Hash,
|
|
287
|
+
blockNumber: BigInt(blockNumber || 0),
|
|
288
|
+
transactionHash: transactionHash || "0x0",
|
|
289
|
+
}) as AuditEvent
|
|
295
290
|
);
|
|
296
291
|
} catch (error) {
|
|
297
292
|
if (error instanceof StarknetSDKError) throw error;
|
|
298
293
|
throw new StarknetSDKError(
|
|
299
|
-
`Failed to fetch ragequits: ${error instanceof Error ? error.message : "Unknown error"
|
|
300
|
-
}`,
|
|
294
|
+
`Failed to fetch ragequits: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
301
295
|
SNBaseErrorCode.UNKNOWN
|
|
302
296
|
);
|
|
303
297
|
}
|
|
@@ -305,14 +299,12 @@ export class StarknetDataService {
|
|
|
305
299
|
|
|
306
300
|
private static parseGenericEvents<K extends AbiEventName>(
|
|
307
301
|
abiEventName: K,
|
|
308
|
-
emittedEvents:
|
|
302
|
+
emittedEvents: StarknetEmittedEvent[],
|
|
309
303
|
pool: PoolInfo
|
|
310
304
|
) {
|
|
311
305
|
const poolAbiEvents = events.getAbiEvents(PrivacyPoolABI);
|
|
312
306
|
const parsedEvents = events.parseEvents(
|
|
313
|
-
emittedEvents.filter(
|
|
314
|
-
(e) => num.toBigInt(e.from_address) === num.toBigInt(pool.address)
|
|
315
|
-
),
|
|
307
|
+
emittedEvents.filter((e) => num.toBigInt(e.from_address) === num.toBigInt(pool.address)),
|
|
316
308
|
poolAbiEvents,
|
|
317
309
|
{},
|
|
318
310
|
{},
|
|
@@ -330,28 +322,16 @@ export class StarknetDataService {
|
|
|
330
322
|
});
|
|
331
323
|
}
|
|
332
324
|
|
|
333
|
-
static parseDepositEvents(emittedEvents:
|
|
334
|
-
return StarknetDataService.parseGenericEvents(
|
|
335
|
-
AbiEventName.Deposit,
|
|
336
|
-
emittedEvents,
|
|
337
|
-
pool
|
|
338
|
-
);
|
|
325
|
+
static parseDepositEvents(emittedEvents: StarknetEmittedEvent[], pool: PoolInfo) {
|
|
326
|
+
return StarknetDataService.parseGenericEvents(AbiEventName.Deposit, emittedEvents, pool);
|
|
339
327
|
}
|
|
340
328
|
|
|
341
|
-
static parseWithdrawalEvents(emittedEvents:
|
|
342
|
-
return StarknetDataService.parseGenericEvents(
|
|
343
|
-
AbiEventName.Withdraw,
|
|
344
|
-
emittedEvents,
|
|
345
|
-
pool
|
|
346
|
-
);
|
|
329
|
+
static parseWithdrawalEvents(emittedEvents: StarknetEmittedEvent[], pool: PoolInfo) {
|
|
330
|
+
return StarknetDataService.parseGenericEvents(AbiEventName.Withdraw, emittedEvents, pool);
|
|
347
331
|
}
|
|
348
332
|
|
|
349
|
-
static parseRagequitEvents(emittedEvents:
|
|
350
|
-
return StarknetDataService.parseGenericEvents(
|
|
351
|
-
AbiEventName.Ragequit,
|
|
352
|
-
emittedEvents,
|
|
353
|
-
pool
|
|
354
|
-
);
|
|
333
|
+
static parseRagequitEvents(emittedEvents: StarknetEmittedEvent[], pool: PoolInfo) {
|
|
334
|
+
return StarknetDataService.parseGenericEvents(AbiEventName.Ragequit, emittedEvents, pool);
|
|
355
335
|
}
|
|
356
336
|
|
|
357
337
|
async getTxEvents<K extends AbiEventName>(
|
|
@@ -360,21 +340,18 @@ export class StarknetDataService {
|
|
|
360
340
|
pool: PoolInfo
|
|
361
341
|
): Promise<AbiToEvent[K][]> {
|
|
362
342
|
const receipt = await this.provider.getTransactionReceipt(transactionHash);
|
|
363
|
-
if (!receipt.isSuccess())
|
|
364
|
-
throw SNDataError.noEventsToParse("Tx was not succesful");
|
|
343
|
+
if (!receipt.isSuccess()) throw SNDataError.noEventsToParse("Tx was not succesful");
|
|
365
344
|
|
|
366
|
-
const emmitedEvents:
|
|
345
|
+
const emmitedEvents: StarknetEmittedEvent[] = receipt.value.events.map((e, event_index) => {
|
|
367
346
|
return {
|
|
368
347
|
...e,
|
|
369
348
|
block_hash: receipt.value.block_hash,
|
|
370
349
|
block_number: receipt.value.block_number,
|
|
371
350
|
transaction_hash: transactionHash,
|
|
351
|
+
event_index,
|
|
352
|
+
transaction_index: 0,
|
|
372
353
|
};
|
|
373
354
|
});
|
|
374
|
-
return StarknetDataService.parseGenericEvents<K>(
|
|
375
|
-
abiEventName,
|
|
376
|
-
emmitedEvents,
|
|
377
|
-
pool
|
|
378
|
-
);
|
|
355
|
+
return StarknetDataService.parseGenericEvents<K>(abiEventName, emmitedEvents, pool);
|
|
379
356
|
}
|
|
380
357
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Mapping of hexadecimal error codes to human-readable error messages.
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* These error codes correspond to custom errors thrown by Privacy Pool smart contracts
|
|
5
5
|
* on Starknet. The hex codes are the encoded error messages that appear in transaction
|
|
6
6
|
* failure reasons.
|
|
7
|
-
*
|
|
7
|
+
*
|
|
8
8
|
* @constant
|
|
9
9
|
*/
|
|
10
10
|
export const CONTRACT_ERROR_CODES = {
|
|
@@ -31,19 +31,19 @@ export const CONTRACT_ERROR_CODES = {
|
|
|
31
31
|
"0x506f6f6c206e6f742072656769737465726564": "Pool not registered",
|
|
32
32
|
"0x507265636f6d6d69746d656e742075736564": "Precommitment used",
|
|
33
33
|
"0x72656c617965722066656520544f2048494748": "relayer fee TO HIGH",
|
|
34
|
-
"0x56616c7565206c6573732074686174206d696e696d756d": "Value less that minimum"
|
|
34
|
+
"0x56616c7565206c6573732074686174206d696e696d756d": "Value less that minimum",
|
|
35
35
|
} as const;
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* Parses a contract error string to extract a human-readable error message.
|
|
39
|
-
*
|
|
39
|
+
*
|
|
40
40
|
* This function searches through the error string for known hexadecimal error codes
|
|
41
41
|
* and returns the corresponding human-readable description. This is useful for
|
|
42
42
|
* providing better error messages to users when transactions fail.
|
|
43
|
-
*
|
|
43
|
+
*
|
|
44
44
|
* @param errorString - The error string from a failed transaction
|
|
45
45
|
* @returns The human-readable error message if found, null otherwise
|
|
46
|
-
*
|
|
46
|
+
*
|
|
47
47
|
* @example
|
|
48
48
|
* ```typescript
|
|
49
49
|
* const error = "execution failed with error: 0x496e76616c69642050726f6f66";
|
package/src/errors/index.ts
CHANGED
|
@@ -1,32 +1,30 @@
|
|
|
1
|
-
|
|
2
1
|
/** Base error codes for fundamental SDK errors */
|
|
3
2
|
export enum SNBaseErrorCode {
|
|
4
3
|
UNKNOWN,
|
|
5
4
|
UNREACHABLE,
|
|
6
|
-
INTERNAL
|
|
5
|
+
INTERNAL,
|
|
7
6
|
}
|
|
8
7
|
|
|
9
8
|
/** Error codes specific to privacy pool validation */
|
|
10
9
|
export enum SNPoolErrorCode {
|
|
11
|
-
AMOUNT_TOO_SMALL
|
|
10
|
+
AMOUNT_TOO_SMALL,
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
/** Error codes for contract interaction failures */
|
|
15
14
|
export enum SNContractErrorCode {
|
|
16
15
|
DEPOSIT_FAILED,
|
|
17
16
|
INVALID_IPFS_CID,
|
|
18
|
-
REVERT
|
|
17
|
+
REVERT,
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
/** Error codes for data format and conversion issues */
|
|
22
21
|
export enum SNFormatErrorCode {
|
|
23
22
|
CONVERSION,
|
|
24
|
-
PARSE
|
|
23
|
+
PARSE,
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
|
|
28
26
|
export enum SNDataErrorCode {
|
|
29
|
-
NO_EVENTS
|
|
27
|
+
NO_EVENTS,
|
|
30
28
|
}
|
|
31
29
|
|
|
32
30
|
/** Union type of all possible error codes in the Starknet SDK */
|
|
@@ -34,22 +32,24 @@ export type SNErrorCode = SNBaseErrorCode | SNPoolErrorCode | SNContractErrorCod
|
|
|
34
32
|
|
|
35
33
|
/**
|
|
36
34
|
* Base error class for all Starknet SDK errors.
|
|
37
|
-
*
|
|
35
|
+
*
|
|
38
36
|
* This class extends the standard Error class and provides additional context
|
|
39
37
|
* through error codes. All SDK-specific errors should inherit from this class.
|
|
40
38
|
*/
|
|
41
39
|
export class StarknetSDKError extends Error {
|
|
42
|
-
|
|
43
40
|
override readonly name: string;
|
|
44
41
|
override message: string;
|
|
45
42
|
|
|
46
43
|
/**
|
|
47
44
|
* Creates a new StarknetSDKError.
|
|
48
|
-
*
|
|
45
|
+
*
|
|
49
46
|
* @param message - The error message
|
|
50
47
|
* @param code - The specific error code for categorization
|
|
51
48
|
*/
|
|
52
|
-
constructor(
|
|
49
|
+
constructor(
|
|
50
|
+
message: string,
|
|
51
|
+
readonly code: SNErrorCode
|
|
52
|
+
) {
|
|
53
53
|
super();
|
|
54
54
|
this.message = message;
|
|
55
55
|
this.name = this.constructor.name;
|
|
@@ -80,17 +80,15 @@ export class StarknetSDKError extends Error {
|
|
|
80
80
|
public static internal(msg?: string) {
|
|
81
81
|
return new this(msg || "Internal error", SNBaseErrorCode.INTERNAL);
|
|
82
82
|
}
|
|
83
|
-
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
/**
|
|
87
86
|
* Error class for data format and conversion issues.
|
|
88
|
-
*
|
|
87
|
+
*
|
|
89
88
|
* This error is thrown when data conversion operations fail, such as
|
|
90
89
|
* converting between different proof formats or parsing verification keys.
|
|
91
90
|
*/
|
|
92
91
|
export class SNFormatError extends StarknetSDKError {
|
|
93
|
-
|
|
94
92
|
/**
|
|
95
93
|
* Creates a conversion error instance.
|
|
96
94
|
* @param context - Optional context about what conversion failed
|
|
@@ -110,17 +108,15 @@ export class SNFormatError extends StarknetSDKError {
|
|
|
110
108
|
const _context = context || "Parse failed";
|
|
111
109
|
return new this(_context, SNFormatErrorCode.PARSE);
|
|
112
110
|
}
|
|
113
|
-
|
|
114
111
|
}
|
|
115
112
|
|
|
116
113
|
/**
|
|
117
114
|
* Error class for privacy pool validation failures.
|
|
118
|
-
*
|
|
115
|
+
*
|
|
119
116
|
* This error is thrown when privacy pool operations fail validation,
|
|
120
117
|
* such as insufficient deposit amounts or invalid pool parameters.
|
|
121
118
|
*/
|
|
122
119
|
export class SNPoolError extends StarknetSDKError {
|
|
123
|
-
|
|
124
120
|
/**
|
|
125
121
|
* Creates an error for deposit amounts that are too small.
|
|
126
122
|
* @param context - Optional context about the minimum amount requirement
|
|
@@ -130,17 +126,15 @@ export class SNPoolError extends StarknetSDKError {
|
|
|
130
126
|
const _context = context || "Amount is less than expected by pool";
|
|
131
127
|
return new this(_context, SNPoolErrorCode.AMOUNT_TOO_SMALL);
|
|
132
128
|
}
|
|
133
|
-
|
|
134
129
|
}
|
|
135
130
|
|
|
136
131
|
/**
|
|
137
132
|
* Error class for smart contract interaction failures.
|
|
138
|
-
*
|
|
133
|
+
*
|
|
139
134
|
* This error is thrown when contract calls fail or return unexpected results,
|
|
140
135
|
* including transaction reverts and invalid parameters.
|
|
141
136
|
*/
|
|
142
137
|
export class SNContractError extends StarknetSDKError {
|
|
143
|
-
|
|
144
138
|
/**
|
|
145
139
|
* Creates an error for failed deposit operations.
|
|
146
140
|
* @returns SNContractError with DEPOSIT_FAILED code
|
|
@@ -155,7 +149,10 @@ export class SNContractError extends StarknetSDKError {
|
|
|
155
149
|
* @returns SNContractError with INVALID_IPFS_CID code
|
|
156
150
|
*/
|
|
157
151
|
public static invalidIPFSsize(ipfsCID: string) {
|
|
158
|
-
return new this(
|
|
152
|
+
return new this(
|
|
153
|
+
`Invalid IPFS CID size: expected >32 & <64, got ${ipfsCID.length}`,
|
|
154
|
+
SNContractErrorCode.INVALID_IPFS_CID
|
|
155
|
+
);
|
|
159
156
|
}
|
|
160
157
|
|
|
161
158
|
/**
|
|
@@ -166,11 +163,9 @@ export class SNContractError extends StarknetSDKError {
|
|
|
166
163
|
public static revert(reason: string) {
|
|
167
164
|
return new this(reason, SNContractErrorCode.REVERT);
|
|
168
165
|
}
|
|
169
|
-
|
|
170
166
|
}
|
|
171
167
|
|
|
172
168
|
export class SNDataError extends StarknetSDKError {
|
|
173
|
-
|
|
174
169
|
/**
|
|
175
170
|
* Creates a conversion error instance.
|
|
176
171
|
* @param context - Optional context about what conversion failed
|
|
@@ -180,5 +175,4 @@ export class SNDataError extends StarknetSDKError {
|
|
|
180
175
|
const _context = context || "Tx may be incomplete";
|
|
181
176
|
return new this(_context, SNDataErrorCode.NO_EVENTS);
|
|
182
177
|
}
|
|
183
|
-
|
|
184
178
|
}
|
package/src/garaga.ts
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import { Groth16VerifyingKey, Groth16Proof } from "./types/garaga.js";
|
|
2
2
|
import * as garaga from "garaga";
|
|
3
3
|
|
|
4
|
-
let _initialized = false;
|
|
5
|
-
|
|
4
|
+
let _initialized: boolean = false;
|
|
5
|
+
let _error: null | Error = null;
|
|
6
|
+
garaga.init()
|
|
7
|
+
.then(() => _initialized = true)
|
|
8
|
+
.catch((e: Error) => _error = e);
|
|
6
9
|
|
|
7
10
|
function sleep(ms: number) {
|
|
8
|
-
return new Promise(res => setTimeout(res, ms));
|
|
11
|
+
return new Promise((res) => setTimeout(res, ms));
|
|
9
12
|
}
|
|
10
13
|
|
|
11
14
|
async function _waitUntilReady() {
|
|
12
|
-
while (!_initialized) {
|
|
15
|
+
while ((!_initialized) && (_error === null)) {
|
|
13
16
|
await sleep(100);
|
|
14
17
|
}
|
|
18
|
+
if (_error !== null) {
|
|
19
|
+
throw _error;
|
|
20
|
+
}
|
|
15
21
|
}
|
|
16
22
|
|
|
17
23
|
export async function getGroth16CallData(proof: Groth16Proof, verifyingKey: Groth16VerifyingKey) {
|