Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions packages/cli/src/commands/claim.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Command } from "commander";
import type { Address } from "viem";
import { isAddress } from "viem";
import { type Address, erc20Abi, formatUnits, isAddress } from "viem";
import { buildClient } from "../sdk.js";

export function registerClaim(program: Command): void {
Expand All @@ -19,7 +18,21 @@ export function registerClaim(program: Command): void {

console.log("Checking royalties...");
const info = await client.getRoyaltyInfo(tokenAddress);
console.log(` Unclaimed: ${info.unclaimed}`);

// Fetch reserve token decimals dynamically
let decimals = 18;
try {
decimals = await client.publicClient.readContract({
address: tokenAddress,
abi: erc20Abi,
functionName: "decimals",
});
} catch {
// Default to 18 if decimals() call fails
}

const formatted = formatUnits(info.unclaimed, decimals);
console.log(` Unclaimed: ${formatted}`);
console.log(` Beneficiary: ${info.beneficiary}`);

if (info.unclaimed === 0n) {
Expand Down
Loading