@imtbl/sdk 1.38.0-alpha.1 → 1.38.0
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/sdk.js +4 -4
- package/dist/checkout.js +4 -4
- 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 +15 -612
- package/dist/index.d.ts +7 -139
- package/dist/index.js +16 -611
- package/dist/orderbook.js +1 -1
- package/dist/passport.js +4 -4
- package/dist/x.js +3 -3
- package/package.json +1 -9
- package/dist/minting_backend.d.ts +0 -3528
- package/dist/minting_backend.js +0 -6600
- package/dist/webhook.d.ts +0 -11
- package/dist/webhook.js +0 -388
package/dist/index.js
CHANGED
|
@@ -33,7 +33,6 @@ import { keccak256 as keccak256$3 } from '@ethersproject/solidity';
|
|
|
33
33
|
import { SwapRouter, PaymentsExtended } from '@uniswap/router-sdk';
|
|
34
34
|
import { parseUnits as parseUnits$1 } from '@ethersproject/units';
|
|
35
35
|
import { BigNumber as BigNumber$2 } from '@ethersproject/bignumber';
|
|
36
|
-
import MessageValidator from 'sns-validator';
|
|
37
36
|
|
|
38
37
|
const isNode$1 = () => typeof window === 'undefined';
|
|
39
38
|
const isBrowser$1 = () => !isNode$1();
|
|
@@ -161,7 +160,7 @@ const flattenProperties$1 = (properties) => {
|
|
|
161
160
|
};
|
|
162
161
|
|
|
163
162
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
164
|
-
const SDK_VERSION$1 = '1.38.0
|
|
163
|
+
const SDK_VERSION$1 = '1.38.0';
|
|
165
164
|
const getFrameParentDomain$1 = () => {
|
|
166
165
|
if (isNode$1()) {
|
|
167
166
|
return '';
|
|
@@ -14188,7 +14187,7 @@ class MultiRollupApiClients {
|
|
|
14188
14187
|
}
|
|
14189
14188
|
|
|
14190
14189
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
14191
|
-
const defaultHeaders$2 = { 'x-sdk-version': 'ts-immutable-sdk-1.38.0
|
|
14190
|
+
const defaultHeaders$2 = { 'x-sdk-version': 'ts-immutable-sdk-1.38.0' };
|
|
14192
14191
|
const createConfig$1 = ({ basePath, headers, }) => {
|
|
14193
14192
|
if (!basePath.trim()) {
|
|
14194
14193
|
throw Error('basePath can not be empty');
|
|
@@ -14260,7 +14259,7 @@ class APIError extends Error {
|
|
|
14260
14259
|
|
|
14261
14260
|
/* eslint-disable implicit-arrow-linebreak */
|
|
14262
14261
|
const defaultHeaders$1 = {
|
|
14263
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.38.0
|
|
14262
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.38.0',
|
|
14264
14263
|
};
|
|
14265
14264
|
/**
|
|
14266
14265
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -14734,7 +14733,7 @@ var blockchain_data = /*#__PURE__*/Object.freeze({
|
|
|
14734
14733
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
14735
14734
|
class ApiConfiguration extends index$2.Configuration {
|
|
14736
14735
|
}
|
|
14737
|
-
const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.38.0
|
|
14736
|
+
const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.38.0' };
|
|
14738
14737
|
/**
|
|
14739
14738
|
* @dev use createImmutableXConfiguration instead
|
|
14740
14739
|
*/
|
|
@@ -14773,7 +14772,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
14773
14772
|
chainID,
|
|
14774
14773
|
coreContractAddress,
|
|
14775
14774
|
registrationContractAddress,
|
|
14776
|
-
sdkVersion: 'ts-immutable-sdk-1.38.0
|
|
14775
|
+
sdkVersion: 'ts-immutable-sdk-1.38.0',
|
|
14777
14776
|
baseConfig,
|
|
14778
14777
|
});
|
|
14779
14778
|
const production = ({ baseConfig }) => createImmutableXConfiguration({
|
|
@@ -23595,12 +23594,12 @@ function assertOptions$1(options, schema, allowUnknown) {
|
|
|
23595
23594
|
}
|
|
23596
23595
|
}
|
|
23597
23596
|
|
|
23598
|
-
var validator$
|
|
23597
|
+
var validator$1 = {
|
|
23599
23598
|
assertOptions: assertOptions$1,
|
|
23600
23599
|
validators: validators$1$1
|
|
23601
23600
|
};
|
|
23602
23601
|
|
|
23603
|
-
const validators$2 = validator$
|
|
23602
|
+
const validators$2 = validator$1.validators;
|
|
23604
23603
|
|
|
23605
23604
|
/**
|
|
23606
23605
|
* Create a new instance of Axios
|
|
@@ -23641,7 +23640,7 @@ let Axios$2 = class Axios {
|
|
|
23641
23640
|
const {transitional, paramsSerializer, headers} = config;
|
|
23642
23641
|
|
|
23643
23642
|
if (transitional !== undefined) {
|
|
23644
|
-
validator$
|
|
23643
|
+
validator$1.assertOptions(transitional, {
|
|
23645
23644
|
silentJSONParsing: validators$2.transitional(validators$2.boolean),
|
|
23646
23645
|
forcedJSONParsing: validators$2.transitional(validators$2.boolean),
|
|
23647
23646
|
clarifyTimeoutError: validators$2.transitional(validators$2.boolean)
|
|
@@ -23654,7 +23653,7 @@ let Axios$2 = class Axios {
|
|
|
23654
23653
|
serialize: paramsSerializer
|
|
23655
23654
|
};
|
|
23656
23655
|
} else {
|
|
23657
|
-
validator$
|
|
23656
|
+
validator$1.assertOptions(paramsSerializer, {
|
|
23658
23657
|
encode: validators$2.function,
|
|
23659
23658
|
serialize: validators$2.function
|
|
23660
23659
|
}, true);
|
|
@@ -32373,12 +32372,12 @@ function assertOptions(options, schema, allowUnknown) {
|
|
|
32373
32372
|
}
|
|
32374
32373
|
}
|
|
32375
32374
|
|
|
32376
|
-
var validator
|
|
32375
|
+
var validator = {
|
|
32377
32376
|
assertOptions,
|
|
32378
32377
|
validators: validators$1
|
|
32379
32378
|
};
|
|
32380
32379
|
|
|
32381
|
-
const validators = validator
|
|
32380
|
+
const validators = validator.validators;
|
|
32382
32381
|
|
|
32383
32382
|
/**
|
|
32384
32383
|
* Create a new instance of Axios
|
|
@@ -32419,7 +32418,7 @@ class Axios {
|
|
|
32419
32418
|
const {transitional, paramsSerializer, headers} = config;
|
|
32420
32419
|
|
|
32421
32420
|
if (transitional !== undefined) {
|
|
32422
|
-
validator
|
|
32421
|
+
validator.assertOptions(transitional, {
|
|
32423
32422
|
silentJSONParsing: validators.transitional(validators.boolean),
|
|
32424
32423
|
forcedJSONParsing: validators.transitional(validators.boolean),
|
|
32425
32424
|
clarifyTimeoutError: validators.transitional(validators.boolean)
|
|
@@ -32432,7 +32431,7 @@ class Axios {
|
|
|
32432
32431
|
serialize: paramsSerializer
|
|
32433
32432
|
};
|
|
32434
32433
|
} else {
|
|
32435
|
-
validator
|
|
32434
|
+
validator.assertOptions(paramsSerializer, {
|
|
32436
32435
|
encode: validators.function,
|
|
32437
32436
|
serialize: validators.function
|
|
32438
32437
|
}, true);
|
|
@@ -58191,7 +58190,7 @@ const flattenProperties = (properties) => {
|
|
|
58191
58190
|
};
|
|
58192
58191
|
|
|
58193
58192
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
58194
|
-
const SDK_VERSION = '1.38.0
|
|
58193
|
+
const SDK_VERSION = '1.38.0';
|
|
58195
58194
|
const getFrameParentDomain = () => {
|
|
58196
58195
|
if (isNode()) {
|
|
58197
58196
|
return '';
|
|
@@ -63484,7 +63483,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
|
|
|
63484
63483
|
maxPriorityFeePerGas: BigNumber$1.from(10e9),
|
|
63485
63484
|
};
|
|
63486
63485
|
|
|
63487
|
-
const SDK_VERSION_MARKER = '1.38.0
|
|
63486
|
+
const SDK_VERSION_MARKER = '1.38.0';
|
|
63488
63487
|
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
63489
63488
|
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
63490
63489
|
|
|
@@ -69157,598 +69156,4 @@ var x = /*#__PURE__*/Object.freeze({
|
|
|
69157
69156
|
sandbox: sandbox
|
|
69158
69157
|
});
|
|
69159
69158
|
|
|
69160
|
-
|
|
69161
|
-
const allowedTopicArnPrefix = {
|
|
69162
|
-
[Environment$1.PRODUCTION]: 'arn:aws:sns:us-east-2:362750628221:',
|
|
69163
|
-
[Environment$1.SANDBOX]: 'arn:aws:sns:us-east-2:783421985614:'
|
|
69164
|
-
};
|
|
69165
|
-
const init = async (body, env, handlers) => {
|
|
69166
|
-
const msg = await new Promise((resolve, reject) => {
|
|
69167
|
-
validator.validate(body, (err, message) => {
|
|
69168
|
-
if (err) {
|
|
69169
|
-
return reject(err);
|
|
69170
|
-
}
|
|
69171
|
-
// check for topic arn prefix
|
|
69172
|
-
if (!message.TopicArn.startsWith(allowedTopicArnPrefix[env])) {
|
|
69173
|
-
throw new Error('Invalid topic arn');
|
|
69174
|
-
}
|
|
69175
|
-
if (message?.Type === 'SubscriptionConfirmation') {
|
|
69176
|
-
fetch(message.SubscribeURL).then(() => {
|
|
69177
|
-
resolve(message);
|
|
69178
|
-
}).catch((e) => {
|
|
69179
|
-
reject(e);
|
|
69180
|
-
});
|
|
69181
|
-
}
|
|
69182
|
-
return resolve(message);
|
|
69183
|
-
});
|
|
69184
|
-
});
|
|
69185
|
-
if (msg.Type === 'Notification') {
|
|
69186
|
-
const event = JSON.parse(msg.Message);
|
|
69187
|
-
switch (event.event_name) {
|
|
69188
|
-
case 'imtbl_zkevm_mint_request_updated':
|
|
69189
|
-
await handlers.zkevmMintRequestUpdated(event);
|
|
69190
|
-
break;
|
|
69191
|
-
default:
|
|
69192
|
-
if (handlers.others) {
|
|
69193
|
-
await handlers.others(event);
|
|
69194
|
-
}
|
|
69195
|
-
break;
|
|
69196
|
-
}
|
|
69197
|
-
}
|
|
69198
|
-
};
|
|
69199
|
-
|
|
69200
|
-
var webhook = /*#__PURE__*/Object.freeze({
|
|
69201
|
-
__proto__: null,
|
|
69202
|
-
init: init
|
|
69203
|
-
});
|
|
69204
|
-
|
|
69205
|
-
const moduleName = 'minting_backend_sdk';
|
|
69206
|
-
const trackInitializePersistencePG = () => {
|
|
69207
|
-
try {
|
|
69208
|
-
track(moduleName, 'initializePersistencePG');
|
|
69209
|
-
}
|
|
69210
|
-
catch {
|
|
69211
|
-
// ignore
|
|
69212
|
-
}
|
|
69213
|
-
};
|
|
69214
|
-
const trackInitializePersistencePrismaSqlite = () => {
|
|
69215
|
-
try {
|
|
69216
|
-
track(moduleName, 'initializePersistencePrismaSqlite');
|
|
69217
|
-
}
|
|
69218
|
-
catch {
|
|
69219
|
-
// ignore
|
|
69220
|
-
}
|
|
69221
|
-
};
|
|
69222
|
-
const trackSubmitMintingRequests = () => {
|
|
69223
|
-
try {
|
|
69224
|
-
track(moduleName, 'submitMintingRequests');
|
|
69225
|
-
}
|
|
69226
|
-
catch {
|
|
69227
|
-
// ignore
|
|
69228
|
-
}
|
|
69229
|
-
};
|
|
69230
|
-
const trackProcessMint = () => {
|
|
69231
|
-
try {
|
|
69232
|
-
track(moduleName, 'processMint');
|
|
69233
|
-
}
|
|
69234
|
-
catch {
|
|
69235
|
-
// ignore
|
|
69236
|
-
}
|
|
69237
|
-
};
|
|
69238
|
-
const trackRecordMint = () => {
|
|
69239
|
-
try {
|
|
69240
|
-
track(moduleName, 'recordMint');
|
|
69241
|
-
}
|
|
69242
|
-
catch {
|
|
69243
|
-
// ignore
|
|
69244
|
-
}
|
|
69245
|
-
};
|
|
69246
|
-
|
|
69247
|
-
const mintingPersistence$1 = (client) => {
|
|
69248
|
-
trackInitializePersistencePG();
|
|
69249
|
-
return {
|
|
69250
|
-
recordMint: async (request) => {
|
|
69251
|
-
const r = await client.query(`
|
|
69252
|
-
INSERT INTO im_assets (asset_id, contract_address, owner_address, metadata)
|
|
69253
|
-
VALUES ($1, $2, $3, $4) ON CONFLICT (asset_id, contract_address) DO NOTHING;
|
|
69254
|
-
`, [request.asset_id, request.contract_address, request.owner_address, request.metadata]);
|
|
69255
|
-
if (r.rowCount === 0) {
|
|
69256
|
-
throw new Error('Duplicated mint');
|
|
69257
|
-
}
|
|
69258
|
-
},
|
|
69259
|
-
getNextBatchForSubmission: async (limit) => {
|
|
69260
|
-
const res = await client.query(`
|
|
69261
|
-
UPDATE im_assets SET minting_status = 'submitting' WHERE minting_status IS NULL and id in (
|
|
69262
|
-
select id from im_assets where minting_status is null limit $1 for update skip locked
|
|
69263
|
-
) returning *;
|
|
69264
|
-
`, [limit]);
|
|
69265
|
-
return res.rows;
|
|
69266
|
-
},
|
|
69267
|
-
updateMintingStatusToSubmitted: async (ids) => {
|
|
69268
|
-
await client.query(`
|
|
69269
|
-
UPDATE im_assets SET minting_status = $2 WHERE id = ANY($1);
|
|
69270
|
-
`, [ids, 'submitted']);
|
|
69271
|
-
},
|
|
69272
|
-
syncMintingStatus: async (submittedMintRequest) => {
|
|
69273
|
-
// doing a upsert just in case the row has not been created yet
|
|
69274
|
-
await client.query(`
|
|
69275
|
-
INSERT INTO im_assets (
|
|
69276
|
-
asset_id,
|
|
69277
|
-
contract_address,
|
|
69278
|
-
owner_address,
|
|
69279
|
-
token_id,
|
|
69280
|
-
minting_status,
|
|
69281
|
-
metadata_id,
|
|
69282
|
-
last_imtbl_zkevm_mint_request_updated_id,
|
|
69283
|
-
error
|
|
69284
|
-
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) ON CONFLICT (asset_id, contract_address)
|
|
69285
|
-
DO UPDATE SET
|
|
69286
|
-
owner_address = $3,
|
|
69287
|
-
token_id = $4,
|
|
69288
|
-
minting_status = $5,
|
|
69289
|
-
metadata_id = $6,
|
|
69290
|
-
last_imtbl_zkevm_mint_request_updated_id = $7,
|
|
69291
|
-
error = $8
|
|
69292
|
-
where (
|
|
69293
|
-
im_assets.last_imtbl_zkevm_mint_request_updated_id < $7 OR
|
|
69294
|
-
im_assets.last_imtbl_zkevm_mint_request_updated_id is null
|
|
69295
|
-
);
|
|
69296
|
-
`, [
|
|
69297
|
-
submittedMintRequest.assetId,
|
|
69298
|
-
submittedMintRequest.contractAddress,
|
|
69299
|
-
submittedMintRequest.ownerAddress,
|
|
69300
|
-
submittedMintRequest.tokenId,
|
|
69301
|
-
submittedMintRequest.status,
|
|
69302
|
-
submittedMintRequest.metadataId,
|
|
69303
|
-
submittedMintRequest.imtblZkevmMintRequestUpdatedId,
|
|
69304
|
-
submittedMintRequest.error
|
|
69305
|
-
]);
|
|
69306
|
-
},
|
|
69307
|
-
markAsConflict: async (assetIds, contractAddress) => {
|
|
69308
|
-
await client.query(`
|
|
69309
|
-
UPDATE im_assets
|
|
69310
|
-
SET minting_status = 'conflicting'
|
|
69311
|
-
WHERE asset_id = ANY($1)
|
|
69312
|
-
AND contract_address = $2;
|
|
69313
|
-
`, [assetIds, contractAddress]);
|
|
69314
|
-
},
|
|
69315
|
-
resetMintingStatus: async (ids) => {
|
|
69316
|
-
await client.query(`
|
|
69317
|
-
UPDATE im_assets SET minting_status = null WHERE id = ANY($1);
|
|
69318
|
-
`, [ids]);
|
|
69319
|
-
},
|
|
69320
|
-
markForRetry: async (ids) => {
|
|
69321
|
-
await client.query(`
|
|
69322
|
-
UPDATE im_assets
|
|
69323
|
-
SET minting_status = null, tried_count = tried_count + 1 WHERE id = ANY($1);
|
|
69324
|
-
`, [ids]);
|
|
69325
|
-
},
|
|
69326
|
-
updateMintingStatusToSubmissionFailed: async (ids) => {
|
|
69327
|
-
await client.query(`
|
|
69328
|
-
UPDATE im_assets SET minting_status = 'submission_failed' WHERE id = ANY($1);
|
|
69329
|
-
`, [ids]);
|
|
69330
|
-
},
|
|
69331
|
-
getMintingRequest: async (contractAddress, referenceId) => {
|
|
69332
|
-
const res = await client.query(`
|
|
69333
|
-
SELECT * FROM im_assets WHERE contract_address = $1 and asset_id = $2;
|
|
69334
|
-
`, [contractAddress, referenceId]);
|
|
69335
|
-
return res.rows[0] || null;
|
|
69336
|
-
}
|
|
69337
|
-
};
|
|
69338
|
-
};
|
|
69339
|
-
|
|
69340
|
-
/* eslint-disable no-await-in-loop */
|
|
69341
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
69342
|
-
// client is a PrismaClient instance. it needs to be generated with
|
|
69343
|
-
// additional schema defined inside (TODO: point to repo) file.
|
|
69344
|
-
const mintingPersistence = (client) => {
|
|
69345
|
-
trackInitializePersistencePrismaSqlite();
|
|
69346
|
-
return {
|
|
69347
|
-
recordMint: async (request) => {
|
|
69348
|
-
const result = await client.imAssets.upsert({
|
|
69349
|
-
where: {
|
|
69350
|
-
im_assets_uindex: {
|
|
69351
|
-
assetId: request.asset_id, contractAddress: request.contract_address
|
|
69352
|
-
}
|
|
69353
|
-
},
|
|
69354
|
-
update: {},
|
|
69355
|
-
create: {
|
|
69356
|
-
assetId: request.asset_id,
|
|
69357
|
-
contractAddress: request.contract_address,
|
|
69358
|
-
ownerAddress: request.owner_address,
|
|
69359
|
-
metadata: JSON.stringify(request.metadata), // Serialize JSON metadata
|
|
69360
|
-
},
|
|
69361
|
-
});
|
|
69362
|
-
// Since upsert does not throw on update and does not tell directly if it updated or inserted,
|
|
69363
|
-
// we need to add additional logic to handle this if "result" does not provide enough info.
|
|
69364
|
-
if (!result) {
|
|
69365
|
-
throw new Error('Duplicated mint');
|
|
69366
|
-
}
|
|
69367
|
-
},
|
|
69368
|
-
// WARNING: this is NOT concurrency safe. Please only call this method one at a time.
|
|
69369
|
-
getNextBatchForSubmission: async (limit) => {
|
|
69370
|
-
const assets = await client.imAssets.findMany({
|
|
69371
|
-
where: {
|
|
69372
|
-
mintingStatus: null
|
|
69373
|
-
},
|
|
69374
|
-
take: limit
|
|
69375
|
-
});
|
|
69376
|
-
const assetIds = assets.map((asset) => asset.id);
|
|
69377
|
-
await client.imAssets.updateMany({
|
|
69378
|
-
where: {
|
|
69379
|
-
id: {
|
|
69380
|
-
in: assetIds
|
|
69381
|
-
}
|
|
69382
|
-
},
|
|
69383
|
-
data: {
|
|
69384
|
-
mintingStatus: 'submitting'
|
|
69385
|
-
}
|
|
69386
|
-
});
|
|
69387
|
-
const updatedAssets = await client.imAssets.findMany({
|
|
69388
|
-
where: {
|
|
69389
|
-
id: {
|
|
69390
|
-
in: assetIds
|
|
69391
|
-
}
|
|
69392
|
-
}
|
|
69393
|
-
});
|
|
69394
|
-
return updatedAssets.map((asset) => ({
|
|
69395
|
-
id: asset.id,
|
|
69396
|
-
contract_address: asset.contractAddress,
|
|
69397
|
-
wallet_address: asset.ownerAddress,
|
|
69398
|
-
asset_id: asset.assetId,
|
|
69399
|
-
metadata: asset.metadata ? JSON.parse(asset.metadata) : null,
|
|
69400
|
-
owner_address: asset.ownerAddress,
|
|
69401
|
-
tried_count: asset.triedCount,
|
|
69402
|
-
}));
|
|
69403
|
-
},
|
|
69404
|
-
updateMintingStatusToSubmitted: async (ids) => {
|
|
69405
|
-
await client.imAssets.updateMany({
|
|
69406
|
-
where: {
|
|
69407
|
-
id: {
|
|
69408
|
-
in: ids
|
|
69409
|
-
}
|
|
69410
|
-
},
|
|
69411
|
-
data: {
|
|
69412
|
-
mintingStatus: 'submitted'
|
|
69413
|
-
}
|
|
69414
|
-
});
|
|
69415
|
-
},
|
|
69416
|
-
syncMintingStatus: async (submittedMintRequest) => {
|
|
69417
|
-
// First, attempt to retrieve the existing asset
|
|
69418
|
-
const existingAsset = await client.imAssets.findUnique({
|
|
69419
|
-
where: {
|
|
69420
|
-
im_assets_uindex: {
|
|
69421
|
-
assetId: submittedMintRequest.assetId,
|
|
69422
|
-
contractAddress: submittedMintRequest.contractAddress,
|
|
69423
|
-
},
|
|
69424
|
-
}
|
|
69425
|
-
});
|
|
69426
|
-
// Check if the asset exists and the condition for updating is met
|
|
69427
|
-
if (existingAsset && (existingAsset.lastImtblZkevmMintRequestUpdatedId === null
|
|
69428
|
-
|| existingAsset.lastImtblZkevmMintRequestUpdatedId < submittedMintRequest.imtblZkevmMintRequestUpdatedId)) {
|
|
69429
|
-
// Perform update if the existing record's lastImtblZkevmMintRequestUpdatedId is less than the new one or is null
|
|
69430
|
-
await client.imAssets.update({
|
|
69431
|
-
where: {
|
|
69432
|
-
im_assets_uindex: {
|
|
69433
|
-
assetId: submittedMintRequest.assetId,
|
|
69434
|
-
contractAddress: submittedMintRequest.contractAddress,
|
|
69435
|
-
},
|
|
69436
|
-
},
|
|
69437
|
-
data: {
|
|
69438
|
-
ownerAddress: submittedMintRequest.ownerAddress,
|
|
69439
|
-
tokenId: submittedMintRequest.tokenId,
|
|
69440
|
-
mintingStatus: submittedMintRequest.status,
|
|
69441
|
-
metadataId: submittedMintRequest.metadataId,
|
|
69442
|
-
lastImtblZkevmMintRequestUpdatedId: submittedMintRequest.imtblZkevmMintRequestUpdatedId,
|
|
69443
|
-
error: submittedMintRequest.error,
|
|
69444
|
-
}
|
|
69445
|
-
});
|
|
69446
|
-
}
|
|
69447
|
-
else if (!existingAsset) {
|
|
69448
|
-
// Perform insert if no existing record is found
|
|
69449
|
-
await client.imAssets.create({
|
|
69450
|
-
data: {
|
|
69451
|
-
assetId: submittedMintRequest.assetId,
|
|
69452
|
-
contractAddress: submittedMintRequest.contractAddress,
|
|
69453
|
-
ownerAddress: submittedMintRequest.ownerAddress,
|
|
69454
|
-
tokenId: submittedMintRequest.tokenId,
|
|
69455
|
-
mintingStatus: submittedMintRequest.status,
|
|
69456
|
-
metadataId: submittedMintRequest.metadataId,
|
|
69457
|
-
lastImtblZkevmMintRequestUpdatedId: submittedMintRequest.imtblZkevmMintRequestUpdatedId,
|
|
69458
|
-
error: submittedMintRequest.error,
|
|
69459
|
-
}
|
|
69460
|
-
});
|
|
69461
|
-
}
|
|
69462
|
-
// If existing asset does not meet the update condition, do nothing
|
|
69463
|
-
},
|
|
69464
|
-
updateMintingStatusToSubmissionFailed: async (ids) => {
|
|
69465
|
-
await client.imAssets.updateMany({
|
|
69466
|
-
where: {
|
|
69467
|
-
id: {
|
|
69468
|
-
in: ids
|
|
69469
|
-
}
|
|
69470
|
-
},
|
|
69471
|
-
data: {
|
|
69472
|
-
mintingStatus: 'submission_failed'
|
|
69473
|
-
}
|
|
69474
|
-
});
|
|
69475
|
-
},
|
|
69476
|
-
markAsConflict: async (assetIds, contractAddress) => {
|
|
69477
|
-
await client.imAssets.updateMany({
|
|
69478
|
-
where: {
|
|
69479
|
-
assetId: {
|
|
69480
|
-
in: assetIds // Targets assets where assetId is in the provided list
|
|
69481
|
-
},
|
|
69482
|
-
contractAddress // Additional condition for contract address
|
|
69483
|
-
},
|
|
69484
|
-
data: {
|
|
69485
|
-
mintingStatus: 'conflicting' // Set the new status
|
|
69486
|
-
}
|
|
69487
|
-
});
|
|
69488
|
-
},
|
|
69489
|
-
resetMintingStatus: async (ids) => {
|
|
69490
|
-
await client.imAssets.updateMany({
|
|
69491
|
-
where: {
|
|
69492
|
-
id: {
|
|
69493
|
-
in: ids // Condition to match ids
|
|
69494
|
-
}
|
|
69495
|
-
},
|
|
69496
|
-
data: {
|
|
69497
|
-
mintingStatus: null // Setting minting_status to null
|
|
69498
|
-
}
|
|
69499
|
-
});
|
|
69500
|
-
},
|
|
69501
|
-
// this method is not concurrency safe
|
|
69502
|
-
markForRetry: async (ids) => {
|
|
69503
|
-
// Retrieve the current values of tried_count for the specified ids
|
|
69504
|
-
const assets = await client.imAssets.findMany({
|
|
69505
|
-
where: {
|
|
69506
|
-
id: {
|
|
69507
|
-
in: ids
|
|
69508
|
-
}
|
|
69509
|
-
},
|
|
69510
|
-
select: {
|
|
69511
|
-
id: true,
|
|
69512
|
-
triedCount: true // Assuming the field is named triedCount
|
|
69513
|
-
}
|
|
69514
|
-
});
|
|
69515
|
-
// Update each asset with the new tried_count and nullify minting_status
|
|
69516
|
-
for (const asset of assets) {
|
|
69517
|
-
await client.imAssets.update({
|
|
69518
|
-
where: {
|
|
69519
|
-
id: asset.id
|
|
69520
|
-
},
|
|
69521
|
-
data: {
|
|
69522
|
-
mintingStatus: null,
|
|
69523
|
-
triedCount: asset.triedCount + 1
|
|
69524
|
-
}
|
|
69525
|
-
});
|
|
69526
|
-
}
|
|
69527
|
-
},
|
|
69528
|
-
getMintingRequest: async (contractAddress, referenceId) => {
|
|
69529
|
-
// Retrieve the asset from the database based on contract_address and asset_id
|
|
69530
|
-
const asset = await client.imAssets.findFirst({
|
|
69531
|
-
where: {
|
|
69532
|
-
contractAddress,
|
|
69533
|
-
assetId: referenceId
|
|
69534
|
-
}
|
|
69535
|
-
});
|
|
69536
|
-
if (!asset) {
|
|
69537
|
-
return null;
|
|
69538
|
-
}
|
|
69539
|
-
return {
|
|
69540
|
-
asset_id: asset.assetId,
|
|
69541
|
-
contract_address: asset.contractAddress,
|
|
69542
|
-
id: asset.id,
|
|
69543
|
-
metadata: asset.metadata ? JSON.parse(asset.metadata) : null,
|
|
69544
|
-
owner_address: asset.ownerAddress,
|
|
69545
|
-
tried_count: asset.triedCount,
|
|
69546
|
-
wallet_address: asset.ownerAddress
|
|
69547
|
-
};
|
|
69548
|
-
}
|
|
69549
|
-
};
|
|
69550
|
-
};
|
|
69551
|
-
|
|
69552
|
-
// TODO: expose metrics
|
|
69553
|
-
// - submitting status count, conflicting status count
|
|
69554
|
-
// - failed events count
|
|
69555
|
-
const recordMint = async (mintingPersistence, mintRequest) => {
|
|
69556
|
-
trackRecordMint();
|
|
69557
|
-
mintingPersistence.recordMint(mintRequest);
|
|
69558
|
-
};
|
|
69559
|
-
const defaultMintingDelay = 1000;
|
|
69560
|
-
// This function can be called in different node process and will run in parallel to mint assets.
|
|
69561
|
-
// Each process will NOT mint the same asset.
|
|
69562
|
-
// Monitor your database to see if parallel processes are saturating the database CPU and triggering excessive vacuuming.
|
|
69563
|
-
// default batch size will be treated as 100 when it exceeds 100 because minting API has a limit of 100 assets per request.
|
|
69564
|
-
const submitMintingRequests = async (mintingPersistence, blockchainDataSDKClient, { defaultBatchSize = 1000, chainName = 'imtbl-zkevm-testnet', maxNumberOfTries = 3, }, logger = console) => {
|
|
69565
|
-
trackSubmitMintingRequests();
|
|
69566
|
-
let mintingResponse;
|
|
69567
|
-
// eslint-disable-next-line no-constant-condition
|
|
69568
|
-
while (true) {
|
|
69569
|
-
await new Promise((resolve) => {
|
|
69570
|
-
setTimeout(resolve, defaultMintingDelay);
|
|
69571
|
-
});
|
|
69572
|
-
let batchSize = Math.min(mintingResponse?.imx_remaining_mint_requests
|
|
69573
|
-
? parseInt(mintingResponse.imx_remaining_mint_requests, 10)
|
|
69574
|
-
: defaultBatchSize, defaultBatchSize);
|
|
69575
|
-
if (batchSize === 0
|
|
69576
|
-
&& mintingResponse
|
|
69577
|
-
&& new Date(mintingResponse.imx_mint_requests_limit_reset) > new Date()) {
|
|
69578
|
-
logger.info(`minting limit reached, waiting for reset at ${mintingResponse?.imx_mint_requests_limit_reset}`);
|
|
69579
|
-
continue;
|
|
69580
|
-
}
|
|
69581
|
-
if (batchSize === 0) {
|
|
69582
|
-
logger.info(`minting limit has been reset, use default batch size: ${defaultBatchSize}`);
|
|
69583
|
-
mintingResponse = undefined;
|
|
69584
|
-
batchSize = defaultBatchSize;
|
|
69585
|
-
}
|
|
69586
|
-
// get mints to be submitted
|
|
69587
|
-
const pendingMints = await mintingPersistence.getNextBatchForSubmission(batchSize);
|
|
69588
|
-
if (pendingMints.length === 0) {
|
|
69589
|
-
logger.info('no assets to mint');
|
|
69590
|
-
continue;
|
|
69591
|
-
}
|
|
69592
|
-
// chunk assets by every 100 assets. every chunk should all be for the same contract address.
|
|
69593
|
-
const chunkedAssets = pendingMints.sort((a, b) => (a.contract_address > b.contract_address ? 1 : -1)).reduce((acc, row) => {
|
|
69594
|
-
if (acc.length === 0) {
|
|
69595
|
-
return [{ contractAddress: row.contract_address, assets: [row] }];
|
|
69596
|
-
}
|
|
69597
|
-
const lastBatch = acc[acc.length - 1];
|
|
69598
|
-
if (lastBatch.contractAddress === row.contract_address && lastBatch.assets.length < 100) {
|
|
69599
|
-
return [...acc.slice(0, -1), { ...lastBatch, assets: [...lastBatch.assets, row] }];
|
|
69600
|
-
}
|
|
69601
|
-
return [...acc, { contractAddress: row.contract_address, assets: [row] }];
|
|
69602
|
-
}, []);
|
|
69603
|
-
// submit minting request for each contract address in parallel
|
|
69604
|
-
const mintingResults = await Promise.allSettled(chunkedAssets.map(async ({ contractAddress, assets }) => {
|
|
69605
|
-
const mintingRequest = {
|
|
69606
|
-
chainName,
|
|
69607
|
-
contractAddress,
|
|
69608
|
-
createMintRequestRequest: {
|
|
69609
|
-
assets: assets.map((row) => ({
|
|
69610
|
-
reference_id: row.asset_id,
|
|
69611
|
-
owner_address: row.owner_address,
|
|
69612
|
-
metadata: row.metadata,
|
|
69613
|
-
})),
|
|
69614
|
-
},
|
|
69615
|
-
};
|
|
69616
|
-
try {
|
|
69617
|
-
const response = await blockchainDataSDKClient.createMintRequest(mintingRequest);
|
|
69618
|
-
logger.info(`mintingResponse: ${JSON.stringify(response, null, 2)}`);
|
|
69619
|
-
// update minting status to submitted
|
|
69620
|
-
await mintingPersistence.updateMintingStatusToSubmitted(assets.map(({ id }) => id));
|
|
69621
|
-
return response;
|
|
69622
|
-
}
|
|
69623
|
-
catch (e) {
|
|
69624
|
-
logger.error(e);
|
|
69625
|
-
if (e.code === 'CONFLICT_ERROR'
|
|
69626
|
-
&& e.details?.id === 'reference_id') {
|
|
69627
|
-
try {
|
|
69628
|
-
// mark the assets as conflicting, so that we don't send them again.
|
|
69629
|
-
await mintingPersistence.markAsConflict(e.details.values, contractAddress);
|
|
69630
|
-
// remove non conflicting assets status so that they can be retried.
|
|
69631
|
-
await mintingPersistence.resetMintingStatus(assets
|
|
69632
|
-
.map(({ id }) => id)
|
|
69633
|
-
.filter((id) => !e.details.values.includes(id)));
|
|
69634
|
-
}
|
|
69635
|
-
catch (e2) {
|
|
69636
|
-
logger.error(e2);
|
|
69637
|
-
}
|
|
69638
|
-
}
|
|
69639
|
-
else {
|
|
69640
|
-
// separate assets into "need to be retied" and "exceeded max number of tries."
|
|
69641
|
-
const { assetsToRetry, assetsExceededMaxNumberOfTries } = assets.reduce((acc, { tried_count = 0, id }) => {
|
|
69642
|
-
if (tried_count < maxNumberOfTries) {
|
|
69643
|
-
acc.assetsToRetry.push(id);
|
|
69644
|
-
}
|
|
69645
|
-
else {
|
|
69646
|
-
acc.assetsExceededMaxNumberOfTries.push(id);
|
|
69647
|
-
}
|
|
69648
|
-
return acc;
|
|
69649
|
-
}, {
|
|
69650
|
-
assetsToRetry: [],
|
|
69651
|
-
assetsExceededMaxNumberOfTries: [],
|
|
69652
|
-
});
|
|
69653
|
-
// remove all assets status so that they can be retried.
|
|
69654
|
-
await mintingPersistence.markForRetry(assetsToRetry);
|
|
69655
|
-
// mark assets that have exceeded the max number of tries as submission_failed
|
|
69656
|
-
await mintingPersistence.updateMintingStatusToSubmissionFailed(assetsExceededMaxNumberOfTries);
|
|
69657
|
-
}
|
|
69658
|
-
return e;
|
|
69659
|
-
}
|
|
69660
|
-
}));
|
|
69661
|
-
mintingResponse = mintingResults
|
|
69662
|
-
.reverse()
|
|
69663
|
-
.find((r) => r.status === 'fulfilled')?.value;
|
|
69664
|
-
}
|
|
69665
|
-
};
|
|
69666
|
-
const processMint = async (mintingPersistence, event, logger = console) => {
|
|
69667
|
-
trackProcessMint();
|
|
69668
|
-
if (event.event_name !== 'imtbl_zkevm_mint_request_updated') {
|
|
69669
|
-
logger.info(`${event.event_name} is not imtbl_zkevm_mint_request_updated, skip.`);
|
|
69670
|
-
return;
|
|
69671
|
-
}
|
|
69672
|
-
const referenceId = event.data.reference_id;
|
|
69673
|
-
if (!referenceId) {
|
|
69674
|
-
throw new Error('reference_id not found in webhook event');
|
|
69675
|
-
}
|
|
69676
|
-
const contractAddress = event.data.contract_address;
|
|
69677
|
-
if (!contractAddress) {
|
|
69678
|
-
throw new Error('contract_address not found in webhook event');
|
|
69679
|
-
}
|
|
69680
|
-
if (event.data.status === 'failed') {
|
|
69681
|
-
logger.error(`mint failed: ${JSON.stringify(event.data, null, 2)}`);
|
|
69682
|
-
}
|
|
69683
|
-
const mintReq = await mintingPersistence.getMintingRequest(contractAddress, referenceId);
|
|
69684
|
-
if (!mintReq) {
|
|
69685
|
-
logger.info(`minting request not found in the database, ${JSON.stringify(event.data)}`);
|
|
69686
|
-
}
|
|
69687
|
-
const ownerAddress = mintReq?.wallet_address || event.data.owner_address;
|
|
69688
|
-
if (!ownerAddress) {
|
|
69689
|
-
logger.error('owner_address missing');
|
|
69690
|
-
throw new Error('owner_address missing');
|
|
69691
|
-
}
|
|
69692
|
-
await mintingPersistence.syncMintingStatus({
|
|
69693
|
-
tokenId: event.data.token_id,
|
|
69694
|
-
status: event.data.status,
|
|
69695
|
-
assetId: referenceId,
|
|
69696
|
-
contractAddress,
|
|
69697
|
-
ownerAddress,
|
|
69698
|
-
metadataId: event.data.metadata_id,
|
|
69699
|
-
imtblZkevmMintRequestUpdatedId: event.event_id,
|
|
69700
|
-
error: event.data.error ? JSON.stringify(event.data.error) : null,
|
|
69701
|
-
});
|
|
69702
|
-
};
|
|
69703
|
-
|
|
69704
|
-
const noopHandlers = {
|
|
69705
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
69706
|
-
zkevmMintRequestUpdated: async (event) => { },
|
|
69707
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
69708
|
-
others: async (..._args) => { }
|
|
69709
|
-
};
|
|
69710
|
-
class MintingBackendModule {
|
|
69711
|
-
baseConfig;
|
|
69712
|
-
persistence;
|
|
69713
|
-
blockchainDataClient;
|
|
69714
|
-
logger;
|
|
69715
|
-
constructor(config) {
|
|
69716
|
-
this.baseConfig = config.baseConfig;
|
|
69717
|
-
this.persistence = config.persistence;
|
|
69718
|
-
this.logger = config.logger || console;
|
|
69719
|
-
this.blockchainDataClient = new BlockchainData({
|
|
69720
|
-
baseConfig: config.baseConfig
|
|
69721
|
-
});
|
|
69722
|
-
setEnvironment(this.baseConfig.environment);
|
|
69723
|
-
if (this.baseConfig.publishableKey) {
|
|
69724
|
-
setPublishableApiKey(this.baseConfig.publishableKey);
|
|
69725
|
-
}
|
|
69726
|
-
}
|
|
69727
|
-
async recordMint(mintRequest) {
|
|
69728
|
-
await recordMint(this.persistence, mintRequest);
|
|
69729
|
-
}
|
|
69730
|
-
async submitMintingRequests(config) {
|
|
69731
|
-
await submitMintingRequests(this.persistence, this.blockchainDataClient, config);
|
|
69732
|
-
}
|
|
69733
|
-
async processMint(body, otherHandlers = noopHandlers) {
|
|
69734
|
-
await init(body, this.baseConfig.environment, {
|
|
69735
|
-
zkevmMintRequestUpdated: async (event) => {
|
|
69736
|
-
await processMint(this.persistence, event, this.logger);
|
|
69737
|
-
otherHandlers.zkevmMintRequestUpdated(event);
|
|
69738
|
-
},
|
|
69739
|
-
others: otherHandlers.others
|
|
69740
|
-
});
|
|
69741
|
-
}
|
|
69742
|
-
}
|
|
69743
|
-
|
|
69744
|
-
var minting_backend = /*#__PURE__*/Object.freeze({
|
|
69745
|
-
__proto__: null,
|
|
69746
|
-
MintingBackendModule: MintingBackendModule,
|
|
69747
|
-
mintingPersistencePg: mintingPersistence$1,
|
|
69748
|
-
mintingPersistencePrismaSqlite: mintingPersistence,
|
|
69749
|
-
processMint: processMint,
|
|
69750
|
-
recordMint: recordMint,
|
|
69751
|
-
submitMintingRequests: submitMintingRequests
|
|
69752
|
-
});
|
|
69753
|
-
|
|
69754
|
-
export { blockchain_data as blockchainData, checkout, config, minting_backend as mintingBackend, orderbook, passport, webhook, x };
|
|
69159
|
+
export { blockchain_data as blockchainData, checkout, config, orderbook, passport, x };
|