Skip to content

Commit

Permalink
Add topUp fn
Browse files Browse the repository at this point in the history
  • Loading branch information
wbt committed Oct 21, 2023
1 parent 1b216d1 commit 00fcbd0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/hardhat/contracts/SubscryptoToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ contract SubscryptoToken is ERC20, ERC20Burnable, Ownable, ERC20Permit {
uint amount
);

event TopUp(
address indexed merchant,
address indexed customer,
uint amount
);

// Constructor: Called once on contract deployment
// Check packages/hardhat/deploy/00_deploy_your_contract.ts
constructor(address initialOwner)
Expand Down Expand Up @@ -93,6 +99,21 @@ contract SubscryptoToken is ERC20, ERC20Burnable, Ownable, ERC20Permit {
);
}

function topUpWithMerchant(
address merchant,
uint amount
) public {
address customer = msg.sender;
require(balanceOf(customer) >= amount, 'Insufficient balance in Subscrypto contract.');
_burn(customer, amount);
serviceDeposits[merchant][customer] += amount;
emit TopUp(
merchant,
msg.sender,
amount
);
}

/**
* Called by a customer to choose which tier to be in
* Set tierIndex = 0 to end subscription
Expand Down

0 comments on commit 00fcbd0

Please sign in to comment.