12 Commits

Author SHA1 Message Date
akildemir
08d258a16f Merge branch 'develop' of https://github.com/serai-dex/serai into set-correct-swap-fee 2024-10-18 09:51:14 +03:00
akildemir
be46ac3ee1 bug fixes 2024-10-18 09:50:49 +03:00
Luke Parker
f3d20e60b3 Remove --no-deps from docs build to fix linking to deps 2024-10-17 21:14:13 -04:00
Luke Parker
dafba81b40 Add wasm32-unknown-unknown target to docs build 2024-10-17 18:45:34 -04:00
Luke Parker
91f8ec53d9 Add build-dependencies into docs build 2024-10-17 18:29:47 -04:00
Luke Parker
fc9a4a08b8 Correct rust-docs component name 2024-10-17 18:12:35 -04:00
Luke Parker
45fadb21ac Correct paths in pages.yml 2024-10-17 18:05:54 -04:00
Luke Parker
28619fbee1 CI fixes
Mainly corrects for https://github.com/alloy-rs/alloy/issues/1510 yet also
corrects a missing machete ignore.
2024-10-17 18:02:57 -04:00
Luke Parker
bbe014c3a7 Have CI build with doc_auto_cfg 2024-10-17 17:48:14 -04:00
Luke Parker
fb3fadb3d3 Publish Rust docs to GH pages 2024-10-17 17:18:58 -04:00
Luke Parker
f481d20773 Correct licensing for .github 2024-10-17 17:17:36 -04:00
Luke Parker
599b2dec8f cargo update
Should fix the recent CI failures re: Ethereum as well.
2024-10-09 00:39:34 -04:00
19 changed files with 477 additions and 402 deletions

View File

@@ -1,6 +1,7 @@
# MIT License # MIT License
# #
# Copyright (c) 2022 just-the-docs # Copyright (c) 2022 just-the-docs
# Copyright (c) 2022-2024 Luke Parker
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
@@ -20,31 +21,21 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE. # SOFTWARE.
# This workflow uses actions that are not certified by GitHub. name: Deploy Rust docs and Jekyll site to Pages
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# Sample workflow for building and deploying a Jekyll site to GitHub Pages
name: Deploy Jekyll site to Pages
on: on:
push: push:
branches: branches:
- "develop" - "develop"
paths:
- "docs/**"
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch: workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions: permissions:
contents: read contents: read
pages: write pages: write
id-token: write id-token: write
# Allow one concurrent deployment # Only allow one concurrent deployment
concurrency: concurrency:
group: "pages" group: "pages"
cancel-in-progress: true cancel-in-progress: true
@@ -53,9 +44,6 @@ jobs:
# Build job # Build job
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
defaults:
run:
working-directory: docs
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
@@ -69,11 +57,24 @@ jobs:
id: pages id: pages
uses: actions/configure-pages@v3 uses: actions/configure-pages@v3
- name: Build with Jekyll - name: Build with Jekyll
run: bundle exec jekyll build --baseurl "${{ steps.pages.outputs.base_path }}" run: cd ${{ github.workspace }}/docs && bundle exec jekyll build --baseurl "${{ steps.pages.outputs.base_path }}"
env: env:
JEKYLL_ENV: production JEKYLL_ENV: production
- name: Get nightly version to use
id: nightly
shell: bash
run: echo "version=$(cat .github/nightly-version)" >> $GITHUB_OUTPUT
- name: Build Dependencies
uses: ./.github/actions/build-dependencies
- name: Buld Rust docs
run: |
rustup toolchain install ${{ steps.nightly.outputs.version }} --profile minimal -t wasm32-unknown-unknown -c rust-docs
RUSTDOCFLAGS="--cfg docsrs" cargo +${{ steps.nightly.outputs.version }} doc --workspace --all-features
mv target/doc docs/_site/rust
- name: Upload artifact - name: Upload artifact
uses: actions/upload-pages-artifact@v1 uses: actions/upload-pages-artifact@v3
with: with:
path: "docs/_site/" path: "docs/_site/"
@@ -87,4 +88,4 @@ jobs:
steps: steps:
- name: Deploy to GitHub Pages - name: Deploy to GitHub Pages
id: deployment id: deployment
uses: actions/deploy-pages@v2 uses: actions/deploy-pages@v4

