@signet-base/cli 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signet-base/cli",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "CLI for Signet onchain advertising — list and post spotlight ads",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,33 +1,44 @@
1
+ import { createPublicClient, http } from "viem";
2
+ import { base } from "viem/chains";
1
3
  import { fetchSignatures } from "../api.js";
2
4
 
5
+ const SIGNET_CONTRACT = "0xd53A6Ff418a5647704032089F64D9f0c5Ac958B0";
6
+ const SIGNET_ABI = [
7
+ {
8
+ inputs: [],
9
+ name: "getSignatureCount",
10
+ outputs: [{ type: "uint256" }],
11
+ stateMutability: "view",
12
+ type: "function",
13
+ },
14
+ ];
15
+
16
+ async function getSignatureCount() {
17
+ const client = createPublicClient({
18
+ chain: base,
19
+ transport: http(),
20
+ });
21
+ const count = await client.readContract({
22
+ address: SIGNET_CONTRACT,
23
+ abi: SIGNET_ABI,
24
+ functionName: "getSignatureCount",
25
+ });
26
+ return Number(count);
27
+ }
28
+
3
29
  export async function list(opts) {
4
30
  const count = parseInt(opts.count);
5
31
 
6
32
  try {
7
- // Find the latest signature index by probing
8
- let high = 100;
9
- let latestIndex = -1;
10
-
11
- // Quick probe to find approximate range
12
- for (const probe of [1000, 500, 100, 50, 20, 10]) {
13
- const { signatures } = await fetchSignatures(Math.max(0, probe - 1), probe, opts.baseUrl);
14
- if (signatures?.length > 0) {
15
- latestIndex = Math.max(latestIndex, ...signatures.map(s => s.signatureIndex));
16
- break;
17
- }
18
- }
33
+ const total = await getSignatureCount();
19
34
 
20
- // If no high index found, try from 0
21
- if (latestIndex < 0) {
22
- const { signatures } = await fetchSignatures(0, 9, opts.baseUrl);
23
- if (!signatures?.length) {
24
- console.log("No signatures found.");
25
- return;
26
- }
27
- latestIndex = Math.max(...signatures.map(s => s.signatureIndex));
35
+ if (total === 0) {
36
+ console.log("No signatures found.");
37
+ return;
28
38
  }
29
39
 
30
- // Fetch the most recent signatures
40
+ // Fetch the most recent signatures (0-indexed)
41
+ const latestIndex = total - 1;
31
42
  const startIndex = Math.max(0, latestIndex - count + 1);
32
43
  const { signatures } = await fetchSignatures(startIndex, latestIndex, opts.baseUrl);
33
44
 
@@ -38,11 +49,10 @@ export async function list(opts) {
38
49
 
39
50
  // Sort descending (most recent first)
40
51
  signatures.sort((a, b) => b.signatureIndex - a.signatureIndex);
41
- const display = signatures.slice(0, count);
42
52
 
43
- console.log(`\nšŸ“‹ Recent Signet Signatures (${display.length})\n`);
53
+ console.log(`\nšŸ“‹ Recent Signet Signatures (${signatures.length} of ${total})\n`);
44
54
 
45
- for (const sig of display) {
55
+ for (const sig of signatures) {
46
56
  const date = new Date(sig.timestamp * 1000).toLocaleDateString();
47
57
  const hunt = (Number(sig.huntAmount) / 1e18).toFixed(2);
48
58
  const title = sig.metadata?.title || "(no title)";