Skip to content

Commit

Permalink
Add executedSurplusFee to TwapOrders
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorgomezv committed Jul 2, 2024
1 parent cba4fb4 commit 048e2c7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ export class CowSwapTwapConfirmationView implements Baseline, TwapOrderInfo {
})
executedSellAmount: string | null;

@ApiPropertyOptional({
nullable: true,
description:
'The executed surplus fee raw amount (no decimals), or null if there are too many parts',
})
executedSurplusFee: string | null;

@ApiPropertyOptional({
nullable: true,
description:
Expand Down Expand Up @@ -276,6 +283,7 @@ export class CowSwapTwapConfirmationView implements Baseline, TwapOrderInfo {
buyAmount: string;
executedSellAmount: string | null;
executedBuyAmount: string | null;
executedSurplusFee: string | null;
sellToken: TokenInfo;
buyToken: TokenInfo;
receiver: `0x${string}`;
Expand All @@ -298,6 +306,7 @@ export class CowSwapTwapConfirmationView implements Baseline, TwapOrderInfo {
this.buyAmount = args.buyAmount;
this.executedSellAmount = args.executedSellAmount;
this.executedBuyAmount = args.executedBuyAmount;
this.executedSurplusFee = args.executedSurplusFee;
this.sellToken = args.sellToken;
this.buyToken = args.buyToken;
this.receiver = args.receiver;
Expand Down
10 changes: 10 additions & 0 deletions src/routes/transactions/entities/swaps/twap-order-info.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type TwapOrderInfo = {
buyAmount: string;
executedSellAmount: string | null;
executedBuyAmount: string | null;
executedSurplusFee: string | null;
sellToken: TokenInfo;
buyToken: TokenInfo;
receiver: `0x${string}`;
Expand Down Expand Up @@ -100,6 +101,13 @@ export class TwapOrderTransactionInfo
})
executedBuyAmount: string | null;

@ApiPropertyOptional({
nullable: true,
description:
'The executed surplus fee raw amount (no decimals), or null if there are too many parts',
})
executedSurplusFee: string | null;

@ApiProperty({ description: 'The sell token of the TWAP' })
sellToken: TokenInfo;

Expand Down Expand Up @@ -162,6 +170,7 @@ export class TwapOrderTransactionInfo
buyAmount: string;
executedSellAmount: string | null;
executedBuyAmount: string | null;
executedSurplusFee: string | null;
sellToken: TokenInfo;
buyToken: TokenInfo;
receiver: `0x${string}`;
Expand All @@ -183,6 +192,7 @@ export class TwapOrderTransactionInfo
this.buyAmount = args.buyAmount;
this.executedSellAmount = args.executedSellAmount;
this.executedBuyAmount = args.executedBuyAmount;
this.executedSurplusFee = args.executedSurplusFee;
this.sellToken = args.sellToken;
this.buyToken = args.buyToken;
this.receiver = args.receiver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ describe('TwapOrderMapper', () => {
},
executedBuyAmount: '0',
executedSellAmount: '0',
executedSurplusFee: '0',
fullAppData,
humanDescription: null,
kind: 'sell',
Expand Down Expand Up @@ -203,7 +204,7 @@ describe('TwapOrderMapper', () => {
executedSellAmount: '213586875483862141750',
executedSellAmountBeforeFees: '213586875483862141750',
executedFeeAmount: '0',
executedSurplusFee: '2135868754838621119',
executedSurplusFee: '111111111',
invalidated: false,
status: 'fulfilled',
class: 'limit',
Expand Down Expand Up @@ -243,7 +244,7 @@ describe('TwapOrderMapper', () => {
executedSellAmount: '213586875483862141750',
executedSellAmountBeforeFees: '213586875483862141750',
executedFeeAmount: '0',
executedSurplusFee: '2135868754838621123',
executedSurplusFee: '111111111',
invalidated: false,
status: 'fulfilled',
class: 'limit',
Expand Down Expand Up @@ -320,6 +321,7 @@ describe('TwapOrderMapper', () => {
},
executedBuyAmount: '1379444631694674400',
executedSellAmount: '427173750967724300000',
executedSurplusFee: '222222222',
fullAppData,
humanDescription: null,
kind: 'sell',
Expand Down Expand Up @@ -455,6 +457,7 @@ describe('TwapOrderMapper', () => {
},
executedBuyAmount: null,
executedSellAmount: null,
executedSurplusFee: null,
fullAppData,
humanDescription: null,
kind: 'sell',
Expand Down
10 changes: 10 additions & 0 deletions src/routes/transactions/mappers/common/twap-order.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ export class TwapOrderMapper {
const executedBuyAmount: TwapOrderInfo['executedBuyAmount'] =
hasAbundantParts ? null : this.getExecutedBuyAmount(orders).toString();

const executedSurplusFee: TwapOrderInfo['executedSurplusFee'] =
hasAbundantParts ? null : this.getExecutedSurplusFee(orders).toString();

const [sellToken, buyToken] = await Promise.all([
this.swapOrderHelper.getToken({
chainId,
Expand All @@ -139,6 +142,7 @@ export class TwapOrderMapper {
buyAmount: twapOrderData.buyAmount,
executedSellAmount,
executedBuyAmount,
executedSurplusFee,
sellToken: new TokenInfo({
address: sellToken.address,
decimals: sellToken.decimals,
Expand Down Expand Up @@ -211,6 +215,12 @@ export class TwapOrderMapper {
return acc + Number(order.executedBuyAmount);
}, 0);
}

private getExecutedSurplusFee(orders: Array<KnownOrder>): number {
return orders.reduce((acc, order) => {
return acc + Number(order.executedSurplusFee);
}, 0);
}
}

@Module({
Expand Down
1 change: 1 addition & 0 deletions src/routes/transactions/transactions-view.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export class TransactionsViewService {
buyAmount: twapOrderData.buyAmount,
executedSellAmount: '0',
executedBuyAmount: '0',
executedSurplusFee: '0',
sellToken: new TokenInfo({
address: sellToken.address,
decimals: sellToken.decimals,
Expand Down

0 comments on commit 048e2c7

Please sign in to comment.