Skip to content

Commit

Permalink
Merge branch 'main' into deploy-staging
Browse files Browse the repository at this point in the history
  • Loading branch information
vrde authored Nov 10, 2023
2 parents ee57ff9 + 670a0a7 commit 4c979d1
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 90 deletions.
7 changes: 7 additions & 0 deletions contracts/InternalMarket/InternalMarket.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ contract InternalMarket is Initializable, HasRole, InternalMarketBase {
* @param amount The amount of tokens to offer for sale.
*/
function makeOffer(uint256 amount) public virtual {
require(
_shareholderRegistry.isAtLeast(
_shareholderRegistry.CONTRIBUTOR_STATUS(),
msg.sender
),
"InternalMarket: only contributors can make offers"
);
_makeOffer(_msgSender(), amount);
}

Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const config: HardhatUserConfig = {
accounts: [POLYGON_PRIVATE_KEY],
},
tevmos: {
url: "https://eth.bd.evmos.dev:8545",
url: "https://evmos-testnet.lava.build",
accounts: [TEVMOS_PRIVATE_KEY],
},
evmos: {
Expand Down
5 changes: 3 additions & 2 deletions tasks/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import { question } from "../lib/utils";
const MULTISIG_MAINNET = "0xd232121c41EF9ad4e4d0251BdCbe60b9F3D20758";
const MULTISIG_TESTNET = "0x7549fe2ED3c16240f97FE736146347409C6dD81D";

task("deploy", "Deploy DAO")
task("deploy:dao", "Deploy DAO")
.addFlag("verify", "Verify contracts")
.addFlag("restart", "Start a new deployment from scratch")
.setAction(
async ({ verify, restart }: { verify: boolean; restart: boolean }, hre) => {
if (restart) await hre.run("compile", { force: true });
const neokingdom = await NeokingdomDAOHardhat.initialize(hre, {
verifyContracts: verify,
verbose: true,
Expand All @@ -30,7 +31,7 @@ task("deploy", "Deploy DAO")
}
);

task("setup", "Set up the DAO")
task("setup:dao", "Set up the DAO")
.addFlag("mainnet", "Go to Mainnet")
.setAction(async ({ mainnet }: { mainnet: boolean }, hre) => {
let sequence = SETUP_SEQUENCE_TESTNET;
Expand Down
136 changes: 50 additions & 86 deletions tasks/upgrade.ts
Original file line number Diff line number Diff line change
@@ -1,105 +1,69 @@
import { task } from "hardhat/config";

import {
GovernanceToken,
GovernanceToken__factory,
InternalMarket__factory,
ProxyAdmin,
ProxyAdmin__factory,
ResolutionManager__factory,
} from "../typechain";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { exit } from "process";

import { NeokingdomDAOHardhat } from "../lib";
import { NeokingdomContracts } from "../lib/internal/types";
import { question } from "../lib/utils";

task("upgrade:resolution", "Upgrade ResolutionManager", async (_, hre) => {
const resolutionFactory = (await hre.ethers.getContractFactory(
"ResolutionManager"
)) as ResolutionManager__factory;

function toPascalCase(str: string): string {
let words = str.split(/(?=[A-Z])/);

// Capitalize the first letter of each word, leave the rest as it is
let pascalCase = words
.map((word) => word[0].toUpperCase() + word.slice(1))
.join("");

return pascalCase;
}

const validContracts = [
"governanceToken",
"internalMarket",
"redemptionController",
"resolutionManager",
"shareholderRegistry",
"voting",
];

async function upgrade(
hre: HardhatRuntimeEnvironment,
contractType: keyof NeokingdomContracts
) {
await hre.run("compile", { force: true });
const neokingdom = await NeokingdomDAOHardhat.initialize(hre);
const contracts = await neokingdom.loadContracts();
console.log("Upgrade ResolutionManager");
console.log(" Network:", hre.network.name);

const resolutionContract = await hre.upgrades.upgradeProxy(
contracts.resolutionManager.address,
resolutionFactory
);
await resolutionContract.deployed();

console.log(" Address:", resolutionContract.address);
console.log("Resolution upgraded");
});

task("upgrade:market", "Upgrade Internal Market", async (_, hre) => {
const internalMarketFactory = (await hre.ethers.getContractFactory(
"InternalMarket"
)) as InternalMarket__factory;

const neokingdom = await NeokingdomDAOHardhat.initialize(hre);
const contracts = await neokingdom.loadContracts();
console.log(`Upgrade InternalMarket ${contracts.internalMarket.address}`);
const contractTypeStr = toPascalCase(contractType);
const contractFactory = await hre.ethers.getContractFactory(contractTypeStr);
const proxyAddress = contracts[contractType].address;
console.log(`Upgrade ${contractTypeStr} ${proxyAddress}`);
console.log(" Network:", hre.network.name);

const answer = await question(
"This action is irreversible. Please type 'GO' to continue.\n"
);

if (answer == "GO") {
const internalMarketContract = await hre.upgrades.upgradeProxy(
contracts.internalMarket.address,
internalMarketFactory
const contractInstance = await hre.upgrades.upgradeProxy(
proxyAddress,
contractFactory
);
await internalMarketContract.deployed();
await contractInstance.deployed();

console.log(" Address:", internalMarketContract.address);
console.log("InternalMarket upgraded");
console.log(" Address:", contractInstance.address);
console.log(`${contractTypeStr} upgraded`);
}
});

task("upgrade:governance", "Upgrade Governance Token", async (_, hre) => {
const governanceTokenFactory = (await hre.ethers.getContractFactory(
"GovernanceToken"
)) as GovernanceToken__factory;

const neokingdom = await NeokingdomDAOHardhat.initialize(hre);
const contracts = await neokingdom.loadContracts();
console.log(`Upgrade GovernanceToken ${contracts.governanceToken.address}`);
console.log(" Network:", hre.network.name);

const answer = await question(
"This action is irreversible. Please type 'GO' to continue.\n"
);

if (answer == "GO") {
const governanceTokenContract = (await hre.upgrades.upgradeProxy(
contracts.governanceToken.address,
governanceTokenFactory
)) as GovernanceToken;
await governanceTokenContract.deployed();

console.log(" Address:", governanceTokenContract.address);
console.log("GovernanceToken upgraded");
}
});

task("impl", "Get Proxy Impl")
.addParam("admin", "Proxy Admin")
.addParam("address", "Proxy address")
.setAction(
async ({ admin, address }: { admin: string; address: string }, hre) => {
const [deployer] = await hre.ethers.getSigners();
const ProxyAdmin = await hre.ethers.getContractFactory("ProxyAdmin");
const proxyAdmin = ProxyAdmin.attach(admin).connect(
deployer
) as ProxyAdmin;

console.log(" Proxy Owner:", await proxyAdmin.owner());

console.log(
" Address:",
await proxyAdmin.getProxyImplementation(address)
);
}

task("upgrade")
.addPositionalParam("contract", "The smart contract to upgrade")
.setAction(async ({ contract }: { contract: string }, hre) => {
console.log(contract);
if (!validContracts.includes(contract)) {
console.error(`Invalid contract. Valid options are: ${validContracts}`);
exit(1);
}
);

await upgrade(hre, contract as keyof NeokingdomContracts);
});
5 changes: 5 additions & 0 deletions test/Integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,11 @@ describe("Integration", async () => {
"Resolution: account cannot vote"
);

// user3 cannot offer tokens
await expect(internalMarket.connect(user3).makeOffer(10)).revertedWith(
"InternalMarket: only contributors can make offers"
);

// ... and finally the world is saved.
expect(await resolutionManager.getResolutionResult(resolutionId)).to.be
.true;
Expand Down
7 changes: 7 additions & 0 deletions test/InternalMarket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ describe("InternalMarket", async () => {
);
});

it("should revert when called by a non-contributor", async () => {
registry.isAtLeast.returns(false);
await expect(internalMarket.makeOffer(1000)).revertedWith(
"InternalMarket: only contributors can make offers"
);
});

describe("redeem", async () => {
describe("with some unlocked tokens", async () => {
beforeEach(async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/RedemptionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ describe("RedemptionController", () => {
);
});

describe.only("when 10 tokens are redeemable", async () => {
describe("when 10 tokens are redeemable", async () => {
beforeEach(async () => {
await redemptionController.afterMint(account.address, 10);
await redemptionController.afterOffer(account.address, 10);
Expand Down

0 comments on commit 4c979d1

Please sign in to comment.