basic cheat view
This commit is contained in:
parent
2be1e9d520
commit
3f137a2757
5 changed files with 503 additions and 12 deletions
|
|
@ -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}`);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue