@forgedevv/core 0.1.0 → 0.3.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/CHANGELOG.md +227 -4
- package/README.md +4 -3
- package/dist/addresses.d.ts +73 -7
- package/dist/addresses.js +96 -5
- package/dist/claims.d.ts +43 -6
- package/dist/claims.js +75 -16
- package/dist/config.d.ts +48 -37
- package/dist/config.js +282 -52
- package/dist/constants.d.ts +16 -0
- package/dist/constants.js +20 -0
- package/dist/index.d.ts +9 -5
- package/dist/index.js +15 -4
- package/dist/jupiter-referral.d.ts +334 -0
- package/dist/jupiter-referral.js +666 -0
- package/dist/launch-metadata.d.ts +5 -1
- package/dist/launch-metadata.js +2 -0
- package/dist/meteora-referral.d.ts +119 -0
- package/dist/meteora-referral.js +188 -0
- package/dist/payments.d.ts +17 -0
- package/dist/payments.js +20 -2
- package/dist/pool.d.ts +108 -17
- package/dist/pool.js +237 -60
- package/dist/position-claims.d.ts +215 -0
- package/dist/position-claims.js +457 -0
- package/dist/priority-fee.d.ts +202 -0
- package/dist/priority-fee.js +322 -0
- package/dist/reads.d.ts +20 -0
- package/dist/reads.js +39 -2
- package/dist/settings.d.ts +73 -0
- package/dist/settings.js +119 -0
- package/dist/swap.d.ts +95 -23
- package/dist/swap.js +144 -30
- package/dist/tx.d.ts +2 -0
- package/dist/tx.js +4 -2
- package/dist/validate.d.ts +14 -1
- package/dist/validate.js +86 -6
- package/package.json +3 -2
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fixed settings of every FORGE config (docs/METEORA.md, "Settings for the two configs").
|
|
3
|
+
*
|
|
4
|
+
* They live in their own module so that both the builders (config.ts) and the checks
|
|
5
|
+
* (validate.ts, the on-chain comparison in config.ts) read the same constants without an import
|
|
6
|
+
* cycle. `config.ts` re-exports them: they stay part of its public surface.
|
|
7
|
+
*/
|
|
8
|
+
import { ActivationType, BaseFeeMode, MigrationFeeOption, MigrationOption, TokenAuthorityOption, TokenDecimal, TokenType, type BaseFee } from '@meteora-ag/dynamic-bonding-curve-sdk';
|
|
9
|
+
import type BN from 'bn.js';
|
|
10
|
+
/** Token of every coin: SPL token, 1,000,000,000 tokens with 6 decimals, immutable metadata. */
|
|
11
|
+
export declare const FORGE_TOKEN_SETTINGS: {
|
|
12
|
+
readonly tokenType: TokenType.SPLToken;
|
|
13
|
+
readonly tokenBaseDecimal: TokenDecimal.SIX;
|
|
14
|
+
readonly tokenQuoteDecimal: 9;
|
|
15
|
+
readonly tokenAuthorityOption: TokenAuthorityOption.Immutable;
|
|
16
|
+
readonly totalTokenSupply: 1000000000;
|
|
17
|
+
readonly leftover: 0;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Anti-sniper fee schedule (`spec.antiSniper`): the fee starts at `startingFeeBps` and decreases
|
|
21
|
+
* linearly, in `numberOfPeriod` equal steps over `totalDurationSeconds`, to `spec.tradingFeeBps`.
|
|
22
|
+
* validate.ts requires exactly this schedule (or none when `spec.antiSniper` is off).
|
|
23
|
+
*/
|
|
24
|
+
export declare const ANTI_SNIPER_FEE_SCHEDULE: {
|
|
25
|
+
readonly baseFeeMode: BaseFeeMode.FeeSchedulerLinear;
|
|
26
|
+
readonly startingFeeBps: 9900;
|
|
27
|
+
readonly numberOfPeriod: 10;
|
|
28
|
+
readonly totalDurationSeconds: 60;
|
|
29
|
+
};
|
|
30
|
+
/** Migration: DAMM v2, migrated pool fee 0.25%, no migration fee, 20% of the supply migrated. */
|
|
31
|
+
export declare const FORGE_MIGRATION_SETTINGS: {
|
|
32
|
+
readonly migrationOption: MigrationOption.MET_DAMM_V2;
|
|
33
|
+
readonly migrationFeeOption: MigrationFeeOption.FixedBps25;
|
|
34
|
+
readonly migrationFee: {
|
|
35
|
+
readonly feePercentage: 0;
|
|
36
|
+
readonly creatorFeePercentage: 0;
|
|
37
|
+
};
|
|
38
|
+
readonly percentageSupplyOnMigration: 20;
|
|
39
|
+
};
|
|
40
|
+
/** Fee scheduler periods are counted in seconds. */
|
|
41
|
+
export declare const FORGE_ACTIVATION_TYPE = ActivationType.Timestamp;
|
|
42
|
+
/** Total supply of every coin in raw base units (1,000,000,000 tokens x 10^6). */
|
|
43
|
+
export declare const FORGE_TOKEN_SUPPLY_RAW: bigint;
|
|
44
|
+
/** The SDK `feeSchedulerParam` of a FORGE config (anti-sniper schedule, or a flat fee). */
|
|
45
|
+
export declare function forgeFeeSchedulerParam(tradingFeeBps: number, antiSniper: boolean): {
|
|
46
|
+
startingFeeBps: number;
|
|
47
|
+
endingFeeBps: number;
|
|
48
|
+
numberOfPeriod: number;
|
|
49
|
+
totalDuration: number;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* The base fee a FORGE config must carry for this trading fee and anti-sniper flag, computed by
|
|
53
|
+
* the SDK exactly as `buildCurve` does (cliff, number of periods, period, reduction factor, mode).
|
|
54
|
+
*
|
|
55
|
+
* @throws when the SDK refuses the fee (out of its bounds).
|
|
56
|
+
*/
|
|
57
|
+
export declare function forgeBaseFee(tradingFeeBps: number, antiSniper: boolean): BaseFee;
|
|
58
|
+
/** Start price and curve shared by every FORGE config (they only depend on the settings above). */
|
|
59
|
+
export interface ForgeReferenceCurve {
|
|
60
|
+
sqrtStartPrice: BN;
|
|
61
|
+
curve: readonly {
|
|
62
|
+
sqrtPrice: BN;
|
|
63
|
+
liquidity: BN;
|
|
64
|
+
}[];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The curve and start price of every FORGE config. They follow from the token settings, the
|
|
68
|
+
* migration settings and the 10 SOL threshold only (the SDK's `buildCurve` does not read the
|
|
69
|
+
* fees or the liquidity split for them), so one reference fits both configs of every launchpad.
|
|
70
|
+
* The curve decides how the supply is split between the swap, the migration and the leftover
|
|
71
|
+
* (sent to the leftover receiver): pinning it pins the leftover. Computed once, then cached.
|
|
72
|
+
*/
|
|
73
|
+
export declare function forgeReferenceCurve(): ForgeReferenceCurve;
|
package/dist/settings.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fixed settings of every FORGE config (docs/METEORA.md, "Settings for the two configs").
|
|
3
|
+
*
|
|
4
|
+
* They live in their own module so that both the builders (config.ts) and the checks
|
|
5
|
+
* (validate.ts, the on-chain comparison in config.ts) read the same constants without an import
|
|
6
|
+
* cycle. `config.ts` re-exports them: they stay part of its public surface.
|
|
7
|
+
*/
|
|
8
|
+
import { ActivationType, BaseFeeMode, CollectFeeMode, MigrationFeeOption, MigrationOption, TokenAuthorityOption, TokenDecimal, TokenType, buildCurve, getBaseFeeParams, } from '@meteora-ag/dynamic-bonding-curve-sdk';
|
|
9
|
+
import { CLIENT_BOUNDS, MAX_ANTI_SNIPER_STARTING_FEE_BPS, SOL_DECIMALS } from './constants.js';
|
|
10
|
+
/** Token of every coin: SPL token, 1,000,000,000 tokens with 6 decimals, immutable metadata. */
|
|
11
|
+
export const FORGE_TOKEN_SETTINGS = {
|
|
12
|
+
tokenType: TokenType.SPLToken,
|
|
13
|
+
tokenBaseDecimal: TokenDecimal.SIX,
|
|
14
|
+
tokenQuoteDecimal: SOL_DECIMALS,
|
|
15
|
+
tokenAuthorityOption: TokenAuthorityOption.Immutable,
|
|
16
|
+
totalTokenSupply: 1_000_000_000,
|
|
17
|
+
leftover: 0,
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Anti-sniper fee schedule (`spec.antiSniper`): the fee starts at `startingFeeBps` and decreases
|
|
21
|
+
* linearly, in `numberOfPeriod` equal steps over `totalDurationSeconds`, to `spec.tradingFeeBps`.
|
|
22
|
+
* validate.ts requires exactly this schedule (or none when `spec.antiSniper` is off).
|
|
23
|
+
*/
|
|
24
|
+
export const ANTI_SNIPER_FEE_SCHEDULE = {
|
|
25
|
+
baseFeeMode: BaseFeeMode.FeeSchedulerLinear,
|
|
26
|
+
startingFeeBps: MAX_ANTI_SNIPER_STARTING_FEE_BPS,
|
|
27
|
+
numberOfPeriod: 10,
|
|
28
|
+
totalDurationSeconds: 60,
|
|
29
|
+
};
|
|
30
|
+
/** Migration: DAMM v2, migrated pool fee 0.25%, no migration fee, 20% of the supply migrated. */
|
|
31
|
+
export const FORGE_MIGRATION_SETTINGS = {
|
|
32
|
+
migrationOption: MigrationOption.MET_DAMM_V2,
|
|
33
|
+
migrationFeeOption: MigrationFeeOption.FixedBps25,
|
|
34
|
+
migrationFee: { feePercentage: 0, creatorFeePercentage: 0 },
|
|
35
|
+
percentageSupplyOnMigration: 20,
|
|
36
|
+
};
|
|
37
|
+
/** Fee scheduler periods are counted in seconds. */
|
|
38
|
+
export const FORGE_ACTIVATION_TYPE = ActivationType.Timestamp;
|
|
39
|
+
/** Total supply of every coin in raw base units (1,000,000,000 tokens x 10^6). */
|
|
40
|
+
export const FORGE_TOKEN_SUPPLY_RAW = BigInt(FORGE_TOKEN_SETTINGS.totalTokenSupply) *
|
|
41
|
+
10n ** BigInt(FORGE_TOKEN_SETTINGS.tokenBaseDecimal);
|
|
42
|
+
/** The SDK `feeSchedulerParam` of a FORGE config (anti-sniper schedule, or a flat fee). */
|
|
43
|
+
export function forgeFeeSchedulerParam(tradingFeeBps, antiSniper) {
|
|
44
|
+
const schedule = ANTI_SNIPER_FEE_SCHEDULE;
|
|
45
|
+
return antiSniper
|
|
46
|
+
? {
|
|
47
|
+
startingFeeBps: schedule.startingFeeBps,
|
|
48
|
+
endingFeeBps: tradingFeeBps,
|
|
49
|
+
numberOfPeriod: schedule.numberOfPeriod,
|
|
50
|
+
totalDuration: schedule.totalDurationSeconds,
|
|
51
|
+
}
|
|
52
|
+
: {
|
|
53
|
+
startingFeeBps: tradingFeeBps,
|
|
54
|
+
endingFeeBps: tradingFeeBps,
|
|
55
|
+
numberOfPeriod: 0,
|
|
56
|
+
totalDuration: 0,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The base fee a FORGE config must carry for this trading fee and anti-sniper flag, computed by
|
|
61
|
+
* the SDK exactly as `buildCurve` does (cliff, number of periods, period, reduction factor, mode).
|
|
62
|
+
*
|
|
63
|
+
* @throws when the SDK refuses the fee (out of its bounds).
|
|
64
|
+
*/
|
|
65
|
+
export function forgeBaseFee(tradingFeeBps, antiSniper) {
|
|
66
|
+
return getBaseFeeParams({
|
|
67
|
+
baseFeeMode: ANTI_SNIPER_FEE_SCHEDULE.baseFeeMode,
|
|
68
|
+
feeSchedulerParam: forgeFeeSchedulerParam(tradingFeeBps, antiSniper),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
let referenceCurve = null;
|
|
72
|
+
/**
|
|
73
|
+
* The curve and start price of every FORGE config. They follow from the token settings, the
|
|
74
|
+
* migration settings and the 10 SOL threshold only (the SDK's `buildCurve` does not read the
|
|
75
|
+
* fees or the liquidity split for them), so one reference fits both configs of every launchpad.
|
|
76
|
+
* The curve decides how the supply is split between the swap, the migration and the leftover
|
|
77
|
+
* (sent to the leftover receiver): pinning it pins the leftover. Computed once, then cached.
|
|
78
|
+
*/
|
|
79
|
+
export function forgeReferenceCurve() {
|
|
80
|
+
if (referenceCurve)
|
|
81
|
+
return referenceCurve;
|
|
82
|
+
const built = buildCurve({
|
|
83
|
+
token: { ...FORGE_TOKEN_SETTINGS },
|
|
84
|
+
fee: {
|
|
85
|
+
baseFeeParams: {
|
|
86
|
+
baseFeeMode: ANTI_SNIPER_FEE_SCHEDULE.baseFeeMode,
|
|
87
|
+
feeSchedulerParam: forgeFeeSchedulerParam(CLIENT_BOUNDS.tradingFeeBps.min, false),
|
|
88
|
+
},
|
|
89
|
+
dynamicFeeEnabled: false,
|
|
90
|
+
collectFeeMode: CollectFeeMode.QuoteToken,
|
|
91
|
+
creatorTradingFeePercentage: 0,
|
|
92
|
+
poolCreationFee: 0,
|
|
93
|
+
enableFirstSwapWithMinFee: true,
|
|
94
|
+
},
|
|
95
|
+
migration: {
|
|
96
|
+
migrationOption: FORGE_MIGRATION_SETTINGS.migrationOption,
|
|
97
|
+
migrationFeeOption: FORGE_MIGRATION_SETTINGS.migrationFeeOption,
|
|
98
|
+
migrationFee: { ...FORGE_MIGRATION_SETTINGS.migrationFee },
|
|
99
|
+
},
|
|
100
|
+
liquidityDistribution: {
|
|
101
|
+
partnerPermanentLockedLiquidityPercentage: 100,
|
|
102
|
+
partnerLiquidityPercentage: 0,
|
|
103
|
+
creatorPermanentLockedLiquidityPercentage: 0,
|
|
104
|
+
creatorLiquidityPercentage: 0,
|
|
105
|
+
},
|
|
106
|
+
lockedVesting: {
|
|
107
|
+
totalLockedVestingAmount: 0,
|
|
108
|
+
numberOfVestingPeriod: 0,
|
|
109
|
+
cliffUnlockAmount: 0,
|
|
110
|
+
totalVestingDuration: 0,
|
|
111
|
+
cliffDurationFromMigrationTime: 0,
|
|
112
|
+
},
|
|
113
|
+
activationType: FORGE_ACTIVATION_TYPE,
|
|
114
|
+
percentageSupplyOnMigration: FORGE_MIGRATION_SETTINGS.percentageSupplyOnMigration,
|
|
115
|
+
migrationQuoteThreshold: CLIENT_BOUNDS.migrationThresholdSol,
|
|
116
|
+
});
|
|
117
|
+
referenceCurve = { sqrtStartPrice: built.sqrtStartPrice, curve: built.curve };
|
|
118
|
+
return referenceCurve;
|
|
119
|
+
}
|
package/dist/swap.d.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* One transaction contains, in this order:
|
|
6
6
|
*
|
|
7
7
|
* 1. compute budget: `setComputeUnitLimit`, then `setComputeUnitPrice` (only when a priority fee
|
|
8
|
-
* is given
|
|
8
|
+
* is given: a fixed `priorityFeeMicroLamports`, or a `priority` setting whose price is read
|
|
9
|
+
* from the recent fees of the swap's writable accounts and bounded, see priority-fee.ts);
|
|
9
10
|
* 2. token accounts: the user's wrapped SOL ATA is always created (idempotent) and, on a buy, the
|
|
10
11
|
* user's coin ATA when it does not exist yet;
|
|
11
12
|
* 3. buy only: SOL transfer of `amountInLamports` into the wrapped SOL ATA + `SyncNative` (wrap);
|
|
@@ -27,19 +28,26 @@
|
|
|
27
28
|
* Refusals (typed `SwapError`, never a silent fallback):
|
|
28
29
|
* - the pool is migrated or its curve is complete (`POOL_GRADUATED`): the template trades through
|
|
29
30
|
* Jupiter in that case;
|
|
31
|
+
* - the pool's config is not in the caller's `allowedConfigs` (`POOL_NOT_ALLOWED`): a launchpad
|
|
32
|
+
* site only trades its own coins;
|
|
30
33
|
* - the platform fee wallet does not exist or is not rent-exempt
|
|
31
34
|
* (`PLATFORM_FEE_WALLET_NOT_RENT_EXEMPT`): the whole swap would fail on-chain (devnet finding);
|
|
32
|
-
* - the
|
|
35
|
+
* - the platform fee wallet is not exactly `FORGE_PLATFORM_FEE_WALLET`, or not a system account,
|
|
36
|
+
* or `FORGE_PLATFORM_FEE_WALLET` is not the revenue wallet when the environment has
|
|
37
|
+
* `FORGE_REVENUE_WALLET` (`PLATFORM_FEE_WALLET_MISMATCH`);
|
|
38
|
+
* - the referral account is not an initialized wrapped SOL token account, or is not held by
|
|
39
|
+
* `FORGE_REVENUE_WALLET` when the environment has it (`REFERRAL_ACCOUNT_INVALID`);
|
|
33
40
|
* - the pool is not a plain SOL-quoted DBC pool (`UNSUPPORTED_POOL`; transfer-hook pools excluded);
|
|
34
41
|
* - the serialized transaction exceeds 1,232 bytes (`TRANSACTION_TOO_LARGE`).
|
|
35
42
|
*
|
|
36
43
|
* Transaction size: measured on devnet (scripts/devnet-tests/reports/core-swap.md) at 819 bytes for a
|
|
37
44
|
* buy and 797 bytes for a sell with this exact layout, far below the 1,232-byte limit (a buy that
|
|
38
|
-
* also creates the coin ATA adds 10 bytes
|
|
39
|
-
*
|
|
40
|
-
* `AddressLookupTableAccount`s, e.g. one holding the
|
|
41
|
-
*
|
|
42
|
-
* is then compiled against those tables and checked
|
|
45
|
+
* also creates the coin ATA adds 10 bytes, a priority fee 12 bytes for `setComputeUnitPrice`). If
|
|
46
|
+
* a future layout does not fit, the builders throw `TRANSACTION_TOO_LARGE` unless the caller
|
|
47
|
+
* passes `addressLookupTables` (already fetched `AddressLookupTableAccount`s, e.g. one holding the
|
|
48
|
+
* DBC program, the pool authority, the event authority, the token programs, the wrapped SOL mint
|
|
49
|
+
* and the two FORGE fee accounts); the message is then compiled against those tables and checked
|
|
50
|
+
* again.
|
|
43
51
|
*
|
|
44
52
|
* Layering: `fetchSwapContext` does all the network reads (with retries); everything else is pure
|
|
45
53
|
* and unit-tested without network (`buildSwapTransaction`, `computeSwapQuote`, fee math).
|
|
@@ -48,10 +56,11 @@ import { PublicKey, TransactionInstruction, VersionedTransaction, type AddressLo
|
|
|
48
56
|
import BN from 'bn.js';
|
|
49
57
|
import { type PoolConfig, type VirtualPool } from '@meteora-ag/dynamic-bonding-curve-sdk';
|
|
50
58
|
import { type AddressEnv } from './addresses.js';
|
|
59
|
+
import { type PriorityFeeQuote, type PriorityFeeSetting } from './priority-fee.js';
|
|
51
60
|
/** Platform fee on swaps built by @forge/core, in bps (`FEES.platformFeeBps` from @forge/shared). */
|
|
52
61
|
export declare const PLATFORM_FEE_BPS: number;
|
|
53
|
-
/** Highest slippage tolerance accepted by the builders (
|
|
54
|
-
export declare const MAX_SWAP_SLIPPAGE_BPS =
|
|
62
|
+
/** Highest slippage tolerance accepted by the builders (25%), whether given in bps or as a minimum. */
|
|
63
|
+
export declare const MAX_SWAP_SLIPPAGE_BPS = 2500;
|
|
55
64
|
/**
|
|
56
65
|
* Default compute unit limit. Measured on devnet: ~51,000 CU for a buy (~66,500 when it also creates
|
|
57
66
|
* the coin ATA), ~49,000 CU for a sell; the default leaves about 2x headroom (fee scheduler,
|
|
@@ -66,7 +75,7 @@ export declare const MAX_SWAP_PRIORITY_FEE_MICRO_LAMPORTS = 10000000;
|
|
|
66
75
|
export declare const SWAP_BASE_FEE_LAMPORTS_PER_SIGNATURE = 5000n;
|
|
67
76
|
/** Serialized transaction size limit (`PACKET_DATA_SIZE` = 1,232 bytes). */
|
|
68
77
|
export declare const SWAP_MAX_TRANSACTION_BYTES: number;
|
|
69
|
-
export declare const SWAP_ERROR_CODES: readonly ["INVALID_PARAMS", "POOL_NOT_FOUND", "UNSUPPORTED_POOL", "POOL_GRADUATED", "PLATFORM_FEE_WALLET_NOT_RENT_EXEMPT", "REFERRAL_ACCOUNT_INVALID", "INSUFFICIENT_LIQUIDITY", "QUOTE_FAILED", "AMOUNT_TOO_SMALL", "MIN_AMOUNT_OUT_ABOVE_QUOTE", "SLIPPAGE_TOO_HIGH", "INSUFFICIENT_SOL_BALANCE", "INSUFFICIENT_TOKEN_BALANCE", "TRANSACTION_TOO_LARGE", "RPC_ERROR"];
|
|
78
|
+
export declare const SWAP_ERROR_CODES: readonly ["INVALID_PARAMS", "POOL_NOT_FOUND", "UNSUPPORTED_POOL", "POOL_GRADUATED", "POOL_NOT_ALLOWED", "PLATFORM_FEE_WALLET_NOT_RENT_EXEMPT", "PLATFORM_FEE_WALLET_MISMATCH", "REFERRAL_ACCOUNT_INVALID", "INSUFFICIENT_LIQUIDITY", "QUOTE_FAILED", "AMOUNT_TOO_SMALL", "MIN_AMOUNT_OUT_ABOVE_QUOTE", "SLIPPAGE_TOO_HIGH", "INSUFFICIENT_SOL_BALANCE", "INSUFFICIENT_TOKEN_BALANCE", "TRANSACTION_TOO_LARGE", "RPC_ERROR"];
|
|
70
79
|
export type SwapErrorCode = (typeof SWAP_ERROR_CODES)[number];
|
|
71
80
|
/** Public data attached to a `SwapError` (addresses, amounts as decimal strings). Never secrets. */
|
|
72
81
|
export type SwapErrorDetails = Readonly<Record<string, string | number | boolean>>;
|
|
@@ -270,15 +279,43 @@ export interface SwapContext extends SwapPoolState {
|
|
|
270
279
|
recentBlockhash: string;
|
|
271
280
|
lastValidBlockHeight: number;
|
|
272
281
|
}
|
|
273
|
-
/**
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
282
|
+
/**
|
|
283
|
+
* Throws unless the platform fee wallet exists and holds at least its rent-exempt minimum. With
|
|
284
|
+
* `expectedWallet` (FORGE_PLATFORM_FEE_WALLET, as `buildBuyTx` / `buildSellTx` pass it), the
|
|
285
|
+
* wallet must be exactly that key and a plain system account: lamports sent to an account owned by
|
|
286
|
+
* another program could not be spent by FORGE (`PLATFORM_FEE_WALLET_MISMATCH`).
|
|
287
|
+
*/
|
|
288
|
+
export declare function assertPlatformFeeWalletReady(wallet: PublicKey, account: SwapAccountSnapshot | null, rentExemptMinimum: bigint, expectedWallet?: PublicKey | null): void;
|
|
289
|
+
/**
|
|
290
|
+
* Throws unless the referral account is an initialized wrapped SOL token account (SPL Token).
|
|
291
|
+
* With `expectedOwner` (FORGE_REVENUE_WALLET, when the environment has it), the token account must
|
|
292
|
+
* be held by that key: otherwise the referral share would be paid to someone else.
|
|
293
|
+
*/
|
|
294
|
+
export declare function assertReferralAccountReady(address: PublicKey, account: SwapAccountSnapshot | null, expectedOwner?: PublicKey | null): void;
|
|
295
|
+
/** The FORGE fee accounts a swap transaction must pay, as the builders read them from the env. */
|
|
296
|
+
export interface SwapFeeAccountExpectations {
|
|
297
|
+
/** The platform fee transfer must go to exactly this key (FORGE_PLATFORM_FEE_WALLET). */
|
|
298
|
+
platformFeeWallet?: PublicKey | null;
|
|
299
|
+
/** The Meteora referral token account must be held by this key (FORGE_REVENUE_WALLET). */
|
|
300
|
+
referralOwner?: PublicKey | null;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Throws `POOL_NOT_ALLOWED` unless the pool's config is one of `allowedConfigs`. Without a list
|
|
304
|
+
* (`undefined`), any config is accepted; an empty list accepts none.
|
|
305
|
+
*/
|
|
306
|
+
export declare function assertPoolConfigAllowed(pool: PublicKey, config: PublicKey, allowedConfigs: readonly (PublicKey | string)[] | undefined): void;
|
|
277
307
|
export interface SwapBuildOptions {
|
|
278
308
|
/** Compute unit limit (default `DEFAULT_SWAP_COMPUTE_UNIT_LIMIT`). */
|
|
279
309
|
computeUnitLimit?: number;
|
|
280
310
|
/** Priority fee in micro-lamports per CU (default 0: no `setComputeUnitPrice` instruction). */
|
|
281
311
|
priorityFeeMicroLamports?: number;
|
|
312
|
+
/**
|
|
313
|
+
* Priority fee read from the cluster (priority-fee.ts): the recent fees of the swap's writable
|
|
314
|
+
* accounts, bounded by this setting (`{}` = `DEFAULT_PRIORITY_FEE_POLICY`: at most 0.0005 SOL
|
|
315
|
+
* per swap). Only `buildBuyTx` / `buildSellTx` read it (they hold the connection); not with
|
|
316
|
+
* `priorityFeeMicroLamports`.
|
|
317
|
+
*/
|
|
318
|
+
priority?: PriorityFeeSetting;
|
|
282
319
|
/**
|
|
283
320
|
* Address lookup tables to compile the v0 message with, if the transaction would exceed 1,232
|
|
284
321
|
* bytes without them (it does not with the current layout). Fetch them with
|
|
@@ -298,6 +335,11 @@ export interface BuiltSwapTransaction {
|
|
|
298
335
|
sizeBytes: number;
|
|
299
336
|
computeUnitLimit: number;
|
|
300
337
|
priorityFeeMicroLamports: number;
|
|
338
|
+
/**
|
|
339
|
+
* The priority fee: price, fee in lamports and its cap (`maxLamports`, the cost guard to show
|
|
340
|
+
* before signing), and where the price comes from (`fixed` without a `priority` setting).
|
|
341
|
+
*/
|
|
342
|
+
priorityFee: PriorityFeeQuote;
|
|
301
343
|
/** Base fee + priority fee, in lamports. */
|
|
302
344
|
estimatedNetworkFeeLamports: bigint;
|
|
303
345
|
/** Rent locked in a coin ATA created by a buy (0 when it already existed or on a sell). */
|
|
@@ -321,12 +363,19 @@ export declare function compileSwapTransaction(args: {
|
|
|
321
363
|
sizeBytes: number;
|
|
322
364
|
};
|
|
323
365
|
/**
|
|
324
|
-
* Pure transaction builder: validates the context (pool on its curve, fee accounts ready,
|
|
325
|
-
* quotes, and assembles the instructions in the order documented at
|
|
366
|
+
* Pure transaction builder: validates the context (pool on its curve, fee accounts ready and, with
|
|
367
|
+
* `expected`, exactly FORGE's), quotes, and assembles the instructions in the order documented at
|
|
368
|
+
* the top of this file.
|
|
369
|
+
*/
|
|
370
|
+
export declare function buildSwapTransaction(ctx: SwapContext, request: SwapBuildRequest, expected?: SwapFeeAccountExpectations): BuiltSwapTransaction;
|
|
371
|
+
/**
|
|
372
|
+
* Reads and decodes a pool and its config, plus the current point. With
|
|
373
|
+
* `options.allowedConfigs`, a pool whose config is not in the list is refused (`POOL_NOT_ALLOWED`)
|
|
374
|
+
* before its config is read.
|
|
326
375
|
*/
|
|
327
|
-
export declare function
|
|
328
|
-
|
|
329
|
-
|
|
376
|
+
export declare function fetchSwapPoolState(connection: Connection, poolAddress: PublicKey | string, commitment?: Commitment, options?: {
|
|
377
|
+
allowedConfigs?: readonly (PublicKey | string)[];
|
|
378
|
+
}): Promise<SwapPoolState & {
|
|
330
379
|
configAddress: PublicKey;
|
|
331
380
|
}>;
|
|
332
381
|
export interface FetchSwapContextParams {
|
|
@@ -336,22 +385,42 @@ export interface FetchSwapContextParams {
|
|
|
336
385
|
platformFeeWallet: PublicKey;
|
|
337
386
|
referralTokenAccount: PublicKey;
|
|
338
387
|
commitment?: Commitment;
|
|
388
|
+
/** Configs the pool may belong to; anything else is `POOL_NOT_ALLOWED` (default: any config). */
|
|
389
|
+
allowedConfigs?: readonly (PublicKey | string)[];
|
|
339
390
|
}
|
|
340
391
|
/** All network reads of a swap build: pool, config, user accounts, fee accounts, rent, blockhash. */
|
|
341
392
|
export declare function fetchSwapContext(p: FetchSwapContextParams): Promise<SwapContext>;
|
|
342
|
-
/**
|
|
393
|
+
/**
|
|
394
|
+
* FORGE fee accounts used by the swap, resolved through addresses.ts (never hard-coded), and the
|
|
395
|
+
* revenue wallet that must hold the referral account (`null` when the environment does not have
|
|
396
|
+
* `FORGE_REVENUE_WALLET`: the owner check is then skipped). When the environment has it, the
|
|
397
|
+
* platform fee wallet must be that same wallet (D34: the platform fee is revenue too), otherwise
|
|
398
|
+
* `PLATFORM_FEE_WALLET_MISMATCH`.
|
|
399
|
+
*/
|
|
343
400
|
export declare function swapFeeAddresses(env?: AddressEnv): {
|
|
344
401
|
platformFeeWallet: PublicKey;
|
|
345
402
|
referralTokenAccount: PublicKey;
|
|
403
|
+
revenueWallet: PublicKey | null;
|
|
346
404
|
};
|
|
347
405
|
interface SwapCommonParams extends SwapBuildOptions {
|
|
348
406
|
connection: Connection;
|
|
349
407
|
pool: PublicKey | string;
|
|
350
408
|
/** The trader: fee payer, signer and owner of the token accounts. */
|
|
351
409
|
user: PublicKey | string;
|
|
352
|
-
/**
|
|
410
|
+
/**
|
|
411
|
+
* Environment to read the FORGE addresses from (defaults to `process.env`):
|
|
412
|
+
* `FORGE_PLATFORM_FEE_WALLET` and `FORGE_METEORA_REFERRAL_ACCOUNT` (required), and
|
|
413
|
+
* `FORGE_REVENUE_WALLET` (optional: when set, the referral account must be held by it and the
|
|
414
|
+
* platform fee wallet must be it).
|
|
415
|
+
*/
|
|
353
416
|
env?: AddressEnv;
|
|
354
417
|
commitment?: Commitment;
|
|
418
|
+
/**
|
|
419
|
+
* Configs the pool must belong to (e.g. the two configs of the launchpad whose site builds the
|
|
420
|
+
* swap). The pool's config is read on-chain; any other pool is refused with `POOL_NOT_ALLOWED`.
|
|
421
|
+
* Without it, any SOL-quoted DBC pool is accepted.
|
|
422
|
+
*/
|
|
423
|
+
allowedConfigs?: readonly (PublicKey | string)[];
|
|
355
424
|
}
|
|
356
425
|
export type BuildBuyTxParams = SwapCommonParams & {
|
|
357
426
|
/** SOL into the swap, in lamports. The platform fee is paid on top of it. */
|
|
@@ -372,6 +441,8 @@ export type QuoteSwapParams = {
|
|
|
372
441
|
/** Lamports on a buy, raw coin units on a sell. */
|
|
373
442
|
amountIn: bigint;
|
|
374
443
|
commitment?: Commitment;
|
|
444
|
+
/** Same as on `buildBuyTx`: configs the pool must belong to (`POOL_NOT_ALLOWED` otherwise). */
|
|
445
|
+
allowedConfigs?: readonly (PublicKey | string)[];
|
|
375
446
|
} & (SlippageInput | {
|
|
376
447
|
slippageBps?: undefined;
|
|
377
448
|
minAmountOut?: undefined;
|
|
@@ -382,8 +453,9 @@ export type QuoteSwapParams = {
|
|
|
382
453
|
*/
|
|
383
454
|
export declare function quoteSwap(params: QuoteSwapParams): Promise<SwapQuote>;
|
|
384
455
|
/**
|
|
385
|
-
* Startup / pre-build check of the FORGE fee accounts: the platform fee wallet must be
|
|
386
|
-
* and the referral account must be a wrapped SOL token account
|
|
456
|
+
* Startup / pre-build check of the FORGE fee accounts: the platform fee wallet must be a
|
|
457
|
+
* rent-exempt system account and the referral account must be a wrapped SOL token account, held by
|
|
458
|
+
* `FORGE_REVENUE_WALLET` when the environment has it. Throws `SwapError`.
|
|
387
459
|
*/
|
|
388
460
|
export declare function assertSwapFeeAccountsReady(params: {
|
|
389
461
|
connection: Connection;
|