@coffer_so/sdk 1.0.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 +283 -0
- package/dist/clients/AdminClient.d.ts +194 -0
- package/dist/clients/AdminClient.d.ts.map +1 -0
- package/dist/clients/AdminClient.js +482 -0
- package/dist/clients/AdminClient.js.map +1 -0
- package/dist/clients/CofferBackendClient.d.ts +877 -0
- package/dist/clients/CofferBackendClient.d.ts.map +1 -0
- package/dist/clients/CofferBackendClient.js +536 -0
- package/dist/clients/CofferBackendClient.js.map +1 -0
- package/dist/clients/CubeBackendClient.d.ts +877 -0
- package/dist/clients/CubeBackendClient.d.ts.map +1 -0
- package/dist/clients/CubeBackendClient.js +536 -0
- package/dist/clients/CubeBackendClient.js.map +1 -0
- package/dist/clients/CubicPoolClient.d.ts +120 -0
- package/dist/clients/CubicPoolClient.d.ts.map +1 -0
- package/dist/clients/CubicPoolClient.js +687 -0
- package/dist/clients/CubicPoolClient.js.map +1 -0
- package/dist/clients/PoolFactoryClient.d.ts +53 -0
- package/dist/clients/PoolFactoryClient.d.ts.map +1 -0
- package/dist/clients/PoolFactoryClient.js +91 -0
- package/dist/clients/PoolFactoryClient.js.map +1 -0
- package/dist/clients/RpcClient.d.ts +49 -0
- package/dist/clients/RpcClient.d.ts.map +1 -0
- package/dist/clients/RpcClient.js +135 -0
- package/dist/clients/RpcClient.js.map +1 -0
- package/dist/clients/SingleTokenDepositClient.d.ts +67 -0
- package/dist/clients/SingleTokenDepositClient.d.ts.map +1 -0
- package/dist/clients/SingleTokenDepositClient.js +105 -0
- package/dist/clients/SingleTokenDepositClient.js.map +1 -0
- package/dist/clients/contract-instructions.d.ts +24 -0
- package/dist/clients/contract-instructions.d.ts.map +1 -0
- package/dist/clients/contract-instructions.js +130 -0
- package/dist/clients/contract-instructions.js.map +1 -0
- package/dist/clients/index.d.ts +10 -0
- package/dist/clients/index.d.ts.map +1 -0
- package/dist/clients/index.js +26 -0
- package/dist/clients/index.js.map +1 -0
- package/dist/clients/quote-math.d.ts +15 -0
- package/dist/clients/quote-math.d.ts.map +1 -0
- package/dist/clients/quote-math.js +98 -0
- package/dist/clients/quote-math.js.map +1 -0
- package/dist/clients/tx-builders.d.ts +231 -0
- package/dist/clients/tx-builders.d.ts.map +1 -0
- package/dist/clients/tx-builders.js +861 -0
- package/dist/clients/tx-builders.js.map +1 -0
- package/dist/clients/versioned.d.ts +34 -0
- package/dist/clients/versioned.d.ts.map +1 -0
- package/dist/clients/versioned.js +55 -0
- package/dist/clients/versioned.js.map +1 -0
- package/dist/config/index.d.ts +65 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +75 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/networks.d.ts +12 -0
- package/dist/config/networks.d.ts.map +1 -0
- package/dist/config/networks.js +51 -0
- package/dist/config/networks.js.map +1 -0
- package/dist/config/tokens.d.ts +19 -0
- package/dist/config/tokens.d.ts.map +1 -0
- package/dist/config/tokens.js +43 -0
- package/dist/config/tokens.js.map +1 -0
- package/dist/idl/cubic_pool.json +4203 -0
- package/dist/idl/index.d.ts +1769 -0
- package/dist/idl/index.d.ts.map +1 -0
- package/dist/idl/index.js +18 -0
- package/dist/idl/index.js.map +1 -0
- package/dist/idl/protocol_admin.json +2615 -0
- package/dist/idl/single_token_liquidity.json +1121 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +206 -0
- package/dist/index.js.map +1 -0
- package/dist/math/cubicMath.d.ts +40 -0
- package/dist/math/cubicMath.d.ts.map +1 -0
- package/dist/math/cubicMath.js +82 -0
- package/dist/math/cubicMath.js.map +1 -0
- package/dist/math/fixedPoint.d.ts +19 -0
- package/dist/math/fixedPoint.d.ts.map +1 -0
- package/dist/math/fixedPoint.js +86 -0
- package/dist/math/fixedPoint.js.map +1 -0
- package/dist/math/index.d.ts +9 -0
- package/dist/math/index.d.ts.map +1 -0
- package/dist/math/index.js +30 -0
- package/dist/math/index.js.map +1 -0
- package/dist/math/logExp.d.ts +6 -0
- package/dist/math/logExp.d.ts.map +1 -0
- package/dist/math/logExp.js +68 -0
- package/dist/math/logExp.js.map +1 -0
- package/dist/math/lpLoss.d.ts +44 -0
- package/dist/math/lpLoss.d.ts.map +1 -0
- package/dist/math/lpLoss.js +103 -0
- package/dist/math/lpLoss.js.map +1 -0
- package/dist/math/maxSelloff.d.ts +164 -0
- package/dist/math/maxSelloff.d.ts.map +1 -0
- package/dist/math/maxSelloff.js +397 -0
- package/dist/math/maxSelloff.js.map +1 -0
- package/dist/math/singleToken.d.ts +54 -0
- package/dist/math/singleToken.d.ts.map +1 -0
- package/dist/math/singleToken.js +188 -0
- package/dist/math/singleToken.js.map +1 -0
- package/dist/math/slippage.d.ts +13 -0
- package/dist/math/slippage.d.ts.map +1 -0
- package/dist/math/slippage.js +44 -0
- package/dist/math/slippage.js.map +1 -0
- package/dist/math/surgeFee.d.ts +24 -0
- package/dist/math/surgeFee.d.ts.map +1 -0
- package/dist/math/surgeFee.js +85 -0
- package/dist/math/surgeFee.js.map +1 -0
- package/dist/math/weightedMath.d.ts +20 -0
- package/dist/math/weightedMath.d.ts.map +1 -0
- package/dist/math/weightedMath.js +66 -0
- package/dist/math/weightedMath.js.map +1 -0
- package/dist/parsers/borsh.d.ts +28 -0
- package/dist/parsers/borsh.d.ts.map +1 -0
- package/dist/parsers/borsh.js +104 -0
- package/dist/parsers/borsh.js.map +1 -0
- package/dist/parsers/contracts.d.ts +26 -0
- package/dist/parsers/contracts.d.ts.map +1 -0
- package/dist/parsers/contracts.js +62 -0
- package/dist/parsers/contracts.js.map +1 -0
- package/dist/parsers/events.d.ts +3 -0
- package/dist/parsers/events.d.ts.map +1 -0
- package/dist/parsers/events.js +281 -0
- package/dist/parsers/events.js.map +1 -0
- package/dist/parsers/index.d.ts +6 -0
- package/dist/parsers/index.d.ts.map +1 -0
- package/dist/parsers/index.js +22 -0
- package/dist/parsers/index.js.map +1 -0
- package/dist/parsers/mintAccount.d.ts +24 -0
- package/dist/parsers/mintAccount.d.ts.map +1 -0
- package/dist/parsers/mintAccount.js +27 -0
- package/dist/parsers/mintAccount.js.map +1 -0
- package/dist/parsers/poolAccount.d.ts +141 -0
- package/dist/parsers/poolAccount.d.ts.map +1 -0
- package/dist/parsers/poolAccount.js +224 -0
- package/dist/parsers/poolAccount.js.map +1 -0
- package/dist/types/contracts.d.ts +1340 -0
- package/dist/types/contracts.d.ts.map +1 -0
- package/dist/types/contracts.js +3 -0
- package/dist/types/contracts.js.map +1 -0
- package/dist/types/events.d.ts +172 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +3 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +22 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/pool.d.ts +149 -0
- package/dist/types/pool.d.ts.map +1 -0
- package/dist/types/pool.js +3 -0
- package/dist/types/pool.js.map +1 -0
- package/dist/types/result.d.ts +24 -0
- package/dist/types/result.d.ts.map +1 -0
- package/dist/types/result.js +11 -0
- package/dist/types/result.js.map +1 -0
- package/dist/types/tx.d.ts +261 -0
- package/dist/types/tx.d.ts.map +1 -0
- package/dist/types/tx.js +3 -0
- package/dist/types/tx.js.map +1 -0
- package/dist/utils/errors.d.ts +44 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +192 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/extensions.d.ts +98 -0
- package/dist/utils/extensions.d.ts.map +1 -0
- package/dist/utils/extensions.js +187 -0
- package/dist/utils/extensions.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +21 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/pda.d.ts +8 -0
- package/dist/utils/pda.d.ts.map +1 -0
- package/dist/utils/pda.js +27 -0
- package/dist/utils/pda.js.map +1 -0
- package/dist/utils/retry.d.ts +22 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +62 -0
- package/dist/utils/retry.js.map +1 -0
- package/package.json +54 -0
- package/src/clients/AdminClient.ts +608 -0
- package/src/clients/CofferBackendClient.ts +1413 -0
- package/src/clients/CubicPoolClient.ts +719 -0
- package/src/clients/PoolFactoryClient.ts +110 -0
- package/src/clients/RpcClient.ts +195 -0
- package/src/clients/SingleTokenDepositClient.ts +143 -0
- package/src/clients/contract-instructions.ts +115 -0
- package/src/clients/index.ts +9 -0
- package/src/clients/quote-math.ts +81 -0
- package/src/clients/tx-builders.ts +1096 -0
- package/src/clients/versioned.ts +80 -0
- package/src/config/index.ts +111 -0
- package/src/config/networks.ts +71 -0
- package/src/config/tokens.ts +52 -0
- package/src/idl/cubic_pool.json +4203 -0
- package/src/idl/index.ts +13 -0
- package/src/idl/protocol_admin.json +2615 -0
- package/src/idl/single_token_liquidity.json +1121 -0
- package/src/index.ts +262 -0
- package/src/math/cubicMath.ts +92 -0
- package/src/math/fixedPoint.ts +71 -0
- package/src/math/index.ts +13 -0
- package/src/math/logExp.ts +61 -0
- package/src/math/lpLoss.ts +160 -0
- package/src/math/maxSelloff.ts +564 -0
- package/src/math/singleToken.ts +251 -0
- package/src/math/slippage.ts +38 -0
- package/src/math/surgeFee.ts +101 -0
- package/src/math/weightedMath.ts +64 -0
- package/src/parsers/borsh.ts +106 -0
- package/src/parsers/contracts.ts +64 -0
- package/src/parsers/events.ts +275 -0
- package/src/parsers/index.ts +5 -0
- package/src/parsers/mintAccount.ts +44 -0
- package/src/parsers/poolAccount.ts +372 -0
- package/src/types/contracts.ts +238 -0
- package/src/types/events.ts +198 -0
- package/src/types/index.ts +5 -0
- package/src/types/pool.ts +147 -0
- package/src/types/result.ts +51 -0
- package/src/types/tx.ts +278 -0
- package/src/utils/errors.ts +210 -0
- package/src/utils/extensions.ts +196 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/pda.ts +58 -0
- package/src/utils/retry.ts +85 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @coffer_so/sdk — client library for the Cubic Pool AMM on Solana.
|
|
3
|
+
*
|
|
4
|
+
* Entry point barrel. Most consumers will want to import from this root:
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { CubicPoolClient, CofferBackendClient, getConfig } from "@coffer_so/sdk";
|
|
8
|
+
*
|
|
9
|
+
* const cfg = getConfig("mainnet", { backendEndpoint: "https://api.coffer.so" });
|
|
10
|
+
* const pool = new CubicPoolClient({ config: cfg, poolAddress });
|
|
11
|
+
* const info = await pool.sync();
|
|
12
|
+
* if (info.ok) console.log(info.data.tokens.map(t => t.metadata?.symbol));
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export * from "./config";
|
|
16
|
+
export * from "./types";
|
|
17
|
+
export * from "./utils";
|
|
18
|
+
export * from "./math";
|
|
19
|
+
export * from "./parsers";
|
|
20
|
+
export * from "./clients";
|
|
21
|
+
export * from "./idl";
|
|
22
|
+
export { getConfig, programId, CUBIC_POOL_SEED, BPT_MINT_SEED, STLD_HELPER_SEED, TREASURY_SEED, WEIGHT_SCALE, MIN_WEIGHT, MAX_WEIGHT, MIN_TOKENS, MAX_TOKENS, BPT_DECIMALS, SWAP_FEE_PRECISION, PROTOCOL_FEE_PRECISION, PERCENT_SCALE, MAX_SWAP_FEE_RATE, MAX_PROTOCOL_FEE_RATE, MINIMUM_INITIAL_BPT, SLIPPAGE_PRECISION, MIN_SLIPPAGE_HBPS, } from "./config";
|
|
23
|
+
export { NETWORK_PROGRAMS, DEFAULT_RPC_ENDPOINT, DEFAULT_RPC_ENDPOINTS, DEFAULT_RPC_TIMEOUT_MS, } from "./config/networks";
|
|
24
|
+
export { KNOWN_TOKENS, resolveKnownToken } from "./config/tokens";
|
|
25
|
+
export { ok, err } from "./types/result";
|
|
26
|
+
export { ONE, mulDown, mulUp, divDown, divUp, complement, weightToFp, } from "./math/fixedPoint";
|
|
27
|
+
export { lnFp, expFp, powFp } from "./math/logExp";
|
|
28
|
+
export { calcOutGivenIn, calcBptOutGivenExactTokensIn, calcTokensOutGivenBptIn, calcSpotOut, } from "./math/cubicMath";
|
|
29
|
+
export { validateWeights, calcSpotPrice } from "./math/weightedMath";
|
|
30
|
+
export { capDepositAmountsToLpRatio, computeAllocations, computeTwoTokenOptimalAllocations, } from "./math/singleToken";
|
|
31
|
+
export { applySlippage, applySwapFee, lpBalances, priceImpactHbps } from "./math/slippage";
|
|
32
|
+
export { computeSelloffWindow, projectSelloffWindow, calcSurgeFeePct, calcSurgeFeeAmount, calcSegmentedSurgeFeeAmount, SURGE_FEE_SEGMENTS, } from "./math/maxSelloff";
|
|
33
|
+
export { RpcClient } from "./clients/RpcClient";
|
|
34
|
+
export { CofferBackendClient } from "./clients/CofferBackendClient";
|
|
35
|
+
export { CubicPoolClient } from "./clients/CubicPoolClient";
|
|
36
|
+
export { SingleTokenDepositClient } from "./clients/SingleTokenDepositClient";
|
|
37
|
+
export { PoolFactoryClient } from "./clients/PoolFactoryClient";
|
|
38
|
+
export { AdminClient } from "./clients/AdminClient";
|
|
39
|
+
export { buildSwapIx, buildSwapTx, buildAddLiquidityIx, buildAddLiquidityTx, buildRemoveLiquidityIx, buildRemoveLiquidityTx, buildSingleTokenDepositIx, buildSingleTokenDepositTx, buildSingleTokenDepositTxs, buildSingleTokenDepositAtaIxs, buildInitializeConfigIx, buildPoolInitializeConfigIx, buildInitializeCubicPoolIx, buildDeployPoolTx, buildInitializePoolAltIx, buildInitializePoolAltTx, buildSetRangeManagerIx, buildSetRangeManagerConfigIx, buildRangeManagerUpdateIx, deriveAltAddress, STLD_MAX_TOKENS, STLD_DEPOSIT_CU_LIMIT, } from "./clients/tx-builders";
|
|
40
|
+
export { buildVersionedTx, compileBuiltTx } from "./clients/versioned";
|
|
41
|
+
export type { InitializePoolAltParams } from "./clients/tx-builders";
|
|
42
|
+
export { decodePoolAccount, POOL_DISCRIMINATOR_LEN, POOL_LEN, POOL_V4_LEN } from "./parsers/poolAccount";
|
|
43
|
+
export { toSdkError, describeProgramError } from "./utils/errors";
|
|
44
|
+
export { decodeMintAccount } from "./parsers/mintAccount";
|
|
45
|
+
export { parseCubicPoolEvents } from "./parsers/events";
|
|
46
|
+
export { BorshReader } from "./parsers/borsh";
|
|
47
|
+
export type { CofferConfig, CofferConfigOverrides, ProgramIdKind, Network, NetworkPrograms, TokenInfo, } from "./config";
|
|
48
|
+
export type { SdkResult, SdkError, SdkErrorCode, PoolTokenInfo, PoolInfo, PoolSummary, SwapParams, SwapQuote, AddLiquidityParams, RemoveLiquidityParams, SingleTokenDepositParams, SingleTokenDepositQuote, BuiltTx, DeployPoolParams, CubicPoolEvent, PoolInitializedEvent, SwapEvent, LiquidityAddedEvent, LiquidityRemovedEvent, ProtocolFeesCollectedEvent, PoolEnabledUpdatedEvent, SwapsEnabledUpdatedEvent, SingleTokenDepositEvent, PoolStateLogEvent, MaxSelloffWindowAdvancedEvent, BannedExtensionsUpdatedEvent, UnknownEvent, TokenChange, RangeManagerUpdateParams, SetRangeManagerParams, SetRangeManagerConfigParams, } from "./types";
|
|
49
|
+
export type { CofferProgram } from "./utils/errors";
|
|
50
|
+
export type { AllocationResult, } from "./math/singleToken";
|
|
51
|
+
export type { SelloffWindowInputs, SelloffWindowStatus, WindowProjection, } from "./math/maxSelloff";
|
|
52
|
+
export type { RawPoolAccount, RawMintAccount, } from "./parsers";
|
|
53
|
+
export type { RpcClientParams, CofferBackendClientParams, StatsKind, StatsWindow, StatsSeriesPoint, StatsSeries, PriceMap, LeaderboardEntry, LeaderboardResponse, LeaderboardUserStats, XpAccrualHistoryEntry, XpAccrualHistoryResponse, EpochHistoryEntry, LeaderboardEpochResponse, CampaignStatusResponse, CampaignInfoResponse, CampaignPrizeTier, CampaignRankResponse, CampaignTopEntry, CampaignTopResponse, PortfolioChartMetric, PortfolioChartRange, PortfolioChartResponse, PairChartRange, TokenPairChartResponse, PortfolioActivityType, PortfolioActivityFilter, ActivityTokenInfo, PortfolioActivityItem, PortfolioActivityResponse, SortOrder, PortfolioActivitySortField, PortfolioHoldingsSortField, PortfolioHoldingItem, PortfolioHoldingsResponse, PortfolioPositionsSortField, PortfolioPositionItem, PortfolioPositionsResponse, NonceResponse, TxChallengeResponse, AuthTokens, SwapRouteEntry, SwapRouteResponse, CubicPoolClientParams, SingleTokenDepositClientParams, PoolFactoryClientParams, InitializeConfigParams, } from "./clients";
|
|
54
|
+
export { buildContractInstruction } from "./clients/contract-instructions";
|
|
55
|
+
export { decodeContractAccount, decodeContractEvent, parseContractEvents } from "./parsers/contracts";
|
|
56
|
+
export type { ContractEvent } from "./parsers/contracts";
|
|
57
|
+
export type { ContractInstructionArgs, ContractInstructionAccounts } from "./clients/contract-instructions";
|
|
58
|
+
export type { ContractProgram, ContractInstructionMap, ContractAccountMap, ContractEventMap, ContractTypes } from "./types/contracts";
|
|
59
|
+
export { buildSetSwapFeeRateIx, buildSetMaxSelloffIx, buildInitiatePoolAdminTransferIx, buildAcceptPoolAdminTransferIx, buildCancelPoolAdminTransferIx, buildDisablePoolAdminIx, buildGetPoolInfoIx } from "./clients/tx-builders";
|
|
60
|
+
export type { SelloffParams, AddLiquidityQuote } from "./types/tx";
|
|
61
|
+
export { calculateSwapFee, calculateProtocolFee } from "./math/slippage";
|
|
62
|
+
export { checkAndAdvanceSelloff, rescaleSelloffWindow } from "./math/maxSelloff";
|
|
63
|
+
export type { SelloffState, SelloffResult } from "./math/maxSelloff";
|
|
64
|
+
export type { SurgeCurve } from "./math/surgeFee";
|
|
65
|
+
export { calculateInvariant } from "./math/weightedMath";
|
|
66
|
+
export { MintExtension, MAX_KNOWN_MINT_EXTENSION, HARD_UNSUPPORTED_MINT_EXTENSIONS, DEFAULT_BANNED_EXTENSIONS, mintExtensionName, parseMintExtensions, unsupportedMintExtensions, bannedMintExtensions, describeUnsupportedToken, assertTokensSupported } from "./utils/extensions";
|
|
67
|
+
/** @deprecated Use `CofferBackendClient`. */
|
|
68
|
+
export { CofferBackendClient as CubeBackendClient } from "./clients/CofferBackendClient";
|
|
69
|
+
/** @deprecated Use `CofferConfig` / `CofferConfigOverrides`. */
|
|
70
|
+
export type { CofferConfig as CubeConfig, CofferConfigOverrides as CubeConfigOverrides, } from "./config";
|
|
71
|
+
/** @deprecated Use `CofferProgram`. */
|
|
72
|
+
export type { CofferProgram as CubeProgram } from "./utils/errors";
|
|
73
|
+
/** @deprecated Use `CofferBackendClientParams`. */
|
|
74
|
+
export type { CofferBackendClientParams as CubeBackendClientParams } from "./clients";
|
|
75
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;GAaG;AAEH,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,OAAO,CAAC;AAItB,OAAO,EACL,SAAS,EACT,SAAS,EACT,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,YAAY,EACZ,kBAAkB,EAClB,sBAAsB,EACtB,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,gB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EAAE,MAAM,uBAAuB,CAAC;AACnO,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACjF,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACrE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAAE,gCAAgC,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAMpR,6CAA6C;AAC7C,OAAO,EAAE,mBAAmB,IAAI,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACzF,gEAAgE;AAChE,YAAY,EACV,YAAY,IAAI,UAAU,EAC1B,qBAAqB,IAAI,mBAAmB,GAC7C,MAAM,UAAU,CAAC;AAClB,uCAAuC;AACvC,YAAY,EAAE,aAAa,IAAI,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACnE,mDAAmD;AACnD,YAAY,EAAE,yBAAyB,IAAI,uBAAuB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) 2026 Endgame AMM DEX Foundation.
|
|
4
|
+
// See LICENSE at the repository root.
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.lpBalances = exports.applySwapFee = exports.applySlippage = exports.computeTwoTokenOptimalAllocations = exports.computeAllocations = exports.capDepositAmountsToLpRatio = exports.calcSpotPrice = exports.validateWeights = exports.calcSpotOut = exports.calcTokensOutGivenBptIn = exports.calcBptOutGivenExactTokensIn = exports.calcOutGivenIn = exports.powFp = exports.expFp = exports.lnFp = exports.weightToFp = exports.complement = exports.divUp = exports.divDown = exports.mulUp = exports.mulDown = exports.ONE = exports.err = exports.ok = exports.resolveKnownToken = exports.KNOWN_TOKENS = exports.DEFAULT_RPC_TIMEOUT_MS = exports.DEFAULT_RPC_ENDPOINTS = exports.DEFAULT_RPC_ENDPOINT = exports.NETWORK_PROGRAMS = exports.MIN_SLIPPAGE_HBPS = exports.SLIPPAGE_PRECISION = exports.MINIMUM_INITIAL_BPT = exports.MAX_PROTOCOL_FEE_RATE = exports.MAX_SWAP_FEE_RATE = exports.PERCENT_SCALE = exports.PROTOCOL_FEE_PRECISION = exports.SWAP_FEE_PRECISION = exports.BPT_DECIMALS = exports.MAX_TOKENS = exports.MIN_TOKENS = exports.MAX_WEIGHT = exports.MIN_WEIGHT = exports.WEIGHT_SCALE = exports.TREASURY_SEED = exports.STLD_HELPER_SEED = exports.BPT_MINT_SEED = exports.CUBIC_POOL_SEED = exports.programId = exports.getConfig = void 0;
|
|
21
|
+
exports.parseContractEvents = exports.decodeContractEvent = exports.decodeContractAccount = exports.buildContractInstruction = exports.BorshReader = exports.parseCubicPoolEvents = exports.decodeMintAccount = exports.describeProgramError = exports.toSdkError = exports.POOL_V4_LEN = exports.POOL_LEN = exports.POOL_DISCRIMINATOR_LEN = exports.decodePoolAccount = exports.compileBuiltTx = exports.buildVersionedTx = exports.STLD_DEPOSIT_CU_LIMIT = exports.STLD_MAX_TOKENS = exports.deriveAltAddress = exports.buildRangeManagerUpdateIx = exports.buildSetRangeManagerConfigIx = exports.buildSetRangeManagerIx = exports.buildInitializePoolAltTx = exports.buildInitializePoolAltIx = exports.buildDeployPoolTx = exports.buildInitializeCubicPoolIx = exports.buildPoolInitializeConfigIx = exports.buildInitializeConfigIx = exports.buildSingleTokenDepositAtaIxs = exports.buildSingleTokenDepositTxs = exports.buildSingleTokenDepositTx = exports.buildSingleTokenDepositIx = exports.buildRemoveLiquidityTx = exports.buildRemoveLiquidityIx = exports.buildAddLiquidityTx = exports.buildAddLiquidityIx = exports.buildSwapTx = exports.buildSwapIx = exports.AdminClient = exports.PoolFactoryClient = exports.SingleTokenDepositClient = exports.CubicPoolClient = exports.CofferBackendClient = exports.RpcClient = exports.SURGE_FEE_SEGMENTS = exports.calcSegmentedSurgeFeeAmount = exports.calcSurgeFeeAmount = exports.calcSurgeFeePct = exports.projectSelloffWindow = exports.computeSelloffWindow = exports.priceImpactHbps = void 0;
|
|
22
|
+
exports.CubeBackendClient = exports.assertTokensSupported = exports.describeUnsupportedToken = exports.bannedMintExtensions = exports.unsupportedMintExtensions = exports.parseMintExtensions = exports.mintExtensionName = exports.DEFAULT_BANNED_EXTENSIONS = exports.HARD_UNSUPPORTED_MINT_EXTENSIONS = exports.MAX_KNOWN_MINT_EXTENSION = exports.MintExtension = exports.calculateInvariant = exports.rescaleSelloffWindow = exports.checkAndAdvanceSelloff = exports.calculateProtocolFee = exports.calculateSwapFee = exports.buildGetPoolInfoIx = exports.buildDisablePoolAdminIx = exports.buildCancelPoolAdminTransferIx = exports.buildAcceptPoolAdminTransferIx = exports.buildInitiatePoolAdminTransferIx = exports.buildSetMaxSelloffIx = exports.buildSetSwapFeeRateIx = void 0;
|
|
23
|
+
/**
|
|
24
|
+
* @coffer_so/sdk — client library for the Cubic Pool AMM on Solana.
|
|
25
|
+
*
|
|
26
|
+
* Entry point barrel. Most consumers will want to import from this root:
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { CubicPoolClient, CofferBackendClient, getConfig } from "@coffer_so/sdk";
|
|
30
|
+
*
|
|
31
|
+
* const cfg = getConfig("mainnet", { backendEndpoint: "https://api.coffer.so" });
|
|
32
|
+
* const pool = new CubicPoolClient({ config: cfg, poolAddress });
|
|
33
|
+
* const info = await pool.sync();
|
|
34
|
+
* if (info.ok) console.log(info.data.tokens.map(t => t.metadata?.symbol));
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
__exportStar(require("./config"), exports);
|
|
38
|
+
__exportStar(require("./types"), exports);
|
|
39
|
+
__exportStar(require("./utils"), exports);
|
|
40
|
+
__exportStar(require("./math"), exports);
|
|
41
|
+
__exportStar(require("./parsers"), exports);
|
|
42
|
+
__exportStar(require("./clients"), exports);
|
|
43
|
+
__exportStar(require("./idl"), exports);
|
|
44
|
+
// Explicit runtime re-exports keep CommonJS output statically discoverable for
|
|
45
|
+
// Vite/Rollup consumers that import named exports from the package root.
|
|
46
|
+
var config_1 = require("./config");
|
|
47
|
+
Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return config_1.getConfig; } });
|
|
48
|
+
Object.defineProperty(exports, "programId", { enumerable: true, get: function () { return config_1.programId; } });
|
|
49
|
+
Object.defineProperty(exports, "CUBIC_POOL_SEED", { enumerable: true, get: function () { return config_1.CUBIC_POOL_SEED; } });
|
|
50
|
+
Object.defineProperty(exports, "BPT_MINT_SEED", { enumerable: true, get: function () { return config_1.BPT_MINT_SEED; } });
|
|
51
|
+
Object.defineProperty(exports, "STLD_HELPER_SEED", { enumerable: true, get: function () { return config_1.STLD_HELPER_SEED; } });
|
|
52
|
+
Object.defineProperty(exports, "TREASURY_SEED", { enumerable: true, get: function () { return config_1.TREASURY_SEED; } });
|
|
53
|
+
Object.defineProperty(exports, "WEIGHT_SCALE", { enumerable: true, get: function () { return config_1.WEIGHT_SCALE; } });
|
|
54
|
+
Object.defineProperty(exports, "MIN_WEIGHT", { enumerable: true, get: function () { return config_1.MIN_WEIGHT; } });
|
|
55
|
+
Object.defineProperty(exports, "MAX_WEIGHT", { enumerable: true, get: function () { return config_1.MAX_WEIGHT; } });
|
|
56
|
+
Object.defineProperty(exports, "MIN_TOKENS", { enumerable: true, get: function () { return config_1.MIN_TOKENS; } });
|
|
57
|
+
Object.defineProperty(exports, "MAX_TOKENS", { enumerable: true, get: function () { return config_1.MAX_TOKENS; } });
|
|
58
|
+
Object.defineProperty(exports, "BPT_DECIMALS", { enumerable: true, get: function () { return config_1.BPT_DECIMALS; } });
|
|
59
|
+
Object.defineProperty(exports, "SWAP_FEE_PRECISION", { enumerable: true, get: function () { return config_1.SWAP_FEE_PRECISION; } });
|
|
60
|
+
Object.defineProperty(exports, "PROTOCOL_FEE_PRECISION", { enumerable: true, get: function () { return config_1.PROTOCOL_FEE_PRECISION; } });
|
|
61
|
+
Object.defineProperty(exports, "PERCENT_SCALE", { enumerable: true, get: function () { return config_1.PERCENT_SCALE; } });
|
|
62
|
+
Object.defineProperty(exports, "MAX_SWAP_FEE_RATE", { enumerable: true, get: function () { return config_1.MAX_SWAP_FEE_RATE; } });
|
|
63
|
+
Object.defineProperty(exports, "MAX_PROTOCOL_FEE_RATE", { enumerable: true, get: function () { return config_1.MAX_PROTOCOL_FEE_RATE; } });
|
|
64
|
+
Object.defineProperty(exports, "MINIMUM_INITIAL_BPT", { enumerable: true, get: function () { return config_1.MINIMUM_INITIAL_BPT; } });
|
|
65
|
+
Object.defineProperty(exports, "SLIPPAGE_PRECISION", { enumerable: true, get: function () { return config_1.SLIPPAGE_PRECISION; } });
|
|
66
|
+
Object.defineProperty(exports, "MIN_SLIPPAGE_HBPS", { enumerable: true, get: function () { return config_1.MIN_SLIPPAGE_HBPS; } });
|
|
67
|
+
var networks_1 = require("./config/networks");
|
|
68
|
+
Object.defineProperty(exports, "NETWORK_PROGRAMS", { enumerable: true, get: function () { return networks_1.NETWORK_PROGRAMS; } });
|
|
69
|
+
Object.defineProperty(exports, "DEFAULT_RPC_ENDPOINT", { enumerable: true, get: function () { return networks_1.DEFAULT_RPC_ENDPOINT; } });
|
|
70
|
+
Object.defineProperty(exports, "DEFAULT_RPC_ENDPOINTS", { enumerable: true, get: function () { return networks_1.DEFAULT_RPC_ENDPOINTS; } });
|
|
71
|
+
Object.defineProperty(exports, "DEFAULT_RPC_TIMEOUT_MS", { enumerable: true, get: function () { return networks_1.DEFAULT_RPC_TIMEOUT_MS; } });
|
|
72
|
+
var tokens_1 = require("./config/tokens");
|
|
73
|
+
Object.defineProperty(exports, "KNOWN_TOKENS", { enumerable: true, get: function () { return tokens_1.KNOWN_TOKENS; } });
|
|
74
|
+
Object.defineProperty(exports, "resolveKnownToken", { enumerable: true, get: function () { return tokens_1.resolveKnownToken; } });
|
|
75
|
+
var result_1 = require("./types/result");
|
|
76
|
+
Object.defineProperty(exports, "ok", { enumerable: true, get: function () { return result_1.ok; } });
|
|
77
|
+
Object.defineProperty(exports, "err", { enumerable: true, get: function () { return result_1.err; } });
|
|
78
|
+
var fixedPoint_1 = require("./math/fixedPoint");
|
|
79
|
+
Object.defineProperty(exports, "ONE", { enumerable: true, get: function () { return fixedPoint_1.ONE; } });
|
|
80
|
+
Object.defineProperty(exports, "mulDown", { enumerable: true, get: function () { return fixedPoint_1.mulDown; } });
|
|
81
|
+
Object.defineProperty(exports, "mulUp", { enumerable: true, get: function () { return fixedPoint_1.mulUp; } });
|
|
82
|
+
Object.defineProperty(exports, "divDown", { enumerable: true, get: function () { return fixedPoint_1.divDown; } });
|
|
83
|
+
Object.defineProperty(exports, "divUp", { enumerable: true, get: function () { return fixedPoint_1.divUp; } });
|
|
84
|
+
Object.defineProperty(exports, "complement", { enumerable: true, get: function () { return fixedPoint_1.complement; } });
|
|
85
|
+
Object.defineProperty(exports, "weightToFp", { enumerable: true, get: function () { return fixedPoint_1.weightToFp; } });
|
|
86
|
+
var logExp_1 = require("./math/logExp");
|
|
87
|
+
Object.defineProperty(exports, "lnFp", { enumerable: true, get: function () { return logExp_1.lnFp; } });
|
|
88
|
+
Object.defineProperty(exports, "expFp", { enumerable: true, get: function () { return logExp_1.expFp; } });
|
|
89
|
+
Object.defineProperty(exports, "powFp", { enumerable: true, get: function () { return logExp_1.powFp; } });
|
|
90
|
+
var cubicMath_1 = require("./math/cubicMath");
|
|
91
|
+
Object.defineProperty(exports, "calcOutGivenIn", { enumerable: true, get: function () { return cubicMath_1.calcOutGivenIn; } });
|
|
92
|
+
Object.defineProperty(exports, "calcBptOutGivenExactTokensIn", { enumerable: true, get: function () { return cubicMath_1.calcBptOutGivenExactTokensIn; } });
|
|
93
|
+
Object.defineProperty(exports, "calcTokensOutGivenBptIn", { enumerable: true, get: function () { return cubicMath_1.calcTokensOutGivenBptIn; } });
|
|
94
|
+
Object.defineProperty(exports, "calcSpotOut", { enumerable: true, get: function () { return cubicMath_1.calcSpotOut; } });
|
|
95
|
+
var weightedMath_1 = require("./math/weightedMath");
|
|
96
|
+
Object.defineProperty(exports, "validateWeights", { enumerable: true, get: function () { return weightedMath_1.validateWeights; } });
|
|
97
|
+
Object.defineProperty(exports, "calcSpotPrice", { enumerable: true, get: function () { return weightedMath_1.calcSpotPrice; } });
|
|
98
|
+
var singleToken_1 = require("./math/singleToken");
|
|
99
|
+
Object.defineProperty(exports, "capDepositAmountsToLpRatio", { enumerable: true, get: function () { return singleToken_1.capDepositAmountsToLpRatio; } });
|
|
100
|
+
Object.defineProperty(exports, "computeAllocations", { enumerable: true, get: function () { return singleToken_1.computeAllocations; } });
|
|
101
|
+
Object.defineProperty(exports, "computeTwoTokenOptimalAllocations", { enumerable: true, get: function () { return singleToken_1.computeTwoTokenOptimalAllocations; } });
|
|
102
|
+
var slippage_1 = require("./math/slippage");
|
|
103
|
+
Object.defineProperty(exports, "applySlippage", { enumerable: true, get: function () { return slippage_1.applySlippage; } });
|
|
104
|
+
Object.defineProperty(exports, "applySwapFee", { enumerable: true, get: function () { return slippage_1.applySwapFee; } });
|
|
105
|
+
Object.defineProperty(exports, "lpBalances", { enumerable: true, get: function () { return slippage_1.lpBalances; } });
|
|
106
|
+
Object.defineProperty(exports, "priceImpactHbps", { enumerable: true, get: function () { return slippage_1.priceImpactHbps; } });
|
|
107
|
+
var maxSelloff_1 = require("./math/maxSelloff");
|
|
108
|
+
Object.defineProperty(exports, "computeSelloffWindow", { enumerable: true, get: function () { return maxSelloff_1.computeSelloffWindow; } });
|
|
109
|
+
Object.defineProperty(exports, "projectSelloffWindow", { enumerable: true, get: function () { return maxSelloff_1.projectSelloffWindow; } });
|
|
110
|
+
Object.defineProperty(exports, "calcSurgeFeePct", { enumerable: true, get: function () { return maxSelloff_1.calcSurgeFeePct; } });
|
|
111
|
+
Object.defineProperty(exports, "calcSurgeFeeAmount", { enumerable: true, get: function () { return maxSelloff_1.calcSurgeFeeAmount; } });
|
|
112
|
+
Object.defineProperty(exports, "calcSegmentedSurgeFeeAmount", { enumerable: true, get: function () { return maxSelloff_1.calcSegmentedSurgeFeeAmount; } });
|
|
113
|
+
Object.defineProperty(exports, "SURGE_FEE_SEGMENTS", { enumerable: true, get: function () { return maxSelloff_1.SURGE_FEE_SEGMENTS; } });
|
|
114
|
+
var RpcClient_1 = require("./clients/RpcClient");
|
|
115
|
+
Object.defineProperty(exports, "RpcClient", { enumerable: true, get: function () { return RpcClient_1.RpcClient; } });
|
|
116
|
+
var CofferBackendClient_1 = require("./clients/CofferBackendClient");
|
|
117
|
+
Object.defineProperty(exports, "CofferBackendClient", { enumerable: true, get: function () { return CofferBackendClient_1.CofferBackendClient; } });
|
|
118
|
+
var CubicPoolClient_1 = require("./clients/CubicPoolClient");
|
|
119
|
+
Object.defineProperty(exports, "CubicPoolClient", { enumerable: true, get: function () { return CubicPoolClient_1.CubicPoolClient; } });
|
|
120
|
+
var SingleTokenDepositClient_1 = require("./clients/SingleTokenDepositClient");
|
|
121
|
+
Object.defineProperty(exports, "SingleTokenDepositClient", { enumerable: true, get: function () { return SingleTokenDepositClient_1.SingleTokenDepositClient; } });
|
|
122
|
+
var PoolFactoryClient_1 = require("./clients/PoolFactoryClient");
|
|
123
|
+
Object.defineProperty(exports, "PoolFactoryClient", { enumerable: true, get: function () { return PoolFactoryClient_1.PoolFactoryClient; } });
|
|
124
|
+
var AdminClient_1 = require("./clients/AdminClient");
|
|
125
|
+
Object.defineProperty(exports, "AdminClient", { enumerable: true, get: function () { return AdminClient_1.AdminClient; } });
|
|
126
|
+
var tx_builders_1 = require("./clients/tx-builders");
|
|
127
|
+
Object.defineProperty(exports, "buildSwapIx", { enumerable: true, get: function () { return tx_builders_1.buildSwapIx; } });
|
|
128
|
+
Object.defineProperty(exports, "buildSwapTx", { enumerable: true, get: function () { return tx_builders_1.buildSwapTx; } });
|
|
129
|
+
Object.defineProperty(exports, "buildAddLiquidityIx", { enumerable: true, get: function () { return tx_builders_1.buildAddLiquidityIx; } });
|
|
130
|
+
Object.defineProperty(exports, "buildAddLiquidityTx", { enumerable: true, get: function () { return tx_builders_1.buildAddLiquidityTx; } });
|
|
131
|
+
Object.defineProperty(exports, "buildRemoveLiquidityIx", { enumerable: true, get: function () { return tx_builders_1.buildRemoveLiquidityIx; } });
|
|
132
|
+
Object.defineProperty(exports, "buildRemoveLiquidityTx", { enumerable: true, get: function () { return tx_builders_1.buildRemoveLiquidityTx; } });
|
|
133
|
+
Object.defineProperty(exports, "buildSingleTokenDepositIx", { enumerable: true, get: function () { return tx_builders_1.buildSingleTokenDepositIx; } });
|
|
134
|
+
Object.defineProperty(exports, "buildSingleTokenDepositTx", { enumerable: true, get: function () { return tx_builders_1.buildSingleTokenDepositTx; } });
|
|
135
|
+
Object.defineProperty(exports, "buildSingleTokenDepositTxs", { enumerable: true, get: function () { return tx_builders_1.buildSingleTokenDepositTxs; } });
|
|
136
|
+
Object.defineProperty(exports, "buildSingleTokenDepositAtaIxs", { enumerable: true, get: function () { return tx_builders_1.buildSingleTokenDepositAtaIxs; } });
|
|
137
|
+
Object.defineProperty(exports, "buildInitializeConfigIx", { enumerable: true, get: function () { return tx_builders_1.buildInitializeConfigIx; } });
|
|
138
|
+
Object.defineProperty(exports, "buildPoolInitializeConfigIx", { enumerable: true, get: function () { return tx_builders_1.buildPoolInitializeConfigIx; } });
|
|
139
|
+
Object.defineProperty(exports, "buildInitializeCubicPoolIx", { enumerable: true, get: function () { return tx_builders_1.buildInitializeCubicPoolIx; } });
|
|
140
|
+
Object.defineProperty(exports, "buildDeployPoolTx", { enumerable: true, get: function () { return tx_builders_1.buildDeployPoolTx; } });
|
|
141
|
+
Object.defineProperty(exports, "buildInitializePoolAltIx", { enumerable: true, get: function () { return tx_builders_1.buildInitializePoolAltIx; } });
|
|
142
|
+
Object.defineProperty(exports, "buildInitializePoolAltTx", { enumerable: true, get: function () { return tx_builders_1.buildInitializePoolAltTx; } });
|
|
143
|
+
Object.defineProperty(exports, "buildSetRangeManagerIx", { enumerable: true, get: function () { return tx_builders_1.buildSetRangeManagerIx; } });
|
|
144
|
+
Object.defineProperty(exports, "buildSetRangeManagerConfigIx", { enumerable: true, get: function () { return tx_builders_1.buildSetRangeManagerConfigIx; } });
|
|
145
|
+
Object.defineProperty(exports, "buildRangeManagerUpdateIx", { enumerable: true, get: function () { return tx_builders_1.buildRangeManagerUpdateIx; } });
|
|
146
|
+
Object.defineProperty(exports, "deriveAltAddress", { enumerable: true, get: function () { return tx_builders_1.deriveAltAddress; } });
|
|
147
|
+
Object.defineProperty(exports, "STLD_MAX_TOKENS", { enumerable: true, get: function () { return tx_builders_1.STLD_MAX_TOKENS; } });
|
|
148
|
+
Object.defineProperty(exports, "STLD_DEPOSIT_CU_LIMIT", { enumerable: true, get: function () { return tx_builders_1.STLD_DEPOSIT_CU_LIMIT; } });
|
|
149
|
+
var versioned_1 = require("./clients/versioned");
|
|
150
|
+
Object.defineProperty(exports, "buildVersionedTx", { enumerable: true, get: function () { return versioned_1.buildVersionedTx; } });
|
|
151
|
+
Object.defineProperty(exports, "compileBuiltTx", { enumerable: true, get: function () { return versioned_1.compileBuiltTx; } });
|
|
152
|
+
var poolAccount_1 = require("./parsers/poolAccount");
|
|
153
|
+
Object.defineProperty(exports, "decodePoolAccount", { enumerable: true, get: function () { return poolAccount_1.decodePoolAccount; } });
|
|
154
|
+
Object.defineProperty(exports, "POOL_DISCRIMINATOR_LEN", { enumerable: true, get: function () { return poolAccount_1.POOL_DISCRIMINATOR_LEN; } });
|
|
155
|
+
Object.defineProperty(exports, "POOL_LEN", { enumerable: true, get: function () { return poolAccount_1.POOL_LEN; } });
|
|
156
|
+
Object.defineProperty(exports, "POOL_V4_LEN", { enumerable: true, get: function () { return poolAccount_1.POOL_V4_LEN; } });
|
|
157
|
+
var errors_1 = require("./utils/errors");
|
|
158
|
+
Object.defineProperty(exports, "toSdkError", { enumerable: true, get: function () { return errors_1.toSdkError; } });
|
|
159
|
+
Object.defineProperty(exports, "describeProgramError", { enumerable: true, get: function () { return errors_1.describeProgramError; } });
|
|
160
|
+
var mintAccount_1 = require("./parsers/mintAccount");
|
|
161
|
+
Object.defineProperty(exports, "decodeMintAccount", { enumerable: true, get: function () { return mintAccount_1.decodeMintAccount; } });
|
|
162
|
+
var events_1 = require("./parsers/events");
|
|
163
|
+
Object.defineProperty(exports, "parseCubicPoolEvents", { enumerable: true, get: function () { return events_1.parseCubicPoolEvents; } });
|
|
164
|
+
var borsh_1 = require("./parsers/borsh");
|
|
165
|
+
Object.defineProperty(exports, "BorshReader", { enumerable: true, get: function () { return borsh_1.BorshReader; } });
|
|
166
|
+
var contract_instructions_1 = require("./clients/contract-instructions");
|
|
167
|
+
Object.defineProperty(exports, "buildContractInstruction", { enumerable: true, get: function () { return contract_instructions_1.buildContractInstruction; } });
|
|
168
|
+
var contracts_1 = require("./parsers/contracts");
|
|
169
|
+
Object.defineProperty(exports, "decodeContractAccount", { enumerable: true, get: function () { return contracts_1.decodeContractAccount; } });
|
|
170
|
+
Object.defineProperty(exports, "decodeContractEvent", { enumerable: true, get: function () { return contracts_1.decodeContractEvent; } });
|
|
171
|
+
Object.defineProperty(exports, "parseContractEvents", { enumerable: true, get: function () { return contracts_1.parseContractEvents; } });
|
|
172
|
+
var tx_builders_2 = require("./clients/tx-builders");
|
|
173
|
+
Object.defineProperty(exports, "buildSetSwapFeeRateIx", { enumerable: true, get: function () { return tx_builders_2.buildSetSwapFeeRateIx; } });
|
|
174
|
+
Object.defineProperty(exports, "buildSetMaxSelloffIx", { enumerable: true, get: function () { return tx_builders_2.buildSetMaxSelloffIx; } });
|
|
175
|
+
Object.defineProperty(exports, "buildInitiatePoolAdminTransferIx", { enumerable: true, get: function () { return tx_builders_2.buildInitiatePoolAdminTransferIx; } });
|
|
176
|
+
Object.defineProperty(exports, "buildAcceptPoolAdminTransferIx", { enumerable: true, get: function () { return tx_builders_2.buildAcceptPoolAdminTransferIx; } });
|
|
177
|
+
Object.defineProperty(exports, "buildCancelPoolAdminTransferIx", { enumerable: true, get: function () { return tx_builders_2.buildCancelPoolAdminTransferIx; } });
|
|
178
|
+
Object.defineProperty(exports, "buildDisablePoolAdminIx", { enumerable: true, get: function () { return tx_builders_2.buildDisablePoolAdminIx; } });
|
|
179
|
+
Object.defineProperty(exports, "buildGetPoolInfoIx", { enumerable: true, get: function () { return tx_builders_2.buildGetPoolInfoIx; } });
|
|
180
|
+
var slippage_2 = require("./math/slippage");
|
|
181
|
+
Object.defineProperty(exports, "calculateSwapFee", { enumerable: true, get: function () { return slippage_2.calculateSwapFee; } });
|
|
182
|
+
Object.defineProperty(exports, "calculateProtocolFee", { enumerable: true, get: function () { return slippage_2.calculateProtocolFee; } });
|
|
183
|
+
var maxSelloff_2 = require("./math/maxSelloff");
|
|
184
|
+
Object.defineProperty(exports, "checkAndAdvanceSelloff", { enumerable: true, get: function () { return maxSelloff_2.checkAndAdvanceSelloff; } });
|
|
185
|
+
Object.defineProperty(exports, "rescaleSelloffWindow", { enumerable: true, get: function () { return maxSelloff_2.rescaleSelloffWindow; } });
|
|
186
|
+
var weightedMath_2 = require("./math/weightedMath");
|
|
187
|
+
Object.defineProperty(exports, "calculateInvariant", { enumerable: true, get: function () { return weightedMath_2.calculateInvariant; } });
|
|
188
|
+
var extensions_1 = require("./utils/extensions");
|
|
189
|
+
Object.defineProperty(exports, "MintExtension", { enumerable: true, get: function () { return extensions_1.MintExtension; } });
|
|
190
|
+
Object.defineProperty(exports, "MAX_KNOWN_MINT_EXTENSION", { enumerable: true, get: function () { return extensions_1.MAX_KNOWN_MINT_EXTENSION; } });
|
|
191
|
+
Object.defineProperty(exports, "HARD_UNSUPPORTED_MINT_EXTENSIONS", { enumerable: true, get: function () { return extensions_1.HARD_UNSUPPORTED_MINT_EXTENSIONS; } });
|
|
192
|
+
Object.defineProperty(exports, "DEFAULT_BANNED_EXTENSIONS", { enumerable: true, get: function () { return extensions_1.DEFAULT_BANNED_EXTENSIONS; } });
|
|
193
|
+
Object.defineProperty(exports, "mintExtensionName", { enumerable: true, get: function () { return extensions_1.mintExtensionName; } });
|
|
194
|
+
Object.defineProperty(exports, "parseMintExtensions", { enumerable: true, get: function () { return extensions_1.parseMintExtensions; } });
|
|
195
|
+
Object.defineProperty(exports, "unsupportedMintExtensions", { enumerable: true, get: function () { return extensions_1.unsupportedMintExtensions; } });
|
|
196
|
+
Object.defineProperty(exports, "bannedMintExtensions", { enumerable: true, get: function () { return extensions_1.bannedMintExtensions; } });
|
|
197
|
+
Object.defineProperty(exports, "describeUnsupportedToken", { enumerable: true, get: function () { return extensions_1.describeUnsupportedToken; } });
|
|
198
|
+
Object.defineProperty(exports, "assertTokensSupported", { enumerable: true, get: function () { return extensions_1.assertTokensSupported; } });
|
|
199
|
+
// ── Legacy aliases (pre-rebrand identifiers) ────────────────────────────
|
|
200
|
+
// The package was renamed @cubee_ee/sdk → @coffer_so/sdk. These aliases
|
|
201
|
+
// keep old import names compiling so migration is just a package-name
|
|
202
|
+
// swap. New code should use the Coffer* names.
|
|
203
|
+
/** @deprecated Use `CofferBackendClient`. */
|
|
204
|
+
var CofferBackendClient_2 = require("./clients/CofferBackendClient");
|
|
205
|
+
Object.defineProperty(exports, "CubeBackendClient", { enumerable: true, get: function () { return CofferBackendClient_2.CofferBackendClient; } });
|
|
206
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,+BAA+B;AAC/B,iDAAiD;AACjD,sCAAsC;;;;;;;;;;;;;;;;;;;AAEtC;;;;;;;;;;;;;GAaG;AAEH,2CAAyB;AACzB,0CAAwB;AACxB,0CAAwB;AACxB,yCAAuB;AACvB,4CAA0B;AAC1B,4CAA0B;AAC1B,wCAAsB;AAEtB,+EAA+E;AAC/E,yEAAyE;AACzE,mCAqBkB;AApBhB,mGAAA,SAAS,OAAA;AACT,mGAAA,SAAS,OAAA;AACT,yGAAA,eAAe,OAAA;AACf,uGAAA,aAAa,OAAA;AACb,0GAAA,gBAAgB,OAAA;AAChB,uGAAA,aAAa,OAAA;AACb,sGAAA,YAAY,OAAA;AACZ,oGAAA,UAAU,OAAA;AACV,oGAAA,UAAU,OAAA;AACV,oGAAA,UAAU,OAAA;AACV,oGAAA,UAAU,OAAA;AACV,sGAAA,YAAY,OAAA;AACZ,4GAAA,kBAAkB,OAAA;AAClB,gHAAA,sBAAsB,OAAA;AACtB,uGAAA,aAAa,OAAA;AACb,2GAAA,iBAAiB,OAAA;AACjB,+GAAA,qBAAqB,OAAA;AACrB,6GAAA,mBAAmB,OAAA;AACnB,4GAAA,kBAAkB,OAAA;AAClB,2GAAA,iBAAiB,OAAA;AAEnB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BAAqB,OAAA;AAAE,gHAAA,mBAAmB,OAAA;AAAE,gHAAA,mBAAmB,OAAA;AAIxE,qDAAmO;AAA1N,oHAAA,qBAAqB,OAAA;AAAE,mHAAA,oBAAoB,OAAA;AAAE,+HAAA,gCAAgC,OAAA;AAAE,6HAAA,8BAA8B,OAAA;AAAE,6HAAA,8BAA8B,OAAA;AAAE,sHAAA,uBAAuB,OAAA;AAAE,iHAAA,kBAAkB,OAAA;AAEnM,4CAAyE;AAAhE,4GAAA,gBAAgB,OAAA;AAAE,gHAAA,oBAAoB,OAAA;AAC/C,gDAAiF;AAAxE,oHAAA,sBAAsB,OAAA;AAAE,kHAAA,oBAAoB,OAAA;AAGrD,oDAAyD;AAAhD,kHAAA,kBAAkB,OAAA;AAE3B,iDAAoR;AAA3Q,2GAAA,aAAa,OAAA;AAAE,sHAAA,wBAAwB,OAAA;AAAE,8HAAA,gCAAgC,OAAA;AAAE,uHAAA,yBAAyB,OAAA;AAAE,+GAAA,iBAAiB,OAAA;AAAE,iHAAA,mBAAmB,OAAA;AAAE,uHAAA,yBAAyB,OAAA;AAAE,kHAAA,oBAAoB,OAAA;AAAE,sHAAA,wBAAwB,OAAA;AAAE,mHAAA,qBAAqB,OAAA;AAEvP,2EAA2E;AAC3E,wEAAwE;AACxE,sEAAsE;AACtE,+CAA+C;AAC/C,6CAA6C;AAC7C,qEAAyF;AAAhF,wHAAA,mBAAmB,OAAqB"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Port of `CubicMath::calc_out_given_in` from
|
|
3
|
+
* `contracts/programs/cubic-pool/src/math/cubic_math.rs`.
|
|
4
|
+
*
|
|
5
|
+
* Formula: aO = bO * (1 - (bI / (bI + aI))^(wI / wO))
|
|
6
|
+
*
|
|
7
|
+
* Inputs are u64 raw amounts (bigint here to avoid overflow). Decimals
|
|
8
|
+
* cancel in the ratio bI/(bI+aI), so no scaling needed.
|
|
9
|
+
*/
|
|
10
|
+
export declare function calcOutGivenIn(params: {
|
|
11
|
+
virtualBalanceIn: bigint;
|
|
12
|
+
weightInBps: bigint;
|
|
13
|
+
virtualBalanceOut: bigint;
|
|
14
|
+
weightOutBps: bigint;
|
|
15
|
+
amountIn: bigint;
|
|
16
|
+
actualBalanceOut: bigint;
|
|
17
|
+
}): bigint;
|
|
18
|
+
/**
|
|
19
|
+
* Port of `CubicMath::calc_bpt_out_given_exact_tokens_in`.
|
|
20
|
+
* Proportional join: `bpt = total_supply * min(amount_i / actual_balance_i)`
|
|
21
|
+
* across tokens with `actual_balance_i > 0`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function calcBptOutGivenExactTokensIn(actualBalances: bigint[], amountsIn: bigint[], bptTotalSupply: bigint): bigint;
|
|
24
|
+
/**
|
|
25
|
+
* Port of `CubicMath::calc_tokens_out_given_bpt_in`. Proportional exit.
|
|
26
|
+
*/
|
|
27
|
+
export declare function calcTokensOutGivenBptIn(actualBalances: bigint[], bptAmount: bigint, bptTotalSupply: bigint): bigint[];
|
|
28
|
+
/**
|
|
29
|
+
* Spot amount-out: aO = aI * (bO * wI) / (bI * wO). Always ≥
|
|
30
|
+
* `calcOutGivenIn` for the same inputs (curve slippage drags the real
|
|
31
|
+
* value below spot). Useful for UI "price impact" calculations.
|
|
32
|
+
*/
|
|
33
|
+
export declare function calcSpotOut(params: {
|
|
34
|
+
virtualBalanceIn: bigint;
|
|
35
|
+
weightInBps: bigint;
|
|
36
|
+
virtualBalanceOut: bigint;
|
|
37
|
+
weightOutBps: bigint;
|
|
38
|
+
amountIn: bigint;
|
|
39
|
+
}): bigint;
|
|
40
|
+
//# sourceMappingURL=cubicMath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cubicMath.d.ts","sourceRoot":"","sources":["../../src/math/cubicMath.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE;IACrC,gBAAgB,EAAE,MAAM,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,GAAG,MAAM,CAiBT;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,cAAc,EAAE,MAAM,EAAE,EACxB,SAAS,EAAE,MAAM,EAAE,EACnB,cAAc,EAAE,MAAM,GACrB,MAAM,CAaR;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,cAAc,EAAE,MAAM,EAAE,EACxB,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,GACrB,MAAM,EAAE,CAKV;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE;IAClC,gBAAgB,EAAE,MAAM,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,MAAM,CAIT"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calcOutGivenIn = calcOutGivenIn;
|
|
4
|
+
exports.calcBptOutGivenExactTokensIn = calcBptOutGivenExactTokensIn;
|
|
5
|
+
exports.calcTokensOutGivenBptIn = calcTokensOutGivenBptIn;
|
|
6
|
+
exports.calcSpotOut = calcSpotOut;
|
|
7
|
+
const fixedPoint_1 = require("./fixedPoint");
|
|
8
|
+
const logExp_1 = require("./logExp");
|
|
9
|
+
/**
|
|
10
|
+
* Port of `CubicMath::calc_out_given_in` from
|
|
11
|
+
* `contracts/programs/cubic-pool/src/math/cubic_math.rs`.
|
|
12
|
+
*
|
|
13
|
+
* Formula: aO = bO * (1 - (bI / (bI + aI))^(wI / wO))
|
|
14
|
+
*
|
|
15
|
+
* Inputs are u64 raw amounts (bigint here to avoid overflow). Decimals
|
|
16
|
+
* cancel in the ratio bI/(bI+aI), so no scaling needed.
|
|
17
|
+
*/
|
|
18
|
+
function calcOutGivenIn(params) {
|
|
19
|
+
const { virtualBalanceIn, weightInBps, virtualBalanceOut, weightOutBps, amountIn, actualBalanceOut } = params;
|
|
20
|
+
[virtualBalanceIn, weightInBps, virtualBalanceOut, weightOutBps, amountIn, actualBalanceOut].forEach((v) => (0, fixedPoint_1.assertU64)(v));
|
|
21
|
+
const denom = (0, fixedPoint_1.assertU128)(virtualBalanceIn + amountIn);
|
|
22
|
+
const base = (0, fixedPoint_1.divUp)(virtualBalanceIn, denom);
|
|
23
|
+
const exp = (0, fixedPoint_1.divDown)((0, fixedPoint_1.weightToFp)(weightInBps), (0, fixedPoint_1.weightToFp)(weightOutBps));
|
|
24
|
+
let power = (0, logExp_1.powFp)(base, exp);
|
|
25
|
+
// Match Rust's +1 bias + clamp to ONE.
|
|
26
|
+
power = power + 1n;
|
|
27
|
+
if (power > fixedPoint_1.ONE)
|
|
28
|
+
power = fixedPoint_1.ONE;
|
|
29
|
+
const comp = (0, fixedPoint_1.complement)(power);
|
|
30
|
+
const out = (0, fixedPoint_1.mulDown)(virtualBalanceOut, comp);
|
|
31
|
+
if (out > actualBalanceOut) {
|
|
32
|
+
throw new Error("cubicMath: amount out exceeds actual balance");
|
|
33
|
+
}
|
|
34
|
+
return (0, fixedPoint_1.assertU64)(out);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Port of `CubicMath::calc_bpt_out_given_exact_tokens_in`.
|
|
38
|
+
* Proportional join: `bpt = total_supply * min(amount_i / actual_balance_i)`
|
|
39
|
+
* across tokens with `actual_balance_i > 0`.
|
|
40
|
+
*/
|
|
41
|
+
function calcBptOutGivenExactTokensIn(actualBalances, amountsIn, bptTotalSupply) {
|
|
42
|
+
if (actualBalances.length !== amountsIn.length) {
|
|
43
|
+
throw new Error("cubicMath: balances/amounts length mismatch");
|
|
44
|
+
}
|
|
45
|
+
(0, fixedPoint_1.assertU64)(bptTotalSupply);
|
|
46
|
+
actualBalances.forEach((v) => (0, fixedPoint_1.assertU64)(v));
|
|
47
|
+
amountsIn.forEach((v) => (0, fixedPoint_1.assertU64)(v));
|
|
48
|
+
let ratioMin = null;
|
|
49
|
+
for (let i = 0; i < actualBalances.length; i++) {
|
|
50
|
+
if (actualBalances[i] === 0n)
|
|
51
|
+
continue;
|
|
52
|
+
const ratio = (0, fixedPoint_1.divDown)(amountsIn[i], actualBalances[i]);
|
|
53
|
+
ratioMin = ratioMin === null || ratio < ratioMin ? ratio : ratioMin;
|
|
54
|
+
}
|
|
55
|
+
if (ratioMin === null)
|
|
56
|
+
throw new Error("cubicMath: no live tokens");
|
|
57
|
+
return (0, fixedPoint_1.assertU64)((0, fixedPoint_1.assertU128)(bptTotalSupply * ratioMin) / fixedPoint_1.ONE);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Port of `CubicMath::calc_tokens_out_given_bpt_in`. Proportional exit.
|
|
61
|
+
*/
|
|
62
|
+
function calcTokensOutGivenBptIn(actualBalances, bptAmount, bptTotalSupply) {
|
|
63
|
+
(0, fixedPoint_1.assertU64)(bptAmount);
|
|
64
|
+
(0, fixedPoint_1.assertU64)(bptTotalSupply);
|
|
65
|
+
actualBalances.forEach((v) => (0, fixedPoint_1.assertU64)(v));
|
|
66
|
+
if (bptTotalSupply === 0n)
|
|
67
|
+
throw new Error("cubicMath: zero total supply");
|
|
68
|
+
const ratio = (0, fixedPoint_1.divDown)(bptAmount, bptTotalSupply);
|
|
69
|
+
return actualBalances.map((bal) => (0, fixedPoint_1.assertU64)((0, fixedPoint_1.mulDown)(bal, ratio)));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Spot amount-out: aO = aI * (bO * wI) / (bI * wO). Always ≥
|
|
73
|
+
* `calcOutGivenIn` for the same inputs (curve slippage drags the real
|
|
74
|
+
* value below spot). Useful for UI "price impact" calculations.
|
|
75
|
+
*/
|
|
76
|
+
function calcSpotOut(params) {
|
|
77
|
+
const { virtualBalanceIn, weightInBps, virtualBalanceOut, weightOutBps, amountIn } = params;
|
|
78
|
+
if (virtualBalanceIn === 0n || weightOutBps === 0n)
|
|
79
|
+
return 0n;
|
|
80
|
+
return (amountIn * virtualBalanceOut * weightInBps) / (virtualBalanceIn * weightOutBps);
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=cubicMath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cubicMath.js","sourceRoot":"","sources":["../../src/math/cubicMath.ts"],"names":[],"mappings":";;AAYA,wCAwBC;AAOD,oEAiBC;AAKD,0DASC;AAOD,kCAUC;AA3FD,6CAA2G;AAC3G,qCAAiC;AAEjC;;;;;;;;GAQG;AACH,SAAgB,cAAc,CAAC,MAO9B;IACC,MAAM,EAAE,gBAAgB,EAAE,WAAW,EAAE,iBAAiB,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB,EAAE,GAClG,MAAM,CAAC;IACT,CAAC,gBAAgB,EAAE,WAAW,EAAE,iBAAiB,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,sBAAS,EAAC,CAAC,CAAC,CAAC,CAAC;IAC1H,MAAM,KAAK,GAAG,IAAA,uBAAU,EAAC,gBAAgB,GAAG,QAAQ,CAAC,CAAC;IACtD,MAAM,IAAI,GAAG,IAAA,kBAAK,EAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;IAC5C,MAAM,GAAG,GAAG,IAAA,oBAAO,EAAC,IAAA,uBAAU,EAAC,WAAW,CAAC,EAAE,IAAA,uBAAU,EAAC,YAAY,CAAC,CAAC,CAAC;IACvE,IAAI,KAAK,GAAG,IAAA,cAAK,EAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC7B,uCAAuC;IACvC,KAAK,GAAG,KAAK,GAAG,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ool's checked u128 operations. */
|
|
2
|
+
export declare const ONE = 1000000000000000000n;
|
|
3
|
+
export declare const U64_MAX: bigint;
|
|
4
|
+
export declare const U128_MAX: bigint;
|
|
5
|
+
export declare const I128_MIN: bigint;
|
|
6
|
+
export declare const I128_MAX: bigint;
|
|
7
|
+
export declare function assertU64(value: bigint, label?: string): bigint;
|
|
8
|
+
export declare function assertU128(value: bigint, label?: string): bigint;
|
|
9
|
+
export declare function assertI128(value: bigint, label?: string): bigint;
|
|
10
|
+
export declare function assertInteger(value: number, min: number, max: number, label: string): number;
|
|
11
|
+
/** Rust mul_div_down permits a 256-bit product, but a u128 quotient. */
|
|
12
|
+
export declare function mulDivDown(a: bigint, b: bigint, denominator: bigint): bigint;
|
|
13
|
+
export declare function mulDown(a: bigint, b: bigint): bigint;
|
|
14
|
+
export declare function mulUp(a: bigint, b: bigint): bigint;
|
|
15
|
+
export declare function divDown(a: bigint, b: bigint): bigint;
|
|
16
|
+
export declare function divUp(a: bigint, b: bigint): bigint;
|
|
17
|
+
export declare function complement(x: bigint): bigint;
|
|
18
|
+
export declare function weightToFp(weightBps: bigint | number): bigint;
|
|
19
|
+
//# sourceMappingURL=fixedPoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixedPoint.d.ts","sourceRoot":"","sources":["../../src/math/fixedPoint.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,eAAO,MAAM,GAAG,uBAAuB,CAAC;AACxC,eAAO,MAAM,OAAO,QAAmB,CAAC;AACxC,eAAO,MAAM,QAAQ,QAAoB,CAAC;AAC1C,eAAO,MAAM,QAAQ,QAAgB,CAAC;AACtC,eAAO,MAAM,QAAQ,QAAoB,CAAC;AAC1C,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,SAAU,GAAG,MAAM,CAIhE;AACD,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,SAAU,GAAG,MAAM,CAIjE;AACD,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,SAAU,GAAG,MAAM,CAIjE;AACD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAI5F;AACD,wEAAwE;AACxE,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAO5E;AACD,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAIpD;AACD,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAKlD;AACD,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAMpD;AACD,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAOlD;AACD,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAK5C;AACD,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAG7D"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.I128_MAX = exports.I128_MIN = exports.U128_MAX = exports.U64_MAX = exports.ONE = void 0;
|
|
4
|
+
exports.assertU64 = assertU64;
|
|
5
|
+
exports.assertU128 = assertU128;
|
|
6
|
+
exports.assertI128 = assertI128;
|
|
7
|
+
exports.assertInteger = assertInteger;
|
|
8
|
+
exports.mulDivDown = mulDivDown;
|
|
9
|
+
exports.mulDown = mulDown;
|
|
10
|
+
exports.mulUp = mulUp;
|
|
11
|
+
exports.divDown = divDown;
|
|
12
|
+
exports.divUp = divUp;
|
|
13
|
+
exports.complement = complement;
|
|
14
|
+
exports.weightToFp = weightToFp;
|
|
15
|
+
/** Fixed-point primitives matching cubic-pool's checked u128 operations. */
|
|
16
|
+
exports.ONE = 1000000000000000000n;
|
|
17
|
+
exports.U64_MAX = (1n << 64n) - 1n;
|
|
18
|
+
exports.U128_MAX = (1n << 128n) - 1n;
|
|
19
|
+
exports.I128_MIN = -(1n << 127n);
|
|
20
|
+
exports.I128_MAX = (1n << 127n) - 1n;
|
|
21
|
+
function assertU64(value, label = "value") {
|
|
22
|
+
if (value < 0n || value > exports.U64_MAX)
|
|
23
|
+
throw new Error(`${label}: outside u64`);
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
function assertU128(value, label = "value") {
|
|
27
|
+
if (value < 0n || value > exports.U128_MAX)
|
|
28
|
+
throw new Error(`${label}: outside u128`);
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
function assertI128(value, label = "value") {
|
|
32
|
+
if (value < exports.I128_MIN || value > exports.I128_MAX)
|
|
33
|
+
throw new Error(`${label}: outside i128`);
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
function assertInteger(value, min, max, label) {
|
|
37
|
+
if (!Number.isSafeInteger(value) || value < min || value > max)
|
|
38
|
+
throw new Error(`${label}: invalid integer`);
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
/** Rust mul_div_down permits a 256-bit product, but a u128 quotient. */
|
|
42
|
+
function mulDivDown(a, b, denominator) {
|
|
43
|
+
assertU128(a);
|
|
44
|
+
assertU128(b);
|
|
45
|
+
assertU128(denominator);
|
|
46
|
+
if (denominator === 0n)
|
|
47
|
+
throw new Error("mulDivDown: divide by zero");
|
|
48
|
+
return assertU128(a * b / denominator);
|
|
49
|
+
}
|
|
50
|
+
function mulDown(a, b) {
|
|
51
|
+
assertU128(a);
|
|
52
|
+
assertU128(b);
|
|
53
|
+
return assertU128(a * b) / exports.ONE;
|
|
54
|
+
}
|
|
55
|
+
function mulUp(a, b) {
|
|
56
|
+
assertU128(a);
|
|
57
|
+
assertU128(b);
|
|
58
|
+
const product = assertU128(a * b);
|
|
59
|
+
return product === 0n ? 0n : (product - 1n) / exports.ONE + 1n;
|
|
60
|
+
}
|
|
61
|
+
function divDown(a, b) {
|
|
62
|
+
assertU128(a);
|
|
63
|
+
assertU128(b);
|
|
64
|
+
if (b === 0n)
|
|
65
|
+
throw new Error("fixedPoint.divDown: divide by zero");
|
|
66
|
+
return assertU128(a * exports.ONE) / b;
|
|
67
|
+
}
|
|
68
|
+
function divUp(a, b) {
|
|
69
|
+
assertU128(a);
|
|
70
|
+
assertU128(b);
|
|
71
|
+
if (b === 0n)
|
|
72
|
+
throw new Error("fixedPoint.divUp: divide by zero");
|
|
73
|
+
const numerator = assertU128(a * exports.ONE);
|
|
74
|
+
return numerator === 0n ? 0n : (numerator - 1n) / b + 1n;
|
|
75
|
+
}
|
|
76
|
+
function complement(x) {
|
|
77
|
+
assertU128(x);
|
|
78
|
+
if (x > exports.ONE)
|
|
79
|
+
throw new Error("fixedPoint.complement: greater than ONE");
|
|
80
|
+
return exports.ONE - x;
|
|
81
|
+
}
|
|
82
|
+
function weightToFp(weightBps) {
|
|
83
|
+
const w = typeof weightBps === "number" ? BigInt(assertInteger(weightBps, 0, 10000, "weight")) : assertU64(weightBps);
|
|
84
|
+
return w * exports.ONE / 10000n;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=fixedPoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixedPoint.js","sourceRoot":"","sources":["../../src/math/fixedPoint.ts"],"names":[],"mappings":";;;AAMA,8BAIC;AACD,gCAIC;AACD,gCAIC;AACD,sCAIC;AAED,gCAOC;AACD,0BAIC;AACD,sBAKC;AACD,0BAMC;AACD,sBAOC;AACD,gCAKC;AACD,gCAGC;AAtED,4EAA4E;AAC/D,QAAA,GAAG,GAAG,oBAAoB,CAAC;AAC3B,QAA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K,CAAC,kCAAkC,CAAC,CAAC;IACxD,MAAM,SAAS,GAAG,UAAU,CAAC,CAAC,GAAG,WAAG,CAAC,CAAC;IACtC,OAAO,SAAS,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;AAC7D,CAAC;AACD,SAAgB,UAAU,CAAC,CAAS;IAChC,UAAU,CAAC,CAAC,CAAC,CAAC;IACd,IAAI,CAAC,GAAG,WAAG;QACP,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC/D,OAAO,WAAG,GAAG,CAAC,CAAC;AACnB,CAAC;AACD,SAAgB,UAAU,CAAC,SAA0B;IACjD,MAAM,CAAC,GAAG,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IACtH,OAAO,CAAC,GAAG,WAAG,GAAG,MAAM,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./fixedPoint";
|
|
2
|
+
export * from "./logExp";
|
|
3
|
+
export * from "./cubicMath";
|
|
4
|
+
export * from "./weightedMath";
|
|
5
|
+
export * from "./singleToken";
|
|
6
|
+
export * from "./slippage";
|
|
7
|
+
export * from "./maxSelloff";
|
|
8
|
+
export * from "./lpLoss";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/math/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC"}
|