Skip to content

Commit

Permalink
wow. finish tests and frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
proxima424 committed Dec 27, 2022
1 parent 86e7e89 commit 1bedc26
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 22 deletions.
30 changes: 27 additions & 3 deletions src/DNSShortPosition.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

import {AggregatorV3Interface} from "../src/AggregatorV3Interface.sol";


contract DNSShortPosition {

/* ERRORS */
error INVALID_USER(address entrant);

constructor(){
priceFeed =
AggregatorV3Interface(0x48731cF7e84dc94C5f84577882c14Be11a5B7456);
}

/// @notice Address of the controlling factory contract
address immutable factory;

Expand All @@ -18,12 +25,29 @@ contract DNSShortPosition {
uint256 startPrice;
}

function getCurrentShortPosition(CollateralData memory params) external returns(uint256 magnitudePNL,uint256 indicator){
// returns ( magnitude of PNL , ( 0 for negative,1 for positive ) )
uint256 currentPrice = getLatestPrice(); // 6 Decimals
uint256 magnitudePNL = currentPrice > params.startPrice ? currentPrice - params.startPrice : params.startPrice - currentPrice ;
uint256 indicator = currentPrice > params.startPrice ? 0 : 1 ;
uint256 magnitudePNL = magnitudePNL * params.amount ; // need to divide this py 10**24
}


constructor(address _factory){
factory = _factory;
function getLatestPrice() public view returns (int256) {
(
uint80 roundID,
int256 price,
uint256 startedAt,
uint256 timeStamp,
uint80 answeredInRound
) = priceFeed.latestRoundData();
// for LINK / USD price
return price;
}




/// @notice Instead of a modifier, we include this line at the start of every function
/// @notice This is to decrease contract bytecode size (find out more why)
function onlyFactory() internal {
Expand Down
37 changes: 18 additions & 19 deletions src/DNSfactory.sol
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

// Supports LINK Tokens as support for now
// Supports LINK Tokens as collateral for now

//dependencies
import {DNSerc20} from "./DNSerc20.sol";
import {DNSerc721} from "./DNSerc721.sol";
import {DNSerc20} from
"./DNSerc20.sol";
import {DNSerc721} from
"./DNSerc721.sol";
import {Ownable} from
"../lib/openzeppelin-contracts/contracts/access/Ownable.sol";

// // interfaces
//interfaces
import {IERC20} from
"../lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {IERC721} from
"../lib/openzeppelin-contracts/contracts/token/ERC721/IERC721.sol";

import {AggregatorV3Interface} from "./AggregatorV3Interface.sol";
import {AggregatorV3Interface} from
"./AggregatorV3Interface.sol";

interface DNSfactory is Ownable, DNSerc721 {
/////////////////////////// STORAGE ///////////////////////////////////
Expand Down Expand Up @@ -51,7 +53,7 @@ interface DNSfactory is Ownable, DNSerc721 {
constructor(string memory name_, string memory symbol_, address _DNSerc20)
DNSerc721(name_, symbol_)
{
//LINK Tokens
//LINK Tokens Price Feed GOERLI Testnet
priceFeed =
AggregatorV3Interface(0x48731cF7e84dc94C5f84577882c14Be11a5B7456);
}
Expand All @@ -64,7 +66,6 @@ interface DNSfactory is Ownable, DNSerc721 {
chainLinkPriceFeed[_erc20] = _ChainlinkFeed;
}


function constructTokenId(
address _user,
address _collateral,
Expand All @@ -87,15 +88,15 @@ interface DNSfactory is Ownable, DNSerc721 {
external
returns (CollateralData memory)
{
require(_collateral != address(0), "ZERO_ADDRESS");
require(isERC20Supported[_collateral],"UNSUPPORTED_COLLATERAL");
require(_amount != 0, "ZERO_AMOUNT");

bool success =
IERC20(_collateral).transferFrom(msg.sender, address(this), _amount);
require(success, "TRANSFER_FAILED");
uint256 currentTokenId =
constructTokenId(msg.sender, _collateral, _amount);
uint256 currentPrice = uint256(getLatestPrice(chainLinkPriceFeed[_erc20]));
uint256 currentPrice = uint256(getLatestPrice(chainLinkPriceFeed[_collateral]));
CollateralData memory positionData =
new CollateralData({ token:_collateral,amount:_amount, tokenId : currentTokenId, startPrice: currentPrice});
//create function called updateMappings
Expand Down Expand Up @@ -186,29 +187,27 @@ interface DNSfactory is Ownable, DNSerc721 {
return price;
}

function getAmountDNSToMint(address _erc20, uint256 _quantity)
function getAmountDNSToMint(address _erc20, uint256 _quantity, uint256 _price)
internal
returns (uint256 quantity)
{
require(isERC20Supported[_erc20], "DNS_NOT_SUPPORTED");
uint256 quantity = uint256(getLatestPrice(chainLinkPriceFeed[_erc20]));
quantity = quantity * (10 ** 10) * _quantity;
uint256 quantity = _price * (10 ** 10) * _quantity;
}

function createShortPosition() internal returns(bool){

}

function getShortPositionData() public returns(int256){

function getCollateralParams(uint256 tokenId) public returns(uint256 _amount,uint256 _startPrice){
_amount = tokenIDToPosition[tokenId].amount;
_startPrice = tokenIDToPosition[tokenId].startPrice; // 6 decimals
}


function mintERC20DNS(uint256 theTokenId) external returns (bool) {
require(!isMinted[theTokenId], "ALREADY_MINTED");
CollateralData memory userPosition = tokenIDToPosition[theTokenId];
uint256 DNS_TO_MINT =
getAmountDNSToMint(userPosition.token, userPosition.amount);
getAmountDNSToMint(userPosition.token, userPosition.amount, userPosition.startPrice);
isMinted[theTokenId] = true;
bool success = createShortPosition();
require(success,"INVALID_ATTEMPT");
Expand Down

0 comments on commit 1bedc26

Please sign in to comment.