FluidSmartLending ​
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"
string private constant TOKEN_NAME_PREFIX = "Fluid Smart Lending ";
TOKEN_SYMBOL_PREFIX ​
prefix for token symbol. constructor appends dex id, e.g. "fSL12"
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
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
Functions ​
validAddress ​
Validates that an address is not the zero address
modifier validAddress(address value_);
constructor ​
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 ​
modifier setDexFrom();
onlyAuth ​
modifier onlyAuth();
onlyOwner ​
modifier onlyOwner();
_updateExchangePrice ​
modifier _updateExchangePrice();
getUpdateExchangePrice ​
gets updated exchange price
function getUpdateExchangePrice() public view returns (uint184 exchangePrice_, bool rewardsOrFeeActive_);
updateExchangePrice ​
triggers updateExchangePrice
function updateExchangePrice() public _updateExchangePrice;
setFeeOrReward ​
Set the fee or reward. Only callable by auths.
function setFeeOrReward(int256 feeOrReward_) external onlyAuth _updateExchangePrice;
Parameters
Name | Type | Description |
---|---|---|
feeOrReward_ | int256 | The 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.
function setRebalancer(address rebalancer_) external onlyAuth validAddress(rebalancer_);
Parameters
Name | Type | Description |
---|---|---|
rebalancer_ | address | The new rebalancer |
spell ​
Spell allows auths (governance) to do any arbitrary call
function spell(address target_, bytes memory data_) external onlyOwner returns (bytes memory response_);
Parameters
Name | Type | Description |
---|---|---|
target_ | address | Address to which the call needs to be delegated |
data_ | bytes | Data to execute at the delegated address |
depositPerfect ​
Deposit tokens in equal proportion to the current pool ratio
function depositPerfect(uint256 shares_, uint256 maxToken0Deposit_, uint256 maxToken1Deposit_, address to_)
external
payable
setDexFrom
_updateExchangePrice
nonReentrant
returns (uint256 amount_, uint256 token0Amt_, uint256 token1Amt_);
Parameters
Name | Type | Description |
---|---|---|
shares_ | uint256 | The number of shares to mint |
maxToken0Deposit_ | uint256 | Maximum amount of token0 to deposit |
maxToken1Deposit_ | uint256 | Maximum amount of token1 to deposit |
to_ | address | Recipient of minted tokens. If to_ == address(0) then out tokens will be sent to msg.sender. |
Returns
Name | Type | Description |
---|---|---|
amount_ | uint256 | Amount of tokens minted |
token0Amt_ | uint256 | Amount of token0 deposited |
token1Amt_ | uint256 | Amount of token1 deposited |
deposit ​
This function allows users to deposit tokens in any proportion into the col pool
function deposit(uint256 token0Amt_, uint256 token1Amt_, uint256 minSharesAmt_, address to_)
external
payable
setDexFrom
_updateExchangePrice
nonReentrant
returns (uint256 amount_, uint256 shares_);
Parameters
Name | Type | Description |
---|---|---|
token0Amt_ | uint256 | The amount of token0 to deposit |
token1Amt_ | uint256 | The amount of token1 to deposit |
minSharesAmt_ | uint256 | The minimum amount of shares the user expects to receive |
to_ | address | Recipient of minted tokens. If to_ == address(0) then out tokens will be sent to msg.sender. |
Returns
Name | Type | Description |
---|---|---|
amount_ | uint256 | The amount of tokens minted for the deposit |
shares_ | uint256 | The number of dex pool shares deposited |
withdrawPerfect ​
This function allows users to withdraw a perfect amount of collateral liquidity
function withdrawPerfect(uint256 shares_, uint256 minToken0Withdraw_, uint256 minToken1Withdraw_, address to_)
external
_updateExchangePrice
nonReentrant
returns (uint256 amount_, uint256 token0Amt_, uint256 token1Amt_);
Parameters
Name | Type | Description |
---|---|---|
shares_ | uint256 | The number of shares to withdraw. set to type(uint).max to withdraw maximum balance. |
minToken0Withdraw_ | uint256 | The minimum amount of token0 the user is willing to accept |
minToken1Withdraw_ | uint256 | The minimum amount of token1 the user is willing to accept |
to_ | address | Recipient of withdrawn tokens. If to_ == address(0) then out tokens will be sent to msg.sender. |
Returns
Name | Type | Description |
---|---|---|
amount_ | uint256 | amount_ of shares actually burnt |
token0Amt_ | uint256 | The amount of token0 withdrawn |
token1Amt_ | uint256 | The amount of token1 withdrawn |
withdraw ​
This function allows users to withdraw tokens in any proportion from the col pool
function withdraw(uint256 token0Amt_, uint256 token1Amt_, uint256 maxSharesAmt_, address to_)
external
_updateExchangePrice
nonReentrant
returns (uint256 amount_, uint256 shares_);
Parameters
Name | Type | Description |
---|---|---|
token0Amt_ | uint256 | The amount of token0 to withdraw |
token1Amt_ | uint256 | The amount of token1 to withdraw |
maxSharesAmt_ | uint256 | The maximum number of shares the user is willing to burn |
to_ | address | Recipient 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
Name | Type | Description |
---|---|---|
amount_ | uint256 | The number of tokens burned for the withdrawal |
shares_ | uint256 | The number of dex pool shares withdrawn |
rebalance ​
Rebalances the share to tokens ratio to balance out rewards and fees
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.
function rebalanceDiff() public view returns (int256);
dexCallback ​
dex liquidity callback
function dexCallback(address token_, uint256 amount_) external;
Parameters
Name | Type | Description |
---|---|---|
token_ | address | The token being transferred |
amount_ | uint256 | The amount being transferred |
receive ​
for excess eth being sent back from dex to here
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
function _log10(uint256 value) internal pure returns (uint256);
_toString ​
function _toString(uint256 value) internal pure returns (string memory);