Albert Lipaev
Albert Lipaev

Reputation: 76

I am trying to make the fork of Pancakeswap and I am currently being stuck on generating my own token pairs address for my factory and init_hash_code

As the title said, I have my own implementations of cake token, factory and router. As far as I got it, the factory and init_code_hash are correct. The issue is that even after changing them in pancakeswap SDK it still generates pairs for the original pancakeswap and not my implementation.

const pairAddresses = useMemo(
    () =>
      tokens.map(([tokenA, tokenB]) => {
        try {
          if (tokenA && tokenB && !tokenA.equals(tokenB)) {
            // line of code responsible for pair fetching
            const pairAddress = Pair.getAddress(tokenA, tokenB)
            console.log(`Pair Address for ${tokenA.address} and ${tokenB.address}: ${pairAddress}`)
            return pairAddress
          } else {
            return undefined
          }
        } catch (error: any) {
          console.error(
            error.msg,
            `- pairAddresses: ${tokenA?.address}-${tokenB?.address}`,
            `chainId: ${tokenA?.chainId}`,
          )
          return undefined
        }
      }),
    [tokens],
  )

I am aware that Pair.getAddresses is responsible for fetching the addresses of LP pairs however there is no declaration of factory or init_code_hash anywhere in the code.

import { Price } from './fractions/price';
import { TokenAmount } from './fractions/tokenAmount';
import { BigintIsh, ChainId } from '../constants';
import { Token } from './token';
export declare class Pair {
    readonly liquidityToken: Token;
    private readonly tokenAmounts;
    static getAddress(tokenA: Token, tokenB: Token): string;
    constructor(tokenAmountA: TokenAmount, tokenAmountB: TokenAmount);
    /**
     * Returns true if the token is either token0 or token1
     * @param token to check
     */
    involvesToken(token: Token): boolean;
    /**
     * Returns the current mid price of the pair in terms of token0, i.e. the ratio of reserve1 to reserve0
     */
    get token0Price(): Price;
    /**
     * Returns the current mid price of the pair in terms of token1, i.e. the ratio of reserve0 to reserve1
     */
    get token1Price(): Price;
    /**
     * Return the price of the given token in terms of the other token in the pair.
     * @param token token to return price of
     */
    priceOf(token: Token): Price;
    /**
     * Returns the chain ID of the tokens in the pair.
     */
    get chainId(): ChainId;
    get token0(): Token;
    get token1(): Token;
    get reserve0(): TokenAmount;
    get reserve1(): TokenAmount;
    reserveOf(token: Token): TokenAmount;
    getOutputAmount(inputAmount: TokenAmount): [TokenAmount, Pair];
    getInputAmount(outputAmount: TokenAmount): [TokenAmount, Pair];
    getLiquidityMinted(totalSupply: TokenAmount, tokenAmountA: TokenAmount, tokenAmountB: TokenAmount): TokenAmount;
    getLiquidityValue(token: Token, totalSupply: TokenAmount, liquidity: TokenAmount, feeOn?: boolean, kLast?: BigintIsh): TokenAmount;
}

How do I make it work with my implementations of router and factory smart contracts? Thank you!

Upvotes: 0

Views: 44

Answers (0)

Related Questions