Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Get a list of staged files that are added, copied, modified, or renamed
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACMR | grep '\.sol' || true)

# Exit early if no files are staged
if [ -z "$STAGED_FILES" ]; then
echo "No relevant files to format."
exit 0
fi

# Run prettier check
echo "Running Prettier check..."
yarn prettier --check --ignore-unknown --plugin=prettier-plugin-solidity $STAGED_FILES

echo "Running solhint check..."
yarn solhint $STAGED_FILES
38 changes: 17 additions & 21 deletions contracts/merkle/MerkleProof.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,26 @@
pragma solidity ^0.8.24;

/*
* Merkle Proof library as seen on:
* https://github.com/gnosis/safe-token-distribution/blob/master/tooling/contracts/MerkleProof.sol
*/
* Merkle Proof library as seen on:
* https://github.com/gnosis/safe-token-distribution/blob/master/tooling/contracts/MerkleProof.sol
*/
library MerkleProof {
function verify(
bytes32[] calldata proof,
bytes32 root,
bytes32 leaf
) internal pure returns (bool) {
bytes32 computed = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computed = hashPair(computed, proof[i]);
function verify(bytes32[] calldata proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
bytes32 computed = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computed = hashPair(computed, proof[i]);
}
return computed == root;
}
return computed == root;
}

function hashPair(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
(a, b) = (a < b) ? (a, b) : (b, a);
function hashPair(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
(a, b) = (a < b) ? (a, b) : (b, a);

/// @solidity memory-safe-assembly
assembly {
mstore(0x00, a)
mstore(0x20, b)
value := keccak256(0x00, 0x40)
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, a)
mstore(0x20, b)
value := keccak256(0x00, 0x40)
}
}
}
}
2 changes: 1 addition & 1 deletion contracts/passport/PassportRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ contract PassportRegistry is Ownable, Pausable {
walletActive[wallet] = true;
idActive[id] = true;
idSource[id] = source;

uint256 result = sourcePassports[source] + 1;
sourcePassports[source] = result;

Expand Down
2 changes: 1 addition & 1 deletion contracts/passport/PassportSources.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ contract PassportSources is Ownable {
function removeSource(string memory name) external onlyOwner {
sources[name] = address(0);
}
}
}
222 changes: 111 additions & 111 deletions contracts/talent/TalentCommunitySale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,115 +7,115 @@ import "@openzeppelin/contracts/utils/math/Math.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

