-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.ts
More file actions
73 lines (61 loc) · 2.61 KB
/
index.ts
File metadata and controls
73 lines (61 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { PermitMessage } from "../types";
import { SeaPortPayload } from "../types/seaport";
import { BlurIoOrder } from "../types/blur";
import { LooksrareMakerOrderWithEncodedParams } from "../types/looksrare";
import { LooksRareV2MakerOrder } from "../types/looksrare-v2";
import { OneInchFusionOrder } from "../types/oneinch";
import { RaribleOrder } from "../types/rarible";
import blurIo from "./blur-io";
import erc20Permit from "./erc20-permit";
import looksrare from "./looksrare";
import looksrareV2 from "./looksrare-v2";
import oneinch from "./oneinch";
import seaport from "./seaport";
import { Domain, VisualizationResult } from "../types/visualizer";
import { WizardError } from "../utils";
export enum PROTOCOL_ID {
OPENSEA_SEAPORT = "OPENSEA_SEAPORT",
LOOKSRARE_EXCHANGE = "LOOKSRARE_EXCHANGE",
LOOKSRARE_EXCHANGE_V2 = "LOOKSRARE_EXCHANGE_V2",
BLUR_IO_MARKETPLACE = "BLUR_IO_MARKETPLACE",
ERC20_PERMIT = "ERC20_PERMIT",
RARIBLE = "EXCHANGE",
ONEINCH_FUSION = "ONEINCH_FUSION",
}
export const getProtocolId = (domain: Domain): PROTOCOL_ID | undefined => {
if (seaport.isCorrectDomain(domain)) return PROTOCOL_ID.OPENSEA_SEAPORT;
if (blurIo.isCorrectDomain(domain)) return PROTOCOL_ID.BLUR_IO_MARKETPLACE;
if (looksrareV2.isCorrectDomain(domain)) return PROTOCOL_ID.LOOKSRARE_EXCHANGE_V2;
if (looksrare.isCorrectDomain(domain)) return PROTOCOL_ID.LOOKSRARE_EXCHANGE;
if (oneinch.isCorrectDomain(domain)) return PROTOCOL_ID.ONEINCH_FUSION;
return;
};
/**
* @param {T} message EIP-712 message
* @param {Domain} domain EIP-712 domain
* @returns {VisualizationResult} assets impact and message liveness
* @throws {Error}
*/
export default async function visualize<T extends object>(
message: T,
domain: Domain
): Promise<VisualizationResult> {
const protocolId = getProtocolId(domain);
switch (protocolId) {
case PROTOCOL_ID.OPENSEA_SEAPORT:
return seaport.visualize(message as SeaPortPayload, domain);
case PROTOCOL_ID.LOOKSRARE_EXCHANGE_V2:
return looksrareV2.visualize(message as LooksRareV2MakerOrder, domain);
case PROTOCOL_ID.LOOKSRARE_EXCHANGE:
return looksrare.visualize(message as LooksrareMakerOrderWithEncodedParams, domain);
case PROTOCOL_ID.BLUR_IO_MARKETPLACE:
return blurIo.visualize(message as BlurIoOrder, domain);
case PROTOCOL_ID.ONEINCH_FUSION:
return oneinch.visualize(message as OneInchFusionOrder, domain);
default:
if (erc20Permit.isERC20Permit(message)) {
return erc20Permit.visualize(message as PermitMessage, domain);
}
throw new WizardError("Unrecognized/Unsupported EIP712Protocol Domain");
}
}