sememe 0.0.0-stage → 0.4.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +2777 -2
- package/bin/sememe.mjs +556 -0
- package/index.mjs +48 -0
- package/interface/ata-ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL.json +62 -0
- package/interface/native-11111111111111111111111111111111.json +226 -0
- package/interface/native-ComputeBudget111111111111111111111111111111.json +72 -0
- package/interface/raydium-675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8.json +352 -0
- package/interface/token-TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA.json +334 -0
- package/interface/token-TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb.json +535 -0
- package/interface/token-metadata.json +132 -0
- package/package.json +71 -4
- package/src/account-list.mjs +308 -0
- package/src/account-union.mjs +523 -0
- package/src/account.mjs +199 -0
- package/src/acquire.mjs +145 -0
- package/src/adopt.mjs +206 -0
- package/src/ata-interface.mjs +276 -0
- package/src/ata.mjs +223 -0
- package/src/base58.mjs +96 -0
- package/src/canonical.mjs +24 -0
- package/src/cli-surface.mjs +300 -0
- package/src/codec.mjs +1118 -0
- package/src/conformance.mjs +431 -0
- package/src/corpus/harvest-compute-budget-2026-10-31.json +19122 -0
- package/src/corpus/harvest-system-2026-10-31.json +26090 -0
- package/src/decode.mjs +286 -0
- package/src/dialect.mjs +180 -0
- package/src/discriminators.mjs +192 -0
- package/src/drift.mjs +172 -0
- package/src/gap.mjs +205 -0
- package/src/lighthouse.mjs +168 -0
- package/src/lock.mjs +440 -0
- package/src/native-audit.mjs +56 -0
- package/src/native-corpus.mjs +57 -0
- package/src/native-interface.mjs +252 -0
- package/src/native.mjs +324 -0
- package/src/peer.mjs +95 -0
- package/src/program-id.mjs +74 -0
- package/src/pull.mjs +117 -0
- package/src/rawle.mjs +454 -0
- package/src/raydium-interface.mjs +747 -0
- package/src/raydium.mjs +391 -0
- package/src/receipt-digest.mjs +84 -0
- package/src/receipt-name.mjs +128 -0
- package/src/receipt-order.mjs +56 -0
- package/src/shank.mjs +73 -0
- package/src/short-forms.mjs +209 -0
- package/src/store-read.mjs +253 -0
- package/src/store-write.mjs +46 -0
- package/src/token-interface.mjs +394 -0
- package/src/token-metadata-interface.mjs +371 -0
- package/src/token-metadata.mjs +317 -0
- package/src/token.mjs +443 -0
- package/src/union.mjs +428 -0
- package/vendor/anza-solana-sdk/8db406e2edfafa25939ec782b77b5b6f30de164d/LICENSE.txt +201 -0
- package/vendor/anza-solana-sdk/8db406e2edfafa25939ec782b77b5b6f30de164d/compute-budget-interface/src/lib.rs +93 -0
- package/vendor/anza-solana-sdk/8db406e2edfafa25939ec782b77b5b6f30de164d/system-interface/src/instruction.rs +1899 -0
- package/vendor/lighthouse/4c579479c98635e419b1b167f08be02a71604a71/LICENSE +21 -0
- package/vendor/lighthouse/4c579479c98635e419b1b167f08be02a71604a71/lighthouse.json +2769 -0
- package/vendor/raydium-amm/91739d8d9f5cf347e0ce14ebe4d2bb7069fb31b6/LICENSE +201 -0
- package/vendor/raydium-amm/91739d8d9f5cf347e0ce14ebe4d2bb7069fb31b6/program/src/instruction.rs +1189 -0
- package/vendor/raydium-amm/91739d8d9f5cf347e0ce14ebe4d2bb7069fb31b6/program/src/state.rs +1348 -0
- package/vendor/spl-associated-token-account/fbf5379e7398ac8b231c73ee8a9ff677b43dd0ec/LICENSE +201 -0
- package/vendor/spl-associated-token-account/fbf5379e7398ac8b231c73ee8a9ff677b43dd0ec/interface/src/instruction.rs +169 -0
- package/vendor/spl-associated-token-account/fbf5379e7398ac8b231c73ee8a9ff677b43dd0ec/interface/src/lib.rs +12 -0
- package/vendor/spl-associated-token-account/fbf5379e7398ac8b231c73ee8a9ff677b43dd0ec/program/src/processor.rs +308 -0
- package/vendor/spl-token/737788ff5bcc3f1f44cfb222f25483187650be76/LICENSE.txt +176 -0
- package/vendor/spl-token/737788ff5bcc3f1f44cfb222f25483187650be76/interface/src/instruction.rs +1963 -0
- package/vendor/spl-token-2022/5251dcc07ecbcb721d6c4f0231090defadf00311/LICENSE.txt +176 -0
- package/vendor/spl-token-2022/5251dcc07ecbcb721d6c4f0231090defadf00311/interface/src/instruction.rs +2868 -0
- package/vendor/spl-token-metadata-interface/7038969ec74a89f1afdb9bc97c112d4d26fead9a/LICENSE +201 -0
- package/vendor/spl-token-metadata-interface/7038969ec74a89f1afdb9bc97c112d4d26fead9a/interface/src/error.rs +58 -0
- package/vendor/spl-token-metadata-interface/7038969ec74a89f1afdb9bc97c112d4d26fead9a/interface/src/instruction.rs +596 -0
- package/vendor/spl-token-metadata-interface/7038969ec74a89f1afdb9bc97c112d4d26fead9a/interface/src/lib.rs +21 -0
- package/vendor/spl-token-metadata-interface/7038969ec74a89f1afdb9bc97c112d4d26fead9a/interface/src/state.rs +229 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
//! Token-metadata interface state types
|
|
2
|
+
|
|
3
|
+
use {
|
|
4
|
+
alloc::{
|
|
5
|
+
string::{String, ToString},
|
|
6
|
+
vec::Vec,
|
|
7
|
+
},
|
|
8
|
+
borsh::{BorshDeserialize, BorshSchema, BorshSerialize},
|
|
9
|
+
solana_address::Address,
|
|
10
|
+
solana_borsh::v1::{get_instance_packed_len, try_from_slice_unchecked},
|
|
11
|
+
solana_nullable::MaybeNull,
|
|
12
|
+
solana_program_error::ProgramError,
|
|
13
|
+
spl_discriminator::{ArrayDiscriminator, SplDiscriminate},
|
|
14
|
+
spl_type_length_value::{
|
|
15
|
+
state::{TlvState, TlvStateBorrowed},
|
|
16
|
+
variable_len_pack::VariableLenPack,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
#[cfg(feature = "serde-traits")]
|
|
21
|
+
use serde::{Deserialize, Serialize};
|
|
22
|
+
|
|
23
|
+
/// Data struct for all token-metadata, stored in a TLV entry
|
|
24
|
+
///
|
|
25
|
+
/// The type and length parts must be handled by the TLV library, and not stored
|
|
26
|
+
/// as part of this struct.
|
|
27
|
+
#[derive(Clone, Debug, Default, PartialEq, BorshDeserialize, BorshSerialize, BorshSchema)]
|
|
28
|
+
pub struct TokenMetadata {
|
|
29
|
+
/// The authority that can sign to update the metadata
|
|
30
|
+
pub update_authority: MaybeNull<Address>,
|
|
31
|
+
/// The associated mint, used to counter spoofing to be sure that metadata
|
|
32
|
+
/// belongs to a particular mint
|
|
33
|
+
pub mint: Address,
|
|
34
|
+
/// The longer name of the token
|
|
35
|
+
pub name: String,
|
|
36
|
+
/// The shortened symbol for the token
|
|
37
|
+
pub symbol: String,
|
|
38
|
+
/// The URI pointing to richer metadata
|
|
39
|
+
pub uri: String,
|
|
40
|
+
/// Any additional metadata about the token as key-value pairs. The program
|
|
41
|
+
/// must avoid storing the same key twice.
|
|
42
|
+
pub additional_metadata: Vec<(String, String)>,
|
|
43
|
+
}
|
|
44
|
+
impl SplDiscriminate for TokenMetadata {
|
|
45
|
+
/// Please use this discriminator in your program when matching
|
|
46
|
+
const SPL_DISCRIMINATOR: ArrayDiscriminator =
|
|
47
|
+
ArrayDiscriminator::new([112, 132, 90, 90, 11, 88, 157, 87]);
|
|
48
|
+
}
|
|
49
|
+
impl TokenMetadata {
|
|
50
|
+
/// Gives the total size of this struct as a TLV entry in an account
|
|
51
|
+
pub fn tlv_size_of(&self) -> Result<usize, ProgramError> {
|
|
52
|
+
TlvStateBorrowed::get_base_len()
|
|
53
|
+
.checked_add(get_instance_packed_len(self)?)
|
|
54
|
+
.ok_or(ProgramError::InvalidAccountData)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/// Updates a field in the metadata struct
|
|
58
|
+
pub fn update(&mut self, field: Field, value: String) {
|
|
59
|
+
match field {
|
|
60
|
+
Field::Name => self.name = value,
|
|
61
|
+
Field::Symbol => self.symbol = value,
|
|
62
|
+
Field::Uri => self.uri = value,
|
|
63
|
+
Field::Key(key) => self.set_key_value(key, value),
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/// Sets a key-value pair in the additional metadata
|
|
68
|
+
///
|
|
69
|
+
/// If the key is already present, overwrites the existing entry. Otherwise,
|
|
70
|
+
/// adds it to the end.
|
|
71
|
+
pub fn set_key_value(&mut self, new_key: String, new_value: String) {
|
|
72
|
+
for (key, value) in self.additional_metadata.iter_mut() {
|
|
73
|
+
if *key == new_key {
|
|
74
|
+
value.replace_range(.., &new_value);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
self.additional_metadata.push((new_key, new_value));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/// Removes the key-value pair given by the provided key. Returns true if
|
|
82
|
+
/// the key was found.
|
|
83
|
+
pub fn remove_key(&mut self, key: &str) -> bool {
|
|
84
|
+
let mut found_key = false;
|
|
85
|
+
self.additional_metadata.retain(|x| {
|
|
86
|
+
let should_retain = x.0 != key;
|
|
87
|
+
if !should_retain {
|
|
88
|
+
found_key = true;
|
|
89
|
+
}
|
|
90
|
+
should_retain
|
|
91
|
+
});
|
|
92
|
+
found_key
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/// Get the slice corresponding to the given start and end range
|
|
96
|
+
pub fn get_slice(data: &[u8], start: Option<u64>, end: Option<u64>) -> Option<&[u8]> {
|
|
97
|
+
let start = start.unwrap_or(0) as usize;
|
|
98
|
+
let end = end.map(|x| x as usize).unwrap_or(data.len());
|
|
99
|
+
data.get(start..end)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
impl VariableLenPack for TokenMetadata {
|
|
103
|
+
fn pack_into_slice(&self, dst: &mut [u8]) -> Result<(), ProgramError> {
|
|
104
|
+
borsh::to_writer(&mut dst[..], self).map_err(Into::into)
|
|
105
|
+
}
|
|
106
|
+
fn unpack_from_slice(src: &[u8]) -> Result<Self, ProgramError> {
|
|
107
|
+
try_from_slice_unchecked(src).map_err(Into::into)
|
|
108
|
+
}
|
|
109
|
+
fn get_packed_len(&self) -> Result<usize, ProgramError> {
|
|
110
|
+
get_instance_packed_len(self).map_err(Into::into)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/// Fields in the metadata account, used for updating
|
|
115
|
+
#[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))]
|
|
116
|
+
#[cfg_attr(feature = "serde-traits", serde(rename_all = "camelCase"))]
|
|
117
|
+
#[derive(Clone, Debug, PartialEq, BorshSerialize, BorshDeserialize)]
|
|
118
|
+
pub enum Field {
|
|
119
|
+
/// The name field, corresponding to `TokenMetadata.name`
|
|
120
|
+
Name,
|
|
121
|
+
/// The symbol field, corresponding to `TokenMetadata.symbol`
|
|
122
|
+
Symbol,
|
|
123
|
+
/// The uri field, corresponding to `TokenMetadata.uri`
|
|
124
|
+
Uri,
|
|
125
|
+
/// A user field, whose key is given by the associated string
|
|
126
|
+
Key(String),
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
#[cfg(test)]
|
|
130
|
+
mod tests {
|
|
131
|
+
use {
|
|
132
|
+
super::*,
|
|
133
|
+
crate::NAMESPACE,
|
|
134
|
+
alloc::{format, string::ToString},
|
|
135
|
+
solana_sha256_hasher::hashv,
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
#[test]
|
|
139
|
+
fn discriminator() {
|
|
140
|
+
let preimage = hashv(&[format!("{NAMESPACE}:token_metadata").as_bytes()]);
|
|
141
|
+
let discriminator =
|
|
142
|
+
ArrayDiscriminator::try_from(&preimage.as_ref()[..ArrayDiscriminator::LENGTH]).unwrap();
|
|
143
|
+
assert_eq!(TokenMetadata::SPL_DISCRIMINATOR, discriminator);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
#[test]
|
|
147
|
+
fn update() {
|
|
148
|
+
let name = "name".to_string();
|
|
149
|
+
let symbol = "symbol".to_string();
|
|
150
|
+
let uri = "uri".to_string();
|
|
151
|
+
let mut token_metadata = TokenMetadata {
|
|
152
|
+
name,
|
|
153
|
+
symbol,
|
|
154
|
+
uri,
|
|
155
|
+
..Default::default()
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// updating base fields
|
|
159
|
+
let new_name = "new_name".to_string();
|
|
160
|
+
token_metadata.update(Field::Name, new_name.clone());
|
|
161
|
+
assert_eq!(token_metadata.name, new_name);
|
|
162
|
+
|
|
163
|
+
let new_symbol = "new_symbol".to_string();
|
|
164
|
+
token_metadata.update(Field::Symbol, new_symbol.clone());
|
|
165
|
+
assert_eq!(token_metadata.symbol, new_symbol);
|
|
166
|
+
|
|
167
|
+
let new_uri = "new_uri".to_string();
|
|
168
|
+
token_metadata.update(Field::Uri, new_uri.clone());
|
|
169
|
+
assert_eq!(token_metadata.uri, new_uri);
|
|
170
|
+
|
|
171
|
+
// add new key-value pairs
|
|
172
|
+
let key1 = "key1".to_string();
|
|
173
|
+
let value1 = "value1".to_string();
|
|
174
|
+
token_metadata.update(Field::Key(key1.clone()), value1.clone());
|
|
175
|
+
assert_eq!(token_metadata.additional_metadata.len(), 1);
|
|
176
|
+
assert_eq!(
|
|
177
|
+
token_metadata.additional_metadata[0],
|
|
178
|
+
(key1.clone(), value1.clone())
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
let key2 = "key2".to_string();
|
|
182
|
+
let value2 = "value2".to_string();
|
|
183
|
+
token_metadata.update(Field::Key(key2.clone()), value2.clone());
|
|
184
|
+
assert_eq!(token_metadata.additional_metadata.len(), 2);
|
|
185
|
+
assert_eq!(
|
|
186
|
+
token_metadata.additional_metadata[0],
|
|
187
|
+
(key1.clone(), value1)
|
|
188
|
+
);
|
|
189
|
+
assert_eq!(
|
|
190
|
+
token_metadata.additional_metadata[1],
|
|
191
|
+
(key2.clone(), value2.clone())
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
// update first key, see that order is preserved
|
|
195
|
+
let new_value1 = "new_value1".to_string();
|
|
196
|
+
token_metadata.update(Field::Key(key1.clone()), new_value1.clone());
|
|
197
|
+
assert_eq!(token_metadata.additional_metadata.len(), 2);
|
|
198
|
+
assert_eq!(token_metadata.additional_metadata[0], (key1, new_value1));
|
|
199
|
+
assert_eq!(token_metadata.additional_metadata[1], (key2, value2));
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
#[test]
|
|
203
|
+
fn remove_key() {
|
|
204
|
+
let name = "name".to_string();
|
|
205
|
+
let symbol = "symbol".to_string();
|
|
206
|
+
let uri = "uri".to_string();
|
|
207
|
+
let mut token_metadata = TokenMetadata {
|
|
208
|
+
name,
|
|
209
|
+
symbol,
|
|
210
|
+
uri,
|
|
211
|
+
..Default::default()
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// add new key-value pair
|
|
215
|
+
let key = "key".to_string();
|
|
216
|
+
let value = "value".to_string();
|
|
217
|
+
token_metadata.update(Field::Key(key.clone()), value.clone());
|
|
218
|
+
assert_eq!(token_metadata.additional_metadata.len(), 1);
|
|
219
|
+
assert_eq!(token_metadata.additional_metadata[0], (key.clone(), value));
|
|
220
|
+
|
|
221
|
+
// remove it
|
|
222
|
+
assert!(token_metadata.remove_key(&key));
|
|
223
|
+
assert_eq!(token_metadata.additional_metadata.len(), 0);
|
|
224
|
+
|
|
225
|
+
// remove it again, returns false
|
|
226
|
+
assert!(!token_metadata.remove_key(&key));
|
|
227
|
+
assert_eq!(token_metadata.additional_metadata.len(), 0);
|
|
228
|
+
}
|
|
229
|
+
}
|