1.0.17 • Published 2 years ago

skytale-liquidity-pools v1.0.17

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
2 years ago

skytale-liquidity-pools

Library to get APR/APY of Liquidity pools and invest in them.

Installation

npm install skytale-liquidity-pools

Usage

import { liquidityPools } from  'skytale-liquidity-pools';

const providers = liquidityPools.getProviders();
// output: ['balancer', 'mstable']

const balancerService = liquidityPools.getProvider(provider);

Supported Pools

const balancerService = liquidityPools.getProvider('balancer').setCurrency('eur');

/**
 * only usd usd and eur supported
 * /

Get Paginated Pools By Chain

balancerService.getPools(CHAIN_ID, PAGE_NO, PAGE_SIZE)
    .then((pools) => console.log(pools))
    .catch((error) => console.log(error));

/** output: 
  [
    {
        apr: {
        min: 1.2851894678129268,
        max: 1.2851894678129268,
        base: 1.2851894678129268
        },
        apy: {
        min: 1.2934606026798967,
        max: 1.2934606026798967,
        base: 1.2934606026798967
        },
        id: '0x231e687c9961d3a27e6e266ac5c433ce4f8253e4000200000000000000000023',
        liquidity: '6482128.171858008',
        poolName: 'Balancer 50 SRM 50 WETH',
        tokens: [
            {
                address: '0x476c5e26a75bd202a9683ffd34359c0cc15be0ff',
                balance: 3877214.902257,
                decimals: 6,
                name: undefined,
                symbol: 'SRM',
                weight: 0.5
            },
            {
                address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
                balance: 3070.3491080134445,
                decimals: 18,
                name: undefined,
                symbol: 'WETH',
                weight: 0.5
            }
        ],
        volume: '5966901.794115081',
        linearPoolTokensMap: undefined,
        wrappedTokens: undefined,
        mainTokens: undefined,
        chainId: 1
    }
    ...
    ...
    ...
  ]

**/

Get Pool By Id

balancerService.getPool(POOL_ID, CHAIN_ID)
    .then((pools) => console.log(pool))
    .catch((error) => console.log(error));

/** output: 
{
    apr: {
    min: 1.2851894678129268,
    max: 1.2851894678129268,
    base: 1.2851894678129268
    },
    apy: {
    min: 1.2934606026798967,
    max: 1.2934606026798967,
    base: 1.2934606026798967
    },
    id: '0x231e687c9961d3a27e6e266ac5c433ce4f8253e4000200000000000000000023',
    liquidity: '6482128.171858008',
    poolName: 'Balancer 50 SRM 50 WETH',
    tokens: [
        {
            address: '0x476c5e26a75bd202a9683ffd34359c0cc15be0ff',
            balance: 3877214.902257,
            decimals: 6,
            name: undefined,
            symbol: 'SRM',
            weight: 0.5
        },
        {
            address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
            balance: 3070.3491080134445,
            decimals: 18,
            name: undefined,
            symbol: 'WETH',
            weight: 0.5
        }
    ],
    volume: '5966901.794115081',
    linearPoolTokensMap: undefined,
    wrappedTokens: undefined,
    mainTokens: undefined,
    chainId: 1
}
**/

Get Pools With Investment Details of Wallet Address

balancerService.getUserPools(WALLETS)
    .then((userPools) => console.log(userPools))
    .catch((error) => console.log(error));

/** output:
    [
        {
            walletAddress: 'WALLET_ADDRESS',
            chain: 'polygon',
            userPoolShare: {
                balance: '0.793507214668472709',
                currency: 'EUR',
                investedAmount: 5.7703065445532875,
                userAddress: 'Mywallet',
                pool: {
                    apr: { base: 13.972187871832457 },
                    apy: { base: 14.992318305052832 },
                    id: '0x0297e37f1873d2dab4487aa67cd56b58e2f27875000100000000000000000002',
                    liquidity: 2842802.1908321516,
                    poolName: 'Balancer Polygon Base Pool',
                    tokens: [
                        {
                            address: '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270',
                            balance: 1695842.946616207,
                            decimals: 18,
                            symbol: 'WMATIC',
                            weight: 0.25
                        },
                        {
                            address: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174',
                            balance: 740560.659314,
                            decimals: 6,
                            symbol: 'USDC',
                            weight: 0.25
                        },
                        {
                            address: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',
                            balance: 724.2606535552587,
                            decimals: 18,
                            symbol: 'WETH',
                            weight: 0.25
                        },
                        {
                            address: '0x9a71012b13ca4d3d0cdc72a177df3ef03b0e76a3',
                            balance: 171873.59791679878,
                            decimals: 18,
                            symbol: 'BAL',
                            weight: 0.25
                        },
                        chainId: 1,
                    ],
                    volume: 5966901.794115081
                }
            }
        }
        ...
        ...
        ...

    ]
**/

