thirdweb 5.45.0 → 5.45.2-nightly-141fd53759f1b5515e38688fe96364edc4c76644-20240812000351
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.
- package/dist/cjs/cli/bin.js +0 -17
- package/dist/cjs/cli/bin.js.map +1 -1
- package/dist/cjs/exports/deploys.js +3 -1
- package/dist/cjs/exports/deploys.js.map +1 -1
- package/dist/cjs/exports/extensions/split.js +7 -1
- package/dist/cjs/exports/extensions/split.js.map +1 -1
- package/dist/cjs/extensions/prebuilts/__generated__/Split/write/initialize.js +157 -0
- package/dist/cjs/extensions/prebuilts/__generated__/Split/write/initialize.js.map +1 -0
- package/dist/cjs/extensions/prebuilts/deploy-split.js +79 -0
- package/dist/cjs/extensions/prebuilts/deploy-split.js.map +1 -0
- package/dist/cjs/extensions/split/__generated__/Split/read/totalShares.js +71 -0
- package/dist/cjs/extensions/split/__generated__/Split/read/totalShares.js.map +1 -0
- package/dist/cjs/extensions/split/read/getAllRecipientsAddresses.js +24 -0
- package/dist/cjs/extensions/split/read/getAllRecipientsAddresses.js.map +1 -0
- package/dist/cjs/extensions/split/read/getAllRecipientsPercentages.js +34 -0
- package/dist/cjs/extensions/split/read/getAllRecipientsPercentages.js.map +1 -0
- package/dist/cjs/extensions/split/read/getRecipientSplitPercentage.js +21 -0
- package/dist/cjs/extensions/split/read/getRecipientSplitPercentage.js.map +1 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/cli/bin.js +0 -17
- package/dist/esm/cli/bin.js.map +1 -1
- package/dist/esm/exports/deploys.js +1 -0
- package/dist/esm/exports/deploys.js.map +1 -1
- package/dist/esm/exports/extensions/split.js +3 -0
- package/dist/esm/exports/extensions/split.js.map +1 -1
- package/dist/esm/extensions/prebuilts/__generated__/Split/write/initialize.js +150 -0
- package/dist/esm/extensions/prebuilts/__generated__/Split/write/initialize.js.map +1 -0
- package/dist/esm/extensions/prebuilts/deploy-split.js +76 -0
- package/dist/esm/extensions/prebuilts/deploy-split.js.map +1 -0
- package/dist/esm/extensions/split/__generated__/Split/read/totalShares.js +65 -0
- package/dist/esm/extensions/split/__generated__/Split/read/totalShares.js.map +1 -0
- package/dist/esm/extensions/split/read/getAllRecipientsAddresses.js +21 -0
- package/dist/esm/extensions/split/read/getAllRecipientsAddresses.js.map +1 -0
- package/dist/esm/extensions/split/read/getAllRecipientsPercentages.js +31 -0
- package/dist/esm/extensions/split/read/getAllRecipientsPercentages.js.map +1 -0
- package/dist/esm/extensions/split/read/getRecipientSplitPercentage.js +18 -0
- package/dist/esm/extensions/split/read/getRecipientSplitPercentage.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/exports/deploys.d.ts +1 -0
- package/dist/types/exports/deploys.d.ts.map +1 -1
- package/dist/types/exports/extensions/split.d.ts +3 -0
- package/dist/types/exports/extensions/split.d.ts.map +1 -1
- package/dist/types/extensions/prebuilts/__generated__/Split/write/initialize.d.ts +108 -0
- package/dist/types/extensions/prebuilts/__generated__/Split/write/initialize.d.ts.map +1 -0
- package/dist/types/extensions/prebuilts/deploy-split.d.ts +66 -0
- package/dist/types/extensions/prebuilts/deploy-split.d.ts.map +1 -0
- package/dist/types/extensions/split/__generated__/Split/read/totalShares.d.ts +46 -0
- package/dist/types/extensions/split/__generated__/Split/read/totalShares.d.ts.map +1 -0
- package/dist/types/extensions/split/read/getAllRecipientsAddresses.d.ts +14 -0
- package/dist/types/extensions/split/read/getAllRecipientsAddresses.d.ts.map +1 -0
- package/dist/types/extensions/split/read/getAllRecipientsPercentages.d.ts +27 -0
- package/dist/types/extensions/split/read/getAllRecipientsPercentages.d.ts.map +1 -0
- package/dist/types/extensions/split/read/getRecipientSplitPercentage.d.ts +21 -0
- package/dist/types/extensions/split/read/getRecipientSplitPercentage.d.ts.map +1 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cli/bin.ts +0 -18
- package/src/exports/deploys.ts +5 -0
- package/src/exports/extensions/split.ts +8 -0
- package/src/extensions/prebuilts/__generated__/Split/write/initialize.ts +191 -0
- package/src/extensions/prebuilts/deploy-split.test.ts +31 -0
- package/src/extensions/prebuilts/deploy-split.ts +144 -0
- package/src/extensions/split/__generated__/Split/read/totalShares.ts +72 -0
- package/src/extensions/split/read/getAllRecipientsAddresses.test.ts +39 -0
- package/src/extensions/split/read/getAllRecipientsAddresses.ts +26 -0
- package/src/extensions/split/read/getAllRecipientsPercentages.test.ts +48 -0
- package/src/extensions/split/read/getAllRecipientsPercentages.ts +41 -0
- package/src/extensions/split/read/getRecipientSplitPercentage.test.ts +45 -0
- package/src/extensions/split/read/getRecipientSplitPercentage.ts +40 -0
- package/src/version.ts +1 -1
@@ -0,0 +1,46 @@
|
|
1
|
+
import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
|
2
|
+
import type { Hex } from "../../../../../utils/encoding/hex.js";
|
3
|
+
import type { ThirdwebContract } from "../../../../../contract/contract.js";
|
4
|
+
export declare const FN_SELECTOR: "0x3a98ef39";
|
5
|
+
/**
|
6
|
+
* Checks if the `totalShares` method is supported by the given contract.
|
7
|
+
* @param contract The ThirdwebContract.
|
8
|
+
* @returns A promise that resolves to a boolean indicating if the `totalShares` method is supported.
|
9
|
+
* @extension SPLIT
|
10
|
+
* @example
|
11
|
+
* ```ts
|
12
|
+
* import { isTotalSharesSupported } from "thirdweb/extensions/split";
|
13
|
+
*
|
14
|
+
* const supported = await isTotalSharesSupported(contract);
|
15
|
+
* ```
|
16
|
+
*/
|
17
|
+
export declare function isTotalSharesSupported(contract: ThirdwebContract<any>): Promise<boolean>;
|
18
|
+
/**
|
19
|
+
* Decodes the result of the totalShares function call.
|
20
|
+
* @param result - The hexadecimal result to decode.
|
21
|
+
* @returns The decoded result as per the FN_OUTPUTS definition.
|
22
|
+
* @extension SPLIT
|
23
|
+
* @example
|
24
|
+
* ```ts
|
25
|
+
* import { decodeTotalSharesResult } from "thirdweb/extensions/split";
|
26
|
+
* const result = decodeTotalSharesResult("...");
|
27
|
+
* ```
|
28
|
+
*/
|
29
|
+
export declare function decodeTotalSharesResult(result: Hex): bigint;
|
30
|
+
/**
|
31
|
+
* Calls the "totalShares" function on the contract.
|
32
|
+
* @param options - The options for the totalShares function.
|
33
|
+
* @returns The parsed result of the function call.
|
34
|
+
* @extension SPLIT
|
35
|
+
* @example
|
36
|
+
* ```ts
|
37
|
+
* import { totalShares } from "thirdweb/extensions/split";
|
38
|
+
*
|
39
|
+
* const result = await totalShares({
|
40
|
+
* contract,
|
41
|
+
* });
|
42
|
+
*
|
43
|
+
* ```
|
44
|
+
*/
|
45
|
+
export declare function totalShares(options: BaseTransactionOptions): Promise<bigint>;
|
46
|
+
//# sourceMappingURL=totalShares.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"totalShares.d.ts","sourceRoot":"","sources":["../../../../../../../src/extensions/split/__generated__/Split/read/totalShares.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAGlF,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,sCAAsC,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAG5E,eAAO,MAAM,WAAW,cAAwB,CAAC;AAQjD;;;;;;;;;;;GAWG;AACH,wBAAsB,sBAAsB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,GAAG,CAAC,oBAK3E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,GAAG,UAElD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,sBAAsB,mBAMhE"}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import type { BaseTransactionOptions } from "../../../transaction/types.js";
|
2
|
+
/**
|
3
|
+
* Get the addresses of all recipients of a [`thirdweb Split contract`](https://thirdweb.com/thirdweb.eth/Split)
|
4
|
+
* @extension SPLIT
|
5
|
+
* @returns an array of wallet addresses
|
6
|
+
*
|
7
|
+
* @example
|
8
|
+
* ```ts
|
9
|
+
* import { getAllRecipientsAddresses } from "thirdweb/extensions/split";
|
10
|
+
*
|
11
|
+
* const addresses = await getAllRecipientsAddresses({ contract });
|
12
|
+
*/
|
13
|
+
export declare function getAllRecipientsAddresses(options: BaseTransactionOptions): Promise<string[]>;
|
14
|
+
//# sourceMappingURL=getAllRecipientsAddresses.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"getAllRecipientsAddresses.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/split/read/getAllRecipientsAddresses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAI5E;;;;;;;;;;GAUG;AACH,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,MAAM,EAAE,CAAC,CAQnB"}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import type { BaseTransactionOptions } from "../../../transaction/types.js";
|
2
|
+
import { type SplitRecipient } from "./getRecipientSplitPercentage.js";
|
3
|
+
/**
|
4
|
+
* Get all the recipients of a Split contracts
|
5
|
+
* @extension SPLIT
|
6
|
+
* @returns an array of recipients' addresses and split percentage of each
|
7
|
+
*
|
8
|
+
* @example
|
9
|
+
* ```ts
|
10
|
+
* import { getAllRecipientsPercentages } from "thirdweb/extensions/split";
|
11
|
+
*
|
12
|
+
* const allRecipients = await getAllRecipientsPercentages({ contract });
|
13
|
+
* // Example result:
|
14
|
+
* [
|
15
|
+
* {
|
16
|
+
* address: "0x1...",
|
17
|
+
* splitPercentage: 25, // 25%
|
18
|
+
* },
|
19
|
+
* {
|
20
|
+
* address: "0x2...",
|
21
|
+
* splitPercentage: 75, // 75%
|
22
|
+
* },
|
23
|
+
* ];
|
24
|
+
* ```
|
25
|
+
*/
|
26
|
+
export declare function getAllRecipientsPercentages(options: BaseTransactionOptions): Promise<SplitRecipient[]>;
|
27
|
+
//# sourceMappingURL=getAllRecipientsPercentages.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"getAllRecipientsPercentages.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/split/read/getAllRecipientsPercentages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAE5E,OAAO,EACL,KAAK,cAAc,EAEpB,MAAM,kCAAkC,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,cAAc,EAAE,CAAC,CAQ3B"}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import type { BaseTransactionOptions } from "../../../transaction/types.js";
|
2
|
+
/**
|
3
|
+
* @extension SPLIT
|
4
|
+
*/
|
5
|
+
export interface SplitRecipient {
|
6
|
+
/**
|
7
|
+
* The address of the recipient
|
8
|
+
*/
|
9
|
+
address: string;
|
10
|
+
/**
|
11
|
+
* The split of the recipient as a percentage of the total amount
|
12
|
+
*
|
13
|
+
* I.e. If a recipient has a split of 50%, and the asset sells for 100 ETH,
|
14
|
+
* the recipient will receive 50 ETH.
|
15
|
+
*/
|
16
|
+
splitPercentage: number;
|
17
|
+
}
|
18
|
+
export declare function getRecipientSplitPercentage(options: BaseTransactionOptions<{
|
19
|
+
recipientAddress: string;
|
20
|
+
}>): Promise<SplitRecipient>;
|
21
|
+
//# sourceMappingURL=getRecipientSplitPercentage.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"getRecipientSplitPercentage.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/split/read/getRecipientSplitPercentage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAI5E;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;;OAKG;IACH,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,sBAAsB,CAAC;IAAE,gBAAgB,EAAE,MAAM,CAAA;CAAE,CAAC,GAC5D,OAAO,CAAC,cAAc,CAAC,CAezB"}
|
package/dist/types/version.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export declare const version = "5.45.
|
1
|
+
export declare const version = "5.45.2-nightly-141fd53759f1b5515e38688fe96364edc4c76644-20240812000351";
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,2EAA2E,CAAC"}
|
package/package.json
CHANGED
package/src/cli/bin.ts
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
-
|
3
|
-
import { execSync } from "node:child_process";
|
4
2
|
import { spawn } from "cross-spawn";
|
5
3
|
import {
|
6
4
|
generate,
|
@@ -44,25 +42,9 @@ async function main() {
|
|
44
42
|
|
45
43
|
const isWindows = /^win/.test(process.platform);
|
46
44
|
|
47
|
-
const isBunAvailable = (() => {
|
48
|
-
try {
|
49
|
-
const res = execSync("bun --version", {
|
50
|
-
// stdio: "ignore",
|
51
|
-
encoding: "utf-8",
|
52
|
-
});
|
53
|
-
if (typeof res === "string" && res.indexOf(".") > -1) {
|
54
|
-
return true;
|
55
|
-
}
|
56
|
-
} catch {}
|
57
|
-
return false;
|
58
|
-
})();
|
59
|
-
|
60
45
|
let runner = "npx";
|
61
46
|
|
62
47
|
switch (true) {
|
63
|
-
case isBunAvailable:
|
64
|
-
runner = "bunx";
|
65
|
-
break;
|
66
48
|
case isWindows:
|
67
49
|
runner = "npx.cmd";
|
68
50
|
break;
|
package/src/exports/deploys.ts
CHANGED
@@ -33,3 +33,8 @@ export {
|
|
33
33
|
type PrepareDirectDeployTransactionOptions,
|
34
34
|
} from "../contract/deployment/deploy-with-abi.js";
|
35
35
|
export { computePublishedContractAddress } from "../utils/any-evm/compute-published-contract-address.js";
|
36
|
+
export {
|
37
|
+
deploySplitContract,
|
38
|
+
type SplitContractParams,
|
39
|
+
type DeploySplitContractOptions,
|
40
|
+
} from "../extensions/prebuilts/deploy-split.js";
|
@@ -34,6 +34,14 @@ export { totalReleased } from "../../extensions/split/__generated__/Split/read/t
|
|
34
34
|
|
35
35
|
export { totalReleasedByToken } from "../../extensions/split/read/totalReleasedByToken.js";
|
36
36
|
|
37
|
+
export { getAllRecipientsAddresses } from "../../extensions/split/read/getAllRecipientsAddresses.js";
|
38
|
+
|
39
|
+
export { getAllRecipientsPercentages } from "../../extensions/split/read/getAllRecipientsPercentages.js";
|
40
|
+
|
41
|
+
export {
|
42
|
+
getRecipientSplitPercentage,
|
43
|
+
type SplitRecipient,
|
44
|
+
} from "../../extensions/split/read/getRecipientSplitPercentage.js";
|
37
45
|
/**
|
38
46
|
* WRITE
|
39
47
|
*/
|
@@ -0,0 +1,191 @@
|
|
1
|
+
import type { AbiParameterToPrimitiveType } from "abitype";
|
2
|
+
import type {
|
3
|
+
BaseTransactionOptions,
|
4
|
+
WithOverrides,
|
5
|
+
} from "../../../../../transaction/types.js";
|
6
|
+
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
|
7
|
+
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
|
8
|
+
import { once } from "../../../../../utils/promise/once.js";
|
9
|
+
import type { ThirdwebContract } from "../../../../../contract/contract.js";
|
10
|
+
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Represents the parameters for the "initialize" function.
|
14
|
+
*/
|
15
|
+
export type InitializeParams = WithOverrides<{
|
16
|
+
defaultAdmin: AbiParameterToPrimitiveType<{
|
17
|
+
type: "address";
|
18
|
+
name: "_defaultAdmin";
|
19
|
+
}>;
|
20
|
+
contractURI: AbiParameterToPrimitiveType<{
|
21
|
+
type: "string";
|
22
|
+
name: "_contractURI";
|
23
|
+
}>;
|
24
|
+
trustedForwarders: AbiParameterToPrimitiveType<{
|
25
|
+
type: "address[]";
|
26
|
+
name: "_trustedForwarders";
|
27
|
+
}>;
|
28
|
+
payees: AbiParameterToPrimitiveType<{ type: "address[]"; name: "_payees" }>;
|
29
|
+
shares: AbiParameterToPrimitiveType<{ type: "uint256[]"; name: "_shares" }>;
|
30
|
+
}>;
|
31
|
+
|
32
|
+
export const FN_SELECTOR = "0xb1a14437" as const;
|
33
|
+
const FN_INPUTS = [
|
34
|
+
{
|
35
|
+
type: "address",
|
36
|
+
name: "_defaultAdmin",
|
37
|
+
},
|
38
|
+
{
|
39
|
+
type: "string",
|
40
|
+
name: "_contractURI",
|
41
|
+
},
|
42
|
+
{
|
43
|
+
type: "address[]",
|
44
|
+
name: "_trustedForwarders",
|
45
|
+
},
|
46
|
+
{
|
47
|
+
type: "address[]",
|
48
|
+
name: "_payees",
|
49
|
+
},
|
50
|
+
{
|
51
|
+
type: "uint256[]",
|
52
|
+
name: "_shares",
|
53
|
+
},
|
54
|
+
] as const;
|
55
|
+
const FN_OUTPUTS = [] as const;
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Checks if the `initialize` method is supported by the given contract.
|
59
|
+
* @param contract The ThirdwebContract.
|
60
|
+
* @returns A promise that resolves to a boolean indicating if the `initialize` method is supported.
|
61
|
+
* @extension PREBUILTS
|
62
|
+
* @example
|
63
|
+
* ```ts
|
64
|
+
* import { isInitializeSupported } from "thirdweb/extensions/prebuilts";
|
65
|
+
*
|
66
|
+
* const supported = await isInitializeSupported(contract);
|
67
|
+
* ```
|
68
|
+
*/
|
69
|
+
export async function isInitializeSupported(contract: ThirdwebContract<any>) {
|
70
|
+
return detectMethod({
|
71
|
+
contract,
|
72
|
+
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
|
73
|
+
});
|
74
|
+
}
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Encodes the parameters for the "initialize" function.
|
78
|
+
* @param options - The options for the initialize function.
|
79
|
+
* @returns The encoded ABI parameters.
|
80
|
+
* @extension PREBUILTS
|
81
|
+
* @example
|
82
|
+
* ```ts
|
83
|
+
* import { encodeInitializeParams } "thirdweb/extensions/prebuilts";
|
84
|
+
* const result = encodeInitializeParams({
|
85
|
+
* defaultAdmin: ...,
|
86
|
+
* contractURI: ...,
|
87
|
+
* trustedForwarders: ...,
|
88
|
+
* payees: ...,
|
89
|
+
* shares: ...,
|
90
|
+
* });
|
91
|
+
* ```
|
92
|
+
*/
|
93
|
+
export function encodeInitializeParams(options: InitializeParams) {
|
94
|
+
return encodeAbiParameters(FN_INPUTS, [
|
95
|
+
options.defaultAdmin,
|
96
|
+
options.contractURI,
|
97
|
+
options.trustedForwarders,
|
98
|
+
options.payees,
|
99
|
+
options.shares,
|
100
|
+
]);
|
101
|
+
}
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Encodes the "initialize" function into a Hex string with its parameters.
|
105
|
+
* @param options - The options for the initialize function.
|
106
|
+
* @returns The encoded hexadecimal string.
|
107
|
+
* @extension PREBUILTS
|
108
|
+
* @example
|
109
|
+
* ```ts
|
110
|
+
* import { encodeInitialize } "thirdweb/extensions/prebuilts";
|
111
|
+
* const result = encodeInitialize({
|
112
|
+
* defaultAdmin: ...,
|
113
|
+
* contractURI: ...,
|
114
|
+
* trustedForwarders: ...,
|
115
|
+
* payees: ...,
|
116
|
+
* shares: ...,
|
117
|
+
* });
|
118
|
+
* ```
|
119
|
+
*/
|
120
|
+
export function encodeInitialize(options: InitializeParams) {
|
121
|
+
// we do a "manual" concat here to avoid the overhead of the "concatHex" function
|
122
|
+
// we can do this because we know the specific formats of the values
|
123
|
+
return (FN_SELECTOR +
|
124
|
+
encodeInitializeParams(options).slice(
|
125
|
+
2,
|
126
|
+
)) as `${typeof FN_SELECTOR}${string}`;
|
127
|
+
}
|
128
|
+
|
129
|
+
/**
|
130
|
+
* Prepares a transaction to call the "initialize" function on the contract.
|
131
|
+
* @param options - The options for the "initialize" function.
|
132
|
+
* @returns A prepared transaction object.
|
133
|
+
* @extension PREBUILTS
|
134
|
+
* @example
|
135
|
+
* ```ts
|
136
|
+
* import { initialize } from "thirdweb/extensions/prebuilts";
|
137
|
+
*
|
138
|
+
* const transaction = initialize({
|
139
|
+
* contract,
|
140
|
+
* defaultAdmin: ...,
|
141
|
+
* contractURI: ...,
|
142
|
+
* trustedForwarders: ...,
|
143
|
+
* payees: ...,
|
144
|
+
* shares: ...,
|
145
|
+
* overrides: {
|
146
|
+
* ...
|
147
|
+
* }
|
148
|
+
* });
|
149
|
+
*
|
150
|
+
* // Send the transaction
|
151
|
+
* ...
|
152
|
+
*
|
153
|
+
* ```
|
154
|
+
*/
|
155
|
+
export function initialize(
|
156
|
+
options: BaseTransactionOptions<
|
157
|
+
| InitializeParams
|
158
|
+
| {
|
159
|
+
asyncParams: () => Promise<InitializeParams>;
|
160
|
+
}
|
161
|
+
>,
|
162
|
+
) {
|
163
|
+
const asyncOptions = once(async () => {
|
164
|
+
return "asyncParams" in options ? await options.asyncParams() : options;
|
165
|
+
});
|
166
|
+
|
167
|
+
return prepareContractCall({
|
168
|
+
contract: options.contract,
|
169
|
+
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
|
170
|
+
params: async () => {
|
171
|
+
const resolvedOptions = await asyncOptions();
|
172
|
+
return [
|
173
|
+
resolvedOptions.defaultAdmin,
|
174
|
+
resolvedOptions.contractURI,
|
175
|
+
resolvedOptions.trustedForwarders,
|
176
|
+
resolvedOptions.payees,
|
177
|
+
resolvedOptions.shares,
|
178
|
+
] as const;
|
179
|
+
},
|
180
|
+
value: async () => (await asyncOptions()).overrides?.value,
|
181
|
+
accessList: async () => (await asyncOptions()).overrides?.accessList,
|
182
|
+
gas: async () => (await asyncOptions()).overrides?.gas,
|
183
|
+
gasPrice: async () => (await asyncOptions()).overrides?.gasPrice,
|
184
|
+
maxFeePerGas: async () => (await asyncOptions()).overrides?.maxFeePerGas,
|
185
|
+
maxPriorityFeePerGas: async () =>
|
186
|
+
(await asyncOptions()).overrides?.maxPriorityFeePerGas,
|
187
|
+
nonce: async () => (await asyncOptions()).overrides?.nonce,
|
188
|
+
extraGas: async () => (await asyncOptions()).overrides?.extraGas,
|
189
|
+
erc20Value: async () => (await asyncOptions()).overrides?.erc20Value,
|
190
|
+
});
|
191
|
+
}
|
@@ -0,0 +1,31 @@
|
|
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 { isAddress } from "../../utils/address.js";
|
6
|
+
import { deploySplitContract } from "./deploy-split.js";
|
7
|
+
|
8
|
+
describe("deploy-split contract", () => {
|
9
|
+
it("should deploy Split contract", async () => {
|
10
|
+
const address = await deploySplitContract({
|
11
|
+
account: TEST_ACCOUNT_A,
|
12
|
+
client: TEST_CLIENT,
|
13
|
+
chain: ANVIL_CHAIN,
|
14
|
+
params: {
|
15
|
+
name: "split-contract",
|
16
|
+
payees: [
|
17
|
+
"0x12345674b599ce99958242b3D3741e7b01841DF3",
|
18
|
+
"0xA6f11e47dE28B3dB934e945daeb6F538E9019694",
|
19
|
+
],
|
20
|
+
shares: [
|
21
|
+
5100n, // 51%
|
22
|
+
4900n, // 49%
|
23
|
+
],
|
24
|
+
},
|
25
|
+
});
|
26
|
+
expect(address).toBeDefined();
|
27
|
+
expect(isAddress(address)).toBe(true);
|
28
|
+
// Further tests to verify the functionality of this contract
|
29
|
+
// are done in other Split tests
|
30
|
+
});
|
31
|
+
});
|
@@ -0,0 +1,144 @@
|
|
1
|
+
import type { ThirdwebClient } from "../../client/client.js";
|
2
|
+
import type { ThirdwebContract } from "../../contract/contract.js";
|
3
|
+
import { deployViaAutoFactory } from "../../contract/deployment/deploy-via-autofactory.js";
|
4
|
+
import { getOrDeployInfraForPublishedContract } from "../../contract/deployment/utils/bootstrap.js";
|
5
|
+
import { upload } from "../../storage/upload.js";
|
6
|
+
import type { FileOrBufferOrString } from "../../storage/upload/types.js";
|
7
|
+
import type { Prettify } from "../../utils/type-utils.js";
|
8
|
+
import type { ClientAndChainAndAccount } from "../../utils/types.js";
|
9
|
+
import { initialize } from "./__generated__/Split/write/initialize.js";
|
10
|
+
|
11
|
+
/**
|
12
|
+
* @extension PREBUILT
|
13
|
+
*/
|
14
|
+
export type SplitContractParams = {
|
15
|
+
name: string;
|
16
|
+
|
17
|
+
/**
|
18
|
+
* An array of strings containing wallet addresses of the recipients
|
19
|
+
* For example:
|
20
|
+
* ```ts
|
21
|
+
* ["0x...123", "0x...456"]
|
22
|
+
* ```
|
23
|
+
*/
|
24
|
+
payees: string[];
|
25
|
+
/**
|
26
|
+
* An array of bigints containing the shared percentages of each respective payees.
|
27
|
+
* Must have the same length as `payees`
|
28
|
+
* @example
|
29
|
+
* ```ts
|
30
|
+
* [
|
31
|
+
* 5100n, // 51%
|
32
|
+
* 4900n, // 49%
|
33
|
+
* ]
|
34
|
+
* ```
|
35
|
+
*/
|
36
|
+
shares: bigint[];
|
37
|
+
description?: string;
|
38
|
+
image?: FileOrBufferOrString;
|
39
|
+
external_link?: string;
|
40
|
+
social_urls?: Record<string, string>;
|
41
|
+
symbol?: string;
|
42
|
+
contractURI?: string;
|
43
|
+
defaultAdmin?: string;
|
44
|
+
trustedForwarders?: string[];
|
45
|
+
};
|
46
|
+
|
47
|
+
/**
|
48
|
+
* @extension DEPLOY
|
49
|
+
*/
|
50
|
+
export type DeploySplitContractOptions = Prettify<
|
51
|
+
ClientAndChainAndAccount & {
|
52
|
+
params: SplitContractParams;
|
53
|
+
}
|
54
|
+
>;
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Deploys a thirdweb [`Split contract`](https://thirdweb.com/thirdweb.eth/Split)
|
58
|
+
* On chains where the thirdweb infrastructure contracts are not deployed, this function will deploy them as well.
|
59
|
+
* @param options - The deployment options.
|
60
|
+
* @returns The deployed contract address.
|
61
|
+
* @extension DEPLOY
|
62
|
+
*
|
63
|
+
* @example
|
64
|
+
* ```ts
|
65
|
+
* import { deploySplitContract } from "thirdweb/deploys";
|
66
|
+
* const contractAddress = await deploySplitContract({
|
67
|
+
* chain,
|
68
|
+
* client,
|
69
|
+
* account,
|
70
|
+
* params: {
|
71
|
+
* name: "Split contract",
|
72
|
+
* payees: ["0x...123", "0x...456"],
|
73
|
+
* shares: [5100, 4900], // See type `SplitContractParams` for more context
|
74
|
+
* });
|
75
|
+
* ```
|
76
|
+
*/
|
77
|
+
export async function deploySplitContract(options: DeploySplitContractOptions) {
|
78
|
+
const { chain, client, account, params } = options;
|
79
|
+
const { cloneFactoryContract, implementationContract } =
|
80
|
+
await getOrDeployInfraForPublishedContract({
|
81
|
+
chain,
|
82
|
+
client,
|
83
|
+
account,
|
84
|
+
contractId: "Split",
|
85
|
+
constructorParams: [],
|
86
|
+
});
|
87
|
+
const initializeTransaction = await getInitializeTransaction({
|
88
|
+
client,
|
89
|
+
implementationContract,
|
90
|
+
params,
|
91
|
+
accountAddress: account.address,
|
92
|
+
});
|
93
|
+
|
94
|
+
return deployViaAutoFactory({
|
95
|
+
client,
|
96
|
+
chain,
|
97
|
+
account,
|
98
|
+
cloneFactoryContract,
|
99
|
+
initializeTransaction,
|
100
|
+
});
|
101
|
+
}
|
102
|
+
|
103
|
+
async function getInitializeTransaction(options: {
|
104
|
+
client: ThirdwebClient;
|
105
|
+
implementationContract: ThirdwebContract;
|
106
|
+
params: SplitContractParams;
|
107
|
+
accountAddress: string;
|
108
|
+
}) {
|
109
|
+
const { client, implementationContract, params, accountAddress } = options;
|
110
|
+
const {
|
111
|
+
name,
|
112
|
+
description,
|
113
|
+
symbol,
|
114
|
+
image,
|
115
|
+
external_link,
|
116
|
+
social_urls,
|
117
|
+
payees,
|
118
|
+
shares,
|
119
|
+
} = params;
|
120
|
+
const contractURI =
|
121
|
+
params.contractURI ||
|
122
|
+
(await upload({
|
123
|
+
client,
|
124
|
+
files: [
|
125
|
+
{
|
126
|
+
name,
|
127
|
+
description,
|
128
|
+
symbol,
|
129
|
+
image,
|
130
|
+
external_link,
|
131
|
+
social_urls,
|
132
|
+
},
|
133
|
+
],
|
134
|
+
})) ||
|
135
|
+
"";
|
136
|
+
return initialize({
|
137
|
+
contract: implementationContract,
|
138
|
+
defaultAdmin: params.defaultAdmin || accountAddress,
|
139
|
+
contractURI,
|
140
|
+
trustedForwarders: params.trustedForwarders || [],
|
141
|
+
payees,
|
142
|
+
shares,
|
143
|
+
});
|
144
|
+
}
|
@@ -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("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
|
+
});
|