From 6fa62278be98a2bc470ba70db00cf0355bbdb749 Mon Sep 17 00:00:00 2001 From: mac Date: Tue, 21 May 2024 18:20:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AE=89=E5=85=A8=E8=AE=A1?= =?UTF-8?q?=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .openzeppelin/bsc-testnet.json | 1323 ++++++++++++++++++++++++++++++++ contracts/Pledge.sol | 284 ++++--- contracts/SafeMath.sol | 55 ++ package-lock.json | 65 +- package.json | 3 + scripts/deployProxy.ts | 10 +- sync.block.js | 4 +- test/Pledge.ts | 35 +- 8 files changed, 1645 insertions(+), 134 deletions(-) create mode 100644 contracts/SafeMath.sol diff --git a/.openzeppelin/bsc-testnet.json b/.openzeppelin/bsc-testnet.json index 3a1eb12..967fc53 100644 --- a/.openzeppelin/bsc-testnet.json +++ b/.openzeppelin/bsc-testnet.json @@ -125,6 +125,36 @@ "address": "0x9a1baA5b0282dc948Af3011e730da7236060f806", "txHash": "0x953e6746fa3c3d5efa634a16f7c07cf7d72e32b8b25e12615c645d01f387048e", "kind": "transparent" + }, + { + "address": "0xE68addAceD636047573F3A3Ab43B5CaB554fdaFf", + "txHash": "0x2bc6632dc6306d8a50acc7c87946829326c82f888a57c4ed6f25b8a3b8f1b9d0", + "kind": "transparent" + }, + { + "address": "0x358380F644B320dbD56648b93F6D5D82C58aDf83", + "txHash": "0x4bb5eeca9702cf2daa212ac3241f45c3b9c7e85903c0b329cc3e41571e4614a2", + "kind": "transparent" + }, + { + "address": "0x810AE94f1E3daCaD63c8708BD0C4bf446f0cAcEA", + "txHash": "0x6a09e20d02d40be91a4ac22033c5c686f4dc4460828fe8462b137c73acbb2eea", + "kind": "transparent" + }, + { + "address": "0xD38380A68Be1c09eF68d6B97d3D2e094e3463146", + "txHash": "0x668d67e3c9a87165be1d5bddf5a64f4a42f6d5999e445bb2cf391a63cfae3bb2", + "kind": "transparent" + }, + { + "address": "0x2CEd9862567e0FD98EdB3Db3147c68841b311687", + "txHash": "0xc645343a676bc3fec8f43379ec98a7587eaabd01f0b7713217b211fd31d14a4b", + "kind": "transparent" + }, + { + "address": "0xD1D827B8B5337C1c3c22ccFD47BCC16899b509e9", + "txHash": "0xbd54c56248a364e708a75bb634ef978c476f6be2f47c67d269fd0c9313aaee07", + "kind": "transparent" } ], "impls": { @@ -4852,6 +4882,1299 @@ ] } } + }, + "1eebcc0c7ec23966dd508924d60fe99e2198c4a9592c44538841b5cb4316ec24": { + "address": "0x36ae272aE1bFCCd6691162242D2d0C29b7A00b92", + "txHash": "0xd153811be7f6122241607c70d96c2fdc910bfd31cd4b1905629243b64c0f3e57", + "layout": { + "solcVersion": "0.8.24", + "storage": [ + { + "label": "nftContract", + "offset": 0, + "slot": "0", + "type": "t_contract(NFT)4554", + "contract": "Pledge", + "src": "contracts/Pledge.sol:14" + }, + { + "label": "poolContract", + "offset": 0, + "slot": "1", + "type": "t_contract(Pool)6647", + "contract": "Pledge", + "src": "contracts/Pledge.sol:15" + }, + { + "label": "productInfo", + "offset": 0, + "slot": "2", + "type": "t_array(t_struct(ProductInfo)6456_storage)dyn_storage", + "contract": "Pledge", + "src": "contracts/Pledge.sol:16" + }, + { + "label": "pledges", + "offset": 0, + "slot": "3", + "type": "t_mapping(t_uint256,t_struct(PledgeType)6451_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:17" + }, + { + "label": "pledgeRecords", + "offset": 0, + "slot": "4", + "type": "t_mapping(t_address,t_array(t_struct(PledgeType)6451_storage)dyn_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:18" + }, + { + "label": "invitationPledges", + "offset": 0, + "slot": "5", + "type": "t_mapping(t_uint256,t_struct(PledgeType)6451_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:19" + }, + { + "label": "recommendObj", + "offset": 0, + "slot": "6", + "type": "t_mapping(t_address,t_struct(RecommendObjType)6465_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:20" + }, + { + "label": "invitationTokens", + "offset": 0, + "slot": "7", + "type": "t_mapping(t_address,t_array(t_uint256)dyn_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:21" + }, + { + "label": "invitationAddress", + "offset": 0, + "slot": "8", + "type": "t_mapping(t_address,t_array(t_address)dyn_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:22" + }, + { + "label": "pledgeWithdrawRecord", + "offset": 0, + "slot": "9", + "type": "t_mapping(t_address,t_array(t_struct(PledgeWithdrawRecordType)6481_storage)dyn_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:23" + }, + { + "label": "invitationWithdrawRecord", + "offset": 0, + "slot": "10", + "type": "t_mapping(t_address,t_array(t_struct(InvitationWithdrawRecordType)6470_storage)dyn_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:24" + }, + { + "label": "blackList", + "offset": 0, + "slot": "11", + "type": "t_array(t_address)dyn_storage", + "contract": "Pledge", + "src": "contracts/Pledge.sol:26" + }, + { + "label": "whiteList", + "offset": 0, + "slot": "12", + "type": "t_array(t_address)dyn_storage", + "contract": "Pledge", + "src": "contracts/Pledge.sol:27" + }, + { + "label": "pledgeDestoryRecords", + "offset": 0, + "slot": "13", + "type": "t_mapping(t_address,t_array(t_struct(PledgeType)6451_storage)dyn_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:28" + }, + { + "label": "invitationRate", + "offset": 0, + "slot": "14", + "type": "t_uint256", + "contract": "Pledge", + "src": "contracts/Pledge.sol:29" + }, + { + "label": "nextTokenId", + "offset": 0, + "slot": "15", + "type": "t_uint256", + "contract": "Pledge", + "src": "contracts/Pledge.sol:30" + }, + { + "label": "pledgeStatus", + "offset": 0, + "slot": "16", + "type": "t_bool", + "contract": "Pledge", + "src": "contracts/Pledge.sol:31" + }, + { + "label": "dayTime", + "offset": 0, + "slot": "17", + "type": "t_uint256", + "contract": "Pledge", + "src": "contracts/Pledge.sol:32" + } + ], + "types": { + "t_bool": { + "label": "bool", + "numberOfBytes": "1" + }, + "t_struct(InitializableStorage)10_storage": { + "label": "struct Initializable.InitializableStorage", + "members": [ + { + "label": "_initialized", + "type": "t_uint64", + "offset": 0, + "slot": "0" + }, + { + "label": "_initializing", + "type": "t_bool", + "offset": 8, + "slot": "0" + } + ], + "numberOfBytes": "32" + }, + "t_uint64": { + "label": "uint64", + "numberOfBytes": "8" + }, + "t_address": { + "label": "address", + "numberOfBytes": "20" + }, + "t_array(t_address)dyn_storage": { + "label": "address[]", + "numberOfBytes": "32" + }, + "t_array(t_struct(InvitationWithdrawRecordType)6470_storage)dyn_storage": { + "label": "struct InvitationWithdrawRecordType[]", + "numberOfBytes": "32" + }, + "t_array(t_struct(PledgeType)6451_storage)dyn_storage": { + "label": "struct PledgeType[]", + "numberOfBytes": "32" + }, + "t_array(t_struct(PledgeWithdrawRecordType)6481_storage)dyn_storage": { + "label": "struct PledgeWithdrawRecordType[]", + "numberOfBytes": "32" + }, + "t_array(t_struct(ProductInfo)6456_storage)dyn_storage": { + "label": "struct ProductInfo[]", + "numberOfBytes": "32" + }, + "t_array(t_uint256)dyn_storage": { + "label": "uint256[]", + "numberOfBytes": "32" + }, + "t_contract(NFT)4554": { + "label": "contract NFT", + "numberOfBytes": "20" + }, + "t_contract(Pool)6647": { + "label": "contract Pool", + "numberOfBytes": "20" + }, + "t_mapping(t_address,t_array(t_address)dyn_storage)": { + "label": "mapping(address => address[])", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_array(t_struct(InvitationWithdrawRecordType)6470_storage)dyn_storage)": { + "label": "mapping(address => struct InvitationWithdrawRecordType[])", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_array(t_struct(PledgeType)6451_storage)dyn_storage)": { + "label": "mapping(address => struct PledgeType[])", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_array(t_struct(PledgeWithdrawRecordType)6481_storage)dyn_storage)": { + "label": "mapping(address => struct PledgeWithdrawRecordType[])", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_array(t_uint256)dyn_storage)": { + "label": "mapping(address => uint256[])", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_struct(RecommendObjType)6465_storage)": { + "label": "mapping(address => struct RecommendObjType)", + "numberOfBytes": "32" + }, + "t_mapping(t_uint256,t_struct(PledgeType)6451_storage)": { + "label": "mapping(uint256 => struct PledgeType)", + "numberOfBytes": "32" + }, + "t_struct(InvitationWithdrawRecordType)6470_storage": { + "label": "struct InvitationWithdrawRecordType", + "members": [ + { + "label": "amount", + "type": "t_uint256", + "offset": 0, + "slot": "0" + }, + { + "label": "createTime", + "type": "t_uint256", + "offset": 0, + "slot": "1" + } + ], + "numberOfBytes": "64" + }, + "t_struct(PledgeType)6451_storage": { + "label": "struct PledgeType", + "members": [ + { + "label": "tokenId", + "type": "t_uint256", + "offset": 0, + "slot": "0" + }, + { + "label": "startTime", + "type": "t_uint256", + "offset": 0, + "slot": "1" + }, + { + "label": "endTime", + "type": "t_uint256", + "offset": 0, + "slot": "2" + }, + { + "label": "withdrawTime", + "type": "t_uint256", + "offset": 0, + "slot": "3" + }, + { + "label": "pledgeAmount", + "type": "t_uint256", + "offset": 0, + "slot": "4" + }, + { + "label": "rate", + "type": "t_uint256", + "offset": 0, + "slot": "5" + }, + { + "label": "pledgeDay", + "type": "t_uint256", + "offset": 0, + "slot": "6" + }, + { + "label": "sender", + "type": "t_address", + "offset": 0, + "slot": "7" + }, + { + "label": "isBlack", + "type": "t_bool", + "offset": 20, + "slot": "7" + } + ], + "numberOfBytes": "256" + }, + "t_struct(PledgeWithdrawRecordType)6481_storage": { + "label": "struct PledgeWithdrawRecordType", + "members": [ + { + "label": "amount", + "type": "t_uint256", + "offset": 0, + "slot": "0" + }, + { + "label": "createTime", + "type": "t_uint256", + "offset": 0, + "slot": "1" + }, + { + "label": "tokenId", + "type": "t_uint256", + "offset": 0, + "slot": "2" + }, + { + "label": "pledgeDay", + "type": "t_uint256", + "offset": 0, + "slot": "3" + }, + { + "label": "_type", + "type": "t_uint256", + "offset": 0, + "slot": "4" + } + ], + "numberOfBytes": "160" + }, + "t_struct(ProductInfo)6456_storage": { + "label": "struct ProductInfo", + "members": [ + { + "label": "day", + "type": "t_uint256", + "offset": 0, + "slot": "0" + }, + { + "label": "rate", + "type": "t_uint256", + "offset": 0, + "slot": "1" + } + ], + "numberOfBytes": "64" + }, + "t_struct(RecommendObjType)6465_storage": { + "label": "struct RecommendObjType", + "members": [ + { + "label": "key", + "type": "t_address", + "offset": 0, + "slot": "0" + }, + { + "label": "referrer", + "type": "t_address", + "offset": 0, + "slot": "1" + }, + { + "label": "bindTime", + "type": "t_uint256", + "offset": 0, + "slot": "2" + }, + { + "label": "contribute", + "type": "t_uint256", + "offset": 0, + "slot": "3" + } + ], + "numberOfBytes": "128" + }, + "t_uint256": { + "label": "uint256", + "numberOfBytes": "32" + } + }, + "namespaces": { + "erc7201:openzeppelin.storage.Initializable": [ + { + "contract": "Initializable", + "label": "_initialized", + "type": "t_uint64", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:69", + "offset": 0, + "slot": "0" + }, + { + "contract": "Initializable", + "label": "_initializing", + "type": "t_bool", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:73", + "offset": 8, + "slot": "0" + } + ] + } + } + }, + "9d35b15e04d545df0bd61a5f1b6e2268655cbe7445756ea35acb61cfecc0ae26": { + "address": "0xb7bE528ba5F8968D7C2EaA1E785CbC1ecFa60757", + "txHash": "0xcd4f9d72b0372f7274ef4a04c95ffeab0fbeb1a6ee13f9262e0934fe46f080c3", + "layout": { + "solcVersion": "0.8.24", + "storage": [ + { + "label": "nftContract", + "offset": 0, + "slot": "0", + "type": "t_contract(NFT)3942", + "contract": "Pledge", + "src": "contracts/Pledge.sol:14" + }, + { + "label": "poolContract", + "offset": 0, + "slot": "1", + "type": "t_contract(Pool)6045", + "contract": "Pledge", + "src": "contracts/Pledge.sol:15" + }, + { + "label": "productInfo", + "offset": 0, + "slot": "2", + "type": "t_array(t_struct(ProductInfo)5854_storage)dyn_storage", + "contract": "Pledge", + "src": "contracts/Pledge.sol:16" + }, + { + "label": "pledges", + "offset": 0, + "slot": "3", + "type": "t_mapping(t_uint256,t_struct(PledgeType)5849_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:17" + }, + { + "label": "pledgeRecords", + "offset": 0, + "slot": "4", + "type": "t_mapping(t_address,t_array(t_struct(PledgeType)5849_storage)dyn_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:18" + }, + { + "label": "invitationPledges", + "offset": 0, + "slot": "5", + "type": "t_mapping(t_uint256,t_struct(PledgeType)5849_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:19" + }, + { + "label": "recommendObj", + "offset": 0, + "slot": "6", + "type": "t_mapping(t_address,t_struct(RecommendObjType)5863_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:20" + }, + { + "label": "invitationTokens", + "offset": 0, + "slot": "7", + "type": "t_mapping(t_address,t_array(t_uint256)dyn_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:21" + }, + { + "label": "invitationAddress", + "offset": 0, + "slot": "8", + "type": "t_mapping(t_address,t_array(t_address)dyn_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:22" + }, + { + "label": "pledgeWithdrawRecord", + "offset": 0, + "slot": "9", + "type": "t_mapping(t_address,t_array(t_struct(PledgeWithdrawRecordType)5879_storage)dyn_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:23" + }, + { + "label": "invitationWithdrawRecord", + "offset": 0, + "slot": "10", + "type": "t_mapping(t_address,t_array(t_struct(InvitationWithdrawRecordType)5868_storage)dyn_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:24" + }, + { + "label": "blackList", + "offset": 0, + "slot": "11", + "type": "t_array(t_address)dyn_storage", + "contract": "Pledge", + "src": "contracts/Pledge.sol:26" + }, + { + "label": "whiteList", + "offset": 0, + "slot": "12", + "type": "t_array(t_address)dyn_storage", + "contract": "Pledge", + "src": "contracts/Pledge.sol:27" + }, + { + "label": "pledgeDestoryRecords", + "offset": 0, + "slot": "13", + "type": "t_mapping(t_address,t_array(t_struct(PledgeType)5849_storage)dyn_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:28" + }, + { + "label": "invitationRate", + "offset": 0, + "slot": "14", + "type": "t_uint256", + "contract": "Pledge", + "src": "contracts/Pledge.sol:29" + }, + { + "label": "nextTokenId", + "offset": 0, + "slot": "15", + "type": "t_uint256", + "contract": "Pledge", + "src": "contracts/Pledge.sol:30" + }, + { + "label": "pledgeStatus", + "offset": 0, + "slot": "16", + "type": "t_bool", + "contract": "Pledge", + "src": "contracts/Pledge.sol:31" + }, + { + "label": "dayTime", + "offset": 0, + "slot": "17", + "type": "t_uint256", + "contract": "Pledge", + "src": "contracts/Pledge.sol:32" + } + ], + "types": { + "t_bool": { + "label": "bool", + "numberOfBytes": "1" + }, + "t_struct(InitializableStorage)10_storage": { + "label": "struct Initializable.InitializableStorage", + "members": [ + { + "label": "_initialized", + "type": "t_uint64", + "offset": 0, + "slot": "0" + }, + { + "label": "_initializing", + "type": "t_bool", + "offset": 8, + "slot": "0" + } + ], + "numberOfBytes": "32" + }, + "t_uint64": { + "label": "uint64", + "numberOfBytes": "8" + }, + "t_address": { + "label": "address", + "numberOfBytes": "20" + }, + "t_array(t_address)dyn_storage": { + "label": "address[]", + "numberOfBytes": "32" + }, + "t_array(t_struct(InvitationWithdrawRecordType)5868_storage)dyn_storage": { + "label": "struct InvitationWithdrawRecordType[]", + "numberOfBytes": "32" + }, + "t_array(t_struct(PledgeType)5849_storage)dyn_storage": { + "label": "struct PledgeType[]", + "numberOfBytes": "32" + }, + "t_array(t_struct(PledgeWithdrawRecordType)5879_storage)dyn_storage": { + "label": "struct PledgeWithdrawRecordType[]", + "numberOfBytes": "32" + }, + "t_array(t_struct(ProductInfo)5854_storage)dyn_storage": { + "label": "struct ProductInfo[]", + "numberOfBytes": "32" + }, + "t_array(t_uint256)dyn_storage": { + "label": "uint256[]", + "numberOfBytes": "32" + }, + "t_contract(NFT)3942": { + "label": "contract NFT", + "numberOfBytes": "20" + }, + "t_contract(Pool)6045": { + "label": "contract Pool", + "numberOfBytes": "20" + }, + "t_mapping(t_address,t_array(t_address)dyn_storage)": { + "label": "mapping(address => address[])", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_array(t_struct(InvitationWithdrawRecordType)5868_storage)dyn_storage)": { + "label": "mapping(address => struct InvitationWithdrawRecordType[])", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_array(t_struct(PledgeType)5849_storage)dyn_storage)": { + "label": "mapping(address => struct PledgeType[])", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_array(t_struct(PledgeWithdrawRecordType)5879_storage)dyn_storage)": { + "label": "mapping(address => struct PledgeWithdrawRecordType[])", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_array(t_uint256)dyn_storage)": { + "label": "mapping(address => uint256[])", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_struct(RecommendObjType)5863_storage)": { + "label": "mapping(address => struct RecommendObjType)", + "numberOfBytes": "32" + }, + "t_mapping(t_uint256,t_struct(PledgeType)5849_storage)": { + "label": "mapping(uint256 => struct PledgeType)", + "numberOfBytes": "32" + }, + "t_struct(InvitationWithdrawRecordType)5868_storage": { + "label": "struct InvitationWithdrawRecordType", + "members": [ + { + "label": "amount", + "type": "t_uint256", + "offset": 0, + "slot": "0" + }, + { + "label": "createTime", + "type": "t_uint256", + "offset": 0, + "slot": "1" + } + ], + "numberOfBytes": "64" + }, + "t_struct(PledgeType)5849_storage": { + "label": "struct PledgeType", + "members": [ + { + "label": "tokenId", + "type": "t_uint256", + "offset": 0, + "slot": "0" + }, + { + "label": "startTime", + "type": "t_uint256", + "offset": 0, + "slot": "1" + }, + { + "label": "endTime", + "type": "t_uint256", + "offset": 0, + "slot": "2" + }, + { + "label": "withdrawTime", + "type": "t_uint256", + "offset": 0, + "slot": "3" + }, + { + "label": "pledgeAmount", + "type": "t_uint256", + "offset": 0, + "slot": "4" + }, + { + "label": "rate", + "type": "t_uint256", + "offset": 0, + "slot": "5" + }, + { + "label": "pledgeDay", + "type": "t_uint256", + "offset": 0, + "slot": "6" + }, + { + "label": "sender", + "type": "t_address", + "offset": 0, + "slot": "7" + }, + { + "label": "isBlack", + "type": "t_bool", + "offset": 20, + "slot": "7" + } + ], + "numberOfBytes": "256" + }, + "t_struct(PledgeWithdrawRecordType)5879_storage": { + "label": "struct PledgeWithdrawRecordType", + "members": [ + { + "label": "amount", + "type": "t_uint256", + "offset": 0, + "slot": "0" + }, + { + "label": "createTime", + "type": "t_uint256", + "offset": 0, + "slot": "1" + }, + { + "label": "tokenId", + "type": "t_uint256", + "offset": 0, + "slot": "2" + }, + { + "label": "pledgeDay", + "type": "t_uint256", + "offset": 0, + "slot": "3" + }, + { + "label": "_type", + "type": "t_uint256", + "offset": 0, + "slot": "4" + } + ], + "numberOfBytes": "160" + }, + "t_struct(ProductInfo)5854_storage": { + "label": "struct ProductInfo", + "members": [ + { + "label": "day", + "type": "t_uint256", + "offset": 0, + "slot": "0" + }, + { + "label": "rate", + "type": "t_uint256", + "offset": 0, + "slot": "1" + } + ], + "numberOfBytes": "64" + }, + "t_struct(RecommendObjType)5863_storage": { + "label": "struct RecommendObjType", + "members": [ + { + "label": "key", + "type": "t_address", + "offset": 0, + "slot": "0" + }, + { + "label": "referrer", + "type": "t_address", + "offset": 0, + "slot": "1" + }, + { + "label": "bindTime", + "type": "t_uint256", + "offset": 0, + "slot": "2" + }, + { + "label": "contribute", + "type": "t_uint256", + "offset": 0, + "slot": "3" + } + ], + "numberOfBytes": "128" + }, + "t_uint256": { + "label": "uint256", + "numberOfBytes": "32" + } + }, + "namespaces": { + "erc7201:openzeppelin.storage.Initializable": [ + { + "contract": "Initializable", + "label": "_initialized", + "type": "t_uint64", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:69", + "offset": 0, + "slot": "0" + }, + { + "contract": "Initializable", + "label": "_initializing", + "type": "t_bool", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:73", + "offset": 8, + "slot": "0" + } + ] + } + } + }, + "dc69575b5ea3e919d78a28c1bffbdca3e8bd14bda62cf41752b14edc92302451": { + "address": "0xBaD3162fcaa9D2db66d418EBd9730aa30e8B0Dd9", + "txHash": "0xb0f261726091f8d85744e0459ea4a063c35bb9bc85360068a3f74a895e10c7fe", + "layout": { + "solcVersion": "0.8.24", + "storage": [ + { + "label": "nftContract", + "offset": 0, + "slot": "0", + "type": "t_contract(NFT)3942", + "contract": "Pledge", + "src": "contracts/Pledge.sol:14" + }, + { + "label": "poolContract", + "offset": 0, + "slot": "1", + "type": "t_contract(Pool)6047", + "contract": "Pledge", + "src": "contracts/Pledge.sol:15" + }, + { + "label": "productInfo", + "offset": 0, + "slot": "2", + "type": "t_array(t_struct(ProductInfo)5856_storage)dyn_storage", + "contract": "Pledge", + "src": "contracts/Pledge.sol:16" + }, + { + "label": "pledges", + "offset": 0, + "slot": "3", + "type": "t_mapping(t_uint256,t_struct(PledgeType)5851_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:17" + }, + { + "label": "pledgeRecords", + "offset": 0, + "slot": "4", + "type": "t_mapping(t_address,t_array(t_struct(PledgeType)5851_storage)dyn_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:18" + }, + { + "label": "invitationPledges", + "offset": 0, + "slot": "5", + "type": "t_mapping(t_uint256,t_struct(PledgeType)5851_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:19" + }, + { + "label": "recommendObj", + "offset": 0, + "slot": "6", + "type": "t_mapping(t_address,t_struct(RecommendObjType)5865_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:20" + }, + { + "label": "invitationTokens", + "offset": 0, + "slot": "7", + "type": "t_mapping(t_address,t_array(t_uint256)dyn_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:21" + }, + { + "label": "invitationAddress", + "offset": 0, + "slot": "8", + "type": "t_mapping(t_address,t_array(t_address)dyn_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:22" + }, + { + "label": "pledgeWithdrawRecord", + "offset": 0, + "slot": "9", + "type": "t_mapping(t_address,t_array(t_struct(PledgeWithdrawRecordType)5881_storage)dyn_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:23" + }, + { + "label": "invitationWithdrawRecord", + "offset": 0, + "slot": "10", + "type": "t_mapping(t_address,t_array(t_struct(InvitationWithdrawRecordType)5870_storage)dyn_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:24" + }, + { + "label": "blackList", + "offset": 0, + "slot": "11", + "type": "t_array(t_address)dyn_storage", + "contract": "Pledge", + "src": "contracts/Pledge.sol:26" + }, + { + "label": "whiteList", + "offset": 0, + "slot": "12", + "type": "t_array(t_address)dyn_storage", + "contract": "Pledge", + "src": "contracts/Pledge.sol:27" + }, + { + "label": "pledgeDestoryRecords", + "offset": 0, + "slot": "13", + "type": "t_mapping(t_address,t_array(t_struct(PledgeType)5851_storage)dyn_storage)", + "contract": "Pledge", + "src": "contracts/Pledge.sol:28" + }, + { + "label": "invitationRate", + "offset": 0, + "slot": "14", + "type": "t_uint256", + "contract": "Pledge", + "src": "contracts/Pledge.sol:29" + }, + { + "label": "nextTokenId", + "offset": 0, + "slot": "15", + "type": "t_uint256", + "contract": "Pledge", + "src": "contracts/Pledge.sol:30" + }, + { + "label": "pledgeStatus", + "offset": 0, + "slot": "16", + "type": "t_bool", + "contract": "Pledge", + "src": "contracts/Pledge.sol:31" + }, + { + "label": "dayTime", + "offset": 0, + "slot": "17", + "type": "t_uint256", + "contract": "Pledge", + "src": "contracts/Pledge.sol:32" + } + ], + "types": { + "t_bool": { + "label": "bool", + "numberOfBytes": "1" + }, + "t_struct(InitializableStorage)10_storage": { + "label": "struct Initializable.InitializableStorage", + "members": [ + { + "label": "_initialized", + "type": "t_uint64", + "offset": 0, + "slot": "0" + }, + { + "label": "_initializing", + "type": "t_bool", + "offset": 8, + "slot": "0" + } + ], + "numberOfBytes": "32" + }, + "t_uint64": { + "label": "uint64", + "numberOfBytes": "8" + }, + "t_address": { + "label": "address", + "numberOfBytes": "20" + }, + "t_array(t_address)dyn_storage": { + "label": "address[]", + "numberOfBytes": "32" + }, + "t_array(t_struct(InvitationWithdrawRecordType)5870_storage)dyn_storage": { + "label": "struct InvitationWithdrawRecordType[]", + "numberOfBytes": "32" + }, + "t_array(t_struct(PledgeType)5851_storage)dyn_storage": { + "label": "struct PledgeType[]", + "numberOfBytes": "32" + }, + "t_array(t_struct(PledgeWithdrawRecordType)5881_storage)dyn_storage": { + "label": "struct PledgeWithdrawRecordType[]", + "numberOfBytes": "32" + }, + "t_array(t_struct(ProductInfo)5856_storage)dyn_storage": { + "label": "struct ProductInfo[]", + "numberOfBytes": "32" + }, + "t_array(t_uint256)dyn_storage": { + "label": "uint256[]", + "numberOfBytes": "32" + }, + "t_contract(NFT)3942": { + "label": "contract NFT", + "numberOfBytes": "20" + }, + "t_contract(Pool)6047": { + "label": "contract Pool", + "numberOfBytes": "20" + }, + "t_mapping(t_address,t_array(t_address)dyn_storage)": { + "label": "mapping(address => address[])", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_array(t_struct(InvitationWithdrawRecordType)5870_storage)dyn_storage)": { + "label": "mapping(address => struct InvitationWithdrawRecordType[])", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_array(t_struct(PledgeType)5851_storage)dyn_storage)": { + "label": "mapping(address => struct PledgeType[])", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_array(t_struct(PledgeWithdrawRecordType)5881_storage)dyn_storage)": { + "label": "mapping(address => struct PledgeWithdrawRecordType[])", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_array(t_uint256)dyn_storage)": { + "label": "mapping(address => uint256[])", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_struct(RecommendObjType)5865_storage)": { + "label": "mapping(address => struct RecommendObjType)", + "numberOfBytes": "32" + }, + "t_mapping(t_uint256,t_struct(PledgeType)5851_storage)": { + "label": "mapping(uint256 => struct PledgeType)", + "numberOfBytes": "32" + }, + "t_struct(InvitationWithdrawRecordType)5870_storage": { + "label": "struct InvitationWithdrawRecordType", + "members": [ + { + "label": "amount", + "type": "t_uint256", + "offset": 0, + "slot": "0" + }, + { + "label": "createTime", + "type": "t_uint256", + "offset": 0, + "slot": "1" + } + ], + "numberOfBytes": "64" + }, + "t_struct(PledgeType)5851_storage": { + "label": "struct PledgeType", + "members": [ + { + "label": "tokenId", + "type": "t_uint256", + "offset": 0, + "slot": "0" + }, + { + "label": "startTime", + "type": "t_uint256", + "offset": 0, + "slot": "1" + }, + { + "label": "endTime", + "type": "t_uint256", + "offset": 0, + "slot": "2" + }, + { + "label": "withdrawTime", + "type": "t_uint256", + "offset": 0, + "slot": "3" + }, + { + "label": "pledgeAmount", + "type": "t_uint256", + "offset": 0, + "slot": "4" + }, + { + "label": "rate", + "type": "t_uint256", + "offset": 0, + "slot": "5" + }, + { + "label": "pledgeDay", + "type": "t_uint256", + "offset": 0, + "slot": "6" + }, + { + "label": "sender", + "type": "t_address", + "offset": 0, + "slot": "7" + }, + { + "label": "isBlack", + "type": "t_bool", + "offset": 20, + "slot": "7" + } + ], + "numberOfBytes": "256" + }, + "t_struct(PledgeWithdrawRecordType)5881_storage": { + "label": "struct PledgeWithdrawRecordType", + "members": [ + { + "label": "amount", + "type": "t_uint256", + "offset": 0, + "slot": "0" + }, + { + "label": "createTime", + "type": "t_uint256", + "offset": 0, + "slot": "1" + }, + { + "label": "tokenId", + "type": "t_uint256", + "offset": 0, + "slot": "2" + }, + { + "label": "pledgeDay", + "type": "t_uint256", + "offset": 0, + "slot": "3" + }, + { + "label": "_type", + "type": "t_uint256", + "offset": 0, + "slot": "4" + } + ], + "numberOfBytes": "160" + }, + "t_struct(ProductInfo)5856_storage": { + "label": "struct ProductInfo", + "members": [ + { + "label": "day", + "type": "t_uint256", + "offset": 0, + "slot": "0" + }, + { + "label": "rate", + "type": "t_uint256", + "offset": 0, + "slot": "1" + } + ], + "numberOfBytes": "64" + }, + "t_struct(RecommendObjType)5865_storage": { + "label": "struct RecommendObjType", + "members": [ + { + "label": "key", + "type": "t_address", + "offset": 0, + "slot": "0" + }, + { + "label": "referrer", + "type": "t_address", + "offset": 0, + "slot": "1" + }, + { + "label": "bindTime", + "type": "t_uint256", + "offset": 0, + "slot": "2" + }, + { + "label": "contribute", + "type": "t_uint256", + "offset": 0, + "slot": "3" + } + ], + "numberOfBytes": "128" + }, + "t_uint256": { + "label": "uint256", + "numberOfBytes": "32" + } + }, + "namespaces": { + "erc7201:openzeppelin.storage.Initializable": [ + { + "contract": "Initializable", + "label": "_initialized", + "type": "t_uint64", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:69", + "offset": 0, + "slot": "0" + }, + { + "contract": "Initializable", + "label": "_initializing", + "type": "t_bool", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:73", + "offset": 8, + "slot": "0" + } + ] + } + } } } } diff --git a/contracts/Pledge.sol b/contracts/Pledge.sol index 13b52e4..90e3611 100644 --- a/contracts/Pledge.sol +++ b/contracts/Pledge.sol @@ -6,66 +6,80 @@ import "./NFT.sol"; import "./Pool.sol"; import "./PledgeType.sol"; import "./Utils.sol"; +import "./SafeMath.sol"; contract Pledge is Initializable { + using SafeMath for uint256; NFT nftContract; Pool poolContract; ProductInfo[] public productInfo; - mapping(uint256 => PledgeType) pledges; - mapping(address => PledgeType[]) public pledgeRecords; - mapping(uint256 => PledgeType) public invitationPledges; + mapping(uint256 => PledgeType) pledges; + mapping(address => PledgeType[]) public pledgeRecords; + mapping(uint256 => PledgeType) public invitationPledges; mapping(address => RecommendObjType) public recommendObj; - mapping(address => uint256[]) public invitationTokens; - mapping(address => address[]) public invitationAddress; + mapping(address => uint256[]) public invitationTokens; + mapping(address => address[]) public invitationAddress; mapping(address => PledgeWithdrawRecordType[]) public pledgeWithdrawRecord; - mapping(address => InvitationWithdrawRecordType[]) public invitationWithdrawRecord; - address[] public blackList; + mapping(address => InvitationWithdrawRecordType[]) + public invitationWithdrawRecord; + address[] public blackList; address[] public whiteList; mapping(address => PledgeType[]) public pledgeDestoryRecords; - uint256 public invitationRate; + uint256 public invitationRate; uint256 public nextTokenId; bool public pledgeStatus; uint256 public dayTime; - function initialize(address nftAddress, address poolAddress) public initializer { + function initialize( + address nftAddress, + address poolAddress + ) public initializer { nftContract = NFT(nftAddress); poolContract = Pool(poolAddress); nextTokenId = 1; - invitationRate = 1; + invitationRate = 100; pledgeStatus = false; dayTime = 1 days; - productInfo.push(ProductInfo(180, 14)); - productInfo.push(ProductInfo(270, 15)); - productInfo.push(ProductInfo(360, 16)); + productInfo.push(ProductInfo(180, 1408)); + productInfo.push(ProductInfo(270, 1521)); + productInfo.push(ProductInfo(360, 1623)); } - modifier onlyAdmin (){ + modifier onlyAdmin() { address[] memory _admins = nftContract.getAdmin(); bool _isAdmin = Utils.isAdmin(_admins, msg.sender); - require(_isAdmin == true,"For administrators only"); + require(_isAdmin == true, "For administrators only"); _; } - modifier onlyBlacks (){ + modifier onlyBlacks() { bool _isBlack = Utils.isAdmin(blackList, msg.sender); - require(_isBlack == false,"You've been blacklisted."); + require(_isBlack == false, "You've been blacklisted."); _; } - function getPledgeRecords(address _owner) public view returns(PledgeType[] memory){ + function getPledgeRecords( + address _owner + ) public view returns (PledgeType[] memory) { return pledgeRecords[_owner]; } - function getPledgeWithdrawRecord(address _owner) public view returns(PledgeWithdrawRecordType[] memory){ + function getPledgeWithdrawRecord( + address _owner + ) public view returns (PledgeWithdrawRecordType[] memory) { return pledgeWithdrawRecord[_owner]; } - function getInvitationWithdrawRecord(address _owner) public view returns(InvitationWithdrawRecordType[] memory){ + function getInvitationWithdrawRecord( + address _owner + ) public view returns (InvitationWithdrawRecordType[] memory) { return invitationWithdrawRecord[_owner]; } - function getPledgeDestoryRecords(address _owner) public view returns(PledgeType[] memory){ + function getPledgeDestoryRecords( + address _owner + ) public view returns (PledgeType[] memory) { return pledgeDestoryRecords[_owner]; } @@ -73,7 +87,9 @@ contract Pledge is Initializable { return productInfo; } - function getOwnerAllPledgeInfo( address _ownerAddress ) public view returns (PledgeType[] memory result) { + function getOwnerAllPledgeInfo( + address _ownerAddress + ) public view returns (PledgeType[] memory result) { uint256[] memory tokens = getOwnerAllTokens(_ownerAddress); result = new PledgeType[](tokens.length); for (uint256 i = 0; i < tokens.length; i++) { @@ -83,9 +99,15 @@ contract Pledge is Initializable { } function bindRecommend(address _referrer) internal { - require(recommendObj[msg.sender].key == address(0),"Already have recommenders"); - require(msg.sender != _referrer ,"You can't recommend yourself."); - require(recommendObj[_referrer].referrer != msg.sender,"Can't recommend each other"); + require( + recommendObj[msg.sender].key == address(0), + "Already have recommenders" + ); + require(msg.sender != _referrer, "You can't recommend yourself."); + require( + recommendObj[_referrer].referrer != msg.sender, + "Can't recommend each other" + ); recommendObj[msg.sender] = RecommendObjType( msg.sender, _referrer, @@ -94,7 +116,7 @@ contract Pledge is Initializable { ); invitationAddress[_referrer].push(msg.sender); } - + function setInvitationIncomes(PledgeType memory _pledge) internal { address recommendAddr = recommendObj[msg.sender].referrer; PledgeType memory _invitationPledge = _pledge; @@ -103,9 +125,11 @@ contract Pledge is Initializable { uint256 rate = _invitationPledge.rate; uint256 day = _invitationPledge.pledgeDay; uint256 tokenId = _invitationPledge.tokenId; - uint256 contribute = (((amount * rate) / 365) * day) / 100; - recommendObj[msg.sender].contribute += contribute; - + // uint256 contribute = (((amount * rate) / 365) * day) / 100; + uint256 contribute = amount.mul(rate).div(365).mul(day).div(10000); + + recommendObj[msg.sender].contribute = contribute.add(recommendObj[msg.sender].contribute); + if (invitationTokens[recommendAddr].length == 0) { invitationTokens[recommendAddr] = new uint256[](0); } @@ -116,10 +140,14 @@ contract Pledge is Initializable { invitationPledges[tokenId] = _invitationPledge; } - function pledge(uint256 amount, uint256 index, address _referrer) external onlyBlacks { + function pledge( + uint256 amount, + uint256 index, + address _referrer + ) external onlyBlacks { bool _isWhite = Utils.isAdmin(whiteList, msg.sender); - if(!_isWhite){ - require(pledgeStatus == false,"The pledge is closed."); + if (!_isWhite) { + require(pledgeStatus == false, "The pledge is closed."); } require(amount >= 1, "Minimum pledge 1FIL"); require(index < productInfo.length, "Product does not exist"); @@ -133,16 +161,27 @@ contract Pledge is Initializable { uint256 startTime = block.timestamp; uint256 endTime = block.timestamp + (item.day * dayTime); nftContract.mint(msg.sender, tokenId); - PledgeType memory _pledge = PledgeType(tokenId,startTime,endTime,startTime,amount,item.rate,item.day,msg.sender,false); + PledgeType memory _pledge = PledgeType( + tokenId, + startTime, + endTime, + startTime, + amount, + item.rate, + item.day, + msg.sender, + false + ); pledges[tokenId] = _pledge; pledgeRecords[msg.sender].push(_pledge); if (recommendObj[msg.sender].key != address(0)) { setInvitationIncomes(_pledge); } - } - function getOwnerAllTokens( address _ownerAddress ) public view returns (uint256[] memory) { + function getOwnerAllTokens( + address _ownerAddress + ) public view returns (uint256[] memory) { uint256 nftAmount = nftContract.balanceOf(_ownerAddress); uint256[] memory tokens = new uint256[](nftAmount); for (uint256 i = 0; i < nftAmount; i++) { @@ -151,20 +190,24 @@ contract Pledge is Initializable { return tokens; } - function calculateInterest( PledgeType memory _pledge ) public view returns (uint256) { + function calculateInterest( + PledgeType memory _pledge + ) public view returns (uint256) { uint256 total_amount = _pledge.pledgeAmount; uint256 currentTime = block.timestamp; uint256 withdrawTime = _pledge.withdrawTime; uint256 rate = _pledge.rate; - if(_pledge.endTime < currentTime){ + if (_pledge.endTime < currentTime) { currentTime = _pledge.endTime; } uint256 daysPassed = (currentTime - withdrawTime) / dayTime; - uint256 dailyShare = (((total_amount * rate) / 365) * daysPassed) / 100; + uint256 dailyShare = total_amount.mul(rate).div(365).mul(daysPassed).div(10000); return dailyShare; } - function getWithdrawbleAmount( address _owner ) public view returns (uint256) { + function getWithdrawbleAmount( + address _owner + ) public view returns (uint256) { uint256[] memory tokens = getOwnerAllTokens(_owner); if (tokens.length <= 0) return 0; uint256 _total_interest = 0; @@ -178,39 +221,59 @@ contract Pledge is Initializable { function withdraAllInterest() external onlyBlacks { uint256 _total_interest = getWithdrawbleAmount(msg.sender); - require(_total_interest > 0, "Withdrawal amount must be greater than 0"); + require( + _total_interest > 0, + "Withdrawal amount must be greater than 0" + ); uint256[] memory tokens = getOwnerAllTokens(msg.sender); - for(uint256 i=0;i 0, "Withdrawal amount must be greater than 0"); uint256 _withdrawTime = block.timestamp; - if(data.endTime < _withdrawTime){ + if (data.endTime < _withdrawTime) { _withdrawTime = data.endTime; } poolContract.withdraw(msg.sender, _interest); pledges[tokenId].withdrawTime = _withdrawTime; - pledgeWithdrawRecord[msg.sender].push(PledgeWithdrawRecordType(_interest,block.timestamp,data.tokenId,data.pledgeDay,1)); - + pledgeWithdrawRecord[msg.sender].push( + PledgeWithdrawRecordType( + _interest, + block.timestamp, + data.tokenId, + data.pledgeDay, + 1 + ) + ); } - function getOwnerInvitationPledges( address addr ) public view returns (PledgeType[] memory result) { + function getOwnerInvitationPledges( + address addr + ) public view returns (PledgeType[] memory result) { uint256[] memory _tokens = invitationTokens[addr]; result = new PledgeType[](_tokens.length); for (uint256 i = 0; i < _tokens.length; i++) { @@ -220,84 +283,97 @@ contract Pledge is Initializable { return result; } - function getOwnerAllInvitationWithdrawAmout(address owner) public view returns(uint256){ + function getOwnerAllInvitationWithdrawAmout( + address owner + ) public view returns (uint256) { uint256 _income = 0; PledgeType[] memory _pledges = getOwnerInvitationPledges(owner); - for(uint256 i=0;i<_pledges.length;i++){ + for (uint256 i = 0; i < _pledges.length; i++) { PledgeType memory data = _pledges[i]; _income += calculateInterest(data); } return _income; } - function withdraInvitationAllInterest() external onlyBlacks { - uint256 _total_interest = getOwnerAllInvitationWithdrawAmout(msg.sender); - require(_total_interest > 0, "Withdrawal amount must be greater than 0"); + function withdraInvitationAllInterest() external onlyBlacks { + uint256 _total_interest = getOwnerAllInvitationWithdrawAmout( + msg.sender + ); + require( + _total_interest > 0, + "Withdrawal amount must be greater than 0" + ); uint256[] memory tokens = invitationTokens[msg.sender]; - for(uint256 i=0;i 0, "Withdrawal amount must be greater than 0"); uint256 _withdrawTime = block.timestamp; - if(data.endTime < _withdrawTime){ + if (data.endTime < _withdrawTime) { _withdrawTime = data.endTime; } poolContract.withdraw(msg.sender, _interest); uint256 currentTime = block.timestamp; invitationPledges[tokenId].withdrawTime = _withdrawTime; - invitationWithdrawRecord[msg.sender].push(InvitationWithdrawRecordType(_interest,currentTime)); + invitationWithdrawRecord[msg.sender].push( + InvitationWithdrawRecordType(_interest, currentTime) + ); } - function getAllInvitationMember( address addr ) public view returns (RecommendObjType[] memory result) { + function getAllInvitationMember( + address addr + ) public view returns (RecommendObjType[] memory result) { address[] memory _addresss = invitationAddress[addr]; result = new RecommendObjType[](_addresss.length); for (uint256 i = 0; i < _addresss.length; i++) { result[i] = recommendObj[_addresss[i]]; } return result; - } + } - function getCurrentTime() public view returns (uint256){ + function getCurrentTime() public view returns (uint256) { uint256 currentTime = block.timestamp; return currentTime; } - function destroyPledge(uint256 tokenId) external onlyBlacks{ + function destroyPledge(uint256 tokenId) external onlyBlacks { address _owner = nftContract.ownerOf(tokenId); - require(_owner == msg.sender,"You're not a contract owner."); + require(_owner == msg.sender, "You're not a contract owner."); uint256 currentTime = block.timestamp; PledgeType memory data = pledges[tokenId]; - require(data.endTime < currentTime,"Unexpired Pledge Agreement"); - nftContract.transferFrom(msg.sender,address(this), tokenId); + require(data.endTime < currentTime, "Unexpired Pledge Agreement"); + nftContract.transferFrom(msg.sender, address(this), tokenId); poolContract.withdraw(msg.sender, data.pledgeAmount); data.withdrawTime = currentTime; pledgeDestoryRecords[msg.sender].push(data); - } + } - function setInvitationRate(uint256 _rate) external onlyAdmin{ + function setInvitationRate(uint256 _rate) external onlyAdmin { invitationRate = _rate; } @@ -305,67 +381,85 @@ contract Pledge is Initializable { pledgeStatus = _status; } - function addBlackOrWhiteList(address[] memory _blacks,uint256 _type) external onlyAdmin { - require(_blacks.length>0,"Enter at least one address"); - if(_type == 1){ + function addBlackOrWhiteList( + address[] memory _blacks, + uint256 _type + ) external onlyAdmin { + require(_blacks.length > 0, "Enter at least one address"); + if (_type == 1) { address[] memory blacks = Utils.addAdmin(blackList, _blacks); - blackList = blacks; + blackList = blacks; } - if(_type == 2){ + if (_type == 2) { address[] memory whites = Utils.addAdmin(whiteList, _blacks); - whiteList = whites; + whiteList = whites; } } - function delBlackOrWhiteList(address[] memory _blacks,uint256 _type) external onlyAdmin{ - require(_blacks.length>0,"Enter at least one address"); - if(_type == 1){ + function delBlackOrWhiteList( + address[] memory _blacks, + uint256 _type + ) external onlyAdmin { + require(_blacks.length > 0, "Enter at least one address"); + if (_type == 1) { address[] memory blacks = Utils.deleteAdmin(blackList, _blacks); blackList = blacks; } - if(_type == 2){ + if (_type == 2) { address[] memory whites = Utils.deleteAdmin(whiteList, _blacks); - whiteList = whites; + whiteList = whites; } } - function getBlackOrWhiteList(uint256 _type) public view returns (address[] memory) { + function getBlackOrWhiteList( + uint256 _type + ) public view returns (address[] memory) { return _type == 1 ? blackList : whiteList; } - function setProductInfo(uint256[] memory _days,uint256[] memory _rates) external onlyAdmin { + function setProductInfo( + uint256[] memory _days, + uint256[] memory _rates + ) external onlyAdmin { delete productInfo; - for(uint256 i=0;i<3;i++){ - productInfo.push(ProductInfo(_days[i],_rates[i])); + for (uint256 i = 0; i < 3; i++) { + productInfo.push(ProductInfo(_days[i], _rates[i])); } } - function getDetails(uint256 tokenId,uint256 _type) public view returns(PledgeType memory){ - if(_type == 1){ + function getDetails( + uint256 tokenId, + uint256 _type + ) public view returns (PledgeType memory) { + if (_type == 1) { return pledges[tokenId]; } return invitationPledges[tokenId]; } function addNftBalcks(uint256[] memory _tokenIds) external onlyAdmin { - require(_tokenIds.length > 0,"Parameter is empty"); + require(_tokenIds.length > 0, "Parameter is empty"); nftContract.addBlacks(_tokenIds); - for(uint256 i=0;i<_tokenIds.length;i++){ + for (uint256 i = 0; i < _tokenIds.length; i++) { uint256 _id = _tokenIds[i]; require(pledges[_id].sender != address(0), "NFT ID does not exist"); - require(!pledges[_id].isBlack,"NFT ID already exists"); + require(!pledges[_id].isBlack, "NFT ID already exists"); pledges[_id].isBlack = true; } } function deleteNftBlacks(uint256[] memory _ids) external onlyAdmin { - require(_ids.length > 0,"Parameter is empty"); + require(_ids.length > 0, "Parameter is empty"); nftContract.delBlacks(_ids); - for(uint256 i=0;i<_ids.length;i++){ + for (uint256 i = 0; i < _ids.length; i++) { uint256 _id = _ids[i]; require(pledges[_id].sender != address(0), "NFT ID does not exist"); pledges[_id].isBlack = false; } } -} \ No newline at end of file + function setDayTime(uint256 time) external onlyAdmin { + dayTime = time; + } + +} diff --git a/contracts/SafeMath.sol b/contracts/SafeMath.sol new file mode 100644 index 0000000..7f6a22a --- /dev/null +++ b/contracts/SafeMath.sol @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; + + +// TODO(zx): Replace all instances of SafeMath with OZ implementation +library SafeMath { + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + assert(a == b * c + (a % b)); // There is no case in which this doesn't hold + return c; + } + +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 8a57276..61f025b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,9 @@ "packages": { "": { "name": "hardhat-project", + "dependencies": { + "@nomicfoundation/edr-darwin-arm64": "^0.3.8" + }, "devDependencies": { "@nomicfoundation/hardhat-chai-matchers": "^2.0.6", "@nomicfoundation/hardhat-ethers": "^3.0.5", @@ -1084,17 +1087,9 @@ } }, "node_modules/@nomicfoundation/edr-darwin-arm64": { - "version": "0.3.3", - "resolved": "https://registry.npmjs.org/@nomicfoundation/edr-darwin-arm64/-/edr-darwin-arm64-0.3.3.tgz", - "integrity": "sha512-E9VGsUD+1Ga4mn/5ooHsMi8JEfhZbKP6CXN/BhJ8kXbIC10NqTD1RuhCKGRtYq4vqH/3Nfq25Xg8E8RWOF4KBQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "darwin" - ], + "version": "0.3.8", + "resolved": "https://registry.npmjs.org/@nomicfoundation/edr-darwin-arm64/-/edr-darwin-arm64-0.3.8.tgz", + "integrity": "sha512-eB0leCexS8sQEmfyD72cdvLj9djkBzQGP4wSQw6SNf2I4Sw4Cnzb3d45caG2FqFFjbvfqL0t+badUUIceqQuMw==", "engines": { "node": ">= 18" } @@ -1227,6 +1222,22 @@ "node": ">= 18" } }, + "node_modules/@nomicfoundation/edr/node_modules/@nomicfoundation/edr-darwin-arm64": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/@nomicfoundation/edr-darwin-arm64/-/edr-darwin-arm64-0.3.3.tgz", + "integrity": "sha512-E9VGsUD+1Ga4mn/5ooHsMi8JEfhZbKP6CXN/BhJ8kXbIC10NqTD1RuhCKGRtYq4vqH/3Nfq25Xg8E8RWOF4KBQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 18" + } + }, "node_modules/@nomicfoundation/ethereumjs-common": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/@nomicfoundation/ethereumjs-common/-/ethereumjs-common-4.0.4.tgz", @@ -8901,14 +8912,21 @@ "@nomicfoundation/edr-win32-arm64-msvc": "0.3.3", "@nomicfoundation/edr-win32-ia32-msvc": "0.3.3", "@nomicfoundation/edr-win32-x64-msvc": "0.3.3" + }, + "dependencies": { + "@nomicfoundation/edr-darwin-arm64": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/@nomicfoundation/edr-darwin-arm64/-/edr-darwin-arm64-0.3.3.tgz", + "integrity": "sha512-E9VGsUD+1Ga4mn/5ooHsMi8JEfhZbKP6CXN/BhJ8kXbIC10NqTD1RuhCKGRtYq4vqH/3Nfq25Xg8E8RWOF4KBQ==", + "dev": true, + "optional": true + } } }, "@nomicfoundation/edr-darwin-arm64": { - "version": "0.3.3", - "resolved": "https://registry.npmjs.org/@nomicfoundation/edr-darwin-arm64/-/edr-darwin-arm64-0.3.3.tgz", - "integrity": "sha512-E9VGsUD+1Ga4mn/5ooHsMi8JEfhZbKP6CXN/BhJ8kXbIC10NqTD1RuhCKGRtYq4vqH/3Nfq25Xg8E8RWOF4KBQ==", - "dev": true, - "optional": true + "version": "0.3.8", + "resolved": "https://registry.npmjs.org/@nomicfoundation/edr-darwin-arm64/-/edr-darwin-arm64-0.3.8.tgz", + "integrity": "sha512-eB0leCexS8sQEmfyD72cdvLj9djkBzQGP4wSQw6SNf2I4Sw4Cnzb3d45caG2FqFFjbvfqL0t+badUUIceqQuMw==" }, "@nomicfoundation/edr-darwin-x64": { "version": "0.3.3", @@ -9038,7 +9056,8 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/@nomicfoundation/hardhat-toolbox/-/hardhat-toolbox-4.0.0.tgz", "integrity": "sha512-jhcWHp0aHaL0aDYj8IJl80v4SZXWMS1A2XxXa1CA6pBiFfJKuZinCkO6wb+POAt0LIfXB3gA3AgdcOccrcwBwA==", - "dev": true + "dev": true, + "requires": {} }, "@nomicfoundation/hardhat-verify": { "version": "2.0.5", @@ -9155,7 +9174,8 @@ "version": "5.0.2", "resolved": "https://registry.npmjs.org/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-5.0.2.tgz", "integrity": "sha512-0MmkHSHiW2NRFiT9/r5Lu4eJq5UJ4/tzlOgYXNAIj/ONkQTVnz22pLxDvp4C4uZ9he7ZFvGn3Driptn1/iU7tQ==", - "dev": true + "dev": true, + "requires": {} }, "@openzeppelin/defender-admin-client": { "version": "1.54.1", @@ -11121,7 +11141,8 @@ "version": "8.5.0", "resolved": "https://registry.npmjs.org/ws/-/ws-8.5.0.tgz", "integrity": "sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==", - "dev": true + "dev": true, + "requires": {} } } }, @@ -13678,7 +13699,8 @@ "version": "7.0.3", "resolved": "https://registry.npmjs.org/ts-essentials/-/ts-essentials-7.0.3.tgz", "integrity": "sha512-8+gr5+lqO3G84KdiTSMRLtuyJ+nTBVRKuCrK4lidMPdVeEp0uqC875uE5NMcaA7YYMN7XsNiFQuMvasF8HT/xQ==", - "dev": true + "dev": true, + "requires": {} }, "ts-node": { "version": "10.9.2", @@ -14158,7 +14180,8 @@ "version": "7.4.6", "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz", "integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==", - "dev": true + "dev": true, + "requires": {} }, "y18n": { "version": "5.0.8", diff --git a/package.json b/package.json index 1f79f31..34646f6 100644 --- a/package.json +++ b/package.json @@ -28,5 +28,8 @@ "deploy:dev": "npx hardhat run --network bscTest scripts/deployProxy.ts", "deploy:local": "npx hardhat run --network local scripts/deployProxy.ts", "deploy:prod": "npx hardhat run --network bscMain scripts/deployProxy.ts" + }, + "dependencies": { + "@nomicfoundation/edr-darwin-arm64": "^0.3.8" } } diff --git a/scripts/deployProxy.ts b/scripts/deployProxy.ts index 1339e98..695d95c 100644 --- a/scripts/deployProxy.ts +++ b/scripts/deployProxy.ts @@ -1,3 +1,4 @@ +import { toBigInt } from "ethers"; import { ethers, upgrades } from "hardhat"; async function main() { @@ -8,11 +9,11 @@ async function main() { const FIL_ADDRESS = process.env.FIL_ADDRESS // const FIL_ADDRESS = fil.target - console.log('fil地址:',FIL_ADDRESS); + console.log('fil地址:', FIL_ADDRESS); console.log("開始部署NFT合約"); const NFT = await ethers.getContractFactory("NFT"); - const baseURI = "ipfs://QmQpgq4FvXNHZfoytpiwk617Nozmeu7iMiyiSzthVg1ZV7/metadata.json" + const baseURI = "ipfs://QmXrE6iMBSHKe6jcLJnXtC9RtnUyjdJx9sBFbvLUTMunQv/metadata.json" const nft = await NFT.deploy("SOFIL NFT", "SFSC", baseURI); console.log("NFT合約", nft.target); @@ -35,11 +36,16 @@ async function main() { await tx.wait() const tx1 = await pool.setPledgeContractAddress(pledge.target); await tx1.wait() + + // 主网删除 + const tx2 = await pledge.setDayTime(toBigInt(60)) + await tx2.wait() // 測試使用 console.log('設置成功'); console.log('NFT的質押合約地址', await nft.pledgeAddress()); console.log('Pool的質押合約地址', await pool._pledgeContractAddress()); + console.log('质押时间', await pledge.dayTime()); } diff --git a/sync.block.js b/sync.block.js index 7270abb..f84c8f5 100644 --- a/sync.block.js +++ b/sync.block.js @@ -1122,7 +1122,7 @@ const _abi = [ ] const private = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80' const provider = new ethers.JsonRpcProvider("http://127.0.0.1:8545") -const contractAddress = "0x5eb3Bc0a489C5A8288765d2336659EbCA68FCd00"; +const contractAddress = "0xA51c1fc2f0D1a1b8494Ed1FE312d7C3a78Ed91C0"; const wallet = new ethers.Wallet(private, provider); const contract = new ethers.Contract(contractAddress, _abi, wallet) @@ -1132,7 +1132,7 @@ async function sync() { const res = await contract.setDayTime(ethers.toBigInt(1)) a++ } - +// 0x2ADDed672bacEfe857a408B577CB7DF1f6687c07 setInterval(() => { sync() }, 5000) \ No newline at end of file diff --git a/test/Pledge.ts b/test/Pledge.ts index 504a81d..b6f874a 100644 --- a/test/Pledge.ts +++ b/test/Pledge.ts @@ -10,7 +10,7 @@ describe("NFT", function () { const fil = await FIL.deploy(); const NFT = await ethers.getContractFactory("NFT"); - const nft = await NFT.deploy("MyNFT", "MNFT"); + const nft = await NFT.deploy("MyNFT", "MNFT", "123"); const Pool = await ethers.getContractFactory("Pool"); const pool = await upgrades.deployProxy(Pool, [fil.target, nft.target]); @@ -21,9 +21,9 @@ describe("NFT", function () { pool.target, ]); - await nft.setPledgeAddress(pledge.target); - await pool.setPledgeContractAddress(pledge.target); - await pledge.setDayTime(ethers.toBigInt(1)); + // await nft.setPledgeAddress(pledge.target); + // await pool.setPledgeContractAddress(pledge.target); + // await pledge.setDayTime(ethers.toBigInt(1)); return { nft, owner, otherAccount, pool, pledge, fil }; } @@ -53,16 +53,23 @@ describe("NFT", function () { // }); describe("Test Contract", async function () { - it("测试NFT黑名单", async () => { - const { pledge,fil,pool,otherAccount,owner,nft } = await loadFixture(deployOneYearLockFixture); - await fil.approve(pool.target, ethers.parseEther("1000")); - await pledge.pledge(ethers.parseEther("1000"), "0x2",otherAccount.address); - // console.log(await pledge.getOwnerAllPledgeInfo(owner.address)); - await pledge.addNftBalcks(["0x1"]) - await nft.setApprovalForAll(pledge.target,true) - await pledge.destroyPledge("0x1") - - }); + // it("测试NFT黑名单", async () => { + // const { pledge, fil, pool, otherAccount, owner, nft } = await loadFixture(deployOneYearLockFixture); + // await fil.approve(pool.target, ethers.parseEther("1000")); + // await pledge.pledge(ethers.parseEther("1000"), "0x2", otherAccount.address); + // // console.log(await pledge.getOwnerAllPledgeInfo(owner.address)); + // await pledge.addNftBalcks(["0x1"]) + // await nft.setApprovalForAll(pledge.target, true) + // await pledge.destroyPledge("0x1") + + // }); + + it("测试安全计算", async function () { + const { pool, owner, pledge, fil } = await loadFixture(deployOneYearLockFixture); + console.log(await pledge.safeAdd(ethers.parseEther("10000000000000000000000000000"), ethers.parseEther("10000000000000000"))); + + + }) // it("测试质押销毁",async ()=>{