thirdweb 5.55.1-nightly-b2a2c9784a33394dffbcd32bbd28b2c612a4e603-20240915000420 → 5.56.0-nightly-a5e605c65e360a9d3d2e553d6783e58582b50a70-20240917000331

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 (127) hide show
  1. package/dist/cjs/contract/deployment/publisher.js +4 -4
  2. package/dist/cjs/contract/deployment/publisher.js.map +1 -1
  3. package/dist/cjs/exports/extensions/thirdweb.js +4 -3
  4. package/dist/cjs/exports/extensions/thirdweb.js.map +1 -1
  5. package/dist/cjs/exports/modules.js +4 -1
  6. package/dist/cjs/exports/modules.js.map +1 -1
  7. package/dist/cjs/exports/react.js +4 -2
  8. package/dist/cjs/exports/react.js.map +1 -1
  9. package/dist/cjs/exports/react.native.js +3 -1
  10. package/dist/cjs/exports/react.native.js.map +1 -1
  11. package/dist/cjs/extensions/modules/common/checkModulesCompatibility.js +95 -0
  12. package/dist/cjs/extensions/modules/common/checkModulesCompatibility.js.map +1 -0
  13. package/dist/cjs/extensions/thirdweb/write/publish.js +106 -0
  14. package/dist/cjs/extensions/thirdweb/write/publish.js.map +1 -0
  15. package/dist/cjs/react/core/hooks/wallets/useAdminAccount.js +23 -0
  16. package/dist/cjs/react/core/hooks/wallets/useAdminAccount.js.map +1 -0
  17. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +2 -1
  18. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
  19. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.js +1 -1
  20. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.js.map +1 -1
  21. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/usePayerSetup.js +0 -1
  22. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/usePayerSetup.js.map +1 -1
  23. package/dist/cjs/react/web/ui/ConnectWallet/screens/SignatureScreen.js +7 -5
  24. package/dist/cjs/react/web/ui/ConnectWallet/screens/SignatureScreen.js.map +1 -1
  25. package/dist/cjs/utils/arrays.js +23 -0
  26. package/dist/cjs/utils/arrays.js.map +1 -0
  27. package/dist/cjs/utils/extensions/convert-erc20-amount.js +21 -16
  28. package/dist/cjs/utils/extensions/convert-erc20-amount.js.map +1 -1
  29. package/dist/cjs/utils/semver.js +67 -0
  30. package/dist/cjs/utils/semver.js.map +1 -0
  31. package/dist/cjs/version.js +1 -1
  32. package/dist/cjs/wallets/in-app/web/lib/in-app-account.js +0 -1
  33. package/dist/cjs/wallets/in-app/web/lib/in-app-account.js.map +1 -1
  34. package/dist/cjs/wallets/smart/smart-wallet.js +3 -0
  35. package/dist/cjs/wallets/smart/smart-wallet.js.map +1 -1
  36. package/dist/esm/contract/deployment/publisher.js +1 -1
  37. package/dist/esm/contract/deployment/publisher.js.map +1 -1
  38. package/dist/esm/exports/extensions/thirdweb.js +1 -1
  39. package/dist/esm/exports/extensions/thirdweb.js.map +1 -1
  40. package/dist/esm/exports/modules.js +2 -1
  41. package/dist/esm/exports/modules.js.map +1 -1
  42. package/dist/esm/exports/react.js +1 -0
  43. package/dist/esm/exports/react.js.map +1 -1
  44. package/dist/esm/exports/react.native.js +1 -0
  45. package/dist/esm/exports/react.native.js.map +1 -1
  46. package/dist/esm/extensions/modules/common/checkModulesCompatibility.js +93 -0
  47. package/dist/esm/extensions/modules/common/checkModulesCompatibility.js.map +1 -0
  48. package/dist/esm/extensions/thirdweb/write/publish.js +102 -0
  49. package/dist/esm/extensions/thirdweb/write/publish.js.map +1 -0
  50. package/dist/esm/react/core/hooks/wallets/useAdminAccount.js +20 -0
  51. package/dist/esm/react/core/hooks/wallets/useAdminAccount.js.map +1 -0
  52. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +2 -1
  53. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
  54. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.js +1 -1
  55. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.js.map +1 -1
  56. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/usePayerSetup.js +0 -1
  57. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/usePayerSetup.js.map +1 -1
  58. package/dist/esm/react/web/ui/ConnectWallet/screens/SignatureScreen.js +7 -5
  59. package/dist/esm/react/web/ui/ConnectWallet/screens/SignatureScreen.js.map +1 -1
  60. package/dist/esm/utils/arrays.js +20 -0
  61. package/dist/esm/utils/arrays.js.map +1 -0
  62. package/dist/esm/utils/extensions/convert-erc20-amount.js +21 -16
  63. package/dist/esm/utils/extensions/convert-erc20-amount.js.map +1 -1
  64. package/dist/esm/utils/semver.js +62 -0
  65. package/dist/esm/utils/semver.js.map +1 -0
  66. package/dist/esm/version.js +1 -1
  67. package/dist/esm/wallets/in-app/web/lib/in-app-account.js +0 -1
  68. package/dist/esm/wallets/in-app/web/lib/in-app-account.js.map +1 -1
  69. package/dist/esm/wallets/smart/smart-wallet.js +3 -0
  70. package/dist/esm/wallets/smart/smart-wallet.js.map +1 -1
  71. package/dist/types/contract/deployment/publisher.d.ts +1 -0
  72. package/dist/types/contract/deployment/publisher.d.ts.map +1 -1
  73. package/dist/types/exports/extensions/thirdweb.d.ts +1 -1
  74. package/dist/types/exports/extensions/thirdweb.d.ts.map +1 -1
  75. package/dist/types/exports/modules.d.ts +2 -1
  76. package/dist/types/exports/modules.d.ts.map +1 -1
  77. package/dist/types/exports/react.d.ts +1 -0
  78. package/dist/types/exports/react.d.ts.map +1 -1
  79. package/dist/types/exports/react.native.d.ts +1 -0
  80. package/dist/types/exports/react.native.d.ts.map +1 -1
  81. package/dist/types/extensions/modules/common/checkModulesCompatibility.d.ts +9 -0
  82. package/dist/types/extensions/modules/common/checkModulesCompatibility.d.ts.map +1 -0
  83. package/dist/types/extensions/thirdweb/write/publish.d.ts +29 -0
  84. package/dist/types/extensions/thirdweb/write/publish.d.ts.map +1 -0
  85. package/dist/types/react/core/hooks/wallets/useAdminAccount.d.ts +7 -0
  86. package/dist/types/react/core/hooks/wallets/useAdminAccount.d.ts.map +1 -0
  87. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/usePayerSetup.d.ts.map +1 -1
  88. package/dist/types/react/web/ui/ConnectWallet/screens/SignatureScreen.d.ts.map +1 -1
  89. package/dist/types/utils/any-evm/deploy-metadata.d.ts +18 -1
  90. package/dist/types/utils/any-evm/deploy-metadata.d.ts.map +1 -1
  91. package/dist/types/utils/arrays.d.ts +5 -0
  92. package/dist/types/utils/arrays.d.ts.map +1 -0
  93. package/dist/types/utils/extensions/convert-erc20-amount.d.ts.map +1 -1
  94. package/dist/types/utils/semver.d.ts +25 -0
  95. package/dist/types/utils/semver.d.ts.map +1 -0
  96. package/dist/types/version.d.ts +1 -1
  97. package/dist/types/wallets/in-app/web/lib/in-app-account.d.ts.map +1 -1
  98. package/dist/types/wallets/interfaces/wallet.d.ts +5 -0
  99. package/dist/types/wallets/interfaces/wallet.d.ts.map +1 -1
  100. package/dist/types/wallets/smart/smart-wallet.d.ts.map +1 -1
  101. package/package.json +23 -23
  102. package/src/contract/deployment/publisher.ts +2 -1
  103. package/src/exports/extensions/thirdweb.ts +6 -4
  104. package/src/exports/modules.ts +5 -1
  105. package/src/exports/react.native.ts +1 -0
  106. package/src/exports/react.ts +1 -0
  107. package/src/extensions/erc721/lazyMinting/write/createAndReveal.test.ts +1 -1
  108. package/src/extensions/modules/MintableERC1155/mintableERC1155.test.ts +1 -1
  109. package/src/extensions/modules/MintableERC20/mintableERC20.test.ts +1 -1
  110. package/src/extensions/modules/MintableERC721/mintableERC721.test.ts +1 -1
  111. package/src/extensions/modules/common/checkModulesCompatibility.test.ts +46 -0
  112. package/src/extensions/modules/common/checkModulesCompatibility.ts +123 -0
  113. package/src/extensions/thirdweb/write/publish.test.ts +162 -0
  114. package/src/extensions/thirdweb/write/publish.ts +131 -0
  115. package/src/react/core/hooks/wallets/useAdminAccount.ts +25 -0
  116. package/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx +2 -1
  117. package/src/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.tsx +1 -1
  118. package/src/react/web/ui/ConnectWallet/screens/Buy/usePayerSetup.tsx +0 -2
  119. package/src/react/web/ui/ConnectWallet/screens/SignatureScreen.tsx +9 -5
  120. package/src/utils/any-evm/deploy-metadata.ts +18 -4
  121. package/src/utils/arrays.ts +23 -0
  122. package/src/utils/extensions/convert-erc20-amount.ts +23 -17
  123. package/src/utils/semver.ts +76 -0
  124. package/src/version.ts +1 -1
  125. package/src/wallets/in-app/web/lib/in-app-account.ts +0 -1
  126. package/src/wallets/interfaces/wallet.ts +6 -0
  127. package/src/wallets/smart/smart-wallet.ts +3 -0
