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

matic fork #345

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .envrc.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ export BSCSCAN_API_KEY=''
# Required for forking
export ALCHEMY_URL=''

# Required for forking Polygon (Matic)
export MATICVIGIL_URL=''

#required for mainnet governance forking testnets
export PATH_TO_GOVERNANCE_REPO=''
8 changes: 6 additions & 2 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const networks = require('./hardhat.networks')

const RNGBlockhashMatic = require('@pooltogether/pooltogether-rng-contracts/deployments/matic_137/RNGBlockhash.json')
const RNGBlockhashMainnet = require('@pooltogether/pooltogether-rng-contracts/deployments/mainnet/RNGBlockhash.json')
const RNGBlockhashRopsten = require('@pooltogether/pooltogether-rng-contracts/deployments/ropsten/RNGBlockhash.json')
const RNGBlockhashRinkeby = require('@pooltogether/pooltogether-rng-contracts/deployments/rinkeby/RNGBlockhash.json')
const RNGBlockhashKovan = require('@pooltogether/pooltogether-rng-contracts/deployments/kovan/RNGBlockhash.json')
Expand Down Expand Up @@ -58,9 +60,11 @@ const config = {
97: '0x3e8b9901dBFE766d3FE44B36c180A1bca2B9A295' //bscTestnet
},
rng: {
42: RNGBlockhashKovan.address,
1: RNGBlockhashMainnet.address,
3: RNGBlockhashRopsten.address,
4: RNGBlockhashRinkeby.address,
3: RNGBlockhashRopsten.address
42: RNGBlockhashKovan.address,
137: RNGBlockhashMatic.address
},
admin: {
42: testnetAdmin,
Expand Down
15 changes: 12 additions & 3 deletions hardhat.networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ const networks = {
allowUnlimitedContractSize: true
},
localhost: {
chainId: 1,
url: 'http://127.0.0.1:8545',
allowUnlimitedContractSize: true
}
}

