@openzeppelin/ui-builder-adapter-evm 1.2.0 → 1.4.0

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.
Files changed (105) hide show
  1. package/README.md +33 -18
  2. package/dist/index.cjs +4651 -4448
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +12 -226
  5. package/dist/index.d.ts +12 -226
  6. package/dist/index.js +4737 -4535
  7. package/dist/index.js.map +1 -1
  8. package/package.json +7 -6
  9. package/src/__tests__/adapter-parsing.test.ts +4 -3
  10. package/src/__tests__/getDefaultServiceConfig.test.ts +185 -0
  11. package/src/__tests__/mocks/mock-network-configs.ts +1 -1
  12. package/src/__tests__/provenanceLinks.test.ts +6 -4
  13. package/src/__tests__/providerSelection.test.ts +5 -4
  14. package/src/__tests__/timeouts.test.ts +5 -3
  15. package/src/__tests__/wallet-connect.test.ts +2 -2
  16. package/src/adapter.ts +61 -107
  17. package/src/configuration/execution.ts +1 -52
  18. package/src/configuration/index.ts +2 -3
  19. package/src/configuration/network-services.ts +47 -60
  20. package/src/index.ts +22 -13
  21. package/src/networks/index.ts +2 -1
  22. package/src/networks/mainnet.ts +1 -1
  23. package/src/networks/testnet.ts +1 -1
  24. package/src/query/adapter-query.ts +72 -0
  25. package/src/query/index.ts +2 -2
  26. package/src/transaction/components/useEvmRelayerOptions.ts +5 -3
  27. package/src/transaction/index.ts +1 -5
  28. package/src/types/artifacts.ts +5 -30
  29. package/src/types/providers.ts +7 -18
  30. package/src/wallet/components/EvmWalletUiRoot.tsx +1 -1
  31. package/src/wallet/evmUiKitManager.ts +26 -129
  32. package/src/wallet/hooks/index.ts +0 -1
  33. package/src/wallet/implementation/wagmi-implementation.ts +45 -577
  34. package/src/wallet/index.ts +2 -3
  35. package/src/wallet/rainbowkit/__tests__/export-service.test.ts +1 -2
  36. package/src/wallet/rainbowkit/componentFactory.ts +10 -8
  37. package/src/wallet/rainbowkit/components.tsx +16 -133
  38. package/src/wallet/rainbowkit/index.ts +27 -5
  39. package/src/wallet/utils/__tests__/uiKitService.test.ts +5 -1
  40. package/src/wallet/utils/connection.ts +8 -52
  41. package/src/wallet/utils/index.ts +0 -2
  42. package/src/wallet/utils/uiKitService.ts +7 -3
  43. package/src/wallet/utils/walletImplementationManager.ts +5 -4
  44. package/src/wallet/utils.ts +1 -65
  45. package/src/abi/__tests__/etherscan-v2.test.ts +0 -117
  46. package/src/abi/__tests__/transformer.test.ts +0 -342
  47. package/src/abi/comparison.ts +0 -389
  48. package/src/abi/etherscan-v2.ts +0 -243
  49. package/src/abi/etherscan.ts +0 -158
  50. package/src/abi/index.ts +0 -7
  51. package/src/abi/loader.ts +0 -415
  52. package/src/abi/sourcify.ts +0 -75
  53. package/src/abi/transformer.ts +0 -163
  54. package/src/abi/types.ts +0 -101
  55. package/src/configuration/__tests__/explorer.test.ts +0 -174
  56. package/src/configuration/__tests__/rpc.test.ts +0 -176
  57. package/src/configuration/explorer.ts +0 -243
  58. package/src/configuration/rpc.ts +0 -257
  59. package/src/mapping/__tests__/field-generator.test.ts +0 -137
  60. package/src/mapping/__tests__/type-mapper.test.ts +0 -139
  61. package/src/mapping/constants.ts +0 -57
  62. package/src/mapping/field-generator.ts +0 -115
  63. package/src/mapping/index.ts +0 -4
  64. package/src/mapping/type-mapper.ts +0 -80
  65. package/src/proxy/detection.ts +0 -465
  66. package/src/query/handler.ts +0 -227
  67. package/src/query/view-checker.ts +0 -10
  68. package/src/transaction/eoa.ts +0 -98
  69. package/src/transaction/execution-strategy.ts +0 -33
  70. package/src/transaction/formatter.ts +0 -101
  71. package/src/transaction/relayer.ts +0 -380
  72. package/src/transaction/sender.ts +0 -185
  73. package/src/transform/index.ts +0 -3
  74. package/src/transform/input-parser.ts +0 -177
  75. package/src/transform/output-formatter.ts +0 -64
  76. package/src/types/__tests__/artifacts.test.ts +0 -105
  77. package/src/types.ts +0 -92
  78. package/src/utils/__tests__/artifacts.test.ts +0 -81
  79. package/src/utils/artifacts.ts +0 -30
  80. package/src/utils/formatting.ts +0 -25
  81. package/src/utils/gas.ts +0 -17
  82. package/src/utils/index.ts +0 -6
  83. package/src/utils/json.ts +0 -19
  84. package/src/utils/validation.ts +0 -10
  85. package/src/validation/eoa.ts +0 -33
  86. package/src/validation/index.ts +0 -2
  87. package/src/validation/relayer.ts +0 -13
  88. package/src/wallet/__tests__/utils.test.ts +0 -149
  89. package/src/wallet/components/account/AccountDisplay.tsx +0 -52
  90. package/src/wallet/components/connect/ConnectButton.tsx +0 -125
  91. package/src/wallet/components/connect/ConnectorDialog.tsx +0 -140
  92. package/src/wallet/components/index.ts +0 -4
  93. package/src/wallet/components/network/NetworkSwitcher.tsx +0 -90
  94. package/src/wallet/context/index.ts +0 -1
  95. package/src/wallet/context/wagmi-context.tsx +0 -7
  96. package/src/wallet/hooks/useIsWagmiProviderInitialized.ts +0 -11
  97. package/src/wallet/rainbowkit/config-generator.ts +0 -56
  98. package/src/wallet/rainbowkit/config-service.ts +0 -169
  99. package/src/wallet/rainbowkit/export-service.ts +0 -18
  100. package/src/wallet/rainbowkit/rainbowkitAssetManager.ts +0 -74
  101. package/src/wallet/rainbowkit/types.ts +0 -74
  102. package/src/wallet/rainbowkit/utils.ts +0 -96
  103. package/src/wallet/services/configResolutionService.ts +0 -65
  104. package/src/wallet/utils/SafeWagmiComponent.tsx +0 -72
  105. package/src/wallet/utils/filterWalletComponents.ts +0 -89
