Skip to content

Commit

Permalink
add custom NegRiskCtfExchange
Browse files Browse the repository at this point in the history
  • Loading branch information
mshrieve committed Nov 1, 2023
1 parent 7871d08 commit e381ab5
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ docs/

# python virtualenv
env/

node_modules/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "lib/forge-gas-snapshot"]
path = lib/forge-gas-snapshot
url = https://github.com/marktoda/forge-gas-snapshot
[submodule "lib/ctf-exchange"]
path = lib/ctf-exchange
url = https://github.com/Polymarket/ctf-exchange
1 change: 0 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[profile.default]
solc = "0.8.19"
src = "src"
out = "out"
libs = ["lib"]
Expand Down
1 change: 1 addition & 0 deletions lib/ctf-exchange
Submodule ctf-exchange added at 503c0a
2 changes: 2 additions & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/
solmate/=lib/solmate/src/
forge-gas-snapshot/=lib/forge-gas-snapshot/src/

openzeppelin-contracts/=lib/ctf-exchange/lib/openzeppelin-contracts/contracts/
26 changes: 26 additions & 0 deletions src/NegRiskAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,32 @@ contract NegRiskAdapter is ERC1155TokenReceiver, MarketStateManager, INegRiskAda
emit PositionsMerge(msg.sender, _conditionId, _amount);
}

/*//////////////////////////////////////////////////////////////
ERC1155
//////////////////////////////////////////////////////////////*/

function balanceOf(address _owner, uint256 _id) external view returns (uint256) {
return ctf.balanceOf(_owner, _id);
}

function balanceOfBatch(address[] memory _owners, uint256[] memory _ids) external view returns (uint256[] memory) {
return ctf.balanceOfBatch(_owners, _ids);
}

function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _value, bytes calldata _data) external {
return ctf.safeTransferFrom(_from, _to, _id, _value, _data);
}

function safeBatchTransferFrom(
address _from,
address _to,
uint256[] calldata _ids,
uint256[] calldata _values,
bytes calldata _data
) external {
return ctf.safeBatchTransferFrom(_from, _to, _ids, _values, _data);
}

/*//////////////////////////////////////////////////////////////
REDEEM POSITION
//////////////////////////////////////////////////////////////*/
Expand Down
13 changes: 13 additions & 0 deletions src/NegRiskCtfExchange.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;

import {CTFExchange} from "lib/ctf-exchange/src/exchange/CTFExchange.sol";
import {ERC1155} from "lib/solmate/src/tokens/ERC1155.sol";

contract NegRiskCtfExchange is CTFExchange {
constructor(address _collateral, address _negRiskAdapter, address _ctf, address _proxyFactory, address _safeFactory)
CTFExchange(_collateral, _negRiskAdapter, _proxyFactory, _safeFactory)
{
ERC1155(_ctf).setApprovalForAll(_negRiskAdapter, true);
}
}
14 changes: 14 additions & 0 deletions src/dev/libraries/DeployLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,18 @@ library DeployLib {
vm.label(deployment, "UmaCtfAdapter");
return deployment;
}

function deployNegRiskCtfExchange(
address _collateral,
address _negRiskAdapter,
address _ctf,
address _proxyFactory,
address _safeFactory
) public returns (address) {
address deployment = _deployCode(
"artifacts/UmaCtfAdapter.json", abi.encode(_collateral, _negRiskAdapter, _ctf, _proxyFactory, _safeFactory)
);
vm.label(deployment, "UmaCtfAdapter");
return deployment;
}
}
44 changes: 44 additions & 0 deletions src/interfaces/INegRiskAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
pragma solidity ^0.8.10;

interface Interface {
event MarketPrepared(bytes32 indexed marketId, address indexed oracle, uint256 feeBips, bytes data);
event OutcomeReported(bytes32 indexed marketId, bytes32 indexed questionId, bool outcome);
event PayoutRedemption(address indexed redeemer, bytes32 indexed conditionId, uint256[] amounts, uint256 payout);
event PositionSplit(address indexed stakeholder, bytes32 indexed conditionId, uint256 amount);
event PositionsConverted(
address indexed stakeholder, bytes32 indexed marketId, uint256 indexed indexSet, uint256 amount
);
event PositionsMerge(address indexed stakeholder, bytes32 indexed conditionId, uint256 amount);
event QuestionPrepared(bytes32 indexed marketId, bytes32 indexed questionId, uint256 index, bytes data);

function FEE_DENOMINATOR() external view returns (uint256);
function NO_TOKEN_BURN_ADDRESS() external view returns (address);
function col() external view returns (address);
function convertPositions(bytes32 _marketId, uint256 _indexSet, uint256 _amount) external;
function ctf() external view returns (address);
function getConditionId(bytes32 _questionId) external view returns (bytes32);
function getDetermined(bytes32 _marketId) external view returns (bool);
function getFeeBips(bytes32 _marketId) external view returns (uint256);
function getMarketData(bytes32 _marketId) external view returns (bytes32);
function getOracle(bytes32 _marketId) external view returns (address);
function getPositionId(bytes32 _questionId, bool _outcome) external view returns (uint256);
function getQuestionCount(bytes32 _marketId) external view returns (uint256);
function getResult(bytes32 _marketId) external view returns (uint256);
function mergePositions(address _collateralToken, bytes32, bytes32 _conditionId, uint256[] memory, uint256 _amount)
external;
function mergePositions(bytes32 _conditionId, uint256 _amount) external;
function onERC1155BatchReceived(address, address, uint256[] memory, uint256[] memory, bytes memory)
external
returns (bytes4);
function onERC1155Received(address, address, uint256, uint256, bytes memory) external returns (bytes4);
function prepareMarket(uint256 _feeBips, bytes memory _metadata) external returns (bytes32);
function prepareQuestion(bytes32 _marketId, bytes memory _metadata) external returns (bytes32);
function redeemPositions(bytes32 _conditionId, uint256[] memory _amounts) external;
function reportOutcome(bytes32 _questionId, bool _outcome) external;
function splitPosition(address _collateralToken, bytes32, bytes32 _conditionId, uint256[] memory, uint256 _amount)
external;
function splitPosition(bytes32 _conditionId, uint256 _amount) external;
function vault() external view returns (address);
function wcol() external view returns (address);
}

2 changes: 1 addition & 1 deletion src/modules/MarketDataManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface IMarketStateManagerEE {
/// @notice Manages market state on behalf of the NegRiskAdapter
/// @author Mike Shrieve([email protected])
abstract contract MarketStateManager is IMarketStateManagerEE {
mapping(bytes32 _marketId => MarketData) internal marketData;
mapping(bytes32 => MarketData) internal marketData;

/*//////////////////////////////////////////////////////////////
GETTERS
Expand Down

0 comments on commit e381ab5

Please sign in to comment.