github.com/diadata-org/diadata@v1.4.593/cmd/interlay/utils.js (about)

     1  function collaterlaratio(issuedtoken, lockedtoken) {
     2    return { issued_token: issuedtoken, locked_token: lockedtoken };
     3  }
     4  
     5  function createResponse(issuedtoken, lockedtoken, fairPrice, ratio) {
     6    return {
     7      collateral_ratio: {
     8        issued_token: issuedtoken,
     9        locked_token: lockedtoken,
    10        ratio: ratio,
    11      },
    12      fair_price: fairPrice,
    13      timestamp: Date.now(),
    14  
    15    };
    16  }
    17  
    18  function tokenkey(source, token) {
    19    return "LSD_" + token;
    20  }
    21  
    22  function pricekey(token) {
    23    return "BASE_PARICE_" + token;
    24  }
    25  
    26  let cache;
    27  
    28  let isRedisStarted;
    29  function redis() {
    30    const redis = require("redis");
    31    const redishost = process.env.REDISHOST;
    32    const redisport = process.env.REDISPORT;
    33  
    34    const redispassword = process.env.REDISPASSWORD;
    35    let redisurl = "redis://:" + redispassword + "@" + redishost + ":" + redisport;
    36  
    37   
    38    if (!isRedisStarted) {
    39      (async () => {
    40        cache = redis.createClient({
    41          url: redisurl,
    42        });
    43  
    44        // cache =  redis.createClient();
    45  
    46        cache.on("error", (error) => console.error(`Error : ${error}`));
    47  
    48        await cache.connect();
    49      })();
    50      isRedisStarted = true;
    51    }
    52  
    53    return cache;
    54  }
    55  
    56  const allowedTokens = [
    57    // {
    58    //   vtoken: "nASTR",
    59    //   token: "ASTR",
    60    //   source: "astar",
    61    //   issuer: "Algem",
    62  
    63    // },
    64  
    65    {
    66      vtoken: "vMOVR",
    67      token: "MOVR",
    68      source: "bifrost",
    69      issuer: "Bifrost",
    70    },
    71    {
    72      vtoken: "vBNC",
    73      token: "BNC",
    74      source: "bifrost",
    75      issuer: "Bifrost",
    76    },
    77    {
    78      vtoken: "vGLMR",
    79      token: "GLMR",
    80      source: "bifrost",
    81      issuer: "Bifrost",
    82    },
    83    {
    84      vtoken: "vASTR",
    85      token: "ASTR",
    86      source: "bifrost",
    87      issuer: "Bifrost",
    88    },
    89    {
    90      vtoken: "vFIL",
    91      token: "FIL",
    92      source: "bifrost",
    93      issuer: "Bifrost",
    94    },
    95    {
    96      vtoken: "IBTC",
    97      token: "BTC",
    98      source: "interlay",
    99      issuer: "Interlay",
   100    },
   101    {
   102      vtoken: "vKSM",
   103      token: "KSM",
   104      source: "bifrost",
   105      issuer: "Bifrost",
   106    },
   107    {
   108      vtoken: "vDOT",
   109      token: "DOT",
   110      source: "bifrost",
   111      issuer: "Bifrost",
   112    },
   113    {
   114      vtoken: "stDOT",
   115      token: "DOT",
   116      source: "stDOT",
   117      issuer: "Lido",
   118    },
   119    {
   120      vtoken: "rETH",
   121      token: "ETH",
   122      source: "rETH",
   123      issuer: "RocketPool",
   124    },
   125    {
   126      vtoken: "stETH",
   127      token: "ETH",
   128      source: "stETH",
   129      issuer: "Lido",
   130    },
   131    // {
   132    //   vtoken: "cbETH",
   133    //   token: "ETH",
   134    //   source: "cbETH",
   135    //   issuer: "Coinbase",
   136  
   137    // },
   138    {
   139      vtoken: "KBTC",
   140      token: "BTC",
   141      source: "interlay",
   142      issuer: "Interlay",
   143    },
   144  ];
   145  
   146  async function getPrice(asset) {
   147    var providerurl = process.env.DIADATA_API || "https://api.diadata.org/v1/quotation/";
   148  
   149    let response = await fetch(providerurl + "/quotation/" + asset);
   150    let ethprice = await response.json();
   151    return ethprice.Price;
   152  }
   153  
   154  module.exports = {
   155    collaterlaratio: collaterlaratio,
   156    tokenkey: tokenkey,
   157    redis: redis,
   158    createResponse: createResponse,
   159    allowedTokens: allowedTokens,
   160    getPrice: getPrice,
   161    pricekey: pricekey,
   162  };