Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh9200 committed Aug 27, 2024
1 parent 45decf2 commit 032b047
Show file tree
Hide file tree
Showing 28 changed files with 1,028 additions and 332 deletions.
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# IDE & Editor Directories
.vscode/
.idea/
Reference/

# Rust-specific Directories
/target/
**/target/
/build/
**/build/

# Environment & Config Files
.envrc
buf.gen.yaml
*.dev.yaml
**/buf.gen.yaml
/configs/substream/*.index.yaml

# Rust-specific Files
Cargo.lock

# Substreams Files
*/pb/
**/data/
**/*.spkg
*.spkg
/sink
/debug.log
/replay.log

# Miscellaneous
*~
/env/
/node_modules/
deploy.sh
18 changes: 18 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[workspace]
resolver = "2"
members = ["derive_deserialize", "orca-whirlpool"]
exclude = []

[workspace.dependencies]
substreams = "^0.5.21"
substreams-solana = { git = "https://github.com/streamingfast/substreams-solana", branch = "master" }
substreams-entity-change = "1.3.2"
substreams-solana-program-instructions = "0.1"

[build]
target = "wasm32-unknown-unknown"

[profile.release]
lto = true
opt-level = 's'
strip = "debuginfo"
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2018-2022 Messari Inc.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Empty file added Makefile
Empty file.
Empty file added README.md
Empty file.
13 changes: 13 additions & 0 deletions derive_deserialize/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "derive_deserialize"
version = "0.1.0"
edition = "2021"

[lib]
proc-macro = true

[dependencies]
syn = { version = "2.0", features = ["full"] }
quote = "1.0"
proc-macro2 = "1.0"
substreams-solana = { workspace = true }
45 changes: 45 additions & 0 deletions derive_deserialize/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
extern crate proc_macro;
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, DeriveInput, Data, Fields};

#[proc_macro_derive(AccountsDeserialize)]
pub fn accounts_deserialize_derive(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);
let name = &input.ident;

let expanded = match input.data {
Data::Struct(data_struct) => match data_struct.fields {
Fields::Named(fields_named) => {
let field_names = fields_named.named.iter().map(|f| &f.ident);
let field_indices = (0..fields_named.named.len()).map(syn::Index::from);

quote! {
impl<'a> AccountsDeserialize<'a> for #name<'a> {
fn deserialize(
confirmed_txn: &'a ConfirmedTransaction,
compiled_instr: &'a CompiledInstruction,
) -> Option<Self>
where
Self: Sized,
{
let instr_accounts: Vec<&Vec<u8>> = compiled_instr
.accounts
.iter()
.map(|&idx| confirmed_txn.account_at(idx as u8).0)
.collect();

Some(Self {
#(#field_names: Address(instr_accounts.get(#field_indices)?)),*
})
}
}
}
}
_ => panic!("AccountsDeserialize can only be derived for structs with named fields"),
},
_ => panic!("AccountsDeserialize can only be derived for structs"),
};

TokenStream::from(expanded)
}
17 changes: 0 additions & 17 deletions orca-whirlpool/.gitignore

This file was deleted.

28 changes: 9 additions & 19 deletions orca-whirlpool/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
[package]
name = "orca-whirlpool-solana-substreams"
name = "orca-whirlpool"
version = "1.0.0"
edition = "2021"
license = "MIT"
description = "Orca Whirlpool Substream - by Messari"

[lib]
name = "substreams"
crate-type = ["cdylib"]

[dependencies]
sha2 = "0.10.8"
substreams = "^0.5.21"
borsh = { version = "0.10.3" }
substreams-solana = { git = "https://github.com/streamingfast/substreams-solana", branch = "master" }
substreams-solana-program-instructions = "0.1"
substreams-entity-change = "1.3.2"
bytes = "1.1.0"
prost = "0.11"
num-bigint = "0.4"
bs58 = "0.5.0"
chrono = { version = "0.4", features = [ "std" ], default-features = false }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
regex = "1.10.2"
hex = "0.4.0"

[profile.release]
lto = true
opt-level = 's'
strip = "debuginfo"
borsh = { version = "1.5.0", features = ["derive"] }
substreams = { workspace = true }
substreams-solana = { workspace = true }
substreams-entity-change = { workspace = true }
substreams-solana-program-instructions = { workspace = true }
derive_deserialize = { path = "../derive_deserialize" }
2 changes: 1 addition & 1 deletion orca-whirlpool/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build:

.PHONY: stream
stream: build
substreams run -e $(ENDPOINT) substreams.yaml graph_out -s 283380456 -t +10000
substreams run -e $(ENDPOINT) substreams.yaml graph_out -s 193554025 -t +1000

.PHONY: protogen
protogen:
Expand Down
168 changes: 155 additions & 13 deletions orca-whirlpool/proto/output.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,162 @@ syntax = "proto3";

package messari.orca_whirlpool.v1;

message OrcaSwaps {
repeated Swap data = 1;
message Events {
repeated Event data = 1;
}

message Event {
oneof type {
InitializePool initalize_pool = 10;
IncreaseLiquidity increase_liquidity = 20;
DecreaseLiquidity decrease_liquidity = 30;
TwoHopSwap two_hop_swap = 40;
Swap swap = 50;
}

uint64 slot = 100;
string txn_id = 101;
uint64 block_height = 102;
int64 block_timestamp = 103;
string block_hash = 104;
}

message Swap {
uint64 amount = 1;

uint64 other_amount_threshold = 2;

string sqrt_price_limit = 3;

bool amount_specified_is_input = 4;

bool a_to_b = 5;

string signature = 6;
SwapInstruction instruction = 1;
SwapInstructionAccounts accounts = 2;

message SwapInstruction {
uint64 amount = 1;
uint64 other_amount_threshold = 2;
string sqrt_price_limit = 3;
bool amount_specified_is_input = 4;
bool a_to_b = 5;
}

message SwapInstructionAccounts {
string token_program = 1;
string token_authority = 2;
string whirlpool = 3;
string token_owner_account_a = 4;
string token_vault_a = 5;
string token_owner_account_b = 6;
string token_vault_b = 7;
string tick_array_0 = 8;
string tick_array_1 = 9;
string tick_array_2 = 10;
string oracle = 11;
}
}

message InitializePool {
InitializePoolInstruction instruction = 1;
InitializePoolInstructionAccounts accounts = 2;

message InitializePoolInstruction {
uint32 bumps = 1;
uint32 tick_spacing = 2;
string initial_sqrt_price = 3;
}

message InitializePoolInstructionAccounts {
string whirlpools_config = 1;
string token_mint_a = 2;
string token_mint_b = 3;
string funder = 4;
string whirlpool = 5;
string token_vault_a = 6;
string token_vault_b = 7;
string fee_tier = 8;
string token_program = 9;
string system_program = 10;
string rent = 11;
}
}

message IncreaseLiquidity {
IncreaseLiquidityInstruction instruction = 1;
IncreaseLiquidityInstructionAccounts accounts = 2;

message IncreaseLiquidityInstruction {
string liquidity_amount = 1;
uint64 token_max_a = 2;
uint64 token_max_b = 3;
}

message IncreaseLiquidityInstructionAccounts {
string whirlpool = 1;
string token_program = 2;
string position_authority = 3;
string position = 4;
string position_token_account = 5;
string token_owner_account_a = 6;
string token_owner_account_b = 7;
string token_vault_a = 8;
string token_vault_b = 9;
string tick_array_lower = 10;
string tick_array_upper = 11;
}
}

message DecreaseLiquidity {
DecreaseLiquidityInstruction instruction = 1;
DecreaseLiquidityInstructionAccounts accounts = 2;

message DecreaseLiquidityInstruction {
string liquidity_amount = 1;
uint64 token_max_a = 2;
uint64 token_max_b = 3;
}

message DecreaseLiquidityInstructionAccounts {
string whirlpool = 1;
string token_program = 2;
string position_authority = 3;
string position = 4;
string position_token_account = 5;
string token_owner_account_a = 6;
string token_owner_account_b = 7;
string token_vault_a = 8;
string token_vault_b = 9;
string tick_array_lower = 10;
string tick_array_upper = 11;
}
}

message TwoHopSwap {
TwoHopSwapInstruction instruction = 1;
TwoHopSwapInstructionAccounts accounts = 2;

message TwoHopSwapInstruction {
uint64 amount = 1;
uint64 other_amount_threshold = 2;
bool amount_specified_is_input = 3;
bool a_to_b_one = 4;
bool a_to_b_two = 5;
string sqrt_price_limit_one = 6;
string sqrt_price_limit_two = 7;
}

message TwoHopSwapInstructionAccounts {
string token_program = 1;
string token_authority = 2;
string whirlpool_one = 3;
string whirlpool_two = 4;
string token_owner_account_one_a = 5;
string token_vault_one_a = 6;
string token_owner_account_one_b = 7;
string token_vault_one_b = 8;
string token_owner_account_two_a = 9;
string token_vault_two_a = 10;
string token_owner_account_two_b = 11;
string token_vault_two_b = 12;
string tick_array_one0 = 13;
string tick_array_one1 = 14;
string tick_array_one2 = 15;
string tick_array_two0 = 16;
string tick_array_two1 = 17;
string tick_array_two2 = 18;
string oracle_one = 19;
string oracle_two = 20;
}
}
Loading

0 comments on commit 032b047

Please sign in to comment.