Skip to content

Commit

Permalink
Remove half duplex erc20 token code (#457)
Browse files Browse the repository at this point in the history
  • Loading branch information
patitonar committed Jul 29, 2020
1 parent 67e536f commit dd46135
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 298 deletions.
14 changes: 0 additions & 14 deletions contracts/interfaces/IScdMcdMigration.sol

This file was deleted.

15 changes: 0 additions & 15 deletions contracts/mocks/ForeignBridgeErcToNativeMock.sol
Expand Up @@ -3,21 +3,6 @@ pragma solidity 0.4.24;
import "../upgradeable_contracts/erc20_to_native/ForeignBridgeErcToNative.sol";

contract ForeignBridgeErcToNativeMock is ForeignBridgeErcToNative {
function migrationContract() internal pure returns (IScdMcdMigration) {
// Address generated in unit test
return IScdMcdMigration(0x44Bf5539DAAc4259f7F11A24280255ED2Fa3F7BF);
}

function halfDuplexErc20token() public pure returns (ERC20) {
// Address generated in unit test
return ERC20(0x872D709De609c391741c7595F0053F6060e59e0D);
}

function saiTopContract() internal pure returns (ISaiTop) {
// Address generated in unit test
return ISaiTop(0x96bc48adACdB60E6536E55a6727919a397F14540);
}

bytes32 internal constant CHAI_TOKEN_MOCK = 0x5d6f4e61a116947624416975e8d26d4aff8f32e21ea6308dfa35cee98ed41fd8; // keccak256(abi.encodePacked("chaiTokenMock"))

function setChaiToken(IChai _chaiToken) external {
Expand Down
9 changes: 0 additions & 9 deletions contracts/mocks/SaiTopMock.sol

This file was deleted.

24 changes: 0 additions & 24 deletions contracts/mocks/ScdMcdMigrationMock.sol

This file was deleted.

Expand Up @@ -3,14 +3,9 @@ pragma solidity 0.4.24;
import "../BasicForeignBridge.sol";
import "../ERC20Bridge.sol";
import "../OtherSideBridgeStorage.sol";
import "../../interfaces/IScdMcdMigration.sol";
import "../ChaiConnector.sol";

contract ForeignBridgeErcToNative is BasicForeignBridge, ERC20Bridge, OtherSideBridgeStorage, ChaiConnector {
bytes32 internal constant MIN_HDTOKEN_BALANCE = 0x48649cf195feb695632309f41e61252b09f537943654bde13eb7bb1bca06964e; // keccak256(abi.encodePacked("minHDTokenBalance"))
bytes32 internal constant LOCKED_SAI_FIXED = 0xbeb8b2ece34b32b36c9cc00744143b61b2c23f93adcc3ce78d38937229423051; // keccak256(abi.encodePacked("lockedSaiFixed"))
bytes4 internal constant SWAP_TOKENS = 0x73d00224; // swapTokens()

function initialize(
address _validatorContract,
address _erc20token,
Expand Down Expand Up @@ -60,23 +55,10 @@ contract ForeignBridgeErcToNative is BasicForeignBridge, ERC20Bridge, OtherSideB
return 0x18762d46; // bytes4(keccak256(abi.encodePacked("erc-to-native-core")))
}

function fixLockedSai(address _receiver) external {
require(msg.sender == address(this));
require(!boolStorage[LOCKED_SAI_FIXED]);
boolStorage[LOCKED_SAI_FIXED] = true;
setInvestedAmountInDai(investedAmountInDai() + 49938645266079271041);
claimValues(halfDuplexErc20token(), _receiver);
}

function claimTokens(address _token, address _to) public {
require(_token != address(erc20token()));
// Chai token is not claimable if investing into Chai is enabled
require(_token != address(chaiToken()) || !isChaiTokenEnabled());
if (_token == address(halfDuplexErc20token())) {
// SCD is not claimable if the bridge accepts deposits of this token
// solhint-disable-next-line not-rely-on-time
require(!isTokenSwapAllowed(now));
}
super.claimTokens(_token, _to);
}

Expand All @@ -100,75 +82,17 @@ contract ForeignBridgeErcToNative is BasicForeignBridge, ERC20Bridge, OtherSideB

bool res = erc20token().transfer(_recipient, amount);

if (tokenBalance(halfDuplexErc20token()) > 0) {
address(this).call(abi.encodeWithSelector(SWAP_TOKENS));
}

return res;
}

function onFailedMessage(address, uint256, bytes32) internal {
revert();
}

function saiTopContract() internal pure returns (ISaiTop) {
return ISaiTop(0x9b0ccf7C8994E19F39b2B4CF708e0A7DF65fA8a3);
}

function isTokenSwapAllowed(
uint256 /* _ts */
) public pure returns (bool) {
return false;
}

function halfDuplexErc20token() public pure returns (ERC20) {
return ERC20(0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359);
}

function setMinHDTokenBalance(uint256 _minBalance) external onlyOwner {
uintStorage[MIN_HDTOKEN_BALANCE] = _minBalance;
}

function minHDTokenBalance() public view returns (uint256) {
return uintStorage[MIN_HDTOKEN_BALANCE];
}

function isHDTokenBalanceAboveMinBalance() public view returns (bool) {
if (tokenBalance(halfDuplexErc20token()) > minHDTokenBalance()) {
return true;
}
return false;
}

function tokenBalance(ERC20 _token) internal view returns (uint256) {
return _token.balanceOf(address(this));
}

function migrationContract() internal pure returns (IScdMcdMigration) {
return IScdMcdMigration(0xc73e0383F3Aff3215E6f04B0331D58CeCf0Ab849);
}

function swapTokens() public {
// solhint-disable-next-line not-rely-on-time
require(isTokenSwapAllowed(now));

IScdMcdMigration mcdMigrationContract = migrationContract();
ERC20 hdToken = halfDuplexErc20token();
ERC20 fdToken = erc20token();

uint256 curHDTokenBalance = tokenBalance(hdToken);
require(curHDTokenBalance > 0);

uint256 curFDTokenBalance = tokenBalance(fdToken);

require(hdToken.approve(mcdMigrationContract, curHDTokenBalance));
mcdMigrationContract.swapSaiToDai(curHDTokenBalance);

require(tokenBalance(fdToken).sub(curFDTokenBalance) == curHDTokenBalance);

emit TokensSwapped(hdToken, fdToken, curHDTokenBalance);
}

function relayTokens(address _receiver, uint256 _amount) external {
_relayTokens(msg.sender, _receiver, _amount, erc20token());
}
Expand All @@ -194,23 +118,19 @@ contract ForeignBridgeErcToNative is BasicForeignBridge, ERC20Bridge, OtherSideB
require(withinLimit(_amount));

ERC20 tokenToOperate = ERC20(_token);
ERC20 hdToken = halfDuplexErc20token();
ERC20 fdToken = erc20token();

if (tokenToOperate == ERC20(0x0)) {
tokenToOperate = fdToken;
}

require(tokenToOperate == fdToken || tokenToOperate == hdToken);
require(tokenToOperate == fdToken);

setTotalSpentPerDay(getCurrentDay(), totalSpentPerDay(getCurrentDay()).add(_amount));

tokenToOperate.transferFrom(_sender, address(this), _amount);
emit UserRequestForAffirmation(_receiver, _amount);

if (tokenToOperate == hdToken) {
swapTokens();
}
if (isDaiNeedsToBeInvested()) {
convertDaiToChai();
}
Expand Down

0 comments on commit dd46135

Please sign in to comment.