Skip to content

Commit 087138c

Browse files
authored
feat(new-chains): add q4 chains (#191)
# Description Add Linea and Plasma by updating SDK to latest version. It also required some minor adjustments to work with the new multi-pkg sdk # Changes - [ ] Bump to cow-sdk 7.1.0 - [ ] Added global adapter for ethersv5 - [ ] Adjusted types as needed - [ ] Added Linea config example ## How to test - Unit tests - Run the service locally with Linea config: ```json { "networks": [ { "name": "linea", "rpc": "https://rpc.linea.build", "deploymentBlock": 25028604, "filterPolicy": { "defaultAction": "ACCEPT", "conditionalOrderIds": { "0x5b3cdb6ffa3c95507cbfc459162609007865c2e87340312d3cd469c4ffbfae81": "DROP" }, "transactions": { "0x33ef06af308d1e4f94dd61fa8df43fe52b67e8a485f4e4fff75235080e663bfa": "DROP" }, "handlers": { "0xd3338f21c89745e46af56aeaf553cf96ba9bc66f": "DROP" }, "owners": { "0xd3338f21c89745e46af56aeaf553cf96ba9bc66f": "DROP" } } } ] } ``` * Should start as expected and sync to latest block - Add a custom Safe app https://swap-dev-git-feat-q4-chains-cowswap-dev.vercel.app/ - Place a TWAP order * TWAP should be created * Should see log entries in the console similar to: <img width="775" height="289" alt="image" src="https://github.com/user-attachments/assets/e8e41cac-f448-42cf-9b2f-f0de599eb734" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** - Linea network now supported for protocol operations. * **Chores** - Updated SDK dependencies and integrated new blockchain adapter libraries for enhanced network compatibility. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent bd8ed25 commit 087138c

File tree

11 files changed

+181
-79
lines changed

11 files changed

+181
-79
lines changed

config.json.example

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,25 @@
140140
}
141141
}
142142
}
143+
{
144+
"name": "linea",
145+
"rpc": "https://rpc.linea.build",
146+
"deploymentBlock": 25028604,
147+
"filterPolicy": {
148+
"defaultAction": "ACCEPT",
149+
"conditionalOrderIds": {
150+
"0x5b3cdb6ffa3c95507cbfc459162609007865c2e87340312d3cd469c4ffbfae81": "DROP"
151+
},
152+
"transactions": {
153+
"0x33ef06af308d1e4f94dd61fa8df43fe52b67e8a485f4e4fff75235080e663bfa": "DROP"
154+
},
155+
"handlers": {
156+
"0xd3338f21c89745e46af56aeaf553cf96ba9bc66f": "DROP"
157+
},
158+
"owners": {
159+
"0xd3338f21c89745e46af56aeaf553cf96ba9bc66f": "DROP"
160+
}
161+
}
162+
}
143163
]
144164
}

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@cowprotocol/watch-tower",
33
"license": "GPL-3.0-or-later",
4-
"version": "2.11.1",
4+
"version": "2.13.0",
55
"description": "A standalone watch tower, keeping an eye on Composable Cows 👀🐮",
66
"author": {
77
"name": "Cow Protocol"
@@ -46,7 +46,9 @@
4646
"dependencies": {
4747
"@commander-js/extra-typings": "^11.0.0",
4848
"@cowprotocol/contracts": "^1.4.0",
49-
"@cowprotocol/cow-sdk": "6.2.0-RC.0",
49+
"@cowprotocol/cow-sdk": "^7.1.0",
50+
"@cowprotocol/sdk-composable": "^0.1.10",
51+
"@cowprotocol/sdk-ethers-v5-adapter": "^0.2.0",
5052
"ajv": "^8.12.0",
5153
"ajv-formats": "^2.1.1",
5254
"chalk": "^4.1.2",

src/domain/events/index.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import {
2-
getAreConditionalOrderParamsEqual,
3-
getLogger,
4-
handleExecutionError,
5-
metrics,
6-
toConditionalOrderParams,
7-
} from "../../utils";
2+
ConditionalOrder,
3+
ConditionalOrderParams,
4+
} from "@cowprotocol/sdk-composable";
85
import { BytesLike, ethers } from "ethers";
96

7+
import { ChainContext } from "../../services/chain";
108
import {
119
ComposableCoW,
1210
ComposableCoW__factory,
@@ -17,9 +15,13 @@ import {
1715
Proof,
1816
Registry,
1917
} from "../../types";
20-
import { ConditionalOrder, ConditionalOrderParams } from "@cowprotocol/cow-sdk";
21-
22-
import { ChainContext } from "../../services/chain";
18+
import {
19+
getAreConditionalOrderParamsEqual,
20+
getLogger,
21+
handleExecutionError,
22+
metrics,
23+
toConditionalOrderParams,
24+
} from "../../utils";
2325
import { policy } from "../polling/filtering";
2426

2527
const composableCow = ComposableCoW__factory.createInterface();

src/domain/polling/filtering/policy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { ConditionalOrderParams } from "@cowprotocol/cow-sdk";
1+
import { ConditionalOrderParams } from "@cowprotocol/sdk-composable";
2+
23
import { Config, FilterAction as FilterActionSchema } from "../../../types";
34

45
export enum FilterAction {

src/domain/polling/index.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,28 @@ import {
44
OrderKind,
55
computeOrderUid,
66
} from "@cowprotocol/contracts";
7-
8-
import { ethers } from "ethers";
9-
import { BytesLike } from "ethers/lib/utils";
10-
117
import {
12-
ConditionalOrder as ConditionalOrderSDK,
138
OrderBookApi,
149
OrderCreation,
1510
OrderPostError,
11+
SigningScheme,
12+
SupportedChainId,
13+
} from "@cowprotocol/cow-sdk";
14+
import {
15+
ConditionalOrder as ConditionalOrderSDK,
1616
PollParams,
1717
PollResult,
1818
PollResultCode,
1919
PollResultErrors,
2020
PollResultSuccess,
21-
SigningScheme,
22-
SupportedChainId,
2321
formatEpoch,
24-
} from "@cowprotocol/cow-sdk";
22+
} from "@cowprotocol/sdk-composable";
23+
import { ethers } from "ethers";
24+
import { BytesLike } from "ethers/lib/utils";
25+
2526
import { ChainContext } from "../../services";
2627
import { ConditionalOrder, OrderStatus } from "../../types";
28+
2729
import {
2830
LoggerWithMethods,
2931
formatStatus,
@@ -410,9 +412,10 @@ async function processConditionalOrder(
410412

411413
const orderToSubmit: Order = {
412414
...order,
413-
kind: kindToString(order.kind.toString()),
414-
sellTokenBalance: balanceToString(order.sellTokenBalance.toString()),
415-
buyTokenBalance: balanceToString(order.buyTokenBalance.toString()),
415+
appData: order.appData as string,
416+
kind: kindToString(order.kind as string),
417+
sellTokenBalance: balanceToString(order.sellTokenBalance as string),
418+
buyTokenBalance: balanceToString(order.buyTokenBalance as string),
416419
validTo: Number(order.validTo),
417420
};
418421

src/domain/polling/poll.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import { SupportedChainId } from "@cowprotocol/cow-sdk";
12
import {
23
ConditionalOrderFactory,
34
ConditionalOrderParams,
45
DEFAULT_CONDITIONAL_ORDER_REGISTRY,
56
PollParams,
67
PollResult,
7-
SupportedChainId,
8-
} from "@cowprotocol/cow-sdk";
8+
} from "@cowprotocol/sdk-composable";
99
import { getLogger } from "../../utils/logging";
1010

1111
// Watch-tower will index every block, so we will by default the processing block and not the latest.

src/services/chain.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import {
22
ApiBaseUrls,
33
OrderBookApi,
4+
setGlobalAdapter,
45
SupportedChainId,
56
} from "@cowprotocol/cow-sdk";
7+
import { EthersV5Adapter } from "@cowprotocol/sdk-ethers-v5-adapter";
68
import { ethers, providers } from "ethers";
79
import { DBService } from ".";
810
import { processNewOrderEvent } from "../domain/events";
@@ -18,10 +20,10 @@ import {
1820
RegistryBlock,
1921
} from "../types";
2022
import {
21-
LoggerWithMethods,
2223
composableCowContract,
2324
getLogger,
2425
isRunningInKubernetesPod,
26+
LoggerWithMethods,
2527
metrics,
2628
} from "../utils";
2729

@@ -152,6 +154,8 @@ export class ChainContext {
152154
const provider = getProvider(rpc.toLowerCase());
153155
const chainId = (await provider.getNetwork()).chainId;
154156

157+
setGlobalAdapter(new EthersV5Adapter({ provider: provider }));
158+
155159
const registry = await Registry.load(
156160
storage,
157161
chainId.toString(),

src/types/model.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import Slack = require("node-slack");
33
import { BytesLike } from "ethers";
44

55
import {
6-
ConditionalOrder as ConditionalOrderSdk,
76
ConditionalOrderParams,
7+
ConditionalOrder as ConditionalOrderSdk,
88
PollResult,
9-
} from "@cowprotocol/cow-sdk";
9+
} from "@cowprotocol/sdk-composable";
1010
import { DBService } from "../services";
11-
import * as metrics from "../utils/metrics";
1211
import { getLogger } from "../utils/logging";
12+
import * as metrics from "../utils/metrics";
1313

1414
// Standardise the storage key
1515
const LAST_NOTIFIED_ERROR_STORAGE_KEY = "LAST_NOTIFIED_ERROR";

src/utils/contracts.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import { BigNumber, ethers } from "ethers";
2-
import { ComposableCoW, ComposableCoW__factory } from "../types";
31
import {
42
COMPOSABLE_COW_CONTRACT_ADDRESS,
53
MAX_UINT32,
6-
PollResultCode,
7-
PollResultErrors,
84
SupportedChainId,
95
} from "@cowprotocol/cow-sdk";
10-
import { getLogger } from "./logging";
6+
import { PollResultCode, PollResultErrors } from "@cowprotocol/sdk-composable";
7+
import { BigNumber, ethers } from "ethers";
118
import { metrics } from ".";
9+
import { ComposableCoW, ComposableCoW__factory } from "../types";
10+
import { getLogger } from "./logging";
1211

1312
// Define an enum for the custom error revert hints that can be returned by the ComposableCoW's interfaces.
1413
export enum CustomErrorSelectors {

src/utils/misc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ConditionalOrderParams } from "@cowprotocol/cow-sdk";
1+
import { ConditionalOrderParams } from "@cowprotocol/sdk-composable";
22
import { IConditionalOrder, OrderStatus } from "../types";
33
export function formatStatus(status: OrderStatus) {
44
switch (status) {

0 commit comments

Comments
 (0)