Skip to content

Commit

Permalink
Merge branch 'develop' into chainflip-dca
Browse files Browse the repository at this point in the history
  • Loading branch information
CumpsD committed Nov 21, 2024
2 parents af129ac + 53916c5 commit dd90aa3
Show file tree
Hide file tree
Showing 17 changed files with 286 additions and 56 deletions.
7 changes: 5 additions & 2 deletions packages/swapper/src/swappers/ChainflipSwapper/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import type {
UtxoFeeData,
} from '../../types'
import { isExecutableTradeQuote, isExecutableTradeStep, isToken } from '../../utils'
import { CHAINFLIP_BAAS_COMMISSION } from './constants'
import type { ChainflipBaasSwapDepositAddress } from './models'
import { CHAINFLIP_BAAS_COMMISSION, CHAINFLIP_BOOST_SWAP_SOURCE } from './constants'
import type { ChainflipBaasSwapDepositAddress } from './models/ChainflipBaasSwapDepositAddress'
import { getTradeQuote } from './swapperApi/getTradeQuote'
import { getTradeRate } from './swapperApi/getTradeRate'
import type { ChainFlipStatus } from './types'
Expand Down Expand Up @@ -84,6 +84,7 @@ export const chainflipApi: SwapperApi = {
commissionBps: serviceCommission,
numberOfChunks: step.chainflipNumberOfChunks,
chunkIntervalBlocks: step.chainflipChunkIntervalBlocks
boostFee: 0,
})

if (maybeSwapResponse.isErr()) {
Expand Down Expand Up @@ -211,6 +212,7 @@ export const chainflipApi: SwapperApi = {
commissionBps: serviceCommission,
numberOfChunks: step.chainflipNumberOfChunks,
chunkIntervalBlocks: step.chainflipChunkIntervalBlocks
boostFee: step.source === CHAINFLIP_BOOST_SWAP_SOURCE ? 10 : 0,
})

if (maybeSwapResponse.isErr()) {
Expand Down Expand Up @@ -286,6 +288,7 @@ export const chainflipApi: SwapperApi = {
commissionBps: serviceCommission,
numberOfChunks: step.chainflipNumberOfChunks,
chunkIntervalBlocks: step.chainflipChunkIntervalBlocks
boostFee: 0,
})

