@imtbl/sdk 1.35.2-alpha → 1.35.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/blockchain_data.js +2 -2
  2. package/dist/browser/checkout/{BridgeWidget-22c8b08d.js → BridgeWidget-b9e736eb.js} +1 -1
  3. package/dist/browser/checkout/{OnRampWidget-aeb5d57c.js → OnRampWidget-08bfa49c.js} +1 -1
  4. package/dist/browser/checkout/{SaleWidget-93a4fffd.js → SaleWidget-62cda384.js} +1 -1
  5. package/dist/browser/checkout/{SpendingCapHero-8459b91d.js → SpendingCapHero-341cfc38.js} +1 -1
  6. package/dist/browser/checkout/{SwapWidget-11ecb4ae.js → SwapWidget-40adbff0.js} +1 -1
  7. package/dist/browser/checkout/{TopUpView-ad058510.js → TopUpView-17d237f3.js} +1 -1
  8. package/dist/browser/checkout/{WalletWidget-920b03b4.js → WalletWidget-a19ab89c.js} +1 -1
  9. package/dist/browser/checkout/{auto-track-469b3ba5.js → auto-track-ffcab507.js} +1 -1
  10. package/dist/browser/checkout/{balance-c9c03af5.js → balance-4d6f9b6f.js} +1 -1
  11. package/dist/browser/checkout/{index-06896b92.js → index-11eefc56.js} +1 -1
  12. package/dist/browser/checkout/{index-09b1efac.js → index-317dcefc.js} +1 -1
  13. package/dist/browser/checkout/{index-9997f064.js → index-4fb1863d.js} +1 -1
  14. package/dist/browser/checkout/{index-e5f07d9e.js → index-7a9fdf09.js} +2 -2
  15. package/dist/browser/checkout/{index-cbf7168d.js → index-9a663258.js} +1 -1
  16. package/dist/browser/checkout/{index-37c4003a.js → index-ab21662b.js} +1 -1
  17. package/dist/browser/checkout/index-bafd7f6d.js +1 -0
  18. package/dist/browser/checkout/{index-c53e5321.js → index-be2f6fa5.js} +1 -1
  19. package/dist/browser/checkout/{index.umd-e783a603.js → index.umd-cb823fd6.js} +1 -1
  20. package/dist/browser/checkout/{retry-10de11e8.js → retry-0002f89a.js} +1 -1
  21. package/dist/browser/checkout/sdk.js +4 -4
  22. package/dist/browser/checkout/widgets-esm.js +1 -1
  23. package/dist/browser/checkout/widgets.js +1 -1
  24. package/dist/checkout.d.ts +14 -2
  25. package/dist/checkout.js +18 -13
  26. package/dist/config.js +1 -1
  27. package/dist/index.browser.js +4 -4
  28. package/dist/index.browser.js.map +1 -1
  29. package/dist/index.cjs +89 -578
  30. package/dist/index.d.ts +21 -114
  31. package/dist/index.js +90 -577
  32. package/dist/orderbook.js +1 -1
  33. package/dist/passport.js +64 -55
  34. package/dist/x.js +3 -3
  35. package/package.json +1 -9
  36. package/dist/browser/checkout/index-1b8b7ce9.js +0 -1
  37. package/dist/minting_backend.d.ts +0 -3506
  38. package/dist/minting_backend.js +0 -447
  39. package/dist/webhook.d.ts +0 -11
  40. 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.35.2-alpha';
