Skip to content

Commit b1d6b31

Browse files
committed
feat: extended aave-data module with flashloan configurations
1 parent 79085d9 commit b1d6b31

File tree

3 files changed

+236
-1
lines changed

3 files changed

+236
-1
lines changed

aave-core/aave-data/sources/v1.move

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ module aave_data::v1 {
5454
oracle_configs_testnet: smart_table::SmartTable<string::String, Option<aave_data::v1_values::CappedAssetData>>,
5555
/// @dev Oracle configuration for mainnet
5656
oracle_configs_mainnet: smart_table::SmartTable<string::String, Option<aave_data::v1_values::CappedAssetData>>,
57+
/// @dev Flashloan premiums to protocol configuration for testnet
58+
flashloan_premium_to_protocol_testnet: smart_table::SmartTable<string::String, u256>,
59+
/// @dev Flashloan premiums to protocol configuration for mainnet
60+
flashloan_premium_to_protocol_mainnet: smart_table::SmartTable<string::String, u256>,
61+
/// @dev Flashloan premium totals for testnet
62+
flashloan_premium_premium_totals_testnet: smart_table::SmartTable<string::String, u256>,
63+
/// @dev Flashloan premium totals for mainnet
64+
flashloan_premium_premium_totals_mainnet: smart_table::SmartTable<string::String, u256>,
5765

5866
/// @dev Pool admins addresses for testnet
5967
pool_admins_testnet: vector<address>,
@@ -136,7 +144,11 @@ module aave_data::v1 {
136144
admin_controlled_ecosystem_reserve_funds_admins_mainnet: aave_data::v1_values::build_admin_controlled_ecosystem_reserve_funds_admins_mainnet(),
137145
rewards_controller_admins_mainnet: aave_data::v1_values::build_rewards_controller_admins_mainnet(),
138146
oracle_configs_testnet: aave_data::v1_values::build_oracle_configs_testnet(),
139-
oracle_configs_mainnet: aave_data::v1_values::build_oracle_configs_mainnet()
147+
oracle_configs_mainnet: aave_data::v1_values::build_oracle_configs_mainnet(),
148+
flashloan_premium_to_protocol_testnet: aave_data::v1_values::build_flashloan_premium_to_protocol_testnet(),
149+
flashloan_premium_to_protocol_mainnet: aave_data::v1_values::build_flashloan_premium_to_protocol_mainnet(),
150+
flashloan_premium_premium_totals_testnet: aave_data::v1_values::build_flashloan_premium_totals_testnet(),
151+
flashloan_premium_premium_totals_mainnet: aave_data::v1_values::build_flashloan_premium_totals_mainnet()
140152
}
141153
);
142154
}
@@ -491,4 +503,82 @@ module aave_data::v1 {
491503
global_data.rewards_controller_admins_mainnet
492504
)
493505
}
506+
507+
/// @notice Gets the flashloan_premium_premium_totals for mainnet in normalized format (keys and values as separate vectors)
508+
/// @return Tuple of (asset symbols, values)
509+
public fun get_flashloan_premium_totals_mainnet_normalized():
510+
(vector<String>, vector<u256>) acquires Data {
511+
let table =
512+
&borrow_global<Data>(@aave_data).flashloan_premium_premium_totals_mainnet;
513+
let keys = smart_table::keys(table);
514+
let views = vector::empty<u256>();
515+
516+
let i = 0;
517+
while (i < vector::length(&keys)) {
518+
let key = *vector::borrow(&keys, i);
519+
let val = *smart_table::borrow(table, key);
520+
vector::push_back(&mut views, val);
521+
i = i + 1;
522+
};
523+
(keys, views)
524+
}
525+
526+
/// @notice Gets the flashloan_premium_premium_totals for testnet in normalized format (keys and values as separate vectors)
527+
/// @return Tuple of (asset symbols, values)
528+
public fun get_flashloan_premium_totals_testnet_normalized():
529+
(vector<String>, vector<u256>) acquires Data {
530+
let table =
531+
&borrow_global<Data>(@aave_data).flashloan_premium_premium_totals_testnet;
532+
let keys = smart_table::keys(table);
533+
let views = vector::empty<u256>();
534+
535+
let i = 0;
536+
while (i < vector::length(&keys)) {
537+
let key = *vector::borrow(&keys, i);
538+
let val = *smart_table::borrow(table, key);
539+
vector::push_back(&mut views, val);
540+
i = i + 1;
541+
};
542+
(keys, views)
543+
}
544+
545+
/// @notice Gets the flashloan_premium_to_protocol for mainnet in normalized format (keys and values as separate vectors)
546+
/// @return Tuple of (asset symbols, values)
547+
public fun get_flashloan_premium_to_protocol_mainnet_normalized(): (
548+
vector<String>, vector<u256>
549+
) acquires Data {
550+
let table =
551+
&borrow_global<Data>(@aave_data).flashloan_premium_to_protocol_mainnet;
552+
let keys = smart_table::keys(table);
553+
let views = vector::empty<u256>();
554+
555+
let i = 0;
556+
while (i < vector::length(&keys)) {
557+
let key = *vector::borrow(&keys, i);
558+
let val = *smart_table::borrow(table, key);
559+
vector::push_back(&mut views, val);
560+
i = i + 1;
561+
};
562+
(keys, views)
563+
}
564+
565+
/// @notice Gets the flashloan_premium_to_protocol for testnet in normalized format (keys and values as separate vectors)
566+
/// @return Tuple of (asset symbols, values)
567+
public fun get_flashloan_premium_to_protocol_testnet_normalized(): (
568+
vector<String>, vector<u256>
569+
) acquires Data {
570+
let table =
571+
&borrow_global<Data>(@aave_data).flashloan_premium_to_protocol_testnet;
572+
let keys = smart_table::keys(table);
573+
let views = vector::empty<u256>();
574+
575+
let i = 0;
576+
while (i < vector::length(&keys)) {
577+
let key = *vector::borrow(&keys, i);
578+
let val = *smart_table::borrow(table, key);
579+
vector::push_back(&mut views, val);
580+
i = i + 1;
581+
};
582+
(keys, views)
583+
}
494584
}

