Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main #266

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Main #266

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract TestIncrement {

function increment() external {
if (msg.sender != owner) {
revert("Only owner can increment");
revert("can increment");
}
number++;
}
Expand Down
58 changes: 58 additions & 0 deletions internal-testnet/smart-wallet-retainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Smart Wallet Retainer

This project implements a smart wallet retainer using Ethereum smart contracts. It consists of two main contracts: `SmartWallet` and `Retainer`, which work together to manage assets securely.

## Project Structure

```
smart-wallet-retainer
├── contracts
│ ├── SmartWallet.sol # SmartWallet contract for managing assets
│ └── Retainer.sol # Retainer contract for asset retention logic
├── migrations
│ └── 1_initial_migration.js # Migration script for deploying contracts
├── test
│ └── smartWalletTest.js # Test cases for SmartWallet contract
├── truffle-config.js # Truffle configuration file
├── package.json # npm configuration file
└── README.md # Project documentation
```

## Installation

1. Clone the repository:
```
git clone https://github.com/yourusername/smart-wallet-retainer.git
cd smart-wallet-retainer
```

2. Install the dependencies:
```
npm install
```

## Usage

To deploy the contracts, run the following command:
```
truffle migrate
```

To run the tests for the SmartWallet contract, use:
```
truffle test
```

## Contracts Overview

### SmartWallet

The `SmartWallet` contract allows users to deposit and withdraw assets, as well as check their balance. It is designed to provide a secure way to manage digital assets.

### Retainer

The `Retainer` contract manages the relationship between the smart wallet and the assets it retains. It includes functions for asset management and retention logic.

## License

This project is licensed under the MIT License. See the LICENSE file for details.
25 changes: 25 additions & 0 deletions internal-testnet/smart-wallet-retainer/contracts/Retainer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pragma solidity ^0.8.0;

import "./SmartWallet.sol";

contract Retainer {
SmartWallet private smartWallet;

constructor(address _smartWalletAddress) {
smartWallet = SmartWallet(_smartWalletAddress);
}

function retainAsset(address asset, uint256 amount) external {
require(smartWallet.balanceOf(asset) >= amount, "Insufficient balance in SmartWallet");
smartWallet.transferFrom(msg.sender, address(this), asset, amount);
}

function releaseAsset(address asset, uint256 amount) external {
require(msg.sender == address(smartWallet), "Only SmartWallet can release assets");
smartWallet.transfer(asset, msg.sender, amount);
}

function getRetainedAssets() external view returns (address[] memory) {
// Logic to return retained assets
}
}
25 changes: 25 additions & 0 deletions internal-testnet/smart-wallet-retainer/contracts/SmartWallet.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pragma solidity ^0.8.0;

contract SmartWallet {
mapping(address => uint256) private balances;

event Deposited(address indexed user, uint256 amount);
event Withdrawn(address indexed user, uint256 amount);

function deposit() public payable {
require(msg.value > 0, "Deposit amount must be greater than zero");
balances[msg.sender] += msg.value;
emit Deposited(msg.sender, msg.value);
}

function withdraw(uint256 amount) public {
require(balances[msg.sender] >= amount, "Insufficient balance");
balances[msg.sender] -= amount;
payable(msg.sender).transfer(amount);
emit Withdrawn(msg.sender, amount);
}

function getBalance() public view returns (uint256) {
return balances[msg.sender];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = function(deployer) {
deployer.deploy(SmartWallet);
deployer.deploy(Retainer);
};
21 changes: 21 additions & 0 deletions internal-testnet/smart-wallet-retainer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "smart-wallet-retainer",
"version": "1.0.0",
"description": "A project for managing smart wallets and asset retention using smart contracts.",
"main": "index.js",
"scripts": {
"test": "truffle test",
"migrate": "truffle migrate",
"dev": "truffle develop"
},
"dependencies": {
"truffle": "^5.4.0",
"web3": "^1.5.0"
},
"devDependencies": {
"chai": "^4.3.0",
"mocha": "^8.3.0"
},
"author": "Your Name",
"license": "MIT"
}
31 changes: 31 additions & 0 deletions internal-testnet/smart-wallet-retainer/test/smartWalletTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const SmartWallet = artifacts.require("SmartWallet");

contract("SmartWallet", accounts => {
let smartWallet;

beforeEach(async () => {
smartWallet = await SmartWallet.new();
});

it("should allow deposits", async () => {
const depositAmount = web3.utils.toWei("1", "ether");
await smartWallet.deposit({ value: depositAmount });
const balance = await smartWallet.getBalance();
assert.equal(balance.toString(), depositAmount, "Balance should be equal to the deposited amount");
});

it("should allow withdrawals", async () => {
const depositAmount = web3.utils.toWei("1", "ether");
await smartWallet.deposit({ value: depositAmount });
await smartWallet.withdraw(depositAmount);
const balance = await smartWallet.getBalance();
assert.equal(balance.toString(), "0", "Balance should be zero after withdrawal");
});

it("should return the correct balance", async () => {
const depositAmount = web3.utils.toWei("1", "ether");
await smartWallet.deposit({ value: depositAmount });
const balance = await smartWallet.getBalance();
assert.equal(balance.toString(), depositAmount, "Balance should be equal to the deposited amount");
});
});
14 changes: 14 additions & 0 deletions internal-testnet/smart-wallet-retainer/truffle-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 7545,
network_id: "*"
}
},
compilers: {
solc: {
version: "0.8.0"
}
}
};
26 changes: 26 additions & 0 deletions keyManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

import * as crypto from 'crypto';

class KeyManager {
private keys: Map<string, string>;

constructor() {
this.keys = new Map();
}

generateKey(keyName: string): string {
const key = crypto.randomBytes(32).toString('hex');
this.keys.set(keyName, key);
return key;
}

getKey(keyName: string): string | undefined {
return this.keys.get(keyName);
}

deleteKey(keyName: string): boolean {
return this.keys.delete(keyName);
}
}

export default KeyManager;