Skip to content

Commit

Permalink
Updates to contracts and deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
Srecko Smodis committed Jun 10, 2021
1 parent 12bcfd3 commit 9c20171
Show file tree
Hide file tree
Showing 22 changed files with 11,155 additions and 631 deletions.
17 changes: 17 additions & 0 deletions contracts/ERC20TransferProxy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.9 <0.8.0;

import "protocol-contracts/transfer-proxy/contracts/roles/OperatorRole.sol";
import "@rarible/exchange-interfaces/contracts/IERC20TransferProxy.sol";

contract ERC20TransferProxy is IERC20TransferProxy, Initializable, OperatorRole {

function __ERC20TransferProxy_init() external initializer {
__Ownable_init();
}

function erc20safeTransferFrom(IERC20Upgradeable token, address from, address to, uint256 value) override external onlyOperator {
require(token.transferFrom(from, to, value), "failure while transferring");
}
}
40 changes: 38 additions & 2 deletions contracts/EcoFiERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ pragma abicoder v2;

import "protocol-contracts/tokens/contracts/erc-1155/ERC1155Base.sol";

contract EcoFiERC1155 is ERC1155Base {
import "hardhat/console.sol";
import "./lib/ERC1155Image.sol";

contract EcoFiERC1155 is ERC1155Base, ERC1155Image {
event CreateEcoFiERC1155(address owner, string name, string symbol);

function __EcoFiERC1155_init(string memory _name, string memory _symbol, string memory baseURI, string memory contractURI) external initializer {
Expand All @@ -20,8 +23,41 @@ contract EcoFiERC1155 is ERC1155Base {
__RoyaltiesV2Upgradeable_init_unchained();
__ERC1155Base_init_unchained(_name, _symbol);
_setBaseURI(baseURI);
_setDefaultApproval(_msgSender(), true);
_setDefaultApproval(_msgSender(), true); // set the contract deployer as approved
emit CreateEcoFiERC1155(_msgSender(), _name, _symbol);
}

function mintWithImage(LibERC1155LazyMint.Mint1155Data memory data, string memory image, address to, uint256 _amount) public virtual {
// mintAndTransfer(data, to, _amount);
console.log("TokenID before", data.tokenId);
address minter = _msgSender();
address sender = _msgSender();

console.log("Minter", minter);
console.log("Sender", sender);
console.log("TokenID", data.tokenId >> 96);

require(minter == data.creators[0].account, "tokenId incorrect");
require(data.creators.length == data.signatures.length);
require(minter == sender || isApprovedForAll(minter, sender), "ERC1155: transfer caller is not approved");

require(data.supply > 0, "supply incorrect");
require(_amount > 0, "amount incorrect");
require(bytes(data.uri).length > 0, "uri should be set");

if (_getSupply(data.tokenId) == 0) {
for (uint i = 0; i < data.creators.length; i++) {
validate(sender, data, i);
}

_saveSupply(data.tokenId, data.supply);
_saveRoyalties(data.tokenId, data.royalties);
_saveCreators(data.tokenId, data.creators);
_setTokenURI(data.tokenId, data.uri);
_setTokenImage(data.tokenId, image);
}

_mint(to, data.tokenId, _amount, "");
}
uint256[50] private __gap;
}
21 changes: 21 additions & 0 deletions contracts/NftTransferProxy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.9 <0.8.0;

import "protocol-contracts/transfer-proxy/contracts/roles/OperatorRole.sol";
import "@rarible/exchange-interfaces/contracts/INftTransferProxy.sol";

contract NftTransferProxy is INftTransferProxy, Initializable, OperatorRole {

function __NftTransferProxy_init() external initializer {
__Ownable_init();
}

function erc721safeTransferFrom(IERC721Upgradeable token, address from, address to, uint256 tokenId) override external onlyOperator {
token.safeTransferFrom(from, to, tokenId);
}

function erc1155safeTransferFrom(IERC1155Upgradeable token, address from, address to, uint256 id, uint256 value, bytes calldata data) override external onlyOperator {
token.safeTransferFrom(from, to, id, value, data);
}
}
1 change: 1 addition & 0 deletions contracts/SproutToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ contract SproutToken is ERC20Burnable {
{
mEcoFiTokenContract = _baseTokenContract; // ECO token contract address
mEcoFi = _ecoFiAddress; // ECO address for generation share
_mint(_ecoFiAddress, 10*10**6*10**18);
}

/**
Expand Down
43 changes: 43 additions & 0 deletions contracts/lib/ERC1155Image.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";

contract ERC1155Image {
using StringsUpgradeable for uint;

// Optional mapping for token URIs
mapping (uint256 => string) private _tokenImages;

event Image(string value, uint256 indexed id);

function image(uint id) external view virtual returns (string memory) {
return _tokenImage(id);
}

function _tokenImage(uint256 tokenId) internal view virtual returns (string memory) {
string memory _tokenImage = _tokenImages[tokenId];
return _tokenImage;
}

/**
* @dev Sets `_tokenImage` as the tokenImage of `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _setTokenImage(uint256 tokenId, string memory _image) internal virtual {
_tokenImages[tokenId] = _image;
emit Image(_tokenImage(tokenId), tokenId);
}

function _clearTokenImages(uint256 tokenId) internal {
if (bytes(_tokenImages[tokenId]).length != 0) {
delete _tokenImages[tokenId];
}
}
uint256[50] private __gap;
}
24 changes: 20 additions & 4 deletions deploy/00_ecofi_token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,43 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

/* const SproutToken = await ethers.getContractFactory("SproutToken");
const sproutToken1: Contract = await SproutToken.deploy('ecoToken.address', await eco_multisig.getAddress()); */
console.log("EcoFi signer: ", signer);

const ecoToken: DeployResult = await deploy('EcoFiToken', {
from,
args: [signer],
log: true
log: false
});

console.log("EcoFi token deployed to: ", ecoToken.address);

const sproutToken = await deploy('SproutToken', {
from,
args: [ecoToken.address, signer],
log: true
log: false
});

console.log("Sprout token deployed to: ", sproutToken.address);

const ecoTokenContract = new ethers.Contract(ecoToken.address, ecoToken.abi, eco_multisig);
const ecoTokenContract = new ethers.Contract(ecoToken.address, ecoToken.abi, eco_multisig).connect(deployer);
const sprtTokenContract = new ethers.Contract(sproutToken.address, sproutToken.abi, eco_multisig).connect(deployer);

// Set sprout contract address in ECO contract (to prevent accidental transfer())
await ecoTokenContract.connect(deployer).setSproutAddress(sproutToken.address);
await ecoTokenContract.setSproutAddress(sproutToken.address);
console.log("Set SproutToken address in EcoFiToken contract");

const tx = await ecoTokenContract.connect(eco_multisig)
.transfer(
from,
ethers.BigNumber.from("1000000000000000000000"),
);
await tx.wait();

const tx1 = await sprtTokenContract.connect(eco_multisig)
.transfer(
from,
ethers.BigNumber.from("1000000000000000000000"),
);
await tx1.wait();
};
export default func;
18 changes: 0 additions & 18 deletions deploy/02_ecofi_exchange.ts

This file was deleted.

31 changes: 31 additions & 0 deletions deploy/02_ecofi_proxies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const {deployments, ethers} = hre;
const {deploy} = deployments;

const [deployer] = await ethers.getSigners();
const from = await deployer.getAddress();

const erc20_p = await deploy('ERC20TransferProxy', {
from,
gasLimit: 9500000,
args: [],
log: true
});

const nft_p = await deploy('NftTransferProxy', {
from,
gasLimit: 9500000,
args: [],
log: true
});

const erc20ProxyContract = new ethers.Contract(erc20_p.address, erc20_p.abi);
await erc20ProxyContract.connect(deployer).__ERC20TransferProxy_init();

const nftProxyContract = new ethers.Contract(nft_p.address, nft_p.abi);
await nftProxyContract.connect(deployer).__NftTransferProxy_init();
};
export default func;
36 changes: 36 additions & 0 deletions deploy/03_ecofi_exchange.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const {deployments, ethers} = hre;
const {deploy} = deployments;

const [deployer] = await ethers.getSigners();
const from = await deployer.getAddress();

const contract = await deploy('EcoFiExchangeV2', {
from,
gasLimit: 9500000,
args: [],
log: true
});

const deps = await deployments.all();
const erc20_p = deps['ERC20TransferProxy'];
const nft_p = deps['NftTransferProxy'];

const exchangeContract = new ethers.Contract(contract.address, contract.abi);
await exchangeContract.connect(deployer).__EcoExchangeV2_init(
nft_p.address,
erc20_p.address,
'10000',
'0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
deps['EcoFiERC1155'].address);

const erc20ProxyContract = new ethers.Contract(erc20_p.address, erc20_p.abi);
await erc20ProxyContract.connect(deployer).addOperator(contract.address);

const nftProxyContract = new ethers.Contract(nft_p.address, nft_p.abi);
await nftProxyContract.connect(deployer).addOperator(contract.address);
};
export default func;
20 changes: 10 additions & 10 deletions deploy/03_setup_contracts.ts → deploy/04_setup_contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
contractsDir + "/all.json",
JSON.stringify(exp, null, 2)
);

