-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added RewardsManager and track denylist
- Loading branch information
Showing
10 changed files
with
630 additions
and
7 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { | ||
RewardsDenylistUpdated as RewardsDenylistUpdatedEvent, | ||
} from "../generated/RewardsManager/RewardsManager" | ||
import { StoreCache } from "./store-cache"; | ||
|
||
export function handleRewardsDenylistUpdated( | ||
event: RewardsDenylistUpdatedEvent, | ||
): void { | ||
let subgraphDeploymentID = event.params.subgraphDeploymentID; | ||
let id = event.transaction.hash.concatI32(event.logIndex.toI32()); | ||
|
||
let cache = new StoreCache(); | ||
let state = cache.getGlobalState(); | ||
|
||
let subgraphState = cache.getSubgraphState(subgraphDeploymentID); | ||
subgraphState.globalState = state.id; | ||
subgraphState.lastUpdated = event.block.timestamp; | ||
|
||
let entity = cache.getRewardsDenylist(id); | ||
entity.subgraphDeploymentID = subgraphDeploymentID; | ||
entity.subgraphState = subgraphState.id; | ||
entity.sinceBlock = event.params.sinceBlock; | ||
entity.timestamp = event.block.timestamp; | ||
|
||
cache.commitChanges(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { newMockEvent } from "matchstick-as" | ||
import { ethereum, Bytes, BigInt } from "@graphprotocol/graph-ts" | ||
import { | ||
RewardsDenylistUpdated | ||
} from "../generated/RewardsManager/RewardsManager" | ||
|
||
export function createRewardsDenylistUpdatedEvent( | ||
subgraphDeploymentID: Bytes, | ||
sinceBlock: BigInt | ||
): RewardsDenylistUpdated { | ||
let rewardsDenylistUpdatedEvent = | ||
changetype<RewardsDenylistUpdated>(newMockEvent()) | ||
|
||
rewardsDenylistUpdatedEvent.parameters = new Array() | ||
|
||
rewardsDenylistUpdatedEvent.parameters.push( | ||
new ethereum.EventParam( | ||
"subgraphDeploymentID", | ||
ethereum.Value.fromFixedBytes(subgraphDeploymentID) | ||
) | ||
) | ||
rewardsDenylistUpdatedEvent.parameters.push( | ||
new ethereum.EventParam( | ||
"sinceBlock", | ||
ethereum.Value.fromUnsignedBigInt(sinceBlock) | ||
) | ||
) | ||
|
||
return rewardsDenylistUpdatedEvent | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { | ||
assert, | ||
describe, | ||
test, | ||
clearStore, | ||
afterEach | ||
} from "matchstick-as/assembly/index" | ||
import { Bytes, BigInt } from "@graphprotocol/graph-ts" | ||
import { handleRewardsDenylistUpdated } from "../src/rewards-manager" | ||
import { createRewardsDenylistUpdatedEvent } from "./rewards-manager-utils" | ||
|
||
const subgraphDeploymentID = "0x0000000000000000000000000000000000000005" | ||
const subgraphDeploymentBytes = Bytes.fromHexString(subgraphDeploymentID) | ||
|
||
describe("RewardsManager", () => { | ||
afterEach(() => { | ||
clearStore() | ||
}) | ||
|
||
test("RewardsDenylistUpdated created and stored", () => { | ||
let newRewardsDenylistUpdatedEvent = createRewardsDenylistUpdatedEvent( | ||
subgraphDeploymentBytes, | ||
BigInt.fromI32(100) | ||
) | ||
handleRewardsDenylistUpdated(newRewardsDenylistUpdatedEvent) | ||
|
||
assert.entityCount("RewardsDenylist", 1) | ||
assert.fieldEquals( | ||
"RewardsDenylist", | ||
newRewardsDenylistUpdatedEvent.transaction.hash.concatI32(newRewardsDenylistUpdatedEvent.logIndex.toI32()).toHexString(), | ||
"subgraphDeploymentID", | ||
subgraphDeploymentID | ||
) | ||
assert.fieldEquals( | ||
"RewardsDenylist", | ||
newRewardsDenylistUpdatedEvent.transaction.hash.concatI32(newRewardsDenylistUpdatedEvent.logIndex.toI32()).toHexString(), | ||
"sinceBlock", | ||
"100" | ||
) | ||
// Verify SubgraphState relationship | ||
assert.entityCount("SubgraphState", 1) | ||
assert.fieldEquals("SubgraphState", subgraphDeploymentID, "id", subgraphDeploymentID) | ||
assert.fieldEquals( | ||
"SubgraphState", | ||
subgraphDeploymentID, | ||
"lastUpdated", | ||
newRewardsDenylistUpdatedEvent.block.timestamp.toString() | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters