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

Arthera mainnet #4

Draft
wants to merge 11 commits into
base: arthera-mainnet
Choose a base branch
from
Draft
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
39 changes: 38 additions & 1 deletion Algebra/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,39 @@
# Algebra Subgraph
# Algebra subgraph

## Configure

Before build you need to make a few changes:

* Update FACTORY_ADDRESS in Algebra/src/utils/constants.ts
* Update WAA_USDT_POOL, WHITELIST_TOKENS and STABLE_COINS in Algebra/src/utils/pricing.ts, through which the price in usd will be calculated.
* Depending on the order of the tokens in the pool, you must set the required price( token0Price/token1Price) in Algebra/src/utils/pricing.ts#L41
* You can also set the required number of native tokens in the pool to include it when calculating prices by changing MINIMUM_Arthera_LOCKED in Algebra/src/utils/pricing.ts
* Update network, startBlock and addresses in subgraph.yaml

## Install

To install dependencies you need to run:
```
yarn
```
## Build

To build you need to run:
```
yarn codegen
yarn build
```

## Create

To create you need to run:
```
yarn run create
```

## Deploy

To deploy you need to run:
```
yarn run deploy
```
10 changes: 4 additions & 6 deletions Algebra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
{
"name": "algebra-subgraph",
"version": "1.0.0",
"repository": "https://github.com/graphprotocol/algebra-subgraph",
"repository": "https://github.com/bertux/algebra-subgraph",
"license": "GPL-3.0-or-later",
"scripts": {
"codegen": "graph codegen --output-dir src/types/",
"build": "graph build",
"create-local": "graph create cryptoalgebra/algebra --node http://127.0.0.1:8020",
"deploy-local": "graph deploy cryptoalgebra/algebra --debug --ipfs http://localhost:5001 --node http://127.0.0.1:8020",
"deploy": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ --access-token iliaazhel/integral-core subgraph.yaml",
"deploy-dev": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ --access-token a3f47169869d4585a475d0d1d10a4062 iliaazhel/fuzzyswap subgraph.yaml",
"create": "graph create cryptoalgebra/info --node https://api.thegraph.com/create/"
"create": "graph create cryptoalgebra/algebra --node http://127.0.0.1:8020",
"remove": "graph remove cryptoalgebra/algebra --node http://127.0.0.1:8020/",
"deploy": "graph deploy cryptoalgebra/algebra --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020"
},
"devDependencies": {
"@graphprotocol/graph-cli": "0.64.0",
Expand Down
14 changes: 7 additions & 7 deletions Algebra/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type Factory @entity {
txCount: BigInt!
# total volume all time in derived USD
totalVolumeUSD: BigDecimal!
# total volume all time in derived Matic
# total volume all time in derived Arthera
totalVolumeMatic: BigDecimal!
# total swap fees all time in USD
totalFeesUSD: BigDecimal!
Expand All @@ -19,11 +19,11 @@ type Factory @entity {
totalValueLockedUSD: BigDecimal!
#
defaultCommunityFee: BigInt!
# TVL derived in Matic
# TVL derived in Arthera
totalValueLockedMatic: BigDecimal!
# TVL derived in USD untracked
totalValueLockedUSDUntracked: BigDecimal!
# TVL derived in Matic untracked
# TVL derived in Arthera untracked
totalValueLockedMaticUntracked: BigDecimal!
# current owner of the factory
owner: ID!
Expand All @@ -32,7 +32,7 @@ type Factory @entity {
# stores for USD calculations
type Bundle @entity {
id: ID!
# price of Matic in usd
# price of Arthera in usd
maticPriceUSD: BigDecimal!
}

Expand Down Expand Up @@ -65,7 +65,7 @@ type Token @entity {
totalValueLockedUSD: BigDecimal!
# TVL derived in USD untracked
totalValueLockedUSDUntracked: BigDecimal!
# derived price in Matic
# derived price in Arthera
derivedMatic: BigDecimal!
# pools token is in that are white listed for USD pricing
whitelistPools: [Pool!]!
Expand Down Expand Up @@ -131,7 +131,7 @@ type Pool @entity {
totalValueLockedToken1: BigDecimal!
feesToken0: BigDecimal!
feesToken1: BigDecimal!
# tvl derived Matic
# tvl derived Arthera
totalValueLockedMatic: BigDecimal!
# tvl USD
totalValueLockedUSD: BigDecimal!
Expand Down Expand Up @@ -463,7 +463,7 @@ type AlgebraDayData @entity {
id: ID!
# timestamp rounded to current day by dividing by 86400
date: Int!
# total daily volume in Algebra derived in terms of Matic
# total daily volume in Algebra derived in terms of Arthera
volumeMatic: BigDecimal!
# total daily volume in Algebra derived in terms of USD
volumeUSD: BigDecimal!
Expand Down
2 changes: 1 addition & 1 deletion Algebra/src/mappings/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function handleInitialize(event: Initialize): void {
let token0 = Token.load(pool.token0)!
let token1 = Token.load(pool.token1)!

// update Matic price now that prices could have changed
// update Arthera price now that prices could have changed
let bundle = Bundle.load('1')!
bundle.maticPriceUSD = getEthPriceInUSD()
bundle.save()
Expand Down
37 changes: 18 additions & 19 deletions Algebra/src/utils/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@ import { Bundle, Pool, Token } from './../types/schema'
import { BigDecimal, BigInt } from '@graphprotocol/graph-ts'
import { exponentToBigDecimal, safeDiv } from '../utils/index'

const WMatic_ADDRESS = '0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6'
const USDC_WMatic_03_POOL = '0xb104f0535a35a69880dab51008756c31d47dbf0f'
const WAA_ADDRESS = '0x69d349e2009af35206efc3937bad6817424729f7'
const WAA_USDT_POOL = '0xbb65cc425bcc049e0fcc084e312cccec72b3f6af'

// token where amounts should contribute to tracked volume and liquidity
// usually tokens that many tokens are paired with s
export let WHITELIST_TOKENS: string[] = [
'0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6', // WMATIC
'0xf2a0bc44debd394076c67962bb4869fd43c78018', // USDC
'0x5aefba317baba46eaf98fd6f381d07673bca6467', // USDT
'0x49a390a3dfd2d01389f799965f3af5961f87d228'
'0x69d349e2009af35206efc3937bad6817424729f7', // WAA
'0x8c4acd74ff4385f3b7911432fa6787aa14406f8b', // USDC
'0x6c45e28a76977a96e263f84f95912b47f927b687' // USDT
]

let MINIMUM_Matic_LOCKED = BigDecimal.fromString('0')
let MINIMUM_Arthera_LOCKED = BigDecimal.fromString('300')

let Q192 = Math.pow(2, 192)

let STABLE_COINS: string[] = [
'0xf2a0bc44debd394076c67962bb4869fd43c78018', // USDC
'0x5aefba317baba46eaf98fd6f381d07673bca6467' // SUDT
'0x8c4acd74ff4385f3b7911432fa6787aa14406f8b', // USDC
'0x6c45e28a76977a96e263f84f95912b47f927b687' // USDT
]


Expand All @@ -39,9 +38,9 @@ export function priceToTokenPrices(price: BigInt, token0: Token, token1: Token):
}

export function getEthPriceInUSD(): BigDecimal {
let usdcPool = Pool.load(USDC_WMatic_03_POOL) // dai is token0
if (usdcPool !== null) {
return usdcPool.token0Price
let usdtPool = Pool.load(WAA_USDT_POOL) // dai is token0
if (usdtPool !== null) {
return usdtPool.token1Price
} else {
return ZERO_BD
}
Expand All @@ -50,10 +49,10 @@ export function getEthPriceInUSD(): BigDecimal {

/**
* Search through graph to find derived Eth per token.
* @todo update to be derived Matic (add stablecoin estimates)
* @todo update to be derived Arthera (add stablecoin estimates)
**/
export function findEthPerToken(token: Token): BigDecimal {
if (token.id == WMatic_ADDRESS) {
if (token.id == WAA_ADDRESS) {
return ONE_BD
}
let whiteList = token.whitelistPools
Expand All @@ -76,21 +75,21 @@ export function findEthPerToken(token: Token): BigDecimal {
if (pool.token0 == token.id) {
// whitelist token is token1
let token1 = Token.load(pool.token1)!
// get the derived Matic in pool
// get the derived Arthera in pool
let maticLocked = pool.totalValueLockedToken1.times(token1.derivedMatic)
if (maticLocked.gt(largestLiquidityMatic) && maticLocked.gt(MINIMUM_Matic_LOCKED)) {
if (maticLocked.gt(largestLiquidityMatic) && maticLocked.gt(MINIMUM_Arthera_LOCKED)) {
largestLiquidityMatic = maticLocked
// token1 per our token * Eth per token1
priceSoFar = pool.token1Price.times(token1.derivedMatic as BigDecimal)
}
}
if (pool.token1 == token.id) {
let token0 = Token.load(pool.token0)!
// get the derived Matic in pool
// get the derived Arthera in pool
let maticLocked = pool.totalValueLockedToken0.times(token0.derivedMatic)
if (maticLocked.gt(largestLiquidityMatic) && maticLocked.gt(MINIMUM_Matic_LOCKED)) {
if (maticLocked.gt(largestLiquidityMatic) && maticLocked.gt(MINIMUM_Arthera_LOCKED)) {
largestLiquidityMatic = maticLocked
// token0 per our token * Matic per token0
// token0 per our token * Arthera per token0
priceSoFar = pool.token0Price.times(token0.derivedMatic as BigDecimal)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Algebra/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dataSources:
source:
address: '0x10253594A832f967994b44f33411940533302ACb'
abi: Factory
startBlock: 100000
startBlock: 138104
mapping:
kind: ethereum/events
apiVersion: 0.0.6
Expand Down Expand Up @@ -40,7 +40,7 @@ dataSources:
source:
address: '0x0BFaCE9a5c9F884a4f09fadB83b69e81EA41424B'
abi: NonfungiblePositionManager
startBlock: 100000
startBlock: 138126
mapping:
kind: ethereum/events
apiVersion: 0.0.6
Expand Down
36 changes: 35 additions & 1 deletion AlgebraFarming/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,36 @@
# Algebra Farming Subgraph
# AlgebraFarming subgraph

## Configure

Before build you need to make a few changes:

* Update FarmingCenterAddress in AlgebraFarming/src/utils/constants.ts
* Update network, startBlock and addresses in subgraph.yaml

## Install

To install dependencies you need to run:
```
yarn
```
## Build

To build you need to run:
```
yarn codegen
yarn build
```

## Create

To create you need to run:
```
yarn run create
```

## Deploy

To deploy you need to run:
```
yarn run deploy
```
11 changes: 4 additions & 7 deletions AlgebraFarming/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
{
"name": "algebra-farming-subgraph",
"version": "1.0.0",
"repository": "https://github.com/cryptoalgebra/algebra-subgraph",
"repository": "https://github.com/bertux/algebra-subgraph",
"license": "GPL-3.0-or-later",
"scripts": {
"codegen": "graph codegen --output-dir src/types/",
"build": "graph build",
"create-local": "graph create iliaazhel/karasb --node http://127.0.0.1:8020",
"create-pulse": "graph create cryptoalgebra/algebra-farming --node http://3.16.122.80:8120/",
"deploy-pulse": "graph deploy cryptoalgebra/algebra-farming --debug --ipfs http://3.16.122.80:5101 --node http://3.16.122.80:8120/",
"deploy-local": "graph deploy iliaazhel/karasb --debug --ipfs http://localhost:5001 --node http://127.0.0.1:8020",
"deploy": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ --access-token iliaazhel/zyberswap-farming subgraph.yaml",
"deploy-dev": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ iliaazhel/algebra-dev-staker subgraph.yaml"
"create": "graph create cryptoalgebra/algebra-farming --node http://127.0.0.1:8020",
"remove": "graph remove cryptoalgebra/algebra-farming --node http://127.0.0.1:8020/",
"deploy": "graph deploy cryptoalgebra/algebra-farming --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020"
},
"devDependencies": {
"@graphprotocol/graph-cli": "0.64.0",
Expand Down
4 changes: 2 additions & 2 deletions AlgebraFarming/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dataSources:
source:
address: '0x0BFaCE9a5c9F884a4f09fadB83b69e81EA41424B'
abi: NonfungiblePositionManager
startBlock: 100000
startBlock: 138126
mapping:
kind: ethereum/events
apiVersion: 0.0.6
Expand Down Expand Up @@ -40,7 +40,7 @@ dataSources:
source:
address: '0x13fcE0acbe6Fb11641ab753212550574CaD31415'
abi: EternalFarming
startBlock: 100000
startBlock: 138130
mapping:
kind: ethereum/events
apiVersion: 0.0.6
Expand Down
45 changes: 5 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,13 @@
# Algebra_Subgraph
# Algebra Subgraphs

## Algebra

### Build

Before build you need to make a few changes:

* Update FACTORY_ADDRESS in Algebra/src/utils/constants.ts
* Update USDC_WMatic_03_POOL, WHITELIST_TOKENS and STABLE_COINS in Algebra/src/utils/pricing.ts, through which the price in usd will be calculated.
* Depending on the order of the tokens in the pool, you must set the requred price( token0Price/token1Price) in Algebra/src/utils/pricing.ts#L41
* You can also set the required number of native tokens in the pool to include it when calculating prices by changing MINIMUM_Matic_LOCKED in Algebra/src/utils/pricing.ts
* Update network, startBlock and addresses in subgraph.yaml

After that you need to run:
```
$ yarn
$ yarn codegen
$ yarn build
```

### Deploy

For deploy you need to run:
```
$ yarn graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ --access-token <access-token> <graph-name> subgraph.yaml
```
[Algebra](Algebra/README.md)

## AlgebraFarming

Before build you need to make a few changes:

Update FarmingCenterAddress in AlgebraFarming/src/utils/constants.ts
Update network, startBlock and addresses in subgraph.yaml

After that you need to run:
```
$ yarn
$ yarn codegen
$ yarn build
```
[AlgebraFarming](AlgebraFarming/README.md)

### Deploy
## Blocklytics

For deploy you need to run:
```
$ yarn graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ --access-token <access-token> <graph-name> subgraph.yaml
```
[blocklytics](blocklytics/README.md)
Loading