I've implemented use primitive_types::U256
and now I'm trying to return a U256
int as a result from one of my functions, but I'm getting the following error: the trait TypeInfo
is not implemented for primitive_types::U256
, I understand that I need to implement TypeInfo
in my smart contract but I just don't understand how.
Here is the mentioned function:
#[ink(message)]
pub fn get_est_price_psp22_to_a01(
&self,
psp22_amount_in:Balance
) -> Result<U256, TradingPairErrors> {
let caller = self.env().caller();
//fetching caller current PSP22 balance
let caller_current_balance:Balance = PSP22Ref::balance_of(
&self.panx_contract,
caller
);
let actual_fee:Balance;
//calculating the actual LP fee
match self.fee.checked_div(10u128.pow(18)) {
Some(result) => {
actual_fee = result;
}
None => {
return Err(TradingPairErrors::Overflow);
}
};
let mut amount_in_with_lp_fees:Balance;
//reducting the LP fee from the PSP22 amount in
match psp22_amount_in.checked_mul(100u128 - actual_fee) {
Some(result) => {
amount_in_with_lp_fees = result;
}
None => {
return Err(TradingPairErrors::Overflow);
}
};
let tokens_to_validate:Balance = 3500u128 * 10u128.pow(18);
//validating if caller has more than 3500 PANX to verify if the caller is eligible for the incentive program
if caller_current_balance >= tokens_to_validate{
if self.fee <= 1400000000000u128 {
//reducting HALF of the LP fee from PSP22 amount in, if the caller has more than 3500 PANX and the LP fee is less than 1.4%
match psp22_amount_in.checked_mul(100u128 - (actual_fee / 2u128)) {
Some(result) => {
amount_in_with_lp_fees = result;
}
None => {
return Err(TradingPairErrors::Overflow);
}
};
}
if self.fee > 1400000000000u128 {
//reducting (LP fee - 1) of the LP fee from PSP22 amount in, if the caller has more than 3500 PANX and the LP fee is more than 1.4%
match psp22_amount_in.checked_mul(100u128 - (actual_fee - 1u128)) {
Some(result) => {
amount_in_with_lp_fees = result;
}
None => {
return Err(TradingPairErrors::Overflow);
}
};
}
}
let a0_amount_out = self.casted_div(amount_in_with_lp_fees * self.get_a0_balance(),(self.get_psp22_balance() * 100u128) + amount_in_with_lp_fees);
//calculating the final A0 amount to transfer to the caller.
//match (amount_in_with_lp_fees * self.get_a0_balance()).checked_div((self.get_psp22_balance() * 100u128) + amount_in_with_lp_fees) {
// Some(result) => {
// a0_amount_out = result;
// }
// None => {
// return Err(TradingPairErrors::Overflow);
// }
//};
Ok(a0_amount_out)
}
I'm using casted_div
function which takes two u128
objects and turns them into U256
:
fn casted_div(
&self,
value1: u128,
value2: u128
) -> U256 {
U256::from(value1) / U256::from(value2)
}
Thank you and have a pleasant day.