Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replace the usage of executedSurplusFee with executedFee #229

Merged
merged 3 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class OrderMetaData {
+ fullFeeAmount?: TokenAmount;
+ isLiquidityOrder?: boolean;
+ onchainUser?: Address;
+ executedSurplusFee?: BigUint | null;
+ executedFee?: BigUint | null;
}

class OrderStatus {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cowprotocol/cow-sdk",
"version": "5.9.0",
"version": "5.10.0-RC.0",
"license": "(MIT OR Apache-2.0)",
"files": [
"/dist"
Expand All @@ -27,7 +27,7 @@
"prepare": "npm run build",
"prepublishOnly": "npm test && npm run lint",
"graphql:codegen": "graphql-codegen --config graphql-codegen.yml",
"swagger:codegen": " openapi --input https://raw.githubusercontent.com/cowprotocol/services/v2.285.0/crates/orderbook/openapi.yml --output src/order-book/generated --exportServices false --exportCore false",
"swagger:codegen": " openapi --input https://raw.githubusercontent.com/cowprotocol/services/v2.291.0/crates/orderbook/openapi.yml --output src/order-book/generated --exportServices false --exportCore false",
"typechain:codegen": "typechain --target ethers-v5 --out-dir ./src/common/generated './abi/*.json'",
"trading:generateSchemas": "ts-node scripts/generateTradingSchemas.ts"
},
Expand Down
1 change: 0 additions & 1 deletion src/order-book/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export type { PreSignature } from './models/PreSignature';
export { PriceEstimationError } from './models/PriceEstimationError';
export type { PriceImprovement } from './models/PriceImprovement';
export { PriceQuality } from './models/PriceQuality';
export type { ProtocolAppData } from './models/ProtocolAppData';
export type { Quote } from './models/Quote';
export { SellTokenSource } from './models/SellTokenSource';
export type { Signature } from './models/Signature';
Expand Down
11 changes: 1 addition & 10 deletions src/order-book/generated/models/Auction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,10 @@ export type Auction = {
*/
id?: number;
/**
* The block number for the auction. Orders and prices are guaranteed to be valid on this
* block. Proposed settlements should be valid for this block as well.
* The block number for the auction. Orders and prices are guaranteed to be valid on this block. Proposed settlements should be valid for this block as well.
*
*/
block?: number;
/**
* The latest block on which a settlement has been processed.
*
* **NOTE**: Under certain conditions it is possible for a settlement to have been mined as
* part of `block` but not have yet been processed.
*
*/
latestSettlementBlock?: number;
/**
* The solvable orders included in the auction.
*
Expand Down
5 changes: 1 addition & 4 deletions src/order-book/generated/models/AuctionPrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import type { BigUint } from './BigUint';

/**
* The reference prices for all traded tokens in the auction as a mapping from token
* addresses to a price denominated in native token (i.e. 1e18 represents a token that
* trades one to one with the native token). These prices are used for solution competition
* for computing surplus and converting fees to native token.
* The reference prices for all traded tokens in the auction as a mapping from token addresses to a price denominated in native token (i.e. 1e18 represents a token that trades one to one with the native token). These prices are used for solution competition for computing surplus and converting fees to native token.
*
*/
export type AuctionPrices = Record<string, BigUint>;
6 changes: 4 additions & 2 deletions src/order-book/generated/models/CompetitionOrderStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import type { ExecutedAmounts } from './ExecutedAmounts';
export type CompetitionOrderStatus = {
type: CompetitionOrderStatus.type;
/**
* A list of solvers who participated in the latest competition, sorted by score in ascending order, where the last element is the winner.
* The presence of executed amounts defines whether the solver provided a solution for the desired order.
* A list of solvers who participated in the latest competition, sorted
* by score in ascending order, where the last element is the winner.
*
* The presence of executed amounts defines whether the solver provided
* a solution for the desired order.
*/
value?: Array<{
/**
Expand Down
6 changes: 0 additions & 6 deletions src/order-book/generated/models/ExecutedProtocolFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ import type { TokenAmount } from './TokenAmount';

export type ExecutedProtocolFee = {
policy?: FeePolicy;
/**
* Fee amount taken
*/
amount?: TokenAmount;
/**
* The token in which the fee is taken
*/
token?: Address;
};

12 changes: 3 additions & 9 deletions src/order-book/generated/models/OnchainOrderData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ import type { Address } from './Address';

export type OnchainOrderData = {
/**
* If orders are placed as on-chain orders, the owner of the order might
* be a smart contract, but not the user placing the order. The
* actual user will be provided in this field.
* If orders are placed as on-chain orders, the owner of the order might be a smart contract, but not the user placing the order. The actual user will be provided in this field.
*
*/
sender: Address;
/**
* Describes the error, if the order placement was not successful. This could
* happen, for example, if the `validTo` is too high, or no valid quote was
* found or generated.
* Describes the error, if the order placement was not successful. This could happen, for example, if the `validTo` is too high, or no valid quote was found or generated.
*
*/
placementError?: OnchainOrderData.placementError;
Expand All @@ -24,9 +20,7 @@ export type OnchainOrderData = {
export namespace OnchainOrderData {

/**
* Describes the error, if the order placement was not successful. This could
* happen, for example, if the `validTo` is too high, or no valid quote was
* found or generated.
* Describes the error, if the order placement was not successful. This could happen, for example, if the `validTo` is too high, or no valid quote was found or generated.
*
*/
export enum placementError {
Expand Down
16 changes: 4 additions & 12 deletions src/order-book/generated/models/OrderCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,22 @@ export type OrderCreation = {
signingScheme: SigningScheme;
signature: Signature;
/**
* If set, the backend enforces that this address matches what is decoded as the *signer* of
* the signature. This helps catch errors with invalid signature encodings as the backend
* might otherwise silently work with an unexpected address that for example does not have
* any balance.
* If set, the backend enforces that this address matches what is decoded as the *signer* of the signature. This helps catch errors with invalid signature encodings as the backend might otherwise silently work with an unexpected address that for example does not have any balance.
*
*/
from?: Address | null;
/**
* Orders can optionally include a quote ID. This way the order can be linked to a quote
* and enable providing more metadata when analysing order slippage.
* Orders can optionally include a quote ID. This way the order can be linked to a quote and enable providing more metadata when analysing order slippage.
*
*/
quoteId?: number | null;
/**
* This field comes in two forms for backward compatibility. The hash form will eventually
* stop being accepted.
* This field comes in two forms for backward compatibility. The hash form will eventually stop being accepted.
*
*/
appData: (AppData | AppDataHash);
/**
* May be set for debugging purposes. If set, this field is compared to what the backend
* internally calculates as the app data hash based on the contents of `appData`. If the
* hash does not match, an error is returned. If this field is set, then `appData` **MUST** be
* a string encoding of a JSON object.
* May be set for debugging purposes. If set, this field is compared to what the backend internally calculates as the app data hash based on the contents of `appData`. If the hash does not match, an error is returned. If this field is set, then `appData` **MUST** be a string encoding of a JSON object.
*
*/
appDataHash?: AppDataHash | null;
Expand Down
37 changes: 20 additions & 17 deletions src/order-book/generated/models/OrderMetaData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import type { TokenAmount } from './TokenAmount';
import type { UID } from './UID';

/**
* Extra order data that is returned to users when querying orders but not provided by users
* when creating orders.
* Extra order data that is returned to users when querying orders but not provided by users when creating orders.
*
*/
export type OrderMetaData = {
Expand Down Expand Up @@ -62,40 +61,44 @@ export type OrderMetaData = {
*/
fullFeeAmount?: TokenAmount;
/**
* Liquidity orders are functionally the same as normal smart contract orders but are not
* placed with the intent of actively getting traded. Instead they facilitate the
* trade of normal orders by allowing them to be matched against liquidity orders which
* uses less gas and can have better prices than external liquidity.
*
* As such liquidity orders will only be used in order to improve settlement of normal
* orders. They should not be expected to be traded otherwise and should not expect to get
* surplus.
* Liquidity orders are functionally the same as normal smart contract
* orders but are not placed with the intent of actively getting
* traded. Instead they facilitate the trade of normal orders by
* allowing them to be matched against liquidity orders which uses less
* gas and can have better prices than external liquidity.
*
* As such liquidity orders will only be used in order to improve
* settlement of normal orders. They should not be expected to be
* traded otherwise and should not expect to get surplus.
*/
isLiquidityOrder?: boolean;
ethflowData?: EthflowData;
/**
* This represents the actual trader of an on-chain order.
*
* ### ethflow orders
*
* In this case, the `owner` would be the `EthFlow` contract and *not* the actual trader.
*
*/
onchainUser?: Address;
/**
* There is some data only available for orders that are placed on-chain. This data
* can be found in this object.
* There is some data only available for orders that are placed on-chain. This data can be found in this object.
*
*/
onchainOrderData?: OnchainOrderData;
/**
* Surplus fee that the limit order was executed with.
*/
executedSurplusFee?: BigUint | null;
executedSurplusFee?: BigUint;
/**
* Total fee charged for execution of the order. Contains network fee and protocol fees.
*/
executedFee?: BigUint;
/**
* Token the executed fee was captured in.
*/
executedFeeToken?: Address;
/**
* Full `appData`, which the contract-level `appData` is a hash of. See `OrderCreation`
* for more information.
* Full `appData`, which the contract-level `appData` is a hash of. See `OrderCreation` for more information.
*
*/
fullAppData?: string | null;
Expand Down
3 changes: 1 addition & 2 deletions src/order-book/generated/models/OrderParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ export type OrderParameters = {
*/
buyToken: Address;
/**
* An optional Ethereum address to receive the proceeds of the trade instead
* of the owner (i.e. the order signer).
* An optional Ethereum address to receive the proceeds of the trade instead of the owner (i.e. the order signer).
*
*/
receiver?: Address | null;
Expand Down
18 changes: 11 additions & 7 deletions src/order-book/generated/models/OrderQuoteRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,22 @@ export type OrderQuoteRequest = (OrderQuoteSide & OrderQuoteValidity & {
receiver?: Address | null;
/**
* AppData which will be assigned to the order.
* Expects either a string JSON doc as defined on [AppData](https://github.com/cowprotocol/app-data) or a
* hex encoded string for backwards compatibility.
* When the first format is used, it's possible to provide the derived appDataHash field.
*
* Expects either a string JSON doc as defined on
* [AppData](https://github.com/cowprotocol/app-data) or a hex
* encoded string for backwards compatibility.
*
* When the first format is used, it's possible to provide the
* derived appDataHash field.
*/
appData?: (AppData | AppDataHash);
/**
* The hash of the stringified JSON appData doc.
* If present, `appData` field must be set with the aforementioned data where this hash is derived from.
* In case they differ, the call will fail.
*
* If present, `appData` field must be set with the aforementioned
* data where this hash is derived from.
*
* In case they differ, the call will fail.
*/
appDataHash?: AppDataHash;
sellTokenBalance?: SellTokenSource;
Expand All @@ -51,8 +56,7 @@ export type OrderQuoteRequest = (OrderQuoteSide & OrderQuoteValidity & {
priceQuality?: PriceQuality;
signingScheme?: SigningScheme;
/**
* Flag to signal whether the order is intended for on-chain order placement. Only valid
* for non ECDSA-signed orders."
* Flag to signal whether the order is intended for on-chain order placement. Only valid for non ECDSA-signed orders."
*
*/
onchainOrder?: any;
Expand Down
3 changes: 1 addition & 2 deletions src/order-book/generated/models/OrderQuoteResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export type OrderQuoteResponse = {
*/
expiration: string;
/**
* Quote ID linked to a quote to enable providing more metadata when analysing
* order slippage.
* Quote ID linked to a quote to enable providing more metadata when analysing order slippage.
*
*/
id?: number;
Expand Down
3 changes: 1 addition & 2 deletions src/order-book/generated/models/OrderQuoteSide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import type { TokenAmount } from './TokenAmount';
export type OrderQuoteSide = ({
kind: OrderQuoteSideKindSell;
/**
* The total amount that is available for the order. From this value, the fee
* is deducted and the buy amount is calculated.
* The total amount that is available for the order. From this value, the fee is deducted and the buy amount is calculated.
*
*/
sellAmountBeforeFee: TokenAmount;
Expand Down
7 changes: 4 additions & 3 deletions src/order-book/generated/models/PriceQuality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
*
* Fast: The price estimate is chosen among the fastest N price estimates.
* Optimal: The price estimate is chosen among all price estimates.
* Verified: The price estimate is chosen among all verified/simulated price estimates.
*
* **NOTE**: Orders are supposed to be created from `verified` or `optimal` price estimates.
* Verified: The price estimate is chosen among all verified/simulated
* price estimates.
*
* **NOTE**: Orders are supposed to be created from `verified` or `optimal`
* price estimates.
*/
export enum PriceQuality {
FAST = 'fast',
Expand Down
7 changes: 0 additions & 7 deletions src/order-book/generated/models/ProtocolAppData.ts

This file was deleted.

7 changes: 6 additions & 1 deletion src/order-book/generated/models/SolverSettlement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ export type SolverSettlement = {
solver?: string;
/**
* The address used by the solver to execute the settlement on-chain.
* This field is missing for old settlements, the zero address has been used instead.
*
* This field is missing for old settlements, the zero address has been
* used instead.
*/
solverAddress?: string;
objective?: {
Expand Down Expand Up @@ -44,5 +45,9 @@ export type SolverSettlement = {
id?: UID;
executedAmount?: BigUint;
}>;
/**
* whether the solution is a winner (received the right to get executed) or not
*/
isWinner?: boolean;
};

7 changes: 4 additions & 3 deletions src/order-book/generated/models/UID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
/* eslint-disable */

/**
* Unique identifier for the order: 56 bytes encoded as hex with `0x` prefix.
* Bytes 0..32 are the order digest, bytes 30..52 the owner address and bytes
* 52..56 the expiry (`validTo`) as a `uint32` unix epoch timestamp.
* Unique identifier for the order: 56 bytes encoded as hex with `0x`
* prefix.
*
* Bytes 0..32 are the order digest, bytes 30..52 the owner address and
* bytes 52..56 the expiry (`validTo`) as a `uint32` unix epoch timestamp.
*/
export type UID = string;
16 changes: 8 additions & 8 deletions src/order-book/transformOrder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,29 @@ const ORDER: Order = {

describe('transformOrder', () => {
describe('addTotalFeeToOrder', () => {
test('should use executedFeeAmount when executedSurplusFee is 0', () => {
const rawOrder = { ...ORDER, executedFeeAmount: '1', executedSurplusFee: '0' }
test('should use executedFeeAmount when executedFee is 0', () => {
const rawOrder = { ...ORDER, executedFeeAmount: '1', executedFee: '0' }
const transformedOrder = transformOrder(rawOrder)

expect(transformedOrder.totalFee).toEqual('1')
})

test('should use executedSurplusFee when executedFeeAmount is 0', () => {
const rawOrder = { ...ORDER, executedFeeAmount: '0', executedSurplusFee: '1' }
test('should use executedFee when executedFeeAmount is 0', () => {
const rawOrder = { ...ORDER, executedFeeAmount: '0', executedFee: '1' }
const transformedOrder = transformOrder(rawOrder)

expect(transformedOrder.totalFee).toEqual('1')
})

test('should use sum of executedFeeAmount and executedSurplusFee', () => {
const rawOrder = { ...ORDER, executedFeeAmount: '1', executedSurplusFee: '1' }
test('should use sum of executedFeeAmount and executedFee', () => {
const rawOrder = { ...ORDER, executedFeeAmount: '1', executedFee: '1' }
const transformedOrder = transformOrder(rawOrder)

expect(transformedOrder.totalFee).toEqual('2')
})

test('should not fail when executedSurplusFee is falsy', () => {
const rawOrder = { ...ORDER, executedSurplusFee: null }
test('should not fail when executedFee is falsy', () => {
const rawOrder = { ...ORDER, executedFee: undefined }
const transformedOrder = transformOrder(rawOrder)

expect(transformedOrder.totalFee).toEqual('1234567890')
Expand Down
Loading
Loading