Skip to content

Commit

Permalink
fix: add natspec and shift tokenBridgeController to MintableTokenBridge
Browse files Browse the repository at this point in the history
  • Loading branch information
GitGuru7 committed Feb 27, 2024
1 parent b16e7f7 commit 63994bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 0 additions & 3 deletions contracts/Bridge/BaseTokenBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { ExponentialNoError } from "@venusprotocol/solidity-utilities/contracts/
abstract contract BaseTokenBridge is Pausable, ExponentialNoError, BaseOFTV2 {
using SafeERC20 for IERC20;
IERC20 internal immutable innerToken;

Check warning on line 24 in contracts/Bridge/BaseTokenBridge.sol

View workflow job for this annotation

GitHub Actions / Lint

Immutable variables name are set to be in capitalized SNAKE_CASE
address internal immutable tokenBridgeController;
bool public sendAndCallEnabled;
uint256 internal immutable ld2sdRate;

Check warning on line 26 in contracts/Bridge/BaseTokenBridge.sol

View workflow job for this annotation

GitHub Actions / Lint

Immutable variables name are set to be in capitalized SNAKE_CASE

Expand Down Expand Up @@ -125,7 +124,6 @@ abstract contract BaseTokenBridge is Pausable, ExponentialNoError, BaseOFTV2 {
*/
constructor(
address tokenAddress_,
address tokenBridgeController_,
uint8 sharedDecimals_,
address lzEndpoint_,
address oracle_
Expand All @@ -135,7 +133,6 @@ abstract contract BaseTokenBridge is Pausable, ExponentialNoError, BaseOFTV2 {
ensureNonzeroAddress(oracle_);

innerToken = IERC20(tokenAddress_);
tokenBridgeController = tokenBridgeController_;

(bool success, bytes memory data) = tokenAddress_.staticcall(abi.encodeWithSignature("decimals()"));
require(success, "ProxyOFT: failed to get token decimals");

Check warning on line 138 in contracts/Bridge/BaseTokenBridge.sol

View workflow job for this annotation

GitHub Actions / Lint

Use Custom Errors instead of require statements
Expand Down
16 changes: 14 additions & 2 deletions contracts/Bridge/MintableTokenBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ contract MintableTokenBridge is BaseTokenBridge {
*/
bool public immutable isForceMintActive;

/**
* @notice Address of Token Bridge Controller. It can be zero address when token can be directly accessed.
*/
address public immutable tokenBridgeController;

/**
* @notice Emits when stored message dropped without successful retrying.
*/
Expand All @@ -35,8 +40,9 @@ contract MintableTokenBridge is BaseTokenBridge {
address lzEndpoint_,
address oracle_,
bool isForceMintActive_
) BaseTokenBridge(tokenAddress_, tokenBridgeController_, sharedDecimals_, lzEndpoint_, oracle_) {
) BaseTokenBridge(tokenAddress_, sharedDecimals_, lzEndpoint_, oracle_) {
isForceMintActive = isForceMintActive_;
tokenBridgeController = tokenBridgeController_;
}

/**
Expand Down Expand Up @@ -65,6 +71,8 @@ contract MintableTokenBridge is BaseTokenBridge {
require(isForceMintActive, "ProxyOFT: Force mint of token is not allowed on this chain");

ensureNonzeroAddress(to_);

// When controller is used to interact with token
if (tokenBridgeController != address(0)) {
IMultichainToken(tokenBridgeController).mint(to_, amount_);
} else {
Expand Down Expand Up @@ -96,6 +104,8 @@ contract MintableTokenBridge is BaseTokenBridge {
) internal override whenNotPaused returns (uint256) {
require(from_ == _msgSender(), "ProxyOFT: owner is not send caller");
_isEligibleToSend(from_, dstChainId_, amount_);

// When controller is used to interact with token
if (tokenBridgeController != address(0)) {
IMultichainToken(tokenBridgeController).burn(from_, amount_);
} else {
Expand All @@ -117,6 +127,8 @@ contract MintableTokenBridge is BaseTokenBridge {
uint256 amount_
) internal override whenNotPaused returns (uint256) {
_isEligibleToReceive(toAddress_, srcChainId_, amount_);

// When controller is used to interact with token
if (tokenBridgeController != address(0)) {
IMultichainToken(tokenBridgeController).mint(toAddress_, amount_);
} else {
Expand All @@ -125,5 +137,5 @@ contract MintableTokenBridge is BaseTokenBridge {
return amount_;
}

function _transferFrom(address _from, address _to, uint _amount) internal virtual override returns (uint) {}
function _transferFrom(address from_, address to_, uint256 amount_) internal override returns (uint256) {}
}

0 comments on commit 63994bc

Please sign in to comment.