aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contract-wrappers/src
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-12-21 11:40:16 +0800
committerGreg Hysen <greg.hysen@gmail.com>2019-01-08 07:50:48 +0800
commit5da748a062043b46133a2dbce248a756bbefce12 (patch)
treecfb15848673ed4347dfc87dd5cca941aa49f2060 /packages/contract-wrappers/src
parent09afee55ed4afc9ff41ecaf7417e4c8761bb8f87 (diff)
downloaddexon-sol-tools-5da748a062043b46133a2dbce248a756bbefce12.tar
dexon-sol-tools-5da748a062043b46133a2dbce248a756bbefce12.tar.gz
dexon-sol-tools-5da748a062043b46133a2dbce248a756bbefce12.tar.bz2
dexon-sol-tools-5da748a062043b46133a2dbce248a756bbefce12.tar.lz
dexon-sol-tools-5da748a062043b46133a2dbce248a756bbefce12.tar.xz
dexon-sol-tools-5da748a062043b46133a2dbce248a756bbefce12.tar.zst
dexon-sol-tools-5da748a062043b46133a2dbce248a756bbefce12.zip
Progress on dutch auction wrapper. Need to add auction data decoding to it.
Diffstat (limited to 'packages/contract-wrappers/src')
-rw-r--r--packages/contract-wrappers/src/contract_wrappers.ts2
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts74
2 files changed, 73 insertions, 3 deletions
diff --git a/packages/contract-wrappers/src/contract_wrappers.ts b/packages/contract-wrappers/src/contract_wrappers.ts
index 396505866..3728d58d3 100644
--- a/packages/contract-wrappers/src/contract_wrappers.ts
+++ b/packages/contract-wrappers/src/contract_wrappers.ts
@@ -149,7 +149,7 @@ export class ContractWrappers {
this.dutchAuction = new DutchAuctionWrapper(
this._web3Wrapper,
config.networkId,
- contractAddresses.orderValidator,
+ contractAddresses.dutchAuction,
);
}
/**
diff --git a/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts
index 500e7a63d..fee543c3b 100644
--- a/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts
@@ -21,9 +21,13 @@ import { OrderTransactionOpts } from '../types';
import { ContractWrapper } from './contract_wrapper';
import { ExchangeWrapperError } from '../types';
+import { orderFactory } from '@0x/order-utils/lib/src/order_factory';
+import { constants } from 'zlib';
+
export class DutchAuctionWrapper extends ContractWrapper {
public abi: ContractAbi = DutchAuction.compilerOutput.abi;
public address: string;
+ private _exchangeAddress: string;
private _dutchAuctionContractIfExists?: DutchAuctionContract;
/**
* Instantiate DutchAuctionWrapper
@@ -35,10 +39,12 @@ export class DutchAuctionWrapper extends ContractWrapper {
constructor(
web3Wrapper: Web3Wrapper,
networkId: number,
- address: string,
+ address?: string,
+ exchangeAddress?: string,
) {
super(web3Wrapper, networkId);
- this.address = address;
+ this.address = this.address = _.isUndefined(address) ? _getDefaultContractAddresses(networkId).dutchAuction : address;
+ this._exchangeAddress = _.isUndefined(exchangeAddress) ? _getDefaultContractAddresses(networkId).exchange : exchangeAddress;
}
/**
* Matches the buy and sell orders at an amount given the following: the current block time, the auction
@@ -110,6 +116,8 @@ export class DutchAuctionWrapper extends ContractWrapper {
// type assertions
assert.doesConformToSchema('sellOrder', sellOrder, schemas.signedOrderSchema);
// get contract
+ console.log(sellOrder);
+ console.log(await this._getDutchAuctionContractAsync());
const dutchAuctionInstance = await this._getDutchAuctionContractAsync();
// call contract
const afterAuctionDetails = await dutchAuctionInstance.getAuctionDetails.callAsync(sellOrder);
@@ -128,6 +136,66 @@ export class DutchAuctionWrapper extends ContractWrapper {
this._dutchAuctionContractIfExists = contractInstance;
return this._dutchAuctionContractIfExists;
}
+
+ public async createSignedSellOrderAsync(
+ auctionBeginTimeSections: BigNumber,
+ auctionBeginAmount: BigNumber,
+ auctionEndAmount: BigNumber,
+ acutionEndTime: BigNumber,
+ makerAssetData: string,
+ takerAssetData: string,
+ makerAddress: string,
+ takerAddress: string,
+ takerFillableAmount: BigNumber,
+ senderAddress?: string,
+ makerFee?: BigNumber,
+ takerFee?: BigNumber,
+ feeRecipientAddress?: string,
+ ): Promise<SignedOrder> {
+ console.log(`asdasd`);
+ const makerAssetAmount = auctionEndAmount;
+ const makerAssetDataWithAuctionDetails = DutchAuctionWrapper.encodeDutchAuctionAssetData(makerAssetData, auctionBeginTimeSections, auctionBeginAmount);
+ const signedOrder = await orderFactory.createSignedOrderAsync(
+ this._web3Wrapper.getProvider(),
+ makerAddress,
+ makerAssetAmount,
+ makerAssetDataWithAuctionDetails,
+ takerFillableAmount,
+ takerAssetData,
+ this._exchangeAddress,
+ {
+ takerAddress,
+ senderAddress,
+ makerFee,
+ takerFee,
+ feeRecipientAddress,
+ expirationTimeSeconds: acutionEndTime,
+ },
+ );
+ //console.log(signedOrder);
+ return signedOrder;
+ }
+
+ public async createSignedBuyOrderAsync(sellOrder: SignedOrder, buyerAddress: string, senderAddress?: string, makerFee?: BigNumber, takerFee?: BigNumber, feeRecipientAddress?: string): Promise<SignedOrder> {
+ const signedOrder = await orderFactory.createSignedOrderAsync(
+ this._web3Wrapper.getProvider(),
+ buyerAddress,
+ sellOrder.takerAssetAmount.times(2), // change this to decode value from auction @TODO -- add decode above for this.
+ sellOrder.takerAssetData,
+ sellOrder.makerAssetAmount,
+ sellOrder.makerAssetData,
+ sellOrder.exchangeAddress,
+ {
+ senderAddress,
+ makerFee,
+ takerFee,
+ feeRecipientAddress,
+ expirationTimeSeconds: sellOrder.expirationTimeSeconds,
+ },
+ );
+ // console.log(signedOrder);
+ return signedOrder;
+ }
/**
* Dutch auction details are encoded with the asset data for a 0x order. This function produces a hex
* encoded assetData string, containing information both about the asset being traded and the
@@ -138,6 +206,7 @@ export class DutchAuctionWrapper extends ContractWrapper {
* @return The hex encoded assetData string.
*/
public static encodeDutchAuctionAssetData(assetData: string, beginTimeSeconds: BigNumber, beginAmount: BigNumber): string {
+ // console.log(`yoooo`, assetData);
const assetDataBuffer = ethUtil.toBuffer(assetData);
const abiEncodedAuctionData = (ethAbi as any).rawEncode(
['uint256', 'uint256'],
@@ -145,6 +214,7 @@ export class DutchAuctionWrapper extends ContractWrapper {
);
const abiEncodedAuctionDataBuffer = ethUtil.toBuffer(abiEncodedAuctionData);
const dutchAuctionDataBuffer = Buffer.concat([assetDataBuffer, abiEncodedAuctionDataBuffer]);
+ // console.log(`GREFG --- `, abiEncodedAuctionData);
const dutchAuctionData = ethUtil.bufferToHex(dutchAuctionDataBuffer);
return dutchAuctionData;
};