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

[skip ci] wip: chainflip swapper #8049

Draft
wants to merge 84 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 72 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
f9cf7a9
feat: add chainflip swagger schema
CumpsD Oct 22, 2024
b0fef83
feat: add chainflip icon
CumpsD Oct 23, 2024
6f4b2cd
feat: add chainflip env settings
CumpsD Oct 23, 2024
ae0d083
feat: start chainflip swapper
CumpsD Oct 23, 2024
56a4003
fix: forgot a missing type
CumpsD Oct 23, 2024
53cfa9f
feat: build sell and buy asset strings
CumpsD Oct 23, 2024
8515f51
fix: dont add chainflip to unchained
CumpsD Oct 23, 2024
c4131d5
feat: add supported chains and assets for chainflip
CumpsD Oct 23, 2024
159650a
feat: add chainflip csp
CumpsD Oct 23, 2024
cca5688
feat: fetch chainflip quote
CumpsD Oct 23, 2024
09b820d
feat: add fees to quotes
CumpsD Oct 23, 2024
9f60594
feat: add boost swaps
CumpsD Oct 23, 2024
8bab08e
fix: correct commissionBPs
CumpsD Oct 23, 2024
09b9b02
feat: first steps to get gas prices displayed
CumpsD Oct 23, 2024
e6a43ac
fix: correct arb to eth
CumpsD Oct 23, 2024
9c2f447
refactor: cleanup const and types
CumpsD Oct 23, 2024
20216d6
chore: add todo wrt minimum amounts
CumpsD Oct 23, 2024
d5b9fee
fix: deal with SellAmountBelowTradeFee error
CumpsD Oct 23, 2024
2861ba3
refactor: cleanup chainflip feature flag
CumpsD Oct 23, 2024
57e08d1
refactor: move default chainflip settings to env
CumpsD Oct 23, 2024
2207d5b
chore: newline eof
CumpsD Oct 23, 2024
56697f1
refactor: consistent order of swapper imports
CumpsD Oct 23, 2024
9507b73
fix: allowanceContract 0x0
CumpsD Oct 23, 2024
668856f
feat: filter out assets even more
CumpsD Oct 23, 2024
1765b86
feat: provide gaslimits for simple asset sends
CumpsD Oct 23, 2024
7b3cc26
chore: newline at eof
CumpsD Oct 23, 2024
a6d42f9
feat: support amount to low
CumpsD Oct 23, 2024
dfa6a3a
refactor: delete unneeded generated openai models
CumpsD Oct 23, 2024
ef79b52
chore: remove polkadot todo
CumpsD Oct 23, 2024
fea992c
refactor: clarify networkfee crypto base unit naming
CumpsD Oct 23, 2024
ee0d7bd
refactor: turn asset symbols into asset ids
CumpsD Oct 23, 2024
572135d
Merge branch 'develop' into add-chainflip
CumpsD Oct 23, 2024
089fff0
feat: use correct caip-19s
CumpsD Oct 23, 2024
1d25ce9
feat: place dca swaps behind feature toggle
CumpsD Oct 24, 2024
a1661cd
chore: pull magic values into constants
CumpsD Oct 25, 2024
72f1c7e
fix: pass pubkey for utxo estimation
CumpsD Oct 25, 2024
3fd7b62
fix: pass accountNumber
CumpsD Oct 25, 2024
519546b
refactor: cleanup swapsource and rate code
CumpsD Oct 25, 2024
799320f
Merge branch 'shapeshift:develop' into add-chainflip
CumpsD Oct 25, 2024
708a826
fix: add feature flag to tests
CumpsD Oct 25, 2024
8a17ba6
fix: unwanted quote char snuck in
CumpsD Oct 26, 2024
12ae967
style: be consistent in quotes style
CumpsD Oct 26, 2024
c090d43
chore: make prettier happy
CumpsD Oct 26, 2024
34ea201
fix: populate receiveAddress to get swap preview
CumpsD Oct 26, 2024
b253f4b
refactor: make code consistent with styling and restructure folders
CumpsD Oct 26, 2024
630f8ef
fix: correct swapper path
CumpsD Oct 26, 2024
e931c5b
refactor: move files around
CumpsD Oct 28, 2024
8f4b47a
feat: start unsigned evm tx
CumpsD Oct 28, 2024
8662c0d
chore: add todo
CumpsD Oct 28, 2024
3517d98
feat: add unsigned utxo
CumpsD Oct 28, 2024
ae28709
feat: add executeUtxoTransaction
CumpsD Oct 28, 2024
1251fa3
Merge branch 'shapeshift:develop' into add-chainflip
CumpsD Oct 28, 2024
15a0499
fix: check for undefined accountNumber
CumpsD Oct 28, 2024
c3c1745
wip: stuck at getUnsignedEvmTransaction
CumpsD Oct 28, 2024
1e57f3d
Merge branch 'shapeshift:develop' into add-chainflip
CumpsD Oct 28, 2024
4a227c5
refactor: move to buildSendApiTransaction to get rid of wallet
CumpsD Oct 28, 2024
22372ed
feat: estimate maxFeePerGas
CumpsD Oct 28, 2024
0c309d4
style: quotes
CumpsD Oct 28, 2024
3997245
refactor: add getGasLimit
CumpsD Oct 28, 2024
2cce1db
feat: use getErc20Data to get data
CumpsD Oct 28, 2024
5626b31
feat: return signing request
CumpsD Oct 28, 2024
5b4a64d
fix: no need for toHex
CumpsD Oct 28, 2024
f69ae34
chore: add slippage reference code
CumpsD Oct 28, 2024
a906812
Merge remote-tracking branch 'origin/develop' into add-chainflip
gomesalexandre Oct 30, 2024
4924c16
feat: lint and cleanup some
gomesalexandre Oct 30, 2024
1fd442b
feat: improve types
gomesalexandre Oct 30, 2024
dccd703
feat: cleanup unused models
gomesalexandre Oct 30, 2024
206a337
feat: cleanup
gomesalexandre Oct 30, 2024
7cfe7c2
feat: cleanup some more
gomesalexandre Oct 31, 2024
c2def52
feat: more prgorammatic
gomesalexandre Oct 31, 2024
5ef0169
feat: clean diff up
gomesalexandre Oct 31, 2024
2e77080
feat: cleanup consts
gomesalexandre Oct 31, 2024
c32b370
feat: consistency
gomesalexandre Oct 31, 2024
9a10db4
feat: stopping point
gomesalexandre Oct 31, 2024
19f5fcd
feat: false in base
gomesalexandre Oct 31, 2024
3111366
feat: stopping point for real this time
gomesalexandre Oct 31, 2024
820283b
fix: lint
gomesalexandre Oct 31, 2024
8c25692
Merge remote-tracking branch 'origin/develop' into add-chainflip
gomesalexandre Nov 4, 2024
ddd1339
fix: ci
gomesalexandre Nov 4, 2024
1c1b711
feat: split quotes/rates
gomesalexandre Nov 4, 2024
3172d80
feat: cleanup
gomesalexandre Nov 4, 2024
388b4dc
feat: trade status
gomesalexandre Nov 4, 2024
267eb4f
feat: flip polling and messaging
gomesalexandre Nov 4, 2024
ae0dd35
feat: improve btc things
gomesalexandre Nov 4, 2024
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
6 changes: 6 additions & 0 deletions .env.base
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ REACT_APP_FEATURE_DYNAMIC_LP_ASSETS=false
REACT_APP_FEATURE_READ_ONLY_ASSETS=true

