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AA;AAAA;AAAA,EAOA,MAAa,YAAA,CACX,QAAA,EACA,MAAA,EAGA;AACA,IAAA,MAAM,iBAAA,EAAmB,MAAM,IAAA,CAAK,mBAAA,CAAoB,QAAA,EAAU,MAAM,CAAA;AAExE,IAAA,OAAO,6BAAA,CAAY,MAAA,CAAO,gBAAgB,CAAA;AAAA,EAC5C;AACF,yDAAA;AD7GA;AACA;AACE;AACF,wBAAC","file":"/Users/paul-n/git/ston-fi/public/sdk-contracts/packages/sdk/dist/chunk-7JHUCCLN.cjs","sourcesContent":[null,"import {\n  beginCell,\n  type Cell,\n  type ContractProvider,\n  type Sender,\n  type SenderArguments,\n  toNano,\n} from \"@ton/ton\";\n\nimport type { AddressType, AmountType, QueryIdType } from \"../../../types\";\nimport { toAddress } from \"../../../utils/toAddress\";\nimport type { ContractOptions } from \"../../core/Contract\";\nimport { JettonMinter } from \"../../core/JettonMinter\";\nimport { JettonWallet } from \"../../core/JettonWallet\";\nimport { DEX_VERSION } from \"../constants\";\nimport { DEX_OP_CODES } from \"./constants\";\nimport { LpAccountV1 } from \"./LpAccountV1\";\n\nexport interface PoolV1Options extends ContractOptions {\n  gasConstants?: Partial<typeof PoolV1.gasConstants>;\n}\n\n/**\n * The pool is the contract that stores the AMM data for a certain pair and is responsible for handling “swaps” or providing liquidity for a certain pool.\n * For each pair (e.g. STON/USDT), there is only a single pool contract.\n * The pool is also a Jetton Minter, and handles minting/burning of Liquidity Provider Jettons.\n * All the swap/lp calculations are done in the pool contract.\n */\nexport class PoolV1 extends JettonMinter {\n  public static readonly version: DEX_VERSION = DEX_VERSION.v1;\n  public static readonly gasConstants = {\n    collectFees: toNano(\"1.1\"),\n    burn: toNano(\"0.5\"),\n  };\n\n  public readonly gasConstants;\n\n  constructor(\n    address: AddressType,\n    { gasConstants, ...options }: PoolV1Options = {},\n  ) {\n    super(address, options);\n\n    this.gasConstants = {\n      ...PoolV1.gasConstants,\n      ...gasConstants,\n    };\n  }\n\n  public async createCollectFeesBody(params?: {\n    queryId?: QueryIdType;\n  }): Promise<Cell> {\n    return beginCell()\n      .storeUint(DEX_OP_CODES.COLLECT_FEES, 32)\n      .storeUint(params?.queryId ?? 0, 64)\n      .endCell();\n  }\n\n  /**\n   * Build all data required to execute a `collect_fees` transaction.\n   *\n   * @param {bigint | number | string | undefined} params.gasAmount - Optional; Custom transaction gas amount (in nanoTons)\n   * @param {bigint | number | undefined} params.queryId - Optional; query id\n   *\n   * @returns {SenderArguments} all data required to execute a `collect_fees` transaction.\n   */\n  public async getCollectFeeTxParams(\n    provider: ContractProvider,\n    params?: {\n      gasAmount?: AmountType;\n      queryId?: QueryIdType;\n    },\n  ): Promise<SenderArguments> {\n    const to = this.address;\n\n    const body = await this.createCollectFeesBody({\n      queryId: params?.queryId,\n    });\n\n    const value = BigInt(params?.gasAmount ?? this.gasConstants.collectFees);\n\n    return { to, value, body };\n  }\n\n  public async sendCollectFees(\n    provider: ContractProvider,\n    via: Sender,\n    params: Parameters<PoolV1[\"getCollectFeeTxParams\"]>[1],\n  ) {\n    const txParams = await this.getCollectFeeTxParams(provider, params);\n\n    return via.send(txParams);\n  }\n\n  public async createBurnBody(params: {\n    amount: AmountType;\n    responseAddress: AddressType;\n    queryId?: QueryIdType;\n  }): Promise<Cell> {\n    return beginCell()\n      .storeUint(DEX_OP_CODES.BURN, 32)\n      .storeUint(params?.queryId ?? 0, 64)\n      .storeCoins(BigInt(params.amount))\n      .storeAddress(toAddress(params.responseAddress))\n      .storeMaybeRef()\n      .endCell();\n  }\n\n  /**\n   * Build all data required to execute a `burn` transaction.\n   *\n   * @param {bigint | number} params.amount - Amount of lp tokens to burn (in basic token units)\n   * @param {Address | string} params.responseAddress - Address of a user\n   * @param {bigint | number | string | undefined} params.gasAmount - Optional; Custom transaction gas amount (in nanoTons)\n   * @param {bigint | number | undefined} params.queryId - Optional; query id\n   *\n   * @returns {SenderArguments} all data required to execute a `burn` transaction.\n   */\n  public async getBurnTxParams(\n    provider: ContractProvider,\n    params: {\n      amount: AmountType;\n      responseAddress: AddressType;\n      gasAmount?: AmountType;\n      queryId?: QueryIdType;\n    },\n  ): Promise<SenderArguments> {\n    const [to, body] = await Promise.all([\n      this.getWalletAddress(provider, params.responseAddress),\n      this.createBurnBody({\n        amount: params.amount,\n        responseAddress: params.responseAddress,\n        queryId: params.queryId,\n      }),\n    ]);\n\n    const value = BigInt(params.gasAmount ?? this.gasConstants.burn);\n\n    return { to, value, body };\n  }\n\n  public async sendBurn(\n    provider: ContractProvider,\n    via: Sender,\n    params: Parameters<PoolV1[\"getBurnTxParams\"]>[1],\n  ) {\n    const txParams = await this.getBurnTxParams(provider, params);\n\n    return via.send(txParams);\n  }\n\n  /**\n   * Estimate the expected result of the amount of jettonWallet tokens swapped to the other token of the pool\n   *\n   * @param {bigint | number} params.amount - Amount of tokens to swap (in basic token units)\n   * @param {Address | string} params.jettonWallet - jetton wallet address (owned by the router)\n   *\n   * @returns structure with the expected result of a token swap\n   */\n  public async getExpectedOutputs(\n    provider: ContractProvider,\n    params: {\n      amount: AmountType;\n      jettonWallet: AddressType;\n    },\n  ) {\n    const result = await provider.get(\"get_expected_outputs\", [\n      { type: \"int\", value: BigInt(params.amount) },\n      {\n        type: \"slice\",\n        cell: beginCell()\n          .storeAddress(toAddress(params.jettonWallet))\n          .endCell(),\n      },\n    ]);\n\n    return {\n      jettonToReceive: result.stack.readBigNumber(),\n      protocolFeePaid: result.stack.readBigNumber(),\n      refFeePaid: result.stack.readBigNumber(),\n    };\n  }\n\n  /**\n   * Estimate an expected amount of lp tokens minted when providing liquidity.\n   *\n   * @param {bigint | number} params.amount0 - Amount of tokens for the first Jetton (in basic token units)\n   * @param {bigint | number} params.amount1 - Amount of tokens for the second Jetton (in basic token units)\n   *\n   * @returns {bigint} an estimated amount of liquidity tokens to be minted\n   */\n  public async getExpectedTokens(\n    provider: ContractProvider,\n    params: {\n      amount0: AmountType;\n      amount1: AmountType;\n    },\n  ) {\n    const result = await provider.get(\"get_expected_tokens\", [\n      { type: \"int\", value: BigInt(params.amount0) },\n      { type: \"int\", value: BigInt(params.amount1) },\n    ]);\n\n    return result.stack.readBigNumber();\n  }\n\n  /**\n   * Estimate expected liquidity freed upon burning liquidity tokens.\n   *\n   * @param {bigint | number} params.jettonAmount - Amount of liquidity tokens (in basic token units)\n   *\n   * @returns structure with expected freed liquidity\n   */\n  public async getExpectedLiquidity(\n    provider: ContractProvider,\n    params: {\n      jettonAmount: AmountType;\n    },\n  ) {\n    const result = await provider.get(\"get_expected_liquidity\", [\n      { type: \"int\", value: BigInt(params.jettonAmount) },\n    ]);\n\n    return {\n      amount0: result.stack.readBigNumber(),\n      amount1: result.stack.readBigNumber(),\n    };\n  }\n\n  /**\n   * @param {Address | string} params.ownerAddress - Address of a user\n   *\n   * @returns {Address} the lp account address of a user\n   */\n  public async getLpAccountAddress(\n    provider: ContractProvider,\n    params: {\n      ownerAddress: AddressType;\n    },\n  ) {\n    const result = await provider.get(\"get_lp_account_address\", [\n      {\n        type: \"slice\",\n        cell: beginCell()\n          .storeAddress(toAddress(params.ownerAddress))\n          .endCell(),\n      },\n    ]);\n\n    return result.stack.readAddress();\n  }\n\n  /**\n   * @param {Address | string} params.ownerAddress - Address of a user\n   *\n   * @returns {JettonWallet} a JettonWallet instance with address returned by getJettonWalletAddress\n   */\n  public async getJettonWallet(\n    provider: ContractProvider,\n    params: {\n      ownerAddress: AddressType;\n    },\n  ) {\n    const jettonWalletAddress = await this.getWalletAddress(\n      provider,\n      params.ownerAddress,\n    );\n\n    return JettonWallet.create(jettonWalletAddress);\n  }\n\n  /**\n   * @returns structure containing current state of the pool.\n   */\n  public async getPoolData(provider: ContractProvider) {\n    const result = await provider.get(\"get_pool_data\", []);\n\n    return {\n      reserve0: result.stack.readBigNumber(),\n      reserve1: result.stack.readBigNumber(),\n      token0WalletAddress: result.stack.readAddress(),\n      token1WalletAddress: result.stack.readAddress(),\n      lpFee: result.stack.readBigNumber(),\n      protocolFee: result.stack.readBigNumber(),\n      refFee: result.stack.readBigNumber(),\n      protocolFeeAddress: result.stack.readAddress(),\n      collectedToken0ProtocolFee: result.stack.readBigNumber(),\n      collectedToken1ProtocolFee: result.stack.readBigNumber(),\n    };\n  }\n\n  /**\n   * @param {Address | string} params.ownerAddress - Address of a user\n   *\n   * @returns {LpAccount} object for address returned by getLpAccountAddress\n   */\n  public async getLpAccount(\n    provider: ContractProvider,\n    params: {\n      ownerAddress: AddressType;\n    },\n  ) {\n    const lpAccountAddress = await this.getLpAccountAddress(provider, params);\n\n    return LpAccountV1.create(lpAccountAddress);\n  }\n}\n"]}