Skip to content

BorrowFees Contract 📜

Contract that handles fees for keeping positions open. Otherwise known as the borrowing fee.

State Variables

P_1

solidity
uint256 constant P_1 = 1e10;
uint256 constant P_1 = 1e10;

P_2

solidity
uint256 constant P_2 = 1e40;
uint256 constant P_2 = 1e40;

storageT

solidity
StorageInterfaceV5 public storageT;
StorageInterfaceV5 public storageT;

pairInfos

solidity
GNSPairInfosInterfaceV6 public pairInfos;
GNSPairInfosInterfaceV6 public pairInfos;

groups

solidity
mapping(uint16 => Group) public groups;
mapping(uint16 => Group) public groups;

pairs

solidity
mapping(uint256 => Pair) public pairs;
mapping(uint256 => Pair) public pairs;

initialAccFees

solidity
mapping(address => mapping(uint256 => mapping(uint256 => InitialAccFees))) public initialAccFees;
mapping(address => mapping(uint256 => mapping(uint256 => InitialAccFees))) public initialAccFees;

Functions

initialize

solidity
function initialize(StorageInterfaceV5 _storageT, GNSPairInfosInterfaceV6 _pairInfos) external initializer;
function initialize(StorageInterfaceV5 _storageT, GNSPairInfosInterfaceV6 _pairInfos) external initializer;

onlyManager

solidity
modifier onlyManager();
modifier onlyManager();

onlyCallbacks

solidity
modifier onlyCallbacks();
modifier onlyCallbacks();

setPairParams

solidity
function setPairParams(uint256 pairIndex, PairParams calldata value) external onlyManager;
function setPairParams(uint256 pairIndex, PairParams calldata value) external onlyManager;

setPairParamsArray

solidity
function setPairParamsArray(uint256[] calldata indices, PairParams[] calldata values) external onlyManager;
function setPairParamsArray(uint256[] calldata indices, PairParams[] calldata values) external onlyManager;

_setPairParams

solidity
function _setPairParams(uint256 pairIndex, PairParams calldata value) private;
function _setPairParams(uint256 pairIndex, PairParams calldata value) private;

setGroupParams

solidity
function setGroupParams(uint16 groupIndex, GroupParams calldata value) external onlyManager;
function setGroupParams(uint16 groupIndex, GroupParams calldata value) external onlyManager;

setGroupParamsArray

solidity
function setGroupParamsArray(uint16[] calldata indices, GroupParams[] calldata values) external onlyManager;
function setGroupParamsArray(uint16[] calldata indices, GroupParams[] calldata values) external onlyManager;

_setGroupParams

solidity
function _setGroupParams(uint16 groupIndex, GroupParams calldata value) private;
function _setGroupParams(uint16 groupIndex, GroupParams calldata value) private;

_setGroupOi

solidity
function _setGroupOi(uint16 groupIndex, bool long, bool increase, uint256 amount) private;
function _setGroupOi(uint16 groupIndex, bool long, bool increase, uint256 amount) private;

getPendingAccFees

solidity
function getPendingAccFees(
    uint64 accFeeLong,
    uint64 accFeeShort,
    uint256 oiLong,
    uint256 oiShort,
    uint32 feePerBlock,
    uint256 currentBlock,
    uint256 accLastUpdatedBlock,
    uint256 vaultMarketCap
) public pure returns (uint64 newAccFeeLong, uint64 newAccFeeShort, int256 delta);
function getPendingAccFees(
    uint64 accFeeLong,
    uint64 accFeeShort,
    uint256 oiLong,
    uint256 oiShort,
    uint32 feePerBlock,
    uint256 currentBlock,
    uint256 accLastUpdatedBlock,
    uint256 vaultMarketCap
) public pure returns (uint64 newAccFeeLong, uint64 newAccFeeShort, int256 delta);

getPairGroupAccFeesDeltasNoTrade

solidity
function getPairGroupAccFeesDeltasNoTrade(
    uint256 i,
    PairGroup[] memory pairGroups,
    uint256 pairIndex,
    bool long,
    uint256 currentBlock
) public view returns (uint64 deltaGroup, uint64 deltaPair);
function getPairGroupAccFeesDeltasNoTrade(
    uint256 i,
    PairGroup[] memory pairGroups,
    uint256 pairIndex,
    bool long,
    uint256 currentBlock
) public view returns (uint64 deltaGroup, uint64 deltaPair);

getPairGroupAccFeesDeltas

solidity
function getPairGroupAccFeesDeltas(
    uint256 i,
    PairGroup[] memory pairGroups,
    InitialAccFees memory initialFees,
    uint256 pairIndex,
    bool long,
    uint256 currentBlock
) public view returns (uint64 deltaGroup, uint64 deltaPair, bool beforeTradeOpen);
function getPairGroupAccFeesDeltas(
    uint256 i,
    PairGroup[] memory pairGroups,
    InitialAccFees memory initialFees,
    uint256 pairIndex,
    bool long,
    uint256 currentBlock
) public view returns (uint64 deltaGroup, uint64 deltaPair, bool beforeTradeOpen);

getPairPendingAccFees

solidity
function getPairPendingAccFees(uint256 pairIndex, uint256 currentBlock)
    public
    view
    returns (uint64 accFeeLong, uint64 accFeeShort, int256 pairAccFeeDelta);
function getPairPendingAccFees(uint256 pairIndex, uint256 currentBlock)
    public
    view
    returns (uint64 accFeeLong, uint64 accFeeShort, int256 pairAccFeeDelta);

