Skip to Content
ExamplesP2P Flashloan

Peer-to-Peer Flashloan

A P2P flashloan allows third parties to draw temporary liquidity from other accounts. For users, this means any token they hold can become a source of yield.

This workflows defines a simple p2p flashloan. The lender transfers their token balance to a loan taker, allows subsequent workflows to execute, and finally checks that their balance is restored. If the loan is not repaid, the transaction reverts.

# Flashloan script: Lends tokens to a participant and ensures repayment within the same tx contracts: weth: abi: std/erc20 address: 0x... constants: my_balance_before: !Uint # Balance before the loan my_balance_after: !Uint # Balance after the loan variables: loan_taker: !Address # Address of the loan recipient workflow: # Load the next participant (loan taker) - loan_taker: vm.load(vm.pid++, this.account) - my_balance_before: weth.balanceOf(this.account) - erc20.transfer(loan_taker, my_balance_before) # Temporarily pause and pass control to the next script - vm.continue() - my_balance_after: weth.balanceOf(this.account) - require(my_balance_after >= my_balance_before)

Note:
A subsequent signed intent can use the tokens, but must ensure sufficient tokens are returned.

Last updated on