Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
79 changes: 0 additions & 79 deletions oxlint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,6 @@
"count": 1
}
},
"packages/solana-wallet-snap/src/core/components/Domain/Domain.tsx": {
"typescript/no-unsafe-return": {
"count": 1
}
},
"packages/solana-wallet-snap/src/core/fees/FeeCalculator.test.ts": {
"typescript/no-explicit-any": {
"count": 1
Expand Down Expand Up @@ -558,24 +553,6 @@
"count": 1
}
},
"packages/solana-wallet-snap/src/core/sdk-extensions/codecs.test.ts": {
"typescript/no-unsafe-argument": {
"count": 1
}
},
"packages/solana-wallet-snap/src/core/sdk-extensions/codecs.ts": {
"typescript/no-unsafe-assignment": {
"count": 2
}
},
"packages/solana-wallet-snap/src/core/sdk-extensions/transaction-messages.ts": {
"no-unused-vars": {
"count": 1
},
"typescript/explicit-function-return-type": {
"count": 3
}
},
"packages/solana-wallet-snap/src/core/services/__mocks__/mockConnection.ts": {
"typescript/explicit-function-return-type": {
"count": 9
Expand Down Expand Up @@ -1254,28 +1231,9 @@
"count": 1
}
},
"packages/solana-wallet-snap/src/entities/instructions/instructions.test.ts": {
"vitest/no-conditional-in-test": {
"count": 4
}
},
"packages/solana-wallet-snap/src/entities/instructions/instructions.ts": {
"internal-snaps/no-in-operator": {
"count": 1
},
"typescript/explicit-function-return-type": {
"count": 2
},
"typescript/no-explicit-any": {
"count": 1
},
"typescript/no-unsafe-assignment": {
"count": 1
}
},
"packages/solana-wallet-snap/src/entities/instructions/programs/secp256k1-secp256r1.ts": {
"typescript/explicit-function-return-type": {
"count": 4
}
},
"packages/solana-wallet-snap/src/features/confirmation/components/Advanced/Advanced.tsx": {
Expand Down Expand Up @@ -1453,43 +1411,6 @@
"count": 1
}
},
"packages/solana-wallet-snap/src/infrastructure/event-emitter/EventEmitter.ts": {
"typescript/explicit-function-return-type": {
"count": 3
},
"typescript/no-explicit-any": {
"count": 2
}
},
"packages/solana-wallet-snap/src/polyfills/dom-exception/index.ts": {
"typescript/explicit-function-return-type": {
"count": 1
}
},
"packages/solana-wallet-snap/src/polyfills/ed25519/polyfill.ts": {
"internal-snaps/no-in-operator": {
"count": 1
},
"typescript/explicit-function-return-type": {
"count": 4
}
},
"packages/solana-wallet-snap/src/polyfills/index.ts": {
"typescript/explicit-function-return-type": {
"count": 1
}
},
"packages/solana-wallet-snap/src/polyfills/queue-microtask/index.ts": {
"no-shadow": {
"count": 1
},
"promise/no-callback-in-promise": {
"count": 1
},
"typescript/explicit-function-return-type": {
"count": 2
}
},
"packages/solana-wallet-snap/src/snapContext.ts": {
"no-unused-vars": {
"count": 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import type { SnapComponent } from '@metamask/snaps-sdk/jsx';
import type { SnapComponent, SnapElement } from '@metamask/snaps-sdk/jsx';
import { Box, Link } from '@metamask/snaps-sdk/jsx';

import type { Network } from '../../constants/solana';
import { getSolanaExplorerUrl } from '../../utils/getSolanaExplorerUrl';

export const Domain: SnapComponent<{
type DomainProps = {
domain: string;
scope: Network;
address: string;
}> = ({ domain, scope, address }) => {
return (
};

export const Domain: SnapComponent<DomainProps> = ({
domain,
scope,
address,
}) =>
(
<Box direction="horizontal" alignment="center">
{/* TODO: Bring it back when there is a smaller avatar option */}
{/* <Avatar size="sm" address={addressToCaip10(scope, address)} /> */}
<Link href={getSolanaExplorerUrl(scope, 'address', address)}>
{domain}
</Link>
</Box>
);
};
) as SnapElement<DomainProps>;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
getCompiledTransactionMessageEncoder,
pipe,
} from '@solana/kit';
import type { TransactionMessageBytes } from '@solana/kit';
import type { Transaction, TransactionMessageBytes } from '@solana/kit';
import type { GetMultipleAccountsApi, Rpc } from '@solana/kit';

import { MOCK_EXECUTION_SCENARIOS } from '../services/signer/mocks/scenarios';
Expand Down Expand Up @@ -63,7 +63,9 @@ describe('codecs', () => {

describe('fromTransactionToBase64String', () => {
it('encodes a transaction to a base64 string', () => {
const result = fromTransactionToBase64String(signedTransaction);
const result = fromTransactionToBase64String(
signedTransaction as Transaction,
);

expect(result).toStrictEqual(signedTransactionBase64Encoded);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const fromBase64StringCompiledMessageToTransaction = async (

const signerAccounts = compiledTransactionMessage.staticAccounts
.slice(0, compiledTransactionMessage.header.numSignerAccounts)
.map((address) => [address, null]);
.map((address) => [address, null] as const);

const signatures = Object.fromEntries(signerAccounts);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '@solana-program/compute-budget';
import type {
Address,
ExcludeTransactionMessageLifetime,
Instruction,
Rpc,
SimulateTransactionApi,
Expand Down Expand Up @@ -80,7 +81,10 @@ export const setTransactionMessageLifetimeUsingBlockhashIfMissing = <
>(
blockhashLifetimeConstraint: TransactionMessageWithBlockhashLifetime['lifetimeConstraint'],
transaction: TTransaction,
) =>
):
| (TTransaction & TransactionMessageWithBlockhashLifetime)
| (ExcludeTransactionMessageLifetime<TTransaction> &
TransactionMessageWithBlockhashLifetime) =>
isTransactionMessageWithBlockhashLifetime(transaction)
? transaction
: setTransactionMessageLifetimeUsingBlockhash(
Expand All @@ -94,7 +98,9 @@ export const setTransactionMessageLifetimeUsingBlockhashIfMissing = <
* @param instruction - The instruction to check.
* @returns A predicate function that checks if an instruction is a compute unit price instruction.
*/
export const isComputeUnitPriceInstruction = (instruction: Instruction) =>
export const isComputeUnitPriceInstruction = (
instruction: Instruction,
): boolean =>
instruction.programAddress === COMPUTE_BUDGET_PROGRAM_ADDRESS &&
identifyComputeBudgetInstruction({
data: new Uint8Array(), // Provide a default value for instruction.data it can be undefined
Expand Down Expand Up @@ -147,7 +153,9 @@ export const setComputeUnitPriceInstructionIfMissing = <
* @param instruction - The instruction to check.
* @returns A predicate function that checks if an instruction is a compute unit limit instruction.
*/
export const isComputeUnitLimitInstruction = (instruction: Instruction) =>
export const isComputeUnitLimitInstruction = (
instruction: Instruction,
): boolean =>
instruction.programAddress === COMPUTE_BUDGET_PROGRAM_ADDRESS &&
identifyComputeBudgetInstruction({
data: new Uint8Array(), // Provide a default value for instruction.data it can be undefined
Expand Down Expand Up @@ -281,7 +289,7 @@ export const estimateAndOverrideComputeUnitLimit = async <
),
],
};
} catch (error) {
} catch {
// If the estimate fails, return the original transaction message unchanged.
return transactionMessage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,48 @@ import {
toIInstruction,
} from './instructions';

const ASSOCIATED_TOKEN_PROGRAM_ADDRESS =
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';

/**
* Checks whether an instruction is an associated token account creation that
* uses accounts loaded from an address lookup table.
*
* @param accountKeys - The account keys inlined in the transaction message.
* @param instruction - The instruction to check.
* @returns Whether the instruction creates an associated token account.
*/
const isCreateAssociatedTokenInstruction = (
accountKeys: readonly string[],
instruction: { programIdIndex: number; accounts: readonly number[] },
): boolean =>
accountKeys[instruction.programIdIndex] ===
ASSOCIATED_TOKEN_PROGRAM_ADDRESS &&
instruction.accounts.some((index) => index >= accountKeys.length);

describe('toIInstruction', () => {
beforeEach(() => {
vi.clearAllMocks();
vi.spyOn(Errors, 'trackError').mockResolvedValue('tracked-error-id');
});

it.each(['legacy', 0, 1] as const)(
'preserves inline account order for version %s',
(version) => {
it.each([
{ version: 'legacy' as const, messageExtras: {} },
{ version: 0 as const, messageExtras: {} },
{
version: 1 as const,
messageExtras: {
transactionConfig: {
computeUnitLimit: 30_000,
heapSize: null,
loadedAccountsDataSizeLimit: 200_000,
priorityFee: null,
},
},
},
])(
'preserves inline account order for version $version',
({ version, messageExtras }) => {
const feePayer = address('11111111111111111111111111111112');
const readonlySigner = address('11111111111111111111111111111113');
const writableAccount = address('11111111111111111111111111111114');
Expand Down Expand Up @@ -60,14 +93,7 @@ describe('toIInstruction', () => {
],
instructions: [instruction],
recentBlockhash: original.transaction.message.recentBlockhash,
...(version === 1 && {
transactionConfig: {
computeUnitLimit: 30_000,
heapSize: null,
loadedAccountsDataSizeLimit: 200_000,
priorityFee: null,
},
}),
...messageExtras,
},
},
};
Expand Down Expand Up @@ -95,15 +121,13 @@ describe('toIInstruction', () => {
'parses account creation using lookup table accounts in a %s',
(_, transaction) => {
const { accountKeys, instructions } = transaction.transaction.message;
const accountCreationInstruction = instructions.find(
(instruction) =>
accountKeys[instruction.programIdIndex] ===
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' &&
instruction.accounts.some((index) => index >= accountKeys.length),
const accountCreationInstruction = instructions.find((instruction) =>
isCreateAssociatedTokenInstruction(accountKeys, instruction),
);
assert(
accountCreationInstruction,
'Fixture must contain an associated token instruction',
);
if (!accountCreationInstruction) {
throw new Error('Fixture must contain an associated token instruction');
}

const converted = toIInstruction(accountCreationInstruction, transaction);

Expand All @@ -118,8 +142,9 @@ describe('toIInstruction', () => {
it('resolves writable and readonly lookup addresses in account index order', () => {
const transaction = EXPECTED_SWAP_SOL_TO_OBRIC_DATA;
const { accountKeys } = transaction.transaction.message;
const { writable = [], readonly = [] } =
transaction.meta?.loadedAddresses ?? {};
const loadedAddresses = transaction.meta?.loadedAddresses;
assert(loadedAddresses, 'Fixture must contain loaded addresses');
const { writable, readonly } = loadedAddresses;
const writableIndex = accountKeys.length;
const readonlyIndex = writableIndex + writable.length;
const [originalInstruction] = transaction.transaction.message.instructions;
Expand Down
Loading
Loading