@exodus/solana-lib 1.2.9-build → 1.2.9-build2

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/lib/index.js CHANGED
@@ -4,9 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  var _exportNames = {
7
+ StakeInstruction: true,
7
8
  tokens: true,
8
9
  Transaction: true
9
10
  };
11
+ Object.defineProperty(exports, "StakeInstruction", {
12
+ enumerable: true,
13
+ get: function () {
14
+ return _vendor.StakeInstruction;
15
+ }
16
+ });
10
17
  Object.defineProperty(exports, "tokens", {
11
18
  enumerable: true,
12
19
  get: function () {
@@ -72,6 +79,8 @@ Object.keys(_tx).forEach(function (key) {
72
79
  });
73
80
  });
74
81
 
82
+ var _vendor = require("./vendor");
83
+
75
84
  var _tokens = _interopRequireDefault(require("./tokens"));
76
85
 
77
86
  var _transaction = _interopRequireDefault(require("./transaction"));
@@ -7,6 +7,10 @@ exports.default = void 0;
7
7
 
8
8
  var _assert = _interopRequireDefault(require("assert"));
9
9
 
10
+ var _bs = _interopRequireDefault(require("bs58"));
11
+
12
+ var _lodash = require("lodash");
13
+
10
14
  var _keypair = require("./keypair");
11
15
 
12
16
  var _encode = require("./encode");
@@ -19,8 +23,6 @@ var _constants = require("./constants");
19
23
 
20
24
  var _tokens = _interopRequireDefault(require("./tokens"));
21
25
 
22
- var _bs = _interopRequireDefault(require("bs58"));
23
-
24
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
27
 
26
28
  class Tx {
@@ -254,6 +256,63 @@ class Tx {
254
256
  return transaction.serialize().toString('base64');
255
257
  }
256
258
 
259
+ static decodeStakingTx(serialized) {
260
+ // as base64
261
+ const wireTransaction = Buffer.from(serialized, 'base64');
262
+
263
+ const tx = _vendor.Transaction.from(wireTransaction); // Transaction instance
264
+
265
+
266
+ const txId = _bs.default.encode(tx.signature);
267
+
268
+ const stakingInstructions = tx.instructions.filter(ix => ix.programId.toString() === _constants.STAKE_PROGRAM_ID.toString());
269
+ const isStakingTx = !!stakingInstructions.length;
270
+ if (!isStakingTx) return null; // normal transfer tx
271
+
272
+ const info = {
273
+ txId,
274
+ owner: tx.feePayer.toString() // SOL sender
275
+
276
+ };
277
+ const txDetails = stakingInstructions.reduce((info, ix) => {
278
+ const type = _vendor.StakeInstruction.decodeInstructionType(ix);
279
+
280
+ switch (type) {
281
+ case 'Delegate':
282
+ info.type = 'Delegate';
283
+ info.stakeAddress = (0, _lodash.get)(ix, 'keys[0].pubkey', '').toString();
284
+ info.validator = (0, _lodash.get)(ix, 'keys[1].pubkey', '').toString(); // pool
285
+
286
+ return info;
287
+
288
+ case 'Deactivate':
289
+ // undelegate
290
+ info.type = 'Deactivate';
291
+ info.stakeAddress = (0, _lodash.get)(ix, 'keys[0].pubkey', '').toString(); // TODO: could have multiple addresses undelegating
292
+
293
+ return info;
294
+
295
+ case 'Withdraw':
296
+ info.type = 'Withdraw';
297
+ info.stakeAddress = (0, _lodash.get)(ix, 'keys[0].pubkey', '').toString();
298
+
299
+ const {
300
+ lamports,
301
+ toPubkey
302
+ } = _vendor.StakeInstruction.decodeWithdraw(ix);
303
+
304
+ info.to = toPubkey.toString();
305
+ info.lamports = lamports.toString();
306
+ return info;
307
+
308
+ default:
309
+ // skip unknown instruction type
310
+ return info;
311
+ }
312
+ }, info);
313
+ return txDetails;
314
+ }
315
+
257
316
  getTxId() {
258
317
  if (!this.transaction.signature) {
259
318
  throw new Error('Cannot get txId, tx is not signed');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/solana-lib",
3
- "version": "1.2.9-build",
3
+ "version": "1.2.9-build2",
4
4
  "description": "Exodus internal Solana low-level library",
5
5
  "main": "lib/index.js",
6
6
  "files": [