-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add trustline creation to the borrow flow.
- Loading branch information
Showing
6 changed files
with
70 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Asset, Horizon, Networks, Operation, type Transaction, TransactionBuilder } from '@stellar/stellar-sdk'; | ||
import type { XDR_BASE64 } from '@stellar/stellar-sdk/contract'; | ||
import type { Currency } from 'currencies'; | ||
|
||
const HorizonServer = new Horizon.Server('https://horizon-testnet.stellar.org/'); | ||
|
||
export const getBalances = async (account: string): Promise<Horizon.HorizonApi.BalanceLine[]> => { | ||
const { balances } = await HorizonServer.loadAccount(account); | ||
return balances; | ||
}; | ||
|
||
export const createAddTrustlineTransaction = async ( | ||
account: string, | ||
{ ticker, issuer }: Currency, | ||
): Promise<Transaction> => { | ||
const asset = new Asset(ticker, issuer); | ||
|
||
const sourceAccount = await HorizonServer.loadAccount(account); | ||
|
||
const transaction = new TransactionBuilder(sourceAccount, { | ||
networkPassphrase: Networks.TESTNET, | ||
fee: '100000', | ||
}) | ||
.addOperation(Operation.changeTrust({ asset })) | ||
.setTimeout(300) // 5 minutes timeout | ||
.build(); | ||
|
||
return transaction; | ||
}; | ||
|
||
export const sendTransaction = async (txXdr: XDR_BASE64): Promise<Horizon.HorizonApi.SubmitTransactionResponse> => { | ||
const tx = TransactionBuilder.fromXDR(txXdr, Networks.TESTNET); | ||
return HorizonServer.submitTransaction(tx); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters