Skip to content

Commit

Permalink
fix(EIP2612): retrieve ticket and token from prizePool
Browse files Browse the repository at this point in the history
  • Loading branch information
PierrickGT committed Nov 1, 2021
1 parent 1bbaf51 commit 769cfda
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 34 deletions.
11 changes: 5 additions & 6 deletions contracts/permit/EIP2612PermitAndDeposit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,30 @@ contract EIP2612PermitAndDeposit {
/**
* @notice Permits this contract to spend on a user's behalf, and deposits into the prize pool.
* @dev The `spender` address required by the permit function is the address of this contract.
* @param _token Address of the EIP-2612 token to approve and deposit
* @param _owner Token owner's address (Authorizer)
* @param _amount Amount of tokens to deposit
* @param _deadline Timestamp at which the signature expires
* @param _permitSignature Permit signature
* @param _delegateSignature Delegate signature
* @param _prizePool Address of the prize pool to deposit into
* @param _to Address that will receive the tickets
* @param _ticket Address of the prize pool ticket
* @param _delegate The address to delegate the prize pool tickets to
*/
function permitAndDepositToAndDelegate(
address _token,
address _owner,
uint256 _amount,
uint256 _deadline,
Signature calldata _permitSignature,
Signature calldata _delegateSignature,
address _prizePool,
IPrizePool _prizePool,
address _to,
ITicket _ticket,
address _delegate
) external {
require(msg.sender == _owner, "EIP2612PermitAndDeposit/only-signer");

ITicket _ticket = _prizePool.getTicket();
address _token = _prizePool.getToken();

IERC20Permit(_token).permit(
_owner,
address(this),
Expand All @@ -63,7 +62,7 @@ contract EIP2612PermitAndDeposit {
_permitSignature.s
);

_depositTo(_token, _owner, _amount, _prizePool, _to);
_depositTo(_token, _owner, _amount, address(_prizePool), _to);

_ticket.delegateWithSignature(
_owner,
Expand Down
43 changes: 15 additions & 28 deletions test/permit/EIP2612PermitAndDeposit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ describe('EIP2612PermitAndDeposit', () => {
fromWallet?: SignerWithAddress;
to: string;
amount: string;
ticketAddress: string;
delegateAddress: string;
};

Expand All @@ -43,8 +42,7 @@ describe('EIP2612PermitAndDeposit', () => {
fromWallet,
to,
amount,
ticketAddress,
delegateAddress
delegateAddress,
}: EIP2612PermitAndDepositToAndDelegate) {
if (!fromWallet) {
fromWallet = wallet;
Expand Down Expand Up @@ -77,19 +75,16 @@ describe('EIP2612PermitAndDeposit', () => {

const permitSignature = splitSignature(permit.sig);

return permitAndDeposit
.permitAndDepositToAndDelegate(
usdc.address,
user,
amount,
deadline,
permitSignature,
delegateSign,
prizePool,
to,
ticketAddress,
delegate
);
return permitAndDeposit.permitAndDepositToAndDelegate(
user,
amount,
deadline,
permitSignature,
delegateSign,
prizePool,
to,
delegate,
);
}

beforeEach(async () => {
Expand All @@ -112,12 +107,7 @@ describe('EIP2612PermitAndDeposit', () => {
permitAndDeposit = await EIP2612PermitAndDeposit.deploy();

const Ticket = await getContractFactory('TicketHarness');
ticket = await Ticket.deploy(
'PoolTogether Usdc Ticket',
'PcUSDC',
18,
prizePool.address,
);
ticket = await Ticket.deploy('PoolTogether Usdc Ticket', 'PcUSDC', 18, prizePool.address);

await prizePool.setTicket(ticket.address);
await prizePool.setPrizeStrategy(prizeStrategyManager.address);
Expand All @@ -135,8 +125,7 @@ describe('EIP2612PermitAndDeposit', () => {
prizePool: prizePool.address,
to: wallet.address,
amount: '100000000000000000000',
ticketAddress: ticket.address,
delegateAddress: wallet.address
delegateAddress: wallet.address,
});

expect(await usdc.balanceOf(prizePool.address)).to.equal(amount);
Expand All @@ -156,8 +145,7 @@ describe('EIP2612PermitAndDeposit', () => {
prizePool: prizePool.address,
to: wallet.address,
amount: '100000000000000000000',
ticketAddress: ticket.address,
delegateAddress: wallet2.address
delegateAddress: wallet2.address,
});

expect(await usdc.balanceOf(prizePool.address)).to.equal(amount);
Expand All @@ -181,8 +169,7 @@ describe('EIP2612PermitAndDeposit', () => {
to: wallet2.address,
fromWallet: wallet2,
amount: '100000000000000000000',
ticketAddress: ticket.address,
delegateAddress: wallet2.address
delegateAddress: wallet2.address,
}),
).to.be.revertedWith('EIP2612PermitAndDeposit/only-signer');
});
Expand Down

0 comments on commit 769cfda

Please sign in to comment.