diff --git a/packages/examples/src/drawdownAndPayback.ts b/packages/examples/src/drawdownAndPayback.ts index 45bf609..ba1b650 100644 --- a/packages/examples/src/drawdownAndPayback.ts +++ b/packages/examples/src/drawdownAndPayback.ts @@ -15,8 +15,8 @@ import { const main = async () => { const borrower = new StellarWallet(process.env.TEST_PRIVATE_KEY as string); - const poolName = POOL_NAME.Arf; - const network = StellarNetwork.humanet; + const poolName = POOL_NAME.Roam; + const network = StellarNetwork.testnet; const availableBalanceForPool = await getAvailableBalanceForPool( poolName, @@ -54,7 +54,10 @@ const main = async () => { network, borrower ); - console.log("approveAllowance:", approveAllowance); + console.log( + "approveAllowance:", + approveAllowance.sendTransactionResponse?.hash + ); const drawdownResult = await drawdown( poolName, @@ -73,7 +76,9 @@ const main = async () => { 100_0000000 as any, false ); - console.log(`Payment success. Tx hash: ${paymentResult}`); + console.log( + `Payment success. Tx hash: ${paymentResult.sendTransactionResponse?.hash}` + ); }; main(); diff --git a/packages/sdk/API.md b/packages/sdk/API.md index da4b330..9862f15 100644 --- a/packages/sdk/API.md +++ b/packages/sdk/API.md @@ -18,8 +18,8 @@ associated with the given pool name on the current chain.
Draws down from a pool.
Promise.<SentTransaction>
Makes a payment.
Promise.<(SentTransaction.<null>|null)>
Approves an Sep41 allowance for a spender address, if the current allowance is insufficient. +
Approves an Sep41 allowance for a spender address. Allowance is required to do certain actions on the Huma protocol (e.g. makePayment for Autopay)
bigint
| The amount to payback.
| | principalOnly |boolean
| Whether this payment should ONLY apply to the principal
| - + -## approveSep41AllowanceIfInsufficient(poolName, network, wallet, spenderAddress, allowanceAmount) ⇒Promise.<(SentTransaction.<null>\|null)>
-Approves an Sep41 allowance for a spender address, if the current allowance is insufficient. +## approveSep41Allowance(poolName, network, wallet, spenderAddress) +
Approves an Sep41 allowance for a spender address. Allowance is required to do certain actions on the Huma protocol (e.g. makePayment for Autopay)
**Kind**: global function -**Returns**:Promise.<(SentTransaction.<null>\|null)>
- StellarNetwork
| The stellar network.
| | wallet |StellarWallet
| The wallet used to send the transaction.
| | spenderAddress |string
| The address of the spender to approve an allowance for.
| -| allowanceAmount |bigint
| The amount of tokens to approve, if applicable. Denominated in the Sep41 tokens.
| diff --git a/packages/sdk/src/helpers/CreditContractHelper.ts b/packages/sdk/src/helpers/CreditContractHelper.ts index 3b4e56c..a7ca36b 100644 --- a/packages/sdk/src/helpers/CreditContractHelper.ts +++ b/packages/sdk/src/helpers/CreditContractHelper.ts @@ -9,7 +9,7 @@ import { StellarNetwork, TransactionContext, } from '../utils' -import { approveSep41AllowanceIfInsufficient } from './Sep41ContractHelper' +import { approveSep41Allowance } from './Sep41ContractHelper' /** * Returns the current pool balance available for borrowing @@ -223,13 +223,7 @@ export async function approveAllowanceForSentinel( method: 'get_sentinel', }) - const tx = await approveSep41AllowanceIfInsufficient( - poolName, - network, - wallet, - sentinel, - totalDue, - ) + const tx = await approveSep41Allowance(poolName, network, wallet, sentinel) return tx } @@ -311,13 +305,7 @@ export async function makePayment( method: 'get_sentinel', }) - await approveSep41AllowanceIfInsufficient( - poolName, - network, - wallet, - sentinel, - paymentAmount, - ) + await approveSep41Allowance(poolName, network, wallet, sentinel) const poolCreditContext = new TransactionContext( poolName, @@ -344,7 +332,7 @@ export async function makePayment( value: wallet.userInfo.publicKey, }) } - const result: { result: readonly [bigint, boolean] } = await sendTransaction({ + const result = await sendTransaction({ context: poolCreditContext, method: principalOnly ? 'make_principal_payment' : 'make_payment', params: params, diff --git a/packages/sdk/src/helpers/Sep41ContractHelper.ts b/packages/sdk/src/helpers/Sep41ContractHelper.ts index 510a8f3..f8047ee 100644 --- a/packages/sdk/src/helpers/Sep41ContractHelper.ts +++ b/packages/sdk/src/helpers/Sep41ContractHelper.ts @@ -9,7 +9,7 @@ import { } from '../utils' /** - * Approves an Sep41 allowance for a spender address, if the current allowance is insufficient. + * Approves an Sep41 allowance for a spender address. * Allowance is required to do certain actions on the Huma protocol (e.g. makePayment for Autopay) * * @async @@ -18,15 +18,12 @@ import { * @param {StellarNetwork} network - The stellar network. * @param {StellarWallet} wallet - The wallet used to send the transaction. * @param {string} spenderAddress - The address of the spender to approve an allowance for. - * @param {bigint} allowanceAmount - The amount of tokens to approve, if applicable. Denominated in the Sep41 tokens. - * @returns {Promise