@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,128 @@
|
|
|
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
|
+
containsBytes,
|
|
11
|
+
fixEncoderSize,
|
|
12
|
+
getAddressDecoder,
|
|
13
|
+
getBytesEncoder,
|
|
14
|
+
getI64Decoder,
|
|
15
|
+
getStructDecoder,
|
|
16
|
+
getU64Decoder,
|
|
17
|
+
getU8Decoder,
|
|
18
|
+
type Address,
|
|
19
|
+
type FixedSizeDecoder,
|
|
20
|
+
type ReadonlyUint8Array,
|
|
21
|
+
} from '@solana/kit';
|
|
22
|
+
import { SEND_DEX_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
23
|
+
import { ANCHOR_EVENT_CPI_DISCRIMINATOR } from './anchorEventCpiDiscriminator.framing.js';
|
|
24
|
+
|
|
25
|
+
export const POOL_CREATE_EVENT_DISCRIMINATOR: ReadonlyUint8Array =
|
|
26
|
+
new Uint8Array([151, 215, 226, 9, 118, 161, 115, 174]);
|
|
27
|
+
|
|
28
|
+
export function getPoolCreateEventDiscriminatorBytes(): ReadonlyUint8Array {
|
|
29
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
30
|
+
POOL_CREATE_EVENT_DISCRIMINATOR,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type PoolCreateEvent = {
|
|
35
|
+
pool: Address;
|
|
36
|
+
baseMint: Address;
|
|
37
|
+
baseDecimals: number;
|
|
38
|
+
quoteMint: Address;
|
|
39
|
+
quoteDecimals: number;
|
|
40
|
+
coinCreator: Address;
|
|
41
|
+
creatorFeeConfig: Address;
|
|
42
|
+
platformConfig: Address;
|
|
43
|
+
baseVault: Address;
|
|
44
|
+
quoteVault: Address;
|
|
45
|
+
lpMint: Address;
|
|
46
|
+
lpMinted: bigint;
|
|
47
|
+
baseReserves: bigint;
|
|
48
|
+
quoteReserves: bigint;
|
|
49
|
+
timestamp: bigint;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
let getPoolCreateEventDecoderCache:
|
|
53
|
+
| FixedSizeDecoder<PoolCreateEvent>
|
|
54
|
+
| undefined;
|
|
55
|
+
|
|
56
|
+
export function getPoolCreateEventDecoder(): FixedSizeDecoder<PoolCreateEvent> {
|
|
57
|
+
return (getPoolCreateEventDecoderCache ??= getStructDecoder([
|
|
58
|
+
['pool', getAddressDecoder()],
|
|
59
|
+
['baseMint', getAddressDecoder()],
|
|
60
|
+
['baseDecimals', getU8Decoder()],
|
|
61
|
+
['quoteMint', getAddressDecoder()],
|
|
62
|
+
['quoteDecimals', getU8Decoder()],
|
|
63
|
+
['coinCreator', getAddressDecoder()],
|
|
64
|
+
['creatorFeeConfig', getAddressDecoder()],
|
|
65
|
+
['platformConfig', getAddressDecoder()],
|
|
66
|
+
['baseVault', getAddressDecoder()],
|
|
67
|
+
['quoteVault', getAddressDecoder()],
|
|
68
|
+
['lpMint', getAddressDecoder()],
|
|
69
|
+
['lpMinted', getU64Decoder()],
|
|
70
|
+
['baseReserves', getU64Decoder()],
|
|
71
|
+
['quoteReserves', getU64Decoder()],
|
|
72
|
+
['timestamp', getI64Decoder()],
|
|
73
|
+
]));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Checks whether the event data matches the framing and discriminator bytes of a
|
|
78
|
+
* {@link PoolCreateEvent}, without decoding. Never throws.
|
|
79
|
+
*
|
|
80
|
+
* Returns `false` unless `event.programAddress` is SEND_DEX_PROGRAM_ADDRESS.
|
|
81
|
+
* Raw bytes carry no emitter and SKIP that check.
|
|
82
|
+
*
|
|
83
|
+
* @see parsePoolCreateEvent to decode the matching data
|
|
84
|
+
*/
|
|
85
|
+
export function isPoolCreateEvent(
|
|
86
|
+
event:
|
|
87
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
88
|
+
| ReadonlyUint8Array,
|
|
89
|
+
): boolean {
|
|
90
|
+
if ('data' in event && event.programAddress !== SEND_DEX_PROGRAM_ADDRESS)
|
|
91
|
+
return false;
|
|
92
|
+
const data = 'data' in event ? event.data : event;
|
|
93
|
+
return (
|
|
94
|
+
containsBytes(data, ANCHOR_EVENT_CPI_DISCRIMINATOR, 0) &&
|
|
95
|
+
containsBytes(data, POOL_CREATE_EVENT_DISCRIMINATOR, 8)
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Parses raw event data as a {@link PoolCreateEvent}. Returns `null` on framing or discriminator
|
|
101
|
+
* mismatch; throws if the event matches but its body fails to decode.
|
|
102
|
+
*
|
|
103
|
+
* Returns `null` unless `event.programAddress` is SEND_DEX_PROGRAM_ADDRESS.
|
|
104
|
+
* Raw bytes carry no emitter and SKIP that check.
|
|
105
|
+
*
|
|
106
|
+
* @see isPoolCreateEvent to check without decoding
|
|
107
|
+
* @see identifySendDexEvent to identify any program event
|
|
108
|
+
* @see parseSendDexEvent
|
|
109
|
+
*/
|
|
110
|
+
export function parsePoolCreateEvent(
|
|
111
|
+
event:
|
|
112
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
113
|
+
| ReadonlyUint8Array,
|
|
114
|
+
): PoolCreateEvent | null {
|
|
115
|
+
const checkedEvent =
|
|
116
|
+
'data' in event
|
|
117
|
+
? { data: event.data, programAddress: event.programAddress }
|
|
118
|
+
: event;
|
|
119
|
+
if (!isPoolCreateEvent(checkedEvent)) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
const data = 'data' in checkedEvent ? checkedEvent.data : checkedEvent;
|
|
123
|
+
return getPoolCreateEventDecoder().decode(
|
|
124
|
+
data,
|
|
125
|
+
ANCHOR_EVENT_CPI_DISCRIMINATOR.length +
|
|
126
|
+
POOL_CREATE_EVENT_DISCRIMINATOR.length,
|
|
127
|
+
);
|
|
128
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
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
|
+
containsBytes,
|
|
11
|
+
fixEncoderSize,
|
|
12
|
+
getAddressDecoder,
|
|
13
|
+
getBytesEncoder,
|
|
14
|
+
getI64Decoder,
|
|
15
|
+
getStructDecoder,
|
|
16
|
+
getU64Decoder,
|
|
17
|
+
type Address,
|
|
18
|
+
type FixedSizeDecoder,
|
|
19
|
+
type ReadonlyUint8Array,
|
|
20
|
+
} from '@solana/kit';
|
|
21
|
+
import { SEND_DEX_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
22
|
+
import { ANCHOR_EVENT_CPI_DISCRIMINATOR } from './anchorEventCpiDiscriminator.framing.js';
|
|
23
|
+
|
|
24
|
+
export const PROTOCOL_CLAIM_EVENT_DISCRIMINATOR: ReadonlyUint8Array =
|
|
25
|
+
new Uint8Array([149, 70, 119, 5, 21, 57, 123, 244]);
|
|
26
|
+
|
|
27
|
+
export function getProtocolClaimEventDiscriminatorBytes(): ReadonlyUint8Array {
|
|
28
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
29
|
+
PROTOCOL_CLAIM_EVENT_DISCRIMINATOR,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type ProtocolClaimEvent = {
|
|
34
|
+
pool: Address;
|
|
35
|
+
baseMint: Address;
|
|
36
|
+
quoteMint: Address;
|
|
37
|
+
platformConfig: Address;
|
|
38
|
+
amount: bigint;
|
|
39
|
+
quoteTransferFee: bigint;
|
|
40
|
+
timestamp: bigint;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
let getProtocolClaimEventDecoderCache:
|
|
44
|
+
| FixedSizeDecoder<ProtocolClaimEvent>
|
|
45
|
+
| undefined;
|
|
46
|
+
|
|
47
|
+
export function getProtocolClaimEventDecoder(): FixedSizeDecoder<ProtocolClaimEvent> {
|
|
48
|
+
return (getProtocolClaimEventDecoderCache ??= getStructDecoder([
|
|
49
|
+
['pool', getAddressDecoder()],
|
|
50
|
+
['baseMint', getAddressDecoder()],
|
|
51
|
+
['quoteMint', getAddressDecoder()],
|
|
52
|
+
['platformConfig', getAddressDecoder()],
|
|
53
|
+
['amount', getU64Decoder()],
|
|
54
|
+
['quoteTransferFee', getU64Decoder()],
|
|
55
|
+
['timestamp', getI64Decoder()],
|
|
56
|
+
]));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Checks whether the event data matches the framing and discriminator bytes of a
|
|
61
|
+
* {@link ProtocolClaimEvent}, without decoding. Never throws.
|
|
62
|
+
*
|
|
63
|
+
* Returns `false` unless `event.programAddress` is SEND_DEX_PROGRAM_ADDRESS.
|
|
64
|
+
* Raw bytes carry no emitter and SKIP that check.
|
|
65
|
+
*
|
|
66
|
+
* @see parseProtocolClaimEvent to decode the matching data
|
|
67
|
+
*/
|
|
68
|
+
export function isProtocolClaimEvent(
|
|
69
|
+
event:
|
|
70
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
71
|
+
| ReadonlyUint8Array,
|
|
72
|
+
): boolean {
|
|
73
|
+
if ('data' in event && event.programAddress !== SEND_DEX_PROGRAM_ADDRESS)
|
|
74
|
+
return false;
|
|
75
|
+
const data = 'data' in event ? event.data : event;
|
|
76
|
+
return (
|
|
77
|
+
containsBytes(data, ANCHOR_EVENT_CPI_DISCRIMINATOR, 0) &&
|
|
78
|
+
containsBytes(data, PROTOCOL_CLAIM_EVENT_DISCRIMINATOR, 8)
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Parses raw event data as a {@link ProtocolClaimEvent}. Returns `null` on framing or discriminator
|
|
84
|
+
* mismatch; throws if the event matches but its body fails to decode.
|
|
85
|
+
*
|
|
86
|
+
* Returns `null` unless `event.programAddress` is SEND_DEX_PROGRAM_ADDRESS.
|
|
87
|
+
* Raw bytes carry no emitter and SKIP that check.
|
|
88
|
+
*
|
|
89
|
+
* @see isProtocolClaimEvent to check without decoding
|
|
90
|
+
* @see identifySendDexEvent to identify any program event
|
|
91
|
+
* @see parseSendDexEvent
|
|
92
|
+
*/
|
|
93
|
+
export function parseProtocolClaimEvent(
|
|
94
|
+
event:
|
|
95
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
96
|
+
| ReadonlyUint8Array,
|
|
97
|
+
): ProtocolClaimEvent | null {
|
|
98
|
+
const checkedEvent =
|
|
99
|
+
'data' in event
|
|
100
|
+
? { data: event.data, programAddress: event.programAddress }
|
|
101
|
+
: event;
|
|
102
|
+
if (!isProtocolClaimEvent(checkedEvent)) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
const data = 'data' in checkedEvent ? checkedEvent.data : checkedEvent;
|
|
106
|
+
return getProtocolClaimEventDecoder().decode(
|
|
107
|
+
data,
|
|
108
|
+
ANCHOR_EVENT_CPI_DISCRIMINATOR.length +
|
|
109
|
+
PROTOCOL_CLAIM_EVENT_DISCRIMINATOR.length,
|
|
110
|
+
);
|
|
111
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
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
|
+
containsBytes,
|
|
11
|
+
type Address,
|
|
12
|
+
type ReadonlyUint8Array,
|
|
13
|
+
} from '@solana/kit';
|
|
14
|
+
import { SEND_DEX_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
15
|
+
import { ANCHOR_EVENT_CPI_DISCRIMINATOR } from './anchorEventCpiDiscriminator.framing.js';
|
|
16
|
+
import {
|
|
17
|
+
CREATOR_CLAIM_EVENT_DISCRIMINATOR,
|
|
18
|
+
getCreatorClaimEventDecoder,
|
|
19
|
+
type CreatorClaimEvent,
|
|
20
|
+
} from './creatorClaimEvent.js';
|
|
21
|
+
import {
|
|
22
|
+
DEPOSIT_QUOTE_EVENT_DISCRIMINATOR,
|
|
23
|
+
getDepositQuoteEventDecoder,
|
|
24
|
+
type DepositQuoteEvent,
|
|
25
|
+
} from './depositQuoteEvent.js';
|
|
26
|
+
import {
|
|
27
|
+
getPoolCreateEventDecoder,
|
|
28
|
+
POOL_CREATE_EVENT_DISCRIMINATOR,
|
|
29
|
+
type PoolCreateEvent,
|
|
30
|
+
} from './poolCreateEvent.js';
|
|
31
|
+
import {
|
|
32
|
+
getProtocolClaimEventDecoder,
|
|
33
|
+
PROTOCOL_CLAIM_EVENT_DISCRIMINATOR,
|
|
34
|
+
type ProtocolClaimEvent,
|
|
35
|
+
} from './protocolClaimEvent.js';
|
|
36
|
+
import {
|
|
37
|
+
getTokenCreateEventDecoder,
|
|
38
|
+
TOKEN_CREATE_EVENT_DISCRIMINATOR,
|
|
39
|
+
type TokenCreateEvent,
|
|
40
|
+
} from './tokenCreateEvent.js';
|
|
41
|
+
import {
|
|
42
|
+
getTradeEventDecoder,
|
|
43
|
+
TRADE_EVENT_DISCRIMINATOR,
|
|
44
|
+
type TradeEvent,
|
|
45
|
+
} from './tradeEvent.js';
|
|
46
|
+
|
|
47
|
+
/** Event kinds of the sendDex program. */
|
|
48
|
+
export type SendDexEventType =
|
|
49
|
+
| 'creatorClaimEvent'
|
|
50
|
+
| 'depositQuoteEvent'
|
|
51
|
+
| 'poolCreateEvent'
|
|
52
|
+
| 'protocolClaimEvent'
|
|
53
|
+
| 'tokenCreateEvent'
|
|
54
|
+
| 'tradeEvent';
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Identifies sendDex event data by its discriminators, without decoding.
|
|
58
|
+
* Returns `null` when the event was emitted by another program or no known event matches.
|
|
59
|
+
* Never throws.
|
|
60
|
+
*
|
|
61
|
+
* Raw bytes carry no emitter and SKIP the program check.
|
|
62
|
+
*/
|
|
63
|
+
export function identifySendDexEvent(
|
|
64
|
+
event:
|
|
65
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
66
|
+
| ReadonlyUint8Array,
|
|
67
|
+
): SendDexEventType | null {
|
|
68
|
+
if ('data' in event && event.programAddress !== SEND_DEX_PROGRAM_ADDRESS)
|
|
69
|
+
return null;
|
|
70
|
+
const data = 'data' in event ? event.data : event;
|
|
71
|
+
if (containsBytes(data, ANCHOR_EVENT_CPI_DISCRIMINATOR, 0)) {
|
|
72
|
+
if (containsBytes(data, CREATOR_CLAIM_EVENT_DISCRIMINATOR, 8)) {
|
|
73
|
+
return 'creatorClaimEvent';
|
|
74
|
+
}
|
|
75
|
+
if (containsBytes(data, DEPOSIT_QUOTE_EVENT_DISCRIMINATOR, 8)) {
|
|
76
|
+
return 'depositQuoteEvent';
|
|
77
|
+
}
|
|
78
|
+
if (containsBytes(data, POOL_CREATE_EVENT_DISCRIMINATOR, 8)) {
|
|
79
|
+
return 'poolCreateEvent';
|
|
80
|
+
}
|
|
81
|
+
if (containsBytes(data, PROTOCOL_CLAIM_EVENT_DISCRIMINATOR, 8)) {
|
|
82
|
+
return 'protocolClaimEvent';
|
|
83
|
+
}
|
|
84
|
+
if (containsBytes(data, TOKEN_CREATE_EVENT_DISCRIMINATOR, 8)) {
|
|
85
|
+
return 'tokenCreateEvent';
|
|
86
|
+
}
|
|
87
|
+
if (containsBytes(data, TRADE_EVENT_DISCRIMINATOR, 8)) {
|
|
88
|
+
return 'tradeEvent';
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Parsed sendDex event: the event kind tag plus its decoded payload. */
|
|
95
|
+
export type ParsedSendDexEvent =
|
|
96
|
+
| { eventType: 'creatorClaimEvent'; data: CreatorClaimEvent }
|
|
97
|
+
| { eventType: 'depositQuoteEvent'; data: DepositQuoteEvent }
|
|
98
|
+
| { eventType: 'poolCreateEvent'; data: PoolCreateEvent }
|
|
99
|
+
| { eventType: 'protocolClaimEvent'; data: ProtocolClaimEvent }
|
|
100
|
+
| { eventType: 'tokenCreateEvent'; data: TokenCreateEvent }
|
|
101
|
+
| { eventType: 'tradeEvent'; data: TradeEvent };
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Parses sendDex event data into its event kind and decoded payload.
|
|
105
|
+
* Returns `null` when the event was emitted by another program or no known event matches;
|
|
106
|
+
* throws if a matched event fails to decode.
|
|
107
|
+
*
|
|
108
|
+
* Raw bytes carry no emitter and SKIP the program check.
|
|
109
|
+
*/
|
|
110
|
+
export function parseSendDexEvent(
|
|
111
|
+
event:
|
|
112
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
113
|
+
| ReadonlyUint8Array,
|
|
114
|
+
): ParsedSendDexEvent | null {
|
|
115
|
+
const checkedEvent =
|
|
116
|
+
'data' in event
|
|
117
|
+
? { data: event.data, programAddress: event.programAddress }
|
|
118
|
+
: event;
|
|
119
|
+
const eventType = identifySendDexEvent(checkedEvent);
|
|
120
|
+
if (eventType === null) return null;
|
|
121
|
+
const data = 'data' in checkedEvent ? checkedEvent.data : checkedEvent;
|
|
122
|
+
switch (eventType) {
|
|
123
|
+
case 'creatorClaimEvent': {
|
|
124
|
+
return {
|
|
125
|
+
eventType: 'creatorClaimEvent',
|
|
126
|
+
data: getCreatorClaimEventDecoder().decode(
|
|
127
|
+
data,
|
|
128
|
+
ANCHOR_EVENT_CPI_DISCRIMINATOR.length +
|
|
129
|
+
CREATOR_CLAIM_EVENT_DISCRIMINATOR.length,
|
|
130
|
+
),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
case 'depositQuoteEvent': {
|
|
134
|
+
return {
|
|
135
|
+
eventType: 'depositQuoteEvent',
|
|
136
|
+
data: getDepositQuoteEventDecoder().decode(
|
|
137
|
+
data,
|
|
138
|
+
ANCHOR_EVENT_CPI_DISCRIMINATOR.length +
|
|
139
|
+
DEPOSIT_QUOTE_EVENT_DISCRIMINATOR.length,
|
|
140
|
+
),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
case 'poolCreateEvent': {
|
|
144
|
+
return {
|
|
145
|
+
eventType: 'poolCreateEvent',
|
|
146
|
+
data: getPoolCreateEventDecoder().decode(
|
|
147
|
+
data,
|
|
148
|
+
ANCHOR_EVENT_CPI_DISCRIMINATOR.length +
|
|
149
|
+
POOL_CREATE_EVENT_DISCRIMINATOR.length,
|
|
150
|
+
),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
case 'protocolClaimEvent': {
|
|
154
|
+
return {
|
|
155
|
+
eventType: 'protocolClaimEvent',
|
|
156
|
+
data: getProtocolClaimEventDecoder().decode(
|
|
157
|
+
data,
|
|
158
|
+
ANCHOR_EVENT_CPI_DISCRIMINATOR.length +
|
|
159
|
+
PROTOCOL_CLAIM_EVENT_DISCRIMINATOR.length,
|
|
160
|
+
),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
case 'tokenCreateEvent': {
|
|
164
|
+
return {
|
|
165
|
+
eventType: 'tokenCreateEvent',
|
|
166
|
+
data: getTokenCreateEventDecoder().decode(
|
|
167
|
+
data,
|
|
168
|
+
ANCHOR_EVENT_CPI_DISCRIMINATOR.length +
|
|
169
|
+
TOKEN_CREATE_EVENT_DISCRIMINATOR.length,
|
|
170
|
+
),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
case 'tradeEvent': {
|
|
174
|
+
return {
|
|
175
|
+
eventType: 'tradeEvent',
|
|
176
|
+
data: getTradeEventDecoder().decode(
|
|
177
|
+
data,
|
|
178
|
+
ANCHOR_EVENT_CPI_DISCRIMINATOR.length +
|
|
179
|
+
TRADE_EVENT_DISCRIMINATOR.length,
|
|
180
|
+
),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
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
|
+
addDecoderSizePrefix,
|
|
11
|
+
containsBytes,
|
|
12
|
+
fixEncoderSize,
|
|
13
|
+
getAddressDecoder,
|
|
14
|
+
getBooleanDecoder,
|
|
15
|
+
getBytesEncoder,
|
|
16
|
+
getI64Decoder,
|
|
17
|
+
getStructDecoder,
|
|
18
|
+
getU32Decoder,
|
|
19
|
+
getU64Decoder,
|
|
20
|
+
getU8Decoder,
|
|
21
|
+
getUtf8Decoder,
|
|
22
|
+
type Address,
|
|
23
|
+
type Decoder,
|
|
24
|
+
type ReadonlyUint8Array,
|
|
25
|
+
} from '@solana/kit';
|
|
26
|
+
import { SEND_DEX_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
27
|
+
import { ANCHOR_EVENT_CPI_DISCRIMINATOR } from './anchorEventCpiDiscriminator.framing.js';
|
|
28
|
+
|
|
29
|
+
export const TOKEN_CREATE_EVENT_DISCRIMINATOR: ReadonlyUint8Array =
|
|
30
|
+
new Uint8Array([152, 16, 194, 59, 171, 105, 172, 45]);
|
|
31
|
+
|
|
32
|
+
export function getTokenCreateEventDiscriminatorBytes(): ReadonlyUint8Array {
|
|
33
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
34
|
+
TOKEN_CREATE_EVENT_DISCRIMINATOR,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type TokenCreateEvent = {
|
|
39
|
+
pool: Address;
|
|
40
|
+
baseMint: Address;
|
|
41
|
+
baseDecimals: number;
|
|
42
|
+
baseSupply: bigint;
|
|
43
|
+
quoteMint: Address;
|
|
44
|
+
quoteDecimals: number;
|
|
45
|
+
coinCreator: Address;
|
|
46
|
+
creatorPlatform: string;
|
|
47
|
+
creatorId: string;
|
|
48
|
+
creatorFeeConfig: Address;
|
|
49
|
+
platformConfig: Address;
|
|
50
|
+
name: string;
|
|
51
|
+
symbol: string;
|
|
52
|
+
uri: string;
|
|
53
|
+
partner: Address;
|
|
54
|
+
isPartner: boolean;
|
|
55
|
+
creationFee: bigint;
|
|
56
|
+
baseReserves: bigint;
|
|
57
|
+
quoteReserves: bigint;
|
|
58
|
+
timestamp: bigint;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
let getTokenCreateEventDecoderCache: Decoder<TokenCreateEvent> | undefined;
|
|
62
|
+
|
|
63
|
+
export function getTokenCreateEventDecoder(): Decoder<TokenCreateEvent> {
|
|
64
|
+
return (getTokenCreateEventDecoderCache ??= getStructDecoder([
|
|
65
|
+
['pool', getAddressDecoder()],
|
|
66
|
+
['baseMint', getAddressDecoder()],
|
|
67
|
+
['baseDecimals', getU8Decoder()],
|
|
68
|
+
['baseSupply', getU64Decoder()],
|
|
69
|
+
['quoteMint', getAddressDecoder()],
|
|
70
|
+
['quoteDecimals', getU8Decoder()],
|
|
71
|
+
['coinCreator', getAddressDecoder()],
|
|
72
|
+
[
|
|
73
|
+
'creatorPlatform',
|
|
74
|
+
addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder()),
|
|
75
|
+
],
|
|
76
|
+
['creatorId', addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
|
|
77
|
+
['creatorFeeConfig', getAddressDecoder()],
|
|
78
|
+
['platformConfig', getAddressDecoder()],
|
|
79
|
+
['name', addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
|
|
80
|
+
['symbol', addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
|
|
81
|
+
['uri', addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
|
|
82
|
+
['partner', getAddressDecoder()],
|
|
83
|
+
['isPartner', getBooleanDecoder()],
|
|
84
|
+
['creationFee', getU64Decoder()],
|
|
85
|
+
['baseReserves', getU64Decoder()],
|
|
86
|
+
['quoteReserves', getU64Decoder()],
|
|
87
|
+
['timestamp', getI64Decoder()],
|
|
88
|
+
]));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Checks whether the event data matches the framing and discriminator bytes of a
|
|
93
|
+
* {@link TokenCreateEvent}, without decoding. Never throws.
|
|
94
|
+
*
|
|
95
|
+
* Returns `false` unless `event.programAddress` is SEND_DEX_PROGRAM_ADDRESS.
|
|
96
|
+
* Raw bytes carry no emitter and SKIP that check.
|
|
97
|
+
*
|
|
98
|
+
* @see parseTokenCreateEvent to decode the matching data
|
|
99
|
+
*/
|
|
100
|
+
export function isTokenCreateEvent(
|
|
101
|
+
event:
|
|
102
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
103
|
+
| ReadonlyUint8Array,
|
|
104
|
+
): boolean {
|
|
105
|
+
if ('data' in event && event.programAddress !== SEND_DEX_PROGRAM_ADDRESS)
|
|
106
|
+
return false;
|
|
107
|
+
const data = 'data' in event ? event.data : event;
|
|
108
|
+
return (
|
|
109
|
+
containsBytes(data, ANCHOR_EVENT_CPI_DISCRIMINATOR, 0) &&
|
|
110
|
+
containsBytes(data, TOKEN_CREATE_EVENT_DISCRIMINATOR, 8)
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Parses raw event data as a {@link TokenCreateEvent}. Returns `null` on framing or discriminator
|
|
116
|
+
* mismatch; throws if the event matches but its body fails to decode.
|
|
117
|
+
*
|
|
118
|
+
* Returns `null` unless `event.programAddress` is SEND_DEX_PROGRAM_ADDRESS.
|
|
119
|
+
* Raw bytes carry no emitter and SKIP that check.
|
|
120
|
+
*
|
|
121
|
+
* @see isTokenCreateEvent to check without decoding
|
|
122
|
+
* @see identifySendDexEvent to identify any program event
|
|
123
|
+
* @see parseSendDexEvent
|
|
124
|
+
*/
|
|
125
|
+
export function parseTokenCreateEvent(
|
|
126
|
+
event:
|
|
127
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
128
|
+
| ReadonlyUint8Array,
|
|
129
|
+
): TokenCreateEvent | null {
|
|
130
|
+
const checkedEvent =
|
|
131
|
+
'data' in event
|
|
132
|
+
? { data: event.data, programAddress: event.programAddress }
|
|
133
|
+
: event;
|
|
134
|
+
if (!isTokenCreateEvent(checkedEvent)) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
const data = 'data' in checkedEvent ? checkedEvent.data : checkedEvent;
|
|
138
|
+
return getTokenCreateEventDecoder().decode(
|
|
139
|
+
data,
|
|
140
|
+
ANCHOR_EVENT_CPI_DISCRIMINATOR.length +
|
|
141
|
+
TOKEN_CREATE_EVENT_DISCRIMINATOR.length,
|
|
142
|
+
);
|
|
143
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
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
|
+
containsBytes,
|
|
11
|
+
fixEncoderSize,
|
|
12
|
+
getAddressDecoder,
|
|
13
|
+
getBooleanDecoder,
|
|
14
|
+
getBytesEncoder,
|
|
15
|
+
getI64Decoder,
|
|
16
|
+
getStructDecoder,
|
|
17
|
+
getU64Decoder,
|
|
18
|
+
type Address,
|
|
19
|
+
type FixedSizeDecoder,
|
|
20
|
+
type ReadonlyUint8Array,
|
|
21
|
+
} from '@solana/kit';
|
|
22
|
+
import { SEND_DEX_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
23
|
+
import {
|
|
24
|
+
getTradeDirectionDecoder,
|
|
25
|
+
type TradeDirection,
|
|
26
|
+
} from '../types/index.js';
|
|
27
|
+
import { ANCHOR_EVENT_CPI_DISCRIMINATOR } from './anchorEventCpiDiscriminator.framing.js';
|
|
28
|
+
|
|
29
|
+
export const TRADE_EVENT_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
|
|
30
|
+
189, 219, 127, 211, 78, 230, 97, 238,
|
|
31
|
+
]);
|
|
32
|
+
|
|
33
|
+
export function getTradeEventDiscriminatorBytes(): ReadonlyUint8Array {
|
|
34
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
35
|
+
TRADE_EVENT_DISCRIMINATOR,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type TradeEvent = {
|
|
40
|
+
pool: Address;
|
|
41
|
+
baseMint: Address;
|
|
42
|
+
quoteMint: Address;
|
|
43
|
+
user: Address;
|
|
44
|
+
coinCreator: Address;
|
|
45
|
+
creatorFeeConfig: Address;
|
|
46
|
+
platformConfig: Address;
|
|
47
|
+
baseAmount: bigint;
|
|
48
|
+
quoteAmountGross: bigint;
|
|
49
|
+
quoteAmountNet: bigint;
|
|
50
|
+
tradeDirection: TradeDirection;
|
|
51
|
+
partner: Address;
|
|
52
|
+
isPartner: boolean;
|
|
53
|
+
protocolFee: bigint;
|
|
54
|
+
lpFee: bigint;
|
|
55
|
+
creatorFee: bigint;
|
|
56
|
+
baseTransferFee: bigint;
|
|
57
|
+
quoteTransferFee: bigint;
|
|
58
|
+
baseReserves: bigint;
|
|
59
|
+
quoteReserves: bigint;
|
|
60
|
+
timestamp: bigint;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
let getTradeEventDecoderCache: FixedSizeDecoder<TradeEvent> | undefined;
|
|
64
|
+
|
|
65
|
+
export function getTradeEventDecoder(): FixedSizeDecoder<TradeEvent> {
|
|
66
|
+
return (getTradeEventDecoderCache ??= getStructDecoder([
|
|
67
|
+
['pool', getAddressDecoder()],
|
|
68
|
+
['baseMint', getAddressDecoder()],
|
|
69
|
+
['quoteMint', getAddressDecoder()],
|
|
70
|
+
['user', getAddressDecoder()],
|
|
71
|
+
['coinCreator', getAddressDecoder()],
|
|
72
|
+
['creatorFeeConfig', getAddressDecoder()],
|
|
73
|
+
['platformConfig', getAddressDecoder()],
|
|
74
|
+
['baseAmount', getU64Decoder()],
|
|
75
|
+
['quoteAmountGross', getU64Decoder()],
|
|
76
|
+
['quoteAmountNet', getU64Decoder()],
|
|
77
|
+
['tradeDirection', getTradeDirectionDecoder()],
|
|
78
|
+
['partner', getAddressDecoder()],
|
|
79
|
+
['isPartner', getBooleanDecoder()],
|
|
80
|
+
['protocolFee', getU64Decoder()],
|
|
81
|
+
['lpFee', getU64Decoder()],
|
|
82
|
+
['creatorFee', getU64Decoder()],
|
|
83
|
+
['baseTransferFee', getU64Decoder()],
|
|
84
|
+
['quoteTransferFee', getU64Decoder()],
|
|
85
|
+
['baseReserves', getU64Decoder()],
|
|
86
|
+
['quoteReserves', getU64Decoder()],
|
|
87
|
+
['timestamp', getI64Decoder()],
|
|
88
|
+
]));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Checks whether the event data matches the framing and discriminator bytes of a
|
|
93
|
+
* {@link TradeEvent}, without decoding. Never throws.
|
|
94
|
+
*
|
|
95
|
+
* Returns `false` unless `event.programAddress` is SEND_DEX_PROGRAM_ADDRESS.
|
|
96
|
+
* Raw bytes carry no emitter and SKIP that check.
|
|
97
|
+
*
|
|
98
|
+
* @see parseTradeEvent to decode the matching data
|
|
99
|
+
*/
|
|
100
|
+
export function isTradeEvent(
|
|
101
|
+
event:
|
|
102
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
103
|
+
| ReadonlyUint8Array,
|
|
104
|
+
): boolean {
|
|
105
|
+
if ('data' in event && event.programAddress !== SEND_DEX_PROGRAM_ADDRESS)
|
|
106
|
+
return false;
|
|
107
|
+
const data = 'data' in event ? event.data : event;
|
|
108
|
+
return (
|
|
109
|
+
containsBytes(data, ANCHOR_EVENT_CPI_DISCRIMINATOR, 0) &&
|
|
110
|
+
containsBytes(data, TRADE_EVENT_DISCRIMINATOR, 8)
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Parses raw event data as a {@link TradeEvent}. Returns `null` on framing or discriminator
|
|
116
|
+
* mismatch; throws if the event matches but its body fails to decode.
|
|
117
|
+
*
|
|
118
|
+
* Returns `null` unless `event.programAddress` is SEND_DEX_PROGRAM_ADDRESS.
|
|
119
|
+
* Raw bytes carry no emitter and SKIP that check.
|
|
120
|
+
*
|
|
121
|
+
* @see isTradeEvent to check without decoding
|
|
122
|
+
* @see identifySendDexEvent to identify any program event
|
|
123
|
+
* @see parseSendDexEvent
|
|
124
|
+
*/
|
|
125
|
+
export function parseTradeEvent(
|
|
126
|
+
event:
|
|
127
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
128
|
+
| ReadonlyUint8Array,
|
|
129
|
+
): TradeEvent | null {
|
|
130
|
+
const checkedEvent =
|
|
131
|
+
'data' in event
|
|
132
|
+
? { data: event.data, programAddress: event.programAddress }
|
|
133
|
+
: event;
|
|
134
|
+
if (!isTradeEvent(checkedEvent)) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
const data = 'data' in checkedEvent ? checkedEvent.data : checkedEvent;
|
|
138
|
+
return getTradeEventDecoder().decode(
|
|
139
|
+
data,
|
|
140
|
+
ANCHOR_EVENT_CPI_DISCRIMINATOR.length +
|
|
141
|
+
TRADE_EVENT_DISCRIMINATOR.length,
|
|
142
|
+
);
|
|
143
|
+
}
|