Commit a9f718f
authored
refactor(deps): source BN from anchor and drop unused @types/bn.js (#688)
* refactor(deps): source BN from anchor and drop unused @types/bn.js
Tests imported BN directly from bn.js while declaring only @types/bn.js,
resolving the runtime package transitively. @anchor-lang/core re-exports
BN and depends on bn.js itself, so these tests can take BN from the
Anchor namespace they already import instead.
- Rewrite 17 test files from a direct bn.js import to anchor.BN
- Drop the now-dead direct bn.js dependency from two packages
- Remove @types/bn.js from 16 packages with no BN in their type surface
- Regenerate the affected per-project lockfiles
@types/bn.js is kept wherever BN is reachable. bn.js ships no type
declarations, so it is the only supplier of the BN type that Anchor maps
u64/i64/u128/i128 IDL fields to; removing it there widens those fields to
any instead of failing, because every tsconfig sets skipLibCheck.
* refactor(tokens): decode token accounts with kit codecs
Three litesvm tests decoded SPL token accounts with AccountLayout from
@solana/spl-token. The official program clients expose a decoder for this,
so use getTokenDecoder() from @solana-program/token, or token-2022 for the
Token-2022 example. amount is a bigint from both, so assertions are
unchanged. @solana/spl-token stays: all three still use its instruction
builders.
Also drops the unused ethers dependency from external-delegate-token-master.
The token clients are pinned to 0.15.0 rather than the 0.14.x used
elsewhere in the repo, because 0.14.x imports
getMinimumBalanceForRentExemption from @solana/kit, an export kit removed
in 7.1.0.
* refactor: remove dead dependencies and the last direct bn.js import
Removes dependencies with no importer in their package:
- nft-operations/anchor: @metaplex-foundation/mpl-token-metadata,
@metaplex-foundation/umi, axios, node-fetch
- cnft-burn/anchor: @metaplex-foundation/umi
- cutils/anchor: @metaplex-foundation/js
- nft-meta-data-pointer/{anchor,app}: @coral-xyz/spl-token,
browserify-sign, crypto-js, @chakra-ui/next-js
@metaplex-foundation/js is kept in cnft-burn, which does import it, and
Chakra's emotion and framer-motion peers are kept because Chakra needs
them. browserify-sign and crypto-js were version-floor pins rather than
real dependencies: crypto-js still resolves to 4.2.0 transitively, and
nothing in the tree depends on browserify-sign at all.
Also replaces the repository's last direct bn.js import, in cnft-burn's
ReadApi wrapper, where new BN(leaf_id).toArray('le', 8) becomes
getU64Encoder().encode(BigInt(leaf_id)).
* refactor(escrow): replace borsh helper with kit struct codecs
Both escrow examples wrapped a local borshSerialize(schema, data) helper
to build instruction data and to decode the Offer account. Replaces it
with getStructEncoder and getStructDecoder, matching the shape already
used in basics/close-account/native, and drops the borsh dependency.
Field widths and order were checked against each program's Rust source.
The decoder's fixed size of 113 matches Offer::LEN, and decoding the
pubkey fields with getAddressDecoder yields Address values directly, so
the tests no longer round-trip them through a raw byte array.
* refactor(basics,tokens): encode native instruction data with kit codecs
The remaining native and pinocchio examples hand-rolled borsh schemas
inline in their tests to build instruction data and decode their own
program accounts. Each example now exposes a ts/ client module built on
@solana/kit codecs, following basics/close-account/native: instruction
encoders and builders under ts/instructions, account decoders under
ts/state, and a discriminant map matching the program's instruction enum.
Tests import the builders instead of serializing by hand, and borsh is
removed from all twelve packages.
Encodings were checked field by field against each program's Rust source.
Where a program has no instruction discriminant, as in account-data,
processing-instructions and repository-layout, the encoder covers the bare
payload rather than inventing a tag.
Covers the last of the packages carrying borsh, so the repository no
longer depends on it anywhere.1 parent 56e16c9 commit a9f718f
171 files changed
Lines changed: 5052 additions & 4653 deletions
File tree
- basics
- account-data
- anchor
- native
- tests
- ts
- instructions
- state
- checking-accounts/anchor
- close-account/anchor
- cross-program-invocation
- anchor
- native
- tests
- ts
- instructions
- favorites
- anchor/tests
- native
- tests
- ts
- instructions
- state
- hello-solana/anchor
- pda-rent-payer
- anchor/tests
- native
- tests
- ts
- instructions
- processing-instructions
- anchor
- native
- tests
- ts
- instructions
- program-derived-addresses
- anchor
- native
- tests
- ts
- instructions
- state
- realloc
- anchor
- native
- tests
- ts
- instructions
- state
- repository-layout
- anchor
- native
- tests
- ts
- instructions
- pinocchio
- tests
- ts
- instructions
- transfer-sol
- anchor/tests
- native
- tests
- ts
- instructions
- compression
- cnft-burn/anchor
- tests/ReadApi
- cutils/anchor
- tokens
- create-token/anchor
- escrow
- native
- tests
- pinocchio
- tests
- external-delegate-token-master/anchor
- tests
- nft-operations/anchor
- pda-mint-authority
- anchor/tests
- native
- tests
- ts
- instructions
- token-2022
- basics/anchor/tests
- cpi-guard/anchor
- group/anchor
- metadata/anchor
- mint-close-authority/anchor
- nft-meta-data-pointer
- anchor
- app
- permanent-delegate/anchor
- transfer-hook
- account-data-as-seed/anchor/tests
- counter/anchor/tests
- hello-world/anchor/tests
- transfer-switch/anchor
- tests
- token-fundraiser/anchor
- tests
- token-swap/anchor/tests
- transfer-tokens
- anchor
- tests
- native
- tests
- ts
- instructions
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
| 11 | + | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
3 | | - | |
4 | 2 | | |
5 | 3 | | |
6 | 4 | | |
| |||
11 | 9 | | |
12 | 10 | | |
13 | 11 | | |
14 | | - | |
15 | | - | |
16 | 12 | | |
17 | 13 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
| 14 | + | |
38 | 15 | | |
39 | 16 | | |
40 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
41 | 24 | | |
42 | 25 | | |
43 | 26 | | |
| |||
51 | 34 | | |
52 | 35 | | |
53 | 36 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
| 37 | + | |
78 | 38 | | |
79 | 39 | | |
80 | 40 | | |
| |||
92 | 52 | | |
93 | 53 | | |
94 | 54 | | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
| 55 | + | |
100 | 56 | | |
101 | 57 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
| |||
0 commit comments