Skip to content
Merged
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
4 changes: 2 additions & 2 deletions contracts/examples/order-book/factory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use multiversx_sc::{derive_imports::*, imports::*};
#[type_abi]
#[derive(TopEncode, TopDecode, NestedEncode, NestedDecode, Clone)]
pub struct TokenIdPair<M: ManagedTypeApi> {
first_token_id: EsdtTokenIdentifier<M>,
second_token_id: EsdtTokenIdentifier<M>,
first_token_id: TokenId<M>,
second_token_id: TokenId<M>,
}

#[multiversx_sc::contract]
Expand Down
6 changes: 3 additions & 3 deletions contracts/examples/order-book/pair/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub enum OrderType {

#[derive(ManagedVecItem, Clone)]
pub struct FungiblePayment<M: ManagedTypeApi> {
pub token_id: EsdtTokenIdentifier<M>,
pub token_id: TokenId<M>,
pub amount: BigUint<M>,
}

Expand Down Expand Up @@ -121,9 +121,9 @@ pub trait CommonModule {

#[view(getFirstTokenId)]
#[storage_mapper("first_token_id")]
fn first_token_id(&self) -> SingleValueMapper<EsdtTokenIdentifier>;
fn first_token_id(&self) -> SingleValueMapper<TokenId>;

#[view(getSecondTokenId)]
#[storage_mapper("second_token_id")]
fn second_token_id(&self) -> SingleValueMapper<EsdtTokenIdentifier>;
fn second_token_id(&self) -> SingleValueMapper<TokenId>;
}
2 changes: 1 addition & 1 deletion contracts/examples/order-book/pair/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub trait Pair:
+ validation::ValidationModule
{
#[init]
fn init(&self, first_token_id: EsdtTokenIdentifier, second_token_id: EsdtTokenIdentifier) {
fn init(&self, first_token_id: TokenId, second_token_id: TokenId) {
self.first_token_id().set_if_empty(&first_token_id);
self.second_token_id().set_if_empty(&second_token_id);
}
Expand Down
14 changes: 8 additions & 6 deletions contracts/examples/order-book/pair/src/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ pub trait OrdersModule:
&self,
order_id: u64,
caller: &ManagedAddress,
first_token_id: &EsdtTokenIdentifier,
second_token_id: &EsdtTokenIdentifier,
first_token_id: &TokenId,
second_token_id: &TokenId,
epoch: u64,
) -> Order<Self::Api> {
let order = self.orders(order_id).get();
Expand Down Expand Up @@ -186,8 +186,8 @@ pub trait OrdersModule:
&self,
order_id: u64,
caller: &ManagedAddress,
first_token_id: &EsdtTokenIdentifier,
second_token_id: &EsdtTokenIdentifier,
first_token_id: &TokenId,
second_token_id: &TokenId,
epoch: u64,
) -> Order<Self::Api> {
let order = self.orders(order_id).get();
Expand Down Expand Up @@ -308,7 +308,7 @@ pub trait OrdersModule:
&self,
orders: MultiValueManagedVec<Order<Self::Api>>,
total_paid: BigUint,
token_requested: EsdtTokenIdentifier,
token_requested: TokenId,
leftover: BigUint,
) -> ManagedVec<Transfer<Self::Api>> {
let mut transfers: ManagedVec<Self::Api, Transfer<Self::Api>> = ManagedVec::new();
Expand Down Expand Up @@ -353,9 +353,11 @@ pub trait OrdersModule:
fn execute_transfers(&self, transfers: ManagedVec<Transfer<Self::Api>>) {
for transfer in &transfers {
if transfer.payment.amount > 0 {
let token_id = transfer.payment.token_id.clone();
let amount = NonZeroBigUint::new(transfer.payment.amount.clone()).unwrap();
self.tx()
.to(&transfer.to)
.single_esdt(&transfer.payment.token_id, 0, &transfer.payment.amount)
.payment(Payment::new(token_id, 0, amount))
.transfer();
}
}
Expand Down
31 changes: 18 additions & 13 deletions contracts/examples/order-book/pair/src/validation.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use multiversx_sc::imports::*;

use crate::common::{FeeConfig, FeeConfigEnum};
use crate::common::{FeeConfig, FeeConfigEnum, FungiblePayment};

use super::{
common,
common::{
FungiblePayment, Order, OrderInputParams, FEE_PENALTY_INCREASE_PERCENT,
MAX_ORDERS_PER_USER, PERCENT_BASE_POINTS,
Order, OrderInputParams, FEE_PENALTY_INCREASE_PERCENT, MAX_ORDERS_PER_USER,
PERCENT_BASE_POINTS,
},
};

Expand Down Expand Up @@ -69,30 +69,35 @@ pub trait ValidationModule: common::CommonModule {
}

fn require_valid_buy_payment(&self) -> FungiblePayment<Self::Api> {
let (token_id, amount) = self.call_value().single_fungible_esdt();
let payment = self.call_value().single();
let second_token_id = self.second_token_id().get();
require!(
*token_id == second_token_id,
"Token in and second token id should be the same"
payment.token_identifier.is_valid_esdt_identifier(),
"Payment is not a fungible token"
);
require!(
payment.token_identifier == second_token_id,
"Token id and second token id should be the same"
);

FungiblePayment {
token_id: token_id.clone(),
amount: amount.clone(),
token_id: payment.token_identifier.clone(),
amount: payment.amount.as_big_uint().clone(),
}
}

fn require_valid_sell_payment(&self) -> FungiblePayment<Self::Api> {
let (token_id, amount) = self.call_value().single_fungible_esdt();
let payment = self.call_value().single();
let first_token_id = self.first_token_id().get();
require!(payment.is_fungible(), "Payment is not a fungible token");
require!(
*token_id == first_token_id,
"Token in and first token id should be the same"
payment.token_identifier == first_token_id,
"Token id and first token id should be the same"
);

FungiblePayment {
token_id: token_id.clone(),
amount: amount.clone(),
token_id: payment.token_identifier.clone(),
amount: payment.amount.as_big_uint().clone(),
}
}

Expand Down
18 changes: 2 additions & 16 deletions framework/base/src/types/managed/wrapped/token/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::{
api::ManagedTypeApi,
types::{
managed_vec_item_read_from_payload_index, managed_vec_item_save_to_payload_index, BigUint,
Egld, EsdtTokenPayment, EsdtTokenPaymentRefs, EsdtTokenType, ManagedVecItem,
ManagedVecItemPayloadBuffer, NonZeroBigUint, PaymentMultiValue, PaymentRefs, Ref, TokenId,
Egld, EsdtTokenPayment, EsdtTokenPaymentRefs, ManagedVecItem, ManagedVecItemPayloadBuffer,
NonZeroBigUint, PaymentMultiValue, PaymentRefs, Ref, TokenId,
},
};

Expand Down Expand Up @@ -40,20 +40,6 @@ impl<M: ManagedTypeApi> Payment<M> {
}
}

pub fn token_type(&self) -> EsdtTokenType {
if self.amount != 0 {
if self.token_nonce == 0 {
EsdtTokenType::Fungible
} else if self.amount == 1u64 {
EsdtTokenType::NonFungible
} else {
EsdtTokenType::SemiFungible
}
} else {
EsdtTokenType::Invalid
}
}

pub fn is_fungible(&self) -> bool {
self.token_nonce == 0
}
Expand Down
Loading