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

Merged
merged 66 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
44bc3b8
feat: solana vault swaps elections
ramizhasan111 Oct 24, 2024
be5f075
feat: account closing tracking in elections
ramizhasan111 Oct 25, 2024
b9a66db
chore: clippy
ramizhasan111 Oct 25, 2024
b9ac4db
chore: minor
ramizhasan111 Oct 25, 2024
534d1df
fix: consensus
ramizhasan111 Oct 28, 2024
1e8f904
chore: minor
ramizhasan111 Oct 28, 2024
a284434
chore: minor rename
ramizhasan111 Oct 28, 2024
65ca599
Feat: engine logic to witness solana program swaps (#5313)
albert-llimos Oct 29, 2024
c888544
feat: return swap account along with swap details
ramizhasan111 Oct 29, 2024
a5eb16b
refactor: use election properties
ramizhasan111 Oct 29, 2024
687f650
feat: engine
ramizhasan111 Oct 30, 2024
84cd7da
feat: vault swap details
ramizhasan111 Oct 30, 2024
24c5a6d
chore: bouncer solana program swaps (#5318)
albert-llimos Oct 16, 2024
33da84b
Fixed bouncer
syan095 Oct 29, 2024
a8c60a0
chore: fix issues and renamings
albert-llimos Oct 31, 2024
b3d4fa3
chore: get block number from runtime
ramizhasan111 Oct 31, 2024
a565639
chore: vault_swap_request remove origin
ramizhasan111 Oct 31, 2024
0c6de22
fix: add is_vote_desired()
ramizhasan111 Oct 31, 2024
2965d78
fix: clippy, tests, benchmarks
ramizhasan111 Oct 31, 2024
5d23dbf
Feat: Expand Solana Vault Swap functionality and fix bouncer (#5375)
albert-llimos Nov 1, 2024
4d8af61
fix: BenchmarkValue shit, clippy and election order
ramizhasan111 Nov 1, 2024
a2c8bc6
feat: is_vote_needed
ramizhasan111 Nov 1, 2024
8758806
Test: bouncer solana event closure (#5378)
albert-llimos Nov 5, 2024
a96b1dd
Chore: refactor Solana program idls (#5381)
albert-llimos Nov 5, 2024
178cd10
chore: address comments
ramizhasan111 Nov 5, 2024
eef290e
chore: improve comment
albert-llimos Nov 5, 2024
d6f4f17
chore: nit
albert-llimos Nov 5, 2024
a403988
chore: nit CcmCfParameters
albert-llimos Nov 5, 2024
dc66695
chore: remove unnecessary comment
albert-llimos Nov 5, 2024
eceba13
chore: return hashshet in get_swap_endpoint_data
albert-llimos Nov 5, 2024
4927a01
chore: reduce duplication of data removing unnecessary hashet
albert-llimos Nov 5, 2024
ce0ec19
fix: filter out errored rpc calls
ramizhasan111 Nov 5, 2024
9783c86
chore: workaround for bouncer lint
albert-llimos Nov 6, 2024
9efd869
chore: address comments
albert-llimos Nov 6, 2024
18f793f
chore: address comments
ramizhasan111 Nov 7, 2024
a16fdbd
chore: rename file
ramizhasan111 Nov 7, 2024
8329c22
chore: make src_token safer, add unwrap()
ramizhasan111 Nov 7, 2024
51ed806
chore: pull out common code
ramizhasan111 Nov 7, 2024
3896a89
fix: chore: address comments
ramizhasan111 Nov 8, 2024
f1bf1e5
chore: address comments
ramizhasan111 Nov 8, 2024
c6811f8
chore: rebase related fixes, integrating latest features from main
ramizhasan111 Nov 14, 2024
f53e86c
chore: fixes after merge
albert-llimos Nov 14, 2024
d7c280e
chore: merge latest main
albert-llimos Nov 14, 2024
5788216
feat: update engine broker and affiliate fees
albert-llimos Nov 14, 2024
89fa7c5
chore: update dummy hardcoded test cf_parameters
albert-llimos Nov 14, 2024
39381d1
chore: refactor bouncer vault swaps
albert-llimos Nov 15, 2024
7f5ae33
chore: fix versioned decoding
albert-llimos Nov 15, 2024
4033b59
chore: fix bouncer lint
albert-llimos Nov 15, 2024
0eee9b7
feat: close accounts even for invalid swaps (#5405)
ramizhasan111 Nov 15, 2024
e1312d1
test: solana vault swap electoral system tests (#5382)
ramizhasan111 Nov 20, 2024
850eba7
fix: merge fixes
ramizhasan111 Nov 20, 2024
21a1cf4
feat: additional test for invalid swap case
ramizhasan111 Nov 20, 2024
2ca01b0
chore: minor
ramizhasan111 Nov 20, 2024
7eeb355
fix: remove expects
ramizhasan111 Nov 20, 2024
7027910
chore: clearer error message
dandanlen Nov 20, 2024
be8c5a1
feat: migration
ramizhasan111 Nov 21, 2024
aa607bd
chore: test upgrade
albert-llimos Nov 21, 2024
e6ba51f
Merge branch 'main' into feat/solana-vault-swaps-election
dandanlen Nov 21, 2024
9bda265
chore: update migration versions
dandanlen Nov 21, 2024
284e81e
chore: update version
ramizhasan111 Nov 21, 2024
b99e051
Merge branch 'main' into feat/solana-vault-swaps-election
kylezs Nov 25, 2024
bafc496
fix: print pre and post upgrade logs in upgrade-test
kylezs Nov 25, 2024
f52d20c
Feat: Use TransactionInId for Solana Vault Swaps (#5442)
albert-llimos Nov 26, 2024
0f0746c
chore: update affiliate_fee type
albert-llimos Nov 26, 2024
bcabca3
chore: restore upgrade flag
albert-llimos Nov 26, 2024
6854f90
chore: merge from main and fix clippy
albert-llimos Nov 27, 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
4 changes: 2 additions & 2 deletions state-chain/pallets/cf-elections/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ use frame_system::pallet_prelude::*;

pub use pallet::*;

pub const PALLET_VERSION: StorageVersion = StorageVersion::new(1);
pub const PALLET_VERSION: StorageVersion = StorageVersion::new(2);
ramizhasan111 marked this conversation as resolved.
Show resolved Hide resolved

pub use pallet::UniqueMonotonicIdentifier;

Expand Down Expand Up @@ -492,7 +492,7 @@ pub mod pallet {

/// Stores persistent state the electoral system needs.
#[pallet::storage]
pub(crate) type ElectoralUnsynchronisedState<T: Config<I>, I: 'static = ()> = StorageValue<
pub type ElectoralUnsynchronisedState<T: Config<I>, I: 'static = ()> = StorageValue<
_,
<T::ElectoralSystemRunner as ElectoralSystemRunner>::ElectoralUnsynchronisedState,
OptionQuery,
Expand Down
2 changes: 1 addition & 1 deletion state-chain/runtime/src/chainflip/solana_elections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn initial_state(
(),
(),
(),
0,
0u32,
),
unsynchronised_settings: (
(),
Expand Down
10 changes: 8 additions & 2 deletions state-chain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ use cf_traits::{
};
use codec::{alloc::string::ToString, Decode, Encode};
use core::ops::Range;
use frame_support::{derive_impl, instances::*};
use frame_support::{derive_impl, instances::*, migrations::VersionedMigration};
pub use frame_system::Call as SystemCall;
use pallet_cf_governance::GovCallHash;
use pallet_cf_ingress_egress::{
Expand Down Expand Up @@ -1291,7 +1291,13 @@ type PalletMigrations = (
pallet_cf_cfe_interface::migrations::PalletMigration<Runtime>,
);

type MigrationsForV1_8 = ();
type MigrationsForV1_8 = VersionedMigration<
1,
2,
ramizhasan111 marked this conversation as resolved.
Show resolved Hide resolved
migrations::solana_vault_swaps_migration::SolanaVaultSwapsMigration,
pallet_cf_elections::Pallet<Runtime, SolanaInstance>,
DbWeight,
>;

#[cfg(feature = "runtime-benchmarks")]
#[macro_use]
Expand Down
1 change: 1 addition & 0 deletions state-chain/runtime/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

pub mod housekeeping;
pub mod reap_old_accounts;
pub mod solana_vault_swaps_migration;
106 changes: 106 additions & 0 deletions state-chain/runtime/src/migrations/solana_vault_swaps_migration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
use crate::*;
use chainflip::solana_elections::SolanaVaultSwapsSettings;
use frame_support::{pallet_prelude::Weight, storage::unhashed, traits::UncheckedOnRuntimeUpgrade};

use pallet_cf_elections::{
Config, ElectoralSettings, ElectoralSystemRunner, ElectoralUnsynchronisedState,
};
#[cfg(feature = "try-runtime")]
use sp_runtime::DispatchError;

use cf_utilities::bs58_array;
use codec::{Decode, Encode};

pub struct SolanaVaultSwapsMigration;

impl UncheckedOnRuntimeUpgrade for SolanaVaultSwapsMigration {
fn on_runtime_upgrade() -> Weight {
let mut raw_unsynchronised_state = unhashed::get_raw(&ElectoralUnsynchronisedState::<
Runtime,
SolanaInstance,
>::hashed_key())
.unwrap();
raw_unsynchronised_state.extend(0u32.encode());
ElectoralUnsynchronisedState::<Runtime, SolanaInstance>::put(<<Runtime as Config<SolanaInstance>>::ElectoralSystemRunner as ElectoralSystemRunner>::ElectoralUnsynchronisedState::decode(&mut &raw_unsynchronised_state[..]).unwrap());

let (usdc_token_mint_pubkey, swap_endpoint_data_account_address) =
match cf_runtime_utilities::genesis_hashes::genesis_hash::<Runtime>() {
cf_runtime_utilities::genesis_hashes::BERGHAIN => (
SolAddress(bs58_array("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v")),
SolAddress(bs58_array("5mFsKrqCH5v9Q9uF5o6qrsUi1GV2myuhc23NAi5YFs4M")),
),
cf_runtime_utilities::genesis_hashes::PERSEVERANCE => (
SolAddress(bs58_array("4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU")),
SolAddress(bs58_array("4hD7UM6rQtcqQWtzELvrafpmBYReVXvCpssB6qjY1Sg5")),
),
cf_runtime_utilities::genesis_hashes::SISYPHOS => (
SolAddress(bs58_array("4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU")),
SolAddress(bs58_array("mYabVW1uMXpGqwgHUBQu4Fg6GT9EMYUzYaGYbi3zgT7")),
),
_ => (
SolAddress(bs58_array("24PNhTaNtomHhoy3fTRaMhAFCRj4uHqhZEEoWrKDbR5p")),
SolAddress(bs58_array("2tmtGLQcBd11BMiE9B1tAkQXwmPNgR79Meki2Eme4Ec9")),
),
};

for key in ElectoralSettings::<Runtime, SolanaInstance>::iter_keys() {
let mut raw_storage_at_key = unhashed::get_raw(&ElectoralSettings::<
Runtime,
SolanaInstance,
>::hashed_key_for(key))
.expect("We just got the keys directly from the storage");
raw_storage_at_key.extend(
SolanaVaultSwapsSettings {
usdc_token_mint_pubkey,
swap_endpoint_data_account_address,
}
.encode(),
);
ElectoralSettings::<Runtime, SolanaInstance>::insert(key, <<Runtime as Config<SolanaInstance>>::ElectoralSystemRunner as ElectoralSystemRunner>::ElectoralSettings::decode(&mut &raw_storage_at_key[..]).unwrap());
}

Weight::zero()
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
assert!(ElectoralUnsynchronisedState::<Runtime, SolanaInstance>::exists());
assert!(ElectoralSettings::<Runtime, SolanaInstance>::iter_keys().next().is_some());
Ok(Default::default())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), DispatchError> {
let (.., last_block_number) =
ElectoralUnsynchronisedState::<Runtime, SolanaInstance>::get().unwrap();
assert_eq!(last_block_number, 0u32);
for (
..,
SolanaVaultSwapsSettings { usdc_token_mint_pubkey, swap_endpoint_data_account_address },
) in ElectoralSettings::<Runtime, SolanaInstance>::iter_values()
{
assert_eq!(
(usdc_token_mint_pubkey, swap_endpoint_data_account_address),
match cf_runtime_utilities::genesis_hashes::genesis_hash::<Runtime>() {
cf_runtime_utilities::genesis_hashes::BERGHAIN => (
SolAddress(bs58_array("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v")),
SolAddress(bs58_array("5mFsKrqCH5v9Q9uF5o6qrsUi1GV2myuhc23NAi5YFs4M")),
),
cf_runtime_utilities::genesis_hashes::PERSEVERANCE => (
SolAddress(bs58_array("4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU")),
SolAddress(bs58_array("4hD7UM6rQtcqQWtzELvrafpmBYReVXvCpssB6qjY1Sg5")),
),
cf_runtime_utilities::genesis_hashes::SISYPHOS => (
SolAddress(bs58_array("4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU")),
SolAddress(bs58_array("mYabVW1uMXpGqwgHUBQu4Fg6GT9EMYUzYaGYbi3zgT7")),
),
_ => (
SolAddress(bs58_array("24PNhTaNtomHhoy3fTRaMhAFCRj4uHqhZEEoWrKDbR5p")),
SolAddress(bs58_array("2tmtGLQcBd11BMiE9B1tAkQXwmPNgR79Meki2Eme4Ec9")),
),
}
);
}
Ok(())
}
}
Loading