thirdweb 5.45.1 → 5.45.2-nightly-b15aa4cdff3f3b233025da285780668a18fe29ab-20240813000336

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 (82) hide show
  1. package/dist/cjs/exports/deploys.js +3 -1
  2. package/dist/cjs/exports/deploys.js.map +1 -1
  3. package/dist/cjs/exports/extensions/split.js +7 -1
  4. package/dist/cjs/exports/extensions/split.js.map +1 -1
  5. package/dist/cjs/extensions/prebuilts/__generated__/Split/write/initialize.js +157 -0
  6. package/dist/cjs/extensions/prebuilts/__generated__/Split/write/initialize.js.map +1 -0
  7. package/dist/cjs/extensions/prebuilts/deploy-split.js +79 -0
  8. package/dist/cjs/extensions/prebuilts/deploy-split.js.map +1 -0
  9. package/dist/cjs/extensions/split/__generated__/Split/read/totalShares.js +71 -0
  10. package/dist/cjs/extensions/split/__generated__/Split/read/totalShares.js.map +1 -0
  11. package/dist/cjs/extensions/split/read/getAllRecipientsAddresses.js +24 -0
  12. package/dist/cjs/extensions/split/read/getAllRecipientsAddresses.js.map +1 -0
  13. package/dist/cjs/extensions/split/read/getAllRecipientsPercentages.js +34 -0
  14. package/dist/cjs/extensions/split/read/getAllRecipientsPercentages.js.map +1 -0
  15. package/dist/cjs/extensions/split/read/getRecipientSplitPercentage.js +21 -0
  16. package/dist/cjs/extensions/split/read/getRecipientSplitPercentage.js.map +1 -0
  17. package/dist/cjs/react/core/hooks/auth/useSiweAuth.js +4 -0
  18. package/dist/cjs/react/core/hooks/auth/useSiweAuth.js.map +1 -1
  19. package/dist/cjs/react/core/hooks/others/useProfiles.js +1 -1
  20. package/dist/cjs/version.js +1 -1
  21. package/dist/cjs/version.js.map +1 -1
  22. package/dist/cjs/wallets/in-app/core/wallet/profiles.js +3 -3
  23. package/dist/esm/exports/deploys.js +1 -0
  24. package/dist/esm/exports/deploys.js.map +1 -1
  25. package/dist/esm/exports/extensions/split.js +3 -0
  26. package/dist/esm/exports/extensions/split.js.map +1 -1
  27. package/dist/esm/extensions/prebuilts/__generated__/Split/write/initialize.js +150 -0
  28. package/dist/esm/extensions/prebuilts/__generated__/Split/write/initialize.js.map +1 -0
  29. package/dist/esm/extensions/prebuilts/deploy-split.js +76 -0
  30. package/dist/esm/extensions/prebuilts/deploy-split.js.map +1 -0
  31. package/dist/esm/extensions/split/__generated__/Split/read/totalShares.js +65 -0
  32. package/dist/esm/extensions/split/__generated__/Split/read/totalShares.js.map +1 -0
  33. package/dist/esm/extensions/split/read/getAllRecipientsAddresses.js +21 -0
  34. package/dist/esm/extensions/split/read/getAllRecipientsAddresses.js.map +1 -0
  35. package/dist/esm/extensions/split/read/getAllRecipientsPercentages.js +31 -0
  36. package/dist/esm/extensions/split/read/getAllRecipientsPercentages.js.map +1 -0
  37. package/dist/esm/extensions/split/read/getRecipientSplitPercentage.js +18 -0
  38. package/dist/esm/extensions/split/read/getRecipientSplitPercentage.js.map +1 -0
  39. package/dist/esm/react/core/hooks/auth/useSiweAuth.js +4 -0
  40. package/dist/esm/react/core/hooks/auth/useSiweAuth.js.map +1 -1
  41. package/dist/esm/react/core/hooks/others/useProfiles.js +1 -1
  42. package/dist/esm/version.js +1 -1
  43. package/dist/esm/version.js.map +1 -1
  44. package/dist/esm/wallets/in-app/core/wallet/profiles.js +3 -3
  45. package/dist/types/exports/deploys.d.ts +1 -0
  46. package/dist/types/exports/deploys.d.ts.map +1 -1
  47. package/dist/types/exports/extensions/split.d.ts +3 -0
  48. package/dist/types/exports/extensions/split.d.ts.map +1 -1
  49. package/dist/types/extensions/prebuilts/__generated__/Split/write/initialize.d.ts +108 -0
  50. package/dist/types/extensions/prebuilts/__generated__/Split/write/initialize.d.ts.map +1 -0
  51. package/dist/types/extensions/prebuilts/deploy-split.d.ts +66 -0
  52. package/dist/types/extensions/prebuilts/deploy-split.d.ts.map +1 -0
  53. package/dist/types/extensions/split/__generated__/Split/read/totalShares.d.ts +46 -0
  54. package/dist/types/extensions/split/__generated__/Split/read/totalShares.d.ts.map +1 -0
  55. package/dist/types/extensions/split/read/getAllRecipientsAddresses.d.ts +14 -0
  56. package/dist/types/extensions/split/read/getAllRecipientsAddresses.d.ts.map +1 -0
  57. package/dist/types/extensions/split/read/getAllRecipientsPercentages.d.ts +27 -0
  58. package/dist/types/extensions/split/read/getAllRecipientsPercentages.d.ts.map +1 -0
  59. package/dist/types/extensions/split/read/getRecipientSplitPercentage.d.ts +21 -0
  60. package/dist/types/extensions/split/read/getRecipientSplitPercentage.d.ts.map +1 -0
  61. package/dist/types/react/core/hooks/auth/useSiweAuth.d.ts.map +1 -1
  62. package/dist/types/react/core/hooks/others/useProfiles.d.ts +1 -1
  63. package/dist/types/version.d.ts +1 -1
  64. package/dist/types/version.d.ts.map +1 -1
  65. package/dist/types/wallets/in-app/core/wallet/profiles.d.ts +3 -3
  66. package/package.json +1 -1
  67. package/src/exports/deploys.ts +5 -0
  68. package/src/exports/extensions/split.ts +8 -0
  69. package/src/extensions/prebuilts/__generated__/Split/write/initialize.ts +191 -0
  70. package/src/extensions/prebuilts/deploy-split.test.ts +31 -0
  71. package/src/extensions/prebuilts/deploy-split.ts +144 -0
  72. package/src/extensions/split/__generated__/Split/read/totalShares.ts +72 -0
  73. package/src/extensions/split/read/getAllRecipientsAddresses.test.ts +39 -0
  74. package/src/extensions/split/read/getAllRecipientsAddresses.ts +26 -0
  75. package/src/extensions/split/read/getAllRecipientsPercentages.test.ts +48 -0
  76. package/src/extensions/split/read/getAllRecipientsPercentages.ts +41 -0
  77. package/src/extensions/split/read/getRecipientSplitPercentage.test.ts +45 -0
  78. package/src/extensions/split/read/getRecipientSplitPercentage.ts +40 -0
  79. package/src/react/core/hooks/auth/useSiweAuth.ts +7 -0
  80. package/src/react/core/hooks/others/useProfiles.ts +1 -1
  81. package/src/version.ts +1 -1
  82. package/src/wallets/in-app/core/wallet/profiles.ts +3 -3
