Skip to content

Commit

Permalink
Merge pull request #17 from superform-xyz/upgrades
Browse files Browse the repository at this point in the history
fix: Upgrades
  • Loading branch information
sujithsomraaj authored Sep 13, 2023
2 parents b0b83a6 + c17dffb commit 379b8c0
Show file tree
Hide file tree
Showing 14 changed files with 270 additions and 98 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/solmate"]
path = lib/solmate
url = https://github.com/Rari-Capital/solmate
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/solmate"]
path = lib/solmate
url = https://github.com/transmissions11/solmate
15 changes: 0 additions & 15 deletions .prettierrc

This file was deleted.

12 changes: 11 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,14 @@ evm_version = "paris" # to prevent usage of PUSH0, which is not supported on

optimizer = true
optimizer_runs = 200
test = 'src/test'
test = 'src/test'

[fmt]
bracket_spacing = true
int_types = "long"
line_length = 120
multiline_func_header = "all"
number_underscore = "thousands"
quote_style = "double"
tab_width = 4
wrap_comments = true
2 changes: 1 addition & 1 deletion lib/openzeppelin-contracts
74 changes: 59 additions & 15 deletions src/ERC1155A.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.21;

import {IERC1155A} from "./interfaces/IERC1155A.sol";
import {Strings} from "openzeppelin-contracts/contracts/utils/Strings.sol";
import { IERC1155A } from "./interfaces/IERC1155A.sol";
import { Strings } from "openzeppelin-contracts/contracts/utils/Strings.sol";

