Code Monkey home page Code Monkey logo

peggedassets-server's Introduction

peggedassets-server

How to list a new pegged asset

  1. Fork this repository.
  2. npm i in root folder.
  3. Create folder in src/adapters/peggedAssets with the same name as the CoinGecko id for the pegged asset.
  4. In that folder, write an adapter in Typescript and name it index.ts (see below for spec).
  5. In src/adapters/peggedAssets, npm i and then test your adapter with npx ts-node test YOURPEGGEDASSET/index peggedXYZ, where "peggedXYZ" is the key of the balance object returned by your adapter. or npx ts-node --transpile-only test.ts YOURPEGGEDASSET peggedXYZ
  6. Import your adapter in src/adapters/peggedAssets/index.ts and then add it to the exports.
  7. (Optional) if the pegged asset has a ChainLink price feed or a liquid Uniswap V3 pool, you can add the ChainLink smart contract/Uniswap V3 pool info to src/adapters/peggedAssets/prices/index.ts.

After submitting a PR, you can submit basic info about the pegged asset (website, ticker, icon, etc.) in the Defillama Discord.

Pegged asset adapters

An adapter is a Typescript file that exports an object in the following format:

const  adapter: PeggedIssuanceAdapter = {
  [chain1]: {
    minted: async fn,
    unreleased: async fn,
    [bridgedFromChain1]: async fn,
    [bridgedFromChain2]: async fn,
    .
    .
  },
  [chain2]: {
    minted: async fn,
    unreleased: async fn,
  },
.
.
}

The minted and unreleased properties are required to be present on every chain object. minted means pegged assets that have been issued on that chain (not bridged from anywhere). unreleased means pegged assets that are in a reserve wallet and have never been circulating. If either of these are 0, you can use async () => ({}).

The bridgedFromChain properties are optional. The property name should simply be the name of the chain the pegged assets are bridged from.

The async functions should take timestamp, ethBlock, and chainBlocks as parameters, just like Defillama TVL Adapters. They must return an object { peggedXYZ: x }, where peggedXYZ is a supported pegged asset type, and x is a Number. Currently we support peggedUSD, peggedEUR,peggedVAR (variable peg) and more you can see the full list here https://github.com/DefiLlama/peggedassets-server/blob/master/src/adapters/peggedAssets/peggedAsset.type.ts#L7 If we are not supporting a particular peggedTYPE, please inform us on discord.

Here is an example adapter:

const sdk = require("@defillama/sdk");
import {
  ChainBlocks,
  PeggedIssuanceAdapter,
} from "../peggedAsset.type";

const chainContracts = {
    ethereum: {
        issued: "0x853d955acef822db058eb8505911ed77f175b99e",
    },
    bsc: {
        bridgedFromETH: "0x90c97f71e18723b0cf0dfa30ee176ab653e89f40",
    },
};

async function ethereumMinted() {
return async function (
    _timestamp: number,
    _ethBlock: number,
    _chainBlocks: ChainBlocks
) {
    const totalSupply = (
      await sdk.api.abi.call({
        abi: "erc20:totalSupply",
        target: chainContracts.ethereum.issued,
        block: _ethBlock,
        chain: "ethereum",
      })
    ).output;
    return { peggedUSD: totalSupply / 10 ** 18 };
  };
}

async function bridgedFromEthereum(chain: string, decimals: number, address: string) {
return async function (
    _timestamp: number,
    _ethBlock: number,
    _chainBlocks: ChainBlocks
) {
    const totalSupply = (
      await sdk.api.abi.call({
        abi: "erc20:totalSupply",
        target: address,
        block: _chainBlocks[chain],
        chain: chain,
      })
    ).output;
    return { peggedUSD: totalSupply / 10 ** decimals };
  };
}

const adapter: PeggedIssuanceAdapter = {
  ethereum: {
    minted: ethereumMinted(),
  },
  bsc: {
    ethereum: bridgedFromEthereum("bsc", 18, chainContracts.bsc.bridgedFromETH),
  },
};

export default adapter;

Running the Server

If you want to run your own copy of this server on AWS:

npm run build # Build with webpack & check for type errors
npm run format # Format code

aws configure
serverless deploy

peggedassets-server's People

Contributors

0xaces avatar 0xmdreamy avatar 0xngmi avatar 0xstrobe avatar 0xtubanator avatar blazewashere avatar cocoahomology avatar codehans avatar define101 avatar dimarud1995 avatar elliotfriend avatar g1nt0ki avatar gmo-z-trust-deployer avatar grothem avatar hoomp3 avatar hyferion avatar hyperhammest avatar iamvukasin avatar jonathansmirnoff avatar khiemsoft avatar ktarun1419 avatar lgingerich avatar lililud avatar nkrulikovsky avatar realdealshaman avatar roinevirta avatar rrr-source avatar sunnya97 avatar szul-07 avatar tutacrypto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

peggedassets-server's Issues

fix issue avax/avalance

some protocols have chain name as avax, others have avalance, probably the same issue with stored data, need to check/fix this everywhere

remove /stablecoincharts/:chain & remove cache

verify that the route /stablecoincharts/:chain is not used anywhere and remove it to reduce server load

and since everything is loaded as a file, we no longer need to load cache for api server

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.