Skip to content

Instantly share code, notes, and snippets.

@ngmachado
Created May 19, 2022 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngmachado/ec35d359654f311942cd0a40194260c9 to your computer and use it in GitHub Desktop.
Save ngmachado/ec35d359654f311942cd0a40194260c9 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT //0xECd2f5870c6D2EE5Dc4441B1887585A760E227fc
pragma solidity ^0.8.4;
import "./TinyWorld.sol";
import "./TinyWorldRegistry.sol";
import "./TileContract.sol";
import "./Types.sol";
import {CFAv1Library} from "https://github.com/superfluid-finance/protocol-monorepo/blob/dev/packages/ethereum-contracts/contracts/apps/CFAv1Library.sol";
import {ISuperfluid, ISuperToken} from "https://github.com/superfluid-finance/protocol-monorepo/blob/dev/packages/ethereum-contracts/contracts/interfaces/superfluid/ISuperfluid.sol";
import {IConstantFlowAgreementV1} from "https://github.com/superfluid-finance/protocol-monorepo/blob/dev/packages/ethereum-contracts/contracts/interfaces/agreements/IConstantFlowAgreementV1.sol";
contract WaterWell is ITileContract {
using CFAv1Library for CFAv1Library.InitData;
CFAv1Library.InitData public cfaV1Lib;
TinyWorld constant connectedWorld = TinyWorld(0x0583f380BDa6C1b97029BF1a95C757329b5Ba3B3);
ISuperToken constant waterToken = ISuperToken(0x05FeA5C765a82A1742E0B6635a2FF526075b196B);
constructor() {
cfaV1Lib = CFAv1Library.InitData(
ISuperfluid(0x74b57883f8ce9F2BD330286E884CfD8BB24AC4ED),
IConstantFlowAgreementV1(0x523481a8a5455efB1F301C6e00B5525Eb12a51da)
);
}
function tileEmoji(Coords memory coords) external view override returns (string memory) {
return unicode"🌊";
}
function tileName(Coords memory coords) external view override returns (string memory) {
return "Water well";
}
function tileDescription(Coords memory coords)
external
view
virtual
override
returns (string memory)
{
return "";
}
function isContract(address addr) internal view returns (bool) {
return addr.code.length > 0;
}
function tileABI(Coords memory coords) external view virtual override returns (string memory) {
// Autogenerated - DO NOT EDIT
return "https://exgrasia.infura-ipfs.io/ipfs/QmSExy5Tk3VkHCjEuGHZ8coetY6WUa5PctK3SLy2gLVpgT";
}
function getWater() external {
_beforeStream(msg.sender);
cfaV1Lib.createFlow(msg.sender, waterToken, 11574074074074074);
}
function getAddressOrContractLocations(address addr) internal view returns (Coords[] memory) {
if (isContract(addr)) {
return connectedWorld.getContractLocations(addr);
} else {
require(connectedWorld.playerInited(addr), "addr is not an exgrasia player");
Coords[] memory ret = new Coords[](1);
ret[0] = connectedWorld.getPlayerLocation(addr);
return ret;
}
}
function _beforeStream(address receiver) internal view {
Coords[] memory fromLocations = getAddressOrContractLocations(address(this));
Coords[] memory toLocations = getAddressOrContractLocations(receiver);
bool satisfactory = false;
for (uint256 i = 0; i < fromLocations.length; i++) {
for (uint256 j = 0; j < toLocations.length; j++) {
if (connectedWorld.dist(fromLocations[i], toLocations[j]) <= 1) {
satisfactory = true;
break;
}
}
if (satisfactory) break;
}
require(satisfactory, "Start stream is only allowed between adjacent tiles");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment