@infiniteezverse/monskills-ezpath 0.1.0
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/.well-known/agent.json +241 -0
- package/.well-known/openapi.json +310 -0
- package/ARENA.md +551 -0
- package/DEPLOYMENT.md +460 -0
- package/LAUNCH.md +345 -0
- package/LICENSE +24 -0
- package/MANIFEST.md +356 -0
- package/MONAD.md +375 -0
- package/QUICKSTART.md +378 -0
- package/README.md +88 -0
- package/X402_IMPLEMENTATION.md +468 -0
- package/dist/agents/arena-agent.d.ts +166 -0
- package/dist/agents/arena-agent.d.ts.map +1 -0
- package/dist/agents/arena-agent.js +267 -0
- package/dist/agents/arena-agent.js.map +1 -0
- package/dist/agents/bankroll-manager.d.ts +114 -0
- package/dist/agents/bankroll-manager.d.ts.map +1 -0
- package/dist/agents/bankroll-manager.js +293 -0
- package/dist/agents/bankroll-manager.js.map +1 -0
- package/dist/agents/index.d.ts +9 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +29 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/strategy.d.ts +48 -0
- package/dist/agents/strategy.d.ts.map +1 -0
- package/dist/agents/strategy.js +265 -0
- package/dist/agents/strategy.js.map +1 -0
- package/dist/agents/types.d.ts +197 -0
- package/dist/agents/types.d.ts.map +1 -0
- package/dist/agents/types.js +7 -0
- package/dist/agents/types.js.map +1 -0
- package/dist/config/monad.d.ts +175 -0
- package/dist/config/monad.d.ts.map +1 -0
- package/dist/config/monad.js +222 -0
- package/dist/config/monad.js.map +1 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +153 -0
- package/dist/index.js.map +1 -0
- package/dist/payments/eip3009.d.ts +210 -0
- package/dist/payments/eip3009.d.ts.map +1 -0
- package/dist/payments/eip3009.js +261 -0
- package/dist/payments/eip3009.js.map +1 -0
- package/dist/payments/index.d.ts +8 -0
- package/dist/payments/index.d.ts.map +1 -0
- package/dist/payments/index.js +25 -0
- package/dist/payments/index.js.map +1 -0
- package/dist/payments/quote-execution.d.ts +76 -0
- package/dist/payments/quote-execution.d.ts.map +1 -0
- package/dist/payments/quote-execution.js +285 -0
- package/dist/payments/quote-execution.js.map +1 -0
- package/dist/types/ezpath.d.ts +65 -0
- package/dist/types/ezpath.d.ts.map +1 -0
- package/dist/types/ezpath.js +7 -0
- package/dist/types/ezpath.js.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Arena Agent
|
|
4
|
+
* Complete poker-style competition agent with bankroll management and strategy
|
|
5
|
+
*
|
|
6
|
+
* Features:
|
|
7
|
+
* - Real-time bankroll valuation via EZ-Path
|
|
8
|
+
* - Risk of ruin calculations
|
|
9
|
+
* - Dynamic strategy selection
|
|
10
|
+
* - Tournament participation logic
|
|
11
|
+
* - Performance tracking
|
|
12
|
+
*/
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Agent = void 0;
|
|
18
|
+
const bankroll_manager_1 = __importDefault(require("./bankroll-manager"));
|
|
19
|
+
const strategy_1 = __importDefault(require("./strategy"));
|
|
20
|
+
/**
|
|
21
|
+
* Arena Agent Implementation
|
|
22
|
+
*/
|
|
23
|
+
class Agent {
|
|
24
|
+
constructor(config) {
|
|
25
|
+
this.id = config.id;
|
|
26
|
+
this.name = config.name;
|
|
27
|
+
this.address = config.address;
|
|
28
|
+
this.chain = config.chain;
|
|
29
|
+
this.bankrollToken = config.bankrollToken;
|
|
30
|
+
this.initialBankroll = config.initialBankroll;
|
|
31
|
+
this.currentBankroll = config.initialBankroll;
|
|
32
|
+
this.minimumBankroll = config.minimumBankroll;
|
|
33
|
+
this.skillLevel = config.skillLevel;
|
|
34
|
+
this.strategy = config.strategy;
|
|
35
|
+
this.aggressivenessLevel = config.aggressivenessLevel || 0.5;
|
|
36
|
+
this.riskTolerance = config.riskTolerance || 0.4;
|
|
37
|
+
this.targetROI = config.targetROI || 0.2; // 20% monthly target
|
|
38
|
+
this.createdAt = Date.now();
|
|
39
|
+
this.updatedAt = Date.now();
|
|
40
|
+
this.bankrollManager = new bankroll_manager_1.default(this);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Join a tournament
|
|
44
|
+
*/
|
|
45
|
+
async joinTournament(tournament, buyin) {
|
|
46
|
+
console.log(`\n[${this.name}] Evaluating tournament entry...`);
|
|
47
|
+
// Check if we can afford it
|
|
48
|
+
if (!this.bankrollManager.canAffordBuyin(buyin)) {
|
|
49
|
+
console.log(`❌ Cannot afford buyin of ${buyin.toString()}`);
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
// Check bankroll management rules
|
|
53
|
+
const shouldPlay = this.bankrollManager.shouldPlayTournament(buyin, tournament.totalPlayers);
|
|
54
|
+
if (!shouldPlay) {
|
|
55
|
+
console.log(`⚠️ Tournament is too risky relative to bankroll`);
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
// Get current metrics
|
|
59
|
+
const metrics = await this.bankrollManager.getMetrics();
|
|
60
|
+
console.log(`✅ Bankroll metrics:`);
|
|
61
|
+
console.log(` Buyins remaining: ${metrics.buyinsRemaining.toFixed(1)}`);
|
|
62
|
+
console.log(` Risk of ruin: ${(metrics.riskOfRuin * 100).toFixed(1)}%`);
|
|
63
|
+
console.log(` Status: ${metrics.status}`);
|
|
64
|
+
// Deduct buyin from bankroll
|
|
65
|
+
this.currentBankroll -= buyin;
|
|
66
|
+
this.bankrollManager.updateBankroll(this.currentBankroll);
|
|
67
|
+
// Set tournament state
|
|
68
|
+
this.tournamentEntry = {
|
|
69
|
+
tournamentId: tournament.id,
|
|
70
|
+
agentId: this.id,
|
|
71
|
+
entryFee: buyin,
|
|
72
|
+
initialStack: buyin, // Stack = buyin initially
|
|
73
|
+
currentStack: buyin,
|
|
74
|
+
position: 0,
|
|
75
|
+
handsPlayed: 0,
|
|
76
|
+
handsWon: 0,
|
|
77
|
+
handsLost: 0,
|
|
78
|
+
totalWinnings: BigInt(0),
|
|
79
|
+
totalLosses: BigInt(0),
|
|
80
|
+
isActive: true,
|
|
81
|
+
joinedAt: Date.now(),
|
|
82
|
+
lastActionAt: Date.now(),
|
|
83
|
+
};
|
|
84
|
+
console.log(`✅ Joined tournament: ${tournament.name}`);
|
|
85
|
+
console.log(` Buyin: ${buyin.toString()}`);
|
|
86
|
+
console.log(` Initial stack: ${buyin.toString()}`);
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Exit tournament (busted or cashed)
|
|
91
|
+
*/
|
|
92
|
+
exitTournament(finishPosition, _finalStack, prize) {
|
|
93
|
+
if (!this.tournamentEntry) {
|
|
94
|
+
console.warn('Not in a tournament');
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
console.log(`\n[${this.name}] Tournament Exit`);
|
|
98
|
+
console.log(` Finish position: ${finishPosition}`);
|
|
99
|
+
console.log(` Prize: ${prize.toString()}`);
|
|
100
|
+
const profit = prize - this.tournamentEntry.entryFee;
|
|
101
|
+
const roi = Number(profit) / Number(this.tournamentEntry.entryFee);
|
|
102
|
+
console.log(` Profit: ${profit.toString()} (${(roi * 100).toFixed(1)}%)`);
|
|
103
|
+
// Update bankroll
|
|
104
|
+
this.currentBankroll += prize;
|
|
105
|
+
this.bankrollManager.updateBankroll(this.currentBankroll);
|
|
106
|
+
this.bankrollManager.recordTournamentResult(this.tournamentEntry.tournamentId, this.tournamentEntry.entryFee, profit);
|
|
107
|
+
// Update entry
|
|
108
|
+
this.tournamentEntry.isActive = false;
|
|
109
|
+
this.tournamentEntry.finishPosition = finishPosition;
|
|
110
|
+
this.tournamentEntry.exitedAt = Date.now();
|
|
111
|
+
this.tournamentEntry = undefined;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Get strategy recommendation
|
|
115
|
+
*/
|
|
116
|
+
async getStrategyRecommendation() {
|
|
117
|
+
const metrics = await this.bankrollManager.getMetrics();
|
|
118
|
+
return strategy_1.default.recommendStrategy(metrics, this.skillLevel, this.strategy);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Update strategy if recommended
|
|
122
|
+
*/
|
|
123
|
+
async updateStrategyIfNeeded() {
|
|
124
|
+
const recommendation = await this.getStrategyRecommendation();
|
|
125
|
+
if (recommendation.recommendedStrategy !== this.strategy &&
|
|
126
|
+
recommendation.confidence > 0.7) {
|
|
127
|
+
console.log(`\n[${this.name}] Strategy update:`);
|
|
128
|
+
console.log(` Current: ${this.strategy}`);
|
|
129
|
+
console.log(` Recommended: ${recommendation.recommendedStrategy}`);
|
|
130
|
+
console.log(` Confidence: ${(recommendation.confidence * 100).toFixed(0)}%`);
|
|
131
|
+
console.log(` Reason: ${recommendation.reasoning}`);
|
|
132
|
+
this.strategy = recommendation.recommendedStrategy;
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Make game decision given context
|
|
139
|
+
*/
|
|
140
|
+
makeDecision(context) {
|
|
141
|
+
if (!context.strategy || !context.metrics) {
|
|
142
|
+
return {
|
|
143
|
+
action: 'fold',
|
|
144
|
+
confidence: 0.5,
|
|
145
|
+
reasoning: 'Insufficient context for decision',
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
return strategy_1.default.makeGameDecision(context);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get bankroll metrics
|
|
152
|
+
*/
|
|
153
|
+
async getMetrics() {
|
|
154
|
+
return this.bankrollManager.getMetrics();
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Get agent status
|
|
158
|
+
*/
|
|
159
|
+
async getStatus() {
|
|
160
|
+
const metrics = await this.bankrollManager.getMetrics();
|
|
161
|
+
const recommendation = await this.getStrategyRecommendation();
|
|
162
|
+
return {
|
|
163
|
+
agent: {
|
|
164
|
+
id: this.id,
|
|
165
|
+
name: this.name,
|
|
166
|
+
address: this.address,
|
|
167
|
+
skillLevel: this.skillLevel,
|
|
168
|
+
currentStrategy: this.strategy,
|
|
169
|
+
},
|
|
170
|
+
bankroll: {
|
|
171
|
+
current: this.currentBankroll.toString(),
|
|
172
|
+
initial: this.initialBankroll.toString(),
|
|
173
|
+
inUSDC: metrics.valueInUSDC,
|
|
174
|
+
buyinsRemaining: metrics.buyinsRemaining.toFixed(1),
|
|
175
|
+
status: metrics.status,
|
|
176
|
+
},
|
|
177
|
+
risk: {
|
|
178
|
+
riskOfRuin: (metrics.riskOfRuin * 100).toFixed(1) + '%',
|
|
179
|
+
healthScore: metrics.healthScore,
|
|
180
|
+
trend: this.bankrollManager['getRecentTrend'](),
|
|
181
|
+
},
|
|
182
|
+
strategy: {
|
|
183
|
+
current: this.strategy,
|
|
184
|
+
recommended: recommendation.recommendedStrategy,
|
|
185
|
+
confidence: (recommendation.confidence * 100).toFixed(0) + '%',
|
|
186
|
+
reasoning: recommendation.reasoning,
|
|
187
|
+
},
|
|
188
|
+
tournament: this.tournamentEntry
|
|
189
|
+
? {
|
|
190
|
+
id: this.tournamentEntry.tournamentId,
|
|
191
|
+
stack: this.tournamentEntry.currentStack.toString(),
|
|
192
|
+
handsPlayed: this.tournamentEntry.handsPlayed,
|
|
193
|
+
active: this.tournamentEntry.isActive,
|
|
194
|
+
}
|
|
195
|
+
: null,
|
|
196
|
+
actions: metrics.recommendedAction,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Simulate a hand
|
|
201
|
+
*/
|
|
202
|
+
async playHand(handType, stackSizeInBuyins) {
|
|
203
|
+
if (!this.tournamentEntry) {
|
|
204
|
+
console.warn('Agent is not in a tournament');
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const handStrength = strategy_1.default.evaluateHandStrength(handType);
|
|
208
|
+
console.log(`\n[${this.name}] Playing hand ${handType}`);
|
|
209
|
+
console.log(` Strength: ${(handStrength * 100).toFixed(0)}%`);
|
|
210
|
+
console.log(` Stack: ${stackSizeInBuyins.toFixed(1)} BB`);
|
|
211
|
+
this.tournamentEntry.handsPlayed++;
|
|
212
|
+
// Simulate outcome (very simplified)
|
|
213
|
+
const winChance = handStrength * 0.8; // 80% win rate for strong hands
|
|
214
|
+
const won = Math.random() < winChance;
|
|
215
|
+
if (won) {
|
|
216
|
+
this.tournamentEntry.handsWon++;
|
|
217
|
+
this.tournamentEntry.currentStack += BigInt(100); // Won 100 chips
|
|
218
|
+
console.log(` ✅ Won hand`);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
this.tournamentEntry.handsLost++;
|
|
222
|
+
this.tournamentEntry.currentStack -= BigInt(50); // Lost 50 chips
|
|
223
|
+
console.log(` ❌ Lost hand`);
|
|
224
|
+
}
|
|
225
|
+
this.tournamentEntry.lastActionAt = Date.now();
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Check if should quit tournament early
|
|
229
|
+
*/
|
|
230
|
+
shouldQuitTournament() {
|
|
231
|
+
if (!this.tournamentEntry)
|
|
232
|
+
return false;
|
|
233
|
+
const recommendation = this.strategy;
|
|
234
|
+
// Quit if in critical condition and playing conservative
|
|
235
|
+
if (recommendation === 'conservative' && this.tournamentEntry.handsLost > 5) {
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Export agent state as JSON
|
|
242
|
+
*/
|
|
243
|
+
async toJSON() {
|
|
244
|
+
return {
|
|
245
|
+
agent: {
|
|
246
|
+
id: this.id,
|
|
247
|
+
name: this.name,
|
|
248
|
+
address: this.address,
|
|
249
|
+
chain: this.chain,
|
|
250
|
+
skillLevel: this.skillLevel,
|
|
251
|
+
strategy: this.strategy,
|
|
252
|
+
},
|
|
253
|
+
bankroll: {
|
|
254
|
+
current: this.currentBankroll.toString(),
|
|
255
|
+
initial: this.initialBankroll.toString(),
|
|
256
|
+
minimum: this.minimumBankroll.toString(),
|
|
257
|
+
},
|
|
258
|
+
metrics: await this.getMetrics(),
|
|
259
|
+
status: await this.getStatus(),
|
|
260
|
+
createdAt: this.createdAt,
|
|
261
|
+
updatedAt: this.updatedAt,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
exports.Agent = Agent;
|
|
266
|
+
exports.default = Agent;
|
|
267
|
+
//# sourceMappingURL=arena-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arena-agent.js","sourceRoot":"","sources":["../../src/agents/arena-agent.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;;;;AAGH,0EAAiD;AACjD,0DAAwC;AAExC;;GAEG;AACH,MAAa,KAAK;IA2BhB,YAAY,MAAmB;QAC7B,IAAI,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;QAC1C,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;QAC9C,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;QAC9C,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;QAE9C,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QACpC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC,mBAAmB,IAAI,GAAG,CAAC;Q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,CAAC,SAAS;YACzB,SAAS,EAAE,IAAI,CAAC,SAAS;SAC1B,CAAC;IACJ,CAAC;CACF;AA/TD,sBA+TC;AAED,kBAAe,KAAK,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bankroll Manager
|
|
3
|
+
* Handles bankroll tracking, valuation, and risk calculations for Arena agents
|
|
4
|
+
*/
|
|
5
|
+
import { ArenaAgent, BankrollMetrics, HistoricalRecord } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* Bankroll Manager class
|
|
8
|
+
* Tracks and analyzes agent bankroll
|
|
9
|
+
*/
|
|
10
|
+
export declare class BankrollManager {
|
|
11
|
+
private agent;
|
|
12
|
+
private history;
|
|
13
|
+
constructor(agent: ArenaAgent);
|
|
14
|
+
/**
|
|
15
|
+
* Record current bankroll snapshot
|
|
16
|
+
*/
|
|
17
|
+
private recordSnapshot;
|
|
18
|
+
/**
|
|
19
|
+
* Update agent's current bankroll
|
|
20
|
+
*/
|
|
21
|
+
updateBankroll(newAmount: bigint): void;
|
|
22
|
+
/**
|
|
23
|
+
* Get current bankroll metrics
|
|
24
|
+
*/
|
|
25
|
+
getMetrics(): Promise<BankrollMetrics>;
|
|
26
|
+
/**
|
|
27
|
+
* Valuate bankroll in USDC
|
|
28
|
+
*/
|
|
29
|
+
private valuateBankroll;
|
|
30
|
+
/**
|
|
31
|
+
* Estimate USDC value (fallback)
|
|
32
|
+
*/
|
|
33
|
+
private estimateUSDCValue;
|
|
34
|
+
/**
|
|
35
|
+
* Calculate number of buyins remaining
|
|
36
|
+
*/
|
|
37
|
+
private calculateBuyinsRemaining;
|
|
38
|
+
/**
|
|
39
|
+
* Calculate risk of ruin
|
|
40
|
+
* Based on bankroll in buyins and assumed win rate
|
|
41
|
+
*/
|
|
42
|
+
private calculateRiskOfRuin;
|
|
43
|
+
/**
|
|
44
|
+
* Estimate agent's win rate based on skill level
|
|
45
|
+
*/
|
|
46
|
+
private estimateWinRate;
|
|
47
|
+
/**
|
|
48
|
+
* Determine bankroll status
|
|
49
|
+
*/
|
|
50
|
+
private determineBankrollStatus;
|
|
51
|
+
/**
|
|
52
|
+
* Calculate expected value over time
|
|
53
|
+
*/
|
|
54
|
+
private calculateExpectedValue;
|
|
55
|
+
/**
|
|
56
|
+
* Get peak bankroll value
|
|
57
|
+
*/
|
|
58
|
+
private getPeakValue;
|
|
59
|
+
/**
|
|
60
|
+
* Get lowest bankroll value
|
|
61
|
+
*/
|
|
62
|
+
private getLowestValue;
|
|
63
|
+
/**
|
|
64
|
+
* Calculate daily P&L
|
|
65
|
+
*/
|
|
66
|
+
private calculateDailyChange;
|
|
67
|
+
/**
|
|
68
|
+
* Calculate total ROI
|
|
69
|
+
*/
|
|
70
|
+
private calculateTotalROI;
|
|
71
|
+
/**
|
|
72
|
+
* Calculate health score (0-100)
|
|
73
|
+
*/
|
|
74
|
+
private calculateHealthScore;
|
|
75
|
+
/**
|
|
76
|
+
* Get recommended action based on status
|
|
77
|
+
*/
|
|
78
|
+
private getRecommendedAction;
|
|
79
|
+
/**
|
|
80
|
+
* Get historical data
|
|
81
|
+
*/
|
|
82
|
+
getHistory(since?: number): HistoricalRecord[];
|
|
83
|
+
/**
|
|
84
|
+
* Add tournament result to history
|
|
85
|
+
*/
|
|
86
|
+
recordTournamentResult(tournamentId: string, buyin: bigint, profit: bigint): void;
|
|
87
|
+
/**
|
|
88
|
+
* Get bankroll trend (last 24 hours)
|
|
89
|
+
*/
|
|
90
|
+
getRecentTrend(): 'up' | 'down' | 'flat';
|
|
91
|
+
/**
|
|
92
|
+
* Simulate tournament buyins
|
|
93
|
+
*/
|
|
94
|
+
canAffordBuyin(buyinAmount: bigint): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Check if agent should play in tournament
|
|
97
|
+
*/
|
|
98
|
+
shouldPlayTournament(buyinAmount: bigint, expectedFieldSize: number): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Export metrics as JSON
|
|
101
|
+
*/
|
|
102
|
+
toJSON(): Promise<{
|
|
103
|
+
agent: {
|
|
104
|
+
id: string;
|
|
105
|
+
name: string;
|
|
106
|
+
skillLevel: import("./types").AgentSkillLevel;
|
|
107
|
+
};
|
|
108
|
+
metrics: BankrollMetrics;
|
|
109
|
+
trend: "up" | "down" | "flat";
|
|
110
|
+
history: HistoricalRecord[];
|
|
111
|
+
}>;
|
|
112
|
+
}
|
|
113
|
+
export default BankrollManager;
|
|
114
|
+
//# sourceMappingURL=bankroll-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bankroll-manager.d.ts","sourceRoot":"","sources":["../../src/agents/bankroll-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACL,UAAU,EACV,eAAe,EAEf,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAEjB;;;GAGG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,KAAK,CAAa;IAC1B,OAAO,CAAC,OAAO,CAA0B;gBAE7B,KAAK,EAAE,UAAU;IAK7B;;OAEG;IACH,OAAO,CAAC,cAAc;IAUtB;;OAEG;IACH,cAAc,CAAC,SAAS,EAAE,MAAM;IAMhC;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,eAAe,CAAC;IAsB5C;;OAEG;YACW,eAAe;IAoB7B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAMzB;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAMhC;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAY3B;;OAEG;IACH,OAAO,CAAC,eAAe;IAYvB;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAgB/B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAQ9B;;OAEG;IACH,OAAO,CAAC,YAAY;IAQpB;;OAEG;IACH,OAAO,CAAC,cAAc;IAQtB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAY5B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAOzB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAU5B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAe5B;;OAEG;IACH,UAAU,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,gBAAgB,EAAE;IAM9C;;OAEG;IACH,sBAAsB,CACpB,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM;IAahB;;OAEG;IACH,cAAc,IAAI,IAAI,GAAG,MAAM,GAAG,MAAM;IAaxC;;OAEG;IACH,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO;IAI5C;;OAEG;IACH,oBAAoB,CAAC,WAAW,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,GAAG,OAAO;IAoB7E;;OAEG;IACG,MAAM;;;;;;;;;;CAcb;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Bankroll Manager
|
|
4
|
+
* Handles bankroll tracking, valuation, and risk calculations for Arena agents
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.BankrollManager = void 0;
|
|
8
|
+
const index_1 = require("../index");
|
|
9
|
+
/**
|
|
10
|
+
* Bankroll Manager class
|
|
11
|
+
* Tracks and analyzes agent bankroll
|
|
12
|
+
*/
|
|
13
|
+
class BankrollManager {
|
|
14
|
+
constructor(agent) {
|
|
15
|
+
this.history = [];
|
|
16
|
+
this.agent = agent;
|
|
17
|
+
this.recordSnapshot();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Record current bankroll snapshot
|
|
21
|
+
*/
|
|
22
|
+
recordSnapshot() {
|
|
23
|
+
// TODO: Get current price from cache or API
|
|
24
|
+
// For now, just record the raw value
|
|
25
|
+
this.history.push({
|
|
26
|
+
timestamp: Date.now(),
|
|
27
|
+
bankroll: this.agent.currentBankroll,
|
|
28
|
+
valueInUSDC: this.estimateUSDCValue(),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Update agent's current bankroll
|
|
33
|
+
*/
|
|
34
|
+
updateBankroll(newAmount) {
|
|
35
|
+
this.agent.currentBankroll = newAmount;
|
|
36
|
+
this.agent.updatedAt = Date.now();
|
|
37
|
+
this.recordSnapshot();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get current bankroll metrics
|
|
41
|
+
*/
|
|
42
|
+
async getMetrics() {
|
|
43
|
+
const valueInUSDC = await this.valuateBankroll();
|
|
44
|
+
const buyinsRemaining = this.calculateBuyinsRemaining();
|
|
45
|
+
const riskOfRuin = this.calculateRiskOfRuin(buyinsRemaining);
|
|
46
|
+
const status = this.determineBankrollStatus(buyinsRemaining, riskOfRuin);
|
|
47
|
+
return {
|
|
48
|
+
value: this.agent.currentBankroll,
|
|
49
|
+
valueInUSDC,
|
|
50
|
+
buyinsRemaining,
|
|
51
|
+
riskOfRuin,
|
|
52
|
+
expectedValue: this.calculateExpectedValue(),
|
|
53
|
+
peakValue: this.getPeakValue(),
|
|
54
|
+
lowestValue: this.getLowestValue(),
|
|
55
|
+
dailyChange: this.calculateDailyChange(),
|
|
56
|
+
totalROI: this.calculateTotalROI(),
|
|
57
|
+
status,
|
|
58
|
+
healthScore: this.calculateHealthScore(buyinsRemaining, riskOfRuin),
|
|
59
|
+
recommendedAction: this.getRecommendedAction(status, buyinsRemaining),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Valuate bankroll in USDC
|
|
64
|
+
*/
|
|
65
|
+
async valuateBankroll() {
|
|
66
|
+
try {
|
|
67
|
+
// Use getPrice to get current valuation
|
|
68
|
+
const result = await (0, index_1.getPrice)(this.agent.chain, this.agent.bankrollToken, '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC
|
|
69
|
+
this.agent.currentBankroll.toString());
|
|
70
|
+
if ('price' in result) {
|
|
71
|
+
return result.price;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
console.warn('Failed to valuate bankroll:', error);
|
|
76
|
+
}
|
|
77
|
+
return this.estimateUSDCValue();
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Estimate USDC value (fallback)
|
|
81
|
+
*/
|
|
82
|
+
estimateUSDCValue() {
|
|
83
|
+
// Rough estimate based on agent configuration
|
|
84
|
+
// In production, this would be derived from actual price data
|
|
85
|
+
return (Number(this.agent.currentBankroll) / 1e18).toFixed(2);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Calculate number of buyins remaining
|
|
89
|
+
*/
|
|
90
|
+
calculateBuyinsRemaining() {
|
|
91
|
+
// Assume 1 buyin = 1 unit of bankroll token
|
|
92
|
+
// In production, would use actual buyin amounts from tournaments
|
|
93
|
+
return Number(this.agent.currentBankroll) / Number(this.agent.initialBankroll);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Calculate risk of ruin
|
|
97
|
+
* Based on bankroll in buyins and assumed win rate
|
|
98
|
+
*/
|
|
99
|
+
calculateRiskOfRuin(bankrollInBuyins) {
|
|
100
|
+
// Simplified Kelly Criterion-based RoR calculation
|
|
101
|
+
// winRate estimation available via estimateWinRate() but using fixed thresholds for simplicity
|
|
102
|
+
if (bankrollInBuyins < 1)
|
|
103
|
+
return 0.99; // Nearly certain bust
|
|
104
|
+
if (bankrollInBuyins < 5)
|
|
105
|
+
return 0.7;
|
|
106
|
+
if (bankrollInBuyins < 10)
|
|
107
|
+
return 0.4;
|
|
108
|
+
if (bankrollInBuyins < 20)
|
|
109
|
+
return 0.15;
|
|
110
|
+
if (bankrollInBuyins < 30)
|
|
111
|
+
return 0.05;
|
|
112
|
+
return 0.01;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Estimate agent's win rate based on skill level
|
|
116
|
+
*/
|
|
117
|
+
estimateWinRate() {
|
|
118
|
+
// Base win rate assumptions by skill level
|
|
119
|
+
const baseWinRates = {
|
|
120
|
+
beginner: 0.48,
|
|
121
|
+
intermediate: 0.51,
|
|
122
|
+
advanced: 0.54,
|
|
123
|
+
expert: 0.58,
|
|
124
|
+
};
|
|
125
|
+
return baseWinRates[this.agent.skillLevel] || 0.50;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Determine bankroll status
|
|
129
|
+
*/
|
|
130
|
+
determineBankrollStatus(buyinsRemaining, riskOfRuin) {
|
|
131
|
+
if (Number(this.agent.currentBankroll) <= Number(this.agent.minimumBankroll)) {
|
|
132
|
+
return 'bust';
|
|
133
|
+
}
|
|
134
|
+
if (buyinsRemaining < 5 || riskOfRuin > 0.5) {
|
|
135
|
+
return 'critical';
|
|
136
|
+
}
|
|
137
|
+
if (buyinsRemaining < 10 || riskOfRuin > 0.2) {
|
|
138
|
+
return 'cautious';
|
|
139
|
+
}
|
|
140
|
+
return 'healthy';
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Calculate expected value over time
|
|
144
|
+
*/
|
|
145
|
+
calculateExpectedValue() {
|
|
146
|
+
const winRate = this.estimateWinRate();
|
|
147
|
+
const hourlyRate = 0.1; // 10% of buyin per hour (assumption)
|
|
148
|
+
const expectedHourly = Number(this.agent.initialBankroll) * hourlyRate * (winRate - 0.5);
|
|
149
|
+
return expectedHourly.toFixed(2);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get peak bankroll value
|
|
153
|
+
*/
|
|
154
|
+
getPeakValue() {
|
|
155
|
+
if (this.history.length === 0)
|
|
156
|
+
return this.agent.initialBankroll;
|
|
157
|
+
return this.history.reduce((max, record) => record.bankroll > max ? record.bankroll : max, this.agent.initialBankroll);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Get lowest bankroll value
|
|
161
|
+
*/
|
|
162
|
+
getLowestValue() {
|
|
163
|
+
if (this.history.length === 0)
|
|
164
|
+
return this.agent.currentBankroll;
|
|
165
|
+
return this.history.reduce((min, record) => record.bankroll < min ? record.bankroll : min, this.agent.currentBankroll);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Calculate daily P&L
|
|
169
|
+
*/
|
|
170
|
+
calculateDailyChange() {
|
|
171
|
+
const oneDayAgo = Date.now() - 86400000;
|
|
172
|
+
const historicalRecord = this.history.find((r) => r.timestamp <= oneDayAgo);
|
|
173
|
+
if (!historicalRecord) {
|
|
174
|
+
return '0.00';
|
|
175
|
+
}
|
|
176
|
+
const change = Number(this.agent.currentBankroll - historicalRecord.bankroll) / 1e18;
|
|
177
|
+
return change.toFixed(2);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Calculate total ROI
|
|
181
|
+
*/
|
|
182
|
+
calculateTotalROI() {
|
|
183
|
+
const current = Number(this.agent.currentBankroll) / 1e18;
|
|
184
|
+
const initial = Number(this.agent.initialBankroll) / 1e18;
|
|
185
|
+
return ((current - initial) / initial) * 100;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Calculate health score (0-100)
|
|
189
|
+
*/
|
|
190
|
+
calculateHealthScore(buyinsRemaining, riskOfRuin) {
|
|
191
|
+
// More buyins = higher score
|
|
192
|
+
const buyinScore = Math.min(buyinsRemaining / 30, 1) * 50;
|
|
193
|
+
// Lower RoR = higher score
|
|
194
|
+
const rorScore = (1 - riskOfRuin) * 50;
|
|
195
|
+
return Math.round(buyinScore + rorScore);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Get recommended action based on status
|
|
199
|
+
*/
|
|
200
|
+
getRecommendedAction(status, buyinsRemaining) {
|
|
201
|
+
switch (status) {
|
|
202
|
+
case 'bust':
|
|
203
|
+
return 'RELOAD: Bankroll below minimum. Consider adding funds or taking a break.';
|
|
204
|
+
case 'critical':
|
|
205
|
+
return `CAUTIOUS: Only ${buyinsRemaining.toFixed(1)} buyins remaining. Play tight.`;
|
|
206
|
+
case 'cautious':
|
|
207
|
+
return `CAREFUL: ${buyinsRemaining.toFixed(1)} buyins remaining. Play ABC poker.`;
|
|
208
|
+
case 'healthy':
|
|
209
|
+
return `HEALTHY: ${buyinsRemaining.toFixed(1)} buyins. Play your strategy.`;
|
|
210
|
+
default:
|
|
211
|
+
return 'UNKNOWN';
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Get historical data
|
|
216
|
+
*/
|
|
217
|
+
getHistory(since) {
|
|
218
|
+
if (!since)
|
|
219
|
+
return this.history;
|
|
220
|
+
return this.history.filter((r) => r.timestamp >= since);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Add tournament result to history
|
|
224
|
+
*/
|
|
225
|
+
recordTournamentResult(tournamentId, buyin, profit) {
|
|
226
|
+
this.history.push({
|
|
227
|
+
timestamp: Date.now(),
|
|
228
|
+
bankroll: this.agent.currentBankroll,
|
|
229
|
+
valueInUSDC: this.estimateUSDCValue(),
|
|
230
|
+
tournamentId,
|
|
231
|
+
buyin,
|
|
232
|
+
profit,
|
|
233
|
+
notes: `Tournament ${tournamentId.substring(0, 8)}...`,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Get bankroll trend (last 24 hours)
|
|
238
|
+
*/
|
|
239
|
+
getRecentTrend() {
|
|
240
|
+
const oneDayAgo = Date.now() - 86400000;
|
|
241
|
+
const dayOldRecord = this.history.find((r) => r.timestamp <= oneDayAgo);
|
|
242
|
+
if (!dayOldRecord)
|
|
243
|
+
return 'flat';
|
|
244
|
+
const change = this.agent.currentBankroll - dayOldRecord.bankroll;
|
|
245
|
+
if (change > BigInt(0))
|
|
246
|
+
return 'up';
|
|
247
|
+
if (change < BigInt(0))
|
|
248
|
+
return 'down';
|
|
249
|
+
return 'flat';
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Simulate tournament buyins
|
|
253
|
+
*/
|
|
254
|
+
canAffordBuyin(buyinAmount) {
|
|
255
|
+
return this.agent.currentBankroll >= buyinAmount;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Check if agent should play in tournament
|
|
259
|
+
*/
|
|
260
|
+
shouldPlayTournament(buyinAmount, expectedFieldSize) {
|
|
261
|
+
if (!this.canAffordBuyin(buyinAmount)) {
|
|
262
|
+
return false; // Can't afford it
|
|
263
|
+
}
|
|
264
|
+
const buyinRatio = Number(buyinAmount) / Number(this.agent.currentBankroll);
|
|
265
|
+
// Only play if buyin is <5% of bankroll (conservative)
|
|
266
|
+
if (buyinRatio > 0.05) {
|
|
267
|
+
return false; // Too risky
|
|
268
|
+
}
|
|
269
|
+
// Check expected value
|
|
270
|
+
const expectedWinChance = 1 / expectedFieldSize;
|
|
271
|
+
const expectedEV = expectedWinChance; // Very rough
|
|
272
|
+
return expectedEV > 0;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Export metrics as JSON
|
|
276
|
+
*/
|
|
277
|
+
async toJSON() {
|
|
278
|
+
const metrics = await this.getMetrics();
|
|
279
|
+
return {
|
|
280
|
+
agent: {
|
|
281
|
+
id: this.agent.id,
|
|
282
|
+
name: this.agent.name,
|
|
283
|
+
skillLevel: this.agent.skillLevel,
|
|
284
|
+
},
|
|
285
|
+
metrics,
|
|
286
|
+
trend: this.getRecentTrend(),
|
|
287
|
+
history: this.history.slice(-24), // Last 24 records
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
exports.BankrollManager = BankrollManager;
|
|
292
|
+
exports.default = BankrollManager;
|
|
293
|
+
//# sourceMappingURL=bankroll-manager.js.map
|