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

Cross-Chain POL #273

Merged
merged 21 commits into from
Jul 25, 2024
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Deployed at:
- [Ethereum mainnet](https://thegraph.com/explorer/subgraphs/7jeChfyUTWRyp2JxPGuuzxvGt3fDKMkC9rLjm7sfLcNp?view=Overview&chain=arbitrum-one)
- [Polygon](https://thegraph.com/explorer/subgraphs/aF7zBXagiSjwwM1yAUiyrWFJDhh5RLpVn2nuvVbKwDw?view=Overview&chain=arbitrum-one)
- [Arbitrum](https://thegraph.com/explorer/subgraphs/8Zxb1kVv9ZBChHXEPSgtC5u5gjCijMn5k8ErpzRYWNgH?view=Overview&chain=arbitrum-one)
- [Fantom](https://thegraph.com/hosted-service/subgraph/olympusdao/protocol-metrics-polygon)
- [Fantom](https://thegraph.com/explorer/subgraphs/3qSJTWdWJETFzht814HVV9rVafwRLQp3k9mZhCF39bYd?v=1&view=Query&chain=arbitrum-one)
- [Base](https://thegraph.com/explorer/subgraphs/3YAC1Gj2AUFCQ8wd4DaBQmqU3DJZjKyr45dQykAtXuMU?view=Overview&chain=arbitrum-one)

## Initial Setup

Expand Down
7 changes: 7 additions & 0 deletions subgraphs/arbitrum/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Arbitrum Subgraph Changelog

## 1.7.9 (2024-07-17)

- Adds POL in Camelot
- Change the Chainlink price feed used as a trigger in order to increase indexing speed
- Reduce code paths for determining protocol addresses
- Modify Uniswap V2 PriceHandler to return 0 if the contract reverts

## 1.6.4 (2023-09-13)

- Apply write-off of JonesDAO token, since it cannot be sold.
Expand Down
4 changes: 2 additions & 2 deletions subgraphs/arbitrum/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "QmRf3fo7tVsXsj9cQZSgT3Y2R67Hv41T1Ph559oQAmTLe1",
"id": "QmNQfMN2GjnGYx2mGo92gAc7z47fMbTMRR9M1gGEUjLZHX",
"org": "olympusdao",
"name": "protocol-metrics-arbitrum",
"version": "1.6.4"
"version": "1.7.9"
}
19 changes: 15 additions & 4 deletions subgraphs/arbitrum/src/contracts/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const LP_UNISWAP_V2_JONES_GOHM_GOHM = "0x292d1587a6bb37e34574c9ad5993f221
export const LP_UNISWAP_V2_JONES_WETH = "0xe8ee01ae5959d3231506fcdef2d5f3e85987a39c".toLowerCase();
export const LP_UNISWAP_V2_LQTY_WETH = "0x8e78f0f6d116f94252d3bcd73d8ade63d415c1bf".toLowerCase();
export const LP_UNISWAP_V2_MAGIC_WETH = "0xb7e50106a5bd3cf21af210a755f9c8740890a8c9".toLowerCase();
export const LP_CAMELOT_OHM_WETH = "0x8aCd42e4B5A5750B44A28C5fb50906eBfF145359".toLowerCase();
export const LP_UNISWAP_V3_ARB_WETH = "0xc6f780497a95e246eb9449f5e4770916dcd6396a".toLowerCase();
export const LP_UNISWAP_V3_WETH_USDC = "0xc31e54c7a869b9fcbecc14363cf510d1c41fa443".toLowerCase();

Expand All @@ -45,6 +46,7 @@ export const SILO_ADDRESS = "0x9992f660137979C1ca7f8b119Cd16361594E3681".toLower
export const SENTIMENT_LTOKEN = "0x37E6a0EcB9e8E5D90104590049a0A197E1363b67".toLowerCase();

export const JONES_WRITE_OFF_BLOCK = "130482707";
export const LUSD_START_BLOCK = "80000000";

export const SILO_DEPLOYMENTS = new Array<LendingMarketDeployment>();
SILO_DEPLOYMENTS.push(new LendingMarketDeployment(ERC20_OHM, BigInt.fromString("99067079"), BigDecimal.fromString("25000"), SILO_ADDRESS)); // https://arbiscan.io/tx/0x55cabbd6cd41d2fa79a6c93743729bbfa85577ff3e92255f27bfd832344871f6
Expand All @@ -71,19 +73,27 @@ ERC20_TOKENS_ARBITRUM.set(LP_UNISWAP_V2_GOHM_WETH, new TokenDefinition(LP_UNISWA
ERC20_TOKENS_ARBITRUM.set(LP_UNISWAP_V2_JONES_GOHM_GOHM, new TokenDefinition(LP_UNISWAP_V2_JONES_GOHM_GOHM, TokenCategoryPOL, true, false));
ERC20_TOKENS_ARBITRUM.set(LP_UNISWAP_V2_JONES_WETH, new TokenDefinition(LP_UNISWAP_V2_JONES_WETH, TokenCategoryPOL, true, false));
ERC20_TOKENS_ARBITRUM.set(LP_UNISWAP_V2_MAGIC_WETH, new TokenDefinition(LP_UNISWAP_V2_MAGIC_WETH, TokenCategoryPOL, true, false));
ERC20_TOKENS_ARBITRUM.set(LP_CAMELOT_OHM_WETH, new TokenDefinition(LP_CAMELOT_OHM_WETH, TokenCategoryPOL, true, false));
ERC20_TOKENS_ARBITRUM.set(LP_UNISWAP_V3_ARB_WETH, new TokenDefinition(LP_UNISWAP_V3_ARB_WETH, TokenCategoryPOL, true, false));
ERC20_TOKENS_ARBITRUM.set(LP_UNISWAP_V3_WETH_USDC, new TokenDefinition(LP_UNISWAP_V3_WETH_USDC, TokenCategoryPOL, true, false));

export const OHM_TOKENS = [ERC20_GOHM_SYNAPSE, ERC20_OHM];

export const DAO_MULTISIG = "0x012BBf0481b97170577745D2167ee14f63E2aD4C".toLowerCase();

export const getProtocolAddresses = (): string[] => {
// Combine the wallet addresses with DAO multisig
return WALLET_ADDRESSES.concat([DAO_MULTISIG]);
};

const TREASURY_BLACKLIST = new Map<string, string[]>();

/**
* OHM and gOHM in the following wallets are blacklisted (not indexed) as we do not want the value
* being considered as part of the protocol or DAO treasuries.
*/
TREASURY_BLACKLIST.set(ERC20_GOHM_SYNAPSE, WALLET_ADDRESSES);
TREASURY_BLACKLIST.set(ERC20_OHM, WALLET_ADDRESSES);
TREASURY_BLACKLIST.set(ERC20_GOHM_SYNAPSE, getProtocolAddresses());
TREASURY_BLACKLIST.set(ERC20_OHM, getProtocolAddresses());

/**
* Some wallets (e.g. {DAO_WALLET}) have specific treasury assets mixed into them.
Expand All @@ -96,7 +106,7 @@ TREASURY_BLACKLIST.set(ERC20_OHM, WALLET_ADDRESSES);
* @returns
*/
export const getWalletAddressesForContract = (contractAddress: string): string[] => {
const walletAddresses = WALLET_ADDRESSES.slice(0);
const walletAddresses = getProtocolAddresses().slice(0);

// If the contract isn't on the blacklist, return as normal
if (!TREASURY_BLACKLIST.has(contractAddress.toLowerCase())) {
Expand Down Expand Up @@ -124,7 +134,7 @@ export const getWalletAddressesForContract = (contractAddress: string): string[]

/**
* Defines the contract addresses that belong to the protocol & DAO treasuries.
*
*
* This is normally deducted from total supply to determine circulating supply.
*/
export const CIRCULATING_SUPPLY_WALLETS = [
Expand Down Expand Up @@ -176,6 +186,7 @@ CONTRACT_NAME_MAP.set(LP_UNISWAP_V2_JONES_GOHM_GOHM, "UniswapV2 jgOHM-gOHM Liqui
CONTRACT_NAME_MAP.set(LP_UNISWAP_V2_JONES_WETH, "UniswapV2 JONES-wETH Liquidity Pool");
CONTRACT_NAME_MAP.set(LP_UNISWAP_V2_LQTY_WETH, "Ramses LQTY-wETH Liquidity Pool");
CONTRACT_NAME_MAP.set(LP_UNISWAP_V2_MAGIC_WETH, "UniswapV2 MAGIC-wETH Liquidity Pool");
CONTRACT_NAME_MAP.set(LP_CAMELOT_OHM_WETH, "Camelot OHM-wETH Liquidity Pool");
CONTRACT_NAME_MAP.set(LP_UNISWAP_V3_ARB_WETH, "UniswapV3 ARB-wETH Liquidity Pool");
CONTRACT_NAME_MAP.set(LP_UNISWAP_V3_WETH_USDC, "UniswapV3 wETH-USDC Liquidity Pool");
CONTRACT_NAME_MAP.set(LUSD_ALLOCATOR, "LUSD Allocator");
Expand Down
5 changes: 3 additions & 2 deletions subgraphs/arbitrum/src/contracts/Contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BigDecimal, BigInt, log } from "@graphprotocol/graph-ts";
import { ERC20 } from "../../../shared/generated/Price/ERC20";
import { TokenRecord } from "../../../shared/generated/schema";
import { getERC20TokenRecordFromWallet } from "../../../shared/src/contracts/ERC20";
import { DAO_WALLET, WALLET_ADDRESSES } from "../../../shared/src/Wallets";
import { DAO_WALLET } from "../../../shared/src/Wallets";
import {
BLOCKCHAIN,
CONTRACT_ABBREVIATION_MAP,
Expand All @@ -12,6 +12,7 @@ import {
ERC20_TOKENS_ARBITRUM,
ERC20_WETH,
JONES_WRITE_OFF_BLOCK,
getProtocolAddresses,
} from "./Constants";
import { getTokenRecordValue } from "../../../shared/src/utils/TokenRecordHelper";

Expand Down Expand Up @@ -56,7 +57,7 @@ export const getWalletAddressesForContract = (contractAddress: string): string[]
const nonTreasuryAddresses = NON_TREASURY_ASSET_WHITELIST.has(contractAddress.toLowerCase())
? NON_TREASURY_ASSET_WHITELIST.get(contractAddress.toLowerCase())
: [];
const newAddresses = WALLET_ADDRESSES.slice(0);
const newAddresses = getProtocolAddresses().slice(0);

// Add the values of nonTreasuryAddresses, but filter duplicates
for (let i = 0; i < nonTreasuryAddresses.length; i++) {
Expand Down
7 changes: 4 additions & 3 deletions subgraphs/arbitrum/src/contracts/JonesStaking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import {
getIsTokenLiquid,
getTokenRecordValue,
} from "../../../shared/src/utils/TokenRecordHelper";
import { WALLET_ADDRESSES } from "../../../shared/src/Wallets";
import { JONESStaking } from "../../generated/TokenRecords-arbitrum/JONESStaking";
import { getPrice } from "../price/PriceLookup";
import {
BLOCKCHAIN,
ERC20_TOKENS_ARBITRUM,
getProtocolAddresses,
JONES_STAKING,
JONES_STAKING_POOL_IDS,
JONES_WRITE_OFF_BLOCK,
Expand Down Expand Up @@ -83,8 +83,9 @@ export const getStakedBalances = (
const records: TokenRecord[] = [];
let price: BigDecimal | null = null;

for (let i = 0; i < WALLET_ADDRESSES.length; i++) {
const walletAddress = WALLET_ADDRESSES[i];
const allWallets = getProtocolAddresses();
for (let i = 0; i < allWallets.length; i++) {
const walletAddress = allWallets[i];
for (let j = 0; j < JONES_STAKING_POOL_IDS.length; j++) {
const balance = getStakedBalance(
tokenAddress,
Expand Down
8 changes: 4 additions & 4 deletions subgraphs/arbitrum/src/contracts/TreasureMining.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import { TokenRecord } from "../../../shared/generated/schema";
import { toDecimal } from "../../../shared/src/utils/Decimals";
import { addressesEqual } from "../../../shared/src/utils/StringHelper";
import { createTokenRecord } from "../../../shared/src/utils/TokenRecordHelper";
import { WALLET_ADDRESSES } from "../../../shared/src/Wallets";
import { TreasureMining } from "../../generated/TokenRecords-arbitrum/TreasureMining";
import { getPrice } from "../price/PriceLookup";
import { BLOCKCHAIN, ERC20_MAGIC, ERC20_TOKENS_ARBITRUM, TREASURE_ATLAS_MINE } from "./Constants";
import { BLOCKCHAIN, ERC20_MAGIC, ERC20_TOKENS_ARBITRUM, getProtocolAddresses, TREASURE_ATLAS_MINE } from "./Constants";
import { getContractName } from "./Contracts";

/**
Expand Down Expand Up @@ -89,8 +88,9 @@ export const getStakedBalances = (

const contract = getStakingContract(block);

for (let i = 0; i < WALLET_ADDRESSES.length; i++) {
const walletAddress = WALLET_ADDRESSES[i];
const allWallets = getProtocolAddresses();
for (let i = 0; i < allWallets.length; i++) {
const walletAddress = allWallets[i];
const depositIds = getUserDepositIds(walletAddress, contract, block);

for (let j = 0; j < depositIds.length; j++) {
Expand Down
2 changes: 2 additions & 0 deletions subgraphs/arbitrum/src/price/PriceLookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
LP_BALANCER_POOL_OHM_USDC,
LP_BALANCER_POOL_WETH_OHM,
LP_BALANCER_POOL_WETH_VESTA,
LP_CAMELOT_OHM_WETH,
LP_UNISWAP_V2_GOHM_WETH,
LP_UNISWAP_V2_JONES_WETH,
LP_UNISWAP_V2_LQTY_WETH,
Expand All @@ -43,6 +44,7 @@ export const PRICE_HANDLERS: PriceHandler[] = [
new PriceHandlerUniswapV2([ERC20_MAGIC, ERC20_WETH], LP_UNISWAP_V2_MAGIC_WETH, getContractName),
new PriceHandlerUniswapV3([ERC20_USDC, ERC20_WETH], LP_UNISWAP_V3_WETH_USDC, getContractName),
new PriceHandlerUniswapV3([ERC20_ARB, ERC20_WETH], LP_UNISWAP_V3_ARB_WETH, getContractName),
new PriceHandlerUniswapV2([ERC20_OHM, ERC20_WETH], LP_CAMELOT_OHM_WETH, getContractName),
];

/**
Expand Down
8 changes: 4 additions & 4 deletions subgraphs/arbitrum/src/treasury/OwnedLiquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import {
createTokenRecord,
getIsTokenLiquid,
} from "../../../shared/src/utils/TokenRecordHelper";
import { WALLET_ADDRESSES } from "../../../shared/src/Wallets";
import { BLOCKCHAIN, ERC20_TOKENS_ARBITRUM, OHM_TOKENS } from "../contracts/Constants";
import { BLOCKCHAIN, ERC20_TOKENS_ARBITRUM, getProtocolAddresses, OHM_TOKENS } from "../contracts/Constants";
import { getContractName } from "../contracts/Contracts";
import { getPriceRecursive, PRICE_HANDLERS } from "../price/PriceLookup";

Expand Down Expand Up @@ -51,8 +50,9 @@ function getOwnedLiquidityBalance(
return records;
}

for (let i = 0; i < WALLET_ADDRESSES.length; i++) {
const currentWalletAddress = WALLET_ADDRESSES[i];
const allWallets = getProtocolAddresses();
for (let i = 0; i < allWallets.length; i++) {
const currentWalletAddress = allWallets[i];

// Get the balance
const balance = liquidityHandler.getBalance(currentWalletAddress, block);
Expand Down
10 changes: 9 additions & 1 deletion subgraphs/arbitrum/src/treasury/TokenBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TokenRecord } from "../../../shared/generated/schema";
import { getERC20 } from "../../../shared/src/contracts/ERC20";
import { pushTokenRecordArray } from "../../../shared/src/utils/ArrayHelper";
import { getTokensInCategory } from "../../../shared/src/utils/TokenRecordHelper";
import { ERC20_TOKENS_ARBITRUM } from "../contracts/Constants";
import { ERC20_LUSD, ERC20_TOKENS_ARBITRUM, LUSD_START_BLOCK } from "../contracts/Constants";
import { getContractName, getERC20TokenRecordsFromWallets } from "../contracts/Contracts";
import { getStakedBalances as getJonesStakedBalances } from "../contracts/JonesStaking";
import { getStakedBalances as getTreasureStakedBalances } from "../contracts/TreasureMining";
Expand Down Expand Up @@ -40,6 +40,14 @@ function getTokenBalance(
return records;
}

// If the token is LUSD and the block number is less that the start block of the Chainlink feed, skip it
if (contractAddress.toLowerCase() == ERC20_LUSD.toLowerCase()
&&
blockNumber.lt(BigInt.fromString(LUSD_START_BLOCK))) {
log.info("getTokenBalance: Skipping {} token record at block {}", [getContractName(ERC20_LUSD), blockNumber.toString()]);
return records;
}

const rate = getPrice(contractAddress, blockNumber);

// Standard ERC20
Expand Down
22 changes: 7 additions & 15 deletions subgraphs/arbitrum/subgraph.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
specVersion: 0.0.4
specVersion: 0.0.8
description: Olympus Protocol Metrics Subgraph - Arbitrum
repository: https://github.com/OlympusDAO/olympus-protocol-metrics-subgraph
# Given the block speed of Arbitrum, it is abominably slow to index from scratch.
# Avoid changing the schema, as it will require indexing from scratch.
features:
- grafting
graft:
base: QmXVMuS639JzTTq9ZVkRnGFTftiYJ8c6FPrB52qCshSnFa # 1.5.3
block: 130482707 # JonesDAO write-off
# features:
# - grafting
# graft:
# base: QmRf3fo7tVsXsj9cQZSgT3Y2R67Hv41T1Ph559oQAmTLe1 # 1.6.4
# block: 190428287 # POL deployment
schema:
file: ../../schema.graphql
dataSources:
- kind: ethereum/contract
name: TokenRecords-arbitrum
network: arbitrum-one
source:
address: "0x79daa21a44d1415306ec17c361e0090bdd4cfcbe" # COMP-USD feed, once per hour(-ish)
address: "0x5D041081725468Aa43e72ff0445Fde2Ad1aDE775" # FRAX-USD feed, once every 16 hours
abi: ChainlinkAggregator
startBlock: 10950000 # 2022-05-01
mapping:
Expand Down Expand Up @@ -50,14 +50,6 @@ dataSources:
file: abis/TreasureMining.json
- name: ChainlinkAggregator
file: abis/ChainlinkAggregator.json
# This can be re-enabled, but likely needs a reindexing from scratch
# blockHandlers:
# - handler: handleBlock
# filter:
# kind: polling
# # Every 4 hours
# # 4 blocks per second * 60 seconds * 60 minutes * 4 hours
# every: 57600
eventHandlers:
- event: NewRound(indexed uint256,indexed address,uint256)
handler: handleEvent
Expand Down
5 changes: 5 additions & 0 deletions subgraphs/base/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Base Subgraph Changelog

## 0.0.1 (2024-06-04)

- Adds POL in Uniswap V2
6 changes: 6 additions & 0 deletions subgraphs/base/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "QmdqJ1zoExrs8u2T93wXSRWSx5VSKqKWTV4gCE2vszGwgt",
"org": "olympusdao",
"name": "protocol-metrics-base",
"version": "0.0.2"
}
Loading
Loading