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

migration and new proxies for composability #1517

Merged
merged 10 commits into from
Mar 29, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
proxy-paths = ["../parent/src/child_proxy.rs"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Code generated by the multiversx-sc proxy generator. DO NOT EDIT.

////////////////////////////////////////////////////
////////////////// AUTO-GENERATED //////////////////
////////////////////////////////////////////////////

#![allow(dead_code)]
#![allow(clippy::all)]

use multiversx_sc::proxy_imports::*;

pub struct ChildProxy;

impl<Env, From, To, Gas> TxProxyTrait<Env, From, To, Gas> for ChildProxy
where
Env: TxEnv,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
type TxProxyMethods = ChildProxyMethods<Env, From, To, Gas>;

fn proxy_methods(self, tx: Tx<Env, From, To, (), Gas, (), ()>) -> Self::TxProxyMethods {
ChildProxyMethods { wrapped_tx: tx }
}
}

pub struct ChildProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
wrapped_tx: Tx<Env, From, To, (), Gas, (), ()>,
}

#[rustfmt::skip]
impl<Env, From, Gas> ChildProxyMethods<Env, From, (), Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
Gas: TxGas<Env>,
{
pub fn init(
self,
) -> TxProxyDeploy<Env, From, Gas, ()> {
self.wrapped_tx
.raw_deploy()
.original_result()
}
}

#[rustfmt::skip]
impl<Env, From, To, Gas> ChildProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
}

#[rustfmt::skip]
impl<Env, From, To, Gas> ChildProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
pub fn issue_wrapped_egld<
Arg0: CodecInto<ManagedBuffer<Env::Api>>,
Arg1: CodecInto<ManagedBuffer<Env::Api>>,
Arg2: CodecInto<BigUint<Env::Api>>,
>(
self,
token_display_name: Arg0,
token_ticker: Arg1,
initial_supply: Arg2,
) -> TxProxyCall<Env, From, To, Gas, ()> {
self.wrapped_tx
.raw_call()
.function_name("issueWrappedEgld")
.argument(&token_display_name)
.argument(&token_ticker)
.argument(&initial_supply)
.original_result()
}

