Forkchoice Ethereum Mainnet

Address Contract Partially Verified

Address 0xD37BbE5744D730a1d98d8DC97c42F0Ca46aD7146
Balance 0 ETH
Nonce 1
Code Size 5141 bytes
Indexed Transactions 0 (1 on-chain, 1.7% indexed)
External Etherscan · Sourcify

Contract Bytecode

5141 bytes
Copy Bytecode
0x60806040526004361061007b5760003560e01c80634039fd4b1161004e5780634039fd4b1461012157806344bc937b14610134578063574da7171461014757806393e4eaa91461015a57600080fd5b806303b6a673146100805780631b738b32146100d95780631fece7b4146100fb5780632923e82e1461010e575b600080fd5b34801561008c57600080fd5b506100c661009b366004610da0565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6040519081526020015b60405180910390f35b3480156100e557600080fd5b506100f96100f4366004610eb9565b610192565b005b6100f9610109366004610f38565b610248565b6100f961011c366004610fa4565b61049c565b6100f961012f366004610eb9565b610620565b6100f96101423660046110b7565b6107ac565b6100f9610155366004610f38565b61080e565b34801561016657600080fd5b5060005461017a906001600160a01b031681565b6040516001600160a01b0390911681526020016100d0565b60028054036101bc5760405162461bcd60e51b81526004016101b39061112b565b60405180910390fd5b60028055306001600160a01b0386160361022f576101db8484846109fd565b836001600160a01b0316336001600160a01b03167f05b90458f953d3fcb2d7fb25616a2fddeca749d0c47cc5c9832d0266b5346eea858585604051610222939291906111be565b60405180910390a361023c565b61023c8585858585610a76565b50506001600255505050565b60028054036102695760405162461bcd60e51b81526004016101b39061112b565b6002805560006001600160a01b0384166102b9575060405134906000906001600160a01b0387169083156108fc0290849084818181858888f193505050509050806102b357600080fd5b50610443565b34156103075760405162461bcd60e51b815260206004820181905260248201527f54484f52436861696e5f526f757465723a20756e65787065637465642065746860448201526064016101b3565b6000546001600160a01b03908116908516036103f757506000546040516302ccb1b360e41b81523060048201526024810184905283916001600160a01b031690632ccb1b30906044016020604051808303816000875af115801561036f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061039391906111ee565b50600054604051630852cd8d60e31b8152600481018590526001600160a01b03909116906342966c6890602401600060405180830381600087803b1580156103da57600080fd5b505af11580156103ee573d6000803e3d6000fd5b50505050610443565b6104018484610bc7565b6001600160a01b03808716600090815260016020908152604080832093891683529290529081208054929350839290919061043d90849061122d565b90915550505b836001600160a01b0316856001600160a01b03167fef519b7eb82aaf6ac376a6df2d793843ebfd593de5f1a0601d3cc6ab49ebb3958385604051610488929190611245565b60405180910390a350506001600255505050565b60028054036104bd5760405162461bcd60e51b81526004016101b39061112b565b60028055306001600160a01b038516036105875760005b825181101561053457610522848483815181106104f3576104f3611266565b60200260200101516000015185848151811061051157610511611266565b6020026020010151602001516109fd565b8061052c8161127c565b9150506104d4565b50826001600160a01b0316336001600160a01b03167f281daef48d91e5cd3d32db0784f6af69cd8d8d2e8c612a3568dca51ded51e08f848460405161057a929190611295565b60405180910390a36105ee565b60005b82518110156105ec576105da85858584815181106105aa576105aa611266565b6020026020010151600001518685815181106105c8576105c8611266565b60200260200101516020015186610a76565b806105e48161127c565b91505061058a565b505b6040516000906001600160a01b038516903480156108fc029184818181858888f1935050505090508061023c57600080fd5b60028054036106415760405162461bcd60e51b81526004016101b39061112b565b600280556040516001600160a01b0385811660248301528481166044830152606482018490523491600091881690839060840160408051601f198184030181529181526020820180516001600160e01b0316631230c53d60e21b179052516106a99190611300565b60006040518083038185875af1925050503d80600081146106e6576040519150601f19603f3d011682016040523d82523d6000602084013e6106eb565b606091505b5050905080610753576040516000906001600160a01b0387169084156108fc0290859084818181858888f1935050505090508061075157604051339084156108fc029085906000818181858888f1935050505015801561074f573d6000803e3d6000fd5b505b505b336001600160a01b03167f8e5841bcd195b858d53b38bcf91b38d47f3bc800469b6812d35451ab619c6f6c8884898989896040516107969695949392919061131c565b60405180910390a2505060016002555050505050565b8042106107fb5760405162461bcd60e51b815260206004820152601960248201527f54484f52436861696e5f526f757465723a20657870697265640000000000000060448201526064016101b3565b61080785858585610248565b5050505050565b600280540361082f5760405162461bcd60e51b81526004016101b39061112b565b6002805560006001600160a01b0384166108a9575060405134906000906001600160a01b0387169083156108fc0290849084818181858888f193505050509050806108a357604051339083156108fc029084906000818181858888f193505050501580156108a1573d6000803e3d6000fd5b505b506109b6565b3360009081526001602090815260408083206001600160a01b0388168452909152812080548592906108dc90849061136a565b90915550506040516001600160a01b03868116602483015260448201859052600091829187169060640160408051601f198184030181529181526020820180516001600160e01b031663a9059cbb60e01b1790525161093b9190611300565b6000604051808303816000865af19150503d8060008114610978576040519150601f19603f3d011682016040523d82523d6000602084013e61097d565b606091505b50915091508180156109a75750805115806109a75750808060200190518101906109a791906111ee565b6109b057600080fd5b84925050505b846001600160a01b0316336001600160a01b03167fa9cd03aa3c1b4515114539cd53d22085129d495cb9e9f9af77864526240f1bf7868486604051610488939291906111be565b3360009081526001602090815260408083206001600160a01b038616845290915281208054839290610a3090849061136a565b90915550506001600160a01b03808416600090815260016020908152604080832093861683529290529081208054839290610a6c90849061122d565b9091555050505050565b3360009081526001602090815260408083206001600160a01b038716845290915281208054849290610aa990849061136a565b90915550506040516001600160a01b038681166024830152604482018490526000919085169060640160408051601f198184030181529181526020820180516001600160e01b031663095ea7b360e01b17905251610b079190611300565b6000604051808303816000865af19150503d8060008114610b44576040519150601f19603f3d011682016040523d82523d6000602084013e610b49565b606091505b5050905080610b5757600080fd5b6040516344bc937b60e01b81526001600160a01b038716906344bc937b90610b8d90889088908890889060001990600401611381565b600060405180830381600087803b158015610ba757600080fd5b505af1158015610bbb573d6000803e3d6000fd5b50505050505050505050565b6040516370a0823160e01b815230600482015260009081906001600160a01b038516906370a0823190602401602060405180830381865afa158015610c10573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c3491906113c6565b6040513360248201523060448201526064810185905290915060009081906001600160a01b0387169060840160408051601f198184030181529181526020820180516001600160e01b03166323b872dd60e01b17905251610c959190611300565b6000604051808303816000865af19150503d8060008114610cd2576040519150601f19603f3d011682016040523d82523d6000602084013e610cd7565b606091505b5091509150818015610d01575080511580610d01575080806020019051810190610d0191906111ee565b610d0a57600080fd5b6040516370a0823160e01b815230600482015283906001600160a01b038816906370a0823190602401602060405180830381865afa158015610d50573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d7491906113c6565b610d7e919061136a565b9695505050505050565b6001600160a01b0381168114610d9d57600080fd5b50565b60008060408385031215610db357600080fd5b8235610dbe81610d88565b91506020830135610dce81610d88565b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b6040805190810167ffffffffffffffff81118282101715610e1257610e12610dd9565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715610e4157610e41610dd9565b604052919050565b600082601f830112610e5a57600080fd5b813567ffffffffffffffff811115610e7457610e74610dd9565b610e87601f8201601f1916602001610e18565b818152846020838601011115610e9c57600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080600060a08688031215610ed157600080fd5b8535610edc81610d88565b94506020860135610eec81610d88565b93506040860135610efc81610d88565b925060608601359150608086013567ffffffffffffffff811115610f1f57600080fd5b610f2b88828901610e49565b9150509295509295909350565b60008060008060808587031215610f4e57600080fd5b8435610f5981610d88565b93506020850135610f6981610d88565b925060408501359150606085013567ffffffffffffffff811115610f8c57600080fd5b610f9887828801610e49565b91505092959194509250565b60008060008060808587031215610fba57600080fd5b8435610fc581610d88565b9350602085810135610fd681610d88565b935060408681013567ffffffffffffffff80821115610ff457600080fd5b818901915089601f83011261100857600080fd5b81358181111561101a5761101a610dd9565b611028858260051b01610e18565b81815260069190911b8301850190858101908c83111561104757600080fd5b938601935b828510156110905785858e0312156110645760008081fd5b61106c610def565b853561107781610d88565b815285880135888201528252938501939086019061104c565b9750505060608901359350808411156110a857600080fd5b505050610f9887828801610e49565b600080600080600060a086880312156110cf57600080fd5b85356110da81610d88565b945060208601356110ea81610d88565b935060408601359250606086013567ffffffffffffffff81111561110d57600080fd5b61111988828901610e49565b95989497509295608001359392505050565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b60005b8381101561117d578181015183820152602001611165565b8381111561118c576000848401525b50505050565b600081518084526111aa816020860160208601611162565b601f01601f19169290920160200192915050565b60018060a01b03841681528260208201526060604082015260006111e56060830184611192565b95945050505050565b60006020828403121561120057600080fd5b8151801515811461121057600080fd5b9392505050565b634e487b7160e01b600052601160045260246000fd5b6000821982111561124057611240611217565b500190565b82815260406020820152600061125e6040830184611192565b949350505050565b634e487b7160e01b600052603260045260246000fd5b60006001820161128e5761128e611217565b5060010190565b60408082528351828201819052600091906020906060850190828801855b828110156112e157815180516001600160a01b031685528501518585015292850192908401906001016112b3565b505050848103828601526112f58187611192565b979650505050505050565b60008251611312818460208701611162565b9190910192915050565b6001600160a01b038781168252602082018790528581166040830152841660608201526080810183905260c060a0820181905260009061135e90830184611192565b98975050505050505050565b60008282101561137c5761137c611217565b500390565b6001600160a01b038681168252851660208201526040810184905260a0606082018190526000906113b490830185611192565b90508260808301529695505050505050565b6000602082840312156113d857600080fd5b505191905056fea26469706673582212202cfe991af8d38fa2ac1704297d010d8644417c5713ec84f255506fc12400514d64736f6c634300080d0033

