Gauravk0029 / madhouse-wallet

MIT License
1 stars 0 forks source link

Collect Madhouse Wallet fees #15

Open quincy120 opened 1 week ago

quincy120 commented 1 week ago

We should create module for the gnosis smart wallet. when the user sends btc to the wallet, they would authorize an allowance for the smart wallet to collect. This allowance will be in aavetBTC tokens. that will be what the contract will send to a targeted wallet daily.

Collecting fees: Allow for send: https://github.com/safe-global/safe-modules/tree/main/modules/allowances Trigger: https://chain.link/tutorials/trigger-smart-contract-execution Create Module: https://docs.safe.global/advanced/smart-account-modules Add Module UI: https://help.safe.global/en/articles/40826-add-a-module Module here: https://github.com/5afe/safe-core-protocol/blob/main/contracts/interfaces/Modules.sol Deploy safe with module: https://github.com/safe-global/safe-modules/tree/466a9b8ef169003c5df856c6ecd295e6ecb9e99d/examples/4337-passkeys

Create module via sdk: https://github.com/safe-global/safe-core-sdk/tree/014f365e46cf278897c5ece45c1490c7c749f2d7/packages/protocol-kit/src/managers

Exposed modulemanager via protocolkit here: https://github.com/safe-global/safe-core-sdk/blob/014f365e46cf278897c5ece45c1490c7c749f2d7/packages/protocol-kit/src/Safe.ts

The module would send 3%/365 of aavetBTC tokens to a wallet every day.

// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract PercentageSender {

address payable public recipient; // Address to receive the percentage
uint256 public percentage; // Percentage to send (e.g., 10 for 10%) 

constructor(address payable _recipient, uint256 _percentage) {
    recipient = _recipient;
    percentage = _percentage;
}

function sendPercentage() public {
    uint256 amountToSend = (address(this).balance * percentage) / 100;
    recipient.transfer(amountToSend);
}

}

Explanation: Contract Details: recipient: A public variable storing the address where the percentage of the wallet balance will be sent. percentage: A public variable defining the percentage of the balance to be sent (represented as a whole number, e.g., 10 for 10%). Constructor: When deploying the contract, you need to specify the recipient address and the desired percentage. sendPercentage function: Calculation: (address(this).balance * percentage) / 100: Calculates the amount to send by multiplying the contract's balance by the specified percentage and dividing by 100 to get the correct percentage value. Transfer: recipient.transfer(amountToSend): Sends the calculated amount to the designated recipient address using the transfer function. Key Points: Security Considerations: Gas Fees: Be aware of potential gas fees associated with sending transactions, especially if the percentage is large or the recipient address is on a different network. Reentrancy Attacks: Consider implementing safeguards against reentrancy attacks if your contract interacts with other contracts. Access Control: If you want to restrict who can trigger the sendPercentage function, you can add access control mechanisms like onlyOwner modifiers. How to Use:

  1. Deploy the Contract: Provide the desired recipient address and percentage value when deploying the contract.
  2. Trigger the Transfer: Call the sendPercentage function on the deployed contract. This will automatically calculate and send the specified percentage from the contract's balance to the recipient. Important Note: This is a basic example and might need adjustments depending on your specific requirements, such as handling different token standards, adding additional functionalities, or implementing more complex logic for percentage calculations. Always thoroughly test your smart contracts before deploying on a live network.
quincy120 commented 6 days ago

This is the job used to collect fees. we are triggering from a cron job in aws

Image

quincy120 commented 4 days ago

We will need to add signed verification for any module execution from here: https://www.kaleido.io/blockchain-platform/aws-cloudhsm-signer

https://medium.com/@etimpaul22/signature-verification-in-smart-contracts-8666baa06614

https://console.kaleido.io/profile/apikeys https://docs.kaleido.io/kaleido-services/cloudhsm/