diff --git a/packages/hardhat/contracts/SubscryptoToken.sol b/packages/hardhat/contracts/SubscryptoToken.sol index 7b9153d..4c3d1ed 100644 --- a/packages/hardhat/contracts/SubscryptoToken.sol +++ b/packages/hardhat/contracts/SubscryptoToken.sol @@ -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) @@ -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