diff --git a/CHANGELOG.md b/CHANGELOG.md index 91806aaf..2bc65dfe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security +## @mercurial-finance/dynamic-amm-sdk [1.1.14] - PR[#177](https://github.com/mercurial-finance/mercurial-dynamic-amm-sdk/pull/177) + +### Added + +- Fix function `swapAndStakeForFee` to accept additional param `inAmountLamport` + ## @mercurial-finance/dynamic-amm-sdk [1.1.13] - PR[#176](https://github.com/mercurial-finance/mercurial-dynamic-amm-sdk/pull/176) ### Added diff --git a/ts-client/package.json b/ts-client/package.json index 9d9f6cff..d77c0d95 100644 --- a/ts-client/package.json +++ b/ts-client/package.json @@ -1,6 +1,6 @@ { "name": "@mercurial-finance/dynamic-amm-sdk", - "version": "1.1.13", + "version": "1.1.14", "description": "Mercurial Vaults SDK is a typescript library that allows you to interact with Mercurial v2's AMM.", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", diff --git a/ts-client/src/amm/index.ts b/ts-client/src/amm/index.ts index 546d48cd..ab22fa64 100644 --- a/ts-client/src/amm/index.ts +++ b/ts-client/src/amm/index.ts @@ -2002,78 +2002,17 @@ export default class AmmImpl implements AmmImplementation { owner: PublicKey, inTokenMint: PublicKey, inAmountLamport: BN, + minOutAmountLamport: BN, outAmountLamport: BN, stakeForFee: StakeForFee, ): Promise { const resultTxs: Transaction[] = []; - const [sourceToken, destinationToken] = this.tokenAMint.address.equals(inTokenMint) - ? [this.poolState.tokenAMint, this.poolState.tokenBMint] - : [this.poolState.tokenBMint, this.poolState.tokenAMint]; - - const protocolTokenFee = this.tokenAMint.address.equals(inTokenMint) - ? this.poolState.protocolTokenAFee - : this.poolState.protocolTokenBFee; - - let preInstructions: Array = []; - const [[userSourceToken, createUserSourceIx], [userDestinationToken, createUserDestinationIx]] = - await this.createATAPreInstructions(owner, [sourceToken, destinationToken]); - - createUserSourceIx && preInstructions.push(createUserSourceIx); - createUserDestinationIx && preInstructions.push(createUserDestinationIx); - - if (sourceToken.equals(NATIVE_MINT)) { - preInstructions = preInstructions.concat( - wrapSOLInstruction(owner, userSourceToken, BigInt(inAmountLamport.toString())), - ); - } - - const postInstructions: Array = []; - if (NATIVE_MINT.equals(destinationToken)) { - const unwrapSOLIx = await unwrapSOLInstruction(owner); - unwrapSOLIx && postInstructions.push(unwrapSOLIx); - } - - const remainingAccounts = this.swapCurve.getRemainingAccounts(); - - const swapTx = await this.program.methods - .swap(inAmountLamport, outAmountLamport) - .accounts({ - aTokenVault: this.vaultA.vaultState.tokenVault, - bTokenVault: this.vaultB.vaultState.tokenVault, - aVault: this.poolState.aVault, - bVault: this.poolState.bVault, - aVaultLp: this.poolState.aVaultLp, - bVaultLp: this.poolState.bVaultLp, - aVaultLpMint: this.vaultA.vaultState.lpMint, - bVaultLpMint: this.vaultB.vaultState.lpMint, - userSourceToken, - userDestinationToken, - user: owner, - protocolTokenFee, - pool: this.address, - tokenProgram: TOKEN_PROGRAM_ID, - vaultProgram: this.vaultProgram.programId, - }) - .remainingAccounts(remainingAccounts) - .preInstructions(preInstructions) - .postInstructions(postInstructions) - .transaction(); - - resultTxs.push( - new Transaction({ - feePayer: owner, - ...(await this.program.provider.connection.getLatestBlockhash(this.program.provider.connection.commitment)), - }).add(swapTx), - ); + const swapTx = await this.swap(owner, inTokenMint, inAmountLamport, minOutAmountLamport); + resultTxs.push(swapTx); + const stakeTx = await stakeForFee.stake(outAmountLamport, owner); - - resultTxs.push( - new Transaction({ - feePayer: owner, - ...(await this.program.provider.connection.getLatestBlockhash(this.program.provider.connection.commitment)), - }).add(stakeTx), - ); + resultTxs.push(stakeTx); return resultTxs; }