Skip to content
Merged
Show file tree
Hide file tree
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
32 changes: 25 additions & 7 deletions packages/cli/src/commands/claim.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Command } from "commander";
import { type Address, erc20Abi, formatUnits, isAddress } from "viem";
import { MCV2_BOND_ADDRESS, mcv2BondAbi } from "@plotlink/sdk";
import { buildClient } from "../sdk.js";

export function registerClaim(program: Command): void {
Expand All @@ -19,20 +20,37 @@ export function registerClaim(program: Command): void {
console.log("Checking royalties...");
const info = await client.getRoyaltyInfo(tokenAddress);

// Fetch reserve token decimals dynamically
// Fetch reserve token address via tokenBond(), then read its decimals
let decimals = 18;
let symbol = "TOKEN";
try {
decimals = await client.publicClient.readContract({
address: tokenAddress,
abi: erc20Abi,
functionName: "decimals",
const bond = await client.publicClient.readContract({
address: MCV2_BOND_ADDRESS,
abi: mcv2BondAbi,
functionName: "tokenBond",
args: [tokenAddress],
});
const reserveToken = (bond as readonly unknown[])[4] as Address;
const [dec, sym] = await Promise.all([
client.publicClient.readContract({
address: reserveToken,
abi: erc20Abi,
functionName: "decimals",
}),
client.publicClient.readContract({
address: reserveToken,
abi: erc20Abi,
functionName: "symbol",
}),
]);
decimals = dec;
symbol = sym;
} catch {
// Default to 18 if decimals() call fails
// Default to 18/TOKEN if calls fail
}

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

if (info.unclaimed === 0n) {
Expand Down
16 changes: 12 additions & 4 deletions packages/cli/src/commands/status.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Command } from "commander";
import { createClient } from "@supabase/supabase-js";
import { type Address, erc20Abi, formatUnits } from "viem";
import { MCV2_BOND_ADDRESS, mcv2BondAbi } from "@plotlink/sdk";
import { buildClient } from "../sdk.js";
import { loadConfig } from "../config.js";

Expand Down Expand Up @@ -49,27 +50,34 @@ export function registerStatus(program: Command): void {
}

// -----------------------------------------------------------------
// 3. Reserve token metadata (symbol + decimals)
// 3. Reserve token metadata (symbol + decimals via tokenBond)
// -----------------------------------------------------------------
let tokenSymbol = "TOKEN";
let tokenDecimals = 18;
try {
const bond = await client.publicClient.readContract({
address: MCV2_BOND_ADDRESS,
abi: mcv2BondAbi,
functionName: "tokenBond",
args: [info.tokenAddress],
});
const reserveToken = (bond as readonly unknown[])[4] as Address;
const [sym, dec] = await Promise.all([
client.publicClient.readContract({
address: info.tokenAddress,
address: reserveToken,
abi: erc20Abi,
functionName: "symbol",
}),
client.publicClient.readContract({
address: info.tokenAddress,
address: reserveToken,
abi: erc20Abi,
functionName: "decimals",
}),
]);
tokenSymbol = sym;
tokenDecimals = dec;
} catch {
// Fall back to defaults if token doesn't support ERC-20 metadata
// Fall back to defaults if calls fail
}

// -----------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ export {
BASE_SEPOLIA_CHAIN_ID,
BASE_MAINNET_CHAIN_ID,
} from "./constants";

// Re-export ABIs for direct contract reads
export { mcv2BondAbi } from "./abi";
Loading