mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Add ABI crate
Call and Event are both from the pallets, which are AGPL licensed. Accordingly, they make serai-client AGPL licensed when serai-client must end up MIT licensed. This creates a MIT-licensed variant of Calls and Events such that they can be used by serai-client, enabling transitioning it to MIT. Relevant to https://github.com/serai-dex/serai/issues/337.
This commit is contained in:
38
substrate/abi/Cargo.toml
Normal file
38
substrate/abi/Cargo.toml
Normal file
@@ -0,0 +1,38 @@
|
||||
[package]
|
||||
name = "serai-abi"
|
||||
version = "0.1.0"
|
||||
description = "ABI for the Serai runtime"
|
||||
license = "MIT"
|
||||
repository = "https://github.com/serai-dex/serai/tree/develop/substrate/abi"
|
||||
authors = ["Luke Parker <lukeparker5132@gmail.com>"]
|
||||
edition = "2021"
|
||||
rust-version = "1.69"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
|
||||
[dependencies]
|
||||
scale = { package = "parity-scale-codec", version = "3", features = ["derive"] }
|
||||
|
||||
borsh = { version = "1", features = ["derive", "de_strict_order"], optional = true }
|
||||
serde = { version = "1", features = ["derive", "alloc"], optional = true }
|
||||
|
||||
sp-application-crypto = { git = "https://github.com/serai-dex/substrate" }
|
||||
sp-core = { git = "https://github.com/serai-dex/substrate" }
|
||||
sp-runtime = { git = "https://github.com/serai-dex/substrate" }
|
||||
|
||||
sp-consensus-babe = { git = "https://github.com/serai-dex/substrate" }
|
||||
sp-consensus-grandpa = { git = "https://github.com/serai-dex/substrate" }
|
||||
|
||||
serai-primitives = { path = "../primitives", version = "0.1" }
|
||||
serai-coins-primitives = { path = "../coins/primitives", version = "0.1" }
|
||||
serai-validator-sets-primitives = { path = "../validator-sets/primitives", version = "0.1" }
|
||||
serai-in-instructions-primitives = { path = "../in-instructions/primitives", version = "0.1" }
|
||||
serai-signals-primitives = { path = "../signals/primitives", version = "0.1" }
|
||||
|
||||
frame-support = { git = "https://github.com/serai-dex/substrate" }
|
||||
|
||||
[features]
|
||||
borsh = ["dep:borsh"]
|
||||
serde = ["dep:serde"]
|
||||
21
substrate/abi/LICENSE
Normal file
21
substrate/abi/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 Luke Parker
|
||||
|
||||
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.
|
||||
15
substrate/abi/src/babe.rs
Normal file
15
substrate/abi/src/babe.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
use sp_consensus_babe::EquivocationProof;
|
||||
|
||||
use serai_primitives::Header;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode)]
|
||||
pub struct ReportEquivocation {
|
||||
pub equivocation_proof: Box<EquivocationProof<Header>>,
|
||||
pub key_owner_proof: (),
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode)]
|
||||
pub enum Call {
|
||||
report_equivocation(ReportEquivocation),
|
||||
report_equivocation_unsigned(ReportEquivocation),
|
||||
}
|
||||
23
substrate/abi/src/coins.rs
Normal file
23
substrate/abi/src/coins.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use serai_primitives::{Balance, SeraiAddress};
|
||||
|
||||
pub use serai_coins_primitives as primitives;
|
||||
use primitives::OutInstructionWithBalance;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode)]
|
||||
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum Call {
|
||||
transfer { to: SeraiAddress, balance: Balance },
|
||||
burn { balance: Balance },
|
||||
burn_with_instruction { instruction: OutInstructionWithBalance },
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode)]
|
||||
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum Event {
|
||||
Mint { to: SeraiAddress, balance: Balance },
|
||||
Burn { from: SeraiAddress, balance: Balance },
|
||||
BurnWithInstruction { from: SeraiAddress, instruction: OutInstructionWithBalance },
|
||||
Transfer { from: SeraiAddress, to: SeraiAddress, balance: Balance },
|
||||
}
|
||||
77
substrate/abi/src/dex.rs
Normal file
77
substrate/abi/src/dex.rs
Normal file
@@ -0,0 +1,77 @@
|
||||
use sp_runtime::BoundedVec;
|
||||
|
||||
use serai_primitives::*;
|
||||
|
||||
type PoolId = Coin;
|
||||
type PoolCoinId = Coin;
|
||||
type MaxSwapPathLength = sp_core::ConstU32<3>;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum Call {
|
||||
add_liquidity {
|
||||
coin: Coin,
|
||||
coin_desired: SubstrateAmount,
|
||||
sri_desired: SubstrateAmount,
|
||||
coin_min: SubstrateAmount,
|
||||
sri_min: SubstrateAmount,
|
||||
mint_to: SeraiAddress,
|
||||
},
|
||||
remove_liquidity {
|
||||
coin: Coin,
|
||||
lp_token_burn: SubstrateAmount,
|
||||
coin_min_receive: SubstrateAmount,
|
||||
sri_min_receive: SubstrateAmount,
|
||||
withdraw_to: SeraiAddress,
|
||||
},
|
||||
swap_exact_tokens_for_tokens {
|
||||
path: BoundedVec<Coin, MaxSwapPathLength>,
|
||||
amount_in: SubstrateAmount,
|
||||
amount_out_min: SubstrateAmount,
|
||||
send_to: SeraiAddress,
|
||||
},
|
||||
swap_tokens_for_exact_tokens {
|
||||
path: BoundedVec<Coin, MaxSwapPathLength>,
|
||||
amount_out: SubstrateAmount,
|
||||
amount_in_max: SubstrateAmount,
|
||||
send_to: SeraiAddress,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum Event {
|
||||
PoolCreated {
|
||||
pool_id: PoolId,
|
||||
pool_account: SeraiAddress,
|
||||
lp_token: PoolCoinId,
|
||||
},
|
||||
|
||||
LiquidityAdded {
|
||||
who: SeraiAddress,
|
||||
mint_to: SeraiAddress,
|
||||
pool_id: PoolId,
|
||||
coin_amount: SubstrateAmount,
|
||||
sri_amount: SubstrateAmount,
|
||||
lp_token: PoolCoinId,
|
||||
lp_token_minted: SubstrateAmount,
|
||||
},
|
||||
|
||||
LiquidityRemoved {
|
||||
who: SeraiAddress,
|
||||
withdraw_to: SeraiAddress,
|
||||
pool_id: PoolId,
|
||||
coin_amount: SubstrateAmount,
|
||||
sri_amount: SubstrateAmount,
|
||||
lp_token: PoolCoinId,
|
||||
lp_token_burned: SubstrateAmount,
|
||||
},
|
||||
|
||||
SwapExecuted {
|
||||
who: SeraiAddress,
|
||||
send_to: SeraiAddress,
|
||||
path: BoundedVec<Coin, MaxSwapPathLength>,
|
||||
amount_in: SubstrateAmount,
|
||||
amount_out: SubstrateAmount,
|
||||
},
|
||||
}
|
||||
24
substrate/abi/src/grandpa.rs
Normal file
24
substrate/abi/src/grandpa.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
use sp_consensus_grandpa::EquivocationProof;
|
||||
|
||||
use serai_primitives::{BlockNumber, SeraiAddress};
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode)]
|
||||
pub struct ReportEquivocation {
|
||||
pub equivocation_proof: Box<EquivocationProof<[u8; 32], BlockNumber>>,
|
||||
pub key_owner_proof: (),
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode)]
|
||||
pub enum Call {
|
||||
report_equivocation(ReportEquivocation),
|
||||
report_equivocation_unsigned(ReportEquivocation),
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode)]
|
||||
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum Event {
|
||||
NewAuthorities { authority_set: Vec<(SeraiAddress, u64)> },
|
||||
Paused,
|
||||
Resumed,
|
||||
}
|
||||
20
substrate/abi/src/in_instructions.rs
Normal file
20
substrate/abi/src/in_instructions.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use serai_primitives::*;
|
||||
|
||||
pub use serai_in_instructions_primitives as primitives;
|
||||
use primitives::SignedBatch;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode)]
|
||||
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum Call {
|
||||
execute_batch { batch: SignedBatch },
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode)]
|
||||
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum Event {
|
||||
Batch { network: NetworkId, id: u32, block: BlockHash, instructions_hash: [u8; 32] },
|
||||
InstructionFailure { network: NetworkId, id: u32, index: u32 },
|
||||
Halt { network: NetworkId },
|
||||
}
|
||||
42
substrate/abi/src/lib.rs
Normal file
42
substrate/abi/src/lib.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
pub mod system;
|
||||
|
||||
pub mod timestamp;
|
||||
|
||||
pub mod coins;
|
||||
pub mod dex;
|
||||
|
||||
pub mod validator_sets;
|
||||
pub mod in_instructions;
|
||||
pub mod signals;
|
||||
|
||||
pub mod babe;
|
||||
pub mod grandpa;
|
||||
|
||||
pub use serai_primitives as primitives;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode)]
|
||||
pub enum Call {
|
||||
Timestamp(timestamp::Call),
|
||||
Coins(coins::Call),
|
||||
LiquidityTokens(coins::Call),
|
||||
Dex(dex::Call),
|
||||
ValidatorSets(validator_sets::Call),
|
||||
InInstructions(in_instructions::Call),
|
||||
Signals(signals::Call),
|
||||
Babe(babe::Call),
|
||||
Grandpa(grandpa::Call),
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode)]
|
||||
pub enum Event {
|
||||
System(system::Event),
|
||||
Coins(coins::Event),
|
||||
LiquidityTokens(coins::Event),
|
||||
Dex(dex::Event),
|
||||
ValidatorSets(validator_sets::Event),
|
||||
InInstructions(in_instructions::Event),
|
||||
Signals(signals::Event),
|
||||
Grandpa(grandpa::Event),
|
||||
}
|
||||
57
substrate/abi/src/signals.rs
Normal file
57
substrate/abi/src/signals.rs
Normal file
@@ -0,0 +1,57 @@
|
||||
use serai_primitives::{NetworkId, SeraiAddress};
|
||||
|
||||
use serai_validator_sets_primitives::ValidatorSet;
|
||||
|
||||
pub use serai_signals_primitives as primitives;
|
||||
use primitives::SignalId;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode)]
|
||||
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum Call {
|
||||
register_retirement_signal { in_favor_of: [u8; 32] },
|
||||
revoke_retirement_signal { retirement_signal_id: [u8; 32] },
|
||||
favor { signal_id: SignalId, for_network: NetworkId },
|
||||
revoke_favor { signal_id: SignalId, for_network: NetworkId },
|
||||
stand_against { signal_id: SignalId, for_network: NetworkId },
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode)]
|
||||
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum Event {
|
||||
RetirementSignalRegistered {
|
||||
signal_id: [u8; 32],
|
||||
in_favor_of: [u8; 32],
|
||||
registrant: SeraiAddress,
|
||||
},
|
||||
RetirementSignalRevoked {
|
||||
signal_id: [u8; 32],
|
||||
},
|
||||
SignalFavored {
|
||||
signal_id: SignalId,
|
||||
by: SeraiAddress,
|
||||
for_network: NetworkId,
|
||||
},
|
||||
SetInFavor {
|
||||
signal_id: SignalId,
|
||||
set: ValidatorSet,
|
||||
},
|
||||
RetirementSignalLockedIn {
|
||||
signal_id: [u8; 32],
|
||||
},
|
||||
SetNoLongerInFavor {
|
||||
signal_id: SignalId,
|
||||
set: ValidatorSet,
|
||||
},
|
||||
FavorRevoked {
|
||||
signal_id: SignalId,
|
||||
by: SeraiAddress,
|
||||
for_network: NetworkId,
|
||||
},
|
||||
AgainstSignal {
|
||||
signal_id: SignalId,
|
||||
who: SeraiAddress,
|
||||
for_network: NetworkId,
|
||||
},
|
||||
}
|
||||
8
substrate/abi/src/system.rs
Normal file
8
substrate/abi/src/system.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
use frame_support::dispatch::{DispatchInfo, DispatchError};
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum Event {
|
||||
ExtrinsicSuccess { dispatch_info: DispatchInfo },
|
||||
ExtrinsicFailed { dispatch_error: DispatchError, dispatch_info: DispatchInfo },
|
||||
}
|
||||
6
substrate/abi/src/timestamp.rs
Normal file
6
substrate/abi/src/timestamp.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode)]
|
||||
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum Call {
|
||||
set { now: u64 },
|
||||
}
|
||||
68
substrate/abi/src/validator_sets.rs
Normal file
68
substrate/abi/src/validator_sets.rs
Normal file
@@ -0,0 +1,68 @@
|
||||
pub use serai_validator_sets_primitives as primitives;
|
||||
|
||||
use serai_primitives::*;
|
||||
use serai_validator_sets_primitives::*;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum Call {
|
||||
set_keys {
|
||||
network: NetworkId,
|
||||
key_pair: KeyPair,
|
||||
signature: Signature,
|
||||
},
|
||||
remove_participant {
|
||||
network: NetworkId,
|
||||
to_remove: SeraiAddress,
|
||||
signers: Vec<SeraiAddress>,
|
||||
signature: Signature,
|
||||
},
|
||||
allocate {
|
||||
network: NetworkId,
|
||||
amount: Amount,
|
||||
},
|
||||
deallocate {
|
||||
network: NetworkId,
|
||||
amount: Amount,
|
||||
},
|
||||
claim_deallocation {
|
||||
network: NetworkId,
|
||||
session: Session,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode)]
|
||||
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum Event {
|
||||
NewSet {
|
||||
set: ValidatorSet,
|
||||
},
|
||||
ParticipantRemoved {
|
||||
set: ValidatorSet,
|
||||
removed: SeraiAddress,
|
||||
},
|
||||
KeyGen {
|
||||
set: ValidatorSet,
|
||||
key_pair: KeyPair,
|
||||
},
|
||||
AllocationIncreased {
|
||||
validator: SeraiAddress,
|
||||
network: NetworkId,
|
||||
amount: Amount,
|
||||
},
|
||||
AllocationDecreased {
|
||||
validator: SeraiAddress,
|
||||
network: NetworkId,
|
||||
amount: Amount,
|
||||
delayed_until: Option<Session>,
|
||||
},
|
||||
DeallocationClaimed {
|
||||
validator: SeraiAddress,
|
||||
network: NetworkId,
|
||||
session: Session,
|
||||
},
|
||||
SetRetired {
|
||||
set: ValidatorSet,
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user