@ethersproject/solidity#pack TypeScript Examples

The following examples show how to use @ethersproject/solidity#pack. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: pairs.ts    From limit-orders-lib with GNU General Public License v3.0 6 votes vote down vote up
getPancakeSwapPairAddress = (tokenA: Token, tokenB: Token): string => {
  const tokens = tokenA.sortsBefore(tokenB)
    ? [tokenA, tokenB]
    : [tokenB, tokenA]; // does safety checks

  return getCreate2Address(
    PANCAKESWAP_FACTORY_ADDRESS,
    keccak256(
      ["bytes"],
      [pack(["address", "address"], [tokens[0].address, tokens[1].address])]
    ),
    PANCAKESWAP_INIT_CODE_HASH
  );
}
Example #2
Source File: pair.ts    From vvs-ui with GNU General Public License v3.0 6 votes vote down vote up
public static getAddress(tokenA: Token, tokenB: Token): string {
    const tokens = tokenA.sortsBefore(tokenB) ? [tokenA, tokenB] : [tokenB, tokenA] // does safety checks
    const { chainId } = tokenA

    if (PAIR_ADDRESS_CACHE?.[tokens[0].address]?.[tokens[1].address] === undefined) {
      PAIR_ADDRESS_CACHE = {
        ...PAIR_ADDRESS_CACHE,
        [tokens[0].address]: {
          ...PAIR_ADDRESS_CACHE?.[tokens[0].address],
          [tokens[1].address]: getCreate2Address(
            FACTORY_ADDRESSES[chainId],
            keccak256(['bytes'], [pack(['address', 'address'], [tokens[0].address, tokens[1].address])]),
            INIT_CODE_HASHES[chainId]
          ),
        },
      }
    }

    return PAIR_ADDRESS_CACHE[tokens[0].address][tokens[1].address]
  }
Example #3
Source File: pair.ts    From sushiswap-exchange with GNU General Public License v3.0 6 votes vote down vote up
public static getAddress(tokenA: Token, tokenB: Token): string {
    const tokens = tokenA.sortsBefore(tokenB) ? [tokenA, tokenB] : [tokenB, tokenA] // does safety checks

    if (PAIR_ADDRESS_CACHE?.[tokens[0].address]?.[tokens[1].address] === undefined) {
      PAIR_ADDRESS_CACHE = {
        ...PAIR_ADDRESS_CACHE,
        [tokens[0].address]: {
          ...PAIR_ADDRESS_CACHE?.[tokens[0].address],
          [tokens[1].address]: getCreate2Address(
            FACTORY_ADDRESS,
            keccak256(['bytes'], [pack(['address', 'address'], [tokens[0].address, tokens[1].address])]),
            INIT_CODE_HASH
          )
        }
      }
    }

    return PAIR_ADDRESS_CACHE[tokens[0].address][tokens[1].address]
  }
Example #4
Source File: multiSend.ts    From snapshot-plugins with MIT License 6 votes vote down vote up
export function encodeTransactions(transactions: ModuleTransaction[]) {
  const values = transactions.map((tx) => [
    tx.operation,
    tx.to,
    tx.value,
    hexDataLength(tx.data || '0x'),
    tx.data || '0x'
  ]);

  const types = transactions.map(() => [
    'uint8',
    'address',
    'uint256',
    'uint256',
    'bytes'
  ]);

  return pack(types.flat(1), values.flat(1));
}
Example #5
Source File: pair.ts    From sdk with MIT License 6 votes vote down vote up
public static getAddress(tokenA: Token, tokenB: Token, chainId: ChainId = ChainId.AVALANCHE): string {
    const tokens = tokenA.sortsBefore(tokenB) ? [tokenA, tokenB] : [tokenB, tokenA] // does safety checks

    if (PAIR_ADDRESS_CACHE?.[tokens[0].address]?.[tokens[1].address] === undefined) {
      PAIR_ADDRESS_CACHE = {
        ...PAIR_ADDRESS_CACHE,
        [tokens[0].address]: {
          ...PAIR_ADDRESS_CACHE?.[tokens[0].address],
          [tokens[1].address]: getCreate2Address(
            FACTORY_ADDRESS[chainId],
            keccak256(['bytes'], [pack(['address', 'address'], [tokens[0].address, tokens[1].address])]),
            INIT_CODE_HASH
          )
        }
      }
    }

    return PAIR_ADDRESS_CACHE[tokens[0].address][tokens[1].address]
  }
