@kiroboio/fct-plugins
v1.3.39
Published
Plugins to create Fct calls
Downloads
1,356
Keywords
Readme
FCT PROVIDER
Uniswap Provider
import { ethers } from 'ethers'
import { FctProvider, UNISWAP_TYPE } from '@@kiroboio/fct-contracts/ki-eth-fct-provider'
const provider = new ethers.providers.JsonRpcProvider('https://mainnet.infura.io/v3/infura_id')
export const uniswap = new FctProvider({
library: provider,
chainId: 1,
account: 'wallet_address',
}).uniswap
export const testTokenPair = ({
inputToken,
outputToken,
}: {
inputToken: {
decimals: number
address: string
}
outputToken: {
decimals: number
address: string
}
}) => {
it('Should return uniswap values for exact output', async () => {
const amount = Math.floor(Math.random() * 1000).toString()
const values = await uniswap.getSwapValues({
input: {
currency: inputToken,
},
output: {
amount,
currency: outputToken,
},
})
expect(values.type).toEqual(UNISWAP_TYPE.EXACT_OUTPUT)
expect(values.outputAmountFormatted).toEqual(amount)
expect(values.inputAmountFormatted).toBeDefined()
expect(values.state).toEqual('VALID')
expect(values.swapCalls).toHaveLength(1)
})
it('Should return uniswap values for exact input', async () => {
const amount = Math.floor(Math.random() * 1000).toString()
const values = await uniswap.getSwapValues({
input: {
amount,
currency: inputToken,
},
output: {
currency: outputToken,
},
})
expect(values.type).toEqual(UNISWAP_TYPE.EXACT_INPUT)
expect(values.inputAmountFormatted).toEqual(amount)
expect(values.outputAmountFormatted).toBeDefined()
expect(values.state).toEqual('VALID')
expect(values.swapCalls).toHaveLength(1)
})
it('Should return uniswap invalid trade for big output values', async () => {
const amount = '1000000000'
const values = await uniswap.getSwapValues({
input: {
currency: inputToken,
},
output: {
amount,
currency: outputToken,
},
})
expect(values.type).toEqual(UNISWAP_TYPE.EXACT_OUTPUT)
expect(values.outputAmountFormatted).toEqual(amount)
expect(values.inputAmountFormatted).toBeUndefined()
expect(values.state).toEqual('INVALID')
expect(values.swapCalls).toHaveLength(0)
})
}