@imtbl/sdk 0.11.0-alpha → 0.12.0-alpha

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/index.cjs CHANGED
@@ -2420,7 +2420,7 @@ class MultiRollupApiClients {
2420
2420
  }
2421
2421
 
2422
2422
  // eslint-disable-next-line @typescript-eslint/naming-convention
2423
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.11.0-alpha' };
2423
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.12.0-alpha' };
2424
2424
  const createConfig = ({ basePath, headers, }) => {
2425
2425
  if (!basePath.trim()) {
2426
2426
  throw Error('basePath can not be empty');
@@ -2480,7 +2480,7 @@ class APIError extends Error {
2480
2480
 
2481
2481
  /* eslint-disable implicit-arrow-linebreak */
2482
2482
  const defaultHeaders = {
2483
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.11.0-alpha',
2483
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.12.0-alpha',
2484
2484
  };
2485
2485
  /**
2486
2486
  * createAPIConfiguration to create a custom Configuration
@@ -2752,7 +2752,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
2752
2752
  chainID,
2753
2753
  coreContractAddress,
2754
2754
  registrationContractAddress,
2755
- sdkVersion: 'ts-immutable-sdk-0.11.0-alpha',
2755
+ sdkVersion: 'ts-immutable-sdk-0.12.0-alpha',
2756
2756
  });
2757
2757
  /**
2758
2758
  * Sets `sdkVersion` at the time of build
@@ -7418,22 +7418,28 @@ class AuthManager {
7418
7418
 
7419
7419
  class MagicAdapter {
7420
7420
  config;
7421
+ magicClient;
7421
7422
  constructor(config) {
7422
7423
  this.config = config;
7423
7424
  }
7424
7425
  async login(idToken, network) {
7425
7426
  return withPassportError(async () => {
7426
- const magicClient = new magicSdk.Magic(this.config.magicPublishableApiKey, {
7427
+ this.magicClient = new magicSdk.Magic(this.config.magicPublishableApiKey, {
7427
7428
  extensions: [new oidc.OpenIdExtension()],
7428
7429
  network,
7429
7430
  });
7430
- await magicClient.openid.loginWithOIDC({
7431
+ await this.magicClient.openid.loginWithOIDC({
7431
7432
  jwt: idToken,
7432
7433
  providerId: this.config.magicProviderId,
7433
7434
  });
7434
- return magicClient.rpcProvider;
7435
+ return this.magicClient.rpcProvider;
7435
7436
  }, PassportErrorType.WALLET_CONNECTION_ERROR);
7436
7437
  }
7438
+ async logout() {
7439
+ if (this.magicClient?.user) {
7440
+ await this.magicClient.user.logout();
7441
+ }
7442
+ }
7437
7443
  }
7438
7444
 
7439
7445
  const getStarkSigner = async (signer) => withPassportError(async () => {
@@ -7467,6 +7473,8 @@ const retryWithDelay = async (fn, options) => {
7467
7473
 
7468
7474
  /**
7469
7475
  * ProviderErrors should take priority over RpcErrorCodes
7476
+ * https://eips.ethereum.org/EIPS/eip-1193#provider-errors
7477
+ * https://eips.ethereum.org/EIPS/eip-1474#error-codes
7470
7478
  */
7471
7479
  var ProviderErrorCode;
7472
7480
  (function (ProviderErrorCode) {
@@ -7483,7 +7491,7 @@ var RpcErrorCode;
7483
7491
  RpcErrorCode[RpcErrorCode["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
7484
7492
  RpcErrorCode[RpcErrorCode["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
7485
7493
  RpcErrorCode[RpcErrorCode["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
7486
- RpcErrorCode[RpcErrorCode["USER_REJECTED_REQUEST"] = -32003] = "USER_REJECTED_REQUEST";
7494
+ RpcErrorCode[RpcErrorCode["TRANSACTION_REJECTED"] = -32003] = "TRANSACTION_REJECTED";
7487
7495
  })(RpcErrorCode || (RpcErrorCode = {}));
7488
7496
  class JsonRpcError extends Error {
7489
7497
  message;
@@ -7495,6 +7503,8 @@ class JsonRpcError extends Error {
7495
7503
  }
7496
7504
  }
7497
7505
 
7506
+ const transactionRejectedCrossSdkBridgeError = 'Transaction requires confirmation but this functionality is not'
7507
+ + ' supported in this environment. Please contact Immutable support if you need to enable this feature.';
7498
7508
  const convertBigNumberishToString = (value) => ethers.BigNumber.from(value).toString();
7499
7509
  const transformGuardianTransactions = (txs) => {
7500
7510
  try {
@@ -7517,13 +7527,15 @@ class GuardianClient {
7517
7527
  confirmationScreen;
7518
7528
  // TODO: ID-977, make this rollup agnostic
7519
7529
  imxEtherAddress;
7520
- constructor({ imxPublicApiDomain, accessToken, confirmationScreen, imxEtherAddress, }) {
7530
+ crossSdkBridgeEnabled;
7531
+ constructor({ accessToken, confirmationScreen, imxEtherAddress, config, }) {
7521
7532
  this.confirmationScreen = confirmationScreen;
7522
7533
  this.transactionAPI = new TransactionsApi(new Configuration({
7523
7534
  accessToken,
7524
- basePath: imxPublicApiDomain,
7535
+ basePath: config.imxPublicApiDomain,
7525
7536
  }));
7526
7537
  this.imxEtherAddress = imxEtherAddress;
7538
+ this.crossSdkBridgeEnabled = config.crossSdkBridgeEnabled;
7527
7539
  }
7528
7540
  /**
7529
7541
  * Open confirmation screen and close it automatically if the
@@ -7536,8 +7548,7 @@ class GuardianClient {
7536
7548
  return (task) => async () => {
7537
7549
  this.confirmationScreen.loading(popupWindowSize);
7538
7550
  try {
7539
- const result = await task();
7540
- return result;
7551
+ return await task();
7541
7552
  }
7542
7553
  catch (err) {
7543
7554
  this.confirmationScreen.closeWindow();
@@ -7567,7 +7578,10 @@ class GuardianClient {
7567
7578
  });
7568
7579
  const { confirmationRequired } = evaluateStarkexRes.data;
7569
7580
  if (confirmationRequired) {
7570
- const confirmationResult = await this.confirmationScreen.startGuardianTransaction(payloadHash, this.imxEtherAddress, TransactionApprovalRequestChainTypeEnum.Starkex);
7581
+ if (this.crossSdkBridgeEnabled) {
7582
+ throw new Error(transactionRejectedCrossSdkBridgeError);
7583
+ }
7584
+ const confirmationResult = await this.confirmationScreen.requestConfirmation(payloadHash, this.imxEtherAddress, TransactionApprovalRequestChainTypeEnum.Starkex);
7571
7585
  if (!confirmationResult.confirmed) {
7572
7586
  throw new Error('Transaction rejected by user');
7573
7587
  }
@@ -7607,10 +7621,13 @@ class GuardianClient {
7607
7621
  metaTransactions,
7608
7622
  });
7609
7623
  const { confirmationRequired, transactionId } = transactionEvaluationResponse;
7624
+ if (confirmationRequired && this.crossSdkBridgeEnabled) {
7625
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
7626
+ }
7610
7627
  if (confirmationRequired && !!transactionId) {
7611
- const confirmationResult = await this.confirmationScreen.startGuardianTransaction(transactionId, this.imxEtherAddress, TransactionApprovalRequestChainTypeEnum.Evm, chainId);
7628
+ const confirmationResult = await this.confirmationScreen.requestConfirmation(transactionId, this.imxEtherAddress, TransactionApprovalRequestChainTypeEnum.Evm, chainId);
7612
7629
  if (!confirmationResult.confirmed) {
7613
- throw new JsonRpcError(RpcErrorCode.USER_REJECTED_REQUEST, 'Transaction rejected by user ');
7630
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Transaction rejected by user');
7614
7631
  }
7615
7632
  }
7616
7633
  else {
@@ -7619,6 +7636,16 @@ class GuardianClient {
7619
7636
  }
7620
7637
  }
7621
7638
 
7639
+ var PassportEvents;
7640
+ (function (PassportEvents) {
7641
+ PassportEvents["LOGGED_OUT"] = "loggedOut";
7642
+ })(PassportEvents || (PassportEvents = {}));
7643
+ var Networks;
7644
+ (function (Networks) {
7645
+ Networks["PRODUCTION"] = "mainnet";
7646
+ Networks["SANDBOX"] = "goerli";
7647
+ })(Networks || (Networks = {}));
7648
+
7622
7649
  async function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, }) {
7623
7650
  return withPassportError(async () => {
7624
7651
  const { ethAddress } = user.imx;
@@ -7818,10 +7845,10 @@ async function createTrade$1({ request, tradesApi, user, starkSigner, guardianCl
7818
7845
  }), PassportErrorType.CREATE_TRADE_ERROR);
7819
7846
  }
7820
7847
 
7821
- const ERC721$2 = 'ERC721';
7848
+ const ERC721 = 'ERC721';
7822
7849
  async function transfer$1({ request, transfersApi, starkSigner, user, guardianClient, }) {
7823
7850
  return withPassportError(guardianClient.withDefaultConfirmationScreenTask(async () => {
7824
- const transferAmount = request.type === ERC721$2 ? '1' : request.amount;
7851
+ const transferAmount = request.type === ERC721 ? '1' : request.amount;
7825
7852
  const getSignableTransferRequest = {
7826
7853
  sender: user.imx.ethAddress,
7827
7854
  token: convertToSignableToken(request),
@@ -7871,7 +7898,7 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, guar
7871
7898
  const signableRequests = request.map((nftTransfer) => ({
7872
7899
  amount: '1',
7873
7900
  token: convertToSignableToken({
7874
- type: ERC721$2,
7901
+ type: ERC721,
7875
7902
  tokenId: nftTransfer.tokenId,
7876
7903
  tokenAddress: nftTransfer.tokenAddress,
7877
7904
  }),
@@ -7923,19 +7950,30 @@ class PassportImxProvider {
7923
7950
  immutableXClient;
7924
7951
  confirmationScreen;
7925
7952
  guardianClient;
7926
- constructor({ user, starkSigner, immutableXClient, imxPublicApiDomain, confirmationScreen, }) {
7953
+ constructor({ user, starkSigner, immutableXClient, confirmationScreen, config, passportEventEmitter, }) {
7927
7954
  this.user = user;
7928
7955
  this.starkSigner = starkSigner;
7929
7956
  this.immutableXClient = immutableXClient;
7930
7957
  this.confirmationScreen = confirmationScreen;
7931
7958
  this.guardianClient = new GuardianClient({
7932
- imxPublicApiDomain,
7933
7959
  accessToken: user.accessToken,
7934
7960
  confirmationScreen,
7935
7961
  imxEtherAddress: user.imx.ethAddress,
7962
+ config,
7936
7963
  });
7964
+ passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.handleLogout);
7965
+ }
7966
+ handleLogout = () => {
7967
+ this.user = undefined;
7968
+ this.starkSigner = undefined;
7969
+ };
7970
+ checkIsLoggedIn() {
7971
+ if (this.user === undefined || this.starkSigner === undefined) {
7972
+ throw new PassportError('User has been logged out', PassportErrorType.NOT_LOGGED_IN_ERROR);
7973
+ }
7937
7974
  }
7938
7975
  async transfer(request) {
7976
+ this.checkIsLoggedIn();
7939
7977
  return transfer$1({
7940
7978
  request,
7941
7979
  user: this.user,
@@ -7955,6 +7993,7 @@ class PassportImxProvider {
7955
7993
  throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
7956
7994
  }
7957
7995
  createOrder(request) {
7996
+ this.checkIsLoggedIn();
7958
7997
  return createOrder$1({
7959
7998
  request,
7960
7999
  user: this.user,
@@ -7964,6 +8003,7 @@ class PassportImxProvider {
7964
8003
  });
7965
8004
  }
7966
8005
  cancelOrder(request) {
8006
+ this.checkIsLoggedIn();
7967
8007
  return cancelOrder$1({
7968
8008
  request,
7969
8009
  user: this.user,
@@ -7973,6 +8013,7 @@ class PassportImxProvider {
7973
8013
  });
7974
8014
  }
7975
8015
  createTrade(request) {
8016
+ this.checkIsLoggedIn();
7976
8017
  return createTrade$1({
7977
8018
  request,
7978
8019
  user: this.user,
@@ -7982,6 +8023,7 @@ class PassportImxProvider {
7982
8023
  });
7983
8024
  }
7984
8025
  batchNftTransfer(request) {
8026
+ this.checkIsLoggedIn();
7985
8027
  return batchNftTransfer({
7986
8028
  request,
7987
8029
  user: this.user,
@@ -7991,6 +8033,7 @@ class PassportImxProvider {
7991
8033
  });
7992
8034
  }
7993
8035
  exchangeTransfer(request) {
8036
+ this.checkIsLoggedIn();
7994
8037
  return exchangeTransfer$1({
7995
8038
  request,
7996
8039
  user: this.user,
@@ -8018,6 +8061,7 @@ class PassportImxProvider {
8018
8061
  throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
8019
8062
  }
8020
8063
  getAddress() {
8064
+ this.checkIsLoggedIn();
8021
8065
  return Promise.resolve(this.user.imx.ethAddress);
8022
8066
  }
8023
8067
  }
@@ -8028,12 +8072,14 @@ class PassportImxProviderFactory {
8028
8072
  confirmationScreen;
8029
8073
  immutableXClient;
8030
8074
  magicAdapter;
8031
- constructor({ authManager, config, confirmationScreen, immutableXClient, magicAdapter, }) {
8075
+ passportEventEmitter;
8076
+ constructor({ authManager, config, confirmationScreen, immutableXClient, magicAdapter, passportEventEmitter, }) {
8032
8077
  this.authManager = authManager;
8033
8078
  this.config = config;
8034
8079
  this.confirmationScreen = confirmationScreen;
8035
8080
  this.immutableXClient = immutableXClient;
8036
8081
  this.magicAdapter = magicAdapter;
8082
+ this.passportEventEmitter = passportEventEmitter;
8037
8083
  }
8038
8084
  async getProvider() {
8039
8085
  const user = await this.authManager.login();
@@ -8075,16 +8121,18 @@ class PassportImxProviderFactory {
8075
8121
  user: userImx,
8076
8122
  starkSigner,
8077
8123
  immutableXClient: this.immutableXClient,
8078
- imxPublicApiDomain: this.config.imxPublicApiDomain,
8079
8124
  confirmationScreen: this.confirmationScreen,
8125
+ config: this.config,
8126
+ passportEventEmitter: this.passportEventEmitter,
8080
8127
  });
8081
8128
  }
8082
8129
  return new PassportImxProvider({
8083
8130
  user: user,
8084
8131
  starkSigner,
8085
8132
  immutableXClient: this.immutableXClient,
8086
- imxPublicApiDomain: this.config.imxPublicApiDomain,
8087
8133
  confirmationScreen: this.confirmationScreen,
8134
+ config: this.config,
8135
+ passportEventEmitter: this.passportEventEmitter,
8088
8136
  });
8089
8137
  }
8090
8138
  async registerStarkEx(userAdminKeySigner, starkSigner, jwt) {
@@ -8108,12 +8156,6 @@ class PassportImxProviderFactory {
8108
8156
  }
8109
8157
  }
8110
8158
 
8111
- var Networks;
8112
- (function (Networks) {
8113
- Networks["PRODUCTION"] = "mainnet";
8114
- Networks["SANDBOX"] = "goerli";
8115
- })(Networks || (Networks = {}));
8116
-
8117
8159
  const validateConfiguration = (configuration, requiredKeys, prefix) => {
8118
8160
  const missingKeys = requiredKeys
8119
8161
  .map((key) => !configuration[key] && key)
@@ -8135,11 +8177,11 @@ class PassportConfiguration {
8135
8177
  magicProviderId;
8136
8178
  oidcConfiguration;
8137
8179
  baseConfig;
8138
- zkEvmChainId;
8139
8180
  zkEvmRpcUrl;
8140
8181
  relayerUrl;
8141
8182
  multiRollupConfig;
8142
- constructor({ baseConfig, overrides, ...oidcConfiguration }) {
8183
+ crossSdkBridgeEnabled;
8184
+ constructor({ baseConfig, overrides, crossSdkBridgeEnabled, ...oidcConfiguration }) {
8143
8185
  validateConfiguration(oidcConfiguration, [
8144
8186
  'clientId',
8145
8187
  'logoutRedirectUri',
@@ -8147,6 +8189,7 @@ class PassportConfiguration {
8147
8189
  ]);
8148
8190
  this.oidcConfiguration = oidcConfiguration;
8149
8191
  this.baseConfig = baseConfig;
8192
+ this.crossSdkBridgeEnabled = crossSdkBridgeEnabled || false;
8150
8193
  if (overrides) {
8151
8194
  validateConfiguration(overrides, [
8152
8195
  'network',
@@ -8155,7 +8198,6 @@ class PassportConfiguration {
8155
8198
  'magicPublishableApiKey',
8156
8199
  'magicProviderId',
8157
8200
  'zkEvmRpcUrl',
8158
- 'zkEvmChainId',
8159
8201
  'relayerUrl',
8160
8202
  'imxPublicApiDomain',
8161
8203
  'indexerMrBasePath',
@@ -8169,7 +8211,6 @@ class PassportConfiguration {
8169
8211
  this.magicPublishableApiKey = overrides.magicPublishableApiKey;
8170
8212
  this.magicProviderId = overrides.magicProviderId;
8171
8213
  this.zkEvmRpcUrl = overrides.zkEvmRpcUrl;
8172
- this.zkEvmChainId = overrides.zkEvmChainId;
8173
8214
  this.relayerUrl = overrides.relayerUrl;
8174
8215
  this.multiRollupConfig = {
8175
8216
  indexer: createConfig({
@@ -8193,7 +8234,6 @@ class PassportConfiguration {
8193
8234
  this.passportDomain = 'https://passport.immutable.com';
8194
8235
  this.imxPublicApiDomain = 'https://api.immutable.com';
8195
8236
  this.zkEvmRpcUrl = ''; // TODO: ID-785 Update once mainnet has been deployed
8196
- this.zkEvmChainId = ''; // TODO: ID-785 Update once mainnet has been deployed
8197
8237
  this.relayerUrl = 'https://api.immutable.com/relayer-mr';
8198
8238
  this.multiRollupConfig = multiRollupConfig.getProduction();
8199
8239
  break;
@@ -8207,7 +8247,6 @@ class PassportConfiguration {
8207
8247
  this.passportDomain = 'https://passport.sandbox.immutable.com';
8208
8248
  this.imxPublicApiDomain = 'https://api.sandbox.immutable.com';
8209
8249
  this.zkEvmRpcUrl = 'https://rpc.testnet.immutable.com';
8210
- this.zkEvmChainId = 'eip155:13472';
8211
8250
  this.relayerUrl = 'https://api.sandbox.immutable.com/relayer-mr';
8212
8251
  this.multiRollupConfig = multiRollupConfig.getSandbox();
8213
8252
  break;
@@ -8223,18 +8262,6 @@ var ReceiveMessage;
8223
8262
  ReceiveMessage["TRANSACTION_CONFIRMED"] = "transaction_confirmed";
8224
8263
  ReceiveMessage["TRANSACTION_ERROR"] = "transaction_error";
8225
8264
  })(ReceiveMessage || (ReceiveMessage = {}));
8226
- var SendMessage;
8227
- (function (SendMessage) {
8228
- SendMessage["TRANSACTION_START"] = "transaction_start";
8229
- })(SendMessage || (SendMessage = {}));
8230
- var TransactionTypes$1;
8231
- (function (TransactionTypes) {
8232
- TransactionTypes["cancelOrder"] = "delete:v1/orders";
8233
- TransactionTypes["createOrder"] = "post:v1/orders";
8234
- TransactionTypes["createTrade"] = "post:v1/trades";
8235
- TransactionTypes["createTransfer"] = "post:v1/transfers";
8236
- TransactionTypes["createBatchTransfer"] = "post:v2/transfers";
8237
- })(TransactionTypes$1 || (TransactionTypes$1 = {}));
8238
8265
  const PASSPORT_EVENT_TYPE = 'imx_passport_confirmation';
8239
8266
 
8240
8267
  const openPopupCenter = ({ url, title, width, height, }) => {
@@ -8264,60 +8291,7 @@ class ConfirmationScreen {
8264
8291
  constructor(config) {
8265
8292
  this.config = config;
8266
8293
  }
8267
- postMessage(destinationWindow, accessToken, message) {
8268
- destinationWindow.postMessage({
8269
- eventType: PASSPORT_EVENT_TYPE,
8270
- accessToken,
8271
- ...message,
8272
- }, this.config.passportDomain);
8273
- }
8274
- startTransaction(accessToken, transaction, popupOptions) {
8275
- return new Promise((resolve, reject) => {
8276
- const messageHandler = ({ data, origin }) => {
8277
- if (origin !== this.config.passportDomain
8278
- || data.eventType !== PASSPORT_EVENT_TYPE) {
8279
- return;
8280
- }
8281
- switch (data.messageType) {
8282
- case ReceiveMessage.CONFIRMATION_WINDOW_READY: {
8283
- // TODO: remove once fixed
8284
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
8285
- this.postMessage(confirmationWindow, accessToken, {
8286
- messageType: SendMessage.TRANSACTION_START,
8287
- messageData: transaction,
8288
- });
8289
- break;
8290
- }
8291
- case ReceiveMessage.TRANSACTION_CONFIRMED: {
8292
- resolve({ confirmed: true });
8293
- break;
8294
- }
8295
- case ReceiveMessage.TRANSACTION_ERROR: {
8296
- reject(new Error('Transaction error'));
8297
- break;
8298
- }
8299
- default:
8300
- reject(new Error('Unsupported message type'));
8301
- }
8302
- };
8303
- window.addEventListener('message', messageHandler);
8304
- const confirmationWindow = openPopupCenter({
8305
- url: `${this.config.passportDomain}/transaction-confirmation`,
8306
- title: CONFIRMATION_WINDOW_TITLE,
8307
- width: popupOptions?.width || CONFIRMATION_WINDOW_WIDTH,
8308
- height: popupOptions?.height || CONFIRMATION_WINDOW_HEIGHT,
8309
- });
8310
- // https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
8311
- const timer = setInterval(() => {
8312
- if (confirmationWindow.closed) {
8313
- clearInterval(timer);
8314
- window.removeEventListener('message', messageHandler);
8315
- resolve({ confirmed: false });
8316
- }
8317
- }, CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION);
8318
- });
8319
- }
8320
- startGuardianTransaction(transactionId, imxEtherAddress, chainType, chainId) {
8294
+ requestConfirmation(transactionId, imxEtherAddress, chainType, chainId) {
8321
8295
  return new Promise((resolve, reject) => {
8322
8296
  const messageHandler = ({ data, origin }) => {
8323
8297
  if (origin !== this.config.passportDomain
@@ -8345,7 +8319,6 @@ class ConfirmationScreen {
8345
8319
  resolve({ confirmed: false });
8346
8320
  return;
8347
8321
  }
8348
- // eslint-disable-next-line max-len
8349
8322
  let href = '';
8350
8323
  if (chainType === TransactionApprovalRequestChainTypeEnum.Starkex) {
8351
8324
  // eslint-disable-next-line max-len
@@ -8367,6 +8340,10 @@ class ConfirmationScreen {
8367
8340
  });
8368
8341
  }
8369
8342
  loading(popupOptions) {
8343
+ if (this.config.crossSdkBridgeEnabled) {
8344
+ // There is no need to open a confirmation window if cross-sdk bridge is enabled
8345
+ return;
8346
+ }
8370
8347
  this.confirmationWindow = openPopupCenter({
8371
8348
  url: `${this.config.passportDomain}/transaction-confirmation/loading.html`,
8372
8349
  title: CONFIRMATION_WINDOW_TITLE,
@@ -8405,11 +8382,82 @@ class TypedEventEmitter {
8405
8382
  }
8406
8383
  }
8407
8384
 
8385
+ // These are ignored by the Relayer but for consistency we set them to the
8386
+ // appropriate values for a 1/1 wallet.
8387
+ //
8388
+ // Weight of a single signature in the multisig
8389
+ const SIGNATURE_WEIGHT = 1;
8390
+ // Total required weight in the multisig
8391
+ const SIGNATURE_THRESHOLD = 1;
8392
+ const ETH_SIGN_FLAG = '02';
8393
+ const ETH_SIGN_PREFIX = '\x19\x01';
8394
+ const META_TRANSACTIONS_TYPE = `tuple(
8395
+ bool delegateCall,
8396
+ bool revertOnError,
8397
+ uint256 gasLimit,
8398
+ address target,
8399
+ uint256 value,
8400
+ bytes data
8401
+ )[]`;
8402
+ function getNormalisedTransactions(txs) {
8403
+ return txs.map((t) => ({
8404
+ delegateCall: t.delegateCall === true,
8405
+ revertOnError: t.revertOnError === true,
8406
+ gasLimit: t.gasLimit ?? ethers.ethers.constants.Zero,
8407
+ target: t.to ?? ethers.ethers.constants.AddressZero,
8408
+ value: t.value ?? ethers.ethers.constants.Zero,
8409
+ data: t.data ?? [],
8410
+ }));
8411
+ }
8412
+ function digestOfTransactionsAndNonce(nonce, normalisedTransactions) {
8413
+ const packMetaTransactionsNonceData = ethers.ethers.utils.defaultAbiCoder.encode(['uint256', META_TRANSACTIONS_TYPE], [nonce, normalisedTransactions]);
8414
+ return ethers.ethers.utils.keccak256(packMetaTransactionsNonceData);
8415
+ }
8416
+ const getNonce = async (jsonRpcProvider, smartContractWalletAddress) => {
8417
+ const code = await jsonRpcProvider.send('eth_getCode', [smartContractWalletAddress, 'latest']);
8418
+ if (code && code !== '0x') {
8419
+ const contract = new ethers.ethers.Contract(smartContractWalletAddress, abi.walletContracts.mainModule.abi, jsonRpcProvider);
8420
+ return contract.nonce();
8421
+ }
8422
+ return 0;
8423
+ };
8424
+ const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walletAddress, signer) => {
8425
+ const normalisedMetaTransactions = getNormalisedTransactions(metaTransactions);
8426
+ // Get the hash
8427
+ const digest = digestOfTransactionsAndNonce(nonce, normalisedMetaTransactions);
8428
+ const completePayload = ethers.ethers.utils.solidityPack(['string', 'uint256', 'address', 'bytes32'], [ETH_SIGN_PREFIX, chainId, walletAddress, digest]);
8429
+ const hash = ethers.ethers.utils.keccak256(completePayload);
8430
+ // Sign the digest
8431
+ const hashArray = ethers.ethers.utils.arrayify(hash);
8432
+ const ethsigNoType = await signer.signMessage(hashArray);
8433
+ const signedDigest = `${ethsigNoType}${ETH_SIGN_FLAG}`;
8434
+ // Add metadata
8435
+ const encodedSignature = config$1.encodeSignature({
8436
+ threshold: SIGNATURE_THRESHOLD,
8437
+ signers: [
8438
+ {
8439
+ weight: SIGNATURE_WEIGHT,
8440
+ signature: signedDigest,
8441
+ },
8442
+ ],
8443
+ });
8444
+ // Encode the transaction;
8445
+ const walletInterface = new ethers.ethers.utils.Interface(abi.walletContracts.mainModule.abi);
8446
+ return walletInterface.encodeFunctionData(walletInterface.getFunction('execute'), [
8447
+ normalisedMetaTransactions,
8448
+ nonce,
8449
+ encodedSignature,
8450
+ ]);
8451
+ };
8452
+ const getEip155ChainId = (chainId) => `eip155:${chainId}`;
8453
+
8408
8454
  class RelayerClient {
8409
8455
  config;
8456
+ jsonRpcProvider;
8410
8457
  user;
8411
- constructor({ config, user }) {
8458
+ constructor({ config, jsonRpcProvider, user }) {
8412
8459
  this.config = config;
8460
+ this.jsonRpcProvider = jsonRpcProvider;
8413
8461
  this.user = user;
8414
8462
  }
8415
8463
  async postToRelayer(request) {
@@ -8433,12 +8481,13 @@ class RelayerClient {
8433
8481
  return jsonResponse;
8434
8482
  }
8435
8483
  async ethSendTransaction(to, data) {
8484
+ const { chainId } = await this.jsonRpcProvider.ready;
8436
8485
  const payload = {
8437
8486
  method: 'eth_sendTransaction',
8438
8487
  params: [{
8439
8488
  to,
8440
8489
  data,
8441
- chainId: this.config.zkEvmChainId.toString(),
8490
+ chainId: getEip155ChainId(chainId),
8442
8491
  }],
8443
8492
  };
8444
8493
  const { result } = await this.postToRelayer(payload);
@@ -8453,12 +8502,13 @@ class RelayerClient {
8453
8502
  return result;
8454
8503
  }
8455
8504
  async imGetFeeOptions(userAddress, data) {
8505
+ const { chainId } = await this.jsonRpcProvider.ready;
8456
8506
  const payload = {
8457
8507
  method: 'im_getFeeOptions',
8458
8508
  params: [{
8459
8509
  userAddress,
8460
8510
  data,
8461
- chainId: this.config.zkEvmChainId.toString(),
8511
+ chainId: getEip155ChainId(chainId),
8462
8512
  }],
8463
8513
  };
8464
8514
  const { result } = await this.postToRelayer(payload);
@@ -8516,90 +8566,16 @@ const loginZkEvmUser = async ({ authManager, config, magicAdapter, multiRollupAp
8516
8566
  };
8517
8567
  };
8518
8568
 
8519
- // These are ignored by the Relayer but for consistency we set them to the
8520
- // appropriate values for a 1/1 wallet.
8521
- //
8522
- // Weight of a single signature in the multisig
8523
- const SIGNATURE_WEIGHT = 1;
8524
- // Total required weight in the multisig
8525
- const SIGNATURE_THRESHOLD = 1;
8526
- const ETH_SIGN_FLAG = '02';
8527
- const ETH_SIGN_PREFIX = '\x19\x01';
8528
- const META_TRANSACTIONS_TYPE = `tuple(
8529
- bool delegateCall,
8530
- bool revertOnError,
8531
- uint256 gasLimit,
8532
- address target,
8533
- uint256 value,
8534
- bytes data
8535
- )[]`;
8536
- function getNormalisedTransactions(txs) {
8537
- return txs.map((t) => ({
8538
- delegateCall: t.delegateCall === true,
8539
- revertOnError: t.revertOnError === true,
8540
- gasLimit: t.gasLimit ?? ethers.ethers.constants.Zero,
8541
- target: t.to ?? ethers.ethers.constants.AddressZero,
8542
- value: t.value ?? ethers.ethers.constants.Zero,
8543
- data: t.data ?? [],
8544
- }));
8545
- }
8546
- function digestOfTransactionsAndNonce(nonce, normalisedTransactions) {
8547
- const packMetaTransactionsNonceData = ethers.ethers.utils.defaultAbiCoder.encode(['uint256', META_TRANSACTIONS_TYPE], [nonce, normalisedTransactions]);
8548
- return ethers.ethers.utils.keccak256(packMetaTransactionsNonceData);
8549
- }
8550
- const getNonce = async (jsonRpcProvider, smartContractWalletAddress) => {
8551
- const code = await jsonRpcProvider.send('eth_getCode', [smartContractWalletAddress, 'latest']);
8552
- if (code && code !== '0x') {
8553
- const contract = new ethers.ethers.Contract(smartContractWalletAddress, abi.walletContracts.mainModule.abi, jsonRpcProvider);
8554
- return contract.nonce();
8555
- }
8556
- return 0;
8557
- };
8558
- const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walletAddress, signer) => {
8559
- const normalisedMetaTransactions = getNormalisedTransactions(metaTransactions);
8560
- // Get the hash
8561
- const digest = digestOfTransactionsAndNonce(nonce, normalisedMetaTransactions);
8562
- const completePayload = ethers.ethers.utils.solidityPack(['string', 'uint256', 'address', 'bytes32'], [ETH_SIGN_PREFIX, chainId, walletAddress, digest]);
8563
- const hash = ethers.ethers.utils.keccak256(completePayload);
8564
- // Sign the digest
8565
- const hashArray = ethers.ethers.utils.arrayify(hash);
8566
- const ethsigNoType = await signer.signMessage(hashArray);
8567
- const signedDigest = `${ethsigNoType}${ETH_SIGN_FLAG}`;
8568
- // Add metadata
8569
- const encodedSignature = config$1.encodeSignature({
8570
- threshold: SIGNATURE_THRESHOLD,
8571
- signers: [
8572
- {
8573
- weight: SIGNATURE_WEIGHT,
8574
- signature: signedDigest,
8575
- },
8576
- ],
8577
- });
8578
- // Encode the transaction;
8579
- const walletInterface = new ethers.ethers.utils.Interface(abi.walletContracts.mainModule.abi);
8580
- return walletInterface.encodeFunctionData(walletInterface.getFunction('execute'), [
8581
- normalisedMetaTransactions,
8582
- nonce,
8583
- encodedSignature,
8584
- ]);
8585
- };
8586
- const chainIdNumber = (chainId) => {
8587
- const caip2Components = chainId.split(':');
8588
- if (caip2Components.length !== 2) {
8589
- throw new Error('Invalid configuration, chain ID is not in CAIP-2 format');
8590
- }
8591
- return ethers.BigNumber.from(caip2Components[1]);
8592
- };
8593
-
8594
8569
  const MAX_TRANSACTION_HASH_RETRIEVAL_RETRIES = 30;
8595
8570
  const TRANSACTION_HASH_RETRIEVAL_WAIT = 1000;
8596
- const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, config, user, }) => guardianClient
8571
+ const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, user, }) => guardianClient
8597
8572
  .withConfirmationScreen({ width: 480, height: 520 })(async () => {
8598
8573
  const transactionRequest = params[0];
8599
8574
  if (!transactionRequest.to) {
8600
8575
  throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'eth_sendTransaction requires a "to" field');
8601
8576
  }
8602
- const chainId = chainIdNumber(config.zkEvmChainId);
8577
+ const { chainId } = await jsonRpcProvider.ready;
8578
+ const chainIdBigNumber = ethers.BigNumber.from(chainId);
8603
8579
  const magicWeb3Provider = new providers.Web3Provider(magicProvider);
8604
8580
  const signer = magicWeb3Provider.getSigner();
8605
8581
  const nonce = await getNonce(jsonRpcProvider, user.zkEvm.ethAddress);
@@ -8614,7 +8590,7 @@ const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient
8614
8590
  // accurate estimation of a transaction gas cost is only possible if the smart
8615
8591
  // wallet contract can actually execute it (in a simulated environment) - and
8616
8592
  // it can only execute signed transactions.
8617
- const signedTransaction = await getSignedMetaTransactions([metaTransaction], nonce, chainId, user.zkEvm.ethAddress, signer);
8593
+ const signedTransaction = await getSignedMetaTransactions([metaTransaction], nonce, chainIdBigNumber, user.zkEvm.ethAddress, signer);
8618
8594
  // TODO: ID-698 Add support for non-native gas payments (e.g ERC20, feeTransaction initialisation must change)
8619
8595
  // NOTE: "Fee Options" represent the multiple ways we could pay for the gas
8620
8596
  // used in this transaction. Each fee option has a "recipientAddress" we
@@ -8633,15 +8609,14 @@ const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient
8633
8609
  revertOnError: true,
8634
8610
  };
8635
8611
  await guardianClient.validateEVMTransaction({
8636
- chainId: config.zkEvmChainId,
8612
+ chainId: getEip155ChainId(chainId),
8637
8613
  nonce: convertBigNumberishToString(nonce),
8638
8614
  user,
8639
8615
  metaTransactions: [metaTransaction, feeMetaTransaction],
8640
8616
  });
8641
8617
  // NOTE: We sign again because we now are adding the fee transaction, so the
8642
8618
  // whole payload is different and needs a new signature.
8643
- const signedTransactions = await getSignedMetaTransactions([metaTransaction, feeMetaTransaction], nonce, chainId, user.zkEvm.ethAddress, signer);
8644
- // TODO: ID-697 Evaluate transactions through Guardian
8619
+ const signedTransactions = await getSignedMetaTransactions([metaTransaction, feeMetaTransaction], nonce, chainIdBigNumber, user.zkEvm.ethAddress, signer);
8645
8620
  const relayerId = await relayerClient.ethSendTransaction(user.zkEvm.ethAddress, signedTransactions);
8646
8621
  const retrieveRelayerTransaction = async () => {
8647
8622
  const tx = await relayerClient.imGetTransactionByHash(relayerId);
@@ -8681,7 +8656,8 @@ class ZkEvmProvider {
8681
8656
  relayerClient;
8682
8657
  magicProvider; // Used for signing
8683
8658
  user;
8684
- constructor({ authManager, magicAdapter, config, confirmationScreen, multiRollupApiClients, }) {
8659
+ isPassport = true;
8660
+ constructor({ authManager, magicAdapter, config, confirmationScreen, multiRollupApiClients, passportEventEmitter, }) {
8685
8661
  this.authManager = authManager;
8686
8662
  this.magicAdapter = magicAdapter;
8687
8663
  this.config = config;
@@ -8692,8 +8668,18 @@ class ZkEvmProvider {
8692
8668
  this.jsonRpcProvider = new providers.JsonRpcProvider(this.config.zkEvmRpcUrl);
8693
8669
  this.multiRollupApiClients = multiRollupApiClients;
8694
8670
  this.eventEmitter = new TypedEventEmitter();
8671
+ passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.handleLogout);
8695
8672
  }
8696
- isPassport = true;
8673
+ handleLogout = () => {
8674
+ const shouldEmitAccountsChanged = this.isLoggedIn();
8675
+ this.magicProvider = undefined;
8676
+ this.user = undefined;
8677
+ this.relayerClient = undefined;
8678
+ this.guardianClient = undefined;
8679
+ if (shouldEmitAccountsChanged) {
8680
+ this.eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, []);
8681
+ }
8682
+ };
8697
8683
  isLoggedIn() {
8698
8684
  return this.magicProvider !== undefined
8699
8685
  && this.user !== undefined
@@ -8716,13 +8702,19 @@ class ZkEvmProvider {
8716
8702
  this.magicProvider = magicProvider;
8717
8703
  this.relayerClient = new RelayerClient({
8718
8704
  config: this.config,
8705
+ jsonRpcProvider: this.jsonRpcProvider,
8719
8706
  user: this.user,
8720
8707
  });
8721
8708
  this.guardianClient = new GuardianClient({
8722
- imxPublicApiDomain: this.config.imxPublicApiDomain,
8723
8709
  accessToken: this.user.accessToken,
8724
8710
  confirmationScreen: this.confirmationScreen,
8725
8711
  imxEtherAddress: this.user.zkEvm.ethAddress,
8712
+ config: new PassportConfiguration({
8713
+ baseConfig: {},
8714
+ clientId: 'client123',
8715
+ logoutRedirectUri: 'http://localhost:3000/logout',
8716
+ redirectUri: 'http://localhost:3000/redirect',
8717
+ }),
8726
8718
  });
8727
8719
  this.eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, [this.user.zkEvm.ethAddress]);
8728
8720
  return [this.user.zkEvm.ethAddress];
@@ -8736,7 +8728,6 @@ class ZkEvmProvider {
8736
8728
  magicProvider: this.magicProvider,
8737
8729
  guardianClient: this.guardianClient,
8738
8730
  jsonRpcProvider: this.jsonRpcProvider,
8739
- config: this.config,
8740
8731
  relayerClient: this.relayerClient,
8741
8732
  user: this.user,
8742
8733
  });
@@ -8868,8 +8859,9 @@ class Passport {
8868
8859
  confirmationScreen;
8869
8860
  immutableXClient;
8870
8861
  magicAdapter;
8871
- passportImxProviderFactory;
8872
8862
  multiRollupApiClients;
8863
+ passportImxProviderFactory;
8864
+ passportEventEmitter;
8873
8865
  constructor(passportModuleConfiguration) {
8874
8866
  this.config = new PassportConfiguration(passportModuleConfiguration);
8875
8867
  this.authManager = new AuthManager(this.config);
@@ -8880,12 +8872,14 @@ class Passport {
8880
8872
  baseConfig: passportModuleConfiguration.baseConfig,
8881
8873
  });
8882
8874
  this.multiRollupApiClients = new MultiRollupApiClients(this.config.multiRollupConfig);
8875
+ this.passportEventEmitter = new TypedEventEmitter();
8883
8876
  this.passportImxProviderFactory = new PassportImxProviderFactory({
8884
8877
  authManager: this.authManager,
8885
8878
  config: this.config,
8886
8879
  confirmationScreen: this.confirmationScreen,
8887
8880
  immutableXClient: this.immutableXClient,
8888
8881
  magicAdapter: this.magicAdapter,
8882
+ passportEventEmitter: this.passportEventEmitter,
8889
8883
  });
8890
8884
  }
8891
8885
  async connectImxSilent() {
@@ -8920,6 +8914,7 @@ class Passport {
8920
8914
  throw new Error('EVM is not supported on production network');
8921
8915
  }
8922
8916
  return new ZkEvmProvider({
8917
+ passportEventEmitter: this.passportEventEmitter,
8923
8918
  authManager: this.authManager,
8924
8919
  magicAdapter: this.magicAdapter,
8925
8920
  config: this.config,
@@ -8931,7 +8926,10 @@ class Passport {
8931
8926
  return this.authManager.loginCallback();
8932
8927
  }
8933
8928
  async logout() {
8934
- return this.authManager.logout();
8929
+ await this.authManager.logout();
8930
+ // Code after this point is only executed if the logout mode is silent
8931
+ await this.magicAdapter.logout();
8932
+ this.passportEventEmitter.emit(PassportEvents.LOGGED_OUT);
8935
8933
  }
8936
8934
  /**
8937
8935
  * This method should only be called from the logout redirect uri
@@ -9494,6 +9492,9 @@ var Fee;
9494
9492
  (function (Fee) {
9495
9493
  (function (fee_type) {
9496
9494
  fee_type["ROYALTY"] = "ROYALTY";
9495
+ fee_type["MAKER_MARKETPLACE"] = "MAKER_MARKETPLACE";
9496
+ fee_type["TAKER_MARKETPLACE"] = "TAKER_MARKETPLACE";
9497
+ fee_type["PROTOCOL"] = "PROTOCOL";
9497
9498
  })(Fee.fee_type || (Fee.fee_type = {}));
9498
9499
  })(Fee || (Fee = {}));
9499
9500
 
@@ -9647,8 +9648,7 @@ function mapImmutableOrderToSeaportOrderComponents(order, counter, zoneAddress)
9647
9648
  }
9648
9649
  });
9649
9650
  const fees = order.fees.map((fee) => ({
9650
- startAmount: fee.amount,
9651
- endAmount: fee.amount,
9651
+ amount: fee.amount,
9652
9652
  itemType: order.buy[0].item_type === 'ERC20' ? ItemType.ERC20 : ItemType.NATIVE,
9653
9653
  recipient: fee.recipient,
9654
9654
  token: order.buy[0].item_type === 'ERC20'
@@ -9657,27 +9657,31 @@ function mapImmutableOrderToSeaportOrderComponents(order, counter, zoneAddress)
9657
9657
  identifierOrCriteria: '0',
9658
9658
  }));
9659
9659
  return {
9660
- conduitKey: ethers.constants.HashZero,
9661
- consideration: [...considerationItems, ...fees],
9662
- offer: order.sell.map((sellItem) => {
9663
- const erc721Item = sellItem;
9664
- return {
9665
- startAmount: '1',
9666
- endAmount: '1',
9667
- itemType: ItemType.ERC721,
9668
- token: erc721Item.contract_address,
9669
- identifierOrCriteria: erc721Item.token_id,
9670
- };
9671
- }),
9672
- counter,
9673
- endTime: Math.round(new Date(order.end_time).getTime() / 1000).toString(),
9674
- startTime: Math.round(new Date(order.start_time).getTime() / 1000).toString(),
9675
- salt: order.salt,
9676
- offerer: order.account_address,
9677
- zone: zoneAddress,
9678
- totalOriginalConsiderationItems: 2,
9679
- orderType: OrderType.FULL_RESTRICTED,
9680
- zoneHash: ethers.constants.HashZero,
9660
+ orderComponents: {
9661
+ conduitKey: ethers.constants.HashZero,
9662
+ consideration: [...considerationItems],
9663
+ offer: order.sell.map((sellItem) => {
9664
+ const erc721Item = sellItem;
9665
+ return {
9666
+ startAmount: '1',
9667
+ endAmount: '1',
9668
+ itemType: ItemType.ERC721,
9669
+ token: erc721Item.contract_address,
9670
+ identifierOrCriteria: erc721Item.token_id,
9671
+ };
9672
+ }),
9673
+ counter,
9674
+ endTime: Math.round(new Date(order.end_time).getTime() / 1000).toString(),
9675
+ startTime: Math.round(new Date(order.start_time).getTime() / 1000).toString(),
9676
+ salt: order.salt,
9677
+ offerer: order.account_address,
9678
+ zone: zoneAddress,
9679
+ // this should be the fee exclusive number of items the user signed for
9680
+ totalOriginalConsiderationItems: considerationItems.length,
9681
+ orderType: OrderType.FULL_RESTRICTED,
9682
+ zoneHash: ethers.constants.HashZero,
9683
+ },
9684
+ tips: fees,
9681
9685
  };
9682
9686
  }
9683
9687
 
@@ -9692,11 +9696,10 @@ class Seaport {
9692
9696
  this.seaportContractAddress = seaportContractAddress;
9693
9697
  this.zoneContractAddress = zoneContractAddress;
9694
9698
  }
9695
- async prepareSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry) {
9696
- const { actions: seaportActions } = await this.createSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry);
9699
+ async prepareSeaportOrder(offerer, listingItem, considerationItem, orderStart, orderExpiry) {
9700
+ const { actions: seaportActions } = await this.createSeaportOrder(offerer, listingItem, considerationItem, orderStart, orderExpiry);
9697
9701
  const listingActions = [];
9698
- const approvalAction = seaportActions
9699
- .find((action) => action.type === 'approval');
9702
+ const approvalAction = seaportActions.find((action) => action.type === 'approval');
9700
9703
  if (approvalAction) {
9701
9704
  listingActions.push({
9702
9705
  type: ActionType.TRANSACTION,
@@ -9704,8 +9707,7 @@ class Seaport {
9704
9707
  buildTransaction: prepareTransaction(approvalAction.transactionMethods),
9705
9708
  });
9706
9709
  }
9707
- const createAction = seaportActions
9708
- .find((action) => action.type === 'create');
9710
+ const createAction = seaportActions.find((action) => action.type === 'create');
9709
9711
  if (!createAction) {
9710
9712
  throw new Error('No create order action found');
9711
9713
  }
@@ -9723,21 +9725,23 @@ class Seaport {
9723
9725
  };
9724
9726
  }
9725
9727
  async fulfillOrder(order, account, extraData) {
9726
- const orderComponents = await this.mapImmutableOrderToSeaportOrderComponents(order);
9728
+ const { orderComponents, tips } = this.mapImmutableOrderToSeaportOrderComponents(order);
9727
9729
  const seaportLib = this.getSeaportLib(order);
9728
9730
  const { actions: seaportActions } = await seaportLib.fulfillOrders({
9729
9731
  accountAddress: account,
9730
- fulfillOrderDetails: [{
9732
+ fulfillOrderDetails: [
9733
+ {
9731
9734
  order: {
9732
9735
  parameters: orderComponents,
9733
9736
  signature: order.signature,
9734
9737
  },
9735
9738
  extraData,
9736
- }],
9739
+ tips,
9740
+ },
9741
+ ],
9737
9742
  });
9738
9743
  const fulfillmentActions = [];
9739
- const approvalAction = seaportActions
9740
- .find((action) => action.type === 'approval');
9744
+ const approvalAction = seaportActions.find((action) => action.type === 'approval');
9741
9745
  if (approvalAction) {
9742
9746
  fulfillmentActions.push({
9743
9747
  type: ActionType.TRANSACTION,
@@ -9745,8 +9749,7 @@ class Seaport {
9745
9749
  purpose: TransactionPurpose.APPROVAL,
9746
9750
  });
9747
9751
  }
9748
- const fulfilOrderAction = seaportActions
9749
- .find((action) => action.type === 'exchange');
9752
+ const fulfilOrderAction = seaportActions.find((action) => action.type === 'exchange');
9750
9753
  if (!fulfilOrderAction) {
9751
9754
  throw new Error('No exchange action found');
9752
9755
  }
@@ -9758,7 +9761,7 @@ class Seaport {
9758
9761
  return { actions: fulfillmentActions };
9759
9762
  }
9760
9763
  async cancelOrder(order, account) {
9761
- const orderComponents = await this.mapImmutableOrderToSeaportOrderComponents(order);
9764
+ const { orderComponents } = this.mapImmutableOrderToSeaportOrderComponents(order);
9762
9765
  const seaportLib = this.getSeaportLib(order);
9763
9766
  const cancellationTransaction = await seaportLib.cancelOrders([orderComponents], account);
9764
9767
  return prepareTransaction(cancellationTransaction)();
@@ -9767,7 +9770,7 @@ class Seaport {
9767
9770
  const orderCounter = order.protocol_data.counter;
9768
9771
  return mapImmutableOrderToSeaportOrderComponents(order, orderCounter, this.zoneContractAddress);
9769
9772
  }
9770
- createSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry) {
9773
+ createSeaportOrder(offerer, listingItem, considerationItem, orderStart, orderExpiry) {
9771
9774
  const seaportLib = this.getSeaportLib();
9772
9775
  return seaportLib.createOrder({
9773
9776
  allowPartialFills: false,
@@ -9780,15 +9783,12 @@ class Seaport {
9780
9783
  ],
9781
9784
  consideration: [
9782
9785
  {
9783
- token: considerationItem.type === 'ERC20' ? considerationItem.contractAddress : undefined,
9786
+ token: considerationItem.type === 'ERC20'
9787
+ ? considerationItem.contractAddress
9788
+ : undefined,
9784
9789
  amount: considerationItem.amount,
9785
9790
  recipient: offerer,
9786
9791
  },
9787
- {
9788
- token: considerationItem.type === 'ERC20' ? considerationItem.contractAddress : undefined,
9789
- amount: royaltyInfo.amountRequired,
9790
- recipient: royaltyInfo.recipient,
9791
- },
9792
9792
  ],
9793
9793
  startTime: (orderStart.getTime() / 1000).toFixed(0),
9794
9794
  endTime: (orderExpiry.getTime() / 1000).toFixed(0),
@@ -9847,7 +9847,7 @@ class ImmutableApiClient {
9847
9847
  ...listOrderParams,
9848
9848
  });
9849
9849
  }
9850
- async createListing({ orderHash, orderComponents, orderSignature, }) {
9850
+ async createListing({ orderHash, orderComponents, orderSignature, makerFee, }) {
9851
9851
  if (orderComponents.offer.length !== 1) {
9852
9852
  throw new Error('Only one item can be listed at a time');
9853
9853
  }
@@ -9876,15 +9876,7 @@ class ImmutableApiClient {
9876
9876
  contract_address: orderComponents.consideration[0].token,
9877
9877
  },
9878
9878
  ],
9879
- fees: orderComponents.consideration.length > 1
9880
- ? [
9881
- {
9882
- amount: orderComponents.consideration[1].startAmount,
9883
- recipient: orderComponents.consideration[1].recipient,
9884
- fee_type: Fee.fee_type.ROYALTY,
9885
- },
9886
- ]
9887
- : [],
9879
+ fees: makerFee ? [makerFee] : [],
9888
9880
  end_time: new Date(parseInt(`${orderComponents.endTime.toString()}000`, 10)).toISOString(),
9889
9881
  protocol_data: {
9890
9882
  order_type: CreateOrderProtocolData.order_type.FULL_RESTRICTED,
@@ -9951,945 +9943,23 @@ function getOrderbookConfig(environment) {
9951
9943
  }
9952
9944
  }
9953
9945
 
9954
- class ERC721 {
9955
- erc721;
9956
- constructor(erc721) {
9957
- this.erc721 = erc721;
9946
+ class SeaportLibFactory {
9947
+ defaultSeaportContractAddress;
9948
+ provider;
9949
+ constructor(defaultSeaportContractAddress, provider) {
9950
+ this.defaultSeaportContractAddress = defaultSeaportContractAddress;
9951
+ this.provider = provider;
9958
9952
  }
9959
- async royaltyInfo(tokenId, salePrice) {
9960
- const [recipient, royaltyRequired] = await this.erc721.royaltyInfo(tokenId, salePrice);
9961
- return { recipient, amountRequired: royaltyRequired.toString() };
9962
- }
9963
- }
9964
-
9965
- /* Autogenerated file. Do not edit manually. */
9966
- /* tslint:disable */
9967
- /* eslint-disable */
9968
- const _abi$5 = [
9969
- {
9970
- inputs: [
9971
- {
9972
- internalType: "address",
9973
- name: "owner_",
9974
- type: "address",
9975
- },
9976
- {
9977
- internalType: "string",
9978
- name: "name_",
9979
- type: "string",
9980
- },
9981
- {
9982
- internalType: "string",
9983
- name: "symbol_",
9984
- type: "string",
9985
- },
9986
- {
9987
- internalType: "string",
9988
- name: "baseURI_",
9989
- type: "string",
9990
- },
9991
- {
9992
- internalType: "string",
9993
- name: "contractURI_",
9994
- type: "string",
9995
- },
9996
- {
9997
- internalType: "address",
9998
- name: "_receiver",
9999
- type: "address",
10000
- },
10001
- {
10002
- internalType: "uint96",
10003
- name: "_feeNumerator",
10004
- type: "uint96",
10005
- },
10006
- ],
10007
- stateMutability: "nonpayable",
10008
- type: "constructor",
10009
- },
10010
- {
10011
- inputs: [
10012
- {
10013
- internalType: "address",
10014
- name: "target",
10015
- type: "address",
10016
- },
10017
- ],
10018
- name: "ApproveTargetNotInAllowlist",
10019
- type: "error",
10020
- },
10021
- {
10022
- inputs: [
10023
- {
10024
- internalType: "address",
10025
- name: "caller",
10026
- type: "address",
10027
- },
10028
- ],
10029
- name: "CallerNotInAllowlist",
10030
- type: "error",
10031
- },
10032
- {
10033
- anonymous: false,
10034
- inputs: [
10035
- {
10036
- indexed: true,
10037
- internalType: "address",
10038
- name: "owner",
10039
- type: "address",
10040
- },
10041
- {
10042
- indexed: true,
10043
- internalType: "address",
10044
- name: "approved",
10045
- type: "address",
10046
- },
10047
- {
10048
- indexed: true,
10049
- internalType: "uint256",
10050
- name: "tokenId",
10051
- type: "uint256",
10052
- },
10053
- ],
10054
- name: "Approval",
10055
- type: "event",
10056
- },
10057
- {
10058
- anonymous: false,
10059
- inputs: [
10060
- {
10061
- indexed: true,
10062
- internalType: "address",
10063
- name: "owner",
10064
- type: "address",
10065
- },
10066
- {
10067
- indexed: true,
10068
- internalType: "address",
10069
- name: "operator",
10070
- type: "address",
10071
- },
10072
- {
10073
- indexed: false,
10074
- internalType: "bool",
10075
- name: "approved",
10076
- type: "bool",
10077
- },
10078
- ],
10079
- name: "ApprovalForAll",
10080
- type: "event",
10081
- },
10082
- {
10083
- anonymous: false,
10084
- inputs: [
10085
- {
10086
- indexed: true,
10087
- internalType: "bytes32",
10088
- name: "role",
10089
- type: "bytes32",
10090
- },
10091
- {
10092
- indexed: true,
10093
- internalType: "bytes32",
10094
- name: "previousAdminRole",
10095
- type: "bytes32",
10096
- },
10097
- {
10098
- indexed: true,
10099
- internalType: "bytes32",
10100
- name: "newAdminRole",
10101
- type: "bytes32",
10102
- },
10103
- ],
10104
- name: "RoleAdminChanged",
10105
- type: "event",
10106
- },
10107
- {
10108
- anonymous: false,
10109
- inputs: [
10110
- {
10111
- indexed: true,
10112
- internalType: "bytes32",
10113
- name: "role",
10114
- type: "bytes32",
10115
- },
10116
- {
10117
- indexed: true,
10118
- internalType: "address",
10119
- name: "account",
10120
- type: "address",
10121
- },
10122
- {
10123
- indexed: true,
10124
- internalType: "address",
10125
- name: "sender",
10126
- type: "address",
10127
- },
10128
- ],
10129
- name: "RoleGranted",
10130
- type: "event",
10131
- },
10132
- {
10133
- anonymous: false,
10134
- inputs: [
10135
- {
10136
- indexed: true,
10137
- internalType: "bytes32",
10138
- name: "role",
10139
- type: "bytes32",
10140
- },
10141
- {
10142
- indexed: true,
10143
- internalType: "address",
10144
- name: "account",
10145
- type: "address",
10146
- },
10147
- {
10148
- indexed: true,
10149
- internalType: "address",
10150
- name: "sender",
10151
- type: "address",
10152
- },
10153
- ],
10154
- name: "RoleRevoked",
10155
- type: "event",
10156
- },
10157
- {
10158
- anonymous: false,
10159
- inputs: [
10160
- {
10161
- indexed: false,
10162
- internalType: "address",
10163
- name: "oldRegistry",
10164
- type: "address",
10165
- },
10166
- {
10167
- indexed: false,
10168
- internalType: "address",
10169
- name: "newRegistry",
10170
- type: "address",
10171
- },
10172
- ],
10173
- name: "RoyaltytAllowlistRegistryUpdated",
10174
- type: "event",
10175
- },
10176
- {
10177
- anonymous: false,
10178
- inputs: [
10179
- {
10180
- indexed: true,
10181
- internalType: "address",
10182
- name: "from",
10183
- type: "address",
10184
- },
10185
- {
10186
- indexed: true,
10187
- internalType: "address",
10188
- name: "to",
10189
- type: "address",
10190
- },
10191
- {
10192
- indexed: true,
10193
- internalType: "uint256",
10194
- name: "tokenId",
10195
- type: "uint256",
10196
- },
10197
- ],
10198
- name: "Transfer",
10199
- type: "event",
10200
- },
10201
- {
10202
- inputs: [],
10203
- name: "DEFAULT_ADMIN_ROLE",
10204
- outputs: [
10205
- {
10206
- internalType: "bytes32",
10207
- name: "",
10208
- type: "bytes32",
10209
- },
10210
- ],
10211
- stateMutability: "view",
10212
- type: "function",
10213
- },
10214
- {
10215
- inputs: [],
10216
- name: "MINTER_ROLE",
10217
- outputs: [
10218
- {
10219
- internalType: "bytes32",
10220
- name: "",
10221
- type: "bytes32",
10222
- },
10223
- ],
10224
- stateMutability: "view",
10225
- type: "function",
10226
- },
10227
- {
10228
- inputs: [
10229
- {
10230
- internalType: "address",
10231
- name: "to",
10232
- type: "address",
10233
- },
10234
- {
10235
- internalType: "uint256",
10236
- name: "tokenId",
10237
- type: "uint256",
10238
- },
10239
- ],
10240
- name: "approve",
10241
- outputs: [],
10242
- stateMutability: "nonpayable",
10243
- type: "function",
10244
- },
10245
- {
10246
- inputs: [
10247
- {
10248
- internalType: "address",
10249
- name: "owner",
10250
- type: "address",
10251
- },
10252
- ],
10253
- name: "balanceOf",
10254
- outputs: [
10255
- {
10256
- internalType: "uint256",
10257
- name: "",
10258
- type: "uint256",
10259
- },
10260
- ],
10261
- stateMutability: "view",
10262
- type: "function",
10263
- },
10264
- {
10265
- inputs: [],
10266
- name: "baseURI",
10267
- outputs: [
10268
- {
10269
- internalType: "string",
10270
- name: "",
10271
- type: "string",
10272
- },
10273
- ],
10274
- stateMutability: "view",
10275
- type: "function",
10276
- },
10277
- {
10278
- inputs: [
10279
- {
10280
- internalType: "uint256",
10281
- name: "tokenId",
10282
- type: "uint256",
10283
- },
10284
- ],
10285
- name: "burn",
10286
- outputs: [],
10287
- stateMutability: "nonpayable",
10288
- type: "function",
10289
- },
10290
- {
10291
- inputs: [],
10292
- name: "contractURI",
10293
- outputs: [
10294
- {
10295
- internalType: "string",
10296
- name: "",
10297
- type: "string",
10298
- },
10299
- ],
10300
- stateMutability: "view",
10301
- type: "function",
10302
- },
10303
- {
10304
- inputs: [],
10305
- name: "getAdmins",
10306
- outputs: [
10307
- {
10308
- internalType: "address[]",
10309
- name: "",
10310
- type: "address[]",
10311
- },
10312
- ],
10313
- stateMutability: "view",
10314
- type: "function",
10315
- },
10316
- {
10317
- inputs: [
10318
- {
10319
- internalType: "uint256",
10320
- name: "tokenId",
10321
- type: "uint256",
10322
- },
10323
- ],
10324
- name: "getApproved",
10325
- outputs: [
10326
- {
10327
- internalType: "address",
10328
- name: "",
10329
- type: "address",
10330
- },
10331
- ],
10332
- stateMutability: "view",
10333
- type: "function",
10334
- },
10335
- {
10336
- inputs: [
10337
- {
10338
- internalType: "bytes32",
10339
- name: "role",
10340
- type: "bytes32",
10341
- },
10342
- ],
10343
- name: "getRoleAdmin",
10344
- outputs: [
10345
- {
10346
- internalType: "bytes32",
10347
- name: "",
10348
- type: "bytes32",
10349
- },
10350
- ],
10351
- stateMutability: "view",
10352
- type: "function",
10353
- },
10354
- {
10355
- inputs: [
10356
- {
10357
- internalType: "bytes32",
10358
- name: "role",
10359
- type: "bytes32",
10360
- },
10361
- {
10362
- internalType: "uint256",
10363
- name: "index",
10364
- type: "uint256",
10365
- },
10366
- ],
10367
- name: "getRoleMember",
10368
- outputs: [
10369
- {
10370
- internalType: "address",
10371
- name: "",
10372
- type: "address",
10373
- },
10374
- ],
10375
- stateMutability: "view",
10376
- type: "function",
10377
- },
10378
- {
10379
- inputs: [
10380
- {
10381
- internalType: "bytes32",
10382
- name: "role",
10383
- type: "bytes32",
10384
- },
10385
- ],
10386
- name: "getRoleMemberCount",
10387
- outputs: [
10388
- {
10389
- internalType: "uint256",
10390
- name: "",
10391
- type: "uint256",
10392
- },
10393
- ],
10394
- stateMutability: "view",
10395
- type: "function",
10396
- },
10397
- {
10398
- inputs: [
10399
- {
10400
- internalType: "address",
10401
- name: "user",
10402
- type: "address",
10403
- },
10404
- ],
10405
- name: "grantMinterRole",
10406
- outputs: [],
10407
- stateMutability: "nonpayable",
10408
- type: "function",
10409
- },
10410
- {
10411
- inputs: [
10412
- {
10413
- internalType: "bytes32",
10414
- name: "role",
10415
- type: "bytes32",
10416
- },
10417
- {
10418
- internalType: "address",
10419
- name: "account",
10420
- type: "address",
10421
- },
10422
- ],
10423
- name: "grantRole",
10424
- outputs: [],
10425
- stateMutability: "nonpayable",
10426
- type: "function",
10427
- },
10428
- {
10429
- inputs: [
10430
- {
10431
- internalType: "bytes32",
10432
- name: "role",
10433
- type: "bytes32",
10434
- },
10435
- {
10436
- internalType: "address",
10437
- name: "account",
10438
- type: "address",
10439
- },
10440
- ],
10441
- name: "hasRole",
10442
- outputs: [
10443
- {
10444
- internalType: "bool",
10445
- name: "",
10446
- type: "bool",
10447
- },
10448
- ],
10449
- stateMutability: "view",
10450
- type: "function",
10451
- },
10452
- {
10453
- inputs: [
10454
- {
10455
- internalType: "address",
10456
- name: "owner",
10457
- type: "address",
10458
- },
10459
- {
10460
- internalType: "address",
10461
- name: "operator",
10462
- type: "address",
10463
- },
10464
- ],
10465
- name: "isApprovedForAll",
10466
- outputs: [
10467
- {
10468
- internalType: "bool",
10469
- name: "",
10470
- type: "bool",
10471
- },
10472
- ],
10473
- stateMutability: "view",
10474
- type: "function",
10475
- },
10476
- {
10477
- inputs: [
10478
- {
10479
- internalType: "address",
10480
- name: "to",
10481
- type: "address",
10482
- },
10483
- {
10484
- internalType: "uint256",
10485
- name: "amount",
10486
- type: "uint256",
10487
- },
10488
- ],
10489
- name: "mint",
10490
- outputs: [],
10491
- stateMutability: "nonpayable",
10492
- type: "function",
10493
- },
10494
- {
10495
- inputs: [],
10496
- name: "name",
10497
- outputs: [
10498
- {
10499
- internalType: "string",
10500
- name: "",
10501
- type: "string",
10502
- },
10503
- ],
10504
- stateMutability: "view",
10505
- type: "function",
10506
- },
10507
- {
10508
- inputs: [
10509
- {
10510
- internalType: "uint256",
10511
- name: "tokenId",
10512
- type: "uint256",
10513
- },
10514
- ],
10515
- name: "ownerOf",
10516
- outputs: [
10517
- {
10518
- internalType: "address",
10519
- name: "",
10520
- type: "address",
10521
- },
10522
- ],
10523
- stateMutability: "view",
10524
- type: "function",
10525
- },
10526
- {
10527
- inputs: [
10528
- {
10529
- internalType: "bytes32",
10530
- name: "role",
10531
- type: "bytes32",
10532
- },
10533
- {
10534
- internalType: "address",
10535
- name: "account",
10536
- type: "address",
10537
- },
10538
- ],
10539
- name: "renounceRole",
10540
- outputs: [],
10541
- stateMutability: "nonpayable",
10542
- type: "function",
10543
- },
10544
- {
10545
- inputs: [
10546
- {
10547
- internalType: "address",
10548
- name: "user",
10549
- type: "address",
10550
- },
10551
- ],
10552
- name: "revokeMinterRole",
10553
- outputs: [],
10554
- stateMutability: "nonpayable",
10555
- type: "function",
10556
- },
10557
- {
10558
- inputs: [
10559
- {
10560
- internalType: "bytes32",
10561
- name: "role",
10562
- type: "bytes32",
10563
- },
10564
- {
10565
- internalType: "address",
10566
- name: "account",
10567
- type: "address",
10568
- },
10569
- ],
10570
- name: "revokeRole",
10571
- outputs: [],
10572
- stateMutability: "nonpayable",
10573
- type: "function",
10574
- },
10575
- {
10576
- inputs: [],
10577
- name: "royaltyAllowlist",
10578
- outputs: [
10579
- {
10580
- internalType: "contract IRoyaltyAllowlist",
10581
- name: "",
10582
- type: "address",
10583
- },
10584
- ],
10585
- stateMutability: "view",
10586
- type: "function",
10587
- },
10588
- {
10589
- inputs: [
10590
- {
10591
- internalType: "uint256",
10592
- name: "_tokenId",
10593
- type: "uint256",
10594
- },
10595
- {
10596
- internalType: "uint256",
10597
- name: "_salePrice",
10598
- type: "uint256",
10599
- },
10600
- ],
10601
- name: "royaltyInfo",
10602
- outputs: [
10603
- {
10604
- internalType: "address",
10605
- name: "",
10606
- type: "address",
10607
- },
10608
- {
10609
- internalType: "uint256",
10610
- name: "",
10611
- type: "uint256",
10612
- },
10613
- ],
10614
- stateMutability: "view",
10615
- type: "function",
10616
- },
10617
- {
10618
- inputs: [
10619
- {
10620
- internalType: "address",
10621
- name: "from",
10622
- type: "address",
10623
- },
10624
- {
10625
- internalType: "address",
10626
- name: "to",
10627
- type: "address",
10628
- },
10629
- {
10630
- internalType: "uint256",
10631
- name: "tokenId",
10632
- type: "uint256",
10633
- },
10634
- ],
10635
- name: "safeTransferFrom",
10636
- outputs: [],
10637
- stateMutability: "nonpayable",
10638
- type: "function",
10639
- },
10640
- {
10641
- inputs: [
10642
- {
10643
- internalType: "address",
10644
- name: "from",
10645
- type: "address",
10646
- },
10647
- {
10648
- internalType: "address",
10649
- name: "to",
10650
- type: "address",
10651
- },
10652
- {
10653
- internalType: "uint256",
10654
- name: "tokenId",
10655
- type: "uint256",
10656
- },
10657
- {
10658
- internalType: "bytes",
10659
- name: "data",
10660
- type: "bytes",
10661
- },
10662
- ],
10663
- name: "safeTransferFrom",
10664
- outputs: [],
10665
- stateMutability: "nonpayable",
10666
- type: "function",
10667
- },
10668
- {
10669
- inputs: [
10670
- {
10671
- internalType: "address",
10672
- name: "operator",
10673
- type: "address",
10674
- },
10675
- {
10676
- internalType: "bool",
10677
- name: "approved",
10678
- type: "bool",
10679
- },
10680
- ],
10681
- name: "setApprovalForAll",
10682
- outputs: [],
10683
- stateMutability: "nonpayable",
10684
- type: "function",
10685
- },
10686
- {
10687
- inputs: [
10688
- {
10689
- internalType: "string",
10690
- name: "baseURI_",
10691
- type: "string",
10692
- },
10693
- ],
10694
- name: "setBaseURI",
10695
- outputs: [],
10696
- stateMutability: "nonpayable",
10697
- type: "function",
10698
- },
10699
- {
10700
- inputs: [
10701
- {
10702
- internalType: "string",
10703
- name: "_contractURI",
10704
- type: "string",
10705
- },
10706
- ],
10707
- name: "setContractURI",
10708
- outputs: [],
10709
- stateMutability: "nonpayable",
10710
- type: "function",
10711
- },
10712
- {
10713
- inputs: [
10714
- {
10715
- internalType: "address",
10716
- name: "_royaltyAllowlist",
10717
- type: "address",
10718
- },
10719
- ],
10720
- name: "setRoyaltyAllowlistRegistry",
10721
- outputs: [],
10722
- stateMutability: "nonpayable",
10723
- type: "function",
10724
- },
10725
- {
10726
- inputs: [
10727
- {
10728
- internalType: "bytes4",
10729
- name: "interfaceId",
10730
- type: "bytes4",
10731
- },
10732
- ],
10733
- name: "supportsInterface",
10734
- outputs: [
10735
- {
10736
- internalType: "bool",
10737
- name: "",
10738
- type: "bool",
10739
- },
10740
- ],
10741
- stateMutability: "view",
10742
- type: "function",
10743
- },
10744
- {
10745
- inputs: [],
10746
- name: "symbol",
10747
- outputs: [
10748
- {
10749
- internalType: "string",
10750
- name: "",
10751
- type: "string",
10752
- },
10753
- ],
10754
- stateMutability: "view",
10755
- type: "function",
10756
- },
10757
- {
10758
- inputs: [
10759
- {
10760
- internalType: "uint256",
10761
- name: "index",
10762
- type: "uint256",
10763
- },
10764
- ],
10765
- name: "tokenByIndex",
10766
- outputs: [
10767
- {
10768
- internalType: "uint256",
10769
- name: "",
10770
- type: "uint256",
10771
- },
10772
- ],
10773
- stateMutability: "view",
10774
- type: "function",
10775
- },
10776
- {
10777
- inputs: [
10778
- {
10779
- internalType: "address",
10780
- name: "owner",
10781
- type: "address",
10782
- },
10783
- {
10784
- internalType: "uint256",
10785
- name: "index",
10786
- type: "uint256",
10787
- },
10788
- ],
10789
- name: "tokenOfOwnerByIndex",
10790
- outputs: [
10791
- {
10792
- internalType: "uint256",
10793
- name: "",
10794
- type: "uint256",
10795
- },
10796
- ],
10797
- stateMutability: "view",
10798
- type: "function",
10799
- },
10800
- {
10801
- inputs: [
10802
- {
10803
- internalType: "uint256",
10804
- name: "tokenId",
10805
- type: "uint256",
10806
- },
10807
- ],
10808
- name: "tokenURI",
10809
- outputs: [
10810
- {
10811
- internalType: "string",
10812
- name: "",
10813
- type: "string",
10814
- },
10815
- ],
10816
- stateMutability: "view",
10817
- type: "function",
10818
- },
10819
- {
10820
- inputs: [],
10821
- name: "totalSupply",
10822
- outputs: [
10823
- {
10824
- internalType: "uint256",
10825
- name: "",
10826
- type: "uint256",
10827
- },
10828
- ],
10829
- stateMutability: "view",
10830
- type: "function",
10831
- },
10832
- {
10833
- inputs: [
10834
- {
10835
- internalType: "address",
10836
- name: "from",
10837
- type: "address",
10838
- },
10839
- {
10840
- internalType: "address",
10841
- name: "to",
10842
- type: "address",
10843
- },
10844
- {
10845
- internalType: "uint256",
10846
- name: "tokenId",
10847
- type: "uint256",
10848
- },
10849
- ],
10850
- name: "transferFrom",
10851
- outputs: [],
10852
- stateMutability: "nonpayable",
10853
- type: "function",
10854
- },
10855
- ];
10856
- class ImmutableERC721Base__factory {
10857
- static abi = _abi$5;
10858
- static createInterface() {
10859
- return new ethers.utils.Interface(_abi$5);
10860
- }
10861
- static connect(address, signerOrProvider) {
10862
- return new ethers.Contract(address, _abi$5, signerOrProvider);
10863
- }
10864
- }
10865
-
10866
- class ERC721Factory {
10867
- erc721;
10868
- constructor(contractAddress, provider) {
10869
- this.erc721 = ImmutableERC721Base__factory.connect(contractAddress, provider);
10870
- }
10871
- create() {
10872
- return new ERC721(this.erc721);
10873
- }
10874
- }
10875
-
10876
- class SeaportLibFactory {
10877
- defaultSeaportContractAddress;
10878
- provider;
10879
- constructor(defaultSeaportContractAddress, provider) {
10880
- this.defaultSeaportContractAddress = defaultSeaportContractAddress;
10881
- this.provider = provider;
10882
- }
10883
- create(orderSeaportVersion, orderSeaportAddress) {
10884
- const seaportVersion = orderSeaportVersion ?? SEAPORT_CONTRACT_VERSION_V1_5;
10885
- const seaportContractAddress = orderSeaportAddress ?? this.defaultSeaportContractAddress;
10886
- return new seaportJs.Seaport(this.provider, {
10887
- seaportVersion,
10888
- balanceAndApprovalChecksOnOrderCreation: true,
10889
- overrides: {
10890
- contractAddress: seaportContractAddress,
10891
- },
10892
- });
9953
+ create(orderSeaportVersion, orderSeaportAddress) {
9954
+ const seaportVersion = orderSeaportVersion ?? SEAPORT_CONTRACT_VERSION_V1_5;
9955
+ const seaportContractAddress = orderSeaportAddress ?? this.defaultSeaportContractAddress;
9956
+ return new seaportJs.Seaport(this.provider, {
9957
+ seaportVersion,
9958
+ balanceAndApprovalChecksOnOrderCreation: true,
9959
+ overrides: {
9960
+ contractAddress: seaportContractAddress,
9961
+ },
9962
+ });
10893
9963
  }
10894
9964
  }
10895
9965
 
@@ -10938,8 +10008,8 @@ class Orderbook {
10938
10008
  /**
10939
10009
  * List orders. This method is used to get a list of orders filtered by conditions specified
10940
10010
  * in the params object.
10941
- * @param {ListOrderParams} listOrderParams - Filtering, ordering and page parameters.
10942
- * @return {Orders} The paged orders.
10011
+ * @param {ListListingsParams} listOrderParams - Filtering, ordering and page parameters.
10012
+ * @return {ListListingsResult} The paged orders.
10943
10013
  */
10944
10014
  listListings(listOrderParams) {
10945
10015
  return this.apiClient.listListings(listOrderParams);
@@ -10953,9 +10023,7 @@ class Orderbook {
10953
10023
  * the order components that can be submitted to `createListing` with a signature.
10954
10024
  */
10955
10025
  async prepareListing({ makerAddress, sell, buy, orderExpiry, }) {
10956
- const erc721 = new ERC721Factory(sell.contractAddress, this.orderbookConfig.provider).create();
10957
- const royaltyInfo = await erc721.royaltyInfo(sell.tokenId, buy.amount);
10958
- return this.seaport.prepareSeaportOrder(makerAddress, sell, buy, royaltyInfo,
10026
+ return this.seaport.prepareSeaportOrder(makerAddress, sell, buy,
10959
10027
  // Default order start to now
10960
10028
  new Date(),
10961
10029
  // Default order expiry to 2 years from now
@@ -10977,12 +10045,13 @@ class Orderbook {
10977
10045
  * @param {string} fulfillerAddress - The address of the account fulfilling the order.
10978
10046
  * @return {FulfillOrderResponse} Approval and fulfilment transactions.
10979
10047
  */
10980
- async fulfillOrder(listingId, takerAddress) {
10981
- const fulfillmentDataRes = await this.apiClient.fulfillmentData([{
10048
+ async fulfillOrder(listingId, takerAddress, takerFee) {
10049
+ const fulfillmentDataRes = await this.apiClient.fulfillmentData([
10050
+ {
10982
10051
  order_id: listingId,
10983
- // fee: takerFee,
10984
- fee: undefined,
10985
- }]);
10052
+ fee: takerFee,
10053
+ },
10054
+ ]);
10986
10055
  if (fulfillmentDataRes.result.length !== 1) {
10987
10056
  throw new Error('unexpected fulfillment data result length');
10988
10057
  }
@@ -27554,7 +26623,7 @@ function validateSecondaryFees(secondaryFees) {
27554
26623
  if (!isValidNonZeroAddress(secondaryFee.recipient)) {
27555
26624
  throw new InvalidConfigurationError(`Invalid secondary fee recipient address: ${secondaryFee.recipient}`);
27556
26625
  }
27557
- if (secondaryFee.basisPoints < 0 || secondaryFee.basisPoints > MAX_SECONDARY_FEE_BASIS_POINTS) {
26626
+ if (secondaryFee.basisPoints <= 0 || secondaryFee.basisPoints > MAX_SECONDARY_FEE_BASIS_POINTS) {
27558
26627
  throw new InvalidConfigurationError(`Invalid secondary fee basis points: ${secondaryFee.basisPoints}`);
27559
26628
  }
27560
26629
  totalSecondaryFeeBasisPoints += secondaryFee.basisPoints;
@@ -27686,93 +26755,34 @@ class Exchange {
27686
26755
  * @param {string} tokenInAddress Token address to sell.
27687
26756
  * @param {string} tokenOutAddress Token address to buy.
27688
26757
  * @param {ethers.BigNumberish} amountIn Amount to sell.
27689
- * @param {number} slippagePercent (optional) The percentage of slippage tolerance. Default = 0.1. Max = 50. Min = 0.
27690
- * @param {number} maxHops (optional) Maximum hops allowed in optimal route. Default is 2.
27691
- * @param {number} deadline (optional) Latest time swap can execute. Default is 15 minutes.
27692
- * @return {TransactionResponse} The result containing the unsigned transaction and details of the swap.
27693
- */
27694
- async getUnsignedSwapTxFromAmountIn(fromAddress, tokenInAddress, tokenOutAddress, amountIn, slippagePercent = DEFAULT_SLIPPAGE, maxHops = DEFAULT_MAX_HOPS, deadline = DEFAULT_DEADLINE) {
27695
- return await this.getUnsignedSwapTx(fromAddress, tokenInAddress, tokenOutAddress, ethers.ethers.BigNumber.from(amountIn), slippagePercent, maxHops, deadline, sdkCore.TradeType.EXACT_INPUT);
27696
- }
27697
- /**
27698
- * Get the unsigned swap transaction given the amount to buy.
27699
- * Includes quote details for the swap.
27700
- *
27701
- * @param {string} fromAddress The public address that will sign and submit the transaction.
27702
- * @param {string} tokenInAddress Token address to sell.
27703
- * @param {string} tokenOutAddress Token address to buy.
27704
- * @param {ethers.BigNumberish} amountOut Amount to buy.
27705
- * @param {number} slippagePercent (optional) The percentage of slippage tolerance. Default = 0.1. Max = 50. Min = 0.
27706
- * @param {number} maxHops (optional) Maximum hops allowed in optimal route. Default is 2.
27707
- * @param {number} deadline (optional) Latest time swap can execute. Default is 15 minutes.
27708
- * @return {TransactionResponse} The result containing the unsigned transaction and details of the swap.
27709
- */
27710
- async getUnsignedSwapTxFromAmountOut(fromAddress, tokenInAddress, tokenOutAddress, amountOut, slippagePercent = DEFAULT_SLIPPAGE, maxHops = DEFAULT_MAX_HOPS, deadline = DEFAULT_DEADLINE) {
27711
- return await this.getUnsignedSwapTx(fromAddress, tokenInAddress, tokenOutAddress, ethers.ethers.BigNumber.from(amountOut), slippagePercent, maxHops, deadline, sdkCore.TradeType.EXACT_OUTPUT);
27712
- }
27713
- }
27714
-
27715
- /* eslint-disable class-methods-use-this */
27716
-
27717
- const $762782b6c862d954$export$db5daa1b5156ccfe = [
27718
- {
27719
- constant: true,
27720
- inputs: [],
27721
- name: "name",
27722
- outputs: [
27723
- {
27724
- name: "",
27725
- type: "string"
27726
- }
27727
- ],
27728
- payable: false,
27729
- type: "function"
27730
- },
27731
- {
27732
- constant: true,
27733
- inputs: [],
27734
- name: "decimals",
27735
- outputs: [
27736
- {
27737
- name: "",
27738
- type: "uint8"
27739
- }
27740
- ],
27741
- payable: false,
27742
- type: "function"
27743
- },
27744
- {
27745
- constant: true,
27746
- inputs: [
27747
- {
27748
- name: "_owner",
27749
- type: "address"
27750
- }
27751
- ],
27752
- name: "balanceOf",
27753
- outputs: [
27754
- {
27755
- name: "balance",
27756
- type: "uint256"
27757
- }
27758
- ],
27759
- payable: false,
27760
- type: "function"
27761
- },
27762
- {
27763
- constant: true,
27764
- inputs: [],
27765
- name: "symbol",
27766
- outputs: [
27767
- {
27768
- name: "",
27769
- type: "string"
27770
- }
27771
- ],
27772
- payable: false,
27773
- type: "function"
26758
+ * @param {number} slippagePercent (optional) The percentage of slippage tolerance. Default = 0.1. Max = 50. Min = 0.
26759
+ * @param {number} maxHops (optional) Maximum hops allowed in optimal route. Default is 2.
26760
+ * @param {number} deadline (optional) Latest time swap can execute. Default is 15 minutes.
26761
+ * @return {TransactionResponse} The result containing the unsigned transaction and details of the swap.
26762
+ */
26763
+ async getUnsignedSwapTxFromAmountIn(fromAddress, tokenInAddress, tokenOutAddress, amountIn, slippagePercent = DEFAULT_SLIPPAGE, maxHops = DEFAULT_MAX_HOPS, deadline = DEFAULT_DEADLINE) {
26764
+ return await this.getUnsignedSwapTx(fromAddress, tokenInAddress, tokenOutAddress, ethers.ethers.BigNumber.from(amountIn), slippagePercent, maxHops, deadline, sdkCore.TradeType.EXACT_INPUT);
27774
26765
  }
27775
- ];
26766
+ /**
26767
+ * Get the unsigned swap transaction given the amount to buy.
26768
+ * Includes quote details for the swap.
26769
+ *
26770
+ * @param {string} fromAddress The public address that will sign and submit the transaction.
26771
+ * @param {string} tokenInAddress Token address to sell.
26772
+ * @param {string} tokenOutAddress Token address to buy.
26773
+ * @param {ethers.BigNumberish} amountOut Amount to buy.
26774
+ * @param {number} slippagePercent (optional) The percentage of slippage tolerance. Default = 0.1. Max = 50. Min = 0.
26775
+ * @param {number} maxHops (optional) Maximum hops allowed in optimal route. Default is 2.
26776
+ * @param {number} deadline (optional) Latest time swap can execute. Default is 15 minutes.
26777
+ * @return {TransactionResponse} The result containing the unsigned transaction and details of the swap.
26778
+ */
26779
+ async getUnsignedSwapTxFromAmountOut(fromAddress, tokenInAddress, tokenOutAddress, amountOut, slippagePercent = DEFAULT_SLIPPAGE, maxHops = DEFAULT_MAX_HOPS, deadline = DEFAULT_DEADLINE) {
26780
+ return await this.getUnsignedSwapTx(fromAddress, tokenInAddress, tokenOutAddress, ethers.ethers.BigNumber.from(amountOut), slippagePercent, maxHops, deadline, sdkCore.TradeType.EXACT_OUTPUT);
26781
+ }
26782
+ }
26783
+
26784
+ /* eslint-disable class-methods-use-this */
26785
+
27776
26786
 
27777
26787
 
27778
26788
 
@@ -27980,6 +26990,111 @@ const $d85ad1457a3f1a83$export$3a9ebede6a150274 = new Map([
27980
26990
  }
27981
26991
  ]
27982
26992
  ]);
26993
+ const $d85ad1457a3f1a83$export$db5daa1b5156ccfe = [
26994
+ {
26995
+ constant: true,
26996
+ inputs: [],
26997
+ name: "name",
26998
+ outputs: [
26999
+ {
27000
+ name: "",
27001
+ type: "string"
27002
+ }
27003
+ ],
27004
+ payable: false,
27005
+ type: "function"
27006
+ },
27007
+ {
27008
+ constant: true,
27009
+ inputs: [],
27010
+ name: "decimals",
27011
+ outputs: [
27012
+ {
27013
+ name: "",
27014
+ type: "uint8"
27015
+ }
27016
+ ],
27017
+ payable: false,
27018
+ type: "function"
27019
+ },
27020
+ {
27021
+ constant: true,
27022
+ inputs: [
27023
+ {
27024
+ name: "_owner",
27025
+ type: "address"
27026
+ }
27027
+ ],
27028
+ name: "balanceOf",
27029
+ outputs: [
27030
+ {
27031
+ name: "balance",
27032
+ type: "uint256"
27033
+ }
27034
+ ],
27035
+ payable: false,
27036
+ type: "function"
27037
+ },
27038
+ {
27039
+ constant: true,
27040
+ inputs: [],
27041
+ name: "symbol",
27042
+ outputs: [
27043
+ {
27044
+ name: "",
27045
+ type: "string"
27046
+ }
27047
+ ],
27048
+ payable: false,
27049
+ type: "function"
27050
+ },
27051
+ {
27052
+ constant: true,
27053
+ inputs: [
27054
+ {
27055
+ name: "_owner",
27056
+ type: "address"
27057
+ },
27058
+ {
27059
+ name: "_spender",
27060
+ type: "address"
27061
+ }
27062
+ ],
27063
+ name: "allowance",
27064
+ outputs: [
27065
+ {
27066
+ name: "",
27067
+ type: "uint256"
27068
+ }
27069
+ ],
27070
+ payable: false,
27071
+ stateMutability: "view",
27072
+ type: "function"
27073
+ },
27074
+ {
27075
+ constant: false,
27076
+ inputs: [
27077
+ {
27078
+ name: "_spender",
27079
+ type: "address"
27080
+ },
27081
+ {
27082
+ name: "_value",
27083
+ type: "uint256"
27084
+ }
27085
+ ],
27086
+ name: "approve",
27087
+ outputs: [
27088
+ {
27089
+ name: "",
27090
+ type: "bool"
27091
+ }
27092
+ ],
27093
+ payable: false,
27094
+ stateMutability: "nonpayable",
27095
+ type: "function"
27096
+ }
27097
+ ];
27983
27098
 
27984
27099
 
27985
27100
  var $4b58188d47aafe8d$export$1fc8f52ad1810e52;
@@ -28032,6 +27147,7 @@ var $4b58188d47aafe8d$export$5d3b0ad129b9b98e;
28032
27147
  CheckoutErrorType["UNSUPPORTED_TOKEN_TYPE_ERROR"] = "UNSUPPORTED_TOKEN_TYPE_ERROR";
28033
27148
  CheckoutErrorType["GET_ORDER_LISTING_ERROR"] = "GET_ORDER_LISTING_ERROR";
28034
27149
  CheckoutErrorType["SWITCH_NETWORK_UNSUPPORTED"] = "SWITCH_NETWORK_UNSUPPORTED";
27150
+ CheckoutErrorType["GET_ERC20_ALLOWANCE_ERROR"] = "GET_ERC20_ALLOWANCE_ERROR";
28035
27151
  })($a8bc256d81a5e2c1$export$e3dc0620abde7f5a || ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a = {}));
28036
27152
  class $a8bc256d81a5e2c1$export$b722478a3cbfa3bc extends Error {
28037
27153
  message;
@@ -28248,7 +27364,7 @@ const $1564e43dde50bb61$export$df96cd8d56be0ab1 = async (config, web3Provider, w
28248
27364
  });
28249
27365
  async function $1564e43dde50bb61$export$60e0fe116a0e6ed0(web3Provider, walletAddress, contractAddress) {
28250
27366
  return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
28251
- const contract = new (ethers.Contract)(contractAddress, JSON.stringify(($762782b6c862d954$export$db5daa1b5156ccfe)), web3Provider);
27367
+ const contract = new (ethers.Contract)(contractAddress, JSON.stringify(($d85ad1457a3f1a83$export$db5daa1b5156ccfe)), web3Provider);
28252
27368
  const name = await contract.name();
28253
27369
  const symbol = await contract.symbol();
28254
27370
  const balance = await contract.balanceOf(walletAddress);
@@ -28372,6 +27488,8 @@ function $bb88265fe45a0393$export$ebe4804963e71f98(web3Provider) {
28372
27488
  }
28373
27489
  async function $bb88265fe45a0393$export$9e1fd9cc88c637a0(config, web3Provider, validateProviderOptions) {
28374
27490
  return ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
27491
+ if (web3Provider.provider?.isPassport) // if Passport skip the validation checks
27492
+ return web3Provider;
28375
27493
  if (!$bb88265fe45a0393$export$ebe4804963e71f98(web3Provider)) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Parsed provider is not a valid Web3Provider", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).WEB3_PROVIDER_ERROR);
28376
27494
  // this sets the default options and overrides them with any parsed options
28377
27495
  const options = {
@@ -28630,7 +27748,7 @@ const $2e7bf45a7c9a9570$var$DUMMY_WALLET_ADDRESS = "0x00000000000000000000000000
28630
27748
  const $2e7bf45a7c9a9570$var$DEFAULT_TOKEN_DECIMALS = 18;
28631
27749
  async function $2e7bf45a7c9a9570$var$getTokenInfoByAddress(config, tokenAddress, chainId, provider) {
28632
27750
  if (tokenAddress === "NATIVE") return config.networkMap.get(chainId)?.nativeCurrency;
28633
- const contract = new (ethers.Contract)(tokenAddress, JSON.stringify(($762782b6c862d954$export$db5daa1b5156ccfe)), provider);
27751
+ const contract = new (ethers.Contract)(tokenAddress, JSON.stringify(($d85ad1457a3f1a83$export$db5daa1b5156ccfe)), provider);
28634
27752
  const name = await contract.name();
28635
27753
  const symbol = await contract.symbol();
28636
27754
  const decimals = await contract.decimals();
@@ -28725,16 +27843,169 @@ async function $2e7bf45a7c9a9570$export$942c8de7174809fc(params, readOnlyProvide
28725
27843
 
28726
27844
 
28727
27845
 
28728
- const $c147333b1f360629$export$92589613aaa38e1f = 300000;
28729
- const $c147333b1f360629$export$dea9ce0e9bb2441c = "0x474989C4D25DD41B0B9b1ECb4643B9Fe25f83B19";
28730
- const $c147333b1f360629$export$4249179755829904 = (type, contractAddress, amount)=>{
27846
+
27847
+
27848
+
27849
+
27850
+
27851
+ const $2499eab4caa6dc71$export$1ede6278abcdf1cb = (itemRequirements)=>{
27852
+ const aggregatedMap = new Map();
27853
+ const aggregatedItemRequirements = [];
27854
+ itemRequirements.forEach((itemRequirement)=>{
27855
+ const { type: type } = itemRequirement;
27856
+ if (type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
27857
+ aggregatedItemRequirements.push(itemRequirement);
27858
+ return;
27859
+ }
27860
+ const { contractAddress: contractAddress, spenderAddress: spenderAddress, amount: amount } = itemRequirement;
27861
+ const key = `${contractAddress}${spenderAddress}`;
27862
+ const aggregateItem = aggregatedMap.get(key);
27863
+ if (aggregateItem && aggregateItem.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) aggregateItem.amount = (ethers.BigNumber).from(aggregateItem.amount).add(amount);
27864
+ else aggregatedMap.set(key, {
27865
+ ...itemRequirement
27866
+ });
27867
+ });
27868
+ return aggregatedItemRequirements.concat(Array.from(aggregatedMap.values()));
27869
+ };
27870
+ const $2499eab4caa6dc71$export$c804c9ade5c28607 = (itemRequirements)=>$2499eab4caa6dc71$export$1ede6278abcdf1cb(itemRequirements);
27871
+
27872
+
27873
+
27874
+
27875
+
27876
+ const $95b61a5bfb091547$export$41491ea105c4dc2d = async (provider, ownerAddress, contractAddress, spenderAddress)=>{
27877
+ try {
27878
+ const contract = new (0, ethers.Contract)(contractAddress, JSON.stringify((0, $d85ad1457a3f1a83$export$db5daa1b5156ccfe)), provider);
27879
+ return await contract.allowance(ownerAddress, spenderAddress);
27880
+ } catch (err) {
27881
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Failed to get the allowance for ERC20", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC20_ALLOWANCE_ERROR, {
27882
+ contractAddress: contractAddress
27883
+ });
27884
+ }
27885
+ };
27886
+ const $95b61a5bfb091547$export$5c6bea080a6ee647 = async (provider, ownerAddress, contractAddress, spenderAddress, amount)=>{
27887
+ try {
27888
+ const contract = new (0, ethers.Contract)(contractAddress, JSON.stringify((0, $d85ad1457a3f1a83$export$db5daa1b5156ccfe)), provider);
27889
+ const approveTransaction = await contract.populateTransaction.approve(spenderAddress, amount);
27890
+ if (approveTransaction) approveTransaction.from = ownerAddress;
27891
+ return approveTransaction;
27892
+ } catch {
27893
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Failed to get the approval transaction for ERC20", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC20_ALLOWANCE_ERROR, {
27894
+ contractAddress: contractAddress
27895
+ });
27896
+ }
27897
+ };
27898
+ const $95b61a5bfb091547$export$d93c00812189e36 = async (provider, ownerAddress, itemRequirements)=>{
27899
+ let sufficient = true;
27900
+ const sufficientAllowances = [];
27901
+ const erc20s = new Map();
27902
+ const allowancePromises = new Map();
27903
+ const insufficientERC20s = new Map();
27904
+ const transactionPromises = new Map();
27905
+ // Populate maps for both the ERC20 data and promises to get the allowance using the same key
27906
+ // so the promise and data can be linked together when the promise resolves
27907
+ for (const itemRequirement of itemRequirements){
27908
+ if (itemRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) continue;
27909
+ const { contractAddress: contractAddress, spenderAddress: spenderAddress } = itemRequirement;
27910
+ erc20s.set(`${contractAddress}${spenderAddress}`, itemRequirement);
27911
+ allowancePromises.set(`${contractAddress}${spenderAddress}`, $95b61a5bfb091547$export$41491ea105c4dc2d(provider, ownerAddress, contractAddress, spenderAddress));
27912
+ }
27913
+ const allowances = await Promise.all(allowancePromises.values());
27914
+ const allowancePromiseIds = Array.from(allowancePromises.keys());
27915
+ // Iterate through the allowance promises and get the ERC20 data from the ERC20 map
27916
+ // If the allowance returned for that ERC20 is sufficient then just set the item requirements
27917
+ // If the allowance is insufficient then set the delta and a promise for the approval transaction
27918
+ for(let index = 0; index < allowances.length; index++){
27919
+ const itemRequirement = erc20s.get(allowancePromiseIds[index]);
27920
+ if (!itemRequirement || itemRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) continue;
27921
+ if (allowances[index].gte(itemRequirement.amount)) {
27922
+ sufficientAllowances.push({
27923
+ sufficient: true,
27924
+ itemRequirement: itemRequirement
27925
+ });
27926
+ continue;
27927
+ }
27928
+ sufficient = false; // Set sufficient false on the root of the return object when an ERC20 is insufficient
27929
+ const { contractAddress: contractAddress, spenderAddress: spenderAddress } = itemRequirement;
27930
+ const delta = itemRequirement.amount.sub(allowances[index]);
27931
+ // Create maps for both the insufficient ERC20 data and the transaction promises using the same key so the results can be merged
27932
+ insufficientERC20s.set(`${contractAddress}${spenderAddress}`, {
27933
+ sufficient: false,
27934
+ delta: delta,
27935
+ itemRequirement: itemRequirement,
27936
+ approvalTransaction: undefined
27937
+ });
27938
+ transactionPromises.set(`${contractAddress}${spenderAddress}`, $95b61a5bfb091547$export$5c6bea080a6ee647(provider, ownerAddress, contractAddress, spenderAddress, delta));
27939
+ }
27940
+ // Resolves the approval transactions and merges them with the insufficient ERC20 data
27941
+ const transactions = await Promise.all(transactionPromises.values());
27942
+ const transactionPromiseIds = Array.from(allowancePromises.keys());
27943
+ transactions.forEach((transaction, index)=>{
27944
+ const insufficientERC20 = insufficientERC20s.get(transactionPromiseIds[index]);
27945
+ if (!insufficientERC20) return;
27946
+ if (insufficientERC20.sufficient) return;
27947
+ insufficientERC20.approvalTransaction = transaction;
27948
+ });
27949
+ // Merge the allowance arrays to get both the sufficient allowances and the insufficient ERC20 allowances
27950
+ return {
27951
+ sufficient: sufficient,
27952
+ allowances: sufficientAllowances.concat(Array.from(insufficientERC20s.values()))
27953
+ };
27954
+ };
27955
+
27956
+
27957
+ const $0e7419077c373b24$export$9e073f9ada8c81e6 = async (provider, itemRequirements, transactionOrGasAmount)=>{
27958
+ const ownerAddress = await provider.getSigner().getAddress();
27959
+ // eslint-disable-next-line no-console
27960
+ console.log(provider, itemRequirements, transactionOrGasAmount);
27961
+ const aggregatedItems = ($2499eab4caa6dc71$export$c804c9ade5c28607)(itemRequirements);
27962
+ // eslint-disable-next-line no-console
27963
+ console.log(aggregatedItems);
27964
+ const erc20Allowances = await ($95b61a5bfb091547$export$d93c00812189e36)(provider, ownerAddress, aggregatedItems);
27965
+ // eslint-disable-next-line no-console
27966
+ console.log(erc20Allowances);
27967
+ return {
27968
+ sufficient: true,
27969
+ transactionRequirements: [
27970
+ {
27971
+ type: ($4b58188d47aafe8d$export$5d3b0ad129b9b98e).GAS,
27972
+ sufficient: true,
27973
+ required: {
27974
+ balance: (ethers.BigNumber).from(0),
27975
+ formattedBalance: "0",
27976
+ token: {
27977
+ name: "IMX",
27978
+ symbol: "IMX",
27979
+ address: "0x0",
27980
+ decimals: 18
27981
+ }
27982
+ },
27983
+ current: {
27984
+ balance: (ethers.BigNumber).from(1),
27985
+ formattedBalance: "1",
27986
+ token: {
27987
+ name: "IMX",
27988
+ symbol: "IMX",
27989
+ address: "0x0",
27990
+ decimals: 18
27991
+ }
27992
+ }
27993
+ }
27994
+ ]
27995
+ };
27996
+ };
27997
+
27998
+
27999
+
28000
+
28001
+ const $64863c39386de592$export$4249179755829904 = (type, contractAddress, amount, spenderAddress)=>{
28731
28002
  switch(type){
28732
28003
  case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20:
28733
28004
  return {
28734
28005
  type: type,
28735
28006
  amount: amount,
28736
28007
  contractAddress: contractAddress,
28737
- spenderAddress: $c147333b1f360629$export$dea9ce0e9bb2441c
28008
+ spenderAddress: spenderAddress
28738
28009
  };
28739
28010
  case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE:
28740
28011
  default:
@@ -28744,17 +28015,48 @@ const $c147333b1f360629$export$4249179755829904 = (type, contractAddress, amount
28744
28015
  };
28745
28016
  }
28746
28017
  };
28747
- const $c147333b1f360629$export$7f8e2b98eca5a7f0 = async (config, provider, orderId)=>{
28018
+ const $64863c39386de592$export$e0cb3ec5326d496b = async (actions)=>{
28019
+ for (const action of actions){
28020
+ if (action.type === (ActionType).TRANSACTION && action.purpose === (TransactionPurpose).FULFILL_ORDER) // eslint-disable-next-line no-await-in-loop
28021
+ return await action.buildTransaction();
28022
+ }
28023
+ return undefined;
28024
+ };
28025
+ const $64863c39386de592$export$8f2ff92ab8657f0b = (gasLimit, transaction)=>{
28026
+ if (transaction) return {
28027
+ type: ($4b58188d47aafe8d$export$65c64e46348ee3c1).TRANSACTION,
28028
+ transaction: transaction
28029
+ };
28030
+ return {
28031
+ type: ($4b58188d47aafe8d$export$65c64e46348ee3c1).GAS,
28032
+ gasToken: {
28033
+ type: ($4b58188d47aafe8d$export$537fa3efd10ed435).NATIVE,
28034
+ limit: (ethers.BigNumber).from(gasLimit)
28035
+ }
28036
+ };
28037
+ };
28038
+ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, orderId)=>{
28039
+ let orderbook;
28748
28040
  let order;
28041
+ let spenderAddress = "";
28042
+ const gasLimit = (constants).estimatedFulfillmentGasGwei;
28749
28043
  try {
28750
- const orderbook = await $67fc622a2b913d5f$export$c60ce6c6a92bc2ff(config);
28044
+ orderbook = await $67fc622a2b913d5f$export$c60ce6c6a92bc2ff(config);
28751
28045
  order = await orderbook.getListing(orderId);
28046
+ const { seaportContractAddress: seaportContractAddress } = orderbook.config();
28047
+ spenderAddress = seaportContractAddress;
28752
28048
  } catch (err) {
28753
28049
  throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("An error occurred while getting the order listing", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ORDER_LISTING_ERROR, {
28754
28050
  orderId: orderId,
28755
28051
  message: err.message
28756
28052
  });
28757
28053
  }
28054
+ let unsignedTransaction;
28055
+ try {
28056
+ const fulfillerAddress = await provider.getSigner().getAddress();
28057
+ const { actions: actions } = await orderbook.fulfillOrder(orderId, fulfillerAddress);
28058
+ unsignedTransaction = await $64863c39386de592$export$e0cb3ec5326d496b(actions);
28059
+ } catch {}
28758
28060
  let amount = (ethers.BigNumber).from("0");
28759
28061
  let type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE;
28760
28062
  let contractAddress = "";
@@ -28780,13 +28082,14 @@ const $c147333b1f360629$export$7f8e2b98eca5a7f0 = async (config, provider, order
28780
28082
  amount = amount.add((ethers.BigNumber).from(item.amount));
28781
28083
  });
28782
28084
  const itemRequirements = [
28783
- $c147333b1f360629$export$4249179755829904(type, contractAddress, amount)
28085
+ $64863c39386de592$export$4249179755829904(type, contractAddress, amount, spenderAddress)
28784
28086
  ];
28087
+ await ($0e7419077c373b24$export$9e073f9ada8c81e6)(provider, itemRequirements, $64863c39386de592$export$8f2ff92ab8657f0b(gasLimit, unsignedTransaction));
28785
28088
  return {
28786
28089
  itemRequirements: itemRequirements,
28787
28090
  gasToken: {
28788
28091
  type: ($4b58188d47aafe8d$export$537fa3efd10ed435).NATIVE,
28789
- limit: (ethers.BigNumber).from($c147333b1f360629$export$92589613aaa38e1f)
28092
+ limit: (ethers.BigNumber).from(gasLimit)
28790
28093
  }
28791
28094
  };
28792
28095
  };
@@ -28796,44 +28099,6 @@ const $c147333b1f360629$export$7f8e2b98eca5a7f0 = async (config, provider, order
28796
28099
 
28797
28100
 
28798
28101
 
28799
- const $0e7419077c373b24$export$9e073f9ada8c81e6 = async (provider, itemRequirements, transactionOrGasAmount)=>{
28800
- // eslint-disable-next-line no-console
28801
- console.log(provider, itemRequirements, transactionOrGasAmount);
28802
- return {
28803
- sufficient: true,
28804
- transactionRequirements: [
28805
- {
28806
- type: ($4b58188d47aafe8d$export$5d3b0ad129b9b98e).GAS,
28807
- sufficient: true,
28808
- required: {
28809
- balance: (ethers.BigNumber).from(0),
28810
- formattedBalance: "0",
28811
- token: {
28812
- name: "IMX",
28813
- symbol: "IMX",
28814
- address: "0x0",
28815
- decimals: 18
28816
- }
28817
- },
28818
- current: {
28819
- balance: (ethers.BigNumber).from(1),
28820
- formattedBalance: "1",
28821
- token: {
28822
- name: "IMX",
28823
- symbol: "IMX",
28824
- address: "0x0",
28825
- decimals: 18
28826
- }
28827
- }
28828
- }
28829
- ]
28830
- };
28831
- };
28832
-
28833
-
28834
-
28835
-
28836
-
28837
28102
 
28838
28103
 
28839
28104
 
@@ -28978,7 +28243,7 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
28978
28243
  // eslint-disable-next-line no-console
28979
28244
  console.warn("This endpoint is currently under construction.");
28980
28245
  const web3Provider = await $bb88265fe45a0393$export$9e1fd9cc88c637a0(this.config, params.provider);
28981
- await $c147333b1f360629$export$7f8e2b98eca5a7f0(this.config, web3Provider, params.orderId);
28246
+ await $64863c39386de592$export$7f8e2b98eca5a7f0(this.config, web3Provider, params.orderId);
28982
28247
  }
28983
28248
  /**
28984
28249
  * Determines the transaction requirements to complete a purchase.
@@ -29024,7 +28289,7 @@ var checkout_sdk = /*#__PURE__*/Object.freeze({
29024
28289
  function $parcel$export(e, n, v, s) {
29025
28290
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
29026
28291
  }
29027
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.11.0-alpha";
28292
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.12.0-alpha";
29028
28293
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
29029
28294
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
29030
28295