From 9f9b3295969bdf05724c7ac9e0834e0793b71d4c Mon Sep 17 00:00:00 2001 From: Abdelrhman Farag Date: Wed, 12 Oct 2022 17:06:52 +0200 Subject: [PATCH 01/18] Add types --- core/src/types.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/types.ts b/core/src/types.ts index 3d1730f63..bd52172b3 100644 --- a/core/src/types.ts +++ b/core/src/types.ts @@ -21,6 +21,8 @@ export declare interface AuctionInitialInfo { isFinished: boolean; isRestarting: boolean; marketUnitPrice?: BigNumber; + suggestedMarketId?: string; + marketData?: Record; marketUnitPriceToUnitPriceRatio?: BigNumber; transactionGrossProfit?: BigNumber; transactionAddress?: string; From edfd9be4399fe2c94aa5d60c1d5d7bf509d46eff Mon Sep 17 00:00:00 2001 From: Abdelrhman Farag Date: Wed, 12 Oct 2022 17:08:30 +0200 Subject: [PATCH 02/18] Add new types to helpers/generateFakeAuction --- frontend/helpers/generateFakeAuction.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/frontend/helpers/generateFakeAuction.ts b/frontend/helpers/generateFakeAuction.ts index 319dcbbf1..f7e3552c6 100644 --- a/frontend/helpers/generateFakeAuction.ts +++ b/frontend/helpers/generateFakeAuction.ts @@ -19,6 +19,21 @@ export const generateFakeAuction = function () { const marketUnitPrice = approximateUnitPrice.multipliedBy( new BigNumber(1).minus(marketUnitPriceToUnitPriceRatio || 0) ); + const suggestedMarketId = 'Uniswap v3'; + const marketData = { + 'Uniswap v3': { + unitPrice: marketUnitPrice.multipliedBy( + new BigNumber(faker.datatype.float({ min: 1.1, max: 1.5, precision: 0.001 })) + ), + route: [collateralObject.symbol, 'USDC'], + }, + 'Uniswap v2': { + unitPrice: marketUnitPrice.multipliedBy( + new BigNumber(faker.datatype.float({ min: 1.1, max: 1.5, precision: 0.001 })) + ), + route: [collateralObject.symbol], + }, + }; const transactionGrossProfit = marketUnitPrice .multipliedBy(collateralAmount) .minus(approximateUnitPrice.multipliedBy(collateralAmount)); @@ -40,6 +55,8 @@ export const generateFakeAuction = function () { approximateUnitPrice, unitPrice: approximateUnitPrice, marketUnitPrice, + marketData, + suggestedMarketId, isActive, transactionGrossProfit, isFinished, From 8f3f23cf7c47c259f137c8202d74899a2c92898e Mon Sep 17 00:00:00 2001 From: Abdelrhman Farag Date: Wed, 12 Oct 2022 17:09:07 +0200 Subject: [PATCH 03/18] Create MarketPriceSelection component and stories --- .../MarketPriceSelection.stories.js | 15 ++++ .../collateral/MarketPriceSelection.vue | 86 +++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 frontend/components/auction/collateral/MarketPriceSelection.stories.js create mode 100644 frontend/components/auction/collateral/MarketPriceSelection.vue diff --git a/frontend/components/auction/collateral/MarketPriceSelection.stories.js b/frontend/components/auction/collateral/MarketPriceSelection.stories.js new file mode 100644 index 000000000..2d98213ed --- /dev/null +++ b/frontend/components/auction/collateral/MarketPriceSelection.stories.js @@ -0,0 +1,15 @@ +import { storiesOf } from '@storybook/vue'; +import MarketPriceSelection from './MarketPriceSelection'; +import { generateFakeAuctionTransaction } from '~/helpers/generateFakeAuction.ts'; + +const fakeAuctionTransaction = generateFakeAuctionTransaction(); + +storiesOf('Auction/Collateral/MarketPriceSelection', module).add('Default', () => ({ + components: { + MarketPriceSelection, + }, + data: () => ({ + auctionTransaction: fakeAuctionTransaction, + }), + template: '', +})); diff --git a/frontend/components/auction/collateral/MarketPriceSelection.vue b/frontend/components/auction/collateral/MarketPriceSelection.vue new file mode 100644 index 000000000..8346c9c05 --- /dev/null +++ b/frontend/components/auction/collateral/MarketPriceSelection.vue @@ -0,0 +1,86 @@ + + + + + From f211ed593d234debf18de634554a96654eefac72 Mon Sep 17 00:00:00 2001 From: Abdelrhman Farag Date: Wed, 12 Oct 2022 18:29:40 +0200 Subject: [PATCH 04/18] Emit from MarketPriceSelection to sync marketId --- .../collateral/MarketPriceSelection.vue | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/frontend/components/auction/collateral/MarketPriceSelection.vue b/frontend/components/auction/collateral/MarketPriceSelection.vue index 8346c9c05..c500fb22a 100644 --- a/frontend/components/auction/collateral/MarketPriceSelection.vue +++ b/frontend/components/auction/collateral/MarketPriceSelection.vue @@ -2,8 +2,10 @@
per @@ -23,7 +25,7 @@
- @@ -58,11 +60,14 @@ export default Vue.extend({ type: Object as Vue.PropType, required: true, }, + marketId: { + type: String, + default: '', + }, }, data() { return { isExpanded: false, - marketId: '', }; }, computed: { @@ -78,9 +83,12 @@ export default Vue.extend({ From 4be5323b251173d1849144b96328faf88423ad9e Mon Sep 17 00:00:00 2001 From: Abdelrhman Farag Date: Wed, 12 Oct 2022 21:03:04 +0200 Subject: [PATCH 05/18] Initial implementation --- .../CollateralAuctionSwapTransaction.vue | 7 ++++- .../CollateralAuctionSwapTransactionTable.vue | 21 ++++++------- .../MarketPriceSelection.stories.js | 9 ++++-- .../collateral/MarketPriceSelection.vue | 31 ++++++++++--------- frontend/containers/AuctionsContainer.vue | 4 ++- frontend/helpers/generateFakeAuction.ts | 4 +++ 6 files changed, 44 insertions(+), 32 deletions(-) diff --git a/frontend/components/auction/collateral/CollateralAuctionSwapTransaction.vue b/frontend/components/auction/collateral/CollateralAuctionSwapTransaction.vue index 8d4fdaea5..a4f9ccd63 100644 --- a/frontend/components/auction/collateral/CollateralAuctionSwapTransaction.vue +++ b/frontend/components/auction/collateral/CollateralAuctionSwapTransaction.vue @@ -7,7 +7,11 @@ type="error" /> - + Please note, the transaction fee is a suggested value based on the current gas prices on the market; the Transaction Net Profit is also approximate, since it is extrapolated from the exchange rates and may change @@ -151,6 +155,7 @@ export default Vue.extend({ }, data() { return { + marketId: '', isWalletConnectedCheck: false, isWalletDAIAuthorizationCheckPassed: false, isWalletCollateralAuthorizationCheckPassed: false, diff --git a/frontend/components/auction/collateral/CollateralAuctionSwapTransactionTable.vue b/frontend/components/auction/collateral/CollateralAuctionSwapTransactionTable.vue index 8156f97f5..8d7c594be 100644 --- a/frontend/components/auction/collateral/CollateralAuctionSwapTransactionTable.vue +++ b/frontend/components/auction/collateral/CollateralAuctionSwapTransactionTable.vue @@ -21,16 +21,7 @@ {{ auctionTransaction.collateralSymbol }}
-
-
Price On Uniswap
-
- - Unknown -
-
+
Market Difference
@@ -98,9 +89,10 @@ diff --git a/frontend/components/auction/collateral/MarketPriceSelection.stories.js b/frontend/components/auction/collateral/MarketPriceSelection.stories.js index 2d98213ed..c866663ac 100644 --- a/frontend/components/auction/collateral/MarketPriceSelection.stories.js +++ b/frontend/components/auction/collateral/MarketPriceSelection.stories.js @@ -4,12 +4,15 @@ import { generateFakeAuctionTransaction } from '~/helpers/generateFakeAuction.ts const fakeAuctionTransaction = generateFakeAuctionTransaction(); -storiesOf('Auction/Collateral/MarketPriceSelection', module).add('Default', () => ({ +const common = { components: { MarketPriceSelection, }, data: () => ({ auctionTransaction: fakeAuctionTransaction, + marketId: '', }), - template: '', -})); + template: ``, +}; + +storiesOf('Auction/Collateral/MarketPriceSelection', module).add('Default', () => ({ ...common })); diff --git a/frontend/components/auction/collateral/MarketPriceSelection.vue b/frontend/components/auction/collateral/MarketPriceSelection.vue index c500fb22a..1377993b4 100644 --- a/frontend/components/auction/collateral/MarketPriceSelection.vue +++ b/frontend/components/auction/collateral/MarketPriceSelection.vue @@ -15,16 +15,14 @@
- - - - - -
{{ key }} - {{ currency }} → - DAI -
-
+
+
{{ key }}
+
+ ({{ currency }} → + DAI) +
+
+
-
Unknown
+
Unknown
@@ -71,11 +69,14 @@ export default Vue.extend({ }; }, computed: { - suggestionOrSelection(): string { - return this.marketId ? this.marketId : this.auctionTransaction.suggestedMarketId; + suggestionOrSelection(): string | undefined { + return this.marketId || this.auctionTransaction.suggestedMarketId; }, - marketUnitPrice(): BigNumber { - return this.auctionTransaction.marketData[this.suggestionOrSelection].unitPrice; + marketUnitPrice(): BigNumber | undefined { + if (this.auctionTransaction.marketData && this.suggestionOrSelection) { + return this.auctionTransaction.marketData[this.suggestionOrSelection].unitPrice; + } + return undefined; }, }, }); diff --git a/frontend/containers/AuctionsContainer.vue b/frontend/containers/AuctionsContainer.vue index 68d59eec8..9772d1c2b 100644 --- a/frontend/containers/AuctionsContainer.vue +++ b/frontend/containers/AuctionsContainer.vue @@ -39,8 +39,10 @@ diff --git a/frontend/store/auctions.ts b/frontend/store/auctions.ts index 6e3025d09..715a983c0 100644 --- a/frontend/store/auctions.ts +++ b/frontend/store/auctions.ts @@ -233,8 +233,13 @@ export const actions = { }, async bidWithCallee( { getters, commit, rootGetters }: ActionContext, - { id, alternativeDestinationAddress }: { id: string; alternativeDestinationAddress: string | undefined } + { + id, + marketId, + alternativeDestinationAddress, + }: { id: string; marketId: string; alternativeDestinationAddress: string | undefined } ) { + console.log(marketId); // to be removed after core implementation const auction = getters.getAuctionById(id); if (!auction) { message.error(`Bidding error: can not find auction with id "${id}"`); From 4121563e530cafa926997b2a00c1c0cc98b34dc0 Mon Sep 17 00:00:00 2001 From: Abdelrhman Farag Date: Fri, 14 Oct 2022 13:11:36 +0200 Subject: [PATCH 08/18] Change console.log to console.info to avoid lint error --- frontend/store/auctions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/store/auctions.ts b/frontend/store/auctions.ts index 715a983c0..393c51e07 100644 --- a/frontend/store/auctions.ts +++ b/frontend/store/auctions.ts @@ -239,7 +239,7 @@ export const actions = { alternativeDestinationAddress, }: { id: string; marketId: string; alternativeDestinationAddress: string | undefined } ) { - console.log(marketId); // to be removed after core implementation + console.info(marketId); // to be removed after core implementation const auction = getters.getAuctionById(id); if (!auction) { message.error(`Bidding error: can not find auction with id "${id}"`); From cc19d8505dc2924153d838fd6950a830d5d3d8bf Mon Sep 17 00:00:00 2001 From: Abdelrhman Farag Date: Wed, 19 Oct 2022 10:31:01 +0200 Subject: [PATCH 09/18] Sort callees --- .../collateral/MarketPriceSelection.vue | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/frontend/components/auction/collateral/MarketPriceSelection.vue b/frontend/components/auction/collateral/MarketPriceSelection.vue index 4eb03ad32..d4bc7bd8c 100644 --- a/frontend/components/auction/collateral/MarketPriceSelection.vue +++ b/frontend/components/auction/collateral/MarketPriceSelection.vue @@ -16,7 +16,7 @@
- +
{{ key }} {{ currency }} → @@ -82,6 +82,25 @@ export default Vue.extend({ } return undefined; }, + callees(): Object { + const unknown = []; + const sorted = []; + for (const callee in this.auctionTransaction.marketData) { + if ( + this.auctionTransaction.marketData[callee].unitPrice && + !this.auctionTransaction.marketData[callee].unitPrice.isNaN() + ) { + sorted.push([callee, this.auctionTransaction.marketData[callee].unitPrice]); + } else { + unknown.push([callee, this.auctionTransaction.marketData[callee].unitPrice]); + } + } + sorted.sort((a, b) => a[1].minus(b[1]).toNumber()); + const calleesArray = [...sorted, ...unknown]; + const calleesObject = {}; + calleesArray.forEach(item => (calleesObject[item[0]] = this.auctionTransaction.marketData[item[0]])); + return calleesObject; + }, }, }); From c6f85ca0a0cb3a4b7d7cfeb45e084d1d6cee4651 Mon Sep 17 00:00:00 2001 From: Abdelrhman Farag Date: Wed, 19 Oct 2022 15:04:39 +0200 Subject: [PATCH 10/18] Modify types --- core/src/types.ts | 7 +++- .../collateral/MarketPriceSelection.vue | 33 +++++++++---------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/core/src/types.ts b/core/src/types.ts index bd52172b3..e1f2d46fd 100644 --- a/core/src/types.ts +++ b/core/src/types.ts @@ -6,6 +6,11 @@ export declare interface GasParameters { gasPrice?: string; } +export type MarketData = { + unitPrice: BigNumber; + route: string[]; +}; + export declare interface AuctionInitialInfo { network: string; id: string; @@ -22,7 +27,7 @@ export declare interface AuctionInitialInfo { isRestarting: boolean; marketUnitPrice?: BigNumber; suggestedMarketId?: string; - marketData?: Record; + marketData?: Record; marketUnitPriceToUnitPriceRatio?: BigNumber; transactionGrossProfit?: BigNumber; transactionAddress?: string; diff --git a/frontend/components/auction/collateral/MarketPriceSelection.vue b/frontend/components/auction/collateral/MarketPriceSelection.vue index d4bc7bd8c..cff3634af 100644 --- a/frontend/components/auction/collateral/MarketPriceSelection.vue +++ b/frontend/components/auction/collateral/MarketPriceSelection.vue @@ -16,20 +16,22 @@
- - + +
{{ key }}
{{ callee[0] }} - {{ currency }} → + {{ currency }} → + DAI -
- - per + per {{ auctionTransaction.collateralSymbol }}
@@ -48,7 +50,7 @@ import Vue from 'vue'; import BigNumber from 'bignumber.js'; import { Icon } from 'ant-design-vue'; import CollapseTransition from '@ivanv/vue-collapse-transition'; -import { AuctionTransaction } from 'auctions-core/src/types'; +import { AuctionTransaction, MarketData } from 'auctions-core/src/types'; import FormatCurrency from '~/components/common/formatters/FormatCurrency.vue'; export default Vue.extend({ @@ -82,24 +84,21 @@ export default Vue.extend({ } return undefined; }, - callees(): Object { - const unknown = []; + callees(): Array> { const sorted = []; + const unknown = []; for (const callee in this.auctionTransaction.marketData) { if ( this.auctionTransaction.marketData[callee].unitPrice && !this.auctionTransaction.marketData[callee].unitPrice.isNaN() ) { - sorted.push([callee, this.auctionTransaction.marketData[callee].unitPrice]); + sorted.push([callee, this.auctionTransaction.marketData[callee]]); } else { - unknown.push([callee, this.auctionTransaction.marketData[callee].unitPrice]); + unknown.push([callee, this.auctionTransaction.marketData[callee]]); } } - sorted.sort((a, b) => a[1].minus(b[1]).toNumber()); - const calleesArray = [...sorted, ...unknown]; - const calleesObject = {}; - calleesArray.forEach(item => (calleesObject[item[0]] = this.auctionTransaction.marketData[item[0]])); - return calleesObject; + sorted.sort((a, b) => a[1].unitPrice.minus(b[1].unitPrice).toNumber()); + return [...sorted, ...unknown]; }, }, }); From 3fcc0e3869ca8edb1287f06032710dbba8b91c08 Mon Sep 17 00:00:00 2001 From: Abdelrhman Farag Date: Fri, 4 Nov 2022 19:08:02 +0100 Subject: [PATCH 11/18] Reflect change in marketId in all related values --- .../CollateralAuctionSwapTransactionTable.vue | 33 +++++++++++++++---- .../collateral/MarketPriceSelection.vue | 24 +++++++------- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/frontend/components/auction/collateral/CollateralAuctionSwapTransactionTable.vue b/frontend/components/auction/collateral/CollateralAuctionSwapTransactionTable.vue index 8d7c594be..10ab6c624 100644 --- a/frontend/components/auction/collateral/CollateralAuctionSwapTransactionTable.vue +++ b/frontend/components/auction/collateral/CollateralAuctionSwapTransactionTable.vue @@ -25,8 +25,8 @@
Market Difference
- diff --git a/frontend/components/auction/collateral/MarketPriceSelection.vue b/frontend/components/auction/collateral/MarketPriceSelection.vue index cff3634af..e35ecc30b 100644 --- a/frontend/components/auction/collateral/MarketPriceSelection.vue +++ b/frontend/components/auction/collateral/MarketPriceSelection.vue @@ -25,13 +25,13 @@ DAI
-
+
- per + per {{ auctionTransaction.collateralSymbol }}
@@ -50,7 +50,7 @@ import Vue from 'vue'; import BigNumber from 'bignumber.js'; import { Icon } from 'ant-design-vue'; import CollapseTransition from '@ivanv/vue-collapse-transition'; -import { AuctionTransaction, MarketData } from 'auctions-core/src/types'; +import { AuctionTransaction } from 'auctions-core/src/types'; import FormatCurrency from '~/components/common/formatters/FormatCurrency.vue'; export default Vue.extend({ @@ -79,25 +79,25 @@ export default Vue.extend({ return this.marketId || this.auctionTransaction.suggestedMarketId; }, marketUnitPrice(): BigNumber | undefined { - if (this.auctionTransaction.marketData && this.suggestionOrSelection) { - return this.auctionTransaction.marketData[this.suggestionOrSelection].unitPrice; + if (this.auctionTransaction.marketDataRecords && this.suggestionOrSelection) { + return this.auctionTransaction.marketDataRecords[this.suggestionOrSelection].marketUnitPrice; } return undefined; }, - callees(): Array> { + callees() { const sorted = []; const unknown = []; - for (const callee in this.auctionTransaction.marketData) { + for (const callee in this.auctionTransaction.marketDataRecords) { if ( - this.auctionTransaction.marketData[callee].unitPrice && - !this.auctionTransaction.marketData[callee].unitPrice.isNaN() + this.auctionTransaction.marketDataRecords[callee].marketUnitPrice && + !this.auctionTransaction.marketDataRecords[callee].marketUnitPrice.isNaN() ) { - sorted.push([callee, this.auctionTransaction.marketData[callee]]); + sorted.push([callee, this.auctionTransaction.marketDataRecords[callee]]); } else { - unknown.push([callee, this.auctionTransaction.marketData[callee]]); + unknown.push([callee, this.auctionTransaction.marketDataRecords[callee]]); } } - sorted.sort((a, b) => a[1].unitPrice.minus(b[1].unitPrice).toNumber()); + sorted.sort((a, b) => a[1].marketUnitPrice.minus(b[1].marketUnitPrice).toNumber()); return [...sorted, ...unknown]; }, }, From d99db0e9f26bde991ce5c3455309736f8b73ba9c Mon Sep 17 00:00:00 2001 From: Abdelrhman Farag Date: Fri, 4 Nov 2022 19:29:52 +0100 Subject: [PATCH 12/18] Remove duplicate type --- core/src/types.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/core/src/types.ts b/core/src/types.ts index ad17f19c4..160d10df8 100644 --- a/core/src/types.ts +++ b/core/src/types.ts @@ -6,11 +6,6 @@ export declare interface GasParameters { gasPrice?: string; } -export type MarketData = { - unitPrice: BigNumber; - route: string[]; -}; - export declare interface AuctionInitialInfo { network: string; id: string; @@ -28,8 +23,6 @@ export declare interface AuctionInitialInfo { suggestedMarketId?: string; marketDataRecords?: Record; marketUnitPrice?: BigNumber; - suggestedMarketId?: string; - marketData?: Record; marketUnitPriceToUnitPriceRatio?: BigNumber; transactionGrossProfit?: BigNumber; transactionAddress?: string; From c9a34458aefeff6cc55c16c2d8cf2d28ce1a069a Mon Sep 17 00:00:00 2001 From: Abdelrhman Farag Date: Sat, 5 Nov 2022 19:28:08 +0100 Subject: [PATCH 13/18] Modify stories to reflect callee selection --- frontend/helpers/generateFakeAuction.ts | 70 ++++++++++++++++--------- 1 file changed, 46 insertions(+), 24 deletions(-) diff --git a/frontend/helpers/generateFakeAuction.ts b/frontend/helpers/generateFakeAuction.ts index 24871181d..33cdb9339 100644 --- a/frontend/helpers/generateFakeAuction.ts +++ b/frontend/helpers/generateFakeAuction.ts @@ -2,7 +2,32 @@ import faker from 'faker'; import { random } from 'lodash'; import BigNumber from 'bignumber.js'; import COLLATERALS from 'auctions-core/src/constants/COLLATERALS'; -import { AuctionTransaction } from '~/../core/src/types'; +import { AuctionTransaction, MarketData } from '~/../core/src/types'; + +const FAKE_CALLEES = ['Uniswap V3', '1inch']; // Curve V3 marketUnitPrice is NaN (see below) + +export const generateFakeMarketData = function ( + isActive: boolean, + approximateUnitPrice: BigNumber, + collateralAmount: BigNumber +) { + const marketUnitPriceToUnitPriceRatio = isActive + ? new BigNumber(faker.datatype.number({ min: -0.3, max: 0.3, precision: 0.001 })) + : undefined; + const marketUnitPrice = approximateUnitPrice.multipliedBy( + new BigNumber(1).minus(marketUnitPriceToUnitPriceRatio || 0) + ); + const transactionGrossProfit = marketUnitPrice + .multipliedBy(collateralAmount) + .minus(approximateUnitPrice.multipliedBy(collateralAmount)); + const transactionGrossProfitDate = faker.date.future(); + return { + marketUnitPrice, + marketUnitPriceToUnitPriceRatio, + transactionGrossProfit, + transactionGrossProfitDate, + }; +}; export const generateFakeAuction = function () { const index = faker.datatype.number(); @@ -12,35 +37,26 @@ export const generateFakeAuction = function () { const isActive = faker.datatype.boolean(); const isFinished = faker.datatype.boolean(); const approximateUnitPrice = totalPrice.dividedBy(collateralAmount); - const marketUnitPriceToUnitPriceRatio = isActive - ? new BigNumber(faker.datatype.number({ min: -0.3, max: 0.3, precision: 0.001 })) - : undefined; const collateralObject = faker.helpers.randomize(Object.values(COLLATERALS)); - const marketUnitPrice = approximateUnitPrice.multipliedBy( - new BigNumber(1).minus(marketUnitPriceToUnitPriceRatio || 0) - ); - const suggestedMarketId = 'Uniswap v3'; - const marketData = { - 'Uniswap v3': { - unitPrice: marketUnitPrice.multipliedBy( - new BigNumber(faker.datatype.float({ min: 1.1, max: 1.5, precision: 0.001 })) - ), + const suggestedMarketId = faker.helpers.randomize(FAKE_CALLEES); + const marketDataRecords: Record = { + 'Uniswap V3': { + ...generateFakeMarketData(isActive, approximateUnitPrice, collateralAmount), route: [collateralObject.symbol, 'USDC'], }, - 'Uniswap v2': { - unitPrice: new BigNumber(NaN), + 'Curve V3': { + marketUnitPrice: new BigNumber(NaN), route: [collateralObject.symbol], }, '1inch': { - unitPrice: marketUnitPrice.multipliedBy( - new BigNumber(faker.datatype.float({ min: 1.1, max: 1.5, precision: 0.001 })) - ), + ...generateFakeMarketData(isActive, approximateUnitPrice, collateralAmount), route: [collateralObject.symbol], }, }; - const transactionGrossProfit = marketUnitPrice - .multipliedBy(collateralAmount) - .minus(approximateUnitPrice.multipliedBy(collateralAmount)); + const marketUnitPriceToUnitPriceRatio = marketDataRecords[suggestedMarketId].marketUnitPriceToUnitPriceRatio; + const marketUnitPrice = marketDataRecords[suggestedMarketId].marketUnitPrice; + const transactionGrossProfit = marketDataRecords[suggestedMarketId].transactionGrossProfit; + const transactionGrossProfitDate = marketDataRecords[suggestedMarketId].transactionGrossProfitDate; const secondsBetweenPriceDrops = faker.datatype.number(120); const secondsTillNextPriceDrop = faker.datatype.number(secondsBetweenPriceDrops); return { @@ -59,7 +75,7 @@ export const generateFakeAuction = function () { approximateUnitPrice, unitPrice: approximateUnitPrice, marketUnitPrice, - marketData, + marketDataRecords, suggestedMarketId, isActive, transactionGrossProfit, @@ -72,7 +88,7 @@ export const generateFakeAuction = function () { collateralToCoverDebt: collateralAmount.multipliedBy(debtDAI.dividedBy(totalPrice)), minimumBidDai: new BigNumber(faker.finance.amount()), priceDropRatio: new BigNumber(faker.datatype.number({ min: 0.5, max: 1, precision: 0.0001 })), - transactionGrossProfitDate: faker.date.future(), + transactionGrossProfitDate, fetchedAt: new Date(), }; }; @@ -87,7 +103,13 @@ export const generateFakeAuctionTransaction = function (): AuctionTransaction { const authTransactionFeeDAI = authTransactionFeeETH.multipliedBy(1000); const restartTransactionFeeETH = new BigNumber(faker.datatype.float({ min: 0, max: 0.001, precision: 0.000001 })); const restartTransactionFeeDAI = restartTransactionFeeETH.multipliedBy(1000); - const transactionNetProfit = auction.transactionGrossProfit.minus(swapTransactionFeeDAI); + for (const marketData of Object.values(auction.marketDataRecords)) { + if (marketData.transactionGrossProfit) { + marketData.transactionNetProfit = marketData.transactionGrossProfit.minus(swapTransactionFeeDAI); + } + } + const transactionNetProfit = + auction.marketDataRecords[auction.suggestedMarketId].transactionNetProfit || new BigNumber(NaN); const combinedSwapFeesETH = swapTransactionFeeETH.plus(authTransactionFeeETH).plus(authTransactionFeeETH); const combinedSwapFeesDAI = combinedSwapFeesETH.multipliedBy(1000); const combinedBidFeesETH = bidTransactionFeeETH.plus(authTransactionFeeETH).plus(authTransactionFeeETH); From 06265c158ee9c927fc95a99b96f933ee91124a39 Mon Sep 17 00:00:00 2001 From: Abdelrhman Farag Date: Sat, 5 Nov 2022 20:19:22 +0100 Subject: [PATCH 14/18] Make market price selection persist --- core/src/auctions.ts | 3 ++- .../CollateralAuctionSwapTransactionTable.vue | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/core/src/auctions.ts b/core/src/auctions.ts index 934359d97..b95fa9281 100644 --- a/core/src/auctions.ts +++ b/core/src/auctions.ts @@ -159,13 +159,14 @@ export const enrichAuctionWithMarketDataRecords = async function ( const transactionNetProfit = enrichedMarketDataRecords[suggestedMarketId].transactionNetProfit; return { ...auction, + collateralToCoverDebt, suggestedMarketId, marketUnitPrice, marketUnitPriceToUnitPriceRatio, transactionGrossProfit, transactionGrossProfitDate, transactionNetProfit: transactionNetProfit ? transactionNetProfit : new BigNumber(NaN), - marketDataRecords, + marketDataRecords: enrichedMarketDataRecords, }; } catch (error: any) { // since it's expected that some collaterals are not tradable on some networks diff --git a/frontend/components/auction/collateral/CollateralAuctionSwapTransactionTable.vue b/frontend/components/auction/collateral/CollateralAuctionSwapTransactionTable.vue index 10ab6c624..f65335091 100644 --- a/frontend/components/auction/collateral/CollateralAuctionSwapTransactionTable.vue +++ b/frontend/components/auction/collateral/CollateralAuctionSwapTransactionTable.vue @@ -21,7 +21,7 @@ {{ auctionTransaction.collateralSymbol }}
- +
Market Difference
@@ -118,24 +118,29 @@ export default Vue.extend({ default: '', }, }, + data() { + return { + currentMarketId: '', + }; + }, computed: { marketUnitPriceToUnitPriceRatio(): BigNumber | undefined { - if (!this.marketId || !this.auctionTransaction.marketDataRecords) { + if (!this.currentMarketId || !this.auctionTransaction.marketDataRecords) { return this.auctionTransaction.marketUnitPriceToUnitPriceRatio; } - return this.auctionTransaction.marketDataRecords[this.marketId].marketUnitPriceToUnitPriceRatio; + return this.auctionTransaction.marketDataRecords[this.currentMarketId].marketUnitPriceToUnitPriceRatio; }, transactionGrossProfit(): BigNumber | undefined { - if (!this.marketId || !this.auctionTransaction.marketDataRecords) { + if (!this.currentMarketId || !this.auctionTransaction.marketDataRecords) { return this.auctionTransaction.transactionGrossProfit; } - return this.auctionTransaction.marketDataRecords[this.marketId].transactionGrossProfit; + return this.auctionTransaction.marketDataRecords[this.currentMarketId].transactionGrossProfit; }, transactionNetProfit(): BigNumber | undefined { - if (!this.marketId || !this.auctionTransaction.marketDataRecords) { + if (!this.currentMarketId || !this.auctionTransaction.marketDataRecords) { return this.auctionTransaction.transactionNetProfit; } - return this.auctionTransaction.marketDataRecords[this.marketId].transactionNetProfit; + return this.auctionTransaction.marketDataRecords[this.currentMarketId].transactionNetProfit; }, }, }); From e2e543272b0e3e01772d88e6ea2810b49af8afb6 Mon Sep 17 00:00:00 2001 From: Abdelrhman Farag Date: Sat, 5 Nov 2022 22:07:51 +0100 Subject: [PATCH 15/18] Pass marketId up for execution --- .../auction/collateral/CollateralAuctionSwapTransaction.vue | 6 +++--- .../collateral/CollateralAuctionSwapTransactionTable.vue | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/frontend/components/auction/collateral/CollateralAuctionSwapTransaction.vue b/frontend/components/auction/collateral/CollateralAuctionSwapTransaction.vue index a7be0ce13..695308703 100644 --- a/frontend/components/auction/collateral/CollateralAuctionSwapTransaction.vue +++ b/frontend/components/auction/collateral/CollateralAuctionSwapTransaction.vue @@ -9,7 +9,7 @@ @@ -161,7 +161,7 @@ export default Vue.extend({ }, data() { return { - marketId: '', + currentMarketId: '', isWalletConnectedCheck: false, isWalletDAIAuthorizationCheckPassed: false, isWalletCollateralAuthorizationCheckPassed: false, @@ -189,7 +189,7 @@ export default Vue.extend({ return fees; }, marketSuggestionOrSelection(): string | undefined { - return this.marketId || this.auctionTransaction.suggestedMarketId; + return this.currentMarketId || this.auctionTransaction.suggestedMarketId; }, }, }); diff --git a/frontend/components/auction/collateral/CollateralAuctionSwapTransactionTable.vue b/frontend/components/auction/collateral/CollateralAuctionSwapTransactionTable.vue index f65335091..7b4ee0820 100644 --- a/frontend/components/auction/collateral/CollateralAuctionSwapTransactionTable.vue +++ b/frontend/components/auction/collateral/CollateralAuctionSwapTransactionTable.vue @@ -143,6 +143,11 @@ export default Vue.extend({ return this.auctionTransaction.marketDataRecords[this.currentMarketId].transactionNetProfit; }, }, + watch: { + currentMarketId(): void { + this.$emit('update:marketId', this.currentMarketId); + }, + }, }); From 5a61905fbfe4d5d9a93c343b651f6744c65e3604 Mon Sep 17 00:00:00 2001 From: Abdelrhman Farag Date: Mon, 7 Nov 2022 12:56:07 +0100 Subject: [PATCH 16/18] Sort callees ascendingly --- core/src/auctions.ts | 21 ++++++------- core/src/calleeFunctions/index.ts | 2 +- .../collateral/MarketPriceSelection.vue | 31 ++++++++++--------- frontend/store/auctions.ts | 1 - 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/core/src/auctions.ts b/core/src/auctions.ts index b95fa9281..ebbbe2032 100644 --- a/core/src/auctions.ts +++ b/core/src/auctions.ts @@ -86,31 +86,34 @@ export const enrichMarketDataRecordsWithValues = async function ( for (const marketId in marketDataRecords) { let marketData = marketDataRecords[marketId]; // enrich with values dependent on marketUnitPrice - if (marketData.marketUnitPrice.isNaN()) { + let marketUnitPrice = marketData.marketUnitPrice; + if (marketUnitPrice.isNaN()) { enrichedMarketDataRecords = { ...enrichedMarketDataRecords, [marketId]: { ...marketData }, }; continue; } + marketUnitPrice = marketUnitPrice.plus(exchangeFeePerUnitDAI); marketData = { ...marketData, - marketUnitPrice: marketData.marketUnitPrice.plus(exchangeFeePerUnitDAI), + marketUnitPrice, marketUnitPriceToUnitPriceRatio: auction.approximateUnitPrice - .minus(marketData.marketUnitPrice) - .dividedBy(marketData.marketUnitPrice), + .minus(marketUnitPrice) + .dividedBy(marketUnitPrice), ...exchangeFees, transactionGrossProfit: calculateTransactionGrossProfit( - marketData.marketUnitPrice, + marketUnitPrice, amount, auction.approximateUnitPrice ), }; // enrich with values dependent on fees if (marketData.transactionGrossProfit && auction.combinedSwapFeesDAI) { + const transactionGrossProfit = marketData.transactionGrossProfit; marketData = { ...marketData, - transactionNetProfit: marketData.transactionGrossProfit.minus(auction.combinedSwapFeesDAI), + transactionNetProfit: transactionGrossProfit.minus(auction.combinedSwapFeesDAI), }; } // enrich with values dependent on currentDate @@ -118,11 +121,7 @@ export const enrichMarketDataRecordsWithValues = async function ( const currentDate = await getNetworkDate(auction.network); marketData = { ...marketData, - transactionGrossProfitDate: calculateTransactionGrossProfitDate( - auction, - marketData.marketUnitPrice, - currentDate - ), + transactionGrossProfitDate: calculateTransactionGrossProfitDate(auction, marketUnitPrice, currentDate), }; } catch {} enrichedMarketDataRecords = { diff --git a/core/src/calleeFunctions/index.ts b/core/src/calleeFunctions/index.ts index 950007ba2..428615aa9 100644 --- a/core/src/calleeFunctions/index.ts +++ b/core/src/calleeFunctions/index.ts @@ -108,7 +108,7 @@ export const getBestMarketId = async function (marketDataRecords: Record { + // push NaNs to the end + if (a[1].marketUnitPrice.isNaN() && b[1].marketUnitPrice.isNaN()) { + return 1; } - } - sorted.sort((a, b) => a[1].marketUnitPrice.minus(b[1].marketUnitPrice).toNumber()); - return [...sorted, ...unknown]; + if (a[1].marketUnitPrice.isNaN()) { + return 1; + } + if (b[1].marketUnitPrice.isNaN()) { + return -1; + } + return a[1].marketUnitPrice.minus(b[1].marketUnitPrice).multipliedBy(-1).toNumber(); + }); + return marketDataRecordsSorted; }, }, }); diff --git a/frontend/store/auctions.ts b/frontend/store/auctions.ts index 68f763a23..eb49734de 100644 --- a/frontend/store/auctions.ts +++ b/frontend/store/auctions.ts @@ -239,7 +239,6 @@ export const actions = { alternativeDestinationAddress, }: { id: string; marketId: string; alternativeDestinationAddress: string | undefined } ) { - console.info(marketId); // to be removed after core implementation const auction = getters.getAuctionById(id); if (!auction) { message.error(`Bidding error: can not find auction with id "${id}"`); From 48a31c01f89612791802c695eef9042037ea59c9 Mon Sep 17 00:00:00 2001 From: Abdelrhman Farag <85403429+aomafarag@users.noreply.github.com> Date: Mon, 7 Nov 2022 13:12:53 +0100 Subject: [PATCH 17/18] Pre-select suggestedMarketId Co-authored-by: valia fetisov --- frontend/components/auction/collateral/MarketPriceSelection.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/components/auction/collateral/MarketPriceSelection.vue b/frontend/components/auction/collateral/MarketPriceSelection.vue index d38fc3a72..e6f6b32b0 100644 --- a/frontend/components/auction/collateral/MarketPriceSelection.vue +++ b/frontend/components/auction/collateral/MarketPriceSelection.vue @@ -27,7 +27,7 @@
From c510d3f0586679115ff8c88e23cba93b346d5a7b Mon Sep 17 00:00:00 2001 From: Abdelrhman Farag Date: Mon, 7 Nov 2022 14:14:53 +0100 Subject: [PATCH 18/18] Lint --- .../components/auction/collateral/MarketPriceSelection.vue | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/components/auction/collateral/MarketPriceSelection.vue b/frontend/components/auction/collateral/MarketPriceSelection.vue index e6f6b32b0..a58df534f 100644 --- a/frontend/components/auction/collateral/MarketPriceSelection.vue +++ b/frontend/components/auction/collateral/MarketPriceSelection.vue @@ -27,7 +27,9 @@