Skip to content

Commit 365a604

Browse files
committed
chore: add mapQuoteAmountsAndCosts util
1 parent 54e279b commit 365a604

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cowprotocol/cow-sdk",
3-
"version": "5.8.0-RC.6",
3+
"version": "5.8.0-RC.7",
44
"license": "(MIT OR Apache-2.0)",
55
"files": [
66
"/dist"

src/trading/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ export { getEthFlowTransaction } from './getEthFlowTransaction'
1818

1919
export * from './appDataUtils'
2020
export * from './calculateUniqueOrderId'
21-
export { swapParamsToLimitOrderParams } from './utils'
21+
export { swapParamsToLimitOrderParams, mapQuoteAmountsAndCosts } from './utils'

src/trading/utils.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,39 @@ export function getSigner(signer: Signer | ExternalProvider | PrivateKey): Signe
3636
export function isAccountAddress(address: any): address is AccountAddress {
3737
return typeof address === 'string' && /^0x[0-9a-fA-F]{40}$/.test(address)
3838
}
39+
40+
export function mapQuoteAmountsAndCosts<T, R>(
41+
value: QuoteAmountsAndCosts<T>,
42+
mapper: (value: T) => R
43+
): QuoteAmountsAndCosts<R> {
44+
const {
45+
costs: { networkFee, partnerFee },
46+
} = value
47+
48+
function serializeAmounts(value: { sellAmount: T; buyAmount: T }): { sellAmount: R; buyAmount: R } {
49+
return {
50+
sellAmount: mapper(value.sellAmount),
51+
buyAmount: mapper(value.buyAmount),
52+
}
53+
}
54+
55+
return {
56+
...value,
57+
costs: {
58+
...value.costs,
59+
networkFee: {
60+
...networkFee,
61+
amountInSellCurrency: mapper(networkFee.amountInSellCurrency),
62+
amountInBuyCurrency: mapper(networkFee.amountInBuyCurrency),
63+
},
64+
partnerFee: {
65+
...partnerFee,
66+
amount: mapper(partnerFee.amount),
67+
},
68+
},
69+
beforeNetworkCosts: serializeAmounts(value.beforeNetworkCosts),
70+
afterNetworkCosts: serializeAmounts(value.afterNetworkCosts),
71+
afterPartnerFees: serializeAmounts(value.afterPartnerFees),
72+
afterSlippage: serializeAmounts(value.afterSlippage),
73+
}
74+
}

0 commit comments

Comments
 (0)