@imtbl/sdk 0.28.6-alpha.1 → 0.28.8

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/orderbook.js CHANGED
@@ -861,12 +861,15 @@ function getOrderComponentsFromMessage(orderMessage) {
861
861
 
862
862
  // Add 20% more gas than estimate to prevent out of gas errors
863
863
  // This can always be overwritten by the user signing the transaction
864
- function prepareTransaction(transactionMethods) {
864
+ function prepareTransaction(transactionMethods,
865
+ // chainId is required for EIP155
866
+ chainId) {
865
867
  return async () => {
866
868
  const transaction = await transactionMethods.buildTransaction();
867
869
  transaction.gasLimit = await transactionMethods.estimateGas();
868
870
  transaction.gasLimit = transaction.gasLimit
869
871
  .add(transaction.gasLimit.div(5));
872
+ transaction.chainId = chainId;
870
873
  return transaction;
871
874
  };
872
875
  }
@@ -960,7 +963,7 @@ class Seaport {
960
963
  listingActions.push({
961
964
  type: ActionType.TRANSACTION,
962
965
  purpose: TransactionPurpose.APPROVAL,
963
- buildTransaction: prepareTransaction(approvalAction.transactionMethods),
966
+ buildTransaction: prepareTransaction(approvalAction.transactionMethods, (await this.provider.getNetwork()).chainId),
964
967
  });
965
968
  }
966
969
  const createAction = seaportActions.find((action) => action.type === 'create');
@@ -1001,7 +1004,7 @@ class Seaport {
1001
1004
  if (approvalAction) {
1002
1005
  fulfillmentActions.push({
1003
1006
  type: ActionType.TRANSACTION,
1004
- buildTransaction: prepareTransaction(approvalAction.transactionMethods),
1007
+ buildTransaction: prepareTransaction(approvalAction.transactionMethods, (await this.provider.getNetwork()).chainId),
1005
1008
  purpose: TransactionPurpose.APPROVAL,
1006
1009
  });
1007
1010
  }
@@ -1011,7 +1014,7 @@ class Seaport {
1011
1014
  }
1012
1015
  fulfillmentActions.push({
1013
1016
  type: ActionType.TRANSACTION,
1014
- buildTransaction: prepareTransaction(fulfilOrderAction.transactionMethods),
1017
+ buildTransaction: prepareTransaction(fulfilOrderAction.transactionMethods, (await this.provider.getNetwork()).chainId),
1015
1018
  purpose: TransactionPurpose.FULFILL_ORDER,
1016
1019
  });
1017
1020
  return {
@@ -1041,7 +1044,7 @@ class Seaport {
1041
1044
  if (approvalAction) {
1042
1045
  fulfillmentActions.push({
1043
1046
  type: ActionType.TRANSACTION,
1044
- buildTransaction: prepareTransaction(approvalAction.transactionMethods),
1047
+ buildTransaction: prepareTransaction(approvalAction.transactionMethods, (await this.provider.getNetwork()).chainId),
1045
1048
  purpose: TransactionPurpose.APPROVAL,
1046
1049
  });
1047
1050
  }
@@ -1051,7 +1054,7 @@ class Seaport {
1051
1054
  }
1052
1055
  fulfillmentActions.push({
1053
1056
  type: ActionType.TRANSACTION,
1054
- buildTransaction: prepareTransaction(fulfilOrderAction.transactionMethods),
1057
+ buildTransaction: prepareTransaction(fulfilOrderAction.transactionMethods, (await this.provider.getNetwork()).chainId),
1055
1058
  purpose: TransactionPurpose.FULFILL_ORDER,
1056
1059
  });
1057
1060
  return {
@@ -1068,7 +1071,7 @@ class Seaport {
1068
1071
  const cancellationTransaction = await seaportLib.cancelOrders(orderComponents, account);
1069
1072
  return {
1070
1073
  type: ActionType.TRANSACTION,
1071
- buildTransaction: prepareTransaction(cancellationTransaction),
1074
+ buildTransaction: prepareTransaction(cancellationTransaction, (await this.provider.getNetwork()).chainId),
1072
1075
  purpose: TransactionPurpose.CANCEL,
1073
1076
  };
1074
1077
  }
@@ -9732,6 +9732,12 @@ interface IMXProvider {
9732
9732
  * @return {Promise<RegisterUserResponse>} Returns a promise that resolves with the user registration response
9733
9733
  */
9734
9734
  registerOffchain(): Promise<RegisterUserResponse>;
9735
+ /**
9736
+ * Checks if a User is registered off-chain
9737
+ *
9738
+ * @return {Promise<boolean>} Returns a promise that resolves with true if the User is registered with IMX, false otherwise
9739
+ */
9740
+ isRegisteredOffchain(): Promise<boolean>;
9735
9741
  /**
9736
9742
  * Checks if a User is registered on-chain
9737
9743
  *
@@ -10184,7 +10190,7 @@ type UserProfile = {
10184
10190
  };
10185
10191
  declare enum Networks {
10186
10192
  PRODUCTION = "mainnet",
10187
- SANDBOX = "goerli"
10193
+ SANDBOX = "sepolia"
10188
10194
  }
10189
10195
  interface OidcConfiguration {
10190
10196
  clientId: string;
package/dist/passport.js CHANGED
@@ -2072,7 +2072,7 @@ class MultiRollupApiClients {
2072
2072
  }
2073
2073
 
2074
2074
  // eslint-disable-next-line @typescript-eslint/naming-convention
2075
- const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.28.6-alpha.1' };
2075
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.28.8' };
2076
2076
  const createConfig = ({ basePath, headers, }) => {
2077
2077
  if (!basePath.trim()) {
2078
2078
  throw Error('basePath can not be empty');
@@ -2128,7 +2128,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
2128
2128
  chainID,
2129
2129
  coreContractAddress,
2130
2130
  registrationContractAddress,
2131
- sdkVersion: 'ts-immutable-sdk-0.28.6-alpha.1',
2131
+ sdkVersion: 'ts-immutable-sdk-0.28.8',
2132
2132
  });
2133
2133
  /**
2134
2134
  * Sets `sdkVersion` at the time of build
@@ -7056,39 +7056,63 @@ class AuthManager {
7056
7056
  }
7057
7057
  }
7058
7058
 
7059
+ const lazyLoad = (promiseToAwait, initialiseFunction) => (promiseToAwait().then(initialiseFunction));
7060
+ const lazyDocumentReady = (initialiseFunction) => {
7061
+ const documentReadyPromise = () => new Promise((resolve) => {
7062
+ if (window.document.readyState === 'complete') {
7063
+ resolve();
7064
+ }
7065
+ else {
7066
+ const onReadyStateChange = () => {
7067
+ if (window.document.readyState === 'complete') {
7068
+ resolve();
7069
+ window.document.removeEventListener('readystatechange', onReadyStateChange);
7070
+ }
7071
+ };
7072
+ window.document.addEventListener('readystatechange', onReadyStateChange);
7073
+ }
7074
+ });
7075
+ return lazyLoad(documentReadyPromise, initialiseFunction);
7076
+ };
7077
+
7059
7078
  class MagicAdapter {
7060
7079
  config;
7061
- magicClient;
7080
+ lazyMagicClient;
7062
7081
  constructor(config) {
7063
7082
  this.config = config;
7064
7083
  if (typeof window !== 'undefined') {
7065
- this.magicClient = this.initMagicClient();
7066
- this.magicClient.preload();
7084
+ this.lazyMagicClient = lazyDocumentReady(() => {
7085
+ const client = new Magic(this.config.magicPublishableApiKey, {
7086
+ extensions: [new OpenIdExtension()],
7087
+ network: this.config.network,
7088
+ });
7089
+ client.preload();
7090
+ return client;
7091
+ });
7092
+ }
7093
+ }
7094
+ get magicClient() {
7095
+ if (!this.lazyMagicClient) {
7096
+ throw new Error('Cannot perform this action outside of the browser');
7067
7097
  }
7098
+ return this.lazyMagicClient;
7068
7099
  }
7069
7100
  async login(idToken) {
7070
7101
  return withPassportError(async () => {
7071
- if (!this.magicClient) {
7072
- this.magicClient = this.initMagicClient();
7073
- }
7074
- await this.magicClient.openid.loginWithOIDC({
7102
+ const magicClient = await this.magicClient;
7103
+ await magicClient.openid.loginWithOIDC({
7075
7104
  jwt: idToken,
7076
7105
  providerId: this.config.magicProviderId,
7077
7106
  });
7078
- return this.magicClient.rpcProvider;
7107
+ return magicClient.rpcProvider;
7079
7108
  }, PassportErrorType.WALLET_CONNECTION_ERROR);
7080
7109
  }
7081
7110
  async logout() {
7082
- if (this.magicClient?.user) {
7083
- await this.magicClient.user.logout();
7111
+ const magicClient = await this.magicClient;
7112
+ if (magicClient.user) {
7113
+ await magicClient.user.logout();
7084
7114
  }
7085
7115
  }
7086
- initMagicClient() {
7087
- return new Magic(this.config.magicPublishableApiKey, {
7088
- extensions: [new OpenIdExtension()],
7089
- network: this.config.network,
7090
- });
7091
- }
7092
7116
  }
7093
7117
 
7094
7118
  const getStarkSigner = async (signer) => withPassportError(async () => {
@@ -7315,7 +7339,7 @@ var PassportEvents;
7315
7339
  var Networks;
7316
7340
  (function (Networks) {
7317
7341
  Networks["PRODUCTION"] = "mainnet";
7318
- Networks["SANDBOX"] = "goerli";
7342
+ Networks["SANDBOX"] = "sepolia";
7319
7343
  })(Networks || (Networks = {}));
7320
7344
 
7321
7345
  async function exchangeTransfer({ user, starkSigner, request, exchangesApi, }) {
@@ -7664,6 +7688,11 @@ class PassportImxProvider {
7664
7688
  }
7665
7689
  // TODO: Remove once implemented
7666
7690
  // eslint-disable-next-line class-methods-use-this
7691
+ isRegisteredOffchain() {
7692
+ throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
7693
+ }
7694
+ // TODO: Remove once implemented
7695
+ // eslint-disable-next-line class-methods-use-this
7667
7696
  isRegisteredOnchain() {
7668
7697
  throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
7669
7698
  }
@@ -7757,7 +7786,17 @@ class PassportImxProviderFactory {
7757
7786
  this.passportEventEmitter = passportEventEmitter;
7758
7787
  }
7759
7788
  async getProvider() {
7760
- const user = await this.authManager.loginSilent() || await this.authManager.login();
7789
+ let user = null;
7790
+ try {
7791
+ user = await this.authManager.loginSilent();
7792
+ }
7793
+ catch (e) {
7794
+ // eslint-disable-next-line no-console
7795
+ console.warn(e);
7796
+ }
7797
+ if (!user) {
7798
+ user = await this.authManager.login();
7799
+ }
7761
7800
  return this.createProviderInstance(user);
7762
7801
  }
7763
7802
  async getProviderSilent() {
@@ -8812,7 +8851,14 @@ class Passport {
8812
8851
  */
8813
8852
  async login(options) {
8814
8853
  const { useCachedSession = false } = options || {};
8815
- let user = await this.authManager.loginSilent();
8854
+ let user = null;
8855
+ try {
8856
+ user = await this.authManager.loginSilent();
8857
+ }
8858
+ catch (error) {
8859
+ // eslint-disable-next-line no-console
8860
+ console.warn('loginSilent failed with error:', error);
8861
+ }
8816
8862
  if (!user && !useCachedSession) {
8817
8863
  user = await this.authManager.login();
8818
8864
  }
@@ -1,5 +1,3 @@
1
- import { ProviderConfiguration as ProviderConfiguration$1 } from 'config';
2
-
3
1
  declare type Bytes = ArrayLike<number>;
4
2
  declare type BytesLike = Bytes | string;
5
3
  interface Hexable {
@@ -833,6 +831,12 @@ interface IMXProvider {
833
831
  * @return {Promise<RegisterUserResponse>} Returns a promise that resolves with the user registration response
834
832
  */
835
833
  registerOffchain(): Promise<RegisterUserResponse>;
834
+ /**
835
+ * Checks if a User is registered off-chain
836
+ *
837
+ * @return {Promise<boolean>} Returns a promise that resolves with true if the User is registered with IMX, false otherwise
838
+ */
839
+ isRegisteredOffchain(): Promise<boolean>;
836
840
  /**
837
841
  * Checks if a User is registered on-chain
838
842
  *
@@ -905,31 +909,6 @@ interface IMXProvider {
905
909
  completeWithdrawal(starkPublicKey: string, token: AnyToken): Promise<TransactionResponse>;
906
910
  }
907
911
 
908
- declare class GenericIMXProvider implements IMXProvider {
909
- private readonly config;
910
- private readonly signers;
911
- constructor(config: ProviderConfiguration$1, ethSigner: Signer, starkSigner: StarkSigner);
912
- getAddress(): Promise<string>;
913
- registerOffchain(): Promise<RegisterUserResponse>;
914
- batchNftTransfer(request: Array<NftTransferDetails>): Promise<CreateTransferResponse>;
915
- cancelOrder(request: GetSignableCancelOrderRequest): Promise<CancelOrderResponse>;
916
- completeWithdrawal(starkPublicKey: string, token: AnyToken): Promise<TransactionResponse>;
917
- createOrder(request: UnsignedOrderRequest): Promise<CreateOrderResponse>;
918
- createTrade(request: GetSignableTradeRequest): Promise<CreateTradeResponse>;
919
- deposit(tokenAmount: TokenAmount): Promise<TransactionResponse>;
920
- exchangeTransfer(request: UnsignedExchangeTransferRequest): Promise<CreateTransferResponseV1>;
921
- isRegisteredOnchain(): Promise<boolean>;
922
- prepareWithdrawal(request: TokenAmount): Promise<CreateWithdrawalResponse>;
923
- transfer(request: UnsignedTransferRequest): Promise<CreateTransferResponseV1>;
924
- }
925
-
926
- declare class MetaMaskIMXProvider extends GenericIMXProvider {
927
- private static imxSigner;
928
- static connect(config: ProviderConfiguration$1): Promise<MetaMaskIMXProvider>;
929
- static disconnect(): Promise<void>;
930
- static signMessage(message: string): Promise<string>;
931
- }
932
-
933
912
  declare enum Environment {
934
913
  PRODUCTION = "production",
935
914
  SANDBOX = "sandbox"
@@ -962,4 +941,30 @@ declare class ProviderConfiguration {
962
941
  constructor({ baseConfig, overrides }: ProviderModuleConfiguration);
963
942
  }
964
943
 
944
+ declare class GenericIMXProvider implements IMXProvider {
945
+ private readonly config;
946
+ private readonly signers;
947
+ constructor(config: ProviderConfiguration, ethSigner: Signer, starkSigner: StarkSigner);
948
+ getAddress(): Promise<string>;
949
+ isRegisteredOffchain(): Promise<boolean>;
950
+ registerOffchain(): Promise<RegisterUserResponse>;
951
+ batchNftTransfer(request: Array<NftTransferDetails>): Promise<CreateTransferResponse>;
952
+ cancelOrder(request: GetSignableCancelOrderRequest): Promise<CancelOrderResponse>;
953
+ completeWithdrawal(starkPublicKey: string, token: AnyToken): Promise<TransactionResponse>;
954
+ createOrder(request: UnsignedOrderRequest): Promise<CreateOrderResponse>;
955
+ createTrade(request: GetSignableTradeRequest): Promise<CreateTradeResponse>;
956
+ deposit(tokenAmount: TokenAmount): Promise<TransactionResponse>;
957
+ exchangeTransfer(request: UnsignedExchangeTransferRequest): Promise<CreateTransferResponseV1>;
958
+ isRegisteredOnchain(): Promise<boolean>;
959
+ prepareWithdrawal(request: TokenAmount): Promise<CreateWithdrawalResponse>;
960
+ transfer(request: UnsignedTransferRequest): Promise<CreateTransferResponseV1>;
961
+ }
962
+
963
+ declare class MetaMaskIMXProvider extends GenericIMXProvider {
964
+ private static imxSigner;
965
+ static connect(config: ProviderConfiguration): Promise<MetaMaskIMXProvider>;
966
+ static disconnect(): Promise<void>;
967
+ static signMessage(message: string): Promise<string>;
968
+ }
969
+
965
970
  export { GenericIMXProvider, IMXProvider, MetaMaskIMXProvider, ProviderConfiguration };
package/dist/provider.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { Config, TransfersApi, OrdersApi, UsersApi, Contracts, TradesApi, ExchangesApi, WithdrawalsApi, MintsApi, DepositsApi, EncodingApi, TokensApi } from '@imtbl/core-sdk';
2
2
  import BN from 'bn.js';
3
3
  import * as encUtils from 'enc-utils';
4
+ import { AxiosError } from 'axios';
4
5
  import { parseUnits } from '@ethersproject/units';
5
6
  import { BigNumber } from '@ethersproject/bignumber';
6
7
  import { ethers } from 'ethers';
7
8
  import detectEthereumProvider from '@metamask/detect-provider';
8
- import 'axios';
9
9
 
10
10
  // used to sign message with L1 keys. Used for registration
11
11
  function serializeEthSignature(sig) {
@@ -285,6 +285,22 @@ async function registerOffchain(signers, config) {
285
285
  });
286
286
  return registeredUser.data;
287
287
  }
288
+ async function isRegisteredOffchain(ethAddress, config) {
289
+ try {
290
+ const usersApi = new UsersApi(config.immutableXConfig.apiConfiguration);
291
+ const getUsersResult = await usersApi.getUsers({
292
+ user: ethAddress,
293
+ });
294
+ const { accounts } = getUsersResult.data;
295
+ return accounts?.length > 0;
296
+ }
297
+ catch (ex) {
298
+ if (ex instanceof AxiosError && ex.response?.status === 404) {
299
+ return false;
300
+ }
301
+ throw ex;
302
+ }
303
+ }
288
304
  async function isRegisteredOnChain(starkPublicKey, ethSigner, config) {
289
305
  await validateChain(ethSigner, config.immutableXConfig);
290
306
  const registrationContract = Contracts.Registration.connect(config.immutableXConfig.ethConfiguration.registrationContractAddress, ethSigner);
@@ -820,7 +836,11 @@ class GenericIMXProvider {
820
836
  this.signers = { ethSigner, starkSigner };
821
837
  }
822
838
  async getAddress() {
823
- return await this.signers.ethSigner.getAddress();
839
+ return this.signers.ethSigner.getAddress();
840
+ }
841
+ async isRegisteredOffchain() {
842
+ const ethAddress = await this.getAddress();
843
+ return isRegisteredOffchain(ethAddress, this.config);
824
844
  }
825
845
  registerOffchain() {
826
846
  return registerOffchain(this.signers, this.config);
package/package.json CHANGED
@@ -1,47 +1,32 @@
1
1
  {
2
2
  "name": "@imtbl/sdk",
3
3
  "description": "Immutable Unified SDK",
4
- "version": "0.28.6-alpha.1",
4
+ "version": "0.28.8",
5
5
  "author": "Immutable",
6
6
  "browser": "./dist/index.browser.js",
7
7
  "bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
8
8
  "dependencies": {
9
9
  "@0xsequence/abi": "^0.43.34",
10
10
  "@0xsequence/config": "^0.43.34",
11
- "@biom3/design-tokens": "0.2.4-beta",
12
- "@biom3/react": "^0.10.12",
13
11
  "@ethersproject/abi": "^5.7.0",
14
12
  "@ethersproject/abstract-signer": "^5.7.0",
15
13
  "@ethersproject/providers": "^5.7.2",
16
14
  "@ethersproject/wallet": "^5.7.0",
17
15
  "@imtbl/core-sdk": "^2.4.0",
18
- "@imtbl/react-analytics": "0.2.1-alpha",
19
16
  "@jest/globals": "^29.5.0",
20
- "@magic-ext/oidc": "^1.0.1",
17
+ "@magic-ext/oidc": "^4.2.0",
21
18
  "@metamask/detect-provider": "^2.0.0",
22
19
  "@opensea/seaport-js": "2.0.7",
23
20
  "@uniswap/router-sdk": "^1.4.0",
24
21
  "@uniswap/sdk-core": "^3.0.1",
25
22
  "@uniswap/v3-sdk": "^3.9.0",
26
- "assert": "^2.0.0",
27
23
  "axios": "^1.3.5",
28
24
  "bn.js": "^5.2.1",
29
- "buffer": "^6.0.3",
30
- "crypto-browserify": "^3.12.0",
31
25
  "enc-utils": "^3.0.0",
32
26
  "ethers": "^5.7.2",
33
- "https-browserify": "^1.0.0",
34
27
  "jwt-decode": "^3.1.2",
35
- "magic-sdk": "^13.3.1",
36
- "oidc-client-ts": "^2.2.1",
37
- "os-browserify": "^0.3.0",
38
- "pako": "^2.1.0",
39
- "react": "^18.2.0",
40
- "react-dom": "^18.2.0",
41
- "react-router-dom": "^6.11.0",
42
- "stream-browserify": "^3.0.0",
43
- "stream-http": "^3.2.0",
44
- "url": "^0.11.0"
28
+ "magic-sdk": "^21.2.0",
29
+ "oidc-client-ts": "^2.2.1"
45
30
  },
46
31
  "devDependencies": {
47
32
  "@imtbl/blockchain-data": "0.0.0",
@@ -109,6 +94,10 @@
109
94
  "./checkout_sdk": {
110
95
  "types": "./dist/checkout_sdk.d.ts",
111
96
  "import": "./dist/checkout_sdk.js"
97
+ },
98
+ "./checkout_widgets": {
99
+ "types": "./dist/checkout_widgets.d.ts",
100
+ "import": "./dist/checkout_widgets.js"
112
101
  }
113
102
  },
114
103
  "files": [