@fogo/sessions-sdk 0.1.6 → 0.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.
- package/cjs/connection.d.ts +2 -1
- package/cjs/connection.js +17 -7
- package/esm/connection.d.ts +2 -1
- package/esm/connection.js +17 -7
- package/package.json +1 -1
package/cjs/connection.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GetLatestBlockhashApi, Instruction, Rpc, Transaction, TransactionWithLifetime } from "@solana/kit";
|
|
1
|
+
import type { Address, GetLatestBlockhashApi, Instruction, Rpc, Transaction, TransactionWithLifetime } from "@solana/kit";
|
|
2
2
|
import type { TransactionError } from "@solana/web3.js";
|
|
3
3
|
import { Keypair, PublicKey, TransactionInstruction, VersionedTransaction, Connection as Web3Connection } from "@solana/web3.js";
|
|
4
4
|
import { Network } from "./network.js";
|
|
@@ -42,6 +42,7 @@ export type SendTransactionOptions = {
|
|
|
42
42
|
variation?: string | undefined;
|
|
43
43
|
addressLookupTable?: string | undefined;
|
|
44
44
|
extraSigners?: (CryptoKeyPair | Keypair)[] | undefined;
|
|
45
|
+
feeMint?: PublicKey | Address;
|
|
45
46
|
};
|
|
46
47
|
export type Connection = ReturnType<typeof createSessionConnection>;
|
|
47
48
|
export {};
|
package/cjs/connection.js
CHANGED
|
@@ -11,7 +11,6 @@ const web3_js_1 = require("@solana/web3.js");
|
|
|
11
11
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
12
12
|
const zod_1 = require("zod");
|
|
13
13
|
const instructions_js_1 = require("./instructions.js");
|
|
14
|
-
const mints_js_1 = require("./mints.js");
|
|
15
14
|
const network_js_1 = require("./network.js");
|
|
16
15
|
const paymaster_js_1 = require("./paymaster.js");
|
|
17
16
|
const DEFAULT_RPC = {
|
|
@@ -108,7 +107,9 @@ const sendToPaymaster = async (connection, domain, sessionKey, instructions, wal
|
|
|
108
107
|
}
|
|
109
108
|
};
|
|
110
109
|
const buildTransaction = async (connection, domain, sessionKey, signerKeys, instructions, walletPublicKey, extraConfig) => {
|
|
111
|
-
const feeMint =
|
|
110
|
+
const feeMint = extraConfig?.feeMint === undefined
|
|
111
|
+
? undefined
|
|
112
|
+
: new web3_js_1.PublicKey(extraConfig.feeMint);
|
|
112
113
|
const [{ value: latestBlockhash }, sponsor, addressLookupTable, signers, feeAmount, sessionKeyAddress,] = await Promise.all([
|
|
113
114
|
connection.rpc.getLatestBlockhash().send(),
|
|
114
115
|
connection.sponsor === undefined
|
|
@@ -118,7 +119,7 @@ const buildTransaction = async (connection, domain, sessionKey, signerKeys, inst
|
|
|
118
119
|
? Promise.resolve(undefined)
|
|
119
120
|
: getAddressLookupTable(connection.connection, connection.addressLookupTableCache, extraConfig.addressLookupTable),
|
|
120
121
|
Promise.all(signerKeys.map((signer) => (0, kit_1.createSignerFromKeyPair)(signer))),
|
|
121
|
-
extraConfig?.variation === undefined
|
|
122
|
+
extraConfig?.variation === undefined || feeMint === undefined
|
|
122
123
|
? Promise.resolve(new bn_js_1.default(0))
|
|
123
124
|
: (0, paymaster_js_1.getPaymasterFee)(connection.paymaster ?? DEFAULT_PAYMASTER[connection.network], domain, extraConfig.variation, feeMint),
|
|
124
125
|
sessionKey === undefined
|
|
@@ -144,7 +145,9 @@ const buildTransaction = async (connection, domain, sessionKey, signerKeys, inst
|
|
|
144
145
|
}), (tx) => (0, kit_1.addSignersToTransactionMessage)(signers, tx)));
|
|
145
146
|
};
|
|
146
147
|
const buildTollboothInstructionIfNeeded = ({ sessionKeyAddress, walletPublicKey, domain, feeMint, feeAmount, }) => {
|
|
147
|
-
if (feeAmount.gt(new bn_js_1.default(0)) &&
|
|
148
|
+
if (feeAmount.gt(new bn_js_1.default(0)) &&
|
|
149
|
+
sessionKeyAddress !== undefined &&
|
|
150
|
+
feeMint !== undefined) {
|
|
148
151
|
return (0, instructions_js_1.createPaymasterFeeInstruction)({
|
|
149
152
|
sessionKey: new web3_js_1.PublicKey(sessionKeyAddress),
|
|
150
153
|
walletPublicKey,
|
|
@@ -157,9 +160,16 @@ const buildTollboothInstructionIfNeeded = ({ sessionKeyAddress, walletPublicKey,
|
|
|
157
160
|
return undefined;
|
|
158
161
|
}
|
|
159
162
|
};
|
|
160
|
-
const addSignaturesToExistingTransaction = (transaction, signerKeys) =>
|
|
161
|
-
|
|
162
|
-
|
|
163
|
+
const addSignaturesToExistingTransaction = async (transaction, signerKeys) => {
|
|
164
|
+
const kitTransaction = transaction instanceof web3_js_1.VersionedTransaction
|
|
165
|
+
? (0, compat_1.fromVersionedTransaction)(transaction) // VersionedTransaction has a lifetime so it's fine to cast it so we can call partiallySignTransaction
|
|
166
|
+
: transaction;
|
|
167
|
+
const signerAddresses = await Promise.all(signerKeys.map(async (signer) => [signer, await (0, kit_1.getAddressFromPublicKey)(signer.publicKey)]));
|
|
168
|
+
const filteredSignerKeys = signerAddresses
|
|
169
|
+
.filter(([, address]) => kitTransaction.signatures[address] !== undefined)
|
|
170
|
+
.map(([signer]) => signer);
|
|
171
|
+
return (0, kit_1.partiallySignTransaction)(filteredSignerKeys, kitTransaction);
|
|
172
|
+
};
|
|
163
173
|
const getSignerKeys = async (sessionKey, extraSigners) => {
|
|
164
174
|
const extraSignerKeys = extraSigners === undefined
|
|
165
175
|
? []
|
package/esm/connection.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GetLatestBlockhashApi, Instruction, Rpc, Transaction, TransactionWithLifetime } from "@solana/kit";
|
|
1
|
+
import type { Address, GetLatestBlockhashApi, Instruction, Rpc, Transaction, TransactionWithLifetime } from "@solana/kit";
|
|
2
2
|
import type { TransactionError } from "@solana/web3.js";
|
|
3
3
|
import { Keypair, PublicKey, TransactionInstruction, VersionedTransaction, Connection as Web3Connection } from "@solana/web3.js";
|
|
4
4
|
import { Network } from "./network.js";
|
|
@@ -42,6 +42,7 @@ export type SendTransactionOptions = {
|
|
|
42
42
|
variation?: string | undefined;
|
|
43
43
|
addressLookupTable?: string | undefined;
|
|
44
44
|
extraSigners?: (CryptoKeyPair | Keypair)[] | undefined;
|
|
45
|
+
feeMint?: PublicKey | Address;
|
|
45
46
|
};
|
|
46
47
|
export type Connection = ReturnType<typeof createSessionConnection>;
|
|
47
48
|
export {};
|
package/esm/connection.js
CHANGED
|
@@ -5,7 +5,6 @@ import { Keypair, PublicKey, TransactionInstruction, VersionedTransaction, Conne
|
|
|
5
5
|
import BN from "bn.js";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { createPaymasterFeeInstruction } from "./instructions.js";
|
|
8
|
-
import { USDC_MINT } from "./mints.js";
|
|
9
8
|
import { Network } from "./network.js";
|
|
10
9
|
import { getPaymasterFee, PaymasterResponseError } from "./paymaster.js";
|
|
11
10
|
const DEFAULT_RPC = {
|
|
@@ -101,7 +100,9 @@ const sendToPaymaster = async (connection, domain, sessionKey, instructions, wal
|
|
|
101
100
|
}
|
|
102
101
|
};
|
|
103
102
|
const buildTransaction = async (connection, domain, sessionKey, signerKeys, instructions, walletPublicKey, extraConfig) => {
|
|
104
|
-
const feeMint =
|
|
103
|
+
const feeMint = extraConfig?.feeMint === undefined
|
|
104
|
+
? undefined
|
|
105
|
+
: new PublicKey(extraConfig.feeMint);
|
|
105
106
|
const [{ value: latestBlockhash }, sponsor, addressLookupTable, signers, feeAmount, sessionKeyAddress,] = await Promise.all([
|
|
106
107
|
connection.rpc.getLatestBlockhash().send(),
|
|
107
108
|
connection.sponsor === undefined
|
|
@@ -111,7 +112,7 @@ const buildTransaction = async (connection, domain, sessionKey, signerKeys, inst
|
|
|
111
112
|
? Promise.resolve(undefined)
|
|
112
113
|
: getAddressLookupTable(connection.connection, connection.addressLookupTableCache, extraConfig.addressLookupTable),
|
|
113
114
|
Promise.all(signerKeys.map((signer) => createSignerFromKeyPair(signer))),
|
|
114
|
-
extraConfig?.variation === undefined
|
|
115
|
+
extraConfig?.variation === undefined || feeMint === undefined
|
|
115
116
|
? Promise.resolve(new BN(0))
|
|
116
117
|
: getPaymasterFee(connection.paymaster ?? DEFAULT_PAYMASTER[connection.network], domain, extraConfig.variation, feeMint),
|
|
117
118
|
sessionKey === undefined
|
|
@@ -137,7 +138,9 @@ const buildTransaction = async (connection, domain, sessionKey, signerKeys, inst
|
|
|
137
138
|
}), (tx) => addSignersToTransactionMessage(signers, tx)));
|
|
138
139
|
};
|
|
139
140
|
const buildTollboothInstructionIfNeeded = ({ sessionKeyAddress, walletPublicKey, domain, feeMint, feeAmount, }) => {
|
|
140
|
-
if (feeAmount.gt(new BN(0)) &&
|
|
141
|
+
if (feeAmount.gt(new BN(0)) &&
|
|
142
|
+
sessionKeyAddress !== undefined &&
|
|
143
|
+
feeMint !== undefined) {
|
|
141
144
|
return createPaymasterFeeInstruction({
|
|
142
145
|
sessionKey: new PublicKey(sessionKeyAddress),
|
|
143
146
|
walletPublicKey,
|
|
@@ -150,9 +153,16 @@ const buildTollboothInstructionIfNeeded = ({ sessionKeyAddress, walletPublicKey,
|
|
|
150
153
|
return undefined;
|
|
151
154
|
}
|
|
152
155
|
};
|
|
153
|
-
const addSignaturesToExistingTransaction = (transaction, signerKeys) =>
|
|
154
|
-
|
|
155
|
-
|
|
156
|
+
const addSignaturesToExistingTransaction = async (transaction, signerKeys) => {
|
|
157
|
+
const kitTransaction = transaction instanceof VersionedTransaction
|
|
158
|
+
? fromVersionedTransaction(transaction) // VersionedTransaction has a lifetime so it's fine to cast it so we can call partiallySignTransaction
|
|
159
|
+
: transaction;
|
|
160
|
+
const signerAddresses = await Promise.all(signerKeys.map(async (signer) => [signer, await getAddressFromPublicKey(signer.publicKey)]));
|
|
161
|
+
const filteredSignerKeys = signerAddresses
|
|
162
|
+
.filter(([, address]) => kitTransaction.signatures[address] !== undefined)
|
|
163
|
+
.map(([signer]) => signer);
|
|
164
|
+
return partiallySignTransaction(filteredSignerKeys, kitTransaction);
|
|
165
|
+
};
|
|
156
166
|
const getSignerKeys = async (sessionKey, extraSigners) => {
|
|
157
167
|
const extraSignerKeys = extraSigners === undefined
|
|
158
168
|
? []
|