Skip to content

Commit 96bf9ba

Browse files
committed
feat: Added aave-scripts with commands and flashloan calls
1 parent 64c9c1d commit 96bf9ba

File tree

5 files changed

+420
-0
lines changed

5 files changed

+420
-0
lines changed

Makefile

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,78 @@ configure-price-feeds:
806806
--function-id '0x${AAVE_DATA_ADDRESS}::v1_deployment::configure_price_feeds' \
807807
--args string:$(APTOS_NETWORK)
808808

809+
810+
# ===================== AAVE-SCRIPTS ===================== #
811+
812+
compile-scripts-testnet:
813+
cd aave-core && aptos move compile \
814+
--included-artifacts none \
815+
--save-metadata \
816+
--package-dir "aave-scripts" \
817+
--skip-fetch-latest-git-deps \
818+
--language-version "$(MOVE_VERSION)" \
819+
--compiler-version "$(COMPILER_VERSION)" \
820+
--named-addresses "aave_acl=0xb23539ad6490a465e92e751943a3eaedf4b48d7d844ff59adf2ae66bcb09f53d,aave_config=0x4fb5d8348c8873295f97136bbe1c43d976fb18a4a966a85e21d16958eaecef99,aave_math=0xf6f896cefd7b1b1e85ff56033981cf92dcd5d6e93b1349a7ab5003761c52498d,aave_oracle=0xcb9eb79a52f41933192c2e1e37a9e72bfd726fdb9a687cd6cfe45527e52f4e41,aave_pool=0xbd7912c555a06809c2e385eab635ff0ef52b1fa062ce865c785c67694a12bb12,aave_large_packages=0x0e1ca3011bdd07246d4d16d909dbb2d6953a86c4735d5acf5865d962c630cce7,aave_mock_underlyings=0xe2b42cab2f84bf57edaf87bcaffee409c2b3d5243e3def00d9d2f7dec568d867,aave_data=0xb0ec364235f47ad2a8eb52d639c80579b11497d0711879840f1ce51c885b165f,data_feeds=0xf1099f135ddddad1c065203431be328a408b0ca452ada70374ce26bd2b32fdd3,platform=0x516e771e1b4a903afe74c27d057c65849ecc1383782f6642d7ff21425f4f9c99,aave_oracle_racc_address=0x3836084d178459c08f27620462d531f5b5b23d14ddbf4f47c4a72d404d87bcb4"
821+
822+
compile-scripts-mainnet:
823+
cd aave-core && aptos move compile \
824+
--included-artifacts none \
825+
--save-metadata \
826+
--package-dir "aave-scripts" \
827+
--skip-fetch-latest-git-deps \
828+
--language-version "$(MOVE_VERSION)" \
829+
--compiler-version "$(COMPILER_VERSION)" \
830+
--named-addresses "aave_acl=0x34c3e6af238f3a7fa3f3b0088cbc4b194d21f62e65a15b79ae91364de5a81a3a,aave_config=0x531069f4741cdead39d70b76e5779863864654fae6db8a752a244ff2f9916c15,aave_math=0xc0338eea778de2a5348824ddbfcec033c7f7cbe18da6da40869562906b63c78c,aave_oracle=0x249676f3faddb83d64fd101baa3f84a171ae02505d796e3edbf4861038a4b5cc,aave_pool=0x39ddcd9e1a39fa14f25e3f9ec8a86074d05cc0881cbf667df8a6ee70942016fb,aave_large_packages=0x0e1ca3011bdd07246d4d16d909dbb2d6953a86c4735d5acf5865d962c630cce7,aave_mock_underlyings=0x12b05c42ac3209a3c6ffadff4ebb6c3e983e5115f26031d56652815b49a14245,aave_data=0x5eb5cc775c5a446db0f3a1c944e11563b97e6a7e1387b9fb459aa26168f738dc,data_feeds=0x3f985798ce4975f430ef5c75776ff98a77b9f9d0fb38184d225adc9c1cc6b79b,platform=0x9976bb288ed9177b542d568fa1ac386819dc99141630e582315804840f41928a,aave_oracle_racc_address=0x3836084d178459c08f27620462d531f5b5b23d14ddbf4f47c4a72d404d87bcb4"
831+
832+
execute-flashloan-simple-dry-run:
833+
aptos move run-script \
834+
--local \
835+
--assume-yes \
836+
--compiled-script-path aave-core/aave-scripts/build/AaveScripts/bytecode_scripts/flashloan_simple.mv \
837+
--language-version "$(MOVE_VERSION)" \
838+
--compiler-version "$(COMPILER_VERSION)" \
839+
--sender-account "$(FLASHLOANER)" \
840+
--profile "$(FLASHLOANER)" \
841+
--args address:$(FLASHLOAN_ASSET) u256:$(FLASHLOAN_AMOUNT)
842+
843+
execute-flashloan-complex-dry-run:
844+
aptos move run-script \
845+
--local \
846+
--assume-yes \
847+
--compiled-script-path aave-core/aave-scripts/build/AaveScripts/bytecode_scripts/flashloan_complex.mv \
848+
--language-version "$(MOVE_VERSION)" \
849+
--compiler-version "$(COMPILER_VERSION)" \
850+
--sender-account "$(FLASHLOANER)" \
851+
--profile "$(FLASHLOANER)" \
852+
--args address:$(FLASHLOAN_ASSET) u256:$(FLASHLOAN_AMOUNT)
853+
854+
execute-flashloan-simple:
855+
aptos move run-script \
856+
--assume-yes \
857+
--compiled-script-path aave-core/aave-scripts/build/AaveScripts/bytecode_scripts/flashloan_simple.mv \
858+
--language-version "$(MOVE_VERSION)" \
859+
--compiler-version "$(COMPILER_VERSION)" \
860+
--sender-account "$(FLASHLOANER)" \
861+
--profile "$(FLASHLOANER)" \
862+
--args address:$(FLASHLOAN_ASSET) u256:$(FLASHLOAN_AMOUNT)
863+
864+
execute-flashloan-complex:
865+
aptos move run-script \
866+
--assume-yes \
867+
--compiled-script-path aave-core/aave-scripts/build/AaveScripts/bytecode_scripts/flashloan_complex.mv \
868+
--language-version "$(MOVE_VERSION)" \
869+
--compiler-version "$(COMPILER_VERSION)" \
870+
--sender-account "$(FLASHLOANER)" \
871+
--profile "$(FLASHLOANER)" \
872+
--args address:$(FLASHLOAN_ASSET) u256:$(FLASHLOAN_AMOUNT)
873+
874+
fmt-scripts:
875+
aptos move fmt \
876+
--package-path "aave-core/aave-scripts" \
877+
--config-path ./movefmt.toml \
878+
--emit-mode "overwrite" \
879+
-v
880+
809881
# ===================== GLOBAL COMMANDS ===================== #
810882

