diff --git a/schema.graphql b/schema.graphql index eb48ee0..5ba2535 100644 --- a/schema.graphql +++ b/schema.graphql @@ -525,4 +525,20 @@ type Template @entity{ fixedRateTemplates: [String!] dispenserTemplates: [String!] ssTemplates: [String!] -} \ No newline at end of file +} + +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") +} diff --git a/src/mappings/factoryRouter.ts b/src/mappings/factoryRouter.ts index a5fef68..0bf1a10 100644 --- a/src/mappings/factoryRouter.ts +++ b/src/mappings/factoryRouter.ts @@ -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 = [] diff --git a/src/mappings/sscontract.ts b/src/mappings/sscontract.ts new file mode 100644 index 0000000..5f0598e --- /dev/null +++ b/src/mappings/sscontract.ts @@ -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() +} diff --git a/subgraph.template.yaml b/subgraph.template.yaml index ce74523..567e79d 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -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 \ No newline at end of file + 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 \ No newline at end of file