@powersun/mcp-client 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/README.md +117 -0
- package/dist/index.d.mts +265 -0
- package/dist/index.d.ts +265 -0
- package/dist/index.js +170 -0
- package/dist/index.mjs +141 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# @powersun/mcp-client
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for [PowerSun.vip](https://powersun.vip) — the TRON Energy & Bandwidth marketplace for AI agents.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @powersun/mcp-client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { PowerSun } from '@powersun/mcp-client';
|
|
15
|
+
|
|
16
|
+
// Public access (market data, estimates)
|
|
17
|
+
const ps = new PowerSun();
|
|
18
|
+
const prices = await ps.market.getPrices();
|
|
19
|
+
const estimate = await ps.market.estimateCost({
|
|
20
|
+
txCount: 10,
|
|
21
|
+
txType: 'trc20_transfer',
|
|
22
|
+
durationMinutes: 60,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Authenticated access (buy energy, check balance)
|
|
26
|
+
const client = new PowerSun({ apiKey: 'ps_your_key_here' });
|
|
27
|
+
const balance = await client.buyer.getBalance();
|
|
28
|
+
const order = await client.buyer.buyEnergy({
|
|
29
|
+
targetAddress: 'TYourAddressHere...',
|
|
30
|
+
txCount: 5,
|
|
31
|
+
durationMinutes: 60,
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## HTTP 402 Pay-per-use (No Registration)
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { PowerSun, PaymentRequiredError } from '@powersun/mcp-client';
|
|
39
|
+
|
|
40
|
+
const ps = new PowerSun(); // no API key
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
await ps.buyer.buyEnergy({
|
|
44
|
+
targetAddress: 'TYourAddressHere...',
|
|
45
|
+
txCount: 1,
|
|
46
|
+
durationMinutes: 5,
|
|
47
|
+
});
|
|
48
|
+
} catch (err) {
|
|
49
|
+
if (err instanceof PaymentRequiredError) {
|
|
50
|
+
// Send TRX to the deposit address
|
|
51
|
+
console.log('Deposit address:', err.payment.depositAddress);
|
|
52
|
+
console.log('Amount (TRX):', err.payment.requiredAmountTrx);
|
|
53
|
+
|
|
54
|
+
// Poll for payment confirmation
|
|
55
|
+
const status = await ps.paymentStatus(err.payment.intentId);
|
|
56
|
+
console.log('Payment status:', status.status);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Registration
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
const ps = new PowerSun();
|
|
65
|
+
|
|
66
|
+
// Step 1: Get challenge
|
|
67
|
+
const { challengeId, challenge } = await ps.register('TYourAddress...');
|
|
68
|
+
|
|
69
|
+
// Step 2: Sign challenge with TronLink / tronWeb
|
|
70
|
+
const signature = await tronWeb.trx.signMessageV2(challenge);
|
|
71
|
+
|
|
72
|
+
// Step 3: Verify and get API key
|
|
73
|
+
const { apiKey } = await ps.verify(challengeId, 'TYourAddress...', signature);
|
|
74
|
+
|
|
75
|
+
// Step 4: Use authenticated client
|
|
76
|
+
const client = new PowerSun({ apiKey });
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## API Reference
|
|
80
|
+
|
|
81
|
+
### `new PowerSun(config?)`
|
|
82
|
+
|
|
83
|
+
| Option | Type | Default | Description |
|
|
84
|
+
|--------|------|---------|-------------|
|
|
85
|
+
| `apiKey` | `string` | — | API key (`ps_*` format) |
|
|
86
|
+
| `baseUrl` | `string` | `https://powersun.vip` | API base URL |
|
|
87
|
+
| `timeout` | `number` | `30000` | Request timeout (ms) |
|
|
88
|
+
|
|
89
|
+
### Market (public)
|
|
90
|
+
|
|
91
|
+
- `ps.market.getPrices()` — Price tiers for all durations
|
|
92
|
+
- `ps.market.estimateCost(params)` — Cost estimate
|
|
93
|
+
- `ps.market.getAvailableResources()` — Available energy/bandwidth
|
|
94
|
+
- `ps.market.getOverview()` — Full market snapshot
|
|
95
|
+
|
|
96
|
+
### Buyer (auth required)
|
|
97
|
+
|
|
98
|
+
- `ps.buyer.buyEnergy(params)` — Purchase energy
|
|
99
|
+
- `ps.buyer.getBalance()` — Account balance
|
|
100
|
+
- `ps.buyer.getOrderStatus(orderId)` — Order details
|
|
101
|
+
- `ps.buyer.broadcast(params)` — Broadcast pre-signed tx
|
|
102
|
+
|
|
103
|
+
### Registration (public)
|
|
104
|
+
|
|
105
|
+
- `ps.register(address)` — Start registration
|
|
106
|
+
- `ps.verify(challengeId, address, signature)` — Verify & get API key
|
|
107
|
+
- `ps.paymentStatus(intentId)` — Check 402 payment status
|
|
108
|
+
|
|
109
|
+
## Links
|
|
110
|
+
|
|
111
|
+
- **Platform:** [powersun.vip](https://powersun.vip)
|
|
112
|
+
- **MCP Server:** [powersun.vip/mcp](https://powersun.vip/mcp)
|
|
113
|
+
- **API Docs:** [powersun.vip/api-docs](https://powersun.vip/api-docs)
|
|
114
|
+
|
|
115
|
+
## License
|
|
116
|
+
|
|
117
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/** PowerSun SDK configuration */
|
|
2
|
+
interface PowerSunConfig {
|
|
3
|
+
/** API key (format: ps_*). Required for authenticated endpoints. */
|
|
4
|
+
apiKey?: string;
|
|
5
|
+
/** Base URL of the PowerSun API. Default: https://powersun.vip */
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
/** Request timeout in ms. Default: 30000 */
|
|
8
|
+
timeout?: number;
|
|
9
|
+
}
|
|
10
|
+
interface PriceTier {
|
|
11
|
+
durationMinutes: number;
|
|
12
|
+
durationLabel: string;
|
|
13
|
+
energyPriceSun: number;
|
|
14
|
+
bandwidthPriceSun: number;
|
|
15
|
+
}
|
|
16
|
+
interface PricesResponse {
|
|
17
|
+
tiers: PriceTier[];
|
|
18
|
+
updatedAt: string;
|
|
19
|
+
}
|
|
20
|
+
interface EstimateCostParams {
|
|
21
|
+
energy?: number;
|
|
22
|
+
bandwidth?: number;
|
|
23
|
+
txCount?: number;
|
|
24
|
+
txType?: 'trc20_transfer' | 'trc20_transfer_new' | 'trc10_transfer' | 'contract_call';
|
|
25
|
+
durationMinutes?: 5 | 10 | 15 | 30 | 60 | 120 | 1440 | 10080;
|
|
26
|
+
resourceType?: 'ENERGY' | 'BANDWIDTH';
|
|
27
|
+
}
|
|
28
|
+
interface EstimateResponse {
|
|
29
|
+
estimate: {
|
|
30
|
+
txCount: number;
|
|
31
|
+
energyPerTx: number;
|
|
32
|
+
totalEnergyNeeded: number;
|
|
33
|
+
durationMinutes: number;
|
|
34
|
+
resourceType: string;
|
|
35
|
+
};
|
|
36
|
+
pricing: {
|
|
37
|
+
pricePerUnitSun: number;
|
|
38
|
+
totalCostSun: number;
|
|
39
|
+
totalCostTrx: number;
|
|
40
|
+
costPerTxTrx: number;
|
|
41
|
+
burnCostPerTxTrx: number;
|
|
42
|
+
savingsPercent: number;
|
|
43
|
+
};
|
|
44
|
+
constraints: {
|
|
45
|
+
minimumOrderSize: number;
|
|
46
|
+
allowedDurations: number[];
|
|
47
|
+
meetsMinimum: boolean;
|
|
48
|
+
};
|
|
49
|
+
balance?: {
|
|
50
|
+
currentTrx: number;
|
|
51
|
+
sufficient: boolean;
|
|
52
|
+
remainingAfterTrx: number;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
interface AvailableResourcesResponse {
|
|
56
|
+
energy: {
|
|
57
|
+
total: number;
|
|
58
|
+
available: number;
|
|
59
|
+
};
|
|
60
|
+
bandwidth: {
|
|
61
|
+
total: number;
|
|
62
|
+
available: number;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
interface MarketOverviewResponse {
|
|
66
|
+
prices: PriceTier[];
|
|
67
|
+
availability: AvailableResourcesResponse;
|
|
68
|
+
stats: {
|
|
69
|
+
totalOrders24h: number;
|
|
70
|
+
totalVolume24hTrx: number;
|
|
71
|
+
activePools: number;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
interface BuyEnergyParams {
|
|
75
|
+
targetAddress: string;
|
|
76
|
+
txCount: number;
|
|
77
|
+
txType?: 'trc20_transfer' | 'trc20_transfer_new' | 'trc10_transfer' | 'contract_call';
|
|
78
|
+
durationMinutes?: 5 | 10 | 15 | 30 | 60 | 120 | 1440 | 10080;
|
|
79
|
+
resourceType?: 'ENERGY' | 'BANDWIDTH';
|
|
80
|
+
maxPriceTrx?: number;
|
|
81
|
+
}
|
|
82
|
+
interface OrderResponse {
|
|
83
|
+
order: {
|
|
84
|
+
orderId: string;
|
|
85
|
+
status: 'pending' | 'active' | 'completed' | 'failed';
|
|
86
|
+
targetAddress: string;
|
|
87
|
+
resourceType: string;
|
|
88
|
+
energyAmount: number;
|
|
89
|
+
durationMinutes: number;
|
|
90
|
+
totalCostTrx: number;
|
|
91
|
+
totalCostSun: number;
|
|
92
|
+
createdAt: string;
|
|
93
|
+
estimatedDelivery: string;
|
|
94
|
+
};
|
|
95
|
+
balance: {
|
|
96
|
+
previousTrx: number;
|
|
97
|
+
deductedTrx: number;
|
|
98
|
+
remainingTrx: number;
|
|
99
|
+
};
|
|
100
|
+
nextAction: {
|
|
101
|
+
action: string;
|
|
102
|
+
url: string;
|
|
103
|
+
pollIntervalSeconds: number;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
interface PaymentRequiredResponse {
|
|
107
|
+
error: 'payment_required';
|
|
108
|
+
message: string;
|
|
109
|
+
payment: {
|
|
110
|
+
depositAddress: string;
|
|
111
|
+
requiredAmountTrx: number;
|
|
112
|
+
requiredAmountSun: number;
|
|
113
|
+
intentId: string;
|
|
114
|
+
expiresAt: string;
|
|
115
|
+
checkStatusUrl: string;
|
|
116
|
+
scheme: string;
|
|
117
|
+
};
|
|
118
|
+
x402?: {
|
|
119
|
+
scheme: string;
|
|
120
|
+
network: string;
|
|
121
|
+
asset: string;
|
|
122
|
+
maxAmountRequired: string;
|
|
123
|
+
payTo: string;
|
|
124
|
+
intentId: string;
|
|
125
|
+
expiresAt: string;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
interface BalanceResponse {
|
|
129
|
+
address: string;
|
|
130
|
+
balanceTrx: number;
|
|
131
|
+
balanceSun: number;
|
|
132
|
+
estimatedCapacity: {
|
|
133
|
+
trc20Transfers: {
|
|
134
|
+
count: number;
|
|
135
|
+
atDuration: string;
|
|
136
|
+
pricePerTxTrx: number;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
depositAddress: string;
|
|
140
|
+
depositInstructions: string;
|
|
141
|
+
}
|
|
142
|
+
interface OrderStatusResponse {
|
|
143
|
+
orderId: string;
|
|
144
|
+
status: 'pending' | 'active' | 'completed' | 'failed';
|
|
145
|
+
resourceType: string;
|
|
146
|
+
energyDelegated: number;
|
|
147
|
+
targetAddress: string;
|
|
148
|
+
durationMinutes: number;
|
|
149
|
+
totalCostTrx: number;
|
|
150
|
+
createdAt: string;
|
|
151
|
+
completedAt: string | null;
|
|
152
|
+
progress: {
|
|
153
|
+
totalSize: number;
|
|
154
|
+
filledSize: number;
|
|
155
|
+
percentFilled: number;
|
|
156
|
+
fillCount: number;
|
|
157
|
+
};
|
|
158
|
+
fills: Array<{
|
|
159
|
+
poolId: string;
|
|
160
|
+
filledSize: number;
|
|
161
|
+
status: string;
|
|
162
|
+
txHash: string;
|
|
163
|
+
}>;
|
|
164
|
+
}
|
|
165
|
+
interface PaymentStatusResponse {
|
|
166
|
+
status: 'pending' | 'success' | 'expired' | 'failed';
|
|
167
|
+
intentId: string;
|
|
168
|
+
confirmedAt: string | null;
|
|
169
|
+
order: {
|
|
170
|
+
orderId: string;
|
|
171
|
+
status: string;
|
|
172
|
+
targetAddress: string;
|
|
173
|
+
} | null;
|
|
174
|
+
}
|
|
175
|
+
interface BroadcastParams {
|
|
176
|
+
txData: {
|
|
177
|
+
txID: string;
|
|
178
|
+
raw_data: Record<string, unknown>;
|
|
179
|
+
raw_data_hex?: string;
|
|
180
|
+
signature?: string[];
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
interface BroadcastResponse {
|
|
184
|
+
orderId: string;
|
|
185
|
+
status: string;
|
|
186
|
+
txId: string;
|
|
187
|
+
resourceType: string;
|
|
188
|
+
energyDelegated: number;
|
|
189
|
+
costTrx: number;
|
|
190
|
+
}
|
|
191
|
+
interface RegisterResponse {
|
|
192
|
+
challenge: string;
|
|
193
|
+
challengeId: string;
|
|
194
|
+
expiresAt: string;
|
|
195
|
+
}
|
|
196
|
+
interface VerifyResponse {
|
|
197
|
+
apiKey: string;
|
|
198
|
+
address: string;
|
|
199
|
+
}
|
|
200
|
+
declare class PowerSunError extends Error {
|
|
201
|
+
status: number;
|
|
202
|
+
code?: string | undefined;
|
|
203
|
+
details?: unknown | undefined;
|
|
204
|
+
constructor(message: string, status: number, code?: string | undefined, details?: unknown | undefined);
|
|
205
|
+
}
|
|
206
|
+
declare class PaymentRequiredError extends PowerSunError {
|
|
207
|
+
payment: PaymentRequiredResponse['payment'];
|
|
208
|
+
x402?: PaymentRequiredResponse['x402'];
|
|
209
|
+
constructor(data: PaymentRequiredResponse);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
declare class PowerSun {
|
|
213
|
+
private baseUrl;
|
|
214
|
+
private apiKey?;
|
|
215
|
+
private timeout;
|
|
216
|
+
readonly market: MarketAPI;
|
|
217
|
+
readonly buyer: BuyerAPI;
|
|
218
|
+
constructor(config?: PowerSunConfig);
|
|
219
|
+
/** Internal HTTP request handler */
|
|
220
|
+
request<T>(method: string, path: string, body?: unknown): Promise<T>;
|
|
221
|
+
/** Start registration — returns a challenge to sign with your TRON wallet */
|
|
222
|
+
register(address: string): Promise<RegisterResponse>;
|
|
223
|
+
/** Verify signature and receive API key */
|
|
224
|
+
verify(challengeId: string, address: string, signature: string): Promise<VerifyResponse>;
|
|
225
|
+
/** Check HTTP 402 payment status (no auth required) */
|
|
226
|
+
paymentStatus(intentId: string): Promise<PaymentStatusResponse>;
|
|
227
|
+
}
|
|
228
|
+
declare class MarketAPI {
|
|
229
|
+
private client;
|
|
230
|
+
constructor(client: PowerSun);
|
|
231
|
+
/** Get current Energy & Bandwidth prices for all duration tiers */
|
|
232
|
+
getPrices(): Promise<PricesResponse>;
|
|
233
|
+
/** Estimate cost for a specific energy amount and duration */
|
|
234
|
+
estimateCost(params: EstimateCostParams): Promise<EstimateResponse>;
|
|
235
|
+
/** Check available Energy & Bandwidth in the marketplace */
|
|
236
|
+
getAvailableResources(): Promise<AvailableResourcesResponse>;
|
|
237
|
+
/** Full market snapshot — prices, availability, order stats */
|
|
238
|
+
getOverview(): Promise<MarketOverviewResponse>;
|
|
239
|
+
}
|
|
240
|
+
declare class BuyerAPI {
|
|
241
|
+
private client;
|
|
242
|
+
constructor(client: PowerSun);
|
|
243
|
+
/**
|
|
244
|
+
* Purchase Energy delegation for a TRON address.
|
|
245
|
+
*
|
|
246
|
+
* If authenticated (API key), deducts from balance and returns order.
|
|
247
|
+
* If not authenticated, throws PaymentRequiredError with payment instructions.
|
|
248
|
+
*
|
|
249
|
+
* @throws {PaymentRequiredError} When no API key — contains deposit address and x402 info
|
|
250
|
+
*/
|
|
251
|
+
buyEnergy(params: BuyEnergyParams): Promise<OrderResponse>;
|
|
252
|
+
/** Get account balance and deposit info. Requires API key. */
|
|
253
|
+
getBalance(): Promise<BalanceResponse>;
|
|
254
|
+
/** Get order status with delegation progress. Requires API key. */
|
|
255
|
+
getOrderStatus(orderId: string): Promise<OrderStatusResponse>;
|
|
256
|
+
/**
|
|
257
|
+
* Broadcast a pre-signed TRON transaction with automatic Energy delegation.
|
|
258
|
+
* The platform estimates required energy, delegates it, then broadcasts. Requires API key.
|
|
259
|
+
*/
|
|
260
|
+
broadcast(params: BroadcastParams): Promise<BroadcastResponse>;
|
|
261
|
+
/** Check HTTP 402 payment status (no auth required) */
|
|
262
|
+
paymentStatus(intentId: string): Promise<PaymentStatusResponse>;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export { type AvailableResourcesResponse, type BalanceResponse, type BroadcastParams, type BroadcastResponse, type BuyEnergyParams, type EstimateCostParams, type EstimateResponse, type MarketOverviewResponse, type OrderResponse, type OrderStatusResponse, PaymentRequiredError, type PaymentStatusResponse, PowerSun, type PowerSunConfig, PowerSunError, type PriceTier, type PricesResponse, type RegisterResponse, type VerifyResponse };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/** PowerSun SDK configuration */
|
|
2
|
+
interface PowerSunConfig {
|
|
3
|
+
/** API key (format: ps_*). Required for authenticated endpoints. */
|
|
4
|
+
apiKey?: string;
|
|
5
|
+
/** Base URL of the PowerSun API. Default: https://powersun.vip */
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
/** Request timeout in ms. Default: 30000 */
|
|
8
|
+
timeout?: number;
|
|
9
|
+
}
|
|
10
|
+
interface PriceTier {
|
|
11
|
+
durationMinutes: number;
|
|
12
|
+
durationLabel: string;
|
|
13
|
+
energyPriceSun: number;
|
|
14
|
+
bandwidthPriceSun: number;
|
|
15
|
+
}
|
|
16
|
+
interface PricesResponse {
|
|
17
|
+
tiers: PriceTier[];
|
|
18
|
+
updatedAt: string;
|
|
19
|
+
}
|
|
20
|
+
interface EstimateCostParams {
|
|
21
|
+
energy?: number;
|
|
22
|
+
bandwidth?: number;
|
|
23
|
+
txCount?: number;
|
|
24
|
+
txType?: 'trc20_transfer' | 'trc20_transfer_new' | 'trc10_transfer' | 'contract_call';
|
|
25
|
+
durationMinutes?: 5 | 10 | 15 | 30 | 60 | 120 | 1440 | 10080;
|
|
26
|
+
resourceType?: 'ENERGY' | 'BANDWIDTH';
|
|
27
|
+
}
|
|
28
|
+
interface EstimateResponse {
|
|
29
|
+
estimate: {
|
|
30
|
+
txCount: number;
|
|
31
|
+
energyPerTx: number;
|
|
32
|
+
totalEnergyNeeded: number;
|
|
33
|
+
durationMinutes: number;
|
|
34
|
+
resourceType: string;
|
|
35
|
+
};
|
|
36
|
+
pricing: {
|
|
37
|
+
pricePerUnitSun: number;
|
|
38
|
+
totalCostSun: number;
|
|
39
|
+
totalCostTrx: number;
|
|
40
|
+
costPerTxTrx: number;
|
|
41
|
+
burnCostPerTxTrx: number;
|
|
42
|
+
savingsPercent: number;
|
|
43
|
+
};
|
|
44
|
+
constraints: {
|
|
45
|
+
minimumOrderSize: number;
|
|
46
|
+
allowedDurations: number[];
|
|
47
|
+
meetsMinimum: boolean;
|
|
48
|
+
};
|
|
49
|
+
balance?: {
|
|
50
|
+
currentTrx: number;
|
|
51
|
+
sufficient: boolean;
|
|
52
|
+
remainingAfterTrx: number;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
interface AvailableResourcesResponse {
|
|
56
|
+
energy: {
|
|
57
|
+
total: number;
|
|
58
|
+
available: number;
|
|
59
|
+
};
|
|
60
|
+
bandwidth: {
|
|
61
|
+
total: number;
|
|
62
|
+
available: number;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
interface MarketOverviewResponse {
|
|
66
|
+
prices: PriceTier[];
|
|
67
|
+
availability: AvailableResourcesResponse;
|
|
68
|
+
stats: {
|
|
69
|
+
totalOrders24h: number;
|
|
70
|
+
totalVolume24hTrx: number;
|
|
71
|
+
activePools: number;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
interface BuyEnergyParams {
|
|
75
|
+
targetAddress: string;
|
|
76
|
+
txCount: number;
|
|
77
|
+
txType?: 'trc20_transfer' | 'trc20_transfer_new' | 'trc10_transfer' | 'contract_call';
|
|
78
|
+
durationMinutes?: 5 | 10 | 15 | 30 | 60 | 120 | 1440 | 10080;
|
|
79
|
+
resourceType?: 'ENERGY' | 'BANDWIDTH';
|
|
80
|
+
maxPriceTrx?: number;
|
|
81
|
+
}
|
|
82
|
+
interface OrderResponse {
|
|
83
|
+
order: {
|
|
84
|
+
orderId: string;
|
|
85
|
+
status: 'pending' | 'active' | 'completed' | 'failed';
|
|
86
|
+
targetAddress: string;
|
|
87
|
+
resourceType: string;
|
|
88
|
+
energyAmount: number;
|
|
89
|
+
durationMinutes: number;
|
|
90
|
+
totalCostTrx: number;
|
|
91
|
+
totalCostSun: number;
|
|
92
|
+
createdAt: string;
|
|
93
|
+
estimatedDelivery: string;
|
|
94
|
+
};
|
|
95
|
+
balance: {
|
|
96
|
+
previousTrx: number;
|
|
97
|
+
deductedTrx: number;
|
|
98
|
+
remainingTrx: number;
|
|
99
|
+
};
|
|
100
|
+
nextAction: {
|
|
101
|
+
action: string;
|
|
102
|
+
url: string;
|
|
103
|
+
pollIntervalSeconds: number;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
interface PaymentRequiredResponse {
|
|
107
|
+
error: 'payment_required';
|
|
108
|
+
message: string;
|
|
109
|
+
payment: {
|
|
110
|
+
depositAddress: string;
|
|
111
|
+
requiredAmountTrx: number;
|
|
112
|
+
requiredAmountSun: number;
|
|
113
|
+
intentId: string;
|
|
114
|
+
expiresAt: string;
|
|
115
|
+
checkStatusUrl: string;
|
|
116
|
+
scheme: string;
|
|
117
|
+
};
|
|
118
|
+
x402?: {
|
|
119
|
+
scheme: string;
|
|
120
|
+
network: string;
|
|
121
|
+
asset: string;
|
|
122
|
+
maxAmountRequired: string;
|
|
123
|
+
payTo: string;
|
|
124
|
+
intentId: string;
|
|
125
|
+
expiresAt: string;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
interface BalanceResponse {
|
|
129
|
+
address: string;
|
|
130
|
+
balanceTrx: number;
|
|
131
|
+
balanceSun: number;
|
|
132
|
+
estimatedCapacity: {
|
|
133
|
+
trc20Transfers: {
|
|
134
|
+
count: number;
|
|
135
|
+
atDuration: string;
|
|
136
|
+
pricePerTxTrx: number;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
depositAddress: string;
|
|
140
|
+
depositInstructions: string;
|
|
141
|
+
}
|
|
142
|
+
interface OrderStatusResponse {
|
|
143
|
+
orderId: string;
|
|
144
|
+
status: 'pending' | 'active' | 'completed' | 'failed';
|
|
145
|
+
resourceType: string;
|
|
146
|
+
energyDelegated: number;
|
|
147
|
+
targetAddress: string;
|
|
148
|
+
durationMinutes: number;
|
|
149
|
+
totalCostTrx: number;
|
|
150
|
+
createdAt: string;
|
|
151
|
+
completedAt: string | null;
|
|
152
|
+
progress: {
|
|
153
|
+
totalSize: number;
|
|
154
|
+
filledSize: number;
|
|
155
|
+
percentFilled: number;
|
|
156
|
+
fillCount: number;
|
|
157
|
+
};
|
|
158
|
+
fills: Array<{
|
|
159
|
+
poolId: string;
|
|
160
|
+
filledSize: number;
|
|
161
|
+
status: string;
|
|
162
|
+
txHash: string;
|
|
163
|
+
}>;
|
|
164
|
+
}
|
|
165
|
+
interface PaymentStatusResponse {
|
|
166
|
+
status: 'pending' | 'success' | 'expired' | 'failed';
|
|
167
|
+
intentId: string;
|
|
168
|
+
confirmedAt: string | null;
|
|
169
|
+
order: {
|
|
170
|
+
orderId: string;
|
|
171
|
+
status: string;
|
|
172
|
+
targetAddress: string;
|
|
173
|
+
} | null;
|
|
174
|
+
}
|
|
175
|
+
interface BroadcastParams {
|
|
176
|
+
txData: {
|
|
177
|
+
txID: string;
|
|
178
|
+
raw_data: Record<string, unknown>;
|
|
179
|
+
raw_data_hex?: string;
|
|
180
|
+
signature?: string[];
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
interface BroadcastResponse {
|
|
184
|
+
orderId: string;
|
|
185
|
+
status: string;
|
|
186
|
+
txId: string;
|
|
187
|
+
resourceType: string;
|
|
188
|
+
energyDelegated: number;
|
|
189
|
+
costTrx: number;
|
|
190
|
+
}
|
|
191
|
+
interface RegisterResponse {
|
|
192
|
+
challenge: string;
|
|
193
|
+
challengeId: string;
|
|
194
|
+
expiresAt: string;
|
|
195
|
+
}
|
|
196
|
+
interface VerifyResponse {
|
|
197
|
+
apiKey: string;
|
|
198
|
+
address: string;
|
|
199
|
+
}
|
|
200
|
+
declare class PowerSunError extends Error {
|
|
201
|
+
status: number;
|
|
202
|
+
code?: string | undefined;
|
|
203
|
+
details?: unknown | undefined;
|
|
204
|
+
constructor(message: string, status: number, code?: string | undefined, details?: unknown | undefined);
|
|
205
|
+
}
|
|
206
|
+
declare class PaymentRequiredError extends PowerSunError {
|
|
207
|
+
payment: PaymentRequiredResponse['payment'];
|
|
208
|
+
x402?: PaymentRequiredResponse['x402'];
|
|
209
|
+
constructor(data: PaymentRequiredResponse);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
declare class PowerSun {
|
|
213
|
+
private baseUrl;
|
|
214
|
+
private apiKey?;
|
|
215
|
+
private timeout;
|
|
216
|
+
readonly market: MarketAPI;
|
|
217
|
+
readonly buyer: BuyerAPI;
|
|
218
|
+
constructor(config?: PowerSunConfig);
|
|
219
|
+
/** Internal HTTP request handler */
|
|
220
|
+
request<T>(method: string, path: string, body?: unknown): Promise<T>;
|
|
221
|
+
/** Start registration — returns a challenge to sign with your TRON wallet */
|
|
222
|
+
register(address: string): Promise<RegisterResponse>;
|
|
223
|
+
/** Verify signature and receive API key */
|
|
224
|
+
verify(challengeId: string, address: string, signature: string): Promise<VerifyResponse>;
|
|
225
|
+
/** Check HTTP 402 payment status (no auth required) */
|
|
226
|
+
paymentStatus(intentId: string): Promise<PaymentStatusResponse>;
|
|
227
|
+
}
|
|
228
|
+
declare class MarketAPI {
|
|
229
|
+
private client;
|
|
230
|
+
constructor(client: PowerSun);
|
|
231
|
+
/** Get current Energy & Bandwidth prices for all duration tiers */
|
|
232
|
+
getPrices(): Promise<PricesResponse>;
|
|
233
|
+
/** Estimate cost for a specific energy amount and duration */
|
|
234
|
+
estimateCost(params: EstimateCostParams): Promise<EstimateResponse>;
|
|
235
|
+
/** Check available Energy & Bandwidth in the marketplace */
|
|
236
|
+
getAvailableResources(): Promise<AvailableResourcesResponse>;
|
|
237
|
+
/** Full market snapshot — prices, availability, order stats */
|
|
238
|
+
getOverview(): Promise<MarketOverviewResponse>;
|
|
239
|
+
}
|
|
240
|
+
declare class BuyerAPI {
|
|
241
|
+
private client;
|
|
242
|
+
constructor(client: PowerSun);
|
|
243
|
+
/**
|
|
244
|
+
* Purchase Energy delegation for a TRON address.
|
|
245
|
+
*
|
|
246
|
+
* If authenticated (API key), deducts from balance and returns order.
|
|
247
|
+
* If not authenticated, throws PaymentRequiredError with payment instructions.
|
|
248
|
+
*
|
|
249
|
+
* @throws {PaymentRequiredError} When no API key — contains deposit address and x402 info
|
|
250
|
+
*/
|
|
251
|
+
buyEnergy(params: BuyEnergyParams): Promise<OrderResponse>;
|
|
252
|
+
/** Get account balance and deposit info. Requires API key. */
|
|
253
|
+
getBalance(): Promise<BalanceResponse>;
|
|
254
|
+
/** Get order status with delegation progress. Requires API key. */
|
|
255
|
+
getOrderStatus(orderId: string): Promise<OrderStatusResponse>;
|
|
256
|
+
/**
|
|
257
|
+
* Broadcast a pre-signed TRON transaction with automatic Energy delegation.
|
|
258
|
+
* The platform estimates required energy, delegates it, then broadcasts. Requires API key.
|
|
259
|
+
*/
|
|
260
|
+
broadcast(params: BroadcastParams): Promise<BroadcastResponse>;
|
|
261
|
+
/** Check HTTP 402 payment status (no auth required) */
|
|
262
|
+
paymentStatus(intentId: string): Promise<PaymentStatusResponse>;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export { type AvailableResourcesResponse, type BalanceResponse, type BroadcastParams, type BroadcastResponse, type BuyEnergyParams, type EstimateCostParams, type EstimateResponse, type MarketOverviewResponse, type OrderResponse, type OrderStatusResponse, PaymentRequiredError, type PaymentStatusResponse, PowerSun, type PowerSunConfig, PowerSunError, type PriceTier, type PricesResponse, type RegisterResponse, type VerifyResponse };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
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
|
+
PaymentRequiredError: () => PaymentRequiredError,
|
|
24
|
+
PowerSun: () => PowerSun,
|
|
25
|
+
PowerSunError: () => PowerSunError
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
|
|
29
|
+
// src/types.ts
|
|
30
|
+
var PowerSunError = class extends Error {
|
|
31
|
+
constructor(message, status, code, details) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.status = status;
|
|
34
|
+
this.code = code;
|
|
35
|
+
this.details = details;
|
|
36
|
+
this.name = "PowerSunError";
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var PaymentRequiredError = class extends PowerSunError {
|
|
40
|
+
constructor(data) {
|
|
41
|
+
super(data.message, 402, "payment_required");
|
|
42
|
+
this.name = "PaymentRequiredError";
|
|
43
|
+
this.payment = data.payment;
|
|
44
|
+
this.x402 = data.x402;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/client.ts
|
|
49
|
+
var DEFAULT_BASE_URL = "https://powersun.vip";
|
|
50
|
+
var DEFAULT_TIMEOUT = 3e4;
|
|
51
|
+
var PowerSun = class {
|
|
52
|
+
constructor(config = {}) {
|
|
53
|
+
this.baseUrl = (config.baseUrl || DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
54
|
+
this.apiKey = config.apiKey;
|
|
55
|
+
this.timeout = config.timeout || DEFAULT_TIMEOUT;
|
|
56
|
+
this.market = new MarketAPI(this);
|
|
57
|
+
this.buyer = new BuyerAPI(this);
|
|
58
|
+
}
|
|
59
|
+
/** Internal HTTP request handler */
|
|
60
|
+
async request(method, path, body) {
|
|
61
|
+
const url = `${this.baseUrl}${path}`;
|
|
62
|
+
const headers = {
|
|
63
|
+
"Content-Type": "application/json",
|
|
64
|
+
"User-Agent": "@powersun/mcp-client/1.0.0"
|
|
65
|
+
};
|
|
66
|
+
if (this.apiKey) {
|
|
67
|
+
headers["X-API-Key"] = this.apiKey;
|
|
68
|
+
}
|
|
69
|
+
const controller = new AbortController();
|
|
70
|
+
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
71
|
+
try {
|
|
72
|
+
const res = await fetch(url, {
|
|
73
|
+
method,
|
|
74
|
+
headers,
|
|
75
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
76
|
+
signal: controller.signal
|
|
77
|
+
});
|
|
78
|
+
const data = await res.json().catch(() => null);
|
|
79
|
+
if (res.status === 402 && data) {
|
|
80
|
+
throw new PaymentRequiredError(data);
|
|
81
|
+
}
|
|
82
|
+
if (!res.ok) {
|
|
83
|
+
throw new PowerSunError(
|
|
84
|
+
data?.error || data?.message || `HTTP ${res.status}`,
|
|
85
|
+
res.status,
|
|
86
|
+
data?.code,
|
|
87
|
+
data
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
return data;
|
|
91
|
+
} finally {
|
|
92
|
+
clearTimeout(timer);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// ─── Registration (static-like, no API key needed) ────────────────────
|
|
96
|
+
/** Start registration — returns a challenge to sign with your TRON wallet */
|
|
97
|
+
async register(address) {
|
|
98
|
+
return this.request("POST", "/api/v2/agent/register", { address });
|
|
99
|
+
}
|
|
100
|
+
/** Verify signature and receive API key */
|
|
101
|
+
async verify(challengeId, address, signature) {
|
|
102
|
+
return this.request("POST", "/api/v2/agent/verify", { challengeId, address, signature });
|
|
103
|
+
}
|
|
104
|
+
/** Check HTTP 402 payment status (no auth required) */
|
|
105
|
+
async paymentStatus(intentId) {
|
|
106
|
+
return this.request("GET", `/api/v2/agent/payment-status/${intentId}`);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
var MarketAPI = class {
|
|
110
|
+
constructor(client) {
|
|
111
|
+
this.client = client;
|
|
112
|
+
}
|
|
113
|
+
/** Get current Energy & Bandwidth prices for all duration tiers */
|
|
114
|
+
async getPrices() {
|
|
115
|
+
return this.client.request("GET", "/api/v2/agent/prices");
|
|
116
|
+
}
|
|
117
|
+
/** Estimate cost for a specific energy amount and duration */
|
|
118
|
+
async estimateCost(params) {
|
|
119
|
+
return this.client.request("POST", "/api/v2/agent/estimate", params);
|
|
120
|
+
}
|
|
121
|
+
/** Check available Energy & Bandwidth in the marketplace */
|
|
122
|
+
async getAvailableResources() {
|
|
123
|
+
return this.client.request("GET", "/api/v2/agent/resources");
|
|
124
|
+
}
|
|
125
|
+
/** Full market snapshot — prices, availability, order stats */
|
|
126
|
+
async getOverview() {
|
|
127
|
+
return this.client.request("GET", "/api/v2/agent/market-overview");
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
var BuyerAPI = class {
|
|
131
|
+
constructor(client) {
|
|
132
|
+
this.client = client;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Purchase Energy delegation for a TRON address.
|
|
136
|
+
*
|
|
137
|
+
* If authenticated (API key), deducts from balance and returns order.
|
|
138
|
+
* If not authenticated, throws PaymentRequiredError with payment instructions.
|
|
139
|
+
*
|
|
140
|
+
* @throws {PaymentRequiredError} When no API key — contains deposit address and x402 info
|
|
141
|
+
*/
|
|
142
|
+
async buyEnergy(params) {
|
|
143
|
+
return this.client.request("POST", "/api/v2/agent/buy-energy", params);
|
|
144
|
+
}
|
|
145
|
+
/** Get account balance and deposit info. Requires API key. */
|
|
146
|
+
async getBalance() {
|
|
147
|
+
return this.client.request("GET", "/api/v2/agent/balance");
|
|
148
|
+
}
|
|
149
|
+
/** Get order status with delegation progress. Requires API key. */
|
|
150
|
+
async getOrderStatus(orderId) {
|
|
151
|
+
return this.client.request("GET", `/api/v2/agent/order/${orderId}`);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Broadcast a pre-signed TRON transaction with automatic Energy delegation.
|
|
155
|
+
* The platform estimates required energy, delegates it, then broadcasts. Requires API key.
|
|
156
|
+
*/
|
|
157
|
+
async broadcast(params) {
|
|
158
|
+
return this.client.request("POST", "/api/v2/agent/broadcast", params);
|
|
159
|
+
}
|
|
160
|
+
/** Check HTTP 402 payment status (no auth required) */
|
|
161
|
+
async paymentStatus(intentId) {
|
|
162
|
+
return this.client.request("GET", `/api/v2/agent/payment-status/${intentId}`);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
166
|
+
0 && (module.exports = {
|
|
167
|
+
PaymentRequiredError,
|
|
168
|
+
PowerSun,
|
|
169
|
+
PowerSunError
|
|
170
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// src/types.ts
|
|
2
|
+
var PowerSunError = class extends Error {
|
|
3
|
+
constructor(message, status, code, details) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.status = status;
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.details = details;
|
|
8
|
+
this.name = "PowerSunError";
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var PaymentRequiredError = class extends PowerSunError {
|
|
12
|
+
constructor(data) {
|
|
13
|
+
super(data.message, 402, "payment_required");
|
|
14
|
+
this.name = "PaymentRequiredError";
|
|
15
|
+
this.payment = data.payment;
|
|
16
|
+
this.x402 = data.x402;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// src/client.ts
|
|
21
|
+
var DEFAULT_BASE_URL = "https://powersun.vip";
|
|
22
|
+
var DEFAULT_TIMEOUT = 3e4;
|
|
23
|
+
var PowerSun = class {
|
|
24
|
+
constructor(config = {}) {
|
|
25
|
+
this.baseUrl = (config.baseUrl || DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
26
|
+
this.apiKey = config.apiKey;
|
|
27
|
+
this.timeout = config.timeout || DEFAULT_TIMEOUT;
|
|
28
|
+
this.market = new MarketAPI(this);
|
|
29
|
+
this.buyer = new BuyerAPI(this);
|
|
30
|
+
}
|
|
31
|
+
/** Internal HTTP request handler */
|
|
32
|
+
async request(method, path, body) {
|
|
33
|
+
const url = `${this.baseUrl}${path}`;
|
|
34
|
+
const headers = {
|
|
35
|
+
"Content-Type": "application/json",
|
|
36
|
+
"User-Agent": "@powersun/mcp-client/1.0.0"
|
|
37
|
+
};
|
|
38
|
+
if (this.apiKey) {
|
|
39
|
+
headers["X-API-Key"] = this.apiKey;
|
|
40
|
+
}
|
|
41
|
+
const controller = new AbortController();
|
|
42
|
+
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
43
|
+
try {
|
|
44
|
+
const res = await fetch(url, {
|
|
45
|
+
method,
|
|
46
|
+
headers,
|
|
47
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
48
|
+
signal: controller.signal
|
|
49
|
+
});
|
|
50
|
+
const data = await res.json().catch(() => null);
|
|
51
|
+
if (res.status === 402 && data) {
|
|
52
|
+
throw new PaymentRequiredError(data);
|
|
53
|
+
}
|
|
54
|
+
if (!res.ok) {
|
|
55
|
+
throw new PowerSunError(
|
|
56
|
+
data?.error || data?.message || `HTTP ${res.status}`,
|
|
57
|
+
res.status,
|
|
58
|
+
data?.code,
|
|
59
|
+
data
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return data;
|
|
63
|
+
} finally {
|
|
64
|
+
clearTimeout(timer);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// ─── Registration (static-like, no API key needed) ────────────────────
|
|
68
|
+
/** Start registration — returns a challenge to sign with your TRON wallet */
|
|
69
|
+
async register(address) {
|
|
70
|
+
return this.request("POST", "/api/v2/agent/register", { address });
|
|
71
|
+
}
|
|
72
|
+
/** Verify signature and receive API key */
|
|
73
|
+
async verify(challengeId, address, signature) {
|
|
74
|
+
return this.request("POST", "/api/v2/agent/verify", { challengeId, address, signature });
|
|
75
|
+
}
|
|
76
|
+
/** Check HTTP 402 payment status (no auth required) */
|
|
77
|
+
async paymentStatus(intentId) {
|
|
78
|
+
return this.request("GET", `/api/v2/agent/payment-status/${intentId}`);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
var MarketAPI = class {
|
|
82
|
+
constructor(client) {
|
|
83
|
+
this.client = client;
|
|
84
|
+
}
|
|
85
|
+
/** Get current Energy & Bandwidth prices for all duration tiers */
|
|
86
|
+
async getPrices() {
|
|
87
|
+
return this.client.request("GET", "/api/v2/agent/prices");
|
|
88
|
+
}
|
|
89
|
+
/** Estimate cost for a specific energy amount and duration */
|
|
90
|
+
async estimateCost(params) {
|
|
91
|
+
return this.client.request("POST", "/api/v2/agent/estimate", params);
|
|
92
|
+
}
|
|
93
|
+
/** Check available Energy & Bandwidth in the marketplace */
|
|
94
|
+
async getAvailableResources() {
|
|
95
|
+
return this.client.request("GET", "/api/v2/agent/resources");
|
|
96
|
+
}
|
|
97
|
+
/** Full market snapshot — prices, availability, order stats */
|
|
98
|
+
async getOverview() {
|
|
99
|
+
return this.client.request("GET", "/api/v2/agent/market-overview");
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
var BuyerAPI = class {
|
|
103
|
+
constructor(client) {
|
|
104
|
+
this.client = client;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Purchase Energy delegation for a TRON address.
|
|
108
|
+
*
|
|
109
|
+
* If authenticated (API key), deducts from balance and returns order.
|
|
110
|
+
* If not authenticated, throws PaymentRequiredError with payment instructions.
|
|
111
|
+
*
|
|
112
|
+
* @throws {PaymentRequiredError} When no API key — contains deposit address and x402 info
|
|
113
|
+
*/
|
|
114
|
+
async buyEnergy(params) {
|
|
115
|
+
return this.client.request("POST", "/api/v2/agent/buy-energy", params);
|
|
116
|
+
}
|
|
117
|
+
/** Get account balance and deposit info. Requires API key. */
|
|
118
|
+
async getBalance() {
|
|
119
|
+
return this.client.request("GET", "/api/v2/agent/balance");
|
|
120
|
+
}
|
|
121
|
+
/** Get order status with delegation progress. Requires API key. */
|
|
122
|
+
async getOrderStatus(orderId) {
|
|
123
|
+
return this.client.request("GET", `/api/v2/agent/order/${orderId}`);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Broadcast a pre-signed TRON transaction with automatic Energy delegation.
|
|
127
|
+
* The platform estimates required energy, delegates it, then broadcasts. Requires API key.
|
|
128
|
+
*/
|
|
129
|
+
async broadcast(params) {
|
|
130
|
+
return this.client.request("POST", "/api/v2/agent/broadcast", params);
|
|
131
|
+
}
|
|
132
|
+
/** Check HTTP 402 payment status (no auth required) */
|
|
133
|
+
async paymentStatus(intentId) {
|
|
134
|
+
return this.client.request("GET", `/api/v2/agent/payment-status/${intentId}`);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
export {
|
|
138
|
+
PaymentRequiredError,
|
|
139
|
+
PowerSun,
|
|
140
|
+
PowerSunError
|
|
141
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@powersun/mcp-client",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "TypeScript SDK for PowerSun.vip — TRON Energy & Bandwidth marketplace. Buy energy, sell resources, earn passive income.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": ["dist"],
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
18
|
+
"prepublishOnly": "npm run build"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"tron", "tron-energy", "tron-bandwidth", "trx", "usdt",
|
|
22
|
+
"energy-rental", "bandwidth", "blockchain", "crypto", "defi",
|
|
23
|
+
"mcp", "ai-agent", "powersun", "http-402", "x402"
|
|
24
|
+
],
|
|
25
|
+
"author": "PowerSun.vip",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"homepage": "https://powersun.vip",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/Hovsteder/powersun-tron-mcp"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"tsup": "^8.0.0",
|
|
34
|
+
"typescript": "^5.5.0"
|
|
35
|
+
}
|
|
36
|
+
}
|