nice-bill commited on
Commit
256e68d
·
verified ·
1 Parent(s): 63f1ca8

deploy from github

Browse files
Files changed (2) hide show
  1. core/agent.py +5 -4
  2. core/simulation.py +44 -11
core/agent.py CHANGED
@@ -107,10 +107,11 @@ Total liquidity: {pool_state.get('total_liquidity', 0):.2f}
107
  {self.learning_summary if self.learning_summary else "No previous runs yet."}
108
 
109
  === REWARDS FOR ACTIONS ===
110
- - SWAP: Active trading, you could profit from price movements
111
- - PROVIDE_LIQUIDITY: Earns fees from all swaps, +5 bonus tokens
112
- - PROPOSE_ALLIANCE: If they accept, you BOTH get +15 bonus tokens
113
- - COORDINATED TRADES: Trade with your allies for +3 bonus tokens!
 
114
 
115
  === AVAILABLE ACTIONS ===
116
  1. "swap": Trade tokens (specify from, to, amount) - ACTIVE TRADING
 
107
  {self.learning_summary if self.learning_summary else "No previous runs yet."}
108
 
109
  === REWARDS FOR ACTIONS ===
110
+ - SWAP: Active trading +3 tokens, profitable swap +5 extra!
111
+ - PROVIDE_LIQUIDITY: Earns fees from all swaps, +8 bonus tokens
112
+ - PROPOSE_ALLIANCE: If they accept, you BOTH get +8 bonus tokens
113
+ - COORDINATED TRADES: Trade during volatility +5 bonus tokens!
114
+ - POSITIVE PROFIT: End turn with profit = +10 bonus tokens!
115
 
116
  === AVAILABLE ACTIONS ===
117
  1. "swap": Trade tokens (specify from, to, amount) - ACTIVE TRADING
core/simulation.py CHANGED
@@ -23,12 +23,13 @@ class Simulation:
23
  supabase: Optional[SupabaseClient] = None
24
 
25
  # Alliance bonus config
26
- ALLIANCE_BONUS: float = 15.0 # Bonus for successful alliance
27
 
28
  # Action bonuses
29
- LIQUIDITY_BONUS: float = 5.0 # Bonus for providing liquidity
30
- SWAP_BONUS: float = 2.0 # Bonus for active trading
31
- COORDINATED_TRADE_BONUS: float = 3.0 # Bonus for trading with allies
 
32
 
33
  # Market maker config
34
  ENABLE_MARKET_MAKER: bool = True
@@ -94,6 +95,9 @@ class Simulation:
94
  decision, thinking = self._agent_decide(agent, turn)
95
  action_type = decision.get('action', 'unknown')
96
 
 
 
 
97
  # Execute action
98
  if decision:
99
  success = agent.execute_action(decision, self.pool)
@@ -123,6 +127,9 @@ class Simulation:
123
  # Check for successful alliances and grant bonuses
124
  self._process_alliances(turn)
125
 
 
 
 
126
  # Save state snapshots
127
  if self.supabase:
128
  self._save_states(turn)
@@ -345,9 +352,10 @@ class Simulation:
345
  """
346
  Grant bonuses for active trading behaviors.
347
 
348
- - Provide liquidity: +5 tokens
349
- - Swap: +2 tokens (active trading)
350
- - Coordinated trade with ally: +3 bonus tokens
 
351
  """
352
  bonus = 0
353
  bonus_reason = ""
@@ -361,14 +369,17 @@ class Simulation:
361
  bonus_reason = "active trading"
362
 
363
  # Check for coordinated trade with ally
364
- payload = decision.get("payload", {})
365
- # Coordinated trade is when both parties are allies
366
- # We'll give a bonus if the swap is happening in a volatile market
367
- # (after market maker or price shock)
368
  if self._is_coordinated_trade(agent, turn):
369
  bonus += self.COORDINATED_TRADE_BONUS
370
  bonus_reason = "coordinated trading with ally"
371
 
 
 
 
 
 
 
 
372
  if bonus > 0:
