From 00fcbd0ecfd69c8f3aee5a6d762a8fcc90392956 Mon Sep 17 00:00:00 2001 From: WBT Date: Sat, 21 Oct 2023 14:10:43 -0400 Subject: [PATCH] Add topUp fn --- .../hardhat/contracts/SubscryptoToken.sol | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) 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