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: Solana Vault Swaps Elections #5355

Open
wants to merge 25 commits into
base: feat/solana-program-swaps-close-accounts
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9d83bde
wip
ramizhasan111 Oct 8, 2024
b0c5f6c
feat: solana open/close contract swap accounts
ramizhasan111 Oct 11, 2024
b0e82d0
feat: initiate contract swap
ramizhasan111 Oct 11, 2024
e323c72
feat: root origin for contract_swap_request
ramizhasan111 Oct 14, 2024
c505b3c
chore: address comment
ramizhasan111 Oct 14, 2024
0e34208
feat: solana vault swaps elections
ramizhasan111 Oct 24, 2024
4e458fb
feat: account closing tracking in elections
ramizhasan111 Oct 25, 2024
695af88
chore: clippy
ramizhasan111 Oct 25, 2024
a4bfda6
chore: minor
ramizhasan111 Oct 25, 2024
df598e8
chore: remove previous impl
ramizhasan111 Oct 25, 2024
108d839
fix: consensus
ramizhasan111 Oct 28, 2024
3c9e11f
chore: minor
ramizhasan111 Oct 28, 2024
ca07a5e
chore: minor rename
ramizhasan111 Oct 28, 2024
8f91452
Feat: engine logic to witness solana program swaps (#5313)
albert-llimos Oct 29, 2024
c842f9a
feat: return swap account along with swap details
ramizhasan111 Oct 29, 2024
222a79b
refactor: use election properties
ramizhasan111 Oct 29, 2024
9c70be0
feat: engine
ramizhasan111 Oct 30, 2024
bdea2f1
feat: vault swap details
ramizhasan111 Oct 30, 2024
6015e36
Merge branch 'feat/solana-program-swaps-close-accounts' into feat/sol…
ramizhasan111 Oct 30, 2024
e75d610
chore: merge from base branch
albert-llimos Oct 31, 2024
be95b64
chore: fix issues and renamings
albert-llimos Oct 31, 2024
634a962
chore: get block number from runtime
ramizhasan111 Oct 31, 2024
eb7146c
chore: vault_swap_request remove origin
ramizhasan111 Oct 31, 2024
bf40c42
fix: add is_vote_desired()
ramizhasan111 Oct 31, 2024
e5dcf4b
fix: clippy, tests, benchmarks
ramizhasan111 Oct 31, 2024
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
1 change: 1 addition & 0 deletions Cargo.lock

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

31 changes: 25 additions & 6 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ async-channel = { workspace = true }
async-trait = { workspace = true }
bincode = { workspace = true }
bitcoin = { workspace = true, features = ["serde"] }
borsh = { version = "1.2.1", default_features = false, features = [
"derive",
"unstable__schema",
"hashbrown",
] }
chrono = { workspace = true, features = ["clock"] }
clap = { workspace = true, features = ["derive", "env"] }
config = { workspace = true }
Expand All @@ -41,7 +46,10 @@ num-bigint = { workspace = true }
num-derive = { workspace = true }
num-traits = { workspace = true }
secp256k1 = { workspace = true, features = ["hashes"] }
serde = { workspace = true, default-features = true, features = ["derive", "rc"] }
serde = { workspace = true, default-features = true, features = [
"derive",
"rc",
] }
serde_json = { workspace = true }
sha2 = { workspace = true, default-features = true }
subxt = { workspace = true, features = ["substrate-compat"] }
Expand All @@ -51,7 +59,9 @@ tokio-stream = { workspace = true, features = ["sync"] }
url = { workspace = true }
web3 = { workspace = true, features = ["ws-tls-tokio"] }
zeroize = { workspace = true }
curve25519-dalek = { workspace = true, default-features = true, features = ["serde"] }
curve25519-dalek = { workspace = true, default-features = true, features = [
"serde",
] }
ed25519-dalek = { workspace = true }
pin-project = { workspace = true }
rand = { workspace = true, default-features = true }
Expand Down Expand Up @@ -92,19 +102,26 @@ sol-prim = { workspace = true, features = ["pda", "str", "serde", "scale"] }

# substrate deps
cf-amm = { workspace = true, default-features = true }
codec = { workspace = true, default-features = true, features = ["derive", "full"] }
codec = { workspace = true, default-features = true, features = [
"derive",
"full",
] }
frame-support = { workspace = true, default-features = true }
frame-system = { workspace = true, default-features = true }
sc-rpc-api = { workspace = true, default-features = true }
sc-transaction-pool-api = { workspace = true, default-features = true }
scale-info = { workspace = true, default-features = true, features = ["derive"] }
scale-info = { workspace = true, default-features = true, features = [
"derive",
] }
sp-core = { workspace = true, default-features = true }
sp-rpc = { workspace = true, default-features = true }
sp-runtime = { workspace = true, default-features = true }
sp-version = { workspace = true, default-features = true }
substrate-frame-rpc-system = { workspace = true }

frame-metadata = { workspace = true, default-features = true, features = ["current"] }
frame-metadata = { workspace = true, default-features = true, features = [
"current",
] }
serde_bytes = { workspace = true, default-features = true }
bs58 = { workspace = true, default-features = true }
base64 = { workspace = true }
Expand All @@ -117,7 +134,9 @@ mockall = { workspace = true, features = ["nightly"] }
multisig = { workspace = true, features = ["test"] }
rlp = { workspace = true, default-features = true }
tempfile = { workspace = true }
cf-utilities = { workspace = true, default-features = true, features = ["test-utils"] }
cf-utilities = { workspace = true, default-features = true, features = [
"test-utils",
] }
serde_path_to_error = { workspace = true }

[build-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion engine/src/elections/voter_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ macro_rules! generate_voter_api_tuple_impls {
}
}

generate_voter_api_tuple_impls!(tuple_6_impls: ((A, A0), (B, B0), (C, C0), (D, D0), (EE, E0), (FF, F0)));
generate_voter_api_tuple_impls!(tuple_7_impls: ((A, A0), (B, B0), (C, C0), (D, D0), (EE, E0), (FF, F0), (GG, G0)));
52 changes: 48 additions & 4 deletions engine/src/witness/sol.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod egress_witnessing;
mod fee_tracking;
mod nonce_witnessing;
mod program_swaps_witnessing;
mod sol_deposits;

use crate::{
Expand All @@ -16,14 +17,21 @@ use crate::{
},
};
use anyhow::Result;
use cf_chains::{sol::SolHash, Chain};
use cf_chains::{
sol::{api::VaultSwapAccountAndSender, SolHash},
Chain,
};
use futures::FutureExt;
use pallet_cf_elections::{electoral_system::ElectoralSystem, vote_storage::VoteStorage};
use pallet_cf_elections::{
electoral_system::ElectoralSystem,
electoral_systems::solana_swap_accounts_tracking::SolanaVaultSwapsVote,
vote_storage::VoteStorage,
};
use state_chain_runtime::{
chainflip::solana_elections::{
SolanaBlockHeightTracking, SolanaEgressWitnessing, SolanaElectoralSystem,
SolanaFeeTracking, SolanaIngressTracking, SolanaLiveness, SolanaNonceTracking,
TransactionSuccessDetails,
SolanaVaultSwapTracking, TransactionSuccessDetails,
},
SolanaInstance,
};
Expand All @@ -33,7 +41,7 @@ use cf_utilities::{
task_scope::{self, Scope},
};
use pallet_cf_elections::vote_storage::change::MonotonicChangeVote;
use std::{str::FromStr, sync::Arc};
use std::{collections::BTreeSet, str::FromStr, sync::Arc};

#[derive(Clone)]
struct SolanaBlockHeightTrackingVoter {
Expand Down Expand Up @@ -175,6 +183,41 @@ impl VoterApi<SolanaLiveness> for SolanaLivenessVoter {
}
}

#[allow(dead_code)]
#[derive(Clone)]
struct SolanaVaultSwapsVoter {
client: SolRetryRpcClient,
}

#[async_trait::async_trait]
impl VoterApi<SolanaVaultSwapTracking> for SolanaVaultSwapsVoter {
async fn vote(
&self,
settings: <SolanaVaultSwapTracking as ElectoralSystem>::ElectoralSettings,
properties: <SolanaVaultSwapTracking as ElectoralSystem>::ElectionProperties,
) -> Result<
<<SolanaVaultSwapTracking as ElectoralSystem>::Vote as VoteStorage>::Vote,
anyhow::Error,
> {
program_swaps_witnessing::get_program_swaps(
&self.client,
settings.swap_endpoint_data_account_address,
properties
.witnessed_open_accounts
.into_iter()
.map(|VaultSwapAccountAndSender { vault_swap_account, .. }| vault_swap_account)
.collect(),
properties.closure_initiated_accounts,
settings.usdc_token_mint_pubkey,
)
.await
.map(|(new_accounts, confirm_closed_accounts)| SolanaVaultSwapsVote {
new_accounts: new_accounts.into_iter().collect::<BTreeSet<_>>(),
confirm_closed_accounts: confirm_closed_accounts.into_iter().collect::<BTreeSet<_>>(),
})
}
}

pub async fn start<StateChainClient>(
scope: &Scope<'_, anyhow::Error>,
client: SolRetryRpcClient,
Expand All @@ -201,6 +244,7 @@ where
SolanaIngressTrackingVoter { client: client.clone() },
SolanaNonceTrackingVoter { client: client.clone() },
SolanaEgressWitnessingVoter { client: client.clone() },
SolanaVaultSwapsVoter { client: client.clone() },
SolanaLivenessVoter { client },
)),
)
Expand Down
Loading