Skip to content

Commit f040892

Browse files
authored
update chainflip protocol fee return (#1569)
* update chainflip protocol fee return * update * fix test * update * fix tests
1 parent 01e5051 commit f040892

File tree

5 files changed

+31
-19
lines changed

5 files changed

+31
-19
lines changed

.changeset/some-parks-yell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@xchainjs/xchain-aggregator': patch
3+
---
4+
5+
Chainflip to return network fee & affiliate fee

packages/xchain-aggregator/__e2e__/chainflip-broker.e2e.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,12 @@ describe('Chainflip protocol with broker - E2E', () => {
9090
destinationAddress: await wallet.getAddress(AssetBTC.chain),
9191
})
9292

93-
const brokerAffiliateFee = estimatedSwapWithBroker.fees.affiliateFee.baseAmount.amount()
94-
const noBrokerAffiliateFee = estimatedSwapWithoutBroker.fees.affiliateFee.baseAmount.amount()
95-
96-
console.log('Broker affiliate fee:', brokerAffiliateFee.toString())
97-
console.log('Non-broker affiliate fee:', noBrokerAffiliateFee.toString())
93+
console.log('Broker affiliate fee:', estimatedSwapWithBroker.fees.affiliateFee.formatedAssetString())
94+
console.log('Non-broker affiliate fee:', estimatedSwapWithoutBroker.fees.affiliateFee.formatedAssetString())
95+
console.log(
96+
'Network fee:',
97+
estimatedSwapWithoutBroker.fees.networkFee ? estimatedSwapWithoutBroker.fees.networkFee.formatedAssetString() : 0,
98+
)
9899

99100
// With broker configuration, affiliate fees should be higher (broker takes commission)
100101
// This test might need adjustment based on actual broker behavior

packages/xchain-aggregator/__tests__/chainflipProtocol.test.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,12 @@ describe('Chainflip protocol', () => {
100100
expect(assetToString(estimatedSwap.dustThreshold.asset)).toBe('ETH.ETH')
101101
expect(estimatedSwap.dustThreshold.baseAmount.amount().toString()).toBe('10000000000000000')
102102
expect(estimatedSwap.dustThreshold.baseAmount.decimal).toBe(18)
103-
expect(assetToString(estimatedSwap.fees.asset)).toBe('BTC.BTC')
104-
expect(assetToString(estimatedSwap.fees.affiliateFee.asset)).toBe('BTC.BTC')
103+
expect(assetToString(estimatedSwap.fees.asset)).toBe('ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48')
104+
expect(assetToString(estimatedSwap.fees.affiliateFee.asset)).toBe(
105+
'ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48',
106+
)
105107
expect(estimatedSwap.fees.affiliateFee.baseAmount.amount().toString()).toBe('0')
106-
expect(estimatedSwap.fees.affiliateFee.baseAmount.decimal).toBe(8)
108+
expect(estimatedSwap.fees.affiliateFee.baseAmount.decimal).toBe(6)
107109
expect(assetToString(estimatedSwap.fees.outboundFee.asset)).toBe('BTC.BTC')
108110
expect(estimatedSwap.fees.outboundFee.baseAmount.amount().toString()).toBe('1599')
109111
expect(estimatedSwap.fees.outboundFee.baseAmount.decimal).toBe(8)
@@ -135,10 +137,12 @@ describe('Chainflip protocol', () => {
135137
expect(assetToString(estimatedSwap.dustThreshold.asset)).toBe('ETH.USDT-0xdAC17F958D2ee523a2206206994597C13D831ec7')
136138
expect(estimatedSwap.dustThreshold.baseAmount.amount().toString()).toBe('20000000')
137139
expect(estimatedSwap.dustThreshold.baseAmount.decimal).toBe(6)
138-
expect(assetToString(estimatedSwap.fees.asset)).toBe('ETH.ETH')
139-
expect(assetToString(estimatedSwap.fees.affiliateFee.asset)).toBe('ETH.ETH')
140+
expect(assetToString(estimatedSwap.fees.asset)).toBe('ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48')
141+
expect(assetToString(estimatedSwap.fees.affiliateFee.asset)).toBe(
142+
'ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48',
143+
)
140144
expect(estimatedSwap.fees.affiliateFee.baseAmount.amount().toString()).toBe('0')
141-
expect(estimatedSwap.fees.affiliateFee.baseAmount.decimal).toBe(18)
145+
expect(estimatedSwap.fees.affiliateFee.baseAmount.decimal).toBe(6)
142146
expect(assetToString(estimatedSwap.fees.outboundFee.asset)).toBe('ETH.ETH')
143147
expect(estimatedSwap.fees.outboundFee.baseAmount.amount().toString()).toBe('1447621978320000')
144148
expect(estimatedSwap.fees.outboundFee.baseAmount.decimal).toBe(18)
@@ -172,9 +176,9 @@ describe('Chainflip protocol', () => {
172176
expect(assetToString(estimatedSwap.dustThreshold.asset)).toBe('ETH.ETH')
173177
expect(estimatedSwap.dustThreshold.baseAmount.amount().toString()).toBe('10000000000000000')
174178
expect(estimatedSwap.dustThreshold.baseAmount.decimal).toBe(18)
175-
expect(assetToString(estimatedSwap.fees.asset)).toBe('ETH.USDT-0xdAC17F958D2ee523a2206206994597C13D831ec7')
179+
expect(assetToString(estimatedSwap.fees.asset)).toBe('ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48')
176180
expect(assetToString(estimatedSwap.fees.affiliateFee.asset)).toBe(
177-
'ETH.USDT-0xdAC17F958D2ee523a2206206994597C13D831ec7',
181+
'ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48',
178182
)
179183
expect(estimatedSwap.fees.affiliateFee.baseAmount.amount().toString()).toBe('0')
180184
expect(estimatedSwap.fees.affiliateFee.baseAmount.decimal).toBe(6)

packages/xchain-aggregator/src/protocols/chainflip/chainflipProtocol.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { IProtocol, ProtocolConfig, QuoteSwap, QuoteSwapParams, SwapHistory, TxS
2020

2121
import { CompatibleAsset } from './types'
2222
import { cChainToXChain, xAssetToCAsset } from './utils'
23+
import { assetUSDC } from '@xchainjs/xchain-thorchain-query'
2324

2425
/**
2526
* Chainflip protocol
@@ -142,6 +143,7 @@ export class ChainflipProtocol implements IProtocol {
142143

143144
const outboundFee = selectedQuote?.includedFees.find((fee) => fee.type === 'EGRESS')
144145
const brokerFee = selectedQuote?.includedFees.find((fee) => fee.type === 'BROKER')
146+
const networkFee = selectedQuote?.includedFees.find((fee) => fee.type === 'NETWORK')
145147

146148
return {
147149
protocol: this.name,
@@ -164,15 +166,13 @@ export class ChainflipProtocol implements IProtocol {
164166
errors: [],
165167
slipBasisPoints: 0,
166168
fees: {
167-
asset: params.destinationAsset,
169+
asset: assetUSDC, // neworkFee & broker fee paid in usdc
170+
networkFee: new CryptoAmount(baseAmount(networkFee ? networkFee.amount : 0, 6), assetUSDC),
168171
outboundFee: new CryptoAmount(
169172
baseAmount(outboundFee ? outboundFee.amount : 0, destAssetData.decimals),
170173
params.destinationAsset,
171174
),
172-
affiliateFee: new CryptoAmount(
173-
baseAmount(brokerFee ? brokerFee.amount : 0, destAssetData.decimals),
174-
params.destinationAsset,
175-
),
175+
affiliateFee: new CryptoAmount(baseAmount(brokerFee ? brokerFee.amount : 0, 6), assetUSDC),
176176
},
177177
depositChannelId,
178178
}
@@ -195,7 +195,8 @@ export class ChainflipProtocol implements IProtocol {
195195
fees: {
196196
asset: params.destinationAsset,
197197
outboundFee: new CryptoAmount(baseAmount(0, destAssetData.decimals), params.destinationAsset),
198-
affiliateFee: new CryptoAmount(baseAmount(0, destAssetData.decimals), params.destinationAsset),
198+
networkFee: new CryptoAmount(baseAmount(0, 6), assetUSDC),
199+
affiliateFee: new CryptoAmount(baseAmount(0, 6), assetUSDC),
199200
},
200201
depositChannelId: undefined,
201202
}

packages/xchain-aggregator/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type Fees = {
2727
asset: Asset | TokenAsset | SynthAsset | TradeAsset | SecuredAsset // The asset for which fees are calculated
2828
affiliateFee: CryptoAmount<Asset | TokenAsset | SynthAsset | TradeAsset | SecuredAsset> // The affiliate fee amount
2929
outboundFee: CryptoAmount<Asset | TokenAsset | SynthAsset | TradeAsset | SecuredAsset> // The outbound fee amount
30+
networkFee?: CryptoAmount<Asset | TokenAsset | SynthAsset | TradeAsset | SecuredAsset> // The network fee amount
3031
}
3132

3233
/**

0 commit comments

Comments
 (0)