编译器
0.6.12+commit.27d51765
文件 1 的 25:AaveSmartWalletB.sol
pragma solidity 0.6.12;
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "../../interfaces/IAaveBridge.sol";
import "../../lib/SmartWalletBaseB.sol";
contract AaveSmartWalletB is SmartWalletBaseB {
using SafeMath for uint256;
using SafeERC20 for IERC20;
uint256 constant internal RAY = 1e27;
IAaveBridge internal _bridge;
uint256 internal _nftCreatorAmountDischarged;
mapping (address => address) internal _assetATokens;
function initialize(
address aaveBridge
)
public
{
SmartWalletBaseB.initializeBase();
_bridge = IAaveBridge(aaveBridge);
}
function isReserveActive(address assetToken) external view override returns (bool) {
return _bridge.isReserveActive(assetToken);
}
function getReserveInterestToken(address assetToken) external view override returns (address) {
return _bridge.getReserveInterestToken(assetToken);
}
function getPrincipal(address assetToken) external override returns (uint256) {
return _getPrincipal(assetToken);
}
function getInterest(address assetToken, uint256 creatorPct) external override returns (uint256 creatorInterest, uint256 ownerInterest) {
return _getInterest(assetToken, creatorPct);
}
function getTotal(address assetToken) external override returns (uint256) {
return _getTotal(assetToken);
}
function getRewards(address rewardToken) external override returns (uint256) {
return IERC20(rewardToken).balanceOf(address(this));
}
function deposit(
address assetToken,
uint256 assetAmount,
uint256 referralCode
)
external
override
onlyWalletManager
returns (uint256)
{
return _deposit(assetToken, assetAmount, referralCode);
}
function withdraw(
address receiver,
address creator,
uint256 creatorPct,
address assetToken
)
external
override
onlyWalletManager
returns (uint256 creatorAmount, uint256 receiverAmount)
{
uint256 walletPrincipal = _getPrincipal(assetToken);
(, uint256 ownerInterest) = _getInterest(assetToken, creatorPct);
return _withdraw(receiver, creator, creatorPct, assetToken, walletPrincipal.add(ownerInterest));
}
function withdrawAmount(
address receiver,
address creator,
uint256 creatorPct,
address assetToken,
uint256 assetAmount
)
external
override
onlyWalletManager
returns (uint256 creatorAmount, uint256 receiverAmount)
{
return _withdraw(receiver, creator, creatorPct, assetToken, assetAmount);
}
function withdrawAmountForCreator(
address receiver,
uint256 creatorPct,
address assetToken,
uint256 assetAmount
)
external
override
onlyWalletManager
returns (uint256 receiverAmount)
{
return _withdrawForCreator(receiver, creatorPct, assetToken, assetAmount);
}
function withdrawRewards(
address receiver,
address rewardsToken,
uint256 rewardsAmount
)
external
override
onlyWalletManager
returns (uint256)
{
return _withdrawRewards(receiver, rewardsToken, rewardsAmount);
}
function refreshPrincipal(address assetToken) external virtual override onlyWalletManager {
uint256 aTokenBalance = IERC20(_assetATokens[assetToken]).balanceOf(address(this));
if (_assetPrincipalBalance[assetToken] > aTokenBalance) {
_assetPrincipalBalance[assetToken] = aTokenBalance;
}
}
function _deposit(
address assetToken,
uint256 assetAmount,
uint256 referralCode
)
internal
returns (uint256)
{
_trackAssetToken(assetToken);
_assetPrincipalBalance[assetToken] = _assetPrincipalBalance[assetToken].add(assetAmount);
_sendToken(address(_bridge), assetToken, assetAmount);
uint256 aTokensAmount = _bridge.deposit(assetToken, assetAmount, referralCode);
return aTokensAmount;
}
function _withdraw(
address receiver,
address creator,
uint256 creatorPct,
address assetToken,
uint256 assetAmount
)
internal
returns (uint256 creatorAmount, uint256 receiverAmount)
{
uint256 walletPrincipal = _getPrincipal(assetToken);
(uint256 creatorInterest, uint256 ownerInterest) = _getInterest(assetToken, creatorPct);
if (assetAmount < ownerInterest) {
if (creatorInterest > 0) {
uint256 ratio = assetAmount.mul(RAY).div(ownerInterest);
creatorAmount = creatorInterest.add(_nftCreatorAmountDischarged).mul(ratio).div(RAY);
if (creatorAmount <= _nftCreatorAmountDischarged) {
_nftCreatorAmountDischarged = _nftCreatorAmountDischarged.sub(creatorAmount);
creatorAmount = 0;
}
else {
creatorAmount = creatorAmount.sub(_nftCreatorAmountDischarged);
_nftCreatorAmountDischarged = 0;
}
}
receiverAmount = assetAmount;
}
else {
uint256 fromPrincipal = assetAmount.sub(ownerInterest);
if (fromPrincipal > walletPrincipal) {
fromPrincipal = walletPrincipal.sub(ownerInterest);
}
creatorAmount = creatorInterest;
receiverAmount = ownerInterest.add(fromPrincipal);
_nftCreatorAmountDischarged = 0;
_assetPrincipalBalance[assetToken] = _assetPrincipalBalance[assetToken].sub(fromPrincipal);
}
address aTokenAddress = _bridge.getReserveInterestToken(assetToken);
_sendToken(address(_bridge), aTokenAddress, receiverAmount.add(creatorAmount));
if (creatorAmount > 0) {
if (creator != address(0)) {
_bridge.withdraw(creator, assetToken, creatorAmount);
} else {
receiverAmount = receiverAmount.add(creatorAmount);
creatorAmount = 0;
}
}
_bridge.withdraw(receiver, assetToken, receiverAmount);
}
function _withdrawForCreator(
address receiver,
uint256 creatorPct,
address assetToken,
uint256 assetAmount
)
internal
returns (uint256 receiverAmount)
{
(uint256 creatorInterest,) = _getInterest(assetToken, creatorPct);
if (creatorInterest == 0) { return 0; }
if (assetAmount > creatorInterest) {
assetAmount = creatorInterest;
}
_nftCreatorAmountDischarged = _nftCreatorAmountDischarged.add(assetAmount);
address aTokenAddress = _bridge.getReserveInterestToken(assetToken);
_sendToken(address(_bridge), aTokenAddress, assetAmount);
_bridge.withdraw(receiver, assetToken, assetAmount);
}
function _withdrawRewards(
address receiver,
address rewardsTokenAddress,
uint256 rewardsAmount
)
internal
returns (uint256)
{
address self = address(this);
IERC20 rewardsToken = IERC20(rewardsTokenAddress);
uint256 walletBalance = rewardsToken.balanceOf(self);
require(walletBalance >= rewardsAmount, "ASW:E-411");
rewardsToken.safeTransfer(receiver, rewardsAmount);
return rewardsAmount;
}
function _getTotal(address assetToken) internal view returns (uint256) {
return _bridge.getTotalBalance(address(this), assetToken);
}
function _getInterest(address assetToken, uint256 creatorPct) internal view returns (uint256 creatorInterest, uint256 ownerInterest) {
uint256 total = _getTotal(assetToken);
uint256 principal = _getPrincipal(assetToken);
uint256 interest = total.sub(principal);
if (creatorPct > 0) {
if (interest <= PERCENTAGE_SCALE) {
creatorInterest = 0;
}
else {
creatorInterest = interest
.add(_nftCreatorAmountDischarged)
.mul(creatorPct)
.div(PERCENTAGE_SCALE)
.sub(_nftCreatorAmountDischarged);
}
}
ownerInterest = interest.sub(creatorInterest);
}
function _trackAssetToken(address assetToken) internal override {
if (!_assetTokens.contains(assetToken)) {
_assetTokens.add(assetToken);
address aTokenAddress = _bridge.getReserveInterestToken(assetToken);
_assetATokens[assetToken] = aTokenAddress;
}
}
function _sendToken(address to, address token, uint256 amount) internal {
IERC20(token).safeTransfer(to, amount);
}
}
文件 2 的 25:AaveWalletManagerB.sol
pragma solidity 0.6.12;
import "@openzeppelin/contracts/math/SafeMath.sol";
import "../../lib/WalletManagerBase.sol";
import "../../interfaces/IChargedSettings.sol";
import "./AaveSmartWalletB.sol";
contract AaveWalletManagerB is WalletManagerBase {
using SafeMath for uint256;
event AaveBridgeSet(address indexed aaveBridge);
event ChargedSettingsSet(address indexed settings);
event ValidRewardsTokenSet(address indexed rewardsToken, bool state);
IChargedSettings internal _chargedSettings;
address internal _aaveBridge;
uint256 internal _referralCode;
mapping (address => bool) public _rewardsTokenWhitelist;
constructor () public {
_walletTemplate = address(new AaveSmartWalletB());
}
function isReserveActive(address contractAddress, uint256 tokenId, address assetToken) external view override returns (bool) {
uint256 uuid = contractAddress.getTokenUUID(tokenId);
if (_wallets[uuid] == address(0x0)) { return false; }
return AaveSmartWalletB(_wallets[uuid]).isReserveActive(assetToken);
}
function getReserveInterestToken(address contractAddress, uint256 tokenId, address assetToken) external view override returns (address) {
uint256 uuid = contractAddress.getTokenUUID(tokenId);
if (_wallets[uuid] == address(0x0)) { return address(0x0); }
return AaveSmartWalletB(_wallets[uuid]).getReserveInterestToken(assetToken);
}
function getPrincipal(address contractAddress, uint256 tokenId, address assetToken) external override returns (uint256) {
uint256 uuid = contractAddress.getTokenUUID(tokenId);
if (_wallets[uuid] == address(0x0)) { return 0; }
return AaveSmartWalletB(_wallets[uuid]).getPrincipal(assetToken);
}
function getInterest(address contractAddress, uint256 tokenId, address assetToken)
external
override
returns (uint256 creatorInterest, uint256 ownerInterest)
{
uint256 uuid = contractAddress.getTokenUUID(tokenId);
if (_wallets[uuid] != address(0x0)) {
(, uint256 annuityPct) = _chargedSettings.getCreatorAnnuities(contractAddress, tokenId);
return AaveSmartWalletB(_wallets[uuid]).getInterest(assetToken, annuityPct);
}
}
function getTotal(address contractAddress, uint256 tokenId, address assetToken) external override returns (uint256) {
uint256 uuid = contractAddress.getTokenUUID(tokenId);
if (_wallets[uuid] == address(0x0)) { return 0; }
return AaveSmartWalletB(_wallets[uuid]).getTotal(assetToken);
}
function getRewards(address contractAddress, uint256 tokenId, address _rewardToken) external override returns (uint256) {
uint256 uuid = contractAddress.getTokenUUID(tokenId);
if (_wallets[uuid] == address(0x0)) { return 0; }
return AaveSmartWalletB(_wallets[uuid]).getRewards(_rewardToken);
}
function energize(
address contractAddress,
uint256 tokenId,
address assetToken,
uint256 assetAmount
)
external
override
onlyController
returns (uint256 yieldTokensAmount)
{
uint256 uuid = contractAddress.getTokenUUID(tokenId);
address wallet = _wallets[uuid];
yieldTokensAmount = AaveSmartWalletB(wallet).deposit(assetToken, assetAmount, _referralCode);
emit WalletEnergized(contractAddress, tokenId, assetToken, assetAmount, yieldTokensAmount);
}
function discharge(
address receiver,
address contractAddress,
uint256 tokenId,
address assetToken,
address creatorRedirect
)
external
override
onlyController
returns (uint256 creatorAmount, uint256 receiverAmount)
{
uint256 uuid = contractAddress.getTokenUUID(tokenId);
address wallet = _wallets[uuid];
require(wallet != address(0x0), "AWM:E-403");
(address creator, uint256 annuityPct) = _chargedSettings.getCreatorAnnuities(contractAddress, tokenId);
(, uint256 ownerInterest) = AaveSmartWalletB(wallet).getInterest(assetToken, annuityPct);
require(ownerInterest > 0, "AWM:E-412");
if (creatorRedirect != address(0)) {
creator = creatorRedirect;
}
(creatorAmount, receiverAmount) = AaveSmartWalletB(wallet).withdrawAmount(receiver, creator, annuityPct, assetToken, ownerInterest);
emit WalletDischarged(contractAddress, tokenId, assetToken, creatorAmount, receiverAmount);
}
function dischargeAmount(
address receiver,
address contractAddress,
uint256 tokenId,
address assetToken,
uint256 assetAmount,
address creatorRedirect
)
external
override
onlyController
returns (uint256 creatorAmount, uint256 receiverAmount)
{
uint256 uuid = contractAddress.getTokenUUID(tokenId);
address wallet = _wallets[uuid];
require(wallet != address(0x0), "AWM:E-403");
(address creator, uint256 annuityPct) = _chargedSettings.getCreatorAnnuities(contractAddress, tokenId);
(, uint256 ownerInterest) = AaveSmartWalletB(wallet).getInterest(assetToken, annuityPct);
require(assetAmount > 0 && ownerInterest >= assetAmount, "AWM:E-412");
if (creatorRedirect != address(0)) {
creator = creatorRedirect;
}
(creatorAmount, receiverAmount) = AaveSmartWalletB(wallet).withdrawAmount(receiver, creator, annuityPct, assetToken, assetAmount);
emit WalletDischarged(contractAddress, tokenId, assetToken, creatorAmount, receiverAmount);
}
function dischargeAmountForCreator(
address receiver,
address contractAddress,
uint256 tokenId,
address creator,
address assetToken,
uint256 assetAmount
)
external
override
onlyController
returns (uint256 receiverAmount)
{
uint256 uuid = contractAddress.getTokenUUID(tokenId);
address wallet = _wallets[uuid];
require(wallet != address(0x0), "AWM:E-403");
(, uint256 annuityPct) = _chargedSettings.getCreatorAnnuities(contractAddress, tokenId);
(uint256 creatorInterest,) = AaveSmartWalletB(wallet).getInterest(assetToken, annuityPct);
require(assetAmount > 0 && creatorInterest >= assetAmount, "AWM:E-412");
receiverAmount = AaveSmartWalletB(wallet).withdrawAmountForCreator(receiver, annuityPct, assetToken, assetAmount);
emit WalletDischargedForCreator(contractAddress, tokenId, assetToken, creator, receiverAmount);
}
function release(
address receiver,
address contractAddress,
uint256 tokenId,
address assetToken,
address creatorRedirect
)
external
override
onlyController
returns (uint256 principalAmount, uint256 creatorAmount, uint256 receiverAmount)
{
uint256 uuid = contractAddress.getTokenUUID(tokenId);
address wallet = _wallets[uuid];
require(wallet != address(0x0), "AWM:E-403");
(address creator, uint256 annuityPct) = _chargedSettings.getCreatorAnnuities(contractAddress, tokenId);
if (creatorRedirect != address(0)) {
creator = creatorRedirect;
}
principalAmount = AaveSmartWalletB(wallet).getPrincipal(assetToken);
(creatorAmount, receiverAmount) = AaveSmartWalletB(wallet).withdraw(receiver, creator, annuityPct, assetToken);
emit WalletReleased(contractAddress, tokenId, receiver, assetToken, principalAmount, creatorAmount, receiverAmount);
}
function releaseAmount(
address receiver,
address contractAddress,
uint256 tokenId,
address assetToken,
uint256 assetAmount,
address creatorRedirect
)
external
override
onlyController
returns (uint256 principalAmount, uint256 creatorAmount, uint256 receiverAmount)
{
uint256 uuid = contractAddress.getTokenUUID(tokenId);
address wallet = _wallets[uuid];
require(wallet != address(0x0), "AWM:E-403");
(address creator, uint256 annuityPct) = _chargedSettings.getCreatorAnnuities(contractAddress, tokenId);
if (creatorRedirect != address(0)) {
creator = creatorRedirect;
}
(, uint256 ownerInterest) = AaveSmartWalletB(wallet).getInterest(assetToken, annuityPct);
principalAmount = (ownerInterest < assetAmount) ? assetAmount.sub(ownerInterest) : 0;
(creatorAmount, receiverAmount) = AaveSmartWalletB(wallet).withdrawAmount(receiver, creator, annuityPct, assetToken, assetAmount);
emit WalletReleased(contractAddress, tokenId, receiver, assetToken, principalAmount, creatorAmount, receiverAmount);
}
function withdrawRewards(
address receiver,
address contractAddress,
uint256 tokenId,
address rewardsToken,
uint256 rewardsAmount
)
external
override
onlyController
returns (uint256 amount)
{
uint256 uuid = contractAddress.getTokenUUID(tokenId);
address wallet = _wallets[uuid];
require(wallet != address(0x0), "AWM:E-403");
require(_rewardsTokenWhitelist[rewardsToken], "AWM:E-423");
amount = AaveSmartWalletB(wallet).withdrawRewards(receiver, rewardsToken, rewardsAmount);
emit WalletRewarded(contractAddress, tokenId, receiver, rewardsToken, amount);
}
function executeForAccount(
address contractAddress,
uint256 tokenId,
address externalAddress,
uint256 ethValue,
bytes memory encodedParams
)
external
override
onlyControllerOrExecutor
returns (bytes memory)
{
uint256 uuid = contractAddress.getTokenUUID(tokenId);
address wallet = _wallets[uuid];
return AaveSmartWalletB(wallet).executeForAccount(externalAddress, ethValue, encodedParams);
}
function refreshPrincipal(address contractAddress, uint256 tokenId, address assetToken)
external
override
onlyControllerOrExecutor
{
uint256 uuid = contractAddress.getTokenUUID(tokenId);
address wallet = _wallets[uuid];
AaveSmartWalletB(wallet).refreshPrincipal(assetToken);
}
function getWalletAddressById(
address contractAddress,
uint256 tokenId,
address ,
uint256
)
external
override
onlyControllerOrExecutor
returns (address)
{
uint256 uuid = contractAddress.getTokenUUID(tokenId);
address wallet = _wallets[uuid];
if (wallet == address(0x0)) {
wallet = _createWallet();
_wallets[uuid] = wallet;
emit NewSmartWallet(contractAddress, tokenId, wallet, address(0), 0);
}
return wallet;
}
function setAaveBridge(address aaveBridge) external onlyOwner {
require(aaveBridge != address(0x0), "AWM:E-403");
_aaveBridge = aaveBridge;
emit AaveBridgeSet(aaveBridge);
}
function setChargedSettings(address settings) external onlyOwner {
require(settings != address(0x0), "AWM:E-403");
_chargedSettings = IChargedSettings(settings);
emit ChargedSettingsSet(settings);
}
function setReferralCode(uint256 referralCode) external onlyOwner {
_referralCode = referralCode;
}
function setValidRewardsToken(address rewardsToken, bool state) external onlyOwner {
_rewardsTokenWhitelist[rewardsToken] = state;
emit ValidRewardsTokenSet(rewardsToken, state);
}
function _createWallet()
internal
returns (address)
{
address newWallet = _createClone(_walletTemplate);
AaveSmartWalletB(newWallet).initialize(_aaveBridge);
return newWallet;
}
}
文件 3 的 25:Address.sol
pragma solidity ^0.6.2;
library Address {
function isContract(address account) internal view returns (bool) {
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
文件 4 的 25:BlackholePrevention.sol
pragma solidity >=0.6.0;
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
contract BlackholePrevention {
using Address for address payable;
using SafeERC20 for IERC20;
event WithdrawStuckEther(address indexed receiver, uint256 amount);
event WithdrawStuckERC20(address indexed receiver, address indexed tokenAddress, uint256 amount);
event WithdrawStuckERC721(address indexed receiver, address indexed tokenAddress, uint256 indexed tokenId);
event WithdrawStuckERC1155(address indexed receiver, address indexed tokenAddress, uint256 indexed tokenId, uint256 amount);
function _withdrawEther(address payable receiver, uint256 amount) internal virtual {
require(receiver != address(0x0), "BHP:E-403");
if (address(this).balance >= amount) {
receiver.sendValue(amount);
emit WithdrawStuckEther(receiver, amount);
}
}
function _withdrawERC20(address payable receiver, address tokenAddress, uint256 amount) internal virtual {
require(receiver != address(0x0), "BHP:E-403");
if (IERC20(tokenAddress).balanceOf(address(this)) >= amount) {
IERC20(tokenAddress).safeTransfer(receiver, amount);
emit WithdrawStuckERC20(receiver, tokenAddress, amount);
}
}
function _withdrawERC721(address payable receiver, address tokenAddress, uint256 tokenId) internal virtual {
require(receiver != address(0x0), "BHP:E-403");
if (IERC721(tokenAddress).ownerOf(tokenId) == address(this)) {
IERC721(tokenAddress).transferFrom(address(this), receiver, tokenId);
emit WithdrawStuckERC721(receiver, tokenAddress, tokenId);
}
}
function _withdrawERC1155(address payable receiver, address tokenAddress, uint256 tokenId, uint256 amount) internal virtual {
require(receiver != address(0x0), "BHP:E-403");
if (IERC1155(tokenAddress).balanceOf(address(this), tokenId) >= amount) {
IERC1155(tokenAddress).safeTransferFrom(address(this), receiver, tokenId, amount, "");
emit WithdrawStuckERC1155(receiver, tokenAddress, tokenId, amount);
}
}
}
文件 5 的 25:Context.sol
pragma solidity ^0.6.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this;
return msg.data;
}
}
文件 6 的 25:EnumerableSet.sol
pragma solidity ^0.6.0;
library EnumerableSet {
struct Set {
bytes32[] _values;
mapping (bytes32 => uint256) _indexes;
}
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
function _remove(Set storage set, bytes32 value) private returns (bool) {
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
bytes32 lastvalue = set._values[lastIndex];
set._values[toDeleteIndex] = lastvalue;
set._indexes[lastvalue] = toDeleteIndex + 1;
set._values.pop();
delete set._indexes[value];
return true;
} else {
return false;
}
}
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
function _at(Set storage set, uint256 index) private view returns (bytes32) {
require(set._values.length > index, "EnumerableSet: index out of bounds");
return set._values[index];
}
struct AddressSet {
Set _inner;
}
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(value)));
}
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(value)));
}
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(value)));
}
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint256(_at(set._inner, index)));
}
struct UintSet {
Set _inner;
}
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
}
文件 7 的 25:IAaveBridge.sol
pragma solidity >=0.6.0;
interface IAaveBridge {
function getReserveInterestToken(address assetToken) external view returns (address aTokenAddress);
function isReserveActive(address assetToken) external view returns (bool);
function getTotalBalance(address account, address assetToken) external view returns (uint256);
function deposit(address assetToken, uint256 assetAmount, uint256 referralCode) external returns (uint256);
function withdraw(address receiver, address assetToken, uint256 assetAmount) external;
}
文件 8 的 25:IBasketManager.sol
pragma solidity >=0.6.0;
interface IBasketManager {
event ControllerSet(address indexed controller);
event ExecutorSet(address indexed executor);
event PausedStateSet(bool isPaused);
event NewSmartBasket(address indexed contractAddress, uint256 indexed tokenId, address indexed smartBasket);
event BasketAdd(address indexed contractAddress, uint256 indexed tokenId, address basketTokenAddress, uint256 basketTokenId, uint256 basketTokenAmount);
event BasketRemove(address indexed receiver, address indexed contractAddress, uint256 indexed tokenId, address basketTokenAddress, uint256 basketTokenId, uint256 basketTokenAmount);
event BasketRewarded(address indexed contractAddress, uint256 indexed tokenId, address indexed receiver, address rewardsToken, uint256 rewardsAmount);
function isPaused() external view returns (bool);
function getTokenTotalCount(address contractAddress, uint256 tokenId) external view returns (uint256);
function getTokenCountByType(address contractAddress, uint256 tokenId, address basketTokenAddress, uint256 basketTokenId) external returns (uint256);
function prepareTransferAmount(uint256 nftTokenAmount) external;
function addToBasket(address contractAddress, uint256 tokenId, address basketTokenAddress, uint256 basketTokenId) external returns (bool);
function removeFromBasket(address receiver, address contractAddress, uint256 tokenId, address basketTokenAddress, uint256 basketTokenId) external returns (bool);
function withdrawRewards(address receiver, address contractAddress, uint256 tokenId, address rewardsToken, uint256 rewardsAmount) external returns (uint256 amount);
function executeForAccount(address contractAddress, uint256 tokenId, address externalAddress, uint256 ethValue, bytes memory encodedParams) external returns (bytes memory);
function getBasketAddressById(address contractAddress, uint256 tokenId) external returns (address);
function withdrawEther(address contractAddress, uint256 tokenId, address payable receiver, uint256 amount) external;
function withdrawERC20(address contractAddress, uint256 tokenId, address payable receiver, address tokenAddress, uint256 amount) external;
function withdrawERC721(address contractAddress, uint256 tokenId, address payable receiver, address nftTokenAddress, uint256 nftTokenId) external;
function withdrawERC1155(address contractAddress, uint256 tokenId, address payable receiver, address nftTokenAddress, uint256 nftTokenId, uint256 amount) external;
}
文件 9 的 25:IChargedSettings.sol
pragma solidity >=0.6.0;
import "./IWalletManager.sol";
import "./IBasketManager.sol";
interface IChargedSettings {
function getCreatorAnnuities(address contractAddress, uint256 tokenId) external returns (address creator, uint256 annuityPct);
function getCreatorAnnuitiesRedirect(address contractAddress, uint256 tokenId) external view returns (address);
function getTempLockExpiryBlocks() external view returns (uint256);
function getTimelockApprovals(address operator) external view returns (bool timelockAny, bool timelockOwn);
function getAssetRequirements(
address contractAddress,
address assetToken
) external view returns (
string memory requiredWalletManager,
bool energizeEnabled,
bool restrictedAssets,
bool validAsset,
uint256 depositCap,
uint256 depositMin,
uint256 depositMax,
bool invalidAsset
);
function getNftAssetRequirements(
address contractAddress,
address nftTokenAddress
) external view returns (
string memory requiredBasketManager,
bool basketEnabled,
uint256 maxNfts
);
function setCreatorAnnuities(address contractAddress, uint256 tokenId, address creator, uint256 annuityPercent) external;
function setCreatorAnnuitiesRedirect(address contractAddress, uint256 tokenId, address receiver) external;
function setRequiredWalletManager(address contractAddress, string calldata walletManager) external;
function setRequiredBasketManager(address contractAddress, string calldata basketManager) external;
function setAssetTokenRestrictions(address contractAddress, bool restrictionsEnabled) external;
function setAllowedAssetToken(address contractAddress, address assetToken, bool isAllowed) external;
function setAssetTokenLimits(address contractAddress, address assetToken, uint256 depositMin, uint256 depositMax) external;
function setMaxNfts(address contractAddress, address nftTokenAddress, uint256 maxNfts) external;
function setAssetInvalidity(address assetToken, bool invalidity) external;
function enableNftContracts(address[] calldata contracts) external;
function setPermsForCharge(address contractAddress, bool state) external;
function setPermsForBasket(address contractAddress, bool state) external;
function setPermsForTimelockAny(address contractAddress, bool state) external;
function setPermsForTimelockSelf(address contractAddress, bool state) external;
event Initialized(address indexed initiator);
event ControllerSet(address indexed controllerAddress, string controllerId);
event DepositCapSet(address assetToken, uint256 depositCap);
event TempLockExpirySet(uint256 expiryBlocks);
event RequiredWalletManagerSet(address indexed contractAddress, string walletManager);
event RequiredBasketManagerSet(address indexed contractAddress, string basketManager);
event AssetTokenRestrictionsSet(address indexed contractAddress, bool restrictionsEnabled);
event AllowedAssetTokenSet(address indexed contractAddress, address assetToken, bool isAllowed);
event AssetTokenLimitsSet(address indexed contractAddress, address assetToken, uint256 assetDepositMin, uint256 assetDepositMax);
event MaxNftsSet(address indexed contractAddress, address indexed nftTokenAddress, uint256 maxNfts);
event AssetInvaliditySet(address indexed assetToken, bool invalidity);
event TokenCreatorConfigsSet(address indexed contractAddress, uint256 indexed tokenId, address indexed creatorAddress, uint256 annuityPercent);
event TokenCreatorAnnuitiesRedirected(address indexed contractAddress, uint256 indexed tokenId, address indexed redirectAddress);
event PermsSetForCharge(address indexed contractAddress, bool state);
event PermsSetForBasket(address indexed contractAddress, bool state);
event PermsSetForTimelockAny(address indexed contractAddress, bool state);
event PermsSetForTimelockSelf(address indexed contractAddress, bool state);
}
文件 10 的 25:IERC1155.sol
pragma solidity ^0.6.2;
import "../../introspection/IERC165.sol";
interface IERC1155 is IERC165 {
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
event TransferBatch(address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values);
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
event URI(string value, uint256 indexed id);
function balanceOf(address account, uint256 id) external view returns (uint256);
function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids) external view returns (uint256[] memory);
function setApprovalForAll(address operator, bool approved) external;
function isApprovedForAll(address account, address operator) external view returns (bool);
function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) external;
function safeBatchTransferFrom(address from, address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data) external;
}
文件 11 的 25:IERC165.sol
pragma solidity ^0.6.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 12 的 25:IERC165Upgradeable.sol
pragma solidity >=0.6.0 <0.8.0;
interface IERC165Upgradeable {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 13 的 25:IERC20.sol
pragma solidity ^0.6.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
文件 14 的 25:IERC20Upgradeable.sol
pragma solidity >=0.6.0 <0.8.0;
interface IERC20Upgradeable {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
文件 15 的 25:IERC721.sol
pragma solidity ^0.6.2;
import "../../introspection/IERC165.sol";
interface IERC721 is IERC165 {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
function balanceOf(address owner) external view returns (uint256 balance);
function ownerOf(uint256 tokenId) external view returns (address owner);
function safeTransferFrom(address from, address to, uint256 tokenId) external;
function transferFrom(address from, address to, uint256 tokenId) external;
function approve(address to, uint256 tokenId) external;
function getApproved(uint256 tokenId) external view returns (address operator);
function setApprovalForAll(address operator, bool _approved) external;
function isApprovedForAll(address owner, address operator) external view returns (bool);
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
}
文件 16 的 25:IERC721Chargeable.sol
pragma solidity >=0.6.0;
import "@openzeppelin/contracts-upgradeable/introspection/IERC165Upgradeable.sol";
interface IERC721Chargeable is IERC165Upgradeable {
function owner() external view returns (address);
function creatorOf(uint256 tokenId) external view returns (address);
function balanceOf(address tokenOwner) external view returns (uint256 balance);
function ownerOf(uint256 tokenId) external view returns (address tokenOwner);
function safeTransferFrom(address from, address to, uint256 tokenId) external;
function transferFrom(address from, address to, uint256 tokenId) external;
function approve(address to, uint256 tokenId) external;
function getApproved(uint256 tokenId) external view returns (address operator);
function setApprovalForAll(address operator, bool _approved) external;
function isApprovedForAll(address tokenOwner, address operator) external view returns (bool);
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
}
文件 17 的 25:ISmartWallet.sol
pragma solidity >=0.6.0;
interface ISmartWallet {
function getAssetTokenCount() external view returns (uint256);
function getAssetTokenByIndex(uint256 index) external view returns (address);
function setNftCreator(address creator, uint256 annuityPct) external;
function isReserveActive(address assetToken) external view returns (bool);
function getReserveInterestToken(address assetToken) external view returns (address);
function getPrincipal(address assetToken) external returns (uint256);
function getInterest(address assetToken) external returns (uint256 creatorInterest, uint256 ownerInterest);
function getTotal(address assetToken) external returns (uint256);
function getRewards(address assetToken) external returns (uint256);
function deposit(address assetToken, uint256 assetAmount, uint256 referralCode) external returns (uint256);
function withdraw(address receiver, address creatorRedirect, address assetToken) external returns (uint256 creatorAmount, uint256 receiverAmount);
function withdrawAmount(address receiver, address creatorRedirect, address assetToken, uint256 assetAmount) external returns (uint256 creatorAmount, uint256 receiverAmount);
function withdrawAmountForCreator(address receiver, address assetToken, uint256 assetAmount) external returns (uint256 receiverAmount);
function withdrawRewards(address receiver, address rewardsToken, uint256 rewardsAmount) external returns (uint256);
function executeForAccount(address contractAddress, uint256 ethValue, bytes memory encodedParams) external returns (bytes memory);
function refreshPrincipal(address assetToken) external;
function withdrawEther(address payable receiver, uint256 amount) external;
function withdrawERC20(address payable receiver, address tokenAddress, uint256 amount) external;
function withdrawERC721(address payable receiver, address tokenAddress, uint256 tokenId) external;
}
文件 18 的 25:ISmartWalletB.sol
pragma solidity >=0.6.0;
interface ISmartWalletB {
function getAssetTokenCount() external view returns (uint256);
function getAssetTokenByIndex(uint256 index) external view returns (address);
function isReserveActive(address assetToken) external view returns (bool);
function getReserveInterestToken(address assetToken) external view returns (address);
function getPrincipal(address assetToken) external returns (uint256);
function getInterest(address assetToken, uint256 creatorPct) external returns (uint256 creatorInterest, uint256 ownerInterest);
function getTotal(address assetToken) external returns (uint256);
function getRewards(address assetToken) external returns (uint256);
function deposit(address assetToken, uint256 assetAmount, uint256 referralCode) external returns (uint256);
function withdraw(
address receiver,
address creator,
uint256 creatorPct,
address assetToken
) external returns (
uint256 creatorAmount,
uint256 receiverAmount
);
function withdrawAmount(
address receiver,
address creator,
uint256 creatorPct,
address assetToken,
uint256 assetAmount
) external returns (
uint256 creatorAmount,
uint256 receiverAmount
);
function withdrawAmountForCreator(
address receiver,
uint256 creatorPct,
address assetToken,
uint256 assetAmount
) external returns (
uint256 receiverAmount
);
function withdrawRewards(address receiver, address rewardsToken, uint256 rewardsAmount) external returns (uint256);
function executeForAccount(address contractAddress, uint256 ethValue, bytes memory encodedParams) external returns (bytes memory);
function refreshPrincipal(address assetToken) external;
function withdrawEther(address payable receiver, uint256 amount) external;
function withdrawERC20(address payable receiver, address tokenAddress, uint256 amount) external;
function withdrawERC721(address payable receiver, address tokenAddress, uint256 tokenId) external;
function withdrawERC1155(address payable receiver, address tokenAddress, uint256 tokenId, uint256 amount) external;
}
文件 19 的 25:IWalletManager.sol
pragma solidity >=0.6.0;
interface IWalletManager {
event ControllerSet(address indexed controller);
event ExecutorSet(address indexed executor);
event PausedStateSet(bool isPaused);
event NewSmartWallet(address indexed contractAddress, uint256 indexed tokenId, address indexed smartWallet, address creator, uint256 annuityPct);
event WalletEnergized(address indexed contractAddress, uint256 indexed tokenId, address indexed assetToken, uint256 assetAmount, uint256 yieldTokensAmount);
event WalletDischarged(address indexed contractAddress, uint256 indexed tokenId, address indexed assetToken, uint256 creatorAmount, uint256 receiverAmount);
event WalletDischargedForCreator(address indexed contractAddress, uint256 indexed tokenId, address indexed assetToken, address creator, uint256 receiverAmount);
event WalletReleased(address indexed contractAddress, uint256 indexed tokenId, address indexed receiver, address assetToken, uint256 principalAmount, uint256 creatorAmount, uint256 receiverAmount);
event WalletRewarded(address indexed contractAddress, uint256 indexed tokenId, address indexed receiver, address rewardsToken, uint256 rewardsAmount);
function isPaused() external view returns (bool);
function isReserveActive(address contractAddress, uint256 tokenId, address assetToken) external view returns (bool);
function getReserveInterestToken(address contractAddress, uint256 tokenId, address assetToken) external view returns (address);
function getTotal(address contractAddress, uint256 tokenId, address assetToken) external returns (uint256);
function getPrincipal(address contractAddress, uint256 tokenId, address assetToken) external returns (uint256);
function getInterest(address contractAddress, uint256 tokenId, address assetToken) external returns (uint256 creatorInterest, uint256 ownerInterest);
function getRewards(address contractAddress, uint256 tokenId, address rewardToken) external returns (uint256);
function energize(address contractAddress, uint256 tokenId, address assetToken, uint256 assetAmount) external returns (uint256 yieldTokensAmount);
function discharge(address receiver, address contractAddress, uint256 tokenId, address assetToken, address creatorRedirect) external returns (uint256 creatorAmount, uint256 receiverAmount);
function dischargeAmount(address receiver, address contractAddress, uint256 tokenId, address assetToken, uint256 assetAmount, address creatorRedirect) external returns (uint256 creatorAmount, uint256 receiverAmount);
function dischargeAmountForCreator(address receiver, address contractAddress, uint256 tokenId, address creator, address assetToken, uint256 assetAmount) external returns (uint256 receiverAmount);
function release(address receiver, address contractAddress, uint256 tokenId, address assetToken, address creatorRedirect) external returns (uint256 principalAmount, uint256 creatorAmount, uint256 receiverAmount);
function releaseAmount(address receiver, address contractAddress, uint256 tokenId, address assetToken, uint256 assetAmount, address creatorRedirect) external returns (uint256 principalAmount, uint256 creatorAmount, uint256 receiverAmount);
function withdrawRewards(address receiver, address contractAddress, uint256 tokenId, address rewardsToken, uint256 rewardsAmount) external returns (uint256 amount);
function executeForAccount(address contractAddress, uint256 tokenId, address externalAddress, uint256 ethValue, bytes memory encodedParams) external returns (bytes memory);
function refreshPrincipal(address contractAddress, uint256 tokenId, address assetToken) external;
function getWalletAddressById(address contractAddress, uint256 tokenId, address creator, uint256 annuityPct) external returns (address);
function withdrawEther(address contractAddress, uint256 tokenId, address payable receiver, uint256 amount) external;
function withdrawERC20(address contractAddress, uint256 tokenId, address payable receiver, address tokenAddress, uint256 amount) external;
function withdrawERC721(address contractAddress, uint256 tokenId, address payable receiver, address nftTokenAddress, uint256 nftTokenId) external;
}
文件 20 的 25:Ownable.sol
pragma solidity ^0.6.0;
import "../GSN/Context.sol";
contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
文件 21 的 25:SafeERC20.sol
pragma solidity ^0.6.0;
import "./IERC20.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";
library SafeERC20 {
using SafeMath for uint256;
using Address for address;
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(IERC20 token, address spender, uint256 value) internal {
require((value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).add(value);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function _callOptionalReturn(IERC20 token, bytes memory data) private {
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
文件 22 的 25:SafeMath.sol
pragma solidity ^0.6.0;
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;
return c;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
文件 23 的 25:SmartWalletBaseB.sol
pragma solidity >=0.6.0;
import "@openzeppelin/contracts/utils/EnumerableSet.sol";
import "../interfaces/ISmartWalletB.sol";
import "./BlackholePrevention.sol";
abstract contract SmartWalletBaseB is ISmartWalletB, BlackholePrevention {
using EnumerableSet for EnumerableSet.AddressSet;
uint256 constant internal PERCENTAGE_SCALE = 1e4;
address internal _walletManager;
EnumerableSet.AddressSet internal _assetTokens;
mapping (address => uint256) internal _assetPrincipalBalance;
function initializeBase() public {
require(_walletManager == address(0x0), "SWB:E-002");
_walletManager = msg.sender;
}
function getAssetTokenCount() external view virtual override returns (uint256) {
return _assetTokens.length();
}
function getAssetTokenByIndex(uint256 index) external view virtual override returns (address) {
if (index >= _assetTokens.length()) {
return address(0);
}
return _assetTokens.at(index);
}
function executeForAccount(
address contractAddress,
uint256 ethValue,
bytes memory encodedParams
)
external
override
onlyWalletManager
returns (bytes memory)
{
(bool success, bytes memory result) = contractAddress.call{value: ethValue}(encodedParams);
require(success, string(result));
return result;
}
function withdrawEther(address payable receiver, uint256 amount) external virtual override onlyWalletManager {
_withdrawEther(receiver, amount);
}
function withdrawERC20(address payable receiver, address tokenAddress, uint256 amount) external virtual override onlyWalletManager {
_withdrawERC20(receiver, tokenAddress, amount);
}
function withdrawERC721(address payable receiver, address tokenAddress, uint256 tokenId) external virtual override onlyWalletManager {
_withdrawERC721(receiver, tokenAddress, tokenId);
}
function withdrawERC1155(address payable receiver, address tokenAddress, uint256 tokenId, uint256 amount) external virtual override onlyWalletManager {
_withdrawERC1155(receiver, tokenAddress, tokenId, amount);
}
function _getPrincipal(address assetToken) internal view virtual returns (uint256) {
return _assetPrincipalBalance[assetToken];
}
function _trackAssetToken(address assetToken) internal virtual {
if (!_assetTokens.contains(assetToken)) {
_assetTokens.add(assetToken);
}
}
modifier onlyWalletManager() {
require(_walletManager == msg.sender, "SWB:E-109");
_;
}
}
文件 24 的 25:TokenInfo.sol
pragma solidity 0.6.12;
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "../interfaces/IERC721Chargeable.sol";
library TokenInfo {
function getTokenUUID(address contractAddress, uint256 tokenId) internal pure virtual returns (uint256) {
return uint256(keccak256(abi.encodePacked(contractAddress, tokenId)));
}
function getTokenOwner(address contractAddress, uint256 tokenId) internal view virtual returns (address) {
IERC721Chargeable tokenInterface = IERC721Chargeable(contractAddress);
return tokenInterface.ownerOf(tokenId);
}
function getTokenCreator(address contractAddress, uint256 tokenId) internal view virtual returns (address) {
IERC721Chargeable tokenInterface = IERC721Chargeable(contractAddress);
return tokenInterface.creatorOf(tokenId);
}
function isContractOwner(address contractAddress, address account) internal view virtual returns (bool) {
address contractOwner = IERC721Chargeable(contractAddress).owner();
return contractOwner != address(0x0) && contractOwner == account;
}
function isTokenCreator(address contractAddress, uint256 tokenId, address sender) internal view virtual returns (bool) {
IERC721Chargeable tokenInterface = IERC721Chargeable(contractAddress);
address tokenCreator = tokenInterface.creatorOf(tokenId);
return (sender == tokenCreator);
}
function isTokenContractOrCreator(address contractAddress, uint256 tokenId, address creator, address sender) internal view virtual returns (bool) {
IERC721Chargeable tokenInterface = IERC721Chargeable(contractAddress);
address tokenCreator = tokenInterface.creatorOf(tokenId);
if (sender == contractAddress && creator == tokenCreator) { return true; }
return (sender == tokenCreator);
}
function isErc721OwnerOrOperator(address contractAddress, uint256 tokenId, address sender) internal view virtual returns (bool) {
IERC721Chargeable tokenInterface = IERC721Chargeable(contractAddress);
address tokenOwner = tokenInterface.ownerOf(tokenId);
return (sender == tokenOwner || tokenInterface.isApprovedForAll(tokenOwner, sender));
}
function isContract(address account) internal view returns (bool) {
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
function sendValue(address payable recipient, uint256 amount, uint256 gasLimit) internal {
require(address(this).balance >= amount, "TokenInfo: insufficient balance");
(bool success, ) = (gasLimit > 0)
? recipient.call{ value: amount, gas: gasLimit }("")
: recipient.call{ value: amount }("");
require(success, "TokenInfo: unable to send value, recipient may have reverted");
}
}
文件 25 的 25:WalletManagerBase.sol
pragma solidity >=0.6.0;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../interfaces/IWalletManager.sol";
import "../interfaces/ISmartWallet.sol";
import "../lib/TokenInfo.sol";
import "./BlackholePrevention.sol";
abstract contract WalletManagerBase is Ownable, BlackholePrevention, IWalletManager {
using TokenInfo for address;
address internal _controller;
address internal _executor;
address internal _walletTemplate;
mapping (uint256 => address) internal _wallets;
bool internal _paused;
function isPaused() external view override returns (bool) {
return _paused;
}
function setPausedState(bool paused) external onlyOwner {
_paused = paused;
emit PausedStateSet(paused);
}
function setController(address controller) external onlyOwner {
_controller = controller;
emit ControllerSet(controller);
}
function setExecutor(address executor) external onlyOwner {
_executor = executor;
emit ExecutorSet(executor);
}
function withdrawEther(address contractAddress, uint256 tokenId, address payable receiver, uint256 amount)
external
virtual
override
onlyOwner
{
uint256 uuid = contractAddress.getTokenUUID(tokenId);
address wallet = _wallets[uuid];
_withdrawEther(receiver, amount);
return ISmartWallet(wallet).withdrawEther(receiver, amount);
}
function withdrawERC20(address contractAddress, uint256 tokenId, address payable receiver, address tokenAddress, uint256 amount)
external
virtual
override
onlyOwner
{
uint256 uuid = contractAddress.getTokenUUID(tokenId);
address wallet = _wallets[uuid];
_withdrawERC20(receiver, tokenAddress, amount);
return ISmartWallet(wallet).withdrawERC20(receiver, tokenAddress, amount);
}
function withdrawERC721(address contractAddress, uint256 tokenId, address payable receiver, address nftTokenAddress, uint256 nftTokenId)
external
virtual
override
onlyOwner
{
uint256 uuid = contractAddress.getTokenUUID(tokenId);
address wallet = _wallets[uuid];
_withdrawERC721(receiver, nftTokenAddress, nftTokenId);
return ISmartWallet(wallet).withdrawERC721(receiver, nftTokenAddress, nftTokenId);
}
function _getTokenUUID(address contractAddress, uint256 tokenId) internal pure returns (uint256) {
return uint256(keccak256(abi.encodePacked(contractAddress, tokenId)));
}
function _createClone(address target) internal returns (address result) {
bytes20 targetBytes = bytes20(target);
assembly {
let clone := mload(0x40)
mstore(clone, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
mstore(add(clone, 0x14), targetBytes)
mstore(add(clone, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
result := create(0, clone, 0x37)
}
}
modifier onlyController() {
require(_controller == msg.sender, "WMB:E-108");
_;
}
modifier onlyExecutor() {
require(_executor == msg.sender, "WMB:E-108");
_;
}
modifier onlyControllerOrExecutor() {
require(_executor == msg.sender || _controller == msg.sender, "WMB:E-108");
_;
}
modifier whenNotPaused() {
require(_paused != true, "WMB:E-101");
_;
}
}
{
"compilationTarget": {
"contracts/yield/aave/AaveWalletManagerB.sol": "AaveWalletManagerB"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"aaveBridge","type":"address"}],"name":"AaveBridgeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"settings","type":"address"}],"name":"ChargedSettingsSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"controller","type":"address"}],"name":"ControllerSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"executor","type":"address"}],"name":"ExecutorSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"contractAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"address","name":"smartWallet","type":"address"},{"indexed":false,"internalType":"address","name":"creator","type":"address"},{"indexed":false,"internalType":"uint256","name":"annuityPct","type":"uint256"}],"name":"NewSmartWallet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"isPaused","type":"bool"}],"name":"PausedStateSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"rewardsToken","type":"address"},{"indexed":false,"internalType":"bool","name":"state","type":"bool"}],"name":"ValidRewardsTokenSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"contractAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"address","name":"assetToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"creatorAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"receiverAmount","type":"uint256"}],"name":"WalletDischarged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"contractAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"address","name":"assetToken","type":"address"},{"indexed":false,"internalType":"address","name":"creator","type":"address"},{"indexed":false,"internalType":"uint256","name":"receiverAmount","type":"uint256"}],"name":"WalletDischargedForCreator","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"contractAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"address","name":"assetToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"assetAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"yieldTokensAmount","type":"uint256"}],"name":"WalletEnergized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"contractAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"address","name":"assetToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"principalAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"creatorAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"receiverAmount","type":"uint256"}],"name":"WalletReleased","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"contractAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"address","name":"rewardsToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"rewardsAmount","type":"uint256"}],"name":"WalletRewarded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WithdrawStuckERC1155","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WithdrawStuckERC20","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"WithdrawStuckERC721","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WithdrawStuckEther","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"_rewardsTokenWhitelist","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"assetToken","type":"address"},{"internalType":"address","name":"creatorRedirect","type":"address"}],"name":"discharge","outputs":[{"internalType":"uint256","name":"creatorAmount","type":"uint256"},{"internalType":"uint256","name":"receiverAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"assetToken","type":"address"},{"internalType":"uint256","name":"assetAmount","type":"uint256"},{"internalType":"address","name":"creatorRedirect","type":"address"}],"name":"dischargeAmount","outputs":[{"internalType":"uint256","name":"creatorAmount","type":"uint256"},{"internalType":"uint256","name":"receiverAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"creator","type":"address"},{"internalType":"address","name":"assetToken","type":"address"},{"internalType":"uint256","name":"assetAmount","type":"uint256"}],"name":"dischargeAmountForCreator","outputs":[{"internalType":"uint256","name":"receiverAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"assetToken","type":"address"},{"internalType":"uint256","name":"assetAmount","type":"uint256"}],"name":"energize","outputs":[{"internalType":"uint256","name":"yieldTokensAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"externalAddress","type":"address"},{"internalType":"uint256","name":"ethValue","type":"uint256"},{"internalType":"bytes","name":"encodedParams","type":"bytes"}],"name":"executeForAccount","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"assetToken","type":"address"}],"name":"getInterest","outputs":[{"internalType":"uint256","name":"creatorInterest","type":"uint256"},{"internalType":"uint256","name":"ownerInterest","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"assetToken","type":"address"}],"name":"getPrincipal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"assetToken","type":"address"}],"name":"getReserveInterestToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"_rewardToken","type":"address"}],"name":"getRewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"assetToken","type":"address"}],"name":"getTotal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"getWalletAddressById","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"isPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"assetToken","type":"address"}],"name":"isReserveActive","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"assetToken","type":"address"}],"name":"refreshPrincipal","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"assetToken","type":"address"},{"internalType":"address","name":"creatorRedirect","type":"address"}],"name":"release","outputs":[{"internalType":"uint256","name":"principalAmount","type":"uint256"},{"internalType":"uint256","name":"creatorAmount","type":"uint256"},{"internalType":"uint256","name":"receiverAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"assetToken","type":"address"},{"internalType":"uint256","name":"assetAmount","type":"uint256"},{"internalType":"address","name":"creatorRedirect","type":"address"}],"name":"releaseAmount","outputs":[{"internalType":"uint256","name":"principalAmount","type":"uint256"},{"internalType":"uint256","name":"creatorAmount","type":"uint256"},{"internalType":"uint256","name":"receiverAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"aaveBridge","type":"address"}],"name":"setAaveBridge","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"settings","type":"address"}],"name":"setChargedSettings","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"controller","type":"address"}],"name":"setController","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"executor","type":"address"}],"name":"setExecutor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"paused","type":"bool"}],"name":"setPausedState","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"referralCode","type":"uint256"}],"name":"setReferralCode","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"rewardsToken","type":"address"},{"internalType":"bool","name":"state","type":"bool"}],"name":"setValidRewardsToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address payable","name":"receiver","type":"address"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address payable","name":"receiver","type":"address"},{"internalType":"address","name":"nftTokenAddress","type":"address"},{"internalType":"uint256","name":"nftTokenId","type":"uint256"}],"name":"withdrawERC721","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address payable","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawEther","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"rewardsToken","type":"address"},{"internalType":"uint256","name":"rewardsAmount","type":"uint256"}],"name":"withdrawRewards","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]