@instadapp/avocado-base 0.0.0-dev.19925f5 → 0.0.0-dev.2177c3e
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/avoFactoryProxy.json +109 -0
- package/abi/balanceResolver.json +110 -0
- package/abi/erc20.json +350 -0
- package/abi/forwarder.json +1435 -0
- package/abi/gaslessWallet.json +289 -0
- package/app.vue +27 -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 -416
- 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 +47 -0
- package/components/metadata/Swap.vue +74 -0
- package/components/metadata/Transfer.vue +50 -0
- package/components.d.ts +13 -0
- package/contracts/AvoFactoryProxy.ts +302 -0
- package/contracts/BalanceResolver.ts +321 -0
- package/contracts/Erc20.ts +526 -0
- package/contracts/Forwarder.ts +1644 -0
- package/contracts/GaslessWallet.ts +660 -0
- package/contracts/common.ts +46 -0
- package/contracts/factories/AvoFactoryProxy__factory.ts +181 -0
- package/contracts/factories/BalanceResolver__factory.ts +212 -0
- package/contracts/factories/Erc20__factory.ts +368 -0
- package/contracts/factories/Forwarder__factory.ts +1456 -0
- package/contracts/factories/GaslessWallet__factory.ts +499 -0
- package/contracts/factories/index.ts +8 -0
- package/contracts/index.ts +14 -0
- package/nuxt.config.ts +18 -2
- package/package.json +17 -6
- package/server/utils/index.ts +2 -0
- package/utils/avocado.ts +2 -0
- package/utils/bignumber.ts +51 -0
- package/utils/formatter.ts +94 -0
- package/utils/helper.ts +62 -0
- package/utils/metadata.ts +536 -0
- package/utils/network.ts +235 -42
- package/utils/services.ts +21 -0
- package/utils/utils.d.ts +130 -14
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export function formatPercent(
|
|
2
|
+
value?: number | string,
|
|
3
|
+
fractionDigits = 2,
|
|
4
|
+
maxValue = null
|
|
5
|
+
) {
|
|
6
|
+
if (!value || isZero(value)) return "0.00%";
|
|
7
|
+
|
|
8
|
+
const valueAsNumber = toBN(value).toNumber();
|
|
9
|
+
|
|
10
|
+
if (maxValue && gt(times(valueAsNumber, "100"), maxValue))
|
|
11
|
+
return `>${maxValue}%`;
|
|
12
|
+
|
|
13
|
+
const formatter = new Intl.NumberFormat("en-US", {
|
|
14
|
+
style: "percent",
|
|
15
|
+
minimumFractionDigits: fractionDigits,
|
|
16
|
+
maximumFractionDigits: fractionDigits,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
return formatter.format(valueAsNumber);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function shortenHash(hash: string, length: number = 4) {
|
|
23
|
+
if (!hash) return;
|
|
24
|
+
if (hash.length < 12) return hash;
|
|
25
|
+
const beginningChars = hash.startsWith("0x") ? length + 2 : length;
|
|
26
|
+
const shortened =
|
|
27
|
+
hash.substr(0, beginningChars) + "..." + hash.substr(-length);
|
|
28
|
+
return shortened;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function formatUsd(value: any, fractionDigits = 2) {
|
|
32
|
+
const formatter = new Intl.NumberFormat("en-US", {
|
|
33
|
+
style: "currency",
|
|
34
|
+
currency: "USD",
|
|
35
|
+
minimumFractionDigits: fractionDigits,
|
|
36
|
+
maximumFractionDigits: fractionDigits,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return formatter.format(value);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function signedNumber(numb: string | number) {
|
|
43
|
+
return new Intl.NumberFormat("en-US", {
|
|
44
|
+
signDisplay: "exceptZero",
|
|
45
|
+
}).format(toBN(numb).toNumber());
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getFractionDigits(value: string | number) {
|
|
49
|
+
const absoluteValue = toBN(value).abs();
|
|
50
|
+
|
|
51
|
+
if (isZero(absoluteValue)) {
|
|
52
|
+
return 2;
|
|
53
|
+
} else if (lt(absoluteValue, 0.01)) {
|
|
54
|
+
return 6;
|
|
55
|
+
} else if (lt(absoluteValue, 1)) {
|
|
56
|
+
return 4;
|
|
57
|
+
} else if (lt(absoluteValue, 10000)) {
|
|
58
|
+
return 2;
|
|
59
|
+
} else {
|
|
60
|
+
return 0;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function formatDecimal(value: string | number, fractionDigits?: number) {
|
|
65
|
+
if (!value) {
|
|
66
|
+
value = "0";
|
|
67
|
+
}
|
|
68
|
+
if (lt(value, "0.0001") && gt(value, "0")) {
|
|
69
|
+
return "< 0.0001";
|
|
70
|
+
} else {
|
|
71
|
+
const num = toBN(value);
|
|
72
|
+
let decimals;
|
|
73
|
+
|
|
74
|
+
if (num.lt(1)) {
|
|
75
|
+
decimals = 4;
|
|
76
|
+
} else if (num.lt(10)) {
|
|
77
|
+
decimals = 6;
|
|
78
|
+
} else if (num.lt(100)) {
|
|
79
|
+
decimals = 4;
|
|
80
|
+
} else if (num.lt(1000)) {
|
|
81
|
+
decimals = 3;
|
|
82
|
+
} else if (num.lt(10000)) {
|
|
83
|
+
decimals = 2;
|
|
84
|
+
} else if (num.lt(100000)) {
|
|
85
|
+
decimals = 1;
|
|
86
|
+
} else {
|
|
87
|
+
decimals = 0;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const formattedNumber = num.toFixed(fractionDigits || decimals);
|
|
91
|
+
|
|
92
|
+
return toBN(formattedNumber).toFormat();
|
|
93
|
+
}
|
|
94
|
+
}
|
package/utils/helper.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export const indexSorter = (aIndex: number, bIndex: number) => {
|
|
2
|
+
if (aIndex === -1 && bIndex === -1) {
|
|
3
|
+
return 0; // fallback to other sorting criteria
|
|
4
|
+
} else if (aIndex === -1) {
|
|
5
|
+
return 1; // b comes first if a is not in the priority list
|
|
6
|
+
} else if (bIndex === -1) {
|
|
7
|
+
return -1; // a comes first if b is not in the priority list
|
|
8
|
+
} else {
|
|
9
|
+
return aIndex - bIndex; // sort by the index in the priority list
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function sortByMany<T>(
|
|
14
|
+
items: T[],
|
|
15
|
+
callback: ((a: T, b: T) => number)[]
|
|
16
|
+
) {
|
|
17
|
+
return items.sort(function (a, b) {
|
|
18
|
+
var result = 0;
|
|
19
|
+
for (var i = 0; i < callback.length; i++) {
|
|
20
|
+
var func = callback[i];
|
|
21
|
+
result = func(a, b);
|
|
22
|
+
if (result !== 0) {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function cloneDeep<T>(value: T): T {
|
|
31
|
+
return JSON.parse(JSON.stringify(value));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function filterArray(array: any, filters: any) {
|
|
35
|
+
const filterKeys = Object.keys(filters);
|
|
36
|
+
return array.filter((item: any) => {
|
|
37
|
+
// validates all filter criteria
|
|
38
|
+
return filterKeys.every((key) => {
|
|
39
|
+
// ignores non-function predicates
|
|
40
|
+
if (typeof filters[key] !== "function") return true;
|
|
41
|
+
return filters[key](item[key], item);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function onImageError(this: HTMLImageElement) {
|
|
47
|
+
const parentElement = this.parentElement;
|
|
48
|
+
this.onerror = null;
|
|
49
|
+
this.remove();
|
|
50
|
+
|
|
51
|
+
if (parentElement) {
|
|
52
|
+
parentElement.classList.add("bg-gray-300");
|
|
53
|
+
}
|
|
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
|
+
|
|
@@ -0,0 +1,536 @@
|
|
|
1
|
+
import { ethers, utils } from "ethers";
|
|
2
|
+
import { Forwarder__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;
|
|
21
|
+
|
|
22
|
+
const multiMetadataTypes = ["bytes[]"];
|
|
23
|
+
|
|
24
|
+
const metadataTypes = ["bytes32 type", "uint8 version", "bytes data"];
|
|
25
|
+
|
|
26
|
+
const actionMetadataTypes: Record<MetadataTypes, string[]> = {
|
|
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
|
+
],
|
|
35
|
+
bridge: [
|
|
36
|
+
"uint256 amount",
|
|
37
|
+
"address receiver",
|
|
38
|
+
"address fromToken",
|
|
39
|
+
"address toToken",
|
|
40
|
+
"uint256 toChainId",
|
|
41
|
+
"uint256 bridgeFee",
|
|
42
|
+
"address nativeToken",
|
|
43
|
+
],
|
|
44
|
+
swap: [
|
|
45
|
+
"address sellToken",
|
|
46
|
+
"address buyToken",
|
|
47
|
+
"uint256 sellAmount",
|
|
48
|
+
"uint256 buyAmount",
|
|
49
|
+
"address receiver",
|
|
50
|
+
"bytes32 protocol",
|
|
51
|
+
],
|
|
52
|
+
"gas-topup": ["uint256 amount", "address token", "address onBehalf"],
|
|
53
|
+
upgrade: ["bytes32 version", "address walletImpl"],
|
|
54
|
+
dapp: ["string name", "string url"],
|
|
55
|
+
auth: ["address address", "uint256 chainId", "bool remove"],
|
|
56
|
+
deploy: [],
|
|
57
|
+
permit2: [
|
|
58
|
+
"address token",
|
|
59
|
+
"address spender",
|
|
60
|
+
"uint160 amount",
|
|
61
|
+
"uint48 expiration",
|
|
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'],
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const encodeMetadata = (props: MetadataProps) => {
|
|
71
|
+
return ethers.utils.defaultAbiCoder.encode(metadataTypes, [
|
|
72
|
+
ethers.utils.formatBytes32String(props.type),
|
|
73
|
+
props.version || "1",
|
|
74
|
+
props.encodedData,
|
|
75
|
+
]);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export const encodeDappMetadata = (
|
|
79
|
+
params: DappMetadataProps,
|
|
80
|
+
single = true
|
|
81
|
+
) => {
|
|
82
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
83
|
+
actionMetadataTypes.dapp,
|
|
84
|
+
[params.name, params.url]
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const data = encodeMetadata({
|
|
88
|
+
type: MetadataEnums.dapp,
|
|
89
|
+
encodedData,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
return single ? encodeMultipleActions(data) : data;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export const encodeTransferMetadata = (
|
|
96
|
+
params: SendMetadataProps,
|
|
97
|
+
single = true
|
|
98
|
+
) => {
|
|
99
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
100
|
+
actionMetadataTypes.transfer,
|
|
101
|
+
[params.token, params.amount, params.receiver]
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const data = encodeMetadata({
|
|
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,
|
|
160
|
+
encodedData,
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
return single ? encodeMultipleActions(data) : data;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export const encodeDeployMetadata = (single = true) => {
|
|
167
|
+
const data = encodeMetadata({
|
|
168
|
+
type: MetadataEnums.deploy,
|
|
169
|
+
encodedData: "0x",
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
return single ? encodeMultipleActions(data) : data;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export const encodeWCSignMetadata = (
|
|
176
|
+
params: SignMetadataProps,
|
|
177
|
+
single = true
|
|
178
|
+
) => {
|
|
179
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
180
|
+
actionMetadataTypes["permit2"],
|
|
181
|
+
[params.token, params.spender, params.amount, params.expiration]
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
const data = encodeMetadata({
|
|
185
|
+
type: MetadataEnums.permit2,
|
|
186
|
+
encodedData,
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
return single ? encodeMultipleActions(data) : data;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export const encodeUpgradeMetadata = (
|
|
193
|
+
params: UpgradeMetadataProps,
|
|
194
|
+
single = true
|
|
195
|
+
) => {
|
|
196
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
197
|
+
actionMetadataTypes.upgrade,
|
|
198
|
+
[params.version, params.walletImpl]
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
const data = encodeMetadata({
|
|
202
|
+
type: MetadataEnums.upgrade,
|
|
203
|
+
encodedData,
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
return single ? encodeMultipleActions(data) : data;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
export const encodeSwapMetadata = (
|
|
210
|
+
params: SwapMetadataProps,
|
|
211
|
+
single = true
|
|
212
|
+
) => {
|
|
213
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
214
|
+
actionMetadataTypes.swap,
|
|
215
|
+
[
|
|
216
|
+
params.sellToken,
|
|
217
|
+
params.buyToken,
|
|
218
|
+
params.sellAmount,
|
|
219
|
+
params.buyAmount,
|
|
220
|
+
params.receiver,
|
|
221
|
+
params.protocol,
|
|
222
|
+
]
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
const data = encodeMetadata({
|
|
226
|
+
type: MetadataEnums.swap,
|
|
227
|
+
encodedData,
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
return single ? encodeMultipleActions(data) : data;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
export const encodeTopupMetadata = (
|
|
234
|
+
params: TopupMetadataProps,
|
|
235
|
+
single = true
|
|
236
|
+
) => {
|
|
237
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
238
|
+
actionMetadataTypes["gas-topup"],
|
|
239
|
+
[params.amount, params.token, params.onBehalf]
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
const data = encodeMetadata({
|
|
243
|
+
type: MetadataEnums["gas-topup"],
|
|
244
|
+
encodedData,
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
return single ? encodeMultipleActions(data) : data;
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
export const encodeBridgeMetadata = (
|
|
251
|
+
params: BridgeMetadataProps,
|
|
252
|
+
single = true
|
|
253
|
+
) => {
|
|
254
|
+
const encodedData = ethers.utils.defaultAbiCoder.encode(
|
|
255
|
+
actionMetadataTypes.bridge,
|
|
256
|
+
[
|
|
257
|
+
params.amount,
|
|
258
|
+
params.receiver,
|
|
259
|
+
params.fromToken,
|
|
260
|
+
params.toToken,
|
|
261
|
+
params.toChainId,
|
|
262
|
+
params.bridgeFee,
|
|
263
|
+
params.nativeToken,
|
|
264
|
+
]
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
const data = encodeMetadata({
|
|
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"],
|
|
320
|
+
encodedData,
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
return single ? encodeMultipleActions(data) : data;
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
export const encodeMultipleActions = (...actionData: string[]) => {
|
|
327
|
+
return ethers.utils.defaultAbiCoder.encode(multiMetadataTypes, [actionData]);
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
export const decodeData = (data: string) => {
|
|
331
|
+
try {
|
|
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 getMetadataFromData = (data: string) => {
|
|
350
|
+
const iface = Forwarder__factory.createInterface();
|
|
351
|
+
let metadata = "0x";
|
|
352
|
+
|
|
353
|
+
if (data.startsWith("0x18e7f485")) {
|
|
354
|
+
const executeData = iface.decodeFunctionData("execute", data);
|
|
355
|
+
if (executeData.metadata_ === "0x" || !executeData.metadata_) {
|
|
356
|
+
return null;
|
|
357
|
+
} else {
|
|
358
|
+
metadata = executeData.metadata_;
|
|
359
|
+
}
|
|
360
|
+
} else if (data.startsWith("0x14f80a8d")) {
|
|
361
|
+
const executeDataV2 = iface.decodeFunctionData("executeV2", data);
|
|
362
|
+
if (
|
|
363
|
+
executeDataV2.params_.metadata === "0x" ||
|
|
364
|
+
!executeDataV2.params_.metadata
|
|
365
|
+
) {
|
|
366
|
+
return null;
|
|
367
|
+
} else {
|
|
368
|
+
metadata = executeDataV2.params_.metadata;
|
|
369
|
+
}
|
|
370
|
+
} else if (data.startsWith("0x85114d53")) {
|
|
371
|
+
const executeDataV3 = iface.decodeFunctionData("executeV3", data);
|
|
372
|
+
if (
|
|
373
|
+
executeDataV3.params_.metadata === "0x" ||
|
|
374
|
+
!executeDataV3.params_.metadata
|
|
375
|
+
) {
|
|
376
|
+
return null;
|
|
377
|
+
} else {
|
|
378
|
+
metadata = executeDataV3.params_.metadata;
|
|
379
|
+
}
|
|
380
|
+
} else {
|
|
381
|
+
const executeDataMultisigV3 = iface.decodeFunctionData(
|
|
382
|
+
"executeMultisigV3",
|
|
383
|
+
data
|
|
384
|
+
);
|
|
385
|
+
if (
|
|
386
|
+
executeDataMultisigV3.params_.metadata === "0x" ||
|
|
387
|
+
!executeDataMultisigV3.params_.metadata
|
|
388
|
+
) {
|
|
389
|
+
return null;
|
|
390
|
+
} else {
|
|
391
|
+
metadata = executeDataMultisigV3.params_.metadata;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return metadata;
|
|
396
|
+
};
|
|
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
|
+
|
|
486
|
+
const parseMetadata = (metadata: string) => {
|
|
487
|
+
const metadataArr = [];
|
|
488
|
+
|
|
489
|
+
const [decodedMultiMetadata = []] =
|
|
490
|
+
(ethers.utils.defaultAbiCoder.decode(
|
|
491
|
+
multiMetadataTypes,
|
|
492
|
+
metadata
|
|
493
|
+
) as string[]) || [];
|
|
494
|
+
|
|
495
|
+
for (let metadata of decodedMultiMetadata) {
|
|
496
|
+
const decodedMetadata = ethers.utils.defaultAbiCoder.decode(
|
|
497
|
+
metadataTypes,
|
|
498
|
+
metadata
|
|
499
|
+
);
|
|
500
|
+
|
|
501
|
+
const type = ethers.utils.parseBytes32String(
|
|
502
|
+
decodedMetadata.type
|
|
503
|
+
) as keyof typeof actionMetadataTypes;
|
|
504
|
+
|
|
505
|
+
const decodedData = ethers.utils.defaultAbiCoder.decode(
|
|
506
|
+
actionMetadataTypes[type],
|
|
507
|
+
decodedMetadata.data
|
|
508
|
+
);
|
|
509
|
+
|
|
510
|
+
const payloadFunc = typesPayload[type]
|
|
511
|
+
|
|
512
|
+
if (payloadFunc) {
|
|
513
|
+
const payload = payloadFunc(decodedData, type)
|
|
514
|
+
metadataArr.push(payload);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
return metadataArr;
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Replaces hyphens with spaces and capitalizes the first letter of each word in a sentence.
|
|
526
|
+
* @param {string} txType - The input sentence to modify
|
|
527
|
+
*
|
|
528
|
+
* @returns {string} - The modified sentence with hyphens replaced with spaces and the first letter of each word capitalized.
|
|
529
|
+
*/
|
|
530
|
+
export const formatTxType = (txType: string) => {
|
|
531
|
+
const finalSentence = txType
|
|
532
|
+
.replace("-", " ")
|
|
533
|
+
.replace(/(^\w{1})|(\s+\w{1})/g, (letter) => letter.toUpperCase());
|
|
534
|
+
|
|
535
|
+
return finalSentence;
|
|
536
|
+
};
|