Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigation profit calculation test #364

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
01c76ae
add collateralToCoverDebt
valiafetisov May 5, 2022
c139af9
update generateFakeAuction
valiafetisov May 5, 2022
a70f599
added test to improve investigation
KirillDogadin-std Jul 18, 2022
11e98cf
remove the log statements
KirillDogadin-std Jul 18, 2022
a41a832
change order of commands in test - authorize earlier
KirillDogadin-std Jul 18, 2022
b5f95c4
Revert "remove the log statements"
KirillDogadin-std Jul 18, 2022
c86c840
Merge remote-tracking branch 'origin/fix-profit-calc' into investigat…
KirillDogadin-std Jul 19, 2022
4b356e9
Hound caught the pray (???)
KirillDogadin-std Jul 20, 2022
0e281fd
polish comments
KirillDogadin-std Jul 20, 2022
e82caed
add parametrization
KirillDogadin-std Jul 20, 2022
2ab4c10
change naming of theprecision test
KirillDogadin-std Jul 20, 2022
4cdb5e4
add the parametrizaton
KirillDogadin-std Jul 21, 2022
ae5368a
polish parametrization
KirillDogadin-std Jul 21, 2022
ffc29b0
lint
KirillDogadin-std Jul 21, 2022
26f1d9b
Merge branch 'main' into investigation-profit-calculation-test
KirillDogadin-std Jul 21, 2022
43c052e
Nicer clear cache.
KirillDogadin-std Jul 21, 2022
56d54be
remove unused file
KirillDogadin-std Jul 21, 2022
d33e522
lint
KirillDogadin-std Jul 21, 2022
ee9e829
retry to fetch block if null
KirillDogadin-std Jul 21, 2022
4756daa
further drone experiments
KirillDogadin-std Jul 21, 2022
32d7c4b
remove the recursion
KirillDogadin-std Jul 21, 2022
45cfd6d
adjust test to try to fix ci
KirillDogadin-std Jul 21, 2022
d7ecc48
use different block extraction in case of fork
KirillDogadin-std Jul 22, 2022
27bb3cd
clear more cache
KirillDogadin-std Jul 22, 2022
17bc035
Revert "clear more cache"
KirillDogadin-std Jul 22, 2022
0b5265a
adjust the margin of comparison
KirillDogadin-std Jul 25, 2022
4f4d8cf
lint
KirillDogadin-std Jul 25, 2022
f7b08cf
wip: experiment with disabling cache
KirillDogadin-std Jul 25, 2022
d9934f7
adjust the approximate unit price logic based on fork
KirillDogadin-std Jul 25, 2022
06c8b75
bigger timeout
KirillDogadin-std Jul 29, 2022
6857229
Revert "wip: experiment with disabling cache"
KirillDogadin-std Jul 29, 2022
80735cc
clear cache for surplus test
KirillDogadin-std Jul 29, 2022
2e3b4f1
remove the step compensation margin
KirillDogadin-std Jul 29, 2022
b93b4f6
revert the block extraction logic
KirillDogadin-std Jul 29, 2022
e957a5e
lint
KirillDogadin-std Jul 29, 2022
08fc94d
Merge branch 'main' into investigation-profit-calculation-test
KirillDogadin-std Jul 29, 2022
dc47409
stub functions for fetching block timestamp
KirillDogadin-std Jul 29, 2022
0891ec8
lint
KirillDogadin-std Jul 29, 2022
f6ed774
adjust precision
KirillDogadin-std Jul 29, 2022
d30f7db
fix the comparison technique
KirillDogadin-std Jul 29, 2022
e12cce2
set timestamps of blocks
KirillDogadin-std Jul 29, 2022
ce3428f
+1 fake timestamp for hre
KirillDogadin-std Jul 29, 2022
513a638
adjust timetravel
KirillDogadin-std Jul 29, 2022
f2fb573
polish
KirillDogadin-std Jul 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ const customNetworkConfig = {
export default {
solidity: '0.8.4',
networks: customNetworkConfig,
mocha: {
timeout: 120 * 1000,
},
};
214 changes: 211 additions & 3 deletions core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"date-fns": "^2.28.0",
"ethers": "^5.4.6",
"memoizee": "^0.4.15",
"sinon": "^14.0.0",
"uuid": "^8.3.2"
},
"devDependencies": {
Expand Down
16 changes: 12 additions & 4 deletions core/src/auctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { enrichAuctionWithTransactionFees, getApproximateTransactionFees } from
import parseAuctionId from './helpers/parseAuctionId';
import { EventFilter } from 'ethers';
import getNetworkDate, { fetchDateByBlockNumber } from './date';
import { getNetworkConfigByType } from './network';

const enrichAuctionWithActualNumbers = async function (
network: string,
Expand Down Expand Up @@ -95,7 +96,7 @@ const enrichAuctionWithMarketValues = async function (auction: Auction, network:
}
};

export const enrichAuctionWithPriceDrop = async function (auction: Auction): Promise<Auction> {
export const enrichAuctionWithPriceDrop = async function (auction: Auction, network: string): Promise<Auction> {
if (!auction.isActive || auction.isFinished) {
return auction;
}
Expand All @@ -108,7 +109,14 @@ export const enrichAuctionWithPriceDrop = async function (auction: Auction): Pro
};
const currentDate = await getNetworkDate(auction.network);
const secondsTillNextPriceDrop = calculateAuctionDropTime(auctionWithParams, currentDate);
const approximateUnitPrice = calculateAuctionPrice(auctionWithParams, currentDate);

let approximateUnitPrice;
const networkConfig = getNetworkConfigByType(network);
if (networkConfig.isFork) {
approximateUnitPrice = auction.unitPrice;
} else {
approximateUnitPrice = calculateAuctionPrice(auctionWithParams, currentDate);
}
const totalPrice = auction.collateralAmount.multipliedBy(approximateUnitPrice);
const transactionGrossProfitDate = calculateTransactionGrossProfitDate(auctionWithParams, currentDate);
return {
Expand All @@ -130,7 +138,7 @@ export const enrichAuctionWithPriceDropAndMarketValue = async function (
auction: Auction,
network: string
): Promise<Auction> {
const enrichedAuctionWithNewPriceDrop = await enrichAuctionWithPriceDrop(auction);
const enrichedAuctionWithNewPriceDrop = await enrichAuctionWithPriceDrop(auction, network);
return await enrichAuctionWithMarketValues(enrichedAuctionWithNewPriceDrop, network);
};

Expand Down Expand Up @@ -170,7 +178,7 @@ export const enrichAuction = async function (
const auctionWithStatus = await enrichAuctionWithActualNumbers(network, auction);

// enrich them with price drop
const auctionWithPriceDrop = await enrichAuctionWithPriceDrop(auctionWithStatus);
const auctionWithPriceDrop = await enrichAuctionWithPriceDrop(auctionWithStatus, network);

// enrich them with market values
const auctionWithMarketValue = await enrichAuctionWithMarketValues(auctionWithPriceDrop, network);
Expand Down
Loading