Move Router and XAppConnectionClient to core (#195)

pull/206/head
Asa Oines 3 years ago committed by GitHub
parent f022a770a3
commit 8be12f9eb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      package.json
  2. 12
      solidity/abacus-core/contracts/ValidatorManager.sol
  3. 4
      solidity/abacus-core/contracts/XAppConnectionManager.sol
  4. 3
      solidity/abacus-core/contracts/router/Router.sol
  5. 5
      solidity/abacus-core/contracts/router/XAppConnectionClient.sol
  6. 2
      solidity/abacus-core/test/inbox.test.ts
  7. 9
      solidity/abacus-core/test/lib/AbacusDeployment.ts
  8. 2
      solidity/abacus-core/test/validatorManager.test.ts
  9. 4
      solidity/abacus-core/test/xAppConnectionManager.test.ts
  10. 6
      solidity/abacus-xapps/contracts/bridge/BridgeRouter.sol
  11. 2
      solidity/abacus-xapps/contracts/bridge/TokenRegistry.sol
  12. 2
      solidity/abacus-xapps/contracts/governance/GovernanceRouter.sol
  13. 4
      solidity/abacus-xapps/contracts/ping-pong/PingPongRouter.sol
  14. 4
      solidity/abacus-xapps/contracts/xapp-template/RouterTemplate.sol
  15. 2
      solidity/abacus-xapps/test/bridge/bridge.test.ts
  16. 2
      typescript/abacus-deploy/src/core/govern.ts
  17. 8
      typescript/abacus-deploy/src/core/index.ts

@ -2,6 +2,7 @@
"name": "@abacus-network/monorepo",
"scripts": {
"build": "npm run build --workspaces",
"test": "npm run test --workspaces",
"prettier": "npm run prettier --workspaces"
},
"workspaces": [

@ -21,11 +21,11 @@ contract ValidatorManager is IValidatorManager, Ownable {
// ============ Events ============
/**
* @notice Emitted when a validator is set
* @param domain The domain for which the validator is being set
* @notice Emitted when a validator is enrolled
* @param domain The domain for which the validator is being enrolled
* @param validator The address of the validator
*/
event NewValidator(uint32 indexed domain, address indexed validator);
event ValidatorEnrolled(uint32 indexed domain, address indexed validator);
/**
* @notice Emitted when proof of an improper checkpoint is submitted,
@ -50,17 +50,17 @@ contract ValidatorManager is IValidatorManager, Ownable {
// ============ External Functions ============
/**
* @notice Set the address of a new validator
* @notice Enroll a validator for the given domain
* @dev only callable by trusted owner
* @param _domain The domain for which the validator is being set
* @param _validator The address of the validator
*/
function setValidator(uint32 _domain, address _validator)
function enrollValidator(uint32 _domain, address _validator)
external
onlyOwner
{
validators[_domain] = _validator;
emit NewValidator(_domain, _validator);
emit ValidatorEnrolled(_domain, _validator);
}
/**

@ -65,10 +65,10 @@ contract XAppConnectionManager is Ownable {
/**
* @notice Allow Owner to enroll Inbox contract
* @param _inbox the address of the Inbox
* @param _domain the remote domain of the Outbox contract for the Inbox
* @param _inbox the address of the Inbox
*/
function enrollInbox(address _inbox, uint32 _domain) external onlyOwner {
function enrollInbox(uint32 _domain, address _inbox) external onlyOwner {
// un-enroll any existing inbox
_unenrollInbox(_inbox);
// add inbox and domain to two-way mapping

@ -3,8 +3,7 @@ pragma solidity >=0.6.11;
// ============ Internal Imports ============
import {XAppConnectionClient} from "./XAppConnectionClient.sol";
// ============ External Imports ============
import {IMessageRecipient} from "@abacus-network/abacus-sol/interfaces/IMessageRecipient.sol";
import {IMessageRecipient} from "../../interfaces/IMessageRecipient.sol";
abstract contract Router is XAppConnectionClient, IMessageRecipient {
// ============ Mutable Storage ============

@ -1,9 +1,10 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
// ============ Internal Imports ============
import {Outbox} from "../Outbox.sol";
import {XAppConnectionManager} from "../XAppConnectionManager.sol";
// ============ External Imports ============
import {Outbox} from "@abacus-network/abacus-sol/contracts/Outbox.sol";
import {XAppConnectionManager} from "@abacus-network/abacus-sol/contracts/XAppConnectionManager.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
abstract contract XAppConnectionClient is OwnableUpgradeable {

@ -51,7 +51,7 @@ describe('Inbox', async () => {
fakeValidator = await Validator.fromSigner(fakeSigner, remoteDomain);
const validatorManagerFactory = new ValidatorManager__factory(signer);
validatorManager = await validatorManagerFactory.deploy();
await validatorManager.setValidator(remoteDomain, validator.address);
await validatorManager.enrollValidator(remoteDomain, validator.address);
});
beforeEach(async () => {

@ -58,10 +58,13 @@ export class AbacusDeployment {
): Promise<AbacusInstance> {
const validatorManagerFactory = new ValidatorManager__factory(signer);
const validatorManager = await validatorManagerFactory.deploy();
await validatorManager.setValidator(local, await signer.getAddress());
await validatorManager.enrollValidator(local, await signer.getAddress());
await Promise.all(
remotes.map(async (remoteDomain) =>
validatorManager.setValidator(remoteDomain, await signer.getAddress()),
validatorManager.enrollValidator(
remoteDomain,
await signer.getAddress(),
),
),
);
@ -86,7 +89,7 @@ export class AbacusDeployment {
ethers.constants.HashZero,
0,
);
await connectionManager.enrollInbox(inbox.address, remoteDomain);
await connectionManager.enrollInbox(remoteDomain, inbox.address);
inboxs[remoteDomain] = inbox;
});
await Promise.all(deploys);

@ -31,7 +31,7 @@ describe('ValidatorManager', async () => {
beforeEach(async () => {
const validatorManagerFactory = new ValidatorManager__factory(signer);
validatorManager = await validatorManagerFactory.deploy();
await validatorManager.setValidator(localDomain, validator.address);
await validatorManager.enrollValidator(localDomain, validator.address);
});
it('Accepts validator signature', async () => {

@ -52,7 +52,7 @@ describe('XAppConnectionManager', async () => {
const connectionManagerFactory = new XAppConnectionManager__factory(signer);
connectionManager = await connectionManagerFactory.deploy();
await connectionManager.setOutbox(outbox.address);
await connectionManager.enrollInbox(enrolledInbox.address, remoteDomain);
await connectionManager.enrollInbox(remoteDomain, enrolledInbox.address);
});
it('Returns the local domain', async () => {
@ -94,7 +94,7 @@ describe('XAppConnectionManager', async () => {
expect(await connectionManager.isInbox(newInbox.address)).to.be.false;
await expect(
connectionManager.enrollInbox(newInbox.address, newRemoteDomain),
connectionManager.enrollInbox(newRemoteDomain, newInbox.address),
).to.emit(connectionManager, 'InboxEnrolled');
expect(await connectionManager.domainToInbox(newRemoteDomain)).to.equal(

@ -3,11 +3,11 @@ pragma solidity >=0.6.11;
// ============ Internal Imports ============
import {TokenRegistry} from "./TokenRegistry.sol";
import {Router} from "../Router.sol";
import {XAppConnectionClient} from "../XAppConnectionClient.sol";
import {IBridgeToken} from "../../interfaces/bridge/IBridgeToken.sol";
import {BridgeMessage} from "./BridgeMessage.sol";
import {IBridgeToken} from "../../interfaces/bridge/IBridgeToken.sol";
// ============ External Imports ============
import {Router} from "@abacus-network/abacus-sol/contracts/router/Router.sol";
import {XAppConnectionClient} from "@abacus-network/abacus-sol/contracts/router/XAppConnectionClient.sol";
import {Outbox} from "@abacus-network/abacus-sol/contracts/Outbox.sol";
import {Version0} from "@abacus-network/abacus-sol/contracts/Version0.sol";
import {TypeCasts} from "@abacus-network/abacus-sol/contracts/XAppConnectionManager.sol";

@ -5,8 +5,8 @@ pragma solidity >=0.6.11;
import {BridgeMessage} from "./BridgeMessage.sol";
import {Encoding} from "./Encoding.sol";
import {IBridgeToken} from "../../interfaces/bridge/IBridgeToken.sol";
import {XAppConnectionClient} from "../XAppConnectionClient.sol";
// ============ External Imports ============
import {XAppConnectionClient} from "@abacus-network/abacus-sol/contracts/router/XAppConnectionClient.sol";
import {TypeCasts} from "@abacus-network/abacus-sol/contracts/XAppConnectionManager.sol";
import {UpgradeBeaconProxy} from "@abacus-network/abacus-sol/contracts/upgrade/UpgradeBeaconProxy.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

@ -3,10 +3,10 @@ pragma solidity >=0.6.11;
pragma experimental ABIEncoderV2;
// ============ Internal Imports ============
import {Router} from "../Router.sol";
import {GovernanceMessage} from "./GovernanceMessage.sol";
// ============ External Imports ============
import {Version0} from "@abacus-network/abacus-sol/contracts/Version0.sol";
import {Router} from "@abacus-network/abacus-sol/contracts/router/Router.sol";
import {TypeCasts} from "@abacus-network/abacus-sol/contracts/XAppConnectionManager.sol";
import {Initializable} from "@openzeppelin/contracts/proxy/Initializable.sol";
import {SafeMath} from "@openzeppelin/contracts/math/SafeMath.sol";

@ -3,10 +3,10 @@ pragma solidity >=0.6.11;
// ============ External Imports ============
import {TypedMemView} from "@summa-tx/memview-sol/contracts/TypedMemView.sol";
import {Router} from "@abacus-network/abacus-sol/contracts/router/Router.sol";
import {XAppConnectionClient} from "@abacus-network/abacus-sol/contracts/router/XAppConnectionClient.sol";
// ============ Internal Imports ============
import {PingPongMessage} from "./PingPongMessage.sol";
import {Router} from "../Router.sol";
import {XAppConnectionClient} from "../XAppConnectionClient.sol";
/*
============ PingPong xApp ============

@ -3,10 +3,10 @@ pragma solidity >=0.6.11;
// ============ External Imports ============
import {TypedMemView} from "@summa-tx/memview-sol/contracts/TypedMemView.sol";
import {Router} from "@abacus-network/abacus-sol/contracts/router/Router.sol";
import {XAppConnectionClient} from "@abacus-network/abacus-sol/contracts/router/XAppConnectionClient.sol";
// ============ Internal Imports ============
import {Message} from "./MessageTemplate.sol";
import {Router} from "../Router.sol";
import {XAppConnectionClient} from "../XAppConnectionClient.sol";
/*
============ Overview: Building a xApp ============

@ -39,7 +39,7 @@ describe('BridgeRouter', async () => {
// local router.
await abacus
.connectionManager(localDomain)
.enrollInbox(deployer.address, remoteDomain);
.enrollInbox(remoteDomain, deployer.address);
});
beforeEach(async () => {

@ -73,7 +73,7 @@ export class GovernanceCallBatchBuilder {
const deploy = this.getDeploy(domain);
const manager = deploy.contracts.validatorManager;
expect(manager).to.not.be.undefined;
const tx = await manager!.populateTransaction.setValidator(
const tx = await manager!.populateTransaction.enrollValidator(
violation.remote,
violation.expected,
);

@ -229,9 +229,9 @@ export async function deployAbacus(deploy: CoreDeploy) {
log(
isTestDeploy,
`${deploy.chain.name}: awaiting validatorManager.setValidator(...);`,
`${deploy.chain.name}: awaiting validatorManager.enrollValidator(...);`,
);
await deploy.contracts.validatorManager!.setValidator(
await deploy.contracts.validatorManager!.enrollValidator(
deploy.chain.domain,
deploy.validator,
deploy.overrides,
@ -316,8 +316,8 @@ export async function enrollInbox(local: CoreDeploy, remote: CoreDeploy) {
log(isTestDeploy, `${local.chain.name}: starting inbox enrollment`);
let tx = await local.contracts.xAppConnectionManager!.enrollInbox(
local.contracts.inboxes[remote.chain.domain].proxy.address,
remote.chain.domain,
local.contracts.inboxes[remote.chain.domain].proxy.address,
local.overrides,
);
await tx.wait(local.chain.confirmations);
@ -362,7 +362,7 @@ export async function enrollValidator(local: CoreDeploy, remote: CoreDeploy) {
const isTestDeploy = local.test;
log(isTestDeploy, `${local.chain.name}: starting validator enrollment`);
let tx = await local.contracts.validatorManager!.setValidator(
let tx = await local.contracts.validatorManager!.enrollValidator(
remote.chain.domain,
remote.validator,
local.overrides,

Loading…
Cancel
Save