Skip to content

Commit

Permalink
dump changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pintoinfant committed Sep 12, 2023
1 parent 0f60dc6 commit 2232aa9
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 45 deletions.
37 changes: 22 additions & 15 deletions app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@ const app = express();
const port = 3000;

// Initialize your Ethereum provider (e.g., Infura)
const provider = new ethers.providers.JsonRpcProvider('https://polygon-mumbai-bor.publicnode.com');
const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545');
// const provider = new ethers.providers.JsonRpcProvider('https://polygon-mumbai-bor.publicnode.com');


const client = new MongoClient(process.env.MONGO_URI as string);
const db = client.db('tcr')
const db = client.db('netspan')

// const tokenContractAddress = '0xA388d56F953Eb6D61eee909692E382D6401Ccb44';
// const tcrContractAddress = '0x7048802ad7CE3F52035dE87a4Fe85fA1c6632902';
// const timeLockContractAddress = '0xfdDCbc3Bb1E96f8a970dF64C09393179FD50ab73';
// const governorContractAddress = '0xAE7D442940BE4D830ec02fe4007E3DE9F24AFED3';

const tokenContractAddress = '0xA388d56F953Eb6D61eee909692E382D6401Ccb44';
const tcrContractAddress = '0x7048802ad7CE3F52035dE87a4Fe85fA1c6632902';
const timeLockContractAddress = '0xfdDCbc3Bb1E96f8a970dF64C09393179FD50ab73';
const governorContractAddress = '0xAE7D442940BE4D830ec02fe4007E3DE9F24AFED3';
const tokenContractAddress = '0x5FbDB2315678afecb367f032d93F642f64180aa3';
const tcrContractAddress = '0x8A791620dd6260079BF849Dc5567aDC3F2FdC318';
const timeLockContractAddress = '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9';
const governorContractAddress = '0x5FC8d32690cc91D4c39d9d3abcBD16989F875707';

// Connect to the contract
const tokenContract = new ethers.Contract(tokenContractAddress, tokenContractABI.abi, provider);
Expand All @@ -33,28 +40,28 @@ const governorContract = new ethers.Contract(governorContractAddress, governorCo
// const eventName = 'Transfer'; // Replace with the actual event name

// Start listening to the event
tokenContract.on('*', (event) => {
tokenContract.on('*', async (event) => {
// console.log('Event emitted:');
db.collection('events').insertOne(event)
console.log(event); // Log the event data
await db.collection('tcr-registry').insertOne({ ...event, chainId: 31337 })
});

tcrContract.on('*', (event) => {
tcrContract.on('*', async (event) => {
// console.log('Event emitted:');
db.collection('events').insertOne(event)
console.log(event); // Log the event data
console.log({ ...event, chainId: 31337 }); // Log the event data
await db.collection('tcr-registry').insertOne({ ...event, chainId: 31337 })
});

timeLockContract.on('*', (event) => {
timeLockContract.on('*', async (event) => {
// console.log('Event emitted:');
db.collection('events').insertOne(event)
console.log(event); // Log the event data
await db.collection('tcr-registry').insertOne({ ...event, chainId: 31337 })
});

governorContract.on('*', (event) => {
governorContract.on('*', async (event) => {
// console.log('Event emitted:');
db.collection('events').insertOne(event)
console.log(event); // Log the event data
await db.collection('tcr-registry').insertOne({ ...event, chainId: 31337 })
});

// Start the Express.js server
Expand Down
30 changes: 24 additions & 6 deletions contracts/governance_standard/GovernorContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,33 @@ contract NetSpanGovernor is
GovernorVotesQuorumFraction,
GovernorTimelockControl
{
constructor(IVotes _token, TimelockController _timelock)
Governor("NetSpanGovernor")
// constructor(IVotes _token, TimelockController _timelock, uint256 _votingDelay, uint256 _votingPeriod, uint256 gigi_qurorumFraction)
// Governor("NetSpanGovernor")
// GovernorSettings(
// 300, /* 1 hour */
// 21600, /* 3 days */
// 0
// )
// GovernorVotes(_token)
// GovernorVotesQuorumFraction(4)
// GovernorTimelockControl(_timelock)
// {}

constructor(
IVotes _token,
TimelockController _timelock,
uint256 _quorumPercentage,
uint256 _votingPeriod,
uint256 _votingDelay
)
Governor("GovernorContract")
GovernorSettings(
300, /* 1 hour */
21600, /* 3 days */
0
_votingDelay, /* 1 block */ // voting delay
_votingPeriod, // 45818, /* 1 week */ // voting period
0 // proposal threshold
)
GovernorVotes(_token)
GovernorVotesQuorumFraction(4)
GovernorVotesQuorumFraction(_quorumPercentage)
GovernorTimelockControl(_timelock)
{}

Expand Down
4 changes: 2 additions & 2 deletions deploy/01-deploy-governor-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const deployGovernanceToken: DeployFunction = async function (hre: HardhatRuntim
const { deployer, alpha, beta, charlie, delta, echo } = await getNamedAccounts();
log("----------------------------------------------------")
log("Deploying GovernanceToken and waiting for confirmations...")
const governanceToken = await deploy("TCRToken", {
const governanceToken = await deploy("NetSpanToken", {
from: deployer,
args: [],
log: true,
Expand All @@ -22,7 +22,7 @@ const deployGovernanceToken: DeployFunction = async function (hre: HardhatRuntim

log("----------------------------------------------------")
log('Minting 5000 TCRToken to deployer...')
const mintTx = await ethers.getContractAt('TCRToken', governanceToken.address)
const mintTx = await ethers.getContractAt('NetSpanToken', governanceToken.address)
mintTx.addNewDAOMember(deployer, 5000)
log('Minted 5000 TCRToken to deployer...')

Expand Down
7 changes: 2 additions & 5 deletions deploy/03-deploy-governor-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,16 @@ const deployGovernorContract: DeployFunction = async function (hre: HardhatRunti
const { getNamedAccounts, deployments, network } = hre
const { deploy, log, get } = deployments
const { deployer, alpha, beta, charlie, delta, echo } = await getNamedAccounts();
const governanceToken = await get("TCRToken")
const governanceToken = await get("NetSpanToken")
const timeLock = await get("TimeLock")
const args = [
governanceToken.address,
timeLock.address,
QUORUM_PERCENTAGE,
VOTING_PERIOD,
VOTING_DELAY,
]

log("----------------------------------------------------")
log("Deploying GovernorContract and waiting for confirmations...")
const governorContract = await deploy("GovernorContract", {
const governorContract = await deploy("NetSpanGovernor", {
from: deployer,
args,
log: true,
Expand Down
2 changes: 1 addition & 1 deletion deploy/04-setup-governance-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const setupContracts: DeployFunction = async function (hre: HardhatRuntimeEnviro
const { deployer, alpha, beta, charlie, delta, echo } = await getNamedAccounts();

const timeLock = await ethers.getContract("TimeLock", deployer)
const governor = await ethers.getContract("GovernorContract", deployer)
const governor = await ethers.getContract("NetSpanGovernor", deployer)

log("----------------------------------------------------")
log("Setting up contracts for roles...")
Expand Down
6 changes: 3 additions & 3 deletions deploy/05-deploy-box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ const deployRegistry: DeployFunction = async function (hre: HardhatRuntimeEnviro
const { getNamedAccounts, deployments, network } = hre
const { deploy, log, get } = deployments
const { deployer } = await getNamedAccounts()
const governorContract = await get("GovernorContract")
const governorContract = await get("NetSpanGovernor")
log("----------------------------------------------------")
log("Deploying TCR Registry and waiting for confirmations...")

const tcrRegistry = await deploy("PLMN", {
const tcrRegistry = await deploy("TCR", {
from: deployer,
args: [governorContract.address],
log: true,
})


log(`TCR Registry at ${tcrRegistry.address}`)
const tcrRegistryContract = await ethers.getContractAt("PLMN", tcrRegistry.address)
const tcrRegistryContract = await ethers.getContractAt("TCR", tcrRegistry.address)
const timeLock = await ethers.getContract("TimeLock")
const transferTx = await tcrRegistryContract.transferOwnership(timeLock.address)
await transferTx.wait(1)
Expand Down
8 changes: 4 additions & 4 deletions helper-hardhat-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ export const developmentChains = ["hardhat", "localhost"]
export const proposalsFile = "proposals.json"

// Governor Values
export const QUORUM_PERCENTAGE = 4 // Need 4% of voters to pass
export const MIN_DELAY = 3600 // 1 hour - after a vote passes, you have 1 hour before you can enact
export const QUORUM_PERCENTAGE = 1 // Need 4% of voters to pass
export const MIN_DELAY = 120 // 1 hour - after a vote passes, you have 1 hour before you can enact
// export const VOTING_PERIOD = 45818 // 1 week - how long the vote lasts. This is pretty long even for local tests
export const VOTING_PERIOD = 5 // blocks
export const VOTING_DELAY = 1 // 1 Block - How many blocks till a proposal vote becomes active
export const ADDRESS_ZERO = "0x0000000000000000000000000000000000000000"

export const PLMN = 9046//ethers.utils.ParamType.from({ name: "plmn", type: "uint256"})
export const REGION = 'TN' //ethers.utils.ParamType.from({ name: "region", type: "string" })
export const PLMN = 9048//ethers.utils.ParamType.from({ name: "plmn", type: "uint256"})
export const REGION = 'AP' //ethers.utils.ParamType.from({ name: "region", type: "string" })
export const NAME = 'Jio' //ethers.utils.ParamType.from({ name: "name", type: "string" })
export const FUNC = "createEntry"
export const PROPOSAL_DESCRIPTION = `Proposal to allocate ${PLMN} MNC code to ${NAME} in ${REGION} region.`
13 changes: 9 additions & 4 deletions scripts/addMember.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { ethers, network } from "hardhat"

export async function addMembers() {
const tokenContract = await ethers.getContract("TCRToken")
const tokenContract = await ethers.getContract("NetSpanToken")
// const memberTx = await tokenContract.balanceOf(
// '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266')
// // await memberTx.waitForDeployment(1)

// console.log(`Member balance : ${memberTx}`)

const memberTx = await tokenContract.addNewDAOMember(
'0x8626f6940e2eb28930efb4cef49b2d1f2c9c1199',
'0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
1000
)
await memberTx.wait(1)

console.log(`Member added`)
console.log(`Member added : ${memberTx}`)
}


Expand Down
4 changes: 2 additions & 2 deletions scripts/propose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import * as fs from "fs"
import { moveBlocks } from "../utils/move-blocks"

export async function propose(args: any[], functionToCall: string, proposalDescription: string) {
const governor = await ethers.getContract("GovernorContract")
const registry = await ethers.getContract("PLMN")
const governor = await ethers.getContract("NetSpanGovernor")
const registry = await ethers.getContract("TCR")
const encodedFunctionCall = registry.interface.encodeFunctionData(functionToCall, args)
console.log(`Proposing ${functionToCall} on ${registry.address} with ${args}`)
console.log(`Proposal Description:\n ${proposalDescription}`)
Expand Down
4 changes: 2 additions & 2 deletions scripts/queue-and-execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import { moveTime } from "../utils/move-time"
export async function queueAndExecute() {
const args = [PLMN, REGION, NAME]
const functionToCall = FUNC
const registry = await ethers.getContract("PLMN")
const registry = await ethers.getContract("TCR")
const encodedFunctionCall = registry.interface.encodeFunctionData(functionToCall, args)
const descriptionHash = ethers.utils.keccak256(ethers.utils.toUtf8Bytes(PROPOSAL_DESCRIPTION))
// could also use ethers.utils.id(PROPOSAL_DESCRIPTION)

const governor = await ethers.getContract("GovernorContract")
const governor = await ethers.getContract("NetSpanGovernor")
console.log("Queueing...")
const queueTx = await governor.queue([registry.address], [0], [encodedFunctionCall], descriptionHash)
await queueTx.wait(1)
Expand Down
2 changes: 1 addition & 1 deletion scripts/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function main() {
// 0 = Against, 1 = For, 2 = Abstain for this example
export async function vote(proposalId: string, voteWay: number, reason: string) {
console.log("Voting...")
const governor = await ethers.getContract("GovernorContract")
const governor = await ethers.getContract("NetSpanGovernor")
const voteTx = await governor.castVoteWithReason(proposalId, voteWay, reason)
const voteTxReceipt = await voteTx.wait(1)
console.log(voteTxReceipt.events[0].args.reason)
Expand Down

0 comments on commit 2232aa9

Please sign in to comment.