@imtbl/sdk 1.35.1-alpha → 1.35.2-alpha.1
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 +22 -22
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +51 -222
- package/dist/index.d.ts +5 -10
- package/dist/index.js +51 -222
- package/dist/minting_backend.d.ts +5 -9
- package/dist/minting_backend.js +26 -213
- package/dist/orderbook.js +1 -1
- package/dist/passport.js +21 -4
- package/dist/webhook.js +2 -2
- package/dist/x.js +3 -3
- package/package.json +2 -3
package/dist/index.js
CHANGED
|
@@ -161,7 +161,7 @@ const flattenProperties$1 = (properties) => {
|
|
|
161
161
|
};
|
|
162
162
|
|
|
163
163
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
164
|
-
const SDK_VERSION$1 = '1.35.
|
|
164
|
+
const SDK_VERSION$1 = '1.35.2-alpha.1';
|
|
165
165
|
const getFrameParentDomain$1 = () => {
|
|
166
166
|
if (isNode$1()) {
|
|
167
167
|
return '';
|
|
@@ -14188,7 +14188,7 @@ class MultiRollupApiClients {
|
|
|
14188
14188
|
}
|
|
14189
14189
|
|
|
14190
14190
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
14191
|
-
const defaultHeaders$2 = { 'x-sdk-version': 'ts-immutable-sdk-1.35.
|
|
14191
|
+
const defaultHeaders$2 = { 'x-sdk-version': 'ts-immutable-sdk-1.35.2-alpha.1' };
|
|
14192
14192
|
const createConfig$1 = ({ basePath, headers, }) => {
|
|
14193
14193
|
if (!basePath.trim()) {
|
|
14194
14194
|
throw Error('basePath can not be empty');
|
|
@@ -14260,7 +14260,7 @@ class APIError extends Error {
|
|
|
14260
14260
|
|
|
14261
14261
|
/* eslint-disable implicit-arrow-linebreak */
|
|
14262
14262
|
const defaultHeaders$1 = {
|
|
14263
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.35.
|
|
14263
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.35.2-alpha.1',
|
|
14264
14264
|
};
|
|
14265
14265
|
/**
|
|
14266
14266
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -14734,7 +14734,7 @@ var blockchain_data = /*#__PURE__*/Object.freeze({
|
|
|
14734
14734
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
14735
14735
|
class ApiConfiguration extends index$2.Configuration {
|
|
14736
14736
|
}
|
|
14737
|
-
const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.35.
|
|
14737
|
+
const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.35.2-alpha.1' };
|
|
14738
14738
|
/**
|
|
14739
14739
|
* @dev use createImmutableXConfiguration instead
|
|
14740
14740
|
*/
|
|
@@ -14773,7 +14773,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
14773
14773
|
chainID,
|
|
14774
14774
|
coreContractAddress,
|
|
14775
14775
|
registrationContractAddress,
|
|
14776
|
-
sdkVersion: 'ts-immutable-sdk-1.35.
|
|
14776
|
+
sdkVersion: 'ts-immutable-sdk-1.35.2-alpha.1',
|
|
14777
14777
|
baseConfig,
|
|
14778
14778
|
});
|
|
14779
14779
|
const production = ({ baseConfig }) => createImmutableXConfiguration({
|
|
@@ -26353,6 +26353,7 @@ const getOverlay = (contents) => `
|
|
|
26353
26353
|
height: 100% !important;
|
|
26354
26354
|
background: rgba(13, 13, 13, 0.48) !important;
|
|
26355
26355
|
backdrop-filter: blur(28px) !important;
|
|
26356
|
+
-webkit-backdrop-filter: blur(28px) !important;
|
|
26356
26357
|
display: flex !important;
|
|
26357
26358
|
flex-direction: column !important;
|
|
26358
26359
|
justify-content: center !important;
|
|
@@ -26381,6 +26382,19 @@ const getOverlay = (contents) => `
|
|
|
26381
26382
|
</div>
|
|
26382
26383
|
</div>
|
|
26383
26384
|
`;
|
|
26385
|
+
function addLink({ id, href, rel, crossOrigin, }) {
|
|
26386
|
+
const fullId = `${PASSPORT_OVERLAY_ID}-${id}`;
|
|
26387
|
+
if (!document.getElementById(fullId)) {
|
|
26388
|
+
const link = document.createElement('link');
|
|
26389
|
+
link.id = fullId;
|
|
26390
|
+
link.href = href;
|
|
26391
|
+
if (rel)
|
|
26392
|
+
link.rel = rel;
|
|
26393
|
+
if (crossOrigin)
|
|
26394
|
+
link.crossOrigin = crossOrigin;
|
|
26395
|
+
document.head.appendChild(link);
|
|
26396
|
+
}
|
|
26397
|
+
}
|
|
26384
26398
|
const getBlockedOverlay = () => getOverlay(getBlockedContents());
|
|
26385
26399
|
const getGenericOverlay = () => getOverlay(getGenericContents());
|
|
26386
26400
|
|
|
@@ -26422,6 +26436,9 @@ class Overlay {
|
|
|
26422
26436
|
}
|
|
26423
26437
|
appendOverlay() {
|
|
26424
26438
|
if (!this.overlay) {
|
|
26439
|
+
addLink({ id: 'link-googleapis', href: 'https://fonts.googleapis.com' });
|
|
26440
|
+
addLink({ id: 'link-gstatic', href: 'https://fonts.gstatic.com', crossOrigin: 'anonymous' });
|
|
26441
|
+
addLink({ id: 'link-roboto', href: 'https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,500;0,700;1,400;1,500;1,700&display=swap', rel: 'stylesheet' });
|
|
26425
26442
|
const overlay = document.createElement('div');
|
|
26426
26443
|
overlay.innerHTML = this.isBlockedOverlay ? getBlockedOverlay() : getGenericOverlay();
|
|
26427
26444
|
document.body.insertAdjacentElement('beforeend', overlay);
|
|
@@ -58093,7 +58110,7 @@ const flattenProperties = (properties) => {
|
|
|
58093
58110
|
};
|
|
58094
58111
|
|
|
58095
58112
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
58096
|
-
const SDK_VERSION = '1.35.
|
|
58113
|
+
const SDK_VERSION = '1.35.2-alpha.1';
|
|
58097
58114
|
const getFrameParentDomain = () => {
|
|
58098
58115
|
if (isNode()) {
|
|
58099
58116
|
return '';
|
|
@@ -63386,7 +63403,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
|
|
|
63386
63403
|
maxPriorityFeePerGas: BigNumber$1.from(10e9),
|
|
63387
63404
|
};
|
|
63388
63405
|
|
|
63389
|
-
const SDK_VERSION_MARKER = '1.35.
|
|
63406
|
+
const SDK_VERSION_MARKER = '1.35.2-alpha.1';
|
|
63390
63407
|
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
63391
63408
|
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
63392
63409
|
|
|
@@ -69059,7 +69076,7 @@ const init = async (body, env, handlers) => {
|
|
|
69059
69076
|
return reject(err);
|
|
69060
69077
|
}
|
|
69061
69078
|
// check for topic arn prefix
|
|
69062
|
-
if (!
|
|
69079
|
+
if (!msg.TopicArn.startsWith(allowedTopicArnPrefix[env])) {
|
|
69063
69080
|
throw new Error('Invalid topic arn');
|
|
69064
69081
|
}
|
|
69065
69082
|
if (message?.Type === 'SubscriptionConfirmation') {
|
|
@@ -69092,7 +69109,27 @@ var webhook = /*#__PURE__*/Object.freeze({
|
|
|
69092
69109
|
init: init
|
|
69093
69110
|
});
|
|
69094
69111
|
|
|
69095
|
-
|
|
69112
|
+
/* eslint-disable no-console */
|
|
69113
|
+
/* eslint-disable global-require */
|
|
69114
|
+
let optionalPackage = null;
|
|
69115
|
+
let pgClient = null;
|
|
69116
|
+
try {
|
|
69117
|
+
optionalPackage = require('pg');
|
|
69118
|
+
pgClient = new optionalPackage.Pool({
|
|
69119
|
+
user: process.env.PG_USER || 'postgres',
|
|
69120
|
+
host: process.env.PG_HOST || 'localhost',
|
|
69121
|
+
database: process.env.PG_DB_NAME || 'nullus',
|
|
69122
|
+
password: process.env.PG_PASSWORD || 'postgres',
|
|
69123
|
+
port: parseInt(process.env.PG_PORT || '5432', 10) || 5432,
|
|
69124
|
+
});
|
|
69125
|
+
}
|
|
69126
|
+
catch (error) {
|
|
69127
|
+
console.error('pg is not installed. Please install it by running `npm install pg`');
|
|
69128
|
+
optionalPackage = null;
|
|
69129
|
+
}
|
|
69130
|
+
const client = pgClient;
|
|
69131
|
+
|
|
69132
|
+
const mintingPersistence = {
|
|
69096
69133
|
recordMint: async (request) => {
|
|
69097
69134
|
const r = await client.query(`
|
|
69098
69135
|
INSERT INTO im_assets (asset_id, contract_address, owner_address, metadata)
|
|
@@ -69160,7 +69197,7 @@ const mintingPersistence$1 = (client) => ({
|
|
|
69160
69197
|
},
|
|
69161
69198
|
resetMintingStatus: async (ids) => {
|
|
69162
69199
|
await client.query(`
|
|
69163
|
-
UPDATE im_assets SET minting_status = null WHERE id = ANY($1);
|
|
69200
|
+
UPDATE im_assets SET minting_status = null WHERE id = ANY($1) and contract_address = $2;
|
|
69164
69201
|
`, [ids]);
|
|
69165
69202
|
},
|
|
69166
69203
|
markForRetry: async (ids) => {
|
|
@@ -69178,216 +69215,9 @@ const mintingPersistence$1 = (client) => ({
|
|
|
69178
69215
|
const res = await client.query(`
|
|
69179
69216
|
SELECT * FROM im_assets WHERE contract_address = $1 and asset_id = $2;
|
|
69180
69217
|
`, [contractAddress, referenceId]);
|
|
69181
|
-
return res.rows[0]
|
|
69218
|
+
return res.rows[0];
|
|
69182
69219
|
}
|
|
69183
|
-
}
|
|
69184
|
-
|
|
69185
|
-
// client is a PrismaClient instance. it needs to be generated with
|
|
69186
|
-
// additional schema defined inside (TODO: point to repo) file.
|
|
69187
|
-
const mintingPersistence = (client) => ({
|
|
69188
|
-
recordMint: async (request) => {
|
|
69189
|
-
const result = await client.imAssets.upsert({
|
|
69190
|
-
where: {
|
|
69191
|
-
im_assets_uindex: {
|
|
69192
|
-
assetId: request.asset_id, contractAddress: request.contract_address
|
|
69193
|
-
}
|
|
69194
|
-
},
|
|
69195
|
-
update: {},
|
|
69196
|
-
create: {
|
|
69197
|
-
assetId: request.asset_id,
|
|
69198
|
-
contractAddress: request.contract_address,
|
|
69199
|
-
ownerAddress: request.owner_address,
|
|
69200
|
-
metadata: JSON.stringify(request.metadata), // Serialize JSON metadata
|
|
69201
|
-
},
|
|
69202
|
-
});
|
|
69203
|
-
// Since upsert does not throw on update and does not tell directly if it updated or inserted,
|
|
69204
|
-
// we need to add additional logic to handle this if "result" does not provide enough info.
|
|
69205
|
-
if (!result) {
|
|
69206
|
-
throw new Error('Duplicated mint');
|
|
69207
|
-
}
|
|
69208
|
-
},
|
|
69209
|
-
// WARNING: this is NOT concurrency safe. Please only call this method one at a time.
|
|
69210
|
-
getNextBatchForSubmission: async (limit) => {
|
|
69211
|
-
const assets = await client.imAssets.findMany({
|
|
69212
|
-
where: {
|
|
69213
|
-
mintingStatus: null
|
|
69214
|
-
},
|
|
69215
|
-
take: limit
|
|
69216
|
-
});
|
|
69217
|
-
const assetIds = assets.map((asset) => asset.id);
|
|
69218
|
-
await client.imAssets.updateMany({
|
|
69219
|
-
where: {
|
|
69220
|
-
id: {
|
|
69221
|
-
in: assetIds
|
|
69222
|
-
}
|
|
69223
|
-
},
|
|
69224
|
-
data: {
|
|
69225
|
-
mintingStatus: 'submitting'
|
|
69226
|
-
}
|
|
69227
|
-
});
|
|
69228
|
-
const updatedAssets = await client.imAssets.findMany({
|
|
69229
|
-
where: {
|
|
69230
|
-
id: {
|
|
69231
|
-
in: assetIds
|
|
69232
|
-
}
|
|
69233
|
-
}
|
|
69234
|
-
});
|
|
69235
|
-
return updatedAssets.map((asset) => ({
|
|
69236
|
-
id: asset.id,
|
|
69237
|
-
contract_address: asset.contractAddress,
|
|
69238
|
-
wallet_address: asset.ownerAddress,
|
|
69239
|
-
asset_id: asset.assetId,
|
|
69240
|
-
metadata: asset.metadata ? JSON.parse(asset.metadata) : null,
|
|
69241
|
-
owner_address: asset.ownerAddress,
|
|
69242
|
-
tried_count: asset.triedCount,
|
|
69243
|
-
}));
|
|
69244
|
-
},
|
|
69245
|
-
updateMintingStatusToSubmitted: async (ids) => {
|
|
69246
|
-
await client.imAssets.updateMany({
|
|
69247
|
-
where: {
|
|
69248
|
-
id: {
|
|
69249
|
-
in: ids
|
|
69250
|
-
}
|
|
69251
|
-
},
|
|
69252
|
-
data: {
|
|
69253
|
-
mintingStatus: 'submitted'
|
|
69254
|
-
}
|
|
69255
|
-
});
|
|
69256
|
-
},
|
|
69257
|
-
syncMintingStatus: async (submittedMintRequest) => {
|
|
69258
|
-
// First, attempt to retrieve the existing asset
|
|
69259
|
-
const existingAsset = await client.imAssets.findUnique({
|
|
69260
|
-
where: {
|
|
69261
|
-
im_assets_uindex: {
|
|
69262
|
-
assetId: submittedMintRequest.assetId,
|
|
69263
|
-
contractAddress: submittedMintRequest.contractAddress,
|
|
69264
|
-
},
|
|
69265
|
-
}
|
|
69266
|
-
});
|
|
69267
|
-
// Check if the asset exists and the condition for updating is met
|
|
69268
|
-
if (existingAsset && (existingAsset.lastImtblZkevmMintRequestUpdatedId === null
|
|
69269
|
-
|| existingAsset.lastImtblZkevmMintRequestUpdatedId < submittedMintRequest.imtblZkevmMintRequestUpdatedId)) {
|
|
69270
|
-
// Perform update if the existing record's lastImtblZkevmMintRequestUpdatedId is less than the new one or is null
|
|
69271
|
-
await client.imAssets.update({
|
|
69272
|
-
where: {
|
|
69273
|
-
im_assets_uindex: {
|
|
69274
|
-
assetId: submittedMintRequest.assetId,
|
|
69275
|
-
contractAddress: submittedMintRequest.contractAddress,
|
|
69276
|
-
},
|
|
69277
|
-
},
|
|
69278
|
-
data: {
|
|
69279
|
-
ownerAddress: submittedMintRequest.ownerAddress,
|
|
69280
|
-
tokenId: submittedMintRequest.tokenId,
|
|
69281
|
-
mintingStatus: submittedMintRequest.status,
|
|
69282
|
-
metadataId: submittedMintRequest.metadataId,
|
|
69283
|
-
lastImtblZkevmMintRequestUpdatedId: submittedMintRequest.imtblZkevmMintRequestUpdatedId,
|
|
69284
|
-
error: submittedMintRequest.error,
|
|
69285
|
-
}
|
|
69286
|
-
});
|
|
69287
|
-
}
|
|
69288
|
-
else if (!existingAsset) {
|
|
69289
|
-
// Perform insert if no existing record is found
|
|
69290
|
-
await client.imAssets.create({
|
|
69291
|
-
data: {
|
|
69292
|
-
assetId: submittedMintRequest.assetId,
|
|
69293
|
-
contractAddress: submittedMintRequest.contractAddress,
|
|
69294
|
-
ownerAddress: submittedMintRequest.ownerAddress,
|
|
69295
|
-
tokenId: submittedMintRequest.tokenId,
|
|
69296
|
-
mintingStatus: submittedMintRequest.status,
|
|
69297
|
-
metadataId: submittedMintRequest.metadataId,
|
|
69298
|
-
lastImtblZkevmMintRequestUpdatedId: submittedMintRequest.imtblZkevmMintRequestUpdatedId,
|
|
69299
|
-
error: submittedMintRequest.error,
|
|
69300
|
-
}
|
|
69301
|
-
});
|
|
69302
|
-
}
|
|
69303
|
-
// If existing asset does not meet the update condition, do nothing
|
|
69304
|
-
},
|
|
69305
|
-
updateMintingStatusToSubmissionFailed: async (ids) => {
|
|
69306
|
-
await client.imAssets.updateMany({
|
|
69307
|
-
where: {
|
|
69308
|
-
id: {
|
|
69309
|
-
in: ids
|
|
69310
|
-
}
|
|
69311
|
-
},
|
|
69312
|
-
data: {
|
|
69313
|
-
mintingStatus: 'submission_failed'
|
|
69314
|
-
}
|
|
69315
|
-
});
|
|
69316
|
-
},
|
|
69317
|
-
markAsConflict: async (assetIds, contractAddress) => {
|
|
69318
|
-
await client.imAssets.updateMany({
|
|
69319
|
-
where: {
|
|
69320
|
-
assetId: {
|
|
69321
|
-
in: assetIds // Targets assets where assetId is in the provided list
|
|
69322
|
-
},
|
|
69323
|
-
contractAddress // Additional condition for contract address
|
|
69324
|
-
},
|
|
69325
|
-
data: {
|
|
69326
|
-
mintingStatus: 'conflicting' // Set the new status
|
|
69327
|
-
}
|
|
69328
|
-
});
|
|
69329
|
-
},
|
|
69330
|
-
resetMintingStatus: async (ids) => {
|
|
69331
|
-
await client.imAssets.updateMany({
|
|
69332
|
-
where: {
|
|
69333
|
-
id: {
|
|
69334
|
-
in: ids // Condition to match ids
|
|
69335
|
-
}
|
|
69336
|
-
},
|
|
69337
|
-
data: {
|
|
69338
|
-
mintingStatus: null // Setting minting_status to null
|
|
69339
|
-
}
|
|
69340
|
-
});
|
|
69341
|
-
},
|
|
69342
|
-
// this method is not concurrency safe
|
|
69343
|
-
markForRetry: async (ids) => {
|
|
69344
|
-
// Retrieve the current values of tried_count for the specified ids
|
|
69345
|
-
const assets = await client.imAssets.findMany({
|
|
69346
|
-
where: {
|
|
69347
|
-
id: {
|
|
69348
|
-
in: ids
|
|
69349
|
-
}
|
|
69350
|
-
},
|
|
69351
|
-
select: {
|
|
69352
|
-
id: true,
|
|
69353
|
-
triedCount: true // Assuming the field is named triedCount
|
|
69354
|
-
}
|
|
69355
|
-
});
|
|
69356
|
-
// Update each asset with the new tried_count and nullify minting_status
|
|
69357
|
-
for (const asset of assets) {
|
|
69358
|
-
await client.imAssets.update({
|
|
69359
|
-
where: {
|
|
69360
|
-
id: asset.id
|
|
69361
|
-
},
|
|
69362
|
-
data: {
|
|
69363
|
-
mintingStatus: null,
|
|
69364
|
-
triedCount: asset.triedCount + 1
|
|
69365
|
-
}
|
|
69366
|
-
});
|
|
69367
|
-
}
|
|
69368
|
-
},
|
|
69369
|
-
getMintingRequest: async (contractAddress, referenceId) => {
|
|
69370
|
-
// Retrieve the asset from the database based on contract_address and asset_id
|
|
69371
|
-
const asset = await client.imAssets.findFirst({
|
|
69372
|
-
where: {
|
|
69373
|
-
contractAddress,
|
|
69374
|
-
assetId: referenceId
|
|
69375
|
-
}
|
|
69376
|
-
});
|
|
69377
|
-
if (!asset) {
|
|
69378
|
-
return null;
|
|
69379
|
-
}
|
|
69380
|
-
return {
|
|
69381
|
-
asset_id: asset.assetId,
|
|
69382
|
-
contract_address: asset.contractAddress,
|
|
69383
|
-
id: asset.id,
|
|
69384
|
-
metadata: asset.metadata ? JSON.parse(asset.metadata) : null,
|
|
69385
|
-
owner_address: asset.ownerAddress,
|
|
69386
|
-
tried_count: asset.triedCount,
|
|
69387
|
-
wallet_address: asset.ownerAddress
|
|
69388
|
-
};
|
|
69389
|
-
}
|
|
69390
|
-
});
|
|
69220
|
+
};
|
|
69391
69221
|
|
|
69392
69222
|
// TODO: expose metrics
|
|
69393
69223
|
// - submitting status count, conflicting status count
|
|
@@ -69407,7 +69237,7 @@ const submitMintingRequests = async (mintingPersistence, blockchainDataSDKClient
|
|
|
69407
69237
|
await new Promise((resolve) => {
|
|
69408
69238
|
setTimeout(resolve, defaultMintingDelay);
|
|
69409
69239
|
});
|
|
69410
|
-
let batchSize = Math.min(mintingResponse
|
|
69240
|
+
let batchSize = Math.min(mintingResponse
|
|
69411
69241
|
? parseInt(mintingResponse.imx_remaining_mint_requests, 10)
|
|
69412
69242
|
: defaultBatchSize, defaultBatchSize);
|
|
69413
69243
|
if (batchSize === 0
|
|
@@ -69540,8 +69370,7 @@ const processMint = async (mintingPersistence, event, logger = console) => {
|
|
|
69540
69370
|
|
|
69541
69371
|
var minting_backend = /*#__PURE__*/Object.freeze({
|
|
69542
69372
|
__proto__: null,
|
|
69543
|
-
mintingPersistencePg: mintingPersistence
|
|
69544
|
-
mintingPersistencePrismaSqlite: mintingPersistence,
|
|
69373
|
+
mintingPersistencePg: mintingPersistence,
|
|
69545
69374
|
processMint: processMint,
|
|
69546
69375
|
recordMint: recordMint,
|
|
69547
69376
|
submitMintingRequests: submitMintingRequests
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Pool } from 'pg';
|
|
2
|
-
|
|
3
1
|
type CreateMintRequest = {
|
|
4
2
|
contract_address: string;
|
|
5
3
|
asset_id: string;
|
|
@@ -28,18 +26,16 @@ type SubmittedMintRequest = {
|
|
|
28
26
|
interface MintingPersistence {
|
|
29
27
|
recordMint: (request: CreateMintRequest) => Promise<void>;
|
|
30
28
|
getNextBatchForSubmission: (limit: number) => Promise<MintRequest[]>;
|
|
31
|
-
updateMintingStatusToSubmitted: (
|
|
32
|
-
updateMintingStatusToSubmissionFailed: (
|
|
29
|
+
updateMintingStatusToSubmitted: (id: string[]) => Promise<void>;
|
|
30
|
+
updateMintingStatusToSubmissionFailed: (id: string[]) => Promise<void>;
|
|
33
31
|
syncMintingStatus: (submittedMintRequest: SubmittedMintRequest) => Promise<void>;
|
|
34
32
|
markAsConflict: (assetIds: string[], contractAddress: string) => Promise<void>;
|
|
35
33
|
resetMintingStatus: (ids: string[]) => Promise<void>;
|
|
36
34
|
markForRetry: (ids: string[]) => Promise<void>;
|
|
37
|
-
getMintingRequest: (contractAddress: string, referenceId: string) => Promise<MintRequest
|
|
35
|
+
getMintingRequest: (contractAddress: string, referenceId: string) => Promise<MintRequest>;
|
|
38
36
|
}
|
|
39
37
|
|
|
40
|
-
declare const mintingPersistence
|
|
41
|
-
|
|
42
|
-
declare const mintingPersistence: (client: any) => MintingPersistence;
|
|
38
|
+
declare const mintingPersistence: MintingPersistence;
|
|
43
39
|
|
|
44
40
|
/**
|
|
45
41
|
* Immutable zkEVM API
|
|
@@ -3503,4 +3499,4 @@ type MintRequestEvent = {
|
|
|
3503
3499
|
};
|
|
3504
3500
|
declare const processMint: (mintingPersistence: MintingPersistence, event: MintRequestEvent, logger?: Logger) => Promise<void>;
|
|
3505
3501
|
|
|
3506
|
-
export { mintingPersistence
|
|
3502
|
+
export { mintingPersistence as mintingPersistencePg, processMint, recordMint, submitMintingRequests };
|
package/dist/minting_backend.js
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
/* eslint-disable global-require */
|
|
3
|
+
let optionalPackage = null;
|
|
4
|
+
let pgClient = null;
|
|
5
|
+
try {
|
|
6
|
+
optionalPackage = require('pg');
|
|
7
|
+
pgClient = new optionalPackage.Pool({
|
|
8
|
+
user: process.env.PG_USER || 'postgres',
|
|
9
|
+
host: process.env.PG_HOST || 'localhost',
|
|
10
|
+
database: process.env.PG_DB_NAME || 'nullus',
|
|
11
|
+
password: process.env.PG_PASSWORD || 'postgres',
|
|
12
|
+
port: parseInt(process.env.PG_PORT || '5432', 10) || 5432,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
console.error('pg is not installed. Please install it by running `npm install pg`');
|
|
17
|
+
optionalPackage = null;
|
|
18
|
+
}
|
|
19
|
+
const client = pgClient;
|
|
20
|
+
|
|
21
|
+
const mintingPersistence = {
|
|
2
22
|
recordMint: async (request) => {
|
|
3
23
|
const r = await client.query(`
|
|
4
24
|
INSERT INTO im_assets (asset_id, contract_address, owner_address, metadata)
|
|
@@ -66,7 +86,7 @@ const mintingPersistence$1 = (client) => ({
|
|
|
66
86
|
},
|
|
67
87
|
resetMintingStatus: async (ids) => {
|
|
68
88
|
await client.query(`
|
|
69
|
-
UPDATE im_assets SET minting_status = null WHERE id = ANY($1);
|
|
89
|
+
UPDATE im_assets SET minting_status = null WHERE id = ANY($1) and contract_address = $2;
|
|
70
90
|
`, [ids]);
|
|
71
91
|
},
|
|
72
92
|
markForRetry: async (ids) => {
|
|
@@ -84,216 +104,9 @@ const mintingPersistence$1 = (client) => ({
|
|
|
84
104
|
const res = await client.query(`
|
|
85
105
|
SELECT * FROM im_assets WHERE contract_address = $1 and asset_id = $2;
|
|
86
106
|
`, [contractAddress, referenceId]);
|
|
87
|
-
return res.rows[0]
|
|
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
|
-
};
|
|
107
|
+
return res.rows[0];
|
|
295
108
|
}
|
|
296
|
-
}
|
|
109
|
+
};
|
|
297
110
|
|
|
298
111
|
// TODO: expose metrics
|
|
299
112
|
// - submitting status count, conflicting status count
|
|
@@ -313,7 +126,7 @@ const submitMintingRequests = async (mintingPersistence, blockchainDataSDKClient
|
|
|
313
126
|
await new Promise((resolve) => {
|
|
314
127
|
setTimeout(resolve, defaultMintingDelay);
|
|
315
128
|
});
|
|
316
|
-
let batchSize = Math.min(mintingResponse
|
|
129
|
+
let batchSize = Math.min(mintingResponse
|
|
317
130
|
? parseInt(mintingResponse.imx_remaining_mint_requests, 10)
|
|
318
131
|
: defaultBatchSize, defaultBatchSize);
|
|
319
132
|
if (batchSize === 0
|
|
@@ -444,4 +257,4 @@ const processMint = async (mintingPersistence, event, logger = console) => {
|
|
|
444
257
|
});
|
|
445
258
|
};
|
|
446
259
|
|
|
447
|
-
export { mintingPersistence
|
|
260
|
+
export { mintingPersistence as mintingPersistencePg, processMint, recordMint, submitMintingRequests };
|
package/dist/orderbook.js
CHANGED
|
@@ -132,7 +132,7 @@ const flattenProperties = (properties) => {
|
|
|
132
132
|
};
|
|
133
133
|
|
|
134
134
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
135
|
-
const SDK_VERSION = '1.35.
|
|
135
|
+
const SDK_VERSION = '1.35.2-alpha.1';
|
|
136
136
|
const getFrameParentDomain = () => {
|
|
137
137
|
if (isNode()) {
|
|
138
138
|
return '';
|