-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
155 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
ETHERSCAN_API_KEY=ABC123ABC123ABC123ABC123ABC123ABC1 | ||
ROPSTEN_URL=https://eth-ropsten.alchemyapi.io/v2/<YOUR ALCHEMY KEY> | ||
PRIVATE_KEY=0xabc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc1 | ||
ETHERSCAN_API_KEY=ABC123ABC123ABC123ABC123ABC123ABC1 | ||
RINKEBY_URL=https://eth-rinkeby.alchemyapi.io/v2/<YOUR ALCHEMY KEY> | ||
PRIVATE_KEY=0xabc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
# Code4rena contracts | ||
|
||
|
||
# Scripts | ||
|
||
## Proposing transfers | ||
|
||
```bash | ||
# fill out example file for your network | ||
cp .env.example .env | ||
# create a batch transfers JSON file | ||
# propose it | ||
yarn hardhat propose --network polygon --json scripts/proposals/example.json | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[ | ||
{ | ||
"token": "0xc1D2300f0065FC076c36F6D414a31A2949ca3027", | ||
"transfers": [ | ||
{ | ||
"to": "0x0f4Aeb1847B7F1a735f4a5Af7E8C299b793c1a9A", | ||
"amount": "1000000000000000000" | ||
}, | ||
{ | ||
"to": "0x3Ab0029e1C4515134464b267557cB80A39902699", | ||
"amount": "2000000000000000000" | ||
}, | ||
{ | ||
"to": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", | ||
"amount": "3000000000000000000" | ||
}, | ||
{ | ||
"to": "0x0000000000000000000000000000000000000000", | ||
"amount": "4000000000000000000" | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import {ethers, Signer} from 'ethers'; | ||
import fs from 'fs'; | ||
import {task} from 'hardhat/config'; | ||
import path from 'path'; | ||
import _ from 'lodash'; | ||
import {ArenaGovernor__factory, ArenaToken__factory} from '../../typechain'; | ||
import {allConfigs} from '../config'; | ||
|
||
let transferInterface = new ethers.utils.Interface([`function transfer(address to, uint256 amount)`]); | ||
const getContracts = (signer: Signer, config: typeof allConfigs[0]) => { | ||
const deploymentFilePath = path.join(`deployments`, config.EXPORT_FILENAME); | ||
if (!fs.existsSync(deploymentFilePath)) throw new Error(`File '${path.resolve(deploymentFilePath)}' does not exist.`); | ||
|
||
const contents = fs.readFileSync(deploymentFilePath, `utf8`); | ||
let governorAddress; | ||
let arenaAddress; | ||
try { | ||
({ governor: governorAddress, token: arenaAddress } = JSON.parse(contents)); | ||
} catch (error) { | ||
throw new Error(`Cannot parse deployment config at '${path.resolve(deploymentFilePath)}'.`); | ||
} | ||
if (!governorAddress) throw new Error(`Deployment file did not include governor address '${deploymentFilePath}'.`); | ||
if (!arenaAddress) throw new Error(`Deployment file did not include arena token address '${deploymentFilePath}'.`); | ||
|
||
return { governor: ArenaGovernor__factory.connect(governorAddress, signer), arenaToken: ArenaToken__factory.connect(arenaAddress, signer) }; | ||
}; | ||
|
||
type BatchTransfer = { | ||
token: string; | ||
transfers: Array<{to: string; amount: string}>; | ||
}; | ||
const getTransfers = (transferPath: string) => { | ||
if (!fs.existsSync(transferPath)) throw new Error(`File '${path.resolve(transferPath)}' does not exist.`); | ||
|
||
const contents = fs.readFileSync(transferPath, `utf8`); | ||
let json; | ||
try { | ||
json = JSON.parse(contents); | ||
} catch (error) { | ||
throw new Error(`Cannot parse transfer JSON file at '${path.resolve(transferPath)}'.`); | ||
} | ||
if (!Array.isArray(json)) throw new Error(`Transfer file must be an array of batch transfers`); | ||
|
||
return json as BatchTransfer[]; | ||
}; | ||
|
||
const toProposalPayload = (batchTransfer: BatchTransfer) => { | ||
return batchTransfer.transfers.map((transfer) => ({ | ||
target: batchTransfer.token, | ||
calldata: transferInterface.encodeFunctionData(`transfer`, [transfer.to, transfer.amount]), | ||
value: `0`, | ||
})); | ||
}; | ||
|
||
task('propose', 'propose transfer') | ||
.addOptionalParam('json', 'The path to batch transfer JSON file', `transfers.json`) | ||
.setAction(async ({json}, hre) => { | ||
const networkId = hre.network.config.chainId as number; | ||
const [proposer] = await hre.ethers.getSigners(); | ||
const proposerAddress = await proposer.getAddress(); | ||
let config = allConfigs[networkId]; | ||
if (!config) throw new Error(`Unknown network ${hre.network.name} (${networkId})`); | ||
|
||
const batchTransfers = _.flattenDeep(getTransfers(json).map(toProposalPayload)); | ||
const targets = batchTransfers.map(({target}) => target); | ||
const values = batchTransfers.map(({value}) => value); | ||
const calldatas = batchTransfers.map(({calldata}) => calldata); | ||
|
||
const { governor, arenaToken } = getContracts(proposer, config); | ||
console.log(`Proposer: ${proposerAddress}`); | ||
console.log(`Governor: ${governor.address}`); | ||
console.log(`Proposal Threshold: ${await governor.proposalThreshold()}`); | ||
console.log(`Proposer Votes: ${await arenaToken.getVotes(proposerAddress)}`); | ||
|
||
console.log(JSON.stringify(targets)); | ||
console.log(JSON.stringify(calldatas)); | ||
|
||
const tx = await governor['propose(address[],uint256[],bytes[],string)']( | ||
targets, | ||
values, | ||
calldatas, | ||
`Distribute tokens for contest #Test` | ||
); | ||
console.log(`proposal submitted: ${tx.hash}`); | ||
console.log(`waiting for block inclusion ...`); | ||
await tx.wait(1) | ||
// TODO: query the transaction for the ProposalCreated event so we can get the proposalId | ||
|
||
console.log(`transaction included - proposal created!`); | ||
process.exit(0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters