solana-risk-engine 0.4.3 → 0.4.5

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/src/tokens.js CHANGED
@@ -34,13 +34,33 @@ export async function getMint(client, mint) {
34
34
  const r = await client.rpc("getAccountInfo", [mint, { encoding: "jsonParsed" }]);
35
35
  const p = r && r.value && r.value.data && r.value.data.parsed && r.value.data.parsed.info;
36
36
  if (!p) return null;
37
+ const exts = p.extensions || [];
38
+ const state = function (name) { const e = exts.find(function (x) { return x.extension === name; }); return (e && e.state) || {}; };
39
+ const hook = state("transferHook");
37
40
  return {
38
41
  mintAuth: p.mintAuthority || null, freezeAuth: p.freezeAuthority || null,
39
42
  supply: Number(p.supply || 0), decimals: Number(p.decimals || 0),
40
- ext: (p.extensions || []).map(function (e) { return e.extension; })
43
+ ext: exts.map(function (e) { return e.extension; }),
44
+ // what the extensions are set to: a transfer hook with no program and no authority does nothing, and
45
+ // "default account state" only matters when new accounts are born frozen
46
+ hook: { program: hook.programId || null, auth: hook.authority || null },
47
+ defaultState: state("defaultAccountState").accountState || null,
48
+ // every key that controls something in the extensions (delegate, hook, pause, metadata...)
49
+ extKeys: extKeys(exts)
41
50
  };
42
51
  }
43
52
 
53
+ function extKeys(exts) {
54
+ const out = [];
55
+ exts.forEach(function (e) {
56
+ Object.keys(e.state || {}).forEach(function (k) {
57
+ const v = e.state[k];
58
+ if (typeof v === "string" && /authority$|^delegate$|^programId$/i.test(k) && out.indexOf(v) < 0) out.push(v);
59
+ });
60
+ });
61
+ return out;
62
+ }
63
+
44
64
  // A key off the ed25519 curve has no private key: only a program can sign for it (a PDA), whoever
45
65
  // owns its account. PDAs that hold SOL (stake pool and AMM authorities) are owned by the System
46
66
  // Program like any wallet, so the owner alone would count them as people.