-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a15e3cc
commit aff8b4a
Showing
17 changed files
with
492 additions
and
488 deletions.
There are no files selected for viewing
Submodule rain.math.float
updated
27 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,68 @@ | ||
// SPDX-License-Identifier: CAL | ||
pragma solidity ^0.8.18; | ||
// // SPDX-License-Identifier: CAL | ||
// pragma solidity ^0.8.18; | ||
|
||
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; | ||
import {Pointer} from "rain.solmem/lib/LibPointer.sol"; | ||
import {IntegrityCheckStateNP} from "../../integrity/LibIntegrityCheckNP.sol"; | ||
import {Operand} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol"; | ||
import {InterpreterStateNP} from "../../state/LibInterpreterStateNP.sol"; | ||
import {IERC20Metadata} from "openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol"; | ||
// import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; | ||
// import {Pointer} from "rain.solmem/lib/LibPointer.sol"; | ||
// import {IntegrityCheckStateNP} from "../../integrity/LibIntegrityCheckNP.sol"; | ||
// import {Operand} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol"; | ||
// import {InterpreterStateNP} from "../../state/LibInterpreterStateNP.sol"; | ||
// import {IERC20Metadata} from "openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol"; | ||
|
||
/// @title LibOpERC20Allowance | ||
/// @notice Opcode for getting the current erc20 allowance of an account. | ||
library LibOpERC20Allowance { | ||
function integrity(IntegrityCheckStateNP memory, Operand) internal pure returns (uint256, uint256) { | ||
// Always 3 inputs, the token, the owner and the spender. | ||
// Always 1 output, the allowance. | ||
return (3, 1); | ||
} | ||
// /// @title LibOpERC20Allowance | ||
// /// @notice Opcode for getting the current erc20 allowance of an account. | ||
// library LibOpERC20Allowance { | ||
// function integrity(IntegrityCheckStateNP memory, Operand) internal pure returns (uint256, uint256) { | ||
// // Always 3 inputs, the token, the owner and the spender. | ||
// // Always 1 output, the allowance. | ||
// return (3, 1); | ||
// } | ||
|
||
function run(InterpreterStateNP memory, Operand, Pointer stackTop) internal view returns (Pointer) { | ||
uint256 token; | ||
uint256 owner; | ||
uint256 spender; | ||
assembly ("memory-safe") { | ||
token := mload(stackTop) | ||
owner := mload(add(stackTop, 0x20)) | ||
stackTop := add(stackTop, 0x40) | ||
spender := mload(stackTop) | ||
} | ||
uint256 tokenAllowance = | ||
IERC20(address(uint160(token))).allowance(address(uint160(owner)), address(uint160(spender))); | ||
// function run(InterpreterStateNP memory, Operand, Pointer stackTop) internal view returns (Pointer) { | ||
// uint256 token; | ||
// uint256 owner; | ||
// uint256 spender; | ||
// assembly ("memory-safe") { | ||
// token := mload(stackTop) | ||
// owner := mload(add(stackTop, 0x20)) | ||
// stackTop := add(stackTop, 0x40) | ||
// spender := mload(stackTop) | ||
// } | ||
// uint256 tokenAllowance = | ||
// IERC20(address(uint160(token))).allowance(address(uint160(owner)), address(uint160(spender))); | ||
|
||
// This can fail as `decimals` is an OPTIONAL part of the ERC20 standard. | ||
uint256 tokenDecimals = IERC20Metadata(address(uint160(token))).decimals(); | ||
tokenAllowance = LibFixedPointDecimalScale.scale18( | ||
tokenAllowance, | ||
tokenDecimals, | ||
// Saturate scaling as "infinite approve" is a fairly common pattern | ||
// so erroring would make a lot of contracts unusable in practise. | ||
// Rounding down is the default. | ||
FLAG_SATURATE | ||
); | ||
// // This can fail as `decimals` is an OPTIONAL part of the ERC20 standard. | ||
// uint256 tokenDecimals = IERC20Metadata(address(uint160(token))).decimals(); | ||
// tokenAllowance = LibFixedPointDecimalScale.scale18( | ||
// tokenAllowance, | ||
// tokenDecimals, | ||
// // Saturate scaling as "infinite approve" is a fairly common pattern | ||
// // so erroring would make a lot of contracts unusable in practise. | ||
// // Rounding down is the default. | ||
// FLAG_SATURATE | ||
// ); | ||
|
||
assembly ("memory-safe") { | ||
mstore(stackTop, tokenAllowance) | ||
} | ||
return stackTop; | ||
} | ||
// assembly ("memory-safe") { | ||
// mstore(stackTop, tokenAllowance) | ||
// } | ||
// return stackTop; | ||
// } | ||
|
||
function referenceFn(InterpreterStateNP memory, Operand, uint256[] memory inputs) | ||
internal | ||
view | ||
returns (uint256[] memory) | ||
{ | ||
uint256 token = inputs[0]; | ||
uint256 owner = inputs[1]; | ||
uint256 spender = inputs[2]; | ||
// function referenceFn(InterpreterStateNP memory, Operand, uint256[] memory inputs) | ||
// internal | ||
// view | ||
// returns (uint256[] memory) | ||
// { | ||
// uint256 token = inputs[0]; | ||
// uint256 owner = inputs[1]; | ||
// uint256 spender = inputs[2]; | ||
|
||
uint256 tokenDecimals = IERC20Metadata(address(uint160(token))).decimals(); | ||
uint256 tokenAllowance = | ||
IERC20(address(uint160(token))).allowance(address(uint160(owner)), address(uint160(spender))); | ||
tokenAllowance = LibFixedPointDecimalScale.scale18(tokenAllowance, tokenDecimals, FLAG_SATURATE); | ||
// uint256 tokenDecimals = IERC20Metadata(address(uint160(token))).decimals(); | ||
// uint256 tokenAllowance = | ||
// IERC20(address(uint160(token))).allowance(address(uint160(owner)), address(uint160(spender))); | ||
// tokenAllowance = LibFixedPointDecimalScale.scale18(tokenAllowance, tokenDecimals, FLAG_SATURATE); | ||
|
||
uint256[] memory outputs = new uint256[](1); | ||
outputs[0] = tokenAllowance; | ||
return outputs; | ||
} | ||
} | ||
// uint256[] memory outputs = new uint256[](1); | ||
// outputs[0] = tokenAllowance; | ||
// return outputs; | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,69 @@ | ||
// SPDX-License-Identifier: CAL | ||
pragma solidity ^0.8.18; | ||
// // SPDX-License-Identifier: CAL | ||
// pragma solidity ^0.8.18; | ||
|
||
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; | ||
import {Pointer} from "rain.solmem/lib/LibPointer.sol"; | ||
import {IntegrityCheckStateNP} from "../../integrity/LibIntegrityCheckNP.sol"; | ||
import {Operand} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol"; | ||
import {InterpreterStateNP} from "../../state/LibInterpreterStateNP.sol"; | ||
import {IERC20Metadata} from "openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol"; | ||
// import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; | ||
// import {Pointer} from "rain.solmem/lib/LibPointer.sol"; | ||
// import {IntegrityCheckStateNP} from "../../integrity/LibIntegrityCheckNP.sol"; | ||
// import {Operand} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol"; | ||
// import {InterpreterStateNP} from "../../state/LibInterpreterStateNP.sol"; | ||
// import {IERC20Metadata} from "openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol"; | ||
|
||
/// @title LibOpERC20BalanceOf | ||
/// @notice Opcode for getting the current erc20 balance of an account. | ||
library LibOpERC20BalanceOf { | ||
function integrity(IntegrityCheckStateNP memory, Operand) internal pure returns (uint256, uint256) { | ||
// Always 2 inputs, the token and the account. | ||
// Always 1 output, the balance. | ||
return (2, 1); | ||
} | ||
// /// @title LibOpERC20BalanceOf | ||
// /// @notice Opcode for getting the current erc20 balance of an account. | ||
// library LibOpERC20BalanceOf { | ||
// function integrity(IntegrityCheckStateNP memory, Operand) internal pure returns (uint256, uint256) { | ||
// // Always 2 inputs, the token and the account. | ||
// // Always 1 output, the balance. | ||
// return (2, 1); | ||
// } | ||
|
||
function run(InterpreterStateNP memory, Operand, Pointer stackTop) internal view returns (Pointer) { | ||
uint256 token; | ||
uint256 account; | ||
assembly ("memory-safe") { | ||
token := mload(stackTop) | ||
stackTop := add(stackTop, 0x20) | ||
account := mload(stackTop) | ||
} | ||
uint256 tokenBalance = IERC20(address(uint160(token))).balanceOf(address(uint160(account))); | ||
// function run(InterpreterStateNP memory, Operand, Pointer stackTop) internal view returns (Pointer) { | ||
// uint256 token; | ||
// uint256 account; | ||
// assembly ("memory-safe") { | ||
// token := mload(stackTop) | ||
// stackTop := add(stackTop, 0x20) | ||
// account := mload(stackTop) | ||
// } | ||
// uint256 tokenBalance = IERC20(address(uint160(token))).balanceOf(address(uint160(account))); | ||
|
||
// This can fail as `decimals` is an OPTIONAL part of the ERC20 standard. | ||
uint256 tokenDecimals = IERC20Metadata(address(uint160(token))).decimals(); | ||
tokenBalance = LibFixedPointDecimalScale.scale18( | ||
tokenBalance, | ||
tokenDecimals, | ||
// Error on overflow as balance is a critical value. | ||
// Rounding down is the default. | ||
0 | ||
); | ||
// // This can fail as `decimals` is an OPTIONAL part of the ERC20 standard. | ||
// uint256 tokenDecimals = IERC20Metadata(address(uint160(token))).decimals(); | ||
// tokenBalance = LibFixedPointDecimalScale.scale18( | ||
// tokenBalance, | ||
// tokenDecimals, | ||
// // Error on overflow as balance is a critical value. | ||
// // Rounding down is the default. | ||
// 0 | ||
// ); | ||
|
||
assembly ("memory-safe") { | ||
mstore(stackTop, tokenBalance) | ||
} | ||
return stackTop; | ||
} | ||
// assembly ("memory-safe") { | ||
// mstore(stackTop, tokenBalance) | ||
// } | ||
// return stackTop; | ||
// } | ||
|
||
function referenceFn(InterpreterStateNP memory, Operand, uint256[] memory inputs) | ||
internal | ||
view | ||
returns (uint256[] memory) | ||
{ | ||
uint256 token = inputs[0]; | ||
uint256 account = inputs[1]; | ||
// function referenceFn(InterpreterStateNP memory, Operand, uint256[] memory inputs) | ||
// internal | ||
// view | ||
// returns (uint256[] memory) | ||
// { | ||
// uint256 token = inputs[0]; | ||
// uint256 account = inputs[1]; | ||
|
||
uint256 tokenBalance = IERC20(address(uint160(token))).balanceOf(address(uint160(account))); | ||
// uint256 tokenBalance = IERC20(address(uint160(token))).balanceOf(address(uint160(account))); | ||
|
||
uint256 tokenDecimals = IERC20Metadata(address(uint160(token))).decimals(); | ||
tokenBalance = LibFixedPointDecimalScale.scale18( | ||
tokenBalance, | ||
tokenDecimals, | ||
// Error on overflow as balance is a critical value. | ||
// Rounding down is the default. | ||
0 | ||
); | ||
// uint256 tokenDecimals = IERC20Metadata(address(uint160(token))).decimals(); | ||
// tokenBalance = LibFixedPointDecimalScale.scale18( | ||
// tokenBalance, | ||
// tokenDecimals, | ||
// // Error on overflow as balance is a critical value. | ||
// // Rounding down is the default. | ||
// 0 | ||
// ); | ||
|
||
uint256[] memory outputs = new uint256[](1); | ||
outputs[0] = tokenBalance; | ||
return outputs; | ||
} | ||
} | ||
// uint256[] memory outputs = new uint256[](1); | ||
// outputs[0] = tokenBalance; | ||
// return outputs; | ||
// } | ||
// } |
Oops, something went wrong.