Skip to content

Commit

Permalink
check operators' balance
Browse files Browse the repository at this point in the history
  • Loading branch information
Guantong committed Mar 6, 2024
1 parent 6955ebc commit be511d1
Show file tree
Hide file tree
Showing 14 changed files with 251 additions and 67 deletions.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ export default async function (fastify, opts) {
// define your routes in one of these
fastify.register(AutoLoad, {
dir: path.join(__dirname, 'routes'),
options: Object.assign({}, opts)
options: Object.assign({ prefix: '/api' }, opts)
})
}
153 changes: 153 additions & 0 deletions server/config/chains.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
const Chains = [
{
"name": "crab",
"id": 44,
"endpoint": "https://crab-rpc.darwinia.network",
"indexer": {
"ormp": "https://thegraph-g2.darwinia.network/ormpipe/subgraphs/name/ormpipe-crab",
"signcribe": "https://thegraph-g2.darwinia.network/ormpipe/subgraphs/name/signcribe-darwinia"
},
"contract": {
"signcribe": "0x57dd62e0986a61a269c769b107a5a7952d73b7ed",
"relayer": "0x0000000000808fE9bDCc1d180EfbF5C53552a6b1",
"ormp": "0x00000000001523057a05d6293C1e5171eE33eE0A",
"oracle": "0x0000000003ebeF32D8f0ED406a5CA8805c80AFba",
"multisig": "0x000000000d60704384100A29efb6C9cf8cD72820"
},
"operator": {
"oracle": "0x178E699c9a6bB2Cd624557Fbd85ed219e6faBa77",
"relayer": "0x912D7601569cBc2DF8A7f0aaE50BFd18e8C64d05",
},
"symbol": "CRAB"
},
{
"name": "darwinia",
"id": 46,
"endpoint": "https://rpc.darwinia.network",
"indexer": {
"ormp": "https://thegraph-g2.darwinia.network/ormpipe/subgraphs/name/ormpipe-darwinia",
"signcribe": "https://thegraph-g2.darwinia.network/ormpipe/subgraphs/name/signcribe-darwinia"
},
"contract": {
"signcribe": "0x57dd62e0986a61a269c769b107a5a7952d73b7ed",
"relayer": "0x0000000000808fE9bDCc1d180EfbF5C53552a6b1",
"ormp": "0x00000000001523057a05d6293C1e5171eE33eE0A",
"oracle": "0x0000000003ebeF32D8f0ED406a5CA8805c80AFba",
"multisig": "0x000000000d60704384100A29efb6C9cf8cD72820"
},
"operator": {
"oracle": "0x178E699c9a6bB2Cd624557Fbd85ed219e6faBa77",
"relayer": "0x912D7601569cBc2DF8A7f0aaE50BFd18e8C64d05",
},
"symbol": "RING"
},
{
"name": "arbitrum",
"id": 42161,
"endpoint": "https://arbitrum-one.publicnode.com",
"indexer": {
"ormp": "https://api.studio.thegraph.com/proxy/51152/ormpipe-arbitrum/version/latest",
"signcribe": "https://thegraph-g2.darwinia.network/ormpipe/subgraphs/name/signcribe-darwinia"
},
"contract": {
"signcribe": "0x57dd62e0986a61a269c769b107a5a7952d73b7ed",
"relayer": "0x0000000000808fE9bDCc1d180EfbF5C53552a6b1",
"ormp": "0x00000000001523057a05d6293C1e5171eE33eE0A",
"oracle": "0x0000000003ebeF32D8f0ED406a5CA8805c80AFba",
"multisig": "0x000000000d60704384100A29efb6C9cf8cD72820"
},
"operator": {
"oracle": "0x178E699c9a6bB2Cd624557Fbd85ed219e6faBa77",
"relayer": "0x912D7601569cBc2DF8A7f0aaE50BFd18e8C64d05",
},
"symbol": "AETH"
},
{
"name": "ethereum",
"id": 1,
"endpoint": "https://ethereum.publicnode.com",
"indexer": {
"ormp": "https://api.studio.thegraph.com/proxy/51152/ormpipe-ethereum/version/latest",
"signcribe": "https://thegraph-g2.darwinia.network/ormpipe/subgraphs/name/signcribe-darwinia"
},
"contract": {
"signcribe": "0x57dd62e0986a61a269c769b107a5a7952d73b7ed",
"relayer": "0x0000000000808fE9bDCc1d180EfbF5C53552a6b1",
"ormp": "0x00000000001523057a05d6293C1e5171eE33eE0A",
"oracle": "0x0000000003ebeF32D8f0ED406a5CA8805c80AFba",
"multisig": "0x000000000d60704384100A29efb6C9cf8cD72820"
},
"operator": {
"oracle": "0x178E699c9a6bB2Cd624557Fbd85ed219e6faBa77",
"relayer": "0x912D7601569cBc2DF8A7f0aaE50BFd18e8C64d05",
},
"symbol": "ETH"
},
{
"name": "polygon",
"id": 137,
"endpoint": "https://polygon-bor-rpc.publicnode.com",
"indexer": {
"ormp": "https://api.studio.thegraph.com/proxy/51152/ormpipe-polygon/version/latest",
"signcribe": "https://thegraph-g2.darwinia.network/ormpipe/subgraphs/name/signcribe-darwinia"
},
"contract": {
"signcribe": "0x57dd62e0986a61a269c769b107a5a7952d73b7ed",
"relayer": "0x0000000000808fE9bDCc1d180EfbF5C53552a6b1",
"ormp": "0x00000000001523057a05d6293C1e5171eE33eE0A",
"oracle": "0x0000000003ebeF32D8f0ED406a5CA8805c80AFba",
"multisig": "0x000000000d60704384100A29efb6C9cf8cD72820"
},
"operator": {
"oracle": "0x178E699c9a6bB2Cd624557Fbd85ed219e6faBa77",
"relayer": "0x912D7601569cBc2DF8A7f0aaE50BFd18e8C64d05",
},
"symbol": "MATIC"
},
{
"name": "blast",
"id": 81457,
"endpoint": "https://rpc.blast.io",
"indexer": {
"ormp": "https://api.studio.thegraph.com/proxy/51152/ormpipe-blast/version/latest",
"signcribe": "https://thegraph-g2.darwinia.network/ormpipe/subgraphs/name/signcribe-darwinia"
},
"contract": {
"signcribe": "0x57dd62e0986a61a269c769b107a5a7952d73b7ed",
"relayer": "0x0000000000808fE9bDCc1d180EfbF5C53552a6b1",
"ormp": "0x00000000001523057a05d6293C1e5171eE33eE0A",
"oracle": "0x0000000003ebeF32D8f0ED406a5CA8805c80AFba",
"multisig": "0x000000000d60704384100A29efb6C9cf8cD72820"
},
"operator": {
"oracle": "0x178E699c9a6bB2Cd624557Fbd85ed219e6faBa77",
"relayer": "0x912D7601569cBc2DF8A7f0aaE50BFd18e8C64d05",
},
"symbol": "ETH"
}
]

function getChainById(id) {
for (const item of Chains) {
if(item.id == id) {
return item;
}
}
return null;
}

function getChainByName(name) {
for (const item of Chains) {
if(item.name == name) {
return item;
}
}
return null;
}


function getAllChains() {
return Chains;
}

export { getAllChains, getChainById, getChainByName };
1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dependencies": {
"@fastify/autoload": "^5.0.0",
"@fastify/sensible": "^5.0.0",
"ethers": "^6.11.1",
"fastify": "^4.26.1",
"fastify-cli": "^6.1.1",
"fastify-plugin": "^4.0.0"
Expand Down
16 changes: 0 additions & 16 deletions server/plugins/README.md

This file was deleted.

10 changes: 0 additions & 10 deletions server/plugins/support.js

This file was deleted.

27 changes: 0 additions & 27 deletions server/routes/README.md

This file was deleted.

6 changes: 6 additions & 0 deletions server/routes/balance/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

function unitToEth(num) {
return Number(num) / Math.pow(10, 18);
}

export { unitToEth }
24 changes: 24 additions & 0 deletions server/routes/balance/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ethers } from "ethers"
import { getAllChains } from "../../config/chains.js"
import { unitToEth } from "./helper.js";

export default async function (fastify) {
fastify.get('/operators', async function () {
return await checkOperatorBalance()
})

async function checkOperatorBalance() {
const operatorInfo = {};
for (const chain of getAllChains()) {
const operatorBalance = {};
const provider = new ethers.JsonRpcProvider(chain.endpoint);
let relayerBalance = await provider.getBalance(chain.operator.relayer);
operatorBalance.relayer = unitToEth(relayerBalance);
let oracleBalance = await provider.getBalance(chain.operator.oracle);
operatorBalance.oracle = unitToEth(oracleBalance);
operatorBalance.symbol = chain.symbol;
operatorInfo[chain.name] = operatorBalance;
}
return operatorInfo;
}
}
5 changes: 0 additions & 5 deletions server/routes/example/index.js

This file was deleted.

5 changes: 0 additions & 5 deletions server/routes/root.js

This file was deleted.

19 changes: 16 additions & 3 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,22 @@ import appService from './app.js'
// Dotenv config
dotenv.config()

const LOG_LEVEL = process.env.LOG_LEVEL || 'info';
const PORT = process.env.PORT || '8000';
const LISTEN = process.env.LISTEN || '127.0.0.1'

// Instantiate Fastify with some config
const app = Fastify({
logger: true
logger: {
level: LOG_LEVEL,
transport: LOG_LEVEL == 'debug' ? {
target: 'pino-pretty',
options: {
translateTime: 'mm-dd HH:MM:ss',
ignore: 'pid,hostname'
}
} : null
}
})

// Register your application as a normal plugin.
Expand All @@ -24,7 +37,7 @@ app.register(appService)
// delay is the number of milliseconds for the graceful close to finish
const closeListeners = closeWithGrace({ delay: process.env.FASTIFY_CLOSE_GRACE_DELAY || 500 }, async function ({ signal, err, manual }) {
if (err) {
app.log.error(err)
app.log.error(err, signal, manual)
}
await app.close()
})
Expand All @@ -35,7 +48,7 @@ app.addHook('onClose', async (instance, done) => {
})

// Start listening.
app.listen({ port: process.env.PORT || 3000 }, (err) => {
app.listen({ port: PORT, host: LISTEN }, (err) => {
if (err) {
app.log.error(err)
process.exit(1)
Expand Down
Loading

0 comments on commit be511d1

Please sign in to comment.