From 45b04633149bf1b9568feeb8c2f475d52a0e45a8 Mon Sep 17 00:00:00 2001 From: Amine Harty Date: Tue, 19 Dec 2023 10:32:54 +0100 Subject: [PATCH] feat: sepolia network (#187) * feat: addsepolia network --------- Co-authored-by: stanleyyuen <102275989+stanleyyconsensys@users.noreply.github.com> --- packages/starknet-snap/snap.manifest.json | 2 +- packages/starknet-snap/src/index.ts | 2 + packages/starknet-snap/src/utils/constants.ts | 71 ++++++++++++++++++- packages/starknet-snap/test/constants.test.ts | 20 +++++- .../test/src/addErc20Token.test.ts | 8 ++- .../starknet-snap/test/src/addNetwork.test.ts | 14 ++-- .../test/src/createAccount.test.ts | 8 ++- .../test/src/declareContract.test.ts | 8 ++- .../starknet-snap/test/src/executeTxn.test.ts | 8 ++- .../test/src/getCurrentNetwork.test.ts | 8 ++- .../test/src/getStoredNetworks.test.ts | 4 +- .../test/src/getStoredTransactions.test.ts | 8 ++- .../test/src/recoverAccounts.test.ts | 8 ++- .../test/src/sendTransaction.test.ts | 2 +- .../test/src/signDeclareTransaction.test.ts | 8 ++- .../src/signDeployAccountTransaction.test.ts | 8 ++- .../test/src/signTransaction.test.ts | 8 ++- .../test/src/switchNetwork.test.ts | 12 ++-- packages/wallet-ui/src/utils/constants.ts | 22 ++++++ packages/wallet-ui/src/utils/utils.ts | 5 ++ yarn.lock | 4 +- 21 files changed, 199 insertions(+), 39 deletions(-) diff --git a/packages/starknet-snap/snap.manifest.json b/packages/starknet-snap/snap.manifest.json index 3efc3054..0b779ea9 100644 --- a/packages/starknet-snap/snap.manifest.json +++ b/packages/starknet-snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/ConsenSys/starknet-snap.git" }, "source": { - "shasum": "CmWnKZgn0YwhCONy9eAp6caU/4MFPO74bXReg/IlBPw=", + "shasum": "P8VzY62ID99iFOTN0jz8AgMI+F+ILOQ65BfiqW8xt6w=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/starknet-snap/src/index.ts b/packages/starknet-snap/src/index.ts index f2fd8910..7311d52a 100644 --- a/packages/starknet-snap/src/index.ts +++ b/packages/starknet-snap/src/index.ts @@ -23,6 +23,7 @@ import { STARKNET_INTEGRATION_NETWORK, STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK, + STARKNET_SEPOLIA_TESTNET_NETWORK, } from './utils/constants'; import { upsertErc20Token, upsertNetwork } from './utils/snapUtils'; import { getStoredNetworks } from './getStoredNetworks'; @@ -87,6 +88,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ origin, request }) => await upsertNetwork(STARKNET_INTEGRATION_NETWORK, snap, saveMutex, state); } else { await upsertNetwork(STARKNET_TESTNET_NETWORK, snap, saveMutex, state); + await upsertNetwork(STARKNET_SEPOLIA_TESTNET_NETWORK, snap, saveMutex, state); } for (const token of PRELOADED_TOKENS) { await upsertErc20Token(token, snap, saveMutex, state); diff --git a/packages/starknet-snap/src/utils/constants.ts b/packages/starknet-snap/src/utils/constants.ts index 86f1f464..47874901 100644 --- a/packages/starknet-snap/src/utils/constants.ts +++ b/packages/starknet-snap/src/utils/constants.ts @@ -25,7 +25,7 @@ export const STARKNET_MAINNET_NETWORK: Network = { }; export const STARKNET_TESTNET_NETWORK: Network = { - name: 'Goerli Testnet', + name: 'Goerli Testnet (deprecated soon)', chainId: constants.StarknetChainId.SN_GOERLI, baseUrl: 'https://alpha4.starknet.io', nodeUrl: 'https://starknet-goerli.infura.io/v3/60c7253fb48147658095fe0460ac9ee9', @@ -33,6 +33,24 @@ export const STARKNET_TESTNET_NETWORK: Network = { accountClassHash: '', // from argent-x repo }; +// TODO: Importing directly from constants when upgrading to starknet.js v6 +const SN_SEPOLIA = { + name: 'Sepolia Testnet', + baseUrl: 'https://alpha-sepolia.starknet.io', + chainId: '0x534e5f5345504f4c4941', + nodeUrl: 'https://starknet-sepolia.infura.io/v3/60c7253fb48147658095fe0460ac9ee9', + voyagerUrl: 'https://sepolia.voyager.online', +}; + +export const STARKNET_SEPOLIA_TESTNET_NETWORK: Network = { + name: SN_SEPOLIA.name, + chainId: SN_SEPOLIA.chainId, + baseUrl: SN_SEPOLIA.baseUrl, + nodeUrl: SN_SEPOLIA.nodeUrl, + voyagerUrl: SN_SEPOLIA.voyagerUrl, + accountClassHash: '', // from argent-x repo +}; + export const STARKNET_INTEGRATION_NETWORK: Network = { name: 'Goerli Integration', chainId: constants.StarknetChainId.SN_GOERLI, @@ -58,6 +76,14 @@ export const ETHER_TESTNET: Erc20Token = { chainId: STARKNET_TESTNET_NETWORK.chainId, }; +export const ETHER_SEPOLIA_TESTNET: Erc20Token = { + address: '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7', + name: 'Ether', + symbol: 'ETH', + decimals: 18, + chainId: SN_SEPOLIA.chainId, +}; + export const DAI_MAINNET: Erc20Token = { address: '0x00da114221cb83fa859dbdb4c44beeaa0bb37c7537ad5ae66fe5e0efd20e6eb3', name: 'DAI', @@ -74,6 +100,14 @@ export const DAI_TESTNET: Erc20Token = { chainId: STARKNET_TESTNET_NETWORK.chainId, }; +export const DAI_SEPOLIA_TESTNET: Erc20Token = { + address: '0x03e85bfbb8e2a42b7bead9e88e9a1b19dbccf661471061807292120462396ec9', + name: 'DAI', + symbol: 'DAI', + decimals: 18, + chainId: SN_SEPOLIA.chainId, +}; + export const WBTC_TESTNET: Erc20Token = { address: '0x12d537dc323c439dc65c976fad242d5610d27cfb5f31689a0a319b8be7f3d56', name: 'Wrapped BTC', @@ -98,6 +132,14 @@ export const USDC_TESTNET: Erc20Token = { chainId: STARKNET_TESTNET_NETWORK.chainId, }; +export const USDC_SEPOLIA_TESTNET: Erc20Token = { + address: '0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8', + name: 'USD Coin', + symbol: 'USDC', + decimals: 6, + chainId: SN_SEPOLIA.chainId, +}; + export const USDT_MAINNET: Erc20Token = { address: '0x068f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8', name: 'Tether USD', @@ -114,6 +156,14 @@ export const USDT_TESTNET: Erc20Token = { chainId: STARKNET_TESTNET_NETWORK.chainId, }; +export const USDT_SEPOLIA_TESTNET: Erc20Token = { + address: '0x068f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8', + name: 'Tether USD', + symbol: 'USDT', + decimals: 6, + chainId: SN_SEPOLIA.chainId, +}; + export const TEST_TOKEN_MAINNET: Erc20Token = { address: '0x06a09ccb1caaecf3d9683efe335a667b2169a409d19c589ba1eb771cd210af75', name: 'Test Token', @@ -130,7 +180,22 @@ export const TEST_TOKEN_TESTNET: Erc20Token = { chainId: STARKNET_TESTNET_NETWORK.chainId, }; -export const PRELOADED_TOKENS = [ETHER_MAINNET, ETHER_TESTNET, USDC_MAINNET, USDC_TESTNET, USDT_MAINNET, USDT_TESTNET]; -export const PRELOADED_NETWORKS = [STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK, STARKNET_INTEGRATION_NETWORK]; +export const PRELOADED_TOKENS = [ + ETHER_MAINNET, + ETHER_TESTNET, + ETHER_SEPOLIA_TESTNET, + USDC_MAINNET, + USDC_TESTNET, + USDC_SEPOLIA_TESTNET, + USDT_MAINNET, + USDT_TESTNET, + USDT_SEPOLIA_TESTNET, +]; +export const PRELOADED_NETWORKS = [ + STARKNET_MAINNET_NETWORK, + STARKNET_TESTNET_NETWORK, + STARKNET_SEPOLIA_TESTNET_NETWORK, + STARKNET_INTEGRATION_NETWORK, +]; export const PROXY_CONTRACT_HASH = '0x25ec026985a3bf9d0cc1fe17326b245dfdc3ff89b8fde106542a3ea56c5a918'; // from argent-x repo diff --git a/packages/starknet-snap/test/constants.test.ts b/packages/starknet-snap/test/constants.test.ts index ef8df609..1b8b430b 100644 --- a/packages/starknet-snap/test/constants.test.ts +++ b/packages/starknet-snap/test/constants.test.ts @@ -9,7 +9,11 @@ import { ExecutionStatus, FinailityStatus, } from '../src/types/snapState'; -import { STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK } from '../src/utils/constants'; +import { + STARKNET_MAINNET_NETWORK, + STARKNET_TESTNET_NETWORK, + STARKNET_SEPOLIA_TESTNET_NETWORK, +} from '../src/utils/constants'; export const invalidNetwork: Network = { name: 'Network with emot', @@ -179,6 +183,20 @@ export const createAccountProxyTxn: Transaction = { eventIds: [], }; +export const createAccountProxyTxnOnSepolia: Transaction = { + chainId: STARKNET_SEPOLIA_TESTNET_NETWORK.chainId, + contractAddress: createAccountProxyResp.contract_address, + contractCallData: [], + contractFuncName: '', + senderAddress: createAccountProxyResp.contract_address, + timestamp: 1653559059, + txnHash: createAccountProxyResp.transaction_hash, + txnType: VoyagerTransactionType.DEPLOY, + failureReason: '', + status: '', + eventIds: [], +}; + export const initAccountTxn: Transaction = { chainId: STARKNET_TESTNET_NETWORK.chainId, contractAddress: account1.address, diff --git a/packages/starknet-snap/test/src/addErc20Token.test.ts b/packages/starknet-snap/test/src/addErc20Token.test.ts index d8973e56..a8319fe6 100644 --- a/packages/starknet-snap/test/src/addErc20Token.test.ts +++ b/packages/starknet-snap/test/src/addErc20Token.test.ts @@ -5,7 +5,11 @@ import { WalletMock } from '../wallet.mock.test'; import { addErc20Token } from '../../src/addErc20Token'; import { SnapState } from '../../src/types/snapState'; import * as snapUtils from '../../src/utils/snapUtils'; -import { DEFAULT_DECIMAL_PLACES, STARKNET_TESTNET_NETWORK } from '../../src/utils/constants'; +import { + DEFAULT_DECIMAL_PLACES, + STARKNET_TESTNET_NETWORK, + STARKNET_SEPOLIA_TESTNET_NETWORK, +} from '../../src/utils/constants'; import { Mutex } from 'async-mutex'; import { AddErc20TokenRequestParams, ApiParams } from '../../src/types/snapApi'; @@ -17,7 +21,7 @@ describe('Test function: addErc20Token', function () { const state: SnapState = { accContracts: [], erc20Tokens: [], - networks: [STARKNET_TESTNET_NETWORK], + networks: [STARKNET_TESTNET_NETWORK, STARKNET_SEPOLIA_TESTNET_NETWORK], transactions: [], }; const apiParams: ApiParams = { diff --git a/packages/starknet-snap/test/src/addNetwork.test.ts b/packages/starknet-snap/test/src/addNetwork.test.ts index 64e83b53..47bea7db 100644 --- a/packages/starknet-snap/test/src/addNetwork.test.ts +++ b/packages/starknet-snap/test/src/addNetwork.test.ts @@ -4,7 +4,11 @@ import sinonChai from 'sinon-chai'; import { WalletMock } from '../wallet.mock.test'; import { SnapState } from '../../src/types/snapState'; import * as snapUtils from '../../src/utils/snapUtils'; -import { STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK } from '../../src/utils/constants'; +import { + STARKNET_MAINNET_NETWORK, + STARKNET_TESTNET_NETWORK, + STARKNET_SEPOLIA_TESTNET_NETWORK, +} from '../../src/utils/constants'; import { addNetwork } from '../../src/addNetwork'; import { Mutex } from 'async-mutex'; import { AddNetworkRequestParams, ApiParams } from '../../src/types/snapApi'; @@ -17,7 +21,7 @@ describe('Test function: addNetwork', function () { const state: SnapState = { accContracts: [], erc20Tokens: [], - networks: [STARKNET_TESTNET_NETWORK, STARKNET_MAINNET_NETWORK], + networks: [STARKNET_TESTNET_NETWORK, STARKNET_MAINNET_NETWORK, STARKNET_SEPOLIA_TESTNET_NETWORK], transactions: [], }; const apiParams: ApiParams = { @@ -51,7 +55,7 @@ describe('Test function: addNetwork', function () { const result = await addNetwork(apiParams); expect(result).to.be.eql(true); expect(stateStub).to.be.calledOnce; - expect(state.networks.length).to.be.eql(3); + expect(state.networks.length).to.be.eql(4); }); it('should update the network correctly', async function () { @@ -65,7 +69,7 @@ describe('Test function: addNetwork', function () { const result = await addNetwork(apiParams); expect(result).to.be.eql(true); expect(stateStub).to.be.calledOnce; - expect(state.networks.length).to.be.eql(3); + expect(state.networks.length).to.be.eql(4); }); it('should not update snap state with the duplicated network', async function () { @@ -79,7 +83,7 @@ describe('Test function: addNetwork', function () { const result = await addNetwork(apiParams); expect(result).to.be.eql(true); expect(stateStub).to.be.callCount(0); - expect(state.networks.length).to.be.eql(3); + expect(state.networks.length).to.be.eql(4); }); it('should throw an error if upsertNetwork failed', async function () { diff --git a/packages/starknet-snap/test/src/createAccount.test.ts b/packages/starknet-snap/test/src/createAccount.test.ts index 811a02c0..d47648f7 100644 --- a/packages/starknet-snap/test/src/createAccount.test.ts +++ b/packages/starknet-snap/test/src/createAccount.test.ts @@ -6,7 +6,11 @@ import * as utils from '../../src/utils/starknetUtils'; import * as snapUtils from '../../src/utils/snapUtils'; import { createAccount } from '../../src/createAccount'; import { SnapState } from '../../src/types/snapState'; -import { STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK } from '../../src/utils/constants'; +import { + STARKNET_MAINNET_NETWORK, + STARKNET_TESTNET_NETWORK, + STARKNET_SEPOLIA_TESTNET_NETWORK, +} from '../../src/utils/constants'; import { createAccountProxyTxn, createAccountProxyResp, @@ -34,7 +38,7 @@ describe('Test function: createAccount', function () { const state: SnapState = { accContracts: [], erc20Tokens: [], - networks: [STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK], + networks: [STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK, STARKNET_SEPOLIA_TESTNET_NETWORK], transactions: [], }; const apiParams: ApiParams = { diff --git a/packages/starknet-snap/test/src/declareContract.test.ts b/packages/starknet-snap/test/src/declareContract.test.ts index da733ec2..30eaf7d9 100644 --- a/packages/starknet-snap/test/src/declareContract.test.ts +++ b/packages/starknet-snap/test/src/declareContract.test.ts @@ -5,7 +5,11 @@ import { WalletMock } from '../wallet.mock.test'; import * as utils from '../../src/utils/starknetUtils'; import { declareContract } from '../../src/declareContract'; import { SnapState } from '../../src/types/snapState'; -import { STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK } from '../../src/utils/constants'; +import { + STARKNET_MAINNET_NETWORK, + STARKNET_TESTNET_NETWORK, + STARKNET_SEPOLIA_TESTNET_NETWORK, +} from '../../src/utils/constants'; import { createAccountProxyTxn, getBip44EntropyStub, account1 } from '../constants.test'; import { getAddressKeyDeriver } from '../../src/utils/keyPair'; import { Mutex } from 'async-mutex'; @@ -20,7 +24,7 @@ describe('Test function: declareContract', function () { const state: SnapState = { accContracts: [], erc20Tokens: [], - networks: [STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK], + networks: [STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK, STARKNET_SEPOLIA_TESTNET_NETWORK], transactions: [], }; const apiParams: ApiParams = { diff --git a/packages/starknet-snap/test/src/executeTxn.test.ts b/packages/starknet-snap/test/src/executeTxn.test.ts index 036fd045..a8da31fd 100644 --- a/packages/starknet-snap/test/src/executeTxn.test.ts +++ b/packages/starknet-snap/test/src/executeTxn.test.ts @@ -5,7 +5,11 @@ import { WalletMock } from '../wallet.mock.test'; import * as utils from '../../src/utils/starknetUtils'; import { executeTxn } from '../../src/executeTxn'; import { SnapState } from '../../src/types/snapState'; -import { STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK } from '../../src/utils/constants'; +import { + STARKNET_MAINNET_NETWORK, + STARKNET_TESTNET_NETWORK, + STARKNET_SEPOLIA_TESTNET_NETWORK, +} from '../../src/utils/constants'; import { createAccountProxyTxn, getBip44EntropyStub, account1 } from '../constants.test'; import { getAddressKeyDeriver } from '../../src/utils/keyPair'; import { Mutex } from 'async-mutex'; @@ -20,7 +24,7 @@ describe('Test function: executeTxn', function () { const state: SnapState = { accContracts: [], erc20Tokens: [], - networks: [STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK], + networks: [STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK, STARKNET_SEPOLIA_TESTNET_NETWORK], transactions: [], }; const apiParams: ApiParams = { diff --git a/packages/starknet-snap/test/src/getCurrentNetwork.test.ts b/packages/starknet-snap/test/src/getCurrentNetwork.test.ts index 1b706305..97b74b64 100644 --- a/packages/starknet-snap/test/src/getCurrentNetwork.test.ts +++ b/packages/starknet-snap/test/src/getCurrentNetwork.test.ts @@ -3,7 +3,11 @@ import sinon from 'sinon'; import sinonChai from 'sinon-chai'; import { WalletMock } from '../wallet.mock.test'; import { SnapState } from '../../src/types/snapState'; -import { STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK } from '../../src/utils/constants'; +import { + STARKNET_MAINNET_NETWORK, + STARKNET_TESTNET_NETWORK, + STARKNET_SEPOLIA_TESTNET_NETWORK, +} from '../../src/utils/constants'; import { getCurrentNetwork } from '../../src/getCurrentNetwork'; import { Mutex } from 'async-mutex'; import { ApiParams } from '../../src/types/snapApi'; @@ -16,7 +20,7 @@ describe('Test function: getStoredNetworks', function () { const state: SnapState = { accContracts: [], erc20Tokens: [], - networks: [STARKNET_TESTNET_NETWORK, STARKNET_MAINNET_NETWORK], + networks: [STARKNET_TESTNET_NETWORK, STARKNET_MAINNET_NETWORK, STARKNET_SEPOLIA_TESTNET_NETWORK], transactions: [], currentNetwork: STARKNET_MAINNET_NETWORK, }; diff --git a/packages/starknet-snap/test/src/getStoredNetworks.test.ts b/packages/starknet-snap/test/src/getStoredNetworks.test.ts index 40b9ebf5..a8d6e326 100644 --- a/packages/starknet-snap/test/src/getStoredNetworks.test.ts +++ b/packages/starknet-snap/test/src/getStoredNetworks.test.ts @@ -3,7 +3,7 @@ import sinon from 'sinon'; import sinonChai from 'sinon-chai'; import { WalletMock } from '../wallet.mock.test'; import { SnapState } from '../../src/types/snapState'; -import { STARKNET_TESTNET_NETWORK } from '../../src/utils/constants'; +import { STARKNET_TESTNET_NETWORK, STARKNET_SEPOLIA_TESTNET_NETWORK } from '../../src/utils/constants'; import { getStoredNetworks } from '../../src/getStoredNetworks'; import * as snapUtils from '../../src/utils/snapUtils'; import { Mutex } from 'async-mutex'; @@ -17,7 +17,7 @@ describe('Test function: getStoredNetworks', function () { const state: SnapState = { accContracts: [], erc20Tokens: [], - networks: [STARKNET_TESTNET_NETWORK, STARKNET_TESTNET_NETWORK], + networks: [STARKNET_TESTNET_NETWORK, STARKNET_SEPOLIA_TESTNET_NETWORK], transactions: [], }; const apiParams: ApiParams = { diff --git a/packages/starknet-snap/test/src/getStoredTransactions.test.ts b/packages/starknet-snap/test/src/getStoredTransactions.test.ts index 9806bd6d..353f215b 100644 --- a/packages/starknet-snap/test/src/getStoredTransactions.test.ts +++ b/packages/starknet-snap/test/src/getStoredTransactions.test.ts @@ -3,7 +3,11 @@ import sinon from 'sinon'; import sinonChai from 'sinon-chai'; import { WalletMock } from '../wallet.mock.test'; import { SnapState, VoyagerTransactionType } from '../../src/types/snapState'; -import { STARKNET_TESTNET_NETWORK, STARKNET_MAINNET_NETWORK } from '../../src/utils/constants'; +import { + STARKNET_TESTNET_NETWORK, + STARKNET_MAINNET_NETWORK, + STARKNET_SEPOLIA_TESTNET_NETWORK, +} from '../../src/utils/constants'; import { getStoredTransactions } from '../../src/getStoredTransactions'; import { createAccountProxyTxn, initAccountTxn, invalidNetwork, txn1, txn2, txn3 } from '../constants.test'; import * as snapUtils from '../../src/utils/snapUtils'; @@ -18,7 +22,7 @@ describe('Test function: getStoredTransactions', function () { const state: SnapState = { accContracts: [], erc20Tokens: [], - networks: [STARKNET_TESTNET_NETWORK, STARKNET_MAINNET_NETWORK, invalidNetwork], + networks: [STARKNET_TESTNET_NETWORK, STARKNET_MAINNET_NETWORK, STARKNET_SEPOLIA_TESTNET_NETWORK, invalidNetwork], transactions: [txn1, txn2, txn3, createAccountProxyTxn, initAccountTxn], }; const apiParams: ApiParams = { diff --git a/packages/starknet-snap/test/src/recoverAccounts.test.ts b/packages/starknet-snap/test/src/recoverAccounts.test.ts index 4e63b7c2..9150d9f8 100644 --- a/packages/starknet-snap/test/src/recoverAccounts.test.ts +++ b/packages/starknet-snap/test/src/recoverAccounts.test.ts @@ -5,7 +5,11 @@ import { WalletMock } from '../wallet.mock.test'; import * as utils from '../../src/utils/starknetUtils'; import * as snapUtils from '../../src/utils/snapUtils'; import { SnapState } from '../../src/types/snapState'; -import { STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK } from '../../src/utils/constants'; +import { + STARKNET_MAINNET_NETWORK, + STARKNET_TESTNET_NETWORK, + STARKNET_SEPOLIA_TESTNET_NETWORK, +} from '../../src/utils/constants'; import { createAccountProxyTxn, testnetAccAddresses, @@ -30,7 +34,7 @@ describe('Test function: recoverAccounts', function () { const state: SnapState = { accContracts: [], erc20Tokens: [], - networks: [STARKNET_TESTNET_NETWORK, STARKNET_MAINNET_NETWORK, INVALID_NETWORK], + networks: [STARKNET_TESTNET_NETWORK, STARKNET_MAINNET_NETWORK, STARKNET_SEPOLIA_TESTNET_NETWORK, INVALID_NETWORK], transactions: [], }; const apiParams: ApiParams = { diff --git a/packages/starknet-snap/test/src/sendTransaction.test.ts b/packages/starknet-snap/test/src/sendTransaction.test.ts index f118dbfb..9cf547d4 100644 --- a/packages/starknet-snap/test/src/sendTransaction.test.ts +++ b/packages/starknet-snap/test/src/sendTransaction.test.ts @@ -255,7 +255,7 @@ describe('Test function: sendTransaction', function () { }, { type: 'copyable', - value: 'Goerli Testnet', + value: 'Goerli Testnet (deprecated soon)', }, ], }, diff --git a/packages/starknet-snap/test/src/signDeclareTransaction.test.ts b/packages/starknet-snap/test/src/signDeclareTransaction.test.ts index 3f518376..8dc2986b 100644 --- a/packages/starknet-snap/test/src/signDeclareTransaction.test.ts +++ b/packages/starknet-snap/test/src/signDeclareTransaction.test.ts @@ -4,7 +4,11 @@ import sinonChai from 'sinon-chai'; import { WalletMock } from '../wallet.mock.test'; import { signDeclareTransaction } from '../../src/signDeclareTransaction'; import { SnapState } from '../../src/types/snapState'; -import { STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK } from '../../src/utils/constants'; +import { + STARKNET_MAINNET_NETWORK, + STARKNET_TESTNET_NETWORK, + STARKNET_SEPOLIA_TESTNET_NETWORK, +} from '../../src/utils/constants'; import { createAccountProxyTxn, getBip44EntropyStub, account1, signature3 } from '../constants.test'; import { getAddressKeyDeriver } from '../../src/utils/keyPair'; import { Mutex } from 'async-mutex'; @@ -21,7 +25,7 @@ describe('Test function: signDeclareTransaction', function () { const state: SnapState = { accContracts: [], erc20Tokens: [], - networks: [STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK], + networks: [STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK, STARKNET_SEPOLIA_TESTNET_NETWORK], transactions: [], }; const apiParams: ApiParams = { diff --git a/packages/starknet-snap/test/src/signDeployAccountTransaction.test.ts b/packages/starknet-snap/test/src/signDeployAccountTransaction.test.ts index db2edb6d..ee9fc7fa 100644 --- a/packages/starknet-snap/test/src/signDeployAccountTransaction.test.ts +++ b/packages/starknet-snap/test/src/signDeployAccountTransaction.test.ts @@ -4,7 +4,11 @@ import sinonChai from 'sinon-chai'; import { WalletMock } from '../wallet.mock.test'; import { signDeployAccountTransaction } from '../../src/signDeployAccountTransaction'; import { SnapState } from '../../src/types/snapState'; -import { STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK } from '../../src/utils/constants'; +import { + STARKNET_MAINNET_NETWORK, + STARKNET_TESTNET_NETWORK, + STARKNET_SEPOLIA_TESTNET_NETWORK, +} from '../../src/utils/constants'; import { createAccountProxyTxn, getBip44EntropyStub, account1, signature3 } from '../constants.test'; import { getAddressKeyDeriver } from '../../src/utils/keyPair'; import { Mutex } from 'async-mutex'; @@ -21,7 +25,7 @@ describe('Test function: signDeployAccountTransaction', function () { const state: SnapState = { accContracts: [], erc20Tokens: [], - networks: [STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK], + networks: [STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK, STARKNET_SEPOLIA_TESTNET_NETWORK], transactions: [], }; const apiParams: ApiParams = { diff --git a/packages/starknet-snap/test/src/signTransaction.test.ts b/packages/starknet-snap/test/src/signTransaction.test.ts index b1e0be29..088fe21a 100644 --- a/packages/starknet-snap/test/src/signTransaction.test.ts +++ b/packages/starknet-snap/test/src/signTransaction.test.ts @@ -4,7 +4,11 @@ import sinonChai from 'sinon-chai'; import { WalletMock } from '../wallet.mock.test'; import { signTransaction } from '../../src/signTransaction'; import { SnapState } from '../../src/types/snapState'; -import { STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK } from '../../src/utils/constants'; +import { + STARKNET_MAINNET_NETWORK, + STARKNET_TESTNET_NETWORK, + STARKNET_SEPOLIA_TESTNET_NETWORK, +} from '../../src/utils/constants'; import { createAccountProxyTxn, getBip44EntropyStub, account1, signature3 } from '../constants.test'; import { getAddressKeyDeriver } from '../../src/utils/keyPair'; import { Mutex } from 'async-mutex'; @@ -21,7 +25,7 @@ describe('Test function: signMessage', function () { const state: SnapState = { accContracts: [], erc20Tokens: [], - networks: [STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK], + networks: [STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK, STARKNET_SEPOLIA_TESTNET_NETWORK], transactions: [], }; const apiParams: ApiParams = { diff --git a/packages/starknet-snap/test/src/switchNetwork.test.ts b/packages/starknet-snap/test/src/switchNetwork.test.ts index f09b093e..57ced9a8 100644 --- a/packages/starknet-snap/test/src/switchNetwork.test.ts +++ b/packages/starknet-snap/test/src/switchNetwork.test.ts @@ -4,7 +4,11 @@ import sinonChai from 'sinon-chai'; import { WalletMock } from '../wallet.mock.test'; import { SnapState } from '../../src/types/snapState'; import * as snapUtils from '../../src/utils/snapUtils'; -import { STARKNET_MAINNET_NETWORK, STARKNET_TESTNET_NETWORK } from '../../src/utils/constants'; +import { + STARKNET_MAINNET_NETWORK, + STARKNET_TESTNET_NETWORK, + STARKNET_SEPOLIA_TESTNET_NETWORK, +} from '../../src/utils/constants'; import { Mutex } from 'async-mutex'; import { SwitchNetworkRequestParams, ApiParams } from '../../src/types/snapApi'; import { switchNetwork } from '../../src/switchNetwork'; @@ -17,7 +21,7 @@ describe('Test function: switchNetwork', function () { const state: SnapState = { accContracts: [], erc20Tokens: [], - networks: [STARKNET_TESTNET_NETWORK, STARKNET_MAINNET_NETWORK], + networks: [STARKNET_TESTNET_NETWORK, STARKNET_MAINNET_NETWORK, STARKNET_SEPOLIA_TESTNET_NETWORK], transactions: [], currentNetwork: STARKNET_TESTNET_NETWORK, }; @@ -52,7 +56,7 @@ describe('Test function: switchNetwork', function () { expect(stateStub).to.be.calledOnce; expect(dialogStub).to.be.calledOnce; expect(state.currentNetwork).to.be.eql(STARKNET_MAINNET_NETWORK); - expect(state.networks.length).to.be.eql(2); + expect(state.networks.length).to.be.eql(3); }); it('should skip autherize when enableAutherize is false or omit', async function () { @@ -65,7 +69,7 @@ describe('Test function: switchNetwork', function () { expect(stateStub).to.be.calledOnce; expect(dialogStub).to.be.callCount(0); expect(state.currentNetwork).to.be.eql(STARKNET_MAINNET_NETWORK); - expect(state.networks.length).to.be.eql(2); + expect(state.networks.length).to.be.eql(3); }); it('should throw an error if network not found', async function () { diff --git a/packages/wallet-ui/src/utils/constants.ts b/packages/wallet-ui/src/utils/constants.ts index d301b8df..b6f81131 100644 --- a/packages/wallet-ui/src/utils/constants.ts +++ b/packages/wallet-ui/src/utils/constants.ts @@ -1,5 +1,8 @@ import { constants } from 'starknet'; +// TODO: Importing directly from constants when upgrading to starknet.js v6 +export const SEPOLIA_CHAINID = '0x534e5f5345504f4c4941'; + export const TOKENS: any = { [constants.StarknetChainId.MAINNET]: { '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7': { @@ -23,6 +26,23 @@ export const TOKENS: any = { coingeckoId: 'usd-coin', }, }, + [SEPOLIA_CHAINID]: { + '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7': { + coingeckoId: 'ethereum', + }, + '0x12d537dc323c439dc65c976fad242d5610d27cfb5f31689a0a319b8be7f3d56': { + coingeckoId: 'wrapped-bitcoin', + }, + '0x386e8d061177f19b3b485c20e31137e6f6bc497cc635ccdfcab96fadf5add6a': { + coingeckoId: 'tether', + }, + '0x03e85bfbb8e2a42b7bead9e88e9a1b19dbccf661471061807292120462396ec9': { + coingeckoId: 'dai', + }, + '0x005a643907b9a4bc6a55e9069c4fd5fd1f5c79a22470690f75556c4736e34426': { + coingeckoId: 'usd-coin', + }, + }, }; export const DECIMALS_DISPLAYED_MAX_LENGTH = 11; @@ -33,6 +53,8 @@ export const STARKNET_MAINNET_EXPLORER = 'https://voyager.online/'; export const STARKNET_TESTNET_EXPLORER = 'https://goerli.voyager.online/'; +export const STARKNET_SEPOLIA_TESTNET_EXPLORER = 'https://sepolia.voyager.online/'; + export const SNAPS_DOC_URL = 'https://docs.metamask.io/guide/snaps.html'; export const STARKNET_ADDRESS_LENGTH = 66; diff --git a/packages/wallet-ui/src/utils/utils.ts b/packages/wallet-ui/src/utils/utils.ts index 70bfe423..3d1b5e1c 100644 --- a/packages/wallet-ui/src/utils/utils.ts +++ b/packages/wallet-ui/src/utils/utils.ts @@ -4,6 +4,8 @@ import { DECIMALS_DISPLAYED_MAX_LENGTH, STARKNET_MAINNET_EXPLORER, STARKNET_TESTNET_EXPLORER, + STARKNET_SEPOLIA_TESTNET_EXPLORER, + SEPOLIA_CHAINID, TIMEOUT_DURATION, } from './constants'; import { Erc20Token, Erc20TokenBalance } from 'types'; @@ -27,6 +29,9 @@ export const openExplorerTab = ( case constants.StarknetChainId.TESTNET: explorerUrl = STARKNET_TESTNET_EXPLORER; break; + case SEPOLIA_CHAINID: + explorerUrl = STARKNET_SEPOLIA_TESTNET_EXPLORER; + break; } window.open(explorerUrl + type + '/' + address, '_blank')?.focus(); }; diff --git a/yarn.lock b/yarn.lock index bd5d9af1..54decb5d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2034,14 +2034,14 @@ __metadata: "@consensys/starknet-snap@file:../starknet-snap::locator=wallet-ui%40workspace%3Apackages%2Fwallet-ui": version: 2.2.0 - resolution: "@consensys/starknet-snap@file:../starknet-snap#../starknet-snap::hash=09b51d&locator=wallet-ui%40workspace%3Apackages%2Fwallet-ui" + resolution: "@consensys/starknet-snap@file:../starknet-snap#../starknet-snap::hash=ab7d53&locator=wallet-ui%40workspace%3Apackages%2Fwallet-ui" dependencies: async-mutex: ^0.3.2 ethereum-unit-converter: ^0.0.17 ethers: ^5.5.1 starknet: ^5.14.0 starknet_v4.22.0: "npm:starknet@4.22.0" - checksum: fee364b7c342fedbbeda32f0d35fc90a826ad42d2948e329f5893ab03e25536b57dd15a342428bda8e628a4416f01dc0102d63450056f0a4799e700279d34fec + checksum: 2503bcfc3279ca6e000859442f9f20ff583c65abdc33b6128a4a89e1e63413ffdf82e73c510b63ee1d26c7c7a40ffeeb25cc53f4a3cb4f36890951f0e61314cb languageName: node linkType: hard