# Grant Application: Dune Sync V2

**URL:** <https://forum.cow.fi/t/grant-application-dune-sync-v2/2597>\
**Category:** Funded Grants\
**Tags:** complete, grant-funded\
**Created:** [October 13, 2024, 2:16pm UTC](https://forum.cow.fi/t/grant-application-dune-sync-v2/2597 "2024-10-13T14:16:06Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![cowanator](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.cow.fi/cowanator/32/1134_2.png) [@cowanator](https://forum.cow.fi/u/cowanator)\
**Post date:** [October 13, 2024, 2:16pm UTC](https://forum.cow.fi/t/grant-application-dune-sync-v2/2597/1 "2024-10-13T14:16:06Z")

</div>

* * *

**Grant Title:**  
General Purpose Bidirectional Data Synchronization: Dune ↔ Local DB

* * *

**Author:**  
The implementation of this project will be carried out by

Github: @bh2smith & [@mooster531](https://github.com/mooster531)

* * *

**About the Authors:**

- _bh2smith_ is an experienced blockchain engineer and former contributor to CoW Protocol. He was the original author and primary maintainer of [Dune Sync V1](https://github.com/cowprotocol/dune-sync).

- _mooster531_ is a seasoned python developer eager to dip their toes into blockchain via data engineering.

* * *

**Grant Category:**

Other (Operation Automation)

* * *

**Grant Description:**

Dune Sync V1 is narrowly scoped and uni-directional. Version 2 aims to improve on by implementing bidirectional data “syncing” and furthermore separating the fetch-insert logic from the Source-Destination configuration. This would allow anyone to run the service from a plain configuration file and preexisting binary image.

The general-purpose tool will enable syncing:

1. **Dune to Local:**  
Archives data from Dune (e.g., historical prices or arbitrary aggregated data) via their API. This allows users to save on API costs and provides quick, easy, and local access to well-structured, readily available.

2. **Local to Dune:**  
Uploads off-chain data collected by an application-specific server (such as CoWSwap’s APP Data, Solver Competition, or ERC-4337 UserOperation requests) to Dune for the sake of transparency, availability, application insight, and overall protocol-data completion.

An outline for Version 2 is sketched in [Dune-Sync v2 · Issue #112 · cowprotocol/dune-sync · GitHub](https://github.com/cowprotocol/dune-sync/issues/112). It shows how the final result will use a configuration file to specify the Source and Destination (along with the credentials for read/write access), allowing the tool to implement fetch and insert logic for both DuneAPI and Postgres.

* * *

**Milestones:**

For the first two milestones `Local DB` refers to `Postgres`

**Milestone 1:** _Dune to Local DB_

This milestone will archive data from Dune via its API, inserting it into Postgres. For example, CoW Protocol may want to archive some of the [CoW AMM Data](https://dune.com/cowprotocol/cow-amms-v2). The docker image delivered will:

• Parse a configuration file containing Dune queries  
• Fetch query results from Dune  
• Insert records into Postgres, mindful of column type inference  
• Avoid duplication and support scheduled syncing (e.g., daily or hourly)

A proof of concept script has already been prepared at [GitHub - bh2smith/dune-sync](https://github.com/bh2smith/dune-sync) (where the project development will take place).

**Milestone 2:** _Local to Dune_

Uploads off-chain data to Dune via its [Upload CSV](https://docs.dune.com/api-reference/tables/endpoint/upload#upload-csv) endpoint. This generalizes the functionality implemented in Version 1, allowing users to upload data from a local DB to Dune using only a configuration file.

The container image should be capable of the following flow:

- User provides read access to a database and a raw SQL statement
- Data retrieved from Postgres will be transformed into CSV and uploaded to Dune via the `upload_csv` endpoint

**Milestone 3 [Optional]:** _Additional Features_

This milestone is reserved for the purpose of further maintenance, improvements, extra features or any unforeseen requirements that couldn’t fit into the first two.

This could include

- support for other databases
- asyncronous query executions (performance)
- more robust insertion conflict resolution

but is ultimately left open to the desires of CoW DAO after delivery of Milestones 1 & 2.

* * *

**Timeline:**

Milestones 1 & 2 aim to ship by early November 2024 (in time for DevCon VII).

* * *

**Funding Request:**

Funding request summary: 10000 COW + (optional 5000 COW for Milestone 3) paid as 5000 COW per milestone.

* * *

**Gnosis Chain Address (to receive the grant):**

gno:0x1ac70B075D431379c3eaF18C130764B2f609C503

* * *

**Referral:**

@fleupold

* * *

**Additional References & Resources:**

- Sketch configuration file and inspiration for this proposal: [Dune-Sync v2 · Issue #112 · cowprotocol/dune-sync · GitHub](https://github.com/cowprotocol/dune-sync/issues/112)
- Implementation notes on type mapping: [DuneSync.V2.md · GitHub](https://gist.github.com/bh2smith/415d6a831d33e673ddf7f53d8cbf4de9)

* * *

**Terms and conditions:**

> By applying for this grant, I agree to be bound by the CowDAO Participation Agreement and the COWDAO Grant Terms and Conditions.

---

<div class="post-metadata">

**Author:** ![harisang](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.cow.fi/harisang/32/524_2.png) [@harisang](https://forum.cow.fi/u/harisang)\
**Post date:** [October 23, 2024, 11:02pm UTC](https://forum.cow.fi/t/grant-application-dune-sync-v2/2597/2 "2024-10-23T23:02:57Z")

</div>

Grant is well-scoped, and the result would definitely be useful for more efficiently pushing and fetching raw competition data and CoW AMM data, so that the dbs maintained by the core team are kept in sync with Dune. Looking forward to it!

---

<div class="post-metadata">

**Author:** ![cowanator](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.cow.fi/cowanator/32/1134_2.png) [@cowanator](https://forum.cow.fi/u/cowanator)\
**Post date:** [October 24, 2024, 12:16am UTC](https://forum.cow.fi/t/grant-application-dune-sync-v2/2597/3 "2024-10-24T00:16:00Z")

</div>

Glad you like it, I have created the snapshot voting here:

[https://snapshot.org/#/cowgrants.eth/proposal/0x11be3f17f867719563898f9c36e36fe9b1423c56105155f3e203e504d6ca851e](https://snapshot.org/#/cowgrants.eth/proposal/0x11be3f17f867719563898f9c36e36fe9b1423c56105155f3e203e504d6ca851e)

---

<div class="post-metadata">

**Author:** ![cowanator](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.cow.fi/cowanator/32/1134_2.png) [@cowanator](https://forum.cow.fi/u/cowanator)\
**Post date:** [November 14, 2024, 12:09pm UTC](https://forum.cow.fi/t/grant-application-dune-sync-v2/2597/4 "2024-11-14T12:09:32Z")

</div>

Milestones 1 & 2 have been completed and candidate release can be found here:

> **[Release Candidate: Milestones 1 & 2 · bh2smith/dune-sync](https://github.com/bh2smith/dune-sync/releases/tag/v0.1.0)**
>
> This release satisfies the conditions of Milestones 1 & 2 according to the Grant Proposal Snapshot.
> What's Changed
> 
> Support for Multiple Sources & Destinations in a Single Config by @bh2smith in #6...

cc @fleupold, @harisang

If considered satisfactory, we would commence the development of Milestone 3.  
Issues for milestone 3 have been recorded here: [Issues · bh2smith/dune-sync · GitHub](https://github.com/bh2smith/dune-sync/issues?q=is%3Aopen+is%3Aissue+label%3A%22Milestone+3%22)

---

<div class="post-metadata">

**Author:** ![bh2smith](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.cow.fi/bh2smith/32/1242_2.png) [@bh2smith](https://forum.cow.fi/u/bh2smith)\
**Post date:** [November 15, 2024, 2:31pm UTC](https://forum.cow.fi/t/grant-application-dune-sync-v2/2597/5 "2024-11-15T14:31:11Z")

</div>

Dang this looks AWESOME! Can’t wait to try this out!

---

<div class="post-metadata">

**Author:** ![harisang](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.cow.fi/harisang/32/524_2.png) [@harisang](https://forum.cow.fi/u/harisang)\
**Post date:** [November 21, 2024, 9:14am UTC](https://forum.cow.fi/t/grant-application-dune-sync-v2/2597/6 "2024-11-21T09:14:35Z")

</div>

Thanks a lot for the update! Will make sure to try this out in the next few days and post an update here soon!

---

<div class="post-metadata">

**Author:** ![cowanator](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.cow.fi/cowanator/32/1134_2.png) [@cowanator](https://forum.cow.fi/u/cowanator)\
**Post date:** [November 27, 2024, 8:13pm UTC](https://forum.cow.fi/t/grant-application-dune-sync-v2/2597/7 "2024-11-27T20:13:43Z")

</div>

Milestone 3 released under v0.3.0 at

> **[Release v0.3.0 · bh2smith/dune-sync](https://github.com/bh2smith/dune-sync/releases/tag/v0.3.0)**
>
> Satisfying all requirements for Milestone 3
> What's Changed
> 
> Update Readme & MakeFile by @bh2smith in #82
> Ruff as Linter by @bh2smith in #84
> Fix the default config.yaml - had invalid src and dest re...

Kindly requesting payment. Mooooooo!

---

<div class="post-metadata">

**Author:** ![mooster](https://avatars.discourse-cdn.com/v4/letter/m/8edcca/32.png) [@mooster](https://forum.cow.fi/u/mooster)\
**Post date:** [January 12, 2025, 4:25pm UTC](https://forum.cow.fi/t/grant-application-dune-sync-v2/2597/8 "2025-01-12T16:25:32Z")

</div>

Hello everybody!

Following the release of Milestone 3, we’d hereby like to apply for a grant for future development.

Grant Title:  
General Purpose Bidirectional Data Synchronization: Dune ↔ Local DB

* * *

Author:  
The implementation of this project will be carried out by

Github: @bh2smith & @mooster531

* * *

About the Authors:

bh2smith is an experienced blockchain engineer and former contributor to CoW Protocol. He was the original author and primary maintainer of Dune Sync V1.

mooster531 is a seasoned python developer eager to dip their toes into blockchain via data engineering.

* * *

Grant Category:

Other (Operation Automation)

* * *

Grant Description:

Dune Sync V2 aims to be a versatile, user-configurable and fast utility to synchronize one or multiple Dune tables with local Postgres databases, or vice versa.  
Following the implementation and successful release of the first three milestones we’re ready to continue working on implementing the features agreed upon for Milestone 4:

1. Utilize the Dune API to create/update tables in addition to allowing data upload via CSV. The advantage of this approach is the more straightforward and robust implementation of a data upload on Dune side.
2. Ship the default Dune Sync V2 application container with a local database which can be used a temporary/staging area for data, so that multiple results from various queries can be concatenated and shipped to Dune in one Job.
3. Support appending Dune tables from a local Postgres instance
4. Support Amazon S3 Buckets as Source and Destination targets

The issues mentioned above have already been filed in the Github repo and can be seen here:

> **[Issues · bh2smith/dune-sync](https://github.com/bh2smith/dune-sync/issues?q=is%3Aissue%2Bis%3Aopen%2Blabel%3AM4)**
>
> Contribute to bh2smith/dune-sync development by creating an account on GitHub.

* * *

Timeline:

Milestone 4 can be delivered by end of March 2025. Sooner is possible, should there be an urgent need for those features.

* * *

Funding Request:

Funding request summary: 5000 COW for Milestone 4

* * *

Gnosis Chain Address (to receive the grant):

gno:0x1ac70B075D431379c3eaF18C130764B2f609C503

* * *

Additional References & Resources:

- Dune Sync V2 Github repository: [GitHub - bh2smith/dune-sync](https://github.com/bh2smith/dune-sync/)

---

<div class="post-metadata">

**Author:** ![fleupold](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.cow.fi/fleupold/32/206_2.png) [@fleupold](https://forum.cow.fi/u/fleupold)\
**Post date:** [January 13, 2025, 9:32am UTC](https://forum.cow.fi/t/grant-application-dune-sync-v2/2597/9 "2025-01-13T09:32:34Z")

</div>

Thanks for the update, I’m generally supportive of the new scope. However, could you clarify the following please:

> [@mooster](#):
>
> - Support appending Dune tables from a local Postgres instance

Shouldn’t this already be possible once support for the new dune api is completed.

I think from our current point of view, we are less interested in the S3 feature (seems more like a feature that other user’s of the system might want to use), but I’m not against it as it makes a lot of sense.

However, one other thing I’d like to add is some “technical marketing” (ie. a blog post, tutorial, etc.) to make sure more people in the space are being made a ware of this awesome public good that was developed with support of CoW Grants.

Wdyt?

---

<div class="post-metadata">

**Author:** ![bh2smith](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.cow.fi/bh2smith/32/1242_2.png) [@bh2smith](https://forum.cow.fi/u/bh2smith)\
**Post date:** [January 13, 2025, 9:48am UTC](https://forum.cow.fi/t/grant-application-dune-sync-v2/2597/10 "2025-01-13T09:48:57Z")

</div>

Right, yes I had started preparing this write up for a knowledge sharing session:

> <https://gist.github.com/bh2smith/99c374b3aa21100594a763bb52bc09d4>

We could scrape some things out of there.

As for

> Support appending Dune tables from a local Postgres instance

I believe @mooster was referring to this issue:

> <https://github.com/bh2smith/dune-sync/issues/120>
>
> This is probably out of scope for milestone 3, but given we have a use case for …it, I'd rate it more important than S3 buckets (which was already labelled for a yet to negotiate milestone 4).
> 
> We would like to be able to do the following
> 1. Run a query on some DB1 and mirror it into a temporary table/storage
> 2. Run another query on some DB2 and mirror it into a temporary table/storage
> 3. Combine the two results and upload the final table to Dune
> 
> Currently this is not possible. Potentially using csv files (which I assume would be part of #59) a strict "append" combination would be possible.
> 
> However, to be maximally flexible I wonder if the container couldn't ship with a built in local sqlite or postgres DB that could be used as a data source and sink?
> 
> Then, we could order jobs accordingly to make sure the local table is populated before it gets synced to Dune.

Perhaps they can clarify…

I would also like to include support for SQLite at some point as well.

---

<div class="post-metadata">

**Author:** ![mooster](https://avatars.discourse-cdn.com/v4/letter/m/8edcca/32.png) [@mooster](https://forum.cow.fi/u/mooster)\
**Post date:** [January 13, 2025, 4:35pm UTC](https://forum.cow.fi/t/grant-application-dune-sync-v2/2597/11 "2025-01-13T16:35:52Z")

</div>

Hey @fleupold and @bh2smith ,

About this:

> Support appending Dune tables from a local Postgres instance

I was referring to the issue currently on the board: [Dune Append Seems Possible · Issue #69 · bh2smith/dune-sync · GitHub](https://github.com/bh2smith/dune-sync/issues/69)  
However, if the currently open [PR 129](https://github.com/bh2smith/dune-sync/pull/129) handles that then point 3 in my proposal can be considered “almost resolved”.  
I hope this clears that up 🙂

+1 on the local SQLite, despite the differences in dialects between that and Postgres, I think we should consider it.

---

<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:** [February 24, 2025, 9:11am UTC](https://forum.cow.fi/t/grant-application-dune-sync-v2/2597/12 "2025-02-24T09:11:12Z")

</div>

Closed on February 24, 2025, 9:11am UTC