Verified Source Code Partial Match

Compiler: v0.8.13+commit.abaa5c0e EVM: london Optimization: Yes (200 runs)
THORChain_Router.sol 187 lines
// SPDX-License-Identifier: MIT
// -------------------
// Router Version: 4.1
// -------------------
pragma solidity 0.8.13;

// ERC20 Interface
interface iERC20 {
    function balanceOf(address) external view returns (uint256);
    function burn(uint) external;
}
// RUNE Interface
interface iRUNE {
    function transferTo(address, uint) external returns (bool);
}
// ROUTER Interface
interface iROUTER {
    function depositWithExpiry(address, address, uint, string calldata, uint) external;
}

// THORChain_Router is managed by THORChain Vaults
contract THORChain_Router {
    address public RUNE;

    struct Coin {
        address asset;
        uint amount;
    }

    // Vault allowance for each asset
    mapping(address => mapping(address => uint)) private _vaultAllowance;

    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;
    uint256 private _status;

    // Emitted for all deposits, the memo distinguishes for swap, add, remove, donate etc
    event Deposit(address indexed to, address indexed asset, uint amount, string memo);

    // Emitted for all outgoing transfers, the vault dictates who sent it, memo used to track.
    event TransferOut(address indexed vault, address indexed to, address asset, uint amount, string memo);

    // Emitted for all outgoing transferAndCalls, the vault dictates who sent it, memo used to track.
    event TransferOutAndCall(address indexed vault, address target, uint amount, address finalAsset, address to, uint256 amountOutMin, string memo);

    // Changes the spend allowance between vaults
    event TransferAllowance(address indexed oldVault, address indexed newVault, address asset, uint amount, string memo);

    // Specifically used to batch send the entire vault assets
    event VaultTransfer(address indexed oldVault, address indexed newVault, Coin[] coins, string memo);

    modifier nonReentrant() {
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
        _status = _ENTERED;
        _;
        _status = _NOT_ENTERED;
    }

    constructor(address rune) {
        RUNE = rune;
        _status = _NOT_ENTERED;
    }

    // Deposit with Expiry (preferred)
    function depositWithExpiry(address payable vault, address asset, uint amount, string memory memo, uint expiration) external payable {
        require(block.timestamp < expiration, "THORChain_Router: expired");
        deposit(vault, asset, amount, memo);
    }

    // Deposit an asset with a memo. ETH is forwarded, ERC-20 stays in ROUTER
    function deposit(address payable vault, address asset, uint amount, string memory memo) public payable nonReentrant{
        uint safeAmount;
        if(asset == address(0)){
            safeAmount = msg.value;
            bool success = vault.send(safeAmount);
            require(success);
        } else {
            require(msg.value == 0, "THORChain_Router: unexpected eth");  // protect user from accidentally locking up eth
            if(asset == RUNE) {
                safeAmount = amount;
                iRUNE(RUNE).transferTo(address(this), amount);
                iERC20(RUNE).burn(amount);
            } else {
                safeAmount = safeTransferFrom(asset, amount); // Transfer asset
                _vaultAllowance[vault][asset] += safeAmount; // Credit to chosen vault
            }
        }
        emit Deposit(vault, asset, safeAmount, memo);
    }

    //############################## ALLOWANCE TRANSFERS ##############################

    // Use for "moving" assets between vaults (asgard<>ygg), as well "churning" to a new Asgard
    function transferAllowance(address router, address newVault, address asset, uint amount, string memory memo) external nonReentrant {
        if (router == address(this)){
            _adjustAllowances(newVault, asset, amount);
            emit TransferAllowance(msg.sender, newVault, asset, amount, memo);
        } else {
            _routerDeposit(router, newVault, asset, amount, memo);
        }
    }

    //############################## ASSET TRANSFERS ##############################

    // Any vault calls to transfer any asset to any recipient.
    // Note: Contract recipients of ETH are only given 2300 Gas to complete execution.
    function transferOut(address payable to, address asset, uint amount, string memory memo) public payable nonReentrant {
        uint safeAmount;
        if(asset == address(0)){
            safeAmount = msg.value;
            bool success = to.send(safeAmount); // Send ETH. 
            if (!success) {
                payable(address(msg.sender)).transfer(safeAmount); // For failure, bounce back to vault & continue.
            }
        } else {
            _vaultAllowance[msg.sender][asset] -= amount; // Reduce allowance
            (bool success, bytes memory data) = asset.call(abi.encodeWithSignature("transfer(address,uint256)" , to, amount));
            require(success && (data.length == 0 || abi.decode(data, (bool))));
            safeAmount = amount;
        }
        emit TransferOut(msg.sender, to, asset, safeAmount, memo);
    }

    // Any vault calls to transferAndCall on a target contract that conforms with "swapOut(address,address,uint256)"
    // Example Memo: "~1b3:ETH.0xFinalToken:0xTo:"
    // Aggregator is matched to the last three digits of whitelisted aggregators
    // FinalToken, To, amountOutMin come from originating memo
    // Memo passed in here is the "OUT:HASH" type
    function transferOutAndCall(address payable aggregator, address finalToken, address to, uint256 amountOutMin, string memory memo) public payable nonReentrant {
        uint256 _safeAmount = msg.value;
        (bool erc20Success, ) = aggregator.call{value:_safeAmount}(abi.encodeWithSignature("swapOut(address,address,uint256)", finalToken, to, amountOutMin));
        if (!erc20Success) {
            bool ethSuccess = payable(to).send(_safeAmount); // If can't swap, just send the recipient the ETH
            if (!ethSuccess) {
                payable(address(msg.sender)).transfer(_safeAmount); // For failure, bounce back to vault & continue.
            }
        }
        emit TransferOutAndCall(msg.sender, aggregator, _safeAmount, finalToken, to, amountOutMin, memo);
    }


    //############################## VAULT MANAGEMENT ##############################

    // A vault can call to "return" all assets to an asgard, including ETH. 
    function returnVaultAssets(address router, address payable asgard, Coin[] memory coins, string memory memo) external payable nonReentrant {
        if (router == address(this)){
            for(uint i = 0; i < coins.length; i++){
                _adjustAllowances(asgard, coins[i].asset, coins[i].amount);
            }
            emit VaultTransfer(msg.sender, asgard, coins, memo); // Does not include ETH.           
        } else {
            for(uint i = 0; i < coins.length; i++){
                _routerDeposit(router, asgard, coins[i].asset, coins[i].amount, memo);
            }
        }
        bool success = asgard.send(msg.value);
        require(success);
    }

    //############################## HELPERS ##############################

    function vaultAllowance(address vault, address token) public view returns(uint amount){
        return _vaultAllowance[vault][token];
    }

    // Safe transferFrom in case asset charges transfer fees
    function safeTransferFrom(address _asset, uint _amount) internal returns(uint amount) {
        uint _startBal = iERC20(_asset).balanceOf(address(this));
        (bool success, bytes memory data) = _asset.call(abi.encodeWithSignature("transferFrom(address,address,uint256)", msg.sender, address(this), _amount));
        require(success && (data.length == 0 || abi.decode(data, (bool))));
        return (iERC20(_asset).balanceOf(address(this)) - _startBal);
    }

    // Decrements and Increments Allowances between two vaults
    function _adjustAllowances(address _newVault, address _asset, uint _amount) internal {
        _vaultAllowance[msg.sender][_asset] -= _amount;
        _vaultAllowance[_newVault][_asset] += _amount;
    }

    // Adjust allowance and forwards funds to new router, credits allowance to desired vault
    function _routerDeposit(address _router, address _vault, address _asset, uint _amount, string memory _memo) internal {
        _vaultAllowance[msg.sender][_asset] -= _amount;
        (bool success,) = _asset.call(abi.encodeWithSignature("approve(address,uint256)", _router, _amount)); // Approve to transfer
        require(success);
        iROUTER(_router).depositWithExpiry(_vault, _asset, _amount, _memo, type(uint).max); // Transfer by depositing
    }
}

