Skip to content

Commit

Permalink
Merge pull request #13 from certusone/evm
Browse files Browse the repository at this point in the history
Add ownerOnly methods to update certain parameters
  • Loading branch information
Karl committed Apr 26, 2022
2 parents b2f09b6 + a618004 commit 745d0b5
Show file tree
Hide file tree
Showing 19 changed files with 433 additions and 171 deletions.
1 change: 1 addition & 0 deletions ethereum/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ CONDUCTOR_CHAIN_ID=0x2
# ICCO Contributor Migrations
CONTRIBUTOR_CHAIN_ID=0x2
KYC_SIGNER=0x1dF62f291b2E969fB0849d99D9Ce41e2F137006e
CONSISTENCY_LEVEL=15
1 change: 1 addition & 0 deletions ethereum/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ tilt-deploy: .env build
@if ! pgrep tilt; then echo "Error: tilt not running. Start it before running tests"; exit 1; fi
npx truffle migrate --f 2 --to 3 --network eth_devnet
sed -i 's/CONTRIBUTOR_CHAIN_ID=0x2/CONTRIBUTOR_CHAIN_ID=0x4/g' .env && npx truffle migrate --f 3 --to 3 --network eth_devnet2
rm -f .env

clean:
rm -rf ganache.log node_modules build wormhole .env
8 changes: 4 additions & 4 deletions ethereum/contracts/icco/conductor/Conductor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ contract Conductor is ConductorGovernance {
});
wormholeSequence = wormhole().publishMessage{
value : msg.value
}(0, ICCOStructs.encodeSaleInit(saleInit), 15);
}(0, ICCOStructs.encodeSaleInit(saleInit), consistencyLevel());
}

function abortSaleBeforeStartTime(uint saleId) public payable returns (uint wormholeSequence) {
Expand All @@ -139,7 +139,7 @@ contract Conductor is ConductorGovernance {
}(0, ICCOStructs.encodeSaleAborted(ICCOStructs.SaleAborted({
payloadID : 4,
saleID : saleId
})), 15);
})), consistencyLevel());
}

function collectContribution(bytes memory encodedVm) public {
Expand Down Expand Up @@ -259,7 +259,7 @@ contract Conductor is ConductorGovernance {
// attest sale success on wormhole
wormholeSequence = wormhole.publishMessage{
value : accounting.messageFee
}(0, ICCOStructs.encodeSaleSealed(saleSealed), 15);
}(0, ICCOStructs.encodeSaleSealed(saleSealed), consistencyLevel());
} else {
// set saleAborted
setSaleAborted(sale.saleID);
Expand All @@ -270,7 +270,7 @@ contract Conductor is ConductorGovernance {
}(0, ICCOStructs.encodeSaleAborted(ICCOStructs.SaleAborted({
payloadID : 4,
saleID : saleId
})), 15);
})), consistencyLevel());
}
}

Expand Down
4 changes: 4 additions & 0 deletions ethereum/contracts/icco/conductor/ConductorGetters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ contract ConductorGetters is ConductorState {
return _state.provider.chainId;
}

function consistencyLevel() public view returns (uint8) {
return _state.consistencyLevel;
}

function contributorContracts(uint16 chainId_) public view returns (bytes32){
return _state.contributorImplementations[chainId_];
}
Expand Down
14 changes: 14 additions & 0 deletions ethereum/contracts/icco/conductor/ConductorGovernance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ contract ConductorGovernance is ConductorGetters, ConductorSetters, ERC1967Upgra
emit ContractUpgraded(currentImplementation, newImplementation);
}

function updateConsistencyLevel(uint16 conductorChainId, uint8 newConsistencyLevel) public onlyOwner {
require(conductorChainId == chainId(), "wrong chain id");
require(newConsistencyLevel > 0, "newConsistencyLevel must be > 0");

setConsistencyLevel(newConsistencyLevel);
}

function transferOwnership(uint16 conductorChainId, address newOwner) public onlyOwner {
require(conductorChainId == chainId(), "wrong chain id");
require(newOwner != address(0), "new owner cannot be the zero address");

setOwner(newOwner);
}

