@instadapp/avocado-base 0.0.0-dev.083a57a → 0.0.0-dev.0841bfc
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/app.vue +7 -0
- package/assets/images/icons/change-threshold.svg +4 -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/gas.svg +12 -5
- package/assets/images/icons/instadapp-pro.svg +4 -0
- package/assets/images/icons/multi-send.svg +7 -0
- package/assets/images/icons/permit-sign.svg +11 -0
- package/assets/images/icons/plus-circle.svg +6 -0
- package/assets/images/icons/refresh.svg +4 -4
- package/assets/images/icons/reject-proposal.svg +6 -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/components/ActionLogo.vue +38 -0
- package/components/ActionMetadata.vue +23 -4
- package/components/AuthorityAvatar.vue +26 -0
- package/components/ChainLogo.vue +4 -562
- package/components/CopyClipboard.vue +64 -0
- package/components/metadata/Bridge.vue +26 -6
- package/components/metadata/CrossTransfer.vue +5 -1
- package/components/metadata/GasTopup.vue +7 -1
- package/components/metadata/Permit2.vue +6 -1
- package/components/metadata/Signers.vue +45 -0
- package/components/metadata/Swap.vue +9 -2
- package/components/metadata/Transfer.vue +6 -2
- package/package.json +5 -3
- package/utils/formatter.ts +1 -1
- package/utils/helper.ts +19 -0
- package/utils/metadata.ts +193 -115
- package/utils/network.ts +124 -79
- package/utils/services.ts +8 -1
- package/utils/utils.d.ts +128 -126
|
@@ -6,31 +6,51 @@ const props = defineProps<{
|
|
|
6
6
|
}>();
|
|
7
7
|
|
|
8
8
|
const compact = inject('compact');
|
|
9
|
+
const tokens = inject<ITokenPrice[]>('tokens');
|
|
9
10
|
|
|
10
11
|
const toToken = asyncComputed(() =>
|
|
11
|
-
|
|
12
|
+
{
|
|
13
|
+
if (Array.isArray(tokens) && !tokens.length) return null;
|
|
14
|
+
return fetchTokenByAddress(props.metadata?.toToken, props.metadata?.toChainId, tokens)
|
|
15
|
+
}
|
|
12
16
|
);
|
|
13
17
|
|
|
18
|
+
const fromToken = asyncComputed(() =>
|
|
19
|
+
{
|
|
20
|
+
if (Array.isArray(tokens) && !tokens.length) return null;
|
|
21
|
+
return fetchTokenByAddress(props.metadata?.fromToken, props.chain_id, tokens)
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const isTokensSame = computed(() => {
|
|
26
|
+
return toToken.value?.symbol === fromToken.value?.symbol
|
|
27
|
+
})
|
|
28
|
+
|
|
14
29
|
const bridgeAmountFormatted = computed(() =>
|
|
15
30
|
formatDecimal(
|
|
16
|
-
fromWei(props.metadata?.amount,
|
|
31
|
+
fromWei(props.metadata?.amount, fromToken?.value?.decimals).toFixed()
|
|
17
32
|
)
|
|
18
33
|
);
|
|
19
34
|
</script>
|
|
20
35
|
|
|
21
36
|
<template>
|
|
22
|
-
<div v-if="!toToken" class="rounded-5 w-24 h-4 loading-box" />
|
|
37
|
+
<div v-if="!toToken || !fromToken" class="rounded-5 w-24 h-4 loading-box" />
|
|
23
38
|
<div
|
|
24
39
|
class="flex gap-5 items-center"
|
|
25
|
-
v-if="
|
|
40
|
+
v-if="toToken && fromToken"
|
|
26
41
|
>
|
|
27
42
|
<span v-if="!compact" class="capitalize text-xs sm:text-sm">{{ metadata.type }}</span>
|
|
28
43
|
<span class="inline-flex gap-2.5 items-center">
|
|
29
|
-
<img width="20" height="20" class="w-5 h-5" :src="
|
|
44
|
+
<img width="20" height="20" class="w-5 h-5" :src="fromToken.logo_url" />
|
|
30
45
|
{{ bridgeAmountFormatted }}
|
|
31
|
-
<span class="uppercase">{{
|
|
46
|
+
<span class="uppercase">{{ fromToken?.symbol }}</span>
|
|
32
47
|
<SvgoBridge class="text-slate-400 w-4 h-4" />
|
|
48
|
+
<template v-if="!isTokensSame">
|
|
49
|
+
<img width="20" height="20" class="w-5 h-5" :src="toToken.logo_url" />
|
|
50
|
+
<span class="uppercase">{{ toToken?.symbol }}</span>
|
|
51
|
+
</template>
|
|
33
52
|
<span class="flex items-center gap-2.5">
|
|
53
|
+
on
|
|
34
54
|
<ChainLogo class="w-5" :chain="metadata.toChainId" />
|
|
35
55
|
<span>{{ chainIdToName(metadata.toChainId) }}</span>
|
|
36
56
|
</span>
|
|
@@ -6,13 +6,17 @@ const props = defineProps<{
|
|
|
6
6
|
}>();
|
|
7
7
|
|
|
8
8
|
const compact = inject('compact');
|
|
9
|
+
const tokens = inject<ITokenPrice[]>('tokens');
|
|
9
10
|
|
|
10
11
|
const fromToken = asyncComputed(() => {
|
|
11
12
|
if (!props?.chain_id) return null;
|
|
12
13
|
|
|
14
|
+
if (Array.isArray(tokens) && !tokens.length) return null;
|
|
15
|
+
|
|
13
16
|
return fetchTokenByAddress(
|
|
14
17
|
props.metadata?.fromToken,
|
|
15
|
-
props?.chain_id
|
|
18
|
+
props?.chain_id,
|
|
19
|
+
tokens
|
|
16
20
|
);
|
|
17
21
|
});
|
|
18
22
|
|
|
@@ -5,8 +5,14 @@ const props = defineProps<{
|
|
|
5
5
|
chain_id: number | string
|
|
6
6
|
}>();
|
|
7
7
|
|
|
8
|
+
const tokens = inject<ITokenPrice[]>('tokens');
|
|
9
|
+
|
|
8
10
|
const token = asyncComputed(() =>
|
|
9
|
-
|
|
11
|
+
{
|
|
12
|
+
if (Array.isArray(tokens) && !tokens.length) return null;
|
|
13
|
+
|
|
14
|
+
return fetchTokenByAddress(props.metadata?.token, props?.chain_id, tokens)
|
|
15
|
+
}
|
|
10
16
|
);
|
|
11
17
|
|
|
12
18
|
const compact = inject('compact');
|
|
@@ -5,8 +5,13 @@ const props = defineProps<{
|
|
|
5
5
|
chain_id: number | string
|
|
6
6
|
}>();
|
|
7
7
|
|
|
8
|
+
const tokens = inject<ITokenPrice[]>('tokens');
|
|
9
|
+
|
|
8
10
|
const token = asyncComputed(() =>
|
|
9
|
-
|
|
11
|
+
{
|
|
12
|
+
if (Array.isArray(tokens) && !tokens.length) return null;
|
|
13
|
+
return fetchTokenByAddress(props.metadata?.token, props?.chain_id, tokens)
|
|
14
|
+
}
|
|
10
15
|
);
|
|
11
16
|
|
|
12
17
|
const calculateDate = (timestamp: number) => {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { Tippy } from 'vue-tippy'
|
|
3
|
+
const props = defineProps<{
|
|
4
|
+
metadata: {
|
|
5
|
+
type: MetadataTypes,
|
|
6
|
+
[key: string]: any
|
|
7
|
+
};
|
|
8
|
+
compact?: boolean;
|
|
9
|
+
}>();
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<template>
|
|
13
|
+
<div>
|
|
14
|
+
<div v-if="!compact || metadata.addresses.length < 3" class="flex gap-[14px] flex-wrap">
|
|
15
|
+
<div v-for="address of metadata.addresses" :key="address" class="flex gap-[8px] rounded-full bg-slate-50 dark:bg-gray-850 justify-start items-center px-[8px] py-[6px]">
|
|
16
|
+
<AuthorityAvatar :address="address" class="w-[18px] h-[18px]" />
|
|
17
|
+
<p class="text-xs leading-5">
|
|
18
|
+
{{ shortenHash(address, compact ? 2 : 4) }}
|
|
19
|
+
</p>
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
<div v-else class="flex gap-2 flex-wrap items-center">
|
|
23
|
+
<div v-for="address of [metadata.addresses[0], metadata.addresses[1]]" :key="address" class="flex gap-[8px] rounded-full bg-slate-50 dark:bg-gray-850 justify-start items-center px-[8px] py-[6px]">
|
|
24
|
+
<AuthorityAvatar :address="address" class="w-[18px] h-[18px]" />
|
|
25
|
+
<p class="text-xs leading-5">
|
|
26
|
+
{{ shortenHash(address, 2) }}
|
|
27
|
+
</p>
|
|
28
|
+
</div>
|
|
29
|
+
...
|
|
30
|
+
<Tippy max-width="none" interactive tag="button" content-tag="div" content-class="content-wrapper">
|
|
31
|
+
<template #default>
|
|
32
|
+
<SvgoInfo2 class="w-[16px] h-[16px] text-slate-500 rounded-full" />
|
|
33
|
+
</template>
|
|
34
|
+
<template #content>
|
|
35
|
+
<ul class="flex flex-col gap-2.5">
|
|
36
|
+
<li v-for="address in metadata.addresses" :key="address" class="flex text-xs items-center gap-2.5">
|
|
37
|
+
<AuthorityAvatar class="shrink-0 w-5 h-5" :address="address" />
|
|
38
|
+
{{ address }}
|
|
39
|
+
</li>
|
|
40
|
+
</ul>
|
|
41
|
+
</template>
|
|
42
|
+
</Tippy>
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
</template>
|
|
@@ -6,12 +6,19 @@ const props = defineProps<{
|
|
|
6
6
|
}>();
|
|
7
7
|
|
|
8
8
|
const compact = inject('compact');
|
|
9
|
+
const tokens = inject<ITokenPrice[]>('tokens');
|
|
9
10
|
|
|
10
11
|
const buyToken = asyncComputed(() =>
|
|
11
|
-
|
|
12
|
+
{
|
|
13
|
+
if (Array.isArray(tokens) && !tokens.length) return null;
|
|
14
|
+
return fetchTokenByAddress(props.metadata?.buyToken, props?.chain_id, tokens)
|
|
15
|
+
}
|
|
12
16
|
);
|
|
13
17
|
const sellToken = asyncComputed(() =>
|
|
14
|
-
|
|
18
|
+
{
|
|
19
|
+
if (Array.isArray(tokens) && !tokens.length) return null;
|
|
20
|
+
return fetchTokenByAddress(props.metadata?.sellToken, props?.chain_id, tokens)
|
|
21
|
+
}
|
|
15
22
|
);
|
|
16
23
|
|
|
17
24
|
const sellAmountFormatted = computed(() =>
|
|
@@ -6,13 +6,17 @@ const props = defineProps<{
|
|
|
6
6
|
}>();
|
|
7
7
|
|
|
8
8
|
const compact = inject('compact');
|
|
9
|
+
const tokens = inject<ITokenPrice[]>('tokens');
|
|
9
10
|
|
|
10
11
|
const token = asyncComputed(() => {
|
|
11
12
|
if (!props?.chain_id) return null;
|
|
12
13
|
|
|
14
|
+
if (Array.isArray(tokens) && !tokens.length) return null;
|
|
15
|
+
|
|
13
16
|
return fetchTokenByAddress(
|
|
14
17
|
props.metadata?.token,
|
|
15
|
-
props?.chain_id
|
|
18
|
+
props?.chain_id,
|
|
19
|
+
tokens
|
|
16
20
|
);
|
|
17
21
|
});
|
|
18
22
|
|
|
@@ -28,9 +32,9 @@ const formattedAmount = computed(() =>
|
|
|
28
32
|
<div class="flex items-center gap-5" v-else>
|
|
29
33
|
<span v-if="!compact" class="capitalize text-xs sm:text-sm">{{ metadata.type }}</span>
|
|
30
34
|
<span class="inline-flex gap-2.5 items-center">
|
|
31
|
-
<img width="20" height="20" class="w-5 h-5" :src="token?.logo_url" />
|
|
32
35
|
{{ formattedAmount }}
|
|
33
36
|
<span class="uppercase">{{ token?.symbol }}</span>
|
|
37
|
+
<img width="20" height="20" class="w-5 h-5" :src="token?.logo_url" />
|
|
34
38
|
<SvgoArrowRight class="w-4 h-4 text-slate-400 mx-2" />
|
|
35
39
|
<NuxtLink
|
|
36
40
|
class="text-primary"
|
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.0841bfc",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./nuxt.config.ts",
|
|
6
6
|
"types": "global.d.ts",
|
|
@@ -20,11 +20,13 @@
|
|
|
20
20
|
"nuxt-svgo": "^3.1.0",
|
|
21
21
|
"rimraf": "^3.0.2",
|
|
22
22
|
"typechain": "^8.1.1",
|
|
23
|
-
"unplugin-vue-components": "^0.25.1"
|
|
23
|
+
"unplugin-vue-components": "^0.25.1",
|
|
24
|
+
"vue-tippy": "^6.0.0"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
27
|
"@vueuse/nuxt": "^10.2.0",
|
|
27
28
|
"bignumber.js": "^9.1.1",
|
|
28
|
-
"ethers": "^5.7.2"
|
|
29
|
+
"ethers": "^5.7.2",
|
|
30
|
+
"xxhashjs": "^0.2.2"
|
|
29
31
|
}
|
|
30
32
|
}
|
package/utils/formatter.ts
CHANGED
package/utils/helper.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as XXH from 'xxhashjs';
|
|
2
|
+
|
|
1
3
|
export const indexSorter = (aIndex: number, bIndex: number) => {
|
|
2
4
|
if (aIndex === -1 && bIndex === -1) {
|
|
3
5
|
return 0; // fallback to other sorting criteria
|
|
@@ -52,3 +54,20 @@ export function onImageError(this: HTMLImageElement) {
|
|
|
52
54
|
parentElement.classList.add("bg-gray-300");
|
|
53
55
|
}
|
|
54
56
|
}
|
|
57
|
+
|
|
58
|
+
export function formatMultipleAddresses(addresses: string[], shorten = true) {
|
|
59
|
+
const formatter = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' })
|
|
60
|
+
const formattedString = formatter.format(addresses.map(i => shorten ? shortenHash(i) || '' : i))
|
|
61
|
+
|
|
62
|
+
return formattedString
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function generateColor(address: string): string {
|
|
66
|
+
const hash = XXH.h32(address, 0xABCD).toNumber()
|
|
67
|
+
|
|
68
|
+
const hue = hash % 360
|
|
69
|
+
const saturation = 80 + (hash % 30)
|
|
70
|
+
const lightness = 70 + (hash % 20)
|
|
71
|
+
|
|
72
|
+
return `hsl(${hue}, ${saturation}%, ${lightness}%)`
|
|
73
|
+
}
|
package/utils/metadata.ts
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
import { ethers, utils } from "ethers";
|
|
2
2
|
import { Forwarder__factory } from "../contracts";
|
|
3
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;
|
|
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"],
|
|
10
28
|
"cross-transfer": [
|
|
11
29
|
"address fromToken",
|
|
@@ -43,6 +61,10 @@ const actionMetadataTypes = {
|
|
|
43
61
|
"uint48 expiration",
|
|
44
62
|
],
|
|
45
63
|
"instadapp-pro": ["string castDetails"],
|
|
64
|
+
'add-signers': ['address[] signers'],
|
|
65
|
+
'remove-signers': ['address[] signers'],
|
|
66
|
+
'change-threshold': ['uint8 count'],
|
|
67
|
+
'rejection': ['bytes32 id'],
|
|
46
68
|
};
|
|
47
69
|
|
|
48
70
|
const encodeMetadata = (props: MetadataProps) => {
|
|
@@ -63,7 +85,7 @@ export const encodeDappMetadata = (
|
|
|
63
85
|
);
|
|
64
86
|
|
|
65
87
|
const data = encodeMetadata({
|
|
66
|
-
type:
|
|
88
|
+
type: MetadataEnums.dapp,
|
|
67
89
|
encodedData,
|
|
68
90
|
});
|
|
69
91
|
|
|
@@ -80,7 +102,21 @@ export const encodeTransferMetadata = (
|
|
|
80
102
|
);
|
|
81
103
|
|
|
82
104
|
const data = encodeMetadata({
|
|
83
|
-
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,
|
|
84
120
|
encodedData,
|
|
85
121
|
});
|
|
86
122
|
|
|
@@ -103,7 +139,7 @@ export const encodeCrossTransferMetadata = (
|
|
|
103
139
|
);
|
|
104
140
|
|
|
105
141
|
const data = encodeMetadata({
|
|
106
|
-
type: "cross-transfer",
|
|
142
|
+
type: MetadataEnums["cross-transfer"],
|
|
107
143
|
encodedData,
|
|
108
144
|
});
|
|
109
145
|
|
|
@@ -120,7 +156,7 @@ export const encodeAuthMetadata = (
|
|
|
120
156
|
);
|
|
121
157
|
|
|
122
158
|
const data = encodeMetadata({
|
|
123
|
-
type:
|
|
159
|
+
type: MetadataEnums.auth,
|
|
124
160
|
encodedData,
|
|
125
161
|
});
|
|
126
162
|
|
|
@@ -129,7 +165,7 @@ export const encodeAuthMetadata = (
|
|
|
129
165
|
|
|
130
166
|
export const encodeDeployMetadata = (single = true) => {
|
|
131
167
|
const data = encodeMetadata({
|
|
132
|
-
type:
|
|
168
|
+
type: MetadataEnums.deploy,
|
|
133
169
|
encodedData: "0x",
|
|
134
170
|
});
|
|
135
171
|
|
|
@@ -146,7 +182,7 @@ export const encodeWCSignMetadata = (
|
|
|
146
182
|
);
|
|
147
183
|
|
|
148
184
|
const data = encodeMetadata({
|
|
149
|
-
type:
|
|
185
|
+
type: MetadataEnums.permit2,
|
|
150
186
|
encodedData,
|
|
151
187
|
});
|
|
152
188
|
|
|
@@ -163,7 +199,7 @@ export const encodeUpgradeMetadata = (
|
|
|
163
199
|
);
|
|
164
200
|
|
|
165
201
|
const data = encodeMetadata({
|
|
166
|
-
type:
|
|
202
|
+
type: MetadataEnums.upgrade,
|
|
167
203
|
encodedData,
|
|
168
204
|
});
|
|
169
205
|
|
|
@@ -187,7 +223,7 @@ export const encodeSwapMetadata = (
|
|
|
187
223
|
);
|
|
188
224
|
|
|
189
225
|
const data = encodeMetadata({
|
|
190
|
-
type:
|
|
226
|
+
type: MetadataEnums.swap,
|
|
191
227
|
encodedData,
|
|
192
228
|
});
|
|
193
229
|
|
|
@@ -203,10 +239,8 @@ export const encodeTopupMetadata = (
|
|
|
203
239
|
[params.amount, params.token, params.onBehalf]
|
|
204
240
|
);
|
|
205
241
|
|
|
206
|
-
console.log(params);
|
|
207
|
-
|
|
208
242
|
const data = encodeMetadata({
|
|
209
|
-
type: "gas-topup",
|
|
243
|
+
type: MetadataEnums["gas-topup"],
|
|
210
244
|
encodedData,
|
|
211
245
|
});
|
|
212
246
|
|
|
@@ -231,7 +265,58 @@ export const encodeBridgeMetadata = (
|
|
|
231
265
|
);
|
|
232
266
|
|
|
233
267
|
const data = encodeMetadata({
|
|
234
|
-
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"],
|
|
235
320
|
encodedData,
|
|
236
321
|
});
|
|
237
322
|
|
|
@@ -310,9 +395,96 @@ const getMetadataFromData = (data: string) => {
|
|
|
310
395
|
return metadata;
|
|
311
396
|
};
|
|
312
397
|
|
|
398
|
+
|
|
399
|
+
const typesPayload: IPayload = {
|
|
400
|
+
transfer: (data, type) => ({
|
|
401
|
+
type,
|
|
402
|
+
token: data.token,
|
|
403
|
+
amount: toBN(data.amount).toFixed(),
|
|
404
|
+
receiver: data.receiver,
|
|
405
|
+
}),
|
|
406
|
+
bridge: (data, type) => ({
|
|
407
|
+
type,
|
|
408
|
+
amount: toBN(data.amount).toFixed(),
|
|
409
|
+
receiver: data.receiver,
|
|
410
|
+
toToken: data.toToken,
|
|
411
|
+
fromToken: data.fromToken,
|
|
412
|
+
toChainId: data.toChainId ? data.toChainId.toString() : null,
|
|
413
|
+
bridgeFee: toBN(data.bridgeFee).toFixed(),
|
|
414
|
+
}),
|
|
415
|
+
swap: (data, type) => ({
|
|
416
|
+
type,
|
|
417
|
+
buyAmount: toBN(data.buyAmount).toFixed(),
|
|
418
|
+
sellAmount: toBN(data.sellAmount).toFixed(),
|
|
419
|
+
buyToken: data.buyToken,
|
|
420
|
+
sellToken: data.sellToken,
|
|
421
|
+
receiver: data.receiver,
|
|
422
|
+
protocol: utils.parseBytes32String(data.protocol || ""),
|
|
423
|
+
}),
|
|
424
|
+
upgrade: (data, type) => ({
|
|
425
|
+
type,
|
|
426
|
+
version: utils.parseBytes32String(data.version || ""),
|
|
427
|
+
walletImpl: data.walletImpl,
|
|
428
|
+
}),
|
|
429
|
+
"gas-topup": (data, type) => ({
|
|
430
|
+
type,
|
|
431
|
+
amount: toBN(data.amount).toFixed(),
|
|
432
|
+
token: data.token,
|
|
433
|
+
onBehalf: data.onBehalf,
|
|
434
|
+
}),
|
|
435
|
+
"dapp": (data, type) => ({
|
|
436
|
+
type,
|
|
437
|
+
name: data.name,
|
|
438
|
+
url: data.url,
|
|
439
|
+
}),
|
|
440
|
+
"deploy": (data, type) => ({
|
|
441
|
+
type,
|
|
442
|
+
}),
|
|
443
|
+
"permit2": (data, type) => ({
|
|
444
|
+
type,
|
|
445
|
+
token: data.token,
|
|
446
|
+
spender: data.spender,
|
|
447
|
+
amount: toBN(data.amount).toFixed(),
|
|
448
|
+
expiration: data.expiration,
|
|
449
|
+
}),
|
|
450
|
+
"cross-transfer": (data, type) => ({
|
|
451
|
+
type,
|
|
452
|
+
fromToken: data.fromToken,
|
|
453
|
+
toToken: data.toToken,
|
|
454
|
+
toChainId: data.toChainId ? data.toChainId.toString() : null,
|
|
455
|
+
amount: toBN(data.amount).toFixed(),
|
|
456
|
+
receiver: data.receiver,
|
|
457
|
+
}),
|
|
458
|
+
"auth": (data) => ({
|
|
459
|
+
type: data.remove ? "remove-authority" : "add-authority",
|
|
460
|
+
address: data.address,
|
|
461
|
+
chainId: data.chainId ? data.chainId.toString() : null,
|
|
462
|
+
remove: data.remove,
|
|
463
|
+
}),
|
|
464
|
+
"instadapp-pro": (data, type) => ({
|
|
465
|
+
type,
|
|
466
|
+
castDetails: data.castDetails,
|
|
467
|
+
}),
|
|
468
|
+
"rejection": (data, type) => ({
|
|
469
|
+
type,
|
|
470
|
+
id: data.id,
|
|
471
|
+
}),
|
|
472
|
+
"add-signers": (data, type) => ({
|
|
473
|
+
type,
|
|
474
|
+
addresses: data.signers,
|
|
475
|
+
}),
|
|
476
|
+
"remove-signers": (data, type) => ({
|
|
477
|
+
type,
|
|
478
|
+
addresses: data.signers,
|
|
479
|
+
}),
|
|
480
|
+
"change-threshold": (data, type) => ({
|
|
481
|
+
type,
|
|
482
|
+
count: data.count,
|
|
483
|
+
}),
|
|
484
|
+
};
|
|
485
|
+
|
|
313
486
|
const parseMetadata = (metadata: string) => {
|
|
314
487
|
const metadataArr = [];
|
|
315
|
-
let payload = {};
|
|
316
488
|
|
|
317
489
|
const [decodedMultiMetadata = []] =
|
|
318
490
|
(ethers.utils.defaultAbiCoder.decode(
|
|
@@ -335,114 +507,20 @@ const parseMetadata = (metadata: string) => {
|
|
|
335
507
|
decodedMetadata.data
|
|
336
508
|
);
|
|
337
509
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
344
|
-
receiver: decodedData.receiver,
|
|
345
|
-
};
|
|
346
|
-
break;
|
|
347
|
-
case "bridge":
|
|
348
|
-
payload = {
|
|
349
|
-
type,
|
|
350
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
351
|
-
receiver: decodedData.receiver,
|
|
352
|
-
toToken: decodedData.toToken,
|
|
353
|
-
fromToken: decodedData.fromToken,
|
|
354
|
-
toChainId: decodedData.toChainId
|
|
355
|
-
? decodedData.toChainId.toString()
|
|
356
|
-
: null,
|
|
357
|
-
bridgeFee: toBN(decodedData.bridgeFee).toFixed(),
|
|
358
|
-
};
|
|
359
|
-
break;
|
|
360
|
-
case "swap":
|
|
361
|
-
payload = {
|
|
362
|
-
type,
|
|
363
|
-
buyAmount: toBN(decodedData.buyAmount).toFixed(),
|
|
364
|
-
sellAmount: toBN(decodedData.sellAmount).toFixed(),
|
|
365
|
-
buyToken: decodedData.buyToken,
|
|
366
|
-
sellToken: decodedData.sellToken,
|
|
367
|
-
receiver: decodedData.receiver,
|
|
368
|
-
protocol: utils.parseBytes32String(decodedData?.protocol || ""),
|
|
369
|
-
};
|
|
370
|
-
break;
|
|
371
|
-
case "upgrade":
|
|
372
|
-
payload = {
|
|
373
|
-
type,
|
|
374
|
-
version: utils.parseBytes32String(decodedData?.version || ""),
|
|
375
|
-
walletImpl: decodedData?.walletImpl,
|
|
376
|
-
};
|
|
377
|
-
break;
|
|
378
|
-
case "gas-topup":
|
|
379
|
-
payload = {
|
|
380
|
-
type,
|
|
381
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
382
|
-
token: decodedData.token,
|
|
383
|
-
onBehalf: decodedData.onBehalf,
|
|
384
|
-
};
|
|
385
|
-
break;
|
|
386
|
-
case "dapp":
|
|
387
|
-
payload = {
|
|
388
|
-
type,
|
|
389
|
-
name: decodedData?.name,
|
|
390
|
-
url: decodedData?.url,
|
|
391
|
-
};
|
|
392
|
-
break;
|
|
393
|
-
case "deploy":
|
|
394
|
-
payload = {
|
|
395
|
-
type,
|
|
396
|
-
};
|
|
397
|
-
break;
|
|
398
|
-
|
|
399
|
-
case "permit2":
|
|
400
|
-
payload = {
|
|
401
|
-
type,
|
|
402
|
-
token: decodedData.token,
|
|
403
|
-
spender: decodedData.spender,
|
|
404
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
405
|
-
expiration: decodedData.expiration,
|
|
406
|
-
};
|
|
407
|
-
break;
|
|
408
|
-
|
|
409
|
-
case "cross-transfer":
|
|
410
|
-
payload = {
|
|
411
|
-
type,
|
|
412
|
-
fromToken: decodedData.fromToken,
|
|
413
|
-
toToken: decodedData.toToken,
|
|
414
|
-
toChainId: decodedData.toChainId
|
|
415
|
-
? decodedData.toChainId.toString()
|
|
416
|
-
: null,
|
|
417
|
-
amount: toBN(decodedData.amount).toFixed(),
|
|
418
|
-
receiver: decodedData.receiver,
|
|
419
|
-
};
|
|
420
|
-
|
|
421
|
-
break;
|
|
422
|
-
case "auth":
|
|
423
|
-
payload = {
|
|
424
|
-
type: decodedData.remove ? "remove-authority" : "add-authority",
|
|
425
|
-
address: decodedData.address,
|
|
426
|
-
chainId: decodedData.chainId ? decodedData.chainId.toString() : null,
|
|
427
|
-
remove: decodedData.remove,
|
|
428
|
-
};
|
|
429
|
-
|
|
430
|
-
break;
|
|
431
|
-
case "instadapp-pro":
|
|
432
|
-
payload = {
|
|
433
|
-
type,
|
|
434
|
-
castDetails: decodedData.castDetails,
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
break;
|
|
510
|
+
const payloadFunc = typesPayload[type]
|
|
511
|
+
|
|
512
|
+
if (payloadFunc) {
|
|
513
|
+
const payload = payloadFunc(decodedData, type)
|
|
514
|
+
metadataArr.push(payload);
|
|
438
515
|
}
|
|
439
516
|
|
|
440
|
-
metadataArr.push(payload);
|
|
441
517
|
}
|
|
442
518
|
|
|
443
519
|
return metadataArr;
|
|
444
520
|
};
|
|
445
521
|
|
|
522
|
+
|
|
523
|
+
|
|
446
524
|
/**
|
|
447
525
|
* Replaces hyphens with spaces and capitalizes the first letter of each word in a sentence.
|
|
448
526
|
* @param {string} txType - The input sentence to modify
|