Skip to content

Commit

Permalink
first draft of Batch swap DEX
Browse files Browse the repository at this point in the history
  • Loading branch information
jatZama committed Feb 15, 2024
1 parent e26201e commit b2134ee
Show file tree
Hide file tree
Showing 10 changed files with 304 additions and 400 deletions.
10 changes: 8 additions & 2 deletions contracts/EncryptedERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract EncryptedERC20 is Reencrypt, Ownable2Step {
event Approval(address indexed owner, address indexed spender);
event Mint(address indexed to, uint32 amount);

uint32 private _totalSupply;
uint32 internal _totalSupply;
string private _name;
string private _symbol;
uint8 public constant decimals = 0;
Expand Down Expand Up @@ -75,6 +75,11 @@ contract EncryptedERC20 is Reencrypt, Ownable2Step {
return TFHE.reencrypt(TFHE.asEuint32(0), publicKey, 0);
}

// Returns the balance of the caller encrypted under the provided public key.
function balanceOfMe() public view returns (euint32) {
return balances[msg.sender];
}

// Sets the `encryptedAmount` as the allowance of `spender` over the caller's tokens.
function approve(address spender, bytes calldata encryptedAmount) public virtual returns (bool) {
approve(spender, TFHE.asEuint32(encryptedAmount));
Expand Down Expand Up @@ -145,4 +150,5 @@ contract EncryptedERC20 is Reencrypt, Ownable2Step {
balances[from] = balances[from] - TFHE.cmux(isTransferable, amount, TFHE.asEuint32(0));
emit Transfer(from, to);
}
}
}

15 changes: 0 additions & 15 deletions contracts/Token.sol

This file was deleted.

2 changes: 2 additions & 0 deletions contracts/UniswapV2Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ contract UniswapV2Factory {
return allPairs.length;
}

// tokenA and tokenB should be EncryptedERC20_32 contracts
function createPair(address tokenA, address tokenB) external returns (address pair) {
require(tokenA != tokenB, "UniswapV2: IDENTICAL_ADDRESSES");
(address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
Expand All @@ -26,4 +27,5 @@ contract UniswapV2Factory {
allPairs.push(pair);
emit PairCreated(token0, token1, pair, allPairs.length);
}

}
350 changes: 231 additions & 119 deletions contracts/UniswapV2Pair.sol

Large diffs are not rendered by default.

151 changes: 0 additions & 151 deletions contracts/UniswapV2Router.sol

This file was deleted.

58 changes: 0 additions & 58 deletions contracts/libraries/UniswapV2Library.sol

This file was deleted.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
"@types/node": "^18.11.9",
"@typescript-eslint/eslint-plugin": "^5.44.0",
"@typescript-eslint/parser": "^5.44.0",
"bigint-buffer": "^1.1.5",
"chai": "^4.3.7",
"cross-env": "^7.0.3",
"dotenv": "^16.0.3",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"ethers": "^6.8.0",
"fhevm": "^0.3.0",
"fhevmjs": "^0.3.1",
"fhevmjs": "^0.4.0-3",
"fs-extra": "^10.1.0",
"hardhat": "^2.19.4",
"hardhat-deploy": "^0.11.29",
Expand Down Expand Up @@ -82,7 +83,7 @@
"task:mint": "hardhat task:mint",
"task:deployERC20": "hardhat task:deployERC20",
"task:accounts": "hardhat task:accounts",
"fhevm:start": "docker run -i -p 8545:8545 -p 8546:8546 --rm --name fhevm ghcr.io/zama-ai/ethermint-dev-node:v0.2.4",
"fhevm:start": "docker run -i -p 8545:8545 -p 8546:8546 --rm --name fhevm ghcr.io/zama-ai/ethermint-dev-node:v0.3.0-0",
"fhevm:stop": "docker rm -f fhevm",
"fhevm:restart": "fhevm:stop && fhevm:start",
"fhevm:faucet": "npm run fhevm:faucet:alice && sleep 5 && npm run fhevm:faucet:bob && sleep 5 && npm run fhevm:faucet:carol && sleep 5 && npm run fhevm:faucet:dave && sleep 5 && npm run fhevm:faucet:eve",
Expand Down
Loading

0 comments on commit b2134ee

Please sign in to comment.