if (maybeSwapResponse.isErr()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// @ts-nocheck
/* tslint:disable */
/* eslint-disable */
/**
* Chainflip Broker as a Service
* Run your own Chainflip Broker without any hassle.
*
* The version of the OpenAPI document: v1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

import { exists, mapValues } from '../runtime';
/**
*
* @export
* @interface ChainflipBaasQuoteEstimatedDurationsSeconds
*/
export interface ChainflipBaasQuoteEstimatedDurationsSeconds {
/**
* The estimated time for a deposit to be witnessed.
* @type {number}
* @memberof ChainflipBaasQuoteEstimatedDurationsSeconds
*/
readonly deposit?: number;
/**
* The estimated time for a swap to be fully executed.
* @type {number}
* @memberof ChainflipBaasQuoteEstimatedDurationsSeconds
*/
readonly swap?: number;
/**
* The estimated time until the output transaction is included in a block.
* @type {number}
* @memberof ChainflipBaasQuoteEstimatedDurationsSeconds
*/
readonly egress?: number;
}

/**
* Check if a given object implements the ChainflipBaasQuoteEstimatedDurationsSeconds interface.
*/
export function instanceOfChainflipBaasQuoteEstimatedDurationsSeconds(value: object): boolean {
let isInstance = true;

return isInstance;
}

export function ChainflipBaasQuoteEstimatedDurationsSecondsFromJSON(json: any): ChainflipBaasQuoteEstimatedDurationsSeconds {
return ChainflipBaasQuoteEstimatedDurationsSecondsFromJSONTyped(json, false);
}

export function ChainflipBaasQuoteEstimatedDurationsSecondsFromJSONTyped(json: any, ignoreDiscriminator: boolean): ChainflipBaasQuoteEstimatedDurationsSeconds {
if ((json === undefined) || (json === null)) {
return json;
}
return {

'deposit': !exists(json, 'deposit') ? undefined : json['deposit'],
'swap': !exists(json, 'swap') ? undefined : json['swap'],
'egress': !exists(json, 'egress') ? undefined : json['egress'],
};
}

export function ChainflipBaasQuoteEstimatedDurationsSecondsToJSON(value?: ChainflipBaasQuoteEstimatedDurationsSeconds | null): any {
if (value === undefined) {
return undefined;
}
if (value === null) {
return null;
}
return {

};
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import {
ChainflipBaasQuoteBoostQuoteFromJSONTyped,
ChainflipBaasQuoteBoostQuoteToJSON,
} from './ChainflipBaasQuoteBoostQuote';
import type { ChainflipBaasQuoteEstimatedDurationsSeconds } from './ChainflipBaasQuoteEstimatedDurationsSeconds';
import {
ChainflipBaasQuoteEstimatedDurationsSecondsFromJSON,
ChainflipBaasQuoteEstimatedDurationsSecondsFromJSONTyped,
ChainflipBaasQuoteEstimatedDurationsSecondsToJSON,
} from './ChainflipBaasQuoteEstimatedDurationsSeconds';
import type { ChainflipBaasQuotePoolInfo } from './ChainflipBaasQuotePoolInfo';
import {
ChainflipBaasQuotePoolInfoFromJSON,
Expand Down Expand Up @@ -63,6 +69,24 @@ export interface ChainflipBaasQuoteQuote {
* @memberof ChainflipBaasQuoteQuote
*/
readonly ingressAmountNative?: string;
/**
* The asset used as intermediary.
* @type {string}
* @memberof ChainflipBaasQuoteQuote
*/
intermediateAsset?: string | null;
/**
* The amount used as intermediary.
* @type {number}
* @memberof ChainflipBaasQuoteQuote
*/
readonly intermediateAmount?: number | null;
/**
* The amount used as intermediary in native units.
* @type {string}
* @memberof ChainflipBaasQuoteQuote
*/
readonly intermediateAmountNative?: string | null;
/**
* The asset to receive.
* @type {string}
Expand All @@ -87,6 +111,12 @@ export interface ChainflipBaasQuoteQuote {
* @memberof ChainflipBaasQuoteQuote
*/
readonly includedFees?: Array<ChainflipBaasQuoteQuoteFee>;
/**
* Recommended slippage percentage to use when calculating minimum price.
* @type {number}
* @memberof ChainflipBaasQuoteQuote
*/
readonly recommendedSlippageTolerancePercent?: number;
/**
* A warning in case liquidity is low and there is a risk of high slippage.
* @type {boolean}
Expand All @@ -98,25 +128,37 @@ export interface ChainflipBaasQuoteQuote {
* @type {Array<ChainflipBaasQuotePoolInfo>}
* @memberof ChainflipBaasQuoteQuote
*/
poolInfo?: Array<ChainflipBaasQuotePoolInfo>;
readonly poolInfo?: Array<ChainflipBaasQuotePoolInfo>;
/**
* The estimated time the swap will take.
* @type {number}
* @memberof ChainflipBaasQuoteQuote
*/
readonly estimatedDurationSeconds?: number;
/**
*
* @type {ChainflipBaasQuoteEstimatedDurationsSeconds}
* @memberof ChainflipBaasQuoteQuote
*/
estimatedDurationsSeconds?: ChainflipBaasQuoteEstimatedDurationsSeconds;
/**
* The estimated price in the destination asset for 1 unit of the source asset. Used for slippage calculations.
* @type {number}
* @memberof ChainflipBaasQuoteQuote
*/
readonly estimatedPrice?: number;
/**
* The number of "sub-swaps" to perform for a DCA swap.
* @type {number}
* @memberof ChainflipBaasQuoteQuote
*/
chunkIntervalBlocks?: number | null;
readonly chunkIntervalBlocks?: number | null;
/**
* The delay between the "sub-swaps" of a DCA swap in number of blocks.
* @type {number}
* @memberof ChainflipBaasQuoteQuote
*/
numberOfChunks?: number | null;
readonly numberOfChunks?: number | null;
/**
*
* @type {ChainflipBaasQuoteBoostQuote}
Expand Down Expand Up @@ -159,13 +201,19 @@ export function ChainflipBaasQuoteQuoteFromJSONTyped(json: any, ignoreDiscrimina
'ingressAsset': !exists(json, 'ingressAsset') ? undefined : json['ingressAsset'],
'ingressAmount': !exists(json, 'ingressAmount') ? undefined : json['ingressAmount'],
'ingressAmountNative': !exists(json, 'ingressAmountNative') ? undefined : json['ingressAmountNative'],
'intermediateAsset': !exists(json, 'intermediateAsset') ? undefined : json['intermediateAsset'],
'intermediateAmount': !exists(json, 'intermediateAmount') ? undefined : json['intermediateAmount'],
'intermediateAmountNative': !exists(json, 'intermediateAmountNative') ? undefined : json['intermediateAmountNative'],
'egressAsset': !exists(json, 'egressAsset') ? undefined : json['egressAsset'],
'egressAmount': !exists(json, 'egressAmount') ? undefined : json['egressAmount'],
'egressAmountNative': !exists(json, 'egressAmountNative') ? undefined : json['egressAmountNative'],
'includedFees': !exists(json, 'includedFees') ? undefined : ((json['includedFees'] as Array<any>).map(ChainflipBaasQuoteQuoteFeeFromJSON)),
'recommendedSlippageTolerancePercent': !exists(json, 'recommendedSlippageTolerancePercent') ? undefined : json['recommendedSlippageTolerancePercent'],
'lowLiquidityWarning': !exists(json, 'lowLiquidityWarning') ? undefined : json['lowLiquidityWarning'],
'poolInfo': !exists(json, 'poolInfo') ? undefined : ((json['poolInfo'] as Array<any>).map(ChainflipBaasQuotePoolInfoFromJSON)),
'estimatedDurationSeconds': !exists(json, 'estimatedDurationSeconds') ? undefined : json['estimatedDurationSeconds'],
'estimatedDurationsSeconds': !exists(json, 'estimatedDurationsSeconds') ? undefined : ChainflipBaasQuoteEstimatedDurationsSecondsFromJSON(json['estimatedDurationsSeconds']),
'estimatedPrice': !exists(json, 'estimatedPrice') ? undefined : json['estimatedPrice'],
'chunkIntervalBlocks': !exists(json, 'chunkIntervalBlocks') ? undefined : json['chunkIntervalBlocks'],
'numberOfChunks': !exists(json, 'numberOfChunks') ? undefined : json['numberOfChunks'],
'boostQuote': !exists(json, 'boostQuote') ? undefined : ChainflipBaasQuoteBoostQuoteFromJSON(json['boostQuote']),
Expand All @@ -183,10 +231,9 @@ export function ChainflipBaasQuoteQuoteToJSON(value?: ChainflipBaasQuoteQuote |

'ingressAsset': value.ingressAsset,
'ingressAmount': value.ingressAmount,
'intermediateAsset': value.intermediateAsset,
'egressAsset': value.egressAsset,
'poolInfo': value.poolInfo === undefined ? undefined : ((value.poolInfo as Array<any>).map(ChainflipBaasQuotePoolInfoToJSON)),
'chunkIntervalBlocks': value.chunkIntervalBlocks,
'numberOfChunks': value.numberOfChunks,
'estimatedDurationsSeconds': ChainflipBaasQuoteEstimatedDurationsSecondsToJSON(value.estimatedDurationsSeconds),
'boostQuote': ChainflipBaasQuoteBoostQuoteToJSON(value.boostQuote),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ export interface ChainflipBaasQuoteQuoteFee {
* @type {string}
* @memberof ChainflipBaasQuoteQuoteFee
*/
type?: ChainflipBaasQuoteQuoteFeeTypeEnum;
readonly type?: ChainflipBaasQuoteQuoteFeeTypeEnum;
/**
* The asset the fee is processed in.
* @type {string}
* @memberof ChainflipBaasQuoteQuoteFee
*/
asset?: string | null;
readonly asset?: string | null;
/**
* The fee amount.
* @type {number}
* @memberof ChainflipBaasQuoteQuoteFee
*/
amount?: number;
readonly amount?: number;
/**
* The fee amount in native units.
* @type {string}
* @memberof ChainflipBaasQuoteQuoteFee
*/
amountNative?: string;
readonly amountNative?: string;
}


Expand Down Expand Up @@ -96,10 +96,6 @@ export function ChainflipBaasQuoteQuoteFeeToJSON(value?: ChainflipBaasQuoteQuote
}
return {

'type': value.type,
'asset': value.asset,
'amount': value.amount,
'amountNative': value.amountNative,
};
}

Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,4 @@ export function ChainflipBaasStatusEgressToJSON(value?: ChainflipBaasStatusEgres
'failure': ChainflipBaasStatusFailureToJSON(value.failure),
};
}

Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,14 @@ export const _getTradeQuote = async (
accountNumber,
allowanceContract: '0x0', // Chainflip does not use contracts
estimatedExecutionTimeMs:
singleQuoteResponse.boostQuote.estimatedDurationSeconds! * 1000,
(singleQuoteResponse.boostQuote.estimatedDurationsSeconds!.deposit! +
singleQuoteResponse.boostQuote.estimatedDurationsSeconds!.swap!) * 1000,
chainflipNumberOfChunks: isStreaming
? singleQuoteResponse.boostQuote.numberOfChunks ?? undefined
: undefined,
chainflipChunkIntervalBlocks: isStreaming
? singleQuoteResponse.boostQuote.chunkIntervalBlocks ?? undefined
: undefined
: undefined,
},
],
}
Expand Down Expand Up @@ -330,7 +331,9 @@ export const _getTradeQuote = async (
sellAsset,
accountNumber,
allowanceContract: '0x0', // Chainflip does not use contracts - all Txs are sends
estimatedExecutionTimeMs: singleQuoteResponse.estimatedDurationSeconds! * 1000,
estimatedExecutionTimeMs:
(singleQuoteResponse.estimatedDurationsSeconds!.deposit! +
singleQuoteResponse.estimatedDurationsSeconds!.swap!) * 1000,
chainflipNumberOfChunks: isStreaming
? singleQuoteResponse.numberOfChunks ?? undefined
: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const getChainFlipSwap = ({
sourceAsset,
destinationAsset,
destinationAddress,
boostFee = 10,
boostFee = 0,
minimumPrice,
refundAddress,
retryDurationInBlocks = 10,
Expand Down
7 changes: 6 additions & 1 deletion src/components/AssetSelection/AssetSelection.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChevronDownIcon } from '@chakra-ui/icons'
import type { ButtonProps, FlexProps } from '@chakra-ui/react'
import { Flex } from '@chakra-ui/react'
import type { AssetId } from '@shapeshiftoss/caip'
import type { AssetId, ChainId } from '@shapeshiftoss/caip'
import type { Asset } from '@shapeshiftoss/types'
import { memo, useCallback, useMemo } from 'react'
import { Text } from 'components/Text'
Expand All @@ -17,6 +17,7 @@ type TradeAssetSelectBaseProps = {
isLoading?: boolean
buttonProps?: ButtonProps
onlyConnectedChains: boolean
chainIdFilterPredicate?: (chainId: ChainId) => boolean
} & FlexProps

type TradeAssetSelectReadonlyProps = {
Expand All @@ -43,6 +44,7 @@ export const TradeAssetSelect: React.FC<TradeAssetSelectProps> = memo(props => {
isLoading,
onlyConnectedChains,
buttonProps,
chainIdFilterPredicate,
flexProps,
} = useMemo(() => {
const {
Expand All @@ -54,6 +56,7 @@ export const TradeAssetSelect: React.FC<TradeAssetSelectProps> = memo(props => {
isLoading,
onlyConnectedChains,
buttonProps,
chainIdFilterPredicate,
...flexProps
} = props
return {
Expand All @@ -65,6 +68,7 @@ export const TradeAssetSelect: React.FC<TradeAssetSelectProps> = memo(props => {
isLoading,
onlyConnectedChains,
buttonProps,
chainIdFilterPredicate,
flexProps,
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down Expand Up @@ -104,6 +108,7 @@ export const TradeAssetSelect: React.FC<TradeAssetSelectProps> = memo(props => {
buttonProps={buttonProps}
rightIcon={rightIcon}
onlyConnectedChains={onlyConnectedChains}
chainIdFilterPredicate={chainIdFilterPredicate}
/>
</Flex>
)
Expand Down
Loading

0 comments on commit dd90aa3

Please sign in to comment.