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

feat: implement jupiter as a swapper #8120

Open
wants to merge 146 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
146 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
8dba9ef
Merge remote-tracking branch 'origin/develop' into add-chainflip
gomesalexandre Nov 12, 2024
b28bb4e
chore: trigger CI
gomesalexandre Nov 12, 2024
757f42e
feat: swapper re-enable solana
gomesalexandre Nov 12, 2024
d2afed0
feat: solana fee estimates
gomesalexandre Nov 12, 2024
86e7a0b
fix: derp
gomesalexandre Nov 12, 2024
7f3fafd
feat: solana progression
gomesalexandre Nov 12, 2024
e165134
feat: more sol progression
gomesalexandre Nov 12, 2024
651649d
feat: solana build api Tx input and wire-up in flip
gomesalexandre Nov 12, 2024
9ea7c28
feat: execute solana Tx
gomesalexandre Nov 12, 2024
5992082
fix: solana status
gomesalexandre Nov 12, 2024
5da5073
feat: slippidge protection
gomesalexandre Nov 12, 2024
9072126
feat: start jupiter swapper implementation
NeOMakinG Nov 8, 2024
bd177c3
fix: continue
NeOMakinG Nov 12, 2024
35648e0
Merge remote-tracking branch 'origin/develop' into add-chainflip
gomesalexandre Nov 13, 2024
bcce88c
feat: add getChainFlipSwap
gomesalexandre Nov 13, 2024
d097f8c
feat: getChainFlipIdFromAssetId
gomesalexandre Nov 13, 2024
38492b0
feat: remove derp monkey patches
gomesalexandre Nov 13, 2024
b514351
feat: and search too
gomesalexandre Nov 13, 2024
9ea3859
feat: cleanup isSwapper
gomesalexandre Nov 13, 2024
204902f
fix: derp
gomesalexandre Nov 13, 2024
cf52fd4
fix: continue
NeOMakinG Nov 13, 2024
54e304d
fix: remove copy pasta
NeOMakinG Nov 13, 2024
84b12de
fix: refactor
NeOMakinG Nov 13, 2024
85b771e
fix: refactor
NeOMakinG Nov 13, 2024
2a5dce4
Merge branch 'add-chainflip' into jup-swapper
NeOMakinG Nov 13, 2024
ef00665
fix: solana token sends to PDAs
gomesalexandre Nov 14, 2024
b2130bd
Merge branch 'add-chainflip' into jup-swapper
NeOMakinG Nov 14, 2024
67adc86
Merge branch 'develop' into jup-swapper
NeOMakinG Nov 14, 2024
8b1e162
fix: continue
NeOMakinG Nov 15, 2024
dc473d2
fix: continue
NeOMakinG Nov 15, 2024
c8b7996
fix: comment fee address because cant use multisig
NeOMakinG Nov 15, 2024
9c1baa9
fix: add address lookup table
NeOMakinG Nov 18, 2024
08d1bab
fix: continue
NeOMakinG Nov 18, 2024
3c8e8e2
fix: pending
NeOMakinG Nov 18, 2024
6950fce
fix: continue
NeOMakinG Nov 19, 2024
1ba279b
fix: finish
NeOMakinG Nov 19, 2024
b913787
fix: remove wherever
NeOMakinG Nov 19, 2024
0481295
fix: continue
NeOMakinG Nov 19, 2024
0252a9e
fix: omg
NeOMakinG Nov 19, 2024
98aad4c
Merge branch 'develop' into jup-swapper
NeOMakinG Nov 20, 2024
c6724b7
Merge branch 'develop' into jup-swapper
NeOMakinG Nov 20, 2024
957945a
fix: wouhouuuuu
NeOMakinG Nov 20, 2024
87894ba
fix: to is not required
NeOMakinG Nov 20, 2024
5ac452c
fix: update hdwallet
NeOMakinG Nov 21, 2024
e4891d6
fix: review feedbacks
NeOMakinG Nov 22, 2024
f7317ee
Merge branch 'develop' into jup-swapper
NeOMakinG Nov 22, 2024
4e76e81
fix: review feedbacks
NeOMakinG Nov 25, 2024
0001e53
fix: review feedbacks
NeOMakinG Nov 26, 2024
9c66e61
fix: review feedbacks
NeOMakinG Nov 26, 2024
0f1cbcd
fix: instructions at quote time
NeOMakinG Nov 26, 2024
0111088
fix: split rate and quote
NeOMakinG Nov 26, 2024
14e71c1
Merge branch 'develop' into jup-swapper
NeOMakinG Nov 26, 2024
56e268f
fix: review feedbacks
NeOMakinG Nov 26, 2024
d2dc8f5
Merge branch 'develop' into jup-swapper
NeOMakinG Nov 27, 2024
6978cac
fix: review feedbacks
NeOMakinG Nov 27, 2024
0af7387
fix: lifi fees same as shapeshift fees
NeOMakinG Nov 27, 2024
5780800
fix: refetch prices at quote time
NeOMakinG Nov 27, 2024
0157593
fix: remove metadata mapping
NeOMakinG Nov 27, 2024
3f8c1d1
fix: split quote and rate
NeOMakinG Nov 27, 2024
561cd08
fix: review feedbacks
NeOMakinG Nov 28, 2024
ebecda4
Merge branch 'develop' into jup-swapper
NeOMakinG Nov 28, 2024
64c483d
Merge branch 'develop' into jup-swapper
gomesalexandre Nov 29, 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
5 changes: 3 additions & 2 deletions .env.base
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ 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_CHAINFLIP_SWAP=false
gomesalexandre marked this conversation as resolved.
Show resolved Hide resolved
REACT_APP_FEATURE_CHAINFLIP_SWAP_DCA=false
REACT_APP_FEATURE_COWSWAP=true
REACT_APP_FEATURE_LIFI_SWAP=true
REACT_APP_FEATURE_THOR_SWAP=true
REACT_APP_FEATURE_THOR_SWAP_STREAMING_SWAPS=true
REACT_APP_FEATURE_ZRX_SWAP=true
REACT_APP_FEATURE_JUPITER_SWAP=false

