Sonic.sol
Major modules in Sonic Router contract are listed below. These modules can be used to interact with smart contract and perform buy, sell , deposit actions
withdraw() : Create Sell Order​
Starts withdraw order of liquid token triggering strategy and best path.
function withdraw(
address _token,
uint256 _amount,
uint256 _fee,
uint256 _deadline,
bool _allowPartial,
bool _startUnstaking
) returns (uint256)
Parameters:​
Name | Description |
---|---|
_token | Liquid token to be withdrawn. |
_amount | Amount of liquid token to be withdrawn. |
_fee | Percentage fee to be paid by owner as discount. |
_deadline | Seconds from execution the order is valid for fulfillment. |
_allowPartial | Whether order allows partial fulfillment. |
_startUnstaking | Whether to start unstaking tokens. |
Note: Requirements:
msg.sender
must have approved_amount
of Token to this contract and must have a balance more than_amount
.- returns uint256
_orderId
of withdraw order created
LogWithdraw​
event LogWithdraw(
address indexed user,
address indexed token,
uint256 indexed orderId,
uint256 amount,
uint256 fee,
uint256 startTime,
uint256 createdAt,
uint256 deadline,
bool allowPartial
);
updateWithdrawOrder()​
Modifies withdraw order conditions.
function updateWithdrawOrder(
uint256 _orderId,
uint256 _fee,
uint256 _deadline,
bool _allowPartial,
bool startUnstaking
) returns (bool)
Parameters:​
Name | Description |
---|---|
_orderId | Order Id of order to be updated. |
_fee | Percentage fee to be paid by owner as discount. |
_deadline | Seconds from execution the order is valid for fulfillment. |
_allowPartial | Whether order allows partial fulfillment. |
_startUnstaking | Whether to start unstaking tokens. |
Note:
- Orders that have already started unstaking will remain so
LogUpdateWithdraw​
event LogUpdateWithdraw(
address indexed user,
uint256 indexed orderId,
uint256 fee,
uint256 deadline,
bool allowPartial,
bool unstake
);
cancelWithdrawOrder()​
Cancels withdraw order which is not unstaked and refunds the amount to user
function cancelWithdrawOrder(uint256 _orderId, bool _unwrap) returns (bool)
Parameters:​
Name | Description |
---|---|
_orderId | Order Id of order to be updated. |
_unwrap | Whether to unwrap rebasable tokens. |
Note:
- Orders that have already started unstaking can't be cancelled, only claimed
LogCancelWithdraw​
event LogCancelWithdraw(address indexed user, uint256 indexed orderId);
claim()​
Allows the user to claim several orders at once.
function claim(uint256[] calldata _orderIds, bytes[] memory _data) returns (bool)
Parameters:​
Name | Description |
---|---|
_orderIds | Array of withdraw order ids issued at withdraw() |
_data | Array of external data required to claim |
LogClaim​
event LogClaim(address indexed user, uint256 indexed orderId, uint256 amount, uint256 amountBase);
fulfill() : Fulfill Sell Order​
Fulfills order by providing base token and sends amount to order owner. If amount is partial and the order started unstaking, user will receive a new order for the corresponding claim. This order can in effect be offered again in the market at a discount.
Fulfill as a payable function allows for two modalities, either sending the fulfillable amount as native token (e.g. ETH) or pre-approving the wrapped amount of the base token (e.g. WETH). When sending the native token, the amount sent must be at least the amount to be fulfilled of liquid token. To simplify the calculation see orderAmounts().
function fulfill(
uint256 _orderId,
uint256 _amount,
bool _startUnstaking,
bool _unwrap
) payable returns (uint256)
Parameters:​
Name | Description |
---|---|
_orderId | Order Id of order to be updated. |
_amount | Liquid tokens to be fulfilled. |
_startUnstaking | Whether to start unstaking tokens. |
_unwrap | Whether to unwrap rebasable tokens. |
Note:
- Orders that have already started unstaking will remain so
- User must approve and provide wrapped base token in case base token is a native chain token
LogFulfill​
event LogFulfill(
address indexed user,
uint256 indexed orderId,
uint256 indexed newOrderId,
uint256 amount,
uint256 amountBase
);
deposit() : Buy LSD on discount​
Fulfill exiting orders & Stakes to a strategy with wrapped native token for LSD
function deposit(
address _token,
uint256 _amount,
uint256[] calldata _orderIds
) returns (uint256)
Parameters:​
Name | Description |
---|---|
_token | Liquid token to be withdrawn. |
_amount | Amount of liquid token to be withdrawn. |
_orderIds | Array of order ids to fulfill. |
Note: Requirements:
msg.sender
must have approved_amount
of Token to this contract and must have a balance more than_amount
._amount
should not be zero.- returns uint256 liquid tokens minted.
LogDeposit​
event LogDeposit(
address indexed user,
address indexed token,
uint256 amount,
uint256 amountLiquid);
Note: There is one more variation of deposit() which allows deposit in Native token. function depositETH(address _token, uint256[] calldata _orderIds) payable returns (uint256).
orderAmounts()​
Calculates the amount to fulfill order including treasury fee. To fulfill an order, the order taker must paid the amount to owner (already includes the discount) and the treasury fee.
- Total amount at current exchange rate (accounts for slashing)
- Amount to be paid to order owner
- Amount to be paid to DAO
function orderAmounts(uint256 _orderId, uint256 _amount) public view returns (uint256, uint256, uint256)
Parameters:​
Name | Description |
---|---|
_orderId | Order Id of order to be updated. |
_amount | Liquid tokens to be fulfilled. |
getOrder()​
Returns order info with calculated values.
function getOrder(uint256 _orderId) view returns (UserWithdrawOrderInfo memory)
UserWithdrawOrderInfo Structure:​
struct UserWithdrawOrderInfo {
address token;
uint256 orderId;
uint256 amount;
uint256 amountOriginal;
uint256 amountValue;
uint256 amountToFulfill;
uint256 discount;
uint256 splitFee;
uint256 fee;
uint256 deadline;
uint256 startTime;
uint256 createdAt;
uint256 exchangeRate;
bool allowPartial;
Status status;
address owner;
uint256 claimTime;
uint256 expireTime;
}
Name | Description |
---|---|
token | Address liquid token. |
orderId | Order Id |
amount | Liquid tokens amount. |
amountOriginal | Total amount from original order. |
amountValue | Amount in base tokens at valid exchange rate. |
amountToFulfill | Total amount to be provided by order taker to fully fulfill. |
discount | Percentage discount offered by order owner. |
splitFee | Percentage of the discount towards order taker. |
fee | Net offered discount to order taker. |
deadline | Seconds from execution the order is valid for fulfillment. |
startTime | Timestamp when unbonding has started. |
createdAt | Timestamp when order was created. |
exchangeRate | Token exchange rate. |
allowPartial | Allows partial fulfillment or not. |
status | 0-Staked, 1-Unbonding, 2-Claimable, 3-Claimed |
owner | Address owner of the order |
claimTime | Timestamp after which order can claimed |
expireTime | Timestamp after which order will be expire |
getOrders()​
Returns array of several user orders at once
function getOrders(uint256[] _orderIds) view returns (UserWithdrawOrderInfo[] memory orders)
getUserOrders()​
Returns paginated list of user's withdraw orders in descending order of creation, in addition it reruns the current block timestamp and total number of pages for the user.
function getUserOrders(
address _user,
uint256 _page
) view returns (UserWithdrawOrderInfo[], uint256, uint256)
orderNonce()​
Linear incremental order nonce. Increases by one after each withdraw request.
function orderNonce() view returns (uint256)
getExchangeRate()​
Returns the current exchange rate from strategy.
function getExchangeRate(address _token) view returns (uint256)