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

Fix indexing issues #6

Merged
merged 1 commit into from
Mar 24, 2023
Merged
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
88 changes: 69 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,96 @@ Configure `ETH_RPC_URL` for your target network in `.env`.

If you will change ABIs, please install `jq`.


## Development and Deployment

Commands for adding new data sources to the subgraph are listed in the [add-commands.txt](./add-commands.txt) file.

Once data sources have been added, entites can be modified in the [schema.graphql](./schema.graphql) file. After any update, the following commands must be run to ensure the new types are available for the event handlers:
```
yarn codegen
EdNoepel marked this conversation as resolved.
Show resolved Hide resolved
yarn build
```

After building, this subgraph can be run locally using provided docker container. To start, set the environment variable *ETH_RPC_URL* in your .env file. Then, run `docker-compose up`. Once the node is running, deploy the subgraph with:
```
yarn create-local
yarn deploy-local
```

Instructions on creating your own deployment are available in the [Graph Protocols Documentation](https://thegraph.com/docs/en/cookbook/quick-start/).


## Querying

The dockerized deployment offers a query UI at http://localhost:8000/subgraphs/name/ajna/graphql.

Below are some examples of queries that can be made to the Ajna Subgraph.

List pools showing their tokens and how many transactions have been performed on them:
```
{
pools {
id
createdAtBlockNumber
createdAtTimestamp
txCount
pools {
id
txCount
quoteToken {
id
symbol
}
collateralToken {
id
symbol
}
}
}
```

## Development

Commands for adding new data sources to the subgraph are listed in the [add-commands.txt](./add-commands.txt) file.

Once data sources have been added, entites can be modified in the [schema.graphql](./schema.graphql) file. After any update, the following commands must be run to ensure the new types are available for the event handlers:
List lender positions across all pools:
```
npm run codegen
npm run build
{
accounts {
id
lends {
lpb
bucket {
bucketIndex
quoteTokens
collateral
}
pool {
id
actualUtilization
currentDebt
htp
hpb
lup
maxBorrower
poolSize
reserves
targetUtilization
totalAjnaBurned
totalInterestEarned
quoteToken {
symbol
}
collateralToken {
symbol
}
}
}
}
}
```

This subgraph can be run locally using provided docker containers. To start, set the environment variable *ETH_RPC_URL* in your .env file. Then, run `docker-compose up`. Once the node is running, deploy the subgraph with:
```
npm run create-local
npm run deploy-local
```

Instructions on creating your own deployment are available in the [Graph Protocols Documentation](https://thegraph.com/docs/en/cookbook/quick-start/).

## Tests

Tests are written using the [Matchstick unit testing framework](https://github.com/LimeChain/matchstick/blob/main/README.md).

Run the Matchstick tests by executing:
```
npm run test
yarn test
```

## Maintenance
Expand Down
3 changes: 0 additions & 3 deletions src/erc-20-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ import {
Kick,
LiquidationAuction,
LoanStamped,
LPAllowance,
LPAllowances,
LPTransferors,
MoveQuoteToken,
Pool,
RemoveCollateral,
Expand Down
18 changes: 8 additions & 10 deletions src/utils/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ export function getPoolAddress(poolId: Bytes): Address {
export function getMomp(poolId: Bytes): BigDecimal {
const poolInfoUtilsAddress = poolInfoUtilsNetworkLookUpTable.get(dataSource.network())!
const poolInfoUtilsContract = PoolInfoUtils.bind(poolInfoUtilsAddress)
const momp = poolInfoUtilsContract.momp(Address.fromBytes(poolId))

return wadToDecimal(momp)
const pool = Pool.load(poolId)
// HACK: work around bug https://github.com/ajna-finance/contracts/issues/702
if (pool == null || pool.loansCount == BigInt.zero()) {
return BigDecimal.zero() // TODO: should probably return MAX_PRICE
} else {
return wadToDecimal(poolInfoUtilsContract.momp(Address.fromBytes(poolId)))
}
}

export class LoansInfo {
Expand Down Expand Up @@ -81,12 +85,6 @@ export function getPoolPricesInfo(pool: Pool): PoolPricesInfo {
return pricesInfo
}

export function getPoolMomp(pool: Pool): BigInt {
const poolInfoUtilsAddress = poolInfoUtilsNetworkLookUpTable.get(dataSource.network())!
const poolInfoUtilsContract = PoolInfoUtils.bind(poolInfoUtilsAddress)
return poolInfoUtilsContract.momp(Address.fromBytes(pool.id));
}

export class ReservesInfo {
reserves: BigInt
claimableReserves: BigInt
Expand Down Expand Up @@ -160,7 +158,7 @@ export function updatePool(pool: Pool): void {
pool.htpIndex = poolPricesInfo.htpIndex
pool.lup = wadToDecimal(poolPricesInfo.lup)
pool.lupIndex = poolPricesInfo.lupIndex
pool.momp = wadToDecimal(getPoolMomp(pool))
pool.momp = getMomp(pool.id)

// update reserve auction information
const poolReservesInfo = getPoolReservesInfo(pool)
Expand Down
8 changes: 7 additions & 1 deletion subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dataSources:
source:
address: "0x31BcbE14Ad30B2f7E1E4A14caB2C16849B73Dac3"
abi: PositionManager
startBlock: 8613513
mapping:
kind: ethereum/events
apiVersion: 0.0.7
Expand Down Expand Up @@ -48,6 +49,7 @@ dataSources:
source:
address: "0x9684b8eC942985b23d343cB82D2F30EdA8fD7179"
abi: ERC20PoolFactory
startBlock: 8613513
mapping:
kind: ethereum/events
apiVersion: 0.0.7
Expand All @@ -57,7 +59,9 @@ dataSources:
abis:
- name: ERC20PoolFactory
file: ./abis/ERC20PoolFactory.json
# add token ABI to each respective factory type for querying token contracts
# add pool and token ABIs to each respective factory type for querying token contracts
- name: ERC20Pool
file: ./abis/ERC20Pool.json
- name: ERC20
file: ./abis/ERC20.json
eventHandlers:
Expand All @@ -70,6 +74,7 @@ dataSources:
source:
address: "0xEd6890d748e62ddbb3f80e7256Deeb2fBb853476"
abi: RewardsManager
startBlock: 8613513
mapping:
kind: ethereum/events
apiVersion: 0.0.7
Expand Down Expand Up @@ -101,6 +106,7 @@ dataSources:
source:
address: "0x7DB5ba7cB6dAD74b45AAB027A7E7388eF18656DF"
abi: ERC721PoolFactory
startBlock: 8613513
mapping:
kind: ethereum/events
apiVersion: 0.0.7
Expand Down