kit-squared 0.2.8 → 1.0.0

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/README.md CHANGED
@@ -108,9 +108,9 @@ It also tracks the transaction state, and fires events when the tx state changes
108
108
  ### Sending Transactions
109
109
  Send a transaction with any instructions using
110
110
  ```typescript
111
- transact(ixs, names);
111
+ transact(ixs, names, preSimulate);
112
112
  ```
113
- Where `ixs` is an array of `@solana/kit` `Instruction`s, and `names` is an optional array of ix names that will be fired with each tx lifecycle event.
113
+ Where `ixs` is an array of `@solana/kit` `Instruction`s, and `names` is an optional array of ix names that will be fired with each tx lifecycle event. If `preSimulate` is `true`, the library will simulate the tx before requesting it, and cause this function fail if the tx will fail.
114
114
 
115
115
  ### Transaction Lifecycle
116
116
  Kit² only expects one tx to be in progress at any given time. While it doesn't prevent multiple simultaneous txs, the tx-lifecycle management is simplified for only one.
@@ -37,9 +37,7 @@ function _connect() {
37
37
  const { value: latestBlockhash } = await rpc.getLatestBlockhash().send({ abortSignal });
38
38
  const transactionMessage = pipe(createTransactionMessage({ version: 0 }), (message) => setTransactionMessageFeePayerSigner(feePayer, message), (message) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, message), (message) => appendTransactionMessageInstructions(instructions, message));
39
39
  assertIsTransactionMessageWithSingleSendingSigner(transactionMessage);
40
- console.log("AA1");
41
40
  const signatureBytes = await signAndSendTransactionMessageWithSigners(transactionMessage);
42
- console.log("AAB");
43
41
  const signature = signatureBytesToBase58String(signatureBytes);
44
42
  return signature;
45
43
  };
@@ -48,5 +48,5 @@ export type SimulationError = {
48
48
  anchorErrorLog: string;
49
49
  };
50
50
  export declare function simulate(ixs?: Instruction[]): Promise<Simulation>;
51
- export declare function transact(ixs?: Instruction[], names?: string[]): Promise<void>;
52
- export declare function transactSingle(ix: Instruction, name?: string | null): Promise<void>;
51
+ export declare function transact(ixs?: Instruction[], names?: string[], preSimulate?: boolean): Promise<void>;
52
+ export declare function transactSingle(ix: Instruction, name?: string | null, preSimulate?: boolean): Promise<void>;
@@ -40,7 +40,6 @@ function _txWasCancelled(e) {
40
40
  }
41
41
  return msg.includes('denied') || msg.includes('rejected') || msg.includes('cancelled');
42
42
  }
43
- let log = console.log;
44
43
  function _parseError(result) {
45
44
  const instructionPrefix = "Program log: Instruction: ";
46
45
  const errorPrefix = "Program log: AnchorError ";
@@ -109,7 +108,7 @@ export async function simulate(ixs = []) {
109
108
  replaceRecentBlockhash: true,
110
109
  sigVerify: false,
111
110
  minContextSlot: undefined,
112
- innerInstructions: undefined,
111
+ innerInstructions: true,
113
112
  accounts: undefined
114
113
  };
115
114
  const feePayer = signer;
@@ -132,11 +131,19 @@ export async function simulate(ixs = []) {
132
131
  success,
133
132
  error
134
133
  };
135
- console.log(simulateResult);
136
134
  }
137
- export async function transact(ixs = [], names = []) {
135
+ export async function transact(ixs = [], names = [], preSimulate = true) {
138
136
  _setTransacting(REQUESTED);
139
137
  onRequest.trigger(names);
138
+ if (preSimulate) {
139
+ const simResult = await simulate(ixs);
140
+ if (!simResult.success) {
141
+ console.error(simResult.error);
142
+ onFail.trigger(names);
143
+ _setTransacting(INITIAL);
144
+ return;
145
+ }
146
+ }
140
147
  const connection = getConnection();
141
148
  try {
142
149
  const signature = await connection.sendTransactionFromInstructionsWithWalletApp({
@@ -167,7 +174,7 @@ export async function transact(ixs = [], names = []) {
167
174
  _setTransacting(INITIAL);
168
175
  }
169
176
  }
170
- export async function transactSingle(ix, name = null) {
177
+ export async function transactSingle(ix, name = null, preSimulate = true) {
171
178
  let names = name ? [name] : [];
172
- return await transact([ix], names);
179
+ return await transact([ix], names, preSimulate);
173
180
  }
@@ -20,7 +20,6 @@ const INITIAL = WALLET_STATE.INITIAL;
20
20
  const CONNECTING = WALLET_STATE.CONNECTING;
21
21
  const CONNECTED = WALLET_STATE.CONNECTED;
22
22
  const ERROR = WALLET_STATE.ERROR;
23
- let log = console.log;
24
23
  export let walletState = writable(WALLET_STATE.INITIAL);
25
24
  function _setWalletState(state) {
26
25
  walletState.set(state);
@@ -84,8 +83,6 @@ async function connectWallet(uiWallet) {
84
83
  const accountsPromise = connectFeature
85
84
  .connect()
86
85
  .then(({ accounts }) => {
87
- // console.log("connected", accounts);
88
- // return accounts;
89
86
  return accounts.map(getOrCreateUiWalletAccountForStandardWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.bind(null, wallet));
90
87
  });
91
88
  const nextAccounts = await accountsPromise;
@@ -161,9 +158,7 @@ function _buildTransactionSendingSigner(_networkType) {
161
158
  chain,
162
159
  account: walletAccount,
163
160
  };
164
- log(111);
165
161
  const [{ signature }] = await getAbortablePromise(signAndSendTransactionFeature.signAndSendTransaction(inputWithOptions), abortSignal);
166
- log(222);
167
162
  return Object.freeze([signature]);
168
163
  },
169
164
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kit-squared",
3
- "version": "0.2.8",
3
+ "version": "1.0.0",
4
4
  "description": "Solana Kit functionality with SvelteKit",
5
5
  "license": "ISC",
6
6
  "author": "AnAllergyToAnalogy",