186
+ const SDK_VERSION$1 = '1.35.3';
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.35.2-alpha' };
14213
+ const defaultHeaders$2 = { 'x-sdk-version': 'ts-immutable-sdk-1.35.3' };
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.35.2-alpha',
14285
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.35.3',
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.35.2-alpha' };
14759
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.35.3' };
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.35.2-alpha',
14798
+ sdkVersion: 'ts-immutable-sdk-1.35.3',
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$2 = {
23620
+ var validator$1 = {
23622
23621
  assertOptions: assertOptions$1,
23623
23622
  validators: validators$1$1
23624
23623
  };
23625
23624
 
23626
- const validators$2 = validator$2.validators;
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$2.assertOptions(transitional, {
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$2.assertOptions(paramsSerializer, {
23679
+ validator$1.assertOptions(paramsSerializer, {
23681
23680
  encode: validators$2.function,
23682
23681
  serialize: validators$2.function
23683
23682
  }, true);
@@ -25411,7 +25410,7 @@ async function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, })
25411
25410
 
25412
25411
  const ERC721$1 = 'ERC721';
25413
25412
  async function createOrder$1({ starkSigner, user, request, ordersApi, guardianClient, }) {
25414
- return withPassportError(guardianClient.withDefaultConfirmationScreenTask(async () => {
25413
+ return withPassportError(async () => {
25415
25414
  const { ethAddress } = user.imx;
25416
25415
  const amountSell = request.sell.type === ERC721$1 ? '1' : request.sell.amount;
25417
25416
  const amountBuy = request.buy.type === ERC721$1 ? '1' : request.buy.amount;
@@ -25457,10 +25456,10 @@ async function createOrder$1({ starkSigner, user, request, ordersApi, guardianCl
25457
25456
  return {
25458
25457
  ...createOrderResponse.data,
25459
25458
  };
25460
- }), PassportErrorType.CREATE_ORDER_ERROR);
25459
+ }, PassportErrorType.CREATE_ORDER_ERROR);
25461
25460
  }
25462
25461
  async function cancelOrder$1({ user, starkSigner, request, ordersApi, guardianClient, }) {
25463
- return withPassportError(guardianClient.withDefaultConfirmationScreenTask(async () => {
25462
+ return withPassportError(async () => {
25464
25463
  const getSignableCancelOrderRequest = {
25465
25464
  order_id: request.order_id,
25466
25465
  };
@@ -25487,7 +25486,7 @@ async function cancelOrder$1({ user, starkSigner, request, ordersApi, guardianCl
25487
25486
  order_id: cancelOrderResponse.data.order_id,
25488
25487
  status: cancelOrderResponse.data.status,
25489
25488
  };
25490
- }), PassportErrorType.CANCEL_ORDER_ERROR);
25489
+ }, PassportErrorType.CANCEL_ORDER_ERROR);
25491
25490
  }
25492
25491
 
25493
25492
  async function registerPassport({ ethSigner, starkSigner, imxApiClients }, authorization) {
@@ -25519,7 +25518,7 @@ async function registerPassport({ ethSigner, starkSigner, imxApiClients }, autho
25519
25518
  }
25520
25519
 
25521
25520
  async function createTrade$1({ request, tradesApi, user, starkSigner, guardianClient, }) {
25522
- return withPassportError(guardianClient.withDefaultConfirmationScreenTask(async () => {
25521
+ return withPassportError(async () => {
25523
25522
  const { ethAddress } = user.imx;
25524
25523
  const getSignableTradeRequest = {
25525
25524
  expiration_timestamp: request.expiration_timestamp,
@@ -25560,12 +25559,12 @@ async function createTrade$1({ request, tradesApi, user, starkSigner, guardianCl
25560
25559
  headers,
25561
25560
  });
25562
25561
  return createTradeResponse;
25563
- }), PassportErrorType.CREATE_TRADE_ERROR);
25562
+ }, PassportErrorType.CREATE_TRADE_ERROR);
25564
25563
  }
25565
25564
 
25566
25565
  const ERC721 = 'ERC721';
25567
25566
  async function transfer$1({ request, transfersApi, starkSigner, user, guardianClient, }) {
25568
- return withPassportError(guardianClient.withDefaultConfirmationScreenTask(async () => {
25567
+ return withPassportError(async () => {
25569
25568
  const transferAmount = request.type === ERC721 ? '1' : request.amount;
25570
25569
  const getSignableTransferRequest = {
25571
25570
  sender: user.imx.ethAddress,
@@ -25607,11 +25606,10 @@ async function transfer$1({ request, transfersApi, starkSigner, user, guardianCl
25607
25606
  time: responseData.time,
25608
25607
  transfer_id: responseData.transfer_id,
25609
25608
  };
25610
- }), PassportErrorType.TRANSFER_ERROR);
25609
+ }, PassportErrorType.TRANSFER_ERROR);
25611
25610
  }
25612
25611
  async function batchNftTransfer({ user, starkSigner, request, transfersApi, guardianClient, }) {
25613
- // eslint-disable-next-line function-paren-newline
25614
- return withPassportError(guardianClient.withConfirmationScreenTask({ width: 480, height: 784 })(async () => {
25612
+ return withPassportError(async () => {
25615
25613
  const { ethAddress } = user.imx;
25616
25614
  const signableRequests = request.map((nftTransfer) => ({
25617
25615
  amount: '1',
@@ -25655,7 +25653,7 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, guar
25655
25653
  return {
25656
25654
  transfer_ids: response?.data.transfer_ids,
25657
25655
  };
25658
- }), PassportErrorType.TRANSFER_ERROR);
25656
+ }, PassportErrorType.TRANSFER_ERROR);
25659
25657
  }
25660
25658
 
25661
25659
  const POLL_INTERVAL = 1 * 1000; // every 1 second
@@ -25806,14 +25804,16 @@ class PassportImxProvider {
25806
25804
  };
25807
25805
  }
25808
25806
  async transfer(request) {
25809
- const { user, starkSigner } = await this.#getRegisteredImxUserAndSigners();
25810
- return transfer$1({
25811
- request,
25812
- user,
25813
- starkSigner,
25814
- transfersApi: this.immutableXClient.transfersApi,
25815
- guardianClient: this.guardianClient,
25816
- });
25807
+ return (this.guardianClient.withDefaultConfirmationScreenTask(async () => {
25808
+ const { user, starkSigner } = await this.#getRegisteredImxUserAndSigners();
25809
+ return transfer$1({
25810
+ request,
25811
+ user,
25812
+ starkSigner,
25813
+ transfersApi: this.immutableXClient.transfersApi,
25814
+ guardianClient: this.guardianClient,
25815
+ });
25816
+ })());
25817
25817
  }
25818
25818
  async registerOffchain() {
25819
25819
  const [user, signers] = await Promise.all([
@@ -25831,44 +25831,52 @@ class PassportImxProvider {
25831
25831
  throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
25832
25832
  }
25833
25833
  async createOrder(request) {
25834
- const { user, starkSigner } = await this.#getRegisteredImxUserAndSigners();
25835
- return createOrder$1({
25836
- request,
25837
- user,
25838
- starkSigner,
25839
- ordersApi: this.immutableXClient.ordersApi,
25840
- guardianClient: this.guardianClient,
25841
- });
25834
+ return this.guardianClient.withDefaultConfirmationScreenTask(async () => {
25835
+ const { user, starkSigner } = await this.#getRegisteredImxUserAndSigners();
25836
+ return createOrder$1({
25837
+ request,
25838
+ user,
25839
+ starkSigner,
25840
+ ordersApi: this.immutableXClient.ordersApi,
25841
+ guardianClient: this.guardianClient,
25842
+ });
25843
+ })();
25842
25844
  }
25843
25845
  async cancelOrder(request) {
25844
- const { user, starkSigner } = await this.#getRegisteredImxUserAndSigners();
25845
- return cancelOrder$1({
25846
- request,
25847
- user,
25848
- starkSigner,
25849
- ordersApi: this.immutableXClient.ordersApi,
25850
- guardianClient: this.guardianClient,
25851
- });
25846
+ return this.guardianClient.withDefaultConfirmationScreenTask(async () => {
25847
+ const { user, starkSigner } = await this.#getRegisteredImxUserAndSigners();
25848
+ return cancelOrder$1({
25849
+ request,
25850
+ user,
25851
+ starkSigner,
25852
+ ordersApi: this.immutableXClient.ordersApi,
25853
+ guardianClient: this.guardianClient,
25854
+ });
25855
+ })();
25852
25856
  }
25853
25857
  async createTrade(request) {
25854
- const { user, starkSigner } = await this.#getRegisteredImxUserAndSigners();
25855
- return createTrade$1({
25856
- request,
25857
- user,
25858
- starkSigner,
25859
- tradesApi: this.immutableXClient.tradesApi,
25860
- guardianClient: this.guardianClient,
25861
- });
25858
+ return this.guardianClient.withDefaultConfirmationScreenTask(async () => {
25859
+ const { user, starkSigner } = await this.#getRegisteredImxUserAndSigners();
25860
+ return createTrade$1({
25861
+ request,
25862
+ user,
25863
+ starkSigner,
25864
+ tradesApi: this.immutableXClient.tradesApi,
25865
+ guardianClient: this.guardianClient,
25866
+ });
25867
+ })();
25862
25868
  }
25863
25869
  async batchNftTransfer(request) {
25864
- const { user, starkSigner } = await this.#getRegisteredImxUserAndSigners();
25865
- return batchNftTransfer({
25866
- request,
25867
- user,
25868
- starkSigner,
25869
- transfersApi: this.immutableXClient.transfersApi,
25870
- guardianClient: this.guardianClient,
25871
- });
25870
+ return this.guardianClient.withConfirmationScreenTask({ width: 480, height: 784 })(async () => {
25871
+ const { user, starkSigner } = await this.#getRegisteredImxUserAndSigners();
25872
+ return batchNftTransfer({
25873
+ request,
25874
+ user,
25875
+ starkSigner,
25876
+ transfersApi: this.immutableXClient.transfersApi,
25877
+ guardianClient: this.guardianClient,
25878
+ });
25879
+ })();
25872
25880
  }
25873
25881
  async exchangeTransfer(request) {
25874
25882
  const { user, starkSigner } = await this.#getRegisteredImxUserAndSigners();
@@ -32330,12 +32338,12 @@ function assertOptions(options, schema, allowUnknown) {
32330
32338
  }
32331
32339
  }
32332
32340
 
32333
- var validator$1 = {
32341
+ var validator = {
32334
32342
  assertOptions,
32335
32343
  validators: validators$1
32336
32344
  };
32337
32345
 
32338
- const validators = validator$1.validators;
32346
+ const validators = validator.validators;
32339
32347
 
32340
32348
  /**
32341
32349
  * Create a new instance of Axios
@@ -32376,7 +32384,7 @@ class Axios {
32376
32384
  const {transitional, paramsSerializer, headers} = config;
32377
32385
 
32378
32386
  if (transitional !== undefined) {
32379
- validator$1.assertOptions(transitional, {
32387
+ validator.assertOptions(transitional, {
32380
32388
  silentJSONParsing: validators.transitional(validators.boolean),
32381
32389
  forcedJSONParsing: validators.transitional(validators.boolean),
32382
32390
  clarifyTimeoutError: validators.transitional(validators.boolean)
@@ -32389,7 +32397,7 @@ class Axios {
32389
32397
  serialize: paramsSerializer
32390
32398
  };
32391
32399
  } else {
32392
- validator$1.assertOptions(paramsSerializer, {
32400
+ validator.assertOptions(paramsSerializer, {
32393
32401
  encode: validators.function,
32394
32402
  serialize: validators.function
32395
32403
  }, true);
@@ -58114,7 +58122,7 @@ const flattenProperties = (properties) => {
58114
58122
  };
58115
58123
 
58116
58124
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
58117
- const SDK_VERSION = '1.35.2-alpha';
58125
+ const SDK_VERSION = '1.35.3';
58118
58126
  const getFrameParentDomain = () => {
58119
58127
  if (isNode()) {
58120
58128
  return '';
@@ -63407,7 +63415,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
63407
63415
  maxPriorityFeePerGas: ethers.BigNumber.from(10e9),
63408
63416
  };
63409
63417
 
63410
- const SDK_VERSION_MARKER = '1.35.2-alpha';
63418
+ const SDK_VERSION_MARKER = '1.35.3';
63411
63419
  // This SDK version is replaced by the `yarn build` command ran on the root level
63412
63420
  const globalPackageVersion = () => SDK_VERSION_MARKER;
63413
63421
 
@@ -67154,22 +67162,23 @@ const sell = async (config, provider, orders) => {
67154
67162
  decimals = await measureAsyncExecution(config, 'Time to get decimals of token contract for the buy token', buyTokenContract.decimals());
67155
67163
  }
67156
67164
  const buyTokenOrNative = getBuyToken(buyToken, decimals);
67165
+ const sellTokenHasType = 'type' in sellToken;
67157
67166
  try {
67158
67167
  const walletAddress = await measureAsyncExecution(config, 'Time to get the address from the provider', provider.getSigner().getAddress());
67159
67168
  orderbook = createOrderbookInstance(config);
67160
67169
  const { seaportContractAddress } = orderbook.config();
67161
67170
  spenderAddress = seaportContractAddress;
67162
- const sellItem = sellToken.type === ItemType.ERC721
67171
+ const sellItem = sellTokenHasType && sellToken.type === ItemType.ERC1155
67163
67172
  ? {
67164
- type: sellToken.type,
67173
+ type: ItemType.ERC1155,
67165
67174
  contractAddress: sellToken.collectionAddress,
67166
67175
  tokenId: sellToken.id,
67176
+ amount: sellToken.amount,
67167
67177
  }
67168
67178
  : {
67169
- type: sellToken.type,
67179
+ type: ItemType.ERC721,
67170
67180
  contractAddress: sellToken.collectionAddress,
67171
67181
  tokenId: sellToken.id,
67172
- amount: sellToken.amount,
67173
67182
  };
67174
67183
  listing = await measureAsyncExecution(config, 'Time to prepare the listing from the orderbook', orderbook.prepareListing({
67175
67184
  makerAddress: walletAddress,
@@ -67185,11 +67194,15 @@ const sell = async (config, provider, orders) => {
67185
67194
  collectionAddress: sellToken.collectionAddress,
67186
67195
  });
67187
67196
  }
67188
- const itemRequirements = [
67189
- sellToken.type === ItemType.ERC721
67190
- ? getERC721Requirement(sellToken.id, sellToken.collectionAddress, spenderAddress)
67191
- : getERC1155Requirement(sellToken.id, sellToken.collectionAddress, spenderAddress, sellToken.amount),
67192
- ];
67197
+ const itemRequirements = [];
67198
+ if (sellTokenHasType && sellToken.type === ItemType.ERC1155) {
67199
+ const erc1155ItemRequirement = getERC1155Requirement(sellToken.id, sellToken.collectionAddress, spenderAddress, sellToken.amount);
67200
+ itemRequirements.push(erc1155ItemRequirement);
67201
+ }
67202
+ else {
67203
+ const erc721ItemRequirement = getERC721Requirement(sellToken.id, sellToken.collectionAddress, spenderAddress);
67204
+ itemRequirements.push(erc721ItemRequirement);
67205
+ }
67193
67206
  let smartCheckoutResult;
67194
67207
  const isPassport = provider.provider?.isPassport;
67195
67208
  if (!isPassport) {
@@ -69068,511 +69081,9 @@ var x = /*#__PURE__*/Object.freeze({
69068
69081
  sandbox: sandbox
69069
69082
  });
69070
69083
 
69071
- const validator = new MessageValidator();
69072
- const allowedTopicArnPrefix = {
69073
- [Environment$1.PRODUCTION]: 'arn:aws:sns:us-east-2:362750628221:',
69074
- [Environment$1.SANDBOX]: 'arn:aws:sns:us-east-2:783421985614:'
69075
- };
69076
- const init = async (body, env, handlers) => {
69077
- const msg = await new Promise((resolve, reject) => {
69078
- validator.validate(body, (err, message) => {
69079
- if (err) {
69080
- return reject(err);
69081
- }
69082
- // check for topic arn prefix
69083
- if (!message.TopicArn.startsWith(allowedTopicArnPrefix[env])) {
69084
- throw new Error('Invalid topic arn');
69085
- }
69086
- if (message?.Type === 'SubscriptionConfirmation') {
69087
- fetch(message.SubscribeURL).then(() => {
69088
- resolve(message);
69089
- }).catch((e) => {
69090
- reject(e);
69091
- });
69092
- }
69093
- return resolve(message);
69094
- });
69095
- });
69096
- if (msg.Type === 'Notification') {
69097
- const event = JSON.parse(msg.Message);
69098
- switch (event.event_name) {
69099
- case 'imtbl_zkevm_mint_request_updated':
69100
- await handlers.zkevmMintRequestUpdated(event);
69101
- break;
69102
- default:
69103
- if (handlers.others) {
69104
- await handlers.others(event);
69105
- }
69106
- break;
69107
- }
69108
- }
69109
- };
69110
-
69111
- var webhook = /*#__PURE__*/Object.freeze({
69112
- __proto__: null,
69113
- init: init
69114
- });
69115
-
69116
- const mintingPersistence$1 = (client) => ({
69117
- recordMint: async (request) => {
69118
- const r = await client.query(`
69119
- INSERT INTO im_assets (asset_id, contract_address, owner_address, metadata)
69120
- VALUES ($1, $2, $3, $4) ON CONFLICT (asset_id) DO NOTHING;
69121
- `, [request.asset_id, request.contract_address, request.owner_address, request.metadata]);
69122
- if (r.rowCount === 0) {
69123
- throw new Error('Duplicated mint');
69124
- }
69125
- },
69126
- getNextBatchForSubmission: async (limit) => {
69127
- const res = await client.query(`
69128
- UPDATE im_assets SET minting_status = 'submitting' WHERE minting_status IS NULL and id in (
69129
- select id from im_assets where minting_status is null limit $1 for update skip locked
69130
- ) returning *;
69131
- `, [limit]);
69132
- return res.rows;
69133
- },
69134
- updateMintingStatusToSubmitted: async (ids) => {
69135
- await client.query(`
69136
- UPDATE im_assets SET minting_status = $2 WHERE id = ANY($1);
69137
- `, [ids, 'submitted']);
69138
- },
69139
- syncMintingStatus: async (submittedMintRequest) => {
69140
- // doing a upsert just in case the row has not been created yet
69141
- await client.query(`
69142
- INSERT INTO im_assets (
69143
- asset_id,
69144
- contract_address,
69145
- owner_address,
69146
- token_id,
69147
- minting_status,
69148
- metadata_id,
69149
- last_imtbl_zkevm_mint_request_updated_id,
69150
- error
69151
- ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) ON CONFLICT (asset_id, contract_address)
69152
- DO UPDATE SET
69153
- owner_address = $3,
69154
- token_id = $4,
69155
- minting_status = $5,
69156
- metadata_id = $6,
69157
- last_imtbl_zkevm_mint_request_updated_id = $7,
69158
- error = $8
69159
- where (
69160
- im_assets.last_imtbl_zkevm_mint_request_updated_id < $7 OR
69161
- im_assets.last_imtbl_zkevm_mint_request_updated_id is null
69162
- );
69163
- `, [
69164
- submittedMintRequest.assetId,
69165
- submittedMintRequest.contractAddress,
69166
- submittedMintRequest.ownerAddress,
69167
- submittedMintRequest.tokenId,
69168
- submittedMintRequest.status,
69169
- submittedMintRequest.metadataId,
69170
- submittedMintRequest.imtblZkevmMintRequestUpdatedId,
69171
- submittedMintRequest.error
69172
- ]);
69173
- },
69174
- markAsConflict: async (assetIds, contractAddress) => {
69175
- await client.query(`
69176
- UPDATE im_assets
69177
- SET minting_status = 'conflicting'
69178
- WHERE asset_id = ANY($1)
69179
- AND contract_address = $2;
69180
- `, [assetIds, contractAddress]);
69181
- },
69182
- resetMintingStatus: async (ids) => {
69183
- await client.query(`
69184
- UPDATE im_assets SET minting_status = null WHERE id = ANY($1);
69185
- `, [ids]);
69186
- },
69187
- markForRetry: async (ids) => {
69188
- await client.query(`
69189
- UPDATE im_assets
69190
- SET minting_status = null, tried_count = tried_count + 1 WHERE id = ANY($1);
69191
- `, [ids]);
69192
- },
69193
- updateMintingStatusToSubmissionFailed: async (ids) => {
69194
- await client.query(`
69195
- UPDATE im_assets SET minting_status = 'submission_failed' WHERE id = ANY($1);
69196
- `, [ids]);
69197
- },
69198
- getMintingRequest: async (contractAddress, referenceId) => {
69199
- const res = await client.query(`
69200
- SELECT * FROM im_assets WHERE contract_address = $1 and asset_id = $2;
69201
- `, [contractAddress, referenceId]);
69202
- return res.rows[0] || null;
69203
- }
69204
- });
69205
-
69206
- // client is a PrismaClient instance. it needs to be generated with
69207
- // additional schema defined inside (TODO: point to repo) file.
69208
- const mintingPersistence = (client) => ({
69209
- recordMint: async (request) => {
69210
- const result = await client.imAssets.upsert({
69211
- where: {
69212
- im_assets_uindex: {
69213
- assetId: request.asset_id, contractAddress: request.contract_address
69214
- }
69215
- },
69216
- update: {},
69217
- create: {
69218
- assetId: request.asset_id,
69219
- contractAddress: request.contract_address,
69220
- ownerAddress: request.owner_address,
69221
- metadata: JSON.stringify(request.metadata), // Serialize JSON metadata
69222
- },
69223
- });
69224
- // Since upsert does not throw on update and does not tell directly if it updated or inserted,
69225
- // we need to add additional logic to handle this if "result" does not provide enough info.
69226
- if (!result) {
69227
- throw new Error('Duplicated mint');
69228
- }
69229
- },
69230
- // WARNING: this is NOT concurrency safe. Please only call this method one at a time.
69231
- getNextBatchForSubmission: async (limit) => {
69232
- const assets = await client.imAssets.findMany({
69233
- where: {
69234
- mintingStatus: null
69235
- },
69236
- take: limit
69237
- });
69238
- const assetIds = assets.map((asset) => asset.id);
69239
- await client.imAssets.updateMany({
69240
- where: {
69241
- id: {
69242
- in: assetIds
69243
- }
69244
- },
69245
- data: {
69246
- mintingStatus: 'submitting'
69247
- }
69248
- });
69249
- const updatedAssets = await client.imAssets.findMany({
69250
- where: {
69251
- id: {
69252
- in: assetIds
69253
- }
69254
- }
69255
- });
69256
- return updatedAssets.map((asset) => ({
69257
- id: asset.id,
69258
- contract_address: asset.contractAddress,
69259
- wallet_address: asset.ownerAddress,
69260
- asset_id: asset.assetId,
69261
- metadata: asset.metadata ? JSON.parse(asset.metadata) : null,
69262
- owner_address: asset.ownerAddress,
69263
- tried_count: asset.triedCount,
69264
- }));
69265
- },
69266
- updateMintingStatusToSubmitted: async (ids) => {
69267
- await client.imAssets.updateMany({
69268
- where: {
69269
- id: {
69270
- in: ids
69271
- }
69272
- },
69273
- data: {
69274
- mintingStatus: 'submitted'
69275
- }
69276
- });
69277
- },
69278
- syncMintingStatus: async (submittedMintRequest) => {
69279
- // First, attempt to retrieve the existing asset
69280
- const existingAsset = await client.imAssets.findUnique({
69281
- where: {
69282
- im_assets_uindex: {
69283
- assetId: submittedMintRequest.assetId,
69284
- contractAddress: submittedMintRequest.contractAddress,
69285
- },
69286
- }
69287
- });
69288
- // Check if the asset exists and the condition for updating is met
69289
- if (existingAsset && (existingAsset.lastImtblZkevmMintRequestUpdatedId === null
69290
- || existingAsset.lastImtblZkevmMintRequestUpdatedId < submittedMintRequest.imtblZkevmMintRequestUpdatedId)) {
69291
- // Perform update if the existing record's lastImtblZkevmMintRequestUpdatedId is less than the new one or is null
69292
- await client.imAssets.update({
69293
- where: {
69294
- im_assets_uindex: {
69295
- assetId: submittedMintRequest.assetId,
69296
- contractAddress: submittedMintRequest.contractAddress,
69297
- },
69298
- },
69299
- data: {
69300
- ownerAddress: submittedMintRequest.ownerAddress,
69301
- tokenId: submittedMintRequest.tokenId,
69302
- mintingStatus: submittedMintRequest.status,
69303
- metadataId: submittedMintRequest.metadataId,
69304
- lastImtblZkevmMintRequestUpdatedId: submittedMintRequest.imtblZkevmMintRequestUpdatedId,
69305
- error: submittedMintRequest.error,
69306
- }
69307
- });
69308
- }
69309
- else if (!existingAsset) {
69310
- // Perform insert if no existing record is found
69311
- await client.imAssets.create({
69312
- data: {
69313
- assetId: submittedMintRequest.assetId,
69314
- contractAddress: submittedMintRequest.contractAddress,
69315
- ownerAddress: submittedMintRequest.ownerAddress,
69316
- tokenId: submittedMintRequest.tokenId,
69317
- mintingStatus: submittedMintRequest.status,
69318
- metadataId: submittedMintRequest.metadataId,
69319
- lastImtblZkevmMintRequestUpdatedId: submittedMintRequest.imtblZkevmMintRequestUpdatedId,
69320
- error: submittedMintRequest.error,
69321
- }
69322
- });
69323
- }
69324
- // If existing asset does not meet the update condition, do nothing
69325
- },
69326
- updateMintingStatusToSubmissionFailed: async (ids) => {
69327
- await client.imAssets.updateMany({
69328
- where: {
69329
- id: {
69330
- in: ids
69331
- }
69332
- },
69333
- data: {
69334
- mintingStatus: 'submission_failed'
69335
- }
69336
- });
69337
- },
69338
- markAsConflict: async (assetIds, contractAddress) => {
69339
- await client.imAssets.updateMany({
69340
- where: {
69341
- assetId: {
69342
- in: assetIds // Targets assets where assetId is in the provided list
69343
- },
69344
- contractAddress // Additional condition for contract address
69345
- },
69346
- data: {
69347
- mintingStatus: 'conflicting' // Set the new status
69348
- }
69349
- });
69350
- },
69351
- resetMintingStatus: async (ids) => {
69352
- await client.imAssets.updateMany({
69353
- where: {
69354
- id: {
69355
- in: ids // Condition to match ids
69356
- }
69357
- },
69358
- data: {
69359
- mintingStatus: null // Setting minting_status to null
69360
- }
69361
- });
69362
- },
69363
- // this method is not concurrency safe
69364
- markForRetry: async (ids) => {
69365
- // Retrieve the current values of tried_count for the specified ids
69366
- const assets = await client.imAssets.findMany({
69367
- where: {
69368
- id: {
69369
- in: ids
69370
- }
69371
- },
69372
- select: {
69373
- id: true,
69374
- triedCount: true // Assuming the field is named triedCount
69375
- }
69376
- });
69377
- // Update each asset with the new tried_count and nullify minting_status
69378
- for (const asset of assets) {
69379
- await client.imAssets.update({
69380
- where: {
69381
- id: asset.id
69382
- },
69383
- data: {
69384
- mintingStatus: null,
69385
- triedCount: asset.triedCount + 1
69386
- }
69387
- });
69388
- }
69389
- },
69390
- getMintingRequest: async (contractAddress, referenceId) => {
69391
- // Retrieve the asset from the database based on contract_address and asset_id
69392
- const asset = await client.imAssets.findFirst({
69393
- where: {
69394
- contractAddress,
69395
- assetId: referenceId
69396
- }
69397
- });
69398
- if (!asset) {
69399
- return null;
69400
- }
69401
- return {
69402
- asset_id: asset.assetId,
69403
- contract_address: asset.contractAddress,
69404
- id: asset.id,
69405
- metadata: asset.metadata ? JSON.parse(asset.metadata) : null,
69406
- owner_address: asset.ownerAddress,
69407
- tried_count: asset.triedCount,
69408
- wallet_address: asset.ownerAddress
69409
- };
69410
- }
69411
- });
69412
-
69413
- // TODO: expose metrics
69414
- // - submitting status count, conflicting status count
69415
- // - failed events count
69416
- const recordMint = async (mintingPersistence, mintRequest) => {
69417
- mintingPersistence.recordMint(mintRequest);
69418
- };
69419
- const defaultMintingDelay = 1000;
69420
- // This function can be called in different node process and will run in parallel to mint assets.
69421
- // Each process will NOT mint the same asset.
69422
- // Monitor your database to see if parallel processes are saturating the database CPU and triggering excessive vacuuming.
69423
- // default batch size will be treated as 100 when it exceeds 100 because minting API has a limit of 100 assets per request.
69424
- const submitMintingRequests = async (mintingPersistence, blockchainDataSDKClient, { defaultBatchSize = 1000, chainName = 'imtbl-zkevm-testnet', maxNumberOfTries = 3, }, logger = console) => {
69425
- let mintingResponse;
69426
- // eslint-disable-next-line no-constant-condition
69427
- while (true) {
69428
- await new Promise((resolve) => {
69429
- setTimeout(resolve, defaultMintingDelay);
69430
- });
69431
- let batchSize = Math.min(mintingResponse?.imx_remaining_mint_requests
69432
- ? parseInt(mintingResponse.imx_remaining_mint_requests, 10)
69433
- : defaultBatchSize, defaultBatchSize);
69434
- if (batchSize === 0
69435
- && mintingResponse
69436
- && new Date(mintingResponse.imx_mint_requests_limit_reset) > new Date()) {
69437
- logger.info(`minting limit reached, waiting for reset at ${mintingResponse?.imx_mint_requests_limit_reset}`);
69438
- continue;
69439
- }
69440
- if (batchSize === 0) {
69441
- logger.info(`minting limit has been reset, use default batch size: ${defaultBatchSize}`);
69442
- mintingResponse = undefined;
69443
- batchSize = defaultBatchSize;
69444
- }
69445
- // get mints to be submitted
69446
- const pendingMints = await mintingPersistence.getNextBatchForSubmission(batchSize);
69447
- if (pendingMints.length === 0) {
69448
- logger.info('no assets to mint');
69449
- continue;
69450
- }
69451
- // chunk assets by every 100 assets. every chunk should all be for the same contract address.
69452
- const chunkedAssets = pendingMints.sort((a, b) => (a.contract_address > b.contract_address ? 1 : -1)).reduce((acc, row) => {
69453
- if (acc.length === 0) {
69454
- return [{ contractAddress: row.contract_address, assets: [row] }];
69455
- }
69456
- const lastBatch = acc[acc.length - 1];
69457
- if (lastBatch.contractAddress === row.contract_address && lastBatch.assets.length < 100) {
69458
- return [...acc.slice(0, -1), { ...lastBatch, assets: [...lastBatch.assets, row] }];
69459
- }
69460
- return [...acc, { contractAddress: row.contract_address, assets: [row] }];
69461
- }, []);
69462
- // submit minting request for each contract address in parallel
69463
- const mintingResults = await Promise.allSettled(chunkedAssets.map(async ({ contractAddress, assets }) => {
69464
- const mintingRequest = {
69465
- chainName,
69466
- contractAddress,
69467
- createMintRequestRequest: {
69468
- assets: assets.map((row) => ({
69469
- reference_id: row.asset_id,
69470
- owner_address: row.owner_address,
69471
- metadata: row.metadata,
69472
- })),
69473
- },
69474
- };
69475
- try {
69476
- const response = await blockchainDataSDKClient.createMintRequest(mintingRequest);
69477
- logger.info(`mintingResponse: ${JSON.stringify(response, null, 2)}`);
69478
- // update minting status to submitted
69479
- await mintingPersistence.updateMintingStatusToSubmitted(assets.map(({ id }) => id));
69480
- return response;
69481
- }
69482
- catch (e) {
69483
- logger.error(e);
69484
- if (e.code === 'CONFLICT_ERROR'
69485
- && e.details?.id === 'reference_id') {
69486
- try {
69487
- // mark the assets as conflicting, so that we don't send them again.
69488
- await mintingPersistence.markAsConflict(e.details.values, contractAddress);
69489
- // remove non conflicting assets status so that they can be retried.
69490
- await mintingPersistence.resetMintingStatus(assets
69491
- .map(({ id }) => id)
69492
- .filter((id) => !e.details.values.includes(id)));
69493
- }
69494
- catch (e2) {
69495
- logger.error(e2);
69496
- }
69497
- }
69498
- else {
69499
- // separate assets into "need to be retied" and "exceeded max number of tries."
69500
- const { assetsToRetry, assetsExceededMaxNumberOfTries } = assets.reduce((acc, { tried_count = 0, id }) => {
69501
- if (tried_count < maxNumberOfTries) {
69502
- acc.assetsToRetry.push(id);
69503
- }
69504
- else {
69505
- acc.assetsExceededMaxNumberOfTries.push(id);
69506
- }
69507
- return acc;
69508
- }, {
69509
- assetsToRetry: [],
69510
- assetsExceededMaxNumberOfTries: [],
69511
- });
69512
- // remove all assets status so that they can be retried.
69513
- await mintingPersistence.markForRetry(assetsToRetry);
69514
- // mark assets that have exceeded the max number of tries as submission_failed
69515
- await mintingPersistence.updateMintingStatusToSubmissionFailed(assetsExceededMaxNumberOfTries);
69516
- }
69517
- return e;
69518
- }
69519
- }));
69520
- mintingResponse = mintingResults
69521
- .reverse()
69522
- .find((r) => r.status === 'fulfilled')?.value;
69523
- }
69524
- };
69525
- const processMint = async (mintingPersistence, event, logger = console) => {
69526
- if (event.event_name !== 'imtbl_zkevm_mint_request_updated') {
69527
- logger.info(`${event.event_name} is not imtbl_zkevm_mint_request_updated, skip.`);
69528
- return;
69529
- }
69530
- const referenceId = event.data.reference_id;
69531
- if (!referenceId) {
69532
- throw new Error('reference_id not found in webhook event');
69533
- }
69534
- const contractAddress = event.data.contract_address;
69535
- if (!contractAddress) {
69536
- throw new Error('contract_address not found in webhook event');
69537
- }
69538
- if (event.data.status === 'failed') {
69539
- logger.error(`mint failed: ${JSON.stringify(event.data, null, 2)}`);
69540
- }
69541
- const mintReq = await mintingPersistence.getMintingRequest(contractAddress, referenceId);
69542
- if (!mintReq) {
69543
- logger.info(`minting request not found in the database, ${JSON.stringify(event.data)}`);
69544
- }
69545
- const ownerAddress = mintReq?.wallet_address || event.data.owner_address;
69546
- if (!ownerAddress) {
69547
- logger.error('owner_address missing');
69548
- throw new Error('owner_address missing');
69549
- }
69550
- await mintingPersistence.syncMintingStatus({
69551
- tokenId: event.data.token_id,
69552
- status: event.data.status,
69553
- assetId: referenceId,
69554
- contractAddress,
69555
- ownerAddress,
69556
- metadataId: event.data.metadata_id,
69557
- imtblZkevmMintRequestUpdatedId: event.event_id,
69558
- error: event.data.error ? JSON.stringify(event.data.error) : null,
69559
- });
69560
- };
69561
-
69562
- var minting_backend = /*#__PURE__*/Object.freeze({
69563
- __proto__: null,
69564
- mintingPersistencePg: mintingPersistence$1,
69565
- mintingPersistencePrismaSqlite: mintingPersistence,
69566
- processMint: processMint,
69567
- recordMint: recordMint,
69568
- submitMintingRequests: submitMintingRequests
69569
- });
69570
-
69571
69084
  exports.blockchainData = blockchain_data;
69572
69085
  exports.checkout = checkout;
69573
69086
  exports.config = config;
69574
- exports.mintingBackend = minting_backend;
69575
69087
  exports.orderbook = orderbook;
69576
69088
  exports.passport = passport;
69577
- exports.webhook = webhook;
69578
69089
  exports.x = x;