Skip to content

Commit

Permalink
feat & fix
Browse files Browse the repository at this point in the history
1, change borrows mapping to array
2, fix borrows add error
  • Loading branch information
john.yang committed Feb 1, 2023
1 parent 992f01f commit b4e6e58
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions contracts/FILL.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ interface FILLInterface {
uint256 amount; //borrow amount
bytes minerAddr; //miner
uint256 interestRate; // interest rate
uint256 borrowTime;
uint256 paybackTime;
bool isPayback;
uint256 borrowTime; // borrow time
uint256 paybackTime; // payback time
bool isPayback; // flag for status
}
struct MinerStackInfo {
bytes minerAddr;
Expand Down Expand Up @@ -215,9 +215,7 @@ contract FILL is Context, FILLInterface {
mapping(bytes => address) private minerBindsMap;
bytes[] bindKeys;
mapping(bytes => MinerStackInfo) private minerStacks;
// mapping(uint256 => BorrowInfo) private borrows;
BorrowInfo[] private borrows;
uint256 private _borrowCount;

address private _owner;
uint256 private _accumulatedDepositFIL;
Expand All @@ -232,7 +230,6 @@ contract FILL is Context, FILLInterface {
uint256 private _exchangeRate; // FIL/FLE=_exchangeRate/DEFAULT_RATE_BASE
uint256 private _interestRate; // interestRate=_interestRate/DEFAULT_RATE_BASE
uint256 private _utilizationRate; //

FLE _tokenFLE;

constructor(address fleAddr) {
Expand Down Expand Up @@ -271,7 +268,6 @@ contract FILL is Context, FILLInterface {
_accumulatedRedeemFIL += amountFIL;

emit Redeem(_msgSender(), amountFLE, amountFIL);

return amountFIL;
}

Expand All @@ -290,23 +286,24 @@ contract FILL is Context, FILLInterface {
"not enough to borow"
);
// add a borrow
borrows[_borrowCount] = BorrowInfo({
id: _borrowCount,
account: _msgSender(),
amount: amount,
minerAddr: minerAddr,
interestRate: interest_rate,
borrowTime: block.timestamp,
paybackTime: 0,
isPayback: false
});
_borrowCount++;
borrows.push(
BorrowInfo({
id: borrows.length,
account: _msgSender(),
amount: amount,
minerAddr: minerAddr,
interestRate: interest_rate,
borrowTime: block.timestamp,
paybackTime: 0,
isPayback: false
})
);
minerStacks[minerAddr].borrowCount += amount;
_accumulatedBorrowFIL += amount;
// send fil to miner
SendAPI.send(minerAddr, amount);

emit Borrow(_borrowCount - 1, _msgSender(), minerAddr, amount);
emit Borrow(borrows.length - 1, _msgSender(), minerAddr, amount);
return amount;
}

Expand Down

0 comments on commit b4e6e58

Please sign in to comment.