Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Liquidity farming contract #3

Open
ilblackdragon opened this issue Mar 23, 2021 · 4 comments
Open

Liquidity farming contract #3

ilblackdragon opened this issue Mar 23, 2021 · 4 comments

Comments

@ilblackdragon
Copy link
Contributor

ilblackdragon commented Mar 23, 2021

Liquidity farm is initialized with some amount of token to release, period of time and set of LP tokens that are supported.

On LP tokens transfer to this contract, it starts to calculate the portion of reward allocated to these holders.

Later the LP tokens can be withdrawn and also the reward can be claimed.

Reference

@robert-zaremba
Copy link
Contributor

We are building Cheddar - a NEAR ecosystem wide farming network.

@ilblackdragon
Copy link
Contributor Author

ilblackdragon commented Apr 14, 2021

The idea to have a bit generic farm contract, that allows for anyone to create a farm for specific pool in Ref (or in other financial contracts with LP tokens) and receive reward from it.
Important is to support double farming - where the same LP tokens contribute to multiple pools.
For this, contract must maintain farms and deposited funds keyed by <exchange_id + ":" + pool_id>.
The calculation of farmed tokens should be lazy based on when LP tokens were deposited, the schedule of the farm and time of query.

Rough interaction:

  • Anyone can create a farm for a specific <exchange_id, pool_id>.
  • Farms are configured by the deposit of the full FT-141 token amount and specify the schedule: X tokens per day, this many days. More complex schedules can be added as well (based on amount of liquidity provided or other parameters or oracles).
  • Contract accepts LP token transfers into the farm. Given the exchange has many pools, the interface of regular FT reciever is extended with extra field "pool_id". Contract records who sent tokens (sender_id) from the exchange and when.
  • Support a view call for given user to calculate the current rate of the farming and total value received.
  • Allow to withdraw the farmed tokens, updating the state of the given user.
  • On withdrawal of LP tokens: calculate how much reward tokens left to withdraw and leave that on the balance for withdrawal.

UI then when adding liquidity, attaches extra action to call share_transfer_call to transfer the received shares to the farm.
Potentially, this may have an issue that if user's tx got after some other transaction changing this pool, the number of shares doesn't match. It might be worse extending #2 to add_liquidity have also support "transfer_call" to the full amount. Or share_transfer_call support None in the amount to transfer all shares.

@robert-zaremba
Copy link
Contributor

robert-zaremba commented Apr 14, 2021

I think the farming should be handled outside of the exchange contract - and each farming should be an independent contract. It gives more possibilities, and avoids the conflict of interest, letting users to decide as they want without involving a governance.

@ilblackdragon
Copy link
Contributor Author

ilblackdragon commented Apr 14, 2021

Yep, this is an external contract that LP tokens get deposited.

Is there a Cheddar design somewhere described timeline?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants