Skip to content

Commit

Permalink
Revert "Merge branch 'main' into feat/sf-644-update-eslint"
Browse files Browse the repository at this point in the history
This reverts commit 2058651, reversing
changes made to d232e45.
  • Loading branch information
stanleyyconsensys committed Jul 23, 2024
1 parent 2058651 commit e906af3
Show file tree
Hide file tree
Showing 55 changed files with 6,290 additions and 7,525 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,18 @@ jobs:
echo "VERSION=${BASE}-dev-${HASH}-${DATE}"
echo "TAG=dev"
echo "ENV=dev"
echo "LOG_LEVEL=all"
} >> "$GITHUB_OUTPUT"
elif [[ $ENV == "staging" ]]; then
{
echo "VERSION=${BASE}-staging"
echo "TAG=staging"
echo "ENV=staging"
echo "LOG_LEVEL=off"
} >> "$GITHUB_OUTPUT"
elif [[ $ENV == "production" ]]; then
{
echo "VERSION=${BASE}"
echo "TAG=latest"
echo "ENV=prod"
echo "LOG_LEVEL=off"
} >> "$GITHUB_OUTPUT"
else
echo "Invalid environment"
Expand All @@ -70,7 +67,6 @@ jobs:
AWS_S3_URL: ${{ steps.prepare_parameters.outputs.AWS_S3_URL }}
GET_STARKNET_PUBLIC_PATH: ${{ steps.prepare_parameters.outputs.GET_STARKNET_PUBLIC_PATH }}
CACHE_KEY: ${{ github.sha }}-${{ steps.prepare_parameters.outputs.ENV }}
LOG_LEVEL: ${{ steps.prepare_parameters.outputs.LOG_LEVEL }}

install-build:
needs:
Expand Down Expand Up @@ -107,7 +103,7 @@ jobs:
echo "Building UI with version $VERSION"
REACT_APP_DEBUG_LEVEL="${LOG_LEVEL}" REACT_APP_SNAP_VERSION="${VERSION}" yarn workspace wallet-ui build
REACT_APP_SNAP_VERSION="$VERSION" yarn workspace wallet-ui build
echo "Building Get Starknet with GET_STARKNET_PUBLIC_PATH=$GET_STARKNET_PUBLIC_PATH"
Expand All @@ -118,7 +114,6 @@ jobs:
VOYAGER_API_KEY: ${{ secrets.VOYAGER_API_KEY }}
ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }}
GET_STARKNET_PUBLIC_PATH: ${{ needs.prepare-deployment.outputs.GET_STARKNET_PUBLIC_PATH }}
LOG_LEVEL: ${{ needs.prepare-deployment.outputs.LOG_LEVEL }}
- name: Cache Build
uses: actions/cache@v3
id: cache
Expand Down
6 changes: 3 additions & 3 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"packages/starknet-snap": "2.9.0",
"packages/wallet-ui": "1.23.0",
"packages/get-starknet": "1.1.0"
"packages/starknet-snap": "2.8.0",
"packages/wallet-ui": "1.22.0",
"packages/get-starknet": "1.0.0"
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"clean": "yarn workspaces foreach --parallel --interlaced --verbose run clean",
"build": "yarn workspaces foreach --parallel --interlaced --verbose run build",
"lint": "yarn workspaces foreach --parallel --interlaced --verbose run lint",
"lint:fix": "yarn workspaces foreach --parallel --interlaced --verbose run lint:fix",
"start": "yarn workspaces foreach --parallel --interlaced --verbose run start",
"test": "yarn workspaces foreach --parallel --interlaced --verbose run test",
"prepare": "husky install"
Expand Down
7 changes: 0 additions & 7 deletions packages/get-starknet/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
# Changelog

## [1.1.0](https://github.com/Consensys/starknet-snap/compare/get-starknet-v1.0.0...get-starknet-v1.1.0) (2024-07-16)


### Features

