Skip to content

Commit 5e391ce

Browse files
committed
Make burnFrom() callable from non-bridge addresses
This makes it compatible with OpenZeppelin's burnFrom() if called by an address that is not a whitelisted bridge.
1 parent 104ea46 commit 5e391ce

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

contracts/pegged/tokens/MultiBridgeToken.sol

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ contract MultiBridgeToken is ERC20, Ownable {
5151
}
5252

5353
/**
54-
* @notice Burns tokens from an address. Decreases total amount minted by the calling bridge.
54+
* @notice Burns tokens from an address. Decreases total amount minted if called by a bridge.
5555
* Alternative to {burnFrom} for compatibility with some bridge implementations.
5656
* See {_burnFrom}.
5757
* @param _from The address to burn tokens from.
@@ -62,7 +62,7 @@ contract MultiBridgeToken is ERC20, Ownable {
6262
}
6363

6464
/**
65-
* @notice Burns tokens from an address. Decreases total amount minted by the calling bridge.
65+
* @notice Burns tokens from an address. Decreases total amount minted if called by a bridge.
6666
* See {_burnFrom}.
6767
* @param _from The address to burn tokens from.
6868
* @param _amount The amount to burn.
@@ -72,16 +72,18 @@ contract MultiBridgeToken is ERC20, Ownable {
7272
}
7373

7474
/**
75-
* @dev Burns tokens from an address. Decreases total amount minted by the calling bridge.
75+
* @dev Burns tokens from an address, deducting from the caller's allowance. Decreases total amount minted if called
76+
* by a bridge.
7677
* @param _from The address to burn tokens from.
7778
* @param _amount The amount to burn.
7879
*/
7980
function _burnFrom(address _from, uint256 _amount) internal returns (bool) {
8081
Supply storage b = bridges[msg.sender];
81-
require(b.cap > 0, "invalid caller");
82-
require(b.total >= _amount, "exceeds bridge minted amount");
83-
unchecked {
84-
b.total -= _amount;
82+
if (b.cap > 0 || b.total > 0) {
83+
require(b.total >= _amount, "exceeds bridge minted amount");
84+
unchecked {
85+
b.total -= _amount;
86+
}
8587
}
8688
_spendAllowance(_from, msg.sender, _amount);
8789
_burn(_from, _amount);

contracts/pegged/tokens/SingleBridgeToken.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ contract SingleBridgeToken is ERC20, Ownable {
5656
* @param _from The address to burn tokens from.
5757
* @param _amount The amount to burn.
5858
*/
59-
function burn(address _from, uint256 _amount) external onlyBridge returns (bool) {
59+
function burn(address _from, uint256 _amount) external returns (bool) {
6060
return _burnFrom(_from, _amount);
6161
}
6262

@@ -66,12 +66,12 @@ contract SingleBridgeToken is ERC20, Ownable {
6666
* @param _from The address to burn tokens from.
6767
* @param _amount The amount to burn.
6868
*/
69-
function burnFrom(address _from, uint256 _amount) external onlyBridge returns (bool) {
69+
function burnFrom(address _from, uint256 _amount) external returns (bool) {
7070
return _burnFrom(_from, _amount);
7171
}
7272

7373
/**
74-
* @dev Burns tokens from an address.
74+
* @dev Burns tokens from an address, deducting from the caller's allowance.
7575
* @param _from The address to burn tokens from.
7676
* @param _amount The amount to burn.
7777
*/

0 commit comments

Comments
 (0)