Skip to content

Commit

Permalink
Wrap and deposit in a single tx (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
k1rill-fedoseev authored Jan 3, 2022
1 parent 702ad72 commit 6827304
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
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)
}
}
}
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 6827304

Please sign in to comment.