704
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -141,6 +141,9 @@ parking_lot = { path = "patches/parking_lot" }
zstd = { path = "patches/zstd" } zstd = { path = "patches/zstd" }
# Needed for WAL compression # Needed for WAL compression
rocksdb = { path = "patches/rocksdb" } rocksdb = { path = "patches/rocksdb" }
# 1.0.1 was yanked due to a breaking change (an extra field)
# 2.0 has fewer dependencies and still works within our tree
tiny-bip39 = { path = "patches/tiny-bip39" }
# is-terminal now has an std-based solution with an equivalent API # is-terminal now has an std-based solution with an equivalent API
is-terminal = { path = "patches/is-terminal" } is-terminal = { path = "patches/is-terminal" }
@@ -155,9 +158,6 @@ matches = { path = "patches/matches" }
option-ext = { path = "patches/option-ext" } option-ext = { path = "patches/option-ext" }
directories-next = { path = "patches/directories-next" } directories-next = { path = "patches/directories-next" }
# https://github.com/alloy-rs/core/issues/717
alloy-sol-type-parser = { git = "https://github.com/alloy-rs/core", rev = "446b9d2fbce12b88456152170709a3eaac929af0" }
[workspace.lints.clippy] [workspace.lints.clippy]
unwrap_or_default = "allow" unwrap_or_default = "allow"
borrow_as_ptr = "deny" borrow_as_ptr = "deny"

View File

@@ -92,7 +92,10 @@ license-files = [
multiple-versions = "warn" multiple-versions = "warn"
wildcards = "warn" wildcards = "warn"
highlight = "all" highlight = "all"
deny = [ { name = "serde_derive", version = ">=1.0.172, <1.0.185" } ] deny = [
{ name = "serde_derive", version = ">=1.0.172, <1.0.185" },
{ name = "hashbrown", version = ">=0.15" },
]
[sources] [sources]
unknown-registry = "deny" unknown-registry = "deny"
@@ -102,5 +105,4 @@ allow-git = [
"https://github.com/rust-lang-nursery/lazy-static.rs", "https://github.com/rust-lang-nursery/lazy-static.rs",
"https://github.com/serai-dex/substrate-bip39", "https://github.com/serai-dex/substrate-bip39",
"https://github.com/serai-dex/substrate", "https://github.com/serai-dex/substrate",
"https://github.com/alloy-rs/core",
] ]

View File

@@ -29,21 +29,21 @@ frost = { package = "modular-frost", path = "../../crypto/frost", default-featur
alloy-core = { version = "0.8", default-features = false } alloy-core = { version = "0.8", default-features = false }
alloy-sol-types = { version = "0.8", default-features = false, features = ["json"] } alloy-sol-types = { version = "0.8", default-features = false, features = ["json"] }
alloy-consensus = { version = "0.3", default-features = false, features = ["k256"] } alloy-consensus = { version = "0.4", default-features = false, features = ["k256"] }
alloy-network = { version = "0.3", default-features = false } alloy-network = { version = "0.4", default-features = false }
alloy-rpc-types-eth = { version = "0.3", default-features = false } alloy-rpc-types-eth = { version = "0.4", default-features = false }
alloy-rpc-client = { version = "0.3", default-features = false } alloy-rpc-client = { version = "0.4", default-features = false }
alloy-simple-request-transport = { path = "./alloy-simple-request-transport", default-features = false } alloy-simple-request-transport = { path = "./alloy-simple-request-transport", default-features = false }
alloy-provider = { version = "0.3", default-features = false } alloy-provider = { version = "0.4", default-features = false }
alloy-node-bindings = { version = "0.3", default-features = false, optional = true } alloy-node-bindings = { version = "0.4", default-features = false, optional = true }
[dev-dependencies] [dev-dependencies]
frost = { package = "modular-frost", path = "../../crypto/frost", default-features = false, features = ["tests"] } frost = { package = "modular-frost", path = "../../crypto/frost", default-features = false, features = ["tests"] }
tokio = { version = "1", features = ["macros"] } tokio = { version = "1", features = ["macros"] }
alloy-node-bindings = { version = "0.3", default-features = false } alloy-node-bindings = { version = "0.4", default-features = false }
[features] [features]
tests = ["alloy-node-bindings", "frost/tests"] tests = ["alloy-node-bindings", "frost/tests"]

View File

@@ -16,13 +16,13 @@ rustdoc-args = ["--cfg", "docsrs"]
workspace = true workspace = true
[dependencies] [dependencies]
tower = "0.4" tower = "0.5"
serde_json = { version = "1", default-features = false } serde_json = { version = "1", default-features = false }
simple-request = { path = "../../../common/request", default-features = false } simple-request = { path = "../../../common/request", default-features = false }
alloy-json-rpc = { version = "0.3", default-features = false } alloy-json-rpc = { version = "0.4", default-features = false }
alloy-transport = { version = "0.3", default-features = false } alloy-transport = { version = "0.4", default-features = false }
[features] [features]
default = ["tls"] default = ["tls"]

View File

@@ -39,7 +39,7 @@ impl Deployer {
nonce: 0, nonce: 0,
gas_price: 100_000_000_000u128, gas_price: 100_000_000_000u128,
// TODO: Use a more accurate gas limit // TODO: Use a more accurate gas limit
gas_limit: 1_000_000u128, gas_limit: 1_000_000,
to: TxKind::Create, to: TxKind::Create,
value: U256::ZERO, value: U256::ZERO,
input: bytecode, input: bytecode,

View File

@@ -226,7 +226,7 @@ impl Router {
to: TxKind::Call(self.1), to: TxKind::Call(self.1),
input: abi::executeCall::new((outs.to_vec(), sig.into())).abi_encode().into(), input: abi::executeCall::new((outs.to_vec(), sig.into())).abi_encode().into(),
// TODO // TODO
gas_limit: 100_000 + ((200_000 + 10_000) * u128::try_from(outs.len()).unwrap()), gas_limit: 100_000 + ((200_000 + 10_000) * u64::try_from(outs.len()).unwrap()),
..Default::default() ..Default::default()
} }
} }

View File

@@ -0,0 +1,24 @@
[package]
name = "tiny-bip39"
version = "1.0.2"
description = "tiny-bip39 which patches to the latest update"
license = "MIT"
repository = "https://github.com/serai-dex/serai/tree/develop/patches/tiny-bip39"
authors = ["Luke Parker <lukeparker5132@gmail.com>"]
keywords = []
edition = "2021"
rust-version = "1.70"
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[package.metadata.cargo-machete]
ignored = ["tiny-bip39"]
[lib]
name = "bip39"
path = "src/lib.rs"
[dependencies]
tiny-bip39 = "2"

View File

@@ -0,0 +1 @@
pub use bip39::*;

View File

@@ -764,7 +764,7 @@ impl<D: Db> Network for Ethereum<D> {
completion.signature(), completion.signature(),
), ),
}; };
tx.gas_limit = 1_000_000u64.into(); tx.gas_limit = 1_000_000u64;
tx.gas_price = 1_000_000_000u64.into(); tx.gas_price = 1_000_000_000u64.into();
let tx = ethereum_serai::crypto::deterministically_sign(&tx); let tx = ethereum_serai::crypto::deterministically_sign(&tx);
@@ -905,7 +905,7 @@ impl<D: Db> Network for Ethereum<D> {
chain_id: None, chain_id: None,
nonce: 0, nonce: 0,
gas_price: 1_000_000_000u128, gas_price: 1_000_000_000u128,
gas_limit: 200_000u128, gas_limit: 200_000,
to: ethereum_serai::alloy::primitives::TxKind::Call(send_to.0.into()), to: ethereum_serai::alloy::primitives::TxKind::Call(send_to.0.into()),
// 1 ETH // 1 ETH
value, value,
@@ -918,13 +918,17 @@ impl<D: Db> Network for Ethereum<D> {
.into(), .into(),
}; };
use ethereum_serai::alloy::{primitives::Signature, consensus::SignableTransaction}; use ethereum_serai::alloy::{
primitives::{Parity, Signature},
consensus::SignableTransaction,
};
let sig = k256::ecdsa::SigningKey::from(k256::elliptic_curve::NonZeroScalar::new(key).unwrap()) let sig = k256::ecdsa::SigningKey::from(k256::elliptic_curve::NonZeroScalar::new(key).unwrap())
.sign_prehash_recoverable(tx.signature_hash().as_ref()) .sign_prehash_recoverable(tx.signature_hash().as_ref())
.unwrap(); .unwrap();
let mut bytes = vec![]; let mut bytes = vec![];
tx.encode_with_signature_fields(&Signature::from(sig), &mut bytes); let parity = Parity::NonEip155(Parity::from(sig.1).y_parity());
tx.encode_with_signature_fields(&Signature::from(sig).with_parity(parity), &mut bytes);
let pending_tx = self.provider.send_raw_transaction(&bytes).await.ok().unwrap(); let pending_tx = self.provider.send_raw_transaction(&bytes).await.ok().unwrap();
// Mine an epoch containing this TX // Mine an epoch containing this TX

View File

@@ -396,7 +396,7 @@ mod ethereum {
let deployer = Deployer::new(provider.clone()).await.unwrap().unwrap(); let deployer = Deployer::new(provider.clone()).await.unwrap().unwrap();
let mut tx = deployer.deploy_router(&key); let mut tx = deployer.deploy_router(&key);
tx.gas_limit = 1_000_000u64.into(); tx.gas_limit = 1_000_000u64;
tx.gas_price = 1_000_000_000u64.into(); tx.gas_price = 1_000_000_000u64.into();
let tx = ethereum_serai::crypto::deterministically_sign(&tx); let tx = ethereum_serai::crypto::deterministically_sign(&tx);

View File

@@ -116,7 +116,7 @@ serai_test!(
send_to: pair.public().into(), send_to: pair.public().into(),
path, path,
amount_in: amount_in.0, amount_in: amount_in.0,
amount_out: 16599866399465 amount_out: 16611018363939
}] }]
); );
@@ -144,7 +144,7 @@ serai_test!(
send_to: pair.public().into(), send_to: pair.public().into(),
path, path,
amount_in: amount_in.0, amount_in: amount_in.0,
amount_out: 17166744497317 amount_out: 17207430166736
}] }]
); );
}) })
@@ -210,7 +210,7 @@ serai_test!(
send_to: pair.public().into(), send_to: pair.public().into(),
path, path,
amount_in: amount_in.0, amount_in: amount_in.0,
amount_out: 12406166091918, amount_out: 12421816676180,
}] }]
); );
}) })
@@ -264,8 +264,8 @@ serai_test!(
mint_to: pair.public().into(), mint_to: pair.public().into(),
pool_id: coin, pool_id: coin,
coin_amount: 10_000_000_000_000, // half of sent amount coin_amount: 10_000_000_000_000, // half of sent amount
sri_amount: 111669009482, sri_amount: 111631562261,
lp_token_minted: 1055147701082 lp_token_minted: 1055499886564
}] }]
); );
}) })
@@ -349,7 +349,7 @@ serai_test!(
send_to: IN_INSTRUCTION_EXECUTOR, send_to: IN_INSTRUCTION_EXECUTOR,
path, path,
amount_in: 200_000_000_000_000, amount_in: 200_000_000_000_000,
amount_out: 18933113030 amount_out: 18970355346
}] }]
); );
} }
@@ -388,7 +388,7 @@ serai_test!(
send_to: out_address.as_native().unwrap(), send_to: out_address.as_native().unwrap(),
path, path,
amount_in: 200_000_000_000, amount_in: 200_000_000_000,
amount_out: 1473437558561637 amount_out: 1482888317565764
}] }]
); );
} }
@@ -426,7 +426,7 @@ serai_test!(
send_to: out_address.as_native().unwrap(), send_to: out_address.as_native().unwrap(),
path, path,
amount_in: 100_000_000_000_000, amount_in: 100_000_000_000_000,
amount_out: 1751430396 amount_out: 1755477054
}] }]
); );
} }

