Skip to content

Commit

Permalink
fix(lending-add-liq): Sort the assets according to fAssetIds
Browse files Browse the repository at this point in the history
  • Loading branch information
gulcinuras committed Jan 10, 2024
1 parent 18d8e5d commit 8fe9c5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

32 changes: 15 additions & 17 deletions src/folks-lending-pools/add-liquidity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,32 @@ export async function generateTxns({
}): Promise<SignerTransaction[]> {
const wrapperAppAddress = algosdk.getApplicationAddress(FOLKS_WRAPPER_APP_ID[network]);
const suggestedParams = await client.getTransactionParams().do();
const isAlgoPool = isAlgo(asset2In.id);

// Make sure to sort the assets according to the fAssetIds
const [asset1, asset2] = [asset1In, asset2In].sort((a, b) => b.fAssetId - a.fAssetId);

const isAlgoPool = isAlgo(asset2.id);

const asset1InTxn = algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({
from: initiatorAddr,
to: wrapperAppAddress,
assetIndex: asset1In.id,
amount: asset1In.amount,
assetIndex: asset1.id,
amount: asset1.amount,
suggestedParams
});

const asset2InTxn = isAlgoPool
? algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: initiatorAddr,
to: wrapperAppAddress,
amount: asset2In.amount,
amount: asset2.amount,
suggestedParams
})
: algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({
from: initiatorAddr,
to: wrapperAppAddress,
assetIndex: asset2In.id,
amount: asset2In.amount,
assetIndex: asset2.id,
amount: asset2.amount,
suggestedParams
});

Expand All @@ -70,11 +74,11 @@ export async function generateTxns({
appArgs: [
encodeString("add_liquidity"),
decodeAddress(poolAddress).publicKey,
encodeUint64(asset1In.lendingAppId),
encodeUint64(asset2In.lendingAppId)
encodeUint64(asset1.lendingAppId),
encodeUint64(asset2.lendingAppId)
],
foreignAssets: [asset1In.id, asset2In.id, asset1In.fAssetId, asset2In.fAssetId],
foreignApps: [asset1In.lendingAppId, asset2In.lendingAppId, lendingManagerId],
foreignAssets: [asset1.id, asset2.id, asset1.fAssetId, asset2.fAssetId],
foreignApps: [asset1.lendingAppId, asset2.lendingAppId, lendingManagerId],
accounts: [poolAddress],
suggestedParams
});
Expand All @@ -98,13 +102,7 @@ export async function generateTxns({
const optInRequiredAssetIds = await getFolksWrapperAppOptInRequiredAssetIDs({
client,
network,
assetIDs: [
asset1In.id,
asset2In.id,
asset1In.fAssetId,
asset2In.fAssetId,
poolTokenId
]
assetIDs: [asset1.id, asset2.id, asset1.fAssetId, asset2.fAssetId, poolTokenId]
});

if (optInRequiredAssetIds.length) {
Expand Down

0 comments on commit 8fe9c5c

Please sign in to comment.