Skip to content

Commit

Permalink
Merge the develop branch to the master branch, preparation to v1.2.0
Browse files Browse the repository at this point in the history
This update for the `master` branch contains the following changes:
  * [Deposit-script, Improvement] Wrap and deposit in a single tx (#18)
  * [Contracts, other] Security audit report for 1.2.0-rc0 by ChainSecurity (#20)
  * [Contracts, other] Bump package version prior to 1.2.0 (#21)
  • Loading branch information
akolotov authored Jan 17, 2022
2 parents 702ad72 + 8161931 commit c7217fc
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
Binary file not shown.
11 changes: 9 additions & 2 deletions migrations/1_deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require('dotenv').config()
const SBCDepositContractProxy = artifacts.require('SBCDepositContractProxy')
const SBCToken = artifacts.require('SBCToken')
const SBCTokenProxy = artifacts.require('SBCTokenProxy')
const SBCWrapper = artifacts.require('SBCWrapper')
const SBCWrapperProxy = artifacts.require('SBCWrapperProxy')

module.exports = async function (deployer, network, accounts) {
Expand All @@ -22,13 +23,19 @@ module.exports = async function (deployer, network, accounts) {
const depositContractProxy = await SBCDepositContractProxy.deployed()

// deploy token wrapper
await deployer.deploy(SBCWrapperProxy, admin, token.address, depositContractProxy.address)
const wrapper = await SBCWrapperProxy.deployed()
await deployer.deploy(SBCWrapperProxy, accounts[0], token.address, depositContractProxy.address)
const wrapperProxy = await SBCWrapperProxy.deployed()
const wrapper = await SBCWrapper.at(wrapperProxy.address)

// set token minter to deployed wrapper
await token.setMinter(wrapper.address)
if (accounts[0].toLowerCase() !== admin.toLowerCase()) {
await tokenProxy.setAdmin(admin)
}

await wrapper.enableToken(process.env.STAKE_TOKEN_ADDRESS, web3.utils.toWei('32'))
if (accounts[0].toLowerCase() !== admin.toLowerCase()) {
await wrapperProxy.setAdmin(admin)
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deposit-contract",
"version": "1.0.0",
"version": "1.2.0",
"description": "Gnosis Chain official deposit contract",
"main": "index.js",
"repository": "https://github.com/gnosischain/deposit-contract",
Expand Down
12 changes: 9 additions & 3 deletions scripts/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ N=256
# index of the first deposit to read from file
OFFSET=0

# address of the wrapped GBC token
TOKEN_ADDRESS=0x722fc4DAABFEaff81b97894fC623f91814a1BF68
# address of the wrapped mGNO token, leave this option only if you want to deposit wrapped mGNO tokens
META_TOKEN_ADDRESS=0x722fc4DAABFEaff81b97894fC623f91814a1BF68
# specify these options only if you want to deposit unwrapped GNO tokens
# address of the GNO token
# TOKEN_ADDRESS=0x9C58BAcC331c9aa871AFD802DB6379a98e80CEdb
# address of the GBC wrapper contract
# WRAPPER_ADDRESS=0x647507A70Ff598F386CB96ae5046486389368C66

# address of the GBC deposit contract
DEPOSIT_CONTRACT_ADDRESS=0x0B98057eA310F4d31F2a452B414647007d1645d9
# block where the deposit contract was deployed at
START_BLOCK_NUMBER=19469077
START_BLOCK_NUMBER=19469077
22 changes: 17 additions & 5 deletions scripts/deposit.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ const {
BATCH_SIZE,
N,
OFFSET,
TOKEN_ADDRESS,
DEPOSIT_CONTRACT_ADDRESS,
START_BLOCK_NUMBER,
SKIP_PREVIOUS_DEPOSITS_CHECK,
WRAPPER_ADDRESS,
TOKEN_ADDRESS,
META_TOKEN_ADDRESS,
DEPOSIT_CONTRACT_ADDRESS,
} = process.env

const web3 = new Web3(RPC_URL)
Expand All @@ -25,8 +27,18 @@ const batchSize = parseInt(BATCH_SIZE, 10)
const offset = parseInt(OFFSET, 10)
const n = parseInt(N, 10)
async function main() {
const token = new web3.eth.Contract(abi, TOKEN_ADDRESS)
const useMetaTokenDeposit = !!META_TOKEN_ADDRESS && !WRAPPER_ADDRESS && !TOKEN_ADDRESS
const useWrapAndDeposit = !META_TOKEN_ADDRESS && !!WRAPPER_ADDRESS && !!TOKEN_ADDRESS
if (useMetaTokenDeposit === useWrapAndDeposit) {
console.log('Specify either a single META_TOKEN_ADDRESS variable for depositing mGNO directly, ' +
'or specify both WRAPPER_ADDRESS and TOKEN_ADDRESS variables for depositing GNO without manual mGNO conversion.')
return
}

const depositContract = new web3.eth.Contract(depositABI, DEPOSIT_CONTRACT_ADDRESS)
const receiver = useWrapAndDeposit ? WRAPPER_ADDRESS : DEPOSIT_CONTRACT_ADDRESS
const tokenAddress = useWrapAndDeposit ? TOKEN_ADDRESS : META_TOKEN_ADDRESS
const token = new web3.eth.Contract(abi, tokenAddress)
const deposits = depositData.slice(offset, offset + n)

if (batchSize > 1) {
Expand All @@ -45,7 +57,7 @@ async function main() {
return
}

const depositAmountBN = web3.utils.toBN(32).mul(web3.utils.toBN('1000000000000000000'))
const depositAmountBN = web3.utils.toBN(useWrapAndDeposit ? 1 : 32).mul(web3.utils.toBN('1000000000000000000'))
const totalDepositAmountBN = depositAmountBN.muln(deposits.length)
const tokenBalance = await token.methods.balanceOf(address).call()

Expand Down Expand Up @@ -88,7 +100,7 @@ async function main() {

if (count === batchSize || i === deposits.length - 1) {
const amount = depositAmountBN.muln(count)
const call = token.methods.transferAndCall(DEPOSIT_CONTRACT_ADDRESS, amount, data)
const call = token.methods.transferAndCall(receiver, amount, data)
let gas
try {
gas = await call.estimateGas({ from: address })
Expand Down

0 comments on commit c7217fc

Please sign in to comment.