dhedge / dhedge-docs

MIT License
5 stars 3 forks source link

[Bounty] Add new data for dHEDGE Pools in the subgraph #2

Open itsahedge opened 3 years ago

itsahedge commented 3 years ago

Prize Title

Add new data for dHEDGE Pools in the subgraph

Prize Bounty

5000 USDC (ERC20)

Challenge Description

At the moment, a Pool's performance (%) on dHEDGE is calculated via our internal backend API. Ideally, this data should be accessible to any developer so the protocol could be adopted in more front-ends/other systems.

Solution

The dHEDGE Subgraph needs a new variable performance to be added onto the Pool entity.

Performance should represent the pool manager’s trading performance, adjusted for any pending fees and direct transfers of synthetic assets into the pool.

Performance should track the pool's trading performance as a big integer, where:

Calculations

Performance calculation is as follows:

pool.performance = pool.fundValue / ( pool.totalSupply + pool.availableManagerFee ) * pool.performanceFactor

Variables

pool.availableManagerFee = pool.availableManagerFee()

pool.availableManagerFee

pool.fundValue & pool.totalSupply

pool.performanceFactor

The formula for adjusting performanceFactor is as follows:

Without Performance Factor:

With Performance Factor:

Submission Requirements

A valid submission would be a demo showcasing the accurate performance of Pools queried by the subgraph. The dhedge subgraph can be forked and re-deployed under participants own account on The Graph.

Judging Criteria

Winner Announcement Date

Winners will be announced at the conclusion of Open-Defi hackathon

Resources

gitcoinbot commented 3 years ago

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


This issue now has a funding of 5000.0 USDC (5000.0 USD @ $1.0/USDC) attached to it.

gitcoinbot commented 3 years ago

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


Work has been started.

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

1) nemani has started work.

We are going to add the performance variable to the Pool entity in the subgraph code. We have worked with subgraphs previously for open source projects. 2) l0c4t0r has started work.

I will add the required data to the subgraph. 3) carlosolivierarocha has started work.

project for dhedge bounty 4) ivangrand-tteb has started work.

New data for DHEDGE pools in subgraph. 5) gitcoindeveloper has started work.

At the moment, a Pool's performance (%) on dHEDGE is calculated via our internal backend API. Ideally, this data should be accessible to any developer so the protocol could be adopted in more front-ends/other systems.

Solution The dHEDGE Subgraph needs a new variable performance to be added onto the Pool entity.

Performance should represent the pool manager’s trading performance, adjusted for any pending fees and direct transfers of synthetic assets into the pool.

Performance should track the pool's trading performance as a big integer, where:

1e18 = 0% return 2e18 = +100% return 5e17 = -50% return Calculations Performance calculation is as follows:

pool.performance = pool.fundValue / ( pool.totalSupply + pool.availableManagerFee ) * pool.performanceFactor

Variables pool.availableManagerFee = pool.availableManagerFee()

pool.availableManagerFee

Calculation should take into account the available manager fee. This is any performance fee owed to the manager as additional pool tokens which can be minted at any time for good trading performance. pool.fundValue & pool.totalSupply

These variables are already available in the subgraph. pool.performanceFactor

If there is a direct transfer of Synthetix synth ERC20s into the pool, the pool's performance should remain unchanged. To account for this, add another new pool variable, performanceFactor. performanceFactor can start at value 1, and decrease towards 0 if there is any value directly transferred into the pool. On pool creation: pool.performanceFactor = 1; If there is a direct transfer of Synthetix ERC20s (eg. sUSD, sETH), which bypass the smart contract deposit / withdraw functions, then the performanceFactor needs to be adjusted to take into account the direct deposit to reflect the true performance from the manager's trades. The formula for adjusting performanceFactor is as follows:

If there is a Synthetix synth ERC20 direct transfer into the pool (not using the pool contract deposit() method), Then: new performanceFactor = performanceFactor * fundValue / (fundValue + valueDeposited) valueDeposited = dollar value of the synth deposit (could be sUSD, sETH, sBTC, etc)` Without Performance Factor: Manager starts a pool and seeds it with $100 sUSD (Performance Factor = 1) Manager direct deposits another $100 sUSD (Performance Factor = 1) The pool performance is now +100% This is Not a true reflection of the pool's trading performance. With Performance Factor: Manager starts a pool and seeds it with $100 sUSD (Performance Factor = 1) Manager direct deposits another 100 sUSD (The subgraph detects the sUSD direct deposit and decreases the Performance Factor from 1 to 0.5) The pool performance is still 0% This Is a true reflection of the pool's trading performance. Submission Requirements A valid submission would be a demo showcasing the accurate performance of Pools queried by the subgraph. The dhedge subgraph can be forked and re-deployed under participants own account on The Graph.

Judging Criteria Meets the tech requirements Clean code Winner Announcement Date Winners will be announced at the conclusion of Open-Defi hackathon

Resources dHEDGE Docs: https://docs.dhedge.org/ dHEDGE Subgraph: https://thegraph.com/explorer/subgraph/dhedge/dhedge The Graph Docs: https://thegraph.com/docs/ dHEDGE Discord: https://discord.gg/BAWTbRA The Graph Discord: https://discord.gg/vtvv7FP

Learn more on the Gitcoin Issue Details page.

carlosolivierarocha commented 3 years ago
pool.performance = pool.fundValue / ( pool.totalSupply + pool.availableManagerFee ) * pool.performanceFactor

@hedgedon ok to use protofire/subgraph-toolkit to cast BigDecimal (RHS) to BigInt (LHS)?

P.S. It is used by Maker, Curve etc subgraphs.

itsahedge commented 3 years ago
pool.performance = pool.fundValue / ( pool.totalSupply + pool.availableManagerFee ) * pool.performanceFactor

@hedgedon ok to use protofire/subgraph-toolkit to cast BigDecimal (RHS) to BigInt (LHS)?

P.S. It is used by Maker, Curve etc subgraphs.

Yes it should be fine.

gitcoinbot commented 3 years ago

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


Work for 5000.0 USDC (5000.00 USD @ $1.0/USDC) has been submitted by:


gitcoinbot commented 3 years ago

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


Work for 5000.0 USDC (5000.00 USD @ $1.0/USDC) has been submitted by:

  1. @sekmet

@hedgedon please take a look at the submitted work: