@subly_fi/pay 0.1.0 → 0.2.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/deposit.js +23 -33
- package/dist/mcp-server.js +490 -663
- package/dist/pay.js +22 -22
- package/dist/withdraw.js +22 -32
- package/package.json +4 -2
package/dist/pay.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
//
|
|
1
|
+
// demo/pay.ts
|
|
2
2
|
import { readFileSync as readFileSync2, writeFileSync } from "node:fs";
|
|
3
3
|
|
|
4
|
-
//
|
|
4
|
+
// src/client/agent-wallet-signer.ts
|
|
5
5
|
import { signBytes } from "@solana/kit";
|
|
6
6
|
import bs584 from "bs58";
|
|
7
7
|
|
|
8
|
-
//
|
|
8
|
+
// src/solana/tx.ts
|
|
9
9
|
import bs58 from "bs58";
|
|
10
10
|
import {
|
|
11
11
|
appendTransactionMessageInstructions,
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
setTransactionMessageLifetimeUsingBlockhash
|
|
21
21
|
} from "@solana/kit";
|
|
22
22
|
|
|
23
|
-
//
|
|
23
|
+
// src/lib/hash.ts
|
|
24
24
|
import { createHash } from "node:crypto";
|
|
25
25
|
var EMPTY_BODY_HASH = "sha256-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
|
|
26
26
|
function sha256TaggedHex(data) {
|
|
@@ -46,7 +46,7 @@ function hashStableJson(value) {
|
|
|
46
46
|
return sha256TaggedHex(stableStringify(value));
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
//
|
|
49
|
+
// src/solana/tx.ts
|
|
50
50
|
function decodeSerializedTransaction(serializedBase64) {
|
|
51
51
|
return getTransactionDecoder().decode(Buffer.from(serializedBase64, "base64"));
|
|
52
52
|
}
|
|
@@ -66,11 +66,11 @@ function signatureBase58ForSigner(transaction, signer2) {
|
|
|
66
66
|
return bs58.encode(signature);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
//
|
|
69
|
+
// src/client/transaction-intent-validator.ts
|
|
70
70
|
import bs583 from "bs58";
|
|
71
71
|
import { getCompiledTransactionMessageDecoder } from "@solana/kit";
|
|
72
72
|
|
|
73
|
-
//
|
|
73
|
+
// src/config/constants.ts
|
|
74
74
|
var PAYMENT_SCHEME = "subly-yield-exact";
|
|
75
75
|
var SOLANA_MAINNET_NETWORK = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
76
76
|
var SPL_TOKEN_PROGRAM_ID = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
|
@@ -86,7 +86,7 @@ var SUBLY_VAULT = {
|
|
|
86
86
|
};
|
|
87
87
|
var USDC_DECIMALS = 6;
|
|
88
88
|
|
|
89
|
-
//
|
|
89
|
+
// src/domain/request-binding.ts
|
|
90
90
|
function computeRequestBindingHash(fields) {
|
|
91
91
|
return hashStableJson({
|
|
92
92
|
sellerRequestId: fields.sellerRequestId,
|
|
@@ -101,7 +101,7 @@ function computeRequestBindingHash(fields) {
|
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
//
|
|
104
|
+
// src/lib/associated-token-account.ts
|
|
105
105
|
import { createHash as createHash2 } from "node:crypto";
|
|
106
106
|
import bs582 from "bs58";
|
|
107
107
|
var PDA_MARKER = Buffer.from("ProgramDerivedAddress", "utf8");
|
|
@@ -193,7 +193,7 @@ function modPow(base, exponent, modulus) {
|
|
|
193
193
|
return result;
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
//
|
|
196
|
+
// src/client/transaction-intent-validator.ts
|
|
197
197
|
var COMPUTE_BUDGET_PROGRAM_ID = "ComputeBudget111111111111111111111111111111";
|
|
198
198
|
var SYSTEM_PROGRAM_ID = "11111111111111111111111111111111";
|
|
199
199
|
var ASSOCIATED_TOKEN_PROGRAM_ID2 = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
|
|
@@ -879,7 +879,7 @@ function readShortVec(bytes, startOffset) {
|
|
|
879
879
|
return null;
|
|
880
880
|
}
|
|
881
881
|
|
|
882
|
-
//
|
|
882
|
+
// src/client/agent-wallet-signer.ts
|
|
883
883
|
var LocalKeypairAgentWalletSigner = class {
|
|
884
884
|
validationMode = "structured_intent_transaction";
|
|
885
885
|
keyPairSigner;
|
|
@@ -949,7 +949,7 @@ var LocalKeypairAgentWalletSigner = class {
|
|
|
949
949
|
}
|
|
950
950
|
};
|
|
951
951
|
|
|
952
|
-
//
|
|
952
|
+
// src/client/lookup-tables.ts
|
|
953
953
|
import { fetchAllMaybeAddressLookupTable } from "@solana-program/address-lookup-table";
|
|
954
954
|
import { address, getCompiledTransactionMessageDecoder as getCompiledTransactionMessageDecoder2 } from "@solana/kit";
|
|
955
955
|
function lookupTableAddressesForTransaction(serializedTransaction) {
|
|
@@ -989,7 +989,7 @@ async function fetchLookupTablesForTransaction(rpc2, serializedTransaction) {
|
|
|
989
989
|
return result;
|
|
990
990
|
}
|
|
991
991
|
|
|
992
|
-
//
|
|
992
|
+
// src/api/wallet-auth.ts
|
|
993
993
|
import { createHash as createHash3 } from "node:crypto";
|
|
994
994
|
import bs585 from "bs58";
|
|
995
995
|
import nacl from "tweetnacl";
|
|
@@ -1007,7 +1007,7 @@ function walletAuthMessage(params) {
|
|
|
1007
1007
|
);
|
|
1008
1008
|
}
|
|
1009
1009
|
|
|
1010
|
-
//
|
|
1010
|
+
// src/client/wallet-auth-headers.ts
|
|
1011
1011
|
async function walletAuthHeaders(params) {
|
|
1012
1012
|
const signedAtMs = String(Date.now());
|
|
1013
1013
|
const message = walletAuthMessage({
|
|
@@ -1023,7 +1023,7 @@ async function walletAuthHeaders(params) {
|
|
|
1023
1023
|
};
|
|
1024
1024
|
}
|
|
1025
1025
|
|
|
1026
|
-
//
|
|
1026
|
+
// src/client/onboarding.ts
|
|
1027
1027
|
var SELF_SERVE_POLICY_ID = "self-serve";
|
|
1028
1028
|
var OnboardingError = class extends Error {
|
|
1029
1029
|
constructor(step, message, detail = null) {
|
|
@@ -1080,7 +1080,7 @@ async function ensureWalletOnboarded(params) {
|
|
|
1080
1080
|
await post("sync", `/v1/wallets/${wallet}/sync`, { source: "chain" });
|
|
1081
1081
|
}
|
|
1082
1082
|
|
|
1083
|
-
//
|
|
1083
|
+
// src/x402/headers.ts
|
|
1084
1084
|
import { z } from "zod";
|
|
1085
1085
|
var PAYMENT_REQUIRED_HEADER = "payment-required";
|
|
1086
1086
|
var PAYMENT_SIGNATURE_HEADER = "payment-signature";
|
|
@@ -1182,7 +1182,7 @@ function requestBodyHashFor(body) {
|
|
|
1182
1182
|
);
|
|
1183
1183
|
}
|
|
1184
1184
|
|
|
1185
|
-
//
|
|
1185
|
+
// src/client/paid-fetch.ts
|
|
1186
1186
|
var PaidFetchError = class extends Error {
|
|
1187
1187
|
constructor(reason, message, detail = null) {
|
|
1188
1188
|
super(message);
|
|
@@ -1436,7 +1436,7 @@ function receiptTransaction(headers) {
|
|
|
1436
1436
|
}
|
|
1437
1437
|
}
|
|
1438
1438
|
|
|
1439
|
-
//
|
|
1439
|
+
// src/solana/keys.ts
|
|
1440
1440
|
import { readFileSync } from "node:fs";
|
|
1441
1441
|
import bs586 from "bs58";
|
|
1442
1442
|
import {
|
|
@@ -1461,13 +1461,13 @@ async function loadKeyPairSigner(params) {
|
|
|
1461
1461
|
throw new Error(`${label} keypair is not configured`);
|
|
1462
1462
|
}
|
|
1463
1463
|
|
|
1464
|
-
//
|
|
1464
|
+
// src/solana/rpc.ts
|
|
1465
1465
|
import { createSolanaRpc } from "@solana/kit";
|
|
1466
1466
|
function createRpc(url2) {
|
|
1467
1467
|
return createSolanaRpc(url2);
|
|
1468
1468
|
}
|
|
1469
1469
|
|
|
1470
|
-
//
|
|
1470
|
+
// src/x402/client.ts
|
|
1471
1471
|
var X402ClientError = class extends Error {
|
|
1472
1472
|
reason;
|
|
1473
1473
|
detail;
|
|
@@ -1642,13 +1642,13 @@ var SublyX402Client = class {
|
|
|
1642
1642
|
}
|
|
1643
1643
|
};
|
|
1644
1644
|
|
|
1645
|
-
//
|
|
1645
|
+
// demo/shared.ts
|
|
1646
1646
|
function fail(message) {
|
|
1647
1647
|
console.error(message);
|
|
1648
1648
|
process.exit(1);
|
|
1649
1649
|
}
|
|
1650
1650
|
|
|
1651
|
-
//
|
|
1651
|
+
// demo/pay.ts
|
|
1652
1652
|
var url = process.argv[2];
|
|
1653
1653
|
if (url === void 0 || !/^https?:\/\//.test(url)) {
|
|
1654
1654
|
fail("Usage: npm run demo:pay -- <url> [maxAmountRawUsdc]");
|
package/dist/withdraw.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
//
|
|
1
|
+
// src/client/agent-wallet-signer.ts
|
|
2
2
|
import { signBytes } from "@solana/kit";
|
|
3
3
|
import bs584 from "bs58";
|
|
4
4
|
|
|
5
|
-
//
|
|
5
|
+
// src/solana/tx.ts
|
|
6
6
|
import bs58 from "bs58";
|
|
7
7
|
import {
|
|
8
8
|
appendTransactionMessageInstructions,
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
setTransactionMessageLifetimeUsingBlockhash
|
|
18
18
|
} from "@solana/kit";
|
|
19
19
|
|
|
20
|
-
//
|
|
20
|
+
// src/lib/hash.ts
|
|
21
21
|
import { createHash } from "node:crypto";
|
|
22
22
|
function sha256TaggedHex(data) {
|
|
23
23
|
return `sha256-${createHash("sha256").update(data).digest("hex")}`;
|
|
@@ -42,7 +42,7 @@ function hashStableJson(value) {
|
|
|
42
42
|
return sha256TaggedHex(stableStringify(value));
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
//
|
|
45
|
+
// src/solana/tx.ts
|
|
46
46
|
function decodeSerializedTransaction(serializedBase64) {
|
|
47
47
|
return getTransactionDecoder().decode(Buffer.from(serializedBase64, "base64"));
|
|
48
48
|
}
|
|
@@ -62,11 +62,11 @@ function signatureBase58ForSigner(transaction, signer2) {
|
|
|
62
62
|
return bs58.encode(signature);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
//
|
|
65
|
+
// src/client/transaction-intent-validator.ts
|
|
66
66
|
import bs583 from "bs58";
|
|
67
67
|
import { getCompiledTransactionMessageDecoder } from "@solana/kit";
|
|
68
68
|
|
|
69
|
-
//
|
|
69
|
+
// src/config/constants.ts
|
|
70
70
|
var PAYMENT_SCHEME = "subly-yield-exact";
|
|
71
71
|
var SOLANA_MAINNET_NETWORK = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
72
72
|
var SPL_TOKEN_PROGRAM_ID = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
|
@@ -82,7 +82,7 @@ var SUBLY_VAULT = {
|
|
|
82
82
|
};
|
|
83
83
|
var USDC_DECIMALS = 6;
|
|
84
84
|
|
|
85
|
-
//
|
|
85
|
+
// src/domain/request-binding.ts
|
|
86
86
|
function computeRequestBindingHash(fields) {
|
|
87
87
|
return hashStableJson({
|
|
88
88
|
sellerRequestId: fields.sellerRequestId,
|
|
@@ -97,7 +97,7 @@ function computeRequestBindingHash(fields) {
|
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
//
|
|
100
|
+
// src/lib/associated-token-account.ts
|
|
101
101
|
import { createHash as createHash2 } from "node:crypto";
|
|
102
102
|
import bs582 from "bs58";
|
|
103
103
|
var PDA_MARKER = Buffer.from("ProgramDerivedAddress", "utf8");
|
|
@@ -189,7 +189,7 @@ function modPow(base, exponent, modulus) {
|
|
|
189
189
|
return result;
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
//
|
|
192
|
+
// src/client/transaction-intent-validator.ts
|
|
193
193
|
var COMPUTE_BUDGET_PROGRAM_ID = "ComputeBudget111111111111111111111111111111";
|
|
194
194
|
var SYSTEM_PROGRAM_ID = "11111111111111111111111111111111";
|
|
195
195
|
var ASSOCIATED_TOKEN_PROGRAM_ID2 = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
|
|
@@ -875,7 +875,7 @@ function readShortVec(bytes, startOffset) {
|
|
|
875
875
|
return null;
|
|
876
876
|
}
|
|
877
877
|
|
|
878
|
-
//
|
|
878
|
+
// src/client/agent-wallet-signer.ts
|
|
879
879
|
var LocalKeypairAgentWalletSigner = class {
|
|
880
880
|
validationMode = "structured_intent_transaction";
|
|
881
881
|
keyPairSigner;
|
|
@@ -945,7 +945,7 @@ var LocalKeypairAgentWalletSigner = class {
|
|
|
945
945
|
}
|
|
946
946
|
};
|
|
947
947
|
|
|
948
|
-
//
|
|
948
|
+
// src/api/wallet-auth.ts
|
|
949
949
|
import { createHash as createHash3 } from "node:crypto";
|
|
950
950
|
import bs585 from "bs58";
|
|
951
951
|
import nacl from "tweetnacl";
|
|
@@ -963,7 +963,7 @@ function walletAuthMessage(params) {
|
|
|
963
963
|
);
|
|
964
964
|
}
|
|
965
965
|
|
|
966
|
-
//
|
|
966
|
+
// src/client/wallet-auth-headers.ts
|
|
967
967
|
async function walletAuthHeaders(params) {
|
|
968
968
|
const signedAtMs = String(Date.now());
|
|
969
969
|
const message = walletAuthMessage({
|
|
@@ -979,7 +979,7 @@ async function walletAuthHeaders(params) {
|
|
|
979
979
|
};
|
|
980
980
|
}
|
|
981
981
|
|
|
982
|
-
//
|
|
982
|
+
// src/client/lookup-tables.ts
|
|
983
983
|
import { fetchAllMaybeAddressLookupTable } from "@solana-program/address-lookup-table";
|
|
984
984
|
import { address, getCompiledTransactionMessageDecoder as getCompiledTransactionMessageDecoder2 } from "@solana/kit";
|
|
985
985
|
function lookupTableAddressesForTransaction(serializedTransaction) {
|
|
@@ -1019,7 +1019,7 @@ async function fetchLookupTablesForTransaction(rpc2, serializedTransaction) {
|
|
|
1019
1019
|
return result;
|
|
1020
1020
|
}
|
|
1021
1021
|
|
|
1022
|
-
//
|
|
1022
|
+
// src/solana/keys.ts
|
|
1023
1023
|
import { readFileSync } from "node:fs";
|
|
1024
1024
|
import bs586 from "bs58";
|
|
1025
1025
|
import {
|
|
@@ -1044,28 +1044,17 @@ async function loadKeyPairSigner(params) {
|
|
|
1044
1044
|
throw new Error(`${label} keypair is not configured`);
|
|
1045
1045
|
}
|
|
1046
1046
|
|
|
1047
|
-
//
|
|
1047
|
+
// src/solana/rpc.ts
|
|
1048
1048
|
import { createSolanaRpc } from "@solana/kit";
|
|
1049
|
-
function
|
|
1050
|
-
const url = env.SOLANA_RPC_URL;
|
|
1051
|
-
if (url === void 0 || url.length === 0) {
|
|
1052
|
-
throw new Error("SOLANA_RPC_URL must be configured");
|
|
1053
|
-
}
|
|
1049
|
+
function createRpc(url) {
|
|
1054
1050
|
return createSolanaRpc(url);
|
|
1055
1051
|
}
|
|
1056
1052
|
|
|
1057
|
-
//
|
|
1053
|
+
// demo/shared.ts
|
|
1058
1054
|
function fail(message) {
|
|
1059
1055
|
console.error(message);
|
|
1060
1056
|
process.exit(1);
|
|
1061
1057
|
}
|
|
1062
|
-
function requireEnv(name) {
|
|
1063
|
-
const value = process.env[name];
|
|
1064
|
-
if (value === void 0 || value.length === 0) {
|
|
1065
|
-
fail(`Missing required environment variable: ${name}`);
|
|
1066
|
-
}
|
|
1067
|
-
return value;
|
|
1068
|
-
}
|
|
1069
1058
|
function formatRawUsdc(raw) {
|
|
1070
1059
|
const units = BigInt(raw);
|
|
1071
1060
|
const whole = units / 1000000n;
|
|
@@ -1073,9 +1062,8 @@ function formatRawUsdc(raw) {
|
|
|
1073
1062
|
return `${whole}.${fraction}`;
|
|
1074
1063
|
}
|
|
1075
1064
|
|
|
1076
|
-
//
|
|
1077
|
-
|
|
1078
|
-
var facilitatorBaseUrl = process.env.SUBLY_FACILITATOR_URL ?? "http://localhost:3000";
|
|
1065
|
+
// demo/withdraw.ts
|
|
1066
|
+
var facilitatorBaseUrl = process.env.SUBLY_FACILITATOR_URL ?? "https://api.demo.sublyfi.com";
|
|
1079
1067
|
var amountRawUsdc = process.argv[2];
|
|
1080
1068
|
if (amountRawUsdc === void 0 || !/^[1-9]\d*$/.test(amountRawUsdc)) {
|
|
1081
1069
|
fail(
|
|
@@ -1088,7 +1076,9 @@ var keyPairSigner = await loadKeyPairSigner({
|
|
|
1088
1076
|
label: "SUBLY_DEMO_AGENT_KEYPAIR"
|
|
1089
1077
|
});
|
|
1090
1078
|
var signer = new LocalKeypairAgentWalletSigner(keyPairSigner);
|
|
1091
|
-
var rpc =
|
|
1079
|
+
var rpc = createRpc(
|
|
1080
|
+
process.env.SOLANA_RPC_URL ?? "https://api.mainnet-beta.solana.com"
|
|
1081
|
+
);
|
|
1092
1082
|
async function postJson(path, body) {
|
|
1093
1083
|
const url = `${facilitatorBaseUrl}${path}`;
|
|
1094
1084
|
const serialized = JSON.stringify(body);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@subly_fi/pay",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Subly client: pay for x402 (
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Subly client: pay for ANY standard x402 (HTTP 402) paid API from Kamino vault yield — the seller needs no Subly integration. Ships an MCP server and a one-shot pay/deposit CLI; non-custodial (signs locally with your own key).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
@@ -21,8 +21,10 @@
|
|
|
21
21
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
22
22
|
"@solana-program/address-lookup-table": "^0.7.0",
|
|
23
23
|
"@solana/kit": "^2.3.0",
|
|
24
|
+
"@solana/web3.js": "^1.98.4",
|
|
24
25
|
"bs58": "^6.0.0",
|
|
25
26
|
"tweetnacl": "^1.0.3",
|
|
27
|
+
"x402-solana": "^2.0.4",
|
|
26
28
|
"zod": "^4.1.13"
|
|
27
29
|
},
|
|
28
30
|
"devDependencies": {
|