mirror of
https://github.com/oceanprotocol/ocean-subgraph.git
synced 2024-12-02 05:57:29 +01:00
testing
This commit is contained in:
parent
4353b15391
commit
449e71f75b
6849
package-lock.json
generated
6849
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
@ -33,7 +33,7 @@
|
||||
"changelog": "auto-changelog -p"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@graphprotocol/graph-cli": "^0.33.0",
|
||||
"@graphprotocol/graph-cli": "^0.29.0",
|
||||
"@graphprotocol/graph-ts": "^0.27.0",
|
||||
"@types/chai": "^4.3.1",
|
||||
"@types/chai-spies": "^1.0.3",
|
||||
@ -48,20 +48,18 @@
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"eslint-plugin-standard": "^5.0.0",
|
||||
"mocha": "^10.0.0",
|
||||
"mock-local-storage": "^1.1.21",
|
||||
"prettier": "^2.7.1",
|
||||
"release-it": "^15.1.4",
|
||||
"release-it": "^15.1.0",
|
||||
"source-map-support": "^0.5.21",
|
||||
"ts-node": "^10.9.1",
|
||||
"ts-node-dev": "^2.0.0",
|
||||
"ts-node-register": "^1.0.0",
|
||||
"typescript": "^4.7.4"
|
||||
"typescript": "^4.6.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@oceanprotocol/lib": "^1.1.6",
|
||||
"@oceanprotocol/lib": "^1.1.3",
|
||||
"cross-fetch": "^3.1.4"
|
||||
},
|
||||
"repository": {
|
||||
|
@ -120,7 +120,7 @@ type Pool @entity {
|
||||
id: ID!
|
||||
|
||||
"owner address, pool controller"
|
||||
controller: String
|
||||
controller: String!
|
||||
|
||||
"only finalized pools are relevant to us"
|
||||
isFinalized: Boolean!
|
||||
@ -207,7 +207,7 @@ type PoolShare @entity {
|
||||
}
|
||||
|
||||
type PoolTransaction @entity {
|
||||
"tx address + eventIndex"
|
||||
"tx address + caller address"
|
||||
id: ID!
|
||||
"pool related to this tx"
|
||||
pool: Pool!
|
||||
@ -222,7 +222,6 @@ type PoolTransaction @entity {
|
||||
timestamp: Int!
|
||||
"pool creation transaction id"
|
||||
tx: String!
|
||||
eventIndex: BigInt
|
||||
"block number when it was created"
|
||||
block: Int
|
||||
|
||||
@ -247,11 +246,9 @@ type OrderReuse @entity {
|
||||
id: ID!
|
||||
order: Order!
|
||||
caller: String!
|
||||
createdTimestamp: Int!
|
||||
createdTimestamp: BigInt!
|
||||
tx: String!
|
||||
block: Int!
|
||||
providerFee: String
|
||||
providerFeeValidUntil: BigInt
|
||||
block: BigInt!
|
||||
}
|
||||
type Order @entity {
|
||||
"transaction hash - token address - from address"
|
||||
@ -268,8 +265,6 @@ type Order @entity {
|
||||
publishingMarket: User
|
||||
publishingMarketToken: Token #
|
||||
publishingMarketAmmount: BigDecimal #call contract to get fee amount
|
||||
providerFee: String
|
||||
providerFeeValidUntil: BigInt
|
||||
|
||||
consumerMarket: User
|
||||
consumerMarketToken: Token #
|
||||
@ -502,19 +497,6 @@ type GlobalStatistic @entity {
|
||||
version: String
|
||||
}
|
||||
|
||||
type OPC @entity {
|
||||
id: ID!
|
||||
"fee in percent for swaps involving OPC approved tokens"
|
||||
swapOceanFee: BigDecimal
|
||||
"fee in percent for swaps involving non OPC approved tokens"
|
||||
swapNonOceanFee: BigDecimal
|
||||
"fee in percent taken by OPC from orderFees"
|
||||
orderFee: BigDecimal
|
||||
"fee in percent taken by OPC from providerFees"
|
||||
providerFee: BigDecimal
|
||||
approvedTokens: [Token!]
|
||||
}
|
||||
|
||||
enum NftUpdateType {
|
||||
METADATA_CREATED,
|
||||
METADATA_UPDATED,
|
||||
@ -552,4 +534,3 @@ type Template @entity{
|
||||
ssTemplates: [String!]
|
||||
}
|
||||
|
||||
|
||||
|
@ -10,8 +10,7 @@ import {
|
||||
RemovedMinter,
|
||||
RemovedPaymentManager,
|
||||
CleanedPermissions,
|
||||
OrderReused,
|
||||
ProviderFee
|
||||
OrderReused
|
||||
} from '../@types/templates/ERC20Template/ERC20Template'
|
||||
|
||||
import { integer } from './utils/constants'
|
||||
@ -19,7 +18,14 @@ import { weiToDecimal } from './utils/generic'
|
||||
import { addOrder } from './utils/globalUtils'
|
||||
import { getToken, getUSDValue } from './utils/tokenUtils'
|
||||
import { getUser } from './utils/userUtils'
|
||||
import { getOrderId } from './utils/orderUtils'
|
||||
|
||||
function getOrderId(
|
||||
tx: string,
|
||||
tokenAddress: string,
|
||||
fromAddress: string
|
||||
): string {
|
||||
return `${tx}-${tokenAddress}-${fromAddress}`
|
||||
}
|
||||
|
||||
export function handleOrderStarted(event: OrderStarted): void {
|
||||
const order = new Order(
|
||||
@ -93,9 +99,9 @@ export function handlerOrderReused(event: OrderReused): void {
|
||||
const reuseOrder = new OrderReuse(event.transaction.hash.toHex())
|
||||
reuseOrder.order = orderId
|
||||
reuseOrder.caller = event.params.caller.toHexString()
|
||||
reuseOrder.createdTimestamp = event.params.timestamp.toI32()
|
||||
reuseOrder.createdTimestamp = event.params.timestamp
|
||||
reuseOrder.tx = event.transaction.hash.toHex()
|
||||
reuseOrder.block = event.params.number.toI32()
|
||||
reuseOrder.block = event.params.number
|
||||
|
||||
reuseOrder.save()
|
||||
}
|
||||
@ -198,43 +204,26 @@ export function handleNewPaymentCollector(event: NewPaymentCollector): void {
|
||||
token.save()
|
||||
}
|
||||
|
||||
export function handleProviderFee(event: ProviderFee): void {
|
||||
const providerFee: string = `{"providerFeeAddress": "${event.params.providerFeeAddress.toHex()}", "providerFeeToken": "${event.params.providerFeeToken.toHex()}", "providerFeeAmount": "${
|
||||
event.params.providerFeeAmount
|
||||
}", "providerData": "${event.params.providerData.toHexString()}", "v": "${
|
||||
event.params.v
|
||||
}", "r": "${event.params.r.toHexString()}", "s": "${event.params.s.toHexString()}", "validUntil": "${
|
||||
event.params.validUntil
|
||||
}"}`
|
||||
// export function handlePublishMarketFees(event: PublishMarketFees): void {
|
||||
// const order = Order.load(
|
||||
// getOrderId(
|
||||
// event.transaction.hash.toHex(),
|
||||
// event.address.toHex(),
|
||||
// event.transaction.from.toHex()
|
||||
// )
|
||||
// )
|
||||
|
||||
const orderId = getOrderId(
|
||||
event.transaction.hash.toHex(),
|
||||
event.address.toHex(),
|
||||
event.transaction.from.toHex()
|
||||
)
|
||||
const order = Order.load(orderId)
|
||||
// order.save()
|
||||
// }
|
||||
|
||||
if (order) {
|
||||
order.providerFee = providerFee
|
||||
order.providerFeeValidUntil = event.params.validUntil
|
||||
order.save()
|
||||
return
|
||||
}
|
||||
// export function handleConsumeMarketFees(event: ConsumeMarketFees): void {
|
||||
// const order = Order.load(
|
||||
// getOrderId(
|
||||
// event.transaction.hash.toHex(),
|
||||
// event.address.toHex(),
|
||||
// event.transaction.from.toHex()
|
||||
// )
|
||||
// )
|
||||
|
||||
let orderReuse = OrderReuse.load(event.transaction.hash.toHex())
|
||||
if (orderReuse) {
|
||||
orderReuse.providerFee = providerFee
|
||||
orderReuse.providerFeeValidUntil = event.params.validUntil
|
||||
orderReuse.save()
|
||||
} else {
|
||||
orderReuse = new OrderReuse(event.transaction.hash.toHex())
|
||||
orderReuse.providerFee = providerFee
|
||||
orderReuse.providerFeeValidUntil = event.params.validUntil
|
||||
orderReuse.order = orderId
|
||||
orderReuse.createdTimestamp = event.block.timestamp.toI32()
|
||||
orderReuse.tx = event.transaction.hash.toHex()
|
||||
orderReuse.block = event.block.number.toI32()
|
||||
orderReuse.caller = event.transaction.from.toHex()
|
||||
orderReuse.save()
|
||||
}
|
||||
}
|
||||
// order.save()
|
||||
// }
|
||||
|
@ -1,9 +1,6 @@
|
||||
import { log } from '@graphprotocol/graph-ts'
|
||||
import {
|
||||
NewPool,
|
||||
TokenAdded,
|
||||
TokenRemoved,
|
||||
OPCFeeChanged,
|
||||
FactoryRouter,
|
||||
SSContractAdded,
|
||||
SSContractRemoved,
|
||||
FixedRateContractAdded,
|
||||
@ -11,95 +8,19 @@ import {
|
||||
DispenserContractAdded,
|
||||
DispenserContractRemoved
|
||||
} from '../@types/FactoryRouter/FactoryRouter'
|
||||
import { BigInt } from '@graphprotocol/graph-ts'
|
||||
import { Pool } from '../@types/schema'
|
||||
import { BPool, FixedRateExchange, Dispenser } from '../@types/templates'
|
||||
import { addPool, getOPC, getTemplates } from './utils/globalUtils'
|
||||
import { weiToDecimal } from './utils/generic'
|
||||
import { getToken } from './utils/tokenUtils'
|
||||
import { addPool, getTemplates } from './utils/globalUtils'
|
||||
|
||||
export function handleNewPool(event: NewPool): void {
|
||||
BPool.create(event.params.poolAddress)
|
||||
log.error('POOL START CREATE', [])
|
||||
const pool = new Pool(event.params.poolAddress.toHexString())
|
||||
pool.save()
|
||||
log.error('POOL CREATED', [])
|
||||
addPool()
|
||||
}
|
||||
|
||||
export function handleOPCFeeChanged(event: OPCFeeChanged): void {
|
||||
const opc = getOPC()
|
||||
const decimals = BigInt.fromI32(18).toI32()
|
||||
opc.swapOceanFee = weiToDecimal(
|
||||
event.params.newSwapOceanFee.toBigDecimal(),
|
||||
decimals
|
||||
)
|
||||
opc.swapNonOceanFee = weiToDecimal(
|
||||
event.params.newSwapNonOceanFee.toBigDecimal(),
|
||||
decimals
|
||||
)
|
||||
opc.orderFee = weiToDecimal(
|
||||
event.params.newConsumeFee.toBigDecimal(),
|
||||
decimals
|
||||
)
|
||||
opc.providerFee = weiToDecimal(
|
||||
event.params.newProviderFee.toBigDecimal(),
|
||||
decimals
|
||||
)
|
||||
opc.save()
|
||||
}
|
||||
|
||||
export function handleTokenAdded(event: TokenAdded): void {
|
||||
const contract = FactoryRouter.bind(event.address)
|
||||
const oceanFees = contract.try_getOPCFees()
|
||||
if (oceanFees.reverted) return
|
||||
|
||||
const opc = getOPC()
|
||||
const decimals = BigInt.fromI32(18).toI32()
|
||||
opc.swapOceanFee = weiToDecimal(
|
||||
oceanFees.value.value0.toBigDecimal(),
|
||||
decimals
|
||||
)
|
||||
opc.swapNonOceanFee = weiToDecimal(
|
||||
oceanFees.value.value1.toBigDecimal(),
|
||||
decimals
|
||||
)
|
||||
|
||||
const newOrderFee = contract.try_getOPCConsumeFee()
|
||||
if (newOrderFee.reverted) return
|
||||
|
||||
const newProviderFee = contract.try_getOPCProviderFee()
|
||||
if (newProviderFee.reverted) return
|
||||
opc.orderFee = weiToDecimal(newOrderFee.value.toBigDecimal(), decimals)
|
||||
opc.providerFee = weiToDecimal(newProviderFee.value.toBigDecimal(), decimals)
|
||||
|
||||
// add token to approvedTokens
|
||||
let existingTokens: string[]
|
||||
if (!opc.approvedTokens) existingTokens = []
|
||||
else existingTokens = opc.approvedTokens as string[]
|
||||
if (!existingTokens.includes(event.params.token.toHexString())) {
|
||||
const newToken = getToken(event.params.token, false)
|
||||
existingTokens.push(newToken.id)
|
||||
}
|
||||
|
||||
opc.approvedTokens = existingTokens
|
||||
|
||||
opc.save()
|
||||
}
|
||||
|
||||
export function handleTokenRemoved(event: TokenRemoved): void {
|
||||
const opc = getOPC()
|
||||
const newList: string[] = []
|
||||
let existingTokens: string[]
|
||||
if (!opc.approvedTokens) existingTokens = []
|
||||
else existingTokens = opc.approvedTokens as string[]
|
||||
if (!existingTokens || existingTokens.length < 1) return
|
||||
while (existingTokens.length > 0) {
|
||||
const role = existingTokens.shift().toString()
|
||||
if (!role) break
|
||||
if (role !== event.params.token.toHexString()) newList.push(role)
|
||||
}
|
||||
opc.approvedTokens = newList
|
||||
opc.save()
|
||||
}
|
||||
export function handleSSContractAdded(event: SSContractAdded): void {
|
||||
// add token to approvedTokens
|
||||
const templates = getTemplates()
|
||||
|
@ -32,12 +32,7 @@ import { getUser } from './utils/userUtils'
|
||||
export function handleJoin(event: LOG_JOIN): void {
|
||||
const pool = getPool(event.address.toHex())
|
||||
const user = getUser(event.params.caller.toHex())
|
||||
const poolTx = getPoolTransaction(
|
||||
event,
|
||||
user.id,
|
||||
PoolTransactionType.JOIN,
|
||||
event.logIndex
|
||||
)
|
||||
const poolTx = getPoolTransaction(event, user.id, PoolTransactionType.JOIN)
|
||||
|
||||
pool.transactionCount = pool.transactionCount.plus(integer.ONE)
|
||||
pool.joinCount = pool.joinCount.plus(integer.ONE)
|
||||
@ -77,12 +72,7 @@ export function handleJoin(event: LOG_JOIN): void {
|
||||
export function handleExit(event: LOG_EXIT): void {
|
||||
const pool = getPool(event.address.toHex())
|
||||
const user = getUser(event.params.caller.toHex())
|
||||
const poolTx = getPoolTransaction(
|
||||
event,
|
||||
user.id,
|
||||
PoolTransactionType.EXIT,
|
||||
event.logIndex
|
||||
)
|
||||
const poolTx = getPoolTransaction(event, user.id, PoolTransactionType.EXIT)
|
||||
|
||||
pool.transactionCount = pool.transactionCount.plus(integer.ONE)
|
||||
pool.joinCount = pool.joinCount.plus(integer.ONE)
|
||||
@ -119,12 +109,7 @@ export function handleExit(event: LOG_EXIT): void {
|
||||
export function handleSwap(event: LOG_SWAP): void {
|
||||
const pool = getPool(event.address.toHex())
|
||||
const user = getUser(event.params.caller.toHex())
|
||||
const poolTx = getPoolTransaction(
|
||||
event,
|
||||
user.id,
|
||||
PoolTransactionType.SWAP,
|
||||
event.logIndex
|
||||
)
|
||||
const poolTx = getPoolTransaction(event, user.id, PoolTransactionType.SWAP)
|
||||
|
||||
pool.transactionCount = pool.transactionCount.plus(integer.ONE)
|
||||
pool.joinCount = pool.joinCount.plus(integer.ONE)
|
||||
@ -242,8 +227,7 @@ export function handleSetup(event: LOG_SETUP): void {
|
||||
const poolTx = getPoolTransaction(
|
||||
event,
|
||||
fromUser.id,
|
||||
PoolTransactionType.SETUP,
|
||||
event.logIndex
|
||||
PoolTransactionType.SETUP
|
||||
)
|
||||
poolTx.type = PoolTransactionType.SETUP
|
||||
poolTx.baseToken = token.id
|
||||
@ -275,12 +259,7 @@ export function handlerBptTransfer(event: Transfer): void {
|
||||
const toAddress = event.params.dst.toHexString()
|
||||
const poolAddress = event.address.toHex()
|
||||
const caller = getUser(event.transaction.from.toHex())
|
||||
const poolTx = getPoolTransaction(
|
||||
event,
|
||||
caller.id,
|
||||
PoolTransactionType.SWAP,
|
||||
event.logIndex
|
||||
)
|
||||
const poolTx = getPoolTransaction(event, caller.id, PoolTransactionType.SWAP)
|
||||
|
||||
// btoken has 18 decimals
|
||||
const ammount = weiToDecimal(event.params.amt.toBigDecimal(), 18)
|
||||
|
@ -4,7 +4,6 @@ import {
|
||||
GlobalTotalFixedSwapPair,
|
||||
GlobalTotalLiquidityPair,
|
||||
GlobalTotalPoolSwapPair,
|
||||
OPC,
|
||||
Template
|
||||
} from '../../@types/schema'
|
||||
|
||||
@ -26,15 +25,6 @@ export function getGlobalStats(): GlobalStatistic {
|
||||
return globalStats
|
||||
}
|
||||
|
||||
export function getOPC(): OPC {
|
||||
let globalStats = OPC.load(GLOBAL_ID)
|
||||
if (!globalStats) {
|
||||
globalStats = new OPC(GLOBAL_ID)
|
||||
globalStats.save()
|
||||
}
|
||||
return globalStats
|
||||
}
|
||||
|
||||
export function getTemplates(): Template {
|
||||
let templates = Template.load(GLOBAL_ID)
|
||||
if (!templates) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Address, BigDecimal, BigInt, ethereum } from '@graphprotocol/graph-ts'
|
||||
import { Address, BigDecimal, ethereum } from '@graphprotocol/graph-ts'
|
||||
import {
|
||||
Pool,
|
||||
PoolShare,
|
||||
@ -19,20 +19,19 @@ export function getPoolShareId(
|
||||
|
||||
export function getPoolTransactionId(
|
||||
txHash: string,
|
||||
eventIndex: BigInt
|
||||
userAddress: string
|
||||
): string {
|
||||
return `${txHash}-` + eventIndex.toString()
|
||||
return `${txHash}-${userAddress}`
|
||||
}
|
||||
|
||||
export function getPoolTransaction(
|
||||
event: ethereum.Event,
|
||||
userAddress: string,
|
||||
type: string,
|
||||
eventIndex: BigInt
|
||||
type: string
|
||||
): PoolTransaction {
|
||||
const txId = getPoolTransactionId(
|
||||
event.transaction.hash.toHexString(),
|
||||
eventIndex
|
||||
userAddress
|
||||
)
|
||||
let poolTx = PoolTransaction.load(txId)
|
||||
|
||||
@ -46,7 +45,6 @@ export function getPoolTransaction(
|
||||
|
||||
poolTx.timestamp = event.block.timestamp.toI32()
|
||||
poolTx.tx = event.transaction.hash.toHex()
|
||||
poolTx.eventIndex = eventIndex
|
||||
poolTx.block = event.block.number.toI32()
|
||||
|
||||
poolTx.gasPrice = gweiToEth(event.transaction.gasPrice.toBigDecimal())
|
||||
|
@ -51,12 +51,6 @@ dataSources:
|
||||
eventHandlers:
|
||||
- event: NewPool(indexed address,bool)
|
||||
handler: handleNewPool
|
||||
- event: TokenAdded(indexed address,indexed address)
|
||||
handler: handleTokenAdded
|
||||
- event: TokenRemoved(indexed address,indexed address)
|
||||
handler: handleTokenRemoved
|
||||
- event: OPCFeeChanged(indexed address,uint256,uint256,uint256,uint256)
|
||||
handler: handleOPCFeeChanged
|
||||
- event: SSContractAdded(indexed address,indexed address)
|
||||
handler: handleSSContractAdded
|
||||
- event: SSContractRemoved(indexed address,indexed address)
|
||||
@ -113,8 +107,6 @@ templates:
|
||||
handler: handleRemovedPaymentManager
|
||||
- event: CleanedPermissions(indexed address,uint256,uint256)
|
||||
handler: handleCleanedPermissions
|
||||
- event: ProviderFee(indexed address,indexed address,uint256,bytes,uint8,bytes32,bytes32,uint256)
|
||||
handler: handleProviderFee
|
||||
|
||||
- name: BPool
|
||||
kind: ethereum/contract
|
||||
|
Loading…
Reference in New Issue
Block a user