ccxt 4.3.70 → 4.3.71

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 (151) hide show
  1. package/README.md +6 -5
  2. package/dist/ccxt.browser.min.js +13 -10
  3. package/dist/cjs/ccxt.js +6 -1
  4. package/dist/cjs/src/abstract/paradex.js +9 -0
  5. package/dist/cjs/src/base/Exchange.js +49 -0
  6. package/dist/cjs/src/paradex.js +2075 -0
  7. package/dist/cjs/src/pro/bequant.js +4 -0
  8. package/dist/cjs/src/pro/paradex.js +365 -0
  9. package/dist/cjs/src/static_dependencies/noble-curves/abstract/poseidon.js +100 -0
  10. package/dist/cjs/src/static_dependencies/noble-curves/abstract/weierstrass.js +1 -0
  11. package/dist/cjs/src/static_dependencies/scure-starknet/index.js +284 -0
  12. package/dist/cjs/src/static_dependencies/starknet/constants.js +60 -0
  13. package/dist/cjs/src/static_dependencies/starknet/types/calldata.js +26 -0
  14. package/dist/cjs/src/static_dependencies/starknet/types/lib/contract/abi.js +8 -0
  15. package/dist/cjs/src/static_dependencies/starknet/types/lib/contract/index.js +13 -0
  16. package/dist/cjs/src/static_dependencies/starknet/types/lib/index.js +56 -0
  17. package/dist/cjs/src/static_dependencies/starknet/types/typedData.js +19 -0
  18. package/dist/cjs/src/static_dependencies/starknet/utils/assert.js +15 -0
  19. package/dist/cjs/src/static_dependencies/starknet/utils/cairoDataTypes/felt.js +44 -0
  20. package/dist/cjs/src/static_dependencies/starknet/utils/cairoDataTypes/uint256.js +122 -0
  21. package/dist/cjs/src/static_dependencies/starknet/utils/cairoDataTypes/uint512.js +137 -0
  22. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/byteArray.js +61 -0
  23. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/cairo.js +218 -0
  24. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/enum/CairoCustomEnum.js +57 -0
  25. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/enum/CairoOption.js +64 -0
  26. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/enum/CairoResult.js +63 -0
  27. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/formatter.js +66 -0
  28. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/index.js +281 -0
  29. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/parser/index.js +33 -0
  30. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/parser/parser-0-1.1.0.js +37 -0
  31. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/parser/parser-2.0.0.js +40 -0
  32. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/propertyOrder.js +156 -0
  33. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/requestParser.js +250 -0
  34. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/responseParser.js +215 -0
  35. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/tuple.js +112 -0
  36. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/validate.js +206 -0
  37. package/dist/cjs/src/static_dependencies/starknet/utils/encode.js +58 -0
  38. package/dist/cjs/src/static_dependencies/starknet/utils/hash/classHash.js +57 -0
  39. package/dist/cjs/src/static_dependencies/starknet/utils/merkle.js +76 -0
  40. package/dist/cjs/src/static_dependencies/starknet/utils/num.js +92 -0
  41. package/dist/cjs/src/static_dependencies/starknet/utils/selector.js +48 -0
  42. package/dist/cjs/src/static_dependencies/starknet/utils/shortString.js +101 -0
  43. package/dist/cjs/src/static_dependencies/starknet/utils/typedData.js +334 -0
  44. package/dist/cjs/src/woo.js +4 -2
  45. package/js/ccxt.d.ts +8 -2
  46. package/js/ccxt.js +6 -2
  47. package/js/src/abstract/paradex.d.ts +43 -0
  48. package/js/src/abstract/paradex.js +11 -0
  49. package/js/src/base/Exchange.d.ts +7 -0
  50. package/js/src/base/Exchange.js +45 -0
  51. package/js/src/paradex.d.ts +76 -0
  52. package/js/src/paradex.js +2075 -0
  53. package/js/src/pro/bequant.js +4 -0
  54. package/js/src/pro/paradex.d.ts +15 -0
  55. package/js/src/pro/paradex.js +366 -0
  56. package/js/src/static_dependencies/noble-curves/abstract/weierstrass.d.ts +24 -0
  57. package/js/src/static_dependencies/noble-curves/abstract/weierstrass.js +1 -1
  58. package/js/src/static_dependencies/scure-starknet/index.d.ts +79 -0
  59. package/js/src/static_dependencies/scure-starknet/index.js +323 -0
  60. package/js/src/static_dependencies/starknet/constants.d.ts +61 -0
  61. package/js/src/static_dependencies/starknet/constants.js +67 -0
  62. package/js/src/static_dependencies/starknet/index.d.ts +7 -0
  63. package/js/src/static_dependencies/starknet/index.js +50 -0
  64. package/js/src/static_dependencies/starknet/types/cairoEnum.d.ts +2 -0
  65. package/js/src/static_dependencies/starknet/types/cairoEnum.js +7 -0
  66. package/js/src/static_dependencies/starknet/types/calldata.d.ts +19 -0
  67. package/js/src/static_dependencies/starknet/types/calldata.js +28 -0
  68. package/js/src/static_dependencies/starknet/types/index.d.ts +13 -0
  69. package/js/src/static_dependencies/starknet/types/index.js +16 -0
  70. package/js/src/static_dependencies/starknet/types/lib/contract/abi.d.ts +71 -0
  71. package/js/src/static_dependencies/starknet/types/lib/contract/abi.js +13 -0
  72. package/js/src/static_dependencies/starknet/types/lib/contract/index.d.ts +24 -0
  73. package/js/src/static_dependencies/starknet/types/lib/contract/index.js +16 -0
  74. package/js/src/static_dependencies/starknet/types/lib/contract/legacy.d.ts +33 -0
  75. package/js/src/static_dependencies/starknet/types/lib/contract/legacy.js +7 -0
  76. package/js/src/static_dependencies/starknet/types/lib/contract/sierra.d.ts +52 -0
  77. package/js/src/static_dependencies/starknet/types/lib/contract/sierra.js +7 -0
  78. package/js/src/static_dependencies/starknet/types/lib/index.d.ts +248 -0
  79. package/js/src/static_dependencies/starknet/types/lib/index.js +52 -0
  80. package/js/src/static_dependencies/starknet/types/typedData.d.ts +44 -0
  81. package/js/src/static_dependencies/starknet/types/typedData.js +19 -0
  82. package/js/src/static_dependencies/starknet/utils/address.d.ts +53 -0
  83. package/js/src/static_dependencies/starknet/utils/address.js +89 -0
  84. package/js/src/static_dependencies/starknet/utils/assert.d.ts +7 -0
  85. package/js/src/static_dependencies/starknet/utils/assert.js +17 -0
  86. package/js/src/static_dependencies/starknet/utils/cairoDataTypes/felt.d.ts +6 -0
  87. package/js/src/static_dependencies/starknet/utils/cairoDataTypes/felt.js +43 -0
  88. package/js/src/static_dependencies/starknet/utils/cairoDataTypes/uint256.d.ts +72 -0
  89. package/js/src/static_dependencies/starknet/utils/cairoDataTypes/uint256.js +117 -0
  90. package/js/src/static_dependencies/starknet/utils/cairoDataTypes/uint512.d.ts +76 -0
  91. package/js/src/static_dependencies/starknet/utils/cairoDataTypes/uint512.js +136 -0
  92. package/js/src/static_dependencies/starknet/utils/calldata/byteArray.d.ts +32 -0
  93. package/js/src/static_dependencies/starknet/utils/calldata/byteArray.js +59 -0
  94. package/js/src/static_dependencies/starknet/utils/calldata/cairo.d.ts +183 -0
  95. package/js/src/static_dependencies/starknet/utils/calldata/cairo.js +229 -0
  96. package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoCustomEnum.d.ts +38 -0
  97. package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoCustomEnum.js +57 -0
  98. package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoOption.d.ts +35 -0
  99. package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoOption.js +64 -0
  100. package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoResult.d.ts +34 -0
  101. package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoResult.js +63 -0
  102. package/js/src/static_dependencies/starknet/utils/calldata/enum/index.d.ts +3 -0
  103. package/js/src/static_dependencies/starknet/utils/calldata/enum/index.js +9 -0
  104. package/js/src/static_dependencies/starknet/utils/calldata/formatter.d.ts +9 -0
  105. package/js/src/static_dependencies/starknet/utils/calldata/formatter.js +67 -0
  106. package/js/src/static_dependencies/starknet/utils/calldata/index.d.ts +89 -0
  107. package/js/src/static_dependencies/starknet/utils/calldata/index.js +280 -0
  108. package/js/src/static_dependencies/starknet/utils/calldata/parser/index.d.ts +5 -0
  109. package/js/src/static_dependencies/starknet/utils/calldata/parser/index.js +30 -0
  110. package/js/src/static_dependencies/starknet/utils/calldata/parser/interface.d.ts +20 -0
  111. package/js/src/static_dependencies/starknet/utils/calldata/parser/interface.js +8 -0
  112. package/js/src/static_dependencies/starknet/utils/calldata/parser/parser-0-1.1.0.d.ts +24 -0
  113. package/js/src/static_dependencies/starknet/utils/calldata/parser/parser-0-1.1.0.js +36 -0
  114. package/js/src/static_dependencies/starknet/utils/calldata/parser/parser-2.0.0.d.ts +23 -0
  115. package/js/src/static_dependencies/starknet/utils/calldata/parser/parser-2.0.0.js +40 -0
  116. package/js/src/static_dependencies/starknet/utils/calldata/propertyOrder.d.ts +2 -0
  117. package/js/src/static_dependencies/starknet/utils/calldata/propertyOrder.js +155 -0
  118. package/js/src/static_dependencies/starknet/utils/calldata/requestParser.d.ts +11 -0
  119. package/js/src/static_dependencies/starknet/utils/calldata/requestParser.js +248 -0
  120. package/js/src/static_dependencies/starknet/utils/calldata/responseParser.d.ts +11 -0
  121. package/js/src/static_dependencies/starknet/utils/calldata/responseParser.js +214 -0
  122. package/js/src/static_dependencies/starknet/utils/calldata/tuple.d.ts +6 -0
  123. package/js/src/static_dependencies/starknet/utils/calldata/tuple.js +113 -0
  124. package/js/src/static_dependencies/starknet/utils/calldata/validate.d.ts +6 -0
  125. package/js/src/static_dependencies/starknet/utils/calldata/validate.js +208 -0
  126. package/js/src/static_dependencies/starknet/utils/encode.d.ts +207 -0
  127. package/js/src/static_dependencies/starknet/utils/encode.js +282 -0
  128. package/js/src/static_dependencies/starknet/utils/hash/classHash.d.ts +57 -0
  129. package/js/src/static_dependencies/starknet/utils/hash/classHash.js +224 -0
  130. package/js/src/static_dependencies/starknet/utils/hash/index.d.ts +6 -0
  131. package/js/src/static_dependencies/starknet/utils/hash/index.js +13 -0
  132. package/js/src/static_dependencies/starknet/utils/json.d.ts +24 -0
  133. package/js/src/static_dependencies/starknet/utils/json.js +43 -0
  134. package/js/src/static_dependencies/starknet/utils/merkle.d.ts +35 -0
  135. package/js/src/static_dependencies/starknet/utils/merkle.js +84 -0
  136. package/js/src/static_dependencies/starknet/utils/num.d.ts +182 -0
  137. package/js/src/static_dependencies/starknet/utils/num.js +244 -0
  138. package/js/src/static_dependencies/starknet/utils/selector.d.ts +48 -0
  139. package/js/src/static_dependencies/starknet/utils/selector.js +85 -0
  140. package/js/src/static_dependencies/starknet/utils/shortString.d.ts +57 -0
  141. package/js/src/static_dependencies/starknet/utils/shortString.js +96 -0
  142. package/js/src/static_dependencies/starknet/utils/starknetId.d.ts +113 -0
  143. package/js/src/static_dependencies/starknet/utils/starknetId.js +265 -0
  144. package/js/src/static_dependencies/starknet/utils/typedData.d.ts +54 -0
  145. package/js/src/static_dependencies/starknet/utils/typedData.js +321 -0
  146. package/js/src/static_dependencies/starknet/utils/uint256.d.ts +21 -0
  147. package/js/src/static_dependencies/starknet/utils/uint256.js +32 -0
  148. package/js/src/static_dependencies/starknet/utils/url.d.ts +29 -0
  149. package/js/src/static_dependencies/starknet/utils/url.js +70 -0
  150. package/js/src/woo.js +4 -2
  151. package/package.json +1 -1
