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