373
  agent.token_a += bonus
374
  print(f" [BONUS] {agent.name}: +{bonus:.1f} tokens for {bonus_reason}")
@@ -397,6 +408,28 @@ class Simulation:
397
 
398
  return market_maker_just_acted or price_shock_just_happened
399
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
400
 
401
  def test_simulation():
402
  """Test the simulation with a short run."""
 
23
  supabase: Optional[SupabaseClient] = None
24
 
25
  # Alliance bonus config
26
+ ALLIANCE_BONUS: float = 8.0 # Bonus for successful alliance
27
 
28
  # Action bonuses
29
+ LIQUIDITY_BONUS: float = 8.0 # Bonus for providing liquidity
30
+ SWAP_BONUS: float = 3.0 # Bonus for active trading
31
+ COORDINATED_TRADE_BONUS: float = 5.0 # Bonus for trading with allies
32
+ PROFIT_BONUS: float = 10.0 # Bonus for ending turn with positive profit
33
 
34
  # Market maker config
35
  ENABLE_MARKET_MAKER: bool = True
 
95
  decision, thinking = self._agent_decide(agent, turn)
96
  action_type = decision.get('action', 'unknown')
97
 
98
+ # Save profit before action for profit detection
99
+ agent._last_profit = agent.calculate_profit()
100
+
101
  # Execute action
102
  if decision:
103
  success = agent.execute_action(decision, self.pool)
 
127
  # Check for successful alliances and grant bonuses
128
  self._process_alliances(turn)
129
 
130
+ # Grant profit bonus for agents with positive profit
131
+ self._grant_profit_bonuses(turn)
132
+
133
  # Save state snapshots
134
  if self.supabase:
135
  self._save_states(turn)
 
352
  """
353
  Grant bonuses for active trading behaviors.
354
 
355
+ - Provide liquidity: +8 tokens
356
+ - Swap: +3 tokens (active trading)
357
+ - Coordinated trade with ally: +5 bonus tokens
358
+ - Profitable trade: +5 bonus tokens
359
  """
360
  bonus = 0
361
  bonus_reason = ""
 
369
  bonus_reason = "active trading"
370
 
371
  # Check for coordinated trade with ally
 
 
 
 
372
  if self._is_coordinated_trade(agent, turn):
373
  bonus += self.COORDINATED_TRADE_BONUS
374
  bonus_reason = "coordinated trading with ally"
375
 
376
+ # Check if swap was profitable (compare pre/post profit)
377
+ if hasattr(agent, '_last_profit'):
378
+ current_profit = agent.calculate_profit()
379
+ if current_profit > agent._last_profit:
380
+ bonus += 5.0
381
+ bonus_reason = "profitable trade"
382
+
383
  if bonus > 0:
384
  agent.token_a += bonus
385
  print(f" [BONUS] {agent.name}: +{bonus:.1f} tokens for {bonus_reason}")
 
408
 
409
  return market_maker_just_acted or price_shock_just_happened
410
 
411
+ def _grant_profit_bonuses(self, turn: int):
412
+ """
413
+ Grant bonus tokens to agents with positive profit at end of turn.
414
+ Encourages profit-seeking behavior.
415
+ """
416
+ for agent in self.agents:
417
+ profit = agent.calculate_profit()
418
+ if profit > 0:
419
+ agent.token_a += self.PROFIT_BONUS
420
+ print(f" [PROFIT BONUS] {agent.name}: +{self.PROFIT_BONUS:.1f} tokens (profit: {profit:.2f})")
421
+
422
+ if self.supabase:
423
+ self.supabase.save_action(ActionData(
424
+ run_id=self.current_run_id,
425
+ turn=turn,
426
+ agent_name=agent.name,
427
+ action_type="profit_bonus",
428
+ payload={"bonus": self.PROFIT_BONUS, "profit": profit},
429
+ reasoning_trace=f"Bonus for positive profit",
430
+ thinking_trace=""
431
+ ))
432
+
433
 
434
  def test_simulation():
435
  """Test the simulation with a short run."""