{"version":3,"sources":["../src/types/metaAg.ts","../src/constants/_7k.ts","../src/features/metaAg/error.ts"],"sourcesContent":["import type {\n  QuoteResponse,\n  SourceDex,\n} from \"@bluefin-exchange/bluefin7k-aggregator-sdk\";\nimport type {\n  PreSwapLpChangeParams,\n  RouterDataV3,\n} from \"@cetusprotocol/aggregator-sdk\";\nimport type { AggregatorQuoter, Protocol } from \"@flowx-finance/sdk\";\nimport type { GasCostSummary } from \"@mysten/sui/client\";\nimport { SignatureWithBytes } from \"@mysten/sui/cryptography\";\nimport type {\n  Transaction,\n  TransactionObjectArgument,\n} from \"@mysten/sui/transactions\";\nimport { OkxSwapResponseData } from \"./okx\";\n\nexport enum EProvider {\n  BLUEFIN7K = \"bluefin7k\",\n  CETUS = \"cetus\",\n  FLOWX = \"flowx\",\n  OKX = \"okx\",\n}\ntype ProviderBaseOptions = {\n  api?: string;\n  apiKey?: string;\n  disabled?: boolean;\n};\nexport type Bluefin7kProviderOptions = ProviderBaseOptions & {\n  sources?: SourceDex[];\n  excludedPools?: string[];\n  targetPools?: string[];\n};\nexport type FlowxProviderOptions = ProviderBaseOptions & {\n  sources?: Protocol[];\n  excludePools?: string[];\n  excludeSources?: Protocol[];\n  maxHops?: number;\n  splitDistributionPercent?: number;\n};\nexport type CetusProviderOptions = ProviderBaseOptions & {\n  sources?: string[];\n  splitCount?: number;\n  splitAlgorithm?: string;\n  splitFactor?: number;\n  depth?: number;\n  liquidityChanges?: PreSwapLpChangeParams[];\n};\nexport type OkxProviderOptions = Required<Omit<ProviderBaseOptions, \"api\">> & {\n  api?: string;\n  secretKey: string;\n  apiPassphrase: string;\n  projectId: string;\n};\nexport interface MetaAgOptions {\n  /**If not specified, all providers will be used */\n  providers?: {\n    [EProvider.BLUEFIN7K]?: Bluefin7kProviderOptions;\n    [EProvider.FLOWX]?: FlowxProviderOptions;\n    [EProvider.CETUS]?: CetusProviderOptions;\n    [EProvider.OKX]?: OkxProviderOptions;\n  };\n  /**Mainnet Json Rpc url, if not specified, the default mainnet url will be used */\n  fullnodeUrl?: string;\n  /**Hermes Api url, if not specified, the default hermes api url will be used */\n  hermesApi?: string;\n  /**Address to receive commission, if not specified, the commission will not be used */\n  partner?: string;\n  /**@default 0 */\n  partnerCommissionBps?: number;\n  /**@default 100 */\n  slippageBps?: number;\n  /**\n   * Tip to support 7k\n   * @default 0 */\n  tipBps?: number;\n}\nexport interface MetaQuoteOptions {\n  coinTypeIn: string;\n  coinTypeOut: string;\n  amountIn: string;\n  /** Required for api-tx providers (ie: Okx) */\n  signer?: string;\n  /**\n   * Timeout for quote operation in milliseconds\n   * @default 2000ms\n   */\n  timeout?: number;\n}\nexport interface MetaSimulationOptions {\n  sender: string;\n  /**\n   * Timeout for simulation operation in milliseconds\n   * @default 2000ms\n   */\n  timeout?: number;\n  /** If specify, defer the simulation that could reduce the time to display quote result, you must update the quote via the id on callback\n   * else await all quote and simulation before return\n   */\n  onSimulated?: (payload: MetaQuote) => void;\n}\nexport interface MetaFastSwapOptions {\n  /** Quote object from the quote operation */\n  quote: MetaQuote;\n  /** Signer address (owner of `coinIn`) */\n  signer: string;\n  /** If true, use the gas coin for the swap\n   * @default true */\n  useGasCoin?: boolean;\n  /**\n   * Sign the transaction bytes\n   * @param txBytes - base64 transaction bytes\n   * @returns - signature with bytes\n   */\n  signTransaction: (txBytes: string) => Promise<SignatureWithBytes>;\n}\nexport interface MetaSwapOptions {\n  /** Quote object from the quote operation */\n  quote: MetaQuote;\n  /** Signer address (owner of `coinIn`) */\n  signer: string;\n  /** Transaction object to add the swap operation */\n  tx: Transaction;\n  /**\n   * Coin object used for the swap, must be consumed completely, no `coinIn` left, user must pass the coinIn object with the balance required for the swap - ie in quote `amountIn`\n   * @warning `coinIn` value must match the quote `amountIn` */\n  coinIn: TransactionObjectArgument;\n}\n\nexport type FlowxQuoteResponse = Awaited<\n  ReturnType<AggregatorQuoter[\"getRoutes\"]>\n>;\nexport type MetaQuote = (\n  | {\n      provider: EProvider.BLUEFIN7K;\n      quote: QuoteResponse;\n    }\n  | {\n      provider: EProvider.CETUS;\n      quote: RouterDataV3;\n    }\n  | {\n      provider: EProvider.FLOWX;\n      quote: FlowxQuoteResponse;\n    }\n  | {\n      provider: EProvider.OKX;\n      quote: OkxSwapResponseData;\n    }\n) & {\n  /** uuid to keep track the quote result, used to apply simulation result on quote on callback `onSimulated`*/\n  id: string;\n  /** coin type: ie 0x2::sui::SUI */\n  coinTypeIn: string;\n  /** coin type: ie 0x2::sui::SUI */\n  coinTypeOut: string;\n  /** Amount in as u64 */\n  amountIn: string;\n  /** Amount out as u64 if there're no commission be applied to the amount out */\n  rawAmountOut: string;\n  /** Amount as u64 after minus any commission kind */\n  amountOut: string;\n  /** Simulated amount out if the transaction is executed */\n  simulatedAmountOut?: string;\n  /** Estimate gas consumption if the transaction is executed */\n  gasUsed?: GasCostSummary;\n};\nexport interface QuoteProvider {\n  readonly kind: EProvider;\n  quote(_quoteOptions: MetaQuoteOptions): Promise<MetaQuote | null>;\n}\n\nexport interface SwapAPIProvider extends QuoteProvider {\n  readonly kind: EProvider.OKX;\n  fastSwap(options: MetaFastSwapOptions): Promise<string>;\n}\n\nexport interface AggregatorProvider extends QuoteProvider {\n  readonly kind: EProvider.BLUEFIN7K | EProvider.CETUS | EProvider.FLOWX;\n  swap(options: MetaSwapOptions): Promise<TransactionObjectArgument>;\n}\n\nexport const isAggregatorProvider = (\n  provider: QuoteProvider,\n): provider is AggregatorProvider =>\n  provider.kind === EProvider.BLUEFIN7K ||\n  provider.kind === EProvider.CETUS ||\n  provider.kind === EProvider.FLOWX;\n\nexport const isSwapAPIProvider = (\n  provider: QuoteProvider,\n): provider is SwapAPIProvider => provider.kind === EProvider.OKX;\n","// export const _7K_PACKAGE_ID =\n//   \"0x62412b7268c35f3808336aee57a52836501f40b8ba5d936f8ad275e672befd04\";\n// //legacy V4: \"0xe8f996ea6ff38c557c253d3b93cfe2ebf393816487266786371aa4532a9229f2\";\n// //legacy V3: \"0x7ea6e27ad7af6f3b8671d59df1aaebd7c03dddab893e52a714227b2f4fe91519\";\n// //legacy V2: \"0xa13447019cd982d6bef91cf7b46ad384a52583b1dfc2bdecf31ef0c4bd787a0f\";\n// //legacy V1: \"0xd48e7cdc9e92bec69ce3baa75578010458a0c5b2733d661a84971e8cef6806bc\";\n// export const _7K_CONFIG =\n//   \"0x47442a93f7727d188ba7cb71031170d1786af70013cb7ad5115f3fe877ff0c54\";\n// //legacy v3: \"0x0f8fc23dbcc9362b72c7a4c5aa53fcefa02ebfbb83a812c8c262ccd2c076d9ee\";\n\n// export const _7K_VAULT =\n//   \"0x442ad50389ed5cda6f7a6f5a7ae6361a4c05ef1d9fb2e54fbba5a268d690bfe6\";\n// //legacy v3: \"0x39a3c55742c0e011b6f65548e73cf589e1ae5e82dbfab449ca57f24c3bcd9514\";\nexport const _7K_META_PUBLISHED_AT =\n  \"0x17c0b1f7a6ad73f51268f16b8c06c049eecc2f28a270cdd29c06e3d2dea23302\";\nexport const _7K_META_PACKAGE_ID =\n  \"0x17c0b1f7a6ad73f51268f16b8c06c049eecc2f28a270cdd29c06e3d2dea23302\";\nexport const _7K_META_VAULT =\n  \"0x9a8abd32fe5721307ce3b697cf982ee84e9ffbd58d667a4a199f1683c1a3d23c\";\nexport const _7K_META_CONFIG =\n  \"0xbbb3a51877ed9b492f26f4e2181811cfb2bd70c532f6f7621263d122d5e96b56\";\nexport const _7K_PARTNER_ADDRESS =\n  \"0x93ead46c1e48a9b62e25b6787f2ea6f75caedabb21726f12431acc4381f5f4c5\";\n","import { DevInspectResults } from \"@mysten/sui/client\";\nimport { EProvider, MetaQuote, MetaQuoteOptions } from \"../../types/metaAg\";\n\nexport enum MetaAgErrorCode {\n  UNKNOWN = 1000,\n  TIMEOUT = 1001,\n  PROVIDER_NOT_FOUND = 1002,\n  PROVIDER_NOT_SUPPORTED = 1003,\n  INVALID_QUOTE = 1004,\n  QUOTE_NOT_FOUND = 1005,\n  INVALID_SIGNER_ADDRESS = 1006,\n  PROVIDER_NOT_SUPPORT_SWAP = 1007,\n  SIMULATION_FAILED = 1008,\n  // OKX error\n  OKX_FINALIZE_COMMAND_NOT_FOUND = 1100,\n}\n\nexport type MetaAgErrorDetailsMap = {\n  [MetaAgErrorCode.UNKNOWN]: any;\n  [MetaAgErrorCode.TIMEOUT]: { timeout: number };\n  [MetaAgErrorCode.PROVIDER_NOT_FOUND]: { provider: EProvider };\n  [MetaAgErrorCode.PROVIDER_NOT_SUPPORTED]: { provider: EProvider };\n  [MetaAgErrorCode.INVALID_QUOTE]: {\n    quote: MetaQuote;\n    expectedProvider: EProvider;\n  };\n  [MetaAgErrorCode.QUOTE_NOT_FOUND]: {\n    provider: EProvider;\n    quoteOptions?: MetaQuoteOptions;\n  };\n  [MetaAgErrorCode.INVALID_SIGNER_ADDRESS]: { signer: string };\n  [MetaAgErrorCode.PROVIDER_NOT_SUPPORT_SWAP]: { provider: EProvider };\n  [MetaAgErrorCode.SIMULATION_FAILED]: { error: DevInspectResults[\"error\"] };\n  // OKX error\n  [MetaAgErrorCode.OKX_FINALIZE_COMMAND_NOT_FOUND]: { packageId: string };\n};\n\nexport type MetaAgErrorDetails<T extends MetaAgErrorCode> =\n  T extends keyof MetaAgErrorDetailsMap ? MetaAgErrorDetailsMap[T] : never;\n\nexport class MetaAgError<T extends MetaAgErrorCode> extends Error {\n  code: T;\n  details?: MetaAgErrorDetails<T>;\n  constructor(message: string, code?: T, details?: MetaAgErrorDetails<T>) {\n    super(message);\n    this.name = \"MetaAgError\";\n    this.code = code ?? (MetaAgErrorCode.UNKNOWN as T);\n    this.details = details;\n  }\n\n  static assert<T extends MetaAgErrorCode>(\n    condition: any,\n    message?: string | null,\n    code?: T,\n    details?: MetaAgErrorDetails<T>,\n  ): asserts condition {\n    if (!condition) {\n      throw new MetaAgError(message ?? \"Assertion failed\", code, details);\n    }\n  }\n}\n"],"mappings":"2UAiBO,IAAKA,OACVA,EAAA,UAAY,YACZA,EAAA,MAAQ,QACRA,EAAA,MAAQ,QACRA,EAAA,IAAM,MAJIA,OAAA,IAqKCC,EACXC,GAEAA,EAAS,OAAS,aAClBA,EAAS,OAAS,SAClBA,EAAS,OAAS,QAEPC,EACXD,GACgCA,EAAS,OAAS,MClL7C,IAAME,EACX,qEACWC,EACX,qEACWC,EACX,qEACWC,EACX,qEACWC,EACX,qECkBK,IAAMC,EAAN,MAAMC,UAA+C,KAAM,CAGhE,YAAYC,EAAiBC,EAAUC,EAAiC,CACtE,MAAMF,CAAO,EACb,KAAK,KAAO,cACZ,KAAK,KAAOC,GAAS,IACrB,KAAK,QAAUC,CACjB,CAEA,OAAO,OACLC,EACAH,EACAC,EACAC,EACmB,CACnB,GAAI,CAACC,EACH,MAAM,IAAIJ,EAAYC,GAAW,mBAAoBC,EAAMC,CAAO,CAEtE,CACF","names":["EProvider","isAggregatorProvider","provider","isSwapAPIProvider","_7K_META_PUBLISHED_AT","_7K_META_PACKAGE_ID","_7K_META_VAULT","_7K_META_CONFIG","_7K_PARTNER_ADDRESS","MetaAgError","_MetaAgError","message","code","details","condition"]}