-
Notifications
You must be signed in to change notification settings - Fork 16
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
feat: make token manager the minter for interchain tokens #313
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -334,7 +334,7 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M | |
if (!token.isMinter(minter)) revert NotMinter(minter); | ||
|
||
// Sanity check to prevent accidental use of the current ITS address as the token minter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update DESIGN.md for this behaviour change |
||
if (minter == address(interchainTokenService)) revert InvalidMinter(minter); | ||
if (minter == interchainTokenService.tokenManagerAddress(tokenId)) revert InvalidMinter(minter); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
pragma solidity ^0.8.0; | ||
|
||
import { IInterchainToken } from '../interfaces/IInterchainToken.sol'; | ||
import { IInterchainTokenService } from '../interfaces/IInterchainTokenService.sol'; | ||
|
||
import { InterchainTokenStandard } from './InterchainTokenStandard.sol'; | ||
import { ERC20Permit } from './ERC20Permit.sol'; | ||
|
@@ -97,7 +98,7 @@ contract InterchainToken is InterchainTokenStandard, ERC20Permit, Minter, IInter | |
* Also add the provided address as a minter. If `address(0)` was provided, | ||
* add it as a minter to allow anyone to easily check that no custom minter was set. | ||
*/ | ||
_addMinter(interchainTokenService_); | ||
_addMinter(IInterchainTokenService(interchainTokenService_).tokenManagerAddress(tokenId_)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. feels like a weird re-entrancy to call ITS back during deployment. better to pass in the token manager, or have ITS call |
||
_addMinter(minter); | ||
|
||
_setNameHash(tokenName); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,10 @@ const { | |
} = ethers; | ||
const { expect } = require('chai'); | ||
const { getRandomBytes32, expectRevert, getChainId } = require('./utils'); | ||
const { deployContract } = require('../scripts/deploy'); | ||
const { deployAll } = require('../scripts/deploy'); | ||
|
||
describe('ERC20 Permit', () => { | ||
let interchainToken, interchainTokenDeployer; | ||
let interchainTokenDeployer; | ||
|
||
const name = 'tokenName'; | ||
const symbol = 'tokenSymbol'; | ||
|
@@ -27,9 +27,7 @@ describe('ERC20 Permit', () => { | |
owner = wallets[0]; | ||
user = wallets[1]; | ||
|
||
interchainToken = await deployContract(owner, 'InterchainToken', [owner.address]); | ||
interchainTokenDeployer = await deployContract(owner, 'InterchainTokenDeployer', [interchainToken.address]); | ||
|
||
({ interchainTokenDeployer } = await deployAll(owner, 'Test')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you make the previous suggested change, then you don't need to deploy all contracts for this to work |
||
const salt = getRandomBytes32(); | ||
const tokenId = getRandomBytes32(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,13 @@ | |
const chai = require('chai'); | ||
const { ethers } = require('hardhat'); | ||
const { | ||
Wallet, | ||
getContractAt, | ||
constants: { AddressZero }, | ||
} = ethers; | ||
const { time } = require('@nomicfoundation/hardhat-network-helpers'); | ||
const { expect } = chai; | ||
const { getRandomBytes32, expectRevert, isHardhat, waitFor } = require('./utils'); | ||
const { deployContract } = require('../scripts/deploy'); | ||
const { deployContract, deployAll } = require('../scripts/deploy'); | ||
|
||
let ownerWallet, otherWallet; | ||
|
||
|
@@ -257,16 +256,15 @@ describe('FlowLimit', async () => { | |
}); | ||
|
||
describe('InterchainTokenDeployer', () => { | ||
let interchainToken, interchainTokenDeployer; | ||
const service = new Wallet(getRandomBytes32()).address; | ||
let interchainTokenDeployer; | ||
let service; | ||
const name = 'tokenName'; | ||
const symbol = 'tokenSymbol'; | ||
const decimals = 18; | ||
const MINTER_ROLE = 0; | ||
|
||
before(async () => { | ||
interchainToken = await deployContract(ownerWallet, 'InterchainToken', [service]); | ||
interchainTokenDeployer = await deployContract(ownerWallet, 'InterchainTokenDeployer', [interchainToken.address]); | ||
({ interchainTokenDeployer, service } = await deployAll(ownerWallet, 'Test')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
}); | ||
|
||
it('Should revert on deployment with invalid implementation address', async () => { | ||
|
@@ -283,20 +281,21 @@ describe('InterchainTokenDeployer', () => { | |
const tokenAddress = await interchainTokenDeployer.deployedAddress(salt); | ||
|
||
const token = await getContractAt('InterchainToken', tokenAddress, ownerWallet); | ||
const tokenManager = await service.tokenManagerAddress(tokenId); | ||
|
||
await expect(interchainTokenDeployer.deployInterchainToken(salt, tokenId, ownerWallet.address, name, symbol, decimals)) | ||
.to.emit(token, 'RolesAdded') | ||
.withArgs(service, 1 << MINTER_ROLE) | ||
.withArgs(tokenManager, 1 << MINTER_ROLE) | ||
.and.to.emit(token, 'RolesAdded') | ||
.withArgs(ownerWallet.address, 1 << MINTER_ROLE); | ||
|
||
expect(await token.name()).to.equal(name); | ||
expect(await token.symbol()).to.equal(symbol); | ||
expect(await token.decimals()).to.equal(decimals); | ||
expect(await token.hasRole(service, MINTER_ROLE)).to.be.true; | ||
expect(await token.hasRole(tokenManager, MINTER_ROLE)).to.be.true; | ||
expect(await token.hasRole(ownerWallet.address, MINTER_ROLE)).to.be.true; | ||
expect(await token.interchainTokenId()).to.equal(tokenId); | ||
expect(await token.interchainTokenService()).to.equal(service); | ||
expect(await token.interchainTokenService()).to.equal(service.address); | ||
|
||
await expectRevert( | ||
(gasOptions) => | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add changeset and briefly discuss the behaviour change reason