Skip to content

Commit

Permalink
Merge pull request #43 from multiversx/composable-sc
Browse files Browse the repository at this point in the history
Create Composable SC
  • Loading branch information
sasurobert authored Jan 15, 2024
2 parents 6dd94d9 + 01f9fb7 commit afbddac
Show file tree
Hide file tree
Showing 36 changed files with 3,208 additions and 228 deletions.
500 changes: 283 additions & 217 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ members = [
"locked-token-pos-creator/meta",
"farm-extra-rewards-wrapper",
"farm-extra-rewards-wrapper/meta",
"composable-tasks",
"composable-tasks/meta",
"energy-dao",
"energy-dao/meta",
"tests-common"
Expand Down
2 changes: 1 addition & 1 deletion auto-farm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub trait AutoFarm:
.set_if_empty(fees_collector_sc_address);
}

#[endpoint]
#[upgrade]
fn upgrade(&self) {}

#[only_owner]
Expand Down
4 changes: 2 additions & 2 deletions auto-pos-creator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ rev = "b202319"

[dependencies.multiversx-wegld-swap-sc]
git = "https://github.com/multiversx/mx-contracts-rs/"
rev = "ec189d2"
rev = "7e6df3d"

[dev-dependencies]
num-bigint = "0.4.2"
num-traits = "0.2"
hex = "0.4"
hex-literal = "0.3.4"
hex-literal = "0.4.1"

[dev-dependencies.multiversx-sc-scenario]
version = "=0.45.2"
Expand Down
2 changes: 1 addition & 1 deletion auto-pos-creator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ pub trait AutoPosCreator:
self.router_address().set(router_address);
}

#[endpoint]
#[upgrade]
fn upgrade(&self) {}
}
4 changes: 2 additions & 2 deletions auto-pos-creator/wasm/Cargo.lock

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

7 changes: 7 additions & 0 deletions composable-tasks/.gitignore
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*/
43 changes: 43 additions & 0 deletions composable-tasks/Cargo.toml
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"
63 changes: 63 additions & 0 deletions composable-tasks/README.md
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());
```
15 changes: 15 additions & 0 deletions composable-tasks/meta/Cargo.toml
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
3 changes: 3 additions & 0 deletions composable-tasks/meta/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
multiversx_sc_meta::cli_main::<composable_tasks::AbiProvider>();
}
3 changes: 3 additions & 0 deletions composable-tasks/multiversx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"language": "rust"
}
18 changes: 18 additions & 0 deletions composable-tasks/mxsc-template.toml
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",
]
39 changes: 39 additions & 0 deletions composable-tasks/scenarios/empty.scen.json
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": "*"
}
}
]
}
Loading

0 comments on commit afbddac

Please sign in to comment.