@7kprotocol/sdk-ts 3.5.0 → 3.5.2-beta.0

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 (104) hide show
  1. package/README.md +45 -171
  2. package/lib/cjs/config/index.js +9 -0
  3. package/lib/cjs/constants/_7k.js +2 -1
  4. package/lib/cjs/features/metaAg/common.js +117 -0
  5. package/lib/cjs/features/metaAg/index.js +88 -93
  6. package/lib/cjs/features/metaAg/providers/astro.js +42 -0
  7. package/lib/cjs/features/metaAg/providers/bluefin.js +8 -8
  8. package/lib/cjs/features/metaAg/providers/bluefinx.js +87 -0
  9. package/lib/cjs/features/metaAg/providers/cetus.js +7 -4
  10. package/lib/cjs/features/metaAg/providers/flowx.js +6 -4
  11. package/lib/cjs/features/metaAg/providers/okx.js +181 -0
  12. package/lib/cjs/features/swap/buildTx.js +3 -0
  13. package/lib/cjs/features/swap/buildTxV2.js +10 -6
  14. package/lib/cjs/features/swap/config.js +2 -1
  15. package/lib/cjs/features/swap/getQuote.js +3 -2
  16. package/lib/cjs/libs/protocols/bluefinx/client.js +1 -1
  17. package/lib/cjs/types/config/index.d.ts +4 -0
  18. package/lib/cjs/types/config/index.d.ts.map +1 -1
  19. package/lib/cjs/types/constants/_7k.d.ts +1 -0
  20. package/lib/cjs/types/constants/_7k.d.ts.map +1 -1
  21. package/lib/cjs/types/features/metaAg/common.d.ts +33 -0
  22. package/lib/cjs/types/features/metaAg/common.d.ts.map +1 -0
  23. package/lib/cjs/types/features/metaAg/index.d.ts +11 -2
  24. package/lib/cjs/types/features/metaAg/index.d.ts.map +1 -1
  25. package/lib/cjs/types/features/metaAg/providers/astro.d.ts +9 -0
  26. package/lib/cjs/types/features/metaAg/providers/astro.d.ts.map +1 -0
  27. package/lib/cjs/types/features/metaAg/providers/bluefin.d.ts +3 -3
  28. package/lib/cjs/types/features/metaAg/providers/bluefin.d.ts.map +1 -1
  29. package/lib/cjs/types/features/metaAg/providers/bluefinx.d.ts +10 -0
  30. package/lib/cjs/types/features/metaAg/providers/bluefinx.d.ts.map +1 -0
  31. package/lib/cjs/types/features/metaAg/providers/cetus.d.ts +4 -5
  32. package/lib/cjs/types/features/metaAg/providers/cetus.d.ts.map +1 -1
  33. package/lib/cjs/types/features/metaAg/providers/flowx.d.ts +3 -3
  34. package/lib/cjs/types/features/metaAg/providers/flowx.d.ts.map +1 -1
  35. package/lib/cjs/types/features/metaAg/providers/okx.d.ts +21 -0
  36. package/lib/cjs/types/features/metaAg/providers/okx.d.ts.map +1 -0
  37. package/lib/cjs/types/features/swap/buildTx.d.ts.map +1 -1
  38. package/lib/cjs/types/features/swap/buildTxV2.d.ts +3 -3
  39. package/lib/cjs/types/features/swap/buildTxV2.d.ts.map +1 -1
  40. package/lib/cjs/types/features/swap/config.d.ts.map +1 -1
  41. package/lib/cjs/types/features/swap/getQuote.d.ts +1 -3
  42. package/lib/cjs/types/features/swap/getQuote.d.ts.map +1 -1
  43. package/lib/cjs/types/index.d.ts +3 -1
  44. package/lib/cjs/types/index.d.ts.map +1 -1
  45. package/lib/cjs/types/metaAg.js +11 -4
  46. package/lib/cjs/types/okx.js +6 -0
  47. package/lib/cjs/types/types/metaAg.d.ts +60 -8
  48. package/lib/cjs/types/types/metaAg.d.ts.map +1 -1
  49. package/lib/cjs/types/types/okx.d.ts +193 -0
  50. package/lib/cjs/types/types/okx.d.ts.map +1 -0
  51. package/lib/cjs/types/utils/condition.d.ts +1 -1
  52. package/lib/cjs/types/utils/condition.d.ts.map +1 -1
  53. package/lib/esm/config/index.js +9 -0
  54. package/lib/esm/constants/_7k.js +1 -0
  55. package/lib/esm/features/metaAg/common.js +109 -0
  56. package/lib/esm/features/metaAg/index.js +89 -94
  57. package/lib/esm/features/metaAg/providers/astro.js +39 -0
  58. package/lib/esm/features/metaAg/providers/bluefin.js +8 -8
  59. package/lib/esm/features/metaAg/providers/bluefinx.js +84 -0
  60. package/lib/esm/features/metaAg/providers/cetus.js +7 -4
  61. package/lib/esm/features/metaAg/providers/flowx.js +7 -5
  62. package/lib/esm/features/metaAg/providers/okx.js +146 -0
  63. package/lib/esm/features/swap/buildTx.js +3 -0
  64. package/lib/esm/features/swap/buildTxV2.js +6 -2
  65. package/lib/esm/features/swap/config.js +2 -1
  66. package/lib/esm/features/swap/getQuote.js +3 -2
  67. package/lib/esm/libs/protocols/bluefinx/client.js +1 -1
  68. package/lib/esm/types/config/index.d.ts +4 -0
  69. package/lib/esm/types/config/index.d.ts.map +1 -1
  70. package/lib/esm/types/constants/_7k.d.ts +1 -0
  71. package/lib/esm/types/constants/_7k.d.ts.map +1 -1
  72. package/lib/esm/types/features/metaAg/common.d.ts +33 -0
  73. package/lib/esm/types/features/metaAg/common.d.ts.map +1 -0
  74. package/lib/esm/types/features/metaAg/index.d.ts +11 -2
  75. package/lib/esm/types/features/metaAg/index.d.ts.map +1 -1
  76. package/lib/esm/types/features/metaAg/providers/astro.d.ts +9 -0
  77. package/lib/esm/types/features/metaAg/providers/astro.d.ts.map +1 -0
  78. package/lib/esm/types/features/metaAg/providers/bluefin.d.ts +3 -3
  79. package/lib/esm/types/features/metaAg/providers/bluefin.d.ts.map +1 -1
  80. package/lib/esm/types/features/metaAg/providers/bluefinx.d.ts +10 -0
  81. package/lib/esm/types/features/metaAg/providers/bluefinx.d.ts.map +1 -0
  82. package/lib/esm/types/features/metaAg/providers/cetus.d.ts +4 -5
  83. package/lib/esm/types/features/metaAg/providers/cetus.d.ts.map +1 -1
  84. package/lib/esm/types/features/metaAg/providers/flowx.d.ts +3 -3
  85. package/lib/esm/types/features/metaAg/providers/flowx.d.ts.map +1 -1
  86. package/lib/esm/types/features/metaAg/providers/okx.d.ts +21 -0
  87. package/lib/esm/types/features/metaAg/providers/okx.d.ts.map +1 -0
  88. package/lib/esm/types/features/swap/buildTx.d.ts.map +1 -1
  89. package/lib/esm/types/features/swap/buildTxV2.d.ts +3 -3
  90. package/lib/esm/types/features/swap/buildTxV2.d.ts.map +1 -1
  91. package/lib/esm/types/features/swap/config.d.ts.map +1 -1
  92. package/lib/esm/types/features/swap/getQuote.d.ts +1 -3
  93. package/lib/esm/types/features/swap/getQuote.d.ts.map +1 -1
  94. package/lib/esm/types/index.d.ts +3 -1
  95. package/lib/esm/types/index.d.ts.map +1 -1
  96. package/lib/esm/types/metaAg.js +8 -2
  97. package/lib/esm/types/okx.js +5 -0
  98. package/lib/esm/types/types/metaAg.d.ts +60 -8
  99. package/lib/esm/types/types/metaAg.d.ts.map +1 -1
  100. package/lib/esm/types/types/okx.d.ts +193 -0
  101. package/lib/esm/types/types/okx.d.ts.map +1 -0
  102. package/lib/esm/types/utils/condition.d.ts +1 -1
  103. package/lib/esm/types/utils/condition.d.ts.map +1 -1
  104. package/package.json +3 -2
