Skip to content

Instantly share code, notes, and snippets.

@Calvin-Huang
Created April 10, 2021 07:05
Show Gist options
  • Save Calvin-Huang/6f5009e86ff57c1df247d4e4dcdfc99c to your computer and use it in GitHub Desktop.
Save Calvin-Huang/6f5009e86ff57c1df247d4e4dcdfc99c to your computer and use it in GitHub Desktop.
const axios = require('axios');
async function getCycPool(address) {
const obj = {};
const resultList = await Promise.allSettled([
await axios.get('https://api.bscscan.com/api?module=proxy&action=eth_call&to=0x9634cfd96f1499990695ebbc081b4ee8d63d2e12&data=0902f1ac&tag=latest'),
await axios.get('https://api.bscscan.com/api?module=proxy&action=eth_call&to=0x9634cfd96f1499990695ebbc081b4ee8d63d2e12&data=18160ddd&tag=latest'),
await axios.get(`https://api.bscscan.com/api?module=proxy&action=eth_call&to=0x567da514637cfd7f9e1f185ae4aa163b3ebb5363&data=0xf40f0f52000000000000000000000000${address.replace(/^0x/, '')}&tag=latest`),
await axios.get(` https://api.bscscan.com/api?module=proxy&action=eth_call&to=0x567da514637cfd7f9e1f185ae4aa163b3ebb5363&data=0x1959a002000000000000000000000000${address.replace(/^0x/, '')}&tag=latest`),
await axios.get('https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=cyclone-protocol'),
]);
const [
LPReservesResponse,
LPTotalSupplyResponse,
pendingRewardResponse,
userInfoResponse,
priceResponse,
] = resultList.map(({ value: resultValue }, i) => resultValue);
const { data: LPReservesData = {} } = LPReservesResponse;
const { result: LPReservesResult = {} } = LPReservesData;
const { data: LPTotalSupplyData = {} } = LPTotalSupplyResponse;
const { result: LPTotalSupplyResult = {} } = LPTotalSupplyData;
const { data: pendingRewardData = {} } = pendingRewardResponse;
const { result: pendingRewardResult = {} } = pendingRewardData;
const { data: userInfoData = {} } = userInfoResponse;
const { result: userInfoResult = {} } = userInfoData;
const { data: priceData = [] } = priceResponse;
const { current_price: price = 0 } = priceData[0] || {};
const totelData = BigInt(LPReservesResult);
const cycInt = totelData / (0x10n ** 0x80n);
const bnbInt = (totelData - (cycInt * (0x10n ** 0x80n))) / (0x10n ** 0x40n);
const totalSupplyInt = BigInt(LPTotalSupplyResult);
const cycRatio = +`${(0xan ** 0x12n) * cycInt / totalSupplyInt}` / (10 ** 18);
const bnbRatio = +`${(0xan ** 0x12n) * bnbInt / totalSupplyInt}` / (10 ** 18);
const pendingRewardInt = BigInt(pendingRewardResult);
const userInfoResultInt = BigInt(userInfoResult) / (0x10n ** 0x40n);
const pendingReward = +`${pendingRewardInt}` / (10 ** 18);
const userLPstake = +`${userInfoResultInt}` / (10 ** 18);
obj.CYC = {
value: pendingReward + cycRatio * userLPstake,
price,
};
obj.WBNB = {
value: bnbRatio * userLPstake,
price: 0,
};
return obj;
}
(async () => {
try {
const [,, address] = process.argv;
const result = await getCycPool(address);
console.log(result);
} catch (error) {
console.log(error);
process.exit(1);
}
process.exit();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment