Skip to content
Open
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
24 changes: 24 additions & 0 deletions contracts/UnionBridgeContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface BridgeInterface {
function requestUnionBridgeRbtc(uint256 amountRequested) external returns (int256);

function releaseUnionBridgeRbtc() external payable returns (int256);
}

contract UnionBridgeContract {
BridgeInterface public bridge = BridgeInterface(0x0000000000000000000000000000000001000006);

function requestUnionBridgeRbtc(uint256 amountToRequest) external returns (int256) {
return bridge.requestUnionBridgeRbtc(amountToRequest);
}

function releaseUnionBridgeRbtc(uint256 amountToRelease) public payable returns (int256) {
return bridge.releaseUnionBridgeRbtc{value: amountToRelease}();
}

receive() external payable { }

fallback() external payable { }
}
7 changes: 3 additions & 4 deletions lib/bridge-provider.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
const precompiledAbisLovell = require("@rsksmart/rsk-precompiled-abis-lovell");
const Web3 = require("web3");
const precompiledAbisReed = require("@rsksmart/rsk-precompiled-abis-reed");

/**
* Returns a new bridge.
* @param {Web3} rskClient
* @returns {Bridge}
*/
const getBridge = async (rskClient) => {
return new rskClient.eth.Contract(precompiledAbisLovell.bridge.abi, precompiledAbisLovell.bridge.address);
return new rskClient.eth.Contract(precompiledAbisReed.bridge.abi, precompiledAbisReed.bridge.address);
};

/**
* Returns the abi of the bridge for the latest fork.
* @returns {json} The bridge abi in json format
*/
const getBridgeAbi = async () => {
return precompiledAbisLovell.bridge.abi;
return precompiledAbisReed.bridge.abi;
};

module.exports = {
Expand Down
76 changes: 76 additions & 0 deletions lib/constants/union-bridge-constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const { btcToWeis } = require("@rsksmart/btc-eth-unit-converter");
const { getBridgeStorageIndexFromLongKey } = require("../utils");

const UNION_BRIDGE_ADDRESS = '0x0000000000000000000000000000000000000000';

// 400 RBTC initial locking cap
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 400 RBTC initial locking cap
// 500 RBTC initial locking cap

?

const INITIAL_LOCKING_CAP = btcToWeis(200);

const LOCKING_CAP_INCREMENTS_MULTIPLIER = 2;

// Change union bridge contract address authorizer public key
const CHANGE_UNION_BRIDGE_CONTRACT_ADDRESS_AUTHORIZER_PK = '7880a81a4591568b0e87947e5150fe8e330091678654f3bc661b516f91a5f00a';

// Change locking cap authorizers public keys
const CHANGE_LOCKING_CAP_AUTHORIZERS_PKS = [
'a2221797b4e6655bf39e8290d6db2c75536cf9ffb7f0d2bf4a7360f0b3716e5d'
];

// Change transfer permissions authorizers public keys
const CHANGE_TRANSFER_PERMISSIONS_AUTHORIZERS_PKS = [
'03918409b6d508f31d72879df0813a6d60d8c74eb91197572c9f3df1da9ae5a5'
];

const UNION_BRIDGE_EVENTS = {
UNION_LOCKING_CAP_INCREASED: {
name: 'union_bridge_locking_cap_increased'
},
UNION_RBTC_REQUESTED: {
name: 'union_rbtc_requested'
},
UNION_RBTC_RELEASED: {
name: 'union_rbtc_released'
},
UNION_BRIDGE_TRANSFER_PERMISSIONS_UPDATED: {
name: 'union_bridge_transfer_permissions_updated'
}
};

const UNION_BRIDGE_STORAGE_INDICES = {
UNION_BRIDGE_CONTRACT_ADDRESS: getBridgeStorageIndexFromLongKey('unionBridgeContractAddress'),
UNION_BRIDGE_LOCKING_CAP: getBridgeStorageIndexFromLongKey('unionBridgeLockingCap'),
UNION_BRIDGE_INCREASE_LOCKING_CAP_ELECTION: getBridgeStorageIndexFromLongKey('unionBridgeIncreaseLockingCapElection'),
WEIS_TRANSFERRED_TO_UNION_BRIDGE: getBridgeStorageIndexFromLongKey('weisTransferredToUnionBridge'),
UNION_BRIDGE_REQUEST_ENABLED: getBridgeStorageIndexFromLongKey('unionBridgeRequestEnabled'),
UNION_BRIDGE_RELEASE_ENABLED: getBridgeStorageIndexFromLongKey('unionBridgeReleaseEnabled'),
UNION_BRIDGE_TRANSFER_PERMISSIONS_ELECTION: getBridgeStorageIndexFromLongKey('unionBridgeTransferPermissionsElection')
}

const UNION_RESPONSE_CODES = {
SUCCESS: "0",
UNAUTHORIZED_CALLER: "-1",
// Response codes when the value specified is invalid:
// 1. The requested amount of RBTC, combined with previously requested amounts, exceeds the current locking cap value.
// 2. The returned amount exceeds the total amount of RBTC previously transferred.
// 3. The new cap value is less than the current cap or excessive.
INVALID_VALUE: "-2",
// Response codes when request or release is disabled:
REQUEST_DISABLED: "-3",
RELEASE_DISABLED: "-3",
// Environment restriction for preventing union bridge address being updated on production
ENVIRONMENT_DISABLED: "-3",
GENERIC_ERROR: "-10"
};


module.exports = {
UNION_BRIDGE_ADDRESS,
INITIAL_LOCKING_CAP,
LOCKING_CAP_INCREMENTS_MULTIPLIER,
CHANGE_UNION_BRIDGE_CONTRACT_ADDRESS_AUTHORIZER_PK,
CHANGE_LOCKING_CAP_AUTHORIZERS_PKS,
CHANGE_TRANSFER_PERMISSIONS_AUTHORIZERS_PKS,
UNION_BRIDGE_EVENTS,
UNION_BRIDGE_STORAGE_INDICES,
UNION_RESPONSE_CODES
};
36 changes: 30 additions & 6 deletions lib/contractDeployer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@

const fs = require('fs');
const path = require('path');
const solUtils = require('./sol-utils');
const TEST_RELEASE_BTC_CONTRACT = '../contracts/CallReleaseBtcContract.sol';
const TEST_RELEASE_BTC_CONTRACT_NAME = 'CallReleaseBtcContract';

const TEST_UNION_BRIDGE_CONTRACT = '../contracts/UnionBridgeContract.sol';
const TEST_UNION_BRIDGE_CONTRACT_NAME = 'UnionBridgeContract';

const SOLIDITY_COMPILER_VERSION = 'v0.8.26+commit.8a97fa7a';

/**
Expand All @@ -16,22 +19,43 @@ const deployCallReleaseBtcContract = async (rskTxHelper, from) => {

const fullPath = path.resolve(__dirname, TEST_RELEASE_BTC_CONTRACT);
const source = fs.readFileSync(fullPath).toString();
const callReleaseBtcContract = await solUtils.compileAndDeploy(

return await solUtils.compileAndDeploy(
SOLIDITY_COMPILER_VERSION,
source,
TEST_RELEASE_BTC_CONTRACT_NAME,
[],
rskTxHelper,
{
from
from
}
);

return callReleaseBtcContract;

};

/**
* Deploys the unionBridgeContract contract.
* @param rskTxHelper
* @param from the funded rsk address from which the contract will be deployed.
* @returns {Promise<*>} the deployed contract.
*/
const deployUnionBridgeContract = async (rskTxHelper, from) => {
const fullPath = path.resolve(__dirname, TEST_UNION_BRIDGE_CONTRACT);
const source = fs.readFileSync(fullPath).toString();

return await solUtils.compileAndDeploy(
SOLIDITY_COMPILER_VERSION,
source,
TEST_UNION_BRIDGE_CONTRACT_NAME,
[],
rskTxHelper,
{
from
}
);
}

module.exports = {
deployCallReleaseBtcContract,
deployUnionBridgeContract
};
Loading