Skip to content

Commit

Permalink
Removes Covalent Deps + Redeployed
Browse files Browse the repository at this point in the history
  • Loading branch information
Ncookiez committed Mar 26, 2023
1 parent 54b0fc7 commit e61d7ea
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 856 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,15 @@ This repository is already setup for Firebase hosting, but could easily be adapt

Currently the API also uses many other cloud functions to manage token prices, API key caching, etc. but those can be easily disabled.

1. Add any required keys in `keys.json` (an example file is provided).
1. Install dependencies by navigating to the `functions` folder and using `npm i`.

2. Install dependencies by navigating to the `functions` folder and using `npm i`.
2. Add your project ID in `.firebaserc` (an example file is provided).

3. Add your project ID in `.firebaserc` (an example file is provided).
3. Change any settings to your liking in `index.ts`.

4. Change any settings to your liking in `index.ts`.
4. Optionally, whitelist any origins to be exempt from rate limits in `.env` (an example file is provided).

5. Optionally, whitelist any origins to be exempt from rate limits in `.env` (an example file is provided).

6. To deploy to Firebase, use `firebase deploy`.
5. To deploy to Firebase, use `firebase deploy`.

Note: The API is currently configured through `getKeyInfo()` in `functions.ts` to only validate keys with a chain identifier appended to it. Modify that function if your implementation is different!

Expand Down
393 changes: 1 addition & 392 deletions functions/functions.ts

Large diffs are not rendered by default.

52 changes: 1 addition & 51 deletions functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ import type { Application, Request, Response, NextFunction } from 'express';
// Fetching Swagger Docs Setup JSON File:
const swaggerDocs: JSON = require('../static/swagger.json');

// Fetching Firebase Logger Compatibility Patch:
require("firebase-functions/lib/logger/compat");

// Initializing Firebase App:
admin.initializeApp();

Expand Down Expand Up @@ -229,7 +226,7 @@ weaver.getAllChains().forEach(chain => {
let tokenPrice = await fn.fetchTokenPriceDB(admin, chain, address);
if(tokenPrice) { tokenInfo.price = tokenPrice; }
}
if(tokenInfo.price === 0) {
if(tokenInfo.price === 0 && decimals !== undefined) {
if(weaver[chain].isAddress(address as Address)) {
tokenInfo.price = await weaver[chain].getTokenPrice(address as Address, decimals);
} else {
Expand Down Expand Up @@ -310,53 +307,6 @@ weaver.getAllChains().forEach(chain => {
}
});

// Transaction History Endpoint:
api.get(`/${chain}/txs`, async (req: Request, res: Response) => {
let address = req.query.address as string | undefined;
let page = req.query.page as string | undefined;
let simple = req.query.simple as string | undefined;
if(address) {
try {
if(weaver[chain].isAddress(address as Address)) {
if(simple === 'true') {
fn.sendResponse(req, res, await fn.getSimpleTXs(chain, address as Address));
} else {
if(page !== undefined) {
fn.sendResponse(req, res, await fn.getTXs(chain, address as Address, parseInt(page)));
} else {
fn.sendResponse(req, res, await fn.getTXs(chain, address as Address));
}
}
} else {
fn.sendError('invalidAddress', res);
}
} catch(err) {
fn.sendError('internalError', res, err);
}
} else {
fn.sendError('missingAddress', res);
}
});

// Transaction Fees Endpoint:
api.get(`/${chain}/fees`, async (req: Request, res: Response) => {
let address = req.query.address as string | undefined;
if(address) {
try {
if(!localTesting && dbPrices) { await fn.fetchTokenPricesDB(admin); }
if(weaver[chain].isAddress(address as Address)) {
fn.sendResponse(req, res, await fn.getFees(chain, address as Address));
} else {
fn.sendError('invalidAddress', res);
}
} catch(err) {
fn.sendError('internalError', res, err);
}
} else {
fn.sendError('missingAddress', res);
}
});

// Token Price History Endpoint:
if(!localTesting && dbPrices) {
api.get(`/${chain}/tokenPriceHistory`, async (req: Request, res: Response) => {
Expand Down
3 changes: 0 additions & 3 deletions functions/keys.json.example

This file was deleted.

8 changes: 3 additions & 5 deletions functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@
"main": "lib/index.js",
"devDependencies": {
"@types/node": "^17.0.25",
"firebase-functions-test": "^0.2.0",
"typescript": "^4.5.4"
},
"dependencies": {
"3pi": "1.0.3",
"axios": "^0.26.1",
"cors": "^2.8.5",
"express": "^4.17.3",
"firebase-admin": "^10.0.2",
"firebase-functions": "^3.18.0",
"firebase-admin": "^11.5.0",
"firebase-functions": "^4.2.1",
"request-ip": "^3.3.0",
"swagger-ui-express": "^4.3.0",
"weaverfi": "1.37.0"
"weaverfi": "1.37.1"
}
}
Loading

0 comments on commit e61d7ea

Please sign in to comment.