flashloan-rs 0.2.0

Minimal Multicall3 Flashloan Module
Documentation
/// @title Owned
/// @notice SPDX-License-Identifier: MIT
/// @author asnared <https://github.com/abigger87>
/// @notice An single owner authorization module
/// @notice Adapted from <https://github.com/transmissions11/solmate/blob/main/src/auth/Owned.sol>

// Interface
#define function setOwner(address) nonpayable returns ()
#define function owner() view returns (address)

// Events
#define event OwnerUpdated(address indexed user, address indexed newOwner)

// Storage Slots
#define constant OWNER = FREE_STORAGE_POINTER()

// CONSTRUCTOR
#define macro OWNED_CONSTRUCTOR() = takes (0) returns (0) {
  // Copy the owner into memory
  0x20                        // [size] - byte size to copy
  0x20 codesize sub           // [offset, size] - offset in the code to copy from
  0x00                        // [mem, offset, size] - offset in memory to copy to
  codecopy                    // []

  // Set the new owner
  0x00 mload                  // [owner]
  dup1                        // [owner, owner]
  [OWNER]                     // [OWNER, owner, owner]
  sstore                      // [owner]

  // Emit the owner updated event
  caller                      // [from, owner]
  __EVENT_HASH(OwnerUpdated)  // [sig, from, owner]
  0x00 0x00                   // [0, 0, sig, from, owner]
  log3                        // []
}

/// @notice Only Owner Modifier
#define macro IS_OWNER() = takes (0) returns (0) {
  caller                      // [msg.sender]
  [OWNER] sload               // [owner, msg.sender]
  eq authed jumpi             // [authed]

  // Revert otherwise
  0x00 0x00 revert

  authed:
}

/// @notice Set the Owner
/// @param {owner} [address] - The new owner
#define macro SET_OWNER() = takes (0) returns (0) {
  // Check that the caller is authorized
  IS_OWNER()

  // Set the new owner
  0x04 calldataload           // [newOwner]
  dup1                        // [newOwner, newOwner]
  [OWNER] sstore              // [newOwner]

  // Emit the owner updated event
  caller                      // [from, newOwner]
  __EVENT_HASH(OwnerUpdated)  // [sig, from, newOwner]
  0x00 0x00                   // [0, 32, sig, from, newOwner]
  log3                        // []

  stop
}

/// @notice Get the owner of the contract
/// @return {owner} [address] - The owner of the contract
#define macro OWNER() = takes (0) returns (0) {
  [OWNER] sload                  // [owner]
  0x00 mstore                    // []
  0x20 0x00 return
}

/// @notice Main Function Dispatcher
#define macro OWNED_MAIN() = takes (1) returns (1) {
  // Input Stack: [function_selector]

  dup1 __FUNC_SIG(setOwner) eq set_owner jumpi
  dup1 __FUNC_SIG(owner)    eq owner jumpi

  // Bubble up to parent macro
  no_match jump

  set_owner:
      SET_OWNER()
  owner:
      OWNER()

  no_match:
}