challenge-1-decentralized-staking
in your base file directory.Staker.sol
and App.jsx
. yarn deploy --reset
to "refresh" your contracts in Scaffold-Eth.http://localhost:3000/
Staker UI
& Debug Contracts
.
Staker UI
contains all the frontend components we'll be primarily interacting with. Staker UI
. You'll notice that it's painfully spartan! That's what we'll be primarily flushing out.Debug Contracts,
is another frontend display that contains one of Scaffold-Eth's superpowers! yarn deploy
your contracts and configure it to read the contract data properly, it'll automatically generate a barebones UI allowing you to interact with your contract's functions.
For example, in the sample below, we can read and write information via our smart contract by simply dropping in parameters and clicking "Send". With Scaffold-Eth, we don't need to only use CLI commands and have a more intuitive way for prototyping. Debug Contracts
tab, make sure to set the variable as public!Staker.sol
file, we see that we have quite an empty Solidity file with a bunch of comments that dictate what needs to be filled out. Staker
ContractStaker
contract has an interest payout rate of 0.1 ETH for every second that the deposited ETH is eligible for interest accrumentStaker
contract should begin 2 timestamp counters. The first deadline should be set to 2 minutes and the second set to 4 minutesExampleExternalContract.sol
block.timestamp
+ XXX seconds to create deadlines exactly XXX seconds after our contract is initatiated. It's definitely a bit "naive" as a timing mechanism; can you think of a better way to implement this so its more generalizable for instance?withdrawalDeadlineReached(bool requireReached)
& claimDeadlineReached(bool requireReached)
both accept a boolean parameter and check to ensure that their respective deadlines are either true or false. notCompleted()
operates in a similar fashion but is actually a little bit more complex in nature even though it contains fewer lines of code. completed()
from an external contract outside of Staker
and checks to see if it's returning true or false to confirm if that flag has been switched.withdrawalDeadlineReached()
to be false and claimDeadlineReached()
to be false since we don't want either deadline to have passed yet. withdrawalDeadlineReached()
to be true and claimDeadlineReached()
to be false. claimDeadlineReached()
to be true since the repatriation of unproductive funds can only happen after the 4-minute mark. notCompleted
to be true since this dApp is only designed for a single use.Staker
contractexampleExternalContract
Staker.sol
should look like the following:Staker.sol
App.jsx
file, specifically at the code block around link 573, we see a block of code used to capture emitted events from our Solidity contracts and display them as a list. Staker UI
tab, you'll notice that the events box has been erased.balance
react component to help with formatting!claimPeriodLeft
and withdrawalTimeLeft
to access the stored variable values in the frontend. App.jsx
file! import { Alert, Button, Col, Menu, Row, List, Divider } from "antd";
App.jsx
should look like the following:App.jsx
yarn deploy --reset
a few times to check each window of time.Staker.sol
contract so that you receive a "non-linear" amount of ETH based on the blocks between deposit and withdrawal ExampleExternalContract
contract, implement a function in Staker.sol
that allows you to retrieve the ETH locked up in ExampleExternalContract
and re-deposit it back into the Staker
contract.Staker
contract over and over again! We want to be able to ping-pong from Staker
-> ExampleExternalContract
repeatedly!