ITradingPlatform

Interface for TradingPlatform smart contract.

Solidity API

ITradingPlatform

Order

struct Order {
  address userAddress;
  address baseToken;
  address targetToken;
  uint24 pairFee;
  uint24 slippage;
  uint128 baseAmount;
  uint128 aimTargetTokenAmount;
  uint128 minTargetTokenAmount;
  uint256 expiration;
  uint256 boundOrder;
  enum ITradingPlatform.Action action;
  bytes data;
}

OrderInfo

struct OrderInfo {
  uint256 id;
  struct ITradingPlatform.Order order;
  uint256 additionalInformation;
  uint256 resultTokenOut;
  bool status;
}

TrailingOrderData

struct TrailingOrderData {
  uint128 baseAmount;
  uint128 fixingPerStep;
  uint24 step;
}

DCAOrderData

struct DCAOrderData {
  uint128 period;
  uint128 amountPerPeriod;
}

Action

enum Action {
  LOSS,
  PROFIT,
  DCA,
  TRAILING
}

Deposited

event Deposited(address operator, address token, uint256 amount)

Emitted when tokens are deposited into the contract.

Parameters

OrdersBounded

event OrdersBounded(uint256 leftOrderId, uint256 rightOrderId)

Emitted when two orders are bound together.

Parameters

OrderCanceled

event OrderCanceled(uint256 orderId)

Emitted when an order is canceled.

Parameters

OrderCreated

event OrderCreated(uint256 orderId, address userAddress)

Emitted when a new order is created.

Parameters

OrderExecuted

event OrderExecuted(uint256 orderId, address validator)

Emitted when an order is executed.

Parameters

TokenAdded

event TokenAdded(address token)

Emitted when a new token is added to the contract.

Parameters

TokenRemoved

event TokenRemoved(address token)

Emitted when a token is removed from the contract.

Parameters

Withdrawed

event Withdrawed(address operator, address token, uint256 amount)

Emitted when tokens are withdrawn from the contract.

Parameters

activeOrdersLength

function activeOrdersLength() external view returns (uint256)

Retrieves the number of active orders.

This function is read-only and can be called by anyone.

Return Values

activeOrderId

function activeOrderId(uint256 itemId) external view returns (uint256)

Retrieves the active order ID at the specified index.

This function is read-only and can be called by anyone. Requires the itemId to be within the valid range of activeOrders length.

Parameters

Return Values

activeOrdersIds

function activeOrdersIds(uint256 offset, uint256 limit) external view returns (uint256[] ordersIds)

Retrieves an array of active order IDs based on pagination parameters.

This function is read-only and can be called by anyone.

Parameters

Return Values

checkUpkeep

function checkUpkeep(bytes checkData) external view returns (bool upkeepNeeded, bytes performData)

Checks the upkeep status and provides the necessary data for performing upkeep.

Parameters

Return Values

getFeeRecipient

function getFeeRecipient() external view returns (address)

Returns the address of the fee recipient.

This function is read-only and can be called by anyone.

Return Values

getOrderCounter

function getOrderCounter() external view returns (uint256)

Retrieves the current order counter.

This function is read-only and can be called by anyone.

Return Values

getProtocolFee

function getProtocolFee() external view returns (uint32)

Returns the current protocol fee percentage.

This function is read-only and can be called by anyone.

Return Values

getResultTokenOut

function getResultTokenOut(uint256 orderId) external view returns (uint256)

Retrieves the result token out value for a specific order ID.

This function is read-only and can be called by anyone.

Parameters

Return Values

getSwapHelper

function getSwapHelper() external view returns (address)

Returns the address of the UniswapHelperV3 contract.

This function is read-only and can be called by anyone.

Return Values

getTokenStatus

function getTokenStatus(address token) external view returns (bool)

Checks if a token is whitelisted.

This function is read-only and can be called by anyone.

Parameters

Return Values

getUserBalance

function getUserBalance(address user, address token) external view returns (uint256)

Retrieves the balance of a specific token for a user.

This function is read-only and can be called by anyone.

Parameters

Return Values

getUserOrdersIds

