@avalabs/core-token-prices-sdk 2.8.0-alpha.197
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +9 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +1 -0
- package/esm/index.d.ts +2 -0
- package/esm/index.js +1 -0
- package/esm/token-pricing.d.ts +11 -0
- package/esm/token-pricing.js +1 -0
- package/esm/trader-joe.d.ts +18 -0
- package/esm/trader-joe.js +1 -0
- package/package.json +26 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Copyright (C) 2021, Ava Labs, Inc. All rights reserved.
|
|
2
|
+
|
|
3
|
+
Subject to the limited license below (**”License””), you may not, and you may not permit anyone else to, copy, reproduce, aggregate, republish, download, post, distribute, license, sublicense, reverse engineer, modify, or create derivative works based on this software (collectively, **“Software”**).
|
|
4
|
+
|
|
5
|
+
You are hereby granted a limited, non-exclusive, non-sublicensable and non-transferable license to download and use the Software as-is solely (i) for use in connection with the Avalanche Public Blockchain platform, having a NetworkID of 1 (Mainnet) or 5 (Fuji), and associated blockchains, comprised exclusively of the Avalanche X-Chain, C-Chain, P-Chain and any subnets linked to the P-Chain (**“Avalanche Authorized Platform”**) or (ii) for non-production, testing or research purposes without any commercial application within the Avalanche ecosystem (**“Non-Commercial Use”**); provided that, in each case, you may not use or allow use of the Software (a) in connection with any forks of the Avalanche Authorized Platform, (b) in any manner not operationally connected to the Avalanche Authorized Platform other than for Non-Commercial Use, or (c) to the extent the number of monthly active users or the number of total installs of any software that uses the Software across all versions thereof exceeds 10,000 at any time. You may not modify or alter the Software in any way.
|
|
6
|
+
|
|
7
|
+
You hereby acknowledge and agree to the terms set forth at www.avalabs.org/important-notice.
|
|
8
|
+
|
|
9
|
+
**TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED ON AN “AS IS” BASIS, AND AVA LABS EXPRESSLY DISCLAIMS AND EXCLUDES ALL REPRESENTATIONS, WARRANTIES AND OTHER TERMS AND CONDITIONS, WHETHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION BY OPERATION OF LAW OR BY CUSTOM, STATUTE OR OTHERWISE, AND INCLUDING, BUT NOT LIMITED TO, ANY IMPLIED WARRANTY, TERM, OR CONDITION OF NON-INFRINGEMENT, MERCHANTABILITY, TITLE, OR FITNESS FOR PARTICULAR PURPOSE. YOU USE THE SOFTWARE AT YOUR OWN RISK. AVA LABS EXPRESSLY DISCLAIMS ALL LIABILITY (INCLUDING FOR ALL DIRECT, CONSEQUENTIAL OR OTHER DAMAGES OR LOSSES) RELATED TO ANY USE OF THE SOFTWARE.**
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param addresses an array of token addresses
|
|
4
|
+
* @param currentCurrency the selected vsCurrency
|
|
5
|
+
* @param avaxPrice The current price of avax
|
|
6
|
+
* @param coinGeckoApiKey optional coin gecko api key
|
|
7
|
+
* @returns Record<address, number>
|
|
8
|
+
*/
|
|
9
|
+
declare function getTokensPrice(addresses: string[], currentCurrency: string, avaxPrice: number, assetPlatformId: string, coinGeckoApiKey?: string): Promise<Record<string, number>>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Returns the price of the given contract address in AVAX.
|
|
13
|
+
* @param address ERC20 contract address
|
|
14
|
+
*/
|
|
15
|
+
declare function getTokenAvaxPrice(address: string): Promise<any>;
|
|
16
|
+
/**
|
|
17
|
+
* Returns a dictionary of AVAX values for each contract address.
|
|
18
|
+
* @param addresses ERC20 Contract addresses
|
|
19
|
+
*/
|
|
20
|
+
declare function getTokenPricesAVAX(addresses: string[]): Promise<Record<string, string>>;
|
|
21
|
+
/**
|
|
22
|
+
* Returns a dictionary of USD values for each contract address.
|
|
23
|
+
* @param addresses ERC20 Contract addresses
|
|
24
|
+
* @param avaxPrice The current price of avax with currency conversion already done
|
|
25
|
+
*/
|
|
26
|
+
declare function getTokenPrices(addresses: string[], avaxPrice: number): Promise<Record<string, number>>;
|
|
27
|
+
|
|
28
|
+
export { getTokenAvaxPrice, getTokenPrices, getTokenPricesAVAX, getTokensPrice };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("@avalabs/core-coingecko-sdk"),t=require("@avalabs/core-utils-sdk");const r="https://api.thegraph.com/subgraphs/name/traderjoe-xyz/exchange";async function n(e){const n=function(e){return{query:`\n {\n token(id: "${e}") {\n derivedAVAX\n }\n }`,variables:{}}}(e),[s]=await t.resolve(fetch(r,{method:"POST",body:JSON.stringify(n)}).then((e=>e.json())));return s.data.token?.derivedAVAX}async function s(e){if(!e.length)return{};const t=e.map((e=>n(e).then((t=>({[e]:t})))));return(await Promise.allSettled(t)).reduce(((e,t)=>{"rejected"!==t.status&&t.value}),{})}async function c(e,t){try{const r=await s(e);return Object.keys(r).reduce(((e,n)=>{const s=parseFloat(r[n]);return isNaN(s)?e:{...e,[n]:s*t}}),{})}catch(e){return{}}}exports.getTokenAvaxPrice=n,exports.getTokenPrices=c,exports.getTokenPricesAVAX=s,exports.getTokensPrice=async function(r,n,s,o,a){const[i]=await t.resolve(e.simpleTokenPrice(a?e.getProCoingeckoHttp():e.getBasicCoingeckoHttp(),{assetPlatformId:o,tokenAddresses:r,currencies:[n],coinGeckoProApiKey:a})),u=Object.keys(i||{}).reduce(((e,t)=>{const r=(i?i[t]:{})[n];return{...e,[t]:r.price}}),{}),d=Object.keys(u),k=r.filter((e=>d.includes(e))),[l]=await t.resolve(c(k,s));return{...u,...l}};
|
package/esm/index.d.ts
ADDED
package/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{getTokensPrice}from"./token-pricing.js";export{getTokenAvaxPrice,getTokenPrices,getTokenPricesAVAX}from"./trader-joe.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param addresses an array of token addresses
|
|
4
|
+
* @param currentCurrency the selected vsCurrency
|
|
5
|
+
* @param avaxPrice The current price of avax
|
|
6
|
+
* @param coinGeckoApiKey optional coin gecko api key
|
|
7
|
+
* @returns Record<address, number>
|
|
8
|
+
*/
|
|
9
|
+
declare function getTokensPrice(addresses: string[], currentCurrency: string, avaxPrice: number, assetPlatformId: string, coinGeckoApiKey?: string): Promise<Record<string, number>>;
|
|
10
|
+
|
|
11
|
+
export { getTokensPrice };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{simpleTokenPrice as e,getProCoingeckoHttp as r,getBasicCoingeckoHttp as o}from"@avalabs/core-coingecko-sdk";import{resolve as t}from"@avalabs/core-utils-sdk";import{getTokenPrices as s}from"./trader-joe.js";async function c(c,a,i,n,d){const[k]=await t(e(d?r():o(),{assetPlatformId:n,tokenAddresses:c,currencies:[a],coinGeckoProApiKey:d})),m=Object.keys(k||{}).reduce(((e,r)=>{const o=(k?k[r]:{})[a];return{...e,[r]:o.price}}),{}),u=Object.keys(m),f=c.filter((e=>u.includes(e))),[l]=await t(s(f,i));return{...m,...l}}export{c as getTokensPrice};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the price of the given contract address in AVAX.
|
|
3
|
+
* @param address ERC20 contract address
|
|
4
|
+
*/
|
|
5
|
+
declare function getTokenAvaxPrice(address: string): Promise<any>;
|
|
6
|
+
/**
|
|
7
|
+
* Returns a dictionary of AVAX values for each contract address.
|
|
8
|
+
* @param addresses ERC20 Contract addresses
|
|
9
|
+
*/
|
|
10
|
+
declare function getTokenPricesAVAX(addresses: string[]): Promise<Record<string, string>>;
|
|
11
|
+
/**
|
|
12
|
+
* Returns a dictionary of USD values for each contract address.
|
|
13
|
+
* @param addresses ERC20 Contract addresses
|
|
14
|
+
* @param avaxPrice The current price of avax with currency conversion already done
|
|
15
|
+
*/
|
|
16
|
+
declare function getTokenPrices(addresses: string[], avaxPrice: number): Promise<Record<string, number>>;
|
|
17
|
+
|
|
18
|
+
export { getTokenAvaxPrice, getTokenPrices, getTokenPricesAVAX };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{resolve as t}from"@avalabs/core-utils-sdk";const e="https://api.thegraph.com/subgraphs/name/traderjoe-xyz/exchange";async function n(n){const r=function(t){return{query:`\n {\n token(id: "${t}") {\n derivedAVAX\n }\n }`,variables:{}}}(n),[a]=await t(fetch(e,{method:"POST",body:JSON.stringify(r)}).then((t=>t.json())));return a.data.token?.derivedAVAX}async function r(t){if(!t.length)return{};const e=t.map((t=>n(t).then((e=>({[t]:e})))));return(await Promise.allSettled(e)).reduce(((t,e)=>{"rejected"!==e.status&&e.value}),{})}async function a(t,e){try{const n=await r(t);return Object.keys(n).reduce(((t,r)=>{const a=parseFloat(n[r]);return isNaN(a)?t:{...t,[r]:a*e}}),{})}catch(t){return{}}}export{n as getTokenAvaxPrice,a as getTokenPrices,r as getTokenPricesAVAX};
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@avalabs/core-token-prices-sdk",
|
|
3
|
+
"version": "2.8.0-alpha.197",
|
|
4
|
+
"license": "Limited Ecosystem License",
|
|
5
|
+
"private": false,
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "esm/index.js",
|
|
8
|
+
"typings": "dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"esm"
|
|
12
|
+
],
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "restricted"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"start": "rollup -c --watch",
|
|
19
|
+
"build": "rollup -c",
|
|
20
|
+
"lint": "eslint --fix -c ./.eslintrc.js \"src/**/*.ts*\""
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@avalabs/core-coingecko-sdk": "2.8.0-alpha.197",
|
|
24
|
+
"@avalabs/core-utils-sdk": "2.8.0-alpha.197"
|
|
25
|
+
}
|
|
26
|
+
}
|