@kiroboio/fct-plugins
TypeScript icon, indicating that this package has built-in type declarations

1.3.16 • Public • Published

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)
  })
}

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.3.16103latest

Version History

VersionDownloads (Last 7 Days)Published
1.3.16103
1.3.150
1.3.140
1.3.130
1.3.120
1.3.110
1.3.102
1.3.90
1.3.80
1.3.70
1.3.60
1.3.50
1.3.40
1.3.20
1.3.10
1.3.00
1.2.990
1.2.980
1.2.960
1.2.950
1.2.940
1.2.910
1.2.900
1.2.890
1.2.880
1.2.870
1.2.860
1.2.850
1.2.840
1.2.830
1.2.820
1.2.810
1.2.800
1.2.790
1.2.780
1.2.770
1.2.760
1.2.750
1.2.740
1.2.730
1.2.720
1.2.710
1.2.700
1.2.690
1.2.680
1.2.670
1.2.660
1.2.650
1.2.640
1.2.620
1.2.610
1.2.600
1.2.590
1.2.580
1.2.560
1.2.550
1.2.540
1.2.530
1.2.520
1.2.510
1.2.500
1.2.490
1.2.480
1.2.470
1.2.460
1.2.450
1.2.440
1.2.420
1.2.410
1.2.400
1.2.390
1.2.380
1.2.370
1.2.360
1.2.350
1.2.340
1.2.330
1.2.320
1.2.310
1.2.300
1.2.290
1.2.280
1.2.270
1.2.260
1.2.250
1.2.240
1.2.230
1.2.220
1.2.210
1.2.200
1.2.190
1.2.180
1.2.170
1.2.160
1.2.150
1.2.140
1.2.130
1.2.120
1.2.110
1.2.100
1.2.90
1.2.80
1.2.70
1.2.60
1.2.50
1.2.30
1.2.20
1.2.10
1.1.6760
1.1.6740
1.1.6730
1.1.6720
1.1.6710
1.1.6700
1.1.6690
1.1.6670
1.1.6660
1.1.6650
1.1.6640
1.1.6630
1.1.6610
1.1.6600
1.1.6580
1.1.6530
1.1.6520
1.1.6500
1.1.6490
1.1.6481
1.1.6470
1.1.6460
1.1.6450
1.1.6440
1.1.6430
1.1.6420
1.1.6410
1.1.6400
1.1.6390
1.1.6380
1.1.6360
1.1.6350
1.1.6330
1.1.6320
1.1.6310
1.1.6300
1.1.6290
1.1.6280
1.1.6270
1.1.6260
1.1.6250
1.1.6240
1.1.6230
1.1.6220
1.1.6210
1.1.6200
1.1.6170
1.1.6140
1.1.6130
1.1.6120
1.1.6100
1.1.6090
1.1.6080
1.1.6060
1.1.6050
1.1.6040
1.1.6030
1.1.6020
1.1.6010
1.1.6000
1.1.5990
1.1.5980
1.1.5970
1.1.5960
1.1.5950
1.1.5940
1.1.5930
1.1.5920
1.1.5910
1.1.5900
1.1.5890
1.1.5880
1.1.5870
1.1.5830
1.1.5820
1.1.5810
1.1.5790
1.1.5780
1.1.5760
1.1.5740
1.1.5730
1.1.5720
1.1.5710
1.1.5700
1.1.5690
1.1.5651
1.1.5640
1.1.5630
1.1.5620
1.1.5610
1.1.5600
1.1.5590
1.1.5580
1.1.5570
1.1.5560
1.1.5550
1.1.5540
1.1.5530
1.1.5510
1.1.5490
1.1.5450
1.1.5440
1.1.5430
1.1.5421
1.1.5410
1.1.5400
1.1.5390
1.1.5380
1.1.5370
1.1.5360
1.1.5330
1.1.5320
1.1.5310
1.1.5290
1.1.5280
1.1.5261
1.1.5230
1.1.5210
1.1.5200
1.1.5190
1.1.5180
1.1.5170
1.1.5160
1.1.5150
1.1.5140
1.1.5130
1.1.5100
1.1.5090
1.1.5080
1.1.5070
1.1.5060
1.1.5050
1.1.5040
1.1.5030
1.1.5020
1.1.5010
1.1.4990
1.1.4970
1.1.4961
1.1.4950
1.1.4940
1.1.4930
1.1.4921
1.1.4910
1.1.4890
1.1.4880
1.1.4870
1.1.4860
1.1.4850
1.1.4840
1.1.4830
1.1.4820
1.1.4790
1.1.4780
1.1.4770
1.1.4760
1.1.4740
1.1.4730
1.1.4720
1.1.4710
1.1.4700
1.1.4690
1.1.4680
1.1.4670
1.1.4660
1.1.4650
1.1.4640
1.1.4630
1.1.4620
1.1.4610
1.1.4590
1.1.4580
1.1.4571
1.1.4560
1.1.4551
1.1.4540
1.1.4530
1.1.4511
1.1.4500
1.1.4491
1.1.4480
1.1.4450
1.1.4430
1.1.4410
1.1.4400
1.1.4390
1.1.4380
1.1.4370
1.1.4360
1.1.4350
1.1.4330
1.1.4310
1.1.4300
1.1.4270
1.1.4250
1.1.4240
1.1.4230
1.1.4210
1.1.4200
1.1.4160
1.1.4140
1.1.4130
1.1.4120
1.1.4110
1.1.4100
1.1.4090
1.1.4081
1.1.4060
1.1.4050
1.1.4030
1.1.4010
1.1.4000
1.1.3990
1.1.3980
1.1.3970
1.1.3960
1.1.3950
1.1.3940
1.1.3930
1.1.3890
1.1.3880
1.1.3870
1.1.3860
1.1.3851
1.1.3840
1.1.3830
1.1.3820
1.1.3810
1.1.3800
1.1.3790
1.1.3780
1.1.3770
1.1.3750
1.1.3740
1.1.3650
1.1.3640
1.1.3630
1.1.3620
1.1.3611
1.1.3600
1.1.3590
1.1.3580
1.1.3570
1.1.3560
1.1.3540
1.1.3530
1.1.3520
1.1.3510
1.1.3500
1.1.3490
1.1.3480
1.1.3470
1.1.3460
1.1.3450
1.1.3440
1.1.3430
1.1.3410
1.1.3400
1.1.3390
1.1.3380
1.1.3360
1.1.3350
1.1.3341
1.1.3330
1.1.3320
1.1.3310
1.1.3300
1.1.3290
1.1.3280
1.1.3270
1.1.3260
1.1.3250
1.1.3240
1.1.3230
1.1.3220
1.1.3210
1.1.3190
1.1.3180
1.1.3170
1.1.3150
1.1.3140
1.1.3130
1.1.3120
1.1.3110
1.1.3060
1.1.3050
1.1.3040
1.1.3030
1.1.3020
1.1.3010
1.1.3000
1.1.2990
1.1.2980
1.1.2971
1.1.2960
1.1.2950
1.1.2940
1.1.2910
1.1.2900
1.1.2890
1.1.2880
1.1.2860
1.1.2850
1.1.2840
1.1.2830
1.1.2810
1.1.2790
1.1.2780
1.1.2770
1.1.2760
1.1.2750
1.1.2740
1.1.2730
1.1.2710
1.1.2700
1.1.2680
1.1.2650
1.1.2630
1.1.2620
1.1.2610
1.1.2600
1.1.2590
1.1.2580
1.1.2570
1.1.2561
1.1.2550
1.1.2530
1.1.2510
1.1.2500
1.1.2470
1.1.2460
1.1.2450
1.1.2430
1.1.2421
1.1.2410
1.1.2371
1.1.2360
1.1.2350
1.1.2340
1.1.2331
1.1.2290
1.1.2280
1.1.2271
1.1.2240
1.1.2231
1.1.2220
1.1.2210
1.1.2200
1.1.2190
1.1.2180
1.1.2160
1.1.2150
1.1.2140
1.1.2130
1.1.2120
1.1.2110
1.1.2100
1.1.2090
1.1.2080
1.1.2070
1.1.2060
1.1.2050
1.1.2030
1.1.2020
1.1.1960
1.1.1950
1.1.1940
1.1.1930
1.1.1920
1.1.1910
1.1.1900
1.1.1890
1.1.1880
1.1.1870
1.1.1861
1.1.1850
1.1.1840
1.1.1831
1.1.1800
1.1.1790
1.1.1770
1.1.1750
1.1.1730
1.1.1720
1.1.1710
1.1.1700
1.1.1690
1.1.1670
1.1.1660
1.1.1650
1.1.1640
1.1.1620
1.1.1610
1.1.1591
1.1.1571
1.1.1560
1.1.1531
1.1.1520
1.1.1510

Package Sidebar

Install

npm i @kiroboio/fct-plugins

Weekly Downloads

131

Version

1.3.16

License

LGPL-3.0-only

Unpacked Size

50 MB

Total Files

1819

Last publish

Collaborators

  • liorcohenn
  • brenzee
  • bigcheeseh
  • liorc
  • talasa
  • asafna2
  • talasa-kiroboio
  • talbtc