Skip to content

Commit a8fdfe3

Browse files
committed
feat: declare v2 intermidiate
1 parent 7cec344 commit a8fdfe3

File tree

7 files changed

+36
-8
lines changed

7 files changed

+36
-8
lines changed

src/account/default.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ export class Account extends Provider implements AccountInterface {
302302
}
303303

304304
public async declare(
305-
{ contract, classHash: providedClassHash }: DeclareContractPayload,
305+
{ contract, classHash: providedClassHash }: DeclareContractPayload, // TODO: compiledClassHash i casm
306306
transactionsDetail: InvocationsDetails = {}
307307
): Promise<DeclareContractResponse> {
308308
const nonce = toBigInt(transactionsDetail.nonce ?? (await this.getNonce()));

src/provider/sequencer.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,14 +388,27 @@ export class SequencerProvider implements ProviderInterface {
388388
{ senderAddress, contractDefinition, signature }: DeclareContractTransaction,
389389
details: InvocationsDetailsWithNonce
390390
): Promise<DeclareContractResponse> {
391+
if ('program' in contractDefinition) {
392+
return this.fetchEndpoint('add_transaction', undefined, {
393+
type: TransactionType.DECLARE,
394+
contract_class: contractDefinition,
395+
nonce: toHex(details.nonce),
396+
signature: signatureToDecimalArray(signature),
397+
sender_address: senderAddress,
398+
max_fee: toHex(details.maxFee || 0),
399+
version: '0x1',
400+
}).then(this.responseParser.parseDeclareContractResponse);
401+
}
402+
// Cairo 1
391403
return this.fetchEndpoint('add_transaction', undefined, {
392404
type: TransactionType.DECLARE,
405+
sender_address: senderAddress,
406+
compiled_class_hash: details.compiledClassHash,
393407
contract_class: contractDefinition,
394408
nonce: toHex(details.nonce),
395409
signature: signatureToDecimalArray(signature),
396-
sender_address: senderAddress,
397410
max_fee: toHex(details.maxFee || 0),
398-
version: toHex(details.version || 1),
411+
version: '0x2',
399412
}).then(this.responseParser.parseDeclareContractResponse);
400413
}
401414

src/signer/default.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,24 @@ export class Signer implements SignerInterface {
7878

7979
public async signDeclareTransaction(
8080
// contractClass: ContractClass, // Should be used once class hash is present in ContractClass
81-
{ classHash, senderAddress, chainId, maxFee, version, nonce }: DeclareSignerDetails
81+
{
82+
classHash,
83+
senderAddress,
84+
chainId,
85+
maxFee,
86+
version,
87+
nonce,
88+
compiledClassHash,
89+
}: DeclareSignerDetails
8290
) {
8391
const msgHash = calculateDeclareTransactionHash(
8492
classHash,
8593
senderAddress,
8694
version,
8795
maxFee,
8896
chainId,
89-
nonce
97+
nonce,
98+
compiledClassHash
9099
);
91100

92101
return starkCurve.sign(msgHash, this.pk);

src/types/api/sequencer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export namespace Sequencer {
8686
nonce: BigNumberish;
8787
max_fee?: BigNumberish;
8888
version?: BigNumberish;
89+
compiled_class_hash?: string; // v2 declare
8990
};
9091

9192
export type DeployTransaction = {

src/types/lib.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ export type InvocationsDetails = {
9898
version?: BigNumberish;
9999
};
100100

101-
export type InvocationsDetailsWithNonce = InvocationsDetails & { nonce: BigNumberish };
101+
export type InvocationsDetailsWithNonce = InvocationsDetails & {
102+
nonce: BigNumberish;
103+
compiledClassHash?: string;
104+
};
102105

103106
export enum TransactionStatus {
104107
NOT_RECEIVED = 'NOT_RECEIVED',

src/types/signer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface DeclareSignerDetails {
1414
maxFee: BigNumberish;
1515
version: BigNumberish;
1616
nonce: BigNumberish;
17+
compiledClassHash?: string;
1718
}
1819

1920
export type DeployAccountSignerDetails = Required<DeployAccountContractPayload> &

src/utils/hash.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ export function calculateDeclareTransactionHash(
126126
version: BigNumberish,
127127
maxFee: BigNumberish,
128128
chainId: StarknetChainId,
129-
nonce: BigNumberish
129+
nonce: BigNumberish,
130+
compiledClassHash?: string
130131
): string {
131132
return calculateTransactionHashCommon(
132133
TransactionHashPrefix.DECLARE,
@@ -136,7 +137,7 @@ export function calculateDeclareTransactionHash(
136137
[classHash],
137138
maxFee,
138139
chainId,
139-
[nonce]
140+
[nonce, ...(compiledClassHash ? [compiledClassHash] : [])]
140141
);
141142
}
142143

0 commit comments

Comments
 (0)