To create pairs, you can follow the steps outlined in this section. There are two forms of pools that can be created (AZERO/PSP22 or PSP22/PSP22) on the protocol and they have distinct approaches.
Note that creating a pair for two tokens that already exists would lead to a panic!
Creating an AZERO/PSP22 Pair
To create an AZERO/PSP22 pair, we can use the following approach:
fncreate_azero_pair(&self, psp22_token:AccountId) ->AccountId {let salt_int = ADDRESS_SALTING_INTEGER;let azero_pair:Result<Result<AccountId, LangError>, Error> =build_call::<DefaultEnvironment>().call_type(Call::new().callee(ROUTER_ADDRESS)).exec_input( ExecutionInput::new(Selector::new( [0x23, 0xc6, 0xff, 0xad] )).push_arg(psp22_token).push_arg(salt_int) ) .call_flags(CallFlags::default().set_allow_reentry(true)) //Ignore this line or set to false if it's not a reentrant call
.returns::<Result<AccountId, LangError>>().fire();match azero_pair {Err(_) => {panic!("Failed call") }Ok(Err(_)) => {panic!("Failed call") }Ok(Ok(_address)) =>return _address }}
Creating a PSP22/PSP22 Pair
To create a PSP22/PSP22 pair, we can use the following approach:
fncreate_azero_pair(&self, psp22_token_a:AccountId, psp22_token_b:AccountId) ->AccountId {let salt_int = ADDRESS_SALTING_INTEGER;let psp22_pair:Result<Result<AccountId, LangError>, Error> =build_call::<DefaultEnvironment>().call_type(Call::new().callee(ROUTER_ADDRESS)).exec_input( ExecutionInput::new(Selector::new( [0x50, 0x49, 0x5b, 0x96] )).push_arg(psp22_token_a).push_arg(psp22_token_b).push_arg(salt_int) ) .call_flags(CallFlags::default().set_allow_reentry(true)) //Ignore this line or set to false if it's not a reentrant call
.returns::<Result<AccountId, LangError>>().fire();match psp22_pair {Err(_) => {panic!("Failed call") }Ok(Err(_)) => {panic!("Failed call") }Ok(Ok(_address)) =>return _address }}