@@ -0,0 +1,193 @@
1
+ /**
2
+ * OKX DEX Swap API Types
3
+ * Documentation: https://web3.okx.com/vi/build/docs/waas/dex-swap
4
+ */
5
+ /**
6
+ * Gas level options for swap transactions
7
+ */
8
+ export type GasLevel = "average" | "fast" | "slow";
9
+ /**
10
+ * Swap API Request Parameters
11
+ */
12
+ export interface OkxSwapRequest {
13
+ /** Chain ID (e.g., 1 for Ethereum) */
14
+ chainId: string;
15
+ /** The input amount of a token to be sold (set in minimal divisible units) */
16
+ amount: string;
17
+ /** The contract address of a token you want to send (e.g., 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee for native token) */
18
+ fromTokenAddress: string;
19
+ /** The contract address of a token you want to receive */
20
+ toTokenAddress: string;
21
+ /** Slippage limit (0-1 for EVM, 0-less than 1 for Solana) */
22
+ slippage: string;
23
+ /** User's wallet address */
24
+ userWalletAddress: string;
25
+ /** Recipient address of a purchased token (if not set, userWalletAddress will receive the token) */
26
+ swapReceiverAddress?: string;
27
+ /** The percentage of fromTokenAmount or toTokenAmount sent to referrer (0-3, max 2 decimal points) */
28
+ feePercent?: string;
29
+ /** Wallet address to receive commission fee from fromToken */
30
+ fromTokenReferrerWalletAddress?: string;
31
+ /** Wallet address to receive commission fee from toToken */
32
+ toTokenReferrerWalletAddress?: string;
33
+ /** When true, positive slippage revenue sent to referrer's address (default: false) */
34
+ enablePositiveSlippage?: boolean;
35
+ /** The gas (in wei) for the swap transaction */
36
+ gaslimit?: string;
37
+ /** Target gas price level (defaults to "average") */
38
+ gasLevel?: GasLevel;
39
+ /** DexId of liquidity pool for limited quotes, multiple separated by comma (e.g., "1,50,180") */
40
+ dexIds?: string;
41
+ /** When enabled, restricts routing to single liquidity pool (Solana only, default: false) */
42
+ directRoute?: boolean;
43
+ /** Percentage (0-1.0) of price impact allowed (default: 0.9) */
44
+ priceImpactProtectionPercentage?: string;
45
+ /** Custom parameters encoded as 128-character 64-bytes hexadecimal string (must start with "0x") */
46
+ callDataMemo?: string;
47
+ /** Used for Solana transactions, similar to gasPrice on Ethereum */
48
+ computeUnitPrice?: string;
49
+ /** Used for Solana transactions, similar to gasLimit on Ethereum */
50
+ computeUnitLimit?: string;
51
+ /** When true, API calculates auto slippage recommendations (default: false) */
52
+ autoSlippage?: boolean;
53
+ /** Maximum auto slippage when autoSlippage is true */
54
+ maxAutoSlippage?: string;
55
+ }
56
+ /**
57
+ * Token information
58
+ */
59
+ export interface OkxTokenInfo {
60
+ /** Token contract address */
61
+ tokenContractAddress: string;
62
+ /** Token symbol (e.g., "USDC") */
63
+ tokenSymbol: string;
64
+ /** Token unit price in USD (may be null for special cases) */
65
+ tokenUnitPrice: string | null;
66
+ /** Decimal number defining smallest unit */
67
+ decimal: string;
68
+ /** Whether the token is a honeypot token */
69
+ isHoneyPot: boolean;
70
+ /** Token tax rate (0-1, where 0.01 = 1%) */
71
+ taxRate: string;
72
+ }
73
+ /**
74
+ * DEX Protocol information
75
+ */
76
+ export interface OkxDexProtocol {
77
+ /** Name of the liquidity protocol (e.g., "Uniswap V3") */
78
+ dexName: string;
79
+ /** Percentage of assets handled by the protocol */
80
+ percent: string;
81
+ }
82
+ /**
83
+ * Sub-router information
84
+ */
85
+ export interface OkxSubRouter {
86
+ /** Liquidity protocols used on the path */
87
+ dexProtocol: OkxDexProtocol[];
88
+ /** Information of token to be sold */
89
+ fromToken: OkxTokenInfo;
90
+ /** Information of token to be bought */
91
+ toToken: OkxTokenInfo;
92
+ }
93
+ /**
94
+ * Main router information
95
+ */
96
+ export interface OkxRouter {
97
+ /** One of the main paths for the token swap */
98
+ router: string;
99
+ /** Percentage of assets handled by the main path */
100
+ routerPercent: string;
101
+ /** Quote path sub data set */
102
+ subRouterList: OkxSubRouter[];
103
+ }
104
+ /**
105
+ * Quote comparison information
106
+ */
107
+ export interface OkxQuoteCompare {
108
+ /** DEX name of the quote route */
109
+ dexName: string;
110
+ /** DEX logo of the quote route */
111
+ dexLogo: string;
112
+ /** Estimated network fee (USD) of the quote route */
113
+ tradeFee: string;
114
+ /** Received amount of the quote route */
115
+ amountOut: string;
116
+ /** Price impact percentage */
117
+ priceImpactPercentage: string;
118
+ }
119
+ /**
120
+ * Transaction data model
121
+ */
122
+ export interface OkxTransactionData {
123
+ /** Additional signing data (if required) */
124
+ signatureData?: string[];
125
+ /** User's wallet address */
126
+ from: string;
127
+ /** Estimated amount of the gas limit */
128
+ gas: string;
129
+ /** Gas price in wei */
130
+ gasPrice?: string;
131
+ /** EIP-1559: Recommended priority cost of gas per unit */
132
+ maxPriorityFeePerGas?: string;
133
+ /** The contract address of OKX DEX router */
134
+ to: string;
135
+ /** The amount of native tokens (in wei) to be sent to the contract */
136
+ value: string;
137
+ /** Minimum amount of token to buy when price reaches slippage limit */
138
+ minReceiveAmount: string;
139
+ /** Call data */
140
+ data: string;
141
+ /** Current transaction slippage value */
142
+ slippage: string;
143
+ }
144
+ /**
145
+ * Router result data
146
+ */
147
+ export interface OkxRouterResult {
148
+ /** Chain ID */
149
+ chainId: string;
150
+ /** The input amount of a token to be sold */
151
+ fromTokenAmount: string;
152
+ /** The resulting amount of a token to be bought */
153
+ toTokenAmount: string;
154
+ /** Estimated network fee (USD) of the quote route */
155
+ tradeFee: string;
156
+ /** Estimated gas consumption in smallest units (e.g., wei) */
157
+ estimateGasFee: string;
158
+ /** Quote path data set */
159
+ dexRouterList: OkxRouter[];
160
+ /** Information of token to be sold */
161
+ fromToken: OkxTokenInfo;
162
+ /** Information of token to be bought */
163
+ toToken: OkxTokenInfo;
164
+ /** Price impact percentage */
165
+ priceImpactPercentage?: string;
166
+ /** Comparison of quote routes */
167
+ quoteCompareList?: OkxQuoteCompare[];
168
+ }
169
+ /**
170
+ * Swap API Response Data
171
+ */
172
+ export interface OkxSwapResponseData {
173
+ /** Quote path data */
174
+ routerResult: OkxRouterResult;
175
+ /** Contract data model */
176
+ tx: OkxTransactionData;
177
+ }
178
+ /**
179
+ * OKX API Standard Response Wrapper
180
+ */
181
+ export interface OkxApiResponse<T> {
182
+ /** Response code ("0" indicates success) */
183
+ code: string;
184
+ /** Response data array */
185
+ data: T[];
186
+ /** Response message */
187
+ msg: string;
188
+ }
189
+ /**
190
+ * Complete Swap API Response
191
+ */
192
+ export type OkxSwapResponse = OkxApiResponse<OkxSwapResponseData>;
193
+ //# sourceMappingURL=okx.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"okx.d.ts","sourceRoot":"","sources":["../../../../src/types/okx.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,8EAA8E;IAC9E,MAAM,EAAE,MAAM,CAAC;IACf,2HAA2H;IAC3H,gBAAgB,EAAE,MAAM,CAAC;IACzB,0DAA0D;IAC1D,cAAc,EAAE,MAAM,CAAC;IACvB,6DAA6D;IAC7D,QAAQ,EAAE,MAAM,CAAC;IACjB,4BAA4B;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,oGAAoG;IACpG,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B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AAE,MAAM,CAAC;IACxB,mDAAmD;IACnD,aAAa,EAAE,MAAM,CAAC;IACtB,qDAAqD;IACrD,QAAQ,EAAE,MAAM,CAAC;IACjB,8DAA8D;IAC9D,cAAc,EAAE,MAAM,CAAC;IACvB,0BAA0B;IAC1B,aAAa,EAAE,SAAS,EAAE,CAAC;IAC3B,sCAAsC;IACtC,SAAS,EAAE,YAAY,CAAC;IACxB,wCAAwC;IACxC,OAAO,EAAE,YAAY,CAAC;IACtB,8BAA8B;IAC9B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,iCAAiC;IACjC,gBAAgB,CAAC,EAAE,eAAe,EAAE,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,sBAAsB;IACtB,YAAY,EAAE,eAAe,CAAC;IAC9B,0BAA0B;IAC1B,EAAE,EAAE,kBAAkB,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,uBAAuB;IACvB,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,cAAc,CAAC,mBAAmB,CAAC,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare function assert(condition: boolean, message?: string | null): asserts condition;
1
+ export declare function assert(condition: any, message?: string | null): asserts condition;
2
2
  //# sourceMappingURL=condition.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"condition.d.ts","sourceRoot":"","sources":["../../../../src/utils/condition.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,CACpB,SAAS,EAAE,OAAO,EAClB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GACtB,OAAO,CAAC,SAAS,CAInB"}
