@cfxjs/sirius-next-common 0.3.3 → 0.3.4

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useDecodeFunctionData
3
- } from "./chunk-ZWZMVVVB.js";
3
+ } from "./chunk-MJ44ZPJO.js";
4
4
  import {
5
5
  useDecodedDataType
6
6
  } from "./chunk-UM5J477V.js";
@@ -189,4 +189,4 @@ var TraceDetail = (props) => {
189
189
  export {
190
190
  TraceDetail
191
191
  };
192
- //# sourceMappingURL=chunk-4DX7CRRE.js.map
192
+ //# sourceMappingURL=chunk-IPACZ2LN.js.map
@@ -27,6 +27,7 @@ var decodeFunctionDataByAbi = ({
27
27
  withOutput = false,
28
28
  similarWarning
29
29
  }) => {
30
+ let abiItem = void 0;
30
31
  try {
31
32
  const abi = typeof _abi === "string" ? JSON.parse(_abi) : _abi;
32
33
  const hasAbi = abi && abi.length > 0;
@@ -34,21 +35,21 @@ var decodeFunctionDataByAbi = ({
34
35
  return null;
35
36
  const isReturnDataEmpty = !output || output === "0x";
36
37
  const methodID = input.slice(0, 10);
38
+ abiItem = getAbiItem({
39
+ abi,
40
+ name: methodID
41
+ });
37
42
  const decodedParams = decodeFunctionData({
38
43
  abi,
39
44
  data: input,
40
45
  space
41
46
  });
42
- let decodedResults = success ? !isReturnDataEmpty ? decodeFunctionResult({
47
+ const decodedResults = success ? !isReturnDataEmpty ? decodeFunctionResult({
43
48
  abi,
44
49
  functionName: methodID,
45
50
  data: output,
46
51
  space
47
52
  }) : void 0 : output;
48
- const abiItem = getAbiItem({
49
- abi,
50
- name: methodID
51
- });
52
53
  const results = decodedResults === void 0 ? void 0 : abiItem.outputs.length === 1 ? [decodedResults] : decodedResults;
53
54
  if (!withOutput) {
54
55
  abiItem.outputs = [];
@@ -64,8 +65,14 @@ var decodeFunctionDataByAbi = ({
64
65
  };
65
66
  } catch (error) {
66
67
  console.log("decode function data and result error", error);
68
+ if (!withOutput && abiItem) {
69
+ abiItem.outputs = [];
70
+ }
71
+ const fullName = abiItem ? formatABI([abiItem])[0] : void 0;
67
72
  return {
68
73
  failed: true,
74
+ abiItem,
75
+ fullName,
69
76
  similarWarning
70
77
  };
71
78
  }
@@ -171,13 +178,9 @@ var useDecodeFunctionData = ({
171
178
  if (implementationLoading || contractLoading || methodAbiLoading) {
172
179
  return [{}, true];
173
180
  }
174
- if (decodedByOuterAbi && decodedByOuterAbi.failed || decodedByImplementationAbi && decodedByImplementationAbi.failed || decodedByContractAbi && decodedByContractAbi.failed || decodedByMethodAbi && decodedByMethodAbi.failed) {
175
- return [
176
- {
177
- failed: true
178
- },
179
- false
180
- ];
181
+ const decoded = decodedByOuterAbi || decodedByImplementationAbi || decodedByContractAbi || decodedByMethodAbi;
182
+ if (decoded) {
183
+ return [decoded, false];
181
184
  }
182
185
  return [
183
186
  {
@@ -200,4 +203,4 @@ var useDecodeFunctionData = ({
200
203
  export {
201
204
  useDecodeFunctionData
202
205
  };
203
- //# sourceMappingURL=chunk-ZWZMVVVB.js.map
206
+ //# sourceMappingURL=chunk-MJ44ZPJO.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/hooks/useDecodeFunctionData.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport {\n decodeFunctionData,\n decodeFunctionResult,\n getAbiItem,\n AbiFunctionWithoutGas,\n} from 'src/utils/sdk';\nimport { useContractDetail } from './useContractDetail';\nimport { formatABI } from '..';\nimport { useMethodAbi } from './useMethodAbi';\nimport { Hex } from '../types';\n\nconst fields = ['abi' as const];\n\nconst decodeFunctionDataByAbi = ({\n abi: _abi,\n input,\n output,\n space,\n success,\n withOutput = false,\n similarWarning,\n}: {\n input: Hex;\n output?: Hex;\n abi?: AbiFunctionWithoutGas[] | string;\n space: 'evm' | 'core';\n success?: boolean;\n withOutput?: boolean;\n similarWarning?: boolean;\n}) => {\n let abiItem: AbiFunctionWithoutGas | undefined = undefined;\n try {\n const abi = typeof _abi === 'string' ? JSON.parse(_abi) : _abi;\n const hasAbi = abi && abi.length > 0;\n if (!hasAbi) return null;\n const isReturnDataEmpty = !output || output === '0x';\n const methodID = input.slice(0, 10);\n abiItem = getAbiItem({\n abi: abi,\n name: methodID,\n }) as AbiFunctionWithoutGas;\n const decodedParams = decodeFunctionData({\n abi: abi,\n data: input,\n space,\n });\n const decodedResults = success\n ? !isReturnDataEmpty\n ? decodeFunctionResult({\n abi: abi,\n functionName: methodID,\n data: output,\n space,\n })\n : undefined\n : output;\n // if the output has only one value, decodeFunctionResult will return the value directly, otherwise it will return an array,\n // so we need to check the length of abiItem.outputs to determine whether to wrap decodedResults in an array\n const results =\n decodedResults === undefined\n ? undefined\n : abiItem.outputs.length === 1\n ? [decodedResults]\n : (decodedResults as unknown[]);\n if (!withOutput) {\n abiItem.outputs = [];\n }\n const fullName = formatABI([abiItem])[0];\n return {\n decodedParams,\n decodedResults: results,\n abiItem,\n fullName: fullName,\n failed: false,\n similarWarning,\n };\n } catch (error) {\n console.log('decode function data and result error', error);\n if (!withOutput && abiItem) {\n abiItem.outputs = [];\n }\n const fullName = abiItem ? formatABI([abiItem])[0] : undefined;\n return {\n failed: true,\n abiItem,\n fullName,\n similarWarning,\n };\n }\n};\n\nexport interface DecodedFunctionData {\n decodedParams?: {\n args: readonly unknown[] | undefined;\n functionName: string;\n };\n decodedResults?: unknown[];\n abiItem?: AbiFunctionWithoutGas;\n fullName?: string;\n // no abi for decoded\n noAbi?: boolean;\n // decoded failed\n failed?: boolean;\n // decoded by method abi, not contract abi\n similarWarning?: boolean;\n}\n\nexport const useDecodeFunctionData = ({\n to,\n abi: outerAbi,\n implementation: _implementation,\n input = '0x',\n output,\n space,\n success,\n supportMethodAbi = false,\n withOutput,\n}: {\n input?: Hex;\n output?: Hex;\n to?: string;\n implementation?: string;\n abi?: AbiFunctionWithoutGas[];\n space: 'evm' | 'core';\n success?: boolean;\n supportMethodAbi?: boolean;\n withOutput?: boolean;\n}): [DecodedFunctionData, boolean] => {\n const hasOuterAbi = outerAbi && outerAbi.length > 0;\n const isDataEmpty = !input || input === '0x';\n const needContractAbi = !hasOuterAbi && !isDataEmpty;\n const { data: contractData, isLoading: contractLoading } = useContractDetail(\n to,\n fields,\n needContractAbi,\n );\n const implementation =\n _implementation ?? contractData?.implementation?.address;\n const { data: implementationData, isLoading: implementationLoading } =\n useContractDetail(implementation, fields, needContractAbi);\n const decodedByOuterAbi = useMemo(() => {\n return decodeFunctionDataByAbi({\n abi: outerAbi,\n input,\n output,\n space,\n success,\n withOutput,\n });\n }, [input, output, outerAbi, success, space, withOutput]);\n const decodedByContractAbi = useMemo(() => {\n if (!contractData?.abi) return null;\n return decodeFunctionDataByAbi({\n abi: contractData.abi as string,\n input,\n output,\n space,\n success,\n withOutput,\n });\n }, [input, output, contractData?.abi, success, space, withOutput]);\n const decodedByImplementationAbi = useMemo(() => {\n if (!implementationData?.abi) return null;\n return decodeFunctionDataByAbi({\n abi: implementationData.abi as string,\n input,\n output,\n space,\n success,\n withOutput,\n });\n }, [input, output, implementationData?.abi, success, space, withOutput]);\n const needMethodAbi =\n supportMethodAbi &&\n needContractAbi &&\n // contract abi decoded failed\n !contractLoading &&\n (!decodedByContractAbi || decodedByContractAbi.failed) &&\n // implementation contract abi decoded failed\n !implementationLoading &&\n (!decodedByImplementationAbi || decodedByImplementationAbi.failed);\n const { data: methodAbi, isLoading: methodAbiLoading } = useMethodAbi(\n input.slice(0, 10),\n needMethodAbi,\n );\n const decodedByMethodAbi = useMemo(() => {\n // decode tx data with function abi only if there is only one function\n if (!methodAbi || methodAbi.list.length !== 1) return null;\n try {\n // e.g. transfer(address,uint256)\n const fullName = methodAbi.list[0]!.fullName;\n // e.g. function transfer(address recipient, uint256 amount) returns (bool)\n const formatWithArg = methodAbi.list[0]!.formatWithArg;\n const abi = formatABI([formatWithArg || `function ${fullName}`], {\n json: true,\n });\n return decodeFunctionDataByAbi({\n abi: abi,\n input,\n output,\n space,\n success,\n withOutput,\n similarWarning: true,\n });\n } catch (error) {\n console.log('decode function data and result error', error);\n return {\n failed: true,\n };\n }\n }, [input, output, methodAbi, success, space, withOutput]);\n\n return useMemo(() => {\n if (!input) return [{}, false];\n if (decodedByOuterAbi && !decodedByOuterAbi.failed)\n return [decodedByOuterAbi, false];\n if (decodedByImplementationAbi && !decodedByImplementationAbi.failed)\n return [decodedByImplementationAbi, implementationLoading];\n if (decodedByContractAbi && !decodedByContractAbi.failed)\n return [decodedByContractAbi, contractLoading];\n if (decodedByMethodAbi && !decodedByMethodAbi.failed)\n return [decodedByMethodAbi, methodAbiLoading];\n if (implementationLoading || contractLoading || methodAbiLoading) {\n return [{}, true];\n }\n const decoded =\n decodedByOuterAbi ||\n decodedByImplementationAbi ||\n decodedByContractAbi ||\n decodedByMethodAbi;\n if (decoded) {\n return [decoded, false];\n }\n return [\n {\n noAbi: true,\n },\n false,\n ];\n }, [\n input,\n decodedByOuterAbi,\n decodedByContractAbi,\n decodedByImplementationAbi,\n decodedByMethodAbi,\n contractLoading,\n implementationLoading,\n methodAbiLoading,\n ]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,SAAS,eAAe;AAYxB,IAAM,SAAS,CAAC,KAAc;AAE9B,IAAM,0BAA0B,CAAC;AAAA,EAC/B,KAAK;AAAA,EACL;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,aAAa;AAAA,EACb;AACF,MAQM;AACJ,MAAI,UAA6C;AACjD,MAAI;AACF,UAAM,MAAM,OAAO,SAAS,WAAW,KAAK,MAAM,IAAI,IAAI;AAC1D,UAAM,SAAS,OAAO,IAAI,SAAS;AACnC,QAAI,CAAC;AAAQ,aAAO;AACpB,UAAM,oBAAoB,CAAC,UAAU,WAAW;AAChD,UAAM,WAAW,MAAM,MAAM,GAAG,EAAE;AAClC,cAAU,WAAW;AAAA,MACnB;AAAA,MACA,MAAM;AAAA,IACR,CAAC;AACD,UAAM,gBAAgB,mBAAmB;AAAA,MACvC;AAAA,MACA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AC/D,MAAM;AAAA,MACR,CAAC;AACD,aAAO,wBAAwB;AAAA,QAC7B;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,gBAAgB;AAAA,MAClB,CAAC;AAAA,IACH,SAAS,OAAP;AACA,cAAQ,IAAI,yCAAyC,KAAK;AAC1D,aAAO;AAAA,QACL,QAAQ;AAAA,MACV;AAAA,IACF;AAAA,EACF,GAAG,CAAC,OAAO,QAAQ,WAAW,SAAS,OAAO,UAAU,CAAC;AAEzD,SAAO,QAAQ,MAAM;AACnB,QAAI,CAAC;AAAO,aAAO,CAAC,CAAC,GAAG,KAAK;AAC7B,QAAI,qBAAqB,CAAC,kBAAkB;AAC1C,aAAO,CAAC,mBAAmB,KAAK;AAClC,QAAI,8BAA8B,CAAC,2BAA2B;AAC5D,aAAO,CAAC,4BAA4B,qBAAqB;AAC3D,QAAI,wBAAwB,CAAC,qBAAqB;AAChD,aAAO,CAAC,sBAAsB,eAAe;AAC/C,QAAI,sBAAsB,CAAC,mBAAmB;AAC5C,aAAO,CAAC,oBAAoB,gBAAgB;AAC9C,QAAI,yBAAyB,mBAAmB,kBAAkB;AAChE,aAAO,CAAC,CAAC,GAAG,IAAI;AAAA,IAClB;AACA,UAAM,UACJ,qBACA,8BACA,wBACA;AACF,QAAI,SAAS;AACX,aAAO,CAAC,SAAS,KAAK;AAAA,IACxB;AACA,WAAO;AAAA,MACL;AAAA,QACE,OAAO;AAAA,MACT;AAAA,MACA;AAAA,IACF;AAAA,EACF,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  TraceDetail
3
- } from "./chunk-4DX7CRRE.js";
3
+ } from "./chunk-IPACZ2LN.js";
4
4
  import {
5
5
  Table
6
6
  } from "./chunk-4WLXG7ZY.js";
@@ -81,4 +81,4 @@ var TreeTraceTable = ({
81
81
  export {
82
82
  TreeTraceTable
83
83
  };
84
- //# sourceMappingURL=chunk-NUKWAN7M.js.map
84
+ //# sourceMappingURL=chunk-Z2SG6IVF.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  TraceDetail
3
- } from "../../chunk-4DX7CRRE.js";
4
- import "../../chunk-ZWZMVVVB.js";
3
+ } from "../../chunk-IPACZ2LN.js";
4
+ import "../../chunk-MJ44ZPJO.js";
5
5
  import "../../chunk-UM5J477V.js";
6
6
  import "../../chunk-UARYZ4C2.js";
7
7
  import "../../chunk-XBQLSMRE.js";
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  TreeTraceTable
3
- } from "../../chunk-NUKWAN7M.js";
4
- import "../../chunk-4DX7CRRE.js";
5
- import "../../chunk-ZWZMVVVB.js";
3
+ } from "../../chunk-Z2SG6IVF.js";
4
+ import "../../chunk-IPACZ2LN.js";
5
+ import "../../chunk-MJ44ZPJO.js";
6
6
  import "../../chunk-UM5J477V.js";
7
7
  import "../../chunk-UARYZ4C2.js";
8
8
  import "../../chunk-4WLXG7ZY.js";
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  TreeTraceTable
3
- } from "../../chunk-NUKWAN7M.js";
3
+ } from "../../chunk-Z2SG6IVF.js";
4
4
  import {
5
5
  TraceDetail
6
- } from "../../chunk-4DX7CRRE.js";
7
- import "../../chunk-ZWZMVVVB.js";
6
+ } from "../../chunk-IPACZ2LN.js";
7
+ import "../../chunk-MJ44ZPJO.js";
8
8
  import "../../chunk-UM5J477V.js";
9
9
  import "../../chunk-UARYZ4C2.js";
10
10
  import "../../chunk-4WLXG7ZY.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useDecodeFunctionData
3
- } from "../../chunk-ZWZMVVVB.js";
3
+ } from "../../chunk-MJ44ZPJO.js";
4
4
  import "../../chunk-UARYZ4C2.js";
5
5
  import "../../chunk-FYDF5QZ6.js";
6
6
  import "../../chunk-XN2TDIIK.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfxjs/sirius-next-common",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist/**"
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils/hooks/useDecodeFunctionData.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport {\n decodeFunctionData,\n decodeFunctionResult,\n getAbiItem,\n AbiFunctionWithoutGas,\n} from 'src/utils/sdk';\nimport { useContractDetail } from './useContractDetail';\nimport { formatABI } from '..';\nimport { useMethodAbi } from './useMethodAbi';\nimport { Hex } from '../types';\n\nconst fields = ['abi' as const];\n\nconst decodeFunctionDataByAbi = ({\n abi: _abi,\n input,\n output,\n space,\n success,\n withOutput = false,\n similarWarning,\n}: {\n input: Hex;\n output?: Hex;\n abi?: AbiFunctionWithoutGas[] | string;\n space: 'evm' | 'core';\n success?: boolean;\n withOutput?: boolean;\n similarWarning?: boolean;\n}) => {\n try {\n const abi = typeof _abi === 'string' ? JSON.parse(_abi) : _abi;\n const hasAbi = abi && abi.length > 0;\n if (!hasAbi) return null;\n const isReturnDataEmpty = !output || output === '0x';\n const methodID = input.slice(0, 10);\n const decodedParams = decodeFunctionData({\n abi: abi,\n data: input,\n space,\n });\n let decodedResults = success\n ? !isReturnDataEmpty\n ? decodeFunctionResult({\n abi: abi,\n functionName: methodID,\n data: output,\n space,\n })\n : undefined\n : output;\n const abiItem = getAbiItem({\n abi: abi,\n name: methodID,\n }) as AbiFunctionWithoutGas;\n // if the output has only one value, decodeFunctionResult will return the value directly, otherwise it will return an array,\n // so we need to check the length of abiItem.outputs to determine whether to wrap decodedResults in an array\n const results =\n decodedResults === undefined\n ? undefined\n : abiItem.outputs.length === 1\n ? [decodedResults]\n : (decodedResults as unknown[]);\n if (!withOutput) {\n abiItem.outputs = [];\n }\n const fullName = formatABI([abiItem])[0];\n return {\n decodedParams,\n decodedResults: results,\n abiItem,\n fullName: fullName,\n failed: false,\n similarWarning,\n };\n } catch (error) {\n console.log('decode function data and result error', error);\n return {\n failed: true,\n similarWarning,\n };\n }\n};\n\nexport interface DecodedFunctionData {\n decodedParams?: {\n args: readonly unknown[] | undefined;\n functionName: string;\n };\n decodedResults?: unknown[];\n abiItem?: AbiFunctionWithoutGas;\n fullName?: string;\n // no abi for decoded\n noAbi?: boolean;\n // decoded failed\n failed?: boolean;\n // decoded by method abi, not contract abi\n similarWarning?: boolean;\n}\n\nexport const useDecodeFunctionData = ({\n to,\n abi: outerAbi,\n implementation: _implementation,\n input = '0x',\n output,\n space,\n success,\n supportMethodAbi = false,\n withOutput,\n}: {\n input?: Hex;\n output?: Hex;\n to?: string;\n implementation?: string;\n abi?: AbiFunctionWithoutGas[];\n space: 'evm' | 'core';\n success?: boolean;\n supportMethodAbi?: boolean;\n withOutput?: boolean;\n}): [DecodedFunctionData, boolean] => {\n const hasOuterAbi = outerAbi && outerAbi.length > 0;\n const isDataEmpty = !input || input === '0x';\n const needContractAbi = !hasOuterAbi && !isDataEmpty;\n const { data: contractData, isLoading: contractLoading } = useContractDetail(\n to,\n fields,\n needContractAbi,\n );\n const implementation =\n _implementation ?? contractData?.implementation?.address;\n const { data: implementationData, isLoading: implementationLoading } =\n useContractDetail(implementation, fields, needContractAbi);\n const decodedByOuterAbi = useMemo(() => {\n return decodeFunctionDataByAbi({\n abi: outerAbi,\n input,\n output,\n space,\n success,\n withOutput,\n });\n }, [input, output, outerAbi, success, space, withOutput]);\n const decodedByContractAbi = useMemo(() => {\n if (!contractData?.abi) return null;\n return decodeFunctionDataByAbi({\n abi: contractData.abi as string,\n input,\n output,\n space,\n success,\n withOutput,\n });\n }, [input, output, contractData?.abi, success, space, withOutput]);\n const decodedByImplementationAbi = useMemo(() => {\n if (!implementationData?.abi) return null;\n return decodeFunctionDataByAbi({\n abi: implementationData.abi as string,\n input,\n output,\n space,\n success,\n withOutput,\n });\n }, [input, output, implementationData?.abi, success, space, withOutput]);\n const needMethodAbi =\n supportMethodAbi &&\n needContractAbi &&\n // contract abi decoded failed\n !contractLoading &&\n (!decodedByContractAbi || decodedByContractAbi.failed) &&\n // implementation contract abi decoded failed\n !implementationLoading &&\n (!decodedByImplementationAbi || decodedByImplementationAbi.failed);\n const { data: methodAbi, isLoading: methodAbiLoading } = useMethodAbi(\n input.slice(0, 10),\n needMethodAbi,\n );\n const decodedByMethodAbi = useMemo(() => {\n // decode tx data with function abi only if there is only one function\n if (!methodAbi || methodAbi.list.length !== 1) return null;\n try {\n // e.g. transfer(address,uint256)\n const fullName = methodAbi.list[0]!.fullName;\n // e.g. function transfer(address recipient, uint256 amount) returns (bool)\n const formatWithArg = methodAbi.list[0]!.formatWithArg;\n const abi = formatABI([formatWithArg || `function ${fullName}`], {\n json: true,\n });\n return decodeFunctionDataByAbi({\n abi: abi,\n input,\n output,\n space,\n success,\n withOutput,\n similarWarning: true,\n });\n } catch (error) {\n console.log('decode function data and result error', error);\n return {\n failed: true,\n };\n }\n }, [input, output, methodAbi, success, space, withOutput]);\n\n return useMemo(() => {\n if (!input) return [{}, false];\n if (decodedByOuterAbi && !decodedByOuterAbi.failed)\n return [decodedByOuterAbi, false];\n if (decodedByImplementationAbi && !decodedByImplementationAbi.failed)\n return [decodedByImplementationAbi, implementationLoading];\n if (decodedByContractAbi && !decodedByContractAbi.failed)\n return [decodedByContractAbi, contractLoading];\n if (decodedByMethodAbi && !decodedByMethodAbi.failed)\n return [decodedByMethodAbi, methodAbiLoading];\n if (implementationLoading || contractLoading || methodAbiLoading) {\n return [{}, true];\n }\n if (\n (decodedByOuterAbi && decodedByOuterAbi.failed) ||\n (decodedByImplementationAbi && decodedByImplementationAbi.failed) ||\n (decodedByContractAbi && decodedByContractAbi.failed) ||\n (decodedByMethodAbi && decodedByMethodAbi.failed)\n ) {\n return [\n {\n failed: true,\n },\n false,\n ];\n }\n return [\n {\n noAbi: true,\n },\n false,\n ];\n }, [\n input,\n decodedByOuterAbi,\n decodedByContractAbi,\n decodedByImplementationAbi,\n decodedByMethodAbi,\n contractLoading,\n implementationLoading,\n methodAbiLoading,\n ]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,SAAS,eAAe;AAYxB,IAAM,SAAS,CAAC,KAAc;AAE9B,IAAM,0BAA0B,CAAC;AAAA,EAC/B,KAAK;AAAA,EACL;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,aAAa;AAAA,EACb;AACF,MAQM;AACJ,MAAI;AACF,UAAM,MAAM,OAAO,SAAS,WAAW,KAAK,MAAM,IAAI,IAAI;AAC1D,UAAM,SAAS,OAAO,IAAI,SAAS;AACnC,QAAI,CAAC;AAAQ,aAAO;AACpB,UAAM,oBAAoB,CAAC,UAAU,WAAW;AAChD,UAAM,WAAW,MAAM,MAAM,GAAG,EAAE;AAClC,UAAM,gBAAgB,mBAAmB;AAAA,MACvC;AAAA,MACA,MAAM;AAAA,MACN;AAAA,IACF,CAAC;AACD,QAAI,iBAAiB,UACjB,CAAC,oBACC,qBAAqB;AAAA,MACnB;AAAA,MACA,cAAc;AAAA,MACd,MAAM;AAAA,MACN;AAAA,IACF,CAAC,IACD,SACF;AACJ,UAAM,UAAU,WAAW;AAAA,MACzB;AAAA,MACA,MAAM;AAAA,IACR,CAAC;AAGD,UAAM,UACJ,mBAAmB,SACf,SACA,QAAQ,QAAQ,WAAW,IACzB,CAAC,cAAc,IACd;AACT,QAAI,CAAC,YAAY;AACf,cAAQ,UAAU,CAAC;AAAA,IACrB;AACA,UAAM,WAAW,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;AACvC,WAAO;AAAA,MACL;AAAA,MACA,gBAAgB;AAAA,MAChB;AAAA,MACA;AAAA,MACA,QAAQ;AAAA,MACR;AAAA,IACF;AAAA,EACF,SAAS,OAAP;AACA,YAAQ,IAAI,yCAAyC,KAAK;AAC1D,WAAO;AAAA,MACL,QAAQ;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;AAkBO,IAAM,wBAAwB,CAAC;A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