diff --git a/README.md b/README.md index ec34328..14b55c5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ -# Astroport API +## ⚠️ Deprecation and maintenace + +This repository is no longer actively maintained by Astroport. It will continue to be here on GitHub and freely available for anyone to fork and use, but we will not be actively monitoring or replying to issues and pull requests. + +This project was set up with [serverless framework](http://serverless.com/). ## Setting up development environment @@ -16,18 +20,20 @@ Copy .env.sample to .env for local development, by default only the GraphQL func cp .env.sample .env ``` -### Local Mongodb setup +### Mongodb setup -Dump development database +Restore backup dynamodb dump. -``` -mongodump --uri mongodb+srv://:@/astroport --out astroport.dev -``` +[Download Zip file](https://astroport-classic-mongodb-dump.s3.eu-west-1.amazonaws.com/astroport-classic-mongodb.zip) -Restore development database locally +Unzip and follow the instructions in the readme to restore mongodb. +Once you have your database running setup the following environment variables with your table name. + +Example for localhost: ``` -mongorestore -d astroport ./astroport.dev/astroport -h 127.0.0.1 --port 27050 +MONGODB_URL_RW="mongodb://localhost:27017/astroport" +MONGODB_URL_R="mongodb://localhost:27017/astroport" ``` ### Running functions @@ -71,14 +77,6 @@ echo -e 'NEW_SECRET="${{ secrets.NEW_SECRET_NAME }}"' >> .env.{dev,prod} After adding it, they must be defined in `src/environment/development.ts` and `src/environment/production.ts` using `process.env.VAR_NAME` -### Testnet wallet - -A testnet wallet with limited funds is available for tests. Just drop a message -in the [Slack #backend-internal](https://astrochad.slack.com/archives/C03B289KPDX) -channel to get access to the wallet - -## Other configuration options - ### Running unit tests - copy .env.development to .env.local and add MONGODB_URL="...." diff --git a/src/aggregator/aggregateXAstroFees.ts b/src/aggregator/aggregateXAstroFees.ts index e6eabf5..fda4292 100644 --- a/src/aggregator/aggregateXAstroFees.ts +++ b/src/aggregator/aggregateXAstroFees.ts @@ -30,6 +30,10 @@ export async function aggregateXAstroFees(priceMap: Map): Promi }); const astro_price = priceMap.get(constants.ASTRO_TOKEN)?.price_ust as number; + console.log("astro_price", astro_price); + if (!astro_price) { + return; + } let _24h_fees_ust = 0; let fees_with_no_price_count = 0; diff --git a/src/aggregator/aggregateXAstroFees7d.ts b/src/aggregator/aggregateXAstroFees7d.ts index c19cc04..e23d991 100644 --- a/src/aggregator/aggregateXAstroFees7d.ts +++ b/src/aggregator/aggregateXAstroFees7d.ts @@ -30,6 +30,9 @@ export async function aggregateXAstroFees7d(priceMap: Map): Pro }); const astro_price = priceMap.get(constants.ASTRO_TOKEN)?.price_ust as number; + if (!astro_price) { + return; + } let _7d_fees_ust = 0; let fees_with_no_price_count = 0; diff --git a/src/aggregator/astroportStatCollect.ts b/src/aggregator/astroportStatCollect.ts index f43eedb..fbac6ba 100644 --- a/src/aggregator/astroportStatCollect.ts +++ b/src/aggregator/astroportStatCollect.ts @@ -22,7 +22,7 @@ export async function astroportStatsCollect(): Promise { // get astro price let astroPrice = await getPriceByTokenAddress(constants.ASTRO_TOKEN); - astroPrice = astroPrice.price_ust; + astroPrice = astroPrice?.price_ust || 0; // write to astroport_stats await AstroportStat.updateOne( diff --git a/src/bot/maker-fee-collector/feeSwap.ts b/src/bot/maker-fee-collector/feeSwap.ts index ec33d4b..cb49d59 100644 --- a/src/bot/maker-fee-collector/feeSwap.ts +++ b/src/bot/maker-fee-collector/feeSwap.ts @@ -7,9 +7,6 @@ import { import axios from "axios"; import constants from "../../environment/constants"; -const SLACK_WEBHOOK = - "https://hooks.slack.com/services/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"; - const waitFor = (ms: number) => new Promise((r) => setTimeout(r, ms)); export async function swap(): Promise { @@ -34,29 +31,16 @@ export async function swap(): Promise { ); try { - let txhash = ""; await wallet .createAndSignTx({ msgs: [msg], gasPrices: [new Coin("uusd", 0.15)] }) .then((tx) => terra.tx.broadcast(tx)) .then((result) => { - txhash = result.txhash; console.log(`TX hash: ${result.txhash}`); if (result.logs.length >= 1) { console.log("logs.events: ", result.logs[result.logs.length - 1].events); } }); - const post_fields = generate_link_to_txn(txhash); - - const config = { - headers: { - "Content-Type": "application/json", - charset: "utf-8", - }, - }; - - await axios.post(SLACK_WEBHOOK, post_fields, config); - await waitFor(8000); } catch (e) { console.log(e); diff --git a/src/bot/slack-bot-backend-stats/index.ts b/src/bot/slack-bot-backend-stats/index.ts index 6a0149b..9347c6d 100644 --- a/src/bot/slack-bot-backend-stats/index.ts +++ b/src/bot/slack-bot-backend-stats/index.ts @@ -15,8 +15,6 @@ bluebird.config({ global.Promise = bluebird as any; const PROD_URL = "https://terra1-api.astroport.fi/graphql"; -const SLACK_WEBHOOK = - "https://hooks.slack.com/services/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"; export const run = lambdaHandlerWrapper( async (): Promise => { @@ -95,8 +93,8 @@ export const run = lambdaHandlerWrapper( charset: "utf-8", }, }; - - await axios.post(SLACK_WEBHOOK, post_fields, config); + // POST TO SLACK + // await axios.post(SLACK_WEBHOOK, post_fields, config); }, { errorMessage: "Error while running slack-bot-backend-stats: ", diff --git a/src/collector/coingecko/client.ts b/src/collector/coingecko/client.ts index 8f04f8c..99363a6 100644 --- a/src/collector/coingecko/client.ts +++ b/src/collector/coingecko/client.ts @@ -4,6 +4,10 @@ import constants from "../../environment/constants"; export async function fetchExternalTokenPrice(source: string, address: string, currency: string) { const url = "https://pro-api.coingecko.com/api/v3/simple/token_price/" + source; + if (!constants.COINGECKO_API_KEY || constants.COINGECKO_API_KEY === "injected-via-secrets") { + return; + } + const params = { contract_addresses: address, vs_currencies: currency, diff --git a/src/collector/priceIndexer/priceCollectV2.ts b/src/collector/priceIndexer/priceCollectV2.ts index 109a80a..28fa69b 100644 --- a/src/collector/priceIndexer/priceCollectV2.ts +++ b/src/collector/priceIndexer/priceCollectV2.ts @@ -116,6 +116,7 @@ export async function indexPrices(pairs: Pair[], height = 0): Promise 0) { const responses = await batchQuery(queries); + // console.log({ responses: JSON.stringify(responses, null, 2) }); if (responses) { // responseIndex is tracked separately because some pairs have // an additional pricing response @@ -124,6 +125,11 @@ export async function indexPrices(pairs: Pair[], height = 0): Promise { console.log("ENABLE_FEE_SWAP_NOTIFICATION: " + constants.ENABLE_FEE_SWAP_NOTIFICATION); @@ -79,17 +75,6 @@ export async function governanceProposalCollect(): Promise { ); new_proposals.push(proposal); - - // notify slack for mainnet - if (constants.ENABLE_FEE_SWAP_NOTIFICATION) { - await notifySlack( - "*New on-chain governance proposal: #" + proposal.proposal_id + "*", - "https://apeboard.finance/dashboard/" + proposal.submitter, - proposal.title, - proposal.description, - proposal.link - ); - } } } @@ -123,22 +108,3 @@ export async function governanceProposalCollect(): Promise { ); } } - -async function notifySlack( - intro: string, - wallet_link: string, - title: string, - description: string, - link: string -) { - const post_fields = generate_post_fields(intro, wallet_link, title, description, link); - - const config = { - headers: { - "Content-Type": "application/json", - charset: "utf-8", - }, - }; - - await axios.post(WEBHOOK_URL, post_fields, config); -} diff --git a/src/lib/handler-wrapper.ts b/src/lib/handler-wrapper.ts index dc6749d..bc642a4 100644 --- a/src/lib/handler-wrapper.ts +++ b/src/lib/handler-wrapper.ts @@ -70,6 +70,7 @@ export const lambdaHandlerWrapper = if (initDatabaseConnection && disconnectDbWhenError) { await disconnectDatabase(); } + console.log(err); //TODO use a better error logging service? throw new Error(errorMessage + err); } diff --git a/src/modules/terra.ts b/src/modules/terra.ts index bf8cc6e..873a488 100644 --- a/src/modules/terra.ts +++ b/src/modules/terra.ts @@ -31,6 +31,10 @@ export const getTokenAmount = (info: any) => { }; export const getAssetAmountsInPool = (pool: any, token: string) => { + if (!pool?.assets) { + return { token1: 0, token2: 0 }; + } + return pool.assets.reduce( (prev: any, a: any) => { const key = getTokenDenom(a.info) === token ? "token1" : "token2"; diff --git a/src/recon/index.ts b/src/recon/index.ts index a1ff880..2245e7f 100644 --- a/src/recon/index.ts +++ b/src/recon/index.ts @@ -28,9 +28,6 @@ global.Promise = bluebird as any; const BATCH_SIZE = 10; const RECON_PREVIOUS_HOURS = 3; -const SLACK_WEBHOOK = - "https://hooks.slack.com/services/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"; - /** * The Recon service checks for any missing events based on the last indexed * block and RECON_PREVIOUS_HOURS @@ -246,8 +243,9 @@ export const run = lambdaHandlerWrapper( charset: "utf-8", }, }; - - await axios.post(SLACK_WEBHOOK, post_fields, config); + //add an endpoint if you want to send notifications to slack; + //const SLACK_WEBHOOK_ENDPOINT = "" + // await axios.post(SLACK_WEBHOOK, post_fields, config); } console.log("Total time elapsed (s): " + (new Date().getTime() - start) / 1000);