Skip to content

Commit

Permalink
immutable ex
Browse files Browse the repository at this point in the history
  • Loading branch information
saflamini committed May 16, 2023
1 parent a2cf259 commit 1e13733
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 1 deletion.
29 changes: 29 additions & 0 deletions contracts/ImmutablePureSuperToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: AGPLv3
pragma solidity ^0.8.0;

import {SuperTokenBase} from "./base/SuperTokenBase.sol";
import {SuperTokenStorage} from "./base/SuperTokenStorage.sol";
import { ImmutableSuperTokenBase } from "./base/ImmutableSuperTokenBase.sol";
import {ISuperToken} from "@superfluid-finance/ethereum-contracts/contracts/interfaces/superfluid/ISuperToken.sol";

/// @title Minimal Pure Super Token
/// @author jtriley.eth
/// @notice Pre-minted supply. This is includes no custom logic. Used in `PureSuperTokenDeployer`
contract ImmutablePureSuperToken is ImmutableSuperTokenBase {

/// @dev Upgrades the super token with the factory, then initializes.
/// @param name super token name
/// @param symbol super token symbol
/// @param receiver Receiver of pre-mint
/// @param initialSupply Initial token supply to pre-mint
function initialize (
string memory name,
string memory symbol,
address receiver,
uint256 initialSupply
) external {
_initialize(name, symbol);
_mint(receiver, initialSupply, "");
}

}
65 changes: 65 additions & 0 deletions contracts/base/ImmutableSuperTokenBase.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// SPDX-License-Identifier: AGPLv3
pragma solidity ^0.8.0;

import {SuperTokenStorage} from "../base/SuperTokenStorage.sol";
import {UUPSProxy} from "../base/UUPSProxy.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {ISuperToken} from "@superfluid-finance/ethereum-contracts/contracts/interfaces/superfluid/ISuperToken.sol";
import {ISuperTokenFactory} from "@superfluid-finance/ethereum-contracts/contracts/interfaces/superfluid/ISuperTokenFactory.sol";

/// @title Abstract contract containing a thin layer of abstraction for aux logic.
/// @dev The initial supply may be zero, in the event the token is mintable.
/// Inheriting contracts MUST have an initializer calling this function!
abstract contract ImmutableSuperTokenBase is SuperTokenStorage {

/// @dev Upgrades the super token with the factory, then initializes.
/// @param name super token name
/// @param symbol super token symbol
function _initialize(string memory name, string memory symbol) internal {
ISuperToken(address(this)).initialize(IERC20(address(0)), 18, name, symbol);
}

/// @dev Gets totalSupply
/// @return t total supply
function _totalSupply() internal view returns (uint256 t) {
return ISuperToken(address(this)).totalSupply();
}

/// @dev Internal mint, calling functions should perform important checks!
/// @param account Address receiving minted tokens
/// @param amount Amount of tokens minted
/// @param userData Optional user data for ERC777 send callback
function _mint(address account, uint256 amount, bytes memory userData) internal {
ISuperToken(address(this)).selfMint(account, amount, userData);
}

/// @dev Internal burn, calling functions should perform important checks!
/// @param from Address from which to burn tokens
/// @param amount Amount to burn
/// @param userData Optional user data for ERC777 send callback
function _burn(address from, uint256 amount, bytes memory userData) internal {
ISuperToken(address(this)).selfBurn(from, amount, userData);
}

/// @dev Internal approve, calling functions should perform important checks!
/// @param account Address of approving party
/// @param spender Address of spending party
/// @param amount Approval amount
function _approve(address account, address spender, uint256 amount) internal {
ISuperToken(address(this)).selfApproveFor(account, spender, amount);
}

/// @dev Internal transferFrom, calling functions should perform important checks!
/// @param holder Owner of the tranfserred tokens
/// @param spender Address of spending party (approved/operator)
/// @param recipient Address of recipient party
/// @param amount Amount to be tranfserred
function _transferFrom(
address holder,
address spender,
address recipient,
uint256 amount
) internal {
ISuperToken(address(this)).selfTransferFrom(holder, spender, recipient, amount);
}
}
82 changes: 82 additions & 0 deletions scripts/deployToken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
const { web3tx } = require("@decentral.ee/web3-helpers")
const { setWeb3Provider } = require("@decentral.ee/web3-helpers/src/config")
const { factory: factoryAddrs } = require("./utils/constants")

/*
* Truffle script for deploying a custom Super Token
* New contracts can be easily added.
* Constructor arguments are to be set via ENV vars.
*
* ENV vars:
* - CONTRACT: the name of the contract, e.g. "MintableSuperToken"
* - CTOR_ARGS: comma-delimited arguments to the constructor of the token proxy contract
* - INIT_ARGS: comma-delimited arguments (excluding factory) to the initialize function of the token contract
* - FACTORY: address of the SuperTokenFactory, needed on dev networks
*
* Example use:
* CONTRACT=MintableSuperToken INIT_ARGS="my token","MTK" npx truffle exec --network goerli scripts/deploy.js
*
* If used to deploy on a development network, you also need to set FACTORY to a Super Token Factory address.
*/
module.exports = async function (callback) {
// const contractName = process.env.CONTRACT
const contractName = "ImmutablePureSuperToken"

// const ctorArgsStr = process.env.CTOR_ARGS
const ctorArgsStr = ""
// const ctorArgsStr = `
// Sam Pure Token,
// SAM,
// 0x969105CB4503Bf98A734c850685A198C530c2Fdb,
// 100000000000000000000
// `
// const initArgsStr = process.env.INIT_ARGS
const initArgsStr = `Sam Pure Token, SAM, 0x969105CB4503Bf98A734c850685A198C530c2Fdb, 100000000000`

const ctorArgs = ctorArgsStr
? ctorArgsStr.split(",").map(e => e.trim())
: []
const initArgs = initArgsStr
? initArgsStr.split(",").map(e => e.trim())
: []

try {
if (contractName === undefined) {
throw "ERR: ENV var CONTRACT not set"
}

// will throw if not found
const Contract = artifacts.require(contractName)

console.log("contructor args:", ctorArgs)
console.log("initialize args:", initArgs)

setWeb3Provider(web3.currentProvider)

const chainId = await web3.eth.net.getId()
const factoryAddr = process.env.FACTORY || factoryAddrs[chainId]
if (factoryAddr === undefined) {
throw "ERR: No SuperTokenFactory address provided of found for the connected chain"
}

// console.log("SuperTokenFactory address", factoryAddr)
console.log("Deploying contract...")

const token = await web3tx(
Contract.new,
"Deploy token contract"
)(...ctorArgs)

console.log(`Token Contract deployed at: ${token.address}`)

await web3tx(token.initialize, "Initialize Token contract")(...initArgs)

console.log(
"All done, token deployed and initialized at:",
token.address
)
callback()
} catch (error) {
callback(error)
}
}
2 changes: 1 addition & 1 deletion truffle-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
mumbai: {
provider: () =>
new HDWalletProvider({
mnemonic: process.env.MUMBAI_MNEMONIC,
privateKeys: [`${process.env.MUMBAI_KEY}`],
url: process.env.MUMBAI_PROVIDER_URL
}),
network_id: 80001,
Expand Down

0 comments on commit 1e13733

Please sign in to comment.