Skip to content

Commit

Permalink
misc: Deployments fixed after changes
Browse files Browse the repository at this point in the history
Co-authored-by: Victor Naumik <[email protected]>
  • Loading branch information
donosonaumczuk and vicnaum committed Jan 5, 2025
1 parent 5924257 commit 26d8b89
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 112 deletions.
60 changes: 30 additions & 30 deletions deploy/deployAux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ export async function deployLensPrimitives() {

async function deployLensAccount(lensFactory: ethers.Contract): Promise<string> {
const contractName = 'Account';
const existingContract = loadContractFromAddressBook(contractName);
const name = 'LensExampleAccount';
const existingContract = loadContractFromAddressBook(name);
if (existingContract && existingContract.address) {
console.log(`${contractName} already deployed at ${existingContract.address}. Skipping...`);
return existingContract.address;
}

console.log('Deploying Account');
console.log('Deploying ' + name);
const transaction = await lensFactory.deployAccount(
metadataURI,
getWallet().address,
Expand All @@ -88,29 +89,30 @@ async function deployLensAccount(lensFactory: ethers.Contract): Promise<string>

const txReceipt = (await transaction.wait()) as ethers.TransactionReceipt;
const events = parseLensContractDeployedEventsFromReceipt(txReceipt);
const accountAddress = getAddressFromEvents(events, 'account');
const accountAddress = getAddressFromEvents(events, contractName.toLowerCase());

await verifyPrimitive('Account', accountAddress, [
getWallet().address,
metadataURI,
[],
[],
emptySourceStamp,
[]
]);
// await verifyPrimitive('Account', accountAddress, [
// getWallet().address,
// metadataURI,
// [],
// [],
// emptySourceStamp,
// []
// ]);

saveContractToAddressBook({
contractName: 'Account',
name: name,
contractName: contractName,
contractType: ContractType.Misc,
address: accountAddress
address: accountAddress,
});

return accountAddress;
}

async function deployLensFeed(lensFactory: ethers.Contract): Promise<string> {
const contractName = 'Feed';
const name = "LensGlobal" + contractName;
const name = 'LensGlobal' + contractName;
const existingContract = loadContractFromAddressBook(name);
if (existingContract && existingContract.address) {
console.log(`${name} already deployed at ${existingContract.address}. Skipping...`);
Expand All @@ -131,15 +133,15 @@ async function deployLensFeed(lensFactory: ethers.Contract): Promise<string> {
name: name,
contractName: contractName,
contractType: ContractType.Primitive,
address: primitiveAddress
address: primitiveAddress,
});

return primitiveAddress;
}

async function deployLensGroup(lensFactory: ethers.Contract): Promise<string> {
const contractName = 'Group';
const name = "LensGlobal" + contractName;
const name = 'LensGlobal' + contractName;
const existingContract = loadContractFromAddressBook(name);
if (existingContract && existingContract.address) {
console.log(`${name} already deployed at ${existingContract.address}. Skipping...`);
Expand All @@ -160,15 +162,15 @@ async function deployLensGroup(lensFactory: ethers.Contract): Promise<string> {
name: name,
contractName: contractName,
contractType: ContractType.Primitive,
address: primitiveAddress
address: primitiveAddress,
});

return primitiveAddress;
}

async function deployLensGraph(lensFactory: ethers.Contract): Promise<string> {
const contractName = 'Graph';
const name = "LensGlobal" + contractName;
const name = 'LensGlobal' + contractName;
const existingContract = loadContractFromAddressBook(name);
if (existingContract && existingContract.address) {
console.log(`${name} already deployed at ${existingContract.address}. Skipping...`);
Expand All @@ -189,7 +191,7 @@ async function deployLensGraph(lensFactory: ethers.Contract): Promise<string> {
name: name,
contractName: contractName,
contractType: ContractType.Primitive,
address: primitiveAddress
address: primitiveAddress,
});

return primitiveAddress;
Expand All @@ -200,7 +202,7 @@ export async function deployLensNamespace(
noVerify: Boolean = false
): Promise<string> {
const contractName = 'Namespace';
const name = "LensGlobal" + contractName;
const name = 'LensGlobal' + contractName;
const existingContract = loadContractFromAddressBook(name);
if (existingContract && existingContract.address) {
console.log(`${name} already deployed at ${existingContract.address}. Skipping...`);
Expand Down Expand Up @@ -245,7 +247,7 @@ export async function deployLensNamespace(
name: name,
contractName: contractName,
contractType: ContractType.Primitive,
address: primitiveAddress
address: primitiveAddress,
});

return primitiveAddress;
Expand All @@ -256,7 +258,7 @@ export async function deployLensApp(
initialProperties: AppInitialProperties
): Promise<string> {
const contractName = 'App';
const name = "LensGlobal" + contractName;
const name = 'LensGlobal' + contractName;
const existingContract = loadContractFromAddressBook(name);
if (existingContract && existingContract.address) {
console.log(`${name} already deployed at ${existingContract.address}. Skipping...`);
Expand Down Expand Up @@ -293,7 +295,7 @@ export async function deployLensApp(
name: name,
contractName: contractName,
contractType: ContractType.Primitive,
address: primitiveAddress
address: primitiveAddress,
});

return primitiveAddress;
Expand Down Expand Up @@ -323,7 +325,8 @@ export async function deployLensAccessControl() {
);

const transaction = await accessControlFactory.deployOwnerAdminOnlyAccessControl(
getWallet().address, []
getWallet().address,
[]
);

const txReceipt = (await transaction.wait()) as ethers.TransactionReceipt;
Expand All @@ -335,7 +338,7 @@ export async function deployLensAccessControl() {
saveContractToAddressBook({
contractName: 'OwnerAdminOnlyAccessControl',
contractType: ContractType.Aux,
address: accessControlAddress
address: accessControlAddress,
});

return accessControlAddress;
Expand All @@ -354,17 +357,14 @@ export async function deployLensActionHub(): Promise<string> {
const actionHub_artifactName = 'ActionHub';
const actionHub_args: any[] = [];

const actionHub = await deployContract(
actionHub_artifactName,
actionHub_args
);
const actionHub = await deployContract(actionHub_artifactName, actionHub_args);

const actionHubAddress = await actionHub.getAddress();

saveContractToAddressBook({
contractName: 'ActionHub',
contractType: ContractType.Aux,
address: actionHubAddress
address: actionHubAddress,
});

return actionHubAddress;
Expand Down
5 changes: 5 additions & 0 deletions deploy/deployRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export async function deployRules(): Promise<void> {
constructorArguments: [metadataURI],
},
// Graph Rules
{
contractName: 'GroupGatedGraphRule',
contractType: ContractType.Rule,
constructorArguments: [metadataURI],
},
{
contractName: 'RestrictedSignersGraphRule',
contractType: ContractType.Rule,
Expand Down
172 changes: 101 additions & 71 deletions deploy/lensUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export enum ContractType {
Action,
Rule,
Misc,
Address
Address,
}

export interface ContractInfo {
Expand Down Expand Up @@ -96,85 +96,115 @@ export async function deployLensContract(contractToDeploy: ContractInfo): Promis
}

export function camelToAllCaps(camelCase: string): string {
return camelCase
.replace(/([a-z])([A-Z])/g, '$1_$2') // Insert underscore between lowercase and uppercase letters
.toUpperCase(); // Convert to uppercase
}
return camelCase
.replace(/([a-z])([A-Z])/g, '$1_$2') // Insert underscore between lowercase and uppercase letters
.toUpperCase(); // Convert to uppercase
}

export function generateEnvFile() {
console.log('Generating env file...');
const addressBook = loadAddressBook();
let output = '';

// Group contracts by type
const factories: string[] = [];
const actions: string[] = [];
const rules: string[] = [];
const primitives: string[] = [];
const aux: string[] = [];
const misc: string[] = [];
for (const [contractName, info] of Object.entries(addressBook as AddressBook)) {
if (!info.address) continue;

const envVarName = camelToAllCaps(contractName);
const line = `${envVarName}="${info.address}"`;

switch (info.contractType) {
case ContractType.Factory: // Using enum instead of magic numbers
factories.push(line);
break;
case ContractType.Primitive:
primitives.push(line);
break;
case ContractType.Aux:
aux.push(line);
break;
case ContractType.Action:
actions.push(line);
break;
case ContractType.Rule:
rules.push(line);
break;
case ContractType.Misc:
misc.push(line);
break;
}
console.log('Generating env file...');
const addressBook = loadAddressBook();
let output = '';

// Group contracts by type
const factories: string[] = [];
const implementations: string[] = [];
const beacons: string[] = [];
const actions: string[] = [];
const rules: string[] = [];
const primitives: string[] = [];
const aux: string[] = [];
const misc: string[] = [];
const addresses: string[] = [];
for (const [contractName, info] of Object.entries(addressBook as AddressBook)) {
if (!info.address) continue;

const envVarName = camelToAllCaps(contractName);
const line = `${envVarName}="${info.address}"`;

switch (info.contractType) {
case ContractType.Factory: // Using enum instead of magic numbers
factories.push(line);
break;
case ContractType.Implementation:
implementations.push(line);
break;
case ContractType.Beacon:
beacons.push(line);
break;
case ContractType.Primitive:
primitives.push(line);
break;
case ContractType.Aux:
aux.push(line);
break;
case ContractType.Action:
actions.push(line);
break;
case ContractType.Rule:
rules.push(line);
break;
case ContractType.Misc:
misc.push(line);
break;
case ContractType.Address:
addresses.push(line);
break;
}
}

// Build output string
output += '# CONTRACTS\n';
output += factories.join('\n');
// Build output string
output += '# FACTORIES\n';
output += factories.join('\n');
output += '\n\n';

if (primitives.length > 0) {
output += '# IMPLEMENTATIONS\n';
output += implementations.join('\n');
output += '\n\n';
}

if (primitives.length > 0) {
output += '# LENS GLOBAL PRIMITIVES\n';
output += primitives.join('\n');
output += '\n\n';
}
if (primitives.length > 0) {
output += '# BEACONS\n';
output += implementations.join('\n');
output += '\n\n';
}

if (aux.length > 0) {
output += '# AUX\n';
output += aux.join('\n');
output += '\n\n';
}
if (primitives.length > 0) {
output += '# LENS GLOBAL PRIMITIVES\n';
output += primitives.join('\n');
output += '\n\n';
}

if (actions.length > 0) {
output += '# ACTIONS\n';
output += actions.join('\n');
output += '\n\n';
}
if (aux.length > 0) {
output += '# AUX\n';
output += aux.join('\n');
output += '\n\n';
}

if (rules.length > 0) {
output += '# RULES\n';
output += rules.join('\n');
output += '\n\n';
}
if (actions.length > 0) {
output += '# ACTIONS\n';
output += actions.join('\n');
output += '\n\n';
}

if (misc.length > 0) {
output += '# MISC\n';
output += misc.join('\n');
output += '\n';
}
if (rules.length > 0) {
output += '# RULES\n';
output += rules.join('\n');
output += '\n\n';
}

if (misc.length > 0) {
output += '# MISC\n';
output += misc.join('\n');
output += '\n';
}

fs.writeFileSync('contracts.env', output);
if (addresses.length > 0) {
output += '# CONSTANTS / ADDRESSES\n';
output += addresses.join('\n');
output += '\n';
}

fs.writeFileSync('contracts.env', output);
}
Loading

0 comments on commit 26d8b89

Please sign in to comment.