Skip to content

Commit 44d8d8b

Browse files
committed
default values for infra
1 parent ecca655 commit 44d8d8b

File tree

3 files changed

+65
-4
lines changed

3 files changed

+65
-4
lines changed

packages/thirdweb/src/contract/deployment/utils/bootstrap.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ import {
2121
getDeployedInfraContractFromMetadata,
2222
prepareInfraContractDeployTransactionFromMetadata,
2323
} from "./infra.js";
24-
import { getDeployedMintFeeManagerContract } from "./mintfee-manager.js";
24+
import { getDeployedMintFeeManagerContract, getDeployedMultisigContract } from "./mintfee-manager.js";
25+
26+
export interface ReplacementValues {
27+
mintFeeManager?: string;
28+
multisig?: string;
29+
}
2530

2631
/**
2732
* @internal
@@ -86,11 +91,15 @@ export async function getOrDeployInfraForPublishedContract(
8691
};
8792
}
8893

89-
let [cloneFactoryContract, mintfeeManagerContract, implementationContract] = await Promise.all([
94+
let [cloneFactoryContract, mintfeeManagerContract, multisig, implementationContract] = await Promise.all([
9095
getDeployedCloneFactoryContract({
9196
chain,
9297
client,
9398
}),
99+
getDeployedMultisigContract({
100+
chain,
101+
client,
102+
}),
94103
getDeployedMintFeeManagerContract({
95104
chain,
96105
client,
@@ -105,13 +114,18 @@ export async function getOrDeployInfraForPublishedContract(
105114
}),
106115
]);
107116

108-
if (!implementationContract || !cloneFactoryContract || !mintfeeManagerContract) {
117+
if (!implementationContract || !cloneFactoryContract || !multisig || !mintfeeManagerContract) {
109118
// deploy the infra and implementation contracts if not found
110119
cloneFactoryContract = await deployCloneFactory({
111120
client,
112121
chain,
113122
account,
114123
});
124+
multisig = await deployMultisig({
125+
client,
126+
chain,
127+
account,
128+
});
115129
mintfeeManagerContract = await deployMintFeeManager({
116130
client,
117131
chain,
@@ -125,6 +139,10 @@ export async function getOrDeployInfraForPublishedContract(
125139
constructorParams,
126140
publisher,
127141
version,
142+
replacementValues: {
143+
mintFeeManager: mintfeeManagerContract.address,
144+
multisig: multisig.address
145+
}
128146
});
129147
}
130148
return { cloneFactoryContract, mintfeeManagerContract, implementationContract };
@@ -212,6 +230,7 @@ export async function deployImplementation(
212230
constructorParams?: Record<string, unknown>;
213231
publisher?: string;
214232
version?: string;
233+
replacementValues?: ReplacementValues
215234
},
216235
) {
217236
return getOrDeployInfraContract({
@@ -220,6 +239,7 @@ export async function deployImplementation(
220239
constructorParams: options.constructorParams,
221240
publisher: options.publisher,
222241
version: options.version,
242+
replacementValues: options.replacementValues
223243
});
224244
}
225245

@@ -233,6 +253,7 @@ export async function getOrDeployInfraContract(
233253
constructorParams?: Record<string, unknown>;
234254
publisher?: string;
235255
version?: string;
256+
replacementValues?: ReplacementValues
236257
},
237258
) {
238259
const contractMetadata = await fetchPublishedContractMetadata({
@@ -254,6 +275,7 @@ export async function getOrDeployInfraContractFromMetadata(
254275
options: ClientAndChainAndAccount & {
255276
contractMetadata: FetchDeployMetadataResult;
256277
constructorParams?: Record<string, unknown>;
278+
replacementValues?: ReplacementValues
257279
},
258280
) {
259281
const infraContract = await getDeployedInfraContractFromMetadata(options);

packages/thirdweb/src/contract/deployment/utils/infra.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { Prettify } from "../../../utils/type-utils.js";
99
import type { ClientAndChain } from "../../../utils/types.js";
1010
import { type ThirdwebContract, getContract } from "../../contract.js";
1111
import { fetchPublishedContractMetadata } from "../publisher.js";
12+
import type { ReplacementValues } from "./bootstrap.js";
1213
import { computeCreate2FactoryAddress } from "./create-2-factory.js";
1314

1415
export type InfraContractId =
@@ -99,8 +100,26 @@ export function prepareInfraContractDeployTransactionFromMetadata(options: {
99100
contractMetadata: FetchDeployMetadataResult;
100101
constructorParams?: Record<string, unknown>;
101102
salt?: string;
103+
replacementValues?: ReplacementValues
102104
}) {
103105
const { client, chain } = options;
106+
let params: Record<string, unknown>;
107+
if(options.contractMetadata.constructorParams) {
108+
if(!options.constructorParams) {
109+
Object.keys(options.contractMetadata.constructorParams).forEach(async (key, index) => {
110+
const param = options.contractMetadata.constructorParams![key];
111+
112+
if (param?.defaultValue === "{{tw-mintfee-mmanager}}") {
113+
params[index] = options.replacementValues?.mintFeeManager || "";
114+
} else if (param?.defaultValue === "{{tw-multisig}}") {
115+
params[index] = options.replacementValues?.multisig || "";
116+
} else {
117+
params[index] = "";
118+
}
119+
});
120+
}
121+
}
122+
104123
return prepareTransaction({
105124
client,
106125
chain,
@@ -111,7 +130,10 @@ export function prepareInfraContractDeployTransactionFromMetadata(options: {
111130
}),
112131
data: async () => {
113132
const infraContractInfo =
114-
await computeDeploymentInfoFromMetadata(options);
133+
await computeDeploymentInfoFromMetadata({
134+
...options,
135+
constructorParams: params
136+
});
115137
return infraContractInfo.initBytecodeWithsalt;
116138
},
117139
});

packages/thirdweb/src/contract/deployment/utils/mintfee-manager.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ export async function getDeployedMintFeeManagerContract(args: ClientAndChain) {
3030
return mintfeeManager;
3131
}
3232

33+
/**
34+
* @internal
35+
*/
36+
export async function getDeployedMultisigContract(args: ClientAndChain) {
37+
const multisig = await getDeployedInfraContract({
38+
...args,
39+
contractId: "MultiSig",
40+
constructorParams: { _signers: [TW_SIGNER_1, TW_SIGNER_2, TW_SIGNER_3], _requiredApprovals: MULTISIG_REQUIRED_APPROVALS },
41+
publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936", // TODO: remove before merging
42+
});
43+
if (!multisig) {
44+
return null;
45+
}
46+
47+
return multisig;
48+
}
49+
3350
/**
3451
* @internal
3552
*/

0 commit comments

Comments
 (0)