diff --git a/src/entities/OrderERC20/OrderERC20Service.ts b/src/entities/OrderERC20/OrderERC20Service.ts index 23a30660..a49f26a8 100644 --- a/src/entities/OrderERC20/OrderERC20Service.ts +++ b/src/entities/OrderERC20/OrderERC20Service.ts @@ -1,22 +1,13 @@ -import { Server, SwapERC20 } from "@airswap/libraries"; -import { - createOrderERC20, - OrderERC20, - Pricing, - toAtomicString, - TokenInfo, - UnsignedOrderERC20, -} from "@airswap/utils"; +import { Server } from "@airswap/libraries"; +import { OrderERC20, toAtomicString, UnsignedOrderERC20 } from "@airswap/utils"; import { Web3Provider } from "@ethersproject/providers"; import { BigNumber } from "bignumber.js"; -import { LAST_LOOK_ORDER_EXPIRY_SEC } from "../../constants/configParams"; -import { AppError, isAppError } from "../../errors/appError"; +import { isAppError } from "../../errors/appError"; import { createOrderERC20Signature } from "../../helpers/createSwapSignature"; import { isPromiseFulfilledResult } from "../../helpers/promise"; -import { ExtendedPricing } from "../ExtendedPricing/ExtendedPricing"; -import { getPricingQuoteAmount } from "../ExtendedPricing/ExtendedPricingHelpers"; +import { getSwapErc20Address } from "../../helpers/swapErc20"; import { isOrderERC20 } from "./OrderERC20Helpers"; import { transformUnsignedOrderERC20ToOrderERC20 } from "./OrderERC20Transformers"; @@ -74,7 +65,7 @@ export const signOrderERC20AndSendForConsideration = async ( const signature = await createOrderERC20Signature( unsignedOrder, library.getSigner(), - SwapERC20.getAddress(chainId)!, + getSwapErc20Address(chainId)!, chainId ); diff --git a/src/features/balances/balancesApi.ts b/src/features/balances/balancesApi.ts index 89a0c60d..4eafb56f 100644 --- a/src/features/balances/balancesApi.ts +++ b/src/features/balances/balancesApi.ts @@ -1,8 +1,8 @@ -import { SwapERC20, Wrapper, BatchCall } from "@airswap/libraries"; +import { Wrapper, BatchCall } from "@airswap/libraries"; -import erc20Abi from "erc-20-abi"; -import { BigNumber, ethers, EventFilter, Event } from "ethers"; -import { hexZeroPad, id } from "ethers/lib/utils"; +import { BigNumber, ethers } from "ethers"; + +import { getSwapErc20Address } from "../../helpers/swapErc20"; interface WalletParams { chainId: number; @@ -30,7 +30,7 @@ const fetchBalancesOrAllowances: ( ? [walletAddress, tokenAddresses] : spenderAddressType === "Swap" ? // sender, spender, tokens. - [walletAddress, SwapERC20.getAddress(chainId), tokenAddresses] + [walletAddress, getSwapErc20Address(chainId), tokenAddresses] : [walletAddress, Wrapper.getAddress(chainId), tokenAddresses]; const amounts: BigNumber[] = await contract[method].apply(null, args); return amounts.map((amount) => amount.toString()); diff --git a/src/features/makeOtc/makeOtcActions.ts b/src/features/makeOtc/makeOtcActions.ts index 6d11d39a..541484dd 100644 --- a/src/features/makeOtc/makeOtcActions.ts +++ b/src/features/makeOtc/makeOtcActions.ts @@ -1,4 +1,3 @@ -import { SwapERC20 } from "@airswap/libraries"; import { createOrderERC20, toAtomicString, @@ -17,6 +16,7 @@ import { } from "../../components/Toasts/ToastController"; import { AppErrorType, isAppError } from "../../errors/appError"; import { createOrderERC20Signature } from "../../helpers/createSwapSignature"; +import { getSwapErc20Address } from "../../helpers/swapErc20"; import { sendOrderToIndexers } from "../indexer/indexerHelpers"; import { setError, setStatus, setUserOrder } from "./makeOtcSlice"; @@ -76,7 +76,7 @@ export const createOtcOrder = createAsyncThunk( const signature = await createOrderERC20Signature( unsignedOrder, params.library.getSigner(), - SwapERC20.getAddress(params.chainId) || "", + getSwapErc20Address(params.chainId) || "", params.chainId ); @@ -95,7 +95,7 @@ export const createOtcOrder = createAsyncThunk( ...unsignedOrder, ...signature, chainId: params.chainId, - swapContract: SwapERC20.getAddress(params.chainId) || "", + swapContract: getSwapErc20Address(params.chainId) || "", }; dispatch(setUserOrder(fullOrder)); diff --git a/src/features/metadata/metadataApi.ts b/src/features/metadata/metadataApi.ts index 6ab54406..d4cb3e7b 100644 --- a/src/features/metadata/metadataApi.ts +++ b/src/features/metadata/metadataApi.ts @@ -1,16 +1,11 @@ -import { SwapERC20 } from "@airswap/libraries"; import { TokenInfo, getTokenInfo } from "@airswap/utils"; import { Web3Provider } from "@ethersproject/providers"; import * as ethers from "ethers"; -import uniqBy from "lodash.uniqby"; +import { getSwapErc20Contract } from "../../helpers/swapErc20"; import { MetadataTokens } from "./metadataSlice"; -const tokensCache: { - [chainId: number]: TokenInfo[]; -} = {}; - export const getActiveTokensLocalStorageKey: ( account: string, chainId: number @@ -94,6 +89,6 @@ export const getProtocolFee = async ( provider: Web3Provider ): Promise => { return ( - await SwapERC20.getContract(provider, chainId).protocolFee() + await getSwapErc20Contract(provider, chainId).protocolFee() ).toNumber(); }; diff --git a/src/features/orders/ordersActions.ts b/src/features/orders/ordersActions.ts index d865fa07..9e06f6a7 100644 --- a/src/features/orders/ordersActions.ts +++ b/src/features/orders/ordersActions.ts @@ -1,4 +1,4 @@ -import { Registry, SwapERC20 } from "@airswap/libraries"; +import { Registry } from "@airswap/libraries"; import { FullOrderERC20, OrderERC20, @@ -40,6 +40,7 @@ import { AppErrorType, isAppError } from "../../errors/appError"; import transformUnknownErrorToAppError from "../../errors/transformUnknownErrorToAppError"; import { createOrderERC20Signature } from "../../helpers/createSwapSignature"; import getWethAddress from "../../helpers/getWethAddress"; +import { getSwapErc20Address } from "../../helpers/swapErc20"; import toRoundedAtomicString from "../../helpers/toRoundedAtomicString"; import i18n from "../../i18n/i18n"; import { TransactionStatusType } from "../../types/transactionTypes"; @@ -397,7 +398,7 @@ export const takeLastLookOrder = const signature = await createOrderERC20Signature( unsignedOrder, library.getSigner(), - SwapERC20.getAddress(chainId)!, + getSwapErc20Address(chainId)!, chainId ); diff --git a/src/features/orders/ordersHelpers.ts b/src/features/orders/ordersHelpers.ts index a26e9c4e..54fa63b3 100644 --- a/src/features/orders/ordersHelpers.ts +++ b/src/features/orders/ordersHelpers.ts @@ -1,4 +1,4 @@ -import { Server, SwapERC20, Wrapper, WETH } from "@airswap/libraries"; +import { Server, Wrapper, WETH } from "@airswap/libraries"; import { toAtomicString, parseCheckResult, @@ -12,12 +12,16 @@ import erc20Abi from "erc-20-abi"; import { BigNumber, ethers, Transaction } from "ethers"; import { RFQ_EXPIRY_BUFFER_MS } from "../../constants/configParams"; -import { AppError, AppErrorType } from "../../errors/appError"; +import { AppError } from "../../errors/appError"; import { SwapError, transformSwapErrorToAppError, } from "../../errors/swapError"; import transformUnknownErrorToAppError from "../../errors/transformUnknownErrorToAppError"; +import { + getSwapErc20Address, + getSwapErc20Contract, +} from "../../helpers/swapErc20"; const REQUEST_ORDER_TIMEOUT_MS = 5000; @@ -28,7 +32,7 @@ async function swap( provider: ethers.providers.Web3Provider, order: OrderERC20 | FullOrderERC20 ) { - let contract = await SwapERC20.getContract(provider.getSigner(), chainId); + let contract = await getSwapErc20Contract(provider.getSigner(), chainId); if ("senderWallet" in order && order.senderWallet === ADDRESS_ZERO) { return contract.swapAnySender( await (await provider.getSigner()).getAddress(), @@ -97,7 +101,7 @@ export async function approveToken( ) { const spender = contractType === "Swap" - ? SwapERC20.getAddress(provider.network.chainId) + ? getSwapErc20Address(provider.network.chainId) : Wrapper.getAddress(provider.network.chainId); const erc20Contract = new ethers.Contract( baseToken, @@ -200,7 +204,7 @@ export async function check( isSwapWithWrap?: boolean ): Promise { const strings = await ( - await SwapERC20.getContract(provider, chainId) + await getSwapErc20Contract(provider, chainId) ).check(senderWallet, ...orderERC20ToParams(order)); const errors = parseCheckResult(strings) as SwapError[]; @@ -225,7 +229,7 @@ export async function getNonceUsed( order: FullOrderERC20, provider: ethers.providers.BaseProvider ): Promise { - return (await SwapERC20.getContract(provider, order.chainId)).nonceUsed( + return (await getSwapErc20Contract(provider, order.chainId)).nonceUsed( order.signerWallet, order.nonce ); diff --git a/src/features/takeOtc/takeOtcActions.ts b/src/features/takeOtc/takeOtcActions.ts index ddc7a9ae..1ce1c8cf 100644 --- a/src/features/takeOtc/takeOtcActions.ts +++ b/src/features/takeOtc/takeOtcActions.ts @@ -1,4 +1,3 @@ -import { SwapERC20 } from "@airswap/libraries"; import { decompressFullOrderERC20, FullOrderERC20, @@ -9,11 +8,11 @@ import { createAsyncThunk } from "@reduxjs/toolkit"; import { providers } from "ethers"; import { - notifyConfirmation, notifyError, notifyRejectedByUserError, } from "../../components/Toasts/ToastController"; import { SubmittedCancellation } from "../../entities/SubmittedTransaction/SubmittedTransaction"; +import { getSwapErc20Contract } from "../../helpers/swapErc20"; import i18n from "../../i18n/i18n"; import { TransactionStatusType, @@ -73,7 +72,7 @@ export const cancelOrder = createAsyncThunk( dispatch(setStatus("signing")); - const tx = await SwapERC20.getContract( + const tx = await getSwapErc20Contract( params.library.getSigner(), params.chainId ) diff --git a/src/features/transactions/hooks/useLatestApproveFromEvents.ts b/src/features/transactions/hooks/useLatestApproveFromEvents.ts index 5358bbe8..3295e56b 100644 --- a/src/features/transactions/hooks/useLatestApproveFromEvents.ts +++ b/src/features/transactions/hooks/useLatestApproveFromEvents.ts @@ -1,6 +1,5 @@ import { useEffect, useState } from "react"; -import { SwapERC20 } from "@airswap/libraries"; import { useWeb3React } from "@web3-react/core"; import erc20Abi from "erc-20-abi"; @@ -13,6 +12,7 @@ import { transformToApproveEvent } from "../../../entities/ApproveEvent/ApproveE import { isApprovalTransaction } from "../../../entities/SubmittedTransaction/SubmittedTransactionHelpers"; import { getTransactionReceiptMined } from "../../../helpers/ethers"; import { compareAddresses } from "../../../helpers/string"; +import { getSwapErc20Address } from "../../../helpers/swapErc20"; import { selectActiveTokens } from "../../metadata/metadataSlice"; import useLatestPendingTransaction from "./useLatestPendingTransaction"; @@ -69,9 +69,7 @@ const useLatestApproveFromEvents = ( ) return; - if ( - !compareAddresses(spenderAddress, SwapERC20.getAddress(chainId) || "") - ) + if (!compareAddresses(spenderAddress, getSwapErc20Address(chainId) || "")) return; setLatestApprove( diff --git a/src/features/transactions/hooks/useLatestCancelFromEvents.ts b/src/features/transactions/hooks/useLatestCancelFromEvents.ts index a58013c2..3cf27da0 100644 --- a/src/features/transactions/hooks/useLatestCancelFromEvents.ts +++ b/src/features/transactions/hooks/useLatestCancelFromEvents.ts @@ -1,6 +1,5 @@ import { useEffect, useState } from "react"; -import { SwapERC20 } from "@airswap/libraries"; import { useWeb3React } from "@web3-react/core"; import { BigNumber, Event } from "ethers"; @@ -8,6 +7,7 @@ import { BigNumber, Event } from "ethers"; import { CancelEvent } from "../../../entities/CancelEvent/CancelEvent"; import { transformToCancelEvent } from "../../../entities/CancelEvent/CancelEventTransformers"; import { compareAddresses } from "../../../helpers/string"; +import { getSwapErc20Contract } from "../../../helpers/swapErc20"; import useNetworkSupported from "../../../hooks/useNetworkSupported"; const useLatestCancelFromEvents = ( @@ -26,7 +26,7 @@ const useLatestCancelFromEvents = ( if (account === accountState && chainId === chainIdState) return; - const swapContract = SwapERC20.getContract(provider, chainId); + const swapContract = getSwapErc20Contract(provider, chainId); const cancelEvent = "Cancel"; swapContract.protocolFeeWallet().then(() => { diff --git a/src/features/transactions/hooks/useLatestSwapFromEvents.ts b/src/features/transactions/hooks/useLatestSwapFromEvents.ts index 59313dbb..32e6d256 100644 --- a/src/features/transactions/hooks/useLatestSwapFromEvents.ts +++ b/src/features/transactions/hooks/useLatestSwapFromEvents.ts @@ -9,6 +9,7 @@ import { BigNumber, Event } from "ethers"; import { FullSwapERC20Event } from "../../../entities/FullSwapERC20Event/FullSwapERC20Event"; import { transformToFullSwapERC20Event } from "../../../entities/FullSwapERC20Event/FullSwapERC20EventTransformers"; import { compareAddresses } from "../../../helpers/string"; +import { getSwapErc20Contract } from "../../../helpers/swapErc20"; import useNetworkSupported from "../../../hooks/useNetworkSupported"; const useLatestSwapFromEvents = ( @@ -27,7 +28,7 @@ const useLatestSwapFromEvents = ( if (account === accountState && chainId === chainIdState) return; - const swapContract = SwapERC20.getContract(provider, chainId); + const swapContract = getSwapErc20Contract(provider, chainId); const swapEvent = "SwapERC20"; swapContract.protocolFeeWallet().then((feeReceiver: string) => { diff --git a/src/features/transactions/hooks/useSwapLogs.ts b/src/features/transactions/hooks/useSwapLogs.ts index 013927a5..e44559b5 100644 --- a/src/features/transactions/hooks/useSwapLogs.ts +++ b/src/features/transactions/hooks/useSwapLogs.ts @@ -9,6 +9,7 @@ import { useWeb3React } from "@web3-react/core"; import { Event } from "ethers"; import getContractEvents from "../../../helpers/getContractEvents"; +import { getSwapErc20Contract } from "../../../helpers/swapErc20"; import useNetworkSupported from "../../../hooks/useNetworkSupported"; interface SwapLogs { @@ -79,7 +80,7 @@ const useSwapLogs = ( if (account === accountState && chainId === chainIdState) return; - const swapContract = SwapERC20.getContract(provider, chainId); + const swapContract = getSwapErc20Contract(provider, chainId); const wrapperContract = Wrapper.getContract(provider, chainId); actions.execute(swapContract, wrapperContract, account); diff --git a/src/helpers/swapErc20.ts b/src/helpers/swapErc20.ts new file mode 100644 index 00000000..9baa0128 --- /dev/null +++ b/src/helpers/swapErc20.ts @@ -0,0 +1,593 @@ +import { SwapERC20 } from "@airswap/libraries"; +import { mainnets } from "@airswap/utils"; + +import { ethers } from "ethers"; + +const shouldOverride = true; +const addressV4 = "0xd82FA167727a4dc6D6F55830A2c47aBbB4b3a0F8"; +const contractV4Abi = [ + { + inputs: [ + { internalType: "uint256", name: "_protocolFee", type: "uint256" }, + { internalType: "uint256", name: "_protocolFeeLight", type: "uint256" }, + { internalType: "address", name: "_protocolFeeWallet", type: "address" }, + { internalType: "uint256", name: "_rebateScale", type: "uint256" }, + { internalType: "uint256", name: "_rebateMax", type: "uint256" }, + { internalType: "address", name: "_staking", type: "address" }, + ], + stateMutability: "nonpayable", + type: "constructor", + }, + { inputs: [], name: "ChainIdChanged", type: "error" }, + { inputs: [], name: "InvalidFee", type: "error" }, + { inputs: [], name: "InvalidFeeLight", type: "error" }, + { inputs: [], name: "InvalidFeeWallet", type: "error" }, + { inputs: [], name: "InvalidStaking", type: "error" }, + { inputs: [], name: "MaxTooHigh", type: "error" }, + { + inputs: [{ internalType: "uint256", name: "", type: "uint256" }], + name: "NonceAlreadyUsed", + type: "error", + }, + { inputs: [], name: "OrderExpired", type: "error" }, + { inputs: [], name: "ScaleTooHigh", type: "error" }, + { inputs: [], name: "SignatoryInvalid", type: "error" }, + { inputs: [], name: "SignatoryUnauthorized", type: "error" }, + { inputs: [], name: "SignatureInvalid", type: "error" }, + { inputs: [], name: "Unauthorized", type: "error" }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "signer", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "signerWallet", + type: "address", + }, + ], + name: "Authorize", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "uint256", + name: "nonce", + type: "uint256", + }, + { + indexed: true, + internalType: "address", + name: "signerWallet", + type: "address", + }, + ], + name: "Cancel", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "previousOwner", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "newOwner", + type: "address", + }, + ], + name: "OwnershipTransferStarted", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "previousOwner", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "newOwner", + type: "address", + }, + ], + name: "OwnershipTransferred", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "signer", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "signerWallet", + type: "address", + }, + ], + name: "Revoke", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "uint256", + name: "protocolFee", + type: "uint256", + }, + ], + name: "SetProtocolFee", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "uint256", + name: "protocolFeeLight", + type: "uint256", + }, + ], + name: "SetProtocolFeeLight", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "feeWallet", + type: "address", + }, + ], + name: "SetProtocolFeeWallet", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "uint256", + name: "rebateMax", + type: "uint256", + }, + ], + name: "SetRebateMax", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "uint256", + name: "rebateScale", + type: "uint256", + }, + ], + name: "SetRebateScale", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "staking", + type: "address", + }, + ], + name: "SetStaking", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "uint256", + name: "nonce", + type: "uint256", + }, + { + indexed: true, + internalType: "address", + name: "signerWallet", + type: "address", + }, + { + indexed: false, + internalType: "address", + name: "signerToken", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "signerAmount", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "protocolFee", + type: "uint256", + }, + { + indexed: true, + internalType: "address", + name: "senderWallet", + type: "address", + }, + { + indexed: false, + internalType: "address", + name: "senderToken", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "senderAmount", + type: "uint256", + }, + ], + name: "SwapERC20", + type: "event", + }, + { + inputs: [], + name: "DOMAIN_CHAIN_ID", + outputs: [{ internalType: "uint256", name: "", type: "uint256" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "DOMAIN_NAME", + outputs: [{ internalType: "string", name: "", type: "string" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "DOMAIN_SEPARATOR", + outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "DOMAIN_VERSION", + outputs: [{ internalType: "string", name: "", type: "string" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "FEE_DIVISOR", + outputs: [{ internalType: "uint256", name: "", type: "uint256" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "ORDER_TYPEHASH", + outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "acceptOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [{ internalType: "address", name: "signatory", type: "address" }], + name: "authorize", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [{ internalType: "address", name: "", type: "address" }], + name: "authorized", + outputs: [{ internalType: "address", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "stakingBalance", type: "uint256" }, + { internalType: "uint256", name: "feeAmount", type: "uint256" }, + ], + name: "calculateDiscount", + outputs: [{ internalType: "uint256", name: "", type: "uint256" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { internalType: "address", name: "wallet", type: "address" }, + { internalType: "uint256", name: "amount", type: "uint256" }, + ], + name: "calculateProtocolFee", + outputs: [{ internalType: "uint256", name: "", type: "uint256" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [{ internalType: "uint256[]", name: "nonces", type: "uint256[]" }], + name: "cancel", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "address", name: "senderWallet", type: "address" }, + { internalType: "uint256", name: "nonce", type: "uint256" }, + { internalType: "uint256", name: "expiry", type: "uint256" }, + { internalType: "address", name: "signerWallet", type: "address" }, + { internalType: "address", name: "signerToken", type: "address" }, + { internalType: "uint256", name: "signerAmount", type: "uint256" }, + { internalType: "address", name: "senderToken", type: "address" }, + { internalType: "uint256", name: "senderAmount", type: "uint256" }, + { internalType: "uint8", name: "v", type: "uint8" }, + { internalType: "bytes32", name: "r", type: "bytes32" }, + { internalType: "bytes32", name: "s", type: "bytes32" }, + ], + name: "check", + outputs: [ + { internalType: "uint256", name: "", type: "uint256" }, + { internalType: "bytes32[]", name: "", type: "bytes32[]" }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { internalType: "address", name: "signer", type: "address" }, + { internalType: "uint256", name: "nonce", type: "uint256" }, + ], + name: "nonceUsed", + outputs: [{ internalType: "bool", name: "", type: "bool" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "owner", + outputs: [{ internalType: "address", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "pendingOwner", + outputs: [{ internalType: "address", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "protocolFee", + outputs: [{ internalType: "uint256", name: "", type: "uint256" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "protocolFeeLight", + outputs: [{ internalType: "uint256", name: "", type: "uint256" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "protocolFeeWallet", + outputs: [{ internalType: "address", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "rebateMax", + outputs: [{ internalType: "uint256", name: "", type: "uint256" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "rebateScale", + outputs: [{ internalType: "uint256", name: "", type: "uint256" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "renounceOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "revoke", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_protocolFee", type: "uint256" }, + ], + name: "setProtocolFee", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_protocolFeeLight", type: "uint256" }, + ], + name: "setProtocolFeeLight", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "address", name: "_protocolFeeWallet", type: "address" }, + ], + name: "setProtocolFeeWallet", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [{ internalType: "uint256", name: "_rebateMax", type: "uint256" }], + name: "setRebateMax", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_rebateScale", type: "uint256" }, + ], + name: "setRebateScale", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [{ internalType: "address", name: "newstaking", type: "address" }], + name: "setStaking", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "staking", + outputs: [{ internalType: "address", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { internalType: "address", name: "recipient", type: "address" }, + { internalType: "uint256", name: "nonce", type: "uint256" }, + { internalType: "uint256", name: "expiry", type: "uint256" }, + { internalType: "address", name: "signerWallet", type: "address" }, + { internalType: "address", name: "signerToken", type: "address" }, + { internalType: "uint256", name: "signerAmount", type: "uint256" }, + { internalType: "address", name: "senderToken", type: "address" }, + { internalType: "uint256", name: "senderAmount", type: "uint256" }, + { internalType: "uint8", name: "v", type: "uint8" }, + { internalType: "bytes32", name: "r", type: "bytes32" }, + { internalType: "bytes32", name: "s", type: "bytes32" }, + ], + name: "swap", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "address", name: "recipient", type: "address" }, + { internalType: "uint256", name: "nonce", type: "uint256" }, + { internalType: "uint256", name: "expiry", type: "uint256" }, + { internalType: "address", name: "signerWallet", type: "address" }, + { internalType: "address", name: "signerToken", type: "address" }, + { internalType: "uint256", name: "signerAmount", type: "uint256" }, + { internalType: "address", name: "senderToken", type: "address" }, + { internalType: "uint256", name: "senderAmount", type: "uint256" }, + { internalType: "uint8", name: "v", type: "uint8" }, + { internalType: "bytes32", name: "r", type: "bytes32" }, + { internalType: "bytes32", name: "s", type: "bytes32" }, + ], + name: "swapAnySender", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "nonce", type: "uint256" }, + { internalType: "uint256", name: "expiry", type: "uint256" }, + { internalType: "address", name: "signerWallet", type: "address" }, + { internalType: "address", name: "signerToken", type: "address" }, + { internalType: "uint256", name: "signerAmount", type: "uint256" }, + { internalType: "address", name: "senderToken", type: "address" }, + { internalType: "uint256", name: "senderAmount", type: "uint256" }, + { internalType: "uint8", name: "v", type: "uint8" }, + { internalType: "bytes32", name: "r", type: "bytes32" }, + { internalType: "bytes32", name: "s", type: "bytes32" }, + ], + name: "swapLight", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [{ internalType: "address", name: "newOwner", type: "address" }], + name: "transferOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, +]; + +export const getSwapErc20Contract = ( + providerOrSigner: ethers.providers.Provider | ethers.Signer, + chainId: number +): ethers.Contract => { + if (!shouldOverride || !mainnets.includes(chainId)) { + return SwapERC20.getContract(providerOrSigner, chainId); + } + + const address = addressV4; + const contractInterface = new ethers.utils.Interface(contractV4Abi); + + return new ethers.Contract(address, contractInterface, providerOrSigner); +}; + +export const getSwapErc20Address = (chainId: number): string | undefined => { + if (!shouldOverride || chainId !== 1) { + return SwapERC20.getAddress(chainId) || undefined; + } + + return addressV4; +};