Skip to content

Commit

Permalink
[ETHEREUM-CONTRACTS] make deploy script compatible with ethers v6 (#1730
Browse files Browse the repository at this point in the history
)

* make deploy script compatible with ethers v6

* more meaningful jsdoc

* add new functions for dev-scripts deployment
  • Loading branch information
0xdavinchee authored Oct 24, 2023
1 parent 8ab5829 commit e8990d8
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 38 deletions.
7 changes: 7 additions & 0 deletions packages/ethereum-contracts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
## Unreleased

### Breaking

- `TokenInfo` and `ERC20WithTokenInfo` interface/abstract contract are removed from the codebase, including the bundled ABI contracts
- Migration: Use `IERC20Metadata` instead, as this replaces the previous contracts
- `build/typechain-ethers-v5` is removed from the npm package
Expand All @@ -25,13 +26,19 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Note that the admin is stored in the EIP-1967 admin storage slot (`0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`)
- `SuperToken.getAdmin()` added to retrieve the admin address
- `SuperTokenFactory.createERC20Wrapper()` overloads added to create a SuperToken AND explicitly initialize a SuperToken with an admin
- New explicit functions: `deployTestFrameworkWithEthersV5` and `deployTestFrameworkWithEthersV6` in `deploy-test-framework.js`
- `deployTestFramework` is still there, but it is considered deprecated now

### Changed

- Reuse config keys from `SuperfluidGovernanceConfigs` instead of duplicating them in `ConstantFlowAgreementV1`.
- Deprecating `registerAppWithKey` and `registerAppByFactory`: DO NOT USE for new deployments
- 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 @@ -2,13 +2,14 @@ const {ethers} = require("hardhat");
const testResolverArtifact = require("@superfluid-finance/ethereum-contracts/build/hardhat/contracts/utils/TestResolver.sol/TestResolver.json");

const {
deployTestFramework,
deployTestFrameworkWithEthersV5,
} = require("@superfluid-finance/ethereum-contracts/dev-scripts/deploy-test-framework");

async function deployContractsAndToken() {
const [Deployer] = await ethers.getSigners();

const {frameworkDeployer: deployer} = await deployTestFramework();
const {frameworkDeployer: deployer} =
await deployTestFrameworkWithEthersV5(Deployer);
const framework = await deployer.getFramework();

const resolver = await ethers.getContractAt(
Expand Down
143 changes: 109 additions & 34 deletions packages/ethereum-contracts/dev-scripts/deploy-test-framework.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const {ethers} = require("hardhat");
const {JsonRpcProvider} = require("@ethersproject/providers");

const SuperfluidGovDeployerLibraryArtifact = require("@superfluid-finance/ethereum-contracts/build/hardhat/contracts/utils/SuperfluidFrameworkDeploymentSteps.sol/SuperfluidGovDeployerLibrary.json");
const SuperfluidHostDeployerLibraryArtifact = require("@superfluid-finance/ethereum-contracts/build/hardhat/contracts/utils/SuperfluidFrameworkDeploymentSteps.sol/SuperfluidHostDeployerLibrary.json");
Expand Down Expand Up @@ -51,6 +52,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 +77,40 @@ 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.
* @returns
*/
const deployTestFramework = async () => {
const signer = (await ethers.getSigners())[0];
await deployERC1820(ethers.provider);
const deployTestFrameworkWithEthersV6 = async (privateKey, provider) => {
if (!privateKey) throw new Error("You must pass a private key.");
if (!provider) throw new Error("You must pass a provider.");

const signer = new ethers.Wallet(privateKey, provider);

return await _deployTestFramework(provider, signer);
};

const deployTestFrameworkWithEthersV5 = async (ethersV5Signer) => {
if (!ethersV5Signer.provider)
throw new Error("Your signer must have a provider.");
return await _deployTestFramework(ethersV5Signer.provider, ethersV5Signer);
};

const _deployTestFramework = async (provider, signer) => {
await deployERC1820(provider);
const SlotsBitmapLibrary = await _getFactoryAndReturnDeployedContract(
"SlotsBitmapLibrary",
SlotsBitmapLibraryArtifact,
Expand Down Expand Up @@ -110,11 +141,10 @@ const deployTestFramework = async () => {
{
signer,
libraries: {
SlotsBitmapLibrary: SlotsBitmapLibrary.address,
SlotsBitmapLibrary: getContractAddress(SlotsBitmapLibrary),
},
}
);

const SuperTokenDeployerLibrary =
await _getFactoryAndReturnDeployedContract(
"SuperTokenDeployerLibrary",
Expand Down Expand Up @@ -170,38 +200,83 @@ 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),
},
}
);
const numSteps = await sfDeployer.getNumSteps();
for (let i = 0; i < numSteps; i++) {
await sfDeployer.executeStep(i);
}
const sf = await sfDeployer.getFramework();
return {frameworkDeployer: sfDeployer};
};

const printProtocolFrameworkAddresses = (framework) => {
const output = {
Host: framework.host,
CFAv1: framework.cfa,
IDAv1: framework.ida,
SuperTokenFactory: framework.superTokenFactory,
SuperTokenLogic: framework.superTokenLogic,
ConstantOutflowNFT: framework.constantOutflowNFT,
ConstantInflowNFT: framework.constantInflowNFT,
Resolver: framework.resolver,
SuperfluidLoader: framework.superfluidLoader,
CFAv1Forwarder: framework.cfaV1Forwarder,
IDAv1Forwarder: framework.idaV1Forwarder,
};

console.log(JSON.stringify(output, null, 2));

return output;
};

/**
* {DEPRECATED}
* Deploys Superfluid Framework in local testing environments.
*
* NOTE: This only works with Hardhat + ethers v5.
* @returns SuperfluidFrameworkDeployer Contract object
*/
const deployTestFramework = async () => {
const signer = (await ethers.getSigners())[0];
return await deployTestFrameworkWithEthersV5(signer);
};

module.exports = {
deployTestFramework,
deployTestFrameworkWithEthersV5,
deployTestFrameworkWithEthersV6,
printProtocolFrameworkAddresses,
};
10 changes: 9 additions & 1 deletion packages/ethereum-contracts/dev-scripts/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
const deployTestFramework = require("./deploy-test-framework");
const {
deployTestFramework,
deployTestFrameworkWithEthersV5,
deployTestFrameworkWithEthersV6,
printProtocolFrameworkAddresses
} = require("./deploy-test-framework");

module.exports = {
deployTestFrameworkWithEthersV6,
deployTestFrameworkWithEthersV5,
deployTestFramework,
printProtocolFrameworkAddresses
};
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

0 comments on commit e8990d8

Please sign in to comment.