Allow minting of STAKE tokens on the Foreign side of the Omnibridge (#568)

This commit is contained in:
Kirill Fedoseev 2020-12-20 03:20:55 +03:00 committed by GitHub
parent 4d77c5d0b7
commit 11d5ec35ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 30 additions and 4 deletions

View File

@ -56,8 +56,7 @@ contract ForeignMultiAMBErc20ToErc677 is BasicMultiAMBErc20ToErc677 {
*/
function executeActionOnBridgedTokens(address _token, address _recipient, uint256 _value) internal {
bytes32 _messageId = messageId();
_token.safeTransfer(_recipient, _value);
_setMediatorBalance(_token, mediatorBalance(_token).sub(_value));
_releaseTokens(_token, _recipient, _value);
emit TokensBridged(_token, _recipient, _value, _messageId);
}
@ -191,8 +190,7 @@ contract ForeignMultiAMBErc20ToErc677 is BasicMultiAMBErc20ToErc677 {
* @param _value amount of tokens to be received.
*/
function executeActionOnFixedTokens(address _token, address _recipient, uint256 _value) internal {
_setMediatorBalance(_token, mediatorBalance(_token).sub(_value));
_token.safeTransfer(_recipient, _value);
_releaseTokens(_token, _recipient, _value);
}
/**
@ -267,4 +265,32 @@ contract ForeignMultiAMBErc20ToErc677 is BasicMultiAMBErc20ToErc677 {
function _setTokenRegistrationMessageId(address _token, bytes32 _messageId) internal {
uintStorage[keccak256(abi.encodePacked("tokenRegistrationMessageId", _token))] = uint256(_messageId);
}
/**
* Internal function for unlocking some amount of tokens.
* In case of bridging STAKE token, the insufficient amount of tokens can be additionally minted.
*/
function _releaseTokens(address _token, address _recipient, uint256 _value) internal {
// It is necessary to use mediatorBalance(STAKE) instead of STAKE.balanceOf(this) to disallow user
// withdraw mistakenly locked funds (via regular transfer()) instead of minting new tokens.
// It should be possible to process mistakenly locked funds by calling fixMediatorBalance.
uint256 balance = mediatorBalance(_token);
// STAKE total supply on xDai can be higher than the native STAKE supply on Mainnet
// Omnibridge is allowed to mint extra native STAKE tokens.
if (_token == address(0x0Ae055097C6d159879521C384F1D2123D1f195e6) && balance < _value) {
// if all locked tokens were already withdrawn, mint new tokens directly to receiver
// mediatorBalance(STAKE) remains 0 in this case.
if (balance == 0) {
IBurnableMintableERC677Token(_token).mint(_recipient, _value);
return;
}
// otherwise, mint insufficient tokens to the contract
IBurnableMintableERC677Token(_token).mint(address(this), _value - balance);
balance = _value;
}
_token.safeTransfer(_recipient, _value);
_setMediatorBalance(_token, balance.sub(_value));
}
}