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

Fee integration #62

Draft
wants to merge 53 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
fe4782a
WIP: Added fee implementation for deposits and withdraw
UrAvgDeveloper May 29, 2023
1b64ba7
Added unit test for finish-deposit method
UrAvgDeveloper May 29, 2023
1796006
fix linting
UrAvgDeveloper May 30, 2023
8c5811e
Merge branch 'master' into fee-integration
UrAvgDeveloper May 30, 2023
755fae9
rebased with new changes
UrAvgDeveloper May 30, 2023
8f4f282
changing linting and code style
UrAvgDeveloper May 30, 2023
8319f90
fixed code style
UrAvgDeveloper May 30, 2023
a8a4cb2
fixed linting and code style
UrAvgDeveloper May 30, 2023
581c4f0
CI fixes
UrAvgDeveloper May 30, 2023
446fb26
CI fix
UrAvgDeveloper May 30, 2023
622a40f
resolved some PR comments
UrAvgDeveloper May 30, 2023
b3e1604
formatting
UrAvgDeveloper May 30, 2023
236dc2e
fixed clippy suggestions
UrAvgDeveloper May 30, 2023
4d33363
added tests for fee-setters
UrAvgDeveloper Jun 7, 2023
c7fdabf
added enum for different fee-types
UrAvgDeveloper Jun 7, 2023
ef1c351
resolved dependancy issue
UrAvgDeveloper Jun 13, 2023
0255fcb
fixed fee minting mecheanism
UrAvgDeveloper Jun 19, 2023
6abb03a
fix ci:lints and withdraw_fee_bound test
UrAvgDeveloper Jun 19, 2023
466461e
added comments to fee-management storage
UrAvgDeveloper Jun 19, 2023
fd910ab
CI: fix linting
UrAvgDeveloper Jun 19, 2023
7173de4
fixed PR comments(1)
UrAvgDeveloper Jun 22, 2023
86e557c
fixed PR comments(2): wrapped upper_bound into Option<u128>
UrAvgDeveloper Jun 22, 2023
93f594d
fixed PR comments(3): wrapped lower_bound into Option<u128>
UrAvgDeveloper Jun 22, 2023
250a9fa
Merge branch 'master' into fee-integration
UrAvgDeveloper Jun 27, 2023
0d6a2e7
Added readme for fee-integration implementation in eth-connector cont…
UrAvgDeveloper Jun 28, 2023
ffc876b
Refactor fee implementation
karim-en Jul 20, 2023
1b9458d
Merge branch 'master' into fee-integration
karim-en Jul 20, 2023
e6486c7
Improve `claim_fee`
karim-en Jul 20, 2023
f4ff5d7
Fix tests and fee calculation
karim-en Jul 24, 2023
bfb6a0b
Cleanup unused code
karim-en Jul 24, 2023
0006dfd
Fix `cargo.toml` file
karim-en Jul 24, 2023
2325a2a
Fix clippy
karim-en Jul 24, 2023
7747a3e
Combine withdraw and deposit fee storage
karim-en Jul 24, 2023
a7d9a92
Implement storage migration
karim-en Jul 24, 2023
2cf9915
Skip minting if the amount is 0
karim-en Jul 24, 2023
72607a1
Remove `private` for migration.
karim-en Jul 24, 2023
8c65167
Fix test `test_deposit_to_aurora_amount_zero_fee_non_zero`
karim-en Jul 24, 2023
d8d2494
Use `assert_owner_access_right`
karim-en Jul 24, 2023
b740c7c
Add fee per silo logic
karim-en Jul 25, 2023
98bf6ee
Add fee getters
karim-en Jul 26, 2023
26c186a
Fee: use pass `sender_id` instead of `predecessor_account_id`
karim-en Jul 26, 2023
eb7ec90
Add test for `None` fee
karim-en Jul 26, 2023
c709963
Fee: add per silo tests
karim-en Jul 26, 2023
aea7543
Use `checked_mul`
karim-en Aug 4, 2023
10d1ab3
Improve code readability
karim-en Aug 6, 2023
0e6d363
Add logs
karim-en Aug 6, 2023
c4aec91
Add comments
karim-en Aug 9, 2023
136f9b1
Add fee owner functionality
karim-en Aug 9, 2023
05bb842
Update eth-connector/src/fee.rs
karim-en Aug 11, 2023
7b9fd39
Use doc comments
karim-en Aug 11, 2023
15fff9a
Remove the default fee from the `FeeStorage`
karim-en Aug 14, 2023
307d3a1
Use custom `log!`
karim-en Sep 4, 2023
9939668
Replace `U128` with `u32` for `fee_percentage`
karim-en Sep 4, 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
18 changes: 18 additions & 0 deletions eth-connector/src/connector.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::fee::{Fee, FeeType};
use crate::{connector_impl::FinishDepositCallArgs, Proof, VerifyProofArgs, WithdrawResult};
use aurora_engine_types::types::Address;
use near_contract_standards::storage_management::StorageBalance;
Expand All @@ -10,6 +11,23 @@ pub trait Deposit {
fn deposit(&mut self, #[serializer(borsh)] raw_proof: Proof) -> Promise;
}

#[ext_contract(ext_fee_manage)]
pub trait FeeManagement {
fn get_deposit_fee_per_silo(&self, silo: Option<AccountId>) -> Option<Fee>;
fn get_withdraw_fee_per_silo(&self, silo: Option<AccountId>) -> Option<Fee>;
fn get_fee_owner(&self) -> AccountId;
fn calculate_fee_amount(
&self,
amount: U128,
fee_type: FeeType,
silo: Option<AccountId>,
) -> U128;
fn set_deposit_fee_per_silo(&mut self, silo: Option<AccountId>, fee: Option<Fee>);
fn set_withdraw_fee_per_silo(&mut self, silo: Option<AccountId>, fee: Option<Fee>);
fn set_fee_owner(&mut self, owner: Option<AccountId>);
fn claim_fee(&mut self, amount: U128, receiver_id: Option<AccountId>);
olga24912 marked this conversation as resolved.
Show resolved Hide resolved
}

#[ext_contract(ext_withdraw)]
pub trait Withdraw {
#[result_serializer(borsh)]
Expand Down
2 changes: 1 addition & 1 deletion eth-connector/src/connector_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct FinishDepositCallArgs {
}

/// withdraw result for eth-connector
#[derive(BorshSerialize, BorshDeserialize)]
#[derive(BorshSerialize, BorshDeserialize, Debug, PartialEq, Eq)]
pub struct WithdrawResult {
pub amount: Balance,
pub recipient_id: Address,
Expand Down
35 changes: 35 additions & 0 deletions eth-connector/src/fee.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use near_sdk::{
borsh::{self, BorshDeserialize, BorshSerialize},
collections::UnorderedMap,
json_types::U128,
serde::{Deserialize, Serialize},
AccountId,
};

#[derive(Copy, Debug, Serialize, Deserialize, Clone)]
pub enum FeeType {
Deposit,
Withdraw,
}

#[derive(BorshDeserialize, BorshSerialize, Debug, Clone, Serialize, Deserialize, Copy)]
pub struct Fee {
/// Fee percentage in 6 decimal precision (10% -> 0.1 * 10e6 -> 100_000)
pub fee_percentage: u32,
/// The minimum fee amount for transfer
pub lower_bound: Option<U128>,
/// The maximum fee amount for transfer
pub upper_bound: Option<U128>,
}

#[derive(BorshDeserialize, BorshSerialize)]
pub struct FeeStorage {
/// Store the fee for deposit transfers that target silos.
/// The `None` is used to store the default fee.
pub deposit_fee_per_silo: UnorderedMap<Option<AccountId>, Fee>,
/// Store the fee for withdrawal transfers initiated by silos.
/// The `None` is used to store the default fee.
pub withdraw_fee_per_silo: UnorderedMap<Option<AccountId>, Fee>,
/// If set, then fee minted to the `fee_owner` account
pub fee_owner: Option<AccountId>,
}
Loading
Loading