Skip to content

Commit

Permalink
build script
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Nov 16, 2023
1 parent 1ea32ce commit 5737d52
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 76 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
on:
push:
tags:
- "*.*.*"
jobs:
publish:
runs-on: "ubuntu-latest"
permissions:
id-token: "write"
contents: "read"
steps:
- uses: "actions/checkout@v3"
- uses: "DeterminateSystems/nix-installer-action@main"
- uses: "DeterminateSystems/flakehub-push@main"
with:
visibility: "public"
17 changes: 17 additions & 0 deletions flake.lock

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

164 changes: 98 additions & 66 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,85 +12,117 @@
inputs.nixpkgs.follows = "nixpkgs";
};
cosmos = {
url =
"github:informalsystems/cosmos.nix";
url = "github:informalsystems/cosmos.nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.rust-overlay.follows = "rust-overlay";
};

devour-flake = {
url = "github:srid/devour-flake";
flake = false;
};
};

outputs = inputs@{ flake-parts, self, crane, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
outputs = inputs @ {
flake-parts,
self,
crane,
devour-flake,
...
}:
flake-parts.lib.mkFlake {inherit inputs;} {
imports = [
];
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
perSystem = { config, self', inputs', pkgs, system, ... }:

let
craneLib = crane.lib.${system};
rust-src = craneLib.cleanCargoSource (craneLib.path ./.);
rust-toolchain =
pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
rust = (self.inputs.crane.mkLib pkgs).overrideToolchain
rust-toolchain;
makeCosmwasmContract = name: rust: std-config:
let binaryName = "${builtins.replaceStrings [ "-" ] [ "_" ] name}.wasm";
in rust.buildPackage ({
src = rust-src;
pnameSuffix = "-${name}";
nativeBuildInputs = [
pkgs.binaryen
self.inputs.cosmos.packages.${system}.cosmwasm-check
];
pname = name;
cargoBuildCommand =
"cargo build --target wasm32-unknown-unknown --profile release --package ${name} ${std-config}";
RUSTFLAGS = "-C link-arg=-s";
installPhaseCommand = ''
mkdir --parents $out/lib
# from CosmWasm/rust-optimizer
# --signext-lowering is needed to support blockchains runnning CosmWasm < 1.3. It can be removed eventually
wasm-opt target/wasm32-unknown-unknown/release/${binaryName} -o $out/lib/${binaryName} -Os --signext-lowering
cosmwasm-check $out/lib/${binaryName}
'';
});

cw-mantis-order = makeCosmwasmContract "cw-mantis-order" rust "--no-default-features";
systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"];
perSystem = {
config,
self',
inputs',
pkgs,
system,
...
}: let
craneLib = crane.lib.${system};
rust-src = pkgs.lib.cleanSourceWith {
filter = pkgs.nix-gitignore.gitignoreFilterPure (name: _type: !(pkgs.lib.strings.hasSuffix ".nix" name)) [./.gitignore] ./.;
src = craneLib.cleanCargoSource (craneLib.path ./.);
};
devour-flake = pkgs.callPackage inputs.devour-flake {};
rust-toolchain =
pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
rust =
(self.inputs.crane.mkLib pkgs).overrideToolchain
rust-toolchain;
makeCosmwasmContract = name: rust: std-config: let
binaryName = "${builtins.replaceStrings ["-"] ["_"] name}.wasm";
in
{
_module.args.pkgs = import self.inputs.nixpkgs {
inherit system;
overlays = with self.inputs; [
rust-overlay.overlays.default
rust.buildPackage {
src = rust-src;
pnameSuffix = "-${name}";
nativeBuildInputs = [
pkgs.binaryen
self.inputs.cosmos.packages.${system}.cosmwasm-check
];
pname = name;
cargoBuildCommand = "cargo build --target wasm32-unknown-unknown --profile release --package ${name} ${std-config}";
RUSTFLAGS = "-C link-arg=-s";
installPhaseCommand = ''
mkdir --parents $out/lib
# from CosmWasm/rust-optimizer
# --signext-lowering is needed to support blockchains runnning CosmWasm < 1.3. It can be removed eventually
wasm-opt target/wasm32-unknown-unknown/release/${binaryName} -o $out/lib/${binaryName} -Os --signext-lowering
cosmwasm-check $out/lib/${binaryName}
'';
};
devShells.default =
let
python-packages = ps: with ps; [ numpy cvxpy wheel virtualenv ];
python = pkgs.python3.withPackages python-packages;
in
pkgs.mkShell {
VIRTUALENV_PYTHON = "${python}/bin/python3.11";
VIRTUAL_ENV = 1;
nativeBuildInputs = [ python ];
buildInputs = [
python
pkgs.virtualenv
pkgs.conda
pkgs.pyo3-pack
rust.cargo
rust.rustc
];
};
packages = {
inherit cw-mantis-order;
default = rust.buildPackage {
src = rust-src;
pname = "mantis-node";
name = "mantis-node";

};
cw-mantis-order = makeCosmwasmContract "cw-mantis-order" rust "--no-default-features";
in {
_module.args.pkgs = import self.inputs.nixpkgs {
inherit system;
overlays = with self.inputs; [
rust-overlay.overlays.default
];
};
devShells.default = let
python-packages = ps: with ps; [numpy cvxpy wheel virtualenv];
python = pkgs.python3.withPackages python-packages;
in
pkgs.mkShell {
VIRTUALENV_PYTHON = "${python}/bin/python3.11";
VIRTUAL_ENV = 1;
nativeBuildInputs = [python];
buildInputs = [
python
devour-flake
pkgs.virtualenv
pkgs.conda
pkgs.pyo3-pack
rust.cargo
rust.rustc
devour-flake
];
};
formatter = pkgs.alejandra;
packages = {
inherit cw-mantis-order;
default = rust.buildPackage {
src = rust-src;
pname = "mantis-node";
name = "mantis-node";
};
ci = pkgs.writeShellApplication {
name = "nix-build-all";
runtimeInputs = [
pkgs.nix
devour-flake
];
text = ''
nix flake lock --no-update-lock-file
devour-flake . "$@"
'';
};
};
};
};
}
7 changes: 6 additions & 1 deletion mantis/node/src/bin/mantis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ async fn simulate_order(write_client: &mut WriteClient, order_contract: String,
/// gets data from chain pools/fees on osmosis and neutron
/// gets CVM routing data
/// uses cfmm algorithm
async fn solve(read: &mut ReadClient, write: WriteClient, order_contract: String, cvm_contract: String) {
async fn solve(
read: &mut ReadClient,
write: WriteClient,
order_contract: String,
cvm_contract: String,
) {
let query = cw_mantis_order::QueryMsg::GetAllOrders {};
let orders_request = QuerySmartContractStateRequest {
address: order_contract.clone(),
Expand Down
3 changes: 1 addition & 2 deletions mantis/node/src/bin/simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {
value: orders.collect(),
};
orders.print();

/// solves nothing as no really overlap of orders
let mut solution = Solution::new(orders.value.clone());
solution = solution.match_orders(Price::new_float(1.0));
Expand All @@ -23,7 +23,6 @@ fn main() {
/// finds maximal volume price
let optimal_price = orders.compute_optimal_price(50);


let mut solution = Solution::new(orders.value.clone());
solution = solution.match_orders(optimal_price);
solution.print();
Expand Down
2 changes: 1 addition & 1 deletion mantis/node/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod mantis;
pub mod prelude;
pub mod solver;
pub mod mantis;
4 changes: 2 additions & 2 deletions mantis/node/src/mantis/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct MantisArgs {
/// CVM contract on Centauri
#[arg(long)]
pub cvm_contract: String,

/// Order contract on Centauri
#[arg(long)]
pub order_contract: String,
Expand All @@ -34,4 +34,4 @@ impl MantisArgs {
let args = Self::parse();
args
}
}
}
2 changes: 1 addition & 1 deletion mantis/node/src/mantis/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod args;
pub mod cosmos;
pub mod cosmos;
2 changes: 1 addition & 1 deletion mantis/node/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ pub use std::collections::HashMap;
pub use std::fmt::format;
pub use std::fmt::Debug;
pub use std::str::FromStr;
pub use tuples::*;
pub use tuples::*;
2 changes: 1 addition & 1 deletion mantis/node/src/solver/orderbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,6 @@ impl<Id: Copy + PartialEq + Debug> OrderList<Id> {
}
order.fill(order.amount_in, price);
filled.0 += order.amount_in;
}
}
}
}
1 change: 0 additions & 1 deletion result

This file was deleted.

0 comments on commit 5737d52

Please sign in to comment.