@stellar-agent-kit/plugin-asset 0.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/LICENSE +201 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +741 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of tracking or otherwise improving the Work,
|
|
59
|
+
but excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Stellar Development Foundation
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
200
|
+
implied. See the License for the specific language governing
|
|
201
|
+
permissions and limitations under the License.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Action, Plugin } from '@stellar-agent-kit/core';
|
|
2
|
+
|
|
3
|
+
declare const transfer: Action;
|
|
4
|
+
|
|
5
|
+
declare const pathPaymentStrictSend: Action;
|
|
6
|
+
|
|
7
|
+
declare const pathPaymentStrictReceive: Action;
|
|
8
|
+
|
|
9
|
+
declare const trustlineAdd: Action;
|
|
10
|
+
declare const trustlineRemove: Action;
|
|
11
|
+
|
|
12
|
+
declare const balance: Action;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* One-shot helper for the classic Stellar issuance pattern:
|
|
16
|
+
* issuer wallet pays the distribution account → distribution trustlines the asset → issuer pays N tokens.
|
|
17
|
+
*
|
|
18
|
+
* Assumes the agent's wallet IS the issuer. The distribution account must already exist;
|
|
19
|
+
* use a separate call (e.g. CreateAccount) or fund via Friendbot in advance.
|
|
20
|
+
*
|
|
21
|
+
* NOTE: For production issuance, set the issuer's `auth_required` / `set_options(home_domain, ...)`
|
|
22
|
+
* via ASSET_SET_OPTIONS first.
|
|
23
|
+
*/
|
|
24
|
+
declare const issue: Action;
|
|
25
|
+
|
|
26
|
+
declare const setOptions: Action;
|
|
27
|
+
|
|
28
|
+
declare const claimableBalanceCreate: Action;
|
|
29
|
+
declare const claimableBalanceClaim: Action;
|
|
30
|
+
|
|
31
|
+
declare const manageSellOffer: Action;
|
|
32
|
+
declare const manageBuyOffer: Action;
|
|
33
|
+
declare const cancelOffer: Action;
|
|
34
|
+
|
|
35
|
+
declare const getOrderbook: Action;
|
|
36
|
+
|
|
37
|
+
declare const friendbotFund: Action;
|
|
38
|
+
|
|
39
|
+
declare const StellarAssetPlugin: Plugin;
|
|
40
|
+
|
|
41
|
+
export { StellarAssetPlugin, balance, cancelOffer, claimableBalanceClaim, claimableBalanceCreate, StellarAssetPlugin as default, friendbotFund, getOrderbook, issue, manageBuyOffer, manageSellOffer, pathPaymentStrictReceive, pathPaymentStrictSend, setOptions, transfer, trustlineAdd, trustlineRemove };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,741 @@
|
|
|
1
|
+
// src/actions/transfer.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { withIdempotency, DEFAULT_IDEMPOTENCY_TTL_MS } from "@stellar-agent-kit/core";
|
|
4
|
+
import { Operation as Operation2 } from "@stellar/stellar-sdk";
|
|
5
|
+
|
|
6
|
+
// src/utils.ts
|
|
7
|
+
import {
|
|
8
|
+
Asset,
|
|
9
|
+
Operation,
|
|
10
|
+
TransactionBuilder,
|
|
11
|
+
BASE_FEE
|
|
12
|
+
} from "@stellar/stellar-sdk";
|
|
13
|
+
function requireHorizon(agent) {
|
|
14
|
+
if (!agent.horizonServer) {
|
|
15
|
+
const err = new Error("Classic asset operations require horizonUrl to be configured.");
|
|
16
|
+
err.code = "HORIZON_NOT_CONFIGURED";
|
|
17
|
+
throw err;
|
|
18
|
+
}
|
|
19
|
+
return agent.horizonServer;
|
|
20
|
+
}
|
|
21
|
+
function makeAsset(input) {
|
|
22
|
+
if (input.code === "XLM" || input.code === "native") return Asset.native();
|
|
23
|
+
if (!input.issuer) {
|
|
24
|
+
const err = new Error(`Asset code ${input.code} requires an issuer.`);
|
|
25
|
+
err.code = "ISSUER_REQUIRED";
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
return new Asset(input.code, input.issuer);
|
|
29
|
+
}
|
|
30
|
+
async function ensureTrustline(horizon, account, asset) {
|
|
31
|
+
if (asset.isNative()) return;
|
|
32
|
+
const acc = await horizon.loadAccount(account);
|
|
33
|
+
const has = acc.balances.some(
|
|
34
|
+
(b) => b.asset_type !== "native" && "asset_code" in b && b.asset_code === asset.getCode() && "asset_issuer" in b && b.asset_issuer === asset.getIssuer()
|
|
35
|
+
);
|
|
36
|
+
if (!has) {
|
|
37
|
+
const err = new Error(
|
|
38
|
+
`Account ${account} has no trustline for ${asset.getCode()}:${asset.getIssuer()}.`
|
|
39
|
+
);
|
|
40
|
+
err.code = "TRUSTLINE_REQUIRED";
|
|
41
|
+
throw err;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function buildSubmitClassic(agent, buildOps, options = {}) {
|
|
45
|
+
const horizon = requireHorizon(agent);
|
|
46
|
+
const account = await horizon.loadAccount(agent.wallet.publicKey);
|
|
47
|
+
let builder = new TransactionBuilder(account, {
|
|
48
|
+
fee: agent.config.defaultFeeStroops ?? BASE_FEE,
|
|
49
|
+
networkPassphrase: agent.config.networkPassphrase
|
|
50
|
+
});
|
|
51
|
+
builder = buildOps(builder);
|
|
52
|
+
if (options.memo) {
|
|
53
|
+
const { Memo } = await import("@stellar/stellar-sdk");
|
|
54
|
+
builder = builder.addMemo(Memo.text(options.memo));
|
|
55
|
+
}
|
|
56
|
+
const tx = builder.setTimeout(180).build();
|
|
57
|
+
const signedXdr = await agent.wallet.signTransaction(tx.toXDR(), {
|
|
58
|
+
networkPassphrase: agent.config.networkPassphrase,
|
|
59
|
+
accountToSign: agent.wallet.publicKey
|
|
60
|
+
});
|
|
61
|
+
const signedTx = TransactionBuilder.fromXDR(signedXdr, agent.config.networkPassphrase);
|
|
62
|
+
const resp = await horizon.submitTransaction(signedTx);
|
|
63
|
+
return { hash: resp.hash, ledger: resp.ledger };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// src/actions/transfer.ts
|
|
67
|
+
var transfer = {
|
|
68
|
+
name: "ASSET_TRANSFER",
|
|
69
|
+
similes: ["send xlm", "send asset", "pay", "transfer asset"],
|
|
70
|
+
description: "Transfer XLM or any Stellar Classic asset from the agent's wallet to a destination account. Verifies destination has a trustline before submitting. Pass `idempotencyKey` to make retries safe \u2014 the same key returns the cached result for 24h instead of re-submitting.",
|
|
71
|
+
examples: [
|
|
72
|
+
[
|
|
73
|
+
{
|
|
74
|
+
input: { destination: "G...", assetCode: "XLM", amount: "10" },
|
|
75
|
+
output: { hash: "abc...", ledger: 12345 },
|
|
76
|
+
explanation: "Send 10 XLM"
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
],
|
|
80
|
+
schema: z.object({
|
|
81
|
+
destination: z.string().describe("Stellar G... address of the recipient"),
|
|
82
|
+
assetCode: z.string().describe("Asset code, e.g. XLM, USDC"),
|
|
83
|
+
issuer: z.string().optional().describe("Asset issuer G... address (required for non-native)"),
|
|
84
|
+
amount: z.string().describe("Amount as a decimal string, e.g. 10.5"),
|
|
85
|
+
memo: z.string().optional(),
|
|
86
|
+
idempotencyKey: z.string().optional().describe(
|
|
87
|
+
"Optional retry-safe key. Same key within 24h returns the cached result instead of re-submitting."
|
|
88
|
+
)
|
|
89
|
+
}),
|
|
90
|
+
handler: async (agent, input) => withIdempotency(agent.kvStore, "ASSET_TRANSFER", input.idempotencyKey, DEFAULT_IDEMPOTENCY_TTL_MS, async () => {
|
|
91
|
+
const horizon = requireHorizon(agent);
|
|
92
|
+
const asset = makeAsset({ code: input.assetCode, issuer: input.issuer });
|
|
93
|
+
await ensureTrustline(horizon, input.destination, asset);
|
|
94
|
+
const { hash, ledger } = await buildSubmitClassic(
|
|
95
|
+
agent,
|
|
96
|
+
(b) => b.addOperation(
|
|
97
|
+
Operation2.payment({ destination: input.destination, asset, amount: input.amount })
|
|
98
|
+
),
|
|
99
|
+
{ memo: input.memo }
|
|
100
|
+
);
|
|
101
|
+
return { hash, ledger };
|
|
102
|
+
})
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// src/actions/pathPayment.ts
|
|
106
|
+
import { z as z2 } from "zod";
|
|
107
|
+
import { Operation as Operation3 } from "@stellar/stellar-sdk";
|
|
108
|
+
var assetSchema = z2.object({
|
|
109
|
+
code: z2.string(),
|
|
110
|
+
issuer: z2.string().optional()
|
|
111
|
+
});
|
|
112
|
+
var pathPaymentStrictSend = {
|
|
113
|
+
name: "ASSET_PATH_PAYMENT_STRICT_SEND",
|
|
114
|
+
similes: ["path payment", "convert and send", "swap and pay"],
|
|
115
|
+
description: "Send a fixed amount of one asset which is converted along the way to a destination asset using Stellar's classic DEX path-payment.",
|
|
116
|
+
examples: [
|
|
117
|
+
[
|
|
118
|
+
{
|
|
119
|
+
input: {
|
|
120
|
+
destination: "G...",
|
|
121
|
+
sendAsset: { code: "XLM" },
|
|
122
|
+
sendAmount: "100",
|
|
123
|
+
destAsset: { code: "USDC", issuer: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN" },
|
|
124
|
+
destMin: "10",
|
|
125
|
+
path: []
|
|
126
|
+
},
|
|
127
|
+
output: { hash: "...", ledger: 1 },
|
|
128
|
+
explanation: "Convert 100 XLM into at least 10 USDC"
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
],
|
|
132
|
+
schema: z2.object({
|
|
133
|
+
destination: z2.string(),
|
|
134
|
+
sendAsset: assetSchema,
|
|
135
|
+
sendAmount: z2.string(),
|
|
136
|
+
destAsset: assetSchema,
|
|
137
|
+
destMin: z2.string(),
|
|
138
|
+
path: z2.array(assetSchema).default([])
|
|
139
|
+
}),
|
|
140
|
+
handler: async (agent, input) => {
|
|
141
|
+
const sendAsset = makeAsset(input.sendAsset);
|
|
142
|
+
const destAsset = makeAsset(input.destAsset);
|
|
143
|
+
const path = input.path.map(makeAsset);
|
|
144
|
+
const { hash, ledger } = await buildSubmitClassic(
|
|
145
|
+
agent,
|
|
146
|
+
(b) => b.addOperation(
|
|
147
|
+
Operation3.pathPaymentStrictSend({
|
|
148
|
+
destination: input.destination,
|
|
149
|
+
sendAsset,
|
|
150
|
+
sendAmount: input.sendAmount,
|
|
151
|
+
destAsset,
|
|
152
|
+
destMin: input.destMin,
|
|
153
|
+
path
|
|
154
|
+
})
|
|
155
|
+
)
|
|
156
|
+
);
|
|
157
|
+
return { hash, ledger };
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// src/actions/pathPaymentReceive.ts
|
|
162
|
+
import { z as z3 } from "zod";
|
|
163
|
+
import { Operation as Operation4 } from "@stellar/stellar-sdk";
|
|
164
|
+
var assetSchema2 = z3.object({
|
|
165
|
+
code: z3.string(),
|
|
166
|
+
issuer: z3.string().optional()
|
|
167
|
+
});
|
|
168
|
+
var pathPaymentStrictReceive = {
|
|
169
|
+
name: "ASSET_PATH_PAYMENT_STRICT_RECEIVE",
|
|
170
|
+
similes: ["path payment receive", "buy exact amount", "swap to receive"],
|
|
171
|
+
description: "Send up to a maximum amount of one asset which is converted along the way so the destination receives an exact amount of another asset using Stellar's classic DEX path-payment.",
|
|
172
|
+
examples: [
|
|
173
|
+
[
|
|
174
|
+
{
|
|
175
|
+
input: {
|
|
176
|
+
destination: "G...",
|
|
177
|
+
sendAsset: { code: "XLM" },
|
|
178
|
+
sendMax: "120",
|
|
179
|
+
destAsset: { code: "USDC", issuer: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN" },
|
|
180
|
+
destAmount: "10",
|
|
181
|
+
path: []
|
|
182
|
+
},
|
|
183
|
+
output: { hash: "...", ledger: 1 },
|
|
184
|
+
explanation: "Spend at most 120 XLM to deliver exactly 10 USDC"
|
|
185
|
+
}
|
|
186
|
+
]
|
|
187
|
+
],
|
|
188
|
+
schema: z3.object({
|
|
189
|
+
destination: z3.string(),
|
|
190
|
+
sendAsset: assetSchema2,
|
|
191
|
+
sendMax: z3.string(),
|
|
192
|
+
destAsset: assetSchema2,
|
|
193
|
+
destAmount: z3.string(),
|
|
194
|
+
path: z3.array(assetSchema2).default([])
|
|
195
|
+
}),
|
|
196
|
+
handler: async (agent, input) => {
|
|
197
|
+
const sendAsset = makeAsset(input.sendAsset);
|
|
198
|
+
const destAsset = makeAsset(input.destAsset);
|
|
199
|
+
const path = input.path.map(makeAsset);
|
|
200
|
+
const { hash, ledger } = await buildSubmitClassic(
|
|
201
|
+
agent,
|
|
202
|
+
(b) => b.addOperation(
|
|
203
|
+
Operation4.pathPaymentStrictReceive({
|
|
204
|
+
destination: input.destination,
|
|
205
|
+
sendAsset,
|
|
206
|
+
sendMax: input.sendMax,
|
|
207
|
+
destAsset,
|
|
208
|
+
destAmount: input.destAmount,
|
|
209
|
+
path
|
|
210
|
+
})
|
|
211
|
+
)
|
|
212
|
+
);
|
|
213
|
+
return { hash, ledger };
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// src/actions/trustline.ts
|
|
218
|
+
import { z as z4 } from "zod";
|
|
219
|
+
import { Operation as Operation5 } from "@stellar/stellar-sdk";
|
|
220
|
+
var trustlineAdd = {
|
|
221
|
+
name: "ASSET_TRUSTLINE_ADD",
|
|
222
|
+
similes: ["change trust", "add trustline", "trust asset"],
|
|
223
|
+
description: "Establish or update a trustline from the agent's wallet for a non-native Stellar asset.",
|
|
224
|
+
examples: [
|
|
225
|
+
[
|
|
226
|
+
{
|
|
227
|
+
input: { assetCode: "USDC", issuer: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN" },
|
|
228
|
+
output: { hash: "...", ledger: 1 },
|
|
229
|
+
explanation: "Trustline USDC at default limit"
|
|
230
|
+
}
|
|
231
|
+
]
|
|
232
|
+
],
|
|
233
|
+
schema: z4.object({
|
|
234
|
+
assetCode: z4.string(),
|
|
235
|
+
issuer: z4.string(),
|
|
236
|
+
limit: z4.string().optional().describe("Trust limit (omit for max). String decimal, e.g. 1000000")
|
|
237
|
+
}),
|
|
238
|
+
handler: async (agent, input) => {
|
|
239
|
+
const asset = makeAsset({ code: input.assetCode, issuer: input.issuer });
|
|
240
|
+
const { hash, ledger } = await buildSubmitClassic(
|
|
241
|
+
agent,
|
|
242
|
+
(b) => b.addOperation(Operation5.changeTrust({ asset, ...input.limit ? { limit: input.limit } : {} }))
|
|
243
|
+
);
|
|
244
|
+
return { hash, ledger };
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
var trustlineRemove = {
|
|
248
|
+
name: "ASSET_TRUSTLINE_REMOVE",
|
|
249
|
+
similes: ["remove trustline", "untrust asset"],
|
|
250
|
+
description: "Remove a trustline by setting its limit to 0. The agent's balance for that asset must already be 0.",
|
|
251
|
+
examples: [
|
|
252
|
+
[
|
|
253
|
+
{
|
|
254
|
+
input: { assetCode: "USDC", issuer: "GA..." },
|
|
255
|
+
output: { hash: "...", ledger: 1 },
|
|
256
|
+
explanation: "Remove a USDC trustline"
|
|
257
|
+
}
|
|
258
|
+
]
|
|
259
|
+
],
|
|
260
|
+
schema: z4.object({ assetCode: z4.string(), issuer: z4.string() }),
|
|
261
|
+
handler: async (agent, input) => {
|
|
262
|
+
const asset = makeAsset({ code: input.assetCode, issuer: input.issuer });
|
|
263
|
+
const { hash, ledger } = await buildSubmitClassic(
|
|
264
|
+
agent,
|
|
265
|
+
(b) => b.addOperation(Operation5.changeTrust({ asset, limit: "0" }))
|
|
266
|
+
);
|
|
267
|
+
return { hash, ledger };
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
// src/actions/balance.ts
|
|
272
|
+
import { z as z5 } from "zod";
|
|
273
|
+
var balance = {
|
|
274
|
+
name: "ASSET_GET_BALANCE",
|
|
275
|
+
similes: ["check balance", "get balance", "wallet balance"],
|
|
276
|
+
description: "Returns native (XLM) and asset balances for the given account, or for the agent's wallet if no account is specified.",
|
|
277
|
+
examples: [
|
|
278
|
+
[
|
|
279
|
+
{
|
|
280
|
+
input: {},
|
|
281
|
+
output: {
|
|
282
|
+
account: "G...",
|
|
283
|
+
balances: [{ asset: "XLM", balance: "10000.0" }]
|
|
284
|
+
},
|
|
285
|
+
explanation: "Default to agent's wallet"
|
|
286
|
+
}
|
|
287
|
+
]
|
|
288
|
+
],
|
|
289
|
+
schema: z5.object({
|
|
290
|
+
account: z5.string().optional()
|
|
291
|
+
}),
|
|
292
|
+
handler: async (agent, input) => {
|
|
293
|
+
const horizon = requireHorizon(agent);
|
|
294
|
+
const account = input.account ?? agent.wallet.publicKey;
|
|
295
|
+
const acc = await horizon.loadAccount(account);
|
|
296
|
+
return {
|
|
297
|
+
account,
|
|
298
|
+
balances: acc.balances.map((b) => {
|
|
299
|
+
if (b.asset_type === "native") return { asset: "XLM", balance: b.balance };
|
|
300
|
+
return {
|
|
301
|
+
asset: "asset_code" in b ? b.asset_code : "?",
|
|
302
|
+
issuer: "asset_issuer" in b ? b.asset_issuer : void 0,
|
|
303
|
+
balance: b.balance
|
|
304
|
+
};
|
|
305
|
+
})
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
// src/actions/issue.ts
|
|
311
|
+
import { z as z6 } from "zod";
|
|
312
|
+
import { Operation as Operation6, Asset as Asset2 } from "@stellar/stellar-sdk";
|
|
313
|
+
var issue = {
|
|
314
|
+
name: "ASSET_ISSUE",
|
|
315
|
+
similes: ["issue token", "create asset", "mint token"],
|
|
316
|
+
description: "Issue a custom Stellar Classic asset by sending an initial supply from the agent (issuer) to a distribution account that has already trustlined the asset.",
|
|
317
|
+
examples: [
|
|
318
|
+
[
|
|
319
|
+
{
|
|
320
|
+
input: { assetCode: "MYTOKEN", distribution: "G...", initialSupply: "1000000" },
|
|
321
|
+
output: { hash: "...", ledger: 1 },
|
|
322
|
+
explanation: "Mint 1M MYTOKEN to the distribution account"
|
|
323
|
+
}
|
|
324
|
+
]
|
|
325
|
+
],
|
|
326
|
+
schema: z6.object({
|
|
327
|
+
assetCode: z6.string().describe("4 or 12 chars, e.g. USDX, MYTOKEN"),
|
|
328
|
+
distribution: z6.string().describe("Distribution account G... that already trustlined the asset"),
|
|
329
|
+
initialSupply: z6.string().describe("Initial supply, decimal string")
|
|
330
|
+
}),
|
|
331
|
+
handler: async (agent, input) => {
|
|
332
|
+
const horizon = requireHorizon(agent);
|
|
333
|
+
const asset = new Asset2(input.assetCode, agent.wallet.publicKey);
|
|
334
|
+
const dist = await horizon.loadAccount(input.distribution);
|
|
335
|
+
const hasTrust = dist.balances.some(
|
|
336
|
+
(b) => b.asset_type !== "native" && "asset_code" in b && b.asset_code === input.assetCode && "asset_issuer" in b && b.asset_issuer === agent.wallet.publicKey
|
|
337
|
+
);
|
|
338
|
+
if (!hasTrust) {
|
|
339
|
+
const err = new Error(
|
|
340
|
+
`Distribution account ${input.distribution} has no trustline for ${input.assetCode}:${agent.wallet.publicKey}. Call ASSET_TRUSTLINE_ADD from the distribution account first.`
|
|
341
|
+
);
|
|
342
|
+
err.code = "TRUSTLINE_REQUIRED";
|
|
343
|
+
throw err;
|
|
344
|
+
}
|
|
345
|
+
const { hash, ledger } = await buildSubmitClassic(
|
|
346
|
+
agent,
|
|
347
|
+
(b) => b.addOperation(
|
|
348
|
+
Operation6.payment({ destination: input.distribution, asset, amount: input.initialSupply })
|
|
349
|
+
)
|
|
350
|
+
);
|
|
351
|
+
return { hash, ledger, assetCode: input.assetCode, issuer: agent.wallet.publicKey };
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
// src/actions/setOptions.ts
|
|
356
|
+
import { z as z7 } from "zod";
|
|
357
|
+
import { Operation as Operation7 } from "@stellar/stellar-sdk";
|
|
358
|
+
var AUTH_REQUIRED = 1;
|
|
359
|
+
var AUTH_REVOCABLE = 2;
|
|
360
|
+
var AUTH_IMMUTABLE = 4;
|
|
361
|
+
var AUTH_CLAWBACK_ENABLED = 8;
|
|
362
|
+
var setOptions = {
|
|
363
|
+
name: "ASSET_SET_OPTIONS",
|
|
364
|
+
similes: ["set issuer options", "set home domain", "set auth flags"],
|
|
365
|
+
description: "Update issuer/account options on the agent's wallet: home_domain, auth flags (required, revocable, immutable, clawback), inflation destination.",
|
|
366
|
+
examples: [
|
|
367
|
+
[
|
|
368
|
+
{
|
|
369
|
+
input: { homeDomain: "example.com", authRequired: true, authRevocable: true },
|
|
370
|
+
output: { hash: "...", ledger: 1 },
|
|
371
|
+
explanation: "Make the agent a regulated issuer"
|
|
372
|
+
}
|
|
373
|
+
]
|
|
374
|
+
],
|
|
375
|
+
schema: z7.object({
|
|
376
|
+
homeDomain: z7.string().optional(),
|
|
377
|
+
inflationDest: z7.string().optional(),
|
|
378
|
+
authRequired: z7.boolean().optional(),
|
|
379
|
+
authRevocable: z7.boolean().optional(),
|
|
380
|
+
authImmutable: z7.boolean().optional(),
|
|
381
|
+
authClawbackEnabled: z7.boolean().optional()
|
|
382
|
+
}),
|
|
383
|
+
handler: async (agent, input) => {
|
|
384
|
+
let setFlags = 0;
|
|
385
|
+
if (input.authRequired) setFlags |= AUTH_REQUIRED;
|
|
386
|
+
if (input.authRevocable) setFlags |= AUTH_REVOCABLE;
|
|
387
|
+
if (input.authImmutable) setFlags |= AUTH_IMMUTABLE;
|
|
388
|
+
if (input.authClawbackEnabled) setFlags |= AUTH_CLAWBACK_ENABLED;
|
|
389
|
+
const { hash, ledger } = await buildSubmitClassic(
|
|
390
|
+
agent,
|
|
391
|
+
(b) => b.addOperation(
|
|
392
|
+
Operation7.setOptions({
|
|
393
|
+
homeDomain: input.homeDomain,
|
|
394
|
+
inflationDest: input.inflationDest,
|
|
395
|
+
// Cast: setOptions accepts an `AuthFlag` enum but the underlying value is the same uint8 bitmask.
|
|
396
|
+
setFlags: setFlags ? setFlags : void 0
|
|
397
|
+
})
|
|
398
|
+
)
|
|
399
|
+
);
|
|
400
|
+
return { hash, ledger };
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
// src/actions/claimableBalance.ts
|
|
405
|
+
import { z as z8 } from "zod";
|
|
406
|
+
import { Operation as Operation8, Claimant } from "@stellar/stellar-sdk";
|
|
407
|
+
var claimableBalanceCreate = {
|
|
408
|
+
name: "ASSET_CLAIMABLE_BALANCE_CREATE",
|
|
409
|
+
similes: ["create claimable", "send claimable balance"],
|
|
410
|
+
description: "Create a claimable balance \u2014 escrow-like primitive where one or more claimants can later claim the funds without needing a trustline first.",
|
|
411
|
+
examples: [
|
|
412
|
+
[
|
|
413
|
+
{
|
|
414
|
+
input: { assetCode: "XLM", amount: "5", claimants: ["G..."] },
|
|
415
|
+
output: { hash: "...", ledger: 1 },
|
|
416
|
+
explanation: "Send 5 XLM as claimable to a recipient"
|
|
417
|
+
}
|
|
418
|
+
]
|
|
419
|
+
],
|
|
420
|
+
schema: z8.object({
|
|
421
|
+
assetCode: z8.string(),
|
|
422
|
+
issuer: z8.string().optional(),
|
|
423
|
+
amount: z8.string(),
|
|
424
|
+
claimants: z8.array(z8.string()).min(1)
|
|
425
|
+
}),
|
|
426
|
+
handler: async (agent, input) => {
|
|
427
|
+
const asset = makeAsset({ code: input.assetCode, issuer: input.issuer });
|
|
428
|
+
const claimants = input.claimants.map(
|
|
429
|
+
(dest) => new Claimant(dest, Claimant.predicateUnconditional())
|
|
430
|
+
);
|
|
431
|
+
const { hash, ledger } = await buildSubmitClassic(
|
|
432
|
+
agent,
|
|
433
|
+
(b) => b.addOperation(Operation8.createClaimableBalance({ asset, amount: input.amount, claimants }))
|
|
434
|
+
);
|
|
435
|
+
return { hash, ledger };
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
var claimableBalanceClaim = {
|
|
439
|
+
name: "ASSET_CLAIMABLE_BALANCE_CLAIM",
|
|
440
|
+
similes: ["claim claimable", "redeem claimable"],
|
|
441
|
+
description: "Claim a claimable balance the agent's wallet is a claimant of.",
|
|
442
|
+
examples: [
|
|
443
|
+
[
|
|
444
|
+
{
|
|
445
|
+
input: { balanceId: "00000000..." },
|
|
446
|
+
output: { hash: "...", ledger: 1 },
|
|
447
|
+
explanation: "Claim by id"
|
|
448
|
+
}
|
|
449
|
+
]
|
|
450
|
+
],
|
|
451
|
+
schema: z8.object({ balanceId: z8.string() }),
|
|
452
|
+
handler: async (agent, input) => {
|
|
453
|
+
const { hash, ledger } = await buildSubmitClassic(
|
|
454
|
+
agent,
|
|
455
|
+
(b) => b.addOperation(Operation8.claimClaimableBalance({ balanceId: input.balanceId }))
|
|
456
|
+
);
|
|
457
|
+
return { hash, ledger };
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
// src/actions/dexOffers.ts
|
|
462
|
+
import { z as z9 } from "zod";
|
|
463
|
+
import { Operation as Operation9 } from "@stellar/stellar-sdk";
|
|
464
|
+
var assetSchema3 = z9.object({
|
|
465
|
+
code: z9.string(),
|
|
466
|
+
issuer: z9.string().optional()
|
|
467
|
+
});
|
|
468
|
+
var manageSellOffer = {
|
|
469
|
+
name: "DEX_MANAGE_SELL_OFFER",
|
|
470
|
+
similes: ["sell offer", "create sell offer", "update sell offer", "place sell order"],
|
|
471
|
+
description: "Create, update or cancel a sell offer on the Stellar Classic DEX. Pass offerId='0' to create a new offer; pass an existing offer id to update it. To cancel use DEX_CANCEL_OFFER.",
|
|
472
|
+
examples: [
|
|
473
|
+
[
|
|
474
|
+
{
|
|
475
|
+
input: {
|
|
476
|
+
selling: { code: "XLM" },
|
|
477
|
+
buying: {
|
|
478
|
+
code: "USDC",
|
|
479
|
+
issuer: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN"
|
|
480
|
+
},
|
|
481
|
+
amount: "100",
|
|
482
|
+
price: "0.1",
|
|
483
|
+
offerId: "0"
|
|
484
|
+
},
|
|
485
|
+
output: { hash: "...", ledger: 1 },
|
|
486
|
+
explanation: "Place a new sell offer of 100 XLM at 0.1 USDC each"
|
|
487
|
+
}
|
|
488
|
+
]
|
|
489
|
+
],
|
|
490
|
+
schema: z9.object({
|
|
491
|
+
selling: assetSchema3,
|
|
492
|
+
buying: assetSchema3,
|
|
493
|
+
amount: z9.string().describe("Amount of selling asset, decimal string. Use '0' to cancel."),
|
|
494
|
+
price: z9.string().describe("Price as decimal string, units of buying per selling"),
|
|
495
|
+
offerId: z9.string().default("0").describe("Existing offer id, or '0' to create a new offer")
|
|
496
|
+
}),
|
|
497
|
+
handler: async (agent, input) => {
|
|
498
|
+
const selling = makeAsset(input.selling);
|
|
499
|
+
const buying = makeAsset(input.buying);
|
|
500
|
+
const { hash, ledger } = await buildSubmitClassic(
|
|
501
|
+
agent,
|
|
502
|
+
(b) => b.addOperation(
|
|
503
|
+
Operation9.manageSellOffer({
|
|
504
|
+
selling,
|
|
505
|
+
buying,
|
|
506
|
+
amount: input.amount,
|
|
507
|
+
price: input.price,
|
|
508
|
+
offerId: input.offerId
|
|
509
|
+
})
|
|
510
|
+
)
|
|
511
|
+
);
|
|
512
|
+
return { hash, ledger };
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
var manageBuyOffer = {
|
|
516
|
+
name: "DEX_MANAGE_BUY_OFFER",
|
|
517
|
+
similes: ["buy offer", "create buy offer", "update buy offer", "place buy order"],
|
|
518
|
+
description: "Create, update or cancel a buy offer on the Stellar Classic DEX. Pass offerId='0' to create a new offer; pass an existing offer id to update it. Set buyAmount to '0' to cancel.",
|
|
519
|
+
examples: [
|
|
520
|
+
[
|
|
521
|
+
{
|
|
522
|
+
input: {
|
|
523
|
+
selling: { code: "XLM" },
|
|
524
|
+
buying: {
|
|
525
|
+
code: "USDC",
|
|
526
|
+
issuer: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN"
|
|
527
|
+
},
|
|
528
|
+
buyAmount: "10",
|
|
529
|
+
price: "10",
|
|
530
|
+
offerId: "0"
|
|
531
|
+
},
|
|
532
|
+
output: { hash: "...", ledger: 1 },
|
|
533
|
+
explanation: "Place a new buy offer to buy 10 USDC at 10 XLM each"
|
|
534
|
+
}
|
|
535
|
+
]
|
|
536
|
+
],
|
|
537
|
+
schema: z9.object({
|
|
538
|
+
selling: assetSchema3,
|
|
539
|
+
buying: assetSchema3,
|
|
540
|
+
buyAmount: z9.string().describe("Amount of buying asset, decimal string. Use '0' to cancel."),
|
|
541
|
+
price: z9.string().describe("Price as decimal string, units of selling per buying"),
|
|
542
|
+
offerId: z9.string().default("0").describe("Existing offer id, or '0' to create a new offer")
|
|
543
|
+
}),
|
|
544
|
+
handler: async (agent, input) => {
|
|
545
|
+
const selling = makeAsset(input.selling);
|
|
546
|
+
const buying = makeAsset(input.buying);
|
|
547
|
+
const { hash, ledger } = await buildSubmitClassic(
|
|
548
|
+
agent,
|
|
549
|
+
(b) => b.addOperation(
|
|
550
|
+
Operation9.manageBuyOffer({
|
|
551
|
+
selling,
|
|
552
|
+
buying,
|
|
553
|
+
buyAmount: input.buyAmount,
|
|
554
|
+
price: input.price,
|
|
555
|
+
offerId: input.offerId
|
|
556
|
+
})
|
|
557
|
+
)
|
|
558
|
+
);
|
|
559
|
+
return { hash, ledger };
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
var cancelOffer = {
|
|
563
|
+
name: "DEX_CANCEL_OFFER",
|
|
564
|
+
similes: ["cancel offer", "delete offer", "remove offer"],
|
|
565
|
+
description: "Cancel an existing sell offer on the Stellar Classic DEX. Submits a manageSellOffer with amount='0' for the supplied offerId.",
|
|
566
|
+
examples: [
|
|
567
|
+
[
|
|
568
|
+
{
|
|
569
|
+
input: {
|
|
570
|
+
selling: { code: "XLM" },
|
|
571
|
+
buying: {
|
|
572
|
+
code: "USDC",
|
|
573
|
+
issuer: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN"
|
|
574
|
+
},
|
|
575
|
+
price: "0.1",
|
|
576
|
+
offerId: "12345"
|
|
577
|
+
},
|
|
578
|
+
output: { hash: "...", ledger: 1 },
|
|
579
|
+
explanation: "Cancel an existing sell offer with id 12345"
|
|
580
|
+
}
|
|
581
|
+
]
|
|
582
|
+
],
|
|
583
|
+
schema: z9.object({
|
|
584
|
+
selling: assetSchema3,
|
|
585
|
+
buying: assetSchema3,
|
|
586
|
+
price: z9.string().default("1").describe("Price is required by the operation but ignored when cancelling"),
|
|
587
|
+
offerId: z9.string().describe("Existing offer id to cancel")
|
|
588
|
+
}),
|
|
589
|
+
handler: async (agent, input) => {
|
|
590
|
+
const selling = makeAsset(input.selling);
|
|
591
|
+
const buying = makeAsset(input.buying);
|
|
592
|
+
const { hash, ledger } = await buildSubmitClassic(
|
|
593
|
+
agent,
|
|
594
|
+
(b) => b.addOperation(
|
|
595
|
+
Operation9.manageSellOffer({
|
|
596
|
+
selling,
|
|
597
|
+
buying,
|
|
598
|
+
amount: "0",
|
|
599
|
+
price: input.price,
|
|
600
|
+
offerId: input.offerId
|
|
601
|
+
})
|
|
602
|
+
)
|
|
603
|
+
);
|
|
604
|
+
return { hash, ledger };
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
// src/actions/orderbook.ts
|
|
609
|
+
import { z as z10 } from "zod";
|
|
610
|
+
var assetSchema4 = z10.object({
|
|
611
|
+
code: z10.string(),
|
|
612
|
+
issuer: z10.string().optional()
|
|
613
|
+
});
|
|
614
|
+
var getOrderbook = {
|
|
615
|
+
name: "DEX_GET_ORDERBOOK",
|
|
616
|
+
similes: ["get orderbook", "read orderbook", "show order book", "fetch dex orderbook"],
|
|
617
|
+
description: "Read the Stellar Classic DEX order book between a base (selling) asset and a counter (buying) asset via Horizon.",
|
|
618
|
+
examples: [
|
|
619
|
+
[
|
|
620
|
+
{
|
|
621
|
+
input: {
|
|
622
|
+
selling: { code: "XLM" },
|
|
623
|
+
buying: {
|
|
624
|
+
code: "USDC",
|
|
625
|
+
issuer: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN"
|
|
626
|
+
},
|
|
627
|
+
limit: 20
|
|
628
|
+
},
|
|
629
|
+
output: { bids: [], asks: [], base: {}, counter: {} },
|
|
630
|
+
explanation: "Fetch the top 20 bid/ask levels for XLM/USDC"
|
|
631
|
+
}
|
|
632
|
+
]
|
|
633
|
+
],
|
|
634
|
+
schema: z10.object({
|
|
635
|
+
selling: assetSchema4,
|
|
636
|
+
buying: assetSchema4,
|
|
637
|
+
limit: z10.number().int().positive().max(200).default(20)
|
|
638
|
+
}),
|
|
639
|
+
handler: async (agent, input) => {
|
|
640
|
+
const horizon = requireHorizon(agent);
|
|
641
|
+
const selling = makeAsset(input.selling);
|
|
642
|
+
const buying = makeAsset(input.buying);
|
|
643
|
+
const resp = await horizon.orderbook(selling, buying).limit(input.limit).call();
|
|
644
|
+
return {
|
|
645
|
+
bids: resp.bids,
|
|
646
|
+
asks: resp.asks,
|
|
647
|
+
base: resp.base,
|
|
648
|
+
counter: resp.counter
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
// src/actions/friendbot.ts
|
|
654
|
+
import { z as z11 } from "zod";
|
|
655
|
+
import { Networks } from "@stellar/stellar-sdk";
|
|
656
|
+
var friendbotFund = {
|
|
657
|
+
name: "ACCOUNT_FRIENDBOT_FUND",
|
|
658
|
+
similes: ["friendbot", "fund testnet account", "airdrop testnet xlm"],
|
|
659
|
+
description: "Fund a Stellar testnet account using the public Friendbot service. Defaults to the agent's wallet public key. Only works on the testnet \u2014 calls on mainnet will be rejected by Friendbot.",
|
|
660
|
+
examples: [
|
|
661
|
+
[
|
|
662
|
+
{
|
|
663
|
+
input: {},
|
|
664
|
+
output: { hash: "...", ledger: 1, funded: true },
|
|
665
|
+
explanation: "Fund the agent's own wallet on testnet"
|
|
666
|
+
}
|
|
667
|
+
]
|
|
668
|
+
],
|
|
669
|
+
schema: z11.object({
|
|
670
|
+
account: z11.string().optional().describe("Stellar G... account to fund. Defaults to agent.wallet.publicKey.")
|
|
671
|
+
}),
|
|
672
|
+
handler: async (agent, input) => {
|
|
673
|
+
const account = input.account ?? agent.wallet.publicKey;
|
|
674
|
+
if (agent.config.networkPassphrase === Networks.PUBLIC) {
|
|
675
|
+
console.warn(
|
|
676
|
+
"[ACCOUNT_FRIENDBOT_FUND] Agent is configured for the public network; Friendbot only funds testnet accounts."
|
|
677
|
+
);
|
|
678
|
+
}
|
|
679
|
+
const url = `https://friendbot.stellar.org?addr=${encodeURIComponent(account)}`;
|
|
680
|
+
const resp = await fetch(url, { method: "POST" });
|
|
681
|
+
if (!resp.ok) {
|
|
682
|
+
let detail = "";
|
|
683
|
+
try {
|
|
684
|
+
detail = await resp.text();
|
|
685
|
+
} catch {
|
|
686
|
+
}
|
|
687
|
+
const err = new Error(
|
|
688
|
+
`Friendbot funding failed for ${account}: ${resp.status} ${resp.statusText}${detail ? ` \u2014 ${detail}` : ""}`
|
|
689
|
+
);
|
|
690
|
+
err.code = "FRIENDBOT_FAILED";
|
|
691
|
+
throw err;
|
|
692
|
+
}
|
|
693
|
+
const body = await resp.json().catch(() => ({}));
|
|
694
|
+
return { hash: body.hash, ledger: body.ledger, funded: true };
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
|
|
698
|
+
// src/index.ts
|
|
699
|
+
var StellarAssetPlugin = {
|
|
700
|
+
name: "stellar-asset",
|
|
701
|
+
methods: {},
|
|
702
|
+
actions: [
|
|
703
|
+
transfer,
|
|
704
|
+
pathPaymentStrictSend,
|
|
705
|
+
trustlineAdd,
|
|
706
|
+
trustlineRemove,
|
|
707
|
+
balance,
|
|
708
|
+
issue,
|
|
709
|
+
setOptions,
|
|
710
|
+
claimableBalanceCreate,
|
|
711
|
+
claimableBalanceClaim,
|
|
712
|
+
pathPaymentStrictReceive,
|
|
713
|
+
manageSellOffer,
|
|
714
|
+
manageBuyOffer,
|
|
715
|
+
cancelOffer,
|
|
716
|
+
getOrderbook,
|
|
717
|
+
friendbotFund
|
|
718
|
+
],
|
|
719
|
+
initialize() {
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
var index_default = StellarAssetPlugin;
|
|
723
|
+
export {
|
|
724
|
+
StellarAssetPlugin,
|
|
725
|
+
balance,
|
|
726
|
+
cancelOffer,
|
|
727
|
+
claimableBalanceClaim,
|
|
728
|
+
claimableBalanceCreate,
|
|
729
|
+
index_default as default,
|
|
730
|
+
friendbotFund,
|
|
731
|
+
getOrderbook,
|
|
732
|
+
issue,
|
|
733
|
+
manageBuyOffer,
|
|
734
|
+
manageSellOffer,
|
|
735
|
+
pathPaymentStrictReceive,
|
|
736
|
+
pathPaymentStrictSend,
|
|
737
|
+
setOptions,
|
|
738
|
+
transfer,
|
|
739
|
+
trustlineAdd,
|
|
740
|
+
trustlineRemove
|
|
741
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stellar-agent-kit/plugin-asset",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Classic Stellar asset operations (transfer, path payment, trustline, issuance, claimable balances) as agent actions.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"module": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@stellar/stellar-sdk": "^14.0.0-rc.3",
|
|
22
|
+
"zod": "^3.23.8"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@stellar-agent-kit/core": "0.1.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"tsup": "^8.3.5",
|
|
29
|
+
"typescript": "^5.7.2",
|
|
30
|
+
"vitest": "^2.1.8",
|
|
31
|
+
"@stellar-agent-kit/core": "0.1.0"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsup src/index.ts --dts --clean --format esm --out-dir dist",
|
|
38
|
+
"test": "vitest run",
|
|
39
|
+
"typecheck": "tsc --noEmit",
|
|
40
|
+
"clean": "rm -rf dist .turbo"
|
|
41
|
+
}
|
|
42
|
+
}
|