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

Dev/warchest tvl #2

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@ module.exports = {
},
env: {
es6: true
},
parserOptions: {
sourceType: 'module',
ecmaVersion: 8
// ecmaFeatures: {
// jsx: true,
// experimentalObjectRestSpread: true
// }
}
};
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<img src="https://app.apollo.farm/favicon.ico" align="right" width="50" />

# Apollo TVL Query


## Installation

```sh
yarn
```

## Use

### Vault TVL Report
```
yarn start
```

### Warchest TVL Report
```
yarn warchest
```

### Lockdrop TVL Report
```
yarn lockdrop
```
45 changes: 45 additions & 0 deletions lockdrop_report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
yarn run v1.22.17
$ ts-node src/lockdrop_query.ts
[
{
height: 7544910,
block_time: '2022-05-07T14:59:37.792844612Z',
total_value: 13213259448696.861,
xastro_balance: 4569088817148,
xastro_price: 2.8918806303582656
},
{
height: 7531780,
block_time: '2022-05-06T14:49:53.986299932Z',
total_value: 11818134230823.59,
xastro_balance: 3758110306029,
xastro_price: 3.1447012643200454
},
{
height: 7518650,
block_time: '2022-05-05T14:30:08.250193914Z',
total_value: 8629176093398.7295,
xastro_balance: 2546560110333,
xastro_price: 3.3885617144416584
},
{
height: 7505520,
block_time: '2022-05-04T14:12:20.49731768Z',
total_value: 7131371351642.362,
xastro_balance: 2170216177565,
xastro_price: 3.286018888516359
},
{
height: 7492390,
block_time: '2022-05-03T13:27:05.484164924Z',
total_value: 5267758232464.739,
xastro_balance: 1613486638987,
xastro_price: 3.2648291626213966
}
]
5 day:
average value: 9211939871405.256
average value (demicrofy): 9211939.871405257
average balance: 2931492410012.4
average balance (demicrofy): 2931492.4100124
Done in 14.49s.
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
"license": "Copyright Apollo DAO",
"private": true,
"scripts": {
"start": "ts-node src/index.ts"
"start": "ts-node src/index.ts",
"warchest": "ts-node src/warchest_query.ts",
"lockdrop": "ts-node src/lockdrop_query.ts",
"dev": "nodemon src/lockdrop_query.ts"
},
"dependencies": {
"@terra-money/terra.js": "^3.1.2",
"axios": "^0.27.2",
"bignumber.js": "^9.0.2"
},
Expand All @@ -18,7 +22,7 @@
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"prettier": "^2.2.1",
"ts-node": "^9.1.1",
"ts-node": "^10.8.1",
"typescript": "^4.2.4"
}
}
37 changes: 37 additions & 0 deletions src/data/anchor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import BigNumber from 'bignumber.js';
import { contractQuery } from '../network';

// fetch aUST balance
export const getaUSTBalance = async (height: number) => {
try {
const output: any = await contractQuery(
'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu',
{
balance: {
address: 'terra1hxrd8pnqytqpelape3aemprw3a023wryw7p0xn'
}
},
height
);
return parseInt(output.balance);
} catch (error) {
return 0;
}
};

// get aUST value
export const getaUSTPrice = async (height: number) => {
try {
const output: any = await contractQuery(
'terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s',
{
epoch_state: {}
},
height
);

return new BigNumber(output.exchange_rate).toNumber();
} catch (error) {
return 0;
}
};
98 changes: 98 additions & 0 deletions src/data/apollo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import BigNumber from 'bignumber.js';

import {
getTokenBalance,
getTokenValueFromStableLP,
getLPTokenValue,
getApolloVaultBalance,
contractQuery
} from '../network';

// fetch Apollo balance
export const getApolloBalance = async (height: number) => {
try {
const output: any = await contractQuery(
'terra100yeqvww74h4yaejj6h733thgcafdaukjtw397',
{
balance: {
address: 'terra1hxrd8pnqytqpelape3aemprw3a023wryw7p0xn'
}
},
height
);
return parseInt(output.balance);
} catch (error) {
return 0;
}
};

// get Apollo value
export const getApolloPrice = async (height: number) => {
try {
const apollo_price = await getTokenValueFromStableLP(height, 'APOLLOUSTLP');
return apollo_price;
} catch (error) {
return 0;
}
};

