You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+52Lines changed: 52 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -198,6 +198,19 @@ For this challenge we will not focus on the Lending aspect as much as the other
198
198
199
199
🎉 Excellent! Re-deploy your contract with `yarn deploy --reset`. We want to do a fresh deploy of all the contracts so that they each have correct constructor parameters. Now try out your methods from the front end and see if you need to make any changes.
200
200
201
+
<Tabs>
202
+
<Tablabel="Hardhat">
203
+
204
+
> 🧪 Run the tests for this checkpoint: `yarn test --grep "Collateral Operations"`
205
+
206
+
</Tab>
207
+
<Tablabel="Foundry">
208
+
209
+
> 🧪 Run the tests for this checkpoint: `yarn test --match-test "test_Collateral_"`
210
+
211
+
</Tab>
212
+
</Tabs>
213
+
201
214
💰 Don't forget to give yourself some ETH from the faucet!
@@ -337,6 +350,19 @@ For this challenge we will not focus on the Lending aspect as much as the other
337
350
338
351
🔄 Run `yarn deploy --reset` so you can play with borrowing and repaying on the front end. You can adjust the price of CORN by pressing the + and - buttons under CORN price in the top right corner. See how your open position's collateral value shifts as the price moves.
339
352
353
+
<Tabs>
354
+
<Tablabel="Hardhat">
355
+
356
+
> 🧪 Run the tests for this checkpoint: `yarn test --grep "Borrowing Operations|Repayment Operations"`
357
+
358
+
</Tab>
359
+
<Tablabel="Foundry">
360
+
361
+
> 🧪 Run the tests for this checkpoint: `yarn test --match-test "test_(Borrowing|Repayment)_"`
362
+
363
+
</Tab>
364
+
</Tabs>
365
+
340
366
<details><summary>Solution Code</summary>
341
367
342
368
```solidity
@@ -451,6 +477,19 @@ For this challenge we will not focus on the Lending aspect as much as the other
451
477
452
478
🔄 You know the drill. Run `yarn deploy --reset` so you can try liquidating on the front end. It may be useful to open a private browser tab and go to `localhost:3000` so you can simulate multiple accounts. You can also borrow and then switch wallets and use the swap button in the CORN wallet (on the right side of the screen) to acquire some CORN. Now adjust the price using the price controls in the CORN price module and liquidate the borrower.
453
479
480
+
<Tabs>
481
+
<Tablabel="Hardhat">
482
+
483
+
> 🧪 Run the tests for this checkpoint: `yarn test --grep "Liquidation"`
484
+
485
+
</Tab>
486
+
<Tablabel="Foundry">
487
+
488
+
> 🧪 Run the tests for this checkpoint: `yarn test --match-test "test_Liquidation_"`
489
+
490
+
</Tab>
491
+
</Tabs>
492
+
454
493
🫴 Notice how the borrower still has their borrowed CORN after they get liquidated. They get to keep their CORN since the liquidator paid their CORN debt back to the protocol on their behalf.
455
494
456
495
---
@@ -466,6 +505,19 @@ For this challenge we will not focus on the Lending aspect as much as the other
466
505
467
506
🔙 Throwback to the `withdrawCollateral` function. What happens when a borrower withdraws collateral exceeding the safe position ratio? You should add a `_validatePosition` check to make sure that never happens. You should add it after the `s_userCollateral` mapping is updated so that it is checking the final state instead of the current state. Skip the check if they don't have any borrowed CORN.
468
507
508
+
<Tabs>
509
+
<Tablabel="Hardhat">
510
+
511
+
> 🧪 Run the tests for this checkpoint: `yarn test --grep "should prevent withdrawing collateral if it makes the position liquidatable"`
512
+
513
+
</Tab>
514
+
<Tablabel="Foundry">
515
+
516
+
> 🧪 Run the tests for this checkpoint: `yarn test --match-test "test_Withdraw_"`
517
+
518
+
</Tab>
519
+
</Tabs>
520
+
469
521
🎉 Great work! Your contract has all the necessary functionality to help people get CORN loans.
470
522
471
523
🍨 Now you get to see something real special. Run `yarn deploy --reset` as you usually do. Then run:
Copy file name to clipboardExpand all lines: extension/.ai/CHALLENGE.yaml
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -135,7 +135,7 @@ checkpoints:
135
135
foundry: "packages/foundry/contracts/Lending.sol"
136
136
test:
137
137
hardhat: "yarn test --grep 'Collateral Operations'"
138
-
foundry: "yarn test --match-test 'Checkpoint1'"
138
+
foundry: "yarn test --match-test 'test_Collateral_'"
139
139
hints:
140
140
- "For `addCollateral`: it's just `s_userCollateral[msg.sender] += msg.value` after the validation check."
141
141
- |
@@ -253,7 +253,7 @@ checkpoints:
253
253
foundry: "packages/foundry/contracts/Lending.sol"
254
254
test:
255
255
hardhat: "yarn test --grep 'Collateral Operations'"
256
-
foundry: "yarn test --match-test 'Checkpoint1'"
256
+
foundry: "yarn test --match-test 'test_Collateral_'"
257
257
hints:
258
258
- "`calculateCollateralValue` is a one-liner: `return (s_userCollateral[user] * i_cornDEX.currentPrice()) / 1e18;`"
259
259
- |
@@ -397,7 +397,7 @@ checkpoints:
397
397
foundry: "packages/foundry/contracts/Lending.sol"
398
398
test:
399
399
hardhat: "yarn test --grep 'Borrowing Operations|Repayment Operations|Collateral Operations'"
400
-
foundry: "yarn test --match-test 'Checkpoint3'"
400
+
foundry: "yarn test --match-test 'test_(Borrowing|Repayment|Withdraw)_'"
401
401
hints:
402
402
- "For `borrowCorn`: update mapping first, validate, then transfer. The order matters — `_validatePosition` checks the new state."
403
403
- |
@@ -536,7 +536,7 @@ checkpoints:
536
536
foundry: "packages/foundry/contracts/Lending.sol"
537
537
test:
538
538
hardhat: "yarn test --grep 'Liquidation'"
539
-
foundry: "yarn test --match-test 'Checkpoint4'"
539
+
foundry: "yarn test --match-test 'test_Liquidation_'"
540
540
hints:
541
541
- "Check `isLiquidatable(user)` first. Then verify `i_corn.balanceOf(msg.sender) >= userDebt`. Use `transferFrom` to pull the CORN from the liquidator."
Copy file name to clipboardExpand all lines: extension/README.md.args.mjs
+8Lines changed: 8 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -168,6 +168,8 @@ For this challenge we will not focus on the Lending aspect as much as the other
168
168
169
169
🎉 Excellent! Re-deploy your contract with \`yarn deploy --reset\`. We want to do a fresh deploy of all the contracts so that they each have correct constructor parameters. Now try out your methods from the front end and see if you need to make any changes.
170
170
171
+
> 🧪 Run the tests for this checkpoint: \`${solidityFramework==="hardhat" ? `yarn test --grep "Collateral Operations"` : `yarn test --match-test "test_Collateral_"`}\`
172
+
171
173
💰 Don't forget to give yourself some ETH from the faucet!
@@ -296,6 +298,8 @@ ${solidityFramework === "hardhat" ? `> 💡 Since we added all those complex hel
296
298
297
299
🔄 Run \`yarn deploy --reset\` so you can play with borrowing and repaying on the front end. You can adjust the price of CORN by pressing the + and - buttons under CORN price in the top right corner. See how your open position's collateral value shifts as the price moves.
298
300
301
+
> 🧪 Run the tests for this checkpoint: \`${solidityFramework==="hardhat" ? `yarn test --grep "Borrowing Operations|Repayment Operations"` : `yarn test --match-test "test_(Borrowing|Repayment)_"`}\`
302
+
299
303
<details><summary>Solution Code</summary>
300
304
301
305
\`\`\`solidity
@@ -409,6 +413,8 @@ ${solidityFramework === "hardhat" ? `> 💡 Since we added all those complex hel
409
413
410
414
🔄 You know the drill. Run \`yarn deploy --reset\` so you can try liquidating on the front end. It may be useful to open a private browser tab and go to \`localhost:3000\` so you can simulate multiple accounts. You can also borrow and then switch wallets and use the swap button in the CORN wallet (on the right side of the screen) to acquire some CORN. Now adjust the price using the price controls in the CORN price module and liquidate the borrower.
411
415
416
+
> 🧪 Run the tests for this checkpoint: \`${solidityFramework==="hardhat" ? `yarn test --grep "Liquidation"` : `yarn test --match-test "test_Liquidation_"`}\`
417
+
412
418
🫴 Notice how the borrower still has their borrowed CORN after they get liquidated. They get to keep their CORN since the liquidator paid their CORN debt back to the protocol on their behalf.
413
419
414
420
---
@@ -424,6 +430,8 @@ ${solidityFramework === "hardhat" ? `> 💡 Since we added all those complex hel
424
430
425
431
🔙 Throwback to the \`withdrawCollateral\` function. What happens when a borrower withdraws collateral exceeding the safe position ratio? You should add a \`_validatePosition\` check to make sure that never happens. You should add it after the \`s_userCollateral\` mapping is updated so that it is checking the final state instead of the current state. Skip the check if they don't have any borrowed CORN.
426
432
433
+
> 🧪 Run the tests for this checkpoint: \`${solidityFramework==="hardhat" ? `yarn test --grep "should prevent withdrawing collateral if it makes the position liquidatable"` : `yarn test --match-test "test_Withdraw_"`}\`
434
+
427
435
🎉 Great work! Your contract has all the necessary functionality to help people get CORN loans.
428
436
429
437
🍨 Now you get to see something real special. Run \`yarn deploy --reset\` as you usually do. Then run:
0 commit comments