Skip to main content

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:​

NameDescription
_tokenLiquid token to be withdrawn.
_amountAmount of liquid token to be withdrawn.
_feePercentage fee to be paid by owner as discount.
_deadlineSeconds from execution the order is valid for fulfillment.
_allowPartialWhether order allows partial fulfillment.
_startUnstakingWhether 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:​

NameDescription
_orderIdOrder Id of order to be updated.
_feePercentage fee to be paid by owner as discount.
_deadlineSeconds from execution the order is valid for fulfillment.
_allowPartialWhether order allows partial fulfillment.
_startUnstakingWhether 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:​

NameDescription
_orderIdOrder Id of order to be updated.
_unwrapWhether 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:​

NameDescription
_orderIdsArray of withdraw order ids issued at withdraw()
_dataArray 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:​

NameDescription
_orderIdOrder Id of order to be updated.
_amountLiquid tokens to be fulfilled.
_startUnstakingWhether to start unstaking tokens.
_unwrapWhether 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:​

NameDescription
_tokenLiquid token to be withdrawn.
_amountAmount of liquid token to be withdrawn.
_orderIdsArray 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:​

NameDescription
_orderIdOrder Id of order to be updated.
_amountLiquid 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;
}
NameDescription
tokenAddress liquid token.
orderIdOrder Id
amountLiquid tokens amount.
amountOriginalTotal amount from original order.
amountValueAmount in base tokens at valid exchange rate.
amountToFulfillTotal amount to be provided by order taker to fully fulfill.
discountPercentage discount offered by order owner.
splitFeePercentage of the discount towards order taker.
feeNet offered discount to order taker.
deadlineSeconds from execution the order is valid for fulfillment.
startTimeTimestamp when unbonding has started.
createdAtTimestamp when order was created.
exchangeRateToken exchange rate.
allowPartialAllows partial fulfillment or not.
status0-Staked, 1-Unbonding, 2-Claimable, 3-Claimed
ownerAddress owner of the order
claimTimeTimestamp after which order can claimed
expireTimeTimestamp 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)