stellar-agent-kit 1.0.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/index.cjs +234 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +147 -0
- package/dist/index.d.ts +147 -0
- package/dist/index.js +201 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
MAINNET_ASSETS: () => MAINNET_ASSETS,
|
|
24
|
+
SOROSWAP_AGGREGATOR: () => SOROSWAP_AGGREGATOR,
|
|
25
|
+
StellarAgentKit: () => StellarAgentKit,
|
|
26
|
+
TESTNET_ASSETS: () => TESTNET_ASSETS,
|
|
27
|
+
createDexClient: () => createDexClient,
|
|
28
|
+
getNetworkConfig: () => getNetworkConfig,
|
|
29
|
+
networks: () => networks
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(index_exports);
|
|
32
|
+
|
|
33
|
+
// src/agent.ts
|
|
34
|
+
var import_stellar_sdk3 = require("@stellar/stellar-sdk");
|
|
35
|
+
|
|
36
|
+
// src/config/networks.ts
|
|
37
|
+
var import_zod = require("zod");
|
|
38
|
+
var NetworkConfigSchema = import_zod.z.object({
|
|
39
|
+
horizonUrl: import_zod.z.string().url(),
|
|
40
|
+
sorobanRpcUrl: import_zod.z.string().url(),
|
|
41
|
+
friendbotUrl: import_zod.z.string().url().optional()
|
|
42
|
+
});
|
|
43
|
+
var testnet = {
|
|
44
|
+
horizonUrl: "https://horizon-testnet.stellar.org",
|
|
45
|
+
sorobanRpcUrl: "https://soroban-testnet.stellar.org",
|
|
46
|
+
friendbotUrl: "https://friendbot.stellar.org"
|
|
47
|
+
};
|
|
48
|
+
var mainnet = {
|
|
49
|
+
horizonUrl: "https://horizon.stellar.org",
|
|
50
|
+
sorobanRpcUrl: "https://soroban-rpc.mainnet.stellar.gateway.fm"
|
|
51
|
+
};
|
|
52
|
+
var networks = { testnet, mainnet };
|
|
53
|
+
function getNetworkConfig(name) {
|
|
54
|
+
const parsed = import_zod.z.enum(["testnet", "mainnet"]).safeParse(name);
|
|
55
|
+
if (!parsed.success) throw new Error(`Invalid network: ${name}. Use "testnet" or "mainnet".`);
|
|
56
|
+
return networks[parsed.data];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/dex/soroSwap.ts
|
|
60
|
+
var import_stellar_sdk = require("@stellar/stellar-sdk");
|
|
61
|
+
var import_stellar_sdk2 = require("@stellar/stellar-sdk");
|
|
62
|
+
var SOROSWAP_API_BASE = "https://api.soroswap.finance";
|
|
63
|
+
function assetToApiString(asset) {
|
|
64
|
+
if (asset.contractId) return asset.contractId;
|
|
65
|
+
if (asset.code && asset.issuer) return `${asset.code}:${asset.issuer}`;
|
|
66
|
+
throw new Error("Asset must have contractId or code+issuer");
|
|
67
|
+
}
|
|
68
|
+
function parseApiQuote(data) {
|
|
69
|
+
const o = data;
|
|
70
|
+
return {
|
|
71
|
+
expectedIn: String(o?.expectedIn ?? o?.amountIn ?? "0"),
|
|
72
|
+
expectedOut: String(o?.expectedOut ?? o?.amountOut ?? "0"),
|
|
73
|
+
minOut: String(o?.minOut ?? o?.minimumAmountOut ?? o?.expectedOut ?? "0"),
|
|
74
|
+
route: Array.isArray(o?.route) ? o.route : Array.isArray(o?.path) ? o.path : [],
|
|
75
|
+
rawData: data
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function createSoroSwapDexClient(networkConfig, apiKey) {
|
|
79
|
+
const networkName = networkConfig.horizonUrl.includes("testnet") ? "testnet" : "mainnet";
|
|
80
|
+
const key = apiKey ?? process.env.SOROSWAP_API_KEY;
|
|
81
|
+
async function getQuote(from, to, amount) {
|
|
82
|
+
const url = `${SOROSWAP_API_BASE}/quote?network=${networkName}`;
|
|
83
|
+
const body = {
|
|
84
|
+
assetIn: assetToApiString(from),
|
|
85
|
+
assetOut: assetToApiString(to),
|
|
86
|
+
amount: String(amount).trim(),
|
|
87
|
+
tradeType: "EXACT_IN",
|
|
88
|
+
protocols: ["soroswap", "phoenix", "aqua"]
|
|
89
|
+
};
|
|
90
|
+
const headers = { "Content-Type": "application/json" };
|
|
91
|
+
if (key) headers["Authorization"] = `Bearer ${key}`;
|
|
92
|
+
const res = await fetch(url, { method: "POST", headers, body: JSON.stringify(body) });
|
|
93
|
+
if (!res.ok) {
|
|
94
|
+
const text = await res.text();
|
|
95
|
+
throw new Error(`SoroSwap quote failed ${res.status}: ${text}`);
|
|
96
|
+
}
|
|
97
|
+
return parseApiQuote(await res.json());
|
|
98
|
+
}
|
|
99
|
+
async function executeSwap(secretKey, quote) {
|
|
100
|
+
if (!key) throw new Error("executeSwap requires SOROSWAP_API_KEY");
|
|
101
|
+
const keypair = import_stellar_sdk.Keypair.fromSecret(secretKey.trim());
|
|
102
|
+
const fromAddress = keypair.publicKey();
|
|
103
|
+
const buildUrl = `${SOROSWAP_API_BASE}/quote/build?network=${networkName}`;
|
|
104
|
+
const buildRes = await fetch(buildUrl, {
|
|
105
|
+
method: "POST",
|
|
106
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${key}` },
|
|
107
|
+
body: JSON.stringify({ quote: quote.rawData ?? quote, from: fromAddress, to: fromAddress })
|
|
108
|
+
});
|
|
109
|
+
if (!buildRes.ok) throw new Error(`SoroSwap build failed ${buildRes.status}: ${await buildRes.text()}`);
|
|
110
|
+
const buildData = await buildRes.json();
|
|
111
|
+
const xdrBase64 = buildData?.xdr;
|
|
112
|
+
if (!xdrBase64 || typeof xdrBase64 !== "string") throw new Error("SoroSwap build response missing xdr");
|
|
113
|
+
const config = getNetworkConfig(networkName);
|
|
114
|
+
const networkPassphrase = config.horizonUrl.includes("testnet") ? import_stellar_sdk.Networks.TESTNET : import_stellar_sdk.Networks.PUBLIC;
|
|
115
|
+
const tx = import_stellar_sdk.TransactionBuilder.fromXDR(xdrBase64, networkPassphrase);
|
|
116
|
+
tx.sign(keypair);
|
|
117
|
+
const server = new import_stellar_sdk2.rpc.Server(config.sorobanRpcUrl, { allowHttp: config.sorobanRpcUrl.startsWith("http:") });
|
|
118
|
+
const sendResult = await server.sendTransaction(tx);
|
|
119
|
+
if (sendResult.errorResult) throw new Error(`Soroban sendTransaction failed: ${String(sendResult.errorResult)}`);
|
|
120
|
+
return { hash: sendResult.hash, status: sendResult.status ?? "PENDING" };
|
|
121
|
+
}
|
|
122
|
+
return { getQuote, executeSwap };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/dex/index.ts
|
|
126
|
+
function createDexClient(networkConfig, apiKey) {
|
|
127
|
+
return createSoroSwapDexClient(networkConfig, apiKey);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/agent.ts
|
|
131
|
+
var StellarAgentKit = class {
|
|
132
|
+
keypair;
|
|
133
|
+
network;
|
|
134
|
+
config;
|
|
135
|
+
_initialized = false;
|
|
136
|
+
_dex = null;
|
|
137
|
+
_horizon = null;
|
|
138
|
+
constructor(secretKey, network) {
|
|
139
|
+
this.keypair = import_stellar_sdk3.Keypair.fromSecret(secretKey.trim());
|
|
140
|
+
this.network = network;
|
|
141
|
+
this.config = getNetworkConfig(network);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Initialize clients (Horizon, Soroban RPC, protocol wrappers).
|
|
145
|
+
* Call after construction before using protocol methods.
|
|
146
|
+
*/
|
|
147
|
+
async initialize() {
|
|
148
|
+
this._horizon = new import_stellar_sdk3.Horizon.Server(this.config.horizonUrl);
|
|
149
|
+
this._dex = createDexClient(this.config, process.env.SOROSWAP_API_KEY);
|
|
150
|
+
this._initialized = true;
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
ensureInitialized() {
|
|
154
|
+
if (!this._initialized || !this._dex) {
|
|
155
|
+
throw new Error("StellarAgentKit not initialized. Call await agent.initialize() first.");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// ─── DEX Operations (mirror Mantle agniSwap / executeSwap) ─────────────────
|
|
159
|
+
/**
|
|
160
|
+
* Get a swap quote (exact-in). Uses SoroSwap aggregator (SoroSwap, Phoenix, Aqua).
|
|
161
|
+
*/
|
|
162
|
+
async dexGetQuote(fromAsset, toAsset, amount) {
|
|
163
|
+
this.ensureInitialized();
|
|
164
|
+
return this._dex.getQuote(fromAsset, toAsset, amount);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Execute a swap using a prior quote.
|
|
168
|
+
*/
|
|
169
|
+
async dexSwap(quote) {
|
|
170
|
+
this.ensureInitialized();
|
|
171
|
+
return this._dex.executeSwap(this.keypair.secret(), quote);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* One-shot: get quote and execute swap (convenience).
|
|
175
|
+
*/
|
|
176
|
+
async dexSwapExactIn(fromAsset, toAsset, amount) {
|
|
177
|
+
const quote = await this.dexGetQuote(fromAsset, toAsset, amount);
|
|
178
|
+
return this.dexSwap(quote);
|
|
179
|
+
}
|
|
180
|
+
// ─── Payments (Horizon) ────────────────────────────────────────────────────
|
|
181
|
+
/**
|
|
182
|
+
* Send a native or custom-asset payment (Horizon).
|
|
183
|
+
* @param to - Destination account (G...)
|
|
184
|
+
* @param amount - Amount in display units (e.g. "10" for 10 XLM)
|
|
185
|
+
* @param assetCode - Optional; omit for native XLM
|
|
186
|
+
* @param assetIssuer - Optional; required if assetCode is set
|
|
187
|
+
*/
|
|
188
|
+
async sendPayment(to, amount, assetCode, assetIssuer) {
|
|
189
|
+
this.ensureInitialized();
|
|
190
|
+
if (!this._horizon) throw new Error("Horizon not initialized");
|
|
191
|
+
const networkPassphrase = this.network === "testnet" ? import_stellar_sdk3.Networks.TESTNET : import_stellar_sdk3.Networks.PUBLIC;
|
|
192
|
+
const sourceAccount = await this._horizon.loadAccount(this.keypair.publicKey());
|
|
193
|
+
const asset = assetCode && assetIssuer ? new import_stellar_sdk3.Asset(assetCode, assetIssuer) : import_stellar_sdk3.Asset.native();
|
|
194
|
+
const tx = new import_stellar_sdk3.TransactionBuilder(sourceAccount, {
|
|
195
|
+
fee: "100",
|
|
196
|
+
networkPassphrase
|
|
197
|
+
}).addOperation(import_stellar_sdk3.Operation.payment({ destination: to, asset, amount })).setTimeout(180).build();
|
|
198
|
+
tx.sign(this.keypair);
|
|
199
|
+
const result = await this._horizon.submitTransaction(tx);
|
|
200
|
+
return { hash: result.hash };
|
|
201
|
+
}
|
|
202
|
+
// ─── Placeholders for lending / oracle / cross-chain (plug later) ────────────
|
|
203
|
+
// async lendingSupply(asset: DexAsset, amount: string): Promise<{ hash: string }> { ... }
|
|
204
|
+
// async lendingBorrow(asset: DexAsset, amount: string): Promise<{ hash: string }> { ... }
|
|
205
|
+
// async getPrice(assetOrFeedId: string): Promise<{ price: string }> { ... }
|
|
206
|
+
// async crossChainSwap(...): Promise<SwapResult> { ... }
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// src/config/assets.ts
|
|
210
|
+
var TESTNET_ASSETS = {
|
|
211
|
+
XLM: { contractId: "CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC" },
|
|
212
|
+
USDC: { contractId: "CBBHRKEP5M3NUDRISGLJKGHDHX3DA2CN2AZBQY6WLVUJ7VNLGSKBDUCM" },
|
|
213
|
+
/** Classic testnet USDC */
|
|
214
|
+
AUSDC: { code: "AUSDC", issuer: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN" }
|
|
215
|
+
};
|
|
216
|
+
var MAINNET_ASSETS = {
|
|
217
|
+
XLM: { contractId: "CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA" },
|
|
218
|
+
USDC: { contractId: "CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75" }
|
|
219
|
+
};
|
|
220
|
+
var SOROSWAP_AGGREGATOR = {
|
|
221
|
+
testnet: "CCJUD55AG6W5HAI5LRVNKAE5WDP5XGZBUDS5WNTIVDU7O264UZZE7BRD",
|
|
222
|
+
mainnet: "CAG5LRYQ5JVEUI5TEID72EYOVX44TTUJT5BQR2J6J77FH65PCCFAJDDH"
|
|
223
|
+
};
|
|
224
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
225
|
+
0 && (module.exports = {
|
|
226
|
+
MAINNET_ASSETS,
|
|
227
|
+
SOROSWAP_AGGREGATOR,
|
|
228
|
+
StellarAgentKit,
|
|
229
|
+
TESTNET_ASSETS,
|
|
230
|
+
createDexClient,
|
|
231
|
+
getNetworkConfig,
|
|
232
|
+
networks
|
|
233
|
+
});
|
|
234
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/agent.ts","../src/config/networks.ts","../src/dex/soroSwap.ts","../src/dex/index.ts","../src/config/assets.ts"],"sourcesContent":["export { StellarAgentKit, type StellarNetwork } from \"./agent.js\";\nexport { getNetworkConfig, networks, type NetworkConfig, type NetworkName } from \"./config/networks.js\";\nexport {\n TESTNET_ASSETS,\n MAINNET_ASSETS,\n SOROSWAP_AGGREGATOR,\n type StellarAsset,\n} from \"./config/assets.js\";\nexport {\n createDexClient,\n type DexClient,\n type DexAsset,\n type QuoteResult,\n type SwapResult,\n} from \"./dex/index.js\";\n","/**\n * StellarAgentKit – unified DeFi agent (MNTAgentKit-style API for Stellar).\n * Constructor(secretKey, network) + initialize() then protocol methods.\n */\n\nimport { Keypair, Asset, TransactionBuilder, Operation, Networks, Horizon } from \"@stellar/stellar-sdk\";\nimport { getNetworkConfig, type NetworkConfig } from \"./config/networks.js\";\nimport { createDexClient, type DexAsset, type QuoteResult, type SwapResult } from \"./dex/index.js\";\n\nexport type StellarNetwork = \"mainnet\" | \"testnet\";\n\nexport class StellarAgentKit {\n public readonly keypair: Keypair;\n public readonly network: StellarNetwork;\n public readonly config: NetworkConfig;\n private _initialized = false;\n private _dex: ReturnType<typeof createDexClient> | null = null;\n private _horizon: Horizon.Server | null = null;\n\n constructor(secretKey: string, network: StellarNetwork) {\n this.keypair = Keypair.fromSecret(secretKey.trim());\n this.network = network;\n this.config = getNetworkConfig(network);\n }\n\n /**\n * Initialize clients (Horizon, Soroban RPC, protocol wrappers).\n * Call after construction before using protocol methods.\n */\n async initialize(): Promise<this> {\n this._horizon = new Horizon.Server(this.config.horizonUrl);\n this._dex = createDexClient(this.config, process.env.SOROSWAP_API_KEY);\n this._initialized = true;\n return this;\n }\n\n private ensureInitialized(): void {\n if (!this._initialized || !this._dex) {\n throw new Error(\"StellarAgentKit not initialized. Call await agent.initialize() first.\");\n }\n }\n\n // ─── DEX Operations (mirror Mantle agniSwap / executeSwap) ─────────────────\n\n /**\n * Get a swap quote (exact-in). Uses SoroSwap aggregator (SoroSwap, Phoenix, Aqua).\n */\n async dexGetQuote(\n fromAsset: DexAsset,\n toAsset: DexAsset,\n amount: string\n ): Promise<QuoteResult> {\n this.ensureInitialized();\n return this._dex!.getQuote(fromAsset, toAsset, amount);\n }\n\n /**\n * Execute a swap using a prior quote.\n */\n async dexSwap(quote: QuoteResult): Promise<SwapResult> {\n this.ensureInitialized();\n return this._dex!.executeSwap(this.keypair.secret(), quote);\n }\n\n /**\n * One-shot: get quote and execute swap (convenience).\n */\n async dexSwapExactIn(\n fromAsset: DexAsset,\n toAsset: DexAsset,\n amount: string\n ): Promise<SwapResult> {\n const quote = await this.dexGetQuote(fromAsset, toAsset, amount);\n return this.dexSwap(quote);\n }\n\n // ─── Payments (Horizon) ────────────────────────────────────────────────────\n\n /**\n * Send a native or custom-asset payment (Horizon).\n * @param to - Destination account (G...)\n * @param amount - Amount in display units (e.g. \"10\" for 10 XLM)\n * @param assetCode - Optional; omit for native XLM\n * @param assetIssuer - Optional; required if assetCode is set\n */\n async sendPayment(\n to: string,\n amount: string,\n assetCode?: string,\n assetIssuer?: string\n ): Promise<{ hash: string }> {\n this.ensureInitialized();\n if (!this._horizon) throw new Error(\"Horizon not initialized\");\n\n const networkPassphrase =\n this.network === \"testnet\" ? Networks.TESTNET : Networks.PUBLIC;\n const sourceAccount = await this._horizon.loadAccount(this.keypair.publicKey());\n\n const asset =\n assetCode && assetIssuer\n ? new Asset(assetCode, assetIssuer)\n : Asset.native();\n\n const tx = new TransactionBuilder(sourceAccount, {\n fee: \"100\",\n networkPassphrase,\n })\n .addOperation(Operation.payment({ destination: to, asset, amount }))\n .setTimeout(180)\n .build();\n\n tx.sign(this.keypair);\n const result = await this._horizon.submitTransaction(tx);\n return { hash: result.hash };\n }\n\n // ─── Placeholders for lending / oracle / cross-chain (plug later) ────────────\n\n // async lendingSupply(asset: DexAsset, amount: string): Promise<{ hash: string }> { ... }\n // async lendingBorrow(asset: DexAsset, amount: string): Promise<{ hash: string }> { ... }\n // async getPrice(assetOrFeedId: string): Promise<{ price: string }> { ... }\n // async crossChainSwap(...): Promise<SwapResult> { ... }\n}\n","import { z } from \"zod\";\n\nexport const NetworkConfigSchema = z.object({\n horizonUrl: z.string().url(),\n sorobanRpcUrl: z.string().url(),\n friendbotUrl: z.string().url().optional(),\n});\n\nexport type NetworkConfig = z.infer<typeof NetworkConfigSchema>;\n\nexport const testnet: NetworkConfig = {\n horizonUrl: \"https://horizon-testnet.stellar.org\",\n sorobanRpcUrl: \"https://soroban-testnet.stellar.org\",\n friendbotUrl: \"https://friendbot.stellar.org\",\n};\n\nexport const mainnet: NetworkConfig = {\n horizonUrl: \"https://horizon.stellar.org\",\n sorobanRpcUrl: \"https://soroban-rpc.mainnet.stellar.gateway.fm\",\n};\n\nexport const networks = { testnet, mainnet } as const;\nexport type NetworkName = keyof typeof networks;\n\nexport function getNetworkConfig(name: string): NetworkConfig {\n const parsed = z.enum([\"testnet\", \"mainnet\"]).safeParse(name);\n if (!parsed.success) throw new Error(`Invalid network: ${name}. Use \"testnet\" or \"mainnet\".`);\n return networks[parsed.data];\n}\n","/**\n * SoroSwap DEX client – quote via API, build + sign + submit for executeSwap.\n */\n\nimport { Keypair, TransactionBuilder, Networks } from \"@stellar/stellar-sdk\";\nimport { rpc } from \"@stellar/stellar-sdk\";\nimport type { NetworkConfig } from \"../config/networks.js\";\nimport { getNetworkConfig, type NetworkName } from \"../config/networks.js\";\nimport type { DexAsset, QuoteResult, SwapResult } from \"./types.js\";\n\nconst SOROSWAP_API_BASE = \"https://api.soroswap.finance\";\n\nfunction assetToApiString(asset: DexAsset): string {\n if (asset.contractId) return asset.contractId;\n if (asset.code && asset.issuer) return `${asset.code}:${asset.issuer}`;\n throw new Error(\"Asset must have contractId or code+issuer\");\n}\n\nfunction parseApiQuote(data: unknown): QuoteResult {\n const o = data as Record<string, unknown>;\n return {\n expectedIn: String(o?.expectedIn ?? o?.amountIn ?? \"0\"),\n expectedOut: String(o?.expectedOut ?? o?.amountOut ?? \"0\"),\n minOut: String(o?.minOut ?? o?.minimumAmountOut ?? o?.expectedOut ?? \"0\"),\n route: Array.isArray(o?.route) ? (o.route as string[]) : Array.isArray(o?.path) ? (o.path as string[]) : [],\n rawData: data,\n };\n}\n\nexport function createSoroSwapDexClient(\n networkConfig: NetworkConfig,\n apiKey?: string\n): { getQuote: (from: DexAsset, to: DexAsset, amount: string) => Promise<QuoteResult>; executeSwap: (secretKey: string, quote: QuoteResult) => Promise<SwapResult> } {\n const networkName: NetworkName = networkConfig.horizonUrl.includes(\"testnet\") ? \"testnet\" : \"mainnet\";\n const key = apiKey ?? process.env.SOROSWAP_API_KEY;\n\n async function getQuote(from: DexAsset, to: DexAsset, amount: string): Promise<QuoteResult> {\n const url = `${SOROSWAP_API_BASE}/quote?network=${networkName}`;\n const body = {\n assetIn: assetToApiString(from),\n assetOut: assetToApiString(to),\n amount: String(amount).trim(),\n tradeType: \"EXACT_IN\",\n protocols: [\"soroswap\", \"phoenix\", \"aqua\"],\n };\n const headers: Record<string, string> = { \"Content-Type\": \"application/json\" };\n if (key) headers[\"Authorization\"] = `Bearer ${key}`;\n const res = await fetch(url, { method: \"POST\", headers, body: JSON.stringify(body) });\n if (!res.ok) {\n const text = await res.text();\n throw new Error(`SoroSwap quote failed ${res.status}: ${text}`);\n }\n return parseApiQuote(await res.json());\n }\n\n async function executeSwap(secretKey: string, quote: QuoteResult): Promise<SwapResult> {\n if (!key) throw new Error(\"executeSwap requires SOROSWAP_API_KEY\");\n const keypair = Keypair.fromSecret(secretKey.trim());\n const fromAddress = keypair.publicKey();\n const buildUrl = `${SOROSWAP_API_BASE}/quote/build?network=${networkName}`;\n const buildRes = await fetch(buildUrl, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\", Authorization: `Bearer ${key}` },\n body: JSON.stringify({ quote: quote.rawData ?? quote, from: fromAddress, to: fromAddress }),\n });\n if (!buildRes.ok) throw new Error(`SoroSwap build failed ${buildRes.status}: ${await buildRes.text()}`);\n const buildData = (await buildRes.json()) as { xdr?: string };\n const xdrBase64 = buildData?.xdr;\n if (!xdrBase64 || typeof xdrBase64 !== \"string\") throw new Error(\"SoroSwap build response missing xdr\");\n const config = getNetworkConfig(networkName);\n const networkPassphrase = config.horizonUrl.includes(\"testnet\") ? Networks.TESTNET : Networks.PUBLIC;\n const tx = TransactionBuilder.fromXDR(xdrBase64, networkPassphrase);\n tx.sign(keypair);\n const server = new rpc.Server(config.sorobanRpcUrl, { allowHttp: config.sorobanRpcUrl.startsWith(\"http:\") });\n const sendResult = await server.sendTransaction(tx);\n if (sendResult.errorResult) throw new Error(`Soroban sendTransaction failed: ${String(sendResult.errorResult)}`);\n return { hash: sendResult.hash, status: sendResult.status ?? \"PENDING\" };\n }\n\n return { getQuote, executeSwap };\n}\n","/**\n * DEX module – swap, quote, aggregator (SoroSwap).\n * Pluggable: add more DEXes by implementing DexClient.\n */\n\nimport type { NetworkConfig } from \"../config/networks.js\";\nimport type { DexAsset, QuoteResult, SwapResult } from \"./types.js\";\nimport { createSoroSwapDexClient } from \"./soroSwap.js\";\n\nexport type { DexAsset, QuoteResult, SwapResult } from \"./types.js\";\nexport { createSoroSwapDexClient } from \"./soroSwap.js\";\n\nexport interface DexClient {\n getQuote(fromAsset: DexAsset, toAsset: DexAsset, amount: string): Promise<QuoteResult>;\n executeSwap(secretKey: string, quote: QuoteResult): Promise<SwapResult>;\n}\n\n/**\n * Build a DEX client for the given network (SoroSwap aggregator).\n */\nexport function createDexClient(networkConfig: NetworkConfig, apiKey?: string): DexClient {\n return createSoroSwapDexClient(networkConfig, apiKey);\n}\n","/**\n * Stellar asset identifiers and contract addresses.\n * Centralized for mainnet/testnet (mirrors Mantle DevKit \"Token Addresses\").\n */\n\nexport type StellarAsset = { code: string; issuer: string } | { contractId: string };\n\nexport const TESTNET_ASSETS = {\n XLM: { contractId: \"CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC\" },\n USDC: { contractId: \"CBBHRKEP5M3NUDRISGLJKGHDHX3DA2CN2AZBQY6WLVUJ7VNLGSKBDUCM\" },\n /** Classic testnet USDC */\n AUSDC: { code: \"AUSDC\", issuer: \"GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN\" },\n} as const;\n\nexport const MAINNET_ASSETS = {\n XLM: { contractId: \"CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA\" },\n USDC: { contractId: \"CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75\" },\n} as const;\n\nexport const SOROSWAP_AGGREGATOR = {\n testnet: \"CCJUD55AG6W5HAI5LRVNKAE5WDP5XGZBUDS5WNTIVDU7O264UZZE7BRD\",\n mainnet: \"CAG5LRYQ5JVEUI5TEID72EYOVX44TTUJT5BQR2J6J77FH65PCCFAJDDH\",\n} as const;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKA,IAAAA,sBAAiF;;;ACLjF,iBAAkB;AAEX,IAAM,sBAAsB,aAAE,OAAO;AAAA,EAC1C,YAAY,aAAE,OAAO,EAAE,IAAI;AAAA,EAC3B,eAAe,aAAE,OAAO,EAAE,IAAI;AAAA,EAC9B,cAAc,aAAE,OAAO,EAAE,IAAI,EAAE,SAAS;AAC1C,CAAC;AAIM,IAAM,UAAyB;AAAA,EACpC,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,cAAc;AAChB;AAEO,IAAM,UAAyB;AAAA,EACpC,YAAY;AAAA,EACZ,eAAe;AACjB;AAEO,IAAM,WAAW,EAAE,SAAS,QAAQ;AAGpC,SAAS,iBAAiB,MAA6B;AAC5D,QAAM,SAAS,aAAE,KAAK,CAAC,WAAW,SAAS,CAAC,EAAE,UAAU,IAAI;AAC5D,MAAI,CAAC,OAAO,QAAS,OAAM,IAAI,MAAM,oBAAoB,IAAI,+BAA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keypair } from '@stellar/stellar-sdk';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
declare const NetworkConfigSchema: z.ZodObject<{
|
|
5
|
+
horizonUrl: z.ZodString;
|
|
6
|
+
sorobanRpcUrl: z.ZodString;
|
|
7
|
+
friendbotUrl: z.ZodOptional<z.ZodString>;
|
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
|
9
|
+
horizonUrl: string;
|
|
10
|
+
sorobanRpcUrl: string;
|
|
11
|
+
friendbotUrl?: string | undefined;
|
|
12
|
+
}, {
|
|
13
|
+
horizonUrl: string;
|
|
14
|
+
sorobanRpcUrl: string;
|
|
15
|
+
friendbotUrl?: string | undefined;
|
|
16
|
+
}>;
|
|
17
|
+
type NetworkConfig = z.infer<typeof NetworkConfigSchema>;
|
|
18
|
+
declare const networks: {
|
|
19
|
+
readonly testnet: {
|
|
20
|
+
horizonUrl: string;
|
|
21
|
+
sorobanRpcUrl: string;
|
|
22
|
+
friendbotUrl?: string | undefined;
|
|
23
|
+
};
|
|
24
|
+
readonly mainnet: {
|
|
25
|
+
horizonUrl: string;
|
|
26
|
+
sorobanRpcUrl: string;
|
|
27
|
+
friendbotUrl?: string | undefined;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
type NetworkName = keyof typeof networks;
|
|
31
|
+
declare function getNetworkConfig(name: string): NetworkConfig;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* DEX / swap types (Stellar: asset = code+issuer or contractId).
|
|
35
|
+
*/
|
|
36
|
+
interface DexAsset {
|
|
37
|
+
contractId?: string;
|
|
38
|
+
code?: string;
|
|
39
|
+
issuer?: string;
|
|
40
|
+
}
|
|
41
|
+
interface QuoteResult {
|
|
42
|
+
expectedIn: string;
|
|
43
|
+
expectedOut: string;
|
|
44
|
+
minOut: string;
|
|
45
|
+
route: string[];
|
|
46
|
+
rawData?: unknown;
|
|
47
|
+
}
|
|
48
|
+
interface SwapResult {
|
|
49
|
+
hash: string;
|
|
50
|
+
status: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* DEX module – swap, quote, aggregator (SoroSwap).
|
|
55
|
+
* Pluggable: add more DEXes by implementing DexClient.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
interface DexClient {
|
|
59
|
+
getQuote(fromAsset: DexAsset, toAsset: DexAsset, amount: string): Promise<QuoteResult>;
|
|
60
|
+
executeSwap(secretKey: string, quote: QuoteResult): Promise<SwapResult>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Build a DEX client for the given network (SoroSwap aggregator).
|
|
64
|
+
*/
|
|
65
|
+
declare function createDexClient(networkConfig: NetworkConfig, apiKey?: string): DexClient;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* StellarAgentKit – unified DeFi agent (MNTAgentKit-style API for Stellar).
|
|
69
|
+
* Constructor(secretKey, network) + initialize() then protocol methods.
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
type StellarNetwork = "mainnet" | "testnet";
|
|
73
|
+
declare class StellarAgentKit {
|
|
74
|
+
readonly keypair: Keypair;
|
|
75
|
+
readonly network: StellarNetwork;
|
|
76
|
+
readonly config: NetworkConfig;
|
|
77
|
+
private _initialized;
|
|
78
|
+
private _dex;
|
|
79
|
+
private _horizon;
|
|
80
|
+
constructor(secretKey: string, network: StellarNetwork);
|
|
81
|
+
/**
|
|
82
|
+
* Initialize clients (Horizon, Soroban RPC, protocol wrappers).
|
|
83
|
+
* Call after construction before using protocol methods.
|
|
84
|
+
*/
|
|
85
|
+
initialize(): Promise<this>;
|
|
86
|
+
private ensureInitialized;
|
|
87
|
+
/**
|
|
88
|
+
* Get a swap quote (exact-in). Uses SoroSwap aggregator (SoroSwap, Phoenix, Aqua).
|
|
89
|
+
*/
|
|
90
|
+
dexGetQuote(fromAsset: DexAsset, toAsset: DexAsset, amount: string): Promise<QuoteResult>;
|
|
91
|
+
/**
|
|
92
|
+
* Execute a swap using a prior quote.
|
|
93
|
+
*/
|
|
94
|
+
dexSwap(quote: QuoteResult): Promise<SwapResult>;
|
|
95
|
+
/**
|
|
96
|
+
* One-shot: get quote and execute swap (convenience).
|
|
97
|
+
*/
|
|
98
|
+
dexSwapExactIn(fromAsset: DexAsset, toAsset: DexAsset, amount: string): Promise<SwapResult>;
|
|
99
|
+
/**
|
|
100
|
+
* Send a native or custom-asset payment (Horizon).
|
|
101
|
+
* @param to - Destination account (G...)
|
|
102
|
+
* @param amount - Amount in display units (e.g. "10" for 10 XLM)
|
|
103
|
+
* @param assetCode - Optional; omit for native XLM
|
|
104
|
+
* @param assetIssuer - Optional; required if assetCode is set
|
|
105
|
+
*/
|
|
106
|
+
sendPayment(to: string, amount: string, assetCode?: string, assetIssuer?: string): Promise<{
|
|
107
|
+
hash: string;
|
|
108
|
+
}>;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Stellar asset identifiers and contract addresses.
|
|
113
|
+
* Centralized for mainnet/testnet (mirrors Mantle DevKit "Token Addresses").
|
|
114
|
+
*/
|
|
115
|
+
type StellarAsset = {
|
|
116
|
+
code: string;
|
|
117
|
+
issuer: string;
|
|
118
|
+
} | {
|
|
119
|
+
contractId: string;
|
|
120
|
+
};
|
|
121
|
+
declare const TESTNET_ASSETS: {
|
|
122
|
+
readonly XLM: {
|
|
123
|
+
readonly contractId: "CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC";
|
|
124
|
+
};
|
|
125
|
+
readonly USDC: {
|
|
126
|
+
readonly contractId: "CBBHRKEP5M3NUDRISGLJKGHDHX3DA2CN2AZBQY6WLVUJ7VNLGSKBDUCM";
|
|
127
|
+
};
|
|
128
|
+
/** Classic testnet USDC */
|
|
129
|
+
readonly AUSDC: {
|
|
130
|
+
readonly code: "AUSDC";
|
|
131
|
+
readonly issuer: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN";
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
declare const MAINNET_ASSETS: {
|
|
135
|
+
readonly XLM: {
|
|
136
|
+
readonly contractId: "CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA";
|
|
137
|
+
};
|
|
138
|
+
readonly USDC: {
|
|
139
|
+
readonly contractId: "CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75";
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
declare const SOROSWAP_AGGREGATOR: {
|
|
143
|
+
readonly testnet: "CCJUD55AG6W5HAI5LRVNKAE5WDP5XGZBUDS5WNTIVDU7O264UZZE7BRD";
|
|
144
|
+
readonly mainnet: "CAG5LRYQ5JVEUI5TEID72EYOVX44TTUJT5BQR2J6J77FH65PCCFAJDDH";
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export { type DexAsset, type DexClient, MAINNET_ASSETS, type NetworkConfig, type NetworkName, type QuoteResult, SOROSWAP_AGGREGATOR, StellarAgentKit, type StellarAsset, type StellarNetwork, type SwapResult, TESTNET_ASSETS, createDexClient, getNetworkConfig, networks };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Keypair } from '@stellar/stellar-sdk';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
declare const NetworkConfigSchema: z.ZodObject<{
|
|
5
|
+
horizonUrl: z.ZodString;
|
|
6
|
+
sorobanRpcUrl: z.ZodString;
|
|
7
|
+
friendbotUrl: z.ZodOptional<z.ZodString>;
|
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
|
9
|
+
horizonUrl: string;
|
|
10
|
+
sorobanRpcUrl: string;
|
|
11
|
+
friendbotUrl?: string | undefined;
|
|
12
|
+
}, {
|
|
13
|
+
horizonUrl: string;
|
|
14
|
+
sorobanRpcUrl: string;
|
|
15
|
+
friendbotUrl?: string | undefined;
|
|
16
|
+
}>;
|
|
17
|
+
type NetworkConfig = z.infer<typeof NetworkConfigSchema>;
|
|
18
|
+
declare const networks: {
|
|
19
|
+
readonly testnet: {
|
|
20
|
+
horizonUrl: string;
|
|
21
|
+
sorobanRpcUrl: string;
|
|
22
|
+
friendbotUrl?: string | undefined;
|
|
23
|
+
};
|
|
24
|
+
readonly mainnet: {
|
|
25
|
+
horizonUrl: string;
|
|
26
|
+
sorobanRpcUrl: string;
|
|
27
|
+
friendbotUrl?: string | undefined;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
type NetworkName = keyof typeof networks;
|
|
31
|
+
declare function getNetworkConfig(name: string): NetworkConfig;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* DEX / swap types (Stellar: asset = code+issuer or contractId).
|
|
35
|
+
*/
|
|
36
|
+
interface DexAsset {
|
|
37
|
+
contractId?: string;
|
|
38
|
+
code?: string;
|
|
39
|
+
issuer?: string;
|
|
40
|
+
}
|
|
41
|
+
interface QuoteResult {
|
|
42
|
+
expectedIn: string;
|
|
43
|
+
expectedOut: string;
|
|
44
|
+
minOut: string;
|
|
45
|
+
route: string[];
|
|
46
|
+
rawData?: unknown;
|
|
47
|
+
}
|
|
48
|
+
interface SwapResult {
|
|
49
|
+
hash: string;
|
|
50
|
+
status: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* DEX module – swap, quote, aggregator (SoroSwap).
|
|
55
|
+
* Pluggable: add more DEXes by implementing DexClient.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
interface DexClient {
|
|
59
|
+
getQuote(fromAsset: DexAsset, toAsset: DexAsset, amount: string): Promise<QuoteResult>;
|
|
60
|
+
executeSwap(secretKey: string, quote: QuoteResult): Promise<SwapResult>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Build a DEX client for the given network (SoroSwap aggregator).
|
|
64
|
+
*/
|
|
65
|
+
declare function createDexClient(networkConfig: NetworkConfig, apiKey?: string): DexClient;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* StellarAgentKit – unified DeFi agent (MNTAgentKit-style API for Stellar).
|
|
69
|
+
* Constructor(secretKey, network) + initialize() then protocol methods.
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
type StellarNetwork = "mainnet" | "testnet";
|
|
73
|
+
declare class StellarAgentKit {
|
|
74
|
+
readonly keypair: Keypair;
|
|
75
|
+
readonly network: StellarNetwork;
|
|
76
|
+
readonly config: NetworkConfig;
|
|
77
|
+
private _initialized;
|
|
78
|
+
private _dex;
|
|
79
|
+
private _horizon;
|
|
80
|
+
constructor(secretKey: string, network: StellarNetwork);
|
|
81
|
+
/**
|
|
82
|
+
* Initialize clients (Horizon, Soroban RPC, protocol wrappers).
|
|
83
|
+
* Call after construction before using protocol methods.
|
|
84
|
+
*/
|
|
85
|
+
initialize(): Promise<this>;
|
|
86
|
+
private ensureInitialized;
|
|
87
|
+
/**
|
|
88
|
+
* Get a swap quote (exact-in). Uses SoroSwap aggregator (SoroSwap, Phoenix, Aqua).
|
|
89
|
+
*/
|
|
90
|
+
dexGetQuote(fromAsset: DexAsset, toAsset: DexAsset, amount: string): Promise<QuoteResult>;
|
|
91
|
+
/**
|
|
92
|
+
* Execute a swap using a prior quote.
|
|
93
|
+
*/
|
|
94
|
+
dexSwap(quote: QuoteResult): Promise<SwapResult>;
|
|
95
|
+
/**
|
|
96
|
+
* One-shot: get quote and execute swap (convenience).
|
|
97
|
+
*/
|
|
98
|
+
dexSwapExactIn(fromAsset: DexAsset, toAsset: DexAsset, amount: string): Promise<SwapResult>;
|
|
99
|
+
/**
|
|
100
|
+
* Send a native or custom-asset payment (Horizon).
|
|
101
|
+
* @param to - Destination account (G...)
|
|
102
|
+
* @param amount - Amount in display units (e.g. "10" for 10 XLM)
|
|
103
|
+
* @param assetCode - Optional; omit for native XLM
|
|
104
|
+
* @param assetIssuer - Optional; required if assetCode is set
|
|
105
|
+
*/
|
|
106
|
+
sendPayment(to: string, amount: string, assetCode?: string, assetIssuer?: string): Promise<{
|
|
107
|
+
hash: string;
|
|
108
|
+
}>;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Stellar asset identifiers and contract addresses.
|
|
113
|
+
* Centralized for mainnet/testnet (mirrors Mantle DevKit "Token Addresses").
|
|
114
|
+
*/
|
|
115
|
+
type StellarAsset = {
|
|
116
|
+
code: string;
|
|
117
|
+
issuer: string;
|
|
118
|
+
} | {
|
|
119
|
+
contractId: string;
|
|
120
|
+
};
|
|
121
|
+
declare const TESTNET_ASSETS: {
|
|
122
|
+
readonly XLM: {
|
|
123
|
+
readonly contractId: "CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC";
|
|
124
|
+
};
|
|
125
|
+
readonly USDC: {
|
|
126
|
+
readonly contractId: "CBBHRKEP5M3NUDRISGLJKGHDHX3DA2CN2AZBQY6WLVUJ7VNLGSKBDUCM";
|
|
127
|
+
};
|
|
128
|
+
/** Classic testnet USDC */
|
|
129
|
+
readonly AUSDC: {
|
|
130
|
+
readonly code: "AUSDC";
|
|
131
|
+
readonly issuer: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN";
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
declare const MAINNET_ASSETS: {
|
|
135
|
+
readonly XLM: {
|
|
136
|
+
readonly contractId: "CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA";
|
|
137
|
+
};
|
|
138
|
+
readonly USDC: {
|
|
139
|
+
readonly contractId: "CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75";
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
declare const SOROSWAP_AGGREGATOR: {
|
|
143
|
+
readonly testnet: "CCJUD55AG6W5HAI5LRVNKAE5WDP5XGZBUDS5WNTIVDU7O264UZZE7BRD";
|
|
144
|
+
readonly mainnet: "CAG5LRYQ5JVEUI5TEID72EYOVX44TTUJT5BQR2J6J77FH65PCCFAJDDH";
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export { type DexAsset, type DexClient, MAINNET_ASSETS, type NetworkConfig, type NetworkName, type QuoteResult, SOROSWAP_AGGREGATOR, StellarAgentKit, type StellarAsset, type StellarNetwork, type SwapResult, TESTNET_ASSETS, createDexClient, getNetworkConfig, networks };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// src/agent.ts
|
|
2
|
+
import { Keypair as Keypair2, Asset, TransactionBuilder as TransactionBuilder2, Operation, Networks as Networks2, Horizon } from "@stellar/stellar-sdk";
|
|
3
|
+
|
|
4
|
+
// src/config/networks.ts
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
var NetworkConfigSchema = z.object({
|
|
7
|
+
horizonUrl: z.string().url(),
|
|
8
|
+
sorobanRpcUrl: z.string().url(),
|
|
9
|
+
friendbotUrl: z.string().url().optional()
|
|
10
|
+
});
|
|
11
|
+
var testnet = {
|
|
12
|
+
horizonUrl: "https://horizon-testnet.stellar.org",
|
|
13
|
+
sorobanRpcUrl: "https://soroban-testnet.stellar.org",
|
|
14
|
+
friendbotUrl: "https://friendbot.stellar.org"
|
|
15
|
+
};
|
|
16
|
+
var mainnet = {
|
|
17
|
+
horizonUrl: "https://horizon.stellar.org",
|
|
18
|
+
sorobanRpcUrl: "https://soroban-rpc.mainnet.stellar.gateway.fm"
|
|
19
|
+
};
|
|
20
|
+
var networks = { testnet, mainnet };
|
|
21
|
+
function getNetworkConfig(name) {
|
|
22
|
+
const parsed = z.enum(["testnet", "mainnet"]).safeParse(name);
|
|
23
|
+
if (!parsed.success) throw new Error(`Invalid network: ${name}. Use "testnet" or "mainnet".`);
|
|
24
|
+
return networks[parsed.data];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/dex/soroSwap.ts
|
|
28
|
+
import { Keypair, TransactionBuilder, Networks } from "@stellar/stellar-sdk";
|
|
29
|
+
import { rpc } from "@stellar/stellar-sdk";
|
|
30
|
+
var SOROSWAP_API_BASE = "https://api.soroswap.finance";
|
|
31
|
+
function assetToApiString(asset) {
|
|
32
|
+
if (asset.contractId) return asset.contractId;
|
|
33
|
+
if (asset.code && asset.issuer) return `${asset.code}:${asset.issuer}`;
|
|
34
|
+
throw new Error("Asset must have contractId or code+issuer");
|
|
35
|
+
}
|
|
36
|
+
function parseApiQuote(data) {
|
|
37
|
+
const o = data;
|
|
38
|
+
return {
|
|
39
|
+
expectedIn: String(o?.expectedIn ?? o?.amountIn ?? "0"),
|
|
40
|
+
expectedOut: String(o?.expectedOut ?? o?.amountOut ?? "0"),
|
|
41
|
+
minOut: String(o?.minOut ?? o?.minimumAmountOut ?? o?.expectedOut ?? "0"),
|
|
42
|
+
route: Array.isArray(o?.route) ? o.route : Array.isArray(o?.path) ? o.path : [],
|
|
43
|
+
rawData: data
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function createSoroSwapDexClient(networkConfig, apiKey) {
|
|
47
|
+
const networkName = networkConfig.horizonUrl.includes("testnet") ? "testnet" : "mainnet";
|
|
48
|
+
const key = apiKey ?? process.env.SOROSWAP_API_KEY;
|
|
49
|
+
async function getQuote(from, to, amount) {
|
|
50
|
+
const url = `${SOROSWAP_API_BASE}/quote?network=${networkName}`;
|
|
51
|
+
const body = {
|
|
52
|
+
assetIn: assetToApiString(from),
|
|
53
|
+
assetOut: assetToApiString(to),
|
|
54
|
+
amount: String(amount).trim(),
|
|
55
|
+
tradeType: "EXACT_IN",
|
|
56
|
+
protocols: ["soroswap", "phoenix", "aqua"]
|
|
57
|
+
};
|
|
58
|
+
const headers = { "Content-Type": "application/json" };
|
|
59
|
+
if (key) headers["Authorization"] = `Bearer ${key}`;
|
|
60
|
+
const res = await fetch(url, { method: "POST", headers, body: JSON.stringify(body) });
|
|
61
|
+
if (!res.ok) {
|
|
62
|
+
const text = await res.text();
|
|
63
|
+
throw new Error(`SoroSwap quote failed ${res.status}: ${text}`);
|
|
64
|
+
}
|
|
65
|
+
return parseApiQuote(await res.json());
|
|
66
|
+
}
|
|
67
|
+
async function executeSwap(secretKey, quote) {
|
|
68
|
+
if (!key) throw new Error("executeSwap requires SOROSWAP_API_KEY");
|
|
69
|
+
const keypair = Keypair.fromSecret(secretKey.trim());
|
|
70
|
+
const fromAddress = keypair.publicKey();
|
|
71
|
+
const buildUrl = `${SOROSWAP_API_BASE}/quote/build?network=${networkName}`;
|
|
72
|
+
const buildRes = await fetch(buildUrl, {
|
|
73
|
+
method: "POST",
|
|
74
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${key}` },
|
|
75
|
+
body: JSON.stringify({ quote: quote.rawData ?? quote, from: fromAddress, to: fromAddress })
|
|
76
|
+
});
|
|
77
|
+
if (!buildRes.ok) throw new Error(`SoroSwap build failed ${buildRes.status}: ${await buildRes.text()}`);
|
|
78
|
+
const buildData = await buildRes.json();
|
|
79
|
+
const xdrBase64 = buildData?.xdr;
|
|
80
|
+
if (!xdrBase64 || typeof xdrBase64 !== "string") throw new Error("SoroSwap build response missing xdr");
|
|
81
|
+
const config = getNetworkConfig(networkName);
|
|
82
|
+
const networkPassphrase = config.horizonUrl.includes("testnet") ? Networks.TESTNET : Networks.PUBLIC;
|
|
83
|
+
const tx = TransactionBuilder.fromXDR(xdrBase64, networkPassphrase);
|
|
84
|
+
tx.sign(keypair);
|
|
85
|
+
const server = new rpc.Server(config.sorobanRpcUrl, { allowHttp: config.sorobanRpcUrl.startsWith("http:") });
|
|
86
|
+
const sendResult = await server.sendTransaction(tx);
|
|
87
|
+
if (sendResult.errorResult) throw new Error(`Soroban sendTransaction failed: ${String(sendResult.errorResult)}`);
|
|
88
|
+
return { hash: sendResult.hash, status: sendResult.status ?? "PENDING" };
|
|
89
|
+
}
|
|
90
|
+
return { getQuote, executeSwap };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/dex/index.ts
|
|
94
|
+
function createDexClient(networkConfig, apiKey) {
|
|
95
|
+
return createSoroSwapDexClient(networkConfig, apiKey);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// src/agent.ts
|
|
99
|
+
var StellarAgentKit = class {
|
|
100
|
+
keypair;
|
|
101
|
+
network;
|
|
102
|
+
config;
|
|
103
|
+
_initialized = false;
|
|
104
|
+
_dex = null;
|
|
105
|
+
_horizon = null;
|
|
106
|
+
constructor(secretKey, network) {
|
|
107
|
+
this.keypair = Keypair2.fromSecret(secretKey.trim());
|
|
108
|
+
this.network = network;
|
|
109
|
+
this.config = getNetworkConfig(network);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Initialize clients (Horizon, Soroban RPC, protocol wrappers).
|
|
113
|
+
* Call after construction before using protocol methods.
|
|
114
|
+
*/
|
|
115
|
+
async initialize() {
|
|
116
|
+
this._horizon = new Horizon.Server(this.config.horizonUrl);
|
|
117
|
+
this._dex = createDexClient(this.config, process.env.SOROSWAP_API_KEY);
|
|
118
|
+
this._initialized = true;
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
ensureInitialized() {
|
|
122
|
+
if (!this._initialized || !this._dex) {
|
|
123
|
+
throw new Error("StellarAgentKit not initialized. Call await agent.initialize() first.");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// ─── DEX Operations (mirror Mantle agniSwap / executeSwap) ─────────────────
|
|
127
|
+
/**
|
|
128
|
+
* Get a swap quote (exact-in). Uses SoroSwap aggregator (SoroSwap, Phoenix, Aqua).
|
|
129
|
+
*/
|
|
130
|
+
async dexGetQuote(fromAsset, toAsset, amount) {
|
|
131
|
+
this.ensureInitialized();
|
|
132
|
+
return this._dex.getQuote(fromAsset, toAsset, amount);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Execute a swap using a prior quote.
|
|
136
|
+
*/
|
|
137
|
+
async dexSwap(quote) {
|
|
138
|
+
this.ensureInitialized();
|
|
139
|
+
return this._dex.executeSwap(this.keypair.secret(), quote);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* One-shot: get quote and execute swap (convenience).
|
|
143
|
+
*/
|
|
144
|
+
async dexSwapExactIn(fromAsset, toAsset, amount) {
|
|
145
|
+
const quote = await this.dexGetQuote(fromAsset, toAsset, amount);
|
|
146
|
+
return this.dexSwap(quote);
|
|
147
|
+
}
|
|
148
|
+
// ─── Payments (Horizon) ────────────────────────────────────────────────────
|
|
149
|
+
/**
|
|
150
|
+
* Send a native or custom-asset payment (Horizon).
|
|
151
|
+
* @param to - Destination account (G...)
|
|
152
|
+
* @param amount - Amount in display units (e.g. "10" for 10 XLM)
|
|
153
|
+
* @param assetCode - Optional; omit for native XLM
|
|
154
|
+
* @param assetIssuer - Optional; required if assetCode is set
|
|
155
|
+
*/
|
|
156
|
+
async sendPayment(to, amount, assetCode, assetIssuer) {
|
|
157
|
+
this.ensureInitialized();
|
|
158
|
+
if (!this._horizon) throw new Error("Horizon not initialized");
|
|
159
|
+
const networkPassphrase = this.network === "testnet" ? Networks2.TESTNET : Networks2.PUBLIC;
|
|
160
|
+
const sourceAccount = await this._horizon.loadAccount(this.keypair.publicKey());
|
|
161
|
+
const asset = assetCode && assetIssuer ? new Asset(assetCode, assetIssuer) : Asset.native();
|
|
162
|
+
const tx = new TransactionBuilder2(sourceAccount, {
|
|
163
|
+
fee: "100",
|
|
164
|
+
networkPassphrase
|
|
165
|
+
}).addOperation(Operation.payment({ destination: to, asset, amount })).setTimeout(180).build();
|
|
166
|
+
tx.sign(this.keypair);
|
|
167
|
+
const result = await this._horizon.submitTransaction(tx);
|
|
168
|
+
return { hash: result.hash };
|
|
169
|
+
}
|
|
170
|
+
// ─── Placeholders for lending / oracle / cross-chain (plug later) ────────────
|
|
171
|
+
// async lendingSupply(asset: DexAsset, amount: string): Promise<{ hash: string }> { ... }
|
|
172
|
+
// async lendingBorrow(asset: DexAsset, amount: string): Promise<{ hash: string }> { ... }
|
|
173
|
+
// async getPrice(assetOrFeedId: string): Promise<{ price: string }> { ... }
|
|
174
|
+
// async crossChainSwap(...): Promise<SwapResult> { ... }
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
// src/config/assets.ts
|
|
178
|
+
var TESTNET_ASSETS = {
|
|
179
|
+
XLM: { contractId: "CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC" },
|
|
180
|
+
USDC: { contractId: "CBBHRKEP5M3NUDRISGLJKGHDHX3DA2CN2AZBQY6WLVUJ7VNLGSKBDUCM" },
|
|
181
|
+
/** Classic testnet USDC */
|
|
182
|
+
AUSDC: { code: "AUSDC", issuer: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN" }
|
|
183
|
+
};
|
|
184
|
+
var MAINNET_ASSETS = {
|
|
185
|
+
XLM: { contractId: "CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA" },
|
|
186
|
+
USDC: { contractId: "CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75" }
|
|
187
|
+
};
|
|
188
|
+
var SOROSWAP_AGGREGATOR = {
|
|
189
|
+
testnet: "CCJUD55AG6W5HAI5LRVNKAE5WDP5XGZBUDS5WNTIVDU7O264UZZE7BRD",
|
|
190
|
+
mainnet: "CAG5LRYQ5JVEUI5TEID72EYOVX44TTUJT5BQR2J6J77FH65PCCFAJDDH"
|
|
191
|
+
};
|
|
192
|
+
export {
|
|
193
|
+
MAINNET_ASSETS,
|
|
194
|
+
SOROSWAP_AGGREGATOR,
|
|
195
|
+
StellarAgentKit,
|
|
196
|
+
TESTNET_ASSETS,
|
|
197
|
+
createDexClient,
|
|
198
|
+
getNetworkConfig,
|
|
199
|
+
networks
|
|
200
|
+
};
|
|
201
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/agent.ts","../src/config/networks.ts","../src/dex/soroSwap.ts","../src/dex/index.ts","../src/config/assets.ts"],"sourcesContent":["/**\n * StellarAgentKit – unified DeFi agent (MNTAgentKit-style API for Stellar).\n * Constructor(secretKey, network) + initialize() then protocol methods.\n */\n\nimport { Keypair, Asset, TransactionBuilder, Operation, Networks, Horizon } from \"@stellar/stellar-sdk\";\nimport { getNetworkConfig, type NetworkConfig } from \"./config/networks.js\";\nimport { createDexClient, type DexAsset, type QuoteResult, type SwapResult } from \"./dex/index.js\";\n\nexport type StellarNetwork = \"mainnet\" | \"testnet\";\n\nexport class StellarAgentKit {\n public readonly keypair: Keypair;\n public readonly network: StellarNetwork;\n public readonly config: NetworkConfig;\n private _initialized = false;\n private _dex: ReturnType<typeof createDexClient> | null = null;\n private _horizon: Horizon.Server | null = null;\n\n constructor(secretKey: string, network: StellarNetwork) {\n this.keypair = Keypair.fromSecret(secretKey.trim());\n this.network = network;\n this.config = getNetworkConfig(network);\n }\n\n /**\n * Initialize clients (Horizon, Soroban RPC, protocol wrappers).\n * Call after construction before using protocol methods.\n */\n async initialize(): Promise<this> {\n this._horizon = new Horizon.Server(this.config.horizonUrl);\n this._dex = createDexClient(this.config, process.env.SOROSWAP_API_KEY);\n this._initialized = true;\n return this;\n }\n\n private ensureInitialized(): void {\n if (!this._initialized || !this._dex) {\n throw new Error(\"StellarAgentKit not initialized. Call await agent.initialize() first.\");\n }\n }\n\n // ─── DEX Operations (mirror Mantle agniSwap / executeSwap) ─────────────────\n\n /**\n * Get a swap quote (exact-in). Uses SoroSwap aggregator (SoroSwap, Phoenix, Aqua).\n */\n async dexGetQuote(\n fromAsset: DexAsset,\n toAsset: DexAsset,\n amount: string\n ): Promise<QuoteResult> {\n this.ensureInitialized();\n return this._dex!.getQuote(fromAsset, toAsset, amount);\n }\n\n /**\n * Execute a swap using a prior quote.\n */\n async dexSwap(quote: QuoteResult): Promise<SwapResult> {\n this.ensureInitialized();\n return this._dex!.executeSwap(this.keypair.secret(), quote);\n }\n\n /**\n * One-shot: get quote and execute swap (convenience).\n */\n async dexSwapExactIn(\n fromAsset: DexAsset,\n toAsset: DexAsset,\n amount: string\n ): Promise<SwapResult> {\n const quote = await this.dexGetQuote(fromAsset, toAsset, amount);\n return this.dexSwap(quote);\n }\n\n // ─── Payments (Horizon) ────────────────────────────────────────────────────\n\n /**\n * Send a native or custom-asset payment (Horizon).\n * @param to - Destination account (G...)\n * @param amount - Amount in display units (e.g. \"10\" for 10 XLM)\n * @param assetCode - Optional; omit for native XLM\n * @param assetIssuer - Optional; required if assetCode is set\n */\n async sendPayment(\n to: string,\n amount: string,\n assetCode?: string,\n assetIssuer?: string\n ): Promise<{ hash: string }> {\n this.ensureInitialized();\n if (!this._horizon) throw new Error(\"Horizon not initialized\");\n\n const networkPassphrase =\n this.network === \"testnet\" ? Networks.TESTNET : Networks.PUBLIC;\n const sourceAccount = await this._horizon.loadAccount(this.keypair.publicKey());\n\n const asset =\n assetCode && assetIssuer\n ? new Asset(assetCode, assetIssuer)\n : Asset.native();\n\n const tx = new TransactionBuilder(sourceAccount, {\n fee: \"100\",\n networkPassphrase,\n })\n .addOperation(Operation.payment({ destination: to, asset, amount }))\n .setTimeout(180)\n .build();\n\n tx.sign(this.keypair);\n const result = await this._horizon.submitTransaction(tx);\n return { hash: result.hash };\n }\n\n // ─── Placeholders for lending / oracle / cross-chain (plug later) ────────────\n\n // async lendingSupply(asset: DexAsset, amount: string): Promise<{ hash: string }> { ... }\n // async lendingBorrow(asset: DexAsset, amount: string): Promise<{ hash: string }> { ... }\n // async getPrice(assetOrFeedId: string): Promise<{ price: string }> { ... }\n // async crossChainSwap(...): Promise<SwapResult> { ... }\n}\n","import { z } from \"zod\";\n\nexport const NetworkConfigSchema = z.object({\n horizonUrl: z.string().url(),\n sorobanRpcUrl: z.string().url(),\n friendbotUrl: z.string().url().optional(),\n});\n\nexport type NetworkConfig = z.infer<typeof NetworkConfigSchema>;\n\nexport const testnet: NetworkConfig = {\n horizonUrl: \"https://horizon-testnet.stellar.org\",\n sorobanRpcUrl: \"https://soroban-testnet.stellar.org\",\n friendbotUrl: \"https://friendbot.stellar.org\",\n};\n\nexport const mainnet: NetworkConfig = {\n horizonUrl: \"https://horizon.stellar.org\",\n sorobanRpcUrl: \"https://soroban-rpc.mainnet.stellar.gateway.fm\",\n};\n\nexport const networks = { testnet, mainnet } as const;\nexport type NetworkName = keyof typeof networks;\n\nexport function getNetworkConfig(name: string): NetworkConfig {\n const parsed = z.enum([\"testnet\", \"mainnet\"]).safeParse(name);\n if (!parsed.success) throw new Error(`Invalid network: ${name}. Use \"testnet\" or \"mainnet\".`);\n return networks[parsed.data];\n}\n","/**\n * SoroSwap DEX client – quote via API, build + sign + submit for executeSwap.\n */\n\nimport { Keypair, TransactionBuilder, Networks } from \"@stellar/stellar-sdk\";\nimport { rpc } from \"@stellar/stellar-sdk\";\nimport type { NetworkConfig } from \"../config/networks.js\";\nimport { getNetworkConfig, type NetworkName } from \"../config/networks.js\";\nimport type { DexAsset, QuoteResult, SwapResult } from \"./types.js\";\n\nconst SOROSWAP_API_BASE = \"https://api.soroswap.finance\";\n\nfunction assetToApiString(asset: DexAsset): string {\n if (asset.contractId) return asset.contractId;\n if (asset.code && asset.issuer) return `${asset.code}:${asset.issuer}`;\n throw new Error(\"Asset must have contractId or code+issuer\");\n}\n\nfunction parseApiQuote(data: unknown): QuoteResult {\n const o = data as Record<string, unknown>;\n return {\n expectedIn: String(o?.expectedIn ?? o?.amountIn ?? \"0\"),\n expectedOut: String(o?.expectedOut ?? o?.amountOut ?? \"0\"),\n minOut: String(o?.minOut ?? o?.minimumAmountOut ?? o?.expectedOut ?? \"0\"),\n route: Array.isArray(o?.route) ? (o.route as string[]) : Array.isArray(o?.path) ? (o.path as string[]) : [],\n rawData: data,\n };\n}\n\nexport function createSoroSwapDexClient(\n networkConfig: NetworkConfig,\n apiKey?: string\n): { getQuote: (from: DexAsset, to: DexAsset, amount: string) => Promise<QuoteResult>; executeSwap: (secretKey: string, quote: QuoteResult) => Promise<SwapResult> } {\n const networkName: NetworkName = networkConfig.horizonUrl.includes(\"testnet\") ? \"testnet\" : \"mainnet\";\n const key = apiKey ?? process.env.SOROSWAP_API_KEY;\n\n async function getQuote(from: DexAsset, to: DexAsset, amount: string): Promise<QuoteResult> {\n const url = `${SOROSWAP_API_BASE}/quote?network=${networkName}`;\n const body = {\n assetIn: assetToApiString(from),\n assetOut: assetToApiString(to),\n amount: String(amount).trim(),\n tradeType: \"EXACT_IN\",\n protocols: [\"soroswap\", \"phoenix\", \"aqua\"],\n };\n const headers: Record<string, string> = { \"Content-Type\": \"application/json\" };\n if (key) headers[\"Authorization\"] = `Bearer ${key}`;\n const res = await fetch(url, { method: \"POST\", headers, body: JSON.stringify(body) });\n if (!res.ok) {\n const text = await res.text();\n throw new Error(`SoroSwap quote failed ${res.status}: ${text}`);\n }\n return parseApiQuote(await res.json());\n }\n\n async function executeSwap(secretKey: string, quote: QuoteResult): Promise<SwapResult> {\n if (!key) throw new Error(\"executeSwap requires SOROSWAP_API_KEY\");\n const keypair = Keypair.fromSecret(secretKey.trim());\n const fromAddress = keypair.publicKey();\n const buildUrl = `${SOROSWAP_API_BASE}/quote/build?network=${networkName}`;\n const buildRes = await fetch(buildUrl, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\", Authorization: `Bearer ${key}` },\n body: JSON.stringify({ quote: quote.rawData ?? quote, from: fromAddress, to: fromAddress }),\n });\n if (!buildRes.ok) throw new Error(`SoroSwap build failed ${buildRes.status}: ${await buildRes.text()}`);\n const buildData = (await buildRes.json()) as { xdr?: string };\n const xdrBase64 = buildData?.xdr;\n if (!xdrBase64 || typeof xdrBase64 !== \"string\") throw new Error(\"SoroSwap build response missing xdr\");\n const config = getNetworkConfig(networkName);\n const networkPassphrase = config.horizonUrl.includes(\"testnet\") ? Networks.TESTNET : Networks.PUBLIC;\n const tx = TransactionBuilder.fromXDR(xdrBase64, networkPassphrase);\n tx.sign(keypair);\n const server = new rpc.Server(config.sorobanRpcUrl, { allowHttp: config.sorobanRpcUrl.startsWith(\"http:\") });\n const sendResult = await server.sendTransaction(tx);\n if (sendResult.errorResult) throw new Error(`Soroban sendTransaction failed: ${String(sendResult.errorResult)}`);\n return { hash: sendResult.hash, status: sendResult.status ?? \"PENDING\" };\n }\n\n return { getQuote, executeSwap };\n}\n","/**\n * DEX module – swap, quote, aggregator (SoroSwap).\n * Pluggable: add more DEXes by implementing DexClient.\n */\n\nimport type { NetworkConfig } from \"../config/networks.js\";\nimport type { DexAsset, QuoteResult, SwapResult } from \"./types.js\";\nimport { createSoroSwapDexClient } from \"./soroSwap.js\";\n\nexport type { DexAsset, QuoteResult, SwapResult } from \"./types.js\";\nexport { createSoroSwapDexClient } from \"./soroSwap.js\";\n\nexport interface DexClient {\n getQuote(fromAsset: DexAsset, toAsset: DexAsset, amount: string): Promise<QuoteResult>;\n executeSwap(secretKey: string, quote: QuoteResult): Promise<SwapResult>;\n}\n\n/**\n * Build a DEX client for the given network (SoroSwap aggregator).\n */\nexport function createDexClient(networkConfig: NetworkConfig, apiKey?: string): DexClient {\n return createSoroSwapDexClient(networkConfig, apiKey);\n}\n","/**\n * Stellar asset identifiers and contract addresses.\n * Centralized for mainnet/testnet (mirrors Mantle DevKit \"Token Addresses\").\n */\n\nexport type StellarAsset = { code: string; issuer: string } | { contractId: string };\n\nexport const TESTNET_ASSETS = {\n XLM: { contractId: \"CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC\" },\n USDC: { contractId: \"CBBHRKEP5M3NUDRISGLJKGHDHX3DA2CN2AZBQY6WLVUJ7VNLGSKBDUCM\" },\n /** Classic testnet USDC */\n AUSDC: { code: \"AUSDC\", issuer: \"GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN\" },\n} as const;\n\nexport const MAINNET_ASSETS =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C,KAAK,SAAU,OAAM,IAAI,MAAM,yBAAyB;AAE7D,UAAM,oBACJ,KAAK,YAAY,YAAYC,UAAS,UAAUA,UAAS;AAC3D,UAAM,gBAAgB,MAAM,KAAK,SAAS,YAAY,KAAK,QAAQ,UAAU,CAAC;AAE9E,UAAM,QACJ,aAAa,cACT,IAAI,MAAM,WAAW,WAAW,IAChC,MAAM,OAAO;AAEnB,UAAM,KAAK,IAAIC,oBAAmB,eAAe;AAAA,MAC/C,KAAK;AAAA,MACL;AAAA,IACF,CAAC,EACE,aAAa,UAAU,QAAQ,EAAE,aAAa,IAAI,OAAO,OAAO,CAAC,CAAC,EAClE,WAAW,GAAG,EACd,MAAM;AAET,OAAG,KAAK,KAAK,OAAO;AACpB,UAAM,SAAS,MAAM,KAAK,SAAS,kBAAkB,EAAE;AACvD,WAAO,EAAE,MAAM,OAAO,KAAK;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAQF;;;AInHO,IAAM,iBAAiB;AAAA,EAC5B,KAAK,EAAE,YAAY,2DAA2D;AAAA,EAC9E,MAAM,EAAE,YAAY,2DAA2D;AAAA;AAAA,EAE/E,OAAO,EAAE,MAAM,SAAS,QAAQ,2DAA2D;AAC7F;AAEO,IAAM,iBAAiB;AAAA,EAC5B,KAAK,EAAE,YAAY,2DAA2D;AAAA,EAC9E,MAAM,EAAE,YAAY,2DAA2D;AACjF;AAEO,IAAM,sBAAsB;AAAA,EACjC,SAAS;AAAA,EACT,SAAS;AACX;","names":["Keypair","TransactionBuilder","Networks","Keypair","Networks","TransactionBuilder"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "stellar-agent-kit",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Unified TypeScript SDK for Stellar DeFi – DEX, lending, oracles, payments",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsup",
|
|
22
|
+
"dev": "tsup --watch",
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"prepublishOnly": "npm run build"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"stellar",
|
|
28
|
+
"soroban",
|
|
29
|
+
"defi",
|
|
30
|
+
"dex",
|
|
31
|
+
"swap",
|
|
32
|
+
"lending",
|
|
33
|
+
"oracle",
|
|
34
|
+
"agent",
|
|
35
|
+
"sdk",
|
|
36
|
+
"typescript"
|
|
37
|
+
],
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@stellar/stellar-sdk": "^14.0.0",
|
|
40
|
+
"zod": "^3.23.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"tsup": "^8.5.0",
|
|
44
|
+
"typescript": "^5.3.0"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=18"
|
|
48
|
+
},
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "git+https://github.com/codewmilan/stellar-agent-kit.git"
|
|
52
|
+
},
|
|
53
|
+
"license": "MIT",
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public"
|
|
56
|
+
}
|
|
57
|
+
}
|