import {Abi, erc20Abi} from "viem";

import ArbitrumNodeInterface from "./ArbitrumNodeInterface.json" with {type: "json"};
import ClaimHandler from "./ClaimHandler.json" with {type: "json"};
import CustomErrors from "./CustomErrors.json" with {type: "json"};
import DataStore from "./DataStore.json" with {type: "json"};
import ERC20PermitInterface from "./ERC20PermitInterface.json" with {type: "json"};
import ERC721 from "./ERC721.json" with {type: "json"};
import EventEmitter from "./EventEmitter.json" with {type: "json"};
import ExchangeRouter from "./ExchangeRouter.json" with {type: "json"};
import GelatoRelayRouter from "./GelatoRelayRouter.json" with {type: "json"};
import GlpManager from "./GlpManager.json" with {type: "json"};
import GlvReader from "./GlvReader.json" with {type: "json"};
import GlvRouter from "./GlvRouter.json" with {type: "json"};
import GMT from "./GMT.json" with {type: "json"};
import GmxMigrator from "./GmxMigrator.json" with {type: "json"};
import GovToken from "./GovToken.json" with {type: "json"};
import LayerZeroProvider from "./LayerZeroProvider.json" with {type: "json"};
import MintableBaseToken from "./MintableBaseToken.json" with {type: "json"};
import Multicall from "./Multicall.json" with {type: "json"};
import MultichainClaimsRouter from "./MultichainClaimsRouter.json" with {type: "json"};
import MultichainGlvRouter from "./MultichainGlvRouter.json" with {type: "json"};
import MultichainGmRouter from "./MultichainGmRouter.json" with {type: "json"};
import MultichainOrderRouter from "./MultichainOrderRouter.json" with {type: "json"};
import MultichainSubaccountRouter from "./MultichainSubaccountRouter.json" with {type: "json"};
import MultichainTransferRouter from "./MultichainTransferRouter.json" with {type: "json"};
import MultichainUtils from "./MultichainUtils.json" with {type: "json"};
import MultichainVault from "./MultichainVault.json" with {type: "json"};
import OrderBook from "./OrderBook.json" with {type: "json"};
import OrderBookReader from "./OrderBookReader.json" with {type: "json"};
import OrderExecutor from "./OrderExecutor.json" with {type: "json"};
import PositionManager from "./PositionManager.json" with {type: "json"};
import PositionRouter from "./PositionRouter.json" with {type: "json"};
import Reader from "./Reader.json" with {type: "json"};
import ReaderV2 from "./ReaderV2.json" with {type: "json"};
import ReferralStorage from "./ReferralStorage.json" with {type: "json"};
import RelayParams from "./RelayParams.json" with {type: "json"};
import RewardReader from "./RewardReader.json" with {type: "json"};
import RewardRouter from "./RewardRouter.json" with {type: "json"};
import RewardTracker from "./RewardTracker.json" with {type: "json"};
import RouterV2 from "./Router-v2.json" with {type: "json"};
import Router from "./Router.json" with {type: "json"};
import SmartAccount from "./SmartAccount.json" with {type: "json"};
import StBTC from "./StBTC.json" with {type: "json"};
import SubaccountGelatoRelayRouter from "./SubaccountGelatoRelayRouter.json" with {type: "json"};
import SubaccountRouter from "./SubaccountRouter.json" with {type: "json"};
import SyntheticsReader from "./SyntheticsReader.json" with {type: "json"};
import SyntheticsRouter from "./SyntheticsRouter.json" with {type: "json"};
import Timelock from "./Timelock.json" with {type: "json"};
import Token from "./Token.json" with {type: "json"};
import Treasury from "./Treasury.json" with {type: "json"};
import UniPool from "./UniPool.json" with {type: "json"};
import UniswapV2 from "./UniswapV2.json" with {type: "json"};
import Vault from "./Vault.json" with {type: "json"};
import VaultReader from "./VaultReader.json" with {type: "json"};
import VaultV2 from "./VaultV2.json" with {type: "json"};
import VaultV2b from "./VaultV2b.json" with {type: "json"};
import Vester from "./Vester.json" with {type: "json"};
import WETH from "./WETH.json" with {type: "json"};
import YieldFarm from "./YieldFarm.json" with {type: "json"};
import YieldToken from "./YieldToken.json" with {type: "json"};

