Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #94 from astroport-fi/feat/cleanup_repo
Browse files Browse the repository at this point in the history
Feat/cleanup repo
  • Loading branch information
miclondev authored Sep 14, 2023
2 parents 9ac13e0 + cc79487 commit b9a881a
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 77 deletions.
30 changes: 14 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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://<username>:<password>@<dev-cluster-host.net>/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
Expand Down Expand Up @@ -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="...."
Expand Down
4 changes: 4 additions & 0 deletions src/aggregator/aggregateXAstroFees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export async function aggregateXAstroFees(priceMap: Map<string, PriceV2>): 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;
Expand Down
3 changes: 3 additions & 0 deletions src/aggregator/aggregateXAstroFees7d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export async function aggregateXAstroFees7d(priceMap: Map<string, PriceV2>): 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;
Expand Down
2 changes: 1 addition & 1 deletion src/aggregator/astroportStatCollect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function astroportStatsCollect(): Promise<void> {

// 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(
Expand Down
16 changes: 0 additions & 16 deletions src/bot/maker-fee-collector/feeSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand All @@ -34,29 +31,16 @@ export async function swap(): Promise<void> {
);

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);
Expand Down
6 changes: 2 additions & 4 deletions src/bot/slack-bot-backend-stats/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
Expand Down Expand Up @@ -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: ",
Expand Down
4 changes: 4 additions & 0 deletions src/collector/coingecko/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions src/collector/priceIndexer/priceCollectV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export async function indexPrices(pairs: Pair[], height = 0): Promise<Map<string
// Submit query and process responses
if (queries.length > 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
Expand All @@ -124,6 +125,11 @@ export async function indexPrices(pairs: Pair[], height = 0): Promise<Map<string
for (let i = 0; i < pairBatch.length; i++) {
const pair = pairBatch[i];
const pool = responses[responseIndex].data.wasm.contractQuery;
if (pool.error) {
responseIndex++;
continue;
}

const pool_type: string = pair.type;
// For stable pools we fetched additional information
let stableSwapRelativePrice = 0;
Expand Down
36 changes: 1 addition & 35 deletions src/governance/governanceProposalCollect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { Proposal } from "../models/proposal.model";
import { getProposals, getTotalVotingPowerAt } from "../lib/terra";
import { getProposals as getSavedProposals, saveProposals } from "../services/proposal.service";
import { proposalListToMap } from "../collector/helpers";
import axios from "axios";
import { generate_post_fields } from "./slackHelpers";
import { ProposalState, update_proposal_timestamps } from "./proposalStateMachine";
import { update_proposal_timestamps } from "./proposalStateMachine";
import constants from "../environment/constants";
import { aggregateVotesCount } from "../services/vote.service";

Expand All @@ -20,8 +18,6 @@ dayjs.extend(utc);
*/

const BATCH_SIZE = 1;
const WEBHOOK_URL =
"https://hooks.slack.com/services/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";

export async function governanceProposalCollect(): Promise<void> {
console.log("ENABLE_FEE_SWAP_NOTIFICATION: " + constants.ENABLE_FEE_SWAP_NOTIFICATION);
Expand Down Expand Up @@ -79,17 +75,6 @@ export async function governanceProposalCollect(): Promise<void> {
);

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
);
}
}
}

Expand Down Expand Up @@ -123,22 +108,3 @@ export async function governanceProposalCollect(): Promise<void> {
);
}
}

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);
}
1 change: 1 addition & 0 deletions src/lib/handler-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions src/modules/terra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
8 changes: 3 additions & 5 deletions src/recon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b9a881a

Please sign in to comment.