Skip to content

Commit

Permalink
Merge branch 'feat/sf-704' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
khanti42 committed Dec 9, 2024
2 parents dac9b45 + 68e1472 commit 11afba5
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
SNAP_ENV: ${{ needs.prepare-deployment.outputs.ENV }}
VERSION: ${{ needs.prepare-deployment.outputs.VERSION }}
VOYAGER_API_KEY: ${{ secrets.VOYAGER_API_KEY }}
ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }}
DIN_API_KEY: ${{ secrets.DIN_API_KEY }}
GET_STARKNET_PUBLIC_PATH: ${{ needs.prepare-deployment.outputs.GET_STARKNET_PUBLIC_PATH }}
LOG_LEVEL: ${{ needs.prepare-deployment.outputs.LOG_LEVEL }}
- name: Cache Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
VERSION: ${{ needs.prepare-deployment.outputs.VERSION }}
LOG_LEVEL: ${{ needs.prepare-deployment.outputs.LOG_LEVEL }}
VOYAGER_API_KEY: ${{ secrets.VOYAGER_API_KEY }}
ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }}
DIN_API_KEY: ${{ secrets.DIN_API_KEY }}
- name: Cache Build
uses: actions/cache@v3
id: cache
Expand Down
4 changes: 2 additions & 2 deletions packages/starknet-snap/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ VOYAGER_API_KEY=
# Description: Environment variables for API key of STARKSCAN
# Required: false
STARKSCAN_API_KEY=
# Description: Environment variables for API key of ALCHEMY
# Description: Environment variables for API key of INFURA DIN
# Required: false
ALCHEMY_API_KEY=
DIN_API_KEY=
# Description: Environment variables for Log Level, 0 does not log anything, 6 logs everything
# Possible Options: 0-6
# Default: 0
Expand Down
4 changes: 2 additions & 2 deletions packages/starknet-snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"serve": "mm-snap serve",
"start": "mm-snap watch",
"test": "yarn run test:unit && yarn run cover:report && yarn run jest",
"test:unit": "nyc --check-coverage --statements 50 --branches 50 --functions 50 --lines 50 mocha --colors -r ts-node/register --require test/global.ts \"test/**/*.test.ts\"",
"test:unit:one": "nyc --check-coverage --statements 50 --branches 50 --functions 50 --lines 50 mocha --colors -r ts-node/register --require test/global.ts"
"test:unit": "nyc --check-coverage --statements 40 --branches 40 --functions 40 --lines 40 mocha --colors -r ts-node/register --require test/global.ts \"test/**/*.test.ts\"",
"test:unit:one": "nyc --check-coverage --statements 40 --branches 40 --functions 40 --lines 40 mocha --colors -r ts-node/register --require test/global.ts"
},
"nyc": {
"exclude": [
Expand Down
2 changes: 1 addition & 1 deletion packages/starknet-snap/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const config: SnapConfig = {
/* eslint-disable */
SNAP_ENV: process.env.SNAP_ENV ?? 'prod',
VOYAGER_API_KEY: process.env.VOYAGER_API_KEY ?? '',
ALCHEMY_API_KEY: process.env.ALCHEMY_API_KEY ?? '',
DIN_API_KEY: process.env.DIN_API_KEY ?? '',
STARKSCAN_API_KEY: process.env.STARKSCAN_API_KEY ?? '',
LOG_LEVEL: process.env.LOG_LEVEL ?? '0',
/* eslint-disable */
Expand Down
12 changes: 12 additions & 0 deletions packages/starknet-snap/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export type SnapConfig = {
defaultNetwork: Network;
availableNetworks: Network[];
preloadTokens: Erc20Token[];
rpcEndpoint: {
[key: string]: string;
};
explorer: {
[key: string]: string;
};
Expand Down Expand Up @@ -49,6 +52,15 @@ export const Config: SnapConfig = {
STARKNET_SEPOLIA_TESTNET_NETWORK,
],

rpcEndpoint: {
[constants.StarknetChainId.SN_MAIN]:
// eslint-disable-next-line no-restricted-globals
`https://starknet-mainnet.infura.io/v3/${process.env.DIN_API_KEY ?? ''}`,
[constants.StarknetChainId.SN_SEPOLIA]:
// eslint-disable-next-line no-restricted-globals
`https://starknet-sepolia.infura.io/v3/${process.env.DIN_API_KEY ?? ''}`,
},

explorer: {
[constants.StarknetChainId.SN_MAIN]:
// eslint-disable-next-line no-template-curly-in-string
Expand Down
23 changes: 23 additions & 0 deletions packages/starknet-snap/src/utils/rpc-provider.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { constants } from 'starknet';

import { getRPCUrl } from './rpc-provider';

describe('getRPCUrl', () => {
it('returns Mainnet RPC URL if chain id is Mainnet', () => {
expect(getRPCUrl(constants.StarknetChainId.SN_MAIN)).toBe(
'https://starknet-mainnet.infura.io/v3/',
);
});

it('returns Sepolia RPC URL if chain id is not either Mainnet or Sepolia', () => {
expect(getRPCUrl('0x534e5f474f45524c49')).toBe(
'https://starknet-sepolia.infura.io/v3/',
);
});

it('returns Sepolia RPC URL if chain id is Sepolia', () => {
expect(getRPCUrl(constants.StarknetChainId.SN_SEPOLIA)).toBe(
'https://starknet-sepolia.infura.io/v3/',
);
});
});
17 changes: 17 additions & 0 deletions packages/starknet-snap/src/utils/rpc-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { constants } from 'starknet';

import { Config } from '../config';

/**
*
* @param chainId
*/
export function getRPCUrl(chainId: string) {
switch (chainId) {
case constants.StarknetChainId.SN_MAIN:
return Config.rpcEndpoint[constants.StarknetChainId.SN_MAIN];
default:
case constants.StarknetChainId.SN_SEPOLIA:
return Config.rpcEndpoint[constants.StarknetChainId.SN_SEPOLIA];
}
}
22 changes: 0 additions & 22 deletions packages/starknet-snap/src/utils/snapUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,28 +745,6 @@ export function getChainIdHex(network: Network) {
return `0x${numUtils.toBigInt(network.chainId).toString(16)}`;
}

/**
*
* @param chainId
*/
export function getRPCUrl(chainId: string) {
switch (chainId) {
case constants.StarknetChainId.SN_MAIN:
return `https://starknet-mainnet.g.alchemy.com/starknet/version/rpc/v0_7/${getRPCCredentials()}`;
default:
case STARKNET_SEPOLIA_TESTNET_NETWORK.chainId:
return `https://starknet-sepolia.g.alchemy.com/starknet/version/rpc/v0_7/${getRPCCredentials()}`;
}
}

/**
*
*/
export function getRPCCredentials(): string {
// eslint-disable-next-line no-restricted-globals
return process.env.ALCHEMY_API_KEY ?? '';
}

/**
*
* @param chainId
Expand Down
2 changes: 1 addition & 1 deletion packages/starknet-snap/src/utils/starknetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ import { DeployRequiredError, UpgradeRequiredError } from './exceptions';
import { hexToString } from './formatter-utils';
import { getAddressKey } from './keyPair';
import { logger } from './logger';
import { getRPCUrl } from './rpc-provider';
import { toJson } from './serializer';
import {
getAccount,
getAccounts,
getRPCUrl,
getTransactionsFromVoyagerUrl,
getVoyagerCredentials,
} from './snapUtils';
Expand Down
21 changes: 0 additions & 21 deletions packages/starknet-snap/test/utils/snapUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
getTransactionFromVoyagerUrl,
getTransactionsFromVoyagerUrl,
getVoyagerCredentials,
getRPCUrl,
} from '../../src/utils/snapUtils';
import { WalletMock } from '../wallet.mock.test';
import { Network, SnapState } from '../../src/types/snapState';
Expand Down Expand Up @@ -152,23 +151,3 @@ describe('getVoyagerCredentials', () => {
expect(getVoyagerCredentials()).to.have.key('X-API-Key');
});
});

describe('getRPCUrl', () => {
it('returns Mainnet RPC URL if chain id is Mainnet', () => {
expect(getRPCUrl(constants.StarknetChainId.SN_MAIN)).to.be.equal(
'https://starknet-mainnet.g.alchemy.com/starknet/version/rpc/v0_7/',
);
});

it('returns Sepolia RPC URL if chain id is not either Mainnet or Sepolia', () => {
expect(getRPCUrl('0x534e5f474f45524c49')).to.be.equal(
'https://starknet-sepolia.g.alchemy.com/starknet/version/rpc/v0_7/',
);
});

it('returns Sepolia RPC URL if chain id is Sepolia', () => {
expect(getRPCUrl(STARKNET_SEPOLIA_TESTNET_NETWORK.chainId)).to.be.equal(
'https://starknet-sepolia.g.alchemy.com/starknet/version/rpc/v0_7/',
);
});
});

0 comments on commit 11afba5

Please sign in to comment.