# Grant Application: Automated fee withdrawal

**URL:** <https://forum.cow.fi/t/grant-application-automated-fee-withdrawal/2388>\
**Category:** Funded Grants\
**Tags:** complete, grant-funded\
**Created:** [April 12, 2024, 8:15am UTC](https://forum.cow.fi/t/grant-application-automated-fee-withdrawal/2388 "2024-04-12T08:15:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![meetm](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@meetm](https://forum.cow.fi/u/meetm)\
**Post date:** [April 12, 2024, 8:15am UTC](https://forum.cow.fi/t/grant-application-automated-fee-withdrawal/2388/1 "2024-04-12T08:15:54Z")

</div>

# CoW Grant - Automated fee withdrawal

## Author

I am [meetmangukiya](https://github.com/meetmangukiya). I am a software developer, have been in DeFi and web3 space for over 3 years now. I also have familiarity with CoW protocol technicals.

## Grant Category

Other/Misc.

## Grant Description

Automated fee withdrawal for solver fee distribution.

## Grant Goals and Impact

Current process is automated but requires manual inspection of calldata everytime its ran by the core team members. It also requires the signers to sign the transactions everytime its ran. With the safe module contract code it won’t require dilligence since the contract code will enforce it.

### Scope

Create a Safe module that can be enabled on the Safe `0x423cEc87f19F0778f549846e0801ee267a917935` that accepts an array of tokens to be sold. The orders created must adhere to the aforementioned limitations (i.e. `receiver`).

The grant would specifically cover the work for handling automated fee collection. Precisely:

1. A Safe module smart contract, which creates orders on behalf of the smart contract.
2. A script that triggers order creation onchain.

The Safe module is required to:

- Be deployed with the `receiver` (`address`), `to-token` (`address`), and `keeper` (`address`) set as immutable variables.
- Provide a permissioned `drip` function (callable only by `keeper`) for “dripping” protocol fees into the `receiver`’s account by means of CoW Protocol orders.
  - Accepts an array of structs, with the struct being defined as:

  - Creates an order selling the tokens from the `GPv2Settlement` contract to the `receiver` that is partially fillable and has buy amount 1.

  - Calls `settle` and triggers the orders via `setPreSignature`.

- Provide a permissioned `approve` function to approve the vault relayer from the settlement contract.
  - Accepts an array of IERC20 tokens.
  - Approves the vault relayer on behalf of the settlement contract to spend type(uint256).max

- Provide a permissioned `revoke` function to revoke approvals from the settlement contract to _any_ contract.
  - Accepts an array of structs, with the struct being defined as:

  - Approves the vault relayer on behalf of the settlement contract to spend 0.

- Gas consumption is kept to a minimum. A suggestion here is to not sell the entire balance and leave 1 wei so as to not reset the slot to zero, and waste a refund.
- Be written in Solidity v0.8.25 using the foundry smart contract development framework.
- Have comprehensive test coverage.
- A script, readily packaged in a docker container, writting in typescript and ethers v6 that:
  - Handles similar parameters as the `self-sell` script above.
  - Creates the transaction for calling `drip` by the `keeper` EOA.
  - Calls the API to post the orders.

The script is required to:

- Determine which tokens should be withdrawn from the settlement contract. This is all tokens whose balance on the settlement contract is worth more than a fixed, configurable amount in USD.
- Determine which tokens need to be approved for trading.
- Post orders to the API in the format that is accepted by the Safe module for each token to be withdrawn.
- Send a transaction from an EOA to the module that sets any needed approval and calls `drip` for all orders created in the previous step.

## Milestones

- The safe module
- Tests
- Script

. Will probably deliver this under 2 weeks.

## Funding Request

5000 xDAI. Full payment can be made on delivery is fine.

## Budget breakdown

- Development - 5000 xDAI

## Gnosis Chain Address

`0xd33d055ea52ec5a685995d40f19fa98d0744df0c`

## Terms and Conditions

By submitting this grant application, I acknowledge and agree to be bound by the CoW DAO Participation Agreement and the CoW Grant Terms and Conditions.

---

<div class="post-metadata">

**Author:** ![mfw78](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.cow.fi/mfw78/32/1598_2.png) [@mfw78](https://forum.cow.fi/u/mfw78)\
**Post date:** [April 12, 2024, 8:18am UTC](https://forum.cow.fi/t/grant-application-automated-fee-withdrawal/2388/2 "2024-04-12T08:18:35Z")

</div>

This will have a tangible, direct effect reducing workload required by the core team with reviewing fee withdrawal transactions, and allow for a higher cadence of fee collection, reducing pressure on bonding mechanisms as well with the advent of fee collection initiatives that have been implemented recently by CoW DAO. I signal my support for this grant.

---

<div class="post-metadata">

**Author:** ![netrunner.eth](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.cow.fi/netrunner.eth/32/252_2.png) [@netrunner.eth](https://forum.cow.fi/u/netrunner.eth)\
**Post date:** [April 12, 2024, 8:43am UTC](https://forum.cow.fi/t/grant-application-automated-fee-withdrawal/2388/3 "2024-04-12T08:43:43Z")

</div>

I agree with @mfw78. This will be on benefit to the core team, giving them the ability to expend efforts elsewhere. I signal my support for this grant.

---

<div class="post-metadata">

**Author:** ![Chim9](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.cow.fi/chim9/32/417_2.png) [@Chim9](https://forum.cow.fi/u/Chim9)\
**Post date:** [April 12, 2024, 8:57am UTC](https://forum.cow.fi/t/grant-application-automated-fee-withdrawal/2388/4 "2024-04-12T08:57:15Z")

</div>

Very interesting proposal even more as mfw78’s comment makes it clear that this proposal will be helpful for the CoW DAO and core team. I support this proposal.

---

<div class="post-metadata">

**Author:** ![Kubesqrt](https://avatars.discourse-cdn.com/v4/letter/k/b38774/32.png) [@Kubesqrt](https://forum.cow.fi/u/Kubesqrt)\
**Post date:** [April 13, 2024, 4:20pm UTC](https://forum.cow.fi/t/grant-application-automated-fee-withdrawal/2388/5 "2024-04-13T16:20:20Z")

</div>

This is a very interesting proposal.

Given the proposed value of the proposal to the Core Team I signal support for this proposal.

---

<div class="post-metadata">

**Author:** ![meetm](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@meetm](https://forum.cow.fi/u/meetm)\
**Post date:** [April 27, 2024, 9:34am UTC](https://forum.cow.fi/t/grant-application-automated-fee-withdrawal/2388/6 "2024-04-27T09:34:11Z")

</div>

Github repo: [GitHub - cowdao-grants/cow-fee](https://github.com/cowdao-grants/cow-fee)

---

<div class="post-metadata">

**Author:** ![Chim9](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.cow.fi/chim9/32/417_2.png) [@Chim9](https://forum.cow.fi/u/Chim9)\
**Post date:** [February 6, 2025, 3:20pm UTC](https://forum.cow.fi/t/grant-application-automated-fee-withdrawal/2388/7 "2025-02-06T15:20:57Z")

</div>