modifier onlyOwner() {
require(owner() == _msgSender(), "caller is not the owner");
_;
Expand Down
4 changes: 4 additions & 0 deletions ethereum/contracts/icco/conductor/ConductorSetters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ contract ConductorSetters is ConductorState, Context {
_state.provider.tokenBridge = payable(tb);
}

function setConsistencyLevel(uint8 level) internal {
_state.consistencyLevel = level;
}

function setSale(uint saleId, ConductorStructs.Sale memory sale) internal {
_state.sales[saleId] = sale;
}
Expand Down
5 changes: 4 additions & 1 deletion ethereum/contracts/icco/conductor/ConductorSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ contract ConductorSetup is ConductorSetters, ERC1967Upgrade {
address implementation,
uint16 chainId,
address wormhole,
address tokenBridge
address tokenBridge,
uint8 consistencyLevel
) public {
setOwner(_msgSender());

Expand All @@ -23,6 +24,8 @@ contract ConductorSetup is ConductorSetters, ERC1967Upgrade {

setTokenBridge(tokenBridge);

setConsistencyLevel(consistencyLevel);

_upgradeTo(implementation);
}
}
2 changes: 2 additions & 0 deletions ethereum/contracts/icco/conductor/ConductorState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ contract ConductorStorage {

// contract deployer
address owner;
// # of confirmations for wormhole messages
uint8 consistencyLevel;

// Mapping of consumed governance actions
mapping(bytes32 => bool) consumedGovernanceActions;
Expand Down
26 changes: 0 additions & 26 deletions ethereum/contracts/icco/conductor/ConductorStructs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,6 @@ contract ConductorStructs {
bool refundIsClaimed;
}

struct RegisterChain {
// Governance Header
// module: "TokenSale" left-padded
bytes32 module;
// governance action: 1
uint8 action;
// governance paket chain id: this or 0
uint16 chainId;
// Chain ID
uint16 emitterChainID;
// Emitter address. Left-zero-padded if shorter than 32 bytes
bytes32 emitterAddress;
}

struct ConductorUpgrade {
// Governance Header
// module: "TokenSale" left-padded
bytes32 module;
// governance action: 2 for ConductorUpgrade
uint8 action;
// governance paket chain id
uint16 chainId;
// Address of the new contract
bytes32 newContract;
}

struct InternalAccounting {
// fees
uint256 messageFee;
Expand Down
5 changes: 2 additions & 3 deletions ethereum/contracts/icco/contributor/Contributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ contract Contributor is ContributorGovernance, ReentrancyGuard {
setSale(saleInit.saleID, sale);
}

function verifySignature(bytes memory encodedHashData, bytes memory sig) public view returns (address key) {
function verifySignature(bytes memory encodedHashData, bytes memory sig) public pure returns (address key) {
require(sig.length == 65, "incorrect signature length");
require(encodedHashData.length > 0, "no hash data");

Expand Down Expand Up @@ -162,7 +162,7 @@ contract Contributor is ContributorGovernance, ReentrancyGuard {

wormholeSequence = wormhole().publishMessage{
value : msg.value
}(0, ICCOStructs.encodeContributionsSealed(consSealed), 15);
}(0, ICCOStructs.encodeContributionsSealed(consSealed), consistencyLevel());
}

function saleSealed(bytes memory saleSealedVaa) public payable {
Expand Down Expand Up @@ -345,5 +345,4 @@ contract Contributor is ContributorGovernance, ReentrancyGuard {
function saleExists(uint saleId) public view returns (bool exists) {
exists = (getSaleTokenAddress(saleId) != bytes32(0));
}

}
4 changes: 4 additions & 0 deletions ethereum/contracts/icco/contributor/ContributorGetters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ contract ContributorGetters is ContributorState {
return ITokenBridge(payable(_state.provider.tokenBridge));
}

function consistencyLevel() public view returns (uint8) {
return _state.consistencyLevel;
}

function chainId() public view returns (uint16){
return _state.provider.chainId;
}
Expand Down
21 changes: 21 additions & 0 deletions ethereum/contracts/icco/contributor/ContributorGovernance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ contract ContributorGovernance is ContributorGetters, ContributorSetters, ERC196
require(success, string(reason));

emit ContractUpgraded(currentImplementation, newImplementation);
}

function updateConsistencyLevel(uint16 contributorChainId, uint8 newConsistencyLevel) public onlyOwner {
require(contributorChainId == chainId(), "wrong chain id");
require(newConsistencyLevel > 0, "newConsistencyLevel must be > 0");

setConsistencyLevel(newConsistencyLevel);
}

function updateAuthority(uint16 contributorChainId, address newAuthority) public onlyOwner {
require(contributorChainId == chainId(), "wrong chain id");

// allow zero address to disable kyc
setAuthority(newAuthority);
}

function transferOwnership(uint16 contributorChainId, address newOwner) public onlyOwner {
require(contributorChainId == chainId(), "wrong chain id");
require(newOwner != address(0), "new owner cannot be the zero address");

setOwner(newOwner);
}

modifier onlyOwner() {
Expand Down
4 changes: 4 additions & 0 deletions ethereum/contracts/icco/contributor/ContributorSetters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ contract ContributorSetters is ContributorState, Context {
_state.provider.tokenBridge = payable(tb);
}

function setConsistencyLevel(uint8 level) internal {
_state.consistencyLevel = level;
}

function setSale(uint saleId, ContributorStructs.Sale memory sale) internal {
_state.sales[saleId] = sale;
}
Expand Down
5 changes: 4 additions & 1 deletion ethereum/contracts/icco/contributor/ContributorSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ contract ContributorSetup is ContributorSetters, ERC1967Upgrade {
bytes32 conductorContract,
address authority,
address wormhole,
address tokenBridge
address tokenBridge,
uint8 consistencyLevel
) public {
setOwner(_msgSender());

Expand All @@ -31,6 +32,8 @@ contract ContributorSetup is ContributorSetters, ERC1967Upgrade {

setTokenBridge(tokenBridge);

setConsistencyLevel(consistencyLevel);

_upgradeTo(implementation);
}
}
2 changes: 1 addition & 1 deletion ethereum/contracts/icco/contributor/ContributorState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ contract ContributorStorage {
Provider provider;

address owner;

address authority;
uint8 consistencyLevel;

// Mapping of consumed governance actions
mapping(bytes32 => bool) consumedGovernanceActions;
Expand Down
13 changes: 0 additions & 13 deletions ethereum/contracts/icco/contributor/ContributorStructs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,4 @@ contract ContributorStructs {
uint256[] allocations;
uint256[] excessContributions;
}

struct ContributorUpgrade {
// Governance Header
// module: "TokenSale" left-padded
bytes32 module;
// governance action: 3 for ContributorUpgrade
uint8 action;
// governance paket chain id
uint16 chainId;

// Address of the new contract
bytes32 newContract;
}
}
4 changes: 3 additions & 1 deletion ethereum/migrations/2_deploy_icco_conductor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const ICCOStructs = artifacts.require("ICCOStructs");

const ethereumRootPath = `${__dirname}/..`;
const WormholeAddresses = require(`${ethereumRootPath}/wormhole-addresses.js`);
const consistencyLevel = process.env.CONSISTENCY_LEVEL;

const chainId = process.env.CONDUCTOR_CHAIN_ID;

Expand Down Expand Up @@ -38,7 +39,8 @@ module.exports = async function (deployer, network) {
ConductorImplementation.address,
chainId,
addresses.wormhole,
addresses.tokenBridge
addresses.tokenBridge,
consistencyLevel,
)
.encodeABI();

Expand Down
4 changes: 3 additions & 1 deletion ethereum/migrations/3_deploy_icco_contributor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const WormholeAddresses = require(`${ethereumRootPath}/wormhole-addresses.js`);
const chainId = process.env.CONTRIBUTOR_CHAIN_ID;
const conductorChainId = process.env.CONDUCTOR_CHAIN_ID;
const kycSigner = process.env.KYC_SIGNER;
const consistencyLevel = process.env.CONSISTENCY_LEVEL;

const fs = require("fs");

Expand Down Expand Up @@ -64,7 +65,8 @@ module.exports = async function (deployer, network) {
conductorAddress,
kycSigner,
addresses.wormhole,
addresses.tokenBridge
addresses.tokenBridge,
consistencyLevel,
)
.encodeABI();

Expand Down

0 comments on commit 745d0b5

Please sign in to comment.