thirdweb 5.60.1-nightly-985c4b08048c3676dc9be0c2069fefc73a742a3a-20241003000322 → 5.61.0-nightly-27375af91b86eb21d251a99dec57e0a6470511ca-20241004000320

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/chains/utils.js +1 -0
  2. package/dist/cjs/chains/utils.js.map +1 -1
  3. package/dist/cjs/exports/extensions/unstoppable-domains.js +10 -0
  4. package/dist/cjs/exports/extensions/unstoppable-domains.js.map +1 -0
  5. package/dist/cjs/extensions/prebuilts/get-required-transactions.js +5 -0
  6. package/dist/cjs/extensions/prebuilts/get-required-transactions.js.map +1 -1
  7. package/dist/cjs/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/getMany.js +122 -0
  8. package/dist/cjs/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/getMany.js.map +1 -0
  9. package/dist/cjs/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/namehash.js +115 -0
  10. package/dist/cjs/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/namehash.js.map +1 -0
  11. package/dist/cjs/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/reverseNameOf.js +115 -0
  12. package/dist/cjs/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/reverseNameOf.js.map +1 -0
  13. package/dist/cjs/extensions/unstoppable-domains/consts.js +5 -0
  14. package/dist/cjs/extensions/unstoppable-domains/consts.js.map +1 -0
  15. package/dist/cjs/extensions/unstoppable-domains/read/resolveAddress.js +77 -0
  16. package/dist/cjs/extensions/unstoppable-domains/read/resolveAddress.js.map +1 -0
  17. package/dist/cjs/extensions/unstoppable-domains/read/resolveName.js +60 -0
  18. package/dist/cjs/extensions/unstoppable-domains/read/resolveName.js.map +1 -0
  19. package/dist/cjs/utils/any-evm/deploy-metadata.js +1 -1
  20. package/dist/cjs/utils/any-evm/deploy-metadata.js.map +1 -1
  21. package/dist/cjs/utils/any-evm/zksync/isZkSyncChain.js +7 -17
  22. package/dist/cjs/utils/any-evm/zksync/isZkSyncChain.js.map +1 -1
  23. package/dist/cjs/version.js +1 -1
  24. package/dist/esm/chains/utils.js +1 -0
  25. package/dist/esm/chains/utils.js.map +1 -1
  26. package/dist/esm/exports/extensions/unstoppable-domains.js +4 -0
  27. package/dist/esm/exports/extensions/unstoppable-domains.js.map +1 -0
  28. package/dist/esm/extensions/prebuilts/get-required-transactions.js +5 -0
  29. package/dist/esm/extensions/prebuilts/get-required-transactions.js.map +1 -1
  30. package/dist/esm/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/getMany.js +114 -0
  31. package/dist/esm/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/getMany.js.map +1 -0
  32. package/dist/esm/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/namehash.js +107 -0
  33. package/dist/esm/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/namehash.js.map +1 -0
  34. package/dist/esm/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/reverseNameOf.js +107 -0
  35. package/dist/esm/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/reverseNameOf.js.map +1 -0
  36. package/dist/esm/extensions/unstoppable-domains/consts.js +2 -0
  37. package/dist/esm/extensions/unstoppable-domains/consts.js.map +1 -0
  38. package/dist/esm/extensions/unstoppable-domains/read/resolveAddress.js +74 -0
  39. package/dist/esm/extensions/unstoppable-domains/read/resolveAddress.js.map +1 -0
  40. package/dist/esm/extensions/unstoppable-domains/read/resolveName.js +57 -0
  41. package/dist/esm/extensions/unstoppable-domains/read/resolveName.js.map +1 -0
  42. package/dist/esm/utils/any-evm/deploy-metadata.js +1 -1
  43. package/dist/esm/utils/any-evm/deploy-metadata.js.map +1 -1
  44. package/dist/esm/utils/any-evm/zksync/isZkSyncChain.js +7 -17
  45. package/dist/esm/utils/any-evm/zksync/isZkSyncChain.js.map +1 -1
  46. package/dist/esm/version.js +1 -1
  47. package/dist/types/chains/types.d.ts +1 -0
  48. package/dist/types/chains/types.d.ts.map +1 -1
  49. package/dist/types/exports/extensions/unstoppable-domains.d.ts +4 -0
  50. package/dist/types/exports/extensions/unstoppable-domains.d.ts.map +1 -0
  51. package/dist/types/extensions/prebuilts/get-required-transactions.d.ts +3 -0
  52. package/dist/types/extensions/prebuilts/get-required-transactions.d.ts.map +1 -1
  53. package/dist/types/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/getMany.d.ts +90 -0
  54. package/dist/types/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/getMany.d.ts.map +1 -0
  55. package/dist/types/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/namehash.d.ts +83 -0
  56. package/dist/types/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/namehash.d.ts.map +1 -0
  57. package/dist/types/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/reverseNameOf.d.ts +83 -0
  58. package/dist/types/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/reverseNameOf.d.ts.map +1 -0
  59. package/dist/types/extensions/unstoppable-domains/consts.d.ts +2 -0
  60. package/dist/types/extensions/unstoppable-domains/consts.d.ts.map +1 -0
  61. package/dist/types/extensions/unstoppable-domains/read/resolveAddress.d.ts +45 -0
  62. package/dist/types/extensions/unstoppable-domains/read/resolveAddress.d.ts.map +1 -0
  63. package/dist/types/extensions/unstoppable-domains/read/resolveName.d.ts +43 -0
  64. package/dist/types/extensions/unstoppable-domains/read/resolveName.d.ts.map +1 -0
  65. package/dist/types/utils/any-evm/zksync/isZkSyncChain.d.ts.map +1 -1
  66. package/dist/types/version.d.ts +1 -1
  67. package/package.json +1 -1
  68. package/src/chains/types.ts +1 -0
  69. package/src/chains/utils.ts +1 -0
  70. package/src/exports/extensions/unstoppable-domains.ts +9 -0
  71. package/src/extensions/prebuilts/get-required-transactions.ts +5 -0
  72. package/src/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/getMany.ts +130 -0
  73. package/src/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/namehash.ts +124 -0
  74. package/src/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/reverseNameOf.ts +126 -0
  75. package/src/extensions/unstoppable-domains/consts.ts +1 -0
  76. package/src/extensions/unstoppable-domains/read/resolveAddress.test.ts +18 -0
  77. package/src/extensions/unstoppable-domains/read/resolveAddress.ts +96 -0
  78. package/src/extensions/unstoppable-domains/read/resolveName.test.ts +16 -0
  79. package/src/extensions/unstoppable-domains/read/resolveName.ts +77 -0
  80. package/src/utils/any-evm/deploy-metadata.ts +1 -1
  81. package/src/utils/any-evm/zksync/isZkSyncChain.ts +7 -23
  82. package/src/version.ts +1 -1
