Skip to content

Commit

Permalink
custom RPC setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Messer4 committed Oct 25, 2024
1 parent 56a5e63 commit e406515
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
12 changes: 10 additions & 2 deletions aptos.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const {UnsetDecimal, SetDecimal} = require("./utils/decimals");
const chain = 'aptos';

const NODE_URL = "https://fullnode.mainnet.aptoslabs.com/v1";
const client = new aptos.AptosClient(NODE_URL);
let client = new aptos.AptosClient(NODE_URL);

const VALIDATOR_ADDRESS = '0xdb5247f859ce63dbe8940cf8773be722a60dcc594a8be9aca4b76abceb251b8e';

Expand Down Expand Up @@ -277,6 +277,13 @@ async function createClient(NODE_URL) {
}
}


// TODO refactor to class with constructor
function setRPC(url) {
client = new aptos.AptosClient(NODE_URL);
}


module.exports = {
// func
getBalanceByAddress,
Expand All @@ -289,7 +296,8 @@ module.exports = {
createClient,
getMinAmountForStake,
getLockupSecs,

setRPC,

// const
NODE_URL,
aptosCoin,
Expand Down
9 changes: 8 additions & 1 deletion cosmos.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const {UnsetDecimal} = require("./utils/decimals");
const BigNumber = require('bignumber.js');
const axios = require('axios');

const API_URL = 'https://cosmos-rest.publicnode.com';
let API_URL = 'https://cosmos-rest.publicnode.com';
const VALIDATOR_ADDRESS = 'cosmosvaloper1tflk30mq5vgqjdly92kkhhq3raev2hnz6eete3';
const decimals = 6;
const minAmount = new BigNumber(0.01);
Expand Down Expand Up @@ -230,11 +230,18 @@ async function getUndelegations(address) {
}
}

// TODO refactor to class with constructor
function setRPC(url) {
API_URL = url
}


module.exports = {
delegate,
redelegate,
undelegate,
withdrawRewards,
getDelegations,
getUndelegations,
setRPC
};
23 changes: 17 additions & 6 deletions polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const ABI_CONTRACT_BUY = [{"inputs":[],"payable":false,"stateMutability":"nonpay

const ADDRESS_CONTRACT_BUY = '0xF30Cf4ed712D3734161fDAab5B1DBb49Fd2D0E5c';

const RPC_URL = 'https://mainnet.infura.io/v3/f583d4f04d384b9e8c59a7ff1c9f68f1';
let RPC_URL = 'https://mainnet.infura.io/v3/f583d4f04d384b9e8c59a7ff1c9f68f1';

// 1 MATIC
const minAmount = new BigNumber('1000000000000000000');
Expand All @@ -28,11 +28,11 @@ const restakeBaseGas = 220000;
const chain = 'polygon';

const WITHDRAW_EPOCH_DELAY = 80;
const web3 = new Web3(RPC_URL);
const contract_approve = new web3.eth.Contract(ABI_CONTRACT_APPROVE, ADDRESS_CONTRACT_APPROVE);
const contract_approve_pol = new web3.eth.Contract(ABI_CONTRACT_APPROVE, ADDRESS_CONTRACT_APPROVE_POL);
const contract_buy = new web3.eth.Contract(ABI_CONTRACT_BUY, ADDRESS_CONTRACT_BUY);
const contract_staking = new web3.eth.Contract(ABI_CONTRACT_STAKING, ADDRESS_CONTRACT_STAKING);
let web3 = new Web3(RPC_URL);
let contract_approve = new web3.eth.Contract(ABI_CONTRACT_APPROVE, ADDRESS_CONTRACT_APPROVE);
let contract_approve_pol = new web3.eth.Contract(ABI_CONTRACT_APPROVE, ADDRESS_CONTRACT_APPROVE_POL);
let contract_buy = new web3.eth.Contract(ABI_CONTRACT_BUY, ADDRESS_CONTRACT_BUY);
let contract_staking = new web3.eth.Contract(ABI_CONTRACT_STAKING, ADDRESS_CONTRACT_STAKING);

/** isTransactionLoading returns TX loading status
* @param {string} hash - TX hash
Expand Down Expand Up @@ -295,6 +295,15 @@ async function getAllowance(owner, spender = ADDRESS_CONTRACT_STAKING, isPOL = f
}
}

// TODO refactor to class with constructor
function setRPC(url) {
RPC_URL = url
web3 = new Web3(RPC_URL);
contract_approve = new web3.eth.Contract(ABI_CONTRACT_APPROVE, ADDRESS_CONTRACT_APPROVE);
contract_approve_pol = new web3.eth.Contract(ABI_CONTRACT_APPROVE, ADDRESS_CONTRACT_APPROVE_POL);
contract_buy = new web3.eth.Contract(ABI_CONTRACT_BUY, ADDRESS_CONTRACT_BUY);
contract_staking = new web3.eth.Contract(ABI_CONTRACT_STAKING, ADDRESS_CONTRACT_STAKING);
}

module.exports = {
isTransactionLoading,
Expand All @@ -311,6 +320,8 @@ module.exports = {
getAllowance,
getBalanceOf,
getUnbondNonces,
setRPC,

ABI_CONTRACT_APPROVE,
ADDRESS_CONTRACT_APPROVE,
ADDRESS_CONTRACT_APPROVE_POL,
Expand Down
8 changes: 7 additions & 1 deletion solana.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ const minAmount = 10000000; // 0.01
const VALIDATOR_ADDRESS = '9QU2QSxhb24FUX3Tu2FpczXjpK3VYrvRudywSZaM29mF';

let connection = null;
let rpcURL = clusterApiUrl("mainnet-beta");

/** connect client
* @returns {Promise<object>} Promise object - client connection
*/
async function connect() {
try {
connection = new Connection(clusterApiUrl("mainnet-beta"), "confirmed");
connection = new Connection(rpcURL, "confirmed");
} catch (error) {
throw new Error(error);
}
Expand Down Expand Up @@ -309,11 +310,16 @@ async function getBlockhash(){
.then((res) => res.blockhash);
}

function setRPC(url) {
rpcURL = url
}

module.exports = {
createAccount,
delegate,
deactivate,
withdraw,
getDelegations,
stake,
setRPC
};

0 comments on commit e406515

Please sign in to comment.