View File

@@ -992,32 +992,30 @@ pub mod pallet {
let (reserve_in, reserve_out) = Self::get_reserves(coin1, coin2)?; let (reserve_in, reserve_out) = Self::get_reserves(coin1, coin2)?;
let prev_amount = amounts.last().expect("Always has at least one element"); let prev_amount = amounts.last().expect("Always has at least one element");
let amount_out = Self::get_amount_out(*prev_amount, reserve_in, reserve_out)?; let amount_out = Self::get_amount_out(*prev_amount, reserve_in, reserve_out)?;
amounts.push(amount_out);
// now that we got swap fee from the user, burn half of it. // now that we got swap fee from the user, burn half of it.
Self::burn_half_of_swap_fee(Self::get_pool_id(*coin1, *coin2)?, *coin1)?; Self::burn_half_of_swap_fee(Self::get_pool_id(*coin1, *coin2)?, *coin1, *prev_amount)?;
amounts.push(amount_out);
} }
} }
Ok(amounts) Ok(amounts)
} }
fn burn_half_of_swap_fee(pool: PoolId, coin: Coin) -> Result<(), DispatchError> { fn burn_half_of_swap_fee(
pool: PoolId,
coin: Coin,
amount: SubstrateAmount,
) -> Result<(), DispatchError> {
let pool_account = Self::get_pool_account(pool); let pool_account = Self::get_pool_account(pool);
let origin = RawOrigin::Signed(pool_account);
let balance = Coins::<T>::balance(pool_account, coin).0; // half of the taken fee
let burn_percent = let burn_percent = T::LPFee::get().checked_div(2).ok_or(Error::<T>::Overflow)?;
HigherPrecisionBalance::from(T::LPFee::get()).checked_div(2).ok_or(Error::<T>::Overflow)?; let burn_amount = Self::mul_div(amount, burn_percent.into(), 1000)?;
let burn_amount = HigherPrecisionBalance::from(balance)
.checked_mul(burn_percent)
.ok_or(Error::<T>::Overflow)?
.checked_div(1000)
.ok_or(Error::<T>::Overflow)?;
Coins::<T>::burn( Coins::<T>::burn(
origin.into(), RawOrigin::Signed(pool_account).into(),
Balance { coin, amount: Amount(burn_amount.try_into().map_err(|_| Error::<T>::Overflow)?) }, Balance { coin, amount: Amount(burn_amount.try_into().map_err(|_| Error::<T>::Overflow)?) },
)?; )?;
Ok(()) Ok(())

View File

@@ -1157,10 +1157,10 @@ fn swap_exact_tokens_for_tokens_in_multi_hops() {
)); ));
// burn half of the taken fees // burn half of the taken fees
let burn_amount = get_burn_amount(liquidity2); let burn_amount = get_burn_amount(input_amount);
liquidity2 -= burn_amount; liquidity2 -= burn_amount;
let burn_amount = get_burn_amount(liquidity1_pool2); let burn_amount = get_burn_amount(expect_out2);
liquidity1_pool2 -= burn_amount; liquidity1_pool2 -= burn_amount;
let pool_id1 = Dex::get_pool_id(coin1, coin2).unwrap(); let pool_id1 = Dex::get_pool_id(coin1, coin2).unwrap();

View File

@@ -215,8 +215,8 @@ impl coins::Config<coins::Instance1> for Runtime {
impl dex::Config for Runtime { impl dex::Config for Runtime {
type RuntimeEvent = RuntimeEvent; type RuntimeEvent = RuntimeEvent;
// 0.6% in total but only half will go to LPs(0.3%) other half to be burned. // 0.5% in total but only half will go to LPs(0.25%) other half to be burned.
type LPFee = ConstU32<6>; type LPFee = ConstU32<5>;
type MintMinLiquidity = ConstU64<10000>; type MintMinLiquidity = ConstU64<10000>;
type MaxSwapPathLength = ConstU32<3>; // coin1 -> SRI -> coin2 type MaxSwapPathLength = ConstU32<3>; // coin1 -> SRI -> coin2

View File

@@ -248,7 +248,7 @@ impl Coordinator {
provider provider
.raw_request::<_, ()>( .raw_request::<_, ()>(
"anvil_setBalance".into(), "anvil_setBalance".into(),
[signer.to_string(), (tx.gas_limit * tx.gas_price).to_string()], [signer.to_string(), (u128::from(tx.gas_limit) * tx.gas_price).to_string()],
) )
.await .await
.unwrap(); .unwrap();

View File

@@ -299,7 +299,7 @@ impl Wallet {
use std::sync::Arc; use std::sync::Arc;
use ethereum_serai::{ use ethereum_serai::{
alloy::{ alloy::{
primitives::{U256, Signature, TxKind}, primitives::{U256, Parity, Signature, TxKind},
sol_types::SolCall, sol_types::SolCall,
simple_request_transport::SimpleRequest, simple_request_transport::SimpleRequest,
consensus::{TxLegacy, SignableTransaction}, consensus::{TxLegacy, SignableTransaction},
@@ -343,13 +343,13 @@ impl Wallet {
provider provider
.raw_request::<_, ()>( .raw_request::<_, ()>(
"anvil_setBalance".into(), "anvil_setBalance".into(),
[signer.to_string(), (tx.gas_limit * tx.gas_price).to_string()], [signer.to_string(), (u128::from(tx.gas_limit) * tx.gas_price).to_string()],
) )
.await .await
.unwrap(); .unwrap();
let mut bytes = vec![]; let mut bytes = vec![];
tx.encode_with_signature_fields(&Signature::from(sig), &mut bytes); tx.encode_with_signature_fields(&sig, &mut bytes);
let _ = provider.send_raw_transaction(&bytes).await.unwrap(); let _ = provider.send_raw_transaction(&bytes).await.unwrap();
provider.raw_request::<_, ()>("anvil_mine".into(), [96]).await.unwrap(); provider.raw_request::<_, ()>("anvil_mine".into(), [96]).await.unwrap();
@@ -364,7 +364,7 @@ impl Wallet {
chain_id: None, chain_id: None,
nonce: *nonce, nonce: *nonce,
gas_price: 1_000_000_000u128, gas_price: 1_000_000_000u128,
gas_limit: 200_000u128, gas_limit: 200_000,
to: TxKind::Call(router_addr.into()), to: TxKind::Call(router_addr.into()),
// 1 ETH // 1 ETH
value: one_eth, value: one_eth,
@@ -389,7 +389,8 @@ impl Wallet {
.unwrap(); .unwrap();
let mut bytes = vec![]; let mut bytes = vec![];
tx.encode_with_signature_fields(&Signature::from(sig), &mut bytes); let parity = Parity::NonEip155(Parity::from(sig.1).y_parity());
tx.encode_with_signature_fields(&Signature::from(sig).with_parity(parity), &mut bytes);
// We drop the bottom 10 decimals // We drop the bottom 10 decimals
( (