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

update network to arbitrum-one #218

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 2 additions & 2 deletions src/mappings/pool/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
MINIMUM_ETH_LOCKED,
STABLE_COINS,
STABLECOIN_IS_TOKEN0,
USDC_WETH_05_POOL,
USDC_WETH_03_POOL,
WETH_ADDRESS,
} from '../../utils/pricing'

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

export function handleInitializeHelper(
event: Initialize,
stablecoinWrappedNativePoolAddress: string = USDC_WETH_05_POOL,
stablecoinWrappedNativePoolAddress: string = USDC_WETH_03_POOL,
stablecoinIsToken0: boolean = STABLECOIN_IS_TOKEN0,
wrappedNativeAddress: string = WETH_ADDRESS,
stablecoinAddresses: string[] = STABLE_COINS,
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 = '0x33128a8fC17869897dcE68Ed026d694621f6FDfD'
export const FACTORY_ADDRESS = '0x1F98431c8aD98523631AE4a59f267346ea31F984'

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

export const WETH_ADDRESS = '0x4200000000000000000000000000000000000006'
export const USDC_WETH_05_POOL = '0x4c36388be6f416a29c8d8eee81c771ce6be14b18'
export const WETH_ADDRESS = '0x82af49447d8a07e3bd95bd0d56f35241523fbab1'
export const USDC_WETH_03_POOL = '0x17c14d2c404d167802b16c450d3c99f88f2c4f4d'
export const STABLECOIN_IS_TOKEN0 = false

const USDC_ADDRESS = '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913'
const USDC_ADDRESS = '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8'
const DAI_ADDRESS = '0xda10009cbd5d07dd0cecc66161fc93d7c9000da1'
const USDT_ADDRESS = '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9'

// token where amounts should contribute to tracked volume and liquidity
// usually tokens that many tokens are paired with s
export const WHITELIST_TOKENS: string[] = [WETH_ADDRESS, USDC_ADDRESS]
export const WHITELIST_TOKENS: string[] = [WETH_ADDRESS, USDC_ADDRESS, DAI_ADDRESS, USDT_ADDRESS]

export const STABLE_COINS: string[] = [USDC_ADDRESS]
export const STABLE_COINS: string[] = [USDC_ADDRESS, DAI_ADDRESS, USDT_ADDRESS]

export const MINIMUM_ETH_LOCKED = BigDecimal.fromString('1')
export const MINIMUM_ETH_LOCKED = BigDecimal.fromString('20')

const Q192 = BigInt.fromI32(2).pow(192 as u8)
export function sqrtPriceX96ToTokenPrices(sqrtPriceX96: BigInt, token0: Token, token1: Token): BigDecimal[] {
const num = sqrtPriceX96.times(sqrtPriceX96).toBigDecimal()
const denom = BigDecimal.fromString(Q192.toString())
const price1 = num.div(denom).times(exponentToBigDecimal(token0.decimals)).div(exponentToBigDecimal(token1.decimals))
const price1 = num
.div(denom)
.times(exponentToBigDecimal(token0.decimals))
.div(exponentToBigDecimal(token1.decimals))

const price0 = safeDiv(BigDecimal.fromString('1'), price1)
return [price0, price1]
}

export function getEthPriceInUSD(
stablecoinWrappedNativePoolAddress: string = USDC_WETH_05_POOL,
stablecoinWrappedNativePoolAddress: string = USDC_WETH_03_POOL,
stablecoinIsToken0: boolean = STABLECOIN_IS_TOKEN0, // true is stablecoin is token0, false if stablecoin is token1
): BigDecimal {
const stablecoinWrappedNativePool = Pool.load(stablecoinWrappedNativePoolAddress)
Expand Down
15 changes: 14 additions & 1 deletion src/utils/staticTokenDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,17 @@ export const getStaticDefinition = (
return null
}

export const STATIC_TOKEN_DEFINITIONS: Array<StaticTokenDefinition> = []
export const STATIC_TOKEN_DEFINITIONS: Array<StaticTokenDefinition> = [
{
address: Address.fromString('0x82af49447d8a07e3bd95bd0d56f35241523fbab1'),
symbol: 'WETH',
name: 'Wrapped Ethereum',
decimals: BigInt.fromI32(18)
},
{
address: Address.fromString('0xff970a61a04b1ca14834a43f5de4533ebddb5cc8'),
symbol: 'USDC',
name: 'USD Coin',
decimals: BigInt.fromI32(6)
}
]
36 changes: 18 additions & 18 deletions src/utils/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export function fetchTokenSymbol(
const contract = ERC20.bind(tokenAddress)
const contractSymbolBytes = ERC20SymbolBytes.bind(tokenAddress)

// try with the static definition
const staticTokenDefinition = getStaticDefinition(tokenAddress, staticTokenDefinitions)
if (staticTokenDefinition != null) {
return staticTokenDefinition.symbol
}

// try types string and bytes32 for symbol
let symbolValue = 'unknown'
const symbolResult = contract.try_symbol()
Expand All @@ -22,12 +28,6 @@ export function fetchTokenSymbol(
// for broken pairs that have no symbol function exposed
if (!isNullEthValue(symbolResultBytes.value.toHexString())) {
symbolValue = symbolResultBytes.value.toString()
} else {
// try with the static definition
const staticTokenDefinition = getStaticDefinition(tokenAddress, staticTokenDefinitions)
if (staticTokenDefinition != null) {
symbolValue = staticTokenDefinition.symbol
}
}
}
} else {
Expand All @@ -44,6 +44,12 @@ export function fetchTokenName(
const contract = ERC20.bind(tokenAddress)
const contractNameBytes = ERC20NameBytes.bind(tokenAddress)

// try with the static definition
const staticTokenDefinition = getStaticDefinition(tokenAddress, staticTokenDefinitions)
if (staticTokenDefinition != null) {
return staticTokenDefinition.name
}

// try types string and bytes32 for name
let nameValue = 'unknown'
const nameResult = contract.try_name()
Expand All @@ -53,12 +59,6 @@ export function fetchTokenName(
// for broken exchanges that have no name function exposed
if (!isNullEthValue(nameResultBytes.value.toHexString())) {
nameValue = nameResultBytes.value.toString()
} else {
// try with the static definition
const staticTokenDefinition = getStaticDefinition(tokenAddress, staticTokenDefinitions)
if (staticTokenDefinition != null) {
nameValue = staticTokenDefinition.name
}
}
}
} else {
Expand All @@ -82,6 +82,12 @@ export function fetchTokenDecimals(
tokenAddress: Address,
staticTokenDefinitions: StaticTokenDefinition[] = STATIC_TOKEN_DEFINITIONS,
): BigInt | null {
// try with the static definition
const staticTokenDefinition = getStaticDefinition(tokenAddress, staticTokenDefinitions)
if (staticTokenDefinition) {
return staticTokenDefinition.decimals
}

const contract = ERC20.bind(tokenAddress)
// try types uint8 for decimals
const decimalResult = contract.try_decimals()
Expand All @@ -90,12 +96,6 @@ export function fetchTokenDecimals(
if (decimalResult.value.lt(BigInt.fromI32(255))) {
return decimalResult.value
}
} else {
// try with the static definition
const staticTokenDefinition = getStaticDefinition(tokenAddress, staticTokenDefinitions)
if (staticTokenDefinition) {
return staticTokenDefinition.decimals
}
}

return null
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: base
network: arbitrum-one
source:
address: '0x33128a8fC17869897dcE68Ed026d694621f6FDfD'
address: '0x1F98431c8aD98523631AE4a59f267346ea31F984'
abi: Factory
startBlock: 2009445
startBlock: 165
mapping:
kind: ethereum/events
apiVersion: 0.0.7
Expand All @@ -39,7 +39,7 @@ dataSources:
templates:
- kind: ethereum/contract
name: Pool
network: base
network: arbitrum-one
source:
abi: Pool
mapping:
Expand Down