811883
ifeq ($(APTOS_NETWORK), local)
@@ -828,6 +900,8 @@ compile-all:
828900
make compile-mock-underlyings
829901
make compile-pool
830902
make compile-data
903+
make compile-scripts-testnet
904+
make compile-scripts-mainnet
831905

832906
publish-all:
833907
make publish-config
@@ -873,6 +947,7 @@ clean-all:
873947
make clean-mock-underlyings
874948
make clean-core
875949
make clean-data
950+
make clean-scripts
876951

877952
# ------------------------------------------------------------
878953
# Coverage
@@ -901,6 +976,7 @@ fmt-move:
901976
make fmt-pool
902977
make fmt-mock-underlyings
903978
make fmt-data
979+
make fmt-scripts
904980

905981
fmt-prettier:
906982
pnpm prettier:fix

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,38 @@ The docs are auto-generated from each package and published using [MkDocs Materi
241241
Browse all modules, structs, functions, and events used across Aave's V3 Aptos packages.
242242

243243
---
244+
245+
## 📜 Running Scripts
246+
247+
In addition to Move unit tests and integration tests, this repository contains **example scripts** (such as flashloans) that demonstrate how to interact with the deployed protocol on Aptos.
248+
249+
### 🛠️ Compile Scripts
250+
251+
Scripts are compiled separately from the core packages:
252+
253+
```bash
254+
# For testnet deployments
255+
make compile-scripts-testnet
256+
257+
# For mainnet deployments
258+
make compile-scripts-mainnet
259+
```
260+
261+
### 🚀 Execute Example Scripts
262+
263+
Once compiled, scripts can be executed against the target network. For example:
264+
265+
```bash
266+
# Simple flashloan example
267+
make execute-flashloan-simple
268+
269+
# Complex flashloan example
270+
make execute-flashloan-complex
271+
```
272+
273+
Each script corresponds to a .mv compiled Move script under `aave-scripts/build/AaveScripts/bytecode_scripts/`.
274+
They are executed via aptos move run-script, with arguments such as asset addresses and flashloan amounts passed in from the Makefile.
275+
276+
🔍 These scripts are primarily intended as examples and tests of protocol functionality, such as taking and repaying flashloans.
277+
278+
---

aave-core/aave-scripts/Move.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
name = "AaveScripts"
3+
version = "1.0.0"
4+
upgrade_policy = "compatible"
5+
authors = []
6+
7+
[addresses]
8+
9+
[dev-addresses]
10+
11+
[dependencies]
12+
AptosStdlib = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-stdlib", rev = "mainnet" }
13+
AptosFramework = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-framework/", rev = "mainnet" }
14+
AptosToken = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-token", rev = "mainnet" }
15+
AptosTokenObjects = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-token-objects", rev = "mainnet" }
16+
AaveAcl = { local = "../aave-acl" }
17+
AaveConfig = { local = "../aave-config" }
18+
AaveOracle = { local = "../aave-oracle" }
19+
AaveData = { local = "../aave-data" }
20+
AavePool = { local = "../" }
21+
22+
[dev-dependencies]
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
// @title Complex Flashloans Test Script
2+
// @author Aave
3+
// @notice Script to test complex flashloans functionality in the Aave protocol
4+
script {
5+
// imports
6+
// std
7+
use std::signer;
8+
use std::vector;
9+
use aptos_std::debug::print;
10+
use aptos_std::string_utils::format1;
11+
use aave_pool::fungible_asset_manager::Self;
12+
// locals
13+
use aave_pool::flashloan_logic::Self;
14+
15+
// Constants
16+
// @notice Success code for successful execution
17+
const SUCCESS: u64 = 1;
18+
19+
// @notice Failure code for failed execution
20+
const FAILURE: u64 = 2;
21+
22+
/// @notice Test script for executing a complex flashloan
23+
/// @param borrower The signer account executing the script (must be the borrower)
24+
/// @param asset The address of the asset to be borrowed in the flashloan
25+
/// @param amount The amount of the asset to be borrowed in the flashloan
26+
fun flashloan_complex(
27+
borrower: &signer, asset: address, amount: u256
28+
) {
29+
30+
let flashloan_borrower_address = signer::address_of(borrower);
31+
let flashloan_asset = asset;
32+
let flashloan_amount = amount;
33+
34+
// check the balance of the borrower before the flashloan is taken
35+
let flashloaner_initial_balance =
36+
fungible_asset_manager::balance_of(
37+
flashloan_borrower_address, flashloan_asset
38+
);
39+
print(&format1(&b"Flashloaner initial balance: {}", flashloaner_initial_balance));
40+
41+
// user prepares to take a flashloan
42+
let flashloan_receipts =
43+
flashloan_logic::flash_loan(
44+
borrower,
45+
flashloan_borrower_address,
46+
vector[flashloan_asset],
47+
vector[flashloan_amount],
48+
vector[2],
49+
flashloan_borrower_address,
50+
0 // no referral code
51+
);
52+
53+
// assert that the flashloan receipts is not empty and it has only 1 item
54+
assert!(vector::length(&flashloan_receipts) == 1, SUCCESS);
55+
56+
let first_flashloan_receipt = vector::borrow(&flashloan_receipts, 0);
57+
58+
// check the balance of the borrower after the flashloan
59+
let flashloaner_postloan_balance =
60+
fungible_asset_manager::balance_of(
61+
flashloan_borrower_address, flashloan_asset
62+
);
63+
print(
64+
&format1(&b"Flashloaner post-loan balance: {}", flashloaner_postloan_balance)
65+
);
66+
67+
assert!(
68+
(flashloaner_postloan_balance as u256)
69+
== (flashloaner_initial_balance as u256) + flashloan_amount,
70+
SUCCESS
71+
);
72+
73+
// do assertion to check if the flashloan was successful
74+
assert!(
75+
flashloan_logic::get_complex_flashloan_current_amount(first_flashloan_receipt) ==
76+
flashloan_amount,
77+
SUCCESS
78+
);
79+
assert!(
80+
flashloan_logic::get_complex_flashloan_current_asset(first_flashloan_receipt) ==
81+
flashloan_asset,
82+
SUCCESS
83+
);
84+
assert!(
85+
flashloan_logic::get_complex_flashloan_on_behalf_of(first_flashloan_receipt)
86+
== flashloan_borrower_address,
87+
SUCCESS
88+
);
89+
assert!(
90+
flashloan_logic::get_complex_flashloan_receipt_index(first_flashloan_receipt) ==
91+
0,
92+
SUCCESS
93+
);
94+
assert!(
95+
flashloan_logic::get_complex_flashloan_receipt_receiver(
96+
first_flashloan_receipt
97+
) == flashloan_borrower_address,
98+
SUCCESS
99+
);
100+
assert!(
101+
flashloan_logic::get_complex_flashloan_referral_code(first_flashloan_receipt) ==
102+
0,
103+
SUCCESS
104+
);
105+
assert!(
106+
flashloan_logic::get_complex_flashloan_receipt_sender(first_flashloan_receipt) ==
107+
flashloan_borrower_address,
108+
SUCCESS
109+
);
110+
111+
print(
112+
&format1(
113+
&b"flashloan_premium_total: {}",
114+
flashloan_logic::get_complex_flashloan_premium_total(
115+
first_flashloan_receipt
116+
)
117+
)
118+
);
119+
print(
120+
&format1(
121+
&b"flashloan_premium_to_protocol: {}",
122+
flashloan_logic::get_complex_flashloan_premium_to_protocol(
123+
first_flashloan_receipt
124+
)
125+
)
126+
);
127+
print(
128+
&format1(
129+
&b"flashloan_total_premium: {}",
130+
flashloan_logic::get_complex_flashloan_total_premium(
131+
first_flashloan_receipt
132+
)
133+
)
134+
);
135+
136+
// pay back the flashloans
137+
flashloan_logic::pay_flash_loan_complex(borrower, flashloan_receipts);
138+
139+
// check the balance of the borrower after the flashloans have been paid back
140+
let flashloaner_postrepay_balance =
141+
fungible_asset_manager::balance_of(
142+
flashloan_borrower_address, flashloan_asset
143+
);
144+
print(
145+
&format1(
146+
&b"Flashloaner post-repay balance: {}", flashloaner_postrepay_balance
147+
)
148+
);
149+
}
150+
}

0 commit comments

Comments
 (0)