Skip to content

Commit 1626b62

Browse files
committed
feat(safe): build Safe API Kit instances for different networks
Without this patch we solely rely on the Safe API Kit to figure out the URL to the Safe Transaction Service. However, this doesn't work for Filecoin Mainnet and Filecoin Calibration. These networks need an explicit URL.
1 parent 0a6c0a2 commit 1626b62

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/commands/SafeApiCommand.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import SafeApiKit from "@safe-global/api-kit";
22

3+
import { SafeApiStrategyFactory } from "../lib/safe/SafeApiKitStrategy.js";
34
import { SupabaseDataService } from "../services/SupabaseDataService.js";
45
import { ISafeApiCommand } from "../types/safe-signatures.js";
56

@@ -15,7 +16,8 @@ export abstract class SafeApiCommand implements ISafeApiCommand {
1516
this.messageHash = messageHash;
1617
this.chainId = chainId;
1718
this.dataService = new SupabaseDataService();
18-
this.safeApiKit = new SafeApiKit.default({ chainId: BigInt(chainId) });
19+
this.safeApiKit =
20+
SafeApiStrategyFactory.getStrategy(chainId).createInstance();
1921
}
2022

2123
abstract execute(): Promise<void>;

src/lib/safe/SafeApiKitStrategy.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import SafeApiKit from "@safe-global/api-kit";
2+
3+
export interface SafeApiKitStrategy {
4+
createInstance(): SafeApiKit.default;
5+
}
6+
7+
export class FilecoinMainnetStrategy implements SafeApiKitStrategy {
8+
createInstance(): SafeApiKit.default {
9+
return new SafeApiKit.default({
10+
chainId: BigInt(314),
11+
txServiceUrl: "https://transaction.safe.filecoin.io/",
12+
});
13+
}
14+
}
15+
16+
export class FilecoinTestnetStrategy implements SafeApiKitStrategy {
17+
createInstance(): SafeApiKit.default {
18+
return new SafeApiKit.default({
19+
chainId: BigInt(314159),
20+
txServiceUrl: "https://transaction-testnet.safe.filecoin.io/",
21+
});
22+
}
23+
}
24+
25+
export class DefaultSafeApiStrategy implements SafeApiKitStrategy {
26+
constructor(private chainId: number) {}
27+
28+
createInstance(): SafeApiKit.default {
29+
return new SafeApiKit.default({
30+
chainId: BigInt(this.chainId),
31+
});
32+
}
33+
}
34+
35+
export class SafeApiStrategyFactory {
36+
static getStrategy(chainId: number): SafeApiKitStrategy {
37+
switch (chainId) {
38+
case 314:
39+
return new FilecoinMainnetStrategy();
40+
case 314159:
41+
return new FilecoinTestnetStrategy();
42+
default:
43+
return new DefaultSafeApiStrategy(chainId);
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)