Read Contract

RUNE 0x93e4eaa9 → address
vaultAllowance 0x03b6a673 → uint256

Write Contract 6 functions

These functions modify contract state and require a wallet transaction to execute.

deposit 0x1fece7b4
address vault
address asset
uint256 amount
string memo
depositWithExpiry 0x44bc937b
address vault
address asset
uint256 amount
string memo
uint256 expiration
returnVaultAssets 0xb98b995f
address router
address asgard
tuple[] coins
string memo
transferAllowance 0x1b738b32
address router
address newVault
address asset
uint256 amount
string memo
transferOut 0x574da717
address to
address asset
uint256 amount
string memo
transferOutAndCall 0x4039fd4b
address aggregator
address finalToken
address to
uint256 amountOutMin
string memo

Token Balances (5) $13,021,388.42

View Transfers →
TokenBalancePriceValue
USDC 5084279.2293 $1.0000 $5,084,274.15
USDT 4460504.7805 $1.0000 $4,460,415.57
WBTC 29.1345 $67,820.00 $1,975,901.79
DAI 1480111.8969 $1.00 $1,480,111.90
LINK 2369.4175 $8.73 $20,685.01

Recent Transactions

This address has 1 on-chain transactions, but only 1.7% of the chain is indexed. Transactions will appear as indexing progresses. View on Etherscan →