From 11d5fec59bf41b34cee487c66ea936faab644d78 Mon Sep 17 00:00:00 2001 From: David Sun Date: Tue, 25 Jun 2019 10:55:53 -0700 Subject: [PATCH] changes on affiliate fee and other changes bumped version to 7 and added changelog updated package.json revert change to package.json trying this package.json config --- packages/asset-buyer/CHANGELOG.json | 9 ++++++++ packages/asset-buyer/src/swap_quoter.ts | 21 +++++++++---------- packages/asset-buyer/src/types.ts | 4 ++++ .../src/utils/affiliate_fee_utils.ts | 6 +++--- packages/instant/package.json | 2 +- yarn.lock | 18 ++++++++++++++++ 6 files changed, 45 insertions(+), 15 deletions(-) diff --git a/packages/asset-buyer/CHANGELOG.json b/packages/asset-buyer/CHANGELOG.json index 51e4f7e28a..c009b29c5f 100644 --- a/packages/asset-buyer/CHANGELOG.json +++ b/packages/asset-buyer/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "7.0.0", + "changes": [ + { + "note": "Add support for ERC<>ERC market buy support for asset-buyer and renamed to swap-quoter", + "pr": 1845 + } + ] + }, { "timestamp": 1558712885, "version": "6.1.5", diff --git a/packages/asset-buyer/src/swap_quoter.ts b/packages/asset-buyer/src/swap_quoter.ts index fdc4ad9eb8..8f611a47ff 100644 --- a/packages/asset-buyer/src/swap_quoter.ts +++ b/packages/asset-buyer/src/swap_quoter.ts @@ -81,6 +81,14 @@ export class SwapQuoter { const swapQuoter = new SwapQuoter(provider, orderProvider, options); return swapQuoter; } + + /** + * + * get the key for _orderEntryMap for maker + taker asset pair + */ + private static _getOrdersEntryMapKey(makerAssetData: string, takerAssetData: string): string { + return `${makerAssetData}_${takerAssetData}`; + } /** * Instantiates a new SwapQuoter instance * @param supportedProvider The Provider instance you would like to use for interacting with the Ethereum network. @@ -284,7 +292,7 @@ export class SwapQuoter { assetDataUtils.decodeAssetDataOrThrow(makerAssetData); assetDataUtils.decodeAssetDataOrThrow(takerAssetData); // try to get ordersEntry from the map - const ordersEntryIfExists = this._ordersEntryMap[this._getOrdersEntryMapKey(makerAssetData, takerAssetData)]; + const ordersEntryIfExists = this._ordersEntryMap[SwapQuoter._getOrdersEntryMapKey(makerAssetData, takerAssetData)]; // we should refresh if: // we do not have any orders OR // we are forced to OR @@ -324,19 +332,10 @@ export class SwapQuoter { ordersAndFillableAmounts, lastRefreshTime, }; - this._ordersEntryMap[this._getOrdersEntryMapKey(makerAssetData, takerAssetData)] = updatedOrdersEntry; + this._ordersEntryMap[SwapQuoter._getOrdersEntryMapKey(makerAssetData, takerAssetData)] = updatedOrdersEntry; return ordersAndFillableAmounts; } - /** - * - * get the key for _orderEntryMap for maker + taker asset pair - */ - // tslint:disable-next-line: prefer-function-over-method - private _getOrdersEntryMapKey(makerAssetData: string, takerAssetData: string): string { - return `${makerAssetData}_${takerAssetData}`; - } - /** * Get the assetData that represents the ZRX token. * Will throw if ZRX does not exist for the current network. diff --git a/packages/asset-buyer/src/types.ts b/packages/asset-buyer/src/types.ts index da0bb6872b..2c4612275a 100644 --- a/packages/asset-buyer/src/types.ts +++ b/packages/asset-buyer/src/types.ts @@ -156,6 +156,10 @@ export interface SwapQuote { worstCaseQuoteInfo: SwapQuoteInfo; } +export interface SwapQuoteWithAffiliateFee extends SwapQuote { + feePercentage: number; +} + /** * assetEthAmount: The amount of eth required to pay for the requested asset. * feeEthAmount: The amount of eth required to pay any fee concerned with completing the swap. diff --git a/packages/asset-buyer/src/utils/affiliate_fee_utils.ts b/packages/asset-buyer/src/utils/affiliate_fee_utils.ts index fcb1b3af32..7276a8dd92 100644 --- a/packages/asset-buyer/src/utils/affiliate_fee_utils.ts +++ b/packages/asset-buyer/src/utils/affiliate_fee_utils.ts @@ -1,14 +1,14 @@ import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; -import { SwapQuote, SwapQuoteInfo } from '../types'; +import { SwapQuote, SwapQuoteInfo, SwapQuoteWithAffiliateFee } from '../types'; export const affiliateFeeUtils = { - getSwapQuoteWithAffiliateFee(quote: SwapQuote, feePercentage: number): SwapQuote { + getSwapQuoteWithAffiliateFee(quote: SwapQuote, feePercentage: number): SwapQuoteWithAffiliateFee { const newQuote = _.clone(quote); newQuote.bestCaseQuoteInfo = getSwapQuoteInfoWithAffiliateFee(newQuote.bestCaseQuoteInfo, feePercentage); newQuote.worstCaseQuoteInfo = getSwapQuoteInfoWithAffiliateFee(newQuote.worstCaseQuoteInfo, feePercentage); - return newQuote; + return { ...newQuote, ...{ feePercentage } }; }, }; diff --git a/packages/instant/package.json b/packages/instant/package.json index e6e8cc9398..570fe37209 100644 --- a/packages/instant/package.json +++ b/packages/instant/package.json @@ -44,7 +44,7 @@ "homepage": "https://github.com/0xProject/0x-monorepo/packages/instant/README.md", "dependencies": { "@0x/assert": "^2.0.10", - "@0x/asset-buyer": "6.1.5", + "@0x/asset-buyer": "6.1.4", "@0x/json-schemas": "^3.0.10", "@0x/order-utils": "^8.1.1", "@0x/subproviders": "^4.1.0", diff --git a/yarn.lock b/yarn.lock index 3ebf7d1857..ad438de4be 100644 --- a/yarn.lock +++ b/yarn.lock @@ -478,6 +478,24 @@ dependencies: "@0x/base-contract" "^4.0.3" +"@0x/asset-buyer@6.1.5", "@0x/asset-buyer@^6.1.5": + version "6.1.5" + resolved "https://registry.yarnpkg.com/@0x/asset-buyer/-/asset-buyer-6.1.5.tgz#bf2056ccd9e749034d993c4de259d2f1b572421e" + integrity sha512-8e2OTSEacyWnWiYtchKHeQ3mYq912dd8OL46Wekt7DMNYx85R1ExTHaTgoKEQAe4EDsETW41yBPT6DLXwMI/Tw== + dependencies: + "@0x/assert" "^2.0.10" + "@0x/connect" "^5.0.10" + "@0x/contract-wrappers" "^9.1.4" + "@0x/json-schemas" "^3.0.10" + "@0x/order-utils" "^8.1.1" + "@0x/subproviders" "^4.1.0" + "@0x/types" "^2.2.2" + "@0x/typescript-typings" "^4.2.2" + "@0x/utils" "^4.3.3" + "@0x/web3-wrapper" "^6.0.6" + ethereum-types "^2.1.2" + lodash "^4.17.11" + "@0x/base-contract@^4.0.1", "@0x/base-contract@^4.0.3": version "4.0.3" resolved "https://registry.yarnpkg.com/@0x/base-contract/-/base-contract-4.0.3.tgz#ea5e3640824ee096813350e55546d98455a57805"