@hawksightco/hawk-sdk 1.1.6 → 1.1.8

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.
@@ -7,6 +7,8 @@ import { Client } from "./Client";
7
7
  import { GeneralUtility } from "./GeneralUtility";
8
8
  import { Search } from "./Search";
9
9
  import { HawkApiOptions } from "../types";
10
+ import { SimpleIxGenerator } from "./SimpleIxGenerator";
11
+ import { TransactionBatchExecute, TransactionBatchExecuteParams } from "./TransactionBatchExecute";
10
12
  /**
11
13
  * HawkAPI is a central gateway class that aggregates access to various functional modules
12
14
  * for interacting with HawkSight's blockchain APIs. This class initializes and exposes modules
@@ -36,6 +38,8 @@ export declare class HawkAPI {
36
38
  readonly txGeneratorAutomation: TxGeneratorAutomations;
37
39
  /** Search module (token search only for now...) */
38
40
  readonly search: Search;
41
+ /** Simple instruction generator */
42
+ readonly simpleIxGenerator: SimpleIxGenerator;
39
43
  /**
40
44
  * Initializes a new instance of the HawkAPI class with a specified API URL.
41
45
  * @param url The base URL for the HawkSight API services, defaulted to "https://api2.hawksight.co" if not specified.
@@ -47,5 +51,11 @@ export declare class HawkAPI {
47
51
  * @param txGenerator
48
52
  */
49
53
  overrideTxGenerator(builderFn: (client: Client, generalUtility: GeneralUtility) => TxGenerator): void;
54
+ /**
55
+ * Create instance of TransactionBatchExecute
56
+ *
57
+ * @param param
58
+ */
59
+ batchExecute({ lookupTableAddresses, instructions, payer, connection, signers }: TransactionBatchExecuteParams): TransactionBatchExecute;
50
60
  }
51
61
  //# sourceMappingURL=HawkAPI.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"HawkAPI.d.ts","sourceRoot":"","sources":["../../../src/classes/HawkAPI.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5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G;IACH,mBAAmB,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,cAAc,KAAK,WAAW;IAI9F;;;;OAIG;IACH,YAAY,CAAC,EAAC,oBAAoB,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAC,EAAE,6BAA6B;CAS7G"}
@@ -10,6 +10,8 @@ const Client_1 = require("./Client");
10
10
  const GeneralUtility_1 = require("./GeneralUtility");
11
11
  const Search_1 = require("./Search");
12
12
  const CreateTxMetadata_1 = require("./CreateTxMetadata");
13
+ const SimpleIxGenerator_1 = require("./SimpleIxGenerator");
14
+ const TransactionBatchExecute_1 = require("./TransactionBatchExecute");
13
15
  /**
14
16
  * HawkAPI is a central gateway class that aggregates access to various functional modules
15
17
  * for interacting with HawkSight's blockchain APIs. This class initializes and exposes modules
@@ -37,6 +39,7 @@ class HawkAPI {
37
39
  this._txGenerator = new TxGenerator_1.TxGenerator(client, this.generalUtility);
38
40
  this.txGeneratorAutomation = new TxGeneratorAutomations_1.TxGeneratorAutomations(client, this.generalUtility);
39
41
  this.search = new Search_1.Search(url);
42
+ this.simpleIxGenerator = new SimpleIxGenerator_1.SimpleIxGenerator(this.generalUtility);
40
43
  // Load create tx metadata module
41
44
  if (this.options === undefined || !this.options.disableTxMetadataLoad) {
42
45
  CreateTxMetadata_1.CreateTxMetadata.instance().load();
@@ -54,5 +57,13 @@ class HawkAPI {
54
57
  overrideTxGenerator(builderFn) {
55
58
  this._txGenerator = builderFn(this.client, this.generalUtility);
56
59
  }
60
+ /**
61
+ * Create instance of TransactionBatchExecute
62
+ *
63
+ * @param param
64
+ */
65
+ batchExecute({ lookupTableAddresses, instructions, payer, connection, signers }) {
66
+ return new TransactionBatchExecute_1.TransactionBatchExecute(lookupTableAddresses, instructions, payer, connection, signers);
67
+ }
57
68
  }
58
69
  exports.HawkAPI = HawkAPI;
