diff --git a/packages/starknet-snap/src/createAccount.ts b/packages/starknet-snap/src/createAccount.ts index bdf7e4c2..d8704183 100644 --- a/packages/starknet-snap/src/createAccount.ts +++ b/packages/starknet-snap/src/createAccount.ts @@ -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'; @@ -26,6 +25,7 @@ import { waitForTransaction, estimateAccountDeployFee, } from './utils/starknetUtils'; +import { newDeployTransaction } from './utils/transaction'; /** * Create an starknet account. @@ -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); } diff --git a/packages/starknet-snap/src/upgradeAccContract.ts b/packages/starknet-snap/src/upgradeAccContract.ts index a6c16204..056b8003 100644 --- a/packages/starknet-snap/src/upgradeAccContract.ts +++ b/packages/starknet-snap/src/upgradeAccContract.ts @@ -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'; @@ -23,6 +21,7 @@ import { isAccountDeployed, estimateFee, } from './utils/starknetUtils'; +import { newInvokeTransaction } from './utils/transaction'; /** * @@ -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); diff --git a/packages/starknet-snap/src/utils/transaction.test.ts b/packages/starknet-snap/src/utils/transaction.test.ts index 17f89eae..768bfa24 100644 --- a/packages/starknet-snap/src/utils/transaction.test.ts +++ b/packages/starknet-snap/src/utils/transaction.test.ts @@ -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, diff --git a/packages/starknet-snap/test/src/upgradeAccContract.test.ts b/packages/starknet-snap/test/src/upgradeAccContract.test.ts index 899f7ede..026b5fd4 100644 --- a/packages/starknet-snap/test/src/upgradeAccContract.test.ts +++ b/packages/starknet-snap/test/src/upgradeAccContract.test.ts @@ -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)); - }); }); });