# chat woot
REACT_APP_CHATWOOT_TOKEN=jmoXp9BPMSPEYHeJX5YKT15Q
Expand Down
7 changes: 4 additions & 3 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# feature flags
REACT_APP_FEATURE_CHAINFLIP=true
REACT_APP_FEATURE_CHAINFLIP_DCA=false
REACT_APP_FEATURE_PUBLIC_TRADE_ROUTE=true
REACT_APP_FEATURE_CHAINFLIP_SWAP=true
REACT_APP_FEATURE_CHAINFLIP_SWAP_DCA=false
REACT_APP_FEATURE_PUBLIC_TRADE_ROUTE=false
REACT_APP_FEATURE_LIMIT_ORDERS=true
REACT_APP_FEATURE_JUPITER_SWAP=true

# logging
REACT_APP_REDUX_WINDOW=false
Expand Down
4 changes: 2 additions & 2 deletions .env.develop
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# feature flags
REACT_APP_FEATURE_LIMIT_ORDERS=true
REACT_APP_FEATURE_CHAINFLIP=true
REACT_APP_FEATURE_CHAINFLIP_DCA=false
REACT_APP_FEATURE_CHAINFLIP_SWAP=true
REACT_APP_FEATURE_CHAINFLIP_SWAP_DCA=false

# mixpanel
REACT_APP_MIXPANEL_TOKEN=1c1369f6ea23a6404bac41b42817cc4b
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"@formatjs/intl-numberformat": "^8.10.3",
"@formatjs/intl-pluralrules": "^5.2.14",
"@json-rpc-tools/utils": "^1.7.6",
"@jup-ag/api": "^6.0.30",
"@keepkey/hdwallet-keepkey-rest": "1.40.42",
"@keepkey/keepkey-sdk": "0.2.57",
"@ledgerhq/hw-transport-webusb": "^6.29.2",
Expand Down
2 changes: 2 additions & 0 deletions packages/caip/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export const arbitrumAssetId: AssetId = 'eip155:42161/slip44:60'
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 wrappedSolAssetId: AssetId =
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:So11111111111111111111111111111111111111112'

