Skip to content

Latest commit

 

History

History
411 lines (352 loc) · 12.5 KB

LoanTokenLogicProxy.md

File metadata and controls

411 lines (352 loc) · 12.5 KB

Loan Token Logic Proxy contract.

  • (LoanTokenLogicProxy.sol)

View Source: contracts/connectors/loantoken/LoanTokenLogicProxy.sol

↗ Extends: AdvancedTokenStorage

LoanTokenLogicProxy contract

This contract contains the proxy functionality and it will query the logic target from LoanTokenLogicBeacon This contract will also has the pause/unpause functionality. The purpose of this pausability is so that we can pause/unpause from the loan token level.

Contract Members

Constants & Variables

//public members
address public sovrynContractAddress;
address public wrbtcTokenAddress;
address public target_;
address public admin;

//internal members
bytes32 internal constant LOAN_TOKEN_LOGIC_BEACON_ADDRESS_SLOT;

Modifiers

onlyAdmin

modifier onlyAdmin() internal

Functions


constructor

Fallback function performs a logic implementation address query to LoanTokenLogicBeacon and then do delegate call to that query result address. Returns whatever the implementation call returns.

function () external payable
Source Code
function() external payable {
        // query the logic target implementation address from the LoanTokenLogicBeacon
        address target = ILoanTokenLogicBeacon(_beaconAddress()).getTarget(msg.sig);
        require(target != address(0), "LoanTokenLogicProxy:target not active");

        bytes memory data = msg.data;
        assembly {
            let result := delegatecall(gas, target, add(data, 0x20), mload(data), 0, 0)
            let size := returndatasize
            let ptr := mload(0x40)
            returndatacopy(ptr, 0, size)
            switch result
                case 0 {
                    revert(ptr, size)
                }
                default {
                    return(ptr, size)
                }
        }
    }

_beaconAddress

Returns the current Loan Token logic Beacon.

function _beaconAddress() internal view
returns(beaconAddress address)
Source Code
function _beaconAddress() internal view returns (address beaconAddress) {
        bytes32 slot = LOAN_TOKEN_LOGIC_BEACON_ADDRESS_SLOT;
        assembly {
            beaconAddress := sload(slot)
        }
    }

beaconAddress

function beaconAddress() external view
returns(address)
Source Code
function beaconAddress() external view returns (address) {
        return _beaconAddress();
    }

_setBeaconAddress

Set/update the new beacon address.

function _setBeaconAddress(address _newBeaconAddress) private nonpayable

Arguments

Name Type Description
_newBeaconAddress address Address of the new LoanTokenLogicBeacon.
Source Code
function _setBeaconAddress(address _newBeaconAddress) private {
        require(
            Address.isContract(_newBeaconAddress),
            "Cannot set beacon address to a non-contract address"
        );

        bytes32 slot = LOAN_TOKEN_LOGIC_BEACON_ADDRESS_SLOT;

        assembly {
            sstore(slot, _newBeaconAddress)
        }
    }

setBeaconAddress

External function to set the new LoanTokenLogicBeacon Address

function setBeaconAddress(address _newBeaconAddress) external nonpayable onlyAdmin 

Arguments

Name Type Description
_newBeaconAddress address Address of the new LoanTokenLogicBeacon
Source Code
function setBeaconAddress(address _newBeaconAddress) external onlyAdmin {
        _setBeaconAddress(_newBeaconAddress);
    }

getTarget

function getTarget(bytes4 functionSignature) external view
returns(logicTargetAddress address)

Arguments

Name Type Description
functionSignature bytes4
Source Code
function getTarget(bytes4 functionSignature)
        external
        view
        returns (address logicTargetAddress);

Contracts