-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from superform-xyz/splitter-to-transmuter
chore: Splitter to transmuter
- Loading branch information
Showing
8 changed files
with
111 additions
and
225 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity 0.8.19; | ||
|
||
interface ITransmuter { | ||
/// @notice id given here needs to be the same as id on Source! | ||
/// @dev Make sure its set for existing ids only | ||
/// @dev Ideally, this should be only called by SuperPositions (or other privileged contract) | ||
/// @param id id of the ERC1155 to wrap | ||
/// @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 | ||
) external returns (address); | ||
|
||
/// @notice Use ERC1155 BatchTransfer to transmute multiple ERC1155 ids into separate ERC20 | ||
/// Easier to transmute to 1155s than to transmute back to erc20 because of ERC1155 beauty! | ||
/// @param ids ids of the ERC1155s to transmute | ||
/// @param amounts amounts of the ERC1155s to transmute | ||
function transmuteBatchToERC20(uint256[] memory ids, uint256[] memory amounts) external; | ||
|
||
/// @param id id of the ERC20s to transmute to erc20 | ||
/// @param amount amount of the ERC20s to transmute to erc20 | ||
function transmuteToERC20(uint256 id, uint256 amount) external; | ||
|
||
/// @param id id of the ERC20s to transmute to erc1155 | ||
/// @param amount amount of the ERC20s to transmute to erc1155 | ||
function transmuteToERC1155s(uint256 id, uint256 amount) external; | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity 0.8.19; | ||
|
||
import "forge-std/Test.sol"; | ||
import {Transmuter} from "../transmuter/Transmuter.sol"; | ||
import {MockERC1155s} from "./mocks/MockERC1155s.sol"; | ||
import {ERC20} from "solmate/tokens/ERC20.sol"; | ||
import {sERC20} from "../transmuter/sERC20.sol"; | ||
|
||
contract TransmuterTest is Test { | ||
uint256 public constant THOUSAND_E18 = 1000 ether; | ||
|
||
MockERC1155s public superPositions; | ||
Transmuter public transmuter; | ||
ERC20 public syntheticERC20Token; | ||
|
||
address public alice = address(0x2137); | ||
address public bob = address(0x0997); | ||
|
||
function setUp() public { | ||
superPositions = new MockERC1155s(); | ||
superPositions.mint(alice, 1, THOUSAND_E18, ""); | ||
|
||
transmuter = new Transmuter(superPositions); | ||
} | ||
|
||
function testTransmute() public { | ||
syntheticERC20Token = sERC20(transmuter.registerTransmuter(1, "SuperPosition Id 1", "SS1", 18)); | ||
|
||
vm.startPrank(alice); | ||
|
||
superPositions.setApprovalForAll(address(transmuter), true); | ||
transmuter.transmuteToERC20(1, THOUSAND_E18); | ||
assertEq(superPositions.balanceOf(alice, 1), 0); | ||
assertEq(superPositions.balanceOf(address(transmuter), 1), THOUSAND_E18); | ||
|
||
assertEq(syntheticERC20Token.balanceOf(alice), THOUSAND_E18); | ||
|
||
uint256 sERC20Balance = syntheticERC20Token.balanceOf(alice); | ||
|
||
syntheticERC20Token.approve(address(transmuter), sERC20Balance); | ||
|
||
/// NOTE: Test if 1:1 between 1155 and 20 always holds | ||
transmuter.transmuteToERC1155s(1, sERC20Balance); | ||
|
||
assertEq(superPositions.balanceOf(alice, 1), THOUSAND_E18); | ||
|
||
assertEq(syntheticERC20Token.balanceOf(address(transmuter)), 0); | ||
} | ||
|
||
function testTransmuterAlreadyRegistered() public { | ||
syntheticERC20Token = sERC20(transmuter.registerTransmuter(1, "SuperPosition Id 1", "SS1", 18)); | ||
|
||
vm.expectRevert(); | ||
syntheticERC20Token = sERC20(transmuter.registerTransmuter(1, "SuperPosition Id 1", "SS1", 18)); | ||
} | ||
} |
Oops, something went wrong.