Page MenuHomePhabricator

[ecash-lib] Add agora advertisements (ads) of offers for AgoraOneshot
ClosedPublic

Authored by tobias_ruck on May 4 2024, 00:26.

Details

Summary

Currently, ecash-agora can be used to broadcast offers on the network, but it's impossible to find them purely by looking at the blockchain, as the Agora covenant is in a P2SH, which is irreversible.

Ideally, we'd put the offer data into an OP_RETURN, however, for SLP, the OP_RETURN is fully occupied with SLP data, so we have to put it somewhere else. One proven method is to put it into the scriptSig, which we do in this diff:

A scriptSig advertising a oneshot offer will look like this:

"AGR0"
"ONESHOT"
<sellerSig>
<redeemScript with the terms>
  • AgoraOneshot gets a method adScript, which builds a script that, when spent using AgoraOneshotAdSignatory, will advertise the terms of the offer on the chain.
  • AgoraOneshot.fromRedeemScript will reconstruct the terms of an advertisement based on the redeemScript.
  • parseAgoraTx will parse a Tx coming from Chronik as Agora tx, returning ParsedAd, parsing the terms, but also verifying the output actually matches the terms, to avoid trying to spend an offer that actually doesn't have the advertised terms in the P2SH.

ParsedAd's definition is intended to be easy to extend with other kinds of terms.

Depends on D16088

Test Plan

BUILD_DIR=../../build npm run integration-tests

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Fabien requested changes to this revision.May 6 2024, 08:14
Fabien added a subscriber: Fabien.
Fabien added inline comments.
modules/ecash-agora/src/ad.ts
1 ↗(On Diff #47611)

missing header (and probably in other files)

This revision now requires changes to proceed.May 6 2024, 08:14

add copyright, fix comments in oneshot.test.ts

bytesofman requested changes to this revision.May 6 2024, 21:30

It is a bit complicated to setup these txs. Not too big of a deal since will be handled by devs and not users.

What happens if someone puts up an SLP one shot agora tx without the preceding ad tx? It's there but just a mystery as to how to spend it? If this happens, can the original seller still cancel easily?

modules/ecash-agora/src/ad.ts
58 ↗(On Diff #47633)

is the intention to implement for ALP in this same function later?

this is ok as a placeholder but otherwise we do not really get much info about what happened here as a user from 'Not implemented'.

why do we throw an error here but return undefined for other unsupported conditions?

129 ↗(On Diff #47633)

is 3 the expected amount of ops we should see in this tx?

label as a const to avoid magic number

modules/ecash-agora/tests/oneshot.test.ts
457 ↗(On Diff #47633)
This revision now requires changes to proceed.May 6 2024, 21:30

It is a bit complicated to setup these txs. Not too big of a deal since will be handled by devs and not users.

Yeah, it's not ideal. But after IMO this is the simplest way without breaking the SLP spec. And some day we'll (hopefully) get atomic broadcasts for multiple txs which will reject the setup tx if the offer tx fails.

And it's nothing compared to what BCH is doing with some CashToken stuff or BTC with ordinary Lightning—not that that excuses it but once you delve into DeFi you quickly run into complexity.

What happens if someone puts up an SLP one shot agora tx without the preceding ad tx? It's there but just a mystery as to how to spend it?

For all others, it'll be just like any other P2SH whose redeemScript is unknown. An unspendable black box.

If this happens, can the original seller still cancel easily?

Yes, they can invoke the OP_ELSE branch that allows them to cancel the trade.

modules/ecash-agora/src/ad.ts
58 ↗(On Diff #47633)

is the intention to implement for ALP in this same function later?

Yes, although the parsing will look different.

why do we throw an error here but return undefined for other unsupported conditions?

Good point. This will be hard to use in practice currently.

129 ↗(On Diff #47633)

No, it's the minimum bound before the function would break—there has to be at least a LOKAD_ID, a covenant variant and a redeemScript.

Since it's an internal variant I thought it would be fine, but something like MIN_NUM_SCRIPTSIG_PUSHOPS could be better.

fix spelling, add const, return undefined for ALP for now

Fabien requested changes to this revision.May 10 2024, 07:49
Fabien added inline comments.
modules/ecash-agora/src/oneshot.ts
165 ↗(On Diff #47722)
This revision now requires changes to proceed.May 10 2024, 07:49
This revision is now accepted and ready to land.May 13 2024, 13:35