-
Notifications
You must be signed in to change notification settings - Fork 110
Forwarder-blind + DEX interactor #2315
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
Merged
+2,333
−61
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3992a12
wegld addresses in readme
andrei-marinica f4bca00
dex interactor - basics
andrei-marinica 0de724a
Display for Payment/EsdtTokenPayment
andrei-marinica caad8b8
dex interactor - direct swap
andrei-marinica 2b04bab
Merge branch 'master' into dex-interactor
andrei-marinica 1d601fe
dex interactor - sync call swap
andrei-marinica 05ce0c9
dex-interactor - all swaps
andrei-marinica 0bc96b0
Merge branch 'master' into dex-interactor
andrei-marinica cd962fd
dex-interactor - drain
andrei-marinica a6405aa
cleanup
andrei-marinica 0bcb4b8
readme update
andrei-marinica b71ad02
test_wallets::for_shard takes ShardId
andrei-marinica File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| [[proxy]] | ||
| path = "../../examples/multisig/interact/src/wegld_proxy.rs" | ||
|
|
||
| [[proxy]] | ||
| path = "../../feature-tests/composability/forwarder-blind/dex-interactor/src/proxies/wegld_proxy.rs" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
contracts/feature-tests/composability/forwarder-blind/dex-interactor/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Pem files are used for interactions, but shouldn't be committed | ||
| *.pem |
33 changes: 33 additions & 0 deletions
33
contracts/feature-tests/composability/forwarder-blind/dex-interactor/Cargo.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| [package] | ||
| name = "forwarder-blind-dex-interactor" | ||
| version = "0.0.0" | ||
| authors = ["MultiversX <contact@multiversx.com>"] | ||
| edition = "2024" | ||
| publish = false | ||
|
|
||
| [[bin]] | ||
| name = "forwarder-blind-dex-interactor" | ||
| path = "src/interactor_main.rs" | ||
|
|
||
| [lib] | ||
| path = "src/interact.rs" | ||
|
|
||
| [dependencies.forwarder-blind] | ||
| path = ".." | ||
|
|
||
| [dependencies.multiversx-sc-snippets] | ||
| version = "0.65.0" | ||
| path = "../../../../../framework/snippets" | ||
|
|
||
| [dependencies.multiversx-sc] | ||
| version = "0.65.0" | ||
| path = "../../../../../framework/base" | ||
|
|
||
| [dependencies] | ||
| clap = { version = "4.4", features = ["derive"] } | ||
| serde = { version = "1.0", features = ["derive"] } | ||
| toml = "1.0" | ||
| tokio = { version = "1.24" } | ||
|
|
||
| [features] | ||
| chain-simulator-tests = [] |
185 changes: 185 additions & 0 deletions
185
contracts/feature-tests/composability/forwarder-blind/dex-interactor/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| # forwarder-blind DEX interactor | ||
|
|
||
| CLI interactor for the `forwarder-blind` contract that demonstrates calling into a DEX pair | ||
| using every available call type. | ||
|
|
||
| ## Running | ||
|
|
||
| ```bash | ||
| cargo run -- <COMMAND> [OPTIONS] | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Commands | ||
|
|
||
| ### `deploy` | ||
|
|
||
| Deploy a new instance of the forwarder-blind contract. | ||
|
|
||
| ```bash | ||
| cargo run -- deploy | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ### `wrap` | ||
|
|
||
| Wrap EGLD into WEGLD via the WEGLD swap contract. | ||
|
|
||
| ```bash | ||
| cargo run -- wrap -a <AMOUNT> | ||
| ``` | ||
|
|
||
| | Flag | Description | | ||
| |------|-------------| | ||
| | `-a`, `--amount` | Amount of EGLD to wrap, in denomination (1 EGLD = 10^18) | | ||
|
|
||
| --- | ||
|
|
||
| ### `swap1` — Swap WEGLD → USDC | ||
|
|
||
| ```bash | ||
| cargo run -- swap1 <METHOD> [OPTIONS] | ||
| ``` | ||
|
|
||
| #### Methods | ||
|
|
||
| | Method | Description | | ||
| |--------|-------------| | ||
| | `direct` | Swap directly on the DEX pair | | ||
| | `sync` | Swap via forwarder-blind using `blind_sync` | | ||
| | `async1` | Swap via forwarder-blind using `blind_async_v1` | | ||
| | `async2` | Swap via forwarder-blind using `blind_async_v2` | | ||
| | `te` | Swap via forwarder-blind using `blind_transf_exec` | | ||
|
|
||
| #### Options (all methods) | ||
|
|
||
| | Flag | Description | Default | | ||
| |------|-------------|---------| | ||
| | `-a`, `--wegld-amount` | Amount of WEGLD to sell | *(required)* | | ||
| | `-m`, `--usdc-amount-min` | Minimum USDC to accept (slippage guard) | `1` | | ||
|
|
||
| #### Examples | ||
|
|
||
| ```bash | ||
| # Direct swap | ||
| cargo run -- swap1 direct -a 1000000000000000000 | ||
|
|
||
| # Via blind_sync | ||
| cargo run -- swap1 sync -a 1000000000000000000 -m 1000 | ||
|
|
||
| # Via blind_async_v1 | ||
| cargo run -- swap1 async1 -a 1000000000000000000 | ||
|
|
||
| # Via blind_async_v2 | ||
| cargo run -- swap1 async2 -a 1000000000000000000 | ||
|
|
||
| # Via blind_transf_exec | ||
| cargo run -- swap1 te -a 1000000000000000000 | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ### `swap2` — Swap USDC → WEGLD | ||
|
|
||
| ```bash | ||
| cargo run -- swap2 <METHOD> [OPTIONS] | ||
| ``` | ||
|
|
||
| #### Methods | ||
|
|
||
| | Method | Description | | ||
| |--------|-------------| | ||
| | `direct` | Swap directly on the DEX pair | | ||
| | `sync` | Swap via forwarder-blind using `blind_sync` | | ||
| | `async1` | Swap via forwarder-blind using `blind_async_v1` | | ||
| | `async2` | Swap via forwarder-blind using `blind_async_v2` | | ||
| | `te` | Swap via forwarder-blind using `blind_transf_exec` | | ||
|
|
||
| #### Options (all methods) | ||
|
|
||
| | Flag | Description | Default | | ||
| |------|-------------|---------| | ||
| | `-a`, `--usdc-amount` | Amount of USDC to sell | *(required)* | | ||
| | `-m`, `--wegld-amount-min` | Minimum WEGLD to accept (slippage guard) | `1` | | ||
|
|
||
| #### Examples | ||
|
|
||
| ```bash | ||
| # Direct swap | ||
| cargo run -- swap2 direct -a 40000 | ||
|
|
||
| # Via blind_sync | ||
| cargo run -- swap2 sync -a 40000 -m 1 | ||
|
|
||
| # Via blind_async_v1 | ||
| cargo run -- swap2 async1 -a 40000 | ||
|
|
||
| # Via blind_async_v2 | ||
| cargo run -- swap2 async2 -a 40000 | ||
|
|
||
| # Via blind_transf_exec | ||
| cargo run -- swap2 te -a 40000 | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ### `get-rate` | ||
|
|
||
| Get the approximate WEGLD → USDC conversion rate. | ||
|
|
||
| ```bash | ||
| cargo run -- get-rate [-a <WEGLD_AMOUNT>] | ||
| ``` | ||
|
|
||
| | Flag | Description | Default | | ||
| |------|-------------|---------| | ||
| | `-a`, `--wegld-amount` | Amount of WEGLD to price | `1000000000000000000` (1 EGLD) | | ||
|
|
||
| --- | ||
|
|
||
| ### `get-liquidity` | ||
|
|
||
| Show the liquidity reserves in the WEGLD/USDC pair. | ||
|
|
||
| ```bash | ||
| cargo run -- get-liquidity | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ### `drain` | ||
|
|
||
| Drain all WEGLD and USDC balances held by the deployed forwarder-blind contract back to the owner. | ||
| Useful to recover tokens left in the contract after transfer-execute swaps (which have no callback). | ||
|
|
||
| ```bash | ||
| cargo run -- drain | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Configuration | ||
|
|
||
| The interactor reads `config.toml` from the current directory. Example: | ||
|
|
||
| ```toml | ||
| chain_type = 'real' | ||
| gateway_uri = 'https://gateway.battleofnodes.com' | ||
| wegld_address = 'erd1...' # WEGLD swap contract | ||
| pair_address = 'erd1...' # WEGLD/USDC DEX pair contract | ||
| wegld_token_id = 'WEGLD-bd4d79' | ||
| usdc_token_id = 'USDC-c76f1f' | ||
| ``` | ||
|
|
||
| | Field | Description | | ||
| |-------|-------------| | ||
| | `chain_type` | `real` for mainnet/testnet or `simulator` for the chain simulator | | ||
| | `gateway_uri` | Gateway endpoint URL | | ||
| | `wegld_address` | Address of the WEGLD swap contract | | ||
| | `pair_address` | Address of the WEGLD/USDC DEX pair contract | | ||
| | `wegld_token_id` | ESDT identifier for WEGLD | | ||
| | `usdc_token_id` | ESDT identifier for USDC | | ||
|
|
||
| The deployed contract address is persisted automatically in `state.toml` after a successful `deploy`. |
6 changes: 6 additions & 0 deletions
6
contracts/feature-tests/composability/forwarder-blind/dex-interactor/config.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| chain_type = 'real' | ||
| gateway_uri = 'https://gateway.battleofnodes.com' | ||
| wegld_address = 'erd1qqqqqqqqqqqqqpgqmuk0q2saj0mgutxm4teywre6dl8wqf58xamqdrukln' | ||
| pair_address = 'erd1qqqqqqqqqqqqqpgqeel2kumf0r8ffyhth7pqdujjat9nx0862jpsg2pqaq' | ||
| wegld_token_id = 'WEGLD-bd4d79' | ||
| usdc_token_id = 'USDC-c76f1f' | ||
andrei-marinica marked this conversation as resolved.
Show resolved
Hide resolved
|
||
47 changes: 47 additions & 0 deletions
47
contracts/feature-tests/composability/forwarder-blind/dex-interactor/src/config.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| use multiversx_sc_snippets::imports::Bech32Address; | ||
| use serde::Deserialize; | ||
| use std::io::Read; | ||
|
|
||
| /// Config file | ||
| const CONFIG_FILE: &str = "config.toml"; | ||
|
|
||
| #[derive(Debug, Deserialize)] | ||
| #[serde(rename_all = "lowercase")] | ||
| pub enum ChainType { | ||
| Real, | ||
| Simulator, | ||
| } | ||
|
|
||
| /// Contract Interact configuration | ||
| #[derive(Debug, Deserialize)] | ||
| pub struct Config { | ||
| pub gateway_uri: String, | ||
| pub chain_type: ChainType, | ||
| pub wegld_address: Bech32Address, | ||
| pub pair_address: Bech32Address, | ||
| pub wegld_token_id: String, | ||
| pub usdc_token_id: String, | ||
| } | ||
|
|
||
| impl Config { | ||
| // Deserializes config from file | ||
| pub fn load_config() -> Self { | ||
| let mut file = std::fs::File::open(CONFIG_FILE).unwrap(); | ||
| let mut content = String::new(); | ||
| file.read_to_string(&mut content).unwrap(); | ||
| toml::from_str(&content).unwrap() | ||
| } | ||
|
|
||
| // Returns the gateway URI | ||
| pub fn gateway_uri(&self) -> &str { | ||
| &self.gateway_uri | ||
| } | ||
|
|
||
| // Returns if chain type is chain simulator | ||
| pub fn use_chain_simulator(&self) -> bool { | ||
| match self.chain_type { | ||
| ChainType::Real => false, | ||
| ChainType::Simulator => true, | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.