function getUserOrdersIds(address userAddress) external view returns (uint256[])

Retrieves the array of order IDs associated with a user address.

This function is read-only and can be called by anyone.

Parameters

Return Values

getUserOrdersInfo

function getUserOrdersInfo(address userAddress) external view returns (struct ITradingPlatform.OrderInfo[])

Retrieves detailed information about the user's orders.

This function is read-only and can be called by anyone.

Parameters

Return Values

isActiveOrderExist

function isActiveOrderExist(uint256 orderId) external view returns (bool)

Checks if an active order with the given ID exists.

This function is read-only and can be called by anyone.

Parameters

Return Values

checkOrder

function checkOrder(uint256 orderId) external view returns (bool)

Checks if an order is valid and can be executed.

Parameters

Return Values

getOrdersInfo

function getOrdersInfo(uint256[] ordersIds) external view returns (struct ITradingPlatform.OrderInfo[] orders)

Retrieves detailed information about multiple orders.

This function is read-only and can be called by anyone.

Parameters

Return Values

shouldRebalance

function shouldRebalance() external view returns (uint256[])

Retrieves the list of order IDs that need to be rebalanced.

Return Values

addTokensToWhitelist

function addTokensToWhitelist(address[] tokens) external

Adds multiple tokens to the whitelist.

Only callable by an address with the ADMIN_ROLE. Requires each token address to be non-zero and not already in the whitelist. Emits a {TokenAdded} event for each token added to the whitelist.

Parameters

boundOrders

function boundOrders(uint256 leftOrderId, uint256 rightOrderId) external

Binds two orders together.

Requires both orders to belong to the calling user and not be DCA orders. Requires both orders to not be already bound with other orders. Updates the boundOrder field of each order to bind them together. Emits a {OrdersBounded} event upon successful binding of the orders.

Parameters

cancelOrders

function cancelOrders(uint256[] ordersIds) external

Cancels the specified orders.

Requires the orders to be active and belong to the calling user. Refunds the base tokens to the user balance. Emits a {OrderCanceled} event for each canceled order.

Parameters

createOrder

function createOrder(struct ITradingPlatform.Order order) external returns (uint256)

Creates a new order.

Requires various checks for the validity of the order. Transfers base tokens from the user to this contract if user balance on contract is insufficient. Adds the order to the active orders list and associates it with the user. Emits a {OrderCreated} event upon successful creation of the order.

Parameters

Return Values

deposit

function deposit(address token, uint256 amount) external returns (bool)

Deposits an amount of tokens into the contract for a specific user.

Requires the token to be allowed in the whitelist. Transfers the specified amount of tokens from the user to this contract. Updates the user's token balance in the contract. Emits a {Deposited} event upon successful deposit.

Parameters

Return Values

executeOrders

function executeOrders(uint256[] ordersIds) external returns (bool)

Executes the orders specified by the given order IDs.

Emits a {OrderExecuted} event for each executed order.

Parameters

Return Values

performUpkeep

function performUpkeep(bytes performData) external

Performs the upkeep based on the provided performData.

Requires the performData does contain any order IDs. Emits a {OrderExecuted} event for each executed order.

Parameters

removeTokensFromWhitelist

function removeTokensFromWhitelist(address[] tokens) external

Removes multiple tokens from the whitelist.

Only callable by an address with the ADMIN_ROLE. Removes each token address from the whitelist if it exists. Emits a {TokenRemoved} event for each token removed from the whitelist.

Parameters

setProtocolFee

function setProtocolFee(uint32 newProtocolFee) external

Sets a new protocol fee percentage.

Only the specified role can call this function. The new protocol fee must be less than 100% (represented as 1,000,000 in 6 digits precision). Emits a {ProtocolFeeSet} event.

Parameters

withdraw

function withdraw(address token, uint256 amount) external returns (bool)

Withdraws an amount of tokens from the contract for a specific user.

Requires the user to have a sufficient balance of the specified token. Transfers the specified amount of tokens from the contract to the user. Updates the user's token balance in the contract. Emits a {Withdrawed} event upon successful withdrawal.

Parameters

Return Values

Last updated