Skip to content
Open
Show file tree
Hide file tree
Changes from all 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: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
target
.snfoundry_cache
.env
.env
my_scripts
scripts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2025 Starknet Vault Kit
// Licensed under the MIT License. See LICENSE file for details.

#[starknet::contract]
pub mod AumProvider4626 {
use core::num::traits::Zero;
use openzeppelin::interfaces::erc20::{ERC20ABIDispatcher, ERC20ABIDispatcherTrait};
use openzeppelin::interfaces::erc4626::{IERC4626Dispatcher, IERC4626DispatcherTrait};
use starknet::ContractAddress;
use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess};
use vault::aum_provider::aum_provider_4626::errors::Errors;
use vault::aum_provider::aum_provider_4626::interface::IAumProvider4626;
use vault::aum_provider::base_aum_provider::BaseAumProviderComponent;
use vault::vault::interface::IVaultDispatcherTrait;
component!(
path: BaseAumProviderComponent, storage: base_aum_provider, event: BaseAumProviderEvent,
);

#[abi(embed_v0)]
impl BaseAumProviderImpl =
BaseAumProviderComponent::BaseAumProviderImpl<ContractState>;
impl BaseAumProviderInternalImpl = BaseAumProviderComponent::InternalImpl<ContractState>;

#[storage]
struct Storage {
#[substorage(v0)]
base_aum_provider: BaseAumProviderComponent::Storage,
strategy4626: IERC4626Dispatcher,
}

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
BaseAumProviderEvent: BaseAumProviderComponent::Event,
}

#[abi(embed_v0)]
impl AumProvider4626Impl of IAumProvider4626<ContractState> {
fn get_strategy_4626(self: @ContractState) -> ContractAddress {
self.strategy4626.read().contract_address
}
}

#[constructor]
fn constructor(ref self: ContractState, vault: ContractAddress, strategy4626: ContractAddress) {
self.base_aum_provider.initializer(vault);
if (strategy4626.is_zero()) {
Errors::invalid_strategy4626_address();
}

self.strategy4626.write(IERC4626Dispatcher { contract_address: strategy4626 });
}

