-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from multiversx/composable-sc
Create Composable SC
- Loading branch information
Showing
36 changed files
with
3,208 additions
and
228 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,7 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
/target/ | ||
*/target/ | ||
|
||
# The mxpy output | ||
/output*/ |
This file contains 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,43 @@ | ||
[package] | ||
name = "composable-tasks" | ||
version = "0.0.0" | ||
authors = ["you"] | ||
edition = "2018" | ||
publish = false | ||
|
||
[lib] | ||
path = "src/lib.rs" | ||
|
||
[dev-dependencies] | ||
num-bigint = "0.4.2" | ||
|
||
[dev-dependencies.multiversx-sc-scenario] | ||
version = "0.45.2" | ||
|
||
[dev-dependencies.pausable] | ||
git = "https://github.com/multiversx/mx-exchange-sc" | ||
rev = "b202319" | ||
|
||
[dependencies.multiversx-sc] | ||
version = "0.45.2" | ||
features = ["back-transfers"] | ||
|
||
[dependencies.farm] | ||
git = "https://github.com/multiversx/mx-exchange-sc" | ||
rev = "b202319" | ||
|
||
[dependencies.farm-with-locked-rewards] | ||
git = "https://github.com/multiversx/mx-exchange-sc" | ||
rev = "b202319" | ||
|
||
[dependencies.pair] | ||
git = "https://github.com/multiversx/mx-exchange-sc" | ||
rev = "b202319" | ||
|
||
[dependencies.router] | ||
git = "https://github.com/multiversx/mx-exchange-sc" | ||
rev = "b202319" | ||
|
||
[dependencies.multiversx-wegld-swap-sc] | ||
git = "https://github.com/multiversx/mx-contracts-rs" | ||
rev = "7e6df3d" |
This file contains 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,63 @@ | ||
# Composable Tasks SC | ||
|
||
## Overview | ||
|
||
This smart contract enables users to compose multiple actions while interacting with various Smart Contracts from MultiversX ecosystem, including xExchange. | ||
It streamlines the process of interacting with WrapEGld and xExchange and provides a convenient way to perform multiple actions in a single transaction on the blockchain. | ||
|
||
Complex actions are formed of multiple tasks. The tasks are performed synchronously, one after the other. | ||
Example of tasks: | ||
- wrapEGLD | ||
- unwrapEGLD | ||
- Swap | ||
- Send EGLD/ESDT to third party | ||
|
||
|
||
Example of actions: | ||
- Wrap EGLD & send to third party | ||
- Swap ESDT to wEGLD & unwrap to EGLD | ||
- Wrap EGLD & swap to ESDT & send to third party | ||
|
||
> **_Note:_** If the last task is **not** `Send tokens`, the resulted payment will be returned to the caller. Otherwise, the payment goes to the destination. | ||
## Task Structure | ||
|
||
A task receives an `EgldOrEsdtPayment` and outputs one as well. | ||
The resulted `EgldOrEsdtPayment` is forwarded to the next task. | ||
If one task fails, the whole process will fail. | ||
|
||
The `composeTasks` endpoint: | ||
``` | ||
#[payable("*")] | ||
#[endpoint(composeTasks)] | ||
fn compose_tasks( | ||
&self, | ||
opt_dest_addr: OptionalValue<ManagedAddress>, | ||
tasks: MultiValueEncoded<MultiValue2<TaskType, ManagedVec<ManagedBuffer>>>, | ||
) | ||
``` | ||
|
||
where `TaskType`: | ||
|
||
``` | ||
pub enum TaskType { | ||
WrapEGLD, | ||
UnwrapEGLD, | ||
Swap, | ||
SendEsdt, | ||
} | ||
``` | ||
|
||
|
||
> **_WARNING:_** If you provide a wrong destination address, the payment will be sent there. | ||
Most of the tasks don't require arguments, but some do (like `Swap`). An example of calling `Swap` task: | ||
|
||
``` | ||
let mut swap_args = ManagedVec::new(); | ||
swap_args.push(managed_buffer!(TOKEN_ID)); | ||
swap_args.push(managed_buffer!(b"1")); | ||
let mut tasks = MultiValueEncoded::new(); | ||
tasks.push((TaskType::Swap, swap_args).into()); | ||
``` |
This file contains 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,15 @@ | ||
[package] | ||
name = "composable-tasks-meta" | ||
version = "0.0.0" | ||
edition = "2018" | ||
publish = false | ||
authors = ["you"] | ||
|
||
[dev-dependencies] | ||
|
||
[dependencies.composable-tasks] | ||
path = ".." | ||
|
||
[dependencies.multiversx-sc-meta] | ||
version = "0.45.2" | ||
default-features = false |
This file contains 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,3 @@ | ||
fn main() { | ||
multiversx_sc_meta::cli_main::<composable_tasks::AbiProvider>(); | ||
} |
This file contains 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,3 @@ | ||
{ | ||
"language": "rust" | ||
} |
This file contains 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,18 @@ | ||
name = "empty" | ||
contract_trait = "EmptyContract" | ||
src_file = "empty.rs" | ||
rename_pairs = [ | ||
[ | ||
"blockchain.set_current_dir_from_workspace(\"contracts/examples/empty\");", | ||
"// blockchain.set_current_dir_from_workspace(\"relative path to your workspace, if applicable\");", | ||
], | ||
] | ||
files_include = [ | ||
"meta", | ||
"scenarios", | ||
"src", | ||
"tests", | ||
"wasm/Cargo.toml", | ||
"Cargo.toml", | ||
"multiversx.json", | ||
] |
This file contains 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,39 @@ | ||
{ | ||
"name": "composable-tasks", | ||
"steps": [ | ||
{ | ||
"step": "setState", | ||
"accounts": { | ||
"address:owner": { | ||
"nonce": "1", | ||
"balance": "0" | ||
} | ||
}, | ||
"newAddresses": [ | ||
{ | ||
"creatorAddress": "address:owner", | ||
"creatorNonce": "1", | ||
"newAddress": "sc:empty" | ||
} | ||
] | ||
}, | ||
{ | ||
"step": "scDeploy", | ||
"id": "deploy", | ||
"tx": { | ||
"from": "address:owner", | ||
"contractCode": "file:../output/composable-tasks.wasm", | ||
"arguments": [], | ||
"gasLimit": "5,000,000", | ||
"gasPrice": "0" | ||
}, | ||
"expect": { | ||
"out": [], | ||
"status": "", | ||
"logs": [], | ||
"gas": "*", | ||
"refund": "*" | ||
} | ||
} | ||
] | ||
} |
Oops, something went wrong.