Skip to content

Commit

Permalink
fix: add address lookup table
Browse files Browse the repository at this point in the history
  • Loading branch information
NeOMakinG committed Nov 18, 2024
1 parent c8b7996 commit 9c1baa9
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"@shapeshiftoss/hdwallet-metamask-multichain": "1.55.12",
"@shapeshiftoss/hdwallet-native": "1.55.12",
"@shapeshiftoss/hdwallet-native-vault": "1.55.12",
"@shapeshiftoss/hdwallet-phantom": "1.55.12",
"@shapeshiftoss/hdwallet-phantom": "../hdwallet/packages/hdwallet-phantom",
"@shapeshiftoss/hdwallet-walletconnectv2": "1.55.12",
"@shapeshiftoss/swapper": "workspace:^",
"@shapeshiftoss/types": "workspace:^",
Expand Down
29 changes: 29 additions & 0 deletions packages/chain-adapters/src/solana/SolanaChainAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from '@solana/spl-token'
import type { TransactionInstruction } from '@solana/web3.js'
import {
AddressLookupTableAccount,
ComputeBudgetProgram,
Connection,
PublicKey,
Expand Down Expand Up @@ -236,6 +237,10 @@ export class ChainAdapter implements IChainAdapter<KnownChainIds.SolanaMainnet>
)
}

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

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

return { txToSign }
Expand Down Expand Up @@ -540,4 +546,27 @@ export class ChainAdapter implements IChainAdapter<KnownChainIds.SolanaMainnet>
get httpProvider(): unchained.solana.Api {
return this.providers.http
}

public async getAddressLookupTableAccounts(
addresses: string[],
): Promise<AddressLookupTableAccount[]> {
const addressLookupTableAccountInfos = await this.connection.getMultipleAccountsInfo(
addresses.map(key => new PublicKey(key)),
)

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>())
}
}
1 change: 1 addition & 0 deletions packages/chain-adapters/src/solana/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type BuildTxInput = {
computeUnitPrice?: string
tokenId?: string
instructions?: SolanaTxInstruction[]
addressLookupTableAccounts?: string[]
}

export type GetFeeDataInput = {
Expand Down
1 change: 1 addition & 0 deletions packages/swapper/src/swappers/JupiterSwapper/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const jupiterApi: SwapperApi = {
value: '0',
accountNumber: step.accountNumber,
chainSpecific: {
addressLookupTableAccounts: swapResponse.addressLookupTableAddresses,
instructions: [...computeBudgetInstructions, ...setupInstructions, swapInstruction],
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const _getTradeQuote = async (
apiUrl: jupiterUrl,
sourceAsset: sellAsset.assetId === solAssetId ? wrappedSolAssetId : sellAsset.assetId,
destinationAsset: buyAsset.assetId === solAssetId ? wrappedSolAssetId : buyAsset.assetId,
toAddress: receiveAddress,
commissionBps: affiliateBps,
amount: sellAmount,
slippageBps: convertDecimalPercentageToBasisPoints(
Expand Down
3 changes: 3 additions & 0 deletions packages/swapper/src/swappers/JupiterSwapper/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type GetJupiterQuoteArgs = {
commissionBps: string
amount: string
slippageBps?: string
toAddress: string
}

type GetJupiterSwapArgs = {
Expand All @@ -34,13 +35,15 @@ export const getJupiterQuote = ({
apiUrl,
sourceAsset,
destinationAsset,
toAddress,
commissionBps,
amount,
slippageBps,
}: GetJupiterQuoteArgs): Promise<Result<AxiosResponse<QuoteResponse, any>, SwapErrorRight>> =>
jupiterService.get<QuoteResponse>(
`${apiUrl}/quote` +
`?inputMint=${fromAssetId(sourceAsset).assetReference}` +
`&destinationTokenAccount=${toAddress}` +
`&outputMint=${fromAssetId(destinationAsset).assetReference}` +
`&amount=${amount}` +
`&slippageBps=${slippageBps}` +
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11451,9 +11451,9 @@ __metadata:
languageName: node
linkType: hard

"@shapeshiftoss/hdwallet-phantom@npm:1.55.12":
"@shapeshiftoss/hdwallet-phantom@file:../hdwallet/packages/hdwallet-phantom::locator=%40shapeshiftoss%2Fweb%40workspace%3A.":
version: 1.55.12
resolution: "@shapeshiftoss/hdwallet-phantom@npm:1.55.12"
resolution: "@shapeshiftoss/hdwallet-phantom@file:../hdwallet/packages/hdwallet-phantom#../hdwallet/packages/hdwallet-phantom::hash=31dd14&locator=%40shapeshiftoss%2Fweb%40workspace%3A."
dependencies:
"@shapeshiftoss/bitcoinjs-lib": 5.2.0-shapeshift.2
"@shapeshiftoss/hdwallet-core": 1.55.12
Expand All @@ -11462,7 +11462,7 @@ __metadata:
bitcoinjs-message: ^2.0.0
ethers: 5.7.2
lodash: ^4.17.21
checksum: eeaffafd3ccfb06b08349b5f45a28d0ce2b2c3677b625ff2dea29dd148b637074875c523acf7595e353868f18f9425af304ea0643de240682bc8802efdb23911
checksum: 1e79337defbaee14298d6f51f4d79072881ac59199d07b11943bde1c53fdb579a7fd41bf39c3423e11679386f3228864b7343011ae99feb22de05df9d8367c44
languageName: node
linkType: hard

Expand Down Expand Up @@ -11682,7 +11682,7 @@ __metadata:
"@shapeshiftoss/hdwallet-metamask-multichain": 1.55.12
"@shapeshiftoss/hdwallet-native": 1.55.12
"@shapeshiftoss/hdwallet-native-vault": 1.55.12
"@shapeshiftoss/hdwallet-phantom": 1.55.12
"@shapeshiftoss/hdwallet-phantom": ../hdwallet/packages/hdwallet-phantom
"@shapeshiftoss/hdwallet-walletconnectv2": 1.55.12
"@shapeshiftoss/swapper": "workspace:^"
"@shapeshiftoss/types": "workspace:^"
Expand Down

0 comments on commit 9c1baa9

Please sign in to comment.