Repository: solana-labs/solana-program-library
Pull request #6389 (2024-03-11 17:46:46)

js: Remove direct usage of `@solana/options`
#### Problem

Per https://github.com/solana-labs/solana-program-library/pull/6388#discussion_r1519883981, we're using `@solana/options` by name, which is also included in `@solana/codecs`

#### Solution

Use everything from `@solana/codecs` directly, and remove the dependency on `@solana/options`


Patch:
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index ae7be2ac7..83e5a10eb 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -491,9 +491,6 @@ importers:
       '@solana/codecs':
         specifier: 2.0.0-preview.1
         version: 2.0.0-preview.1(fastestsmallesttextencoderdecoder@1.0.22)
-      '@solana/options':
-        specifier: 2.0.0-preview.1
-        version: 2.0.0-preview.1
       '@solana/spl-type-length-value':
         specifier: 0.1.0
         version: link:../../libraries/type-length-value/js
@@ -637,9 +634,6 @@ importers:
       '@solana/codecs':
         specifier: 2.0.0-preview.1
         version: 2.0.0-preview.1(fastestsmallesttextencoderdecoder@1.0.22)
-      '@solana/options':
-        specifier: 2.0.0-preview.1
-        version: 2.0.0-preview.1
       '@solana/spl-type-length-value':
         specifier: 0.1.0
         version: link:../../libraries/type-length-value/js
@@ -782,8 +776,8 @@ importers:
         version: 6.0.3
     devDependencies:
       '@solana/codecs-strings':
-        specifier: 2.0.0-preview.1.20240308041540.58947c719d61c07ce3b1ac04edf51a2b8fa4a3eb
-        version: 2.0.0-preview.1.20240308041540.58947c719d61c07ce3b1ac04edf51a2b8fa4a3eb(fastestsmallesttextencoderdecoder@1.0.22)
+        specifier: 2.0.0-preview.1.20240309110023.71d404f228034d8ffbeecaabbc1b43722af03487
+        version: 2.0.0-preview.1.20240309110023.71d404f228034d8ffbeecaabbc1b43722af03487(fastestsmallesttextencoderdecoder@1.0.22)
       '@solana/spl-memo':
         specifier: 0.2.3
         version: link:../../memo/js
@@ -2349,10 +2343,10 @@ packages:
       '@solana/errors': 2.0.0-preview.1
     dev: false
 
-  /@solana/codecs-core@2.0.0-preview.1.20240308041540.58947c719d61c07ce3b1ac04edf51a2b8fa4a3eb:
-    resolution: {integrity: sha512-g4UutMYkgbhA607ED7KXY/wIrkR1cH5Xx+I4x4gUIWHa3F3h2icnj3KszvCOsnpXl821a7LHdtmQWCrgrQIpsQ==}
+  /@solana/codecs-core@2.0.0-preview.1.20240309110023.71d404f228034d8ffbeecaabbc1b43722af03487:
+    resolution: {integrity: sha512-7rRk12B7ii62g9iHUHL9ZPI6uriMomjJGxiNYN6BkjYJg7kpPAdx30i/VNhR481nhGRoIvvRtyZGJ+UyGghPhQ==}
     dependencies:
-      '@solana/errors': 2.0.0-preview.1.20240308041540.58947c719d61c07ce3b1ac04edf51a2b8fa4a3eb
+      '@solana/errors': 2.0.0-preview.1.20240309110023.71d404f228034d8ffbeecaabbc1b43722af03487
     dev: true
 
   /@solana/codecs-data-structures@2.0.0-experimental.8618508:
@@ -2381,11 +2375,11 @@ packages:
       '@solana/errors': 2.0.0-preview.1
     dev: false
 
-  /@solana/codecs-numbers@2.0.0-preview.1.20240308041540.58947c719d61c07ce3b1ac04edf51a2b8fa4a3eb:
-    resolution: {integrity: sha512-rYpFqYNZqWH45N+bJ40O7v5tejtd6eJLK8Z7NKEK3E46p8MXkK3AenCz5pN/c9bwWzdifCt5OIgtnvEVXbMnsg==}
+  /@solana/codecs-numbers@2.0.0-preview.1.20240309110023.71d404f228034d8ffbeecaabbc1b43722af03487:
+    resolution: {integrity: sha512-wZeZ3XfufVsbgGO8FG6xvwI5mY8I4c+lhmNZeCo8C1GUJaSWsqljxA7ssTRr22PyjD8gwr6hFWqbyfws8S6jIg==}
     dependencies:
