Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,331 changes: 1,331 additions & 0 deletions abis/StakingMigrationV2.json

Large diffs are not rendered by default.

1,252 changes: 1,252 additions & 0 deletions abis/StakingV3.json

Large diffs are not rendered by default.

568 changes: 568 additions & 0 deletions abis/TalentFactoryV3.json

Large diffs are not rendered by default.

1,025 changes: 1,025 additions & 0 deletions abis/TalentTokenV3.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions data.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@ network
startBlock
7497000
TalentFactory
0xa902DA7a40a671B84bA3Dd0BdBA6FD9d2D888246
0xE072455F02Ed15bdEEB95165FF4200a8b0C72E1A
Staking
0x5a6eF881E3707AAf7201dDb7c198fc94B4b12636
0x4C9ca5956C4E39ac489081F8b0d85e987c55dB08

## Alfajores

network
celo-alfajores
startBlock
7497000
17392581
TalentFactory
0x8ee4f3044Ef0166A6DB12b0e9Eeb1735f1Fc7cc9
0xd15Dbc6b4BeA37f7A134B78092EB418e45FcD2A9
Staking
0xfc35754091D1540cE605Db87e5284369D766F0bF
0x0af4603de5F98f6C5ba6cCbc1Facf04942E10084

## Mumbai

network
mumbai
startBlock
27780000
34766222
TalentFactory
0x228D74bCf10b9ad89600E70DE265653C9Da1B514
0x6633d99c035AFb90b073A57EE06F9E46e06D3f88
Staking
0x3678cE749b0ffa5C62dd9b300148259d2DFAE572
0x38D0760d77A42740183e5C4DA876B6493DC53272

## Matic

Expand All @@ -40,6 +40,6 @@ network
startBlock
32847300
TalentFactory
0x8Db20Bc35b3AB78CbCC27c1674a26780cBB80918
0x7cc5182F85e316E0AafF86797D59Eb79A776Fabe
Staking
0xb477A9BD2547ad61f4Ac22113172Dd909E5B2331
0xFa236a656A8FBD82801Fe5bA7b127FBbC4B0ed11
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 talent-protocol"
},
"dependencies": {
"@graphprotocol/graph-cli": "0.22.0",
"@graphprotocol/graph-ts": "0.22.0"
"@graphprotocol/graph-cli": "0.40.0",
"@graphprotocol/graph-ts": "0.29.3"
}
}
132 changes: 55 additions & 77 deletions src/mapping.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { BigInt, BigDecimal } from "@graphprotocol/graph-ts"
import { TalentFactory, TalentToken, Supporter, SupporterTalentToken, TalentTokenDayData } from "../generated/schema"
import * as TalentTokenTemplates from "../generated/templates/TalentToken/TalentToken"
import { BigInt, BigDecimal, Address } from "@graphprotocol/graph-ts"
import { TalentFactory, Supporter, TalentToken, SupporterTalentToken, TalentTokenDayData } from "../generated/schema"
import * as TalentTokenTemplates from "../generated/templates/TalentToken/TalentTokenV3"
import * as Templates from "../generated/templates"
import { TalentCreated } from "../generated/TalentFactory/TalentFactory"
import { Transfer } from "../generated/templates/TalentToken/TalentToken"
import { Stake, Unstake, RewardClaim } from "../generated/Staking/Staking"
import { TalentCreated } from "../generated/TalentFactory/TalentFactoryV3"
import { Transfer } from "../generated/templates/TalentToken/TalentTokenV3"
import { Stake, Unstake } from "../generated/Staking/StakingV3"

const FACTORY_ADDRESS = '0xa902DA7a40a671B84bA3Dd0BdBA6FD9d2D888246'
const FACTORY_ADDRESS = '0x33f8FB8C3cA4465Ca02899145b4489b8eDf3A2FD'
const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000'
const ZERO_BI = BigInt.fromI32(0)
const ONE_BI = BigInt.fromI32(1)
Expand All @@ -15,35 +15,15 @@ const INITIAL_SUPPLY_BI = BigInt.fromString("10000000000000000000000")
const ZERO_BD = BigDecimal.fromString('0')

