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

Bug(s) Fix: Leveraged Positions Smart Contract Example #31

Closed
mikedeshazer opened this issue Jan 22, 2020 · 13 comments
Closed

Bug(s) Fix: Leveraged Positions Smart Contract Example #31

mikedeshazer opened this issue Jan 22, 2020 · 13 comments

Comments

@mikedeshazer
Copy link
Member

mikedeshazer commented Jan 22, 2020

The Leverage Facility Token example smart contract (contracts/examples/ConsumeDataExample/ levFacilityTokenExample.sol) was created to do the following (most of which works/there is semi-working code for):

  1. Allow a person/organization to create a token with the initial price pegged to the price of a stock (in the example Alibaba, but could be any that OrFeed currently supports). The creator/owner has to over-collateralize because the token contract also serves as a facility for people to place opinionated (long or short) bets and add leverage (1x to 10x). Additionally, anyone can mint tokens by overcollaterlizing. The creators and minters get rewards when people close positions that go against a trader, and lose funds when positions go for traders. The idea being, with a small fee, that given the random walk theory of markets, the house (creators/owner) always win because 1) odds are slightly in their favor if you add fees (even with 50/50), and 2) traders keep trading and eventually lose their money... it's just the nature of the universe... and ... er gambling.
  2. Allow participants (anyone) to open positions with leverage (both long and short), with the token creator and facility token minters' collateral being the counterparty funds for a trade
  3. When a user closes a position that goes in their favor (their leverage is calculated and collateral funds are sent to the user). When the user closes the position that goes against their favor (part or all of their funds are added into the collateral pool, a percentage of which can be pulled out by the minters/owner as reward for collateralizing an acting as a counter-party).
  4. When there is not enough collateral from minters/owner to pay a position reward, what can be afforded to be paid is paid out, while collateralization is maintained so that other participants that are in positions can withdraw their funds... in this case, the owner/minters would only be able to get up to 25% or so of their funds back).
  5. Throughout this whole flow the actual tokens/not positions are tradable on uniswap etc. Ideally we would integrate the code from the same directory so when token is launched it automatically launches a Uniswap market as well.

Much of the base code is there but some of the functionality is not working/math is a bit janky. First big step we need to achieve is to lay out all the things that are not working or could work better. Please leave comments/ideas if you intend to contribute (and much thanks by the way), and we can collaborate ourselves towards a capital efficient (leverage), opinionated (long and short) future!

@mikedeshazer mikedeshazer changed the title levFacilityTokenExample.sol Doesn't Work Properly Bug Fix: Leveraged Positions Smart Contract Example Jan 22, 2020
@mikedeshazer mikedeshazer changed the title Bug Fix: Leveraged Positions Smart Contract Example Bug(s) Fix: Leveraged Positions Smart Contract Example Jan 22, 2020
@gitcoinbot
Copy link

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


This issue now has a funding of 1.2 ETH (203.51 USD @ $169.59/ETH) attached to it as part of the ProofSuite fund.

@gitcoinbot
Copy link

gitcoinbot commented Jan 22, 2020

Issue Status: 1. Open 2. Cancelled


Work has been started.

These users each claimed they can complete the work by 1 month, 1 week ago.
Please review their action plans below:

1) dale-q has started work.

I will try to write good smart contract
2) luizfelipe3425 has started work.

Vou tentar faser uma verificação nesse caso ok
3) joramowuor has started work.

to lay whichway to reduce ,usage use of .scr limiting ,kernel insert(ping),rcharging with caution,servicing kde.

Learn more on the Gitcoin Issue Details page.

@mul1sh
Copy link

mul1sh commented Feb 10, 2020

Hey @mikedeshazer just to clarify. So it seems 1, 2, 3 are done only 4 and 5 are missing correct? I'm currently looking into this and would like to solve it today 🙂

@mikedeshazer
Copy link
Member Author

@mul1sh mostly yes. Looking forward to reviewing the code!

@mul1sh
Copy link

mul1sh commented Feb 18, 2020

hey @mikedeshazer i've been going through this contract extensively for the past few days and trying to find and fix all the bugs i found. And the only bugs I seem to found relate to no. 4 only and a few syntax warnings, everything else is working as it should, apart also from the uniswap part which will be a later functionality.

So my question is, were you able to find any bugs or is there anything else i've missed?

@mikedeshazer
Copy link
Member Author

@mul1sh #3 is not in the contract. The contract misses the calculations for positions/settlement

@Devilla
Copy link

Devilla commented Feb 19, 2020

@mikedeshazer orfeed.getExchangeRate() isn't returning values for kovan and rinkeby.
https://kovan.etherscan.io/address/0x31a29958301c407d4b4bf0d53dac1f2d154d9d8d#readContract

image

@mul1sh
Copy link

mul1sh commented Feb 19, 2020

Ahh ok, I see it now.

@mul1sh
Copy link

mul1sh commented Feb 24, 2020

@mikedeshazer actually still on no 3, I can see the settlements are being calculated and issued based on the difference of the asset price so this is also done or i'm missing something? Also shouldn't the leverage be set by the user, based on a global leverage ratio, before opening a position? This way you can easily tell whether a user made a profit or loss from their bet and reward them accordingly.

@mul1sh
Copy link

mul1sh commented Feb 24, 2020

Also by how much should the pegged token be over-collaterized should it fixed during contract creation i.e. hard code 50% where for each pegged token to mint you need atleast double the value in ether or dynamic as set by the minter

@mikedeshazer
Copy link
Member Author

@mul1sh yes leverage is set by user. On settlement it is calculated and distributed.

@dzhelezov
Copy link

Is there still anything left to work on?

@gitcoinbot
Copy link

Issue Status: 1. Open 2. Cancelled


The funding of 1.2 ETH (226.68 USD @ $188.9/ETH) attached to this issue has been cancelled by the bounty submitter

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

Successfully merging a pull request may close this issue.

5 participants