export type AbiId =
  | "AbstractSubaccountApprovalNonceable"
  | "ArbitrumNodeInterface"
  | "ClaimHandler"
  | "CustomErrors"
  | "DataStore"
  | "ERC20"
  | "ERC20PermitInterface"
  | "ERC20PermitInterface"
  | "ERC721"
  | "EventEmitter"
  | "ExchangeRouter"
  | "GelatoRelayRouter"
  | "GelatoRelayRouter"
  | "GlpManager"
  | "GlvReader"
  | "GlvRouter"
  | "GMT"
  | "GmxMigrator"
  | "GovToken"
  | "LayerZeroProvider"
  | "MintableBaseToken"
  | "Multicall"
  | "MultichainClaimsRouter"
  | "MultichainGlvRouter"
  | "MultichainGmRouter"
  | "MultichainOrderRouter"
  | "MultichainSubaccountRouter"
  | "MultichainTransferRouter"
  | "MultichainUtils"
  | "MultichainVault"
  | "OrderBook"
  | "OrderBookReader"
  | "OrderExecutor"
  | "PositionManager"
  | "PositionRouter"
  | "Reader"
  | "ReaderV2"
  | "ReferralStorage"
  | "RelayParams"
  | "RewardReader"
  | "RewardRouter"
  | "RewardTracker"
  | "Router"
  | "RouterV2"
  | "SmartAccount"
  | "StBTC"
  | "SubaccountGelatoRelayRouter"
  | "SubaccountGelatoRelayRouter"
  | "SubaccountRouter"
  | "SyntheticsReader"
  | "SyntheticsRouter"
  | "Timelock"
  | "Token"
  | "Treasury"
  | "UniPool"
  | "UniswapV2"
  | "Vault"
  | "VaultReader"
  | "VaultV2"
  | "VaultV2b"
  | "Vester"
  | "WETH"
  | "YieldFarm"
  | "YieldToken";

/** Copied from ethers to enable compatibility with GMX UI */
interface JsonFragmentType {
  readonly name?: string;
  readonly indexed?: boolean;
  readonly type?: string;
  readonly internalType?: string;
  readonly components?: ReadonlyArray<JsonFragmentType>;
}

interface JsonFragment {
  readonly name?: string;
  readonly type?: string;
  readonly anonymous?: boolean;
  readonly payable?: boolean;
  readonly constant?: boolean;
  readonly stateMutability?: string;
  readonly inputs?: ReadonlyArray<JsonFragmentType>;
  readonly outputs?: ReadonlyArray<JsonFragmentType>;
  readonly gas?: string;
}

const AbstractSubaccountApprovalNonceable = [
  {
    inputs: [
      {
        internalType: "address",
        name: "",
        type: "address",
      },
    ],
    name: "subaccountApprovalNonces",
    outputs: [
      {
        internalType: "uint256",
        name: "",
        type: "uint256",
      },
    ],
    stateMutability: "view",
    type: "function",
  },
] as const;

export const abis: Record<AbiId, readonly (Abi[number] & JsonFragment)[]> = {
  AbstractSubaccountApprovalNonceable,
  ArbitrumNodeInterface: ArbitrumNodeInterface.abi,
  ClaimHandler: ClaimHandler.abi,
  CustomErrors: CustomErrors.abi,
  DataStore: DataStore.abi,
  ERC20: erc20Abi,
  ERC20PermitInterface: ERC20PermitInterface.abi,
  ERC721: ERC721.abi,
  EventEmitter: EventEmitter.abi,
  ExchangeRouter: ExchangeRouter.abi,
  GelatoRelayRouter: GelatoRelayRouter.abi,
  GlpManager: GlpManager.abi,
  GlvReader: GlvReader.abi,
  GlvRouter: GlvRouter.abi,
  GMT: GMT.abi,
  GmxMigrator: GmxMigrator.abi,
  GovToken: GovToken.abi,
  LayerZeroProvider: LayerZeroProvider.abi,
  MintableBaseToken: MintableBaseToken.abi,
  Multicall: Multicall.abi,
  MultichainClaimsRouter: MultichainClaimsRouter.abi,
  MultichainGlvRouter: MultichainGlvRouter.abi,
  MultichainGmRouter: MultichainGmRouter.abi,
  MultichainOrderRouter: MultichainOrderRouter.abi,
  MultichainSubaccountRouter: MultichainSubaccountRouter.abi,
  MultichainTransferRouter: MultichainTransferRouter.abi,
  MultichainUtils: MultichainUtils.abi,
  MultichainVault: MultichainVault.abi,
  OrderBook: OrderBook.abi,
  OrderBookReader: OrderBookReader.abi,
  OrderExecutor: OrderExecutor.abi,
  PositionManager: PositionManager.abi,
  PositionRouter: PositionRouter.abi,
  Reader: Reader.abi,
  ReaderV2: ReaderV2.abi,
  ReferralStorage: ReferralStorage.abi,
  RelayParams: RelayParams.abi,
  RewardReader: RewardReader.abi,
  RewardRouter: RewardRouter.abi,
  RewardTracker: RewardTracker.abi,
  Router: Router.abi,
  RouterV2: RouterV2.abi,
  SmartAccount: SmartAccount.abi,
  StBTC: StBTC.abi,
  SubaccountGelatoRelayRouter: SubaccountGelatoRelayRouter.abi,
  SubaccountRouter: SubaccountRouter.abi,
  SyntheticsReader: SyntheticsReader.abi,
  SyntheticsRouter: SyntheticsRouter.abi,
  Timelock: Timelock.abi,
  Token: Token.abi,
  Treasury: Treasury.abi,
  UniPool: UniPool.abi,
  UniswapV2: UniswapV2.abi,
  Vault: Vault.abi,
  VaultReader: VaultReader.abi,
  VaultV2: VaultV2.abi,
  VaultV2b: VaultV2b.abi,
  Vester: Vester.abi,
  WETH: WETH.abi,
  YieldFarm: YieldFarm.abi,
  YieldToken: YieldToken.abi,
} satisfies Record<AbiId, any> as any;
