Skip to content

Instantly share code, notes, and snippets.

@lorentsinani
Created November 11, 2023 01:01
Show Gist options
  • Save lorentsinani/ca4fd246a2ab476879da28eff2a2425f to your computer and use it in GitHub Desktop.
Save lorentsinani/ca4fd246a2ab476879da28eff2a2425f to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.16+commit.07a7930e.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;
contract Consumer {
function getBalance() public view returns (uint256) {
return address(this).balance;
}
function deposit() public payable {}
}
contract SmartContractWallet {
address payable public owner;
mapping(address => bool) public isAllowedToSend;
mapping(address => uint256) public allowance;
mapping(address => bool) public guardians;
address payable nextOwner;
mapping(address => mapping(address => bool))
public nextOwnerGuardianVotedBool;
uint256 guardiansResetCount;
uint256 public constant confirmationsFromGuardiansForReset = 3;
constructor() {
owner = payable(msg.sender);
}
function setGuardian(address _guardian, bool _isGuardian) public {
require(msg.sender == owner, "you are not the owner, aborting!!!");
guardians[_guardian] = _isGuardian;
}
function proposeNewOwner(address payable _newOwner) public {
require(
guardians[msg.sender],
"You are not guardian of this wallet, aborting!!!"
);
require(
nextOwnerGuardianVotedBool[_newOwner][msg.sender],
"You already voted, aborting!!"
);
if (_newOwner != nextOwner) {
nextOwner = _newOwner;
guardiansResetCount = 0;
}
guardiansResetCount++;
if (guardiansResetCount >= confirmationsFromGuardiansForReset) {
owner = nextOwner;
nextOwner = payable(address(0));
}
}
function setAllowance(address _for, uint256 _amount) public {
require(msg.sender == owner, "you are not the owner, aborting!!!");
allowance[_for] = _amount;
if (_amount > 0) {
isAllowedToSend[_for] = true;
} else {
isAllowedToSend[_for] = false;
}
}
function transfer(
address payable _to,
uint256 _amount,
bytes memory _payload
) public returns (bytes memory) {
//require(msg.sender == owner, "You are not the owner, aborting!!!");
if (msg.sender != owner) {
require(
isAllowedToSend[msg.sender],
"You are not allowed to send anything from this smart contract, aborting"
);
require(
allowance[msg.sender] >= _amount,
"You are trying to send more than you are allowed to, aborting!!"
);
allowance[msg.sender] -= _amount;
}
(bool success, bytes memory returnData) = _to.call{value: _amount}(
_payload
);
require(success, "Aborting, call was not successful");
return returnData;
}
receive() external payable {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment