@7kprotocol/sdk-ts 4.0.0 → 5.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +21 -12
  2. package/dist/bluefin7k-63A5CV3A.mjs +2 -0
  3. package/dist/bluefin7k-63A5CV3A.mjs.map +1 -0
  4. package/dist/bluefin7k-MP3A4MG4.js +2 -0
  5. package/dist/bluefin7k-MP3A4MG4.js.map +1 -0
  6. package/dist/cetus-HOKHMQSS.mjs +2 -0
  7. package/dist/cetus-HOKHMQSS.mjs.map +1 -0
  8. package/dist/cetus-MUHFO44Y.js +2 -0
  9. package/dist/cetus-MUHFO44Y.js.map +1 -0
  10. package/dist/chunk-CYI4MM5C.mjs +2 -0
  11. package/dist/chunk-CYI4MM5C.mjs.map +1 -0
  12. package/dist/chunk-E5KM5OVW.js +2 -0
  13. package/dist/chunk-E5KM5OVW.js.map +1 -0
  14. package/dist/flowx-FTPJ3RYF.mjs +2 -0
  15. package/dist/flowx-FTPJ3RYF.mjs.map +1 -0
  16. package/dist/flowx-RRIX3SC4.js +2 -0
  17. package/dist/flowx-RRIX3SC4.js.map +1 -0
  18. package/dist/index.d.mts +44 -6
  19. package/dist/index.d.ts +44 -6
  20. package/dist/index.js +1 -1
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +1 -1
  23. package/dist/index.mjs.map +1 -1
  24. package/package.json +6 -6
  25. package/dist/bluefin7k-I6ZCDWDN.js +0 -2
  26. package/dist/bluefin7k-I6ZCDWDN.js.map +0 -1
  27. package/dist/bluefin7k-TERLUCNL.mjs +0 -2
  28. package/dist/bluefin7k-TERLUCNL.mjs.map +0 -1
  29. package/dist/cetus-AU3OMWOY.mjs +0 -2
  30. package/dist/cetus-AU3OMWOY.mjs.map +0 -1
  31. package/dist/cetus-SIPX6FYL.js +0 -2
  32. package/dist/cetus-SIPX6FYL.js.map +0 -1
  33. package/dist/chunk-ETQEI4QC.mjs +0 -2
  34. package/dist/chunk-ETQEI4QC.mjs.map +0 -1
  35. package/dist/chunk-KVGSSW22.js +0 -2
  36. package/dist/chunk-KVGSSW22.js.map +0 -1
  37. package/dist/flowx-6M54WFWO.js +0 -2
  38. package/dist/flowx-6M54WFWO.js.map +0 -1
  39. package/dist/flowx-OXZZX5FD.mjs +0 -2
  40. package/dist/flowx-OXZZX5FD.mjs.map +0 -1
package/README.md CHANGED
@@ -50,41 +50,50 @@ This package has peer dependencies that are required for core functionality:
50
50
 
51
51
  | Package | Version | Purpose | Required For |
52
52
  | -------------------------- | --------- | ---------------------------- | ------------------ |
53
- | `@mysten/sui` | `^1.44.0` | Sui blockchain interaction | Core functionality |
53
+ | `@mysten/sui` | `^2.17.0` | Sui blockchain interaction | Core functionality |
54
54
  | `@pythnetwork/pyth-sui-js` | `^2.2.0` | Pyth price feeds integration | Price feeds |
55
55
 
56
56
  **Required peer dependencies:**
57
57
 
58
58
  ```bash
59
- npm i @mysten/sui@^1.39.0 @pythnetwork/pyth-sui-js@^2.2.0
59
+ npm i @mysten/sui@^2.17.0 @pythnetwork/pyth-sui-js@^2.2.0
60
60
  ```
61
61
 
62
+ > **v5 note**: `@mysten/sui` v2 ships gRPC, GraphQL, and JSON-RPC transports
63
+ > behind a unified `ClientWithCoreApi`. The SDK constructs a `SuiGrpcClient`
64
+ > against Sui mainnet by default; pass `MetaAgOptions.client` to override with
65
+ > any transport (see the [MetaAg docs](docs/META_AG.md)).
66
+
62
67
  ### Optional Dependencies (for MetaAg providers)
63
68
 
64
69
  The following dependencies are **optional** and only needed for specific MetaAg
65
70
  providers:
66
71
 
67
- | Package | Version | Provider |
68
- | -------------------------------------------- | --------- | ------------------------- |
69
- | Package | Version | Provider |
70
- | -------------------------------------------- | --------- | ----------------------- |
71
- | `@flowx-finance/sdk` | `^1.13.8` | Flowx MetaAg provider |
72
- | `@cetusprotocol/aggregator-sdk` | `^1.4.1` | Cetus MetaAg provider |
73
- | `@bluefin-exchange/bluefin7k-aggregator-sdk` | `^5.1.4` | Bluefin7k MetaAg provider |
72
+ | Package | Version | Provider |
73
+ | -------------------------------------------- | -------- | ------------------------- |
74
+ | `@flowx-finance/sdk` | `^2.0.3` | Flowx MetaAg provider |
75
+ | `@cetusprotocol/aggregator-sdk` | `^1.5.4` | Cetus MetaAg provider |
76
+ | `@bluefin-exchange/bluefin7k-aggregator-sdk` | `^7.2.0` | Bluefin7k MetaAg provider |
74
77
 
75
78
  To use Flowx or Cetus providers, install their respective dependencies:
76
79
 
77
80
  ```bash
78
81
  # For Flowx MetaAg provider
79
- npm i @flowx-finance/sdk@^1.13.8
82
+ npm i @flowx-finance/sdk@^2.0.3
80
83
 
81
84
  # For Cetus MetaAg provider
82
- npm i @cetusprotocol/aggregator-sdk@^1.4.1
85
+ npm i @cetusprotocol/aggregator-sdk@^1.5.4
83
86
 
84
87
  # For Bluefin7k MetaAg provider
85
- npm i @bluefin-exchange/bluefin7k-aggregator-sdk@^5.1.4
88
+ npm i @bluefin-exchange/bluefin7k-aggregator-sdk@^7.2.0
86
89
  ```
87
90
 
91
+ > **Cetus transport caveat (v5)**: Cetus 1.5.4 still types its internal client
92
+ > as `SuiJsonRpcClient` and calls legacy JSON-RPC methods on Pyth-priced and
93
+ > DeepBookV3-driven routes. Most routes work with the default `SuiGrpcClient`,
94
+ > but routes that touch Pyth oracles (e.g. `HAEDALPMM`) will fail. If you need
95
+ > full Cetus coverage, pass a `SuiJsonRpcClient` via `MetaAgOptions.client`.
96
+
88
97
  ### Graceful Degradation
89
98
 
90
99
  The SDK is designed to work gracefully even when optional dependencies are
