outsmart 2.0.0-alpha.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.
- package/LICENSE +21 -0
- package/README.md +568 -0
- package/dist/cli.d.ts +44 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +1251 -0
- package/dist/cli.js.map +1 -0
- package/dist/dex/byreal-clmm.d.ts +16 -0
- package/dist/dex/byreal-clmm.d.ts.map +1 -0
- package/dist/dex/byreal-clmm.js +39 -0
- package/dist/dex/byreal-clmm.js.map +1 -0
- package/dist/dex/dflow.d.ts +27 -0
- package/dist/dex/dflow.d.ts.map +1 -0
- package/dist/dex/dflow.js +200 -0
- package/dist/dex/dflow.js.map +1 -0
- package/dist/dex/fusion-amm.d.ts +44 -0
- package/dist/dex/fusion-amm.d.ts.map +1 -0
- package/dist/dex/fusion-amm.js +546 -0
- package/dist/dex/fusion-amm.js.map +1 -0
- package/dist/dex/futarchy-amm.d.ts +32 -0
- package/dist/dex/futarchy-amm.d.ts.map +1 -0
- package/dist/dex/futarchy-amm.js +443 -0
- package/dist/dex/futarchy-amm.js.map +1 -0
- package/dist/dex/futarchy-idl.d.ts +2568 -0
- package/dist/dex/futarchy-idl.d.ts.map +1 -0
- package/dist/dex/futarchy-idl.js +2570 -0
- package/dist/dex/futarchy-idl.js.map +1 -0
- package/dist/dex/futarchy-launchpad.d.ts +68 -0
- package/dist/dex/futarchy-launchpad.d.ts.map +1 -0
- package/dist/dex/futarchy-launchpad.js +377 -0
- package/dist/dex/futarchy-launchpad.js.map +1 -0
- package/dist/dex/index.d.ts +88 -0
- package/dist/dex/index.d.ts.map +1 -0
- package/dist/dex/index.js +159 -0
- package/dist/dex/index.js.map +1 -0
- package/dist/dex/jupiter-ultra.d.ts +27 -0
- package/dist/dex/jupiter-ultra.d.ts.map +1 -0
- package/dist/dex/jupiter-ultra.js +369 -0
- package/dist/dex/jupiter-ultra.js.map +1 -0
- package/dist/dex/meteora-damm-v1.d.ts +36 -0
- package/dist/dex/meteora-damm-v1.d.ts.map +1 -0
- package/dist/dex/meteora-damm-v1.js +314 -0
- package/dist/dex/meteora-damm-v1.js.map +1 -0
- package/dist/dex/meteora-damm-v2.d.ts +103 -0
- package/dist/dex/meteora-damm-v2.d.ts.map +1 -0
- package/dist/dex/meteora-damm-v2.js +1146 -0
- package/dist/dex/meteora-damm-v2.js.map +1 -0
- package/dist/dex/meteora-dbc.d.ts +38 -0
- package/dist/dex/meteora-dbc.d.ts.map +1 -0
- package/dist/dex/meteora-dbc.js +374 -0
- package/dist/dex/meteora-dbc.js.map +1 -0
- package/dist/dex/meteora-dlmm.d.ts +79 -0
- package/dist/dex/meteora-dlmm.d.ts.map +1 -0
- package/dist/dex/meteora-dlmm.js +735 -0
- package/dist/dex/meteora-dlmm.js.map +1 -0
- package/dist/dex/orca.d.ts +31 -0
- package/dist/dex/orca.d.ts.map +1 -0
- package/dist/dex/orca.js +536 -0
- package/dist/dex/orca.js.map +1 -0
- package/dist/dex/pancakeswap-clmm.d.ts +16 -0
- package/dist/dex/pancakeswap-clmm.d.ts.map +1 -0
- package/dist/dex/pancakeswap-clmm.js +39 -0
- package/dist/dex/pancakeswap-clmm.js.map +1 -0
- package/dist/dex/pumpfun-amm.d.ts +46 -0
- package/dist/dex/pumpfun-amm.d.ts.map +1 -0
- package/dist/dex/pumpfun-amm.js +692 -0
- package/dist/dex/pumpfun-amm.js.map +1 -0
- package/dist/dex/pumpfun.d.ts +41 -0
- package/dist/dex/pumpfun.d.ts.map +1 -0
- package/dist/dex/pumpfun.js +555 -0
- package/dist/dex/pumpfun.js.map +1 -0
- package/dist/dex/raydium-amm-v4.d.ts +11 -0
- package/dist/dex/raydium-amm-v4.d.ts.map +1 -0
- package/dist/dex/raydium-amm-v4.js +649 -0
- package/dist/dex/raydium-amm-v4.js.map +1 -0
- package/dist/dex/raydium-clmm.d.ts +12 -0
- package/dist/dex/raydium-clmm.d.ts.map +1 -0
- package/dist/dex/raydium-clmm.js +675 -0
- package/dist/dex/raydium-clmm.js.map +1 -0
- package/dist/dex/raydium-cpmm.d.ts +10 -0
- package/dist/dex/raydium-cpmm.d.ts.map +1 -0
- package/dist/dex/raydium-cpmm.js +613 -0
- package/dist/dex/raydium-cpmm.js.map +1 -0
- package/dist/dex/raydium-launchlab.d.ts +12 -0
- package/dist/dex/raydium-launchlab.d.ts.map +1 -0
- package/dist/dex/raydium-launchlab.js +530 -0
- package/dist/dex/raydium-launchlab.js.map +1 -0
- package/dist/dex/shared/clmm-base.d.ts +58 -0
- package/dist/dex/shared/clmm-base.d.ts.map +1 -0
- package/dist/dex/shared/clmm-base.js +891 -0
- package/dist/dex/shared/clmm-base.js.map +1 -0
- package/dist/dex/types.d.ts +601 -0
- package/dist/dex/types.d.ts.map +1 -0
- package/dist/dex/types.js +137 -0
- package/dist/dex/types.js.map +1 -0
- package/dist/dexscreener/index.d.ts +2 -0
- package/dist/dexscreener/index.d.ts.map +1 -0
- package/dist/dexscreener/index.js +18 -0
- package/dist/dexscreener/index.js.map +1 -0
- package/dist/dexscreener/info.d.ts +22 -0
- package/dist/dexscreener/info.d.ts.map +1 -0
- package/dist/dexscreener/info.js +104 -0
- package/dist/dexscreener/info.js.map +1 -0
- package/dist/helpers/check_balance.d.ts +10 -0
- package/dist/helpers/check_balance.d.ts.map +1 -0
- package/dist/helpers/check_balance.js +34 -0
- package/dist/helpers/check_balance.js.map +1 -0
- package/dist/helpers/config.d.ts +51 -0
- package/dist/helpers/config.d.ts.map +1 -0
- package/dist/helpers/config.js +118 -0
- package/dist/helpers/config.js.map +1 -0
- package/dist/helpers/index.d.ts +8 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +29 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/logger.d.ts +27 -0
- package/dist/helpers/logger.d.ts.map +1 -0
- package/dist/helpers/logger.js +39 -0
- package/dist/helpers/logger.js.map +1 -0
- package/dist/helpers/token-2022.d.ts +32 -0
- package/dist/helpers/token-2022.d.ts.map +1 -0
- package/dist/helpers/token-2022.js +48 -0
- package/dist/helpers/token-2022.js.map +1 -0
- package/dist/helpers/unwrap_sol.d.ts +2 -0
- package/dist/helpers/unwrap_sol.d.ts.map +1 -0
- package/dist/helpers/unwrap_sol.js +67 -0
- package/dist/helpers/unwrap_sol.js.map +1 -0
- package/dist/helpers/util.d.ts +698 -0
- package/dist/helpers/util.d.ts.map +1 -0
- package/dist/helpers/util.js +181 -0
- package/dist/helpers/util.js.map +1 -0
- package/dist/helpers/utils.d.ts +10 -0
- package/dist/helpers/utils.d.ts.map +1 -0
- package/dist/helpers/utils.js +97 -0
- package/dist/helpers/utils.js.map +1 -0
- package/dist/helpers/wrap_sol.d.ts +3 -0
- package/dist/helpers/wrap_sol.d.ts.map +1 -0
- package/dist/helpers/wrap_sol.js +88 -0
- package/dist/helpers/wrap_sol.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/transactions/bloXroute_tips_tx_executor.d.ts +4 -0
- package/dist/transactions/bloXroute_tips_tx_executor.d.ts.map +1 -0
- package/dist/transactions/bloXroute_tips_tx_executor.js +70 -0
- package/dist/transactions/bloXroute_tips_tx_executor.js.map +1 -0
- package/dist/transactions/index.d.ts +6 -0
- package/dist/transactions/index.d.ts.map +1 -0
- package/dist/transactions/index.js +30 -0
- package/dist/transactions/index.js.map +1 -0
- package/dist/transactions/jito_tips_tx_executor.d.ts +15 -0
- package/dist/transactions/jito_tips_tx_executor.d.ts.map +1 -0
- package/dist/transactions/jito_tips_tx_executor.js +99 -0
- package/dist/transactions/jito_tips_tx_executor.js.map +1 -0
- package/dist/transactions/landing/index.d.ts +30 -0
- package/dist/transactions/landing/index.d.ts.map +1 -0
- package/dist/transactions/landing/index.js +60 -0
- package/dist/transactions/landing/index.js.map +1 -0
- package/dist/transactions/landing/nonce-manager.d.ts +116 -0
- package/dist/transactions/landing/nonce-manager.d.ts.map +1 -0
- package/dist/transactions/landing/nonce-manager.js +393 -0
- package/dist/transactions/landing/nonce-manager.js.map +1 -0
- package/dist/transactions/landing/orchestrator.d.ts +104 -0
- package/dist/transactions/landing/orchestrator.d.ts.map +1 -0
- package/dist/transactions/landing/orchestrator.js +329 -0
- package/dist/transactions/landing/orchestrator.js.map +1 -0
- package/dist/transactions/landing/providers/astralane.d.ts +12 -0
- package/dist/transactions/landing/providers/astralane.d.ts.map +1 -0
- package/dist/transactions/landing/providers/astralane.js +132 -0
- package/dist/transactions/landing/providers/astralane.js.map +1 -0
- package/dist/transactions/landing/providers/blockrazor.d.ts +11 -0
- package/dist/transactions/landing/providers/blockrazor.d.ts.map +1 -0
- package/dist/transactions/landing/providers/blockrazor.js +134 -0
- package/dist/transactions/landing/providers/blockrazor.js.map +1 -0
- package/dist/transactions/landing/providers/bloxroute.d.ts +12 -0
- package/dist/transactions/landing/providers/bloxroute.d.ts.map +1 -0
- package/dist/transactions/landing/providers/bloxroute.js +102 -0
- package/dist/transactions/landing/providers/bloxroute.js.map +1 -0
- package/dist/transactions/landing/providers/flashblock.d.ts +10 -0
- package/dist/transactions/landing/providers/flashblock.d.ts.map +1 -0
- package/dist/transactions/landing/providers/flashblock.js +102 -0
- package/dist/transactions/landing/providers/flashblock.js.map +1 -0
- package/dist/transactions/landing/providers/helius-sender.d.ts +11 -0
- package/dist/transactions/landing/providers/helius-sender.d.ts.map +1 -0
- package/dist/transactions/landing/providers/helius-sender.js +101 -0
- package/dist/transactions/landing/providers/helius-sender.js.map +1 -0
- package/dist/transactions/landing/providers/jito.d.ts +16 -0
- package/dist/transactions/landing/providers/jito.d.ts.map +1 -0
- package/dist/transactions/landing/providers/jito.js +110 -0
- package/dist/transactions/landing/providers/jito.js.map +1 -0
- package/dist/transactions/landing/providers/nextblock.d.ts +11 -0
- package/dist/transactions/landing/providers/nextblock.d.ts.map +1 -0
- package/dist/transactions/landing/providers/nextblock.js +109 -0
- package/dist/transactions/landing/providers/nextblock.js.map +1 -0
- package/dist/transactions/landing/providers/node1.d.ts +11 -0
- package/dist/transactions/landing/providers/node1.d.ts.map +1 -0
- package/dist/transactions/landing/providers/node1.js +101 -0
- package/dist/transactions/landing/providers/node1.js.map +1 -0
- package/dist/transactions/landing/providers/nozomi.d.ts +11 -0
- package/dist/transactions/landing/providers/nozomi.d.ts.map +1 -0
- package/dist/transactions/landing/providers/nozomi.js +124 -0
- package/dist/transactions/landing/providers/nozomi.js.map +1 -0
- package/dist/transactions/landing/providers/soyas.d.ts +16 -0
- package/dist/transactions/landing/providers/soyas.d.ts.map +1 -0
- package/dist/transactions/landing/providers/soyas.js +192 -0
- package/dist/transactions/landing/providers/soyas.js.map +1 -0
- package/dist/transactions/landing/providers/stellium.d.ts +11 -0
- package/dist/transactions/landing/providers/stellium.d.ts.map +1 -0
- package/dist/transactions/landing/providers/stellium.js +102 -0
- package/dist/transactions/landing/providers/stellium.js.map +1 -0
- package/dist/transactions/landing/providers/zero-slot.d.ts +10 -0
- package/dist/transactions/landing/providers/zero-slot.d.ts.map +1 -0
- package/dist/transactions/landing/providers/zero-slot.js +92 -0
- package/dist/transactions/landing/providers/zero-slot.js.map +1 -0
- package/dist/transactions/landing/tip-accounts.d.ts +22 -0
- package/dist/transactions/landing/tip-accounts.d.ts.map +1 -0
- package/dist/transactions/landing/tip-accounts.js +140 -0
- package/dist/transactions/landing/tip-accounts.js.map +1 -0
- package/dist/transactions/landing/types.d.ts +98 -0
- package/dist/transactions/landing/types.d.ts.map +1 -0
- package/dist/transactions/landing/types.js +30 -0
- package/dist/transactions/landing/types.js.map +1 -0
- package/dist/transactions/nozomi/tx-submission.d.ts +14 -0
- package/dist/transactions/nozomi/tx-submission.d.ts.map +1 -0
- package/dist/transactions/nozomi/tx-submission.js +107 -0
- package/dist/transactions/nozomi/tx-submission.js.map +1 -0
- package/dist/transactions/send-rpc.d.ts +54 -0
- package/dist/transactions/send-rpc.d.ts.map +1 -0
- package/dist/transactions/send-rpc.js +126 -0
- package/dist/transactions/send-rpc.js.map +1 -0
- package/dist/transactions/simple_tx_executor.d.ts +10 -0
- package/dist/transactions/simple_tx_executor.d.ts.map +1 -0
- package/dist/transactions/simple_tx_executor.js +33 -0
- package/dist/transactions/simple_tx_executor.js.map +1 -0
- package/package.json +112 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Meteora DAMM v1 (Dynamic AMM) — IDexAdapter Implementation
|
|
4
|
+
*
|
|
5
|
+
* Wraps the @meteora-ag/dynamic-amm-sdk (AmmImpl) for buy/snipe/findPool/getPrice.
|
|
6
|
+
* No sell in source module — sell throws UnsupportedOperationError.
|
|
7
|
+
*
|
|
8
|
+
* Source: 100x-algo-bots/trading-modules/meteora-damm-v1/
|
|
9
|
+
*
|
|
10
|
+
* SDK pattern:
|
|
11
|
+
* const amm = await AmmImpl.create(connection, poolAddress);
|
|
12
|
+
* const quote = amm.getSwapQuote(inputMint, inputAmount, slippagePct);
|
|
13
|
+
* const swapTx = await amm.swap(user, inputMint, inputAmount, minOut);
|
|
14
|
+
*/
|
|
15
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
16
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.MeteoraDammV1Adapter = void 0;
|
|
20
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
21
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
22
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
23
|
+
const dynamic_amm_sdk_1 = __importDefault(require("@meteora-ag/dynamic-amm-sdk"));
|
|
24
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
25
|
+
const config_1 = require("../helpers/config");
|
|
26
|
+
const landing_1 = require("../transactions/landing");
|
|
27
|
+
const send_rpc_1 = require("../transactions/send-rpc");
|
|
28
|
+
const types_1 = require("./types");
|
|
29
|
+
const index_1 = require("./index");
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
// Constants
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
/** Known stablecoin mints with 6 decimals */
|
|
34
|
+
const SIX_DECIMAL_MINTS = new Set([
|
|
35
|
+
types_1.USDC_MINT,
|
|
36
|
+
types_1.USDT_MINT,
|
|
37
|
+
"USD1ttGY1N17NEEHLmELoaybftRBUSErhqYiQzvEmuB", // USD1
|
|
38
|
+
]);
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
// Helpers
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
/**
|
|
43
|
+
* Determine the number of decimals for a quote mint.
|
|
44
|
+
* Returns 6 for known stablecoins, 9 for SOL/unknown.
|
|
45
|
+
*/
|
|
46
|
+
function quoteDecimals(quoteMintStr) {
|
|
47
|
+
return SIX_DECIMAL_MINTS.has(quoteMintStr) ? 6 : 9;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Convert human-readable amount to lamports BN for the given quote mint.
|
|
51
|
+
*/
|
|
52
|
+
function amountToLamports(amount, quoteMintStr) {
|
|
53
|
+
const decimals = quoteDecimals(quoteMintStr);
|
|
54
|
+
return new bn_js_1.default(Math.floor(amount * Math.pow(10, decimals)));
|
|
55
|
+
}
|
|
56
|
+
// ---------------------------------------------------------------------------
|
|
57
|
+
// Adapter
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
class MeteoraDammV1Adapter {
|
|
60
|
+
name = "meteora-damm-v1";
|
|
61
|
+
protocol = "damm-v1";
|
|
62
|
+
capabilities = (0, types_1.defaultCapabilities)({
|
|
63
|
+
canBuy: true,
|
|
64
|
+
canSell: true,
|
|
65
|
+
canSnipe: true,
|
|
66
|
+
canFindPool: true,
|
|
67
|
+
canGetPrice: true,
|
|
68
|
+
});
|
|
69
|
+
// ----- Core: buy -----
|
|
70
|
+
async buy(params) {
|
|
71
|
+
const tokenMint = (0, types_1.requireTokenMint)(params, this.name);
|
|
72
|
+
const { amountSol, quoteMint: quoteMintParam, poolAddress, opts } = params;
|
|
73
|
+
const connection = (0, config_1.getConnection)();
|
|
74
|
+
const wallet = (0, config_1.getWallet)();
|
|
75
|
+
const quoteMintStr = quoteMintParam ?? types_1.WSOL_MINT;
|
|
76
|
+
// Resolve pool
|
|
77
|
+
const poolPk = poolAddress
|
|
78
|
+
? new web3_js_1.PublicKey(poolAddress)
|
|
79
|
+
: await this.resolvePool(tokenMint, quoteMintStr);
|
|
80
|
+
const ammInstance = await dynamic_amm_sdk_1.default.create(connection, poolPk);
|
|
81
|
+
const quoteMintPk = new web3_js_1.PublicKey(quoteMintStr);
|
|
82
|
+
const inputAmount = amountToLamports(amountSol, quoteMintStr);
|
|
83
|
+
// Quote with slippage
|
|
84
|
+
const slippagePct = (opts?.slippageBps ?? types_1.DEFAULT_SLIPPAGE_BPS) / 100; // SDK takes pct (1 = 1%)
|
|
85
|
+
const swapQuote = ammInstance.getSwapQuote(quoteMintPk, inputAmount, slippagePct);
|
|
86
|
+
// Build swap IX
|
|
87
|
+
const swapTx = await ammInstance.swap(wallet.publicKey, quoteMintPk, inputAmount, swapQuote.minSwapOutAmount);
|
|
88
|
+
// Compute budget IXs
|
|
89
|
+
const computeLimit = opts?.computeUnitLimit ?? types_1.DEFAULT_COMPUTE_UNIT_LIMIT;
|
|
90
|
+
const priorityFee = opts?.priorityFeeMicroLamports ?? types_1.DEFAULT_PRIORITY_FEE_MICRO_LAMPORTS;
|
|
91
|
+
const ixs = [
|
|
92
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: computeLimit }),
|
|
93
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: priorityFee }),
|
|
94
|
+
...swapTx.instructions,
|
|
95
|
+
];
|
|
96
|
+
// Submit via RPC send+confirm
|
|
97
|
+
const result = await (0, send_rpc_1.sendAndConfirmVtx)(connection, ixs, wallet, {
|
|
98
|
+
addressLookupTables: opts?.addressLookupTables,
|
|
99
|
+
});
|
|
100
|
+
return {
|
|
101
|
+
txSignature: result.txSignature,
|
|
102
|
+
confirmed: result.confirmed,
|
|
103
|
+
amountIn: amountSol,
|
|
104
|
+
amountInToken: quoteMintStr,
|
|
105
|
+
dex: this.name,
|
|
106
|
+
poolAddress: poolPk.toBase58(),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
// ----- Core: sell -----
|
|
110
|
+
async sell(params) {
|
|
111
|
+
const tokenMint = (0, types_1.requireTokenMint)(params, this.name);
|
|
112
|
+
const { percentage, quoteMint: quoteMintParam, poolAddress, opts } = params;
|
|
113
|
+
const connection = (0, config_1.getConnection)();
|
|
114
|
+
const wallet = (0, config_1.getWallet)();
|
|
115
|
+
const quoteMintStr = quoteMintParam ?? types_1.WSOL_MINT;
|
|
116
|
+
// Resolve pool
|
|
117
|
+
const poolPk = poolAddress
|
|
118
|
+
? new web3_js_1.PublicKey(poolAddress)
|
|
119
|
+
: await this.resolvePool(tokenMint, quoteMintStr);
|
|
120
|
+
const ammInstance = await dynamic_amm_sdk_1.default.create(connection, poolPk);
|
|
121
|
+
const baseMintPk = new web3_js_1.PublicKey(tokenMint);
|
|
122
|
+
// Detect base token program
|
|
123
|
+
const baseMintAccInfo = await connection.getAccountInfo(baseMintPk);
|
|
124
|
+
if (!baseMintAccInfo) {
|
|
125
|
+
throw new Error(`Token mint not found: ${tokenMint}`);
|
|
126
|
+
}
|
|
127
|
+
const baseTokenProgram = baseMintAccInfo.owner.equals(spl_token_1.TOKEN_2022_PROGRAM_ID)
|
|
128
|
+
? spl_token_1.TOKEN_2022_PROGRAM_ID
|
|
129
|
+
: spl_token_1.TOKEN_PROGRAM_ID;
|
|
130
|
+
// Get token balance
|
|
131
|
+
const ata = await (0, spl_token_1.getAssociatedTokenAddress)(baseMintPk, wallet.publicKey, false, baseTokenProgram);
|
|
132
|
+
const tokenAccount = await (0, spl_token_1.getAccount)(connection, ata, "confirmed", baseTokenProgram);
|
|
133
|
+
const balance = tokenAccount.amount;
|
|
134
|
+
// Calculate sell amount based on percentage
|
|
135
|
+
const sellAmount = new bn_js_1.default(Math.floor((Number(balance) * percentage) / 100).toString());
|
|
136
|
+
if (sellAmount.isZero()) {
|
|
137
|
+
throw new Error(`No balance to sell for ${tokenMint}`);
|
|
138
|
+
}
|
|
139
|
+
// Quote with slippage — pass baseMintPk as input (selling base token)
|
|
140
|
+
const slippagePct = (opts?.slippageBps ?? types_1.DEFAULT_SLIPPAGE_BPS) / 100;
|
|
141
|
+
const swapQuote = ammInstance.getSwapQuote(baseMintPk, sellAmount, slippagePct);
|
|
142
|
+
// Build swap IX — reversed direction (base → quote)
|
|
143
|
+
const swapTx = await ammInstance.swap(wallet.publicKey, baseMintPk, sellAmount, swapQuote.minSwapOutAmount);
|
|
144
|
+
// Compute budget IXs
|
|
145
|
+
const computeLimit = opts?.computeUnitLimit ?? types_1.DEFAULT_COMPUTE_UNIT_LIMIT;
|
|
146
|
+
const priorityFee = opts?.priorityFeeMicroLamports ?? types_1.DEFAULT_PRIORITY_FEE_MICRO_LAMPORTS;
|
|
147
|
+
const ixs = [
|
|
148
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: computeLimit }),
|
|
149
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: priorityFee }),
|
|
150
|
+
...swapTx.instructions,
|
|
151
|
+
];
|
|
152
|
+
// Submit via RPC send+confirm
|
|
153
|
+
const result = await (0, send_rpc_1.sendAndConfirmVtx)(connection, ixs, wallet, {
|
|
154
|
+
addressLookupTables: opts?.addressLookupTables,
|
|
155
|
+
});
|
|
156
|
+
// Human-readable sell amount
|
|
157
|
+
let tokenDecimals = 9;
|
|
158
|
+
try {
|
|
159
|
+
const mintData = await connection.getTokenSupply(baseMintPk);
|
|
160
|
+
tokenDecimals = mintData.value.decimals;
|
|
161
|
+
}
|
|
162
|
+
catch { /* fallback to 9 */ }
|
|
163
|
+
const humanAmount = Number(sellAmount.toString()) / Math.pow(10, tokenDecimals);
|
|
164
|
+
return {
|
|
165
|
+
txSignature: result.txSignature,
|
|
166
|
+
confirmed: result.confirmed,
|
|
167
|
+
amountIn: humanAmount,
|
|
168
|
+
amountInToken: tokenMint,
|
|
169
|
+
dex: this.name,
|
|
170
|
+
poolAddress: poolPk.toBase58(),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
// ----- Snipe -----
|
|
174
|
+
async snipe(params) {
|
|
175
|
+
const { tokenMint, amountSol, poolAddress, quoteMint: quoteMintParam, tipSol, opts } = params;
|
|
176
|
+
const connection = (0, config_1.getConnection)();
|
|
177
|
+
const wallet = (0, config_1.getWallet)();
|
|
178
|
+
const quoteMintStr = quoteMintParam ?? types_1.WSOL_MINT;
|
|
179
|
+
const poolPk = new web3_js_1.PublicKey(poolAddress);
|
|
180
|
+
const quoteMintPk = new web3_js_1.PublicKey(quoteMintStr);
|
|
181
|
+
const inputAmount = amountToLamports(amountSol, quoteMintStr);
|
|
182
|
+
const ammInstance = await dynamic_amm_sdk_1.default.create(connection, poolPk);
|
|
183
|
+
// Snipe uses unlimited slippage (minOut = 0) for maximum fill
|
|
184
|
+
const swapTx = await ammInstance.swap(wallet.publicKey, quoteMintPk, inputAmount, new bn_js_1.default(0));
|
|
185
|
+
const computeLimit = opts?.computeUnitLimit ?? types_1.DEFAULT_COMPUTE_UNIT_LIMIT;
|
|
186
|
+
const priorityFee = opts?.priorityFeeMicroLamports ?? 20_000_000; // high priority for snipe
|
|
187
|
+
const ixs = [
|
|
188
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: computeLimit }),
|
|
189
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: priorityFee }),
|
|
190
|
+
...swapTx.instructions,
|
|
191
|
+
];
|
|
192
|
+
// Use concurrent landing (orchestrator handles nonce prepending)
|
|
193
|
+
const blockhash = await connection.getLatestBlockhash();
|
|
194
|
+
const results = await (0, landing_1.landTransaction)(ixs, wallet, blockhash, {
|
|
195
|
+
dex: this.name,
|
|
196
|
+
operation: "snipe",
|
|
197
|
+
tipSol,
|
|
198
|
+
addressLookupTables: opts?.addressLookupTables,
|
|
199
|
+
});
|
|
200
|
+
const accepted = results.find((r) => r.accepted);
|
|
201
|
+
return {
|
|
202
|
+
txSignature: accepted?.signature ?? "",
|
|
203
|
+
confirmed: !!accepted?.accepted,
|
|
204
|
+
amountIn: amountSol,
|
|
205
|
+
amountInToken: quoteMintStr,
|
|
206
|
+
dex: this.name,
|
|
207
|
+
poolAddress,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
// ----- buildSwapIxs (for orchestrator / nonce integration) -----
|
|
211
|
+
async buildSwapIxs(params) {
|
|
212
|
+
if ("percentage" in params) {
|
|
213
|
+
throw new types_1.UnsupportedOperationError(this.name, "buildSwapIxs(sell)");
|
|
214
|
+
}
|
|
215
|
+
const buyParams = params;
|
|
216
|
+
const tokenMint = (0, types_1.requireTokenMint)(buyParams, this.name);
|
|
217
|
+
const connection = (0, config_1.getConnection)();
|
|
218
|
+
const wallet = (0, config_1.getWallet)();
|
|
219
|
+
const quoteMintStr = buyParams.quoteMint ?? types_1.WSOL_MINT;
|
|
220
|
+
const quoteMintPk = new web3_js_1.PublicKey(quoteMintStr);
|
|
221
|
+
const poolPk = buyParams.poolAddress
|
|
222
|
+
? new web3_js_1.PublicKey(buyParams.poolAddress)
|
|
223
|
+
: await this.resolvePool(tokenMint, quoteMintStr);
|
|
224
|
+
const ammInstance = await dynamic_amm_sdk_1.default.create(connection, poolPk);
|
|
225
|
+
const inputAmount = amountToLamports(buyParams.amountSol, quoteMintStr);
|
|
226
|
+
// Build swap with 0 minOut (orchestrator can adjust)
|
|
227
|
+
const swapTx = await ammInstance.swap(wallet.publicKey, quoteMintPk, inputAmount, new bn_js_1.default(0));
|
|
228
|
+
return {
|
|
229
|
+
instructions: swapTx.instructions,
|
|
230
|
+
signers: [],
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
// ----- findPool -----
|
|
234
|
+
async findPool(baseMint, quoteMint) {
|
|
235
|
+
const connection = (0, config_1.getConnection)();
|
|
236
|
+
const baseMintPk = new web3_js_1.PublicKey(baseMint);
|
|
237
|
+
const quoteMintPk = new web3_js_1.PublicKey(quoteMint ?? types_1.WSOL_MINT);
|
|
238
|
+
// DAMM v1 uses AmmImpl — try to derive customizable pool first
|
|
239
|
+
// The SDK's create() will throw if the pool doesn't exist
|
|
240
|
+
const poolAddress = this.deriveCustomizablePoolAddress(baseMintPk, quoteMintPk);
|
|
241
|
+
try {
|
|
242
|
+
const ammInstance = await dynamic_amm_sdk_1.default.create(connection, poolAddress);
|
|
243
|
+
const poolInfo = ammInstance.poolInfo;
|
|
244
|
+
return {
|
|
245
|
+
address: poolAddress.toBase58(),
|
|
246
|
+
dex: this.name,
|
|
247
|
+
protocol: this.protocol,
|
|
248
|
+
baseMint,
|
|
249
|
+
quoteMint: quoteMint ?? types_1.WSOL_MINT,
|
|
250
|
+
baseDecimals: ammInstance.tokenAMint.decimals,
|
|
251
|
+
quoteDecimals: ammInstance.tokenBMint.decimals,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
// Pool not found at derived address
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
// ----- getPrice -----
|
|
260
|
+
async getPrice(poolAddress) {
|
|
261
|
+
const connection = (0, config_1.getConnection)();
|
|
262
|
+
const poolPk = new web3_js_1.PublicKey(poolAddress);
|
|
263
|
+
const ammInstance = await dynamic_amm_sdk_1.default.create(connection, poolPk);
|
|
264
|
+
const poolInfo = ammInstance.poolInfo;
|
|
265
|
+
const tokenAAmount = new decimal_js_1.default(poolInfo.tokenAAmount.toString()).div(Math.pow(10, ammInstance.tokenAMint.decimals));
|
|
266
|
+
const tokenBAmount = new decimal_js_1.default(poolInfo.tokenBAmount.toString()).div(Math.pow(10, ammInstance.tokenBMint.decimals));
|
|
267
|
+
let price;
|
|
268
|
+
if (tokenAAmount.isZero()) {
|
|
269
|
+
price = 0;
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
const rawPrice = tokenBAmount.div(tokenAAmount);
|
|
273
|
+
price = Number(rawPrice);
|
|
274
|
+
}
|
|
275
|
+
return {
|
|
276
|
+
price,
|
|
277
|
+
baseMint: ammInstance.tokenAMint.address.toBase58(),
|
|
278
|
+
quoteMint: ammInstance.tokenBMint.address.toBase58(),
|
|
279
|
+
source: "on-chain",
|
|
280
|
+
poolAddress,
|
|
281
|
+
timestamp: Date.now(),
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
// ----- Internal helpers -----
|
|
285
|
+
/**
|
|
286
|
+
* Resolve pool address — if not provided, discover via findPool().
|
|
287
|
+
* Throws PoolNotFoundError if no pool found.
|
|
288
|
+
*/
|
|
289
|
+
async resolvePool(baseMint, quoteMint) {
|
|
290
|
+
const pool = await this.findPool(baseMint, quoteMint);
|
|
291
|
+
if (!pool) {
|
|
292
|
+
throw new types_1.PoolNotFoundError(this.name, baseMint, quoteMint);
|
|
293
|
+
}
|
|
294
|
+
return new web3_js_1.PublicKey(pool.address);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Derive customizable pool address using PDA seeds.
|
|
298
|
+
* Seeds: ["cpool", max(mintA, mintB), min(mintA, mintB)]
|
|
299
|
+
*/
|
|
300
|
+
deriveCustomizablePoolAddress(mintA, mintB) {
|
|
301
|
+
const DAMM_PROGRAM_ID = new web3_js_1.PublicKey("cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG");
|
|
302
|
+
const buf1 = mintA.toBuffer();
|
|
303
|
+
const buf2 = mintB.toBuffer();
|
|
304
|
+
const first = Buffer.compare(buf1, buf2) === 1 ? buf1 : buf2;
|
|
305
|
+
const second = Buffer.compare(buf1, buf2) === 1 ? buf2 : buf1;
|
|
306
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("cpool"), first, second], DAMM_PROGRAM_ID)[0];
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
exports.MeteoraDammV1Adapter = MeteoraDammV1Adapter;
|
|
310
|
+
// ---------------------------------------------------------------------------
|
|
311
|
+
// Auto-register
|
|
312
|
+
// ---------------------------------------------------------------------------
|
|
313
|
+
(0, index_1.registerAdapter)(new MeteoraDammV1Adapter());
|
|
314
|
+
//# sourceMappingURL=meteora-damm-v1.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meteora-damm-v1.js","sourceRoot":"","sources":["../../src/dex/meteora-damm-v1.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;;;AAEH,kDAAuB;AACvB,4DAAiC;AACjC,6CAIyB;AACzB,kFAAkD;AAClD,iDAAmH;AAEnH,8CAA6D;AAC7D,qDAA0D;AAC1D,uDAA6D;AAE7D,mCAoBiB;AAEjB,mCAA0C;AAE1C,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E,6CAA6C;AAC7C,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAChC,iBAAS;IACT,iBAAS;IACT,6CAA6C,EAAE,OAAO;CACvD,CAAC,CAAC;AAEH,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E;;;GAGG;AACH,SAAS,aAAa,CAAC,YAAoB;IACzC,OAAO,iBAAiB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACrD,CAAC;AAED;;GAEG;AACH,SAAS,gBAAgB,CAAC,MAAc,EAAE,YAAoB;IAC5D,MAAM,QAAQ,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC;IAC7C,OAAO,IAAI,eAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED,8EAA8E;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AAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;QAE9D,OAAO,mBAAS,CAAC,sBAAsB,CACrC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,EACrC,eAAe,CAChB,CAAC,CAAC,CAAC,CAAC;IACP,CAAC;CACF;AAzUD,oDAyUC;AAED,8EAA8E;AAC9E,gBAAgB;AAChB,8EAA8E;AAE9E,IAAA,uBAAe,EAAC,IAAI,oBAAoB,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Meteora DAMM v2 (CP AMM) — IDexAdapter Implementation
|
|
3
|
+
*
|
|
4
|
+
* Wraps the @meteora-ag/cp-amm-sdk (CpAmm) for buy/sell/snipe/findPool/getPrice
|
|
5
|
+
* plus LP operations: addLiquidity (create position), removeLiquidity (close
|
|
6
|
+
* position), and claimFees.
|
|
7
|
+
*
|
|
8
|
+
* Source: 100x-algo-bots/trading-modules/meteora-damm-v2/
|
|
9
|
+
*
|
|
10
|
+
* SDK pattern:
|
|
11
|
+
* const cpAmm = new CpAmm(connection);
|
|
12
|
+
* const poolState = await cpAmm.fetchPoolState(poolAddress);
|
|
13
|
+
* const swapTx = await cpAmm.swap({ payer, pool, inputTokenMint, ... });
|
|
14
|
+
* const addTx = cpAmm.createPositionAndAddLiquidity({ ... });
|
|
15
|
+
* const removeTx = cpAmm.removeAllLiquidityAndClosePosition({ ... });
|
|
16
|
+
* const claimTx = cpAmm.claimPositionFee2({ ... });
|
|
17
|
+
*/
|
|
18
|
+
import { IDexAdapter, DexCapabilities, BuyParams, SellParams, SnipeParams, SwapResult, PoolInfo, PriceInfo, BuildSwapIxsResult, AddLiquidityParams, RemoveLiquidityParams, CreateCustomPoolParams, CreateConfigPoolParams, LpPositionInfo, TxResult } from "./types";
|
|
19
|
+
export declare class MeteoraDammV2Adapter implements IDexAdapter {
|
|
20
|
+
readonly name = "meteora-damm-v2";
|
|
21
|
+
readonly protocol = "damm-v2";
|
|
22
|
+
readonly capabilities: DexCapabilities;
|
|
23
|
+
buy(params: BuyParams): Promise<SwapResult>;
|
|
24
|
+
sell(params: SellParams): Promise<SwapResult>;
|
|
25
|
+
snipe(params: SnipeParams): Promise<SwapResult>;
|
|
26
|
+
buildSwapIxs(params: BuyParams | SellParams): Promise<BuildSwapIxsResult>;
|
|
27
|
+
findPool(baseMint: string, quoteMint?: string): Promise<PoolInfo | null>;
|
|
28
|
+
getPrice(poolAddress: string): Promise<PriceInfo>;
|
|
29
|
+
/**
|
|
30
|
+
* Add liquidity to an existing DAMM v2 pool by creating a new position.
|
|
31
|
+
*
|
|
32
|
+
* DAMM v2 uses full-range positions (MIN_SQRT_PRICE → MAX_SQRT_PRICE).
|
|
33
|
+
*
|
|
34
|
+
* The correct pattern (from zodiac/operator meteora-executor.ts):
|
|
35
|
+
* 1. Read the pool's actual sqrtPrice from on-chain state
|
|
36
|
+
* 2. Compute both token amounts proportionally from pool vault reserves
|
|
37
|
+
* 3. Pass both amounts + pool's sqrtPrice to getLiquidityDelta()
|
|
38
|
+
*
|
|
39
|
+
* The SDK's getLiquidityDelta is the black box — give it both max amounts
|
|
40
|
+
* + the current sqrtPrice, it figures out the correct liquidity delta.
|
|
41
|
+
*/
|
|
42
|
+
addLiquidity(params: AddLiquidityParams): Promise<TxResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Remove liquidity from all DAMM v2 positions on a pool.
|
|
45
|
+
*
|
|
46
|
+
* Uses getPositionsByUser() to discover positions on-chain (no database
|
|
47
|
+
* dependency), then calls removeAllLiquidityAndClosePosition() for each.
|
|
48
|
+
*
|
|
49
|
+
* Params:
|
|
50
|
+
* - poolAddress: the pool to remove liquidity from
|
|
51
|
+
* - percentage: 100 = remove all, <100 = partial (only full removal
|
|
52
|
+
* supported by the SDK's close-position method — partial uses removeLiquidity)
|
|
53
|
+
*
|
|
54
|
+
* Ported from: 100x-algo-bots/trading-modules/meteora-damm-v2/pool.ts
|
|
55
|
+
* removeAllLiquidityAndCloseAllPositions()
|
|
56
|
+
*/
|
|
57
|
+
removeLiquidity(params: RemoveLiquidityParams): Promise<TxResult>;
|
|
58
|
+
/**
|
|
59
|
+
* Claim unclaimed fees from all DAMM v2 positions on a pool.
|
|
60
|
+
*
|
|
61
|
+
* Uses getPositionsByUser() + on-chain fee math (no database dependency).
|
|
62
|
+
* Iterates all positions for the given pool, skips those with zero fees.
|
|
63
|
+
*
|
|
64
|
+
* Ported from: 100x-algo-bots/trading-modules/meteora-damm-v2/pool.ts
|
|
65
|
+
* claimAllPositionFees() + getUnClaimLpFee()
|
|
66
|
+
*/
|
|
67
|
+
claimFees(poolAddress: string, _positionAddress?: string): Promise<TxResult>;
|
|
68
|
+
/**
|
|
69
|
+
* Create a DAMM v2 pool with full fee configuration (custom pool).
|
|
70
|
+
*
|
|
71
|
+
* Uses `cpAmm.createCustomPool()` — allows setting fee schedule, price range,
|
|
72
|
+
* activation params, dynamic fee, and collect-fee mode.
|
|
73
|
+
*
|
|
74
|
+
* This is the primary method for token launches. Creates a customizable pool
|
|
75
|
+
* with MIN_SQRT_PRICE → MAX_SQRT_PRICE full-range liquidity.
|
|
76
|
+
*
|
|
77
|
+
* Ported from: 100x-algo-bots/trading-modules/meteora-damm-v2/create.ts
|
|
78
|
+
* createDammV2BalancedPool()
|
|
79
|
+
*/
|
|
80
|
+
createCustomPool(params: CreateCustomPoolParams): Promise<TxResult>;
|
|
81
|
+
/**
|
|
82
|
+
* Create a DAMM v2 pool using a pre-existing on-chain config.
|
|
83
|
+
*
|
|
84
|
+
* Uses `cpAmm.createPool()` — simpler, less customizable. The config
|
|
85
|
+
* determines the fee schedule and price range boundaries.
|
|
86
|
+
*
|
|
87
|
+
* Ported from: 100x-algo-bots/trading-modules/meteora-damm-v2/create.ts
|
|
88
|
+
* createDammV2Pool()
|
|
89
|
+
*/
|
|
90
|
+
createConfigPool(params: CreateConfigPoolParams): Promise<TxResult>;
|
|
91
|
+
/**
|
|
92
|
+
* List all DAMM v2 positions owned by the user on a specific pool.
|
|
93
|
+
*
|
|
94
|
+
* Uses `getPositionsByUser()` to discover positions on-chain, then
|
|
95
|
+
* calculates unclaimed fees for each position.
|
|
96
|
+
*
|
|
97
|
+
* Ported from: 100x-algo-bots/trading-modules/meteora-damm-v2/pool.ts
|
|
98
|
+
* fetchPositionsByUser()
|
|
99
|
+
*/
|
|
100
|
+
listPositions(poolAddress: string): Promise<LpPositionInfo[]>;
|
|
101
|
+
private resolvePool;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=meteora-damm-v2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meteora-damm-v2.d.ts","sourceRoot":"","sources":["../../src/dex/meteora-damm-v2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AA6CH,OAAO,EACL,WAAW,EACX,eAAe,EAEf,SAAS,EACT,UAAU,EACV,WAAW,EACX,UAAU,EACV,QAAQ,EACR,SAAS,EACT,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EACtB,cAAc,EACd,QAAQ,EAUT,MAAM,SAAS,CAAC;AAsHjB,qBAAa,oBAAqB,YAAW,WAAW;IACtD,QAAQ,CAAC,IAAI,qBAAqB;IAClC,QAAQ,CAAC,QAAQ,aAAa;IAC9B,QAAQ,CAAC,YAAY,EAAE,eAAe,CAWnC;IAIG,GAAG,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC;IA0E3C,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IA0F7C,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;IA6D/C,YAAY,CAAC,MAAM,EAAE,SAAS,GAAG,UAAU,GAAG,OAAO,CAAC,kBAAkB,CAAC;I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