lparolari / wellets-backend

Manage your money placed in different portfolios.
https://wellets-api.ondaniel.com.br/
MIT License
2 stars 0 forks source link

Allow to manage liquidity pool/farms #19

Open lparolari opened 2 years ago

lparolari commented 1 year ago

We may model this concept in Wellet as an "investment".

An investment is the action of investing money for profit.

In Wellet, an investment is made of

where InvestmentItem is a tuple of (wallet_id, amount, dollar_rate) and eventually an alias. Each item should have a input_investment_item_id which can be used for the system to compute proper transaction.

A relevant detail is what happens when investment is closed. Closing an investment means reporting profit or loss to wallets from which liquidity where borrowed. Fees are not taken into account during this calculation and must be covered manually. The divestment is computed by populating the divestment list by updating all entries in investment list with current profit or loss.

Example

Suppose I want to invest in the ETH/CRO pool on vvs.finance. Please note that this farm is 50/50, so for the example when we start the investment 1 ETH = 100 CRO <==> 1 CRO = 0.01 ETH, for simplicity 1 USD = 1 CRO, that is 1 ETH = 100 USD.

investment list = [ (eth wallet, 1, 0.01,), (cro wallet, 100, 1) ]

then we farm & dump some VSS for CRO. In this example we farmed 200000 VVS which are equivalent to 20 CRO dumped when 1 CRO = 2 USD. In the meanwhile ETH performs good and makes a 2x on the price, but CRO go back to its original price 1 CRO = 1 USD.

When we close the investment we have:

Thus, the divestment list is equal to [ (eth wallet, 0.7, 0.005, prev investement item eth), (cro wallet, 20, 0.5), (cro wallet, 141.4, 1, prev investement item cro) ]

The system shall be able to report the divestment list as transaction to proper wallets by generating a transaction for each item in list on the given wallet. Items with prev investment item should compute a value = current amount - prev amount.

lparolari commented 1 year ago

Stories