@send-fun/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 +32 -0
- package/dist/index.cjs +12808 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4406 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +4405 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +12749 -0
- package/dist/index.mjs.map +1 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/package.json +72 -0
- package/src/constants.ts +38 -0
- package/src/dex/generated/accounts/globalConfig.ts +189 -0
- package/src/dex/generated/accounts/index.ts +12 -0
- package/src/dex/generated/accounts/pool.ts +244 -0
- package/src/dex/generated/accounts/rewardAccrual.ts +191 -0
- package/src/dex/generated/accounts/sendDex.accounts.ts +47 -0
- package/src/dex/generated/errors/index.ts +9 -0
- package/src/dex/generated/errors/sendDex.ts +161 -0
- package/src/dex/generated/events/anchorEventCpiDiscriminator.framing.ts +28 -0
- package/src/dex/generated/events/creatorClaimEvent.ts +119 -0
- package/src/dex/generated/events/depositQuoteEvent.ts +115 -0
- package/src/dex/generated/events/index.ts +16 -0
- package/src/dex/generated/events/poolCreateEvent.ts +128 -0
- package/src/dex/generated/events/protocolClaimEvent.ts +111 -0
- package/src/dex/generated/events/sendDex.events.ts +184 -0
- package/src/dex/generated/events/tokenCreateEvent.ts +143 -0
- package/src/dex/generated/events/tradeEvent.ts +143 -0
- package/src/dex/generated/index.ts +16 -0
- package/src/dex/generated/instructions/buyExactIn.ts +815 -0
- package/src/dex/generated/instructions/buyExactOut.ts +815 -0
- package/src/dex/generated/instructions/claimCreatorFees.ts +648 -0
- package/src/dex/generated/instructions/claimProtocolFees.ts +640 -0
- package/src/dex/generated/instructions/index.ts +15 -0
- package/src/dex/generated/instructions/sellExactIn.ts +815 -0
- package/src/dex/generated/instructions/sellExactOut.ts +815 -0
- package/src/dex/generated/instructions/sendDex.instructions.ts +173 -0
- package/src/dex/generated/pdas/eventAuthority.ts +20 -0
- package/src/dex/generated/pdas/globalConfig.ts +20 -0
- package/src/dex/generated/pdas/index.ts +14 -0
- package/src/dex/generated/pdas/lpMint.ts +36 -0
- package/src/dex/generated/pdas/pool.ts +34 -0
- package/src/dex/generated/pdas/rewardAccrual.ts +37 -0
- package/src/dex/generated/pdas/wsolRewardAccrual.ts +20 -0
- package/src/dex/generated/plugins/index.ts +9 -0
- package/src/dex/generated/plugins/sendDex.ts +282 -0
- package/src/dex/generated/programs/index.ts +9 -0
- package/src/dex/generated/programs/sendDex.ts +12 -0
- package/src/dex/generated/types/index.ts +10 -0
- package/src/dex/generated/types/poolStatus.ts +38 -0
- package/src/dex/generated/types/tradeDirection.ts +38 -0
- package/src/dex/index.ts +8 -0
- package/src/dex/trade.ts +215 -0
- package/src/index.ts +8 -0
- package/src/launchpad/create.ts +116 -0
- package/src/launchpad/generated/accounts/bondingCurve.ts +273 -0
- package/src/launchpad/generated/accounts/globalConfig.ts +211 -0
- package/src/launchpad/generated/accounts/index.ts +12 -0
- package/src/launchpad/generated/accounts/rewardAccrual.ts +191 -0
- package/src/launchpad/generated/accounts/sendLaunchpad.accounts.ts +50 -0
- package/src/launchpad/generated/errors/index.ts +9 -0
- package/src/launchpad/generated/errors/sendLaunchpad.ts +175 -0
- package/src/launchpad/generated/events/anchorEventCpiDiscriminator.framing.ts +28 -0
- package/src/launchpad/generated/events/completeEvent.ts +120 -0
- package/src/launchpad/generated/events/creatorClaimEvent.ts +122 -0
- package/src/launchpad/generated/events/index.ts +17 -0
- package/src/launchpad/generated/events/migrateEvent.ts +121 -0
- package/src/launchpad/generated/events/protocolClaimEvent.ts +114 -0
- package/src/launchpad/generated/events/recycleEvent.ts +113 -0
- package/src/launchpad/generated/events/sendLaunchpad.events.ts +207 -0
- package/src/launchpad/generated/events/tokenCreateEvent.ts +156 -0
- package/src/launchpad/generated/events/tradeEvent.ts +148 -0
- package/src/launchpad/generated/index.ts +16 -0
- package/src/launchpad/generated/instructions/buyExactIn.ts +818 -0
- package/src/launchpad/generated/instructions/buyExactOut.ts +818 -0
- package/src/launchpad/generated/instructions/claimCreatorFees.ts +651 -0
- package/src/launchpad/generated/instructions/claimProtocolFees.ts +640 -0
- package/src/launchpad/generated/instructions/createToken.ts +1150 -0
- package/src/launchpad/generated/instructions/index.ts +17 -0
- package/src/launchpad/generated/instructions/migrate.ts +840 -0
- package/src/launchpad/generated/instructions/sellExactIn.ts +818 -0
- package/src/launchpad/generated/instructions/sellExactOut.ts +818 -0
- package/src/launchpad/generated/instructions/sendLaunchpad.instructions.ts +210 -0
- package/src/launchpad/generated/pdas/bondingCurve.ts +39 -0
- package/src/launchpad/generated/pdas/eventAuthority.ts +20 -0
- package/src/launchpad/generated/pdas/globalConfig.ts +20 -0
- package/src/launchpad/generated/pdas/index.ts +14 -0
- package/src/launchpad/generated/pdas/migrationAuthority.ts +20 -0
- package/src/launchpad/generated/pdas/rewardAccrual.ts +37 -0
- package/src/launchpad/generated/pdas/wsolRewardAccrual.ts +20 -0
- package/src/launchpad/generated/plugins/index.ts +9 -0
- package/src/launchpad/generated/plugins/sendLaunchpad.ts +315 -0
- package/src/launchpad/generated/programs/index.ts +9 -0
- package/src/launchpad/generated/programs/sendLaunchpad.ts +12 -0
- package/src/launchpad/generated/types/bondingCurveStatus.ts +43 -0
- package/src/launchpad/generated/types/index.ts +10 -0
- package/src/launchpad/generated/types/tradeDirection.ts +38 -0
- package/src/launchpad/index.ts +10 -0
- package/src/launchpad/migrate.ts +54 -0
- package/src/launchpad/trade.ts +247 -0
- package/src/math/amm.ts +511 -0
- package/src/math/fee-decay.ts +49 -0
- package/src/math/fees.ts +75 -0
- package/src/math/index.ts +3 -0
- package/src/math/internal.ts +16 -0
- package/src/nexus/fee-helpers.ts +49 -0
- package/src/nexus/generated/accounts/altRegistry.ts +177 -0
- package/src/nexus/generated/accounts/creatorFeeConfig.ts +200 -0
- package/src/nexus/generated/accounts/feePreset.ts +196 -0
- package/src/nexus/generated/accounts/globalConfig.ts +188 -0
- package/src/nexus/generated/accounts/index.ts +19 -0
- package/src/nexus/generated/accounts/partnerConfig.ts +209 -0
- package/src/nexus/generated/accounts/partnerMetadata.ts +216 -0
- package/src/nexus/generated/accounts/rewardState.ts +209 -0
- package/src/nexus/generated/accounts/sendNexus.accounts.ts +85 -0
- package/src/nexus/generated/accounts/stakingConfig.ts +197 -0
- package/src/nexus/generated/accounts/userRewardDebt.ts +221 -0
- package/src/nexus/generated/accounts/userStakePosition.ts +218 -0
- package/src/nexus/generated/constants/index.ts +9 -0
- package/src/nexus/generated/constants/sendNexus.ts +13 -0
- package/src/nexus/generated/errors/index.ts +9 -0
- package/src/nexus/generated/errors/sendNexus.ts +229 -0
- package/src/nexus/generated/events/anchorEventCpiDiscriminator.framing.ts +28 -0
- package/src/nexus/generated/events/claimEvent.ts +106 -0
- package/src/nexus/generated/events/index.ts +13 -0
- package/src/nexus/generated/events/sendNexus.events.ts +121 -0
- package/src/nexus/generated/events/stakeEvent.ts +106 -0
- package/src/nexus/generated/events/unstakeEvent.ts +106 -0
- package/src/nexus/generated/index.ts +17 -0
- package/src/nexus/generated/instructions/claim.ts +740 -0
- package/src/nexus/generated/instructions/createUserRewardDebt.ts +498 -0
- package/src/nexus/generated/instructions/index.ts +14 -0
- package/src/nexus/generated/instructions/sendNexus.instructions.ts +146 -0
- package/src/nexus/generated/instructions/settle.ts +517 -0
- package/src/nexus/generated/instructions/stake.ts +615 -0
- package/src/nexus/generated/instructions/unstake.ts +593 -0
- package/src/nexus/generated/pdas/altRegistry.ts +20 -0
- package/src/nexus/generated/pdas/creatorFeeConfig.ts +39 -0
- package/src/nexus/generated/pdas/defaultFeePreset.ts +37 -0
- package/src/nexus/generated/pdas/defaultPartner.ts +40 -0
- package/src/nexus/generated/pdas/defaultPartnerMetadata.ts +42 -0
- package/src/nexus/generated/pdas/eventAuthority.ts +20 -0
- package/src/nexus/generated/pdas/feePreset.ts +39 -0
- package/src/nexus/generated/pdas/globalConfig.ts +20 -0
- package/src/nexus/generated/pdas/index.ts +22 -0
- package/src/nexus/generated/pdas/partnerConfig.ts +36 -0
- package/src/nexus/generated/pdas/partnerMetadata.ts +38 -0
- package/src/nexus/generated/pdas/rewardState.ts +36 -0
- package/src/nexus/generated/pdas/stakingConfig.ts +20 -0
- package/src/nexus/generated/pdas/userRewardDebt.ts +41 -0
- package/src/nexus/generated/pdas/userStakePosition.ts +39 -0
- package/src/nexus/generated/plugins/index.ts +9 -0
- package/src/nexus/generated/plugins/sendNexus.ts +494 -0
- package/src/nexus/generated/programs/index.ts +9 -0
- package/src/nexus/generated/programs/sendNexus.ts +12 -0
- package/src/nexus/generated/types/authPlatformEntry.ts +52 -0
- package/src/nexus/generated/types/callerType.ts +38 -0
- package/src/nexus/generated/types/dexFees.ts +64 -0
- package/src/nexus/generated/types/feeConfig.ts +73 -0
- package/src/nexus/generated/types/index.ts +13 -0
- package/src/nexus/generated/types/launchpadFees.ts +63 -0
- package/src/nexus/index.ts +9 -0
- package/src/nexus/staking.ts +581 -0
- package/src/platform.ts +19 -0
- package/src/transfer-fee.ts +216 -0
- package/src/utils/chunk.ts +21 -0
- package/src/utils/creator-hash.ts +57 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/mint-info.ts +102 -0
- package/src/utils/partner.ts +5 -0
- package/src/utils/pda.ts +24 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was AUTOGENERATED using the Codama library.
|
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
+
* to add features, then rerun Codama to update it.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/codama-idl/codama
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
combineCodec,
|
|
11
|
+
getEnumDecoder,
|
|
12
|
+
getEnumEncoder,
|
|
13
|
+
type FixedSizeCodec,
|
|
14
|
+
type FixedSizeDecoder,
|
|
15
|
+
type FixedSizeEncoder,
|
|
16
|
+
} from '@solana/kit';
|
|
17
|
+
|
|
18
|
+
export enum PoolStatus {
|
|
19
|
+
Active,
|
|
20
|
+
Paused,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type PoolStatusArgs = PoolStatus;
|
|
24
|
+
|
|
25
|
+
export function getPoolStatusEncoder(): FixedSizeEncoder<PoolStatusArgs> {
|
|
26
|
+
return getEnumEncoder(PoolStatus);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function getPoolStatusDecoder(): FixedSizeDecoder<PoolStatus> {
|
|
30
|
+
return getEnumDecoder(PoolStatus);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function getPoolStatusCodec(): FixedSizeCodec<
|
|
34
|
+
PoolStatusArgs,
|
|
35
|
+
PoolStatus
|
|
36
|
+
> {
|
|
37
|
+
return combineCodec(getPoolStatusEncoder(), getPoolStatusDecoder());
|
|
38
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was AUTOGENERATED using the Codama library.
|
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
+
* to add features, then rerun Codama to update it.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/codama-idl/codama
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
combineCodec,
|
|
11
|
+
getEnumDecoder,
|
|
12
|
+
getEnumEncoder,
|
|
13
|
+
type FixedSizeCodec,
|
|
14
|
+
type FixedSizeDecoder,
|
|
15
|
+
type FixedSizeEncoder,
|
|
16
|
+
} from '@solana/kit';
|
|
17
|
+
|
|
18
|
+
export enum TradeDirection {
|
|
19
|
+
Buy,
|
|
20
|
+
Sell,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type TradeDirectionArgs = TradeDirection;
|
|
24
|
+
|
|
25
|
+
export function getTradeDirectionEncoder(): FixedSizeEncoder<TradeDirectionArgs> {
|
|
26
|
+
return getEnumEncoder(TradeDirection);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function getTradeDirectionDecoder(): FixedSizeDecoder<TradeDirection> {
|
|
30
|
+
return getEnumDecoder(TradeDirection);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function getTradeDirectionCodec(): FixedSizeCodec<
|
|
34
|
+
TradeDirectionArgs,
|
|
35
|
+
TradeDirection
|
|
36
|
+
> {
|
|
37
|
+
return combineCodec(getTradeDirectionEncoder(), getTradeDirectionDecoder());
|
|
38
|
+
}
|
package/src/dex/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * as accounts from './generated/accounts/index.js';
|
|
2
|
+
export * as types from './generated/types/index.js';
|
|
3
|
+
export * as errors from './generated/errors/index.js';
|
|
4
|
+
export * as pda from './generated/pdas/index.js';
|
|
5
|
+
export * as events from './generated/events/index.js';
|
|
6
|
+
export * as instructions from './generated/instructions/index.js';
|
|
7
|
+
export * as plugins from './generated/plugins/index.js';
|
|
8
|
+
export * as trade from './trade.js';
|
package/src/dex/trade.ts
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import type { Address, Instruction, TransactionSigner } from '@solana/kit';
|
|
2
|
+
import type { BuyQuote, MintFee, SellQuote } from '../math/amm.js';
|
|
3
|
+
import * as amm from '../math/amm.js';
|
|
4
|
+
import type { PartnerInput } from '../utils/partner.js';
|
|
5
|
+
import { getBuyExactInInstructionAsync } from './generated/instructions/buyExactIn.js';
|
|
6
|
+
import { getBuyExactOutInstructionAsync } from './generated/instructions/buyExactOut.js';
|
|
7
|
+
import { getSellExactInInstructionAsync } from './generated/instructions/sellExactIn.js';
|
|
8
|
+
import { getSellExactOutInstructionAsync } from './generated/instructions/sellExactOut.js';
|
|
9
|
+
|
|
10
|
+
export interface DexTradeParams {
|
|
11
|
+
user: TransactionSigner;
|
|
12
|
+
payer?: TransactionSigner;
|
|
13
|
+
baseMint: Address;
|
|
14
|
+
quoteMint: Address;
|
|
15
|
+
baseReserves: bigint;
|
|
16
|
+
quoteReserves: bigint;
|
|
17
|
+
feeBps: number;
|
|
18
|
+
slippageBps: number;
|
|
19
|
+
partner: PartnerInput;
|
|
20
|
+
platformConfig: Address;
|
|
21
|
+
quoteTokenProgram: Address;
|
|
22
|
+
/** Token-2022 schedule for the epoch the trade lands in; stale or missing skews the slippage bounds. */
|
|
23
|
+
quoteFee?: MintFee;
|
|
24
|
+
baseFee?: MintFee;
|
|
25
|
+
/** {@inheritDoc DexInstructionParams.userQuoteAccount} */
|
|
26
|
+
userQuoteAccount?: Address;
|
|
27
|
+
/** {@inheritDoc DexInstructionParams.userBaseAccount} */
|
|
28
|
+
userBaseAccount?: Address;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface DexInstructionParams {
|
|
32
|
+
user: TransactionSigner;
|
|
33
|
+
payer?: TransactionSigner;
|
|
34
|
+
baseMint: Address;
|
|
35
|
+
quoteMint: Address;
|
|
36
|
+
partner: PartnerInput;
|
|
37
|
+
platformConfig: Address;
|
|
38
|
+
quoteTokenProgram: Address;
|
|
39
|
+
/** Any user-owned quote-mint account. Defaults to the ATA, created mid-trade
|
|
40
|
+
* if missing (payer funds rent), which only rescues a sell. For WSOL,
|
|
41
|
+
* a throwaway `createAccountWithSeed` account is cheaper. */
|
|
42
|
+
userQuoteAccount?: Address;
|
|
43
|
+
/** Any user-owned base-mint account. Defaults to the ATA, created mid-trade
|
|
44
|
+
* if missing (payer funds rent), which only rescues a buy. */
|
|
45
|
+
userBaseAccount?: Address;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** `baseAmountOut` is net to the buyer: the program reads `amount` as `base_to_user`. */
|
|
49
|
+
export async function buyExactOut(
|
|
50
|
+
params: DexTradeParams & { baseAmountOut: bigint },
|
|
51
|
+
): Promise<{ instruction: Instruction; quote: BuyQuote }> {
|
|
52
|
+
const quote = amm.buyExactOut({
|
|
53
|
+
reserveQuote: params.quoteReserves,
|
|
54
|
+
reserveBase: params.baseReserves,
|
|
55
|
+
baseAmountOut: params.baseAmountOut,
|
|
56
|
+
feeBps: params.feeBps,
|
|
57
|
+
quoteFee: params.quoteFee,
|
|
58
|
+
baseFee: params.baseFee,
|
|
59
|
+
});
|
|
60
|
+
// The cap is measured on the gross the buyer sends, quote transfer fee included.
|
|
61
|
+
const maxQuoteIn = amm.calculateSlippageUp(
|
|
62
|
+
quote.quoteFromUser,
|
|
63
|
+
params.slippageBps,
|
|
64
|
+
);
|
|
65
|
+
return {
|
|
66
|
+
instruction: await buildBuyExactOutInstruction({
|
|
67
|
+
...params,
|
|
68
|
+
amountOut: params.baseAmountOut,
|
|
69
|
+
maxAmountIn: maxQuoteIn,
|
|
70
|
+
}),
|
|
71
|
+
quote,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function buyExactIn(
|
|
76
|
+
params: DexTradeParams & { quoteAmountIn: bigint },
|
|
77
|
+
): Promise<{ instruction: Instruction; quote: BuyQuote }> {
|
|
78
|
+
const quote = amm.buyExactIn({
|
|
79
|
+
reserveQuote: params.quoteReserves,
|
|
80
|
+
reserveBase: params.baseReserves,
|
|
81
|
+
quoteAmountIn: params.quoteAmountIn,
|
|
82
|
+
feeBps: params.feeBps,
|
|
83
|
+
quoteFee: params.quoteFee,
|
|
84
|
+
baseFee: params.baseFee,
|
|
85
|
+
});
|
|
86
|
+
// The floor is measured on the buyer's credit, not the vault's debit.
|
|
87
|
+
const minBaseOut = amm.calculateSlippageDown(
|
|
88
|
+
quote.baseToUser,
|
|
89
|
+
params.slippageBps,
|
|
90
|
+
);
|
|
91
|
+
return {
|
|
92
|
+
instruction: await buildBuyExactInInstruction({
|
|
93
|
+
...params,
|
|
94
|
+
amountIn: params.quoteAmountIn,
|
|
95
|
+
minAmountOut: minBaseOut,
|
|
96
|
+
}),
|
|
97
|
+
quote,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export async function sellExactIn(
|
|
102
|
+
params: DexTradeParams & { baseAmountIn: bigint },
|
|
103
|
+
): Promise<{ instruction: Instruction; quote: SellQuote }> {
|
|
104
|
+
const quote = amm.sellExactIn({
|
|
105
|
+
reserveQuote: params.quoteReserves,
|
|
106
|
+
reserveBase: params.baseReserves,
|
|
107
|
+
baseAmountIn: params.baseAmountIn,
|
|
108
|
+
feeBps: params.feeBps,
|
|
109
|
+
quoteFee: params.quoteFee,
|
|
110
|
+
baseFee: params.baseFee,
|
|
111
|
+
});
|
|
112
|
+
// The floor is measured on the seller's credit, not what leaves the vault.
|
|
113
|
+
const minQuoteOut = amm.calculateSlippageDown(
|
|
114
|
+
quote.quoteToUser,
|
|
115
|
+
params.slippageBps,
|
|
116
|
+
);
|
|
117
|
+
return {
|
|
118
|
+
instruction: await buildSellExactInInstruction({
|
|
119
|
+
...params,
|
|
120
|
+
amountIn: params.baseAmountIn,
|
|
121
|
+
minAmountOut: minQuoteOut,
|
|
122
|
+
}),
|
|
123
|
+
quote,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** `quoteAmountOut` is net to the seller: the program reads `amount` as `quote_to_user`. */
|
|
128
|
+
export async function sellExactOut(
|
|
129
|
+
params: DexTradeParams & { quoteAmountOut: bigint },
|
|
130
|
+
): Promise<{ instruction: Instruction; quote: SellQuote }> {
|
|
131
|
+
const quote = amm.sellExactOut({
|
|
132
|
+
reserveQuote: params.quoteReserves,
|
|
133
|
+
reserveBase: params.baseReserves,
|
|
134
|
+
quoteAmountOut: params.quoteAmountOut,
|
|
135
|
+
feeBps: params.feeBps,
|
|
136
|
+
quoteFee: params.quoteFee,
|
|
137
|
+
baseFee: params.baseFee,
|
|
138
|
+
});
|
|
139
|
+
// The cap is measured on the gross the seller sends, base transfer fee included.
|
|
140
|
+
const maxBaseIn = amm.calculateSlippageUp(
|
|
141
|
+
quote.baseFromUser,
|
|
142
|
+
params.slippageBps,
|
|
143
|
+
);
|
|
144
|
+
return {
|
|
145
|
+
instruction: await buildSellExactOutInstruction({
|
|
146
|
+
...params,
|
|
147
|
+
amountOut: params.quoteAmountOut,
|
|
148
|
+
maxAmountIn: maxBaseIn,
|
|
149
|
+
}),
|
|
150
|
+
quote,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export async function buildBuyExactInInstruction(
|
|
155
|
+
params: DexInstructionParams & { amountIn: bigint; minAmountOut: bigint },
|
|
156
|
+
): Promise<Instruction> {
|
|
157
|
+
const shared = resolveSharedAccounts(params);
|
|
158
|
+
return getBuyExactInInstructionAsync({
|
|
159
|
+
...shared,
|
|
160
|
+
amountIn: params.amountIn,
|
|
161
|
+
minAmountOut: params.minAmountOut,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export async function buildBuyExactOutInstruction(
|
|
166
|
+
params: DexInstructionParams & { amountOut: bigint; maxAmountIn: bigint },
|
|
167
|
+
): Promise<Instruction> {
|
|
168
|
+
const shared = resolveSharedAccounts(params);
|
|
169
|
+
return getBuyExactOutInstructionAsync({
|
|
170
|
+
...shared,
|
|
171
|
+
amountOut: params.amountOut,
|
|
172
|
+
maxAmountIn: params.maxAmountIn,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export async function buildSellExactInInstruction(
|
|
177
|
+
params: DexInstructionParams & { amountIn: bigint; minAmountOut: bigint },
|
|
178
|
+
): Promise<Instruction> {
|
|
179
|
+
const shared = resolveSharedAccounts(params);
|
|
180
|
+
return getSellExactInInstructionAsync({
|
|
181
|
+
...shared,
|
|
182
|
+
amountIn: params.amountIn,
|
|
183
|
+
minAmountOut: params.minAmountOut,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export async function buildSellExactOutInstruction(
|
|
188
|
+
params: DexInstructionParams & { amountOut: bigint; maxAmountIn: bigint },
|
|
189
|
+
): Promise<Instruction> {
|
|
190
|
+
const shared = resolveSharedAccounts(params);
|
|
191
|
+
return getSellExactOutInstructionAsync({
|
|
192
|
+
...shared,
|
|
193
|
+
amountOut: params.amountOut,
|
|
194
|
+
maxAmountIn: params.maxAmountIn,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function resolveSharedAccounts(params: DexInstructionParams) {
|
|
199
|
+
return {
|
|
200
|
+
user: params.user,
|
|
201
|
+
payer: params.payer ?? params.user,
|
|
202
|
+
baseMint: params.baseMint,
|
|
203
|
+
quoteMint: params.quoteMint,
|
|
204
|
+
partner: params.partner,
|
|
205
|
+
platformConfig: params.platformConfig,
|
|
206
|
+
quoteTokenProgram: params.quoteTokenProgram,
|
|
207
|
+
// Left undefined so the generated client derives the ATA itself.
|
|
208
|
+
...(params.userQuoteAccount !== undefined && {
|
|
209
|
+
userQuoteAccount: params.userQuoteAccount,
|
|
210
|
+
}),
|
|
211
|
+
...(params.userBaseAccount !== undefined && {
|
|
212
|
+
userBaseAccount: params.userBaseAccount,
|
|
213
|
+
}),
|
|
214
|
+
};
|
|
215
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * as constants from './constants.js';
|
|
2
|
+
export * as dex from './dex/index.js';
|
|
3
|
+
export * as launchpad from './launchpad/index.js';
|
|
4
|
+
export * as math from './math/index.js';
|
|
5
|
+
export * as nexus from './nexus/index.js';
|
|
6
|
+
export * as platform from './platform.js';
|
|
7
|
+
export * as transferFee from './transfer-fee.js';
|
|
8
|
+
export * as utils from './utils/index.js';
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { Address, Instruction, TransactionSigner } from '@solana/kit';
|
|
2
|
+
import type { MintFee, TradeQuote } from '../math/amm.js';
|
|
3
|
+
import type { PartnerInput } from '../utils/partner.js';
|
|
4
|
+
import { creatorHashFromId } from '../utils/creator-hash.js';
|
|
5
|
+
import { findCreatorFeeConfigPda } from '../nexus/generated/pdas/creatorFeeConfig.js';
|
|
6
|
+
import { getCreateTokenInstructionAsync } from './generated/instructions/createToken.js';
|
|
7
|
+
import { buyExactIn } from './trade.js';
|
|
8
|
+
|
|
9
|
+
export interface CreateTokenParams {
|
|
10
|
+
user: TransactionSigner;
|
|
11
|
+
payer?: TransactionSigner;
|
|
12
|
+
coinCreator: Address;
|
|
13
|
+
baseMint: TransactionSigner;
|
|
14
|
+
quoteMint: Address;
|
|
15
|
+
name: string;
|
|
16
|
+
symbol: string;
|
|
17
|
+
uri: string;
|
|
18
|
+
/** An enabled nexus auth platform (e.g. "wallet"), max 32 bytes; hashed with
|
|
19
|
+
* `creatorId` into the creator fee identity. Unrelated to `platformConfig`. */
|
|
20
|
+
creatorPlatform: string;
|
|
21
|
+
creatorId: string;
|
|
22
|
+
partner: PartnerInput;
|
|
23
|
+
platformConfig: Address;
|
|
24
|
+
quoteTokenProgram: Address;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface CreateAndBuyParams extends CreateTokenParams {
|
|
28
|
+
buyQuoteAmount: bigint;
|
|
29
|
+
feeBps: number;
|
|
30
|
+
slippageBps: number;
|
|
31
|
+
initialVirtualQuoteReserves: bigint;
|
|
32
|
+
initialVirtualBaseReserves: bigint;
|
|
33
|
+
/** `globalConfig.initialRealBaseReserves`: caps the appended buy. */
|
|
34
|
+
initialRealBaseReserves: bigint;
|
|
35
|
+
/** Quote mint's Token-2022 schedule for the launch epoch; without it `minAmountOut`
|
|
36
|
+
* ignores the mint's cut, and a cut above `slippageBps` can revert the buy. No
|
|
37
|
+
* `baseFee`: this transaction creates the base mint without the extension. */
|
|
38
|
+
quoteFee?: MintFee;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function buildCreateTokenInstruction(
|
|
42
|
+
params: CreateTokenParams,
|
|
43
|
+
): Promise<Instruction> {
|
|
44
|
+
return buildCreateTokenInstructionWithHash(
|
|
45
|
+
params,
|
|
46
|
+
await creatorHashFromId(params.creatorPlatform, params.creatorId),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function buildCreateTokenInstructionWithHash(
|
|
51
|
+
params: CreateTokenParams,
|
|
52
|
+
creatorHash: Address,
|
|
53
|
+
): Promise<Instruction> {
|
|
54
|
+
const [creatorFeeConfig] = await findCreatorFeeConfigPda({
|
|
55
|
+
creatorHash,
|
|
56
|
+
quoteMint: params.quoteMint,
|
|
57
|
+
});
|
|
58
|
+
// The creation fee is native SOL from `user`; the client derives the WSOL staking vault.
|
|
59
|
+
return getCreateTokenInstructionAsync({
|
|
60
|
+
user: params.user,
|
|
61
|
+
payer: params.payer ?? params.user,
|
|
62
|
+
coinCreator: params.coinCreator,
|
|
63
|
+
baseMint: params.baseMint,
|
|
64
|
+
quoteMint: params.quoteMint,
|
|
65
|
+
creatorFeeConfig,
|
|
66
|
+
partner: params.partner,
|
|
67
|
+
platformConfig: params.platformConfig,
|
|
68
|
+
quoteTokenProgram: params.quoteTokenProgram,
|
|
69
|
+
creatorPlatform: params.creatorPlatform,
|
|
70
|
+
creatorId: params.creatorId,
|
|
71
|
+
creatorHash,
|
|
72
|
+
name: params.name,
|
|
73
|
+
symbol: params.symbol,
|
|
74
|
+
uri: params.uri,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function buildCreateAndBuyInstructions(
|
|
79
|
+
params: CreateAndBuyParams,
|
|
80
|
+
): Promise<{ instructions: Instruction[]; quote?: TradeQuote }> {
|
|
81
|
+
const creatorHash = await creatorHashFromId(
|
|
82
|
+
params.creatorPlatform,
|
|
83
|
+
params.creatorId,
|
|
84
|
+
);
|
|
85
|
+
const createIx = await buildCreateTokenInstructionWithHash(
|
|
86
|
+
params,
|
|
87
|
+
creatorHash,
|
|
88
|
+
);
|
|
89
|
+
const instructions: Instruction[] = [createIx];
|
|
90
|
+
let quote: TradeQuote | undefined;
|
|
91
|
+
|
|
92
|
+
if (params.buyQuoteAmount > 0n) {
|
|
93
|
+
const buyResult = await buyExactIn({
|
|
94
|
+
user: params.user,
|
|
95
|
+
payer: params.payer,
|
|
96
|
+
baseMint: params.baseMint.address,
|
|
97
|
+
quoteMint: params.quoteMint,
|
|
98
|
+
virtualQuoteReserves: params.initialVirtualQuoteReserves,
|
|
99
|
+
virtualBaseReserves: params.initialVirtualBaseReserves,
|
|
100
|
+
realBaseReserves: params.initialRealBaseReserves,
|
|
101
|
+
// The curve was just stamped with this same key.
|
|
102
|
+
platformConfig: params.platformConfig,
|
|
103
|
+
feeBps: params.feeBps,
|
|
104
|
+
slippageBps: params.slippageBps,
|
|
105
|
+
partner: params.partner,
|
|
106
|
+
quoteFee: params.quoteFee,
|
|
107
|
+
quoteTokenProgram: params.quoteTokenProgram,
|
|
108
|
+
quoteAmountIn: params.buyQuoteAmount,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
instructions.push(buyResult.instruction);
|
|
112
|
+
quote = buyResult.quote;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return { instructions, quote };
|
|
116
|
+
}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was AUTOGENERATED using the Codama library.
|
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
+
* to add features, then rerun Codama to update it.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/codama-idl/codama
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
assertAccountExists,
|
|
11
|
+
assertAccountsExist,
|
|
12
|
+
combineCodec,
|
|
13
|
+
containsBytes,
|
|
14
|
+
decodeAccount,
|
|
15
|
+
fetchEncodedAccount,
|
|
16
|
+
fetchEncodedAccounts,
|
|
17
|
+
fixDecoderSize,
|
|
18
|
+
fixEncoderSize,
|
|
19
|
+
getAddressDecoder,
|
|
20
|
+
getAddressEncoder,
|
|
21
|
+
getBytesDecoder,
|
|
22
|
+
getBytesEncoder,
|
|
23
|
+
getI64Decoder,
|
|
24
|
+
getI64Encoder,
|
|
25
|
+
getStructDecoder,
|
|
26
|
+
getStructEncoder,
|
|
27
|
+
getU64Decoder,
|
|
28
|
+
getU64Encoder,
|
|
29
|
+
getU8Decoder,
|
|
30
|
+
getU8Encoder,
|
|
31
|
+
transformEncoder,
|
|
32
|
+
type Account,
|
|
33
|
+
type Address,
|
|
34
|
+
type EncodedAccount,
|
|
35
|
+
type FetchAccountConfig,
|
|
36
|
+
type FetchAccountsConfig,
|
|
37
|
+
type FixedSizeCodec,
|
|
38
|
+
type FixedSizeDecoder,
|
|
39
|
+
type FixedSizeEncoder,
|
|
40
|
+
type MaybeAccount,
|
|
41
|
+
type MaybeEncodedAccount,
|
|
42
|
+
type ReadonlyUint8Array,
|
|
43
|
+
} from '@solana/kit';
|
|
44
|
+
import { SEND_LAUNCHPAD_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
45
|
+
import {
|
|
46
|
+
getBondingCurveStatusDecoder,
|
|
47
|
+
getBondingCurveStatusEncoder,
|
|
48
|
+
type BondingCurveStatus,
|
|
49
|
+
type BondingCurveStatusArgs,
|
|
50
|
+
} from '../types/index.js';
|
|
51
|
+
|
|
52
|
+
export const BONDING_CURVE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
|
|
53
|
+
23, 183, 248, 55, 96, 216, 172, 96,
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
export function getBondingCurveDiscriminatorBytes(): ReadonlyUint8Array {
|
|
57
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
58
|
+
BONDING_CURVE_DISCRIMINATOR,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type BondingCurve = {
|
|
63
|
+
discriminator: ReadonlyUint8Array;
|
|
64
|
+
version: number;
|
|
65
|
+
bump: number;
|
|
66
|
+
status: BondingCurveStatus;
|
|
67
|
+
baseMint: Address;
|
|
68
|
+
baseDecimals: number;
|
|
69
|
+
baseSupply: bigint;
|
|
70
|
+
initialVirtualBase: bigint;
|
|
71
|
+
initialVirtualQuote: bigint;
|
|
72
|
+
initialRealBase: bigint;
|
|
73
|
+
quoteMint: Address;
|
|
74
|
+
quoteDecimals: number;
|
|
75
|
+
coinCreator: Address;
|
|
76
|
+
creatorFeeConfig: Address;
|
|
77
|
+
partner: Address;
|
|
78
|
+
baseVault: Address;
|
|
79
|
+
quoteVault: Address;
|
|
80
|
+
virtualBaseReserves: bigint;
|
|
81
|
+
virtualQuoteReserves: bigint;
|
|
82
|
+
realBaseReserves: bigint;
|
|
83
|
+
realQuoteReserves: bigint;
|
|
84
|
+
createdAt: bigint;
|
|
85
|
+
protocolOwed: bigint;
|
|
86
|
+
creatorOwed: bigint;
|
|
87
|
+
platformConfig: Address;
|
|
88
|
+
reserved: ReadonlyUint8Array;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export type BondingCurveArgs = {
|
|
92
|
+
version: number;
|
|
93
|
+
bump: number;
|
|
94
|
+
status: BondingCurveStatusArgs;
|
|
95
|
+
baseMint: Address;
|
|
96
|
+
baseDecimals: number;
|
|
97
|
+
baseSupply: number | bigint;
|
|
98
|
+
initialVirtualBase: number | bigint;
|
|
99
|
+
initialVirtualQuote: number | bigint;
|
|
100
|
+
initialRealBase: number | bigint;
|
|
101
|
+
quoteMint: Address;
|
|
102
|
+
quoteDecimals: number;
|
|
103
|
+
coinCreator: Address;
|
|
104
|
+
creatorFeeConfig: Address;
|
|
105
|
+
partner: Address;
|
|
106
|
+
baseVault: Address;
|
|
107
|
+
quoteVault: Address;
|
|
108
|
+
virtualBaseReserves: number | bigint;
|
|
109
|
+
virtualQuoteReserves: number | bigint;
|
|
110
|
+
realBaseReserves: number | bigint;
|
|
111
|
+
realQuoteReserves: number | bigint;
|
|
112
|
+
createdAt: number | bigint;
|
|
113
|
+
protocolOwed: number | bigint;
|
|
114
|
+
creatorOwed: number | bigint;
|
|
115
|
+
platformConfig: Address;
|
|
116
|
+
reserved: ReadonlyUint8Array;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/** Gets the encoder for {@link BondingCurveArgs} account data. */
|
|
120
|
+
export function getBondingCurveEncoder(): FixedSizeEncoder<BondingCurveArgs> {
|
|
121
|
+
return transformEncoder(
|
|
122
|
+
getStructEncoder([
|
|
123
|
+
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
|
|
124
|
+
['version', getU8Encoder()],
|
|
125
|
+
['bump', getU8Encoder()],
|
|
126
|
+
['status', getBondingCurveStatusEncoder()],
|
|
127
|
+
['baseMint', getAddressEncoder()],
|
|
128
|
+
['baseDecimals', getU8Encoder()],
|
|
129
|
+
['baseSupply', getU64Encoder()],
|
|
130
|
+
['initialVirtualBase', getU64Encoder()],
|
|
131
|
+
['initialVirtualQuote', getU64Encoder()],
|
|
132
|
+
['initialRealBase', getU64Encoder()],
|
|
133
|
+
['quoteMint', getAddressEncoder()],
|
|
134
|
+
['quoteDecimals', getU8Encoder()],
|
|
135
|
+
['coinCreator', getAddressEncoder()],
|
|
136
|
+
['creatorFeeConfig', getAddressEncoder()],
|
|
137
|
+
['partner', getAddressEncoder()],
|
|
138
|
+
['baseVault', getAddressEncoder()],
|
|
139
|
+
['quoteVault', getAddressEncoder()],
|
|
140
|
+
['virtualBaseReserves', getU64Encoder()],
|
|
141
|
+
['virtualQuoteReserves', getU64Encoder()],
|
|
142
|
+
['realBaseReserves', getU64Encoder()],
|
|
143
|
+
['realQuoteReserves', getU64Encoder()],
|
|
144
|
+
['createdAt', getI64Encoder()],
|
|
145
|
+
['protocolOwed', getU64Encoder()],
|
|
146
|
+
['creatorOwed', getU64Encoder()],
|
|
147
|
+
['platformConfig', getAddressEncoder()],
|
|
148
|
+
['reserved', fixEncoderSize(getBytesEncoder(), 64)],
|
|
149
|
+
]),
|
|
150
|
+
(value) => ({ ...value, discriminator: BONDING_CURVE_DISCRIMINATOR }),
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Gets the decoder for {@link BondingCurve} account data. */
|
|
155
|
+
export function getBondingCurveDecoder(): FixedSizeDecoder<BondingCurve> {
|
|
156
|
+
return getStructDecoder([
|
|
157
|
+
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
|
|
158
|
+
['version', getU8Decoder()],
|
|
159
|
+
['bump', getU8Decoder()],
|
|
160
|
+
['status', getBondingCurveStatusDecoder()],
|
|
161
|
+
['baseMint', getAddressDecoder()],
|
|
162
|
+
['baseDecimals', getU8Decoder()],
|
|
163
|
+
['baseSupply', getU64Decoder()],
|
|
164
|
+
['initialVirtualBase', getU64Decoder()],
|
|
165
|
+
['initialVirtualQuote', getU64Decoder()],
|
|
166
|
+
['initialRealBase', getU64Decoder()],
|
|
167
|
+
['quoteMint', getAddressDecoder()],
|
|
168
|
+
['quoteDecimals', getU8Decoder()],
|
|
169
|
+
['coinCreator', getAddressDecoder()],
|
|
170
|
+
['creatorFeeConfig', getAddressDecoder()],
|
|
171
|
+
['partner', getAddressDecoder()],
|
|
172
|
+
['baseVault', getAddressDecoder()],
|
|
173
|
+
['quoteVault', getAddressDecoder()],
|
|
174
|
+
['virtualBaseReserves', getU64Decoder()],
|
|
175
|
+
['virtualQuoteReserves', getU64Decoder()],
|
|
176
|
+
['realBaseReserves', getU64Decoder()],
|
|
177
|
+
['realQuoteReserves', getU64Decoder()],
|
|
178
|
+
['createdAt', getI64Decoder()],
|
|
179
|
+
['protocolOwed', getU64Decoder()],
|
|
180
|
+
['creatorOwed', getU64Decoder()],
|
|
181
|
+
['platformConfig', getAddressDecoder()],
|
|
182
|
+
['reserved', fixDecoderSize(getBytesDecoder(), 64)],
|
|
183
|
+
]);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Gets the codec for {@link BondingCurve} account data. */
|
|
187
|
+
export function getBondingCurveCodec(): FixedSizeCodec<
|
|
188
|
+
BondingCurveArgs,
|
|
189
|
+
BondingCurve
|
|
190
|
+
> {
|
|
191
|
+
return combineCodec(getBondingCurveEncoder(), getBondingCurveDecoder());
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function decodeBondingCurve<TAddress extends string = string>(
|
|
195
|
+
encodedAccount: EncodedAccount<TAddress>,
|
|
196
|
+
): Account<BondingCurve, TAddress>;
|
|
197
|
+
export function decodeBondingCurve<TAddress extends string = string>(
|
|
198
|
+
encodedAccount: MaybeEncodedAccount<TAddress>,
|
|
199
|
+
): MaybeAccount<BondingCurve, TAddress>;
|
|
200
|
+
export function decodeBondingCurve<TAddress extends string = string>(
|
|
201
|
+
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
|
|
202
|
+
): Account<BondingCurve, TAddress> | MaybeAccount<BondingCurve, TAddress> {
|
|
203
|
+
if (!('exists' in encodedAccount) || encodedAccount.exists) {
|
|
204
|
+
if (encodedAccount.programAddress !== SEND_LAUNCHPAD_PROGRAM_ADDRESS) {
|
|
205
|
+
const error = new Error(
|
|
206
|
+
`decodeBondingCurve: account ${encodedAccount.address} is owned by ${encodedAccount.programAddress}, expected ${SEND_LAUNCHPAD_PROGRAM_ADDRESS}`,
|
|
207
|
+
);
|
|
208
|
+
error.name = 'AccountOwnerMismatchError';
|
|
209
|
+
throw error;
|
|
210
|
+
}
|
|
211
|
+
if (
|
|
212
|
+
!containsBytes(encodedAccount.data, BONDING_CURVE_DISCRIMINATOR, 0)
|
|
213
|
+
) {
|
|
214
|
+
const error = new Error(
|
|
215
|
+
`decodeBondingCurve: account ${encodedAccount.address} does not match the BondingCurve discriminator`,
|
|
216
|
+
);
|
|
217
|
+
error.name = 'AccountDiscriminatorMismatchError';
|
|
218
|
+
throw error;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return decodeAccount(
|
|
222
|
+
encodedAccount as MaybeEncodedAccount<TAddress>,
|
|
223
|
+
getBondingCurveDecoder(),
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export async function fetchBondingCurve<TAddress extends string = string>(
|
|
228
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
229
|
+
address: Address<TAddress>,
|
|
230
|
+
config?: FetchAccountConfig,
|
|
231
|
+
): Promise<Account<BondingCurve, TAddress>> {
|
|
232
|
+
const maybeAccount = await fetchMaybeBondingCurve(rpc, address, config);
|
|
233
|
+
assertAccountExists(maybeAccount);
|
|
234
|
+
return maybeAccount;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export async function fetchMaybeBondingCurve<TAddress extends string = string>(
|
|
238
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
239
|
+
address: Address<TAddress>,
|
|
240
|
+
config?: FetchAccountConfig,
|
|
241
|
+
): Promise<MaybeAccount<BondingCurve, TAddress>> {
|
|
242
|
+
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
243
|
+
return decodeBondingCurve(maybeAccount);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export async function fetchAllBondingCurve(
|
|
247
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
248
|
+
addresses: Array<Address>,
|
|
249
|
+
config?: FetchAccountsConfig,
|
|
250
|
+
): Promise<Account<BondingCurve>[]> {
|
|
251
|
+
const maybeAccounts = await fetchAllMaybeBondingCurve(
|
|
252
|
+
rpc,
|
|
253
|
+
addresses,
|
|
254
|
+
config,
|
|
255
|
+
);
|
|
256
|
+
assertAccountsExist(maybeAccounts);
|
|
257
|
+
return maybeAccounts;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export async function fetchAllMaybeBondingCurve(
|
|
261
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
262
|
+
addresses: Array<Address>,
|
|
263
|
+
config?: FetchAccountsConfig,
|
|
264
|
+
): Promise<MaybeAccount<BondingCurve>[]> {
|
|
265
|
+
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
266
|
+
return maybeAccounts.map((maybeAccount) =>
|
|
267
|
+
decodeBondingCurve(maybeAccount),
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export function getBondingCurveSize(): number {
|
|
272
|
+
return 421;
|
|
273
|
+
}
|