Skip to content

Commit

Permalink
Merge pull request #10 from superform-xyz/splitter-to-transmuter
Browse files Browse the repository at this point in the history
chore: Splitter to transmuter
  • Loading branch information
vikramarun authored Aug 9, 2023
2 parents 40e635b + 7f77431 commit 870614d
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 225 deletions.
84 changes: 0 additions & 84 deletions .gas-snapshot

This file was deleted.

21 changes: 0 additions & 21 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,6 @@ jobs:
# make fuzzing semi-deterministic to avoid noisy gas cost estimation
# due to non-deterministic fuzzing (but still use pseudo-random fuzzing seeds)
FOUNDRY_FUZZ_SEED: 0x${{ github.event.pull_request.base.sha || github.sha }}
snapshot:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: dependencies
run: forge install
- name: check contract sizes
run: forge build --sizes
- name: check gas snapshots
run: forge snapshot --check
env:
# make fuzzing semi-deterministic to avoid noisy gas cost estimation
# due to non-deterministic fuzzing (but still use pseudo-random fuzzing seeds)
FOUNDRY_FUZZ_SEED: 0x${{ github.event.pull_request.base.sha || github.sha }}


# slither:
# runs-on: ubuntu-latest
# steps:
Expand Down
32 changes: 0 additions & 32 deletions src/interfaces/IPositionsSplitter.sol

This file was deleted.

32 changes: 32 additions & 0 deletions src/interfaces/ITransmuter.sol
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;
}
57 changes: 0 additions & 57 deletions src/test/PostionsSplitter.t.sol

This file was deleted.

57 changes: 57 additions & 0 deletions src/test/Transmuter.t.sol
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));
}
}
Loading

0 comments on commit 870614d

Please sign in to comment.