Skip to content

Commit

Permalink
Only execute startup transactions when contracts newly deployed
Browse files Browse the repository at this point in the history
  • Loading branch information
jummy123 authored and cryptofish7 committed Jan 19, 2022
1 parent dfe0ad6 commit 21fa447
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 44 deletions.
59 changes: 30 additions & 29 deletions deploy/LaunchTokenTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,39 @@ module.exports = async function ({ getNamedAccounts, deployments }) {

const chainId = await getChainId();

await deploy("ERC20Token", {
const token = await deploy("ERC20Token", {
from: deployer,
log: true,
});

const tokenAddress = (await deployments.get("ERC20Token")).address;
const token = await ethers.getContractAt("ERC20Token", tokenAddress);

const factoryAddress = (await deployments.get("RocketJoeFactory")).address;
const factory = await ethers.getContractAt(
"RocketJoeFactory",
factoryAddress
);

const tokenAmount = ethers.utils.parseEther("105");

await token.mint(deployer, tokenAmount);
await token.approve(factoryAddress, tokenAmount);

await factory.createRJLaunchEvent(
deployer,
(await ethers.provider.getBlock()).timestamp + 60,
tokenAddress,
tokenAmount,
ethers.utils.parseEther("0.05"), // incentive token
ethers.utils.parseEther("0"), // floor price
4e11, // withdraw penalty gradient
4e11, // fixed withdraw penalty
ethers.utils.parseEther("5"), // maxAllocation
60 * 60 * 24, // user timelock
60 * 60 * 24 + 1 // issuer timelock
);
if (token.newlyDeployed) {
const tokenAddress = (await deployments.get("ERC20Token")).address;
const token = await ethers.getContractAt("ERC20Token", tokenAddress);

const factoryAddress = (await deployments.get("RocketJoeFactory")).address;
const factory = await ethers.getContractAt(
"RocketJoeFactory",
factoryAddress
);

const tokenAmount = ethers.utils.parseEther("105");

await token.mint(deployer, tokenAmount);
await token.approve(factoryAddress, tokenAmount);

await factory.createRJLaunchEvent(
deployer,
(await ethers.provider.getBlock()).timestamp + 60,
tokenAddress,
tokenAmount,
ethers.utils.parseEther("0.05"), // incentive token
ethers.utils.parseEther("0"), // floor price
4e11, // withdraw penalty gradient
4e11, // fixed withdraw penalty
ethers.utils.parseEther("5"), // maxAllocation
60 * 60 * 24, // user timelock
60 * 60 * 24 + 1 // issuer timelock
);
}
};

module.exports.tags = ["ERC20Token"];
Expand Down
19 changes: 10 additions & 9 deletions deploy/RocketJoeFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = async function ({ getNamedAccounts, deployments }) {
);
}

await deploy("RocketJoeFactory", {
const factory = await deploy("RocketJoeFactory", {
from: deployer,
args: [
launchEventAddress,
Expand All @@ -44,14 +44,15 @@ module.exports = async function ({ getNamedAccounts, deployments }) {
],
log: true,
});

const rocketJoeFactoryAddress = (await deployments.get("RocketJoeFactory"))
.address;
const launchEvent = await ethers.getContractAt(
"LaunchEvent",
launchEventAddress
);
await launchEvent.transferOwnership(rocketJoeFactoryAddress);
if (factory.newlyDeployed) {
const rocketJoeFactoryAddress = (await deployments.get("RocketJoeFactory"))
.address;
const launchEvent = await ethers.getContractAt(
"LaunchEvent",
launchEventAddress
);
await launchEvent.transferOwnership(rocketJoeFactoryAddress);
}
};

module.exports.tags = ["RocketJoeFactory"];
Expand Down
13 changes: 7 additions & 6 deletions deploy/RocketJoeStaking.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@ module.exports = async function ({ getNamedAccounts, deployments }) {
);
}

await deploy("RocketJoeStaking", {
const staking = await deploy("RocketJoeStaking", {
from: deployer,
proxyContract: "OpenZeppelinTransparentProxy",
init: {
args: [joeAddress, rJoeAddress, rJoePerSec],
},
log: true,
});

const rJoeStakingAddress = (await deployments.get("RocketJoeStaking"))
.address;
const rJoe = await ethers.getContractAt("RocketJoeToken", rJoeAddress);
await rJoe.transferOwnership(rJoeStakingAddress);
if (staking.newlyDeployed) {
const rJoeStakingAddress = (await deployments.get("RocketJoeStaking"))
.address;
const rJoe = await ethers.getContractAt("RocketJoeToken", rJoeAddress);
await rJoe.transferOwnership(rJoeStakingAddress);
}
};

module.exports.tags = ["RocketJoeStaking"];
Expand Down

0 comments on commit 21fa447

Please sign in to comment.