@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.cjs
CHANGED
|
@@ -34,7 +34,6 @@ var solidity = require('@ethersproject/solidity');
|
|
|
34
34
|
var routerSdk = require('@uniswap/router-sdk');
|
|
35
35
|
var units = require('@ethersproject/units');
|
|
36
36
|
var bignumber = require('@ethersproject/bignumber');
|
|
37
|
-
var MessageValidator = require('sns-validator');
|
|
38
37
|
|
|
39
38
|
function _interopNamespaceDefault(e) {
|
|
40
39
|
var n = Object.create(null);
|
|
@@ -184,7 +183,7 @@ const flattenProperties$1 = (properties) => {
|
|
|
184
183
|
};
|
|
185
184
|
|
|
186
185
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
187
|
-
const SDK_VERSION$1 = '1.38.0
|
|
186
|
+
const SDK_VERSION$1 = '1.38.0';
|
|
188
187
|
const getFrameParentDomain$1 = () => {
|
|
189
188
|
if (isNode$1()) {
|
|
190
189
|
return '';
|
|
@@ -14211,7 +14210,7 @@ class MultiRollupApiClients {
|
|
|
14211
14210
|
}
|
|
14212
14211
|
|
|
14213
14212
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
14214
|
-
const defaultHeaders$2 = { 'x-sdk-version': 'ts-immutable-sdk-1.38.0
|
|
14213
|
+
const defaultHeaders$2 = { 'x-sdk-version': 'ts-immutable-sdk-1.38.0' };
|
|
14215
14214
|
const createConfig$1 = ({ basePath, headers, }) => {
|
|
14216
14215
|
if (!basePath.trim()) {
|
|
14217
14216
|
throw Error('basePath can not be empty');
|
|
@@ -14283,7 +14282,7 @@ class APIError extends Error {
|
|
|
14283
14282
|
|
|
14284
14283
|
/* eslint-disable implicit-arrow-linebreak */
|
|
14285
14284
|
const defaultHeaders$1 = {
|
|
14286
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.38.0
|
|
14285
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.38.0',
|
|
14287
14286
|
};
|
|
14288
14287
|
/**
|
|
14289
14288
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -14757,7 +14756,7 @@ var blockchain_data = /*#__PURE__*/Object.freeze({
|
|
|
14757
14756
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
14758
14757
|
class ApiConfiguration extends index$2.Configuration {
|
|
14759
14758
|
}
|
|
14760
|
-
const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.38.0
|
|
14759
|
+
const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.38.0' };
|
|
14761
14760
|
/**
|
|
14762
14761
|
* @dev use createImmutableXConfiguration instead
|
|
14763
14762
|
*/
|
|
@@ -14796,7 +14795,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
14796
14795
|
chainID,
|
|
14797
14796
|
coreContractAddress,
|
|
14798
14797
|
registrationContractAddress,
|
|
14799
|
-
sdkVersion: 'ts-immutable-sdk-1.38.0
|
|
14798
|
+
sdkVersion: 'ts-immutable-sdk-1.38.0',
|
|
14800
14799
|
baseConfig,
|
|
14801
14800
|
});
|
|
14802
14801
|
const production = ({ baseConfig }) => createImmutableXConfiguration({
|
|
@@ -23618,12 +23617,12 @@ function assertOptions$1(options, schema, allowUnknown) {
|
|
|
23618
23617
|
}
|
|
23619
23618
|
}
|
|
23620
23619
|
|
|
23621
|
-
var validator$
|
|
23620
|
+
var validator$1 = {
|
|
23622
23621
|
assertOptions: assertOptions$1,
|
|
23623
23622
|
validators: validators$1$1
|
|
23624
23623
|
};
|
|
23625
23624
|
|
|
23626
|
-
const validators$2 = validator$
|
|
23625
|
+
const validators$2 = validator$1.validators;
|
|
23627
23626
|
|
|
23628
23627
|
/**
|
|
23629
23628
|
* Create a new instance of Axios
|
|
@@ -23664,7 +23663,7 @@ let Axios$2 = class Axios {
|
|
|
23664
23663
|
const {transitional, paramsSerializer, headers} = config;
|
|
23665
23664
|
|
|
23666
23665
|
if (transitional !== undefined) {
|
|
23667
|
-
validator$
|
|
23666
|
+
validator$1.assertOptions(transitional, {
|
|
23668
23667
|
silentJSONParsing: validators$2.transitional(validators$2.boolean),
|
|
23669
23668
|
forcedJSONParsing: validators$2.transitional(validators$2.boolean),
|
|
23670
23669
|
clarifyTimeoutError: validators$2.transitional(validators$2.boolean)
|
|
@@ -23677,7 +23676,7 @@ let Axios$2 = class Axios {
|
|
|
23677
23676
|
serialize: paramsSerializer
|
|
23678
23677
|
};
|
|
23679
23678
|
} else {
|
|
23680
|
-
validator$
|
|
23679
|
+
validator$1.assertOptions(paramsSerializer, {
|
|
23681
23680
|
encode: validators$2.function,
|
|
23682
23681
|
serialize: validators$2.function
|
|
23683
23682
|
}, true);
|
|
@@ -32396,12 +32395,12 @@ function assertOptions(options, schema, allowUnknown) {
|
|
|
32396
32395
|
}
|
|
32397
32396
|
}
|
|
32398
32397
|
|
|
32399
|
-
var validator
|
|
32398
|
+
var validator = {
|
|
32400
32399
|
assertOptions,
|
|
32401
32400
|
validators: validators$1
|
|
32402
32401
|
};
|
|
32403
32402
|
|
|
32404
|
-
const validators = validator
|
|
32403
|
+
const validators = validator.validators;
|
|
32405
32404
|
|
|
32406
32405
|
/**
|
|
32407
32406
|
* Create a new instance of Axios
|
|
@@ -32442,7 +32441,7 @@ class Axios {
|
|
|
32442
32441
|
const {transitional, paramsSerializer, headers} = config;
|
|
32443
32442
|
|
|
32444
32443
|
if (transitional !== undefined) {
|
|
32445
|
-
validator
|
|
32444
|
+
validator.assertOptions(transitional, {
|
|
32446
32445
|
silentJSONParsing: validators.transitional(validators.boolean),
|
|
32447
32446
|
forcedJSONParsing: validators.transitional(validators.boolean),
|
|
32448
32447
|
clarifyTimeoutError: validators.transitional(validators.boolean)
|
|
@@ -32455,7 +32454,7 @@ class Axios {
|
|
|
32455
32454
|
serialize: paramsSerializer
|
|
32456
32455
|
};
|
|
32457
32456
|
} else {
|
|
32458
|
-
validator
|
|
32457
|
+
validator.assertOptions(paramsSerializer, {
|
|
32459
32458
|
encode: validators.function,
|
|
32460
32459
|
serialize: validators.function
|
|
32461
32460
|
}, true);
|
|
@@ -58214,7 +58213,7 @@ const flattenProperties = (properties) => {
|
|
|
58214
58213
|
};
|
|
58215
58214
|
|
|
58216
58215
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
58217
|
-
const SDK_VERSION = '1.38.0
|
|
58216
|
+
const SDK_VERSION = '1.38.0';
|
|
58218
58217
|
const getFrameParentDomain = () => {
|
|
58219
58218
|
if (isNode()) {
|
|
58220
58219
|
return '';
|
|
@@ -63507,7 +63506,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
|
|
|
63507
63506
|
maxPriorityFeePerGas: ethers.BigNumber.from(10e9),
|
|
63508
63507
|
};
|
|
63509
63508
|
|
|
63510
|
-
const SDK_VERSION_MARKER = '1.38.0
|
|
63509
|
+
const SDK_VERSION_MARKER = '1.38.0';
|
|
63511
63510
|
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
63512
63511
|
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
63513
63512
|
|
|
@@ -69180,605 +69179,9 @@ var x = /*#__PURE__*/Object.freeze({
|
|
|
69180
69179
|
sandbox: sandbox
|
|
69181
69180
|
});
|
|
69182
69181
|
|
|
69183
|
-
const validator = new MessageValidator();
|
|
69184
|
-
const allowedTopicArnPrefix = {
|
|
69185
|
-
[Environment$1.PRODUCTION]: 'arn:aws:sns:us-east-2:362750628221:',
|
|
69186
|
-
[Environment$1.SANDBOX]: 'arn:aws:sns:us-east-2:783421985614:'
|
|
69187
|
-
};
|
|
69188
|
-
const init = async (body, env, handlers) => {
|
|
69189
|
-
const msg = await new Promise((resolve, reject) => {
|
|
69190
|
-
validator.validate(body, (err, message) => {
|
|
69191
|
-
if (err) {
|
|
69192
|
-
return reject(err);
|
|
69193
|
-
}
|
|
69194
|
-
// check for topic arn prefix
|
|
69195
|
-
if (!message.TopicArn.startsWith(allowedTopicArnPrefix[env])) {
|
|
69196
|
-
throw new Error('Invalid topic arn');
|
|
69197
|
-
}
|
|
69198
|
-
if (message?.Type === 'SubscriptionConfirmation') {
|
|
69199
|
-
fetch(message.SubscribeURL).then(() => {
|
|
69200
|
-
resolve(message);
|
|
69201
|
-
}).catch((e) => {
|
|
69202
|
-
reject(e);
|
|
69203
|
-
});
|
|
69204
|
-
}
|
|
69205
|
-
return resolve(message);
|
|
69206
|
-
});
|
|
69207
|
-
});
|
|
69208
|
-
if (msg.Type === 'Notification') {
|
|
69209
|
-
const event = JSON.parse(msg.Message);
|
|
69210
|
-
switch (event.event_name) {
|
|
69211
|
-
case 'imtbl_zkevm_mint_request_updated':
|
|
69212
|
-
await handlers.zkevmMintRequestUpdated(event);
|
|
69213
|
-
break;
|
|
69214
|
-
default:
|
|
69215
|
-
if (handlers.others) {
|
|
69216
|
-
await handlers.others(event);
|
|
69217
|
-
}
|
|
69218
|
-
break;
|
|
69219
|
-
}
|
|
69220
|
-
}
|
|
69221
|
-
};
|
|
69222
|
-
|
|
69223
|
-
var webhook = /*#__PURE__*/Object.freeze({
|
|
69224
|
-
__proto__: null,
|
|
69225
|
-
init: init
|
|
69226
|
-
});
|
|
69227
|
-
|
|
69228
|
-
const moduleName = 'minting_backend_sdk';
|
|
69229
|
-
const trackInitializePersistencePG = () => {
|
|
69230
|
-
try {
|
|
69231
|
-
track(moduleName, 'initializePersistencePG');
|
|
69232
|
-
}
|
|
69233
|
-
catch {
|
|
69234
|
-
// ignore
|
|
69235
|
-
}
|
|
69236
|
-
};
|
|
69237
|
-
const trackInitializePersistencePrismaSqlite = () => {
|
|
69238
|
-
try {
|
|
69239
|
-
track(moduleName, 'initializePersistencePrismaSqlite');
|
|
69240
|
-
}
|
|
69241
|
-
catch {
|
|
69242
|
-
// ignore
|
|
69243
|
-
}
|
|
69244
|
-
};
|
|
69245
|
-
const trackSubmitMintingRequests = () => {
|
|
69246
|
-
try {
|
|
69247
|
-
track(moduleName, 'submitMintingRequests');
|
|
69248
|
-
}
|
|
69249
|
-
catch {
|
|
69250
|
-
// ignore
|
|
69251
|
-
}
|
|
69252
|
-
};
|
|
69253
|
-
const trackProcessMint = () => {
|
|
69254
|
-
try {
|
|
69255
|
-
track(moduleName, 'processMint');
|
|
69256
|
-
}
|
|
69257
|
-
catch {
|
|
69258
|
-
// ignore
|
|
69259
|
-
}
|
|
69260
|
-
};
|
|
69261
|
-
const trackRecordMint = () => {
|
|
69262
|
-
try {
|
|
69263
|
-
track(moduleName, 'recordMint');
|
|
69264
|
-
}
|
|
69265
|
-
catch {
|
|
69266
|
-
// ignore
|
|
69267
|
-
}
|
|
69268
|
-
};
|
|
69269
|
-
|
|
69270
|
-
const mintingPersistence$1 = (client) => {
|
|
69271
|
-
trackInitializePersistencePG();
|
|
69272
|
-
return {
|
|
69273
|
-
recordMint: async (request) => {
|
|
69274
|
-
const r = await client.query(`
|
|
69275
|
-
INSERT INTO im_assets (asset_id, contract_address, owner_address, metadata)
|
|
69276
|
-
VALUES ($1, $2, $3, $4) ON CONFLICT (asset_id, contract_address) DO NOTHING;
|
|
69277
|
-
`, [request.asset_id, request.contract_address, request.owner_address, request.metadata]);
|
|
69278
|
-
if (r.rowCount === 0) {
|
|
69279
|
-
throw new Error('Duplicated mint');
|
|
69280
|
-
}
|
|
69281
|
-
},
|
|
69282
|
-
getNextBatchForSubmission: async (limit) => {
|
|
69283
|
-
const res = await client.query(`
|
|
69284
|
-
UPDATE im_assets SET minting_status = 'submitting' WHERE minting_status IS NULL and id in (
|
|
69285
|
-
select id from im_assets where minting_status is null limit $1 for update skip locked
|
|
69286
|
-
) returning *;
|
|
69287
|
-
`, [limit]);
|
|
69288
|
-
return res.rows;
|
|
69289
|
-
},
|
|
69290
|
-
updateMintingStatusToSubmitted: async (ids) => {
|
|
69291
|
-
await client.query(`
|
|
69292
|
-
UPDATE im_assets SET minting_status = $2 WHERE id = ANY($1);
|
|
69293
|
-
`, [ids, 'submitted']);
|
|
69294
|
-
},
|
|
69295
|
-
syncMintingStatus: async (submittedMintRequest) => {
|
|
69296
|
-
// doing a upsert just in case the row has not been created yet
|
|
69297
|
-
await client.query(`
|
|
69298
|
-
INSERT INTO im_assets (
|
|
69299
|
-
asset_id,
|
|
69300
|
-
contract_address,
|
|
69301
|
-
owner_address,
|
|
69302
|
-
token_id,
|
|
69303
|
-
minting_status,
|
|
69304
|
-
metadata_id,
|
|
69305
|
-
last_imtbl_zkevm_mint_request_updated_id,
|
|
69306
|
-
error
|
|
69307
|
-
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) ON CONFLICT (asset_id, contract_address)
|
|
69308
|
-
DO UPDATE SET
|
|
69309
|
-
owner_address = $3,
|
|
69310
|
-
token_id = $4,
|
|
69311
|
-
minting_status = $5,
|
|
69312
|
-
metadata_id = $6,
|
|
69313
|
-
last_imtbl_zkevm_mint_request_updated_id = $7,
|
|
69314
|
-
error = $8
|
|
69315
|
-
where (
|
|
69316
|
-
im_assets.last_imtbl_zkevm_mint_request_updated_id < $7 OR
|
|
69317
|
-
im_assets.last_imtbl_zkevm_mint_request_updated_id is null
|
|
69318
|
-
);
|
|
69319
|
-
`, [
|
|
69320
|
-
submittedMintRequest.assetId,
|
|
69321
|
-
submittedMintRequest.contractAddress,
|
|
69322
|
-
submittedMintRequest.ownerAddress,
|
|
69323
|
-
submittedMintRequest.tokenId,
|
|
69324
|
-
submittedMintRequest.status,
|
|
69325
|
-
submittedMintRequest.metadataId,
|
|
69326
|
-
submittedMintRequest.imtblZkevmMintRequestUpdatedId,
|
|
69327
|
-
submittedMintRequest.error
|
|
69328
|
-
]);
|
|
69329
|
-
},
|
|
69330
|
-
markAsConflict: async (assetIds, contractAddress) => {
|
|
69331
|
-
await client.query(`
|
|
69332
|
-
UPDATE im_assets
|
|
69333
|
-
SET minting_status = 'conflicting'
|
|
69334
|
-
WHERE asset_id = ANY($1)
|
|
69335
|
-
AND contract_address = $2;
|
|
69336
|
-
`, [assetIds, contractAddress]);
|
|
69337
|
-
},
|
|
69338
|
-
resetMintingStatus: async (ids) => {
|
|
69339
|
-
await client.query(`
|
|
69340
|
-
UPDATE im_assets SET minting_status = null WHERE id = ANY($1);
|
|
69341
|
-
`, [ids]);
|
|
69342
|
-
},
|
|
69343
|
-
markForRetry: async (ids) => {
|
|
69344
|
-
await client.query(`
|
|
69345
|
-
UPDATE im_assets
|
|
69346
|
-
SET minting_status = null, tried_count = tried_count + 1 WHERE id = ANY($1);
|
|
69347
|
-
`, [ids]);
|
|
69348
|
-
},
|
|
69349
|
-
updateMintingStatusToSubmissionFailed: async (ids) => {
|
|
69350
|
-
await client.query(`
|
|
69351
|
-
UPDATE im_assets SET minting_status = 'submission_failed' WHERE id = ANY($1);
|
|
69352
|
-
`, [ids]);
|
|
69353
|
-
},
|
|
69354
|
-
getMintingRequest: async (contractAddress, referenceId) => {
|
|
69355
|
-
const res = await client.query(`
|
|
69356
|
-
SELECT * FROM im_assets WHERE contract_address = $1 and asset_id = $2;
|
|
69357
|
-
`, [contractAddress, referenceId]);
|
|
69358
|
-
return res.rows[0] || null;
|
|
69359
|
-
}
|
|
69360
|
-
};
|
|
69361
|
-
};
|
|
69362
|
-
|
|
69363
|
-
/* eslint-disable no-await-in-loop */
|
|
69364
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
69365
|
-
// client is a PrismaClient instance. it needs to be generated with
|
|
69366
|
-
// additional schema defined inside (TODO: point to repo) file.
|
|
69367
|
-
const mintingPersistence = (client) => {
|
|
69368
|
-
trackInitializePersistencePrismaSqlite();
|
|
69369
|
-
return {
|
|
69370
|
-
recordMint: async (request) => {
|
|
69371
|
-
const result = await client.imAssets.upsert({
|
|
69372
|
-
where: {
|
|
69373
|
-
im_assets_uindex: {
|
|
69374
|
-
assetId: request.asset_id, contractAddress: request.contract_address
|
|
69375
|
-
}
|
|
69376
|
-
},
|
|
69377
|
-
update: {},
|
|
69378
|
-
create: {
|
|
69379
|
-
assetId: request.asset_id,
|
|
69380
|
-
contractAddress: request.contract_address,
|
|
69381
|
-
ownerAddress: request.owner_address,
|
|
69382
|
-
metadata: JSON.stringify(request.metadata), // Serialize JSON metadata
|
|
69383
|
-
},
|
|
69384
|
-
});
|
|
69385
|
-
// Since upsert does not throw on update and does not tell directly if it updated or inserted,
|
|
69386
|
-
// we need to add additional logic to handle this if "result" does not provide enough info.
|
|
69387
|
-
if (!result) {
|
|
69388
|
-
throw new Error('Duplicated mint');
|
|
69389
|
-
}
|
|
69390
|
-
},
|
|
69391
|
-
// WARNING: this is NOT concurrency safe. Please only call this method one at a time.
|
|
69392
|
-
getNextBatchForSubmission: async (limit) => {
|
|
69393
|
-
const assets = await client.imAssets.findMany({
|
|
69394
|
-
where: {
|
|
69395
|
-
mintingStatus: null
|
|
69396
|
-
},
|
|
69397
|
-
take: limit
|
|
69398
|
-
});
|
|
69399
|
-
const assetIds = assets.map((asset) => asset.id);
|
|
69400
|
-
await client.imAssets.updateMany({
|
|
69401
|
-
where: {
|
|
69402
|
-
id: {
|
|
69403
|
-
in: assetIds
|
|
69404
|
-
}
|
|
69405
|
-
},
|
|
69406
|
-
data: {
|
|
69407
|
-
mintingStatus: 'submitting'
|
|
69408
|
-
}
|
|
69409
|
-
});
|
|
69410
|
-
const updatedAssets = await client.imAssets.findMany({
|
|
69411
|
-
where: {
|
|
69412
|
-
id: {
|
|
69413
|
-
in: assetIds
|
|
69414
|
-
}
|
|
69415
|
-
}
|
|
69416
|
-
});
|
|
69417
|
-
return updatedAssets.map((asset) => ({
|
|
69418
|
-
id: asset.id,
|
|
69419
|
-
contract_address: asset.contractAddress,
|
|
69420
|
-
wallet_address: asset.ownerAddress,
|
|
69421
|
-
asset_id: asset.assetId,
|
|
69422
|
-
metadata: asset.metadata ? JSON.parse(asset.metadata) : null,
|
|
69423
|
-
owner_address: asset.ownerAddress,
|
|
69424
|
-
tried_count: asset.triedCount,
|
|
69425
|
-
}));
|
|
69426
|
-
},
|
|
69427
|
-
updateMintingStatusToSubmitted: async (ids) => {
|
|
69428
|
-
await client.imAssets.updateMany({
|
|
69429
|
-
where: {
|
|
69430
|
-
id: {
|
|
69431
|
-
in: ids
|
|
69432
|
-
}
|
|
69433
|
-
},
|
|
69434
|
-
data: {
|
|
69435
|
-
mintingStatus: 'submitted'
|
|
69436
|
-
}
|
|
69437
|
-
});
|
|
69438
|
-
},
|
|
69439
|
-
syncMintingStatus: async (submittedMintRequest) => {
|
|
69440
|
-
// First, attempt to retrieve the existing asset
|
|
69441
|
-
const existingAsset = await client.imAssets.findUnique({
|
|
69442
|
-
where: {
|
|
69443
|
-
im_assets_uindex: {
|
|
69444
|
-
assetId: submittedMintRequest.assetId,
|
|
69445
|
-
contractAddress: submittedMintRequest.contractAddress,
|
|
69446
|
-
},
|
|
69447
|
-
}
|
|
69448
|
-
});
|
|
69449
|
-
// Check if the asset exists and the condition for updating is met
|
|
69450
|
-
if (existingAsset && (existingAsset.lastImtblZkevmMintRequestUpdatedId === null
|
|
69451
|
-
|| existingAsset.lastImtblZkevmMintRequestUpdatedId < submittedMintRequest.imtblZkevmMintRequestUpdatedId)) {
|
|
69452
|
-
// Perform update if the existing record's lastImtblZkevmMintRequestUpdatedId is less than the new one or is null
|
|
69453
|
-
await client.imAssets.update({
|
|
69454
|
-
where: {
|
|
69455
|
-
im_assets_uindex: {
|
|
69456
|
-
assetId: submittedMintRequest.assetId,
|
|
69457
|
-
contractAddress: submittedMintRequest.contractAddress,
|
|
69458
|
-
},
|
|
69459
|
-
},
|
|
69460
|
-
data: {
|
|
69461
|
-
ownerAddress: submittedMintRequest.ownerAddress,
|
|
69462
|
-
tokenId: submittedMintRequest.tokenId,
|
|
69463
|
-
mintingStatus: submittedMintRequest.status,
|
|
69464
|
-
metadataId: submittedMintRequest.metadataId,
|
|
69465
|
-
lastImtblZkevmMintRequestUpdatedId: submittedMintRequest.imtblZkevmMintRequestUpdatedId,
|
|
69466
|
-
error: submittedMintRequest.error,
|
|
69467
|
-
}
|
|
69468
|
-
});
|
|
69469
|
-
}
|
|
69470
|
-
else if (!existingAsset) {
|
|
69471
|
-
// Perform insert if no existing record is found
|
|
69472
|
-
await client.imAssets.create({
|
|
69473
|
-
data: {
|
|
69474
|
-
assetId: submittedMintRequest.assetId,
|
|
69475
|
-
contractAddress: submittedMintRequest.contractAddress,
|
|
69476
|
-
ownerAddress: submittedMintRequest.ownerAddress,
|
|
69477
|
-
tokenId: submittedMintRequest.tokenId,
|
|
69478
|
-
mintingStatus: submittedMintRequest.status,
|
|
69479
|
-
metadataId: submittedMintRequest.metadataId,
|
|
69480
|
-
lastImtblZkevmMintRequestUpdatedId: submittedMintRequest.imtblZkevmMintRequestUpdatedId,
|
|
69481
|
-
error: submittedMintRequest.error,
|
|
69482
|
-
}
|
|
69483
|
-
});
|
|
69484
|
-
}
|
|
69485
|
-
// If existing asset does not meet the update condition, do nothing
|
|
69486
|
-
},
|
|
69487
|
-
updateMintingStatusToSubmissionFailed: async (ids) => {
|
|
69488
|
-
await client.imAssets.updateMany({
|
|
69489
|
-
where: {
|
|
69490
|
-
id: {
|
|
69491
|
-
in: ids
|
|
69492
|
-
}
|
|
69493
|
-
},
|
|
69494
|
-
data: {
|
|
69495
|
-
mintingStatus: 'submission_failed'
|
|
69496
|
-
}
|
|
69497
|
-
});
|
|
69498
|
-
},
|
|
69499
|
-
markAsConflict: async (assetIds, contractAddress) => {
|
|
69500
|
-
await client.imAssets.updateMany({
|
|
69501
|
-
where: {
|
|
69502
|
-
assetId: {
|
|
69503
|
-
in: assetIds // Targets assets where assetId is in the provided list
|
|
69504
|
-
},
|
|
69505
|
-
contractAddress // Additional condition for contract address
|
|
69506
|
-
},
|
|
69507
|
-
data: {
|
|
69508
|
-
mintingStatus: 'conflicting' // Set the new status
|
|
69509
|
-
}
|
|
69510
|
-
});
|
|
69511
|
-
},
|
|
69512
|
-
resetMintingStatus: async (ids) => {
|
|
69513
|
-
await client.imAssets.updateMany({
|
|
69514
|
-
where: {
|
|
69515
|
-
id: {
|
|
69516
|
-
in: ids // Condition to match ids
|
|
69517
|
-
}
|
|
69518
|
-
},
|
|
69519
|
-
data: {
|
|
69520
|
-
mintingStatus: null // Setting minting_status to null
|
|
69521
|
-
}
|
|
69522
|
-
});
|
|
69523
|
-
},
|
|
69524
|
-
// this method is not concurrency safe
|
|
69525
|
-
markForRetry: async (ids) => {
|
|
69526
|
-
// Retrieve the current values of tried_count for the specified ids
|
|
69527
|
-
const assets = await client.imAssets.findMany({
|
|
69528
|
-
where: {
|
|
69529
|
-
id: {
|
|
69530
|
-
in: ids
|
|
69531
|
-
}
|
|
69532
|
-
},
|
|
69533
|
-
select: {
|
|
69534
|
-
id: true,
|
|
69535
|
-
triedCount: true // Assuming the field is named triedCount
|
|
69536
|
-
}
|
|
69537
|
-
});
|
|
69538
|
-
// Update each asset with the new tried_count and nullify minting_status
|
|
69539
|
-
for (const asset of assets) {
|
|
69540
|
-
await client.imAssets.update({
|
|
69541
|
-
where: {
|
|
69542
|
-
id: asset.id
|
|
69543
|
-
},
|
|
69544
|
-
data: {
|
|
69545
|
-
mintingStatus: null,
|
|
69546
|
-
triedCount: asset.triedCount + 1
|
|
69547
|
-
}
|
|
69548
|
-
});
|
|
69549
|
-
}
|
|
69550
|
-
},
|
|
69551
|
-
getMintingRequest: async (contractAddress, referenceId) => {
|
|
69552
|
-
// Retrieve the asset from the database based on contract_address and asset_id
|
|
69553
|
-
const asset = await client.imAssets.findFirst({
|
|
69554
|
-
where: {
|
|
69555
|
-
contractAddress,
|
|
69556
|
-
assetId: referenceId
|
|
69557
|
-
}
|
|
69558
|
-
});
|
|
69559
|
-
if (!asset) {
|
|
69560
|
-
return null;
|
|
69561
|
-
}
|
|
69562
|
-
return {
|
|
69563
|
-
asset_id: asset.assetId,
|
|
69564
|
-
contract_address: asset.contractAddress,
|
|
69565
|
-
id: asset.id,
|
|
69566
|
-
metadata: asset.metadata ? JSON.parse(asset.metadata) : null,
|
|
69567
|
-
owner_address: asset.ownerAddress,
|
|
69568
|
-
tried_count: asset.triedCount,
|
|
69569
|
-
wallet_address: asset.ownerAddress
|
|
69570
|
-
};
|
|
69571
|
-
}
|
|
69572
|
-
};
|
|
69573
|
-
};
|
|
69574
|
-
|
|
69575
|
-
// TODO: expose metrics
|
|
69576
|
-
// - submitting status count, conflicting status count
|
|
69577
|
-
// - failed events count
|
|
69578
|
-
const recordMint = async (mintingPersistence, mintRequest) => {
|
|
69579
|
-
trackRecordMint();
|
|
69580
|
-
mintingPersistence.recordMint(mintRequest);
|
|
69581
|
-
};
|
|
69582
|
-
const defaultMintingDelay = 1000;
|
|
69583
|
-
// This function can be called in different node process and will run in parallel to mint assets.
|
|
69584
|
-
// Each process will NOT mint the same asset.
|
|
69585
|
-
// Monitor your database to see if parallel processes are saturating the database CPU and triggering excessive vacuuming.
|
|
69586
|
-
// default batch size will be treated as 100 when it exceeds 100 because minting API has a limit of 100 assets per request.
|
|
69587
|
-
const submitMintingRequests = async (mintingPersistence, blockchainDataSDKClient, { defaultBatchSize = 1000, chainName = 'imtbl-zkevm-testnet', maxNumberOfTries = 3, }, logger = console) => {
|
|
69588
|
-
trackSubmitMintingRequests();
|
|
69589
|
-
let mintingResponse;
|
|
69590
|
-
// eslint-disable-next-line no-constant-condition
|
|
69591
|
-
while (true) {
|
|
69592
|
-
await new Promise((resolve) => {
|
|
69593
|
-
setTimeout(resolve, defaultMintingDelay);
|
|
69594
|
-
});
|
|
69595
|
-
let batchSize = Math.min(mintingResponse?.imx_remaining_mint_requests
|
|
69596
|
-
? parseInt(mintingResponse.imx_remaining_mint_requests, 10)
|
|
69597
|
-
: defaultBatchSize, defaultBatchSize);
|
|
69598
|
-
if (batchSize === 0
|
|
69599
|
-
&& mintingResponse
|
|
69600
|
-
&& new Date(mintingResponse.imx_mint_requests_limit_reset) > new Date()) {
|
|
69601
|
-
logger.info(`minting limit reached, waiting for reset at ${mintingResponse?.imx_mint_requests_limit_reset}`);
|
|
69602
|
-
continue;
|
|
69603
|
-
}
|
|
69604
|
-
if (batchSize === 0) {
|
|
69605
|
-
logger.info(`minting limit has been reset, use default batch size: ${defaultBatchSize}`);
|
|
69606
|
-
mintingResponse = undefined;
|
|
69607
|
-
batchSize = defaultBatchSize;
|
|
69608
|
-
}
|
|
69609
|
-
// get mints to be submitted
|
|
69610
|
-
const pendingMints = await mintingPersistence.getNextBatchForSubmission(batchSize);
|
|
69611
|
-
if (pendingMints.length === 0) {
|
|
69612
|
-
logger.info('no assets to mint');
|
|
69613
|
-
continue;
|
|
69614
|
-
}
|
|
69615
|
-
// chunk assets by every 100 assets. every chunk should all be for the same contract address.
|
|
69616
|
-
const chunkedAssets = pendingMints.sort((a, b) => (a.contract_address > b.contract_address ? 1 : -1)).reduce((acc, row) => {
|
|
69617
|
-
if (acc.length === 0) {
|
|
69618
|
-
return [{ contractAddress: row.contract_address, assets: [row] }];
|
|
69619
|
-
}
|
|
69620
|
-
const lastBatch = acc[acc.length - 1];
|
|
69621
|
-
if (lastBatch.contractAddress === row.contract_address && lastBatch.assets.length < 100) {
|
|
69622
|
-
return [...acc.slice(0, -1), { ...lastBatch, assets: [...lastBatch.assets, row] }];
|
|
69623
|
-
}
|
|
69624
|
-
return [...acc, { contractAddress: row.contract_address, assets: [row] }];
|
|
69625
|
-
}, []);
|
|
69626
|
-
// submit minting request for each contract address in parallel
|
|
69627
|
-
const mintingResults = await Promise.allSettled(chunkedAssets.map(async ({ contractAddress, assets }) => {
|
|
69628
|
-
const mintingRequest = {
|
|
69629
|
-
chainName,
|
|
69630
|
-
contractAddress,
|
|
69631
|
-
createMintRequestRequest: {
|
|
69632
|
-
assets: assets.map((row) => ({
|
|
69633
|
-
reference_id: row.asset_id,
|
|
69634
|
-
owner_address: row.owner_address,
|
|
69635
|
-
metadata: row.metadata,
|
|
69636
|
-
})),
|
|
69637
|
-
},
|
|
69638
|
-
};
|
|
69639
|
-
try {
|
|
69640
|
-
const response = await blockchainDataSDKClient.createMintRequest(mintingRequest);
|
|
69641
|
-
logger.info(`mintingResponse: ${JSON.stringify(response, null, 2)}`);
|
|
69642
|
-
// update minting status to submitted
|
|
69643
|
-
await mintingPersistence.updateMintingStatusToSubmitted(assets.map(({ id }) => id));
|
|
69644
|
-
return response;
|
|
69645
|
-
}
|
|
69646
|
-
catch (e) {
|
|
69647
|
-
logger.error(e);
|
|
69648
|
-
if (e.code === 'CONFLICT_ERROR'
|
|
69649
|
-
&& e.details?.id === 'reference_id') {
|
|
69650
|
-
try {
|
|
69651
|
-
// mark the assets as conflicting, so that we don't send them again.
|
|
69652
|
-
await mintingPersistence.markAsConflict(e.details.values, contractAddress);
|
|
69653
|
-
// remove non conflicting assets status so that they can be retried.
|
|
69654
|
-
await mintingPersistence.resetMintingStatus(assets
|
|
69655
|
-
.map(({ id }) => id)
|
|
69656
|
-
.filter((id) => !e.details.values.includes(id)));
|
|
69657
|
-
}
|
|
69658
|
-
catch (e2) {
|
|
69659
|
-
logger.error(e2);
|
|
69660
|
-
}
|
|
69661
|
-
}
|
|
69662
|
-
else {
|
|
69663
|
-
// separate assets into "need to be retied" and "exceeded max number of tries."
|
|
69664
|
-
const { assetsToRetry, assetsExceededMaxNumberOfTries } = assets.reduce((acc, { tried_count = 0, id }) => {
|
|
69665
|
-
if (tried_count < maxNumberOfTries) {
|
|
69666
|
-
acc.assetsToRetry.push(id);
|
|
69667
|
-
}
|
|
69668
|
-
else {
|
|
69669
|
-
acc.assetsExceededMaxNumberOfTries.push(id);
|
|
69670
|
-
}
|
|
69671
|
-
return acc;
|
|
69672
|
-
}, {
|
|
69673
|
-
assetsToRetry: [],
|
|
69674
|
-
assetsExceededMaxNumberOfTries: [],
|
|
69675
|
-
});
|
|
69676
|
-
// remove all assets status so that they can be retried.
|
|
69677
|
-
await mintingPersistence.markForRetry(assetsToRetry);
|
|
69678
|
-
// mark assets that have exceeded the max number of tries as submission_failed
|
|
69679
|
-
await mintingPersistence.updateMintingStatusToSubmissionFailed(assetsExceededMaxNumberOfTries);
|
|
69680
|
-
}
|
|
69681
|
-
return e;
|
|
69682
|
-
}
|
|
69683
|
-
}));
|
|
69684
|
-
mintingResponse = mintingResults
|
|
69685
|
-
.reverse()
|
|
69686
|
-
.find((r) => r.status === 'fulfilled')?.value;
|
|
69687
|
-
}
|
|
69688
|
-
};
|
|
69689
|
-
const processMint = async (mintingPersistence, event, logger = console) => {
|
|
69690
|
-
trackProcessMint();
|
|
69691
|
-
if (event.event_name !== 'imtbl_zkevm_mint_request_updated') {
|
|
69692
|
-
logger.info(`${event.event_name} is not imtbl_zkevm_mint_request_updated, skip.`);
|
|
69693
|
-
return;
|
|
69694
|
-
}
|
|
69695
|
-
const referenceId = event.data.reference_id;
|
|
69696
|
-
if (!referenceId) {
|
|
69697
|
-
throw new Error('reference_id not found in webhook event');
|
|
69698
|
-
}
|
|
69699
|
-
const contractAddress = event.data.contract_address;
|
|
69700
|
-
if (!contractAddress) {
|
|
69701
|
-
throw new Error('contract_address not found in webhook event');
|
|
69702
|
-
}
|
|
69703
|
-
if (event.data.status === 'failed') {
|
|
69704
|
-
logger.error(`mint failed: ${JSON.stringify(event.data, null, 2)}`);
|
|
69705
|
-
}
|
|
69706
|
-
const mintReq = await mintingPersistence.getMintingRequest(contractAddress, referenceId);
|
|
69707
|
-
if (!mintReq) {
|
|
69708
|
-
logger.info(`minting request not found in the database, ${JSON.stringify(event.data)}`);
|
|
69709
|
-
}
|
|
69710
|
-
const ownerAddress = mintReq?.wallet_address || event.data.owner_address;
|
|
69711
|
-
if (!ownerAddress) {
|
|
69712
|
-
logger.error('owner_address missing');
|
|
69713
|
-
throw new Error('owner_address missing');
|
|
69714
|
-
}
|
|
69715
|
-
await mintingPersistence.syncMintingStatus({
|
|
69716
|
-
tokenId: event.data.token_id,
|
|
69717
|
-
status: event.data.status,
|
|
69718
|
-
assetId: referenceId,
|
|
69719
|
-
contractAddress,
|
|
69720
|
-
ownerAddress,
|
|
69721
|
-
metadataId: event.data.metadata_id,
|
|
69722
|
-
imtblZkevmMintRequestUpdatedId: event.event_id,
|
|
69723
|
-
error: event.data.error ? JSON.stringify(event.data.error) : null,
|
|
69724
|
-
});
|
|
69725
|
-
};
|
|
69726
|
-
|
|
69727
|
-
const noopHandlers = {
|
|
69728
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
69729
|
-
zkevmMintRequestUpdated: async (event) => { },
|
|
69730
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
69731
|
-
others: async (..._args) => { }
|
|
69732
|
-
};
|
|
69733
|
-
class MintingBackendModule {
|
|
69734
|
-
baseConfig;
|
|
69735
|
-
persistence;
|
|
69736
|
-
blockchainDataClient;
|
|
69737
|
-
logger;
|
|
69738
|
-
constructor(config) {
|
|
69739
|
-
this.baseConfig = config.baseConfig;
|
|
69740
|
-
this.persistence = config.persistence;
|
|
69741
|
-
this.logger = config.logger || console;
|
|
69742
|
-
this.blockchainDataClient = new BlockchainData({
|
|
69743
|
-
baseConfig: config.baseConfig
|
|
69744
|
-
});
|
|
69745
|
-
setEnvironment(this.baseConfig.environment);
|
|
69746
|
-
if (this.baseConfig.publishableKey) {
|
|
69747
|
-
setPublishableApiKey(this.baseConfig.publishableKey);
|
|
69748
|
-
}
|
|
69749
|
-
}
|
|
69750
|
-
async recordMint(mintRequest) {
|
|
69751
|
-
await recordMint(this.persistence, mintRequest);
|
|
69752
|
-
}
|
|
69753
|
-
async submitMintingRequests(config) {
|
|
69754
|
-
await submitMintingRequests(this.persistence, this.blockchainDataClient, config);
|
|
69755
|
-
}
|
|
69756
|
-
async processMint(body, otherHandlers = noopHandlers) {
|
|
69757
|
-
await init(body, this.baseConfig.environment, {
|
|
69758
|
-
zkevmMintRequestUpdated: async (event) => {
|
|
69759
|
-
await processMint(this.persistence, event, this.logger);
|
|
69760
|
-
otherHandlers.zkevmMintRequestUpdated(event);
|
|
69761
|
-
},
|
|
69762
|
-
others: otherHandlers.others
|
|
69763
|
-
});
|
|
69764
|
-
}
|
|
69765
|
-
}
|
|
69766
|
-
|
|
69767
|
-
var minting_backend = /*#__PURE__*/Object.freeze({
|
|
69768
|
-
__proto__: null,
|
|
69769
|
-
MintingBackendModule: MintingBackendModule,
|
|
69770
|
-
mintingPersistencePg: mintingPersistence$1,
|
|
69771
|
-
mintingPersistencePrismaSqlite: mintingPersistence,
|
|
69772
|
-
processMint: processMint,
|
|
69773
|
-
recordMint: recordMint,
|
|
69774
|
-
submitMintingRequests: submitMintingRequests
|
|
69775
|
-
});
|
|
69776
|
-
|
|
69777
69182
|
exports.blockchainData = blockchain_data;
|
|
69778
69183
|
exports.checkout = checkout;
|
|
69779
69184
|
exports.config = config;
|
|
69780
|
-
exports.mintingBackend = minting_backend;
|
|
69781
69185
|
exports.orderbook = orderbook;
|
|
69782
69186
|
exports.passport = passport;
|
|
69783
|
-
exports.webhook = webhook;
|
|
69784
69187
|
exports.x = x;
|