Skip to content

Commit

Permalink
fix: resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
GitGuru7 committed Nov 8, 2023
1 parent 15bd3cb commit aba9539
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
8 changes: 8 additions & 0 deletions contracts/Bridge/BaseXVSProxyOFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ abstract contract BaseXVSProxyOFT is Pausable, ExponentialNoError, BaseOFTV2 {
* @notice Event emitted when trusted remote sets to empty.
*/
event TrustedRemoteRemoved(uint16 chainId);
/**
* @notice Event emitted when inner token set successfully.
*/
event InnerTokenAdded(address indexed innerToken);

/**
* @param tokenAddress_ Address of the inner token.
Expand Down Expand Up @@ -122,6 +126,10 @@ abstract contract BaseXVSProxyOFT is Pausable, ExponentialNoError, BaseOFTV2 {
ld2sdRate = 10 ** (decimals - sharedDecimals_);

ensureNonzeroAddress(oracle_);

emit InnerTokenAdded(tokenAddress_);
emit OracleChanged(address(0), oracle_);

oracle = ResilientOracleInterface(oracle_);
}

Expand Down
22 changes: 11 additions & 11 deletions contracts/Bridge/XVSBridgeAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract XVSBridgeAdmin is AccessControlledV8 {
mapping(bytes4 => string) public functionRegistry;

// Event emitted when function registry updated
event FunctionRegistryChanged(string signature, bool isRemoved);
event FunctionRegistryChanged(string signature, bool active);

/// @custom:oz-upgrades-unsafe-allow constructor
constructor(address XVSBridge_) {
Expand Down Expand Up @@ -66,21 +66,21 @@ contract XVSBridgeAdmin is AccessControlledV8 {
}

/**
* @notice Function to update the function registry.
* @param signatures_ Array of function names string.
* @param remove_ Boolean to specify whether to remove the function from registry mapping.
* @custom:access Only owner.
* @notice A registry of functions that are allowed to be executed from proposals
* @param signatures_ Function signature to be added or removed.
* @param active_ bool value, should be true to add function.
*/
function upsertSignature(string[] calldata signatures_, bool[] calldata remove_) external onlyOwner {
function upsertSignature(string[] calldata signatures_, bool[] calldata active_) external onlyOwner {
uint256 signatureLength = signatures_.length;
require(signatureLength == remove_.length, "Input arrays must have the same length");
require(signatureLength == active_.length, "Input arrays must have the same length");
for (uint256 i; i < signatureLength; i++) {
bytes4 sigHash = bytes4(keccak256(bytes(signatures_[i])));
if (remove_[i]) {
delete functionRegistry[sigHash];
emit FunctionRegistryChanged(signatures_[i], true);
} else {
bytes memory signature = bytes(functionRegistry[sigHash]);
if (active_[i] && signature.length == 0) {
functionRegistry[sigHash] = signatures_[i];
emit FunctionRegistryChanged(signatures_[i], true);
} else if (!active_[i] && signature.length != 0) {
delete functionRegistry[sigHash];
emit FunctionRegistryChanged(signatures_[i], false);
}
}
Expand Down
10 changes: 5 additions & 5 deletions test/bridgeAdmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ describe("Bridge Admin: ", function () {
"setPayloadSizeLimit(uint16,uint256)",
"setUseCustomAdapterParams(bool)",
];
const removeArray = new Array(functionregistry.length).fill(false);
await bridgeAdmin.upsertSignature(functionregistry, removeArray);
const activeArray = new Array(functionregistry.length).fill(true);
await bridgeAdmin.upsertSignature(functionregistry, activeArray);
await loadFixture(grantPermissionsFixture);
});

Expand All @@ -115,7 +115,7 @@ describe("Bridge Admin: ", function () {
);
});

it("Revert if permisssions are not granted to call owner functions of bridge", async function () {
it("Revert if permissions are not granted to call owner functions of bridge", async function () {
let data = remoteOFT.interface.encodeFunctionData("setTrustedRemote", [localChainId, remotePath]);
await expect(
acc1.sendTransaction({
Expand Down Expand Up @@ -163,7 +163,7 @@ describe("Bridge Admin: ", function () {
).to.revertedWithCustomError(bridgeAdmin, "Unauthorized");
});

it("Success if permisssions are granted to call owner functions of bridge", async function () {
it("Success if permissions are granted to call owner functions of bridge", async function () {
let data = remoteOFT.interface.encodeFunctionData("setMaxDailyLimit", [localChainId, maxDailyTransactionLimit]);
await acc2.sendTransaction({
to: bridgeAdmin.address,
Expand Down Expand Up @@ -196,7 +196,7 @@ describe("Bridge Admin: ", function () {
});

it("Revert if function is removed from function registry", async function () {
await bridgeAdmin.upsertSignature(["setMaxDailyReceiveLimit(uint16,uint256)"], [true]);
await bridgeAdmin.upsertSignature(["setMaxDailyReceiveLimit(uint16,uint256)"], [false]);
const data = remoteOFT.interface.encodeFunctionData("setMaxDailyReceiveLimit", [
localChainId,
maxDailyTransactionLimit,
Expand Down
18 changes: 9 additions & 9 deletions test/proxyOFT.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FakeContract, smock } from "@defi-wonderland/smock";
import { time } from "@nomicfoundation/hardhat-network-helpers";
import { loadFixture, time } from "@nomicfoundation/hardhat-network-helpers";
import { expect } from "chai";
import { ethers, upgrades } from "hardhat";
import { SignerWithAddress } from "hardhat-deploy-ethers/signers";
Expand Down Expand Up @@ -50,8 +50,7 @@ describe("Proxy OFTV2: ", function () {
accessControlManager: FakeContract<AccessControlManager>,
oracle: FakeContract<ResilientOracleInterface>,
defaultAdapterParams: any;

before(async function () {
const bridgeFixture = async () => {
LZEndpointMock = await ethers.getContractFactory("LZEndpointMock");
ProxyOFTV2Src = await ethers.getContractFactory("XVSProxyOFTSrc");
ProxyOFTV2Dest = await ethers.getContractFactory("XVSProxyOFTDest");
Expand All @@ -65,9 +64,7 @@ describe("Proxy OFTV2: ", function () {
oracle = await smock.fake<ResilientOracleInterface>("ResilientOracleInterface");
oracle.getPrice.returns(convertToUnit(1, 18));
defaultAdapterParams = ethers.utils.solidityPack(["uint16", "uint256"], [1, 200000]);
});

beforeEach(async function () {
localEndpoint = await LZEndpointMock.deploy(localChainId);
remoteEndpoint = await LZEndpointMock.deploy(remoteChainId);

Expand Down Expand Up @@ -95,7 +92,6 @@ describe("Proxy OFTV2: ", function () {
initializer: "initialize",
});
await bridgeAdminLocal.deployed();

await remoteOFT.transferOwnership(bridgeAdminRemote.address);
await localOFT.transferOwnership(bridgeAdminLocal.address);
// internal bookkeeping for endpoints (not part of a real deploy, just for this test)
Expand Down Expand Up @@ -137,9 +133,9 @@ describe("Proxy OFTV2: ", function () {
"setUseCustomAdapterParams(bool)",
"removeTrustedRemote(uint16)",
];
const removeArray = new Array(functionregistry.length).fill(false);
await bridgeAdminRemote.upsertSignature(functionregistry, removeArray);
await bridgeAdminLocal.upsertSignature(functionregistry, removeArray);
const activeArray = new Array(functionregistry.length).fill(true);
await bridgeAdminRemote.upsertSignature(functionregistry, activeArray);
await bridgeAdminLocal.upsertSignature(functionregistry, activeArray);

// Setting local chain
await bridgeAdminLocal.setTrustedRemoteAddress(remoteChainId, remoteOFT.address);
Expand Down Expand Up @@ -215,6 +211,10 @@ describe("Proxy OFTV2: ", function () {
to: bridgeAdminRemote.address,
data: data,
});
};

beforeEach(async function () {
await loadFixture(bridgeFixture);
});

it("send tokens from proxy oft and receive them back", async function () {
Expand Down

0 comments on commit aba9539

Please sign in to comment.