This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ANSWER 4: | |
* While the question references `web3.js`, I typically prefer using `ethers.js` | |
* for frontend interactions due to its cleaner API, better modularity, and superior developer experience. | |
* | |
* When implementing real-time staking balance and rewards updates, the first thing I consider is: | |
* | |
* 👉 **Is there a subgraph (The Graph) available?** | |
* | |
* If yes, I always prefer querying the subgraph via GraphQL — it's efficient, fast, and offloads logic from the frontend. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ANSWER 3: | |
* BEP-20 tokens follow the same interface as ERC-20 (EVM standard). | |
* To interact with a BEP-20 token, I use the standard ERC-20 interface, | |
* or preferably the `SafeERC20` wrapper from OpenZeppelin to improve safety. | |
* | |
* Key functions used to interact with the token contract: | |
* | |
* - `transferFrom(address from, address to, uint256 amount)` — for staking |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
ANSWER 2: | |
Reentrancy is a type of attack where an external contract repeatedly calls back into a vulnerable function | |
before the previous execution is completed. This can be exploited to manipulate the contract's state | |
or drain its funds. | |
To prevent this, we can use the `ReentrancyGuard` contract from OpenZeppelin and apply its `nonReentrant` modifier. | |
*/ | |
// SPDX-License-Identifier: UNLICENSED |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
ANSWER 1: | |
In order to enforce lock-up periods, I typically use a staking info struct that | |
stores details of each user stake, including the timestamp when they staked. | |
Then, in the withdraw function, I check whether the lock-up period has passed | |
using a `require` statement, like this: | |
*/ | |
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity 0.8.28; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity 0.8.28; | |
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | |
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | |
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; | |
import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol"; | |
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; | |
import {IVesting} from "./interfaces/IVesting.sol"; | |
import {ISamuraiTiers} from "./interfaces/ISamuraiTiers.sol"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: UNLINCENSED | |
pragma solidity 0.8.28; | |
import {Script} from "forge-std/Script.sol"; | |
import {Vesting} from "../src/Vesting.sol"; | |
import {IVesting} from "../src/interfaces/IVesting.sol"; | |
import {console} from "forge-std/console.sol"; | |
import {SamuraiTiers} from "../src/SamuraiTiers.sol"; | |
import {ISamuraiTiers} from "../src/interfaces/ISamuraiTiers.sol"; | |
import {ERC20Mock} from "../src/mocks/ERC20Mock.sol"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MyContract constructor | |
constructor(address,uint256,MyInterface.MyStruct[] memory,bool,bool) | |
// Script used in deploy | |
function run() external returns (MyContract myContract) { | |
address someAddress = 0x...; | |
uint256 totalMax = 100_000 ether; | |
MyInterface.MyStruct[] memory strs = new MyInterface.MyStruct[](6); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity ^0.8.20; | |
import "forge-std/Script.sol"; | |
import "../src/Sam.sol"; | |
contract SamScript is Script { | |
function run() public { | |
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CharacterSet { | |
static let vowels = CharacterSet(charactersIn: "aeiou") | |
static let consonants = CharacterSet.letters.subtracting(vowels) | |
} | |
extension String { | |
var specialChars: String { | |
self | |
.components(separatedBy: .punctuationCharacters) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl https://api.github.com/authorizations --user lucasfernandes --header "X-GitHub-OTP: 921217" |
NewerOlder