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

Parse AnyHedge transactions #151

Open
dagurval opened this issue Jan 6, 2021 · 1 comment
Open

Parse AnyHedge transactions #151

dagurval opened this issue Jan 6, 2021 · 1 comment

Comments

@dagurval
Copy link

dagurval commented Jan 6, 2021

Like we do for flipstarter and voter.cash transactions, we can identify AnyHedge transactions.

This is possible to parse from a transaction (quoting @rkalis from AnyHedge telegram):

Let me put it in pseudocode.

From the parsed tx, you have:

hedge payout satoshis
long payout satoshis
settlement price
funding transaction (outpoint)

From that you get:

total contract satoshis = hedge payout satoshis + long payout satoshis
hedge USD payout = (hedge payout satoshis / 1e8) * settlement price
long USD payout = (long payout satoshis / 1e8) * settlement price

By definition:

hedge USD payin = hedge USD payout

Then you look up the funding transaction's block timestamp (1 rpc call).
Then you look up the approximate BCH price at the time of funding (e.g. coingecko API). Note that this is an approximation, because we cannot know the exact price used in the contract funding.

From there you calculate:

approx hedge payin satoshis = (hedge USD payin / approx funding price) * 1e8
approx long payin satoshis = total contract satoshis - approx hedge payin satoshis
approx long USD payin = (approx long payin satoshis / 1e8) * approx funding price

From there you can calculate the long's approx profit/loss in terms of sats, $ or %.

Does that make sense? So it should be 1 rpc call + 1 price api call

We don't need to provide all that info, but that is what is possible.

@rkalis
Copy link

rkalis commented Jan 6, 2021

See https://gitlab.com/GeneralProtocols/anyhedge/library/-/blob/development/examples/parse-settlement-transaction.js for a code example of how to use the AnyHedge library to parse settlement transactions.

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