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

Snapshot integration #118

Merged
merged 1 commit into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 15 additions & 6 deletions contracts/District.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import "./RegistryEntry.sol";
import "./StakeBank.sol";
import "./proxy/Forwarder2.sol";
import "./DistrictChallenge.sol";
import "./KitDistrict.sol";
import "@aragon/os/contracts/lib/ens/ENS.sol";
import "@aragon/os/contracts/lib/ens/PublicResolver.sol";


/**
Expand All @@ -18,7 +19,7 @@ import "./KitDistrict.sol";
contract District is RegistryEntry {

StakeBank public stakeBank;
KitDistrict public constant kitDistrict = KitDistrict(0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa);
ENS public constant ens = ENS(0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa);

/**
* @dev IPFS hash of file that contains all data from form fields
Expand All @@ -33,23 +34,31 @@ contract District is RegistryEntry {
* @param _creator Creator of a district
* @param _version Version of District contract
* @param _metaHash IPFS hash of data related to a district
* @param _aragonId ENS name registered as <somename>.aragonid.eth
* @param _ensNode Namehash of the ENS name registered by the sender
* @param _ensName ENS name registered by the sender
*/
function construct(
address _creator,
uint _version,
bytes _metaHash,
string _aragonId
bytes32 _ensNode,
string _ensName
)
public
{
super.construct(_creator, _version);
// requires creator is owner of ENS domain and it does not have any linked snapshot
require(_creator == ens.owner(_ensNode));
address resolverAddr = ens.resolver(_ensNode);
if (resolverAddr != address(0x0)) {
PublicResolver resolver = PublicResolver(resolverAddr);
require(bytes(resolver.text(_ensNode, "snapshot")).length == 0);
}
stakeBank = StakeBank(new Forwarder2());
stakeBank.construct();
challengePeriodEnd = ~uint(0);
metaHash = _metaHash;
Kernel aragonDao = kitDistrict.createDAO(_aragonId, MiniMeToken(stakeBank), _creator);
registry.fireDistrictConstructedEvent(version, creator, metaHash, deposit, challengePeriodEnd, address(stakeBank), address(aragonDao), _aragonId);
registry.fireDistrictConstructedEvent(version, creator, metaHash, deposit, challengePeriodEnd, address(stakeBank), _ensName);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions contracts/DistrictFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ contract DistrictFactory is RegistryEntryFactory {
function createDistrict(
address _creator,
bytes _metaHash,
string _aragonId
bytes32 _ensNameNode,
string _ensName
)
public
notEmergency
Expand All @@ -35,7 +36,8 @@ contract DistrictFactory is RegistryEntryFactory {
_creator,
version,
_metaHash,
_aragonId
_ensNameNode,
_ensName
);
}
}
Expand Down
7 changes: 3 additions & 4 deletions contracts/Registry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract Registry is DSAuth {
event ChallengeCreatedEvent(address registryEntry, uint version, uint index, address challenger, uint commitPeriodEnd, uint revealPeriodEnd, uint rewardPool, bytes metaHash, uint timestamp);
event ChallengerRewardClaimedEvent(address registryEntry, uint version, uint index, address challenger, uint amount, uint timestamp);
event CreatorRewardClaimedEvent(address registryEntry, uint version, uint index, address creator, uint amount, uint timestamp);
event DistrictConstructedEvent(address registryEntry, uint version, address creator, bytes metaHash, uint deposit, uint challengePeriodEnd, address stakeBank, address aragonDao, string aragonId, uint timestamp);
event DistrictConstructedEvent(address registryEntry, uint version, address creator, bytes metaHash, uint deposit, uint challengePeriodEnd, address stakeBank, string ensName, uint timestamp);
event DistrictStakeChangedEvent(address registryEntry, uint version, uint stakeId, uint dntTotalStaked, uint votingTokenTotalSupply, address staker, uint stakerDntStaked, uint stakerVotingTokenBalance, uint stakedAmount, bool isUnstake, uint timestamp);
event DistrictMetaHashChangedEvent(address registryEntry, uint version, bytes metaHash, uint timestamp);
event VotesReclaimedEvent(address registryEntry, uint version, uint index, address voter, uint amount, uint timestamp);
Expand Down Expand Up @@ -155,13 +155,12 @@ contract Registry is DSAuth {
uint deposit,
uint challengePeriodEnd,
address stakeBank,
address aragonDao,
string aragonId
string ensName
)
public
onlyRegistryEntry
{
emit DistrictConstructedEvent(msg.sender, version, creator, metaHash, deposit, challengePeriodEnd, stakeBank, aragonDao, aragonId, now);
emit DistrictConstructedEvent(msg.sender, version, creator, metaHash, deposit, challengePeriodEnd, stakeBank, ensName, now);
}
function fireDistrictStakeChangedEvent(uint version, uint stakeId, uint dntTotalStaked, uint votingTokenTotalSupply, address staker, uint stakerDntStaked, uint stakerVotingTokenBalance, uint stakedAmount, bool isUnstake)
public
Expand Down
31 changes: 20 additions & 11 deletions migrations/2_district_registry_migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const {copyContract, copy, smartContractsTemplate, encodeContractEDN, linkByteco
const fs = require("fs");
const edn = require("jsedn");
const {env, smartContractsPath, parameters} = require("../truffle.js");
const {registryPlaceholder, dntPlaceholder, forwarder1TargetPlaceholder, forwarder2TargetPlaceholder, minimeTokenFactoryPlaceholder, kitDistrictPlaceholder, zeroAddress, dsGuardANY, aragonENSNode} = require("./constants.js");
const {registryPlaceholder, dntPlaceholder, forwarder1TargetPlaceholder, forwarder2TargetPlaceholder, minimeTokenFactoryPlaceholder, ensPlaceholder, zeroAddress, dsGuardANY, aragonENSNode} = require("./constants.js");
const namehash = require('eth-ens-namehash');
const web3Utils = require('web3-utils');
const sha3 = web3Utils.sha3;
Expand Down Expand Up @@ -285,13 +285,13 @@ async function deploy_District(deployer, opts) {
const districtChallenge = await DistrictChallenge.deployed();
const stakeBank = await StakeBank.deployed();
const districtRegistryForwarder = await DistrictRegistryForwarder.deployed();
const kitDistrict = await KitDistrict.deployed();
const ens = await getENS();

linkBytecode(District, dntPlaceholder, dnt.address);
linkBytecode(District, registryPlaceholder, districtRegistryForwarder.address);
linkBytecode(District, forwarder1TargetPlaceholder, districtChallenge.address);
linkBytecode(District, forwarder2TargetPlaceholder, stakeBank.address);
linkBytecode(District, kitDistrictPlaceholder, kitDistrict.address);
linkBytecode(District, ensPlaceholder, ens.address);

await deployer.deploy(District, Object.assign({}, opts, {gas: 6.2e6}));
const district = await District.deployed();
Expand Down Expand Up @@ -378,6 +378,18 @@ async function deploy_ENS(deployer, opts) {
assignContract(ens, "ENS", "ENS");
}

async function reg_ENS(name, ens, publicResolver, opts) {
var ensName = name + ".eth";
console.log("Setting active account to be owner of " + ensName);
await ens.setSubnodeOwner(namehash.hash("eth"), sha3(name), opts.from, Object.assign({}, opts, {gas: 0.2e6}));

console.log("Setting resolver for " + ensName);
await ens.setResolver(namehash.hash(ensName), publicResolver.address, Object.assign({}, opts, {gas: 0.2e6}));

console.log("Setting resolving address for " + ensName);
await publicResolver.setAddr(namehash.hash(ensName), publicResolver.address, Object.assign({}, opts, {gas: 0.3e6}));
}

async function deploy_PublicResolver(deployer, opts) {
if (!parameters.ENS) {
console.log("Deploying ENS PublicResolver");
Expand All @@ -386,14 +398,11 @@ async function deploy_PublicResolver(deployer, opts) {
await deployer.deploy(PublicResolver, ens.address, Object.assign({}, opts, {gas: 1.9e6}));
const publicResolver = await PublicResolver.deployed();

console.log("Setting active account to be owner of resolver.eth");
await ens.setSubnodeOwner(namehash.hash("eth"), sha3("resolver"), opts.from, Object.assign({}, opts, {gas: 0.2e6}));

console.log("Setting resolver for resolver.eth");
await ens.setResolver(namehash.hash("resolver.eth"), publicResolver.address, Object.assign({}, opts, {gas: 0.2e6}));

console.log("Setting resolving address for resolver.eth");
await publicResolver.setAddr(namehash.hash("resolver.eth"), publicResolver.address, Object.assign({}, opts, {gas: 0.3e6}));
reg_ENS("resolver", ens, publicResolver, opts);
// register multiple domains for testing
for (var i = 0; i< 10;i++) {
reg_ENS(i + "resolver", ens, publicResolver, opts);
}

assignContract(publicResolver, "PublicResolver", "public-resolver");
}
Expand Down
2 changes: 1 addition & 1 deletion migrations/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
forwarder1TargetPlaceholder: "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef",
forwarder2TargetPlaceholder: "feebfeebfeebfeebfeebfeebfeebfeebfeebfeeb",
minimeTokenFactoryPlaceholder: "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
kitDistrictPlaceholder: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
ensPlaceholder: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
zeroAddress: "0x0000000000000000000000000000000000000000",
dsGuardANY: "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
aragonENSNode: namehash.hash("aragonid.eth")
Expand Down
Binary file modified resources/public/css/fonts/icomoon.eot
Binary file not shown.
5 changes: 1 addition & 4 deletions resources/public/css/fonts/icomoon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/public/css/fonts/icomoon.ttf
Binary file not shown.
Binary file modified resources/public/css/fonts/icomoon.woff
Binary file not shown.
Loading