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

V0.2 dev #63

Merged
merged 30 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ba54d3e
wip: add base idea for state and handlers
willyrgf Oct 11, 2023
ca3185f
remove target dir
willyrgf Oct 11, 2023
ae02b6c
add custom errors for state with recoverability tag
willyrgf Oct 11, 2023
f2ec279
add generic context input and output for state handlers
willyrgf Oct 12, 2023
a07f8d5
refactor context to enforce read and write
willyrgf Oct 12, 2023
f791495
break state module into minor submodules
willyrgf Oct 13, 2023
c3bbe65
add dependency for state to enable safe replays for operations
willyrgf Oct 13, 2023
8d84990
generalize context for states and add state machine execution
willyrgf Oct 14, 2023
8d3ca43
add state wrapper to all impls of states handlers and state machine test
willyrgf Oct 16, 2023
7debcc0
breakdown state_machine execution and add transition
willyrgf Oct 16, 2023
d80d242
add mfm_machine_macros with proc macros for state config trait requir…
willyrgf Oct 16, 2023
e083ff2
add new state reqs macro to avoid state boilerplate
willyrgf Oct 16, 2023
fd9f756
renaming state reqs macro to state config reqs
willyrgf Oct 17, 2023
ffa2753
Merge branch 'main' into v0.2
willyrgf Oct 17, 2023
ed0edef
refactor(state): accepting arbitrary N-state and N-context definitons
willyrgf Nov 8, 2023
be3fd52
move examples to tests
willyrgf Nov 8, 2023
1e9c9f3
feat(mfm_machine): generalizing errors for state and state machine
willyrgf Nov 11, 2023
e3ba896
refactor(state): accepting arbitrary N-state and N-context definitons
willyrgf Nov 8, 2023
5c2e1fb
move examples to tests
willyrgf Nov 8, 2023
ebe3ad3
feat(mfm_machine): generalizing errors for state and state machine
willyrgf Nov 11, 2023
250176a
fix: mfm_machine_macro importing and add tests/public_api_test
willyrgf Nov 11, 2023
8125061
Merge branch 'v0.2' into fix/mfm-machine-macro
willyrgf Nov 11, 2023
1763e26
refactor(state): make tag and label static and immutable
willyrgf Nov 18, 2023
b6cb2de
wip: add state machine tracker and refactor state_machine to be an mod
willyrgf Nov 18, 2023
59201bc
wip: testing all capabilities
willyrgf Nov 18, 2023
16872d1
wip: making the state_machine recoverable and fault-tolerant
willyrgf Nov 21, 2023
834c34e
feat: add tracker and improve context to be trackable
willyrgf Nov 25, 2023
de9b7a6
test: making the state_machine recoverable and fault-tolerant
willyrgf Nov 25, 2023
cf33232
cleanup old v0.1 and make it an workspace for all mfm crates
willyrgf Nov 26, 2023
d076622
update readme
willyrgf Nov 26, 2023
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
2,987 changes: 273 additions & 2,714 deletions Cargo.lock

Large diffs are not rendered by default.

50 changes: 7 additions & 43 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,45 +1,9 @@
[package]
name = "mfm"
version = "0.1.29"
edition = "2021"
[workspace]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
resolver = "2"

[dependencies]
clap = { version = "4.0", features = ["derive", "cargo"] }
serde_yaml = "0.9"
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
rustc-hex = "2.1"
tokio = { version = "1.0", features = ["full"] }
# TODO: upgrade and use as: https://github.com/graphprotocol/solidity-bindgen/blob/master/solidity-bindgen/src/secrets.rs
secp256k1 = "0.21.3" # this version is a dependency for web3
web3 = { version = "0.18.0" }
futures = "0.3.21"
prettytable-rs = "0.10"
once_cell = "1.10.0"
phf = { version = "0.11", default-features = false }
rpassword = "7.0"
# TODO: review the use of this lib to encryption, https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html
magic-crypt = "3.1.10"
reqwest = "0.11.11"
tracing = { version = "0.1", features = [ "log" ] }
tracing-subscriber = { version = "0.3", features = [ "registry", "env-filter" ] }
tracing-bunyan-formatter = "0.3"
tracing-log = "0.1"
anyhow = { version = "1.0", default-features = false }
hex = "0.4.3"
thiserror = "1.0.33"
bigdecimal = { version = "0.3.0", features = ["serde"] }
num-bigint = { version = "0.4.3", features = ["serde"] }
num-traits = "0.2.15"
zeroize = "1.5.7"
orion = "0.17.2"
chrono = "0.4.23"
teloxide = "0.12.2"



[build-dependencies]
phf_codegen = "0.11.1"
walkdir = "2"
members = [
"mfm_cli",
"mfm_machine",
"mfm_machine_derive",
]
145 changes: 1 addition & 144 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,153 +1,10 @@
# MFM


