Skip to content

Commit

Permalink
returnXXX to releaseXXX
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik committed Jan 24, 2023
1 parent 6a650b1 commit 93aeaec
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 24 deletions.
6 changes: 3 additions & 3 deletions packages/protocol/contracts/bridge/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import "../common/EssentialContract.sol";
import "./IBridge.sol";
import "./libs/LibBridgeData.sol";
import "./libs/LibBridgeProcess.sol";
import "./libs/LibBridgeRelease.sol";
import "./libs/LibBridgeRetry.sol";
import "./libs/LibBridgeReturn.sol";
import "./libs/LibBridgeSend.sol";
import "./libs/LibBridgeStatus.sol";

Expand Down Expand Up @@ -66,12 +66,12 @@ contract Bridge is EssentialContract, IBridge {
});
}

function returnEther(
function releaseEther(
IBridge.Message calldata message,
bytes calldata proof
) external nonReentrant {
return
LibBridgeReturn.returnEther({
LibBridgeRelease.releaseEther({
state: state,
resolver: AddressResolver(this),
message: message,
Expand Down
10 changes: 5 additions & 5 deletions packages/protocol/contracts/bridge/EtherVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract EtherVault is EssentialContract {

event Authorized(address indexed addr, bool authorized);

event EtherTransferred(address indexed to, uint256 amount);
event EtherReleased(address indexed to, uint256 amount);

/*********************
* Modifiers *
Expand Down Expand Up @@ -69,9 +69,9 @@ contract EtherVault is EssentialContract {
* is authorized.
* @param amount Amount of ether to send.
*/
function returnEther(uint256 amount) public onlyAuthorized nonReentrant {
function releaseEther(uint256 amount) public onlyAuthorized nonReentrant {
msg.sender.sendEther(amount);
emit EtherTransferred(msg.sender, amount);
emit EtherReleased(msg.sender, amount);
}

/**
Expand All @@ -80,13 +80,13 @@ contract EtherVault is EssentialContract {
* @param recipient Address to receive Ether
* @param amount Amount of ether to send.
*/
function returnEtherTo(
function releaseEtherTo(
address recipient,
uint256 amount
) public onlyAuthorized nonReentrant {
require(recipient != address(0), "EV:recipient");
recipient.sendEther(amount);
emit EtherTransferred(recipient, amount);
emit EtherReleased(recipient, amount);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/bridge/IBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ interface IBridge {

// Release Ether with a proof that the message processing on the destination
// chain has been failed.
function returnEther(
function releaseEther(
IBridge.Message calldata message,
bytes calldata proof
) external;
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/bridge/TokenVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ contract TokenVault is EssentialContract {
* @param proof The proof from the destination chain to show the message
* has failed.
*/
function returnERC20(
function releaseERC20(
IBridge.Message calldata message,
bytes calldata proof
) external nonReentrant {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ library LibBridgeProcess {
// We retrieve the necessary ether from EtherVault
address ethVault = resolver.resolve("ether_vault", false);
if (ethVault != address(0)) {
EtherVault(payable(ethVault)).returnEther(
EtherVault(payable(ethVault)).releaseEther(
message.depositValue + message.callValue + message.processingFee
);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/protocol/contracts/bridge/libs/LibBridgeReturn.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import "./LibBridgeStatus.sol";
/**
* @author dantaik <[email protected]>
*/
library LibBridgeReturn {
library LibBridgeRelease {
using LibBridgeData for IBridge.Message;

event EtherReleased(bytes32 indexed msgHash, address to, uint256 amount);

function returnEther(
function releaseEther(
LibBridgeData.State storage state,
AddressResolver resolver,
IBridge.Message calldata message,
Expand Down Expand Up @@ -46,7 +46,7 @@ library LibBridgeReturn {
if (releaseAmount > 0) {
address ethVault = resolver.resolve("ether_vault", true);
if (ethVault != address(0)) {
EtherVault(payable(ethVault)).returnEtherTo(
EtherVault(payable(ethVault)).releaseEtherTo(
message.owner,
releaseAmount
);
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol/docs/bridge/EtherVault.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ receive() external payable
function init(address addressManager) external
```

### returnEther
### releaseEther

```solidity
function returnEther(uint256 amount) public
function releaseEther(uint256 amount) public
```

Send Ether from EtherVault to the sender, checking they are authorized.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("LibBridgeProcess", async function () {
`${blockChainId}.ether_vault`,
etherVault.address
);
// Sends initial value of 10 ether to EtherVault for returnEther calls
// Sends initial value of 10 ether to EtherVault for releaseEther calls
await owner.sendTransaction({
to: etherVault.address,
value: ethers.utils.parseEther("10.0"),
Expand Down
16 changes: 9 additions & 7 deletions packages/protocol/test/etherVault/EtherVault.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe("EtherVault", function () {
});
});

describe("returnEther()", async function () {
describe("releaseEther()", async function () {
it("throws if not enough ether to send", async () => {
const balance = await ethers.provider.getBalance(
etherVault.address
Expand All @@ -81,13 +81,13 @@ describe("EtherVault", function () {
await expect(
etherVault
.connect(authorized)
.returnEther(balance.add(additionalAmount))
.releaseEther(balance.add(additionalAmount))
).to.be.revertedWith("ETH transfer failed");
});

it("throws if not authorized", async () => {
await expect(
etherVault.connect(notAuthorized).returnEther(1)
etherVault.connect(notAuthorized).releaseEther(1)
).to.be.revertedWith("EV:denied");
});

Expand All @@ -97,7 +97,9 @@ describe("EtherVault", function () {
authorized.address
);

const tx = await etherVault.connect(authorized).returnEther(amount);
const tx = await etherVault
.connect(authorized)
.releaseEther(amount);
const receipt = await tx.wait();
const gasUsed = receipt.cumulativeGasUsed.mul(
receipt.effectiveGasPrice
Expand All @@ -111,11 +113,11 @@ describe("EtherVault", function () {
);
});

it("emits EtherTransferred event upon success", async () => {
it("emits EtherReleased event upon success", async () => {
const amount = 69;

await expect(etherVault.connect(authorized).returnEther(amount))
.to.emit(etherVault, "EtherTransferred")
await expect(etherVault.connect(authorized).releaseEther(amount))
.to.emit(etherVault, "EtherReleased")
.withArgs(authorized.address, amount);
});
});
Expand Down

0 comments on commit 93aeaec

Please sign in to comment.