-
Notifications
You must be signed in to change notification settings - Fork 23
Open
Description
Copying great feedback received via Twitter DMS:
Wilson
- Gas can be saved during struct initialization, since these values all are already initialized to 0.
- Interest rate does not support decimals, recommended to use a scalar constant.
- No need for
== truehere. - No need for a loan capacity check because the draw capacity check will already fail (since
0<0 == false). - More idiomatic to start loans at 1 (
uint256 loanId = ++numLoans;).
Vasa
- The current code uses a max-sized struct, which prevents me from adding a
isRepaidboolean without stack-overflowing. This is currently solved by using thetokenOwnerstruct param as a dirty field to represent a paid loan if it is equal to 0x0. Vasa recommended using address and uint arrays to reduce stack size:
struct PawnLoan {
address[3] addrs; // [tokenAddress, tokenOwner, lender]
uint256[9] uints; // [tokenId, interestRate, loanAmount, maxLoanAmount, loanAmountDrawn, firstBidTime, lastBidTime, historicInterest, loanCompleteTime]
bool isRepaid;
}Alternatively, I could also use a mapping to represent repaid loans which may offer cheaper lookup.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels