Skip to content

Commit

Permalink
update network to celo
Browse files Browse the repository at this point in the history
  • Loading branch information
mzywang committed May 30, 2024
1 parent bfde16b commit aaa3b82
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 39 deletions.
4 changes: 2 additions & 2 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Factory @entity {
# stores for USD calculations
type Bundle @entity {
id: ID!
# todo: update this to nativePriceUSD because avax is native asset
# todo: update this to nativePriceUSD because celo is native asset
# price of ETH in usd
ethPriceUSD: BigDecimal!
}
Expand Down Expand Up @@ -66,7 +66,7 @@ type Token @entity {
# TVL derived in USD untracked
totalValueLockedUSDUntracked: BigDecimal!
# derived price in ETH
# todo: update this to derivedNative because avax is native asset
# todo: update this to derivedNative because celo is native asset
derivedETH: BigDecimal!
# pools token is in that are white listed for USD pricing
whitelistPools: [Pool!]!
Expand Down
8 changes: 4 additions & 4 deletions src/mappings/pool/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { Bundle, Pool, Token } from '../../types/schema'
import { Initialize } from '../../types/templates/Pool/Pool'
import { updatePoolDayData, updatePoolHourData } from '../../utils/intervalUpdates'
import {
CELO_NATIVE_ADDRESS,
CUSD_CELO_POOL_ADDRESS,
findEthPerToken,
getEthPriceInUSD,
MINIMUM_ETH_LOCKED,
STABLE_COINS,
STABLECOIN_IS_TOKEN0,
WAVAX_ADDRESS,
WAVAX_USDC_05_POOL,
} from '../../utils/pricing'

export function handleInitialize(event: Initialize): void {
Expand All @@ -19,9 +19,9 @@ export function handleInitialize(event: Initialize): void {

export function handleInitializeHelper(
event: Initialize,
stablecoinWrappedNativePoolAddress: string = WAVAX_USDC_05_POOL,
stablecoinWrappedNativePoolAddress: string = CUSD_CELO_POOL_ADDRESS,
stablecoinIsToken0: boolean = STABLECOIN_IS_TOKEN0,
wrappedNativeAddress: string = WAVAX_ADDRESS,
wrappedNativeAddress: string = CELO_NATIVE_ADDRESS,
stablecoinAddresses: string[] = STABLE_COINS,
minimumEthLocked: BigDecimal = MINIMUM_ETH_LOCKED,
): void {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Address, BigDecimal, BigInt } from '@graphprotocol/graph-ts'
import { Factory as FactoryContract } from '../types/templates/Pool/Factory'

export const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000'
export const FACTORY_ADDRESS = '0x740b1c1de25031C31FF4fC9A62f554A55cdC1baD'
export const FACTORY_ADDRESS = '0xAfE208a311B21f13EF87E33A90049fC17A7acDEc'

export const ZERO_BI = BigInt.fromI32(0)
export const ONE_BI = BigInt.fromI32(1)
Expand Down
48 changes: 20 additions & 28 deletions src/utils/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,32 @@ import { exponentToBigDecimal, safeDiv } from '../utils/index'
import { Bundle, Pool, Token } from './../types/schema'
import { ONE_BD, ZERO_BD, ZERO_BI } from './constants'

export const WAVAX_ADDRESS = '0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7'
export const WAVAX_USDC_05_POOL = '0xfae3f424a0a47706811521e3ee268f00cfb5c45e'
export const CELO_NATIVE_ADDRESS = '0x471ece3750da237f93b8e339c536989b8978a438'
export const CUSD_CELO_POOL_ADDRESS = '0x2d70cbabf4d8e61d5317b62cbe912935fd94e0fe'
export const STABLECOIN_IS_TOKEN0 = false

const DAI_E_ADDRESS = '0xd586e7f844cea2f87f50152665bcbc2c279d8d70'
const DAI_ADDRESS = '0xba7deebbfc5fa1100fb055a87773e1e99cd3507a'
const USDC_E_ADDRESS = '0xa7d7079b0fead91f3e65f86e8915cb59c1a4c664'
const USDC_ADDRESS = '0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e'
const USDT_E_ADDRESS = '0xc7198437980c041c805a1edcba50c1ce5db95118'
const USDT_ADDRESS = '0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7'
const CUSD_ADDRESS = '0x765de816845861e75a25fca122bb6898b8b1282a'
const BRIDGED_USDC_ADDRESS = '0xef4229c8c3250c675f21bcefa42f58efbff6002a'
const NATIVE_USDC_ADDRESS = '0xceba9300f2b948710d2653dd7b07f33a8b32118c'

// token where amounts should contribute to tracked volume and liquidity
// usually tokens that many tokens are paired with s
// usually tokens that many tokens are paired with
export const WHITELIST_TOKENS: string[] = [
WAVAX_ADDRESS,
DAI_E_ADDRESS,
DAI_ADDRESS,
USDC_E_ADDRESS,
USDC_ADDRESS,
USDT_E_ADDRESS,
USDT_ADDRESS,
'0x130966628846bfd36ff31a822705796e8cb8c18d', // mim
CELO_NATIVE_ADDRESS,
CUSD_ADDRESS,
BRIDGED_USDC_ADDRESS,
NATIVE_USDC_ADDRESS,
'0xd8763cba276a3738e6de85b4b3bf5fded6d6ca73', // CEUR
'0xe8537a3d056da446677b9e9d6c5db704eaab4787', // CREAL
'0x46c9757c5497c5b1f2eb73ae79b6b67d119b0b58', // PACT
'0x17700282592d6917f6a73d0bf8accf4d578c131e', // MOO
'0x66803fb87abd4aac3cbb3fad7c3aa01f6f3fb207', // Portal Eth
'0xbaab46e28388d2779e6e31fd00cf0e5ad95e327b', // WBTC
]

export const STABLE_COINS: string[] = [
DAI_E_ADDRESS,
DAI_ADDRESS,
USDC_E_ADDRESS,
USDC_ADDRESS,
USDT_E_ADDRESS,
USDT_ADDRESS,
]
export const STABLE_COINS: string[] = [CUSD_ADDRESS, BRIDGED_USDC_ADDRESS, NATIVE_USDC_ADDRESS]

export const MINIMUM_ETH_LOCKED = BigDecimal.fromString('1000')
export const MINIMUM_ETH_LOCKED = BigDecimal.fromString('3600')

const Q192 = BigInt.fromI32(2).pow(192 as u8)
export function sqrtPriceX96ToTokenPrices(sqrtPriceX96: BigInt, token0: Token, token1: Token): BigDecimal[] {
Expand All @@ -53,7 +45,7 @@ export function sqrtPriceX96ToTokenPrices(sqrtPriceX96: BigInt, token0: Token, t
}

export function getEthPriceInUSD(
stablecoinWrappedNativePoolAddress: string = WAVAX_USDC_05_POOL,
stablecoinWrappedNativePoolAddress: string = CUSD_CELO_POOL_ADDRESS,
stablecoinIsToken0: boolean = STABLECOIN_IS_TOKEN0, // true is stablecoin is token0, false if stablecoin is token1
): BigDecimal {
const stablecoinWrappedNativePool = Pool.load(stablecoinWrappedNativePoolAddress)
Expand All @@ -70,7 +62,7 @@ export function getEthPriceInUSD(
**/
export function findEthPerToken(
token: Token,
wrappedNativeAddress: string = WAVAX_ADDRESS,
wrappedNativeAddress: string = CELO_NATIVE_ADDRESS,
stablecoinAddresses: string[] = STABLE_COINS,
minimumEthLocked: BigDecimal = MINIMUM_ETH_LOCKED,
): BigDecimal {
Expand Down
8 changes: 4 additions & 4 deletions subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ features:
dataSources:
- kind: ethereum/contract
name: Factory
network: avalanche
network: celo
source:
address: '0x740b1c1de25031C31FF4fC9A62f554A55cdC1baD'
address: '0xAfE208a311B21f13EF87E33A90049fC17A7acDEc'
abi: Factory
startBlock: 27832971
startBlock: 13916355
mapping:
kind: ethereum/events
apiVersion: 0.0.7
Expand All @@ -39,7 +39,7 @@ dataSources:
templates:
- kind: ethereum/contract
name: Pool
network: avalanche
network: celo
source:
abi: Pool
mapping:
Expand Down

0 comments on commit aaa3b82

Please sign in to comment.