Skip to content

Instantly share code, notes, and snippets.

View lucasfernandes's full-sized avatar
:octocat:
Always Coding!

0xtheL lucasfernandes

:octocat:
Always Coding!
View GitHub Profile
@lucasfernandes
lucasfernandes / Answer4.ts
Last active June 27, 2025 18:44
Bitgert Finance Blockchain Lead Developer
/**
* 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.
@lucasfernandes
lucasfernandes / Answer3.sol
Last active June 27, 2025 18:39
Bitgert Finance Blockchain Lead Developer
/**
* 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
@lucasfernandes
lucasfernandes / Answer2.sol
Last active June 27, 2025 18:38
Bitgert Finance Blockchain Lead Developer
/**
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
@lucasfernandes
lucasfernandes / Answer1.sol
Last active June 27, 2025 18:38
Bitgert Finance Blockchain Lead Developer
/**
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;
// 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";
// 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";
// 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);
// 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");
@lucasfernandes
lucasfernandes / Extensions.swift
Last active March 5, 2021 18:27
String Extensions
extension CharacterSet {
static let vowels = CharacterSet(charactersIn: "aeiou")
static let consonants = CharacterSet.letters.subtracting(vowels)
}
extension String {
var specialChars: String {
self
.components(separatedBy: .punctuationCharacters)
@lucasfernandes
lucasfernandes / githubcurl.rb
Created May 21, 2020 17:36
Github curl actions
curl https://api.github.com/authorizations --user lucasfernandes --header "X-GitHub-OTP: 921217"