more logic to lib
This commit is contained in:
parent
cf6b9fa381
commit
25fc4a4c4d
25 changed files with 5838 additions and 3464 deletions
|
|
@ -2,7 +2,7 @@ require('dotenv').config();
|
|||
const { ethers } = require('ethers');
|
||||
const express = require('express');
|
||||
const { execute } = require('./.graphclient');
|
||||
const { bytesToUint256 } = require('kraiken-lib');
|
||||
const { decodePositionId, isPositionDelinquent } = require('kraiken-lib');
|
||||
|
||||
const myQuery = `
|
||||
query GetPositions {
|
||||
|
|
@ -56,17 +56,10 @@ async function canCallFunction() {
|
|||
}
|
||||
|
||||
async function checkPosition(position) {
|
||||
let taxRate = parseFloat(position.taxRate);
|
||||
let lastTaxTime = position.lastTaxTime;
|
||||
let passed = (Date.now() / 1000) - lastTaxTime;
|
||||
if (passed > 365 * 24 * 60 * 60 / taxRate ) {
|
||||
const hexString = position.id;
|
||||
const cleanHexString = hexString.startsWith('0x') ? hexString.substring(2) : hexString;
|
||||
const bytes = new Uint8Array(Math.ceil(cleanHexString.length / 2));
|
||||
for (let i = 0, j = 0; i < cleanHexString.length; i += 2, j++) {
|
||||
bytes[j] = parseInt(cleanHexString.slice(i, i + 2), 16);
|
||||
}
|
||||
let positionId = bytesToUint256(bytes);
|
||||
const taxRate = Number(position.taxRate);
|
||||
const lastTaxTime = Number(position.lastTaxTime);
|
||||
if (isPositionDelinquent(lastTaxTime, taxRate)) {
|
||||
const positionId = decodePositionId(position.id);
|
||||
console.log(`Calling payTax on ${positionId}`);
|
||||
const tx = await stakeContract.payTax(positionId);
|
||||
await tx.wait();
|
||||
|
|
@ -163,4 +156,3 @@ app.get('/status', async (req, res) => {
|
|||
app.listen(PORT, () => {
|
||||
console.log(`HTTP server running on port ${PORT}`);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue