x402-svm-mantle 2.1.1-mantle
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 +200 -0
- package/dist/cjs/exact/client/index.d.ts +37 -0
- package/dist/cjs/exact/client/index.js +281 -0
- package/dist/cjs/exact/client/index.js.map +1 -0
- package/dist/cjs/exact/facilitator/index.d.ts +110 -0
- package/dist/cjs/exact/facilitator/index.js +714 -0
- package/dist/cjs/exact/facilitator/index.js.map +1 -0
- package/dist/cjs/exact/server/index.d.ts +87 -0
- package/dist/cjs/exact/server/index.js +209 -0
- package/dist/cjs/exact/server/index.js.map +1 -0
- package/dist/cjs/exact/v1/client/index.d.ts +33 -0
- package/dist/cjs/exact/v1/client/index.js +169 -0
- package/dist/cjs/exact/v1/client/index.js.map +1 -0
- package/dist/cjs/exact/v1/facilitator/index.d.ts +71 -0
- package/dist/cjs/exact/v1/facilitator/index.js +384 -0
- package/dist/cjs/exact/v1/facilitator/index.js.map +1 -0
- package/dist/cjs/index.d.ts +118 -0
- package/dist/cjs/index.js +433 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/scheme-CkL_b_xl.d.ts +29 -0
- package/dist/cjs/scheme-MoBRXFM8.d.ts +29 -0
- package/dist/cjs/signer-BMkbhFYE.d.ts +123 -0
- package/dist/cjs/v1/index.d.ts +12 -0
- package/dist/cjs/v1/index.js +180 -0
- package/dist/cjs/v1/index.js.map +1 -0
- package/dist/esm/chunk-M7NDDMX7.mjs +111 -0
- package/dist/esm/chunk-M7NDDMX7.mjs.map +1 -0
- package/dist/esm/chunk-PHFXLBH6.mjs +157 -0
- package/dist/esm/chunk-PHFXLBH6.mjs.map +1 -0
- package/dist/esm/chunk-TA6OPUHK.mjs +108 -0
- package/dist/esm/chunk-TA6OPUHK.mjs.map +1 -0
- package/dist/esm/chunk-WRDCPYFH.mjs +339 -0
- package/dist/esm/chunk-WRDCPYFH.mjs.map +1 -0
- package/dist/esm/chunk-WWACQNRQ.mjs +7 -0
- package/dist/esm/chunk-WWACQNRQ.mjs.map +1 -0
- package/dist/esm/exact/client/index.d.mts +37 -0
- package/dist/esm/exact/client/index.mjs +36 -0
- package/dist/esm/exact/client/index.mjs.map +1 -0
- package/dist/esm/exact/facilitator/index.d.mts +110 -0
- package/dist/esm/exact/facilitator/index.mjs +350 -0
- package/dist/esm/exact/facilitator/index.mjs.map +1 -0
- package/dist/esm/exact/server/index.d.mts +87 -0
- package/dist/esm/exact/server/index.mjs +129 -0
- package/dist/esm/exact/server/index.mjs.map +1 -0
- package/dist/esm/exact/v1/client/index.d.mts +33 -0
- package/dist/esm/exact/v1/client/index.mjs +8 -0
- package/dist/esm/exact/v1/client/index.mjs.map +1 -0
- package/dist/esm/exact/v1/facilitator/index.d.mts +71 -0
- package/dist/esm/exact/v1/facilitator/index.mjs +8 -0
- package/dist/esm/exact/v1/facilitator/index.mjs.map +1 -0
- package/dist/esm/index.d.mts +118 -0
- package/dist/esm/index.mjs +198 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/scheme-VFikrqtD.d.mts +29 -0
- package/dist/esm/signer-BMkbhFYE.d.mts +123 -0
- package/dist/esm/v1/index.d.mts +12 -0
- package/dist/esm/v1/index.mjs +13 -0
- package/dist/esm/v1/index.mjs.map +1 -0
- package/package.json +130 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { SchemeNetworkServer, MoneyParser, Price, Network, AssetAmount, PaymentRequirements } from 'x402-core-mantle/types';
|
|
2
|
+
import { x402ResourceServer } from 'x402-core-mantle/server';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* SVM server implementation for the Exact payment scheme.
|
|
6
|
+
*/
|
|
7
|
+
declare class ExactSvmScheme implements SchemeNetworkServer {
|
|
8
|
+
readonly scheme = "exact";
|
|
9
|
+
private moneyParsers;
|
|
10
|
+
/**
|
|
11
|
+
* Register a custom money parser in the parser chain.
|
|
12
|
+
* Multiple parsers can be registered - they will be tried in registration order.
|
|
13
|
+
* Each parser receives a decimal amount (e.g., 1.50 for $1.50).
|
|
14
|
+
* If a parser returns null, the next parser in the chain will be tried.
|
|
15
|
+
* The default parser is always the final fallback.
|
|
16
|
+
*
|
|
17
|
+
* @param parser - Custom function to convert amount to AssetAmount (or null to skip)
|
|
18
|
+
* @returns The service instance for chaining
|
|
19
|
+
*/
|
|
20
|
+
registerMoneyParser(parser: MoneyParser): ExactSvmScheme;
|
|
21
|
+
/**
|
|
22
|
+
* Parses a price into an asset amount.
|
|
23
|
+
* If price is already an AssetAmount, returns it directly.
|
|
24
|
+
* If price is Money (string | number), parses to decimal and tries custom parsers.
|
|
25
|
+
* Falls back to default conversion if all custom parsers return null.
|
|
26
|
+
*
|
|
27
|
+
* @param price - The price to parse
|
|
28
|
+
* @param network - The network to use
|
|
29
|
+
* @returns Promise that resolves to the parsed asset amount
|
|
30
|
+
*/
|
|
31
|
+
parsePrice(price: Price, network: Network): Promise<AssetAmount>;
|
|
32
|
+
/**
|
|
33
|
+
* Build payment requirements for this scheme/network combination
|
|
34
|
+
*
|
|
35
|
+
* @param paymentRequirements - The base payment requirements
|
|
36
|
+
* @param supportedKind - The supported kind configuration
|
|
37
|
+
* @param supportedKind.x402Version - The x402 protocol version
|
|
38
|
+
* @param supportedKind.scheme - The payment scheme
|
|
39
|
+
* @param supportedKind.network - The network identifier
|
|
40
|
+
* @param supportedKind.extra - Extra metadata including feePayer address
|
|
41
|
+
* @param extensionKeys - Extension keys supported by the facilitator
|
|
42
|
+
* @returns Enhanced payment requirements with feePayer in extra
|
|
43
|
+
*/
|
|
44
|
+
enhancePaymentRequirements(paymentRequirements: PaymentRequirements, supportedKind: {
|
|
45
|
+
x402Version: number;
|
|
46
|
+
scheme: string;
|
|
47
|
+
network: Network;
|
|
48
|
+
extra?: Record<string, unknown>;
|
|
49
|
+
}, extensionKeys: string[]): Promise<PaymentRequirements>;
|
|
50
|
+
/**
|
|
51
|
+
* Parse Money (string | number) to a decimal number.
|
|
52
|
+
* Handles formats like "$1.50", "1.50", 1.50, etc.
|
|
53
|
+
*
|
|
54
|
+
* @param money - The money value to parse
|
|
55
|
+
* @returns Decimal number
|
|
56
|
+
*/
|
|
57
|
+
private parseMoneyToDecimal;
|
|
58
|
+
/**
|
|
59
|
+
* Default money conversion implementation.
|
|
60
|
+
* Converts decimal amount to USDC on the specified network.
|
|
61
|
+
*
|
|
62
|
+
* @param amount - The decimal amount (e.g., 1.50)
|
|
63
|
+
* @param network - The network to use
|
|
64
|
+
* @returns The parsed asset amount in USDC
|
|
65
|
+
*/
|
|
66
|
+
private defaultMoneyConversion;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Configuration options for registering SVM schemes to an x402ResourceServer
|
|
71
|
+
*/
|
|
72
|
+
interface SvmResourceServerConfig {
|
|
73
|
+
/**
|
|
74
|
+
* Optional specific networks to register
|
|
75
|
+
*/
|
|
76
|
+
networks?: Network[];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Registers SVM payment schemes to an existing x402ResourceServer instance.
|
|
80
|
+
*
|
|
81
|
+
* @param server - The x402ResourceServer instance to register schemes to
|
|
82
|
+
* @param config - Configuration for SVM resource server registration
|
|
83
|
+
* @returns The server instance for chaining
|
|
84
|
+
*/
|
|
85
|
+
declare function registerExactSvmScheme(server: x402ResourceServer, config?: SvmResourceServerConfig): x402ResourceServer;
|
|
86
|
+
|
|
87
|
+
export { ExactSvmScheme, type SvmResourceServerConfig, registerExactSvmScheme };
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import {
|
|
2
|
+
convertToTokenAmount,
|
|
3
|
+
getUsdcAddress
|
|
4
|
+
} from "../../chunk-PHFXLBH6.mjs";
|
|
5
|
+
|
|
6
|
+
// src/exact/server/scheme.ts
|
|
7
|
+
var ExactSvmScheme = class {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.scheme = "exact";
|
|
10
|
+
this.moneyParsers = [];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Register a custom money parser in the parser chain.
|
|
14
|
+
* Multiple parsers can be registered - they will be tried in registration order.
|
|
15
|
+
* Each parser receives a decimal amount (e.g., 1.50 for $1.50).
|
|
16
|
+
* If a parser returns null, the next parser in the chain will be tried.
|
|
17
|
+
* The default parser is always the final fallback.
|
|
18
|
+
*
|
|
19
|
+
* @param parser - Custom function to convert amount to AssetAmount (or null to skip)
|
|
20
|
+
* @returns The service instance for chaining
|
|
21
|
+
*/
|
|
22
|
+
registerMoneyParser(parser) {
|
|
23
|
+
this.moneyParsers.push(parser);
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Parses a price into an asset amount.
|
|
28
|
+
* If price is already an AssetAmount, returns it directly.
|
|
29
|
+
* If price is Money (string | number), parses to decimal and tries custom parsers.
|
|
30
|
+
* Falls back to default conversion if all custom parsers return null.
|
|
31
|
+
*
|
|
32
|
+
* @param price - The price to parse
|
|
33
|
+
* @param network - The network to use
|
|
34
|
+
* @returns Promise that resolves to the parsed asset amount
|
|
35
|
+
*/
|
|
36
|
+
async parsePrice(price, network) {
|
|
37
|
+
if (typeof price === "object" && price !== null && "amount" in price) {
|
|
38
|
+
if (!price.asset) {
|
|
39
|
+
throw new Error(`Asset address must be specified for AssetAmount on network ${network}`);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
amount: price.amount,
|
|
43
|
+
asset: price.asset,
|
|
44
|
+
extra: price.extra || {}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const amount = this.parseMoneyToDecimal(price);
|
|
48
|
+
for (const parser of this.moneyParsers) {
|
|
49
|
+
const result = await parser(amount, network);
|
|
50
|
+
if (result !== null) {
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return this.defaultMoneyConversion(amount, network);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Build payment requirements for this scheme/network combination
|
|
58
|
+
*
|
|
59
|
+
* @param paymentRequirements - The base payment requirements
|
|
60
|
+
* @param supportedKind - The supported kind configuration
|
|
61
|
+
* @param supportedKind.x402Version - The x402 protocol version
|
|
62
|
+
* @param supportedKind.scheme - The payment scheme
|
|
63
|
+
* @param supportedKind.network - The network identifier
|
|
64
|
+
* @param supportedKind.extra - Extra metadata including feePayer address
|
|
65
|
+
* @param extensionKeys - Extension keys supported by the facilitator
|
|
66
|
+
* @returns Enhanced payment requirements with feePayer in extra
|
|
67
|
+
*/
|
|
68
|
+
enhancePaymentRequirements(paymentRequirements, supportedKind, extensionKeys) {
|
|
69
|
+
void extensionKeys;
|
|
70
|
+
return Promise.resolve({
|
|
71
|
+
...paymentRequirements,
|
|
72
|
+
extra: {
|
|
73
|
+
...paymentRequirements.extra,
|
|
74
|
+
feePayer: supportedKind.extra?.feePayer
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Parse Money (string | number) to a decimal number.
|
|
80
|
+
* Handles formats like "$1.50", "1.50", 1.50, etc.
|
|
81
|
+
*
|
|
82
|
+
* @param money - The money value to parse
|
|
83
|
+
* @returns Decimal number
|
|
84
|
+
*/
|
|
85
|
+
parseMoneyToDecimal(money) {
|
|
86
|
+
if (typeof money === "number") {
|
|
87
|
+
return money;
|
|
88
|
+
}
|
|
89
|
+
const cleanMoney = money.replace(/^\$/, "").trim();
|
|
90
|
+
const amount = parseFloat(cleanMoney);
|
|
91
|
+
if (isNaN(amount)) {
|
|
92
|
+
throw new Error(`Invalid money format: ${money}`);
|
|
93
|
+
}
|
|
94
|
+
return amount;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Default money conversion implementation.
|
|
98
|
+
* Converts decimal amount to USDC on the specified network.
|
|
99
|
+
*
|
|
100
|
+
* @param amount - The decimal amount (e.g., 1.50)
|
|
101
|
+
* @param network - The network to use
|
|
102
|
+
* @returns The parsed asset amount in USDC
|
|
103
|
+
*/
|
|
104
|
+
defaultMoneyConversion(amount, network) {
|
|
105
|
+
const tokenAmount = convertToTokenAmount(amount.toString(), 6);
|
|
106
|
+
return {
|
|
107
|
+
amount: tokenAmount,
|
|
108
|
+
asset: getUsdcAddress(network),
|
|
109
|
+
extra: {}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// src/exact/server/register.ts
|
|
115
|
+
function registerExactSvmScheme(server, config = {}) {
|
|
116
|
+
if (config.networks && config.networks.length > 0) {
|
|
117
|
+
config.networks.forEach((network) => {
|
|
118
|
+
server.register(network, new ExactSvmScheme());
|
|
119
|
+
});
|
|
120
|
+
} else {
|
|
121
|
+
server.register("solana:*", new ExactSvmScheme());
|
|
122
|
+
}
|
|
123
|
+
return server;
|
|
124
|
+
}
|
|
125
|
+
export {
|
|
126
|
+
ExactSvmScheme,
|
|
127
|
+
registerExactSvmScheme
|
|
128
|
+
};
|
|
129
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/exact/server/scheme.ts","../../../../src/exact/server/register.ts"],"sourcesContent":["import type {\n AssetAmount,\n Network,\n PaymentRequirements,\n Price,\n SchemeNetworkServer,\n MoneyParser,\n} from \"x402-core-mantle/types\";\nimport { convertToTokenAmount, getUsdcAddress } from \"../../utils\";\n\n/**\n * SVM server implementation for the Exact payment scheme.\n */\nexport class ExactSvmScheme implements SchemeNetworkServer {\n readonly scheme = \"exact\";\n private moneyParsers: MoneyParser[] = [];\n\n /**\n * Register a custom money parser in the parser chain.\n * Multiple parsers can be registered - they will be tried in registration order.\n * Each parser receives a decimal amount (e.g., 1.50 for $1.50).\n * If a parser returns null, the next parser in the chain will be tried.\n * The default parser is always the final fallback.\n *\n * @param parser - Custom function to convert amount to AssetAmount (or null to skip)\n * @returns The service instance for chaining\n */\n registerMoneyParser(parser: MoneyParser): ExactSvmScheme {\n this.moneyParsers.push(parser);\n return this;\n }\n\n /**\n * Parses a price into an asset amount.\n * If price is already an AssetAmount, returns it directly.\n * If price is Money (string | number), parses to decimal and tries custom parsers.\n * Falls back to default conversion if all custom parsers return null.\n *\n * @param price - The price to parse\n * @param network - The network to use\n * @returns Promise that resolves to the parsed asset amount\n */\n async parsePrice(price: Price, network: Network): Promise<AssetAmount> {\n // If already an AssetAmount, return it directly\n if (typeof price === \"object\" && price !== null && \"amount\" in price) {\n if (!price.asset) {\n throw new Error(`Asset address must be specified for AssetAmount on network ${network}`);\n }\n return {\n amount: price.amount,\n asset: price.asset,\n extra: price.extra || {},\n };\n }\n\n // Parse Money to decimal number\n const amount = this.parseMoneyToDecimal(price);\n\n // Try each custom money parser in order\n for (const parser of this.moneyParsers) {\n const result = await parser(amount, network);\n if (result !== null) {\n return result;\n }\n }\n\n // All custom parsers returned null, use default conversion\n return this.defaultMoneyConversion(amount, network);\n }\n\n /**\n * Build payment requirements for this scheme/network combination\n *\n * @param paymentRequirements - The base payment requirements\n * @param supportedKind - The supported kind configuration\n * @param supportedKind.x402Version - The x402 protocol version\n * @param supportedKind.scheme - The payment scheme\n * @param supportedKind.network - The network identifier\n * @param supportedKind.extra - Extra metadata including feePayer address\n * @param extensionKeys - Extension keys supported by the facilitator\n * @returns Enhanced payment requirements with feePayer in extra\n */\n enhancePaymentRequirements(\n paymentRequirements: PaymentRequirements,\n supportedKind: {\n x402Version: number;\n scheme: string;\n network: Network;\n extra?: Record<string, unknown>;\n },\n extensionKeys: string[],\n ): Promise<PaymentRequirements> {\n // Mark unused parameters to satisfy linter\n void extensionKeys;\n\n // Add feePayer from supportedKind.extra to payment requirements\n // The facilitator provides its address as the fee payer for transaction fees\n return Promise.resolve({\n ...paymentRequirements,\n extra: {\n ...paymentRequirements.extra,\n feePayer: supportedKind.extra?.feePayer,\n },\n });\n }\n\n /**\n * Parse Money (string | number) to a decimal number.\n * Handles formats like \"$1.50\", \"1.50\", 1.50, etc.\n *\n * @param money - The money value to parse\n * @returns Decimal number\n */\n private parseMoneyToDecimal(money: string | number): number {\n if (typeof money === \"number\") {\n return money;\n }\n\n // Remove $ sign and whitespace, then parse\n const cleanMoney = money.replace(/^\\$/, \"\").trim();\n const amount = parseFloat(cleanMoney);\n\n if (isNaN(amount)) {\n throw new Error(`Invalid money format: ${money}`);\n }\n\n return amount;\n }\n\n /**\n * Default money conversion implementation.\n * Converts decimal amount to USDC on the specified network.\n *\n * @param amount - The decimal amount (e.g., 1.50)\n * @param network - The network to use\n * @returns The parsed asset amount in USDC\n */\n private defaultMoneyConversion(amount: number, network: Network): AssetAmount {\n // Convert decimal amount to token amount (USDC has 6 decimals)\n const tokenAmount = convertToTokenAmount(amount.toString(), 6);\n\n return {\n amount: tokenAmount,\n asset: getUsdcAddress(network),\n extra: {},\n };\n }\n}\n","import { x402ResourceServer } from \"x402-core-mantle/server\";\nimport { Network } from \"x402-core-mantle/types\";\nimport { ExactSvmScheme } from \"./scheme\";\n\n/**\n * Configuration options for registering SVM schemes to an x402ResourceServer\n */\nexport interface SvmResourceServerConfig {\n /**\n * Optional specific networks to register\n */\n networks?: Network[];\n}\n\n/**\n * Registers SVM payment schemes to an existing x402ResourceServer instance.\n *\n * @param server - The x402ResourceServer instance to register schemes to\n * @param config - Configuration for SVM resource server registration\n * @returns The server instance for chaining\n */\nexport function registerExactSvmScheme(\n server: x402ResourceServer,\n config: SvmResourceServerConfig = {},\n): x402ResourceServer {\n if (config.networks && config.networks.length > 0) {\n config.networks.forEach(network => {\n server.register(network, new ExactSvmScheme());\n });\n } else {\n server.register(\"solana:*\", new ExactSvmScheme());\n }\n\n return server;\n}\n"],"mappings":";;;;;;AAaO,IAAM,iBAAN,MAAoD;AAAA,EAApD;AACL,SAAS,SAAS;AAClB,SAAQ,eAA8B,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYvC,oBAAoB,QAAqC;AACvD,SAAK,aAAa,KAAK,MAAM;AAC7B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,MAAM,WAAW,OAAc,SAAwC;AAErE,QAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,YAAY,OAAO;AACpE,UAAI,CAAC,MAAM,OAAO;AAChB,cAAM,IAAI,MAAM,8DAA8D,OAAO,EAAE;AAAA,MACzF;AACA,aAAO;AAAA,QACL,QAAQ,MAAM;AAAA,QACd,OAAO,MAAM;AAAA,QACb,OAAO,MAAM,SAAS,CAAC;AAAA,MACzB;AAAA,IACF;AAGA,UAAM,SAAS,KAAK,oBAAoB,KAAK;AAG7C,eAAW,UAAU,KAAK,cAAc;AACtC,YAAM,SAAS,MAAM,OAAO,QAAQ,OAAO;AAC3C,UAAI,WAAW,MAAM;AACnB,eAAO;AAAA,MACT;AAAA,IACF;AAGA,WAAO,KAAK,uBAAuB,QAAQ,OAAO;AAAA,EACpD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,2BACE,qBACA,eAMA,eAC8B;AAE9B,SAAK;AAIL,WAAO,QAAQ,QAAQ;AAAA,MACrB,GAAG;AAAA,MACH,OAAO;AAAA,QACL,GAAG,oBAAoB;AAAA,QACvB,UAAU,cAAc,OAAO;AAAA,MACjC;AAAA,IACF,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASQ,oBAAoB,OAAgC;AAC1D,QAAI,OAAO,UAAU,UAAU;AAC7B,aAAO;AAAA,IACT;AAGA,UAAM,aAAa,MAAM,QAAQ,OAAO,EAAE,EAAE,KAAK;AACjD,UAAM,SAAS,WAAW,UAAU;AAEpC,QAAI,MAAM,MAAM,GAAG;AACjB,YAAM,IAAI,MAAM,yBAAyB,KAAK,EAAE;AAAA,IAClD;AAEA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUQ,uBAAuB,QAAgB,SAA+B;AAE5E,UAAM,cAAc,qBAAqB,OAAO,SAAS,GAAG,CAAC;AAE7D,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,OAAO,eAAe,OAAO;AAAA,MAC7B,OAAO,CAAC;AAAA,IACV;AAAA,EACF;AACF;;;AC9HO,SAAS,uBACd,QACA,SAAkC,CAAC,GACf;AACpB,MAAI,OAAO,YAAY,OAAO,SAAS,SAAS,GAAG;AACjD,WAAO,SAAS,QAAQ,aAAW;AACjC,aAAO,SAAS,SAAS,IAAI,eAAe,CAAC;AAAA,IAC/C,CAAC;AAAA,EACH,OAAO;AACL,WAAO,SAAS,YAAY,IAAI,eAAe,CAAC;AAAA,EAClD;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { SchemeNetworkClient, PaymentRequirements, PaymentPayload, Network } from 'x402-core-mantle/types';
|
|
2
|
+
import { C as ClientSvmSigner, a as ClientSvmConfig } from '../../../signer-BMkbhFYE.mjs';
|
|
3
|
+
import '@solana/kit';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* SVM client implementation for the Exact payment scheme (V1).
|
|
7
|
+
*/
|
|
8
|
+
declare class ExactSvmSchemeV1 implements SchemeNetworkClient {
|
|
9
|
+
private readonly signer;
|
|
10
|
+
private readonly config?;
|
|
11
|
+
readonly scheme = "exact";
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new ExactSvmClientV1 instance.
|
|
14
|
+
*
|
|
15
|
+
* @param signer - The SVM signer for client operations
|
|
16
|
+
* @param config - Optional configuration with custom RPC URL
|
|
17
|
+
* @returns ExactSvmClientV1 instance
|
|
18
|
+
*/
|
|
19
|
+
constructor(signer: ClientSvmSigner, config?: ClientSvmConfig | undefined);
|
|
20
|
+
/**
|
|
21
|
+
* Creates a payment payload for the Exact scheme (V1).
|
|
22
|
+
*
|
|
23
|
+
* @param x402Version - The x402 protocol version
|
|
24
|
+
* @param paymentRequirements - The payment requirements
|
|
25
|
+
* @returns Promise resolving to a payment payload
|
|
26
|
+
*/
|
|
27
|
+
createPaymentPayload(x402Version: number, paymentRequirements: PaymentRequirements): Promise<Pick<PaymentPayload, "x402Version" | "payload"> & {
|
|
28
|
+
scheme: string;
|
|
29
|
+
network: Network;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { ExactSvmSchemeV1 };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { SchemeNetworkFacilitator, PaymentPayload, PaymentRequirements, VerifyResponse, SettleResponse } from 'x402-core-mantle/types';
|
|
2
|
+
import { F as FacilitatorSvmSigner } from '../../../signer-BMkbhFYE.mjs';
|
|
3
|
+
import '@solana/kit';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* SVM facilitator implementation for the Exact payment scheme (V1).
|
|
7
|
+
*/
|
|
8
|
+
declare class ExactSvmSchemeV1 implements SchemeNetworkFacilitator {
|
|
9
|
+
private readonly signer;
|
|
10
|
+
readonly scheme = "exact";
|
|
11
|
+
readonly caipFamily = "solana:*";
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new ExactSvmFacilitatorV1 instance.
|
|
14
|
+
*
|
|
15
|
+
* @param signer - The SVM RPC client for facilitator operations
|
|
16
|
+
* @returns ExactSvmFacilitatorV1 instance
|
|
17
|
+
*/
|
|
18
|
+
constructor(signer: FacilitatorSvmSigner);
|
|
19
|
+
/**
|
|
20
|
+
* Get mechanism-specific extra data for the supported kinds endpoint.
|
|
21
|
+
* For SVM, this includes a randomly selected fee payer address.
|
|
22
|
+
* Random selection distributes load across multiple signers.
|
|
23
|
+
*
|
|
24
|
+
* @param _ - The network identifier (unused for SVM)
|
|
25
|
+
* @returns Extra data with feePayer address
|
|
26
|
+
*/
|
|
27
|
+
getExtra(_: string): Record<string, unknown> | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Get signer addresses used by this facilitator.
|
|
30
|
+
* For SVM, returns all available fee payer addresses.
|
|
31
|
+
*
|
|
32
|
+
* @param _ - The network identifier (unused for SVM)
|
|
33
|
+
* @returns Array of fee payer addresses
|
|
34
|
+
*/
|
|
35
|
+
getSigners(_: string): string[];
|
|
36
|
+
/**
|
|
37
|
+
* Verifies a payment payload (V1).
|
|
38
|
+
*
|
|
39
|
+
* @param payload - The payment payload to verify
|
|
40
|
+
* @param requirements - The payment requirements
|
|
41
|
+
* @returns Promise resolving to verification response
|
|
42
|
+
*/
|
|
43
|
+
verify(payload: PaymentPayload, requirements: PaymentRequirements): Promise<VerifyResponse>;
|
|
44
|
+
/**
|
|
45
|
+
* Settles a payment by submitting the transaction (V1).
|
|
46
|
+
* Ensures the correct signer is used based on the feePayer specified in requirements.
|
|
47
|
+
*
|
|
48
|
+
* @param payload - The payment payload to settle
|
|
49
|
+
* @param requirements - The payment requirements
|
|
50
|
+
* @returns Promise resolving to settlement response
|
|
51
|
+
*/
|
|
52
|
+
settle(payload: PaymentPayload, requirements: PaymentRequirements): Promise<SettleResponse>;
|
|
53
|
+
/**
|
|
54
|
+
* Verify compute limit instruction
|
|
55
|
+
*
|
|
56
|
+
* @param instruction - The compute limit instruction
|
|
57
|
+
* @param instruction.programAddress - Program address
|
|
58
|
+
* @param instruction.data - Instruction data bytes
|
|
59
|
+
*/
|
|
60
|
+
private verifyComputeLimitInstruction;
|
|
61
|
+
/**
|
|
62
|
+
* Verify compute price instruction
|
|
63
|
+
*
|
|
64
|
+
* @param instruction - The compute price instruction
|
|
65
|
+
* @param instruction.programAddress - Program address
|
|
66
|
+
* @param instruction.data - Instruction data bytes
|
|
67
|
+
*/
|
|
68
|
+
private verifyComputePriceInstruction;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { ExactSvmSchemeV1 };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
export { E as ExactSvmScheme } from './scheme-VFikrqtD.mjs';
|
|
2
|
+
export { a as ClientSvmConfig, C as ClientSvmSigner, c as FacilitatorRpcClient, d as FacilitatorRpcConfig, F as FacilitatorSvmSigner, t as toClientSvmSigner, b as toFacilitatorSvmSigner } from './signer-BMkbhFYE.mjs';
|
|
3
|
+
import { Transaction, RpcDevnet, SolanaRpcApiDevnet, RpcTestnet, SolanaRpcApiTestnet, RpcMainnet, SolanaRpcApiMainnet } from '@solana/kit';
|
|
4
|
+
import { Network } from 'x402-core-mantle/types';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Exact SVM payload structure containing a base64 encoded Solana transaction
|
|
8
|
+
*/
|
|
9
|
+
type ExactSvmPayloadV1 = {
|
|
10
|
+
/**
|
|
11
|
+
* Base64 encoded Solana transaction
|
|
12
|
+
*/
|
|
13
|
+
transaction: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Exact SVM payload V2 structure (currently same as V1, reserved for future extensions)
|
|
17
|
+
*/
|
|
18
|
+
type ExactSvmPayloadV2 = ExactSvmPayloadV1;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Token program addresses for SPL Token and Token-2022
|
|
22
|
+
* These addresses are the same across all Solana networks (mainnet, devnet, testnet)
|
|
23
|
+
*/
|
|
24
|
+
declare const TOKEN_PROGRAM_ADDRESS = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
|
25
|
+
declare const TOKEN_2022_PROGRAM_ADDRESS = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
|
|
26
|
+
declare const COMPUTE_BUDGET_PROGRAM_ADDRESS = "ComputeBudget111111111111111111111111111111";
|
|
27
|
+
/**
|
|
28
|
+
* Default RPC URLs for Solana networks
|
|
29
|
+
*/
|
|
30
|
+
declare const DEVNET_RPC_URL = "https://api.devnet.solana.com";
|
|
31
|
+
declare const TESTNET_RPC_URL = "https://api.testnet.solana.com";
|
|
32
|
+
declare const MAINNET_RPC_URL = "https://api.mainnet-beta.solana.com";
|
|
33
|
+
declare const DEVNET_WS_URL = "wss://api.devnet.solana.com";
|
|
34
|
+
declare const TESTNET_WS_URL = "wss://api.testnet.solana.com";
|
|
35
|
+
declare const MAINNET_WS_URL = "wss://api.mainnet-beta.solana.com";
|
|
36
|
+
/**
|
|
37
|
+
* USDC token mint addresses (default stablecoin)
|
|
38
|
+
*/
|
|
39
|
+
declare const USDC_MAINNET_ADDRESS = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
40
|
+
declare const USDC_DEVNET_ADDRESS = "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU";
|
|
41
|
+
declare const USDC_TESTNET_ADDRESS = "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU";
|
|
42
|
+
/**
|
|
43
|
+
* Compute budget configuration
|
|
44
|
+
* All prices are in microlamports (1 lamport = 1,000,000 microlamports)
|
|
45
|
+
*/
|
|
46
|
+
declare const DEFAULT_COMPUTE_UNIT_PRICE_MICROLAMPORTS = 1;
|
|
47
|
+
declare const MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS = 5000000;
|
|
48
|
+
declare const DEFAULT_COMPUTE_UNIT_LIMIT = 6500;
|
|
49
|
+
/**
|
|
50
|
+
* Solana address validation regex (base58, 32-44 characters)
|
|
51
|
+
*/
|
|
52
|
+
declare const SVM_ADDRESS_REGEX: RegExp;
|
|
53
|
+
/**
|
|
54
|
+
* CAIP-2 network identifiers for Solana (V2)
|
|
55
|
+
*/
|
|
56
|
+
declare const SOLANA_MAINNET_CAIP2 = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
57
|
+
declare const SOLANA_DEVNET_CAIP2 = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
|
|
58
|
+
declare const SOLANA_TESTNET_CAIP2 = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z";
|
|
59
|
+
/**
|
|
60
|
+
* V1 to V2 network identifier mappings (for backwards compatibility)
|
|
61
|
+
* V1 used simple names like solana, V2 uses CAIP-2
|
|
62
|
+
*/
|
|
63
|
+
declare const V1_TO_V2_NETWORK_MAP: Record<string, string>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Normalize network identifier to CAIP-2 format
|
|
67
|
+
* Handles both V1 names (solana, solana-devnet) and V2 CAIP-2 format
|
|
68
|
+
*
|
|
69
|
+
* @param network - Network identifier (V1 or V2 format)
|
|
70
|
+
* @returns CAIP-2 network identifier
|
|
71
|
+
*/
|
|
72
|
+
declare function normalizeNetwork(network: Network): string;
|
|
73
|
+
/**
|
|
74
|
+
* Validate Solana address format
|
|
75
|
+
*
|
|
76
|
+
* @param address - Base58 encoded address string
|
|
77
|
+
* @returns true if address is valid, false otherwise
|
|
78
|
+
*/
|
|
79
|
+
declare function validateSvmAddress(address: string): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Decode a base64 encoded transaction from an SVM payload
|
|
82
|
+
*
|
|
83
|
+
* @param svmPayload - The SVM payload containing a base64 encoded transaction
|
|
84
|
+
* @returns Decoded Transaction object
|
|
85
|
+
*/
|
|
86
|
+
declare function decodeTransactionFromPayload(svmPayload: ExactSvmPayloadV1): Transaction;
|
|
87
|
+
/**
|
|
88
|
+
* Extract the token sender (owner of the source token account) from a TransferChecked instruction
|
|
89
|
+
*
|
|
90
|
+
* @param transaction - The decoded transaction
|
|
91
|
+
* @returns The token payer address as a base58 string
|
|
92
|
+
*/
|
|
93
|
+
declare function getTokenPayerFromTransaction(transaction: Transaction): string;
|
|
94
|
+
/**
|
|
95
|
+
* Create an RPC client for the specified network
|
|
96
|
+
*
|
|
97
|
+
* @param network - Network identifier (CAIP-2 or V1 format)
|
|
98
|
+
* @param customRpcUrl - Optional custom RPC URL
|
|
99
|
+
* @returns RPC client for the specified network
|
|
100
|
+
*/
|
|
101
|
+
declare function createRpcClient(network: Network, customRpcUrl?: string): RpcDevnet<SolanaRpcApiDevnet> | RpcTestnet<SolanaRpcApiTestnet> | RpcMainnet<SolanaRpcApiMainnet>;
|
|
102
|
+
/**
|
|
103
|
+
* Get the default USDC mint address for a network
|
|
104
|
+
*
|
|
105
|
+
* @param network - Network identifier (CAIP-2 or V1 format)
|
|
106
|
+
* @returns USDC mint address for the network
|
|
107
|
+
*/
|
|
108
|
+
declare function getUsdcAddress(network: Network): string;
|
|
109
|
+
/**
|
|
110
|
+
* Convert a decimal amount to token smallest units
|
|
111
|
+
*
|
|
112
|
+
* @param decimalAmount - The decimal amount (e.g., "0.10")
|
|
113
|
+
* @param decimals - The number of decimals for the token (e.g., 6 for USDC)
|
|
114
|
+
* @returns The amount in smallest units as a string
|
|
115
|
+
*/
|
|
116
|
+
declare function convertToTokenAmount(decimalAmount: string, decimals: number): string;
|
|
117
|
+
|
|
118
|
+
export { COMPUTE_BUDGET_PROGRAM_ADDRESS, DEFAULT_COMPUTE_UNIT_LIMIT, DEFAULT_COMPUTE_UNIT_PRICE_MICROLAMPORTS, DEVNET_RPC_URL, DEVNET_WS_URL, type ExactSvmPayloadV1, type ExactSvmPayloadV2, MAINNET_RPC_URL, MAINNET_WS_URL, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SOLANA_DEVNET_CAIP2, SOLANA_MAINNET_CAIP2, SOLANA_TESTNET_CAIP2, SVM_ADDRESS_REGEX, TESTNET_RPC_URL, TESTNET_WS_URL, TOKEN_2022_PROGRAM_ADDRESS, TOKEN_PROGRAM_ADDRESS, USDC_DEVNET_ADDRESS, USDC_MAINNET_ADDRESS, USDC_TESTNET_ADDRESS, V1_TO_V2_NETWORK_MAP, convertToTokenAmount, createRpcClient, decodeTransactionFromPayload, getTokenPayerFromTransaction, getUsdcAddress, normalizeNetwork, validateSvmAddress };
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ExactSvmScheme
|
|
3
|
+
} from "./chunk-TA6OPUHK.mjs";
|
|
4
|
+
import {
|
|
5
|
+
COMPUTE_BUDGET_PROGRAM_ADDRESS,
|
|
6
|
+
DEFAULT_COMPUTE_UNIT_LIMIT,
|
|
7
|
+
DEFAULT_COMPUTE_UNIT_PRICE_MICROLAMPORTS,
|
|
8
|
+
DEVNET_RPC_URL,
|
|
9
|
+
DEVNET_WS_URL,
|
|
10
|
+
MAINNET_RPC_URL,
|
|
11
|
+
MAINNET_WS_URL,
|
|
12
|
+
MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS,
|
|
13
|
+
SOLANA_DEVNET_CAIP2,
|
|
14
|
+
SOLANA_MAINNET_CAIP2,
|
|
15
|
+
SOLANA_TESTNET_CAIP2,
|
|
16
|
+
SVM_ADDRESS_REGEX,
|
|
17
|
+
TESTNET_RPC_URL,
|
|
18
|
+
TESTNET_WS_URL,
|
|
19
|
+
TOKEN_2022_PROGRAM_ADDRESS,
|
|
20
|
+
TOKEN_PROGRAM_ADDRESS,
|
|
21
|
+
USDC_DEVNET_ADDRESS,
|
|
22
|
+
USDC_MAINNET_ADDRESS,
|
|
23
|
+
USDC_TESTNET_ADDRESS,
|
|
24
|
+
V1_TO_V2_NETWORK_MAP,
|
|
25
|
+
convertToTokenAmount,
|
|
26
|
+
createRpcClient,
|
|
27
|
+
decodeTransactionFromPayload,
|
|
28
|
+
getTokenPayerFromTransaction,
|
|
29
|
+
getUsdcAddress,
|
|
30
|
+
normalizeNetwork,
|
|
31
|
+
validateSvmAddress
|
|
32
|
+
} from "./chunk-PHFXLBH6.mjs";
|
|
33
|
+
|
|
34
|
+
// src/signer.ts
|
|
35
|
+
import { getBase64EncodedWireTransaction } from "@solana/kit";
|
|
36
|
+
function toClientSvmSigner(signer) {
|
|
37
|
+
return signer;
|
|
38
|
+
}
|
|
39
|
+
function createRpcCapabilitiesFromRpc(rpc) {
|
|
40
|
+
return {
|
|
41
|
+
getBalance: async (address) => {
|
|
42
|
+
const result = await rpc.getBalance(address).send();
|
|
43
|
+
return result.value;
|
|
44
|
+
},
|
|
45
|
+
getTokenAccountBalance: async (address) => {
|
|
46
|
+
const accountInfo = await rpc.getAccountInfo(address, {
|
|
47
|
+
encoding: "jsonParsed"
|
|
48
|
+
}).send();
|
|
49
|
+
if (!accountInfo.value) {
|
|
50
|
+
throw new Error(`Token account not found: ${address}`);
|
|
51
|
+
}
|
|
52
|
+
const parsed = accountInfo.value.data;
|
|
53
|
+
return BigInt(parsed.parsed.info.tokenAmount.amount);
|
|
54
|
+
},
|
|
55
|
+
getLatestBlockhash: async () => {
|
|
56
|
+
const result = await rpc.getLatestBlockhash().send();
|
|
57
|
+
return {
|
|
58
|
+
blockhash: result.value.blockhash,
|
|
59
|
+
lastValidBlockHeight: result.value.lastValidBlockHeight
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
simulateTransaction: async (transaction, config) => {
|
|
63
|
+
return await rpc.simulateTransaction(transaction, config).send();
|
|
64
|
+
},
|
|
65
|
+
sendTransaction: async (transaction) => {
|
|
66
|
+
return await rpc.sendTransaction(transaction, {
|
|
67
|
+
encoding: "base64"
|
|
68
|
+
}).send();
|
|
69
|
+
},
|
|
70
|
+
confirmTransaction: async (signature) => {
|
|
71
|
+
let confirmed = false;
|
|
72
|
+
let attempts = 0;
|
|
73
|
+
const maxAttempts = 30;
|
|
74
|
+
while (!confirmed && attempts < maxAttempts) {
|
|
75
|
+
const status = await rpc.getSignatureStatuses([signature]).send();
|
|
76
|
+
if (status.value[0]?.confirmationStatus === "confirmed" || status.value[0]?.confirmationStatus === "finalized") {
|
|
77
|
+
confirmed = true;
|
|
78
|
+
return status.value[0];
|
|
79
|
+
}
|
|
80
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
81
|
+
attempts++;
|
|
82
|
+
}
|
|
83
|
+
throw new Error("Transaction confirmation timeout");
|
|
84
|
+
},
|
|
85
|
+
fetchMint: async (address) => {
|
|
86
|
+
const { fetchMint } = await import("@solana-program/token-2022");
|
|
87
|
+
return await fetchMint(rpc, address);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function toFacilitatorSvmSigner(signer, rpcConfig) {
|
|
92
|
+
let rpcMap = {};
|
|
93
|
+
let defaultRpcUrl;
|
|
94
|
+
if (rpcConfig) {
|
|
95
|
+
if ("defaultRpcUrl" in rpcConfig && typeof rpcConfig.defaultRpcUrl === "string") {
|
|
96
|
+
defaultRpcUrl = rpcConfig.defaultRpcUrl;
|
|
97
|
+
} else if ("getBalance" in rpcConfig || "getSlot" in rpcConfig) {
|
|
98
|
+
rpcMap["*"] = rpcConfig;
|
|
99
|
+
} else {
|
|
100
|
+
rpcMap = rpcConfig;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const getRpcForNetwork = (network) => {
|
|
104
|
+
if (rpcMap[network]) {
|
|
105
|
+
return rpcMap[network];
|
|
106
|
+
}
|
|
107
|
+
if (rpcMap["*"]) {
|
|
108
|
+
return rpcMap["*"];
|
|
109
|
+
}
|
|
110
|
+
return createRpcClient(network, defaultRpcUrl);
|
|
111
|
+
};
|
|
112
|
+
return {
|
|
113
|
+
getAddresses: () => {
|
|
114
|
+
return [signer.address];
|
|
115
|
+
},
|
|
116
|
+
signTransaction: async (transaction, feePayer, _) => {
|
|
117
|
+
if (feePayer !== signer.address) {
|
|
118
|
+
throw new Error(`No signer for feePayer ${feePayer}. Available: ${signer.address}`);
|
|
119
|
+
}
|
|
120
|
+
const tx = decodeTransactionFromPayload({ transaction });
|
|
121
|
+
const signableMessage = {
|
|
122
|
+
content: tx.messageBytes,
|
|
123
|
+
signatures: tx.signatures
|
|
124
|
+
};
|
|
125
|
+
const [facilitatorSignatureDictionary] = await signer.signMessages([
|
|
126
|
+
signableMessage
|
|
127
|
+
]);
|
|
128
|
+
const fullySignedTx = {
|
|
129
|
+
...tx,
|
|
130
|
+
signatures: {
|
|
131
|
+
...tx.signatures,
|
|
132
|
+
...facilitatorSignatureDictionary
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
return getBase64EncodedWireTransaction(fullySignedTx);
|
|
136
|
+
},
|
|
137
|
+
simulateTransaction: async (transaction, network) => {
|
|
138
|
+
const rpc = getRpcForNetwork(network);
|
|
139
|
+
const result = await rpc.simulateTransaction(transaction, {
|
|
140
|
+
sigVerify: true,
|
|
141
|
+
replaceRecentBlockhash: false,
|
|
142
|
+
commitment: "confirmed",
|
|
143
|
+
encoding: "base64"
|
|
144
|
+
}).send();
|
|
145
|
+
if (result.value.err) {
|
|
146
|
+
const errorStr = JSON.stringify(
|
|
147
|
+
result.value.err,
|
|
148
|
+
(_, v) => typeof v === "bigint" ? v.toString() : v
|
|
149
|
+
);
|
|
150
|
+
throw new Error(`Simulation failed: ${errorStr}`);
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
sendTransaction: async (transaction, network) => {
|
|
154
|
+
const rpc = getRpcForNetwork(network);
|
|
155
|
+
return await rpc.sendTransaction(transaction, {
|
|
156
|
+
encoding: "base64"
|
|
157
|
+
}).send();
|
|
158
|
+
},
|
|
159
|
+
confirmTransaction: async (signature, network) => {
|
|
160
|
+
const rpc = getRpcForNetwork(network);
|
|
161
|
+
const rpcCapabilities = createRpcCapabilitiesFromRpc(rpc);
|
|
162
|
+
await rpcCapabilities.confirmTransaction(signature);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
export {
|
|
167
|
+
COMPUTE_BUDGET_PROGRAM_ADDRESS,
|
|
168
|
+
DEFAULT_COMPUTE_UNIT_LIMIT,
|
|
169
|
+
DEFAULT_COMPUTE_UNIT_PRICE_MICROLAMPORTS,
|
|
170
|
+
DEVNET_RPC_URL,
|
|
171
|
+
DEVNET_WS_URL,
|
|
172
|
+
ExactSvmScheme,
|
|
173
|
+
MAINNET_RPC_URL,
|
|
174
|
+
MAINNET_WS_URL,
|
|
175
|
+
MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS,
|
|
176
|
+
SOLANA_DEVNET_CAIP2,
|
|
177
|
+
SOLANA_MAINNET_CAIP2,
|
|
178
|
+
SOLANA_TESTNET_CAIP2,
|
|
179
|
+
SVM_ADDRESS_REGEX,
|
|
180
|
+
TESTNET_RPC_URL,
|
|
181
|
+
TESTNET_WS_URL,
|
|
182
|
+
TOKEN_2022_PROGRAM_ADDRESS,
|
|
183
|
+
TOKEN_PROGRAM_ADDRESS,
|
|
184
|
+
USDC_DEVNET_ADDRESS,
|
|
185
|
+
USDC_MAINNET_ADDRESS,
|
|
186
|
+
USDC_TESTNET_ADDRESS,
|
|
187
|
+
V1_TO_V2_NETWORK_MAP,
|
|
188
|
+
convertToTokenAmount,
|
|
189
|
+
createRpcClient,
|
|
190
|
+
decodeTransactionFromPayload,
|
|
191
|
+
getTokenPayerFromTransaction,
|
|
192
|
+
getUsdcAddress,
|
|
193
|
+
normalizeNetwork,
|
|
194
|
+
toClientSvmSigner,
|
|
195
|
+
toFacilitatorSvmSigner,
|
|
196
|
+
validateSvmAddress
|
|
197
|
+
};
|
|
198
|
+
//# sourceMappingURL=index.mjs.map
|