@@ -0,0 +1,2 @@
1
+ import{a as r,h as i,j as n,k as a}from"./chunk-CYI4MM5C.mjs";import{buildTx as d,Config as s,getQuote as c}from"@bluefin-exchange/bluefin7k-aggregator-sdk";import{v4 as l}from"uuid";var p=class{constructor(o,t,e){this.options=o;this.metaOptions=t;r(this,"kind","bluefin7k");o.apiKey&&s.setApiKey(o.apiKey),s.setSuiClient(e)}async quote(o){let t=await c({tokenIn:o.coinTypeIn,tokenOut:o.coinTypeOut,amountIn:o.amountIn,sources:this.options.sources,excludedPools:this.options.excludedPools,targetPools:this.options.targetPools});return n.assert(!!t,"No quote found",1005,{provider:this.kind}),{id:l(),provider:"bluefin7k",quote:t,amountIn:t.swapAmountWithDecimal,rawAmountOut:t.returnAmountWithDecimal,amountOut:t.returnAmountWithDecimal,coinTypeIn:o.coinTypeIn,coinTypeOut:o.coinTypeOut}}async swap({quote:o,signer:t,tx:e,coinIn:u}){a(o,"bluefin7k");let{coinOut:m}=await d({quoteResponse:o.quote,accountAddress:t,commission:{commissionBps:0,partner:i},slippage:1,extendTx:{tx:e,coinIn:u}});return m}};export{p as Bluefin7kProvider};
2
+ //# sourceMappingURL=bluefin7k-63A5CV3A.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/features/metaAg/providers/bluefin7k.ts"],"sourcesContent":["import {\n buildTx,\n Config,\n getQuote,\n} from \"@bluefin-exchange/bluefin7k-aggregator-sdk\";\nimport { ClientWithCoreApi } from \"@mysten/sui/client\";\nimport { v4 } from \"uuid\";\nimport { _7K_PARTNER_ADDRESS } from \"../../../constants/_7k\";\nimport {\n AggregatorProvider,\n Bluefin7kProviderOptions,\n EProvider,\n MetaAgOptions,\n MetaQuote,\n MetaQuoteOptions,\n MetaSwapOptions,\n QuoteProvider,\n} from \"../../../types/metaAg\";\nimport { assertQuoteProvider } from \"../common\";\nimport { MetaAgError, MetaAgErrorCode } from \"../error\";\n\nexport class Bluefin7kProvider implements QuoteProvider, AggregatorProvider {\n readonly kind = EProvider.BLUEFIN7K;\n constructor(\n private readonly options: Bluefin7kProviderOptions,\n private readonly metaOptions: Required<MetaAgOptions>,\n client: ClientWithCoreApi,\n ) {\n if (options.apiKey) Config.setApiKey(options.apiKey);\n Config.setSuiClient(client);\n }\n\n async quote(quoteOptions: MetaQuoteOptions): Promise<MetaQuote> {\n const quote = await getQuote({\n tokenIn: quoteOptions.coinTypeIn,\n tokenOut: quoteOptions.coinTypeOut,\n amountIn: quoteOptions.amountIn,\n sources: this.options.sources,\n excludedPools: this.options.excludedPools,\n targetPools: this.options.targetPools,\n });\n MetaAgError.assert(\n !!quote,\n \"No quote found\",\n MetaAgErrorCode.QUOTE_NOT_FOUND,\n { provider: this.kind },\n );\n return {\n id: v4(),\n provider: EProvider.BLUEFIN7K,\n quote,\n amountIn: quote.swapAmountWithDecimal,\n rawAmountOut: quote.returnAmountWithDecimal,\n amountOut: quote.returnAmountWithDecimal,\n coinTypeIn: quoteOptions.coinTypeIn,\n coinTypeOut: quoteOptions.coinTypeOut,\n };\n }\n\n async swap({ quote, signer, tx, coinIn }: MetaSwapOptions) {\n assertQuoteProvider(quote, EProvider.BLUEFIN7K);\n const { coinOut } = await buildTx({\n quoteResponse: quote.quote,\n accountAddress: signer,\n commission: {\n commissionBps: 0,\n partner: _7K_PARTNER_ADDRESS,\n },\n slippage: 1,\n extendTx: {\n tx,\n coinIn,\n },\n });\n return coinOut!;\n }\n}\n"],"mappings":"8DAAA,OACE,WAAAA,EACA,UAAAC,EACA,YAAAC,MACK,6CAEP,OAAS,MAAAC,MAAU,OAeZ,IAAMC,EAAN,KAAqE,CAE1E,YACmBC,EACAC,EACjBC,EACA,CAHiB,aAAAF,EACA,iBAAAC,EAHnBE,EAAA,KAAS,oBAMHH,EAAQ,QAAQI,EAAO,UAAUJ,EAAQ,MAAM,EACnDI,EAAO,aAAaF,CAAM,CAC5B,CAEA,MAAM,MAAMG,EAAoD,CAC9D,IAAMC,EAAQ,MAAMC,EAAS,CAC3B,QAASF,EAAa,WACtB,SAAUA,EAAa,YACvB,SAAUA,EAAa,SACvB,QAAS,KAAK,QAAQ,QACtB,cAAe,KAAK,QAAQ,cAC5B,YAAa,KAAK,QAAQ,WAC5B,CAAC,EACD,OAAAG,EAAY,OACV,CAAC,CAACF,EACF,sBAEA,CAAE,SAAU,KAAK,IAAK,CACxB,EACO,CACL,GAAIG,EAAG,EACP,qBACA,MAAAH,EACA,SAAUA,EAAM,sBAChB,aAAcA,EAAM,wBACpB,UAAWA,EAAM,wBACjB,WAAYD,EAAa,WACzB,YAAaA,EAAa,WAC5B,CACF,CAEA,MAAM,KAAK,CAAE,MAAAC,EAAO,OAAAI,EAAQ,GAAAC,EAAI,OAAAC,CAAO,EAAoB,CACzDC,EAAoBP,aAA0B,EAC9C,GAAM,CAAE,QAAAQ,CAAQ,EAAI,MAAMC,EAAQ,CAChC,cAAeT,EAAM,MACrB,eAAgBI,EAChB,WAAY,CACV,cAAe,EACf,QAASM,CACX,EACA,SAAU,EACV,SAAU,CACR,GAAAL,EACA,OAAAC,CACF,CACF,CAAC,EACD,OAAOE,CACT,CACF","names":["buildTx","Config","getQuote","v4","Bluefin7kProvider","options","metaOptions","client","__publicField","Config","quoteOptions","quote","getQuote","MetaAgError","v4","signer","tx","coinIn","assertQuoteProvider","coinOut","buildTx","_7K_PARTNER_ADDRESS"]}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkE5KM5OVWjs = require('./chunk-E5KM5OVW.js');var _bluefin7kaggregatorsdk = require('@bluefin-exchange/bluefin7k-aggregator-sdk');var _uuid = require('uuid');var p=class{constructor(o,t,e){this.options=o;this.metaOptions=t;_chunkE5KM5OVWjs.a.call(void 0, this,"kind","bluefin7k");o.apiKey&&_bluefin7kaggregatorsdk.Config.setApiKey(o.apiKey),_bluefin7kaggregatorsdk.Config.setSuiClient(e)}async quote(o){let t=await _bluefin7kaggregatorsdk.getQuote.call(void 0, {tokenIn:o.coinTypeIn,tokenOut:o.coinTypeOut,amountIn:o.amountIn,sources:this.options.sources,excludedPools:this.options.excludedPools,targetPools:this.options.targetPools});return _chunkE5KM5OVWjs.j.assert(!!t,"No quote found",1005,{provider:this.kind}),{id:_uuid.v4.call(void 0, ),provider:"bluefin7k",quote:t,amountIn:t.swapAmountWithDecimal,rawAmountOut:t.returnAmountWithDecimal,amountOut:t.returnAmountWithDecimal,coinTypeIn:o.coinTypeIn,coinTypeOut:o.coinTypeOut}}async swap({quote:o,signer:t,tx:e,coinIn:u}){_chunkE5KM5OVWjs.k.call(void 0, o,"bluefin7k");let{coinOut:m}=await _bluefin7kaggregatorsdk.buildTx.call(void 0, {quoteResponse:o.quote,accountAddress:t,commission:{commissionBps:0,partner:_chunkE5KM5OVWjs.h},slippage:1,extendTx:{tx:e,coinIn:u}});return m}};exports.Bluefin7kProvider = p;
2
+ //# sourceMappingURL=bluefin7k-MP3A4MG4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/otis/Documents/7k-ts-sdk/dist/bluefin7k-MP3A4MG4.js","../src/features/metaAg/providers/bluefin7k.ts"],"names":["Bluefin7kProvider","options","metaOptions","client","__publicField","Config","quoteOptions","quote","getQuote","MetaAgError","v4","signer","tx","coinIn","assertQuoteProvider","coinOut","buildTx","_7K_PARTNER_ADDRESS"],"mappings":"AAAA,+HAA4D,oFCIrD,4BAEY,IAeNA,CAAAA,CAAN,KAAqE,CAE1E,WAAA,CACmBC,CAAAA,CACAC,CAAAA,CACjBC,CAAAA,CACA,CAHiB,IAAA,CAAA,OAAA,CAAAF,CAAAA,CACA,IAAA,CAAA,WAAA,CAAAC,CAAAA,CAHnBE,gCAAAA,IAAA,CAAS,MAAA,CAAA,WAAA,CAAA,CAMHH,CAAAA,CAAQ,MAAA,EAAQI,8BAAAA,CAAO,SAAA,CAAUJ,CAAAA,CAAQ,MAAM,CAAA,CACnDI,8BAAAA,CAAO,YAAA,CAAaF,CAAM,CAC5B,CAEA,MAAM,KAAA,CAAMG,CAAAA,CAAoD,CAC9D,IAAMC,CAAAA,CAAQ,MAAMC,8CAAAA,CAClB,OAAA,CAASF,CAAAA,CAAa,UAAA,CACtB,QAAA,CAAUA,CAAAA,CAAa,WAAA,CACvB,QAAA,CAAUA,CAAAA,CAAa,QAAA,CACvB,OAAA,CAAS,IAAA,CAAK,OAAA,CAAQ,OAAA,CACtB,aAAA,CAAe,IAAA,CAAK,OAAA,CAAQ,aAAA,CAC5B,WAAA,CAAa,IAAA,CAAK,OAAA,CAAQ,WAC5B,CAAC,CAAA,CACD,OAAAG,kBAAAA,CAAY,MAAA,CACV,CAAC,CAACF,CAAAA,CACF,gBAAA,CAAA,IAAA,CAEA,CAAE,QAAA,CAAU,IAAA,CAAK,IAAK,CACxB,CAAA,CACO,CACL,EAAA,CAAIG,sBAAAA,CAAG,CACP,QAAA,CAAA,WAAA,CACA,KAAA,CAAAH,CAAAA,CACA,QAAA,CAAUA,CAAAA,CAAM,qBAAA,CAChB,YAAA,CAAcA,CAAAA,CAAM,uBAAA,CACpB,SAAA,CAAWA,CAAAA,CAAM,uBAAA,CACjB,UAAA,CAAYD,CAAAA,CAAa,UAAA,CACzB,WAAA,CAAaA,CAAAA,CAAa,WAC5B,CACF,CAEA,MAAM,IAAA,CAAK,CAAE,KAAA,CAAAC,CAAAA,CAAO,MAAA,CAAAI,CAAAA,CAAQ,EAAA,CAAAC,CAAAA,CAAI,MAAA,CAAAC,CAAO,CAAA,CAAoB,CACzDC,gCAAAA,CAAoBP,CAAAA,WAA0B,CAAA,CAC9C,GAAM,CAAE,OAAA,CAAAQ,CAAQ,CAAA,CAAI,MAAMC,6CAAAA,CACxB,aAAA,CAAeT,CAAAA,CAAM,KAAA,CACrB,cAAA,CAAgBI,CAAAA,CAChB,UAAA,CAAY,CACV,aAAA,CAAe,CAAA,CACf,OAAA,CAASM,kBACX,CAAA,CACA,QAAA,CAAU,CAAA,CACV,QAAA,CAAU,CACR,EAAA,CAAAL,CAAAA,CACA,MAAA,CAAAC,CACF,CACF,CAAC,CAAA,CACD,OAAOE,CACT,CACF,CAAA,CAAA,8BAAA","file":"/Users/otis/Documents/7k-ts-sdk/dist/bluefin7k-MP3A4MG4.js","sourcesContent":[null,"import {\n buildTx,\n Config,\n getQuote,\n} from \"@bluefin-exchange/bluefin7k-aggregator-sdk\";\nimport { ClientWithCoreApi } from \"@mysten/sui/client\";\nimport { v4 } from \"uuid\";\nimport { _7K_PARTNER_ADDRESS } from \"../../../constants/_7k\";\nimport {\n AggregatorProvider,\n Bluefin7kProviderOptions,\n EProvider,\n MetaAgOptions,\n MetaQuote,\n MetaQuoteOptions,\n MetaSwapOptions,\n QuoteProvider,\n} from \"../../../types/metaAg\";\nimport { assertQuoteProvider } from \"../common\";\nimport { MetaAgError, MetaAgErrorCode } from \"../error\";\n\nexport class Bluefin7kProvider implements QuoteProvider, AggregatorProvider {\n readonly kind = EProvider.BLUEFIN7K;\n constructor(\n private readonly options: Bluefin7kProviderOptions,\n private readonly metaOptions: Required<MetaAgOptions>,\n client: ClientWithCoreApi,\n ) {\n if (options.apiKey) Config.setApiKey(options.apiKey);\n Config.setSuiClient(client);\n }\n\n async quote(quoteOptions: MetaQuoteOptions): Promise<MetaQuote> {\n const quote = await getQuote({\n tokenIn: quoteOptions.coinTypeIn,\n tokenOut: quoteOptions.coinTypeOut,\n amountIn: quoteOptions.amountIn,\n sources: this.options.sources,\n excludedPools: this.options.excludedPools,\n targetPools: this.options.targetPools,\n });\n MetaAgError.assert(\n !!quote,\n \"No quote found\",\n MetaAgErrorCode.QUOTE_NOT_FOUND,\n { provider: this.kind },\n );\n return {\n id: v4(),\n provider: EProvider.BLUEFIN7K,\n quote,\n amountIn: quote.swapAmountWithDecimal,\n rawAmountOut: quote.returnAmountWithDecimal,\n amountOut: quote.returnAmountWithDecimal,\n coinTypeIn: quoteOptions.coinTypeIn,\n coinTypeOut: quoteOptions.coinTypeOut,\n };\n }\n\n async swap({ quote, signer, tx, coinIn }: MetaSwapOptions) {\n assertQuoteProvider(quote, EProvider.BLUEFIN7K);\n const { coinOut } = await buildTx({\n quoteResponse: quote.quote,\n accountAddress: signer,\n commission: {\n commissionBps: 0,\n partner: _7K_PARTNER_ADDRESS,\n },\n slippage: 1,\n extendTx: {\n tx,\n coinIn,\n },\n });\n return coinOut!;\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import{a as o,h as i,j as r,k as n}from"./chunk-CYI4MM5C.mjs";import{AggregatorClient as p,Env as u}from"@cetusprotocol/aggregator-sdk";import{v4 as m}from"uuid";var a=class{constructor(t,e,s){this.options=t;o(this,"kind","cetus");o(this,"cetusClient");this.cetusClient=new p({apiKey:t.apiKey,client:s,endpoint:t.api,env:u.Mainnet,pythUrls:e.hermesApi?[e.hermesApi]:[],overlayFeeRate:0,overlayFeeReceiver:i})}async quote(t){let e=await this.cetusClient.findRouters({amount:t.amountIn,byAmountIn:!0,from:t.coinTypeIn,target:t.coinTypeOut,providers:this.options.sources,splitCount:this.options.splitCount,splitAlgorithm:this.options.splitAlgorithm,splitFactor:this.options.splitFactor,depth:this.options.depth,liquidityChanges:this.options.liquidityChanges});return r.assert(!!e,"No quote found",1005,{provider:this.kind}),{id:m(),provider:"cetus",quote:e,amountIn:e.amountIn.toString()||"0",rawAmountOut:e.amountOut.toString()||"0",amountOut:e.amountOut.toString()||"0",coinTypeIn:t.coinTypeIn,coinTypeOut:t.coinTypeOut}}async swap(t){return n(t.quote,"cetus"),await this.cetusClient.routerSwap({inputCoin:t.coinIn,router:t.quote.quote,slippage:1,txb:t.tx})}};export{a as CetusProvider};
2
+ //# sourceMappingURL=cetus-HOKHMQSS.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/features/metaAg/providers/cetus.ts"],"sourcesContent":["import { AggregatorClient, Env } from \"@cetusprotocol/aggregator-sdk\";\nimport { ClientWithCoreApi } from \"@mysten/sui/client\";\nimport { v4 } from \"uuid\";\nimport { _7K_PARTNER_ADDRESS } from \"../../../constants/_7k\";\nimport {\n AggregatorProvider,\n CetusProviderOptions,\n EProvider,\n MetaAgOptions,\n MetaQuote,\n MetaQuoteOptions,\n MetaSwapOptions,\n QuoteProvider,\n} from \"../../../types/metaAg\";\nimport { assertQuoteProvider } from \"../common\";\nimport { MetaAgError, MetaAgErrorCode } from \"../error\";\n\nexport class CetusProvider implements QuoteProvider, AggregatorProvider {\n readonly kind = EProvider.CETUS;\n private readonly cetusClient: AggregatorClient;\n constructor(\n private readonly options: CetusProviderOptions,\n metaOptions: MetaAgOptions,\n client: ClientWithCoreApi,\n ) {\n this.cetusClient = new AggregatorClient({\n apiKey: options.apiKey,\n // Cetus 1.5.4 types `client` as `SuiJsonRpcClient` but the methods\n // exercised by the `findRouters` + `routerSwap` path we use here are\n // present on `SuiGrpcClient`. The legacy-only methods it can call\n // (`getDynamicFieldObject`, `getCoins`, `getOwnedObjects`,\n // `devInspectTransactionBlock`) sit behind code paths we don't enter\n // (Pyth-priced routes, DeepBookV3 account caps, in-pool simulation).\n // Cast at this single boundary to keep the SDK gRPC-only.\n client: client as unknown as ConstructorParameters<\n typeof AggregatorClient\n >[0][\"client\"],\n endpoint: options.api,\n env: Env.Mainnet,\n pythUrls: metaOptions.hermesApi ? [metaOptions.hermesApi] : [],\n overlayFeeRate: 0,\n overlayFeeReceiver: _7K_PARTNER_ADDRESS,\n });\n }\n\n async quote(quoteOptions: MetaQuoteOptions): Promise<MetaQuote> {\n const quote = await this.cetusClient.findRouters({\n amount: quoteOptions.amountIn,\n byAmountIn: true,\n from: quoteOptions.coinTypeIn,\n target: quoteOptions.coinTypeOut,\n providers: this.options.sources,\n splitCount: this.options.splitCount,\n splitAlgorithm: this.options.splitAlgorithm,\n splitFactor: this.options.splitFactor,\n depth: this.options.depth,\n liquidityChanges: this.options.liquidityChanges,\n });\n MetaAgError.assert(\n !!quote,\n \"No quote found\",\n MetaAgErrorCode.QUOTE_NOT_FOUND,\n { provider: this.kind },\n );\n return {\n id: v4(),\n provider: EProvider.CETUS,\n quote,\n amountIn: quote.amountIn.toString() || \"0\",\n rawAmountOut: quote.amountOut.toString() || \"0\",\n amountOut: quote.amountOut.toString() || \"0\",\n coinTypeIn: quoteOptions.coinTypeIn,\n coinTypeOut: quoteOptions.coinTypeOut,\n };\n }\n\n async swap(options: MetaSwapOptions) {\n assertQuoteProvider(options.quote, EProvider.CETUS);\n const coinOut = await this.cetusClient.routerSwap({\n inputCoin: options.coinIn,\n router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CAAC,CAEH,CACF","names":["AggregatorClient","Env","v4","CetusProvider","options","metaOptions","client","__publicField","AggregatorClient","Env","_7K_PARTNER_ADDRESS","quoteOptions","quote","MetaAgError","v4","assertQuoteProvider"]}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkE5KM5OVWjs = require('./chunk-E5KM5OVW.js');var _aggregatorsdk = require('@cetusprotocol/aggregator-sdk');var _uuid = require('uuid');var a=class{constructor(t,e,s){this.options=t;_chunkE5KM5OVWjs.a.call(void 0, this,"kind","cetus");_chunkE5KM5OVWjs.a.call(void 0, this,"cetusClient");this.cetusClient=new (0, _aggregatorsdk.AggregatorClient)({apiKey:t.apiKey,client:s,endpoint:t.api,env:_aggregatorsdk.Env.Mainnet,pythUrls:e.hermesApi?[e.hermesApi]:[],overlayFeeRate:0,overlayFeeReceiver:_chunkE5KM5OVWjs.h})}async quote(t){let e=await this.cetusClient.findRouters({amount:t.amountIn,byAmountIn:!0,from:t.coinTypeIn,target:t.coinTypeOut,providers:this.options.sources,splitCount:this.options.splitCount,splitAlgorithm:this.options.splitAlgorithm,splitFactor:this.options.splitFactor,depth:this.options.depth,liquidityChanges:this.options.liquidityChanges});return _chunkE5KM5OVWjs.j.assert(!!e,"No quote found",1005,{provider:this.kind}),{id:_uuid.v4.call(void 0, ),provider:"cetus",quote:e,amountIn:e.amountIn.toString()||"0",rawAmountOut:e.amountOut.toString()||"0",amountOut:e.amountOut.toString()||"0",coinTypeIn:t.coinTypeIn,coinTypeOut:t.coinTypeOut}}async swap(t){return _chunkE5KM5OVWjs.k.call(void 0, t.quote,"cetus"),await this.cetusClient.routerSwap({inputCoin:t.coinIn,router:t.quote.quote,slippage:1,txb:t.tx})}};exports.CetusProvider = a;
2
+ //# sourceMappingURL=cetus-MUHFO44Y.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/otis/Documents/7k-ts-sdk/dist/cetus-MUHFO44Y.js","../src/features/metaAg/providers/cetus.ts"],"names":["CetusProvider","options","metaOptions","client","__publicField","AggregatorClient","Env","_7K_PARTNER_ADDRESS","quoteOptions","quote","MetaAgError","v4","assertQuoteProvider"],"mappings":"AAAA,+HAA4D,8DCAtB,4BAEnB,IAeNA,CAAAA,CAAN,KAAiE,CAGtE,WAAA,CACmBC,CAAAA,CACjBC,CAAAA,CACAC,CAAAA,CACA,CAHiB,IAAA,CAAA,OAAA,CAAAF,CAAAA,CAHnBG,gCAAAA,IAAA,CAAS,MAAA,CAAA,OAAA,CAAA,CACTA,gCAAAA,IAAA,CAAiB,aAAA,CAAA,CAMf,IAAA,CAAK,WAAA,CAAc,IAAIC,oCAAAA,CAAiB,CACtC,MAAA,CAAQJ,CAAAA,CAAQ,MAAA,CAQhB,MAAA,CAAQE,CAAAA,CAGR,QAAA,CAAUF,CAAAA,CAAQ,GAAA,CAClB,GAAA,CAAKK,kBAAAA,CAAI,OAAA,CACT,QAAA,CAAUJ,CAAAA,CAAY,SAAA,CAAY,CAACA,CAAAA,CAAY,SAAS,CAAA,CAAI,CAAC,CAAA,CAC7D,cAAA,CAAgB,CAAA,CAChB,kBAAA,CAAoBK,kBACtB,CAAC,CACH,CAEA,MAAM,KAAA,CAAMC,CAAAA,CAAoD,CAC9D,IAAMC,CAAAA,CAAQ,MAAM,IAAA,CAAK,WAAA,CAAY,WAAA,CAAY,CAC/C,MAAA,CAAQD,CAAAA,CAAa,QAAA,CACrB,UAAA,CAAY,CAAA,CAAA,CACZ,IAAA,CAAMA,CAAAA,CAAa,UAAA,CACnB,MAAA,CAAQA,CAAAA,CAAa,WAAA,CACrB,SAAA,CAAW,IAAA,CAAK,OAAA,CAAQ,OAAA,CACxB,UAAA,CAAY,IAAA,CAAK,OAAA,CAAQ,UAAA,CACzB,cAAA,CAAgB,IAAA,CAAK,OAAA,CAAQ,cAAA,CAC7B,WAAA,CAAa,IAAA,CAAK,OAAA,CAAQ,WAAA,CAC1B,KAAA,CAAO,IAAA,CAAK,OAAA,CAAQ,KAAA,CACpB,gBAAA,CAAkB,IAAA,CAAK,OAAA,CAAQ,gBACjC,CAAC,CAAA,CACD,OAAAE,kBAAAA,CAAY,MAAA,CACV,CAAC,CAACD,CAAAA,CACF,gBAAA,CAAA,IAAA,CAEA,CAAE,QAAA,CAAU,IAAA,CAAK,IAAK,CACxB,CAAA,CACO,CACL,EAAA,CAAIE,sBAAAA,CAAG,CACP,QAAA,CAAA,OAAA,CACA,KAAA,CAAAF,CAAAA,CACA,QAAA,CAAUA,CAAAA,CAAM,QAAA,CAAS,QAAA,CAAS,CAAA,EAAK,GAAA,CACvC,YAAA,CAAcA,CAAAA,CAAM,SAAA,CAAU,QAAA,CAAS,CAAA,EAAK,GAAA,CAC5C,SAAA,CAAWA,CAAAA,CAAM,SAAA,CAAU,QAAA,CAAS,CAAA,EAAK,GAAA,CACzC,UAAA,CAAYD,CAAAA,CAAa,UAAA,CACzB,WAAA,CAAaA,CAAAA,CAAa,WAC5B,CACF,CAEA,MAAM,IAAA,CAAKP,CAAAA,CAA0B,CACnC,OAAAW,gCAAAA,CAAoBX,CAAQ,KAAA,CAAA,OAAsB,CAAA,CAClC,MAAM,IAAA,CAAK,WAAA,CAAY,UAAA,CAAW,CAChD,SAAA,CAAWA,CAAAA,CAAQ,MAAA,CACnB,MAAA,CAAQA,CAAAA,CAAQ,KAAA,CAAM,KAAA,CACtB,QAAA,CAAU,CAAA,CACV,GAAA,CAAKA,CAAAA,CAAQ,EACf,CAAC,CAEH,CACF,CAAA,CAAA,0BAAA","file":"/Users/otis/Documents/7k-ts-sdk/dist/cetus-MUHFO44Y.js","sourcesContent":[null,"import { AggregatorClient, Env } from \"@cetusprotocol/aggregator-sdk\";\nimport { ClientWithCoreApi } from \"@mysten/sui/client\";\nimport { v4 } from \"uuid\";\nimport { _7K_PARTNER_ADDRESS } from \"../../../constants/_7k\";\nimport {\n AggregatorProvider,\n CetusProviderOptions,\n EProvider,\n MetaAgOptions,\n MetaQuote,\n MetaQuoteOptions,\n MetaSwapOptions,\n QuoteProvider,\n} from \"../../../types/metaAg\";\nimport { assertQuoteProvider } from \"../common\";\nimport { MetaAgError, MetaAgErrorCode } from \"../error\";\n\nexport class CetusProvider implements QuoteProvider, AggregatorProvider {\n readonly kind = EProvider.CETUS;\n private readonly cetusClient: AggregatorClient;\n constructor(\n private readonly options: CetusProviderOptions,\n metaOptions: MetaAgOptions,\n client: ClientWithCoreApi,\n ) {\n this.cetusClient = new AggregatorClient({\n apiKey: options.apiKey,\n // Cetus 1.5.4 types `client` as `SuiJsonRpcClient` but the methods\n // exercised by the `findRouters` + `routerSwap` path we use here are\n // present on `SuiGrpcClient`. The legacy-only methods it can call\n // (`getDynamicFieldObject`, `getCoins`, `getOwnedObjects`,\n // `devInspectTransactionBlock`) sit behind code paths we don't enter\n // (Pyth-priced routes, DeepBookV3 account caps, in-pool simulation).\n // Cast at this single boundary to keep the SDK gRPC-only.\n client: client as unknown as ConstructorParameters<\n typeof AggregatorClient\n >[0][\"client\"],\n endpoint: options.api,\n env: Env.Mainnet,\n pythUrls: metaOptions.hermesApi ? [metaOptions.hermesApi] : [],\n overlayFeeRate: 0,\n overlayFeeReceiver: _7K_PARTNER_ADDRESS,\n });\n }\n\n async quote(quoteOptions: MetaQuoteOptions): Promise<MetaQuote> {\n const quote = await this.cetusClient.findRouters({\n amount: quoteOptions.amountIn,\n byAmountIn: true,\n from: quoteOptions.coinTypeIn,\n target: quoteOptions.coinTypeOut,\n providers: this.options.sources,\n splitCount: this.options.splitCount,\n splitAlgorithm: this.options.splitAlgorithm,\n splitFactor: this.options.splitFactor,\n depth: this.options.depth,\n liquidityChanges: this.options.liquidityChanges,\n });\n MetaAgError.assert(\n !!quote,\n \"No quote found\",\n MetaAgErrorCode.QUOTE_NOT_FOUND,\n { provider: this.kind },\n );\n return {\n id: v4(),\n provider: EProvider.CETUS,\n quote,\n amountIn: quote.amountIn.toString() || \"0\",\n rawAmountOut: quote.amountOut.toString() || \"0\",\n amountOut: quote.amountOut.toString() || \"0\",\n coinTypeIn: quoteOptions.coinTypeIn,\n coinTypeOut: quoteOptions.coinTypeOut,\n };\n }\n\n async swap(options: MetaSwapOptions) {\n assertQuoteProvider(options.quote, EProvider.CETUS);\n const coinOut = await this.cetusClient.routerSwap({\n inputCoin: options.coinIn,\n router: options.quote.quote,\n slippage: 1,\n txb: options.tx,\n });\n return coinOut;\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ var E=Object.defineProperty;var T=e=>{throw TypeError(e)};var A=(e,t,r)=>t in e?E(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var c=(e,t,r)=>A(e,typeof t!="symbol"?t+"":t,r),g=(e,t,r)=>t.has(e)||T("Cannot "+r);var D=(e,t,r)=>(g(e,t,"read from private field"),r?r.call(e):t.get(e)),M=(e,t,r)=>t.has(e)?T("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),w=(e,t,r,n)=>(g(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r);var f=(o=>(o.BLUEFIN7K="bluefin7k",o.CETUS="cetus",o.FLOWX="flowx",o.OKX="okx",o))(f||{}),U=e=>e.kind==="bluefin7k"||e.kind==="cetus"||e.kind==="flowx",R=e=>e.kind==="okx";var d="0x17c0b1f7a6ad73f51268f16b8c06c049eecc2f28a270cdd29c06e3d2dea23302",O="0x17c0b1f7a6ad73f51268f16b8c06c049eecc2f28a270cdd29c06e3d2dea23302",m="0x9a8abd32fe5721307ce3b697cf982ee84e9ffbd58d667a4a199f1683c1a3d23c",l="0xbbb3a51877ed9b492f26f4e2181811cfb2bd70c532f6f7621263d122d5e96b56",Q="0x93ead46c1e48a9b62e25b6787f2ea6f75caedabb21726f12431acc4381f5f4c5";var u=class e extends Error{constructor(r,n,o){super(r);c(this,"code");c(this,"details");this.name="MetaAgError",this.code=n??1e3,this.details=o}static assert(r,n,o,s){if(!r)throw new e(n??"Assertion failed",o,s)}};import{coinWithBalance as v,Transaction as _}from"@mysten/sui/transactions";var P=(e,t,r,n=0)=>{if(t>1e4)throw new Error("Slippage must be less than 100%");if(r>1e4)throw new Error("Commission must be less than 100%");if(n>1e4)throw new Error("Tip must be less than 100%");let o=BigInt(e),s=o*BigInt(n||0)/10000n,i=(o-s)*BigInt(r)/10000n,a=o-s-i,p=a*BigInt(1e4-t)/10000n;return{tipAmount:s,minAmount:p,commissionAmount:i,expectedAmount:a.toString(10)}};var I=(e,t="Transaction returned no result")=>{let r=e.Transaction??e.FailedTransaction;if(!r)throw new u(t,1008,{error:t});return r};function G(e,t){u.assert(e.provider===t,"Invalid quote",1004,{quote:e,expectedProvider:t})}var S=async(e,t,r)=>{let n=await N(()=>t.simulateTransaction({sender:r.sender,transactionBlock:e}),r.timeout??2e3),o=I(n,"Simulation failed"),s=o.effects.status;if(!s.success){let a=s.error.message??"Simulation failed";throw new u(a,1008,{error:a})}return{simulatedAmountOut:b(o.events??[]),gasUsed:o.effects.gasUsed}},q=async(e,t,r,n,o)=>{let s=new _,i=await e.swap({quote:t,coinIn:v({balance:BigInt(t.amountIn),type:t.coinTypeIn,useGasCoin:!1}),signer:r.sender,tx:s});s.add(x(t,i,1e4,o.tipBps,o.partner,o.partnerCommissionBps)),s.transferObjects([i],r.sender);let a=await S(s,n,r);return{id:t.id,provider:e.kind,...a}},x=(e,t,r=100,n=0,o,s=0)=>i=>{let{minAmount:a,expectedAmount:p}=P(e.rawAmountOut,r,s,n);n>0&&i.moveCall({target:`${d}::vault::collect_tip`,typeArguments:[e.coinTypeOut],arguments:[i.object(m),i.object(l),t,i.pure.u64(n)]}),i.moveCall({target:`${d}::settle::settle`,typeArguments:[e.coinTypeIn,e.coinTypeOut],arguments:[i.object(l),i.object(m),i.pure.u64(e.amountIn),t,i.pure.u64(a),i.pure.u64(p),i.pure.option("address",o),i.pure.u64(s),i.pure.u64(0)]})},b=e=>e.filter(n=>n.eventType===`${O}::settle::Swap`)?.pop()?.json?.amount_out,N=async(e,t,r)=>t<=0?e():new Promise((n,o)=>{let s=setTimeout(()=>o(new u(`Timeout ${r??"operation"}`,1001,{timeout:t})),t);e().then(n).catch(o).finally(()=>clearTimeout(s))});export{c as a,D as b,M as c,w as d,f as e,U as f,R as g,Q as h,P as i,u as j,G as k,S as l,q as m,x as n,N as o};
2
+ //# sourceMappingURL=chunk-CYI4MM5C.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types/metaAg.ts","../src/constants/_7k.ts","../src/features/metaAg/error.ts","../src/features/metaAg/common.ts","../src/utils/swap.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 { ClientWithCoreApi, SuiClientTypes } 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 /**\n * Sui client to use for on-chain reads, simulation, and execution. Accepts\n * any v2 `ClientWithCoreApi` implementation (`SuiGrpcClient`,\n * `SuiGraphQLClient`, `SuiJsonRpcClient`, or a custom transport). If not\n * specified, a default `SuiGrpcClient` against Sui mainnet is constructed.\n *\n * @warning **Cetus provider compatibility**: `@cetusprotocol/aggregator-sdk`\n * is **only fully compatible with `SuiJsonRpcClient`**. It calls legacy\n * JSON-RPC-only methods (`getDynamicFieldObject`, `getCoins`,\n * `getOwnedObjects`, `devInspectTransactionBlock`) for specific routes:\n *\n * - Pyth-priced routes (uses `getDynamicFieldObject` to resolve price\n * feeds in `routerSwap`).\n * - DeepBookV3 routes (uses `getCoins` for coin merging and\n * `getOwnedObjects` to mint/find an account cap).\n *\n * Passing a `SuiGrpcClient` / `SuiGraphQLClient` will work for plain\n * `findRouters + routerSwap` routes but **will throw at runtime** for the\n * cases above. If you need full Cetus coverage, pass a `SuiJsonRpcClient`\n * here (or disable the Cetus provider, or update to the latest cetus sdk that fully compatible with any sui client).\n */\n client?: ClientWithCoreApi;\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?: SuiClientTypes.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 { 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]: unknown;\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: string | undefined };\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","import {\n coinWithBalance,\n Transaction,\n TransactionObjectArgument,\n} from \"@mysten/sui/transactions\";\nimport {\n _7K_META_CONFIG,\n _7K_META_PACKAGE_ID,\n _7K_META_PUBLISHED_AT,\n _7K_META_VAULT,\n} from \"../../constants/_7k\";\nimport {\n AggregatorProvider,\n EProvider,\n MetaAgOptions,\n MetaQuote,\n MetaSimulationOptions,\n} from \"../../types/metaAg\";\nimport type { SimulateTransactionResult } from \"../../utils/SuiClientUtils\";\nimport { SuiClientUtils } from \"../../utils/SuiClientUtils\";\nimport { getExpectedReturn } from \"../../utils/swap\";\nimport { MetaAgError, MetaAgErrorCode } from \"./error\";\n\ntype SimulatedTransaction = NonNullable<\n | SimulateTransactionResult[\"Transaction\"]\n | SimulateTransactionResult[\"FailedTransaction\"]\n>;\ntype SimulatedEvent = NonNullable<SimulatedTransaction[\"events\"]>[number];\n\n/**\n * v2 gRPC returns a `{ Transaction?, FailedTransaction? }` envelope from\n * both `executeTransaction` and `simulateTransaction`. Unwrap to the inner\n * payload, throwing `SIMULATION_FAILED` if neither arm is populated.\n */\nexport const unwrapTxResult = <\n T extends {\n Transaction?: unknown;\n FailedTransaction?: unknown;\n },\n>(\n res: T,\n msg = \"Transaction returned no result\",\n): NonNullable<T[\"Transaction\"] | T[\"FailedTransaction\"]> => {\n const inner = (res.Transaction ?? res.FailedTransaction) as\n | NonNullable<T[\"Transaction\"] | T[\"FailedTransaction\"]>\n | undefined;\n if (!inner) {\n throw new MetaAgError(msg, MetaAgErrorCode.SIMULATION_FAILED, {\n error: msg,\n });\n }\n return inner;\n};\n\n/**\n * Assert that `quote.provider` matches the expected provider kind. All\n * provider classes use this identical guard at the top of `swap`/`fastSwap`.\n */\nexport function assertQuoteProvider<E extends EProvider>(\n quote: MetaQuote,\n expected: E,\n): asserts quote is Extract<MetaQuote, { provider: E }> {\n MetaAgError.assert(\n quote.provider === expected,\n \"Invalid quote\",\n MetaAgErrorCode.INVALID_QUOTE,\n { quote, expectedProvider: expected },\n );\n}\n\nexport const simulateSwapTx = async (\n tx: Transaction,\n inspector: SuiClientUtils,\n simulation: MetaSimulationOptions,\n) => {\n const res = await timeout(\n () =>\n inspector.simulateTransaction({\n sender: simulation.sender,\n transactionBlock: tx,\n }),\n simulation.timeout ?? 2000,\n );\n const result = unwrapTxResult(res, \"Simulation failed\");\n const status = result.effects.status;\n if (!status.success) {\n const errorMessage = status.error.message ?? \"Simulation failed\";\n throw new MetaAgError(errorMessage, MetaAgErrorCode.SIMULATION_FAILED, {\n error: errorMessage,\n });\n }\n const amountOut = extractAmountOutWrapper(result.events ?? []);\n return {\n simulatedAmountOut: amountOut,\n gasUsed: result.effects.gasUsed,\n };\n};\nexport const simulateAggregator = async (\n provider: AggregatorProvider,\n quote: MetaQuote,\n simulation: MetaSimulationOptions,\n inspector: SuiClientUtils,\n options: Required<MetaAgOptions>,\n) => {\n const tx = new Transaction();\n const coinOut = await provider.swap({\n quote,\n coinIn: coinWithBalance({\n balance: BigInt(quote.amountIn),\n type: quote.coinTypeIn,\n useGasCoin: false,\n }),\n signer: simulation.sender,\n tx,\n });\n tx.add(\n metaSettle(\n quote,\n coinOut,\n 10000,\n options.tipBps,\n options.partner,\n options.partnerCommissionBps,\n ),\n );\n tx.transferObjects([coinOut], simulation.sender);\n const res = await simulateSwapTx(tx, inspector, simulation);\n return {\n id: quote.id,\n provider: provider.kind,\n ...res,\n };\n};\n\n/**\n * this settlement does not charge commission fee for partner, since all integrated aggregators already charge commission fee for partner\n * @param quote Meta Aggregator Quote\n * @param coinOut Coin Out Object\n * @param slippageBps Slippage Bps\n * @param tipBps Tip Bps default = 0\n * @param partner address of partner for analytic default is zero address\n */\nexport const metaSettle = (\n quote: MetaQuote,\n coinOut: TransactionObjectArgument,\n slippageBps = 100,\n tipBps = 0,\n partner?: string,\n commissionBps = 0,\n) => {\n return (tx: Transaction) => {\n const { minAmount, expectedAmount } = getExpectedReturn(\n quote.rawAmountOut,\n slippageBps,\n commissionBps,\n tipBps,\n );\n\n if (tipBps > 0) {\n tx.moveCall({\n target: `${_7K_META_PUBLISHED_AT}::vault::collect_tip`,\n typeArguments: [quote.coinTypeOut],\n arguments: [\n tx.object(_7K_META_VAULT),\n tx.object(_7K_META_CONFIG),\n coinOut,\n tx.pure.u64(tipBps),\n ],\n });\n }\n\n tx.moveCall({\n target: `${_7K_META_PUBLISHED_AT}::settle::settle`,\n typeArguments: [quote.coinTypeIn, quote.coinTypeOut],\n arguments: [\n tx.object(_7K_META_CONFIG),\n tx.object(_7K_META_VAULT),\n tx.pure.u64(quote.amountIn),\n coinOut,\n tx.pure.u64(minAmount),\n tx.pure.u64(expectedAmount),\n tx.pure.option(\"address\", partner),\n tx.pure.u64(commissionBps),\n tx.pure.u64(0), // ps\n ],\n });\n };\n};\n\nconst extractAmountOutWrapper = (events: SimulatedEvent[]) => {\n const swapEvent = events\n .filter(\n (event) => event.eventType === `${_7K_META_PACKAGE_ID}::settle::Swap`,\n )\n ?.pop();\n const json = swapEvent?.json as { amount_out?: string } | null | undefined;\n return json?.amount_out;\n};\n\nexport const timeout = async <T>(\n fn: () => Promise<T>,\n timeout: number,\n msg?: string,\n): Promise<T> => {\n if (timeout <= 0) return fn();\n return new Promise<T>((resolve, reject) => {\n const timer = setTimeout(\n () =>\n reject(\n new MetaAgError(\n `Timeout ${msg ?? \"operation\"}`,\n MetaAgErrorCode.TIMEOUT,\n { timeout },\n ),\n ),\n timeout,\n );\n fn()\n .then(resolve)\n .catch(reject)\n .finally(() => clearTimeout(timer));\n });\n};\n","/**\n * Calculate expected return amount after applying slippage, commission, and tip\n * @param returnAmount - The raw return amount (with decimals)\n * @param slippageBps - Slippage in basis points (1 bps = 0.01%)\n * @param commissionBps - Commission in basis points\n * @param tipBps - Tip in basis points (default: 0)\n * @returns Object containing tipAmount, minAmount, commissionAmount, and expectedAmount\n */\nexport const getExpectedReturn = (\n returnAmount: string,\n slippageBps: number,\n commissionBps: number,\n tipBps: number = 0,\n) => {\n if (slippageBps > 10000) {\n throw new Error(\"Slippage must be less than 100%\");\n }\n if (commissionBps > 10000) {\n throw new Error(\"Commission must be less than 100%\");\n }\n if (tipBps > 10000) {\n throw new Error(\"Tip must be less than 100%\");\n }\n const returnAmountWithDecimal = BigInt(returnAmount);\n const tipAmountWithDecimal =\n (returnAmountWithDecimal * BigInt(tipBps || 0)) / 10000n;\n const commissionAmountWithDecimal =\n ((returnAmountWithDecimal - tipAmountWithDecimal) * BigInt(commissionBps)) /\n 10000n;\n const expectedReturnWithDecimal =\n returnAmountWithDecimal -\n tipAmountWithDecimal -\n commissionAmountWithDecimal;\n const minAmountWithDecimal =\n (expectedReturnWithDecimal * BigInt(1e4 - slippageBps)) / 10000n;\n\n return {\n tipAmount: tipAmountWithDecimal,\n minAmount: minAmountWithDecimal,\n commissionAmount: commissionAmountWithDecimal,\n expectedAmount: expectedReturnWithDecimal.toString(10),\n };\n};\n"],"mappings":"2eAiBO,IAAKA,OACVA,EAAA,UAAY,YACZA,EAAA,MAAQ,QACRA,EAAA,MAAQ,QACRA,EAAA,IAAM,MAJIA,OAAA,IAyLCC,EACXC,GAEAA,EAAS,OAAS,aAClBA,EAAS,OAAS,SAClBA,EAAS,OAA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,EAAG,SAAS,CACV,OAAQ,GAAGsB,CAAqB,uBAChC,cAAe,CAACzB,EAAM,WAAW,EACjC,UAAW,CACTG,EAAG,OAAOuB,CAAc,EACxBvB,EAAG,OAAOwB,CAAe,EACzBZ,EACAZ,EAAG,KAAK,IAAIgB,CAAM,CACpB,CACF,CAAC,EAGHhB,EAAG,SAAS,CACV,OAAQ,GAAGsB,CAAqB,mBAChC,cAAe,CAACzB,EAAM,WAAYA,EAAM,WAAW,EACnD,UAAW,CACTG,EAAG,OAAOwB,CAAe,EACzBxB,EAAG,OAAOuB,CAAc,EACxBvB,EAAG,KAAK,IAAIH,EAAM,QAAQ,EAC1Be,EACAZ,EAAG,KAAK,IAAImB,CAAS,EACrBnB,EAAG,KAAK,IAAIoB,CAAc,EAC1BpB,EAAG,KAAK,OAAO,UAAWiB,CAAO,EACjCjB,EAAG,KAAK,IAAIkB,CAAa,EACzBlB,EAAG,KAAK,IAAI,CAAC,CACf,CACF,CAAC,CACH,EAGIO,EAA2BkB,GACbA,EACf,OACEC,GAAUA,EAAM,YAAc,GAAGC,CAAmB,gBACvD,GACE,IAAI,GACgB,MACX,WAGFxB,EAAU,MACrByB,EACAzB,EACAV,IAEIU,GAAW,EAAUyB,EAAG,EACrB,IAAI,QAAW,CAACC,EAASC,IAAW,CACzC,IAAMC,EAAQ,WACZ,IACED,EACE,IAAInC,EACF,WAAWF,GAAO,WAAW,QAE7B,CAAE,QAAAU,CAAQ,CACZ,CACF,EACFA,CACF,EACAyB,EAAG,EACA,KAAKC,CAAO,EACZ,MAAMC,CAAM,EACZ,QAAQ,IAAM,aAAaC,CAAK,CAAC,CACtC,CAAC","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","__publicField","condition","coinWithBalance","Transaction","getExpectedReturn","returnAmount","slippageBps","commissionBps","tipBps","returnAmountWithDecimal","tipAmountWithDecimal","commissionAmountWithDecimal","expectedReturnWithDecimal","minAmountWithDecimal","unwrapTxResult","res","msg","inner","MetaAgError","assertQuoteProvider","quote","expected","simulateSwapTx","tx","inspector","simulation","timeout","result","status","errorMessage","extractAmountOutWrapper","simulateAggregator","provider","options","Transaction","coinOut","coinWithBalance","metaSettle","slippageBps","tipBps","partner","commissionBps","minAmount","expectedAmount","getExpectedReturn","_7K_META_PUBLISHED_AT","_7K_META_VAULT","_7K_META_CONFIG","events","event","_7K_META_PACKAGE_ID","fn","resolve","reject","timer"]}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var E=Object.defineProperty;var T=e=>{throw TypeError(e)};var A=(e,t,r)=>t in e?E(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var c=(e,t,r)=>A(e,typeof t!="symbol"?t+"":t,r),g=(e,t,r)=>t.has(e)||T("Cannot "+r);var D=(e,t,r)=>(g(e,t,"read from private field"),r?r.call(e):t.get(e)),M= exports.c =(e,t,r)=>t.has(e)?T("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),w= exports.d =(e,t,r,n)=>(g(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r);var f=(o=>(o.BLUEFIN7K="bluefin7k",o.CETUS="cetus",o.FLOWX="flowx",o.OKX="okx",o))(f||{}),U= exports.f =e=>e.kind==="bluefin7k"||e.kind==="cetus"||e.kind==="flowx",R= exports.g =e=>e.kind==="okx";var d="0x17c0b1f7a6ad73f51268f16b8c06c049eecc2f28a270cdd29c06e3d2dea23302",O="0x17c0b1f7a6ad73f51268f16b8c06c049eecc2f28a270cdd29c06e3d2dea23302",m="0x9a8abd32fe5721307ce3b697cf982ee84e9ffbd58d667a4a199f1683c1a3d23c",l="0xbbb3a51877ed9b492f26f4e2181811cfb2bd70c532f6f7621263d122d5e96b56",Q= exports.h ="0x93ead46c1e48a9b62e25b6787f2ea6f75caedabb21726f12431acc4381f5f4c5";var u=class e extends Error{constructor(r,n,o){super(r);c(this,"code");c(this,"details");this.name="MetaAgError",this.code=_nullishCoalesce(n, () => (1e3)),this.details=o}static assert(r,n,o,s){if(!r)throw new e(_nullishCoalesce(n, () => ("Assertion failed")),o,s)}};var _transactions = require('@mysten/sui/transactions');var P=(e,t,r,n=0)=>{if(t>1e4)throw new Error("Slippage must be less than 100%");if(r>1e4)throw new Error("Commission must be less than 100%");if(n>1e4)throw new Error("Tip must be less than 100%");let o=BigInt(e),s=o*BigInt(n||0)/10000n,i=(o-s)*BigInt(r)/10000n,a=o-s-i,p=a*BigInt(1e4-t)/10000n;return{tipAmount:s,minAmount:p,commissionAmount:i,expectedAmount:a.toString(10)}};var I=(e,t="Transaction returned no result")=>{let r=_nullishCoalesce(e.Transaction, () => (e.FailedTransaction));if(!r)throw new u(t,1008,{error:t});return r};function G(e,t){u.assert(e.provider===t,"Invalid quote",1004,{quote:e,expectedProvider:t})}var S=async(e,t,r)=>{let n=await N(()=>t.simulateTransaction({sender:r.sender,transactionBlock:e}),_nullishCoalesce(r.timeout, () => (2e3))),o=I(n,"Simulation failed"),s=o.effects.status;if(!s.success){let a=_nullishCoalesce(s.error.message, () => ("Simulation failed"));throw new u(a,1008,{error:a})}return{simulatedAmountOut:b(_nullishCoalesce(o.events, () => ([]))),gasUsed:o.effects.gasUsed}},q= exports.m =async(e,t,r,n,o)=>{let s=new _transactions.Transaction,i=await e.swap({quote:t,coinIn:_transactions.coinWithBalance.call(void 0, {balance:BigInt(t.amountIn),type:t.coinTypeIn,useGasCoin:!1}),signer:r.sender,tx:s});s.add(x(t,i,1e4,o.tipBps,o.partner,o.partnerCommissionBps)),s.transferObjects([i],r.sender);let a=await S(s,n,r);return{id:t.id,provider:e.kind,...a}},x= exports.n =(e,t,r=100,n=0,o,s=0)=>i=>{let{minAmount:a,expectedAmount:p}=P(e.rawAmountOut,r,s,n);n>0&&i.moveCall({target:`${d}::vault::collect_tip`,typeArguments:[e.coinTypeOut],arguments:[i.object(m),i.object(l),t,i.pure.u64(n)]}),i.moveCall({target:`${d}::settle::settle`,typeArguments:[e.coinTypeIn,e.coinTypeOut],arguments:[i.object(l),i.object(m),i.pure.u64(e.amountIn),t,i.pure.u64(a),i.pure.u64(p),i.pure.option("address",o),i.pure.u64(s),i.pure.u64(0)]})},b=e=>_optionalChain([e, 'access', _2 => _2.filter, 'call', _3 => _3(n=>n.eventType===`${O}::settle::Swap`), 'optionalAccess', _4 => _4.pop, 'call', _5 => _5(), 'optionalAccess', _6 => _6.json, 'optionalAccess', _7 => _7.amount_out]),N= exports.o =async(e,t,r)=>t<=0?e():new Promise((n,o)=>{let s=setTimeout(()=>o(new u(`Timeout ${_nullishCoalesce(r, () => ("operation"))}`,1001,{timeout:t})),t);e().then(n).catch(o).finally(()=>clearTimeout(s))});exports.a = c; exports.b = D; exports.c = M; exports.d = w; exports.e = f; exports.f = U; exports.g = R; exports.h = Q; exports.i = P; exports.j = u; exports.k = G; exports.l = S; exports.m = q; exports.n = x; exports.o = N;
2
+ //# sourceMappingURL=chunk-E5KM5OVW.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/otis/Documents/7k-ts-sdk/dist/chunk-E5KM5OVW.js","../src/types/metaAg.ts","../src/constants/_7k.ts","../src/features/metaAg/error.ts","../src/features/metaAg/common.ts","../src/utils/swap.ts"],"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","__publicField","condition","getExpectedReturn","returnAmount","slippageBps","commissionBps","tipBps","returnAmountWithDecimal","tipAmountWithDecimal","commissionAmountWithDecimal","expectedReturnWithDecimal","minAmountWithDecimal","unwrapTxResult","res","msg","inner","assertQuoteProvider","quote","expected","simulateSwapTx","tx","inspector","simulation","timeout","result","status","errorMessage","extractAmountOutWrapper","simulateAggregator","options","Transaction","coinOut","coinWithBalance","metaSettle","partner","minAmount","expectedAmount"],"mappings":"AAAA,qrBAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,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,CAAM,EAAA,CACV,QAAA,CAAU7B,CAAAA,CAAS,IAAA,CACnB,GAAGyB,CACL,CACF,CAAA,CAUaoB,CAAAA,aAAa,CACxBhB,CAAAA,CACAc,CAAAA,CACA3B,CAAAA,CAAc,GAAA,CACdE,CAAAA,CAAS,CAAA,CACT4B,CAAAA,CACA7B,CAAAA,CAAgB,CAAA,CAAA,EAERe,CAAAA,EAAoB,CAC1B,GAAM,CAAE,SAAA,CAAAe,CAAAA,CAAW,cAAA,CAAAC,CAAe,CAAA,CAAIlC,CAAAA,CACpCe,CAAAA,CAAM,YAAA,CACNb,CAAAA,CACAC,CAAAA,CACAC,CACF,CAAA,CAEIA,CAAAA,CAAS,CAAA,EACXc,CAAAA,CAAG,QAAA,CAAS,CACV,MAAA,CAAQ,CAAA,EAAA","file":"/Users/otis/Documents/7k-ts-sdk/dist/chunk-E5KM5OVW.js","sourcesContent":[null,"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 { ClientWithCoreApi, SuiClientTypes } 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 /**\n * Sui client to use for on-chain reads, simulation, and execution. Accepts\n * any v2 `ClientWithCoreApi` implementation (`SuiGrpcClient`,\n * `SuiGraphQLClient`, `SuiJsonRpcClient`, or a custom transport). If not\n * specified, a default `SuiGrpcClient` against Sui mainnet is constructed.\n *\n * @warning **Cetus provider compatibility**: `@cetusprotocol/aggregator-sdk`\n * is **only fully compatible with `SuiJsonRpcClient`**. It calls legacy\n * JSON-RPC-only methods (`getDynamicFieldObject`, `getCoins`,\n * `getOwnedObjects`, `devInspectTransactionBlock`) for specific routes:\n *\n * - Pyth-priced routes (uses `getDynamicFieldObject` to resolve price\n * feeds in `routerSwap`).\n * - DeepBookV3 routes (uses `getCoins` for coin merging and\n * `getOwnedObjects` to mint/find an account cap).\n *\n * Passing a `SuiGrpcClient` / `SuiGraphQLClient` will work for plain\n * `findRouters + routerSwap` routes but **will throw at runtime** for the\n * cases above. If you need full Cetus coverage, pass a `SuiJsonRpcClient`\n * here (or disable the Cetus provider, or update to the latest cetus sdk that fully compatible with any sui client).\n */\n client?: ClientWithCoreApi;\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?: SuiClientTypes.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 { 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]: unknown;\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: string | undefined };\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","import {\n coinWithBalance,\n Transaction,\n TransactionObjectArgument,\n} from \"@mysten/sui/transactions\";\nimport {\n _7K_META_CONFIG,\n _7K_META_PACKAGE_ID,\n _7K_META_PUBLISHED_AT,\n _7K_META_VAULT,\n} from \"../../constants/_7k\";\nimport {\n AggregatorProvider,\n EProvider,\n MetaAgOptions,\n MetaQuote,\n MetaSimulationOptions,\n} from \"../../types/metaAg\";\nimport type { SimulateTransactionResult } from \"../../utils/SuiClientUtils\";\nimport { SuiClientUtils } from \"../../utils/SuiClientUtils\";\nimport { getExpectedReturn } from \"../../utils/swap\";\nimport { MetaAgError, MetaAgErrorCode } from \"./error\";\n\ntype SimulatedTransaction = NonNullable<\n | SimulateTransactionResult[\"Transaction\"]\n | SimulateTransactionResult[\"FailedTransaction\"]\n>;\ntype SimulatedEvent = NonNullable<SimulatedTransaction[\"events\"]>[number];\n\n/**\n * v2 gRPC returns a `{ Transaction?, FailedTransaction? }` envelope from\n * both `executeTransaction` and `simulateTransaction`. Unwrap to the inner\n * payload, throwing `SIMULATION_FAILED` if neither arm is populated.\n */\nexport const unwrapTxResult = <\n T extends {\n Transaction?: unknown;\n FailedTransaction?: unknown;\n },\n>(\n res: T,\n msg = \"Transaction returned no result\",\n): NonNullable<T[\"Transaction\"] | T[\"FailedTransaction\"]> => {\n const inner = (res.Transaction ?? res.FailedTransaction) as\n | NonNullable<T[\"Transaction\"] | T[\"FailedTransaction\"]>\n | undefined;\n if (!inner) {\n throw new MetaAgError(msg, MetaAgErrorCode.SIMULATION_FAILED, {\n error: msg,\n });\n }\n return inner;\n};\n\n/**\n * Assert that `quote.provider` matches the expected provider kind. All\n * provider classes use this identical guard at the top of `swap`/`fastSwap`.\n */\nexport function assertQuoteProvider<E extends EProvider>(\n quote: MetaQuote,\n expected: E,\n): asserts quote is Extract<MetaQuote, { provider: E }> {\n MetaAgError.assert(\n quote.provider === expected,\n \"Invalid quote\",\n MetaAgErrorCode.INVALID_QUOTE,\n { quote, expectedProvider: expected },\n );\n}\n\nexport const simulateSwapTx = async (\n tx: Transaction,\n inspector: SuiClientUtils,\n simulation: MetaSimulationOptions,\n) => {\n const res = await timeout(\n () =>\n inspector.simulateTransaction({\n sender: simulation.sender,\n transactionBlock: tx,\n }),\n simulation.timeout ?? 2000,\n );\n const result = unwrapTxResult(res, \"Simulation failed\");\n const status = result.effects.status;\n if (!status.success) {\n const errorMessage = status.error.message ?? \"Simulation failed\";\n throw new MetaAgError(errorMessage, MetaAgErrorCode.SIMULATION_FAILED, {\n error: errorMessage,\n });\n }\n const amountOut = extractAmountOutWrapper(result.events ?? []);\n return {\n simulatedAmountOut: amountOut,\n gasUsed: result.effects.gasUsed,\n };\n};\nexport const simulateAggregator = async (\n provider: AggregatorProvider,\n quote: MetaQuote,\n simulation: MetaSimulationOptions,\n inspector: SuiClientUtils,\n options: Required<MetaAgOptions>,\n) => {\n const tx = new Transaction();\n const coinOut = await provider.swap({\n quote,\n coinIn: coinWithBalance({\n balance: BigInt(quote.amountIn),\n type: quote.coinTypeIn,\n useGasCoin: false,\n }),\n signer: simulation.sender,\n tx,\n });\n tx.add(\n metaSettle(\n quote,\n coinOut,\n 10000,\n options.tipBps,\n options.partner,\n options.partnerCommissionBps,\n ),\n );\n tx.transferObjects([coinOut], simulation.sender);\n const res = await simulateSwapTx(tx, inspector, simulation);\n return {\n id: quote.id,\n provider: provider.kind,\n ...res,\n };\n};\n\n/**\n * this settlement does not charge commission fee for partner, since all integrated aggregators already charge commission fee for partner\n * @param quote Meta Aggregator Quote\n * @param coinOut Coin Out Object\n * @param slippageBps Slippage Bps\n * @param tipBps Tip Bps default = 0\n * @param partner address of partner for analytic default is zero address\n */\nexport const metaSettle = (\n quote: MetaQuote,\n coinOut: TransactionObjectArgument,\n slippageBps = 100,\n tipBps = 0,\n partner?: string,\n commissionBps = 0,\n) => {\n return (tx: Transaction) => {\n const { minAmount, expectedAmount } = getExpectedReturn(\n quote.rawAmountOut,\n slippageBps,\n commissionBps,\n tipBps,\n );\n\n if (tipBps > 0) {\n tx.moveCall({\n target: `${_7K_META_PUBLISHED_AT}::vault::collect_tip`,\n typeArguments: [quote.coinTypeOut],\n arguments: [\n tx.object(_7K_META_VAULT),\n tx.object(_7K_META_CONFIG),\n coinOut,\n tx.pure.u64(tipBps),\n ],\n });\n }\n\n tx.moveCall({\n target: `${_7K_META_PUBLISHED_AT}::settle::settle`,\n typeArguments: [quote.coinTypeIn, quote.coinTypeOut],\n arguments: [\n tx.object(_7K_META_CONFIG),\n tx.object(_7K_META_VAULT),\n tx.pure.u64(quote.amountIn),\n coinOut,\n tx.pure.u64(minAmount),\n tx.pure.u64(expectedAmount),\n tx.pure.option(\"address\", partner),\n tx.pure.u64(commissionBps),\n tx.pure.u64(0), // ps\n ],\n });\n };\n};\n\nconst extractAmountOutWrapper = (events: SimulatedEvent[]) => {\n const swapEvent = events\n .filter(\n (event) => event.eventType === `${_7K_META_PACKAGE_ID}::settle::Swap`,\n )\n ?.pop();\n const json = swapEvent?.json as { amount_out?: string } | null | undefined;\n return json?.amount_out;\n};\n\nexport const timeout = async <T>(\n fn: () => Promise<T>,\n timeout: number,\n msg?: string,\n): Promise<T> => {\n if (timeout <= 0) return fn();\n return new Promise<T>((resolve, reject) => {\n const timer = setTimeout(\n () =>\n reject(\n new MetaAgError(\n `Timeout ${msg ?? \"operation\"}`,\n MetaAgErrorCode.TIMEOUT,\n { timeout },\n ),\n ),\n timeout,\n );\n fn()\n .then(resolve)\n .catch(reject)\n .finally(() => clearTimeout(timer));\n });\n};\n","/**\n * Calculate expected return amount after applying slippage, commission, and tip\n * @param returnAmount - The raw return amount (with decimals)\n * @param slippageBps - Slippage in basis points (1 bps = 0.01%)\n * @param commissionBps - Commission in basis points\n * @param tipBps - Tip in basis points (default: 0)\n * @returns Object containing tipAmount, minAmount, commissionAmount, and expectedAmount\n */\nexport const getExpectedReturn = (\n returnAmount: string,\n slippageBps: number,\n commissionBps: number,\n tipBps: number = 0,\n) => {\n if (slippageBps > 10000) {\n throw new Error(\"Slippage must be less than 100%\");\n }\n if (commissionBps > 10000) {\n throw new Error(\"Commission must be less than 100%\");\n }\n if (tipBps > 10000) {\n throw new Error(\"Tip must be less than 100%\");\n }\n const returnAmountWithDecimal = BigInt(returnAmount);\n const tipAmountWithDecimal =\n (returnAmountWithDecimal * BigInt(tipBps || 0)) / 10000n;\n const commissionAmountWithDecimal =\n ((returnAmountWithDecimal - tipAmountWithDecimal) * BigInt(commissionBps)) /\n 10000n;\n const expectedReturnWithDecimal =\n returnAmountWithDecimal -\n tipAmountWithDecimal -\n commissionAmountWithDecimal;\n const minAmountWithDecimal =\n (expectedReturnWithDecimal * BigInt(1e4 - slippageBps)) / 10000n;\n\n return {\n tipAmount: tipAmountWithDecimal,\n minAmount: minAmountWithDecimal,\n commissionAmount: commissionAmountWithDecimal,\n expectedAmount: expectedReturnWithDecimal.toString(10),\n };\n};\n"]}
@@ -0,0 +1,2 @@
1
+ import{a as o,h as i,j as n,k as u}from"./chunk-CYI4MM5C.mjs";import{AggregatorQuoter as a,Commission as m,CommissionType as c,TradeBuilder as p}from"@flowx-finance/sdk";import{v4 as d}from"uuid";var s=class{constructor(t,e){this.options=t;this.client=e;o(this,"kind","flowx");o(this,"quoter");this.quoter=new a("mainnet",t.apiKey)}async quote(t){let e=await this.quoter.getRoutes({amountIn:t.amountIn,tokenIn:t.coinTypeIn,tokenOut:t.coinTypeOut,includeSources:this.options.sources,excludePools:this.options.excludePools,excludeSources:this.options.excludeSources,maxHops:this.options.maxHops,splitDistributionPercent:this.options.splitDistributionPercent});return{id:d(),provider:"flowx",quote:e,amountIn:e.amountIn?.toString()??"0",rawAmountOut:e.amountOut?.toString()??"0",amountOut:e.amountOut?.toString()??"0",coinTypeIn:t.coinTypeIn,coinTypeOut:t.coinTypeOut}}async swap(t){u(t.quote,"flowx");let e=new p("mainnet",t.quote.quote.routes);e.sender(t.signer),e.slippage(1e4*100),e.commission(new m(i,t.quote.quote.coinOut,c.PERCENTAGE,0,!0));let r=await e.build().swap({tx:t.tx,client:this.client,coinIn:t.coinIn});return n.assert(!!r,"FlowX swap returned no coin out",1004,{quote:t.quote,expectedProvider:"flowx"}),r}};export{s as FlowxProvider};
2
+ //# sourceMappingURL=flowx-FTPJ3RYF.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/features/metaAg/providers/flowx.ts"],"sourcesContent":["import {\n AggregatorQuoter,\n Commission,\n CommissionType,\n TradeBuilder,\n} from \"@flowx-finance/sdk\";\nimport { ClientWithCoreApi } from \"@mysten/sui/client\";\nimport { SuiGrpcClient } from \"@mysten/sui/grpc\";\nimport { TransactionObjectArgument } from \"@mysten/sui/transactions\";\nimport { v4 } from \"uuid\";\nimport { _7K_PARTNER_ADDRESS } from \"../../../constants/_7k\";\nimport {\n AggregatorProvider,\n EProvider,\n FlowxProviderOptions,\n MetaQuote,\n MetaQuoteOptions,\n MetaSwapOptions,\n QuoteProvider,\n} from \"../../../types/metaAg\";\nimport { assertQuoteProvider } from \"../common\";\nimport { MetaAgError, MetaAgErrorCode } from \"../error\";\n\nexport class FlowxProvider implements QuoteProvider, AggregatorProvider {\n readonly kind = EProvider.FLOWX;\n private quoter: AggregatorQuoter;\n constructor(\n private readonly options: FlowxProviderOptions,\n private readonly client: ClientWithCoreApi,\n ) {\n this.quoter = new AggregatorQuoter(\"mainnet\", options.apiKey);\n }\n\n async quote(quoteOptions: MetaQuoteOptions): Promise<MetaQuote> {\n const quote = await this.quoter.getRoutes({\n amountIn: quoteOptions.amountIn,\n tokenIn: quoteOptions.coinTypeIn,\n tokenOut: quoteOptions.coinTypeOut,\n includeSources: this.options.sources,\n excludePools: this.options.excludePools,\n excludeSources: this.options.excludeSources,\n maxHops: this.options.maxHops,\n splitDistributionPercent: this.options.splitDistributionPercent,\n });\n return {\n id: v4(),\n provider: EProvider.FLOWX,\n quote: quote,\n amountIn: quote.amountIn?.toString() ?? \"0\",\n rawAmountOut: quote.amountOut?.toString() ?? \"0\",\n amountOut: quote.amountOut?.toString() ?? \"0\",\n coinTypeIn: quoteOptions.coinTypeIn,\n coinTypeOut: quoteOptions.coinTypeOut,\n };\n }\n\n async swap(options: MetaSwapOptions): Promise<TransactionObjectArgument> {\n assertQuoteProvider(options.quote, EProvider.FLOWX);\n const builder = new TradeBuilder(\"mainnet\", options.quote.quote.routes);\n builder.sender(options.signer);\n builder.slippage(10000 * 100);\n builder.commission(\n new Commission(\n _7K_PARTNER_ADDRESS,\n options.quote.quote.coinOut,\n CommissionType.PERCENTAGE,\n 0,\n true,\n ),\n );\n const res = await builder.build().swap({\n tx: options.tx,\n client: this.client as unknown as SuiGrpcClient,\n coinIn: options.coinIn,\n });\n MetaAgError.assert(\n !!res,\n \"FlowX swap returned no coin out\",\n MetaAgErrorCode.INVALID_QUOTE,\n { quote: options.quote,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AY,OACV,CAAC,CAACD,EACF,uCAEA,CAAE,MAAOb,EAAQ,MAAO,wBAAkC,CAC5D,EACOa,CACT,CACF","names":["AggregatorQuoter","Commission","CommissionType","TradeBuilder","v4","FlowxProvider","options","client","__publicField","AggregatorQuoter","quoteOptions","quote","v4","assertQuoteProvider","builder","TradeBuilder","Commission","_7K_PARTNER_ADDRESS","CommissionType","res","MetaAgError"]}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkE5KM5OVWjs = require('./chunk-E5KM5OVW.js');var _sdk = require('@flowx-finance/sdk');var _uuid = require('uuid');var s=class{constructor(t,e){this.options=t;this.client=e;_chunkE5KM5OVWjs.a.call(void 0, this,"kind","flowx");_chunkE5KM5OVWjs.a.call(void 0, this,"quoter");this.quoter=new (0, _sdk.AggregatorQuoter)("mainnet",t.apiKey)}async quote(t){let e=await this.quoter.getRoutes({amountIn:t.amountIn,tokenIn:t.coinTypeIn,tokenOut:t.coinTypeOut,includeSources:this.options.sources,excludePools:this.options.excludePools,excludeSources:this.options.excludeSources,maxHops:this.options.maxHops,splitDistributionPercent:this.options.splitDistributionPercent});return{id:_uuid.v4.call(void 0, ),provider:"flowx",quote:e,amountIn:_nullishCoalesce(_optionalChain([e, 'access', _ => _.amountIn, 'optionalAccess', _2 => _2.toString, 'call', _3 => _3()]), () => ("0")),rawAmountOut:_nullishCoalesce(_optionalChain([e, 'access', _4 => _4.amountOut, 'optionalAccess', _5 => _5.toString, 'call', _6 => _6()]), () => ("0")),amountOut:_nullishCoalesce(_optionalChain([e, 'access', _7 => _7.amountOut, 'optionalAccess', _8 => _8.toString, 'call', _9 => _9()]), () => ("0")),coinTypeIn:t.coinTypeIn,coinTypeOut:t.coinTypeOut}}async swap(t){_chunkE5KM5OVWjs.k.call(void 0, t.quote,"flowx");let e=new (0, _sdk.TradeBuilder)("mainnet",t.quote.quote.routes);e.sender(t.signer),e.slippage(1e4*100),e.commission(new (0, _sdk.Commission)(_chunkE5KM5OVWjs.h,t.quote.quote.coinOut,_sdk.CommissionType.PERCENTAGE,0,!0));let r=await e.build().swap({tx:t.tx,client:this.client,coinIn:t.coinIn});return _chunkE5KM5OVWjs.j.assert(!!r,"FlowX swap returned no coin out",1004,{quote:t.quote,expectedProvider:"flowx"}),r}};exports.FlowxProvider = s;
2
+ //# sourceMappingURL=flowx-RRIX3SC4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/otis/Documents/7k-ts-sdk/dist/flowx-RRIX3SC4.js","../src/features/metaAg/providers/flowx.ts"],"names":["FlowxProvider","options","client","__publicField","AggregatorQuoter","quoteOptions","quote","v4","assertQuoteProvider","builder","TradeBuilder","Commission","_7K_PARTNER_ADDRESS","CommissionType","res","MetaAgError"],"mappings":"AAAA,uuBAA4D,yCCKrD,4BAIY,IAcNA,CAAAA,CAAN,KAAiE,CAGtE,WAAA,CACmBC,CAAAA,CACAC,CAAAA,CACjB,CAFiB,IAAA,CAAA,OAAA,CAAAD,CAAAA,CACA,IAAA,CAAA,MAAA,CAAAC,CAAAA,CAJnBC,gCAAAA,IAAA,CAAS,MAAA,CAAA,OAAA,CAAA,CACTA,gCAAAA,IAAA,CAAQ,QAAA,CAAA,CAKN,IAAA,CAAK,MAAA,CAAS,IAAIC,0BAAAA,CAAiB,SAAA,CAAWH,CAAAA,CAAQ,MAAM,CAC9D,CAEA,MAAM,KAAA,CAAMI,CAAAA,CAAoD,CAC9D,IAAMC,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AAA,CACFC,kBAAAA,CACAX,CAAAA,CAAQ,KAAA,CAAM,KAAA,CAAM,OAAA,CACpBY,mBAAAA,CAAe,UAAA,CACf,CAAA,CACA,CAAA,CACF,CACF,CAAA,CACA,IAAMC,CAAAA,CAAM,MAAML,CAAAA,CAAQ,KAAA,CAAM,CAAA,CAAE,IAAA,CAAK,CACrC,EAAA,CAAIR,CAAAA,CAAQ,EAAA,CACZ,MAAA,CAAQ,IAAA,CAAK,MAAA,CACb,MAAA,CAAQA,CAAAA,CAAQ,MAClB,CAAC,CAAA,CACD,OAAAc,kBAAAA,CAAY,MAAA,CACV,CAAC,CAACD,CAAAA,CACF,iCAAA,CAAA,IAAA,CAEA,CAAE,KAAA,CAAOb,CAAAA,CAAQ,KAAA,CAAO,gBAAA,CAAA,OAAkC,CAC5D,CAAA,CACOa,CACT,CACF,CAAA,CAAA,0BAAA","file":"/Users/otis/Documents/7k-ts-sdk/dist/flowx-RRIX3SC4.js","sourcesContent":[null,"import {\n AggregatorQuoter,\n Commission,\n CommissionType,\n TradeBuilder,\n} from \"@flowx-finance/sdk\";\nimport { ClientWithCoreApi } from \"@mysten/sui/client\";\nimport { SuiGrpcClient } from \"@mysten/sui/grpc\";\nimport { TransactionObjectArgument } from \"@mysten/sui/transactions\";\nimport { v4 } from \"uuid\";\nimport { _7K_PARTNER_ADDRESS } from \"../../../constants/_7k\";\nimport {\n AggregatorProvider,\n EProvider,\n FlowxProviderOptions,\n MetaQuote,\n MetaQuoteOptions,\n MetaSwapOptions,\n QuoteProvider,\n} from \"../../../types/metaAg\";\nimport { assertQuoteProvider } from \"../common\";\nimport { MetaAgError, MetaAgErrorCode } from \"../error\";\n\nexport class FlowxProvider implements QuoteProvider, AggregatorProvider {\n readonly kind = EProvider.FLOWX;\n private quoter: AggregatorQuoter;\n constructor(\n private readonly options: FlowxProviderOptions,\n private readonly client: ClientWithCoreApi,\n ) {\n this.quoter = new AggregatorQuoter(\"mainnet\", options.apiKey);\n }\n\n async quote(quoteOptions: MetaQuoteOptions): Promise<MetaQuote> {\n const quote = await this.quoter.getRoutes({\n amountIn: quoteOptions.amountIn,\n tokenIn: quoteOptions.coinTypeIn,\n tokenOut: quoteOptions.coinTypeOut,\n includeSources: this.options.sources,\n excludePools: this.options.excludePools,\n excludeSources: this.options.excludeSources,\n maxHops: this.options.maxHops,\n splitDistributionPercent: this.options.splitDistributionPercent,\n });\n return {\n id: v4(),\n provider: EProvider.FLOWX,\n quote: quote,\n amountIn: quote.amountIn?.toString() ?? \"0\",\n rawAmountOut: quote.amountOut?.toString() ?? \"0\",\n amountOut: quote.amountOut?.toString() ?? \"0\",\n coinTypeIn: quoteOptions.coinTypeIn,\n coinTypeOut: quoteOptions.coinTypeOut,\n };\n }\n\n async swap(options: MetaSwapOptions): Promise<TransactionObjectArgument> {\n assertQuoteProvider(options.quote, EProvider.FLOWX);\n const builder = new TradeBuilder(\"mainnet\", options.quote.quote.routes);\n builder.sender(options.signer);\n builder.slippage(10000 * 100);\n builder.commission(\n new Commission(\n _7K_PARTNER_ADDRESS,\n options.quote.quote.coinOut,\n CommissionType.PERCENTAGE,\n 0,\n true,\n ),\n );\n const res = await builder.build().swap({\n tx: options.tx,\n client: this.client as unknown as SuiGrpcClient,\n coinIn: options.coinIn,\n });\n MetaAgError.assert(\n !!res,\n \"FlowX swap returned no coin out\",\n MetaAgErrorCode.INVALID_QUOTE,\n { quote: options.quote, expectedProvider: EProvider.FLOWX },\n );\n return res;\n }\n}\n"]}
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { SourceDex, QuoteResponse } from '@bluefin-exchange/bluefin7k-aggregator-sdk';
2
2
  import { PreSwapLpChangeParams, RouterDataV3 } from '@cetusprotocol/aggregator-sdk';
