Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
6f46957
initial
Okm165 Aug 23, 2023
0684b57
modals
Okm165 Aug 23, 2023
e4ee407
looks good no backend
Okm165 Aug 24, 2023
29b9c45
minor fixes
Okm165 Aug 24, 2023
6b243c2
frontend improvements
Okm165 Aug 24, 2023
2c72878
fetch user balance
neotheprogramist Aug 24, 2023
7a0019d
linting
neotheprogramist Aug 24, 2023
860f3bf
linting
neotheprogramist Aug 24, 2023
4f479db
wallet works
Okm165 Aug 24, 2023
053c4ab
merge fix
Okm165 Aug 24, 2023
234f13c
basic deposit view
neotheprogramist Aug 24, 2023
0314982
Contract Address Provider & updates
neotheprogramist Aug 24, 2023
4ffec94
fix deposit params
neotheprogramist Aug 24, 2023
bfc5c6a
transfers in progress and dark mode
Okm165 Aug 24, 2023
ccc79a6
withdraws working
neotheprogramist Aug 24, 2023
7ccb066
frontend for transfers
Okm165 Aug 24, 2023
30e37bf
deposit withdraw design adjusted
Okm165 Aug 24, 2023
19b0cc7
minor fixes
Okm165 Aug 24, 2023
6fa6d82
tiny fixes & confirmation struct
neotheprogramist Aug 23, 2023
a206954
add icon path
neotheprogramist Aug 23, 2023
69c32c1
initial
Okm165 Aug 23, 2023
4659588
transfer endpoint in progress
neotheprogramist Aug 24, 2023
88cb69c
new endpoint in progress
neotheprogramist Aug 25, 2023
df92681
external account fetch
neotheprogramist Aug 25, 2023
7c5b5a7
transfer display endpoint
neotheprogramist Aug 25, 2023
c81afc9
remove user email & phone
neotheprogramist Aug 25, 2023
683fb87
transfers display fix
Okm165 Aug 25, 2023
27c568d
display transfer zod
Okm165 Aug 25, 2023
7a6c85d
TransferElement from to design
Okm165 Aug 25, 2023
0a7c699
transfers when session
Okm165 Aug 25, 2023
d4962ae
fix optional
neotheprogramist Aug 25, 2023
57392c0
visual enhancemnts
Okm165 Aug 25, 2023
e7c7df3
refactor display transfer
neotheprogramist Aug 25, 2023
f51e11f
transfer icons
Okm165 Aug 25, 2023
4b3f727
change external account to accept custom other user address
neotheprogramist Aug 25, 2023
8b2928f
rounding errors fixed
Okm165 Aug 25, 2023
3860abc
prepare to production deployment
neotheprogramist Aug 25, 2023
8a360d6
prepare for production
neotheprogramist Aug 26, 2023
d45af5a
fix tests
neotheprogramist Aug 26, 2023
8d38498
weth contract handler
neotheprogramist Aug 26, 2023
d63a268
transfers
Okm165 Aug 26, 2023
7a67bf3
production working
neotheprogramist Aug 26, 2023
3ed31c6
setup production
neotheprogramist Aug 27, 2023
4e0594e
fix for production
neotheprogramist Aug 27, 2023
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
4 changes: 2 additions & 2 deletions blockchain/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM ghcr.io/foundry-rs/foundry
ENTRYPOINT [ "anvil", "--block-time", "5", "--host", "0.0.0.0" ]
FROM ghcr.io/foundry-rs/foundry:v1.0.0
ENTRYPOINT [ "anvil", "--host", "0.0.0.0", "--port", "80", "--chain-id", "74207", "--block-time", "5" ]
58 changes: 40 additions & 18 deletions blockchain/apps/treasury/contracts/Treasury.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import "@openzeppelin/contracts/interfaces/IERC20.sol";
Expand All @@ -7,24 +7,44 @@ import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "./WETH.sol";

contract Treasury is Ownable, EIP712 {
address private publicKey;
address private publicKey_;
string private name_;
address payable private weth_;
bool private isFrozen_;

using Counters for Counters.Counter;

mapping(address => Counters.Counter) private _nonces;

// solhint-disable-next-line var-name-mixedcase
bytes32 private constant _PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,address token,uint256 value,uint256 nonce,uint256 deadline)");

event Deposit(address indexed owner, address indexed spender, address indexed token, uint256 amount);
event Withdraw(address indexed owner, address indexed spender, address indexed token, uint256 amount, uint256 nonce, uint256 deadline);

constructor(string memory _name, address _publicKey) EIP712(_name, "1") {
publicKey = _publicKey;
constructor(string memory _name, address payable _weth, address _publicKey) EIP712(_name, "1") {
publicKey_ = _publicKey;
name_ = _name;
weth_ = _weth;
isFrozen_ = false;
}

function isFrozen() public view returns (bool) {
return isFrozen_;
}

function freeze() onlyOwner external {
isFrozen_ = true;
}

function unfreeze() onlyOwner external {
isFrozen_ = false;
}

function adminWithdraw(address token, uint256 amount, address to) onlyOwner external {
IERC20(token).transfer(to, amount);
}

/**
Expand All @@ -41,14 +61,6 @@ contract Treasury is Ownable, EIP712 {
return _nonces[owner].current();
}

/**
* @dev See {IERC20Permit-DOMAIN_SEPARATOR}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32) {
return _domainSeparatorV4();
}

/**
* @dev "Consume a nonce": return the current value and increment.
*
Expand All @@ -60,28 +72,38 @@ contract Treasury is Ownable, EIP712 {
nonce.increment();
}

receive() external payable {
require(!isFrozen_, "Treasury: contract is fronzen");
address owner = address(msg.sender);
uint256 amount = msg.value;
IWETH(weth_).deposit{value: amount}();
emit Deposit(owner, publicKey_, weth_, amount);
}

function depositPermit(address token, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external {
require(!isFrozen_, "Treasury: contract is fronzen");
address owner = address(msg.sender);
IERC20Permit(token).permit(owner, address(this), amount, deadline, v, r, s);
IERC20(token).transferFrom(owner, address(this), amount);
emit Deposit(owner, publicKey, token, amount);
emit Deposit(owner, publicKey_, token, amount);
}

function withdrawPermit(address token, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s, address to) external {
require(!isFrozen_, "Treasury: contract is fronzen");
address owner = address(msg.sender);
uint256 nonce = _useNonce(owner);

require(block.timestamp <= deadline, "ERC20Permit: expired deadline");
require(block.timestamp <= deadline, "Treasury: expired deadline");

bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, publicKey, owner, token, amount, nonce, deadline));
bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, publicKey_, owner, token, amount, nonce, deadline));

bytes32 hash = _hashTypedDataV4(structHash);

address signer = ECDSA.recover(hash, v, r, s);
require(signer == publicKey, "ERC20Permit: invalid signature");
require(signer == publicKey_, "Treasury: invalid signature");

IERC20(token).transfer(to, amount);

emit Withdraw(publicKey, owner, token, amount, nonce, deadline);
emit Withdraw(publicKey_, owner, token, amount, nonce, deadline);
}
}
41 changes: 41 additions & 0 deletions blockchain/apps/treasury/contracts/WETH.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
import "@openzeppelin/contracts/interfaces/IERC20.sol";

interface IWETH is IERC20 {
event Deposit(address indexed from, uint256 value);
event Withdrawal(address indexed to, uint256 value);

receive() external payable;

function deposit() external payable;

function withdraw(uint256 wad) external;
}

contract WETH is IWETH, ERC20Permit {
constructor(
string memory _name,
string memory _symbol
) ERC20(_name, _symbol) ERC20Permit(_name) {}

receive() external payable {
deposit();
}

function deposit() public payable {
_mint(_msgSender(), msg.value);
emit Deposit(_msgSender(), msg.value);
}

function withdraw(uint256 amount) public {
require(balanceOf(_msgSender()) >= amount);
_burn(_msgSender(), amount);
payable(_msgSender()).transfer(amount);
emit Withdrawal(_msgSender(), amount);
}
}
6 changes: 6 additions & 0 deletions blockchain/apps/treasury/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ const config: HardhatUserConfig = {
local: {
url: "http://localhost:8545/",
},
testnet: {
url: "https://node.ksox.finance/",
},
polygon: {
url: "https://polygon-rpc.com/",
}
},
};

Expand Down
5 changes: 4 additions & 1 deletion blockchain/apps/treasury/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"scripts": {
"compile": "npx hardhat compile",
"test": "npx hardhat test",
"deploy": "npx hardhat --network local run scripts/deploy.ts"
"hardhat": "npx hardhat",
"deploy:local": "npx hardhat run --network local scripts/deploy.ts",
"deploy:testnet": "npx hardhat run --network testnet scripts/deploy.ts"
},
"author": "",
"license": "ISC",
Expand All @@ -15,6 +17,7 @@
},
"dependencies": {
"@openzeppelin/contracts": "^4.9.3",
"@trezor/connect": "^9.1.1",
"dotenv": "^16.3.1"
}
}
11 changes: 10 additions & 1 deletion blockchain/apps/treasury/scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { ethers } from "hardhat";
async function main() {
const [owner] = await ethers.getSigners();

const WethFactory = await ethers.getContractFactory("WETH");
const weth = await WethFactory.deploy("Wrapped Native", "WETH");
await weth.waitForDeployment();

const TokenFactory = await ethers.getContractFactory("Token");

const tokens = [
Expand All @@ -12,7 +16,11 @@ async function main() {
];

const TreasuryFactory = await ethers.getContractFactory("Treasury");
const treasury = await TreasuryFactory.deploy("Treasury", owner);
const treasury = await TreasuryFactory.deploy(
"Treasury",
await weth.getAddress(),
owner
);

console.log("waiting for token contracts to be deployed...");
for (let i = 0; i < tokens.length; i += 1) {
Expand Down Expand Up @@ -47,6 +55,7 @@ async function main() {
}
console.log("tokens minted");

console.log(`${await weth.name()}: ${await weth.getAddress()}`);
for (let i = 0; i < tokens.length; i += 1) {
const token = tokens[i];
console.log(`${await token.name()}: ${await token.getAddress()}`);
Expand Down
9 changes: 9 additions & 0 deletions blockchain/apps/treasury/scripts/generateRandomAccount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { privateKeyToAccount } from "viem/accounts";
import { toHex } from "viem/utils";
import { randomBytes } from "crypto";

let privateKey = toHex(randomBytes(32));
let account = privateKeyToAccount(privateKey);

console.log(privateKey);
console.log(account.address);
Loading