Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Uniswap v2: Use internal pairFor call rather than cross contract call #19

Closed
HyunggyuJang opened this issue Oct 21, 2022 · 0 comments · Fixed by #20
Closed

Uniswap v2: Use internal pairFor call rather than cross contract call #19

HyunggyuJang opened this issue Oct 21, 2022 · 0 comments · Fixed by #20

Comments

@HyunggyuJang
Copy link
Collaborator

/// Original Uniswap Library pairFor function calculate pair contract address without making cross contract calls.
/// Please refer https://github.com/Uniswap/v2-periphery/blob/master/contracts/libraries/UniswapV2Library.sol#L18
///
/// In this contract, use cross contract call to get pair contract address.
default fn _pair_for(
&self,
factory: AccountId,
token_a: AccountId,
token_b: AccountId,
) -> Result<AccountId, RouterError> {
let (token_0, token_1) = self._sort_tokens(token_a, token_b)?;
let pair =
FactoryRef::get_pair(&factory, token_0, token_1).ok_or(RouterError::PairNotFound)?;
Ok(pair)
}

We should use internal call to query pair address, which also will be a good showcase how to retrieve predetermined contract address like the one from create2 of EVM.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant