Skip to content

Parse AnyHedge transactions #151

@dagurval

Description

@dagurval

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions