Skip to content

Commit f2be762

Browse files
committed
feat: add descriptor/name to safe addresses
1 parent 02b0724 commit f2be762

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

config.example.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ telegramChannelId: "-1111"
33
slackBotToken: "xxxx"
44
slackChannelId: "C1111"
55
safeAddresses:
6-
- "eth:0x11111"
6+
- "desc: eth:0x11111"
77
signers:
88
"0x22222": "alice"
99
"0x33333": "bob"

src/SafeWatcher.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ interface SafeWatcherOptions {
2424
class SafeWatcher {
2525
readonly #prefix: string;
2626
readonly #safe: Address;
27+
readonly #name: string;
2728
readonly #notificationSender?: INotificationSender;
2829
readonly #logger: Logger;
2930
readonly #api: ISafeAPI;
@@ -33,10 +34,11 @@ class SafeWatcher {
3334
#interval?: NodeJS.Timeout;
3435

3536
constructor(opts: SafeWatcherOptions) {
36-
const [prefix, address] = parsePrefixedAddress(opts.safe);
37+
const [prefix, address, name] = parsePrefixedAddress(opts.safe);
3738
this.#logger = logger.child({ chain: prefix, address });
3839
this.#prefix = prefix;
3940
this.#safe = address;
41+
this.#name = name;
4042
this.#notificationSender = opts.notifier;
4143
this.#signers = opts.signers ?? {};
4244
this.#api = new SafeApiWrapper(opts.safe, opts.api);
@@ -125,6 +127,7 @@ class SafeWatcher {
125127

126128
await this.#notificationSender?.notify({
127129
type: isMalicious ? "malicious" : "created",
130+
name: this.#name,
128131
chainPrefix: this.#prefix,
129132
safe: this.#safe,
130133
tx: detailed,
@@ -153,6 +156,7 @@ class SafeWatcher {
153156

154157
await this.#notificationSender?.notify({
155158
type: tx.isExecuted ? "executed" : "updated",
159+
name: this.#name,
156160
chainPrefix: this.#prefix,
157161
safe: this.#safe,
158162
tx: detailed,

src/config/parsePrefixedAddress.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import type { PrefixedAddress } from "./schema.js";
55

66
export function parsePrefixedAddress(
77
addr: PrefixedAddress,
8-
): [prefix: string, address: Address] {
9-
const [prefix, address] = addr.split(":");
8+
): [prefix: string, address: Address, name: string] {
9+
const [name, prefix, address] = addr.split(":");
1010
if (!isAddress(address)) {
1111
throw new Error(`invalid prefixed safe address '${addr}'`);
1212
}
13-
return [prefix, address];
13+
return [prefix, address, name];
1414
}

src/config/schema.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { z } from "zod";
33

44
import { SafeAPIMode } from "../safe/schema.js";
55

6-
export type PrefixedAddress = `${string}:0x${string}`;
6+
export type PrefixedAddress = `${string}: ${string}:0x${string}`;
77

88
export const PrefixedAddress = z.string().transform((val, ctx) => {
9-
const regex = /^[a-zA-Z0-9]+:0x[a-fA-F0-9]{40}$/;
9+
const regex = /^[a-zA-Z0-9]+: [a-zA-Z0-9]+:0x[a-fA-F0-9]{40}$/;
1010

1111
if (!regex.test(val)) {
1212
ctx.addIssue({

src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { ListedSafeTx, SafeTx, Signer } from "./safe/index.js";
55
export type EventType = "created" | "updated" | "executed" | "malicious";
66

77
export interface Event {
8+
name: string;
89
chainPrefix: string;
910
safe: Address;
1011
type: EventType;

0 commit comments

Comments
 (0)