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

VAL-110 Ensure deposits go against callers #110

Merged
merged 1 commit into from
Nov 30, 2022
Merged
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
2 changes: 2 additions & 0 deletions contracts/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ contract Pool is IPool, ERC20 {
onlyCrankedPool
returns (uint256 shares)
{
require(msg.sender == receiver, "Pool: invalid receiver");
shares = PoolLib.executeDeposit(
asset(),
address(this),
Expand Down Expand Up @@ -707,6 +708,7 @@ contract Pool is IPool, ERC20 {
onlyCrankedPool
returns (uint256 assets)
{
require(msg.sender == receiver, "Pool: invalid receiver");
assets = previewMint(shares);
PoolLib.executeDeposit(
asset(),
Expand Down
48 changes: 48 additions & 0 deletions test/Pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,30 @@ describe("Pool", () => {
// 91 shares at an exchange rate of 150 / 144 = 94.79 assets rounded down
expect(await pool.maxWithdrawRequest(lenderB.address)).to.equal(94);
});

it("depositing requires receiver address to be the same as caller", async () => {
const { pool, otherAccount, liquidityAsset, poolAdmin, otherAccounts } =
await loadFixture(loadPoolFixture);

const receiver = otherAccounts[otherAccounts.length - 1];
expect(receiver.address).to.not.equal(otherAccount.address);

await activatePool(pool, poolAdmin, liquidityAsset);

// Provide capital to lender
const depositAmount = 1000;
await liquidityAsset.mint(otherAccount.address, depositAmount);

// Approve the deposit
await liquidityAsset
.connect(otherAccount)
.approve(pool.address, depositAmount);

// Deposit against a different receiver
await expect(
pool.connect(otherAccount).deposit(depositAmount, receiver.address)
).to.be.revertedWith("Pool: invalid receiver");
});
});

describe("mint()", async () => {
Expand Down Expand Up @@ -175,6 +199,30 @@ describe("Pool", () => {
depositAmount
);
});

it("minting requires receiver address to be the same as caller", async () => {
const { pool, otherAccount, liquidityAsset, poolAdmin, otherAccounts } =
await loadFixture(loadPoolFixture);

const receiver = otherAccounts[otherAccounts.length - 1];
expect(receiver.address).to.not.equal(otherAccount.address);

await activatePool(pool, poolAdmin, liquidityAsset);

// Provide capital to lender
const depositAmount = 1000;
await liquidityAsset.mint(otherAccount.address, depositAmount);

// Approve the deposit
await liquidityAsset
.connect(otherAccount)
.approve(pool.address, depositAmount);

// Mint against a different receiver
await expect(
pool.connect(otherAccount).mint(depositAmount, receiver.address)
).to.be.revertedWith("Pool: invalid receiver");
});
});

describe("previewDeposit()", async () => {
Expand Down