diff --git a/packages/sdk/src/constants/index.ts b/packages/sdk/src/constants/index.ts index 227a6694..4162c58e 100644 --- a/packages/sdk/src/constants/index.ts +++ b/packages/sdk/src/constants/index.ts @@ -7,3 +7,6 @@ export const MAXIMUM_FEE = 5000000 // Maximum number of bytes pushable to the witness stack export const MAXIMUM_SCRIPT_ELEMENT_SIZE = 520 + +// Maximum royalty percentage +export const MAXIMUM_ROYALTY_PERCENTAGE = 0.1 diff --git a/packages/sdk/src/inscription/collection.ts b/packages/sdk/src/inscription/collection.ts index ddf44d44..d0c40f48 100644 --- a/packages/sdk/src/inscription/collection.ts +++ b/packages/sdk/src/inscription/collection.ts @@ -1,5 +1,6 @@ import { BaseDatasource, GetWalletOptions, Inscriber, JsonRpcDatasource, verifyMessage } from ".." import { Network } from "../config/types" +import { MAXIMUM_ROYALTY_PERCENTAGE } from "../constants" export async function publishCollection({ title, @@ -17,8 +18,8 @@ export async function publishCollection({ } if (royalty) { - // 0 = 0%, 10 = 1000% - if (isNaN(royalty.pct) || royalty.pct < 0 || royalty.pct > 10) { + // 0 = 0%, 0.1 = 10% + if (isNaN(royalty.pct) || royalty.pct < 0 || royalty.pct > MAXIMUM_ROYALTY_PERCENTAGE) { throw new Error("Invalid royalty %") } diff --git a/packages/sdk/src/instant-trade/InstantTradeSellerTxBuilder.ts b/packages/sdk/src/instant-trade/InstantTradeSellerTxBuilder.ts index bf32536b..9e5c5019 100644 --- a/packages/sdk/src/instant-trade/InstantTradeSellerTxBuilder.ts +++ b/packages/sdk/src/instant-trade/InstantTradeSellerTxBuilder.ts @@ -52,9 +52,10 @@ export default class InstantTradeSellerTxBuilder extends InstantTradeBuilder { private async generateSellerOutputs() { const royalty = await this.calculateRoyalty() - this.outputs = [{ address: this.receiveAddress || this.address, value: this.price + this.postage }] + const royaltyAmount = royalty && royalty.amount >= MINIMUM_AMOUNT_IN_SATS ? royalty.amount : 0 + this.outputs = [{ address: this.receiveAddress || this.address, value: this.price + this.postage - royaltyAmount }] - if (royalty && royalty.amount >= MINIMUM_AMOUNT_IN_SATS) { + if (royalty && royaltyAmount) { this.outputs.push({ address: royalty.address, // creator address value: royalty.amount // royalty in sats to be paid to original creator