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,254 @@
|
|
|
1
|
+
import { defaultProvider } from "../provider/index.mjs";
|
|
2
|
+
import {
|
|
3
|
+
ValidateType
|
|
4
|
+
} from "../types/index.mjs";
|
|
5
|
+
import assert from "../utils/assert.mjs";
|
|
6
|
+
import { CallData, cairo } from "../utils/calldata/index.mjs";
|
|
7
|
+
import { createAbiParser } from "../utils/calldata/parser/index.mjs";
|
|
8
|
+
import { getAbiEvents, parseEvents as parseRawEvents } from "../utils/events/index.mjs";
|
|
9
|
+
import { cleanHex } from "../utils/num.mjs";
|
|
10
|
+
export const splitArgsAndOptions = (args) => {
|
|
11
|
+
const options = [
|
|
12
|
+
"blockIdentifier",
|
|
13
|
+
"parseRequest",
|
|
14
|
+
"parseResponse",
|
|
15
|
+
"formatResponse",
|
|
16
|
+
"maxFee",
|
|
17
|
+
"nonce",
|
|
18
|
+
"signature",
|
|
19
|
+
"addressSalt"
|
|
20
|
+
];
|
|
21
|
+
const lastArg = args[args.length - 1];
|
|
22
|
+
if (typeof lastArg === "object" && options.some((x) => x in lastArg)) {
|
|
23
|
+
return { args, options: args.pop() };
|
|
24
|
+
}
|
|
25
|
+
return { args };
|
|
26
|
+
};
|
|
27
|
+
function buildCall(contract, functionAbi) {
|
|
28
|
+
return async function(...args) {
|
|
29
|
+
const params = splitArgsAndOptions(args);
|
|
30
|
+
return contract.call(functionAbi.name, params.args, {
|
|
31
|
+
parseRequest: true,
|
|
32
|
+
parseResponse: true,
|
|
33
|
+
...params.options
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function buildInvoke(contract, functionAbi) {
|
|
38
|
+
return async function(...args) {
|
|
39
|
+
const params = splitArgsAndOptions(args);
|
|
40
|
+
return contract.invoke(functionAbi.name, params.args, {
|
|
41
|
+
parseRequest: true,
|
|
42
|
+
...params.options
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function buildDefault(contract, functionAbi) {
|
|
47
|
+
if (functionAbi.stateMutability === "view" || functionAbi.state_mutability === "view") {
|
|
48
|
+
return buildCall(contract, functionAbi);
|
|
49
|
+
}
|
|
50
|
+
return buildInvoke(contract, functionAbi);
|
|
51
|
+
}
|
|
52
|
+
function buildPopulate(contract, functionAbi) {
|
|
53
|
+
return function(...args) {
|
|
54
|
+
return contract.populate(functionAbi.name, args);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function buildEstimate(contract, functionAbi) {
|
|
58
|
+
return function(...args) {
|
|
59
|
+
return contract.estimate(functionAbi.name, args);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export function getCalldata(args, callback) {
|
|
63
|
+
if (Array.isArray(args) && "__compiled__" in args) return args;
|
|
64
|
+
if (Array.isArray(args) && Array.isArray(args[0]) && "__compiled__" in args[0])
|
|
65
|
+
return args[0];
|
|
66
|
+
return callback();
|
|
67
|
+
}
|
|
68
|
+
export class Contract {
|
|
69
|
+
abi;
|
|
70
|
+
address;
|
|
71
|
+
providerOrAccount;
|
|
72
|
+
deployTransactionHash;
|
|
73
|
+
structs;
|
|
74
|
+
events;
|
|
75
|
+
functions;
|
|
76
|
+
callStatic;
|
|
77
|
+
populateTransaction;
|
|
78
|
+
estimateFee;
|
|
79
|
+
callData;
|
|
80
|
+
/**
|
|
81
|
+
* Contract class to handle contract methods
|
|
82
|
+
*
|
|
83
|
+
* @param abi - Abi of the contract object
|
|
84
|
+
* @param address (optional) - address to connect to
|
|
85
|
+
* @param providerOrAccount (optional) - Provider or Account to attach to
|
|
86
|
+
*/
|
|
87
|
+
constructor(abi, address, providerOrAccount = defaultProvider) {
|
|
88
|
+
this.address = address && address.toLowerCase();
|
|
89
|
+
this.providerOrAccount = providerOrAccount;
|
|
90
|
+
this.callData = new CallData(abi);
|
|
91
|
+
this.structs = CallData.getAbiStruct(abi);
|
|
92
|
+
this.events = getAbiEvents(abi);
|
|
93
|
+
const parser = createAbiParser(abi);
|
|
94
|
+
this.abi = parser.getLegacyFormat();
|
|
95
|
+
const options = { enumerable: true, value: {}, writable: false };
|
|
96
|
+
Object.defineProperties(this, {
|
|
97
|
+
functions: { enumerable: true, value: {}, writable: false },
|
|
98
|
+
callStatic: { enumerable: true, value: {}, writable: false },
|
|
99
|
+
populateTransaction: { enumerable: true, value: {}, writable: false },
|
|
100
|
+
estimateFee: { enumerable: true, value: {}, writable: false }
|
|
101
|
+
});
|
|
102
|
+
this.abi.forEach((abiElement) => {
|
|
103
|
+
if (abiElement.type !== "function") return;
|
|
104
|
+
const signature = abiElement.name;
|
|
105
|
+
if (!this[signature]) {
|
|
106
|
+
Object.defineProperty(this, signature, {
|
|
107
|
+
...options,
|
|
108
|
+
value: buildDefault(this, abiElement)
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
if (!this.functions[signature]) {
|
|
112
|
+
Object.defineProperty(this.functions, signature, {
|
|
113
|
+
...options,
|
|
114
|
+
value: buildDefault(this, abiElement)
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (!this.callStatic[signature]) {
|
|
118
|
+
Object.defineProperty(this.callStatic, signature, {
|
|
119
|
+
...options,
|
|
120
|
+
value: buildCall(this, abiElement)
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
if (!this.populateTransaction[signature]) {
|
|
124
|
+
Object.defineProperty(this.populateTransaction, signature, {
|
|
125
|
+
...options,
|
|
126
|
+
value: buildPopulate(this, abiElement)
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
if (!this.estimateFee[signature]) {
|
|
130
|
+
Object.defineProperty(this.estimateFee, signature, {
|
|
131
|
+
...options,
|
|
132
|
+
value: buildEstimate(this, abiElement)
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
attach(address) {
|
|
138
|
+
this.address = address;
|
|
139
|
+
}
|
|
140
|
+
connect(providerOrAccount) {
|
|
141
|
+
this.providerOrAccount = providerOrAccount;
|
|
142
|
+
}
|
|
143
|
+
async deployed() {
|
|
144
|
+
if (this.deployTransactionHash) {
|
|
145
|
+
await this.providerOrAccount.waitForTransaction(this.deployTransactionHash);
|
|
146
|
+
this.deployTransactionHash = void 0;
|
|
147
|
+
}
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
async call(method, args = [], {
|
|
151
|
+
parseRequest = true,
|
|
152
|
+
parseResponse = true,
|
|
153
|
+
formatResponse = void 0,
|
|
154
|
+
blockIdentifier = void 0
|
|
155
|
+
} = {}) {
|
|
156
|
+
assert(this.address !== null, "contract is not connected to an address");
|
|
157
|
+
const calldata = getCalldata(args, () => {
|
|
158
|
+
if (parseRequest) {
|
|
159
|
+
this.callData.validate(ValidateType.CALL, method, args);
|
|
160
|
+
return this.callData.compile(method, args);
|
|
161
|
+
}
|
|
162
|
+
console.warn("Call skipped parsing but provided rawArgs, possible malfunction request");
|
|
163
|
+
return args;
|
|
164
|
+
});
|
|
165
|
+
return this.providerOrAccount.callContract(
|
|
166
|
+
{
|
|
167
|
+
contractAddress: this.address,
|
|
168
|
+
calldata,
|
|
169
|
+
entrypoint: method
|
|
170
|
+
},
|
|
171
|
+
blockIdentifier
|
|
172
|
+
).then((it) => {
|
|
173
|
+
if (!parseResponse) {
|
|
174
|
+
return it;
|
|
175
|
+
}
|
|
176
|
+
if (formatResponse) {
|
|
177
|
+
return this.callData.format(method, it, formatResponse);
|
|
178
|
+
}
|
|
179
|
+
return this.callData.parse(method, it);
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
invoke(method, args = [], { parseRequest = true, maxFee, nonce, signature } = {}) {
|
|
183
|
+
assert(this.address !== null, "contract is not connected to an address");
|
|
184
|
+
const calldata = getCalldata(args, () => {
|
|
185
|
+
if (parseRequest) {
|
|
186
|
+
this.callData.validate(ValidateType.INVOKE, method, args);
|
|
187
|
+
return this.callData.compile(method, args);
|
|
188
|
+
}
|
|
189
|
+
console.warn("Invoke skipped parsing but provided rawArgs, possible malfunction request");
|
|
190
|
+
return args;
|
|
191
|
+
});
|
|
192
|
+
const invocation = {
|
|
193
|
+
contractAddress: this.address,
|
|
194
|
+
calldata,
|
|
195
|
+
entrypoint: method
|
|
196
|
+
};
|
|
197
|
+
if ("execute" in this.providerOrAccount) {
|
|
198
|
+
return this.providerOrAccount.execute(invocation, void 0, {
|
|
199
|
+
maxFee,
|
|
200
|
+
nonce
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
if (!nonce) throw new Error(`Nonce is required when invoking a function without an account`);
|
|
204
|
+
console.warn(`Invoking ${method} without an account. This will not work on a public node.`);
|
|
205
|
+
return this.providerOrAccount.invokeFunction(
|
|
206
|
+
{
|
|
207
|
+
...invocation,
|
|
208
|
+
signature
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
nonce
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
async estimate(method, args = []) {
|
|
216
|
+
assert(this.address !== null, "contract is not connected to an address");
|
|
217
|
+
if (!getCalldata(args, () => false)) {
|
|
218
|
+
this.callData.validate(ValidateType.INVOKE, method, args);
|
|
219
|
+
}
|
|
220
|
+
const invocation = this.populate(method, args);
|
|
221
|
+
if ("estimateInvokeFee" in this.providerOrAccount) {
|
|
222
|
+
return this.providerOrAccount.estimateInvokeFee(invocation);
|
|
223
|
+
}
|
|
224
|
+
throw Error("Contract must be connected to the account contract to estimate");
|
|
225
|
+
}
|
|
226
|
+
populate(method, args = []) {
|
|
227
|
+
const calldata = getCalldata(args, () => this.callData.compile(method, args));
|
|
228
|
+
return {
|
|
229
|
+
contractAddress: this.address,
|
|
230
|
+
entrypoint: method,
|
|
231
|
+
calldata
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
parseEvents(receipt) {
|
|
235
|
+
return parseRawEvents(
|
|
236
|
+
receipt.events?.filter(
|
|
237
|
+
(event) => cleanHex(event.from_address) === cleanHex(this.address),
|
|
238
|
+
[]
|
|
239
|
+
) || [],
|
|
240
|
+
this.events,
|
|
241
|
+
this.structs,
|
|
242
|
+
CallData.getAbiEnum(this.abi)
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
isCairo1() {
|
|
246
|
+
return cairo.isCairo1Abi(this.abi);
|
|
247
|
+
}
|
|
248
|
+
async getVersion() {
|
|
249
|
+
return this.providerOrAccount.getContractVersion(this.address);
|
|
250
|
+
}
|
|
251
|
+
typedv2(tAbi) {
|
|
252
|
+
return this;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _default = require("./default.cjs");
|
|
7
|
+
Object.keys(_default).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _default[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _default[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _interface = require("./interface.cjs");
|
|
18
|
+
Object.keys(_interface).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _interface[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _interface[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _contractFactory = require("./contractFactory.cjs");
|
|
29
|
+
Object.keys(_contractFactory).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _contractFactory[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _contractFactory[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ContractInterface = void 0;
|
|
7
|
+
class ContractInterface {
|
|
8
|
+
functions;
|
|
9
|
+
callStatic;
|
|
10
|
+
populateTransaction;
|
|
11
|
+
estimateFee;
|
|
12
|
+
}
|
|
13
|
+
exports.ContractInterface = ContractInterface;
|
|
@@ -0,0 +1,128 @@
|
|
|
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, ArgsOrCalldata, AsyncContractFunction, BigNumberish, BlockIdentifier, CallOptions, Calldata, ContractFunction, ContractVersion, EstimateFeeResponse, Invocation, InvokeFunctionResponse, InvokeOptions, ParsedEvents, RawArgs, Result, Uint256 } from '../types';
|
|
5
|
+
import { CairoCustomEnum } from '../utils/calldata/enum/CairoCustomEnum';
|
|
6
|
+
import { CairoOption } from '../utils/calldata/enum/CairoOption';
|
|
7
|
+
import { CairoResult } from '../utils/calldata/enum/CairoResult';
|
|
8
|
+
import type { GetTransactionReceiptResponse } from '../utils/transactionReceipt';
|
|
9
|
+
declare module 'abi-wan-kanabi' {
|
|
10
|
+
interface Config<OptionT = any, ResultT = any, ErrorT = any> {
|
|
11
|
+
FeltType: BigNumberish;
|
|
12
|
+
U256Type: number | bigint | Uint256;
|
|
13
|
+
U512Type: BigNumberish;
|
|
14
|
+
Secp256k1PointType: BigNumberish;
|
|
15
|
+
Option: CairoOption<OptionT>;
|
|
16
|
+
Tuple: Record<number, BigNumberish | object | boolean>;
|
|
17
|
+
Result: CairoResult<ResultT, ErrorT>;
|
|
18
|
+
Enum: CairoCustomEnum;
|
|
19
|
+
Calldata: RawArgs | Calldata;
|
|
20
|
+
CallOptions: CallOptions;
|
|
21
|
+
InvokeOptions: InvokeOptions;
|
|
22
|
+
InvokeFunctionResponse: InvokeFunctionResponse;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
type TypedContractV2<TAbi extends AbiKanabi> = AbiWanTypedContract<TAbi> & ContractInterface;
|
|
26
|
+
export declare abstract class ContractInterface {
|
|
27
|
+
abstract abi: Abi;
|
|
28
|
+
abstract address: string;
|
|
29
|
+
abstract providerOrAccount: ProviderInterface | AccountInterface;
|
|
30
|
+
abstract deployTransactionHash?: string;
|
|
31
|
+
readonly functions: {
|
|
32
|
+
[name: string]: AsyncContractFunction;
|
|
33
|
+
};
|
|
34
|
+
readonly callStatic: {
|
|
35
|
+
[name: string]: AsyncContractFunction;
|
|
36
|
+
};
|
|
37
|
+
readonly populateTransaction: {
|
|
38
|
+
[name: string]: ContractFunction;
|
|
39
|
+
};
|
|
40
|
+
readonly estimateFee: {
|
|
41
|
+
[name: string]: ContractFunction;
|
|
42
|
+
};
|
|
43
|
+
readonly [key: string]: AsyncContractFunction | any;
|
|
44
|
+
/**
|
|
45
|
+
* Saves the address of the contract deployed on network that will be used for interaction
|
|
46
|
+
*
|
|
47
|
+
* @param address - address of the contract
|
|
48
|
+
*/
|
|
49
|
+
abstract attach(address: string): void;
|
|
50
|
+
/**
|
|
51
|
+
* Attaches to new Provider or Account
|
|
52
|
+
*
|
|
53
|
+
* @param providerOrAccount - new Provider or Account to attach to
|
|
54
|
+
*/
|
|
55
|
+
abstract connect(providerOrAccount: ProviderInterface | AccountInterface): void;
|
|
56
|
+
/**
|
|
57
|
+
* Resolves when contract is deployed on the network or when no deployment transaction is found
|
|
58
|
+
*
|
|
59
|
+
* @returns Promise that resolves when contract is deployed on the network or when no deployment transaction is found
|
|
60
|
+
* @throws When deployment fails
|
|
61
|
+
*/
|
|
62
|
+
abstract deployed(): Promise<ContractInterface>;
|
|
63
|
+
/**
|
|
64
|
+
* Calls a method on a contract
|
|
65
|
+
*
|
|
66
|
+
* @param method name of the method
|
|
67
|
+
* @param args Array of the arguments for the call
|
|
68
|
+
* @param options optional blockIdentifier
|
|
69
|
+
* @returns Result of the call as an array with key value pars
|
|
70
|
+
*/
|
|
71
|
+
abstract call(method: string, args?: ArgsOrCalldata, options?: CallOptions): Promise<Result>;
|
|
72
|
+
/**
|
|
73
|
+
* Invokes a method on a contract
|
|
74
|
+
*
|
|
75
|
+
* @param method name of the method
|
|
76
|
+
* @param args Array of the arguments for the invoke or Calldata
|
|
77
|
+
* @param options
|
|
78
|
+
* @returns Add Transaction Response
|
|
79
|
+
*/
|
|
80
|
+
abstract invoke(method: string, args?: ArgsOrCalldata, options?: InvokeOptions): Promise<InvokeFunctionResponse>;
|
|
81
|
+
/**
|
|
82
|
+
* Estimates a method on a contract
|
|
83
|
+
*
|
|
84
|
+
* @param method name of the method
|
|
85
|
+
* @param args Array of the arguments for the call or Calldata
|
|
86
|
+
* @param options optional blockIdentifier
|
|
87
|
+
*/
|
|
88
|
+
abstract estimate(method: string, args?: ArgsOrCalldata, options?: {
|
|
89
|
+
blockIdentifier?: BlockIdentifier;
|
|
90
|
+
}): Promise<EstimateFeeResponse>;
|
|
91
|
+
/**
|
|
92
|
+
* Calls a method on a contract
|
|
93
|
+
*
|
|
94
|
+
* @param method name of the method
|
|
95
|
+
* @param args Array of the arguments for the call or Calldata
|
|
96
|
+
* @returns Invocation object
|
|
97
|
+
*/
|
|
98
|
+
abstract populate(method: string, args?: ArgsOrCalldata): Invocation;
|
|
99
|
+
/**
|
|
100
|
+
* Parse contract events of a GetTransactionReceiptResponse received from waitForTransaction. Based on contract's abi
|
|
101
|
+
*
|
|
102
|
+
* @param receipt transaction receipt
|
|
103
|
+
* @returns Events parsed
|
|
104
|
+
*/
|
|
105
|
+
abstract parseEvents(receipt: GetTransactionReceiptResponse): ParsedEvents;
|
|
106
|
+
/**
|
|
107
|
+
* tells if the contract comes from a Cairo 1 contract
|
|
108
|
+
*
|
|
109
|
+
* @returns TRUE if the contract comes from a Cairo1 contract
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const isCairo1: boolean = myContract.isCairo1();
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
abstract isCairo1(): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Retrieves the version of the contract (cairo version & compiler version)
|
|
118
|
+
*/
|
|
119
|
+
abstract getVersion(): Promise<ContractVersion>;
|
|
120
|
+
/**
|
|
121
|
+
* Returns a typed instance of ContractV2 based on the supplied ABI.
|
|
122
|
+
*
|
|
123
|
+
* @param {TAbi} tAbi - The ABI (Abstract Binary Interface) of the ContractV2.
|
|
124
|
+
* @return {TypedContractV2<TAbi>} - A typed instance of ContractV2.
|
|
125
|
+
*/
|
|
126
|
+
abstract typedv2<TAbi extends AbiKanabi>(tAbi: TAbi): TypedContractV2<TAbi>;
|
|
127
|
+
}
|
|
128
|
+
export {};
|