import { Interface, JsonFragment } from "@ethersproject/abi"; import Web3 from "web3"; import { AbiItem } from "web3-utils"; import { ERC20 } from "../../web3-types/ERC20"; import { MultiCall } from "../../web3-types/MultiCall"; import { NodeWallet } from "../../web3-types/NodeWallet"; import { OneClickFarm } from "../../web3-types/OneClickFarm"; import { Router } from "../../web3-types/Router"; import { StakingRewards } from "../../web3-types/StakingRewards"; import { WalletFactory } from "../../web3-types/WalletFactory"; import GAUGE_CONTROLLER_ABI from "../constants/abis/GaugeController.json"; import LENDING_POOL_ABI from "../constants/abis/LendingPool.json"; import LIQUIDITY_GAUGE_ABI from "../constants/abis/LiquidityGaugeV3.json"; import STABLE_SWAP_ABI from "../constants/abis/StableSwap.json"; import STAKING_ABI from "../constants/abis/StakingRewards.json"; import STAKING_REWARDS_ABI from "../constants/abis/StakingRewards.json"; import UNI_V2_PAIR_ABI from "../constants/abis/UniV2Pair.json"; import ERC20_ABI from "./abis/ERC20.json"; import MULTICALL_ABI from "./abis/MultiCall.json"; import WALLET_ABI from "./abis/NodeWallet.json"; import ONE_CLICK_ABI from "./abis/OneClickFarm.json"; import ROUTER_ABI from "./abis/Router.json"; import WALLET_FACTORY_ABI from "./abis/WalletFactory.json"; import { Address, ChainId, DEFAULT_CHAIN, MULTICALL_NETWORKS, WALLET_FACTORY_ADDRESS, } from "."; export const ERC20_INTERFACE = new Interface(ERC20_ABI); export const STABLE_SWAP_INTERFACE = new Interface(STABLE_SWAP_ABI); export const UNI_V2_PAIR_INTERFACE = new Interface(UNI_V2_PAIR_ABI); export const STAKING_REWARDS_INTERFACE = new Interface(STAKING_REWARDS_ABI); export const LIQUIDITY_GAUGE_INTERFACE = new Interface( LIQUIDITY_GAUGE_ABI as JsonFragment[] ); export const GAUGE_CONTROLLER_INTERFACE = new Interface( GAUGE_CONTROLLER_ABI as JsonFragment[] ); export const LENDING_POOL_INTERFACE = new Interface( LENDING_POOL_ABI as JsonFragment[] ); export const ROUTER_INTERFACE = new Interface(ROUTER_ABI as JsonFragment[]); export function getRouterContract(web3: Web3, address: Address): Router { return new web3.eth.Contract( ROUTER_ABI as AbiItem[], address ) as unknown as Router; } export function getOneClickFarm(web3: Web3, address: Address): OneClickFarm { return new web3.eth.Contract( ONE_CLICK_ABI as AbiItem[], address ) as unknown as OneClickFarm; } export function getWalletFactoryContract( web3: Web3, chain = ChainId.Celo ): WalletFactory { return new web3.eth.Contract( WALLET_FACTORY_ABI as AbiItem[], WALLET_FACTORY_ADDRESS[chain] ) as unknown as WalletFactory; } export function getWalletContract( web3: Web3, address: string ): NodeWallet | undefined { return new web3.eth.Contract(WALLET_ABI as AbiItem[], address) as unknown as | NodeWallet | undefined; } export function getErc20(web3: Web3, address: Address): ERC20 | undefined { return new web3.eth.Contract(ERC20_ABI as AbiItem[], address) as unknown as | ERC20 | undefined; } export function getMulticallContract( web3: Web3, chain = DEFAULT_CHAIN ): MultiCall { return new web3.eth.Contract( MULTICALL_ABI as AbiItem[], MULTICALL_NETWORKS[chain] ) as unknown as MultiCall; } export function getSNXContract( web3: Web3, address: string ): StakingRewards | null { return new web3.eth.Contract( STAKING_ABI as AbiItem[], address ) as unknown as StakingRewards | null; }