starknet 4.7.0 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/CONTRIBUTING.md +2 -2
- package/__mocks__/l1l2_compiled.json +10107 -0
- package/__tests__/defaultProvider.test.ts +0 -6
- package/__tests__/fixtures.ts +2 -0
- package/__tests__/sequencerProvider.test.ts +40 -1
- package/__tests__/utils/merkle.test.ts +15 -0
- package/dist/provider/sequencer.d.ts +2 -1
- package/dist/provider/sequencer.js +22 -1
- package/dist/types/api/sequencer.d.ts +21 -16
- package/dist/types/provider.d.ts +4 -0
- package/dist/utils/hash.d.ts +6 -0
- package/dist/utils/hash.js +16 -1
- package/dist/utils/merkle.js +2 -1
- package/dist/utils/number.d.ts +5 -0
- package/dist/utils/number.js +29 -1
- package/dist/utils/responseParser/sequencer.js +7 -19
- package/package.json +1 -1
- package/provider/sequencer.d.ts +2 -1
- package/provider/sequencer.js +22 -1
- package/src/provider/sequencer.ts +31 -3
- package/src/types/api/sequencer.ts +22 -16
- package/src/types/provider.ts +4 -0
- package/src/utils/hash.ts +24 -1
- package/src/utils/merkle.ts +2 -1
- package/src/utils/number.ts +27 -0
- package/src/utils/responseParser/sequencer.ts +12 -7
- package/types/api/sequencer.d.ts +21 -16
- package/types/provider.d.ts +4 -0
- package/utils/hash.d.ts +6 -0
- package/utils/hash.js +16 -1
- package/utils/merkle.js +2 -1
- package/utils/number.d.ts +5 -0
- package/utils/number.js +29 -1
- package/utils/responseParser/sequencer.js +7 -19
- package/www/docs/API/provider.md +14 -6
- package/www/guides/account.md +1 -1
|
@@ -245,9 +245,7 @@ describe('defaultProvider', () => {
|
|
|
245
245
|
|
|
246
246
|
expect(receipt).toHaveProperty('transaction_hash');
|
|
247
247
|
expect(receipt).toHaveProperty('status');
|
|
248
|
-
expect(receipt).toHaveProperty('status_data');
|
|
249
248
|
expect(receipt).toHaveProperty('messages_sent');
|
|
250
|
-
expect(receipt).toHaveProperty('l1_origin_message');
|
|
251
249
|
expect(receipt).toHaveProperty('events');
|
|
252
250
|
});
|
|
253
251
|
});
|
|
@@ -260,10 +258,6 @@ describe('defaultProvider', () => {
|
|
|
260
258
|
|
|
261
259
|
beforeAll(async () => {
|
|
262
260
|
deployResponse = await provider.deployContract({ contract: compiledErc20 });
|
|
263
|
-
console.log(
|
|
264
|
-
'🚀 ~ file: defaultProvider.test.ts ~ line 264 ~ beforeAll ~ deployResponse',
|
|
265
|
-
deployResponse
|
|
266
|
-
);
|
|
267
261
|
contractAddress = deployResponse.contract_address;
|
|
268
262
|
declareResponse = await provider.declareContract({ contract: compiledErc20 });
|
|
269
263
|
await Promise.all([
|
package/__tests__/fixtures.ts
CHANGED
|
@@ -8,6 +8,7 @@ const readContract = (name: string): CompiledContract =>
|
|
|
8
8
|
|
|
9
9
|
export const compiledOpenZeppelinAccount = readContract('Account');
|
|
10
10
|
export const compiledErc20 = readContract('ERC20');
|
|
11
|
+
export const compiledL1L2 = readContract('l1l2_compiled');
|
|
11
12
|
export const compiledTypeTransformation = readContract('contract');
|
|
12
13
|
export const compiledMulticall = readContract('multicall');
|
|
13
14
|
export const compiledTestDapp = readContract('TestDapp');
|
|
@@ -26,6 +27,7 @@ const IS_RPC_DEVNET = Boolean(
|
|
|
26
27
|
);
|
|
27
28
|
const IS_SEQUENCER = !IS_RPC;
|
|
28
29
|
const IS_SEQUENCER_DEVNET = !BASE_URL.includes('starknet.io');
|
|
30
|
+
export const IS_SEQUENCER_GOERLI = BASE_URL === 'https://alpha4.starknet.io';
|
|
29
31
|
export const IS_DEVNET = IS_SEQUENCER ? IS_SEQUENCER_DEVNET : IS_RPC_DEVNET;
|
|
30
32
|
|
|
31
33
|
export const getTestProvider = () => {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Contract, Provider, SequencerProvider, stark } from '../src';
|
|
2
2
|
import { toBN } from '../src/utils/number';
|
|
3
3
|
import {
|
|
4
|
+
IS_SEQUENCER_GOERLI,
|
|
4
5
|
compiledErc20,
|
|
6
|
+
compiledL1L2,
|
|
5
7
|
describeIfNotDevnet,
|
|
6
8
|
describeIfSequencer,
|
|
7
9
|
getTestProvider,
|
|
@@ -44,7 +46,7 @@ describeIfSequencer('SequencerProvider', () => {
|
|
|
44
46
|
|
|
45
47
|
test('transaction trace', async () => {
|
|
46
48
|
const transactionTrace = await sequencerProvider.getTransactionTrace(exampleTransactionHash);
|
|
47
|
-
|
|
49
|
+
// TODO test optional properties
|
|
48
50
|
expect(transactionTrace).toHaveProperty('signature');
|
|
49
51
|
});
|
|
50
52
|
|
|
@@ -82,4 +84,41 @@ describeIfSequencer('SequencerProvider', () => {
|
|
|
82
84
|
expect(res).toStrictEqual(result.res);
|
|
83
85
|
});
|
|
84
86
|
});
|
|
87
|
+
|
|
88
|
+
describe('Test Estimate message fee', () => {
|
|
89
|
+
const L1_ADDRESS = '0x8359E4B0152ed5A731162D3c7B0D8D56edB165A0';
|
|
90
|
+
let l1l2ContractAddress: string;
|
|
91
|
+
|
|
92
|
+
beforeAll(async () => {
|
|
93
|
+
if (IS_SEQUENCER_GOERLI) {
|
|
94
|
+
l1l2ContractAddress = '0x2863141e0d9a74e9b484c1f5b1e3a2f6cbb6b84df8233c7c1cbe31334d9aed8';
|
|
95
|
+
} else {
|
|
96
|
+
const { transaction_hash, contract_address } = await sequencerProvider.deployContract({
|
|
97
|
+
contract: compiledL1L2,
|
|
98
|
+
});
|
|
99
|
+
await sequencerProvider.waitForTransaction(transaction_hash);
|
|
100
|
+
l1l2ContractAddress = contract_address;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('estimate message fee', async () => {
|
|
105
|
+
const estimation = await sequencerProvider.estimateMessageFee(
|
|
106
|
+
{
|
|
107
|
+
from_address: L1_ADDRESS,
|
|
108
|
+
to_address: l1l2ContractAddress,
|
|
109
|
+
entry_point_selector: 'deposit',
|
|
110
|
+
payload: ['556', '123'],
|
|
111
|
+
},
|
|
112
|
+
'latest'
|
|
113
|
+
);
|
|
114
|
+
expect(estimation).toEqual(
|
|
115
|
+
expect.objectContaining({
|
|
116
|
+
overall_fee: expect.anything(),
|
|
117
|
+
gas_price: expect.anything(),
|
|
118
|
+
gas_usage: expect.anything(),
|
|
119
|
+
unit: 'wei',
|
|
120
|
+
})
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
85
124
|
});
|
|
@@ -1,6 +1,21 @@
|
|
|
1
|
+
import { pedersen } from '../../src/utils/hash';
|
|
1
2
|
import { MerkleTree, proofMerklePath } from '../../src/utils/merkle';
|
|
3
|
+
import { toBN } from '../../src/utils/number';
|
|
2
4
|
|
|
3
5
|
describe('MerkleTree class', () => {
|
|
6
|
+
describe('calculate hashes', () => {
|
|
7
|
+
test('should generate hash with sorted arguments', async () => {
|
|
8
|
+
let leaves = ['0x12', '0xa']; // 18, 10
|
|
9
|
+
let merkleHash = MerkleTree.hash(leaves[0], leaves[1]);
|
|
10
|
+
let rawHash = pedersen([toBN(leaves[1]), toBN(leaves[0])]);
|
|
11
|
+
expect(merkleHash).toBe(rawHash);
|
|
12
|
+
|
|
13
|
+
leaves = ['0x5bb9440e27889a364bcb678b1f679ecd1347acdedcbf36e83494f857cc58026', '0x3'];
|
|
14
|
+
merkleHash = MerkleTree.hash(leaves[0], leaves[1]);
|
|
15
|
+
rawHash = pedersen([toBN(leaves[1]), toBN(leaves[0])]);
|
|
16
|
+
expect(merkleHash).toBe(rawHash);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
4
19
|
describe('generate roots', () => {
|
|
5
20
|
test('should generate valid root for 1 elements', async () => {
|
|
6
21
|
const leaves = ['0x1'];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
2
|
import { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
|
|
3
|
-
import { GetContractAddressesResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Sequencer } from '../types/api';
|
|
3
|
+
import { CallL1Handler, GetContractAddressesResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Sequencer } from '../types/api';
|
|
4
4
|
import { BigNumberish } from '../utils/number';
|
|
5
5
|
import { ProviderInterface } from './interface';
|
|
6
6
|
import { BlockIdentifier } from './utils';
|
|
@@ -65,5 +65,6 @@ export declare class SequencerProvider implements ProviderInterface {
|
|
|
65
65
|
* @returns the transaction trace
|
|
66
66
|
*/
|
|
67
67
|
getTransactionTrace(txHash: BigNumberish): Promise<GetTransactionTraceResponse>;
|
|
68
|
+
estimateMessageFee({ from_address, to_address, entry_point_selector, payload }: CallL1Handler, blockIdentifier?: BlockIdentifier): Promise<Sequencer.EstimateFeeResponse>;
|
|
68
69
|
}
|
|
69
70
|
export {};
|
|
@@ -123,7 +123,12 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
123
123
|
return gatewayUrlEndpoints.includes(endpoint) ? this.gatewayUrl : this.feederGatewayUrl;
|
|
124
124
|
};
|
|
125
125
|
SequencerProvider.prototype.getFetchMethod = function (endpoint) {
|
|
126
|
-
var postMethodEndpoints = [
|
|
126
|
+
var postMethodEndpoints = [
|
|
127
|
+
'add_transaction',
|
|
128
|
+
'call_contract',
|
|
129
|
+
'estimate_fee',
|
|
130
|
+
'estimate_message_fee',
|
|
131
|
+
];
|
|
127
132
|
return postMethodEndpoints.includes(endpoint) ? 'POST' : 'GET';
|
|
128
133
|
};
|
|
129
134
|
SequencerProvider.prototype.getQueryString = function (query) {
|
|
@@ -463,6 +468,22 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
463
468
|
});
|
|
464
469
|
});
|
|
465
470
|
};
|
|
471
|
+
SequencerProvider.prototype.estimateMessageFee = function (_a, blockIdentifier) {
|
|
472
|
+
var from_address = _a.from_address, to_address = _a.to_address, entry_point_selector = _a.entry_point_selector, payload = _a.payload;
|
|
473
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
474
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
475
|
+
var validCallL1Handler;
|
|
476
|
+
return __generator(this, function (_b) {
|
|
477
|
+
validCallL1Handler = {
|
|
478
|
+
from_address: (0, number_1.getDecimalString)(from_address),
|
|
479
|
+
to_address: (0, number_1.getHexString)(to_address),
|
|
480
|
+
entry_point_selector: (0, hash_1.getSelector)(entry_point_selector),
|
|
481
|
+
payload: (0, number_1.getHexStringArray)(payload),
|
|
482
|
+
};
|
|
483
|
+
return [2 /*return*/, this.fetchEndpoint('estimate_message_fee', { blockIdentifier: blockIdentifier }, validCallL1Handler)];
|
|
484
|
+
});
|
|
485
|
+
});
|
|
486
|
+
};
|
|
466
487
|
return SequencerProvider;
|
|
467
488
|
}());
|
|
468
489
|
exports.SequencerProvider = SequencerProvider;
|
|
@@ -15,15 +15,17 @@ export declare type GetContractAddressesResponse = {
|
|
|
15
15
|
Starknet: string;
|
|
16
16
|
GpsStatementVerifier: string;
|
|
17
17
|
};
|
|
18
|
-
export declare type
|
|
18
|
+
export declare type FunctionInvocation = {
|
|
19
19
|
caller_address: string;
|
|
20
20
|
contract_address: string;
|
|
21
|
-
code_address: string;
|
|
22
|
-
selector: string;
|
|
23
21
|
calldata: RawCalldata;
|
|
22
|
+
call_type?: string;
|
|
23
|
+
class_hash?: string;
|
|
24
|
+
selector?: string;
|
|
25
|
+
entry_point_type?: EntryPointType;
|
|
24
26
|
result: Array<any>;
|
|
25
27
|
execution_resources: ExecutionResources;
|
|
26
|
-
|
|
28
|
+
internal_calls: Array<FunctionInvocation>;
|
|
27
29
|
events: Array<any>;
|
|
28
30
|
messages: Array<any>;
|
|
29
31
|
};
|
|
@@ -40,18 +42,9 @@ export declare type ExecutionResources = {
|
|
|
40
42
|
n_memory_holes: number;
|
|
41
43
|
};
|
|
42
44
|
export declare type GetTransactionTraceResponse = {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
code_address: string;
|
|
47
|
-
selector: string;
|
|
48
|
-
calldata: RawArgs;
|
|
49
|
-
result: Array<any>;
|
|
50
|
-
execution_resources: ExecutionResources;
|
|
51
|
-
internal_call: Array<any>;
|
|
52
|
-
events: Array<any>;
|
|
53
|
-
messages: Array<any>;
|
|
54
|
-
};
|
|
45
|
+
validate_invocation?: FunctionInvocation;
|
|
46
|
+
function_invocation?: FunctionInvocation;
|
|
47
|
+
fee_transfer_invocation?: FunctionInvocation;
|
|
55
48
|
signature: Signature;
|
|
56
49
|
};
|
|
57
50
|
export declare type RawArgs = {
|
|
@@ -60,6 +53,12 @@ export declare type RawArgs = {
|
|
|
60
53
|
[k: string]: BigNumberish;
|
|
61
54
|
};
|
|
62
55
|
};
|
|
56
|
+
export declare type CallL1Handler = {
|
|
57
|
+
from_address: string;
|
|
58
|
+
to_address: string;
|
|
59
|
+
entry_point_selector: string;
|
|
60
|
+
payload: Array<string>;
|
|
61
|
+
};
|
|
63
62
|
export declare namespace Sequencer {
|
|
64
63
|
type DeclareTransaction = {
|
|
65
64
|
type: 'DECLARE';
|
|
@@ -165,6 +164,7 @@ export declare namespace Sequencer {
|
|
|
165
164
|
status: Status;
|
|
166
165
|
gas_price: string;
|
|
167
166
|
sequencer_address: string;
|
|
167
|
+
starknet_version: string;
|
|
168
168
|
};
|
|
169
169
|
type CallContractTransaction = Omit<InvokeFunctionTransaction, 'type' | 'entry_point_type' | 'nonce'> & {
|
|
170
170
|
entry_point_selector: string;
|
|
@@ -296,5 +296,10 @@ export declare namespace Sequencer {
|
|
|
296
296
|
REQUEST: never;
|
|
297
297
|
RESPONSE: any;
|
|
298
298
|
};
|
|
299
|
+
estimate_message_fee: {
|
|
300
|
+
QUERY: any;
|
|
301
|
+
REQUEST: any;
|
|
302
|
+
RESPONSE: EstimateFeeResponse;
|
|
303
|
+
};
|
|
299
304
|
};
|
|
300
305
|
}
|
package/dist/types/provider.d.ts
CHANGED
|
@@ -13,6 +13,10 @@ export interface GetBlockResponse {
|
|
|
13
13
|
parent_hash: string;
|
|
14
14
|
status: Status;
|
|
15
15
|
transactions: Array<string>;
|
|
16
|
+
gas_price?: string;
|
|
17
|
+
sequencer_address?: string;
|
|
18
|
+
starknet_version?: string;
|
|
19
|
+
transaction_receipts?: any;
|
|
16
20
|
}
|
|
17
21
|
export interface GetCodeResponse {
|
|
18
22
|
bytecode: string[];
|
package/dist/utils/hash.d.ts
CHANGED
|
@@ -21,6 +21,12 @@ export declare function starknetKeccak(value: string): BN;
|
|
|
21
21
|
* @returns hex selector of given abi function name
|
|
22
22
|
*/
|
|
23
23
|
export declare function getSelectorFromName(funcName: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Function to get hex selector from function name, decimal string or hex string
|
|
26
|
+
* @param value hex string | decimal string | string
|
|
27
|
+
* @returns Hex selector
|
|
28
|
+
*/
|
|
29
|
+
export declare function getSelector(value: string): string;
|
|
24
30
|
export declare function pedersen(input: [BigNumberish, BigNumberish]): string;
|
|
25
31
|
export declare function computeHashOnElements(data: BigNumberish[]): string;
|
|
26
32
|
export declare function calculateTransactionHashCommon(txHashPrefix: TransactionHashPrefix, version: BigNumberish, contractAddress: BigNumberish, entryPointSelector: BigNumberish, calldata: BigNumberish[], maxFee: BigNumberish, chainId: StarknetChainId, additionalData?: BigNumberish[]): string;
|
package/dist/utils/hash.js
CHANGED
|
@@ -28,7 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
29
|
};
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.calculateContractAddressFromHash = exports.calculateTransactionHash = exports.calculateDeployTransactionHash = exports.calculateTransactionHashCommon = exports.computeHashOnElements = exports.pedersen = exports.getSelectorFromName = exports.starknetKeccak = exports.keccakBn = exports.feeTransactionVersion = exports.transactionVersion = void 0;
|
|
31
|
+
exports.calculateContractAddressFromHash = exports.calculateTransactionHash = exports.calculateDeployTransactionHash = exports.calculateTransactionHashCommon = exports.computeHashOnElements = exports.pedersen = exports.getSelector = exports.getSelectorFromName = exports.starknetKeccak = exports.keccakBn = exports.feeTransactionVersion = exports.transactionVersion = void 0;
|
|
32
32
|
var keccak_1 = require("ethereum-cryptography/keccak");
|
|
33
33
|
var utils_1 = require("ethereum-cryptography/utils");
|
|
34
34
|
var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
@@ -70,6 +70,21 @@ function getSelectorFromName(funcName) {
|
|
|
70
70
|
return (0, number_1.toHex)(starknetKeccak(funcName));
|
|
71
71
|
}
|
|
72
72
|
exports.getSelectorFromName = getSelectorFromName;
|
|
73
|
+
/**
|
|
74
|
+
* Function to get hex selector from function name, decimal string or hex string
|
|
75
|
+
* @param value hex string | decimal string | string
|
|
76
|
+
* @returns Hex selector
|
|
77
|
+
*/
|
|
78
|
+
function getSelector(value) {
|
|
79
|
+
if ((0, number_1.isHex)(value)) {
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
if ((0, number_1.isStringWholeNumber)(value)) {
|
|
83
|
+
return (0, number_1.toHexString)(value);
|
|
84
|
+
}
|
|
85
|
+
return getSelectorFromName(value);
|
|
86
|
+
}
|
|
87
|
+
exports.getSelector = getSelector;
|
|
73
88
|
var constantPoints = constants_1.CONSTANT_POINTS.map(function (coords) {
|
|
74
89
|
return ellipticCurve_1.ec.curve.point(coords[0], coords[1]);
|
|
75
90
|
});
|
package/dist/utils/merkle.js
CHANGED
|
@@ -27,6 +27,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
28
|
exports.proofMerklePath = exports.MerkleTree = void 0;
|
|
29
29
|
var hash_1 = require("./hash");
|
|
30
|
+
var number_1 = require("./number");
|
|
30
31
|
var MerkleTree = /** @class */ (function () {
|
|
31
32
|
function MerkleTree(leafHashes) {
|
|
32
33
|
this.branches = [];
|
|
@@ -52,7 +53,7 @@ var MerkleTree = /** @class */ (function () {
|
|
|
52
53
|
return this.build(newLeaves);
|
|
53
54
|
};
|
|
54
55
|
MerkleTree.hash = function (a, b) {
|
|
55
|
-
var _a = __read([a, b].sort(), 2), aSorted = _a[0], bSorted = _a[1];
|
|
56
|
+
var _a = __read([(0, number_1.toBN)(a), (0, number_1.toBN)(b)].sort(function (x, y) { return (x.gte(y) ? 1 : -1); }), 2), aSorted = _a[0], bSorted = _a[1];
|
|
56
57
|
return (0, hash_1.pedersen)([aSorted, bSorted]);
|
|
57
58
|
};
|
|
58
59
|
MerkleTree.prototype.getProof = function (leaf, branch, hashPath) {
|
package/dist/utils/number.d.ts
CHANGED
|
@@ -8,3 +8,8 @@ export declare function toFelt(num: BigNumberish): string;
|
|
|
8
8
|
export declare function assertInRange(input: BigNumberish, lowerBound: BigNumberish, upperBound: BigNumberish, inputName?: string): void;
|
|
9
9
|
export declare function bigNumberishArrayToDecimalStringArray(rawCalldata: BigNumberish[]): string[];
|
|
10
10
|
export declare function bigNumberishArrayToHexadecimalStringArray(rawCalldata: BigNumberish[]): string[];
|
|
11
|
+
export declare const isStringWholeNumber: (value: string) => boolean;
|
|
12
|
+
export declare const toHexString: (value: string) => string;
|
|
13
|
+
export declare function getDecimalString(value: string): string;
|
|
14
|
+
export declare function getHexString(value: string): string;
|
|
15
|
+
export declare function getHexStringArray(value: Array<string>): string[];
|
package/dist/utils/number.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.bigNumberishArrayToHexadecimalStringArray = exports.bigNumberishArrayToDecimalStringArray = exports.assertInRange = exports.toFelt = exports.hexToDecimalString = exports.toHex = exports.toBN = exports.isHex = void 0;
|
|
29
|
+
exports.getHexStringArray = exports.getHexString = exports.getDecimalString = exports.toHexString = exports.isStringWholeNumber = exports.bigNumberishArrayToHexadecimalStringArray = exports.bigNumberishArrayToDecimalStringArray = exports.assertInRange = exports.toFelt = exports.hexToDecimalString = exports.toHex = exports.toBN = exports.isHex = void 0;
|
|
30
30
|
var bn_js_1 = __importStar(require("bn.js"));
|
|
31
31
|
var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
32
32
|
var encode_1 = require("./encode");
|
|
@@ -80,3 +80,31 @@ function bigNumberishArrayToHexadecimalStringArray(rawCalldata) {
|
|
|
80
80
|
return rawCalldata.map(function (x) { return toHex(toBN(x)); });
|
|
81
81
|
}
|
|
82
82
|
exports.bigNumberishArrayToHexadecimalStringArray = bigNumberishArrayToHexadecimalStringArray;
|
|
83
|
+
var isStringWholeNumber = function (value) { return /^\d+$/.test(value); };
|
|
84
|
+
exports.isStringWholeNumber = isStringWholeNumber;
|
|
85
|
+
var toHexString = function (value) { return toHex(toBN(value)); };
|
|
86
|
+
exports.toHexString = toHexString;
|
|
87
|
+
function getDecimalString(value) {
|
|
88
|
+
if (isHex(value)) {
|
|
89
|
+
return hexToDecimalString(value);
|
|
90
|
+
}
|
|
91
|
+
if ((0, exports.isStringWholeNumber)(value)) {
|
|
92
|
+
return value;
|
|
93
|
+
}
|
|
94
|
+
throw new Error("".concat(value, " need to be hex-string or whole-number-string"));
|
|
95
|
+
}
|
|
96
|
+
exports.getDecimalString = getDecimalString;
|
|
97
|
+
function getHexString(value) {
|
|
98
|
+
if (isHex(value)) {
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
if ((0, exports.isStringWholeNumber)(value)) {
|
|
102
|
+
return (0, exports.toHexString)(value);
|
|
103
|
+
}
|
|
104
|
+
throw new Error("".concat(value, " need to be hex-string or whole-number-string"));
|
|
105
|
+
}
|
|
106
|
+
exports.getHexString = getHexString;
|
|
107
|
+
function getHexStringArray(value) {
|
|
108
|
+
return value.map(function (el) { return getHexString(el); });
|
|
109
|
+
}
|
|
110
|
+
exports.getHexStringArray = getHexStringArray;
|
|
@@ -35,17 +35,9 @@ var SequencerAPIResponseParser = /** @class */ (function (_super) {
|
|
|
35
35
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
36
36
|
}
|
|
37
37
|
SequencerAPIResponseParser.prototype.parseGetBlockResponse = function (res) {
|
|
38
|
-
return {
|
|
39
|
-
timestamp: res.timestamp,
|
|
40
|
-
block_hash: res.block_hash,
|
|
41
|
-
block_number: res.block_number,
|
|
42
|
-
new_root: res.state_root,
|
|
43
|
-
parent_hash: res.parent_block_hash,
|
|
44
|
-
status: res.status,
|
|
45
|
-
transactions: Object.values(res.transactions)
|
|
38
|
+
return __assign(__assign({}, res), { new_root: res.state_root, parent_hash: res.parent_block_hash, transactions: Object.values(res.transactions)
|
|
46
39
|
.map(function (value) { return 'transaction_hash' in value && value.transaction_hash; })
|
|
47
|
-
.filter(Boolean)
|
|
48
|
-
};
|
|
40
|
+
.filter(Boolean) });
|
|
49
41
|
};
|
|
50
42
|
SequencerAPIResponseParser.prototype.parseGetTransactionResponse = function (res) {
|
|
51
43
|
return {
|
|
@@ -66,15 +58,11 @@ var SequencerAPIResponseParser = /** @class */ (function (_super) {
|
|
|
66
58
|
};
|
|
67
59
|
};
|
|
68
60
|
SequencerAPIResponseParser.prototype.parseGetTransactionReceiptResponse = function (res) {
|
|
69
|
-
return {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
messages_sent: res.l2_to_l1_messages,
|
|
75
|
-
events: res.events,
|
|
76
|
-
l1_origin_message: undefined,
|
|
77
|
-
};
|
|
61
|
+
return __assign(__assign(__assign(__assign(__assign(__assign(__assign({ transaction_hash: res.transaction_hash, status: res.status, messages_sent: res.l2_to_l1_messages, events: res.events }, ('block_hash' in res && { block_hash: res.block_hash })), ('block_number' in res && { block_number: res.block_number })), ('actual_fee' in res && { actual_fee: res.actual_fee })), ('transaction_index' in res && { transaction_index: res.transaction_index })), ('execution_resources' in res && { execution_resources: res.execution_resources })), ('l1_to_l2_consumed_message' in res && {
|
|
62
|
+
l1_to_l2_consumed_message: res['l1_to_l2_consumed_message'],
|
|
63
|
+
})), ('transaction_failure_reason' in res && {
|
|
64
|
+
transaction_failure_reason: res.transaction_failure_reason,
|
|
65
|
+
}));
|
|
78
66
|
};
|
|
79
67
|
SequencerAPIResponseParser.prototype.parseFeeEstimateResponse = function (res) {
|
|
80
68
|
if ('overall_fee' in res) {
|
package/package.json
CHANGED
package/provider/sequencer.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
2
|
import { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
|
|
3
|
-
import { GetContractAddressesResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Sequencer } from '../types/api';
|
|
3
|
+
import { CallL1Handler, GetContractAddressesResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Sequencer } from '../types/api';
|
|
4
4
|
import { BigNumberish } from '../utils/number';
|
|
5
5
|
import { ProviderInterface } from './interface';
|
|
6
6
|
import { BlockIdentifier } from './utils';
|
|
@@ -65,5 +65,6 @@ export declare class SequencerProvider implements ProviderInterface {
|
|
|
65
65
|
* @returns the transaction trace
|
|
66
66
|
*/
|
|
67
67
|
getTransactionTrace(txHash: BigNumberish): Promise<GetTransactionTraceResponse>;
|
|
68
|
+
estimateMessageFee({ from_address, to_address, entry_point_selector, payload }: CallL1Handler, blockIdentifier?: BlockIdentifier): Promise<Sequencer.EstimateFeeResponse>;
|
|
68
69
|
}
|
|
69
70
|
export {};
|
package/provider/sequencer.js
CHANGED
|
@@ -123,7 +123,12 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
123
123
|
return gatewayUrlEndpoints.includes(endpoint) ? this.gatewayUrl : this.feederGatewayUrl;
|
|
124
124
|
};
|
|
125
125
|
SequencerProvider.prototype.getFetchMethod = function (endpoint) {
|
|
126
|
-
var postMethodEndpoints = [
|
|
126
|
+
var postMethodEndpoints = [
|
|
127
|
+
'add_transaction',
|
|
128
|
+
'call_contract',
|
|
129
|
+
'estimate_fee',
|
|
130
|
+
'estimate_message_fee',
|
|
131
|
+
];
|
|
127
132
|
return postMethodEndpoints.includes(endpoint) ? 'POST' : 'GET';
|
|
128
133
|
};
|
|
129
134
|
SequencerProvider.prototype.getQueryString = function (query) {
|
|
@@ -463,6 +468,22 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
463
468
|
});
|
|
464
469
|
});
|
|
465
470
|
};
|
|
471
|
+
SequencerProvider.prototype.estimateMessageFee = function (_a, blockIdentifier) {
|
|
472
|
+
var from_address = _a.from_address, to_address = _a.to_address, entry_point_selector = _a.entry_point_selector, payload = _a.payload;
|
|
473
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
474
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
475
|
+
var validCallL1Handler;
|
|
476
|
+
return __generator(this, function (_b) {
|
|
477
|
+
validCallL1Handler = {
|
|
478
|
+
from_address: (0, number_1.getDecimalString)(from_address),
|
|
479
|
+
to_address: (0, number_1.getHexString)(to_address),
|
|
480
|
+
entry_point_selector: (0, hash_1.getSelector)(entry_point_selector),
|
|
481
|
+
payload: (0, number_1.getHexStringArray)(payload),
|
|
482
|
+
};
|
|
483
|
+
return [2 /*return*/, this.fetchEndpoint('estimate_message_fee', { blockIdentifier: blockIdentifier }, validCallL1Handler)];
|
|
484
|
+
});
|
|
485
|
+
});
|
|
486
|
+
};
|
|
466
487
|
return SequencerProvider;
|
|
467
488
|
}());
|
|
468
489
|
exports.SequencerProvider = SequencerProvider;
|
|
@@ -18,15 +18,24 @@ import {
|
|
|
18
18
|
InvokeFunctionResponse,
|
|
19
19
|
} from '../types';
|
|
20
20
|
import {
|
|
21
|
+
CallL1Handler,
|
|
21
22
|
GetContractAddressesResponse,
|
|
22
23
|
GetTransactionStatusResponse,
|
|
23
24
|
GetTransactionTraceResponse,
|
|
24
25
|
Sequencer,
|
|
25
26
|
} from '../types/api';
|
|
26
27
|
import fetch from '../utils/fetchPonyfill';
|
|
27
|
-
import { getSelectorFromName } from '../utils/hash';
|
|
28
|
+
import { getSelector, getSelectorFromName } from '../utils/hash';
|
|
28
29
|
import { parse, parseAlwaysAsBig, stringify } from '../utils/json';
|
|
29
|
-
import {
|
|
30
|
+
import {
|
|
31
|
+
BigNumberish,
|
|
32
|
+
bigNumberishArrayToDecimalStringArray,
|
|
33
|
+
getDecimalString,
|
|
34
|
+
getHexString,
|
|
35
|
+
getHexStringArray,
|
|
36
|
+
toBN,
|
|
37
|
+
toHex,
|
|
38
|
+
} from '../utils/number';
|
|
30
39
|
import { parseContract, wait } from '../utils/provider';
|
|
31
40
|
import { SequencerAPIResponseParser } from '../utils/responseParser/sequencer';
|
|
32
41
|
import { randomAddress } from '../utils/stark';
|
|
@@ -117,7 +126,12 @@ export class SequencerProvider implements ProviderInterface {
|
|
|
117
126
|
}
|
|
118
127
|
|
|
119
128
|
private getFetchMethod(endpoint: keyof Sequencer.Endpoints) {
|
|
120
|
-
const postMethodEndpoints = [
|
|
129
|
+
const postMethodEndpoints = [
|
|
130
|
+
'add_transaction',
|
|
131
|
+
'call_contract',
|
|
132
|
+
'estimate_fee',
|
|
133
|
+
'estimate_message_fee',
|
|
134
|
+
];
|
|
121
135
|
|
|
122
136
|
return postMethodEndpoints.includes(endpoint) ? 'POST' : 'GET';
|
|
123
137
|
}
|
|
@@ -406,4 +420,18 @@ export class SequencerProvider implements ProviderInterface {
|
|
|
406
420
|
const txHashHex = toHex(toBN(txHash));
|
|
407
421
|
return this.fetchEndpoint('get_transaction_trace', { transactionHash: txHashHex });
|
|
408
422
|
}
|
|
423
|
+
|
|
424
|
+
public async estimateMessageFee(
|
|
425
|
+
{ from_address, to_address, entry_point_selector, payload }: CallL1Handler,
|
|
426
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
427
|
+
): Promise<Sequencer.EstimateFeeResponse> {
|
|
428
|
+
const validCallL1Handler = {
|
|
429
|
+
from_address: getDecimalString(from_address),
|
|
430
|
+
to_address: getHexString(to_address),
|
|
431
|
+
entry_point_selector: getSelector(entry_point_selector),
|
|
432
|
+
payload: getHexStringArray(payload),
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
return this.fetchEndpoint('estimate_message_fee', { blockIdentifier }, validCallL1Handler);
|
|
436
|
+
}
|
|
409
437
|
}
|
|
@@ -27,15 +27,17 @@ export type GetContractAddressesResponse = {
|
|
|
27
27
|
GpsStatementVerifier: string;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
export type
|
|
30
|
+
export type FunctionInvocation = {
|
|
31
31
|
caller_address: string;
|
|
32
32
|
contract_address: string;
|
|
33
|
-
code_address: string;
|
|
34
|
-
selector: string;
|
|
35
33
|
calldata: RawCalldata;
|
|
34
|
+
call_type?: string;
|
|
35
|
+
class_hash?: string;
|
|
36
|
+
selector?: string;
|
|
37
|
+
entry_point_type?: EntryPointType;
|
|
36
38
|
result: Array<any>;
|
|
37
39
|
execution_resources: ExecutionResources;
|
|
38
|
-
|
|
40
|
+
internal_calls: Array<FunctionInvocation>;
|
|
39
41
|
events: Array<any>;
|
|
40
42
|
messages: Array<any>;
|
|
41
43
|
};
|
|
@@ -54,18 +56,9 @@ export type ExecutionResources = {
|
|
|
54
56
|
};
|
|
55
57
|
|
|
56
58
|
export type GetTransactionTraceResponse = {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
code_address: string;
|
|
61
|
-
selector: string;
|
|
62
|
-
calldata: RawArgs;
|
|
63
|
-
result: Array<any>;
|
|
64
|
-
execution_resources: ExecutionResources;
|
|
65
|
-
internal_call: Array<any>;
|
|
66
|
-
events: Array<any>;
|
|
67
|
-
messages: Array<any>;
|
|
68
|
-
};
|
|
59
|
+
validate_invocation?: FunctionInvocation;
|
|
60
|
+
function_invocation?: FunctionInvocation;
|
|
61
|
+
fee_transfer_invocation?: FunctionInvocation;
|
|
69
62
|
signature: Signature;
|
|
70
63
|
};
|
|
71
64
|
|
|
@@ -73,6 +66,13 @@ export type RawArgs = {
|
|
|
73
66
|
[inputName: string]: string | string[] | { type: 'struct'; [k: string]: BigNumberish };
|
|
74
67
|
};
|
|
75
68
|
|
|
69
|
+
export type CallL1Handler = {
|
|
70
|
+
from_address: string;
|
|
71
|
+
to_address: string;
|
|
72
|
+
entry_point_selector: string;
|
|
73
|
+
payload: Array<string>;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
76
|
export namespace Sequencer {
|
|
77
77
|
export type DeclareTransaction = {
|
|
78
78
|
type: 'DECLARE';
|
|
@@ -197,6 +197,7 @@ export namespace Sequencer {
|
|
|
197
197
|
status: Status;
|
|
198
198
|
gas_price: string;
|
|
199
199
|
sequencer_address: string;
|
|
200
|
+
starknet_version: string;
|
|
200
201
|
};
|
|
201
202
|
|
|
202
203
|
export type CallContractTransaction = Omit<
|
|
@@ -340,5 +341,10 @@ export namespace Sequencer {
|
|
|
340
341
|
REQUEST: never;
|
|
341
342
|
RESPONSE: any;
|
|
342
343
|
};
|
|
344
|
+
estimate_message_fee: {
|
|
345
|
+
QUERY: any;
|
|
346
|
+
REQUEST: any;
|
|
347
|
+
RESPONSE: EstimateFeeResponse;
|
|
348
|
+
};
|
|
343
349
|
};
|
|
344
350
|
}
|
package/src/types/provider.ts
CHANGED
|
@@ -15,6 +15,10 @@ export interface GetBlockResponse {
|
|
|
15
15
|
parent_hash: string;
|
|
16
16
|
status: Status;
|
|
17
17
|
transactions: Array<string>;
|
|
18
|
+
gas_price?: string;
|
|
19
|
+
sequencer_address?: string;
|
|
20
|
+
starknet_version?: string;
|
|
21
|
+
transaction_receipts?: any;
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
export interface GetCodeResponse {
|