{"version":3,"file":"app-manager.mjs","names":[],"sources":["../../src/types/app-manager.ts"],"sourcesContent":["import algosdk, { Address, ProgramSourceMap } from 'algosdk'\nimport { getABIReturnValue } from '../transaction/transaction'\nimport { TransactionSignerAccount } from './account'\nimport {\n  BoxName,\n  DELETABLE_TEMPLATE_NAME,\n  UPDATABLE_TEMPLATE_NAME,\n  type ABIReturn,\n  type AppState,\n  type CompiledTeal,\n  type TealTemplateParams,\n} from './app'\nimport modelsv2 = algosdk.modelsv2\n\n/** Information about an app. */\nexport interface AppInformation {\n  /** The ID of the app. */\n  appId: bigint\n  /** The escrow address that the app operates with. */\n  appAddress: Address\n  /**\n   * Approval program.\n   */\n  approvalProgram: Uint8Array\n  /**\n   * Clear state program.\n   */\n  clearStateProgram: Uint8Array\n  /**\n   * The address that created this application. This is the address where the\n   * parameters and global state for this application can be found.\n   */\n  creator: Address\n  /**\n   * Current global state values.\n   */\n  globalState: AppState\n  /** The number of allocated ints in per-user local state. */\n  localInts: number\n  /** The number of allocated byte slices in per-user local state. */\n  localByteSlices: number\n  /** The number of allocated ints in global state. */\n  globalInts: number\n  /** The number of allocated byte slices in global state. */\n  globalByteSlices: number\n  /** Any extra pages that are needed for the smart contract. */\n  extraProgramPages?: number\n  /** The number of updates to the application programs */\n  version?: number\n}\n\n/**\n * Something that identifies an app box name - either a:\n *  * `Uint8Array` (the actual binary of the box name)\n *  * `string` (that will be encoded to a `Uint8Array`)\n *  * `TransactionSignerAccount` (that will be encoded into the\n *    public key address of the corresponding account)\n */\nexport type BoxIdentifier = string | Uint8Array | TransactionSignerAccount\n\n/**\n * A grouping of the app ID and name identifier to reference an app box.\n */\nexport interface BoxReference {\n  /**\n   * A unique application id\n   */\n  appId: bigint\n  /**\n   * Identifier for a box name\n   */\n  name: BoxIdentifier\n}\n\n/**\n * Parameters to get and decode a box value as an ABI type.\n */\nexport interface BoxValueRequestParams {\n  /** The ID of the app return box names for */\n  appId: bigint\n  /** The name of the box to return either as a string, binary array or `BoxName` */\n  boxName: BoxIdentifier\n  /** The ABI type to decode the value using */\n  type: algosdk.ABIType\n}\n\n/**\n * Parameters to get and decode a box value as an ABI type.\n */\nexport interface BoxValuesRequestParams {\n  /** The ID of the app return box names for */\n  appId: bigint\n  /** The names of the boxes to return either as a string, binary array or BoxName` */\n  boxNames: BoxIdentifier[]\n  /** The ABI type to decode the value using */\n  type: algosdk.ABIType\n}\n\n/**\n * Defines a holding by referring to an Address and Asset it belongs to.\n */\nexport type HoldingReference = {\n  /** Asset ID for asset in access list. */\n  assetId: bigint\n  /** Address in access list, or the sender of the transaction. */\n  address: Address\n}\n\n/**\n * Defines a local state by referring to an Address and App it belongs to.\n */\nexport type LocalsReference = {\n  /** Application ID for app in access list, or zero if referring to the called application. */\n  appId: bigint\n  /** Address in access list, or the sender of the transaction. */\n  address: Address\n}\n\n/**\n * Names a single resource reference. Only one of the fields should be set.\n */\nexport type ResourceReference = {\n  /** Any account addresses whose balance record is accessible by the executing ApprovalProgram or ClearStateProgram. */\n  address?: Address\n  /** Application ID whose GlobalState may be read by the executing ApprovalProgram or ClearStateProgram. */\n  appId?: bigint\n  /** Asset ID whose AssetParams may be read by the executing ApprovalProgram or ClearStateProgram. */\n  assetId?: bigint\n  /** Defines a holding by referring to an Address and Asset it belongs to. */\n  holding?: HoldingReference\n  /** Defines a local state by referring to an Address and App it belongs to. */\n  locals?: LocalsReference\n  /** Defines a box by its name and the application ID it belongs to. */\n  box?: BoxReference\n}\n\n/** Allows management of application information. */\nexport class AppManager {\n  private _algod: algosdk.Algodv2\n  private _compilationResults: Record<string, CompiledTeal> = {}\n\n  /**\n   * Creates an `AppManager`\n   * @param algod An algod instance\n   */\n  constructor(algod: algosdk.Algodv2) {\n    this._algod = algod\n  }\n\n  /**\n   * Compiles the given TEAL using algod and returns the result, including source map.\n   *\n   * The result of this compilation is also cached keyed by the TEAL\n   *  code so it can be retrieved via `getCompilationResult`.\n   *\n   * This function is re-entrant; it will only compile the same code once.\n   *\n   * @param tealCode The TEAL code\n   * @returns The information about the compiled file\n   * @example\n   * ```typescript\n   * const compiled = await appManager.compileTeal(tealProgram)\n   * ```\n   */\n  async compileTeal(tealCode: string): Promise<CompiledTeal> {\n    if (this._compilationResults[tealCode]) {\n      return this._compilationResults[tealCode]\n    }\n\n    const compiled = await this._algod.compile(tealCode).sourcemap(true).do()\n    const result = {\n      teal: tealCode,\n      compiled: compiled.result,\n      compiledHash: compiled.hash,\n      compiledBase64ToBytes: new Uint8Array(Buffer.from(compiled.result, 'base64')),\n      sourceMap: new ProgramSourceMap(JSON.parse(algosdk.encodeJSON(compiled.sourcemap!))),\n    }\n    this._compilationResults[tealCode] = result\n\n    return result\n  }\n\n  /**\n   * Performs template substitution of a teal template and compiles it, returning the compiled result.\n   *\n   * Looks for `TMPL_{parameter}` for template replacements and replaces AlgoKit deploy-time control parameters\n   * if deployment metadata is specified.\n   *\n   * * `TMPL_UPDATABLE` for updatability / immutability control\n   * * `TMPL_DELETABLE` for deletability / permanence control\n   *\n   * @param tealTemplateCode The TEAL logic to compile\n   * @param templateParams Any parameters to replace in the .teal file before compiling\n   * @param deploymentMetadata The deployment metadata the app will be deployed with\n   * @returns The information about the compiled code\n   * @example\n   * ```typescript\n   * const compiled = await appManager.compileTealTemplate(tealTemplate, { TMPL_APP_ID: 12345n }, { updatable: true, deletable: false })\n   * ```\n   */\n  async compileTealTemplate(\n    tealTemplateCode: string,\n    templateParams?: TealTemplateParams,\n    deploymentMetadata?: { updatable?: boolean; deletable?: boolean },\n  ): Promise<CompiledTeal> {\n    let tealCode = AppManager.stripTealComments(tealTemplateCode)\n\n    tealCode = AppManager.replaceTealTemplateParams(tealCode, templateParams)\n\n    if (deploymentMetadata) {\n      tealCode = AppManager.replaceTealTemplateDeployTimeControlParams(tealCode, deploymentMetadata)\n    }\n\n    return await this.compileTeal(tealCode)\n  }\n\n  /**\n   * Returns a previous compilation result.\n   * @param tealCode The TEAL code\n   * @returns The information about the previously compiled file\n   *  or `undefined` if that TEAL code wasn't previously compiled\n   * @example\n   * ```typescript\n   * const compiled = appManager.getCompilationResult(tealProgram)\n   * ```\n   */\n  getCompilationResult(tealCode: string): CompiledTeal | undefined {\n    return this._compilationResults[tealCode]\n  }\n\n  /**\n   * Returns the current app information for the app with the given ID.\n   *\n   * @example\n   * ```typescript\n   * const appInfo = await appManager.getById(12353n);\n   * ```\n   *\n   * @param appId The ID of the app\n   * @returns The app information\n   */\n  public async getById(appId: bigint): Promise<AppInformation> {\n    const app = await this._algod.getApplicationByID(Number(appId)).do()\n    const params = app.params!\n    return {\n      appId: BigInt(app.id),\n      appAddress: algosdk.getApplicationAddress(app.id),\n      approvalProgram: params.approvalProgram,\n      clearStateProgram: params.clearStateProgram,\n      creator: params.creator,\n      localInts: Number(params.localStateSchema?.numUint ?? 0),\n      localByteSlices: Number(params.localStateSchema?.numByteSlice ?? 0),\n      globalInts: Number(params.globalStateSchema?.numUint ?? 0),\n      globalByteSlices: Number(params.globalStateSchema?.numByteSlice ?? 0),\n      extraProgramPages: Number(params.extraProgramPages ?? 0),\n      globalState: AppManager.decodeAppState(params.globalState ?? []),\n      version: params.version,\n    }\n  }\n\n  /**\n   * Returns the current global state values for the given app ID and account address\n   *\n   * @param appId The ID of the app to return global state for\n   * @returns The current global state for the given app\n   * @example\n   * ```typescript\n   * const globalState = await appManager.getGlobalState(12353n);\n   * ```\n   */\n  public async getGlobalState(appId: bigint) {\n    return (await this.getById(appId)).globalState\n  }\n\n  /**\n   * Returns the current local state values for the given app ID and account address\n   *\n   * @param appId The ID of the app to return local state for\n   * @param address The string address of the account to get local state for the given app\n   * @returns The current local state for the given (app, account) combination\n   * @example\n   * ```typescript\n   * const localState = await appManager.getLocalState(12353n, 'ACCOUNTADDRESS');\n   * ```\n   */\n  public async getLocalState(appId: bigint, address: Address | string) {\n    const appInfo = await this._algod.accountApplicationInformation(address, appId).do()\n\n    if (!appInfo.appLocalState?.keyValue) {\n      throw new Error(\"Couldn't find local state\")\n    }\n\n    return AppManager.decodeAppState(appInfo.appLocalState.keyValue)\n  }\n\n  /**\n   * Returns the names of the current boxes for the given app.\n   * @param appId The ID of the app return box names for\n   * @returns The current box names\n   * @example\n   * ```typescript\n   * const boxNames = await appManager.getBoxNames(12353n);\n   * ```\n   */\n  public async getBoxNames(appId: bigint): Promise<BoxName[]> {\n    const boxResult = await this._algod.getApplicationBoxes(appId).do()\n    return boxResult.boxes.map((b) => {\n      return {\n        nameRaw: b.name,\n        nameBase64: Buffer.from(b.name).toString('base64'),\n        name: Buffer.from(b.name).toString('utf-8'),\n      }\n    })\n  }\n\n  /**\n   * Returns the value of the given box name for the given app.\n   * @param appId The ID of the app return box names for\n   * @param boxName The name of the box to return either as a string, binary array or `BoxName`\n   * @returns The current box value as a byte array\n   * @example\n   * ```typescript\n   * const boxValue = await appManager.getBoxValue(12353n, 'boxName');\n   * ```\n   */\n  public async getBoxValue(appId: bigint, boxName: BoxIdentifier | BoxName): Promise<Uint8Array> {\n    const boxId = typeof boxName === 'object' && 'nameRaw' in boxName ? boxName.nameRaw : boxName\n    const name = AppManager.getBoxReference(boxId).name\n    const boxResult = await this._algod.getApplicationBoxByName(Number(appId), name).do()\n    return boxResult.value\n  }\n\n  /**\n   * Returns the value of the given box names for the given app.\n   * @param appId The ID of the app return box names for\n   * @param boxNames The names of the boxes to return either as a string, binary array or `BoxName`\n   * @returns The current box values as a byte array in the same order as the passed in box names\n   * @example\n   * ```typescript\n   * const boxValues = await appManager.getBoxValues(12353n, ['boxName1', 'boxName2']);\n   * ```\n   */\n  public async getBoxValues(appId: bigint, boxNames: (BoxIdentifier | BoxName)[]): Promise<Uint8Array[]> {\n    return await Promise.all(boxNames.map(async (boxName) => await this.getBoxValue(appId, boxName)))\n  }\n\n  /**\n   * Returns the value of the given box name for the given app decoded based on the given ABI type.\n   * @param request The parameters for the box value request\n   * @returns The current box value as an ABI value\n   * @example\n   * ```typescript\n   * const boxValue = await appManager.getBoxValueFromABIType({ appId: 12353n, boxName: 'boxName', type: new ABIUintType(32) });\n   * ```\n   */\n  public async getBoxValueFromABIType(request: BoxValueRequestParams): Promise<algosdk.ABIValue> {\n    const { appId, boxName, type } = request\n    const value = await this.getBoxValue(appId, boxName)\n    return type.decode(value)\n  }\n\n  /**\n   * Returns the value of the given box names for the given app decoded based on the given ABI type.\n   * @param request The parameters for the box value request\n   * @returns The current box values as an ABI value in the same order as the passed in box names\n   * @example\n   * ```typescript\n   * const boxValues = await appManager.getBoxValuesFromABIType({ appId: 12353n, boxNames: ['boxName1', 'boxName2'], type: new ABIUintType(32) });\n   * ```\n   */\n  public async getBoxValuesFromABIType(request: BoxValuesRequestParams): Promise<algosdk.ABIValue[]> {\n    const { appId, boxNames, type } = request\n    return await Promise.all(boxNames.map(async (boxName) => await this.getBoxValueFromABIType({ appId, boxName, type })))\n  }\n\n  /**\n   * Returns a `algosdk.BoxReference` given a `BoxIdentifier` or `BoxReference`.\n   * @param boxId The box to return a reference for\n   * @returns The box reference ready to pass into a `algosdk.Transaction`\n   * @example\n   * ```typescript\n   * const boxRef = AppManager.getBoxReference('boxName');\n   * ```\n   */\n  public static getBoxReference(boxId: BoxIdentifier | BoxReference): algosdk.BoxReference {\n    const ref = typeof boxId === 'object' && 'appId' in boxId ? boxId : { appId: 0n, name: boxId }\n    return {\n      appIndex: ref.appId,\n      name: typeof ref.name === 'string' ? new TextEncoder().encode(ref.name) : 'length' in ref.name ? ref.name : ref.name.addr.publicKey,\n    } as algosdk.BoxReference\n  }\n\n  /**\n   * Converts an array of global/local state values from the algod api to a more friendly\n   * generic object keyed by the UTF-8 value of the key.\n   * @param state A `global-state`, `local-state`, `global-state-deltas` or `local-state-deltas`\n   * @returns An object keyeed by the UTF-8 representation of the key with various parsings of the values\n   * @example\n   * ```typescript\n   * const stateValues = AppManager.decodeAppState(state);\n   * ```\n   */\n  public static decodeAppState(state: { key: Uint8Array; value: modelsv2.TealValue | modelsv2.EvalDelta }[]): AppState {\n    const stateValues = {} as AppState\n\n    // Start with empty set\n    for (const stateVal of state) {\n      const keyBase64 = Buffer.from(stateVal.key).toString('base64')\n      const keyRaw = stateVal.key\n      const key = Buffer.from(stateVal.key).toString('utf-8')\n      const tealValue = stateVal.value\n\n      const dataTypeFlag = 'action' in tealValue ? tealValue.action : tealValue.type\n      let valueBase64: string\n      let valueRaw: Buffer\n      switch (dataTypeFlag) {\n        case 1:\n          valueBase64 =\n            typeof tealValue.bytes === 'string' ? tealValue.bytes : tealValue.bytes ? Buffer.from(tealValue.bytes).toString('base64') : ''\n          valueRaw = Buffer.from(valueBase64, 'base64')\n          stateValues[key] = {\n            keyRaw,\n            keyBase64,\n            valueRaw: new Uint8Array(valueRaw),\n            valueBase64: valueBase64,\n            value: valueRaw.toString('utf-8'),\n          }\n          break\n        case 2: {\n          const value = tealValue.uint ?? 0\n          stateValues[key] = {\n            keyRaw,\n            keyBase64,\n            value: BigInt(value),\n          }\n          break\n        }\n        default:\n          throw new Error(`Received unknown state data type of ${dataTypeFlag}`)\n      }\n    }\n\n    return stateValues\n  }\n\n  /**\n   * Returns any ABI return values for the given app call arguments and transaction confirmation.\n   * @param confirmation The transaction confirmation from algod\n   * @param method The ABI method\n   * @returns The return value for the method call\n   * @example\n   * ```typescript\n   * const returnValue = AppManager.getABIReturn(confirmation, ABIMethod.fromSignature('hello(string)void'));\n   * ```\n   */\n  public static getABIReturn(\n    confirmation: modelsv2.PendingTransactionResponse | undefined,\n    method: algosdk.ABIMethod | undefined,\n  ): ABIReturn | undefined {\n    if (!method || !confirmation || method.returns.type === 'void') {\n      return undefined\n    }\n\n    // The parseMethodResponse method mutates the second parameter :(\n    const resultDummy: algosdk.ABIResult = {\n      txID: '',\n      method,\n      rawReturnValue: new Uint8Array(),\n    }\n    return getABIReturnValue(algosdk.AtomicTransactionComposer.parseMethodResponse(method, resultDummy, confirmation), method.returns.type)\n  }\n\n  /**\n   * Replaces AlgoKit deploy-time deployment control parameters within the given TEAL template code.\n   *\n   * * `TMPL_UPDATABLE` for updatability / immutability control\n   * * `TMPL_DELETABLE` for deletability / permanence control\n   *\n   * Note: If these values are defined, but the corresponding `TMPL_*` value\n   *  isn't in the teal code it will throw an exception.\n   *\n   * @param tealTemplateCode The TEAL template code to substitute\n   * @param params The deploy-time deployment control parameter value to replace\n   * @returns The replaced TEAL code\n   * @example\n   * ```typescript\n   * const tealCode = AppManager.replaceTealTemplateDeployTimeControlParams(tealTemplate, { updatable: true, deletable: false });\n   * ```\n   */\n  static replaceTealTemplateDeployTimeControlParams(tealTemplateCode: string, params: { updatable?: boolean; deletable?: boolean }) {\n    if (params.updatable !== undefined) {\n      if (!tealTemplateCode.includes(UPDATABLE_TEMPLATE_NAME)) {\n        throw new Error(\n          `Deploy-time updatability control requested for app deployment, but ${UPDATABLE_TEMPLATE_NAME} not present in TEAL code`,\n        )\n      }\n      tealTemplateCode = replaceTemplateVariable(tealTemplateCode, UPDATABLE_TEMPLATE_NAME, (params.updatable ? 1 : 0).toString())\n    }\n\n    if (params.deletable !== undefined) {\n      if (!tealTemplateCode.includes(DELETABLE_TEMPLATE_NAME)) {\n        throw new Error(\n          `Deploy-time deletability control requested for app deployment, but ${DELETABLE_TEMPLATE_NAME} not present in TEAL code`,\n        )\n      }\n      tealTemplateCode = replaceTemplateVariable(tealTemplateCode, DELETABLE_TEMPLATE_NAME, (params.deletable ? 1 : 0).toString())\n    }\n\n    return tealTemplateCode\n  }\n\n  /**\n   * Performs template substitution of a teal file.\n   *\n   * Looks for `TMPL_{parameter}` for template replacements.\n   *\n   * @param tealTemplateCode The TEAL template code to make parameter replacements in\n   * @param templateParams Any parameters to replace in the teal code\n   * @returns The TEAL code with replacements\n   * @example\n   * ```typescript\n   * const tealCode = AppManager.replaceTealTemplateParams(tealTemplate, { TMPL_APP_ID: 12345n });\n   * ```\n   */\n  static replaceTealTemplateParams(tealTemplateCode: string, templateParams?: TealTemplateParams) {\n    if (templateParams !== undefined) {\n      for (const key in templateParams) {\n        const value = templateParams[key]\n        const token = `TMPL_${key.replace(/^TMPL_/, '')}`\n\n        // If this is a number, first replace any byte representations of the number\n        // These may appear in the TEAL in order to circumvent int compression and preserve PC values\n        if (typeof value === 'number' || typeof value === 'bigint') {\n          tealTemplateCode = tealTemplateCode.replace(new RegExp(`(?<=bytes )${token}`, 'g'), `0x${value.toString(16).padStart(16, '0')}`)\n\n          // We could probably return here since mixing pushint and pushbytes is likely not going to happen, but might as well do both\n        }\n\n        tealTemplateCode = replaceTemplateVariable(\n          tealTemplateCode,\n          token,\n          typeof value === 'string'\n            ? `0x${Buffer.from(value, 'utf-8').toString('hex')}`\n            : ArrayBuffer.isView(value)\n              ? `0x${Buffer.from(value).toString('hex')}`\n              : value.toString(),\n        )\n      }\n    }\n\n    return tealTemplateCode\n  }\n\n  /**\n   * Remove comments from TEAL code (useful to reduce code size before compilation).\n   *\n   * @param tealCode The TEAL logic to strip\n   * @returns The TEAL without comments\n   * @example\n   * ```typescript\n   * const stripped = AppManager.stripTealComments(tealProgram);\n   * ```\n   */\n  static stripTealComments(tealCode: string) {\n    const stripCommentFromLine = (line: string) => {\n      const commentIndex = findUnquotedString(line, '//')\n      if (commentIndex === undefined) {\n        return line\n      }\n      return line.slice(0, commentIndex).trimEnd()\n    }\n\n    return tealCode\n      .split('\\n')\n      .map((line) => stripCommentFromLine(line))\n      .join('\\n')\n  }\n}\n\n/**\n * Find the first string within a line of TEAL. Only matches outside of quotes and base64 are returned.\n * Returns undefined if not found\n */\nconst findUnquotedString = (line: string, token: string, startIndex: number = 0, _endIndex?: number): number | undefined => {\n  const endIndex = _endIndex === undefined ? line.length : _endIndex\n  let index = startIndex\n  let inQuotes = false\n  let inBase64 = false\n\n  while (index < endIndex) {\n    const currentChar = line[index]\n    if ((currentChar === ' ' || currentChar === '(') && !inQuotes && lastTokenBase64(line, index)) {\n      // enter base64\n      inBase64 = true\n    } else if ((currentChar === ' ' || currentChar === ')') && !inQuotes && inBase64) {\n      // exit base64\n      inBase64 = false\n    } else if (currentChar === '\\\\' && inQuotes) {\n      // escaped char, skip next character\n      index += 1\n    } else if (currentChar === '\"') {\n      // quote boundary\n      inQuotes = !inQuotes\n    } else if (!inQuotes && !inBase64 && line.startsWith(token, index)) {\n      // can test for match\n      return index\n    }\n    index += 1\n  }\n  return undefined\n}\n\nconst lastTokenBase64 = (line: string, index: number): boolean => {\n  try {\n    const tokens = line.slice(0, index).split(/\\s+/)\n    const last = tokens[tokens.length - 1]\n    return ['base64', 'b64'].includes(last)\n  } catch {\n    return false\n  }\n}\n\nfunction replaceTemplateVariable(program: string, token: string, replacement: string): string {\n  const result: string[] = []\n  const tokenIndexOffset = replacement.length - token.length\n\n  const programLines = program.split('\\n')\n\n  for (const line of programLines) {\n    const _commentIndex = findUnquotedString(line, '//')\n    const commentIndex = _commentIndex === undefined ? line.length : _commentIndex\n    let code = line.substring(0, commentIndex)\n    const comment = line.substring(commentIndex)\n    let trailingIndex = 0\n\n    while (true) {\n      const tokenIndex = findTemplateToken(code, token, trailingIndex)\n      if (tokenIndex === undefined) {\n        break\n      }\n      trailingIndex = tokenIndex + token.length\n      const prefix = code.substring(0, tokenIndex)\n      const suffix = code.substring(trailingIndex)\n      code = `${prefix}${replacement}${suffix}`\n      trailingIndex += tokenIndexOffset\n    }\n    result.push(code + comment)\n  }\n\n  return result.join('\\n')\n}\n\nconst findTemplateToken = (line: string, token: string, startIndex: number = 0, _endIndex?: number): number | undefined => {\n  const endIndex = _endIndex === undefined ? line.length : _endIndex\n\n  let index = startIndex\n  while (index < endIndex) {\n    const tokenIndex = findUnquotedString(line, token, index, endIndex)\n    if (tokenIndex === undefined) {\n      break\n    }\n    const trailingIndex = tokenIndex + token.length\n    if (\n      (tokenIndex === 0 || !isValidTokenCharacter(line[tokenIndex - 1])) &&\n      (trailingIndex >= line.length || !isValidTokenCharacter(line[trailingIndex]))\n    ) {\n      return tokenIndex\n    }\n    index = trailingIndex\n  }\n  return undefined\n}\n\nfunction isValidTokenCharacter(char: string): boolean {\n  return char.length === 1 && (/\\w/.test(char) || char === '_')\n}\n"],"mappings":";;;;;AAyI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