Skip to content

Commit

Permalink
fix: ekoke presale soft cap related to USDT raised
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Dec 5, 2024
1 parent 936d47d commit d5c0e61
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
25 changes: 15 additions & 10 deletions ethereum/contracts/EkokePresale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract EkokePresale is Ownable {
uint256 private baseTokenPrice = 1_000_000; // 1 USDT

/// @notice The soft cap of the presale in EKOKE tokens
uint256 public constant SOFT_CAP = 2_000_000_000_000; // 20_000 EKOKE
uint256 public constant SOFT_CAP_USDT = 20_000 * 1_000_000; // 20_000 $

/// @notice The step at which the token price is increased.
/// @dev The token price is summed to baseTokenPrice every TOKEN_PRICE_STEP tokens sold
Expand All @@ -25,11 +25,14 @@ contract EkokePresale is Ownable {
mapping(address => uint256) private presaleAmounts;

/// @notice The amount of USD paid by an account (used for refunds)
mapping(address => uint256) private usdPaid;
mapping(address => uint256) private usdtPaid;

/// @notice The amount of EKOKE tokens sold in the presale
uint256 public tokensSold = 0;

/// @notice The amount of USDT raised in the presale
uint256 public usdtRaised = 0;

/// @notice The cap of the presale in EKOKE tokens
uint256 public presaleCap = 0;

Expand Down Expand Up @@ -108,10 +111,10 @@ contract EkokePresale is Ownable {
/// @notice Get the amount of USD invested by an account
/// @param _account The account to get the balance of
/// @return invested The amount of USD invested by the account
function usdInvested(
function usdtInvested(
address _account
) public view returns (uint256 invested) {
return usdPaid[_account];
return usdtPaid[_account];
}

/// @notice Buy presale tokens. The amount of tokens is 100_000_000 EKOKE with decimals, because you can't buy less than 1 token
Expand All @@ -126,16 +129,18 @@ contract EkokePresale is Ownable {
);

uint256 currentTokenPrice = tokenPrice();
uint256 usdToPay = _amount * currentTokenPrice; // NOTE: price must be calculated against the integer amount
uint256 usdtToPay = _amount * currentTokenPrice; // NOTE: price must be calculated against the integer amount

// check allowance and transfer USDT
IERC20(usdt).transferFrom(msg.sender, address(this), usdToPay);
IERC20(usdt).transferFrom(msg.sender, address(this), usdtToPay);

// set the amount of tokens bought by the account and increase the total amount of tokens sold
presaleAmounts[msg.sender] += realAmount;
tokensSold += realAmount;
// increase the amount of USD paid by the account
usdPaid[msg.sender] += usdToPay;
usdtPaid[msg.sender] += usdtToPay;
// increase the amount of USD raised
usdtRaised += usdtToPay;

emit TokensSold(msg.sender, realAmount);
}
Expand All @@ -155,11 +160,11 @@ contract EkokePresale is Ownable {
function refund() external onlyPresaleFailed {
uint256 amount = presaleAmounts[msg.sender];
require(amount > 0, "EkokePresale: No tokens to refund");
uint256 refundAmount = usdPaid[msg.sender];
uint256 refundAmount = usdtPaid[msg.sender];
require(refundAmount > 0, "EkokePresale: No USD to refund");

presaleAmounts[msg.sender] = 0;
usdPaid[msg.sender] = 0;
usdtPaid[msg.sender] = 0;
IERC20(usdt).transfer(msg.sender, refundAmount);

emit TokensRefunded(msg.sender, refundAmount);
Expand All @@ -168,7 +173,7 @@ contract EkokePresale is Ownable {
/// @notice Close the presale. From now on, no more tokens can be bought. If the soft cap is not reached, the presale is considered failed
function adminClosePresale() external onlyOwner onlyPresaleOpen {
presaleOpen = false;
if (tokensSold < SOFT_CAP) {
if (usdtRaised < SOFT_CAP_USDT) {
presaleFailed = true;
} else {
presaleFailed = false;
Expand Down
5 changes: 3 additions & 2 deletions ethereum/test/EkokePresale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe("EkokePresale", () => {

// verify balances
expect(await presale.balanceOf(owner.address)).to.equal(ekokeToE8s(1_000));
expect(await presale.usdInvested(owner.address)).to.equal(totalPrice);
expect(await presale.usdtInvested(owner.address)).to.equal(totalPrice);

// check USDT balance
expect(await usdt.balanceOf(owner.address)).to.equal(
Expand Down Expand Up @@ -117,7 +117,7 @@ describe("EkokePresale", () => {

// verify balances
expect(await presale.balanceOf(owner.address)).to.equal(ekokeToE8s(200));
expect(await presale.usdInvested(owner.address)).to.equal(
expect(await presale.usdtInvested(owner.address)).to.equal(
totalPrice * BigInt(2)
);
});
Expand Down Expand Up @@ -162,6 +162,7 @@ describe("EkokePresale", () => {

// verify balances
expect(balance).to.equal(SOFT_CAP);
expect(await presale.usdtRaised()).to.equal(20_000 * 1_000_000);

// verify presale balance is 0
expect(await presale.balanceOf(alice.address)).to.equal(0);
Expand Down

0 comments on commit d5c0e61

Please sign in to comment.