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

WIP: Subgraph Migration #373

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
node-version: [14.x]
node-version: [18.16.0]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ yarn-error.log*

# subgraph
packages/subgraph/build/
packages/subgraph/generated/
packages/subgraph/data/
packages/subgraph/src/types/
packages/subgraph/subgraph.yaml
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@
"packages": [
"packages/*"
]
},
"resolutions": {
"prettier": "2.3.1"
}
}
3 changes: 3 additions & 0 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"pretty": "npx prettier --check 'src/**/*.{ts,tsx,js,jsx}'",
"format": "npx prettier --write 'src/**/*.{ts,tsx,js,jsx}'"
},
"engines": {
"node": "^18"
},
"dependencies": {
"@apollo/client": "^3.4.3",
"@ethersproject/units": "5.6.0",
Expand Down
4 changes: 3 additions & 1 deletion packages/landing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"pretty": "npx prettier --check 'src/**/*.{ts,tsx,js,jsx}'",
"format": "npx prettier --write 'src/**/*.{ts,tsx,js,jsx}'"
},
"engines": {
"node": "^18"
},
"dependencies": {
"@apollo/client": "^3.4.3",
"@fortawesome/free-solid-svg-icons": "^5.15.4",
Expand All @@ -27,7 +30,6 @@
"lru-cache": "^6.0.0",
"next": "12.0.8",
"polished": "^4.1.3",
"prettier": "^2.3.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
Expand Down
1 change: 0 additions & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"grommet-icons": "^4.7.0",
"lru-cache": "^6.0.0",
"polished": "^4.1.3",
"prettier": "^2.3.1",
"react": "^17.0.2",
"react-device-detect": "^2.1.2",
"react-dom": "^17.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MultiAPILink } from "@habx/apollo-multi-endpoint-link";

const ENDPOINTS: Endpoints = {
[ChainId.Arbitrum]: "https://api.thegraph.com/subgraphs/name/tenderize/tenderize-arbitrum",
[ChainId.Mainnet]: "https://api.thegraph.com/subgraphs/name/tenderize/tenderize-ethereum",
[ChainId.Mainnet]: "https://api.studio.thegraph.com/proxy/45331/tenderize-ethereum/0.0.31",
[ChainId.Hardhat]: "http://127.0.0.1:8000/subgraphs/name/tenderize/tenderize-localhost",
};

Expand Down
4 changes: 2 additions & 2 deletions packages/subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "@tender/subgraph",
"version": "1.0.0",
"dependencies": {
"@graphprotocol/graph-cli": "^0.20.1",
"@graphprotocol/graph-ts": "^0.20.1",
"@graphprotocol/graph-cli": "^0.46.1",
"@graphprotocol/graph-ts": "^0.29.3",
"@protofire/subgraph-toolkit": "^0.1.2"
},
"license": "MIT",
Expand Down
7 changes: 5 additions & 2 deletions packages/subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ type TenderSwap @entity {
weeklyVolumes: [WeeklyVolume!] @derivedFrom(field: "swap")
}

interface TradeVolume @entity {
interface TradeVolume {
id: ID!
swap: TenderSwap!
timestamp: BigInt!
volume: BigDecimal!
Expand All @@ -381,7 +382,8 @@ type WeeklyVolume implements TradeVolume @entity {
volume: BigDecimal!
}

interface SwapEvent @entity {
interface SwapEvent {
id: ID!
swap: TenderSwap!

block: BigInt!
Expand Down Expand Up @@ -472,6 +474,7 @@ type RemoveLiquidityEvent implements SwapEvent @entity {
}

interface Exchange {
id: ID!
swap: TenderSwap!

buyer: Bytes!
Expand Down
6 changes: 3 additions & 3 deletions packages/subgraph/src/mappings/tenderFarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function handleFarmEvent(farmEvent: Farm): void {
let tenderFarmAddress = farmEvent.address.toHex()
let protocolId = getProtocolIdByTenderFarmAddress(tenderFarmAddress)
let amount = farmEvent.params.amount
let usdPrice = getUSDPrice(Config.load(protocolId).steak)
let usdPrice = getUSDPrice(Config.load(protocolId)!.steak)

// Update User data
let userData = loadOrCreateUserDeployment(farmEvent.params.account.toHex(), protocolId)
Expand Down Expand Up @@ -52,7 +52,7 @@ export function handleUnfarmEvent(unfarmEvent: Unfarm): void {
let tenderFarmAddress = unfarmEvent.address.toHex()
let protocolId = getProtocolIdByTenderFarmAddress(tenderFarmAddress)
let amount = unfarmEvent.params.amount
let usdPrice = getUSDPrice(Config.load(protocolId).steak)
let usdPrice = getUSDPrice(Config.load(protocolId)!.steak)

// Update User data
let userData = loadOrCreateUserDeployment(unfarmEvent.params.account.toHex(), protocolId)
Expand Down Expand Up @@ -85,7 +85,7 @@ export function handleHarvestEvent(harvestEvent: Harvest): void {
let tenderFarmAddress = harvestEvent.address.toHex()
let protocolId = getProtocolIdByTenderFarmAddress(tenderFarmAddress)
let amount = harvestEvent.params.amount
let usdPrice = getUSDPrice(Config.load(protocolId).steak)
let usdPrice = getUSDPrice(Config.load(protocolId)!.steak)

// Update User data
let userData = loadOrCreateUserDeployment(harvestEvent.params.account.toHex(), protocolId)
Expand Down
16 changes: 8 additions & 8 deletions packages/subgraph/src/mappings/tenderizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export function handleDepositEvent(depositEvent: Deposit): void {
let tenderizerAddress = depositEvent.address.toHex()
let protocolId = getProtocolIdByTenderizerAddress(tenderizerAddress)
let amount = depositEvent.params.amount
let usdPrice = getUSDPrice(Config.load(protocolId).steak)
let config = Config.load(protocolId)
let config = Config.load(protocolId)!
let usdPrice = getUSDPrice(config.steak)
let tenderToken = TenderToken.bind(Address.fromString(config.tenderToken))
let timestamp = depositEvent.block.timestamp.toI32()
let userAddress = depositEvent.params.from.toHex()
Expand Down Expand Up @@ -79,7 +79,7 @@ export function handleUnstakeEvent(unstakeEvent: Unstake): void {
let tenderizerAddress = unstakeEvent.address.toHex()
let protocolId = getProtocolIdByTenderizerAddress(tenderizerAddress)
let amount = unstakeEvent.params.amount
let config = Config.load(protocolId)
let config = Config.load(protocolId)!
let tenderToken = TenderToken.bind(Address.fromString(config.tenderToken))
let timestamp = unstakeEvent.block.timestamp.toI32()

Expand Down Expand Up @@ -142,8 +142,8 @@ export function handleWithdrawEvent(withdrawEvent: Withdraw): void {
let tenderizerAddress = withdrawEvent.address.toHex()
let protocolId = getProtocolIdByTenderizerAddress(tenderizerAddress)
let amount = withdrawEvent.params.amount
let usdPrice = getUSDPrice(Config.load(protocolId).steak)
let config = Config.load(protocolId)
let usdPrice = getUSDPrice(Config.load(protocolId)!.steak)
let config = Config.load(protocolId)!
let tenderToken = TenderToken.bind(Address.fromString(config.tenderToken))

// Update day data
Expand Down Expand Up @@ -173,7 +173,7 @@ export function handleRewardsClaimedEvent(rewardsClaimedEvent: RewardsClaimed):
let tenderizerAddress = rewardsClaimedEvent.address.toHex()
let protocolId = getProtocolIdByTenderizerAddress(tenderizerAddress)
let amount = rewardsClaimedEvent.params.stakeDiff
let usdPrice = getUSDPrice(Config.load(protocolId).steak)
let usdPrice = getUSDPrice(Config.load(protocolId)!.steak)

// Update day data
let day = loadOrCreateTernderizerDay(rewardsClaimedEvent.block.timestamp.toI32(), protocolId)
Expand Down Expand Up @@ -202,7 +202,7 @@ export function handleRewardsClaimedEvent(rewardsClaimedEvent: RewardsClaimed):
export function handleProtocolFeeCollectedEvent(protocolFeeCollectedEvent: ProtocolFeeCollected): void {
let tenderizerAddress = protocolFeeCollectedEvent.address.toHex()
let protocolId = getProtocolIdByTenderizerAddress(tenderizerAddress)
let usdPrice = getUSDPrice(Config.load(protocolId).steak)
let usdPrice = getUSDPrice(Config.load(protocolId)!.steak)

// Update Tenderizer totals
let tenderizer = loadOrCreateTenderizer(protocolId)
Expand All @@ -221,7 +221,7 @@ export function handleProtocolFeeCollectedEvent(protocolFeeCollectedEvent: Proto
export function handleLiquidityFeeCollectedEvent(liquidityFeeCollectedEvent: LiquidityFeeCollected): void {
let tenderizerAddress = liquidityFeeCollectedEvent.address.toHex()
let protocolId = getProtocolIdByTenderizerAddress(tenderizerAddress)
let usdPrice = getUSDPrice(Config.load(protocolId).steak)
let usdPrice = getUSDPrice(Config.load(protocolId)!.steak)

// Update Tenderizer totals
let tenderizer = loadOrCreateTenderizer(protocolId)
Expand Down
36 changes: 17 additions & 19 deletions packages/subgraph/src/mappings/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function loadOrCreateUserDeployment(address: string, protocolName: string

export function getProtocolIdByTenderizerAddress(address: string): string {
// TODO: Is there a better way to do this?
let globals = TenderizeGlobal.load('1')
let globals = TenderizeGlobal.load('1')!
let globalConfigs = globals.configs
for (let i = 0; i < globalConfigs.length; i++) {
let c = Config.load(globalConfigs[i]) as Config
Expand All @@ -147,7 +147,7 @@ export function getProtocolIdByTenderizerAddress(address: string): string {

export function getProtocolIdByTenderFarmAddress(address: string): string {
// TODO: Is there a better way to do this?
let globals = TenderizeGlobal.load('1')
let globals = TenderizeGlobal.load('1')!
let globalConfigs = globals.configs
for (let i = 0; i < globalConfigs.length; i++) {
let c = Config.load(globalConfigs[i]) as Config
Expand All @@ -160,7 +160,7 @@ export function getProtocolIdByTenderFarmAddress(address: string): string {

export function getProtocolIdByTenderTokenAddress(address: string): string {
// TODO: Is there a better way to do this?
let globals = TenderizeGlobal.load('1')
let globals = TenderizeGlobal.load('1')!
let globalConfigs = globals.configs
for (let i = 0; i < globalConfigs.length; i++) {
let c = Config.load(globalConfigs[i]) as Config
Expand All @@ -173,7 +173,7 @@ export function getProtocolIdByTenderTokenAddress(address: string): string {

export function getProtocolIdByTenderSwapAddress(address: string): string {
// TODO: Is there a better way to do this?
let globals = TenderizeGlobal.load('1')
let globals = TenderizeGlobal.load('1')!
let globalConfigs = globals.configs
for (let i = 0; i < globalConfigs.length; i++) {
let c = Config.load(globalConfigs[i]) as Config
Expand Down Expand Up @@ -239,12 +239,12 @@ export function loadOrCreateUserDeploymentDay(timestamp: i32, address: string, p
// Initialize data with previous day data
// Not needed for just a single value
let dayList = user.dayData
if(dayList.length == 0) {
day.shares = ZERO_BI
} else {
if(dayList) {
let previousDayID = dayList.pop()
let previousDay = UserDeploymentDay.load(previousDayID)
let previousDay = UserDeploymentDay.load(previousDayID)!
day.shares = previousDay.shares
} else {
day.shares = ZERO_BI
}
day.save()
}
Expand All @@ -257,10 +257,8 @@ export function getUSDPrice(steakToken: string): BigDecimal {
return ZERO_BD
}

let usdc: string
if(network == 'mainnet'){
usdc = config.USDC_ADDRESS
} else if(network == 'arbitrum-one'){
let usdc = config.USDC_ADDRESS
if(network == 'arbitrum-one'){
usdc = config.USDC_ADDRESS_ARBITURM
}

Expand Down Expand Up @@ -290,7 +288,7 @@ export function getUSDPrice(steakToken: string): BigDecimal {
}

export function LPTokenToToken(amount: BigDecimal, protocol: string): BigDecimal {
let config = Config.load(protocol)
let config = Config.load(protocol)!
let tenderSwap = TenderSwapContact.bind(Address.fromString(config.tenderSwap))
let lpToken = LiquidityPoolToken.bind(tenderSwap.lpToken())
let totalSupply = lpToken.totalSupply().toBigDecimal()
Expand All @@ -300,20 +298,20 @@ export function LPTokenToToken(amount: BigDecimal, protocol: string): BigDecimal
}

export function tokensToShares(amount: BigInt, protocol: string): BigInt {
let config = Config.load(protocol)
let config = Config.load(protocol)!
let tenderToken = TenderToken.bind(Address.fromString(config.tenderToken))
return tenderToken.tokensToShares(amount)
}

export function addressIsContract(config: Config, address: Address): Boolean {
export function addressIsContract(config: Config, address: Address): boolean {
let addressString = address.toHex()
return (
addressString.includes(config.tenderToken) ||
addressString.includes(config.lpToken) ||
addressString.includes(config.tenderSwap) ||
addressString.includes(config.tenderFarm) ||
addressString.includes(config.tenderizer)
) as Boolean
)
}

// Tenderswap helpers
Expand Down Expand Up @@ -496,7 +494,7 @@ export function getHourlyTradeVolume(
volume.volume = decimal.ZERO
}

return volume!
return volume
}

export function getDailyTradeVolume(
Expand All @@ -516,7 +514,7 @@ export function getDailyTradeVolume(
volume.volume = decimal.ZERO
}

return volume!
return volume
}

export function getWeeklyTradeVolume(
Expand All @@ -536,5 +534,5 @@ export function getWeeklyTradeVolume(
volume.volume = decimal.ZERO
}

return volume!
return volume
}
10 changes: 5 additions & 5 deletions packages/subgraph/subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dataSources:
abi: Registry
mapping:
kind: ethereum/events
apiVersion: 0.0.3
apiVersion: 0.0.5
abis:
- name: Registry
file: ../contracts/src/abis/Registry.json
Expand All @@ -40,7 +40,7 @@ templates:
abi: Tenderizer
mapping:
kind: ethereum/events
apiVersion: 0.0.1
apiVersion: 0.0.5
language: wasm/assemblyscript
file: ./src/mappings/tenderizer.ts
entities:
Expand Down Expand Up @@ -78,7 +78,7 @@ templates:
abi: TenderFarm
mapping:
kind: ethereum/events
apiVersion: 0.0.1
apiVersion: 0.0.5
language: wasm/assemblyscript
file: ./src/mappings/tenderFarm.ts
entities:
Expand Down Expand Up @@ -112,7 +112,7 @@ templates:
abi: TenderToken
mapping:
kind: ethereum/events
apiVersion: 0.0.1
apiVersion: 0.0.5
language: wasm/assemblyscript
file: ./src/mappings/tenderToken.ts
entities:
Expand All @@ -132,7 +132,7 @@ templates:
abi: TenderSwap
mapping:
kind: ethereum/events
apiVersion: 0.0.1
apiVersion: 0.0.5
language: wasm/assemblyscript
file: ./src/mappings/tenderSwap.ts
entities:
Expand Down
Loading