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,70 @@
|
|
|
1
|
+
import { ETransactionVersion } from './types/api';
|
|
2
|
+
import { ValuesType } from './types/helpers/valuesType';
|
|
3
|
+
export { IS_BROWSER } from './utils/encode';
|
|
4
|
+
/**
|
|
5
|
+
* Cairo Felt support storing max 31 character
|
|
6
|
+
*/
|
|
7
|
+
export declare const TEXT_TO_FELT_MAX_LEN = 31;
|
|
8
|
+
/**
|
|
9
|
+
* Alternatively use directly from api specification
|
|
10
|
+
* types.RPC.ETransactionVersion
|
|
11
|
+
* For BN do BigInt(TRANSACTION_VERSION.*)
|
|
12
|
+
*/
|
|
13
|
+
export { ETransactionVersion as TRANSACTION_VERSION };
|
|
14
|
+
export declare const ZERO = 0n;
|
|
15
|
+
export declare const MASK_250: bigint;
|
|
16
|
+
export declare const API_VERSION = 0n;
|
|
17
|
+
export declare const PRIME: bigint;
|
|
18
|
+
export declare const MAX_STORAGE_ITEM_SIZE = 256n;
|
|
19
|
+
export declare const ADDR_BOUND: bigint;
|
|
20
|
+
export declare const RANGE_FELT: {
|
|
21
|
+
readonly min: bigint;
|
|
22
|
+
readonly max: bigint;
|
|
23
|
+
};
|
|
24
|
+
export declare const RANGE_I128: {
|
|
25
|
+
readonly min: bigint;
|
|
26
|
+
readonly max: bigint;
|
|
27
|
+
};
|
|
28
|
+
export declare const RANGE_U128: {
|
|
29
|
+
readonly min: bigint;
|
|
30
|
+
readonly max: bigint;
|
|
31
|
+
};
|
|
32
|
+
export declare const BaseUrl: {
|
|
33
|
+
readonly SN_MAIN: "https://alpha-mainnet.starknet.io";
|
|
34
|
+
readonly SN_SEPOLIA: "https://alpha-sepolia.starknet.io";
|
|
35
|
+
};
|
|
36
|
+
export type BaseUrl = ValuesType<typeof BaseUrl>;
|
|
37
|
+
export declare const NetworkName: {
|
|
38
|
+
readonly SN_MAIN: "SN_MAIN";
|
|
39
|
+
readonly SN_SEPOLIA: "SN_SEPOLIA";
|
|
40
|
+
};
|
|
41
|
+
export type NetworkName = ValuesType<typeof NetworkName>;
|
|
42
|
+
export declare const StarknetChainId: {
|
|
43
|
+
readonly SN_MAIN: "0x534e5f4d41494e";
|
|
44
|
+
readonly SN_SEPOLIA: "0x534e5f5345504f4c4941";
|
|
45
|
+
};
|
|
46
|
+
export type StarknetChainId = ValuesType<typeof StarknetChainId>;
|
|
47
|
+
export declare const TransactionHashPrefix: {
|
|
48
|
+
readonly DECLARE: "0x6465636c617265";
|
|
49
|
+
readonly DEPLOY: "0x6465706c6f79";
|
|
50
|
+
readonly DEPLOY_ACCOUNT: "0x6465706c6f795f6163636f756e74";
|
|
51
|
+
readonly INVOKE: "0x696e766f6b65";
|
|
52
|
+
readonly L1_HANDLER: "0x6c315f68616e646c6572";
|
|
53
|
+
};
|
|
54
|
+
export type TransactionHashPrefix = ValuesType<typeof TransactionHashPrefix>;
|
|
55
|
+
export declare const FeeMarginPercentage: {
|
|
56
|
+
readonly L1_BOUND_MAX_AMOUNT: 50;
|
|
57
|
+
readonly L1_BOUND_MAX_PRICE_PER_UNIT: 50;
|
|
58
|
+
readonly MAX_FEE: 50;
|
|
59
|
+
};
|
|
60
|
+
export type FeeMarginPercentage = ValuesType<typeof FeeMarginPercentage>;
|
|
61
|
+
export declare const UDC: {
|
|
62
|
+
readonly ADDRESS: "0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf";
|
|
63
|
+
readonly ENTRYPOINT: "deployContract";
|
|
64
|
+
};
|
|
65
|
+
export type UDC = ValuesType<typeof UDC>;
|
|
66
|
+
export declare const RPC_DEFAULT_VERSION = "v0_7";
|
|
67
|
+
export declare const RPC_NODES: {
|
|
68
|
+
readonly SN_MAIN: readonly ["https://starknet-mainnet.public.blastapi.io/rpc/v0_7", "https://free-rpc.nethermind.io/mainnet-juno/v0_7"];
|
|
69
|
+
readonly SN_SEPOLIA: readonly ["https://starknet-sepolia.public.blastapi.io/rpc/v0_7", "https://free-rpc.nethermind.io/sepolia-juno/v0_7"];
|
|
70
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ETransactionVersion } from "./types/api/index.mjs";
|
|
2
|
+
export { IS_BROWSER } from "./utils/encode.mjs";
|
|
3
|
+
export const TEXT_TO_FELT_MAX_LEN = 31;
|
|
4
|
+
export { ETransactionVersion as TRANSACTION_VERSION };
|
|
5
|
+
export const ZERO = 0n;
|
|
6
|
+
export const MASK_250 = 2n ** 250n - 1n;
|
|
7
|
+
export const API_VERSION = ZERO;
|
|
8
|
+
export const PRIME = 2n ** 251n + 17n * 2n ** 192n + 1n;
|
|
9
|
+
export const MAX_STORAGE_ITEM_SIZE = 256n;
|
|
10
|
+
export const ADDR_BOUND = 2n ** 251n - MAX_STORAGE_ITEM_SIZE;
|
|
11
|
+
const range = (min, max) => ({ min, max });
|
|
12
|
+
export const RANGE_FELT = range(ZERO, PRIME - 1n);
|
|
13
|
+
export const RANGE_I128 = range(-(2n ** 127n), 2n ** 127n - 1n);
|
|
14
|
+
export const RANGE_U128 = range(ZERO, 2n ** 128n - 1n);
|
|
15
|
+
export const BaseUrl = {
|
|
16
|
+
SN_MAIN: "https://alpha-mainnet.starknet.io",
|
|
17
|
+
SN_SEPOLIA: "https://alpha-sepolia.starknet.io"
|
|
18
|
+
};
|
|
19
|
+
export const NetworkName = {
|
|
20
|
+
SN_MAIN: "SN_MAIN",
|
|
21
|
+
SN_SEPOLIA: "SN_SEPOLIA"
|
|
22
|
+
};
|
|
23
|
+
export const StarknetChainId = {
|
|
24
|
+
SN_MAIN: "0x534e5f4d41494e",
|
|
25
|
+
// encodeShortString('SN_MAIN'),
|
|
26
|
+
SN_SEPOLIA: "0x534e5f5345504f4c4941"
|
|
27
|
+
// encodeShortString('SN_SEPOLIA')
|
|
28
|
+
};
|
|
29
|
+
export const TransactionHashPrefix = {
|
|
30
|
+
DECLARE: "0x6465636c617265",
|
|
31
|
+
// encodeShortString('declare'),
|
|
32
|
+
DEPLOY: "0x6465706c6f79",
|
|
33
|
+
// encodeShortString('deploy'),
|
|
34
|
+
DEPLOY_ACCOUNT: "0x6465706c6f795f6163636f756e74",
|
|
35
|
+
// encodeShortString('deploy_account'),
|
|
36
|
+
INVOKE: "0x696e766f6b65",
|
|
37
|
+
// encodeShortString('invoke'),
|
|
38
|
+
L1_HANDLER: "0x6c315f68616e646c6572"
|
|
39
|
+
// encodeShortString('l1_handler'),
|
|
40
|
+
};
|
|
41
|
+
export const FeeMarginPercentage = {
|
|
42
|
+
L1_BOUND_MAX_AMOUNT: 50,
|
|
43
|
+
L1_BOUND_MAX_PRICE_PER_UNIT: 50,
|
|
44
|
+
MAX_FEE: 50
|
|
45
|
+
};
|
|
46
|
+
export const UDC = {
|
|
47
|
+
ADDRESS: "0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf",
|
|
48
|
+
ENTRYPOINT: "deployContract"
|
|
49
|
+
};
|
|
50
|
+
export const RPC_DEFAULT_VERSION = "v0_7";
|
|
51
|
+
export const RPC_NODES = {
|
|
52
|
+
SN_MAIN: [
|
|
53
|
+
`https://starknet-mainnet.public.blastapi.io/rpc/${RPC_DEFAULT_VERSION}`,
|
|
54
|
+
`https://free-rpc.nethermind.io/mainnet-juno/${RPC_DEFAULT_VERSION}`
|
|
55
|
+
],
|
|
56
|
+
SN_SEPOLIA: [
|
|
57
|
+
`https://starknet-sepolia.public.blastapi.io/rpc/${RPC_DEFAULT_VERSION}`,
|
|
58
|
+
`https://free-rpc.nethermind.io/sepolia-juno/${RPC_DEFAULT_VERSION}`
|
|
59
|
+
]
|
|
60
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ContractFactory = void 0;
|
|
7
|
+
var _types = require("../types/index.cjs");
|
|
8
|
+
var _assert = _interopRequireDefault(require("../utils/assert.cjs"));
|
|
9
|
+
var _calldata = require("../utils/calldata/index.cjs");
|
|
10
|
+
var _default = require("./default.cjs");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
class ContractFactory {
|
|
13
|
+
compiledContract;
|
|
14
|
+
account;
|
|
15
|
+
abi;
|
|
16
|
+
classHash;
|
|
17
|
+
casm;
|
|
18
|
+
compiledClassHash;
|
|
19
|
+
CallData;
|
|
20
|
+
/**
|
|
21
|
+
* @param params CFParams
|
|
22
|
+
* - compiledContract: CompiledContract;
|
|
23
|
+
* - account: AccountInterface;
|
|
24
|
+
* - casm?: CairoAssembly;
|
|
25
|
+
* - classHash?: string;
|
|
26
|
+
* - compiledClassHash?: string;
|
|
27
|
+
* - abi?: Abi;
|
|
28
|
+
*/
|
|
29
|
+
constructor(params) {
|
|
30
|
+
this.compiledContract = params.compiledContract;
|
|
31
|
+
this.account = params.account;
|
|
32
|
+
this.casm = params.casm;
|
|
33
|
+
this.abi = params.abi ?? params.compiledContract.abi;
|
|
34
|
+
this.classHash = params.classHash;
|
|
35
|
+
this.compiledClassHash = params.compiledClassHash;
|
|
36
|
+
this.CallData = new _calldata.CallData(this.abi);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Deploys contract and returns new instance of the Contract
|
|
40
|
+
*
|
|
41
|
+
* If contract is not declared it will first declare it, and then deploy
|
|
42
|
+
*/
|
|
43
|
+
async deploy(...args) {
|
|
44
|
+
const {
|
|
45
|
+
args: param,
|
|
46
|
+
options = {
|
|
47
|
+
parseRequest: true
|
|
48
|
+
}
|
|
49
|
+
} = (0, _default.splitArgsAndOptions)(args);
|
|
50
|
+
const constructorCalldata = (0, _default.getCalldata)(param, () => {
|
|
51
|
+
if (options.parseRequest) {
|
|
52
|
+
this.CallData.validate(_types.ValidateType.DEPLOY, "constructor", param);
|
|
53
|
+
return this.CallData.compile("constructor", param);
|
|
54
|
+
}
|
|
55
|
+
console.warn("Call skipped parsing but provided rawArgs, possible malfunction request");
|
|
56
|
+
return param;
|
|
57
|
+
});
|
|
58
|
+
const {
|
|
59
|
+
deploy: {
|
|
60
|
+
contract_address,
|
|
61
|
+
transaction_hash
|
|
62
|
+
}
|
|
63
|
+
} = await this.account.declareAndDeploy({
|
|
64
|
+
contract: this.compiledContract,
|
|
65
|
+
casm: this.casm,
|
|
66
|
+
classHash: this.classHash,
|
|
67
|
+
compiledClassHash: this.compiledClassHash,
|
|
68
|
+
constructorCalldata,
|
|
69
|
+
salt: options.addressSalt
|
|
70
|
+
});
|
|
71
|
+
(0, _assert.default)(Boolean(contract_address), "Deployment of the contract failed");
|
|
72
|
+
const contractInstance = new _default.Contract(this.compiledContract.abi, contract_address, this.account);
|
|
73
|
+
contractInstance.deployTransactionHash = transaction_hash;
|
|
74
|
+
return contractInstance;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Attaches to new Account
|
|
78
|
+
*
|
|
79
|
+
* @param account - new Account to attach to
|
|
80
|
+
*/
|
|
81
|
+
connect(account) {
|
|
82
|
+
this.account = account;
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Attaches current abi and account to the new address
|
|
87
|
+
*/
|
|
88
|
+
attach(address) {
|
|
89
|
+
return new _default.Contract(this.abi, address, this.account);
|
|
90
|
+
}
|
|
91
|
+
// ethers.js' getDeployTransaction can't be supported as it requires the account or signer to return a signed transaction which is not possible with the current implementation
|
|
92
|
+
}
|
|
93
|
+
exports.ContractFactory = ContractFactory;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { AccountInterface } from '../account';
|
|
2
|
+
import { Abi, ArgsOrCalldataWithOptions, CairoAssembly, CompiledContract } from '../types';
|
|
3
|
+
import { Contract } from './default';
|
|
4
|
+
export type ContractFactoryParams = {
|
|
5
|
+
compiledContract: CompiledContract;
|
|
6
|
+
account: any;
|
|
7
|
+
casm?: CairoAssembly;
|
|
8
|
+
classHash?: string;
|
|
9
|
+
compiledClassHash?: string;
|
|
10
|
+
abi?: Abi;
|
|
11
|
+
};
|
|
12
|
+
export declare class ContractFactory {
|
|
13
|
+
compiledContract: CompiledContract;
|
|
14
|
+
account: AccountInterface;
|
|
15
|
+
abi: Abi;
|
|
16
|
+
classHash?: string;
|
|
17
|
+
casm?: CairoAssembly;
|
|
18
|
+
compiledClassHash?: string;
|
|
19
|
+
private CallData;
|
|
20
|
+
/**
|
|
21
|
+
* @param params CFParams
|
|
22
|
+
* - compiledContract: CompiledContract;
|
|
23
|
+
* - account: AccountInterface;
|
|
24
|
+
* - casm?: CairoAssembly;
|
|
25
|
+
* - classHash?: string;
|
|
26
|
+
* - compiledClassHash?: string;
|
|
27
|
+
* - abi?: Abi;
|
|
28
|
+
*/
|
|
29
|
+
constructor(params: ContractFactoryParams);
|
|
30
|
+
/**
|
|
31
|
+
* Deploys contract and returns new instance of the Contract
|
|
32
|
+
*
|
|
33
|
+
* If contract is not declared it will first declare it, and then deploy
|
|
34
|
+
*/
|
|
35
|
+
deploy(...args: ArgsOrCalldataWithOptions): Promise<Contract>;
|
|
36
|
+
/**
|
|
37
|
+
* Attaches to new Account
|
|
38
|
+
*
|
|
39
|
+
* @param account - new Account to attach to
|
|
40
|
+
*/
|
|
41
|
+
connect(account: AccountInterface): ContractFactory;
|
|
42
|
+
/**
|
|
43
|
+
* Attaches current abi and account to the new address
|
|
44
|
+
*/
|
|
45
|
+
attach(address: string): Contract;
|
|
46
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ValidateType
|
|
3
|
+
} from "../types/index.mjs";
|
|
4
|
+
import assert from "../utils/assert.mjs";
|
|
5
|
+
import { CallData } from "../utils/calldata/index.mjs";
|
|
6
|
+
import { Contract, getCalldata, splitArgsAndOptions } from "./default.mjs";
|
|
7
|
+
export class ContractFactory {
|
|
8
|
+
compiledContract;
|
|
9
|
+
account;
|
|
10
|
+
abi;
|
|
11
|
+
classHash;
|
|
12
|
+
casm;
|
|
13
|
+
compiledClassHash;
|
|
14
|
+
CallData;
|
|
15
|
+
/**
|
|
16
|
+
* @param params CFParams
|
|
17
|
+
* - compiledContract: CompiledContract;
|
|
18
|
+
* - account: AccountInterface;
|
|
19
|
+
* - casm?: CairoAssembly;
|
|
20
|
+
* - classHash?: string;
|
|
21
|
+
* - compiledClassHash?: string;
|
|
22
|
+
* - abi?: Abi;
|
|
23
|
+
*/
|
|
24
|
+
constructor(params) {
|
|
25
|
+
this.compiledContract = params.compiledContract;
|
|
26
|
+
this.account = params.account;
|
|
27
|
+
this.casm = params.casm;
|
|
28
|
+
this.abi = params.abi ?? params.compiledContract.abi;
|
|
29
|
+
this.classHash = params.classHash;
|
|
30
|
+
this.compiledClassHash = params.compiledClassHash;
|
|
31
|
+
this.CallData = new CallData(this.abi);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Deploys contract and returns new instance of the Contract
|
|
35
|
+
*
|
|
36
|
+
* If contract is not declared it will first declare it, and then deploy
|
|
37
|
+
*/
|
|
38
|
+
async deploy(...args) {
|
|
39
|
+
const { args: param, options = { parseRequest: true } } = splitArgsAndOptions(args);
|
|
40
|
+
const constructorCalldata = getCalldata(param, () => {
|
|
41
|
+
if (options.parseRequest) {
|
|
42
|
+
this.CallData.validate(ValidateType.DEPLOY, "constructor", param);
|
|
43
|
+
return this.CallData.compile("constructor", param);
|
|
44
|
+
}
|
|
45
|
+
console.warn("Call skipped parsing but provided rawArgs, possible malfunction request");
|
|
46
|
+
return param;
|
|
47
|
+
});
|
|
48
|
+
const {
|
|
49
|
+
deploy: { contract_address, transaction_hash }
|
|
50
|
+
} = await this.account.declareAndDeploy({
|
|
51
|
+
contract: this.compiledContract,
|
|
52
|
+
casm: this.casm,
|
|
53
|
+
classHash: this.classHash,
|
|
54
|
+
compiledClassHash: this.compiledClassHash,
|
|
55
|
+
constructorCalldata,
|
|
56
|
+
salt: options.addressSalt
|
|
57
|
+
});
|
|
58
|
+
assert(Boolean(contract_address), "Deployment of the contract failed");
|
|
59
|
+
const contractInstance = new Contract(
|
|
60
|
+
this.compiledContract.abi,
|
|
61
|
+
contract_address,
|
|
62
|
+
this.account
|
|
63
|
+
);
|
|
64
|
+
contractInstance.deployTransactionHash = transaction_hash;
|
|
65
|
+
return contractInstance;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Attaches to new Account
|
|
69
|
+
*
|
|
70
|
+
* @param account - new Account to attach to
|
|
71
|
+
*/
|
|
72
|
+
connect(account) {
|
|
73
|
+
this.account = account;
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Attaches current abi and account to the new address
|
|
78
|
+
*/
|
|
79
|
+
attach(address) {
|
|
80
|
+
return new Contract(this.abi, address, this.account);
|
|
81
|
+
}
|
|
82
|
+
// ethers.js' getDeployTransaction can't be supported as it requires the account or signer to return a signed transaction which is not possible with the current implementation
|
|
83
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Contract = void 0;
|
|
7
|
+
exports.getCalldata = getCalldata;
|
|
8
|
+
exports.splitArgsAndOptions = void 0;
|
|
9
|
+
var _provider = require("../provider/index.cjs");
|
|
10
|
+
var _types = require("../types/index.cjs");
|
|
11
|
+
var _assert = _interopRequireDefault(require("../utils/assert.cjs"));
|
|
12
|
+
var _calldata = require("../utils/calldata/index.cjs");
|
|
13
|
+
var _parser = require("../utils/calldata/parser/index.cjs");
|
|
14
|
+
var _index = require("../utils/events/index.cjs");
|
|
15
|
+
var _num = require("../utils/num.cjs");
|
|
16
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
|
+
const splitArgsAndOptions = args => {
|
|
18
|
+
const options = ["blockIdentifier", "parseRequest", "parseResponse", "formatResponse", "maxFee", "nonce", "signature", "addressSalt"];
|
|
19
|
+
const lastArg = args[args.length - 1];
|
|
20
|
+
if (typeof lastArg === "object" && options.some(x => x in lastArg)) {
|
|
21
|
+
return {
|
|
22
|
+
args,
|
|
23
|
+
options: args.pop()
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
args
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
exports.splitArgsAndOptions = splitArgsAndOptions;
|
|
31
|
+
function buildCall(contract, functionAbi) {
|
|
32
|
+
return async function (...args) {
|
|
33
|
+
const params = splitArgsAndOptions(args);
|
|
34
|
+
return contract.call(functionAbi.name, params.args, {
|
|
35
|
+
parseRequest: true,
|
|
36
|
+
parseResponse: true,
|
|
37
|
+
...params.options
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function buildInvoke(contract, functionAbi) {
|
|
42
|
+
return async function (...args) {
|
|
43
|
+
const params = splitArgsAndOptions(args);
|
|
44
|
+
return contract.invoke(functionAbi.name, params.args, {
|
|
45
|
+
parseRequest: true,
|
|
46
|
+
...params.options
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function buildDefault(contract, functionAbi) {
|
|
51
|
+
if (functionAbi.stateMutability === "view" || functionAbi.state_mutability === "view") {
|
|
52
|
+
return buildCall(contract, functionAbi);
|
|
53
|
+
}
|
|
54
|
+
return buildInvoke(contract, functionAbi);
|
|
55
|
+
}
|
|
56
|
+
function buildPopulate(contract, functionAbi) {
|
|
57
|
+
return function (...args) {
|
|
58
|
+
return contract.populate(functionAbi.name, args);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function buildEstimate(contract, functionAbi) {
|
|
62
|
+
return function (...args) {
|
|
63
|
+
return contract.estimate(functionAbi.name, args);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function getCalldata(args, callback) {
|
|
67
|
+
if (Array.isArray(args) && "__compiled__" in args) return args;
|
|
68
|
+
if (Array.isArray(args) && Array.isArray(args[0]) && "__compiled__" in args[0]) return args[0];
|
|
69
|
+
return callback();
|
|
70
|
+
}
|
|
71
|
+
class Contract {
|
|
72
|
+
abi;
|
|
73
|
+
address;
|
|
74
|
+
providerOrAccount;
|
|
75
|
+
deployTransactionHash;
|
|
76
|
+
structs;
|
|
77
|
+
events;
|
|
78
|
+
functions;
|
|
79
|
+
callStatic;
|
|
80
|
+
populateTransaction;
|
|
81
|
+
estimateFee;
|
|
82
|
+
callData;
|
|
83
|
+
/**
|
|
84
|
+
* Contract class to handle contract methods
|
|
85
|
+
*
|
|
86
|
+
* @param abi - Abi of the contract object
|
|
87
|
+
* @param address (optional) - address to connect to
|
|
88
|
+
* @param providerOrAccount (optional) - Provider or Account to attach to
|
|
89
|
+
*/
|
|
90
|
+
constructor(abi, address, providerOrAccount = _provider.defaultProvider) {
|
|
91
|
+
this.address = address && address.toLowerCase();
|
|
92
|
+
this.providerOrAccount = providerOrAccount;
|
|
93
|
+
this.callData = new _calldata.CallData(abi);
|
|
94
|
+
this.structs = _calldata.CallData.getAbiStruct(abi);
|
|
95
|
+
this.events = (0, _index.getAbiEvents)(abi);
|
|
96
|
+
const parser = (0, _parser.createAbiParser)(abi);
|
|
97
|
+
this.abi = parser.getLegacyFormat();
|
|
98
|
+
const options = {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
value: {},
|
|
101
|
+
writable: false
|
|
102
|
+
};
|
|
103
|
+
Object.defineProperties(this, {
|
|
104
|
+
functions: {
|
|
105
|
+
enumerable: true,
|
|
106
|
+
value: {},
|
|
107
|
+
writable: false
|
|
108
|
+
},
|
|
109
|
+
callStatic: {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
value: {},
|
|
112
|
+
writable: false
|
|
113
|
+
},
|
|
114
|
+
populateTransaction: {
|
|
115
|
+
enumerable: true,
|
|
116
|
+
value: {},
|
|
117
|
+
writable: false
|
|
118
|
+
},
|
|
119
|
+
estimateFee: {
|
|
120
|
+
enumerable: true,
|
|
121
|
+
value: {},
|
|
122
|
+
writable: false
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
this.abi.forEach(abiElement => {
|
|
126
|
+
if (abiElement.type !== "function") return;
|
|
127
|
+
const signature = abiElement.name;
|
|
128
|
+
if (!this[signature]) {
|
|
129
|
+
Object.defineProperty(this, signature, {
|
|
130
|
+
...options,
|
|
131
|
+
value: buildDefault(this, abiElement)
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
if (!this.functions[signature]) {
|
|
135
|
+
Object.defineProperty(this.functions, signature, {
|
|
136
|
+
...options,
|
|
137
|
+
value: buildDefault(this, abiElement)
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
if (!this.callStatic[signature]) {
|
|
141
|
+
Object.defineProperty(this.callStatic, signature, {
|
|
142
|
+
...options,
|
|
143
|
+
value: buildCall(this, abiElement)
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
if (!this.populateTransaction[signature]) {
|
|
147
|
+
Object.defineProperty(this.populateTransaction, signature, {
|
|
148
|
+
...options,
|
|
149
|
+
value: buildPopulate(this, abiElement)
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
if (!this.estimateFee[signature]) {
|
|
153
|
+
Object.defineProperty(this.estimateFee, signature, {
|
|
154
|
+
...options,
|
|
155
|
+
value: buildEstimate(this, abiElement)
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
attach(address) {
|
|
161
|
+
this.address = address;
|
|
162
|
+
}
|
|
163
|
+
connect(providerOrAccount) {
|
|
164
|
+
this.providerOrAccount = providerOrAccount;
|
|
165
|
+
}
|
|
166
|
+
async deployed() {
|
|
167
|
+
if (this.deployTransactionHash) {
|
|
168
|
+
await this.providerOrAccount.waitForTransaction(this.deployTransactionHash);
|
|
169
|
+
this.deployTransactionHash = void 0;
|
|
170
|
+
}
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
async call(method, args = [], {
|
|
174
|
+
parseRequest = true,
|
|
175
|
+
parseResponse = true,
|
|
176
|
+
formatResponse = void 0,
|
|
177
|
+
blockIdentifier = void 0
|
|
178
|
+
} = {}) {
|
|
179
|
+
(0, _assert.default)(this.address !== null, "contract is not connected to an address");
|
|
180
|
+
const calldata = getCalldata(args, () => {
|
|
181
|
+
if (parseRequest) {
|
|
182
|
+
this.callData.validate(_types.ValidateType.CALL, method, args);
|
|
183
|
+
return this.callData.compile(method, args);
|
|
184
|
+
}
|
|
185
|
+
console.warn("Call skipped parsing but provided rawArgs, possible malfunction request");
|
|
186
|
+
return args;
|
|
187
|
+
});
|
|
188
|
+
return this.providerOrAccount.callContract({
|
|
189
|
+
contractAddress: this.address,
|
|
190
|
+
calldata,
|
|
191
|
+
entrypoint: method
|
|
192
|
+
}, blockIdentifier).then(it => {
|
|
193
|
+
if (!parseResponse) {
|
|
194
|
+
return it;
|
|
195
|
+
}
|
|
196
|
+
if (formatResponse) {
|
|
197
|
+
return this.callData.format(method, it, formatResponse);
|
|
198
|
+
}
|
|
199
|
+
return this.callData.parse(method, it);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
invoke(method, args = [], {
|
|
203
|
+
parseRequest = true,
|
|
204
|
+
maxFee,
|
|
205
|
+
nonce,
|
|
206
|
+
signature
|
|
207
|
+
} = {}) {
|
|
208
|
+
(0, _assert.default)(this.address !== null, "contract is not connected to an address");
|
|
209
|
+
const calldata = getCalldata(args, () => {
|
|
210
|
+
if (parseRequest) {
|
|
211
|
+
this.callData.validate(_types.ValidateType.INVOKE, method, args);
|
|
212
|
+
return this.callData.compile(method, args);
|
|
213
|
+
}
|
|
214
|
+
console.warn("Invoke skipped parsing but provided rawArgs, possible malfunction request");
|
|
215
|
+
return args;
|
|
216
|
+
});
|
|
217
|
+
const invocation = {
|
|
218
|
+
contractAddress: this.address,
|
|
219
|
+
calldata,
|
|
220
|
+
entrypoint: method
|
|
221
|
+
};
|
|
222
|
+
if ("execute" in this.providerOrAccount) {
|
|
223
|
+
return this.providerOrAccount.execute(invocation, void 0, {
|
|
224
|
+
maxFee,
|
|
225
|
+
nonce
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
if (!nonce) throw new Error(`Nonce is required when invoking a function without an account`);
|
|
229
|
+
console.warn(`Invoking ${method} without an account. This will not work on a public node.`);
|
|
230
|
+
return this.providerOrAccount.invokeFunction({
|
|
231
|
+
...invocation,
|
|
232
|
+
signature
|
|
233
|
+
}, {
|
|
234
|
+
nonce
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
async estimate(method, args = []) {
|
|
238
|
+
(0, _assert.default)(this.address !== null, "contract is not connected to an address");
|
|
239
|
+
if (!getCalldata(args, () => false)) {
|
|
240
|
+
this.callData.validate(_types.ValidateType.INVOKE, method, args);
|
|
241
|
+
}
|
|
242
|
+
const invocation = this.populate(method, args);
|
|
243
|
+
if ("estimateInvokeFee" in this.providerOrAccount) {
|
|
244
|
+
return this.providerOrAccount.estimateInvokeFee(invocation);
|
|
245
|
+
}
|
|
246
|
+
throw Error("Contract must be connected to the account contract to estimate");
|
|
247
|
+
}
|
|
248
|
+
populate(method, args = []) {
|
|
249
|
+
const calldata = getCalldata(args, () => this.callData.compile(method, args));
|
|
250
|
+
return {
|
|
251
|
+
contractAddress: this.address,
|
|
252
|
+
entrypoint: method,
|
|
253
|
+
calldata
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
parseEvents(receipt) {
|
|
257
|
+
return (0, _index.parseEvents)(receipt.events?.filter(event => (0, _num.cleanHex)(event.from_address) === (0, _num.cleanHex)(this.address), []) || [], this.events, this.structs, _calldata.CallData.getAbiEnum(this.abi));
|
|
258
|
+
}
|
|
259
|
+
isCairo1() {
|
|
260
|
+
return _calldata.cairo.isCairo1Abi(this.abi);
|
|
261
|
+
}
|
|
262
|
+
async getVersion() {
|
|
263
|
+
return this.providerOrAccount.getContractVersion(this.address);
|
|
264
|
+
}
|
|
265
|
+
typedv2(tAbi) {
|
|
266
|
+
return this;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
exports.Contract = Contract;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Abi as AbiKanabi, TypedContract as AbiWanTypedContract } from 'abi-wan-kanabi';
|
|
2
|
+
import { AccountInterface } from '../account';
|
|
3
|
+
import { ProviderInterface } from '../provider';
|
|
4
|
+
import { Abi, AbiEvents, ArgsOrCalldata, ArgsOrCalldataWithOptions, AsyncContractFunction, Call, CallOptions, Calldata, ContractFunction, ContractOptions, EstimateFeeResponse, InvokeFunctionResponse, InvokeOptions, ParsedEvents, RawArgs, Result, AbiStruct } from '../types';
|
|
5
|
+
import { ContractInterface } from './interface';
|
|
6
|
+
import type { GetTransactionReceiptResponse } from '../utils/transactionReceipt';
|
|
7
|
+
export type TypedContractV2<TAbi extends AbiKanabi> = AbiWanTypedContract<TAbi> & Contract;
|
|
8
|
+
export declare const splitArgsAndOptions: (args: ArgsOrCalldataWithOptions) => {
|
|
9
|
+
args: ArgsOrCalldata;
|
|
10
|
+
options: ContractOptions;
|
|
11
|
+
} | {
|
|
12
|
+
args: ArgsOrCalldata;
|
|
13
|
+
options?: undefined;
|
|
14
|
+
};
|
|
15
|
+
export declare function getCalldata(args: RawArgs, callback: Function): Calldata;
|
|
16
|
+
export declare class Contract implements ContractInterface {
|
|
17
|
+
abi: Abi;
|
|
18
|
+
address: string;
|
|
19
|
+
providerOrAccount: ProviderInterface | AccountInterface;
|
|
20
|
+
deployTransactionHash?: string;
|
|
21
|
+
protected readonly structs: {
|
|
22
|
+
[name: string]: AbiStruct;
|
|
23
|
+
};
|
|
24
|
+
protected readonly events: AbiEvents;
|
|
25
|
+
readonly functions: {
|
|
26
|
+
[name: string]: AsyncContractFunction;
|
|
27
|
+
};
|
|
28
|
+
readonly callStatic: {
|
|
29
|
+
[name: string]: AsyncContractFunction;
|
|
30
|
+
};
|
|
31
|
+
readonly populateTransaction: {
|
|
32
|
+
[name: string]: ContractFunction;
|
|
33
|
+
};
|
|
34
|
+
readonly estimateFee: {
|
|
35
|
+
[name: string]: ContractFunction;
|
|
36
|
+
};
|
|
37
|
+
readonly [key: string]: AsyncContractFunction | any;
|
|
38
|
+
private callData;
|
|
39
|
+
/**
|
|
40
|
+
* Contract class to handle contract methods
|
|
41
|
+
*
|
|
42
|
+
* @param abi - Abi of the contract object
|
|
43
|
+
* @param address (optional) - address to connect to
|
|
44
|
+
* @param providerOrAccount (optional) - Provider or Account to attach to
|
|
45
|
+
*/
|
|
46
|
+
constructor(abi: Abi, address: string, providerOrAccount?: ProviderInterface | AccountInterface);
|
|
47
|
+
attach(address: string): void;
|
|
48
|
+
connect(providerOrAccount: ProviderInterface | AccountInterface): void;
|
|
49
|
+
deployed(): Promise<Contract>;
|
|
50
|
+
call(method: string, args?: ArgsOrCalldata, { parseRequest, parseResponse, formatResponse, blockIdentifier, }?: CallOptions): Promise<Result>;
|
|
51
|
+
invoke(method: string, args?: ArgsOrCalldata, { parseRequest, maxFee, nonce, signature }?: InvokeOptions): Promise<InvokeFunctionResponse>;
|
|
52
|
+
estimate(method: string, args?: ArgsOrCalldata): Promise<EstimateFeeResponse>;
|
|
53
|
+
populate(method: string, args?: RawArgs): Call;
|
|
54
|
+
parseEvents(receipt: GetTransactionReceiptResponse): ParsedEvents;
|
|
55
|
+
isCairo1(): boolean;
|
|
56
|
+
getVersion(): Promise<import("../types").ContractVersion>;
|
|
57
|
+
typedv2<TAbi extends AbiKanabi>(tAbi: TAbi): TypedContractV2<TAbi>;
|
|
58
|
+
}
|