Phoenix-Protocol-Group / phoenix-contracts

Source code of the smart contracts of the Phoenix DeFi hub DEX protocol
GNU General Public License v3.0
10 stars 6 forks source link

[Design document] Designated trader contract #287

Closed ueco-jb closed 2 months ago

ueco-jb commented 2 months ago

Abstract

The purpose of the designated trader contract is to convert into the $PHO token all of the fees gathered from each pair. That contract will be a recipient of the fees, which then will have to be traded using a preconfigured liquidity pools. When the fees are in one denom, they would be sent to a fee splitting contract (or directly to the origin's staking contract to fuel the staking rewards).

The point is to have each nominated trader for each trading pair - meaning, we'll have to deploy them after the staking contract. Reasoning for that - if we combine fees, we can't clearly tell how many


Messages

fn initialize(
    env: Env,
    admin: Address,
    contract_name: String,
    pair_addresses: (Address, Address),
    pho_token: Address,
    max_spread: Option<Decimal>
)

Initialize is simple, it supposed to set an admin in the storage. Admin is the only one allowed to add trade routes or configure the trading pairs to be expected. Name is required to make sure you are using the proper contract.

fn trade_token(
    env: Env,
    token_address: Address,
    liquidity_pool: Address,
    amount: Option<u64>
)

Trade tokens should check if it's one of the two that is configured and check the given token's balance on the contract. Then it tries to perform a trade using provided liquidity pool's contract. When trade is successful, this nominated trader should hold only PHO tokens.

fn transfer(
    env: Env,
    recipient: Address,
    amount: u64,
    token_address: Option<Address>,
)

Transfer tokens should allow the admin to withdraw transferred PHO tokens to a given recipient, for example fee splitter. It should be used by default for PHO tokens (from initialization), but let's include a token_address parameter in some case where tokens is getting stuck.


Queries

Make sure to include informations that are usable for the admin, for example balances which would quickly return amount of (configured) tokens that this contract supports.