Skip to content

Latest commit

 

History

History
264 lines (242 loc) · 9.4 KB

ProtocolTokenUser.md

File metadata and controls

264 lines (242 loc) · 9.4 KB

The Protocol Token User contract. (ProtocolTokenUser.sol)

View Source: contracts/mixins/ProtocolTokenUser.sol

↗ Extends: State ↘ Derived Contracts: ProtocolSettings

ProtocolTokenUser contract

This contract code comes from bZx. bZx is a protocol for tokenized margin trading and lending https://bzx.network similar to the dYdX protocol.

  • This contract implements functionality to withdraw protocol tokens.

Functions


_withdrawProtocolToken

Internal function to withdraw an amount of protocol tokens from this contract. *

function _withdrawProtocolToken(address receiver, uint256 amount) internal nonpayable
returns(address, bool)

Arguments

Name Type Description
receiver address The address of the recipient.
amount uint256 The amount of tokens to withdraw. *

Returns

The protocol token address.

Source Code
function _withdrawProtocolToken(address receiver, uint256 amount)
        internal
        returns (address, bool)
    {
        uint256 withdrawAmount = amount;

        uint256 tokenBalance = protocolTokenHeld;
        if (withdrawAmount > tokenBalance) {
            withdrawAmount = tokenBalance;
        }
        if (withdrawAmount == 0) {
            return (protocolTokenAddress, false);
        }

        protocolTokenHeld = tokenBalance.sub(withdrawAmount);

        IERC20(protocolTokenAddress).safeTransfer(receiver, withdrawAmount);

        return (protocolTokenAddress, true);
    }

Contracts