Skip to content

Commit 5918c8b

Browse files
authored
add vesting details (#353)
1 parent 3aabf53 commit 5918c8b

File tree

4 files changed

+93
-3
lines changed

4 files changed

+93
-3
lines changed

schema.graphql

+17-1
Original file line numberDiff line numberDiff line change
@@ -525,4 +525,20 @@ type Template @entity{
525525
fixedRateTemplates: [String!]
526526
dispenserTemplates: [String!]
527527
ssTemplates: [String!]
528-
}
528+
}
529+
530+
type Vested @entity {
531+
id: ID!
532+
amount: BigDecimal!
533+
block: BigInt!
534+
vesting: Vesting!
535+
}
536+
537+
type Vesting @entity {
538+
id: ID!
539+
user: User!
540+
token: Token!
541+
endBlock: BigInt!
542+
amount: BigDecimal!
543+
vestingHistory: [Vested!]! @derivedFrom(field: "vesting")
544+
}

src/mappings/factoryRouter.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ import {
1313
} from '../@types/FactoryRouter/FactoryRouter'
1414
import { BigInt } from '@graphprotocol/graph-ts'
1515
import { Pool } from '../@types/schema'
16-
import { BPool, FixedRateExchange, Dispenser } from '../@types/templates'
16+
import {
17+
BPool,
18+
FixedRateExchange,
19+
Dispenser,
20+
SSContract
21+
} from '../@types/templates'
1722
import { addPool, getOPC, getTemplates } from './utils/globalUtils'
1823
import { weiToDecimal } from './utils/generic'
1924

@@ -99,6 +104,7 @@ export function handleTokenRemoved(event: TokenRemoved): void {
99104

100105
export function handleSSContractAdded(event: SSContractAdded): void {
101106
// add token to approvedTokens
107+
SSContract.create(event.params.contractAddress)
102108
const templates = getTemplates()
103109
let existingContracts: string[]
104110
if (!templates.ssTemplates) existingContracts = []

src/mappings/sscontract.ts

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import {
2+
VestingCreated,
3+
Vesting as VestingEvent
4+
} from '../@types/templates/SSContract/SSContract'
5+
import { Vested, Vesting } from '../@types/schema'
6+
import { getUser } from './utils/userUtils'
7+
import { getToken } from './utils/tokenUtils'
8+
import { weiToDecimal } from './utils/generic'
9+
10+
export function handleVestingCreated(event: VestingCreated): void {
11+
const vesting = new Vesting(
12+
event.address
13+
.toHexString()
14+
.concat('-')
15+
.concat(event.params.datatokenAddress.toHexString())
16+
)
17+
const user = getUser(event.params.publisherAddress.toHexString())
18+
vesting.user = user.id
19+
const token = getToken(event.params.datatokenAddress, true)
20+
vesting.token = token.id
21+
vesting.endBlock = event.params.vestingEndBlock
22+
vesting.amount = weiToDecimal(
23+
event.params.totalVestingAmount.toBigDecimal(),
24+
token.decimals
25+
)
26+
vesting.save()
27+
}
28+
29+
export function handleVesting(event: VestingEvent): void {
30+
const vesting = new Vesting(
31+
event.address
32+
.toHexString()
33+
.concat('-')
34+
.concat(event.params.datatokenAddress.toHexString())
35+
)
36+
const vestingHistory = new Vested(
37+
event.transaction.hash.toHex().concat('-').concat(event.logIndex.toString())
38+
)
39+
vestingHistory.block = event.block.number
40+
const token = getToken(event.params.datatokenAddress, true)
41+
vestingHistory.amount = weiToDecimal(
42+
event.params.amountVested.toBigDecimal(),
43+
token.decimals
44+
)
45+
vestingHistory.vesting = vesting.id
46+
vestingHistory.save()
47+
}

subgraph.template.yaml

+22-1
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,25 @@ templates:
261261
- event: Swapped(indexed bytes32,indexed address,uint256,uint256,address,uint256,uint256,uint256)
262262
handler: handleSwap
263263
- event: PublishMarketFeeChanged(indexed bytes32,address,address,uint256)
264-
handler: handlePublishMarketFeeChanged
264+
handler: handlePublishMarketFeeChanged
265+
266+
- name: SSContract
267+
kind: ethereum/contract
268+
network: __NETWORK__
269+
source:
270+
abi: SSContract
271+
mapping:
272+
kind: ethereum/events
273+
apiVersion: 0.0.6
274+
language: wasm/assemblyscript
275+
file: ./src/mappings/sscontract.ts
276+
entities:
277+
- SSContract
278+
abis:
279+
- name: SSContract
280+
file: ./node_modules/@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json
281+
eventHandlers:
282+
- event: VestingCreated(indexed address,indexed address,uint256,uint256)
283+
handler: handleVestingCreated
284+
- event: Vesting(indexed address,indexed address,indexed address,uint256)
285+
handler: handleVesting

0 commit comments

Comments
 (0)