Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Commit

Permalink
Renamed contracts. Added auction time increment constant.
Browse files Browse the repository at this point in the history
  • Loading branch information
bweick committed Sep 28, 2018
1 parent 071eb0e commit be1af07
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 26 deletions.
Expand Up @@ -23,7 +23,7 @@ pragma solidity 0.4.24;
* The IAuctionLibrary interface provides a structured way to interact with any AuctionLibrary
*/

interface IAuctionLibrary {
interface IAuctionPriceCurve {

/*
* Calculate the current priceRatio for an auction given defined price and time parameters
Expand Down
Expand Up @@ -19,15 +19,15 @@ pragma solidity 0.4.24;
import { SafeMath } from "zeppelin-solidity/contracts/math/SafeMath.sol";

/**
* @title LinearAuctionLibrary
* @title LinearAuctionPriceCurve
* @author Set Protocol
*
* Library used in rebalancing auctions to calculate price based off of a linear curve
* Contract used in rebalancing auctions to calculate price based off of a linear curve
*
*/


contract LinearAuctionLibrary {
contract LinearAuctionPriceCurve {
using SafeMath for uint256;

/*
Expand Down
Expand Up @@ -18,14 +18,14 @@ pragma solidity 0.4.24;


/**
* @title LinearAuctionLibrary
* @title ConstantAuctionPriceCurve
* @author Set Protocol
*
* Library used in rebalancing auctions to calculate price based off of a linear curve
* Contract used in rebalancing auctions to calculate price based off of a linear curve
*
*/

contract ConstantPriceAuctionLibrary {
contract ConstantAuctionPriceCurve {

uint256 public constantPrice;

Expand Down
Expand Up @@ -5,7 +5,7 @@ import * as setProtocolUtils from 'set-protocol-utils';
import { Address } from 'set-protocol-utils';
import { BigNumber } from 'bignumber.js';

import { LinearAuctionLibraryContract } from '@utils/contracts';
import { LinearAuctionPriceCurveContract } from '@utils/contracts';
import { Blockchain } from '@utils/blockchain';
import { ERC20Wrapper } from '@utils/erc20Wrapper';
import { CoreWrapper } from '@utils/coreWrapper';
Expand All @@ -26,7 +26,7 @@ contract('LinearAuctionLibrary', accounts => {
ownerAccount,
] = accounts;

let auctionLib: LinearAuctionLibraryContract;
let auctionCurve: LinearAuctionPriceCurveContract;

const coreWrapper = new CoreWrapper(ownerAccount, ownerAccount);
const erc20Wrapper = new ERC20Wrapper(ownerAccount);
Expand All @@ -40,14 +40,14 @@ contract('LinearAuctionLibrary', accounts => {

beforeEach(async () => {
blockchain.saveSnapshotAsync();
auctionLib = await coreWrapper.deployLinearAuctionLibraryAsync();
auctionCurve = await coreWrapper.deployLinearAuctionPriceCurveAsync();
});

afterEach(async () => {
blockchain.revertAsync();
});

describe('#getCurrentPrice', async () => {
describe.only('#getCurrentPrice', async () => {
let subjectAuctionStartTime: BigNumber;
let subjectAuctionStartPrice: BigNumber;
let subjectCurveCoefficient: BigNumber;
Expand All @@ -61,7 +61,7 @@ contract('LinearAuctionLibrary', accounts => {
});

async function subject(): Promise<BigNumber> {
return auctionLib.getCurrentPrice.callAsync(
return auctionCurve.getCurrentPrice.callAsync(
subjectAuctionStartTime,
subjectAuctionStartPrice,
subjectCurveCoefficient,
Expand Down
9 changes: 4 additions & 5 deletions utils/RebalancingTokenWrapper.ts
Expand Up @@ -16,7 +16,8 @@ import {
ONE_DAY_IN_SECONDS,
DEFAULT_UNIT_SHARES,
DEFAULT_REBALANCING_NATURAL_UNIT,
UNLIMITED_ALLOWANCE_IN_BASE_UNITS
UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
AUCTION_TIME_INCREMENT
} from './constants';

import { CoreWrapper } from './coreWrapper';
Expand Down Expand Up @@ -265,14 +266,12 @@ export class RebalancingTokenWrapper {
return {unitShares, issueAmount};
}

public getExpectedLinearAuctionPrice(
public getExpectedLinearAuctionPrice(
elapsedTime: BigNumber,
curveCoefficient: BigNumber,
auctionStartPrice: BigNumber
): BigNumber {
const contractTimeIncrement = new BigNumber(30);

const elaspedTimeFromStart = elapsedTime.div(contractTimeIncrement).round(0, 3);
const elaspedTimeFromStart = elapsedTime.div(AUCTION_TIME_INCREMENT).round(0, 3);
const expectedPrice = curveCoefficient.mul(elaspedTimeFromStart).add(auctionStartPrice);
return expectedPrice;
}
Expand Down
1 change: 1 addition & 0 deletions utils/constants.ts
Expand Up @@ -13,6 +13,7 @@ export const STANDARD_NATURAL_UNIT = ether(1);
export const STANDARD_QUANTITY_ISSUED: BigNumber = ether(10);
export const UNLIMITED_ALLOWANCE_IN_BASE_UNITS = new BigNumber(2).pow(256).minus(1);
export const ZERO: BigNumber = new BigNumber(0);
export const AUCTION_TIME_INCREMENT = new BigNumber(30);

export const PRIVATE_KEYS = [
'767df558efc63b6ba9a9257e68509c38f5c48d5938a41ab191a9a073ebff7c4f',
Expand Down
4 changes: 2 additions & 2 deletions utils/contracts.ts
Expand Up @@ -10,7 +10,7 @@ import { DetailedERC20Contract } from '../types/generated/detailed_erc20';
import { ERC20WrapperMockContract } from '../types/generated/erc20_wrapper_mock';
import { InvalidReturnTokenMockContract } from '../types/generated/invalid_return_token_mock';
import { KyberNetworkWrapperContract } from '../types/generated/kyber_network_wrapper';
import { LinearAuctionLibraryContract } from '../types/generated/linear_auction_library';
import { LinearAuctionPriceCurveContract } from '../types/generated/linear_auction_price_curve';
import { NoDecimalTokenMockContract } from '../types/generated/no_decimal_token_mock';
import { NoXferReturnTokenMockContract } from '../types/generated/no_xfer_return_token_mock';
import { OrderLibraryMockContract } from '../types/generated/order_library_mock';
Expand Down Expand Up @@ -38,7 +38,7 @@ export {
ERC20WrapperMockContract,
InvalidReturnTokenMockContract,
KyberNetworkWrapperContract,
LinearAuctionLibraryContract,
LinearAuctionPriceCurveContract,
NoDecimalTokenMockContract,
NoXferReturnTokenMockContract,
OrderLibraryMockContract,
Expand Down
14 changes: 7 additions & 7 deletions utils/coreWrapper.ts
Expand Up @@ -6,7 +6,7 @@ import {
AuthorizableContract,
CoreContract,
CoreMockContract,
LinearAuctionLibraryContract,
LinearAuctionPriceCurveContract,
OrderLibraryMockContract,
SetTokenContract,
RebalancingSetTokenContract,
Expand All @@ -23,7 +23,7 @@ const Authorizable = artifacts.require('Authorizable');
const Core = artifacts.require('Core');
const CoreMock = artifacts.require('CoreMock');
const ERC20Wrapper = artifacts.require('ERC20Wrapper');
const LinearAuctionLibrary = artifacts.require('LinearAuctionLibrary');
const LinearAuctionPriceCurve = artifacts.require('LinearAuctionPriceCurve');
const OrderLibrary = artifacts.require('OrderLibrary');
const OrderLibraryMock = artifacts.require('OrderLibraryMock');
const RebalancingSetToken = artifacts.require('RebalancingSetToken');
Expand Down Expand Up @@ -151,15 +151,15 @@ export class CoreWrapper {
);
}

public async deployLinearAuctionLibraryAsync(
public async deployLinearAuctionPriceCurveAsync(
from: Address = this._tokenOwnerAddress
): Promise<LinearAuctionLibraryContract> {
const truffleLinearAuctionLibrary = await LinearAuctionLibrary.new(
): Promise<LinearAuctionPriceCurveContract> {
const truffleLinearAuctionPriceCurve = await LinearAuctionPriceCurve.new(
{ from },
);

return new LinearAuctionLibraryContract(
web3.eth.contract(truffleLinearAuctionLibrary.abi).at(truffleLinearAuctionLibrary.address),
return new LinearAuctionPriceCurveContract(
web3.eth.contract(truffleLinearAuctionPriceCurve.abi).at(truffleLinearAuctionPriceCurve.address),
{ from, gas: DEFAULT_GAS },
);
}
Expand Down

0 comments on commit be1af07

Please sign in to comment.