3
3
  import { Protocol, AggregatorQuoter } from '@flowx-finance/sdk';
4
- import { GasCostSummary, SuiClient, GetTransactionBlockParams, SuiTransactionBlockResponse } from '@mysten/sui/client';
4
+ import { ClientWithCoreApi, SuiClientTypes, CoreClient } from '@mysten/sui/client';
5
5
  import { SignatureWithBytes } from '@mysten/sui/cryptography';
6
6
  import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
7
7
 
@@ -178,8 +178,28 @@ interface MetaAgOptions {
178
178
  [EProvider.CETUS]?: CetusProviderOptions;
179
179
  [EProvider.OKX]?: OkxProviderOptions;
180
180
  };
181
- /**Mainnet Json Rpc url, if not specified, the default mainnet url will be used */
182
- fullnodeUrl?: string;
181
+ /**
182
+ * Sui client to use for on-chain reads, simulation, and execution. Accepts
183
+ * any v2 `ClientWithCoreApi` implementation (`SuiGrpcClient`,
184
+ * `SuiGraphQLClient`, `SuiJsonRpcClient`, or a custom transport). If not
185
+ * specified, a default `SuiGrpcClient` against Sui mainnet is constructed.
186
+ *
187
+ * @warning **Cetus provider compatibility**: `@cetusprotocol/aggregator-sdk`
188
+ * is **only fully compatible with `SuiJsonRpcClient`**. It calls legacy
189
+ * JSON-RPC-only methods (`getDynamicFieldObject`, `getCoins`,
190
+ * `getOwnedObjects`, `devInspectTransactionBlock`) for specific routes:
191
+ *
192
+ * - Pyth-priced routes (uses `getDynamicFieldObject` to resolve price
193
+ * feeds in `routerSwap`).
194
+ * - DeepBookV3 routes (uses `getCoins` for coin merging and
195
+ * `getOwnedObjects` to mint/find an account cap).
196
+ *
197
+ * Passing a `SuiGrpcClient` / `SuiGraphQLClient` will work for plain
198
+ * `findRouters + routerSwap` routes but **will throw at runtime** for the
199
+ * cases above. If you need full Cetus coverage, pass a `SuiJsonRpcClient`
200
+ * here (or disable the Cetus provider, or update to the latest cetus sdk that fully compatible with any sui client).
201
+ */
202
+ client?: ClientWithCoreApi;
183
203
  /**Hermes Api url, if not specified, the default hermes api url will be used */
