Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

fix depositBulk using mapToken #493

Merged
merged 1 commit into from
Dec 6, 2023
Merged
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
2 changes: 1 addition & 1 deletion contracts/root/depositManager/DepositManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract DepositManager is DepositManagerStorage, IDepositManager, ERC721Holder
modifier isTokenMapped(address _token) {
// new: exception for POL token
require(
registry.isTokenMapped(_token) || _token == registry.contractMap(keccak256("pol")),
registry.isTokenMapped(_token),
"TOKEN_NOT_SUPPORTED"
);
_;
Expand Down
28 changes: 28 additions & 0 deletions test/integration/root/DepositManagerUpdate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import * as artifacts from '../../helpers/artifacts.js'
import StatefulUtils from '../../helpers/StatefulUtils'
import logDecoder from '../../helpers/log-decoder'

const predicateTestUtils = require('./predicates/predicateTestUtils')
const ethUtils = require('ethereumjs-util')
Expand Down Expand Up @@ -51,6 +52,12 @@ contract('DepositManager Update @skip-on-coverage', async function(accounts) {
registry.contract.methods.updateContractMap(ethUtils.keccak256('pol'), pol.address).encodeABI()
)

// map POL token
await governance.update(
registry.address,
registry.contract.methods.mapToken(pol.address, e20.childToken.address, false).encodeABI()
)

await polygonMigrationTest.contract.methods.setTokenAddresses(e20.rootERC20.address, pol.address).send({
from: accounts[0]
})
Expand Down Expand Up @@ -119,6 +126,27 @@ contract('DepositManager Update @skip-on-coverage', async function(accounts) {
utils.assertBigNumberEquality(await e20.childToken.balanceOf(bob), amount)
})

it('depositBulk: bridges MATIC when depositing POL', async() => {
const bob = '0x' + crypto.randomBytes(20).toString('hex')
const totalAmount = amount.mul(web3.utils.toBN(2))

await pol.approve(depositManager.address, totalAmount)

const result = await depositManager.depositBulk([pol.address, pol.address], [amount, amount], bob)

const logs = logDecoder.decodeLogs(result.receipt.rawLogs)
const newDepositBlockEvent = logs.find(
log => log.event === 'NewDepositBlock'
)

// token has been changed to MATIC
assert.strictEqual(newDepositBlockEvent.args.token, e20.rootERC20.address)
await utils.fireDepositFromMainToMatic(childContracts.childChain, '0xa', bob, e20.rootERC20.address, totalAmount, newDepositBlockEvent.args.depositBlockId)

// deposit on child chain is technically still in MATIC
utils.assertBigNumberEquality(await e20.childToken.balanceOf(bob), totalAmount)
})

it('returns POL when withdrawing MATIC', async() => {
// no POL on this account
utils.assertBigNumberEquality(await pol.balanceOf(accounts[1]), 0)
Expand Down
Loading