Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

Prepare exchange subgraph for Aurora network #104

Open
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ typings/
# next.js build output
.next

.idea
.vscode
.DS_Store

Expand Down
26 changes: 26 additions & 0 deletions config/aurora.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"key": "aurora",
"network": "aurora",
"factory_address": "0xc66f594268041db60507f00703b152492fb176e7",
"usdc_weth_pair": "0x20f8aefb5697b77e0bb835a8518be70775cda1b0",
"usdt_weth_pair": "0x03b666f3488a7992b2385b12df7f35156d7b29cd",
"sushi_address": "0xfa94348467f64d5a457f75f8bc40495d33c65abb",
"weth_address": "0xc9bdeed33cd01541e1eed10f90519d2c06fe3feb",
"native_address": "0xc42c30ac6cc15fac9bd938618bcaa1a1fae8501d",
"usdc_address": "0xb12bfca5a55806aaf64e99521918a4bf0fc40802",
"usdt_address": "0x4988a896b1227218e4a686fde5eabdcabd91571f",
"whitelist": [
"0xc42c30ac6cc15fac9bd938618bcaa1a1fae8501d",
"0xfa94348467f64d5a457f75f8bc40495d33c65abb",
"0xc9bdeed33cd01541e1eed10f90519d2c06fe3feb",
"0xb12bfca5a55806aaf64e99521918a4bf0fc40802",
"0xe3520349f477a5f6eb06107066048508498a291b",
"0x4988a896b1227218e4a686fde5eabdcabd91571f"
],
"factory": {
"address": "0xc66f594268041db60507f00703b152492fb176e7",
"startBlock": "51600000"
},
"minimum_usd_threshold_new_pairs": "1000",
"minimum_liquidity_threshold_eth": "1"
}
4 changes: 4 additions & 0 deletions packages/constants/index.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export const BIG_DECIMAL_1E12 = BigDecimal.fromString('1e12')

export const BIG_DECIMAL_1E18 = BigDecimal.fromString('1e18')

export const BIG_DECIMAL_1E24 = BigDecimal.fromString('1e24')

export const BIG_DECIMAL_ZERO = BigDecimal.fromString('0')

export const BIG_DECIMAL_ONE = BigDecimal.fromString('1')
Expand Down Expand Up @@ -54,6 +56,8 @@ export const PAIR_BORROW = 'borrow'

export const PAIR_REPAY = 'repay'

export const NETWORK = '{{ network }}{{^network}}mainnet{{/network}}'

export const FACTORY_ADDRESS = Address.fromString(
'{{ factory_address }}{{^factory_address}}0x0000000000000000000000000000000000000000{{/factory_address}}'
)
Expand Down
1 change: 1 addition & 0 deletions packages/constants/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"prepare:harmony": "mustache ../../config/harmony.json index.template.ts > index.ts",
"prepare:celo": "mustache ../../config/celo.json index.template.ts > index.ts",
"prepare:avalanche": "mustache ../../config/avalanche.json index.template.ts > index.ts",
"prepare:aurora": "mustache ../../config/aurora.json index.template.ts > index.ts",
"prepare:arbitrum": "mustache ../../config/arbitrum.json index.template.ts > index.ts",
"prepare:palm": "mustache ../../config/palm.json index.template.ts > index.ts",
"prepare:heco": "mustache ../../config/heco.json index.template.ts > index.ts",
Expand Down
4 changes: 3 additions & 1 deletion subgraphs/exchange/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "exchange",
"license": "MIT",
"version": "1.2.0",
"version": "1.2.1",
"author": "SushiSwap",
"files": [
"generated"
Expand All @@ -21,6 +21,7 @@
"deploy:arbitrum": "graph deploy --product hosted-service matthewlilley/arbitrum-exchange",
"deploy:fuse": "graph deploy --product hosted-service sushiswap/fuse-exchange",
"deploy:avalanche": "graph deploy --product hosted-service sushiswap/avalanche-exchange",
"deploy:aurora": "graph deploy --product hosted-service sushiswap/aurora-exchange",
"deploy:matic": "graph deploy --product hosted-service sushiswap/matic-exchange",
"deploy:celo": "graph deploy --product hosted-service sushiswap/celo-exchange",
"deploy:moonriver": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ sushiswap/moonriver-exchange subgraph.yaml",
Expand All @@ -41,6 +42,7 @@
"prepare:celo": "mustache ../../config/celo.json template.yaml > subgraph.yaml",
"prepare:moonriver": "mustache ../../config/moonriver.json template.yaml > subgraph.yaml",
"prepare:avalanche": "mustache ../../config/avalanche.json template.yaml > subgraph.yaml",
"prepare:aurora": "mustache ../../config/aurora.json template.yaml > subgraph.yaml",
"prepare:palm": "mustache ../../config/palm.json template.yaml > subgraph.yaml",
"prepare:heco": "mustache ../../config/heco.json template.yaml > subgraph.yaml",
"prepare:fuse": "mustache ../../config/fuse.json template.yaml > subgraph.yaml",
Expand Down
31 changes: 30 additions & 1 deletion subgraphs/exchange/src/mappings/factory.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
import { getFactory, getPair } from '../enitites'

import { BIG_INT_ONE } from 'const'
import { BIG_INT_ONE, USDC_WETH_PAIR, USDT_WETH_PAIR, NETWORK } from 'const'
import { Address, log } from '@graphprotocol/graph-ts'
import { PairCreated } from '../../generated/Factory/Factory'
import { Pair as PairTemplate } from '../../generated/templates'
import { Pair } from '../../generated/schema'

export function onPairCreated(event: PairCreated): void {
const factory = getFactory()
/**
* Note. The following condition is only for the Aurora network for main pairs.
* Because the current subgraph is created and subscribes to listen for the events
* of the pairs that were created in the selected factory with the special event of the created pair.
* In the Aurora network at the Trisolaris factory, thegraph cannot find this event,
* it can no longer be subscribed to, we have created a condition for creating and
* subscribing to the USDC and USDT pair if it has not been created before."
*/
if (NETWORK === 'aurora') {
let usdcPair = Pair.load(USDC_WETH_PAIR)
let usdtPair = Pair.load(USDT_WETH_PAIR)

if (usdcPair === null) {
usdcPair = getPair(Address.fromString(USDC_WETH_PAIR), event.block)
log.warning("USDC save", [])
usdcPair.save()
PairTemplate.create(Address.fromString(USDC_WETH_PAIR))
factory.pairCount = factory.pairCount.plus(BIG_INT_ONE)
}
if (usdtPair === null) {
usdtPair = getPair(Address.fromString(USDT_WETH_PAIR), event.block)
log.warning("USDT save", [])
usdtPair.save()
PairTemplate.create(Address.fromString(USDT_WETH_PAIR))
factory.pairCount = factory.pairCount.plus(BIG_INT_ONE)
}
}

const pair = getPair(event.params.pair, event.block, event.params.token0, event.params.token1)

Expand Down
6 changes: 6 additions & 0 deletions subgraphs/exchange/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ templates:
file: ../../node_modules/@sushiswap/core/build/abi/UniswapV2Pair.json
- name: Factory
file: ../../node_modules/@sushiswap/core/build/abi/UniswapV2Factory.json
- name: ERC20
file: ../../node_modules/@sushiswap/core/build/abi/ERC20.json
- name: ERC20SymbolBytes
file: ../../packages/abis/ERC20SymbolBytes.json
- name: ERC20NameBytes
file: ../../packages/abis/ERC20NameBytes.json
eventHandlers:
- event: Mint(indexed address,uint256,uint256)
handler: onMint
Expand Down