@0xward/proofofalpha-core 1.0.5 → 1.0.6
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/index.js +154 -5
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,10 +1,159 @@
|
|
|
1
|
-
//
|
|
1
|
+
// @0xward/proofofalpha-core
|
|
2
|
+
// Full on-chain intelligence ecosystem built on Celo
|
|
3
|
+
// Forensic wallet analysis, arena leaderboard, and DeFi vault routing
|
|
4
|
+
|
|
5
|
+
const SUPPORTED_NETWORKS = {
|
|
6
|
+
celo: { rpc: "https://forno.celo.org", chainId: 42220, currency: "CELO" },
|
|
7
|
+
alfajores: { rpc: "https://alfajores-forno.celo-testnet.org", chainId: 44787, currency: "CELO" },
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const TIER_THRESHOLDS = [
|
|
11
|
+
{ tier: "Alpha", minScore: 900, color: "#FFD700" },
|
|
12
|
+
{ tier: "Beta", minScore: 700, color: "#C0C0C0" },
|
|
13
|
+
{ tier: "Gamma", minScore: 500, color: "#CD7F32" },
|
|
14
|
+
{ tier: "Delta", minScore: 250, color: "#4A90D9" },
|
|
15
|
+
{ tier: "Epsilon", minScore: 0, color: "#888888" },
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
const RECOMMENDED_VAULTS = {
|
|
19
|
+
high: ["Aave-V3-CELO", "Ubeswap-CELO-cUSD", "Mento-cStables"],
|
|
20
|
+
medium: ["Aave-V3-cUSD", "Curve-Celo-Pool"],
|
|
21
|
+
low: ["Aave-V3-cEUR"],
|
|
22
|
+
};
|
|
23
|
+
|
|
2
24
|
class ProofOfAlpha {
|
|
25
|
+
constructor(config = {}) {
|
|
26
|
+
const network = config.network || "celo";
|
|
27
|
+
if (!SUPPORTED_NETWORKS[network]) {
|
|
28
|
+
throw new Error(`Unsupported network: "${network}". Use "celo" or "alfajores".`);
|
|
29
|
+
}
|
|
30
|
+
this.network = SUPPORTED_NETWORKS[network];
|
|
31
|
+
this.networkName = network;
|
|
32
|
+
this.version = "1.0.6";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
_validateAddress(address) {
|
|
36
|
+
if (typeof address !== "string" || address.trim().length === 0) {
|
|
37
|
+
throw new Error("Wallet address must be a non-empty string.");
|
|
38
|
+
}
|
|
39
|
+
const isEVM = /^0x[0-9a-fA-F]{40}$/.test(address);
|
|
40
|
+
if (!isEVM) {
|
|
41
|
+
throw new Error(`Invalid EVM address format: "${address}"`);
|
|
42
|
+
}
|
|
43
|
+
return address.toLowerCase();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
_computeAlphaScore(txCount, defiInteractions, avgValueUsd) {
|
|
47
|
+
const txScore = Math.min(txCount * 2, 400);
|
|
48
|
+
const defiScore = Math.min(defiInteractions * 5, 400);
|
|
49
|
+
const valueScore = Math.min(Math.floor(avgValueUsd / 10), 200);
|
|
50
|
+
return Math.min(txScore + defiScore + valueScore, 1000);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
_resolveTier(score) {
|
|
54
|
+
for (const entry of TIER_THRESHOLDS) {
|
|
55
|
+
if (score >= entry.minScore) return entry;
|
|
56
|
+
}
|
|
57
|
+
return TIER_THRESHOLDS[TIER_THRESHOLDS.length - 1];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
_resolveDefiActivity(defiInteractions) {
|
|
61
|
+
if (defiInteractions >= 50) return "Very High";
|
|
62
|
+
if (defiInteractions >= 20) return "High";
|
|
63
|
+
if (defiInteractions >= 8) return "Medium";
|
|
64
|
+
if (defiInteractions >= 2) return "Low";
|
|
65
|
+
return "None";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
_resolveVaults(defiActivity) {
|
|
69
|
+
if (defiActivity === "Very High" || defiActivity === "High") return RECOMMENDED_VAULTS.high;
|
|
70
|
+
if (defiActivity === "Medium") return RECOMMENDED_VAULTS.medium;
|
|
71
|
+
return RECOMMENDED_VAULTS.low;
|
|
72
|
+
}
|
|
73
|
+
|
|
3
74
|
async analyzeWalletHistory(walletAddress) {
|
|
4
|
-
|
|
75
|
+
const address = this._validateAddress(walletAddress);
|
|
76
|
+
|
|
77
|
+
// Deterministic mock scoring based on address checksum
|
|
78
|
+
const seed = parseInt(address.slice(2, 10), 16);
|
|
79
|
+
const txCount = (seed % 180) + 20;
|
|
80
|
+
const defiCount = (seed % 60) + 5;
|
|
81
|
+
const avgValueUsd = ((seed % 900) + 100);
|
|
82
|
+
|
|
83
|
+
const score = this._computeAlphaScore(txCount, defiCount, avgValueUsd);
|
|
84
|
+
const tierEntry = this._resolveTier(score);
|
|
85
|
+
const defiActivity = this._resolveDefiActivity(defiCount);
|
|
86
|
+
const vaults = this._resolveVaults(defiActivity);
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
address,
|
|
90
|
+
network: this.networkName,
|
|
91
|
+
chainId: this.network.chainId,
|
|
92
|
+
score,
|
|
93
|
+
maxScore: 1000,
|
|
94
|
+
tier: tierEntry.tier,
|
|
95
|
+
tierColor: tierEntry.color,
|
|
96
|
+
defiActivity,
|
|
97
|
+
transactionCount: txCount,
|
|
98
|
+
defiInteractions: defiCount,
|
|
99
|
+
avgTransactionValueUsd: avgValueUsd,
|
|
100
|
+
recommendedVaults: vaults,
|
|
101
|
+
analysisTimestamp: new Date().toISOString(),
|
|
102
|
+
sdkVersion: this.version,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async getArenaLeaderboard(options = {}) {
|
|
107
|
+
const limit = Math.min(options.limit || 10, 50);
|
|
108
|
+
if (!Number.isInteger(limit) || limit < 1) {
|
|
109
|
+
throw new Error("Limit must be a positive integer (max 50).");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const mockAddresses = [
|
|
113
|
+
"0x1722875731a404937dee0db60998b24838bd638b",
|
|
114
|
+
"0xabcdef1234567890abcdef1234567890abcdef12",
|
|
115
|
+
"0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
|
|
116
|
+
"0xcafebabecafebabecafebabecafebabecafebabe",
|
|
117
|
+
"0x0000000000000000000000000000000000000001",
|
|
118
|
+
];
|
|
119
|
+
|
|
120
|
+
const board = mockAddresses.slice(0, Math.min(limit, mockAddresses.length)).map((addr, i) => {
|
|
121
|
+
const seed = parseInt(addr.slice(2, 10), 16);
|
|
122
|
+
const score = Math.max(990 - i * 85, 100);
|
|
123
|
+
const tier = this._resolveTier(score);
|
|
124
|
+
return {
|
|
125
|
+
rank: i + 1,
|
|
126
|
+
wallet: addr,
|
|
127
|
+
score,
|
|
128
|
+
tier: tier.tier,
|
|
129
|
+
tierColor: tier.color,
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
leaderboard: board,
|
|
135
|
+
totalEntries: board.length,
|
|
136
|
+
network: this.networkName,
|
|
137
|
+
fetchedAt: new Date().toISOString(),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
getSupportedNetworks() {
|
|
142
|
+
return Object.keys(SUPPORTED_NETWORKS).map((key) => ({
|
|
143
|
+
name: key,
|
|
144
|
+
chainId: SUPPORTED_NETWORKS[key].chainId,
|
|
145
|
+
rpc: SUPPORTED_NETWORKS[key].rpc,
|
|
146
|
+
currency: SUPPORTED_NETWORKS[key].currency,
|
|
147
|
+
}));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
getTierThresholds() {
|
|
151
|
+
return TIER_THRESHOLDS.map((t) => ({ ...t }));
|
|
5
152
|
}
|
|
6
|
-
|
|
7
|
-
|
|
153
|
+
|
|
154
|
+
getVersion() {
|
|
155
|
+
return this.version;
|
|
8
156
|
}
|
|
9
157
|
}
|
|
10
|
-
|
|
158
|
+
|
|
159
|
+
module.exports = { ProofOfAlpha, SUPPORTED_NETWORKS, TIER_THRESHOLDS };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xward/proofofalpha-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Full on-chain intelligence ecosystem built on Celo featuring forensic analysis, wallet arena, and DeFi vaults.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -21,4 +21,4 @@
|
|
|
21
21
|
"url": "https://github.com/0xward/proofofalpha-core/issues"
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://www.npmjs.com/package/@0xward/proofofalpha-core#readme"
|
|
24
|
-
}
|
|
24
|
+
}
|