Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Splits constants.js file #167

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/2wp-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const { getBridge } = require('./precompiled-abi-forks-util');
const { getBridgeState } = require('@rsksmart/bridge-state-data-parser');
const { getDerivedRSKAddressInformation } = require('@rsksmart/btc-rsk-derivation');
const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter');
const { PEGIN_EVENTS, DEFAULT_RSK_ADDRESS_FUNDING_IN_BTC, PEGOUT_EVENTS } = require("./constants");
const { PEGIN_EVENTS, DEFAULT_RSK_ADDRESS_FUNDING_IN_BTC } = require('./constants/pegin-constants');
const { PEGOUT_EVENTS } = require('./constants/pegout-constants');

const peginVerifier = require('pegin-address-verificator');
const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider');
Expand Down
2 changes: 1 addition & 1 deletion lib/assertions/2wp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var {wait, removePrefix0x} = require('../utils');
var bitcoin = require('peglib').bitcoin;
var rsk = require('peglib').rsk;

const {MAX_ESTIMATED_FEE_PER_PEGOUT, FEE_DIFFERENCE_PER_PEGOUT} = require('../constants');
const { MAX_ESTIMATED_FEE_PER_PEGOUT, FEE_DIFFERENCE_PER_PEGOUT } = require('../constants/pegout-constants');
const {encodeOutpointValuesAsMap, decodeOutpointValues} = require("../varint");

const BTC_TX_FEE = bitcoin.btcToSatoshis(0.001);
Expand Down
156 changes: 0 additions & 156 deletions lib/constants.js

This file was deleted.

57 changes: 57 additions & 0 deletions lib/constants/federation-constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const KEY_TYPE_BTC = 'btc';
const KEY_TYPE_RSK = 'rsk';
const KEY_TYPE_MST = 'mst';

const KEY_TYPES = [KEY_TYPE_BTC, KEY_TYPE_RSK, KEY_TYPE_MST];

const ERP_PUBKEYS = [
'029cecea902067992d52c38b28bf0bb2345bda9b21eca76b16a17c477a64e43301',
'03284178e5fbcc63c54c3b38e3ef88adf2da6c526313650041b0ef955763634ebd',
'03776b1fd8f86da3c1db3d69699e8250a15877d286734ea9a6da8e9d8ad25d16c1',
'03ab0e2cd7ed158687fc13b88019990860cdb72b1f5777b58513312550ea1584bc',
'03b9fc46657cf72a1afa007ecf431de1cd27ff5cc8829fa625b66ca47b967e6b24'
];

const ERP_CSV_VALUE = 500;

const MAX_INPUTS_PER_MIGRATION_TRANSACTION = 10;

const REGTEST_FEDERATION_CHANGE_PRIVATE_KEYS = [
'c14991a187e185ca1442e75eb8f60a6a5efd4ca57ce31e50d6e841d9381e996b',
'488cdd0c11d602598225fe96c4b85c2afbec3f1d938cd88f4655831cb6ff454b',
'72255947e1aff21d3fc9c077c6a70912aede3674913d5c76b4128c1ec5692499',
'fb69358d4760c80977497073e80281e47fa3e6ccf7371a215506ec295c1d8c69',
'857ec435ef0160993dc5f1e70f19f30b1b0249f061cc52294fd266cb093df173',
];

const REGTEST_FEDERATION_CHANGE_ADDRESSES = [
'5252403bca6ac3c104abdd320a736fa38282045d',
'0d8c44bd578a4e7148d1758b3332b529e93e48c1',
'566bca18df14ed75efcc1a8a4f3947e81132dbbc',
'2e7c9159614ddc0185e335d3343e92700c3e5a2d',
'f0652637df184eca87e6bde29893825721dfb79f',
];

const GENESIS_FEDERATION_ADDRESS = '2N5muMepJizJE1gR7FbHJU6CD18V3BpNF9p';
const GENESIS_FEDERATION_REDEEM_SCRIPT = '0x522102cd53fc53a07f211641a677d250f6de99caf620e8e77071e811a28b3bcddf0be1210362634ab57dae9cb373a5d536e66a8c4f67468bbcfb063809bab643072d78a1242103c5946b3fbae03a654237da863c9ed534e0878657175b132b8ca630f245df04db53ae';

const FEDERATION_ACTIVATION_AGE = 20;
const FUNDS_MIGRATION_AGE_SINCE_ACTIVATION_BEGIN = 15;
const FUNDS_MIGRATION_AGE_SINCE_ACTIVATION_END = 150;