# swapper feature flags - other .env files will override these
REACT_APP_FEATURE_CHAINFLIP=true
REACT_APP_FEATURE_CHAINFLIP_DCA=true
REACT_APP_FEATURE_COWSWAP=true
REACT_APP_FEATURE_LIFI_SWAP=true
REACT_APP_FEATURE_THOR_SWAP=true
Expand Down Expand Up @@ -169,3 +171,7 @@ REACT_APP_ZERION_BASE_URL=https://api.proxy.shapeshift.com/api/v1/zerion

# 0x
REACT_APP_ZRX_BASE_URL=https://api.proxy.shapeshift.com/api/v1/zrx/

# chainflip
REACT_APP_CHAINFLIP_API_KEY=6ba154d4-e219-472a-9674-5fa5b1300ccf
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give me a ping to set up Shapeshift's API key when going forward, this is currently mine for testing! :) The best person to reach out to me for this would be the one who will be responsible for redeeming affiliate rewards in the future. The one controlling the wallet to sign Chainflip transactions that is (redeeming is a chainflip tx)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good @CumpsD! Is there any reason we should wait for go-live to get an actual API key here, or can we already get one? Will get the convs going already

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key in there right now is actually the one from my swapping Discord bot https://swappy.be/ :) It works, you can test with it, but it charges 0.15% fee (0.05 BaaS + 0.10 Swappy). I can make you a temp one that does only 0.05 (BaaS fee + 0% partner) if you want. You can go live with that as well and swap it out to the Shapeshift one afterwards. lmk

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CumpsD just to be sure, we can parametrize fee bps right i.e this isn't tied to the API key used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current one for dev is absolutely fine, so long as we go live on prod (and ideally on develop as a follow-up) with a proper API key 🙏🏽

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CumpsD just to be sure, we can parametrize fee bps right i.e this isn't tied to the API key used?

