Pair Addresses
Bu açık kaynak protokol/SDK referansı TurkDex markasıyla sunulan uyarlamadır; sayfadaki entegrasyon örnekleri Turkchain’de etkin özelliklerin garantisi değildir. Ağ, kontrat ve işlem değerlerinde yalnızca bu kurulumun doğrulanmış ENV/registry bilgilerini kullanın.
getPair
The most obvious way to get the address for a pair is to call getPair on the factory. If the pair exists, this function will return its address, else address(0) (0x0000000000000000000000000000000000000000).
- The "canonical" way to determine whether or not a pair exists.
- Requires an onchain lookup.
CREATE2
Thanks to some fancy footwork in the factory, we can also compute pair addresses _without any onchain lookups_ because of CREATE2. The following values are required for this technique:
address | The factory address |
salt | keccak256(abi.encodePacked(token0, token1)) |
keccak256(init_code) | 0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f |
token0must be strictly less thantoken1by sort order.
- Can be computed offline.
- Requires the ability to perform
keccak256.
Examples
TypeScript
This example makes use of the TurkDex v2 SDK. In reality, the SDK computes pair addresses behind the scenes, obviating the need to compute them manually like this.
import from '@uniswap/v2-sdk'
import from '@ethersproject/solidity'
import from '@ethersproject/address'
const token0 = '0xCAFE000000000000000000000000000000000000' // change me!
const token1 = '0xF00D000000000000000000000000000000000000' // change me!
const pair = getCreate2Address(
FACTORY_ADDRESS,
keccak256(['bytes'], [pack(['address', 'address'], [token0, token1])]),
INIT_CODE_HASH
)Uyarlanmış geliştirici referansı. Kaynak: kaynak dokümantasyon reposu. Kaynak ve lisans bildirimi: NOTICE.