Fix pools (#287)

* small cleanup

* fix pools
This commit is contained in:
mihaisc 2022-01-14 06:51:23 -08:00 committed by GitHub
parent 2839649b28
commit 7f945f02f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 1422 additions and 1006 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -94,7 +94,7 @@ type Pool @entity {
id: ID!
"owner address, pool controller"
owner: String!
controller: String!
"only finalized pools are relevant to us"
isFinalized: Boolean!

View File

@ -1,5 +1,11 @@
import { Order } from '../@types/schema'
import { OrderStarted } from '../@types/templates/ERC20Template/ERC20Template'
import {
ConsumeMarketFees,
NewPaymentCollector,
OrderStarted,
PublishMarketFees
} from '../@types/templates/ERC20Template/ERC20Template'
import { integer } from './utils/constants'
import { weiToDecimal } from './utils/generic'
import { getGlobalStats } from './utils/globalUtils'
@ -58,6 +64,10 @@ export function handleOrderStarted(event: OrderStarted): void {
token.save()
}
export function handleNewPaymentCollector(event: NewPaymentCollector): void {}
export function handlePublishMarketFees(event: PublishMarketFees): void {}
export function handleConsumeMarketFees(event: ConsumeMarketFees): void {}
// export function handlePublishMarketFees(event: PublishMarketFees): void {
// const order = Order.load(
// getOrderId(

View File

@ -1,15 +1,14 @@
import { log } from '@graphprotocol/graph-ts'
import { NFTCreated, TokenCreated } from '../@types/ERC721Factory/ERC721Factory'
import { Nft, Token } from '../@types/schema'
import { ERC20Template, ERC721Template } from '../@types/templates'
import { decimal, integer } from './utils/constants'
import { weiToDecimal } from './utils/generic'
import { getGlobalStats } from './utils/globalUtils'
import { getUser } from './utils/userUtils'
export function handleNftCreated(event: NFTCreated): void {
log.warning('handleNftCreated is starting', [])
const nft = new Nft(event.params.newTokenAddress.toHexString())
ERC721Template.create(event.params.newTokenAddress)
const user = getUser(event.params.admin.toHexString())
nft.owner = user.id
nft.address = event.params.newTokenAddress.toHexString()
@ -27,11 +26,8 @@ export function handleNftCreated(event: NFTCreated): void {
}
export function handleNewToken(event: TokenCreated): void {
log.warning('handleNewToken {} {}', [
event.transaction.from.toHexString(),
event.address.toHexString()
])
const token = new Token(event.params.newTokenAddress.toHexString())
ERC20Template.create(event.params.newTokenAddress)
token.isDatatoken = true
token.address = event.params.newTokenAddress.toHexString()
token.createdTimestamp = event.block.timestamp.toI32()

View File

@ -0,0 +1,9 @@
import { NewPool } from '../@types/FactoryRouter/FactoryRouter'
import { Pool } from '../@types/schema'
import { BPool } from '../@types/templates'
export function handleNewPool(event: NewPool): void {
BPool.create(event.params.poolAddress)
const pool = new Pool(event.params.poolAddress.toHexString())
pool.save()
}

View File

@ -1,3 +1,4 @@
import { log } from '@graphprotocol/graph-ts'
import { Nft, NftUpdate } from '../@types/schema'
import {
MetadataCreated,
@ -12,6 +13,7 @@ function getId(tx: string, nftAddress: string): string {
}
export function handleCreated(event: MetadataCreated): void {
log.warning('nft handleCreated {}', [event.address.toHex()])
const nftAddress = event.address.toHex()
const nft = Nft.load(nftAddress)
if (!nft) return

View File

@ -1,3 +1,4 @@
import { log } from '@graphprotocol/graph-ts'
import { PoolTransaction } from '../@types/schema'
import {
LOG_BPT,
@ -9,6 +10,7 @@ import {
import { Transfer } from '../@types/templates/BPool/BToken'
import { integer, PoolTransactionType } from './utils/constants'
import { weiToDecimal } from './utils/generic'
import { getGlobalStats } from './utils/globalUtils'
import {
calcSpotPrice,
getPool,
@ -21,6 +23,7 @@ import { getUser } from './utils/userUtils'
// kinda redundant code in join/swap/exit
export function handleJoin(event: LOG_JOIN): void {
log.warning('handle join {}', [event.address.toHex()])
const pool = getPool(event.address.toHex())
const user = getUser(event.params.caller.toHex())
const poolTx = getPoolTransaction(event, user.id, PoolTransactionType.JOIN)
@ -35,6 +38,10 @@ export function handleJoin(event: LOG_JOIN): void {
event.params.tokenAmountIn.toBigDecimal(),
token.decimals
)
log.warning('handle join ammount {} tokenAmountIn {}', [
ammount.toString(),
event.params.tokenAmountIn.toString()
])
if (token.isDatatoken) {
poolTx.datatoken = token.id
poolTx.datatokenValue = ammount
@ -42,7 +49,7 @@ export function handleJoin(event: LOG_JOIN): void {
poolSnapshot.datatokenLiquidity =
poolSnapshot.datatokenLiquidity.plus(ammount)
pool.datatokenLiquidity.plus(ammount)
pool.datatokenLiquidity = pool.datatokenLiquidity.plus(ammount)
} else {
poolTx.baseToken = token.id
poolTx.baseTokenValue = ammount
@ -50,9 +57,14 @@ export function handleJoin(event: LOG_JOIN): void {
poolSnapshot.baseTokenLiquidity =
poolSnapshot.baseTokenLiquidity.plus(ammount)
pool.baseTokenLiquidity.plus(ammount)
pool.baseTokenLiquidity = pool.baseTokenLiquidity.plus(ammount)
}
log.warning('handle join baseTokenLiquidity {} datatokenLiquidity {}', [
pool.baseTokenLiquidity.toString(),
pool.datatokenLiquidity.toString()
])
poolSnapshot.save()
poolTx.save()
pool.save()
@ -171,8 +183,10 @@ export function handleSwap(event: LOG_SWAP): void {
// setup is just to set token weight(it will mostly be 50:50) and spotPrice
export function handleSetup(event: LOG_SETUP): void {
log.warning('new Pool ', [])
const pool = getPool(event.address.toHex())
pool.controller = event.params.caller.toHexString()
const token = getToken(event.params.baseToken.toHex())
pool.baseToken = token.id
pool.baseTokenWeight = weiToDecimal(
@ -203,6 +217,9 @@ export function handleSetup(event: LOG_SETUP): void {
poolTx.save()
}
const globalStats = getGlobalStats()
globalStats.poolCount = globalStats.poolCount + 1
globalStats.save()
pool.save()
datatoken.save()
}

View File

@ -1,26 +0,0 @@
import { Pool } from '../@types/schema'
import { BPoolCreated } from '../@types/templates/BFactory/BFactory'
import { integer } from './utils/constants'
import { getGlobalStats } from './utils/globalUtils'
import { getToken } from './utils/tokenUtils'
export function handleNewPool(event: BPoolCreated): void {
const pool = new Pool(event.params.newBPoolAddress.toHex())
const baseToken = getToken(event.params.basetokenAddress.toHex())
pool.baseToken = baseToken.id
const datatoken = getToken(event.params.datatokenAddress.toHex())
pool.datatoken = datatoken.id
pool.owner = event.params.registeredBy.toHex()
pool.createdTimestamp = event.block.timestamp.toI32()
pool.tx = event.transaction.hash.toHex()
pool.block = event.block.number.toI32()
const globalStats = getGlobalStats()
globalStats.poolCount = globalStats.poolCount + 1
globalStats.save()
pool.save()
}

View File

@ -46,7 +46,6 @@ export function getOpfCollectorAddress(): string {
return '0x967da4048cd07ab37855c090aaf366e4ce1b9f48'
}
export const OCEAN: string = getOceanAddress()
export function weiToDecimal(amount: BigDecimal, decimals: i32): BigDecimal {
@ -57,5 +56,5 @@ export function weiToDecimal(amount: BigDecimal, decimals: i32): BigDecimal {
}
export function gweiToEth(ammount: BigDecimal): BigDecimal {
return ammount.div(BigDecimal.fromString('1.000.000.000'))
return ammount.div(BigDecimal.fromString('1000000000'))
}

View File

@ -6,7 +6,7 @@ import {
PoolTransaction
} from '../../@types/schema'
import { BPool } from '../../@types/templates/BPool/BPool'
import { DAY, decimal } from './constants'
import { DAY, decimal, integer } from './constants'
import { gweiToEth, weiToDecimal } from './generic'
export function getPoolSharesId(
@ -72,7 +72,8 @@ export function calcSpotPrice(
// tokenIn is always the baseToken and tokenOut is the datatoken because we want the spot price to be in baseToken eg: 1 DT = 0.5 OCEAN
const weiPrice = poolContract.try_getSpotPrice(
Address.fromString(baseTokenAddress),
Address.fromString(datatokenAddress)
Address.fromString(datatokenAddress),
integer.ZERO
).value
const price = weiToDecimal(weiPrice.toBigDecimal(), baseTokenDecimals)

View File

@ -8,12 +8,12 @@ dataSources:
name: ERC721Factory
network: rinkeby
source:
address: '0xe4B39C90355899DB8f625D879B44Fa9C5Cdde550'
address: '0x15087E3E9eAAAb37d32d9D06Fa4000309BD7Ee6D'
abi: ERC721Factory
startBlock: 9984045
startBlock: 9989814
mapping:
kind: ethereum/events
apiVersion: 0.0.5
apiVersion: 0.0.6
language: wasm/assemblyscript
file: ./src/mappings/erc721Factory.ts
entities:
@ -30,12 +30,12 @@ dataSources:
name: FixedRateExchange
network: rinkeby
source:
address: '0x7084f7353bB7cfc92A65e7d23987Cb5D1A3Fb9b2'
address: '0xB5f34bd0B3E8e59447fD5a750F2dE4262BABE66C'
abi: FixedRateExchange
startBlock: 9984045
startBlock: 9989814
mapping:
kind: ethereum/events
apiVersion: 0.0.5
apiVersion: 0.0.6
language: wasm/assemblyscript
file: ./src/mappings/fixedRateExchange.ts
entities:
@ -64,12 +64,12 @@ dataSources:
name: Dispenser
network: rinkeby
source:
address: '0xa8fFDd525835795C940370FB816f82a5F7F5F860'
address: '0x17b1760c20eAc7A2656412412F6020e6c00b78BD'
abi: Dispenser
startBlock: 9984045
startBlock: 9989814
mapping:
kind: ethereum/events
apiVersion: 0.0.5
apiVersion: 0.0.6
language: wasm/assemblyscript
file: ./src/mappings/dispenser.ts
entities:
@ -90,6 +90,28 @@ dataSources:
handler: handleTokensDispensed
- event: OwnerWithdrawed(indexed address,indexed address,uint256)
handler: handleOwnerWinthdraw
- kind: ethereum/contract
name: FactoryRouter
network: rinkeby
source:
address: '0x31066E8eFe281C755dC21d828bdF30363D055baB'
abi: FactoryRouter
startBlock: 9989814
mapping:
kind: ethereum/events
apiVersion: 0.0.6
language: wasm/assemblyscript
file: ./src/mappings/factoryRouter.ts
entities:
- FactoryRouter
abis:
- name: FactoryRouter
file: ./abis/FactoryRouter.json
eventHandlers:
- event: NewPool(indexed address,bool)
handler: handleNewPool
templates:
- name: ERC20Template
kind: ethereum/contract
@ -98,7 +120,7 @@ templates:
abi: ERC20Template
mapping:
kind: ethereum/events
apiVersion: 0.0.5
apiVersion: 0.0.6
language: wasm/assemblyscript
file: ./src/mappings/erc20Templates.ts
entities:
@ -121,32 +143,15 @@ templates:
handler: handlePublishMarketFees
- event: ConsumeMarketFees(indexed address,indexed address,uint256)
handler: handleConsumeMarketFees
- kind: ethereum/contract
name: BFactory
network: rinkeby
source:
abi: BFactory
mapping:
kind: ethereum/events
apiVersion: 0.0.5
language: wasm/assemblyscript
file: ./src/mappings/poolFactory.ts
entities:
- BFactory
abis:
- name: BFactory
file: ./abis/BFactory.json
eventHandlers:
- event: BPoolCreated(indexed address,indexed address,indexed address,address,address,address)
handler: handleNewPool
- kind: ethereum/contract
name: BPool
- name: BPool
kind: ethereum/contract
network: rinkeby
source:
abi: BPool
mapping:
kind: ethereum/events
apiVersion: 0.0.5
apiVersion: 0.0.6
language: wasm/assemblyscript
file: ./src/mappings/pool.ts
entities:
@ -158,6 +163,8 @@ templates:
file: ./abis/BToken.json
- name: BMath
file: ./abis/BMath.json
- name: ERC20
file: ./abis/ERC20.json
eventHandlers:
- event: LOG_SWAP(indexed address,indexed address,indexed address,uint256,uint256,uint256)
handler: handleSwap
@ -167,10 +174,8 @@ templates:
handler: handleExit
- event: LOG_SETUP(indexed address,indexed address,uint256,uint256,indexed address,uint256,uint256)
handler: handleSetup
- event: LOG_BPT(uint256)
handler: handleBpt
- event: Transfer(indexed address,indexed address,uint256)
handler: handlerBptTransfer
- name: ERC721Template
kind: ethereum/contract
network: rinkeby
@ -178,7 +183,7 @@ templates:
abi: ERC721Template
mapping:
kind: ethereum/events
apiVersion: 0.0.5
apiVersion: 0.0.6
language: wasm/assemblyscript
file: ./src/mappings/nftUpdate.ts
entities:

View File

@ -6,14 +6,14 @@ schema:
dataSources:
- kind: ethereum/contract
name: ERC721Factory
network: barge
network: rinkeby
source:
address: '0x0599a4a2873B38D836E10302De1ca4834F7BDF4E'
address: '0xe4B39C90355899DB8f625D879B44Fa9C5Cdde550'
abi: ERC721Factory
startBlock: 0
startBlock: 9984045
mapping:
kind: ethereum/events
apiVersion: 0.0.5
apiVersion: 0.0.6
language: wasm/assemblyscript
file: ./src/mappings/erc721Factory.ts
entities:
@ -28,14 +28,14 @@ dataSources:
handler: handleNewToken
- kind: ethereum/contract
name: FixedRateExchange
network: barge
network: rinkeby
source:
address: '0x2356DeCd8CFB6c6f2bf46b5ED4531818B4662337'
address: '0x7084f7353bB7cfc92A65e7d23987Cb5D1A3Fb9b2'
abi: FixedRateExchange
startBlock: 0
startBlock: 9984045
mapping:
kind: ethereum/events
apiVersion: 0.0.5
apiVersion: 0.0.6
language: wasm/assemblyscript
file: ./src/mappings/fixedRateExchange.ts
entities:
@ -43,6 +43,8 @@ dataSources:
abis:
- name: FixedRateExchange
file: ./abis/FixedRateExchange.json
- name: ERC20
file: ./abis/ERC20.json
eventHandlers:
- event: ExchangeCreated(indexed bytes32,indexed address,indexed address,address,uint256)
handler: handleExchangeCreated
@ -60,14 +62,14 @@ dataSources:
handler: handleSwap
- kind: ethereum/contract
name: Dispenser
network: barge
network: rinkeby
source:
address: '0xb119b8895801111ff323ba63a77D4Fe78ED057a5'
address: '0xa8fFDd525835795C940370FB816f82a5F7F5F860'
abi: Dispenser
startBlock: 0
startBlock: 9984045
mapping:
kind: ethereum/events
apiVersion: 0.0.5
apiVersion: 0.0.6
language: wasm/assemblyscript
file: ./src/mappings/dispenser.ts
entities:
@ -88,15 +90,37 @@ dataSources:
handler: handleTokensDispensed
- event: OwnerWithdrawed(indexed address,indexed address,uint256)
handler: handleOwnerWinthdraw
- kind: ethereum/contract
name: FactoryRouter
network: rinkeby
source:
address: '0xAB4FD86E4aaAb2243463Cbe92CD5194C1593fb9A'
abi: FactoryRouter
startBlock: 9984045
mapping:
kind: ethereum/events
apiVersion: 0.0.6
language: wasm/assemblyscript
file: ./src/mappings/factoryRouter.ts
entities:
- FactoryRouter
abis:
- name: FactoryRouter
file: ./abis/FactoryRouter.json
eventHandlers:
- event: NewPool(indexed address,bool)
handler: handleNewPool
templates:
- name: ERC20Template
kind: ethereum/contract
network: barge
network: rinkeby
source:
abi: ERC20Template
mapping:
kind: ethereum/events
apiVersion: 0.0.5
apiVersion: 0.0.6
language: wasm/assemblyscript
file: ./src/mappings/erc20Templates.ts
entities:
@ -119,32 +143,15 @@ templates:
handler: handlePublishMarketFees
- event: ConsumeMarketFees(indexed address,indexed address,uint256)
handler: handleConsumeMarketFees
- kind: ethereum/contract
name: BFactory
network: barge
source:
abi: BFactory
mapping:
kind: ethereum/events
apiVersion: 0.0.5
language: wasm/assemblyscript
file: ./src/mappings/poolFactory.ts
entities:
- BFactory
abis:
- name: BFactory
file: ./abis/BFactory.json
eventHandlers:
- event: BPoolCreated(indexed address,indexed address,indexed address,address,address,address)
handler: handleNewPool
- kind: ethereum/contract
name: BPool
network: barge
- name: BPool
kind: ethereum/contract
network: rinkeby
source:
abi: BPool
mapping:
kind: ethereum/events
apiVersion: 0.0.5
apiVersion: 0.0.6
language: wasm/assemblyscript
file: ./src/mappings/pool.ts
entities:
@ -165,18 +172,16 @@ templates:
handler: handleExit
- event: LOG_SETUP(indexed address,indexed address,uint256,uint256,indexed address,uint256,uint256)
handler: handleSetup
- event: LOG_BPT(uint256)
handler: handleBpt
- event: Transfer(indexed address,indexed address,uint256)
handler: handlerBptTransfer
- name: ERC721Template
kind: ethereum/contract
network: barge
network: rinkeby
source:
abi: ERC721Template
mapping:
kind: ethereum/events
apiVersion: 0.0.5
apiVersion: 0.0.6
language: wasm/assemblyscript
file: ./src/mappings/nftUpdate.ts
entities: