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 #7

Open
wants to merge 2 commits into
base: upgradable2
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
12 changes: 12 additions & 0 deletions contracts/WrappedTokenBridgeUpgradable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,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);
Copy link
Member

Choose a reason for hiding this comment

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

How those events are used?
do we need UneegisterToken event?

}

function setWithdrawalFeeBps(uint16 _withdrawalFeeBps) external onlyOwner {
require(_withdrawalFeeBps < TOTAL_BPS, "WrappedTokenBridge: invalid withdrawal fee bps");
withdrawalFeeBps = _withdrawalFeeBps;
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 when token has locked value", async () => {
await wrappedTokenBridge.registerToken(wrappedToken.target, originalTokenChainId, originalToken.target)
await wrappedTokenBridge.simulateNonblockingLzReceive(originalTokenChainId, createPayload())
await expect(wrappedTokenBridge.updateToken(wrappedToken.target, originalTokenChainId, originalToken.target)).to.be.revertedWith("WrappedTokenBridge: token has locked value")
})

it("updates token", async () => {
await wrappedTokenBridge.registerToken(wrappedToken.target, originalTokenChainId, originalToken.target)
await wrappedTokenBridge.updateToken(wrappedToken.target, originalTokenChainId, originalToken.target)

expect(await wrappedTokenBridge.localToRemote(wrappedToken.target, originalTokenChainId)).to.be.eq(originalToken.target)
expect(await wrappedTokenBridge.remoteToLocal(originalToken.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
Loading