Skip to content
This repository was archived by the owner on Nov 26, 2022. It is now read-only.
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
19 changes: 19 additions & 0 deletions deploy-all-chains.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

chains=("arbitrum" "aurora" "avalanche" "bsc" "bttc" "ethereum" "cronos" "fantom" "oasis" "polygon" "velas")

for i in "${chains[@]}"
do
# prepare
mustache configs/$i.json subgraph.template.yaml > subgraph.yaml && mustache configs/$i
# codegen
graph codegen --output-dir src/types/
# build
graph build
# create subgraph
# graph create ${SUBGRAPH_NAME}-$i --node ${NODE}
echo ${SUBGRAPH_NAME}-$i
echo ${NODE}
done


20 changes: 14 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@
"build": "graph build",
"deploy": "graph deploy kybernetwork/kyberswap-exchange-${NETWORK} --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --debug",
"create-subgraph": "graph create kybernetwork/kyberswap-exchange-${NETWORK} --node https://${NETWORK}-graph.kyberengineering.io/admin",
"remove-subgraph": "graph remove kybernetwork/kyberswap-exchange-${NETWORK} --node https://${NETWORK}-graph.kyberengineering.io/admin",
"deploy-subgraph": "graph deploy kybernetwork/kyberswap-exchange-${NETWORK} --debug --ipfs https://${NETWORK}-graph.kyberengineering.io/ipfs --node https://${NETWORK}-graph.kyberengineering.io/admin",
"create-local": "graph create dynamic-amm/dynamic-amm --node http://127.0.0.1:8020",
"deploy-local": "graph deploy dynamic-amm/dynamic-amm --debug --ipfs http://localhost:5001 --node http://127.0.0.1:8020",
"watch-local": "graph deploy dynamic-amm/dynamic-amm --watch --debug --node http://127.0.0.1:8020/ --ipfs http://localhost:5001",
"create-dev": "graph create kybernetwork/kyberswap-exchange-${NETWORK} --node https://${NETWORK}-graph.dev.kyberengineering.io/admin",
"remove-dev": "graph remove kybernetwork/kyberswap-exchange-${NETWORK} --node https://${NETWORK}-graph.dev.kyberengineering.io/admin",
"deploy-dev": "graph deploy kybernetwork/kyberswap-exchange-${NETWORK} --debug --ipfs https://${NETWORK}-graph.dev.kyberengineering.io/ipfs --node https://${NETWORK}-graph.dev.kyberengineering.io/admin",
"create-halink": "graph create kybernetwork/kyberswap-exchange-${NETWORK} --node https://${NETWORK}-graph.dev.kyberengineering.io/admin",
"remove-halink": "graph remove kybernetwork/kyberswap-exchange-${NETWORK} --node https://${NETWORK}-graph.dev.kyberengineering.io/admin",
"deploy-halink": "graph deploy --product hosted-service halink0803/kyberswap-exchange-${NETWORK}",
"create-local": "graph create dynamic-amm/dynamic-amm-${NETWORK} --node http://127.0.0.1:8020",
"deploy-local": "graph deploy dynamic-amm/dynamic-amm-${NETWORK} --debug --ipfs http://localhost:5002 --node http://127.0.0.1:8020",
"remove-local": "graph remove dynamic-amm/dynamic-amm-${NETWORK} --node http://127.0.0.1:8020",
"watch-local": "graph deploy dynamic-amm/dynamic-amm-${NETWORK} --watch --debug --node http://127.0.0.1:8020/ --ipfs http://localhost:5001",
"prettier": "./node_modules/.bin/prettier --write src/mappings/*",
"deploy-ropsten": "graph deploy viet-nv/kyberswap-classic-ropsten --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --debug"
},
Expand All @@ -21,10 +29,10 @@
"@graphprotocol/graph-ts": "0.20.1",
"@typescript-eslint/eslint-plugin": "^2.0.0",
"@typescript-eslint/parser": "^2.0.0",
"eslint": "^6.2.2",
"eslint": "^8.25.0",
"eslint-config-prettier": "^6.1.0",
"mustache": "^4.2.0",
"prettier": "^1.18.2",
"typescript": "^3.5.2"
"prettier": "^2.7.1",
"typescript": "^4.8.4"
}
}
16 changes: 8 additions & 8 deletions src/config/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ export const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000'

