Skip to content

Commit

Permalink
feat: amount check on swap and quote functions
Browse files Browse the repository at this point in the history
  • Loading branch information
CoviloMilos committed Jan 30, 2023
1 parent 27b9706 commit ec28946
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/modules/fungibleTrading/quoter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IQuoterContract, ProviderOrSigner, TheaNetwork, UniswapPoolFee } from "../../types";
import { consts, ContractWrapper, validateAddress } from "../../utils";
import { amountShouldBeGTZero, consts, ContractWrapper, validateAddress } from "../../utils";
import Quoter_ABI from "../../abi/Quoter_ABI.json";
import { BigNumber, BigNumberish } from "@ethersproject/bignumber";

Expand All @@ -22,6 +22,7 @@ export class Quoter extends ContractWrapper<IQuoterContract> {
): Promise<{ amountOut: BigNumber | 0; fee: number }> {
validateAddress(tokenIn);
validateAddress(tokenOut);
amountShouldBeGTZero(amount);

const fees = Object.values(UniswapPoolFee);

Expand Down
3 changes: 2 additions & 1 deletion src/modules/fungibleTrading/swapRouter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExactInputSingleParams, ProviderOrSigner, ISwapRouterContract, SwapTokens, TheaNetwork } from "../../types";
import { consts, ContractWrapper, signerRequired, validateAddress } from "../../utils";
import { amountShouldBeGTZero, consts, ContractWrapper, signerRequired, validateAddress } from "../../utils";
import SwapRouter_ABI from "../../abi/SwapRouter_ABI.json";
import { ContractReceipt } from "@ethersproject/contracts";
import { approve, checkBalance, execute } from "../shared";
Expand All @@ -24,6 +24,7 @@ export class SwapRouter extends ContractWrapper<ISwapRouterContract> {
*/
async swap(params: ExactInputSingleParams, tokenIn: SwapTokens): Promise<ContractReceipt> {
signerRequired(this.providerOrSigner);
amountShouldBeGTZero(params.amountIn);
[params.tokenIn, params.tokenOut, params.recipient].forEach((address) => validateAddress(address));

// Check balance of token in
Expand Down

0 comments on commit ec28946

Please sign in to comment.