@instadapp/avocado-base 0.0.0-dev.fc86158 → 0.0.0-dev.fcdcc0f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/abi/forwarder.json +1253 -149
- package/abi/multisigForwarder.json +697 -0
- package/app.vue +7 -0
- package/assets/images/icons/arrow-left.svg +5 -0
- package/assets/images/icons/arrow-right.svg +5 -0
- package/assets/images/icons/avocado.svg +4 -0
- package/assets/images/icons/bridge-2.svg +3 -0
- package/assets/images/icons/bridge.svg +7 -0
- package/assets/images/icons/calendar.svg +8 -0
- package/assets/images/icons/change-threshold.svg +4 -0
- package/assets/images/icons/check-circle.svg +4 -0
- package/assets/images/icons/chevron-down.svg +4 -0
- package/assets/images/icons/clipboard.svg +7 -0
- package/assets/images/icons/clock-circle.svg +5 -0
- package/assets/images/icons/copy.svg +5 -0
- package/assets/images/icons/cross-transfer.svg +7 -0
- package/assets/images/icons/dapp.svg +4 -0
- package/assets/images/icons/deploy.svg +12 -0
- package/assets/images/icons/error-circle.svg +6 -0
- package/assets/images/icons/exclamation-circle.svg +13 -0
- package/assets/images/icons/exclamation-octagon.svg +13 -0
- package/assets/images/icons/exclamation-triangle.svg +5 -0
- package/assets/images/icons/external-link.svg +6 -0
- package/assets/images/icons/eye.svg +4 -0
- package/assets/images/icons/flowers.svg +8 -0
- package/assets/images/icons/gas-emoji.svg +193 -0
- package/assets/images/icons/gas.svg +14 -0
- package/assets/images/icons/gift.svg +153 -0
- package/assets/images/icons/globe.svg +110 -0
- package/assets/images/icons/hamburger.svg +6 -0
- package/assets/images/icons/info-2.svg +12 -0
- package/assets/images/icons/instadapp-pro.svg +4 -0
- package/assets/images/icons/logout.svg +3 -0
- package/assets/images/icons/moon.svg +3 -0
- package/assets/images/icons/multi-send.svg +7 -0
- package/assets/images/icons/network.svg +13 -0
- package/assets/images/icons/options.svg +5 -0
- package/assets/images/icons/permit-sign.svg +11 -0
- package/assets/images/icons/plus-circle.svg +6 -0
- package/assets/images/icons/plus.svg +5 -0
- package/assets/images/icons/power-off-bg.svg +24 -0
- package/assets/images/icons/power-off.svg +19 -0
- package/assets/images/icons/power-on.svg +19 -0
- package/assets/images/icons/qr.svg +20 -0
- package/assets/images/icons/question-circle.svg +14 -0
- package/assets/images/icons/refresh.svg +6 -0
- package/assets/images/icons/reject-proposal.svg +6 -0
- package/assets/images/icons/search.svg +12 -0
- package/assets/images/icons/sun.svg +3 -0
- package/assets/images/icons/transfer.svg +5 -0
- package/assets/images/icons/trash-2.svg +8 -0
- package/assets/images/icons/upgrade.svg +4 -0
- package/assets/images/icons/wave.svg +214 -0
- package/assets/images/icons/x.svg +5 -0
- package/components/ActionLogo.vue +38 -0
- package/components/ActionMetadata.vue +72 -0
- package/components/AuthorityAvatar.vue +38 -0
- package/components/ChainLogo.vue +14 -556
- package/components/CopyClipboard.vue +64 -0
- package/components/metadata/Bridge.vue +59 -0
- package/components/metadata/CrossTransfer.vue +71 -0
- package/components/metadata/GasTopup.vue +39 -0
- package/components/metadata/Permit2.vue +42 -0
- package/components/metadata/Signers.vue +62 -0
- package/components/metadata/Swap.vue +74 -0
- package/components/metadata/Transfer.vue +50 -0
- package/components.d.ts +13 -0
- package/contracts/Forwarder.ts +856 -2
- package/contracts/MultisigForwarder.ts +859 -0
- package/contracts/factories/Forwarder__factory.ts +816 -16
- package/contracts/factories/MultisigForwarder__factory.ts +721 -0
- package/contracts/factories/index.ts +1 -0
- package/contracts/index.ts +2 -0
- package/nuxt.config.ts +17 -1
- package/package.json +9 -4
- package/utils/avocado.ts +2 -0
- package/utils/bignumber.ts +20 -0
- package/utils/formatter.ts +49 -6
- package/utils/helper.ts +8 -0
- package/utils/metadata.ts +335 -133
- package/utils/network.ts +157 -82
- package/utils/services.ts +21 -0
- package/utils/utils.d.ts +129 -96
package/utils/metadata.ts
CHANGED
|
@@ -1,12 +1,37 @@
|
|
|
1
1
|
import { ethers, utils } from "ethers";
|
|
2
|
-
import { Forwarder__factory } from "
|
|
2
|
+
import { Forwarder__factory, MultisigForwarder__factory } from "../contracts";
|
|
3
|
+
|
|
4
|
+
export const MetadataEnums = {
|
|
5
|
+
"transfer": "transfer",
|
|
6
|
+
"bridge": "bridge",
|
|
7
|
+
"swap": "swap",
|
|
8
|
+
"gas-topup": "gas-topup",
|
|
9
|
+
"upgrade": "upgrade",
|
|
10
|
+
"dapp": "dapp",
|
|
11
|
+
"deploy": "deploy",
|
|
12
|
+
"permit2": "permit2",
|
|
13
|
+
"cross-transfer": "cross-transfer",
|
|
14
|
+
"auth": "auth",
|
|
15
|
+
"rejection": "rejection",
|
|
16
|
+
"instadapp-pro": "instadapp-pro",
|
|
17
|
+
"add-signers": "add-signers",
|
|
18
|
+
"remove-signers": "remove-signers",
|
|
19
|
+
"change-threshold": "change-threshold",
|
|
20
|
+
} as const;
|
|
3
21
|
|
|
4
22
|
const multiMetadataTypes = ["bytes[]"];
|
|
5
23
|
|
|
6
24
|
const metadataTypes = ["bytes32 type", "uint8 version", "bytes data"];
|
|
7
25
|
|
|
8
|
-
const actionMetadataTypes = {
|
|
26
|
+
const actionMetadataTypes: Record<MetadataTypes, string[]> = {
|
|
9
27
|
transfer: ["address token", "uint256 amount", "address receiver"],
|
|
28
|
+
"cross-transfer": [
|
|
29
|
+
"address fromToken",
|
|
30
|
+
"address toToken",
|
|
31
|
+
"uint256 toChainId",
|
|
32
|
+
"uint256 amount",
|
|
33
|
+
"address receiver",
|
|
34
|
+
],
|
|
10
35
|
bridge: [
|
|
11
36
|
"uint256 amount",
|
|
12
37
|
"address receiver",
|
|
@@ -27,6 +52,7 @@ const actionMetadataTypes = {
|
|
|
27
52
|
"gas-topup": ["uint256 amount", "address token", "address onBehalf"],
|
|
28
53
|
upgrade: ["bytes32 version", "address walletImpl"],
|
|
29
54
|
dapp: ["string name", "string url"],
|
|
55
|
+
auth: ["address address", "uint256 chainId", "bool remove"],
|
|
30
56
|
deploy: [],
|
|
31
57
|
permit2: [
|
|
32
58
|
"address token",
|
|
@@ -34,6 +60,11 @@ const actionMetadataTypes = {
|
|
|
34
60
|
"uint160 amount",
|
|
35
61
|
"uint48 expiration",
|
|
36
62
|
],
|
|
63
|
+
"instadapp-pro": ["string castDetails"],
|
|
64
|
+
'add-signers': ['address[] signers'],
|
|
65
|
+
'remove-signers': ['address[] signers'],
|
|
66
|
+
'change-threshold': ['uint8 count'],
|
|
67
|
+
'rejection': ['bytes32 id'],
|
|
37
68
|
};
|
|
38
69
|
|
|
39
70
|
const encodeMetadata = (props: MetadataProps) => {
|
|
@@ -54,7 +85,7 @@ export const encodeDappMetadata = (
|
|
|
54
85
|
);
|
|
55
86
|
|
|
56
87
|
const data = encodeMetadata({
|
|
57
|
-
type:
|
|
88
|
+
type: MetadataEnums.dapp,
|
|
58
89
|
encodedData,
|
|
59
90
|
});
|
|
60
91
|
|
|
@@ -71,7 +102,61 @@ export const encodeTransferMetadata = (
|
|
|
71
102
|
);
|
|
72
103
|
|
|
73
104
|
const data = encodeMetadata({
|
|
74
|
-
type:
|
|
105
|
+
type: MetadataEnums.transfer,
|
|
106
|
+
encodedData,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
return single ? encodeMultipleActions(data) : data;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const encodeRejectionMetadata = (id: string, single = true) => {
|
|
113
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
114
|
+
actionMetadataTypes.rejection,
|
|
115
|
+
[id]
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const data = encodeMetadata({
|
|
119
|
+
type: MetadataEnums.rejection,
|
|
120
|
+
encodedData,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
return single ? encodeMultipleActions(data) : data;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export const encodeCrossTransferMetadata = (
|
|
127
|
+
params: CrossSendMetadataProps,
|
|
128
|
+
single = true
|
|
129
|
+
) => {
|
|
130
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
131
|
+
actionMetadataTypes["cross-transfer"],
|
|
132
|
+
[
|
|
133
|
+
params.fromToken,
|
|
134
|
+
params.toToken,
|
|
135
|
+
params.toChainId,
|
|
136
|
+
params.amount,
|
|
137
|
+
params.receiver,
|
|
138
|
+
]
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const data = encodeMetadata({
|
|
142
|
+
type: MetadataEnums["cross-transfer"],
|
|
143
|
+
encodedData,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
return single ? encodeMultipleActions(data) : data;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export const encodeAuthMetadata = (
|
|
150
|
+
params: AuthMetadataProps,
|
|
151
|
+
single = true
|
|
152
|
+
) => {
|
|
153
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
154
|
+
actionMetadataTypes["auth"],
|
|
155
|
+
[params.address, params.chainId, params.remove]
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
const data = encodeMetadata({
|
|
159
|
+
type: MetadataEnums.auth,
|
|
75
160
|
encodedData,
|
|
76
161
|
});
|
|
77
162
|
|
|
@@ -80,7 +165,7 @@ export const encodeTransferMetadata = (
|
|
|
80
165
|
|
|
81
166
|
export const encodeDeployMetadata = (single = true) => {
|
|
82
167
|
const data = encodeMetadata({
|
|
83
|
-
type:
|
|
168
|
+
type: MetadataEnums.deploy,
|
|
84
169
|
encodedData: "0x",
|
|
85
170
|
});
|
|
86
171
|
|
|
@@ -97,7 +182,7 @@ export const encodeWCSignMetadata = (
|
|
|
97
182
|
);
|
|
98
183
|
|
|
99
184
|
const data = encodeMetadata({
|
|
100
|
-
type:
|
|
185
|
+
type: MetadataEnums.permit2,
|
|
101
186
|
encodedData,
|
|
102
187
|
});
|
|
103
188
|
|
|
@@ -114,7 +199,7 @@ export const encodeUpgradeMetadata = (
|
|
|
114
199
|
);
|
|
115
200
|
|
|
116
201
|
const data = encodeMetadata({
|
|
117
|
-
type:
|
|
202
|
+
type: MetadataEnums.upgrade,
|
|
118
203
|
encodedData,
|
|
119
204
|
});
|
|
120
205
|
|
|
@@ -138,7 +223,7 @@ export const encodeSwapMetadata = (
|
|
|
138
223
|
);
|
|
139
224
|
|
|
140
225
|
const data = encodeMetadata({
|
|
141
|
-
type:
|
|
226
|
+
type: MetadataEnums.swap,
|
|
142
227
|
encodedData,
|
|
143
228
|
});
|
|
144
229
|
|
|
@@ -154,10 +239,8 @@ export const encodeTopupMetadata = (
|
|
|
154
239
|
[params.amount, params.token, params.onBehalf]
|
|
155
240
|
);
|
|
156
241
|
|
|
157
|
-
console.log(params);
|
|
158
|
-
|
|
159
242
|
const data = encodeMetadata({
|
|
160
|
-
type: "gas-topup",
|
|
243
|
+
type: MetadataEnums["gas-topup"],
|
|
161
244
|
encodedData,
|
|
162
245
|
});
|
|
163
246
|
|
|
@@ -182,7 +265,58 @@ export const encodeBridgeMetadata = (
|
|
|
182
265
|
);
|
|
183
266
|
|
|
184
267
|
const data = encodeMetadata({
|
|
185
|
-
type:
|
|
268
|
+
type: MetadataEnums.bridge,
|
|
269
|
+
encodedData,
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
return single ? encodeMultipleActions(data) : data;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
export const encodeChangeThresholdMetadata = (
|
|
276
|
+
threshold: string | number,
|
|
277
|
+
single = true
|
|
278
|
+
) => {
|
|
279
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
280
|
+
actionMetadataTypes["change-threshold"],
|
|
281
|
+
[toBN(threshold).toNumber()]
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
const data = encodeMetadata({
|
|
285
|
+
type: MetadataEnums["change-threshold"],
|
|
286
|
+
encodedData,
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
return single ? encodeMultipleActions(data) : data;
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
export const encodeRemoveSignersMetadata = (
|
|
293
|
+
addresses: string[],
|
|
294
|
+
single = true
|
|
295
|
+
) => {
|
|
296
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
297
|
+
actionMetadataTypes["remove-signers"],
|
|
298
|
+
[addresses]
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
const data = encodeMetadata({
|
|
302
|
+
type: MetadataEnums["remove-signers"],
|
|
303
|
+
encodedData,
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
return single ? encodeMultipleActions(data) : data;
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
export const encodeAddSignersMetadata = (
|
|
310
|
+
addresses: string[],
|
|
311
|
+
single = true
|
|
312
|
+
) => {
|
|
313
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
314
|
+
actionMetadataTypes["add-signers"],
|
|
315
|
+
[addresses]
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
const data = encodeMetadata({
|
|
319
|
+
type: MetadataEnums["add-signers"],
|
|
186
320
|
encodedData,
|
|
187
321
|
});
|
|
188
322
|
|
|
@@ -193,134 +327,202 @@ export const encodeMultipleActions = (...actionData: string[]) => {
|
|
|
193
327
|
return ethers.utils.defaultAbiCoder.encode(multiMetadataTypes, [actionData]);
|
|
194
328
|
};
|
|
195
329
|
|
|
196
|
-
export const
|
|
330
|
+
export const decodeData = (data: string) => {
|
|
197
331
|
try {
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
332
|
+
const metadata = getMetadataFromData(data) || "0x";
|
|
333
|
+
|
|
334
|
+
return parseMetadata(metadata);
|
|
335
|
+
} catch (e) {
|
|
336
|
+
// console.log(e);
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
export const decodeMetadata = (metadata: string) => {
|
|
342
|
+
try {
|
|
343
|
+
return parseMetadata(metadata);
|
|
344
|
+
} catch (e) {
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
const iface = Forwarder__factory.createInterface();
|
|
350
|
+
const ifaceMultisig = MultisigForwarder__factory.createInterface();
|
|
351
|
+
|
|
352
|
+
const getMetadataFromData = (data: string) => {
|
|
353
|
+
let metadata = "0x";
|
|
354
|
+
|
|
355
|
+
if (data.startsWith("0x18e7f485")) {
|
|
356
|
+
const executeData = iface.decodeFunctionData("execute", data);
|
|
357
|
+
if (executeData.metadata_ === "0x" || !executeData.metadata_) {
|
|
358
|
+
return null;
|
|
359
|
+
} else {
|
|
360
|
+
metadata = executeData.metadata_;
|
|
361
|
+
}
|
|
362
|
+
} else if (data.startsWith("0x14f80a8d")) {
|
|
363
|
+
const executeDataV2 = iface.decodeFunctionData("executeV2", data);
|
|
364
|
+
if (
|
|
365
|
+
executeDataV2.params_.metadata === "0x" ||
|
|
366
|
+
!executeDataV2.params_.metadata
|
|
367
|
+
) {
|
|
368
|
+
return null;
|
|
369
|
+
} else {
|
|
370
|
+
metadata = executeDataV2.params_.metadata;
|
|
371
|
+
}
|
|
372
|
+
} else {
|
|
373
|
+
const executeDataMultisig = ifaceMultisig.decodeFunctionData(
|
|
374
|
+
"executeV1",
|
|
375
|
+
data
|
|
376
|
+
);
|
|
377
|
+
if (
|
|
378
|
+
executeDataMultisig.params_.metadata === "0x" ||
|
|
379
|
+
!executeDataMultisig.params_.metadata
|
|
380
|
+
) {
|
|
381
|
+
return null;
|
|
211
382
|
} else {
|
|
212
|
-
|
|
213
|
-
if (
|
|
214
|
-
executeDataV2.params_.metadata === "0x" ||
|
|
215
|
-
!executeDataV2.params_.metadata
|
|
216
|
-
) {
|
|
217
|
-
return null;
|
|
218
|
-
} else {
|
|
219
|
-
metadata = executeDataV2.params_.metadata;
|
|
220
|
-
}
|
|
383
|
+
metadata = executeDataMultisig.params_.metadata;
|
|
221
384
|
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
return metadata;
|
|
388
|
+
};
|
|
222
389
|
|
|
223
|
-
const metadataArr = [];
|
|
224
|
-
|
|
225
|
-
const [decodedMultiMetadata = []] =
|
|
226
|
-
(ethers.utils.defaultAbiCoder.decode(
|
|
227
|
-
multiMetadataTypes,
|
|
228
|
-
metadata
|
|
229
|
-
) as string[]) || [];
|
|
230
|
-
|
|
231
|
-
for (let metadata of decodedMultiMetadata) {
|
|
232
|
-
const decodedMetadata = ethers.utils.defaultAbiCoder.decode(
|
|
233
|
-
metadataTypes,
|
|
234
|
-
metadata
|
|
235
|
-
);
|
|
236
|
-
|
|
237
|
-
const type = ethers.utils.parseBytes32String(
|
|
238
|
-
decodedMetadata.type
|
|
239
|
-
) as keyof typeof actionMetadataTypes;
|
|
240
|
-
|
|
241
|
-
const decodedData = ethers.utils.defaultAbiCoder.decode(
|
|
242
|
-
actionMetadataTypes[type],
|
|
243
|
-
decodedMetadata.data
|
|
244
|
-
);
|
|
245
|
-
|
|
246
|
-
switch (type) {
|
|
247
|
-
case "transfer":
|
|
248
|
-
payload = {
|
|
249
|
-
type,
|
|
250
|
-
token: decodedData.token,
|
|
251
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
252
|
-
receiver: decodedData.receiver,
|
|
253
|
-
};
|
|
254
|
-
break;
|
|
255
|
-
case "bridge":
|
|
256
|
-
payload = {
|
|
257
|
-
type,
|
|
258
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
259
|
-
receiver: decodedData.receiver,
|
|
260
|
-
toToken: decodedData.toToken,
|
|
261
|
-
fromToken: decodedData.fromToken,
|
|
262
|
-
toChainId: decodedData.toChainId
|
|
263
|
-
? decodedData.toChainId.toString()
|
|
264
|
-
: null,
|
|
265
|
-
bridgeFee: toBN(decodedData.bridgeFee).toFixed(),
|
|
266
|
-
};
|
|
267
|
-
break;
|
|
268
|
-
case "swap":
|
|
269
|
-
payload = {
|
|
270
|
-
type,
|
|
271
|
-
buyAmount: toBN(decodedData.buyAmount).toFixed(),
|
|
272
|
-
sellAmount: toBN(decodedData.sellAmount).toFixed(),
|
|
273
|
-
buyToken: decodedData.buyToken,
|
|
274
|
-
sellToken: decodedData.sellToken,
|
|
275
|
-
receiver: decodedData.receiver,
|
|
276
|
-
protocol: utils.parseBytes32String(decodedData?.protocol || ""),
|
|
277
|
-
};
|
|
278
|
-
break;
|
|
279
|
-
case "upgrade":
|
|
280
|
-
payload = {
|
|
281
|
-
type,
|
|
282
|
-
version: utils.parseBytes32String(decodedData?.version || ""),
|
|
283
|
-
walletImpl: decodedData?.walletImpl,
|
|
284
|
-
};
|
|
285
|
-
break;
|
|
286
|
-
case "gas-topup":
|
|
287
|
-
payload = {
|
|
288
|
-
type,
|
|
289
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
290
|
-
token: decodedData.token,
|
|
291
|
-
onBehalf: decodedData.onBehalf,
|
|
292
|
-
};
|
|
293
|
-
break;
|
|
294
|
-
case "dapp":
|
|
295
|
-
payload = {
|
|
296
|
-
type,
|
|
297
|
-
name: decodedData?.name,
|
|
298
|
-
url: decodedData?.url,
|
|
299
|
-
};
|
|
300
|
-
break;
|
|
301
|
-
case "deploy":
|
|
302
|
-
payload = {
|
|
303
|
-
type,
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
case "permit2":
|
|
307
|
-
payload = {
|
|
308
|
-
type,
|
|
309
|
-
token: decodedData.token,
|
|
310
|
-
spender: decodedData.spender,
|
|
311
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
312
|
-
expiration: decodedData.expiration,
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
break;
|
|
316
|
-
}
|
|
317
390
|
|
|
391
|
+
const typesPayload: IPayload = {
|
|
392
|
+
transfer: (data, type) => ({
|
|
393
|
+
type,
|
|
394
|
+
token: data.token,
|
|
395
|
+
amount: toBN(data.amount).toFixed(),
|
|
396
|
+
receiver: data.receiver,
|
|
397
|
+
}),
|
|
398
|
+
bridge: (data, type) => ({
|
|
399
|
+
type,
|
|
400
|
+
amount: toBN(data.amount).toFixed(),
|
|
401
|
+
receiver: data.receiver,
|
|
402
|
+
toToken: data.toToken,
|
|
403
|
+
fromToken: data.fromToken,
|
|
404
|
+
toChainId: data.toChainId ? data.toChainId.toString() : null,
|
|
405
|
+
bridgeFee: toBN(data.bridgeFee).toFixed(),
|
|
406
|
+
}),
|
|
407
|
+
swap: (data, type) => ({
|
|
408
|
+
type,
|
|
409
|
+
buyAmount: toBN(data.buyAmount).toFixed(),
|
|
410
|
+
sellAmount: toBN(data.sellAmount).toFixed(),
|
|
411
|
+
buyToken: data.buyToken,
|
|
412
|
+
sellToken: data.sellToken,
|
|
413
|
+
receiver: data.receiver,
|
|
414
|
+
protocol: utils.parseBytes32String(data.protocol || ""),
|
|
415
|
+
}),
|
|
416
|
+
upgrade: (data, type) => ({
|
|
417
|
+
type,
|
|
418
|
+
version: utils.parseBytes32String(data.version || ""),
|
|
419
|
+
walletImpl: data.walletImpl,
|
|
420
|
+
}),
|
|
421
|
+
"gas-topup": (data, type) => ({
|
|
422
|
+
type,
|
|
423
|
+
amount: toBN(data.amount).toFixed(),
|
|
424
|
+
token: data.token,
|
|
425
|
+
onBehalf: data.onBehalf,
|
|
426
|
+
}),
|
|
427
|
+
"dapp": (data, type) => ({
|
|
428
|
+
type,
|
|
429
|
+
name: data.name,
|
|
430
|
+
url: data.url,
|
|
431
|
+
}),
|
|
432
|
+
"deploy": (data, type) => ({
|
|
433
|
+
type,
|
|
434
|
+
}),
|
|
435
|
+
"permit2": (data, type) => ({
|
|
436
|
+
type,
|
|
437
|
+
token: data.token,
|
|
438
|
+
spender: data.spender,
|
|
439
|
+
amount: toBN(data.amount).toFixed(),
|
|
440
|
+
expiration: data.expiration,
|
|
441
|
+
}),
|
|
442
|
+
"cross-transfer": (data, type) => ({
|
|
443
|
+
type,
|
|
444
|
+
fromToken: data.fromToken,
|
|
445
|
+
toToken: data.toToken,
|
|
446
|
+
toChainId: data.toChainId ? data.toChainId.toString() : null,
|
|
447
|
+
amount: toBN(data.amount).toFixed(),
|
|
448
|
+
receiver: data.receiver,
|
|
449
|
+
}),
|
|
450
|
+
"auth": (data) => ({
|
|
451
|
+
type: data.remove ? "remove-authority" : "add-authority",
|
|
452
|
+
address: data.address,
|
|
453
|
+
chainId: data.chainId ? data.chainId.toString() : null,
|
|
454
|
+
remove: data.remove,
|
|
455
|
+
}),
|
|
456
|
+
"instadapp-pro": (data, type) => ({
|
|
457
|
+
type,
|
|
458
|
+
castDetails: data.castDetails,
|
|
459
|
+
}),
|
|
460
|
+
"rejection": (data, type) => ({
|
|
461
|
+
type,
|
|
462
|
+
id: data.id,
|
|
463
|
+
}),
|
|
464
|
+
"add-signers": (data, type) => ({
|
|
465
|
+
type,
|
|
466
|
+
addresses: data.signers,
|
|
467
|
+
}),
|
|
468
|
+
"remove-signers": (data, type) => ({
|
|
469
|
+
type,
|
|
470
|
+
addresses: data.signers,
|
|
471
|
+
}),
|
|
472
|
+
"change-threshold": (data, type) => ({
|
|
473
|
+
type,
|
|
474
|
+
count: data.count,
|
|
475
|
+
}),
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
const parseMetadata = (metadata: string) => {
|
|
479
|
+
const metadataArr = [];
|
|
480
|
+
|
|
481
|
+
const [decodedMultiMetadata = []] =
|
|
482
|
+
(ethers.utils.defaultAbiCoder.decode(
|
|
483
|
+
multiMetadataTypes,
|
|
484
|
+
metadata
|
|
485
|
+
) as string[]) || [];
|
|
486
|
+
|
|
487
|
+
for (let metadata of decodedMultiMetadata) {
|
|
488
|
+
const decodedMetadata = ethers.utils.defaultAbiCoder.decode(
|
|
489
|
+
metadataTypes,
|
|
490
|
+
metadata
|
|
491
|
+
);
|
|
492
|
+
|
|
493
|
+
const type = ethers.utils.parseBytes32String(
|
|
494
|
+
decodedMetadata.type
|
|
495
|
+
) as keyof typeof actionMetadataTypes;
|
|
496
|
+
|
|
497
|
+
const decodedData = ethers.utils.defaultAbiCoder.decode(
|
|
498
|
+
actionMetadataTypes[type],
|
|
499
|
+
decodedMetadata.data
|
|
500
|
+
);
|
|
501
|
+
|
|
502
|
+
const payloadFunc = typesPayload[type]
|
|
503
|
+
|
|
504
|
+
if (payloadFunc) {
|
|
505
|
+
const payload = payloadFunc(decodedData, type)
|
|
318
506
|
metadataArr.push(payload);
|
|
319
507
|
}
|
|
320
508
|
|
|
321
|
-
return metadataArr;
|
|
322
|
-
} catch (e) {
|
|
323
|
-
console.log(e);
|
|
324
|
-
return null;
|
|
325
509
|
}
|
|
510
|
+
|
|
511
|
+
return metadataArr;
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* Replaces hyphens with spaces and capitalizes the first letter of each word in a sentence.
|
|
518
|
+
* @param {string} txType - The input sentence to modify
|
|
519
|
+
*
|
|
520
|
+
* @returns {string} - The modified sentence with hyphens replaced with spaces and the first letter of each word capitalized.
|
|
521
|
+
*/
|
|
522
|
+
export const formatTxType = (txType: string) => {
|
|
523
|
+
const finalSentence = txType
|
|
524
|
+
.replace("-", " ")
|
|
525
|
+
.replace(/(^\w{1})|(\s+\w{1})/g, (letter) => letter.toUpperCase());
|
|
526
|
+
|
|
527
|
+
return finalSentence;
|
|
326
528
|
};
|