Skip to content

Commit

Permalink
fix: addressed testing issues and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
msacco8 committed Feb 6, 2024
1 parent 5c4db22 commit fa22967
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 79 deletions.
4 changes: 3 additions & 1 deletion Forta-Bots-Challenge-4/liquidatable-positions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This bot monitors COMP III's Comet Ethereum Mainnet contracts for base assets WE
## Alerts

- COMPIII-POSITION

- Fired when a transaction contains a supply/withdraw function call indicating a newly tracked borrow position over the threshold
- Severity is always set to "low"
- Type is always set to "info" (mention any conditions where it could be something else)
Expand All @@ -30,6 +31,7 @@ This bot monitors COMP III's Comet Ethereum Mainnet contracts for base assets WE
## Test Data

The bot behaviour can be verified with the following transactions:
- _Note_: Ttransaction may be outdated and position may no longer be open

- _Note_: Transaction may be outdated and position may no longer be open

- [0x23e5a57dcd73dff352684d26337bfc29d02444b04811078fcd761fc867ca20f9](https://etherscan.io/tx/0x23e5a57dcd73dff352684d26337bfc29d02444b04811078fcd761fc867ca20f9)
174 changes: 96 additions & 78 deletions Forta-Bots-Challenge-4/liquidatable-positions/src/agent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,35 @@ import { HandleTransaction, Initialize, Finding, FindingType, FindingSeverity, H
import { provideHandleTransaction, provideInitialize, provideHandleBlock } from "./agent";
import { MockEthersProvider, TestBlockEvent, TestTransactionEvent } from "forta-agent-tools/lib/test";
import { createAddress } from "forta-agent-tools";
import { Interface } from "ethers/lib/utils";
import { BigNumber } from "ethers";
import {
CollateralAddresses,
PositionData,
emptyPositionData,
Liquidatable,
FetcherConfig,
CollateralQuotes,
CollateralBalances,
} from "./agent.utils";
} from "./mock.agent.utils";
import {
mockCallSignatures,
mockCometIFACE,
mockCometSignaturesIFACE,
mockERC20IFACE,
mockFetcherConfigUSDC,
mockFetcherConfigWETH,
mockManaged,
mockSendees,
mockSenders,
mockBaseUSDC,
mockCometSignatures,
mockCollateralUSDC,
mockBaseWETH,
mockCollateralWETH,
mockCometABI,
mockCometAddressUSDC,
mockCometAddressWETH,
mockERC20ABI
} from "./mock.constants"

const createTestNewPositionFinding = (newPosition: PositionData) => {
const newPositionToken = newPosition.token.toLowerCase();
Expand Down Expand Up @@ -65,81 +83,81 @@ const createCollateralObject = (baseAsset: string, values: string[]): Collateral
};
};

const mockCallSignatures: string[] = ["withdraw", "withdrawTo", "withdrawFrom", "supply", "supplyTo", "supplyFrom"];

const mockBorrowThresholdUSDC: BigNumber = BigNumber.from(50);
const mockBorrowThresholdWETH: BigNumber = BigNumber.from(5);

const mockCometAddressUSDC: string = createAddress("0xa1");
const mockCometAddressWETH: string = createAddress("0xa2");

const mockBaseUSDC: string = createAddress("0xa3");
const mockBaseWETH: string = createAddress("0xa4");

const mockERC20ABI: string[] = ["function balanceOf(address) external view returns (uint256)"];
const mockCometABI: string[] = [
"function isLiquidatable(address) public view returns (bool)",
"function borrowBalanceOf(address) public view returns (uint256)",
"function quoteCollateral(address, uint) public view returns (uint)",
];
const mockCometSignatures: string[] = [
"function withdraw(address, uint) external",
"function withdrawTo(address, address, uint) external",
"function withdrawFrom(address, address, address, uint) external",
"function supply(address, uint) external",
"function supplyTo(address, address, uint) external",
"function supplyFrom(address, address, address, uint) external",
];

const mockERC20IFACE: Interface = new Interface(mockERC20ABI);
const mockCometIFACE: Interface = new Interface(mockCometABI);
const mockCometSignaturesIFACE: Interface = new Interface(mockCometSignatures);

const mockCollateralUSDC: CollateralAddresses = {
WBTC: createAddress("0xb1"),
WETH: createAddress("0xb2"),
COMP: createAddress("0xb3"),
UNI: createAddress("0xb4"),
LINK: createAddress("0xb5"),
};
const mockCollateralWETH: CollateralAddresses = {
wstETH: createAddress("0xc1"),
cbETH: createAddress("0xc2"),
rETH: createAddress("0xc3"),
};

const mockFetcherConfigUSDC: FetcherConfig = {
cometAddress: mockCometAddressUSDC,
baseAssetAddress: mockBaseUSDC,
collateralAddresses: mockCollateralUSDC,
borrowThreshold: mockBorrowThresholdUSDC,
maxPositions: 5,
};
const mockFetcherConfigWETH: FetcherConfig = {
cometAddress: mockCometAddressWETH,
baseAssetAddress: mockBaseWETH,
collateralAddresses: mockCollateralWETH,
borrowThreshold: mockBorrowThresholdWETH,
maxPositions: 5,
};

const mockSenders: string[] = [
createAddress("0xd1"),
createAddress("0xd2"),
createAddress("0xd3"),
createAddress("0xd4"),
createAddress("0xd5"),
createAddress("0xd6"),
];

const mockSendees: string[] = [
createAddress("0xe1"),
createAddress("0xe2"),
createAddress("0xe3"),
createAddress("0xe4"),
];

const mockManaged: string[] = [createAddress("0xf1"), createAddress("0xf2")];
// const mockCallSignatures: string[] = ["withdraw", "withdrawTo", "withdrawFrom", "supply", "supplyTo", "supplyFrom"];

// const mockBorrowThresholdUSDC: BigNumber = BigNumber.from(50);
// const mockBorrowThresholdWETH: BigNumber = BigNumber.from(5);

// const mockCometAddressUSDC: string = createAddress("0xa1");
// const mockCometAddressWETH: string = createAddress("0xa2");

// const mockBaseUSDC: string = createAddress("0xa3");
// const mockBaseWETH: string = createAddress("0xa4");

// const mockERC20ABI: string[] = ["function balanceOf(address) external view returns (uint256)"];
// const mockCometABI: string[] = [
// "function isLiquidatable(address) public view returns (bool)",
// "function borrowBalanceOf(address) public view returns (uint256)",
// "function quoteCollateral(address, uint) public view returns (uint)",
// ];
// const mockCometSignatures: string[] = [
// "function withdraw(address, uint) external",
// "function withdrawTo(address, address, uint) external",
// "function withdrawFrom(address, address, address, uint) external",
// "function supply(address, uint) external",
// "function supplyTo(address, address, uint) external",
// "function supplyFrom(address, address, address, uint) external",
// ];

// const mockERC20IFACE: Interface = new Interface(mockERC20ABI);
// const mockCometIFACE: Interface = new Interface(mockCometABI);
// const mockCometSignaturesIFACE: Interface = new Interface(mockCometSignatures);

// const mockCollateralUSDC: CollateralAddresses = {
// WBTC: createAddress("0xb1"),
// WETH: createAddress("0xb2"),
// COMP: createAddress("0xb3"),
// UNI: createAddress("0xb4"),
// LINK: createAddress("0xb5"),
// };
// const mockCollateralWETH: CollateralAddresses = {
// wstETH: createAddress("0xc1"),
// cbETH: createAddress("0xc2"),
// rETH: createAddress("0xc3"),
// };

// const mockFetcherConfigUSDC: FetcherConfig = {
// cometAddress: mockCometAddressUSDC,
// baseAssetAddress: mockBaseUSDC,
// collateralAddresses: mockCollateralUSDC,
// borrowThreshold: mockBorrowThresholdUSDC,
// maxPositions: 5,
// };
// const mockFetcherConfigWETH: FetcherConfig = {
// cometAddress: mockCometAddressWETH,
// baseAssetAddress: mockBaseWETH,
// collateralAddresses: mockCollateralWETH,
// borrowThreshold: mockBorrowThresholdWETH,
// maxPositions: 5,
// };

// const mockSenders: string[] = [
// createAddress("0xd1"),
// createAddress("0xd2"),
// createAddress("0xd3"),
// createAddress("0xd4"),
// createAddress("0xd5"),
// createAddress("0xd6"),
// ];

// const mockSendees: string[] = [
// createAddress("0xe1"),
// createAddress("0xe2"),
// createAddress("0xe3"),
// createAddress("0xe4"),
// ];

// const mockManaged: string[] = [createAddress("0xf1"), createAddress("0xf2")];

describe("Comp III Position Tracker Test Suite", () => {
let handleTransaction: HandleTransaction;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { BigNumber, Contract } from "ethers";

export type CollateralAddresses = {
[key: string]: string;
};

export type CollateralBalances = {
[key: string]: string;
};

export type CollateralQuotes = {
[key: string]: string;
};

export type CollateralContracts = {
[key: string]: Contract;
};

export type PositionData = {
owner: string;
token: string;
};

export type PositionDataResponse = {
newOrUpdatedPosition: boolean;
position: PositionData;
};

export type Liquidatable = {
position: PositionData;
isLiquidatable: boolean;
borrowBalance: BigNumber;
collateralBalances: CollateralBalances;
collateralQuotes: CollateralQuotes;
};

export type FetcherConfig = {
cometAddress: string;
baseAssetAddress: string;
collateralAddresses: CollateralAddresses;
borrowThreshold: BigNumber;
maxPositions: number;
};

export const emptyPositionData: PositionData = {
owner: "",
token: "",
};

export const emptyPositionDataResponse: PositionDataResponse = {
newOrUpdatedPosition: false,
position: emptyPositionData,
};

export const emptyLiquidationInfo: Liquidatable = {
position: emptyPositionData,
isLiquidatable: false,
borrowBalance: BigNumber.from(0),
collateralBalances: {},
collateralQuotes: {},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { createAddress } from "forta-agent-tools";
import { Interface } from "ethers/lib/utils";
import { BigNumber } from "ethers";
import { CollateralAddresses, FetcherConfig } from "./mock.agent.utils";

export const mockCallSignatures: string[] = ["withdraw", "withdrawTo", "withdrawFrom", "supply", "supplyTo", "supplyFrom"];

const mockBorrowThresholdUSDC: BigNumber = BigNumber.from(50);
const mockBorrowThresholdWETH: BigNumber = BigNumber.from(5);

export const mockCometAddressUSDC: string = createAddress("0xa1");
export const mockCometAddressWETH: string = createAddress("0xa2");

export const mockBaseUSDC: string = createAddress("0xa3");
export const mockBaseWETH: string = createAddress("0xa4");

export const mockERC20ABI: string[] = ["function balanceOf(address) external view returns (uint256)"];
export const mockCometABI: string[] = [
"function isLiquidatable(address) public view returns (bool)",
"function borrowBalanceOf(address) public view returns (uint256)",
"function quoteCollateral(address, uint) public view returns (uint)",
];
export const mockCometSignatures: string[] = [
"function withdraw(address, uint) external",
"function withdrawTo(address, address, uint) external",
"function withdrawFrom(address, address, address, uint) external",
"function supply(address, uint) external",
"function supplyTo(address, address, uint) external",
"function supplyFrom(address, address, address, uint) external",
];

export const mockERC20IFACE: Interface = new Interface(mockERC20ABI);
export const mockCometIFACE: Interface = new Interface(mockCometABI);
export const mockCometSignaturesIFACE: Interface = new Interface(mockCometSignatures);

export const mockCollateralUSDC: CollateralAddresses = {
WBTC: createAddress("0xb1"),
WETH: createAddress("0xb2"),
COMP: createAddress("0xb3"),
UNI: createAddress("0xb4"),
LINK: createAddress("0xb5"),
};
export const mockCollateralWETH: CollateralAddresses = {
wstETH: createAddress("0xc1"),
cbETH: createAddress("0xc2"),
rETH: createAddress("0xc3"),
};

export const mockFetcherConfigUSDC: FetcherConfig = {
cometAddress: mockCometAddressUSDC,
baseAssetAddress: mockBaseUSDC,
collateralAddresses: mockCollateralUSDC,
borrowThreshold: mockBorrowThresholdUSDC,
maxPositions: 5,
};
export const mockFetcherConfigWETH: FetcherConfig = {
cometAddress: mockCometAddressWETH,
baseAssetAddress: mockBaseWETH,
collateralAddresses: mockCollateralWETH,
borrowThreshold: mockBorrowThresholdWETH,
maxPositions: 5,
};

export const mockSenders: string[] = [
createAddress("0xd1"),
createAddress("0xd2"),
createAddress("0xd3"),
createAddress("0xd4"),
createAddress("0xd5"),
createAddress("0xd6"),
];

export const mockSendees: string[] = [
createAddress("0xe1"),
createAddress("0xe2"),
createAddress("0xe3"),
createAddress("0xe4"),
];

export const mockManaged: string[] = [createAddress("0xf1"), createAddress("0xf2")];

0 comments on commit fa22967

Please sign in to comment.