Skip to content

Commit

Permalink
feat: add fees
Browse files Browse the repository at this point in the history
  • Loading branch information
0xChin committed Sep 9, 2024
1 parent f448eef commit 445b2e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/contracts/Grateful.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ contract Grateful is IGrateful, Ownable2Step {
_;
}

constructor(address[] memory _tokens, IPool _aavePool) Ownable(msg.sender) {
constructor(address[] memory _tokens, IPool _aavePool, uint256 _initialFee) Ownable(msg.sender) {
aavePool = _aavePool;
fee = _initialFee;
for (uint256 i = 0; i < _tokens.length; i++) {
tokensWhitelisted[_tokens[i]] = true;
IERC20(_tokens[i]).approve(address(_aavePool), type(uint256).max);
Expand Down Expand Up @@ -209,8 +210,8 @@ contract Grateful is IGrateful, Ownable2Step {
}

function applyFee(uint256 amount) public view returns (uint256) {
uint256 fee = (amount * 100) / 10_000;
return amount - fee;
uint256 feeAmount = (amount * fee) / 10_000;
return amount - feeAmount;
}

/**
Expand Down Expand Up @@ -249,4 +250,8 @@ contract Grateful is IGrateful, Ownable2Step {

emit PaymentProcessed(_sender, _merchant, _token, _amount, yieldingFunds[_merchant], _paymentId, _subscriptionId);
}

function setFee(uint256 _newFee) external onlyOwner {
fee = _newFee;
}
}
3 changes: 2 additions & 1 deletion test/integration/IntegrationBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ contract IntegrationBase is Test {
IGrateful internal _grateful;
AaveV3Vault internal _vault;
uint256 internal _amount = 10 * 10 ** 6; // 10 DAI
uint256 internal _fee = 100;

function setUp() public {
vm.startPrank(_owner);
vm.createSelectFork(vm.rpcUrl("mainnet"), _FORK_BLOCK);
vm.label(address(_vault), "Vault");
_tokens = new address[](1);
_tokens[0] = address(_usdc);
_grateful = new Grateful(_tokens, _aavePool);
_grateful = new Grateful(_tokens, _aavePool, _fee);
_vault = new AaveV3Vault(
ERC20(address(_usdc)),
ERC20(_aUsdc),
Expand Down

0 comments on commit 445b2e7

Please sign in to comment.