Skip to content

Commit

Permalink
remove sponsor helper function to free up build size
Browse files Browse the repository at this point in the history
  • Loading branch information
trmid committed Jul 16, 2024
1 parent 2acdde5 commit f6190ce
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 101 deletions.
27 changes: 1 addition & 26 deletions src/PrizeVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TwabERC20 } from "./TwabERC20.sol";

import { ILiquidationSource } from "pt-v5-liquidator-interfaces/ILiquidationSource.sol";
import { PrizePool } from "pt-v5-prize-pool/PrizePool.sol";
import { TwabController, SPONSORSHIP_ADDRESS } from "pt-v5-twab-controller/TwabController.sol";
import { TwabController } from "pt-v5-twab-controller/TwabController.sol";

/// @dev The TWAB supply limit is the max number of shares that can be minted in the TWAB controller.
uint256 constant TWAB_SUPPLY_LIMIT = type(uint96).max;
Expand Down Expand Up @@ -152,12 +152,6 @@ contract PrizeVault is TwabERC20, Claimable, IERC4626, ILiquidationSource, Ownab
/// @param yieldFeePercentage New yield fee percentage
event YieldFeePercentageSet(uint256 yieldFeePercentage);

/// @notice Emitted when a user sponsors the Vault.
/// @param caller Address that called the function
/// @param assets Amount of assets deposited into the Vault
/// @param shares Amount of shares minted to the caller address
event Sponsor(address indexed caller, uint256 assets, uint256 shares);

/// @notice Emitted when yield is transferred out by the liquidation pair address.
/// @param liquidationPair The liquidation pair address that initiated the transfer
/// @param tokenOut The token that was transferred out
Expand Down Expand Up @@ -554,25 +548,6 @@ contract PrizeVault is TwabERC20, Claimable, IERC4626, ILiquidationSource, Ownab
return _shares;
}

/// @notice Deposit assets into the Vault and delegate to the sponsorship address.
/// @dev Emits a `Sponsor` event
/// @param _assets Amount of assets to deposit
/// @return Amount of shares minted to caller.
function sponsor(uint256 _assets) external returns (uint256) {
address _owner = msg.sender;

uint256 _shares = previewDeposit(_assets);
_depositAndMint(_owner, _owner, _assets, _shares);

if (twabController.delegateOf(address(this), _owner) != SPONSORSHIP_ADDRESS) {
twabController.sponsor(_owner);
}

emit Sponsor(_owner, _assets, _shares);

return _shares;
}

////////////////////////////////////////////////////////////////////////////////
// Additional Withdrawal Flows
////////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 0 additions & 1 deletion test/integration/BaseIntegration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ abstract contract BaseIntegration is Test, Permit {
event MockContribute(address prizeVault, uint256 amount);
event ClaimYieldFeeShares(address indexed recipient, uint256 shares);
event TransferYieldOut(address indexed liquidationPair, address indexed tokenOut, address indexed recipient, uint256 amountOut, uint256 yieldFee);
event Sponsor(address indexed caller, uint256 assets, uint256 shares);

/* ============ variables ============ */

Expand Down
15 changes: 0 additions & 15 deletions test/invariant/PrizeVault/PrizeVaultFuzzHarness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ contract PrizeVaultFuzzHarness is Permit, StdCheats, StdUtils {
address public joe;
uint256 public joePrivateKey;

address public constant SPONSORSHIP_ADDRESS = address(1);

PrizeVault public vault;
string public vaultName = "PoolTogether Test Vault";
string public vaultSymbol = "pTest";
Expand Down Expand Up @@ -297,19 +295,6 @@ contract PrizeVaultFuzzHarness is Permit, StdCheats, StdUtils {
vm.stopPrank();
}

/* ============ sponsor ============ */

function sponsor(uint256 callerSeed, uint256 assets) public useCurrentTime useActor(callerSeed) {
assets = _bound(assets, 0, vault.maxDeposit(currentActor));
assets = _bound(assets, 0, _maxDealAssets());
_dealAssets(currentActor, assets);
IERC20(vault.asset()).approve(address(vault), assets);

vm.expectEmit();
emit Deposit(currentActor, currentActor, assets, vault.previewDeposit(assets));
vault.sponsor(assets);
}

/* ============ claimYieldFeeShares ============ */

function claimYieldFeeShares(uint256 callerSeed, uint256 shares) public useCurrentTime useActor(callerSeed) {
Expand Down
20 changes: 0 additions & 20 deletions test/unit/PrizeVault/DepositLossyProtection.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -128,26 +128,6 @@ contract PrizeVaultDepositLossyProtection is UnitBaseSetup {
vm.stopPrank();
}

/* ============ sponsor ============ */

function testSponsor_revertWhenLossy() external {
underlyingAsset.mint(alice, 1e18);

vm.startPrank(alice);
underlyingAsset.approve(address(vault), 1e18);
vault.sponsor(1e18);
vm.stopPrank();

underlyingAsset.mint(alice, 1e18);
underlyingAsset.burn(address(yieldVault), 1); // lost 1 asset in yield vault, new sponsors will be lossy

vm.startPrank(alice);
underlyingAsset.approve(address(vault), 1e18);
vm.expectRevert(abi.encodeWithSelector(PrizeVault.LossyDeposit.selector, 2e18 - 1, 2e18));
vault.sponsor(1e18);
vm.stopPrank();
}

/* ============ depositWithPermit ============ */

function testDepositWithPermit_revertWhenLossy() external {
Expand Down
36 changes: 0 additions & 36 deletions test/unit/PrizeVault/PrizeVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -480,42 +480,6 @@ contract PrizeVaultTest is UnitBaseSetup {
vault.previewWithdraw(1);
}

/* ============ sponsor ============ */

function testSponsor() public {
// sponsor the vault
uint256 assets = 4e18;
underlyingAsset.mint(address(this), assets);
underlyingAsset.approve(address(vault), assets);
vm.expectEmit();
emit Sponsor(address(this), assets, assets); // 1:1
uint256 shares = vault.sponsor(assets);
assertEq(shares, assets);
assertEq(twabController.delegateOf(address(vault), address(this)), address(1));

// sponsor again
underlyingAsset.mint(address(this), assets);
underlyingAsset.approve(address(vault), assets);
vm.expectEmit();
emit Sponsor(address(this), assets, assets); // 1:1
shares = vault.sponsor(assets);
assertEq(shares, assets);
assertEq(twabController.delegateOf(address(vault), address(this)), address(1));
}

// tests if the TWAB sponsor call reverts
function testSponsor_SameDelegateAlreadySet() public {
uint256 assets = 4e18;
underlyingAsset.mint(address(this), assets);
underlyingAsset.approve(address(vault), assets);

// spoof sponsor revert
bytes memory err = abi.encodeWithSelector(SameDelegateAlreadySet.selector, address(this));
vm.mockCallRevert(address(twabController), abi.encodeWithSelector(TwabController.sponsor.selector, address(this)), err);
vm.expectRevert(err);
vault.sponsor(assets);
}

/* ============ depositAndMint ============ */

function testDepositAndMint_DepositZeroAssets() public {
Expand Down
3 changes: 0 additions & 3 deletions test/unit/PrizeVault/UnitBaseSetup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ contract UnitBaseSetup is Test, Permit {
event MockContribute(address prizeVault, uint256 amount);
event ClaimYieldFeeShares(address indexed recipient, uint256 shares);
event TransferYieldOut(address indexed liquidationPair, address indexed tokenOut, address indexed recipient, uint256 amountOut, uint256 yieldFee);
event Sponsor(address indexed caller, uint256 assets, uint256 shares);

/* ============ variables ============ */

Expand All @@ -43,8 +42,6 @@ contract UnitBaseSetup is Test, Permit {
address internal bob;
uint256 internal bobPrivateKey;

address public constant SPONSORSHIP_ADDRESS = address(1);

PrizeVaultWrapper public vault;
string public vaultName = "PoolTogether Test Vault";
string public vaultSymbol = "pTest";
Expand Down

0 comments on commit f6190ce

Please sign in to comment.