Skip to content

Commit

Permalink
solution: use Sepolia testnet in development (#1380)
Browse files Browse the repository at this point in the history
  • Loading branch information
splix committed Apr 25, 2024
1 parent 9ad5c06 commit eb4c5fd
Show file tree
Hide file tree
Showing 34 changed files with 133 additions and 113 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
"packages/*"
],
"resolutions": {
"@emeraldpay/api": "https://artifacts.emerald.cash/builds/emerald-api-js/a4a88f2e/emeraldpay-api-v0.4.4-dev.tgz",
"@emeraldpay/api-node": "https://artifacts.emerald.cash/builds/emerald-api-js/a4a88f2e/emeraldpay-api-node-v0.4.4-dev.tgz"
"@emeraldpay/api": "https://artifacts.emerald.cash/builds/emerald-api-js/a35b8b1c/emeraldpay-api-v0.5.0-dev.tgz",
"@emeraldpay/api-node": "https://artifacts.emerald.cash/builds/emerald-api-js/a35b8b1c/emeraldpay-api-node-v0.5.0-dev.tgz",
"@emeraldpay/emerald-vault-core": "https://artifacts.emerald.cash/builds/vault-node/1ffb2ac8/emeraldpay-emerald-vault-core-v0.13.0-dev.tgz",
"@emeraldpay/emerald-vault-native": "https://artifacts.emerald.cash/builds/vault-node/1ffb2ac8/emeraldpay-emerald-vault-native-v0.13.0-dev.tgz"
}
}
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"dependencies": {
"@emeraldpay/bigamount": "^0.4.2",
"@emeraldpay/bigamount-crypto": "^0.4.2",
"@emeraldpay/emerald-vault-core": "^0.12.0",
"@emeraldpay/emerald-vault-core": "^0.13.0-dev",
"@ethereumjs/common": "^3.1.2",
"@ethereumjs/tx": "^4.1.2",
"@ethersproject/abi": "^5.7.0",
Expand Down
48 changes: 26 additions & 22 deletions packages/core/src/blockchains/blockchains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export enum BlockchainCode {
ETC = 'etc',
ETH = 'eth',
// Testnet
Goerli = 'goerli',
Sepolia = 'sepolia',
TestBTC = 'testbtc',
// Other
Unknown = 'unknown',
Expand Down Expand Up @@ -44,17 +44,17 @@ export const Blockchains: Record<BlockchainCode | string, IBlockchain> = {
),
'Ethereum Classic',
),
[BlockchainCode.Goerli]: new Ethereum(
[BlockchainCode.Sepolia]: new Ethereum(
new EthereumParams(
BlockchainCode.Goerli,
BlockchainCode.Sepolia,
Coin.ETHER,
CoinTicker.ETG,
5,
CoinTicker.SEPOLIA,
11155111,
HDPath.default().forCoin(BlockchainCode.ETH).forAccount(160720),
100,
true,
),
'Goerli Testnet',
'Sepolia Testnet',
),
[BlockchainCode.BTC]: new Bitcoin({
chainId: 0,
Expand All @@ -80,7 +80,7 @@ const allCodes = [
BlockchainCode.BTC,
BlockchainCode.ETC,
BlockchainCode.ETH,
BlockchainCode.Goerli,
BlockchainCode.Sepolia,
BlockchainCode.TestBTC,
];

Expand Down Expand Up @@ -109,6 +109,10 @@ export function ethereumByChainId(id?: number): IBlockchain | undefined {
return allChains.find((chain) => chain.params.chainId === id);
}

export function isBlockchainId(id: number): boolean {
return id == 1 || id == 100 || id == 101 || id == 10003 || id == 10009;
}

export function blockchainIdToCode(id: number): BlockchainCode {
switch (id) {
case 1:
Expand All @@ -119,8 +123,8 @@ export function blockchainIdToCode(id: number): BlockchainCode {
return BlockchainCode.ETC;
case 10003:
return BlockchainCode.TestBTC;
case 10005:
return BlockchainCode.Goerli;
case 10009:
return BlockchainCode.Sepolia;
default:
throw new Error(`Unsupported blockchain id: ${id}`);
}
Expand All @@ -140,29 +144,29 @@ export function blockchainCodeToId(code: BlockchainCode): number {
return 101;
case BlockchainCode.TestBTC:
return 10003;
case BlockchainCode.Goerli:
return 10005;
case BlockchainCode.Sepolia:
return 10009;
default:
throw new Error(`Unsupported blockchain: ${code}`);
}
}

export function isEthereum(code: BlockchainCode): boolean {
return code === BlockchainCode.ETH || code === BlockchainCode.ETC || code === BlockchainCode.Goerli;
return code === BlockchainCode.ETH || code === BlockchainCode.ETC || code === BlockchainCode.Sepolia;
}

export function isBitcoin(code: BlockchainCode): boolean {
return code == BlockchainCode.BTC || code == BlockchainCode.TestBTC;
}

export const WEIS_GOERLI = new Units([
new Unit(0, 'Goerli Wei', 'WeiG'),
new Unit(3, 'Goerli Kwei', 'KWeiG'),
new Unit(6, 'Goerli Mwei', 'MWeiG'),
new Unit(9, 'Goerli Gwei', 'GWeiG'),
new Unit(12, 'Goerli Microether', 'μETG'),
new Unit(15, 'Goerli Milliether', 'mETG'),
new Unit(18, 'Goerli Ether', 'ETG'),
export const WEIS_SEPOLIA = new Units([
new Unit(0, 'Sepolia Wei', 'WeiS'),
new Unit(3, 'Sepolia Kwei', 'KWeiS'),
new Unit(6, 'Sepolia Mwei', 'MWeiS'),
new Unit(9, 'Sepolia Gwei', 'GWeiS'),
new Unit(12, 'Sepolia Microether', 'μETS'),
new Unit(15, 'Sepolia Milliether', 'mETS'),
new Unit(18, 'Sepolia Ether', 'ETS'),
]);

export const SATOSHIS_TEST = new Units([
Expand All @@ -181,8 +185,8 @@ export function amountFactory(code: BlockchainCode): CreateAmount<BigAmount> {
return WeiEtc.factory();
case BlockchainCode.ETH:
return Wei.factory();
case BlockchainCode.Goerli:
return (value) => new WeiAny(value, WEIS_GOERLI);
case BlockchainCode.Sepolia:
return (value) => new WeiAny(value, WEIS_SEPOLIA);
case BlockchainCode.TestBTC:
return (value) => new SatoshiAny(value, SATOSHIS_TEST);
default:
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/blockchains/coinTicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export enum CoinTicker {
ETC = 'ETC',
ETH = 'ETH',
// Testnet
ETG = 'ETG',
SEPOLIA = 'SEPOLIA',
TESTBTC = 'TESTBTC',
}

export type CoinTickerCode = 'BTC' | 'ETC' | 'ETH' | 'ETG' | 'TESTBTC';
export type CoinTickerCode = 'BTC' | 'ETC' | 'ETH' | 'TESTBTC' | 'SEPOLIA';
1 change: 1 addition & 0 deletions packages/core/src/blockchains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export {
ethereumByChainId,
isBitcoin,
isEthereum,
isBlockchainId,
ledgerByBlockchain,
} from './blockchains';
export { Coin, CoinCode } from './coin';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/blockchains/tokens/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const TOKEN_TYPES = ['ERC20', 'ERC721', 'ERC1155'] as const;
const WRAPPED_TOKENS: Readonly<Partial<Record<BlockchainCode, string>>> = {
[BlockchainCode.ETH]: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
[BlockchainCode.ETC]: '0x1953cab0E5bFa6D4a9BaD6E05fD46C1CC6527a5a',
[BlockchainCode.Goerli]: '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6',
[BlockchainCode.Sepolia]: '0xc31e8a1087bf1460b9926274de4a03b0dd44a6da',
};

export interface TokenData {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export {
ethereumByChainId,
isBitcoin,
isEthereum,
isBlockchainId,
isStructuredMessage,
isToken,
isWrappedToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import { ApproveTarget, CreateErc20ApproveTx } from './CreateErc20ApproveTx';
describe('CreateErc20ApproveTx', () => {
const wethTokenData: TokenData = {
name: 'Wrapped Ether',
blockchain: 10005,
address: '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6',
symbol: 'WETG',
blockchain: 10009,
address: '0xc31e8a1087bf1460b9926274de4a03b0dd44a6da',
symbol: 'WSEPOLIA',
decimals: 18,
type: 'ERC20',
};
const weenusTokenData: TokenData = {
name: 'Weenus',
blockchain: 10005,
blockchain: 10009,
address: '0xaFF4481D10270F50f203E0763e2597776068CBc5',
symbol: 'WEENUS',
decimals: 18,
Expand All @@ -25,15 +25,15 @@ describe('CreateErc20ApproveTx', () => {

const tokenRegistry = new TokenRegistry([wethTokenData, weenusTokenData]);

const wethToken = tokenRegistry.byAddress(BlockchainCode.Goerli, '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6');
const weenusToken = tokenRegistry.byAddress(BlockchainCode.Goerli, '0xaFF4481D10270F50f203E0763e2597776068CBc5');
const wethToken = tokenRegistry.byAddress(BlockchainCode.Sepolia, '0xc31e8a1087bf1460b9926274de4a03b0dd44a6da');
const weenusToken = tokenRegistry.byAddress(BlockchainCode.Sepolia, '0xaFF4481D10270F50f203E0763e2597776068CBc5');

test('should create legacy approve tx', () => {
const tx = new CreateErc20ApproveTx(
{
amount: wethToken.getAmount(0),
asset: wethToken.address,
blockchain: BlockchainCode.Goerli,
blockchain: BlockchainCode.Sepolia,
meta: { type: TxMetaType.ERC20_APPROVE },
target: ApproveTarget.MANUAL,
type: EthereumTransactionType.LEGACY,
Expand All @@ -52,7 +52,7 @@ describe('CreateErc20ApproveTx', () => {
{
amount: wethToken.getAmount(0),
asset: wethToken.address,
blockchain: BlockchainCode.Goerli,
blockchain: BlockchainCode.Sepolia,
meta: { type: TxMetaType.ERC20_APPROVE },
target: ApproveTarget.MANUAL,
type: EthereumTransactionType.EIP1559,
Expand All @@ -74,7 +74,7 @@ describe('CreateErc20ApproveTx', () => {
{
amount: wethToken.getAmount(0),
asset: wethToken.address,
blockchain: BlockchainCode.Goerli,
blockchain: BlockchainCode.Sepolia,
meta: { type: TxMetaType.ERC20_APPROVE },
target: ApproveTarget.MAX_AVAILABLE,
totalTokenBalance: amount,
Expand All @@ -89,7 +89,7 @@ describe('CreateErc20ApproveTx', () => {
{
amount: wethToken.getAmount(0),
asset: wethToken.address,
blockchain: BlockchainCode.Goerli,
blockchain: BlockchainCode.Sepolia,
meta: { type: TxMetaType.ERC20_APPROVE },
target: ApproveTarget.INFINITE,
type: EthereumTransactionType.EIP1559,
Expand All @@ -107,7 +107,7 @@ describe('CreateErc20ApproveTx', () => {
{
amount: wethToken.getAmount(0),
asset: wethToken.address,
blockchain: BlockchainCode.Goerli,
blockchain: BlockchainCode.Sepolia,
meta: { type: TxMetaType.ERC20_APPROVE },
target: ApproveTarget.MANUAL,
totalTokenBalance: amount,
Expand Down Expand Up @@ -136,7 +136,7 @@ describe('CreateErc20ApproveTx', () => {
{
amount,
asset: wethToken.address,
blockchain: BlockchainCode.Goerli,
blockchain: BlockchainCode.Sepolia,
meta: { type: TxMetaType.ERC20_APPROVE },
target: ApproveTarget.MANUAL,
totalTokenBalance: amount,
Expand All @@ -159,7 +159,7 @@ describe('CreateErc20ApproveTx', () => {
{
amount: wethToken.getAmount(0),
asset: wethToken.address,
blockchain: BlockchainCode.Goerli,
blockchain: BlockchainCode.Sepolia,
meta: { type: TxMetaType.ERC20_APPROVE },
target: ApproveTarget.MANUAL,
type: EthereumTransactionType.EIP1559,
Expand All @@ -185,7 +185,7 @@ describe('CreateErc20ApproveTx', () => {
approveBy: '0xe62c6f33a58d7f49e6b782aab931450e53d01f12',
allowFor: '0x3f54eb67fea225d0a21263f1a7cb456e342cb1e8',
asset: wethToken.address,
blockchain: BlockchainCode.Goerli,
blockchain: BlockchainCode.Sepolia,
meta: { type: TxMetaType.ERC20_APPROVE },
target: ApproveTarget.MANUAL,
type: EthereumTransactionType.EIP1559,
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/src/main/utils/api-modes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ApiMode } from '@emeraldwallet/electron-app';

export const DevelopmentMode: ApiMode = {
id: 'development',
chains: ['ETH', 'ETC', 'BTC', 'GOERLI', 'TESTBTC'],
chains: ['ETH', 'ETC', 'BTC', 'SEPOLIA', 'TESTBTC'],
};

export const ProductionMode: ApiMode = {
Expand Down
3 changes: 2 additions & 1 deletion packages/desktop/src/main/utils/update-tokens.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Logger, TokenData } from '@emeraldwallet/core';
import fetch from 'node-fetch';
import { tokens as defaults } from '../../../defaults.json';
import {isBlockchainId} from "@emeraldwallet/core";

type Updated = { changed: boolean; tokens: TokenData[] };

Expand All @@ -16,7 +17,7 @@ export default async function (appVersion: string, stored: TokenData[]): Promise

if (response.status === 200) {
try {
const tokens = (await response.json()) as TokenData[];
const tokens = ((await response.json()) as TokenData[]).filter((token) => isBlockchainId(token.blockchain));

const addresses = stored.map(({ address }) => address.toLowerCase());

Expand Down
3 changes: 2 additions & 1 deletion packages/desktop/src/renderer/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import updateOptions from '../../main/utils/update-options';
import updateTokens from '../../main/utils/update-tokens';
import { initAllowancesState } from './cache/allowances';
import { initBalancesState } from './cache/balances';
import {isBlockchainId} from "@emeraldwallet/core";

Logger.setInstance(ElectronLogger);

Expand Down Expand Up @@ -185,7 +186,7 @@ export function startStore(): void {
const { options = {}, tokens = [] } = store.getState().application;

checkOptionsUpdates(versions.appVersion, options);
checkTokensUpdates(versions.appVersion, tokens);
checkTokensUpdates(versions.appVersion, tokens.filter((token) => isBlockchainId(token.blockchain)));
});

checkWalletUpdates(versions.appVersion);
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"compile": "tsc -b"
},
"dependencies": {
"@emeraldpay/emerald-vault-core": "^0.12.0",
"@emeraldpay/emerald-vault-native": "^0.12.0",
"@emeraldpay/emerald-vault-core": "^0.13.0-dev",
"@emeraldpay/emerald-vault-native": "^0.13.0-dev",
"@emeraldwallet/core": "2.11.0-dev",
"@emeraldwallet/persistent-state": "2.11.0-dev",
"@emeraldwallet/services": "2.11.0-dev",
Expand Down
5 changes: 3 additions & 2 deletions packages/electron-app/src/application/Settings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SettingsManager, SettingsOptions, SettingsStore, TokenData } from '@emeraldwallet/core';
import {blockchainIdToCode, SettingsManager, SettingsOptions, SettingsStore, TokenData} from '@emeraldwallet/core';
import ElectronStore from 'electron-store';
import { v4 as uuid } from 'uuid';
import {isBlockchainId} from "@emeraldwallet/core";

const DEFAULTS: SettingsStore = {
id: uuid(),
Expand Down Expand Up @@ -33,7 +34,7 @@ export class Settings implements SettingsManager {
}

getTokens(): TokenData[] {
return this.settings.get('tokens');
return this.settings.get('tokens').filter((token: TokenData) => isBlockchainId(token.blockchain));
}

setLastCursor(timestamp: number): Settings {
Expand Down
2 changes: 1 addition & 1 deletion packages/persistent-state/native/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/persistent-state/native/src/commons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub fn blockchain_from_code<S: AsRef<str>>(code: S) -> Result<u32, StateManagerE
"etc" => Ok(101),
"testbtc" => Ok(10003),
"goerli" => Ok(10005),
"sepolia" => Ok(10009),
_ => Err(StateManagerError::InvalidValue("Invalid blockchain code".to_string()))
}
}
Expand All @@ -36,6 +37,7 @@ pub fn blockchain_to_code(id: u32) -> Result<String, StateManagerError> {
101 => Ok("etc".to_string()),
10003 => Ok("testbtc".to_string()),
10005 => Ok("goerli".to_string()),
10009 => Ok("sepolia".to_string()),
_ => Err(StateManagerError::InvalidValue("Invalid blockchain id".to_string()))
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/persistent-state/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"test:coverage": "jest --coverage"
},
"dependencies": {
"@emeraldpay/emerald-vault-core": "^0.12.0",
"@emeraldpay/emerald-vault-core": "^0.13.0-dev",
"@emeraldpay/neon-frame": "^0.1.1",
"@emeraldwallet/core": "2.11.0-dev"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/persistent-state/src/__tests__/txhistory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ describe('Tx History', () => {
height: 4910978,
timestamp: new Date('2021-06-04T14:14:23.000Z'),
},
blockchain: 10005,
blockchain: 10009,
changes: [
{
asset: 'ETH',
Expand Down
2 changes: 1 addition & 1 deletion packages/react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@electron/remote": "^2.0.9",
"@emeraldpay/bigamount": "^0.4.2",
"@emeraldpay/bigamount-crypto": "^0.4.2",
"@emeraldpay/emerald-vault-core": "^0.12.0",
"@emeraldpay/emerald-vault-core": "^0.13.0-dev",
"@emeraldwallet/core": "2.11.0-dev",
"@emeraldwallet/store": "2.11.0-dev",
"@emeraldwallet/ui": "2.11.0-dev",
Expand Down

0 comments on commit eb4c5fd

Please sign in to comment.