This commit is contained in:
mihaisc 2021-11-26 10:04:14 +02:00
parent 64cdaf8993
commit b469174136
7 changed files with 1498 additions and 1373 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -199,13 +199,13 @@ type PoolTransaction @entity {
"number of shares transfered"
sharesTransferAmount: BigDecimal
"pool fee percent, fee goes to all liquidity providers : SWAP, JOIN , EXIT"
"pool fee value, fee goes to all liquidity providers : SWAP, JOIN , EXIT"
poolFee: BigDecimal!
"OPF Fee percent, fee that goes to Ocean Protocol Foundation : SWAP"
"OPF Fee value, fee that goes to Ocean Protocol Foundation : SWAP"
opfFee: BigDecimal!
"fee that goes to the publishing market"
"market fee value, fee that goes to the publishing market"
marketFee: BigDecimal!
"block time when pool was created"
@ -232,8 +232,9 @@ type PoolTransaction @entity {
datatokenValue: BigDecimal
}
type Order @entity { # renamed from TokenOrder to Order
id: ID! # datatokenId + userAddress + tx
type Order @entity {
"transaction hash - token address - from address"
id: ID!
token: Token!
consumer: User!
@ -243,11 +244,11 @@ type Order @entity { # renamed from Toke
# the fees will be updated from an event that will be created after (todo)
publishingMarketAddress: User
publishingMarket: User
publishingMarketToken: Token #
publishingMarketAmmount: BigDecimal #call contract to get fee ammount
consumerMarketAddress: User
consumerMarket: User
consumerMarketToken: Token #
consumerMarketAmmount: BigDecimal #call contract to get fee ammount

View File

@ -1,9 +0,0 @@
import {
MinterApproved,
OrderStarted
} from '../@types/ERC20Template/ERC20Template'
// TODO: no events in contracts , it's ok !!
export function handleMinterApproved(event: MinterApproved): void {}
// TODO: to complicated at this point, return after basic events implemented ¯\_(ツ)_/¯
export function handleOrderStarted(event: OrderStarted): void {}

View File

@ -0,0 +1,78 @@
import { OrderStarted } from '../@types/ERC20Template/ERC20Template'
import { Order } from '../@types/schema'
import {
ConsumeMarketFees,
PublishMarketFees
} from '../@types/templates/ERC20Template/ERC20Template'
import { integer } from './utils/constants'
import { weiToDecimal } from './utils/generic'
import { getToken } from './utils/tokenUtils'
import { getUser } from './utils/userUtils'
function getOrderId(tx: string, tokenAddress: string, fromAddress: string) {
return `${tx}-${tokenAddress}-${fromAddress}`
}
export function handleOrderStarted(event: OrderStarted): void {
const order = new Order(
getOrderId(
event.transaction.hash.toHex(),
event.address.toHex(),
event.transaction.from.toHex()
)
)
const token = getToken(event.address.toHex())
order.token = token.id
token.orderCount = token.orderCount.plus(integer.ONE)
const consumer = getUser(event.params.consumer.toHex())
order.consumer = consumer.id
const payer = getUser(event.params.payer.toHex())
order.payer = payer.id
order.amount = weiToDecimal(
event.params.amount.toBigDecimal(),
token.decimals
)
order.serviceId = event.params.serviceId
const publishMarket = getUser(event.params.publishMarketAddress.toHex())
order.publishingMarket = publishMarket.id
const consumeMarket = getUser(event.params.consumeFeeMarketAddress.toHex())
order.consumerMarket = consumeMarket.id
order.createdTimestamp = event.block.timestamp.toI32()
order.tx = event.transaction.hash
order.block = event.block.number.toI32()
order.save()
token.save()
}
export function handlePublishMarketFees(event: PublishMarketFees): void {
const order = Order.load(
getOrderId(
event.transaction.hash.toHex(),
event.address.toHex(),
event.transaction.from.toHex()
)
)
order.save()
}
export function handleConsumeMarketFees(event: ConsumeMarketFees): void {
const order = Order.load(
getOrderId(
event.transaction.hash.toHex(),
event.address.toHex(),
event.transaction.from.toHex()
)
)
order.save()
}

View File

@ -105,6 +105,7 @@ export function handleDeactivated(event: ExchangeDeactivated): void {
)
newExchangeUpdate.oldActive = fixedRateExchange.active
newExchangeUpdate.newActive = false
newExchangeUpdate.createdTimestamp = event.block.timestamp.toI32()
newExchangeUpdate.tx = event.transaction.hash
newExchangeUpdate.block = event.block.number.toI32()

View File

@ -98,7 +98,7 @@ templates:
kind: ethereum/events
apiVersion: 0.0.5
language: wasm/assemblyscript
file: ./src/mappings/erc20Template.ts
file: ./src/mappings/erc20Templates.ts
entities:
- ERC20Template
abis:
@ -114,7 +114,11 @@ templates:
- event: OrderStarted(indexed address,address,uint256,uint256,uint256,indexed address,indexed address,uint256)
handler: handleOrderStarted
- event: NewPaymentCollector(indexed address,indexed address,uint256,uint256)
handler: handlerNewPaymentCollector
handler: handleNewPaymentCollector
- event: PublishMarketFees(indexed address,indexed address,uint256)
handler: handlePublishMarketFees
- event: ConsumeMarketFees(indexed address,indexed address,uint256)
handler: handleConsumeMarketFees
- kind: ethereum/contract
name: BFactory
network: barge
@ -165,8 +169,8 @@ templates:
handler: handleBpt
- event: Transfer(indexed address,indexed address,uint256)
handler: handlerBptTransfer
- event: SWAP_FEES(uint,uint,uint,address)
handler: handlerSwapFees
# - event: SWAP_FEES(uint,uint,uint,address)
# handler: handlerSwapFees
features:
- nonFatalErrors