@@ -0,0 +1,183 @@
1
+ import { Abi, AbiEnums, AbiStructs, BigNumberish, ContractVersion, Uint256, Uint512 } from '../../types/index.js';
2
+ /**
3
+ * Checks if the given name ends with "_len".
4
+ *
5
+ * @param {string} name - The name to be checked.
6
+ * @returns - True if the name ends with "_len", false otherwise.
7
+ */
8
+ export declare const isLen: (name: string) => boolean;
9
+ /**
10
+ * Checks if a given type is felt.
11
+ *
12
+ * @param {string} type - The type to check.
13
+ * @returns - True if the type is felt, false otherwise.
14
+ */
15
+ export declare const isTypeFelt: (type: string) => boolean;
16
+ /**
17
+ * Checks if the given type is an array type.
18
+ *
19
+ * @param {string} type - The type to check.
20
+ * @returns - `true` if the type is an array type, `false` otherwise.
21
+ */
22
+ export declare const isTypeArray: (type: string) => boolean;
23
+ /**
24
+ * Checks if the given type is a tuple type.
25
+ *
26
+ * @param {string} type - The type to be checked.
27
+ * @returns - `true` if the type is a tuple type, otherwise `false`.
28
+ */
29
+ export declare const isTypeTuple: (type: string) => boolean;
30
+ /**
31
+ * Checks whether a given type is a named tuple.
32
+ *
33
+ * @param {string} type - The type to be checked.
34
+ * @returns - True if the type is a named tuple, false otherwise.
35
+ */
36
+ export declare const isTypeNamedTuple: (type: string) => boolean;
37
+ /**
38
+ * Checks if a given type is a struct.
39
+ *
40
+ * @param {string} type - The type to check for existence.
41
+ * @param {AbiStructs} structs - The collection of structs to search in.
42
+ * @returns - True if the type exists in the structs, false otherwise.
43
+ */
44
+ export declare const isTypeStruct: (type: string, structs: AbiStructs) => boolean;
45
+ /**
46
+ * Checks if a given type is an enum.
47
+ *
48
+ * @param {string} type - The type to check.
49
+ * @param {AbiEnums} enums - The enumeration to search in.
50
+ * @returns - True if the type exists in the enumeration, otherwise false.
51
+ */
52
+ export declare const isTypeEnum: (type: string, enums: AbiEnums) => boolean;
53
+ /**
54
+ * Determines if the given type is an Option type.
55
+ *
56
+ * @param {string} type - The type to check.
57
+ * @returns - True if the type is an Option type, false otherwise.
58
+ */
59
+ export declare const isTypeOption: (type: string) => boolean;
60
+ /**
61
+ * Checks whether a given type starts with 'core::result::Result::'.
62
+ *
63
+ * @param {string} type - The type to check.
64
+ * @returns - True if the type starts with 'core::result::Result::', false otherwise.
65
+ */
66
+ export declare const isTypeResult: (type: string) => boolean;
67
+ /**
68
+ * Checks if the given value is a valid Uint type.
69
+ *
70
+ * @param {string} type - The value to check.
71
+ * @returns - Returns true if the value is a valid Uint type, otherwise false.
72
+ */
73
+ export declare const isTypeUint: (type: string) => boolean;
74
+ /**
75
+ * Checks if the given type is `uint256`.
76
+ *
77
+ * @param {string} type - The type to be checked.
78
+ * @returns - Returns true if the type is `uint256`, otherwise false.
79
+ */
80
+ export declare const isTypeUint256: (type: string) => boolean;
81
+ /**
82
+ * Checks if the given type is a literal type.
83
+ *
84
+ * @param {string} type - The type to check.
85
+ * @returns - True if the type is a literal type, false otherwise.
86
+ */
87
+ export declare const isTypeLiteral: (type: string) => boolean;
88
+ /**
89
+ * Checks if the given type is a boolean type.
90
+ *
91
+ * @param {string} type - The type to be checked.
92
+ * @returns - Returns true if the type is a boolean type, otherwise false.
93
+ */
94
+ export declare const isTypeBool: (type: string) => boolean;
95
+ /**
96
+ * Checks if the provided type is equal to 'core::starknet::contract_address::ContractAddress'.
97
+ * @param {string} type - The type to be checked.
98
+ * @returns - true if the type matches 'core::starknet::contract_address::ContractAddress', false otherwise.
99
+ */
100
+ export declare const isTypeContractAddress: (type: string) => boolean;
101
+ /**
102
+ * Determines if the given type is an Ethereum address type.
103
+ *
104
+ * @param {string} type - The type to check.
105
+ * @returns - Returns true if the given type is 'core::starknet::eth_address::EthAddress', otherwise false.
106
+ */
107
+ export declare const isTypeEthAddress: (type: string) => boolean;
108
+ /**
109
+ * Checks if the given type is 'core::bytes_31::bytes31'.
110
+ *
111
+ * @param {string} type - The type to check.
112
+ * @returns - True if the type is 'core::bytes_31::bytes31', false otherwise.
113
+ */
114
+ export declare const isTypeBytes31: (type: string) => boolean;
115
+ /**
116
+ * Checks if the given type is equal to the 'core::byte_array::ByteArray'.
117
+ *
118
+ * @param {string} type - The type to check.
119
+ * @returns - True if the given type is equal to 'core::byte_array::ByteArray', false otherwise.
120
+ */
121
+ export declare const isTypeByteArray: (type: string) => boolean;
122
+ export declare const isTypeSecp256k1Point: (type: string) => boolean;
123
+ export declare const isCairo1Type: (type: string) => boolean;
124
+ /**
125
+ * Retrieves the array type from the given type string.
126
+ *
127
+ * @param {string} type - The type string.
128
+ * @returns - The array type.
129
+ */
130
+ export declare const getArrayType: (type: string) => string;
131
+ /**
132
+ * Test if an ABI comes from a Cairo 1 contract
133
+ * @param abi representing the interface of a Cairo contract
134
+ * @returns TRUE if it is an ABI from a Cairo1 contract
135
+ * @example
136
+ * ```typescript
137
+ * const isCairo1: boolean = isCairo1Abi(myAbi: Abi);
138
+ * ```
139
+ */
140
+ export declare function isCairo1Abi(abi: Abi): boolean;
141
+ /**
142
+ * Return ContractVersion (Abi version) based on Abi
143
+ * or undefined for unknown version
144
+ * @param abi
145
+ * @returns string
146
+ */
147
+ export declare function getAbiContractVersion(abi: Abi): ContractVersion;
148
+ /**
149
+ * named tuple cairo type is described as js object {}
150
+ * struct cairo type are described as js object {}
151
+ * array cairo type are described as js array []
152
+ */
153
+ /**
154
+ * Create Uint256 Cairo type (helper for common struct type)
155
+ * @example
156
+ * ```typescript
157
+ * uint256('892349863487563453485768723498');
158
+ * ```
159
+ */
160
+ export declare const uint256: (it: BigNumberish) => Uint256;
161
+ /**
162
+ * Create Uint512 Cairo type (helper for common struct type)
163
+ * @param it BigNumberish representation of a 512 bits unsigned number
164
+ * @returns Uint512 struct
165
+ * @example
166
+ * ```typescript
167
+ * uint512('345745685892349863487563453485768723498');
168
+ * ```
169
+ */
170
+ export declare const uint512: (it: BigNumberish) => Uint512;
171
+ /**
172
+ * Create unnamed tuple Cairo type (helper same as common struct type)
173
+ * @example
174
+ * ```typescript
175
+ * tuple(1, '0x101', 16);
176
+ * ```
177
+ */
178
+ export declare const tuple: (...args: (BigNumberish | object | boolean)[]) => Record<number, BigNumberish | object | boolean>;
179
+ /**
180
+ * Create felt Cairo type (cairo type helper)
181
+ * @returns format: felt-string
182
+ */
183
+ export declare function felt(it: BigNumberish): string;
@@ -0,0 +1,229 @@
1
+ // ----------------------------------------------------------------------------
2
+
3
+ // PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
4
+ // https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
5
+ // EDIT THE CORRESPONDENT .ts FILE INSTEAD
6
+
7
+ import { Literal, Uint, } from '../../types/index.js';
8
+ import { CairoFelt } from '../cairoDataTypes/felt.js';
9
+ import { CairoUint256 } from '../cairoDataTypes/uint256.js';
10
+ import { CairoUint512 } from '../cairoDataTypes/uint512.js';
11
+ // Intended for internal usage, maybe should be exported somewhere else and not exported to utils
12
+ /**
13
+ * Checks if the given name ends with "_len".
14
+ *
15
+ * @param {string} name - The name to be checked.
16
+ * @returns - True if the name ends with "_len", false otherwise.
17
+ */
18
+ export const isLen = (name) => /_len$/.test(name);
19
+ /**
20
+ * Checks if a given type is felt.
21
+ *
22
+ * @param {string} type - The type to check.
23
+ * @returns - True if the type is felt, false otherwise.
24
+ */
25
+ export const isTypeFelt = (type) => type === 'felt' || type === 'core::felt252';
26
+ /**
27
+ * Checks if the given type is an array type.
28
+ *
29
+ * @param {string} type - The type to check.
30
+ * @returns - `true` if the type is an array type, `false` otherwise.
31
+ */
32
+ export const isTypeArray = (type) => /\*/.test(type) ||
33
+ type.startsWith('core::array::Array::') ||
34
+ type.startsWith('core::array::Span::');
35
+ /**
36
+ * Checks if the given type is a tuple type.
37
+ *
38
+ * @param {string} type - The type to be checked.
39
+ * @returns - `true` if the type is a tuple type, otherwise `false`.
40
+ */
41
+ export const isTypeTuple = (type) => /^\(.*\)$/i.test(type);
42
+ /**
43
+ * Checks whether a given type is a named tuple.
44
+ *
45
+ * @param {string} type - The type to be checked.
46
+ * @returns - True if the type is a named tuple, false otherwise.
47
+ */
48
+ export const isTypeNamedTuple = (type) => /\(.*\)/i.test(type) && type.includes(':');
49
+ /**
50
+ * Checks if a given type is a struct.
51
+ *
52
+ * @param {string} type - The type to check for existence.
53
+ * @param {AbiStructs} structs - The collection of structs to search in.
54
+ * @returns - True if the type exists in the structs, false otherwise.
55
+ */
56
+ export const isTypeStruct = (type, structs) => type in structs;
57
+ /**
58
+ * Checks if a given type is an enum.
59
+ *
60
+ * @param {string} type - The type to check.
61
+ * @param {AbiEnums} enums - The enumeration to search in.
62
+ * @returns - True if the type exists in the enumeration, otherwise false.
63
+ */
64
+ export const isTypeEnum = (type, enums) => type in enums;
65
+ /**
66
+ * Determines if the given type is an Option type.
67
+ *
68
+ * @param {string} type - The type to check.
69
+ * @returns - True if the type is an Option type, false otherwise.
70
+ */
71
+ export const isTypeOption = (type) => type.startsWith('core::option::Option::');
72
+ /**
73
+ * Checks whether a given type starts with 'core::result::Result::'.
74
+ *
75
+ * @param {string} type - The type to check.
76
+ * @returns - True if the type starts with 'core::result::Result::', false otherwise.
77
+ */
78
+ export const isTypeResult = (type) => type.startsWith('core::result::Result::');
79
+ /**
80
+ * Checks if the given value is a valid Uint type.
81
+ *
82
+ * @param {string} type - The value to check.
83
+ * @returns - Returns true if the value is a valid Uint type, otherwise false.
84
+ */
85
+ export const isTypeUint = (type) => Object.values(Uint).includes(type);
86
+ // Legacy Export
87
+ /**
88
+ * Checks if the given type is `uint256`.
89
+ *
90
+ * @param {string} type - The type to be checked.
91
+ * @returns - Returns true if the type is `uint256`, otherwise false.
92
+ */
93
+ export const isTypeUint256 = (type) => CairoUint256.isAbiType(type);
94
+ /**
95
+ * Checks if the given type is a literal type.
96
+ *
97
+ * @param {string} type - The type to check.
98
+ * @returns - True if the type is a literal type, false otherwise.
99
+ */
100
+ export const isTypeLiteral = (type) => Object.values(Literal).includes(type);
101
+ /**
102
+ * Checks if the given type is a boolean type.
103
+ *
104
+ * @param {string} type - The type to be checked.
105
+ * @returns - Returns true if the type is a boolean type, otherwise false.
106
+ */
107
+ export const isTypeBool = (type) => type === 'core::bool';
108
+ /**
109
+ * Checks if the provided type is equal to 'core::starknet::contract_address::ContractAddress'.
110
+ * @param {string} type - The type to be checked.
111
+ * @returns - true if the type matches 'core::starknet::contract_address::ContractAddress', false otherwise.
112
+ */
113
+ export const isTypeContractAddress = (type) => type === 'core::starknet::contract_address::ContractAddress';
114
+ /**
115
+ * Determines if the given type is an Ethereum address type.
116
+ *
117
+ * @param {string} type - The type to check.
118
+ * @returns - Returns true if the given type is 'core::starknet::eth_address::EthAddress', otherwise false.
119
+ */
120
+ export const isTypeEthAddress = (type) => type === 'core::starknet::eth_address::EthAddress';
121
+ /**
122
+ * Checks if the given type is 'core::bytes_31::bytes31'.
123
+ *
124
+ * @param {string} type - The type to check.
125
+ * @returns - True if the type is 'core::bytes_31::bytes31', false otherwise.
126
+ */
127
+ export const isTypeBytes31 = (type) => type === 'core::bytes_31::bytes31';
128
+ /**
129
+ * Checks if the given type is equal to the 'core::byte_array::ByteArray'.
130
+ *
131
+ * @param {string} type - The type to check.
132
+ * @returns - True if the given type is equal to 'core::byte_array::ByteArray', false otherwise.
133
+ */
134
+ export const isTypeByteArray = (type) => type === 'core::byte_array::byteArray.js';
135
+ export const isTypeSecp256k1Point = (type) => type === 'core::starknet::secp256k1::Secp256k1Point';
136
+ export const isCairo1Type = (type) => type.includes('::');
137
+ /**
138
+ * Retrieves the array type from the given type string.
139
+ *
140
+ * @param {string} type - The type string.
141
+ * @returns - The array type.
142
+ */
143
+ export const getArrayType = (type) => {
144
+ if (isCairo1Type(type)) {
145
+ return type.substring(type.indexOf('<') + 1, type.lastIndexOf('>'));
146
+ }
147
+ return type.replace('*', '');
148
+ };
149
+ /**
150
+ * Test if an ABI comes from a Cairo 1 contract
151
+ * @param abi representing the interface of a Cairo contract
152
+ * @returns TRUE if it is an ABI from a Cairo1 contract
153
+ * @example
154
+ * ```typescript
155
+ * const isCairo1: boolean = isCairo1Abi(myAbi: Abi);
156
+ * ```
157
+ */
158
+ export function isCairo1Abi(abi) {
159
+ const { cairo } = getAbiContractVersion(abi);
160
+ if (cairo === undefined) {
161
+ throw Error('Unable to determine Cairo version');
162
+ }
163
+ return cairo === '1';
164
+ }
165
+ /**
166
+ * Return ContractVersion (Abi version) based on Abi
167
+ * or undefined for unknown version
168
+ * @param abi
169
+ * @returns string
170
+ */
171
+ export function getAbiContractVersion(abi) {
172
+ // determine by interface for "Cairo 1.2"
173
+ if (abi.find((it) => it.type === 'interface')) {
174
+ return { cairo: '1', compiler: '2' };
175
+ }
176
+ // determine by function io types "Cairo 1.1" or "Cairo 0.0"
177
+ // find first function with inputs or outputs
178
+ const testFunction = abi.find((it) => it.type === 'function' && (it.inputs.length || it.outputs.length));
179
+ if (!testFunction) {
180
+ return { cairo: undefined, compiler: undefined };
181
+ }
182
+ const io = testFunction.inputs.length ? testFunction.inputs : testFunction.outputs;
183
+ if (isCairo1Type(io[0].type)) {
184
+ return { cairo: '1', compiler: '1' };
185
+ }
186
+ return { cairo: '0', compiler: '0' };
187
+ }
188
+ /**
189
+ * named tuple cairo type is described as js object {}
190
+ * struct cairo type are described as js object {}
191
+ * array cairo type are described as js array []
192
+ */
193
+ /**
194
+ * Create Uint256 Cairo type (helper for common struct type)
195
+ * @example
196
+ * ```typescript
197
+ * uint256('892349863487563453485768723498');
198
+ * ```
199
+ */
200
+ export const uint256 = (it) => {
201
+ return new CairoUint256(it).toUint256DecimalString();
202
+ };
203
+ /**
204
+ * Create Uint512 Cairo type (helper for common struct type)
205
+ * @param it BigNumberish representation of a 512 bits unsigned number
206
+ * @returns Uint512 struct
207
+ * @example
208
+ * ```typescript
209
+ * uint512('345745685892349863487563453485768723498');
210
+ * ```
211
+ */
212
+ export const uint512 = (it) => {
213
+ return new CairoUint512(it).toUint512DecimalString();
214
+ };
215
+ /**
216
+ * Create unnamed tuple Cairo type (helper same as common struct type)
217
+ * @example
218
+ * ```typescript
219
+ * tuple(1, '0x101', 16);
220
+ * ```
221
+ */
222
+ export const tuple = (...args) => ({ ...args });
223
+ /**
224
+ * Create felt Cairo type (cairo type helper)
225
+ * @returns format: felt-string
226
+ */
227
+ export function felt(it) {
228
+ return CairoFelt(it);
229
+ }
@@ -0,0 +1,38 @@
1
+ export declare type CairoEnumRaw = {
2
+ [key: string]: any;
3
+ };
4
+ /**
5
+ * Class to handle Cairo custom Enum
6
+ * @param enumContent object containing the variants and its content. Example :
7
+ * {Success: 234, Warning: undefined, Error: undefined}.
8
+ * Only one variant with a value, object, array.
9
+ * @returns an instance representing a Cairo custom Enum.
10
+ * @example
11
+ * ```typescript
12
+ * const myCairoEnum = new CairoCustomEnum( {Success: undefined, Warning: "0x7f32ea", Error: undefined})
13
+ * ```
14
+ */
15
+ export declare class CairoCustomEnum {
16
+ /**
17
+ * direct readonly access to variants of the Cairo Custom Enum.
18
+ * @returns a value of type any
19
+ * @example
20
+ * ```typescript
21
+ * const successValue = myCairoEnum.variant.Success;
22
+ */
23
+ readonly variant: CairoEnumRaw;
24
+ /**
25
+ * @param enumContent an object with the variants as keys and the content as value. Only one content shall be defined.
26
+ */
27
+ constructor(enumContent: CairoEnumRaw);
28
+ /**
29
+ *
30
+ * @returns the content of the valid variant of a Cairo custom Enum.
31
+ */
32
+ unwrap(): any;
33
+ /**
34
+ *
35
+ * @returns the name of the valid variant of a Cairo custom Enum.
36
+ */
37
+ activeVariant(): string;
38
+ }
@@ -0,0 +1,57 @@
1
+ // ----------------------------------------------------------------------------
2
+
3
+ // PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
4
+ // https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
5
+ // EDIT THE CORRESPONDENT .ts FILE INSTEAD
6
+
7
+ /**
8
+ * Class to handle Cairo custom Enum
9
+ * @param enumContent object containing the variants and its content. Example :
10
+ * {Success: 234, Warning: undefined, Error: undefined}.
11
+ * Only one variant with a value, object, array.
12
+ * @returns an instance representing a Cairo custom Enum.
13
+ * @example
14
+ * ```typescript
15
+ * const myCairoEnum = new CairoCustomEnum( {Success: undefined, Warning: "0x7f32ea", Error: undefined})
16
+ * ```
17
+ */
18
+ export class CairoCustomEnum {
19
+ /**
20
+ * @param enumContent an object with the variants as keys and the content as value. Only one content shall be defined.
21
+ */
22
+ constructor(enumContent) {
23
+ const variantsList = Object.values(enumContent);
24
+ if (variantsList.length === 0) {
25
+ throw new Error('This Enum must have at least 1 variant');
26
+ }
27
+ const nbActiveVariants = variantsList.filter((content) => typeof content !== 'undefined').length;
28
+ if (nbActiveVariants !== 1) {
29
+ throw new Error('This Enum must have exactly one active variant');
30
+ }
31
+ this.variant = enumContent;
32
+ }
33
+ /**
34
+ *
35
+ * @returns the content of the valid variant of a Cairo custom Enum.
36
+ */
37
+ unwrap() {
38
+ const variants = Object.entries(this.variant);
39
+ const activeVariant = variants.find((item) => typeof item[1] !== 'undefined');
40
+ if (typeof activeVariant === 'undefined') {
41
+ return undefined;
42
+ }
43
+ return activeVariant[1];
44
+ }
45
+ /**
46
+ *
47
+ * @returns the name of the valid variant of a Cairo custom Enum.
48
+ */
49
+ activeVariant() {
50
+ const variants = Object.entries(this.variant);
51
+ const activeVariant = variants.find((item) => typeof item[1] !== 'undefined');
52
+ if (typeof activeVariant === 'undefined') {
53
+ return '';
54
+ }
55
+ return activeVariant[0];
56
+ }
57
+ }
@@ -0,0 +1,35 @@
1
+ export declare enum CairoOptionVariant {
2
+ Some = 0,
3
+ None = 1
4
+ }
5
+ /**
6
+ * Class to handle Cairo Option
7
+ * @param variant CairoOptionVariant.Some or CairoOptionVariant.None
8
+ * @param someContent value of type T.
9
+ * @returns an instance representing a Cairo Option.
10
+ * @example
11
+ * ```typescript
12
+ * const myOption = new CairoOption<BigNumberish>(CairoOptionVariant.Some, "0x54dda8");
13
+ * ```
14
+ */
15
+ export declare class CairoOption<T> {
16
+ readonly Some?: T;
17
+ readonly None?: boolean;
18
+ constructor(variant: CairoOptionVariant, someContent?: T);
19
+ /**
20
+ *
21
+ * @returns the content of the valid variant of a Cairo custom Enum.
22
+ * If None, returns 'undefined'.
23
+ */
24
+ unwrap(): T | undefined;
25
+ /**
26
+ *
27
+ * @returns true if the valid variant is 'isSome'.
28
+ */
29
+ isSome(): boolean;
30
+ /**
31
+ *
32
+ * @returns true if the valid variant is 'isNone'.
33
+ */
34
+ isNone(): boolean;
35
+ }
@@ -0,0 +1,64 @@
1
+ // ----------------------------------------------------------------------------
2
+
3
+ // PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
4
+ // https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
5
+ // EDIT THE CORRESPONDENT .ts FILE INSTEAD
6
+
7
+ export var CairoOptionVariant;
8
+ (function (CairoOptionVariant) {
9
+ CairoOptionVariant[CairoOptionVariant["Some"] = 0] = "Some";
10
+ CairoOptionVariant[CairoOptionVariant["None"] = 1] = "None";
11
+ })(CairoOptionVariant || (CairoOptionVariant = {}));
12
+ /**
13
+ * Class to handle Cairo Option
14
+ * @param variant CairoOptionVariant.Some or CairoOptionVariant.None
15
+ * @param someContent value of type T.
16
+ * @returns an instance representing a Cairo Option.
17
+ * @example
18
+ * ```typescript
19
+ * const myOption = new CairoOption<BigNumberish>(CairoOptionVariant.Some, "0x54dda8");
20
+ * ```
21
+ */
22
+ export class CairoOption {
23
+ constructor(variant, someContent) {
24
+ if (!(variant in CairoOptionVariant)) {
25
+ throw new Error('Wrong variant : should be CairoOptionVariant.Some or .None.');
26
+ }
27
+ if (variant === CairoOptionVariant.Some) {
28
+ if (typeof someContent === 'undefined') {
29
+ throw new Error('The creation of a Cairo Option with "Some" variant needs a content as input.');
30
+ }
31
+ this.Some = someContent;
32
+ this.None = undefined;
33
+ }
34
+ else {
35
+ this.Some = undefined;
36
+ this.None = true;
37
+ }
38
+ }
39
+ /**
40
+ *
41
+ * @returns the content of the valid variant of a Cairo custom Enum.
42
+ * If None, returns 'undefined'.
43
+ */
44
+ unwrap() {
45
+ if (this.None) {
46
+ return undefined;
47
+ }
48
+ return this.Some;
49
+ }
50
+ /**
51
+ *
52
+ * @returns true if the valid variant is 'isSome'.
53
+ */
54
+ isSome() {
55
+ return !(typeof this.Some === 'undefined');
56
+ }
57
+ /**
58
+ *
59
+ * @returns true if the valid variant is 'isNone'.
60
+ */
61
+ isNone() {
62
+ return this.None === true;
63
+ }
64
+ }
@@ -0,0 +1,34 @@
1
+ export declare enum CairoResultVariant {
2
+ Ok = 0,
3
+ Err = 1
4
+ }
5
+ /**
6
+ * Class to handle Cairo Result
7
+ * @param variant CairoResultVariant.Ok or CairoResultVariant.Err
8
+ * @param resultContent value of type T or U.
9
+ * @returns an instance representing a Cairo Result.
10
+ * @example
11
+ * ```typescript
12
+ * const myOption = new CairoResult<BigNumberish, CustomError>(CairoResultVariant.Ok, "0x54dda8");
13
+ * ```
14
+ */
15
+ export declare class CairoResult<T, U> {
16
+ readonly Ok?: T;
17
+ readonly Err?: U;
18
+ constructor(variant: CairoResultVariant, resultContent: T | U);
19
+ /**
20
+ *
21
+ * @returns the content of the valid variant of a Cairo Result.
22
+ */
23
+ unwrap(): T | U;
24
+ /**
25
+ *
26
+ * @returns true if the valid variant is 'Ok'.
27
+ */
28
+ isOk(): boolean;
29
+ /**
30
+ *
31
+ * @returns true if the valid variant is 'isErr'.
32
+ */
33
+ isErr(): boolean;
34
+ }