export const foxatarAssetId: AssetId =
'eip155:137/erc721:0x2e727c425a11ce6b8819b3004db332c12d2af2a2'
Expand Down
157 changes: 134 additions & 23 deletions packages/chain-adapters/src/solana/SolanaChainAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@shapeshiftoss/caip'
import type {
HDWallet,
SolanaAddressLookupTableAccountInfo,
SolanaSignTx,
SolanaTxInstruction,
SolanaWallet,
Expand All @@ -22,18 +23,22 @@ import {
createTransferInstruction,
getAccount,
getAssociatedTokenAddressSync,
TOKEN_2022_PROGRAM_ID,
TOKEN_PROGRAM_ID,
TokenAccountNotFoundError,
TokenInvalidAccountOwnerError,
} from '@solana/spl-token'
import type { TransactionInstruction } from '@solana/web3.js'
import type { AccountInfo, TransactionInstruction } from '@solana/web3.js'
import {
AddressLookupTableAccount,
ComputeBudgetProgram,
Connection,
PublicKey,
SystemProgram,
TransactionMessage,
VersionedTransaction,
} from '@solana/web3.js'
import { isUndefined } from 'lodash'
import PQueue from 'p-queue'

import type { ChainAdapter as IChainAdapter } from '../api'
Expand Down Expand Up @@ -62,6 +67,8 @@ import { toAddressNList, toRootDerivationPath } from '../utils'
import { assertAddressNotSanctioned } from '../utils/validateAddress'
import { microLamportsToLamports } from './utils'

export const svmChainIds = [KnownChainIds.SolanaMainnet] as const
gomesalexandre marked this conversation as resolved.
Show resolved Hide resolved

// Maximum compute units allowed for a single solana transaction
const MAX_COMPUTE_UNITS = 1400000

Expand Down Expand Up @@ -251,6 +258,10 @@ export class ChainAdapter implements IChainAdapter<KnownChainIds.SolanaMainnet>
)
}

const addressLookupTableAccountInfos = await this.getAddressLookupTableAccounts(
chainSpecific.addressLookupTableAccounts ?? [],
)

const txToSign: SignTx<KnownChainIds.SolanaMainnet> = {
addressNList: toAddressNList(this.getBIP44Params({ accountNumber })),
blockHash: blockhash,
Expand All @@ -259,6 +270,7 @@ export class ChainAdapter implements IChainAdapter<KnownChainIds.SolanaMainnet>
instructions,
to: tokenId ? '' : to,
value: tokenId ? '' : value,
addressLookupTableAccountInfos,
}

return { txToSign }
Expand Down Expand Up @@ -449,8 +461,14 @@ export class ChainAdapter implements IChainAdapter<KnownChainIds.SolanaMainnet>
const { to, chainSpecific } = input
const { from, tokenId, instructions = [] } = chainSpecific

if (!to) throw new Error('to is required')
gomesalexandre marked this conversation as resolved.
Show resolved Hide resolved
if (!input.value) throw new Error('value is required')
const estimationInstructions = [...instructions]
gomesalexandre marked this conversation as resolved.
Show resolved Hide resolved

const addressLookupTableAccounts = await this.getSolanaAddressLookupTableAccountsInfo(
chainSpecific.addressLookupTableAccounts ?? [],
)

if (isUndefined(input.to)) throw new Error(`${this.getName()}ChainAdapter: to is required`)
if (!input.value) throw new Error(`${this.getName()}ChainAdapter: value is required`)

const value = Number(input.value)

Expand All @@ -463,9 +481,9 @@ export class ChainAdapter implements IChainAdapter<KnownChainIds.SolanaMainnet>
value: input.value,
})

