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: deprecate goerli network #217

Merged
merged 4 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 14 additions & 7 deletions packages/starknet-snap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ import {
PRELOADED_TOKENS,
STARKNET_INTEGRATION_NETWORK,
STARKNET_MAINNET_NETWORK,
STARKNET_TESTNET_NETWORK,
STARKNET_SEPOLIA_TESTNET_NETWORK,
STARKNET_TESTNET_NETWORK,
} from './utils/constants';
import { dappUrl, getNetworkFromChainId, isSameChainId, upsertErc20Token, upsertNetwork } from './utils/snapUtils';
import {
dappUrl,
getNetworkFromChainId,
isSameChainId,
upsertErc20Token,
upsertNetwork,
removeNetwork,
} from './utils/snapUtils';
import { getStoredNetworks } from './getStoredNetworks';
import { getStoredTransactions } from './getStoredTransactions';
import { getTransactions } from './getTransactions';
Expand Down Expand Up @@ -92,9 +99,12 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ origin, request }) =>
if (isDev) {
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);
}

// remove the testnet network (migration)
await removeNetwork(STARKNET_TESTNET_NETWORK, snap, saveMutex, state);

for (const token of PRELOADED_TOKENS) {
await upsertErc20Token(token, snap, saveMutex, state);
}
Expand Down Expand Up @@ -238,10 +248,7 @@ export const onInstall: OnInstallHandler = async () => {
export const onUpdate: OnUpdateHandler = async () => {
const component = panel([
text('Features released with this update:'),
text('**Home Page**: You can now see your account and balance on the Snap homepage.'),
text(
'To get to the Starknet Snap homepage, from the MetaMask menu, click **Snaps**, then click on the Starknet Snap.',
),
text('- Deprecation of the Starknet Goerli Testnet'),
]);

await snap.request({
Expand Down
74 changes: 7 additions & 67 deletions packages/starknet-snap/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ export const STARKNET_MAINNET_NETWORK: Network = {
accountClassHash: '', // from argent-x repo
};

// Keep this constants for unit test
export const STARKNET_TESTNET_NETWORK: Network = {
name: 'Goerli Testnet (deprecated soon)',
chainId: constants.StarknetChainId.SN_GOERLI,
baseUrl: 'https://alpha4.starknet.io',
nodeUrl: 'https://starknet-goerli.infura.io/v3/60c7253fb48147658095fe0460ac9ee9',
voyagerUrl: 'https://goerli.voyager.online',
accountClassHash: '', // from argent-x repo
name: 'Goerli Testnet (deprecated)',
chainId: '0x534e5f474f45524c49',
baseUrl: '',
nodeUrl: '',
voyagerUrl: '',
accountClassHash: '',
};

// TODO: Importing directly from constants when upgrading to starknet.js v6
Expand Down Expand Up @@ -80,14 +81,6 @@ export const ETHER_MAINNET: Erc20Token = {
chainId: STARKNET_MAINNET_NETWORK.chainId,
};

export const ETHER_TESTNET: Erc20Token = {
address: '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7',
name: 'Ether',
symbol: 'ETH',
decimals: 18,
chainId: STARKNET_TESTNET_NETWORK.chainId,
};

export const ETHER_SEPOLIA_TESTNET: Erc20Token = {
address: '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7',
name: 'Ether',
Expand All @@ -104,14 +97,6 @@ export const DAI_MAINNET: Erc20Token = {
chainId: STARKNET_MAINNET_NETWORK.chainId,
};

export const DAI_TESTNET: Erc20Token = {
address: '0x03e85bfbb8e2a42b7bead9e88e9a1b19dbccf661471061807292120462396ec9',
name: 'DAI',
symbol: 'DAI',
decimals: 18,
chainId: STARKNET_TESTNET_NETWORK.chainId,
};

export const DAI_SEPOLIA_TESTNET: Erc20Token = {
address: '0x03e85bfbb8e2a42b7bead9e88e9a1b19dbccf661471061807292120462396ec9',
name: 'DAI',
Expand All @@ -120,14 +105,6 @@ export const DAI_SEPOLIA_TESTNET: Erc20Token = {
chainId: SN_SEPOLIA.chainId,
};

export const WBTC_TESTNET: Erc20Token = {
address: '0x12d537dc323c439dc65c976fad242d5610d27cfb5f31689a0a319b8be7f3d56',
name: 'Wrapped BTC',
symbol: 'WBTC',
decimals: 8,
chainId: STARKNET_TESTNET_NETWORK.chainId,
};

export const STRK_MAINNET: Erc20Token = {
address: '0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d',
name: 'Starknet Token',
Expand All @@ -136,14 +113,6 @@ export const STRK_MAINNET: Erc20Token = {
chainId: STARKNET_MAINNET_NETWORK.chainId,
};

export const STRK_TESTNET: Erc20Token = {
address: '0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d',
name: 'Starknet Token',
symbol: 'STRK',
decimals: 18,
chainId: STARKNET_TESTNET_NETWORK.chainId,
};

export const STRK_SEPOLIA_TESTNET: Erc20Token = {
address: '0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d',
name: 'Starknet Token',
Expand All @@ -160,14 +129,6 @@ export const USDC_MAINNET: Erc20Token = {
chainId: STARKNET_MAINNET_NETWORK.chainId,
};

export const USDC_TESTNET: Erc20Token = {
address: '0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8',
name: 'USD Coin',
symbol: 'USDC',
decimals: 6,
chainId: STARKNET_TESTNET_NETWORK.chainId,
};

export const USDC_SEPOLIA_TESTNET: Erc20Token = {
address: '0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8',
name: 'USD Coin',
Expand All @@ -184,14 +145,6 @@ export const USDT_MAINNET: Erc20Token = {
chainId: STARKNET_MAINNET_NETWORK.chainId,
};

export const USDT_TESTNET: Erc20Token = {
address: '0x068f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8',
name: 'Tether USD',
symbol: 'USDT',
decimals: 6,
chainId: STARKNET_TESTNET_NETWORK.chainId,
};

export const USDT_SEPOLIA_TESTNET: Erc20Token = {
address: '0x068f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8',
name: 'Tether USD',
Expand All @@ -208,32 +161,19 @@ export const TEST_TOKEN_MAINNET: Erc20Token = {
chainId: STARKNET_MAINNET_NETWORK.chainId,
};

export const TEST_TOKEN_TESTNET: Erc20Token = {
address: '0x07394cbe418daa16e42b87ba67372d4ab4a5df0b05c6e554d158458ce245bc10',
name: 'Test Token',
symbol: 'TEST',
decimals: 18,
chainId: STARKNET_TESTNET_NETWORK.chainId,
};

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,
STRK_MAINNET,
STRK_TESTNET,
STRK_SEPOLIA_TESTNET,
];

export const PRELOADED_NETWORKS = [
STARKNET_MAINNET_NETWORK,
STARKNET_TESTNET_NETWORK,
STARKNET_SEPOLIA_TESTNET_NETWORK,
STARKNET_INTEGRATION_NETWORK,
];
Expand Down
35 changes: 32 additions & 3 deletions packages/starknet-snap/src/utils/snapUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
MAXIMUM_TOKEN_SYMBOL_LENGTH,
PRELOADED_NETWORKS,
PRELOADED_TOKENS,
STARKNET_TESTNET_NETWORK,
STARKNET_SEPOLIA_TESTNET_NETWORK,
VOYAGER_API_TXNS_URL_SUFFIX,
VOYAGER_API_TXN_URL_SUFFIX,
} from './constants';
Expand Down Expand Up @@ -430,6 +430,35 @@ export async function upsertNetwork(network: Network, wallet, mutex: Mutex, stat
});
}

export async function removeNetwork(network: Network, wallet, mutex: Mutex, state: SnapState = undefined) {
return mutex.runExclusive(async () => {
if (!state) {
state = await wallet.request({
method: 'snap_manageState',
params: {
operation: 'get',
},
});
}

if (state.currentNetwork && isSameChainId(state.currentNetwork.chainId, network.chainId)) {
state.currentNetwork = undefined; // fallback to default network
}

const storedNetwork = getNetwork(state, network.chainId);
if (storedNetwork) {
state.networks = state.networks.filter((net) => !isSameChainId(net.chainId, network.chainId));
await wallet.request({
method: 'snap_manageState',
params: {
operation: 'update',
newState: state,
},
});
}
});
}

export function getErc20Token(state: SnapState, tokenAddress: string, chainId: string) {
const bigIntTokenAddress = num.toBigInt(tokenAddress);
return state.erc20Tokens?.find(
Expand Down Expand Up @@ -485,7 +514,7 @@ export async function upsertErc20Token(erc20Token: Erc20Token, wallet, mutex: Mu
}

export function getNetworkFromChainId(state: SnapState, targerChainId: string | undefined) {
const chainId = targerChainId || STARKNET_TESTNET_NETWORK.chainId;
const chainId = targerChainId || STARKNET_SEPOLIA_TESTNET_NETWORK.chainId;
const network = getNetwork(state, chainId);
if (!network) {
throw new Error(`can't find the network in snap state with chainId: ${chainId}`);
Expand Down Expand Up @@ -649,7 +678,7 @@ export async function removeAcceptedTransaction(
}

export function getCurrentNetwork(state: SnapState) {
return state.currentNetwork || STARKNET_TESTNET_NETWORK;
return state.currentNetwork || STARKNET_SEPOLIA_TESTNET_NETWORK;
}

export async function setCurrentNetwork(network: Network, wallet, mutex: Mutex, state: SnapState = undefined) {
Expand Down
Loading
Loading