@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.js CHANGED
@@ -5,7 +5,7 @@ import jwt_decode from 'jwt-decode';
5
5
  import * as crypto from 'crypto';
6
6
  import { Magic } from 'magic-sdk';
7
7
  import { OpenIdExtension } from '@magic-ext/oidc';
8
- import { BigNumber as BigNumber$1, ethers, providers, constants as constants$1, utils as utils$1, Contract as Contract$1, ContractFactory } from 'ethers';
8
+ import { BigNumber as BigNumber$1, ethers, providers, constants as constants$1, ContractFactory, utils as utils$1, Contract as Contract$1 } from 'ethers';
9
9
  import BN$2 from 'bn.js';
10
10
  import * as encUtils from 'enc-utils';
11
11
  import { Web3Provider, JsonRpcProvider } from '@ethersproject/providers';
@@ -2398,7 +2398,7 @@ class MultiRollupApiClients {
2398
2398
  }
2399
2399
 
2400
2400
  // eslint-disable-next-line @typescript-eslint/naming-convention
2401
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.11.0-alpha' };
2401
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.12.0-alpha' };
2402
2402
  const createConfig = ({ basePath, headers, }) => {
2403
2403
  if (!basePath.trim()) {
2404
2404
  throw Error('basePath can not be empty');
@@ -2458,7 +2458,7 @@ class APIError extends Error {
2458
2458
 
2459
2459
  /* eslint-disable implicit-arrow-linebreak */
2460
2460
  const defaultHeaders = {
2461
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.11.0-alpha',
2461
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.12.0-alpha',
2462
2462
  };
2463
2463
  /**
2464
2464
  * createAPIConfiguration to create a custom Configuration
@@ -2730,7 +2730,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
2730
2730
  chainID,
2731
2731
  coreContractAddress,
2732
2732
  registrationContractAddress,
2733
- sdkVersion: 'ts-immutable-sdk-0.11.0-alpha',
2733
+ sdkVersion: 'ts-immutable-sdk-0.12.0-alpha',
2734
2734
  });
2735
2735
  /**
2736
2736
  * Sets `sdkVersion` at the time of build
@@ -7396,22 +7396,28 @@ class AuthManager {
7396
7396
 
7397
7397
  class MagicAdapter {
7398
7398
  config;
7399
+ magicClient;
7399
7400
  constructor(config) {
7400
7401
  this.config = config;
7401
7402
  }
7402
7403
  async login(idToken, network) {
7403
7404
  return withPassportError(async () => {
7404
- const magicClient = new Magic(this.config.magicPublishableApiKey, {
7405
+ this.magicClient = new Magic(this.config.magicPublishableApiKey, {
7405
7406
  extensions: [new OpenIdExtension()],
7406
7407
  network,
7407
7408
  });
7408
- await magicClient.openid.loginWithOIDC({
7409
+ await this.magicClient.openid.loginWithOIDC({
7409
7410
  jwt: idToken,
7410
7411
  providerId: this.config.magicProviderId,
7411
7412
  });
7412
- return magicClient.rpcProvider;
7413
+ return this.magicClient.rpcProvider;
7413
7414
  }, PassportErrorType.WALLET_CONNECTION_ERROR);
7414
7415
  }
7416
+ async logout() {
7417
+ if (this.magicClient?.user) {
7418
+ await this.magicClient.user.logout();
7419
+ }
7420
+ }
7415
7421
  }
7416
7422
 
7417
7423
  const getStarkSigner = async (signer) => withPassportError(async () => {
@@ -7445,6 +7451,8 @@ const retryWithDelay = async (fn, options) => {
7445
7451
 
7446
7452
  /**
7447
7453
  * ProviderErrors should take priority over RpcErrorCodes
7454
+ * https://eips.ethereum.org/EIPS/eip-1193#provider-errors
7455
+ * https://eips.ethereum.org/EIPS/eip-1474#error-codes
7448
7456
  */
7449
7457
  var ProviderErrorCode;
7450
7458
  (function (ProviderErrorCode) {
@@ -7461,7 +7469,7 @@ var RpcErrorCode;
7461
7469
  RpcErrorCode[RpcErrorCode["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
7462
7470
  RpcErrorCode[RpcErrorCode["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
7463
7471
  RpcErrorCode[RpcErrorCode["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
7464
- RpcErrorCode[RpcErrorCode["USER_REJECTED_REQUEST"] = -32003] = "USER_REJECTED_REQUEST";
7472
+ RpcErrorCode[RpcErrorCode["TRANSACTION_REJECTED"] = -32003] = "TRANSACTION_REJECTED";
7465
7473
  })(RpcErrorCode || (RpcErrorCode = {}));
7466
7474
  class JsonRpcError extends Error {
7467
7475
  message;
@@ -7473,6 +7481,8 @@ class JsonRpcError extends Error {
7473
7481
  }
7474
7482
  }
7475
7483
 
7484
+ const transactionRejectedCrossSdkBridgeError = 'Transaction requires confirmation but this functionality is not'
7485
+ + ' supported in this environment. Please contact Immutable support if you need to enable this feature.';
7476
7486
  const convertBigNumberishToString = (value) => BigNumber$1.from(value).toString();
7477
7487
  const transformGuardianTransactions = (txs) => {
7478
7488
  try {
@@ -7495,13 +7505,15 @@ class GuardianClient {
7495
7505
  confirmationScreen;
7496
7506
  // TODO: ID-977, make this rollup agnostic
7497
7507
  imxEtherAddress;
7498
- constructor({ imxPublicApiDomain, accessToken, confirmationScreen, imxEtherAddress, }) {
7508
+ crossSdkBridgeEnabled;
7509
+ constructor({ accessToken, confirmationScreen, imxEtherAddress, config, }) {
7499
7510
  this.confirmationScreen = confirmationScreen;
7500
7511
  this.transactionAPI = new TransactionsApi(new Configuration({
7501
7512
  accessToken,
7502
- basePath: imxPublicApiDomain,
7513
+ basePath: config.imxPublicApiDomain,
7503
7514
  }));
7504
7515
  this.imxEtherAddress = imxEtherAddress;
7516
+ this.crossSdkBridgeEnabled = config.crossSdkBridgeEnabled;
7505
7517
  }
7506
7518
  /**
7507
7519
  * Open confirmation screen and close it automatically if the
@@ -7514,8 +7526,7 @@ class GuardianClient {
7514
7526
  return (task) => async () => {
7515
7527
  this.confirmationScreen.loading(popupWindowSize);
7516
7528
  try {
7517
- const result = await task();
7518
- return result;
7529
+ return await task();
7519
7530
  }
7520
7531
  catch (err) {
7521
7532
  this.confirmationScreen.closeWindow();
@@ -7545,7 +7556,10 @@ class GuardianClient {
7545
7556
  });
7546
7557
  const { confirmationRequired } = evaluateStarkexRes.data;
7547
7558
  if (confirmationRequired) {
7548
- const confirmationResult = await this.confirmationScreen.startGuardianTransaction(payloadHash, this.imxEtherAddress, TransactionApprovalRequestChainTypeEnum.Starkex);
7559
+ if (this.crossSdkBridgeEnabled) {
7560
+ throw new Error(transactionRejectedCrossSdkBridgeError);
7561
+ }
7562
+ const confirmationResult = await this.confirmationScreen.requestConfirmation(payloadHash, this.imxEtherAddress, TransactionApprovalRequestChainTypeEnum.Starkex);
7549
7563
  if (!confirmationResult.confirmed) {
7550
7564
  throw new Error('Transaction rejected by user');
7551
7565
  }
@@ -7585,10 +7599,13 @@ class GuardianClient {
7585
7599
  metaTransactions,
7586
7600
  });
7587
7601
  const { confirmationRequired, transactionId } = transactionEvaluationResponse;
7602
+ if (confirmationRequired && this.crossSdkBridgeEnabled) {
7603
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
7604
+ }
7588
7605
  if (confirmationRequired && !!transactionId) {
7589
- const confirmationResult = await this.confirmationScreen.startGuardianTransaction(transactionId, this.imxEtherAddress, TransactionApprovalRequestChainTypeEnum.Evm, chainId);
7606
+ const confirmationResult = await this.confirmationScreen.requestConfirmation(transactionId, this.imxEtherAddress, TransactionApprovalRequestChainTypeEnum.Evm, chainId);
7590
7607
  if (!confirmationResult.confirmed) {
7591
- throw new JsonRpcError(RpcErrorCode.USER_REJECTED_REQUEST, 'Transaction rejected by user ');
7608
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Transaction rejected by user');
7592
7609
  }
7593
7610
  }
7594
7611
  else {
@@ -7597,6 +7614,16 @@ class GuardianClient {
7597
7614
  }
7598
7615
  }
7599
7616
 
7617
+ var PassportEvents;
7618
+ (function (PassportEvents) {
7619
+ PassportEvents["LOGGED_OUT"] = "loggedOut";
7620
+ })(PassportEvents || (PassportEvents = {}));
7621
+ var Networks;
7622
+ (function (Networks) {
7623
+ Networks["PRODUCTION"] = "mainnet";
7624
+ Networks["SANDBOX"] = "goerli";
7625
+ })(Networks || (Networks = {}));
7626
+
7600
7627
  async function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, }) {
7601
7628
  return withPassportError(async () => {
7602
7629
  const { ethAddress } = user.imx;
@@ -7796,10 +7823,10 @@ async function createTrade$1({ request, tradesApi, user, starkSigner, guardianCl
7796
7823
  }), PassportErrorType.CREATE_TRADE_ERROR);
7797
7824
  }
7798
7825
 
7799
- const ERC721$2 = 'ERC721';
7826
+ const ERC721 = 'ERC721';
7800
7827
  async function transfer$1({ request, transfersApi, starkSigner, user, guardianClient, }) {
7801
7828
  return withPassportError(guardianClient.withDefaultConfirmationScreenTask(async () => {
7802
- const transferAmount = request.type === ERC721$2 ? '1' : request.amount;
7829
+ const transferAmount = request.type === ERC721 ? '1' : request.amount;
7803
7830
  const getSignableTransferRequest = {
7804
7831
  sender: user.imx.ethAddress,
7805
7832
  token: convertToSignableToken(request),
@@ -7849,7 +7876,7 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, guar
7849
7876
  const signableRequests = request.map((nftTransfer) => ({
7850
7877
  amount: '1',
7851
7878
  token: convertToSignableToken({
7852
- type: ERC721$2,
7879
+ type: ERC721,
7853
7880
  tokenId: nftTransfer.tokenId,
7854
7881
  tokenAddress: nftTransfer.tokenAddress,
7855
7882
  }),
@@ -7901,19 +7928,30 @@ class PassportImxProvider {
7901
7928
  immutableXClient;
7902
7929
  confirmationScreen;
7903
7930
  guardianClient;
7904
- constructor({ user, starkSigner, immutableXClient, imxPublicApiDomain, confirmationScreen, }) {
7931
+ constructor({ user, starkSigner, immutableXClient, confirmationScreen, config, passportEventEmitter, }) {
7905
7932
  this.user = user;
7906
7933
  this.starkSigner = starkSigner;
7907
7934
  this.immutableXClient = immutableXClient;
7908
7935
  this.confirmationScreen = confirmationScreen;
7909
7936
  this.guardianClient = new GuardianClient({
7910
- imxPublicApiDomain,
7911
7937
  accessToken: user.accessToken,
7912
7938
  confirmationScreen,
7913
7939
  imxEtherAddress: user.imx.ethAddress,
7940
+ config,
7914
7941
  });
7942
+ passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.handleLogout);
7943
+ }
7944
+ handleLogout = () => {
7945
+ this.user = undefined;
7946
+ this.starkSigner = undefined;
7947
+ };
7948
+ checkIsLoggedIn() {
7949
+ if (this.user === undefined || this.starkSigner === undefined) {
7950
+ throw new PassportError('User has been logged out', PassportErrorType.NOT_LOGGED_IN_ERROR);
7951
+ }
7915
7952
  }
7916
7953
  async transfer(request) {
7954
+ this.checkIsLoggedIn();
7917
7955
  return transfer$1({
7918
7956
  request,
7919
7957
  user: this.user,
@@ -7933,6 +7971,7 @@ class PassportImxProvider {
7933
7971
  throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
7934
7972
  }
7935
7973
  createOrder(request) {
7974
+ this.checkIsLoggedIn();
7936
7975
  return createOrder$1({
7937
7976
  request,
7938
7977
  user: this.user,
@@ -7942,6 +7981,7 @@ class PassportImxProvider {
7942
7981
  });
7943
7982
  }
7944
7983
  cancelOrder(request) {
7984
+ this.checkIsLoggedIn();
7945
7985
  return cancelOrder$1({
7946
7986
  request,
7947
7987
  user: this.user,
@@ -7951,6 +7991,7 @@ class PassportImxProvider {
7951
7991
  });
7952
7992
  }
7953
7993
  createTrade(request) {
7994
+ this.checkIsLoggedIn();
7954
7995
  return createTrade$1({
7955
7996
  request,
7956
7997
  user: this.user,
@@ -7960,6 +8001,7 @@ class PassportImxProvider {
7960
8001
  });
7961
8002
  }
7962
8003
  batchNftTransfer(request) {
8004
+ this.checkIsLoggedIn();
7963
8005
  return batchNftTransfer({
7964
8006
  request,
7965
8007
  user: this.user,
@@ -7969,6 +8011,7 @@ class PassportImxProvider {
7969
8011
  });
7970
8012
  }
7971
8013
  exchangeTransfer(request) {
8014
+ this.checkIsLoggedIn();
7972
8015
  return exchangeTransfer$1({
7973
8016
  request,
7974
8017
  user: this.user,
@@ -7996,6 +8039,7 @@ class PassportImxProvider {
7996
8039
  throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
7997
8040
  }
7998
8041
  getAddress() {
8042
+ this.checkIsLoggedIn();
7999
8043
  return Promise.resolve(this.user.imx.ethAddress);
8000
8044
  }
8001
8045
  }
@@ -8006,12 +8050,14 @@ class PassportImxProviderFactory {
8006
8050
  confirmationScreen;
8007
8051
  immutableXClient;
8008
8052
  magicAdapter;
8009
- constructor({ authManager, config, confirmationScreen, immutableXClient, magicAdapter, }) {
8053
+ passportEventEmitter;
8054
+ constructor({ authManager, config, confirmationScreen, immutableXClient, magicAdapter, passportEventEmitter, }) {
8010
8055
  this.authManager = authManager;
8011
8056
  this.config = config;
8012
8057
  this.confirmationScreen = confirmationScreen;
8013
8058
  this.immutableXClient = immutableXClient;
8014
8059
  this.magicAdapter = magicAdapter;
8060
+ this.passportEventEmitter = passportEventEmitter;
8015
8061
  }
8016
8062
  async getProvider() {
8017
8063
  const user = await this.authManager.login();
@@ -8053,16 +8099,18 @@ class PassportImxProviderFactory {
8053
8099
  user: userImx,
8054
8100
  starkSigner,
8055
8101
  immutableXClient: this.immutableXClient,
8056
- imxPublicApiDomain: this.config.imxPublicApiDomain,
8057
8102
  confirmationScreen: this.confirmationScreen,
8103
+ config: this.config,
8104
+ passportEventEmitter: this.passportEventEmitter,
8058
8105
  });
8059
8106
  }
8060
8107
  return new PassportImxProvider({
8061
8108
  user: user,
8062
8109
  starkSigner,
8063
8110
  immutableXClient: this.immutableXClient,
8064
- imxPublicApiDomain: this.config.imxPublicApiDomain,
8065
8111
  confirmationScreen: this.confirmationScreen,
8112
+ config: this.config,
8113
+ passportEventEmitter: this.passportEventEmitter,
8066
8114
  });
8067
8115
  }
8068
8116
  async registerStarkEx(userAdminKeySigner, starkSigner, jwt) {
@@ -8086,12 +8134,6 @@ class PassportImxProviderFactory {
8086
8134
  }
8087
8135
  }
8088
8136
 
8089
- var Networks;
8090
- (function (Networks) {
8091
- Networks["PRODUCTION"] = "mainnet";
8092
- Networks["SANDBOX"] = "goerli";
8093
- })(Networks || (Networks = {}));
8094
-
8095
8137
  const validateConfiguration = (configuration, requiredKeys, prefix) => {
8096
8138
  const missingKeys = requiredKeys
8097
8139
  .map((key) => !configuration[key] && key)
@@ -8113,11 +8155,11 @@ class PassportConfiguration {
8113
8155
  magicProviderId;
8114
8156
  oidcConfiguration;
8115
8157
  baseConfig;
8116
- zkEvmChainId;
8117
8158
  zkEvmRpcUrl;
8118
8159
  relayerUrl;
8119
8160
  multiRollupConfig;
8120
- constructor({ baseConfig, overrides, ...oidcConfiguration }) {
8161
+ crossSdkBridgeEnabled;
8162
+ constructor({ baseConfig, overrides, crossSdkBridgeEnabled, ...oidcConfiguration }) {
8121
8163
  validateConfiguration(oidcConfiguration, [
8122
8164
  'clientId',
8123
8165
  'logoutRedirectUri',
@@ -8125,6 +8167,7 @@ class PassportConfiguration {
8125
8167
  ]);
8126
8168
  this.oidcConfiguration = oidcConfiguration;
8127
8169
  this.baseConfig = baseConfig;
8170
+ this.crossSdkBridgeEnabled = crossSdkBridgeEnabled || false;
8128
8171
  if (overrides) {
8129
8172
  validateConfiguration(overrides, [
8130
8173
  'network',
@@ -8133,7 +8176,6 @@ class PassportConfiguration {
8133
8176
  'magicPublishableApiKey',
8134
8177
  'magicProviderId',
8135
8178
  'zkEvmRpcUrl',
8136
- 'zkEvmChainId',
8137
8179
  'relayerUrl',
8138
8180
  'imxPublicApiDomain',
8139
8181
  'indexerMrBasePath',
@@ -8147,7 +8189,6 @@ class PassportConfiguration {
8147
8189
  this.magicPublishableApiKey = overrides.magicPublishableApiKey;
8148
8190
  this.magicProviderId = overrides.magicProviderId;
8149
8191
  this.zkEvmRpcUrl = overrides.zkEvmRpcUrl;
8150
- this.zkEvmChainId = overrides.zkEvmChainId;
8151
8192
  this.relayerUrl = overrides.relayerUrl;
8152
8193
  this.multiRollupConfig = {
8153
8194
  indexer: createConfig({
@@ -8171,7 +8212,6 @@ class PassportConfiguration {
8171
8212
  this.passportDomain = 'https://passport.immutable.com';
8172
8213
  this.imxPublicApiDomain = 'https://api.immutable.com';
8173
8214
  this.zkEvmRpcUrl = ''; // TODO: ID-785 Update once mainnet has been deployed
8174
- this.zkEvmChainId = ''; // TODO: ID-785 Update once mainnet has been deployed
8175
8215
  this.relayerUrl = 'https://api.immutable.com/relayer-mr';
8176
8216
  this.multiRollupConfig = multiRollupConfig.getProduction();
8177
8217
  break;
@@ -8185,7 +8225,6 @@ class PassportConfiguration {
8185
8225
  this.passportDomain = 'https://passport.sandbox.immutable.com';
8186
8226
  this.imxPublicApiDomain = 'https://api.sandbox.immutable.com';
8187
8227
  this.zkEvmRpcUrl = 'https://rpc.testnet.immutable.com';
8188
- this.zkEvmChainId = 'eip155:13472';
8189
8228
  this.relayerUrl = 'https://api.sandbox.immutable.com/relayer-mr';
8190
8229
  this.multiRollupConfig = multiRollupConfig.getSandbox();
8191
8230
  break;
@@ -8201,18 +8240,6 @@ var ReceiveMessage;
8201
8240
  ReceiveMessage["TRANSACTION_CONFIRMED"] = "transaction_confirmed";
8202
8241
  ReceiveMessage["TRANSACTION_ERROR"] = "transaction_error";
8203
8242
  })(ReceiveMessage || (ReceiveMessage = {}));
8204
- var SendMessage;
8205
- (function (SendMessage) {
8206
- SendMessage["TRANSACTION_START"] = "transaction_start";
8207
- })(SendMessage || (SendMessage = {}));
8208
- var TransactionTypes$1;
8209
- (function (TransactionTypes) {
8210
- TransactionTypes["cancelOrder"] = "delete:v1/orders";
8211
- TransactionTypes["createOrder"] = "post:v1/orders";
8212
- TransactionTypes["createTrade"] = "post:v1/trades";
8213
- TransactionTypes["createTransfer"] = "post:v1/transfers";
8214
- TransactionTypes["createBatchTransfer"] = "post:v2/transfers";
8215
- })(TransactionTypes$1 || (TransactionTypes$1 = {}));
8216
8243
  const PASSPORT_EVENT_TYPE = 'imx_passport_confirmation';
8217
8244
 
8218
8245
  const openPopupCenter = ({ url, title, width, height, }) => {
@@ -8242,60 +8269,7 @@ class ConfirmationScreen {
8242
8269
  constructor(config) {
8243
8270
  this.config = config;
8244
8271
  }
8245
- postMessage(destinationWindow, accessToken, message) {
8246
- destinationWindow.postMessage({
8247
- eventType: PASSPORT_EVENT_TYPE,
8248
- accessToken,
8249
- ...message,
8250
- }, this.config.passportDomain);
8251
- }
8252
- startTransaction(accessToken, transaction, popupOptions) {
8253
- return new Promise((resolve, reject) => {
8254
- const messageHandler = ({ data, origin }) => {
8255
- if (origin !== this.config.passportDomain
8256
- || data.eventType !== PASSPORT_EVENT_TYPE) {
8257
- return;
8258
- }
8259
- switch (data.messageType) {
8260
- case ReceiveMessage.CONFIRMATION_WINDOW_READY: {
8261
- // TODO: remove once fixed
8262
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
8263
- this.postMessage(confirmationWindow, accessToken, {
8264
- messageType: SendMessage.TRANSACTION_START,
8265
- messageData: transaction,
8266
- });
8267
- break;
8268
- }
8269
- case ReceiveMessage.TRANSACTION_CONFIRMED: {
8270
- resolve({ confirmed: true });
8271
- break;
8272
- }
8273
- case ReceiveMessage.TRANSACTION_ERROR: {
8274
- reject(new Error('Transaction error'));
8275
- break;
8276
- }
8277
- default:
8278
- reject(new Error('Unsupported message type'));
8279
- }
8280
- };
8281
- window.addEventListener('message', messageHandler);
8282
- const confirmationWindow = openPopupCenter({
8283
- url: `${this.config.passportDomain}/transaction-confirmation`,
8284
- title: CONFIRMATION_WINDOW_TITLE,
8285
- width: popupOptions?.width || CONFIRMATION_WINDOW_WIDTH,
8286
- height: popupOptions?.height || CONFIRMATION_WINDOW_HEIGHT,
8287
- });
8288
- // https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
8289
- const timer = setInterval(() => {
8290
- if (confirmationWindow.closed) {
8291
- clearInterval(timer);
8292
- window.removeEventListener('message', messageHandler);
8293
- resolve({ confirmed: false });
8294
- }
8295
- }, CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION);
8296
- });
8297
- }
8298
- startGuardianTransaction(transactionId, imxEtherAddress, chainType, chainId) {
8272
+ requestConfirmation(transactionId, imxEtherAddress, chainType, chainId) {
8299
8273
  return new Promise((resolve, reject) => {
8300
8274
  const messageHandler = ({ data, origin }) => {
8301
8275
  if (origin !== this.config.passportDomain
@@ -8323,7 +8297,6 @@ class ConfirmationScreen {
8323
8297
  resolve({ confirmed: false });
8324
8298
  return;
8325
8299
  }
8326
- // eslint-disable-next-line max-len
8327
8300
  let href = '';
8328
8301
  if (chainType === TransactionApprovalRequestChainTypeEnum.Starkex) {
8329
8302
  // eslint-disable-next-line max-len
@@ -8345,6 +8318,10 @@ class ConfirmationScreen {
8345
8318
  });
8346
8319
  }
8347
8320
  loading(popupOptions) {
8321
+ if (this.config.crossSdkBridgeEnabled) {
8322
+ // There is no need to open a confirmation window if cross-sdk bridge is enabled
8323
+ return;
8324
+ }
8348
8325
  this.confirmationWindow = openPopupCenter({
8349
8326
  url: `${this.config.passportDomain}/transaction-confirmation/loading.html`,
8350
8327
  title: CONFIRMATION_WINDOW_TITLE,
@@ -8383,11 +8360,82 @@ class TypedEventEmitter {
8383
8360
  }
8384
8361
  }
8385
8362
 
8363
+ // These are ignored by the Relayer but for consistency we set them to the
8364
+ // appropriate values for a 1/1 wallet.
8365
+ //
8366
+ // Weight of a single signature in the multisig
8367
+ const SIGNATURE_WEIGHT = 1;
8368
+ // Total required weight in the multisig
8369
+ const SIGNATURE_THRESHOLD = 1;
8370
+ const ETH_SIGN_FLAG = '02';
8371
+ const ETH_SIGN_PREFIX = '\x19\x01';
8372
+ const META_TRANSACTIONS_TYPE = `tuple(
8373
+ bool delegateCall,
8374
+ bool revertOnError,
8375
+ uint256 gasLimit,
8376
+ address target,
8377
+ uint256 value,
8378
+ bytes data
8379
+ )[]`;
8380
+ function getNormalisedTransactions(txs) {
8381
+ return txs.map((t) => ({
8382
+ delegateCall: t.delegateCall === true,
8383
+ revertOnError: t.revertOnError === true,
8384
+ gasLimit: t.gasLimit ?? ethers.constants.Zero,
8385
+ target: t.to ?? ethers.constants.AddressZero,
8386
+ value: t.value ?? ethers.constants.Zero,
8387
+ data: t.data ?? [],
8388
+ }));
8389
+ }
8390
+ function digestOfTransactionsAndNonce(nonce, normalisedTransactions) {
8391
+ const packMetaTransactionsNonceData = ethers.utils.defaultAbiCoder.encode(['uint256', META_TRANSACTIONS_TYPE], [nonce, normalisedTransactions]);
8392
+ return ethers.utils.keccak256(packMetaTransactionsNonceData);
8393
+ }
8394
+ const getNonce = async (jsonRpcProvider, smartContractWalletAddress) => {
8395
+ const code = await jsonRpcProvider.send('eth_getCode', [smartContractWalletAddress, 'latest']);
8396
+ if (code && code !== '0x') {
8397
+ const contract = new ethers.Contract(smartContractWalletAddress, walletContracts.mainModule.abi, jsonRpcProvider);
8398
+ return contract.nonce();
8399
+ }
8400
+ return 0;
8401
+ };
8402
+ const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walletAddress, signer) => {
8403
+ const normalisedMetaTransactions = getNormalisedTransactions(metaTransactions);
8404
+ // Get the hash
8405
+ const digest = digestOfTransactionsAndNonce(nonce, normalisedMetaTransactions);
8406
+ const completePayload = ethers.utils.solidityPack(['string', 'uint256', 'address', 'bytes32'], [ETH_SIGN_PREFIX, chainId, walletAddress, digest]);
8407
+ const hash = ethers.utils.keccak256(completePayload);
8408
+ // Sign the digest
8409
+ const hashArray = ethers.utils.arrayify(hash);
8410
+ const ethsigNoType = await signer.signMessage(hashArray);
8411
+ const signedDigest = `${ethsigNoType}${ETH_SIGN_FLAG}`;
8412
+ // Add metadata
8413
+ const encodedSignature = encodeSignature({
8414
+ threshold: SIGNATURE_THRESHOLD,
8415
+ signers: [
8416
+ {
8417
+ weight: SIGNATURE_WEIGHT,
8418
+ signature: signedDigest,
8419
+ },
8420
+ ],
8421
+ });
8422
+ // Encode the transaction;
8423
+ const walletInterface = new ethers.utils.Interface(walletContracts.mainModule.abi);
8424
+ return walletInterface.encodeFunctionData(walletInterface.getFunction('execute'), [
8425
+ normalisedMetaTransactions,
8426
+ nonce,
8427
+ encodedSignature,
8428
+ ]);
8429
+ };
8430
+ const getEip155ChainId = (chainId) => `eip155:${chainId}`;
8431
+
8386
8432
  class RelayerClient {
8387
8433
  config;
8434
+ jsonRpcProvider;
8388
8435
  user;
8389
- constructor({ config, user }) {
8436
+ constructor({ config, jsonRpcProvider, user }) {
8390
8437
  this.config = config;
8438
+ this.jsonRpcProvider = jsonRpcProvider;
8391
8439
  this.user = user;
8392
8440
  }
8393
8441
  async postToRelayer(request) {
@@ -8411,12 +8459,13 @@ class RelayerClient {
8411
8459
  return jsonResponse;
8412
8460
  }
8413
8461
  async ethSendTransaction(to, data) {
8462
+ const { chainId } = await this.jsonRpcProvider.ready;
8414
8463
  const payload = {
8415
8464
  method: 'eth_sendTransaction',
8416
8465
  params: [{
8417
8466
  to,
8418
8467
  data,
8419
- chainId: this.config.zkEvmChainId.toString(),
8468
+ chainId: getEip155ChainId(chainId),
8420
8469
  }],
8421
8470
  };
8422
8471
  const { result } = await this.postToRelayer(payload);
@@ -8431,12 +8480,13 @@ class RelayerClient {
8431
8480
  return result;
8432
8481
  }
8433
8482
  async imGetFeeOptions(userAddress, data) {
8483
+ const { chainId } = await this.jsonRpcProvider.ready;
8434
8484
  const payload = {
8435
8485
  method: 'im_getFeeOptions',
8436
8486
  params: [{
8437
8487
  userAddress,
8438
8488
  data,
8439
- chainId: this.config.zkEvmChainId.toString(),
8489
+ chainId: getEip155ChainId(chainId),
8440
8490
  }],
8441
8491
  };
8442
8492
  const { result } = await this.postToRelayer(payload);
@@ -8494,90 +8544,16 @@ const loginZkEvmUser = async ({ authManager, config, magicAdapter, multiRollupAp
8494
8544
  };
8495
8545
  };
8496
8546
 
8497
- // These are ignored by the Relayer but for consistency we set them to the
8498
- // appropriate values for a 1/1 wallet.
8499
- //
8500
- // Weight of a single signature in the multisig
8501
- const SIGNATURE_WEIGHT = 1;
8502
- // Total required weight in the multisig
8503
- const SIGNATURE_THRESHOLD = 1;
8504
- const ETH_SIGN_FLAG = '02';
8505
- const ETH_SIGN_PREFIX = '\x19\x01';
8506
- const META_TRANSACTIONS_TYPE = `tuple(
8507
- bool delegateCall,
8508
- bool revertOnError,
8509
- uint256 gasLimit,
8510
- address target,
8511
- uint256 value,
8512
- bytes data
8513
- )[]`;
8514
- function getNormalisedTransactions(txs) {
8515
- return txs.map((t) => ({
8516
- delegateCall: t.delegateCall === true,
8517
- revertOnError: t.revertOnError === true,
8518
- gasLimit: t.gasLimit ?? ethers.constants.Zero,
8519
- target: t.to ?? ethers.constants.AddressZero,
8520
- value: t.value ?? ethers.constants.Zero,
8521
- data: t.data ?? [],
8522
- }));
8523
- }
8524
- function digestOfTransactionsAndNonce(nonce, normalisedTransactions) {
8525
- const packMetaTransactionsNonceData = ethers.utils.defaultAbiCoder.encode(['uint256', META_TRANSACTIONS_TYPE], [nonce, normalisedTransactions]);
8526
- return ethers.utils.keccak256(packMetaTransactionsNonceData);
8527
- }
8528
- const getNonce = async (jsonRpcProvider, smartContractWalletAddress) => {
8529
- const code = await jsonRpcProvider.send('eth_getCode', [smartContractWalletAddress, 'latest']);
8530
- if (code && code !== '0x') {
8531
- const contract = new ethers.Contract(smartContractWalletAddress, walletContracts.mainModule.abi, jsonRpcProvider);
8532
- return contract.nonce();
8533
- }
8534
- return 0;
8535
- };
8536
- const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walletAddress, signer) => {
8537
- const normalisedMetaTransactions = getNormalisedTransactions(metaTransactions);
8538
- // Get the hash
8539
- const digest = digestOfTransactionsAndNonce(nonce, normalisedMetaTransactions);
8540
- const completePayload = ethers.utils.solidityPack(['string', 'uint256', 'address', 'bytes32'], [ETH_SIGN_PREFIX, chainId, walletAddress, digest]);
8541
- const hash = ethers.utils.keccak256(completePayload);
8542
- // Sign the digest
8543
- const hashArray = ethers.utils.arrayify(hash);
8544
- const ethsigNoType = await signer.signMessage(hashArray);
8545
- const signedDigest = `${ethsigNoType}${ETH_SIGN_FLAG}`;
8546
- // Add metadata
8547
- const encodedSignature = encodeSignature({
8548
- threshold: SIGNATURE_THRESHOLD,
8549
- signers: [
8550
- {
8551
- weight: SIGNATURE_WEIGHT,
8552
- signature: signedDigest,
8553
- },
8554
- ],
8555
- });
8556
- // Encode the transaction;
8557
- const walletInterface = new ethers.utils.Interface(walletContracts.mainModule.abi);
8558
- return walletInterface.encodeFunctionData(walletInterface.getFunction('execute'), [
8559
- normalisedMetaTransactions,
8560
- nonce,
8561
- encodedSignature,
8562
- ]);
8563
- };
8564
- const chainIdNumber = (chainId) => {
8565
- const caip2Components = chainId.split(':');
8566
- if (caip2Components.length !== 2) {
8567
- throw new Error('Invalid configuration, chain ID is not in CAIP-2 format');
8568
- }
8569
- return BigNumber$1.from(caip2Components[1]);
8570
- };
8571
-
8572
8547
  const MAX_TRANSACTION_HASH_RETRIEVAL_RETRIES = 30;
8573
8548
  const TRANSACTION_HASH_RETRIEVAL_WAIT = 1000;
8574
- const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, config, user, }) => guardianClient
8549
+ const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, user, }) => guardianClient
8575
8550
  .withConfirmationScreen({ width: 480, height: 520 })(async () => {
8576
8551
  const transactionRequest = params[0];
8577
8552
  if (!transactionRequest.to) {
8578
8553
  throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'eth_sendTransaction requires a "to" field');
8579
8554
  }
8580
- const chainId = chainIdNumber(config.zkEvmChainId);
8555
+ const { chainId } = await jsonRpcProvider.ready;
8556
+ const chainIdBigNumber = BigNumber$1.from(chainId);
8581
8557
  const magicWeb3Provider = new Web3Provider(magicProvider);
8582
8558
  const signer = magicWeb3Provider.getSigner();
8583
8559
  const nonce = await getNonce(jsonRpcProvider, user.zkEvm.ethAddress);
@@ -8592,7 +8568,7 @@ const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient
8592
8568
  // accurate estimation of a transaction gas cost is only possible if the smart
8593
8569
  // wallet contract can actually execute it (in a simulated environment) - and
8594
8570
  // it can only execute signed transactions.
8595
- const signedTransaction = await getSignedMetaTransactions([metaTransaction], nonce, chainId, user.zkEvm.ethAddress, signer);
8571
+ const signedTransaction = await getSignedMetaTransactions([metaTransaction], nonce, chainIdBigNumber, user.zkEvm.ethAddress, signer);
8596
8572
  // TODO: ID-698 Add support for non-native gas payments (e.g ERC20, feeTransaction initialisation must change)
8597
8573
  // NOTE: "Fee Options" represent the multiple ways we could pay for the gas
8598
8574
  // used in this transaction. Each fee option has a "recipientAddress" we
@@ -8611,15 +8587,14 @@ const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient
8611
8587
  revertOnError: true,
8612
8588
  };
8613
8589
  await guardianClient.validateEVMTransaction({
8614
- chainId: config.zkEvmChainId,
8590
+ chainId: getEip155ChainId(chainId),
8615
8591
  nonce: convertBigNumberishToString(nonce),
8616
8592
  user,
8617
8593
  metaTransactions: [metaTransaction, feeMetaTransaction],
8618
8594
  });
8619
8595
  // NOTE: We sign again because we now are adding the fee transaction, so the
8620
8596
  // whole payload is different and needs a new signature.
8621
- const signedTransactions = await getSignedMetaTransactions([metaTransaction, feeMetaTransaction], nonce, chainId, user.zkEvm.ethAddress, signer);
8622
- // TODO: ID-697 Evaluate transactions through Guardian
8597
+ const signedTransactions = await getSignedMetaTransactions([metaTransaction, feeMetaTransaction], nonce, chainIdBigNumber, user.zkEvm.ethAddress, signer);
8623
8598
  const relayerId = await relayerClient.ethSendTransaction(user.zkEvm.ethAddress, signedTransactions);
8624
8599
  const retrieveRelayerTransaction = async () => {
8625
8600
  const tx = await relayerClient.imGetTransactionByHash(relayerId);
@@ -8659,7 +8634,8 @@ class ZkEvmProvider {
8659
8634
  relayerClient;
8660
8635
  magicProvider; // Used for signing
8661
8636
  user;
8662
- constructor({ authManager, magicAdapter, config, confirmationScreen, multiRollupApiClients, }) {
8637
+ isPassport = true;
8638
+ constructor({ authManager, magicAdapter, config, confirmationScreen, multiRollupApiClients, passportEventEmitter, }) {
8663
8639
  this.authManager = authManager;
8664
8640
  this.magicAdapter = magicAdapter;
8665
8641
  this.config = config;
@@ -8670,8 +8646,18 @@ class ZkEvmProvider {
8670
8646
  this.jsonRpcProvider = new JsonRpcProvider(this.config.zkEvmRpcUrl);
8671
8647
  this.multiRollupApiClients = multiRollupApiClients;
8672
8648
  this.eventEmitter = new TypedEventEmitter();
8649
+ passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.handleLogout);
8673
8650
  }
8674
- isPassport = true;
8651
+ handleLogout = () => {
8652
+ const shouldEmitAccountsChanged = this.isLoggedIn();
8653
+ this.magicProvider = undefined;
8654
+ this.user = undefined;
8655
+ this.relayerClient = undefined;
8656
+ this.guardianClient = undefined;
8657
+ if (shouldEmitAccountsChanged) {
8658
+ this.eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, []);
8659
+ }
8660
+ };
8675
8661
  isLoggedIn() {
8676
8662
  return this.magicProvider !== undefined
8677
8663
  && this.user !== undefined
@@ -8694,13 +8680,19 @@ class ZkEvmProvider {
8694
8680
  this.magicProvider = magicProvider;
8695
8681
  this.relayerClient = new RelayerClient({
8696
8682
  config: this.config,
8683
+ jsonRpcProvider: this.jsonRpcProvider,
8697
8684
  user: this.user,
8698
8685
  });
8699
8686
  this.guardianClient = new GuardianClient({
8700
- imxPublicApiDomain: this.config.imxPublicApiDomain,
8701
8687
  accessToken: this.user.accessToken,
8702
8688
  confirmationScreen: this.confirmationScreen,
8703
8689
  imxEtherAddress: this.user.zkEvm.ethAddress,
8690
+ config: new PassportConfiguration({
8691
+ baseConfig: {},
8692
+ clientId: 'client123',
8693
+ logoutRedirectUri: 'http://localhost:3000/logout',
8694
+ redirectUri: 'http://localhost:3000/redirect',
8695
+ }),
8704
8696
  });
8705
8697
  this.eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, [this.user.zkEvm.ethAddress]);
8706
8698
  return [this.user.zkEvm.ethAddress];
@@ -8714,7 +8706,6 @@ class ZkEvmProvider {
8714
8706
  magicProvider: this.magicProvider,
8715
8707
  guardianClient: this.guardianClient,
8716
8708
  jsonRpcProvider: this.jsonRpcProvider,
8717
- config: this.config,
8718
8709
  relayerClient: this.relayerClient,
8719
8710
  user: this.user,
8720
8711
  });
@@ -8846,8 +8837,9 @@ class Passport {
8846
8837
  confirmationScreen;
8847
8838
  immutableXClient;
8848
8839
  magicAdapter;
8849
- passportImxProviderFactory;
8850
8840
  multiRollupApiClients;
8841
+ passportImxProviderFactory;
8842
+ passportEventEmitter;
8851
8843
  constructor(passportModuleConfiguration) {
8852
8844
  this.config = new PassportConfiguration(passportModuleConfiguration);
8853
8845
  this.authManager = new AuthManager(this.config);
@@ -8858,12 +8850,14 @@ class Passport {
8858
8850
  baseConfig: passportModuleConfiguration.baseConfig,
8859
8851
  });
8860
8852
  this.multiRollupApiClients = new MultiRollupApiClients(this.config.multiRollupConfig);
8853
+ this.passportEventEmitter = new TypedEventEmitter();
8861
8854
  this.passportImxProviderFactory = new PassportImxProviderFactory({
8862
8855
  authManager: this.authManager,
8863
8856
  config: this.config,
8864
8857
  confirmationScreen: this.confirmationScreen,
8865
8858
  immutableXClient: this.immutableXClient,
8866
8859
  magicAdapter: this.magicAdapter,
8860
+ passportEventEmitter: this.passportEventEmitter,
8867
8861
  });
8868
8862
  }
8869
8863
  async connectImxSilent() {
@@ -8898,6 +8892,7 @@ class Passport {
8898
8892
  throw new Error('EVM is not supported on production network');
8899
8893
  }
8900
8894
  return new ZkEvmProvider({
8895
+ passportEventEmitter: this.passportEventEmitter,
8901
8896
  authManager: this.authManager,
8902
8897
  magicAdapter: this.magicAdapter,
8903
8898
  config: this.config,
@@ -8909,7 +8904,10 @@ class Passport {
8909
8904
  return this.authManager.loginCallback();
8910
8905
  }
8911
8906
  async logout() {
8912
- return this.authManager.logout();
8907
+ await this.authManager.logout();
8908
+ // Code after this point is only executed if the logout mode is silent
8909
+ await this.magicAdapter.logout();
8910
+ this.passportEventEmitter.emit(PassportEvents.LOGGED_OUT);
8913
8911
  }
8914
8912
  /**
8915
8913
  * This method should only be called from the logout redirect uri
@@ -9472,6 +9470,9 @@ var Fee;
9472
9470
  (function (Fee) {
9473
9471
  (function (fee_type) {
9474
9472
  fee_type["ROYALTY"] = "ROYALTY";
9473
+ fee_type["MAKER_MARKETPLACE"] = "MAKER_MARKETPLACE";
9474
+ fee_type["TAKER_MARKETPLACE"] = "TAKER_MARKETPLACE";
9475
+ fee_type["PROTOCOL"] = "PROTOCOL";
9475
9476
  })(Fee.fee_type || (Fee.fee_type = {}));
9476
9477
  })(Fee || (Fee = {}));
9477
9478
 
@@ -9625,8 +9626,7 @@ function mapImmutableOrderToSeaportOrderComponents(order, counter, zoneAddress)
9625
9626
  }
9626
9627
  });
9627
9628
  const fees = order.fees.map((fee) => ({
9628
- startAmount: fee.amount,
9629
- endAmount: fee.amount,
9629
+ amount: fee.amount,
9630
9630
  itemType: order.buy[0].item_type === 'ERC20' ? ItemType.ERC20 : ItemType.NATIVE,
9631
9631
  recipient: fee.recipient,
9632
9632
  token: order.buy[0].item_type === 'ERC20'
@@ -9635,27 +9635,31 @@ function mapImmutableOrderToSeaportOrderComponents(order, counter, zoneAddress)
9635
9635
  identifierOrCriteria: '0',
9636
9636
  }));
9637
9637
  return {
9638
- conduitKey: constants$1.HashZero,
9639
- consideration: [...considerationItems, ...fees],
9640
- offer: order.sell.map((sellItem) => {
9641
- const erc721Item = sellItem;
9642
- return {
9643
- startAmount: '1',
9644
- endAmount: '1',
9645
- itemType: ItemType.ERC721,
9646
- token: erc721Item.contract_address,
9647
- identifierOrCriteria: erc721Item.token_id,
9648
- };
9649
- }),
9650
- counter,
9651
- endTime: Math.round(new Date(order.end_time).getTime() / 1000).toString(),
9652
- startTime: Math.round(new Date(order.start_time).getTime() / 1000).toString(),
9653
- salt: order.salt,
9654
- offerer: order.account_address,
9655
- zone: zoneAddress,
9656
- totalOriginalConsiderationItems: 2,
9657
- orderType: OrderType.FULL_RESTRICTED,
9658
- zoneHash: constants$1.HashZero,
9638
+ orderComponents: {
9639
+ conduitKey: constants$1.HashZero,
9640
+ consideration: [...considerationItems],
9641
+ offer: order.sell.map((sellItem) => {
9642
+ const erc721Item = sellItem;
9643
+ return {
9644
+ startAmount: '1',
9645
+ endAmount: '1',
9646
+ itemType: ItemType.ERC721,
9647
+ token: erc721Item.contract_address,
9648
+ identifierOrCriteria: erc721Item.token_id,
9649
+ };
9650
+ }),
9651
+ counter,
9652
+ endTime: Math.round(new Date(order.end_time).getTime() / 1000).toString(),
9653
+ startTime: Math.round(new Date(order.start_time).getTime() / 1000).toString(),
9654
+ salt: order.salt,
9655
+ offerer: order.account_address,
9656
+ zone: zoneAddress,
9657
+ // this should be the fee exclusive number of items the user signed for
9658
+ totalOriginalConsiderationItems: considerationItems.length,
9659
+ orderType: OrderType.FULL_RESTRICTED,
9660
+ zoneHash: constants$1.HashZero,
9661
+ },
9662
+ tips: fees,
9659
9663
  };
9660
9664
  }
9661
9665
 
@@ -9670,11 +9674,10 @@ class Seaport {
9670
9674
  this.seaportContractAddress = seaportContractAddress;
9671
9675
  this.zoneContractAddress = zoneContractAddress;
9672
9676
  }
9673
- async prepareSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry) {
9674
- const { actions: seaportActions } = await this.createSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry);
9677
+ async prepareSeaportOrder(offerer, listingItem, considerationItem, orderStart, orderExpiry) {
9678
+ const { actions: seaportActions } = await this.createSeaportOrder(offerer, listingItem, considerationItem, orderStart, orderExpiry);
9675
9679
  const listingActions = [];
9676
- const approvalAction = seaportActions
9677
- .find((action) => action.type === 'approval');
9680
+ const approvalAction = seaportActions.find((action) => action.type === 'approval');
9678
9681
  if (approvalAction) {
9679
9682
  listingActions.push({
9680
9683
  type: ActionType.TRANSACTION,
@@ -9682,8 +9685,7 @@ class Seaport {
9682
9685
  buildTransaction: prepareTransaction(approvalAction.transactionMethods),
9683
9686
  });
9684
9687
  }
9685
- const createAction = seaportActions
9686
- .find((action) => action.type === 'create');
9688
+ const createAction = seaportActions.find((action) => action.type === 'create');
9687
9689
  if (!createAction) {
9688
9690
  throw new Error('No create order action found');
9689
9691
  }
@@ -9701,21 +9703,23 @@ class Seaport {
9701
9703
  };
9702
9704
  }
9703
9705
  async fulfillOrder(order, account, extraData) {
9704
- const orderComponents = await this.mapImmutableOrderToSeaportOrderComponents(order);
9706
+ const { orderComponents, tips } = this.mapImmutableOrderToSeaportOrderComponents(order);
9705
9707
  const seaportLib = this.getSeaportLib(order);
9706
9708
  const { actions: seaportActions } = await seaportLib.fulfillOrders({
9707
9709
  accountAddress: account,
9708
- fulfillOrderDetails: [{
9710
+ fulfillOrderDetails: [
9711
+ {
9709
9712
  order: {
9710
9713
  parameters: orderComponents,
9711
9714
  signature: order.signature,
9712
9715
  },
9713
9716
  extraData,
9714
- }],
9717
+ tips,
9718
+ },
9719
+ ],
9715
9720
  });
9716
9721
  const fulfillmentActions = [];
9717
- const approvalAction = seaportActions
9718
- .find((action) => action.type === 'approval');
9722
+ const approvalAction = seaportActions.find((action) => action.type === 'approval');
9719
9723
  if (approvalAction) {
9720
9724
  fulfillmentActions.push({
9721
9725
  type: ActionType.TRANSACTION,
@@ -9723,8 +9727,7 @@ class Seaport {
9723
9727
  purpose: TransactionPurpose.APPROVAL,
9724
9728
  });
9725
9729
  }
9726
- const fulfilOrderAction = seaportActions
9727
- .find((action) => action.type === 'exchange');
9730
+ const fulfilOrderAction = seaportActions.find((action) => action.type === 'exchange');
9728
9731
  if (!fulfilOrderAction) {
9729
9732
  throw new Error('No exchange action found');
9730
9733
  }
@@ -9736,7 +9739,7 @@ class Seaport {
9736
9739
  return { actions: fulfillmentActions };
9737
9740
  }
9738
9741
  async cancelOrder(order, account) {
9739
- const orderComponents = await this.mapImmutableOrderToSeaportOrderComponents(order);
9742
+ const { orderComponents } = this.mapImmutableOrderToSeaportOrderComponents(order);
9740
9743
  const seaportLib = this.getSeaportLib(order);
9741
9744
  const cancellationTransaction = await seaportLib.cancelOrders([orderComponents], account);
9742
9745
  return prepareTransaction(cancellationTransaction)();
@@ -9745,7 +9748,7 @@ class Seaport {
9745
9748
  const orderCounter = order.protocol_data.counter;
9746
9749
  return mapImmutableOrderToSeaportOrderComponents(order, orderCounter, this.zoneContractAddress);
9747
9750
  }
9748
- createSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry) {
9751
+ createSeaportOrder(offerer, listingItem, considerationItem, orderStart, orderExpiry) {
9749
9752
  const seaportLib = this.getSeaportLib();
9750
9753
  return seaportLib.createOrder({
9751
9754
  allowPartialFills: false,
@@ -9758,15 +9761,12 @@ class Seaport {
9758
9761
  ],
9759
9762
  consideration: [
9760
9763
  {
9761
- token: considerationItem.type === 'ERC20' ? considerationItem.contractAddress : undefined,
9764
+ token: considerationItem.type === 'ERC20'
9765
+ ? considerationItem.contractAddress
9766
+ : undefined,
9762
9767
  amount: considerationItem.amount,
9763
9768
  recipient: offerer,
9764
9769
  },
9765
- {
9766
- token: considerationItem.type === 'ERC20' ? considerationItem.contractAddress : undefined,
9767
- amount: royaltyInfo.amountRequired,
9768
- recipient: royaltyInfo.recipient,
9769
- },
9770
9770
  ],
9771
9771
  startTime: (orderStart.getTime() / 1000).toFixed(0),
9772
9772
  endTime: (orderExpiry.getTime() / 1000).toFixed(0),
@@ -9825,7 +9825,7 @@ class ImmutableApiClient {
9825
9825
  ...listOrderParams,
9826
9826
  });
9827
9827
  }
9828
- async createListing({ orderHash, orderComponents, orderSignature, }) {
9828
+ async createListing({ orderHash, orderComponents, orderSignature, makerFee, }) {
9829
9829
  if (orderComponents.offer.length !== 1) {
9830
9830
  throw new Error('Only one item can be listed at a time');
9831
9831
  }
@@ -9854,15 +9854,7 @@ class ImmutableApiClient {
9854
9854
  contract_address: orderComponents.consideration[0].token,
9855
9855
  },
9856
9856
  ],
9857
- fees: orderComponents.consideration.length > 1
9858
- ? [
9859
- {
9860
- amount: orderComponents.consideration[1].startAmount,
9861
- recipient: orderComponents.consideration[1].recipient,
9862
- fee_type: Fee.fee_type.ROYALTY,
9863
- },
9864
- ]
9865
- : [],
9857
+ fees: makerFee ? [makerFee] : [],
9866
9858
  end_time: new Date(parseInt(`${orderComponents.endTime.toString()}000`, 10)).toISOString(),
9867
9859
  protocol_data: {
9868
9860
  order_type: CreateOrderProtocolData.order_type.FULL_RESTRICTED,
@@ -9929,945 +9921,23 @@ function getOrderbookConfig(environment) {
9929
9921
  }
9930
9922
  }
9931
9923
 
9932
- class ERC721 {
9933
- erc721;
9934
- constructor(erc721) {
9935
- this.erc721 = erc721;
9924
+ class SeaportLibFactory {
9925
+ defaultSeaportContractAddress;
9926
+ provider;
9927
+ constructor(defaultSeaportContractAddress, provider) {
9928
+ this.defaultSeaportContractAddress = defaultSeaportContractAddress;
9929
+ this.provider = provider;
9936
9930
  }
9937
- async royaltyInfo(tokenId, salePrice) {
9938
- const [recipient, royaltyRequired] = await this.erc721.royaltyInfo(tokenId, salePrice);
9939
- return { recipient, amountRequired: royaltyRequired.toString() };
9940
- }
9941
- }
9942
-
9943
- /* Autogenerated file. Do not edit manually. */
9944
- /* tslint:disable */
9945
- /* eslint-disable */
9946
- const _abi$5 = [
9947
- {
9948
- inputs: [
9949
- {
9950
- internalType: "address",
9951
- name: "owner_",
9952
- type: "address",
9953
- },
9954
- {
9955
- internalType: "string",
9956
- name: "name_",
9957
- type: "string",
9958
- },
9959
- {
9960
- internalType: "string",
9961
- name: "symbol_",
9962
- type: "string",
9963
- },
9964
- {
9965
- internalType: "string",
9966
- name: "baseURI_",
9967
- type: "string",
9968
- },
9969
- {
9970
- internalType: "string",
9971
- name: "contractURI_",
9972
- type: "string",
9973
- },
9974
- {
9975
- internalType: "address",
9976
- name: "_receiver",
9977
- type: "address",
9978
- },
9979
- {
9980
- internalType: "uint96",
9981
- name: "_feeNumerator",
9982
- type: "uint96",
9983
- },
9984
- ],
9985
- stateMutability: "nonpayable",
9986
- type: "constructor",
9987
- },
9988
- {
9989
- inputs: [
9990
- {
9991
- internalType: "address",
9992
- name: "target",
9993
- type: "address",
9994
- },
9995
- ],
9996
- name: "ApproveTargetNotInAllowlist",
9997
- type: "error",
9998
- },
9999
- {
10000
- inputs: [
10001
- {
10002
- internalType: "address",
10003
- name: "caller",
10004
- type: "address",
10005
- },
10006
- ],
10007
- name: "CallerNotInAllowlist",
10008
- type: "error",
10009
- },
10010
- {
10011
- anonymous: false,
10012
- inputs: [
10013
- {
10014
- indexed: true,
10015
- internalType: "address",
10016
- name: "owner",
10017
- type: "address",
10018
- },
10019
- {
10020
- indexed: true,
10021
- internalType: "address",
10022
- name: "approved",
10023
- type: "address",
10024
- },
10025
- {
10026
- indexed: true,
10027
- internalType: "uint256",
10028
- name: "tokenId",
10029
- type: "uint256",
10030
- },
10031
- ],
10032
- name: "Approval",
10033
- type: "event",
10034
- },
10035
- {
10036
- anonymous: false,
10037
- inputs: [
10038
- {
10039
- indexed: true,
10040
- internalType: "address",
10041
- name: "owner",
10042
- type: "address",
10043
- },
10044
- {
10045
- indexed: true,
10046
- internalType: "address",
10047
- name: "operator",
10048
- type: "address",
10049
- },
10050
- {
10051
- indexed: false,
10052
- internalType: "bool",
10053
- name: "approved",
10054
- type: "bool",
10055
- },
10056
- ],
10057
- name: "ApprovalForAll",
10058
- type: "event",
10059
- },
10060
- {
10061
- anonymous: false,
10062
- inputs: [
10063
- {
10064
- indexed: true,
10065
- internalType: "bytes32",
10066
- name: "role",
10067
- type: "bytes32",
10068
- },
10069
- {
10070
- indexed: true,
10071
- internalType: "bytes32",
10072
- name: "previousAdminRole",
10073
- type: "bytes32",
10074
- },
10075
- {
10076
- indexed: true,
10077
- internalType: "bytes32",
10078
- name: "newAdminRole",
10079
- type: "bytes32",
10080
- },
10081
- ],
10082
- name: "RoleAdminChanged",
10083
- type: "event",
10084
- },
10085
- {
10086
- anonymous: false,
10087
- inputs: [
10088
- {
10089
- indexed: true,
10090
- internalType: "bytes32",
10091
- name: "role",
10092
- type: "bytes32",
10093
- },
10094
- {
10095
- indexed: true,
10096
- internalType: "address",
10097
- name: "account",
10098
- type: "address",
10099
- },
10100
- {
10101
- indexed: true,
10102
- internalType: "address",
10103
- name: "sender",
10104
- type: "address",
10105
- },
10106
- ],
10107
- name: "RoleGranted",
10108
- type: "event",
10109
- },
10110
- {
10111
- anonymous: false,
10112
- inputs: [
10113
- {
10114
- indexed: true,
10115
- internalType: "bytes32",
10116
- name: "role",
10117
- type: "bytes32",
10118
- },
10119
- {
10120
- indexed: true,
10121
- internalType: "address",
10122
- name: "account",
10123
- type: "address",
10124
- },
10125
- {
10126
- indexed: true,
10127
- internalType: "address",
10128
- name: "sender",
10129
- type: "address",
10130
- },
10131
- ],
10132
- name: "RoleRevoked",
10133
- type: "event",
10134
- },
10135
- {
10136
- anonymous: false,
10137
- inputs: [
10138
- {
10139
- indexed: false,
10140
- internalType: "address",
10141
- name: "oldRegistry",
10142
- type: "address",
10143
- },
10144
- {
10145
- indexed: false,
10146
- internalType: "address",
10147
- name: "newRegistry",
10148
- type: "address",
10149
- },
10150
- ],
10151
- name: "RoyaltytAllowlistRegistryUpdated",
10152
- type: "event",
10153
- },
10154
- {
10155
- anonymous: false,
10156
- inputs: [
10157
- {
10158
- indexed: true,
10159
- internalType: "address",
10160
- name: "from",
10161
- type: "address",
10162
- },
10163
- {
10164
- indexed: true,
10165
- internalType: "address",
10166
- name: "to",
10167
- type: "address",
10168
- },
10169
- {
10170
- indexed: true,
10171
- internalType: "uint256",
10172
- name: "tokenId",
10173
- type: "uint256",
10174
- },
10175
- ],
10176
- name: "Transfer",
10177
- type: "event",
10178
- },
10179
- {
10180
- inputs: [],
10181
- name: "DEFAULT_ADMIN_ROLE",
10182
- outputs: [
10183
- {
10184
- internalType: "bytes32",
10185
- name: "",
10186
- type: "bytes32",
10187
- },
10188
- ],
10189
- stateMutability: "view",
10190
- type: "function",
10191
- },
10192
- {
10193
- inputs: [],
10194
- name: "MINTER_ROLE",
10195
- outputs: [
10196
- {
10197
- internalType: "bytes32",
10198
- name: "",
10199
- type: "bytes32",
10200
- },
10201
- ],
10202
- stateMutability: "view",
10203
- type: "function",
10204
- },
10205
- {
10206
- inputs: [
10207
- {
10208
- internalType: "address",
10209
- name: "to",
10210
- type: "address",
10211
- },
10212
- {
10213
- internalType: "uint256",
10214
- name: "tokenId",
10215
- type: "uint256",
10216
- },
10217
- ],
10218
- name: "approve",
10219
- outputs: [],
10220
- stateMutability: "nonpayable",
10221
- type: "function",
10222
- },
10223
- {
10224
- inputs: [
10225
- {
10226
- internalType: "address",
10227
- name: "owner",
10228
- type: "address",
10229
- },
10230
- ],
10231
- name: "balanceOf",
10232
- outputs: [
10233
- {
10234
- internalType: "uint256",
10235
- name: "",
10236
- type: "uint256",
10237
- },
10238
- ],
10239
- stateMutability: "view",
10240
- type: "function",
10241
- },
10242
- {
10243
- inputs: [],
10244
- name: "baseURI",
10245
- outputs: [
10246
- {
10247
- internalType: "string",
10248
- name: "",
10249
- type: "string",
10250
- },
10251
- ],
10252
- stateMutability: "view",
10253
- type: "function",
10254
- },
10255
- {
10256
- inputs: [
10257
- {
10258
- internalType: "uint256",
10259
- name: "tokenId",
10260
- type: "uint256",
10261
- },
10262
- ],
10263
- name: "burn",
10264
- outputs: [],
10265
- stateMutability: "nonpayable",
10266
- type: "function",
10267
- },
10268
- {
10269
- inputs: [],
10270
- name: "contractURI",
10271
- outputs: [
10272
- {
10273
- internalType: "string",
10274
- name: "",
10275
- type: "string",
10276
- },
10277
- ],
10278
- stateMutability: "view",
10279
- type: "function",
10280
- },
10281
- {
10282
- inputs: [],
10283
- name: "getAdmins",
10284
- outputs: [
10285
- {
10286
- internalType: "address[]",
10287
- name: "",
10288
- type: "address[]",
10289
- },
10290
- ],
10291
- stateMutability: "view",
10292
- type: "function",
10293
- },
10294
- {
10295
- inputs: [
10296
- {
10297
- internalType: "uint256",
10298
- name: "tokenId",
10299
- type: "uint256",
10300
- },
10301
- ],
10302
- name: "getApproved",
10303
- outputs: [
10304
- {
10305
- internalType: "address",
10306
- name: "",
10307
- type: "address",
10308
- },
10309
- ],
10310
- stateMutability: "view",
10311
- type: "function",
10312
- },
10313
- {
10314
- inputs: [
10315
- {
10316
- internalType: "bytes32",
10317
- name: "role",
10318
- type: "bytes32",
10319
- },
10320
- ],
10321
- name: "getRoleAdmin",
10322
- outputs: [
10323
- {
10324
- internalType: "bytes32",
10325
- name: "",
10326
- type: "bytes32",
10327
- },
10328
- ],
10329
- stateMutability: "view",
10330
- type: "function",
10331
- },
10332
- {
10333
- inputs: [
10334
- {
10335
- internalType: "bytes32",
10336
- name: "role",
10337
- type: "bytes32",
10338
- },
10339
- {
10340
- internalType: "uint256",
10341
- name: "index",
10342
- type: "uint256",
10343
- },
10344
- ],
10345
- name: "getRoleMember",
10346
- outputs: [
10347
- {
10348
- internalType: "address",
10349
- name: "",
10350
- type: "address",
10351
- },
10352
- ],
10353
- stateMutability: "view",
10354
- type: "function",
10355
- },
10356
- {
10357
- inputs: [
10358
- {
10359
- internalType: "bytes32",
10360
- name: "role",
10361
- type: "bytes32",
10362
- },
10363
- ],
10364
- name: "getRoleMemberCount",
10365
- outputs: [
10366
- {
10367
- internalType: "uint256",
10368
- name: "",
10369
- type: "uint256",
10370
- },
10371
- ],
10372
- stateMutability: "view",
10373
- type: "function",
10374
- },
10375
- {
10376
- inputs: [
10377
- {
10378
- internalType: "address",
10379
- name: "user",
10380
- type: "address",
10381
- },
10382
- ],
10383
- name: "grantMinterRole",
10384
- outputs: [],
10385
- stateMutability: "nonpayable",
10386
- type: "function",
10387
- },
10388
- {
10389
- inputs: [
10390
- {
10391
- internalType: "bytes32",
10392
- name: "role",
10393
- type: "bytes32",
10394
- },
10395
- {
10396
- internalType: "address",
10397
- name: "account",
10398
- type: "address",
10399
- },
10400
- ],
10401
- name: "grantRole",
10402
- outputs: [],
10403
- stateMutability: "nonpayable",
10404
- type: "function",
10405
- },
10406
- {
10407
- inputs: [
10408
- {
10409
- internalType: "bytes32",
10410
- name: "role",
10411
- type: "bytes32",
10412
- },
10413
- {
10414
- internalType: "address",
10415
- name: "account",
10416
- type: "address",
10417
- },
10418
- ],
10419
- name: "hasRole",
10420
- outputs: [
10421
- {
10422
- internalType: "bool",
10423
- name: "",
10424
- type: "bool",
10425
- },
10426
- ],
10427
- stateMutability: "view",
10428
- type: "function",
10429
- },
10430
- {
10431
- inputs: [
10432
- {
10433
- internalType: "address",
10434
- name: "owner",
10435
- type: "address",
10436
- },
10437
- {
10438
- internalType: "address",
10439
- name: "operator",
10440
- type: "address",
10441
- },
10442
- ],
10443
- name: "isApprovedForAll",
10444
- outputs: [
10445
- {
10446
- internalType: "bool",
10447
- name: "",
10448
- type: "bool",
10449
- },
10450
- ],
10451
- stateMutability: "view",
10452
- type: "function",
10453
- },
10454
- {
10455
- inputs: [
10456
- {
10457
- internalType: "address",
10458
- name: "to",
10459
- type: "address",
10460
- },
10461
- {
10462
- internalType: "uint256",
10463
- name: "amount",
10464
- type: "uint256",
10465
- },
10466
- ],
10467
- name: "mint",
10468
- outputs: [],
10469
- stateMutability: "nonpayable",
10470
- type: "function",
10471
- },
10472
- {
10473
- inputs: [],
10474
- name: "name",
10475
- outputs: [
10476
- {
10477
- internalType: "string",
10478
- name: "",
10479
- type: "string",
10480
- },
10481
- ],
10482
- stateMutability: "view",
10483
- type: "function",
10484
- },
10485
- {
10486
- inputs: [
10487
- {
10488
- internalType: "uint256",
10489
- name: "tokenId",
10490
- type: "uint256",
10491
- },
10492
- ],
10493
- name: "ownerOf",
10494
- outputs: [
10495
- {
10496
- internalType: "address",
10497
- name: "",
10498
- type: "address",
10499
- },
10500
- ],
10501
- stateMutability: "view",
10502
- type: "function",
10503
- },
10504
- {
10505
- inputs: [
10506
- {
10507
- internalType: "bytes32",
10508
- name: "role",
10509
- type: "bytes32",
10510
- },
10511
- {
10512
- internalType: "address",
10513
- name: "account",
10514
- type: "address",
10515
- },
10516
- ],
10517
- name: "renounceRole",
10518
- outputs: [],
10519
- stateMutability: "nonpayable",
10520
- type: "function",
10521
- },
10522
- {
10523
- inputs: [
10524
- {
10525
- internalType: "address",
10526
- name: "user",
10527
- type: "address",
10528
- },
10529
- ],
10530
- name: "revokeMinterRole",
10531
- outputs: [],
10532
- stateMutability: "nonpayable",
10533
- type: "function",
10534
- },
10535
- {
10536
- inputs: [
10537
- {
10538
- internalType: "bytes32",
10539
- name: "role",
10540
- type: "bytes32",
10541
- },
10542
- {
10543
- internalType: "address",
10544
- name: "account",
10545
- type: "address",
10546
- },
10547
- ],
10548
- name: "revokeRole",
10549
- outputs: [],
10550
- stateMutability: "nonpayable",
10551
- type: "function",
10552
- },
10553
- {
10554
- inputs: [],
10555
- name: "royaltyAllowlist",
10556
- outputs: [
10557
- {
10558
- internalType: "contract IRoyaltyAllowlist",
10559
- name: "",
10560
- type: "address",
10561
- },
10562
- ],
10563
- stateMutability: "view",
10564
- type: "function",
10565
- },
10566
- {
10567
- inputs: [
10568
- {
10569
- internalType: "uint256",
10570
- name: "_tokenId",
10571
- type: "uint256",
10572
- },
10573
- {
10574
- internalType: "uint256",
10575
- name: "_salePrice",
10576
- type: "uint256",
10577
- },
10578
- ],
10579
- name: "royaltyInfo",
10580
- outputs: [
10581
- {
10582
- internalType: "address",
10583
- name: "",
10584
- type: "address",
10585
- },
10586
- {
10587
- internalType: "uint256",
10588
- name: "",
10589
- type: "uint256",
10590
- },
10591
- ],
10592
- stateMutability: "view",
10593
- type: "function",
10594
- },
10595
- {
10596
- inputs: [
10597
- {
10598
- internalType: "address",
10599
- name: "from",
10600
- type: "address",
10601
- },
10602
- {
10603
- internalType: "address",
10604
- name: "to",
10605
- type: "address",
10606
- },
10607
- {
10608
- internalType: "uint256",
10609
- name: "tokenId",
10610
- type: "uint256",
10611
- },
10612
- ],
10613
- name: "safeTransferFrom",
10614
- outputs: [],
10615
- stateMutability: "nonpayable",
10616
- type: "function",
10617
- },
10618
- {
10619
- inputs: [
10620
- {
10621
- internalType: "address",
10622
- name: "from",
10623
- type: "address",
10624
- },
10625
- {
10626
- internalType: "address",
10627
- name: "to",
10628
- type: "address",
10629
- },
10630
- {
10631
- internalType: "uint256",
10632
- name: "tokenId",
10633
- type: "uint256",
10634
- },
10635
- {
10636
- internalType: "bytes",
10637
- name: "data",
10638
- type: "bytes",
10639
- },
10640
- ],
10641
- name: "safeTransferFrom",
10642
- outputs: [],
10643
- stateMutability: "nonpayable",
10644
- type: "function",
10645
- },
10646
- {
10647
- inputs: [
10648
- {
10649
- internalType: "address",
10650
- name: "operator",
10651
- type: "address",
10652
- },
10653
- {
10654
- internalType: "bool",
10655
- name: "approved",
10656
- type: "bool",
10657
- },
10658
- ],
10659
- name: "setApprovalForAll",
10660
- outputs: [],
10661
- stateMutability: "nonpayable",
10662
- type: "function",
10663
- },
10664
- {
10665
- inputs: [
10666
- {
10667
- internalType: "string",
10668
- name: "baseURI_",
10669
- type: "string",
10670
- },
10671
- ],
10672
- name: "setBaseURI",
10673
- outputs: [],
10674
- stateMutability: "nonpayable",
10675
- type: "function",
10676
- },
10677
- {
10678
- inputs: [
10679
- {
10680
- internalType: "string",
10681
- name: "_contractURI",
10682
- type: "string",
10683
- },
10684
- ],
10685
- name: "setContractURI",
10686
- outputs: [],
10687
- stateMutability: "nonpayable",
10688
- type: "function",
10689
- },
10690
- {
10691
- inputs: [
10692
- {
10693
- internalType: "address",
10694
- name: "_royaltyAllowlist",
10695
- type: "address",
10696
- },
10697
- ],
10698
- name: "setRoyaltyAllowlistRegistry",
10699
- outputs: [],
10700
- stateMutability: "nonpayable",
10701
- type: "function",
10702
- },
10703
- {
10704
- inputs: [
10705
- {
10706
- internalType: "bytes4",
10707
- name: "interfaceId",
10708
- type: "bytes4",
10709
- },
10710
- ],
10711
- name: "supportsInterface",
10712
- outputs: [
10713
- {
10714
- internalType: "bool",
10715
- name: "",
10716
- type: "bool",
10717
- },
10718
- ],
10719
- stateMutability: "view",
10720
- type: "function",
10721
- },
10722
- {
10723
- inputs: [],
10724
- name: "symbol",
10725
- outputs: [
10726
- {
10727
- internalType: "string",
10728
- name: "",
10729
- type: "string",
10730
- },
10731
- ],
10732
- stateMutability: "view",
10733
- type: "function",
10734
- },
10735
- {
10736
- inputs: [
10737
- {
10738
- internalType: "uint256",
10739
- name: "index",
10740
- type: "uint256",
10741
- },
10742
- ],
10743
- name: "tokenByIndex",
10744
- outputs: [
10745
- {
10746
- internalType: "uint256",
10747
- name: "",
10748
- type: "uint256",
10749
- },
10750
- ],
10751
- stateMutability: "view",
10752
- type: "function",
10753
- },
10754
- {
10755
- inputs: [
10756
- {
10757
- internalType: "address",
10758
- name: "owner",
10759
- type: "address",
10760
- },
10761
- {
10762
- internalType: "uint256",
10763
- name: "index",
10764
- type: "uint256",
10765
- },
10766
- ],
10767
- name: "tokenOfOwnerByIndex",
10768
- outputs: [
10769
- {
10770
- internalType: "uint256",
10771
- name: "",
10772
- type: "uint256",
10773
- },
10774
- ],
10775
- stateMutability: "view",
10776
- type: "function",
10777
- },
10778
- {
10779
- inputs: [
10780
- {
10781
- internalType: "uint256",
10782
- name: "tokenId",
10783
- type: "uint256",
10784
- },
10785
- ],
10786
- name: "tokenURI",
10787
- outputs: [
10788
- {
10789
- internalType: "string",
10790
- name: "",
10791
- type: "string",
10792
- },
10793
- ],
10794
- stateMutability: "view",
10795
- type: "function",
10796
- },
10797
- {
10798
- inputs: [],
10799
- name: "totalSupply",
10800
- outputs: [
10801
- {
10802
- internalType: "uint256",
10803
- name: "",
10804
- type: "uint256",
10805
- },
10806
- ],
10807
- stateMutability: "view",
10808
- type: "function",
10809
- },
10810
- {
10811
- inputs: [
10812
- {
10813
- internalType: "address",
10814
- name: "from",
10815
- type: "address",
10816
- },
10817
- {
10818
- internalType: "address",
10819
- name: "to",
10820
- type: "address",
10821
- },
10822
- {
10823
- internalType: "uint256",
10824
- name: "tokenId",
10825
- type: "uint256",
10826
- },
10827
- ],
10828
- name: "transferFrom",
10829
- outputs: [],
10830
- stateMutability: "nonpayable",
10831
- type: "function",
10832
- },
10833
- ];
10834
- class ImmutableERC721Base__factory {
10835
- static abi = _abi$5;
10836
- static createInterface() {
10837
- return new utils$1.Interface(_abi$5);
10838
- }
10839
- static connect(address, signerOrProvider) {
10840
- return new Contract$1(address, _abi$5, signerOrProvider);
10841
- }
10842
- }
10843
-
10844
- class ERC721Factory {
10845
- erc721;
10846
- constructor(contractAddress, provider) {
10847
- this.erc721 = ImmutableERC721Base__factory.connect(contractAddress, provider);
10848
- }
10849
- create() {
10850
- return new ERC721(this.erc721);
10851
- }
10852
- }
10853
-
10854
- class SeaportLibFactory {
10855
- defaultSeaportContractAddress;
10856
- provider;
10857
- constructor(defaultSeaportContractAddress, provider) {
10858
- this.defaultSeaportContractAddress = defaultSeaportContractAddress;
10859
- this.provider = provider;
10860
- }
10861
- create(orderSeaportVersion, orderSeaportAddress) {
10862
- const seaportVersion = orderSeaportVersion ?? SEAPORT_CONTRACT_VERSION_V1_5;
10863
- const seaportContractAddress = orderSeaportAddress ?? this.defaultSeaportContractAddress;
10864
- return new Seaport$1(this.provider, {
10865
- seaportVersion,
10866
- balanceAndApprovalChecksOnOrderCreation: true,
10867
- overrides: {
10868
- contractAddress: seaportContractAddress,
10869
- },
10870
- });
9931
+ create(orderSeaportVersion, orderSeaportAddress) {
9932
+ const seaportVersion = orderSeaportVersion ?? SEAPORT_CONTRACT_VERSION_V1_5;
9933
+ const seaportContractAddress = orderSeaportAddress ?? this.defaultSeaportContractAddress;
9934
+ return new Seaport$1(this.provider, {
9935
+ seaportVersion,
9936
+ balanceAndApprovalChecksOnOrderCreation: true,
9937
+ overrides: {
9938
+ contractAddress: seaportContractAddress,
9939
+ },
9940
+ });
10871
9941
  }
10872
9942
  }
10873
9943
 
@@ -10916,8 +9986,8 @@ class Orderbook {
10916
9986
  /**
10917
9987
  * List orders. This method is used to get a list of orders filtered by conditions specified
10918
9988
  * in the params object.
10919
- * @param {ListOrderParams} listOrderParams - Filtering, ordering and page parameters.
10920
- * @return {Orders} The paged orders.
9989
+ * @param {ListListingsParams} listOrderParams - Filtering, ordering and page parameters.
9990
+ * @return {ListListingsResult} The paged orders.
10921
9991
  */
10922
9992
  listListings(listOrderParams) {
10923
9993
  return this.apiClient.listListings(listOrderParams);
@@ -10931,9 +10001,7 @@ class Orderbook {
10931
10001
  * the order components that can be submitted to `createListing` with a signature.
10932
10002
  */
10933
10003
  async prepareListing({ makerAddress, sell, buy, orderExpiry, }) {
10934
- const erc721 = new ERC721Factory(sell.contractAddress, this.orderbookConfig.provider).create();
10935
- const royaltyInfo = await erc721.royaltyInfo(sell.tokenId, buy.amount);
10936
- return this.seaport.prepareSeaportOrder(makerAddress, sell, buy, royaltyInfo,
10004
+ return this.seaport.prepareSeaportOrder(makerAddress, sell, buy,
10937
10005
  // Default order start to now
10938
10006
  new Date(),
10939
10007
  // Default order expiry to 2 years from now
@@ -10955,12 +10023,13 @@ class Orderbook {
10955
10023
  * @param {string} fulfillerAddress - The address of the account fulfilling the order.
10956
10024
  * @return {FulfillOrderResponse} Approval and fulfilment transactions.
10957
10025
  */
10958
- async fulfillOrder(listingId, takerAddress) {
10959
- const fulfillmentDataRes = await this.apiClient.fulfillmentData([{
10026
+ async fulfillOrder(listingId, takerAddress, takerFee) {
10027
+ const fulfillmentDataRes = await this.apiClient.fulfillmentData([
10028
+ {
10960
10029
  order_id: listingId,
10961
- // fee: takerFee,
10962
- fee: undefined,
10963
- }]);
10030
+ fee: takerFee,
10031
+ },
10032
+ ]);
10964
10033
  if (fulfillmentDataRes.result.length !== 1) {
10965
10034
  throw new Error('unexpected fulfillment data result length');
10966
10035
  }
@@ -27532,7 +26601,7 @@ function validateSecondaryFees(secondaryFees) {
27532
26601
  if (!isValidNonZeroAddress(secondaryFee.recipient)) {
27533
26602
  throw new InvalidConfigurationError(`Invalid secondary fee recipient address: ${secondaryFee.recipient}`);
27534
26603
  }
27535
- if (secondaryFee.basisPoints < 0 || secondaryFee.basisPoints > MAX_SECONDARY_FEE_BASIS_POINTS) {
26604
+ if (secondaryFee.basisPoints <= 0 || secondaryFee.basisPoints > MAX_SECONDARY_FEE_BASIS_POINTS) {
27536
26605
  throw new InvalidConfigurationError(`Invalid secondary fee basis points: ${secondaryFee.basisPoints}`);
27537
26606
  }
27538
26607
  totalSecondaryFeeBasisPoints += secondaryFee.basisPoints;
@@ -27664,93 +26733,34 @@ class Exchange {
27664
26733
  * @param {string} tokenInAddress Token address to sell.
27665
26734
  * @param {string} tokenOutAddress Token address to buy.
27666
26735
  * @param {ethers.BigNumberish} amountIn Amount to sell.
27667
- * @param {number} slippagePercent (optional) The percentage of slippage tolerance. Default = 0.1. Max = 50. Min = 0.
27668
- * @param {number} maxHops (optional) Maximum hops allowed in optimal route. Default is 2.
27669
- * @param {number} deadline (optional) Latest time swap can execute. Default is 15 minutes.
27670
- * @return {TransactionResponse} The result containing the unsigned transaction and details of the swap.
27671
- */
27672
- async getUnsignedSwapTxFromAmountIn(fromAddress, tokenInAddress, tokenOutAddress, amountIn, slippagePercent = DEFAULT_SLIPPAGE, maxHops = DEFAULT_MAX_HOPS, deadline = DEFAULT_DEADLINE) {
27673
- return await this.getUnsignedSwapTx(fromAddress, tokenInAddress, tokenOutAddress, ethers.BigNumber.from(amountIn), slippagePercent, maxHops, deadline, TradeType.EXACT_INPUT);
27674
- }
27675
- /**
27676
- * Get the unsigned swap transaction given the amount to buy.
27677
- * Includes quote details for the swap.
27678
- *
27679
- * @param {string} fromAddress The public address that will sign and submit the transaction.
27680
- * @param {string} tokenInAddress Token address to sell.
27681
- * @param {string} tokenOutAddress Token address to buy.
27682
- * @param {ethers.BigNumberish} amountOut Amount to buy.
27683
- * @param {number} slippagePercent (optional) The percentage of slippage tolerance. Default = 0.1. Max = 50. Min = 0.
27684
- * @param {number} maxHops (optional) Maximum hops allowed in optimal route. Default is 2.
27685
- * @param {number} deadline (optional) Latest time swap can execute. Default is 15 minutes.
27686
- * @return {TransactionResponse} The result containing the unsigned transaction and details of the swap.
27687
- */
27688
- async getUnsignedSwapTxFromAmountOut(fromAddress, tokenInAddress, tokenOutAddress, amountOut, slippagePercent = DEFAULT_SLIPPAGE, maxHops = DEFAULT_MAX_HOPS, deadline = DEFAULT_DEADLINE) {
27689
- return await this.getUnsignedSwapTx(fromAddress, tokenInAddress, tokenOutAddress, ethers.BigNumber.from(amountOut), slippagePercent, maxHops, deadline, TradeType.EXACT_OUTPUT);
27690
- }
27691
- }
27692
-
27693
- /* eslint-disable class-methods-use-this */
27694
-
27695
- const $762782b6c862d954$export$db5daa1b5156ccfe = [
27696
- {
27697
- constant: true,
27698
- inputs: [],
27699
- name: "name",
27700
- outputs: [
27701
- {
27702
- name: "",
27703
- type: "string"
27704
- }
27705
- ],
27706
- payable: false,
27707
- type: "function"
27708
- },
27709
- {
27710
- constant: true,
27711
- inputs: [],
27712
- name: "decimals",
27713
- outputs: [
27714
- {
27715
- name: "",
27716
- type: "uint8"
27717
- }
27718
- ],
27719
- payable: false,
27720
- type: "function"
27721
- },
27722
- {
27723
- constant: true,
27724
- inputs: [
27725
- {
27726
- name: "_owner",
27727
- type: "address"
27728
- }
27729
- ],
27730
- name: "balanceOf",
27731
- outputs: [
27732
- {
27733
- name: "balance",
27734
- type: "uint256"
27735
- }
27736
- ],
27737
- payable: false,
27738
- type: "function"
27739
- },
27740
- {
27741
- constant: true,
27742
- inputs: [],
27743
- name: "symbol",
27744
- outputs: [
27745
- {
27746
- name: "",
27747
- type: "string"
27748
- }
27749
- ],
27750
- payable: false,
27751
- type: "function"
26736
+ * @param {number} slippagePercent (optional) The percentage of slippage tolerance. Default = 0.1. Max = 50. Min = 0.
26737
+ * @param {number} maxHops (optional) Maximum hops allowed in optimal route. Default is 2.
26738
+ * @param {number} deadline (optional) Latest time swap can execute. Default is 15 minutes.
26739
+ * @return {TransactionResponse} The result containing the unsigned transaction and details of the swap.
26740
+ */
26741
+ async getUnsignedSwapTxFromAmountIn(fromAddress, tokenInAddress, tokenOutAddress, amountIn, slippagePercent = DEFAULT_SLIPPAGE, maxHops = DEFAULT_MAX_HOPS, deadline = DEFAULT_DEADLINE) {
26742
+ return await this.getUnsignedSwapTx(fromAddress, tokenInAddress, tokenOutAddress, ethers.BigNumber.from(amountIn), slippagePercent, maxHops, deadline, TradeType.EXACT_INPUT);
27752
26743
  }
27753
- ];
26744
+ /**
26745
+ * Get the unsigned swap transaction given the amount to buy.
26746
+ * Includes quote details for the swap.
26747
+ *
26748
+ * @param {string} fromAddress The public address that will sign and submit the transaction.
26749
+ * @param {string} tokenInAddress Token address to sell.
26750
+ * @param {string} tokenOutAddress Token address to buy.
26751
+ * @param {ethers.BigNumberish} amountOut Amount to buy.
26752
+ * @param {number} slippagePercent (optional) The percentage of slippage tolerance. Default = 0.1. Max = 50. Min = 0.
26753
+ * @param {number} maxHops (optional) Maximum hops allowed in optimal route. Default is 2.
26754
+ * @param {number} deadline (optional) Latest time swap can execute. Default is 15 minutes.
26755
+ * @return {TransactionResponse} The result containing the unsigned transaction and details of the swap.
26756
+ */
26757
+ async getUnsignedSwapTxFromAmountOut(fromAddress, tokenInAddress, tokenOutAddress, amountOut, slippagePercent = DEFAULT_SLIPPAGE, maxHops = DEFAULT_MAX_HOPS, deadline = DEFAULT_DEADLINE) {
26758
+ return await this.getUnsignedSwapTx(fromAddress, tokenInAddress, tokenOutAddress, ethers.BigNumber.from(amountOut), slippagePercent, maxHops, deadline, TradeType.EXACT_OUTPUT);
26759
+ }
26760
+ }
26761
+
26762
+ /* eslint-disable class-methods-use-this */
26763
+
27754
26764
 
27755
26765
 
27756
26766
 
@@ -27958,6 +26968,111 @@ const $d85ad1457a3f1a83$export$3a9ebede6a150274 = new Map([
27958
26968
  }
27959
26969
  ]
27960
26970
  ]);
26971
+ const $d85ad1457a3f1a83$export$db5daa1b5156ccfe = [
26972
+ {
26973
+ constant: true,
26974
+ inputs: [],
26975
+ name: "name",
26976
+ outputs: [
26977
+ {
26978
+ name: "",
26979
+ type: "string"
26980
+ }
26981
+ ],
26982
+ payable: false,
26983
+ type: "function"
26984
+ },
26985
+ {
26986
+ constant: true,
26987
+ inputs: [],
26988
+ name: "decimals",
26989
+ outputs: [
26990
+ {
26991
+ name: "",
26992
+ type: "uint8"
26993
+ }
26994
+ ],
26995
+ payable: false,
26996
+ type: "function"
26997
+ },
26998
+ {
26999
+ constant: true,
27000
+ inputs: [
27001
+ {
27002
+ name: "_owner",
27003
+ type: "address"
27004
+ }
27005
+ ],
27006
+ name: "balanceOf",
27007
+ outputs: [
27008
+ {
27009
+ name: "balance",
27010
+ type: "uint256"
27011
+ }
27012
+ ],
27013
+ payable: false,
27014
+ type: "function"
27015
+ },
27016
+ {
27017
+ constant: true,
27018
+ inputs: [],
27019
+ name: "symbol",
27020
+ outputs: [
27021
+ {
27022
+ name: "",
27023
+ type: "string"
27024
+ }
27025
+ ],
27026
+ payable: false,
27027
+ type: "function"
27028
+ },
27029
+ {
27030
+ constant: true,
27031
+ inputs: [
27032
+ {
27033
+ name: "_owner",
27034
+ type: "address"
27035
+ },
27036
+ {
27037
+ name: "_spender",
27038
+ type: "address"
27039
+ }
27040
+ ],
27041
+ name: "allowance",
27042
+ outputs: [
27043
+ {
27044
+ name: "",
27045
+ type: "uint256"
27046
+ }
27047
+ ],
27048
+ payable: false,
27049
+ stateMutability: "view",
27050
+ type: "function"
27051
+ },
27052
+ {
27053
+ constant: false,
27054
+ inputs: [
27055
+ {
27056
+ name: "_spender",
27057
+ type: "address"
27058
+ },
27059
+ {
27060
+ name: "_value",
27061
+ type: "uint256"
27062
+ }
27063
+ ],
27064
+ name: "approve",
27065
+ outputs: [
27066
+ {
27067
+ name: "",
27068
+ type: "bool"
27069
+ }
27070
+ ],
27071
+ payable: false,
27072
+ stateMutability: "nonpayable",
27073
+ type: "function"
27074
+ }
27075
+ ];
27961
27076
 
27962
27077
 
27963
27078
  var $4b58188d47aafe8d$export$1fc8f52ad1810e52;
@@ -28010,6 +27125,7 @@ var $4b58188d47aafe8d$export$5d3b0ad129b9b98e;
28010
27125
  CheckoutErrorType["UNSUPPORTED_TOKEN_TYPE_ERROR"] = "UNSUPPORTED_TOKEN_TYPE_ERROR";
28011
27126
  CheckoutErrorType["GET_ORDER_LISTING_ERROR"] = "GET_ORDER_LISTING_ERROR";
28012
27127
  CheckoutErrorType["SWITCH_NETWORK_UNSUPPORTED"] = "SWITCH_NETWORK_UNSUPPORTED";
27128
+ CheckoutErrorType["GET_ERC20_ALLOWANCE_ERROR"] = "GET_ERC20_ALLOWANCE_ERROR";
28013
27129
  })($a8bc256d81a5e2c1$export$e3dc0620abde7f5a || ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a = {}));
28014
27130
  class $a8bc256d81a5e2c1$export$b722478a3cbfa3bc extends Error {
28015
27131
  message;
@@ -28226,7 +27342,7 @@ const $1564e43dde50bb61$export$df96cd8d56be0ab1 = async (config, web3Provider, w
28226
27342
  });
28227
27343
  async function $1564e43dde50bb61$export$60e0fe116a0e6ed0(web3Provider, walletAddress, contractAddress) {
28228
27344
  return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
28229
- const contract = new (Contract$1)(contractAddress, JSON.stringify(($762782b6c862d954$export$db5daa1b5156ccfe)), web3Provider);
27345
+ const contract = new (Contract$1)(contractAddress, JSON.stringify(($d85ad1457a3f1a83$export$db5daa1b5156ccfe)), web3Provider);
28230
27346
  const name = await contract.name();
28231
27347
  const symbol = await contract.symbol();
28232
27348
  const balance = await contract.balanceOf(walletAddress);
@@ -28350,6 +27466,8 @@ function $bb88265fe45a0393$export$ebe4804963e71f98(web3Provider) {
28350
27466
  }
28351
27467
  async function $bb88265fe45a0393$export$9e1fd9cc88c637a0(config, web3Provider, validateProviderOptions) {
28352
27468
  return ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
27469
+ if (web3Provider.provider?.isPassport) // if Passport skip the validation checks
27470
+ return web3Provider;
28353
27471
  if (!$bb88265fe45a0393$export$ebe4804963e71f98(web3Provider)) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Parsed provider is not a valid Web3Provider", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).WEB3_PROVIDER_ERROR);
28354
27472
  // this sets the default options and overrides them with any parsed options
28355
27473
  const options = {
@@ -28608,7 +27726,7 @@ const $2e7bf45a7c9a9570$var$DUMMY_WALLET_ADDRESS = "0x00000000000000000000000000
28608
27726
  const $2e7bf45a7c9a9570$var$DEFAULT_TOKEN_DECIMALS = 18;
28609
27727
  async function $2e7bf45a7c9a9570$var$getTokenInfoByAddress(config, tokenAddress, chainId, provider) {
28610
27728
  if (tokenAddress === "NATIVE") return config.networkMap.get(chainId)?.nativeCurrency;
28611
- const contract = new (Contract$1)(tokenAddress, JSON.stringify(($762782b6c862d954$export$db5daa1b5156ccfe)), provider);
27729
+ const contract = new (Contract$1)(tokenAddress, JSON.stringify(($d85ad1457a3f1a83$export$db5daa1b5156ccfe)), provider);
28612
27730
  const name = await contract.name();
28613
27731
  const symbol = await contract.symbol();
28614
27732
  const decimals = await contract.decimals();
@@ -28703,16 +27821,169 @@ async function $2e7bf45a7c9a9570$export$942c8de7174809fc(params, readOnlyProvide
28703
27821
 
28704
27822
 
28705
27823
 
28706
- const $c147333b1f360629$export$92589613aaa38e1f = 300000;
28707
- const $c147333b1f360629$export$dea9ce0e9bb2441c = "0x474989C4D25DD41B0B9b1ECb4643B9Fe25f83B19";
28708
- const $c147333b1f360629$export$4249179755829904 = (type, contractAddress, amount)=>{
27824
+
27825
+
27826
+
27827
+
27828
+
27829
+ const $2499eab4caa6dc71$export$1ede6278abcdf1cb = (itemRequirements)=>{
27830
+ const aggregatedMap = new Map();
27831
+ const aggregatedItemRequirements = [];
27832
+ itemRequirements.forEach((itemRequirement)=>{
27833
+ const { type: type } = itemRequirement;
27834
+ if (type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
27835
+ aggregatedItemRequirements.push(itemRequirement);
27836
+ return;
27837
+ }
27838
+ const { contractAddress: contractAddress, spenderAddress: spenderAddress, amount: amount } = itemRequirement;
27839
+ const key = `${contractAddress}${spenderAddress}`;
27840
+ const aggregateItem = aggregatedMap.get(key);
27841
+ if (aggregateItem && aggregateItem.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) aggregateItem.amount = (BigNumber$1).from(aggregateItem.amount).add(amount);
27842
+ else aggregatedMap.set(key, {
27843
+ ...itemRequirement
27844
+ });
27845
+ });
27846
+ return aggregatedItemRequirements.concat(Array.from(aggregatedMap.values()));
27847
+ };
27848
+ const $2499eab4caa6dc71$export$c804c9ade5c28607 = (itemRequirements)=>$2499eab4caa6dc71$export$1ede6278abcdf1cb(itemRequirements);
27849
+
27850
+
27851
+
27852
+
27853
+
27854
+ const $95b61a5bfb091547$export$41491ea105c4dc2d = async (provider, ownerAddress, contractAddress, spenderAddress)=>{
27855
+ try {
27856
+ const contract = new (0, Contract$1)(contractAddress, JSON.stringify((0, $d85ad1457a3f1a83$export$db5daa1b5156ccfe)), provider);
27857
+ return await contract.allowance(ownerAddress, spenderAddress);
27858
+ } catch (err) {
27859
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Failed to get the allowance for ERC20", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC20_ALLOWANCE_ERROR, {
27860
+ contractAddress: contractAddress
27861
+ });
27862
+ }
27863
+ };
27864
+ const $95b61a5bfb091547$export$5c6bea080a6ee647 = async (provider, ownerAddress, contractAddress, spenderAddress, amount)=>{
27865
+ try {
27866
+ const contract = new (0, Contract$1)(contractAddress, JSON.stringify((0, $d85ad1457a3f1a83$export$db5daa1b5156ccfe)), provider);
27867
+ const approveTransaction = await contract.populateTransaction.approve(spenderAddress, amount);
27868
+ if (approveTransaction) approveTransaction.from = ownerAddress;
27869
+ return approveTransaction;
27870
+ } catch {
27871
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Failed to get the approval transaction for ERC20", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC20_ALLOWANCE_ERROR, {
27872
+ contractAddress: contractAddress
27873
+ });
27874
+ }
27875
+ };
27876
+ const $95b61a5bfb091547$export$d93c00812189e36 = async (provider, ownerAddress, itemRequirements)=>{
27877
+ let sufficient = true;
27878
+ const sufficientAllowances = [];
27879
+ const erc20s = new Map();
27880
+ const allowancePromises = new Map();
27881
+ const insufficientERC20s = new Map();
27882
+ const transactionPromises = new Map();
27883
+ // Populate maps for both the ERC20 data and promises to get the allowance using the same key
27884
+ // so the promise and data can be linked together when the promise resolves
27885
+ for (const itemRequirement of itemRequirements){
27886
+ if (itemRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) continue;
27887
+ const { contractAddress: contractAddress, spenderAddress: spenderAddress } = itemRequirement;
27888
+ erc20s.set(`${contractAddress}${spenderAddress}`, itemRequirement);
27889
+ allowancePromises.set(`${contractAddress}${spenderAddress}`, $95b61a5bfb091547$export$41491ea105c4dc2d(provider, ownerAddress, contractAddress, spenderAddress));
27890
+ }
27891
+ const allowances = await Promise.all(allowancePromises.values());
27892
+ const allowancePromiseIds = Array.from(allowancePromises.keys());
27893
+ // Iterate through the allowance promises and get the ERC20 data from the ERC20 map
27894
+ // If the allowance returned for that ERC20 is sufficient then just set the item requirements
27895
+ // If the allowance is insufficient then set the delta and a promise for the approval transaction
27896
+ for(let index = 0; index < allowances.length; index++){
27897
+ const itemRequirement = erc20s.get(allowancePromiseIds[index]);
27898
+ if (!itemRequirement || itemRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) continue;
27899
+ if (allowances[index].gte(itemRequirement.amount)) {
27900
+ sufficientAllowances.push({
27901
+ sufficient: true,
27902
+ itemRequirement: itemRequirement
27903
+ });
27904
+ continue;
27905
+ }
27906
+ sufficient = false; // Set sufficient false on the root of the return object when an ERC20 is insufficient
27907
+ const { contractAddress: contractAddress, spenderAddress: spenderAddress } = itemRequirement;
27908
+ const delta = itemRequirement.amount.sub(allowances[index]);
27909
+ // Create maps for both the insufficient ERC20 data and the transaction promises using the same key so the results can be merged
27910
+ insufficientERC20s.set(`${contractAddress}${spenderAddress}`, {
27911
+ sufficient: false,
27912
+ delta: delta,
27913
+ itemRequirement: itemRequirement,
27914
+ approvalTransaction: undefined
27915
+ });
27916
+ transactionPromises.set(`${contractAddress}${spenderAddress}`, $95b61a5bfb091547$export$5c6bea080a6ee647(provider, ownerAddress, contractAddress, spenderAddress, delta));
27917
+ }
27918
+ // Resolves the approval transactions and merges them with the insufficient ERC20 data
27919
+ const transactions = await Promise.all(transactionPromises.values());
27920
+ const transactionPromiseIds = Array.from(allowancePromises.keys());
27921
+ transactions.forEach((transaction, index)=>{
27922
+ const insufficientERC20 = insufficientERC20s.get(transactionPromiseIds[index]);
27923
+ if (!insufficientERC20) return;
27924
+ if (insufficientERC20.sufficient) return;
27925
+ insufficientERC20.approvalTransaction = transaction;
27926
+ });
27927
+ // Merge the allowance arrays to get both the sufficient allowances and the insufficient ERC20 allowances
27928
+ return {
27929
+ sufficient: sufficient,
27930
+ allowances: sufficientAllowances.concat(Array.from(insufficientERC20s.values()))
27931
+ };
27932
+ };
27933
+
27934
+
27935
+ const $0e7419077c373b24$export$9e073f9ada8c81e6 = async (provider, itemRequirements, transactionOrGasAmount)=>{
27936
+ const ownerAddress = await provider.getSigner().getAddress();
27937
+ // eslint-disable-next-line no-console
27938
+ console.log(provider, itemRequirements, transactionOrGasAmount);
27939
+ const aggregatedItems = ($2499eab4caa6dc71$export$c804c9ade5c28607)(itemRequirements);
27940
+ // eslint-disable-next-line no-console
27941
+ console.log(aggregatedItems);
27942
+ const erc20Allowances = await ($95b61a5bfb091547$export$d93c00812189e36)(provider, ownerAddress, aggregatedItems);
27943
+ // eslint-disable-next-line no-console
27944
+ console.log(erc20Allowances);
27945
+ return {
27946
+ sufficient: true,
27947
+ transactionRequirements: [
27948
+ {
27949
+ type: ($4b58188d47aafe8d$export$5d3b0ad129b9b98e).GAS,
27950
+ sufficient: true,
27951
+ required: {
27952
+ balance: (BigNumber$1).from(0),
27953
+ formattedBalance: "0",
27954
+ token: {
27955
+ name: "IMX",
27956
+ symbol: "IMX",
27957
+ address: "0x0",
27958
+ decimals: 18
27959
+ }
27960
+ },
27961
+ current: {
27962
+ balance: (BigNumber$1).from(1),
27963
+ formattedBalance: "1",
27964
+ token: {
27965
+ name: "IMX",
27966
+ symbol: "IMX",
27967
+ address: "0x0",
27968
+ decimals: 18
27969
+ }
27970
+ }
27971
+ }
27972
+ ]
27973
+ };
27974
+ };
27975
+
27976
+
27977
+
27978
+
27979
+ const $64863c39386de592$export$4249179755829904 = (type, contractAddress, amount, spenderAddress)=>{
28709
27980
  switch(type){
28710
27981
  case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20:
28711
27982
  return {
28712
27983
  type: type,
28713
27984
  amount: amount,
28714
27985
  contractAddress: contractAddress,
28715
- spenderAddress: $c147333b1f360629$export$dea9ce0e9bb2441c
27986
+ spenderAddress: spenderAddress
28716
27987
  };
28717
27988
  case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE:
28718
27989
  default:
@@ -28722,17 +27993,48 @@ const $c147333b1f360629$export$4249179755829904 = (type, contractAddress, amount
28722
27993
  };
28723
27994
  }
28724
27995
  };
28725
- const $c147333b1f360629$export$7f8e2b98eca5a7f0 = async (config, provider, orderId)=>{
27996
+ const $64863c39386de592$export$e0cb3ec5326d496b = async (actions)=>{
27997
+ for (const action of actions){
27998
+ if (action.type === (ActionType).TRANSACTION && action.purpose === (TransactionPurpose).FULFILL_ORDER) // eslint-disable-next-line no-await-in-loop
27999
+ return await action.buildTransaction();
28000
+ }
28001
+ return undefined;
28002
+ };
28003
+ const $64863c39386de592$export$8f2ff92ab8657f0b = (gasLimit, transaction)=>{
28004
+ if (transaction) return {
28005
+ type: ($4b58188d47aafe8d$export$65c64e46348ee3c1).TRANSACTION,
28006
+ transaction: transaction
28007
+ };
28008
+ return {
28009
+ type: ($4b58188d47aafe8d$export$65c64e46348ee3c1).GAS,
28010
+ gasToken: {
28011
+ type: ($4b58188d47aafe8d$export$537fa3efd10ed435).NATIVE,
28012
+ limit: (BigNumber$1).from(gasLimit)
28013
+ }
28014
+ };
28015
+ };
28016
+ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, orderId)=>{
28017
+ let orderbook;
28726
28018
  let order;
28019
+ let spenderAddress = "";
28020
+ const gasLimit = (constants).estimatedFulfillmentGasGwei;
28727
28021
  try {
28728
- const orderbook = await $67fc622a2b913d5f$export$c60ce6c6a92bc2ff(config);
28022
+ orderbook = await $67fc622a2b913d5f$export$c60ce6c6a92bc2ff(config);
28729
28023
  order = await orderbook.getListing(orderId);
28024
+ const { seaportContractAddress: seaportContractAddress } = orderbook.config();
28025
+ spenderAddress = seaportContractAddress;
28730
28026
  } catch (err) {
28731
28027
  throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("An error occurred while getting the order listing", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ORDER_LISTING_ERROR, {
28732
28028
  orderId: orderId,
28733
28029
  message: err.message
28734
28030
  });
28735
28031
  }
28032
+ let unsignedTransaction;
28033
+ try {
28034
+ const fulfillerAddress = await provider.getSigner().getAddress();
28035
+ const { actions: actions } = await orderbook.fulfillOrder(orderId, fulfillerAddress);
28036
+ unsignedTransaction = await $64863c39386de592$export$e0cb3ec5326d496b(actions);
28037
+ } catch {}
28736
28038
  let amount = (BigNumber$1).from("0");
28737
28039
  let type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE;
28738
28040
  let contractAddress = "";
@@ -28758,13 +28060,14 @@ const $c147333b1f360629$export$7f8e2b98eca5a7f0 = async (config, provider, order
28758
28060
  amount = amount.add((BigNumber$1).from(item.amount));
28759
28061
  });
28760
28062
  const itemRequirements = [
28761
- $c147333b1f360629$export$4249179755829904(type, contractAddress, amount)
28063
+ $64863c39386de592$export$4249179755829904(type, contractAddress, amount, spenderAddress)
28762
28064
  ];
28065
+ await ($0e7419077c373b24$export$9e073f9ada8c81e6)(provider, itemRequirements, $64863c39386de592$export$8f2ff92ab8657f0b(gasLimit, unsignedTransaction));
28763
28066
  return {
28764
28067
  itemRequirements: itemRequirements,
28765
28068
  gasToken: {
28766
28069
  type: ($4b58188d47aafe8d$export$537fa3efd10ed435).NATIVE,
28767
- limit: (BigNumber$1).from($c147333b1f360629$export$92589613aaa38e1f)
28070
+ limit: (BigNumber$1).from(gasLimit)
28768
28071
  }
28769
28072
  };
28770
28073
  };
@@ -28774,44 +28077,6 @@ const $c147333b1f360629$export$7f8e2b98eca5a7f0 = async (config, provider, order
28774
28077
 
28775
28078
 
28776
28079
 
28777
- const $0e7419077c373b24$export$9e073f9ada8c81e6 = async (provider, itemRequirements, transactionOrGasAmount)=>{
28778
- // eslint-disable-next-line no-console
28779
- console.log(provider, itemRequirements, transactionOrGasAmount);
28780
- return {
28781
- sufficient: true,
28782
- transactionRequirements: [
28783
- {
28784
- type: ($4b58188d47aafe8d$export$5d3b0ad129b9b98e).GAS,
28785
- sufficient: true,
28786
- required: {
28787
- balance: (BigNumber$1).from(0),
28788
- formattedBalance: "0",
28789
- token: {
28790
- name: "IMX",
28791
- symbol: "IMX",
28792
- address: "0x0",
28793
- decimals: 18
28794
- }
28795
- },
28796
- current: {
28797
- balance: (BigNumber$1).from(1),
28798
- formattedBalance: "1",
28799
- token: {
28800
- name: "IMX",
28801
- symbol: "IMX",
28802
- address: "0x0",
28803
- decimals: 18
28804
- }
28805
- }
28806
- }
28807
- ]
28808
- };
28809
- };
28810
-
28811
-
28812
-
28813
-
28814
-
28815
28080
 
28816
28081
 
28817
28082
 
@@ -28956,7 +28221,7 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
28956
28221
  // eslint-disable-next-line no-console
28957
28222
  console.warn("This endpoint is currently under construction.");
28958
28223
  const web3Provider = await $bb88265fe45a0393$export$9e1fd9cc88c637a0(this.config, params.provider);
28959
- await $c147333b1f360629$export$7f8e2b98eca5a7f0(this.config, web3Provider, params.orderId);
28224
+ await $64863c39386de592$export$7f8e2b98eca5a7f0(this.config, web3Provider, params.orderId);
28960
28225
  }
28961
28226
  /**
28962
28227
  * Determines the transaction requirements to complete a purchase.
@@ -29002,7 +28267,7 @@ var checkout_sdk = /*#__PURE__*/Object.freeze({
29002
28267
  function $parcel$export(e, n, v, s) {
29003
28268
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
29004
28269
  }
29005
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.11.0-alpha";
28270
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.12.0-alpha";
29006
28271
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
29007
28272
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
29008
28273