Yes, you can pass in commissionBps for both quote and opening a deposit channel (I think I added that in the PR already even! taking in affiliateBps from shapeshift)

REACT_APP_CHAINFLIP_API_URL=https://chainflip-broker.io
14 changes: 10 additions & 4 deletions packages/caip/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,22 @@ export const arbitrumNovaAssetId: AssetId = 'eip155:42170/slip44:60'
export const baseAssetId: AssetId = 'eip155:8453/slip44:60'
export const solAssetId: AssetId = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501'

export const foxatarAssetId: AssetId =
'eip155:137/erc721:0x2e727c425a11ce6b8819b3004db332c12d2af2a2'

export const foxyAssetId: AssetId = 'eip155:1/erc20:0xdc49108ce5c57bc3408c3a5e95f3d864ec386ed3'
export const foxOnGnosisAssetId: AssetId =
'eip155:100/erc20:0x21a42669643f45bc0e086b8fc2ed70c23d67509d'
export const foxOnArbitrumOneAssetId: AssetId =
'eip155:42161/erc20:0xf929de51d91c77e42f5090069e0ad7a09e513c73'
export const foxAssetId: AssetId = 'eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d'
export const foxatarAssetId: AssetId =
'eip155:137/erc721:0x2e727c425a11ce6b8819b3004db332c12d2af2a2'
export const foxyAssetId: AssetId = 'eip155:1/erc20:0xdc49108ce5c57bc3408c3a5e95f3d864ec386ed3'

export const usdtAssetId: AssetId = 'eip155:1/erc20:0xdac17f958d2ee523a2206206994597c13d831ec7'
export const usdcAssetId: AssetId = 'eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
export const usdcOnArbitrumOneAssetId: AssetId =
'eip155:42161/erc20:0xaf88d065e77c8cc2239327c5edb3a432268e5831'
export const usdcOnSolanaAssetId: AssetId =
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'
export const flipAssetId: AssetId = 'eip155:1/erc20:0x826180541412d574cf1336d22c0c0a287822678a'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all common AssetIds moved into one block + some additions


