Skip to content

Instantly share code, notes, and snippets.

@extropyCoder
Created August 14, 2024 08:39
Show Gist options
  • Select an option

  • Save extropyCoder/2bcf09197003311c405ce09d1a5a7b10 to your computer and use it in GitHub Desktop.

Select an option

Save extropyCoder/2bcf09197003311c405ce09d1a5a7b10 to your computer and use it in GitHub Desktop.
Fixed Code
module 0x42::example {
struct Coin<T> {
amount: u64
}
struct Receipt<phantom T> {
amount: u64
}
public fun flash_loan<T>(_user: &signer, amount:u64): (Coin<T>, Receipt<T>) {
let (coin, fee) = withdraw(user, amount);
(coin,Receipt { amount: amount + fee})
}
public fun repay_flash_loan<T>(rec: Receipt<T>, coins: Coin<T>) {
let Receipt{ amount } = rec;
assert!(coin::value<T>(&coin) >= rec.amount, 0);
deposit(coin);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment