Skip to content
This repository has been archived by the owner on Dec 5, 2021. It is now read-only.

Commit

Permalink
Integrate #37, confirm compilation and function
Browse files Browse the repository at this point in the history
  • Loading branch information
CAPtheorem committed Jun 3, 2021
1 parent 1cf7ee7 commit 2c9bf82
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 29 deletions.
58 changes: 45 additions & 13 deletions packages/omgx/wallet/contracts/LP/L1LiquidityPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -508,20 +508,52 @@ contract L1LiquidityPool is OVM_CrossDomainEnabled, Ownable {
external
onlyFromCrossDomainAccount(address(L2LiquidityPoolAddress))
{
bool replyNeeded = false;

if (_tokenAddress != address(0)) {
IERC20(_tokenAddress).safeTransfer(_to, _amount);
//IERC20(_tokenAddress).safeTransfer(_to, _amount);
if (_amount > IERC20(_tokenAddress).balanceOf(address(this))) {
replyNeeded = true;
} else {
IERC20(_tokenAddress).safeTransfer(_to, _amount);
}
} else {
//this is ETH
// balances[address(0)] = balances[address(0)].sub(_amount);
//_to.transfer(_amount); UNSAFE
(bool sent,) = _to.call{gas: SAFE_GAS_STIPEND, value: _amount}("");
require(sent, "Failed to send Ether");
}

emit ClientPayL1(
_to,
_amount,
_tokenAddress
);
// //this is ETH
// // balances[address(0)] = balances[address(0)].sub(_amount);
// //_to.transfer(_amount); UNSAFE
// (bool sent,) = _to.call{gas: SAFE_GAS_STIPEND, value: _amount}("");
// require(sent, "Failed to send Ether");
if (_amount > address(this).balance) {
replyNeeded = true;
} else {
//this is ETH
// balances[address(0)] = balances[address(0)].sub(_amount);
//_to.transfer(_amount); UNSAFE
(bool sent,) = _to.call{gas: SAFE_GAS_STIPEND, value: _amount}("");
require(sent, "Failed to send Ether");
}
}

if (replyNeeded) {
// send cross domain message
bytes memory data = abi.encodeWithSelector(
iL2LiquidityPool.clientPayL2.selector,
_to,
_amount,
poolInfo[_tokenAddress].l2TokenAddress
);

sendCrossDomainMessage(
address(L2LiquidityPoolAddress),
data,
getFinalizeDepositL2Gas()
);
} else {
emit ClientPayL1(
_to,
_amount,
_tokenAddress
);
}
}
}
16 changes: 8 additions & 8 deletions packages/omgx/wallet/deployment/local/addresses.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"L1LiquidityPool": "0x8198f5d8F8CfFE8f9C413d98a0A55aEB8ab9FbB7",
"L2LiquidityPool": "0x998abeb3E57409262aE5b751f60747921B33613E",
"L1ERC20": "0x202CCe504e04bEd6fC0521238dDf04Bc9E8E15aB",
"L2DepositedERC20": "0x4826533B4897376654Bb4d4AD88B7faFD0C98528",
"L1ERC20Gateway": "0xf4B146FbA71F41E0592668ffbF264F1D186b2Ca8",
"L1LiquidityPool": "0x86A2EE8FAf9A840F7a2c64CA3d51209F9A02081D",
"L2LiquidityPool": "0x922D6956C99E12DFeB3224DEA977D0939758A1Fe",
"L1ERC20": "0xf953b3A269d80e3eB0F2947630Da976B896A8C5b",
"L2DepositedERC20": "0x1fA02b2d6A771842690194Cf62D91bdd92BfE28d",
"L1ERC20Gateway": "0xAA292E8611aDF267e563f334Ee42320aC96D0463",
"l1ETHGatewayAddress": "0x998abeb3E57409262aE5b751f60747921B33613E",
"l1MessengerAddress": "0x59b670e9fA9D0A427751Af201D676719a970857b",
"L2TokenPool": "0x172076E0166D1F9Cc711C77Adf8488051744980C",
"AtomicSwap": "0xBEc49fA140aCaA83533fB00A2BB19bDdd0290f25",
"L2ERC721": "0xc351628EB244ec633d5f21fBD6621e1a683B1181"
"L2TokenPool": "0x5c74c94173F05dA1720953407cbb920F3DF9f887",
"AtomicSwap": "0xe8D2A1E88c91DCd5433208d4152Cc4F399a7e91d",
"L2ERC721": "0xfbC22278A96299D91d41C453234d97b4F5Eb9B2d"
}
32 changes: 32 additions & 0 deletions packages/omgx/wallet/test/c_lp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,4 +492,36 @@ describe('Liquidity Pool Test', async () => {
postPoolInfo.accOwnerReward.sub(depositAmount.mul(15).div(1000))
)
})

it("should revert unfulfillable swaps", async () => {

const preBobL2ERC20Balance = await L2DepositedERC20.balanceOf(env.bobl2Wallet.address)
const preBobL1ERC20Balance = await L1ERC20.balanceOf(env.bobl1Wallet.address)
const requestedLiquidity = (await L1ERC20.balanceOf(L1LiquidityPool.address)).add(1)
const fastExitAmount = requestedLiquidity.mul(1000).div(950)

const approveBobL2TX = await L2DepositedERC20.connect(env.bobl2Wallet).approve(
L2LiquidityPool.address,
fastExitAmount,
{gasLimit: 800000, gasPrice: 0}
)
await approveBobL2TX.wait()

await env.waitForRevertXDomainTransaction(
L2LiquidityPool.connect(env.bobl2Wallet).clientDepositL2(
fastExitAmount,
L2DepositedERC20.address,
{gasLimit: 800000, gasPrice: 0}
),
Direction.L2ToL1
)

const postBobL1ERC20Balance = await L1ERC20.balanceOf(env.bobl1Wallet.address)
const postBobL2ERC20Balance = await L2DepositedERC20.balanceOf(env.bobl2Wallet.address)

expect(preBobL1ERC20Balance).to.deep.eq(postBobL1ERC20Balance)

const exitFees = fastExitAmount.mul(50).div(1000)
expect(postBobL2ERC20Balance).to.deep.eq(preBobL2ERC20Balance.sub(exitFees))
})
})
9 changes: 9 additions & 0 deletions packages/omgx/wallet/test/shared/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,13 @@ export class OptimismEnv {
): Promise<CrossDomainMessagePair> {
return waitForXDomainTransaction(this.watcher, tx, direction)
}

async waitForRevertXDomainTransaction(
tx: Promise<TransactionResponse> | TransactionResponse,
direction: Direction
) {
const {remoteReceipt} = await waitForXDomainTransaction(this.watcher, tx, direction)
const [xDomainMsgHash] = await this.watcher.getMessageHashesFromL1Tx(remoteReceipt.transactionHash)
await this.watcher.getL2TransactionReceipt(xDomainMsgHash)
}
}
16 changes: 8 additions & 8 deletions packages/omgx/wallet/wallet/src/deployment/local/addresses.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"L1LiquidityPool": "0x8198f5d8F8CfFE8f9C413d98a0A55aEB8ab9FbB7",
"L2LiquidityPool": "0x998abeb3E57409262aE5b751f60747921B33613E",
"L1ERC20": "0x202CCe504e04bEd6fC0521238dDf04Bc9E8E15aB",
"L2DepositedERC20": "0x4826533B4897376654Bb4d4AD88B7faFD0C98528",
"L1ERC20Gateway": "0xf4B146FbA71F41E0592668ffbF264F1D186b2Ca8",
"L1LiquidityPool": "0x86A2EE8FAf9A840F7a2c64CA3d51209F9A02081D",
"L2LiquidityPool": "0x922D6956C99E12DFeB3224DEA977D0939758A1Fe",
"L1ERC20": "0xf953b3A269d80e3eB0F2947630Da976B896A8C5b",
"L2DepositedERC20": "0x1fA02b2d6A771842690194Cf62D91bdd92BfE28d",
"L1ERC20Gateway": "0xAA292E8611aDF267e563f334Ee42320aC96D0463",
"l1ETHGatewayAddress": "0x998abeb3E57409262aE5b751f60747921B33613E",
"l1MessengerAddress": "0x59b670e9fA9D0A427751Af201D676719a970857b",
"L2TokenPool": "0x172076E0166D1F9Cc711C77Adf8488051744980C",
"AtomicSwap": "0xBEc49fA140aCaA83533fB00A2BB19bDdd0290f25",
"L2ERC721": "0xc351628EB244ec633d5f21fBD6621e1a683B1181"
"L2TokenPool": "0x5c74c94173F05dA1720953407cbb920F3DF9f887",
"AtomicSwap": "0xe8D2A1E88c91DCd5433208d4152Cc4F399a7e91d",
"L2ERC721": "0xfbC22278A96299D91d41C453234d97b4F5Eb9B2d"
}

0 comments on commit 2c9bf82

Please sign in to comment.