@@ -0,0 +1,72 @@
1
+ import { readContract } from "../../../../../transaction/read-contract.js";
2
+ import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
3
+
4
+ import { decodeAbiParameters } from "viem";
5
+ import type { Hex } from "../../../../../utils/encoding/hex.js";
6
+ import type { ThirdwebContract } from "../../../../../contract/contract.js";
7
+ import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
8
+
9
+ export const FN_SELECTOR = "0x3a98ef39" as const;
10
+ const FN_INPUTS = [] as const;
11
+ const FN_OUTPUTS = [
12
+ {
13
+ type: "uint256",
14
+ },
15
+ ] as const;
16
+
17
+ /**
18
+ * Checks if the `totalShares` method is supported by the given contract.
19
+ * @param contract The ThirdwebContract.
20
+ * @returns A promise that resolves to a boolean indicating if the `totalShares` method is supported.
21
+ * @extension SPLIT
22
+ * @example
23
+ * ```ts
24
+ * import { isTotalSharesSupported } from "thirdweb/extensions/split";
25
+ *
26
+ * const supported = await isTotalSharesSupported(contract);
27
+ * ```
28
+ */
29
+ export async function isTotalSharesSupported(contract: ThirdwebContract<any>) {
30
+ return detectMethod({
31
+ contract,
32
+ method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
33
+ });
34
+ }
35
+
36
+ /**
37
+ * Decodes the result of the totalShares function call.
38
+ * @param result - The hexadecimal result to decode.
39
+ * @returns The decoded result as per the FN_OUTPUTS definition.
40
+ * @extension SPLIT
41
+ * @example
42
+ * ```ts
43
+ * import { decodeTotalSharesResult } from "thirdweb/extensions/split";
44
+ * const result = decodeTotalSharesResult("...");
45
+ * ```
46
+ */
47
+ export function decodeTotalSharesResult(result: Hex) {
48
+ return decodeAbiParameters(FN_OUTPUTS, result)[0];
49
+ }
50
+
51
+ /**
52
+ * Calls the "totalShares" function on the contract.
53
+ * @param options - The options for the totalShares function.
54
+ * @returns The parsed result of the function call.
55
+ * @extension SPLIT
56
+ * @example
57
+ * ```ts
58
+ * import { totalShares } from "thirdweb/extensions/split";
59
+ *
60
+ * const result = await totalShares({
61
+ * contract,
62
+ * });
63
+ *
64
+ * ```
65
+ */
66
+ export async function totalShares(options: BaseTransactionOptions) {
67
+ return readContract({
68
+ contract: options.contract,
69
+ method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
70
+ params: [],
71
+ });
72
+ }
@@ -0,0 +1,39 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { ANVIL_CHAIN } from "~test/chains.js";
3
+ import { TEST_CLIENT } from "~test/test-clients.js";
4
+ import { TEST_ACCOUNT_A } from "~test/test-wallets.js";
5
+ import { getContract } from "../../../contract/contract.js";
6
+ import { deploySplitContract } from "../../../extensions/prebuilts/deploy-split.js";
7
+ import { getAllRecipientsAddresses } from "./getAllRecipientsAddresses.js";
8
+
9
+ const chain = ANVIL_CHAIN;
10
+ const client = TEST_CLIENT;
11
+
12
+ describe.runIf(process.env.TW_SECRET_KEY)("getAllRecipientsAddresses", () => {
13
+ it("should work", async () => {
14
+ const payees = [
15
+ "0x12345674b599ce99958242b3D3741e7b01841DF3",
16
+ "0xA6f11e47dE28B3dB934e945daeb6F538E9019694",
17
+ ];
18
+ const address = await deploySplitContract({
19
+ account: TEST_ACCOUNT_A,
20
+ client: TEST_CLIENT,
21
+ chain: ANVIL_CHAIN,
22
+ params: {
23
+ name: "split-contract",
24
+ payees,
25
+ shares: [
26
+ 5100n, // 51%
27
+ 4900n, // 49%
28
+ ],
29
+ },
30
+ });
31
+ const contract = getContract({
32
+ address,
33
+ chain,
34
+ client,
35
+ });
36
+ const result = await getAllRecipientsAddresses({ contract });
37
+ expect(result).toStrictEqual(payees);
38
+ });
39
+ });
@@ -0,0 +1,26 @@
1
+ import type { BaseTransactionOptions } from "../../../transaction/types.js";
2
+ import { payee } from "../__generated__/Split/read/payee.js";
3
+ import { payeeCount } from "../__generated__/Split/read/payeeCount.js";
4
+
5
+ /**
6
+ * Get the addresses of all recipients of a [`thirdweb Split contract`](https://thirdweb.com/thirdweb.eth/Split)
7
+ * @extension SPLIT
8
+ * @returns an array of wallet addresses
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { getAllRecipientsAddresses } from "thirdweb/extensions/split";
13
+ *
14
+ * const addresses = await getAllRecipientsAddresses({ contract });
15
+ */
16
+ export async function getAllRecipientsAddresses(
17
+ options: BaseTransactionOptions,
18
+ ): Promise<string[]> {
19
+ const { contract } = options;
20
+ const _totalRecipients = await payeeCount(options);
21
+ const indexes = Array.from({ length: Number(_totalRecipients) }, (_, i) => i);
22
+ const recipientAddresses = await Promise.all(
23
+ indexes.map((index) => payee({ contract, index: BigInt(index) })),
24
+ );
25
+ return recipientAddresses;
26
+ }
@@ -0,0 +1,48 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { ANVIL_CHAIN } from "~test/chains.js";
3
+ import { TEST_CLIENT } from "~test/test-clients.js";
4
+ import { TEST_ACCOUNT_A } from "~test/test-wallets.js";
5
+ import { getContract } from "../../../contract/contract.js";
6
+ import { deploySplitContract } from "../../../extensions/prebuilts/deploy-split.js";
7
+ import { getAllRecipientsPercentages } from "./getAllRecipientsPercentages.js";
8
+
9
+ const chain = ANVIL_CHAIN;
10
+ const client = TEST_CLIENT;
11
+
12
+ describe.runIf(process.env.TW_SECRET_KEY)("getAllRecipientsPercentages", () => {
13
+ it("should work", async () => {
14
+ const payees = [
15
+ "0x12345674b599ce99958242b3D3741e7b01841DF3",
16
+ "0xA6f11e47dE28B3dB934e945daeb6F538E9019694",
17
+ ];
18
+ const address = await deploySplitContract({
19
+ account: TEST_ACCOUNT_A,
20
+ client: TEST_CLIENT,
21
+ chain: ANVIL_CHAIN,
22
+ params: {
23
+ name: "split-contract",
24
+ payees,
25
+ shares: [
26
+ 5100n, // 51%
27
+ 4900n, // 49%
28
+ ],
29
+ },
30
+ });
31
+ const contract = getContract({
32
+ address,
33
+ chain,
34
+ client,
35
+ });
36
+ const result = await getAllRecipientsPercentages({ contract });
37
+ expect(result).toStrictEqual([
38
+ {
39
+ address: "0x12345674b599ce99958242b3D3741e7b01841DF3",
40
+ splitPercentage: 51,
41
+ },
42
+ {
43
+ address: "0xA6f11e47dE28B3dB934e945daeb6F538E9019694",
44
+ splitPercentage: 49,
45
+ },
46
+ ]);
47
+ });
48
+ });
@@ -0,0 +1,41 @@
1
+ import type { BaseTransactionOptions } from "../../../transaction/types.js";
2
+ import { getAllRecipientsAddresses } from "./getAllRecipientsAddresses.js";
3
+ import {
4
+ type SplitRecipient,
5
+ getRecipientSplitPercentage,
6
+ } from "./getRecipientSplitPercentage.js";
7
+
8
+ /**
9
+ * Get all the recipients of a Split contracts
10
+ * @extension SPLIT
11
+ * @returns an array of recipients' addresses and split percentage of each
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { getAllRecipientsPercentages } from "thirdweb/extensions/split";
16
+ *
17
+ * const allRecipients = await getAllRecipientsPercentages({ contract });
18
+ * // Example result:
19
+ * [
20
+ * {
21
+ * address: "0x1...",
22
+ * splitPercentage: 25, // 25%
23
+ * },
24
+ * {
25
+ * address: "0x2...",
26
+ * splitPercentage: 75, // 75%
27
+ * },
28
+ * ];
29
+ * ```
30
+ */
31
+ export async function getAllRecipientsPercentages(
32
+ options: BaseTransactionOptions,
33
+ ): Promise<SplitRecipient[]> {
34
+ const { contract } = options;
35
+ const recipientAddresses = await getAllRecipientsAddresses({ contract });
36
+ return await Promise.all(
37
+ recipientAddresses.map((recipientAddress) =>
38
+ getRecipientSplitPercentage({ contract, recipientAddress }),
39
+ ),
40
+ );
41
+ }
@@ -0,0 +1,45 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { ANVIL_CHAIN } from "~test/chains.js";
3
+ import { TEST_CLIENT } from "~test/test-clients.js";
4
+ import { TEST_ACCOUNT_A } from "~test/test-wallets.js";
5
+ import { getContract } from "../../../contract/contract.js";
6
+ import { deploySplitContract } from "../../../extensions/prebuilts/deploy-split.js";
7
+ import { getRecipientSplitPercentage } from "./getRecipientSplitPercentage.js";
8
+ const chain = ANVIL_CHAIN;
9
+ const client = TEST_CLIENT;
10
+
11
+ describe.runIf(process.env.TW_SECRET_KEY)("getRecipientSplitPercentage", () => {
12
+ it("should work", async () => {
13
+ const payees = [
14
+ "0x12345674b599ce99958242b3D3741e7b01841DF3",
15
+ "0xA6f11e47dE28B3dB934e945daeb6F538E9019694",
16
+ ];
17
+ const address = await deploySplitContract({
18
+ account: TEST_ACCOUNT_A,
19
+ client: TEST_CLIENT,
20
+ chain: ANVIL_CHAIN,
21
+ params: {
22
+ name: "split-contract",
23
+ payees,
24
+ shares: [
25
+ 5100n, // 51%
26
+ 4900n, // 49%
27
+ ],
28
+ },
29
+ });
30
+ const contract = getContract({
31
+ address,
32
+ chain,
33
+ client,
34
+ });
35
+ const result = await getRecipientSplitPercentage({
36
+ contract,
37
+ recipientAddress: "0x12345674b599ce99958242b3D3741e7b01841DF3",
38
+ });
39
+
40
+ expect(result).toStrictEqual({
41
+ address: "0x12345674b599ce99958242b3D3741e7b01841DF3",
42
+ splitPercentage: 51,
43
+ });
44
+ });
45
+ });
@@ -0,0 +1,40 @@
1
+ import type { BaseTransactionOptions } from "../../../transaction/types.js";
2
+ import { shares } from "../__generated__/Split/read/shares.js";
3
+ import { totalShares } from "../__generated__/Split/read/totalShares.js";
4
+
5
+ /**
6
+ * @extension SPLIT
7
+ */
8
+ export interface SplitRecipient {
9
+ /**
10
+ * The address of the recipient
11
+ */
12
+ address: string;
13
+
14
+ /**
15
+ * The split of the recipient as a percentage of the total amount
16
+ *
17
+ * I.e. If a recipient has a split of 50%, and the asset sells for 100 ETH,
18
+ * the recipient will receive 50 ETH.
19
+ */
20
+ splitPercentage: number;
21
+ }
22
+
23
+ export async function getRecipientSplitPercentage(
24
+ options: BaseTransactionOptions<{ recipientAddress: string }>,
25
+ ): Promise<SplitRecipient> {
26
+ const { contract, recipientAddress } = options;
27
+ const [_totalShares, walletsShares] = await Promise.all([
28
+ totalShares({ contract }),
29
+ shares({ contract, account: recipientAddress }),
30
+ ]);
31
+ // We convert to basis points to avoid floating point loss of precision
32
+ // 7544n -> 75.44 (75.44 %)
33
+ // also we don't have to worry about number overflow in this particular context
34
+ const splitPercentage =
35
+ (Number(walletsShares) * 1e7) / Number(_totalShares) / 1e5;
36
+ return {
37
+ address: recipientAddress,
38
+ splitPercentage,
39
+ };
40
+ }
@@ -1,6 +1,7 @@
1
1
  import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
