Skip to content

Commit

Permalink
Replace api key with rpc url
Browse files Browse the repository at this point in the history
  • Loading branch information
makarychev committed Mar 20, 2024
1 parent c854512 commit bf1bfa3
Show file tree
Hide file tree
Showing 20 changed files with 43 additions and 53 deletions.
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PROJECT_ID=2
PROJECT_API_KEY=sWo+muXwPNtR7XgX04sBWPE2z1yXIb5G
COMAKERY_SERVER_URL=http://localhost:3000
BLOCKCHAIN_NETWORK=ethereum_sepolia
ALCHEMY_API_KEY=
RPC_URL=
ETHEREUM_TOKEN_TYPE=token_release_schedule
ETHEREUM_CONTRACT_ADDRESS=0x9608848FA0063063d2Bb401e8B5efFcb8152Ec65
ETHEREUM_APPROVAL_CONTRACT_ADDRESS=0xe322488096c36edcce397d179e7b1217353884bb
Expand All @@ -13,4 +13,3 @@ REDIS_URL=redis://localhost:6379
BETWEEN_TRANSACTION_DELAY=5
EMPTY_QUEUE_DELAY=30
MAX_AMOUNT_FOR_TRANSFER=9900000000
ALCHEMY_API_KEY=
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const envs = {
projectApiKey: process.env.PROJECT_API_KEY,
comakeryServerUrl: process.env.COMAKERY_SERVER_URL,
purestakeApi: process.env.PURESTAKE_API,
alchemyApiKey: process.env.ALCHEMY_API_KEY,
rpcUrl: process.env.RPC_URL,
redisUrl: process.env.REDIS_URL,
emptyQueueDelay: parseInt(process.env.EMPTY_QUEUE_DELAY),
betweenTransactionDelay: parseInt(process.env.BETWEEN_TRANSACTION_DELAY),
Expand Down
4 changes: 2 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@
"required": true,
"value": "4"
},
"ALCHEMY_API_KEY": {
"description": "API key for Alchemy. Required to use with Solana and Ethereum blockchain.",
"RPC_URL": {
"description": "RPC url without specified protocol (http/https). Required to use with Solana and Ethereum blockchain.",
"required": false
},
"OPT_IN_APP": {
Expand Down
2 changes: 1 addition & 1 deletion lib/blockchains/EthereumBlockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class EthereumBlockchain {
constructor(envs) {
this.envs = envs
this.blockchainNetwork = envs.blockchainNetwork
this.web3 = new Web3(new Web3.providers.HttpProvider(`https://${this.chainName}.g.alchemy.com/v2/${this.envs.alchemyApiKey}`))
this.web3 = new Web3(new Web3.providers.HttpProvider(`https://${this.envs.rpcUrl}`))
// It is necessary to cache values gotten from blockchain
this.ethBalances = {}
this.tokenBalances = {}
Expand Down
11 changes: 1 addition & 10 deletions lib/blockchains/SolanaBlockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,11 @@ class SolanaBlockchain {
})
}

mainnetEndpoints() {
return `https://solana-mainnet.g.alchemy.com/v2/${this.envs.alchemyApiKey}`
}

devnetEndpoints() {
return `https://solana-devnet.g.alchemy.com/v2/${this.envs.alchemyApiKey}`
}

endpointsByNetwork(network) {
switch (network) {
case 'solana':
return this.mainnetEndpoints()
case 'solana_devnet':
return this.devnetEndpoints()
return `https://${this.envs.rpcUrl}`
case 'solana_testnet':
default:
console.error("Unknown or unsupported network")
Expand Down
6 changes: 3 additions & 3 deletions lib/hotwalletUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ exports.checkAllVariablesAreSet = function checkAllVariablesAreSet(envs) {
let ethereumEnvs = false

if (envs.ethereumTokenType == 'eth') {
ethereumEnvs = Boolean(envs.alchemyApiKey) && Boolean(envs.ethereumTokenSymbol)
ethereumEnvs = Boolean(envs.rpcUrl) && Boolean(envs.ethereumTokenSymbol)
} else {
ethereumEnvs = Boolean(envs.alchemyApiKey) && Boolean(envs.ethereumTokenSymbol) && Boolean(envs.ethereumContractAddress)
ethereumEnvs = Boolean(envs.rpcUrl) && Boolean(envs.ethereumTokenSymbol) && Boolean(envs.ethereumContractAddress)
}

const variables = [
Expand All @@ -37,7 +37,7 @@ exports.checkAllVariablesAreSet = function checkAllVariablesAreSet(envs) {
blockchainNetworks: ["algorand", "algorand_test", "algorand_beta"]
},
{
isEnvCorrect: Boolean(envs.alchemyApiKey),
isEnvCorrect: Boolean(envs.rpcUrl),
blockchainNetworks: ["solana", "solana_devnet"]
}
]
Expand Down
4 changes: 2 additions & 2 deletions tests/Blockchain.generateNewWallet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("Blockchain generate new wallet test suite", () => {

test('return correct generated keys for ethereum ', async () => {
const ethBlockchain = new hwUtils.EthereumBlockchain({
alchemyApiKey: "alchemy_api_key",
rpcUrl: "rpc_url",
blockchainNetwork: 'ethereum_sepolia'
})
const createAccount = {
Expand All @@ -41,7 +41,7 @@ describe("Blockchain generate new wallet test suite", () => {

test('return correct generated keys for solana ', async () => {
const solanaBlockchain = new hwUtils.Blockchain({
alchemyApiKey: 'alchemy_api',
rpcUrl: 'rpc_url',
blockchainNetwork: 'solana_devnet'
})

Expand Down
2 changes: 1 addition & 1 deletion tests/EthereumBlockchain.disableWallet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("EthereumBlockchain.disableWallet", () => {
const ethContractAddress = "0x1d1592c28fff3d3e71b1d29e31147846026a0a37"
const transactionHash = "0xb5c8bd9430b6cc87a0e2fe110ece6bf527fa4f170a4bc8cd032f768fc5219838"
const ethBlockchain = new EthereumBlockchain({
alchemyApiKey: "alchemy_api_key",
rpcUrl: 'rpc_url',
blockchainNetwork: 'ethereum_sepolia',
ethereumContractAddress: ethContractAddress
})
Expand Down
4 changes: 2 additions & 2 deletions tests/EthereumBlockchain.getEthBalance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const BigNumber = require('bignumber.js')
describe("EthereumBlockchain check for eth balance", () => {
test('return balance as a BigNumber object', async () => {
const ethBlockchain = new EthereumBlockchain({
alchemyApiKey: "alchemy_api_key",
rpcUrl: 'rpc_url',
blockchainNetwork: 'ethereum_sepolia'
})

Expand All @@ -16,7 +16,7 @@ describe("EthereumBlockchain check for eth balance", () => {

test('return zero if undefined', async () => {
const ethBlockchain = new EthereumBlockchain({
alchemyApiKey: "alchemy_api_key",
rpcUrl: 'rpc_url',
blockchainNetwork: 'ethereum_sepolia'
})

Expand Down
6 changes: 3 additions & 3 deletions tests/EthereumBlockchain.getTokenBalance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const BigNumber = require('bignumber.js')
describe("EthereumBlockchain check for token balance", () => {
test('return balance as an object with balances (in base units and in tokens)', async () => {
const ethBlockchain = new EthereumBlockchain({
alchemyApiKey: "alchemy_api_key",
rpcUrl: 'rpc_url',
blockchainNetwork: 'ethereum_sepolia',
ethereumContractAddress: "0x1d1592c28fff3d3e71b1d29e31147846026a0a37"
})
Expand All @@ -26,7 +26,7 @@ describe("EthereumBlockchain check for token balance", () => {

test('return zero for unknown contract', async () => {
const ethBlockchain = new EthereumBlockchain({
alchemyApiKey: "alchemy_api_key",
rpcUrl: 'rpc_url',
blockchainNetwork: 'ethereum_sepolia',
ethereumContractAddress: "0xB5e3062f536cE503B27CB366529613aa3bE0408e"
})
Expand All @@ -48,7 +48,7 @@ describe("EthereumBlockchain check for token balance", () => {

test('get ethereumApprovalContractAddress balance for Lockup contract', async () => {
const ethBlockchain = new EthereumBlockchain({
alchemyApiKey: "alchemy_api_key",
rpcUrl: 'rpc_url',
blockchainNetwork: 'ethereum_sepolia',
ethereumTokenType: "token_release_schedule",
ethereumContractAddress: "0x9608848fa0063063d2bb401e8b5effcb8152ec65",
Expand Down
2 changes: 1 addition & 1 deletion tests/EthereumTxValidator.isTransactionValid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const blockchainTransaction = require('./fixtures/ethereumBlockchainTransaction'
describe("EthereumBlockchain.isTransactionValid", () => {
const hwAddress = '0x15b4eda54e7aa56e4ca4fe6c19f7bf9d82eca2fc'
const ethBlockchain = new EthereumBlockchain({
alchemyApiKey: "alchemy_api_key",
rpcUrl: 'rpc_url',
blockchainNetwork: 'ethereum_sepolia',
ethereumContractAddress: "0x1d1592c28fff3d3e71b1d29e31147846026a0a37"
})
Expand Down
2 changes: 1 addition & 1 deletion tests/SolanaBlockchain.disableWallet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe("SolanaBlockchain.disableWallet", () => {
const tokenMintAddress = '91enn7UUM3rXqqMAmYgYRNuVQBRgTumTvV7kMCVyz5g'
const txHash = '2xu6HaySKadbeMozXnh69bP976uX78fhhw4LoWcd8U7FxKD99onMJUVyYzMGyAPSm61MxxnEC9z5rKtvVsVm9YpC'
const solanaBlockchain = new SolanaBlockchain({
alchemyApiKey: "alchemy_project_id",
rpcUrl: "rpc_url",
blockchainNetwork: 'solana_devnet',
})
let sendTransactionSpy = jest.spyOn(solanaBlockchain, "sendTransaction")
Expand Down
4 changes: 2 additions & 2 deletions tests/SolanaBlockchain.getSolBalance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const BigNumber = require('bignumber.js')
describe("SolanaBlockchain check for SOL balance", () => {
test('return balance as a BigNumber object', async () => {
const solanaBlockchain = new SolanaBlockchain({
alchemyApiKey: "alchemy_api_key",
rpcUrl: 'rpc_url',
blockchainNetwork: 'solana_devnet'
})

Expand All @@ -17,7 +17,7 @@ describe("SolanaBlockchain check for SOL balance", () => {

test('return zero of something went wrong', async () => {
const solanaBlockchain = new SolanaBlockchain({
alchemyApiKey: "alchemy_api_key",
rpcUrl: 'rpc_url',
blockchainNetwork: 'solana_devnet'
})

Expand Down
2 changes: 1 addition & 1 deletion tests/SolanaBlockchain.getTokenBalance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const SolanaBlockchain = require('../lib/blockchains/SolanaBlockchain').SolanaBl
const BigNumber = require('bignumber.js')

const solanaBlockchain = new SolanaBlockchain({
alchemyApiKey: "alchemy_api_key",
rpcUrl: 'rpc_url',
blockchainNetwork: 'solana_devnet'
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { SolanaTxValidator } = require('../lib/TxValidator');

describe("SolanaTxValidator.isSplBatchFundReleaseScheduleTxValid", () => {
const solanaBlockchain = new SolanaBlockchain({
alchemyApiKey: "alchemy_project_id",
rpcUrl: "rpc_url",
blockchainNetwork: 'solana_devnet',
})

Expand Down
2 changes: 1 addition & 1 deletion tests/SolanaTxValidator.isSplTxBatchValid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { SolanaTxValidator } = require('../lib/TxValidator');

describe("SolanaTxValidator.isSplTxBatchValid", () => {
const solanaBlockchain = new SolanaBlockchain({
alchemyApiKey: "alchemy_project_id",
rpcUrl: "rpc_url",
blockchainNetwork: 'solana_devnet',
})

Expand Down
2 changes: 1 addition & 1 deletion tests/SolanaTxValidator.isSystemTxValid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { SolanaTxValidator } = require('../lib/TxValidator');
describe("solanaTxValidator.isSystemTxValid", () => {
const hwAddress = 'CQSE22PAUYdorqCLqAguCkjAvhSnCB2zXyNPTinWNG58'
const solanaBlockchain = new SolanaBlockchain({
alchemyApiKey: "alchemy_project_id",
rpcUrl: "rpc_url",
blockchainNetwork: 'solana_devnet',
})

Expand Down
2 changes: 1 addition & 1 deletion tests/SolanaTxValidator.isTransactionValid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { SolanaTxValidator } = require('../lib/TxValidator');
describe("SolanaBlockchain.isTransactionValid", () => {
const hwAddress = 'CQSE22PAUYdorqCLqAguCkjAvhSnCB2zXyNPTinWNG58'
const solanaBlockchain = new SolanaBlockchain({
alchemyApiKey: "alchemy_project_id",
rpcUrl: "rpc_url",
blockchainNetwork: 'solana_devnet',
})
const solanaTxValidator = new SolanaTxValidator({
Expand Down
32 changes: 16 additions & 16 deletions tests/checkAllVariablesAreSet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("Check that all variables are set test suite", () => {
projectApiKey: "project_api_key",
comakeryServerUrl: "http://cmk.server",
// purestakeApi: "purestake_api_key", // not required for ethereum
alchemyApiKey: "alchemy_api_key",
rpcUrl: 'rpc_url',
redisUrl: "redis://localhost:6379/0",
emptyQueueDelay: 30,
// optInApp: 13997710, // not required for ethereum
Expand All @@ -43,7 +43,7 @@ describe("Check that all variables are set test suite", () => {
projectApiKey: "project_api_key",
comakeryServerUrl: "http://cmk.server",
// purestakeApi: "purestake_api_key", // not required for solana
alchemyApiKey: "alchemy_key",
rpcUrl: 'rpc_url',
redisUrl: "redis://localhost:6379/0",
emptyQueueDelay: 30,
// optInApp: 13997710, // not required for ethereum
Expand Down Expand Up @@ -150,7 +150,7 @@ describe("Check that all variables are set test suite", () => {
projectApiKey: "project_api_key",
comakeryServerUrl: "http://cmk.server",
purestakeApi: null,
alchemyApiKey: "alchemy_api_key",
rpcUrl: 'rpc_url',
redisUrl: "redis://localhost:6379/0",
emptyQueueDelay: 30,
optInApp: 13997710,
Expand Down Expand Up @@ -212,7 +212,7 @@ describe("Check that all variables are set test suite", () => {
projectId: "1",
projectApiKey: "project_api_key",
comakeryServerUrl: "http://cmk.server",
alchemyApiKey: "alchemy_api_key",
rpcUrl: 'rpc_url',
redisUrl: "redis://localhost:6379/0",
emptyQueueDelay: 30,
optInApp: null,
Expand All @@ -231,7 +231,7 @@ describe("Check that all variables are set test suite", () => {
projectApiKey: "project_api_key",
comakeryServerUrl: "http://cmk.server",
purestakeApi: "purestake_api_key",
alchemyApiKey: "alchemy_api_key",
rpcUrl: 'rpc_url',
redisUrl: "redis://localhost:6379/0",
emptyQueueDelay: 30,
optInApp: 13997710,
Expand Down Expand Up @@ -264,7 +264,7 @@ describe("Check that all variables are set test suite", () => {
projectApiKey: "project_api_key",
comakeryServerUrl: "http://cmk.server",
purestakeApi: "purestake_api_key",
alchemyApiKey: "alchemy_api_key",
rpcUrl: 'rpc_url',
redisUrl: "redis://localhost:6379/0",
emptyQueueDelay: 30,
optInApp: 13997710,
Expand All @@ -281,7 +281,7 @@ describe("Check that all variables are set test suite", () => {
projectId: "1",
projectApiKey: "project_api_key",
comakeryServerUrl: "http://cmk.server",
alchemyApiKey: "alchemy_api_key",
rpcUrl: 'rpc_url',
redisUrl: "redis://localhost:6379/0",
emptyQueueDelay: 30,
blockchainNetwork: 'ethereum_sepolia',
Expand All @@ -298,7 +298,7 @@ describe("Check that all variables are set test suite", () => {
projectApiKey: "project_api_key",
comakeryServerUrl: "http://cmk.server",
purestakeApi: "purestake_api_key",
alchemyApiKey: "alchemy_api_key",
rpcUrl: 'rpc_url',
redisUrl: "redis://localhost:6379/0",
emptyQueueDelay: 30,
optInApp: 13997710,
Expand All @@ -315,7 +315,7 @@ describe("Check that all variables are set test suite", () => {
projectId: "1",
projectApiKey: "project_api_key",
comakeryServerUrl: "http://cmk.server",
alchemyApiKey: "alchemy_api_key",
rpcUrl: 'rpc_url',
redisUrl: "redis://localhost:6379/0",
emptyQueueDelay: 30,
blockchainNetwork: 'ethereum_sepolia',
Expand All @@ -331,7 +331,7 @@ describe("Check that all variables are set test suite", () => {
projectId: "1",
projectApiKey: "project_api_key",
comakeryServerUrl: "http://cmk.server",
alchemyApiKey: "alchemy_api_key",
rpcUrl: 'rpc_url',
redisUrl: "redis://localhost:6379/0",
emptyQueueDelay: 30,
blockchainNetwork: 'ethereum_sepolia',
Expand All @@ -343,13 +343,13 @@ describe("Check that all variables are set test suite", () => {
expect(hwUtils.checkAllVariablesAreSet(envs)).toBe(true)
})

test('alchemyApiKey is null for algorand', async () => {
test('rpcUrl is null for algorand', async () => {
const envs = {
projectId: "1",
projectApiKey: "project_api_key",
comakeryServerUrl: "http://cmk.server",
purestakeApi: "purestake_api_key",
alchemyApiKey: null,
rpcUrl: null,
redisUrl: "redis://localhost:6379/0",
emptyQueueDelay: 30,
optInApp: 13997710,
Expand All @@ -361,12 +361,12 @@ describe("Check that all variables are set test suite", () => {
expect(hwUtils.checkAllVariablesAreSet(envs)).toBe(true)
})

test('alchemyApiKey is null for ethereum', async () => {
test('rpcUrl is null for ethereum', async () => {
const envs = {
projectId: "1",
projectApiKey: "project_api_key",
comakeryServerUrl: "http://cmk.server",
alchemyApiKey: null,
rpcUrl: null,
redisUrl: "redis://localhost:6379/0",
emptyQueueDelay: 30,
blockchainNetwork: 'ethereum_sepolia',
Expand All @@ -377,12 +377,12 @@ describe("Check that all variables are set test suite", () => {
expect(hwUtils.checkAllVariablesAreSet(envs)).toBe(false)
})

test('alchemyApiKey is null for solana', async () => {
test('rpcUrl is null for solana', async () => {
const envs = {
projectId: "1",
projectApiKey: "project_api_key",
comakeryServerUrl: "http://cmk.server",
alchemyApiKey: null,
rpcUrl: null,
redisUrl: "redis://localhost:6379/0",
emptyQueueDelay: 30,
blockchainNetwork: 'solana',
Expand Down
2 changes: 1 addition & 1 deletion tests/waitForNewTransaction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe("For Ethereum blockchain", () => {
projectId: "1",
projectApiKey: "project_api_key",
comakeryServerUrl: null,
alchemyApiKey: "alchemy_api_key",
rpcUrl: 'rpc_url',
redisUrl: "redis://localhost:6379/0",
blockchainNetwork: "ethereum_sepolia"
}
Expand Down

0 comments on commit bf1bfa3

Please sign in to comment.