// locked LP Balance
export const getAstroportApolloLpBalance = async (height: number) => {
try {
const output: any = await contractQuery(
'terra1627ldjvxatt54ydd3ns6xaxtd68a2vtyu7kakj',
{
user_info: {
address: 'terra1hxrd8pnqytqpelape3aemprw3a023wryw7p0xn'
}
},
height
);
return new BigNumber(output.lockup_infos[0].lp_units_locked).toNumber();
} catch (error) {
return 0;
}
};

// get apollo lp share
export const getApolloLPTotalSupply = async (height: number) => {
try {
const output: any = await contractQuery(
'terra1n3gt4k3vth0uppk0urche6m3geu9eqcyujt88q',
{
token_info: {}
},
height
);
return new BigNumber(output.total_supply || '0').toNumber();
} catch (error) {
return 0;
}
};

// get apollo lp uusd amount
export const getApolloLpUusdAmount = async (height: number) => {
try {
const output: any = await contractQuery(
'terra1xj2w7w8mx6m2nueczgsxy2gnmujwejjeu2xf78',
{
pool: {}
},
height
);
return new BigNumber(
output.assets.find((a: any) => a.info.hasOwnProperty('native_token'))
.amount || '0'
)
.times(2)
.toNumber();
} catch (error) {
return 0;
}
};

export const getApolloLPPrice = async (height: number) => {
return new BigNumber(await getAstroportApolloLpBalance(height))
.div(new BigNumber(await getApolloLPTotalSupply(height)))
.toNumber();
};
115 changes: 115 additions & 0 deletions src/data/astro.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { networks } from '../networks';
import {
contractQuery,
getTokenBalance,
getTokenValueFromStableLP
} from '../network';

// get astro deposited into staking contract
const getAstroDeposited = async (height: number, network = 'classic') => {
try {
const res: any = await contractQuery(
networks[network].contracts.astro_farm_governance,
{
total_deposit: {}
},
height
);
return parseFloat(res);
} catch (error) {
// console.log(`ERROR: ${error}`);
console.log('error fetching astro balance');
return 0;
}
};

// get xastro total supply
const getXAstroSupply = async (height: number, network = 'classic') => {
const x_astro_contract = networks[network].tokens.find(
(token: any) => token.symbol === 'XASTRO'
).token_contract;

if (!x_astro_contract) return 0;

try {
const res: any = await contractQuery(
x_astro_contract,
{
token_info: {}
},
height
);
return parseFloat(res.total_supply);
} catch (error) {
// console.log(`ERROR: ${error}`);
console.log('error fetching xastro supply');
return 0;
}
};

// fetch astro balance
export const getAstroBalance = async (height: number): Promise<number> => {
try {
const astro_balance = await getTokenBalance(height, 'ASTRO', '');
return astro_balance;
} catch (error) {
// console.log(error);
console.log('error fetching astro balance');
return 0;
}
};

// fetch xastro balance
export const getXAstroBalance = async (height: number): Promise<number> => {
try {
const x_astro_balance = await getTokenBalance(height, 'XASTRO', '');
return x_astro_balance;
} catch (error) {
console.log('error fetching xastro balance');
return 0;
}
};

// get astro value from ASTRO-UST LP pool
export const getAstroPrice = async (height: number) => {
try {
const astro_price = await getTokenValueFromStableLP(height, 'ASTROUSTLP');
return astro_price;
} catch (error) {
console.log('error fetching astro price');
return 0;
}
};

// convert astro to xastro
export const getXAstroPrice = async (height: number) => {
try {
const astro_price = await getAstroPrice(height);
const total_astro_deposited = await getAstroDeposited(height);
const x_astro_supply = await getXAstroSupply(height);

const astro_xastro_exchange = total_astro_deposited / x_astro_supply;

return astro_price * astro_xastro_exchange;
} catch (error) {
console.log('error fetching xastro price');
//console.log(`ERROR: ${error}`);
return 0;
}
};

// return just exchange
const getXAstroExchange = async (height: number) => {
try {
const total_astro_deposited = await getAstroDeposited(height);
const x_astro_supply = await getXAstroSupply(height);

const astro_xastro_exchange = total_astro_deposited / x_astro_supply;

return astro_xastro_exchange;
} catch (error) {
//console.log(`ERROR: ${error}`);
console.log('error fetching x astro price');
return 0;
}
};
Loading