@imtbl/sdk 0.0.1-alpha.2 → 0.1.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/README.md ADDED
@@ -0,0 +1,28 @@
1
+ <div align="center">
2
+ <p align="center">
3
+ <a href="https://docs.x.immutable.com/docs">
4
+ <img src="https://cdn.dribbble.com/users/1299339/screenshots/7133657/media/837237d447d36581ebd59ec36d30daea.gif" width="280"/>
5
+ </a>
6
+ </p>
7
+ <h1>Immutable Unified TypeScript SDK</h1>
8
+ </div>
9
+
10
+ # Immutable Unified TypeScript SDK
11
+
12
+ ## Documentation
13
+
14
+ See our [developer documentation](https://docs.immutable.com) for information on building on Immutable.
15
+
16
+ See our [API reference](https://docs.immutable.com/reference) for more information on our APIs.
17
+
18
+ ### Examples
19
+
20
+ - For examples, please view them on our [documentation website](https://docs.immutable.com/sdk-docs/ts-immutable-sdk/overview/).
21
+
22
+ ## Installation
23
+
24
+ ```sh
25
+ npm install @imtbl/sdk --save
26
+ # or
27
+ yarn add @imtbl/sdk
28
+ ```
@@ -546,6 +546,14 @@ declare class Web3Provider extends JsonRpcProvider {
546
546
  send(method: string, params: Array<any>): Promise<any>;
547
547
  }
548
548
 
549
+ /**
550
+ * Interface representing token information.
551
+ * @property {string} name - The token name.
552
+ * @property {string} symbol - The token symbol.
553
+ * @property {number} decimals - The token decimals.
554
+ * @property {string} [address] - The token contract address.
555
+ * @property {string} [icon] - The token icon URL/data:image.
556
+ */
549
557
  interface TokenInfo {
550
558
  name: string;
551
559
  symbol: string;
@@ -553,71 +561,218 @@ interface TokenInfo {
553
561
  address?: string;
554
562
  icon?: string;
555
563
  }
564
+ /**
565
+ * Interface representing the parameters for {@link Checkout.getTokenAllowList}.
566
+ * @property {TokenFilterTypes} type - The type of token to retrieve.
567
+ * @property {ChainId} chainId - The ID of the blockchain network.
568
+ * @property {TokenFilter[]} [exclude] - The tokens to exclude from the list.
569
+ */
556
570
  interface GetTokenAllowListParams {
571
+ type: TokenFilterTypes;
557
572
  chainId: ChainId;
573
+ exclude?: TokenFilter[];
558
574
  }
575
+ /**
576
+ * Interface representing the result of {@link Checkout.getTokenAllowList}.
577
+ * @property {TokenInfo[]} tokens - The list of tokens allowed for the specified params.
578
+ */
559
579
  interface GetTokenAllowListResult {
560
580
  tokens: TokenInfo[];
561
581
  }
582
+ /**
583
+ * Enum representing the types of token filters available.
584
+ */
585
+ declare enum TokenFilterTypes {
586
+ SWAP = "swap",
587
+ BRIDGE = "bridge",
588
+ ALL = "all"
589
+ }
590
+ /**
591
+ * Interface representing a token filter that can be used to exclude certain tokens.
592
+ * @property {string} address - The token contract address.
593
+ */
594
+ interface TokenFilter {
595
+ address: string;
596
+ }
597
+ /**
598
+ * Enum representing the supported chains with their corresponding IDs.
599
+ */
562
600
  declare enum ChainId {
563
601
  ETHEREUM = 1,
564
602
  GOERLI = 5,
565
603
  POLYGON = 137
566
604
  }
605
+ /**
606
+ * Interface representing the information of a network.
607
+ * @property {string} name - The name of the network.
608
+ * @property {number} chainId - The ID of the network.
609
+ * @property {TokenInfo} nativeCurrency - The info of the network's native currency.
610
+ * @property {boolean} isSupported - Flag indicating if the network is supported by the application.
611
+ */
567
612
  interface NetworkInfo {
568
613
  name: string;
569
614
  chainId: number;
570
615
  nativeCurrency: TokenInfo;
616
+ isSupported: boolean;
571
617
  }
618
+ /**
619
+ * Interface representing the parameters for {@link Checkout.switchNetwork}.
620
+ * @property {Web3Provider} provider - The provider to connect to the network.
621
+ * @property {ChainId} chainId - The ID of the network to switch to.
622
+ */
572
623
  interface SwitchNetworkParams {
573
624
  provider: Web3Provider;
574
625
  chainId: ChainId;
575
626
  }
627
+ /**
628
+ * Interface representing the result of {@link Checkout.switchNetwork}.
629
+ * @property {NetworkInfo} network - The information of the network that was switched to.
630
+ */
576
631
  interface SwitchNetworkResult {
577
632
  network: NetworkInfo;
633
+ provider: Web3Provider;
634
+ }
635
+ /**
636
+ * * Interface representing the parameters for {@link Checkout.getNetworkInfo}.
637
+ * @property {Web3Provider} provider - The provider to connect to the network.
638
+ */
639
+ interface GetNetworkParams {
640
+ provider: Web3Provider;
641
+ }
642
+ /**
643
+ * Enum representing the types of filters that can be applied to get the allow list of networks.
644
+ */
645
+ declare enum NetworkFilterTypes {
646
+ ALL = "all"
647
+ }
648
+ /**
649
+ * Interface representing a filter for filtering a specific network.
650
+ * @property {ChainId} chainId - The ID of the network to allow or disallow.
651
+ */
652
+ interface NetworkFilter {
653
+ chainId: ChainId;
578
654
  }
655
+ /**
656
+ * * Interface representing the parameters for {@link Checkout.getNetworkAllowList}.
657
+ * @property {NetworkFilterTypes} type - The type of allow list filter to apply.
658
+ * @property {NetworkFilter[]} [exclude] - The list of networks to exclude from the allow list.
659
+ */
660
+ interface GetNetworkAllowListParams {
661
+ type: NetworkFilterTypes;
662
+ exclude?: NetworkFilter[];
663
+ }
664
+ /**
665
+ * Interface representing the result of {@link Checkout.getNetworkAllowList}.
666
+ * @property {NetworkInfo[]} networks - The list of allowed networks.
667
+ */
668
+ interface GetNetworkAllowListResult {
669
+ networks: NetworkInfo[];
670
+ }
671
+ /**
672
+ * Interface representing the parameters for {@link Checkout.getBalance}.
673
+ * @property {@link Web3Provider} provider - The provider to connect to the network.
674
+ * @property {string} walletAddress - The wallet address.
675
+ * @property {string | undefined} contractAddress - The contract address of the token.
676
+ */
579
677
  interface GetBalanceParams {
580
678
  provider: Web3Provider;
581
679
  walletAddress: string;
582
680
  contractAddress?: string;
583
681
  }
682
+ /**
683
+ * Interface representing the result of {@link Checkout.getBalance}.
684
+ * @property {BigNumber} balance - The balance of the wallet for the token.
685
+ * @property {string} formattedBalance - The formatted balance of the wallet for the token.
686
+ * @property {TokenInfo} token - The token information.
687
+ */
584
688
  interface GetBalanceResult {
585
689
  balance: BigNumber;
586
690
  formattedBalance: string;
587
691
  token: TokenInfo;
588
692
  }
693
+ /**
694
+ * Interface representing the parameters for {@link Checkout.getAllBalances}.
695
+ * @property {Web3Provider} provider - The provider to connect to the network.
696
+ * @property {string} walletAddress - The wallet address.
697
+ * @property {ChainId} chainId - The ID of the network.
698
+ */
589
699
  interface GetAllBalancesParams {
590
700
  provider: Web3Provider;
591
701
  walletAddress: string;
592
702
  chainId: ChainId;
593
703
  }
704
+ /**
705
+ * Interface representing the result of {@link Checkout.getAllBalances}.
706
+ * @property {GetBalanceResult[]} balances - The array of balances of the wallet for every token.
707
+ */
594
708
  interface GetAllBalancesResult {
595
709
  balances: GetBalanceResult[];
596
710
  }
711
+ /**
712
+ * Enum representing the list of default supported providers.
713
+ */
597
714
  declare enum ConnectionProviders {
598
715
  METAMASK = "metamask"
599
716
  }
717
+ /**
718
+ * Interface representing the parameters for {@link Checkout.connect}.
719
+ * @property {ConnectionProviders} providerPreference - The preferred provider to connect to the network.
720
+ */
600
721
  type ConnectParams = {
601
722
  providerPreference: ConnectionProviders;
602
723
  };
724
+ /**
725
+ * Interface representing the result of {@link Checkout.connect}.
726
+ * @property {Web3Provider} provider - The provider used to connect to the network.
727
+ * @property {NetworkInfo} network - Information about the connected network.
728
+ */
603
729
  interface ConnectResult {
604
730
  provider: Web3Provider;
605
731
  network: NetworkInfo;
606
732
  }
733
+ /**
734
+ * Interface representing the parameters for {@link Checkout.checkIsWalletConnected}.
735
+ * @property {ConnectionProviders} providerPreference - The preferred provider to use to check the connection status to th Web3 network.
736
+ */
607
737
  interface CheckConnectionParams {
608
738
  providerPreference: ConnectionProviders;
609
739
  }
740
+ /**
741
+ * Interface representing the result of {@link Checkout.checkIsWalletConnected}.
742
+ * @property {boolean} isConnected - A boolean indicating the connection status of th Web3 provider.
743
+ * @property {string} walletAddress - The wallet address used to check the connection.
744
+ */
610
745
  interface CheckConnectionResult {
611
746
  isConnected: boolean;
612
747
  walletAddress: string;
613
748
  }
749
+ /**
750
+ * Interface representing the parameters for {@link Checkout.sendTransaction}.
751
+ * @property {Web3Provider} provider - The provider to connect to the network.
752
+ * @property {Transaction} transaction - The transaction to send.
753
+ */
614
754
  interface SendTransactionParams {
615
755
  provider: Web3Provider;
616
756
  transaction: Transaction;
617
757
  }
758
+ /**
759
+ * Interface representing the result of {@link Checkout.sendTransaction}.
760
+ * @property {TransactionResponse} transactionResponse - The response of the transaction.
761
+ */
618
762
  interface SendTransactionResult {
619
763
  transactionResponse: TransactionResponse;
620
764
  }
765
+ /**
766
+ * Interface representing a blockchain transaction.
767
+ * @property {string} nonce - The transaction nonce.
768
+ * @property {string} gasPrice - The gas price of the transaction.
769
+ * @property {string} gas - The gas limit for the transaction.
770
+ * @property {string} to - The address of the recipient.
771
+ * @property {string} from - The address of the sender.
772
+ * @property {string} value - The value to transfer in wei.
773
+ * @property {string} data - The data to include in the transaction.
774
+ * @property {number} chainId - The ID of the chain the transaction is for.
775
+ */
621
776
  interface Transaction {
622
777
  nonce: string;
623
778
  gasPrice: string;
@@ -628,14 +783,150 @@ interface Transaction {
628
783
  data: string;
629
784
  chainId: number;
630
785
  }
786
+ /**
787
+ * Interface representing a wallet filter to be used in {@link GetWalletAllowListParams}.
788
+ * @property {ConnectionProviders} connectionProvider - The connection provider to filter wallets by.
789
+ */
790
+ interface WalletFilter {
791
+ connectionProvider: ConnectionProviders;
792
+ }
793
+ /**
794
+ * Interface representing the parameters for {@link Checkout.getWalletAllowList}.
795
+ * @property {WalletFilterTypes} type - The type of wallets to filter by.
796
+ * @property {WalletFilter[]} [exclude] - An optional list of wallet filters to exclude from the allowed wallets list.
797
+ */
798
+ interface GetWalletAllowListParams {
799
+ type: WalletFilterTypes;
800
+ exclude?: WalletFilter[];
801
+ }
802
+ /**
803
+ * Interface representing information about a wallet used in {@link GetWalletAllowListResult}.
804
+ * @property {ConnectionProviders} connectionProvider - The connection provider for the wallet.
805
+ * @property {string} name - The name of the wallet.
806
+ * @property {string} description - A description of the wallet.
807
+ * @property {string} icon - The URL/data:image of an icon for the wallet.
808
+ */
809
+ interface WalletInfo {
810
+ connectionProvider: ConnectionProviders;
811
+ name: string;
812
+ description: string;
813
+ icon: string;
814
+ }
815
+ /**
816
+ * Interface representing the result of {@link Checkout.getWalletAllowList}.
817
+ * @property {WalletInfo[]} wallets - A list of {@link WalletInfo} objects representing the allowed wallets.
818
+ */
819
+ interface GetWalletAllowListResult {
820
+ wallets: WalletInfo[];
821
+ }
822
+ /**
823
+ * Enum representing the platform filters used in {@link GetWalletAllowListParams}.
824
+ */
825
+ declare enum WalletFilterTypes {
826
+ ALL = "all",
827
+ DESKTOP = "desktop",
828
+ MOBILE = "mobile"
829
+ }
830
+ /**
831
+ * The different types of errors that can be returned by the checkout process.
832
+ */
833
+ declare enum CheckoutErrorType {
834
+ PROVIDER_PREFERENCE_ERROR = "PROVIDER_PREFERENCE_ERROR",
835
+ CONNECT_PROVIDER_ERROR = "CONNECT_PROVIDER_ERROR",
836
+ GET_BALANCE_ERROR = "GET_BALANCE_ERROR",
837
+ GET_ERC20_BALANCE_ERROR = "GET_ERC20_BALANCE_ERROR",
838
+ GET_NETWORK_INFO_ERROR = "GET_NETWORK_INFO_ERROR",
839
+ METAMASK_PROVIDER_ERROR = "METAMASK_PROVIDER_ERROR",
840
+ CHAIN_NOT_SUPPORTED_ERROR = "CHAIN_NOT_SUPPORTED_ERROR",
841
+ PROVIDER_REQUEST_MISSING_ERROR = "PROVIDER_REQUEST_MISSING_ERROR",
842
+ PROVIDER_REQUEST_FAILED_ERROR = "PROVIDER_REQUEST_FAILED_ERROR",
843
+ USER_REJECTED_REQUEST_ERROR = "USER_REJECTED_REQUEST_ERROR",
844
+ TRANSACTION_ERROR = "TRANSACTION_ERROR"
845
+ }
846
+ /**
847
+ * The type signature for an error.
848
+ * Contains a type that corresponds to a {@link CheckoutErrorType}, an optional message string and optional data object.
849
+ */
850
+ type ErrorType = {
851
+ type: CheckoutErrorType;
852
+ message?: string;
853
+ data?: {
854
+ [key: string]: string;
855
+ };
856
+ };
631
857
  declare class Checkout {
858
+ /**
859
+ * Check if a wallet is connected to the current application without requesting permission from the wallet and hence triggering a connect popup.
860
+ * @param {CheckConnectionParams} params - The necessary data required to verify a wallet connection status.
861
+ * @returns Wallet connection status details.
862
+ * @throws {@link ErrorType}
863
+ */
632
864
  checkIsWalletConnected(params: CheckConnectionParams): Promise<CheckConnectionResult>;
865
+ /**
866
+ * Establish a connection with a wallet provider such as MetaMask and returns the provider object and the current network details.
867
+ * @param {ConnectParams} params - The necessary data required to establish a connection with a wallet provider.
868
+ * @returns Wallet provider and current network information.
869
+ * @throws {@link ErrorType}
870
+ */
633
871
  connect(params: ConnectParams): Promise<ConnectResult>;
872
+ /**
873
+ * Switch the currently connected wallet to a new network.
874
+ * @param {SwitchNetworkParams} params - The necessary data required to switch network.
875
+ * @returns The new network information.
876
+ * @throws {@link ErrorType}
877
+ */
634
878
  switchNetwork(params: SwitchNetworkParams): Promise<SwitchNetworkResult>;
879
+ /**
880
+ * Fetch the balance of the native token of the current connected network or, if a contract address is provided, it will return the balance of that ERC20 token. For example, if the wallet is connected to the Ethereum Mainnet then the function gets the wallet ETH L1 balance.
881
+ * @param {GetBalanceParams} params - The necessary data required to fetch the wallet balance.
882
+ * @returns Native token balance for the given wallet.
883
+ * @throws {@link ErrorType}
884
+ */
635
885
  getBalance(params: GetBalanceParams): Promise<GetBalanceResult>;
886
+ /**
887
+ * Fetch all available balances (ERC20 & Native) of the current connected network of the given wallet. It will loop through the list of allowed tokens and check for balance on each one.
888
+ * @param {GetAllBalancesParams} params - The necessary data required to fetch all the wallet balances.
889
+ * @returns List of tokens balance for the given wallet.
890
+ * @throws {@link ErrorType}
891
+ */
636
892
  getAllBalances(params: GetAllBalancesParams): Promise<GetAllBalancesResult>;
637
- getTokenAllowList(params: GetTokenAllowListParams): GetTokenAllowListResult;
893
+ /**
894
+ * Fetch the list of available networks that a wallet can add or/and switch to.
895
+ * @param {GetNetworkAllowListParams} params - The necessary data required to fetch the list of available networks.
896
+ * @returns List of networks.
897
+ * @throws {@link ErrorType}
898
+ */
899
+ getNetworkAllowList(params: GetNetworkAllowListParams): Promise<GetNetworkAllowListResult>;
900
+ /**
901
+ * Get the list of tokens which are allowed to be used with the product.
902
+ * @param {GetTokenAllowListParams} params - The necessary data required to fetch the list of allowed tokens.
903
+ * @returns List of allowed tokens.
904
+ * @throws {@link ErrorType}
905
+ */
906
+ getTokenAllowList(params: GetTokenAllowListParams): Promise<GetTokenAllowListResult>;
907
+ /**
908
+ * Fetch the list of wallets which are available to connect with.
909
+ * @param {GetWalletAllowListParams} params - The necessary data required to fetch the list of allowed wallets.
910
+ * @returns List of allowed wallets.
911
+ * @throws {@link ErrorType}
912
+ */
913
+ getWalletAllowList(params: GetWalletAllowListParams): Promise<GetWalletAllowListResult>;
914
+ /**
915
+ * Send a generic transaction to the provider.
916
+ * @param {SendTransactionParams} params - The necessary data required to send a transaction.
917
+ * @returns Transaction response.
918
+ * @throws {@link ErrorType}
919
+ * @remarks
920
+ * Further documenation can be found at [MetaMask | Sending Transactions](https://docs.metamask.io/guide/sending-transactions.html).
921
+ */
638
922
  sendTransaction(params: SendTransactionParams): Promise<SendTransactionResult>;
923
+ /**
924
+ * Get network information about the currently selected network.
925
+ * @param {GetNetworkParams} params - The necessary data required to get the current network information.
926
+ * @returns Network details.
927
+ * @throws {@link ErrorType}
928
+ */
929
+ getNetworkInfo(params: GetNetworkParams): Promise<NetworkInfo>;
639
930
  }
640
931
 
641
- export { ChainId, CheckConnectionParams, CheckConnectionResult, Checkout, ConnectParams, ConnectResult, ConnectionProviders, GetAllBalancesParams, GetAllBalancesResult, GetBalanceParams, GetBalanceResult, GetTokenAllowListParams, GetTokenAllowListResult, NetworkInfo, SendTransactionParams, SendTransactionResult, SwitchNetworkParams, SwitchNetworkResult, TokenInfo };
932
+ export { ChainId, CheckConnectionParams, CheckConnectionResult, Checkout, CheckoutErrorType, ConnectParams, ConnectResult, ConnectionProviders, ErrorType, GetAllBalancesParams, GetAllBalancesResult, GetBalanceParams, GetBalanceResult, GetNetworkAllowListParams, GetNetworkAllowListResult, GetNetworkParams, GetTokenAllowListParams, GetTokenAllowListResult, GetWalletAllowListParams, GetWalletAllowListResult, NetworkFilter, NetworkFilterTypes, NetworkInfo, SendTransactionParams, SendTransactionResult, SwitchNetworkParams, SwitchNetworkResult, TokenFilter, TokenFilterTypes, TokenInfo, Transaction, WalletFilter, WalletFilterTypes, WalletInfo };