synapsecns/sanguine

View on GitHub
packages/synapse-interface/actions/swapPoolCalculateTokenAmount.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { readContract } from '@wagmi/core'

import { getSwapDepositContractFields } from '@/utils/getSwapDepositContractFields'
import { Token } from '@/utils/types'
import { wagmiConfig } from '@/wagmiConfig'

export const swapPoolCalculateTokenAmount = async ({
  chainId,
  pool,
  inputAmounts,
}: {
  chainId: number
  pool: Token
  inputAmounts: any
}) => {
  const { abi, poolAddress } = getSwapDepositContractFields(pool, chainId)

  const minToMint = await readContract(wagmiConfig, {
    chainId,
    address: poolAddress,
    abi,
    functionName: 'calculateTokenAmount',
    args: [Object.values(inputAmounts), true],
  })

  return minToMint
}