Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ const vaultPerformance = require("./services/vaults/performance/handler");
const stakeVIP = require("./services/staking/xdvg/handler");
const stakePool = require("./services/staking/handler");
const stakeXDvg = require("./services/staking/vipdvg/handler");
const reimbursementAddresses = require("./services/reimbursement/handler")
const reimbursementAddresses = require("./services/reimbursement/handler");
const stakeDaoStakes = require("./services/staking/dao-stake/handler");
const specialEvent = require("./services/user/special-event/handler");
const reimburse = require("./services/user/reimburse/handler");
const referral = require("./services/referral/handler");
const deposit = require("./services/referral/deposit/handler");
const withdraw = require("./services/referral/withdraw/handler");
const app = express();
const cors = require("cors");
const port = process.env.PORT || 8080;
Expand All @@ -32,7 +35,6 @@ async function init() {

db.connectDB(async (err) => {
if (err) throw err;

jobs.saveVault();
jobs.saveVaultAPY();
jobs.savePolygonVaultAPY();
Expand All @@ -44,6 +46,7 @@ async function init() {
jobs.saveABIPools();
jobs.saveVipApr();
jobs.savePerformance();
jobs.saveTransaction();
});

app.use(cors());
Expand Down Expand Up @@ -80,7 +83,7 @@ async function init() {
stakeXDvg.getxDVGStake(req, res)
);
app.get("/staking/get-xdvd-stake", (req, res) => {
stakeXDvg.getxDVDStake(req, res)
stakeXDvg.getxDVDStake(req, res);
});
app.get("/event/verify", (req, res) =>
specialEvent.handleVerifyEvent(req, res)
Expand All @@ -103,7 +106,7 @@ async function init() {
app.get("/reimbursement-addresses/dvg/:address", (req, res) =>
reimbursementAddresses.handler(req, res)
);

app.get("/vaults/pnl/:farmer/:days", (req, res) =>
vaultPerformance.pnlHandle(req, res)
);
Expand All @@ -115,12 +118,36 @@ async function init() {
stakePool.snapshotEmergency(req, res)
);

app.get('/user/reimburse-address/:address', (req, res) =>
app.get("/user/reimburse-address/:address", (req, res) =>
reimburse.getReimburseAddress(req, res)
);

app.post('/user/reimburse-address/update', (req, res) => {
reimburse.updateReimburseAddressClaimAmount(req, res)
app.get("/user/getreferrals", (req, res) => {
referral.seeAllReferrals(req, res);
});

app.post("/user/addreferral", (req, res) => {
referral.addNewReferral(req, res);
});

app.post("/user/adddeposit", (req, res) => {
deposit.addDepositAmount(req, res);
});

app.get("/user/deposits", (req, res) => {
deposit.getAll(req, res);
});

app.post("/user/addwithdrawal", (req, res) => {
withdraw.addWithdrawalAmount(req, res);
});

app.get("/user/withdrawals", (req, res) => {
withdraw.getAll(req, res);
});

app.post("/user/reimburse-address/update", (req, res) => {
reimburse.updateReimburseAddressClaimAmount(req, res);
});

app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
Expand Down
8 changes: 5 additions & 3 deletions config/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ const Api = require("../utils/api");

let _db;
const connectDB = async (callback) => {
var url = '';
if (process.env.MONGO_AUTH != '') {
url = `mongodb://${encodeURIComponent(MONGO_USERNAME)}:${encodeURIComponent(MONGO_PASSWORD)}@${MONGO_HOSTNAME}:${MONGO_PORT}/${MONGO_DB}?authMechanism=${AUTH_MECHANISM}`;
var url = "";
if (process.env.MONGO_AUTH != "") {
url = `mongodb://${encodeURIComponent(MONGO_USERNAME)}:${encodeURIComponent(
MONGO_PASSWORD
)}@${MONGO_HOSTNAME}:${MONGO_PORT}/${MONGO_DB}?authMechanism=${AUTH_MECHANISM}`;
} else {
url = `mongodb://${MONGO_HOSTNAME}`;
}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
database:
image: mongo
container_name: "database"
command: [--auth]
#command: [--auth]
restart: always
ports:
- "27017:27017"
Expand Down
75 changes: 49 additions & 26 deletions jobs/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ const stakeSave = require("../services/staking/dao-stake/handler");
const poolSave = require("../services/staking/handler");
const vipDVG = require("../services/staking/vipdvg/handler");
const performanceSave = require("../services/vaults/performance/handler");
const transactionValidator = require("../services/referral/validate/handler");

const jobDelayTime = {
const jobDelayTime = {
saveHistoricalApy: 3 * 60 * 1000, // 3 mins in milliseconds
savePricePerFullShare: 6 * 60 * 1000, // 5 mins in milliseconds
saveTransaction: 6 * 60 * 1000, // 6 mins in milliseconds
savePricePerFullShare: 6 * 60 * 1000, // 6 mins in milliseconds
saveHistoricalTVL: 7 * 60 * 1000, // 7 mins
saveVaultApy: 15 * 60 * 1000, // 15 mins
saveABIPools: 18 * 60 * 1000, // 18 mins
savePolygonVaultAPY: 3 * 60 * 1000, // 3 mins in milliseconds;
saveReferralStatus: 6 * 60 * 1000, // 6 mins in milliseconds
};

/** Save Vault **/
Expand All @@ -35,11 +38,11 @@ const saveVault = async () => {
}
);
};
const saveVaultHandler = async() => {
const saveVaultHandler = async () => {
console.log(`[saveVault] START: ${new Date().getTime()}`);
await vaultSave.handler();
console.log(`[saveVault] END: ${new Date().getTime()}`);
}
};

/** Save Vault APY */
const saveVaultAPY = async () => {
Expand All @@ -57,16 +60,16 @@ const saveVaultAPY = async () => {
}
);
};
const saveVaultAPYHandler = async() => {
const saveVaultAPYHandler = async () => {
console.log(`[saveVaultAPY] START: ${new Date().getTime()}`);
await vaultHandlerSave.handler();
console.log(`[saveVaultAPY] END: ${new Date().getTime()}`);
}
};

/** Save Vault APY */
const savePolygonVaultAPY = async() => {
const savePolygonVaultAPY = async () => {
await delay(jobDelayTime.savePolygonVaultAPY);
await savePolygonVaultAPYHandler();;
await savePolygonVaultAPYHandler();

cron.schedule(
"0 0 0 * * *",
Expand All @@ -78,12 +81,12 @@ const savePolygonVaultAPY = async() => {
timezone: "Etc/UTC", // UTC +0
}
);
}
const savePolygonVaultAPYHandler = async() => {
};
const savePolygonVaultAPYHandler = async () => {
console.log(`[saveVaultAPY Polygon] START: ${new Date().getTime()}`);
await vaultPolygonHandlerSave.saveHandler();
console.log(`[saveVaultAPY Polygon] END: ${new Date().getTime()}`);
}
};

/** Store getPricePerFullShare */
const savePricePerFullShare = async () => {
Expand All @@ -100,17 +103,17 @@ const savePricePerFullShare = async () => {
}
);
};
const savePricePerFullShareHandler = async() => {
const savePricePerFullShareHandler = async () => {
console.log(`[savePricePerFullShare] START: ${new Date().getTime()}`);
await priceSave.handler();
console.log(`[savePricePerFullShare] END: ${new Date().getTime()}`);
}
};

/** Store Historical APY */
const saveHistoricalAPY = async () => {
await delay(jobDelayTime.saveHistoricalApy);
await saveHistoricalApyHandler();

cron.schedule(
"*/5 * * * *",
async () => {
Expand All @@ -121,11 +124,11 @@ const saveHistoricalAPY = async () => {
}
);
};
const saveHistoricalApyHandler = async() => {
const saveHistoricalApyHandler = async () => {
console.log(`[saveHistoricalAPY] START: ${new Date().getTime()}`);
await vaultApySave.saveHandler();
console.log(`[saveHistoricalAPY] END: ${new Date().getTime()}`);
}
};

/** Store Historical APY For Polygon */
const savePolygonHistoricalAPY = async () => {
Expand All @@ -139,12 +142,31 @@ const savePolygonHistoricalAPY = async () => {
scheduled: true,
}
);
}
};
const savePolygonHistoricalAPYHandler = async () => {
console.log(`[savePolygonHistoricalAPY] START: ${new Date().getTime()}`);
await vaultPolygonApySave.saveHandler();
console.log(`[savePolygonHistoricalAPY] END: ${new Date().getTime()}`);
}
};

//Blockchain Transaction Validator
const saveTransaction = async () => {
await saveTransactionHandler();
cron.schedule(
async () => {
await saveTransactionHandler();
},
{
scheduled: true,
}
);
};

const saveTransactionHandler = async () => {
console.log(`[saveTransaction] START: ${new Date().getTime()}`);
await transactionValidator.validator();
console.log(`[saveTransaction] END: ${new Date().getTime()}`);
};

/** Store Historical TVL */
const saveHistoricalTVL = async () => {
Expand All @@ -161,11 +183,11 @@ const saveHistoricalTVL = async () => {
}
);
};
const saveHistoricalTVLHandler = async() => {
const saveHistoricalTVLHandler = async () => {
console.log(`[saveTVL] START: ${new Date().getTime()}`);
await tvlSave.saveAllTVLhandler();
console.log(`[saveTVL] END: ${new Date().getTime()}`);
}
};

/** Store Historical Stake Pools */
const saveHistoricalPools = async () => {
Expand All @@ -180,11 +202,11 @@ const saveHistoricalPools = async () => {
}
);
};
const saveStakedPoolsHandler = async() => {
const saveStakedPoolsHandler = async () => {
console.log(`[saveStakedPools] START: ${new Date().getTime()}`);
await stakeSave.saveStakedPools();
console.log(`[saveStakedPools] END: ${new Date().getTime()}`);
}
};

/** Store Stake Pools ABI */
const saveABIPools = async () => {
Expand All @@ -201,11 +223,11 @@ const saveABIPools = async () => {
}
);
};
const saveABIPoolsHandler = async() => {
const saveABIPoolsHandler = async () => {
console.log(`[savePoolInfo] START: ${new Date().getTime()}`);
await poolSave.savePoolInfo();
console.log(`[savePoolInfo] END: ${new Date().getTime()}`);
}
};

/** Store DAOVIP APR */
const saveVipApr = async () => {
Expand All @@ -220,11 +242,11 @@ const saveVipApr = async () => {
}
);
};
const saveVipAprHandler = async() => {
const saveVipAprHandler = async () => {
console.log(`[saveVipApr] START: ${new Date().getTime()}`);
await vipDVG.getVipAPY();
console.log(`[saveVipApr] END: ${new Date().getTime()}`);
}
};

