Skip to content

Commit

Permalink
added envio indexer for querying blockchain
Browse files Browse the repository at this point in the history
  • Loading branch information
Oba-One committed Aug 25, 2024
1 parent 176b131 commit 8e884b0
Show file tree
Hide file tree
Showing 21 changed files with 4,925 additions and 90 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"deploy:arbitrum": "pnpm --filter 'contracts' run deploy:arbitrum --network arbitrum"
},
"dependencies": {
"@ethereum-attestation-service/eas-sdk": "^2.5.0",
"dotenv": "16.4.5",
"ethers": "^6.13.2",
"viem": "^2.19.6"
Expand Down
16 changes: 8 additions & 8 deletions packages/contracts/src/registries/Action.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ contract ActionRegistry is UUPSUpgradeable, OwnableUpgradeable {
/// @notice Emitted when a new action is registered.
/// @param owner The address of the action owner.
/// @param action The details of the registered action.
event ActionRegistered(address indexed owner, Action indexed action);
event ActionRegistered(address indexed owner, uint256 actionUID, Action indexed action);

/// @notice Emitted when an action is updated.
/// @param owner The address of the action owner.
/// @param action The updated details of the action.
event ActionUpdated(address indexed owner, Action indexed action);
event ActionUpdated(address indexed owner, uint256 actionUID, Action indexed action);

uint256 private _nextActionUID;

Expand Down Expand Up @@ -79,7 +79,7 @@ contract ActionRegistry is UUPSUpgradeable, OwnableUpgradeable {
actionToOwner[actionUID] = _msgSender();
idToAction[actionUID] = Action(_startTime, _endTime, _title, _instructions, _capitals, _media);

emit ActionRegistered(_msgSender(), idToAction[actionUID]);
emit ActionRegistered(_msgSender(), actionUID, idToAction[actionUID]);
}

/// @notice Updates the start time of an existing action.
Expand All @@ -88,7 +88,7 @@ contract ActionRegistry is UUPSUpgradeable, OwnableUpgradeable {
function updateActionStartTime(uint256 actionUID, uint256 _startTime) external onlyActionOwner(actionUID) {
idToAction[actionUID].startTime = _startTime;

emit ActionUpdated(actionToOwner[actionUID], idToAction[actionUID]);
emit ActionUpdated(actionToOwner[actionUID], actionUID, idToAction[actionUID]);
}

/// @notice Updates the end time of an existing action.
Expand All @@ -97,7 +97,7 @@ contract ActionRegistry is UUPSUpgradeable, OwnableUpgradeable {
function updateActionEndTime(uint256 actionUID, uint256 _endTime) external onlyActionOwner(actionUID) {
idToAction[actionUID].endTime = _endTime;

emit ActionUpdated(actionToOwner[actionUID], idToAction[actionUID]);
emit ActionUpdated(actionToOwner[actionUID], actionUID, idToAction[actionUID]);
}

/// @notice Updates the title of an existing action.
Expand All @@ -106,7 +106,7 @@ contract ActionRegistry is UUPSUpgradeable, OwnableUpgradeable {
function updateActionTitle(uint256 actionUID, string calldata _title) external onlyActionOwner(actionUID) {
idToAction[actionUID].title = _title;

emit ActionUpdated(actionToOwner[actionUID], idToAction[actionUID]);
emit ActionUpdated(actionToOwner[actionUID], actionUID, idToAction[actionUID]);
}

/// @notice Updates the instructions for an existing action.
Expand All @@ -118,7 +118,7 @@ contract ActionRegistry is UUPSUpgradeable, OwnableUpgradeable {
) external onlyActionOwner(actionUID) {
idToAction[actionUID].instructions = _instructions;

emit ActionUpdated(actionToOwner[actionUID], idToAction[actionUID]);
emit ActionUpdated(actionToOwner[actionUID], actionUID, idToAction[actionUID]);
}

/// @notice Updates the media associated with an existing action.
Expand All @@ -127,7 +127,7 @@ contract ActionRegistry is UUPSUpgradeable, OwnableUpgradeable {
function updateActionMedia(uint256 actionUID, string[] memory _media) external onlyActionOwner(actionUID) {
idToAction[actionUID].media = _media;

emit ActionUpdated(actionToOwner[actionUID], idToAction[actionUID]);
emit ActionUpdated(actionToOwner[actionUID], actionUID, idToAction[actionUID]);
}

/// @dev Authorizes an upgrade to the contract's implementation.
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/src/tokens/Garden.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract GardenToken is ERC721Upgradeable, OwnableUpgradeable, UUPSUpgradeable {
/// @param owner The owner of the minted Garden token.
/// @param tokenId The unique identifier of the minted Garden token.
/// @param name The name of the Garden associated with the minted token.
event GardenMinted(address indexed owner, uint256 indexed tokenId, string name);
event GardenMinted(address indexed owner, uint256 indexed tokenId, address indexed account, string name);

/// @custom:oz-upgrades-unsafe-allow constructor
/// @param gardenAccountImplementation The address of the Garden account implementation.
Expand Down
1 change: 0 additions & 1 deletion packages/eas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"author": "",
"license": "ISC",
"dependencies": {
"@ethereum-attestation-service/eas-sdk": "^2.5.0",
"commander": "^12.1.0",
"zod": "^3.23.8"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/indexer/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# To create or update a token visit https://envio.dev/app/api-tokens
ENVIO_API_TOKEN="<YOUR-API-TOKEN>"
34 changes: 34 additions & 0 deletions packages/indexer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
*.exe
*.obj
*.out
*.compile
*.native
*.byte
*.cmo
*.annot
*.cmi
*.cmx
*.cmt
*.cmti
*.cma
*.a
*.cmxa
*.obj
*~
*.annot
*.cmj
*.bak
lib/*
*.mlast
*.mliast
.vscode
.merlin
.bsb.lock
/node_modules/
benchmarks/
artifacts
cache
build
*.bs.js
generated
.env
5 changes: 5 additions & 0 deletions packages/indexer/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Needed for ts build folder to have
# access to rescript node_modules
shamefully-hoist=true
# Needed so users can run `pnpm install` in the root of the repo without requiring the `-w` flag.
ignore-workspace-root-check=true
3 changes: 3 additions & 0 deletions packages/indexer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Envio Greeter Template

*Please refer to the [documentation website](https://docs.envio.dev) for a thorough guide on all Envio indexer features*
40 changes: 17 additions & 23 deletions packages/indexer/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,38 @@
name: Green Goods
description: Green Goods Indexer
contracts:
- name: Action Registry
- name: ActionRegistry
abi_file_path: ../contracts/out/Action.sol/ActionRegistry.json
handler: ./src/EventHandlers.ts
handler: src/EventHandlers.ts
events:
- event: ActionRegistered
- event: ActionUpdated
- name: Garden Account
- name: GardenToken
abi_file_path: ../contracts/out/Garden.sol/GardenToken.json
handler: src/EventHandlers.ts
events:
- event: GardenMinted
- name: GardenAccount
abi_file_path: ../contracts/out/Garden.sol/GardenAccount.json
handler: ./src/EventHandlers.ts
handler: src/EventHandlers.ts
events:
- event: NameUpdated
- event: GardenerAdded
- event: GardenerRemoved
- event: GardenOperatorAdded
- event: GardenOperatorRemoved
- name: Garden Token
abi_file_path: ../contracts/out/Garden.sol/GardenToken.json
handler: ./src/EventHandlers.ts
- name: EAS
abi_file_path: src/abis/EAS.json
handler: src/EventHandlers.ts
events:
- event: GardenMinted
# - name: Community Token
# abi_file_path: ../contracts/out/Action.sol/ActionRegistry.json
# handler: ./src/EventHandlers.ts
# events:
# - event: ActionRegistered
# - event: ActionUpdated
- event: Attested
networks:
- id: 42161 # Arbitrum
start_block: 242630858
contracts:
- name: Action Registry
address: 0x70Df51173B3EF27A245e1a0F129e2BAab39A937E
- name: Garden Token
address: 0x5D29C573581270d2bF436382820B3b64904AEeD7
- id: 11155111 # Sepolia
start_block: 6234598
contracts:
- name: Action Registry
- name: ActionRegistry
address: 0x70Df51173B3EF27A245e1a0F129e2BAab39A937E
- name: Garden Token
- name: GardenToken
address: 0x5D29C573581270d2bF436382820B3b64904AEeD7
- name: EAS
address: 0xbD75f629A22Dc1ceD33dDA0b68c546A1c035c458
70 changes: 70 additions & 0 deletions packages/indexer/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

<!--
* Copyright (c) 2021 GraphQL Contributors
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<title>GraphiQL</title>
<style>
body {
height: 100%;
margin: 0;
width: 100%;
overflow: hidden;
}

#graphiql {
height: 100vh;
}
</style>

<!--
This GraphiQL example depends on Promise and fetch, which are available in
modern browsers, but can be "polyfilled" for older browsers.
GraphiQL itself depends on React DOM.
If you do not want to rely on a CDN, you can host these files locally or
include them directly in your favored resource bundler.
-->
<script
src="https://unpkg.com/react@17/umd/react.development.js"
integrity="sha512-Vf2xGDzpqUOEIKO+X2rgTLWPY+65++WPwCHkX2nFMu9IcstumPsf/uKKRd5prX3wOu8Q0GBylRpsDB26R6ExOg=="
crossorigin="anonymous"
></script>
<script
src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"
integrity="sha512-Wr9OKCTtq1anK0hq5bY3X/AvDI5EflDSAh0mE9gma+4hl+kXdTJPKZ3TwLMBcrgUeoY0s3dq9JjhCQc7vddtFg=="
crossorigin="anonymous"
></script>

<!--
These two files can be found in the npm module, however you may wish to
copy them directly into your environment, or perhaps include them in your
favored resource bundler.
-->
<link rel="stylesheet" href="https://unpkg.com/graphiql/graphiql.min.css" />
</head>

<body>
<div id="graphiql">Loading...</div>
<script
src="https://unpkg.com/graphiql/graphiql.min.js"
type="application/javascript"
></script>
<script>
ReactDOM.render(
React.createElement(GraphiQL, {
fetcher: GraphiQL.createFetcher({
url: 'http://localhost:8080/v1/graphql',
}),
defaultEditorToolsVisibility: true,
}),
document.getElementById('graphiql'),
);
</script>
</body>
</html>
31 changes: 31 additions & 0 deletions packages/indexer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "indexer",
"version": "0.0.0",
"scripts": {
"clean": "tsc --clean",
"build": "tsc --build",
"watch": "tsc --watch",
"mocha": "ts-mocha test/**/*.ts",
"codegen": "envio codegen",
"dev": "envio dev",
"test": "pnpm mocha",
"start": "ts-node generated/src/Index.bs.js"
},
"devDependencies": {
"@types/chai": "^4.3.11",
"@types/mocha": "10.0.6",
"@types/node": "20.8.8",
"ts-mocha": "^10.0.0",
"ts-node": "10.9.1",
"typescript": "5.2.2",
"mocha": "10.2.0"
},
"dependencies": {
"chai": "4.3.10",
"envio": "2.1.0",
"ethers": "6.8.0"
},
"optionalDependencies": {
"generated": "./generated"
}
}
Loading

0 comments on commit 8e884b0

Please sign in to comment.