**WARNING: this v0.1.x is not being in development anymore due to an [in-progress full refactor for a v0.2](https://github.com/willyrgf/mfm/pull/59)**

---


MFM (Multiverse Finance Machine) is a CLI to managing portfolio of cryptoassets directly in Blockchain using DEXs.

> **WARNING**: This project is in an alpha stage. It has not been audited and may contain bugs and security flaws. This implementation is NOT ready for production use.

## Big features coming
- [ ] Support LP's as a asset type and handle with them in the portfolio
- [ ] Support Yield Farms and Harvest rewards
- [ ] Add machine command within a module using state-machine logic to run sequencially and conditionally multiples commands as workflows
- [ ] Add automatic hedge using levarage derivatives (futures/options)
- [ ] Trading strategies with TA (in [mfm_server](https://github.com/willyrgf/mfm_server)?) to adjust dynamic portfolio positions

## Install via Nix profile
```sh
nix profile install github:willyrgf/mfm
```

## Local install & update using releases

### *nix (?)
```sh
# may need adjust for some systems
LATEST_APP_URL="$( \
curl -s https://api.github.com/repos/willyrgf/mfm/releases/latest |
grep 'browser_download_url' |
grep "$(uname | tr '[[:upper:]]' '[[:lower:]]')" |
awk -F '"' '!/.sha256sum/ {print $4}' \
)"
curl -s -L $LATEST_APP_URL -O
unzip -qo ${LATEST_APP_URL##*/}
```

## res/ directory
This directory will carry all the abi files used as default in this project.
All these abi files in this directory will be add in the binary in compilation time (`build.rs`).

To access this files we've a `shared::resources` module that will always condering your currently
filesystem `res/` directory and the default `static RES` compiled in the binary (`build.rs`),
following this order of priority respectively.

## Local test environment

### run GETH server
```sh
docker build -t geth_local tests/blockchains/gethnet
docker run --name geth_local -d -p 8545:8545 -p 8546:8546 geth_local
```

### stop & drop GETH server
```sh
docker stop geth_local && docker rm geth_local
```

### extract base wallet private key
```sh
$ ethkey inspect --private --passwordfile tests/blockchains/gethnet/password.txt tests/blockchains/gethnet/data/keystore/UTC--2023-03-28T01-13-34.803419000Z--4e22e05c29a7165aeee0d813be03af17f129a2d1
Address: 0x4E22e05C29A7165Aeee0D813bE03Af17F129A2d1
Public key: 04bf840d4f25bda6e5cf46dfe8177f33f8ea5ab5e90d17992272c6b3a931976f3a6328d513e943becbc4f9e46d89bce4f9c9654698252d7b09469015ea2c36862d
Private key: afcaf34d4647a3e50b39029fb34aa94b59ae75606f57d78e4bcb286948ed4816
```



<!-- TODO: add install doc and res folder -->

## cmd examples

### wrap token (ex: in bsc bnb -> wbnb, in eth eth -> weth, in polygon matic -> wmatic )

```bash
cargo run -- wrap --network bsc --wallet test-wallet --amount 0.005
```

---

### unwrap token (ex: in bsc wbnb -> bnb, in eth weth -> eth, in polygon wmatic -> matic )

```bash
cargo run -- unwrap --network bsc --wallet test-wallet --amount 0.005
```
**WARNING: this is the `dev`, a branch with the in-development progress of the mfm v0.2**; the [v0.1 was moved to `v0.1` branch](https://github.com/willyrgf/mfm/tree/v0.1).

---

### check allowance data for an asset

```bash
cargo run -- allowance -e pancake_swap_v2 -w test-wallet -a wbnb
```

---

### approve spender for an asset

```bash
cargo run -- approve -e pancake_swap_v2 -w test-wallet -a wbnb -v 10
```


#### To approve all assets
```bash
cargo run -- allowance --network polygon --wallet test-wallet |
grep ^\| |
grep -v Exchange |
awk -F '|' '{print $2 $3}' |
xargs -n 2 bash -c 'cargo run -- approve --exchange $0 -w test-wallet --asset $1 --amount 10000000'
```

---

### get a quote

```bash
cargo run -- quote --network bsc --exchange pancake_swap_v2 -i wbnb -o busd -a 1.0
```

---

### swap tokens for tokens supporting fees on transfer

```bash
cargo run -- swap -w test-wallet -n bsc -e pancake_swap_v2 -i wbnb -o busd -a 0.0006
```

---

### get balances of assets from wallet

```bash
cargo run -- balances -w test-wallet
```

---

### run rebalancer

```bash
cargo run -- rebalancer -n test-rebalancer
```

---

### run withdraw

```bash
cargo run -- withdraw --wallet test-wallet --network bsc --withdraw-wallet test-wallet2 -v 0.008 -a wbnb
```
31 changes: 0 additions & 31 deletions build.rs

This file was deleted.

26 changes: 0 additions & 26 deletions default.nix

This file was deleted.

Loading
Loading