Skip to content

Commit

Permalink
fix: ⚡ royalty price precision
Browse files Browse the repository at this point in the history
  • Loading branch information
ignazio-bovo committed Aug 17, 2023
1 parent b312f9c commit 2d1167f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/**Versions.jsonl

# IDE files
/.vscode
/.idea
src/model/generated
/schema.graphql
Expand Down
6 changes: 3 additions & 3 deletions src/mappings/content/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ export async function addRoyaltyPaymentNotification(
}

export function computeRoyalty(royaltyPct: number, price: bigint): bigint {
const royaltyDecimal = royaltyPct / 100
const royaltyPrice = Math.floor(royaltyDecimal * Number(price))
return BigInt(royaltyPrice)
const scaledRoyalty = BigInt(Math.round(royaltyPct * 1e7)) // Scale to 10^7 and convert to bigint
const royaltyPrice = (scaledRoyalty * price) / BigInt(1e9) // Divide by 10^9 to account for scaling
return royaltyPrice
}
4 changes: 2 additions & 2 deletions src/server-extension/resolvers/ChannelsResolver/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ export class ChannelsResolver {
}
// otherwise create a new suspension
const newSuspension = new ChannelSuspension({
id: uniqueId(8),
id: uniqueId(),
channelId: channel.id,
timestamp: new Date(),
})
Expand Down Expand Up @@ -414,7 +414,7 @@ export class ChannelsResolver {
}
// othewise create new verification
const newVerification = new ChannelVerification({
id: uniqueId(8),
id: uniqueId(),
channelId: channel.id,
timestamp: new Date(),
})
Expand Down

0 comments on commit 2d1167f

Please sign in to comment.