Skip to content

Commit

Permalink
Add function burnMint in CMTAT_BASE + optimize string in EnforcementM…
Browse files Browse the repository at this point in the history
…odule
  • Loading branch information
rya-sge committed Dec 20, 2023
1 parent 9938ab1 commit a2e90a3
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 14 deletions.
16 changes: 16 additions & 0 deletions contracts/modules/CMTAT_BASE.sol
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,22 @@ abstract contract CMTAT_BASE is
return ERC20BaseModule.transferFrom(sender, recipient, amount);
}

/**
@notice burn and mint atomically
@param from current token holder to burn tokens
@param to receiver to send the new minted tokens
@param amountToBurn number of tokens to burn
@param amountToMint number of tokens to mint
@dev
- The access control is managed by the functions burn and mint
- Input validation is also managed by the functions burn and mint
- You can mint more tokens than burnt
*/
function burnAndMint(address from, address to, uint256 amountToBurn, uint256 amountToMint, string calldata reason) public {
burnWithReason(from, amountToBurn, reason);
mint(to, amountToMint);
}

/**
* @dev
*
Expand Down
1 change: 1 addition & 0 deletions contracts/modules/wrapper/core/BaseModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ abstract contract BaseModule is AuthorizationModule {
string public tokenId;
string public terms;
string public information;
// additional attribute to store information as an uint256
uint256 public flag;


Expand Down
8 changes: 5 additions & 3 deletions contracts/modules/wrapper/core/ERC20BurnModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ abstract contract ERC20BurnModule is ERC20Upgradeable, ICCIPBurnERC20, Authoriza

/**
* @notice burn with empty string as reason
* @param account token holder
* @param value amount of tokens
* @dev
* use to be compatible with CCIP pool system
* used to be compatible with CCIP pool system
*/
function burn(
address account,
Expand All @@ -50,7 +52,7 @@ abstract contract ERC20BurnModule is ERC20Upgradeable, ICCIPBurnERC20, Authoriza

/**
*
* @notice batch version of {forceBurn}.
* @notice batch version of {burn}.
* @dev
* See {ERC20-_burn} and {OpenZeppelin ERC1155_burnBatch}.
*
Expand All @@ -62,7 +64,7 @@ abstract contract ERC20BurnModule is ERC20Upgradeable, ICCIPBurnERC20, Authoriza
* - `accounts` and `values` must have the same length
* - the caller must have the `BURNER_ROLE`.
*/
function forceBurnBatch(
function burnBatch(
address[] calldata accounts,
uint256[] calldata values,
string calldata reason
Expand Down
2 changes: 2 additions & 0 deletions contracts/modules/wrapper/core/ERC20MintModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ abstract contract ERC20MintModule is ERC20Upgradeable, ICCIPMintERC20, Authoriza

/**
* @notice Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0)
* @param account token receiver
* @param value amount of tokens
* @dev
* See {OpenZeppelin ERC20-_mint}.
* Emits a {Mint} event.
Expand Down
4 changes: 2 additions & 2 deletions contracts/modules/wrapper/core/EnforcementModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ abstract contract EnforcementModule is
AuthorizationModule
{
string internal constant TEXT_TRANSFER_REJECTED_FROM_FROZEN =
"The address FROM is frozen";
"Address FROM is frozen";

string internal constant TEXT_TRANSFER_REJECTED_TO_FROZEN =
"The address TO is frozen";
"Address TO is frozen";

function __EnforcementModule_init_unchained() internal onlyInitializing {
// no variable to initialize
Expand Down
14 changes: 7 additions & 7 deletions test/common/ERC20BurnModuleCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ function ERC20BurnModuleCommon (admin, address1, address2) {
it('testCanBeBurntBatchByAdmin', async function () {
// Act
// Burn
this.logs = await this.cmtat.forceBurnBatch(
this.logs = await this.cmtat.burnBatch(
TOKEN_HOLDER,
TOKEN_BY_HOLDERS_TO_BURN,
REASON,
Expand Down Expand Up @@ -312,7 +312,7 @@ function ERC20BurnModuleCommon (admin, address1, address2) {

// Act
// Burn
this.logs = await this.cmtat.forceBurnBatch(
this.logs = await this.cmtat.burnBatch(
TOKEN_HOLDER,
TOKEN_BY_HOLDERS_TO_BURN,
REASON,
Expand Down Expand Up @@ -359,7 +359,7 @@ function ERC20BurnModuleCommon (admin, address1, address2) {
const ADDRESS2_BALANCE = await this.cmtat.balanceOf(address2)
// Act
await expectRevertCustomError(
this.cmtat.forceBurnBatch(
this.cmtat.burnBatch(
TOKEN_HOLDER,
TOKEN_BY_HOLDERS_TO_BURN_FAIL,
'',
Expand All @@ -372,7 +372,7 @@ function ERC20BurnModuleCommon (admin, address1, address2) {

it('testCannotBeBurntWithoutBurnerRole', async function () {
await expectRevertCustomError(
this.cmtat.forceBurnBatch(TOKEN_HOLDER, TOKEN_BY_HOLDERS_TO_BURN, '', {
this.cmtat.burnBatch(TOKEN_HOLDER, TOKEN_BY_HOLDERS_TO_BURN, '', {
from: address2
}),
'AccessControlUnauthorizedAccount',
Expand All @@ -384,7 +384,7 @@ function ERC20BurnModuleCommon (admin, address1, address2) {
// Number of addresses is insufficient
const TOKEN_HOLDER_INVALID = [admin, address1]
await expectRevertCustomError(
this.cmtat.forceBurnBatch(
this.cmtat.burnBatch(
TOKEN_HOLDER_INVALID,
TOKEN_BY_HOLDERS_TO_BURN,
REASON,
Expand All @@ -399,7 +399,7 @@ function ERC20BurnModuleCommon (admin, address1, address2) {
// There are too many addresses
const TOKEN_HOLDER_INVALID = [admin, address1, address1, address1]
await expectRevertCustomError(
this.cmtat.forceBurnBatch(
this.cmtat.burnBatch(
TOKEN_HOLDER_INVALID,
TOKEN_BY_HOLDERS_TO_BURN,
REASON,
Expand All @@ -413,7 +413,7 @@ function ERC20BurnModuleCommon (admin, address1, address2) {
it('testCannotBurnBatchIfAccountsIsEmpty', async function () {
const TOKEN_ADDRESS_TOS_INVALID = []
await expectRevertCustomError(
this.cmtat.forceBurnBatch(
this.cmtat.burnBatch(
TOKEN_ADDRESS_TOS_INVALID,
TOKEN_BY_HOLDERS_TO_BURN,
REASON,
Expand Down
4 changes: 2 additions & 2 deletions test/common/EnforcementModuleCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function EnforcementModuleCommon (owner, address1, address2, address3) {
await this.cmtat.detectTransferRestriction(address1, address2, 10)
).should.be.bignumber.equal('2');
(await this.cmtat.messageForTransferRestriction(2)).should.equal(
'The address FROM is frozen'
'Address FROM is frozen'
)
const AMOUNT_TO_TRANSFER = 10
await expectRevertCustomError(
Expand All @@ -168,7 +168,7 @@ function EnforcementModuleCommon (owner, address1, address2, address3) {
await this.cmtat.detectTransferRestriction(address1, address2, 10)
).should.be.bignumber.equal('3');
(await this.cmtat.messageForTransferRestriction(3)).should.equal(
'The address TO is frozen'
'Address TO is frozen'
)
const AMOUNT_TO_TRANSFER = 10
await expectRevertCustomError(
Expand Down

0 comments on commit a2e90a3

Please sign in to comment.