@faremeter/payment-solana 0.8.0 → 0.9.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/dist/src/exact/client.d.ts +1 -1
- package/dist/src/exact/client.d.ts.map +1 -1
- package/dist/src/exact/client.js +22 -4
- package/dist/src/exact/facilitator.d.ts +2 -0
- package/dist/src/exact/facilitator.d.ts.map +1 -1
- package/dist/src/exact/facilitator.js +15 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -7,5 +7,5 @@ export type Wallet = {
|
|
|
7
7
|
updateTransaction?: (tx: VersionedTransaction) => Promise<VersionedTransaction>;
|
|
8
8
|
sendTransaction?: (tx: VersionedTransaction) => Promise<string>;
|
|
9
9
|
};
|
|
10
|
-
export declare function createPaymentHandler(wallet: Wallet, mint: PublicKey, connection
|
|
10
|
+
export declare function createPaymentHandler(wallet: Wallet, mint: PublicKey, connection?: Connection): PaymentHandler;
|
|
11
11
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/exact/client.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAEV,cAAc,EAEf,MAAM,yBAAyB,CAAC;AAWjC,OAAO,EAEL,UAAU,EACV,SAAS,EACT,sBAAsB,EAEtB,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AAQzB,MAAM,MAAM,MAAM,GAAG;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,SAAS,CAAC;IACrB,gBAAgB,CAAC,EAAE,CACjB,YAAY,EAAE,sBAAsB,EAAE,EACtC,eAAe,EAAE,MAAM,KACpB,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACnC,iBAAiB,CAAC,EAAE,CAClB,EAAE,EAAE,oBAAoB,KACrB,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACnC,eAAe,CAAC,EAAE,CAAC,EAAE,EAAE,oBAAoB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CACjE,CAAC;AAEF,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,EACf,UAAU,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/exact/client.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAEV,cAAc,EAEf,MAAM,yBAAyB,CAAC;AAWjC,OAAO,EAEL,UAAU,EACV,SAAS,EACT,sBAAsB,EAEtB,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AAQzB,MAAM,MAAM,MAAM,GAAG;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,SAAS,CAAC;IACrB,gBAAgB,CAAC,EAAE,CACjB,YAAY,EAAE,sBAAsB,EAAE,EACtC,eAAe,EAAE,MAAM,KACpB,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACnC,iBAAiB,CAAC,EAAE,CAClB,EAAE,EAAE,oBAAoB,KACrB,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACnC,eAAe,CAAC,EAAE,CAAC,EAAE,EAAE,oBAAoB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CACjE,CAAC;AAEF,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,EACf,UAAU,CAAC,EAAE,UAAU,GACtB,cAAc,CAyHhB"}
|
package/dist/src/exact/client.js
CHANGED
|
@@ -19,6 +19,27 @@ export function createPaymentHandler(wallet, mint, connection) {
|
|
|
19
19
|
throwValidationError("couldn't validate requirements extra field", extra);
|
|
20
20
|
}
|
|
21
21
|
const exec = async () => {
|
|
22
|
+
let recentBlockhash;
|
|
23
|
+
if (extra.recentBlockhash !== undefined) {
|
|
24
|
+
recentBlockhash = extra.recentBlockhash;
|
|
25
|
+
}
|
|
26
|
+
else if (connection !== undefined) {
|
|
27
|
+
recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
throw new Error("couldn't get the latest Solana network block hash");
|
|
31
|
+
}
|
|
32
|
+
let decimals;
|
|
33
|
+
if (extra.decimals !== undefined) {
|
|
34
|
+
decimals = extra.decimals;
|
|
35
|
+
}
|
|
36
|
+
else if (connection !== undefined) {
|
|
37
|
+
const mintInfo = await getMint(connection, mint);
|
|
38
|
+
decimals = mintInfo.decimals;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
throw new Error("couldn't get the decimal information for the mint");
|
|
42
|
+
}
|
|
22
43
|
const paymentRequirements = {
|
|
23
44
|
...extra,
|
|
24
45
|
amount: Number(requirements.maxAmountRequired),
|
|
@@ -26,7 +47,6 @@ export function createPaymentHandler(wallet, mint, connection) {
|
|
|
26
47
|
};
|
|
27
48
|
const sourceAccount = getAssociatedTokenAddressSync(mint, wallet.publicKey);
|
|
28
49
|
const receiverAccount = getAssociatedTokenAddressSync(mint, paymentRequirements.receiver);
|
|
29
|
-
const mintInfo = await getMint(connection, mint);
|
|
30
50
|
const instructions = [
|
|
31
51
|
ComputeBudgetProgram.setComputeUnitLimit({
|
|
32
52
|
units: 50_000,
|
|
@@ -34,10 +54,8 @@ export function createPaymentHandler(wallet, mint, connection) {
|
|
|
34
54
|
ComputeBudgetProgram.setComputeUnitPrice({
|
|
35
55
|
microLamports: 1,
|
|
36
56
|
}),
|
|
37
|
-
createTransferCheckedInstruction(sourceAccount, mint, receiverAccount, wallet.publicKey, paymentRequirements.amount,
|
|
57
|
+
createTransferCheckedInstruction(sourceAccount, mint, receiverAccount, wallet.publicKey, paymentRequirements.amount, decimals),
|
|
38
58
|
];
|
|
39
|
-
const recentBlockhash = (await connection.getLatestBlockhash())
|
|
40
|
-
.blockhash;
|
|
41
59
|
let tx;
|
|
42
60
|
if (wallet.buildTransaction) {
|
|
43
61
|
tx = await wallet.buildTransaction(instructions, recentBlockhash);
|
|
@@ -5,6 +5,8 @@ import { Keypair, type PublicKey } from "@solana/web3.js";
|
|
|
5
5
|
export declare const x402Scheme = "exact";
|
|
6
6
|
export declare const PaymentRequirementsExtra: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
7
7
|
feePayer: string;
|
|
8
|
+
decimals?: number;
|
|
9
|
+
recentBlockhash?: string;
|
|
8
10
|
}, {}>;
|
|
9
11
|
export declare const PaymentPayload: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
10
12
|
transaction: (In: string) => import("arktype").Out<Readonly<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"facilitator.d.ts","sourceRoot":"","sources":["../../../src/exact/facilitator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"facilitator.d.ts","sourceRoot":"","sources":["../../../src/exact/facilitator.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,OAAO,EAML,KAAK,GAAG,EACR,KAAK,YAAY,EAClB,MAAM,aAAa,CAAC;AAOrB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAK1D,eAAO,MAAM,UAAU,UAAU,CAAC;AAElC,eAAO,MAAM,wBAAwB;;;;MAInC,CAAC;AAmBH,eAAO,MAAM,cAAc;;;;;MAEzB,CAAC;AAEH,eAAO,MAAM,iBAAiB,GAAI,SAAS,MAAM,WAEhD,CAAC;AAEF,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,gBAAgB,UAY3D;AAiDD,eAAO,MAAM,wBAAwB,GACnC,SAAS,MAAM,EACf,KAAK,GAAG,CAAC,YAAY,CAAC,EACtB,iBAAiB,OAAO,EACxB,MAAM,SAAS,EACf,mBAAe,EACf,qBAAmB,KAClB,kBAqHF,CAAC"}
|
|
@@ -9,6 +9,8 @@ import { logger } from "./logger.js";
|
|
|
9
9
|
export const x402Scheme = "exact";
|
|
10
10
|
export const PaymentRequirementsExtra = type({
|
|
11
11
|
feePayer: "string",
|
|
12
|
+
decimals: "number?",
|
|
13
|
+
recentBlockhash: "string?",
|
|
12
14
|
});
|
|
13
15
|
function errorResponse(msg) {
|
|
14
16
|
logger.error(msg);
|
|
@@ -80,6 +82,18 @@ export const createFacilitatorHandler = (network, rpc, feePayerKeypair, mint, ma
|
|
|
80
82
|
const checkTupleAndAsset = checkTuple.and({
|
|
81
83
|
asset: caseInsensitiveLiteral(mint.toBase58()),
|
|
82
84
|
});
|
|
85
|
+
const getSupported = () => {
|
|
86
|
+
return [
|
|
87
|
+
Promise.resolve({
|
|
88
|
+
x402Version: 1,
|
|
89
|
+
scheme: x402Scheme,
|
|
90
|
+
network: lookupX402Network(network),
|
|
91
|
+
extra: {
|
|
92
|
+
feePayer: feePayerKeypair.publicKey.toString(),
|
|
93
|
+
},
|
|
94
|
+
}),
|
|
95
|
+
];
|
|
96
|
+
};
|
|
83
97
|
const getRequirements = async (req) => {
|
|
84
98
|
const recentBlockhash = (await rpc.getLatestBlockhash().send()).value
|
|
85
99
|
.blockhash;
|
|
@@ -150,6 +164,7 @@ export const createFacilitatorHandler = (network, rpc, feePayerKeypair, mint, ma
|
|
|
150
164
|
};
|
|
151
165
|
};
|
|
152
166
|
return {
|
|
167
|
+
getSupported,
|
|
153
168
|
getRequirements,
|
|
154
169
|
handleSettle,
|
|
155
170
|
};
|