Skip to content

Instantly share code, notes, and snippets.

@elmariachi111
Created July 26, 2024 12:53
Show Gist options
  • Save elmariachi111/4f1c6c0ed35f5b5dc860476b6b7f0567 to your computer and use it in GitHub Desktop.
Save elmariachi111/4f1c6c0ed35f5b5dc860476b6b7f0567 to your computer and use it in GitHub Desktop.
Test Funding Goal
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
import { Test } from "forge-std/Test.sol";
import "forge-std/console.sol";
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { LinearCurve } from "../src/curves/LinearCurve.sol";
import { CurveParametersOutOfRange, TradeType } from "../src/curves/IIPSeedCurve.sol";
import { CommonTest, Defaults } from "./helpers/CommonTest.sol";
import { ParameterMismatch, PremintTooLarge } from "../src/IPSeedTrust.sol";
import {
IPSeed,
MarketData,
MarketParameters,
UnauthorizedAccess,
TokenAlreadyExists,
InvalidTokenId,
TradeSizeOutOfRange,
InsufficientPayment,
PriceDriftTooHigh,
BalanceTooLow,
TransferRestricted,
BadState,
MarketState,
MarketParameters,
BASIS_POINTS
} from "../src/IPSeed.sol";
import {
ReentrancyBurnAttacker, ReentrancyWithdrawalsAttacker
} from "./helpers/ReentrancyAttacker.sol";
error OwnableUnauthorizedAccount(address account);
contract BugBashTest is CommonTest {
function testGoodFeeAndSlopeParameters() public {
address sourcer = makeAddr("kevin");
uint16 lpFeeBps = 500;
uint128 netFundingGoal = 1 ether;
uint128 premint = 500 ether;
uint256 tokenId = ipSeed.computeTokenId(sourcer, Defaults.projectId);
uint256 grossFundingGoal = (netFundingGoal * (BASIS_POINTS + lpFeeBps) / BASIS_POINTS);
uint256 slope = curve.computeSlope(grossFundingGoal, 10_000 ether, premint);
MarketParameters memory params = MarketParameters({
tokenId: tokenId,
projectId: Defaults.projectId,
sourcer: sourcer,
beneficiary: payable(beneficiaryMultisig),
priceCurve: curve,
curveParameters: bytes32(abi.encodePacked(uint128(slope), uint128(premint))),
fundingGoal: uint128(grossFundingGoal),
premint: premint,
deadline: uint64(block.timestamp + defaultDeadline)
});
vm.startPrank(sourcer);
ipSeed.spawn(params);
assertEq(ipSeed.totalSupply(), premint);
assertEq(ipSeed.balanceOf(beneficiaryMultisig, tokenId), Defaults.defaultPremint);
uint256 fundingGoalInTokens =
curve.supplyAtCollateral(params.curveParameters, params.fundingGoal);
assertEq(fundingGoalInTokens, 10_000.00000019229513999 ether);
vm.startPrank(alice);
vm.deal(alice, grossFundingGoal);
ipSeed.mint{ value: netFundingGoal }(tokenId, 0 ether);
assertEq(ipSeed.totalSupply(), 9771.050693198689432819 ether);
ipSeed.mint{ value: alice.balance }(tokenId, 0 ether);
assertEq(ipSeed.totalSupply(), 10000.000000095020357146 ether);
assertEq(ipSeed.collateral(tokenId), grossFundingGoal);
}
function testContradictingFeeAndSlopeParameters() public {
address sourcer = makeAddr("kevin");
uint16 lpFeeBps = 500;
uint128 netFundingGoal = 1 ether;
uint128 premint = 500 ether;
uint256 tokenId = ipSeed.computeTokenId(sourcer, Defaults.projectId);
uint256 grossFundingGoal = (netFundingGoal * (BASIS_POINTS + lpFeeBps) / BASIS_POINTS);
assertEq(grossFundingGoal, 1.05 ether);
uint256 slope = curve.computeSlope(grossFundingGoal, 10_000 ether, premint);
MarketParameters memory params = MarketParameters({
tokenId: tokenId,
projectId: Defaults.projectId,
sourcer: sourcer,
beneficiary: payable(beneficiaryMultisig),
priceCurve: curve,
curveParameters: bytes32(abi.encodePacked(uint128(slope), uint128(premint))),
fundingGoal: uint128(netFundingGoal),
premint: premint,
deadline: uint64(block.timestamp + defaultDeadline)
});
vm.startPrank(sourcer);
ipSeed.spawn(params);
assertEq(ipSeed.totalSupply(), premint);
assertEq(ipSeed.balanceOf(beneficiaryMultisig, tokenId), Defaults.defaultPremint);
uint256 fundingGoalInTokens =
curve.supplyAtCollateral(params.curveParameters, params.fundingGoal);
assertEq(fundingGoalInTokens, 9771.050693198726048531 ether);
vm.startPrank(alice);
vm.deal(alice, grossFundingGoal);
ipSeed.mint{ value: netFundingGoal }(tokenId, 0 ether);
assertEq(ipSeed.totalSupply(), 9771.050693198689432819 ether);
vm.expectRevert();
ipSeed.mint{ value: alice.balance }(tokenId, 0 ether);
assertEq(ipSeed.balanceOf(alice, tokenId), 9271.050693198689432819 ether);
assertEq(ipSeed.collateral(tokenId), netFundingGoal);
}
// function testParameterConformity() public {
// uint256 tokenId = ipSeed.computeTokenId(ophelia, Defaults.projectId);
// //the curve parameters contain the premint but we're setting a different premint value on the actual parameters
// MarketParameters memory params =
// Defaults.defaultParams(tokenId, ophelia, beneficiaryMultisig, ipSeedTrust, curve);
// params.premint = 200 ether;
// vm.startPrank(ophelia);
// vm.expectRevert(ParameterMismatch.selector);
// ipSeed.spawn(params);
// params.premint = 500 ether;
// //someone posted a Javascript ms timestamp, this is Nov 14 56226
// params.deadline = 1712181414 * 1000;
// vm.expectRevert(ParameterMismatch.selector);
// ipSeed.spawn(params);
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment