diff --git a/services/marketMaker/README.md b/services/marketMaker/README.md new file mode 100644 index 0000000..e13b8a7 --- /dev/null +++ b/services/marketMaker/README.md @@ -0,0 +1,4 @@ +## RUN + +node service.js + diff --git a/services/marketMaker/package.json b/services/marketMaker/package.json index d4f0918..b7287ca 100644 --- a/services/marketMaker/package.json +++ b/services/marketMaker/package.json @@ -5,7 +5,7 @@ "license": "GPL3", "dependencies": { "dotenv": "^16.4.5", - "ethers": "5", + "ethers": "^6.13.2", "express": "^4.19.2" } } diff --git a/services/marketMaker/service.js b/services/marketMaker/service.js index 698655e..dd4ded4 100644 --- a/services/marketMaker/service.js +++ b/services/marketMaker/service.js @@ -3,33 +3,32 @@ const { ethers } = require('ethers'); const express = require('express'); // Load environment variables -const INFURA_PROJECT_ID = process.env.INFURA_PROJECT_ID; +const PROVIDER_URL = process.env.PROVIDER_URL; const PRIVATE_KEY = process.env.PRIVATE_KEY; const CONTRACT_ADDRESS = process.env.CONTRACT_ADDRESS; const ABI = [ // Add your contract's ABI here - "function shilft() public", - "function slide() public" + {"type":"function","name":"recenter","inputs":[],"outputs":[],"stateMutability":"nonpayable"} ]; // Initialize the provider -const provider = new ethers.providers.InfuraProvider('sepolia', INFURA_PROJECT_ID); +const provider = new ethers.JsonRpcProvider(PROVIDER_URL); + const wallet = new ethers.Wallet(PRIVATE_KEY, provider); const contract = new ethers.Contract(CONTRACT_ADDRESS, ABI, wallet); let startTime = new Date(); -let lastShilftTime = null; -let lastSlideTime = null; +let lastCallTime = null; async function checkFunds() { - const balance = await wallet.getBalance(); - return ethers.utils.formatEther(balance); + const balance = await provider.getBalance(wallet.address); + return ethers.formatEther(balance); } -async function canCallFunction(func) { +async function canCallFunction() { try { - // Simulate calling the function - await func.callStatic(); + // this will throw if the function is not callable + await contract.recenter.estimateGas(); return true; } catch (error) { return false; @@ -54,18 +53,12 @@ async function main() { while (true) { try { - if (await canCallFunction(contract.shilft)) { - console.log('Calling shilft...'); - const tx = await contract.shilft(); + if (await canCallFunction()) { + console.log('Calling recenter...'); + const tx = await contract.recenter(); await tx.wait(); - lastShilftTime = new Date(); - console.log('shilft called successfully.'); - } else if (await canCallFunction(contract.slide)) { - console.log('Calling slide...'); - const tx = await contract.slide(); - await tx.wait(); - lastSlideTime = new Date(); - console.log('slide called successfully.'); + lastCallTime = new Date(); + console.log('recenter called successfully.'); } else { console.log('No function can be called at the moment.'); } @@ -94,8 +87,7 @@ app.get('/status', async (req, res) => { const status = { balance: `${balance} ETH`, uptime: uptime, - lastShilftTime: lastShilftTime ? lastShilftTime.toString() : 'Never', - lastSlideTime: lastSlideTime ? lastSlideTime.toString() : 'Never' + lastCallTime: lastCallTime ? lastCallTime.toString() : 'Never' }; if (parseFloat(balance) < 0.1) {