contract TalentCommunitySale is Ownable, ReentrancyGuard {
using Math for uint256;

IERC20 public paymentToken;
uint256 private tokenDecimals;
address public receivingWallet;

uint32 public constant TIER1_MAX_BUYS = 100;
uint32 public constant TIER2_MAX_BUYS = 580;
uint32 public constant TIER3_MAX_BUYS = 1250;
uint32 public constant TIER4_MAX_BUYS = 520;

uint32 public tier1Bought;
uint32 public tier2Bought;
uint32 public tier3Bought;
uint32 public tier4Bought;

uint256 public totalRaised;

bool public saleActive;

event Tier1Bought(address indexed buyer, uint256 amount);
event Tier2Bought(address indexed buyer, uint256 amount);
event Tier3Bought(address indexed buyer, uint256 amount);
event Tier4Bought(address indexed buyer, uint256 amount);

mapping(address => bool) public listOfBuyers;

constructor(
address initialOwner,
address _paymentToken,
address _receivingWallet,
uint256 _tokenDecimals
) Ownable(initialOwner) {
paymentToken = IERC20(_paymentToken);
receivingWallet = _receivingWallet;
tokenDecimals = _tokenDecimals;
totalRaised = 0;
saleActive = false;
}

function enableSale() external onlyOwner {
saleActive = true;
}

function disableSale() external onlyOwner {
saleActive = false;
}

function buyTier1() external nonReentrant {
require(saleActive, "TalentCommunitySale: Sale is not active");
require(
paymentToken.allowance(msg.sender, address(this)) >= 100 * 10**tokenDecimals,
"TalentCommunitySale: Insufficient allowance"
);
require(tier1Bought < TIER1_MAX_BUYS, "TalentCommunitySale: Tier 1 sold out");
require(!listOfBuyers[msg.sender], "TalentCommunitySale: Address already bought");
require(paymentToken.transferFrom(msg.sender, receivingWallet, 100 * 10**tokenDecimals), "Transfer failed");

tier1Bought++;
listOfBuyers[msg.sender] = true;
totalRaised += 100 * 10**tokenDecimals;
emit Tier1Bought(msg.sender, 100 * 10**tokenDecimals);
}

function buyTier2() external nonReentrant {
require(saleActive, "TalentCommunitySale: Sale is not active");
require(
paymentToken.allowance(msg.sender, address(this)) >= 250 * 10**tokenDecimals,
"TalentCommunitySale: Insufficient allowance"
);
require(tier2Bought < TIER2_MAX_BUYS, "TalentCommunitySale: Tier 2 sold out");
require(!listOfBuyers[msg.sender], "TalentCommunitySale: Address already bought");
require(paymentToken.transferFrom(msg.sender, receivingWallet, 250 * 10**tokenDecimals), "Transfer failed");

tier2Bought++;
listOfBuyers[msg.sender] = true;
totalRaised += 250 * 10**tokenDecimals;
emit Tier2Bought(msg.sender, 250 * 10**tokenDecimals);
}

function buyTier3() external nonReentrant {
require(saleActive, "TalentCommunitySale: Sale is not active");
require(
paymentToken.allowance(msg.sender, address(this)) >= 500 * 10**tokenDecimals,
"TalentCommunitySale: Insufficient allowance"
);
require(tier3Bought < TIER3_MAX_BUYS, "TalentCommunitySale: Tier 3 sold out");
require(!listOfBuyers[msg.sender], "TalentCommunitySale: Address already bought");
require(paymentToken.transferFrom(msg.sender, receivingWallet, 500 * 10**tokenDecimals), "Transfer failed");

tier3Bought++;
listOfBuyers[msg.sender] = true;
totalRaised += 500 * 10**tokenDecimals;
emit Tier3Bought(msg.sender, 500 * 10**tokenDecimals);
}

function buyTier4() external nonReentrant {
require(saleActive, "TalentCommunitySale: Sale is not active");
require(
paymentToken.allowance(msg.sender, address(this)) >= 1000 * 10**tokenDecimals,
"TalentCommunitySale: Insufficient allowance"
);
require(tier4Bought < TIER4_MAX_BUYS, "TalentCommunitySale: Tier 4 sold out");
require(!listOfBuyers[msg.sender], "TalentCommunitySale: Address already bought");
require(paymentToken.transferFrom(msg.sender, receivingWallet, 1000 * 10**tokenDecimals), "Transfer failed");

tier4Bought++;
listOfBuyers[msg.sender] = true;
totalRaised += 1000 * 10**tokenDecimals;
emit Tier4Bought(msg.sender, 1000 * 10**tokenDecimals);
}
using Math for uint256;

IERC20 public paymentToken;
uint256 private tokenDecimals;
address public receivingWallet;

uint32 public constant TIER1_MAX_BUYS = 100;
uint32 public constant TIER2_MAX_BUYS = 580;
uint32 public constant TIER3_MAX_BUYS = 1250;
uint32 public constant TIER4_MAX_BUYS = 520;

uint32 public tier1Bought;
uint32 public tier2Bought;
uint32 public tier3Bought;
uint32 public tier4Bought;

uint256 public totalRaised;

bool public saleActive;

event Tier1Bought(address indexed buyer, uint256 amount);
event Tier2Bought(address indexed buyer, uint256 amount);
event Tier3Bought(address indexed buyer, uint256 amount);
event Tier4Bought(address indexed buyer, uint256 amount);

mapping(address => bool) public listOfBuyers;

constructor(
address initialOwner,
address _paymentToken,
address _receivingWallet,
uint256 _tokenDecimals
) Ownable(initialOwner) {
paymentToken = IERC20(_paymentToken);
receivingWallet = _receivingWallet;
tokenDecimals = _tokenDecimals;
totalRaised = 0;
saleActive = false;
}

function enableSale() external onlyOwner {
saleActive = true;
}

function disableSale() external onlyOwner {
saleActive = false;
}

function buyTier1() external nonReentrant {
require(saleActive, "TalentCommunitySale: Sale is not active");
require(
paymentToken.allowance(msg.sender, address(this)) >= 100 * 10 ** tokenDecimals,
"TalentCommunitySale: Insufficient allowance"
);
require(tier1Bought < TIER1_MAX_BUYS, "TalentCommunitySale: Tier 1 sold out");
require(!listOfBuyers[msg.sender], "TalentCommunitySale: Address already bought");
require(paymentToken.transferFrom(msg.sender, receivingWallet, 100 * 10 ** tokenDecimals), "Transfer failed");

tier1Bought++;
listOfBuyers[msg.sender] = true;
totalRaised += 100 * 10 ** tokenDecimals;
emit Tier1Bought(msg.sender, 100 * 10 ** tokenDecimals);
}

function buyTier2() external nonReentrant {
require(saleActive, "TalentCommunitySale: Sale is not active");
require(
paymentToken.allowance(msg.sender, address(this)) >= 250 * 10 ** tokenDecimals,
"TalentCommunitySale: Insufficient allowance"
);
require(tier2Bought < TIER2_MAX_BUYS, "TalentCommunitySale: Tier 2 sold out");
require(!listOfBuyers[msg.sender], "TalentCommunitySale: Address already bought");
require(paymentToken.transferFrom(msg.sender, receivingWallet, 250 * 10 ** tokenDecimals), "Transfer failed");

tier2Bought++;
listOfBuyers[msg.sender] = true;
totalRaised += 250 * 10 ** tokenDecimals;
emit Tier2Bought(msg.sender, 250 * 10 ** tokenDecimals);
}

function buyTier3() external nonReentrant {
require(saleActive, "TalentCommunitySale: Sale is not active");
require(
paymentToken.allowance(msg.sender, address(this)) >= 500 * 10 ** tokenDecimals,
"TalentCommunitySale: Insufficient allowance"
);
require(tier3Bought < TIER3_MAX_BUYS, "TalentCommunitySale: Tier 3 sold out");
require(!listOfBuyers[msg.sender], "TalentCommunitySale: Address already bought");
require(paymentToken.transferFrom(msg.sender, receivingWallet, 500 * 10 ** tokenDecimals), "Transfer failed");

tier3Bought++;
listOfBuyers[msg.sender] = true;
totalRaised += 500 * 10 ** tokenDecimals;
emit Tier3Bought(msg.sender, 500 * 10 ** tokenDecimals);
}

function buyTier4() external nonReentrant {
require(saleActive, "TalentCommunitySale: Sale is not active");
require(
paymentToken.allowance(msg.sender, address(this)) >= 1000 * 10 ** tokenDecimals,
"TalentCommunitySale: Insufficient allowance"
);
require(tier4Bought < TIER4_MAX_BUYS, "TalentCommunitySale: Tier 4 sold out");
require(!listOfBuyers[msg.sender], "TalentCommunitySale: Address already bought");
require(paymentToken.transferFrom(msg.sender, receivingWallet, 1000 * 10 ** tokenDecimals), "Transfer failed");

tier4Bought++;
listOfBuyers[msg.sender] = true;
totalRaised += 1000 * 10 ** tokenDecimals;
emit Tier4Bought(msg.sender, 1000 * 10 ** tokenDecimals);
}
}
43 changes: 20 additions & 23 deletions contracts/talent/TalentProtocolToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,27 @@ import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Pausable.sol";

