update all contracts
This commit is contained in:
parent
88c5aa6ec8
commit
868fab32c4
|
|
@ -0,0 +1,74 @@
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.8.0;
|
||||||
|
|
||||||
|
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||||
|
import "./DTLToken.sol";
|
||||||
|
import "./NftCertificate.sol";
|
||||||
|
|
||||||
|
contract CubLearn is Ownable {
|
||||||
|
DTLToken dtlContract;
|
||||||
|
NftCertificate cubcertContract;
|
||||||
|
|
||||||
|
uint256 public cashbackPercentage;
|
||||||
|
|
||||||
|
// course id => price in DTL
|
||||||
|
mapping(string => uint256) private coursePrices;
|
||||||
|
|
||||||
|
// course id => student address => is enrolled
|
||||||
|
mapping(string => mapping(address => bool)) private enrolledCourses;
|
||||||
|
|
||||||
|
// course id => student address => is certificate issued
|
||||||
|
mapping(string => mapping(address => bool)) private issuedCertificates;
|
||||||
|
|
||||||
|
constructor(address dtlContractAddress, address cubcertContractAddress) Ownable(msg.sender) {
|
||||||
|
dtlContract = DTLToken(dtlContractAddress);
|
||||||
|
cubcertContract = NftCertificate(cubcertContractAddress);
|
||||||
|
|
||||||
|
coursePrices["1"] = 300;
|
||||||
|
coursePrices["2"] = 500;
|
||||||
|
coursePrices["3"] = 200;
|
||||||
|
cashbackPercentage = 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setCashbackPercentage(uint256 newValue) external onlyOwner {
|
||||||
|
require(newValue <= 100, "Cashback percentage cannot be more than 100.");
|
||||||
|
|
||||||
|
cashbackPercentage = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
function enroll(string memory courseId) external {
|
||||||
|
require(coursePrices[courseId] != 0, "Course not found.");
|
||||||
|
|
||||||
|
dtlContract.transferFrom(msg.sender, address(this), coursePrices[courseId]);
|
||||||
|
|
||||||
|
enrolledCourses[courseId][msg.sender] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function finishCourse(
|
||||||
|
string memory courseId,
|
||||||
|
string memory studentFullName,
|
||||||
|
string memory courseName,
|
||||||
|
string memory instructorFullName
|
||||||
|
) external {
|
||||||
|
require(enrolledCourses[courseId][msg.sender], "Must be enrolled in course.");
|
||||||
|
require(!issuedCertificates[courseId][msg.sender], "Certificate already issued.");
|
||||||
|
|
||||||
|
cubcertContract.mintCertificate(msg.sender, studentFullName, courseName, instructorFullName);
|
||||||
|
|
||||||
|
// Mark the certificate as issued
|
||||||
|
issuedCertificates[courseId][msg.sender] = true;
|
||||||
|
|
||||||
|
// Cashback
|
||||||
|
uint256 cashbackAmount = coursePrices[courseId] * cashbackPercentage / 100;
|
||||||
|
dtlContract.transfer(msg.sender, cashbackAmount);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDTLBalance() external view onlyOwner returns (uint256) {
|
||||||
|
return dtlContract.balanceOf(address(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
function transferAllDTLBalanceToMe() external onlyOwner {
|
||||||
|
uint256 balance = dtlContract.balanceOf(address(this));
|
||||||
|
dtlContract.transfer(msg.sender, balance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.8.0;
|
||||||
|
|
||||||
|
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||||
|
|
||||||
|
contract DTLToken is ERC20 {
|
||||||
|
constructor(address initialHolder) ERC20("Digital Turkish Lira", "DTL") {
|
||||||
|
_mint(initialHolder, 1000000000);
|
||||||
|
}
|
||||||
|
|
||||||
|
function decimals() public view virtual override returns (uint8) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function approveMax(address spender) external returns (bool) {
|
||||||
|
return approve(spender, totalSupply());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,9 +12,6 @@ contract NftCertificate is ERC721 {
|
||||||
|
|
||||||
mapping(uint256 => CertificateInfo) private certificateInfoMapping;
|
mapping(uint256 => CertificateInfo) private certificateInfoMapping;
|
||||||
|
|
||||||
// course id => student address => is cert issued
|
|
||||||
mapping(string => mapping(address => bool)) private issuedCertificates;
|
|
||||||
|
|
||||||
struct CertificateInfo {
|
struct CertificateInfo {
|
||||||
string studentFullName;
|
string studentFullName;
|
||||||
string courseName;
|
string courseName;
|
||||||
|
|
@ -24,21 +21,16 @@ contract NftCertificate is ERC721 {
|
||||||
constructor() ERC721("CubLearn Certificate", "CUBCERT") {}
|
constructor() ERC721("CubLearn Certificate", "CUBCERT") {}
|
||||||
|
|
||||||
function mintCertificate(
|
function mintCertificate(
|
||||||
string memory courseId,
|
address recipient,
|
||||||
string memory studentFullName,
|
string memory studentFullName,
|
||||||
string memory courseName,
|
string memory courseName,
|
||||||
string memory instructorFullName
|
string memory instructorFullName
|
||||||
) external {
|
) external {
|
||||||
require(!issuedCertificates[courseId][msg.sender], "Certificate already issued.");
|
|
||||||
|
|
||||||
uint256 tokenId = nextTokenId;
|
uint256 tokenId = nextTokenId;
|
||||||
|
|
||||||
_storeCertificateInfo(tokenId, studentFullName, courseName, instructorFullName);
|
_storeCertificateInfo(tokenId, studentFullName, courseName, instructorFullName);
|
||||||
|
|
||||||
_safeMint(msg.sender, tokenId);
|
_safeMint(recipient, tokenId);
|
||||||
|
|
||||||
// Mark the certificate as issued
|
|
||||||
issuedCertificates[courseId][msg.sender] = true;
|
|
||||||
|
|
||||||
nextTokenId++;
|
nextTokenId++;
|
||||||
}
|
}
|
||||||
|
|
@ -85,7 +77,7 @@ contract NftCertificate is ERC721 {
|
||||||
}
|
}
|
||||||
|
|
||||||
function tokenURI(uint256 tokenId)
|
function tokenURI(uint256 tokenId)
|
||||||
external
|
public
|
||||||
view
|
view
|
||||||
override
|
override
|
||||||
returns (string memory)
|
returns (string memory)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue