starknet 6.9.0 → 6.10.1
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/CHANGELOG.md +12 -0
- package/LICENSE +1 -1
- package/README.md +5 -9
- package/dist/account/default.cjs +655 -0
- package/dist/account/default.d.ts +67 -0
- package/dist/account/default.mjs +652 -0
- package/dist/account/index.cjs +27 -0
- package/dist/account/index.d.ts +2 -0
- package/dist/account/index.mjs +2 -0
- package/dist/account/interface.cjs +9 -0
- package/dist/account/interface.d.ts +301 -0
- package/dist/account/interface.mjs +3 -0
- package/dist/channel/index.cjs +27 -0
- package/dist/channel/index.d.ts +3 -0
- package/dist/channel/index.mjs +3 -0
- package/dist/channel/rpc_0_6.cjs +607 -0
- package/dist/channel/rpc_0_6.d.ts +78 -0
- package/dist/channel/rpc_0_6.mjs +543 -0
- package/dist/channel/rpc_0_7.cjs +619 -0
- package/dist/channel/rpc_0_7.d.ts +81 -0
- package/dist/channel/rpc_0_7.mjs +561 -0
- package/dist/constants.cjs +76 -0
- package/dist/constants.d.ts +70 -0
- package/dist/constants.mjs +60 -0
- package/dist/contract/contractFactory.cjs +93 -0
- package/dist/contract/contractFactory.d.ts +46 -0
- package/dist/contract/contractFactory.mjs +83 -0
- package/dist/contract/default.cjs +269 -0
- package/dist/contract/default.d.ts +58 -0
- package/dist/contract/default.mjs +254 -0
- package/dist/contract/index.cjs +38 -0
- package/dist/contract/index.d.ts +3 -0
- package/dist/contract/index.mjs +3 -0
- package/dist/contract/interface.cjs +13 -0
- package/dist/contract/interface.d.ts +128 -0
- package/dist/contract/interface.mjs +6 -0
- package/dist/index.cjs +267 -0
- package/dist/index.d.ts +45 -5991
- package/dist/index.global.js +728 -609
- package/dist/index.global.js.map +1 -1
- package/dist/index.mjs +39 -7320
- package/dist/provider/errors.cjs +50 -0
- package/dist/provider/errors.d.ts +16 -0
- package/dist/provider/errors.mjs +35 -0
- package/dist/provider/extensions/default.cjs +11 -0
- package/dist/provider/extensions/default.d.ts +6 -0
- package/dist/provider/extensions/default.mjs +5 -0
- package/dist/provider/extensions/starknetId.cjs +174 -0
- package/dist/provider/extensions/starknetId.d.ts +10 -0
- package/dist/provider/extensions/starknetId.mjs +230 -0
- package/dist/provider/index.cjs +56 -0
- package/dist/provider/index.d.ts +6 -0
- package/dist/provider/index.mjs +6 -0
- package/dist/provider/interface.cjs +8 -0
- package/dist/provider/interface.d.ts +261 -0
- package/dist/provider/interface.mjs +2 -0
- package/dist/provider/rpc.cjs +301 -0
- package/dist/provider/rpc.d.ts +115 -0
- package/dist/provider/rpc.mjs +302 -0
- package/dist/service/types.cjs +1 -0
- package/dist/service/types.d.ts +5 -0
- package/dist/service/types.mjs +0 -0
- package/dist/signer/default.cjs +105 -0
- package/dist/signer/default.d.ts +12 -0
- package/dist/signer/default.mjs +102 -0
- package/dist/signer/ethSigner.cjs +123 -0
- package/dist/signer/ethSigner.d.ts +25 -0
- package/dist/signer/ethSigner.mjs +140 -0
- package/dist/signer/index.cjs +38 -0
- package/dist/signer/index.d.ts +3 -0
- package/dist/signer/index.mjs +3 -0
- package/dist/signer/interface.cjs +8 -0
- package/dist/signer/interface.d.ts +115 -0
- package/dist/signer/interface.mjs +2 -0
- package/dist/types/account.cjs +1 -0
- package/dist/types/account.d.ts +79 -0
- package/dist/types/account.mjs +0 -0
- package/dist/types/api/index.cjs +30 -0
- package/dist/types/api/index.d.ts +4 -0
- package/dist/types/api/index.mjs +4 -0
- package/dist/types/api/jsonrpc/index.cjs +1 -0
- package/dist/types/api/jsonrpc/index.d.ts +21 -0
- package/dist/types/api/jsonrpc/index.mjs +0 -0
- package/dist/types/api/rpcspec_0_6/components.cjs +1 -0
- package/dist/types/api/rpcspec_0_6/components.d.ts +541 -0
- package/dist/types/api/rpcspec_0_6/components.mjs +0 -0
- package/dist/types/api/rpcspec_0_6/contract.cjs +1 -0
- package/dist/types/api/rpcspec_0_6/contract.d.ts +85 -0
- package/dist/types/api/rpcspec_0_6/contract.mjs +0 -0
- package/dist/types/api/rpcspec_0_6/errors.cjs +1 -0
- package/dist/types/api/rpcspec_0_6/errors.d.ts +128 -0
- package/dist/types/api/rpcspec_0_6/errors.mjs +0 -0
- package/dist/types/api/rpcspec_0_6/index.cjs +45 -0
- package/dist/types/api/rpcspec_0_6/index.d.ts +8 -0
- package/dist/types/api/rpcspec_0_6/index.mjs +5 -0
- package/dist/types/api/rpcspec_0_6/methods.cjs +1 -0
- package/dist/types/api/rpcspec_0_6/methods.d.ts +207 -0
- package/dist/types/api/rpcspec_0_6/methods.mjs +0 -0
- package/dist/types/api/rpcspec_0_6/nonspec.cjs +65 -0
- package/dist/types/api/rpcspec_0_6/nonspec.d.ts +147 -0
- package/dist/types/api/rpcspec_0_6/nonspec.mjs +59 -0
- package/dist/types/cairoEnum.cjs +1 -0
- package/dist/types/cairoEnum.d.ts +2 -0
- package/dist/types/cairoEnum.mjs +0 -0
- package/dist/types/calldata.cjs +27 -0
- package/dist/types/calldata.d.ts +23 -0
- package/dist/types/calldata.mjs +21 -0
- package/dist/types/contract.cjs +1 -0
- package/dist/types/contract.d.ts +27 -0
- package/dist/types/contract.mjs +0 -0
- package/dist/types/helpers/valuesType.cjs +1 -0
- package/dist/types/helpers/valuesType.d.ts +1 -0
- package/dist/types/helpers/valuesType.mjs +0 -0
- package/dist/types/index.cjs +121 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.mjs +10 -0
- package/dist/types/lib/contract/abi.cjs +1 -0
- package/dist/types/lib/contract/abi.d.ts +71 -0
- package/dist/types/lib/contract/abi.mjs +0 -0
- package/dist/types/lib/contract/index.cjs +50 -0
- package/dist/types/lib/contract/index.d.ts +26 -0
- package/dist/types/lib/contract/index.mjs +8 -0
- package/dist/types/lib/contract/legacy.cjs +1 -0
- package/dist/types/lib/contract/legacy.d.ts +33 -0
- package/dist/types/lib/contract/legacy.mjs +0 -0
- package/dist/types/lib/contract/sierra.cjs +1 -0
- package/dist/types/lib/contract/sierra.d.ts +52 -0
- package/dist/types/lib/contract/sierra.mjs +0 -0
- package/dist/types/lib/index.cjs +61 -0
- package/dist/types/lib/index.d.ts +259 -0
- package/dist/types/lib/index.mjs +36 -0
- package/dist/types/provider/configuration.cjs +1 -0
- package/dist/types/provider/configuration.d.ts +20 -0
- package/dist/types/provider/configuration.mjs +0 -0
- package/dist/types/provider/index.cjs +27 -0
- package/dist/types/provider/index.d.ts +2 -0
- package/dist/types/provider/index.mjs +2 -0
- package/dist/types/provider/response.cjs +30 -0
- package/dist/types/provider/response.d.ts +98 -0
- package/dist/types/provider/response.mjs +1 -0
- package/dist/types/provider/spec.cjs +1 -0
- package/dist/types/provider/spec.d.ts +49 -0
- package/dist/types/provider/spec.mjs +0 -0
- package/dist/types/signer.cjs +1 -0
- package/dist/types/signer.d.ts +49 -0
- package/dist/types/signer.mjs +0 -0
- package/dist/types/transactionReceipt.cjs +1 -0
- package/dist/types/transactionReceipt.d.ts +23 -0
- package/dist/types/transactionReceipt.mjs +0 -0
- package/dist/types/typedData.cjs +12 -0
- package/dist/types/typedData.d.ts +1 -0
- package/dist/types/typedData.mjs +3 -0
- package/dist/utils/address.cjs +44 -0
- package/dist/utils/address.d.ts +55 -0
- package/dist/utils/address.mjs +35 -0
- package/dist/utils/assert.cjs +11 -0
- package/dist/utils/assert.d.ts +12 -0
- package/dist/utils/assert.mjs +5 -0
- package/dist/utils/cairoDataTypes/felt.cjs +31 -0
- package/dist/utils/cairoDataTypes/felt.d.ts +6 -0
- package/dist/utils/cairoDataTypes/felt.mjs +27 -0
- package/dist/utils/cairoDataTypes/uint256.cjs +113 -0
- package/dist/utils/cairoDataTypes/uint256.d.ts +72 -0
- package/dist/utils/cairoDataTypes/uint256.mjs +103 -0
- package/dist/utils/cairoDataTypes/uint512.cjs +125 -0
- package/dist/utils/cairoDataTypes/uint512.d.ts +76 -0
- package/dist/utils/cairoDataTypes/uint512.mjs +123 -0
- package/dist/utils/calldata/byteArray.cjs +27 -0
- package/dist/utils/calldata/byteArray.d.ts +32 -0
- package/dist/utils/calldata/byteArray.mjs +20 -0
- package/dist/utils/calldata/cairo.cjs +114 -0
- package/dist/utils/calldata/cairo.d.ts +196 -0
- package/dist/utils/calldata/cairo.mjs +68 -0
- package/dist/utils/calldata/enum/CairoCustomEnum.cjs +55 -0
- package/dist/utils/calldata/enum/CairoCustomEnum.d.ts +38 -0
- package/dist/utils/calldata/enum/CairoCustomEnum.mjs +50 -0
- package/dist/utils/calldata/enum/CairoOption.cjs +55 -0
- package/dist/utils/calldata/enum/CairoOption.d.ts +37 -0
- package/dist/utils/calldata/enum/CairoOption.mjs +50 -0
- package/dist/utils/calldata/enum/CairoResult.cjs +54 -0
- package/dist/utils/calldata/enum/CairoResult.d.ts +36 -0
- package/dist/utils/calldata/enum/CairoResult.mjs +47 -0
- package/dist/utils/calldata/enum/index.cjs +38 -0
- package/dist/utils/calldata/enum/index.d.ts +3 -0
- package/dist/utils/calldata/enum/index.mjs +3 -0
- package/dist/utils/calldata/formatter.cjs +55 -0
- package/dist/utils/calldata/formatter.d.ts +9 -0
- package/dist/utils/calldata/formatter.mjs +58 -0
- package/dist/utils/calldata/index.cjs +272 -0
- package/dist/utils/calldata/index.d.ts +90 -0
- package/dist/utils/calldata/index.mjs +276 -0
- package/dist/utils/calldata/parser/index.cjs +29 -0
- package/dist/utils/calldata/parser/index.d.ts +5 -0
- package/dist/utils/calldata/parser/index.mjs +21 -0
- package/dist/utils/calldata/parser/interface.cjs +8 -0
- package/dist/utils/calldata/parser/interface.d.ts +20 -0
- package/dist/utils/calldata/parser/interface.mjs +2 -0
- package/dist/utils/calldata/parser/parser-0-1.1.0.cjs +38 -0
- package/dist/utils/calldata/parser/parser-0-1.1.0.d.ts +24 -0
- package/dist/utils/calldata/parser/parser-0-1.1.0.mjs +31 -0
- package/dist/utils/calldata/parser/parser-2.0.0.cjs +42 -0
- package/dist/utils/calldata/parser/parser-2.0.0.d.ts +23 -0
- package/dist/utils/calldata/parser/parser-2.0.0.mjs +37 -0
- package/dist/utils/calldata/propertyOrder.cjs +159 -0
- package/dist/utils/calldata/propertyOrder.d.ts +2 -0
- package/dist/utils/calldata/propertyOrder.mjs +189 -0
- package/dist/utils/calldata/requestParser.cjs +204 -0
- package/dist/utils/calldata/requestParser.d.ts +11 -0
- package/dist/utils/calldata/requestParser.mjs +231 -0
- package/dist/utils/calldata/responseParser.cjs +200 -0
- package/dist/utils/calldata/responseParser.d.ts +11 -0
- package/dist/utils/calldata/responseParser.mjs +201 -0
- package/dist/utils/calldata/tuple.cjs +106 -0
- package/dist/utils/calldata/tuple.d.ts +6 -0
- package/dist/utils/calldata/tuple.mjs +88 -0
- package/dist/utils/calldata/validate.cjs +241 -0
- package/dist/utils/calldata/validate.d.ts +6 -0
- package/dist/utils/calldata/validate.mjs +315 -0
- package/dist/utils/contract.cjs +40 -0
- package/dist/utils/contract.d.ts +37 -0
- package/dist/utils/contract.mjs +31 -0
- package/dist/utils/ec.cjs +12 -0
- package/dist/utils/ec.d.ts +2 -0
- package/dist/utils/ec.mjs +2 -0
- package/dist/utils/encode.cjs +78 -0
- package/dist/utils/encode.d.ts +207 -0
- package/dist/utils/encode.mjs +56 -0
- package/dist/utils/eth.cjs +22 -0
- package/dist/utils/eth.d.ts +22 -0
- package/dist/utils/eth.mjs +14 -0
- package/dist/utils/events/index.cjs +144 -0
- package/dist/utils/events/index.d.ts +84 -0
- package/dist/utils/events/index.mjs +136 -0
- package/dist/utils/fetchPonyfill.cjs +14 -0
- package/dist/utils/fetchPonyfill.d.ts +2 -0
- package/dist/utils/fetchPonyfill.mjs +5 -0
- package/dist/utils/hash/classHash.cjs +151 -0
- package/dist/utils/hash/classHash.d.ts +120 -0
- package/dist/utils/hash/classHash.mjs +168 -0
- package/dist/utils/hash/index.cjs +49 -0
- package/dist/utils/hash/index.d.ts +7 -0
- package/dist/utils/hash/index.mjs +4 -0
- package/dist/utils/hash/selector.cjs +37 -0
- package/dist/utils/hash/selector.d.ts +57 -0
- package/dist/utils/hash/selector.mjs +28 -0
- package/dist/utils/hash/transactionHash/index.cjs +38 -0
- package/dist/utils/hash/transactionHash/index.d.ts +81 -0
- package/dist/utils/hash/transactionHash/index.mjs +102 -0
- package/dist/utils/hash/transactionHash/v2.cjs +31 -0
- package/dist/utils/hash/transactionHash/v2.d.ts +34 -0
- package/dist/utils/hash/transactionHash/v2.mjs +57 -0
- package/dist/utils/hash/transactionHash/v3.cjs +45 -0
- package/dist/utils/hash/transactionHash/v3.d.ts +24 -0
- package/dist/utils/hash/transactionHash/v3.mjs +80 -0
- package/dist/utils/json.cjs +21 -0
- package/dist/utils/json.d.ts +50 -0
- package/dist/utils/json.mjs +10 -0
- package/dist/utils/merkle.cjs +118 -0
- package/dist/utils/merkle.d.ts +87 -0
- package/dist/utils/merkle.mjs +114 -0
- package/dist/utils/num.cjs +109 -0
- package/dist/utils/num.d.ts +283 -0
- package/dist/utils/num.mjs +86 -0
- package/dist/utils/provider.cjs +182 -0
- package/dist/utils/provider.d.ts +217 -0
- package/dist/utils/provider.mjs +158 -0
- package/dist/utils/responseParser/index.cjs +27 -0
- package/dist/utils/responseParser/index.d.ts +2 -0
- package/dist/utils/responseParser/index.mjs +2 -0
- package/dist/utils/responseParser/interface.cjs +8 -0
- package/dist/utils/responseParser/interface.d.ts +13 -0
- package/dist/utils/responseParser/interface.mjs +2 -0
- package/dist/utils/responseParser/rpc.cjs +83 -0
- package/dist/utils/responseParser/rpc.d.ts +19 -0
- package/dist/utils/responseParser/rpc.mjs +77 -0
- package/dist/utils/shortString.cjs +56 -0
- package/dist/utils/shortString.d.ts +116 -0
- package/dist/utils/shortString.mjs +39 -0
- package/dist/utils/stark.cjs +137 -0
- package/dist/utils/stark.d.ts +224 -0
- package/dist/utils/stark.mjs +109 -0
- package/dist/utils/starknetId.cjs +196 -0
- package/dist/utils/starknetId.d.ts +182 -0
- package/dist/utils/starknetId.mjs +185 -0
- package/dist/utils/transaction.cjs +115 -0
- package/dist/utils/transaction.d.ts +185 -0
- package/dist/utils/transaction.mjs +98 -0
- package/dist/utils/transactionReceipt.cjs +54 -0
- package/dist/utils/transactionReceipt.d.ts +33 -0
- package/dist/utils/transactionReceipt.mjs +49 -0
- package/dist/utils/typedData.cjs +285 -0
- package/dist/utils/typedData.d.ts +54 -0
- package/dist/utils/typedData.mjs +286 -0
- package/dist/utils/uint256.cjs +30 -0
- package/dist/utils/uint256.d.ts +45 -0
- package/dist/utils/uint256.mjs +11 -0
- package/dist/utils/url.cjs +35 -0
- package/dist/utils/url.d.ts +29 -0
- package/dist/utils/url.mjs +27 -0
- package/dist/wallet/account.cjs +115 -0
- package/dist/wallet/account.d.ts +31 -0
- package/dist/wallet/account.mjs +112 -0
- package/dist/wallet/connect.cjs +90 -0
- package/dist/wallet/connect.d.ts +82 -0
- package/dist/wallet/connect.mjs +64 -0
- package/dist/wallet/index.cjs +16 -0
- package/dist/wallet/index.d.ts +1 -0
- package/dist/wallet/index.mjs +1 -0
- package/dist/wallet/types.cjs +1 -0
- package/dist/wallet/types.d.ts +4 -0
- package/dist/wallet/types.mjs +0 -0
- package/package.json +13 -13
- package/dist/index.js +0 -7426
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { NetworkName } from '../constants';
|
|
2
|
+
import { BlockIdentifier, CompiledContract, CompiledSierra, ContractClass, GetBlockResponse, InvocationsDetailsWithNonce, PendingBlock, PendingStateUpdate, SierraContractClass, StateUpdateResponse, V3TransactionDetails } from '../types';
|
|
3
|
+
import type { GetTransactionReceiptResponse } from './transactionReceipt';
|
|
4
|
+
/**
|
|
5
|
+
* Helper - Async Sleep for 'delay' time
|
|
6
|
+
*
|
|
7
|
+
* @param {number} delay - Number of milliseconds to delay
|
|
8
|
+
* @returns {Promise<unknown>}
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* await provider.wait(1000) // 1000 milliseconds == 1 second
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function wait(delay: number): Promise<unknown>;
|
|
15
|
+
/**
|
|
16
|
+
* Create Sierra compressed Contract Class from a given Compiled Sierra
|
|
17
|
+
*
|
|
18
|
+
* CompiledSierra -> SierraContractClass
|
|
19
|
+
*
|
|
20
|
+
* @param {CompiledSierra} contract sierra code from the Cairo compiler
|
|
21
|
+
* @returns {SierraContractClass} compressed Sierra
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const result = provider.createSierraContractClass({
|
|
25
|
+
"sierra_program": [
|
|
26
|
+
"0x1",
|
|
27
|
+
"0x4",
|
|
28
|
+
"0x0",
|
|
29
|
+
"0x2",
|
|
30
|
+
"0x4",
|
|
31
|
+
"0x1",
|
|
32
|
+
"0x3b4",
|
|
33
|
+
"0x4c",
|
|
34
|
+
"0x65",
|
|
35
|
+
"0x52616e6765436865636b",...})
|
|
36
|
+
* // result = {sierra_program: 'H4sIAAAAAAAAA6x9WZbsrI7uVGqd53qgb8ZynwzYY7jDv5JAAmxHZuQ+96yq/L0jIzEINZ8axP/5j/q/+j//+z/wH9f/o/p/zPbh+Iot49+u9v8G3//rTdDhDDF4Z0MKPthQ+m+S2v6n1S//638VvdXW2PQ6RvxuDG+jiybCXKJ7Hef6ZRi9E+Q89WmKLilfqbrsL6PUCf8...}
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function createSierraContractClass(contract: CompiledSierra): SierraContractClass;
|
|
40
|
+
/**
|
|
41
|
+
* Create a compressed contract from a given compiled Cairo 0 & 1 contract or a string.
|
|
42
|
+
* @param {CompiledContract | string} contract - Compiled Cairo 0 or Cairo 1 contract, or string
|
|
43
|
+
* @returns {ContractClass} Cairo 0 or Cairo 1 compressed contract
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const result = provider.parseContract({
|
|
47
|
+
"sierra_program": [
|
|
48
|
+
"0x1",
|
|
49
|
+
"0x4",
|
|
50
|
+
"0x0",
|
|
51
|
+
"0x2",
|
|
52
|
+
"0x4",
|
|
53
|
+
"0x1",
|
|
54
|
+
"0x3b4",
|
|
55
|
+
"0x4c",
|
|
56
|
+
"0x65",
|
|
57
|
+
"0x52616e6765436865636b",...})
|
|
58
|
+
* // result = {sierra_program: 'H4sIAAAAAAAAA6x9WZbsrI7uVGqd53qgb8ZynwzYY7jDv5JAAmxHZuQ+96yq/L0jIzEINZ8axP/5j/q/+j//+z/wH9f/o/p/zPbh+Iot49+u9v8G3//rTdDhDDF4Z0MKPthQ+m+S2v6n1S//638VvdXW2PQ6RvxuDG+jiybCXKJ7Hef6ZRi9E+Q89WmKLilfqbrsL6PUCf8...}
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function parseContract(contract: CompiledContract | string): ContractClass;
|
|
62
|
+
/**
|
|
63
|
+
* Return randomly select available public node
|
|
64
|
+
* @param {NetworkName} networkName NetworkName
|
|
65
|
+
* @param {boolean} mute mute public node warning
|
|
66
|
+
* @returns {string} default node url
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const result= provider.getDefaultNodeUrl(constants.NetworkName.SN_MAIN,false);
|
|
70
|
+
* // console : "Using default public node url, please provide nodeUrl in provider options!"
|
|
71
|
+
* // result = "https://starknet-mainnet.public.blastapi.io/rpc/v0_7"
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare const getDefaultNodeUrl: (networkName?: NetworkName, mute?: boolean) => string;
|
|
75
|
+
export declare const validBlockTags: ("latest" | "pending")[];
|
|
76
|
+
/**
|
|
77
|
+
* This class is formatting the identifier of a block.
|
|
78
|
+
*
|
|
79
|
+
* hex string and BigInt are detected as block hashes. identifier return { block_hash: hash }
|
|
80
|
+
*
|
|
81
|
+
* decimal string and number are detected as block numbers. identifier return { block_number: number }
|
|
82
|
+
*
|
|
83
|
+
* text string are detected as block tag. identifier return tag
|
|
84
|
+
*
|
|
85
|
+
* null is detected as 'pending' block tag. identifier return 'pending'
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const result = new provider.Block(null).identifier;
|
|
89
|
+
* // result = "pending"
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare class Block {
|
|
93
|
+
/**
|
|
94
|
+
* @param {BlockIdentifier} hash if not null, contains the block hash
|
|
95
|
+
*/
|
|
96
|
+
hash: BlockIdentifier;
|
|
97
|
+
/**
|
|
98
|
+
* @param {BlockIdentifier} number if not null, contains the block number
|
|
99
|
+
*/
|
|
100
|
+
number: BlockIdentifier;
|
|
101
|
+
/**
|
|
102
|
+
* @param {BlockIdentifier} tag if not null, contains "pending" or "latest"
|
|
103
|
+
*/
|
|
104
|
+
tag: BlockIdentifier;
|
|
105
|
+
private setIdentifier;
|
|
106
|
+
/**
|
|
107
|
+
* Create a Block instance
|
|
108
|
+
* @param {BlockIdentifier} _identifier hex string and BigInt are detected as block hashes.
|
|
109
|
+
* decimal string and number are detected as block numbers.
|
|
110
|
+
* text string are detected as block tag.
|
|
111
|
+
* null is considered as a 'pending' block tag.
|
|
112
|
+
*/
|
|
113
|
+
constructor(_identifier: BlockIdentifier);
|
|
114
|
+
/**
|
|
115
|
+
* @returns {any} the identifier as a string
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const result = new provider.Block(123456n).queryIdentifier;
|
|
119
|
+
* // result = "blockHash=0x1e240"
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
get queryIdentifier(): any;
|
|
123
|
+
/**
|
|
124
|
+
* @returns {any} the identifier as an object
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const result = new provider.Block(56789).identifier;
|
|
128
|
+
* // result = { block_number: 56789 }
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
get identifier(): any;
|
|
132
|
+
/**
|
|
133
|
+
* change the identifier of an existing Block instance
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const myBlock = new provider.Block("latest");
|
|
137
|
+
* myBlock.identifier ="0x3456789abc";
|
|
138
|
+
* const result = myBlock.identifier;
|
|
139
|
+
* // result = { block_hash: '0x3456789abc' }
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
set identifier(_identifier: BlockIdentifier);
|
|
143
|
+
valueOf: () => BlockIdentifier;
|
|
144
|
+
toString: () => BlockIdentifier;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Check if the given transaction details is a V3 transaction.
|
|
148
|
+
*
|
|
149
|
+
* @param {InvocationsDetailsWithNonce} details The transaction details to be checked.
|
|
150
|
+
* @return {boolean} Returns true if the transaction is a V3 transaction, otherwise false.
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* const invocation: InvocationsDetailsWithNonce = {
|
|
154
|
+
* nonce: 1,
|
|
155
|
+
* version: 3,
|
|
156
|
+
* maxFee: 10 ** 15,
|
|
157
|
+
* feeDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,
|
|
158
|
+
* tip: 10 ** 13,
|
|
159
|
+
* paymasterData: [],
|
|
160
|
+
* resourceBounds: {
|
|
161
|
+
* l1_gas: { max_amount: num.toHex(10 ** 14), max_price_per_unit: num.toHex(50) },
|
|
162
|
+
* l2_gas: { max_amount: num.toHex(0), max_price_per_unit: num.toHex(0) }}};
|
|
163
|
+
* const result = provider.isV3Tx(invocation);
|
|
164
|
+
* // result = true
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
export declare function isV3Tx(details: InvocationsDetailsWithNonce): details is V3TransactionDetails;
|
|
168
|
+
/**
|
|
169
|
+
* Determines if the given response matches the specified version.
|
|
170
|
+
*
|
|
171
|
+
* @param {('0.5' | '0.6' | '0.7')} version The version to compare against the response.
|
|
172
|
+
* @param {string} response The response to check against the version.
|
|
173
|
+
* @returns {boolean} True if the response matches the version, false otherwise.
|
|
174
|
+
* @example
|
|
175
|
+
* ``` typescript
|
|
176
|
+
* const result = provider.isVersion("0.7","0_7");
|
|
177
|
+
* // result = false
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
export declare function isVersion(version: '0.5' | '0.6' | '0.7', response: string): boolean;
|
|
181
|
+
/**
|
|
182
|
+
* Guard Pending Block
|
|
183
|
+
* @param {GetBlockResponse} response answer of myProvider.getBlock()
|
|
184
|
+
* @return {boolean} true if block is the pending block
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* const block = await myProvider.getBlock("pending");
|
|
188
|
+
* const result = provider.isPendingBlock(block);
|
|
189
|
+
* // result = true
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
export declare function isPendingBlock(response: GetBlockResponse): response is PendingBlock;
|
|
193
|
+
/**
|
|
194
|
+
* Guard Pending Transaction
|
|
195
|
+
* @param {GetTransactionReceiptResponse} response transaction Receipt
|
|
196
|
+
* @return {boolean} true if the transaction is part of the pending block
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* const block = await myProvider.getBlockWithTxs("pending");
|
|
200
|
+
* const txR = await myProvider.getTransactionReceipt(block.transactions[0].transaction_hash);
|
|
201
|
+
* const result = provider.isPendingTransaction(txR);
|
|
202
|
+
* // result = true
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
export declare function isPendingTransaction(response: GetTransactionReceiptResponse): boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Guard Pending State Update
|
|
208
|
+
* @param {StateUpdateResponse} response State of a block
|
|
209
|
+
* @return {boolean} true if the block is pending
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* const state: StateUpdateResponse = await myProvider.getStateUpdate("pending");
|
|
213
|
+
* const result = provider.isPendingStateUpdate(state);
|
|
214
|
+
* // result = true
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
export declare function isPendingStateUpdate(response: StateUpdateResponse): response is PendingStateUpdate;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { NetworkName, RPC_NODES } from "../constants.mjs";
|
|
2
|
+
import {
|
|
3
|
+
BlockTag
|
|
4
|
+
} from "../types/index.mjs";
|
|
5
|
+
import { ETransactionVersion } from "../types/api/index.mjs";
|
|
6
|
+
import { isSierra } from "./contract.mjs";
|
|
7
|
+
import { formatSpaces } from "./hash/index.mjs";
|
|
8
|
+
import { parse, stringify } from "./json.mjs";
|
|
9
|
+
import { isBigInt, isHex, isNumber, toHex } from "./num.mjs";
|
|
10
|
+
import { isDecimalString, isString } from "./shortString.mjs";
|
|
11
|
+
import { compressProgram } from "./stark.mjs";
|
|
12
|
+
export function wait(delay) {
|
|
13
|
+
return new Promise((res) => {
|
|
14
|
+
setTimeout(res, delay);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export function createSierraContractClass(contract) {
|
|
18
|
+
const result = { ...contract };
|
|
19
|
+
delete result.sierra_program_debug_info;
|
|
20
|
+
result.abi = formatSpaces(stringify(contract.abi));
|
|
21
|
+
result.sierra_program = formatSpaces(stringify(contract.sierra_program));
|
|
22
|
+
result.sierra_program = compressProgram(result.sierra_program);
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
export function parseContract(contract) {
|
|
26
|
+
const parsedContract = isString(contract) ? parse(contract) : contract;
|
|
27
|
+
if (!isSierra(contract)) {
|
|
28
|
+
return {
|
|
29
|
+
...parsedContract,
|
|
30
|
+
..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return createSierraContractClass(parsedContract);
|
|
34
|
+
}
|
|
35
|
+
export const getDefaultNodeUrl = (networkName, mute = false) => {
|
|
36
|
+
if (!mute) {
|
|
37
|
+
console.warn("Using default public node url, please provide nodeUrl in provider options!");
|
|
38
|
+
}
|
|
39
|
+
const nodes = RPC_NODES[networkName ?? NetworkName.SN_SEPOLIA];
|
|
40
|
+
const randIdx = Math.floor(Math.random() * nodes.length);
|
|
41
|
+
return nodes[randIdx];
|
|
42
|
+
};
|
|
43
|
+
export const validBlockTags = Object.values(BlockTag);
|
|
44
|
+
export class Block {
|
|
45
|
+
/**
|
|
46
|
+
* @param {BlockIdentifier} hash if not null, contains the block hash
|
|
47
|
+
*/
|
|
48
|
+
hash = null;
|
|
49
|
+
/**
|
|
50
|
+
* @param {BlockIdentifier} number if not null, contains the block number
|
|
51
|
+
*/
|
|
52
|
+
number = null;
|
|
53
|
+
/**
|
|
54
|
+
* @param {BlockIdentifier} tag if not null, contains "pending" or "latest"
|
|
55
|
+
*/
|
|
56
|
+
tag = null;
|
|
57
|
+
setIdentifier(__identifier) {
|
|
58
|
+
if (isString(__identifier)) {
|
|
59
|
+
if (isDecimalString(__identifier)) {
|
|
60
|
+
this.number = parseInt(__identifier, 10);
|
|
61
|
+
} else if (isHex(__identifier)) {
|
|
62
|
+
this.hash = __identifier;
|
|
63
|
+
} else if (validBlockTags.includes(__identifier)) {
|
|
64
|
+
this.tag = __identifier;
|
|
65
|
+
} else {
|
|
66
|
+
throw TypeError(`Block identifier unmanaged: ${__identifier}`);
|
|
67
|
+
}
|
|
68
|
+
} else if (isBigInt(__identifier)) {
|
|
69
|
+
this.hash = toHex(__identifier);
|
|
70
|
+
} else if (isNumber(__identifier)) {
|
|
71
|
+
this.number = __identifier;
|
|
72
|
+
} else {
|
|
73
|
+
this.tag = BlockTag.PENDING;
|
|
74
|
+
}
|
|
75
|
+
if (isNumber(this.number) && this.number < 0) {
|
|
76
|
+
throw TypeError(`Block number (${this.number}) can't be negative`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Create a Block instance
|
|
81
|
+
* @param {BlockIdentifier} _identifier hex string and BigInt are detected as block hashes.
|
|
82
|
+
* decimal string and number are detected as block numbers.
|
|
83
|
+
* text string are detected as block tag.
|
|
84
|
+
* null is considered as a 'pending' block tag.
|
|
85
|
+
*/
|
|
86
|
+
constructor(_identifier) {
|
|
87
|
+
this.setIdentifier(_identifier);
|
|
88
|
+
}
|
|
89
|
+
// TODO: fix any
|
|
90
|
+
/**
|
|
91
|
+
* @returns {any} the identifier as a string
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const result = new provider.Block(123456n).queryIdentifier;
|
|
95
|
+
* // result = "blockHash=0x1e240"
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
get queryIdentifier() {
|
|
99
|
+
if (this.number !== null) {
|
|
100
|
+
return `blockNumber=${this.number}`;
|
|
101
|
+
}
|
|
102
|
+
if (this.hash !== null) {
|
|
103
|
+
return `blockHash=${this.hash}`;
|
|
104
|
+
}
|
|
105
|
+
return `blockNumber=${this.tag}`;
|
|
106
|
+
}
|
|
107
|
+
// TODO: fix any
|
|
108
|
+
/**
|
|
109
|
+
* @returns {any} the identifier as an object
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const result = new provider.Block(56789).identifier;
|
|
113
|
+
* // result = { block_number: 56789 }
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
get identifier() {
|
|
117
|
+
if (this.number !== null) {
|
|
118
|
+
return { block_number: this.number };
|
|
119
|
+
}
|
|
120
|
+
if (this.hash !== null) {
|
|
121
|
+
return { block_hash: this.hash };
|
|
122
|
+
}
|
|
123
|
+
return this.tag;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* change the identifier of an existing Block instance
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* const myBlock = new provider.Block("latest");
|
|
130
|
+
* myBlock.identifier ="0x3456789abc";
|
|
131
|
+
* const result = myBlock.identifier;
|
|
132
|
+
* // result = { block_hash: '0x3456789abc' }
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
set identifier(_identifier) {
|
|
136
|
+
this.setIdentifier(_identifier);
|
|
137
|
+
}
|
|
138
|
+
valueOf = () => this.number;
|
|
139
|
+
toString = () => this.hash;
|
|
140
|
+
}
|
|
141
|
+
export function isV3Tx(details) {
|
|
142
|
+
const version = details.version ? toHex(details.version) : ETransactionVersion.V3;
|
|
143
|
+
return version === ETransactionVersion.V3 || version === ETransactionVersion.F3;
|
|
144
|
+
}
|
|
145
|
+
export function isVersion(version, response) {
|
|
146
|
+
const [majorS, minorS] = version.split(".");
|
|
147
|
+
const [majorR, minorR] = response.split(".");
|
|
148
|
+
return majorS === majorR && minorS === minorR;
|
|
149
|
+
}
|
|
150
|
+
export function isPendingBlock(response) {
|
|
151
|
+
return response.status === "PENDING";
|
|
152
|
+
}
|
|
153
|
+
export function isPendingTransaction(response) {
|
|
154
|
+
return !("block_hash" in response);
|
|
155
|
+
}
|
|
156
|
+
export function isPendingStateUpdate(response) {
|
|
157
|
+
return !("block_hash" in response);
|
|
158
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _interface = require("./interface.cjs");
|
|
7
|
+
Object.keys(_interface).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _interface[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _interface[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _rpc = require("./rpc.cjs");
|
|
18
|
+
Object.keys(_rpc).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _rpc[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _rpc[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BlockWithTxHashes, FeeEstimate, CallContractResponse, DeclareContractResponse, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionResponse, InvokeFunctionResponse, SimulateTransactionResponse } from '../../types';
|
|
2
|
+
import type { GetTransactionReceiptResponse } from '../transactionReceipt';
|
|
3
|
+
export declare abstract class ResponseParser {
|
|
4
|
+
abstract parseGetBlockResponse(res: BlockWithTxHashes): GetBlockResponse;
|
|
5
|
+
abstract parseGetTransactionResponse(res: any): GetTransactionResponse;
|
|
6
|
+
abstract parseGetTransactionReceiptResponse(res: any): GetTransactionReceiptResponse;
|
|
7
|
+
abstract parseFeeEstimateResponse(res: FeeEstimate[]): EstimateFeeResponse;
|
|
8
|
+
abstract parseCallContractResponse(res: any): CallContractResponse;
|
|
9
|
+
abstract parseInvokeFunctionResponse(res: any): InvokeFunctionResponse;
|
|
10
|
+
abstract parseDeployContractResponse(res: any): DeployContractResponse;
|
|
11
|
+
abstract parseDeclareContractResponse(res: any): DeclareContractResponse;
|
|
12
|
+
abstract parseSimulateTransactionResponse(res: any): SimulateTransactionResponse;
|
|
13
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.RPCResponseParser = void 0;
|
|
7
|
+
var _num = require("../num.cjs");
|
|
8
|
+
var _shortString = require("../shortString.cjs");
|
|
9
|
+
var _stark = require("../stark.cjs");
|
|
10
|
+
class RPCResponseParser {
|
|
11
|
+
margin;
|
|
12
|
+
constructor(margin) {
|
|
13
|
+
this.margin = margin;
|
|
14
|
+
}
|
|
15
|
+
estimatedFeeToMaxFee(estimatedFee) {
|
|
16
|
+
return (0, _stark.estimatedFeeToMaxFee)(estimatedFee, this.margin?.maxFee);
|
|
17
|
+
}
|
|
18
|
+
estimateFeeToBounds(estimate) {
|
|
19
|
+
return (0, _stark.estimateFeeToBounds)(estimate, this.margin?.l1BoundMaxAmount, this.margin?.l1BoundMaxPricePerUnit);
|
|
20
|
+
}
|
|
21
|
+
parseGetBlockResponse(res) {
|
|
22
|
+
return {
|
|
23
|
+
status: "PENDING",
|
|
24
|
+
...res
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
parseTransactionReceipt(res) {
|
|
28
|
+
if ("actual_fee" in res && (0, _shortString.isString)(res.actual_fee)) {
|
|
29
|
+
return {
|
|
30
|
+
...res,
|
|
31
|
+
actual_fee: {
|
|
32
|
+
amount: res.actual_fee,
|
|
33
|
+
unit: "FRI"
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return res;
|
|
38
|
+
}
|
|
39
|
+
parseFeeEstimateResponse(res) {
|
|
40
|
+
const val = res[0];
|
|
41
|
+
return {
|
|
42
|
+
overall_fee: (0, _num.toBigInt)(val.overall_fee),
|
|
43
|
+
gas_consumed: (0, _num.toBigInt)(val.gas_consumed),
|
|
44
|
+
gas_price: (0, _num.toBigInt)(val.gas_price),
|
|
45
|
+
unit: val.unit,
|
|
46
|
+
suggestedMaxFee: this.estimatedFeeToMaxFee(val.overall_fee),
|
|
47
|
+
resourceBounds: this.estimateFeeToBounds(val),
|
|
48
|
+
data_gas_consumed: val.data_gas_consumed ? (0, _num.toBigInt)(val.data_gas_consumed) : 0n,
|
|
49
|
+
data_gas_price: val.data_gas_price ? (0, _num.toBigInt)(val.data_gas_price) : 0n
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
parseFeeEstimateBulkResponse(res) {
|
|
53
|
+
return res.map(val => ({
|
|
54
|
+
overall_fee: (0, _num.toBigInt)(val.overall_fee),
|
|
55
|
+
gas_consumed: (0, _num.toBigInt)(val.gas_consumed),
|
|
56
|
+
gas_price: (0, _num.toBigInt)(val.gas_price),
|
|
57
|
+
unit: val.unit,
|
|
58
|
+
suggestedMaxFee: this.estimatedFeeToMaxFee(val.overall_fee),
|
|
59
|
+
resourceBounds: this.estimateFeeToBounds(val),
|
|
60
|
+
data_gas_consumed: val.data_gas_consumed ? (0, _num.toBigInt)(val.data_gas_consumed) : 0n,
|
|
61
|
+
data_gas_price: val.data_gas_price ? (0, _num.toBigInt)(val.data_gas_price) : 0n
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
parseSimulateTransactionResponse(res) {
|
|
65
|
+
return res.map(it => {
|
|
66
|
+
return {
|
|
67
|
+
...it,
|
|
68
|
+
suggestedMaxFee: this.estimatedFeeToMaxFee(it.fee_estimation.overall_fee),
|
|
69
|
+
resourceBounds: this.estimateFeeToBounds(it.fee_estimation)
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
parseContractClassResponse(res) {
|
|
74
|
+
return {
|
|
75
|
+
...res,
|
|
76
|
+
abi: (0, _shortString.isString)(res.abi) ? JSON.parse(res.abi) : res.abi
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
parseL1GasPriceResponse(res) {
|
|
80
|
+
return res.l1_gas_price.price_in_wei;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.RPCResponseParser = RPCResponseParser;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map RPC Response to common interface response
|
|
3
|
+
* Intersection (sequencer response ∩ (∪ rpc responses))
|
|
4
|
+
*/
|
|
5
|
+
import type { BlockWithTxHashes, ContractClassPayload, ContractClassResponse, EstimateFeeResponse, EstimateFeeResponseBulk, FeeEstimate, GetBlockResponse, GetTxReceiptResponseWithoutHelper, RpcProviderOptions, SimulateTransactionResponse, TransactionReceipt } from '../../types/provider';
|
|
6
|
+
import { ResponseParser } from './interface';
|
|
7
|
+
export declare class RPCResponseParser implements Omit<ResponseParser, 'parseDeclareContractResponse' | 'parseDeployContractResponse' | 'parseInvokeFunctionResponse' | 'parseGetTransactionReceiptResponse' | 'parseGetTransactionResponse' | 'parseCallContractResponse'> {
|
|
8
|
+
private margin;
|
|
9
|
+
constructor(margin?: RpcProviderOptions['feeMarginPercentage']);
|
|
10
|
+
private estimatedFeeToMaxFee;
|
|
11
|
+
private estimateFeeToBounds;
|
|
12
|
+
parseGetBlockResponse(res: BlockWithTxHashes): GetBlockResponse;
|
|
13
|
+
parseTransactionReceipt(res: TransactionReceipt): GetTxReceiptResponseWithoutHelper;
|
|
14
|
+
parseFeeEstimateResponse(res: FeeEstimate[]): EstimateFeeResponse;
|
|
15
|
+
parseFeeEstimateBulkResponse(res: FeeEstimate[]): EstimateFeeResponseBulk;
|
|
16
|
+
parseSimulateTransactionResponse(res: any): SimulateTransactionResponse;
|
|
17
|
+
parseContractClassResponse(res: ContractClassPayload): ContractClassResponse;
|
|
18
|
+
parseL1GasPriceResponse(res: BlockWithTxHashes): string;
|
|
19
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { toBigInt } from "../num.mjs";
|
|
2
|
+
import { isString } from "../shortString.mjs";
|
|
3
|
+
import { estimateFeeToBounds, estimatedFeeToMaxFee } from "../stark.mjs";
|
|
4
|
+
export class RPCResponseParser {
|
|
5
|
+
margin;
|
|
6
|
+
constructor(margin) {
|
|
7
|
+
this.margin = margin;
|
|
8
|
+
}
|
|
9
|
+
estimatedFeeToMaxFee(estimatedFee) {
|
|
10
|
+
return estimatedFeeToMaxFee(estimatedFee, this.margin?.maxFee);
|
|
11
|
+
}
|
|
12
|
+
estimateFeeToBounds(estimate) {
|
|
13
|
+
return estimateFeeToBounds(
|
|
14
|
+
estimate,
|
|
15
|
+
this.margin?.l1BoundMaxAmount,
|
|
16
|
+
this.margin?.l1BoundMaxPricePerUnit
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
parseGetBlockResponse(res) {
|
|
20
|
+
return { status: "PENDING", ...res };
|
|
21
|
+
}
|
|
22
|
+
parseTransactionReceipt(res) {
|
|
23
|
+
if ("actual_fee" in res && isString(res.actual_fee)) {
|
|
24
|
+
return {
|
|
25
|
+
...res,
|
|
26
|
+
actual_fee: {
|
|
27
|
+
amount: res.actual_fee,
|
|
28
|
+
unit: "FRI"
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return res;
|
|
33
|
+
}
|
|
34
|
+
parseFeeEstimateResponse(res) {
|
|
35
|
+
const val = res[0];
|
|
36
|
+
return {
|
|
37
|
+
overall_fee: toBigInt(val.overall_fee),
|
|
38
|
+
gas_consumed: toBigInt(val.gas_consumed),
|
|
39
|
+
gas_price: toBigInt(val.gas_price),
|
|
40
|
+
unit: val.unit,
|
|
41
|
+
suggestedMaxFee: this.estimatedFeeToMaxFee(val.overall_fee),
|
|
42
|
+
resourceBounds: this.estimateFeeToBounds(val),
|
|
43
|
+
data_gas_consumed: val.data_gas_consumed ? toBigInt(val.data_gas_consumed) : 0n,
|
|
44
|
+
data_gas_price: val.data_gas_price ? toBigInt(val.data_gas_price) : 0n
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
parseFeeEstimateBulkResponse(res) {
|
|
48
|
+
return res.map((val) => ({
|
|
49
|
+
overall_fee: toBigInt(val.overall_fee),
|
|
50
|
+
gas_consumed: toBigInt(val.gas_consumed),
|
|
51
|
+
gas_price: toBigInt(val.gas_price),
|
|
52
|
+
unit: val.unit,
|
|
53
|
+
suggestedMaxFee: this.estimatedFeeToMaxFee(val.overall_fee),
|
|
54
|
+
resourceBounds: this.estimateFeeToBounds(val),
|
|
55
|
+
data_gas_consumed: val.data_gas_consumed ? toBigInt(val.data_gas_consumed) : 0n,
|
|
56
|
+
data_gas_price: val.data_gas_price ? toBigInt(val.data_gas_price) : 0n
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
parseSimulateTransactionResponse(res) {
|
|
60
|
+
return res.map((it) => {
|
|
61
|
+
return {
|
|
62
|
+
...it,
|
|
63
|
+
suggestedMaxFee: this.estimatedFeeToMaxFee(it.fee_estimation.overall_fee),
|
|
64
|
+
resourceBounds: this.estimateFeeToBounds(it.fee_estimation)
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
parseContractClassResponse(res) {
|
|
69
|
+
return {
|
|
70
|
+
...res,
|
|
71
|
+
abi: isString(res.abi) ? JSON.parse(res.abi) : res.abi
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
parseL1GasPriceResponse(res) {
|
|
75
|
+
return res.l1_gas_price.price_in_wei;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.decodeShortString = decodeShortString;
|
|
7
|
+
exports.encodeShortString = encodeShortString;
|
|
8
|
+
exports.isASCII = isASCII;
|
|
9
|
+
exports.isDecimalString = isDecimalString;
|
|
10
|
+
exports.isLongText = void 0;
|
|
11
|
+
exports.isShortString = isShortString;
|
|
12
|
+
exports.isShortText = void 0;
|
|
13
|
+
exports.isString = isString;
|
|
14
|
+
exports.isText = isText;
|
|
15
|
+
exports.splitLongString = splitLongString;
|
|
16
|
+
var _constants = require("../constants.cjs");
|
|
17
|
+
var _encode = require("./encode.cjs");
|
|
18
|
+
var _num = require("./num.cjs");
|
|
19
|
+
function isASCII(str) {
|
|
20
|
+
return /^[\x00-\x7F]*$/.test(str);
|
|
21
|
+
}
|
|
22
|
+
function isShortString(str) {
|
|
23
|
+
return str.length <= _constants.TEXT_TO_FELT_MAX_LEN;
|
|
24
|
+
}
|
|
25
|
+
function isDecimalString(str) {
|
|
26
|
+
return /^[0-9]*$/i.test(str);
|
|
27
|
+
}
|
|
28
|
+
function isString(value) {
|
|
29
|
+
return typeof value === "string";
|
|
30
|
+
}
|
|
31
|
+
function isText(val) {
|
|
32
|
+
return isString(val) && !(0, _num.isHex)(val) && !(0, _num.isStringWholeNumber)(val);
|
|
33
|
+
}
|
|
34
|
+
const isShortText = val => isText(val) && isShortString(val);
|
|
35
|
+
exports.isShortText = isShortText;
|
|
36
|
+
const isLongText = val => isText(val) && !isShortString(val);
|
|
37
|
+
exports.isLongText = isLongText;
|
|
38
|
+
function splitLongString(longStr) {
|
|
39
|
+
const regex = RegExp(`[^]{1,${_constants.TEXT_TO_FELT_MAX_LEN}}`, "g");
|
|
40
|
+
return longStr.match(regex) || [];
|
|
41
|
+
}
|
|
42
|
+
function encodeShortString(str) {
|
|
43
|
+
if (!isASCII(str)) throw new Error(`${str} is not an ASCII string`);
|
|
44
|
+
if (!isShortString(str)) throw new Error(`${str} is too long`);
|
|
45
|
+
return (0, _encode.addHexPrefix)(str.replace(/./g, char => char.charCodeAt(0).toString(16)));
|
|
46
|
+
}
|
|
47
|
+
function decodeShortString(str) {
|
|
48
|
+
if (!isASCII(str)) throw new Error(`${str} is not an ASCII string`);
|
|
49
|
+
if ((0, _num.isHex)(str)) {
|
|
50
|
+
return (0, _encode.removeHexPrefix)(str).replace(/.{2}/g, hex => String.fromCharCode(parseInt(hex, 16)));
|
|
51
|
+
}
|
|
52
|
+
if (isDecimalString(str)) {
|
|
53
|
+
return decodeShortString("0X".concat(BigInt(str).toString(16)));
|
|
54
|
+
}
|
|
55
|
+
throw new Error(`${str} is not Hex or decimal`);
|
|
56
|
+
}
|