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

feat(#major); add sol balance substream #114

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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 Dec 10, 2022
ab018e2
WIP: trying to get accounts linked to balances...
melotik Dec 14, 2022
6c6d8f0
update substreams-solana
melotik Dec 14, 2022
6a0ec2c
set output
melotik Dec 15, 2022
59d9d74
add README
melotik Dec 15, 2022
1966989
add README
melotik Dec 15, 2022
3ea48ec
Add proper commands for sol-balance
melotik Dec 16, 2022
6957e07
Merge branch 'master' of github.com:dmelotik/substreams into sol-balance
melotik Dec 22, 2022
22a4c46
add cargo and makefile for sol
melotik Dec 22, 2022
af3f71d
remove typo
melotik Dec 22, 2022
def13f0
encode to vec and update readmes
melotik Dec 22, 2022
6e45941
add sol token proto to common
melotik Jan 7, 2023
a72906a
update to map module
melotik Jan 7, 2023
13690d7
begin map handler
melotik Jan 7, 2023
3a4cbbf
fix sol balance build setup
melotik Jan 12, 2023
61d4b08
change to map module
melotik Jan 13, 2023
61583d0
initial commit on solana balances
melotik Dec 10, 2022
f7f2a17
WIP: trying to get accounts linked to balances...
melotik Dec 14, 2022
43ccb3b
update substreams-solana
melotik Dec 14, 2022
618e52e
set output
melotik Dec 15, 2022
9ed710c
add README
melotik Dec 15, 2022
6cce6f6
add README
melotik Dec 15, 2022
1b93606
Add proper commands for sol-balance
melotik Dec 16, 2022
dba9cf5
rebase merge
melotik Jan 13, 2023
3ce1bf6
encode to vec and update readmes
melotik Dec 22, 2022
482a24a
add sol token proto to common
melotik Jan 7, 2023
05b67e4
update to map module
melotik Jan 7, 2023
b321579
begin map handler
melotik Jan 7, 2023
2497eae
fix sol balance build setup
melotik Jan 12, 2023
24753da
change to map module
melotik Jan 13, 2023
b4ac3b9
Merge branch 'master' into sol-balance
melotik Jan 13, 2023
ad9e559
Merge branch 'sol-balance' of github.com:dmelotik/substreams into sol…
melotik Jan 13, 2023
b7a7726
remove outer string message
melotik Jan 13, 2023
b132063
update schema
melotik Jan 19, 2023
3b067b9
change map module to output balance changes
melotik Jan 25, 2023
f730c0f
find accounts in sol balance
melotik Jan 26, 2023
81da0bc
add transaction id to balance change
melotik Jan 26, 2023
0222147
add a few fields to the SOL proto
melotik Feb 1, 2023
43b8731
add comment about account_table_lookup
melotik Feb 2, 2023
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
35 changes: 34 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ members = [
"substreams-helper",
"uniswap-v2",
"solana-sample",
"sol-balance",
"ens-names",
]
exclude = ["messari-cli"]

[workspace.dependencies]
substreams = "0.3.2"
substreams-ethereum = "0.6.2"
substreams-solana = "0.1.0"
substreams-solana = "0.2.0"

[build]
target = "wasm32-unknown-unknown"
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ build-all:
$(MAKE) -C network build
$(MAKE) -C solana-sample build
$(MAKE) -C eth-balance build
$(MAKE) -C sol-balance build
$(MAKE) -C ens-names build

.PHONY: run-all
Expand All @@ -19,6 +20,7 @@ run-all:
$(MAKE) -C erc20-market-cap run
$(MAKE) -C erc721 run
$(MAKE) -C network run
$(MAKE) -C sol-balance run
$(MAKE) -C ens-names run

.PHONY: test
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
| ENS Look Up | 🔨 | ENS records for lookup and reverse lookup |
| Uniswap v2 | 🔨 | Substreams for Uniswap v2 |
| Compound v2 | 🔨 | Substreams for Compound v2 |
| SOL Balance | 🛠 | SOL balance for every Solana address |

## Workflow

Expand Down
47 changes: 47 additions & 0 deletions common/proto/sol_token.proto
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 added erc20-holdings/README.md
Empty file.
38 changes: 4 additions & 34 deletions erc20-holdings/src/pb.rs
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::*;
}
}
10 changes: 10 additions & 0 deletions erc20-market-cap/src/pb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,13 @@ pub mod erc20_price {
pub use super::super::erc20_price_v1::*;
}
}

#[rustfmt::skip]
#[path = "../target/pb/messari.uniswap.v1.rs"]
pub(in crate::pb) mod uniswap_v1;

pub mod uniswap {
pub mod v1 {
pub use super::super::uniswap_v1::*;
}
}
23 changes: 23 additions & 0 deletions sol-balance/Cargo.toml
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" }
7 changes: 7 additions & 0 deletions sol-balance/Makefile
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
10 changes: 10 additions & 0 deletions sol-balance/README.md
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.
10 changes: 10 additions & 0 deletions sol-balance/build.rs
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(())
}
4 changes: 4 additions & 0 deletions sol-balance/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[toolchain]
Copy link
Contributor

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 :)

channel = "1.64.0"
components = [ "rustfmt" ]
targets = [ "wasm32-unknown-unknown" ]
1 change: 1 addition & 0 deletions sol-balance/src/abi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// DO NOT EDIT - the file is generated by build script
41 changes: 41 additions & 0 deletions sol-balance/src/lib.rs
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 })
}
19 changes: 19 additions & 0 deletions sol-balance/src/pb.rs
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::*;
}
}
27 changes: 27 additions & 0 deletions sol-balance/substreams.yaml
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
1 change: 1 addition & 0 deletions substreams-helper/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::{Ok, Result};
use substreams_common::codegen;

fn main() -> Result<(), anyhow::Error> {
codegen::generate(None);
codegen::generate_abi(None)?;
Ok(())
}
2 changes: 2 additions & 0 deletions substreams-helper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ pub mod abi;
pub mod erc20;
pub mod keyer;
pub mod math;
pub mod pb;
pub mod price;
pub mod token;
pub mod types;
pub mod utils;
9 changes: 9 additions & 0 deletions substreams-helper/src/pb.rs
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::*;
}
}
Loading