Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade node, get rid of axios #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: get-npm-version
id: package-version
uses: martinbeentjes/npm-get-version-action@main
Expand Down Expand Up @@ -39,11 +39,11 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup .npmrc file to publish to npm
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: '12.x'
node-version: '22'
registry-url: 'https://registry.npmjs.org'
- name: Install modules
run: npm install
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/chai": "^4.2.18",
"@types/memoizee": "^0.4.7",
"@types/mocha": "^8.2.2",
"@types/node": "^14.14.37",
"@types/node": "^22.10.7",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.20.0",
"babel-eslint": "^10.1.0",
Expand All @@ -32,7 +32,6 @@
},
"dependencies": {
"@ethersproject/networks": "^5.5.0",
"axios": "^0.21.1",
"bignumber.js": "^9.0.1",
"ethcall": "^4.2.5",
"ethers": "^5.4.6",
Expand Down
12 changes: 6 additions & 6 deletions src/external-api.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import axios from "axios";
import memoize from "memoizee";
import { crvusd } from "./crvusd.js";
import { IExtendedPoolDataFromApi, INetworkName } from "./interfaces";

export const _getPoolsFromApi = memoize(
async (network: INetworkName, poolType: "main" | "crypto" | "factory" | "factory-crvusd" | "factory-crypto"): Promise<IExtendedPoolDataFromApi> => {
const url = `https://api.curve.fi/api/getPools/${network}/${poolType}`;
const response = await axios.get(url, { validateStatus: () => true });
return response.data.data ?? { poolData: [], tvl: 0, tvlAll: 0 };
const response = await fetch(url);
const {data} = await response.json() as { data: IExtendedPoolDataFromApi };
return data ?? { poolData: [], tvl: 0, tvlAll: 0 };
},
{
promise: true,
Expand All @@ -18,8 +17,9 @@ export const _getPoolsFromApi = memoize(
export const _getUserCollateral = memoize(
async (network: INetworkName, controller: string, user: string): Promise<string> => {
const url = `https://prices.curve.fi/v1/crvusd/collateral_events/${network}/${controller}/${user}`;
const response = await axios.get(url, { validateStatus: () => true });
return response.data.total_deposit;
const response = await fetch(url);
const {total_deposit} = await response.json() as { total_deposit: string };
return total_deposit;
},
{
promise: true,
Expand Down
12 changes: 6 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import axios from "axios";
import { ethers } from "ethers";
import BigNumber from 'bignumber.js';
import { IDict } from "./interfaces";
Expand Down Expand Up @@ -255,9 +254,10 @@ export const getUsdRate = async (coin: string): Promise<number> => {
const url = coinAddress === nativeTokenName ?
`https://api.coingecko.com/api/v3/simple/price?ids=${coinAddress}&vs_currencies=usd` :
`https://api.coingecko.com/api/v3/simple/token_price/${chainName}?contract_addresses=${coinAddress}&vs_currencies=usd`
const response = await axios.get(url);
const response = await fetch(url);
const data = await response.json() as IDict<{ usd?: number }>;
try {
_usdRatesCache[coinAddress] = {'rate': response.data[coinAddress]['usd'] ?? 0, 'time': Date.now()};
_usdRatesCache[coinAddress] = {'rate': data[coinAddress].usd ?? 0, 'time': Date.now()};
} catch (err) { // TODO pay attention!
_usdRatesCache[coinAddress] = {'rate': 0, 'time': Date.now()};
}
Expand Down Expand Up @@ -296,8 +296,8 @@ export const getLsdApy = memoize(async(name: 'wstETH' | 'sfrxETH'): Promise<{
baseApy: number,
apyMean30d: number,
}> => {
const response = await axios.get('https://yields.llama.fi/pools');
const {data} = response.data;
const response = await fetch('https://yields.llama.fi/pools');
const {data} = await response.json() as { data: { chain: string, project: string, symbol: string, apy: number, apyBase: number, apyMean30d: number }[] };

const params = {
'wstETH': {
Expand All @@ -314,7 +314,7 @@ export const getLsdApy = memoize(async(name: 'wstETH' | 'sfrxETH'): Promise<{
chain,
project,
symbol,
}: any) => (
}) => (
chain === 'Ethereum' &&
project === params[name].project &&
symbol === params[name].symbol
Expand Down
12 changes: 6 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"lib": ["ES2017"], /* Specify library files to be included in the compilation. */
"module": "ESNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"lib": ["ES2020"], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./dist", /* Redirect output structure to the directory. */
"rootDir": ".", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"outDir": "./dist", /* Redirect output structure to the directory. */
"rootDir": ".", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
Expand Down Expand Up @@ -43,7 +43,7 @@
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */

/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
Expand Down