From 6c83097886d52dc7f02a0ce88242252b2290d21c Mon Sep 17 00:00:00 2001 From: Big Boss Date: Thu, 18 Jul 2024 13:28:11 -0700 Subject: [PATCH] contracts: bonus -> rewards (#605) --- packages/contracts/src/SendtagCheckout.sol | 20 +++++++------- packages/contracts/test/SendtagCheckout.t.sol | 26 +++++++++---------- packages/wagmi/src/generated.ts | 20 +++++++------- 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/packages/contracts/src/SendtagCheckout.sol b/packages/contracts/src/SendtagCheckout.sol index a6162ff70..05824fe03 100644 --- a/packages/contracts/src/SendtagCheckout.sol +++ b/packages/contracts/src/SendtagCheckout.sol @@ -19,8 +19,8 @@ contract SendtagCheckout is Ownable { /// @notice When false, the contract is paused and checkouts are not allowed. bool public open; - /// @notice The event emitted when a referrer is paid. - event ReferralBonus(address indexed referrer, address referred, uint256 amount); + /// @notice The event emitted when a referrer is paid a reward. + event ReferralReward(address indexed referrer, address referred, uint256 amount); /// @notice The event emitted when the contract is toggled. event Toggled(bool open); @@ -37,25 +37,25 @@ contract SendtagCheckout is Ownable { /// @notice Sends the funds to the Send Multisig and remits funds to a referrer. /// @param amount The amount of tokens to pay. /// @param referrer The address of the referrer. - /// @param bonus The amount to pay to the referrer. + /// @param reward The amount to pay to the referrer. /// @dev Does not check if amount is valid or not. That is done offchain. - function checkout(uint256 amount, address referrer, uint256 bonus) external { - require(open, "Not open"); + function checkout(uint256 amount, address referrer, uint256 reward) external { + require(open, "Closed"); require(amount > 0, "Invalid amount"); // First, collect the amount to this contract SafeERC20.safeTransferFrom(token, msg.sender, address(this), amount); // Then, pay the referrer... - if (bonus > 0) { + if (reward > 0) { require(referrer != address(0), "Invalid referrer address"); - require(bonus <= amount, "Invalid referrer bonus"); - SafeERC20.safeTransfer(token, referrer, bonus); - emit ReferralBonus(referrer, msg.sender, bonus); + require(reward <= amount, "Invalid referrer reward"); + SafeERC20.safeTransfer(token, referrer, reward); + emit ReferralReward(referrer, msg.sender, reward); } // Finally, send the funds to the Send Multisig - SafeERC20.safeTransfer(token, multisig, amount - bonus); + SafeERC20.safeTransfer(token, multisig, amount - reward); } /// @notice Toggle the contract. diff --git a/packages/contracts/test/SendtagCheckout.t.sol b/packages/contracts/test/SendtagCheckout.t.sol index 709368ca4..873a15fe6 100644 --- a/packages/contracts/test/SendtagCheckout.t.sol +++ b/packages/contracts/test/SendtagCheckout.t.sol @@ -46,36 +46,36 @@ contract SendtagCheckoutTest is Test { /// @notice Test the checkout function with a referrer. /// Bob wants a sendtag, he just found send.app because of his friend Alice and uses her referral code - function testFuzzCheckoutReferrer(uint256 amount, uint256 bonus) public { + function testFuzzCheckoutReferrer(uint256 amount, uint256 rewards) public { vm.assume(amount > 0); - vm.assume(bonus <= amount); + vm.assume(rewards <= amount); address sender = address(0xb0b); address referrer = address(0xa71ce); vm.startPrank(sender); token.mint(amount); token.approve(address(checkout), amount); - if (bonus > 0) { + if (rewards > 0) { vm.expectEmit(true, true, true, true); - emit SendtagCheckout.ReferralBonus(referrer, sender, bonus); + emit SendtagCheckout.ReferralReward(referrer, sender, rewards); } - checkout.checkout(amount, referrer, bonus); + checkout.checkout(amount, referrer, rewards); vm.stopPrank(); - assertEq(token.balanceOf(multisig), amount - bonus); + assertEq(token.balanceOf(multisig), amount - rewards); assertEq(token.balanceOf(sender), 0); - assertEq(token.balanceOf(referrer), bonus); + assertEq(token.balanceOf(referrer), rewards); } - /// @notice Test the checkout function with a bonus and invalid referrer. - function testCheckoutInvalidReferrer(uint256 amount, uint256 bonus) public { + /// @notice Test the checkout function with a rewards and invalid referrer. + function testCheckoutInvalidReferrer(uint256 amount, uint256 rewards) public { vm.assume(amount > 0); - vm.assume(bonus > 0); - vm.assume(bonus <= amount); + vm.assume(rewards > 0); + vm.assume(rewards <= amount); address sender = address(0xb0b); vm.startPrank(sender); token.mint(amount); token.approve(address(checkout), amount); vm.expectRevert("Invalid referrer address"); - checkout.checkout(amount, address(0), bonus); + checkout.checkout(amount, address(0), rewards); vm.stopPrank(); } @@ -93,7 +93,7 @@ contract SendtagCheckoutTest is Test { uint256 amount = 100; token.mint(amount); token.approve(address(checkout), amount); - vm.expectRevert("Not open"); + vm.expectRevert("Closed"); checkout.checkout(amount, address(0), 0); vm.stopPrank(); diff --git a/packages/wagmi/src/generated.ts b/packages/wagmi/src/generated.ts index 30e35be93..9f5f13348 100644 --- a/packages/wagmi/src/generated.ts +++ b/packages/wagmi/src/generated.ts @@ -3210,7 +3210,7 @@ export const sendtagCheckoutAbi = [ inputs: [ { name: 'amount', internalType: 'uint256', type: 'uint256' }, { name: 'referrer', internalType: 'address', type: 'address' }, - { name: 'bonus', internalType: 'uint256', type: 'uint256' }, + { name: 'reward', internalType: 'uint256', type: 'uint256' }, ], name: 'checkout', outputs: [], @@ -3287,7 +3287,7 @@ export const sendtagCheckoutAbi = [ { name: 'referred', internalType: 'address', type: 'address', indexed: false }, { name: 'amount', internalType: 'uint256', type: 'uint256', indexed: false }, ], - name: 'ReferralBonus', + name: 'ReferralReward', }, { type: 'event', @@ -7671,14 +7671,14 @@ export const watchSendtagCheckoutOwnershipTransferredEvent = /*#__PURE__*/ creat ) /** - * Wraps __{@link watchContractEvent}__ with `abi` set to __{@link sendtagCheckoutAbi}__ and `eventName` set to `"ReferralBonus"` + * Wraps __{@link watchContractEvent}__ with `abi` set to __{@link sendtagCheckoutAbi}__ and `eventName` set to `"ReferralReward"` * * */ -export const watchSendtagCheckoutReferralBonusEvent = /*#__PURE__*/ createWatchContractEvent({ +export const watchSendtagCheckoutReferralRewardEvent = /*#__PURE__*/ createWatchContractEvent({ abi: sendtagCheckoutAbi, address: sendtagCheckoutAddress, - eventName: 'ReferralBonus', + eventName: 'ReferralReward', }) /** @@ -12347,15 +12347,13 @@ export const useWatchSendtagCheckoutOwnershipTransferredEvent = }) /** - * Wraps __{@link useWatchContractEvent}__ with `abi` set to __{@link sendtagCheckoutAbi}__ and `eventName` set to `"ReferralBonus"` + * Wraps __{@link useWatchContractEvent}__ with `abi` set to __{@link sendtagCheckoutAbi}__ and `eventName` set to `"ReferralReward"` * * */ -export const useWatchSendtagCheckoutReferralBonusEvent = /*#__PURE__*/ createUseWatchContractEvent({ - abi: sendtagCheckoutAbi, - address: sendtagCheckoutAddress, - eventName: 'ReferralBonus', -}) +export const useWatchSendtagCheckoutReferralRewardEvent = /*#__PURE__*/ createUseWatchContractEvent( + { abi: sendtagCheckoutAbi, address: sendtagCheckoutAddress, eventName: 'ReferralReward' } +) /** * Wraps __{@link useWatchContractEvent}__ with `abi` set to __{@link sendtagCheckoutAbi}__ and `eventName` set to `"Toggled"`