@imtbl/sdk 1.43.5-alpha.2 → 1.43.5

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 (36) hide show
  1. package/dist/blockchain_data-08e66ad1.js +1 -0
  2. package/dist/blockchain_data.js +1 -1
  3. package/dist/browser/checkout/sdk.js +4 -4
  4. package/dist/{checkout-72eec63c.js → checkout-835624fb.js} +2 -2
  5. package/dist/{checkout.d-7613e722.d.ts → checkout.d-ae9ca847.d.ts} +0 -5
  6. package/dist/checkout.d.ts +1 -1
  7. package/dist/checkout.js +1 -1
  8. package/dist/{config-d87a2319.js → config-e6decb95.js} +1 -1
  9. package/dist/config.js +1 -1
  10. package/dist/{index-fd5abec4.js → index-1ff17202.js} +1 -1
  11. package/dist/{index-e1d8ce77.js → index-3c4d20df.js} +1 -1
  12. package/dist/index-7d2761cb.js +1 -0
  13. package/dist/index-974c422d.js +1 -0
  14. package/dist/index-cfadae12.js +1 -0
  15. package/dist/{index-7e641800.js → index-d7b7aff9.js} +1 -1
  16. package/dist/index.browser.js +4 -4
  17. package/dist/index.browser.js.map +1 -1
  18. package/dist/index.cjs +7 -12
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.js +1 -1
  21. package/dist/{minting_backend-929041e8.js → minting_backend-10ddbfd1.js} +1 -1
  22. package/dist/minting_backend.js +1 -1
  23. package/dist/{orderbook-99ea7b03.js → orderbook-10fe79b7.js} +1 -1
  24. package/dist/orderbook.js +1 -1
  25. package/dist/{passport-b97e7652.js → passport-e96a6719.js} +1 -1
  26. package/dist/passport.js +1 -1
  27. package/dist/webhook-8b165b7a.js +1 -0
  28. package/dist/webhook.js +1 -1
  29. package/dist/{x-f7c2f6d2.js → x-7dcaea97.js} +1 -1
  30. package/dist/x.js +1 -1
  31. package/package.json +1 -1
  32. package/dist/blockchain_data-4a9c13c2.js +0 -1
  33. package/dist/index-92dae7ab.js +0 -1
  34. package/dist/index-d3f538a4.js +0 -1
  35. package/dist/index-fffda076.js +0 -1
  36. package/dist/webhook-00229e18.js +0 -1
package/dist/index.cjs CHANGED
@@ -185,7 +185,7 @@ const flattenProperties$1 = (properties) => {
185
185
  };
186
186
 