if(process.env.ALCHEMY_URL && process.env.FORK_ENABLED){
if(process.env.MAINNET_FORK_ENABLED && process.env.ALCHEMY_URL) {
networks.hardhat = {
chainId: 1,
forking: {
Expand All @@ -20,8 +19,18 @@ if(process.env.ALCHEMY_URL && process.env.FORK_ENABLED){
},
accounts: {
mnemonic: process.env.HDWALLET_MNEMONIC
}
}
} else if (process.env.MATIC_FORK_ENABLED && process.env.MATICVIGIL_URL) {
networks.hardhat = {
chainId: 137,
forking: {
url: process.env.MATICVIGIL_URL,
blockNumber: 13481600
},
// allowUnlimitedContractSize: true
accounts: {
mnemonic: process.env.HDWALLET_MNEMONIC
}
}
} else {
networks.hardhat = {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"compile": "hardhat --show-stack-traces --max-memory 8192 compile",
"start": "echo 'Starting node for local testing....\n'; rm -rf deployments/localhost_31337; DISABLE_HARNESS=true hardhat node",
"start-gas": "echo 'Starting node for gas testing....\n'; rm -rf deployments/localhost_31337; DISABLE_HARNESS=true hardhat node",
"start-fork": "rm -rf deployments/localhost; cp -r deployments/mainnet deployments/localhost && FORK_ENABLED=true hardhat node --no-reset --no-deploy",
"start-fork": "rm -rf deployments/localhost; cp -r deployments/mainnet deployments/localhost && MAINNET_FORK_ENABLED=true hardhat node --no-reset --no-deploy",
"start-fork-matic": "rm -rf deployments/localhost; cp -r deployments/matic deployments/localhost && MATIC_FORK_ENABLED=true hardhat node --no-reset --no-deploy",
"redeploy-fork": "rm -rf deployments/localhost; yarn deploy localhost",
"impersonate-accounts": "hardhat run ./scripts/fork/impersonateAccounts.js --network localhost",
"stop-impersonate": "hardhat run ./scripts/fork/stopImpersonation.js --network localhost",
Expand All @@ -41,7 +42,7 @@
"dependencies": {
"@openzeppelin/contracts-upgradeable": "3.4.0",
"@pooltogether/fixed-point": "1.0.0-beta.2",
"@pooltogether/pooltogether-rng-contracts": "1.0.0",
"@pooltogether/pooltogether-rng-contracts": "1.1.2",
"@pooltogether/uniform-random-number": "1.0.0-beta.1",
"@pooltogether/yield-source-interface": "^1.0.1",
"deploy-eip-1820": "1.0.0",
Expand Down
13 changes: 13 additions & 0 deletions scripts/fork/helpers/console.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const chalk = require("chalk")

function dim() {
console.log(chalk.dim.call(chalk, ...arguments))
}

function green() {
console.log(chalk.green.call(chalk, ...arguments))
}

module.exports = {
dim, green
}
16 changes: 6 additions & 10 deletions scripts/fork/helpers/createAndRunYieldSourcePrizePool.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
const hardhat = require('hardhat')
const chalk = require("chalk")
const { dim, green } = require('./console')

const {
getPrizePoolAddressFromBuilderTransaction,
runPoolLifecycle
} = require('../helpers/runPoolLifecycle')

function dim() {
console.log(chalk.dim.call(chalk, ...arguments))
}

function green() {
console.log(chalk.green.call(chalk, ...arguments))
}

const { ethers } = hardhat

async function createAndRunYieldSourcePrizePool(signer, yieldSourceAddress) {
const { getNamedAccounts } = hardhat
const { rng } = await getNamedAccounts()
const builder = await ethers.getContract('PoolWithMultipleWinnersBuilder', signer)

dim(`Using PoolWithMultipleWinnersBuilder @ ${builder.address}`)
Expand All @@ -30,7 +24,7 @@ async function createAndRunYieldSourcePrizePool(signer, yieldSourceAddress) {
}

const multipleWinnersConfig = {
rngService: "0xb1D89477d1b505C261bab6e73f08fA834544CD21",
rngService: rng,
prizePeriodStart: block.timestamp,
prizePeriodSeconds: 1,
ticketName: "TICKET",
Expand All @@ -43,6 +37,8 @@ async function createAndRunYieldSourcePrizePool(signer, yieldSourceAddress) {
splitExternalErc20Awards: false
}

dim(`Creating prize pool...`)

const tx = await builder.createYieldSourceMultipleWinners(
yieldSourcePrizePoolConfig,
multipleWinnersConfig,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { createAndRunYieldSourcePrizePool } = require('../helpers/createAndRunYieldSourcePrizePool')
const { createAndRunYieldSourcePrizePool } = require('../../helpers/createAndRunYieldSourcePrizePool')
const hardhat = require('hardhat')
const { BUSD_HOLDER } = require('../constants')
const { ethers } = hardhat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { createAndRunYieldSourcePrizePool } = require('../helpers/createAndRunYieldSourcePrizePool')
const { createAndRunYieldSourcePrizePool } = require('../../helpers/createAndRunYieldSourcePrizePool')
const hardhat = require('hardhat')
const { GUSD_HOLDER } = require('../constants')
const { ethers } = hardhat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { createAndRunYieldSourcePrizePool } = require('../helpers/createAndRunYieldSourcePrizePool')
const { createAndRunYieldSourcePrizePool } = require('../../helpers/createAndRunYieldSourcePrizePool')
const hardhat = require('hardhat')
const { SUSD_HOLDER } = require('../constants')
const { ethers } = hardhat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { createAndRunYieldSourcePrizePool } = require('../helpers/createAndRunYieldSourcePrizePool')
const { createAndRunYieldSourcePrizePool } = require('../../helpers/createAndRunYieldSourcePrizePool')
const hardhat = require('hardhat')
const { SUSHI_HOLDER } = require('../constants')
const { ethers } = hardhat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { USDT_HOLDER } = require('../constants')
const {
getPrizePoolAddressFromBuilderTransaction,
runPoolLifecycle
} = require('../helpers/runPoolLifecycle')
} = require('../../helpers/runPoolLifecycle')

function dim() {
console.log(chalk.dim.call(chalk, ...arguments))
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions scripts/fork/matic/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const DAI_HOLDER = '0x7A61A0Ed364E599Ae4748D1EbE74bf236Dd27B09'
const MATIC_HOLDER = '0x9B39e806Da554aCa2ccdb03E6E7b37ac6369ee7D'

module.exports = {
DAI_HOLDER,
MATIC_HOLDER
}
30 changes: 30 additions & 0 deletions scripts/fork/matic/distributeMatic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const chalk = require('chalk')
const hardhat = require('hardhat')
const {
MATIC_HOLDER,
DAI_HOLDER
} = require('./constants')

async function run() {
const { ethers } = hardhat
const { provider } = ethers

const maticHolder = await provider.getUncheckedSigner(MATIC_HOLDER)

const recipients = {
['DAI Holder']: DAI_HOLDER
}

const keys = Object.keys(recipients)

for (var i = 0; i < keys.length; i++) {
const name = keys[i]
const address = recipients[name]
console.log(chalk.dim(`Sending 10 Ether to ${name}...`))
await maticHolder.sendTransaction({ to: address, value: ethers.utils.parseEther('10') })
}

console.log(chalk.green(`Done!`))
}

run()
15 changes: 15 additions & 0 deletions scripts/fork/matic/impersonateAccounts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const chalk = require('chalk')
const hre = require("hardhat")

const {
DAI_HOLDER,
MATIC_HOLDER
} = require('./constants')

async function run(){
await hre.ethers.provider.send("hardhat_impersonateAccount", ["0x0000000000000000000000000000000000000000"])
await hre.ethers.provider.send("hardhat_impersonateAccount",[DAI_HOLDER])
await hre.ethers.provider.send("hardhat_impersonateAccount",[MATIC_HOLDER])
console.log(chalk.green('Impersonated accounts'))
}
run()
15 changes: 15 additions & 0 deletions scripts/fork/matic/pools/createADAIPool.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { createAndRunYieldSourcePrizePool } = require('../../helpers/createAndRunYieldSourcePrizePool')
const hardhat = require('hardhat')
const {
DAI_HOLDER
} = require('../constants')
const { ethers } = hardhat

async function run() {
const daiHolder = await ethers.provider.getUncheckedSigner(DAI_HOLDER)
const daiYieldSourceAddress = '0x379421d1e78eb2A2245FA1E8326f794101893129'

await createAndRunYieldSourcePrizePool(daiHolder, daiYieldSourceAddress)
}

run()
35 changes: 35 additions & 0 deletions scripts/fork/matic/supplyToADAIYieldSource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const hardhat = require('hardhat')
const {
DAI_HOLDER
} = require('./constants')
const { ethers } = hardhat
const { dim, green } = require('../helpers/console')

async function run() {
const daiHolder = await ethers.provider.getUncheckedSigner(DAI_HOLDER)
const daiYieldSourceAddress = '0x379421d1e78eb2A2245FA1E8326f794101893129'

const dai = await ethers.getContractAt('IERC20Upgradeable', '0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063', daiHolder)
const daiYieldSource = await ethers.getContractAt('IYieldSource', daiYieldSourceAddress, daiHolder)

const amount = ethers.utils.parseEther('100')

dim(`Approving dai spend of ${ethers.utils.formatEther(amount)} for token at address ${dai.address}...`)

await dai.approve(daiYieldSource.address, amount)

dim(`Supply token to yield source...`)

dim(`Checking token...`)

let token = await daiYieldSource.depositToken()

green(`Deposit token is ${token}`)

await daiYieldSource.supplyTokenTo(amount, daiHolder._address)

green(`Done!`)

}

run()
2 changes: 0 additions & 2 deletions scripts/setup_fork.sh

This file was deleted.

2 changes: 2 additions & 0 deletions scripts/setup_mainnet_fork.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
yarn fork-run scripts/fork/mainnet/impersonateAccounts.js
yarn fork-run scripts/fork/mainnet/distributeEtherFromBinance.js
2 changes: 2 additions & 0 deletions scripts/setup_matic_fork.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
yarn fork-run scripts/fork/matic/impersonateAccounts.js
yarn fork-run scripts/fork/matic/distributeMatic.js
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -734,10 +734,10 @@
resolved "https://registry.yarnpkg.com/@pooltogether/fixed-point/-/fixed-point-1.0.0-beta.2.tgz#d76a1e77f21833e9b680296d65526b0ffd7415d7"
integrity sha512-aUw4R0Z2oM0AK3W4LIXyBaojTOzRRbhLDHX0egeuvxfjy4gBb6X66v81gI7Wngg/7O0y9QL/B8jWkUnAFzhTig==

"@pooltogether/pooltogether-rng-contracts@1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@pooltogether/pooltogether-rng-contracts/-/pooltogether-rng-contracts-1.0.0.tgz#191d155dc960559cce06b7ec3b0f9ed2caed0f46"
integrity sha512-jQub/+qPLQwTFtbBCvvyIEqxJDEBEV/hgLKnuocBg2/GySWtHLz67WCy17bNn1hZw8nWIt8Ih8h+7iT2UJhtmQ==
"@pooltogether/pooltogether-rng-contracts@1.1.2":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@pooltogether/pooltogether-rng-contracts/-/pooltogether-rng-contracts-1.1.2.tgz#75e148d9dff9bd5b5bbe6bdd95c7a7a446b316b7"
integrity sha512-7S1qzpPdS/8SRfb3dXdQdiZllPFkOIYf7YYK3+aw+vH4/93T6lvkTu4/+ZAuNH+XbliipLYtTmrhy0YjDoFZRg==

"@pooltogether/[email protected]":
version "1.0.0-beta.1"
Expand Down