Skip to content

Latest commit

 

History

History
353 lines (310 loc) · 11.2 KB

sovrynProtocol.md

File metadata and controls

353 lines (310 loc) · 11.2 KB

Sovryn Protocol contract. (sovrynProtocol.sol)

View Source: contracts/core/Protocol.sol

↗ Extends: State

sovrynProtocol 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 contains the proxy functionality to deploy Protocol anchor and logic apart, turning it upgradable.

Functions


constructor

Fallback function performs a delegate call to the actual implementation address is pointing this proxy. Returns whatever the implementation call returns.

function () external payable
Source Code
function() external payable {
        if (gasleft() <= 2300) {
            return;
        }

        address target = logicTargets[msg.sig];
        require(target != address(0), "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)
                }
        }
    }

replaceContract

External owner target initializer.

function replaceContract(address target) external nonpayable onlyOwner 

Arguments

Name Type Description
target address The target addresses.
Source Code
function replaceContract(address target) external onlyOwner {
        (bool success, ) =
            target.delegatecall(abi.encodeWithSignature("initialize(address)", target));
        require(success, "setup failed");
    }

setTargets

External owner setter for target addresses.

function setTargets(string[] sigsArr, address[] targetsArr) external nonpayable onlyOwner 

Arguments

Name Type Description
sigsArr string[] The array of signatures.
targetsArr address[] The array of addresses.
Source Code
function setTargets(string[] calldata sigsArr, address[] calldata targetsArr)
        external
        onlyOwner
    {
        require(sigsArr.length == targetsArr.length, "count mismatch");

        for (uint256 i = 0; i < sigsArr.length; i++) {
            _setTarget(bytes4(keccak256(abi.encodePacked(sigsArr[i]))), targetsArr[i]);
        }
    }

getTarget

External getter for target addresses.

function getTarget(string sig) external view
returns(address)

Arguments

Name Type Description
sig string The signature.

Returns

The address for a given signature.

Source Code
function getTarget(string calldata sig) external view returns (address) {
        return logicTargets[bytes4(keccak256(abi.encodePacked(sig)))];
    }

Contracts