contract TalentProtocolToken is ERC20, ERC20Burnable, Pausable, Ownable {
// Mint 1B tokens to the initial owner and pause the contract
constructor(address initialOwner)
ERC20("TalentProtocolToken", "TALENT")
Ownable(initialOwner)
{
_mint(initialOwner, 1_000_000_000 ether);
_pause();
}
// Mint 1B tokens to the initial owner and pause the contract
constructor(address initialOwner) ERC20("TalentProtocolToken", "TALENT") Ownable(initialOwner) {
_mint(initialOwner, 1_000_000_000 ether);
_pause();
}

function _update(address from, address to, uint256 value) internal override(ERC20) {
require(to != address(this), "TalentProtocolToken: cannot transfer tokens to self");
require(!paused() || owner() == _msgSender(), "Token transfer is not enabled while paused");
super._update(from, to, value);
}
function _update(address from, address to, uint256 value) internal override(ERC20) {
require(to != address(this), "TalentProtocolToken: cannot transfer tokens to self");
require(!paused() || owner() == _msgSender(), "Token transfer is not enabled while paused");
super._update(from, to, value);
}

// Function to pause token transfers
function pause() external onlyOwner {
require(!paused(), "Token is already paused");
_pause();
}
// Function to pause token transfers
function pause() external onlyOwner {
require(!paused(), "Token is already paused");
_pause();
}

// Function to unpause token transfers
function unpause() external onlyOwner {
require(paused(), "Token is not paused");
_unpause();
}
// Function to unpause token transfers
function unpause() external onlyOwner {
require(paused(), "Token is not paused");
_unpause();
}
}
Loading