getPairPendingAccFee

solidity
function getPairPendingAccFee(uint256 pairIndex, uint256 currentBlock, bool long) public view returns (uint64 accFee);
function getPairPendingAccFee(uint256 pairIndex, uint256 currentBlock, bool long) public view returns (uint64 accFee);

_setPairPendingAccFees

solidity
function _setPairPendingAccFees(uint256 pairIndex, uint256 currentBlock)
    private
    returns (uint64 accFeeLong, uint64 accFeeShort);
function _setPairPendingAccFees(uint256 pairIndex, uint256 currentBlock)
    private
    returns (uint64 accFeeLong, uint64 accFeeShort);

getGroupPendingAccFees

solidity
function getGroupPendingAccFees(uint16 groupIndex, uint256 currentBlock)
    public
    view
    returns (uint64 accFeeLong, uint64 accFeeShort, int256 groupAccFeeDelta);
function getGroupPendingAccFees(uint16 groupIndex, uint256 currentBlock)
    public
    view
    returns (uint64 accFeeLong, uint64 accFeeShort, int256 groupAccFeeDelta);

getGroupPendingAccFee

solidity
function getGroupPendingAccFee(uint16 groupIndex, uint256 currentBlock, bool long)
    public
    view
    returns (uint64 accFee);
function getGroupPendingAccFee(uint16 groupIndex, uint256 currentBlock, bool long)
    public
    view
    returns (uint64 accFee);

_setGroupPendingAccFees

solidity
function _setGroupPendingAccFees(uint16 groupIndex, uint256 currentBlock)
    private
    returns (uint64 accFeeLong, uint64 accFeeShort);
function _setGroupPendingAccFees(uint16 groupIndex, uint256 currentBlock)
    private
    returns (uint64 accFeeLong, uint64 accFeeShort);

getPairBorrowingFee

solidity
function getPairBorrowingFee(uint256 pairIndex, bool long) public view returns (uint256 feeP);
function getPairBorrowingFee(uint256 pairIndex, bool long) public view returns (uint256 feeP);

getTradeBorrowingFee

solidity
function getTradeBorrowingFee(BorrowingFeeInput memory input) public view returns (uint256 fee);
function getTradeBorrowingFee(BorrowingFeeInput memory input) public view returns (uint256 fee);

getTradeLiquidationPrice

solidity
function getTradeLiquidationPrice(LiqPriceInput calldata input) external view returns (uint256);
function getTradeLiquidationPrice(LiqPriceInput calldata input) external view returns (uint256);

getPairGroupIndex

solidity
function getPairGroupIndex(uint256 pairIndex) public view returns (uint16 groupIndex);
function getPairGroupIndex(uint256 pairIndex) public view returns (uint16 groupIndex);

getPendingAccBlockWeightedMarketCap

solidity
function getPendingAccBlockWeightedMarketCap(uint256 currentBlock) public view returns (uint256);
function getPendingAccBlockWeightedMarketCap(uint256 currentBlock) public view returns (uint256);

getGroupWeightedVaultMarketCapSinceLastUpdate

solidity
function getGroupWeightedVaultMarketCapSinceLastUpdate(uint16 groupIndex, uint256 currentBlock)
    public
    view
    returns (uint256);
function getGroupWeightedVaultMarketCapSinceLastUpdate(uint16 groupIndex, uint256 currentBlock)
    public
    view
    returns (uint256);

getPairWeightedVaultMarketCapSinceLastUpdate

solidity
function getPairWeightedVaultMarketCapSinceLastUpdate(uint256 pairIndex, uint256 currentBlock)
    public
    view
    returns (uint256);
function getPairWeightedVaultMarketCapSinceLastUpdate(uint256 pairIndex, uint256 currentBlock)
    public
    view
    returns (uint256);

getWeightedVaultMarketCap

solidity
function getWeightedVaultMarketCap(
    uint256 accBlockWeightedMarketCap,
    uint256 lastAccBlockWeightedMarketCap,
    uint256 blockDelta
) public pure returns (uint256);
function getWeightedVaultMarketCap(
    uint256 accBlockWeightedMarketCap,
    uint256 lastAccBlockWeightedMarketCap,
    uint256 blockDelta
) public pure returns (uint256);

getGroup

solidity
function getGroup(uint16 groupIndex) external view returns (Group memory);
function getGroup(uint16 groupIndex) external view returns (Group memory);

getPair

solidity
function getPair(uint256 pairIndex) external view returns (Pair memory);
function getPair(uint256 pairIndex) external view returns (Pair memory);

getAllPairs

solidity
function getAllPairs() external view returns (Pair[] memory);
function getAllPairs() external view returns (Pair[] memory);

getGroups

solidity
function getGroups(uint16[] calldata indices) external view returns (Group[] memory);
function getGroups(uint16[] calldata indices) external view returns (Group[] memory);

getTradeInitialAccFees

solidity
function getTradeInitialAccFees(address trader, uint256 pairIndex, uint256 index)
    external
    view
    returns (InitialAccFees memory borrowingFees, GNSPairInfosInterfaceV6.TradeInitialAccFees memory otherFees);
function getTradeInitialAccFees(address trader, uint256 pairIndex, uint256 index)
    external
    view
    returns (InitialAccFees memory borrowingFees, GNSPairInfosInterfaceV6.TradeInitialAccFees memory otherFees);