@@ -0,0 +1,130 @@
1
+ import type { AbiParameterToPrimitiveType } from "abitype";
2
+ import { readContract } from "../../../../../transaction/read-contract.js";
3
+ import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
4
+ import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
5
+ import { decodeAbiParameters } from "viem";
6
+ import type { Hex } from "../../../../../utils/encoding/hex.js";
7
+ import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
8
+
9
+ /**
10
+ * Represents the parameters for the "getMany" function.
11
+ */
12
+ export type GetManyParams = {
13
+ keys: AbiParameterToPrimitiveType<{ type: "string[]"; name: "keys" }>;
14
+ tokenId: AbiParameterToPrimitiveType<{ type: "uint256"; name: "tokenId" }>;
15
+ };
16
+
17
+ export const FN_SELECTOR = "0x1bd8cc1a" as const;
18
+ const FN_INPUTS = [
19
+ {
20
+ type: "string[]",
21
+ name: "keys",
22
+ },
23
+ {
24
+ type: "uint256",
25
+ name: "tokenId",
26
+ },
27
+ ] as const;
28
+ const FN_OUTPUTS = [
29
+ {
30
+ type: "string[]",
31
+ name: "values",
32
+ },
33
+ ] as const;
34
+
35
+ /**
36
+ * Checks if the `getMany` method is supported by the given contract.
37
+ * @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors.
38
+ * @returns A boolean indicating if the `getMany` method is supported.
39
+ * @extension UNSTOPPABLE-DOMAINS
40
+ * @example
41
+ * ```ts
42
+ * import { isGetManySupported } from "thirdweb/extensions/unstoppable-domains";
43
+ * const supported = isGetManySupported(["0x..."]);
44
+ * ```
45
+ */
46
+ export function isGetManySupported(availableSelectors: string[]) {
47
+ return detectMethod({
48
+ availableSelectors,
49
+ method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
50
+ });
51
+ }
52
+
53
+ /**
54
+ * Encodes the parameters for the "getMany" function.
55
+ * @param options - The options for the getMany function.
56
+ * @returns The encoded ABI parameters.
57
+ * @extension UNSTOPPABLE-DOMAINS
58
+ * @example
59
+ * ```ts
60
+ * import { encodeGetManyParams } from "thirdweb/extensions/unstoppable-domains";
61
+ * const result = encodeGetManyParams({
62
+ * keys: ...,
63
+ * tokenId: ...,
64
+ * });
65
+ * ```
66
+ */
67
+ export function encodeGetManyParams(options: GetManyParams) {
68
+ return encodeAbiParameters(FN_INPUTS, [options.keys, options.tokenId]);
69
+ }
70
+
71
+ /**
72
+ * Encodes the "getMany" function into a Hex string with its parameters.
73
+ * @param options - The options for the getMany function.
74
+ * @returns The encoded hexadecimal string.
75
+ * @extension UNSTOPPABLE-DOMAINS
76
+ * @example
77
+ * ```ts
78
+ * import { encodeGetMany } from "thirdweb/extensions/unstoppable-domains";
79
+ * const result = encodeGetMany({
80
+ * keys: ...,
81
+ * tokenId: ...,
82
+ * });
83
+ * ```
84
+ */
85
+ export function encodeGetMany(options: GetManyParams) {
86
+ // we do a "manual" concat here to avoid the overhead of the "concatHex" function
87
+ // we can do this because we know the specific formats of the values
88
+ return (FN_SELECTOR +
89
+ encodeGetManyParams(options).slice(2)) as `${typeof FN_SELECTOR}${string}`;
90
+ }
91
+
92
+ /**
93
+ * Decodes the result of the getMany function call.
94
+ * @param result - The hexadecimal result to decode.
95
+ * @returns The decoded result as per the FN_OUTPUTS definition.
96
+ * @extension UNSTOPPABLE-DOMAINS
97
+ * @example
98
+ * ```ts
99
+ * import { decodeGetManyResult } from "thirdweb/extensions/unstoppable-domains";
100
+ * const result = decodeGetManyResultResult("...");
101
+ * ```
102
+ */
103
+ export function decodeGetManyResult(result: Hex) {
104
+ return decodeAbiParameters(FN_OUTPUTS, result)[0];
105
+ }
106
+
107
+ /**
108
+ * Calls the "getMany" function on the contract.
109
+ * @param options - The options for the getMany function.
110
+ * @returns The parsed result of the function call.
111
+ * @extension UNSTOPPABLE-DOMAINS
112
+ * @example
113
+ * ```ts
114
+ * import { getMany } from "thirdweb/extensions/unstoppable-domains";
115
+ *
116
+ * const result = await getMany({
117
+ * contract,
118
+ * keys: ...,
119
+ * tokenId: ...,
120
+ * });
121
+ *
122
+ * ```
123
+ */
124
+ export async function getMany(options: BaseTransactionOptions<GetManyParams>) {
125
+ return readContract({
126
+ contract: options.contract,
127
+ method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
128
+ params: [options.keys, options.tokenId],
129
+ });
130
+ }
@@ -0,0 +1,124 @@
1
+ import type { AbiParameterToPrimitiveType } from "abitype";
2
+ import { readContract } from "../../../../../transaction/read-contract.js";
3
+ import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
4
+ import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
5
+ import { decodeAbiParameters } from "viem";
6
+ import type { Hex } from "../../../../../utils/encoding/hex.js";
7
+ import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
8
+
9
+ /**
10
+ * Represents the parameters for the "namehash" function.
11
+ */
12
+ export type NamehashParams = {
13
+ labels: AbiParameterToPrimitiveType<{ type: "string[]"; name: "labels" }>;
14
+ };
15
+
16
+ export const FN_SELECTOR = "0x276fabb1" as const;
17
+ const FN_INPUTS = [
18
+ {
19
+ type: "string[]",
20
+ name: "labels",
21
+ },
22
+ ] as const;
23
+ const FN_OUTPUTS = [
24
+ {
25
+ type: "uint256",
26
+ name: "hash",
27
+ },
28
+ ] as const;
29
+
30
+ /**
31
+ * Checks if the `namehash` method is supported by the given contract.
32
+ * @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors.
33
+ * @returns A boolean indicating if the `namehash` method is supported.
34
+ * @extension UNSTOPPABLE-DOMAINS
35
+ * @example
36
+ * ```ts
37
+ * import { isNamehashSupported } from "thirdweb/extensions/unstoppable-domains";
38
+ * const supported = isNamehashSupported(["0x..."]);
39
+ * ```
40
+ */
41
+ export function isNamehashSupported(availableSelectors: string[]) {
42
+ return detectMethod({
43
+ availableSelectors,
44
+ method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
45
+ });
46
+ }
47
+
48
+ /**
49
+ * Encodes the parameters for the "namehash" function.
50
+ * @param options - The options for the namehash function.
51
+ * @returns The encoded ABI parameters.
52
+ * @extension UNSTOPPABLE-DOMAINS
53
+ * @example
54
+ * ```ts
55
+ * import { encodeNamehashParams } from "thirdweb/extensions/unstoppable-domains";
56
+ * const result = encodeNamehashParams({
57
+ * labels: ...,
58
+ * });
59
+ * ```
60
+ */
61
+ export function encodeNamehashParams(options: NamehashParams) {
62
+ return encodeAbiParameters(FN_INPUTS, [options.labels]);
63
+ }
64
+
65
+ /**
66
+ * Encodes the "namehash" function into a Hex string with its parameters.
67
+ * @param options - The options for the namehash function.
68
+ * @returns The encoded hexadecimal string.
69
+ * @extension UNSTOPPABLE-DOMAINS
70
+ * @example
71
+ * ```ts
72
+ * import { encodeNamehash } from "thirdweb/extensions/unstoppable-domains";
73
+ * const result = encodeNamehash({
74
+ * labels: ...,
75
+ * });
76
+ * ```
77
+ */
78
+ export function encodeNamehash(options: NamehashParams) {
79
+ // we do a "manual" concat here to avoid the overhead of the "concatHex" function
80
+ // we can do this because we know the specific formats of the values
81
+ return (FN_SELECTOR +
82
+ encodeNamehashParams(options).slice(2)) as `${typeof FN_SELECTOR}${string}`;
83
+ }
84
+
85
+ /**
86
+ * Decodes the result of the namehash function call.
87
+ * @param result - The hexadecimal result to decode.
88
+ * @returns The decoded result as per the FN_OUTPUTS definition.
89
+ * @extension UNSTOPPABLE-DOMAINS
90
+ * @example
91
+ * ```ts
92
+ * import { decodeNamehashResult } from "thirdweb/extensions/unstoppable-domains";
93
+ * const result = decodeNamehashResultResult("...");
94
+ * ```
95
+ */
96
+ export function decodeNamehashResult(result: Hex) {
97
+ return decodeAbiParameters(FN_OUTPUTS, result)[0];
98
+ }
99
+
100
+ /**
101
+ * Calls the "namehash" function on the contract.
102
+ * @param options - The options for the namehash function.
103
+ * @returns The parsed result of the function call.
104
+ * @extension UNSTOPPABLE-DOMAINS
105
+ * @example
106
+ * ```ts
107
+ * import { namehash } from "thirdweb/extensions/unstoppable-domains";
108
+ *
109
+ * const result = await namehash({
110
+ * contract,
111
+ * labels: ...,
112
+ * });
113
+ *
114
+ * ```
115
+ */
116
+ export async function namehash(
117
+ options: BaseTransactionOptions<NamehashParams>,
118
+ ) {
119
+ return readContract({
120
+ contract: options.contract,
121
+ method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
122
+ params: [options.labels],
123
+ });
124
+ }
@@ -0,0 +1,126 @@
1
+ import type { AbiParameterToPrimitiveType } from "abitype";
2
+ import { readContract } from "../../../../../transaction/read-contract.js";
3
+ import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
4
+ import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
5
+ import { decodeAbiParameters } from "viem";
6
+ import type { Hex } from "../../../../../utils/encoding/hex.js";
7
+ import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
8
+
9
+ /**
10
+ * Represents the parameters for the "reverseNameOf" function.
11
+ */
12
+ export type ReverseNameOfParams = {
13
+ addr: AbiParameterToPrimitiveType<{ type: "address"; name: "addr" }>;
14
+ };
15
+
16
+ export const FN_SELECTOR = "0xbebec6b4" as const;
17
+ const FN_INPUTS = [
18
+ {
19
+ type: "address",
20
+ name: "addr",
21
+ },
22
+ ] as const;
23
+ const FN_OUTPUTS = [
24
+ {
25
+ type: "string",
26
+ name: "reverseUri",
27
+ },
28
+ ] as const;
29
+
30
+ /**
31
+ * Checks if the `reverseNameOf` method is supported by the given contract.
32
+ * @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors.
33
+ * @returns A boolean indicating if the `reverseNameOf` method is supported.
34
+ * @extension UNSTOPPABLE-DOMAINS
35
+ * @example
36
+ * ```ts
37
+ * import { isReverseNameOfSupported } from "thirdweb/extensions/unstoppable-domains";
38
+ * const supported = isReverseNameOfSupported(["0x..."]);
39
+ * ```
40
+ */
41
+ export function isReverseNameOfSupported(availableSelectors: string[]) {
42
+ return detectMethod({
43
+ availableSelectors,
44
+ method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
45
+ });
46
+ }
47
+
48
+ /**
49
+ * Encodes the parameters for the "reverseNameOf" function.
50
+ * @param options - The options for the reverseNameOf function.
51
+ * @returns The encoded ABI parameters.
52
+ * @extension UNSTOPPABLE-DOMAINS
53
+ * @example
54
+ * ```ts
55
+ * import { encodeReverseNameOfParams } from "thirdweb/extensions/unstoppable-domains";
56
+ * const result = encodeReverseNameOfParams({
57
+ * addr: ...,
58
+ * });
59
+ * ```
60
+ */
61
+ export function encodeReverseNameOfParams(options: ReverseNameOfParams) {
62
+ return encodeAbiParameters(FN_INPUTS, [options.addr]);
63
+ }
64
+
65
+ /**
66
+ * Encodes the "reverseNameOf" function into a Hex string with its parameters.
67
+ * @param options - The options for the reverseNameOf function.
68
+ * @returns The encoded hexadecimal string.
69
+ * @extension UNSTOPPABLE-DOMAINS
70
+ * @example
71
+ * ```ts
72
+ * import { encodeReverseNameOf } from "thirdweb/extensions/unstoppable-domains";
73
+ * const result = encodeReverseNameOf({
74
+ * addr: ...,
75
+ * });
76
+ * ```
77
+ */
78
+ export function encodeReverseNameOf(options: ReverseNameOfParams) {
79
+ // we do a "manual" concat here to avoid the overhead of the "concatHex" function
80
+ // we can do this because we know the specific formats of the values
81
+ return (FN_SELECTOR +
82
+ encodeReverseNameOfParams(options).slice(
83
+ 2,
84
+ )) as `${typeof FN_SELECTOR}${string}`;
85
+ }
86
+
87
+ /**
88
+ * Decodes the result of the reverseNameOf function call.
89
+ * @param result - The hexadecimal result to decode.
90
+ * @returns The decoded result as per the FN_OUTPUTS definition.
91
+ * @extension UNSTOPPABLE-DOMAINS
92
+ * @example
93
+ * ```ts
94
+ * import { decodeReverseNameOfResult } from "thirdweb/extensions/unstoppable-domains";
95
+ * const result = decodeReverseNameOfResultResult("...");
96
+ * ```
97
+ */
98
+ export function decodeReverseNameOfResult(result: Hex) {
99
+ return decodeAbiParameters(FN_OUTPUTS, result)[0];
100
+ }
101
+
102
+ /**
103
+ * Calls the "reverseNameOf" function on the contract.
104
+ * @param options - The options for the reverseNameOf function.
105
+ * @returns The parsed result of the function call.
106
+ * @extension UNSTOPPABLE-DOMAINS
107
+ * @example
108
+ * ```ts
109
+ * import { reverseNameOf } from "thirdweb/extensions/unstoppable-domains";
110
+ *
111
+ * const result = await reverseNameOf({
112
+ * contract,
113
+ * addr: ...,
114
+ * });
115
+ *
116
+ * ```
117
+ */
118
+ export async function reverseNameOf(
119
+ options: BaseTransactionOptions<ReverseNameOfParams>,
120
+ ) {
121
+ return readContract({
122
+ contract: options.contract,
123
+ method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
124
+ params: [options.addr],
125
+ });
126
+ }
@@ -0,0 +1 @@
1
+ export const UD_POLYGON_MAINNET = "0xa9a6A3626993D487d2Dbda3173cf58cA1a9D9e9f";
@@ -0,0 +1,18 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { TEST_CLIENT } from "~test/test-clients.js";
3
+ import { resolveAddress } from "./resolveAddress.js";
4
+
5
+ // Double check: https://unstoppabledomains.com/d/thirdwebsdk.unstoppable
6
+
7
+ describe("Unstoppable Domain: resolve address", () => {
8
+ it("should resolve address", async () => {
9
+ expect(
10
+ (
11
+ await resolveAddress({
12
+ name: "thirdwebsdk.unstoppable",
13
+ client: TEST_CLIENT,
14
+ })
15
+ ).toLowerCase(),
16
+ ).toBe("0x12345674b599ce99958242b3D3741e7b01841DF3".toLowerCase());
17
+ });
18
+ });
@@ -0,0 +1,96 @@
1
+ import { polygon } from "../../../chains/chain-definitions/polygon.js";
2
+ import type { Chain } from "../../../chains/types.js";
3
+ import type { ThirdwebClient } from "../../../client/client.js";
4
+ import { getContract } from "../../../contract/contract.js";
5
+ import { getAddress, isAddress } from "../../../utils/address.js";
6
+ import { withCache } from "../../../utils/promise/withCache.js";
7
+ import { getMany } from "../__generated__/UnstoppableDomains/read/getMany.js";
8
+ import { namehash } from "../__generated__/UnstoppableDomains/read/namehash.js";
9
+ import { UD_POLYGON_MAINNET } from "../consts.js";
10
+
11
+ /**
12
+ * @extension UNSTOPPABLE-DOMAINS
13
+ */
14
+ export type ResolveAddressOptions = {
15
+ client: ThirdwebClient;
16
+ name: string;
17
+ resolverAddress?: string;
18
+ resolverChain?: Chain;
19
+ };
20
+
21
+ /**
22
+ * Resolve an Unstoppable-Domain domain to an Ethereum address
23
+ * @param options - The options for resolving an UD domain
24
+ * @returns The Ethereum address associated with the domain name. [Learn more](https://docs.unstoppabledomains.com/reverse-resolution/)
25
+ * @example
26
+ *
27
+ * ### Basic usage
28
+ * ```ts
29
+ * import { resolveAddress } from "thirdweb/extension/unstoppable-domains";
30
+ *
31
+ * const address = await resolveAddress({
32
+ * client,
33
+ * name: "thirdweb.crypto",
34
+ * });
35
+ * ```
36
+ *
37
+ * ### Custom resolver
38
+ * By default this extension will try to resolve the name on Polygon mainnet,
39
+ * you can decide to customize the resolver contract by specifying `resolverAddress` and `resolverChain`
40
+ * ```ts
41
+ * import { ethereum } from "thirdweb/chains";
42
+ *
43
+ * const address = await resolveAddress({
44
+ * client,
45
+ * name: "thirdweb.crypto",
46
+ * resolverAddress: "0x...",
47
+ * resolverChain: ethereum,
48
+ * });
49
+ * ```
50
+ *
51
+ * @extension UNSTOPPABLE-DOMAINS
52
+ */
53
+ export async function resolveAddress(
54
+ options: ResolveAddressOptions,
55
+ ): Promise<string> {
56
+ const { client, name, resolverAddress, resolverChain } = options;
57
+ if (isAddress(name)) {
58
+ return getAddress(name);
59
+ }
60
+ return withCache(
61
+ async () => {
62
+ const contract = getContract({
63
+ client,
64
+ chain: resolverChain || polygon,
65
+ address: resolverAddress || UD_POLYGON_MAINNET,
66
+ });
67
+
68
+ // Get namehash
69
+ const possibleTokenId = await namehash({
70
+ contract,
71
+ labels: name.split("."),
72
+ });
73
+
74
+ // Resolve ETH address from the tokenId
75
+ const resolved = await getMany({
76
+ contract,
77
+ tokenId: possibleTokenId,
78
+ // note that you can also retrieve the (BTC, SOL, etc.) address by using "crypto.<symbol>.address" (should that become useful one day)
79
+ keys: ["crypto.ETH.address"],
80
+ });
81
+
82
+ const possibleETHAddress = resolved[0];
83
+ if (!possibleETHAddress) {
84
+ throw new Error(
85
+ `Could not retrieve any ETH address associated with domain name: ${name}. Make sure you have set the base EVM address for your domain here: https://unstoppabledomains.com/manage?page=crypto&domain=<your-domain>`,
86
+ );
87
+ }
88
+ return possibleETHAddress;
89
+ },
90
+ {
91
+ cacheKey: `unstoppable-domain:addr:${resolverChain?.id || 1}:${name}`,
92
+ // 1min cache
93
+ cacheTime: 60 * 1000,
94
+ },
95
+ );
96
+ }
@@ -0,0 +1,16 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { TEST_CLIENT } from "~test/test-clients.js";
3
+ import { resolveName } from "./resolveName.js";
4
+
5
+ // Double check: https://unstoppabledomains.com/d/thirdwebsdk.unstoppable
6
+
7
+ describe("Unstoppable Domain: resolve name", () => {
8
+ it("should resolve name", async () => {
9
+ expect(
10
+ await resolveName({
11
+ address: "0x12345674b599ce99958242b3D3741e7b01841DF3",
12
+ client: TEST_CLIENT,
13
+ }),
14
+ ).toBe("thirdwebsdk.unstoppable");
15
+ });
16
+ });
@@ -0,0 +1,77 @@
1
+ import { polygon } from "../../../chains/chain-definitions/polygon.js";
2
+ import type { Chain } from "../../../chains/types.js";
3
+ import type { ThirdwebClient } from "../../../client/client.js";
4
+ import { getContract } from "../../../contract/contract.js";
5
+ import { withCache } from "../../../utils/promise/withCache.js";
6
+ import { reverseNameOf } from "../__generated__/UnstoppableDomains/read/reverseNameOf.js";
7
+ import { UD_POLYGON_MAINNET } from "../consts.js";
8
+
9
+ /**
10
+ * @extension UNSTOPPABLE-DOMAINS
11
+ */
12
+ export type ResolveUDNameOptions = {
13
+ client: ThirdwebClient;
14
+ address: string;
15
+ resolverAddress?: string;
16
+ resolverChain?: Chain;
17
+ };
18
+
19
+ /**
20
+ * Resolves the primary Untoppable-Domains name for a specified address.
21
+ * @param options - The options for resolving an UD domain
22
+ * @example
23
+ *
24
+ * ### Basic usage
25
+ * ```ts
26
+ * import { resolveName } from "thirdweb/extension/unstoppable-domains";
27
+ *
28
+ * const name = await resolveName({
29
+ * client,
30
+ * address: "0x...",
31
+ * });
32
+ * ```
33
+ *
34
+ * ### Custom resolver
35
+ * By default this extension will try to resolve the address on Polygon mainnet,
36
+ * you can decide to customize the resolver contract by specifying `resolverAddress` and `resolverChain`
37
+ * ```ts
38
+ * import { ethereum } from "thirdweb/chains";
39
+ *
40
+ * const address = await resolveName({
41
+ * client,
42
+ * address: "0x...",
43
+ * resolverAddress: "0x...",
44
+ * resolverChain: ethereum,
45
+ * });
46
+ * ```
47
+ * @extension UNSTOPPABLE-DOMAINS
48
+ */
49
+ export async function resolveName(
50
+ options: ResolveUDNameOptions,
51
+ ): Promise<string> {
52
+ const { client, address, resolverAddress, resolverChain } = options;
53
+ return withCache(
54
+ async () => {
55
+ const contract = getContract({
56
+ client,
57
+ chain: resolverChain || polygon,
58
+ address: resolverAddress || UD_POLYGON_MAINNET,
59
+ });
60
+
61
+ // Note: if the given wallet address does not have any UD name, `reverseNameOf` will return an empty string
62
+ // This can still happen if you have transfered a domain to a new address, and forgot to set up the Reverse Resolution on the new address
63
+ const domain = await reverseNameOf({ contract, addr: address });
64
+ if (!domain) {
65
+ throw new Error(
66
+ `Failed to retrieve domain for address: ${address}. Make sure you have set the Reverse Resolution address for your domain at https://unstoppabledomains.com/manage?page=reverseResolution&domain=your-domain`,
67
+ );
68
+ }
69
+ return domain;
70
+ },
71
+ {
72
+ cacheKey: `unstoppable-domain:name:${resolverChain?.id || 1}:${address}`,
73
+ // 1min cache
74
+ cacheTime: 60 * 1000,
75
+ },
76
+ );
77
+ }
@@ -80,7 +80,7 @@ export async function fetchBytecodeFromCompilerMetadata(options: {
80
80
  async () => {
81
81
  const isZksolc = await isZkSyncChain(chain);
82
82
  const bytecodeUri = isZksolc
83
- ? compilerMetadata.compilers?.zksolc[0]?.bytecodeUri
83
+ ? compilerMetadata.compilers?.zksolc?.[0]?.bytecodeUri
84
84
  : compilerMetadata.bytecodeUri;
85
85
 
86
86
  if (!bytecodeUri) {
@@ -1,5 +1,5 @@
1
1
  import type { Chain } from "../../../chains/types.js";
2
- import { withCache } from "../../promise/withCache.js";
2
+ import { getChainMetadata } from "../../../chains/utils.js";
3
3
 
4
4
  export async function isZkSyncChain(chain: Chain) {
5
5
  if (chain.id === 1337 || chain.id === 31337) {
@@ -12,36 +12,20 @@ export async function isZkSyncChain(chain: Chain) {
12
12
  chain.id === 300 ||
13
13
  chain.id === 302 ||
14
14
  chain.id === 11124 ||
15
- chain.id === 282 || // cronos zkevm testnet
16
- chain.id === 388 // cronos zkevm mainnet
15
+ chain.id === 282 ||
16
+ chain.id === 388 ||
17
+ chain.id === 4654 ||
18
+ chain.id === 333271
17
19
  ) {
18
20
  return true;
19
21
  }
20
22
 
21
23
  // fallback to checking the stack on rpc
22
24
  try {
23
- const stack = await getChainStack(chain.id);
24
- return stack === "zksync-stack";
25
+ const chainMetadata = await getChainMetadata(chain);
26
+ return chainMetadata.stackType === "zksync_stack";
25
27
  } catch {
26
28
  // If the network check fails, assume it's not a ZkSync chain
27
29
  return false;
28
30
  }
29
31
  }
30
-
31
- async function getChainStack(chainId: number): Promise<string> {
32
- return withCache(
33
- async () => {
34
- const res = await fetch(`https://${chainId}.rpc.thirdweb.com/stack`);
35
-
36
- if (!res.ok) {
37
- res.body?.cancel();
38
- throw new Error(`Error fetching stack for ${chainId}`);
39
- }
40
-
41
- const data = await res.json();
42
-
43
- return data.stack;
44
- },
45
- { cacheKey: `stack:${chainId}`, cacheTime: 24 * 60 * 60 * 1000 },
46
- );
47
- }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.60.1-nightly-985c4b08048c3676dc9be0c2069fefc73a742a3a-20241003000322";
1
+ export const version = "5.61.0-nightly-27375af91b86eb21d251a99dec57e0a6470511ca-20241004000320";