Skip to content

Commit

Permalink
add basic tenderly action triggered by settlement events (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith authored Feb 9, 2023
1 parent 9b8b126 commit e6a40d8
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 0 deletions.
38 changes: 38 additions & 0 deletions internal_transfers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Internal Transfers


## Motivation & Summary
Internal Settlements have been a challenge to evaluate slippage since some information
required for the computation never winds up on chain.
Specifically, when the driver decides to internalize an interaction provided by a solver,
the interaction is excluded from the settlement call data.
In order to recover this data we must make token transfers (or imbalances) from
internalized interactions transparently available for consumption.

This project replaces the subquery
[buffer_trades](https://github.com/cowprotocol/solver-rewards/blob/c7e9c85706decb1a1be28d639ee34e35646bca50/queries/dune_v2/period_slippage.sql#L239-L309)
(an approximation for internal interactions implemented purely within Dune Analytics) with the actual internalized data.

In brief, the project consists of a Data Pipeline implementing the following flow;

1. WebHook/Event Listener for CoW Protocol Settlement Events emitted by [CoW Protocol: GPv2Settlement](https://etherscan.io/address/0x9008d19f58aabd9ed0d60971565aa8510560ab41)
2. Settlement Events trigger an ETL Pipeline that
- Fetches full/unoptimized call data provided by the solver for the winning settlement from the [Orderbook API](https://api.cow.fi/docs/#)
- Simulates the full call data extracting and classifying transfers from event logs
- Evaluates the `InternalizedLedger` as the difference `FullLedger - ActualLedger`
3. Finally, the `InternalizedLedger` from step 2 is written to a [Database](./database/README.md) and later synced into Dune community sources.

For more Details on each component outlined above please visit respective readmes:


## [Webhook] Tenderly Actions

Documentation: https://tenderly.co/web3-actions
Requirements: [Tenderly CLI](https://github.com/Tenderly/tenderly-cli)

actions directory was scaffolded and deployed as follows:

```shell
tenderly actions init --language typescript
tenderly actions deploy
```
5 changes: 5 additions & 0 deletions internal_transfers/actions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Dependency directories
node_modules/

# Ignore tsc output
out/**/*
15 changes: 15 additions & 0 deletions internal_transfers/actions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {
ActionFn,
Context,
Event,
TransactionEvent,
} from '@tenderly/actions';

export const triggerInternalTransfersPipeline: ActionFn = async (
context: Context,
event: Event
) => {
const transactionEvent = event as TransactionEvent;
const txHash = transactionEvent.hash;
console.log(`Received Settlement Event with txHash ${txHash}`);
};
18 changes: 18 additions & 0 deletions internal_transfers/actions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions internal_transfers/actions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "actions",
"scripts": {
"build": "tsc"
},
"devDependencies": {
"typescript": "^4.3.5"
},
"dependencies": {
"@tenderly/actions": "^0.1.0"
},
"private": true
}
18 changes: 18 additions & 0 deletions internal_transfers/actions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compileOnSave": true,
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "out",
"sourceMap": true,
"strict": true,
"target": "es2020"
},
"exclude": [
"**/*.spec.ts"
],
"include": [
"**/*"
]
}
19 changes: 19 additions & 0 deletions internal_transfers/tenderly.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
actions:
gp-v2/solver-slippage:
runtime: v2
sources: actions
specs:
settlement-event-trigger:
description: Trigger Data Pipeline for each Settlement event.
function: index:triggerInternalTransfersPipeline
trigger:
type: transaction
transaction:
status:
- mined
filters:
- network: 1
eventEmitted:
contract:
address: 0x9008D19f58AAbD9eD0D60971565AA8510560ab41
name: Settlement

0 comments on commit e6a40d8

Please sign in to comment.