export function handleTalentTokenCreated(event: TalentCreated): void {
let factory = TalentFactory.load(FACTORY_ADDRESS)
// load factory
if (factory === null) {
factory = new TalentFactory(FACTORY_ADDRESS)
factory.talentCount = ZERO_BI
factory.owner = ADDRESS_ZERO
}
const token = event.params.token
const owner = event.params.talent.toHex()
const timestamp = event.block.timestamp

factory.talentCount = factory.talentCount.plus(ONE_BI)
factory.save()

let talentToken = new TalentToken(event.params.token.toHex())
talentToken.owner = event.params.talent.toHex()
talentToken.supporterCounter = ZERO_BI
talentToken.txCount = ZERO_BI
talentToken.totalValueLocked = INITIAL_SUPPLY_BI
talentToken.marketCap = INITIAL_SUPPLY_BI.div(FIVE_BI)
talentToken.rewardsReady = ZERO_BD
talentToken.rewardsClaimed = ZERO_BD
talentToken.createdAtTimestamp = event.block.timestamp;

Templates.TalentToken.create(event.params.token)

talentToken.save()
factory.save()
initializeFactoryAndTalentToken(token, owner, timestamp)
}

export function handleTransfer(event: Transfer): void {
let contract = TalentTokenTemplates.TalentToken.bind(event.address)
let contract = TalentTokenTemplates.TalentTokenV3.bind(event.address)

let talentToken = TalentToken.load(event.address.toHex())
if(talentToken === null) {
Expand All @@ -65,12 +45,23 @@ export function handleTransfer(event: Transfer): void {
export function handleStake(event: Stake): void {
let talentToken = TalentToken.load(event.params.talentToken.toHex())
if(talentToken === null) {
talentToken = new TalentToken(event.params.talentToken.toHex())
const token = event.params.talentToken
let contract = TalentTokenTemplates.TalentTokenV3.bind(token)
const owner = contract.talent().toHex()
const timestamp = event.block.timestamp

talentToken = initializeFactoryAndTalentToken(token, owner, timestamp)

talentToken.supporterCounter = ZERO_BI
talentToken.totalValueLocked = INITIAL_SUPPLY_BI
talentToken.marketCap = INITIAL_SUPPLY_BI.div(FIVE_BI)
talentToken.rewardsReady = ZERO_BD
talentToken.rewardsClaimed = ZERO_BD
talentToken.symbol = contract.symbol()
talentToken.decimals = BigInt.fromI32(contract.decimals())
talentToken.name = contract.name()
talentToken.maxSupply = contract.MAX_SUPPLY()
talentToken.totalSupply = contract.totalSupply()
}

talentToken.totalValueLocked = talentToken.totalValueLocked.plus(event.params.talAmount)
Expand Down Expand Up @@ -149,50 +140,6 @@ export function handleUnstake(event: Unstake): void {
supporterTalentRelationship.save()
}

export function handleRewardClaim(event: RewardClaim): void {
let talentToken = TalentToken.load(event.params.talentToken.toHex())
if(talentToken === null) {
talentToken = new TalentToken(event.params.talentToken.toHex())
talentToken.supporterCounter = ONE_BI
talentToken.totalValueLocked = INITIAL_SUPPLY_BI
talentToken.rewardsReady = ZERO_BD
talentToken.rewardsClaimed = ZERO_BD
}

talentToken.totalValueLocked = talentToken.totalValueLocked.plus(event.params.stakerReward)
talentToken.marketCap = talentToken.marketCap.plus(event.params.stakerReward.div(FIVE_BI))

let supporter = Supporter.load(event.params.owner.toHex())
if(supporter === null) {
supporter = new Supporter(event.params.owner.toHex())
supporter.totalAmount = ZERO_BD
supporter.rewardsClaimed = ZERO_BD
}

supporter.totalAmount = supporter.totalAmount.plus(BigDecimal.fromString(event.params.stakerReward.toString()))
supporter.rewardsClaimed = supporter.rewardsClaimed.plus(BigDecimal.fromString(event.params.stakerReward.toString()))

talentToken.rewardsReady = talentToken.rewardsReady.plus(BigDecimal.fromString(event.params.talentReward.toString()))

let relationshipID = event.params.owner.toHexString() + "-" + event.params.talentToken.toHexString()
let supporterTalentRelationship = SupporterTalentToken.load(relationshipID)
if (supporterTalentRelationship === null) {
supporterTalentRelationship = new SupporterTalentToken(relationshipID)
supporterTalentRelationship.supporter = supporter.id
supporterTalentRelationship.talent = talentToken.id
supporterTalentRelationship.amount = ZERO_BD
supporterTalentRelationship.firstTimeBoughtAt = event.block.timestamp
talentToken.supporterCounter = talentToken.supporterCounter.plus(ONE_BI)
}
supporterTalentRelationship.talAmount = supporterTalentRelationship.talAmount.plus(BigDecimal.fromString(event.params.stakerReward.toString()))
supporterTalentRelationship.amount = supporterTalentRelationship.amount.plus(BigDecimal.fromString(event.params.stakerReward.div(FIVE_BI).toString()))
supporterTalentRelationship.lastTimeBoughtAt = event.block.timestamp

talentToken.save()
supporter.save()
supporterTalentRelationship.save()
}

function updateTalentDayData(event: Transfer): void {
let timestamp = event.block.timestamp.toI32();
let dayID = timestamp / 86400;
Expand All @@ -217,3 +164,34 @@ function updateTalentDayData(event: Transfer): void {
talentDayData.dailySupply = talentToken.totalSupply;
talentDayData.save();
}

function initializeFactoryAndTalentToken(token: Address, owner: string, timestamp: BigInt): TalentToken {
let factory = TalentFactory.load(FACTORY_ADDRESS)
// load factory
if (factory === null) {
factory = new TalentFactory(FACTORY_ADDRESS)
factory.talentCount = ZERO_BI
factory.owner = ADDRESS_ZERO
}

factory.talentCount = factory.talentCount.plus(ONE_BI)
factory.save()

let talentToken = new TalentToken(token.toHex())

talentToken.supporterCounter = ZERO_BI
talentToken.txCount = ZERO_BI
talentToken.totalValueLocked = INITIAL_SUPPLY_BI
talentToken.marketCap = INITIAL_SUPPLY_BI.div(FIVE_BI)
talentToken.rewardsReady = ZERO_BD
talentToken.rewardsClaimed = ZERO_BD
talentToken.createdAtTimestamp = timestamp
talentToken.owner = owner

Templates.TalentToken.create(token)

talentToken.save()
factory.save()

return talentToken
}
46 changes: 23 additions & 23 deletions subgraph.yaml
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
specVersion: 0.0.2
specVersion: 0.0.4
schema:
file: ./schema.graphql
dataSources:
- kind: ethereum/contract
name: TalentFactory
network: celo-alfajores
network: mumbai
source:
address: "0xE6A0829535C76bA3d1A69a27381Ee08c772Cb837"
abi: TalentFactory
startBlock: 7497000
address: "0x33f8FB8C3cA4465Ca02899145b4489b8eDf3A2FD"
abi: TalentFactoryV3
startBlock: 34766222
mapping:
kind: ethereum/events
apiVersion: 0.0.5
apiVersion: 0.0.6
language: wasm/assemblyscript
entities:
- Talent
abis:
- name: TalentFactory
file: ./abis/TalentFactory.json
- name: TalentFactoryV3
file: ./abis/TalentFactoryV3.json
eventHandlers:
- event: TalentCreated(indexed address,indexed address)
handler: handleTalentTokenCreated
file: ./src/mapping.ts
- kind: ethereum/contract
name: Staking
network: celo-alfajores
network: mumbai
source:
address: "0x3c9260F62679b3D08648346223572A8BF3f89fA8"
abi: Staking
startBlock: 7497000
address: "0x4C1A1DaaEc0a1660359F83D76571f4b000eC7DA6"
abi: StakingV3
startBlock: 34766222
mapping:
kind: ethereum/events
apiVersion: 0.0.5
apiVersion: 0.0.6
language: wasm/assemblyscript
entities:
- Talent
abis:
- name: Staking
file: ./abis/Staking.json
- name: StakingV3
file: ./abis/StakingV3.json
- name: TalentTokenV3
file: ./abis/TalentTokenV3.json
eventHandlers:
- event: Stake(indexed address,indexed address,uint256,bool)
handler: handleStake
- event: Unstake(indexed address,indexed address,uint256)
handler: handleUnstake
- event: RewardClaim(indexed address,indexed address,uint256,uint256)
handler: handleRewardClaim
file: ./src/mapping.ts
templates:
- name: TalentToken
kind: ethereum/contract
network: celo-alfajores
network: mumbai
source:
abi: TalentToken
abi: TalentTokenV3
mapping:
kind: ethereum/events
apiVersion: 0.0.5
apiVersion: 0.0.6
language: wasm/assemblyscript
file: ./src/mapping.ts
entities:
- TalentToken
- TalentTokenV3
abis:
- name: TalentToken
file: ./abis/TalentToken.json
- name: TalentTokenV3
file: ./abis/TalentTokenV3.json
eventHandlers:
- event: Transfer(indexed address,indexed address,uint256)
handler: handleTransfer
Loading