添加箱子的合约代码
This commit is contained in:
parent
f548ea0581
commit
723c679676
20339
build/contracts/BEBoxHub.json
Normal file
20339
build/contracts/BEBoxHub.json
Normal file
File diff suppressed because one or more lines are too long
20409
build/contracts/BEBoxMall.json
Normal file
20409
build/contracts/BEBoxMall.json
Normal file
File diff suppressed because one or more lines are too long
@ -30119,12 +30119,12 @@
|
||||
}
|
||||
},
|
||||
"links": {},
|
||||
"address": "0x85A780d8A7AB5fcc4412f053c887B4a6A41ce885",
|
||||
"transactionHash": "0x9b70700a5a89ba90cf8e30afa08a5d98cd866d706bdd9f2e0e11d266dd734ba4"
|
||||
"address": "0x321cc39D32EC3b6A420f00B4f643E5cEB72030eD",
|
||||
"transactionHash": "0xecb31201e5b8ddddbd73bd582dd3606e4d7e3354ffdd2e75923e8b005a9ea155"
|
||||
}
|
||||
},
|
||||
"schemaVersion": "3.4.4",
|
||||
"updatedAt": "2022-01-12T06:14:06.672Z",
|
||||
"updatedAt": "2022-01-12T06:52:32.641Z",
|
||||
"networkType": "ethereum",
|
||||
"devdoc": {
|
||||
"kind": "dev",
|
||||
|
@ -18080,12 +18080,12 @@
|
||||
}
|
||||
},
|
||||
"links": {},
|
||||
"address": "0x23ea63535771da07F0dbc5169c9515ffCe8C908a",
|
||||
"transactionHash": "0xba84707e1943a789a05b3b27febfef0cefa3d2a2b6637da34910489571e9d8e9"
|
||||
"address": "0x95B4b95B8EbCcaBe87ad6D9D899257863ed01B50",
|
||||
"transactionHash": "0xc2b0ed20a0465dbeeaabdd904fce2031c988505843df5d985d0a96e968fc7811"
|
||||
}
|
||||
},
|
||||
"schemaVersion": "3.4.4",
|
||||
"updatedAt": "2022-01-12T06:14:06.725Z",
|
||||
"updatedAt": "2022-01-12T06:52:32.682Z",
|
||||
"networkType": "ethereum",
|
||||
"devdoc": {
|
||||
"kind": "dev",
|
||||
|
@ -30119,12 +30119,12 @@
|
||||
}
|
||||
},
|
||||
"links": {},
|
||||
"address": "0x0e436299A0275De90c63684514621E5288c4E583",
|
||||
"transactionHash": "0x13ef22d65ab890aa84adef31cdafb3bff18f32e9b230da361470b7df5785c78f"
|
||||
"address": "0x9437d89047AF2053230eb38e28C0267c8b3873Ad",
|
||||
"transactionHash": "0xb3d922d990c7fc100330571f303fed8c35f5326a7ffc1e840094e4da95dc6381"
|
||||
}
|
||||
},
|
||||
"schemaVersion": "3.4.4",
|
||||
"updatedAt": "2022-01-12T06:14:06.646Z",
|
||||
"updatedAt": "2022-01-12T06:52:32.621Z",
|
||||
"networkType": "ethereum",
|
||||
"devdoc": {
|
||||
"kind": "dev",
|
||||
|
@ -30125,12 +30125,12 @@
|
||||
}
|
||||
},
|
||||
"links": {},
|
||||
"address": "0x51fE79AA2DDB1C5e6D5D00Bd442B032605771F15",
|
||||
"transactionHash": "0x86fd04bb5575e1be623bdf74c0b4af4cb044ae12f87898f57562148ef0a79680"
|
||||
"address": "0x0f46683e76075ab3C40A2474440c11e82694C03c",
|
||||
"transactionHash": "0xda62597f56c976a6331bf4e25c67c627a32361546f1b44ec2f394281ba1b2e7e"
|
||||
}
|
||||
},
|
||||
"schemaVersion": "3.4.4",
|
||||
"updatedAt": "2022-01-12T06:14:06.626Z",
|
||||
"updatedAt": "2022-01-12T06:52:32.601Z",
|
||||
"networkType": "ethereum",
|
||||
"devdoc": {
|
||||
"kind": "dev",
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -2323,12 +2323,12 @@
|
||||
"1338": {
|
||||
"events": {},
|
||||
"links": {},
|
||||
"address": "0x3Fb7a6D924AcF05039F13D590d6298CFb52c1092",
|
||||
"transactionHash": "0x070fcbe6e808f2f3b9d746393b71ae4e98175f579711bd956edc77e74250dc05"
|
||||
"address": "0xc2976420A0654F22566e70c576a7F550F2Ae5C6A",
|
||||
"transactionHash": "0xa0c8cff94132f9bd0e386edc88811015987e96817f6ab22391bf074b46f994b5"
|
||||
}
|
||||
},
|
||||
"schemaVersion": "3.4.4",
|
||||
"updatedAt": "2022-01-12T06:14:06.732Z",
|
||||
"updatedAt": "2022-01-12T06:52:32.700Z",
|
||||
"networkType": "ethereum",
|
||||
"devdoc": {
|
||||
"kind": "dev",
|
||||
|
File diff suppressed because one or more lines are too long
102
contracts/BEBoxMall.sol
Normal file
102
contracts/BEBoxMall.sol
Normal file
@ -0,0 +1,102 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||
import "./HasSignature.sol";
|
||||
|
||||
contract BEBoxMall is Ownable, HasSignature {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
event BEBoxPaid(
|
||||
uint256 indexed boxId,
|
||||
address indexed buyer,
|
||||
uint256 boxType,
|
||||
uint256 price,
|
||||
address paymentToken
|
||||
);
|
||||
|
||||
address public paymentReceivedAddress;
|
||||
mapping(bytes => bool) public usedSignatures;
|
||||
|
||||
function setPaymentReceivedAddress(address _paymentReceivedAddress)
|
||||
public
|
||||
onlyOwner
|
||||
{
|
||||
paymentReceivedAddress = _paymentReceivedAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev BE box payment buy function
|
||||
*/
|
||||
function buyBoxWithSignature(
|
||||
uint256 boxId,
|
||||
uint256 _type,
|
||||
address userAddress,
|
||||
uint256 price,
|
||||
address paymentErc20,
|
||||
uint256 saltNonce,
|
||||
bytes calldata signature
|
||||
) external onlyOwner {
|
||||
require(
|
||||
!isContract(userAddress),
|
||||
"BEBoxPayment: Only user address is allowed to buy box"
|
||||
);
|
||||
require(_type > 0, "BEBoxPayment: Invalid box type");
|
||||
require(price > 0, "BEBoxPayment: Invalid payment amount");
|
||||
require(
|
||||
!usedSignatures[signature],
|
||||
"BEBoxPayment: signature used. please send another transaction with new signature"
|
||||
);
|
||||
bytes32 criteriaMessageHash = getMessageHash(
|
||||
_type,
|
||||
paymentErc20,
|
||||
price,
|
||||
saltNonce
|
||||
);
|
||||
|
||||
checkSigner(userAddress, criteriaMessageHash, signature);
|
||||
|
||||
IERC20 paymentToken = IERC20(paymentErc20);
|
||||
uint256 allowToPayAmount = paymentToken.allowance(
|
||||
userAddress,
|
||||
address(this)
|
||||
);
|
||||
require(
|
||||
allowToPayAmount >= price,
|
||||
"BEBoxPayment: Invalid token allowance"
|
||||
);
|
||||
// Transfer payment
|
||||
paymentToken.safeTransferFrom(
|
||||
userAddress,
|
||||
paymentReceivedAddress,
|
||||
price
|
||||
);
|
||||
// Emit payment event
|
||||
emit BEBoxPaid(boxId, userAddress, _type, price, paymentErc20);
|
||||
}
|
||||
|
||||
function getMessageHash(
|
||||
uint256 _boxType,
|
||||
address _paymentErc20,
|
||||
uint256 _price,
|
||||
uint256 _saltNonce
|
||||
) public pure returns (bytes32) {
|
||||
return
|
||||
keccak256(
|
||||
abi.encodePacked(_boxType, _paymentErc20, _price, _saltNonce)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Identify an address is user address or contract address
|
||||
*/
|
||||
function isContract(address _address) private view returns (bool) {
|
||||
uint32 size;
|
||||
assembly {
|
||||
size := extcodesize(_address)
|
||||
}
|
||||
return (size > 0);
|
||||
}
|
||||
}
|
@ -4,8 +4,12 @@ const Chip = artifacts.require('BEChip');
|
||||
const Factory = artifacts.require('MinterFactory');
|
||||
const MarketPlace = artifacts.require('MarketPlace');
|
||||
const Coin = artifacts.require('BECoin');
|
||||
const Box = artifacts.require('BEBoxMall');
|
||||
|
||||
module.exports = async function (deployer, network, accounts) {
|
||||
const account = accounts[0];
|
||||
console.log('current account: ', account);
|
||||
|
||||
module.exports = async function (deployer) {
|
||||
await deployer.deploy(Coin);
|
||||
const coinInstance = await Coin.deployed();
|
||||
if(coinInstance) {
|
||||
@ -59,12 +63,26 @@ module.exports = async function (deployer) {
|
||||
console.log("MarketPlace successfully deployed.")
|
||||
}
|
||||
try {
|
||||
marketInstance.setFeeToAddress('0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1');
|
||||
marketInstance.setFeeToAddress(account);
|
||||
marketInstance.setPaymentTokens([coinInstance.address]);
|
||||
} catch(err) {
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
await deployer.deploy(Box);
|
||||
const boxInstance = await Box.deployed();
|
||||
if(boxInstance) {
|
||||
console.log("BEBoxMall successfully deployed.")
|
||||
}
|
||||
try {
|
||||
await boxInstance.setPaymentReceivedAddress(account);
|
||||
console.log(
|
||||
`update payment received address: ${account}`
|
||||
);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
|
||||
// add marketplace to whitelist
|
||||
try {
|
||||
@ -77,12 +95,16 @@ module.exports = async function (deployer) {
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
let jsons = []
|
||||
jsons.push({name: 'coin', json: 'assets/contracts/BECoin.json', address: coinInstance.address})
|
||||
jsons.push({name: 'hero', json: 'assets/contracts/BEHero.json', address: heroInstance.address})
|
||||
jsons.push({name: 'equip', json: 'assets/contracts/BEEquipment.json', address: equipInstance.address})
|
||||
jsons.push({name: 'chip', json: 'assets/contracts/BEChip.json', address: chipInstance.address})
|
||||
jsons.push({name: 'factory', json: 'assets/contracts/MinterFactory.json', address: factoryInstance.address})
|
||||
jsons.push({name: 'market', json: 'assets/contracts/MarketPlace.json', address: marketInstance.address})
|
||||
console.log(jsons);
|
||||
if (network == "local" || network == "development") {
|
||||
let jsons = []
|
||||
jsons.push({name: 'coin', json: 'assets/contracts/BECoin.json', address: coinInstance.address})
|
||||
jsons.push({name: 'hero', json: 'assets/contracts/BEHero.json', address: heroInstance.address})
|
||||
jsons.push({name: 'equip', json: 'assets/contracts/BEEquipment.json', address: equipInstance.address})
|
||||
jsons.push({name: 'chip', json: 'assets/contracts/BEChip.json', address: chipInstance.address})
|
||||
jsons.push({name: 'factory', json: 'assets/contracts/MinterFactory.json', address: factoryInstance.address})
|
||||
jsons.push({name: 'market', json: 'assets/contracts/MarketPlace.json', address: marketInstance.address})
|
||||
jsons.push({name: 'mall', json: 'assets/contracts/BEBoxMall.json', address: boxInstance.address})
|
||||
console.log(jsons);
|
||||
}
|
||||
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user