Skip to content

Commit

Permalink
build: deploy base contracts at pre-deterministic address (#758)
Browse files Browse the repository at this point in the history
* build: deploy base contracts at pre-deterministic address

* build: use pre-defined salt
  • Loading branch information
CJ42 authored Oct 30, 2023
1 parent 66e001d commit b7cfc53
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 44 deletions.
17 changes: 10 additions & 7 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,30 @@ Available `--tags <options>` are:

- `LSP6KeyManager`: deploy a `UniversalProfile` + `KeyManager`, with the Universal Profile address linked to the Key Manager.

- `LSP6KeyManagerInit`: deploy + initialize (= lock) both a `UniversalProfileInit` + `KeyManagerInit`, as base contracts (**NB:** the Key Manager will be initialized with reference to `address(0)`).
- `LSP6KeyManagerInit`: deploy at deterministic address + initialize (= lock) both a `UniversalProfileInit` + `KeyManagerInit`, as base contracts (**NB:** the Key Manager will be initialized with reference to `address(0)`).

- `LSP1UniversalReceiverDelegateUP`: deploy a Universal Receiver Delegate contract that can be used to register assets and vaults received by a Universal Profile.
- `LSP1UniversalReceiverDelegateUP`: deploy at deterministic address a Universal Receiver Delegate contract that can be used to register assets and vaults received by a Universal Profile.

- `LSP1UniversalReceiverDelegateVault`: deploy a Universal Receiver Delegate contract that can be used to register assets received by a LSP9Vault.
- `LSP1UniversalReceiverDelegateVault`: deploy at deterministic address a Universal Receiver Delegate contract that can be used to register assets received by a LSP9Vault.

- `LSP7Mintable`: deploy a `LSP7Mintable` contract (Token), using the deployer address as the owner and allowing this deployer address to then mint tokens. The `isNFT_` parameter is set to `false`, making the token divisible.

- `LSP8Mintable`: deploy a `LSP7Mintable` contract (NFT), using the deployer address as the owner and allowing this deployer address to then mint tokens.

- `LSP7MintableInit`: deploy + initialize (= lock) a `LSP7MintableInit` contract (Token), that can be used as implementation behind proxy. The base contract is deployed with the `isNonDivisible_` parameter set to `false`, making the implementation token divisible.
- `LSP7MintableInit`: deploy at deterministic address + initialize (= lock) a `LSP7MintableInit` contract (Token), that can be used as implementation behind proxy. The base contract is deployed with the `isNonDivisible_` parameter set to `false`, making the implementation token divisible.

- `LSP8MintableInit`: deploy + initialize (= lock) a `LSP8MintableInit` contract, that can be used as implementation behind proxy.
- `LSP8MintableInit`: deploy at deterministic address + initialize (= lock) a `LSP8MintableInit` contract, that can be used as implementation behind proxy.

- `LSP9Vault`: deploy a `LSP9Vault` contract with the deployer as the owner.

- `LSP9VaultInit`: deploy + initialize (= lock) a `LSP9VaultInit` contract that can be used as implementation behind proxy.
- `LSP9VaultInit`: deploy at deterministic address + initialize (= lock) a `LSP9VaultInit` contract that can be used as implementation behind proxy.

- `standard`: deploy the 4 standard contract above.

- `base`: deploy the 4 base contract above (for proxy use)
- `base`: deploy the 4 base contract above (for proxy use) at deterministic addresses.

> **Note:** all the contracts marked as `base` or `Init` are deployed at deterministic addresses, so that they can be used as implementation behind proxies. If the contract is already deployed on the network, the address where the contract exists already will be returned.
> Moreover, **these contracts use `bytes32(0)` as their `salt` to deploy with CREATE2.**
&nbsp;

Expand Down
12 changes: 7 additions & 5 deletions deploy/003_deploy_universal_receiver_delegate.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DeployFunction } from 'hardhat-deploy/types';
import { ethers } from 'hardhat';
import { SALT } from './salt';

