@imtbl/sdk 1.35.2-alpha → 1.35.3
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/blockchain_data.js +2 -2
- package/dist/browser/checkout/{BridgeWidget-22c8b08d.js → BridgeWidget-b9e736eb.js} +1 -1
- package/dist/browser/checkout/{OnRampWidget-aeb5d57c.js → OnRampWidget-08bfa49c.js} +1 -1
- package/dist/browser/checkout/{SaleWidget-93a4fffd.js → SaleWidget-62cda384.js} +1 -1
- package/dist/browser/checkout/{SpendingCapHero-8459b91d.js → SpendingCapHero-341cfc38.js} +1 -1
- package/dist/browser/checkout/{SwapWidget-11ecb4ae.js → SwapWidget-40adbff0.js} +1 -1
- package/dist/browser/checkout/{TopUpView-ad058510.js → TopUpView-17d237f3.js} +1 -1
- package/dist/browser/checkout/{WalletWidget-920b03b4.js → WalletWidget-a19ab89c.js} +1 -1
- package/dist/browser/checkout/{auto-track-469b3ba5.js → auto-track-ffcab507.js} +1 -1
- package/dist/browser/checkout/{balance-c9c03af5.js → balance-4d6f9b6f.js} +1 -1
- package/dist/browser/checkout/{index-06896b92.js → index-11eefc56.js} +1 -1
- package/dist/browser/checkout/{index-09b1efac.js → index-317dcefc.js} +1 -1
- package/dist/browser/checkout/{index-9997f064.js → index-4fb1863d.js} +1 -1
- package/dist/browser/checkout/{index-e5f07d9e.js → index-7a9fdf09.js} +2 -2
- package/dist/browser/checkout/{index-cbf7168d.js → index-9a663258.js} +1 -1
- package/dist/browser/checkout/{index-37c4003a.js → index-ab21662b.js} +1 -1
- package/dist/browser/checkout/index-bafd7f6d.js +1 -0
- package/dist/browser/checkout/{index-c53e5321.js → index-be2f6fa5.js} +1 -1
- package/dist/browser/checkout/{index.umd-e783a603.js → index.umd-cb823fd6.js} +1 -1
- package/dist/browser/checkout/{retry-10de11e8.js → retry-0002f89a.js} +1 -1
- package/dist/browser/checkout/sdk.js +4 -4
- package/dist/browser/checkout/widgets-esm.js +1 -1
- package/dist/browser/checkout/widgets.js +1 -1
- package/dist/checkout.d.ts +14 -2
- package/dist/checkout.js +18 -13
- package/dist/config.js +1 -1
- package/dist/index.browser.js +4 -4
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +89 -578
- package/dist/index.d.ts +21 -114
- package/dist/index.js +90 -577
- package/dist/orderbook.js +1 -1
- package/dist/passport.js +64 -55
- package/dist/x.js +3 -3
- package/package.json +1 -9
- package/dist/browser/checkout/index-1b8b7ce9.js +0 -1
- package/dist/minting_backend.d.ts +0 -3506
- package/dist/minting_backend.js +0 -447
- package/dist/webhook.d.ts +0 -11
- package/dist/webhook.js +0 -388
package/dist/minting_backend.js
DELETED
|
@@ -1,447 +0,0 @@
|
|
|
1
|
-
const mintingPersistence$1 = (client) => ({
|
|
2
|
-
recordMint: async (request) => {
|
|
3
|
-
const r = await client.query(`
|
|
4
|
-
INSERT INTO im_assets (asset_id, contract_address, owner_address, metadata)
|
|
5
|
-
VALUES ($1, $2, $3, $4) ON CONFLICT (asset_id) DO NOTHING;
|
|
6
|
-
`, [request.asset_id, request.contract_address, request.owner_address, request.metadata]);
|
|
7
|
-
if (r.rowCount === 0) {
|
|
8
|
-
throw new Error('Duplicated mint');
|
|
9
|
-
}
|
|
10
|
-
},
|
|
11
|
-
getNextBatchForSubmission: async (limit) => {
|
|
12
|
-
const res = await client.query(`
|
|
13
|
-
UPDATE im_assets SET minting_status = 'submitting' WHERE minting_status IS NULL and id in (
|
|
14
|
-
select id from im_assets where minting_status is null limit $1 for update skip locked
|
|
15
|
-
) returning *;
|
|
16
|
-
`, [limit]);
|
|
17
|
-
return res.rows;
|
|
18
|
-
},
|
|
19
|
-
updateMintingStatusToSubmitted: async (ids) => {
|
|
20
|
-
await client.query(`
|
|
21
|
-
UPDATE im_assets SET minting_status = $2 WHERE id = ANY($1);
|
|
22
|
-
`, [ids, 'submitted']);
|
|
23
|
-
},
|
|
24
|
-
syncMintingStatus: async (submittedMintRequest) => {
|
|
25
|
-
// doing a upsert just in case the row has not been created yet
|
|
26
|
-
await client.query(`
|
|
27
|
-
INSERT INTO im_assets (
|
|
28
|
-
asset_id,
|
|
29
|
-
contract_address,
|
|
30
|
-
owner_address,
|
|
31
|
-
token_id,
|
|
32
|
-
minting_status,
|
|
33
|
-
metadata_id,
|
|
34
|
-
last_imtbl_zkevm_mint_request_updated_id,
|
|
35
|
-
error
|
|
36
|
-
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) ON CONFLICT (asset_id, contract_address)
|
|
37
|
-
DO UPDATE SET
|
|
38
|
-
owner_address = $3,
|
|
39
|
-
token_id = $4,
|
|
40
|
-
minting_status = $5,
|
|
41
|
-
metadata_id = $6,
|
|
42
|
-
last_imtbl_zkevm_mint_request_updated_id = $7,
|
|
43
|
-
error = $8
|
|
44
|
-
where (
|
|
45
|
-
im_assets.last_imtbl_zkevm_mint_request_updated_id < $7 OR
|
|
46
|
-
im_assets.last_imtbl_zkevm_mint_request_updated_id is null
|
|
47
|
-
);
|
|
48
|
-
`, [
|
|
49
|
-
submittedMintRequest.assetId,
|
|
50
|
-
submittedMintRequest.contractAddress,
|
|
51
|
-
submittedMintRequest.ownerAddress,
|
|
52
|
-
submittedMintRequest.tokenId,
|
|
53
|
-
submittedMintRequest.status,
|
|
54
|
-
submittedMintRequest.metadataId,
|
|
55
|
-
submittedMintRequest.imtblZkevmMintRequestUpdatedId,
|
|
56
|
-
submittedMintRequest.error
|
|
57
|
-
]);
|
|
58
|
-
},
|
|
59
|
-
markAsConflict: async (assetIds, contractAddress) => {
|
|
60
|
-
await client.query(`
|
|
61
|
-
UPDATE im_assets
|
|
62
|
-
SET minting_status = 'conflicting'
|
|
63
|
-
WHERE asset_id = ANY($1)
|
|
64
|
-
AND contract_address = $2;
|
|
65
|
-
`, [assetIds, contractAddress]);
|
|
66
|
-
},
|
|
67
|
-
resetMintingStatus: async (ids) => {
|
|
68
|
-
await client.query(`
|
|
69
|
-
UPDATE im_assets SET minting_status = null WHERE id = ANY($1);
|
|
70
|
-
`, [ids]);
|
|
71
|
-
},
|
|
72
|
-
markForRetry: async (ids) => {
|
|
73
|
-
await client.query(`
|
|
74
|
-
UPDATE im_assets
|
|
75
|
-
SET minting_status = null, tried_count = tried_count + 1 WHERE id = ANY($1);
|
|
76
|
-
`, [ids]);
|
|
77
|
-
},
|
|
78
|
-
updateMintingStatusToSubmissionFailed: async (ids) => {
|
|
79
|
-
await client.query(`
|
|
80
|
-
UPDATE im_assets SET minting_status = 'submission_failed' WHERE id = ANY($1);
|
|
81
|
-
`, [ids]);
|
|
82
|
-
},
|
|
83
|
-
getMintingRequest: async (contractAddress, referenceId) => {
|
|
84
|
-
const res = await client.query(`
|
|
85
|
-
SELECT * FROM im_assets WHERE contract_address = $1 and asset_id = $2;
|
|
86
|
-
`, [contractAddress, referenceId]);
|
|
87
|
-
return res.rows[0] || null;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
// client is a PrismaClient instance. it needs to be generated with
|
|
92
|
-
// additional schema defined inside (TODO: point to repo) file.
|
|
93
|
-
const mintingPersistence = (client) => ({
|
|
94
|
-
recordMint: async (request) => {
|
|
95
|
-
const result = await client.imAssets.upsert({
|
|
96
|
-
where: {
|
|
97
|
-
im_assets_uindex: {
|
|
98
|
-
assetId: request.asset_id, contractAddress: request.contract_address
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
update: {},
|
|
102
|
-
create: {
|
|
103
|
-
assetId: request.asset_id,
|
|
104
|
-
contractAddress: request.contract_address,
|
|
105
|
-
ownerAddress: request.owner_address,
|
|
106
|
-
metadata: JSON.stringify(request.metadata), // Serialize JSON metadata
|
|
107
|
-
},
|
|
108
|
-
});
|
|
109
|
-
// Since upsert does not throw on update and does not tell directly if it updated or inserted,
|
|
110
|
-
// we need to add additional logic to handle this if "result" does not provide enough info.
|
|
111
|
-
if (!result) {
|
|
112
|
-
throw new Error('Duplicated mint');
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
// WARNING: this is NOT concurrency safe. Please only call this method one at a time.
|
|
116
|
-
getNextBatchForSubmission: async (limit) => {
|
|
117
|
-
const assets = await client.imAssets.findMany({
|
|
118
|
-
where: {
|
|
119
|
-
mintingStatus: null
|
|
120
|
-
},
|
|
121
|
-
take: limit
|
|
122
|
-
});
|
|
123
|
-
const assetIds = assets.map((asset) => asset.id);
|
|
124
|
-
await client.imAssets.updateMany({
|
|
125
|
-
where: {
|
|
126
|
-
id: {
|
|
127
|
-
in: assetIds
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
data: {
|
|
131
|
-
mintingStatus: 'submitting'
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
const updatedAssets = await client.imAssets.findMany({
|
|
135
|
-
where: {
|
|
136
|
-
id: {
|
|
137
|
-
in: assetIds
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
return updatedAssets.map((asset) => ({
|
|
142
|
-
id: asset.id,
|
|
143
|
-
contract_address: asset.contractAddress,
|
|
144
|
-
wallet_address: asset.ownerAddress,
|
|
145
|
-
asset_id: asset.assetId,
|
|
146
|
-
metadata: asset.metadata ? JSON.parse(asset.metadata) : null,
|
|
147
|
-
owner_address: asset.ownerAddress,
|
|
148
|
-
tried_count: asset.triedCount,
|
|
149
|
-
}));
|
|
150
|
-
},
|
|
151
|
-
updateMintingStatusToSubmitted: async (ids) => {
|
|
152
|
-
await client.imAssets.updateMany({
|
|
153
|
-
where: {
|
|
154
|
-
id: {
|
|
155
|
-
in: ids
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
data: {
|
|
159
|
-
mintingStatus: 'submitted'
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
},
|
|
163
|
-
syncMintingStatus: async (submittedMintRequest) => {
|
|
164
|
-
// First, attempt to retrieve the existing asset
|
|
165
|
-
const existingAsset = await client.imAssets.findUnique({
|
|
166
|
-
where: {
|
|
167
|
-
im_assets_uindex: {
|
|
168
|
-
assetId: submittedMintRequest.assetId,
|
|
169
|
-
contractAddress: submittedMintRequest.contractAddress,
|
|
170
|
-
},
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
// Check if the asset exists and the condition for updating is met
|
|
174
|
-
if (existingAsset && (existingAsset.lastImtblZkevmMintRequestUpdatedId === null
|
|
175
|
-
|| existingAsset.lastImtblZkevmMintRequestUpdatedId < submittedMintRequest.imtblZkevmMintRequestUpdatedId)) {
|
|
176
|
-
// Perform update if the existing record's lastImtblZkevmMintRequestUpdatedId is less than the new one or is null
|
|
177
|
-
await client.imAssets.update({
|
|
178
|
-
where: {
|
|
179
|
-
im_assets_uindex: {
|
|
180
|
-
assetId: submittedMintRequest.assetId,
|
|
181
|
-
contractAddress: submittedMintRequest.contractAddress,
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
data: {
|
|
185
|
-
ownerAddress: submittedMintRequest.ownerAddress,
|
|
186
|
-
tokenId: submittedMintRequest.tokenId,
|
|
187
|
-
mintingStatus: submittedMintRequest.status,
|
|
188
|
-
metadataId: submittedMintRequest.metadataId,
|
|
189
|
-
lastImtblZkevmMintRequestUpdatedId: submittedMintRequest.imtblZkevmMintRequestUpdatedId,
|
|
190
|
-
error: submittedMintRequest.error,
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
else if (!existingAsset) {
|
|
195
|
-
// Perform insert if no existing record is found
|
|
196
|
-
await client.imAssets.create({
|
|
197
|
-
data: {
|
|
198
|
-
assetId: submittedMintRequest.assetId,
|
|
199
|
-
contractAddress: submittedMintRequest.contractAddress,
|
|
200
|
-
ownerAddress: submittedMintRequest.ownerAddress,
|
|
201
|
-
tokenId: submittedMintRequest.tokenId,
|
|
202
|
-
mintingStatus: submittedMintRequest.status,
|
|
203
|
-
metadataId: submittedMintRequest.metadataId,
|
|
204
|
-
lastImtblZkevmMintRequestUpdatedId: submittedMintRequest.imtblZkevmMintRequestUpdatedId,
|
|
205
|
-
error: submittedMintRequest.error,
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
// If existing asset does not meet the update condition, do nothing
|
|
210
|
-
},
|
|
211
|
-
updateMintingStatusToSubmissionFailed: async (ids) => {
|
|
212
|
-
await client.imAssets.updateMany({
|
|
213
|
-
where: {
|
|
214
|
-
id: {
|
|
215
|
-
in: ids
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
data: {
|
|
219
|
-
mintingStatus: 'submission_failed'
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
},
|
|
223
|
-
markAsConflict: async (assetIds, contractAddress) => {
|
|
224
|
-
await client.imAssets.updateMany({
|
|
225
|
-
where: {
|
|
226
|
-
assetId: {
|
|
227
|
-
in: assetIds // Targets assets where assetId is in the provided list
|
|
228
|
-
},
|
|
229
|
-
contractAddress // Additional condition for contract address
|
|
230
|
-
},
|
|
231
|
-
data: {
|
|
232
|
-
mintingStatus: 'conflicting' // Set the new status
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
},
|
|
236
|
-
resetMintingStatus: async (ids) => {
|
|
237
|
-
await client.imAssets.updateMany({
|
|
238
|
-
where: {
|
|
239
|
-
id: {
|
|
240
|
-
in: ids // Condition to match ids
|
|
241
|
-
}
|
|
242
|
-
},
|
|
243
|
-
data: {
|
|
244
|
-
mintingStatus: null // Setting minting_status to null
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
},
|
|
248
|
-
// this method is not concurrency safe
|
|
249
|
-
markForRetry: async (ids) => {
|
|
250
|
-
// Retrieve the current values of tried_count for the specified ids
|
|
251
|
-
const assets = await client.imAssets.findMany({
|
|
252
|
-
where: {
|
|
253
|
-
id: {
|
|
254
|
-
in: ids
|
|
255
|
-
}
|
|
256
|
-
},
|
|
257
|
-
select: {
|
|
258
|
-
id: true,
|
|
259
|
-
triedCount: true // Assuming the field is named triedCount
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
// Update each asset with the new tried_count and nullify minting_status
|
|
263
|
-
for (const asset of assets) {
|
|
264
|
-
await client.imAssets.update({
|
|
265
|
-
where: {
|
|
266
|
-
id: asset.id
|
|
267
|
-
},
|
|
268
|
-
data: {
|
|
269
|
-
mintingStatus: null,
|
|
270
|
-
triedCount: asset.triedCount + 1
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
},
|
|
275
|
-
getMintingRequest: async (contractAddress, referenceId) => {
|
|
276
|
-
// Retrieve the asset from the database based on contract_address and asset_id
|
|
277
|
-
const asset = await client.imAssets.findFirst({
|
|
278
|
-
where: {
|
|
279
|
-
contractAddress,
|
|
280
|
-
assetId: referenceId
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
if (!asset) {
|
|
284
|
-
return null;
|
|
285
|
-
}
|
|
286
|
-
return {
|
|
287
|
-
asset_id: asset.assetId,
|
|
288
|
-
contract_address: asset.contractAddress,
|
|
289
|
-
id: asset.id,
|
|
290
|
-
metadata: asset.metadata ? JSON.parse(asset.metadata) : null,
|
|
291
|
-
owner_address: asset.ownerAddress,
|
|
292
|
-
tried_count: asset.triedCount,
|
|
293
|
-
wallet_address: asset.ownerAddress
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
// TODO: expose metrics
|
|
299
|
-
// - submitting status count, conflicting status count
|
|
300
|
-
// - failed events count
|
|
301
|
-
const recordMint = async (mintingPersistence, mintRequest) => {
|
|
302
|
-
mintingPersistence.recordMint(mintRequest);
|
|
303
|
-
};
|
|
304
|
-
const defaultMintingDelay = 1000;
|
|
305
|
-
// This function can be called in different node process and will run in parallel to mint assets.
|
|
306
|
-
// Each process will NOT mint the same asset.
|
|
307
|
-
// Monitor your database to see if parallel processes are saturating the database CPU and triggering excessive vacuuming.
|
|
308
|
-
// default batch size will be treated as 100 when it exceeds 100 because minting API has a limit of 100 assets per request.
|
|
309
|
-
const submitMintingRequests = async (mintingPersistence, blockchainDataSDKClient, { defaultBatchSize = 1000, chainName = 'imtbl-zkevm-testnet', maxNumberOfTries = 3, }, logger = console) => {
|
|
310
|
-
let mintingResponse;
|
|
311
|
-
// eslint-disable-next-line no-constant-condition
|
|
312
|
-
while (true) {
|
|
313
|
-
await new Promise((resolve) => {
|
|
314
|
-
setTimeout(resolve, defaultMintingDelay);
|
|
315
|
-
});
|
|
316
|
-
let batchSize = Math.min(mintingResponse?.imx_remaining_mint_requests
|
|
317
|
-
? parseInt(mintingResponse.imx_remaining_mint_requests, 10)
|
|
318
|
-
: defaultBatchSize, defaultBatchSize);
|
|
319
|
-
if (batchSize === 0
|
|
320
|
-
&& mintingResponse
|
|
321
|
-
&& new Date(mintingResponse.imx_mint_requests_limit_reset) > new Date()) {
|
|
322
|
-
logger.info(`minting limit reached, waiting for reset at ${mintingResponse?.imx_mint_requests_limit_reset}`);
|
|
323
|
-
continue;
|
|
324
|
-
}
|
|
325
|
-
if (batchSize === 0) {
|
|
326
|
-
logger.info(`minting limit has been reset, use default batch size: ${defaultBatchSize}`);
|
|
327
|
-
mintingResponse = undefined;
|
|
328
|
-
batchSize = defaultBatchSize;
|
|
329
|
-
}
|
|
330
|
-
// get mints to be submitted
|
|
331
|
-
const pendingMints = await mintingPersistence.getNextBatchForSubmission(batchSize);
|
|
332
|
-
if (pendingMints.length === 0) {
|
|
333
|
-
logger.info('no assets to mint');
|
|
334
|
-
continue;
|
|
335
|
-
}
|
|
336
|
-
// chunk assets by every 100 assets. every chunk should all be for the same contract address.
|
|
337
|
-
const chunkedAssets = pendingMints.sort((a, b) => (a.contract_address > b.contract_address ? 1 : -1)).reduce((acc, row) => {
|
|
338
|
-
if (acc.length === 0) {
|
|
339
|
-
return [{ contractAddress: row.contract_address, assets: [row] }];
|
|
340
|
-
}
|
|
341
|
-
const lastBatch = acc[acc.length - 1];
|
|
342
|
-
if (lastBatch.contractAddress === row.contract_address && lastBatch.assets.length < 100) {
|
|
343
|
-
return [...acc.slice(0, -1), { ...lastBatch, assets: [...lastBatch.assets, row] }];
|
|
344
|
-
}
|
|
345
|
-
return [...acc, { contractAddress: row.contract_address, assets: [row] }];
|
|
346
|
-
}, []);
|
|
347
|
-
// submit minting request for each contract address in parallel
|
|
348
|
-
const mintingResults = await Promise.allSettled(chunkedAssets.map(async ({ contractAddress, assets }) => {
|
|
349
|
-
const mintingRequest = {
|
|
350
|
-
chainName,
|
|
351
|
-
contractAddress,
|
|
352
|
-
createMintRequestRequest: {
|
|
353
|
-
assets: assets.map((row) => ({
|
|
354
|
-
reference_id: row.asset_id,
|
|
355
|
-
owner_address: row.owner_address,
|
|
356
|
-
metadata: row.metadata,
|
|
357
|
-
})),
|
|
358
|
-
},
|
|
359
|
-
};
|
|
360
|
-
try {
|
|
361
|
-
const response = await blockchainDataSDKClient.createMintRequest(mintingRequest);
|
|
362
|
-
logger.info(`mintingResponse: ${JSON.stringify(response, null, 2)}`);
|
|
363
|
-
// update minting status to submitted
|
|
364
|
-
await mintingPersistence.updateMintingStatusToSubmitted(assets.map(({ id }) => id));
|
|
365
|
-
return response;
|
|
366
|
-
}
|
|
367
|
-
catch (e) {
|
|
368
|
-
logger.error(e);
|
|
369
|
-
if (e.code === 'CONFLICT_ERROR'
|
|
370
|
-
&& e.details?.id === 'reference_id') {
|
|
371
|
-
try {
|
|
372
|
-
// mark the assets as conflicting, so that we don't send them again.
|
|
373
|
-
await mintingPersistence.markAsConflict(e.details.values, contractAddress);
|
|
374
|
-
// remove non conflicting assets status so that they can be retried.
|
|
375
|
-
await mintingPersistence.resetMintingStatus(assets
|
|
376
|
-
.map(({ id }) => id)
|
|
377
|
-
.filter((id) => !e.details.values.includes(id)));
|
|
378
|
-
}
|
|
379
|
-
catch (e2) {
|
|
380
|
-
logger.error(e2);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
else {
|
|
384
|
-
// separate assets into "need to be retied" and "exceeded max number of tries."
|
|
385
|
-
const { assetsToRetry, assetsExceededMaxNumberOfTries } = assets.reduce((acc, { tried_count = 0, id }) => {
|
|
386
|
-
if (tried_count < maxNumberOfTries) {
|
|
387
|
-
acc.assetsToRetry.push(id);
|
|
388
|
-
}
|
|
389
|
-
else {
|
|
390
|
-
acc.assetsExceededMaxNumberOfTries.push(id);
|
|
391
|
-
}
|
|
392
|
-
return acc;
|
|
393
|
-
}, {
|
|
394
|
-
assetsToRetry: [],
|
|
395
|
-
assetsExceededMaxNumberOfTries: [],
|
|
396
|
-
});
|
|
397
|
-
// remove all assets status so that they can be retried.
|
|
398
|
-
await mintingPersistence.markForRetry(assetsToRetry);
|
|
399
|
-
// mark assets that have exceeded the max number of tries as submission_failed
|
|
400
|
-
await mintingPersistence.updateMintingStatusToSubmissionFailed(assetsExceededMaxNumberOfTries);
|
|
401
|
-
}
|
|
402
|
-
return e;
|
|
403
|
-
}
|
|
404
|
-
}));
|
|
405
|
-
mintingResponse = mintingResults
|
|
406
|
-
.reverse()
|
|
407
|
-
.find((r) => r.status === 'fulfilled')?.value;
|
|
408
|
-
}
|
|
409
|
-
};
|
|
410
|
-
const processMint = async (mintingPersistence, event, logger = console) => {
|
|
411
|
-
if (event.event_name !== 'imtbl_zkevm_mint_request_updated') {
|
|
412
|
-
logger.info(`${event.event_name} is not imtbl_zkevm_mint_request_updated, skip.`);
|
|
413
|
-
return;
|
|
414
|
-
}
|
|
415
|
-
const referenceId = event.data.reference_id;
|
|
416
|
-
if (!referenceId) {
|
|
417
|
-
throw new Error('reference_id not found in webhook event');
|
|
418
|
-
}
|
|
419
|
-
const contractAddress = event.data.contract_address;
|
|
420
|
-
if (!contractAddress) {
|
|
421
|
-
throw new Error('contract_address not found in webhook event');
|
|
422
|
-
}
|
|
423
|
-
if (event.data.status === 'failed') {
|
|
424
|
-
logger.error(`mint failed: ${JSON.stringify(event.data, null, 2)}`);
|
|
425
|
-
}
|
|
426
|
-
const mintReq = await mintingPersistence.getMintingRequest(contractAddress, referenceId);
|
|
427
|
-
if (!mintReq) {
|
|
428
|
-
logger.info(`minting request not found in the database, ${JSON.stringify(event.data)}`);
|
|
429
|
-
}
|
|
430
|
-
const ownerAddress = mintReq?.wallet_address || event.data.owner_address;
|
|
431
|
-
if (!ownerAddress) {
|
|
432
|
-
logger.error('owner_address missing');
|
|
433
|
-
throw new Error('owner_address missing');
|
|
434
|
-
}
|
|
435
|
-
await mintingPersistence.syncMintingStatus({
|
|
436
|
-
tokenId: event.data.token_id,
|
|
437
|
-
status: event.data.status,
|
|
438
|
-
assetId: referenceId,
|
|
439
|
-
contractAddress,
|
|
440
|
-
ownerAddress,
|
|
441
|
-
metadataId: event.data.metadata_id,
|
|
442
|
-
imtblZkevmMintRequestUpdatedId: event.event_id,
|
|
443
|
-
error: event.data.error ? JSON.stringify(event.data.error) : null,
|
|
444
|
-
});
|
|
445
|
-
};
|
|
446
|
-
|
|
447
|
-
export { mintingPersistence$1 as mintingPersistencePg, mintingPersistence as mintingPersistencePrismaSqlite, processMint, recordMint, submitMintingRequests };
|
package/dist/webhook.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
declare enum Environment {
|
|
2
|
-
PRODUCTION = "production",
|
|
3
|
-
SANDBOX = "sandbox"
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
declare const init: (body: string | Record<string, unknown>, env: Environment, handlers: {
|
|
7
|
-
zkevmMintRequestUpdated: (event: any) => Promise<void>;
|
|
8
|
-
others?: ((event: any) => Promise<void>) | undefined;
|
|
9
|
-
}) => Promise<void>;
|
|
10
|
-
|
|
11
|
-
export { init };
|