Tokens pallet (#243)

* Use Monero-compatible additional TX keys

This still sends a fingerprinting flare up if you send to a subaddress which
needs to be fixed. Despite that, Monero no should no longer fail to scan TXs
from monero-serai regarding additional keys.

Previously it failed becuase we supplied one key as THE key, and n-1 as
additional. Monero expects n for additional.

This does correctly select when to use THE key versus when to use the additional
key when sending. That removes the ability for recipients to fingerprint
monero-serai by receiving to a standard address yet needing to use an additional
key.

* Add tokens_primitives

Moves OutInstruction from in-instructions.

Turns Destination into OutInstruction.

* Correct in-instructions DispatchClass

* Add initial tokens pallet

* Don't allow pallet addresses to equal identity

* Add support for InInstruction::transfer

Requires a cargo update due to modifications made to serai-dex/substrate.

Successfully mints a token to a SeraiAddress.

* Bind InInstructions to an amount

* Add a call filter to the runtime

Prevents worrying about calls to the assets pallet/generally tightens things
up.

* Restore Destination

It was meged into OutInstruction, yet it didn't make sense for OutInstruction
to contain a SeraiAddress.

Also deletes the excessively dated Scenarios doc.

* Split PublicKey/SeraiAddress

Lets us define a custom Display/ToString for SeraiAddress.

Also resolves an oddity where PublicKey would be encoded as String, not
[u8; 32].

* Test burning tokens/retrieving OutInstructions

Modularizes processor_coinUpdates into a shared testing utility.

* Misc lint

* Don't use PolkadotExtrinsicParams
This commit is contained in:
Luke Parker
2023-01-28 01:47:13 -05:00
committed by GitHub
parent f12cc2cca6
commit 2ace339975
39 changed files with 1213 additions and 594 deletions

View File

@@ -4,16 +4,18 @@ use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
use sp_core::{ConstU32, bounded::BoundedVec};
use serai_primitives::{Coin, Amount, SeraiAddress, ExternalAddress, Data};
use serai_primitives::{SeraiAddress, Coin, Amount};
use tokens_primitives::OutInstruction;
use crate::{MAX_DATA_LEN, ExternalAddress, RefundableInInstruction, InInstruction, OutInstruction};
use crate::RefundableInInstruction;
#[cfg(feature = "std")]
use crate::InInstruction;
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub enum Shorthand {
Raw(BoundedVec<u8, ConstU32<{ MAX_DATA_LEN }>>),
Raw(Data),
Swap {
origin: Option<ExternalAddress>,
coin: Coin,
@@ -29,9 +31,10 @@ pub enum Shorthand {
}
impl Shorthand {
#[cfg(feature = "std")]
pub fn transfer(origin: Option<ExternalAddress>, address: SeraiAddress) -> Option<Self> {
Some(Self::Raw(
BoundedVec::try_from(
Data::new(
(RefundableInInstruction { origin, instruction: InInstruction::Transfer(address) })
.encode(),
)
@@ -45,7 +48,7 @@ impl TryFrom<Shorthand> for RefundableInInstruction {
fn try_from(shorthand: Shorthand) -> Result<RefundableInInstruction, &'static str> {
Ok(match shorthand {
Shorthand::Raw(raw) => {
RefundableInInstruction::decode(&mut raw.as_ref()).map_err(|_| "invalid raw instruction")?
RefundableInInstruction::decode(&mut raw.data()).map_err(|_| "invalid raw instruction")?
}
Shorthand::Swap { .. } => todo!(),
Shorthand::AddLiquidity { .. } => todo!(),