/* fs.writeFileSync(
contractsDir + "/eco-contract-address.json",
JSON.stringify({ EcoToken: ecoToken.address }, undefined, 2)
);
fs.writeFileSync(
contractsDir + "/sprout-contract-address.json",
JSON.stringify({ SproutToken: sproutToken.address }, undefined, 2)
); */

fs.writeFileSync(
contractsDir + "/EcoToken.json",
Expand All @@ -51,5 +41,15 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
contractsDir + "/SproutToken.json",
JSON.stringify(hre.artifacts.readArtifactSync("SproutToken"), null, 2)
);

fs.writeFileSync(
contractsDir + "/EcoFiERC1155.json",
JSON.stringify(hre.artifacts.readArtifactSync("EcoFiERC1155"), null, 2)
);

fs.writeFileSync(
contractsDir + "/EcoFiExchangeV2.json",
JSON.stringify(hre.artifacts.readArtifactSync("EcoFiExchangeV2"), null, 2)
);
};
export default func;
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@reach/tooltip": "^0.11.2",
"bootstrap": "^4.5.3",
"classnames": "^2.2.6",
"eth-sig-util": "^3.0.1",
"ethers": "^5.0.32",
"react": "^16.12.0",
"react-app-rewired": "^2.1.6",
Expand Down
Loading

0 comments on commit 9c20171

Please sign in to comment.