From f18accf1b181adf1facff2aaebd442d99f8d97cf Mon Sep 17 00:00:00 2001 From: ChefJoJo <94336009+chef-jojo@users.noreply.github.com> Date: Wed, 18 Oct 2023 16:23:40 +0800 Subject: [PATCH] feat: Add scroll (#242) --- README.md | 2 + config/arbitrum-goerli.js | 1 + config/arbitrum.js | 1 + config/base-testnet.js | 1 + config/base.js | 1 + config/config.d.ts | 1 + config/opbnb.js | 1 + config/polygon-zkevm-testnet.js | 1 + config/polygon-zkevm.js | 1 + config/scroll.js | 41 +++++++++++++++++++ config/zksync-era.js | 1 + config/zksync-goerli.js | 1 + .../exchange-v2/mappings/pricing.template.ts | 2 +- subgraphs/exchange-v2/mappings/pricing.ts | 10 ++--- subgraphs/exchange-v2/subgraph.yaml | 6 +-- subgraphs/exchange-v3/template/subgraph.yaml | 10 ++--- .../exchange-v3/template/utils/pricing.ts | 12 +++--- 17 files changed, 73 insertions(+), 20 deletions(-) create mode 100644 config/scroll.js diff --git a/README.md b/README.md index faa2cefa..9b647cad 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Currently, there are multiple subgraphs, but additional subgraphs can be added t - Linea https://graph-query.linea.build/subgraphs/name/pancakeswap/exhange-v2 - Base https://api.studio.thegraph.com/query/45376/exchange-v2-base/version/latest - Base testnet https://api.studio.thegraph.com/query/45376/exchange-v2-base-testnet/version/latest + - Scroll https://api.studio.thegraph.com/query/45376/exchange-v2-scroll/version/latest - Scroll Sepolia https://api.studio.thegraph.com/query/45376/exchange-v2-scroll-sepolia/version/latest - opBNB https://opbnb-mainnet-graph.nodereal.io/subgraphs/name/pancakeswap/exchange-v2 @@ -84,6 +85,7 @@ Currently, there are multiple subgraphs, but additional subgraphs can be added t - Linea https://graph-query.linea.build/subgraphs/name/pancakeswap/exchange-v3-linea - Base https://api.studio.thegraph.com/query/45376/exchange-v3-base/version/latest - Base testnet https://api.studio.thegraph.com/query/45376/exchange-v3-base-testnet/version/latest + - Scroll https://api.studio.thegraph.com/query/45376/exchange-v3-scroll/version/latest - Scroll Sepolia https://api.studio.thegraph.com/query/45376/exchange-v3-scroll-sepolia/version/latest - opBNB https://opbnb-mainnet-graph.nodereal.io/subgraphs/name/pancakeswap/exchange-v3 diff --git a/config/arbitrum-goerli.js b/config/arbitrum-goerli.js index 956285e5..1a1fb376 100644 --- a/config/arbitrum-goerli.js +++ b/config/arbitrum-goerli.js @@ -34,5 +34,6 @@ module.exports = { "0x179522635726710dd7d2035a81d856de4aa7836c", // USDC "0xbe737d08fb505ad45e08a89ac7fda9791f025bf2", // ARB ], + minETHLocked: 5, }, }; diff --git a/config/arbitrum.js b/config/arbitrum.js index 4b8dbd40..25afab6d 100644 --- a/config/arbitrum.js +++ b/config/arbitrum.js @@ -45,6 +45,7 @@ module.exports = { "0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f", // WBTC "0xda10009cbd5d07dd0cecc66161fc93d7c9000da1", // DAI ], + minETHLocked: 5, }, masterChefV3: { masterChefAddress: "0x5e09acf80c0296740ec5d6f643005a4ef8daa694", diff --git a/config/base-testnet.js b/config/base-testnet.js index 268b0291..70b3bf9b 100644 --- a/config/base-testnet.js +++ b/config/base-testnet.js @@ -32,5 +32,6 @@ module.exports = { WETH, "0x853154e2A5604E5C74a2546E2871Ad44932eB92C", // USDC ], + minETHLocked: 5, }, }; diff --git a/config/base.js b/config/base.js index 866603a1..983c3be3 100644 --- a/config/base.js +++ b/config/base.js @@ -45,6 +45,7 @@ module.exports = { "0x417ac0e078398c154edfadd9ef675d30be60af93", // crvUSD "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913", // USDC native ], + minETHLocked: 5, }, masterChefV3: { masterChefAddress: "0xc6a2db661d5a5690172d8eb0a7dea2d3008665a3", diff --git a/config/config.d.ts b/config/config.d.ts index 5ae272b1..975cd0cd 100644 --- a/config/config.d.ts +++ b/config/config.d.ts @@ -19,6 +19,7 @@ export type NetworkConfig = { whitelistAddresses: string[]; wNativeStablePair0: string; wNativeStablePair1: string; + minETHLocked: number; }; masterChefV3: { startBlock: number; diff --git a/config/opbnb.js b/config/opbnb.js index b6596987..0e8bf35b 100644 --- a/config/opbnb.js +++ b/config/opbnb.js @@ -25,5 +25,6 @@ module.exports = { wNativeStablePair0: "0x0000000000000000000000000000000000000000", // WETH-USDC wNativeStablePair1: "0x706f7257e78b6f2404a1afb5c480645a6f5be91d", // WETH-USDT whitelistAddresses: [WETH, USDT], + minETHLocked: 0, }, }; diff --git a/config/polygon-zkevm-testnet.js b/config/polygon-zkevm-testnet.js index 04a553cd..6e916053 100644 --- a/config/polygon-zkevm-testnet.js +++ b/config/polygon-zkevm-testnet.js @@ -32,6 +32,7 @@ module.exports = { WETH, "0x7379a261bC347BDD445484A91648Abf4A2BDEe5E", // USDT ], + minETHLocked: 0, }, masterChefV3: { masterChefAddress: "0xb66b07590b30d4e6e22e45ddc83b06bb018a7b44", diff --git a/config/polygon-zkevm.js b/config/polygon-zkevm.js index 9bd362f8..9d25f791 100644 --- a/config/polygon-zkevm.js +++ b/config/polygon-zkevm.js @@ -43,6 +43,7 @@ module.exports = { "0xc5015b9d9161dca7e18e32f6f25c4ad850731fd4", // DAI "0xea034fb02eb1808c2cc3adbc15f447b93cbe08e1", // WBTC ], + minETHLocked: 0, }, masterChefV3: { masterChefAddress: "0xe9c7f3196ab8c09f6616365e8873daeb207c0391", diff --git a/config/scroll.js b/config/scroll.js new file mode 100644 index 00000000..7b91ad77 --- /dev/null +++ b/config/scroll.js @@ -0,0 +1,41 @@ +const WETH = "0x5300000000000000000000000000000000000004"; +const USDC = "0x06efdbff2a14a7c8e15944d1f4a48f9f95f663a4"; +const USDT = "0xf55bec9cafdbe8730f096aa55dad6d22d44099df"; +const LUSD = "0xedeabc3a1e7d21fe835ffa6f83a710c70bb1a051"; +const WBTC = "0x3c1bca5a656e69edcd0d4e36bebb3fcdaca60cf1"; +const RETH = "0x53878b874283351d26d206fa512aece1bef6c0dd"; +const STETH = "0xf610a9dfb7c89644979b4a0f27063e9e7d7cda32"; +const DAI = "0xca77eb3fefe3725dc33bccb54edefc3d9f764f97"; + +/** + * @type import('./config').NetworkConfig + */ +module.exports = { + network: "scroll", + wNativeAddress: WETH, + v3: { + // WETH-USDC 500 + wNativeStablePoolAddress: "0xb4ea03fd982685c68279cfe6dd05dd26521c35dd", + stableIsToken0: true, + factoryAddress: "0x0bfbcf9fa4f9c56b0f40a671ad40e0805a091865", + startBlock: 6581, + stableCoins: [ + USDC, // USDC + USDT, + LUSD, + DAI, + ], + whitelistAddresses: [WETH, USDT, USDT, LUSD, WBTC, RETH, STETH, DAI], + nonfungiblePositionManagerAddress: "0x46a15b0b27311cedf172ab29e4f4766fbe7f4364", + nonfungiblePositionManagerStartBlock: 6977, + minETHLocked: 0, + }, + v2: { + factoryAddress: "0x02a84c1b3bbd7401a5f7fa98a384ebc70bb5749e", + startBlock: 3804, + wNativeStablePair0: "0xe948be21a0e98f050dd48d8ab954e7b6e26eefa3", // WETH-USDC + wNativeStablePair1: "0x42290c85a8ee259904416aa2d4802eda7308339e", // USDT-WETH + whitelistAddresses: [WETH, USDT, USDT, LUSD, WBTC, RETH, STETH, DAI], + minETHLocked: 1, + }, +}; diff --git a/config/zksync-era.js b/config/zksync-era.js index af472984..8a7d0fb4 100644 --- a/config/zksync-era.js +++ b/config/zksync-era.js @@ -40,6 +40,7 @@ module.exports = { "0x3355df6d4c9c3035724fd0e3914de96a5a83aaf4", // USDC "0xbbeb516fb02a01611cbbe0453fe3c580d7281011", // WBTC ], + minETHLocked: 1, }, masterChefV3: { masterChefAddress: "0x4c615e78c5fca1ad31e4d66eb0d8688d84307463", diff --git a/config/zksync-goerli.js b/config/zksync-goerli.js index f29a38a1..fa9df1c8 100644 --- a/config/zksync-goerli.js +++ b/config/zksync-goerli.js @@ -32,5 +32,6 @@ module.exports = { WETH, "0x0faf6df7054946141266420b43783387a78d82a9", // USDC ], + minETHLocked: 0, }, }; diff --git a/subgraphs/exchange-v2/mappings/pricing.template.ts b/subgraphs/exchange-v2/mappings/pricing.template.ts index 180592c4..d3b39591 100644 --- a/subgraphs/exchange-v2/mappings/pricing.template.ts +++ b/subgraphs/exchange-v2/mappings/pricing.template.ts @@ -38,7 +38,7 @@ export function getETHPriceInUSD(): BigDecimal { let WHITELIST: string[] = "{{ v2.whitelistAddresses }}".split(","); // minimum liquidity for price to get tracked -let MINIMUM_LIQUIDITY_THRESHOLD_ETH = BigDecimal.fromString("5"); +let MINIMUM_LIQUIDITY_THRESHOLD_ETH = BigDecimal.fromString("{{ v2.minETHLocked }}"); /** * Search through graph to find derived BNB per token. diff --git a/subgraphs/exchange-v2/mappings/pricing.ts b/subgraphs/exchange-v2/mappings/pricing.ts index 8d9599b8..f7cc9dda 100644 --- a/subgraphs/exchange-v2/mappings/pricing.ts +++ b/subgraphs/exchange-v2/mappings/pricing.ts @@ -4,11 +4,11 @@ import { Bundle, Pair, Token } from "../generated/schema"; import { ADDRESS_ZERO, factoryContract, ONE_BD, ZERO_BD } from "./utils"; // prettier-ignore -let WETH_ADDRESS = "0x4200000000000000000000000000000000000006"; +let WETH_ADDRESS = "0x5300000000000000000000000000000000000004"; // prettier-ignore -let WETH_USDT_PAIR = "0x706f7257e78b6f2404a1afb5c480645a6f5be91d"; +let WETH_USDT_PAIR = "0x42290c85a8ee259904416aa2d4802eda7308339e"; // prettier-ignore -let WETH_USDC_PAIR = "0x0000000000000000000000000000000000000000"; +let WETH_USDC_PAIR = "0xe948be21a0e98f050dd48d8ab954e7b6e26eefa3"; export function getETHPriceInUSD(): BigDecimal { // fetch eth prices for each stablecoin @@ -35,10 +35,10 @@ export function getETHPriceInUSD(): BigDecimal { // token where amounts should contribute to tracked volume and liquidity // prettier-ignore -let WHITELIST: string[] = "0x4200000000000000000000000000000000000006,0x9e5aac1ba1a2e6aed6b32689dfcf62a509ca96f3".split(","); +let WHITELIST: string[] = "0x5300000000000000000000000000000000000004,0xf55bec9cafdbe8730f096aa55dad6d22d44099df,0xf55bec9cafdbe8730f096aa55dad6d22d44099df,0xedeabc3a1e7d21fe835ffa6f83a710c70bb1a051,0x3c1bca5a656e69edcd0d4e36bebb3fcdaca60cf1,0x53878b874283351d26d206fa512aece1bef6c0dd,0xf610a9dfb7c89644979b4a0f27063e9e7d7cda32,0xca77eb3fefe3725dc33bccb54edefc3d9f764f97".split(","); // minimum liquidity for price to get tracked -let MINIMUM_LIQUIDITY_THRESHOLD_ETH = BigDecimal.fromString("5"); +let MINIMUM_LIQUIDITY_THRESHOLD_ETH = BigDecimal.fromString("1"); /** * Search through graph to find derived BNB per token. diff --git a/subgraphs/exchange-v2/subgraph.yaml b/subgraphs/exchange-v2/subgraph.yaml index c0701e29..3134b5ce 100644 --- a/subgraphs/exchange-v2/subgraph.yaml +++ b/subgraphs/exchange-v2/subgraph.yaml @@ -6,11 +6,11 @@ schema: dataSources: - kind: ethereum/contract name: Factory - network: opbnb-mainnet + network: scroll source: address: "0x02a84c1b3bbd7401a5f7fa98a384ebc70bb5749e" abi: Factory - startBlock: 1708914 + startBlock: 3804 mapping: kind: ethereum/events apiVersion: 0.0.4 @@ -34,7 +34,7 @@ dataSources: templates: - kind: ethereum/contract name: Pair - network: opbnb-mainnet + network: scroll source: abi: Pair mapping: diff --git a/subgraphs/exchange-v3/template/subgraph.yaml b/subgraphs/exchange-v3/template/subgraph.yaml index 0f17d2e7..25842d18 100644 --- a/subgraphs/exchange-v3/template/subgraph.yaml +++ b/subgraphs/exchange-v3/template/subgraph.yaml @@ -8,11 +8,11 @@ features: dataSources: - kind: ethereum/contract name: Factory - network: opbnb-mainnet + network: scroll source: address: "0x0bfbcf9fa4f9c56b0f40a671ad40e0805a091865" abi: Factory - startBlock: 1721753 + startBlock: 6581 mapping: kind: ethereum/events apiVersion: 0.0.4 @@ -37,11 +37,11 @@ dataSources: handler: handlePoolCreated - kind: ethereum/contract name: NonfungiblePositionManager - network: opbnb-mainnet + network: scroll source: address: "0x46a15b0b27311cedf172ab29e4f4766fbe7f4364" abi: NonfungiblePositionManager - startBlock: 1730685 + startBlock: 6977 mapping: kind: ethereum/events apiVersion: 0.0.4 @@ -71,7 +71,7 @@ dataSources: templates: - kind: ethereum/contract name: Pool - network: opbnb-mainnet + network: scroll source: abi: Pool mapping: diff --git a/subgraphs/exchange-v3/template/utils/pricing.ts b/subgraphs/exchange-v3/template/utils/pricing.ts index 802dd158..eda2d731 100644 --- a/subgraphs/exchange-v3/template/utils/pricing.ts +++ b/subgraphs/exchange-v3/template/utils/pricing.ts @@ -5,21 +5,21 @@ import { BigDecimal, BigInt } from "@graphprotocol/graph-ts"; import { exponentToBigDecimal, safeDiv } from "./index"; // prettier-ignore -const WETH_ADDRESS = "0x4200000000000000000000000000000000000006"; +const WETH_ADDRESS = "0x5300000000000000000000000000000000000004"; // prettier-ignore -const USDC_WETH_03_POOL = "0xc4f981189558682f15f60513158b699354b30204"; +const USDC_WETH_03_POOL = "0xb4ea03fd982685c68279cfe6dd05dd26521c35dd"; -const STABLE_IS_TOKEN0 = "false" as string; +const STABLE_IS_TOKEN0 = "true" as string; // token where amounts should contribute to tracked volume and liquidity // usually tokens that many tokens are paired with s // prettier-ignore -export let WHITELIST_TOKENS: string[] = "0x4200000000000000000000000000000000000006,0x9e5aac1ba1a2e6aed6b32689dfcf62a509ca96f3".split(","); +export let WHITELIST_TOKENS: string[] = "0x5300000000000000000000000000000000000004,0xf55bec9cafdbe8730f096aa55dad6d22d44099df,0xf55bec9cafdbe8730f096aa55dad6d22d44099df,0xedeabc3a1e7d21fe835ffa6f83a710c70bb1a051,0x3c1bca5a656e69edcd0d4e36bebb3fcdaca60cf1,0x53878b874283351d26d206fa512aece1bef6c0dd,0xf610a9dfb7c89644979b4a0f27063e9e7d7cda32,0xca77eb3fefe3725dc33bccb54edefc3d9f764f97".split(","); // prettier-ignore -let STABLE_COINS: string[] = "0x9e5aac1ba1a2e6aed6b32689dfcf62a509ca96f3".split(","); +let STABLE_COINS: string[] = "0x06efdbff2a14a7c8e15944d1f4a48f9f95f663a4,0xf55bec9cafdbe8730f096aa55dad6d22d44099df,0xedeabc3a1e7d21fe835ffa6f83a710c70bb1a051,0xca77eb3fefe3725dc33bccb54edefc3d9f764f97".split(","); -let MINIMUM_ETH_LOCKED = BigDecimal.fromString("1"); +let MINIMUM_ETH_LOCKED = BigDecimal.fromString("0"); let Q192 = 2 ** 192; export function sqrtPriceX96ToTokenPrices(sqrtPriceX96: BigInt, token0: Token, token1: Token): BigDecimal[] {