Skip to content

Commit

Permalink
Add burnFrom for compatibility with CCIP and bridge, rename forceBurn…
Browse files Browse the repository at this point in the history
… in burn
  • Loading branch information
rya-sge committed Dec 21, 2023
1 parent a2e90a3 commit 283b1c7
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 144 deletions.
4 changes: 2 additions & 2 deletions contracts/interfaces/ICCIPToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ interface ICCIPMintERC20 {
function mint(address account, uint256 value) external;
}

interface ICCIPBurnERC20 {
interface ICCIPBurnFromERC20 {
/// @notice Burns tokens from a given address..
/// @param account The address to burn tokens from.
/// @param value The number of tokens to be burned.
/// @dev this function decreases the total supply.
function burn(address account, uint256 value) external;
function burnFrom(address account, uint256 value) external;

}
4 changes: 2 additions & 2 deletions contracts/modules/CMTAT_BASE.sol
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ abstract contract CMTAT_BASE is
@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
- The access control is managed by the functions burn (ERC20BurnModule) and mint (ERC20MintModule)
- 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);
burn(from, amountToBurn, reason);
mint(to, amountToMint);
}

Expand Down
1 change: 1 addition & 0 deletions contracts/modules/security/AuthorizationModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ abstract contract AuthorizationModule is AccessControlUpgradeable {
event AuthorizationEngine(IAuthorizationEngine indexed newAuthorizationEngine);
// BurnModule
bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");
bytes32 public constant BURNER_FROM_ROLE = keccak256("BURNER_FROM_ROLE");
// CreditEvents
bytes32 public constant DEBT_CREDIT_EVENT_ROLE =
keccak256("DEBT_CREDIT_EVENT_ROLE");
Expand Down
1 change: 1 addition & 0 deletions contracts/modules/wrapper/core/ERC20BaseModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ abstract contract ERC20BaseModule is ERC20Upgradeable {
/* Events */
/**
* @notice Emitted when the specified `spender` spends the specified `value` tokens owned by the specified `owner` reducing the corresponding allowance.
* @dev The allowance can be also "spend" with the function BurnFrom, but in this case, the emitted event is BurnFrom.
*/
event Spend(address indexed owner, address indexed spender, uint256 value);

Expand Down
61 changes: 43 additions & 18 deletions contracts/modules/wrapper/core/ERC20BurnModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import "../../../../openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC
import "../../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
import "../../security/AuthorizationModule.sol";
import "../../../interfaces/ICCIPToken.sol";
abstract contract ERC20BurnModule is ERC20Upgradeable, ICCIPBurnERC20, AuthorizationModule {
abstract contract ERC20BurnModule is ERC20Upgradeable, ICCIPBurnFromERC20, AuthorizationModule {
/**
* @notice Emitted when the specified `value` amount of tokens owned by `owner`are destroyed with the given `reason`
*/
event Burn(address indexed owner, uint256 value, string reason);

/**
* @notice Emitted when the specified `spender` burns the specified `value` tokens owned by the specified `owner` reducing the corresponding allowance.
*/
event BurnFrom(address indexed owner, address indexed spender, uint256 value);
function __ERC20BurnModule_init_unchained() internal onlyInitializing {
// no variable to initialize
}
Expand All @@ -25,7 +28,7 @@ abstract contract ERC20BurnModule is ERC20Upgradeable, ICCIPBurnERC20, Authoriza
* Requirements:
* - the caller must have the `BURNER_ROLE`.
*/
function burnWithReason(
function burn(
address account,
uint256 value,
string calldata reason
Expand All @@ -34,21 +37,6 @@ abstract contract ERC20BurnModule is ERC20Upgradeable, ICCIPBurnERC20, Authoriza
emit Burn(account, value, reason);
}

/**
* @notice burn with empty string as reason
* @param account token holder
* @param value amount of tokens
* @dev
* used to be compatible with CCIP pool system
*/
function burn(
address account,
uint256 value
) public onlyRole(BURNER_ROLE) {
_burn(account, value);
emit Burn(account, value, "");
}


/**
*
Expand Down Expand Up @@ -87,5 +75,42 @@ abstract contract ERC20BurnModule is ERC20Upgradeable, ICCIPBurnERC20, Authoriza
}
}

/**
* @notice Destroys `amount` tokens from `account`, deducting from the caller's
* allowance.
* @dev
* Can be used to authorize a bridge (e.g. CCIP) to burn token owned by the bridge
* No string parameter reason to be compatible with Bridge, e.g. CCIP
*
* See {ERC20-_burn} and {ERC20-allowance}.
*
* Requirements:
*
* - the caller must have allowance for ``accounts``'s tokens of at least
* `value`.
*/
function burnFrom(address account, uint256 value)
public
onlyRole(BURNER_FROM_ROLE)
{
// Allowance check
address sender = _msgSender();
uint256 currentAllowance = allowance(account, sender);
if(currentAllowance < value){
// ERC-6093
revert ERC20InsufficientAllowance(sender, currentAllowance, value);
}
// Update allowance
unchecked {
_approve(account, sender, currentAllowance - value);
}
// burn
_burn(account, value);
// We also emit a burn event since its a burn operation
emit Burn(account, value, "burnFrom");
// Specific event for the operation
emit BurnFrom(account, sender, value);
}

uint256[50] private __gap;
}
54 changes: 27 additions & 27 deletions contracts/modules/wrapper/extensions/DebtModule/DebtBaseModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ abstract contract DebtBaseModule is
// no variable to initialize
}

/*
@notice Set all attributes of debt
The values of all attributes will be changed even if the new values are the same as the current ones
/**
* @notice Set all attributes of debt
* The values of all attributes will be changed even if the new values are the same as the current ones
*/
function setDebt(DebtBase calldata debt_) public onlyRole(DEBT_ROLE) {
debt = debt_;
Expand Down Expand Up @@ -96,8 +96,8 @@ abstract contract DebtBaseModule is
emit CouponFrequency(debt_.couponFrequency, debt_.couponFrequency);
}

/*
@notice The call will be reverted if the new value of interestRate is the same as the current one
/**
* @notice The call will be reverted if the new value of interestRate is the same as the current one
*/
function setInterestRate(uint256 interestRate_) public onlyRole(DEBT_ROLE) {
if (interestRate_ == debt.interestRate) {
Expand All @@ -107,8 +107,8 @@ abstract contract DebtBaseModule is
emit InterestRate(interestRate_);
}

/*
@notice The call will be reverted if the new value of parValue is the same as the current one
/**
* @notice The call will be reverted if the new value of parValue is the same as the current one
*/
function setParValue(uint256 parValue_) public onlyRole(DEBT_ROLE) {
if (parValue_ == debt.parValue) {
Expand All @@ -118,8 +118,8 @@ abstract contract DebtBaseModule is
emit ParValue(parValue_);
}

/*
@notice The Guarantor will be changed even if the new value is the same as the current one
/**
* @notice The Guarantor will be changed even if the new value is the same as the current one
*/
function setGuarantor(
string calldata guarantor_
Expand All @@ -128,8 +128,8 @@ abstract contract DebtBaseModule is
emit Guarantor(guarantor_, guarantor_);
}

/*
@notice The bonHolder will be changed even if the new value is the same as the current one
/**
* @notice The bonHolder will be changed even if the new value is the same as the current one
*/
function setBondHolder(
string calldata bondHolder_
Expand All @@ -138,8 +138,8 @@ abstract contract DebtBaseModule is
emit BondHolder(bondHolder_, bondHolder_);
}

/*
@notice The maturityDate will be changed even if the new value is the same as the current one
/**
* @notice The maturityDate will be changed even if the new value is the same as the current one
*/
function setMaturityDate(
string calldata maturityDate_
Expand All @@ -148,8 +148,8 @@ abstract contract DebtBaseModule is
emit MaturityDate(maturityDate_, maturityDate_);
}

/*
@notice The interestScheduleFormat will be changed even if the new value is the same as the current one
/**
* @notice The interestScheduleFormat will be changed even if the new value is the same as the current one
*/
function setInterestScheduleFormat(
string calldata interestScheduleFormat_
Expand All @@ -161,8 +161,8 @@ abstract contract DebtBaseModule is
);
}

/*
@notice The interestPaymentDate will be changed even if the new value is the same as the current one
/**
* @notice The interestPaymentDate will be changed even if the new value is the same as the current one
*/
function setInterestPaymentDate(
string calldata interestPaymentDate_
Expand All @@ -171,8 +171,8 @@ abstract contract DebtBaseModule is
emit InterestPaymentDate(interestPaymentDate_, interestPaymentDate_);
}

/*
@notice The dayCountConvention will be changed even if the new value is the same as the current one
/**
* @notice The dayCountConvention will be changed even if the new value is the same as the current one
*/
function setDayCountConvention(
string calldata dayCountConvention_
Expand All @@ -181,8 +181,8 @@ abstract contract DebtBaseModule is
emit DayCountConvention(dayCountConvention_, dayCountConvention_);
}

/*
@notice The businessDayConvention will be changed even if the new value is the same as the current one
/**
* @notice The businessDayConvention will be changed even if the new value is the same as the current one
*/
function setBusinessDayConvention(
string calldata businessDayConvention_
Expand All @@ -194,8 +194,8 @@ abstract contract DebtBaseModule is
);
}

/*
@notice The publicHolidayCalendar will be changed even if the new value is the same as the current one
/**
* @notice The publicHolidayCalendar will be changed even if the new value is the same as the current one
*/
function setPublicHolidaysCalendar(
string calldata publicHolidaysCalendar_
Expand All @@ -207,8 +207,8 @@ abstract contract DebtBaseModule is
);
}

/*
@notice The issuanceDate will be changed even if the new value is the same as the current one
/**
* @notice The issuanceDate will be changed even if the new value is the same as the current one
*/
function setIssuanceDate(
string calldata issuanceDate_
Expand All @@ -217,8 +217,8 @@ abstract contract DebtBaseModule is
emit IssuanceDate(issuanceDate_, issuanceDate_);
}

/*
@notice The couponFrequency will be changed even if the new value is the same as the current one
/**
* @notice The couponFrequency will be changed even if the new value is the same as the current one
*/
function setCouponFrequency(
string calldata couponFrequency_
Expand Down
Loading

0 comments on commit 283b1c7

Please sign in to comment.