export const cosmosAssetId: AssetId = 'cosmos:cosmoshub-4/slip44:118'
export const thorchainAssetId: AssetId = 'cosmos:thorchain-1/slip44:931'
Expand Down
12 changes: 12 additions & 0 deletions packages/swapper/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { assertUnreachable } from '@shapeshiftoss/utils'
import { arbitrumBridgeSwapper } from './swappers/ArbitrumBridgeSwapper/ArbitrumBridgeSwapper'
import { arbitrumBridgeApi } from './swappers/ArbitrumBridgeSwapper/endpoints'
import { ARBITRUM_BRIDGE_SUPPORTED_CHAIN_IDS } from './swappers/ArbitrumBridgeSwapper/utils/constants'
import { chainflipSwapper } from './swappers/ChainflipSwapper/ChainflipSwapper'
import { chainflipApi } from './swappers/ChainflipSwapper/ChainflipSwapperApi'
import { CHAINFLIP_SUPPORTED_CHAIN_IDS } from './swappers/ChainflipSwapper/constants'
import { cowSwapper } from './swappers/CowSwapper/CowSwapper'
import { cowApi } from './swappers/CowSwapper/endpoints'
import { COW_SWAP_SUPPORTED_CHAIN_IDS } from './swappers/CowSwapper/utils/constants'
Expand Down Expand Up @@ -76,6 +79,12 @@ export const swappers: Record<
supportedChainIds: PORTALS_SUPPORTED_CHAIN_IDS,
pollingInterval: DEFAULT_GET_TRADE_QUOTE_POLLING_INTERVAL,
},
[SwapperName.Chainflip]: {
...chainflipSwapper,
...chainflipApi,
supportedChainIds: CHAINFLIP_SUPPORTED_CHAIN_IDS,
pollingInterval: DEFAULT_GET_TRADE_QUOTE_POLLING_INTERVAL,
},
[SwapperName.Test]: undefined,
}

Expand All @@ -86,6 +95,7 @@ const DEFAULT_PORTALS_SLIPPAGE_DECIMAL_PERCENTAGE = '0.01' // 1%
const DEFAULT_LIFI_SLIPPAGE_DECIMAL_PERCENTAGE = '0.005' // .5%
const DEFAULT_THOR_SLIPPAGE_DECIMAL_PERCENTAGE = '0.01' // 1%
const DEFAULT_ARBITRUM_BRIDGE_SLIPPAGE_DECIMAL_PERCENTAGE = '0' // no slippage for Arbitrum Bridge, so no slippage tolerance
const DEFAULT_CHAINFLIP_SLIPPAGE_DECIMAL_PERCENTAGE = '0.02' // 2%