@@ -0,0 +1,38 @@
1
+ /// <reference types="@meteora-ag/dlmm/node_modules/@solana/web3.js" />
2
+ import * as web3 from "@solana/web3.js";
3
+ import { GeneralUtility } from "./GeneralUtility";
4
+ import { AtomicityContextParams } from "../hawksight";
5
+ /**
6
+ * The SimpleIxGenerator class is a general-purpose utility for generating single
7
+ * transaction instructions for simple tasks on the Solana blockchain. It offers
8
+ * methods to set and verify transaction slots within an atomicity context, specifically
9
+ * interacting with the user's PDA (Program Derived Address) account.
10
+ */
11
+ export declare class SimpleIxGenerator {
12
+ protected readonly generalUtility: GeneralUtility;
13
+ /**
14
+ * Initializes an instance of the SimpleIxGenerator class.
15
+ *
16
+ * @param generalUtility - An instance of GeneralUtility that provides general utility functions.
17
+ */
18
+ constructor(generalUtility: GeneralUtility);
19
+ /**
20
+ * Generates a transaction instruction that sets the current blockchain clock
21
+ * to the user's PDA (Program Derived Address) account.
22
+ *
23
+ * @param connection - A Solana web3.js Connection object for interacting with the blockchain.
24
+ * @param params - AtomicityContextParams containing the context and parameters for setting the transaction slot.
25
+ * @returns A Promise that resolves to a TransactionInstruction object for setting the current clock in the PDA.
26
+ */
27
+ setTransactionSlot(connection: web3.Connection, params: AtomicityContextParams): Promise<web3.TransactionInstruction>;
28
+ /**
29
+ * Generates a transaction instruction that verifies whether the current blockchain
30
+ * clock matches the value that has been previously set in the user's PDA (Program Derived Address) account.
31
+ *
32
+ * @param connection - A Solana web3.js Connection object for interacting with the blockchain.
33
+ * @param params - AtomicityContextParams containing the context and parameters for verifying the transaction slot.
34
+ * @returns A Promise that resolves to a TransactionInstruction object for verifying the clock in the PDA.
35
+ */
36
+ verifyTransactionSlot(connection: web3.Connection, params: AtomicityContextParams): Promise<web3.TransactionInstruction>;
37
+ }
38
+ //# sourceMappingURL=SimpleIxGenerator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SimpleIxGenerator.d.ts","sourceRoot":"","sources":["../../../src/classes/SimpleIxGenerator.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAA6C,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEjG;;;;;GAKG;AACH,qBAAa,iBAAiB;IAQ1B,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,cAAc;IANnD;;;;OAIG;gBAEkB,cAAc,EAAE,cAAc;IAGnD;;;;;;;OAOG;IACG,kBAAkB,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,sBAAsB,CAAC;IAQ3H;;;;;;;OAOG;IACG,qBAAqB,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,sBAAsB,CAAC;CAO/H"}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SimpleIxGenerator = void 0;
13
+ const anchor_1 = require("../anchor");
14
+ const hawksight_1 = require("../hawksight");
15
+ /**
16
+ * The SimpleIxGenerator class is a general-purpose utility for generating single
17
+ * transaction instructions for simple tasks on the Solana blockchain. It offers
18
+ * methods to set and verify transaction slots within an atomicity context, specifically
19
+ * interacting with the user's PDA (Program Derived Address) account.
20
+ */
21
+ class SimpleIxGenerator {
22
+ /**
23
+ * Initializes an instance of the SimpleIxGenerator class.
24
+ *
25
+ * @param generalUtility - An instance of GeneralUtility that provides general utility functions.
26
+ */
27
+ constructor(generalUtility) {
28
+ this.generalUtility = generalUtility;
29
+ }
30
+ /**
31
+ * Generates a transaction instruction that sets the current blockchain clock
32
+ * to the user's PDA (Program Derived Address) account.
33
+ *
34
+ * @param connection - A Solana web3.js Connection object for interacting with the blockchain.
35
+ * @param params - AtomicityContextParams containing the context and parameters for setting the transaction slot.
36
+ * @returns A Promise that resolves to a TransactionInstruction object for setting the current clock in the PDA.
37
+ */
38
+ setTransactionSlot(connection, params) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ // Initialize anchor
41
+ anchor_1.Anchor.initialize(connection);
42
+ // Get set transaction slot instruction
43
+ return yield (0, hawksight_1.setTransactionSlot)(params);
44
+ });
45
+ }
46
+ /**
47
+ * Generates a transaction instruction that verifies whether the current blockchain
48
+ * clock matches the value that has been previously set in the user's PDA (Program Derived Address) account.
49
+ *
50
+ * @param connection - A Solana web3.js Connection object for interacting with the blockchain.
51
+ * @param params - AtomicityContextParams containing the context and parameters for verifying the transaction slot.
52
+ * @returns A Promise that resolves to a TransactionInstruction object for verifying the clock in the PDA.
53
+ */
54
+ verifyTransactionSlot(connection, params) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ // Initialize anchor
57
+ anchor_1.Anchor.initialize(connection);
58
+ // Get verify transaction slot instruction
59
+ return yield (0, hawksight_1.verifyTransactionSlot)(params);
60
+ });
61
+ }
62
+ }
63
+ exports.SimpleIxGenerator = SimpleIxGenerator;
@@ -0,0 +1,113 @@
1
+ /// <reference types="@meteora-ag/dlmm/node_modules/@solana/web3.js" />
2
+ import * as web3 from '@solana/web3.js';
3
+ /**
4
+ * Dummy signers
5
+ */
6
+ export type DummySigners = Record<string, web3.Keypair>;
7
+ /**
8
+ * Transaction batch
9
+ */
10
+ export type Batch = {
11
+ addressLookupTables: web3.PublicKey[];
12
+ instructions: web3.PublicKey[];
13
+ signers: web3.Keypair;
14
+ };
15
+ export type TransactionBatchExecuteParams = {
16
+ lookupTableAddresses: web3.PublicKey[];
17
+ instructions: web3.TransactionInstruction[];
18
+ payer: web3.Keypair;
19
+ connection: web3.Connection;
20
+ signers: web3.Keypair[];
21
+ };
22
+ /**
23
+ * Executes transactions in batches
24
+ */
25
+ export declare class TransactionBatchExecute {
26
+ private lookupTableAddresses;
27
+ private instructions;
28
+ private payer;
29
+ private connection;
30
+ private signers;
31
+ private readonly MAX_SIZE;
32
+ /**
33
+ * Downloaded address lookup table accounts
34
+ */
35
+ private alts;
36
+ /**
37
+ * Creates an instance of TransactionExecute class
38
+ *
39
+ * @param lookupTableAddresses Address lookup table addresses to be used by batch of transactions
40
+ * @param instructions Array of instructions to be batched into transactions
41
+ * @param payer Payer that will pay for the batch of transactions
42
+ * @param connection Connection to mainnet
43
+ * @param signers Required signers to fulfill the transactions
44
+ */
45
+ constructor(lookupTableAddresses: web3.PublicKey[], instructions: web3.TransactionInstruction[], payer: web3.Keypair, connection: web3.Connection, signers?: web3.Keypair[]);
46
+ /**
47
+ * Downoad address lookup table from given cluster
48
+ */
49
+ downloadAlts(): Promise<void>;
50
+ /**
51
+ * Override signers (in case that signers are set to empty array)
52
+ *
53
+ * @param signers
54
+ */
55
+ setSigners(signers: web3.Keypair[]): void;
56
+ /**
57
+ * Find missing signers
58
+ */
59
+ findMissingSigners(): web3.PublicKey[];
60
+ /**
61
+ * Returns list of public keys that are required to sign the batch of transaction
62
+ */
63
+ findRequiredSigningPubkeys(): web3.PublicKey[];
64
+ /**
65
+ * Generate dummy signers needed for simulation
66
+ *
67
+ * @returns
68
+ */
69
+ generateDummySigners(): DummySigners;
70
+ /**
71
+ * Generate instruction that has modified signers for simulation purposes
72
+ */
73
+ generateSimulationIxs(): [web3.TransactionInstruction[], DummySigners];
74
+ /**
75
+ * Builds a batch of executable transaction instructions
76
+ */
77
+ buildBatch(): Promise<web3.TransactionInstruction[][]>;
78
+ /**
79
+ * Split transactions
80
+ *
81
+ * @param simulationIxs
82
+ * @param dummySigners
83
+ * @returns
84
+ */
85
+ private splitToTransactions;
86
+ /**
87
+ * Calculate transaction size
88
+ *
89
+ * @param batch
90
+ */
91
+ private calculateTransactionSize;
92
+ /**
93
+ * Find required signers from batch
94
+ *
95
+ * @param ixs
96
+ * @param dummySigners
97
+ */
98
+ private findRequiredSignersFromBatch;
99
+ /**
100
+ * Find required signers from instructions
101
+ *
102
+ * @param ixs
103
+ * @param dummySigners
104
+ */
105
+ private findRequiredSignersFromIxs;
106
+ /**
107
+ * Find required address lookup table addresses for given batch of instructions
108
+ *
109
+ * @param batch
110
+ */
111
+ private findRequiredAltsForBatch;
112
+ }
113
+ //# sourceMappingURL=TransactionBatchExecute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransactionBatchExecute.d.ts","sourceRoot":"","sources":["../../../src/classes/TransactionBatchExecute.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AAExC;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;AAExD;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG;IAClB,mBAAmB,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;IACtC,YAAY,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;IAC/B,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC;CACvB,CAAA;AAED,MAAM,MAAM,6BAA6B,GAAG;IAC1C,oBAAoB,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;IACvC,YAAY,EAAE,IAAI,CAAC,sBAAsB,EAAE,CAAC;IAC5C,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC;IACpB,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC;IAC5B,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;CACzB,CAAA;AAED;;GAEG;AACH,qBAAa,uBAAuB;IAmBhC,OAAO,CAAC,oBAAoB;IAC5B,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,OAAO;IArBjB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;IAEjC;;OAEG;IACH,OAAO,CAAC,IAAI,CAAwC;IAEpD;;;;;;;;OAQG;gBAEO,oBAAoB,EAAE,IAAI,CAAC,SAAS,EAAE,EACtC,YAAY,EAAE,IAAI,CAAC,sBAAsB,EAAE,EAC3C,KAAK,EAAE,IAAI,CAAC,OAAO,EACnB,UAAU,EAAE,IAAI,CAAC,UAAU,EAC3B,OAAO,GAAE,IAAI,CAAC,OAAO,EAAO;IAGtC;;OAEG;IACG,YAAY;IAclB;;;;OAIG;IACH,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;IAIlC;;OAEG;IACH,kBAAkB,IAAI,IAAI,CAAC,SAAS,EAAE;IActC;;OAEG;IACH,0BAA0B,IAAI,IAAI,CAAC,SAAS,EAAE;IAI9C;;;;OAIG;IACH,oBAAoB,IAAI,YAAY;IASpC;;OAEG;IACH,qBAAqB,IAAI,CAAC,IAAI,CAAC,sBAAsB,EAAE,EAAE,YAAY,CAAC;IAiBtE;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,sBAAsB,EAAE,EAAE,CAAC;IAwB5D;;;;;;OAMG;YACW,mBAAmB;IA8BjC;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IAchC;;;;;OAKG;IACH,OAAO,CAAC,4BAA4B;IAapC;;;;;OAKG;IACH,OAAO,CAAC,0BAA0B;IAqBlC;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;CA2BjC"}
@@ -0,0 +1,294 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.TransactionBatchExecute = void 0;
36
+ const web3 = __importStar(require("@solana/web3.js"));
37
+ /**
38
+ * Executes transactions in batches
39
+ */
40
+ class TransactionBatchExecute {
41
+ /**
42
+ * Creates an instance of TransactionExecute class
43
+ *
44
+ * @param lookupTableAddresses Address lookup table addresses to be used by batch of transactions
45
+ * @param instructions Array of instructions to be batched into transactions
46
+ * @param payer Payer that will pay for the batch of transactions
47
+ * @param connection Connection to mainnet
48
+ * @param signers Required signers to fulfill the transactions
49
+ */
50
+ constructor(lookupTableAddresses, instructions, payer, connection, signers = []) {
51
+ this.lookupTableAddresses = lookupTableAddresses;
52
+ this.instructions = instructions;
53
+ this.payer = payer;
54
+ this.connection = connection;
55
+ this.signers = signers;
56
+ this.MAX_SIZE = 1232;
57
+ /**
58
+ * Downloaded address lookup table accounts
59
+ */
60
+ this.alts = [];
61
+ }
62
+ ;
63
+ /**
64
+ * Downoad address lookup table from given cluster
65
+ */
66
+ downloadAlts() {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ // Skip if we already downloaded alts from the cluster
69
+ if (this.alts.length > 0 && this.alts.length === this.lookupTableAddresses.length)
70
+ return;
71
+ // Download if address lookup table does not match with downloaded alts
72
+ for (const lookupTable of this.lookupTableAddresses) {
73
+ const alt = yield this.connection.getAddressLookupTable(lookupTable);
74
+ if (alt.value === null) {
75
+ throw new Error(`Address lookup table: ${lookupTable} does not exist on the blockchain.`);
76
+ }
77
+ this.alts.push(alt.value);
78
+ }
79
+ });
80
+ }
81
+ /**
82
+ * Override signers (in case that signers are set to empty array)
83
+ *
84
+ * @param signers
85
+ */
86
+ setSigners(signers) {
87
+ this.signers = signers;
88
+ }
89
+ /**
90
+ * Find missing signers
91
+ */
92
+ findMissingSigners() {
93
+ const requiredSigners = this.findRequiredSigningPubkeys();
94
+ if (requiredSigners.length > this.signers.length) {
95
+ return requiredSigners;
96
+ }
97
+ const missingSigners = [];
98
+ for (const requiredSigner of requiredSigners) {
99
+ const match = this.signers.find(v => v.publicKey.toBase58() === requiredSigner.toBase58());
100
+ if (!!match)
101
+ continue;
102
+ missingSigners.push(requiredSigner);
103
+ }
104
+ return missingSigners;
105
+ }
106
+ /**
107
+ * Returns list of public keys that are required to sign the batch of transaction
108
+ */
109
+ findRequiredSigningPubkeys() {
110
+ return this.findRequiredSignersFromIxs(this.instructions);
111
+ }
112
+ /**
113
+ * Generate dummy signers needed for simulation
114
+ *
115
+ * @returns
116
+ */
117
+ generateDummySigners() {
118
+ const requiredSigners = this.findRequiredSigningPubkeys();
119
+ const dummySigners = {};
120
+ for (const signer of requiredSigners) {
121
+ dummySigners[signer.toString()] = web3.Keypair.generate();
122
+ }
123
+ return dummySigners;
124
+ }
125
+ /**
126
+ * Generate instruction that has modified signers for simulation purposes
127
+ */
128
+ generateSimulationIxs() {
129
+ const dummySigners = this.generateDummySigners();
130
+ let simulationIxs = this.instructions;
131
+ for (const pubkey in dummySigners) {
132
+ simulationIxs = simulationIxs.map(ix => {
133
+ const keys = ix.keys.map(meta => {
134
+ if (meta.pubkey.toString() === pubkey && meta.isSigner) {
135
+ return Object.assign(Object.assign({}, meta), { pubkey: dummySigners[pubkey].publicKey });
136
+ }
137
+ return meta;
138
+ });
139
+ return Object.assign(Object.assign({}, ix), { keys });
140
+ });
141
+ }
142
+ return [simulationIxs, dummySigners];
143
+ }
144
+ /**
145
+ * Builds a batch of executable transaction instructions
146
+ */
147
+ buildBatch() {
148
+ return __awaiter(this, void 0, void 0, function* () {
149
+ // Download address lookup table from given cluster
150
+ yield this.downloadAlts();
151
+ // Generate dummy instructions for batch calculation
152
+ const [simulationIxs, dummySigners] = this.generateSimulationIxs();
153
+ // Split simulation ixs
154
+ const dummyBatches = yield this.splitToTransactions(simulationIxs, dummySigners);
155
+ // Batch of actual instructions
156
+ const batch = [];
157
+ let index = 0;
158
+ for (const dummyIxs of dummyBatches) {
159
+ const currentBatch = [];
160
+ for (const dummyIx of dummyIxs) {
161
+ currentBatch.push(this.instructions[index++]);
162
+ }
163
+ batch.push(currentBatch);
164
+ }
165
+ return batch;
166
+ });
167
+ }
168
+ /**
169
+ * Split transactions
170
+ *
171
+ * @param simulationIxs
172
+ * @param dummySigners
173
+ * @returns
174
+ */
175
+ splitToTransactions(simulationIxs, dummySigners) {
176
+ return __awaiter(this, void 0, void 0, function* () {
177
+ // Fetch latest blockhash required to calculate transaction size
178
+ const latestBlockhash = yield this.connection.getLatestBlockhash();
179
+ // Run simulation
180
+ let batch = [];
181
+ let result = [];
182
+ for (const ix of simulationIxs) {
183
+ // Include dummy ix to transaction
184
+ batch.push(ix);
185
+ // Calculate transaction size
186
+ const txSize = this.calculateTransactionSize(latestBlockhash, batch, dummySigners);
187
+ if (txSize > this.MAX_SIZE) {
188
+ batch.pop();
189
+ result.push(batch);
190
+ batch = [ix];
191
+ }
192
+ }
193
+ if (batch.length > 0) {
194
+ result.push(batch);
195
+ }
196
+ return result;
197
+ });
198
+ }
199
+ /**
200
+ * Calculate transaction size
201
+ *
202
+ * @param batch
203
+ */
204
+ calculateTransactionSize(latestBlockhash, batch, dummySigners) {
205
+ const alts = this.findRequiredAltsForBatch(batch);
206
+ const messageV0 = new web3.TransactionMessage({
207
+ payerKey: this.payer.publicKey,
208
+ instructions: batch,
209
+ recentBlockhash: latestBlockhash.blockhash,
210
+ }).compileToV0Message(alts);
211
+ const versionedTx = new web3.VersionedTransaction(messageV0);
212
+ const signers = this.findRequiredSignersFromBatch(batch, dummySigners);
213
+ versionedTx.sign(signers);
214
+ const bytes = versionedTx.serialize();
215
+ return bytes.length;
216
+ }
217
+ /**
218
+ * Find required signers from batch
219
+ *
220
+ * @param ixs
221
+ * @param dummySigners
222
+ */
223
+ findRequiredSignersFromBatch(batch, dummySigners) {
224
+ const signers = this.findRequiredSignersFromIxs(batch);
225
+ const result = [];
226
+ for (const key in dummySigners) {
227
+ const dummySigner = signers.find(signer => signer.toBase58() === dummySigners[key].publicKey.toBase58());
228
+ if (dummySigner === undefined) {
229
+ throw new Error('Unexpected error: Dummy signer not found (it should never happen)');
230
+ }
231
+ result.push(dummySigners[key]);
232
+ }
233
+ return result;
234
+ }
235
+ /**
236
+ * Find required signers from instructions
237
+ *
238
+ * @param ixs
239
+ * @param dummySigners
240
+ */
241
+ findRequiredSignersFromIxs(ixs) {
242
+ const signers = [];
243
+ for (const instruction of ixs) {
244
+ const _signers = instruction.keys
245
+ .filter(meta => meta.isSigner)
246
+ .map(meta => meta.pubkey);
247
+ if (_signers.length > 0) {
248
+ signers.push(..._signers);
249
+ }
250
+ }
251
+ const uniqueSigners = {};
252
+ for (const signer of signers) {
253
+ uniqueSigners[signer.toBase58()] = signer;
254
+ }
255
+ const result = [];
256
+ for (const id in uniqueSigners) {
257
+ result.push(uniqueSigners[id]);
258
+ }
259
+ return result;
260
+ }
261
+ /**
262
+ * Find required address lookup table addresses for given batch of instructions
263
+ *
264
+ * @param batch
265
+ */
266
+ findRequiredAltsForBatch(batch) {
267
+ const uniquePubkeys = {};
268
+ batch.map(ix => {
269
+ const pubkeys = ix.keys.map(meta => meta.pubkey);
270
+ for (const pubkey of pubkeys) {
271
+ uniquePubkeys[pubkey.toBase58()] = 1;
272
+ }
273
+ });
274
+ const pubkeys = [];
275
+ for (const pubkey in uniquePubkeys) {
276
+ pubkeys.push(new web3.PublicKey(pubkey));
277
+ }
278
+ const alts = {};
279
+ for (const alt of this.alts) {
280
+ for (const pubkey of pubkeys) {
281
+ const match = alt.state.addresses.find(address => pubkey.toBase58() === address.toBase58());
282
+ if (!!match) {
283
+ alts[alt.key.toString()] = alt;
284
+ }
285
+ }
286
+ }
287
+ const result = [];
288
+ for (const key in alts) {
289
+ result.push(alts[key]);
290
+ }
291
+ return result;
292
+ }
293
+ }
294
+ exports.TransactionBatchExecute = TransactionBatchExecute;
@@ -480,7 +480,7 @@ class Transactions {
480
480
  if (!accountsData[i]) {
481
481
  console.log(`initializing STA: ${filteredMints[i].toBase58()}`);
482
482
  mainInstructions.push(yield anchor_1.Anchor.instance().iyfMain.methods
483
- .initializeStorageTokenAccountAutomation()
483
+ .initializeStorageTokenAccount()
484
484
  .accounts({
485
485
  userPda: userPda,
486
486
  payer: params.userWallet,
@@ -14,4 +14,12 @@ export declare function withdrawMultipleToken(params: {
14
14
  mint: web3.PublicKey;
15
15
  }[];
16
16
  }): Promise<web3.TransactionInstruction>;
17
+ export type AtomicityContextParams = {
18
+ userWallet: web3.PublicKey;
19
+ };
20
+ export declare function setTransactionSlot({ userWallet }: AtomicityContextParams): Promise<web3.TransactionInstruction>;
21
+ export type VerifyTransactionSlotParams = {
22
+ userWallet: web3.PublicKey;
23
+ };
24
+ export declare function verifyTransactionSlot({ userWallet }: AtomicityContextParams): Promise<web3.TransactionInstruction>;
17
25
  //# sourceMappingURL=hawksight.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hawksight.d.ts","sourceRoot":"","sources":["../../src/hawksight.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,MAAM,OAAO,CAAC;AAUvB,wBAAsB,oBAAoB,CAAC,MAAM,EAAE;IACjD,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC;IACtB,OAAO,EAAE;QACP,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;QACrB,MAAM,EAAE,EAAE,CAAC;KACZ,EAAE,CAAC;CACL,wCAyCA;AAED,wBAAsB,qBAAqB,CAAC,MAAM,EAAE;IAClD,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC;IACtB,QAAQ,EAAE;QACR,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;KACtB,EAAE,CAAC;CACL,wCAwCA"}
1
+ {"version":3,"file":"hawksight.d.ts","sourceRoot":"","sources":["../../src/hawksight.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,MAAM,OAAO,CAAC;AAUvB,wBAAsB,oBAAoB,CAAC,MAAM,EAAE;IACjD,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC;IACtB,OAAO,EAAE;QACP,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;QACrB,MAAM,EAAE,EAAE,CAAC;KACZ,EAAE,CAAC;CACL,wCAyCA;AAED,wBAAsB,qBAAqB,CAAC,MAAM,EAAE;IAClD,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC;IACtB,QAAQ,EAAE;QACR,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;KACtB,EAAE,CAAC;CACL,wCAwCA;AAED,MAAM,MAAM,sBAAsB,GAAG;IACnC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC;CAC5B,CAAC;AACF,wBAAsB,kBAAkB,CAAC,EAAE,UAAU,EAAE,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAUrH;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC;CAC5B,CAAC;AACF,wBAAsB,qBAAqB,CAAC,EAAE,UAAU,EAAE,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAUxH"}
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
32
  });
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.withdrawMultipleToken = exports.depositMultipleToken = void 0;
35
+ exports.verifyTransactionSlot = exports.setTransactionSlot = exports.withdrawMultipleToken = exports.depositMultipleToken = void 0;
36
36
  const web3 = __importStar(require("@solana/web3.js"));
37
37
  const anchor_1 = require("./anchor");
38
38
  const addresses_1 = require("./addresses");
@@ -126,3 +126,31 @@ function withdrawMultipleToken(params) {
126
126
  });
127
127
  }
128
128
  exports.withdrawMultipleToken = withdrawMultipleToken;
129
+ function setTransactionSlot(_a) {
130
+ return __awaiter(this, arguments, void 0, function* ({ userWallet }) {
131
+ const ix = yield anchor_1.Anchor
132
+ .instance().iyfMain.methods
133
+ .setTransactionSlot()
134
+ .accounts({
135
+ userPda: util.generateUserPda(userWallet),
136
+ clock: web3.SYSVAR_CLOCK_PUBKEY,
137
+ })
138
+ .instruction();
139
+ return ix;
140
+ });
141
+ }
142
+ exports.setTransactionSlot = setTransactionSlot;
143
+ function verifyTransactionSlot(_a) {
144
+ return __awaiter(this, arguments, void 0, function* ({ userWallet }) {
145
+ const ix = yield anchor_1.Anchor
146
+ .instance().iyfMain.methods
147
+ .verifyTransactionSlot()
148
+ .accounts({
149
+ userPda: util.generateUserPda(userWallet),
150
+ clock: web3.SYSVAR_CLOCK_PUBKEY,
151
+ })
152
+ .instruction();
153
+ return ix;
154
+ });
155
+ }
156
+ exports.verifyTransactionSlot = verifyTransactionSlot;