github.com/diadata-org/diadata@v1.4.593/cmd/interlay/cbETHhelper.js (about) 1 const {collaterlaratio} = require("./utils") 2 const Web3 = require("web3"); 3 const web3 = new Web3( 4 new Web3.providers.HttpProvider( 5 process.env.ETHEREUM_NODE_URL ||"https://mainnet.infura.io/v3/2883d1b22e0e4d62b535592dd8075fee" 6 ) 7 ); 8 9 let abi = [ 10 { 11 inputs: [], 12 name: "exchangeRate", 13 outputs: [ 14 { 15 internalType: "uint256", 16 name: "_exchangeRate", 17 type: "uint256", 18 }, 19 ], 20 stateMutability: "view", 21 type: "function", 22 }, 23 { 24 inputs: [], 25 name: "totalSupply", 26 outputs: [ 27 { 28 internalType: "uint256", 29 name: "", 30 type: "uint256", 31 }, 32 ], 33 stateMutability: "view", 34 type: "function", 35 }, 36 ]; 37 38 const contractAddress = "0xBe9895146f7AF43049ca1c1AE358B0541Ea49704"; 39 40 const contract = new web3.eth.Contract(abi, contractAddress); 41 42 function exchangeRate() { 43 return new Promise(function (resolve, reject) { 44 contract.methods.exchangeRate().call((error, result) => { 45 if (error) { 46 reject(error); 47 } else { 48 resolve(result); 49 } 50 }); 51 }); 52 } 53 function totalSupply() { 54 return new Promise(function (resolve, reject) { 55 contract.methods.totalSupply().call((error, result) => { 56 if (error) { 57 reject(error); 58 } else { 59 resolve(result); 60 } 61 }); 62 }); 63 } 64 65 async function getValues() { 66 let totalIssued = await totalSupply(); 67 // let totalBacked = await getTotalPooledETH(); 68 return collaterlaratio(totalIssued, ""); 69 } 70 71 module.exports = { 72 exchangeRate: exchangeRate, 73 totalSupply: totalSupply, 74 getValues: getValues, 75 };