-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoggers.sol
109 lines (97 loc) · 4.98 KB
/
Loggers.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.18;
// solhint-disable no-console
import {console} from "forge-std/console.sol";
import {Test} from "forge-std/Test.sol";
import {CollateralState, Offer, Ray, NFToken} from "../../src/DataStructure/Objects.sol";
import {Loan, Provision, Auction, Payment} from "../../src/DataStructure/Storage.sol";
contract Loggers is Test {
function logLoan(Loan memory loan, string memory name) internal view {
console.log("~~~~~~~ start loan ", name, " ~~~~~~~");
console.log("assetLent ", address(loan.assetLent));
console.log("lent ", loan.lent);
console.log("shareLent ", Ray.unwrap(loan.shareLent));
console.log("startDate ", loan.startDate);
console.log("endDate ", loan.endDate);
logAuction(true, loan.auction);
console.log("interestPerSecond ", Ray.unwrap(loan.interestPerSecond));
console.log("borrower ", loan.borrower);
logNft("collateral.", loan.collateral);
logPayment(true, loan.payment);
console.log("supplyPositionIndex:");
if (loan.nbOfPositions >= 2) {
console.log(
"from %s to %s",
loan.supplyPositionIndex,
loan.supplyPositionIndex + loan.nbOfPositions - 1
);
} else {
console.log("position ", loan.supplyPositionIndex);
}
console.log("~~~~~~~ end loan ", name, " ~~~~~~~");
}
function logOffer(Offer memory offer, string memory name) internal view {
console.log("~~~~~~~ start offer ", name, " ~~~~~~~");
console.log("assetToLend ", address(offer.assetToLend));
console.log("loanToValue ", offer.loanToValue);
console.log("duration ", offer.duration);
console.log("expirationDate ", offer.expirationDate);
console.log("tranche ", offer.tranche);
console.log("collat implem ", address(offer.collateral.implem));
console.log("collat id ", offer.collateral.id);
console.log("~~~~~~~ end offer ", name, " ~~~~~~~");
}
function logProvision(Provision memory provision, string memory name) internal view {
console.log("~~~~~~~ start provision ", name, " ~~~~~~~");
console.log("amount ", provision.amount);
console.log("share ", Ray.unwrap(provision.share));
console.log("loanId ", provision.loanId);
console.log("~~~~~~~ end provision ", name, " ~~~~~~~");
}
function logCollateralState(CollateralState memory collat, string memory name) internal view {
console.log("~~~~~~~ start Collateral State ", name, " ~~~~~~~");
console.log("matched ", Ray.unwrap(collat.matched));
console.log("minOfferDuration ", collat.minOfferDuration);
console.log("minOfferLoanToValue ", collat.minOfferLoanToValue);
console.log("maxOfferLoanToValue ", collat.maxOfferLoanToValue);
console.log("from ", collat.from);
console.log("nft.id ", collat.nft.id);
console.log("loanId ", collat.loanId);
console.log("~~~~~~~ end Collateral State ", name, " ~~~~~~~");
}
function logNft(NFToken memory nft, string memory name) internal view {
console.log("~~~~~~~ start NFT ", name, " ~~~~~~~");
logNft("", nft);
console.log("~~~~~~~ end NFT ", name, " ~~~~~~~");
}
function logNft(string memory prefix, NFToken memory nft) internal view {
console.log("%simplem %s", prefix, address(nft.implem));
console.log("%sid %s", prefix, nft.id);
}
function logPayment(Payment memory payment, string memory name) internal view {
console.log("~~~~~~~ start Payment ", name, " ~~~~~~~");
logPayment(false, payment);
console.log("~~~~~~~ end Payment ", name, " ~~~~~~~");
}
function logPayment(bool prefixed, Payment memory payment) internal view {
string memory prefix = prefixed ? "payment." : "";
console.log("%spaid %s", prefix, payment.paid);
console.log("%sminToRepay %s", prefix, payment.minInterestsToRepay);
console.log("%sliquidated %s", prefix, payment.liquidated);
console.log("%sborrClaimed %s", prefix, payment.borrowerClaimed);
}
function logAuction(Auction memory auction, string memory name) internal view {
console.log("~~~~~~~ start Auction ", name, " ~~~~~~~");
logAuction(false, auction);
console.log("~~~~~~~ end Auction ", name, " ~~~~~~~");
}
function logAuction(bool prefixed, Auction memory auction) internal view {
if (prefixed) {
console.log("auction.duration ", auction.duration);
console.log("auction.priceFactor ", Ray.unwrap(auction.priceFactor));
} else {
console.log("duration ", auction.duration);
console.log("priceFactor ", Ray.unwrap(auction.priceFactor));
}
}
}