{"version":3,"file":"app-deployer.mjs","names":["indexer.lookupAccountCreatedApplicationByAddress","indexer.searchTransactions"],"sources":["../../src/types/app-deployer.ts"],"sourcesContent":["import algosdk, { Address } from 'algosdk'\nimport { Config } from '../config'\nimport * as indexer from '../indexer-lookup'\nimport { calculateExtraProgramPages } from '../util'\nimport { AlgorandClientTransactionSender } from './algorand-client-transaction-sender'\nimport {\n  APP_DEPLOY_NOTE_DAPP,\n  OnSchemaBreak,\n  OnUpdate,\n  type ABIReturn,\n  type AppDeployMetadata,\n  type SendAppCreateTransactionResult,\n  type SendAppUpdateTransactionResult,\n  type TealTemplateParams,\n} from './app'\nimport { AppManager } from './app-manager'\nimport {\n  AppCreateMethodCall,\n  AppCreateParams,\n  AppDeleteMethodCall,\n  AppDeleteParams,\n  AppUpdateMethodCall,\n  AppUpdateParams,\n  TransactionComposer,\n} from './composer'\nimport { Expand } from './expand'\nimport { ConfirmedTransactionResult, SendParams } from './transaction'\n\n/** Params to specify an update transaction for an app deployment */\nexport type DeployAppUpdateParams = Expand<Omit<AppUpdateParams, 'appId' | 'approvalProgram' | 'clearStateProgram'>>\n/** Params to specify an update method call for an app deployment */\nexport type DeployAppUpdateMethodCall = Expand<Omit<AppUpdateMethodCall, 'appId' | 'approvalProgram' | 'clearStateProgram'>>\n/** Params to specify a transaction for an app deployment */\nexport type DeployAppDeleteParams = Expand<Omit<AppDeleteParams, 'appId'>>\n/** Params to specify a delete method call for an app deployment */\nexport type DeployAppDeleteMethodCall = Expand<Omit<AppDeleteMethodCall, 'appId'>>\n\n/** The parameters to idempotently deploy an app */\nexport type AppDeployParams = Expand<\n  SendParams & {\n    /** The deployment metadata */\n    metadata: AppDeployMetadata\n    /** Any deploy-time parameters to replace in the TEAL code before compiling it (used if teal code is passed in as a string) */\n    deployTimeParams?: TealTemplateParams\n    /** What action to perform if a schema break (storage schema or extra pages change) is detected:\n     *\n     * * `fail` - Fail the deployment (throw an error, **default**)\n     * * `replace` - Delete the old app and create a new one\n     * * `append` - Deploy a new app and leave the old one as is\n     */\n    onSchemaBreak?: 'replace' | 'fail' | 'append' | OnSchemaBreak\n    /** What action to perform if a TEAL code update is detected:\n     *\n     * * `fail` - Fail the deployment (throw an error, **default**)\n     * * `update` - Update the app with the new TEAL code\n     * * `replace` - Delete the old app and create a new one\n     * * `append` - Deploy a new app and leave the old one as is\n     */\n    onUpdate?: 'update' | 'replace' | 'fail' | 'append' | OnUpdate\n    /** Create transaction parameters to use if a create needs to be issued as part of deployment */\n    createParams: AppCreateParams | AppCreateMethodCall\n    /** Update transaction parameters to use if an update needs to be issued as part of deployment */\n    updateParams: DeployAppUpdateParams | DeployAppUpdateMethodCall\n    /** Delete transaction parameters to use if a delete needs to be issued as part of deployment */\n    deleteParams: DeployAppDeleteParams | DeployAppDeleteMethodCall\n    /** Optional cached value of the existing apps for the given creator; use this to avoid an indexer lookup */\n    existingDeployments?: AppLookup\n    /** Whether or not to ignore the app metadata cache and force a lookup, default: use the cache **/\n    ignoreCache?: boolean\n  }\n>\n\n/** The metadata that can be collected about a deployed app */\nexport interface AppMetadata extends AppDeployMetadata {\n  /** The id of the app */\n  appId: bigint\n  /** The Algorand address of the account associated with the app */\n  appAddress: Address\n  /** The round the app was created */\n  createdRound: bigint\n  /** The last round that the app was updated */\n  updatedRound: bigint\n  /** The metadata when the app was created */\n  createdMetadata: AppDeployMetadata\n  /** Whether or not the app is deleted */\n  deleted: boolean\n}\n\n/** A lookup of name -> Algorand app for a creator */\nexport interface AppLookup {\n  /** The address of the creator associated with this lookup */\n  creator: Readonly<Address>\n  /** A hash map of app name to app metadata */\n  apps: {\n    [name: string]: AppMetadata\n  }\n}\n\nexport type AppDeployResult =\n  | Expand<{ operationPerformed: 'create' } & Omit<AppMetadata, 'appId' | 'appAddress'> & SendAppCreateTransactionResult>\n  | Expand<{ operationPerformed: 'update' } & AppMetadata & SendAppUpdateTransactionResult>\n  | Expand<\n      { operationPerformed: 'replace' } & Omit<AppMetadata, 'appId' | 'appAddress'> &\n        SendAppCreateTransactionResult & {\n          deleteReturn?: ABIReturn\n          deleteResult: ConfirmedTransactionResult\n        }\n    >\n  | Expand<{ operationPerformed: 'nothing' } & AppMetadata>\n\n/** Allows management of deployment and deployment metadata of applications. */\nexport class AppDeployer {\n  private _appManager: AppManager\n  private _transactionSender: AlgorandClientTransactionSender\n  private _indexer?: algosdk.Indexer\n  private _appLookups = new Map<string, AppLookup>()\n\n  /**\n   * Creates an `AppManager`\n   * @param appManager An `AppManager` instance\n   * @param transactionSender An `AlgorandClientTransactionSender` instance\n   * @param indexer An optional indexer instance; supply if you want to indexer to look up app metadata\n   * @example\n   * ```ts\n   * const deployer = new AppDeployer(appManager, transactionSender, indexer)\n   * ```\n   */\n  constructor(appManager: AppManager, transactionSender: AlgorandClientTransactionSender, indexer?: algosdk.Indexer) {\n    this._appManager = appManager\n    this._transactionSender = transactionSender\n    this._indexer = indexer\n  }\n\n  /**\n   * Idempotently deploy (create if not exists, update if changed) an app against the given name for the given creator account, including deploy-time TEAL template placeholder substitutions (if specified).\n   *\n   * To understand the architecture decisions behind this functionality please see https://github.com/algorandfoundation/algokit-cli/blob/main/docs/src/content/docs/architecture-decisions/2023-01-12_smart-contract-deployment.md\n   *\n   * **Note:** When using the return from this function be sure to check `operationPerformed` to get access to various return properties like `transaction`, `confirmation` and `deleteResult`.\n   *\n   * **Note:** if there is a breaking state schema change to an existing app (and `onSchemaBreak` is set to `'replace'`) the existing app will be deleted and re-created.\n   *\n   * **Note:** if there is an update (different TEAL code) to an existing app (and `onUpdate` is set to `'replace'`) the existing app will be deleted and re-created.\n   * @param deployment The arguments to control the app deployment\n   * @returns The result of the deployment\n   * @example\n   * ```ts\n   * const deployResult = await deployer.deploy({\n   *   createParams: {\n   *     sender: 'SENDER_ADDRESS',\n   *     approvalProgram: 'APPROVAL PROGRAM',\n   *     clearStateProgram: 'CLEAR PROGRAM',\n   *     schema: {\n   *       globalByteSlices: 0,\n   *       globalInts: 0,\n   *       localByteSlices: 0,\n   *       localInts: 0\n   *     }\n   *   },\n   *   updateParams: {\n   *     sender: 'SENDER_ADDRESS'\n   *   },\n   *   deleteParams: {\n   *     sender: 'SENDER_ADDRESS'\n   *   },\n   *   metadata: { name: 'my_app', version: '2.0', updatable: false, deletable: false },\n   *   onSchemaBreak: 'append',\n   *   onUpdate: 'append'\n   *  })\n   * ```\n   */\n  async deploy(deployment: AppDeployParams): Promise<AppDeployResult> {\n    const {\n      metadata,\n      deployTimeParams,\n      onSchemaBreak,\n      onUpdate,\n      createParams,\n      updateParams,\n      deleteParams,\n      existingDeployments,\n      ignoreCache,\n      ...sendParams\n    } = deployment\n\n    // Set creation note\n\n    createParams.note = updateParams.note = TransactionComposer.arc2Note({\n      dAppName: APP_DEPLOY_NOTE_DAPP,\n      data: metadata,\n      format: 'j',\n    })\n\n    // Check for required fields\n\n    if (existingDeployments && existingDeployments.creator.toString() !== createParams.sender.toString()) {\n      throw new Error(\n        `Received invalid existingDeployments value for creator ${existingDeployments.creator} when attempting to deploy for creator ${createParams.sender}`,\n      )\n    }\n    if (!existingDeployments && !this._indexer) {\n      throw new Error(\n        `Didn't receive an indexer client when this AppManager was created, but also didn't receive an existingDeployments cache - one of them must be provided`,\n      )\n    }\n\n    Config.getLogger(sendParams?.suppressLog).info(\n      `Idempotently deploying app \"${metadata.name}\" from creator ${createParams.sender} using ${createParams.approvalProgram.length} bytes of ${typeof createParams.approvalProgram === 'string' ? 'teal code' : 'AVM bytecode'} and ${createParams.clearStateProgram.length} bytes of ${typeof createParams.approvalProgram === 'string' ? 'teal code' : 'AVM bytecode'}`,\n    )\n\n    // Compile code if required\n\n    const compiledApproval =\n      typeof createParams.approvalProgram === 'string'\n        ? await this._appManager.compileTealTemplate(createParams.approvalProgram, deployTimeParams, metadata)\n        : undefined\n    const approvalProgram = compiledApproval ? compiledApproval.compiledBase64ToBytes : createParams.approvalProgram\n\n    const compiledClear =\n      typeof createParams.clearStateProgram === 'string'\n        ? await this._appManager.compileTealTemplate(createParams.clearStateProgram, deployTimeParams)\n        : undefined\n    const clearStateProgram = compiledClear ? compiledClear.compiledBase64ToBytes : createParams.clearStateProgram\n\n    // Define routines for create, update, and replace\n\n    const createApp = async () => {\n      const result = await ('method' in createParams\n        ? this._transactionSender.appCreateMethodCall({ ...createParams, approvalProgram, clearStateProgram, ...sendParams })\n        : this._transactionSender.appCreate({ ...createParams, approvalProgram, clearStateProgram, ...sendParams }))\n      const appMetadata: AppMetadata = {\n        appId: result.appId,\n        appAddress: result.appAddress,\n        ...metadata,\n        createdMetadata: metadata,\n        createdRound: BigInt(result.confirmation.confirmedRound!),\n        updatedRound: BigInt(result.confirmation.confirmedRound!),\n        deleted: false,\n      }\n      this.updateAppLookup(createParams.sender, appMetadata)\n      return {\n        operationPerformed: 'create',\n        compiledApproval,\n        compiledClear,\n        ...result,\n        ...appMetadata,\n      } satisfies SendAppCreateTransactionResult & AppMetadata & { operationPerformed: 'create' }\n    }\n    const updateApp = async (existingApp: AppMetadata) => {\n      Config.getLogger(sendParams?.suppressLog).info(\n        `Updating existing ${metadata.name} app for ${createParams.sender} to version ${metadata.version}.`,\n      )\n      const result = await ('method' in updateParams\n        ? this._transactionSender.appUpdateMethodCall({\n            appId: existingApp.appId,\n            approvalProgram,\n            clearStateProgram,\n            ...updateParams,\n            ...sendParams,\n          })\n        : this._transactionSender.appUpdate({\n            appId: existingApp.appId,\n            approvalProgram,\n            clearStateProgram,\n            ...updateParams,\n            ...sendParams,\n          }))\n      const appMetadata: AppMetadata = {\n        appId: existingApp.appId,\n        appAddress: existingApp.appAddress,\n        createdMetadata: existingApp.createdMetadata,\n        createdRound: existingApp.createdRound,\n        updatedRound: BigInt(result.confirmation.confirmedRound!),\n        ...metadata,\n        deleted: false,\n      }\n      this.updateAppLookup(createParams.sender, appMetadata)\n      return {\n        operationPerformed: 'update',\n        compiledApproval,\n        compiledClear,\n        ...result,\n        ...appMetadata,\n      } satisfies SendAppUpdateTransactionResult & AppMetadata & { operationPerformed: 'update' }\n    }\n    const replaceApp = async (existingApp: AppMetadata) => {\n      Config.getLogger(sendParams?.suppressLog).info(\n        `Deploying a new ${metadata.name} app for ${createParams.sender}; deploying app with version ${metadata.version}.`,\n      )\n\n      Config.getLogger(sendParams?.suppressLog).warn(\n        `Deleting existing ${metadata.name} app with id ${existingApp.appId} from ${deleteParams.sender} account.`,\n      )\n\n      const composer = this._transactionSender.newGroup()\n      if ('method' in createParams) {\n        composer.addAppCreateMethodCall({ ...createParams, approvalProgram, clearStateProgram })\n      } else {\n        composer.addAppCreate({ ...createParams, approvalProgram, clearStateProgram })\n      }\n      const createIndex = await composer.count()\n      if ('method' in deleteParams) {\n        composer.addAppDeleteMethodCall({ appId: existingApp.appId, ...deleteParams })\n      } else {\n        composer.addAppDelete({ appId: existingApp.appId, ...deleteParams })\n      }\n      const result = await composer.send({ ...sendParams })\n      const confirmation = result.confirmations.at(createIndex - 1)!\n      const transaction = result.transactions.at(createIndex - 1)!\n      const deleteTransaction = result.transactions.at(-1)!\n\n      Config.getLogger(sendParams?.suppressLog).warn(\n        `Sent transactions ${transaction.txID()} to create app with id ${confirmation.applicationIndex} and ${deleteTransaction.txID()} to delete app with id ${\n          existingApp.appId\n        } from ${createParams.sender} account.`,\n      )\n\n      const appMetadata: AppMetadata = {\n        appId: BigInt(confirmation.applicationIndex!),\n        appAddress: algosdk.getApplicationAddress(confirmation.applicationIndex!),\n        ...metadata,\n        createdMetadata: metadata,\n        createdRound: BigInt(confirmation.confirmedRound!),\n        updatedRound: BigInt(confirmation.confirmedRound!),\n        deleted: false,\n      }\n      this.updateAppLookup(createParams.sender, appMetadata)\n\n      return {\n        operationPerformed: 'replace',\n        ...result,\n        compiledApproval,\n        compiledClear,\n        transaction,\n        confirmation,\n        return: 'method' in createParams ? result.returns?.[0] : undefined,\n        deleteReturn: 'method' in deleteParams ? result.returns?.at(-1) : undefined,\n        ...appMetadata,\n        deleteResult: { transaction: deleteTransaction, confirmation: result.confirmations.at(-1)! },\n      } satisfies { operationPerformed: 'replace' } & AppMetadata &\n        SendAppCreateTransactionResult & {\n          deleteReturn?: ABIReturn\n          deleteResult: ConfirmedTransactionResult\n        }\n    }\n\n    // Lookup existing app metadata\n\n    const apps = existingDeployments ?? (await this.getCreatorAppsByName(createParams.sender, ignoreCache))\n\n    const existingApp = apps.apps[metadata.name]\n    if (!existingApp || existingApp.deleted) {\n      Config.getLogger(sendParams?.suppressLog).info(\n        `App ${metadata.name} not found in apps created by ${createParams.sender}; deploying app with version ${metadata.version}.`,\n      )\n\n      return await createApp()\n    }\n\n    Config.getLogger(sendParams?.suppressLog).info(\n      `Existing app ${metadata.name} found by creator ${createParams.sender}, with app id ${existingApp.appId} and version ${existingApp.version}.`,\n    )\n\n    const existingAppRecord = await this._appManager.getById(existingApp.appId)\n    const existingApproval = Buffer.from(existingAppRecord.approvalProgram).toString('base64')\n    const existingClear = Buffer.from(existingAppRecord.clearStateProgram).toString('base64')\n    const extraPages = existingAppRecord.extraProgramPages ?? 0\n\n    const newApprovalBytes = Buffer.from(approvalProgram)\n    const newClearBytes = Buffer.from(clearStateProgram)\n    const newApproval = newApprovalBytes.toString('base64')\n    const newClear = newClearBytes.toString('base64')\n    const newExtraPages = calculateExtraProgramPages(newApprovalBytes, newClearBytes)\n\n    // Check for changes\n\n    const isUpdate = newApproval !== existingApproval || newClear !== existingClear\n    const isSchemaBreak =\n      existingAppRecord.localInts < (createParams.schema?.localInts ?? 0) ||\n      existingAppRecord.globalInts < (createParams.schema?.globalInts ?? 0) ||\n      existingAppRecord.localByteSlices < (createParams.schema?.localByteSlices ?? 0) ||\n      existingAppRecord.globalByteSlices < (createParams.schema?.globalByteSlices ?? 0) ||\n      extraPages < newExtraPages\n\n    if (isSchemaBreak) {\n      Config.getLogger(sendParams?.suppressLog).warn(`Detected a breaking app schema change in app ${existingApp.appId}:`, {\n        from: {\n          globalInts: existingAppRecord.globalInts,\n          globalByteSlices: existingAppRecord.globalByteSlices,\n          localInts: existingAppRecord.localInts,\n          localByteSlices: existingAppRecord.localByteSlices,\n          extraProgramPages: extraPages,\n        },\n        to: { ...createParams.schema, extraProgramPages: newExtraPages },\n      })\n\n      if (onSchemaBreak === undefined || onSchemaBreak === 'fail' || onSchemaBreak === OnSchemaBreak.Fail) {\n        throw new Error(\n          'Schema break detected and onSchemaBreak=OnSchemaBreak.Fail, stopping deployment. ' +\n            'If you want to try deleting and recreating the app then ' +\n            're-run with onSchemaBreak=OnSchemaBreak.ReplaceApp',\n        )\n      }\n\n      if (onSchemaBreak === 'append' || onSchemaBreak === OnSchemaBreak.AppendApp) {\n        Config.getLogger(sendParams?.suppressLog).info('onSchemaBreak=AppendApp, will attempt to create a new app')\n        return await createApp()\n      }\n\n      if (existingApp.deletable) {\n        Config.getLogger(sendParams?.suppressLog).info(\n          'App is deletable and onSchemaBreak=ReplaceApp, will attempt to create new app and delete old app',\n        )\n      } else {\n        Config.getLogger(sendParams?.suppressLog).info(\n          'App is not deletable but onSchemaBreak=ReplaceApp, will attempt to delete app, delete will most likely fail',\n        )\n      }\n\n      return await replaceApp(existingApp)\n    }\n\n    if (isUpdate) {\n      Config.getLogger(sendParams?.suppressLog).info(\n        `Detected a TEAL update in app ${existingApp.appId} for creator ${createParams.sender}`,\n      )\n\n      if (onUpdate === undefined || onUpdate === 'fail' || onUpdate === OnUpdate.Fail) {\n        throw new Error('Update detected and onUpdate=Fail, stopping deployment. Try a different onUpdate value to not fail.')\n      }\n\n      if (onUpdate === 'append' || onUpdate === OnUpdate.AppendApp) {\n        Config.getLogger(sendParams?.suppressLog).info('onUpdate=AppendApp, will attempt to create a new app')\n        return await createApp()\n      }\n\n      if (onUpdate === 'update' || onUpdate === OnUpdate.UpdateApp) {\n        if (existingApp.updatable) {\n          Config.getLogger(sendParams?.suppressLog).info(`App is updatable and onUpdate=UpdateApp, updating app...`)\n        } else {\n          Config.getLogger(sendParams?.suppressLog).warn(\n            `App is not updatable but onUpdate=UpdateApp, will attempt to update app, update will most likely fail`,\n          )\n        }\n\n        return await updateApp(existingApp)\n      }\n\n      if (onUpdate === 'replace' || onUpdate === OnUpdate.ReplaceApp) {\n        if (existingApp.deletable) {\n          Config.getLogger(sendParams?.suppressLog).warn(\n            'App is deletable and onUpdate=ReplaceApp, creating new app and deleting old app...',\n          )\n        } else {\n          Config.getLogger(sendParams?.suppressLog).warn(\n            'App is not deletable and onUpdate=ReplaceApp, will attempt to create new app and delete old app, delete will most likely fail',\n          )\n        }\n\n        return await replaceApp(existingApp)\n      }\n    }\n\n    Config.getLogger(sendParams?.suppressLog).debug('No detected changes in app, nothing to do.')\n\n    return { ...existingApp, operationPerformed: 'nothing' }\n  }\n\n  private updateAppLookup(sender: string | Address, appMetadata: AppMetadata) {\n    const s = typeof sender === 'string' ? sender : sender.toString()\n    const lookup = this._appLookups.get(s)\n    if (!lookup) {\n      this._appLookups.set(s, { creator: Address.fromString(s), apps: { [appMetadata.name]: appMetadata } })\n    } else {\n      lookup.apps[appMetadata.name] = appMetadata\n    }\n  }\n\n  /**\n   * Returns a lookup of name => app metadata (id, address, ...metadata) for all apps created by the given account that have\n   * an [ARC-2](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0002.md) `AppDeployNote` as the transaction\n   * note of the app creation transaction.\n   *\n   * This function caches the result for the given creator account so that subsequent calls will not require an indexer lookup.\n   *\n   * If the `AppManager` instance wasn't created with an indexer client, this function will throw an error.\n   *\n   * @param creatorAddress The address of the account that is the creator of the apps you want to search for\n   * @param ignoreCache Whether or not to ignore the cache and force a lookup, default: use the cache\n   * @returns A name-based lookup of the app metadata\n   * @example\n   * ```ts\n   * const result = await deployer.getCreatorAppsByName(creator)\n   */\n  async getCreatorAppsByName(creatorAddress: string | Address, ignoreCache?: boolean): Promise<AppLookup> {\n    const appLookup: Record<string, AppMetadata> = {}\n\n    const address = typeof creatorAddress === 'string' ? creatorAddress : creatorAddress.toString()\n    if (!ignoreCache && this._appLookups.has(address)) {\n      return this._appLookups.get(address)!\n    }\n\n    if (!this._indexer) {\n      throw new Error(`Didn't receive an indexer client when this AppManager was created, but received a call to getCreatorApps`)\n    }\n\n    // Extract all apps that account created\n    const createdApps = (await indexer.lookupAccountCreatedApplicationByAddress(this._indexer, creatorAddress))\n      .map((a) => {\n        return { id: a.id, createdAtRound: a.createdAtRound!, deleted: a.deleted }\n      })\n      .sort((a, b) => Number(a.createdAtRound - b.createdAtRound))\n\n    // For each app that account created (in parallel)...\n    const apps = await Promise.all(\n      createdApps.map(async (createdApp) => {\n        // Find any app transactions for that app in the round it was created (should always just be a single creation transaction)\n        const appTransactions = await indexer.searchTransactions(this._indexer!, (s) =>\n          s\n            .minRound(createdApp.createdAtRound)\n            .txType(algosdk.TransactionType.appl)\n            .applicationID(Number(createdApp.id))\n            .address(creatorAddress)\n            .addressRole('sender')\n            .notePrefix(Buffer.from(APP_DEPLOY_NOTE_DAPP).toString('base64')),\n        )\n\n        // Triple check the transaction is intact by filtering for the one we want:\n        //  * application-id is 0 when the app is first created\n        //  * also verify the sender to prevent a potential security risk\n        const appCreationTransaction = appTransactions.transactions.filter(\n          (t) => t.applicationTransaction?.applicationId === 0n && t.sender.toString() === creatorAddress.toString(),\n        )[0]\n\n        const latestAppUpdateTransaction = appTransactions.transactions\n          .filter((t) => t.sender.toString() === creatorAddress.toString())\n          .sort((a, b) =>\n            a.confirmedRound === b.confirmedRound\n              ? (b.intraRoundOffset! - a.intraRoundOffset!) / 10\n              : Number(b.confirmedRound! - a.confirmedRound!),\n          )[0]\n\n        if (!appCreationTransaction?.note)\n          // No note; ignoring\n          return null\n\n        return { createdApp, appCreationTransaction, latestAppUpdateTransaction }\n      }),\n    )\n\n    apps\n      .filter((a) => a !== null)\n      .forEach((a) => {\n        const { createdApp, appCreationTransaction, latestAppUpdateTransaction } = a!\n\n        const parseNote = (note?: string) => {\n          if (!note) {\n            // No note; ignoring...\n            return\n          }\n\n          if (!note.startsWith(`${APP_DEPLOY_NOTE_DAPP}:j{`))\n            // Clearly not APP_DEPLOY JSON; ignoring...\n            return\n\n          return JSON.parse(note.substring(APP_DEPLOY_NOTE_DAPP.length + 2)) as AppDeployMetadata\n        }\n\n        try {\n          const creationNote = parseNote(\n            appCreationTransaction.note ? Buffer.from(appCreationTransaction.note).toString('utf-8') : undefined,\n          )\n          const updateNote = parseNote(\n            latestAppUpdateTransaction.note ? Buffer.from(latestAppUpdateTransaction.note).toString('utf-8') : undefined,\n          )\n          if (creationNote?.name) {\n            appLookup[creationNote.name] = {\n              appId: createdApp.id,\n              appAddress: algosdk.getApplicationAddress(createdApp.id),\n              createdMetadata: creationNote,\n              createdRound: appCreationTransaction.confirmedRound ?? 0n,\n              ...(updateNote ?? creationNote),\n              updatedRound: latestAppUpdateTransaction?.confirmedRound ?? 0n,\n              deleted: createdApp.deleted ?? false,\n            }\n          }\n        } catch (e) {\n          Config.logger.warn(\n            `Received error trying to retrieve app with ${createdApp.id} for creator ${creatorAddress}; failing silently`,\n            e,\n          )\n          return\n        }\n      })\n\n    const lookup = {\n      creator: typeof creatorAddress === 'string' ? Address.fromString(creatorAddress) : creatorAddress,\n      apps: appLookup,\n    }\n\n    this._appLookups.set(creatorAddress.toString(), lookup)\n\n    return lookup\n  }\n}\n"],"mappings":";;;;;;;;AA+GA,IAAa,cAAb,MAAyB;CACvB;CACA;CACA;CACA,8BAAsB,IAAI,IAAuB;;;;;;;;;;;CAYjD,YAAY,YAAwB,mBAAoD,SAA2B;EACjH,KAAK,cAAc;EACnB,KAAK,qBAAqB;EAC1B,KAAK,WAAW;CAClB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwCA,MAAM,OAAO,YAAuD;EAClE,MAAM,EACJ,UACA,kBACA,eACA,UACA,cACA,cACA,cACA,qBACA,aACA,GAAG,eACD;EAIJ,aAAa,OAAO,aAAa,OAAO,oBAAoB,SAAS;GACnE,UAAU;GACV,MAAM;GACN,QAAQ;EACV,CAAC;EAID,IAAI,uBAAuB,oBAAoB,QAAQ,SAAS,MAAM,aAAa,OAAO,SAAS,GACjG,MAAM,IAAI,MACR,0D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