-      '@solana/codecs-core': 2.0.0-preview.1.20240308041540.58947c719d61c07ce3b1ac04edf51a2b8fa4a3eb
-      '@solana/errors': 2.0.0-preview.1.20240308041540.58947c719d61c07ce3b1ac04edf51a2b8fa4a3eb
+      '@solana/codecs-core': 2.0.0-preview.1.20240309110023.71d404f228034d8ffbeecaabbc1b43722af03487
+      '@solana/errors': 2.0.0-preview.1.20240309110023.71d404f228034d8ffbeecaabbc1b43722af03487
     dev: true
 
   /@solana/codecs-strings@2.0.0-experimental.8618508(fastestsmallesttextencoderdecoder@1.0.22):
@@ -2408,14 +2402,14 @@ packages:
       fastestsmallesttextencoderdecoder: 1.0.22
     dev: false
 
-  /@solana/codecs-strings@2.0.0-preview.1.20240308041540.58947c719d61c07ce3b1ac04edf51a2b8fa4a3eb(fastestsmallesttextencoderdecoder@1.0.22):
-    resolution: {integrity: sha512-e33PAF9UPqV2xPlIuWeYP7nRhiZuOqF96PJmMQhsk+ck74LtyldDbQ/sMnI9shXcdmjmJivDx/FykhNXI5VVig==}
+  /@solana/codecs-strings@2.0.0-preview.1.20240309110023.71d404f228034d8ffbeecaabbc1b43722af03487(fastestsmallesttextencoderdecoder@1.0.22):
+    resolution: {integrity: sha512-nFlykkY5uWoBiVnZK6XdzbdyGxd1923kO8ZHxpo86dJ1KTfCtolpeDLzO7IBuzp7kch0x2MHRUweXyGQomJwyA==}
     peerDependencies:
       fastestsmallesttextencoderdecoder: ^1.0.22
     dependencies:
-      '@solana/codecs-core': 2.0.0-preview.1.20240308041540.58947c719d61c07ce3b1ac04edf51a2b8fa4a3eb
-      '@solana/codecs-numbers': 2.0.0-preview.1.20240308041540.58947c719d61c07ce3b1ac04edf51a2b8fa4a3eb
-      '@solana/errors': 2.0.0-preview.1.20240308041540.58947c719d61c07ce3b1ac04edf51a2b8fa4a3eb
+      '@solana/codecs-core': 2.0.0-preview.1.20240309110023.71d404f228034d8ffbeecaabbc1b43722af03487
+      '@solana/codecs-numbers': 2.0.0-preview.1.20240309110023.71d404f228034d8ffbeecaabbc1b43722af03487
+      '@solana/errors': 2.0.0-preview.1.20240309110023.71d404f228034d8ffbeecaabbc1b43722af03487
       fastestsmallesttextencoderdecoder: 1.0.22
     dev: true
 
@@ -2439,8 +2433,8 @@ packages:
       commander: 12.0.0
     dev: false
 
-  /@solana/errors@2.0.0-preview.1.20240308041540.58947c719d61c07ce3b1ac04edf51a2b8fa4a3eb:
-    resolution: {integrity: sha512-PqBVMviXnHao5dtpDOAp5HgRhIWFkP4Y5DCXMC2PWAS+ogFo4kDwdMTEl5eCBNL/m7irpgrxDfexMdvK8J4DuA==}
+  /@solana/errors@2.0.0-preview.1.20240309110023.71d404f228034d8ffbeecaabbc1b43722af03487:
+    resolution: {integrity: sha512-yTCpyvfRrt6+SjB9CQLf9iAo2CH17FMnmMT9MeYTi4cqDQlzZch0AWNkFui4YoT6jC4MZJZ4D5eOOYwLD4G2dQ==}
     hasBin: true
     dependencies:
       chalk: 5.3.0
