-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from treejer/develop
TreeBox Feature
- Loading branch information
Showing
33 changed files
with
1,749 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,60 @@ | ||
DEPLOYER_PRIVAE_KEY= | ||
INFURA_PROJECT_ID = | ||
|
||
BASE_URI=https://api.treejer.com/trees/ | ||
|
||
DEPLOYER_PRIVAE_KEY= | ||
|
||
INFURA_PROJECT_ID= | ||
MATICVIGIL_PROJECT_ID= | ||
ARB_DEPLOYER_PRIVAE_KEY= | ||
ARB_PROVIDER_URL= | ||
#---------------------------- tokens --------------------------------- | ||
#--matic | ||
DAI_TOKEN_ADDRESS_MATIC= | ||
SAND_TOKEN_ADDRESS_MATIC= | ||
WMATIC_TOKEN_ADDRESS_MATIC= | ||
WETH_TOKEN_ADDRESS_MATIC= | ||
USDT_TOKEN_ADDRESS_MATIC= | ||
USDC_TOKEN_ADDRESS_MATIC= | ||
QUICK_TOKEN_ADDRESS_MATIC= | ||
|
||
#--rinkeby | ||
DAI_TOKEN_ADDRESS_RINKEBY= | ||
WETH_TOKEN_ADDRESS_RINKEBY = | ||
USDC_TOKEN_ADDRESS_RINKEBY= | ||
USDT_TOKEN_ADDRESS_RINKEBY= | ||
|
||
|
||
#----------------------------- uniswap router | ||
#--matic | ||
UNISWAP_ROUTER_V2_ADDRESS_MATIC= | ||
|
||
#--rinkeby | ||
UNISWAP_ROUTER_V2_ADDRESS_RINKEBY = | ||
|
||
|
||
|
||
|
||
#---------------------------------- gsn | ||
#--matic | ||
GSN_FORWARDER_MATIC= | ||
GSN_RELAY_HUB_MATIC= | ||
|
||
#--rinkeby | ||
GSN_FORWARDER_RINKEBY= | ||
GSN_RELAY_HUB_RINKEBY= | ||
|
||
#----------------------------- safe address | ||
#--matic | ||
|
||
SAFE_ADDRESS_MATIC= | ||
|
||
#--rinkeby | ||
SAFE_ADDRESS_RINKEBY= | ||
|
||
|
||
DAI_ADDRESS= | ||
GSN_RELAY_HUB= | ||
GSN_FORWARDER= | ||
|
||
TREE_RESEARCH_ADDRESS= | ||
LOCAL_DEVELOP_ADDRESS= | ||
INSURANCE_FUND_ADDRESS= | ||
TREEJER_DEVELOP_ADDRESS= | ||
RESERVE_FUND_ADDRESS1= | ||
RESERVE_FUND_ADDRESS2= | ||
|
||
#https://github.com/cgewecke/eth-gas-reporter#options | ||
COINMARKETCAP_APIKEY= | ||
GAS_PRICE_API="https://api.etherscan.io/api?module=proxy&action=eth_gasPrice" | ||
GAS_REPORTER_TOKEN=ETH | ||
|
||
|
||
|
||
#----------RINKEBY------------------ | ||
# GSN_RELAY_HUB=0x6650d69225CA31049DB7Bd210aE4671c0B1ca132 | ||
# GSN_FORWARDER=0x83A54884bE4657706785D7309cf46B58FE5f6e8a | ||
# DAI_TOKEN_ADDRESS_RINKEBY=0xc7ad46e0b8a400bb3c915120d284aafba8fc4735 | ||
# UNISWAP_ROUTER_V2_ADDRESS_RINKEBY=0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D | ||
# WETH_TOKEN_ADDRESS_RINKEBY=0xc778417E063141139Fce010982780140Aa0cD5Ab | ||
|
||
|
||
|
||
#----------ROPSTEN------------------ | ||
# DAI_ADDRESS=0xad6d458402f60fd3bd25163575031acdce07538d | ||
# GSN_RELAY_HUB=0xAa3E82b4c4093b4bA13Cb5714382C99ADBf750cA | ||
# GSN_FORWARDER=0xeB230bF62267E94e657b5cbE74bdcea78EB3a5AB | ||
|
||
#----------MUMBAI------------------ | ||
# DAI_ADDRESS=0xF054e456dE45E391903cd39314a741F4cF993D22 | ||
# GSN_RELAY_HUB=0x6646cD15d33cE3a6933e36de38990121e8ba2806 | ||
# GSN_FORWARDER=0x4d4581c01A457925410cd3877d17b2fd4553b2C5 |
50 changes: 50 additions & 0 deletions
50
contracts/external/testContract/TestWhitelistPaymasterTreeBox.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
pragma solidity ^0.8.6; | ||
import "./ITestWhitelistPaymaster.sol"; | ||
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | ||
import "./../../external/gsn/forwarder/IForwarder.sol"; | ||
|
||
contract TestWhitelistPaymasterTreeBox is Initializable { | ||
|
||
function test(address _address) external { | ||
ITestWhitelistPaymaster test1 = ITestWhitelistPaymaster(_address); | ||
bytes memory context; | ||
bool success = false; | ||
uint256 gasUseWithoutPost = 110; | ||
GsnTypes.RelayData memory s; | ||
test1.postRelayedCall(context, success, gasUseWithoutPost, s); | ||
} | ||
|
||
function testPreRelayedCall( | ||
address _address, | ||
address _toAddress, | ||
address _fromAddress, | ||
bytes calldata _data | ||
) external { | ||
ITestWhitelistPaymaster test1 = ITestWhitelistPaymaster(_address); | ||
|
||
GsnTypes.RelayRequest memory relayRequest; | ||
|
||
relayRequest.request.to = _toAddress; | ||
|
||
relayRequest.request.data = _data; | ||
|
||
if (_fromAddress != address(0)) { | ||
relayRequest.request.from = _fromAddress; | ||
} | ||
|
||
bytes memory signature; | ||
bytes memory approvalData; | ||
uint256 maxPossibleGas = 110; | ||
|
||
test1.preRelayedCall( | ||
relayRequest, | ||
signature, | ||
approvalData, | ||
maxPossibleGas | ||
); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
pragma solidity ^0.8.6; | ||
|
||
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | ||
|
||
|
||
contract TreeNftTest is ERC721 { | ||
|
||
bool public isTree = true; | ||
|
||
constructor ()ERC721("Treejer Trees", "TREE") {} | ||
|
||
function safeMint(address _to, uint256 _tokenId) | ||
external | ||
{ | ||
_safeMint(_to, _tokenId); | ||
} | ||
|
||
function setIsTree() | ||
external | ||
{ | ||
isTree = false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
pragma solidity ^0.8.6; | ||
|
||
pragma abicoder v2; | ||
|
||
import "./../external/gsn/forwarder/IForwarder.sol"; | ||
import "./../external/gsn/BasePaymaster.sol"; | ||
|
||
import "../access/IAccessRestriction.sol"; | ||
|
||
import "./IWhitelistPaymaster.sol"; | ||
|
||
import "../treeBox/ITreeBox.sol"; | ||
|
||
contract WhitelistPaymasterTreeBox is BasePaymaster { | ||
ITreeBox public treeBox; | ||
|
||
constructor(address _treeBox) { | ||
treeBox = ITreeBox(_treeBox); | ||
require(treeBox.isTreeBox()); | ||
} | ||
|
||
function preRelayedCall( | ||
GsnTypes.RelayRequest calldata relayRequest, | ||
bytes calldata signature, | ||
bytes calldata approvalData, | ||
uint256 maxPossibleGas | ||
) | ||
external | ||
virtual | ||
override | ||
returns (bytes memory context, bool revertOnRecipientRevert) | ||
{ | ||
(relayRequest, signature, approvalData, maxPossibleGas); | ||
|
||
_verifyForwarder(relayRequest); | ||
|
||
(relayRequest, signature, approvalData, maxPossibleGas); | ||
|
||
bytes4 sig = GsnUtils.getMethodSig(relayRequest.request.data); | ||
|
||
require(sig == treeBox.claim.selector, "calling wrong method"); | ||
|
||
(address sender, ) = treeBox.boxes(relayRequest.request.from); | ||
|
||
require(sender != address(0), "user is not valid"); | ||
|
||
return ("", false); | ||
} | ||
|
||
function postRelayedCall( | ||
bytes calldata context, | ||
bool success, | ||
uint256 gasUseWithoutPost, | ||
GsnTypes.RelayData calldata relayData | ||
) external virtual override { | ||
(context, success, gasUseWithoutPost, relayData); | ||
} | ||
|
||
function versionPaymaster() | ||
external | ||
view | ||
virtual | ||
override | ||
returns (string memory) | ||
{ | ||
return "2.2.0+treejer.whitelist.ipaymaster"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
pragma solidity ^0.8.6; | ||
|
||
/** @title TreeBox interface */ | ||
interface ITreeBox { | ||
struct Input { | ||
address recipient; | ||
string ipfsHash; | ||
uint256[] treeIds; | ||
} | ||
|
||
/** | ||
* @dev emitted when tree box created | ||
* @param sender address of sender | ||
* @param recipient address of recipient | ||
*/ | ||
event Created(address sender, address recipient); | ||
|
||
/** | ||
* @dev emitted when tree box claimed | ||
* @param claimer address of claimer | ||
* @param recipient address of recipient | ||
* @param treeIds id of trees claimed by claimer | ||
*/ | ||
event Claimed(address claimer, address recipient, uint256[] treeIds); | ||
|
||
/** | ||
* @dev emitted when tree box withdrew | ||
* @param sender address of sender | ||
* @param recipient address of recipient | ||
* @param treeIds id of trees withdrew by sender | ||
*/ | ||
event Withdrew(address sender, address recipient, uint256[] treeIds); | ||
|
||
/** | ||
* @dev initialize AccessRestriction and TreeToken contract and set true | ||
* for isTreeBox | ||
* @param _token address of TreeToken contract | ||
* @param _accessRestrictionAddress address of AccessRestriction contract | ||
*/ | ||
function initialize(address _token, address _accessRestrictionAddress) | ||
external; | ||
|
||
/** @dev set {_address} to trusted forwarder */ | ||
function setTrustedForwarder(address _address) external; | ||
|
||
/** | ||
* @dev msg.sender create treeBoxes for a list of recipients | ||
* NOTE emit a {Created} event | ||
* @param _input is an array of Input struct which contains address of | ||
* recipient, treeIds for that recipient and ipfsHash for that recipient | ||
*/ | ||
function create(Input[] calldata _input) external; | ||
|
||
/** | ||
* @dev msg.sender claimed trees to the given address | ||
* NOTE emit a {Claimed} event | ||
* @param _recipient address of recipient to claim trees for | ||
*/ | ||
function claim(address _recipient) external; | ||
|
||
/** | ||
* @dev sender of treeBoxes can withdrew unclaimed trees given to recipient | ||
* NOTE emit a {Withdrew} event | ||
* @param _recipients array of recipient's addresses to withdrew their trees | ||
*/ | ||
function withdraw(address[] calldata _recipients) external; | ||
|
||
/** @return treeId of a {_recipient} at {_index} in his/her box */ | ||
function getRecipientTreeByIndex(address _recipient, uint256 _index) | ||
external | ||
view | ||
returns (uint256); | ||
|
||
/** @return treeCount for a {_recipient} in his/her box */ | ||
function getRecipientTreesLength(address _recipient) | ||
external | ||
view | ||
returns (uint256); | ||
|
||
/** @return true if TreeBox contract have been initialized */ | ||
function isTreeBox() external view returns (bool); | ||
|
||
/** | ||
* @return sender of box for {_recipient} | ||
* @return ipfsHash of box for {_recipient} */ | ||
function boxes(address _recipient) | ||
external | ||
view | ||
returns (address sender, string memory ipfsHash); | ||
} |
Oops, something went wrong.