-
Notifications
You must be signed in to change notification settings - Fork 14
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
feat(#major); add sol balance substream #114
Open
melotik
wants to merge
39
commits into
messari:master
Choose a base branch
from
melotik:sol-balance
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
f5e3663
initial commit on solana balances
melotik ab018e2
WIP: trying to get accounts linked to balances...
melotik 6c6d8f0
update substreams-solana
melotik 6a0ec2c
set output
melotik 59d9d74
add README
melotik 1966989
add README
melotik 3ea48ec
Add proper commands for sol-balance
melotik 6957e07
Merge branch 'master' of github.com:dmelotik/substreams into sol-balance
melotik 22a4c46
add cargo and makefile for sol
melotik af3f71d
remove typo
melotik def13f0
encode to vec and update readmes
melotik 6e45941
add sol token proto to common
melotik a72906a
update to map module
melotik 13690d7
begin map handler
melotik 3a4cbbf
fix sol balance build setup
melotik 61d4b08
change to map module
melotik 61583d0
initial commit on solana balances
melotik f7f2a17
WIP: trying to get accounts linked to balances...
melotik 43ccb3b
update substreams-solana
melotik 618e52e
set output
melotik 9ed710c
add README
melotik 6cce6f6
add README
melotik 1b93606
Add proper commands for sol-balance
melotik dba9cf5
rebase merge
melotik 3ce1bf6
encode to vec and update readmes
melotik 482a24a
add sol token proto to common
melotik 05b67e4
update to map module
melotik b321579
begin map handler
melotik 2497eae
fix sol balance build setup
melotik 24753da
change to map module
melotik b4ac3b9
Merge branch 'master' into sol-balance
melotik ad9e559
Merge branch 'sol-balance' of github.com:dmelotik/substreams into sol…
melotik b7a7726
remove outer string message
melotik b132063
update schema
melotik 3b067b9
change map module to output balance changes
melotik f730c0f
find accounts in sol balance
melotik 81da0bc
add transaction id to balance change
melotik 0222147
add a few fields to the SOL proto
melotik 43b8731
add comment about account_table_lookup
melotik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,47 @@ | ||
syntax = "proto3"; | ||
|
||
package messari.sol_token.v1; | ||
|
||
message Transfers { | ||
repeated Transfer transfers = 1; | ||
} | ||
|
||
message Transfer { | ||
string signature = 1; | ||
string from = 2; | ||
string to = 3; | ||
TokenAccount token = 4; | ||
string mint = 5; | ||
uint64 native_amount = 6; | ||
uint64 amount = 7; | ||
BalanceChanges balance_changes = 8; | ||
} | ||
|
||
message BalanceChanges { | ||
repeated TokenBalance items = 1; | ||
} | ||
|
||
// balance change | ||
message TokenBalance { | ||
TokenAccount token = 1; | ||
string transaction_id = 2; | ||
uint64 block_height = 3; | ||
string address = 4; // account address of the balance change | ||
string pre_balance = 5; // BigInt, in token's native amount | ||
string post_balance = 6; // BigInt, in token's native amount | ||
} | ||
|
||
message Tokens { | ||
repeated TokenAccount tokens = 1; | ||
} | ||
|
||
message TokenAccount { | ||
string address = 1; | ||
string name = 2; | ||
string symbol = 3; | ||
uint64 decimals = 4; | ||
string freeze_authority = 5; | ||
string mint_authority = 6; | ||
string tx_created = 7; | ||
uint64 block_created = 8; | ||
} |
Empty file.
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 |
---|---|---|
@@ -1,39 +1,9 @@ | ||
#[rustfmt::skip] | ||
#[path = "../target/pb/messari.chainlink.v1.rs"] | ||
pub(in crate::pb) mod chainlink_v1; | ||
#[path = "../target/pb/messari.sol_token.v1.rs"] | ||
pub(in crate::pb) mod sol_token_v1; | ||
|
||
pub mod chainlink { | ||
pub mod sol_token { | ||
pub mod v1 { | ||
pub use super::super::chainlink_v1::*; | ||
} | ||
} | ||
|
||
#[rustfmt::skip] | ||
#[path = "../target/pb/messari.common.v1.rs"] | ||
pub(in crate::pb) mod common_v1; | ||
|
||
pub mod common { | ||
pub mod v1 { | ||
pub use super::super::common_v1::*; | ||
} | ||
} | ||
|
||
#[rustfmt::skip] | ||
#[path = "../target/pb/messari.erc20.v1.rs"] | ||
pub(in crate::pb) mod erc20_v1; | ||
|
||
pub mod erc20 { | ||
pub mod v1 { | ||
pub use super::super::erc20_v1::*; | ||
} | ||
} | ||
|
||
#[rustfmt::skip] | ||
#[path = "../target/pb/messari.erc20_price.v1.rs"] | ||
pub(in crate::pb) mod erc20_price_v1; | ||
|
||
pub mod erc20_price { | ||
pub mod v1 { | ||
pub use super::super::erc20_price_v1::*; | ||
pub use super::super::sol_token_v1::*; | ||
} | ||
} |
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,23 @@ | ||
[package] | ||
name = "sol-balance" | ||
version = "0.1.0" | ||
description = "Messari's substream for solana SOL balances" | ||
edition = "2021" | ||
repository = "https://github.com/messari/substreams" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
bs58 = "0.4.0" | ||
prost = "0.11.2" | ||
ethabi = "17.2.0" | ||
num-bigint = "0.4" | ||
hex-literal = "0.3.4" | ||
substreams = { workspace = true } | ||
substreams-solana = { workspace = true } | ||
substreams-helper = { path = "../substreams-helper" } | ||
|
||
[build-dependencies] | ||
anyhow = "1" | ||
substreams-common = { path = "../common" } |
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,7 @@ | ||
.PHONY: build | ||
build: | ||
cargo build --target wasm32-unknown-unknown --release | ||
|
||
.PHONY: run | ||
run: | ||
substreams run -e mainnet.sol.streamingfast.io:443 substreams.yaml map_balances -s 174257750 -t +1 |
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,10 @@ | ||
# SOL Balance Substream | ||
|
||
This substream is designed to store the SOL balance of every account. | ||
|
||
### Notes | ||
|
||
- We are not able fully map all the accounts to SOL balance changes. | ||
- There is a missing field [`address_table_lookup`](https://github.com/streamingfast/firehose-solana/blob/develop/proto/sf/solana/type/v1/type.proto#L38) that stores the rest of the addresses. | ||
- See the issue filed [here](https://github.com/streamingfast/substreams/issues/144) to track the status. | ||
- This field is available, but there is decoding needed on the substream part in order to actually get that data. Next steps are understanding the Solana data structure better and seeing firesol output to get a better understanding of where this data lives. |
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,10 @@ | ||
use anyhow::{Ok, Result}; | ||
use substreams_common::codegen; | ||
|
||
fn main() -> Result<(), anyhow::Error> { | ||
println!("cargo:rerun-if-changed=proto"); | ||
println!("cargo:rerun-if-changed=abi"); | ||
codegen::generate(None)?; | ||
|
||
Ok(()) | ||
} |
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,4 @@ | ||
[toolchain] | ||
channel = "1.64.0" | ||
components = [ "rustfmt" ] | ||
targets = [ "wasm32-unknown-unknown" ] |
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 @@ | ||
// DO NOT EDIT - the file is generated by build script |
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,41 @@ | ||
use bs58; | ||
use substreams_helper::pb::sol_token::v1 as proto; | ||
use substreams_helper::token::get_sol_token; | ||
use substreams_solana::pb::sol as solana; | ||
|
||
#[substreams::handlers::map] | ||
fn map_balances( | ||
block: solana::v1::Block, | ||
) -> Result<proto::BalanceChanges, substreams::errors::Error> { | ||
let mut balances = vec![]; | ||
for tx in block.transactions { | ||
if let Some(meta) = tx.meta { | ||
if let Some(_) = meta.err { | ||
continue; | ||
} | ||
if let Some(transaction) = tx.transaction { | ||
if let Some(msg) = transaction.message { | ||
for i in 0..meta.post_balances.len() { | ||
let account_id: String; | ||
if i < msg.account_keys.len() { | ||
account_id = bs58::encode(&msg.account_keys[i]).into_string(); | ||
} else { | ||
account_id = "TODO".to_string(); | ||
// TODO: use msg.address_table_lookup table, but it is not avail | ||
} | ||
balances.push(proto::TokenBalance { | ||
token: get_sol_token(), | ||
transaction_id: bs58::encode(&transaction.signatures[0]).into_string(), | ||
block_height: block.block_height.as_ref().unwrap().block_height, | ||
address: account_id, | ||
pre_balance: meta.pre_balances[i].to_string(), | ||
post_balance: meta.post_balances[i].to_string(), | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
Ok(proto::BalanceChanges { items: balances }) | ||
} |
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,19 @@ | ||
#[rustfmt::skip] | ||
#[path = "../target/pb/messari.sol_token.v1.rs"] | ||
pub(in crate::pb) mod sol_token_v1; | ||
|
||
pub mod sol_token { | ||
pub mod v1 { | ||
pub use super::super::sol_token_v1::*; | ||
} | ||
} | ||
|
||
#[rustfmt::skip] | ||
#[path = "../target/pb/messari.solana.type.rs"] | ||
pub(in crate::pb) mod solana_type; | ||
|
||
pub mod solana { | ||
pub mod type { | ||
pub use super::super::solana_type::*; | ||
} | ||
} |
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,27 @@ | ||
specVersion: v0.1.0 | ||
package: | ||
name: sol_balance | ||
version: v0.1.0 | ||
|
||
imports: | ||
sol: https://github.com/streamingfast/firehose-solana/releases/download/v0.1.0/solana-v0.1.0.spkg | ||
|
||
protobuf: | ||
files: | ||
- sol_token.proto | ||
importPaths: | ||
- ../common/proto | ||
|
||
binaries: | ||
default: | ||
type: wasm/rust-v1 | ||
file: "../target/wasm32-unknown-unknown/release/sol_balance.wasm" | ||
|
||
modules: | ||
# get the SOL balance change of each account in each transaction in a block | ||
- name: map_balances | ||
kind: map | ||
inputs: | ||
- source: sf.solana.type.v1.Block | ||
output: | ||
type: proto:messari.sol.token.BalanceChanges |
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,9 @@ | ||
#[rustfmt::skip] | ||
#[path = "../target/pb/messari.sol_token.v1.rs"] | ||
pub(in crate::pb) mod sol_token_v1; | ||
|
||
pub mod sol_token { | ||
pub mod v1 { | ||
pub use super::super::sol_token_v1::*; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Same comments on this sorta stuff as with the other PRs :)