Skip to content

Commit

Permalink
feat(sdk): add the ability to inject royalty (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevzzsk authored May 27, 2024
1 parent d3950a8 commit 2d8de57
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion packages/sdk/src/instant-trade/InstantTradeSellerTxBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ import InstantTradeBuilder, { InstantTradeBuilderArgOptions } from "./InstantTra

interface InstantTradeSellerTxBuilderArgOptions extends InstantTradeBuilderArgOptions {
receiveAddress?: string
injectRoyalty?: { address: string; pct: number } // pct is in percentage 0 - 1, 1 being 100%
}

export default class InstantTradeSellerTxBuilder extends InstantTradeBuilder {
private receiveAddress?: string
private utxo?: UTXO
private readonly injectRoyalty

constructor({
address,
datasource,
network,
publicKey,
inscriptionOutpoint,
receiveAddress
receiveAddress,
injectRoyalty
}: InstantTradeSellerTxBuilderArgOptions) {
super({
address,
Expand All @@ -33,6 +36,7 @@ export default class InstantTradeSellerTxBuilder extends InstantTradeBuilder {
})

this.receiveAddress = receiveAddress
this.injectRoyalty = injectRoyalty
}

private async generatSellerInputs() {
Expand Down Expand Up @@ -65,6 +69,21 @@ export default class InstantTradeSellerTxBuilder extends InstantTradeBuilder {
}

private async calculateRoyalty() {
if (this.injectRoyalty) {
if (this.injectRoyalty.pct <= 0) {
throw new OrditSDKError("Invalid royalty percentage")
}
if (!this.injectRoyalty.address) {
throw new OrditSDKError("Invalid royalty address")
}
this.setRoyalty({
price: this.price,
amount: Math.ceil(this.injectRoyalty.pct * this.price),
receiver: this.injectRoyalty.address,
percentage: this.injectRoyalty.pct
})
return
}
if (!this.inscription || !this.inscription.meta?.col) {
return
}
Expand Down

0 comments on commit 2d8de57

Please sign in to comment.