Get Investment Details of Wallet in a Specific Pool

service invocation:

balancerService.getUserPool(POOL_ID, WALLET)
    .then((userPool) => console.log(userPool))
    .catch((error) => console.log(error));

output:

{
    "walletAddress": "WALLET_ADDRESS",
    "chain": "polygon",
    "userPoolShare": {
        "balance": "0.793507214668472709",
        "currency": "EUR",
        "investedAmount": 5.7703065445532875,
        "userAddress": "Mywallet",
        "pool": {
            "apr": { "base": 13.972187871832457 },
            "apy": { "base": 14.992318305052832 },
            "id": "0x0297e37f1873d2dab4487aa67cd56b58e2f27875000100000000000000000002",
            "liquidity": 2842802.1908321516,
            "poolName": "Balancer Polygon Base Pool",
            "tokens": [
                {
                    "address": "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270",
                    "balance": 1695842.946616207,
                    "decimals": 18,
                    "symbol": "WMATIC",
                    "weight": 0.25
                },
                {
                    "address": "0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
                    "balance": 740560.659314,
                    "decimals": 6,
                    "symbol": "USDC",
                    "weight": 0.25
                },
                {
                    "address": "0x7ceb23fd6bc0add59e62ac25578270cff1b9f619",
                    "balance": 724.2606535552587,
                    "decimals": 18,
                    "symbol": "WETH",
                    "weight": 0.25
                },
                {
                    "address": "0x9a71012b13ca4d3d0cdc72a177df3ef03b0e76a3",
                    "balance": 171873.59791679878,
                    "decimals": 18,
                    "symbol": "BAL",
                    "weight": 0.25
                },
            ],
            "chainId": 137,
            "volume": 5966901.794115081
        }
    }
}

Add Liquidity to a Pool

TOKEN_VALUE_MAP = { '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270' : 1, '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619': 0, 'token_address': amount to invest }

hasInfiniteAllowance : true if the token allowance must be set to exact amount to be invested. false if the allowance is to be set to infinity.

balancerService.joinPool(POOL_ID, TOKENS, TOKEN_ADDRESSES, CHAIN_ID, TOKEN_VALUE_MAP, WALLET_ADDRESS, hasInfiniteAllowance, WEB3_INSTANCE, JOIN_KIND)
    .then((tx) => console.log(tx))
    .catch((error) => console.log(error));

/**
Outputs the transaction hash
**/

Get Gas Cost Estimate to Add Liquidity to Pool

balancerService.getEstimatedGasCost(POOL_ID, TOKENS, TOKEN_ADDRESSES, CHAIN_ID, TOKEN_VALUE_MAP, WALLET_ADDRESS, WEB3_INSTANCE JOIN_KIND)
    .then((gas) => console.log(gas))
    .catch((error) => console.log(error));
/**
Outputs gas in token and in fiat
**/

Get an Estimated Value of Investment in Fiat Currency

balancerService.getEstimatedInvestmentValue(TOKEN_VALUE_MAP, CHAIN_ID)
    .then((value) => console.log(values))
    .catch((error) => console.log(error));
/**
Outputs estimated values and minimum BAL received
**/

Subgraphs Used

Contributors

Skytale Commons is developed by the Skytale team.

Dominic Fernandes@dominic.fernandes
Massimiliano Gerardi@massi.gerardi
Martin Mali@martinheti
Avinash Buddana@avinash.buddana1
Enrico Mariotti@boulder225
Joris Borsboom@jorisborsboom
Patrik Csokas@patricck
1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago