Skip to content

Commit

Permalink
format; update test_InitialState
Browse files Browse the repository at this point in the history
  • Loading branch information
metalogica committed Nov 13, 2024
1 parent f489b8f commit bbd5fdc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 39 deletions.
6 changes: 1 addition & 5 deletions script/LMSR.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ contract DeployLMSR is Script {
}

// Deploy LMSR Market
market = new LMSRMarket(
block.chainid == 31337 ? address(usdc) : getUSDCAddress(),
LIQUIDITY,
NUM_OUTCOMES
);
market = new LMSRMarket(block.chainid == 31337 ? address(usdc) : getUSDCAddress(), LIQUIDITY, NUM_OUTCOMES);

console.log("Deployed LMSR Market at:", address(market));
console.log("USDC address:", address(market.USDC()));
Expand Down
36 changes: 10 additions & 26 deletions src/LMSR.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,9 @@ contract LMSRMarket is ReentrancyGuard {
EVENTS
//////////////////////////////////////////////////////////////*/

event SharesPurchased(
address indexed buyer,
uint256 indexed outcome,
uint256 amount,
uint256 usdcCost
);

event SharesSold(
address indexed seller,
uint256 indexed outcome,
uint256 amount,
uint256 usdcPayout
);
event SharesPurchased(address indexed buyer, uint256 indexed outcome, uint256 amount, uint256 usdcCost);

event SharesSold(address indexed seller, uint256 indexed outcome, uint256 amount, uint256 usdcPayout);

event MarketResolved(uint256 indexed outcome);

Expand Down Expand Up @@ -92,10 +82,7 @@ contract LMSRMarket is ReentrancyGuard {
CORE FUNCTIONS
//////////////////////////////////////////////////////////////*/

function calculateCost(
uint256 outcome,
uint256 amount
) public view returns (uint256 cost) {
function calculateCost(uint256 outcome, uint256 amount) public view returns (uint256 cost) {
if (outcome >= numOutcomes) revert InvalidOutcome();
if (amount < MIN_AMOUNT) revert AmountTooSmall();

Expand Down Expand Up @@ -143,12 +130,14 @@ contract LMSRMarket is ReentrancyGuard {

function claimWinnings(uint256 amount) external nonReentrant {
if (!resolved) revert MarketNotResolved();
if (userShares[msg.sender][winningOutcome] < amount)
if (userShares[msg.sender][winningOutcome] < amount) {
revert InsufficientShares();
}

uint256 usdcAmount = (amount * SCALE) / (10 ** (18 - USDC_DECIMALS));
if (usdcAmount > USDC.balanceOf(address(this)))
if (usdcAmount > USDC.balanceOf(address(this))) {
revert InsufficientUSDC();
}

userShares[msg.sender][winningOutcome] -= amount;
quantities[winningOutcome] -= amount;
Expand All @@ -164,20 +153,15 @@ contract LMSRMarket is ReentrancyGuard {
VIEW FUNCTIONS
//////////////////////////////////////////////////////////////*/

function getUserPosition(
address user,
uint256 outcome
) external view returns (uint256) {
function getUserPosition(address user, uint256 outcome) external view returns (uint256) {
return userShares[user][outcome];
}

/*//////////////////////////////////////////////////////////////
INTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/

function calculateLMSRCost(
uint256[] memory _quantities
) internal view returns (uint256) {
function calculateLMSRCost(uint256[] memory _quantities) internal view returns (uint256) {
uint256 sum = 0;
for (uint256 i = 0; i < numOutcomes; i++) {
sum += exp((_quantities[i] * SCALE) / liquidity);
Expand Down
6 changes: 1 addition & 5 deletions test/ERC20.m.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ contract MockERC20 is ERC20 {
bool public transferShouldRevert;
bool public mintShouldRevert;

constructor(
string memory name,
string memory symbol,
uint8 decimals_
) ERC20(name, symbol) {
constructor(string memory name, string memory symbol, uint8 decimals_) ERC20(name, symbol) {
_decimals = decimals_;
}

Expand Down
5 changes: 2 additions & 3 deletions test/LMSR.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract LMSRMarketTest is Test {
vm.stopPrank();
}

function test_InitialState() public {
function test_InitialState() public view {
assertEq(market.numOutcomes(), NUM_OUTCOMES);
assertEq(market.liquidity(), LIQUIDITY);
assertEq(address(market.USDC()), address(usdc));
Expand Down Expand Up @@ -85,8 +85,7 @@ contract LMSRMarketTest is Test {
uint256 balanceBefore = usdc.balanceOf(alice);
market.claimWinnings(amount);

uint256 expectedPayout = (amount * market.SCALE()) /
(10 ** (18 - market.USDC_DECIMALS()));
uint256 expectedPayout = (amount * market.SCALE()) / (10 ** (18 - market.USDC_DECIMALS()));
assertEq(usdc.balanceOf(alice), balanceBefore + expectedPayout);
assertEq(market.getUserPosition(alice, outcome), 0);
}
Expand Down

0 comments on commit bbd5fdc

Please sign in to comment.