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

Update token #14

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
7 changes: 7 additions & 0 deletions contracts/bridges/OriginalTokenBridgeUpgradable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ contract OriginalTokenBridgeUpgradable is TokenBridgeBaseUpgradable {
event ReceiveToken(address token, address to, uint amount);
event SetRemoteChainId(uint16 remoteChainId);
event RegisterToken(address token);
event DeregisterToken(address token);
event WithdrawFee(address indexed token, address to, uint amount);
event Paused(address account);
event Unpaused(address account);
Expand Down Expand Up @@ -64,6 +65,12 @@ contract OriginalTokenBridgeUpgradable is TokenBridgeBaseUpgradable {
emit RegisterToken(token);
}

function deregisterToken(address token) external onlyOwner {
require(supportedTokens[token], "OriginalTokenBridge: token is not registered");
supportedTokens[token] = false;
LDtoSDConversionRate[token] = 0;
emit DeregisterToken(token);
}
function setRemoteChainId(uint16 _remoteChainId) external onlyOwner {
remoteChainId = _remoteChainId;
emit SetRemoteChainId(_remoteChainId);
Expand Down
12 changes: 12 additions & 0 deletions contracts/bridges/WrappedTokenBridgeUpgradable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ contract WrappedTokenBridgeUpgradable is TokenBridgeBaseUpgradable {
emit RegisterToken(localToken, remoteChainId, remoteToken);
}

function updateToken(address localToken, uint16 remoteChainId, address remoteToken) external onlyOwner {
require(localToken != address(0), "WrappedTokenBridge: invalid local token");
require(remoteToken != address(0), "WrappedTokenBridge: invalid remote token");
require(localToRemote[localToken][remoteChainId] != address(0) && remoteToLocal[remoteToken][remoteChainId] == address(0), "WrappedTokenBridge: token not registered");
address oldRemoteToken = localToRemote[localToken][remoteChainId];
require(totalValueLocked[remoteChainId][oldRemoteToken] == 0, "WrappedTokenBridge: token has locked value");

localToRemote[localToken][remoteChainId] = remoteToken;
remoteToLocal[remoteToken][remoteChainId] = localToken;
emit RegisterToken(localToken, remoteChainId, remoteToken);
}

function setWithdrawalFeeBps(uint16 _withdrawalFeeBps) external onlyOwner {
require(_withdrawalFeeBps < TOTAL_BPS, "WrappedTokenBridge: invalid withdrawal fee bps");
withdrawalFeeBps = _withdrawalFeeBps;
Expand Down
19 changes: 19 additions & 0 deletions test/OriginalTokenBridge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,25 @@ describe("OriginalTokenBridge", () => {
})
})

describe("deregisterToken", () => {
beforeEach(async () => {
await originalTokenBridge.registerToken(originalToken.target, sharedDecimals)
})

it("reverts if token is not registered", async () => {
await expect(originalTokenBridge.deregisterToken(weth.target)).to.be.revertedWith("OriginalTokenBridge: token is not registered")
})

it("reverts when called by non owner", async () => {
await expect(originalTokenBridge.connect(user).deregisterToken(originalToken.target)).to.be.revertedWith("Ownable: caller is not the owner")
})

it("deregisters token", async () => {
await originalTokenBridge.deregisterToken(originalToken.target)
expect(await originalTokenBridge.supportedTokens(originalToken.target)).to.be.false
})
})

describe("setRemoteChainId", () => {
const newRemoteChainId = 2
it("reverts when called by non owner", async () => {
Expand Down
28 changes: 28 additions & 0 deletions test/WrappedTokenBridge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,34 @@ describe("WrappedTokenBridge", () => {
})
})

describe("updateToken", () => {
it("reverts when called by non owner", async () => {
await expect(wrappedTokenBridge.connect(user).updateToken(wrappedToken.target, originalTokenChainId, originalToken.target)).to.be.revertedWith("Ownable: caller is not the owner")
})

it("reverts when local token is address zero", async () => {
await expect(wrappedTokenBridge.updateToken(ZeroAddress, originalTokenChainId, originalToken.target)).to.be.revertedWith("WrappedTokenBridge: invalid local token")
})

it("reverts when remote token is address zero", async () => {
await expect(wrappedTokenBridge.updateToken(wrappedToken.target, originalTokenChainId, ZeroAddress)).to.be.revertedWith("WrappedTokenBridge: invalid remote token")
})

it("reverts if token isn't registered", async () => {
await expect(wrappedTokenBridge.updateToken(wrappedToken.target, originalTokenChainId, originalToken.target)).to.be.revertedWith("WrappedTokenBridge: token not registered")
})

it("updates tokens", async () => {
const ERC20Factory = await ethers.getContractFactory("MintableERC20Mock")
const originalToken2 = await ERC20Factory.deploy("TEST", "TEST")
await wrappedTokenBridge.registerToken(wrappedToken.target, originalTokenChainId, originalToken.target)
await wrappedTokenBridge.updateToken(wrappedToken.target, originalTokenChainId, originalToken2.target)

expect(await wrappedTokenBridge.localToRemote(wrappedToken.target, originalTokenChainId)).to.be.eq(originalToken2.target)
expect(await wrappedTokenBridge.remoteToLocal(originalToken2.target, originalTokenChainId)).to.be.eq(wrappedToken.target)
})
})

describe("setWithdrawalFeeBps", () => {
const withdrawalFeeBps = 10
it("reverts when fee bps is greater than or equal to 100%", async () => {
Expand Down