export const getDefaultSlippageDecimalPercentageForSwapper = (
swapperName?: SwapperName,
Expand All @@ -105,6 +115,8 @@ export const getDefaultSlippageDecimalPercentageForSwapper = (
return DEFAULT_THOR_SLIPPAGE_DECIMAL_PERCENTAGE
case SwapperName.ArbitrumBridge:
return DEFAULT_ARBITRUM_BRIDGE_SLIPPAGE_DECIMAL_PERCENTAGE
case SwapperName.Chainflip:
return DEFAULT_CHAINFLIP_SLIPPAGE_DECIMAL_PERCENTAGE
default:
assertUnreachable(swapperName)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { AssetId } from '@shapeshiftoss/caip'
import type { BTCSignTx } from '@shapeshiftoss/hdwallet-core'
import type { Asset } from '@shapeshiftoss/types'

import type { BuyAssetBySellIdInput, Swapper, UtxoTransactionExecutionProps } from '../../types'
import { executeEvmTransaction } from '../../utils'
import { CHAINFLIP_SUPPORTED_CHAIN_IDS } from './constants'
import { isSupportedAssetId } from './utils/helpers'

export const chainflipSwapper: Swapper = {
executeEvmTransaction,

executeUtxoTransaction: async (
txToSign: BTCSignTx,
{ signAndBroadcastTransaction }: UtxoTransactionExecutionProps,
): Promise<string> => {
return await signAndBroadcastTransaction(txToSign)
},

filterAssetIdsBySellable: (assets: Asset[]): Promise<AssetId[]> => {
return Promise.resolve(
assets
.filter(asset => CHAINFLIP_SUPPORTED_CHAIN_IDS.sell.includes(asset.chainId))
.filter(asset => isSupportedAssetId(asset.chainId, asset.assetId))
.map(asset => asset.assetId),
)
},

filterBuyAssetsBySellAssetId: (input: BuyAssetBySellIdInput): Promise<AssetId[]> => {
return Promise.resolve(
input.assets
.filter(asset => CHAINFLIP_SUPPORTED_CHAIN_IDS.buy.includes(asset.chainId))
.filter(asset => isSupportedAssetId(asset.chainId, asset.assetId))
.map(asset => asset.assetId),
)
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { SwapperApi } from '../../types'
import { checkTradeStatus } from './swapperApi/checkTradeStatus'
import { getTradeQuote } from './swapperApi/getTradeQuote'
import { getUnsignedEvmTransaction } from './swapperApi/getUnsignedEvmTransaction'
import { getUnsignedUtxoTransaction } from './swapperApi/getUnsignedUtxoTransaction'

export const chainflipApi: SwapperApi = {
getTradeQuote,
getUnsignedEvmTransaction,
getUnsignedUtxoTransaction,
checkTradeStatus,
}
69 changes: 69 additions & 0 deletions packages/swapper/src/swappers/ChainflipSwapper/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import {
arbitrumAssetId,
type AssetId,
btcAssetId,
type ChainId,
ethAssetId,
flipAssetId,
solAssetId,
usdcAssetId,
usdcOnArbitrumOneAssetId,
usdcOnSolanaAssetId,
usdtAssetId,
} from '@shapeshiftoss/caip'
import type { Asset } from '@shapeshiftoss/types'
import { KnownChainIds } from '@shapeshiftoss/types'

import type { SupportedChainIds, SwapSource } from '../../types'
import { SwapperName } from '../../types'

export const CHAINFLIP_REGULAR_QUOTE = 'regular'
export const CHAINFLIP_DCA_QUOTE = 'dca'
export const CHAINFLIP_BAAS_COMMISSION = 5

export const ChainflipSupportedChainIds = [
KnownChainIds.EthereumMainnet,
KnownChainIds.ArbitrumMainnet,
KnownChainIds.BitcoinMainnet,
KnownChainIds.SolanaMainnet,
] as const

export type ChainflipSupportedChainId = (typeof ChainflipSupportedChainIds)[number]

export const ChainflipSupportedAssetIdsByChainId: Partial<Record<KnownChainIds, AssetId[]>> = {
[KnownChainIds.EthereumMainnet]: [ethAssetId, flipAssetId, usdcAssetId, usdtAssetId],
[KnownChainIds.ArbitrumMainnet]: [arbitrumAssetId, usdcOnArbitrumOneAssetId],
[KnownChainIds.BitcoinMainnet]: [btcAssetId],
[KnownChainIds.SolanaMainnet]: [solAssetId, usdcOnSolanaAssetId],
}

export const chainIdToChainflipNetwork: Partial<Record<KnownChainIds, string>> = {
[KnownChainIds.EthereumMainnet]: 'eth',
[KnownChainIds.ArbitrumMainnet]: 'arb',
[KnownChainIds.BitcoinMainnet]: 'btc',
[KnownChainIds.SolanaMainnet]: 'sol',
}

export const CHAINFLIP_SUPPORTED_CHAIN_IDS: SupportedChainIds = {
sell: ChainflipSupportedChainIds as unknown as ChainId[],
buy: ChainflipSupportedChainIds as unknown as ChainId[],
}

export const CHAINFLIP_SWAP_SOURCE: SwapSource = SwapperName.Chainflip
export const CHAINFLIP_BOOST_SWAP_SOURCE: SwapSource = `${SwapperName.Chainflip} • Boost`
export const CHAINFLIP_DCA_SWAP_SOURCE: SwapSource = `${SwapperName.Chainflip} • DCA`
export const CHAINFLIP_DCA_BOOST_SWAP_SOURCE: SwapSource = `${SwapperName.Chainflip} • DCA • Boost`

export const usdcAsset: Asset = {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A fyi, the reason I copied this here is because the usdcAsset in caip is only the assetId, but where I've used it, it also needed precision (in the protocol fees calculations)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's absolutely fine @CumpsD!
Just to disambiguate here, what's the two actual flows when fees will be denominated in USDC? i.e i can see the condition is fee.type === 'network'and fee.type === 'liquidity' && fee.asset === 'usdc.eth' but not sure what this means exactly.

Asking because we may be able to simply use buyAsset / sellAsset if one of these is USDC

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Network fee is always USDC, it is the 0.10% buy & burn fee the chainflip network uses.

Liquidity is the LP fee, which I would have to double check but I believe the second leg is always USDC. It's possible this if (fee.type === 'liquidity' && fee.asset === buyChainflipChainKey) return buyAsset might actually never be hit.

Will double check!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, so the second leg seems to be always usdc.eth for the liquidity fee.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to keep the second branch for the sake of paranoia. Tyvm for disambiguating this! Looks like indeed, we need usdc as a static asset then, which means keeping it here as a const is absolutely fine.

Copy link

@CumpsD CumpsD Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to keep the second branch for the sake of paranoia.

Pretty much the reason I added all branches too :D

assetId: 'eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
chainId: KnownChainIds.EthereumMainnet,
color: '#2373CB',
explorer: 'https://etherscan.io',
explorerAddressLink: 'https://etherscan.io/address/',
explorerTxLink: 'https://etherscan.io/tx/',
icon: 'https://rawcdn.githack.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png',
name: 'USDC on Ethereum',
precision: 6,
relatedAssetKey: 'eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
symbol: 'USDC',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
// @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';
import type { ChainflipBaasQuoteBoostQuote } from './ChainflipBaasQuoteBoostQuote';
import {
ChainflipBaasQuoteBoostQuoteFromJSON,
ChainflipBaasQuoteBoostQuoteFromJSONTyped,
ChainflipBaasQuoteBoostQuoteToJSON,
} from './ChainflipBaasQuoteBoostQuote';
import type { ChainflipBaasQuotePoolInfo } from './ChainflipBaasQuotePoolInfo';
import {
ChainflipBaasQuotePoolInfoFromJSON,
ChainflipBaasQuotePoolInfoFromJSONTyped,
ChainflipBaasQuotePoolInfoToJSON,
} from './ChainflipBaasQuotePoolInfo';
import type { ChainflipBaasQuoteQuoteFee } from './ChainflipBaasQuoteQuoteFee';
import {
ChainflipBaasQuoteQuoteFeeFromJSON,
ChainflipBaasQuoteQuoteFeeFromJSONTyped,
ChainflipBaasQuoteQuoteFeeToJSON,
} from './ChainflipBaasQuoteQuoteFee';

/**
*
* @export
* @interface ChainflipBaasQuoteQuote
*/
export interface ChainflipBaasQuoteQuote {
/**
* The type of quote.
* @type {string}
* @memberof ChainflipBaasQuoteQuote
*/
readonly type?: ChainflipBaasQuoteQuoteTypeEnum;
/**
* The asset to send.
* @type {string}
* @memberof ChainflipBaasQuoteQuote
*/
ingressAsset?: string;
/**
* The amount to send.
* @type {number}
* @memberof ChainflipBaasQuoteQuote
*/
ingressAmount?: number;
/**
* The amount to send in native units.
* @type {string}
* @memberof ChainflipBaasQuoteQuote
*/
readonly ingressAmountNative?: string;
/**
* The asset to receive.
* @type {string}
* @memberof ChainflipBaasQuoteQuote
*/
egressAsset?: string;
/**
* The amount to receive.
* @type {number}
* @memberof ChainflipBaasQuoteQuote
*/
readonly egressAmount?: number;
/**
* The amount to receive in native units.
* @type {string}
* @memberof ChainflipBaasQuoteQuote
*/
readonly egressAmountNative?: string;
/**
* The fee structure, this includes all fees.
* @type {Array<ChainflipBaasQuoteQuoteFee>}
* @memberof ChainflipBaasQuoteQuote
*/
readonly includedFees?: Array<ChainflipBaasQuoteQuoteFee>;
/**
* A warning in case liquidity is low and there is a risk of high slippage.
* @type {boolean}
* @memberof ChainflipBaasQuoteQuote
*/
readonly lowLiquidityWarning?: boolean;
/**
* Liquidity pools involved in the swap, as well as estimated liquidity provider fees.
* @type {Array<ChainflipBaasQuotePoolInfo>}
* @memberof ChainflipBaasQuoteQuote
*/
poolInfo?: Array<ChainflipBaasQuotePoolInfo>;
/**
* The estimated time the swap will take.
* @type {number}
* @memberof ChainflipBaasQuoteQuote
*/
readonly estimatedDurationSeconds?: number;
/**
* The number of "sub-swaps" to perform for a DCA swap.
* @type {number}
* @memberof ChainflipBaasQuoteQuote
*/
chunkIntervalBlocks?: number | null;
/**
* The delay between the "sub-swaps" of a DCA swap in number of blocks.
* @type {number}
* @memberof ChainflipBaasQuoteQuote
*/
numberOfChunks?: number | null;
/**
*
* @type {ChainflipBaasQuoteBoostQuote}
* @memberof ChainflipBaasQuoteQuote
*/
boostQuote?: ChainflipBaasQuoteBoostQuote;
}


/**
* @export
*/
export const ChainflipBaasQuoteQuoteTypeEnum = {
Regular: 'regular',
Dca: 'dca'
} as const;
export type ChainflipBaasQuoteQuoteTypeEnum = typeof ChainflipBaasQuoteQuoteTypeEnum[keyof typeof ChainflipBaasQuoteQuoteTypeEnum];


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

return isInstance;
}

export function ChainflipBaasQuoteQuoteFromJSON(json: any): ChainflipBaasQuoteQuote {
return ChainflipBaasQuoteQuoteFromJSONTyped(json, false);
}

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

'type': !exists(json, 'type') ? undefined : json['type'],
'ingressAsset': !exists(json, 'ingressAsset') ? undefined : json['ingressAsset'],
'ingressAmount': !exists(json, 'ingressAmount') ? undefined : json['ingressAmount'],
'ingressAmountNative': !exists(json, 'ingressAmountNative') ? undefined : json['ingressAmountNative'],
'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)),
'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'],
'chunkIntervalBlocks': !exists(json, 'chunkIntervalBlocks') ? undefined : json['chunkIntervalBlocks'],
'numberOfChunks': !exists(json, 'numberOfChunks') ? undefined : json['numberOfChunks'],
'boostQuote': !exists(json, 'boostQuote') ? undefined : ChainflipBaasQuoteBoostQuoteFromJSON(json['boostQuote']),
};
}

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

'ingressAsset': value.ingressAsset,
'ingressAmount': value.ingressAmount,
'egressAsset': value.egressAsset,
'poolInfo': value.poolInfo === undefined ? undefined : ((value.poolInfo as Array<any>).map(ChainflipBaasQuotePoolInfoToJSON)),
'chunkIntervalBlocks': value.chunkIntervalBlocks,
'numberOfChunks': value.numberOfChunks,
'boostQuote': ChainflipBaasQuoteBoostQuoteToJSON(value.boostQuote),
};
}

Loading
Loading