Skip to content

Commit

Permalink
Merge branch 'develop' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
0xApotheosis authored Nov 19, 2024
2 parents 18eff8c + 984cd69 commit 540665d
Show file tree
Hide file tree
Showing 65 changed files with 11,084 additions and 6,112 deletions.
6 changes: 6 additions & 0 deletions .env.base
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,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=false
REACT_APP_FEATURE_CHAINFLIP_DCA=false
REACT_APP_FEATURE_COWSWAP=true
REACT_APP_FEATURE_LIFI_SWAP=true
REACT_APP_FEATURE_THOR_SWAP=true
Expand Down Expand Up @@ -171,3 +173,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
REACT_APP_CHAINFLIP_API_URL=https://chainflip-broker.io
2 changes: 2 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# feature flags
REACT_APP_FEATURE_CHAINFLIP=true
REACT_APP_FEATURE_CHAINFLIP_DCA=false
REACT_APP_FEATURE_PUBLIC_TRADE_ROUTE=false
REACT_APP_FEATURE_LIMIT_ORDERS=true

Expand Down
2 changes: 2 additions & 0 deletions .env.develop
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# feature flags
REACT_APP_FEATURE_LIMIT_ORDERS=true
REACT_APP_FEATURE_PUBLIC_TRADE_ROUTE=false
REACT_APP_FEATURE_CHAINFLIP=true
REACT_APP_FEATURE_CHAINFLIP_DCA=false

# mixpanel
REACT_APP_MIXPANEL_TOKEN=1c1369f6ea23a6404bac41b42817cc4b
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
diff --git a/src/bufferutils.js b/src/bufferutils.js
index a68fd31ceae3e9c465b09efd7b486fe60f88a965..14ac893566b9a87a3a2d3bd98aa5faacc4306850 100644
--- a/src/bufferutils.js
+++ b/src/bufferutils.js
@@ -4,12 +4,11 @@ const types = require('./types');
const typeforce = require('typeforce');
const varuint = require('varuint-bitcoin');
// https://github.com/feross/buffer/blob/master/index.js#L1127
-function verifuint(value, max) {
+function verifuint(value, _max) {
if (typeof value !== 'number')
throw new Error('cannot write a non-number as a number');
if (value < 0)
throw new Error('specified a negative value for writing an unsigned value');
- if (value > max) throw new Error('RangeError: value out of range');
if (Math.floor(value) !== value)
throw new Error('value has a fractional component');
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@
"react-scripts/workbox-webpack-plugin": "^7.1.0",
"p-queue": "^6.6.2",
"web3": "4.2.1-dev.a0d6730.0",
"react-scripts@^5.0.1": "patch:react-scripts@npm%3A5.0.1#./.yarn/patches/react-scripts-npm-5.0.1-d06bd2d5ad.patch"
"react-scripts@^5.0.1": "patch:react-scripts@npm%3A5.0.1#./.yarn/patches/react-scripts-npm-5.0.1-d06bd2d5ad.patch",
"@shapeshiftoss/bitcoinjs-lib@5.2.0-shapeshift.2": "patch:@shapeshiftoss/bitcoinjs-lib@npm%3A5.2.0-shapeshift.2#./.yarn/patches/@shapeshiftoss-bitcoinjs-lib-npm-5.2.0-shapeshift.2-e59ff81828.patch"
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions packages/caip/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +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'

export const cosmosAssetId: AssetId = 'cosmos:cosmoshub-4/slip44:118'
export const thorchainAssetId: AssetId = 'cosmos:thorchain-1/slip44:931'
Expand Down
22 changes: 18 additions & 4 deletions packages/chain-adapters/src/solana/SolanaChainAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { ErrorHandler } from '../error/ErrorHandler'
import type {
Account,
BroadcastTransactionInput,
BuildSendApiTxInput,
BuildSendTxInput,
FeeDataEstimate,
GetAddressInput,
Expand Down Expand Up @@ -203,14 +204,13 @@ export class ChainAdapter implements IChainAdapter<KnownChainIds.SolanaMainnet>
}
}

async buildSendTransaction(input: BuildSendTxInput<KnownChainIds.SolanaMainnet>): Promise<{
async buildSendApiTransaction(input: BuildSendApiTxInput<KnownChainIds.SolanaMainnet>): Promise<{
txToSign: SignTx<KnownChainIds.SolanaMainnet>
}> {
try {
const { accountNumber, to, chainSpecific, value } = input
const { from, accountNumber, to, chainSpecific, value } = input
const { instructions = [], tokenId } = chainSpecific

const from = await this.getAddress(input)
const { blockhash } = await this.connection.getLatestBlockhash()

const computeUnitLimit = chainSpecific.computeUnitLimit
Expand Down Expand Up @@ -250,6 +250,19 @@ export class ChainAdapter implements IChainAdapter<KnownChainIds.SolanaMainnet>
}
}

async buildSendTransaction(input: BuildSendTxInput<KnownChainIds.SolanaMainnet>): Promise<{
txToSign: SignTx<KnownChainIds.SolanaMainnet>
}> {
try {
const from = await this.getAddress(input)
const txToSign = await this.buildSendApiTransaction({ ...input, from })

return txToSign
} catch (err) {
return ErrorHandler(err)
}
}

async signTransaction(signTxInput: SignTxInput<SolanaSignTx>): Promise<string> {
try {
const { txToSign, wallet } = signTxInput
Expand Down Expand Up @@ -453,6 +466,7 @@ export class ChainAdapter implements IChainAdapter<KnownChainIds.SolanaMainnet>
const destinationTokenAccount = getAssociatedTokenAddressSync(
new PublicKey(tokenId),
new PublicKey(to),
true,
)

// check if destination token account exists and add creation instruction if it doesn't
Expand All @@ -477,7 +491,7 @@ export class ChainAdapter implements IChainAdapter<KnownChainIds.SolanaMainnet>

instructions.push(
createTransferInstruction(
getAssociatedTokenAddressSync(new PublicKey(tokenId), new PublicKey(from)),
getAssociatedTokenAddressSync(new PublicKey(tokenId), new PublicKey(from), true),
destinationTokenAccount,
new PublicKey(from),
Number(value),
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 { CHAINFLIP_SUPPORTED_CHAIN_IDS } from './swappers/ChainflipSwapper/constants'
import { chainflipApi } from './swappers/ChainflipSwapper/endpoints'
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
38 changes: 38 additions & 0 deletions packages/swapper/src/swappers/ChainflipSwapper/ChainflipSwapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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, executeSolanaTransaction } from '../../utils'
import { CHAINFLIP_SUPPORTED_CHAIN_IDS } from './constants'
import { isSupportedAssetId } from './utils/helpers'

export const chainflipSwapper: Swapper = {
executeEvmTransaction,
executeSolanaTransaction,

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),
)
},
}
70 changes: 70 additions & 0 deletions packages/swapper/src/swappers/ChainflipSwapper/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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'
import { ChainflipNetwork } 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<ChainId, ChainflipNetwork>> = {
[KnownChainIds.EthereumMainnet]: ChainflipNetwork.Ethereum,
[KnownChainIds.ArbitrumMainnet]: ChainflipNetwork.Arbitrum,
[KnownChainIds.BitcoinMainnet]: ChainflipNetwork.Bitcoin,
[KnownChainIds.SolanaMainnet]: ChainflipNetwork.Solana,
}

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 = {
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',
}
Loading

0 comments on commit 540665d

Please sign in to comment.