-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add snapshot module to create an airdrop #5
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
from datetime import datetime | ||
import argparse | ||
from injective_functions.factory import InjectiveClientFactory | ||
from injective_functions.snapshot import Snapshot | ||
from injective_functions.utils.function_helper import ( | ||
FunctionSchemaLoader, | ||
FunctionExecutor, | ||
|
@@ -46,6 +47,7 @@ def __init__(self): | |
"./injective_functions/exchange/exchange_schema.json", | ||
"./injective_functions/staking/staking_schema.json", | ||
"./injective_functions/token_factory/token_factory_schema.json", | ||
"./injective_functions/snapshot/snapshot_schema.json", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Snapshot implementation needs improvements The snapshot implementation exists but has several issues that need to be addressed:
🔗 Analysis chainVerify snapshot implementation. The snapshot schema path is added, but we need to ensure that the corresponding implementation exists and is properly integrated. Let me gather more information about the snapshot implementation. Let me check the implementation details in the identified files. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify the existence and structure of the snapshot implementation
# Check if snapshot module exists
echo "Checking for snapshot module..."
fd -t f "snapshot" injective_functions/snapshot
# Check for snapshot implementation
echo "Checking for get_snapshot implementation..."
ast-grep --pattern 'class Snapshot:
$$$
async def get_snapshot($$$):
$$$'
Length of output: 351 Script: #!/bin/bash
# Let's check for any Python files in the snapshot directory and their content
echo "Checking for Python files in snapshot directory..."
fd -e py . injective_functions/snapshot
# Let's also check the content of snapshot_schema.json
echo -e "\nChecking snapshot schema content..."
cat injective_functions/snapshot/snapshot_schema.json
# Let's search for any snapshot-related imports or usage
echo -e "\nChecking for snapshot imports or usage..."
rg -l "snapshot" --type py
Length of output: 826 Script: #!/bin/bash
# Check the content of snapshot/__init__.py
echo "Content of snapshot/__init__.py:"
cat injective_functions/snapshot/__init__.py
# Check how snapshot is used in factory.py
echo -e "\nSnapshot usage in factory.py:"
rg "snapshot" -A 5 -B 5 injective_functions/factory.py
# Check how snapshot is used in function_helper.py
echo -e "\nSnapshot usage in function_helper.py:"
rg "snapshot" -A 5 -B 5 injective_functions/utils/function_helper.py
Length of output: 2116 |
||
"./injective_functions/utils/utils_schema.json", | ||
] | ||
self.function_schemas = FunctionSchemaLoader.load_schemas(schema_paths) | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -124,6 +124,15 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"required": ["to_address", "amount"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"name": "get_snapshot", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"description": "Get a snapshot to create an airdrop", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"parameters": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"type": "object", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"properties": {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"required": [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+129
to
+135
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance the snapshot function schema with more detailed parameters and documentation. The current schema lacks important details that would help users understand and properly use this function:
Consider adding these parameters to better define the contract: {
"name": "get_snapshot",
- "description": "Get a snapshot to create an airdrop",
+ "description": "Get a snapshot of token holders or other on-chain data for creating an airdrop. Returns a list of addresses and their corresponding data.",
"parameters": {
"type": "object",
"properties": {
+ "snapshot_type": {
+ "type": "string",
+ "enum": ["token_holders", "stakers", "liquidity_providers"],
+ "description": "Type of snapshot to retrieve"
+ },
+ "token_address": {
+ "type": "string",
+ "description": "Address of the token contract (required for token_holders snapshot type)"
+ },
+ "block_height": {
+ "type": "integer",
+ "description": "Optional block height for historical snapshot. If not provided, uses latest block"
+ }
},
- "required": []
+ "required": ["snapshot_type"]
}
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -906,6 +906,15 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
"uri_hash" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"name": "get_snapshot", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"description": "Get a snapshot to create an airdrop", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance function description with more details The current description is too brief and doesn't explain what data the snapshot captures or how it will be used for the airdrop. Suggested enhancement: - "description": "Get a snapshot to create an airdrop",
+ "description": "Creates a point-in-time snapshot of token holder balances for airdrop distribution. Returns a mapping of addresses to their token balances at the specified block height, filtered by the given criteria.", 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"parameters": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"type": "object", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"properties": {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"required": [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+911
to
+917
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add essential parameters for snapshot functionality The current schema lacks crucial parameters typically needed for creating an airdrop snapshot. Consider adding:
Here's a suggested schema enhancement: "name": "get_snapshot",
"description": "Get a snapshot to create an airdrop",
"parameters": {
"type": "object",
- "properties": {},
- "required": []
+ "properties": {
+ "block_height": {
+ "type": "integer",
+ "description": "Block height at which to take the snapshot. Use 0 for latest block"
+ },
+ "token_address": {
+ "type": "string",
+ "description": "Address of the token contract to snapshot"
+ },
+ "min_balance": {
+ "type": "string",
+ "description": "Minimum token balance required for inclusion in snapshot"
+ }
+ },
+ "required": ["token_address"]
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,17 @@ | ||||||||||||||||||||||||||||||||||||||
import json | ||||||||||||||||||||||||||||||||||||||
from typing import Dict, List | ||||||||||||||||||||||||||||||||||||||
import requests | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
Comment on lines
+1
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove unused import and use aiohttp instead of requests. The -import json
from typing import Dict, List
-import requests
+import aiohttp 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Ruff (0.8.0)1-1: (F401) |
||||||||||||||||||||||||||||||||||||||
"""This class handles all the functions related to the snapshot module""" | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
class Snapshot(): | ||||||||||||||||||||||||||||||||||||||
def __init__(self) -> None: | ||||||||||||||||||||||||||||||||||||||
# Initializes the network and the composer | ||||||||||||||||||||||||||||||||||||||
super().__init__() | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
Comment on lines
+8
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unnecessary super() call. The class Snapshot():
def __init__(self) -> None:
- # Initializes the network and the composer
- super().__init__()
+ pass 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||
async def get_snapshot(self) -> List[Dict]: | ||||||||||||||||||||||||||||||||||||||
data = requests.get( | ||||||||||||||||||||||||||||||||||||||
"https://tokenstation.app/api/snapshots/last").json() | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
return data | ||||||||||||||||||||||||||||||||||||||
Comment on lines
+13
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling and timeout for external API call. The current implementation lacks proper error handling for the HTTP request and response parsing. This could lead to unhandled exceptions and potential security vulnerabilities. async def get_snapshot(self) -> List[Dict]:
+ try:
+ response = requests.get(
+ "https://tokenstation.app/api/snapshots/last",
+ timeout=10, # Add reasonable timeout
+ headers={'User-Agent': 'iAgent/1.0'} # Identify your client
+ )
+ response.raise_for_status() # Check for HTTP errors
+ return response.json()
+ except requests.RequestException as e:
+ raise ValueError(f"Failed to fetch snapshot: {str(e)}")
+ except json.JSONDecodeError as e:
+ raise ValueError(f"Invalid response format: {str(e)}")
- data = requests.get(
- "https://tokenstation.app/api/snapshots/last").json()
-
- return data 📝 Committable suggestion
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,13 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||
"functions": [ | ||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||
"name": "get_snapshot", | ||||||||||||||||||||||||||||||||||||||||||||||||
"description": "Get a snapshot to create an airdrop", | ||||||||||||||||||||||||||||||||||||||||||||||||
"parameters": { | ||||||||||||||||||||||||||||||||||||||||||||||||
"type": "object", | ||||||||||||||||||||||||||||||||||||||||||||||||
"properties": {}, | ||||||||||||||||||||||||||||||||||||||||||||||||
"required": [] | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+6
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parameters schema needs enhancement for airdrop snapshot use case. The current empty parameters schema may be insufficient for airdrop snapshots. Consider adding:
Example enhancement: "parameters": {
"type": "object",
"properties": {
+ "token_address": {
+ "type": "string",
+ "description": "Address of the token to snapshot"
+ },
+ "block_height": {
+ "type": "integer",
+ "description": "Optional block height for historical snapshot"
+ },
+ "min_balance": {
+ "type": "string",
+ "description": "Minimum token balance to include in snapshot"
+ }
},
- "required": []
+ "required": ["token_address"]
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
] | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+1
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add response schema definition. The schema should define the expected response format for better API documentation and runtime validation. Add this after the parameters object: "returns": {
"type": "array",
"items": {
"type": "object",
"properties": {
"address": {
"type": "string",
"description": "Wallet address"
},
"balance": {
"type": "string",
"description": "Token balance at snapshot time"
}
},
"required": ["address", "balance"]
}
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unused import.
The
Snapshot
import is not used in this file. Either remove it or ensure it's properly utilized if needed for the snapshot functionality.-from injective_functions.snapshot import Snapshot
🧰 Tools
🪛 Ruff (0.8.0)
8-8:
injective_functions.snapshot.Snapshot
imported but unusedRemove unused import:
injective_functions.snapshot.Snapshot
(F401)