// --- AUM Trait Implementation ---
impl AumTrait of BaseAumProviderComponent::AumTrait<ContractState> {
fn get_aum(self: @BaseAumProviderComponent::ComponentState<ContractState>) -> u256 {
let contract_state = self.get_contract();
let strategy = contract_state.strategy4626.read();
let vault_allocator_address = contract_state
.base_aum_provider
.vault
.read()
.vault_allocator();

// .vault.vault_allocator();
let underlying_asset = strategy.asset();
let underlying_dispatcher = ERC20ABIDispatcher { contract_address: underlying_asset };
let underlying_balance = underlying_dispatcher.balance_of(vault_allocator_address);
let strategy_shares = ERC20ABIDispatcher { contract_address: strategy.contract_address }
.balance_of(vault_allocator_address);
let strategy_assets = if strategy_shares > 0 {
strategy.convert_to_assets(strategy_shares)
} else {
0
};

underlying_balance + strategy_assets
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2025 Starknet Vault Kit
// Licensed under the MIT License. See LICENSE file for details.

pub mod Errors {
pub fn invalid_strategy4626_address() {
panic!("Invalid strategy4626 address");
}
}
10 changes: 10 additions & 0 deletions packages/vault/src/aum_provider/aum_provider_4626/interface.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2025 Starknet Vault Kit
// Licensed under the MIT License. See LICENSE file for details.

use starknet::ContractAddress;

#[starknet::interface]
pub trait IAumProvider4626<TContractState> {
fn get_strategy_4626(self: @TContractState) -> ContractAddress;
}
52 changes: 52 additions & 0 deletions packages/vault/src/aum_provider/base_aum_provider.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2025 Starknet Vault Kit
// Licensed under the MIT License. See LICENSE file for details.

#[starknet::component]
pub mod BaseAumProviderComponent {
use core::num::traits::Zero;
use starknet::ContractAddress;
use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess};
use vault::aum_provider::errors::Errors;
use vault::aum_provider::interface::IBaseAumProvider;
use vault::vault::interface::{IVaultDispatcher, IVaultDispatcherTrait};
#[storage]
pub struct Storage {
pub vault: IVaultDispatcher,
}

#[event]
#[derive(Drop, Debug, PartialEq, starknet::Event)]
pub enum Event {}


pub trait AumTrait<TContractState, +HasComponent<TContractState>> {
fn get_aum(self: @ComponentState<TContractState>) -> u256;
}


#[embeddable_as(BaseAumProviderImpl)]
impl BaseAumProvider<
TContractState, +HasComponent<TContractState>, impl Aum: AumTrait<TContractState>,
> of IBaseAumProvider<ComponentState<TContractState>> {
fn aum(self: @ComponentState<TContractState>) -> u256 {
Aum::get_aum(self)
}

fn report(ref self: ComponentState<TContractState>) {
self.vault.read().report(Aum::get_aum(@self));
}
}

#[generate_trait]
pub impl InternalImpl<
TContractState, +HasComponent<TContractState>,
> of InternalTrait<TContractState> {
fn initializer(ref self: ComponentState<TContractState>, vault: ContractAddress) {
if (vault.is_zero()) {
Errors::invalid_vault_address();
}
self.vault.write(IVaultDispatcher { contract_address: vault });
}
}
}
9 changes: 9 additions & 0 deletions packages/vault/src/aum_provider/errors.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2025 Starknet Vault Kit
// Licensed under the MIT License. See LICENSE file for details.

pub mod Errors {
pub fn invalid_vault_address() {
panic!("Invalid vault address");
}
}
9 changes: 9 additions & 0 deletions packages/vault/src/aum_provider/interface.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2025 Starknet Vault Kit
// Licensed under the MIT License. See LICENSE file for details.

#[starknet::interface]
pub trait IBaseAumProvider<T> {
fn aum(self: @T) -> u256;
fn report(ref self: T);
}
11 changes: 11 additions & 0 deletions packages/vault/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ pub mod vault {
pub mod vault;
}

pub mod aum_provider {
pub mod base_aum_provider;
pub mod errors;
pub mod interface;
pub mod aum_provider_4626 {
pub mod aum_provider_4626;
pub mod errors;
pub mod interface;
}
}


pub mod redeem_request {
pub mod errors;
Expand Down
11 changes: 11 additions & 0 deletions packages/vault/src/redeem_request/redeem_request.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod RedeemRequest {
};
use openzeppelin::interfaces::upgrades::IUpgradeable;
use openzeppelin::introspection::src5::SRC5Component;
use openzeppelin::token::erc721::extensions::ERC721EnumerableComponent;
use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl};
use openzeppelin::upgrades::upgradeable::UpgradeableComponent;
use starknet::storage::{
Expand All @@ -22,10 +23,16 @@ mod RedeemRequest {

component!(path: SRC5Component, storage: src5, event: SRC5Event);
component!(path: ERC721Component, storage: erc721, event: ERC721Event);
component!(
path: ERC721EnumerableComponent, storage: erc721_enumerable, event: ERC721EnumerableEvent,
);
component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);

#[abi(embed_v0)]
impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl<ContractState>;
#[abi(embed_v0)]
impl ERC721EnumerableImpl =
ERC721EnumerableComponent::ERC721EnumerableImpl<ContractState>;
impl ERC721InternalImpl = ERC721Component::InternalImpl<ContractState>;
impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl<ContractState>;

Expand All @@ -37,6 +44,8 @@ mod RedeemRequest {
#[substorage(v0)]
erc721: ERC721Component::Storage,
#[substorage(v0)]
erc721_enumerable: ERC721EnumerableComponent::Storage,
#[substorage(v0)]
upgradeable: UpgradeableComponent::Storage,
id_len: u256,
id_to_info: Map<u256, RedeemRequestInfo>,
Expand All @@ -49,6 +58,8 @@ mod RedeemRequest {
#[flat]
ERC721Event: ERC721Component::Event,
#[flat]
ERC721EnumerableEvent: ERC721EnumerableComponent::Event,
#[flat]
SRC5Event: SRC5Component::Event,
#[flat]
UpgradeableEvent: UpgradeableComponent::Event,
Expand Down
Loading