/flashloans

Primary LanguageRustMIT LicenseMIT

Flash loans

Built with ink!

Development

Follow the Aleph Zero guide to install rust and ink!. Note, that:

  • probably you'll have to run cargo install dylint-link during the installation, when prompted so,
  • You can now safely execute cargo install cargo-contract to install cargo-contract, instead of installing a specific snapshot as noted in the tutorial.

When adding new contract/library, make sure the ink! version used in Cargo.toml is 3.3.

Unit testing

There are only a few unit tests, because cross-contract unit testing is not available at the current version of ink!, and PSP22 token transfers calls by standard specification _before_transaction method on receiver.

To run these tests, type make test in console.

Deployment to Aleph Zero Testnet:

  1. make all or make all RELEASE_FLAGS="--optimization-passes=0".
  2. Open online blockchain frontend and login to your account.
  3. Make sure you have enough SZERO tokens (or get them on https://faucet-smartnet.test.azero.dev/).
  4. Upload & deploy these contracts: contracts/example_borrower and contracts/psp22_token_a. For contracts/default_provider set fee_per_1M_tokens to, for example, 900 (correcponding to 0.09% fee).

Manual tests on chain

  1. Mint some (e.g 1'000'000) "PSP22 token A" tokens to provider, and some less to borrower (e.g 10).
  2. Execute provide_flashloan method on contracts/default_provider, setting receiver to exaple_borrower, token to PSP22 token A and amount to some integer.
  3. Transaction should be successfull and balances of both accounts should be equal to previous state +- flash loan fee.