> For the complete documentation index, see [llms.txt](https://docs.equiteez.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.equiteez.com/platform/secondary-markets/technical-overview-of-the-rwa-orderbook-dex.md).

# Technical Overview of the RWA Orderbook DEX

Technical Overview of Entry Points and Contract Functions

Below are the key entry points and their corresponding functionalities within the RWA Orderbook contract.

#### A) SuperAdmin Entry Points

* Description: Sets a new SuperAdmin contract address.
* Description: Allows the newly set SuperAdmin to claim control of the contract.
* Description: Sets the KYC (Know Your Customer) address for verifying user compliance.
* Parameters: updateMetadataParams : updateMetadataType
* Description: Allows the Admin to update contract metadata.
* Description:&#x20;
* Description: Admins can transfer tokens that were mistakenly sent to the contract.

#### `%setSuperAdmin`

`Parameters: newSuperAdminAddress : address`

Entrypoint that can only be called by the superAdmin contract to set a new superAdmin contract.

#### `%claimSuperAdmin`

`Parameters: none`

Entrypoint that can only be called by a new superAdmin contract that had previously been set.

#### B) Admin Entry Points

#### `%setKycAddress`

`Parameters: newKycAddress : address`

Entrypoint that can only be called by a new superAdmin contract that had previously been set.

#### `%updateMetadata`

`Parameters: updateMetadataParams : updateMetadataType`

`type updateMetadataType is [@layout:comb] record [`

&#x20;   `metadataKey           : string;`

&#x20;   `metadataHash          : bytes;`&#x20;

`]`

Admin can update the contract metadata

#### `%updateConfig`

`Parameters: updateConfigParams : updateConfigActionType`

`// config`

`type rwaOrderbookConfigType is [@layout:comb] record [`

&#x20; &#x20;

&#x20;   `minExpiryTime               : nat; //`&#x20;

&#x20;  `minTimeBeforeClosingOrder   : nat; // prevent spam e.g. 1mins`

&#x20;   `minBuyOrderAmount           : nat; // prevent spam - rwa token amount`&#x20;

&#x20;   `minBuyOrderValue            : nat; // prevent spam - value of rwa token amount to buy`<br>

&#x20;   `minSellOrderAmount          : nat; // prevent spam - rwa token amount`&#x20;

&#x20;   `minSellOrderValue           : nat; // prevent spam - value of rwa token amount to sell`

&#x20;   `buyOrderFee                 : nat; // 4 decimals`

&#x20;   `sellOrderFee                : nat; // 4 decimals`

`]`

Admin can update the config of the RWA Orderbook contract

#### `%mistakenTransfer`

`Parameters: mistakenTransferParams : transferActionType`

Admin can transfer mav or tokens that had mistakenly been sent to the contract

#### C) Pause/Break Glass Entry Points

#### `%togglePauseEntrypoint`

`Parameters: togglePauseEntrypointParams : rwaOrderbookTogglePauseEntrypointType`

`type rwaOrderbookPausableEntrypointType is`

&#x20;       `PlaceBuyOrder           of bool`

&#x20;   `|   PlaceSellOrder          of bool`

&#x20;   `|   CancelOrder             of bool`

&#x20;  &#x20;

`type rwaOrderbookTogglePauseEntrypointType is [@layout:comb] record [`

&#x20;   `targetEntrypoint  : rwaOrderbookPausableEntrypointType;`

&#x20;   `empty             : unit`

`];`

Admin can pause or unpause entrypoints on the RWA Orderbook contract

#### D) Orderbook Admin Entry Points

#### `%setCurrency`

`Parameters: setCurrencyAction : setCurrencyActionType`

`type setCurrencyActionType is [@layout:comb] record [`

&#x20;   `actionType  : string;`    &#x20;

&#x20;   `name        : string;`

&#x20;   `decimals    : nat;`

&#x20;   `token       : currencyTokenType;`

`]`

Admin can set the valid currencies (e.g. USDT/USDC token) to be used on the RWA Orderbook contract

#### `%transferFees`

`Parameters: transferFeesAction : transferFeesActionType`

`type transferFeesActionType is [@layout:comb] record [`

&#x20;   `receiver : address;`

&#x20;   `currencySet : set(string);`

`]`

Admin can transfer accumulated trading fees on the RWA Orderbook contract to a specified address

#### `%adminCancelOrders`

`Parameters: adminCancelOrdersParams : list(orderIdAndTypeSingle)`

`type orderIdAndTypeSingle is [@layout:comb] record [`

&#x20;   `orderId : nat;`

&#x20;   `orderType : string;`

`]`

`type adminCancelOrdersActionType is list(orderIdAndTypeSingle)`

Admin can cancel a list of buy or sell orders by their order ID

#### `%clearExpiredOrders`

`Parameters: clearExpiredOrdersParams : list(orderIdAndTypeSingle)`

`type orderIdAndTypeSingle is [@layout:comb] record [`

&#x20;   `orderId : nat;`

&#x20;   `orderType : string;`

`]`

`type clearExpiredOrdersActionType is list(orderIdAndTypeSingle)`

Admin can clear expired buy or sell orders by their order ID

#### `%matchOrders`

`Parameters: numberOfOrdersToMatch : int`

This entry point should be called regularly by a trusted source (e.g. Admin) to match orders in the RWA Orderbook contract

#### E) Orderbook Entry Points

#### `%placeBuyOrder`

`Parameters: placeOrderActionParams : placeOrderActionType`

`type placeSingleOrderType is [@layout:comb] record [`

&#x20;   `rwaTokenAmount : nat;`&#x20;

&#x20;   `pricePerRwaToken : nat;`

&#x20;   `currency : string;                  // use USDT or USDC only`

&#x20;   `orderExpiry : option(timestamp);`

`]`

`type placeOrderActionType is list(placeSingleOrderType)`

Users can place a buy order for RWA Tokens. Currency tokens for the buy order will be transferred to the RWA Orderbook contract and held in escrow until orders are matched.

#### `%placeSellOrder`

`Parameters: placeOrderActionParams : placeOrderActionType`

`type placeSingleOrderType is [@layout:comb] record [`

&#x20;   `rwaTokenAmount : nat;`&#x20;

&#x20;   `pricePerRwaToken : nat;`

&#x20;   `currency : string;                  // use USDT or USDC only`

&#x20;   `orderExpiry : option(timestamp);`

`]`

`type placeOrderActionType is list(placeSingleOrderType)`

User can place a sell order for RWA Tokens. RWA tokens used for the buy order will be transferred to the RWA Orderbook contract to be held in escrow until orders are matched.

#### `%cancelOrder`

`Parameters: cancelOrdersParams : list(orderIdAndTypeSingle)`

`type orderIdAndTypeSingle is [@layout:comb] record [`

&#x20;   `orderId : nat;`

&#x20;   `orderType : string;`

`]`

`type cancelOrderActionType is list(orderIdAndTypeSingle)`

Users can cancel a list of buy orders or sell orders they have placed at any time, and be returned the corresponding amount of tokens they owe.

#### `%processRefund`

`Parameters: processRefundParams : list(orderIdAndTypeSingle)`

`type orderIdAndTypeSingle is [@layout:comb] record [`

&#x20;   `orderId : nat;`

&#x20;   `orderType : string;`

`]`

`type processRefundActionType is list(orderIdAndTypeSingle)`

Users with excess amounts left in their buy orders (from being matched with sell orders at lower prices) can process a refund of the corresponding tokens after their buy order is closed.

#### F) Lambda Entry points

#### `%setLambda`

`Parameters: setLambdaParams : setLambdaType`

Admins can set custom lambdas to implement specific contract behavior or automate actions.

<br>
