Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ETHEREUM-CONTRACTS] make deploy script compatible with ethers v6 #1730

Merged
merged 4 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/ethereum-contracts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Simplification of Super App registration: use `registerApp` in all cases going forward.
- Use `registerApp(uint256 configWord)` to be called by the super app in the constructor or `registerApp(ISuperApp app, uint256 configWord)` to be called by any address with a valid app registration config key

### Fixes
- [`dev-scripts/deploy-test-framework.js`](dev-scripts/deploy-test-framework.js) compatible with both ethers-v5 and ethers-v6 now

## [v1.8.1] - 2023-08-28

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
async function deployContractsAndToken() {
const [Deployer] = await ethers.getSigners();

const {frameworkDeployer: deployer} = await deployTestFramework();
const {frameworkDeployer: deployer} = await deployTestFramework(null, ethers.provider, Deployer);
const framework = await deployer.getFramework();

const resolver = await ethers.getContractAt(
Expand Down
93 changes: 65 additions & 28 deletions packages/ethereum-contracts/dev-scripts/deploy-test-framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ async function deployERC1820(provider) {
}
}

/**
* Gets the address of the deployed contract.
* This is for handling the different contract objects in ethers v5 (contract.address)
* vs ethers v6 (contract.target), that is, v6 does not have contract.address and vice versa.
* @param {ethers.Contract} contract
* @returns
*/
const getContractAddress = (contract) => {
return contract.address || contract.target;
};

const _getFactoryAndReturnDeployedContract = async (
contractName,
artifact,
Expand All @@ -65,21 +76,36 @@ const _getFactoryAndReturnDeployedContract = async (
signerOrOptions
);
const contract = await ContractFactory.deploy(...args);
await contract.deployed();

// ethers v5
if (contract.deployed) {
await contract.deployed();
} else if (!contract.deployed) {
// ethers v6
await contract.waitForDeployment();
}

if (process.env.DEBUG_CONSOLE === true) {
console.log(`${contractName} Deployed At:`, contract.address);
console.log(
`${contractName} Deployed At:`,
getContractAddress(contract)
);
}
return contract;
};

/**
* Deploys Superfluid Framework in local testing environments.
* NOTE: This only works with Hardhat.
* NOTE: This only works with Hardhat + ethers v5/ethers v6 currently.
* @param privateKey NEVER USE A PRIVATE KEY WITH REAL FUNDS - a test account private key
* @param provider an ethers provider
* @param ethersV5Signer an ethers v5 signer
* @returns
*/
const deployTestFramework = async () => {
const signer = (await ethers.getSigners())[0];
await deployERC1820(ethers.provider);
const deployTestFramework = async (privateKey, provider, ethersV5Signer) => {
0xdavinchee marked this conversation as resolved.
Show resolved Hide resolved
// use a passed signer OR create one on the spot
const signer = ethersV5Signer || new ethers.Wallet(privateKey, provider);
await deployERC1820(provider);
const SlotsBitmapLibrary = await _getFactoryAndReturnDeployedContract(
"SlotsBitmapLibrary",
SlotsBitmapLibraryArtifact,
Expand Down Expand Up @@ -110,7 +136,7 @@ const deployTestFramework = async () => {
{
signer,
libraries: {
SlotsBitmapLibrary: SlotsBitmapLibrary.address,
SlotsBitmapLibrary: getContractAddress(SlotsBitmapLibrary),
},
}
);
Expand Down Expand Up @@ -170,27 +196,38 @@ const deployTestFramework = async () => {
{
signer,
libraries: {
SuperfluidGovDeployerLibrary:
SuperfluidGovDeployerLibrary.address,
SuperfluidHostDeployerLibrary:
SuperfluidHostDeployerLibrary.address,
SuperfluidCFAv1DeployerLibrary:
SuperfluidCFAv1DeployerLibrary.address,
SuperfluidIDAv1DeployerLibrary:
SuperfluidIDAv1DeployerLibrary.address,
SuperfluidPeripheryDeployerLibrary:
SuperfluidPeripheryDeployerLibrary.address,
SuperTokenDeployerLibrary: SuperTokenDeployerLibrary.address,
SuperfluidNFTLogicDeployerLibrary:
SuperfluidNFTLogicDeployerLibrary.address,
ProxyDeployerLibrary: ProxyDeployerLibrary.address,
CFAv1ForwarderDeployerLibrary:
CFAv1ForwarderDeployerLibrary.address,
IDAv1ForwarderDeployerLibrary:
IDAv1ForwarderDeployerLibrary.address,
SuperfluidLoaderDeployerLibrary:
SuperfluidLoaderDeployerLibrary.address,
TokenDeployerLibrary: TokenDeployerLibrary.address,
SuperfluidGovDeployerLibrary: getContractAddress(
SuperfluidGovDeployerLibrary
),
SuperfluidHostDeployerLibrary: getContractAddress(
SuperfluidHostDeployerLibrary
),
SuperfluidCFAv1DeployerLibrary: getContractAddress(
SuperfluidCFAv1DeployerLibrary
),
SuperfluidIDAv1DeployerLibrary: getContractAddress(
SuperfluidIDAv1DeployerLibrary
),
SuperfluidPeripheryDeployerLibrary: getContractAddress(
SuperfluidPeripheryDeployerLibrary
),
SuperTokenDeployerLibrary: getContractAddress(
SuperTokenDeployerLibrary
),
SuperfluidNFTLogicDeployerLibrary: getContractAddress(
SuperfluidNFTLogicDeployerLibrary
),
ProxyDeployerLibrary: getContractAddress(ProxyDeployerLibrary),
CFAv1ForwarderDeployerLibrary: getContractAddress(
CFAv1ForwarderDeployerLibrary
),
IDAv1ForwarderDeployerLibrary: getContractAddress(
IDAv1ForwarderDeployerLibrary
),
SuperfluidLoaderDeployerLibrary: getContractAddress(
SuperfluidLoaderDeployerLibrary
),
TokenDeployerLibrary: getContractAddress(TokenDeployerLibrary),
},
}
);
Expand Down
4 changes: 3 additions & 1 deletion packages/ethereum-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@
},
"dependencies": {
"@decentral.ee/web3-helpers": "0.5.3",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@openzeppelin/contracts": "4.9.3",
"@truffle/contract": "4.6.29",
"ethereumjs-tx": "2.1.2",
"ethereumjs-util": "7.1.5"
"ethereumjs-util": "7.1.5",
"hardhat": "^2.17.3"
},
"devDependencies": {
"@nomiclabs/hardhat-truffle5": "^2.0.7",
Expand Down