@imtbl/sdk 0.0.1-alpha.3 → 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,98 +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 {
557
571
  type: TokenFilterTypes;
558
572
  chainId: ChainId;
559
573
  exclude?: TokenFilter[];
560
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
+ */
561
579
  interface GetTokenAllowListResult {
562
580
  tokens: TokenInfo[];
563
581
  }
582
+ /**
583
+ * Enum representing the types of token filters available.
584
+ */
564
585
  declare enum TokenFilterTypes {
565
586
  SWAP = "swap",
566
587
  BRIDGE = "bridge",
567
588
  ALL = "all"
568
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
+ */
569
594
  interface TokenFilter {
570
595
  address: string;
571
596
  }
597
+ /**
598
+ * Enum representing the supported chains with their corresponding IDs.
599
+ */
572
600
  declare enum ChainId {
573
601
  ETHEREUM = 1,
574
602
  GOERLI = 5,
575
603
  POLYGON = 137
576
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
+ */
577
612
  interface NetworkInfo {
578
613
  name: string;
579
614
  chainId: number;
580
615
  nativeCurrency: TokenInfo;
581
616
  isSupported: boolean;
582
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
+ */
583
623
  interface SwitchNetworkParams {
584
624
  provider: Web3Provider;
585
625
  chainId: ChainId;
586
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
+ */
587
631
  interface SwitchNetworkResult {
588
632
  network: NetworkInfo;
633
+ provider: Web3Provider;
589
634
  }
635
+ /**
636
+ * * Interface representing the parameters for {@link Checkout.getNetworkInfo}.
637
+ * @property {Web3Provider} provider - The provider to connect to the network.
638
+ */
590
639
  interface GetNetworkParams {
591
640
  provider: Web3Provider;
592
641
  }
642
+ /**
643
+ * Enum representing the types of filters that can be applied to get the allow list of networks.
644
+ */
593
645
  declare enum NetworkFilterTypes {
594
646
  ALL = "all"
595
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
+ */
596
652
  interface NetworkFilter {
597
653
  chainId: ChainId;
598
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
+ */
599
660
  interface GetNetworkAllowListParams {
600
661
  type: NetworkFilterTypes;
601
662
  exclude?: NetworkFilter[];
602
663
  }
664
+ /**
665
+ * Interface representing the result of {@link Checkout.getNetworkAllowList}.
666
+ * @property {NetworkInfo[]} networks - The list of allowed networks.
667
+ */
603
668
  interface GetNetworkAllowListResult {
604
669
  networks: NetworkInfo[];
605
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
+ */
606
677
  interface GetBalanceParams {
607
678
  provider: Web3Provider;
608
679
  walletAddress: string;
609
680
  contractAddress?: string;
610
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
+ */
611
688
  interface GetBalanceResult {
612
689
  balance: BigNumber;
613
690
  formattedBalance: string;
614
691
  token: TokenInfo;
615
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
+ */
616
699
  interface GetAllBalancesParams {
617
700
  provider: Web3Provider;
618
701
  walletAddress: string;
619
702
  chainId: ChainId;
620
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
+ */
621
708
  interface GetAllBalancesResult {
622
709
  balances: GetBalanceResult[];
623
710
  }
711
+ /**
712
+ * Enum representing the list of default supported providers.
713
+ */
624
714
  declare enum ConnectionProviders {
625
715
  METAMASK = "metamask"
626
716
  }
717
+ /**
718
+ * Interface representing the parameters for {@link Checkout.connect}.
719
+ * @property {ConnectionProviders} providerPreference - The preferred provider to connect to the network.
720
+ */
627
721
  type ConnectParams = {
628
722
  providerPreference: ConnectionProviders;
629
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
+ */
630
729
  interface ConnectResult {
631
730
  provider: Web3Provider;
632
731
  network: NetworkInfo;
633
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
+ */
634
737
  interface CheckConnectionParams {
635
738
  providerPreference: ConnectionProviders;
636
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
+ */
637
745
  interface CheckConnectionResult {
638
746
  isConnected: boolean;
639
747
  walletAddress: string;
640
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
+ */
641
754
  interface SendTransactionParams {
642
755
  provider: Web3Provider;
643
756
  transaction: Transaction;
644
757
  }
758
+ /**
759
+ * Interface representing the result of {@link Checkout.sendTransaction}.
760
+ * @property {TransactionResponse} transactionResponse - The response of the transaction.
761
+ */
645
762
  interface SendTransactionResult {
646
763
  transactionResponse: TransactionResponse;
647
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
+ */
648
776
  interface Transaction {
649
777
  nonce: string;
650
778
  gasPrice: string;
@@ -655,38 +783,150 @@ interface Transaction {
655
783
  data: string;
656
784
  chainId: number;
657
785
  }
658
- declare enum WalletFilterTypes {
659
- ALL = "all",
660
- DESKTOP = "desktop",
661
- MOBILE = "mobile"
662
- }
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
+ */
663
790
  interface WalletFilter {
664
791
  connectionProvider: ConnectionProviders;
665
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
+ */
666
798
  interface GetWalletAllowListParams {
667
799
  type: WalletFilterTypes;
668
800
  exclude?: WalletFilter[];
669
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
+ */
670
809
  interface WalletInfo {
671
810
  connectionProvider: ConnectionProviders;
672
811
  name: string;
673
812
  description: string;
674
813
  icon: string;
675
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
+ */
676
819
  interface GetWalletAllowListResult {
677
820
  wallets: WalletInfo[];
678
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
+ };
679
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
+ */
680
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
+ */
681
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
+ */
682
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
+ */
683
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
+ */
684
892
  getAllBalances(params: GetAllBalancesParams): Promise<GetAllBalancesResult>;
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
+ */
685
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
+ */
686
906
  getTokenAllowList(params: GetTokenAllowListParams): Promise<GetTokenAllowListResult>;
687
- getWalletsAllowList(params: GetWalletAllowListParams): Promise<GetWalletAllowListResult>;
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
+ */
688
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
+ */
689
929
  getNetworkInfo(params: GetNetworkParams): Promise<NetworkInfo>;
690
930
  }
691
931
 
692
- export { ChainId, CheckConnectionParams, CheckConnectionResult, Checkout, ConnectParams, ConnectResult, ConnectionProviders, GetAllBalancesParams, GetAllBalancesResult, GetBalanceParams, GetBalanceResult, GetNetworkAllowListParams, GetNetworkAllowListResult, GetTokenAllowListParams, GetTokenAllowListResult, GetWalletAllowListParams, GetWalletAllowListResult, NetworkFilter, NetworkFilterTypes, NetworkInfo, SendTransactionParams, SendTransactionResult, SwitchNetworkParams, SwitchNetworkResult, TokenFilter, TokenFilterTypes, TokenInfo, WalletFilter, WalletFilterTypes, WalletInfo };
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 };