aave-core/aave-data/sources/v1_deployment.move

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,32 @@ module aave_data::v1_deployment {
491491
aave_data::v1::get_reserves_config_testnet_normalized()
492492
};
493493

494+
// Fetch all flashloan premium values based on the specified network
495+
let (_reserve_config_keys, flashloan_premium_totals) =
496+
if (network == utf8(APTOS_MAINNET)) {
497+
aave_data::v1::get_flashloan_premium_totals_mainnet_normalized()
498+
} else if (network == utf8(APTOS_TESTNET)) {
499+
aave_data::v1::get_flashloan_premium_totals_testnet_normalized()
500+
} else {
501+
print(
502+
&format1(&b"Unsupported network - {}. Using testnet values", network)
503+
);
504+
aave_data::v1::get_flashloan_premium_totals_testnet_normalized()
505+
};
506+
507+
// Fetch all flashloan premium to protocol values based on the specified network
508+
let (_reserve_config_keys, flashloan_premiums_to_protocol) =
509+
if (network == utf8(APTOS_MAINNET)) {
510+
aave_data::v1::get_flashloan_premium_to_protocol_mainnet_normalized()
511+
} else if (network == utf8(APTOS_TESTNET)) {
512+
aave_data::v1::get_flashloan_premium_to_protocol_testnet_normalized()
513+
} else {
514+
print(
515+
&format1(&b"Unsupported network - {}. Using testnet values", network)
516+
);
517+
aave_data::v1::get_flashloan_premium_to_protocol_testnet_normalized()
518+
};
519+
494520
// Configure each reserve with its specific parameters
495521
print(&format1(&b"Configuring reserves ... {}", 1));
496522
for (i in 0..vector::length(&underlying_assets_addresses)) {
@@ -501,6 +527,9 @@ module aave_data::v1_deployment {
501527
object::address_to_object<Metadata>(underlying_asset_address);
502528
let underlying_asset_decimals =
503529
fungible_asset::decimals(underlying_asset_metadata);
530+
let flashloan_premium_total = *vector::borrow(&flashloan_premium_totals, i);
531+
let flashloan_premium_to_protocol =
532+
*vector::borrow(&flashloan_premiums_to_protocol, i);
504533

505534
// Extract configuration parameters for this reserve
506535
let reserve_config = vector::borrow(&reserve_configs, i);
@@ -583,6 +612,14 @@ module aave_data::v1_deployment {
583612
);
584613
};
585614

615+
// set flashloan premiums
616+
pool_configurator::update_flashloan_premium_total(
617+
account, flashloan_premium_total as u128
618+
);
619+
pool_configurator::update_flashloan_premium_to_protocol(
620+
account, flashloan_premium_to_protocol as u128
621+
);
622+
586623
// Apply the configuration to the reserve
587624
aave_pool::pool::set_reserve_configuration_with_guard(
588625
account, underlying_asset_address, reserve_config_new

aave-core/aave-data/sources/v1_values.move

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,4 +1143,112 @@ module aave_data::v1_values {
11431143
);
11441144
interest_rate_config
11451145
}
1146+
1147+
/// @notice Build flashloan premium totals for mainnet
1148+
/// @return SmartTable mapping asset symbols to flashloan premium totals
1149+
public fun build_flashloan_premium_totals_mainnet(): SmartTable<string::String, u256> {
1150+
let flashloan_premium_totals = smart_table::new<String, u256>();
1151+
smart_table::upsert(
1152+
&mut flashloan_premium_totals,
1153+
utf8(APT_ASSET),
1154+
(5 * math_utils::get_percentage_factor()) / 10000 // 0.05%
1155+
);
1156+
smart_table::upsert(
1157+
&mut flashloan_premium_totals,
1158+
utf8(USDC_ASSET),
1159+
(5 * math_utils::get_percentage_factor()) / 10000 // 0.05%
1160+
);
1161+
smart_table::upsert(
1162+
&mut flashloan_premium_totals,
1163+
utf8(USDT_ASSET),
1164+
(5 * math_utils::get_percentage_factor()) / 10000 // 0.05%
1165+
);
1166+
smart_table::upsert(
1167+
&mut flashloan_premium_totals,
1168+
utf8(SUSDE_ASSET),
1169+
(5 * math_utils::get_percentage_factor()) / 10000 // 0.05%
1170+
);
1171+
flashloan_premium_totals
1172+
}
1173+
1174+
/// @notice Build flashloan premium totals for testnet
1175+
/// @return SmartTable mapping asset symbols to flashloan premium totals
1176+
public fun build_flashloan_premium_totals_testnet(): SmartTable<string::String, u256> {
1177+
let flashloan_premium_totals = smart_table::new<String, u256>();
1178+
smart_table::upsert(
1179+
&mut flashloan_premium_totals,
1180+
utf8(APT_ASSET),
1181+
(5 * math_utils::get_percentage_factor()) / 10000 // 0.05%
1182+
);
1183+
smart_table::upsert(
1184+
&mut flashloan_premium_totals,
1185+
utf8(USDC_ASSET),
1186+
(5 * math_utils::get_percentage_factor()) / 10000 // 0.05%
1187+
);
1188+
smart_table::upsert(
1189+
&mut flashloan_premium_totals,
1190+
utf8(USDT_ASSET),
1191+
(5 * math_utils::get_percentage_factor()) / 10000 // 0.05%
1192+
);
1193+
smart_table::upsert(
1194+
&mut flashloan_premium_totals,
1195+
utf8(SUSDE_ASSET),
1196+
(5 * math_utils::get_percentage_factor()) / 10000 // 0.05%
1197+
);
1198+
flashloan_premium_totals
1199+
}
1200+
1201+
/// @notice Build flashloan premium to protocol for mainnet
1202+
/// @return SmartTable mapping asset symbols to flashloan premium to protocol
1203+
public fun build_flashloan_premium_to_protocol_mainnet(): SmartTable<string::String, u256> {
1204+
let flashloan_premium_to_protocol = smart_table::new<String, u256>();
1205+
smart_table::upsert(
1206+
&mut flashloan_premium_to_protocol,
1207+
utf8(APT_ASSET),
1208+
0 // 0%
1209+
);
1210+
smart_table::upsert(
1211+
&mut flashloan_premium_to_protocol,
1212+
utf8(USDC_ASSET),
1213+
0 // 0%
1214+
);
1215+
smart_table::upsert(
1216+
&mut flashloan_premium_to_protocol,
1217+
utf8(USDT_ASSET),
1218+
0 // 0%
1219+
);
1220+
smart_table::upsert(
1221+
&mut flashloan_premium_to_protocol,
1222+
utf8(SUSDE_ASSET),
1223+
0 // 0%
1224+
);
1225+
flashloan_premium_to_protocol
1226+
}
1227+
1228+
/// @notice Build flashloan premium to protocol for testnet
1229+
/// @return SmartTable mapping asset symbols to flashloan premium to protocol
1230+
public fun build_flashloan_premium_to_protocol_testnet(): SmartTable<string::String, u256> {
1231+
let flashloan_premium_to_protocol = smart_table::new<String, u256>();
1232+
smart_table::upsert(
1233+
&mut flashloan_premium_to_protocol,
1234+
utf8(APT_ASSET),
1235+
0 // 0%
1236+
);
1237+
smart_table::upsert(
1238+
&mut flashloan_premium_to_protocol,
1239+
utf8(USDC_ASSET),
1240+
0 // 0%
1241+
);
1242+
smart_table::upsert(
1243+
&mut flashloan_premium_to_protocol,
1244+
utf8(USDT_ASSET),
1245+
0 // 0%
1246+
);
1247+
smart_table::upsert(
1248+
&mut flashloan_premium_to_protocol,
1249+
utf8(SUSDE_ASSET),
1250+
0 // 0%
1251+
);
1252+
flashloan_premium_to_protocol
1253+
}
11461254
}

0 commit comments

Comments
 (0)