Skip to content

Commit

Permalink
MAPNFT connects with CashFlow
Browse files Browse the repository at this point in the history
  • Loading branch information
MdTeach committed Aug 7, 2021
1 parent d8be2b7 commit c7df0c4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 93 deletions.
36 changes: 12 additions & 24 deletions hardhat/contracts/CashFlow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,28 @@ pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import {RedirectAll, ISuperToken, IConstantFlowAgreementV1, ISuperfluid} from "./RedirectAll.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract TradeableCashflow is ERC721, RedirectAll {
contract TradeableCashflow is RedirectAll {
// 0x8db7C7ed6403e26445843855D86834014500D4D7
// Host:0xEB796bdb90fFA0f28255275e16936D25d3418603
// CFAv1:0x49e565Ed1bdc17F3d220f72DF0857C26FA83F873
// token:0x5D8B4C2554aeB7e86F387B4d6c00Ac33499Ed01f

address public graphicsTeam = 0x7e3b984faE2b9235B38D8f8704091253F6e34692;
address public musicMaker = 0x09278C2E543A7090f149c4F312be4eb3f8dA70c2;
address public owner = 0x8db7C7ed6403e26445843855D86834014500D4D7;
// address public graphicsTeam = 0x7e3b984faE2b9235B38D8f8704091253F6e34692;
// address public musicMaker = 0x09278C2E543A7090f149c4F312be4eb3f8dA70c2;
// address public owner = 0x8db7C7ed6403e26445843855D86834014500D4D7;

address private _mapNFTContract;

ISuperfluid host = ISuperfluid(0xEB796bdb90fFA0f28255275e16936D25d3418603);
IConstantFlowAgreementV1 cfa =
IConstantFlowAgreementV1(0x49e565Ed1bdc17F3d220f72DF0857C26FA83F873);
ISuperToken acceptedToken =
ISuperToken(0x5D8B4C2554aeB7e86F387B4d6c00Ac33499Ed01f);

constructor()
// address owner
// ISuperfluid host,
// IConstantFlowAgreementV1 cfa,
// ISuperToken acceptedToken
ERC721("_name", "_symbol")
RedirectAll(host, cfa, acceptedToken, owner, musicMaker, graphicsTeam)
{
_mint(owner, 1);
}

//now I will insert a nice little hook in the _transfer, including the RedirectAll function I need
function _beforeTokenTransfer(
address, /*from*/
address to,
uint256 /*tokenId*/
) internal override {
_changeReceiver(to);
}
constructor(
address owner,
address musicMaker,
address graphicsTeam
) RedirectAll(host, cfa, acceptedToken, owner, musicMaker, graphicsTeam) {}
}
43 changes: 33 additions & 10 deletions hardhat/contracts/MapNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract PokeMap is ERC721 {
uint256 public tokenCounter;
mapping(uint256 => string) private _tokenURIs;
mapping(uint256 => address) public CashFlows;

string private _baseURL = "https://ipfs.io/ipfs/";

// public creators data
Expand All @@ -17,22 +19,43 @@ contract PokeMap is ERC721 {
}

// #### HANDLE MINT ####
function MintMap(
address owner,
address graphicOwner,
address musicOwner,
string memory _tokenURI
) public {
// mint the nft
function MintMap() public // address owner,
// address graphicOwner,
// address musicOwner,
// string memory _tokenURI
{
// temp fields
address owner = 0x8db7C7ed6403e26445843855D86834014500D4D7;
address graphicOwner = 0x7e3b984faE2b9235B38D8f8704091253F6e34692;
address musicOwner = 0x09278C2E543A7090f149c4F312be4eb3f8dA70c2;
string
memory _tokenURI = "bafybeig7hfci6swvkdtubmofuhwsdvl6zse5j3qjcdpzah7dkuiypdrqwm";

uint256 newItemId = tokenCounter;
_safeMint(owner, newItemId);
_setTokenURI(newItemId, _tokenURI);
_setTokenURI(newItemId, _tokenURI);

// add the creators address
musicCreator[newItemId] = musicOwner;
graphicsCreator[newItemId] = graphicOwner;

// mint the token
_safeMint(owner, newItemId);
_setTokenURI(newItemId, _tokenURI);
tokenCounter += 1;
}

function _beforeTokenTransfer(
address,
address to,
uint256 tokenId
) internal override {
// init the cashFlows
TradeableCashflow cashFlow = new TradeableCashflow(
to,
musicCreator[tokenId],
graphicsCreator[tokenId]
);

// cashFlow.changeReceiver(owner);
CashFlows[tokenId] = address(cashFlow);
}
}
62 changes: 3 additions & 59 deletions hardhat/contracts/RedirectAll.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ contract RedirectAll is SuperAppBase {
uint256 endTime;
int96 flowRate;
}

// keep the track of user flows
mapping(address => flowRecord) public userMaps;

// income splitting
Expand Down Expand Up @@ -75,26 +77,7 @@ contract RedirectAll is SuperAppBase {
* Redirect Logic
*************************************************************************/

function currentReceiver()
external
view
returns (
uint256 startTime,
address receiver,
int96 flowRate
)
{
if (_receiver != address(0)) {
(startTime, flowRate, , ) = _cfa.getFlow(
_acceptedToken,
address(this),
_receiver
);
receiver = _receiver;
}
}

event ReceiverChanged(address receiver); //what is this?
// event ReceiverChanged(address receiver); //what is this?

/// @dev If a new stream is opened, or an existing one is opened
function _updateOutflow(bytes calldata ctx)
Expand Down Expand Up @@ -181,45 +164,6 @@ contract RedirectAll is SuperAppBase {
}
}

// @dev Change the Receiver of the total flow
function _changeReceiver(address newReceiver) internal {
require(newReceiver != address(0), "New receiver is zero address");
// @dev because our app is registered as final, we can't take downstream apps
require(
!_host.isApp(ISuperApp(newReceiver)),
"New receiver can not be a superApp"
);
if (newReceiver == _receiver) return;
// @dev delete flow to old receiver
_host.callAgreement(
_cfa,
abi.encodeWithSelector(
_cfa.deleteFlow.selector,
_acceptedToken,
address(this),
_receiver,
new bytes(0)
),
"0x"
);
// @dev create flow to new receiver
_host.callAgreement(
_cfa,
abi.encodeWithSelector(
_cfa.createFlow.selector,
_acceptedToken,
newReceiver,
_cfa.getNetFlow(_acceptedToken, address(this)),
new bytes(0)
),
"0x"
);
// @dev set global receiver to new receiver
_receiver = newReceiver;

emit ReceiverChanged(_receiver);
}

/**************************************************************************
* SuperApp callbacks
*************************************************************************/
Expand Down

0 comments on commit c7df0c4

Please sign in to comment.