Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pool 1176 add reserve to prize pool in subgraph #50

Open
wants to merge 4 commits into
base: v3_3_8
Choose a base branch
from
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 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ subgraph.yaml
subgraph.ropsten.yaml
subgraph.rinkeby.yaml
subgraph.mainnet.yaml
subgraph.polygon.yaml
networks/local.json
generated
generated/schema.ts
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"all-mainnet": "yarn clean && yarn prepare:mainnet && yarn gen:mainnet && yarn deploy:mainnet",
"all-mainnet-stg": "yarn clean && yarn prepare:mainnet && yarn gen:mainnet && yarn deploy:mainnet-stg",
"all-polygon-stg": "yarn clean && yarn prepare:polygon && yarn gen:polygon && yarn deploy:polygon-stg",
"update-all" : "yarn all-rinkeby && yarn all-mainnet && yarn all-polygon",
"update-all-stg" : "yarn all-rinkeby-stg && yarn all-mainnet-stg && yarn all-polygon-stg",
"codegen": "graph codegen",
"build:mainnet": "graph build subgraph.mainnet.yaml",
"build:rinkeby": "graph build subgraph.rinkeby.yaml",
Expand Down
4 changes: 2 additions & 2 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ type PrizePool @entity {
stakePrizePool: StakePrizePool
yieldSourcePrizePool: YieldSourcePrizePool

reserveFeeControlledToken: Bytes!

sablierStream: SablierStream @derivedFrom(field: "prizePool")

underlyingCollateralToken: Bytes
Expand Down Expand Up @@ -140,6 +138,8 @@ type Prize @entity {
rngRequestId: BigInt
randomNumber: BigInt

reserveFeeCaptured: BigInt

numberOfSubWinners: BigInt

totalTicketSupply: BigInt # cache of num tickets sold when this prize was awarded
Expand Down
20 changes: 10 additions & 10 deletions src/helpers/loadOrCreateExternalAward.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import {
} from '../../generated/templates/PrizePool/ERC20'

import {
SingleRandomWinnerExternalErc20Award,
SingleRandomWinnerExternalErc721Award,
MultipleWinnersExternalErc20Award,
MultipleWinnersExternalErc721Award,
} from '../../generated/schema'

import { externalAwardId } from './idTemplates'


export function loadOrCreateExternalErc20Award(prizeStrategyAddress: string, tokenAddress: Address): SingleRandomWinnerExternalErc20Award {
export function loadOrCreateExternalErc20Award(prizeStrategyAddress: string, tokenAddress: Address): MultipleWinnersExternalErc20Award {
const awardId = externalAwardId(prizeStrategyAddress, tokenAddress.toHex())

let award = SingleRandomWinnerExternalErc20Award.load(awardId)
let award = MultipleWinnersExternalErc20Award.load(awardId)
if (!award) {
log.warning("creating an externalErc20 entity ",[])
award = new SingleRandomWinnerExternalErc20Award(awardId)
award = new MultipleWinnersExternalErc20Award(awardId)
award.prizeStrategy = prizeStrategyAddress
award.address = tokenAddress

Expand Down Expand Up @@ -51,19 +51,19 @@ export function loadOrCreateExternalErc20Award(prizeStrategyAddress: string, tok
log.warning("external erc20 already existed ",[])
}

return award as SingleRandomWinnerExternalErc20Award
return award as MultipleWinnersExternalErc20Award
}

export function loadOrCreateExternalErc721Award(prizeStrategyAddress: string, tokenAddress: Address): SingleRandomWinnerExternalErc721Award {
export function loadOrCreateExternalErc721Award(prizeStrategyAddress: string, tokenAddress: Address): MultipleWinnersExternalErc721Award {
const awardId = externalAwardId(prizeStrategyAddress, tokenAddress.toHex())

let award = SingleRandomWinnerExternalErc721Award.load(awardId)
let award = MultipleWinnersExternalErc721Award.load(awardId)
if (!award) {
award = new SingleRandomWinnerExternalErc721Award(awardId)
award = new MultipleWinnersExternalErc721Award(awardId)
award.prizeStrategy = prizeStrategyAddress
award.address = tokenAddress
award.save()
}

return award as SingleRandomWinnerExternalErc721Award
return award as MultipleWinnersExternalErc721Award
}
1 change: 0 additions & 1 deletion src/helpers/loadOrCreatePrizePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export function loadOrCreatePrizePool(
}

_prizePool.reserveRegistry = Address.fromString(ZERO_ADDRESS)
_prizePool.reserveFeeControlledToken = Address.fromString(ZERO_ADDRESS)
_prizePool.deactivated = false


Expand Down
17 changes: 16 additions & 1 deletion src/mappingForPrizePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
CreditPlanSet,
PrizeStrategySet,
OwnershipTransferred,
Initialized
Initialized,
ReserveWithdrawal
} from '../generated/templates/PrizePool/PrizePool'

import {externalAwardId} from "./helpers/idTemplates"
Expand Down Expand Up @@ -76,6 +77,20 @@ export function handleReserveFeeCaptured(event: ReserveFeeCaptured): void {
_prizePool.cumulativePrizeReserveFee = _prizePool.cumulativePrizeReserveFee.plus(event.params.amount)
_prizePool.save()

const _prize = loadOrCreatePrize(_prizePool.id, _prizePool.currentPrizeId.plus(ONE).toHexString()) // ReserveFeeCaptured is fired BEFORE Awarded event so we need to increment currentPrizeId here
log.warning("handleReserveFeeCaptured debug9a9 setting reserveFeeCaptured {} on prize {}",[event.params.amount.toHexString(), _prize.id])

_prize.reserveFeeCaptured = event.params.amount;
_prize.save()

}

export function handleReserveWithdrawal(event: ReserveWithdrawal): void {
const _prizePool = loadOrCreatePrizePool(event.address)
log.warning("handleReserveWithdrawal debugiinfo9 cummumative reserve at ", [_prizePool.cumulativePrizeReserveFee.toHexString()])
_prizePool.cumulativePrizeReserveFee = _prizePool.cumulativePrizeReserveFee.minus(event.params.amount)
log.warning("handleReserveWithdrawal debugiinfo0 cummumative updated to ", [(_prizePool.cumulativePrizeReserveFee.minus(event.params.amount)).toHexString()])
_prizePool.save()
}

// this is called BEFORE PrizePoolAwarded - MW strat and SRW
Expand Down
4 changes: 4 additions & 0 deletions subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ templates:
handler: handleDeposited
- event: Initialized(address,uint256,uint256) # added together
handler: handleInitialized
# - event: ReserveFeeCaptured(uint256)
# handler: handleReserveFeeCaptured
- event: ReserveWithdrawal(indexed address,uint256)
handler: handleReserveWithdrawal

- name: ControlledToken # will one controlled token do all versions?
kind: ethereum/contract
Expand Down
1 change: 0 additions & 1 deletion testquery.gql
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
cToken
}

reserveFeeControlledToken

underlyingCollateralToken
underlyingCollateralName
Expand Down