2
2
  import type { LoginPayload } from "../../../../auth/core/types.js";
3
3
  import type { VerifyLoginPayloadParams } from "../../../../auth/core/verify-login-payload.js";
4
+ import { getCachedChain } from "../../../../chains/utils.js";
4
5
  import type { Account, Wallet } from "../../../../wallets/interfaces/wallet.js";
5
6
 
6
7
  /**
@@ -95,6 +96,12 @@ export function useSiweAuth(
95
96
  import("../../../../auth/core/sign-login-payload.js"),
96
97
  ]);
97
98
 
99
+ if (payload.chain_id) {
100
+ await activeWallet.switchChain(
101
+ getCachedChain(Number(payload.chain_id)),
102
+ );
103
+ }
104
+
98
105
  const signedPayload = await signLoginPayload({
99
106
  payload,
100
107
  account: activeAccount,
@@ -5,7 +5,7 @@ import type { Wallet } from "../../../../wallets/interfaces/wallet.js";
5
5
  import { useActiveWallet } from "../wallets/useActiveWallet.js";
6
6
 
7
7
  /**
8
- * @description Retrieves all linked profiles for the current wallet.
8
+ * Retrieves all linked profiles for the current wallet.
9
9
  *
10
10
  * @returns A React Query result containing the linked profiles for the connected in-app wallet.
11
11
  *
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.45.1";
1
+ export const version = "5.45.2-nightly-b15aa4cdff3f3b233025da285780668a18fe29ab-20240813000336";
@@ -6,7 +6,6 @@ import type {
6
6
  } from "../authentication/types.js";
7
7
 
8
8
  /**
9
- * @description
10
9
  * Gets the linked profiles for the provided wallet.
11
10
  * This method is only available for in-app wallets.
12
11
  *
@@ -24,6 +23,7 @@ import type {
24
23
  * console.log(profiles[0].type);
25
24
  * console.log(profiles[0].details.email);
26
25
  * ```
26
+ * @wallet
27
27
  */
28
28
  export async function getProfiles(wallet: Wallet<"inApp">) {
29
29
  if (wallet.id !== "inApp") {
@@ -36,10 +36,9 @@ export async function getProfiles(wallet: Wallet<"inApp">) {
36
36
  }
37
37
 
38
38
  /**
39
- * @description
40
39
  * Connects a new profile (authentication method) to the current user.
41
40
  * The connected profile can be any valid in-app wallet including email, phone, passkey, etc.
42
- * The inputs mirror those used when authenticating normally, @see {@link Wallet.connect}
41
+ * The inputs mirror those used when authenticating normally.
43
42
  *
44
43
  * **When a profile is linked to the account, that profile can then be used to sign into the account.**
45
44
  *
@@ -57,6 +56,7 @@ export async function getProfiles(wallet: Wallet<"inApp">) {
57
56
  * await wallet.connect({ strategy: "google" });
58
57
  * const profiles = await linkProfile(wallet, { strategy: "discord" });
59
58
  * ```
59
+ * @wallet
60
60
  */
61
61
  export async function linkProfile(
62
62
  wallet: Wallet<"inApp">,