@smoothsend/sdk 1.0.2 → 2.0.1
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 +45 -8
- package/dist/adapters/aptos.d.ts +1 -0
- package/dist/adapters/aptos.d.ts.map +1 -1
- package/dist/adapters/stellar-c-address.d.ts +179 -0
- package/dist/adapters/stellar-c-address.d.ts.map +1 -0
- package/dist/adapters/stellar.d.ts +31 -0
- package/dist/adapters/stellar.d.ts.map +1 -0
- package/dist/core/SmoothSendSDK.d.ts +16 -17
- package/dist/core/SmoothSendSDK.d.ts.map +1 -1
- package/dist/index.d.ts +288 -39
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +517 -52
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +519 -51
- package/dist/index.js.map +1 -1
- package/dist/shared-constants.d.ts +17 -9
- package/dist/shared-constants.d.ts.map +1 -1
- package/dist/types/index.d.ts +46 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/wallet-adapter/SmoothSendTransactionSubmitter.d.ts +7 -0
- package/dist/wallet-adapter/SmoothSendTransactionSubmitter.d.ts.map +1 -1
- package/package.json +9 -2
package/dist/index.js
CHANGED
|
@@ -280,7 +280,9 @@ function createNetworkError(error) {
|
|
|
280
280
|
const CHAIN_ECOSYSTEM_MAP = {
|
|
281
281
|
'avalanche': 'evm',
|
|
282
282
|
'aptos-testnet': 'aptos',
|
|
283
|
-
'aptos-mainnet': 'aptos'
|
|
283
|
+
'aptos-mainnet': 'aptos',
|
|
284
|
+
'stellar-testnet': 'stellar',
|
|
285
|
+
'stellar-mainnet': 'stellar',
|
|
284
286
|
};
|
|
285
287
|
/**
|
|
286
288
|
* Aptos-specific error codes
|
|
@@ -329,6 +331,16 @@ const APTOS_ERROR_CODES = {
|
|
|
329
331
|
/** Unsupported token */
|
|
330
332
|
UNSUPPORTED_TOKEN: 'APTOS_UNSUPPORTED_TOKEN'
|
|
331
333
|
};
|
|
334
|
+
/**
|
|
335
|
+
* Stellar adapter error codes
|
|
336
|
+
*/
|
|
337
|
+
const STELLAR_ERROR_CODES = {
|
|
338
|
+
MISSING_SIGNED_TRANSACTION: 'STELLAR_MISSING_SIGNED_TRANSACTION',
|
|
339
|
+
GASLESS_TRANSACTION_ERROR: 'STELLAR_GASLESS_TRANSACTION_ERROR',
|
|
340
|
+
STATUS_ERROR: 'STELLAR_STATUS_ERROR',
|
|
341
|
+
HEALTH_ERROR: 'STELLAR_HEALTH_ERROR',
|
|
342
|
+
INVALID_ADDRESS_FORMAT: 'STELLAR_INVALID_ADDRESS_FORMAT',
|
|
343
|
+
};
|
|
332
344
|
|
|
333
345
|
/**
|
|
334
346
|
* Shared Constants for SmoothSend Platform
|
|
@@ -910,15 +922,27 @@ class AptosAdapter {
|
|
|
910
922
|
}
|
|
911
923
|
/**
|
|
912
924
|
* Get Aptos token address from symbol
|
|
925
|
+
* Mirrors aptosrelayer/config/chains.json
|
|
913
926
|
*/
|
|
914
927
|
getAptosTokenAddress(tokenSymbol) {
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
928
|
+
const symbol = tokenSymbol.toUpperCase();
|
|
929
|
+
const TESTNET_TOKENS = {
|
|
930
|
+
USDC: '0x3c27315fb69ba6e4b960f1507d1cefcc9a4247869f26a8d59d6b7869d23782c::test_coins::USDC'
|
|
931
|
+
};
|
|
932
|
+
const MAINNET_TOKENS = {
|
|
933
|
+
USDT: '0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b',
|
|
934
|
+
USDC: '0xbae207659db88bea0cbead6da0ed00aac12edcdda169e591cd41c94180b46f3b',
|
|
935
|
+
WBTC: '0x68844a0d7f2587e726ad0579f3d640865bb4162c08a4589eeda3f9689ec52a3d',
|
|
936
|
+
USDE: '0xf37a8864fe737eb8ec2c2931047047cbaed1beed3fb0e5b7c5526dafd3b9c2e9',
|
|
937
|
+
USD1: '0x05fabd1b12e39967a3c24e91b7b8f67719a6dacee74f3c8b9fb7d93e855437d2'
|
|
938
|
+
};
|
|
939
|
+
const tokens = this.chain === 'aptos-testnet' ? TESTNET_TOKENS : MAINNET_TOKENS;
|
|
940
|
+
const address = tokens[symbol];
|
|
941
|
+
if (!address) {
|
|
942
|
+
const supported = Object.keys(tokens).join(', ');
|
|
943
|
+
throw new SmoothSendError(`Unsupported token: ${tokenSymbol} on ${this.chain}. Supported: ${supported}`, APTOS_ERROR_CODES.UNSUPPORTED_TOKEN, 400, { chain: this.chain, token: tokenSymbol, supported });
|
|
920
944
|
}
|
|
921
|
-
|
|
945
|
+
return address;
|
|
922
946
|
}
|
|
923
947
|
/**
|
|
924
948
|
* Build Aptos explorer URL for transaction
|
|
@@ -1035,6 +1059,396 @@ class AptosAdapter {
|
|
|
1035
1059
|
}
|
|
1036
1060
|
}
|
|
1037
1061
|
|
|
1062
|
+
/**
|
|
1063
|
+
* Stellar C-Address Adapter — SDK for Soroban Smart Account operations
|
|
1064
|
+
*
|
|
1065
|
+
* Provides a clean interface for:
|
|
1066
|
+
* - Creating C-addresses (smart accounts) from G-addresses
|
|
1067
|
+
* - Looking up existing C-addresses by owner
|
|
1068
|
+
* - Querying token balances (XLM, USDC, EURC)
|
|
1069
|
+
* - Building bridge transfers (G→C)
|
|
1070
|
+
* - Building smart account transfers (C→G, C→C)
|
|
1071
|
+
* - Submitting user-signed transactions via fee-bump
|
|
1072
|
+
* - Getting transaction history
|
|
1073
|
+
*
|
|
1074
|
+
* All transactions are gasless — the relayer covers fees via fee-bump.
|
|
1075
|
+
*
|
|
1076
|
+
* @example
|
|
1077
|
+
* ```typescript
|
|
1078
|
+
* import { SmoothSendSDK } from '@smoothsend/sdk';
|
|
1079
|
+
*
|
|
1080
|
+
* const sdk = new SmoothSendSDK({ apiKey: 'pk_nogas_xxx', network: 'testnet' });
|
|
1081
|
+
*
|
|
1082
|
+
* // Create a C-address for a G-address owner
|
|
1083
|
+
* const { cAddress } = await sdk.stellar.cAddress.create('GABCD...');
|
|
1084
|
+
*
|
|
1085
|
+
* // Get balances
|
|
1086
|
+
* const { balances } = await sdk.stellar.cAddress.getBalances(cAddress);
|
|
1087
|
+
*
|
|
1088
|
+
* // Build a bridge transfer (G→C), user signs, relayer fee-bumps
|
|
1089
|
+
* const { unsignedXDR } = await sdk.stellar.cAddress.buildBridgeTransfer({
|
|
1090
|
+
* from: 'GABCD...',
|
|
1091
|
+
* destination: cAddress,
|
|
1092
|
+
* asset: 'USDC',
|
|
1093
|
+
* amount: '10.5',
|
|
1094
|
+
* });
|
|
1095
|
+
* // Sign with wallet (e.g., Freighter)
|
|
1096
|
+
* const signedXDR = await wallet.signTransaction(unsignedXDR);
|
|
1097
|
+
* // Submit — relayer wraps in fee-bump
|
|
1098
|
+
* const { txHash } = await sdk.stellar.cAddress.submitTransfer(signedXDR);
|
|
1099
|
+
* ```
|
|
1100
|
+
*/
|
|
1101
|
+
class StellarCAddressAdapter {
|
|
1102
|
+
constructor(httpClient, network = 'testnet') {
|
|
1103
|
+
this.httpClient = httpClient;
|
|
1104
|
+
// Multi-chain compatible path: /api/v1/relayer/{chain}/c-address
|
|
1105
|
+
this.basePath = '/api/v1/relayer/stellar/c-address';
|
|
1106
|
+
}
|
|
1107
|
+
/**
|
|
1108
|
+
* Create a new C-address (Soroban Smart Account) for a G-address owner.
|
|
1109
|
+
* If the owner already has a C-address, returns the existing one.
|
|
1110
|
+
*
|
|
1111
|
+
* The relayer pays all deployment fees — completely gasless for the user.
|
|
1112
|
+
*
|
|
1113
|
+
* @param ownerGAddress - The G-address that will control this smart account
|
|
1114
|
+
* @returns The new C-address, tx hash, and whether it already existed
|
|
1115
|
+
*/
|
|
1116
|
+
async create(ownerGAddress) {
|
|
1117
|
+
this.validateGAddress(ownerGAddress);
|
|
1118
|
+
try {
|
|
1119
|
+
const response = await this.httpClient.post(`${this.basePath}/create`, { ownerGAddress }, { headers: { 'X-Chain': 'stellar' } });
|
|
1120
|
+
const data = response.data;
|
|
1121
|
+
if (!data.success) {
|
|
1122
|
+
throw new SmoothSendError(data.error || 'Failed to create C-address', 'C_ADDRESS_CREATE_FAILED', 500);
|
|
1123
|
+
}
|
|
1124
|
+
return {
|
|
1125
|
+
cAddress: data.cAddress,
|
|
1126
|
+
txHash: data.txHash,
|
|
1127
|
+
alreadyExisted: data.alreadyExisted,
|
|
1128
|
+
explorerUrl: data.explorerUrl,
|
|
1129
|
+
};
|
|
1130
|
+
}
|
|
1131
|
+
catch (error) {
|
|
1132
|
+
if (error instanceof SmoothSendError)
|
|
1133
|
+
throw error;
|
|
1134
|
+
throw new SmoothSendError(`Failed to create C-address: ${error instanceof Error ? error.message : String(error)}`, 'C_ADDRESS_CREATE_FAILED', 500);
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
/**
|
|
1138
|
+
* Look up the C-address for a given G-address owner.
|
|
1139
|
+
* Returns null if no C-address exists for this owner.
|
|
1140
|
+
*
|
|
1141
|
+
* @param ownerGAddress - The G-address to look up
|
|
1142
|
+
*/
|
|
1143
|
+
async lookup(ownerGAddress) {
|
|
1144
|
+
this.validateGAddress(ownerGAddress);
|
|
1145
|
+
try {
|
|
1146
|
+
const response = await this.httpClient.get(`${this.basePath}/lookup/${ownerGAddress}`, { headers: { 'X-Chain': 'stellar' } });
|
|
1147
|
+
const data = response.data;
|
|
1148
|
+
return {
|
|
1149
|
+
ownerGAddress: data.ownerGAddress,
|
|
1150
|
+
cAddress: data.cAddress || null,
|
|
1151
|
+
hasAccount: data.hasAccount,
|
|
1152
|
+
};
|
|
1153
|
+
}
|
|
1154
|
+
catch (error) {
|
|
1155
|
+
if (error instanceof SmoothSendError)
|
|
1156
|
+
throw error;
|
|
1157
|
+
throw new SmoothSendError(`Failed to lookup C-address: ${error instanceof Error ? error.message : String(error)}`, 'C_ADDRESS_LOOKUP_FAILED', 500);
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
/**
|
|
1161
|
+
* Get token balances for a C-address.
|
|
1162
|
+
* Returns balances for XLM, USDC, and EURC.
|
|
1163
|
+
*
|
|
1164
|
+
* @param cAddress - The C-address to query
|
|
1165
|
+
*/
|
|
1166
|
+
async getBalances(cAddress) {
|
|
1167
|
+
this.validateCAddress(cAddress);
|
|
1168
|
+
try {
|
|
1169
|
+
const response = await this.httpClient.get(`${this.basePath}/balance/${cAddress}`, { headers: { 'X-Chain': 'stellar' } });
|
|
1170
|
+
const data = response.data;
|
|
1171
|
+
return {
|
|
1172
|
+
cAddress: data.cAddress,
|
|
1173
|
+
balances: data.balances,
|
|
1174
|
+
};
|
|
1175
|
+
}
|
|
1176
|
+
catch (error) {
|
|
1177
|
+
if (error instanceof SmoothSendError)
|
|
1178
|
+
throw error;
|
|
1179
|
+
throw new SmoothSendError(`Failed to get balances: ${error instanceof Error ? error.message : String(error)}`, 'C_ADDRESS_BALANCE_FAILED', 500);
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
/**
|
|
1183
|
+
* Build a bridge transfer (G→C) using SAC.transfer.
|
|
1184
|
+
* Returns unsigned XDR for the user to sign with their wallet.
|
|
1185
|
+
* After signing, submit via submitTransfer().
|
|
1186
|
+
*
|
|
1187
|
+
* @param params.from - Sender G-address (signs the tx)
|
|
1188
|
+
* @param params.destination - Recipient C-address (or G-address)
|
|
1189
|
+
* @param params.asset - Asset to transfer: 'XLM', 'USDC', or 'EURC'
|
|
1190
|
+
* @param params.amount - Human-readable amount (e.g., '10.5')
|
|
1191
|
+
*/
|
|
1192
|
+
async buildBridgeTransfer(params) {
|
|
1193
|
+
this.validateGAddress(params.from);
|
|
1194
|
+
try {
|
|
1195
|
+
const response = await this.httpClient.post(`${this.basePath}/bridge-transfer`, params, { headers: { 'X-Chain': 'stellar' } });
|
|
1196
|
+
const data = response.data;
|
|
1197
|
+
if (!data.success) {
|
|
1198
|
+
throw new SmoothSendError(data.error || 'Bridge transfer failed', 'BRIDGE_TRANSFER_FAILED', 500);
|
|
1199
|
+
}
|
|
1200
|
+
return {
|
|
1201
|
+
unsignedXDR: data.unsignedXDR,
|
|
1202
|
+
networkPassphrase: data.networkPassphrase,
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
catch (error) {
|
|
1206
|
+
if (error instanceof SmoothSendError)
|
|
1207
|
+
throw error;
|
|
1208
|
+
throw new SmoothSendError(`Bridge transfer failed: ${error instanceof Error ? error.message : String(error)}`, 'BRIDGE_TRANSFER_FAILED', 500);
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
/**
|
|
1212
|
+
* Build a transfer from a C-address (SmartAccount.send).
|
|
1213
|
+
* Returns unsigned XDR for the owner to sign.
|
|
1214
|
+
* After signing, submit via submitTransfer().
|
|
1215
|
+
*
|
|
1216
|
+
* @param params.from - Owner G-address (signs auth)
|
|
1217
|
+
* @param params.cAddress - Source C-address (holds the funds)
|
|
1218
|
+
* @param params.destination - Recipient (G or C address)
|
|
1219
|
+
* @param params.asset - Asset: 'XLM', 'USDC', or 'EURC'
|
|
1220
|
+
* @param params.amount - Human-readable amount
|
|
1221
|
+
*/
|
|
1222
|
+
async buildTransfer(params) {
|
|
1223
|
+
this.validateGAddress(params.from);
|
|
1224
|
+
this.validateCAddress(params.cAddress);
|
|
1225
|
+
try {
|
|
1226
|
+
const response = await this.httpClient.post(`${this.basePath}/build-transfer`, params, { headers: { 'X-Chain': 'stellar' } });
|
|
1227
|
+
const data = response.data;
|
|
1228
|
+
if (!data.success) {
|
|
1229
|
+
throw new SmoothSendError(data.error || 'Build transfer failed', 'BUILD_TRANSFER_FAILED', 500);
|
|
1230
|
+
}
|
|
1231
|
+
return {
|
|
1232
|
+
unsignedXDR: data.unsignedXDR,
|
|
1233
|
+
networkPassphrase: data.networkPassphrase,
|
|
1234
|
+
};
|
|
1235
|
+
}
|
|
1236
|
+
catch (error) {
|
|
1237
|
+
if (error instanceof SmoothSendError)
|
|
1238
|
+
throw error;
|
|
1239
|
+
throw new SmoothSendError(`Build transfer failed: ${error instanceof Error ? error.message : String(error)}`, 'BUILD_TRANSFER_FAILED', 500);
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
/**
|
|
1243
|
+
* Submit a user-signed transaction.
|
|
1244
|
+
* The relayer wraps it in a fee-bump transaction and submits to the network.
|
|
1245
|
+
* The user pays zero fees — the relayer covers everything.
|
|
1246
|
+
*
|
|
1247
|
+
* @param signedXDR - The user-signed transaction XDR (base64)
|
|
1248
|
+
*/
|
|
1249
|
+
async submitTransfer(signedXDR) {
|
|
1250
|
+
if (!signedXDR) {
|
|
1251
|
+
throw new SmoothSendError('signedXDR is required', 'MISSING_SIGNED_XDR', 400);
|
|
1252
|
+
}
|
|
1253
|
+
try {
|
|
1254
|
+
const response = await this.httpClient.post(`${this.basePath}/submit-transfer`, { signedXDR }, { headers: { 'X-Chain': 'stellar' } });
|
|
1255
|
+
const data = response.data;
|
|
1256
|
+
if (!data.success) {
|
|
1257
|
+
throw new SmoothSendError(data.error || 'Submit failed', 'SUBMIT_TRANSFER_FAILED', 500);
|
|
1258
|
+
}
|
|
1259
|
+
return {
|
|
1260
|
+
txHash: data.txHash,
|
|
1261
|
+
explorerUrl: data.explorerUrl,
|
|
1262
|
+
};
|
|
1263
|
+
}
|
|
1264
|
+
catch (error) {
|
|
1265
|
+
if (error instanceof SmoothSendError)
|
|
1266
|
+
throw error;
|
|
1267
|
+
throw new SmoothSendError(`Submit transfer failed: ${error instanceof Error ? error.message : String(error)}`, 'SUBMIT_TRANSFER_FAILED', 500);
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
/**
|
|
1271
|
+
* Get transaction history for a C-address.
|
|
1272
|
+
* Returns recent transfer events (sent/received) across all supported tokens.
|
|
1273
|
+
*
|
|
1274
|
+
* @param cAddress - The C-address to query
|
|
1275
|
+
* @param limit - Maximum number of transactions to return (default: 20)
|
|
1276
|
+
*/
|
|
1277
|
+
async getHistory(cAddress, limit = 20) {
|
|
1278
|
+
this.validateCAddress(cAddress);
|
|
1279
|
+
try {
|
|
1280
|
+
const response = await this.httpClient.get(`${this.basePath}/history/${cAddress}?limit=${limit}`, { headers: { 'X-Chain': 'stellar' } });
|
|
1281
|
+
const data = response.data;
|
|
1282
|
+
return {
|
|
1283
|
+
cAddress: data.cAddress,
|
|
1284
|
+
transactions: data.transactions || [],
|
|
1285
|
+
count: data.count || 0,
|
|
1286
|
+
};
|
|
1287
|
+
}
|
|
1288
|
+
catch (error) {
|
|
1289
|
+
if (error instanceof SmoothSendError)
|
|
1290
|
+
throw error;
|
|
1291
|
+
throw new SmoothSendError(`Failed to get history: ${error instanceof Error ? error.message : String(error)}`, 'C_ADDRESS_HISTORY_FAILED', 500);
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
/**
|
|
1295
|
+
* Health check for the C-address bridge service.
|
|
1296
|
+
*/
|
|
1297
|
+
async health() {
|
|
1298
|
+
try {
|
|
1299
|
+
const response = await this.httpClient.get(`${this.basePath}/health`, { headers: { 'X-Chain': 'stellar' } });
|
|
1300
|
+
const data = response.data;
|
|
1301
|
+
return {
|
|
1302
|
+
service: data.service,
|
|
1303
|
+
relayerPublicKey: data.relayerPublicKey,
|
|
1304
|
+
factoryContractId: data.factoryContractId,
|
|
1305
|
+
isReady: data.isReady,
|
|
1306
|
+
network: data.network,
|
|
1307
|
+
};
|
|
1308
|
+
}
|
|
1309
|
+
catch (error) {
|
|
1310
|
+
if (error instanceof SmoothSendError)
|
|
1311
|
+
throw error;
|
|
1312
|
+
throw new SmoothSendError(`C-Address health check failed: ${error instanceof Error ? error.message : String(error)}`, 'C_ADDRESS_HEALTH_FAILED', 500);
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
// ─────────────────────────────────────────────────────────
|
|
1316
|
+
// Validation helpers
|
|
1317
|
+
// ─────────────────────────────────────────────────────────
|
|
1318
|
+
validateGAddress(address) {
|
|
1319
|
+
if (!address || !address.startsWith('G') || address.length !== 56) {
|
|
1320
|
+
throw new SmoothSendError('Invalid G-address. Must start with G and be 56 characters.', 'INVALID_G_ADDRESS', 400);
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
validateCAddress(address) {
|
|
1324
|
+
if (!address || !address.startsWith('C') || address.length !== 56) {
|
|
1325
|
+
throw new SmoothSendError('Invalid C-address. Must start with C and be 56 characters.', 'INVALID_C_ADDRESS', 400);
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
validateAddress(address) {
|
|
1329
|
+
return (typeof address === 'string' &&
|
|
1330
|
+
address.length === 56 &&
|
|
1331
|
+
(address.startsWith('G') || address.startsWith('C')));
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
/** Headers to route requests to Stellar relayer via proxy */
|
|
1336
|
+
const STELLAR_HEADERS = { 'X-Chain': 'stellar' };
|
|
1337
|
+
/**
|
|
1338
|
+
* Stellar Adapter - Gasless transactions via Fee Bump
|
|
1339
|
+
* Routes through proxy.smoothsend.xyz with API key authentication
|
|
1340
|
+
* Supports XLM, USDC, EURC and other Stellar assets
|
|
1341
|
+
*/
|
|
1342
|
+
class StellarAdapter {
|
|
1343
|
+
constructor(chain, config, apiKey, network = 'testnet', includeOrigin = false) {
|
|
1344
|
+
if (CHAIN_ECOSYSTEM_MAP[chain] !== 'stellar') {
|
|
1345
|
+
throw new SmoothSendError(`StellarAdapter can only handle Stellar chains, got: ${chain}`, 'INVALID_CHAIN_FOR_ADAPTER', 400, { chain });
|
|
1346
|
+
}
|
|
1347
|
+
this.chain = chain;
|
|
1348
|
+
this.config = config;
|
|
1349
|
+
this.network = network;
|
|
1350
|
+
this.httpClient = new HttpClient({
|
|
1351
|
+
apiKey,
|
|
1352
|
+
network,
|
|
1353
|
+
timeout: 30000,
|
|
1354
|
+
retries: 3,
|
|
1355
|
+
includeOrigin,
|
|
1356
|
+
});
|
|
1357
|
+
// Initialize C-Address adapter (Soroban Smart Account)
|
|
1358
|
+
this.cAddress = new StellarCAddressAdapter(this.httpClient, network);
|
|
1359
|
+
}
|
|
1360
|
+
setNetwork(network) {
|
|
1361
|
+
this.network = network;
|
|
1362
|
+
this.httpClient.setNetwork(network);
|
|
1363
|
+
}
|
|
1364
|
+
getNetwork() {
|
|
1365
|
+
return this.network;
|
|
1366
|
+
}
|
|
1367
|
+
/**
|
|
1368
|
+
* Stellar gasless: relayer pays fee. Returns 0 for user.
|
|
1369
|
+
*/
|
|
1370
|
+
async estimateFee(_request) {
|
|
1371
|
+
return {
|
|
1372
|
+
relayerFee: '0',
|
|
1373
|
+
feeInUSD: '0',
|
|
1374
|
+
coinType: _request.token || 'XLM',
|
|
1375
|
+
estimatedGas: '0',
|
|
1376
|
+
network: this.network,
|
|
1377
|
+
};
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* Submit signed XDR to relayer for Fee Bump wrapping
|
|
1381
|
+
*/
|
|
1382
|
+
async executeGaslessTransfer(signedData) {
|
|
1383
|
+
if (!signedData.signedTransaction) {
|
|
1384
|
+
throw new SmoothSendError('signedTransaction (XDR) is required for Stellar gasless transfers', STELLAR_ERROR_CODES.MISSING_SIGNED_TRANSACTION, 400, { chain: this.chain });
|
|
1385
|
+
}
|
|
1386
|
+
try {
|
|
1387
|
+
const response = await this.httpClient.post('/api/v1/relayer/gasless-transaction', { signedTransaction: signedData.signedTransaction }, { headers: STELLAR_HEADERS });
|
|
1388
|
+
const data = response.data;
|
|
1389
|
+
const result = {
|
|
1390
|
+
success: data.success ?? true,
|
|
1391
|
+
txHash: data.hash ?? data.txnHash,
|
|
1392
|
+
transferId: data.hash ?? data.txnHash,
|
|
1393
|
+
explorerUrl: data.explorerUrl,
|
|
1394
|
+
gasFeePaidBy: 'relayer',
|
|
1395
|
+
gasUsed: data.feeStroops,
|
|
1396
|
+
};
|
|
1397
|
+
if (response.metadata) {
|
|
1398
|
+
result.metadata = response.metadata;
|
|
1399
|
+
}
|
|
1400
|
+
return result;
|
|
1401
|
+
}
|
|
1402
|
+
catch (error) {
|
|
1403
|
+
if (error instanceof SmoothSendError)
|
|
1404
|
+
throw error;
|
|
1405
|
+
throw new SmoothSendError(`Stellar gasless transfer failed: ${error instanceof Error ? error.message : String(error)}`, STELLAR_ERROR_CODES.GASLESS_TRANSACTION_ERROR, 500, { chain: this.chain });
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
async getTransactionStatus(txHash) {
|
|
1409
|
+
try {
|
|
1410
|
+
const response = await this.httpClient.get(`/api/v1/relayer/stellar/status/${txHash}`, { headers: STELLAR_HEADERS });
|
|
1411
|
+
return response.data;
|
|
1412
|
+
}
|
|
1413
|
+
catch (error) {
|
|
1414
|
+
if (error instanceof SmoothSendError)
|
|
1415
|
+
throw error;
|
|
1416
|
+
throw new SmoothSendError(`Failed to get Stellar transaction status: ${error instanceof Error ? error.message : String(error)}`, STELLAR_ERROR_CODES.STATUS_ERROR, 500, { chain: this.chain });
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
async getHealth() {
|
|
1420
|
+
try {
|
|
1421
|
+
const response = await this.httpClient.get('/api/v1/relayer/stellar/health', {
|
|
1422
|
+
headers: STELLAR_HEADERS,
|
|
1423
|
+
});
|
|
1424
|
+
return {
|
|
1425
|
+
success: true,
|
|
1426
|
+
status: response.data.status ?? 'healthy',
|
|
1427
|
+
timestamp: response.data.timestamp ?? new Date().toISOString(),
|
|
1428
|
+
version: '2.0',
|
|
1429
|
+
};
|
|
1430
|
+
}
|
|
1431
|
+
catch (error) {
|
|
1432
|
+
if (error instanceof SmoothSendError)
|
|
1433
|
+
throw error;
|
|
1434
|
+
throw new SmoothSendError(`Stellar health check failed: ${error instanceof Error ? error.message : String(error)}`, STELLAR_ERROR_CODES.HEALTH_ERROR, 500, { chain: this.chain });
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
validateAddress(address) {
|
|
1438
|
+
// Support both G-addresses (classic) and C-addresses (Soroban smart accounts)
|
|
1439
|
+
return /^[GC][A-Z2-7]{55}$/.test(address);
|
|
1440
|
+
}
|
|
1441
|
+
validateAmount(amount) {
|
|
1442
|
+
try {
|
|
1443
|
+
const n = parseFloat(amount);
|
|
1444
|
+
return !isNaN(n) && n > 0;
|
|
1445
|
+
}
|
|
1446
|
+
catch {
|
|
1447
|
+
return false;
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1038
1452
|
class SmoothSendSDK {
|
|
1039
1453
|
constructor(config) {
|
|
1040
1454
|
this.adapters = new Map();
|
|
@@ -1134,8 +1548,20 @@ class SmoothSendSDK {
|
|
|
1134
1548
|
};
|
|
1135
1549
|
adapter = new AptosAdapter(chain, minimalConfig, this.config.apiKey, this.config.network || 'testnet', this.shouldIncludeOrigin());
|
|
1136
1550
|
}
|
|
1551
|
+
else if (ecosystem === 'stellar') {
|
|
1552
|
+
const minimalConfig = {
|
|
1553
|
+
name: chain,
|
|
1554
|
+
displayName: chain,
|
|
1555
|
+
chainId: 0,
|
|
1556
|
+
rpcUrl: '',
|
|
1557
|
+
relayerUrl: 'https://proxy.smoothsend.xyz',
|
|
1558
|
+
explorerUrl: '',
|
|
1559
|
+
tokens: [],
|
|
1560
|
+
nativeCurrency: { name: 'XLM', symbol: 'XLM', decimals: 7 },
|
|
1561
|
+
};
|
|
1562
|
+
adapter = new StellarAdapter(chain, minimalConfig, this.config.apiKey, this.config.network || 'testnet', this.shouldIncludeOrigin());
|
|
1563
|
+
}
|
|
1137
1564
|
else if (ecosystem === 'evm') {
|
|
1138
|
-
// EVM adapter will be implemented in future phase
|
|
1139
1565
|
throw new SmoothSendError(`EVM chains not yet supported in v2. Chain: ${chain}`, 'UNSUPPORTED_CHAIN');
|
|
1140
1566
|
}
|
|
1141
1567
|
else {
|
|
@@ -1190,6 +1616,22 @@ class SmoothSendSDK {
|
|
|
1190
1616
|
throw error;
|
|
1191
1617
|
}
|
|
1192
1618
|
}
|
|
1619
|
+
/**
|
|
1620
|
+
* Submit a signed Stellar transaction (XDR) for gasless relay.
|
|
1621
|
+
* Use when you've already built and signed the transaction.
|
|
1622
|
+
*
|
|
1623
|
+
* @example
|
|
1624
|
+
* const signedXdr = await stellarWallet.signTransaction(tx);
|
|
1625
|
+
* const result = await sdk.submitStellarTransaction(signedXdr);
|
|
1626
|
+
*/
|
|
1627
|
+
async submitStellarTransaction(signedXdr) {
|
|
1628
|
+
const chain = this.config.network === 'mainnet' ? 'stellar-mainnet' : 'stellar-testnet';
|
|
1629
|
+
return this.executeGaslessTransfer({
|
|
1630
|
+
signedTransaction: signedXdr,
|
|
1631
|
+
chain,
|
|
1632
|
+
network: this.config.network,
|
|
1633
|
+
});
|
|
1634
|
+
}
|
|
1193
1635
|
async executeGaslessTransfer(signedData) {
|
|
1194
1636
|
const adapter = this.getOrCreateAdapter(signedData.chain);
|
|
1195
1637
|
this.emitEvent({
|
|
@@ -1220,68 +1662,84 @@ class SmoothSendSDK {
|
|
|
1220
1662
|
}
|
|
1221
1663
|
/**
|
|
1222
1664
|
* Convenience method for complete transfer flow
|
|
1223
|
-
*
|
|
1665
|
+
* Works for both Aptos and Stellar - same 3-line API.
|
|
1224
1666
|
*
|
|
1225
1667
|
* @param request Transfer request with from, to, token, amount, chain
|
|
1226
|
-
* @param wallet
|
|
1668
|
+
* @param wallet Aptos or Stellar wallet provider
|
|
1227
1669
|
* @returns Transfer result with transaction hash and usage metadata
|
|
1228
1670
|
*
|
|
1229
|
-
*
|
|
1230
|
-
*
|
|
1231
|
-
* - signTransaction(transaction): Sign and serialize transaction
|
|
1232
|
-
*
|
|
1233
|
-
* The wallet's signTransaction should return an object with:
|
|
1234
|
-
* - transactionBytes: number[] - Serialized transaction
|
|
1235
|
-
* - authenticatorBytes: number[] - Serialized authenticator
|
|
1671
|
+
* Aptos wallet: signTransaction returns { transactionBytes, authenticatorBytes }
|
|
1672
|
+
* Stellar wallet: signTransaction returns string (signed XDR)
|
|
1236
1673
|
*/
|
|
1237
1674
|
async transfer(request, wallet) {
|
|
1238
1675
|
this.emitEvent({
|
|
1239
1676
|
type: 'transfer_initiated',
|
|
1240
1677
|
data: { request },
|
|
1241
1678
|
timestamp: Date.now(),
|
|
1242
|
-
chain: request.chain
|
|
1679
|
+
chain: request.chain,
|
|
1243
1680
|
});
|
|
1244
1681
|
try {
|
|
1245
|
-
|
|
1682
|
+
const ecosystem = CHAIN_ECOSYSTEM_MAP[request.chain];
|
|
1683
|
+
if (ecosystem === 'stellar') {
|
|
1684
|
+
return this.transferStellar(request, wallet);
|
|
1685
|
+
}
|
|
1686
|
+
// Aptos flow
|
|
1687
|
+
const aptosWallet = wallet;
|
|
1246
1688
|
const feeEstimate = await this.estimateFee(request);
|
|
1247
|
-
|
|
1248
|
-
const transaction = await wallet.buildTransaction({
|
|
1689
|
+
const transaction = await aptosWallet.buildTransaction({
|
|
1249
1690
|
sender: request.from,
|
|
1250
1691
|
recipient: request.to,
|
|
1251
1692
|
amount: request.amount,
|
|
1252
1693
|
coinType: feeEstimate.coinType,
|
|
1253
|
-
relayerFee: feeEstimate.relayerFee
|
|
1694
|
+
relayerFee: feeEstimate.relayerFee,
|
|
1254
1695
|
});
|
|
1255
1696
|
this.emitEvent({
|
|
1256
1697
|
type: 'transfer_signed',
|
|
1257
1698
|
data: { transaction },
|
|
1258
1699
|
timestamp: Date.now(),
|
|
1259
|
-
chain: request.chain
|
|
1700
|
+
chain: request.chain,
|
|
1260
1701
|
});
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
// Step 4: Execute gasless transfer
|
|
1264
|
-
const result = await this.executeGaslessTransfer({
|
|
1702
|
+
const signedTx = await aptosWallet.signTransaction(transaction);
|
|
1703
|
+
return this.executeGaslessTransfer({
|
|
1265
1704
|
transactionBytes: signedTx.transactionBytes,
|
|
1266
1705
|
authenticatorBytes: signedTx.authenticatorBytes,
|
|
1267
1706
|
chain: request.chain,
|
|
1268
|
-
network: this.config.network
|
|
1707
|
+
network: this.config.network,
|
|
1269
1708
|
});
|
|
1270
|
-
return result;
|
|
1271
1709
|
}
|
|
1272
1710
|
catch (error) {
|
|
1273
1711
|
this.emitEvent({
|
|
1274
1712
|
type: 'transfer_failed',
|
|
1275
1713
|
data: {
|
|
1276
1714
|
error: error instanceof Error ? error.message : String(error),
|
|
1277
|
-
step: 'transfer'
|
|
1715
|
+
step: 'transfer',
|
|
1278
1716
|
},
|
|
1279
1717
|
timestamp: Date.now(),
|
|
1280
|
-
chain: request.chain
|
|
1718
|
+
chain: request.chain,
|
|
1281
1719
|
});
|
|
1282
1720
|
throw error;
|
|
1283
1721
|
}
|
|
1284
1722
|
}
|
|
1723
|
+
async transferStellar(request, wallet) {
|
|
1724
|
+
const transaction = await wallet.buildTransaction({
|
|
1725
|
+
from: request.from,
|
|
1726
|
+
to: request.to,
|
|
1727
|
+
amount: request.amount,
|
|
1728
|
+
token: request.token,
|
|
1729
|
+
});
|
|
1730
|
+
this.emitEvent({
|
|
1731
|
+
type: 'transfer_signed',
|
|
1732
|
+
data: { transaction },
|
|
1733
|
+
timestamp: Date.now(),
|
|
1734
|
+
chain: request.chain,
|
|
1735
|
+
});
|
|
1736
|
+
const signedXdr = await wallet.signTransaction(transaction);
|
|
1737
|
+
return this.executeGaslessTransfer({
|
|
1738
|
+
signedTransaction: signedXdr,
|
|
1739
|
+
chain: request.chain,
|
|
1740
|
+
network: this.config.network,
|
|
1741
|
+
});
|
|
1742
|
+
}
|
|
1285
1743
|
// Note: Batch transfer support will be implemented in a future phase
|
|
1286
1744
|
// Utility methods
|
|
1287
1745
|
/**
|
|
@@ -1385,8 +1843,7 @@ class SmoothSendSDK {
|
|
|
1385
1843
|
* ```
|
|
1386
1844
|
*/
|
|
1387
1845
|
getSupportedChains() {
|
|
1388
|
-
|
|
1389
|
-
return ['aptos-testnet', 'aptos-mainnet'];
|
|
1846
|
+
return ['aptos-testnet', 'aptos-mainnet', 'stellar-testnet', 'stellar-mainnet'];
|
|
1390
1847
|
}
|
|
1391
1848
|
/**
|
|
1392
1849
|
* Get list of supported chains from proxy worker (dynamic)
|
|
@@ -1602,7 +2059,7 @@ class SmoothSendSDK {
|
|
|
1602
2059
|
* ```
|
|
1603
2060
|
*/
|
|
1604
2061
|
static getSupportedChains() {
|
|
1605
|
-
return ['aptos-testnet', 'aptos-mainnet'];
|
|
2062
|
+
return ['aptos-testnet', 'aptos-mainnet', 'stellar-testnet', 'stellar-mainnet'];
|
|
1606
2063
|
}
|
|
1607
2064
|
}
|
|
1608
2065
|
|
|
@@ -1662,6 +2119,7 @@ class SmoothSendTransactionSubmitter {
|
|
|
1662
2119
|
this.network = config.network || 'testnet';
|
|
1663
2120
|
this.gatewayUrl = config.gatewayUrl || 'https://proxy.smoothsend.xyz';
|
|
1664
2121
|
this.timeout = config.timeout || 30000;
|
|
2122
|
+
this.getCaptchaToken = config.getCaptchaToken;
|
|
1665
2123
|
this.debug = config.debug || false;
|
|
1666
2124
|
}
|
|
1667
2125
|
/**
|
|
@@ -1734,6 +2192,20 @@ class SmoothSendTransactionSubmitter {
|
|
|
1734
2192
|
if (this.apiKey.startsWith('pk_nogas_') && typeof window !== 'undefined') {
|
|
1735
2193
|
headers['Origin'] = window.location.origin;
|
|
1736
2194
|
}
|
|
2195
|
+
// Add captcha token if the project requires it
|
|
2196
|
+
if (this.getCaptchaToken) {
|
|
2197
|
+
try {
|
|
2198
|
+
const token = await this.getCaptchaToken();
|
|
2199
|
+
if (token) {
|
|
2200
|
+
headers['X-Captcha-Token'] = token;
|
|
2201
|
+
}
|
|
2202
|
+
}
|
|
2203
|
+
catch (e) {
|
|
2204
|
+
if (this.debug) {
|
|
2205
|
+
console.warn('[SmoothSend] Failed to get captcha token:', e);
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
1737
2209
|
const controller = new AbortController();
|
|
1738
2210
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
1739
2211
|
try {
|
|
@@ -2049,24 +2521,17 @@ function createScriptComposerClient(config) {
|
|
|
2049
2521
|
* @packageDocumentation
|
|
2050
2522
|
*
|
|
2051
2523
|
* @example
|
|
2052
|
-
*
|
|
2524
|
+
* Aptos:
|
|
2053
2525
|
* ```typescript
|
|
2054
|
-
*
|
|
2055
|
-
*
|
|
2056
|
-
*
|
|
2057
|
-
* apiKey: 'no_gas_abc123...',
|
|
2058
|
-
* network: 'testnet'
|
|
2059
|
-
* });
|
|
2060
|
-
*
|
|
2061
|
-
* const result = await sdk.transfer({
|
|
2062
|
-
* from: '0x123...',
|
|
2063
|
-
* to: '0x456...',
|
|
2064
|
-
* token: 'USDC',
|
|
2065
|
-
* amount: '1000000',
|
|
2066
|
-
* chain: 'aptos-testnet'
|
|
2067
|
-
* }, wallet);
|
|
2526
|
+
* const sdk = new SmoothSendSDK({ apiKey: 'pk_nogas_xxx', network: 'testnet' });
|
|
2527
|
+
* const result = await sdk.transfer({ from, to, token: 'USDC', amount: '1000000', chain: 'aptos-testnet' }, aptosWallet);
|
|
2528
|
+
* ```
|
|
2068
2529
|
*
|
|
2069
|
-
*
|
|
2530
|
+
* @example
|
|
2531
|
+
* Stellar (same API):
|
|
2532
|
+
* ```typescript
|
|
2533
|
+
* const sdk = new SmoothSendSDK({ apiKey: 'pk_nogas_xxx', network: 'testnet' });
|
|
2534
|
+
* const result = await sdk.transfer({ from, to, token: 'XLM', amount: '100', chain: 'stellar-testnet' }, stellarWallet);
|
|
2070
2535
|
* ```
|
|
2071
2536
|
*/
|
|
2072
2537
|
// Main SDK export
|
|
@@ -2074,7 +2539,7 @@ function createScriptComposerClient(config) {
|
|
|
2074
2539
|
* SDK version
|
|
2075
2540
|
* @public
|
|
2076
2541
|
*/
|
|
2077
|
-
const VERSION = '2.
|
|
2542
|
+
const VERSION = '2.0.0'; // Multi-chain: Aptos + Stellar + C-Address
|
|
2078
2543
|
|
|
2079
2544
|
exports.APTOS_ERROR_CODES = APTOS_ERROR_CODES;
|
|
2080
2545
|
exports.AptosAdapter = AptosAdapter;
|
|
@@ -2083,10 +2548,13 @@ exports.CHAIN_ECOSYSTEM_MAP = CHAIN_ECOSYSTEM_MAP;
|
|
|
2083
2548
|
exports.HttpClient = HttpClient;
|
|
2084
2549
|
exports.NetworkError = NetworkError;
|
|
2085
2550
|
exports.RateLimitError = RateLimitError;
|
|
2551
|
+
exports.STELLAR_ERROR_CODES = STELLAR_ERROR_CODES;
|
|
2086
2552
|
exports.ScriptComposerClient = ScriptComposerClient;
|
|
2087
2553
|
exports.SmoothSendError = SmoothSendError;
|
|
2088
2554
|
exports.SmoothSendSDK = SmoothSendSDK;
|
|
2089
2555
|
exports.SmoothSendTransactionSubmitter = SmoothSendTransactionSubmitter;
|
|
2556
|
+
exports.StellarAdapter = StellarAdapter;
|
|
2557
|
+
exports.StellarCAddressAdapter = StellarCAddressAdapter;
|
|
2090
2558
|
exports.VERSION = VERSION;
|
|
2091
2559
|
exports.ValidationError = ValidationError;
|
|
2092
2560
|
exports.createErrorFromResponse = createErrorFromResponse;
|