White Whale releases details on Flash lending architecture

Let’s break it down. Simply put, a flash loan is, as the name suggests, a loan that is opened and closed within a very short period of time. More precisely, it is opened and closed in the same transaction. Flash loans are used to execute atomic transactions that take advantage of market inefficiencies or provide other functionality to the borrower. Atomic transactions are transactions that can be completed in a single transaction and almost all chain arbitrations fall into this category. You now, hopefully, realize how powerful this financial instrument can be. But with that power comes responsibility.
While White Whale would be the first to deploy flash loans on Terra (and all of Cosmos!), A number of protocols already offer it on Ethereum. The sometimes bad connotation associated with flash loans is caused by a number of exploits that have occurred on Ethereum in which hackers have used this tool to perform so-called reentry attacks. Fortunately, CosmWasm (Terra’s smart contract language) is designed to prevent this type of attack. Comparing CosmWasm to Ethereum’s smart contract language, the developers state:
“A big difference is that we avoid all reentry attacks by design. This point deserves an article on its own, but in short, a great class of exploits in Ethereum are based on this tip.
And,
“Cosmwasm avoids this entirely by preventing any contract from calling another directly.”
These precautions allow White Whale to provide this service without having to worry too much about other protocols being exploited.
To really understand how it all works, let’s briefly take a look at and unbox White Whale’s flagship vault. UST Safe allows users to deposit USTs into the safe in a simple one-step process. The total liquidity in the UST Vault then acts as a general purpose liquidity pool with a series of internal arbitrage strategies. The first is to keep the ankle. Other strategies are also in the works, such as exploiting price inefficiencies across multiple exchanges, as well as automated liquidations on Mars and Levana. All of these strategies make the ecosystem more stable and efficient, and they all use the liquidity of the UST Vault.
These strategies take us back to flash loans: when one of our bots detects a profitable arbitrage opportunity, the smart contract related to that strategy will request a flash loan from the UST vault. The UST Vault will then remove the UST from the Anchor Protocol (where it earns a comfortable 19.5% when idle) and provide the contract with borrowed money to perform the arbitration. After arbitration, all funds are returned to the safe. This is how we plan to deliver Anchor + returns.
One question that has been raised is: what if the trade is not making a profit? Or what if the borrower just doesn’t pay back the loan? Various mechanisms have been put in place to ensure that depositors do not become injured. First, when a flash loan is requested, White Whale records the total value of the safe. Then the funds are sent to the borrower (i.e. the arb bot) to complete the transaction. What has been added is a reminder at the end of the program which cannot be changed and whose execution is guaranteed.
Once the borrower has executed the transaction, this reminder is executed. The recall is basically the second step. It recalculates the value of the safe and compares it to the initial value before the loan. If this amount is less than the initial amount, it generates an ERROR and cancels the entire transaction, i.e. the flash loan. The transaction then fails and it is as if nothing had happened. In effect, this means that the flash loan will only execute if it pre-determines a profitable outcome, otherwise it will cancel itself out.
In the long term, there will be a whitelist process allowing the community to create bots to integrate through chain governance and use the White Whale flash lending architecture. The community will be able to decide which bots will benefit and secure the ecosystem and vote to add them to the whitelist. There will of course be a small commission (the cost of borrowing the loan) which will be automatically distributed to depositors.
In order to ensure the security of this complex and innovative architecture, White Whale has already scheduled several audits with some of the most respected auditors in the industry. The foundation has already been built, and now the focus is on putting the tools in the hands of our community, empowering them to protect the ankle and stabilize the ecosystem.