instructions.push(...tokenTransferInstructions)
estimationInstructions.push(...tokenTransferInstructions)
} else {
instructions.push(
estimationInstructions.push(
SystemProgram.transfer({
fromPubkey: new PublicKey(from),
toPubkey: new PublicKey(to),
Expand All @@ -477,17 +495,19 @@ export class ChainAdapter implements IChainAdapter<KnownChainIds.SolanaMainnet>

// Set compute unit limit to the maximum compute units for the purposes of estimating the compute unit cost of a transaction,
// ensuring the transaction does not exceed the maximum compute units alotted for a single transaction.
instructions.push(ComputeBudgetProgram.setComputeUnitLimit({ units: MAX_COMPUTE_UNITS }))
estimationInstructions.push(
ComputeBudgetProgram.setComputeUnitLimit({ units: MAX_COMPUTE_UNITS }),
)

// placeholder compute unit price instruction for the purposes of estimating the compute unit cost of a transaction
instructions.push(ComputeBudgetProgram.setComputeUnitPrice({ microLamports: 0 }))
estimationInstructions.push(ComputeBudgetProgram.setComputeUnitPrice({ microLamports: 0 }))

const message = new TransactionMessage({
payerKey: new PublicKey(input.chainSpecific.from),
instructions,
instructions: estimationInstructions,
// static block hash as fee estimation replaces the block hash with latest to save us a client side call
recentBlockhash: '4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZAMdL4VZHirAn',
}).compileToV0Message()
}).compileToV0Message(addressLookupTableAccounts)

const transaction = new VersionedTransaction(message)

Expand All @@ -507,10 +527,49 @@ export class ChainAdapter implements IChainAdapter<KnownChainIds.SolanaMainnet>
}): Promise<TransactionInstruction[]> {
const instructions: TransactionInstruction[] = []

const { instruction, destinationTokenAccount } =
await this.createAssociatedTokenAccountInstruction({ from, to, tokenId })

if (instruction) {
instructions.push(instruction)
}

instructions.push(
createTransferInstruction(
getAssociatedTokenAddressSync(new PublicKey(tokenId), new PublicKey(from), true),
destinationTokenAccount,
new PublicKey(from),
Number(value),
),
)

return instructions
}

public async createAssociatedTokenAccountInstruction({
from,
to,
tokenId,
}: {
from: string
to: string
tokenId: string
}): Promise<{
instruction?: TransactionInstruction
destinationTokenAccount: PublicKey
}> {
const accountInfo = await this.connection.getAccountInfo(new PublicKey(tokenId))

const TOKEN_PROGRAM =
accountInfo?.owner.toString() === TOKEN_2022_PROGRAM_ID.toString()
? TOKEN_2022_PROGRAM_ID
: TOKEN_PROGRAM_ID
NeOMakinG marked this conversation as resolved.
Show resolved Hide resolved

const destinationTokenAccount = getAssociatedTokenAddressSync(
new PublicKey(tokenId),
new PublicKey(to),
true,
TOKEN_PROGRAM,
)

// check if destination token account exists and add creation instruction if it doesn't
Expand All @@ -521,31 +580,27 @@ export class ChainAdapter implements IChainAdapter<KnownChainIds.SolanaMainnet>
err instanceof TokenAccountNotFoundError ||
err instanceof TokenInvalidAccountOwnerError
) {
instructions.push(
createAssociatedTokenAccountInstruction(
return {
instruction: createAssociatedTokenAccountInstruction(
// sender pays for creation of the token account
new PublicKey(from),
destinationTokenAccount,
new PublicKey(to),
new PublicKey(tokenId),
TOKEN_PROGRAM,
),
)
destinationTokenAccount,
}
}
}

instructions.push(
createTransferInstruction(
getAssociatedTokenAddressSync(new PublicKey(tokenId), new PublicKey(from), true),
destinationTokenAccount,
new PublicKey(from),
Number(value),
),
)

return instructions
return {
instruction: undefined,
destinationTokenAccount,
}
}

private convertInstruction(instruction: TransactionInstruction): SolanaTxInstruction {
public convertInstruction(instruction: TransactionInstruction): SolanaTxInstruction {
return {
keys: instruction.keys.map(key => ({
pubkey: key.pubkey.toString(),
Expand All @@ -557,6 +612,12 @@ export class ChainAdapter implements IChainAdapter<KnownChainIds.SolanaMainnet>
}
}

public async getTxStatus(tx: unchained.solana.Tx, pubkey: string): Promise<unchained.TxStatus> {
const parsedTx = await this.parseTx(tx, pubkey)

return parsedTx.status
}

gomesalexandre marked this conversation as resolved.
Show resolved Hide resolved
private async parseTx(tx: unchained.solana.Tx, pubkey: string): Promise<Transaction> {
const { address: _, ...parsedTx } = await this.parser.parse(tx, pubkey)

Expand All @@ -572,4 +633,54 @@ export class ChainAdapter implements IChainAdapter<KnownChainIds.SolanaMainnet>
})),
}
}

get httpProvider(): unchained.solana.Api {
return this.providers.http
}

private async getAddressLookupTableAccountsInfo(
addresses: string[],
): Promise<(AccountInfo<Buffer> | null)[]> {
return await this.connection.getMultipleAccountsInfo(addresses.map(key => new PublicKey(key)))
}

