Reward Vault Implementation with wrapper functions. Working on tests.
This commit is contained in:
@@ -322,7 +322,7 @@ contract Staking is
|
||||
view
|
||||
returns (uint256)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
function computeDelegatorReward(address owner, bytes32 poolId)
|
||||
|
@@ -39,7 +39,7 @@ contract MixinRewards is
|
||||
view
|
||||
returns (uint256)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
function _computeDelegatorReward(address owner, bytes32 poolId)
|
||||
|
@@ -19,7 +19,7 @@
|
||||
pragma solidity ^0.5.5;
|
||||
|
||||
import "../interfaces/IVault.sol";
|
||||
import "../interfaces/IRebateVault.sol";
|
||||
import "../interfaces/IRewardVault.sol";
|
||||
import "./MixinConstants.sol";
|
||||
import "../interfaces/IStructs.sol";
|
||||
|
||||
@@ -110,5 +110,5 @@ contract MixinStorage is
|
||||
IVault zrxVault;
|
||||
|
||||
// Rebate Vault
|
||||
IRebateVault rebateVault;
|
||||
IRewardVault rebateVault;
|
||||
}
|
||||
|
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright 2018 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.5.5;
|
||||
|
||||
|
||||
interface IRebateVault {
|
||||
|
||||
function depositFor(bytes32 poolId) external;
|
||||
//function withdrawFrom(bytes32 poolId, uint256 amount) external;
|
||||
//function withdrawAllFrom(bytes32 poolId) external returns (uint256);
|
||||
function balanceOf(bytes32 poolId) external view returns (uint256);
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
|
||||
Copyright 2018 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.5.5;
|
||||
|
||||
|
||||
interface IRewardVault {
|
||||
|
||||
function depositFor(bytes32 poolId)
|
||||
external
|
||||
payable;
|
||||
|
||||
function withdrawFor(bytes32 poolId, uint256 amount)
|
||||
external;
|
||||
|
||||
function withdrawAllFrom(bytes32 poolId)
|
||||
external
|
||||
returns (uint256);
|
||||
|
||||
function balanceOf(bytes32 poolId)
|
||||
external
|
||||
view
|
||||
returns (uint256);
|
||||
|
||||
function getOwner(bytes32 poolId)
|
||||
external
|
||||
view
|
||||
returns (address);
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ contract MixinVaultCore is
|
||||
Authorizable
|
||||
{
|
||||
|
||||
address internal stakingContractAddress;
|
||||
address payable internal stakingContractAddress;
|
||||
|
||||
bool internal isInCatostrophicFailure;
|
||||
|
||||
@@ -50,7 +50,7 @@ contract MixinVaultCore is
|
||||
_;
|
||||
}
|
||||
|
||||
function setStakingContractAddrsess(address _stakingContractAddress)
|
||||
function setStakingContractAddrsess(address payable _stakingContractAddress)
|
||||
external
|
||||
onlyOwner
|
||||
{
|
||||
|
@@ -21,11 +21,14 @@ pragma solidity ^0.5.5;
|
||||
import "../interfaces/IVault.sol";
|
||||
import "@0x/contracts-utils/contracts/src/SafeMath.sol";
|
||||
import "./MixinVaultCore.sol";
|
||||
import "../interfaces/IRewardVault.sol";
|
||||
import "../immutable/MixinConstants.sol";
|
||||
|
||||
|
||||
contract RebateVault is
|
||||
IVault,
|
||||
contract RewardVault is
|
||||
IRewardVault,
|
||||
SafeMath,
|
||||
MixinConstants,
|
||||
MixinVaultCore
|
||||
{
|
||||
|
||||
@@ -36,15 +39,13 @@ contract RebateVault is
|
||||
// mapping from Pool to Rebate Balance in ETH
|
||||
mapping (bytes32 => uint256) internal balancesByPoolId;
|
||||
|
||||
// mapping from
|
||||
mapping (bytes32 => address) internal ownerByPoolId;
|
||||
// mapping from owner to pool id
|
||||
mapping (bytes32 => address payable) internal ownerByPoolId;
|
||||
|
||||
constructor()
|
||||
public
|
||||
{}
|
||||
|
||||
/////
|
||||
|
||||
function depositFor(bytes32 poolId)
|
||||
external
|
||||
payable
|
||||
@@ -53,6 +54,38 @@ contract RebateVault is
|
||||
balancesByPoolId[poolId] = _safeAdd(balancesByPoolId[poolId], msg.value);
|
||||
}
|
||||
|
||||
function withdrawFor(bytes32 poolId, uint256 amount)
|
||||
external
|
||||
onlyStakingContract
|
||||
{
|
||||
require(
|
||||
amount <= balancesByPoolId[poolId],
|
||||
"AMOUNT_EXCEEDS_BALANCE_OF_POOL"
|
||||
);
|
||||
balancesByPoolId[poolId] = _safeSub(balancesByPoolId[poolId], amount);
|
||||
stakingContractAddress.transfer(amount);
|
||||
}
|
||||
|
||||
function withdrawAllFrom(bytes32 poolId)
|
||||
external
|
||||
onlyInCatostrophicFailure
|
||||
returns (uint256)
|
||||
{
|
||||
address payable owner = ownerByPoolId[poolId];
|
||||
require(
|
||||
owner != NIL_ADDRESS,
|
||||
"INVALID_OWNER"
|
||||
);
|
||||
uint256 balanceInPool = balancesByPoolId[poolId];
|
||||
require(
|
||||
balanceInPool > 0,
|
||||
"POOL_BALANCE_IS_ZERO"
|
||||
);
|
||||
|
||||
balancesByPoolId[poolId] = 0;
|
||||
owner.transfer(balancesByPoolId[poolId]);
|
||||
}
|
||||
|
||||
function balanceOf(bytes32 poolId)
|
||||
external
|
||||
view
|
||||
@@ -60,49 +93,4 @@ contract RebateVault is
|
||||
{
|
||||
return balancesByPoolId[poolId];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
// Deposits shadow ETH
|
||||
function depositFrom(address owner, uint256 amount)
|
||||
external
|
||||
onlyStakingContract
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function withdrawFrom(address owner, bytes32 poolId, uint256 amount)
|
||||
external
|
||||
onlyStakingContract
|
||||
{
|
||||
// check if owner is operator
|
||||
|
||||
|
||||
}
|
||||
|
||||
function _withdrawFromOperator(address owner, uint256 amount)
|
||||
private
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function _withdrawFromNotOperator(address owner, uint256 amount)
|
||||
private
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function withdrawAllFrom(address owner)
|
||||
external
|
||||
onlyInCatostrophicFailure
|
||||
returns (uint256)
|
||||
{}
|
||||
|
||||
function balanceOf(address owner)
|
||||
external
|
||||
view
|
||||
returns (uint256)
|
||||
{
|
||||
return uint256(132 * 10**18);
|
||||
} */
|
||||
}
|
@@ -36,7 +36,7 @@
|
||||
"compile:truffle": "truffle compile"
|
||||
},
|
||||
"config": {
|
||||
"abis": "./generated-artifacts/@(LibMathTest|LibZrxToken|MixinStake|MixinVaultCore|Staking|StakingProxy|ZrxVault).json",
|
||||
"abis": "./generated-artifacts/@(LibMathTest|LibZrxToken|MixinStake|RewardVault|Staking|StakingProxy|ZrxVault).json",
|
||||
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually."
|
||||
},
|
||||
"repository": {
|
||||
|
@@ -8,7 +8,7 @@ import { ContractArtifact } from 'ethereum-types';
|
||||
import * as LibMathTest from '../generated-artifacts/LibMathTest.json';
|
||||
import * as LibZrxToken from '../generated-artifacts/LibZrxToken.json';
|
||||
import * as MixinStake from '../generated-artifacts/MixinStake.json';
|
||||
import * as MixinVaultCore from '../generated-artifacts/MixinVaultCore.json';
|
||||
import * as RewardVault from '../generated-artifacts/RewardVault.json';
|
||||
import * as Staking from '../generated-artifacts/Staking.json';
|
||||
import * as StakingProxy from '../generated-artifacts/StakingProxy.json';
|
||||
import * as ZrxVault from '../generated-artifacts/ZrxVault.json';
|
||||
@@ -17,7 +17,7 @@ export const artifacts = {
|
||||
StakingProxy: StakingProxy as ContractArtifact,
|
||||
MixinStake: MixinStake as ContractArtifact,
|
||||
LibZrxToken: LibZrxToken as ContractArtifact,
|
||||
MixinVaultCore: MixinVaultCore as ContractArtifact,
|
||||
RewardVault: RewardVault as ContractArtifact,
|
||||
ZrxVault: ZrxVault as ContractArtifact,
|
||||
LibMathTest: LibMathTest as ContractArtifact,
|
||||
};
|
||||
|
@@ -6,7 +6,7 @@
|
||||
export * from '../generated-wrappers/lib_math_test';
|
||||
export * from '../generated-wrappers/lib_zrx_token';
|
||||
export * from '../generated-wrappers/mixin_stake';
|
||||
export * from '../generated-wrappers/mixin_vault_core';
|
||||
export * from '../generated-wrappers/reward_vault';
|
||||
export * from '../generated-wrappers/staking';
|
||||
export * from '../generated-wrappers/staking_proxy';
|
||||
export * from '../generated-wrappers/zrx_vault';
|
||||
|
@@ -550,7 +550,12 @@ describe('Staking Core', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it.only('Protocol Fees', async () => {
|
||||
it.only('Reward Vault', async () => {
|
||||
//
|
||||
//await stakingWrapper.depositForAsync()
|
||||
});
|
||||
|
||||
it('Protocol Fees', async () => {
|
||||
///// 0 DEPLOY EXCHANGE /////
|
||||
await stakingWrapper.addExchangeAddressAsync(exchange);
|
||||
///// 1 SETUP POOLS /////
|
||||
|
@@ -8,7 +8,7 @@ import { DummyERC20TokenContract } from '@0x/contracts-erc20';
|
||||
import { ERC20ProxyContract } from '@0x/contracts-asset-proxy';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { artifacts, StakingContract, StakingProxyContract, ZrxVaultContract, LibMathTestContract } from '../../src';
|
||||
import { artifacts, StakingContract, StakingProxyContract, ZrxVaultContract, RewardVaultContract, LibMathTestContract } from '../../src';
|
||||
|
||||
const expect = chai.expect;
|
||||
|
||||
@@ -22,6 +22,7 @@ export class StakingWrapper {
|
||||
private _stakingContractIfExists?: StakingContract;
|
||||
private _stakingProxyContractIfExists?: StakingProxyContract;
|
||||
private _zrxVaultContractIfExists?: ZrxVaultContract;
|
||||
private _rewardVaultContractIfExists?: RewardVaultContract;
|
||||
private _libMathTestContractIfExists?: LibMathTestContract;
|
||||
|
||||
constructor(provider: Provider, ownerAddres: string, erc20ProxyContract: ERC20ProxyContract, zrxTokenContract: DummyERC20TokenContract) {
|
||||
@@ -44,6 +45,10 @@ export class StakingWrapper {
|
||||
this._validateDeployedOrThrow();
|
||||
return this._zrxVaultContractIfExists as ZrxVaultContract;
|
||||
}
|
||||
public getRewardVaultContract(): RewardVaultContract {
|
||||
this._validateDeployedOrThrow();
|
||||
return this._rewardVaultContractIfExists as RewardVaultContract;
|
||||
}
|
||||
public getLibMathTestContract(): LibMathTestContract {
|
||||
this._validateDeployedOrThrow();
|
||||
return this._libMathTestContractIfExists as LibMathTestContract;
|
||||
@@ -86,6 +91,18 @@ export class StakingWrapper {
|
||||
await this._web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await this._web3Wrapper.sendTransactionAsync(setZrxVaultTxData)
|
||||
);
|
||||
// set reward vault in staking contract
|
||||
/*
|
||||
const setZrxVaultCalldata = await (this._stakingContractIfExists as StakingContract).setZrxVault.getABIEncodedTransactionData((this._zrxVaultContractIfExists as ZrxVaultContract).address);
|
||||
const setZrxVaultTxData = {
|
||||
from: this._ownerAddres,
|
||||
to: (this._stakingProxyContractIfExists as StakingProxyContract).address,
|
||||
data: setZrxVaultCalldata
|
||||
}
|
||||
await this._web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await this._web3Wrapper.sendTransactionAsync(setZrxVaultTxData)
|
||||
);
|
||||
*/
|
||||
// deploy libmath test
|
||||
this._libMathTestContractIfExists = await LibMathTestContract.deployFrom0xArtifactAsync(
|
||||
artifacts.LibMathTest,
|
||||
@@ -387,21 +404,41 @@ export class StakingWrapper {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///// REWARD VAULT /////
|
||||
public async depositRewardForAsync(poolId: string): Promise<BigNumber> {
|
||||
const balance = await this.getRewardVaultContract().balanceOf.callAsync(poolId);
|
||||
return balance;
|
||||
}
|
||||
public async withdrawRewardForAsync(poolId: string): Promise<BigNumber> {
|
||||
const balance = await this.getRewardVaultContract().balanceOf.callAsync(poolId);
|
||||
return balance;
|
||||
}
|
||||
public async withdrawAllRewardForAsync(poolId: string): Promise<BigNumber> {
|
||||
const balance = await this.getRewardVaultContract().balanceOf.callAsync(poolId);
|
||||
return balance;
|
||||
}
|
||||
public async getRewardBalanceInEthAsync(poolId: string): Promise<BigNumber> {
|
||||
const balance = await this.getRewardVaultContract().balanceOf.callAsync(poolId);
|
||||
return balance;
|
||||
}
|
||||
public async getEthBalanceOfRewardVaultAsync(): Promise<BigNumber> {
|
||||
const balance = await this.getRewardVaultContract().balanceOf.callAsync(this.getZrxVaultContract().address);
|
||||
return balance;
|
||||
}
|
||||
///// ZRX VAULT /////
|
||||
public async getZrxVaultBalance(holder: string): Promise<BigNumber> {
|
||||
const balance = await this.getZrxVaultContract().balanceOf.callAsync(holder);
|
||||
return balance;
|
||||
}
|
||||
public async getZrxTokenBalance(holder: string): Promise<BigNumber> {
|
||||
const balance = await this._zrxTokenContract.balanceOf.callAsync(holder);
|
||||
const balance = await this.getZrxVaultContract().balanceOf.callAsync(holder);
|
||||
return balance;
|
||||
}
|
||||
public async getZrxTokenBalanceOfZrxVault(): Promise<BigNumber> {
|
||||
const balance = await this._zrxTokenContract.balanceOf.callAsync(this.getZrxVaultContract().address);
|
||||
const balance = await this.getZrxVaultContract().balanceOf.callAsync(this.getZrxVaultContract().address);
|
||||
return balance;
|
||||
}
|
||||
///// MATH /////
|
||||
public async nthRoot(value: BigNumber, n: BigNumber): Promise<BigNumber> {
|
||||
//const txReceipt = await this.getLibMathTestContract().nthRoot.await(value, n);
|
||||
const output = await this.getLibMathTestContract().nthRoot.callAsync(value, n);
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"generated-artifacts/LibMathTest.json",
|
||||
"generated-artifacts/LibZrxToken.json",
|
||||
"generated-artifacts/MixinStake.json",
|
||||
"generated-artifacts/MixinVaultCore.json",
|
||||
"generated-artifacts/RewardVault.json",
|
||||
"generated-artifacts/Staking.json",
|
||||
"generated-artifacts/StakingProxy.json",
|
||||
"generated-artifacts/ZrxVault.json"
|
||||
|
Reference in New Issue
Block a user