Skip to content

Commit

Permalink
fix: Updated displayed fees on bidding transaction page (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
fegbert authored May 25, 2022
1 parent 2083719 commit 66dd011
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 41 deletions.
34 changes: 22 additions & 12 deletions core/src/fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ export const getApproximateTransactionFees = async function (network: string): P

// TODO: figure out a way to properly estimate gas
// for each transaction when no wallet is connected
const biddingTransactionFeeETH = gasPrice.multipliedBy(722651);
const bidTransactionFeeETH = gasPrice.multipliedBy(145438);
const swapTransactionFeeETH = gasPrice.multipliedBy(722651);
const authTransactionFeeETH = gasPrice.multipliedBy(48356);
const restartTransactionFeeETH = gasPrice.multipliedBy(209182);

return {
biddingTransactionFeeETH,
biddingTransactionFeeDAI: await convertETHtoDAI(network, biddingTransactionFeeETH),
bidTransactionFeeETH,
bidTransactionFeeDAI: await convertETHtoDAI(network, bidTransactionFeeETH),
swapTransactionFeeETH,
swapTransactionFeeDAI: await convertETHtoDAI(network, swapTransactionFeeETH),
authTransactionFeeETH,
authTransactionFeeDAI: await convertETHtoDAI(network, authTransactionFeeETH),
restartTransactionFeeETH,
Expand All @@ -34,7 +37,8 @@ export const enrichAuctionWithTransactionFees = async function (
fees: TransactionFees,
network: string
): Promise<AuctionTransaction> {
let totalFeeETH = fees.biddingTransactionFeeETH;
let combinedSwapFeesETH = fees.swapTransactionFeeETH;
let combinedBidFeesETH = fees.bidTransactionFeeETH;

try {
const signer = await getSigner(network);
Expand All @@ -47,24 +51,30 @@ export const enrichAuctionWithTransactionFees = async function (
);

if (!isWalletAuthed) {
totalFeeETH = totalFeeETH.plus(fees.authTransactionFeeETH);
combinedSwapFeesETH = combinedSwapFeesETH.plus(fees.authTransactionFeeETH);
combinedBidFeesETH = combinedBidFeesETH.plus(fees.authTransactionFeeETH);
}
if (!isCollateralAuthed) {
totalFeeETH = totalFeeETH.plus(fees.authTransactionFeeETH);
combinedSwapFeesETH = combinedSwapFeesETH.plus(fees.authTransactionFeeETH);
combinedBidFeesETH = combinedSwapFeesETH.plus(fees.authTransactionFeeETH);
}
} catch (e) {
totalFeeETH = totalFeeETH.plus(fees.authTransactionFeeETH).plus(fees.authTransactionFeeETH);
combinedSwapFeesETH = combinedSwapFeesETH.plus(fees.authTransactionFeeETH).plus(fees.authTransactionFeeETH);
combinedBidFeesETH = combinedBidFeesETH.plus(fees.authTransactionFeeETH).plus(fees.authTransactionFeeETH);
}

const totalFeeDAI = await convertETHtoDAI(network, totalFeeETH);
const combinedSwapFeesDAI = await convertETHtoDAI(network, combinedSwapFeesETH);
const combinedBidFeesDAI = await convertETHtoDAI(network, combinedBidFeesETH);
const auctionTransaction = {
...auction,
...fees,
totalFeeETH: totalFeeETH,
totalFeeDAI: totalFeeDAI,
combinedBidFeesETH: combinedBidFeesETH,
combinedBidFeesDAI: combinedBidFeesDAI,
combinedSwapFeesETH: combinedSwapFeesETH,
combinedSwapFeesDAI: combinedSwapFeesDAI,
} as AuctionTransaction;
if (auction.transactionGrossProfit && fees.biddingTransactionFeeDAI) {
auctionTransaction.transactionNetProfit = auction.transactionGrossProfit.minus(totalFeeDAI);
if (auction.transactionGrossProfit && fees.swapTransactionFeeDAI) {
auctionTransaction.transactionNetProfit = auction.transactionGrossProfit.minus(combinedSwapFeesDAI);
}
return auctionTransaction;
};
12 changes: 8 additions & 4 deletions core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ export declare interface Auction extends AuctionInitialInfo {
}

export declare interface TransactionFees {
biddingTransactionFeeETH: BigNumber;
biddingTransactionFeeDAI: BigNumber;
bidTransactionFeeETH: BigNumber;
bidTransactionFeeDAI: BigNumber;
swapTransactionFeeETH: BigNumber;
swapTransactionFeeDAI: BigNumber;
authTransactionFeeETH: BigNumber;
authTransactionFeeDAI: BigNumber;
restartTransactionFeeETH: BigNumber;
Expand All @@ -64,8 +66,10 @@ export declare interface CollateralRow extends CollateralConfig, Partial<MakerPa

export declare interface AuctionTransaction extends Auction, TransactionFees {
transactionNetProfit: BigNumber;
totalFeeDAI: BigNumber;
totalFeeETH: BigNumber;
combinedBidFeesDAI: BigNumber;
combinedBidFeesETH: BigNumber;
combinedSwapFeesDAI: BigNumber;
combinedSwapFeesETH: BigNumber;
}

export declare interface RegularCalleeConfig {
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/GasTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@
<td class="Body">
<FormatCurrency
v-if="transactionFees"
:value="transactionFees.biddingTransactionFeeETH"
:value="transactionFees.swapTransactionFeeETH"
currency="ETH"
/>
<span v-else class="UnknownValue"> Unknown </span>
</td>
<td class="Body">
<FormatCurrency
v-if="transactionFees"
:value="transactionFees.biddingTransactionFeeDAI"
:value="transactionFees.swapTransactionFeeDAI"
currency="DAI"
/>
<span v-else class="UnknownValue"> Unknown </span>
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/transaction/BidBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TransactionMessage
:is-explanations-shown="isExplanationsShown"
:transaction-address="auctionTransaction.transactionAddress"
:transaction-fee="auctionTransaction.biddingTransactionFeeETH"
:transaction-fee="auctionTransaction.swapTransactionFeeETH"
/>
<div class="flex flex-row-reverse mt-3">
<BaseButton
Expand Down
8 changes: 4 additions & 4 deletions frontend/components/transaction/BidTransactionTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
<span class="text-gray-300">
(~
<FormatCurrency
v-if="auctionTransaction.biddingTransactionFeeETH"
:value="auctionTransaction.biddingTransactionFeeETH"
v-if="auctionTransaction.combinedBidFeesETH"
:value="auctionTransaction.combinedBidFeesETH"
:decimals="5"
/>
<span v-else>Unknown</span>
Expand All @@ -42,8 +42,8 @@
</div>
<div>
<FormatCurrency
v-if="auctionTransaction.biddingTransactionFeeDAI"
:value="auctionTransaction.biddingTransactionFeeDAI * -1"
v-if="auctionTransaction.combinedBidFeesDAI"
:value="auctionTransaction.combinedBidFeesDAI * -1"
currency="DAI"
/>
<span v-else class="opacity-50">Unknown</span>
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/transaction/SwapTransaction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
:wallet-address="walletAddress"
:is-explanations-shown="isExplanationsShown"
:collateral-type="auctionTransaction.collateralType"
:transaction-fee="auctionTransaction.biddingTransactionFeeETH"
:transaction-fee="auctionTransaction.swapTransactionFeeETH"
:transaction-gross-profit="auctionTransaction.transactionGrossProfit"
@execute="$emit('execute', { id: auctionTransaction.id, alternativeDestinationAddress: $event })"
/>
Expand Down
8 changes: 4 additions & 4 deletions frontend/components/transaction/SwapTransactionTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
Combined Transactions Fees
<span class="text-gray-300"
>(~<FormatCurrency
v-if="auctionTransaction.totalFeeETH"
:value="auctionTransaction.totalFeeETH"
v-if="auctionTransaction.combinedSwapFeesETH"
:value="auctionTransaction.combinedSwapFeesETH"
:decimals="5"
/>
<span v-else>Unknown</span>
Expand All @@ -73,8 +73,8 @@
</div>
<div class="RightInfo">
<FormatCurrency
v-if="auctionTransaction.totalFeeDAI"
:value="auctionTransaction.totalFeeDAI * -1"
v-if="auctionTransaction.combinedSwapFeesDAI"
:value="auctionTransaction.combinedSwapFeesDAI * -1"
currency="DAI"
/>
<span v-else class="opacity-50">Unknown</span>
Expand Down
18 changes: 9 additions & 9 deletions frontend/helpers/generateFakeAuction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,24 @@ export const generateFakeAuction = function () {

export const generateFakeAuctionTransaction = function () {
const auction = generateFakeAuction();
const biddingTransactionFeeETH = new BigNumber(faker.datatype.float({ min: 0, max: 0.001, precision: 0.000001 }));
const biddingTransactionFeeDAI = biddingTransactionFeeETH.multipliedBy(1000);
const swapTransactionFeeETH = new BigNumber(faker.datatype.float({ min: 0, max: 0.001, precision: 0.000001 }));
const swapTransactionFeeDAI = swapTransactionFeeETH.multipliedBy(1000);
const authTransactionFeeETH = new BigNumber(faker.datatype.float({ min: 0, max: 0.001, precision: 0.000001 }));
const authTransactionFeeDAI = authTransactionFeeETH.multipliedBy(1000);
const restartTransactionFeeETH = new BigNumber(faker.datatype.float({ min: 0, max: 0.001, precision: 0.000001 }));
const transactionNetProfit = auction.transactionGrossProfit.minus(biddingTransactionFeeDAI);
const totalFeeETH = biddingTransactionFeeETH.plus(authTransactionFeeETH);
const totalFeeDAI = totalFeeETH.multipliedBy(1000);
const transactionNetProfit = auction.transactionGrossProfit.minus(swapTransactionFeeDAI);
const combinedSwapFeesETH = swapTransactionFeeETH.plus(authTransactionFeeETH);
const combinedSwapFeesDAI = combinedSwapFeesETH.multipliedBy(1000);
return {
...auction,
biddingTransactionFeeETH,
biddingTransactionFeeDAI,
swapTransactionFeeETH,
swapTransactionFeeDAI,
authTransactionFeeETH,
authTransactionFeeDAI,
restartTransactionFeeETH,
transactionNetProfit,
totalFeeETH,
totalFeeDAI,
combinedSwapFeesETH,
combinedSwapFeesDAI,
};
};

Expand Down
12 changes: 8 additions & 4 deletions frontend/helpers/generateFakeGas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ export function generateFakeGasParameters(): GasParameters {
}

export function generateFakeTransactionFees(): TransactionFees {
const biddingTransactionFeeETH = new BigNumber(faker.datatype.float({ min: 0, max: 0.001, precision: 0.000001 }));
const biddingTransactionFeeDAI = biddingTransactionFeeETH.multipliedBy(1000);
const bidTransactionFeeETH = new BigNumber(faker.datatype.float({ min: 0, max: 0.001, precision: 0.000001 }));
const bidTransactionFeeDAI = bidTransactionFeeETH.multipliedBy(1000);
const swapTransactionFeeETH = new BigNumber(faker.datatype.float({ min: 0, max: 0.001, precision: 0.000001 }));
const swapTransactionFeeDAI = swapTransactionFeeETH.multipliedBy(1000);
const authTransactionFeeETH = new BigNumber(faker.datatype.float({ min: 0, max: 0.001, precision: 0.000001 }));
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);

return {
biddingTransactionFeeETH,
biddingTransactionFeeDAI,
bidTransactionFeeETH,
bidTransactionFeeDAI,
swapTransactionFeeETH,
swapTransactionFeeDAI,
authTransactionFeeETH,
authTransactionFeeDAI,
restartTransactionFeeETH,
Expand Down

0 comments on commit 66dd011

Please sign in to comment.