Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
@0x/asset-swapper: Rebase against development and pay protocol fees.
Browse files Browse the repository at this point in the history
  • Loading branch information
dorothy-zbornak committed Nov 18, 2019
1 parent 1252045 commit c3a4b7e
Show file tree
Hide file tree
Showing 41 changed files with 5,566 additions and 3,059 deletions.
15 changes: 14 additions & 1 deletion packages/asset-swapper/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
[
{
"version": "2.1.0-beta.3",
"changes": [
{
"note": "Refactor of logic for marketBuy/marketSell order pruning and selecting, introduced protocol fees, and refactored types used by the package",
"pr": 2272
},
{
"note": "Incorporate paying protocol fees.",
"pr": "TODO"
}
]
},
{
"version": "2.1.0-beta.2",
"changes": [
Expand All @@ -7,7 +20,7 @@
"pr": 2342
}
],
"timestamp": 1574030254
"timestamp": 1573159180
},
{
"version": "2.1.0-beta.1",
Expand Down
4 changes: 0 additions & 4 deletions packages/asset-swapper/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ Edit the package's CHANGELOG.json file only.

CHANGELOG

## v2.1.0-beta.2 - _November 17, 2019_

* Update BigNumber version to ~9.0.0 (#2342)

## v2.1.0-beta.1 - _November 7, 2019_

* All references to network ID have been removed, and references to chain ID have been introduced instead (#2313)
Expand Down
1,305 changes: 599 additions & 706 deletions packages/asset-swapper/docs/reference.mdx

Large diffs are not rendered by default.

1,839 changes: 1,839 additions & 0 deletions packages/asset-swapper/package-lock.json

Large diffs are not rendered by default.

38 changes: 20 additions & 18 deletions packages/asset-swapper/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@0x/asset-swapper",
"version": "2.1.0-beta.2",
"version": "2.1.0-beta.1",
"engines": {
"node": ">=6.12"
},
Expand Down Expand Up @@ -40,28 +40,30 @@
},
"homepage": "https://0x.org/asset-swapper",
"dependencies": {
"@0x/assert": "^2.2.0-beta.2",
"@0x/connect": "^5.1.0-beta.2",
"@0x/contract-addresses": "^3.3.0-beta.3",
"@0x/contract-wrappers": "^12.2.0-beta.2",
"@0x/dev-utils": "^2.4.0-beta.2",
"@0x/json-schemas": "^4.1.0-beta.2",
"@0x/migrations": "^4.4.0-beta.2",
"@0x/order-utils": "^8.5.0-beta.2",
"@0x/orderbook": "^0.1.0-beta.2",
"@0x/subproviders": "^5.1.0-beta.2",
"@0x/types": "^2.5.0-beta.2",
"@0x/typescript-typings": "^4.4.0-beta.2",
"@0x/utils": "^4.6.0-beta.2",
"@0x/web3-wrapper": "^6.1.0-beta.2",
"ethereum-types": "^2.2.0-beta.2",
"@0x/assert": "^2.2.0-beta.1",
"@0x/contracts-dev-utils": "^0.1.0-beta.1",
"@0x/contracts-erc20": "^2.3.0-beta.1",
"@0x/contracts-exchange": "^2.2.0-beta.1",
"@0x/contracts-exchange-forwarder": "^3.1.0-beta.1",
"@0x/json-schemas": "^4.1.0-beta.1",
"@0x/order-utils": "^8.5.0-beta.1",
"@0x/orderbook": "^0.1.0-beta.1",
"@0x/types": "^2.5.0-beta.1",
"@0x/utils": "^4.6.0-beta.1",
"@0x/web3-wrapper": "^6.1.0-beta.1",
"ethereum-types": "^2.2.0-beta.1",
"lodash": "^4.17.11"
},
"devDependencies": {
"@0x/contracts-test-utils": "^3.2.0-beta.2",
"@0x/contract-addresses": "^3.3.0-beta.2",
"@0x/contracts-test-utils": "^3.2.0-beta.1",
"@0x/dev-utils": "^2.4.0-beta.1",
"@0x/mesh-rpc-client": "^7.0.3-beta-0xv3",
"@0x/migrations": "^4.4.0-beta.1",
"@0x/subproviders": "^5.1.0-beta.1",
"@0x/ts-doc-gen": "^0.0.22",
"@0x/tslint-config": "^3.1.0-beta.2",
"@0x/tslint-config": "^3.1.0-beta.1",
"@0x/typescript-typings": "^4.4.0-beta.1",
"@types/lodash": "4.14.104",
"@types/mocha": "^5.2.7",
"@types/node": "*",
Expand Down
45 changes: 29 additions & 16 deletions packages/asset-swapper/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,68 @@
import { SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';

import {
ForwarderSwapQuoteExecutionOpts,
ForwarderSwapQuoteGetOutputOpts,
OrdersAndFillableAmounts,
ForwarderExtensionContractOpts,
OrderPrunerOpts,
OrderPrunerPermittedFeeTypes,
SwapQuoteExecutionOpts,
SwapQuoteGetOutputOpts,
SwapQuoteRequestOpts,
SwapQuoterOpts,
} from './types';

const ETH_GAS_STATION_API_BASE_URL = 'https://ethgasstation.info';
const NULL_BYTES = '0x';
const NULL_ERC20_ASSET_DATA = '0xf47261b00000000000000000000000000000000000000000000000000000000000000000';
const NULL_ADDRESS = '0x0000000000000000000000000000000000000000';
const MAINNET_CHAIN_ID = 1;
const ONE_SECOND_MS = 1000;
const DEFAULT_PER_PAGE = 1000;
const PROTOCOL_FEE_MULTIPLIER = 150000;

const DEFAULT_SWAP_QUOTER_OPTS: SwapQuoterOpts = {
chainId: MAINNET_CHAIN_ID,
orderRefreshIntervalMs: 10000, // 10 seconds
const DEFAULT_ORDER_PRUNER_OPTS: OrderPrunerOpts = {
expiryBufferMs: 120000, // 2 minutes
permittedOrderFeeTypes: new Set<OrderPrunerPermittedFeeTypes>([
OrderPrunerPermittedFeeTypes.NoFees,
OrderPrunerPermittedFeeTypes.MakerDenominatedTakerFee,
]), // Default asset-swapper for CFL oriented fee types
};

const DEFAULT_SWAP_QUOTER_OPTS: SwapQuoterOpts = {
...{
chainId: MAINNET_CHAIN_ID,
orderRefreshIntervalMs: 10000, // 10 seconds
},
...DEFAULT_ORDER_PRUNER_OPTS,
};

const DEFAULT_FORWARDER_SWAP_QUOTE_GET_OPTS: ForwarderSwapQuoteGetOutputOpts = {
const DEFAULT_FORWARDER_SWAP_QUOTE_GET_OPTS: SwapQuoteGetOutputOpts & ForwarderExtensionContractOpts = {
feePercentage: 0,
feeRecipient: NULL_ADDRESS,
};

const DEFAULT_FORWARDER_SWAP_QUOTE_EXECUTE_OPTS: ForwarderSwapQuoteExecutionOpts = DEFAULT_FORWARDER_SWAP_QUOTE_GET_OPTS;
const DEFAULT_FORWARDER_SWAP_QUOTE_EXECUTE_OPTS: SwapQuoteExecutionOpts &
ForwarderExtensionContractOpts = DEFAULT_FORWARDER_SWAP_QUOTE_GET_OPTS;

const DEFAULT_SWAP_QUOTE_REQUEST_OPTS: SwapQuoteRequestOpts = {
shouldDisableRequestingFeeOrders: false,
slippagePercentage: 0.2, // 20% slippage protection,
};

const EMPTY_ORDERS_AND_FILLABLE_AMOUNTS: OrdersAndFillableAmounts = {
orders: [] as SignedOrder[],
remainingFillableMakerAssetAmounts: [] as BigNumber[],
};

export const constants = {
ETH_GAS_STATION_API_BASE_URL,
NULL_BYTES,
ZERO_AMOUNT: new BigNumber(0),
NULL_ADDRESS,
MAINNET_CHAIN_ID,
DEFAULT_ORDER_PRUNER_OPTS,
ETHER_TOKEN_DECIMALS: 18,
ONE_AMOUNT: new BigNumber(1),
MAX_AFFILIATE_FEE_PERCENTAGE: 0.05,
ONE_SECOND_MS,
DEFAULT_SWAP_QUOTER_OPTS,
DEFAULT_FORWARDER_SWAP_QUOTE_GET_OPTS,
DEFAULT_FORWARDER_SWAP_QUOTE_EXECUTE_OPTS,
DEFAULT_SWAP_QUOTE_REQUEST_OPTS,
EMPTY_ORDERS_AND_FILLABLE_AMOUNTS,
DEFAULT_PER_PAGE,
PROTOCOL_FEE_MULTIPLIER,
NULL_ERC20_ASSET_DATA,
};
15 changes: 6 additions & 9 deletions packages/asset-swapper/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ export {
ConstructorStateMutability,
} from 'ethereum-types';

export { SignedOrder, AssetPairsItem, APIOrder, Asset } from '@0x/types';
export { SignedOrder, AssetPairsItem, APIOrder, Asset, Order } from '@0x/types';
export { BigNumber } from '@0x/utils';

export { SwapQuoteConsumer } from './quote_consumers/swap_quote_consumer';
export { SwapQuoter } from './swap_quoter';
export { protocolFeeUtils } from './utils/protocol_fee_utils';
export { affiliateFeeUtils } from './utils/affiliate_fee_utils';
export { InsufficientAssetLiquidityError } from './errors';

export {
Expand All @@ -34,21 +36,16 @@ export {
SwapQuoteConsumerOpts,
CalldataInfo,
ExtensionContractType,
SwapQuoteConsumingOpts,
LiquidityForTakerMakerAssetDataPair,
SwapQuoteGetOutputOpts,
PrunedSignedOrder,
SwapQuoteExecutionOpts,
SwapQuoteInfo,
GetExtensionContractTypeOpts,
SwapQuoteExecutionOptsBase,
SwapQuoteGetOutputOptsBase,
ForwarderSwapQuoteExecutionOpts,
ForwarderSwapQuoteGetOutputOpts,
SmartContractParamsInfo,
MarketBuySwapQuote,
MarketSellSwapQuote,
MarketBuySwapQuoteWithAffiliateFee,
MarketSellSwapQuoteWithAffiliateFee,
LiquidityForAssetData,
OrdersAndFillableAmounts,
SwapQuoteConsumerBase,
SwapQuoteRequestOpts,
} from './types';
Expand Down
Loading

0 comments on commit c3a4b7e

Please sign in to comment.