diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-12-20 08:08:59 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2019-01-08 07:50:48 +0800 |
commit | c850046ea0b302f61a5fd24f77bab19784a2adc0 (patch) | |
tree | 34157fa6fb1006c080d42ba3b9c7b8ceb1fb691c /contracts/extensions/test/utils | |
parent | 7dda953bc929e218121c331fedb3884b24555855 (diff) | |
download | dexon-0x-contracts-c850046ea0b302f61a5fd24f77bab19784a2adc0.tar.gz dexon-0x-contracts-c850046ea0b302f61a5fd24f77bab19784a2adc0.tar.zst dexon-0x-contracts-c850046ea0b302f61a5fd24f77bab19784a2adc0.zip |
Dutch Auction Contract Wrapper
Diffstat (limited to 'contracts/extensions/test/utils')
-rw-r--r-- | contracts/extensions/test/utils/dutch_auction_wrapper.ts | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/contracts/extensions/test/utils/dutch_auction_wrapper.ts b/contracts/extensions/test/utils/dutch_auction_wrapper.ts new file mode 100644 index 000000000..138b40ca9 --- /dev/null +++ b/contracts/extensions/test/utils/dutch_auction_wrapper.ts @@ -0,0 +1,62 @@ +import { artifacts as protocolArtifacts } from '@0x/contracts-protocol'; +import { LogDecoder } from '@0x/contracts-test-utils'; +import { artifacts as tokensArtifacts } from '@0x/contracts-tokens'; +import { DutchAuctionDetails, SignedOrder } from '@0x/types'; +import { Web3Wrapper } from '@0x/web3-wrapper'; +import { Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; +import * as _ from 'lodash'; + +import { DutchAuctionContract } from '../../generated-wrappers/dutch_auction'; +import { artifacts } from '../../src/artifacts'; + +export class DutchAuctionWrapper { + private readonly _dutchAuctionContract: DutchAuctionContract; + private readonly _web3Wrapper: Web3Wrapper; + private readonly _logDecoder: LogDecoder; + + constructor(contractInstance: DutchAuctionContract, provider: Provider) { + this._dutchAuctionContract = contractInstance; + this._web3Wrapper = new Web3Wrapper(provider); + this._logDecoder = new LogDecoder(this._web3Wrapper, { + ...artifacts, + ...tokensArtifacts, + ...protocolArtifacts, + }); + } + /** + * Matches the buy and sell orders at an amount given the following: the current block time, the auction + * start time and the auction begin amount. The sell order is a an order at the lowest amount + * at the end of the auction. Excess from the match is transferred to the seller. + * 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 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. + * @return Transaction receipt with decoded logs. + */ + public async matchOrdersAsync( + buyOrder: SignedOrder, + sellOrder: SignedOrder, + from: string, + ): Promise<TransactionReceiptWithDecodedLogs> { + const txHash = await this._dutchAuctionContract.matchOrders.sendTransactionAsync( + buyOrder, + sellOrder, + buyOrder.signature, + sellOrder.signature, + { + from, + }, + ); + const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash); + return tx; + } + /** + * Calculates 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). + * @return The dutch auction details. + */ + public async getAuctionDetailsAsync(sellOrder: SignedOrder): Promise<DutchAuctionDetails> { + const afterAuctionDetails = await this._dutchAuctionContract.getAuctionDetails.callAsync(sellOrder); + return afterAuctionDetails; + } +} |