Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade to sarknet.js v6.11.0 #296

Merged
merged 21 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
"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"
"prepare": "husky install",
"start-debug-ui": "http-server packages/starknet-snap"
},
"devDependencies": {
"@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.3",
"@lavamoat/allow-scripts": "^3.0.0",
"@lavamoat/preinstall-always-fail": "^2.0.0",
"husky": "^8.0.0"
"husky": "^8.0.0",
"http-server": "^14.1.1"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
132 changes: 121 additions & 11 deletions packages/starknet-snap/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,123 @@
<meta charset="utf-8" />
<title>Hello, Snaps!</title>
<link rel="icon" type="image/svg" href="./images/icon.svg" />
<style>
/* Basic Reset */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Arial', sans-serif;
}

body {
background-color: #f4f4f4;
color: #333;
padding: 20px;
}

h1 {
text-align: center;
color: #4caf50;
margin-bottom: 20px;
}

details {
background-color: #fff;
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 20px;
border-radius: 4px;
}

details summary {
font-weight: bold;
cursor: pointer;
}

ul,
ul ul {
list-style: disc;
margin-left: 20px;
}

ul ul {
list-style: circle;
}

code {
background-color: #f4f4f4;
padding: 2px 4px;
border-radius: 3px;
}

button {
background-color: #4caf50;
color: white;
border: none;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 5px 2px;
cursor: pointer;
border-radius: 5px;
transition: background-color 0.3s ease;
}

button:hover {
background-color: #45a049;
}

input[type='text'],
input[type='checkbox'],
select {
padding: 10px;
margin: 5px 0 15px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}

input[type='submit'] {
background-color: #4caf50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.3s ease;
}

input[type='submit']:hover {
background-color: #45a049;
}

form {
background-color: #fff;
padding: 20px;
margin-bottom: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

form fieldset {
border: none;
}

form legend {
font-size: 1.2em;
margin-bottom: 10px;
}

label {
font-weight: bold;
display: block;
margin-bottom: 5px;
}
</style>
</head>

<body>
Expand All @@ -30,10 +147,8 @@ <h1>Hello, Snaps!</h1>
<button class="connect">Connect</button>
<button class="sendPing">Send Ping</button>
<br />
<label for="targetChainId">Target Chain Id in Hex (optional, default Goerli testnet)</label>
<label for="targetChainId">Target Chain Id in Hex (optional, default Sepolia testnet)</label>
<input type="text" id="targetChainId" name="targetChainId" /><br />
<label for="isDev">Use Starknet Integration network for Goerli testnet</label>
<input type="checkbox" id="isDev" name="isDev" /><br />
<label for="debugLevel">Log Level</label>
<select id="debugLevel">
<option value="ALL" selected="selected">All</option>
Expand Down Expand Up @@ -367,7 +482,6 @@ <h1>Hello, Snaps!</h1>
<input type="submit" id="upgrade" value="Upgrade" />
</fieldset>
</form>

</body>

<script type="module">
Expand Down Expand Up @@ -501,7 +615,6 @@ <h1>Hello, Snaps!</h1>

function getReqFlagsFromCheckbox() {
return {
isDev: document.getElementById('isDev').checked,
debugLevel: document.getElementById('debugLevel').value,
};
}
Expand Down Expand Up @@ -772,7 +885,7 @@ <h1>Hello, Snaps!</h1>
e.preventDefault(); // to prevent default form behavior

const networkChainId = document.getElementById('switchNetwork_ChainId').value;

await callSnap('starkNet_switchNetwork', {
chainId: networkChainId,
});
Expand Down Expand Up @@ -895,15 +1008,15 @@ <h1>Hello, Snaps!</h1>
const contractAddress = document.getElementById('upgrade_contractAddress').value;

await callSnap('starkNet_upgradeAccContract', {
contractAddress
contractAddress,
});
}

