thirdweb 5.60.1 → 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 (59) hide show
  1. package/dist/cjs/exports/extensions/unstoppable-domains.js +10 -0
  2. package/dist/cjs/exports/extensions/unstoppable-domains.js.map +1 -0
  3. package/dist/cjs/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/getMany.js +122 -0
  4. package/dist/cjs/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/getMany.js.map +1 -0
  5. package/dist/cjs/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/namehash.js +115 -0
  6. package/dist/cjs/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/namehash.js.map +1 -0
  7. package/dist/cjs/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/reverseNameOf.js +115 -0
  8. package/dist/cjs/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/reverseNameOf.js.map +1 -0
  9. package/dist/cjs/extensions/unstoppable-domains/consts.js +5 -0
  10. package/dist/cjs/extensions/unstoppable-domains/consts.js.map +1 -0
  11. package/dist/cjs/extensions/unstoppable-domains/read/resolveAddress.js +77 -0
  12. package/dist/cjs/extensions/unstoppable-domains/read/resolveAddress.js.map +1 -0
  13. package/dist/cjs/extensions/unstoppable-domains/read/resolveName.js +60 -0
  14. package/dist/cjs/extensions/unstoppable-domains/read/resolveName.js.map +1 -0
  15. package/dist/cjs/version.js +1 -1
  16. package/dist/cjs/version.js.map +1 -1
  17. package/dist/esm/exports/extensions/unstoppable-domains.js +4 -0
  18. package/dist/esm/exports/extensions/unstoppable-domains.js.map +1 -0
  19. package/dist/esm/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/getMany.js +114 -0
  20. package/dist/esm/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/getMany.js.map +1 -0
  21. package/dist/esm/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/namehash.js +107 -0
  22. package/dist/esm/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/namehash.js.map +1 -0
  23. package/dist/esm/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/reverseNameOf.js +107 -0
  24. package/dist/esm/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/reverseNameOf.js.map +1 -0
  25. package/dist/esm/extensions/unstoppable-domains/consts.js +2 -0
  26. package/dist/esm/extensions/unstoppable-domains/consts.js.map +1 -0
  27. package/dist/esm/extensions/unstoppable-domains/read/resolveAddress.js +74 -0
  28. package/dist/esm/extensions/unstoppable-domains/read/resolveAddress.js.map +1 -0
  29. package/dist/esm/extensions/unstoppable-domains/read/resolveName.js +57 -0
  30. package/dist/esm/extensions/unstoppable-domains/read/resolveName.js.map +1 -0
  31. package/dist/esm/version.js +1 -1
  32. package/dist/esm/version.js.map +1 -1
  33. package/dist/types/exports/extensions/unstoppable-domains.d.ts +4 -0
  34. package/dist/types/exports/extensions/unstoppable-domains.d.ts.map +1 -0
  35. package/dist/types/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/getMany.d.ts +90 -0
  36. package/dist/types/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/getMany.d.ts.map +1 -0
  37. package/dist/types/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/namehash.d.ts +83 -0
  38. package/dist/types/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/namehash.d.ts.map +1 -0
  39. package/dist/types/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/reverseNameOf.d.ts +83 -0
  40. package/dist/types/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/reverseNameOf.d.ts.map +1 -0
  41. package/dist/types/extensions/unstoppable-domains/consts.d.ts +2 -0
  42. package/dist/types/extensions/unstoppable-domains/consts.d.ts.map +1 -0
  43. package/dist/types/extensions/unstoppable-domains/read/resolveAddress.d.ts +45 -0
  44. package/dist/types/extensions/unstoppable-domains/read/resolveAddress.d.ts.map +1 -0
  45. package/dist/types/extensions/unstoppable-domains/read/resolveName.d.ts +43 -0
  46. package/dist/types/extensions/unstoppable-domains/read/resolveName.d.ts.map +1 -0
  47. package/dist/types/version.d.ts +1 -1
  48. package/dist/types/version.d.ts.map +1 -1
  49. package/package.json +1 -1
  50. package/src/exports/extensions/unstoppable-domains.ts +9 -0
  51. package/src/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/getMany.ts +130 -0
  52. package/src/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/namehash.ts +124 -0
  53. package/src/extensions/unstoppable-domains/__generated__/UnstoppableDomains/read/reverseNameOf.ts +126 -0
  54. package/src/extensions/unstoppable-domains/consts.ts +1 -0
  55. package/src/extensions/unstoppable-domains/read/resolveAddress.test.ts +18 -0
  56. package/src/extensions/unstoppable-domains/read/resolveAddress.ts +96 -0
  57. package/src/extensions/unstoppable-domains/read/resolveName.test.ts +16 -0
  58. package/src/extensions/unstoppable-domains/read/resolveName.ts +77 -0
  59. package/src/version.ts +1 -1
@@ -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
+ }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.60.1";
1
+ export const version = "5.61.0-nightly-27375af91b86eb21d251a99dec57e0a6470511ca-20241004000320";