* clean up and update dependency ([#259](https://github.com/Consensys/starknet-snap/issues/259)) ([fcb83e1](https://github.com/Consensys/starknet-snap/commit/fcb83e128fd4e483cdf9f4670e4e70e1d3876f7a))

## 1.0.0 (2024-06-21)


Expand Down
2 changes: 1 addition & 1 deletion packages/get-starknet/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@consensys/get-starknet",
"version": "1.1.0",
"version": "1.0.0",
"license": "(Apache-2.0 OR MIT)",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
14 changes: 0 additions & 14 deletions packages/starknet-snap/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
# Changelog


## [2.9.0](https://github.com/Consensys/starknet-snap/compare/starknet-snap-v2.8.0...starknet-snap-v2.9.0) (2024-07-16)


### Features

* clean up and update dependency ([#259](https://github.com/Consensys/starknet-snap/issues/259)) ([fcb83e1](https://github.com/Consensys/starknet-snap/commit/fcb83e128fd4e483cdf9f4670e4e70e1d3876f7a))


### Bug Fixes

* non zero balance on non deployed cairo 0 account ([#276](https://github.com/Consensys/starknet-snap/issues/276)) ([d9beafe](https://github.com/Consensys/starknet-snap/commit/d9beafe45b304685581162ef9247a31919eb7556))
* remove get balance from createAccount ([#272](https://github.com/Consensys/starknet-snap/issues/272)) ([02b92f9](https://github.com/Consensys/starknet-snap/commit/02b92f988476dd621e2c48c4b3f1733e55a5878c))
* validateAccountRequireUpgradeOrDeploy condition check ([#288](https://github.com/Consensys/starknet-snap/issues/288)) ([0f49ab0](https://github.com/Consensys/starknet-snap/commit/0f49ab09b57735158a74eed715cc6665c372ee6d))

## [2.8.0](https://github.com/Consensys/starknet-snap/compare/starknet-snap-v2.7.0...starknet-snap-v2.8.0) (2024-06-21)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"openrpc": "1.0.0-rc1",
"info": {
"version": "2.9.0",
"version": "2.8.0",
"title": "Starknet MetaMask Snap API",
"license": {}
},
Expand Down
27 changes: 20 additions & 7 deletions packages/starknet-snap/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "@consensys/starknet-snap",
"version": "2.9.0",
"keywords": [],
"version": "2.8.0",
"repository": {
"type": "git",
"url": "https://github.com/ConsenSys/starknet-snap.git"
Expand All @@ -27,8 +26,8 @@
"serve": "mm-snap serve",
"start": "mm-snap watch",
"test": "yarn run test:unit && yarn run cover:report",
"test:unit": "nyc --check-coverage --statements 70 --branches 70 --functions 70 --lines 70 mocha --colors -r ts-node/register \"test/**/*.test.ts\"",
"test:unit:one": "nyc --check-coverage --statements 70 --branches 70 --functions 70 --lines 70 mocha --colors -r ts-node/register"
"test:unit": "nyc --check-coverage --statements 80 --branches 80 --functions 80 --lines 80 mocha --colors -r ts-node/register \"test/**/*.test.ts\"",
"test:unit:one": "nyc --check-coverage --statements 80 --branches 80 --functions 80 --lines 80 mocha --colors -r ts-node/register"
},
"nyc": {
"exclude": [
Expand All @@ -46,25 +45,39 @@
"starknet_v4.22.0": "npm:[email protected]"
},
"devDependencies": {
"@metamask/eslint-config": "^12.2.0",
"@metamask/eslint-config-jest": "^12.1.0",
"@metamask/eslint-config-nodejs": "^12.1.0",
"@metamask/eslint-config-typescript": "^12.1.0",
"@metamask/snaps-cli": "^6.1.0",
"@metamask/snaps-jest": "^8.0.0",
"@types/chai": "^4.3.1",
"@types/chai-as-promised": "^7.1.5",
"@types/sinon": "^10.0.11",
"@types/sinon-chai": "^3.2.8",
"@typescript-eslint/eslint-plugin": "^5.20.0",
"@typescript-eslint/parser": "^5.20.0",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"bip174": "^2.1.1",
"chai": "^4.3.6",
"chai-as-promised": "^7.1.1",
"cross-env": "^7.0.3",
"dotenv": "^16.4.5",
"eslint": "^8.13.0",
"eslint": "^8.45.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "~2.26.0",
"eslint-plugin-jest": "^27.1.5",
"eslint-plugin-jsdoc": "^41.1.2",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.1.1",
"mocha": "^9.2.2",
"nyc": "^15.1.0",
"prettier": "^2.7.1",
"prettier-plugin-packagejson": "^2.2.11",
"rimraf": "^3.0.2",
"sinon": "^13.0.2",
"sinon-chai": "^3.7.0",
"ts-node": "^10.9.2",
"typescript": "^4.7.4"
},
"packageManager": "[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion packages/starknet-snap/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.9.0",
"version": "2.8.0",
"description": "Manage Starknet accounts and assets with MetaMask.",
"proposedName": "Starknet",
"repository": {
Expand Down
109 changes: 42 additions & 67 deletions packages/starknet-snap/src/createAccount.ts
Original file line number Diff line number Diff line change
@@ -1,110 +1,85 @@
import type { BIP44AddressKeyDeriver } from '@metamask/key-tree';
import { heading, panel, text, DialogType } from '@metamask/snaps-sdk';

import type { ApiParams, CreateAccountRequestParams } from './types/snapApi';
import type { AccContract, Transaction } from './types/snapState';
import { VoyagerTransactionType, TransactionStatus } from './types/snapState';
import { logger } from './utils/logger';
import { toJson } from './utils/serializer';
import {
getKeysFromAddressIndex,
getAccContractAddressAndCallData,
deployAccount,
waitForTransaction,
getAccContractAddressAndCallDataLegacy,
estimateAccountDeployFee,
} from './utils/starknetUtils';
import {
getNetworkFromChainId,
getValidNumber,
upsertAccount,
upsertTransaction,
getSendTxnText,
addDialogTxt,
} from './utils/snapUtils';
import { AccContract, VoyagerTransactionType, Transaction, TransactionStatus } from './types/snapState';
import { ApiParams, CreateAccountRequestParams } from './types/snapApi';
import { heading, panel, DialogType } from '@metamask/snaps-sdk';
import { logger } from './utils/logger';
import { CAIRO_VERSION, CAIRO_VERSION_LEGACY } from './utils/constants';
import { CairoVersion, EstimateFee, num } from 'starknet';
import {
getKeysFromAddressIndex,
getAccContractAddressAndCallData,
deployAccount,
waitForTransaction,
} from './utils/starknetUtils';

/**
* Create an starknet account.
*
* @template Params - The ApiParams of the request.
* @param params
* @param silentMode - The flag to disable the confirmation dialog from snap.
* @param waitMode - The flag to enable an determination by doing an recursive fetch to check if the deploy account status is on L2 or not. The wait mode is only useful when it compose with other txn together, it can make sure the deploy txn execute complete, avoiding the latter txn failed.
*/
export async function createAccount(
params: ApiParams,
silentMode = false,
waitMode = false,
cairoVersion: CairoVersion = CAIRO_VERSION,
) {
export async function createAccount(params: ApiParams, silentMode = false, waitMode = false) {
try {
const { state, wallet, saveMutex, keyDeriver, requestParams } = params;
const requestParamsObj = requestParams as CreateAccountRequestParams;

const addressIndex = getValidNumber(requestParamsObj.addressIndex, -1, 0);
const network = getNetworkFromChainId(state, requestParamsObj.chainId);
const deploy = !!requestParamsObj.deploy;
const deploy = Boolean(requestParamsObj.deploy);

const {
privateKey,
publicKey,
addressIndex: addressIndexInUsed,
derivationPath,
} = await getKeysFromAddressIndex(keyDeriver, network.chainId, state, addressIndex);

const { address: contractAddress, callData: contractCallData } =
cairoVersion == CAIRO_VERSION_LEGACY
? getAccContractAddressAndCallDataLegacy(publicKey)
: getAccContractAddressAndCallData(publicKey);
} = await getKeysFromAddressIndex(
keyDeriver as unknown as BIP44AddressKeyDeriver,
network.chainId,
state,
addressIndex,
);
const { address: contractAddress, callData: contractCallData } = getAccContractAddressAndCallData(publicKey);
logger.log(
`createAccount:\ncontractAddress = ${contractAddress}\npublicKey = ${publicKey}\naddressIndex = ${addressIndexInUsed}`,
);

if (deploy) {
if (!silentMode) {
logger.log(
`estimateAccountDeployFee:\ncontractAddress = ${contractAddress}\npublicKey = ${publicKey}\naddressIndex = ${addressIndexInUsed}`,
);

const estimateDeployFee: EstimateFee = await estimateAccountDeployFee(
network,
contractAddress,
contractCallData,
publicKey,
privateKey,
cairoVersion,
);
logger.log(`estimateAccountDeployFee:\nestimateDeployFee: ${toJson(estimateDeployFee)}`);
const maxFee = num.toBigInt(estimateDeployFee.suggestedMaxFee.toString(10) ?? '0');
const dialogComponents = getSendTxnText(
state,
contractAddress,
'deploy',
contractCallData,
contractAddress,
maxFee,
network,
);
const components = [];
addDialogTxt(components, 'Address', contractAddress);
addDialogTxt(components, 'Public Key', publicKey);
addDialogTxt(components, 'Address Index', addressIndex.toString());

const response = await wallet.request({
method: 'snap_dialog',
params: {
type: DialogType.Confirmation,
content: panel([heading('Do you want to sign this deploy transaction ?'), ...dialogComponents]),
content: panel([
heading('Do you want to sign this deploy account transaction ?'),
text(`It will be signed with address: ${contractAddress}`),
...components,
]),
},
});

if (!response)
if (!response) {
return {
address: contractAddress,
};
}
}

// Deploy account will auto estimate the fee from the network if not provided
const deployResp = await deployAccount(
network,
contractAddress,
contractCallData,
publicKey,
privateKey,
cairoVersion,
);
const deployResp = await deployAccount(network, contractAddress, contractCallData, publicKey, privateKey);

if (deployResp.contract_address && deployResp.transaction_hash) {
const userAccount: AccContract = {
Expand All @@ -115,8 +90,6 @@ export async function createAccount(
derivationPath,
deployTxnHash: deployResp.transaction_hash,
chainId: network.chainId,
upgradeRequired: cairoVersion === CAIRO_VERSION_LEGACY,
deployRequired: false,
};

await upsertAccount(userAccount, wallet, saveMutex);
Expand Down Expand Up @@ -148,14 +121,16 @@ export async function createAccount(

return {
address: deployResp.contract_address,
// eslint-disable-next-line @typescript-eslint/naming-convention
transaction_hash: deployResp.transaction_hash,
};
}
return {
address: contractAddress,
};
} catch (err) {
logger.error(`Problem found: ${err}`);
throw err;
} catch (error) {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
logger.error(`Problem found: ${error}`);
throw error;
}
}
Loading

0 comments on commit e906af3

Please sign in to comment.