187
187
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
188
- const SDK_VERSION$1 = '1.43.5-alpha.2';
188
+ const SDK_VERSION$1 = '1.43.5';
189
189
  const getFrameParentDomain$1 = () => {
190
190
  if (isNode$1()) {
191
191
  return '';
@@ -14212,7 +14212,7 @@ class MultiRollupApiClients {
14212
14212
  }
14213
14213
 
14214
14214
  // eslint-disable-next-line @typescript-eslint/naming-convention
14215
- const defaultHeaders$2 = { 'x-sdk-version': 'ts-immutable-sdk-1.43.5-alpha.2' };
14215
+ const defaultHeaders$2 = { 'x-sdk-version': 'ts-immutable-sdk-1.43.5' };
14216
14216
  const createConfig$1 = ({ basePath, headers, }) => {
14217
14217
  if (!basePath.trim()) {
14218
14218
  throw Error('basePath can not be empty');
@@ -14284,7 +14284,7 @@ class APIError extends Error {
14284
14284
 
14285
14285
  /* eslint-disable implicit-arrow-linebreak */
14286
14286
  const defaultHeaders$1 = {
14287
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.43.5-alpha.2',
14287
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.43.5',
14288
14288
  };
14289
14289
  /**
14290
14290
  * createAPIConfiguration to create a custom Configuration
@@ -14758,7 +14758,7 @@ var blockchain_data = /*#__PURE__*/Object.freeze({
14758
14758
  /* eslint-disable @typescript-eslint/naming-convention */
14759
14759
  class ApiConfiguration extends index$2.Configuration {
14760
14760
  }
14761
- const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.43.5-alpha.2' };
14761
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.43.5' };
14762
14762
  /**
14763
14763
  * @dev use createImmutableXConfiguration instead
14764
14764
  */
@@ -14799,7 +14799,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
14799
14799
  coreContractAddress,
14800
14800
  registrationContractAddress,
14801
14801
  registrationV4ContractAddress,
14802
- sdkVersion: 'ts-immutable-sdk-1.43.5-alpha.2',
14802
+ sdkVersion: 'ts-immutable-sdk-1.43.5',
14803
14803
  baseConfig,
14804
14804
  });
14805
14805
  const production = ({ baseConfig }) => createImmutableXConfiguration({
@@ -52269,7 +52269,7 @@ const flattenProperties = (properties) => {
52269
52269
  };
52270
52270
 
52271
52271
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
52272
- const SDK_VERSION = '1.43.5-alpha.2';
52272
+ const SDK_VERSION = '1.43.5';
52273
52273
  const getFrameParentDomain = () => {
52274
52274
  if (isNode()) {
52275
52275
  return '';
@@ -57588,7 +57588,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
57588
57588
  maxPriorityFeePerGas: ethers.BigNumber.from(10e9),
57589
57589
  };
57590
57590
 
57591
- const SDK_VERSION_MARKER = '1.43.5-alpha.2';
57591
+ const SDK_VERSION_MARKER = '1.43.5';
57592
57592
  // This SDK version is replaced by the `yarn build` command ran on the root level
57593
57593
  const globalPackageVersion = () => SDK_VERSION_MARKER;
57594
57594
 
@@ -62006,8 +62006,6 @@ class Checkout {
62006
62006
  /**
62007
62007
  * Determines the requirements for performing a buy.
62008
62008
  * @param {BuyParams} params - The parameters for the buy.
62009
- * @deprecated Please use orderbook.fulfillOrder or orderbook.fulfillBulkOrders instead. The smartCheckout
62010
- * method can still be used to ensure the transaction requirements are met before preparing the order fulfillment
62011
62009
  */
62012
62010
  async buy(params) {
62013
62011
  if (params.orders.length > 1) {
@@ -62022,8 +62020,6 @@ class Checkout {
62022
62020
  * @param {SellParams} params - The parameters for the sell.
62023
62021
  * Only currently actions the first order in the array until we support batch processing.
62024
62022
  * Only currently actions the first fee in the fees array of each order until we support multiple fees.
62025
- * @deprecated Please use orderbook.prepareListing or orderbook.prepareBulkListing instead. The smartCheckout
62026
- * method can still be used to ensure the transaction requirements are met before preparing the listing
62027
62023
  */
62028
62024
  async sell(params) {
62029
62025
  if (params.orders.length > 1) {
@@ -62036,7 +62032,6 @@ class Checkout {
62036
62032
  /**
62037
62033
  * Cancels a sell.
62038
62034
  * @param {CancelParams} params - The parameters for the cancel.
62039
- * @deprecated Please use orderbook.prepareOrderCancellations instead.
62040
62035
  */
62041
62036
  async cancel(params) {
62042
62037
  // eslint-disable-next-line no-console
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { c as config } from './config.d-65420620.js';
2
2
  export { b as blockchainData } from './blockchain_data.d-d538f8d4.js';
3
3
  export { p as passport } from './passport.d-d3f44798.js';
4
4
  export { o as orderbook } from './orderbook.d-77162c6c.js';
5
- export { c as checkout } from './checkout.d-7613e722.js';
5
+ export { c as checkout } from './checkout.d-ae9ca847.js';
6
6
  export { x } from './x.d-1b51f0c3.js';
7
7
  export { w as webhook } from './webhook.d-4c3cb340.js';
8
8
  export { m as mintingBackend } from './minting_backend.d-4754ffee.js';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export{c as config}from"./config-d87a2319.js";export{b as blockchainData}from"./blockchain_data-4a9c13c2.js";export{p as passport}from"./passport-b97e7652.js";export{o as orderbook}from"./orderbook-99ea7b03.js";export{c as checkout}from"./checkout-72eec63c.js";export{x}from"./x-f7c2f6d2.js";export{w as webhook}from"./webhook-00229e18.js";export{m as mintingBackend}from"./minting_backend-929041e8.js";import"./index-92dae7ab.js";import"axios";import"lru-memorise";import"global-const";import"./index-fffda076.js";import"./index-e1d8ce77.js";import"./index-d3f538a4.js";import"@ethersproject/keccak256";import"@ethersproject/strings";import"bn.js";import"enc-utils";import"ethers";import"@ethersproject/bytes";import"hash.js";import"elliptic";import"ethereumjs-wallet";import"assert";import"@ethersproject/abstract-signer";import"oidc-client-ts";import"crypto";import"jwt-decode";import"magic-sdk";import"@magic-ext/oidc";import"@ethersproject/providers";import"events";import"@0xsequence/abi";import"@0xsequence/core";import"uuid";import"./index-fd5abec4.js";import"form-data";import"ethers-v6";import"merkletreejs";import"@opensea/seaport-js";import"@metamask/detect-provider";import"@uniswap/sdk-core";import"@uniswap/v3-sdk";import"@ethersproject/solidity";import"@uniswap/router-sdk";import"@ethersproject/units";import"@ethersproject/bignumber";import"./index-7e641800.js";import"sns-validator";
1
+ export{c as config}from"./config-e6decb95.js";export{b as blockchainData}from"./blockchain_data-08e66ad1.js";export{p as passport}from"./passport-e96a6719.js";export{o as orderbook}from"./orderbook-10fe79b7.js";export{c as checkout}from"./checkout-835624fb.js";export{x}from"./x-7dcaea97.js";export{w as webhook}from"./webhook-8b165b7a.js";export{m as mintingBackend}from"./minting_backend-10ddbfd1.js";import"./index-cfadae12.js";import"axios";import"lru-memorise";import"global-const";import"./index-7d2761cb.js";import"./index-3c4d20df.js";import"./index-974c422d.js";import"@ethersproject/keccak256";import"@ethersproject/strings";import"bn.js";import"enc-utils";import"ethers";import"@ethersproject/bytes";import"hash.js";import"elliptic";import"ethereumjs-wallet";import"assert";import"@ethersproject/abstract-signer";import"oidc-client-ts";import"crypto";import"jwt-decode";import"magic-sdk";import"@magic-ext/oidc";import"@ethersproject/providers";import"events";import"@0xsequence/abi";import"@0xsequence/core";import"uuid";import"./index-1ff17202.js";import"form-data";import"ethers-v6";import"merkletreejs";import"@opensea/seaport-js";import"@metamask/detect-provider";import"@uniswap/sdk-core";import"@uniswap/v3-sdk";import"@ethersproject/solidity";import"@uniswap/router-sdk";import"@ethersproject/units";import"@ethersproject/bignumber";import"./index-d7b7aff9.js";import"sns-validator";
@@ -1 +1 @@
1
- import{B as t}from"./index-fffda076.js";import{h as e}from"./index-7e641800.js";import{t as s,s as a,b as n}from"./index-92dae7ab.js";const i="minting_backend_sdk",d=t=>{try{s(i,"error",{name:t.name,message:t.message})}catch{}},r=(t,e)=>{try{s(i,"error",{name:t.name,message:t.message,origin:e})}catch{}},o=t=>((()=>{try{s(i,"initializePersistencePG")}catch{}})(),{recordMint:async e=>{if(0===(await t.query("\n INSERT INTO im_assets (asset_id, contract_address, owner_address, metadata, amount, token_id) \n VALUES ($1, $2, $3, $4, $5, $6) ON CONFLICT (asset_id, contract_address) DO NOTHING;\n ",[e.asset_id,e.contract_address,e.owner_address,e.metadata,e.amount,e.token_id])).rowCount)throw new Error("Duplicated mint")},getNextBatchForSubmission:async e=>(await t.query("\n WITH limited_assets AS (\n SELECT id \n FROM im_assets \n WHERE minting_status IS NULL \n LIMIT $1 \n FOR UPDATE SKIP LOCKED\n )\n UPDATE im_assets \n SET minting_status = 'submitting' \n WHERE minting_status IS NULL \n AND id IN (SELECT id FROM limited_assets)\n RETURNING *;\n ",[e])).rows,updateMintingStatusToSubmitted:async e=>{await t.query("\n UPDATE im_assets SET minting_status = $2 WHERE id = ANY($1);\n ",[e,"submitted"])},syncMintingStatus:async e=>{await t.query("\n INSERT INTO im_assets (\n asset_id, \n contract_address, \n owner_address, \n token_id, \n minting_status, \n metadata_id, \n last_imtbl_zkevm_mint_request_updated_id, \n error,\n amount\n ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) ON CONFLICT (asset_id, contract_address)\n DO UPDATE SET \n owner_address = $3,\n token_id = $4,\n minting_status = $5,\n metadata_id = $6,\n last_imtbl_zkevm_mint_request_updated_id = $7,\n error = $8\n where (\n im_assets.last_imtbl_zkevm_mint_request_updated_id < $7 OR \n im_assets.last_imtbl_zkevm_mint_request_updated_id is null\n );\n ",[e.assetId,e.contractAddress,e.ownerAddress,e.tokenId,e.status,e.metadataId,e.imtblZkevmMintRequestUpdatedId,e.error,e.amount])},markAsConflict:async(e,s)=>{await t.query("\n UPDATE im_assets \n SET minting_status = 'conflicting' \n WHERE asset_id = ANY($1) \n AND contract_address = $2;\n ",[e,s])},resetMintingStatus:async e=>{await t.query("\n UPDATE im_assets SET minting_status = null WHERE id = ANY($1);\n ",[e])},markForRetry:async e=>{await t.query("\n UPDATE im_assets \n SET minting_status = null, tried_count = tried_count + 1 WHERE id = ANY($1);\n ",[e])},updateMintingStatusToSubmissionFailed:async e=>{await t.query("\n UPDATE im_assets SET minting_status = 'submission_failed' WHERE id = ANY($1);\n ",[e])},getMintingRequest:async(e,s)=>(await t.query("\n SELECT * FROM im_assets WHERE contract_address = $1 and asset_id = $2;\n ",[e,s])).rows[0]||null}),m=t=>((()=>{try{s(i,"initializePersistencePrismaSqlite")}catch{}})(),{recordMint:async e=>{if(!await t.imAssets.upsert({where:{im_assets_uindex:{assetId:e.asset_id,contractAddress:e.contract_address}},update:{},create:{assetId:e.asset_id,contractAddress:e.contract_address,ownerAddress:e.owner_address,metadata:JSON.stringify(e.metadata),amount:e.amount||null,tokenId:e.token_id||null}}))throw new Error("Duplicated mint")},getNextBatchForSubmission:async e=>{const s=(await t.imAssets.findMany({where:{mintingStatus:null},take:e})).map((t=>t.id));await t.imAssets.updateMany({where:{id:{in:s}},data:{mintingStatus:"submitting"}});return(await t.imAssets.findMany({where:{id:{in:s}}})).map((t=>({id:t.id,contract_address:t.contractAddress,wallet_address:t.ownerAddress,asset_id:t.assetId,metadata:t.metadata?JSON.parse(t.metadata):null,owner_address:t.ownerAddress,tried_count:t.triedCount,amount:t.amount||null,token_id:t.tokenId||null})))},updateMintingStatusToSubmitted:async e=>{await t.imAssets.updateMany({where:{id:{in:e}},data:{mintingStatus:"submitted"}})},syncMintingStatus:async e=>{const s=await t.imAssets.findUnique({where:{im_assets_uindex:{assetId:e.assetId,contractAddress:e.contractAddress}}});s&&(null===s.lastImtblZkevmMintRequestUpdatedId||s.lastImtblZkevmMintRequestUpdatedId<e.imtblZkevmMintRequestUpdatedId)?await t.imAssets.update({where:{im_assets_uindex:{assetId:e.assetId,contractAddress:e.contractAddress}},data:{ownerAddress:e.ownerAddress,tokenId:e.tokenId,mintingStatus:e.status,metadataId:e.metadataId,lastImtblZkevmMintRequestUpdatedId:e.imtblZkevmMintRequestUpdatedId,error:e.error,amount:e.amount||null}}):s||await t.imAssets.create({data:{assetId:e.assetId,contractAddress:e.contractAddress,ownerAddress:e.ownerAddress,tokenId:e.tokenId,mintingStatus:e.status,metadataId:e.metadataId,lastImtblZkevmMintRequestUpdatedId:e.imtblZkevmMintRequestUpdatedId,error:e.error,amount:e.amount||null}})},updateMintingStatusToSubmissionFailed:async e=>{await t.imAssets.updateMany({where:{id:{in:e}},data:{mintingStatus:"submission_failed"}})},markAsConflict:async(e,s)=>{await t.imAssets.updateMany({where:{assetId:{in:e},contractAddress:s},data:{mintingStatus:"conflicting"}})},resetMintingStatus:async e=>{await t.imAssets.updateMany({where:{id:{in:e}},data:{mintingStatus:null}})},markForRetry:async e=>{const s=await t.imAssets.findMany({where:{id:{in:e}},select:{id:!0,triedCount:!0}});for(const e of s)await t.imAssets.update({where:{id:e.id},data:{mintingStatus:null,triedCount:e.triedCount+1}})},getMintingRequest:async(e,s)=>{const a=await t.imAssets.findFirst({where:{contractAddress:e,assetId:s}});return a?{asset_id:a.assetId,contract_address:a.contractAddress,id:a.id,metadata:a.metadata?JSON.parse(a.metadata):null,owner_address:a.ownerAddress,tried_count:a.triedCount,wallet_address:a.ownerAddress,amount:a.amount||null}:null}}),c=async(t,e)=>{(()=>{try{s(i,"recordMint")}catch{}})(),t.recordMint(e)},u=async(t,e,{defaultBatchSize:a=1e3,chainName:n="imtbl-zkevm-testnet",maxNumberOfTries:r=3},o=console,m=1/0)=>{let c;(()=>{try{s(i,"submitMintingRequests")}catch{}})();let u=0;for(;u++<m;){await new Promise((t=>{setTimeout(t,1e3)}));let s=Math.min(c?.imx_remaining_mint_requests?parseInt(c.imx_remaining_mint_requests,10):a,a);if(0===s&&c&&new Date(c.imx_mint_requests_limit_reset)>new Date){o.info(`minting limit reached, waiting for reset at ${c?.imx_mint_requests_limit_reset}`);continue}0===s&&(o.info(`minting limit has been reset, use default batch size: ${a}`),c=void 0,s=a);const i=await t.getNextBatchForSubmission(s);if(0===i.length){o.info("no assets to mint");continue}const m=i.sort(((t,e)=>t.contract_address>e.contract_address?1:-1)).reduce(((t,e)=>{if(0===t.length)return[{contractAddress:e.contract_address,assets:[e]}];const s=t[t.length-1];return s.contractAddress===e.contract_address&&s.assets.length<100?[...t.slice(0,-1),{...s,assets:[...s.assets,e]}]:[...t,{contractAddress:e.contract_address,assets:[e]}]}),[]),u=await Promise.allSettled(m.map((async({contractAddress:s,assets:a})=>{const i={chainName:n,contractAddress:s,createMintRequestRequest:{assets:a.map((t=>({reference_id:t.asset_id,owner_address:t.owner_address,metadata:t.metadata,token_id:t.token_id,amount:t.amount?`${t.amount}`:null})))}};try{const s=await e.createMintRequest(i);return o.info(`mintingResponse: ${JSON.stringify(s,null,2)}`),await t.updateMintingStatusToSubmitted(a.map((({id:t})=>t))),s}catch(e){if(o.error(e),d(e),"CONFLICT_ERROR"===e.code&&"reference_id"===e.details?.id)try{await t.markAsConflict(e.details.values,s),await t.resetMintingStatus(a.map((({id:t})=>t)).filter((t=>!e.details.values.includes(t))))}catch(t){o.error(t),d(e)}else{const{assetsToRetry:e,assetsExceededMaxNumberOfTries:s}=a.reduce(((t,{tried_count:e=0,id:s})=>(e<r?t.assetsToRetry.push(s):t.assetsExceededMaxNumberOfTries.push(s),t)),{assetsToRetry:[],assetsExceededMaxNumberOfTries:[]});await t.markForRetry(e),await t.updateMintingStatusToSubmissionFailed(s)}return e}})));c=u.reverse().find((t=>"fulfilled"===t.status))?.value}},_=async(t,e,a=console)=>{if((()=>{try{s(i,"processMint")}catch{}})(),"imtbl_zkevm_mint_request_updated"!==e.event_name)return void a.info(`${e.event_name} is not imtbl_zkevm_mint_request_updated, skip.`);const n=e.data.reference_id;if(!n)throw new Error("reference_id not found in webhook event");const d=e.data.contract_address;if(!d)throw new Error("contract_address not found in webhook event");"failed"===e.data.status&&a.error(`mint failed: ${JSON.stringify(e.data,null,2)}`);const r=await t.getMintingRequest(d,n);r||a.info(`minting request not found in the database, ${JSON.stringify(e.data)}`);const o=r?.wallet_address||e.data.owner_address;if(!o)throw a.error("owner_address missing"),new Error("owner_address missing");await t.syncMintingStatus({tokenId:e.data.token_id,status:e.data.status,assetId:n,contractAddress:d,ownerAddress:o,metadataId:e.data.metadata_id,imtblZkevmMintRequestUpdatedId:e.event_id,error:e.data.error?JSON.stringify(e.data.error):null,amount:e.data.amount||null})},l={zkevmMintRequestUpdated:async t=>{}};class w{baseConfig;persistence;blockchainDataClient;logger;constructor(e){this.baseConfig=e.baseConfig,this.persistence=e.persistence,this.logger=e.logger||console,this.blockchainDataClient=new t({baseConfig:e.baseConfig}),a(this.baseConfig.environment),this.baseConfig.publishableKey&&n(this.baseConfig.publishableKey)}async recordMint(t){await c(this.persistence,t)}async submitMintingRequests(t){await u(this.persistence,this.blockchainDataClient,t)}async processMint(t,s=l){await e(t,this.baseConfig.environment,{zkevmMintRequestUpdated:async t=>{await _(this.persistence,t,this.logger),s.zkevmMintRequestUpdated&&s.zkevmMintRequestUpdated(t)}})}}if("undefined"!=typeof process&&process.on)try{process.on("uncaughtExceptionMonitor",r)}catch{}var g=Object.freeze({__proto__:null,MintingBackendModule:w,mintingPersistencePg:o,mintingPersistencePrismaSqlite:m,processMint:_,recordMint:c,submitMintingRequests:u});export{w as M,o as a,m as b,g as m,_ as p,c as r,u as s};
1
+ import{B as t}from"./index-7d2761cb.js";import{h as e}from"./index-d7b7aff9.js";import{t as s,s as a,b as n}from"./index-cfadae12.js";const i="minting_backend_sdk",d=t=>{try{s(i,"error",{name:t.name,message:t.message})}catch{}},r=(t,e)=>{try{s(i,"error",{name:t.name,message:t.message,origin:e})}catch{}},o=t=>((()=>{try{s(i,"initializePersistencePG")}catch{}})(),{recordMint:async e=>{if(0===(await t.query("\n INSERT INTO im_assets (asset_id, contract_address, owner_address, metadata, amount, token_id) \n VALUES ($1, $2, $3, $4, $5, $6) ON CONFLICT (asset_id, contract_address) DO NOTHING;\n ",[e.asset_id,e.contract_address,e.owner_address,e.metadata,e.amount,e.token_id])).rowCount)throw new Error("Duplicated mint")},getNextBatchForSubmission:async e=>(await t.query("\n WITH limited_assets AS (\n SELECT id \n FROM im_assets \n WHERE minting_status IS NULL \n LIMIT $1 \n FOR UPDATE SKIP LOCKED\n )\n UPDATE im_assets \n SET minting_status = 'submitting' \n WHERE minting_status IS NULL \n AND id IN (SELECT id FROM limited_assets)\n RETURNING *;\n ",[e])).rows,updateMintingStatusToSubmitted:async e=>{await t.query("\n UPDATE im_assets SET minting_status = $2 WHERE id = ANY($1);\n ",[e,"submitted"])},syncMintingStatus:async e=>{await t.query("\n INSERT INTO im_assets (\n asset_id, \n contract_address, \n owner_address, \n token_id, \n minting_status, \n metadata_id, \n last_imtbl_zkevm_mint_request_updated_id, \n error,\n amount\n ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) ON CONFLICT (asset_id, contract_address)\n DO UPDATE SET \n owner_address = $3,\n token_id = $4,\n minting_status = $5,\n metadata_id = $6,\n last_imtbl_zkevm_mint_request_updated_id = $7,\n error = $8\n where (\n im_assets.last_imtbl_zkevm_mint_request_updated_id < $7 OR \n im_assets.last_imtbl_zkevm_mint_request_updated_id is null\n );\n ",[e.assetId,e.contractAddress,e.ownerAddress,e.tokenId,e.status,e.metadataId,e.imtblZkevmMintRequestUpdatedId,e.error,e.amount])},markAsConflict:async(e,s)=>{await t.query("\n UPDATE im_assets \n SET minting_status = 'conflicting' \n WHERE asset_id = ANY($1) \n AND contract_address = $2;\n ",[e,s])},resetMintingStatus:async e=>{await t.query("\n UPDATE im_assets SET minting_status = null WHERE id = ANY($1);\n ",[e])},markForRetry:async e=>{await t.query("\n UPDATE im_assets \n SET minting_status = null, tried_count = tried_count + 1 WHERE id = ANY($1);\n ",[e])},updateMintingStatusToSubmissionFailed:async e=>{await t.query("\n UPDATE im_assets SET minting_status = 'submission_failed' WHERE id = ANY($1);\n ",[e])},getMintingRequest:async(e,s)=>(await t.query("\n SELECT * FROM im_assets WHERE contract_address = $1 and asset_id = $2;\n ",[e,s])).rows[0]||null}),m=t=>((()=>{try{s(i,"initializePersistencePrismaSqlite")}catch{}})(),{recordMint:async e=>{if(!await t.imAssets.upsert({where:{im_assets_uindex:{assetId:e.asset_id,contractAddress:e.contract_address}},update:{},create:{assetId:e.asset_id,contractAddress:e.contract_address,ownerAddress:e.owner_address,metadata:JSON.stringify(e.metadata),amount:e.amount||null,tokenId:e.token_id||null}}))throw new Error("Duplicated mint")},getNextBatchForSubmission:async e=>{const s=(await t.imAssets.findMany({where:{mintingStatus:null},take:e})).map((t=>t.id));await t.imAssets.updateMany({where:{id:{in:s}},data:{mintingStatus:"submitting"}});return(await t.imAssets.findMany({where:{id:{in:s}}})).map((t=>({id:t.id,contract_address:t.contractAddress,wallet_address:t.ownerAddress,asset_id:t.assetId,metadata:t.metadata?JSON.parse(t.metadata):null,owner_address:t.ownerAddress,tried_count:t.triedCount,amount:t.amount||null,token_id:t.tokenId||null})))},updateMintingStatusToSubmitted:async e=>{await t.imAssets.updateMany({where:{id:{in:e}},data:{mintingStatus:"submitted"}})},syncMintingStatus:async e=>{const s=await t.imAssets.findUnique({where:{im_assets_uindex:{assetId:e.assetId,contractAddress:e.contractAddress}}});s&&(null===s.lastImtblZkevmMintRequestUpdatedId||s.lastImtblZkevmMintRequestUpdatedId<e.imtblZkevmMintRequestUpdatedId)?await t.imAssets.update({where:{im_assets_uindex:{assetId:e.assetId,contractAddress:e.contractAddress}},data:{ownerAddress:e.ownerAddress,tokenId:e.tokenId,mintingStatus:e.status,metadataId:e.metadataId,lastImtblZkevmMintRequestUpdatedId:e.imtblZkevmMintRequestUpdatedId,error:e.error,amount:e.amount||null}}):s||await t.imAssets.create({data:{assetId:e.assetId,contractAddress:e.contractAddress,ownerAddress:e.ownerAddress,tokenId:e.tokenId,mintingStatus:e.status,metadataId:e.metadataId,lastImtblZkevmMintRequestUpdatedId:e.imtblZkevmMintRequestUpdatedId,error:e.error,amount:e.amount||null}})},updateMintingStatusToSubmissionFailed:async e=>{await t.imAssets.updateMany({where:{id:{in:e}},data:{mintingStatus:"submission_failed"}})},markAsConflict:async(e,s)=>{await t.imAssets.updateMany({where:{assetId:{in:e},contractAddress:s},data:{mintingStatus:"conflicting"}})},resetMintingStatus:async e=>{await t.imAssets.updateMany({where:{id:{in:e}},data:{mintingStatus:null}})},markForRetry:async e=>{const s=await t.imAssets.findMany({where:{id:{in:e}},select:{id:!0,triedCount:!0}});for(const e of s)await t.imAssets.update({where:{id:e.id},data:{mintingStatus:null,triedCount:e.triedCount+1}})},getMintingRequest:async(e,s)=>{const a=await t.imAssets.findFirst({where:{contractAddress:e,assetId:s}});return a?{asset_id:a.assetId,contract_address:a.contractAddress,id:a.id,metadata:a.metadata?JSON.parse(a.metadata):null,owner_address:a.ownerAddress,tried_count:a.triedCount,wallet_address:a.ownerAddress,amount:a.amount||null}:null}}),c=async(t,e)=>{(()=>{try{s(i,"recordMint")}catch{}})(),t.recordMint(e)},u=async(t,e,{defaultBatchSize:a=1e3,chainName:n="imtbl-zkevm-testnet",maxNumberOfTries:r=3},o=console,m=1/0)=>{let c;(()=>{try{s(i,"submitMintingRequests")}catch{}})();let u=0;for(;u++<m;){await new Promise((t=>{setTimeout(t,1e3)}));let s=Math.min(c?.imx_remaining_mint_requests?parseInt(c.imx_remaining_mint_requests,10):a,a);if(0===s&&c&&new Date(c.imx_mint_requests_limit_reset)>new Date){o.info(`minting limit reached, waiting for reset at ${c?.imx_mint_requests_limit_reset}`);continue}0===s&&(o.info(`minting limit has been reset, use default batch size: ${a}`),c=void 0,s=a);const i=await t.getNextBatchForSubmission(s);if(0===i.length){o.info("no assets to mint");continue}const m=i.sort(((t,e)=>t.contract_address>e.contract_address?1:-1)).reduce(((t,e)=>{if(0===t.length)return[{contractAddress:e.contract_address,assets:[e]}];const s=t[t.length-1];return s.contractAddress===e.contract_address&&s.assets.length<100?[...t.slice(0,-1),{...s,assets:[...s.assets,e]}]:[...t,{contractAddress:e.contract_address,assets:[e]}]}),[]),u=await Promise.allSettled(m.map((async({contractAddress:s,assets:a})=>{const i={chainName:n,contractAddress:s,createMintRequestRequest:{assets:a.map((t=>({reference_id:t.asset_id,owner_address:t.owner_address,metadata:t.metadata,token_id:t.token_id,amount:t.amount?`${t.amount}`:null})))}};try{const s=await e.createMintRequest(i);return o.info(`mintingResponse: ${JSON.stringify(s,null,2)}`),await t.updateMintingStatusToSubmitted(a.map((({id:t})=>t))),s}catch(e){if(o.error(e),d(e),"CONFLICT_ERROR"===e.code&&"reference_id"===e.details?.id)try{await t.markAsConflict(e.details.values,s),await t.resetMintingStatus(a.map((({id:t})=>t)).filter((t=>!e.details.values.includes(t))))}catch(t){o.error(t),d(e)}else{const{assetsToRetry:e,assetsExceededMaxNumberOfTries:s}=a.reduce(((t,{tried_count:e=0,id:s})=>(e<r?t.assetsToRetry.push(s):t.assetsExceededMaxNumberOfTries.push(s),t)),{assetsToRetry:[],assetsExceededMaxNumberOfTries:[]});await t.markForRetry(e),await t.updateMintingStatusToSubmissionFailed(s)}return e}})));c=u.reverse().find((t=>"fulfilled"===t.status))?.value}},_=async(t,e,a=console)=>{if((()=>{try{s(i,"processMint")}catch{}})(),"imtbl_zkevm_mint_request_updated"!==e.event_name)return void a.info(`${e.event_name} is not imtbl_zkevm_mint_request_updated, skip.`);const n=e.data.reference_id;if(!n)throw new Error("reference_id not found in webhook event");const d=e.data.contract_address;if(!d)throw new Error("contract_address not found in webhook event");"failed"===e.data.status&&a.error(`mint failed: ${JSON.stringify(e.data,null,2)}`);const r=await t.getMintingRequest(d,n);r||a.info(`minting request not found in the database, ${JSON.stringify(e.data)}`);const o=r?.wallet_address||e.data.owner_address;if(!o)throw a.error("owner_address missing"),new Error("owner_address missing");await t.syncMintingStatus({tokenId:e.data.token_id,status:e.data.status,assetId:n,contractAddress:d,ownerAddress:o,metadataId:e.data.metadata_id,imtblZkevmMintRequestUpdatedId:e.event_id,error:e.data.error?JSON.stringify(e.data.error):null,amount:e.data.amount||null})},l={zkevmMintRequestUpdated:async t=>{}};class w{baseConfig;persistence;blockchainDataClient;logger;constructor(e){this.baseConfig=e.baseConfig,this.persistence=e.persistence,this.logger=e.logger||console,this.blockchainDataClient=new t({baseConfig:e.baseConfig}),a(this.baseConfig.environment),this.baseConfig.publishableKey&&n(this.baseConfig.publishableKey)}async recordMint(t){await c(this.persistence,t)}async submitMintingRequests(t){await u(this.persistence,this.blockchainDataClient,t)}async processMint(t,s=l){await e(t,this.baseConfig.environment,{zkevmMintRequestUpdated:async t=>{await _(this.persistence,t,this.logger),s.zkevmMintRequestUpdated&&s.zkevmMintRequestUpdated(t)}})}}if("undefined"!=typeof process&&process.on)try{process.on("uncaughtExceptionMonitor",r)}catch{}var g=Object.freeze({__proto__:null,MintingBackendModule:w,mintingPersistencePg:o,mintingPersistencePrismaSqlite:m,processMint:_,recordMint:c,submitMintingRequests:u});export{w as M,o as a,m as b,g as m,_ as p,c as r,u as s};
@@ -1 +1 @@
1
- export{M as MintingBackendModule,a as mintingPersistencePg,b as mintingPersistencePrismaSqlite,p as processMint,r as recordMint,s as submitMintingRequests}from"./minting_backend-929041e8.js";import"./index-fffda076.js";import"./index-e1d8ce77.js";import"axios";import"./index-92dae7ab.js";import"lru-memorise";import"global-const";import"./index-7e641800.js";import"sns-validator";
1
+ export{M as MintingBackendModule,a as mintingPersistencePg,b as mintingPersistencePrismaSqlite,p as processMint,r as recordMint,s as submitMintingRequests}from"./minting_backend-10ddbfd1.js";import"./index-7d2761cb.js";import"./index-3c4d20df.js";import"axios";import"./index-cfadae12.js";import"lru-memorise";import"global-const";import"./index-d7b7aff9.js";import"sns-validator";
@@ -1 +1 @@
1
- import{A as e,F as r,O as t,a,S as s,T as n,c as o}from"./index-fd5abec4.js";var u=Object.freeze({__proto__:null,get ActionType(){return e},get FeeType(){return r},get OrderStatusName(){return t},Orderbook:a,get SignablePurpose(){return s},get TransactionPurpose(){return n},constants:o});export{u as o};
1
+ import{A as e,F as r,O as t,a,S as s,T as n,c as o}from"./index-1ff17202.js";var u=Object.freeze({__proto__:null,get ActionType(){return e},get FeeType(){return r},get OrderStatusName(){return t},Orderbook:a,get SignablePurpose(){return s},get TransactionPurpose(){return n},constants:o});export{u as o};
package/dist/orderbook.js CHANGED
@@ -1 +1 @@
1
- export{A as ActionType,F as FeeType,O as OrderStatusName,a as Orderbook,S as SignablePurpose,T as TransactionPurpose,c as constants}from"./index-fd5abec4.js";import"axios";import"form-data";import"ethers";import"ethers-v6";import"merkletreejs";import"./index-92dae7ab.js";import"lru-memorise";import"global-const";import"@opensea/seaport-js";
1
+ export{A as ActionType,F as FeeType,O as OrderStatusName,a as Orderbook,S as SignablePurpose,T as TransactionPurpose,c as constants}from"./index-1ff17202.js";import"axios";import"form-data";import"ethers";import"ethers-v6";import"merkletreejs";import"./index-cfadae12.js";import"lru-memorise";import"global-const";import"@opensea/seaport-js";