add vesting details (#353)

This commit is contained in:
Alex Coseru 2022-02-23 17:47:34 +02:00 committed by GitHub
parent 3aabf53da4
commit 5918c8b035
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 93 additions and 3 deletions

View File

@ -525,4 +525,20 @@ type Template @entity{
fixedRateTemplates: [String!]
dispenserTemplates: [String!]
ssTemplates: [String!]
}
}
type Vested @entity {
id: ID!
amount: BigDecimal!
block: BigInt!
vesting: Vesting!
}
type Vesting @entity {
id: ID!
user: User!
token: Token!
endBlock: BigInt!
amount: BigDecimal!
vestingHistory: [Vested!]! @derivedFrom(field: "vesting")
}

View File

@ -13,7 +13,12 @@ import {
} from '../@types/FactoryRouter/FactoryRouter'
import { BigInt } from '@graphprotocol/graph-ts'
import { Pool } from '../@types/schema'
import { BPool, FixedRateExchange, Dispenser } from '../@types/templates'
import {
BPool,
FixedRateExchange,
Dispenser,
SSContract
} from '../@types/templates'
import { addPool, getOPC, getTemplates } from './utils/globalUtils'
import { weiToDecimal } from './utils/generic'
@ -99,6 +104,7 @@ export function handleTokenRemoved(event: TokenRemoved): void {
export function handleSSContractAdded(event: SSContractAdded): void {
// add token to approvedTokens
SSContract.create(event.params.contractAddress)
const templates = getTemplates()
let existingContracts: string[]
if (!templates.ssTemplates) existingContracts = []

View File

@ -0,0 +1,47 @@
import {
VestingCreated,
Vesting as VestingEvent
} from '../@types/templates/SSContract/SSContract'
import { Vested, Vesting } from '../@types/schema'
import { getUser } from './utils/userUtils'
import { getToken } from './utils/tokenUtils'
import { weiToDecimal } from './utils/generic'
export function handleVestingCreated(event: VestingCreated): void {
const vesting = new Vesting(
event.address
.toHexString()
.concat('-')
.concat(event.params.datatokenAddress.toHexString())
)
const user = getUser(event.params.publisherAddress.toHexString())
vesting.user = user.id
const token = getToken(event.params.datatokenAddress, true)
vesting.token = token.id
vesting.endBlock = event.params.vestingEndBlock
vesting.amount = weiToDecimal(
event.params.totalVestingAmount.toBigDecimal(),
token.decimals
)
vesting.save()
}
export function handleVesting(event: VestingEvent): void {
const vesting = new Vesting(
event.address
.toHexString()
.concat('-')
.concat(event.params.datatokenAddress.toHexString())
)
const vestingHistory = new Vested(
event.transaction.hash.toHex().concat('-').concat(event.logIndex.toString())
)
vestingHistory.block = event.block.number
const token = getToken(event.params.datatokenAddress, true)
vestingHistory.amount = weiToDecimal(
event.params.amountVested.toBigDecimal(),
token.decimals
)
vestingHistory.vesting = vesting.id
vestingHistory.save()
}

View File

@ -261,4 +261,25 @@ templates:
- event: Swapped(indexed bytes32,indexed address,uint256,uint256,address,uint256,uint256,uint256)
handler: handleSwap
- event: PublishMarketFeeChanged(indexed bytes32,address,address,uint256)
handler: handlePublishMarketFeeChanged
handler: handlePublishMarketFeeChanged
- name: SSContract
kind: ethereum/contract
network: __NETWORK__
source:
abi: SSContract
mapping:
kind: ethereum/events
apiVersion: 0.0.6
language: wasm/assemblyscript
file: ./src/mappings/sscontract.ts
entities:
- SSContract
abis:
- name: SSContract
file: ./node_modules/@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json
eventHandlers:
- event: VestingCreated(indexed address,indexed address,uint256,uint256)
handler: handleVestingCreated
- event: Vesting(indexed address,indexed address,indexed address,uint256)
handler: handleVesting