GithubHelp home page GithubHelp logo

peggedassets-server's Introduction

peggedassets-server

How to list a new pegged asset

  1. Fork this repository.
  2. Create folder in src/adapters/peggedAssets with the same name as the CoinGecko id for the pegged asset.
  3. In that folder, write an adapter in Typescript and name it index.ts (see below for spec).
  4. 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.
  5. Import your adapter in src/adapters/peggedAssets/index.ts and then add it to the exports.
  6. (Optional) if the pegged asset has a ChainLink price feed, you can add the ChainLink smart contract 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 Adapters. They must return an object { peggedXYZ: x }, where peggedXYZ is a supported pegged asset type, and x is a Number. Currently only peggedUSD is supported.

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(),
    unreleased: async () => ({}),
  },
  bsc: {
    minted: async () => ({}),
    unreleased: async () => ({}),
    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

cocoahomology avatar edmulraney avatar

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.