@@ -1,139 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
-
3
- import { getEvmCompatibleFieldTypes, mapEvmParamTypeToFieldType } from '../type-mapper';
4
-
5
- describe('EVM Type Mapper', () => {
6
- describe('mapEvmParamTypeToFieldType', () => {
7
- it('should map small integer types to number field', () => {
8
- expect(mapEvmParamTypeToFieldType('uint')).toBe('number');
9
- expect(mapEvmParamTypeToFieldType('uint8')).toBe('number');
10
- expect(mapEvmParamTypeToFieldType('uint16')).toBe('number');
11
- expect(mapEvmParamTypeToFieldType('uint32')).toBe('number');
12
- expect(mapEvmParamTypeToFieldType('int')).toBe('number');
13
- expect(mapEvmParamTypeToFieldType('int8')).toBe('number');
14
- expect(mapEvmParamTypeToFieldType('int16')).toBe('number');
15
- expect(mapEvmParamTypeToFieldType('int32')).toBe('number');
16
- });
17
-
18
- it('should map 64-bit and larger integer types to bigint field to avoid precision loss', () => {
19
- // These types can hold values larger than JavaScript's Number.MAX_SAFE_INTEGER (2^53-1)
20
- expect(mapEvmParamTypeToFieldType('uint64')).toBe('bigint');
21
- expect(mapEvmParamTypeToFieldType('uint128')).toBe('bigint');
22
- expect(mapEvmParamTypeToFieldType('uint256')).toBe('bigint');
23
- expect(mapEvmParamTypeToFieldType('int64')).toBe('bigint');
24
- expect(mapEvmParamTypeToFieldType('int128')).toBe('bigint');
25
- expect(mapEvmParamTypeToFieldType('int256')).toBe('bigint');
26
- });
27
-
28
- it('should map address to blockchain-address field', () => {
29
- expect(mapEvmParamTypeToFieldType('address')).toBe('blockchain-address');
30
- });
31
-
32
- it('should map bool to checkbox field', () => {
33
- expect(mapEvmParamTypeToFieldType('bool')).toBe('checkbox');
34
- });
35
-
36
- it('should map string to text field', () => {
37
- expect(mapEvmParamTypeToFieldType('string')).toBe('text');
38
- });
39
-
40
- it('should map bytes types to text/textarea fields', () => {
41
- expect(mapEvmParamTypeToFieldType('bytes')).toBe('textarea');
42
- expect(mapEvmParamTypeToFieldType('bytes32')).toBe('text');
43
- });
44
-
45
- it('should map array types correctly', () => {
46
- expect(mapEvmParamTypeToFieldType('uint256[]')).toBe('array');
47
- expect(mapEvmParamTypeToFieldType('address[]')).toBe('array');
48
- expect(mapEvmParamTypeToFieldType('string[]')).toBe('array');
49
- });
50
-
51
- it('should map tuple types to object', () => {
52
- expect(mapEvmParamTypeToFieldType('tuple')).toBe('object');
53
- });
54
-
55
- it('should map array of tuples to array-object', () => {
56
- expect(mapEvmParamTypeToFieldType('tuple[]')).toBe('array-object');
57
- expect(mapEvmParamTypeToFieldType('tuple[5]')).toBe('array-object');
58
- });
59
-
60
- it('should default to text for unknown types', () => {
61
- expect(mapEvmParamTypeToFieldType('unknown')).toBe('text');
62
- expect(mapEvmParamTypeToFieldType('custom')).toBe('text');
63
- });
64
- });
65
-
66
- describe('getEvmCompatibleFieldTypes', () => {
67
- it('should return bigint as first compatible type for 64-bit and larger unsigned integers', () => {
68
- // Verify uint64
69
- const compatibleTypesUint64 = getEvmCompatibleFieldTypes('uint64');
70
- expect(compatibleTypesUint64[0]).toBe('bigint'); // First (recommended) type
71
- expect(compatibleTypesUint64).toContain('number');
72
- expect(compatibleTypesUint64).toContain('amount');
73
- expect(compatibleTypesUint64).toContain('text');
74
-
75
- // Verify uint128
76
- const compatibleTypesUint128 = getEvmCompatibleFieldTypes('uint128');
77
- expect(compatibleTypesUint128[0]).toBe('bigint'); // First (recommended) type
78
- expect(compatibleTypesUint128).toContain('number');
79
- expect(compatibleTypesUint128).toContain('amount');
80
- expect(compatibleTypesUint128).toContain('text');
81
-
82
- // Verify uint256
83
- const compatibleTypesUint256 = getEvmCompatibleFieldTypes('uint256');
84
- expect(compatibleTypesUint256[0]).toBe('bigint'); // First (recommended) type
85
- expect(compatibleTypesUint256).toContain('number');
86
- expect(compatibleTypesUint256).toContain('amount');
87
- expect(compatibleTypesUint256).toContain('text');
88
- });
89
-
90
- it('should return bigint as first compatible type for 64-bit and larger signed integers', () => {
91
- // Verify int64
92
- const compatibleTypesInt64 = getEvmCompatibleFieldTypes('int64');
93
- expect(compatibleTypesInt64[0]).toBe('bigint'); // First (recommended) type
94
- expect(compatibleTypesInt64).toContain('number');
95
- expect(compatibleTypesInt64).toContain('text');
96
-
97
- // Verify int128
98
- const compatibleTypesInt128 = getEvmCompatibleFieldTypes('int128');
99
- expect(compatibleTypesInt128[0]).toBe('bigint'); // First (recommended) type
100
- expect(compatibleTypesInt128).toContain('number');
101
- expect(compatibleTypesInt128).toContain('text');
102
-
103
- // Verify int256
104
- const compatibleTypesInt256 = getEvmCompatibleFieldTypes('int256');
105
- expect(compatibleTypesInt256[0]).toBe('bigint'); // First (recommended) type
106
- expect(compatibleTypesInt256).toContain('number');
107
- expect(compatibleTypesInt256).toContain('text');
108
- });
109
-
110
- it('should return number as first compatible type for small integers', () => {
111
- // Small integers that fit within JavaScript Number precision
112
- const compatibleTypes = getEvmCompatibleFieldTypes('uint32');
113
- expect(compatibleTypes[0]).toBe('number'); // First (recommended) type
114
- expect(compatibleTypes).toContain('amount');
115
- expect(compatibleTypes).toContain('text');
116
- });
117
-
118
- it('should return compatible field types for address', () => {
119
- const compatibleTypes = getEvmCompatibleFieldTypes('address');
120
- expect(compatibleTypes[0]).toBe('blockchain-address'); // First (recommended) type
121
- expect(compatibleTypes).toContain('text');
122
- });
123
-
124
- it('should return compatible field types for bool', () => {
125
- const compatibleTypes = getEvmCompatibleFieldTypes('bool');
126
- expect(compatibleTypes[0]).toBe('checkbox'); // First (recommended) type
127
- expect(compatibleTypes).toContain('select');
128
- expect(compatibleTypes).toContain('radio');
129
- expect(compatibleTypes).toContain('text');
130
- });
131
-
132
- it('should return compatible field types for arrays', () => {
133
- const compatibleTypes = getEvmCompatibleFieldTypes('uint256[]');
134
- expect(compatibleTypes[0]).toBe('array'); // First (recommended) type
135
- expect(compatibleTypes).toContain('textarea');
136
- expect(compatibleTypes).toContain('text');
137
- });
138
- });
139
- });
@@ -1,57 +0,0 @@
1
- import type { FieldType, TypeMappingInfo } from '@openzeppelin/ui-types';
2
-
3
- /**
4
- * EVM-specific type mapping to default form field types.
5
- *
6
- * Note: Large integer types (uint128, uint256, int128, int256) are mapped to 'bigint'
7
- * instead of 'number' to avoid JavaScript's Number precision limitations.
8
- * JavaScript's Number type can only safely represent integers up to 2^53 - 1,
9
- * but these types can hold much larger values. The BigIntField component stores values
10
- * as strings and the EVM adapter handles BigInt conversion automatically.
11
- */
12
- export const EVM_TYPE_TO_FIELD_TYPE: Record<string, FieldType> = {
13
- address: 'blockchain-address',
14
- string: 'text',
15
- uint: 'number',
16
- uint8: 'number',
17
- uint16: 'number',
18
- uint32: 'number',
19
- uint64: 'bigint',
20
- uint128: 'bigint',
21
- uint256: 'bigint',
22
- int: 'number',
23
- int8: 'number',
24
- int16: 'number',
25
- int32: 'number',
26
- int64: 'bigint',
27
- int128: 'bigint',
28
- int256: 'bigint',
29
- bool: 'checkbox',
30
- bytes: 'textarea',
31
- bytes32: 'text',
32
- };
33
-
34
- /**
35
- * EVM dynamic type patterns handled through pattern matching.
36
- */
37
- const EVM_DYNAMIC_PATTERNS: TypeMappingInfo['dynamicPatterns'] = [
38
- { name: 'array', syntax: 'T[]', mapsTo: 'array', description: 'Dynamic array of primitives' },
39
- { name: 'fixed-array', syntax: 'T[N]', mapsTo: 'array', description: 'Fixed-size array' },
40
- {
41
- name: 'tuple-array',
42
- syntax: 'tuple[]',
43
- mapsTo: 'array-object',
44
- description: 'Array of structs',
45
- },
46
- { name: 'tuple', syntax: 'tuple', mapsTo: 'object', description: 'Struct/tuple type' },
47
- ];
48
-
49
- /**
50
- * Returns complete type mapping information for EVM.
51
- */
52
- export function getEvmTypeMappingInfo(): TypeMappingInfo {
53
- return {
54
- primitives: { ...EVM_TYPE_TO_FIELD_TYPE },
55
- dynamicPatterns: EVM_DYNAMIC_PATTERNS,
56
- };
57
- }
@@ -1,115 +0,0 @@
1
- import { startCase } from 'lodash';
2
-
3
- import type {
4
- FieldType,
5
- FieldValidation,
6
- FieldValue,
7
- FormFieldType,
8
- FunctionParameter,
9
- } from '@openzeppelin/ui-types';
10
- import {
11
- enhanceNumericValidation,
12
- getDefaultValueForType,
13
- type NumericBoundsMap,
14
- } from '@openzeppelin/ui-utils';
15
-
16
- import { mapEvmParamTypeToFieldType } from './type-mapper';
17
-
18
- /**
19
- * Extracts the inner type from an EVM array type.
20
- * @param parameterType - The parameter type (e.g., 'uint32[]', 'address[]')
21
- * @returns The inner type (e.g., 'uint32', 'address') or null if not an array type
22
- */
23
- function extractArrayElementType(parameterType: string): string | null {
24
- // Handle array types like uint32[], address[], bytes32[]
25
- const arrayMatch = parameterType.match(/^(.+)\[\d*\]$/);
26
- if (arrayMatch) {
27
- return arrayMatch[1];
28
- }
29
- return null;
30
- }
31
-
32
- /**
33
- * Get default validation rules for a parameter.
34
- * Field-specific validation is handled by the field components themselves.
35
- */
36
- function getDefaultValidation(): FieldValidation {
37
- return { required: true };
38
- }
39
-
40
- /**
41
- * EVM numeric type bounds.
42
- * Maps EVM type names to their min/max value constraints.
43
- * Note: uint64, uint128, uint256, int64, int128, int256 exceed JavaScript's Number.MAX_SAFE_INTEGER
44
- * and are handled via BigInt fields, so bounds are not applied here.
45
- */
46
- const EVM_NUMERIC_BOUNDS: NumericBoundsMap = {
47
- uint: { min: 0 },
48
- uint8: { min: 0, max: 255 },
49
- uint16: { min: 0, max: 65_535 },
50
- uint32: { min: 0, max: 4_294_967_295 },
51
- int: {},
52
- int8: { min: -128, max: 127 },
53
- int16: { min: -32_768, max: 32_767 },
54
- int32: { min: -2_147_483_648, max: 2_147_483_647 },
55
- };
56
-
57
- /**
58
- * Generate default field configuration for an EVM function parameter.
59
- */
60
- export function generateEvmDefaultField<T extends FieldType = FieldType>(
61
- parameter: FunctionParameter
62
- ): FormFieldType<T> {
63
- const fieldType = mapEvmParamTypeToFieldType(parameter.type) as T;
64
-
65
- const baseField: FormFieldType<T> = {
66
- id: `field-${Math.random().toString(36).substring(2, 9)}`,
67
- name: parameter.name || parameter.type, // Use type if name missing
68
- label: startCase(parameter.displayName || parameter.name || parameter.type),
69
- type: fieldType,
70
- placeholder: `Enter ${parameter.displayName || parameter.name || parameter.type}`,
71
- helperText: parameter.description || '',
72
- defaultValue: getDefaultValueForType(fieldType) as FieldValue<T>,
73
- validation: enhanceNumericValidation(
74
- getDefaultValidation(),
75
- parameter.type,
76
- EVM_NUMERIC_BOUNDS
77
- ),
78
- width: 'full',
79
- };
80
-
81
- // For array types, provide element type information
82
- if (fieldType === 'array') {
83
- const elementType = extractArrayElementType(parameter.type);
84
- if (elementType) {
85
- const elementFieldType = mapEvmParamTypeToFieldType(elementType);
86
-
87
- // Add array-specific properties
88
- const arrayField = {
89
- ...baseField,
90
- elementType: elementFieldType,
91
- elementFieldConfig: {
92
- type: elementFieldType,
93
- validation: enhanceNumericValidation(
94
- getDefaultValidation(),
95
- elementType,
96
- EVM_NUMERIC_BOUNDS
97
- ),
98
- placeholder: `Enter ${elementType}`,
99
- },
100
- };
101
- return arrayField;
102
- }
103
- }
104
-
105
- // Preserve components for object and array-object types
106
- if (parameter.components && (fieldType === 'object' || fieldType === 'array-object')) {
107
- const result = {
108
- ...baseField,
109
- components: parameter.components,
110
- };
111
- return result;
112
- }
113
-
114
- return baseField;
115
- }
@@ -1,4 +0,0 @@
1
- // Barrel file for mapping module
2
- export * from './constants';
3
- export * from './type-mapper';
4
- export * from './field-generator';
@@ -1,80 +0,0 @@
1
- import type { FieldType } from '@openzeppelin/ui-types';
2
-
3
- import { EVM_TYPE_TO_FIELD_TYPE } from './constants';
4
-
5
- /**
6
- * Map a blockchain-specific parameter type to a default form field type.
7
- * @param parameterType The blockchain parameter type (e.g., 'uint256', 'address', 'tuple')
8
- * @returns The appropriate default form field type (e.g., 'number', 'blockchain-address', 'object')
9
- */
10
- export function mapEvmParamTypeToFieldType(parameterType: string): FieldType {
11
- // Check if this is an array of tuples/objects
12
- if (parameterType.match(/^tuple\[\d*\]$/)) {
13
- return 'array-object';
14
- }
15
-
16
- // Check if this is an array type (ends with [] or [number])
17
- if (parameterType.match(/\[\d*\]$/)) {
18
- return 'array';
19
- }
20
-
21
- // Extract the base type from array types (e.g., uint256[] -> uint256)
22
- const baseType = parameterType.replace(/\[\d*\]/g, '');
23
-
24
- // Handle tuples (structs) - use object for composite types
25
- if (baseType.startsWith('tuple')) {
26
- return 'object';
27
- }
28
-
29
- // Map common EVM types to appropriate field types
30
- return EVM_TYPE_TO_FIELD_TYPE[baseType] || 'text'; // Default to 'text'
31
- }
32
-
33
- /**
34
- * Get field types compatible with a specific parameter type.
35
- * @param parameterType The blockchain parameter type.
36
- * @returns Array of compatible form field types.
37
- */
38
- export function getEvmCompatibleFieldTypes(parameterType: string): FieldType[] {
39
- // Handle array of objects
40
- if (parameterType.match(/^tuple\[\d*\]$/)) {
41
- return ['array-object', 'textarea', 'text'];
42
- }
43
-
44
- // Handle array types - allow array field or fallback to textarea/text
45
- if (parameterType.match(/\[\d*\]$/)) {
46
- return ['array', 'textarea', 'text'];
47
- }
48
-
49
- const baseType = parameterType.replace(/\[\d*\]/g, '');
50
-
51
- // Handle tuples/objects
52
- if (baseType.startsWith('tuple')) {
53
- return ['object', 'textarea', 'text'];
54
- }
55
-
56
- // Define compatibility map for base types
57
- const compatibilityMap: Record<string, FieldType[]> = {
58
- address: ['blockchain-address', 'text'],
59
- uint: ['number', 'amount', 'text'],
60
- uint8: ['number', 'amount', 'text'],
61
- uint16: ['number', 'amount', 'text'],
62
- uint32: ['number', 'amount', 'text'],
63
- uint64: ['bigint', 'number', 'amount', 'text'],
64
- uint128: ['bigint', 'number', 'amount', 'text'],
65
- uint256: ['bigint', 'number', 'amount', 'text'],
66
- int: ['number', 'text'],
67
- int8: ['number', 'text'],
68
- int16: ['number', 'text'],
69
- int32: ['number', 'text'],
70
- int64: ['bigint', 'number', 'text'],
71
- int128: ['bigint', 'number', 'text'],
72
- int256: ['bigint', 'number', 'text'],
73
- bool: ['checkbox', 'select', 'radio', 'text'],
74
- string: ['text', 'textarea', 'email', 'password'],
75
- bytes: ['textarea', 'text'],
76
- bytes32: ['text', 'textarea'],
77
- };
78
-
79
- return compatibilityMap[baseType] || ['text']; // Default to 'text'
80
- }