Skip to content

Commit

Permalink
Add CurvePool for stETH to ETH selling
Browse files Browse the repository at this point in the history
  • Loading branch information
elenadimitrova committed Mar 15, 2021
1 parent 7d53386 commit 9b60db7
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 6 deletions.
33 changes: 33 additions & 0 deletions contracts/infrastructure/dapp/CurveFilter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (C) 2021 Argent Labs Ltd. <https://argent.xyz>

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.s

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.6.12;

import "./BaseFilter.sol";

contract CurveFilter is BaseFilter {
bytes4 private constant EXCHANGE = bytes4(keccak256("exchange(int128,int128,uint256,uint256)"));

function isValid(address /*_wallet*/, address _spender, address _to, bytes calldata _data) external view override returns (bool) {
if (_data.length < 4) {
return false;
}
if(_spender == _to) {
bytes4 methodId = getMethod(_data);
return (methodId == EXCHANGE);
}
}
}
4 changes: 1 addition & 3 deletions contracts/infrastructure/dapp/LidoFilter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ contract LidoFilter is BaseFilter {
}
if(_spender == _to && _data.length >= 4) {
bytes4 methodId = getMethod(_data);
if (methodId == SUBMIT) {
return true;
}
return (methodId == SUBMIT);
}
}
}
52 changes: 49 additions & 3 deletions test-integration/filter-lido.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const GuardianStorage = artifacts.require("GuardianStorage");
const ArgentModule = artifacts.require("ArgentModule");
const DappRegistry = artifacts.require("DappRegistry");
const LidoFilter = artifacts.require("LidoFilter");
const CurveFilter = artifacts.require("CurveFilter");
const ILido = artifacts.require("ILido");
const ICurvePool = artifacts.require("ICurvePool");

// UniswapV2
const UniswapV2Factory = artifacts.require("UniswapV2FactoryMock");
Expand Down Expand Up @@ -48,15 +50,18 @@ contract("Lido Filter", (accounts) => {
let module;
let wallet;
let walletImplementation;
let filter;
let lidoFilter;
let curveFilter;
let dappRegistry;
let uniswapRouter;

let lido;
let curve;

before(async () => {
// Lido contract on mainnet
lido = await ILido.at("0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84");
curve = await ICurvePool.at("0xdc24316b9ae028f1497c275eb9192a3ea0f67022");

const uniswapFactory = await UniswapV2Factory.new(ZERO_ADDRESS);
const weth = await WETH.new();
Expand All @@ -78,8 +83,10 @@ contract("Lido Filter", (accounts) => {
RECOVERY_PERIOD,
LOCK_PERIOD);
await registry.registerModule(module.address, ethers.utils.formatBytes32String("ArgentModule"));
filter = await LidoFilter.new();
await dappRegistry.addDapp(0, lido.address, filter.address);
lidoFilter = await LidoFilter.new();
curveFilter = await CurveFilter.new();
await dappRegistry.addDapp(0, lido.address, lidoFilter.address);
await dappRegistry.addDapp(0, curve.address, curveFilter.address);
await dappRegistry.addDapp(0, relayer, ZERO_ADDRESS);
walletImplementation = await BaseWallet.new();
manager = new RelayManager(guardianStorage.address, ZERO_ADDRESS);
Expand Down Expand Up @@ -158,4 +165,43 @@ contract("Lido Filter", (accounts) => {
assert.equal(error, "TM: call not authorised");
});
});

describe("Selling via CurvePool", () => {
beforeEach(async () => {
// Stake some funds to use to test selling
const data = lido.contract.methods.submit(accounts[5]).encodeABI();
const transaction = encodeTransaction(lido.address, 100, data);

await manager.relay(
module,
"multiCall",
[wallet.address, [transaction]],
wallet,
[owner],
1,
ETH_TOKEN,
relayer);
});

it("should allow selling stETH via Curve", async () => {
const data = curve.contract.methods.exchange(1, 0, 99, 1).encodeABI();
const transaction = encodeTransaction(curve.address, 0, data);

const txReceipt = await manager.relay(
module,
"multiCall",
[wallet.address, [transaction]],
wallet,
[owner],
1,
ETH_TOKEN,
relayer);

const { success, error } = utils.parseRelayReceipt(txReceipt);
assert.isTrue(success, `deposit failed: "${error}"`);

const walletBalance = await lido.balanceOf(wallet.address);
assert.equal(walletBalance.toNumber(), 99);
});
});
});

0 comments on commit 9b60db7

Please sign in to comment.