Skip to content

Commit

Permalink
chore: update RPCs - starkNet_createAccount , `starkNet_createAccou…
Browse files Browse the repository at this point in the history
…ntLegacy`, `starkNet_upgradeAccContract` to handle new txn state (#458)

* feat: add stark scan client

* chore: add starkscan config

* chore: lint

* chore: add interface

* chore: support multiple txn

* chore: update starkscan

* chore: update stark scan client

* chore: update contract func name

* chore: fix test

* chore: update data client

* chore: re-structure starkscan type

* chore: add test coverage

* chore: factory and config

* chore: add backward compatibility for transactions type

* chore: add comment

* chore: lint

* chore: resolve review comment

* chore: change dataVersion to enum

* chore: lint

* chore: update test helper and refactor ContractAddressFilter

* chore: lint

* chore: add test for dataVersion filter

* chore: update txn state mgr test

* chore: update search condition

* chore: update starkscan to handle missing selector_name

* chore: apply starkscan for list transaction

* chore: update list transactions handle

* chore: refactor execute txn

* chore: refactor execute txn

* chore: update create account and upgrade account

* chore: lint

* Revert "chore: lint"

This reverts commit 12be249.

* Revert "chore: update create account and upgrade account"

This reverts commit cf64931.

* chore: update rpcs to handle v2 data

* chore: update rpcs to handle new txn state data

* chore: fix naming

---------

Co-authored-by: khanti42 <[email protected]>
  • Loading branch information
stanleyyconsensys and khanti42 authored Dec 11, 2024
1 parent c363481 commit 6619c62
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 61 deletions.
21 changes: 7 additions & 14 deletions packages/starknet-snap/src/createAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import type {
ApiParamsWithKeyDeriver,
CreateAccountRequestParams,
} from './types/snapApi';
import type { AccContract, Transaction } from './types/snapState';
import { VoyagerTransactionType, TransactionStatus } from './types/snapState';
import type { AccContract } from './types/snapState';
import { CAIRO_VERSION_LEGACY, CAIRO_VERSION } from './utils/constants';
import { logger } from './utils/logger';
import { toJson } from './utils/serializer';
Expand All @@ -26,6 +25,7 @@ import {
waitForTransaction,
estimateAccountDeployFee,
} from './utils/starknetUtils';
import { newDeployTransaction } from './utils/transaction';

/**
* Create an starknet account.
Expand Down Expand Up @@ -142,21 +142,14 @@ export async function createAccount(

await upsertAccount(userAccount, wallet, saveMutex);

const txn: Transaction = {
const txn = newDeployTransaction({
txnHash: deployResp.transaction_hash,
txnType: VoyagerTransactionType.DEPLOY_ACCOUNT,
chainId: network.chainId,
senderAddress: deployResp.contract_address,
contractAddress: deployResp.contract_address,
contractFuncName: '',
contractCallData: [],
finalityStatus: TransactionStatus.RECEIVED,
executionStatus: TransactionStatus.RECEIVED,
status: '',
failureReason: '',
eventIds: [],
timestamp: Math.floor(Date.now() / 1000),
};
// whenever create account is happen, we pay the fee in ETH, so txnVersion is 1
// FIXME: it should allow to pay the fee in STRK
txnVersion: 1,
});

await upsertTransaction(txn, wallet, saveMutex);
}
Expand Down
23 changes: 8 additions & 15 deletions packages/starknet-snap/src/upgradeAccContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import type {
ApiParamsWithKeyDeriver,
UpgradeTransactionRequestParams,
} from './types/snapApi';
import type { Transaction } from './types/snapState';
import { TransactionStatus, VoyagerTransactionType } from './types/snapState';
import { ACCOUNT_CLASS_HASH, CAIRO_VERSION_LEGACY } from './utils/constants';
import { logger } from './utils/logger';
import { toJson } from './utils/serializer';
Expand All @@ -23,6 +21,7 @@ import {
isAccountDeployed,
estimateFee,
} from './utils/starknetUtils';
import { newInvokeTransaction } from './utils/transaction';

/**
*
Expand Down Expand Up @@ -145,21 +144,15 @@ export async function upgradeAccContract(params: ApiParamsWithKeyDeriver) {
throw new Error(`Transaction hash is not found`);
}

const txn: Transaction = {
const txn = newInvokeTransaction({
txnHash: txnResp.transaction_hash,
txnType: VoyagerTransactionType.INVOKE,
chainId: network.chainId,
senderAddress: contractAddress,
contractAddress,
contractFuncName: 'upgrade',
contractCallData: CallData.compile(calldata),
finalityStatus: TransactionStatus.RECEIVED,
executionStatus: TransactionStatus.RECEIVED,
status: '', // DEPRECATED LATER
failureReason: '',
eventIds: [],
timestamp: Math.floor(Date.now() / 1000),
};
chainId: network.chainId,
maxFee: maxFee.toString(10),
calls: [txnInvocation],
// whenever upgrade is happen, we pay the fee in ETH, so txnVersion is 1
txnVersion: 1,
});

await upsertTransaction(txn, wallet, saveMutex);

Expand Down
2 changes: 1 addition & 1 deletion packages/starknet-snap/src/utils/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('feeTokenToTransactionVersion', () => {
});

it.each([FeeToken.ETH, 'invalid_unit'])(
'converts feeToken string to transaction version v1 if it not STRK - %s',
'converts feeToken string to transaction version v1 if it is not STRK - %s',
(txnVersion: string) => {
expect(feeTokenToTransactionVersion(txnVersion)).toStrictEqual(
constants.TRANSACTION_VERSION.V1,
Expand Down
31 changes: 0 additions & 31 deletions packages/starknet-snap/test/src/upgradeAccContract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,36 +280,5 @@ describe('Test function: upgradeAccContract', function () {
expect(result.message).to.be.include('Transaction hash is not found');
}
});

it('should save transaction when execute transaction success', async function () {
executeTxnStub.resolves(sendTransactionResp);
estimateFeeStub.resolves(estimateFeeResp);
walletStub.rpcStubs.snap_dialog.resolves(true);
const address = (
apiParams.requestParams as UpgradeTransactionRequestParams
).contractAddress;
const calldata = CallData.compile({
implementation: ACCOUNT_CLASS_HASH,
calldata: [0],
});
const txn = {
txnHash: sendTransactionResp.transaction_hash,
txnType: VoyagerTransactionType.INVOKE,
chainId: STARKNET_SEPOLIA_TESTNET_NETWORK.chainId,
senderAddress: address,
contractAddress: address,
contractFuncName: 'upgrade',
contractCallData: CallData.compile(calldata),
finalityStatus: TransactionStatus.RECEIVED,
executionStatus: TransactionStatus.RECEIVED,
status: '',
failureReason: '',
eventIds: [],
};

const result = await upgradeAccContract(apiParams);
expect(result).to.be.equal(sendTransactionResp);
expect(upsertTransactionStub).to.calledOnceWith(sinon.match(txn));
});
});
});

0 comments on commit 6619c62

Please sign in to comment.