Skip to content

Commit

Permalink
Merge pull request #6 from casweeney/wallet-structure-setup
Browse files Browse the repository at this point in the history
Wallet structure setup
  • Loading branch information
Dprof-in-tech authored Dec 13, 2024
2 parents b055fbb + 85d0836 commit 912d2d7
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 42 deletions.
8 changes: 4 additions & 4 deletions script/Counter.s.sol → script/WalletFactory.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
pragma solidity ^0.8.13;

import {Script, console} from "forge-std/Script.sol";
import {Counter} from "../src/Counter.sol";
import {WalletFactory} from "../src/WalletFactory.sol";

contract CounterScript is Script {
Counter public counter;
contract WalletFactoryScript is Script {
WalletFactory public factory;

function setUp() public {}

function run() public {
vm.startBroadcast();

counter = new Counter();
factory = new WalletFactory();

vm.stopBroadcast();
}
Expand Down
14 changes: 0 additions & 14 deletions src/Counter.sol

This file was deleted.

48 changes: 48 additions & 0 deletions src/Wallet.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "./interfaces/IERC20.sol";

contract Wallet {
address public owner;
mapping(address => Transaction[]) transactions;
mapping(address => mapping(address => uint256)) token_balance;

struct Transaction {
uint256 amount;
address token;
}

modifier onlyOwner {
require(msg.sender == owner, "not owner");
_;
}

constructor(address _owner) {
require(msg.sender != address(0), "zero address found");
owner = _owner;
}

function createWorldId() onlyOwner external {

}

function transfer() onlyOwner external {

}

//////////////////////////////////////////////
// View Functions //
////////////////////////////////////////////

function getTransactionHistory() external view returns (Transaction[] memory) {

}

////////////////////////////////////////////////
// Private Function //
//////////////////////////////////////////////

function recordTransactionHistory() private {

}
}
19 changes: 19 additions & 0 deletions src/WalletFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "./Wallet.sol";

contract WalletFactory {
Wallet[] wallets;

function createWallet() external returns (Wallet newWallet_, uint256 length_) {
newWallet_ = new Wallet(msg.sender);

wallets.push(newWallet_);

length_ = wallets.length;
}

function getWalletClones() external view returns(Wallet[] memory) {
return wallets;
}
}
20 changes: 20 additions & 0 deletions src/interfaces/IERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.13;

interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);

function totalSupply() external view returns (uint256);

function balanceOf(address account) external view returns (uint256);

function transfer(address to, uint256 value) external returns (bool);

function allowance(address owner, address spender) external view returns (uint256);

function approve(address spender, uint256 value) external returns (bool);

function transferFrom(address from, address to, uint256 value) external returns (bool);
}
24 changes: 0 additions & 24 deletions test/Counter.t.sol

This file was deleted.

19 changes: 19 additions & 0 deletions test/WalletFactory.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Test, console} from "forge-std/Test.sol";
import {WalletFactory} from "../src/WalletFactory.sol";

contract WalletFactoryTest is Test {
WalletFactory public factory;

function setUp() public {
factory = new WalletFactory();
}

function test_CreateWallet() public {
factory.createWallet();

assertEq(factory.getWalletClones().length, 1);
}
}

0 comments on commit 912d2d7

Please sign in to comment.