-
Notifications
You must be signed in to change notification settings - Fork 35
Trade optimizer specification
Status: DRAFT
The c-org smart-contract provides a primary market for FAIRs: Anyone can buy and anyone can sell to the bonding curve. However, there is a significant spread between the buy price and sell price, leaving ample space for secondary market trading. Of course, this secondary market trading could happen on exchanges but we'd like to provide a more integrated and convenient solution. We can do it by creating a Uniswap market with a pair DAI/FAIR specific to the organization. FAIR holders could then decide to act as liquidity providers for this Uniswap market and earn Uniswap fees for doing it.
However, the existence of 2 markets in parallels (the primary market materialized by the c-org smart-contract and the secondary market materialized by the Uniswap smart-contract) poses a challenge for the investor as he/she nows needs to optimize his trade between the 2 markets.
Indeed, buying on the primary market might not be optimal if you can buy FAIRs cheaper on the secondary market. Likewise, buying on the secondary market might not be optimal if the price slippage is such that the price on the secondary market now surpasses the price of FAIR on the primary market.
The goal of this contract is to create an on-chain trade optimizer that, for a given trade (buy or sell), will optimize the trade between the primary and secondary market.
-
market1
. Address of the c-org smart-contract (Primary Market). -
market2
. Address of the Uniswap exchange contract (Secondary Market).
The contract will expose 2 functions: buy
and sell
.
-
input variables:
-
amount
. the amount of currency (i.e. DAI) the investor is sending to buy FAIRs. -
minimum
. the minimum amount of FAIRs the investor wants to have foramount
of currency. Transaction should fail otherwise. -
to
. the address to which the FAIRs should be sent.
-
-
algorithm:
- if not(
to
) thento=caller_address
- read
X
=latest issuance price onmarket1
- calculate
Y
=future price onmarket2
if amount is bought onmarket2
[calculus to be provided] - if
Y
<=X
then-
P1
=market1.buy(amount,minimum)
-
P2
=0
-
- if
Y
>X
then- calculate
Z
=amount to buy onmarket2
so that -
Y
=X
[calculus to be provided] -
P1
=market1.buy(amount-Z,minimum*(amount-Z)/amount)
-
P2
=market2.buy(Z)
- calculate
transfer(P1+P2,to)
- if not(
Note1: the calls to market1.buy()
and market2.buy()
could fail due to a lack of authorizations. Typically, if the address of the caller is not KYCed, which is verified via the TPL contract at the c-org contract level and at the FAIR token contract level.
Note2: It seems hard to enforce strong guarantees regarding the minimum amount of FAIRs that will be returned when Y
>X
because market2.buy()
could return a amount of FAIRs much lower than anticipated when the calculation was done. What do you think?
- input variables:
-
amount
. the amount of FAIRs the investor is sending to redeem currency (i.e. DAI). -
minimum
. the minimum amount of currency the investor wants to have for theamount
of FAIRs he's sending. Transaction should fail otherwise.
-
[TO BE FINISHED 👇]
- algorithm:
- read
X
=latest issuance price onmarket1
- calculate
Y
=future price onmarket2
if amount is bought onmarket2
[calculus to be provided] - if
Y
<=X
then-
P1
=market1.buy(amount,minimum)
-
P2
=0
-
- if
Y
>X
then- calculate
Z
=amount to buy onmarket2
so that -
Y
=X
[calculus to be provided] -
P2
=market2.buy(Z)
-
P1
=market1.buy(amount-Z,minimum-P)
- calculate
transfer(P1+P2,to)
- read
[/TO BE FINISHED ☝]
- Implement the trade-optimizer smart-contract in Solidity.
- Test it extensively with a c-org contract and the associated uniswap exchange.
- Be available to answer questions from the auditors and to fix what needs to be fixed.