const deployUniversalReceiverDelegateUP: DeployFunction = async ({
const deployUniversalReceiverDelegateUPDeterministic: DeployFunction = async ({
deployments,
getNamedAccounts,
}: HardhatRuntimeEnvironment) => {
const { deploy } = deployments;
const { owner } = await getNamedAccounts();
const { owner: deployer } = await getNamedAccounts();

await deploy('LSP1UniversalReceiverDelegateUP', {
from: owner,
from: deployer,
gasPrice: ethers.BigNumber.from(20_000_000_000), // in wei
log: true,
deterministicDeployment: SALT,
});
};

export default deployUniversalReceiverDelegateUP;
deployUniversalReceiverDelegateUP.tags = ['LSP1UniversalReceiverDelegateUP'];
export default deployUniversalReceiverDelegateUPDeterministic;
deployUniversalReceiverDelegateUPDeterministic.tags = ['LSP1UniversalReceiverDelegateUP'];
12 changes: 7 additions & 5 deletions deploy/005_deploy_universal_receiver_delegate_vault.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DeployFunction } from 'hardhat-deploy/types';
import { ethers } from 'hardhat';
import { SALT } from './salt';

const deployUniversalReceiverDelegateVault: DeployFunction = async ({
const deployUniversalReceiverDelegateVaultDeterministic: DeployFunction = async ({
deployments,
getNamedAccounts,
}: HardhatRuntimeEnvironment) => {
const { deploy } = deployments;
const { owner } = await getNamedAccounts();
const { owner: deployer } = await getNamedAccounts();

await deploy('LSP1UniversalReceiverDelegateVault', {
from: owner,
from: deployer,
gasPrice: ethers.BigNumber.from(20_000_000_000), // in wei
log: true,
deterministicDeployment: SALT,
});
};

export default deployUniversalReceiverDelegateVault;
deployUniversalReceiverDelegateVault.tags = ['LSP1UniversalReceiverDelegateVault'];
export default deployUniversalReceiverDelegateVaultDeterministic;
deployUniversalReceiverDelegateVaultDeterministic.tags = ['LSP1UniversalReceiverDelegateVault'];
12 changes: 7 additions & 5 deletions deploy/006_deploy_base_universal_profile.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DeployFunction } from 'hardhat-deploy/types';
import { ethers } from 'hardhat';
import { SALT } from './salt';

const deployBaseUniversalProfile: DeployFunction = async ({
const deployBaseUniversalProfileDeterministic: DeployFunction = async ({
deployments,
getNamedAccounts,
}: HardhatRuntimeEnvironment) => {
const { deploy } = deployments;
const { owner } = await getNamedAccounts();
const { owner: deployer } = await getNamedAccounts();

await deploy('UniversalProfileInit', {
from: owner,
from: deployer,
log: true,
gasPrice: ethers.BigNumber.from(20_000_000_000), // in wei
deterministicDeployment: SALT,
});
};

export default deployBaseUniversalProfile;
deployBaseUniversalProfile.tags = ['UniversalProfileInit', 'base'];
export default deployBaseUniversalProfileDeterministic;
deployBaseUniversalProfileDeterministic.tags = ['UniversalProfileInit', 'base'];
12 changes: 7 additions & 5 deletions deploy/007_deploy_base_key_manager.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DeployFunction } from 'hardhat-deploy/types';
import { ethers } from 'hardhat';
import { SALT } from './salt';

const deployBaseKeyManager: DeployFunction = async ({
const deployBaseKeyManagerDeterministic: DeployFunction = async ({
deployments,
getNamedAccounts,
}: HardhatRuntimeEnvironment) => {
const { deploy } = deployments;
const { owner } = await getNamedAccounts();
const { owner: deployer } = await getNamedAccounts();

await deploy('LSP6KeyManagerInit', {
from: owner,
from: deployer,
log: true,
gasLimit: 5_000_000,
gasPrice: ethers.BigNumber.from(20_000_000_000), // in wei
deterministicDeployment: SALT,
});
};

export default deployBaseKeyManager;
deployBaseKeyManager.tags = ['LSP6KeyManagerInit', 'base'];
export default deployBaseKeyManagerDeterministic;
deployBaseKeyManagerDeterministic.tags = ['LSP6KeyManagerInit', 'base'];
13 changes: 7 additions & 6 deletions deploy/009_deploy_lsp8_mintable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DeployFunction } from 'hardhat-deploy/types';
import { ethers } from 'hardhat';

const deployLSP8Mintable: DeployFunction = async ({
const deployLSP8MintableDeterministic: DeployFunction = async ({
deployments,
getNamedAccounts,
}: HardhatRuntimeEnvironment) => {
const { deploy } = deployments;
const { owner } = await getNamedAccounts();
const { owner: deployer } = await getNamedAccounts();

await deploy('LSP8Mintable', {
from: owner,
args: ['LSP8 Mintable', 'LSP8M', owner],
from: deployer,
args: ['LSP8 Mintable', 'LSP8M', deployer],
gasPrice: ethers.BigNumber.from(20_000_000_000), // in wei,
log: true,
deterministicDeployment: true,
});
};

export default deployLSP8Mintable;
deployLSP8Mintable.tags = ['LSP8Mintable', 'standard'];
export default deployLSP8MintableDeterministic;
deployLSP8MintableDeterministic.tags = ['LSP8Mintable', 'standard'];
12 changes: 7 additions & 5 deletions deploy/010_deploy_base_lsp7_mintable.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DeployFunction } from 'hardhat-deploy/types';
import { ethers } from 'hardhat';
import { SALT } from './salt';

const deployBaseLSP7Mintable: DeployFunction = async ({
const deployBaseLSP7MintableDeterministic: DeployFunction = async ({
deployments,
getNamedAccounts,
}: HardhatRuntimeEnvironment) => {
const { deploy } = deployments;
const { owner } = await getNamedAccounts();
const { owner: deployer } = await getNamedAccounts();

await deploy('LSP7MintableInit', {
from: owner,
from: deployer,
gasPrice: ethers.BigNumber.from(20_000_000_000), // in wei,
log: true,
deterministicDeployment: SALT,
});
};

export default deployBaseLSP7Mintable;
deployBaseLSP7Mintable.tags = ['LSP7MintableInit', 'base'];
export default deployBaseLSP7MintableDeterministic;
deployBaseLSP7MintableDeterministic.tags = ['LSP7MintableInit', 'base'];
2 changes: 2 additions & 0 deletions deploy/011_deploy_base_lsp8_mintable.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DeployFunction } from 'hardhat-deploy/types';
import { ethers } from 'hardhat';
import { SALT } from './salt';

const deployBaseLSP8Mintable: DeployFunction = async ({
deployments,
Expand All @@ -13,6 +14,7 @@ const deployBaseLSP8Mintable: DeployFunction = async ({
from: owner,
gasPrice: ethers.BigNumber.from(20_000_000_000), // in wei,
log: true,
deterministicDeployment: SALT,
});
};

Expand Down
12 changes: 7 additions & 5 deletions deploy/013_deploy_base_vault.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DeployFunction } from 'hardhat-deploy/types';
import { ethers } from 'hardhat';
import { SALT } from './salt';

const deployBaseVault: DeployFunction = async ({
const deployBaseVaultDeterministic: DeployFunction = async ({
deployments,
getNamedAccounts,
}: HardhatRuntimeEnvironment) => {
const { deploy } = deployments;
const { owner } = await getNamedAccounts();
const { owner: deployer } = await getNamedAccounts();

await deploy('LSP9VaultInit', {
from: owner,
from: deployer,
log: true,
gasPrice: ethers.BigNumber.from(20_000_000_000), // in wei
deterministicDeployment: SALT,
});
};

export default deployBaseVault;
deployBaseVault.tags = ['LSP9VaultInit', 'base'];
export default deployBaseVaultDeterministic;
deployBaseVaultDeterministic.tags = ['LSP9VaultInit', 'base'];
1 change: 1 addition & 0 deletions deploy/salt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const SALT = '0xfeedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeed';
13 changes: 12 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function getTestnetChainConfig(): NetworkUserConfig {
live: true,
url: 'https://rpc.testnet.lukso.network',
chainId: 4201,
saveDeployments: true,
};

if (process.env.CONTRACT_VERIFICATION_TESTNET_PK !== undefined) {
Expand All @@ -53,14 +54,24 @@ const config: HardhatUserConfig = {
networks: {
hardhat: {
live: false,
saveDeployments: false,
saveDeployments: true,
allowBlocksWithSameTimestamp: true,
},
luksoTestnet: getTestnetChainConfig(),
},
namedAccounts: {
owner: 0,
},
deterministicDeployment: {
luksoTestnet: {
// Nick Factory. See https://github.com/Arachnid/deterministic-deployment-proxy
factory: '0x4e59b44847b379578588920ca78fbf26c0b4956c',
deployer: '0x3fab184622dc19b6109349b94811493bf2a45362',
funding: '0x0000000000000000000000000000000000000000000000000000000000000000',
signedTx:
'0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222',
},
},
etherscan: {
apiKey: 'no-api-key-needed',
customChains: [
Expand Down

0 comments on commit b7cfc53

Please sign in to comment.