Skip to content

Commit

Permalink
ready
Browse files Browse the repository at this point in the history
  • Loading branch information
TonioMacaronio committed Sep 12, 2019
1 parent b374182 commit ce719ac
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 17 deletions.
56 changes: 40 additions & 16 deletions contracts/test/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,28 @@ describe("INTEGRATION: Complete", function() {
let balanceToWithdraw2 = await franklinDeployedContract.balancesToWithdraw(wallet.address, 0);
expect(balanceToWithdraw2).equal(fullExitAmount);

// TODO: - Withdraw eth.
// const oldBalance = await exitWallet.getBalance();
// const exitTx = await franklinDeployedContract.withdrawETH(exitValue);
// const exitTxReceipt = await exitTx.wait();
// const gasUsed = exitTxReceipt.gasUsed.mul(await provider.getGasPrice());
// const newBalance = await exitWallet.getBalance();
// expect(newBalance.sub(oldBalance).add(gasUsed)).eq(exitValue);

// balanceToWithdraw = await franklinDeployedContract.balancesToWithdraw(exitWallet.address, 0);
// expect(balanceToWithdraw).equal(bigNumberify(0));
// Withdraw eth for wallet
const oldBalance2 = await wallet.getBalance();
const exitTx2 = await franklinDeployedContract.withdrawETH(balanceToWithdraw2);
const exitTxReceipt2 = await exitTx2.wait();
const gasUsed2 = exitTxReceipt2.gasUsed.mul(await provider.getGasPrice());
const newBalance2 = await wallet.getBalance();
expect(newBalance2.sub(oldBalance2).add(gasUsed2)).eq(balanceToWithdraw2);

balanceToWithdraw2 = await franklinDeployedContract.balancesToWithdraw(wallet.address, 0);
expect(balanceToWithdraw2).equal(bigNumberify(0));

// Withdraw eth for exitWallet
const exitWalletFranklinContract = franklinDeployedContract.connect(exitWallet);
const oldBalance1 = await exitWallet.getBalance();
const exitTx1 = await exitWalletFranklinContract.withdrawETH(balanceToWithdraw1, {gasLimit: bigNumberify("500000")});
const exitTxReceipt1 = await exitTx1.wait();
const gasUsed1 = exitTxReceipt1.gasUsed.mul(await provider.getGasPrice());
const newBalance1 = await exitWallet.getBalance();
expect(newBalance1.sub(oldBalance1).add(gasUsed1)).eq(balanceToWithdraw1);

balanceToWithdraw1 = await exitWalletFranklinContract.balancesToWithdraw(exitWallet.address, 0);
expect(balanceToWithdraw1).equal(bigNumberify(0));
});

it("ERC20 deposit, part exit, full exit, commit, verify, withdraw", async () => {
Expand Down Expand Up @@ -378,11 +390,23 @@ describe("INTEGRATION: Complete", function() {
let balanceToWithdraw2 = await franklinDeployedContract.balancesToWithdraw(wallet.address, 1);
expect(balanceToWithdraw2).equal(fullExitAmount);

// // TODO: - Withdraw erc20.
// const exitWalletFranklinContract = franklinDeployedContract.connect(exitWallet);
// const exitTx = await exitWalletFranklinContract.withdrawERC20(erc20DeployedToken.address, exitValue);
// const recp = await exitTx.wait();
// expect(await erc20DeployedToken.balanceOf(exitWallet.address)).eq(exitValue);
// expect((await franklinDeployedContract.balancesToWithdraw(exitWallet.address, 1)).balance).equal(bigNumberify(0));
// Withdraw erc20 for wallet
const oldBalance2 = await erc20DeployedToken.balanceOf(wallet.address);
const exitTx2 = await franklinDeployedContract.withdrawERC20(erc20DeployedToken.address, balanceToWithdraw2);
await exitTx2.wait();
const newBalance2 = await erc20DeployedToken.balanceOf(wallet.address);
expect(newBalance2.sub(oldBalance2)).eq(balanceToWithdraw2);
balanceToWithdraw2 = await franklinDeployedContract.balancesToWithdraw(wallet.address, 1);
expect(balanceToWithdraw2).equal(bigNumberify(0));

// Withdraw erc20 for exit wallet
const exitWalletFranklinContract = franklinDeployedContract.connect(exitWallet);
const oldBalance1 = await erc20DeployedToken.balanceOf(exitWallet.address);
const exitTx1 = await exitWalletFranklinContract.withdrawERC20(erc20DeployedToken.address, balanceToWithdraw1);
await exitTx1.wait();
const newBalance1 = await erc20DeployedToken.balanceOf(exitWallet.address);
expect(newBalance1.sub(oldBalance1)).eq(balanceToWithdraw1);
balanceToWithdraw1 = await exitWalletFranklinContract.balancesToWithdraw(exitWallet.address, 1);
expect(balanceToWithdraw1).equal(bigNumberify(0));
});
});
4 changes: 3 additions & 1 deletion docs/contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ If the block is reverted via Exodus Mode, the funds held by **Deposit priority r

### Fees for Priority Requests

In order to send priority request, the _user_ MUST pay some extra fee. That fee will be subtracted from the amount of Ether that the user sent to Deposit funciton in both cases of Ether and ERC-20 tokens deposits. That fee will be the payment for the _validator’s_ work to include these transactions in the block. One transaction fee is calculated as follows:
In order to send priority request, the _user_ MUST pay some extra fee. That fee will be subtracted from the amount of Ether that the user sent to Deposit or Full Exit funcitons. That fee will be the payment for the _validator’s_ work to include these transactions in the block. One transaction fee is calculated as follows:
`fee = FEE_COEFF * (BASE_GAS + gasleft) * gasprice`, where
- `FEE_COEFF` - fee coefficient for priority request transaction
- `BASE_GAS` - base gas cost for transaction (usually 21000)
- `gasleft` - remaining gas for transaction code execution
- `gasprice` - gas price of the transaction

If the user sends more Ether than necessary, the difference will be returned to him.

### **Validators'** responsibility

**Validators** MUST subscribe for `NewPriorityRequest` events in the RIGHT order to include priority transactions in some upcoming blocks.
Expand Down

0 comments on commit ce719ac

Please sign in to comment.