Skip to content

Commit

Permalink
WIP staking work
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhforrest committed May 29, 2018
1 parent 00aa80e commit 26eebbe
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 23 deletions.
1 change: 1 addition & 0 deletions contracts/CodexTitleAccess.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ contract CodexTitleAccess is CodexTitleCore {
string _providerMetadataId) // TODO: convert to bytes32
public
whenNotPaused
canPayFees
{
return super.mint(
_to,
Expand Down
6 changes: 0 additions & 6 deletions contracts/CodexTitleCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ contract CodexTitleCore is CodexTitleMetadata, CodexTitleFees {
string _providerMetadataId) // TODO: convert to bytes32
public
{
if (feeRecipient != address(0)) {
require(
codexToken.transferFrom(msg.sender, feeRecipient, creationFee),
"Fee in CODX required");
}

// For now, all new tokens will be the last entry in the array
uint256 newTokenId = allTokens.length;

Expand Down
41 changes: 33 additions & 8 deletions contracts/CodexTitleFees.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pragma solidity ^0.4.24;

import "./ERC20/ERC20.sol";
import "./ERC900/ERC900.sol";

import "./library/Pausable.sol";


Expand All @@ -11,31 +13,54 @@ import "./library/Pausable.sol";
*/
contract CodexTitleFees is Pausable {

// Address of the ERC20 Codex Protocol Token, used for fees in the contract
address public codexTokenAddress;

// Implementation of ERC20 Codex Protocol Token, used for fees in the contract
// Implementation of the ERC20 Codex Protocol Token, used for fees in the contract
ERC20 public codexToken;

// Implementation of the ERC900 Codex Protocol Stake Container,
// used to calculate discounts on fees
ERC900 public codexStakeContainer;

// Address where all contract fees are sent, i.e., the Community Fund
address public feeRecipient;

// Fee to create new tokens. 10^18 = 1 token
uint256 public creationFee = 0;

modifier canPayFees() {
if (feeRecipient != address(0)) {
// TODO: Update the discount to be based on weight as opposed to just
// a binary on/off value
uint256 calculatedFee = creationFee;
if (codexStakeContainer != address(0) &&
codexStakeContainer.totalStakedFor(msg.sender) >= 0) {

calculatedFee = 0;
}

require(
codexToken.transferFrom(msg.sender, feeRecipient, calculatedFee),
"Fee in CODX required");
}

_;
}

/**
* @dev Sets the address of the ERC20 token used for fees in the contract.
* @param _codexTokenAddress The address of the ERC20 Codex Protocol Token
* @param _codexToken The address of the ERC20 Codex Protocol Token
* @param _feeRecipient The address where the fees are sent
* @param _creationFee The new creation fee. 10^18 is 1 token.
*/
function setFees(address _codexTokenAddress, address _feeRecipient, uint256 _creationFee) external onlyOwner {
codexTokenAddress = _codexTokenAddress;
codexToken = ERC20(codexTokenAddress);
function setFees(ERC20 _codexToken, address _feeRecipient, uint256 _creationFee) external onlyOwner {
codexToken = _codexToken;
feeRecipient = _feeRecipient;
creationFee = _creationFee;
}

function setStakeContainer(ERC900 _codexStakeContainer) external onlyOwner {
codexStakeContainer = _codexStakeContainer;
}

/**
* @dev Sets the creation fee in CODX
* @param _creationFee The new creation fee. 10^18 is 1 token.
Expand Down
9 changes: 3 additions & 6 deletions contracts/ERC900/ERC900BasicStakeContainer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import "../library/SafeMath.sol";
contract ERC900BasicStakeContainer is ERC900 {
using SafeMath for uint256;

address tokenAddress;

ERC20 stakingToken;

mapping (address => Stake) stakes;
Expand All @@ -26,9 +24,8 @@ contract ERC900BasicStakeContainer is ERC900 {
bool exists;
}

constructor(address _tokenAddress) public {
tokenAddress = _tokenAddress;
stakingToken = ERC20(tokenAddress);
constructor(ERC20 _stakingToken) public {
stakingToken = _stakingToken;
}

function stake(uint256 _amount, bytes _data) public {
Expand Down Expand Up @@ -103,6 +100,6 @@ contract ERC900BasicStakeContainer is ERC900 {
}

function token() public view returns (address) {
return tokenAddress;
return stakingToken;
}
}
4 changes: 2 additions & 2 deletions contracts/ERC900/ERC900StakeContainer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import "./ERC900BasicStakeContainer.sol";
* @title ERC900StakeContainer
*/
contract ERC900StakeContainer is ERC900BasicStakeContainer {
constructor(address _tokenAddress) public
ERC900BasicStakeContainer(_tokenAddress) {
constructor(ERC20 _stakingToken) public
ERC900BasicStakeContainer(_stakingToken) {
}

/*
Expand Down
27 changes: 26 additions & 1 deletion test/token/behaviors/CodexTitle.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import modifyMetadataHashesUnbound from '../../helpers/modifyMetadataHashes'

const { BigNumber } = web3
const CodexToken = artifacts.require('CodexToken.sol')
const ERC900BasicStakeContainer = artifacts.require('ERC900BasicStakeContainer.sol')

require('chai')
.use(require('chai-as-promised'))
Expand Down Expand Up @@ -86,7 +87,7 @@ export default function shouldBehaveLikeCodexTitle(accounts) {
})

it('has a codexToken address', async function () {
const tokenAddress = await this.token.codexTokenAddress()
const tokenAddress = await this.token.codexToken()
tokenAddress.should.be.equal(codexToken.address)
})

Expand Down Expand Up @@ -142,6 +143,30 @@ export default function shouldBehaveLikeCodexTitle(accounts) {
)
})
})

describe('and tokens are staked', function () {
let stakeContainer

beforeEach(async function () {
stakeContainer = await ERC900BasicStakeContainer.new(codexToken.address)

await this.token.setStakeContainer(stakeContainer.address)

await this.token.mint(
creator,
hashedMetadata.name,
hashedMetadata.description,
hashedMetadata.imageBytes,
providerId,
providerMetadataId
)
})

it('should create a new token', async function () {
const numTokens = await this.token.totalSupply()
numTokens.should.be.bignumber.equal(2)
})
})
})
})

Expand Down

0 comments on commit 26eebbe

Please sign in to comment.