@scriptmasterlabs/mcp-x402 2.0.2 → 2.1.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/.well-known/agentcard.json +34 -34
- package/.well-known/ai.txt +32 -0
- package/CONTRIBUTING.md +76 -76
- package/LICENSE +21 -21
- package/README.md +304 -304
- package/agents.json +81 -67
- package/ai/faq.json +74 -0
- package/ai/summary.json +157 -0
- package/dist/lib/chains/base.d.ts.map +1 -1
- package/dist/lib/chains/base.js +2 -0
- package/dist/lib/chains/base.js.map +1 -1
- package/dist/lib/credit/bureau.d.ts +7 -1
- package/dist/lib/credit/bureau.d.ts.map +1 -1
- package/dist/lib/credit/bureau.js +40 -10
- package/dist/lib/credit/bureau.js.map +1 -1
- package/dist/server/index.js +128 -5
- package/dist/server/index.js.map +1 -1
- package/llms.txt +170 -70
- package/package.json +78 -78
- package/server.json +52 -48
- package/.env.example +0 -35
- package/.github/workflows/ci.yml +0 -59
- package/.github/workflows/keepalive.yml +0 -31
- package/Dockerfile +0 -19
- package/docker-compose.yml +0 -50
- package/mcp-publisher.exe +0 -0
- package/render.yaml +0 -39
- package/sdk/mcp-x402-sdk/package.json +0 -18
- package/sdk/mcp-x402-sdk/src/index.ts +0 -118
- package/sdk/mcp-x402-sdk/tsconfig.json +0 -14
- package/services/backtest_service.py +0 -176
- package/src/lib/chains/base.ts +0 -77
- package/src/lib/chains/solana.ts +0 -59
- package/src/lib/chains/xrpl.ts +0 -63
- package/src/lib/credit/bureau.ts +0 -65
- package/src/lib/sml-api/agentcard.ts +0 -40
- package/src/lib/sml-api/backtest.ts +0 -47
- package/src/lib/sml-api/brokers.ts +0 -160
- package/src/lib/sml-api/copytrader.ts +0 -33
- package/src/lib/sml-api/crawl.ts +0 -44
- package/src/lib/sml-api/echo.ts +0 -28
- package/src/lib/sml-api/forge.ts +0 -33
- package/src/lib/sml-api/ftd.ts +0 -53
- package/src/lib/sml-api/ghost.ts +0 -35
- package/src/lib/sml-api/launchpad.ts +0 -43
- package/src/lib/sml-api/leviathan.ts +0 -49
- package/src/lib/sml-api/nexus.ts +0 -50
- package/src/lib/sml-api/proof402.ts +0 -27
- package/src/lib/sml-api/rails.ts +0 -34
- package/src/lib/sml-api/shadow.ts +0 -35
- package/src/lib/sml-api/squeezeos.ts +0 -95
- package/src/lib/sml-api/xdeo.ts +0 -40
- package/src/lib/sml-api/xmit.ts +0 -40
- package/src/server/health.ts +0 -52
- package/src/server/index.ts +0 -213
- package/src/server/payments/ap2.ts +0 -101
- package/src/server/payments/receipt.ts +0 -85
- package/src/server/payments/router.ts +0 -110
- package/src/server/payments/wallet.ts +0 -123
- package/src/server/payments/x402.ts +0 -177
- package/src/server/registry/catalog.ts +0 -61
- package/src/server/registry/discovery.ts +0 -39
- package/src/server/registry/pricing.ts +0 -133
- package/src/server/security/acl.ts +0 -42
- package/src/server/security/audit.ts +0 -94
- package/src/server/security/rate-limit.ts +0 -84
- package/src/server/security/sandbox.ts +0 -40
- package/src/server/tools/agentcard.ts +0 -134
- package/src/server/tools/backtest.ts +0 -119
- package/src/server/tools/brokers.ts +0 -250
- package/src/server/tools/copytrader.ts +0 -104
- package/src/server/tools/crawl.ts +0 -70
- package/src/server/tools/discovery.ts +0 -202
- package/src/server/tools/echo.ts +0 -58
- package/src/server/tools/forge.ts +0 -87
- package/src/server/tools/ftd.ts +0 -88
- package/src/server/tools/ghost.ts +0 -93
- package/src/server/tools/index.ts +0 -42
- package/src/server/tools/launchpad.ts +0 -173
- package/src/server/tools/leviathan.ts +0 -81
- package/src/server/tools/nexus.ts +0 -76
- package/src/server/tools/proof402.ts +0 -87
- package/src/server/tools/rails.ts +0 -92
- package/src/server/tools/shadow.ts +0 -128
- package/src/server/tools/squeezeos.ts +0 -312
- package/src/server/tools/xdeo.ts +0 -67
- package/src/server/tools/xmit.ts +0 -68
- package/tests/integration/e2e.test.ts +0 -51
- package/tests/unit/payments.test.ts +0 -49
- package/tests/unit/security.test.ts +0 -92
- package/tests/unit/tools.test.ts +0 -42
- package/tsconfig.json +0 -21
- package/vitest.config.ts +0 -20
package/src/lib/chains/base.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { createWalletClient, createPublicClient, http, parseUnits } from 'viem';
|
|
2
|
-
import { base, baseSepolia } from 'viem/chains';
|
|
3
|
-
import { privateKeyToAccount } from 'viem/accounts';
|
|
4
|
-
import { mnemonicToSeedSync } from 'bip39';
|
|
5
|
-
import HDKey from 'hdkey';
|
|
6
|
-
import { WalletManager } from '../../server/payments/wallet.js';
|
|
7
|
-
import type { RouteParams } from '../../server/payments/router.js';
|
|
8
|
-
|
|
9
|
-
// USDC contract on Base mainnet
|
|
10
|
-
const USDC_BASE = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';
|
|
11
|
-
// USDC contract on Base Sepolia
|
|
12
|
-
const USDC_BASE_SEPOLIA = '0x036CbD53842c5426634e7929541eC2318f3dCF7e';
|
|
13
|
-
|
|
14
|
-
const ERC20_TRANSFER_ABI = [
|
|
15
|
-
{
|
|
16
|
-
name: 'transfer',
|
|
17
|
-
type: 'function',
|
|
18
|
-
inputs: [
|
|
19
|
-
{ name: 'to', type: 'address' },
|
|
20
|
-
{ name: 'amount', type: 'uint256' },
|
|
21
|
-
],
|
|
22
|
-
outputs: [{ name: '', type: 'bool' }],
|
|
23
|
-
stateMutability: 'nonpayable',
|
|
24
|
-
},
|
|
25
|
-
] as const;
|
|
26
|
-
|
|
27
|
-
export class BaseChain {
|
|
28
|
-
private static instance: BaseChain;
|
|
29
|
-
private readonly testnet: boolean;
|
|
30
|
-
|
|
31
|
-
private constructor() {
|
|
32
|
-
this.testnet = process.env['TESTNET'] === 'true';
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
static getInstance(): BaseChain {
|
|
36
|
-
if (!BaseChain.instance) {
|
|
37
|
-
BaseChain.instance = new BaseChain();
|
|
38
|
-
}
|
|
39
|
-
return BaseChain.instance;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async sendPayment(params: RouteParams): Promise<string> {
|
|
43
|
-
const chain = this.testnet ? baseSepolia : base;
|
|
44
|
-
const rpcUrl = this.testnet
|
|
45
|
-
? (process.env['BASE_SEPOLIA_RPC_URL'] ?? 'https://sepolia.base.org')
|
|
46
|
-
: (process.env['BASE_RPC_URL'] ?? 'https://mainnet.base.org');
|
|
47
|
-
|
|
48
|
-
const privateKey = await this.getPrivateKey();
|
|
49
|
-
const account = privateKeyToAccount(privateKey);
|
|
50
|
-
|
|
51
|
-
const walletClient = createWalletClient({ account, chain, transport: http(rpcUrl) });
|
|
52
|
-
const publicClient = createPublicClient({ chain, transport: http(rpcUrl) });
|
|
53
|
-
|
|
54
|
-
const usdcAddress = this.testnet ? USDC_BASE_SEPOLIA : USDC_BASE;
|
|
55
|
-
const amount = parseUnits(params.amount, 6); // USDC has 6 decimals
|
|
56
|
-
|
|
57
|
-
const hash = await walletClient.writeContract({
|
|
58
|
-
address: usdcAddress,
|
|
59
|
-
abi: ERC20_TRANSFER_ABI,
|
|
60
|
-
functionName: 'transfer',
|
|
61
|
-
args: [params.to as `0x${string}`, amount],
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// Wait for confirmation
|
|
65
|
-
await publicClient.waitForTransactionReceipt({ hash });
|
|
66
|
-
return hash;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
private async getPrivateKey(): Promise<`0x${string}`> {
|
|
70
|
-
const mnemonic = await WalletManager.getInstance().getSeed();
|
|
71
|
-
const seed = mnemonicToSeedSync(mnemonic);
|
|
72
|
-
const hdkey = HDKey.fromMasterSeed(seed);
|
|
73
|
-
const child = hdkey.derive("m/44'/60'/0'/0/0");
|
|
74
|
-
if (!child.privateKey) throw new Error('Key derivation failed');
|
|
75
|
-
return `0x${child.privateKey.toString('hex')}`;
|
|
76
|
-
}
|
|
77
|
-
}
|
package/src/lib/chains/solana.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Connection,
|
|
3
|
-
Keypair,
|
|
4
|
-
PublicKey,
|
|
5
|
-
Transaction,
|
|
6
|
-
sendAndConfirmTransaction,
|
|
7
|
-
} from '@solana/web3.js';
|
|
8
|
-
import { createTransferInstruction, getAssociatedTokenAddress } from '@solana/spl-token';
|
|
9
|
-
import { mnemonicToSeedSync } from 'bip39';
|
|
10
|
-
import HDKey from 'hdkey';
|
|
11
|
-
import { WalletManager } from '../../server/payments/wallet.js';
|
|
12
|
-
import type { RouteParams } from '../../server/payments/router.js';
|
|
13
|
-
|
|
14
|
-
// USDC mint on Solana mainnet
|
|
15
|
-
const USDC_MINT = new PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
|
|
16
|
-
|
|
17
|
-
export class SolanaChain {
|
|
18
|
-
private static instance: SolanaChain;
|
|
19
|
-
private readonly rpcUrl: string;
|
|
20
|
-
|
|
21
|
-
private constructor() {
|
|
22
|
-
this.rpcUrl = process.env['SOLANA_RPC_URL'] ?? 'https://api.mainnet-beta.solana.com';
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
static getInstance(): SolanaChain {
|
|
26
|
-
if (!SolanaChain.instance) {
|
|
27
|
-
SolanaChain.instance = new SolanaChain();
|
|
28
|
-
}
|
|
29
|
-
return SolanaChain.instance;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async sendPayment(params: RouteParams): Promise<string> {
|
|
33
|
-
const connection = new Connection(this.rpcUrl, 'confirmed');
|
|
34
|
-
const payer = await this.getKeypair();
|
|
35
|
-
const destination = new PublicKey(params.to);
|
|
36
|
-
|
|
37
|
-
const fromATA = await getAssociatedTokenAddress(USDC_MINT, payer.publicKey);
|
|
38
|
-
const toATA = await getAssociatedTokenAddress(USDC_MINT, destination);
|
|
39
|
-
|
|
40
|
-
const lamports = Math.round(parseFloat(params.amount) * 1_000_000); // USDC 6 decimals
|
|
41
|
-
|
|
42
|
-
const tx = new Transaction().add(
|
|
43
|
-
createTransferInstruction(fromATA, toATA, payer.publicKey, BigInt(lamports)),
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
const sig = await sendAndConfirmTransaction(connection, tx, [payer]);
|
|
47
|
-
return sig;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
private async getKeypair(): Promise<Keypair> {
|
|
51
|
-
const mnemonic = await WalletManager.getInstance().getSeed();
|
|
52
|
-
const seed = mnemonicToSeedSync(mnemonic);
|
|
53
|
-
const hdkey = HDKey.fromMasterSeed(seed);
|
|
54
|
-
// BIP-44 for Solana: m/44'/501'/0'/0'
|
|
55
|
-
const child = hdkey.derive("m/44'/501'/0'/0'");
|
|
56
|
-
if (!child.privateKey) throw new Error('Solana key derivation failed');
|
|
57
|
-
return Keypair.fromSeed(child.privateKey.slice(0, 32));
|
|
58
|
-
}
|
|
59
|
-
}
|
package/src/lib/chains/xrpl.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { Client, Wallet, xrpToDrops } from 'xrpl';
|
|
2
|
-
import { WalletManager } from '../../server/payments/wallet.js';
|
|
3
|
-
import type { RouteParams } from '../../server/payments/router.js';
|
|
4
|
-
|
|
5
|
-
export class XRPLChain {
|
|
6
|
-
private static instance: XRPLChain;
|
|
7
|
-
private readonly rpcUrl: string;
|
|
8
|
-
|
|
9
|
-
private constructor() {
|
|
10
|
-
this.rpcUrl = process.env['XRPL_RPC_URL'] ?? 'wss://xrplcluster.com';
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
static getInstance(): XRPLChain {
|
|
14
|
-
if (!XRPLChain.instance) {
|
|
15
|
-
XRPLChain.instance = new XRPLChain();
|
|
16
|
-
}
|
|
17
|
-
return XRPLChain.instance;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async sendPayment(params: RouteParams): Promise<string> {
|
|
21
|
-
const client = new Client(this.rpcUrl);
|
|
22
|
-
await client.connect();
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
const wallet = await this.getWallet();
|
|
26
|
-
|
|
27
|
-
// RLUSD on XRPL or XRP-denominated drop equivalent
|
|
28
|
-
const tx = await client.submitAndWait(
|
|
29
|
-
{
|
|
30
|
-
TransactionType: 'Payment',
|
|
31
|
-
Account: wallet.address,
|
|
32
|
-
Destination: params.to,
|
|
33
|
-
Amount:
|
|
34
|
-
params.currency === 'RLUSD'
|
|
35
|
-
? {
|
|
36
|
-
currency: 'USD',
|
|
37
|
-
issuer: process.env['RLUSD_ISSUER'] ?? 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh',
|
|
38
|
-
value: params.amount,
|
|
39
|
-
}
|
|
40
|
-
: xrpToDrops(params.amount),
|
|
41
|
-
},
|
|
42
|
-
{ wallet },
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
if (tx.result.meta && typeof tx.result.meta === 'object' && 'TransactionResult' in tx.result.meta) {
|
|
46
|
-
const meta = tx.result.meta as { TransactionResult: string };
|
|
47
|
-
if (meta.TransactionResult !== 'tesSUCCESS') {
|
|
48
|
-
throw new Error(`XRPL transaction failed: ${meta.TransactionResult}`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const txResult = tx.result as unknown as { hash?: string };
|
|
53
|
-
return txResult.hash ?? 'unknown';
|
|
54
|
-
} finally {
|
|
55
|
-
await client.disconnect();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
private async getWallet(): Promise<Wallet> {
|
|
60
|
-
const mnemonic = await WalletManager.getInstance().getSeed();
|
|
61
|
-
return Wallet.fromMnemonic(mnemonic, { mnemonicEncoding: 'bip39' });
|
|
62
|
-
}
|
|
63
|
-
}
|
package/src/lib/credit/bureau.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
interface ScoreCache {
|
|
2
|
-
score: number;
|
|
3
|
-
fetchedAt: number;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
const SCORE_CACHE_TTL = 300_000; // 5 minutes
|
|
7
|
-
|
|
8
|
-
export class CreditBureau {
|
|
9
|
-
private static instance: CreditBureau;
|
|
10
|
-
private readonly cache = new Map<string, ScoreCache>();
|
|
11
|
-
private readonly baseUrl: string;
|
|
12
|
-
|
|
13
|
-
private constructor() {
|
|
14
|
-
this.baseUrl = process.env['PROOF402_URL'] ?? 'https://four02proof.onrender.com';
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
static getInstance(): CreditBureau {
|
|
18
|
-
if (!CreditBureau.instance) {
|
|
19
|
-
CreditBureau.instance = new CreditBureau();
|
|
20
|
-
}
|
|
21
|
-
return CreditBureau.instance;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async getScore(wallet: string): Promise<number> {
|
|
25
|
-
const now = Date.now();
|
|
26
|
-
const cached = this.cache.get(wallet);
|
|
27
|
-
|
|
28
|
-
if (cached && now - cached.fetchedAt < SCORE_CACHE_TTL) {
|
|
29
|
-
return cached.score;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
const res = await fetch(`${this.baseUrl}/v1/score/${wallet}`, {
|
|
34
|
-
signal: AbortSignal.timeout(5000),
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
if (res.ok) {
|
|
38
|
-
const body = (await res.json()) as { score: number };
|
|
39
|
-
this.cache.set(wallet, { score: body.score, fetchedAt: now });
|
|
40
|
-
return body.score;
|
|
41
|
-
}
|
|
42
|
-
} catch {
|
|
43
|
-
// Fall through to default
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Default score for new/unknown agents
|
|
47
|
-
const defaultScore = 300;
|
|
48
|
-
this.cache.set(wallet, { score: defaultScore, fetchedAt: now });
|
|
49
|
-
return defaultScore;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async incrementScore(wallet: string, delta: number): Promise<void> {
|
|
53
|
-
try {
|
|
54
|
-
await fetch(`${this.baseUrl}/v1/score/${wallet}/increment`, {
|
|
55
|
-
method: 'POST',
|
|
56
|
-
headers: { 'Content-Type': 'application/json' },
|
|
57
|
-
body: JSON.stringify({ delta }),
|
|
58
|
-
});
|
|
59
|
-
// Invalidate cache
|
|
60
|
-
this.cache.delete(wallet);
|
|
61
|
-
} catch {
|
|
62
|
-
// Non-fatal
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const AGENTCARD_BASE = process.env['AGENTCARD_URL'] ?? 'https://agentcard.onrender.com';
|
|
2
|
-
|
|
3
|
-
async function acGet(path: string): Promise<unknown> {
|
|
4
|
-
const res = await fetch(`${AGENTCARD_BASE}${path}`, {
|
|
5
|
-
headers: { 'Accept': 'application/json' },
|
|
6
|
-
signal: AbortSignal.timeout(10_000),
|
|
7
|
-
});
|
|
8
|
-
if (!res.ok) throw new Error(`AgentCard GET ${path}: HTTP ${res.status}`);
|
|
9
|
-
return res.json();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface AgentCardMintParams {
|
|
13
|
-
walletAddress: string;
|
|
14
|
-
name: string;
|
|
15
|
-
did?: string;
|
|
16
|
-
metadata?: Record<string, unknown>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface AgentCardVerifyParams {
|
|
20
|
-
walletAddress: string;
|
|
21
|
-
message: string;
|
|
22
|
-
signature: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async function acPost(path: string, body: unknown): Promise<unknown> {
|
|
26
|
-
const res = await fetch(`${AGENTCARD_BASE}${path}`, {
|
|
27
|
-
method: 'POST',
|
|
28
|
-
headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' },
|
|
29
|
-
body: JSON.stringify(body),
|
|
30
|
-
signal: AbortSignal.timeout(15_000),
|
|
31
|
-
});
|
|
32
|
-
if (!res.ok) throw new Error(`AgentCard POST ${path}: HTTP ${res.status}`);
|
|
33
|
-
return res.json();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const AgentCardAPI = {
|
|
37
|
-
lookup: (walletOrDid: string) => acGet(`/v1/card/${encodeURIComponent(walletOrDid)}`),
|
|
38
|
-
verify: (params: AgentCardVerifyParams) => acPost('/v1/verify', params),
|
|
39
|
-
mint: (params: AgentCardMintParams) => acPost('/v1/mint', params),
|
|
40
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// backtester-mcp microservice client
|
|
2
|
-
// Wraps the Python backtest_service.py running at BACKTEST_BASE_URL
|
|
3
|
-
|
|
4
|
-
const BASE = process.env.BACKTEST_BASE_URL ?? 'http://localhost:8300';
|
|
5
|
-
|
|
6
|
-
export interface BacktestParams {
|
|
7
|
-
ticker: string;
|
|
8
|
-
lookback_days?: number;
|
|
9
|
-
signals?: number[];
|
|
10
|
-
fees?: number;
|
|
11
|
-
slippage?: number;
|
|
12
|
-
momentum_window?: number;
|
|
13
|
-
momentum_threshold?: number;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface ValidateParams {
|
|
17
|
-
ticker: string;
|
|
18
|
-
lookback_days?: number;
|
|
19
|
-
train_ratio?: number;
|
|
20
|
-
fees?: number;
|
|
21
|
-
slippage?: number;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async function post(path: string, body: object): Promise<unknown> {
|
|
25
|
-
const res = await fetch(`${BASE}${path}`, {
|
|
26
|
-
method: 'POST',
|
|
27
|
-
headers: { 'Content-Type': 'application/json' },
|
|
28
|
-
body: JSON.stringify(body),
|
|
29
|
-
signal: AbortSignal.timeout(30_000),
|
|
30
|
-
});
|
|
31
|
-
if (!res.ok) {
|
|
32
|
-
const err = await res.json().catch(() => ({ error: res.statusText }));
|
|
33
|
-
throw new Error((err as { error?: string }).error ?? res.statusText);
|
|
34
|
-
}
|
|
35
|
-
return res.json();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export const BacktestAPI = {
|
|
39
|
-
health: async (): Promise<unknown> => {
|
|
40
|
-
const res = await fetch(`${BASE}/health`, { signal: AbortSignal.timeout(5_000) });
|
|
41
|
-
return res.json();
|
|
42
|
-
},
|
|
43
|
-
|
|
44
|
-
backtest: (params: BacktestParams): Promise<unknown> => post('/backtest', params),
|
|
45
|
-
|
|
46
|
-
walkForward: (params: ValidateParams): Promise<unknown> => post('/validate', params),
|
|
47
|
-
};
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
// Broker execution rails — Robinhood + Tradier
|
|
2
|
-
// Robinhood: OAuth2 Bearer token (ROBINHOOD_ACCESS_TOKEN env)
|
|
3
|
-
// Tradier: Bearer token (TRADIER_API_KEY env, TRADIER_ENV=sandbox|production)
|
|
4
|
-
|
|
5
|
-
const TRADIER_BASE = process.env.TRADIER_ENV === 'production'
|
|
6
|
-
? 'https://api.tradier.com/v1'
|
|
7
|
-
: 'https://sandbox.tradier.com/v1';
|
|
8
|
-
|
|
9
|
-
const ROBINHOOD_BASE = 'https://api.robinhood.com';
|
|
10
|
-
|
|
11
|
-
// ── Shared fetch helpers ────────────────────────────────────────────────────
|
|
12
|
-
|
|
13
|
-
async function tradierGet(path: string, params?: Record<string, string>): Promise<unknown> {
|
|
14
|
-
const token = process.env.TRADIER_API_KEY;
|
|
15
|
-
if (!token) throw new Error('TRADIER_API_KEY not configured');
|
|
16
|
-
const url = new URL(`${TRADIER_BASE}${path}`);
|
|
17
|
-
if (params) Object.entries(params).forEach(([k, v]) => url.searchParams.set(k, v));
|
|
18
|
-
const res = await fetch(url.toString(), {
|
|
19
|
-
headers: { Authorization: `Bearer ${token}`, Accept: 'application/json' },
|
|
20
|
-
signal: AbortSignal.timeout(10_000),
|
|
21
|
-
});
|
|
22
|
-
if (!res.ok) throw new Error(`Tradier ${res.status}: ${res.statusText}`);
|
|
23
|
-
return res.json();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async function tradierPost(path: string, body: Record<string, string>): Promise<unknown> {
|
|
27
|
-
const token = process.env.TRADIER_API_KEY;
|
|
28
|
-
if (!token) throw new Error('TRADIER_API_KEY not configured');
|
|
29
|
-
const res = await fetch(`${TRADIER_BASE}${path}`, {
|
|
30
|
-
method: 'POST',
|
|
31
|
-
headers: {
|
|
32
|
-
Authorization: `Bearer ${token}`,
|
|
33
|
-
Accept: 'application/json',
|
|
34
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
35
|
-
},
|
|
36
|
-
body: new URLSearchParams(body).toString(),
|
|
37
|
-
signal: AbortSignal.timeout(10_000),
|
|
38
|
-
});
|
|
39
|
-
if (!res.ok) throw new Error(`Tradier ${res.status}: ${res.statusText}`);
|
|
40
|
-
return res.json();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async function robinhoodGet(path: string): Promise<unknown> {
|
|
44
|
-
const token = process.env.ROBINHOOD_ACCESS_TOKEN;
|
|
45
|
-
if (!token) throw new Error('ROBINHOOD_ACCESS_TOKEN not configured');
|
|
46
|
-
const res = await fetch(`${ROBINHOOD_BASE}${path}`, {
|
|
47
|
-
headers: { Authorization: `Bearer ${token}`, Accept: 'application/json' },
|
|
48
|
-
signal: AbortSignal.timeout(10_000),
|
|
49
|
-
});
|
|
50
|
-
if (!res.ok) throw new Error(`Robinhood ${res.status}: ${res.statusText}`);
|
|
51
|
-
return res.json();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async function robinhoodPost(path: string, body: object): Promise<unknown> {
|
|
55
|
-
const token = process.env.ROBINHOOD_ACCESS_TOKEN;
|
|
56
|
-
if (!token) throw new Error('ROBINHOOD_ACCESS_TOKEN not configured');
|
|
57
|
-
const res = await fetch(`${ROBINHOOD_BASE}${path}`, {
|
|
58
|
-
method: 'POST',
|
|
59
|
-
headers: {
|
|
60
|
-
Authorization: `Bearer ${token}`,
|
|
61
|
-
Accept: 'application/json',
|
|
62
|
-
'Content-Type': 'application/json',
|
|
63
|
-
},
|
|
64
|
-
body: JSON.stringify(body),
|
|
65
|
-
signal: AbortSignal.timeout(10_000),
|
|
66
|
-
});
|
|
67
|
-
if (!res.ok) throw new Error(`Robinhood ${res.status}: ${res.statusText}`);
|
|
68
|
-
return res.json();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// ── Tradier API ─────────────────────────────────────────────────────────────
|
|
72
|
-
|
|
73
|
-
export interface TradierQuoteParams { symbols: string }
|
|
74
|
-
export interface TradierOrderParams {
|
|
75
|
-
account_id: string;
|
|
76
|
-
symbol: string;
|
|
77
|
-
side: 'buy' | 'sell';
|
|
78
|
-
quantity: number;
|
|
79
|
-
type: 'market' | 'limit' | 'stop' | 'stop_limit';
|
|
80
|
-
duration: 'day' | 'gtc' | 'pre' | 'post';
|
|
81
|
-
price?: number;
|
|
82
|
-
stop?: number;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export const TradierAPI = {
|
|
86
|
-
quote: (params: TradierQuoteParams) =>
|
|
87
|
-
tradierGet('/markets/quotes', { symbols: params.symbols, greeks: 'false' }),
|
|
88
|
-
|
|
89
|
-
optionChain: (symbol: string, expiration: string) =>
|
|
90
|
-
tradierGet('/markets/options/chains', { symbol, expiration, greeks: 'true' }),
|
|
91
|
-
|
|
92
|
-
order: (params: TradierOrderParams) => {
|
|
93
|
-
const body: Record<string, string> = {
|
|
94
|
-
class: 'equity',
|
|
95
|
-
symbol: params.symbol,
|
|
96
|
-
side: params.side,
|
|
97
|
-
quantity: String(params.quantity),
|
|
98
|
-
type: params.type,
|
|
99
|
-
duration: params.duration,
|
|
100
|
-
};
|
|
101
|
-
if (params.price !== undefined) body.price = String(params.price);
|
|
102
|
-
if (params.stop !== undefined) body.stop = String(params.stop);
|
|
103
|
-
return tradierPost(`/accounts/${params.account_id}/orders`, body);
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
positions: (account_id: string) =>
|
|
107
|
-
tradierGet(`/accounts/${account_id}/positions`),
|
|
108
|
-
|
|
109
|
-
balances: (account_id: string) =>
|
|
110
|
-
tradierGet(`/accounts/${account_id}/balances`),
|
|
111
|
-
|
|
112
|
-
orderStatus: (account_id: string, order_id: string) =>
|
|
113
|
-
tradierGet(`/accounts/${account_id}/orders/${order_id}`),
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
// ── Robinhood API ────────────────────────────────────────────────────────────
|
|
117
|
-
|
|
118
|
-
export interface RobinhoodOrderParams {
|
|
119
|
-
symbol: string;
|
|
120
|
-
side: 'buy' | 'sell';
|
|
121
|
-
quantity: number;
|
|
122
|
-
type: 'market' | 'limit';
|
|
123
|
-
time_in_force: 'gfd' | 'gtc' | 'ioc' | 'opg';
|
|
124
|
-
price?: number;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export const RobinhoodAPI = {
|
|
128
|
-
quote: async (symbol: string) => {
|
|
129
|
-
const data = await robinhoodGet(`/quotes/?symbols=${symbol}`) as { results?: unknown[] };
|
|
130
|
-
return data.results?.[0] ?? data;
|
|
131
|
-
},
|
|
132
|
-
|
|
133
|
-
instruments: async (symbol: string) => {
|
|
134
|
-
const data = await robinhoodGet(`/instruments/?symbol=${symbol}`) as { results?: { url: string }[] };
|
|
135
|
-
return data.results?.[0];
|
|
136
|
-
},
|
|
137
|
-
|
|
138
|
-
order: async (params: RobinhoodOrderParams) => {
|
|
139
|
-
const instrument = await RobinhoodAPI.instruments(params.symbol) as { url?: string } | undefined;
|
|
140
|
-
if (!instrument?.url) throw new Error(`Instrument not found: ${params.symbol}`);
|
|
141
|
-
const body: Record<string, unknown> = {
|
|
142
|
-
account: `/accounts/${process.env.ROBINHOOD_ACCOUNT_ID}/`,
|
|
143
|
-
instrument: instrument.url,
|
|
144
|
-
symbol: params.symbol,
|
|
145
|
-
side: params.side,
|
|
146
|
-
quantity: params.quantity,
|
|
147
|
-
type: params.type,
|
|
148
|
-
time_in_force: params.time_in_force,
|
|
149
|
-
trigger: 'immediate',
|
|
150
|
-
};
|
|
151
|
-
if (params.price !== undefined) body.price = String(params.price);
|
|
152
|
-
return robinhoodPost('/orders/', body);
|
|
153
|
-
},
|
|
154
|
-
|
|
155
|
-
portfolio: () => robinhoodGet('/portfolios/'),
|
|
156
|
-
|
|
157
|
-
positions: () => robinhoodGet('/positions/?nonzero=true'),
|
|
158
|
-
|
|
159
|
-
orderHistory: () => robinhoodGet('/orders/?page_size=20'),
|
|
160
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
const COPYTRADER_BASE = process.env['SML_COPYTRADER_URL'] ?? 'https://sml-copytrader.onrender.com';
|
|
2
|
-
|
|
3
|
-
async function ctGet(path: string): Promise<unknown> {
|
|
4
|
-
const res = await fetch(`${COPYTRADER_BASE}${path}`, {
|
|
5
|
-
headers: { 'Accept': 'application/json' },
|
|
6
|
-
signal: AbortSignal.timeout(15_000),
|
|
7
|
-
});
|
|
8
|
-
if (!res.ok) throw new Error(`CopyTrader GET ${path}: HTTP ${res.status}`);
|
|
9
|
-
return res.json();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface CopyTraderSubscribeParams {
|
|
13
|
-
whaleAddress: string;
|
|
14
|
-
subscriberAddress: string;
|
|
15
|
-
maxCopyAmountXrp: number;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async function ctPost(path: string, body: unknown): Promise<unknown> {
|
|
19
|
-
const res = await fetch(`${COPYTRADER_BASE}${path}`, {
|
|
20
|
-
method: 'POST',
|
|
21
|
-
headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' },
|
|
22
|
-
body: JSON.stringify(body),
|
|
23
|
-
signal: AbortSignal.timeout(15_000),
|
|
24
|
-
});
|
|
25
|
-
if (!res.ok) throw new Error(`CopyTrader POST ${path}: HTTP ${res.status}`);
|
|
26
|
-
return res.json();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const CopyTraderAPI = {
|
|
30
|
-
status: () => ctGet('/status'),
|
|
31
|
-
whales: () => ctGet('/whales'),
|
|
32
|
-
subscribe: (params: CopyTraderSubscribeParams) => ctPost('/subscribe', params),
|
|
33
|
-
};
|
package/src/lib/sml-api/crawl.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
export interface CrawlParams {
|
|
2
|
-
url: string;
|
|
3
|
-
extract: 'text' | 'links' | 'tables' | 'structured' | 'all';
|
|
4
|
-
userAgent?: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface CrawlResult {
|
|
8
|
-
url: string;
|
|
9
|
-
content: string | unknown;
|
|
10
|
-
status_code: number;
|
|
11
|
-
content_type: string;
|
|
12
|
-
fetched_at: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class CrawlClient {
|
|
16
|
-
private static instance: CrawlClient;
|
|
17
|
-
private readonly baseUrl: string;
|
|
18
|
-
|
|
19
|
-
private constructor() {
|
|
20
|
-
this.baseUrl = process.env['SML_API_BASE'] ?? 'https://api.scriptmasterlabs.com';
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
static getInstance(): CrawlClient {
|
|
24
|
-
if (!CrawlClient.instance) {
|
|
25
|
-
CrawlClient.instance = new CrawlClient();
|
|
26
|
-
}
|
|
27
|
-
return CrawlClient.instance;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async fetch(params: CrawlParams): Promise<CrawlResult> {
|
|
31
|
-
const res = await fetch(`${this.baseUrl}/crawl/v1/fetch`, {
|
|
32
|
-
method: 'POST',
|
|
33
|
-
headers: {
|
|
34
|
-
'Content-Type': 'application/json',
|
|
35
|
-
...(params.userAgent ? { 'X-Crawl-User-Agent': params.userAgent } : {}),
|
|
36
|
-
},
|
|
37
|
-
body: JSON.stringify({ url: params.url, extract: params.extract }),
|
|
38
|
-
signal: AbortSignal.timeout(30_000),
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
if (!res.ok) throw new Error(`Crawl API error: HTTP ${res.status}`);
|
|
42
|
-
return res.json() as Promise<CrawlResult>;
|
|
43
|
-
}
|
|
44
|
-
}
|
package/src/lib/sml-api/echo.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// echo-forge — historical pattern similarity engine (Polygon.io + ML cosine similarity)
|
|
2
|
-
// Status: NOT YET DEPLOYED. Returns informative stub response until service is live.
|
|
3
|
-
|
|
4
|
-
export interface EchoPatternParams {
|
|
5
|
-
symbol: string;
|
|
6
|
-
lookbackDays: number;
|
|
7
|
-
topN?: number;
|
|
8
|
-
walletAddress: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const EchoForgeAPI = {
|
|
12
|
-
patternMatch: async (params: EchoPatternParams): Promise<unknown> => {
|
|
13
|
-
// Service not yet deployed to Render — surface clear coming-soon message.
|
|
14
|
-
return {
|
|
15
|
-
status: 'coming_soon',
|
|
16
|
-
service: 'echo-forge',
|
|
17
|
-
message:
|
|
18
|
-
'echo-forge (historical pattern similarity engine) is not yet deployed. ' +
|
|
19
|
-
'It uses Polygon.io data + ML cosine similarity to find historical analogs. ' +
|
|
20
|
-
'Check https://github.com/Timwal78/echo-forge for status updates.',
|
|
21
|
-
params_received: {
|
|
22
|
-
symbol: params.symbol,
|
|
23
|
-
lookback_days: params.lookbackDays,
|
|
24
|
-
top_n: params.topN ?? 5,
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
};
|
package/src/lib/sml-api/forge.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
const FORGE_BASE = process.env['FORGE_GATEWAY_URL'] ?? 'https://forge-gateway-a822.onrender.com';
|
|
2
|
-
|
|
3
|
-
async function forgeGet(path: string): Promise<unknown> {
|
|
4
|
-
const res = await fetch(`${FORGE_BASE}${path}`, {
|
|
5
|
-
headers: { 'Accept': 'application/json' },
|
|
6
|
-
signal: AbortSignal.timeout(15_000),
|
|
7
|
-
});
|
|
8
|
-
if (!res.ok) throw new Error(`Forge Gateway GET ${path}: HTTP ${res.status}`);
|
|
9
|
-
return res.json();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface ForgeLLMParams {
|
|
13
|
-
model: string;
|
|
14
|
-
prompt: string;
|
|
15
|
-
maxTokens?: number;
|
|
16
|
-
walletAddress: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async function forgePost(path: string, body: unknown): Promise<unknown> {
|
|
20
|
-
const res = await fetch(`${FORGE_BASE}${path}`, {
|
|
21
|
-
method: 'POST',
|
|
22
|
-
headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' },
|
|
23
|
-
body: JSON.stringify(body),
|
|
24
|
-
signal: AbortSignal.timeout(60_000),
|
|
25
|
-
});
|
|
26
|
-
if (!res.ok) throw new Error(`Forge Gateway POST ${path}: HTTP ${res.status}`);
|
|
27
|
-
return res.json();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const ForgeGatewayAPI = {
|
|
31
|
-
status: () => forgeGet('/health'),
|
|
32
|
-
llm: (params: ForgeLLMParams) => forgePost('/v1/llm', params),
|
|
33
|
-
};
|