Skip to content

Commit

Permalink
fix(#patch): aave-v3; sort reward tokens (#897)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimehgb authored Aug 29, 2022
1 parent 003f263 commit 3914e2c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ This repo contains subgraphs defined using a set of standardized schemas. These
| [VVS Finance](https://vvs.finance/) | 🛠 | 1.3.0 / 1.1.6 / 1.0.0 | [![VVS Finance Cronos](./docs/images/chains/cronos.png)](https://graph.cronoslabs.com/subgraphs/name/messari/vvs-finance) |
| **Lending Protocols** | | |
| [Aave v2](https://aave.com/) || 2.0.1 / 1.2.12 / 1.0.0 | [![Aave V2 Ethereum](./docs/images/chains/ethereum.png)](https://thegraph.com/hosted-service/subgraph/messari/aave-v2-ethereum) [![Aave V2 Ethereum ARC](./docs/images/chains/ethereum.png)](https://thegraph.com/hosted-service/subgraph/messari/aave-arc-ethereum) [![Aave V2 Ethereum RWA](./docs/images/chains/ethereum.png)](https://thegraph.com/hosted-service/subgraph/messari/aave-rwa-ethereum) [![Aave V2 Ethereum AMM](./docs/images/chains/ethereum.png)](https://thegraph.com/hosted-service/subgraph/messari/aave-amm-ethereum) [![Aave V2 Avalanche](./docs/images/chains/avalanche.png)](https://thegraph.com/hosted-service/subgraph/messari/aave-v2-avalanche) [![Aave V2 Polygon](./docs/images/chains/matic.png)](https://thegraph.com/hosted-service/subgraph/messari/aave-v2-polygon) |
| [Aave v3](https://aave.com/) || 2.0.1 / 1.0.2 / 1.0.0 | [![Aave V3 Optimism](./docs/images/chains/optimism.png)](https://thegraph.com/hosted-service/subgraph/messari/aave-v3-optimism) [![Aave V3 Polygon](./docs/images/chains/matic.png)](https://thegraph.com/hosted-service/subgraph/messari/aave-v3-polygon) [![Aave V3 Harmony](./docs/images/chains/harmony.png)](https://thegraph.com/hosted-service/subgraph/messari/aave-v3-harmony) [![Aave V3 Fantom](./docs/images/chains/fantom.png)](https://thegraph.com/hosted-service/subgraph/messari/aave-v3-fantom) [![Aave V3 Avalanche](./docs/images/chains/avalanche.png)](https://thegraph.com/hosted-service/subgraph/messari/aave-v3-avalanche) [![Aave V3 Arbitrum](./docs/images/chains/arbitrum.png)](https://thegraph.com/hosted-service/subgraph/messari/aave-v3-arbitrum) |
| [Aave v3](https://aave.com/) || 2.0.1 / 1.0.3 / 1.0.0 | [![Aave V3 Optimism](./docs/images/chains/optimism.png)](https://thegraph.com/hosted-service/subgraph/messari/aave-v3-optimism) [![Aave V3 Polygon](./docs/images/chains/matic.png)](https://thegraph.com/hosted-service/subgraph/messari/aave-v3-polygon) [![Aave V3 Harmony](./docs/images/chains/harmony.png)](https://thegraph.com/hosted-service/subgraph/messari/aave-v3-harmony) [![Aave V3 Fantom](./docs/images/chains/fantom.png)](https://thegraph.com/hosted-service/subgraph/messari/aave-v3-fantom) [![Aave V3 Avalanche](./docs/images/chains/avalanche.png)](https://thegraph.com/hosted-service/subgraph/messari/aave-v3-avalanche) [![Aave V3 Arbitrum](./docs/images/chains/arbitrum.png)](https://thegraph.com/hosted-service/subgraph/messari/aave-v3-arbitrum) |
| [Aurigami](https://www.aurigami.finance/) | 🛠 | 2.0.1 / 1.1.3 / 1.0.0 | [![Aurigami Aurora](./docs/images/chains/aurora.png)](https://thegraph.com/hosted-service/subgraph/messari/aurigami-aurora) |
| [Alpaca Finance (Lend)](https://app.alpacafinance.org/lend) | 🔨 | | |
| [Bastion Protocol](https://bastionprotocol.com/) | 🛠 | 2.0.1 / 1.1.3 / 1.0.0 | [![Bastion Protocol Aurora](./docs/images/chains/aurora.png)](https://thegraph.com/hosted-service/subgraph/messari/bastion-protocol-aurora) |
Expand Down
42 changes: 42 additions & 0 deletions subgraphs/aave-v3/protocols/aave-v3/src/entities/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ export function updateMarketRewardTokens(
market.rewardTokens = rewardTokens;
market.rewardTokenEmissionsAmount = rewardTokenEmissions;
market.rewardTokenEmissionsUSD = rewardTokenEmissionsUSD;

sortRewardTokens(market);
updateMarketRewardTokenEmissions(event, market);
}

Expand Down Expand Up @@ -446,3 +448,43 @@ function updateMarketTVL(event: ethereum.Event, market: Market): void {
market.totalDepositBalanceUSD = totalValueLocked;
updateMarketRewardTokenEmissions(event, market);
}

function sortRewardTokens(market: Market): void {
if (market.rewardTokens!.length <= 1) {
return;
}

let tokens = market.rewardTokens;
let emissions = market.rewardTokenEmissionsAmount;
let emissionsUSD = market.rewardTokenEmissionsUSD;
multiArraySort(tokens!, emissions!, emissionsUSD!);

market.rewardTokens = tokens;
market.rewardTokenEmissionsAmount = emissions;
market.rewardTokenEmissionsUSD = emissionsUSD;
}

function multiArraySort(ref: Array<string>, arr1: Array<BigInt>, arr2: Array<BigDecimal>): void {
if (ref.length != arr1.length || ref.length != arr2.length) {
// cannot sort
return;
}

let sorter : Array<Array<string>> = [];
for (let i = 0; i < ref.length; i++) {
sorter[i] = [ref[i], arr1[i].toString(), arr2[i].toString()];
}

sorter.sort(function(a: Array<string>, b: Array<string>): i32 {
if (a[0] < b[0]) {
return -1;
}
return 1;
});

for (let i = 0; i < sorter.length; i++) {
ref[i] = sorter[i][0];
arr1[i] = BigInt.fromString(sorter[i][1]);
arr2[i] = BigDecimal.fromString(sorter[i][2]);
}
}
2 changes: 1 addition & 1 deletion subgraphs/aave-v3/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { BigDecimal, BigInt } from "@graphprotocol/graph-ts";
export const PROTOCOL_NAME = "Aave V3";
export const PROTOCOL_SLUG = "aave-v3";
export const PROTOCOL_SCHEMA_VERSION = "1.3.0";
export const PROTOCOL_SUBGRAPH_VERSION = "1.0.2";
export const PROTOCOL_SUBGRAPH_VERSION = "1.0.3";
export const PROTOCOL_METHODOLOGY_VERSION = "1.0.0";

////////////////////////
Expand Down

0 comments on commit 3914e2c

Please sign in to comment.