basic cheat view

This commit is contained in:
johba 2025-09-23 21:16:15 +02:00
parent 2be1e9d520
commit 3f137a2757
5 changed files with 503 additions and 12 deletions

View file

@ -2,7 +2,7 @@
PONDER_NETWORK=BASE_SEPOLIA_LOCAL_FORK
KRAIKEN_ADDRESS=0x56186c1e64ca8043def78d06aff222212ea5df71
STAKE_ADDRESS=0x056e4a859558a3975761abd7385506bc4d8a8e60
START_BLOCK=31441844
START_BLOCK=31443298
# Use PostgreSQL connection
DATABASE_URL=postgresql://ponder:ponder_local@localhost/ponder_local
DATABASE_SCHEMA=ponder_local_31441844
DATABASE_SCHEMA=ponder_local_31443298

View file

@ -61,6 +61,7 @@ const stakeContract = new ethers.Contract(STAKE_CONTRACT_ADDRESS, STAKE_ABI, wal
let startTime = new Date();
let lastRecenterTime = null;
let lastLiquidationTime = null;
let lastRecenterTx = null;
async function fetchActivePositions() {
const response = await fetch(GRAPHQL_ENDPOINT, {
@ -97,6 +98,25 @@ async function canCallFunction() {
}
}
async function attemptRecenter() {
if (!(await canCallFunction())) {
return {
executed: false,
message: 'Liquidity manager denied recenter (likely already centered).'
};
}
const tx = await liquidityManager.recenter();
lastRecenterTx = tx.hash;
await tx.wait();
lastRecenterTime = new Date();
return {
executed: true,
txHash: tx.hash,
message: 'recenter transaction submitted'
};
}
async function checkPosition(position) {
const taxRate = Number(position.taxRate);
const lastTaxTime = Number(position.lastTaxTime);
@ -127,12 +147,9 @@ function formatDuration(ms) {
async function liquidityLoop() {
try {
if (await canCallFunction()) {
console.log('Calling recenter...');
const tx = await liquidityManager.recenter();
await tx.wait();
lastRecenterTime = new Date();
console.log('recenter called successfully.');
const result = await attemptRecenter();
if (result.executed) {
console.log(`recenter called successfully. tx=${result.txHash}`);
} else {
console.log(`No liquidity can be moved at the moment. - ${(new Date()).toISOString()}`);
}
@ -174,6 +191,16 @@ main().catch(async (error) => {
const app = express();
const PORT = process.env.PORT || 3000;
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET,POST,OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
if (req.method === 'OPTIONS') {
return res.sendStatus(204);
}
return next();
});
app.get('/status', async (req, res) => {
try {
const balance = await checkFunds();
@ -182,7 +209,8 @@ app.get('/status', async (req, res) => {
balance: `${balance} ETH`,
uptime: uptime,
lastRecenterTime: lastRecenterTime ? lastRecenterTime.toISOString() : 'Never',
lastLiquidationTime: lastLiquidationTime ? lastLiquidationTime.toISOString() : 'Never'
lastLiquidationTime: lastLiquidationTime ? lastLiquidationTime.toISOString() : 'Never',
lastRecenterTx,
};
if (parseFloat(balance) < 0.1) {
@ -195,6 +223,19 @@ app.get('/status', async (req, res) => {
}
});
app.post('/recenter', async (req, res) => {
try {
const result = await attemptRecenter();
if (!result.executed) {
return res.status(202).json(result);
}
return res.status(200).json(result);
} catch (error) {
console.error('Manual recenter failed:', error);
return res.status(500).json({ error: error.message || 'recenter failed' });
}
});
app.listen(PORT, () => {
console.log(`HTTP server running on port ${PORT}`);
});