export const ADDRESS_LOCK = '0xffffffffffffffffffffffffffffffffffffffff'

export const DMM_DYNAMIC_FEE_FACTORY_ADDRESS = '0x833e4083b7ae46cea85695c4f7ed25cdad8886de'
export const DMM_DYNAMIC_FEE_FACTORY_ADDRESS = '0x878dfe971d44e9122048308301f540910bbd934c'
export const DMM_STATIC_FEE_FACTORY_ADDRESS = '0x1c758af0688502e49140230f6b0ebd376d429be5'
export const DMM_STATIC_FEE_FACTORY_LEGACY_ADDRESS = ''

export const ETH_PRICING_POOLS = '0xd478953d5572f829f457a5052580cbeaee36c1aa|0x20d6b227f4a5a2a13d520329f01bb1f8f9d2d628|0xf8467ef9de03e83b5a778ac858ea5c2d1fc47188|0xce9874c42dce7fffbe5e48b026ff1182733266cb'
export const ETH_PRICING_POOLS = '0xec303ce1edbebf7e71fc7b350341bb6a6a7a6381'

// minimum liquidity required to count towards tracked volume for pairs with small # of Lps
export let MINIMUM_USD_THRESHOLD_NEW_PAIRS = BigDecimal.fromString('4000')

// minimum liquidity for price to get tracked
export let MINIMUM_LIQUIDITY_THRESHOLD_ETH = BigDecimal.fromString('2') // default is 2
export let MINIMUM_LIQUIDITY_THRESHOLD_ETH = BigDecimal.fromString('13') // default is 2

export const WRAPPED_NATIVE_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
export const WRAPPED_NATIVE_ADDRESS = '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c'

export const KNC_ADDRESS = '0xdefa4e8a7bcba345f687a2f1456f5edd9ce97202'
export const KNC_ADDRESS = '0xfe56d5892bdffc7bf58f2e84be1b2c32d21c308b'
export const KNC_NAME = 'Kyber Network'
export const KNC_SYMBOL = 'KNC'

export const KNCL_ADDRESS = '0xdd974d5c2e2928dea5f71b9825b8b646686bd200'
export const KNCL_ADDRESS = '0x7b2810576aa1cce68f2b118cef1f36467c648f92'
export const KNCL_NAME = 'Kyber Network Legacy'
export const KNCL_SYMBOL = 'KNCL'

export let FACTORY_BPS = BigDecimal.fromString('10000')

export let NETWORK = 'mainnet'
export let NETWORK = 'bsc'

export let WHITELISTED_TOKENS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0x6b175474e89094c44da98b954eedeac495271d0f,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0xdac17f958d2ee523a2206206994597c13d831ec7,0xdefa4e8a7bcba345f687a2f1456f5edd9ce97202'
export let WHITELISTED_TOKENS = '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,0xe9e7cea3dedca5984780bafc599bd69add087d56,0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d,0x55d398326f99059ff775485246999027b3197955,0xfe56d5892bdffc7bf58f2e84be1b2c32d21c308b,0x2170ed0880ac9a755fd29b2688956bd959f933f8'
38 changes: 30 additions & 8 deletions src/mappings/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,32 @@ function isCompleteMint(mintId: string): boolean {
return MintEvent.load(mintId).sender !== null // sufficient checks
}

