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

feat: Add VestingWallet #402

Merged
merged 147 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
e8f70ca
Implement basic VestingWallet data structures
0xNeshi Oct 9, 2024
4f27740
Add getters
0xNeshi Oct 9, 2024
c7be5ed
Add vestingAmount methods
0xNeshi Oct 9, 2024
c9d79c7
add releasable methods
0xNeshi Oct 9, 2024
7a5b390
Add release_eth/token
0xNeshi Oct 9, 2024
39a5535
fix comment grammar
0xNeshi Oct 9, 2024
b8e006a
Add stylus_sdk errors to expected errors for 'release'
0xNeshi Oct 9, 2024
aea79ea
Format comments
0xNeshi Oct 9, 2024
6048de3
Add simple getter tests
0xNeshi Oct 10, 2024
f4fd2c0
Fix tests
0xNeshi Oct 10, 2024
fce3c51
refactor tests
0xNeshi Oct 10, 2024
7d002ce
revert test format
0xNeshi Oct 10, 2024
ae68003
Fix comment links + update VestingWallet comment
0xNeshi Oct 10, 2024
4dc658f
put events before errors
0xNeshi Oct 10, 2024
b38960c
Fix 'transfer' comment
0xNeshi Oct 10, 2024
56d6805
Fix Error comment
0xNeshi Oct 10, 2024
0d4d353
update _token suffix -> _erc20
0xNeshi Oct 10, 2024
f5230d7
add test for _vested_schedule
0xNeshi Oct 10, 2024
75bce62
update _vesting_schedule to accept U64 + fix tests
0xNeshi Oct 10, 2024
88abbb2
Set up integration test scaffold
0xNeshi Oct 10, 2024
59b34b6
Revert e2e-tests.sh change
0xNeshi Oct 11, 2024
e06f498
Redefine methods in VestingWalletExample
0xNeshi Oct 11, 2024
e33722d
Revert "Redefine methods in VestingWalletExample"
0xNeshi Oct 11, 2024
37a11ac
Disinherit Ownable in VestingWallet
0xNeshi Oct 11, 2024
efd4b34
Add Ownable errors + override owner method
0xNeshi Oct 11, 2024
21f5425
reorder fields to match actual contract's
0xNeshi Oct 11, 2024
0604a0f
Remove immutable from constructor.sol
0xNeshi Oct 12, 2024
39dd74b
Rename vesting_wallet->vesting-wallet
0xNeshi Oct 14, 2024
44b9990
use Ownable constructor logic in constructor.sol
0xNeshi Oct 14, 2024
3cd13a8
Set const BLOCK_TIMESTAMP in tests
0xNeshi Oct 14, 2024
584a3e5
add mock erc20
0xNeshi Oct 14, 2024
57227ce
Add working erc20 vesting test
0xNeshi Oct 14, 2024
48aa9ac
add receive to abi/mod.rs
0xNeshi Oct 14, 2024
b675d79
add rejects_zero_address_for_beneficiary test
0xNeshi Oct 14, 2024
679742b
Add check vesting schedule test for erc20
0xNeshi Oct 14, 2024
445c0c3
implement check_vesting_schedule for ether + minor refactor
0xNeshi Oct 14, 2024
e23ddf9
refactor
0xNeshi Oct 14, 2024
fb7d9ba
check owner in 'constructs' test
0xNeshi Oct 14, 2024
bb93711
revert e2e-tests.sh
0xNeshi Oct 14, 2024
e033bd0
fetch timestamp dynamically
0xNeshi Oct 15, 2024
96d582f
remove helper timestamp and blocknumber methods
0xNeshi Oct 15, 2024
0a0b58e
use const DURATION
0xNeshi Oct 15, 2024
4de613c
Add check_releasable_X_percentage for ether
0xNeshi Oct 15, 2024
4e11eba
test 'release' for ether inside existing tests
0xNeshi Oct 15, 2024
4f3f6b9
rename check_releasable_0_percent->check_release_0_percent
0xNeshi Oct 15, 2024
458b65b
extract balance
0xNeshi Oct 15, 2024
35e1de4
Add assert_in_delta function
0xNeshi Oct 15, 2024
c96bc23
Add release tests for erc20
0xNeshi Oct 15, 2024
eba2886
vesting_in_past -> vesting_in_the_past
0xNeshi Oct 15, 2024
219f5dc
Extract common check_release logic
0xNeshi Oct 15, 2024
6e4b2c5
Revert e2e-tests.sh
0xNeshi Oct 15, 2024
64bb034
Remove OwnableUnauthorizedAccount from mod.rs
0xNeshi Oct 15, 2024
64d6db6
Missing new line in Erc20 mock
0xNeshi Oct 15, 2024
01c3f0a
Add comment to assert_in_delta
0xNeshi Oct 15, 2024
710cf86
Remove expected_releasable from run_check_release (calc. it from time…
0xNeshi Oct 15, 2024
18682bf
Run cargo fmt
0xNeshi Oct 15, 2024
33f0be5
revert e2e-tests.sh
0xNeshi Oct 15, 2024
a1dead2
Reimplement transfer_ownership & renounce_ownership
0xNeshi Oct 16, 2024
1314a16
Use transfer_eth
0xNeshi Oct 16, 2024
a34adc5
Merge branch 'main' into vesting-wallet
0xNeshi Nov 11, 2024
548c6c9
ref: align example's cargo.toml + import SolidityError from stylus_sdk
0xNeshi Nov 11, 2024
7060af1
ref: format code
0xNeshi Nov 11, 2024
e8e4871
ref: move ierc20 sol interface to local module (avoid missing docs warn)
0xNeshi Nov 11, 2024
8e7270b
fix: remove no_std from vesting-wallet example
0xNeshi Nov 11, 2024
26d8f4b
docs: update CHANGELOG.md
0xNeshi Nov 11, 2024
b2bdc0b
ref: interface casing change IERC20->IErc20
0xNeshi Nov 11, 2024
fc07654
fix: SafeErc20 comment article an->a
0xNeshi Nov 11, 2024
3274415
ref: add IVestingWallet trait
0xNeshi Nov 11, 2024
225716c
ref: rename _vesting_schedule->vesting_schedule
0xNeshi Nov 11, 2024
2e76cf6
fix(tests): add missing IVestingWallet import
0xNeshi Nov 11, 2024
b71170c
ref: update err msg in release_erc20
0xNeshi Nov 11, 2024
166b7c9
fix: docs
0xNeshi Nov 11, 2024
a09a273
fix: return Self::Error in IVestingWallet trait fns
0xNeshi Nov 11, 2024
76c3edd
fix: add missing comment sections (partial)
0xNeshi Nov 11, 2024
a23291c
ref: remove redundant /// in nonces
0xNeshi Nov 12, 2024
e2b5cd9
ref: use unchecked checked_add in end()
0xNeshi Nov 12, 2024
4070246
docs: add missing args section to vesting_schedule
0xNeshi Nov 12, 2024
192a5dd
ref: vesting_schedule
0xNeshi Nov 12, 2024
a6840ac
ref: use checked_add for vested_amount + release fns
0xNeshi Nov 12, 2024
37651f8
ref: remove redundant unsafe sections
0xNeshi Nov 12, 2024
c7e09cb
docs: add missing SAFETY comments to releasable
0xNeshi Nov 12, 2024
be19843
ref: use SafeErc20 for transfer + RawCall for balanceOf
0xNeshi Nov 12, 2024
c9762ce
fix: move SafeErc20 state to the bottom of the storage
0xNeshi Nov 12, 2024
503d0f6
docs: add missing comment sections
0xNeshi Nov 12, 2024
5de1394
ref: rename reads_vesting_allocation->gets_vesting_schedule + extract…
0xNeshi Nov 12, 2024
9763ff4
ref: assert 0 vested amount when deployed
0xNeshi Nov 12, 2024
da9fdf2
Revert e2e-tests.sh
0xNeshi Nov 12, 2024
a7ac3ff
revert: assert 0 vested amount when deployed
0xNeshi Nov 12, 2024
f5c1410
fix: change Self::only_owner->Ownable::only_owner
0xNeshi Nov 12, 2024
5123c4d
feat: add additional unit tests for end() and vesting_schedule + upda…
0xNeshi Nov 12, 2024
8b6854a
ref: extract common deployment logic for erc20 e2e tests
0xNeshi Nov 12, 2024
5e3cddb
build(deps): bump crate-ci/typos from 1.27.2 to 1.27.3 (#401)
0xNeshi Nov 12, 2024
5665362
fix: cast to U256 earlier to avoid overflow in reads_max_end test
0xNeshi Nov 13, 2024
2042642
feat(test): add invalid token tests
0xNeshi Nov 13, 2024
5e02d9f
feat(test): add release_erc20_reverts_on_failed_transfer
0xNeshi Nov 13, 2024
e54df17
fix: revert e2e-tests.sh
0xNeshi Nov 13, 2024
ba28f42
Merge remote-tracking branch 'origin/main' into vesting-wallet
0xNeshi Nov 13, 2024
af39e24
Merge branch 'main' into vesting-wallet
bidzyyys Nov 15, 2024
254512e
docs: Apply comment updates from code review
0xNeshi Nov 18, 2024
0a911b1
ref: remove redundant var "one" from gets_vesting_schedule_zero_duration
0xNeshi Nov 18, 2024
8f4b15a
ref: remove TODO for using existing IErc20
0xNeshi Nov 18, 2024
4c4bc37
docs: use consistent naming for Ether
0xNeshi Nov 18, 2024
932a7fd
ref: remove unused IErc20::transfer
0xNeshi Nov 18, 2024
cd962a4
ref: remove selector attr from trait def
0xNeshi Nov 18, 2024
c18cb9d
revert: add back selector attr to trait def
0xNeshi Nov 18, 2024
3767df0
ref: use Call to get erc20 balance
0xNeshi Nov 18, 2024
3339d41
feat: add bench
0xNeshi Nov 18, 2024
33fd13a
ref: format VestingWallet solidity in benches
0xNeshi Nov 19, 2024
188c5b1
feat: bench receiveEther
0xNeshi Nov 19, 2024
d87382c
docs: Apply comment updates from code review
0xNeshi Nov 19, 2024
3306f5e
ref: move enum Error closer to sol errors
0xNeshi Nov 19, 2024
e5929d3
ref: move receive_ether below ownable fns
0xNeshi Nov 19, 2024
3acb769
ref: format constructor.sol
0xNeshi Nov 19, 2024
4499d71
docs: format end's SAFETY comment
0xNeshi Nov 19, 2024
770fe2d
ref: emit EtherReleased after transferring
0xNeshi Nov 19, 2024
b57df13
fix: checked_add for total allocation
0xNeshi Nov 19, 2024
93b317e
docs: clarify panic error for vesting_schedule
0xNeshi Nov 19, 2024
aa35f89
ref: add back unchecked additions for erc20
0xNeshi Nov 19, 2024
ed4ce98
ref: remove zero token address check
0xNeshi Nov 19, 2024
a4043b6
ref(tests): separate deploy fns for individual contracts
0xNeshi Nov 19, 2024
2040925
ref(tests): add deploy fn for eth tests
0xNeshi Nov 19, 2024
986a584
fix(tests): fix failing test compilation
0xNeshi Nov 19, 2024
c73a640
Merge branch 'main' into vesting-wallet
0xNeshi Nov 19, 2024
09ef93f
ref(test): check_vesting_schedule->check_vested_amount
0xNeshi Nov 19, 2024
3277ccf
ref(tests): fix expect_err msg in safe_erc20
0xNeshi Nov 19, 2024
a7abc28
test: add vested_amount_reverts_on_scaled_allocation_overflow
0xNeshi Nov 19, 2024
b748068
docs: use generic ERC-20 when referring to tokens
0xNeshi Nov 19, 2024
65ca111
feat: add vesting_wallet bench to report
0xNeshi Nov 20, 2024
d1e4ee7
ref: temporarily comment out erc20-related benches
0xNeshi Nov 20, 2024
cf5a100
revert: add back erc20-related benches
0xNeshi Nov 20, 2024
ea75250
ref: remove vesting wallet from benches report
0xNeshi Nov 20, 2024
35a8657
Merge branch 'main' into vesting-wallet
0xNeshi Nov 20, 2024
ba27815
Merge branch 'main' into vesting-wallet
bidzyyys Nov 20, 2024
ee24a1f
add grammar fixes
qalisander Nov 25, 2024
748ebeb
Merge branch 'main' into vesting-wallet
bidzyyys Nov 25, 2024
f826a72
fix: return SafeErc20 errors on release_erc20
0xNeshi Nov 26, 2024
68cf360
fix: pass through the underlying call error when releasing eth
0xNeshi Nov 26, 2024
cde0639
ref(test): explicitly import BlockTransactionsKind
0xNeshi Nov 26, 2024
729a646
ref(test): add init method to motsu tests
0xNeshi Nov 26, 2024
14e736e
chore: update changelog
0xNeshi Nov 26, 2024
b28464b
Merge branch 'main' into vesting-wallet
0xNeshi Nov 27, 2024
2a272f3
ref: use checked_add in release fns
0xNeshi Nov 27, 2024
eba07b4
fix: remove redundant mut self from vested_amount & releasable
0xNeshi Nov 28, 2024
fa0ebab
fix: call safe_transfer after state updates
0xNeshi Nov 28, 2024
c6af098
Merge branch 'main' into vesting-wallet
bidzyyys Nov 28, 2024
0f1f60c
ref: update GUIDELINES.md
bidzyyys Nov 28, 2024
f5892d2
ref: update CHANGELOG.md
bidzyyys Nov 28, 2024
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
14 changes: 4 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- `IErc1155Burnable` extension. #417
- `VestingWallet` contract. #402
- `Erc1155Burnable` extension. #417

### Changed

- Use `function_selector!` to calculate transfer type selector in `Erc1155`. #417
- Implement `MethodError` for `safe_erc20::Error`. #402
- Use `function_selector!` to calculate transfer type selector in `Erc1155`. #417

### Fixed

Expand All @@ -33,14 +35,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Removed `only_owner` from the public interface of `Ownable`. #352

### Changed

-

### Fixed

-

## [0.1.1] - 2024-10-28

### Changed
Expand Down
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ members = [
"examples/erc1155",
"examples/merkle-proofs",
"examples/ownable",
"examples/vesting-wallet",
"examples/access-control",
"examples/basic/token",
"examples/basic/script",
Expand All @@ -39,6 +40,7 @@ default-members = [
"examples/safe-erc20",
"examples/merkle-proofs",
"examples/ownable",
"examples/vesting-wallet",
"examples/ownable-two-step",
"examples/access-control",
"examples/basic/token",
Expand Down
2 changes: 1 addition & 1 deletion GUIDELINES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Setup

1. Install [Docker].
1. Install the [Solidity Compiler] version `0.8.24`
1. Install the [Solidity Compiler] version `0.8.24`.
(NOTE: it is important to use this exact version to avoid compatibility issues).
1. Install toolchain providing `cargo` using [rustup].
1. Install the cargo stylus tool with `cargo install --force cargo-stylus`.
Expand Down
2 changes: 2 additions & 0 deletions benches/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub mod erc721;
pub mod merkle_proofs;
pub mod ownable;
pub mod report;
pub mod vesting_wallet;

#[derive(Debug, Deserialize)]
struct ArbOtherFields {
Expand All @@ -32,6 +33,7 @@ struct ArbOtherFields {

/// Cache options for the contract.
/// `Bid(0)` will likely cache the contract on the nitro test node.
#[derive(Clone)]
pub enum CacheOpt {
None,
Bid(u32),
Expand Down
132 changes: 132 additions & 0 deletions benches/src/vesting_wallet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
use alloy::{
network::{AnyNetwork, EthereumWallet},
primitives::Address,
providers::ProviderBuilder,
sol,
sol_types::{SolCall, SolConstructor},
uint,
};
use alloy_primitives::U256;
use e2e::{receipt, Account};

use crate::{
report::{ContractReport, FunctionReport},
CacheOpt,
};

sol!(
#[sol(rpc)]
contract VestingWallet {
function owner() public view virtual returns (address owner);
function receiveEther() external payable virtual;
function start() external view returns (uint256 start);
function duration() external view returns (uint256 duration);
function end() external view returns (uint256 end);
function released() external view returns (uint256 released);
function released(address token) external view returns (uint256 released);
function releasable() external view returns (uint256 releasable);
function releasable(address token) external view returns (uint256 releasable);
function release() external;
function release(address token) external;
function vestedAmount(uint64 timestamp) external view returns (uint256 vestedAmount);
function vestedAmount(address token, uint64 timestamp) external view returns (uint256 vestedAmount);
}

#[sol(rpc)]
contract Erc20 {
function mint(address account, uint256 amount) external;
}
);

sol!("../examples/vesting-wallet/src/constructor.sol");
sol!("../examples/erc20/src/constructor.sol");

const START_TIMESTAMP: u64 = 1000;
const DURATION_SECONDS: u64 = 1000;

const TOKEN_NAME: &str = "Test Token";
const TOKEN_SYMBOL: &str = "TTK";
const CAP: U256 = uint!(1_000_000_U256);

pub async fn bench() -> eyre::Result<ContractReport> {
let reports = run_with(CacheOpt::None).await?;
let report = reports
.into_iter()
.try_fold(ContractReport::new("VestingWallet"), ContractReport::add)?;

let cached_reports = run_with(CacheOpt::Bid(0)).await?;
let report = cached_reports
.into_iter()
.try_fold(report, ContractReport::add_cached)?;

Ok(report)
}

pub async fn run_with(
cache_opt: CacheOpt,
) -> eyre::Result<Vec<FunctionReport>> {
let alice = Account::new().await?;
let alice_wallet = ProviderBuilder::new()
.network::<AnyNetwork>()
.with_recommended_fillers()
.wallet(EthereumWallet::from(alice.signer.clone()))
.on_http(alice.url().parse()?);

let contract_addr = deploy(&alice, cache_opt.clone()).await?;
let erc20_addr = deploy_token(&alice, cache_opt).await?;

let contract = VestingWallet::new(contract_addr, &alice_wallet);
let erc20 = Erc20::new(erc20_addr, &alice_wallet);

let _ = receipt!(contract.receiveEther().value(uint!(1000_U256)))?;
0xNeshi marked this conversation as resolved.
Show resolved Hide resolved
let _ = receipt!(erc20.mint(contract_addr, uint!(1000_U256)))?;

// IMPORTANT: Order matters!
use VestingWallet::*;
#[rustfmt::skip]
let receipts = vec![
(receiveEtherCall::SIGNATURE, receipt!(contract.receiveEther())?),
(startCall::SIGNATURE, receipt!(contract.start())?),
(durationCall::SIGNATURE, receipt!(contract.duration())?),
(endCall::SIGNATURE, receipt!(contract.end())?),
(released_0Call::SIGNATURE, receipt!(contract.released_0())?),
(released_1Call::SIGNATURE, receipt!(contract.released_1(erc20_addr))?),
(releasable_0Call::SIGNATURE, receipt!(contract.releasable_0())?),
(releasable_1Call::SIGNATURE, receipt!(contract.releasable_1(erc20_addr))?),
(release_0Call::SIGNATURE, receipt!(contract.release_0())?),
(release_1Call::SIGNATURE, receipt!(contract.release_1(erc20_addr))?),
(vestedAmount_0Call::SIGNATURE, receipt!(contract.vestedAmount_0(START_TIMESTAMP))?),
(vestedAmount_1Call::SIGNATURE, receipt!(contract.vestedAmount_1(erc20_addr, START_TIMESTAMP))?),
];

receipts
.into_iter()
.map(FunctionReport::new)
.collect::<eyre::Result<Vec<_>>>()
}

async fn deploy(
account: &Account,
cache_opt: CacheOpt,
) -> eyre::Result<Address> {
let args = VestingWalletExample::constructorCall {
beneficiary: account.address(),
startTimestamp: START_TIMESTAMP,
durationSeconds: DURATION_SECONDS,
};
let args = alloy::hex::encode(args.abi_encode());
crate::deploy(account, "vesting-wallet", Some(args), cache_opt).await
}

async fn deploy_token(
account: &Account,
cache_opt: CacheOpt,
) -> eyre::Result<Address> {
let args = Erc20Example::constructorCall {
name_: TOKEN_NAME.to_owned(),
symbol_: TOKEN_SYMBOL.to_owned(),
cap_: CAP,
};
let args = alloy::hex::encode(args.abi_encode());
crate::deploy(account, "erc20", Some(args), cache_opt).await
}
2 changes: 2 additions & 0 deletions contracts/src/finance/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
//! Primitives for financial systems.
pub mod vesting_wallet;
Loading
Loading