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

Composable tasks to perform complex actions #27

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ members = [
"contracts/paymaster/meta",
"contracts/ping-pong-egld",
"contracts/ping-pong-egld/meta",
"contracts/proxy-actions",
"contracts/proxy-actions/meta",
"contracts/proxy-pause",
"contracts/proxy-pause/meta",
"contracts/rewards-distribution",
Expand Down
7 changes: 7 additions & 0 deletions contracts/proxy-actions/.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*/
21 changes: 21 additions & 0 deletions contracts/proxy-actions/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "proxy-actions"
version = "0.0.0"
authors = [ "MultiversX <[email protected]>" ]
edition = "2021"
publish = false

[lib]
path = "src/proxy_actions.rs"

[dev-dependencies]
num-bigint = "0.4.2"

[dependencies.multiversx-sc]
version = "0.43.4"

[dev-dependencies.multiversx-sc-scenario]
version = "0.43.4"

[dev-dependencies.multiversx-wegld-swap-sc]
path = "../wegld-swap"
14 changes: 14 additions & 0 deletions contracts/proxy-actions/meta/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "proxy-actions-meta"
version = "0.0.0"
edition = "2018"
publish = false
authors = [ "you",]

[dev-dependencies]

[dependencies.proxy-actions]
path = ".."

[dependencies.multiversx-sc-meta]
version = "0.43.4"
3 changes: 3 additions & 0 deletions contracts/proxy-actions/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::<proxy_actions::AbiProvider>();
}
3 changes: 3 additions & 0 deletions contracts/proxy-actions/multiversx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"language": "rust"
}
39 changes: 39 additions & 0 deletions contracts/proxy-actions/scenarios/empty.scen.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "proxy-actions",
"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/proxy-actions.wasm",
"arguments": [],
"gasLimit": "5,000,000",
"gasPrice": "0"
},
"expect": {
"out": [],
"status": "",
"logs": [],
"gas": "*",
"refund": "*"
}
}
]
}
12 changes: 12 additions & 0 deletions contracts/proxy-actions/src/proxy_actions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![no_std]

multiversx_sc::imports!();

mod structs;

/// An empty contract. To be used as a template when starting a new contract from scratch.
#[multiversx_sc::contract]
pub trait ProxyActionsContract: structs::TaskCall {
#[init]
fn init(&self) {}
}
123 changes: 123 additions & 0 deletions contracts/proxy-actions/src/structs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
multiversx_sc::imports!();
multiversx_sc::derive_imports!();

#[derive(TypeAbi, TopEncode, TopDecode, PartialEq, ManagedVecItem)]
pub enum TaskType {
None,
WrapEGLD,
UnwrapEgld,
Swap,
SendEsdt,
ExitLP,
}

pub mod pair_proxy {
#[multiversx_sc::proxy]
pub trait PairProxy {
#[payable("*")]
#[endpoint(swapTokensFixedInput)]
fn swap_tokens_fixed_input(
&self,
token_out: TokenIdentifier,
amount_out_min: BigUint,
) -> EsdtTokenPayment;

#[view(getSafePriceByDefaultOffset)]
fn get_safe_price_by_default_offset(
&self,
pair_address: ManagedAddress,
input_payment: EsdtTokenPayment,
) -> EsdtTokenPayment;
}
}

#[multiversx_sc::module]
pub trait TaskCall {
#[payable("*")]
#[endpoint(composeTasks1)]
fn compose_tasks1(
&self,
tasks: MultiValueEncoded<
MultiValue4<ManagedAddress, ManagedBuffer, MultiValueEncoded<ManagedBuffer>, u64>,
>,
) //-> Result<(), EsdtTokenPayment>
{
let payment = self.call_value().egld_or_single_esdt();
let payment_to_next_task = payment.clone();

Check warning on line 46 in contracts/proxy-actions/src/structs.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/proxy-actions/src/structs.rs#L46

warning: redundant clone --> contracts/proxy-actions/src/structs.rs:46:43 | 46 | let payment_to_next_task = payment.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use --> contracts/proxy-actions/src/structs.rs:46:36 | 46 | let payment_to_next_task = payment.clone(); | ^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone = note: `#[warn(clippy::redundant_clone)]` on by default
Raw output
contracts/proxy-actions/src/structs.rs:46:43:w:warning: redundant clone
  --> contracts/proxy-actions/src/structs.rs:46:43
   |
46 |         let payment_to_next_task = payment.clone();
   |                                           ^^^^^^^^ help: remove this
   |
note: this value is dropped without further use
  --> contracts/proxy-actions/src/structs.rs:46:36
   |
46 |         let payment_to_next_task = payment.clone();
   |                                    ^^^^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
   = note: `#[warn(clippy::redundant_clone)]` on by default


__END__

Check warning on line 46 in contracts/proxy-actions/src/structs.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/proxy-actions/src/structs.rs#L46

warning: redundant clone --> contracts/proxy-actions/src/structs.rs:46:43 | 46 | let payment_to_next_task = payment.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use --> contracts/proxy-actions/src/structs.rs:46:36 | 46 | let payment_to_next_task = payment.clone(); | ^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone = note: `#[warn(clippy::redundant_clone)]` on by default
Raw output
contracts/proxy-actions/src/structs.rs:46:43:w:warning: redundant clone
  --> contracts/proxy-actions/src/structs.rs:46:43
   |
46 |         let payment_to_next_task = payment.clone();
   |                                           ^^^^^^^^ help: remove this
   |
note: this value is dropped without further use
  --> contracts/proxy-actions/src/structs.rs:46:36
   |
46 |         let payment_to_next_task = payment.clone();
   |                                    ^^^^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
   = note: `#[warn(clippy::redundant_clone)]` on by default


__END__

for task in tasks.into_iter() {
let (dest_addr, endpoint_name, endpoint_args, gas_limit) = task.into_tuple();

let payment_to_next_task = self

Check warning on line 51 in contracts/proxy-actions/src/structs.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused variable: `payment_to_next_task`

Check warning on line 51 in contracts/proxy-actions/src/structs.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused variable: `payment_to_next_task`

Check warning on line 51 in contracts/proxy-actions/src/structs.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused variable: `payment_to_next_task`

Check warning on line 51 in contracts/proxy-actions/src/structs.rs

View workflow job for this annotation

GitHub Actions / Contracts / Rust tests

unused variable: `payment_to_next_task`

Check warning on line 51 in contracts/proxy-actions/src/structs.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/proxy-actions/src/structs.rs#L51

warning: unused variable: `payment_to_next_task` --> contracts/proxy-actions/src/structs.rs:51:17 | 51 | let payment_to_next_task = self | ^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_payment_to_next_task` | = note: `#[warn(unused_variables)]` on by default
Raw output
contracts/proxy-actions/src/structs.rs:51:17:w:warning: unused variable: `payment_to_next_task`
  --> contracts/proxy-actions/src/structs.rs:51:17
   |
51 |             let payment_to_next_task = self
   |                 ^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_payment_to_next_task`
   |
   = note: `#[warn(unused_variables)]` on by default


__END__

Check warning on line 51 in contracts/proxy-actions/src/structs.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/proxy-actions/src/structs.rs#L51

warning: this let-binding has unit value --> contracts/proxy-actions/src/structs.rs:51:13 | 51 | / let payment_to_next_task = self 52 | | .send() 53 | | .contract_call::<EsdtTokenPayment>(dest_addr, endpoint_name) 54 | | .with_egld_or_single_esdt_transfer(payment_to_next_task.clone()) 55 | | .with_raw_arguments(endpoint_args.to_arg_buffer()) 56 | | .with_gas_limit(gas_limit) 57 | | .transfer_execute(); | |____________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value = note: `#[warn(clippy::let_unit_value)]` on by default help: omit the `let` binding | 51 ~ self 52 + .send() 53 + .contract_call::<EsdtTokenPayment>(dest_addr, endpoint_name) 54 + .with_egld_or_single_esdt_transfer(payment_to_next_task.clone()) 55 + .with_raw_arguments(endpoint_args.to_arg_buffer()) 56 + .with_gas_limit(gas_limit) 57 + .transfer_execute(); |
Raw output
contracts/proxy-actions/src/structs.rs:51:13:w:warning: this let-binding has unit value
  --> contracts/proxy-actions/src/structs.rs:51:13
   |
51 | /             let payment_to_next_task = self
52 | |                 .send()
53 | |                 .contract_call::<EsdtTokenPayment>(dest_addr, endpoint_name)
54 | |                 .with_egld_or_single_esdt_transfer(payment_to_next_task.clone())
55 | |                 .with_raw_arguments(endpoint_args.to_arg_buffer())
56 | |                 .with_gas_limit(gas_limit)
57 | |                 .transfer_execute();
   | |____________________________________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value
   = note: `#[warn(clippy::let_unit_value)]` on by default
help: omit the `let` binding
   |
51 ~             self
52 +                 .send()
53 +                 .contract_call::<EsdtTokenPayment>(dest_addr, endpoint_name)
54 +                 .with_egld_or_single_esdt_transfer(payment_to_next_task.clone())
55 +                 .with_raw_arguments(endpoint_args.to_arg_buffer())
56 +                 .with_gas_limit(gas_limit)
57 +                 .transfer_execute();
   |


__END__

Check warning on line 51 in contracts/proxy-actions/src/structs.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/proxy-actions/src/structs.rs#L51

warning: unused variable: `payment_to_next_task` --> contracts/proxy-actions/src/structs.rs:51:17 | 51 | let payment_to_next_task = self | ^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_payment_to_next_task` | = note: `#[warn(unused_variables)]` on by default
Raw output
contracts/proxy-actions/src/structs.rs:51:17:w:warning: unused variable: `payment_to_next_task`
  --> contracts/proxy-actions/src/structs.rs:51:17
   |
51 |             let payment_to_next_task = self
   |                 ^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_payment_to_next_task`
   |
   = note: `#[warn(unused_variables)]` on by default


__END__

Check warning on line 51 in contracts/proxy-actions/src/structs.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/proxy-actions/src/structs.rs#L51

warning: this let-binding has unit value --> contracts/proxy-actions/src/structs.rs:51:13 | 51 | / let payment_to_next_task = self 52 | | .send() 53 | | .contract_call::<EsdtTokenPayment>(dest_addr, endpoint_name) 54 | | .with_egld_or_single_esdt_transfer(payment_to_next_task.clone()) 55 | | .with_raw_arguments(endpoint_args.to_arg_buffer()) 56 | | .with_gas_limit(gas_limit) 57 | | .transfer_execute(); | |____________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value = note: `#[warn(clippy::let_unit_value)]` on by default help: omit the `let` binding | 51 ~ self 52 + .send() 53 + .contract_call::<EsdtTokenPayment>(dest_addr, endpoint_name) 54 + .with_egld_or_single_esdt_transfer(payment_to_next_task.clone()) 55 + .with_raw_arguments(endpoint_args.to_arg_buffer()) 56 + .with_gas_limit(gas_limit) 57 + .transfer_execute(); |
Raw output
contracts/proxy-actions/src/structs.rs:51:13:w:warning: this let-binding has unit value
  --> contracts/proxy-actions/src/structs.rs:51:13
   |
51 | /             let payment_to_next_task = self
52 | |                 .send()
53 | |                 .contract_call::<EsdtTokenPayment>(dest_addr, endpoint_name)
54 | |                 .with_egld_or_single_esdt_transfer(payment_to_next_task.clone())
55 | |                 .with_raw_arguments(endpoint_args.to_arg_buffer())
56 | |                 .with_gas_limit(gas_limit)
57 | |                 .transfer_execute();
   | |____________________________________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value
   = note: `#[warn(clippy::let_unit_value)]` on by default
help: omit the `let` binding
   |
51 ~             self
52 +                 .send()
53 +                 .contract_call::<EsdtTokenPayment>(dest_addr, endpoint_name)
54 +                 .with_egld_or_single_esdt_transfer(payment_to_next_task.clone())
55 +                 .with_raw_arguments(endpoint_args.to_arg_buffer())
56 +                 .with_gas_limit(gas_limit)
57 +                 .transfer_execute();
   |


__END__
.send()
.contract_call::<EsdtTokenPayment>(dest_addr, endpoint_name)
.with_egld_or_single_esdt_transfer(payment_to_next_task.clone())
.with_raw_arguments(endpoint_args.to_arg_buffer())
.with_gas_limit(gas_limit)
.transfer_execute();
}
}

#[payable("*")]
#[endpoint(composeTasks2)]
fn compose_tasks2(
&self,
tasks: MultiValueEncoded<
MultiValue4<TaskType, ManagedAddress, MultiValueEncoded<ManagedBuffer>, u64>,
>,
)
//-> Result<(), EsdtTokenPayment>
{
let payment = self.call_value().egld_or_single_esdt();
let payment_to_next_task = payment.clone();

Check warning on line 72 in contracts/proxy-actions/src/structs.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/proxy-actions/src/structs.rs#L72

warning: redundant clone --> contracts/proxy-actions/src/structs.rs:72:43 | 72 | let payment_to_next_task = payment.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use --> contracts/proxy-actions/src/structs.rs:72:36 | 72 | let payment_to_next_task = payment.clone(); | ^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
Raw output
contracts/proxy-actions/src/structs.rs:72:43:w:warning: redundant clone
  --> contracts/proxy-actions/src/structs.rs:72:43
   |
72 |         let payment_to_next_task = payment.clone();
   |                                           ^^^^^^^^ help: remove this
   |
note: this value is dropped without further use
  --> contracts/proxy-actions/src/structs.rs:72:36
   |
72 |         let payment_to_next_task = payment.clone();
   |                                    ^^^^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone


__END__

Check warning on line 72 in contracts/proxy-actions/src/structs.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/proxy-actions/src/structs.rs#L72

warning: redundant clone --> contracts/proxy-actions/src/structs.rs:72:43 | 72 | let payment_to_next_task = payment.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use --> contracts/proxy-actions/src/structs.rs:72:36 | 72 | let payment_to_next_task = payment.clone(); | ^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
Raw output
contracts/proxy-actions/src/structs.rs:72:43:w:warning: redundant clone
  --> contracts/proxy-actions/src/structs.rs:72:43
   |
72 |         let payment_to_next_task = payment.clone();
   |                                           ^^^^^^^^ help: remove this
   |
note: this value is dropped without further use
  --> contracts/proxy-actions/src/structs.rs:72:36
   |
72 |         let payment_to_next_task = payment.clone();
   |                                    ^^^^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone


__END__

for task in tasks.into_iter() {
let (task_type, dest_addr, endpoint_args, gas_limit) = task.into_tuple();

let payment_to_next_task = match task_type {

Check warning on line 77 in contracts/proxy-actions/src/structs.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused variable: `payment_to_next_task`

Check warning on line 77 in contracts/proxy-actions/src/structs.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused variable: `payment_to_next_task`

Check warning on line 77 in contracts/proxy-actions/src/structs.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

unused variable: `payment_to_next_task`

Check warning on line 77 in contracts/proxy-actions/src/structs.rs

View workflow job for this annotation

GitHub Actions / Contracts / Rust tests

unused variable: `payment_to_next_task`

Check warning on line 77 in contracts/proxy-actions/src/structs.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/proxy-actions/src/structs.rs#L77

warning: unused variable: `payment_to_next_task` --> contracts/proxy-actions/src/structs.rs:77:17 | 77 | let payment_to_next_task = match task_type { | ^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_payment_to_next_task`
Raw output
contracts/proxy-actions/src/structs.rs:77:17:w:warning: unused variable: `payment_to_next_task`
  --> contracts/proxy-actions/src/structs.rs:77:17
   |
77 |             let payment_to_next_task = match task_type {
   |                 ^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_payment_to_next_task`


__END__

Check warning on line 77 in contracts/proxy-actions/src/structs.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/proxy-actions/src/structs.rs#L77

warning: this let-binding has unit value --> contracts/proxy-actions/src/structs.rs:77:13 | 77 | / let payment_to_next_task = match task_type { 78 | | TaskType::WrapEGLD => { 79 | | //TODO 80 | | } ... | 117 | | } 118 | | }; | |______________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value help: omit the `let` binding | 77 ~ match task_type { 78 + TaskType::WrapEGLD => { 79 + //TODO 80 + } 81 + TaskType::UnwrapEgld => { 82 + //TODO 83 + } 84 + TaskType::Swap => { 85 + let args = endpoint_args.into_vec_of_buffers(); 86 + let token_out = TokenIdentifier::from(args.get(0).clone_value()); 87 + let min_amount_out = BigUint::from(args.get(1).clone_value()); 88 + let token_payment = payment_to_next_task 89 + .token_identifier 90 + .clone() 91 + .into_esdt_option(); 92 + if token_payment.is_none() { 93 + return; 94 + } 95 + self.pair_contract_proxy(dest_addr) 96 + .swap_tokens_fixed_input(token_out, min_amount_out) 97 + .with_esdt_transfer(EsdtTokenPayment::new( 98 + token_payment.unwrap(), 99 + payment_to_next_task.token_nonce, 100 + payment_to_next_task.amount.clone(), 101 + )) 102 + .with_gas_limit(gas_limit) 103 + .transfer_execute(); 104 + } 105 + TaskType::SendEsdt => { 106 + self.send() 107 + .contract_call::<EsdtTokenPayment>(dest_addr, b"".into()) 108 + .with_egld_or_single_esdt_transfer(payment_to_next_task.clone()) 109 + .with_gas_limit(gas_limit) 110 + .transfer_execute(); 111 + } 112 + TaskType::ExitLP => { 113 + //TODO 114 + } 115 + TaskType::None => { 116 + // return Ok(()) 117 + } 118 + }; |
Raw output
contracts/proxy-actions/src/structs.rs:77:13:w:warning: this let-binding has unit value
   --> contracts/proxy-actions/src/structs.rs:77:13
    |
77  | /             let payment_to_next_task = match task_type {
78  | |                 TaskType::WrapEGLD => {
79  | |                     //TODO
80  | |                 }
...   |
117 | |                 }
118 | |             };
    | |______________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value
help: omit the `let` binding
    |
77  ~             match task_type {
78  +                 TaskType::WrapEGLD => {
79  +                     //TODO
80  +                 }
81  +                 TaskType::UnwrapEgld => {
82  +                     //TODO
83  +                 }
84  +                 TaskType::Swap => {
85  +                     let args = endpoint_args.into_vec_of_buffers();
86  +                     let token_out = TokenIdentifier::from(args.get(0).clone_value());
87  +                     let min_amount_out = BigUint::from(args.get(1).clone_value());
88  +                     let token_payment = payment_to_next_task
89  +                         .token_identifier
90  +                         .clone()
91  +                         .into_esdt_option();
92  +                     if token_payment.is_none() {
93  +                         return;
94  +                     }
95  +                     self.pair_contract_proxy(dest_addr)
96  +                         .swap_tokens_fixed_input(token_out, min_amount_out)
97  +                         .with_esdt_transfer(EsdtTokenPayment::new(
98  +                             token_payment.unwrap(),
99  +                             payment_to_next_task.token_nonce,
100 +                             payment_to_next_task.amount.clone(),
101 +                         ))
102 +                         .with_gas_limit(gas_limit)
103 +                         .transfer_execute();
104 +                 }
105 +                 TaskType::SendEsdt => {
106 +                     self.send()
107 +                         .contract_call::<EsdtTokenPayment>(dest_addr, b"".into())
108 +                         .with_egld_or_single_esdt_transfer(payment_to_next_task.clone())
109 +                         .with_gas_limit(gas_limit)
110 +                         .transfer_execute();
111 +                 }
112 +                 TaskType::ExitLP => {
113 +                     //TODO
114 +                 }
115 +                 TaskType::None => {
116 +                     // return Ok(())
117 +                 }
118 +             };
    |


__END__

Check warning on line 77 in contracts/proxy-actions/src/structs.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/proxy-actions/src/structs.rs#L77

warning: unused variable: `payment_to_next_task` --> contracts/proxy-actions/src/structs.rs:77:17 | 77 | let payment_to_next_task = match task_type { | ^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_payment_to_next_task`
Raw output
contracts/proxy-actions/src/structs.rs:77:17:w:warning: unused variable: `payment_to_next_task`
  --> contracts/proxy-actions/src/structs.rs:77:17
   |
77 |             let payment_to_next_task = match task_type {
   |                 ^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_payment_to_next_task`


__END__

Check warning on line 77 in contracts/proxy-actions/src/structs.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/proxy-actions/src/structs.rs#L77

warning: this let-binding has unit value --> contracts/proxy-actions/src/structs.rs:77:13 | 77 | / let payment_to_next_task = match task_type { 78 | | TaskType::WrapEGLD => { 79 | | //TODO 80 | | } ... | 117 | | } 118 | | }; | |______________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value help: omit the `let` binding | 77 ~ match task_type { 78 + TaskType::WrapEGLD => { 79 + //TODO 80 + } 81 + TaskType::UnwrapEgld => { 82 + //TODO 83 + } 84 + TaskType::Swap => { 85 + let args = endpoint_args.into_vec_of_buffers(); 86 + let token_out = TokenIdentifier::from(args.get(0).clone_value()); 87 + let min_amount_out = BigUint::from(args.get(1).clone_value()); 88 + let token_payment = payment_to_next_task 89 + .token_identifier 90 + .clone() 91 + .into_esdt_option(); 92 + if token_payment.is_none() { 93 + return; 94 + } 95 + self.pair_contract_proxy(dest_addr) 96 + .swap_tokens_fixed_input(token_out, min_amount_out) 97 + .with_esdt_transfer(EsdtTokenPayment::new( 98 + token_payment.unwrap(), 99 + payment_to_next_task.token_nonce, 100 + payment_to_next_task.amount.clone(), 101 + )) 102 + .with_gas_limit(gas_limit) 103 + .transfer_execute(); 104 + } 105 + TaskType::SendEsdt => { 106 + self.send() 107 + .contract_call::<EsdtTokenPayment>(dest_addr, b"".into()) 108 + .with_egld_or_single_esdt_transfer(payment_to_next_task.clone()) 109 + .with_gas_limit(gas_limit) 110 + .transfer_execute(); 111 + } 112 + TaskType::ExitLP => { 113 + //TODO 114 + } 115 + TaskType::None => { 116 + // return Ok(()) 117 + } 118 + }; |
Raw output
contracts/proxy-actions/src/structs.rs:77:13:w:warning: this let-binding has unit value
   --> contracts/proxy-actions/src/structs.rs:77:13
    |
77  | /             let payment_to_next_task = match task_type {
78  | |                 TaskType::WrapEGLD => {
79  | |                     //TODO
80  | |                 }
...   |
117 | |                 }
118 | |             };
    | |______________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value
help: omit the `let` binding
    |
77  ~             match task_type {
78  +                 TaskType::WrapEGLD => {
79  +                     //TODO
80  +                 }
81  +                 TaskType::UnwrapEgld => {
82  +                     //TODO
83  +                 }
84  +                 TaskType::Swap => {
85  +                     let args = endpoint_args.into_vec_of_buffers();
86  +                     let token_out = TokenIdentifier::from(args.get(0).clone_value());
87  +                     let min_amount_out = BigUint::from(args.get(1).clone_value());
88  +                     let token_payment = payment_to_next_task
89  +                         .token_identifier
90  +                         .clone()
91  +                         .into_esdt_option();
92  +                     if token_payment.is_none() {
93  +                         return;
94  +                     }
95  +                     self.pair_contract_proxy(dest_addr)
96  +                         .swap_tokens_fixed_input(token_out, min_amount_out)
97  +                         .with_esdt_transfer(EsdtTokenPayment::new(
98  +                             token_payment.unwrap(),
99  +                             payment_to_next_task.token_nonce,
100 +                             payment_to_next_task.amount.clone(),
101 +                         ))
102 +                         .with_gas_limit(gas_limit)
103 +                         .transfer_execute();
104 +                 }
105 +                 TaskType::SendEsdt => {
106 +                     self.send()
107 +                         .contract_call::<EsdtTokenPayment>(dest_addr, b"".into())
108 +                         .with_egld_or_single_esdt_transfer(payment_to_next_task.clone())
109 +                         .with_gas_limit(gas_limit)
110 +                         .transfer_execute();
111 +                 }
112 +                 TaskType::ExitLP => {
113 +                     //TODO
114 +                 }
115 +                 TaskType::None => {
116 +                     // return Ok(())
117 +                 }
118 +             };
    |


__END__
TaskType::WrapEGLD => {
//TODO
}
TaskType::UnwrapEgld => {
//TODO
}
TaskType::Swap => {
let args = endpoint_args.into_vec_of_buffers();
let token_out = TokenIdentifier::from(args.get(0).clone_value());
let min_amount_out = BigUint::from(args.get(1).clone_value());
let token_payment = payment_to_next_task
.token_identifier
.clone()
.into_esdt_option();
if token_payment.is_none() {
return;
}
self.pair_contract_proxy(dest_addr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to call the router ? it can do all kinds of swaps.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And you would know the router address by default. So it is a setting in the contract. The same is for wrap contract address.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pair contract addresses can be written in storage.

.swap_tokens_fixed_input(token_out, min_amount_out)
.with_esdt_transfer(EsdtTokenPayment::new(
token_payment.unwrap(),
payment_to_next_task.token_nonce,
payment_to_next_task.amount.clone(),
))
.with_gas_limit(gas_limit)
.transfer_execute();
}
TaskType::SendEsdt => {
self.send()
.contract_call::<EsdtTokenPayment>(dest_addr, b"".into())
.with_egld_or_single_esdt_transfer(payment_to_next_task.clone())
.with_gas_limit(gas_limit)
.transfer_execute();
}
TaskType::ExitLP => {
//TODO
}
TaskType::None => {
// return Ok(())
}
};
}
}
#[proxy]
fn pair_contract_proxy(&self, to: ManagedAddress) -> pair_proxy::Proxy<Self::Api>;
}
10 changes: 10 additions & 0 deletions contracts/proxy-actions/tests/empty_scenario_go_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use multiversx_sc_scenario::*;

fn world() -> ScenarioWorld {
ScenarioWorld::vm_go()
}

#[test]
fn empty_go() {
world().run("scenarios/empty.scen.json");
}
17 changes: 17 additions & 0 deletions contracts/proxy-actions/tests/empty_scenario_rs_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use multiversx_sc_scenario::*;

fn world() -> ScenarioWorld {
let mut blockchain = ScenarioWorld::new();
blockchain.set_current_dir_from_workspace("contracts/examples/empty");

blockchain.register_contract(
"file:output/proxy-actions.wasm",
proxy_actions::ContractBuilder,
);
blockchain
}

#[test]
fn empty_rs() {
world().run("scenarios/empty.scen.json");
}
Loading
Loading