pawnft
pawnft copied to clipboard
Feedback from @wilsoncusack and @vasa-develop
Copying great feedback received via Twitter DMS:
Wilson
- [x] 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.
- [x] No need for
== true
here. - [x] No need for a loan capacity check because the draw capacity check will already fail (since
0<0 == false
). - [x] 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
isRepaid
boolean without stack-overflowing. This is currently solved by using thetokenOwner
struct 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.