Skip to content

Commit

Permalink
Add documentation for pair_for
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunggyuJang committed Oct 24, 2022
1 parent 53e2b93 commit 577e066
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 0 additions & 1 deletion uniswap-v2/logics/impls/router/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ pub const STORAGE_KEY: u32 = openbrush::storage_unique_key!(Data);
#[openbrush::upgradeable_storage(STORAGE_KEY)]
pub struct Data {
pub factory: AccountId,
// TODO: remove pair code hash as like /~https://github.com/Uniswap/v2-periphery/blob/master/contracts/libraries/UniswapV2Library.sol#L18
pub pair_code_hash: Hash,
}
7 changes: 6 additions & 1 deletion uniswap-v2/logics/impls/router/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,13 +426,18 @@ impl<T: Storage<data::Data>> Router for T {
Ok(())
}

/// 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 precomputed address like Uniswap's, as ink!'s deployment is done via create2-like one by default.
/// Please refer /~https://github.com/paritytech/substrate/blob/493b58bd4a475080d428ce47193ee9ea9757a808/frame/contracts/src/lib.rs#L178
/// for how contract's address is calculated.
default fn _pair_for(
&self,
factory: AccountId,
token_a: AccountId,
token_b: AccountId,
) -> Result<AccountId, RouterError> {
// TODO: remove pair code hash after deployment
let tokens = self._sort_tokens(token_a, token_b)?;
let salt = &Self::env().hash_encoded::<Blake2x256, _>(&tokens)[..4];
let input: Vec<_> = AsRef::<[u8]>::as_ref(&factory)
Expand Down

0 comments on commit 577e066

Please sign in to comment.