-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: export arg-options type * feat: add base builder for instant trade * feat: add module to build trade tx for seller * feat: pass missing arg * refactor: update seller module * feat: add buyer module * feat: add getter to get inputs to sign * feat: add instant trade mode * feat: add method to split UTXO * feat: export instant-trade modules * refactor: add method to set price * refactor: change fn scope * refactor: remove fn cal * refactor: update import path * feat: add constructor signature for buffer-reverse * refactor: update script detector util * refactor: check inscription for external address * feat: decode seller psbt and extract outpoint+seller address * refactor: bind missing fee rate * feat: merge PSBTs using injectable inputs * fix: remove double multiplication of witness size * feat: merge PSBTs using injectable outputs * refactor: improvise injectable inputs * feat: add injectable inputs & outputs amount * revert: add instant trade restrictions * feat: add method to decode price from seller psbt * fix: attach bare minimum utxos * fix: improvise eligibility implementation * feat: pass injectable outputs * feat: update instant-buy example * fix: update build-psbt example * chore: add deprecation warning to instant-buy fns * fix: remove duplicate member from child class
- Loading branch information
1 parent
6833414
commit ee32996
Showing
15 changed files
with
560 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { OrditApi } from ".." | ||
import { MINIMUM_AMOUNT_IN_SATS } from "../constants" | ||
import { PSBTBuilder, PSBTBuilderOptions } from "../transactions/PSBTBuilder" | ||
|
||
export interface InstantTradeBuilderArgOptions extends Pick<PSBTBuilderOptions, "publicKey" | "network" | "address"> { | ||
inscriptionOutpoint?: string | ||
} | ||
|
||
export default class InstantTradeBuilder extends PSBTBuilder { | ||
protected inscriptionOutpoint?: string | ||
protected price = 0 | ||
protected postage = 0 | ||
|
||
constructor({ address, network, publicKey, inscriptionOutpoint }: InstantTradeBuilderArgOptions) { | ||
super({ | ||
address, | ||
feeRate: 0, | ||
network, | ||
publicKey, | ||
outputs: [], | ||
instantTradeMode: true | ||
}) | ||
|
||
this.address = address | ||
this.inscriptionOutpoint = inscriptionOutpoint | ||
} | ||
|
||
setPrice(value: number) { | ||
this.validatePrice(value) | ||
this.price = parseInt(value.toString()) | ||
} | ||
|
||
protected async verifyAndFindInscriptionUTXO(address?: string) { | ||
if (!this.inscriptionOutpoint) { | ||
throw new Error("set inscription outpoint to the class") | ||
} | ||
|
||
const { totalUTXOs, unspendableUTXOs } = await OrditApi.fetchUnspentUTXOs({ | ||
address: address || this.address, | ||
network: this.network, | ||
type: "all" | ||
}) | ||
if (!totalUTXOs) { | ||
throw new Error("No UTXOs found") | ||
} | ||
|
||
const utxo = unspendableUTXOs.find((utxo) => | ||
utxo.inscriptions?.find((i) => i.outpoint === this.inscriptionOutpoint) | ||
) | ||
if (!utxo) { | ||
throw new Error("Inscription not found") | ||
} | ||
|
||
this.postage = utxo.sats | ||
return utxo | ||
} | ||
|
||
protected validatePrice(price: number) { | ||
if (isNaN(price) || price < MINIMUM_AMOUNT_IN_SATS) { | ||
throw new Error("Invalid price") | ||
} | ||
} | ||
} |
Oops, something went wrong.