pub struct TwoResourcePoolBlueprint;

Implementations§

source§

impl TwoResourcePoolBlueprint

source

pub fn instantiate<Y>( (resource_address1, resource_address2): (ResourceAddress, ResourceAddress), owner_role: OwnerRole, pool_manager_rule: AccessRule, address_reservation: Option<GlobalAddressReservation>, api: &mut Y ) -> Result<TwoResourcePoolInstantiateOutput, RuntimeError>

source

pub fn contribute<Y>( (bucket1, bucket2): (Bucket, Bucket), api: &mut Y ) -> Result<TwoResourcePoolContributeOutput, RuntimeError>

Contributes resources to the pool and mints pool units back representing the contributed resources.

In much of a similar way to the single resource pool, there are a number of states that this pool can be in, there are more states than the single resource pool since this pool has the 2 resource reserves instead of one.

To examine the behavior of this function, lets first define the terminology to use: Let PU denote the total supply of pool units where 0 means that none exists and 1 means that some amount exists. Let R1 denote the total amount of reserves of resource 1 that the pool has where 0 here means that no reserves exist in the pool and 1 means that some reserves exist in the pool and R2 be the equivalent of R1 but for resource 2.

PU R1 R2 0 0 0 => This a new pool since no pool units currently exist in circulation and there are no reserves of either of the resources. This contribution is accepted in full with no change and the geometric mean of the contribution amounts will be minted as pool units. 0 0 1 => This is a new pool since no pool units exist in circulation but some dust is left behind in the pool from it being used in the past. 0 1 0 => This is a new pool since no pool units exist in circulation but some dust is left behind in the pool from it being used in the past. 0 1 1 => This is a new pool since no pool units exist in circulation but some dust is left behind in the pool from it being used in the past. 1 0 0 => This is an illegal state and contributions in this state are not allowed! This is due to some pool units existing in circulation but the pool has no reserves of either of the assets. The contributor should have 100% pool ownership from their contribution but some people already have some pool units. The pool will not accept contributions when it is in this state. 1 0 1 => The pool accepts one sided liquidity of R2 and returns all of the given R1 as change. The amount of pool units minted is equal to the ratio of the R2 contribution to the R2 reserves. 1 1 0 => The pool accepts one sided liquidity of R1 and returns all of the given R2 as change. The amount of pool units minted is equal to the ratio of the R1 contribution to the R1 reserves. 1 1 1 => The pool is in normal operation and both resources are accepted where some of them will be contributed and some of them will be change.

There are common patterns that can be seen from the states above:

  • State 1: When PU = 0 the pool is considered new, the amount of reserves do not really matter as the amount of pool units that the pool mins is the same.
  • State 2: When PU = 1 and all reserves are empty then this is an illegal state that the pool can’t really do anything about.
  • State 3: When PU = 1 and some but not all of the reserves are empty then the resources with the empty reserves are not contributed to the pool and are returned as change.
  • State 4: When all is 1 then the pool is in normal operations.

The above state names will be used in tests as its better than calling them out by name or by description. A simple state x is a lot simpler.

source

pub fn redeem<Y>( bucket: Bucket, api: &mut Y ) -> Result<TwoResourcePoolRedeemOutput, RuntimeError>

source

pub fn protected_deposit<Y>( bucket: Bucket, api: &mut Y ) -> Result<TwoResourcePoolProtectedDepositOutput, RuntimeError>

source

pub fn protected_withdraw<Y>( resource_address: ResourceAddress, amount: Decimal, withdraw_strategy: WithdrawStrategy, api: &mut Y ) -> Result<TwoResourcePoolProtectedWithdrawOutput, RuntimeError>

source

pub fn get_redemption_value<Y>( amount_of_pool_units: Decimal, api: &mut Y ) -> Result<TwoResourcePoolGetRedemptionValueOutput, RuntimeError>

source

pub fn get_vault_amounts<Y>( api: &mut Y ) -> Result<TwoResourcePoolGetVaultAmountsOutput, RuntimeError>

source

fn with_state<Y, F, O>(api: &mut Y, callback: F) -> Result<O, RuntimeError>

source

fn calculate_amount_owed( pool_units_to_redeem: Decimal, pool_units_total_supply: Decimal, reserves: IndexMap<ResourceAddress, ReserveResourceInformation> ) -> Result<IndexMap<ResourceAddress, Decimal>, RuntimeError>

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<U> As for U

§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V