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

Minor improvements for the finance module #1209

Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- SRC9 (Outside Execution) integration to account presets (#1201)

### Changed (Breaking)

- VestingComponent `release` function won't emit an event or attempt to transfer when the amount is zero (#1209)

## 0.19.0 (2024-11-08)

### Added
Expand Down
6 changes: 4 additions & 2 deletions docs/modules/ROOT/pages/api/finance.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Returns the total vested amount of a specified `token` at a given `timestamp`.

Releases the amount of a given `token` that has already vested and returns that amount.

Emits {AmountReleased} event.
Emits an {AmountReleased} event.
ericnordelo marked this conversation as resolved.
Show resolved Hide resolved

[#IVesting-Events]
==== Events
Expand Down Expand Up @@ -208,11 +208,13 @@ Returns the total vested amount of a specified `token` at a given `timestamp`.

Releases the amount of a given `token` that has already vested and returns that amount.

NOTE: If the releasable amount is zero, this function won't emit the event.

ericnordelo marked this conversation as resolved.
Show resolved Hide resolved
Requirements:

- `transfer` call to the `token` must return `true` indicating a successful transfer.

Emits {AmountReleased} event.
May emit an {AmountReleased} event.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we specify here when an event won't be emitted? It feels bit weird given no context

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think the NOTE in the description is not enough?


[#VestingComponent-Internal-Functions]
==== Internal functions
Expand Down
27 changes: 16 additions & 11 deletions packages/finance/src/vesting/vesting.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ pub mod VestingComponent {
) -> u256;
}

//
// External
//

#[embeddable_as(VestingImpl)]
impl Vesting<
TContractState,
Expand Down Expand Up @@ -132,21 +136,25 @@ pub mod VestingComponent {

/// Releases the amount of a given `token` that has already vested.
///
/// NOTE: If the releasable amount is zero, this function won't emit the event.
///
/// Requirements:
///
/// - `transfer` call to the `token` must return `true` indicating a successful transfer.
///
/// Emits an `AmountReleased` event.
/// May emit an `AmountReleased` event.
fn release(ref self: ComponentState<TContractState>, token: ContractAddress) -> u256 {
let amount = self.releasable(token);
self.Vesting_released.write(token, self.Vesting_released.read(token) + amount);
self.emit(AmountReleased { token, amount });

let beneficiary = get_dep_component!(@self, Ownable).owner();
let token_dispatcher = IERC20Dispatcher { contract_address: token };
assert(token_dispatcher.transfer(beneficiary, amount), Errors::TOKEN_TRANSFER_FAILED);

if amount > 0 {
self.Vesting_released.write(token, self.Vesting_released.read(token) + amount);
self.emit(AmountReleased { token, amount });

let beneficiary = get_dep_component!(@self, Ownable).owner();
let token_dispatcher = IERC20Dispatcher { contract_address: token };
assert(
token_dispatcher.transfer(beneficiary, amount), Errors::TOKEN_TRANSFER_FAILED
);
}
ericnordelo marked this conversation as resolved.
Show resolved Hide resolved
amount
}
}
Expand All @@ -159,13 +167,10 @@ pub mod VestingComponent {
> of InternalTrait<TContractState> {
/// Initializes the component by setting the vesting `start`, `duration` and
/// `cliff_duration`.
/// To prevent reinitialization, this should only be used inside of a contract's
/// constructor.
///
/// Requirements:
///
/// - `cliff_duration` must be less than or equal to `duration`.
///
fn initializer(
ref self: ComponentState<TContractState>, start: u64, duration: u64, cliff_duration: u64
) {
Expand Down