184
204
  hermesApi?: string;
185
205
  /**Address to receive commission, if not specified, the commission will not be used */
@@ -273,7 +293,7 @@ type MetaQuote = ({
273
293
  /** Simulated amount out if the transaction is executed */
274
294
  simulatedAmountOut?: string;
275
295
  /** Estimate gas consumption if the transaction is executed */
276
- gasUsed?: GasCostSummary;
296
+ gasUsed?: SuiClientTypes.GasCostSummary;
277
297
  };
278
298
  interface QuoteProvider {
279
299
  readonly kind: EProvider;
@@ -290,8 +310,26 @@ interface AggregatorProvider extends QuoteProvider {
290
310
  declare const isAggregatorProvider: (provider: QuoteProvider) => provider is AggregatorProvider;
291
311
  declare const isSwapAPIProvider: (provider: QuoteProvider) => provider is SwapAPIProvider;
292
312
 
313
+ /** Result type returned by `MetaAg.fastSwap` (transport-agnostic v2 shape). */
314
+ type MetaTransactionResult = Awaited<ReturnType<CoreClient["executeTransaction"]>>;
315
+ /** Subset of v2 `TransactionInclude` flags exposed by `MetaAg.fastSwap`. */
316
+ interface MetaExecuteInclude {
317
+ balanceChanges?: boolean;
318
+ effects?: boolean;
319
+ events?: boolean;
320
+ objectTypes?: boolean;
321
+ }
322
+ interface ExecuteTransactionExtraOptions {
323
+ signal?: AbortSignal;
324
+ /**
325
+ * Flags forwarded to the gRPC `executeTransaction`/`waitForTransaction`
326
+ * call. When omitted, the result contains `digest`/`signatures` only; pass
327
+ * `{ effects: true, events: true }` to populate the corresponding fields.
328
+ */
329
+ include?: MetaExecuteInclude;
330
+ }
293
331
  declare class MetaAg {
294
- client: SuiClient;
332
+ client: ClientWithCoreApi;
295
333
  private providers;
296
334
  private inspector;
297
335
  private options;
@@ -321,7 +359,7 @@ declare class MetaAg {
321
359
  * @param options - fast swap options
322
360
  * @returns - txDigest of the transaction
323
361
  */
324
- fastSwap(options: MetaFastSwapOptions, getTransactionBlockParams?: Omit<GetTransactionBlockParams, "digest">): Promise<SuiTransactionBlockResponse>;
362
+ fastSwap(options: MetaFastSwapOptions, extraOptions?: ExecuteTransactionExtraOptions): Promise<MetaTransactionResult>;
325
363
  /**
326
364
  * Update meta aggregator options
327
365
  * @param options - update options payload
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { SourceDex, QuoteResponse } from '@bluefin-exchange/bluefin7k-aggregator-sdk';
2
2
  import { PreSwapLpChangeParams, RouterDataV3 } from '@cetusprotocol/aggregator-sdk';
3
3
  import { Protocol, AggregatorQuoter } from '@flowx-finance/sdk';
4
- import { GasCostSummary, SuiClient, GetTransactionBlockParams, SuiTransactionBlockResponse } from '@mysten/sui/client';
4
+ import { ClientWithCoreApi, SuiClientTypes, CoreClient } from '@mysten/sui/client';
5
5
  import { SignatureWithBytes } from '@mysten/sui/cryptography';
6
6
  import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
7
7
 
@@ -178,8 +178,28 @@ interface MetaAgOptions {
178
178
  [EProvider.CETUS]?: CetusProviderOptions;
179
179
  [EProvider.OKX]?: OkxProviderOptions;
180
180
  };
181
- /**Mainnet Json Rpc url, if not specified, the default mainnet url will be used */
182
- fullnodeUrl?: string;
181
+ /**
182
+ * Sui client to use for on-chain reads, simulation, and execution. Accepts
183
+ * any v2 `ClientWithCoreApi` implementation (`SuiGrpcClient`,
184
+ * `SuiGraphQLClient`, `SuiJsonRpcClient`, or a custom transport). If not
185
+ * specified, a default `SuiGrpcClient` against Sui mainnet is constructed.
186
+ *
187
+ * @warning **Cetus provider compatibility**: `@cetusprotocol/aggregator-sdk`
188
+ * is **only fully compatible with `SuiJsonRpcClient`**. It calls legacy
189
+ * JSON-RPC-only methods (`getDynamicFieldObject`, `getCoins`,
190
+ * `getOwnedObjects`, `devInspectTransactionBlock`) for specific routes:
191
+ *
192
+ * - Pyth-priced routes (uses `getDynamicFieldObject` to resolve price
193
+ * feeds in `routerSwap`).
194
+ * - DeepBookV3 routes (uses `getCoins` for coin merging and
195
+ * `getOwnedObjects` to mint/find an account cap).
196
+ *
197
+ * Passing a `SuiGrpcClient` / `SuiGraphQLClient` will work for plain
198
+ * `findRouters + routerSwap` routes but **will throw at runtime** for the
199
+ * cases above. If you need full Cetus coverage, pass a `SuiJsonRpcClient`
200
+ * here (or disable the Cetus provider, or update to the latest cetus sdk that fully compatible with any sui client).
201
+ */
202
+ client?: ClientWithCoreApi;
183
203
  /**Hermes Api url, if not specified, the default hermes api url will be used */
184
204
  hermesApi?: string;
185
205
  /**Address to receive commission, if not specified, the commission will not be used */
@@ -273,7 +293,7 @@ type MetaQuote = ({
273
293
  /** Simulated amount out if the transaction is executed */
274
294
  simulatedAmountOut?: string;
275
295
  /** Estimate gas consumption if the transaction is executed */
276
- gasUsed?: GasCostSummary;
296
+ gasUsed?: SuiClientTypes.GasCostSummary;
277
297
  };
278
298
  interface QuoteProvider {
279
299
  readonly kind: EProvider;
@@ -290,8 +310,26 @@ interface AggregatorProvider extends QuoteProvider {
290
310
  declare const isAggregatorProvider: (provider: QuoteProvider) => provider is AggregatorProvider;
291
311
  declare const isSwapAPIProvider: (provider: QuoteProvider) => provider is SwapAPIProvider;
292
312
 
313
+ /** Result type returned by `MetaAg.fastSwap` (transport-agnostic v2 shape). */
314
+ type MetaTransactionResult = Awaited<ReturnType<CoreClient["executeTransaction"]>>;
315
+ /** Subset of v2 `TransactionInclude` flags exposed by `MetaAg.fastSwap`. */
316
+ interface MetaExecuteInclude {
317
+ balanceChanges?: boolean;
318
+ effects?: boolean;
319
+ events?: boolean;
320
+ objectTypes?: boolean;
321
+ }
322
+ interface ExecuteTransactionExtraOptions {
323
+ signal?: AbortSignal;
324
+ /**
325
+ * Flags forwarded to the gRPC `executeTransaction`/`waitForTransaction`
326
+ * call. When omitted, the result contains `digest`/`signatures` only; pass
327
+ * `{ effects: true, events: true }` to populate the corresponding fields.
328
+ */
329
+ include?: MetaExecuteInclude;
330
+ }
293
331
  declare class MetaAg {
294
- client: SuiClient;
332
+ client: ClientWithCoreApi;
295
333
  private providers;
296
334
  private inspector;
297
335
  private options;
@@ -321,7 +359,7 @@ declare class MetaAg {
321
359
  * @param options - fast swap options
322
360
  * @returns - txDigest of the transaction
323
361
  */
324
- fastSwap(options: MetaFastSwapOptions, getTransactionBlockParams?: Omit<GetTransactionBlockParams, "digest">): Promise<SuiTransactionBlockResponse>;
362
+ fastSwap(options: MetaFastSwapOptions, extraOptions?: ExecuteTransactionExtraOptions): Promise<MetaTransactionResult>;
325
363
  /**
326
364
  * Update meta aggregator options
327
365
  * @param options - update options payload