Skip to content

Commit

Permalink
feat(sdk): deduct royalty from seller price & cap to 10% (#84)
Browse files Browse the repository at this point in the history
* feat: deduct royalty from seller price

* feat: restrict max royalty to 10%
  • Loading branch information
iamcrazycoder authored Oct 18, 2023
1 parent fa769f6 commit 0f6cd96
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/sdk/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions packages/sdk/src/inscription/collection.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 %")
}

Expand Down
5 changes: 3 additions & 2 deletions packages/sdk/src/instant-trade/InstantTradeSellerTxBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0f6cd96

Please sign in to comment.