-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathdexter_migration_harness.py
More file actions
154 lines (136 loc) · 4.93 KB
/
dexter_migration_harness.py
File metadata and controls
154 lines (136 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
from __future__ import annotations
import json
import types
from dataclasses import replace
from decimal import Decimal
from pathlib import Path
from unittest import mock
class _HarnessAnalyzer:
def __init__(self, db_dsn):
self.db_dsn = db_dsn
self.total_supply = Decimal("1000000000")
self.sol_price_usd = Decimal("210")
def _seed_harness_position(trader) -> None:
trader.holdings["mint-harness"] = {
"owner": "owner-harness",
"trust_level": 1,
"token_balance": 123456,
"buy_price": "0.0000000280",
"cost_basis_lamports": 100000,
}
trader.swap_folder["mint-harness"] = {
"name": "Mint Harness",
"owner": "owner-harness",
"bonding_curve": "curve-harness",
"market": "pump_fun",
"migration_pending": True,
"state": {
"price": Decimal("0.0000000280"),
"open_price": Decimal("0.0000000280"),
"high_price": Decimal("0.0000000280"),
"mc": Decimal("0"),
"price_usd": 0.0,
"last_tx_time": "0.000",
"holders": {},
"price_history": {},
"tx_counts": {"swaps": 0, "buys": 0, "sells": 0},
"created": 0,
},
}
def _write_report(path: Path, report: dict) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps(report, indent=2, sort_keys=True), encoding="utf-8")
async def run_migration_harness(config) -> dict:
if config.runtime.network != "devnet":
raise ValueError("verify-migration only supports devnet.")
import Dexter as dexter_module
harness_config = replace(
config,
runtime=replace(
config.runtime,
mode="live",
network="devnet",
close_positions_on_shutdown=False,
allow_mainnet_live=False,
mainnet_dry_run=True,
),
phase2=replace(config.phase2, enabled=False),
)
saved_results = []
async def fake_save_result(result):
saved_results.append(result)
with mock.patch.object(dexter_module, "Analyzer", _HarnessAnalyzer):
trader = dexter_module.Dexter(harness_config)
trader.phase2 = None
trader.save_result = fake_save_result # type: ignore[assignment]
trader._validate_result = mock.AsyncMock()
trader.wallet_balance = 100000000
trader.dexLogs = types.SimpleNamespace(
process_log=mock.AsyncMock(return_value={"signature": "pump-swap-sig", "slot": 321}),
)
trader.pump_swap = types.SimpleNamespace(
pump_sell=mock.AsyncMock(return_value="migrated"),
close=mock.AsyncMock(),
)
trader.pump_swap_executor = types.SimpleNamespace(
pump_sell=mock.AsyncMock(return_value="sell-tx-pump-swap"),
)
trader.pump_swap_market = types.SimpleNamespace(
find_pool_for_mint=mock.AsyncMock(
return_value=types.SimpleNamespace(
pool="pool-migrated",
creator="owner-harness",
coin_creator="owner-harness",
is_mayhem_mode=False,
)
),
fetch_price_snapshot=mock.AsyncMock(
return_value={
"pool": "pool-migrated",
"price": Decimal("0.0000000315"),
"liquidity_sol": Decimal("3.2"),
}
),
)
trader.swaps = types.SimpleNamespace(
get_swap_tx=mock.AsyncMock(
return_value={
"wallet_balance": 100078000,
"wallet_delta_lamports": 78000,
"price": 0,
"fee_lamports": 7000,
}
)
)
_seed_harness_position(trader)
await trader.handle_single_log({"params": {}}, dexter_module.PUMP_SWAP)
post_promotion = trader.swap_folder["mint-harness"]
sell_result = await trader.sell(
"mint-harness",
123456,
"harness-drop-time",
"owner-harness",
1,
Decimal("0.0000000280"),
)
report = {
"harness": "pump_fun_to_pump_swap_migration",
"network": harness_config.runtime.network,
"funded_send": False,
"mainnet_send": False,
"price_feed": {
"market": post_promotion.get("market"),
"pool": post_promotion.get("pump_swap_pool"),
"price": str(post_promotion.get("state", {}).get("price")),
"pump_swap_swaps": int(post_promotion.get("state", {}).get("tx_counts", {}).get("pump_swap_swaps", 0) or 0),
},
"exit": {
"result": sell_result,
"venue": saved_results[0]["venue"] if saved_results else None,
"wallet_delta_lamports": saved_results[0]["sell_proceeds_lamports"] if saved_results else None,
"signature": "sell-tx-pump-swap",
},
"report_file": str(config.paths.state_dir / "migration-harness-report.json"),
}
_write_report(config.paths.state_dir / "migration-harness-report.json", report)
return report