module.exports = {
KEY_TYPE_BTC,
KEY_TYPE_RSK,
KEY_TYPE_MST,
KEY_TYPES,
ERP_PUBKEYS,
ERP_CSV_VALUE,
MAX_INPUTS_PER_MIGRATION_TRANSACTION,
REGTEST_FEDERATION_CHANGE_PRIVATE_KEYS,
REGTEST_FEDERATION_CHANGE_ADDRESSES,
GENESIS_FEDERATION_ADDRESS,
GENESIS_FEDERATION_REDEEM_SCRIPT,
FEDERATION_ACTIVATION_AGE,
FUNDS_MIGRATION_AGE_SINCE_ACTIVATION_BEGIN,
FUNDS_MIGRATION_AGE_SINCE_ACTIVATION_END,
};
12 changes: 12 additions & 0 deletions lib/constants/fee-per-kb-constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const FEE_PER_KB_CHANGER_PRIVATE_KEY = '6a4b49312b91e203ddfb9bc2d900ebbd46fbede46a7462e770bedcb11ad405e9';
const FEE_PER_KB_CHANGER_ADDRESS = '53f8f6dabd612b6137215ddd7758bb5cdd638922';

const FEE_PER_KB_RESPONSE_CODES = {
SUCCESSFUL_VOTE: 1,
};

module.exports = {
FEE_PER_KB_CHANGER_PRIVATE_KEY,
FEE_PER_KB_CHANGER_ADDRESS,
FEE_PER_KB_RESPONSE_CODES,
};
39 changes: 39 additions & 0 deletions lib/constants/pegin-constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

const PEGIN_V1_RSKT_PREFIX_HEX = '52534b54';
const DEFAULT_RSK_ADDRESS_FUNDING_IN_BTC = 0.5;

const PEGIN_REJECTION_REASONS = {
PEGIN_CAP_SURPASSED_REASON: '1',
LEGACY_PEGIN_MULTISIG_SENDER: '2',
LEGACY_PEGIN_UNDETERMINED_SENDER: '3',
PEGIN_V1_INVALID_PAYLOAD_REASON: '4',
INVALID_AMOUNT: '5',
};

const PEGIN_UNREFUNDABLE_REASONS = {
LEGACY_PEGIN_UNDETERMINED_SENDER: '1',
INVALID_AMOUNT: '3',
};

const PEGIN_EVENTS = {
PEGIN_BTC: {
name: 'pegin_btc',
signature: '0x44cdc782a38244afd68336ab92a0b39f864d6c0b2a50fa1da58cafc93cd2ae5a'
},
REJECTED_PEGIN: {
name: 'rejected_pegin',
signature: '0x708ce1ead20561c5894a93be3fee64b326b2ad6c198f8253e4bb56f1626053d6'
},
UNREFUNDABLE_PEGIN: {
name: 'unrefundable_pegin',
signature: '0x35be155c87e408cbbcb753dc12f95fc5a242a29460a3d7189e807e63d7c185a7'
},
};

module.exports = {
PEGIN_V1_RSKT_PREFIX_HEX,
DEFAULT_RSK_ADDRESS_FUNDING_IN_BTC,
PEGIN_REJECTION_REASONS,
PEGIN_UNREFUNDABLE_REASONS,
PEGIN_EVENTS,
};
54 changes: 54 additions & 0 deletions lib/constants/pegout-constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const MAX_ESTIMATED_FEE_PER_PEGOUT = 68600;
const FEE_DIFFERENCE_PER_PEGOUT = 3200;
const NUMBER_OF_BLOCKS_BTW_PEGOUTS = 50;
const MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS = 250_000;

const PEGOUT_REJECTION_REASONS = {
LOW_AMOUNT: '1',
CALLER_CONTRACT: '2',
FEE_ABOVE_VALUE: '3',
};

const PEGOUT_EVENTS = {
RELEASE_REQUEST_RECEIVED: {
name: 'release_request_received',
signature: '0x1a4457a4460d48b40c5280955faf8e4685fa73f0866f7d8f573bdd8e64aca5b1'
},
RELEASE_REQUEST_REJECTED: {
name: 'release_request_rejected',
signature: '0xb607c3e1fbe6b38cd145b15b837f7b722b199caa60e3057b36c141adee3b75e7'
},
RELEASE_REQUESTED: {
name: 'release_requested',
signature: '0x7a7c29481528ac8c2b2e93aee658fddd4dc15304fa723a5c2b88514557bcc790'
},
BATCH_PEGOUT_CREATED: {
name: 'batch_pegout_created',
signature: '0x483d0191cc4e784b04a41f6c4801a0766b43b1fdd0b9e3e6bfdca74e5b05c2eb'
},
PEGOUT_TRANSACTION_CREATED: {
name: 'pegout_transaction_created',
signature: '0x9ee5d520fd5e6eaea3fd2e3ae4e35e9a9c0fb05c9d8f84b507f287da84b5117c'
},
PEGOUT_CONFIRMED: {
name: 'pegout_confirmed',
signature: '0xc287f602476eeef8a547a3b82e79045c827c51362ff153f728b6d839bad099ef'
},
ADD_SIGNATURE: {
name: 'add_signature',
signature: '0x83b6efe3a7d95459577ec9396f5d6f1e486ca2378130e2ba4d98a4da108ca743'
},
RELEASE_BTC: {
name: 'release_btc',
signature: '0x655929b56d5c5a24f81ee80267d5151b9d680e7e703387999922e9070bc98a02'
},
};