async function callSnap(method, params) {
try {
const chainId = document.getElementById('targetChainId').value;
//0x534e5f474f45524c42
console.log(params)
console.log(params);
const response = await ethereum.request({
method: 'wallet_invokeSnap',
params: {
Expand All @@ -924,8 +1037,5 @@ <h1>Hello, Snaps!</h1>
alert(`${method} problem happened: ${err.message || err}`);
}
}

</script>


</html>
4 changes: 2 additions & 2 deletions packages/starknet-snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"lint": "yarn lint:eslint && yarn lint:misc --check",
"lint:eslint": "eslint . --cache --ext js,ts",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"lint:misc": "prettier '**/*.ts' '**/*.json' '**/*.md' '!CHANGELOG.md' --ignore-path .gitignore",
"lint:misc": "prettier 'index.html' '**/*.ts' '**/*.json' '**/*.md' '!CHANGELOG.md' --ignore-path .gitignore",
"serve": "mm-snap serve",
"start": "mm-snap watch",
"test": "yarn run test:unit && yarn run cover:report",
Expand All @@ -42,7 +42,7 @@
"async-mutex": "^0.3.2",
"ethereum-unit-converter": "^0.0.17",
"ethers": "^5.5.1",
"starknet": "6.7.0",
"starknet": "6.11.0",
"starknet_v4.22.0": "npm:[email protected]"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/starknet-snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/ConsenSys/starknet-snap.git"
},
"source": {
"shasum": "RzIvMTaF+Zf6YlhAcsnXoCYzBpzluw4FPBvK0qhIyYY=",
"shasum": "W8ix37oJWF324EtWElcuOKfZXueGO88SuL5YdC+tsUo=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
8 changes: 1 addition & 7 deletions packages/starknet-snap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
ETHER_MAINNET,
ETHER_SEPOLIA_TESTNET,
PRELOADED_TOKENS,
STARKNET_INTEGRATION_NETWORK,
STARKNET_MAINNET_NETWORK,
STARKNET_SEPOLIA_TESTNET_NETWORK,
STARKNET_TESTNET_NETWORK,
Expand Down Expand Up @@ -56,7 +55,6 @@ const saveMutex = new Mutex();
export const onRpcRequest: OnRpcRequestHandler = async ({ origin, request }) => {
try {
const requestParams = request?.params as unknown as ApiRequestParams;
const isDev = !!requestParams?.isDev;
const debugLevel = requestParams?.debugLevel;

logger.init(debugLevel);
Expand Down Expand Up @@ -94,11 +92,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ origin, request }) =>

// pre-inserted the default networks and tokens
await upsertNetwork(STARKNET_MAINNET_NETWORK, snap, saveMutex, state);
if (isDev) {
await upsertNetwork(STARKNET_INTEGRATION_NETWORK, snap, saveMutex, state);
} else {
await upsertNetwork(STARKNET_SEPOLIA_TESTNET_NETWORK, snap, saveMutex, state);
}
await upsertNetwork(STARKNET_SEPOLIA_TESTNET_NETWORK, snap, saveMutex, state);

// remove the testnet network (migration)
await removeNetwork(STARKNET_TESTNET_NETWORK, snap, saveMutex, state);
Expand Down
1 change: 0 additions & 1 deletion packages/starknet-snap/src/types/snapApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export type ApiRequestParams =

export interface BaseRequestParams {
chainId?: string;
isDev?: boolean;
debugLevel?: string;
}

Expand Down
15 changes: 1 addition & 14 deletions packages/starknet-snap/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,6 @@ export const STARKNET_SEPOLIA_TESTNET_NETWORK: Network = {
accountClassHash: '', // from argent-x repo
};

export const STARKNET_INTEGRATION_NETWORK: Network = {
name: 'Goerli Integration',
chainId: constants.StarknetChainId.SN_GOERLI,
baseUrl: 'https://external.integration.starknet.io',
nodeUrl: '',
voyagerUrl: '',
accountClassHash: '',
};

export const ETHER_MAINNET: Erc20Token = {
address: '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7',
name: 'Ether',
Expand Down Expand Up @@ -174,11 +165,7 @@ export const PRELOADED_TOKENS = [
STRK_SEPOLIA_TESTNET,
];

export const PRELOADED_NETWORKS = [
STARKNET_MAINNET_NETWORK,
STARKNET_SEPOLIA_TESTNET_NETWORK,
STARKNET_INTEGRATION_NETWORK,
];
export const PRELOADED_NETWORKS = [STARKNET_MAINNET_NETWORK, STARKNET_SEPOLIA_TESTNET_NETWORK];

export const PROXY_CONTRACT_HASH = '0x25ec026985a3bf9d0cc1fe17326b245dfdc3ff89b8fde106542a3ea56c5a918'; // for cairo 0 proxy contract

Expand Down
2 changes: 1 addition & 1 deletion packages/starknet-snap/test/constants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const Cairo1Account1: AccContract = {
derivationPath: "m / bip32:44' / bip32:9004' / bip32:0' / bip32:0",
deployTxnHash: '0x5bc00132b8f2fc0f673dc232594b26727e712b204a2716f9dc28a8c5f607b5e',
publicKey: '0x019e59f349e1aa813ab4556c5836d0472e5e1ae82d1e5c3b3e8aabfeb290befd',
chainId: constants.StarknetChainId.SN_GOERLI,
chainId: constants.StarknetChainId.SN_SEPOLIA,
};

export const token0: Erc20Token = {
Expand Down
Loading