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

Feature/of 504 user metrics in subgraph 2 #82

Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
run-tests:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
name: Execute Tests
steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions src/AppFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
export function handleCreated(event: Created): void {
let context = new DataSourceContext();
context.setString("App", event.params.id.toHex());
context.setBoolean("AggregationFeatureFlag", true);

ERC721FactoryFacet.createWithContext(event.params.id, context);
ERC20FactoryFacet.createWithContext(event.params.id, context);
Expand Down
40 changes: 25 additions & 15 deletions src/facet/RewardsFacet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ export function handleTokenMinted(event: TokenMinted): void {
token.save()
reward.save()

saveRewardTokenData(reward, event);
saveUserRewardData(appAddress, event.params.to, event);
saveAppRewardId(appAddress, reward.rewardId, event);
if (context.getBoolean("AggregationFeatureFlag")) {
saveRewardTokenData(reward, event);
saveUserRewardData(appAddress, event.params.to, event);
saveAppRewardId(appAddress, reward.rewardId, event);
}
}

export function handleTokenTransferred(event: TokenTransferred): void {
Expand Down Expand Up @@ -90,9 +92,11 @@ export function handleTokenTransferred(event: TokenTransferred): void {
token.save()
reward.save()

saveRewardTokenData(reward, event);
saveUserRewardData(appAddress, event.params.to, event);
saveAppRewardId(appAddress, reward.rewardId, event);
if (context.getBoolean("AggregationFeatureFlag")) {
saveRewardTokenData(reward, event);
saveUserRewardData(appAddress, event.params.to, event);
saveAppRewardId(appAddress, reward.rewardId, event);
}
}

// handles ERC721 tokens being rewarded with the uri being emitted from the event
Expand Down Expand Up @@ -127,9 +131,11 @@ export function handleERC721Minted(event: ERC721Minted): void {
user.save()
reward.save()

saveRewardBadgeData(reward, event);
saveUserRewardData(appAddress, event.params.to, event);
saveAppRewardId(appAddress, reward.rewardId, event);
if (context.getBoolean("AggregationFeatureFlag")) {
saveRewardBadgeData(reward, event);
saveUserRewardData(appAddress, event.params.to, event);
saveAppRewardId(appAddress, reward.rewardId, event);
}
}

// handles ERC721 badge tokens being rewarded with the uri on the contract
Expand Down Expand Up @@ -164,9 +170,11 @@ export function handleBadgeMinted(event: BadgeMinted): void {
user.save()
reward.save()

saveRewardBadgeData(reward, event);
saveUserRewardData(appAddress, event.params.to, event);
saveAppRewardId(appAddress, reward.rewardId, event);
if (context.getBoolean("AggregationFeatureFlag")) {
saveRewardBadgeData(reward, event);
saveUserRewardData(appAddress, event.params.to, event);
saveAppRewardId(appAddress, reward.rewardId, event);
}
}

// TODO: Remove as event no longer emitted from contracts, and only needed to maintain arbitrum-sepolia history
Expand Down Expand Up @@ -215,9 +223,11 @@ export function handleBadgeTransferred(event: BadgeTransferred): void {
user.save()
reward.save()

saveRewardBadgeData(reward, event);
saveUserRewardData(appAddress, event.params.to, event);
saveAppRewardId(appAddress, reward.rewardId, event);
if (context.getBoolean("AggregationFeatureFlag")) {
saveRewardBadgeData(reward, event);
saveUserRewardData(appAddress, event.params.to, event);
saveAppRewardId(appAddress, reward.rewardId, event);
}
}

function indexBadgeTokens(badge: Badge, quantity: BigInt, user: string, metadataURI: string, event: ethereum.Event): Array<string> {
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function saveRewardTokenData(reward: Reward, event: ethereum.Event): void
rewardData.userId = reward.user;
rewardData.tokenId = reward.token;
rewardData.tokenAmount = reward.tokenAmount;
rewardData.badgeTokenCount = 0;
rewardData.badgeTokenCount = 0;
rewardData.save()

const rewardTokenData = new RewardTokenData("auto");
Expand All @@ -124,7 +124,7 @@ export function saveRewardBadgeData(reward: Reward, event: ethereum.Event): void
rewardData.metadataURI = reward.metadataURI;
rewardData.userId = reward.user;
rewardData.badgeId = reward.badge;
rewardData.badgeTokenCount = reward.badgeCount;
rewardData.badgeTokenCount = reward.badgeCount;
rewardData.tokenAmount = Zero;
rewardData.save()

Expand All @@ -137,7 +137,7 @@ export function saveRewardBadgeData(reward: Reward, event: ethereum.Event): void
rewardBadgeData.metadataURI = reward.metadataURI;
rewardBadgeData.userId = reward.user;
rewardBadgeData.badgeId = reward.badge;
rewardBadgeData.badgeTokenCount = reward.badgeCount;
rewardBadgeData.badgeTokenCount = reward.badgeCount;
rewardBadgeData.save();
}

Expand Down
5 changes: 5 additions & 0 deletions tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ export function createApp(): AppCreated {
// Set the app in context so it is accessible
let context = new DataSourceContext()
context.set('App', Value.fromString(TEST_APP_ID))

// Matchstick doesn't support aggregation features.
// Setting this flag to false prevents aggregation functions from running during tests.
context.set("AggregationFeatureFlag", Value.fromBoolean(false))

dataSourceMock.setReturnValues(TEST_APP_ID, 'App', context)

return appEvent;
Expand Down