Skip to content

Commit 571b250

Browse files
committed
feat: added atoken proper transfer functionality
1 parent 8881321 commit 571b250

File tree

3 files changed

+52
-23
lines changed

3 files changed

+52
-23
lines changed

aave-core/sources/aave-tokens/a_token_factory.move

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module aave_pool::a_token_factory {
3232
friend aave_pool::supply_logic;
3333
friend aave_pool::borrow_logic;
3434
friend aave_pool::liquidation_logic;
35+
friend aave_pool::gho_direct_minter;
3536

3637
#[test_only]
3738
friend aave_pool::a_token_factory_tests;
@@ -617,6 +618,21 @@ module aave_pool::a_token_factory {
617618
);
618619
}
619620

621+
/// @notice Transfers out any token from an aToken's resource account to a receiver
622+
/// @param token The address of the token to transfer
623+
/// @param to The address of the recipient
624+
/// @param amount The amount of token to transfer
625+
/// @param metadata_address The address of the aToken
626+
public(friend) fun transfer_atokens(
627+
from: address,
628+
to: address,
629+
amount: u256,
630+
index: u256,
631+
metadata_address: address
632+
) acquires TokenMap {
633+
transfer_on_liquidation(from, to, amount, index, metadata_address);
634+
}
635+
620636
/// @notice Drops the a token associated data
621637
/// @dev Only callable by the pool_token_logic module
622638
/// @param metadata_address The address of the metadata object

aave-core/sources/gho-direct-minter/gho_direct_minter.move

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
module aave_pool::gho_direct_minter {
55
// Std imports
66
use std::signer;
7-
use aptos_framework::dispatchable_fungible_asset;
8-
use aptos_framework::primary_fungible_store;
9-
use aptos_framework::fungible_asset::Metadata;
107
use aptos_framework::object::{
118
Self,
129
ExtendRef as ObjExtendRef,
@@ -126,7 +123,7 @@ module aave_pool::gho_direct_minter {
126123
// check: gho_reserve_entity must have RISK ADMIN ROLE for the pool
127124
is_risk_admin(gho_reserve_entity);
128125

129-
// check: the gho_reserve_entity must be registered as a Facilitator with a non zero bucket capacity
126+
// check: the gho_reserve_entity must be registered as a entity with a non zero limit
130127
let (_, _) = ensure_entity_gho_usage(gho_reserve_entity);
131128

132129
// withdraw GHO underlying asset i.e. burn Atokens and send back the underlying to the primary store of the gho_reserve_entity
@@ -173,21 +170,17 @@ module aave_pool::gho_direct_minter {
173170
if (excess_level == 0) {
174171
return;
175172
};
176-
177-
// transfer the excess to the treasury
178-
let a_token_metadata = object::address_to_object<Metadata>(a_token_address);
179-
let store_from =
180-
primary_fungible_store::primary_store(gho_reserve_entity, a_token_metadata);
181-
let store_to =
182-
primary_fungible_store::ensure_primary_store_exists(
183-
gho_direct_minter_data.collector_address, a_token_metadata
184-
);
185-
186-
dispatchable_fungible_asset::transfer(
187-
&minter_signer,
188-
store_from,
189-
store_to,
190-
(excess_level as u64)
173+
// get the underlying asset index
174+
let underlying_asset =
175+
a_token_factory::get_underlying_asset_address(a_token_address);
176+
let index = pool::get_reserve_normalized_income(underlying_asset);
177+
// Transfer the excess level of atokens from the gho_reserve_entity to the collector address
178+
a_token_factory::transfer_atokens(
179+
gho_reserve_entity,
180+
gho_direct_minter_data.collector_address,
181+
excess_level,
182+
index,
183+
a_token_address
191184
);
192185
}
193186

aave-core/tests/gho-direct-minter/gho_direct_minter.move renamed to aave-core/tests/gho-direct-minter/gho_direct_minter_tests.move

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ module aave_pool::gho_direct_minter_tests {
277277
)
278278
]
279279
#[expected_failure(abort_code = 105, location = aave_pool::gho_direct_minter)]
280-
fun test_direct_minter_supply_0_bucket_capacity(
280+
fun test_direct_minter_supply_0_entity_limit(
281281
aave_pool: &signer,
282282
aave_acl: &signer,
283283
aave_std: &signer,
@@ -443,12 +443,12 @@ module aave_pool::gho_direct_minter_tests {
443443
let emitted_supply_events = emitted_events<supply_logic::Supply>();
444444
assert!(vector::length(&emitted_supply_events) == 1, TEST_SUCCESS);
445445

446-
// Check the atoken balance of the facilitator after minting
446+
// Check the atoken balance of the entity after minting
447447
let gho_reserve_entity_atoken_balance_after =
448448
a_token_factory::balance_of(gho_reserve_entity, atoken_address);
449449
assert!(gho_reserve_entity_atoken_balance_after == supply_amount, TEST_SUCCESS);
450450

451-
// Check the gho balance of the facilitator after the supply (should be zero)
451+
// Check the gho balance of the entity after the supply (should be zero)
452452
let gho_balance_after_supply = gho_token::get_balance(gho_reserve_entity);
453453
assert!(gho_balance_after_supply == 0, TEST_SUCCESS);
454454

@@ -642,7 +642,27 @@ module aave_pool::gho_direct_minter_tests {
642642
TEST_SUCCESS
643643
);
644644

645+
// Check the atoken balance of the collector before the transfer is exactly zero
646+
let a_token_collector_balance_before =
647+
a_token_factory::balance_of(
648+
gho_direct_minter::get_collector_address(), atoken_address
649+
);
650+
assert!(
651+
a_token_collector_balance_before == 0,
652+
TEST_SUCCESS
653+
);
654+
645655
// Transfer the excess to the treasury
646-
// gho_direct_minter::transfer_excess_to_treasury(); // FIXME: the atoken stores are frozen
656+
gho_direct_minter::transfer_excess_to_treasury();
657+
658+
// Check the atoken balance of the collector after the transfer is greater than zero
659+
let a_token_collector_balance_after =
660+
a_token_factory::balance_of(
661+
gho_direct_minter::get_collector_address(), atoken_address
662+
);
663+
assert!(
664+
a_token_collector_balance_after > 0,
665+
TEST_SUCCESS
666+
);
647667
}
648668
}

0 commit comments

Comments
 (0)