diff --git a/token-group/js/package.json b/token-group/js/package.json
index 9d3841ed1..68de94c0c 100644
--- a/token-group/js/package.json
+++ b/token-group/js/package.json
@@ -48,7 +48,6 @@
     },
     "dependencies": {
         "@solana/codecs": "2.0.0-preview.1",
-        "@solana/options": "2.0.0-preview.1",
         "@solana/spl-type-length-value": "0.1.0"
     },
     "devDependencies": {
diff --git a/token-metadata/js/package.json b/token-metadata/js/package.json
index a1a391f4a..4ee969d5a 100644
--- a/token-metadata/js/package.json
+++ b/token-metadata/js/package.json
@@ -48,7 +48,6 @@
     },
     "dependencies": {
         "@solana/codecs": "2.0.0-preview.1",
-        "@solana/options": "2.0.0-preview.1",
         "@solana/spl-type-length-value": "0.1.0"
     },
     "devDependencies": {
diff --git a/token-metadata/js/src/instruction.ts b/token-metadata/js/src/instruction.ts
index fcb429873..10493bfb0 100644
--- a/token-metadata/js/src/instruction.ts
+++ b/token-metadata/js/src/instruction.ts
@@ -3,13 +3,13 @@ import {
     getBooleanEncoder,
     getBytesEncoder,
     getDataEnumCodec,
+    getOptionEncoder,
     getStringEncoder,
     getStructEncoder,
     getTupleEncoder,
     getU64Encoder,
     mapEncoder,
 } from '@solana/codecs';
-import { getOptionEncoder } from '@solana/options';
 import { splDiscriminate } from '@solana/spl-type-length-value';
 import type { PublicKey } from '@solana/web3.js';
 import { SystemProgram, TransactionInstruction } from '@solana/web3.js';
diff --git a/token/js/package.json b/token/js/package.json
index 16a08c38c..4d9cbff04 100644
--- a/token/js/package.json
+++ b/token/js/package.json
@@ -60,7 +60,7 @@
         "buffer": "^6.0.3"
     },
     "devDependencies": {
-        "@solana/codecs-strings": "2.0.0-preview.1.20240308041540.58947c719d61c07ce3b1ac04edf51a2b8fa4a3eb",
+        "@solana/codecs-strings": "2.0.0-preview.1.20240309110023.71d404f228034d8ffbeecaabbc1b43722af03487",
         "@solana/spl-memo": "0.2.3",
         "@solana/web3.js": "^1.91.0",
         "@types/chai-as-promised": "^7.1.4",
diff --git a/token/program-2022/src/pod.rs b/token/program-2022/src/pod.rs
index 9c57224b3..09a98212b 100644
--- a/token/program-2022/src/pod.rs
+++ b/token/program-2022/src/pod.rs
@@ -1,14 +1,11 @@
 //! Rewrites of the base state types represented as Pods
 
 #[cfg(test)]
-use {
-    crate::state::{Account, Mint, Multisig},
-    solana_program::program_option::COption,
-};
+use crate::state::{Account, Mint, Multisig};
 use {
     crate::{instruction::MAX_SIGNERS, state::PackedSizeOf},
     bytemuck::{Pod, Zeroable},
-    solana_program::{program_pack::IsInitialized, pubkey::Pubkey},
+    solana_program::{program_option::COption, program_pack::IsInitialized, pubkey::Pubkey},
     spl_pod::{
         bytemuck::pod_get_packed_len,
         primitives::{PodBool, PodU64},
@@ -169,7 +166,6 @@ impl<T: Pod + Default> PodCOption<T> {
         }
     }
 }
-#[cfg(test)]
 impl<T: Pod + Default> From<COption<T>> for PodCOption<T> {
     fn from(opt: COption<T>) -> Self {
         match opt {
diff --git a/token/program-2022/src/processor.rs b/token/program-2022/src/processor.rs
index 30334ed18..4e93a4fd2 100644
--- a/token/program-2022/src/processor.rs
+++ b/token/program-2022/src/processor.rs
@@ -24,10 +24,11 @@ use {
             transfer_fee::{self, TransferFeeAmount, TransferFeeConfig},
             transfer_hook::{self, TransferHook, TransferHookAccount},
             AccountType, BaseStateWithExtensions, BaseStateWithExtensionsMut, ExtensionType,
-            StateWithExtensions, StateWithExtensionsMut,
+            PodStateWithExtensionsMut, StateWithExtensions, StateWithExtensionsMut,
         },
         instruction::{is_valid_signer_index, AuthorityType, TokenInstruction, MAX_SIGNERS},
         native_mint,
+        pod::{PodCOption, PodMint},
         state::{Account, AccountState, Mint, Multisig},
     },
     solana_program::{
@@ -43,6 +44,7 @@ use {
         system_instruction, system_program,
         sysvar::{rent::Rent, Sysvar},
     },
+    spl_pod::primitives::PodBool,
     spl_token_group_interface::instruction::TokenGroupInstruction,
     spl_token_metadata_interface::instruction::TokenMetadataInstruction,
     std::convert::{TryFrom, TryInto},
@@ -72,7 +74,7 @@ impl Processor {
             return Err(TokenError::NotRentExempt.into());
         }
 
-        let mut mint = StateWithExtensionsMut::<Mint>::unpack_uninitialized(&mut mint_data)?;
+        let mut mint = PodStateWithExtensionsMut::<PodMint>::unpack_uninitialized(&mut mint_data)?;
         let extension_types = mint.get_extension_types()?;
         if ExtensionType::try_calculate_account_len::<Mint>(&extension_types)? != mint_data_len {
             return Err(ProgramError::InvalidAccountData);
@@ -87,11 +89,10 @@ impl Processor {
             }
         }
 
-        mint.base.mint_authority = COption::Some(mint_authority);
+        mint.base.mint_authority = PodCOption::some(mint_authority);
         mint.base.decimals = decimals;
-        mint.base.is_initialized = true;
-        mint.base.freeze_authority = freeze_authority;
-        mint.pack_base();
+        mint.base.is_initialized = PodBool::from_bool(true);
+        mint.base.freeze_authority = freeze_authority.into();
         mint.init_account_type()?;
 
         Ok(())


Test patch:
diff --git a/token-metadata/js/test/instruction.test.ts b/token-metadata/js/test/instruction.test.ts
index b9826c06d..442bbe4d8 100644
--- a/token-metadata/js/test/instruction.test.ts
+++ b/token-metadata/js/test/instruction.test.ts
@@ -13,14 +13,14 @@ import {
     getBooleanDecoder,
     getBytesDecoder,
     getDataEnumCodec,
+    getOptionDecoder,
     getStringDecoder,
     getU64Decoder,
     getStructDecoder,
+    some,
 } from '@solana/codecs';
 import { splDiscriminate } from '@solana/spl-type-length-value';
-import type { Decoder } from '@solana/codecs';
-import type { Option } from '@solana/options';
-import { getOptionDecoder, some } from '@solana/options';
+import type { Decoder, Option } from '@solana/codecs';
 import { PublicKey, type TransactionInstruction } from '@solana/web3.js';
 
 function checkPackUnpack<T extends object>(
diff --git a/token/program-2022/tests/assert_instruction_count.rs b/token/program-2022/tests/assert_instruction_count.rs
index 37db71bac..1d24d7f3b 100644
--- a/token/program-2022/tests/assert_instruction_count.rs
+++ b/token/program-2022/tests/assert_instruction_count.rs
@@ -22,7 +22,7 @@ const TRANSFER_AMOUNT: u64 = 1_000_000_000_000_000;
 #[tokio::test]
 async fn initialize_mint() {
     let mut pt = ProgramTest::new("spl_token_2022", id(), processor!(Processor::process));
-    pt.set_compute_max_units(5_000); // last known 2196
+    pt.set_compute_max_units(5_000); // last known 1742
     let (mut banks_client, payer, recent_blockhash) = pt.start().await;
 
     let owner_key = Pubkey::new_unique();