Skip to content

FluidSmartLending ​

Git Source

Inherits: ERC20, Variables, Error, ReentrancyGuard, Events

State Variables ​

TOKEN_NAME_PREFIX ​

prefix for token name. constructor appends dex id, e.g. "Fluid Smart Lending 12"

solidity
string private constant TOKEN_NAME_PREFIX = "Fluid Smart Lending ";

TOKEN_SYMBOL_PREFIX ​

prefix for token symbol. constructor appends dex id, e.g. "fSL12"

solidity
string private constant TOKEN_SYMBOL_PREFIX = "fSL";

HEX_DIGITS ​

Converts a uint256 to its ASCII string decimal representation. taken from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Strings.sol

solidity
bytes16 private constant HEX_DIGITS = "0123456789abcdef";

Functions ​

validAddress ​

Validates that an address is not the zero address

solidity
modifier validAddress(address value_);

constructor ​

solidity
constructor(uint256 dexId_, address liquidity_, address dexFactory_, address smartLendingFactory_)
    ERC20(
        string(abi.encodePacked(TOKEN_NAME_PREFIX, _toString(dexId_))),
        string(abi.encodePacked(TOKEN_SYMBOL_PREFIX, _toString(dexId_)))
    )
    validAddress(liquidity_)
    validAddress(dexFactory_)
    validAddress(smartLendingFactory_);

setDexFrom ​

solidity
modifier setDexFrom();

onlyAuth ​

solidity
modifier onlyAuth();

onlyOwner ​

solidity
modifier onlyOwner();

_updateExchangePrice ​

solidity
modifier _updateExchangePrice();

getUpdateExchangePrice ​

gets updated exchange price

solidity
function getUpdateExchangePrice() public view returns (uint184 exchangePrice_, bool rewardsOrFeeActive_);

updateExchangePrice ​

triggers updateExchangePrice

solidity
function updateExchangePrice() public _updateExchangePrice;

setFeeOrReward ​

Set the fee or reward. Only callable by auths.

solidity
function setFeeOrReward(int256 feeOrReward_) external onlyAuth _updateExchangePrice;

Parameters

NameTypeDescription
feeOrReward_int256The new fee or reward (1e6 = 100%, 1e4 = 1%, minimum 0.0001% fee or reward). 0 means no fee or reward

setRebalancer ​

Set the rebalancer. Only callable by auths.

solidity
function setRebalancer(address rebalancer_) external onlyAuth validAddress(rebalancer_);

Parameters

NameTypeDescription
rebalancer_addressThe new rebalancer

spell ​

Spell allows auths (governance) to do any arbitrary call

solidity
function spell(address target_, bytes memory data_) external onlyOwner returns (bytes memory response_);

Parameters

NameTypeDescription
target_addressAddress to which the call needs to be delegated
data_bytesData to execute at the delegated address

depositPerfect ​

Deposit tokens in equal proportion to the current pool ratio

solidity
function depositPerfect(uint256 shares_, uint256 maxToken0Deposit_, uint256 maxToken1Deposit_, address to_)
    external
    payable
    setDexFrom
    _updateExchangePrice
    nonReentrant
    returns (uint256 amount_, uint256 token0Amt_, uint256 token1Amt_);

Parameters

NameTypeDescription
shares_uint256The number of shares to mint
maxToken0Deposit_uint256Maximum amount of token0 to deposit
maxToken1Deposit_uint256Maximum amount of token1 to deposit
to_addressRecipient of minted tokens. If to_ == address(0) then out tokens will be sent to msg.sender.

Returns

NameTypeDescription
amount_uint256Amount of tokens minted
token0Amt_uint256Amount of token0 deposited
token1Amt_uint256Amount of token1 deposited

deposit ​

This function allows users to deposit tokens in any proportion into the col pool

solidity
function deposit(uint256 token0Amt_, uint256 token1Amt_, uint256 minSharesAmt_, address to_)
    external
    payable
    setDexFrom
    _updateExchangePrice
    nonReentrant
    returns (uint256 amount_, uint256 shares_);

Parameters

NameTypeDescription
token0Amt_uint256The amount of token0 to deposit
token1Amt_uint256The amount of token1 to deposit
minSharesAmt_uint256The minimum amount of shares the user expects to receive
to_addressRecipient of minted tokens. If to_ == address(0) then out tokens will be sent to msg.sender.

Returns

NameTypeDescription
amount_uint256The amount of tokens minted for the deposit
shares_uint256The number of dex pool shares deposited

withdrawPerfect ​

This function allows users to withdraw a perfect amount of collateral liquidity

solidity
function withdrawPerfect(uint256 shares_, uint256 minToken0Withdraw_, uint256 minToken1Withdraw_, address to_)
    external
    _updateExchangePrice
    nonReentrant
    returns (uint256 amount_, uint256 token0Amt_, uint256 token1Amt_);

Parameters

NameTypeDescription
shares_uint256The number of shares to withdraw. set to type(uint).max to withdraw maximum balance.
minToken0Withdraw_uint256The minimum amount of token0 the user is willing to accept
minToken1Withdraw_uint256The minimum amount of token1 the user is willing to accept
to_addressRecipient of withdrawn tokens. If to_ == address(0) then out tokens will be sent to msg.sender.

Returns

NameTypeDescription
amount_uint256amount_ of shares actually burnt
token0Amt_uint256The amount of token0 withdrawn
token1Amt_uint256The amount of token1 withdrawn

withdraw ​

This function allows users to withdraw tokens in any proportion from the col pool

solidity
function withdraw(uint256 token0Amt_, uint256 token1Amt_, uint256 maxSharesAmt_, address to_)
    external
    _updateExchangePrice
    nonReentrant
    returns (uint256 amount_, uint256 shares_);

Parameters

NameTypeDescription
token0Amt_uint256The amount of token0 to withdraw
token1Amt_uint256The amount of token1 to withdraw
maxSharesAmt_uint256The maximum number of shares the user is willing to burn
to_addressRecipient of withdrawn tokens. If to_ == address(0) then out tokens will be sent to msg.sender. If to_ == ADDRESS_DEAD then function will revert with shares_

Returns

NameTypeDescription
amount_uint256The number of tokens burned for the withdrawal
shares_uint256The number of dex pool shares withdrawn

rebalance ​

Rebalances the share to tokens ratio to balance out rewards and fees

solidity
function rebalance(uint256 minOrMaxToken0_, uint256 minOrMaxToken1_)
    public
    payable
    _updateExchangePrice
    nonReentrant
    returns (uint256 shares_, uint256 token0Amt_, uint256 token1Amt_, bool isWithdraw_);

rebalanceDiff ​

Returns the difference between the total smart lending shares on the DEX and the total smart lending shares calculated. A positive value indicates fees to collect, while a negative value indicates rewards to be rebalanced.

solidity
function rebalanceDiff() public view returns (int256);

dexCallback ​

dex liquidity callback

solidity
function dexCallback(address token_, uint256 amount_) external;

Parameters

NameTypeDescription
token_addressThe token being transferred
amount_uint256The amount being transferred

receive ​

for excess eth being sent back from dex to here

solidity
receive() external payable;

_log10 ​

Return the log in base 10 of a positive value rounded towards zero. Returns 0 if given 0. taken from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/Math.sol

solidity
function _log10(uint256 value) internal pure returns (uint256);

_toString ​

solidity
function _toString(uint256 value) internal pure returns (string memory);