/** Store Performance */
const savePerformance = async () => {
Expand Down Expand Up @@ -259,4 +281,5 @@ module.exports = {
saveABIPools,
saveVipApr,
savePerformance,
saveTransaction,
};
58 changes: 58 additions & 0 deletions models/referral-deposit.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const mongo = require("../config/db");
const collection = "Referral-Deposit";
//const subgraphUrl = process.env.SUBGRAPH_ENDPOINT;
//const polygonSubgraphUrl = process.env.POLYGON_SUBGRAPH_ENDPOINT;

const findAll = async (query) => {
const db = mongo.getDB();
return await db.collection(collection).find(query).toArray();
};

const findOne = async (params) => {
const db = mongo.getDB();
return await db.collection(collection).findOne({
address: params,
});
};

const getTransaction = async (transactionID) => {
const db = mongo.getDB();
return await db.collection(collection).findOne({
_id: transactionID,
});
};

//Blockchain address, Amount, Referral

const depositAmount = async (params) => {
const db = mongo.getDB();
return await db.collection(collection).insertOne(params);
};

const updateStatus = async (id, amount) => {
const db = mongo.getDB();
const result = await db.collection(collection).findOne({
_id: id,
});
if (result) {
return await db.collection(collection).updateOne(
{
_id: id,
},
{
$set: {
status: "success",
amount: amount,
},
}
);
}
};

module.exports = {
findAll,
findOne,
getTransaction,
depositAmount,
updateStatus,
};
Loading