-
Notifications
You must be signed in to change notification settings - Fork 5.1k
/
Copy pathbridge-status.ts
175 lines (150 loc) · 4.34 KB
/
bridge-status.ts
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import { TransactionMeta } from '@metamask/transaction-controller';
import type { ChainId, Quote, QuoteMetadata, QuoteResponse } from './bridge';
// All fields need to be types not interfaces, same with their children fields
// o/w you get a type error
export enum StatusTypes {
UNKNOWN = 'UNKNOWN',
FAILED = 'FAILED',
PENDING = 'PENDING',
COMPLETE = 'COMPLETE',
}
export type StatusRequest = {
bridgeId: string; // lifi, socket, squid
srcTxHash?: string; // lifi, socket, squid, might be undefined for STX
bridge: string; // lifi, socket, squid
srcChainId: ChainId; // lifi, socket, squid
destChainId: ChainId; // lifi, socket, squid
quote?: Quote; // squid
refuel?: boolean; // lifi
};
export type StatusRequestDto = Omit<
StatusRequest,
'quote' | 'srcChainId' | 'destChainId' | 'refuel'
> & {
srcChainId: string; // lifi, socket, squid
destChainId: string; // lifi, socket, squid
requestId?: string;
refuel?: string; // lifi
};
export type StatusRequestWithSrcTxHash = StatusRequest & {
srcTxHash: string;
};
export type Asset = {
chainId: ChainId;
address: string;
symbol: string;
name: string;
decimals: number;
icon?: string | null;
};
export type SrcChainStatus = {
chainId: ChainId;
txHash?: string; // might be undefined if this is a smart transaction (STX)
amount?: string;
token?: Asset;
};
export type DestChainStatus = {
chainId: ChainId;
txHash?: string;
amount?: string;
token?: Record<string, never> | Asset;
};
export enum BridgeId {
HOP = 'hop',
CELER = 'celer',
CELERCIRCLE = 'celercircle',
CONNEXT = 'connext',
POLYGON = 'polygon',
AVALANCHE = 'avalanche',
MULTICHAIN = 'multichain',
AXELAR = 'axelar',
ACROSS = 'across',
STARGATE = 'stargate',
}
export enum FeeType {
METABRIDGE = 'metabridge',
REFUEL = 'refuel',
}
export type FeeData = {
amount: string;
asset: Asset;
};
export type Protocol = {
displayName?: string;
icon?: string;
name?: string; // for legacy quotes
};
export enum ActionTypes {
BRIDGE = 'bridge',
SWAP = 'swap',
REFUEL = 'refuel',
}
export type Step = {
action: ActionTypes;
srcChainId: ChainId;
destChainId?: ChainId;
srcAsset: Asset;
destAsset: Asset;
srcAmount: string;
destAmount: string;
protocol: Protocol;
};
export type StatusResponse = {
status: StatusTypes;
srcChain: SrcChainStatus;
destChain?: DestChainStatus;
bridge?: BridgeId;
isExpectedToken?: boolean;
isUnrecognizedRouterAddress?: boolean;
refuel?: RefuelStatusResponse;
};
export type RefuelStatusResponse = object & StatusResponse;
export type RefuelData = object & Step;
export type BridgeHistoryItem = {
txMetaId: string; // Need this to handle STX that might not have a txHash immediately
quote: Quote;
status: StatusResponse;
startTime?: number; // timestamp in ms
estimatedProcessingTimeInSeconds: number;
slippagePercentage: number;
completionTime?: number;
pricingData?: {
amountSent: string; // This is from QuoteMetadata.sentAmount.amount, the actual amount sent by user in non-atomic decimal form
quotedGasInUsd?: string;
quotedReturnInUsd?: string;
amountSentInUsd?: string;
quotedRefuelSrcAmountInUsd?: string;
quotedRefuelDestAmountInUsd?: string;
};
initialDestAssetBalance?: string;
targetContractAddress?: string;
account: string;
};
export enum BridgeStatusAction {
START_POLLING_FOR_BRIDGE_TX_STATUS = 'startPollingForBridgeTxStatus',
WIPE_BRIDGE_STATUS = 'wipeBridgeStatus',
GET_STATE = 'getState',
}
// The BigNumber values are serialized to strings
export type QuoteMetadataSerialized = {
sentAmount: { amount: string; fiat: string | null };
};
export type StartPollingForBridgeTxStatusArgs = {
bridgeTxMeta: TransactionMeta;
statusRequest: StatusRequest;
quoteResponse: QuoteResponse & QuoteMetadata;
startTime?: BridgeHistoryItem['startTime'];
slippagePercentage: BridgeHistoryItem['slippagePercentage'];
initialDestAssetBalance?: BridgeHistoryItem['initialDestAssetBalance'];
targetContractAddress?: BridgeHistoryItem['targetContractAddress'];
};
export type StartPollingForBridgeTxStatusArgsSerialized = Omit<
StartPollingForBridgeTxStatusArgs,
'quoteResponse'
> & {
quoteResponse: QuoteResponse & QuoteMetadataSerialized;
};
export type SourceChainTxMetaId = string;
export type BridgeStatusControllerState = {
txHistory: Record<SourceChainTxMetaId, BridgeHistoryItem>;
};