@dynamic-labs/ethereum-core 3.0.0-alpha.49

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.
Files changed (91) hide show
  1. package/CHANGELOG.md +3894 -0
  2. package/LICENSE +21 -0
  3. package/README.md +11 -0
  4. package/_virtual/_tslib.cjs +49 -0
  5. package/_virtual/_tslib.js +44 -0
  6. package/package.json +37 -0
  7. package/src/index.cjs +34 -0
  8. package/src/index.d.ts +1 -0
  9. package/src/index.js +13 -0
  10. package/src/lib/utils/index.d.ts +2 -0
  11. package/src/lib/utils/logger.cjs +10 -0
  12. package/src/lib/utils/logger.d.ts +2 -0
  13. package/src/lib/utils/logger.js +6 -0
  14. package/src/lib/utils/validateAddressFormat.cjs +8 -0
  15. package/src/lib/utils/validateAddressFormat.d.ts +1 -0
  16. package/src/lib/utils/validateAddressFormat.js +4 -0
  17. package/src/lib/utils/viem/Eip1559FeeFeed.cjs +51 -0
  18. package/src/lib/utils/viem/Eip1559FeeFeed.d.ts +20 -0
  19. package/src/lib/utils/viem/Eip1559FeeFeed.js +47 -0
  20. package/src/lib/utils/viem/ViemRpcUiTransaction/ViemRpcUiTransaction.cjs +98 -0
  21. package/src/lib/utils/viem/ViemRpcUiTransaction/ViemRpcUiTransaction.d.ts +37 -0
  22. package/src/lib/utils/viem/ViemRpcUiTransaction/ViemRpcUiTransaction.js +94 -0
  23. package/src/lib/utils/viem/ViemRpcUiTransaction/index.d.ts +1 -0
  24. package/src/lib/utils/viem/ViemUiTransaction/ViemUiTransaction.cjs +121 -0
  25. package/src/lib/utils/viem/ViemUiTransaction/ViemUiTransaction.d.ts +56 -0
  26. package/src/lib/utils/viem/ViemUiTransaction/ViemUiTransaction.js +117 -0
  27. package/src/lib/utils/viem/ViemUiTransaction/index.d.ts +2 -0
  28. package/src/lib/utils/viem/chainsMap/chainsMap.cjs +31 -0
  29. package/src/lib/utils/viem/chainsMap/chainsMap.d.ts +2 -0
  30. package/src/lib/utils/viem/chainsMap/chainsMap.js +7 -0
  31. package/src/lib/utils/viem/chainsMap/index.d.ts +1 -0
  32. package/src/lib/utils/viem/confirmationTransport/confirmationTransport.cjs +39 -0
  33. package/src/lib/utils/viem/confirmationTransport/confirmationTransport.d.ts +11 -0
  34. package/src/lib/utils/viem/confirmationTransport/confirmationTransport.js +35 -0
  35. package/src/lib/utils/viem/confirmationTransport/index.d.ts +1 -0
  36. package/src/lib/utils/viem/createAccountWithUiConfirmation/createAccountWithUiConfirmation.cjs +41 -0
  37. package/src/lib/utils/viem/createAccountWithUiConfirmation/createAccountWithUiConfirmation.d.ts +12 -0
  38. package/src/lib/utils/viem/createAccountWithUiConfirmation/createAccountWithUiConfirmation.js +37 -0
  39. package/src/lib/utils/viem/createAccountWithUiConfirmation/index.d.ts +1 -0
  40. package/src/lib/utils/viem/createTransportWithUiConfirmation/createTransportWithUiConfirmation.cjs +33 -0
  41. package/src/lib/utils/viem/createTransportWithUiConfirmation/createTransportWithUiConfirmation.d.ts +25 -0
  42. package/src/lib/utils/viem/createTransportWithUiConfirmation/createTransportWithUiConfirmation.js +29 -0
  43. package/src/lib/utils/viem/createTransportWithUiConfirmation/index.d.ts +1 -0
  44. package/src/lib/utils/viem/createViemUiTransaction/createViemUiTransaction.cjs +40 -0
  45. package/src/lib/utils/viem/createViemUiTransaction/createViemUiTransaction.d.ts +9 -0
  46. package/src/lib/utils/viem/createViemUiTransaction/createViemUiTransaction.js +36 -0
  47. package/src/lib/utils/viem/createViemUiTransaction/index.d.ts +1 -0
  48. package/src/lib/utils/viem/createWalletClientFromWallet/createWalletClientFromWallet.cjs +70 -0
  49. package/src/lib/utils/viem/createWalletClientFromWallet/createWalletClientFromWallet.d.ts +19 -0
  50. package/src/lib/utils/viem/createWalletClientFromWallet/createWalletClientFromWallet.js +46 -0
  51. package/src/lib/utils/viem/createWalletClientFromWallet/index.d.ts +1 -0
  52. package/src/lib/utils/viem/createWalletClientWithUiConfirmation/createWalletClientWithUiConfirmation.cjs +73 -0
  53. package/src/lib/utils/viem/createWalletClientWithUiConfirmation/createWalletClientWithUiConfirmation.d.ts +29 -0
  54. package/src/lib/utils/viem/createWalletClientWithUiConfirmation/createWalletClientWithUiConfirmation.js +69 -0
  55. package/src/lib/utils/viem/createWalletClientWithUiConfirmation/index.d.ts +1 -0
  56. package/src/lib/utils/viem/erc20/abi.cjs +230 -0
  57. package/src/lib/utils/viem/erc20/abi.d.ts +38 -0
  58. package/src/lib/utils/viem/erc20/abi.js +226 -0
  59. package/src/lib/utils/viem/erc20/index.d.ts +1 -0
  60. package/src/lib/utils/viem/estimateL1Fee/estimateL1Fee.cjs +31 -0
  61. package/src/lib/utils/viem/estimateL1Fee/estimateL1Fee.d.ts +10 -0
  62. package/src/lib/utils/viem/estimateL1Fee/estimateL1Fee.js +26 -0
  63. package/src/lib/utils/viem/estimateL1Fee/index.d.ts +1 -0
  64. package/src/lib/utils/viem/estimateL1Fee/opStack/abi.cjs +23 -0
  65. package/src/lib/utils/viem/estimateL1Fee/opStack/abi.d.ts +20 -0
  66. package/src/lib/utils/viem/estimateL1Fee/opStack/abi.js +18 -0
  67. package/src/lib/utils/viem/estimateL1Fee/opStack/estimateL1Fee.cjs +30 -0
  68. package/src/lib/utils/viem/estimateL1Fee/opStack/estimateL1Fee.d.ts +3 -0
  69. package/src/lib/utils/viem/estimateL1Fee/opStack/estimateL1Fee.js +25 -0
  70. package/src/lib/utils/viem/estimateL1Fee/opStack/index.d.ts +1 -0
  71. package/src/lib/utils/viem/formatEther/formatEther.cjs +11 -0
  72. package/src/lib/utils/viem/formatEther/formatEther.d.ts +2 -0
  73. package/src/lib/utils/viem/formatEther/formatEther.js +7 -0
  74. package/src/lib/utils/viem/formatEther/index.d.ts +1 -0
  75. package/src/lib/utils/viem/getOrMapViemChain/getOrMapViemChain.cjs +77 -0
  76. package/src/lib/utils/viem/getOrMapViemChain/getOrMapViemChain.d.ts +11 -0
  77. package/src/lib/utils/viem/getOrMapViemChain/getOrMapViemChain.js +51 -0
  78. package/src/lib/utils/viem/getOrMapViemChain/index.d.ts +1 -0
  79. package/src/lib/utils/viem/index.d.ts +11 -0
  80. package/src/lib/utils/viem/interceptTransport/index.d.ts +1 -0
  81. package/src/lib/utils/viem/interceptTransport/interceptTransport.cjs +35 -0
  82. package/src/lib/utils/viem/interceptTransport/interceptTransport.d.ts +29 -0
  83. package/src/lib/utils/viem/interceptTransport/interceptTransport.js +31 -0
  84. package/src/lib/utils/viem/parseEther/index.d.ts +1 -0
  85. package/src/lib/utils/viem/parseEther/parseEther.cjs +10 -0
  86. package/src/lib/utils/viem/parseEther/parseEther.d.ts +1 -0
  87. package/src/lib/utils/viem/parseEther/parseEther.js +6 -0
  88. package/src/lib/utils/viem/unFormatTransaction/index.d.ts +1 -0
  89. package/src/lib/utils/viem/unFormatTransaction/unFormatTransaction.cjs +30 -0
  90. package/src/lib/utils/viem/unFormatTransaction/unFormatTransaction.d.ts +8 -0
  91. package/src/lib/utils/viem/unFormatTransaction/unFormatTransaction.js +26 -0