module.exports = {
MAX_ESTIMATED_FEE_PER_PEGOUT,
FEE_DIFFERENCE_PER_PEGOUT,
NUMBER_OF_BLOCKS_BTW_PEGOUTS,
MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS,
PEGOUT_REJECTION_REASONS,
PEGOUT_EVENTS,
};
2 changes: 1 addition & 1 deletion lib/federate-starter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var LineWrapper = require('stream-line-wrapper');
var { executeWithRetries } = require('./utils');
var HsmRunner = require('./hsm-runner').Runner;
var FederateRunner = require('./federate-runner').Runner;
const { KEY_TYPES, KEY_TYPE_BTC, KEY_TYPE_RSK, KEY_TYPE_MST } = require('./constants');
const { KEY_TYPES, KEY_TYPE_BTC, KEY_TYPE_RSK, KEY_TYPE_MST } = require('./constants/federation-constants');

var FEDERATE_OUTPUT = 'federate-{index}:';
var FEDERATE_COLORS = [
Expand Down
2 changes: 1 addition & 1 deletion lib/federation-utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { KEY_TYPE_BTC, KEY_TYPE_RSK, KEY_TYPE_MST } = require('./constants');
const { KEY_TYPE_BTC, KEY_TYPE_RSK, KEY_TYPE_MST } = require('./constants/federation-constants');

var comparePublicKeys = (publicKeyA, publicKeyB) => {
if (publicKeyA < publicKeyB) {
Expand Down
11 changes: 4 additions & 7 deletions lib/rsk-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider');
const { wait, retryWithCheck, removePrefix0x } = require('./utils');
const { waitForBitcoinMempoolToGetTxs } = require('./btc-utils');
const { getLogger } = require('../logger');
const {
PEGOUT_EVENTS,
FEE_PER_KB_CHANGER_PRIVATE_KEY,
FEE_PER_KB_CHANGER_ADDRESS,
FEE_PER_KB_RESPONSE_CODES,
DEFAULT_RSK_ADDRESS_FUNDING_IN_BTC,
} = require('./constants');
const { PEGOUT_EVENTS } = require('./constants/pegout-constants');
const { FEE_PER_KB_CHANGER_PRIVATE_KEY, FEE_PER_KB_CHANGER_ADDRESS, FEE_PER_KB_RESPONSE_CODES } = require('./constants/fee-per-kb-constants');
const { DEFAULT_RSK_ADDRESS_FUNDING_IN_BTC } = require('./constants/pegin-constants');

const BtcTransactionHelper = require('btc-transaction-helper/btc-transaction-helper');
const { ethToWeis } = require('@rsksmart/btc-eth-unit-converter');

Expand Down
11 changes: 3 additions & 8 deletions lib/tests/2wp.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ const { getRskTransactionHelper, getRskTransactionHelpers } = require('../rsk-tx
const { satoshisToBtc, btcToSatoshis, satoshisToWeis } = require('@rsksmart/btc-eth-unit-converter');
const { findEventInBlock, triggerRelease, getPegoutEventsInBlockRange, setFeePerKb, sendTransaction, getNewFundedRskAddress } = require('../rsk-utils');
const BridgeTransactionParser = require('@rsksmart/bridge-transaction-parser');
const {
PEGIN_REJECTION_REASONS,
PEGIN_UNREFUNDABLE_REASONS,
PEGOUT_EVENTS,
PEGIN_V1_RSKT_PREFIX_HEX,
MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS,
PEGOUT_REJECTION_REASONS,
} = require("../constants");
const { PEGIN_REJECTION_REASONS, PEGIN_UNREFUNDABLE_REASONS, PEGIN_V1_RSKT_PREFIX_HEX } = require('../constants/pegin-constants');
const { PEGOUT_EVENTS, MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS, PEGOUT_REJECTION_REASONS } = require('../constants/pegout-constants');

const { sendPegin,
ensurePeginIsRegistered,
createSenderRecipientInfo,
Expand Down
Loading
Loading