Skip to content

Commit 62c20c5

Browse files
Add Talent Plus smart contracts
1 parent 5879539 commit 62c20c5

13,038 files changed

Lines changed: 1210 additions & 1371805 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.24;
3+
4+
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
5+
import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
6+
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
7+
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
8+
import "./TalentPlusSubscription.sol";
9+
import "@openzeppelin/contracts/access/Ownable.sol";
10+
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
11+
12+
contract TalentPlus is Ownable, ReentrancyGuard {
13+
using ECDSA for bytes32;
14+
using SafeERC20 for IERC20;
15+
16+
// TALENT token address
17+
IERC20 public immutable TALENT_TOKEN;
18+
19+
address public trustedSigner;
20+
address public feeReceiver;
21+
TalentPlusSubscription public talentPlusSubscription;
22+
23+
event SubscriptionCreated(address indexed user, uint256 score, string subscriptionSlug);
24+
25+
bool public enabled;
26+
27+
constructor(
28+
address _trustedSigner,
29+
address _talentPlusSubscriptionAddress,
30+
address _feeReceiver,
31+
address _talentTokenAddress
32+
) Ownable(msg.sender) {
33+
trustedSigner = _trustedSigner;
34+
talentPlusSubscription = TalentPlusSubscription(_talentPlusSubscriptionAddress);
35+
feeReceiver = _feeReceiver;
36+
TALENT_TOKEN = IERC20(_talentTokenAddress);
37+
enabled = true;
38+
}
39+
40+
/**
41+
* @notice Enables or disables the TalentPlus contract.
42+
* @param _enabled Whether the TalentPlus contract should be enabled.
43+
* @dev Can only be called by the owner.
44+
*/
45+
function setEnabled(bool _enabled) public onlyOwner {
46+
enabled = _enabled;
47+
}
48+
49+
/**
50+
* @notice Disables the TalentPlus contract.
51+
* @dev Can only be called by the owner.
52+
*/
53+
function setDisabled() public onlyOwner {
54+
enabled = false;
55+
}
56+
57+
/**
58+
* @notice Updates the TalentPlusSubscription contract address.
59+
* @param _talentPlusSubscriptionAddress The new TalentPlusSubscription contract address.
60+
* @dev Can only be called by the owner.
61+
*/
62+
function updateTalentPlusSubscription(address _talentPlusSubscriptionAddress) public onlyOwner {
63+
require(_talentPlusSubscriptionAddress != address(0), "Invalid TalentPlusSubscription address");
64+
talentPlusSubscription = TalentPlusSubscription(_talentPlusSubscriptionAddress);
65+
}
66+
67+
/**
68+
* @notice Updates the fee receiver address.
69+
* @param _feeReceiver The new fee receiver address.
70+
* @dev Can only be called by the owner.
71+
*/
72+
function updateReceiver(address _feeReceiver) public onlyOwner {
73+
feeReceiver = _feeReceiver;
74+
}
75+
76+
/**
77+
* @notice Creates a subscription if the provided number is signed by the trusted signer.
78+
* @param score The number to be attested.
79+
* @param subscriptionSlug The subscription slug to set in TalentPlusSubscription.
80+
* @param signature The signature of the trusted signer.
81+
*/
82+
function subscribe(uint256 score, string memory subscriptionSlug, bytes memory signature) public nonReentrant {
83+
require(enabled, "Subscription is disabled for this contract");
84+
require(bytes(subscriptionSlug).length > 0, "Subscription slug cannot be empty");
85+
86+
// Get the subscription model details including price
87+
(, uint256 subscriptionCost, bool isActive) = talentPlusSubscription.getSubscriptionModel(subscriptionSlug);
88+
require(isActive, "Subscription model is not active");
89+
90+
// Hash the number with the user's wallet address
91+
bytes32 numberHash = keccak256(abi.encodePacked(score, msg.sender));
92+
93+
// Recover the address that signed the hash
94+
address signer = MessageHashUtils.toEthSignedMessageHash(numberHash).recover(signature);
95+
96+
// Ensure the signer is the trusted signer
97+
require(signer == trustedSigner, "Invalid signature");
98+
99+
// Transfer TALENT tokens from user to fee receiver
100+
TALENT_TOKEN.safeTransferFrom(msg.sender, feeReceiver, subscriptionCost);
101+
102+
// Set the user subscription in TalentPlusSubscription using wallet address
103+
talentPlusSubscription.addUserSubscription(msg.sender, subscriptionSlug);
104+
105+
emit SubscriptionCreated(msg.sender, score, subscriptionSlug);
106+
}
107+
}

0 commit comments

Comments
 (0)