Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Arbitrum goerli preparations #1239

Merged
merged 5 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ describes the project at a high level.
- [Testnets](#testnets)
- [Goerli](#goerli)
- [Running the smoke tests](#running-the-smoke-tests)
- [Arbitrum on Goerli](#arbitrum-on-goerli)

## Obtaining the source code

Expand Down Expand Up @@ -705,3 +706,9 @@ project and use their arbitrum goerli RPC and use it via
```
CAPE_WEB3_PROVIDER_URL=https://arbitrum-goerli.infura.io/v3/... run-tests-arbitrum
```

To deploy mintable tokens that users can mint by sending Ether to it run

```
hardhat deploy --tags Token --network arbitrum_goerli --reset
```
5 changes: 4 additions & 1 deletion contracts/contracts/SimpleToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ pragma solidity ^0.8.0;
import "./WrapToken.sol";

contract SimpleToken is WrapToken {
constructor() WrapToken("Simple Token", "SIT") {}
/// @notice The deployer receives 1e9 units.
constructor() WrapToken("Simple Token", "SIT") {
_mint(msg.sender, 1_000_000_000);
}
}
4 changes: 4 additions & 0 deletions contracts/contracts/USDC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ import "./WrapToken.sol";

contract USDC is WrapToken {
constructor() WrapToken("USD Coin", "USDC") {}

function decimals() public pure override returns (uint8) {
return 6;
}
}
16 changes: 5 additions & 11 deletions contracts/contracts/WrapToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,18 @@ import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

/// @notice This token is only intended to be used for testing.
contract WrapToken is ERC20 {
/// @notice The caller of this method receives 1000*10**6 units.
constructor(string memory name, string memory symbol) ERC20(name, symbol) {
_mint(msg.sender, 1000 * 10**6);
}
constructor(string memory name, string memory symbol) ERC20(name, symbol) {}

/// @notice Allows minting tokens by sending Ether to it.
receive() external payable {
_mint(msg.sender, 10**6 * msg.value);
}

function decimals() public view virtual override returns (uint8) {
return 6;
uint256 amount = msg.value / 10**(18 - decimals());
_mint(msg.sender, amount);
}

function withdraw() external payable {
function withdraw() external {
uint256 balance = balanceOf(msg.sender);
address payable sender = payable(msg.sender);
_burn(sender, balance);
sender.transfer(balance / 10**6);
sender.transfer(balance * 10**(18 - decimals()));
}
}
17 changes: 11 additions & 6 deletions contracts/deploy/10_token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ import { DeployFunction } from "hardhat-deploy/types";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre;
const { deploy } = deployments;
const { tokenOwner } = await getNamedAccounts();
const { deploy, log, read, execute } = deployments;
const { deployer } = await getNamedAccounts();

await deploy("SimpleToken", { from: tokenOwner, log: true });
await deploy("WETH", { from: tokenOwner, log: true });
await deploy("DAI", { from: tokenOwner, log: true });
await deploy("USDC", { from: tokenOwner, log: true });
const deployToken = async (name: string) => {
await deploy(name, { from: deployer, log: true });
let decimals = await read(name, "decimals");
log(`Deployed with ${decimals} decimals`);
};

await deployToken("WETH");
await deployToken("DAI");
await deployToken("USDC");
};

export default func;
Expand Down
65 changes: 65 additions & 0 deletions contracts/test/token.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) 2022 Espresso Systems (espressosys.com)
// This file is part of the Configurable Asset Privacy for Ethereum (CAPE) library.
//
// This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

import { expect } from "chai";
import { ethers } from "hardhat";
import { BigNumber, BigNumberish } from "ethers";
const { utils } = ethers;

describe("Token", function () {
let contract: any;

beforeEach(async () => {
const factory = await ethers.getContractFactory("USDC");
contract = await factory.deploy();
});

it("Mints and withdraws correctly", async function () {
const [owner] = await ethers.getSigners();
const provider = new ethers.providers.JsonRpcProvider();
const decimals = await contract.decimals();
let receipts = [];

let beforeEther = await provider.getBalance(owner.address);
let beforeToken = await contract.balanceOf(owner.address);

// Wrap some Ether.
const etherAmount = BigNumber.from("123");
const tokenAmount = utils.parseUnits(etherAmount.toString(), decimals);
let tx = await owner.sendTransaction({
to: contract.address,
value: utils.parseEther(etherAmount.toString()),
});
await tx.wait();
receipts.push(await provider.getTransactionReceipt(tx.hash));

let afterToken = await contract.balanceOf(owner.address);

expect(afterToken).to.equal(beforeToken.add(tokenAmount));

// Unwrap the tokens back into Ether.
tx = await contract.withdraw({ gasLimit: 1000000 }); // unpredictable gas limit due to storage free
await tx.wait();
receipts.push(await provider.getTransactionReceipt(tx.hash));

const gasFee = receipts.reduce((acc, receipt) => {
return acc.add(receipt.gasUsed.mul(receipt.effectiveGasPrice));
}, BigNumber.from(0));

// Token balance is zero.
expect(await contract.balanceOf(owner.address)).to.equal(0);

// Contract has zero Ether.
expect(await contract.balanceOf(contract.address)).to.equal(0);

// Note: This test can get flaky if geth has been running for a long time
// and the last check may fail in that case. It's therefore currently disabled.

// Ether balance is the same as originally (minus gas fees)
// expect(await provider.getBalance(owner.address)).to.equal(beforeEther.sub(gasFee));
});
});
6 changes: 3 additions & 3 deletions wallet.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ RUN chmod +x /app/wallet-cli

# Point at the Goerli testnet deployment by default; all of these settings can be overridden with
# command line options.
ENV CAPE_EQS_URL=https://eqs.goerli.cape.tech
ENV CAPE_RELAYER_URL=https://relayer.goerli.cape.tech
ENV CAPE_ADDRESS_BOOK_URL=https://address-book.goerli.cape.tech
ENV CAPE_EQS_URL=https://eqs.arbitrum-goerli.cape.tech
ENV CAPE_RELAYER_URL=https://relayer.arbitrum-goerli.cape.tech
ENV CAPE_ADDRESS_BOOK_URL=https://address-book.arbitrum-goerli.cape.tech

# Set the storage directory to allow the wallet to access the official assets library.
ENV CAPE_WALLET_STORAGE=/.espresso
Expand Down