Create Pair
If you are starting the tutorial from here, please check out this branch and open it in your IDE.
1. Add Create Pair to Factory Trait
We will implement the createPair function of the Factory contract.
In the ./logics/traits/factory.rs file, add the create_pair function to the Factory trait, as well as the internal child function _instantiate_pair that will need to be implemented in the contract crate.
The reason why we need an internal _instantiate_pair function here is because the instantiate builder is not part of the #[openbrush::wrapper]
, so we will need to use the one from ink! by importing the Pair contract as an ink-as-dependancy
.
The create_pair message function returns the address of the instantiated Pair contract.
The function that emits a create_pair event will also have to be implemented in the contract:
pub trait Factory {
...
#[ink(message)]
fn create_pair(
&mut self,
token_a: AccountId,
token_b: AccountId,
) -> Result<AccountId, FactoryError>;
fn _instantiate_pair(&mut self, salt_bytes: &[u8]) -> Result<AccountId, FactoryError>;
...
fn _emit_create_pair_event(
&self,
_token_0: AccountId,
_token_1: AccountId,
_pair: AccountId,
_pair_len: u64,
);
}