Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Commit 78b9e2a

Browse files
committed
Update packages, disable DutchAuction
1 parent 94ea1e8 commit 78b9e2a

File tree

6 files changed

+218
-234
lines changed

6 files changed

+218
-234
lines changed

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"version": "0.3.0",
44
"private": true,
55
"dependencies": {
6-
"@0x/connect": "^5.1.0-beta.2",
7-
"@0x/contract-wrappers": "^12.2.0-beta.3",
8-
"@0x/order-utils": "^8.5.0-beta.3",
9-
"@0x/orderbook": "^0.1.0-beta.3",
10-
"@0x/subproviders": "^5.1.0-beta.2",
11-
"@0x/utils": "^4.6.0-beta.2",
12-
"@0x/web3-wrapper": "^6.1.0-beta.2",
6+
"@0x/connect": "^6.0.0",
7+
"@0x/contract-wrappers": "^13.0.0",
8+
"@0x/order-utils": "^9.0.0",
9+
"@0x/orderbook": "^1.0.0",
10+
"@0x/subproviders": "^6.0.0",
11+
"@0x/utils": "^5.0.0",
12+
"@0x/web3-wrapper": "^7.0.0",
1313
"async-retry": "^1.2.3",
1414
"async-sema": "^3.0.0",
1515
"connected-react-router": "^6.2.2",
@@ -72,8 +72,8 @@
7272
"not op_mini all"
7373
],
7474
"devDependencies": {
75-
"@0x/tslint-config": "^3.0.1",
76-
"@0x/types": "^2.5.0-beta.2",
75+
"@0x/tslint-config": "^4.0.0",
76+
"@0x/types": "^3.0.0",
7777
"@types/async-retry": "^1.4.1",
7878
"@types/enzyme": "^3.1.15",
7979
"@types/enzyme-adapter-react-16": "^1.0.3",

src/components/erc721/marketplace/dutch_auction_price_chart_card.tsx

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
// tslint:disable:no-unused-variable
12
import { BigNumber } from '@0x/utils';
23
import React from 'react';
34
import styled from 'styled-components';
45

56
import { ETH_DECIMALS } from '../../../common/constants';
67
import { themeBreakPoints } from '../../../themes/commons';
78
import { getCollectiblePrice } from '../../../util/collectibles';
8-
import { getDutchAuctionData, isDutchAuction } from '../../../util/orders';
99
import { convertTimeInSecondsToDaysAndHours } from '../../../util/time_utils';
1010
import { tokenAmountInUnits } from '../../../util/tokens';
1111
import { Collectible } from '../../../util/types';
@@ -88,49 +88,50 @@ interface Props {
8888
export const DutchAuctionPriceChartCard = (props: Props) => {
8989
const { collectible } = props;
9090
const { order } = collectible;
91-
if (order === null || !isDutchAuction(order)) {
92-
return null;
93-
}
94-
95-
const { makerAssetData, expirationTimeSeconds } = order;
96-
const { beginAmount, beginTimeSeconds } = getDutchAuctionData(makerAssetData);
97-
const price = getCollectiblePrice(collectible) as BigNumber;
98-
const { days, hours } = convertTimeInSecondsToDaysAndHours(expirationTimeSeconds.minus(beginTimeSeconds));
99-
100-
const currentPriceInUnits = +tokenAmountInUnits(price, ETH_DECIMALS);
101-
const beginAmountInUnits = +tokenAmountInUnits(beginAmount, ETH_DECIMALS);
102-
const endAmountInUnits = +tokenAmountInUnits(order.takerAssetAmount, ETH_DECIMALS);
103-
104-
return (
105-
<Card>
106-
<CollectibleDescriptionInnerTitle>Price Chart</CollectibleDescriptionInnerTitle>
107-
<PriceChartContainer>
108-
<PriceChartPriceAndTime>
109-
<PriceChartTitle>Current Price</PriceChartTitle>
110-
<PriceChartValue>{currentPriceInUnits} ETH</PriceChartValue>
111-
<PriceChartTitle>Time Remaining</PriceChartTitle>
112-
<PriceChartValue>{`${days} Days ${hours} Hrs`}</PriceChartValue>
113-
</PriceChartPriceAndTime>
114-
<PriceChartGraphWrapper>
115-
<PriceChartGraph>
116-
<DecliningPriceGraph
117-
beginAmountInUnits={beginAmountInUnits}
118-
endAmountInUnits={endAmountInUnits}
119-
currentPriceInUnits={currentPriceInUnits}
120-
/>
121-
</PriceChartGraph>
122-
<PriceChartGraphValues>
123-
<div>
124-
<PriceChartTitle>Start Price</PriceChartTitle>
125-
<PriceChartValueNeutral>{beginAmountInUnits} ETH</PriceChartValueNeutral>
126-
</div>
127-
<div>
128-
<PriceChartTitle>End Price</PriceChartTitle>
129-
<PriceChartValueNeutral>{endAmountInUnits} ETH</PriceChartValueNeutral>
130-
</div>
131-
</PriceChartGraphValues>
132-
</PriceChartGraphWrapper>
133-
</PriceChartContainer>
134-
</Card>
135-
);
91+
return null;
92+
// if (order === null || !isDutchAuction(order)) {
93+
// return null;
94+
// }
95+
96+
// const { makerAssetData, expirationTimeSeconds } = order;
97+
// const { beginAmount, beginTimeSeconds } = getDutchAuctionData(makerAssetData);
98+
// const price = getCollectiblePrice(collectible) as BigNumber;
99+
// const { days, hours } = convertTimeInSecondsToDaysAndHours(expirationTimeSeconds.minus(beginTimeSeconds));
100+
101+
// const currentPriceInUnits = +tokenAmountInUnits(price, ETH_DECIMALS);
102+
// const beginAmountInUnits = +tokenAmountInUnits(beginAmount, ETH_DECIMALS);
103+
// const endAmountInUnits = +tokenAmountInUnits(order.takerAssetAmount, ETH_DECIMALS);
104+
105+
// return (
106+
// <Card>
107+
// <CollectibleDescriptionInnerTitle>Price Chart</CollectibleDescriptionInnerTitle>
108+
// <PriceChartContainer>
109+
// <PriceChartPriceAndTime>
110+
// <PriceChartTitle>Current Price</PriceChartTitle>
111+
// <PriceChartValue>{currentPriceInUnits} ETH</PriceChartValue>
112+
// <PriceChartTitle>Time Remaining</PriceChartTitle>
113+
// <PriceChartValue>{`${days} Days ${hours} Hrs`}</PriceChartValue>
114+
// </PriceChartPriceAndTime>
115+
// <PriceChartGraphWrapper>
116+
// <PriceChartGraph>
117+
// <DecliningPriceGraph
118+
// beginAmountInUnits={beginAmountInUnits}
119+
// endAmountInUnits={endAmountInUnits}
120+
// currentPriceInUnits={currentPriceInUnits}
121+
// />
122+
// </PriceChartGraph>
123+
// <PriceChartGraphValues>
124+
// <div>
125+
// <PriceChartTitle>Start Price</PriceChartTitle>
126+
// <PriceChartValueNeutral>{beginAmountInUnits} ETH</PriceChartValueNeutral>
127+
// </div>
128+
// <div>
129+
// <PriceChartTitle>End Price</PriceChartTitle>
130+
// <PriceChartValueNeutral>{endAmountInUnits} ETH</PriceChartValueNeutral>
131+
// </div>
132+
// </PriceChartGraphValues>
133+
// </PriceChartGraphWrapper>
134+
// </PriceChartContainer>
135+
// </Card>
136+
// );
136137
};

src/tests/store/actions/blockchain.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ const web3Wrapper = {
1212
getNetworkIdAsync: jest.fn().mockResolvedValue(50),
1313
};
1414

15+
const depositMockSendTx = jest.fn();
16+
const withdrawMockSendTx = jest.fn();
17+
const approveMockSendTx = jest.fn();
1518
const contractWrappers = {
1619
erc20Token: {
17-
approve: {
20+
approve: jest.fn(() => ({
1821
sendTransactionAsync: jest.fn(),
19-
},
22+
})),
2023
},
2124
erc20Proxy: {
2225
address: '0x0000000000000000000000000000000000000001',
2326
},
2427
weth9: {
25-
approve: {
26-
sendTransactionAsync: jest.fn(),
27-
},
28-
deposit: {
29-
sendTransactionAsync: jest.fn(),
30-
},
28+
approve: jest.fn(() => ({ sendTransactionAsync: approveMockSendTx })),
29+
deposit: jest.fn(() => ({ sendTransactionAsync: depositMockSendTx })),
30+
withdraw: jest.fn(() => ({ sendTransactionAsync: withdrawMockSendTx })),
3131
},
3232
getProvider: () => ({ isStandardizedProvider: true }),
3333
};
@@ -45,7 +45,7 @@ describe('blockchain actions', () => {
4545
// HACK(dekz) skipped as erc20Token no longer exists on contractWrappers
4646
// given
4747
const tx = 'some-tx';
48-
contractWrappers.erc20Token.approve.sendTransactionAsync.mockResolvedValueOnce(tx);
48+
contractWrappers.erc20Token.approve().sendTransactionAsync.mockResolvedValueOnce(tx);
4949
const token = tokenFactory.build();
5050
const ethAccount = addressFactory.build().address;
5151
const store = mockStore({
@@ -61,17 +61,17 @@ describe('blockchain actions', () => {
6161
const result = await store.dispatch(toggleTokenLock(token, true) as any);
6262

6363
// then
64-
expect(contractWrappers.erc20Token.approve.sendTransactionAsync).toHaveBeenCalled();
65-
expect(contractWrappers.erc20Token.approve.sendTransactionAsync.mock.calls[0][0]).toEqual(token.address);
66-
expect(contractWrappers.erc20Token.approve.sendTransactionAsync.mock.calls[0][1]).toEqual(ZERO);
64+
expect(contractWrappers.erc20Token.approve().sendTransactionAsync).toHaveBeenCalled();
65+
expect(contractWrappers.erc20Token.approve.mock.calls[0][0]).toEqual(token.address);
66+
expect(contractWrappers.erc20Token.approve().sendTransactionAsync.mock.calls[0][1]).toEqual(ZERO);
6767
expect(result).toEqual(tx);
6868
});
6969
});
7070
describe('updateWethBalance', () => {
7171
it('should convert eth to weth', async () => {
7272
// given
7373
const tx = 'some-tx';
74-
contractWrappers.weth9.deposit.sendTransactionAsync.mockResolvedValueOnce(tx);
74+
contractWrappers.weth9.deposit().sendTransactionAsync.mockResolvedValueOnce(tx);
7575
const store = mockStore({
7676
blockchain: {
7777
ethBalance: new BigNumber(10),
@@ -90,7 +90,7 @@ describe('blockchain actions', () => {
9090
const result = await store.dispatch(updateWethBalance(new BigNumber(5)) as any);
9191

9292
// then
93-
expect(contractWrappers.weth9.deposit.sendTransactionAsync.mock.calls[0][0].value).toEqual(
93+
expect(contractWrappers.weth9.deposit().sendTransactionAsync.mock.calls[0][0].value).toEqual(
9494
new BigNumber(4),
9595
);
9696
expect(result).toEqual(tx);

src/util/collectibles.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
import { BigNumber } from '@0x/utils';
22

3-
import { getDutchAuctionData } from './orders';
4-
import { todayInSeconds } from './time_utils';
53
import { Collectible } from './types';
64

75
export const getCollectiblePrice = (collectible: Collectible): BigNumber | null => {
86
const { order } = collectible;
97
if (order === null) {
108
return null;
119
}
10+
return order.takerAssetAmount;
1211

13-
try {
14-
const dutchAcutionData = getDutchAuctionData(order.makerAssetData);
15-
const { beginAmount, beginTimeSeconds } = dutchAcutionData;
16-
const endAmount = order.takerAssetAmount;
17-
const startTimeSeconds = order.expirationTimeSeconds;
18-
// Use y = mx + b (linear function)
19-
const m = endAmount.minus(beginAmount).dividedBy(startTimeSeconds.minus(beginTimeSeconds));
20-
const b = beginAmount.minus(beginTimeSeconds.multipliedBy(m));
21-
return m.multipliedBy(todayInSeconds()).plus(b);
22-
} catch (err) {
23-
return order.takerAssetAmount;
24-
}
12+
// try {
13+
// const dutchAcutionData = getDutchAuctionData(order.makerAssetData);
14+
// const { beginAmount, beginTimeSeconds } = dutchAcutionData;
15+
// const endAmount = order.takerAssetAmount;
16+
// const startTimeSeconds = order.expirationTimeSeconds;
17+
// // Use y = mx + b (linear function)
18+
// const m = endAmount.minus(beginAmount).dividedBy(startTimeSeconds.minus(beginTimeSeconds));
19+
// const b = beginAmount.minus(beginTimeSeconds.multipliedBy(m));
20+
// return m.multipliedBy(todayInSeconds()).plus(b);
21+
// } catch (err) {
22+
// return order.takerAssetAmount;
23+
// }
2524
};

src/util/orders.ts

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ interface BuildSellCollectibleOrderParams {
2222
price: BigNumber;
2323
}
2424

25-
interface DutchAuctionOrderParams extends BuildSellCollectibleOrderParams {
26-
endPrice: BigNumber;
27-
senderAddress: string;
28-
}
29-
3025
interface BuildLimitOrderParams {
3126
account: string;
3227
amount: BigNumber;
@@ -41,37 +36,6 @@ interface BuildMarketOrderParams {
4136
orders: UIOrder[];
4237
}
4338

44-
export const buildDutchAuctionCollectibleOrder = async (params: DutchAuctionOrderParams) => {
45-
const {
46-
account,
47-
collectibleId,
48-
collectibleAddress,
49-
amount,
50-
price,
51-
exchangeAddress,
52-
wethAddress,
53-
expirationDate,
54-
endPrice,
55-
} = params;
56-
const collectibleData = assetDataUtils.encodeERC721AssetData(collectibleAddress, collectibleId);
57-
const beginTimeSeconds = new BigNumber(Math.round(Date.now() / 1000));
58-
const auctionAssetData = assetDataUtils.encodeDutchAuctionAssetData(collectibleData, beginTimeSeconds, price);
59-
const wethAssetData = assetDataUtils.encodeERC20AssetData(wethAddress);
60-
61-
const orderConfigRequest: OrderConfigRequest = {
62-
exchangeAddress,
63-
makerAssetData: auctionAssetData,
64-
takerAssetData: wethAssetData,
65-
makerAssetAmount: amount,
66-
takerAssetAmount: endPrice,
67-
makerAddress: account,
68-
takerAddress: ZERO_ADDRESS,
69-
expirationTimeSeconds: expirationDate,
70-
};
71-
72-
return orderHelper.getOrderWithTakerAndFeeConfigFromRelayer(orderConfigRequest);
73-
};
74-
7539
export const buildSellCollectibleOrder = async (params: BuildSellCollectibleOrderParams, side: OrderSide) => {
7640
const {
7741
account,
@@ -217,15 +181,6 @@ export const calculateWorstCaseProtocolFee = (orders: SignedOrder[], gasPrice: B
217181
return protocolFee;
218182
};
219183

220-
export const getDutchAuctionData = (assetData: string) => {
221-
return assetDataUtils.decodeDutchAuctionData(assetData);
222-
};
223-
224-
export const isDutchAuction = (order: SignedOrder) => {
225-
try {
226-
getDutchAuctionData(order.makerAssetData);
227-
return true;
228-
} catch (e) {
229-
return false;
230-
}
184+
export const isDutchAuction = (_order: SignedOrder) => {
185+
return false;
231186
};

0 commit comments

Comments
 (0)