Example #6
Source File: pair.ts    From pancake-swap-sdk with MIT License 6 votes vote down vote up
public static getAddress(tokenA: Token, tokenB: Token): string {
    const [token0, token1] = tokenA.sortsBefore(tokenB) ? [tokenA, tokenB] : [tokenB, tokenA] // does safety checks

    const key = composeKey(token0, token1)

    if (PAIR_ADDRESS_CACHE?.[key] === undefined) {
      PAIR_ADDRESS_CACHE = {
        ...PAIR_ADDRESS_CACHE,
        [key]: getCreate2Address(
          FACTORY_ADDRESS_MAP[token0.chainId],
          keccak256(['bytes'], [pack(['address', 'address'], [token0.address, token1.address])]),
          INIT_CODE_HASH_MAP[token0.chainId]
        )
      }
    }

    return PAIR_ADDRESS_CACHE[key]
  }
Example #7
Source File: pair.ts    From pancake-swap-sdk-testnet with MIT License 6 votes vote down vote up
public static getAddress(tokenA: Token, tokenB: Token): string {
    const tokens = tokenA.sortsBefore(tokenB) ? [tokenA, tokenB] : [tokenB, tokenA] // does safety checks

    if (PAIR_ADDRESS_CACHE?.[tokens[0].address]?.[tokens[1].address] === undefined) {
      PAIR_ADDRESS_CACHE = {
        ...PAIR_ADDRESS_CACHE,
        [tokens[0].address]: {
          ...PAIR_ADDRESS_CACHE?.[tokens[0].address],
          [tokens[1].address]: getCreate2Address(
            FACTORY_ADDRESS,
            keccak256(['bytes'], [pack(['address', 'address'], [tokens[0].address, tokens[1].address])]),
            INIT_CODE_HASH
          ),
        },
      }
    }

    return PAIR_ADDRESS_CACHE[tokens[0].address][tokens[1].address]
  }
Example #8
Source File: pairs.ts    From limit-orders-lib with GNU General Public License v3.0 6 votes vote down vote up
getDefySwapPairAddress = (tokenA: Token, tokenB: Token): string => {
  const tokens = tokenA.sortsBefore(tokenB)
    ? [tokenA, tokenB]
    : [tokenB, tokenA]; // does safety checks

  return getCreate2Address(
    DEFYSWAP_FACTORY_ADDRESS,
    keccak256(
      ["bytes"],
      [pack(["address", "address"], [tokens[0].address, tokens[1].address])]
    ),
    DEFYSWAP_INIT_CODE_HASH
  );
}
Example #9
Source File: pairs.ts    From limit-orders-lib with GNU General Public License v3.0 6 votes vote down vote up
getTraderJoePairAddress = (tokenA: Token, tokenB: Token): string => {
  const tokens = tokenA.sortsBefore(tokenB)
    ? [tokenA, tokenB]
    : [tokenB, tokenA]; // does safety checks

  return getCreate2Address(
    TRADERJOE_FACTORY_ADDRESS,
    keccak256(
      ["bytes"],
      [pack(["address", "address"], [tokens[0].address, tokens[1].address])]
    ),
    TRADERJOE_INIT_CODE_HASH
  );
}
Example #10
Source File: pair.ts    From QuickSwap-sdk with MIT License 6 votes vote down vote up
public static getAddress(tokenA: Token, tokenB: Token): string {
    const tokens = tokenA.sortsBefore(tokenB) ? [tokenA, tokenB] : [tokenB, tokenA] // does safety checks

    if (PAIR_ADDRESS_CACHE?.[tokens[0].address]?.[tokens[1].address] === undefined) {
      PAIR_ADDRESS_CACHE = {
        ...PAIR_ADDRESS_CACHE,
        [tokens[0].address]: {
          ...PAIR_ADDRESS_CACHE?.[tokens[0].address],
          [tokens[1].address]: getCreate2Address(
            FACTORY_ADDRESS,
            keccak256(['bytes'], [pack(['address', 'address'], [tokens[0].address, tokens[1].address])]),
            INIT_CODE_HASH
          )
        }
      }
    }

    return PAIR_ADDRESS_CACHE[tokens[0].address][tokens[1].address]
  }
Example #11
Source File: pairs.ts    From limit-orders-lib with GNU General Public License v3.0 6 votes vote down vote up
getCafeSwapPairAddress = (tokenA: Token, tokenB: Token): string => {
  const tokens = tokenA.sortsBefore(tokenB)
    ? [tokenA, tokenB]
    : [tokenB, tokenA]; // does safety checks

  return getCreate2Address(
    CAFESWAP_FACTORY_ADDRESS,
    keccak256(
      ["bytes"],
      [pack(["address", "address"], [tokens[0].address, tokens[1].address])]
    ),
    CAFESWAP_INIT_CODE_HASH
  );
}
Example #12
Source File: pairs.ts    From limit-orders-lib with GNU General Public License v3.0 6 votes vote down vote up
getPolydexPairAddress = (tokenA: Token, tokenB: Token): string => {
  const tokens = tokenA.sortsBefore(tokenB)
    ? [tokenA, tokenB]
    : [tokenB, tokenA]; // does safety checks

  return getCreate2Address(
    POLYDEX_FACTORY_ADDRESS,
    keccak256(
      ["bytes"],
      [pack(["address", "address"], [tokens[0].address, tokens[1].address])]
    ),
    POLYDEX_INIT_CODE_HASH
  );
}
Example #13
Source File: pairs.ts    From limit-orders-lib with GNU General Public License v3.0 6 votes vote down vote up
getUniswapPairAddress = (tokenA: Token, tokenB: Token): string => {
  const tokens = tokenA.sortsBefore(tokenB)
    ? [tokenA, tokenB]
    : [tokenB, tokenA]; // does safety checks

  return getCreate2Address(
    UNISWAP_FACTORY_ADDRESS,
    keccak256(
      ["bytes"],
      [pack(["address", "address"], [tokens[0].address, tokens[1].address])]
    ),
    UNISWAP_INIT_CODE_HASH
  );
}
Example #14
Source File: pairs.ts    From limit-orders-lib with GNU General Public License v3.0 6 votes vote down vote up
getSpookySwapPairAddress = (tokenA: Token, tokenB: Token): string => {
  const tokens = tokenA.sortsBefore(tokenB)
    ? [tokenA, tokenB]
    : [tokenB, tokenA]; // does safety checks

  return getCreate2Address(
    SPOOKY_SWAP_FACTORY_ADDRESS,
    keccak256(
      ["bytes"],
      [pack(["address", "address"], [tokens[0].address, tokens[1].address])]
    ),
    SPOOKY_SWAP_INIT_CODE_HASH
  );
}
Example #15
Source File: pairs.ts    From limit-orders-lib with GNU General Public License v3.0 6 votes vote down vote up
getQuickSwapPairAddress = (tokenA: Token, tokenB: Token): string => {
  const tokens = tokenA.sortsBefore(tokenB)
    ? [tokenA, tokenB]
    : [tokenB, tokenA]; // does safety checks

  return getCreate2Address(
    QUICK_SWAP_FACTORY_ADDRESS,
    keccak256(
      ["bytes"],
      [pack(["address", "address"], [tokens[0].address, tokens[1].address])]
    ),
    QUICK_SWAP_INIT_CODE_HASH
  );
}
Example #16
Source File: pairs.ts    From limit-orders-lib with GNU General Public License v3.0 6 votes vote down vote up
getSpiritSwapPairAddress = (tokenA: Token, tokenB: Token): string => {
  const tokens = tokenA.sortsBefore(tokenB)
    ? [tokenA, tokenB]
    : [tokenB, tokenA]; // does safety checks

  return getCreate2Address(
    SPIRIT_SWAP_FACTORY_ADDRESS,
    keccak256(
      ["bytes"],
      [pack(["address", "address"], [tokens[0].address, tokens[1].address])]
    ),
    SPIRIT_SWAP_INIT_CODE_HASH
  );
}
Example #17
Source File: pair.ts    From Elastos.Essentials.App with MIT License 6 votes vote down vote up
computePairAddress = ({
  initCodeHash,
  factoryAddress,
  tokenA,
  tokenB
}: {
  factoryAddress: string
  initCodeHash: string
  tokenA: Token
  tokenB: Token
}): string => {
  const [token0, token1] = tokenA.sortsBefore(tokenB) ? [tokenA, tokenB] : [tokenB, tokenA] // does safety checks
  return getCreate2Address(
    factoryAddress,
    keccak256(['bytes'], [pack(['address', 'address'], [token0.address, token1.address])]),
    initCodeHash
  )
}
Example #18
Source File: pair.ts    From spookyswap-sdk with MIT License 6 votes vote down vote up
public static getAddress(tokenA: Token, tokenB: Token): string {
    const tokens = tokenA.sortsBefore(tokenB) ? [tokenA, tokenB] : [tokenB, tokenA] // does safety checks

    if (PAIR_ADDRESS_CACHE?.[tokens[0].address]?.[tokens[1].address] === undefined) {
      PAIR_ADDRESS_CACHE = {
        ...PAIR_ADDRESS_CACHE,
        [tokens[0].address]: {
          ...PAIR_ADDRESS_CACHE?.[tokens[0].address],
          [tokens[1].address]: getCreate2Address(
            FACTORY_ADDRESS,
            keccak256(['bytes'], [pack(['address', 'address'], [tokens[0].address, tokens[1].address])]),
            INIT_CODE_HASH
          )
        }
      }
    }

    return PAIR_ADDRESS_CACHE[tokens[0].address][tokens[1].address]
  }