Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 27 additions & 18 deletions api/src/services/stellar.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,41 @@ export class StellarService {
}
}

async buildUnsignedTransaction(
private async buildTransaction(
operation: LendingOperation,
userAddress: string,
assetAddress: string | undefined,
amount: string
): Promise<string> {
try {
const account = await this.getAccount(userAddress);
const contract = new Contract(this.contractId);
const account = await this.getAccount(userAddress);
const contract = new Contract(this.contractId);

const params = [
new Address(userAddress).toScVal(),
assetAddress ? new Address(assetAddress).toScVal() : xdr.ScVal.scvVoid(),
nativeToScVal(BigInt(amount), { type: 'i128' }),
];

const params = [
new Address(userAddress).toScVal(),
assetAddress ? new Address(assetAddress).toScVal() : xdr.ScVal.scvVoid(),
nativeToScVal(BigInt(amount), { type: 'i128' }),
];
const tx = new TransactionBuilder(account, {
fee: BASE_FEE,
networkPassphrase: this.networkPassphrase,
})
.addOperation(contract.call(CONTRACT_METHODS[operation], ...params))
.setTimeout(TX_TIMEOUT_SECONDS)
.build();

const tx = new TransactionBuilder(account, {
fee: BASE_FEE,
networkPassphrase: this.networkPassphrase,
})
.addOperation(contract.call(CONTRACT_METHODS[operation], ...params))
.setTimeout(TX_TIMEOUT_SECONDS)
.build();
const preparedTx = await this.sorobanServer.prepareTransaction(tx);
return preparedTx.toXDR();
}

const preparedTx = await this.sorobanServer.prepareTransaction(tx);
return preparedTx.toXDR();
async buildUnsignedTransaction(
operation: LendingOperation,
userAddress: string,
assetAddress: string | undefined,
amount: string
): Promise<string> {
try {
return await this.buildTransaction(operation, userAddress, assetAddress, amount);
} catch (error) {
logger.error(`Failed to build unsigned ${operation} transaction:`, error);
throw new InternalServerError(`Failed to build ${operation} transaction`);
Expand Down
Loading