Skip to content

Commit

Permalink
feat: sepolia network (#187)
Browse files Browse the repository at this point in the history
* feat: addsepolia network

---------

Co-authored-by: stanleyyuen <[email protected]>
  • Loading branch information
wantedsystem and stanleyyconsensys authored Dec 19, 2023
1 parent 4b4ace7 commit 45b0463
Show file tree
Hide file tree
Showing 21 changed files with 199 additions and 39 deletions.
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": "CmWnKZgn0YwhCONy9eAp6caU/4MFPO74bXReg/IlBPw=",
"shasum": "P8VzY62ID99iFOTN0jz8AgMI+F+ILOQ65BfiqW8xt6w=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 2 additions & 0 deletions packages/starknet-snap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
71 changes: 68 additions & 3 deletions packages/starknet-snap/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,32 @@ 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',
voyagerUrl: 'https://goerli.voyager.online',
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,
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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
20 changes: 19 additions & 1 deletion packages/starknet-snap/test/constants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions packages/starknet-snap/test/src/addErc20Token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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 = {
Expand Down
14 changes: 9 additions & 5 deletions packages/starknet-snap/test/src/addNetwork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 = {
Expand Down Expand Up @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand Down
8 changes: 6 additions & 2 deletions packages/starknet-snap/test/src/createAccount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {
Expand Down
8 changes: 6 additions & 2 deletions packages/starknet-snap/test/src/declareContract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 = {
Expand Down
8 changes: 6 additions & 2 deletions packages/starknet-snap/test/src/executeTxn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 = {
Expand Down
8 changes: 6 additions & 2 deletions packages/starknet-snap/test/src/getCurrentNetwork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
};
Expand Down
4 changes: 2 additions & 2 deletions packages/starknet-snap/test/src/getStoredNetworks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 = {
Expand Down
8 changes: 6 additions & 2 deletions packages/starknet-snap/test/src/getStoredTransactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 = {
Expand Down
8 changes: 6 additions & 2 deletions packages/starknet-snap/test/src/recoverAccounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = {
Expand Down
Loading

0 comments on commit 45b0463

Please sign in to comment.