@instadapp/avocado-base 0.0.0-dev.0f85f1a → 0.0.0-dev.1264496
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 +8 -8
- 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 +4 -4
- package/contracts/MultisigForwarder.ts +859 -0
- package/contracts/factories/Forwarder__factory.ts +8 -8
- 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 +1 -1
- package/utils/helper.ts +8 -0
- package/utils/metadata.ts +289 -177
- package/utils/network.ts +139 -80
- package/utils/services.ts +21 -0
- package/utils/utils.d.ts +129 -114
package/contracts/index.ts
CHANGED
|
@@ -6,9 +6,11 @@ export type { BalanceResolver } from "./BalanceResolver";
|
|
|
6
6
|
export type { Erc20 } from "./Erc20";
|
|
7
7
|
export type { Forwarder } from "./Forwarder";
|
|
8
8
|
export type { GaslessWallet } from "./GaslessWallet";
|
|
9
|
+
export type { MultisigForwarder } from "./MultisigForwarder";
|
|
9
10
|
export * as factories from "./factories";
|
|
10
11
|
export { AvoFactoryProxy__factory } from "./factories/AvoFactoryProxy__factory";
|
|
11
12
|
export { BalanceResolver__factory } from "./factories/BalanceResolver__factory";
|
|
12
13
|
export { Erc20__factory } from "./factories/Erc20__factory";
|
|
13
14
|
export { Forwarder__factory } from "./factories/Forwarder__factory";
|
|
14
15
|
export { GaslessWallet__factory } from "./factories/GaslessWallet__factory";
|
|
16
|
+
export { MultisigForwarder__factory } from "./factories/MultisigForwarder__factory";
|
package/nuxt.config.ts
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
// https://nuxt.com/docs/api/configuration/nuxt-config
|
|
2
|
+
import ViteComponents from "unplugin-vue-components/vite";
|
|
3
|
+
|
|
2
4
|
export default defineNuxtConfig({
|
|
3
|
-
modules: ["@nuxtjs/tailwindcss"],
|
|
5
|
+
modules: ["@nuxtjs/tailwindcss", "nuxt-svgo", "@vueuse/nuxt"],
|
|
6
|
+
svgo: {
|
|
7
|
+
defaultImport: "component",
|
|
8
|
+
autoImportPath: "./assets/images/icons",
|
|
9
|
+
svgoConfig: {
|
|
10
|
+
plugins: ["prefixIds"],
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
vite: {
|
|
14
|
+
plugins: [
|
|
15
|
+
ViteComponents({
|
|
16
|
+
dts: true,
|
|
17
|
+
}),
|
|
18
|
+
],
|
|
19
|
+
},
|
|
4
20
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instadapp/avocado-base",
|
|
3
|
-
"version": "0.0.0-dev.
|
|
3
|
+
"version": "0.0.0-dev.1264496",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./nuxt.config.ts",
|
|
6
6
|
"types": "global.d.ts",
|
|
@@ -16,12 +16,17 @@
|
|
|
16
16
|
"@instadapp/avocado-dev": "npm:@instadapp/avocado@dev",
|
|
17
17
|
"@nuxtjs/tailwindcss": "^6.6.5",
|
|
18
18
|
"@typechain/ethers-v5": "^10.2.0",
|
|
19
|
-
"nuxt": "^3.
|
|
19
|
+
"nuxt": "^3.6.1",
|
|
20
|
+
"nuxt-svgo": "^3.1.0",
|
|
20
21
|
"rimraf": "^3.0.2",
|
|
21
|
-
"typechain": "^8.1.1"
|
|
22
|
+
"typechain": "^8.1.1",
|
|
23
|
+
"unplugin-vue-components": "^0.25.1",
|
|
24
|
+
"vue-tippy": "^6.0.0"
|
|
22
25
|
},
|
|
23
26
|
"dependencies": {
|
|
27
|
+
"@vueuse/nuxt": "^10.2.0",
|
|
24
28
|
"bignumber.js": "^9.1.1",
|
|
25
|
-
"ethers": "^5.7.2"
|
|
29
|
+
"ethers": "^5.7.2",
|
|
30
|
+
"xxhashjs": "^0.2.2"
|
|
26
31
|
}
|
|
27
32
|
}
|
package/utils/avocado.ts
CHANGED
package/utils/bignumber.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { BigNumber } from "bignumber.js";
|
|
2
2
|
import { BigNumber as BN } from "ethers";
|
|
3
3
|
|
|
4
|
+
type CombinedBigNumber = BigNumber | string | number;
|
|
5
|
+
|
|
4
6
|
export const toBN = (value: BigNumber.Value | BN) =>
|
|
5
7
|
new BigNumber(BN.isBigNumber(value) ? value.toString() : value);
|
|
6
8
|
export const isZero = (value: BigNumber.Value | BN) => toBN(value).isZero();
|
|
@@ -29,3 +31,21 @@ export const ensureValue = (value: any) => {
|
|
|
29
31
|
export const max = (...args: BigNumber.Value[]) => {
|
|
30
32
|
return BigNumber.max(...args);
|
|
31
33
|
};
|
|
34
|
+
|
|
35
|
+
export function pow(value: CombinedBigNumber, exponent: string | number) {
|
|
36
|
+
return toBN(value).pow(toBN(exponent));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function toWei(val: CombinedBigNumber, decimals: number): string {
|
|
40
|
+
const num = toBN(val);
|
|
41
|
+
const multiplier = pow(10, decimals);
|
|
42
|
+
return times(num, multiplier).toFixed(0);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function fromWei(val: CombinedBigNumber, decimal = 18) {
|
|
46
|
+
return toBN(val).div(new BigNumber(10).pow(decimal));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function abs(value: CombinedBigNumber) {
|
|
50
|
+
return toBN(value).abs();
|
|
51
|
+
}
|
package/utils/formatter.ts
CHANGED
package/utils/helper.ts
CHANGED
|
@@ -52,3 +52,11 @@ export function onImageError(this: HTMLImageElement) {
|
|
|
52
52
|
parentElement.classList.add("bg-gray-300");
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
+
|
|
56
|
+
export function formatMultipleAddresses(addresses: string[], shorten = true) {
|
|
57
|
+
const formatter = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' })
|
|
58
|
+
const formattedString = formatter.format(addresses.map(i => shorten ? shortenHash(i) || '' : i))
|
|
59
|
+
|
|
60
|
+
return formattedString
|
|
61
|
+
}
|
|
62
|
+
|
package/utils/metadata.ts
CHANGED
|
@@ -1,11 +1,30 @@
|
|
|
1
1
|
import { ethers, utils } from "ethers";
|
|
2
|
-
import { Forwarder__factory } from "../contracts";
|
|
2
|
+
import { Forwarder__factory, MultisigForwarder__factory } from "../contracts";
|
|
3
|
+
import { toBN } from "./bignumber";
|
|
4
|
+
|
|
5
|
+
export const MetadataEnums = {
|
|
6
|
+
"transfer": "transfer",
|
|
7
|
+
"bridge": "bridge",
|
|
8
|
+
"swap": "swap",
|
|
9
|
+
"gas-topup": "gas-topup",
|
|
10
|
+
"upgrade": "upgrade",
|
|
11
|
+
"dapp": "dapp",
|
|
12
|
+
"deploy": "deploy",
|
|
13
|
+
"permit2": "permit2",
|
|
14
|
+
"cross-transfer": "cross-transfer",
|
|
15
|
+
"auth": "auth",
|
|
16
|
+
"rejection": "rejection",
|
|
17
|
+
"instadapp-pro": "instadapp-pro",
|
|
18
|
+
"add-signers": "add-signers",
|
|
19
|
+
"remove-signers": "remove-signers",
|
|
20
|
+
"change-threshold": "change-threshold",
|
|
21
|
+
} as const;
|
|
3
22
|
|
|
4
23
|
const multiMetadataTypes = ["bytes[]"];
|
|
5
24
|
|
|
6
25
|
const metadataTypes = ["bytes32 type", "uint8 version", "bytes data"];
|
|
7
26
|
|
|
8
|
-
const actionMetadataTypes = {
|
|
27
|
+
const actionMetadataTypes: Record<MetadataTypes, string[]> = {
|
|
9
28
|
transfer: ["address token", "uint256 amount", "address receiver"],
|
|
10
29
|
"cross-transfer": [
|
|
11
30
|
"address fromToken",
|
|
@@ -43,6 +62,10 @@ const actionMetadataTypes = {
|
|
|
43
62
|
"uint48 expiration",
|
|
44
63
|
],
|
|
45
64
|
"instadapp-pro": ["string castDetails"],
|
|
65
|
+
'add-signers': ['address[] signers'],
|
|
66
|
+
'remove-signers': ['address[] signers'],
|
|
67
|
+
'change-threshold': ['uint8 count'],
|
|
68
|
+
'rejection': ['bytes32 id'],
|
|
46
69
|
};
|
|
47
70
|
|
|
48
71
|
const encodeMetadata = (props: MetadataProps) => {
|
|
@@ -63,7 +86,7 @@ export const encodeDappMetadata = (
|
|
|
63
86
|
);
|
|
64
87
|
|
|
65
88
|
const data = encodeMetadata({
|
|
66
|
-
type:
|
|
89
|
+
type: MetadataEnums.dapp,
|
|
67
90
|
encodedData,
|
|
68
91
|
});
|
|
69
92
|
|
|
@@ -80,7 +103,21 @@ export const encodeTransferMetadata = (
|
|
|
80
103
|
);
|
|
81
104
|
|
|
82
105
|
const data = encodeMetadata({
|
|
83
|
-
type:
|
|
106
|
+
type: MetadataEnums.transfer,
|
|
107
|
+
encodedData,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
return single ? encodeMultipleActions(data) : data;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const encodeRejectionMetadata = (id: string, single = true) => {
|
|
114
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
115
|
+
actionMetadataTypes.rejection,
|
|
116
|
+
[id]
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
const data = encodeMetadata({
|
|
120
|
+
type: MetadataEnums.rejection,
|
|
84
121
|
encodedData,
|
|
85
122
|
});
|
|
86
123
|
|
|
@@ -103,7 +140,7 @@ export const encodeCrossTransferMetadata = (
|
|
|
103
140
|
);
|
|
104
141
|
|
|
105
142
|
const data = encodeMetadata({
|
|
106
|
-
type: "cross-transfer",
|
|
143
|
+
type: MetadataEnums["cross-transfer"],
|
|
107
144
|
encodedData,
|
|
108
145
|
});
|
|
109
146
|
|
|
@@ -120,7 +157,7 @@ export const encodeAuthMetadata = (
|
|
|
120
157
|
);
|
|
121
158
|
|
|
122
159
|
const data = encodeMetadata({
|
|
123
|
-
type:
|
|
160
|
+
type: MetadataEnums.auth,
|
|
124
161
|
encodedData,
|
|
125
162
|
});
|
|
126
163
|
|
|
@@ -129,7 +166,7 @@ export const encodeAuthMetadata = (
|
|
|
129
166
|
|
|
130
167
|
export const encodeDeployMetadata = (single = true) => {
|
|
131
168
|
const data = encodeMetadata({
|
|
132
|
-
type:
|
|
169
|
+
type: MetadataEnums.deploy,
|
|
133
170
|
encodedData: "0x",
|
|
134
171
|
});
|
|
135
172
|
|
|
@@ -146,7 +183,7 @@ export const encodeWCSignMetadata = (
|
|
|
146
183
|
);
|
|
147
184
|
|
|
148
185
|
const data = encodeMetadata({
|
|
149
|
-
type:
|
|
186
|
+
type: MetadataEnums.permit2,
|
|
150
187
|
encodedData,
|
|
151
188
|
});
|
|
152
189
|
|
|
@@ -163,7 +200,7 @@ export const encodeUpgradeMetadata = (
|
|
|
163
200
|
);
|
|
164
201
|
|
|
165
202
|
const data = encodeMetadata({
|
|
166
|
-
type:
|
|
203
|
+
type: MetadataEnums.upgrade,
|
|
167
204
|
encodedData,
|
|
168
205
|
});
|
|
169
206
|
|
|
@@ -187,7 +224,7 @@ export const encodeSwapMetadata = (
|
|
|
187
224
|
);
|
|
188
225
|
|
|
189
226
|
const data = encodeMetadata({
|
|
190
|
-
type:
|
|
227
|
+
type: MetadataEnums.swap,
|
|
191
228
|
encodedData,
|
|
192
229
|
});
|
|
193
230
|
|
|
@@ -203,10 +240,8 @@ export const encodeTopupMetadata = (
|
|
|
203
240
|
[params.amount, params.token, params.onBehalf]
|
|
204
241
|
);
|
|
205
242
|
|
|
206
|
-
console.log(params);
|
|
207
|
-
|
|
208
243
|
const data = encodeMetadata({
|
|
209
|
-
type: "gas-topup",
|
|
244
|
+
type: MetadataEnums["gas-topup"],
|
|
210
245
|
encodedData,
|
|
211
246
|
});
|
|
212
247
|
|
|
@@ -231,7 +266,58 @@ export const encodeBridgeMetadata = (
|
|
|
231
266
|
);
|
|
232
267
|
|
|
233
268
|
const data = encodeMetadata({
|
|
234
|
-
type:
|
|
269
|
+
type: MetadataEnums.bridge,
|
|
270
|
+
encodedData,
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
return single ? encodeMultipleActions(data) : data;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
export const encodeChangeThresholdMetadata = (
|
|
277
|
+
threshold: string | number,
|
|
278
|
+
single = true
|
|
279
|
+
) => {
|
|
280
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
281
|
+
actionMetadataTypes["change-threshold"],
|
|
282
|
+
[toBN(threshold).toNumber()]
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
const data = encodeMetadata({
|
|
286
|
+
type: MetadataEnums["change-threshold"],
|
|
287
|
+
encodedData,
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
return single ? encodeMultipleActions(data) : data;
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
export const encodeRemoveSignersMetadata = (
|
|
294
|
+
addresses: string[],
|
|
295
|
+
single = true
|
|
296
|
+
) => {
|
|
297
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
298
|
+
actionMetadataTypes["remove-signers"],
|
|
299
|
+
[addresses]
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
const data = encodeMetadata({
|
|
303
|
+
type: MetadataEnums["remove-signers"],
|
|
304
|
+
encodedData,
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
return single ? encodeMultipleActions(data) : data;
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
export const encodeAddSignersMetadata = (
|
|
311
|
+
addresses: string[],
|
|
312
|
+
single = true
|
|
313
|
+
) => {
|
|
314
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
315
|
+
actionMetadataTypes["add-signers"],
|
|
316
|
+
[addresses]
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
const data = encodeMetadata({
|
|
320
|
+
type: MetadataEnums["add-signers"],
|
|
235
321
|
encodedData,
|
|
236
322
|
});
|
|
237
323
|
|
|
@@ -242,176 +328,202 @@ export const encodeMultipleActions = (...actionData: string[]) => {
|
|
|
242
328
|
return ethers.utils.defaultAbiCoder.encode(multiMetadataTypes, [actionData]);
|
|
243
329
|
};
|
|
244
330
|
|
|
245
|
-
export const
|
|
331
|
+
export const decodeData = (data: string) => {
|
|
332
|
+
try {
|
|
333
|
+
const metadata = getMetadataFromData(data) || "0x";
|
|
334
|
+
|
|
335
|
+
return parseMetadata(metadata);
|
|
336
|
+
} catch (e) {
|
|
337
|
+
// console.log(e);
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
export const decodeMetadata = (metadata: string) => {
|
|
246
343
|
try {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
344
|
+
return parseMetadata(metadata);
|
|
345
|
+
} catch (e) {
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
const iface = Forwarder__factory.createInterface();
|
|
351
|
+
const ifaceMultisig = MultisigForwarder__factory.createInterface();
|
|
352
|
+
|
|
353
|
+
const getMetadataFromData = (data: string) => {
|
|
354
|
+
let metadata = "0x";
|
|
355
|
+
|
|
356
|
+
if (data.startsWith("0x18e7f485")) {
|
|
357
|
+
const executeData = iface.decodeFunctionData("execute", data);
|
|
358
|
+
if (executeData.metadata_ === "0x" || !executeData.metadata_) {
|
|
359
|
+
return null;
|
|
360
|
+
} else {
|
|
361
|
+
metadata = executeData.metadata_;
|
|
362
|
+
}
|
|
363
|
+
} else if (data.startsWith("0x14f80a8d")) {
|
|
364
|
+
const executeDataV2 = iface.decodeFunctionData("executeV2", data);
|
|
365
|
+
if (
|
|
366
|
+
executeDataV2.params_.metadata === "0x" ||
|
|
367
|
+
!executeDataV2.params_.metadata
|
|
368
|
+
) {
|
|
369
|
+
return null;
|
|
370
|
+
} else {
|
|
371
|
+
metadata = executeDataV2.params_.metadata;
|
|
372
|
+
}
|
|
373
|
+
} else {
|
|
374
|
+
const executeDataMultisig = ifaceMultisig.decodeFunctionData(
|
|
375
|
+
"executeV1",
|
|
376
|
+
data
|
|
377
|
+
);
|
|
378
|
+
if (
|
|
379
|
+
executeDataMultisig.params_.metadata === "0x" ||
|
|
380
|
+
!executeDataMultisig.params_.metadata
|
|
381
|
+
) {
|
|
382
|
+
return null;
|
|
270
383
|
} else {
|
|
271
|
-
|
|
272
|
-
if (
|
|
273
|
-
executeDataV3.params_.metadata === "0x" ||
|
|
274
|
-
!executeDataV3.params_.metadata
|
|
275
|
-
) {
|
|
276
|
-
return null;
|
|
277
|
-
} else {
|
|
278
|
-
metadata = executeDataV3.params_.metadata;
|
|
279
|
-
}
|
|
384
|
+
metadata = executeDataMultisig.params_.metadata;
|
|
280
385
|
}
|
|
386
|
+
}
|
|
281
387
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
const [decodedMultiMetadata = []] =
|
|
285
|
-
(ethers.utils.defaultAbiCoder.decode(
|
|
286
|
-
multiMetadataTypes,
|
|
287
|
-
metadata
|
|
288
|
-
) as string[]) || [];
|
|
289
|
-
|
|
290
|
-
for (let metadata of decodedMultiMetadata) {
|
|
291
|
-
const decodedMetadata = ethers.utils.defaultAbiCoder.decode(
|
|
292
|
-
metadataTypes,
|
|
293
|
-
metadata
|
|
294
|
-
);
|
|
295
|
-
|
|
296
|
-
const type = ethers.utils.parseBytes32String(
|
|
297
|
-
decodedMetadata.type
|
|
298
|
-
) as keyof typeof actionMetadataTypes;
|
|
299
|
-
|
|
300
|
-
const decodedData = ethers.utils.defaultAbiCoder.decode(
|
|
301
|
-
actionMetadataTypes[type],
|
|
302
|
-
decodedMetadata.data
|
|
303
|
-
);
|
|
304
|
-
|
|
305
|
-
switch (type) {
|
|
306
|
-
case "transfer":
|
|
307
|
-
payload = {
|
|
308
|
-
type,
|
|
309
|
-
token: decodedData.token,
|
|
310
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
311
|
-
receiver: decodedData.receiver,
|
|
312
|
-
};
|
|
313
|
-
break;
|
|
314
|
-
case "bridge":
|
|
315
|
-
payload = {
|
|
316
|
-
type,
|
|
317
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
318
|
-
receiver: decodedData.receiver,
|
|
319
|
-
toToken: decodedData.toToken,
|
|
320
|
-
fromToken: decodedData.fromToken,
|
|
321
|
-
toChainId: decodedData.toChainId
|
|
322
|
-
? decodedData.toChainId.toString()
|
|
323
|
-
: null,
|
|
324
|
-
bridgeFee: toBN(decodedData.bridgeFee).toFixed(),
|
|
325
|
-
};
|
|
326
|
-
break;
|
|
327
|
-
case "swap":
|
|
328
|
-
payload = {
|
|
329
|
-
type,
|
|
330
|
-
buyAmount: toBN(decodedData.buyAmount).toFixed(),
|
|
331
|
-
sellAmount: toBN(decodedData.sellAmount).toFixed(),
|
|
332
|
-
buyToken: decodedData.buyToken,
|
|
333
|
-
sellToken: decodedData.sellToken,
|
|
334
|
-
receiver: decodedData.receiver,
|
|
335
|
-
protocol: utils.parseBytes32String(decodedData?.protocol || ""),
|
|
336
|
-
};
|
|
337
|
-
break;
|
|
338
|
-
case "upgrade":
|
|
339
|
-
payload = {
|
|
340
|
-
type,
|
|
341
|
-
version: utils.parseBytes32String(decodedData?.version || ""),
|
|
342
|
-
walletImpl: decodedData?.walletImpl,
|
|
343
|
-
};
|
|
344
|
-
break;
|
|
345
|
-
case "gas-topup":
|
|
346
|
-
payload = {
|
|
347
|
-
type,
|
|
348
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
349
|
-
token: decodedData.token,
|
|
350
|
-
onBehalf: decodedData.onBehalf,
|
|
351
|
-
};
|
|
352
|
-
break;
|
|
353
|
-
case "dapp":
|
|
354
|
-
payload = {
|
|
355
|
-
type,
|
|
356
|
-
name: decodedData?.name,
|
|
357
|
-
url: decodedData?.url,
|
|
358
|
-
};
|
|
359
|
-
break;
|
|
360
|
-
case "deploy":
|
|
361
|
-
payload = {
|
|
362
|
-
type,
|
|
363
|
-
};
|
|
364
|
-
break;
|
|
365
|
-
|
|
366
|
-
case "permit2":
|
|
367
|
-
payload = {
|
|
368
|
-
type,
|
|
369
|
-
token: decodedData.token,
|
|
370
|
-
spender: decodedData.spender,
|
|
371
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
372
|
-
expiration: decodedData.expiration,
|
|
373
|
-
};
|
|
374
|
-
break;
|
|
375
|
-
|
|
376
|
-
case "cross-transfer":
|
|
377
|
-
payload = {
|
|
378
|
-
type,
|
|
379
|
-
fromToken: decodedData.fromToken,
|
|
380
|
-
toToken: decodedData.toToken,
|
|
381
|
-
toChainId: decodedData.toChainId
|
|
382
|
-
? decodedData.toChainId.toString()
|
|
383
|
-
: null,
|
|
384
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
385
|
-
receiver: decodedData.receiver,
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
break;
|
|
389
|
-
case "auth":
|
|
390
|
-
payload = {
|
|
391
|
-
type: decodedData.remove ? "remove-authority" : "add-authority",
|
|
392
|
-
address: decodedData.address,
|
|
393
|
-
chainId: decodedData.chainId
|
|
394
|
-
? decodedData.chainId.toString()
|
|
395
|
-
: null,
|
|
396
|
-
remove: decodedData.remove,
|
|
397
|
-
};
|
|
398
|
-
|
|
399
|
-
break;
|
|
400
|
-
case "instadapp-pro":
|
|
401
|
-
payload = {
|
|
402
|
-
type,
|
|
403
|
-
castDetails: decodedData.castDetails,
|
|
404
|
-
};
|
|
405
|
-
|
|
406
|
-
break;
|
|
407
|
-
}
|
|
388
|
+
return metadata;
|
|
389
|
+
};
|
|
408
390
|
|
|
391
|
+
|
|
392
|
+
const typesPayload: IPayload = {
|
|
393
|
+
transfer: (data, type) => ({
|
|
394
|
+
type,
|
|
395
|
+
token: data.token,
|
|
396
|
+
amount: toBN(data.amount).toFixed(),
|
|
397
|
+
receiver: data.receiver,
|
|
398
|
+
}),
|
|
399
|
+
bridge: (data, type) => ({
|
|
400
|
+
type,
|
|
401
|
+
amount: toBN(data.amount).toFixed(),
|
|
402
|
+
receiver: data.receiver,
|
|
403
|
+
toToken: data.toToken,
|
|
404
|
+
fromToken: data.fromToken,
|
|
405
|
+
toChainId: data.toChainId ? data.toChainId.toString() : null,
|
|
406
|
+
bridgeFee: toBN(data.bridgeFee).toFixed(),
|
|
407
|
+
}),
|
|
408
|
+
swap: (data, type) => ({
|
|
409
|
+
type,
|
|
410
|
+
buyAmount: toBN(data.buyAmount).toFixed(),
|
|
411
|
+
sellAmount: toBN(data.sellAmount).toFixed(),
|
|
412
|
+
buyToken: data.buyToken,
|
|
413
|
+
sellToken: data.sellToken,
|
|
414
|
+
receiver: data.receiver,
|
|
415
|
+
protocol: utils.parseBytes32String(data.protocol || ""),
|
|
416
|
+
}),
|
|
417
|
+
upgrade: (data, type) => ({
|
|
418
|
+
type,
|
|
419
|
+
version: utils.parseBytes32String(data.version || ""),
|
|
420
|
+
walletImpl: data.walletImpl,
|
|
421
|
+
}),
|
|
422
|
+
"gas-topup": (data, type) => ({
|
|
423
|
+
type,
|
|
424
|
+
amount: toBN(data.amount).toFixed(),
|
|
425
|
+
token: data.token,
|
|
426
|
+
onBehalf: data.onBehalf,
|
|
427
|
+
}),
|
|
428
|
+
"dapp": (data, type) => ({
|
|
429
|
+
type,
|
|
430
|
+
name: data.name,
|
|
431
|
+
url: data.url,
|
|
432
|
+
}),
|
|
433
|
+
"deploy": (data, type) => ({
|
|
434
|
+
type,
|
|
435
|
+
}),
|
|
436
|
+
"permit2": (data, type) => ({
|
|
437
|
+
type,
|
|
438
|
+
token: data.token,
|
|
439
|
+
spender: data.spender,
|
|
440
|
+
amount: toBN(data.amount).toFixed(),
|
|
441
|
+
expiration: data.expiration,
|
|
442
|
+
}),
|
|
443
|
+
"cross-transfer": (data, type) => ({
|
|
444
|
+
type,
|
|
445
|
+
fromToken: data.fromToken,
|
|
446
|
+
toToken: data.toToken,
|
|
447
|
+
toChainId: data.toChainId ? data.toChainId.toString() : null,
|
|
448
|
+
amount: toBN(data.amount).toFixed(),
|
|
449
|
+
receiver: data.receiver,
|
|
450
|
+
}),
|
|
451
|
+
"auth": (data) => ({
|
|
452
|
+
type: data.remove ? "remove-authority" : "add-authority",
|
|
453
|
+
address: data.address,
|
|
454
|
+
chainId: data.chainId ? data.chainId.toString() : null,
|
|
455
|
+
remove: data.remove,
|
|
456
|
+
}),
|
|
457
|
+
"instadapp-pro": (data, type) => ({
|
|
458
|
+
type,
|
|
459
|
+
castDetails: data.castDetails,
|
|
460
|
+
}),
|
|
461
|
+
"rejection": (data, type) => ({
|
|
462
|
+
type,
|
|
463
|
+
id: data.id,
|
|
464
|
+
}),
|
|
465
|
+
"add-signers": (data, type) => ({
|
|
466
|
+
type,
|
|
467
|
+
addresses: data.signers,
|
|
468
|
+
}),
|
|
469
|
+
"remove-signers": (data, type) => ({
|
|
470
|
+
type,
|
|
471
|
+
addresses: data.signers,
|
|
472
|
+
}),
|
|
473
|
+
"change-threshold": (data, type) => ({
|
|
474
|
+
type,
|
|
475
|
+
count: data.count,
|
|
476
|
+
}),
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
const parseMetadata = (metadata: string) => {
|
|
480
|
+
const metadataArr = [];
|
|
481
|
+
|
|
482
|
+
const [decodedMultiMetadata = []] =
|
|
483
|
+
(ethers.utils.defaultAbiCoder.decode(
|
|
484
|
+
multiMetadataTypes,
|
|
485
|
+
metadata
|
|
486
|
+
) as string[]) || [];
|
|
487
|
+
|
|
488
|
+
for (let metadata of decodedMultiMetadata) {
|
|
489
|
+
const decodedMetadata = ethers.utils.defaultAbiCoder.decode(
|
|
490
|
+
metadataTypes,
|
|
491
|
+
metadata
|
|
492
|
+
);
|
|
493
|
+
|
|
494
|
+
const type = ethers.utils.parseBytes32String(
|
|
495
|
+
decodedMetadata.type
|
|
496
|
+
) as keyof typeof actionMetadataTypes;
|
|
497
|
+
|
|
498
|
+
const decodedData = ethers.utils.defaultAbiCoder.decode(
|
|
499
|
+
actionMetadataTypes[type],
|
|
500
|
+
decodedMetadata.data
|
|
501
|
+
);
|
|
502
|
+
|
|
503
|
+
const payloadFunc = typesPayload[type]
|
|
504
|
+
|
|
505
|
+
if (payloadFunc) {
|
|
506
|
+
const payload = payloadFunc(decodedData, type)
|
|
409
507
|
metadataArr.push(payload);
|
|
410
508
|
}
|
|
411
509
|
|
|
412
|
-
return metadataArr;
|
|
413
|
-
} catch (e) {
|
|
414
|
-
console.log(e);
|
|
415
|
-
return null;
|
|
416
510
|
}
|
|
511
|
+
|
|
512
|
+
return metadataArr;
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Replaces hyphens with spaces and capitalizes the first letter of each word in a sentence.
|
|
519
|
+
* @param {string} txType - The input sentence to modify
|
|
520
|
+
*
|
|
521
|
+
* @returns {string} - The modified sentence with hyphens replaced with spaces and the first letter of each word capitalized.
|
|
522
|
+
*/
|
|
523
|
+
export const formatTxType = (txType: string) => {
|
|
524
|
+
const finalSentence = txType
|
|
525
|
+
.replace("-", " ")
|
|
526
|
+
.replace(/(^\w{1})|(\s+\w{1})/g, (letter) => letter.toUpperCase());
|
|
527
|
+
|
|
528
|
+
return finalSentence;
|
|
417
529
|
};
|