# almm:add-liquidity — Ammora SDK 0.3.8 Check the source for arguments and transaction requirements. [Read in Docs](https://docs.ammora.org/examples?command=almm%3Aadd-liquidity) · [Detailed guide](https://docs.ammora.org/guides/src-almm-readme) · [Local setup](https://docs.ammora.org/guides/example-setup) ## Context and execution GIWA Sepolia 91342. Public SDK 0.3.8, Math 0.3.0. Source revision: `a9b3fd798fa51495e8defec99a25de59e4d70672`. Install the SDK in your app, or prepare the example project using the local setup guide for its npm commands. Review the entry source and guide for required arguments, roles and deployment selection. `AMMORA_SEND=0` does not turn send-only commands into previews. Never put CLI keys in a browser or resend an uncertain transaction. Command: `npm run almm:add-liquidity -- ` (`tsx src/almm/add-liquidity.ts`). Omit `--` and arguments when the source accepts none. ## Entry file: `src/almm/add-liquidity.ts` ```typescript import { tokenAmount } from "../shared/input.js"; /** * Add liquidity to a bin position you already hold, weighted across its bins. * * npm run almm:add-liquidity -- * * Weights decide how the deposit is spread. This puts an equal weight on every bin the * position already covers, which keeps its existing shape; pass your own weights to the * SDK to change it. */ import { ALMMClient } from "@ammora-protocol/sdk"; import { clientOptions, address, deployment, reader, signer } from "../shared/env.js"; import { aboutPosition, amount, approve, asPool, main, requireContract, send, tokenInfo } from "../shared/run.js"; main(async () => { const [poolArgument, tokenIdArgument, baseArgument, quoteArgument] = process.argv.slice(2); const pool = address("ALMM_POOL", poolArgument); if (!tokenIdArgument || !baseArgument || !quoteArgument) { throw new Error("usage: "); } const tokenId = BigInt(tokenIdArgument); const { wallet, account } = signer(); const client = await reader(); const contracts = deployment().contracts.liquidityMarketMaker; await requireContract(client, "pool", pool); const sdk = new ALMMClient(client, pool, contracts.positionManager, contracts.binLens, clientOptions()); const state = await asPool(pool, "a bin pool", () => sdk.getPoolState()); const [base, quote] = await Promise.all([ tokenInfo(client, state.baseToken), tokenInfo(client, state.quoteToken), ]); const totalBaseAmount = tokenAmount(baseArgument, base.decimals, true); const totalQuoteAmount = tokenAmount(quoteArgument, quote.decimals, true); // The bins this position already covers; adding to those keeps its shape. const context = await aboutPosition(tokenId, () => sdk.getPositionContext(tokenId, account.address)); const binIds: number[] = []; for (let binId = context.lowerBinId; binId <= context.upperBinId; binId += 1) { binIds.push(binId); } if (binIds.length === 0) throw new Error(`position ${tokenId} covers no bins`); if (binIds.length > 64) { // The contract caps a weighted deposit at 64 bins per call. throw new Error(`position spans ${binIds.length} bins, so add to them in chunks of 64`); } console.log(`pool ${pool}`); console.log(`position ${tokenId} across ${binIds.length} bin(s)`); console.log(`adding ${amount(totalBaseAmount, base.decimals, base.symbol)}`); console.log(` ${amount(totalQuoteAmount, quote.decimals, quote.symbol)}`); console.log(""); const plan = await sdk.planAddLiquidityByWeight({ tokenId, caller: account.address, totalBaseAmount, totalQuoteAmount, weights: binIds.map((binId) => ({ binId, baseWeight: 1n, quoteWeight: 1n })), shareSlippageBps: 100, deadline: BigInt(Math.floor(Date.now() / 1000) + 600), }); await approve(plan.approvalRequirements, wallet, account, client); await send("addLiquidityByWeight", plan.transaction, wallet, account, client); }); ``` ## Supporting files Keep relative paths intact. Local imports are listed recursively; JSON templates are choices to review, not approved inputs. Runtime-selected files and wallet/environment setup still follow the detailed guide. - [src/shared/env.ts](https://docs.ammora.org/examples/source/src/shared/env.ts.txt) - [src/shared/input.ts](https://docs.ammora.org/examples/source/src/shared/input.ts.txt) - [src/shared/retry.ts](https://docs.ammora.org/examples/source/src/shared/retry.ts.txt) - [src/shared/rpc.ts](https://docs.ammora.org/examples/source/src/shared/rpc.ts.txt) - [src/shared/run.ts](https://docs.ammora.org/examples/source/src/shared/run.ts.txt) - [src/almm/rebalance.example.json](https://docs.ammora.org/examples/source/src/almm/rebalance.example.json.txt) - [package.json](https://docs.ammora.org/examples/source/package.json.txt) - [package-lock.json](https://docs.ammora.org/examples/source/package-lock.json.txt) - [tsconfig.json](https://docs.ammora.org/examples/source/tsconfig.json.txt) - [.env.giwa.example](https://docs.ammora.org/examples/source/file.env.giwa.example.txt) - [.nvmrc](https://docs.ammora.org/examples/source/file.nvmrc.txt) ## AI implementation checklist Use the actual SDK exports and parameter types in the linked files. Start with reads and unsigned plans where supported. Use a connected wallet for browser signing. Preserve raw integer units, exact approvals, caller authority, deadlines and receipt reconciliation. Report local checks separately from live-chain verification.