Skip to content

Commit

Permalink
Applied recommandations
Browse files Browse the repository at this point in the history
  • Loading branch information
skimaharvey committed Feb 23, 2024
1 parent c842992 commit 6b6d53b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 25 deletions.
8 changes: 8 additions & 0 deletions smart-contracts-hardhat/global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const LSP23_FACTORY_ADDRESS_TESTNET = '0x2300000A84D25dF63081feAa37ba6b62C4c89a30';
export const LSP23_POST_DEPLOYMENT_MODULE_ADDRESS_TESTNET =
'0x000000000066093407b6704B89793beFfD0D8F00';
export const UNIVERSAL_PROFILE_IMPLEMENTATION_ADDRESS_TESTNET =
'0x3024D38EA2434BA6635003Dc1BDC0daB5882ED4F';
export const LSP6_KEY_MANAGER_IMPLEMENTATION_ADDRESS_TESTNET =
'0x2Fe3AeD98684E7351aD2D408A43cE09a738BF8a4';
export const LSP1_UNIVERSAL_RECEIVER_ADDRESS_TESTNET = '0x7870C5B8BC9572A8001C3f96f7ff59961B23500D';
57 changes: 32 additions & 25 deletions smart-contracts-hardhat/scripts/deployUniversalProfiileWithLSP23.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,63 @@ import { ethers } from 'hardhat';
import { AbiCoder } from 'ethers';
import { ERC725 } from '@erc725/erc725.js';

// LSPs artifacts
// LSPs Smart Contracts artifacts

import LSP23FactoryArtifact from '@lukso/lsp-smart-contracts/artifacts/LSP23LinkedContractsFactory.json';
import UniversalProfileInitArtifact from '@lukso/lsp-smart-contracts/artifacts/UniversalProfileInit.json';

// ERC725.js schemas
// ERC725.js Metadata schemas

import LSP1UniversalReceiverDelegateSchemas from '@erc725/erc725.js/schemas/LSP1UniversalReceiverDelegate.json';
import LSP3ProfileMetadataSchemas from '@erc725/erc725.js/schemas/LSP3ProfileMetadata.json';
import LSP6KeyManagerSchemas from '@erc725/erc725.js/schemas/LSP6KeyManager.json';

const LSP23_FACTORY_ADDRESS = '0x2300000A84D25dF63081feAa37ba6b62C4c89a30';
const LSP23_POST_DEPLOYMENT_MODULE = '0x000000000066093407b6704B89793beFfD0D8F00';
const UNIVERSAL_PROFILE_IMPLEMENTATION_ADDRESS = '0x3024D38EA2434BA6635003Dc1BDC0daB5882ED4F';
const LSP6_KEY_MANAGER_IMPLEMENTATION_ADDRESS = '0x2Fe3AeD98684E7351aD2D408A43cE09a738BF8a4';
const UNIVERSAL_RECEIVER_ADDRESS = '0x7870C5B8BC9572A8001C3f96f7ff59961B23500D'; // this will be needed later so we can set the Universal Receiver to the Universal Profile (see https://docs.lukso.tech/standards/generic-standards/lsp1-universal-receiver)
const MAIN_CONTROLLER = '0x3303Ce3b8644D566271DD2Eb54292d32F1458968';
// Constants
import {
LSP23_FACTORY_ADDRESS_TESTNET,
UNIVERSAL_PROFILE_IMPLEMENTATION_ADDRESS_TESTNET,
LSP23_POST_DEPLOYMENT_MODULE_ADDRESS_TESTNET,
LSP6_KEY_MANAGER_IMPLEMENTATION_ADDRESS_TESTNET,
LSP1_UNIVERSAL_RECEIVER_ADDRESS_TESTNET,
} from '../global';

// Constants that needs to be overwritten
const MAIN_CONTROLLER_EOA = '0x3303Ce3b8644D566271DD2Eb54292d32F1458968';
const SALT = '0x5eed5eed5eed5eed5eed5eed5eed5eed5eed5eed5eed5eed5eed5eed5eed5eed';