@@ -0,0 +1,162 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { FORKED_POLYGON_CHAIN } from "../../../../test/src/chains.js";
3
+ import { TEST_CLIENT } from "../../../../test/src/test-clients.js";
4
+ import { TEST_ACCOUNT_D } from "../../../../test/src/test-wallets.js";
5
+ import { getContract } from "../../../contract/contract.js";
6
+ import { CONTRACT_PUBLISHER_ADDRESS } from "../../../contract/deployment/publisher.js";
7
+ import { parseEventLogs } from "../../../event/actions/parse-logs.js";
8
+ import { download } from "../../../storage/download.js";
9
+ import { sendAndConfirmTransaction } from "../../../transaction/actions/send-and-confirm-transaction.js";
10
+ import { fetchDeployMetadata } from "../../../utils/any-evm/deploy-metadata.js";
11
+ import { contractPublishedEvent } from "../__generated__/IContractPublisher/events/ContractPublished.js";
12
+ import { getAllPublishedContracts } from "../__generated__/IContractPublisher/read/getAllPublishedContracts.js";
13
+ import { getPublishedContractVersions } from "../__generated__/IContractPublisher/read/getPublishedContractVersions.js";
14
+ import { publishContract } from "./publish.js";
15
+
16
+ describe.runIf(process.env.TW_SECRET_KEY)("publishContract", () => {
17
+ it("should publish a contract successfully", async () => {
18
+ const publisherContract = getContract({
19
+ client: TEST_CLIENT,
20
+ chain: FORKED_POLYGON_CHAIN,
21
+ address: CONTRACT_PUBLISHER_ADDRESS,
22
+ });
23
+
24
+ let publishedContracts = await getAllPublishedContracts({
25
+ contract: publisherContract,
26
+ publisher: TEST_ACCOUNT_D.address,
27
+ });
28
+
29
+ expect(publishedContracts.length).toBe(0);
30
+
31
+ const catAttackDeployMetadata = await fetchDeployMetadata({
32
+ client: TEST_CLIENT,
33
+ uri: "ipfs://QmWcAMvBy49WRrzZeK4EQeVnkdmyb5H4STz4gUQwnt1kzC",
34
+ });
35
+
36
+ const tx = publishContract({
37
+ contract: publisherContract,
38
+ account: TEST_ACCOUNT_D,
39
+ metadata: {
40
+ ...catAttackDeployMetadata,
41
+ version: "0.0.1",
42
+ description: "Cat Attack NFT",
43
+ changelog: "Initial release",
44
+ },
45
+ });
46
+ const result = await sendAndConfirmTransaction({
47
+ transaction: tx,
48
+ account: TEST_ACCOUNT_D,
49
+ });
50
+ expect(result.transactionHash.length).toBeGreaterThan(0);
51
+ const logs = parseEventLogs({
52
+ events: [contractPublishedEvent()],
53
+ logs: result.logs,
54
+ });
55
+ expect(logs?.[0]?.args.publishedContract.contractId).toBe("CatAttackNFT");
56
+ expect(logs?.[0]?.args.publishedContract.publishMetadataUri).toBeDefined();
57
+ const rawMeta = await download({
58
+ client: TEST_CLIENT,
59
+ uri: logs?.[0]?.args.publishedContract.publishMetadataUri ?? "",
60
+ }).then((r) => r.json());
61
+ expect(rawMeta).toMatchInlineSnapshot(`
62
+ {
63
+ "bytecodeUri": "ipfs://QmVyB9qAs7XdZYNGPcNbff43BX1tyZFJkqdfp1eXiNS8AG/0",
64
+ "changelog": "Initial release",
65
+ "compilers": {
66
+ "solc": [
67
+ {
68
+ "bytecodeUri": "ipfs://QmVyB9qAs7XdZYNGPcNbff43BX1tyZFJkqdfp1eXiNS8AG/0",
69
+ "compilerVersion": "",
70
+ "evmVersion": "",
71
+ "metadataUri": "ipfs://Qmd2Ef29NzCjomqYXZbWa8ZdF1AESDAS1HDAonmAnTgHPs",
72
+ },
73
+ ],
74
+ },
75
+ "description": "Cat Attack NFT",
76
+ "metadataUri": "ipfs://Qmd2Ef29NzCjomqYXZbWa8ZdF1AESDAS1HDAonmAnTgHPs",
77
+ "name": "CatAttackNFT",
78
+ "publisher": "0x90F79bf6EB2c4f870365E785982E1f101E93b906",
79
+ "routerType": "none",
80
+ "version": "0.0.1",
81
+ }
82
+ `);
83
+ const publishedData = await fetchDeployMetadata({
84
+ client: TEST_CLIENT,
85
+ uri: logs?.[0]?.args.publishedContract.publishMetadataUri ?? "",
86
+ });
87
+ expect(publishedData.abi).toBeDefined();
88
+ expect(publishedData.bytecode).toBeDefined();
89
+ expect(publishedData.version).toBe("0.0.1");
90
+ expect(publishedData.changelog).toBe("Initial release");
91
+ expect(publishedData.name).toBe("CatAttackNFT");
92
+ expect(publishedData.description).toBe("Cat Attack NFT");
93
+ expect(publishedData.publisher).toBe(TEST_ACCOUNT_D.address);
94
+ expect(publishedData.routerType).toBe("none");
95
+
96
+ publishedContracts = await getAllPublishedContracts({
97
+ contract: publisherContract,
98
+ publisher: TEST_ACCOUNT_D.address,
99
+ });
100
+
101
+ expect(publishedContracts.length).toBe(1);
102
+
103
+ expect(
104
+ sendAndConfirmTransaction({
105
+ account: TEST_ACCOUNT_D,
106
+ transaction: publishContract({
107
+ contract: publisherContract,
108
+ account: TEST_ACCOUNT_D,
109
+ previousMetadata: publishedData,
110
+ metadata: {
111
+ ...publishedData,
112
+ version: "0.0.1",
113
+ changelog: "Initial release 2",
114
+ },
115
+ }),
116
+ }),
117
+ ).rejects.toThrow("Version 0.0.1 is not greater than 0.0.1");
118
+
119
+ const tx2 = publishContract({
120
+ contract: publisherContract,
121
+ account: TEST_ACCOUNT_D,
122
+ previousMetadata: publishedData,
123
+ metadata: {
124
+ ...publishedData,
125
+ version: "0.0.2",
126
+ changelog: "Initial release 2",
127
+ },
128
+ });
129
+ const result2 = await sendAndConfirmTransaction({
130
+ transaction: tx2,
131
+ account: TEST_ACCOUNT_D,
132
+ });
133
+
134
+ expect(result2.transactionHash.length).toBeGreaterThan(0);
135
+ const logs2 = parseEventLogs({
136
+ events: [contractPublishedEvent()],
137
+ logs: result2.logs,
138
+ });
139
+ expect(logs2?.[0]?.args.publishedContract.contractId).toBe("CatAttackNFT");
140
+ expect(logs2?.[0]?.args.publishedContract.publishMetadataUri).toBeDefined();
141
+ const publishedData2 = await fetchDeployMetadata({
142
+ client: TEST_CLIENT,
143
+ uri: logs2?.[0]?.args.publishedContract.publishMetadataUri ?? "",
144
+ });
145
+ expect(publishedData2.version).toBe("0.0.2");
146
+
147
+ publishedContracts = await getAllPublishedContracts({
148
+ contract: publisherContract,
149
+ publisher: TEST_ACCOUNT_D.address,
150
+ });
151
+
152
+ expect(publishedContracts.length).toBe(1);
153
+
154
+ const versions = await getPublishedContractVersions({
155
+ contract: publisherContract,
156
+ contractId: "CatAttackNFT",
157
+ publisher: TEST_ACCOUNT_D.address,
158
+ });
159
+
160
+ expect(versions.length).toEqual(2);
161
+ }, 120000);
162
+ });
@@ -0,0 +1,131 @@
1
+ import type { Abi } from "abitype";
2
+ import { encodePacked, keccak256, toFunctionSelector } from "viem/utils";
3
+ import { polygon } from "../../../chains/chain-definitions/polygon.js";
4
+ import type { ThirdwebClient } from "../../../client/client.js";
5
+ import { ZERO_ADDRESS } from "../../../constants/addresses.js";
6
+ import { getContract } from "../../../contract/contract.js";
7
+ import { CONTRACT_PUBLISHER_ADDRESS } from "../../../contract/deployment/publisher.js";
8
+ import { download } from "../../../storage/download.js";
9
+ import { upload } from "../../../storage/upload.js";
10
+ import type { BaseTransactionOptions } from "../../../transaction/types.js";
11
+ import type {
12
+ ExtendedMetadata,
13
+ FetchDeployMetadataResult,
14
+ } from "../../../utils/any-evm/deploy-metadata.js";
15
+ import { ensureBytecodePrefix } from "../../../utils/bytecode/prefix.js";
16
+ import { isIncrementalVersion } from "../../../utils/semver.js";
17
+ import type { Account } from "../../../wallets/interfaces/wallet.js";
18
+ import { isGetInstalledModulesSupported } from "../../modules/__generated__/IModularCore/read/getInstalledModules.js";
19
+ import { publishContract as generatedPublishContract } from "../__generated__/IContractPublisher/write/publishContract.js";
20
+
21
+ export type PublishContractParams = {
22
+ account: Account;
23
+ metadata: FetchDeployMetadataResult & {
24
+ version: string;
25
+ };
26
+ previousMetadata?: FetchDeployMetadataResult;
27
+ };
28
+
29
+ /**
30
+ * Publish a contract to the contract publisher.
31
+ *
32
+ * @param options - The options for publishing the contract.
33
+ * @returns The transaction to publish the contract.
34
+ * @example
35
+ * ```ts
36
+ * const tx = publishContract({
37
+ * contract,
38
+ * account,
39
+ * metadata,
40
+ * });
41
+ * ```
42
+ * @extension thirdweb
43
+ */
44
+ export function publishContract(
45
+ options: BaseTransactionOptions<PublishContractParams>,
46
+ ) {
47
+ return generatedPublishContract({
48
+ contract: options.contract,
49
+ async asyncParams() {
50
+ const currentVersion = options.previousMetadata?.version;
51
+ // check if the version is greater than the current version
52
+ if (
53
+ currentVersion &&
54
+ !isIncrementalVersion(currentVersion, options.metadata.version)
55
+ ) {
56
+ throw Error(
57
+ `Version ${options.metadata.version} is not greater than ${currentVersion}`,
58
+ );
59
+ }
60
+ // hash the bytecode
61
+ const bytecode = await download({
62
+ client: options.contract.client,
63
+ uri: options.metadata.bytecodeUri,
64
+ }).then((r) => r.text());
65
+ const bytecodeHash = keccak256(
66
+ encodePacked(["bytes"], [ensureBytecodePrefix(bytecode)]),
67
+ );
68
+
69
+ const abi = options.metadata.abi;
70
+ const routerType = getRouterType(abi);
71
+ // not spreading here, we don't want to re-upload the fetched data like bytecode
72
+ const newMetadata: ExtendedMetadata = {
73
+ bytecodeUri: options.metadata.bytecodeUri,
74
+ metadataUri: options.metadata.metadataUri,
75
+ name: options.metadata.name,
76
+ version: options.metadata.version,
77
+ audit: options.metadata.audit,
78
+ changelog: options.metadata.changelog,
79
+ compositeAbi: options.metadata.compositeAbi,
80
+ constructorParams: options.metadata.constructorParams,
81
+ defaultExtensions: options.metadata.defaultExtensions,
82
+ defaultModules: options.metadata.defaultModules,
83
+ deployType: options.metadata.deployType,
84
+ description: options.metadata.description,
85
+ displayName: options.metadata.displayName,
86
+ factoryDeploymentData: options.metadata.factoryDeploymentData,
87
+ isDeployableViaFactory: options.metadata.isDeployableViaFactory,
88
+ isDeployableViaProxy: options.metadata.isDeployableViaProxy,
89
+ logo: options.metadata.logo,
90
+ networksForDeployment: options.metadata.networksForDeployment,
91
+ readme: options.metadata.readme,
92
+ tags: options.metadata.tags,
93
+ compilers: options.metadata.compilers,
94
+ publisher: options.account.address,
95
+ routerType,
96
+ };
97
+
98
+ // upload the new metadata
99
+ const newMetadataUri = await upload({
100
+ client: options.contract.client,
101
+ files: [newMetadata],
102
+ });
103
+
104
+ return {
105
+ publisher: options.account.address,
106
+ contractId: options.metadata.name,
107
+ publishMetadataUri: newMetadataUri,
108
+ compilerMetadataUri: options.metadata.metadataUri,
109
+ bytecodeHash,
110
+ implementation: ZERO_ADDRESS,
111
+ };
112
+ },
113
+ });
114
+ }
115
+
116
+ export function getContractPublisher(client: ThirdwebClient) {
117
+ return getContract({
118
+ client,
119
+ chain: polygon,
120
+ address: CONTRACT_PUBLISHER_ADDRESS,
121
+ });
122
+ }
123
+
124
+ function getRouterType(abi: Abi) {
125
+ const fnSelectors = abi
126
+ .filter((f) => f.type === "function")
127
+ .map((f) => toFunctionSelector(f));
128
+ const isModule = isGetInstalledModulesSupported(fnSelectors);
129
+ // TODO add dynamic detection
130
+ return isModule ? "modular" : "none";
131
+ }
@@ -0,0 +1,25 @@
1
+ import { useActiveWallet } from "./useActiveWallet.js";
2
+ import { useConnectedWallets } from "./useConnectedWallets.js";
3
+
4
+ /**
5
+ * Get the admin wallet for the active wallet
6
+ * Useful for smart wallets to get the underlying personal account
7
+ * @returns The admin wallet for the active wallet, or the active wallet if it doesn't have an admin account
8
+ */
9
+ export function useAdminWallet() {
10
+ const activeWallet = useActiveWallet();
11
+ const connectedWallets = useConnectedWallets();
12
+ const adminAccount = activeWallet?.getAdminAccount?.();
13
+
14
+ if (!adminAccount) {
15
+ // If the active wallet doesn't have an admin account, return the active wallet
16
+ return activeWallet;
17
+ }
18
+
19
+ // If the active wallet has an admin account, find the admin wallet in connected wallets and return it
20
+ return connectedWallets.find(
21
+ (wallet) =>
22
+ wallet.getAccount()?.address?.toLowerCase() ===
23
+ adminAccount?.address?.toLowerCase(),
24
+ );
25
+ }
@@ -1120,7 +1120,8 @@ function SwapScreenContent(props: {
1120
1120
 
1121
1121
  function showSwapFlow() {
1122
1122
  if (
1123
- props.payOptions.mode === "direct_payment" &&
1123
+ (props.payOptions.mode === "direct_payment" ||
1124
+ props.payOptions.mode === "fund_wallet") &&
1124
1125
  !isNotEnoughBalance &&
1125
1126
  !swapRequired
1126
1127
  ) {
@@ -126,7 +126,7 @@ export function SwapConfirmationScreen(props: {
126
126
 
127
127
  {/* Send to */}
128
128
  {isDifferentRecipient && (
129
- <ConfirmItem label="Seller">
129
+ <ConfirmItem label="Receiver">
130
130
  <Text color="primaryText" size="sm">
131
131
  {ensName.data || shortenAddress(receiver)}
132
132
  </Text>
@@ -23,8 +23,6 @@ export function usePayerSetup() {
23
23
  const account = wallet.getAccount();
24
24
  const chain = wallet.getChain();
25
25
  if (account && chain) {
26
- console.log("updated to", account, chain);
27
-
28
26
  setPayer({
29
27
  account,
30
28
  chain,
@@ -13,6 +13,7 @@ import { useSiweAuth } from "../../../../core/hooks/auth/useSiweAuth.js";
13
13
  import type { ConnectButtonProps } from "../../../../core/hooks/connection/ConnectButtonProps.js";
14
14
  import { useActiveAccount } from "../../../../core/hooks/wallets/useActiveAccount.js";
15
15
  import { useActiveWallet } from "../../../../core/hooks/wallets/useActiveWallet.js";
16
+ import { useAdminWallet } from "../../../../core/hooks/wallets/useAdminAccount.js";
16
17
  import { useDisconnect } from "../../../../core/hooks/wallets/useDisconnect.js";
17
18
  import { wait } from "../../../../core/utils/wait.js";
18
19
  import { LoadingScreen } from "../../../wallets/shared/LoadingScreen.js";
@@ -46,12 +47,12 @@ export const SignatureScreen: React.FC<{
46
47
  connectLocale,
47
48
  } = props;
48
49
 
49
- const activeWallet = useActiveWallet();
50
+ const wallet = useActiveWallet();
51
+ const adminWallet = useAdminWallet();
50
52
  const activeAccount = useActiveAccount();
51
- const siweAuth = useSiweAuth(activeWallet, activeAccount, props.auth);
53
+ const siweAuth = useSiweAuth(wallet, activeAccount, props.auth);
52
54
  const [status, setStatus] = useState<Status>("idle");
53
55
  const { disconnect } = useDisconnect();
54
- const wallet = useActiveWallet();
55
56
  const locale = connectLocale.signatureScreen;
56
57
 
57
58
  const signIn = useCallback(async () => {
@@ -66,12 +67,15 @@ export const SignatureScreen: React.FC<{
66
67
  }
67
68
  }, [onDone, siweAuth]);
68
69
 
69
- // this should not happen
70
70
  if (!wallet) {
71
71
  return <LoadingScreen />;
72
72
  }
73
73
 
74
- if (wallet.id === "inApp" || wallet.id === "embedded") {
74
+ if (
75
+ wallet.id === "inApp" ||
76
+ wallet.id === "embedded" ||
77
+ (wallet.id === "smart" && adminWallet?.id === "inApp")
78
+ ) {
75
79
  return (
76
80
  <HeadlessSignIn
77
81
  signIn={signIn}
@@ -75,7 +75,7 @@ async function fetchAndParseCompilerMetadata(
75
75
 
76
76
  // types
77
77
 
78
- type RawCompilerMetadata = {
78
+ export type RawCompilerMetadata = {
79
79
  name: string;
80
80
  metadataUri: string;
81
81
  bytecodeUri: string;
@@ -130,9 +130,10 @@ type ParsedCompilerMetadata = {
130
130
  };
131
131
 
132
132
  export type CompilerMetadata = Prettify<
133
- ParsedCompilerMetadata & {
134
- bytecode: Hex;
135
- }
133
+ RawCompilerMetadata &
134
+ ParsedCompilerMetadata & {
135
+ bytecode: Hex;
136
+ }
136
137
  >;
137
138
 
138
139
  export type ExtendedMetadata = {
@@ -195,5 +196,18 @@ export type ExtendedMetadata = {
195
196
  }
196
197
  >;
197
198
  compositeAbi?: Abi;
199
+ compilers?: Record<
200
+ "solc" | "zksolc",
201
+ {
202
+ evmVersion: string;
203
+ compilerVersion: string;
204
+ metadataUri: string;
205
+ bytecodeUri: string;
206
+ }[]
207
+ >;
208
+ externalLinks?: Array<{
209
+ name: string;
210
+ url: string;
211
+ }>;
198
212
  [key: string]: unknown;
199
213
  };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @internal
3
+ */
4
+ export function hasDuplicates<T>(
5
+ arr: T[],
6
+ fn: (a: T | undefined, b: T | undefined) => boolean,
7
+ ): boolean {
8
+ if (arr.length === 0 || arr.length === 1) {
9
+ return false;
10
+ }
11
+ if (!fn) {
12
+ throw new Error("Comparison function required");
13
+ }
14
+
15
+ for (let i = 0; i < arr.length; i++) {
16
+ for (let j = i + 1; j < arr.length; j++) {
17
+ if (fn(arr[i], arr[j])) {
18
+ return true;
19
+ }
20
+ }
21
+ }
22
+ return false;
23
+ }
@@ -22,24 +22,30 @@ export async function convertErc20Amount(
22
22
  } & AmountOrAmountInWei
23
23
  >,
24
24
  ): Promise<bigint> {
25
- if ("amount" in options) {
26
- // for native token, we know decimals are 18
27
- if (!options.erc20Address || isNativeTokenAddress(options.erc20Address)) {
28
- return toUnits(options.amount.toString(), 18);
25
+ try {
26
+ if ("amount" in options) {
27
+ // for native token, we know decimals are 18
28
+ if (!options.erc20Address || isNativeTokenAddress(options.erc20Address)) {
29
+ return toUnits(options.amount.toString(), 18);
30
+ }
31
+ // otherwise get the decimals of the currency
32
+ const currencyContract = getContract({
33
+ client: options.client,
34
+ chain: options.chain,
35
+ address: options.erc20Address,
36
+ });
37
+ const { decimals } = await import(
38
+ "../../extensions/erc20/read/decimals.js"
39
+ );
40
+ const currencyDecimals = await decimals({
41
+ contract: currencyContract,
42
+ });
43
+ return toUnits(options.amount.toString(), currencyDecimals);
29
44
  }
30
- // otherwise get the decimals of the currency
31
- const currencyContract = getContract({
32
- client: options.client,
33
- chain: options.chain,
34
- address: options.erc20Address,
35
- });
36
- const { decimals } = await import(
37
- "../../extensions/erc20/read/decimals.js"
45
+ return options.amountInWei;
46
+ } catch (e) {
47
+ throw new Error(
48
+ `Failed to convert ERC20 amount for token: ${options.erc20Address}: ${e}`,
38
49
  );
39
- const currencyDecimals = await decimals({
40
- contract: currencyContract,
41
- });
42
- return toUnits(options.amount.toString(), currencyDecimals);
43
50
  }
44
- return options.amountInWei;
45
51
  }
@@ -0,0 +1,76 @@
1
+ const MAX_LENGTH = 256;
2
+ const NUMERIC_IDENTIFIER = "0|[1-9]\\d*";
3
+ const MAIN_VERSION_IDENTIFIER = `(${NUMERIC_IDENTIFIER})\\.(${NUMERIC_IDENTIFIER})\\.(${NUMERIC_IDENTIFIER})`;
4
+ const REGEX_MAIN_VERSION = new RegExp(MAIN_VERSION_IDENTIFIER);
5
+
6
+ /**
7
+ * @internal
8
+ */
9
+ export type Semver = {
10
+ major: number;
11
+ minor: number;
12
+ patch: number;
13
+ versionString: string;
14
+ };
15
+
16
+ /**
17
+ * @internal
18
+ * @param version - The version to convert to a Semver
19
+ */
20
+ export function toSemver(version: string): Semver {
21
+ if (version.length > MAX_LENGTH) {
22
+ throw new Error(`version is longer than ${MAX_LENGTH} characters`);
23
+ }
24
+ const matches = version.trim().match(REGEX_MAIN_VERSION);
25
+ if (!matches || matches?.length !== 4) {
26
+ throw new Error(
27
+ `${version} is not a valid semantic version. Should be in the format of major.minor.patch. Ex: 0.4.1`,
28
+ );
29
+ }
30
+ const major = Number(matches[1]);
31
+ const minor = Number(matches[2]);
32
+ const patch = Number(matches[3]);
33
+ const versionString = [major, minor, patch].join(".");
34
+ return {
35
+ major,
36
+ minor,
37
+ patch,
38
+ versionString,
39
+ };
40
+ }
41
+
42
+ /**
43
+ * @internal
44
+ * @param current - The current version
45
+ * @param next - The next version
46
+ */
47
+ export function isIncrementalVersion(current: string, next: string) {
48
+ const currentSemver = toSemver(current);
49
+ const nextSemver = toSemver(next);
50
+ if (nextSemver.major > currentSemver.major) {
51
+ return true;
52
+ }
53
+ const eqMajor = nextSemver.major === currentSemver.major;
54
+ if (eqMajor && nextSemver.minor > currentSemver.minor) {
55
+ return true;
56
+ }
57
+ const eqMinor = nextSemver.minor === currentSemver.minor;
58
+ return eqMajor && eqMinor && nextSemver.patch > currentSemver.patch;
59
+ }
60
+
61
+ /**
62
+ * @internal
63
+ */
64
+ export function isDowngradeVersion(current: string, next: string) {
65
+ const currentSemver = toSemver(current);
66
+ const nextSemver = toSemver(next);
67
+ if (nextSemver.major < currentSemver.major) {
68
+ return true;
69
+ }
70
+ const eqMajor = nextSemver.major === currentSemver.major;
71
+ if (eqMajor && nextSemver.minor < currentSemver.minor) {
72
+ return true;
73
+ }
74
+ const eqMinor = nextSemver.minor === currentSemver.minor;
75
+ return eqMajor && eqMinor && nextSemver.patch < currentSemver.patch;
76
+ }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.55.1-nightly-b2a2c9784a33394dffbcd32bbd28b2c612a4e603-20240915000420";
1
+ export const version = "5.56.0-nightly-a5e605c65e360a9d3d2e553d6783e58582b50a70-20240917000331";
@@ -305,7 +305,6 @@ export class IFrameWallet {
305
305
  return signedMessage as Hex;
306
306
  },
307
307
  async signTypedData(_typedData) {
308
- console.log("signTypedData", _typedData);
309
308
  const parsedTypedData = parseTypedData(_typedData);
310
309
  // deleting EIP712 Domain as it results in ambiguous primary type on some cases
311
310
  // this happens when going from viem to ethers via the iframe
@@ -141,6 +141,12 @@ export type Wallet<TWalletId extends WalletId = WalletId> = {
141
141
  * Can be used to execute any pre-connection actions like showing a modal, etc.
142
142
  */
143
143
  onConnectRequested?: () => Promise<void>;
144
+
145
+ /**
146
+ * Get the admin account of this wallet
147
+ * This is useful for smart wallets to get the underlying personal account
148
+ */
149
+ getAdminAccount?: () => Account | undefined;
144
150
  };
145
151
 
146
152
  /**
@@ -102,6 +102,7 @@ export function smartWallet(
102
102
  ): Wallet<"smart"> {
103
103
  const emitter = createWalletEmitter<"smart">();
104
104
  let account: Account | undefined = undefined;
105
+ let adminAccount: Account | undefined = undefined;
105
106
  let chain: Chain | undefined = undefined;
106
107
  let lastConnectOptions: WalletConnectionOption<"smart"> | undefined;
107
108
 
@@ -118,6 +119,7 @@ export function smartWallet(
118
119
  },
119
120
  getConfig: () => createOptions,
120
121
  getAccount: () => account,
122
+ getAdminAccount: () => adminAccount,
121
123
  autoConnect: async (options) => {
122
124
  const { connectSmartWallet } = await import("./index.js");
123
125
  const [connectedAccount, connectedChain] = await connectSmartWallet(
@@ -145,6 +147,7 @@ export function smartWallet(
145
147
  createOptions,
146
148
  );
147
149
  // set the states
150
+ adminAccount = options.personalAccount;
148
151
  lastConnectOptions = options;
149
152
  account = connectedAccount;
150
153
  chain = connectedChain;