pub fn wrapped_egld_token_identifier(
self,
) -> TxProxyCall<Env, From, To, Gas, TokenIdentifier<Env::Api>> {
self.wrapped_tx
.raw_call()
.function_name("getWrappedEgldTokenIdentifier")
.original_result()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

multiversx_sc::imports!();

pub mod child_proxy;

// Base cost for standalone + estimate cost of actual sc call
const ISSUE_EXPECTED_GAS_COST: u64 = 90_000_000 + 25_000_000;

#[multiversx_sc::contract]
pub trait Parent {
#[proxy]
fn child_proxy(&self, to: ManagedAddress) -> child::Proxy<Self::Api>;

#[init]
fn init(&self) {}

Expand All @@ -19,13 +18,14 @@ pub trait Parent {

#[endpoint(deployChildContract)]
fn deploy_child_contract(&self, code: ManagedBuffer) {
let (child_contract_address, _) = self.send_raw().deploy_contract(
self.blockchain().get_gas_left(),
&BigUint::zero(),
&code,
CodeMetadata::DEFAULT,
&ManagedArgBuffer::new(),
);
let gas_left = self.blockchain().get_gas_left();
let child_contract_address = self
.tx()
.raw_deploy()
.code(code)
.with_gas_limit(gas_left)
.returns(ReturnsNewAddress)
.sync_call();

self.child_contract_address().set(&child_contract_address);
}
Expand All @@ -40,12 +40,14 @@ pub trait Parent {
) {
let issue_cost = self.call_value().egld_value();
let child_contract_adress = self.child_contract_address().get();
let _: IgnoreValue = self
.child_proxy(child_contract_adress)

self.tx()
.to(&child_contract_adress)
.typed(child_proxy::ChildProxy)
.issue_wrapped_egld(token_display_name, token_ticker, initial_supply)
.with_egld_transfer(issue_cost.clone_value())
.egld(issue_cost)
.with_gas_limit(ISSUE_EXPECTED_GAS_COST)
.execute_on_dest_context();
.sync_call();
}

// storage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ multiversx_sc::imports!();
/// Test contract for investigating the new async call framework.
#[multiversx_sc::module]
pub trait CallPromisesDirectModule {
#[proxy]
fn vault_proxy(&self) -> vault::Proxy<Self::Api>;

#[endpoint]
#[payable("*")]
fn promise_raw_single_token(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
multiversx_sc::imports!();

use crate::common::{self, CallbackData};
use crate::{
common::{self, CallbackData},
vault_proxy,
};

#[multiversx_sc::module]
pub trait CallPromisesModule: common::CommonModule {
#[proxy]
fn vault_proxy(&self) -> vault::Proxy<Self::Api>;

#[endpoint]
#[payable("*")]
fn forward_promise_accept_funds(&self, to: ManagedAddress) {
let payment = self.call_value().egld_or_single_esdt();
let gas_limit = self.blockchain().get_gas_left() / 2;
self.vault_proxy()
.contract(to)

self.tx()
.to(&to)
.typed(vault_proxy::VaultProxy)
.accept_funds()
.with_egld_or_single_esdt_transfer(payment)
.with_gas_limit(gas_limit)
.async_call_promise()
.register_promise()
.with_egld_or_single_esdt_transfer(payment)
.async_call()
mihaicalinluca marked this conversation as resolved.
Show resolved Hide resolved
.register_promise();
}

#[endpoint]
Expand All @@ -30,14 +32,16 @@ pub trait CallPromisesModule: common::CommonModule {
amount: BigUint,
) {
let gas_limit = self.blockchain().get_gas_left() - 20_000_000;
self.vault_proxy()
.contract(to)

self.tx()
.to(&to)
.typed(vault_proxy::VaultProxy)
.retrieve_funds(token, token_nonce, amount)
.with_gas_limit(gas_limit)
.async_call_promise()
.async_call()
.with_callback(self.callbacks().retrieve_funds_callback())
.with_extra_gas_for_callback(10_000_000)
.register_promise()
.register_promise();
}

#[promises_callback]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
multiversx_sc::imports!();
multiversx_sc::derive_imports!();

use crate::common::{self, CallbackData};

use crate::{
common::{self, CallbackData},
vault_proxy,
};
#[multiversx_sc::module]
pub trait CallPromisesBackTransfersModule: common::CommonModule {
#[proxy]
fn vault_proxy(&self) -> vault::Proxy<Self::Api>;

#[endpoint]
fn forward_promise_retrieve_funds_back_transfers(
&self,
Expand All @@ -17,14 +16,15 @@ pub trait CallPromisesBackTransfersModule: common::CommonModule {
amount: BigUint,
) {
let gas_limit = self.blockchain().get_gas_left() - 20_000_000;
self.vault_proxy()
.contract(to)
self.tx()
.to(&to)
.typed(vault_proxy::VaultProxy)
.retrieve_funds(token, token_nonce, amount)
.with_gas_limit(gas_limit)
.async_call_promise()
.async_call()
.with_callback(self.callbacks().retrieve_funds_back_transfers_callback())
.with_extra_gas_for_callback(10_000_000)
.register_promise()
.register_promise();
}

#[promises_callback]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::vault_proxy;

multiversx_sc::imports!();

/// Not directly related to promises, but this contract already has the setup for VM 1.5.
#[multiversx_sc::module]
pub trait BackTransfersFeatureModule {
#[proxy]
fn vault_proxy(&self) -> vault::Proxy<Self::Api>;

#[endpoint]
fn forward_sync_retrieve_funds_bt(
&self,
Expand All @@ -15,8 +14,9 @@ pub trait BackTransfersFeatureModule {
amount: BigUint,
) {
let ((), back_transfers) = self
.vault_proxy()
.contract(to)
.tx()
.to(&to)
.typed(vault_proxy::VaultProxy)
.retrieve_funds(token, token_nonce, amount)
.execute_on_dest_context_with_back_transfers::<()>();
mihaicalinluca marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -40,8 +40,9 @@ pub trait BackTransfersFeatureModule {
amount: BigUint,
) {
let ((), back_transfers) = self
.vault_proxy()
.contract(to.clone())
.tx()
.to(&to)
.typed(vault_proxy::VaultProxy)
.retrieve_funds(token.clone(), token_nonce, amount.clone())
.execute_on_dest_context_with_back_transfers::<()>();

Expand All @@ -56,8 +57,9 @@ pub trait BackTransfersFeatureModule {
);

let ((), back_transfers) = self
.vault_proxy()
.contract(to)
.tx()
.to(&to)
.typed(vault_proxy::VaultProxy)
.retrieve_funds(token, token_nonce, amount)
.execute_on_dest_context_with_back_transfers::<()>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod call_promises;
mod call_promises_bt;
pub mod call_sync_bt;
mod common;
pub mod vault_proxy;

multiversx_sc::imports!();

Expand Down
Loading
Loading