1
+ {"version":3,"file":"condition.d.ts","sourceRoot":"","sources":["../../../../src/utils/condition.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,CACpB,SAAS,EAAE,GAAG,EACd,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GACtB,OAAO,CAAC,SAAS,CAInB"}
@@ -3,6 +3,7 @@ import { SuiPriceServiceConnection, SuiPythClient, } from "@pythnetwork/pyth-sui
3
3
  const HERMES_API = "https://hermes.pyth.network";
4
4
  const WORMHOLE_STATE_ID = "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c";
5
5
  const PYTH_STATE_ID = "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8";
6
+ let api = "";
6
7
  let apiKey = "";
7
8
  let bluefinXApiKey = "";
8
9
  let suiClient = new SuiClient({
@@ -10,6 +11,12 @@ let suiClient = new SuiClient({
10
11
  });
11
12
  let pythClient = new SuiPythClient(suiClient, PYTH_STATE_ID, WORMHOLE_STATE_ID);
12
13
  let pythConnection = new SuiPriceServiceConnection(HERMES_API);
14
+ function setApi(url) {
15
+ api = url;
16
+ }
17
+ function getApi() {
18
+ return api;
19
+ }
13
20
  function setApiKey(key) {
14
21
  apiKey = key;
15
22
  }
@@ -41,6 +48,8 @@ function getPythConnection() {
41
48
  return pythConnection;
42
49
  }
43
50
  const Config = {
51
+ setApi,
52
+ getApi,
44
53
  setApiKey,
45
54
  getApiKey,
46
55
  setBluefinXApiKey,
@@ -11,3 +11,4 @@ export const _7K_META_PUBLISHED_AT = "0x17c0b1f7a6ad73f51268f16b8c06c049eecc2f28
11
11
  export const _7K_META_PACKAGE_ID = "0x17c0b1f7a6ad73f51268f16b8c06c049eecc2f28a270cdd29c06e3d2dea23302";
12
12
  export const _7K_META_VAULT = "0x9a8abd32fe5721307ce3b697cf982ee84e9ffbd58d667a4a199f1683c1a3d23c";
13
13
  export const _7K_META_CONFIG = "0xbbb3a51877ed9b492f26f4e2181811cfb2bd70c532f6f7621263d122d5e96b56";
14
+ export const _7K_PARTNER_ADDRESS = "0x93ead46c1e48a9b62e25b6787f2ea6f75caedabb21726f12431acc4381f5f4c5";
@@ -0,0 +1,109 @@
1
+ import { coinWithBalance, Transaction, } from "@mysten/sui/transactions";
2
+ import { _7K_META_CONFIG, _7K_META_PACKAGE_ID, _7K_META_PUBLISHED_AT, _7K_META_VAULT, } from "../../constants/_7k";
3
+ import { getExpectedReturn } from "../swap/buildTx";
4
+ const DEFAULT_GAS_USED = {
5
+ computationCost: "0",
6
+ nonRefundableStorageFee: "0",
7
+ storageCost: "0",
8
+ storageRebate: "0",
9
+ };
10
+ export const simulateBluefinX = (quote) => {
11
+ return {
12
+ id: quote.id,
13
+ simulatedAmountOut: quote.amountOut,
14
+ gasUsed: DEFAULT_GAS_USED,
15
+ provider: quote.provider,
16
+ };
17
+ };
18
+ export const simulateSwapTx = async (tx, inspector, simulation) => {
19
+ const res = await timeout(() => inspector.devInspectTransactionBlock({
20
+ sender: simulation.sender,
21
+ transactionBlock: tx,
22
+ }), simulation.timeout ?? 2000);
23
+ if (res.effects.status.status === "failure") {
24
+ throw new Error(res.error ?? "Simulation failed");
25
+ }
26
+ const amountOut = extractAmountOutWrapper(res.events);
27
+ return {
28
+ simulatedAmountOut: amountOut,
29
+ gasUsed: res.effects.gasUsed,
30
+ };
31
+ };
32
+ export const simulateAggregator = async (provider, quote, simulation, inspector, options) => {
33
+ const tx = new Transaction();
34
+ const coinOut = await provider.swap({
35
+ quote,
36
+ coinIn: coinWithBalance({
37
+ balance: BigInt(quote.amountIn),
38
+ type: quote.coinTypeIn,
39
+ useGasCoin: false,
40
+ }),
41
+ signer: simulation.sender,
42
+ tx,
43
+ });
44
+ tx.add(metaSettle(quote, coinOut, 10000, options.tipBps, options.partner, options.partnerCommissionBps));
45
+ tx.transferObjects([coinOut], simulation.sender);
46
+ const res = await simulateSwapTx(tx, inspector, simulation);
47
+ return {
48
+ id: quote.id,
49
+ provider: provider.kind,
50
+ ...res,
51
+ };
52
+ };
53
+ /**
54
+ * this settlement does not charge commission fee for partner, since all integrated aggregators already charge commission fee for partner
55
+ * @param quote Meta Aggregator Quote
56
+ * @param coinOut Coin Out Object
57
+ * @param slippageBps Slippage Bps
58
+ * @param tipBps Tip Bps default = 0
59
+ * @param partner address of partner for analytic default is zero address
60
+ */
61
+ export const metaSettle = (quote, coinOut, slippageBps = 100, tipBps = 0, partner, commissionBps = 0) => {
62
+ return (tx) => {
63
+ const { minAmount, expectedAmount } = getExpectedReturn(quote.rawAmountOut, slippageBps, commissionBps, tipBps);
64
+ if (tipBps > 0) {
65
+ tx.moveCall({
66
+ target: `${_7K_META_PUBLISHED_AT}::vault::collect_tip`,
67
+ typeArguments: [quote.coinTypeOut],
68
+ arguments: [
69
+ tx.object(_7K_META_VAULT),
70
+ tx.object(_7K_META_CONFIG),
71
+ coinOut,
72
+ tx.pure.u64(tipBps),
73
+ ],
74
+ });
75
+ }
76
+ tx.moveCall({
77
+ target: `${_7K_META_PUBLISHED_AT}::settle::settle`,
78
+ typeArguments: [quote.coinTypeIn, quote.coinTypeOut],
79
+ arguments: [
80
+ tx.object(_7K_META_CONFIG),
81
+ tx.object(_7K_META_VAULT),
82
+ tx.pure.u64(quote.amountIn),
83
+ coinOut,
84
+ tx.pure.u64(minAmount),
85
+ tx.pure.u64(expectedAmount),
86
+ tx.pure.option("address", partner),
87
+ tx.pure.u64(commissionBps),
88
+ tx.pure.u64(0), // ps
89
+ ],
90
+ });
91
+ };
92
+ };
93
+ const extractAmountOutWrapper = (events) => {
94
+ const swapEvent = events
95
+ .filter((event) => event.type === `${_7K_META_PACKAGE_ID}::settle::Swap`)
96
+ ?.pop();
97
+ return swapEvent?.parsedJson?.amount_out;
98
+ };
99
+ export const timeout = async (fn, timeout, msg) => {
100
+ if (timeout <= 0)
101
+ return fn();
102
+ return new Promise((resolve, reject) => {
103
+ const timer = setTimeout(() => reject(new Error(`Timeout ${msg ?? "operation"}`)), timeout);
104
+ fn()
105
+ .then(resolve)
106
+ .catch(reject)
107
+ .finally(() => clearTimeout(timer));
108
+ });
109
+ };
@@ -1,18 +1,22 @@
1
- import { getFullnodeUrl, SuiClient } from "@mysten/sui/client";
1
+ import { getFullnodeUrl, SuiClient, } from "@mysten/sui/client";
2
2
  import { coinWithBalance, Transaction, } from "@mysten/sui/transactions";
3
- import { normalizeStructTag } from "@mysten/sui/utils";
4
- import { _7K_META_CONFIG, _7K_META_PACKAGE_ID, _7K_META_PUBLISHED_AT, _7K_META_VAULT, } from "../../constants/_7k";
3
+ import { normalizeStructTag, toBase64 } from "@mysten/sui/utils";
5
4
  import { SUI_ADDRESS_ZERO } from "../../constants/sui";
6
- import { EProvider, } from "../../types/metaAg";
5
+ import { EProvider, isAggregatorProvider, isSwapAPIProvider, } from "../../types/metaAg";
7
6
  import { assert } from "../../utils/condition";
8
7
  import { SuiClientUtils } from "../../utils/SuiClientUtils";
9
8
  import { getExpectedReturn } from "../swap/buildTx";
9
+ import { metaSettle, simulateAggregator, simulateBluefinX, timeout, } from "./common";
10
10
  import { BluefinProvider } from "./providers/bluefin";
11
+ import { BluefinXProvider } from "./providers/bluefinx";
12
+ import { OkxProvider, simulateOKXSwap } from "./providers/okx";
11
13
  const HERMES_API = "https://hermes.pyth.network";
12
14
  const DEFAULT_PROVIDERS = {
13
15
  [EProvider.BLUEFIN7K]: {},
14
16
  [EProvider.FLOWX]: {},
15
17
  [EProvider.CETUS]: {},
18
+ [EProvider.ASTRO]: {},
19
+ [EProvider.BLUEFINX]: {},
16
20
  };
17
21
  export class MetaAg {
18
22
  client;
@@ -52,6 +56,16 @@ export class MetaAg {
52
56
  const { CetusProvider } = await import("./providers/cetus").catch(catchImportError(EProvider.CETUS));
53
57
  this.providers[EProvider.CETUS] = new CetusProvider(providerOptions, this.options, this.client);
54
58
  break;
59
+ case EProvider.OKX:
60
+ this.providers[EProvider.OKX] = new OkxProvider(providerOptions, this.options, this.client);
61
+ break;
62
+ case EProvider.BLUEFINX:
63
+ this.providers[EProvider.BLUEFINX] = new BluefinXProvider(providerOptions);
64
+ break;
65
+ case EProvider.ASTRO:
66
+ const { AstroProvider } = await import("./providers/astro").catch(catchImportError(EProvider.ASTRO));
67
+ this.providers[EProvider.ASTRO] = new AstroProvider(providerOptions);
68
+ break;
55
69
  default:
56
70
  throw new Error(`Provider not supported: ${provider}`);
57
71
  }
@@ -59,51 +73,40 @@ export class MetaAg {
59
73
  }
60
74
  async _simulate(provider, quote, simulation) {
61
75
  try {
62
- const tx = new Transaction();
63
- const id = quote.id;
64
- const coinOut = await provider.swap({
65
- quote,
66
- coinIn: coinWithBalance({
67
- balance: BigInt(quote.amountIn),
68
- type: quote.coinTypeIn,
69
- useGasCoin: false,
70
- }),
71
- signer: simulation.sender,
72
- tx,
73
- });
74
- tx.add(metaSettle(quote, coinOut, 10000, this.options.tipBps, this.options.partner, this.options.partnerCommissionBps));
75
- tx.transferObjects([coinOut], simulation.sender);
76
- const res = await timeout(() => this.inspector.devInspectTransactionBlock({
77
- sender: simulation.sender,
78
- transactionBlock: tx,
79
- }), simulation.timeout ?? 2000, `simulation for ${provider.kind} provider with id ${id}`);
80
- if (res.effects.status.status === "failure") {
81
- throw new Error(res.error ?? "Simulation failed");
76
+ if (isAggregatorProvider(provider)) {
77
+ return simulateAggregator(provider, quote, simulation, this.inspector, this.options);
78
+ }
79
+ switch (quote.provider) {
80
+ case EProvider.BLUEFINX:
81
+ return simulateBluefinX(quote);
82
+ case EProvider.OKX:
83
+ return simulateOKXSwap(quote, this.inspector, simulation, this.options);
84
+ default:
85
+ throw new Error(`Provider not supported: ${provider.kind}`);
82
86
  }
83
- const amountOut = extractAmountOutWrapper(res.events);
84
- return {
85
- id,
86
- simulatedAmountOut: amountOut,
87
- gasUsed: res.effects.gasUsed,
88
- provider: provider.kind,
89
- };
90
87
  }
91
88
  catch (error) {
92
- console.warn(`Failed to simulate ${provider.kind}: `, error);
89
+ console.warn(error, { provider: provider.kind, quote: quote.id });
93
90
  }
94
91
  }
95
92
  async _quote(provider, options, simulation) {
96
93
  const quote = await timeout(async () => {
97
94
  const quote = await provider.quote(options);
95
+ if (!quote)
96
+ return null;
98
97
  const { expectedAmount } = getExpectedReturn(quote.rawAmountOut, 0, this.options.partnerCommissionBps, this.options.tipBps);
99
98
  quote.amountOut = expectedAmount;
100
99
  return quote;
101
- }, options.timeout ?? 2000, `quote for ${provider.kind} provider from ${options.coinInType} to ${options.coinOutType}`);
102
- if (simulation) {
100
+ }, options.timeout ?? 2000, `quote for ${provider.kind} provider from ${options.coinTypeIn} to ${options.coinTypeOut}`);
101
+ if (quote && simulation) {
103
102
  if (simulation.onSimulated) {
104
103
  this._simulate(provider, quote, simulation).then((payload) => {
105
104
  if (payload) {
106
- simulation.onSimulated?.(payload);
105
+ setTimeout(() => {
106
+ quote.simulatedAmountOut = payload.simulatedAmountOut;
107
+ quote.gasUsed = payload.gasUsed;
108
+ simulation.onSimulated?.({ ...quote });
109
+ });
107
110
  }
108
111
  });
109
112
  }
@@ -115,6 +118,29 @@ export class MetaAg {
115
118
  }
116
119
  return quote;
117
120
  }
121
+ async _fastSwap({ quote, signer, useGasCoin, signTransaction }, getTransactionBlockParams) {
122
+ const tx = new Transaction();
123
+ const coin = await this.swap({
124
+ quote,
125
+ signer,
126
+ tx,
127
+ coinIn: coinWithBalance({
128
+ type: quote.coinTypeIn,
129
+ balance: BigInt(quote.amountIn),
130
+ useGasCoin,
131
+ }),
132
+ });
133
+ tx.transferObjects([coin], signer);
134
+ tx.setSenderIfNotSet(signer);
135
+ const txBytes = await tx.build({ client: this.client });
136
+ const { signature, bytes } = await signTransaction(toBase64(txBytes));
137
+ return this.client.executeTransactionBlock({
138
+ transactionBlock: bytes,
139
+ signature,
140
+ options: getTransactionBlockParams?.options,
141
+ signal: getTransactionBlockParams?.signal,
142
+ });
143
+ }
118
144
  /**
119
145
  * Get quotes from all providers
120
146
  * @param options - quote options
@@ -124,8 +150,8 @@ export class MetaAg {
124
150
  async quote(options, simulation) {
125
151
  const opts = {
126
152
  ...options,
127
- coinInType: normalizeStructTag(options.coinInType),
128
- coinOutType: normalizeStructTag(options.coinOutType),
153
+ coinTypeIn: normalizeStructTag(options.coinTypeIn),
154
+ coinTypeOut: normalizeStructTag(options.coinTypeOut),
129
155
  };
130
156
  const quotes = await Promise.allSettled(Object.entries(this.options.providers)
131
157
  .filter(([_k, v]) => !v.disabled)
@@ -141,6 +167,8 @@ export class MetaAg {
141
167
  }
142
168
  /**
143
169
  * Build transaction from quote
170
+ * @info Use this function to build composable transaction (ie: add more commands after the swap, consume the coin out object)
171
+ * @warning Providers that build transaction on the fly (typically RFQ, Swap-API providers ie: BluefinX, Okx, ...) are not supported, please use `fastSwap` instead
144
172
  * @param options - build tx options
145
173
  * @param slippageBps - slippage bps if not specified, fallback to global slippage bps, if none of them specified, default to 100
146
174
  * @returns coin out object, you must consume it by transferObjects, or other sub sequence commands
@@ -148,11 +176,32 @@ export class MetaAg {
148
176
  async swap(options, slippageBps) {
149
177
  const provider = await this._getProvider(options.quote.provider);
150
178
  assert(!!provider, `Provider not found: ${options.quote.provider}`);
179
+ assert(isAggregatorProvider(provider), `Provider does not support swap: ${provider.kind}`);
151
180
  const coinOut = await provider.swap(options);
152
181
  options.tx.add(metaSettle(options.quote, coinOut, slippageBps ?? this.options.slippageBps ?? 100, this.options.tipBps, this.options.partner, this.options.partnerCommissionBps));
153
182
  options.tx.setSenderIfNotSet(options.signer);
154
183
  return coinOut;
155
184
  }
185
+ /**
186
+ * Build, Sign, and Execute transaction in one step
187
+ * @param options - fast swap options
188
+ * @returns - txDigest of the transaction
189
+ */
190
+ async fastSwap(options, getTransactionBlockParams) {
191
+ const provider = await this._getProvider(options.quote.provider);
192
+ if (isAggregatorProvider(provider)) {
193
+ return this._fastSwap(options, getTransactionBlockParams);
194
+ }
195
+ else if (isSwapAPIProvider(provider)) {
196
+ return this.client.waitForTransaction({
197
+ ...getTransactionBlockParams,
198
+ digest: await provider.fastSwap(options),
199
+ });
200
+ }
201
+ else {
202
+ throw new Error(`Provider not supported: ${provider.kind}`);
203
+ }
204
+ }
156
205
  /**
157
206
  * Update meta aggregator options
158
207
  * @param options - update options payload
@@ -185,71 +234,17 @@ export class MetaAg {
185
234
  }
186
235
  }
187
236
  }
188
- /**
189
- * this settlement does not charge commission fee for partner, since all integrated aggregators already charge commission fee for partner
190
- * @param quote Meta Aggregator Quote
191
- * @param coinOut Coin Out Object
192
- * @param slippageBps Slippage Bps
193
- * @param tipBps Tip Bps default = 0
194
- * @param partner address of partner for analytic default is zero address
195
- */
196
- const metaSettle = (quote, coinOut, slippageBps = 100, tipBps = 0, partner, commissionBps = 0) => {
197
- return (tx) => {
198
- const { minAmount, expectedAmount } = getExpectedReturn(quote.rawAmountOut, slippageBps, commissionBps, tipBps);
199
- if (tipBps > 0) {
200
- tx.moveCall({
201
- target: `${_7K_META_PUBLISHED_AT}::vault::collect_tip`,
202
- typeArguments: [quote.coinTypeOut],
203
- arguments: [
204
- tx.object(_7K_META_VAULT),
205
- tx.object(_7K_META_CONFIG),
206
- coinOut,
207
- tx.pure.u64(tipBps),
208
- ],
209
- });
210
- }
211
- tx.moveCall({
212
- target: `${_7K_META_PUBLISHED_AT}::settle::settle`,
213
- typeArguments: [quote.coinTypeIn, quote.coinTypeOut],
214
- arguments: [
215
- tx.object(_7K_META_CONFIG),
216
- tx.object(_7K_META_VAULT),
217
- tx.pure.u64(quote.amountIn),
218
- coinOut,
219
- tx.pure.u64(minAmount),
220
- tx.pure.u64(expectedAmount),
221
- tx.pure.option("address", partner),
222
- tx.pure.u64(commissionBps),
223
- tx.pure.u64(0), // ps
224
- ],
225
- });
226
- };
227
- };
228
- const extractAmountOutWrapper = (events) => {
229
- const swapEvent = events
230
- .filter((event) => event.type === `${_7K_META_PACKAGE_ID}::settle::Swap`)
231
- ?.pop();
232
- return swapEvent?.parsedJson?.amount_out;
233
- };
234
237
  const catchImportError = (provider) => {
235
238
  return (e) => {
236
239
  const map = {
237
240
  [EProvider.CETUS]: "@cetusprotocol/aggregator-sdk",
238
241
  [EProvider.FLOWX]: "@flowx-finance/sdk",
239
242
  [EProvider.BLUEFIN7K]: "@7kprotocol/sdk-ts",
243
+ [EProvider.ASTRO]: "@naviprotocol/astros-aggregator-sdk",
244
+ [EProvider.OKX]: "",
245
+ [EProvider.BLUEFINX]: "",
240
246
  };
241
247
  console.warn(`Please install ${map[provider]} to use ${provider} provider`);
242
248
  throw e;
243
249
  };
244
250
  };
245
- const timeout = async (fn, timeout, msg) => {
246
- if (timeout <= 0)
247
- return fn();
248
- return new Promise((resolve, reject) => {
249
- const timer = setTimeout(() => reject(new Error(`Timeout ${msg ?? "operation"}`)), timeout);
250
- fn()
251
- .then(resolve)
252
- .catch(reject)
253
- .finally(() => clearTimeout(timer));
254
- });
255
- };
@@ -0,0 +1,39 @@
1
+ import { buildSwapPTBFromQuote, getQuote, } from "@naviprotocol/astros-aggregator-sdk";
2
+ import { v4 } from "uuid";
3
+ import { _7K_PARTNER_ADDRESS } from "../../../constants/_7k";
4
+ import { EProvider, } from "../../../types/metaAg";
5
+ import { assert } from "../../../utils/condition";
6
+ export class AstroProvider {
7
+ options;
8
+ kind = EProvider.ASTRO;
9
+ constructor(options) {
10
+ this.options = options;
11
+ }
12
+ async quote({ amountIn, coinTypeIn, coinTypeOut, }) {
13
+ const quote = await getQuote(coinTypeIn, coinTypeOut, amountIn, this.options.api, {
14
+ baseUrl: this.options.api,
15
+ byAmountIn: true,
16
+ depth: this.options.depth,
17
+ dexList: this.options.dexList,
18
+ serviceFee: {
19
+ fee: 0,
20
+ receiverAddress: _7K_PARTNER_ADDRESS,
21
+ },
22
+ });
23
+ return {
24
+ id: v4(),
25
+ provider: this.kind,
26
+ quote,
27
+ amountIn,
28
+ rawAmountOut: quote.amount_out.toString(),
29
+ amountOut: quote.amount_out.toString(),
30
+ coinTypeIn,
31
+ coinTypeOut,
32
+ };
33
+ }
34
+ async swap({ signer, quote, coinIn, tx }) {
35
+ assert(quote.provider === EProvider.ASTRO, "Invalid quote");
36
+ const coin = await buildSwapPTBFromQuote(signer, tx, 0, coinIn, quote.quote);
37
+ return coin;
38
+ }
39
+ }