/**
* @title ERC1155A
Expand Down Expand Up @@ -37,19 +37,28 @@ abstract contract ERC1155A is IERC1155A {

/// @notice Transfer singleApproved id with this function
/// @dev If caller is owner of ids, transfer just executes.
/// @dev If caller singleApproved > transferAmount, function executes and reduces allowance (even if setApproveForAll is true)
/// @dev If caller singleApproved < transferAmount && isApprovedForAll, function executes without reducing allowance (full trust assumed)
/// @dev If caller singleApproved > transferAmount, function executes and reduces allowance (even if
/// setApproveForAll is true)
/// @dev If caller singleApproved < transferAmount && isApprovedForAll, function executes without reducing allowance
/// (full trust assumed)
/// @dev If caller only approvedForAll, function executes without reducing allowance (full trust assumed)
/// @dev SingleApprove is senior in execution flow, but isApprovedForAll is senior in allowance management
function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data)
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes calldata data
)
public
virtual
override
{
address operator = msg.sender;
uint256 allowed = allowances[from][operator][id];

/// NOTE: This function order makes it more costly to use isApprovedForAll but cheaper to user single approval and owner transfer
/// NOTE: This function order makes it more costly to use isApprovedForAll but cheaper to user single approval
/// and owner transfer

/// @dev operator is an owner of ids
if (operator == from) {
Expand Down Expand Up @@ -80,15 +89,19 @@ abstract contract ERC1155A is IERC1155A {
}

/// @notice Internal safeTranferFrom function called after all checks from the public function are done
/// @dev Notice `operator` param. It's msg.sender to the safeTransferFrom function. Function is specific to SuperForm singleId approve logic.
/// @dev Notice `operator` param. It's msg.sender to the safeTransferFrom function. Function is specific to
/// SuperForm singleId approve logic.
function _safeTransferFrom(
address operator,
address from,
address to,
uint256 id,
uint256 amount,
bytes calldata data
) internal virtual {
)
internal
virtual
{
balanceOf[from][id] -= amount;
balanceOf[to][id] += amount;

Expand Down Expand Up @@ -122,7 +135,11 @@ abstract contract ERC1155A is IERC1155A {
uint256[] calldata ids,
uint256[] calldata amounts,
bytes calldata data
) public virtual override {
)
public
virtual
override
{
bool singleApproval;
uint256 len = ids.length;

Expand Down Expand Up @@ -168,7 +185,10 @@ abstract contract ERC1155A is IERC1155A {
}

/// @dev Implementation copied from solmate/ERC1155
function balanceOfBatch(address[] calldata owners, uint256[] calldata ids)
function balanceOfBatch(
address[] calldata owners,
uint256[] calldata ids
)
public
view
virtual
Expand Down Expand Up @@ -241,7 +261,11 @@ abstract contract ERC1155A is IERC1155A {

/// @notice Public function for increasing multiple id approval amount at once
/// @dev extension of single id increase allowance
function increaseAllowanceForMany(address spender, uint256[] memory ids, uint256[] memory addedValues)
function increaseAllowanceForMany(
address spender,
uint256[] memory ids,
uint256[] memory addedValues
)
public
virtual
returns (bool)
Expand All @@ -261,7 +285,11 @@ abstract contract ERC1155A is IERC1155A {

/// @notice Public function for decreasing multiple id approval amount at once
/// @dev extension of single id decrease allowance
function decreaseAllowanceForMany(address spender, uint256[] memory ids, uint256[] memory subtractedValues)
function decreaseAllowanceForMany(
address spender,
uint256[] memory ids,
uint256[] memory subtractedValues
)
public
virtual
returns (bool)
Expand All @@ -283,7 +311,12 @@ abstract contract ERC1155A is IERC1155A {
/// @dev Only to be used by address(this)
/// @dev Notice `owner` param, only contract functions should be able to define it
/// @dev Re-adapted from ERC20
function _decreaseAllowance(address owner, address spender, uint256 id, uint256 subtractedValue)
function _decreaseAllowance(
address owner,
address spender,
uint256 id,
uint256 subtractedValue
)
internal
virtual
returns (bool)
Expand Down Expand Up @@ -366,7 +399,12 @@ abstract contract ERC1155A is IERC1155A {
}

/// @dev Implementation copied from solmate/ERC1155
function _batchMint(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
function _batchMint(
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
)
internal
virtual
{
Expand Down Expand Up @@ -454,7 +492,13 @@ abstract contract ERC1155TokenReceiver {
return ERC1155TokenReceiver.onERC1155Received.selector;
}

function onERC1155BatchReceived(address, address, uint256[] calldata, uint256[] calldata, bytes calldata)
function onERC1155BatchReceived(
address,
address,
uint256[] calldata,
uint256[] calldata,
bytes calldata
)
external
virtual
returns (bytes4)
Expand Down
14 changes: 11 additions & 3 deletions src/interfaces/IERC1155A.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.21;

import {IERC1155} from "openzeppelin-contracts/contracts/token/ERC1155/IERC1155.sol";
import { IERC1155 } from "openzeppelin-contracts/contracts/token/ERC1155/IERC1155.sol";

interface IERC1155A is IERC1155 {
/*//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -41,13 +41,21 @@ interface IERC1155A is IERC1155 {

/// @notice Public function for increasing multiple id approval amount at once
/// @dev extension of single id increase allowance
function increaseAllowanceForMany(address spender, uint256[] memory ids, uint256[] memory addedValues)
function increaseAllowanceForMany(
address spender,
uint256[] memory ids,
uint256[] memory addedValues
)
external
returns (bool);

/// @notice Public function for decreasing multiple id approval amount at once
/// @dev extension of single id decrease allowance
function decreaseAllowanceForMany(address spender, uint256[] memory ids, uint256[] memory subtractedValues)
function decreaseAllowanceForMany(
address spender,
uint256[] memory ids,
uint256[] memory subtractedValues
)
external
returns (bool);

Expand Down
7 changes: 6 additions & 1 deletion src/interfaces/ITransmuter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ interface ITransmuter {
/// @param name name of the ERC20 to create
/// @param symbol symbol of the ERC20 to create
/// @param decimals decimals of the ERC20 to create
function registerTransmuter(uint256 id, string memory name, string memory symbol, uint8 decimals)
function registerTransmuter(
uint256 id,
string memory name,
string memory symbol,
uint8 decimals
)
external
returns (address);

Expand Down
Loading

0 comments on commit 379b8c0

Please sign in to comment.