function getFactoryWithRetry(poolContract: PoolABI): Address {
let retryAttempt = 5;
let factoryAddress = Address.fromString(ADDRESS_ZERO)
for (let i = 0; i < retryAttempt; i++) {
log.debug("___ debug halink getFactoryWithRetry: {} - {}", ["attempt", i.toString()])
let callResult = poolContract.try_factory()
if (!callResult.reverted) {
factoryAddress = callResult.value;
break;
}
}
return factoryAddress;
}

export function handleTransfer(event: Transfer): void {
// ignore initial transfers for first adds
log.debug("____ debug halink handle transfer: ", [event.address.toHexString()])
if (event.params.to.toHexString() == ADDRESS_LOCK && event.params.value.equals(BigInt.fromI32(1000))) {
return
}

let poolContract = PoolABI.bind(event.address)
let factoryAddress = poolContract.factory()
let factoryAddress = getFactoryWithRetry(poolContract)

let factory = DmmFactory.load(factoryAddress.toHexString())
log.debug("debug halink loaded factory: ", [factory.id])

// user stats
let from = event.params.from
Expand Down Expand Up @@ -236,17 +252,22 @@ export function handleTransfer(event: Transfer): void {
}

export function handleMint(event: Mint): void {
log.debug('___ handle mint ___', [])
log.debug('!__________ run to handle mint {}', [event.transaction.hash.toHexString()])
log.debug('___ debug halink handle mint ___', [])
log.debug('!__________debug run to handle mint {}', [event.transaction.hash.toHexString()])
let transaction = createOrLoadTransaction(event.transaction.hash, event.block)
log.debug('!_____ debug halink createOrLoadTransaction {}', [transaction.id])
let mints = transaction.mints
if (mints.length == 0) {
log.debug('is that ok that there is no mints?', [])
}
log.debug('!_____ debug halink mints', [])
let mint = MintEvent.load(mints[mints.length - 1])

// const pair = Pair.load(event.address.toHex())
log.debug('!!_______ pool address _____ {} ', [event.address.toHex()])
let pool = Pool.load(event.address.toHex())
let poolContract = PoolABI.bind(event.address)
let factoryAddress = poolContract.factory()
let factoryAddress = getFactoryWithRetry(poolContract)

let factory = DmmFactory.load(factoryAddress.toHexString())

Expand Down Expand Up @@ -319,7 +340,7 @@ export function handleBurn(event: Burn): void {
// const pair = Pair.load(event.address.toHex())
let pool = Pool.load(event.address.toHex())
let poolContract = PoolABI.bind(event.address)
let factoryAddress = poolContract.factory()
let factoryAddress = getFactoryWithRetry(poolContract)
let factory = DmmFactory.load(factoryAddress.toHexString())

//update token info
Expand Down Expand Up @@ -458,7 +479,7 @@ export function handleSwap(event: Swap): void {

// update global values, only used tracked amounts for volume
let poolContract = PoolABI.bind(event.address)
let factoryAddress = poolContract.factory()
let factoryAddress = getFactoryWithRetry(poolContract)

let factory = DmmFactory.load(factoryAddress.toHexString())
factory.totalVolumeUSD = factory.totalVolumeUSD.plus(trackedAmountUSD)
Expand Down Expand Up @@ -578,14 +599,15 @@ export function handleSwap(event: Swap): void {
}

export function handleSync(event: Sync): void {
log.debug('___ handle sync ___', [])
log.debug('___ debug halink handle sync ___', [])
// const pair = Pair.load(event.address.toHex())
let pool = Pool.load(event.address.toHex())
log.debug('debug halink', [pool.id.toString()])
let token0 = Token.load(pool.token0)
let token1 = Token.load(pool.token1)
let pair = Pair.load(token0.id + '_' + token1.id)
let poolContract = PoolABI.bind(event.address)
let factoryAddress = poolContract.factory()
let factoryAddress = getFactoryWithRetry(poolContract)

let factory = DmmFactory.load(factoryAddress.toHexString())

Expand Down
67 changes: 58 additions & 9 deletions subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ schema:
dataSources:
- kind: ethereum/contract
name: DmmDynamicFeeFactory
network: mainnet
network: bsc
source:
address: '0x833e4083b7ae46cea85695c4f7ed25cdad8886de'
address: '0x878dfe971d44e9122048308301f540910bbd934c'
abi: DmmDynamicFeeFactory
startBlock: 12178218 # contract creation block
startBlock: 10475000 # contract creation block
mapping:
kind: ethereum/events
apiVersion: 0.0.4
Expand All @@ -37,11 +37,11 @@ dataSources:

- kind: ethereum/contract
name: DmmStaticFeeFactory
network: mainnet
network: bsc
source:
address: '0x1c758af0688502e49140230f6b0ebd376d429be5'
abi: DmmStaticFeeFactory
startBlock: 14971899 # contract creation block
startBlock: 18728872 # contract creation block
mapping:
kind: ethereum/events
apiVersion: 0.0.4
Expand Down Expand Up @@ -69,11 +69,11 @@ dataSources:

- kind: ethereum/contract
name: KyberRewardLocker
network: mainnet
network: bsc
source:
address: '0xfab5186a194588f5ad5074bd52659302906b4522'
abi: KyberRewardLocker
startBlock: 12720768 # contract creation block
startBlock: 10533792 # contract creation block
mapping:
kind: ethereum/events
apiVersion: 0.0.4
Expand All @@ -91,11 +91,35 @@ dataSources:
handler: handleRewardContractAdded
- event: Vested(indexed address,indexed address,uint256,uint256)
handler: handleVestd
- kind: ethereum/contract
name: KyberRewardLockerV2
network: bsc
source:
address: '0xd93f7a2cbf4912158d6ccda585c9d234a0d70652'
abi: KyberRewardLockerV2
startBlock: 15094253 # contract creation block
mapping:
kind: ethereum/events
apiVersion: 0.0.4
language: wasm/assemblyscript
file: ./src/mappings/rewardLockerV2.ts
entities: # defines which entities are written to stores
- RewardLocker
abis:
- name: KyberRewardLockerV2
file: ./abis/KyberRewardLockerV2.json
- name: KyberFairLaunchV2
file: ./abis/KyberFairLaunchV2.json
eventHandlers:
- event: RewardContractAdded(indexed address,indexed address,bool)
handler: handleRewardContractAdded
- event: Vested(indexed address,indexed address,uint256,uint256)
handler: handleVestd

templates:
- kind: ethereum/contract
name: Pool
network: mainnet
network: bsc
source:
abi: Pool
mapping:
Expand Down Expand Up @@ -127,7 +151,7 @@ templates:

- kind: ethereum/contract
name: KyberFairLaunch
network: mainnet
network: bsc
source:
abi: KyberFairLaunch
mapping:
Expand All @@ -150,3 +174,28 @@ templates:
handler: handleWithdraw
- event: AddNewPool(indexed address,indexed uint32,indexed uint32,uint256[])
handler: handleAddNewPool
- kind: ethereum/contract
name: KyberFairLaunchV2
network: bsc
source:
abi: KyberFairLaunchV2
mapping:
kind: ethereum/events
apiVersion: 0.0.4
language: wasm/assemblyscript
file: ./src/mappings/fairLaunchV2.ts
entities:
- Pool
- Token
abis:
- name: KyberFairLaunchV2
file: ./abis/KyberFairLaunchV2.json
eventHandlers:
- event: Deposit(indexed address,indexed uint256,indexed uint256,uint256)
handler: handleDeposit
- event: Harvest(indexed address,indexed uint256,indexed address,uint256,uint256)
handler: handleHarvest
- event: Withdraw(indexed address,indexed uint256,indexed uint256,uint256)
handler: handleWithdraw
- event: AddNewPool(indexed address,indexed address,uint32,uint32,uint32)
handler: handleAddNewPool
Loading