private async getSolanaAddressLookupTableAccountsInfo(
addresses: string[],
): Promise<AddressLookupTableAccount[]> {
const addressLookupTableAccountInfos = await this.getAddressLookupTableAccountsInfo(addresses)

return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
const addressLookupTableAddress = addresses[index]
if (accountInfo) {
const addressLookupTableAccount = new AddressLookupTableAccount({
key: new PublicKey(addressLookupTableAddress),
state: AddressLookupTableAccount.deserialize(
new Uint8Array(Buffer.from(accountInfo.data)),
),
})
acc.push(addressLookupTableAccount)
}

return acc
}, new Array<AddressLookupTableAccount>())
}

private async getAddressLookupTableAccounts(
addresses: string[],
): Promise<SolanaAddressLookupTableAccountInfo[]> {
const addressLookupTableAccountInfos = await this.getAddressLookupTableAccountsInfo(addresses)

return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
const addressLookupTableAddress = addresses[index]
if (accountInfo) {
const addressLookupTableAccount = {
key: addressLookupTableAddress,
data: Buffer.from(accountInfo.data),
}
acc.push(addressLookupTableAccount)
}

return acc
}, new Array<SolanaAddressLookupTableAccountInfo>())
}
}
2 changes: 2 additions & 0 deletions packages/chain-adapters/src/solana/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ export type BuildTxInput = {
computeUnitPrice?: string
tokenId?: string
instructions?: SolanaTxInstruction[]
addressLookupTableAccounts?: string[]
}

export type GetFeeDataInput = {
from: string
tokenId?: string
instructions?: TransactionInstruction[]
addressLookupTableAccounts?: string[]
}

export type FeeData = {
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 @@ -9,6 +9,9 @@ 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'
import { jupiterApi } from './swappers/JupiterSwapper/endpoints'
import { jupiterSwapper } from './swappers/JupiterSwapper/JupiterSwapper'
import { JUPITER_SUPPORTED_CHAIN_IDS } from './swappers/JupiterSwapper/utils/constants'
import { lifiApi } from './swappers/LifiSwapper/endpoints'
import {
LIFI_GET_TRADE_QUOTE_POLLING_INTERVAL,
Expand Down Expand Up @@ -85,6 +88,12 @@ export const swappers: Record<
supportedChainIds: CHAINFLIP_SUPPORTED_CHAIN_IDS,
pollingInterval: DEFAULT_GET_TRADE_QUOTE_POLLING_INTERVAL,
},
[SwapperName.Jupiter]: {
...jupiterSwapper,
...jupiterApi,
supportedChainIds: JUPITER_SUPPORTED_CHAIN_IDS,
pollingInterval: DEFAULT_GET_TRADE_QUOTE_POLLING_INTERVAL,
},
[SwapperName.Test]: undefined,
}

Expand All @@ -96,6 +105,7 @@ 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%
const DEFAULT_JUPITER_SLIPPAGE_DECIMAL_PERCENTAGE = '0.01' // 1%

export const getDefaultSlippageDecimalPercentageForSwapper = (
swapperName?: SwapperName,
Expand All @@ -117,6 +127,8 @@ export const getDefaultSlippageDecimalPercentageForSwapper = (
return DEFAULT_ARBITRUM_BRIDGE_SLIPPAGE_DECIMAL_PERCENTAGE
case SwapperName.Chainflip:
return DEFAULT_CHAINFLIP_SLIPPAGE_DECIMAL_PERCENTAGE
case SwapperName.Jupiter:
return DEFAULT_JUPITER_SLIPPAGE_DECIMAL_PERCENTAGE
default:
assertUnreachable(swapperName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export const _getTradeQuote = async (
const isStreaming = singleQuoteResponse.type === CHAINFLIP_DCA_QUOTE
const feeData = await getFeeData()

if (isStreaming && !deps.config.REACT_APP_FEATURE_CHAINFLIP_DCA) {
if (isStreaming && !deps.config.REACT_APP_FEATURE_CHAINFLIP_SWAP_DCA) {
gomesalexandre marked this conversation as resolved.
Show resolved Hide resolved
// DCA currently disabled - Streaming swap logic is very much tied to THOR currently and will deserve its own PR to generalize
// Even if we manage to get DCA swaps to execute, we wouldn't manage to properly poll with current web THOR-centric arch
continue
Expand Down
Loading