Minor documentation updates to dutch auction wrapper
This commit is contained in:
parent
61a3368826
commit
77a2ca1ddc
@ -3,7 +3,7 @@
|
|||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
"changes": [
|
"changes": [
|
||||||
{
|
{
|
||||||
"note": "Added entries for Dutch Auction contract",
|
"note": "Added testnet entries for Dutch Auction contract (kovan,rinkeby,ropsten)",
|
||||||
"pr": 1465
|
"pr": 1465
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -47,9 +47,9 @@ export class DutchAuctionWrapper extends ContractWrapper {
|
|||||||
return dutchAuctionData;
|
return dutchAuctionData;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Dutch auction details are encoded with the asset data for a 0x order. This function produces a hex
|
* Dutch auction details are encoded with the asset data for a 0x order. This function decodes a hex
|
||||||
* encoded assetData string, containing information both about the asset being traded and the
|
* encoded assetData string, containing information both about the asset being traded and the
|
||||||
* dutch auction; which is usable in the makerAssetData or takerAssetData fields in a 0x order.
|
* dutch auction.
|
||||||
* @param dutchAuctionData Hex encoded assetData string for the asset being auctioned.
|
* @param dutchAuctionData Hex encoded assetData string for the asset being auctioned.
|
||||||
* @return An object containing the auction asset, auction begin time and auction begin amount.
|
* @return An object containing the auction asset, auction begin time and auction begin amount.
|
||||||
*/
|
*/
|
||||||
@ -97,8 +97,9 @@ export class DutchAuctionWrapper extends ContractWrapper {
|
|||||||
* Over time the price moves from beginAmount to endAmount given the current block.timestamp.
|
* Over time the price moves from beginAmount to endAmount given the current block.timestamp.
|
||||||
* @param buyOrder The Buyer's order. This order is for the current expected price of the auction.
|
* @param buyOrder The Buyer's order. This order is for the current expected price of the auction.
|
||||||
* @param sellOrder The Seller's order. This order is for the lowest amount (at the end of the auction).
|
* @param sellOrder The Seller's order. This order is for the lowest amount (at the end of the auction).
|
||||||
* @param from Address the transaction is being sent from.
|
* @param takerAddress The user Ethereum address who would like to fill this order. Must be available via the supplied
|
||||||
* @return Transaction receipt with decoded logs.
|
* Provider provided at instantiation.
|
||||||
|
* @return Transaction hash.
|
||||||
*/
|
*/
|
||||||
public async matchOrdersAsync(
|
public async matchOrdersAsync(
|
||||||
buyOrder: SignedOrder,
|
buyOrder: SignedOrder,
|
||||||
@ -152,7 +153,7 @@ export class DutchAuctionWrapper extends ContractWrapper {
|
|||||||
return txHash;
|
return txHash;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Calculates the Auction Details for the given order
|
* Fetches the Auction Details for the given order
|
||||||
* @param sellOrder The Seller's order. This order is for the lowest amount (at the end of the auction).
|
* @param sellOrder The Seller's order. This order is for the lowest amount (at the end of the auction).
|
||||||
* @return The dutch auction details.
|
* @return The dutch auction details.
|
||||||
*/
|
*/
|
||||||
|
@ -21,7 +21,9 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
|||||||
|
|
||||||
// tslint:disable:custom-no-magic-numbers
|
// tslint:disable:custom-no-magic-numbers
|
||||||
describe('DutchAuctionWrapper', () => {
|
describe('DutchAuctionWrapper', () => {
|
||||||
const fillableAmount = new BigNumber(2);
|
const makerAssetAmount = new BigNumber(5);
|
||||||
|
const auctionEndTakerAmount = new BigNumber(10);
|
||||||
|
const auctionBeginTakerAmount = auctionEndTakerAmount.times(2);
|
||||||
const tenMinutesInSeconds = 10 * 60;
|
const tenMinutesInSeconds = 10 * 60;
|
||||||
let contractWrappers: ContractWrappers;
|
let contractWrappers: ContractWrappers;
|
||||||
let exchangeContractAddress: string;
|
let exchangeContractAddress: string;
|
||||||
@ -35,9 +37,7 @@ describe('DutchAuctionWrapper', () => {
|
|||||||
let makerTokenAssetData: string;
|
let makerTokenAssetData: string;
|
||||||
let takerTokenAssetData: string;
|
let takerTokenAssetData: string;
|
||||||
let auctionBeginTimeSeconds: BigNumber;
|
let auctionBeginTimeSeconds: BigNumber;
|
||||||
let auctionBeginAmount: BigNumber;
|
|
||||||
let auctionEndTimeSeconds: BigNumber;
|
let auctionEndTimeSeconds: BigNumber;
|
||||||
let auctionEndAmount: BigNumber;
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
// setup contract wrappers & addresses
|
// setup contract wrappers & addresses
|
||||||
const contractAddresses = await migrateOnceAsync();
|
const contractAddresses = await migrateOnceAsync();
|
||||||
@ -58,8 +58,6 @@ describe('DutchAuctionWrapper', () => {
|
|||||||
assetDataUtils.encodeERC20AssetData(takerTokenAddress),
|
assetDataUtils.encodeERC20AssetData(takerTokenAddress),
|
||||||
];
|
];
|
||||||
// setup auction details in maker asset data
|
// setup auction details in maker asset data
|
||||||
auctionEndAmount = fillableAmount;
|
|
||||||
auctionBeginAmount = auctionEndAmount.times(2);
|
|
||||||
const currentBlockTimestamp: number = await getLatestBlockTimestampAsync();
|
const currentBlockTimestamp: number = await getLatestBlockTimestampAsync();
|
||||||
auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds);
|
auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds);
|
||||||
auctionEndTimeSeconds = new BigNumber(currentBlockTimestamp + tenMinutesInSeconds);
|
auctionEndTimeSeconds = new BigNumber(currentBlockTimestamp + tenMinutesInSeconds);
|
||||||
@ -73,14 +71,14 @@ describe('DutchAuctionWrapper', () => {
|
|||||||
);
|
);
|
||||||
sellOrder = await dutchAuctionUtils.createSignedSellOrderAsync(
|
sellOrder = await dutchAuctionUtils.createSignedSellOrderAsync(
|
||||||
auctionBeginTimeSeconds,
|
auctionBeginTimeSeconds,
|
||||||
auctionBeginAmount,
|
|
||||||
auctionEndAmount,
|
|
||||||
auctionEndTimeSeconds,
|
auctionEndTimeSeconds,
|
||||||
|
auctionBeginTakerAmount,
|
||||||
|
auctionEndTakerAmount,
|
||||||
|
makerAssetAmount,
|
||||||
makerTokenAssetData,
|
makerTokenAssetData,
|
||||||
takerTokenAssetData,
|
takerTokenAssetData,
|
||||||
makerAddress,
|
makerAddress,
|
||||||
constants.NULL_ADDRESS,
|
constants.NULL_ADDRESS,
|
||||||
auctionEndAmount,
|
|
||||||
);
|
);
|
||||||
buyOrder = await dutchAuctionUtils.createSignedBuyOrderAsync(sellOrder, takerAddress);
|
buyOrder = await dutchAuctionUtils.createSignedBuyOrderAsync(sellOrder, takerAddress);
|
||||||
});
|
});
|
||||||
@ -119,7 +117,7 @@ describe('DutchAuctionWrapper', () => {
|
|||||||
expect(auctionDetails.beginTimeSeconds, 'auctionDetails.beginTimeSeconds').to.be.bignumber.equal(
|
expect(auctionDetails.beginTimeSeconds, 'auctionDetails.beginTimeSeconds').to.be.bignumber.equal(
|
||||||
auctionBeginTimeSeconds,
|
auctionBeginTimeSeconds,
|
||||||
);
|
);
|
||||||
expect(auctionDetails.beginAmount, 'auctionDetails.beginAmount').to.be.bignumber.equal(auctionBeginAmount);
|
expect(auctionDetails.beginAmount, 'auctionDetails.beginAmount').to.be.bignumber.equal(auctionBeginTakerAmount);
|
||||||
expect(auctionDetails.endTimeSeconds, 'auctionDetails.endTimeSeconds').to.be.bignumber.equal(
|
expect(auctionDetails.endTimeSeconds, 'auctionDetails.endTimeSeconds').to.be.bignumber.equal(
|
||||||
auctionEndTimeSeconds,
|
auctionEndTimeSeconds,
|
||||||
);
|
);
|
||||||
|
@ -24,31 +24,34 @@ export class DutchAuctionUtils {
|
|||||||
}
|
}
|
||||||
public async createSignedSellOrderAsync(
|
public async createSignedSellOrderAsync(
|
||||||
auctionBeginTimeSections: BigNumber,
|
auctionBeginTimeSections: BigNumber,
|
||||||
auctionBeginAmount: BigNumber,
|
acutionEndTimeSeconds: BigNumber,
|
||||||
auctionEndAmount: BigNumber,
|
auctionBeginTakerAssetAmount: BigNumber,
|
||||||
acutionEndTime: BigNumber,
|
auctionEndTakerAssetAmount: BigNumber,
|
||||||
|
makerAssetAmount: BigNumber,
|
||||||
makerAssetData: string,
|
makerAssetData: string,
|
||||||
takerAssetData: string,
|
takerAssetData: string,
|
||||||
makerAddress: string,
|
makerAddress: string,
|
||||||
takerAddress: string,
|
takerAddress: string,
|
||||||
takerFillableAmount: BigNumber,
|
|
||||||
senderAddress?: string,
|
senderAddress?: string,
|
||||||
makerFee?: BigNumber,
|
makerFee?: BigNumber,
|
||||||
takerFee?: BigNumber,
|
takerFee?: BigNumber,
|
||||||
feeRecipientAddress?: string,
|
feeRecipientAddress?: string,
|
||||||
): Promise<SignedOrder> {
|
): Promise<SignedOrder> {
|
||||||
const makerAssetAmount = auctionEndAmount;
|
// Notes on sell order:
|
||||||
|
// - The `takerAssetAmount` is set to the `auctionEndTakerAssetAmount`, which is the lowest amount the
|
||||||
|
// the seller can expect to receive
|
||||||
|
// - The `makerAssetData` is overloaded to include the auction begin time and begin taker asset amount
|
||||||
const makerAssetDataWithAuctionDetails = DutchAuctionWrapper.encodeDutchAuctionAssetData(
|
const makerAssetDataWithAuctionDetails = DutchAuctionWrapper.encodeDutchAuctionAssetData(
|
||||||
makerAssetData,
|
makerAssetData,
|
||||||
auctionBeginTimeSections,
|
auctionBeginTimeSections,
|
||||||
auctionBeginAmount,
|
auctionBeginTakerAssetAmount,
|
||||||
);
|
);
|
||||||
const signedOrder = await orderFactory.createSignedOrderAsync(
|
const signedOrder = await orderFactory.createSignedOrderAsync(
|
||||||
this._web3Wrapper.getProvider(),
|
this._web3Wrapper.getProvider(),
|
||||||
makerAddress,
|
makerAddress,
|
||||||
makerAssetAmount,
|
makerAssetAmount,
|
||||||
makerAssetDataWithAuctionDetails,
|
makerAssetDataWithAuctionDetails,
|
||||||
takerFillableAmount,
|
auctionEndTakerAssetAmount,
|
||||||
takerAssetData,
|
takerAssetData,
|
||||||
this._exchangeAddress,
|
this._exchangeAddress,
|
||||||
{
|
{
|
||||||
@ -57,7 +60,7 @@ export class DutchAuctionUtils {
|
|||||||
makerFee,
|
makerFee,
|
||||||
takerFee,
|
takerFee,
|
||||||
feeRecipientAddress,
|
feeRecipientAddress,
|
||||||
expirationTimeSeconds: acutionEndTime,
|
expirationTimeSeconds: acutionEndTimeSeconds,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
const erc20AssetData = assetDataUtils.decodeERC20AssetData(makerAssetData);
|
const erc20AssetData = assetDataUtils.decodeERC20AssetData(makerAssetData);
|
||||||
@ -71,8 +74,15 @@ export class DutchAuctionUtils {
|
|||||||
makerFee?: BigNumber,
|
makerFee?: BigNumber,
|
||||||
takerFee?: BigNumber,
|
takerFee?: BigNumber,
|
||||||
feeRecipientAddress?: string,
|
feeRecipientAddress?: string,
|
||||||
|
expirationTimeSeconds?: BigNumber,
|
||||||
): Promise<SignedOrder> {
|
): Promise<SignedOrder> {
|
||||||
const dutchAuctionData = DutchAuctionWrapper.decodeDutchAuctionData(sellOrder.makerAssetData);
|
const dutchAuctionData = DutchAuctionWrapper.decodeDutchAuctionData(sellOrder.makerAssetData);
|
||||||
|
// Notes on buy order:
|
||||||
|
// - The `makerAssetAmount` is set to `dutchAuctionData.beginAmount`, which is
|
||||||
|
// the highest amount the buyer would have to pay out at any point during the auction.
|
||||||
|
// - The `takerAssetAmount` is set to the seller's `makerAssetAmount`, as the buyer
|
||||||
|
// receives the entire amount being sold by the seller.
|
||||||
|
// - The `makerAssetData`/`takerAssetData` are reversed from the sell order
|
||||||
const signedOrder = await orderFactory.createSignedOrderAsync(
|
const signedOrder = await orderFactory.createSignedOrderAsync(
|
||||||
this._web3Wrapper.getProvider(),
|
this._web3Wrapper.getProvider(),
|
||||||
buyerAddress,
|
buyerAddress,
|
||||||
@ -86,7 +96,7 @@ export class DutchAuctionUtils {
|
|||||||
makerFee,
|
makerFee,
|
||||||
takerFee,
|
takerFee,
|
||||||
feeRecipientAddress,
|
feeRecipientAddress,
|
||||||
expirationTimeSeconds: sellOrder.expirationTimeSeconds,
|
expirationTimeSeconds,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
const buyerERC20AssetData = assetDataUtils.decodeERC20AssetData(sellOrder.takerAssetData);
|
const buyerERC20AssetData = assetDataUtils.decodeERC20AssetData(sellOrder.takerAssetData);
|
||||||
@ -135,7 +145,6 @@ export class DutchAuctionUtils {
|
|||||||
);
|
);
|
||||||
const oldMakerAllowance = await erc20Token.allowance.callAsync(address, this._erc20ProxyAddress);
|
const oldMakerAllowance = await erc20Token.allowance.callAsync(address, this._erc20ProxyAddress);
|
||||||
const newMakerAllowance = oldMakerAllowance.plus(amount);
|
const newMakerAllowance = oldMakerAllowance.plus(amount);
|
||||||
|
|
||||||
const txHash = await erc20Token.approve.sendTransactionAsync(this._erc20ProxyAddress, newMakerAllowance, {
|
const txHash = await erc20Token.approve.sendTransactionAsync(this._erc20ProxyAddress, newMakerAllowance, {
|
||||||
from: address,
|
from: address,
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user