@@ -0,0 +1,40 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../../../_virtual/_tslib.cjs');
7
+ var abi = require('../erc20/abi.cjs');
8
+ var ViemUiTransaction = require('../ViemUiTransaction/ViemUiTransaction.cjs');
9
+
10
+ const createViemUiTransaction = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ from, publicClient, walletClient, }) {
11
+ return new ViemUiTransaction.ViemUiTransaction({
12
+ account: from,
13
+ onSubmit: (transaction) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
14
+ // Non native token
15
+ if (transaction.nonNativeAddress) {
16
+ return walletClient.writeContract({
17
+ abi: abi.erc20Abi,
18
+ account: from,
19
+ address: transaction.nonNativeAddress,
20
+ args: [transaction.to, transaction.nonNativeValue],
21
+ functionName: 'transfer',
22
+ maxFeePerGas: transaction.maxFeePerGas,
23
+ maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,
24
+ });
25
+ }
26
+ // Native token
27
+ return walletClient.sendTransaction({
28
+ account: from,
29
+ maxFeePerGas: transaction.maxFeePerGas,
30
+ maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,
31
+ to: transaction.to,
32
+ value: transaction.value,
33
+ });
34
+ }),
35
+ publicClient,
36
+ transaction: {},
37
+ });
38
+ });
39
+
40
+ exports.createViemUiTransaction = createViemUiTransaction;
@@ -0,0 +1,9 @@
1
+ import { Chain, PublicClient, Transport, WalletClient } from 'viem';
2
+ import { ViemUiTransaction } from '../ViemUiTransaction';
3
+ type CreateViemUiTransactionProps = {
4
+ publicClient: PublicClient<Transport, Chain>;
5
+ walletClient: WalletClient<Transport, Chain>;
6
+ from: string;
7
+ };
8
+ export declare const createViemUiTransaction: ({ from, publicClient, walletClient, }: CreateViemUiTransactionProps) => Promise<ViemUiTransaction>;
9
+ export {};
@@ -0,0 +1,36 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../../../../_virtual/_tslib.js';
3
+ import { erc20Abi } from '../erc20/abi.js';
4
+ import { ViemUiTransaction } from '../ViemUiTransaction/ViemUiTransaction.js';
5
+
6
+ const createViemUiTransaction = (_a) => __awaiter(void 0, [_a], void 0, function* ({ from, publicClient, walletClient, }) {
7
+ return new ViemUiTransaction({
8
+ account: from,
9
+ onSubmit: (transaction) => __awaiter(void 0, void 0, void 0, function* () {
10
+ // Non native token
11
+ if (transaction.nonNativeAddress) {
12
+ return walletClient.writeContract({
13
+ abi: erc20Abi,
14
+ account: from,
15
+ address: transaction.nonNativeAddress,
16
+ args: [transaction.to, transaction.nonNativeValue],
17
+ functionName: 'transfer',
18
+ maxFeePerGas: transaction.maxFeePerGas,
19
+ maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,
20
+ });
21
+ }
22
+ // Native token
23
+ return walletClient.sendTransaction({
24
+ account: from,
25
+ maxFeePerGas: transaction.maxFeePerGas,
26
+ maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,
27
+ to: transaction.to,
28
+ value: transaction.value,
29
+ });
30
+ }),
31
+ publicClient,
32
+ transaction: {},
33
+ });
34
+ });
35
+
36
+ export { createViemUiTransaction };
@@ -0,0 +1 @@
1
+ export { createViemUiTransaction } from './createViemUiTransaction';
@@ -0,0 +1,70 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../../../_virtual/_tslib.cjs');
7
+ var viem = require('viem');
8
+ var chains = require('viem/chains');
9
+
10
+ function _interopNamespace(e) {
11
+ if (e && e.__esModule) return e;
12
+ var n = Object.create(null);
13
+ if (e) {
14
+ Object.keys(e).forEach(function (k) {
15
+ if (k !== 'default') {
16
+ var d = Object.getOwnPropertyDescriptor(e, k);
17
+ Object.defineProperty(n, k, d.get ? d : {
18
+ enumerable: true,
19
+ get: function () { return e[k]; }
20
+ });
21
+ }
22
+ });
23
+ }
24
+ n["default"] = e;
25
+ return Object.freeze(n);
26
+ }
27
+
28
+ var chains__namespace = /*#__PURE__*/_interopNamespace(chains);
29
+
30
+ const findChain = (chainId) => Object.values(chains__namespace).find((chain) => chain.id.toString() === chainId.toString());
31
+ /**
32
+ * Creates a WalletClient instance from a given Wallet object.
33
+ *
34
+ * This function initializes a WalletClient with the appropriate transport, chain, and account
35
+ * details based on the provided Wallet.
36
+ *
37
+ * @param {Wallet} wallet - The wallet
38
+ * @returns {Promise<WalletClient<Transport, Chain, Account>>} - A promise that resolves to a WalletClient instance.
39
+ * @throws Will throw an error if the wallet's chain is not 'eip155', the wallet's network is not set, or the
40
+ * chain is not supported.
41
+ */
42
+ const createWalletClientFromWallet = (wallet) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
43
+ if (wallet.chain !== 'eip155') {
44
+ throw new Error(`Wallet chain "${wallet.chain}" is not viem compatible`);
45
+ }
46
+ const network = wallet.network || (yield wallet.connector.getNetwork());
47
+ if (!network) {
48
+ throw new Error('Wallet network is not set');
49
+ }
50
+ const walletClient = yield wallet.connector.getWalletClient();
51
+ const chain = walletClient.chain || findChain(network);
52
+ const account = getAccount(wallet, walletClient);
53
+ const transport = viem.custom(walletClient.transport);
54
+ if (chain === undefined) {
55
+ throw new Error(`Chain "${network}" is not supported.`);
56
+ }
57
+ return viem.createWalletClient({
58
+ account,
59
+ chain,
60
+ transport,
61
+ });
62
+ });
63
+ const getAccount = (wallet, walletClient) => {
64
+ if (walletClient.account && walletClient.account.type !== 'json-rpc') {
65
+ return walletClient.account;
66
+ }
67
+ return wallet.address;
68
+ };
69
+
70
+ exports.createWalletClientFromWallet = createWalletClientFromWallet;
@@ -0,0 +1,19 @@
1
+ import { Account, Chain, Transport, WalletClient } from 'viem';
2
+ import { BaseWallet } from '@dynamic-labs/types';
3
+ import { WalletConnector } from '@dynamic-labs/wallet-connector-core';
4
+ type WalletWithConnector = BaseWallet & {
5
+ connector: WalletConnector;
6
+ };
7
+ /**
8
+ * Creates a WalletClient instance from a given Wallet object.
9
+ *
10
+ * This function initializes a WalletClient with the appropriate transport, chain, and account
11
+ * details based on the provided Wallet.
12
+ *
13
+ * @param {Wallet} wallet - The wallet
14
+ * @returns {Promise<WalletClient<Transport, Chain, Account>>} - A promise that resolves to a WalletClient instance.
15
+ * @throws Will throw an error if the wallet's chain is not 'eip155', the wallet's network is not set, or the
16
+ * chain is not supported.
17
+ */
18
+ export declare const createWalletClientFromWallet: (wallet: WalletWithConnector) => Promise<WalletClient<Transport, Chain, Account>>;
19
+ export {};
@@ -0,0 +1,46 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../../../../_virtual/_tslib.js';
3
+ import { custom, createWalletClient } from 'viem';
4
+ import * as chains from 'viem/chains';
5
+
6
+ const findChain = (chainId) => Object.values(chains).find((chain) => chain.id.toString() === chainId.toString());
7
+ /**
8
+ * Creates a WalletClient instance from a given Wallet object.
9
+ *
10
+ * This function initializes a WalletClient with the appropriate transport, chain, and account
11
+ * details based on the provided Wallet.
12
+ *
13
+ * @param {Wallet} wallet - The wallet
14
+ * @returns {Promise<WalletClient<Transport, Chain, Account>>} - A promise that resolves to a WalletClient instance.
15
+ * @throws Will throw an error if the wallet's chain is not 'eip155', the wallet's network is not set, or the
16
+ * chain is not supported.
17
+ */
18
+ const createWalletClientFromWallet = (wallet) => __awaiter(void 0, void 0, void 0, function* () {
19
+ if (wallet.chain !== 'eip155') {
20
+ throw new Error(`Wallet chain "${wallet.chain}" is not viem compatible`);
21
+ }
22
+ const network = wallet.network || (yield wallet.connector.getNetwork());
23
+ if (!network) {
24
+ throw new Error('Wallet network is not set');
25
+ }
26
+ const walletClient = yield wallet.connector.getWalletClient();
27
+ const chain = walletClient.chain || findChain(network);
28
+ const account = getAccount(wallet, walletClient);
29
+ const transport = custom(walletClient.transport);
30
+ if (chain === undefined) {
31
+ throw new Error(`Chain "${network}" is not supported.`);
32
+ }
33
+ return createWalletClient({
34
+ account,
35
+ chain,
36
+ transport,
37
+ });
38
+ });
39
+ const getAccount = (wallet, walletClient) => {
40
+ if (walletClient.account && walletClient.account.type !== 'json-rpc') {
41
+ return walletClient.account;
42
+ }
43
+ return wallet.address;
44
+ };
45
+
46
+ export { createWalletClientFromWallet };
@@ -0,0 +1 @@
1
+ export { createWalletClientFromWallet } from './createWalletClientFromWallet';
@@ -0,0 +1,73 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../../../_virtual/_tslib.cjs');
7
+ var viem = require('viem');
8
+ var interceptTransport = require('../interceptTransport/interceptTransport.cjs');
9
+ var unFormatTransaction = require('../unFormatTransaction/unFormatTransaction.cjs');
10
+ var createAccountWithUiConfirmation = require('../createAccountWithUiConfirmation/createAccountWithUiConfirmation.cjs');
11
+
12
+ /**
13
+ * Creates a WalletClient with UI confirmation for sensitive actions.
14
+ *
15
+ * This function initializes a WalletClient instance that integrates with a UI
16
+ * for user confirmations. It wraps the provided transport with additional functionality
17
+ * to handle personal sign requests, transaction sending, and signing typed data by
18
+ * injecting UI confirmation steps before proceeding with the actual wallet actions.
19
+ *
20
+ * @param {Props} props - The properties required to create a WalletClient with UI confirmation.
21
+ * @param {LocalAccount} props.account - The local account to be used with the WalletClient.
22
+ * @param {Chain} props.chain - The blockchain chain to which the WalletClient will connect.
23
+ * @param {Transport} props.transport - The transport layer responsible for communication with the blockchain.
24
+ * @param {WalletUiUtils} props.walletUiUtils - The UI utility functions for the WalletConnector.
25
+ *
26
+ * @returns {WalletClient<Transport, Chain, Account>} An instance of WalletClient equipped with UI confirmation logic.
27
+ */
28
+ const createWalletClientWithUiConfirmation = ({ address, account, chain, transport, walletConnector, walletUiUtils, }) => {
29
+ let client = null;
30
+ const provider = viem.createPublicClient({
31
+ chain,
32
+ transport,
33
+ });
34
+ const gatedAccount = createAccountWithUiConfirmation.createAccountWithUiConfirmation({
35
+ account,
36
+ address,
37
+ provider,
38
+ walletConnector,
39
+ walletUiUtils: walletUiUtils,
40
+ });
41
+ const customTransport = interceptTransport.interceptTransport({
42
+ getAccounts: () => _tslib.__awaiter(void 0, void 0, void 0, function* () { return [address]; }),
43
+ onPersonalSign: (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ message }) {
44
+ if (!client)
45
+ throw new Error('Client not initialized');
46
+ return client.signMessage({
47
+ message: {
48
+ raw: message,
49
+ },
50
+ });
51
+ }),
52
+ onSendTransaction: (_b) => _tslib.__awaiter(void 0, [_b], void 0, function* ({ transaction }) {
53
+ if (!client)
54
+ throw new Error('Client not initialized');
55
+ const unFormattedTransaction = unFormatTransaction.unFormatTransaction(transaction);
56
+ return client.sendTransaction(unFormattedTransaction);
57
+ }),
58
+ onSignTypedData: (_c) => _tslib.__awaiter(void 0, [_c], void 0, function* ({ message }) {
59
+ if (!client)
60
+ throw new Error('Client not initialized');
61
+ return client.signTypedData(JSON.parse(message));
62
+ }),
63
+ transport,
64
+ });
65
+ client = viem.createWalletClient({
66
+ account: gatedAccount,
67
+ chain,
68
+ transport: customTransport,
69
+ });
70
+ return client;
71
+ };
72
+
73
+ exports.createWalletClientWithUiConfirmation = createWalletClientWithUiConfirmation;
@@ -0,0 +1,29 @@
1
+ import { Account, LocalAccount, Transport, WalletClient, Chain } from 'viem';
2
+ import { WalletUiUtils } from '@dynamic-labs/types';
3
+ import { WalletConnector } from '@dynamic-labs/wallet-connector-core';
4
+ type Props = {
5
+ address: `0x${string}`;
6
+ account: () => Promise<LocalAccount>;
7
+ chain: Chain;
8
+ transport: Transport;
9
+ walletConnector: WalletConnector;
10
+ walletUiUtils: WalletUiUtils<WalletConnector>;
11
+ };
12
+ /**
13
+ * Creates a WalletClient with UI confirmation for sensitive actions.
14
+ *
15
+ * This function initializes a WalletClient instance that integrates with a UI
16
+ * for user confirmations. It wraps the provided transport with additional functionality
17
+ * to handle personal sign requests, transaction sending, and signing typed data by
18
+ * injecting UI confirmation steps before proceeding with the actual wallet actions.
19
+ *
20
+ * @param {Props} props - The properties required to create a WalletClient with UI confirmation.
21
+ * @param {LocalAccount} props.account - The local account to be used with the WalletClient.
22
+ * @param {Chain} props.chain - The blockchain chain to which the WalletClient will connect.
23
+ * @param {Transport} props.transport - The transport layer responsible for communication with the blockchain.
24
+ * @param {WalletUiUtils} props.walletUiUtils - The UI utility functions for the WalletConnector.
25
+ *
26
+ * @returns {WalletClient<Transport, Chain, Account>} An instance of WalletClient equipped with UI confirmation logic.
27
+ */
28
+ export declare const createWalletClientWithUiConfirmation: ({ address, account, chain, transport, walletConnector, walletUiUtils, }: Props) => WalletClient<Transport, Chain, Account>;
29
+ export {};
@@ -0,0 +1,69 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../../../../_virtual/_tslib.js';
3
+ import { createPublicClient, createWalletClient } from 'viem';
4
+ import { interceptTransport } from '../interceptTransport/interceptTransport.js';
5
+ import { unFormatTransaction } from '../unFormatTransaction/unFormatTransaction.js';
6
+ import { createAccountWithUiConfirmation } from '../createAccountWithUiConfirmation/createAccountWithUiConfirmation.js';
7
+
8
+ /**
9
+ * Creates a WalletClient with UI confirmation for sensitive actions.
10
+ *
11
+ * This function initializes a WalletClient instance that integrates with a UI
12
+ * for user confirmations. It wraps the provided transport with additional functionality
13
+ * to handle personal sign requests, transaction sending, and signing typed data by
14
+ * injecting UI confirmation steps before proceeding with the actual wallet actions.
15
+ *
16
+ * @param {Props} props - The properties required to create a WalletClient with UI confirmation.
17
+ * @param {LocalAccount} props.account - The local account to be used with the WalletClient.
18
+ * @param {Chain} props.chain - The blockchain chain to which the WalletClient will connect.
19
+ * @param {Transport} props.transport - The transport layer responsible for communication with the blockchain.
20
+ * @param {WalletUiUtils} props.walletUiUtils - The UI utility functions for the WalletConnector.
21
+ *
22
+ * @returns {WalletClient<Transport, Chain, Account>} An instance of WalletClient equipped with UI confirmation logic.
23
+ */
24
+ const createWalletClientWithUiConfirmation = ({ address, account, chain, transport, walletConnector, walletUiUtils, }) => {
25
+ let client = null;
26
+ const provider = createPublicClient({
27
+ chain,
28
+ transport,
29
+ });
30
+ const gatedAccount = createAccountWithUiConfirmation({
31
+ account,
32
+ address,
33
+ provider,
34
+ walletConnector,
35
+ walletUiUtils: walletUiUtils,
36
+ });
37
+ const customTransport = interceptTransport({
38
+ getAccounts: () => __awaiter(void 0, void 0, void 0, function* () { return [address]; }),
39
+ onPersonalSign: (_a) => __awaiter(void 0, [_a], void 0, function* ({ message }) {
40
+ if (!client)
41
+ throw new Error('Client not initialized');
42
+ return client.signMessage({
43
+ message: {
44
+ raw: message,
45
+ },
46
+ });
47
+ }),
48
+ onSendTransaction: (_b) => __awaiter(void 0, [_b], void 0, function* ({ transaction }) {
49
+ if (!client)
50
+ throw new Error('Client not initialized');
51
+ const unFormattedTransaction = unFormatTransaction(transaction);
52
+ return client.sendTransaction(unFormattedTransaction);
53
+ }),
54
+ onSignTypedData: (_c) => __awaiter(void 0, [_c], void 0, function* ({ message }) {
55
+ if (!client)
56
+ throw new Error('Client not initialized');
57
+ return client.signTypedData(JSON.parse(message));
58
+ }),
59
+ transport,
60
+ });
61
+ client = createWalletClient({
62
+ account: gatedAccount,
63
+ chain,
64
+ transport: customTransport,
65
+ });
66
+ return client;
67
+ };
68
+
69
+ export { createWalletClientWithUiConfirmation };
@@ -0,0 +1 @@
1
+ export { createWalletClientWithUiConfirmation } from './createWalletClientWithUiConfirmation';
@@ -0,0 +1,230 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ /* eslint-disable max-len */
7
+ const erc20Abi = [
8
+ {
9
+ constant: true,
10
+ inputs: [],
11
+ name: 'name',
12
+ outputs: [
13
+ {
14
+ name: '',
15
+ type: 'string',
16
+ },
17
+ ],
18
+ payable: false,
19
+ stateMutability: 'view',
20
+ type: 'function',
21
+ },
22
+ {
23
+ constant: false,
24
+ inputs: [
25
+ {
26
+ name: '_spender',
27
+ type: 'address',
28
+ },
29
+ {
30
+ name: '_value',
31
+ type: 'uint256',
32
+ },
33
+ ],
34
+ name: 'approve',
35
+ outputs: [
36
+ {
37
+ name: '',
38
+ type: 'bool',
39
+ },
40
+ ],
41
+ payable: false,
42
+ stateMutability: 'nonpayable',
43
+ type: 'function',
44
+ },
45
+ {
46
+ constant: true,
47
+ inputs: [],
48
+ name: 'totalSupply',
49
+ outputs: [
50
+ {
51
+ name: '',
52
+ type: 'uint256',
53
+ },
54
+ ],
55
+ payable: false,
56
+ stateMutability: 'view',
57
+ type: 'function',
58
+ },
59
+ {
60
+ constant: false,
61
+ inputs: [
62
+ {
63
+ name: '_from',
64
+ type: 'address',
65
+ },
66
+ {
67
+ name: '_to',
68
+ type: 'address',
69
+ },
70
+ {
71
+ name: '_value',
72
+ type: 'uint256',
73
+ },
74
+ ],
75
+ name: 'transferFrom',
76
+ outputs: [
77
+ {
78
+ name: '',
79
+ type: 'bool',
80
+ },
81
+ ],
82
+ payable: false,
83
+ stateMutability: 'nonpayable',
84
+ type: 'function',
85
+ },
86
+ {
87
+ constant: true,
88
+ inputs: [],
89
+ name: 'decimals',
90
+ outputs: [
91
+ {
92
+ name: '',
93
+ type: 'uint8',
94
+ },
95
+ ],
96
+ payable: false,
97
+ stateMutability: 'view',
98
+ type: 'function',
99
+ },
100
+ {
101
+ constant: true,
102
+ inputs: [
103
+ {
104
+ name: '_owner',
105
+ type: 'address',
106
+ },
107
+ ],
108
+ name: 'balanceOf',
109
+ outputs: [
110
+ {
111
+ name: 'balance',
112
+ type: 'uint256',
113
+ },
114
+ ],
115
+ payable: false,
116
+ stateMutability: 'view',
117
+ type: 'function',
118
+ },
119
+ {
120
+ constant: true,
121
+ inputs: [],
122
+ name: 'symbol',
123
+ outputs: [
124
+ {
125
+ name: '',
126
+ type: 'string',
127
+ },
128
+ ],
129
+ payable: false,
130
+ stateMutability: 'view',
131
+ type: 'function',
132
+ },
133
+ {
134
+ constant: false,
135
+ inputs: [
136
+ {
137
+ name: '_to',
138
+ type: 'address',
139
+ },
140
+ {
141
+ name: '_value',
142
+ type: 'uint256',
143
+ },
144
+ ],
145
+ name: 'transfer',
146
+ outputs: [
147
+ {
148
+ name: '',
149
+ type: 'bool',
150
+ },
151
+ ],
152
+ payable: false,
153
+ stateMutability: 'nonpayable',
154
+ type: 'function',
155
+ },
156
+ {
157
+ constant: true,
158
+ inputs: [
159
+ {
160
+ name: '_owner',
161
+ type: 'address',
162
+ },
163
+ {
164
+ name: '_spender',
165
+ type: 'address',
166
+ },
167
+ ],
168
+ name: 'allowance',
169
+ outputs: [
170
+ {
171
+ name: '',
172
+ type: 'uint256',
173
+ },
174
+ ],
175
+ payable: false,
176
+ stateMutability: 'view',
177
+ type: 'function',
178
+ },
179
+ {
180
+ payable: true,
181
+ stateMutability: 'payable',
182
+ type: 'fallback',
183
+ },
184
+ {
185
+ anonymous: false,
186
+ inputs: [
187
+ {
188
+ indexed: true,
189
+ name: 'owner',
190
+ type: 'address',
191
+ },
192
+ {
193
+ indexed: true,
194
+ name: 'spender',
195
+ type: 'address',
196
+ },
197
+ {
198
+ indexed: false,
199
+ name: 'value',
200
+ type: 'uint256',
201
+ },
202
+ ],
203
+ name: 'Approval',
204
+ type: 'event',
205
+ },
206
+ {
207
+ anonymous: false,
208
+ inputs: [
209
+ {
210
+ indexed: true,
211
+ name: 'from',
212
+ type: 'address',
213
+ },
214
+ {
215
+ indexed: true,
216
+ name: 'to',
217
+ type: 'address',
218
+ },
219
+ {
220
+ indexed: false,
221
+ name: 'value',
222
+ type: 'uint256',
223
+ },
224
+ ],
225
+ name: 'Transfer',
226
+ type: 'event',
227
+ },
228
+ ];
229
+
230
+ exports.erc20Abi = erc20Abi;
@@ -0,0 +1,38 @@
1
+ export declare const erc20Abi: ({
2
+ constant: boolean;
3
+ inputs: {
4
+ name: string;
5
+ type: string;
6
+ }[];
7
+ name: string;
8
+ outputs: {
9
+ name: string;
10
+ type: string;
11
+ }[];
12
+ payable: boolean;
13
+ stateMutability: string;
14
+ type: string;
15
+ anonymous?: undefined;
16
+ } | {
17
+ payable: boolean;
18
+ stateMutability: string;
19
+ type: string;
20
+ constant?: undefined;
21
+ inputs?: undefined;
22
+ name?: undefined;
23
+ outputs?: undefined;
24
+ anonymous?: undefined;
25
+ } | {
26
+ anonymous: boolean;
27
+ inputs: {
28
+ indexed: boolean;
29
+ name: string;
30
+ type: string;
31
+ }[];
32
+ name: string;
33
+ type: string;
34
+ constant?: undefined;
35
+ outputs?: undefined;
36
+ payable?: undefined;
37
+ stateMutability?: undefined;
38
+ })[];