async function main() {
// Interacting with the LSP23Factory contract
const lsp23FactoryContract = await ethers.getContractAtFromArtifact(
LSP23FactoryArtifact,
LSP23_FACTORY_ADDRESS,
LSP23_FACTORY_ADDRESS_TESTNET,
);

// Interacting with the UniversalProfileImplementation contract
const universalProfileImplementationContract = await ethers.getContractAtFromArtifact(
UniversalProfileInitArtifact,
UNIVERSAL_PROFILE_IMPLEMENTATION_ADDRESS,
UNIVERSAL_PROFILE_IMPLEMENTATION_ADDRESS_TESTNET,
);

// create the init structs
// create the init structs of LSP23 Linked Contracts Factory
const universalProfileInitStruct = {
salt: SALT,
fundingAmount: 0,
implementationContract: UNIVERSAL_PROFILE_IMPLEMENTATION_ADDRESS,
implementationContract: UNIVERSAL_PROFILE_IMPLEMENTATION_ADDRESS_TESTNET,
initializationCalldata: universalProfileImplementationContract.interface.encodeFunctionData(
'initialize',
[LSP23_POST_DEPLOYMENT_MODULE],
), // this will call the `initialize(...)` function of the Universal Profile and the the LSP23_POST_DEPLOYMENT_MODULE as owner
[LSP23_POST_DEPLOYMENT_MODULE_ADDRESS_TESTNET],
), // this will call the `initialize(...)` function of the Universal Profile and set the LSP23_POST_DEPLOYMENT_MODULE as `owner()`
};

const keyManagerInitStruct = {
fundingAmount: 0,
implementationContract: LSP6_KEY_MANAGER_IMPLEMENTATION_ADDRESS,
implementationContract: LSP6_KEY_MANAGER_IMPLEMENTATION_ADDRESS_TESTNET,
addPrimaryContractAddress: true, // this will append the primary contract address to the init calldata
initializationCalldata: '0xc4d66de8', // `initialize(...)` function selector
initializationCalldata: '0xc4d66de8', // `initialize(address)` function selector
extraInitializationParams: '0x',
};

// instantiate the erc725 class
// instantiate the erc725.js class
const erc725 = new ERC725([
...LSP6KeyManagerSchemas,
...LSP3ProfileMetadataSchemas,
Expand All @@ -65,27 +72,27 @@ async function main() {
method: 'keccak256(utf8)',
data: '0x6d6d08aafb0ee059e3e4b6b3528a5be37308a5d4f4d19657d26dd8a5ae799de0',
},
url: 'ipfs://QmPRoJsaYcNqQiUrQxE7ajTRaXwHyAU29tHqYNctBmK64w',
url: 'ipfs://QmPRoJsaYcNqQiUrQxE7ajTRaXwHyAU29tHqYNctBmK64w', // this is an example of Metadata stored on IPFS
};

// create the permissions data keys
// create the permissions data keys - value pairs to be set
const setDataKeysAndValues = erc725.encodeData([
{ keyName: 'LSP3Profile', value: lsp3DataValue }, // LSP3Metadata data key and value
{
keyName: 'LSP1UniversalReceiverDelegate',
value: UNIVERSAL_RECEIVER_ADDRESS,
value: LSP1_UNIVERSAL_RECEIVER_ADDRESS_TESTNET,
}, // Universal Receiver data key and value
{
keyName: 'AddressPermissions:Permissions:<address>',
dynamicKeyParts: [UNIVERSAL_RECEIVER_ADDRESS],
dynamicKeyParts: [LSP1_UNIVERSAL_RECEIVER_ADDRESS_TESTNET],
value: erc725.encodePermissions({
REENTRANCY: true,
SUPER_SETDATA: true,
}),
}, // Universal Receiver Delegate permissions data key and value
{
keyName: 'AddressPermissions:Permissions:<address>',
dynamicKeyParts: [MAIN_CONTROLLER],
dynamicKeyParts: [MAIN_CONTROLLER_EOA],
value: erc725.encodePermissions({
CHANGEOWNER: true,
ADDCONTROLLER: true,
Expand Down Expand Up @@ -115,7 +122,7 @@ async function main() {
// length of the Address Permissions array and their respective indexed keys and values
{
keyName: 'AddressPermissions[]',
value: [UNIVERSAL_RECEIVER_ADDRESS, MAIN_CONTROLLER],
value: [LSP1_UNIVERSAL_RECEIVER_ADDRESS_TESTNET, MAIN_CONTROLLER_EOA],
},
]);

Expand All @@ -131,7 +138,7 @@ async function main() {
const [upAddress, keyManagerAddress] = await lsp23FactoryContract.deployERC1167Proxies.staticCall(
universalProfileInitStruct,
keyManagerInitStruct,
LSP23_POST_DEPLOYMENT_MODULE,
LSP23_POST_DEPLOYMENT_MODULE_ADDRESS_TESTNET,
initializeEncodedBytes,
);
console.log('Universal Profile address:', upAddress);
Expand All @@ -140,7 +147,7 @@ async function main() {
const tx = await lsp23FactoryContract.deployERC1167Proxies(
universalProfileInitStruct,
keyManagerInitStruct,
LSP23_POST_DEPLOYMENT_MODULE,
LSP23_POST_DEPLOYMENT_MODULE_ADDRESS_TESTNET,
initializeEncodedBytes,
);
await tx.wait();
Expand Down

0 comments on commit 6b6d53b

Please sign in to comment.