cryptoiz-mcp 4.15.4 → 4.15.5
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/index.js +38 -38
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprot
|
|
|
9
9
|
import { Connection, Keypair, PublicKey, Transaction, SystemProgram, VersionedTransaction, TransactionMessage } from '@solana/web3.js';
|
|
10
10
|
import bs58 from 'bs58';
|
|
11
11
|
|
|
12
|
-
var VERSION = 'v4.15.
|
|
12
|
+
var VERSION = 'v4.15.5';
|
|
13
13
|
var GATEWAY = 'https://rehqwsypjnjirhuiapqh.supabase.co/functions/v1/mcp-x402-gateway';
|
|
14
14
|
var RECIPIENT = 'DsKmdkYx49Xc1WhqMUAztwhdYPTqieyC98VmnnJdgpXX';
|
|
15
15
|
var USDC_MINT = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';
|
|
@@ -41,9 +41,14 @@ function findATA(wallet, mint) {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// ===== V2: Build partially-signed tx for Dexter facilitator =====
|
|
44
|
-
//
|
|
45
|
-
// Tx MUST contain
|
|
44
|
+
// Reference: @x402/svm exact/client/scheme.ts (Coinbase reference SDK)
|
|
45
|
+
// Tx MUST contain exactly 4 instructions in this order:
|
|
46
|
+
// 1. SetComputeUnitLimit (20000)
|
|
47
|
+
// 2. SetComputeUnitPrice (1 microLamport)
|
|
48
|
+
// 3. TransferChecked (SPL Token)
|
|
49
|
+
// 4. Memo (random 16-byte nonce hex)
|
|
46
50
|
var COMPUTE_BUDGET_PROGRAM = 'ComputeBudget111111111111111111111111111111';
|
|
51
|
+
var MEMO_PROGRAM = 'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr';
|
|
47
52
|
|
|
48
53
|
async function buildV2PaymentPayload(amount, feePayerAddr) {
|
|
49
54
|
var kp = getKeypair();
|
|
@@ -53,62 +58,59 @@ async function buildV2PaymentPayload(amount, feePayerAddr) {
|
|
|
53
58
|
var recipientATA = findATA(RECIPIENT, USDC_MINT);
|
|
54
59
|
var feePayerPk = new PublicKey(feePayerAddr);
|
|
55
60
|
var computeBudgetPk = new PublicKey(COMPUTE_BUDGET_PROGRAM);
|
|
61
|
+
var memoProgramPk = new PublicKey(MEMO_PROGRAM);
|
|
62
|
+
var tokenProgramPk = new PublicKey(TOKEN_PROGRAM);
|
|
63
|
+
var usdcMintPk = new PublicKey(USDC_MINT);
|
|
56
64
|
|
|
57
|
-
// Instruction 1: SetComputeUnitLimit
|
|
65
|
+
// Instruction 1: SetComputeUnitLimit = 20000 (per @x402/svm constants)
|
|
58
66
|
var setLimitData = Buffer.alloc(5);
|
|
59
67
|
setLimitData.writeUInt8(2, 0);
|
|
60
|
-
setLimitData.writeUInt32LE(
|
|
61
|
-
var setLimitIx = {
|
|
62
|
-
programId: computeBudgetPk,
|
|
63
|
-
keys: [],
|
|
64
|
-
data: setLimitData,
|
|
65
|
-
};
|
|
68
|
+
setLimitData.writeUInt32LE(20000, 1);
|
|
69
|
+
var setLimitIx = { programId: computeBudgetPk, keys: [], data: setLimitData };
|
|
66
70
|
|
|
67
|
-
// Instruction 2: SetComputeUnitPrice
|
|
71
|
+
// Instruction 2: SetComputeUnitPrice = 1 microLamport (per @x402/svm constants)
|
|
68
72
|
var setPriceData = Buffer.alloc(9);
|
|
69
73
|
setPriceData.writeUInt8(3, 0);
|
|
70
|
-
setPriceData.writeUInt32LE(
|
|
74
|
+
setPriceData.writeUInt32LE(1, 1);
|
|
71
75
|
setPriceData.writeUInt32LE(0, 5);
|
|
72
|
-
var setPriceIx = {
|
|
73
|
-
programId: computeBudgetPk,
|
|
74
|
-
keys: [],
|
|
75
|
-
data: setPriceData,
|
|
76
|
-
};
|
|
76
|
+
var setPriceIx = { programId: computeBudgetPk, keys: [], data: setPriceData };
|
|
77
77
|
|
|
78
|
-
// Instruction 3:
|
|
79
|
-
//
|
|
80
|
-
// Accounts: [source_ata, mint, destination_ata, authority]
|
|
81
|
-
// Data: [12, amount_u64_LE, decimals_u8]
|
|
82
|
-
var tokenProgramPk = new PublicKey(TOKEN_PROGRAM);
|
|
83
|
-
var usdcMintPk = new PublicKey(USDC_MINT);
|
|
78
|
+
// Instruction 3: TransferChecked (SPL Token)
|
|
79
|
+
// Accounts order: [source, mint, destination, authority]
|
|
84
80
|
var transferKeys = [
|
|
85
81
|
{ pubkey: userATA, isSigner: false, isWritable: true },
|
|
86
82
|
{ pubkey: usdcMintPk, isSigner: false, isWritable: false },
|
|
87
83
|
{ pubkey: recipientATA, isSigner: false, isWritable: true },
|
|
88
84
|
{ pubkey: kp.publicKey, isSigner: true, isWritable: false },
|
|
89
85
|
];
|
|
90
|
-
// TransferChecked data: instruction_index(1) + amount_u64(8) + decimals(1) = 10 bytes
|
|
91
86
|
var transferData = Buffer.alloc(10);
|
|
92
|
-
transferData.writeUInt8(12, 0); // TransferChecked instruction index
|
|
87
|
+
transferData.writeUInt8(12, 0); // TransferChecked = instruction index 12
|
|
93
88
|
var lo = amount & 0xFFFFFFFF;
|
|
94
89
|
var hi = Math.floor(amount / 0x100000000) & 0xFFFFFFFF;
|
|
95
90
|
transferData.writeUInt32LE(lo, 1);
|
|
96
91
|
transferData.writeUInt32LE(hi, 5);
|
|
97
92
|
transferData.writeUInt8(6, 9); // USDC decimals = 6
|
|
98
|
-
var transferIx = {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
93
|
+
var transferIx = { programId: tokenProgramPk, keys: transferKeys, data: transferData };
|
|
94
|
+
|
|
95
|
+
// Instruction 4: Memo with random 16-byte nonce (per @x402/svm reference)
|
|
96
|
+
var nonceBytes = new Uint8Array(16);
|
|
97
|
+
for (var i = 0; i < 16; i++) { nonceBytes[i] = Math.floor(Math.random() * 256); }
|
|
98
|
+
var nonceHex = '';
|
|
99
|
+
for (var j = 0; j < 16; j++) {
|
|
100
|
+
var h = nonceBytes[j].toString(16);
|
|
101
|
+
nonceHex = nonceHex + (h.length < 2 ? '0' + h : h);
|
|
102
|
+
}
|
|
103
|
+
var memoData = Buffer.from(nonceHex, 'utf8');
|
|
104
|
+
var memoIx = { programId: memoProgramPk, keys: [], data: memoData };
|
|
103
105
|
|
|
104
106
|
// Get recent blockhash
|
|
105
107
|
var bhResult = await conn.getLatestBlockhash('confirmed');
|
|
106
108
|
|
|
107
|
-
// Build V0 message: feePayer = Dexter,
|
|
109
|
+
// Build V0 message: feePayer = Dexter, 4 instructions in spec order
|
|
108
110
|
var message = new TransactionMessage({
|
|
109
111
|
payerKey: feePayerPk,
|
|
110
112
|
recentBlockhash: bhResult.blockhash,
|
|
111
|
-
instructions: [setLimitIx, setPriceIx, transferIx],
|
|
113
|
+
instructions: [setLimitIx, setPriceIx, transferIx, memoIx],
|
|
112
114
|
}).compileToV0Message();
|
|
113
115
|
|
|
114
116
|
var vtx = new VersionedTransaction(message);
|
|
@@ -119,7 +121,7 @@ async function buildV2PaymentPayload(amount, feePayerAddr) {
|
|
|
119
121
|
var serialized = vtx.serialize();
|
|
120
122
|
var txB64 = Buffer.from(serialized).toString('base64');
|
|
121
123
|
|
|
122
|
-
console.error('[cryptoiz-mcp] V2 tx
|
|
124
|
+
console.error('[cryptoiz-mcp] V2 tx: 4 ix (Limit=20000 + Price=1 + TransferChecked + Memo), feePayer=' + feePayerAddr.substring(0, 8) + '..., nonce=' + nonceHex.substring(0, 8) + '...');
|
|
123
125
|
return txB64;
|
|
124
126
|
}
|
|
125
127
|
|
|
@@ -237,17 +239,15 @@ async function callTool(toolName, args) {
|
|
|
237
239
|
var headerName = '';
|
|
238
240
|
|
|
239
241
|
if (useV2 && paymentRequirements.extra && paymentRequirements.extra.feePayer) {
|
|
240
|
-
// V2: Build partially-signed tx, Dexter pays gas
|
|
242
|
+
// V2: Build partially-signed tx with 4 instructions, Dexter pays gas
|
|
241
243
|
var v2FeePayer = paymentRequirements.extra.feePayer;
|
|
242
|
-
console.error('[cryptoiz-mcp] V2 mode:
|
|
244
|
+
console.error('[cryptoiz-mcp] V2 mode: 4-ix tx (Limit+Price+TransferChecked+Memo), feePayer=' + v2FeePayer.substring(0, 8) + '...');
|
|
243
245
|
try {
|
|
244
246
|
var txB64 = await buildV2PaymentPayload(amount, v2FeePayer);
|
|
245
247
|
|
|
246
|
-
//
|
|
248
|
+
// Payload format per @x402/svm reference: only x402Version + payload.transaction
|
|
247
249
|
var v2Payload = {
|
|
248
250
|
x402Version: 2,
|
|
249
|
-
scheme: 'exact',
|
|
250
|
-
network: paymentRequirements.network || 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
|
|
251
251
|
payload: {
|
|
252
252
|
transaction: txB64,
|
|
253
253
|
},
|
package/package.json
CHANGED