@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,121 @@
|
|
|
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_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
15
|
+
import { ANCHOR_EVENT_CPI_DISCRIMINATOR } from './anchorEventCpiDiscriminator.framing.js';
|
|
16
|
+
import {
|
|
17
|
+
CLAIM_EVENT_DISCRIMINATOR,
|
|
18
|
+
getClaimEventDecoder,
|
|
19
|
+
type ClaimEvent,
|
|
20
|
+
} from './claimEvent.js';
|
|
21
|
+
import {
|
|
22
|
+
getStakeEventDecoder,
|
|
23
|
+
STAKE_EVENT_DISCRIMINATOR,
|
|
24
|
+
type StakeEvent,
|
|
25
|
+
} from './stakeEvent.js';
|
|
26
|
+
import {
|
|
27
|
+
getUnstakeEventDecoder,
|
|
28
|
+
type UnstakeEvent,
|
|
29
|
+
UNSTAKE_EVENT_DISCRIMINATOR,
|
|
30
|
+
} from './unstakeEvent.js';
|
|
31
|
+
|
|
32
|
+
/** Event kinds of the sendNexus program. */
|
|
33
|
+
export type SendNexusEventType = 'claimEvent' | 'stakeEvent' | 'unstakeEvent';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Identifies sendNexus event data by its discriminators, without decoding.
|
|
37
|
+
* Returns `null` when the event was emitted by another program or no known event matches.
|
|
38
|
+
* Never throws.
|
|
39
|
+
*
|
|
40
|
+
* Raw bytes carry no emitter and SKIP the program check.
|
|
41
|
+
*/
|
|
42
|
+
export function identifySendNexusEvent(
|
|
43
|
+
event:
|
|
44
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
45
|
+
| ReadonlyUint8Array,
|
|
46
|
+
): SendNexusEventType | null {
|
|
47
|
+
if ('data' in event && event.programAddress !== SEND_NEXUS_PROGRAM_ADDRESS)
|
|
48
|
+
return null;
|
|
49
|
+
const data = 'data' in event ? event.data : event;
|
|
50
|
+
if (containsBytes(data, ANCHOR_EVENT_CPI_DISCRIMINATOR, 0)) {
|
|
51
|
+
if (containsBytes(data, CLAIM_EVENT_DISCRIMINATOR, 8)) {
|
|
52
|
+
return 'claimEvent';
|
|
53
|
+
}
|
|
54
|
+
if (containsBytes(data, STAKE_EVENT_DISCRIMINATOR, 8)) {
|
|
55
|
+
return 'stakeEvent';
|
|
56
|
+
}
|
|
57
|
+
if (containsBytes(data, UNSTAKE_EVENT_DISCRIMINATOR, 8)) {
|
|
58
|
+
return 'unstakeEvent';
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Parsed sendNexus event: the event kind tag plus its decoded payload. */
|
|
65
|
+
export type ParsedSendNexusEvent =
|
|
66
|
+
| { eventType: 'claimEvent'; data: ClaimEvent }
|
|
67
|
+
| { eventType: 'stakeEvent'; data: StakeEvent }
|
|
68
|
+
| { eventType: 'unstakeEvent'; data: UnstakeEvent };
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Parses sendNexus event data into its event kind and decoded payload.
|
|
72
|
+
* Returns `null` when the event was emitted by another program or no known event matches;
|
|
73
|
+
* throws if a matched event fails to decode.
|
|
74
|
+
*
|
|
75
|
+
* Raw bytes carry no emitter and SKIP the program check.
|
|
76
|
+
*/
|
|
77
|
+
export function parseSendNexusEvent(
|
|
78
|
+
event:
|
|
79
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
80
|
+
| ReadonlyUint8Array,
|
|
81
|
+
): ParsedSendNexusEvent | null {
|
|
82
|
+
const checkedEvent =
|
|
83
|
+
'data' in event
|
|
84
|
+
? { data: event.data, programAddress: event.programAddress }
|
|
85
|
+
: event;
|
|
86
|
+
const eventType = identifySendNexusEvent(checkedEvent);
|
|
87
|
+
if (eventType === null) return null;
|
|
88
|
+
const data = 'data' in checkedEvent ? checkedEvent.data : checkedEvent;
|
|
89
|
+
switch (eventType) {
|
|
90
|
+
case 'claimEvent': {
|
|
91
|
+
return {
|
|
92
|
+
eventType: 'claimEvent',
|
|
93
|
+
data: getClaimEventDecoder().decode(
|
|
94
|
+
data,
|
|
95
|
+
ANCHOR_EVENT_CPI_DISCRIMINATOR.length +
|
|
96
|
+
CLAIM_EVENT_DISCRIMINATOR.length,
|
|
97
|
+
),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
case 'stakeEvent': {
|
|
101
|
+
return {
|
|
102
|
+
eventType: 'stakeEvent',
|
|
103
|
+
data: getStakeEventDecoder().decode(
|
|
104
|
+
data,
|
|
105
|
+
ANCHOR_EVENT_CPI_DISCRIMINATOR.length +
|
|
106
|
+
STAKE_EVENT_DISCRIMINATOR.length,
|
|
107
|
+
),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
case 'unstakeEvent': {
|
|
111
|
+
return {
|
|
112
|
+
eventType: 'unstakeEvent',
|
|
113
|
+
data: getUnstakeEventDecoder().decode(
|
|
114
|
+
data,
|
|
115
|
+
ANCHOR_EVENT_CPI_DISCRIMINATOR.length +
|
|
116
|
+
UNSTAKE_EVENT_DISCRIMINATOR.length,
|
|
117
|
+
),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
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_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
22
|
+
import { ANCHOR_EVENT_CPI_DISCRIMINATOR } from './anchorEventCpiDiscriminator.framing.js';
|
|
23
|
+
|
|
24
|
+
export const STAKE_EVENT_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
|
|
25
|
+
226, 134, 188, 173, 19, 33, 75, 175,
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
export function getStakeEventDiscriminatorBytes(): ReadonlyUint8Array {
|
|
29
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
30
|
+
STAKE_EVENT_DISCRIMINATOR,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type StakeEvent = {
|
|
35
|
+
user: Address;
|
|
36
|
+
stakingConfig: Address;
|
|
37
|
+
amount: bigint;
|
|
38
|
+
totalStaked: bigint;
|
|
39
|
+
timestamp: bigint;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
let getStakeEventDecoderCache: FixedSizeDecoder<StakeEvent> | undefined;
|
|
43
|
+
|
|
44
|
+
export function getStakeEventDecoder(): FixedSizeDecoder<StakeEvent> {
|
|
45
|
+
return (getStakeEventDecoderCache ??= getStructDecoder([
|
|
46
|
+
['user', getAddressDecoder()],
|
|
47
|
+
['stakingConfig', getAddressDecoder()],
|
|
48
|
+
['amount', getU64Decoder()],
|
|
49
|
+
['totalStaked', getU64Decoder()],
|
|
50
|
+
['timestamp', getI64Decoder()],
|
|
51
|
+
]));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Checks whether the event data matches the framing and discriminator bytes of a
|
|
56
|
+
* {@link StakeEvent}, without decoding. Never throws.
|
|
57
|
+
*
|
|
58
|
+
* Returns `false` unless `event.programAddress` is SEND_NEXUS_PROGRAM_ADDRESS.
|
|
59
|
+
* Raw bytes carry no emitter and SKIP that check.
|
|
60
|
+
*
|
|
61
|
+
* @see parseStakeEvent to decode the matching data
|
|
62
|
+
*/
|
|
63
|
+
export function isStakeEvent(
|
|
64
|
+
event:
|
|
65
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
66
|
+
| ReadonlyUint8Array,
|
|
67
|
+
): boolean {
|
|
68
|
+
if ('data' in event && event.programAddress !== SEND_NEXUS_PROGRAM_ADDRESS)
|
|
69
|
+
return false;
|
|
70
|
+
const data = 'data' in event ? event.data : event;
|
|
71
|
+
return (
|
|
72
|
+
containsBytes(data, ANCHOR_EVENT_CPI_DISCRIMINATOR, 0) &&
|
|
73
|
+
containsBytes(data, STAKE_EVENT_DISCRIMINATOR, 8)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Parses raw event data as a {@link StakeEvent}. Returns `null` on framing or discriminator
|
|
79
|
+
* mismatch; throws if the event matches but its body fails to decode.
|
|
80
|
+
*
|
|
81
|
+
* Returns `null` unless `event.programAddress` is SEND_NEXUS_PROGRAM_ADDRESS.
|
|
82
|
+
* Raw bytes carry no emitter and SKIP that check.
|
|
83
|
+
*
|
|
84
|
+
* @see isStakeEvent to check without decoding
|
|
85
|
+
* @see identifySendNexusEvent to identify any program event
|
|
86
|
+
* @see parseSendNexusEvent
|
|
87
|
+
*/
|
|
88
|
+
export function parseStakeEvent(
|
|
89
|
+
event:
|
|
90
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
91
|
+
| ReadonlyUint8Array,
|
|
92
|
+
): StakeEvent | null {
|
|
93
|
+
const checkedEvent =
|
|
94
|
+
'data' in event
|
|
95
|
+
? { data: event.data, programAddress: event.programAddress }
|
|
96
|
+
: event;
|
|
97
|
+
if (!isStakeEvent(checkedEvent)) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
const data = 'data' in checkedEvent ? checkedEvent.data : checkedEvent;
|
|
101
|
+
return getStakeEventDecoder().decode(
|
|
102
|
+
data,
|
|
103
|
+
ANCHOR_EVENT_CPI_DISCRIMINATOR.length +
|
|
104
|
+
STAKE_EVENT_DISCRIMINATOR.length,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
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_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
22
|
+
import { ANCHOR_EVENT_CPI_DISCRIMINATOR } from './anchorEventCpiDiscriminator.framing.js';
|
|
23
|
+
|
|
24
|
+
export const UNSTAKE_EVENT_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
|
|
25
|
+
162, 104, 137, 228, 81, 3, 79, 197,
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
export function getUnstakeEventDiscriminatorBytes(): ReadonlyUint8Array {
|
|
29
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
30
|
+
UNSTAKE_EVENT_DISCRIMINATOR,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type UnstakeEvent = {
|
|
35
|
+
user: Address;
|
|
36
|
+
stakingConfig: Address;
|
|
37
|
+
amount: bigint;
|
|
38
|
+
totalStaked: bigint;
|
|
39
|
+
timestamp: bigint;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
let getUnstakeEventDecoderCache: FixedSizeDecoder<UnstakeEvent> | undefined;
|
|
43
|
+
|
|
44
|
+
export function getUnstakeEventDecoder(): FixedSizeDecoder<UnstakeEvent> {
|
|
45
|
+
return (getUnstakeEventDecoderCache ??= getStructDecoder([
|
|
46
|
+
['user', getAddressDecoder()],
|
|
47
|
+
['stakingConfig', getAddressDecoder()],
|
|
48
|
+
['amount', getU64Decoder()],
|
|
49
|
+
['totalStaked', getU64Decoder()],
|
|
50
|
+
['timestamp', getI64Decoder()],
|
|
51
|
+
]));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Checks whether the event data matches the framing and discriminator bytes of a
|
|
56
|
+
* {@link UnstakeEvent}, without decoding. Never throws.
|
|
57
|
+
*
|
|
58
|
+
* Returns `false` unless `event.programAddress` is SEND_NEXUS_PROGRAM_ADDRESS.
|
|
59
|
+
* Raw bytes carry no emitter and SKIP that check.
|
|
60
|
+
*
|
|
61
|
+
* @see parseUnstakeEvent to decode the matching data
|
|
62
|
+
*/
|
|
63
|
+
export function isUnstakeEvent(
|
|
64
|
+
event:
|
|
65
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
66
|
+
| ReadonlyUint8Array,
|
|
67
|
+
): boolean {
|
|
68
|
+
if ('data' in event && event.programAddress !== SEND_NEXUS_PROGRAM_ADDRESS)
|
|
69
|
+
return false;
|
|
70
|
+
const data = 'data' in event ? event.data : event;
|
|
71
|
+
return (
|
|
72
|
+
containsBytes(data, ANCHOR_EVENT_CPI_DISCRIMINATOR, 0) &&
|
|
73
|
+
containsBytes(data, UNSTAKE_EVENT_DISCRIMINATOR, 8)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Parses raw event data as a {@link UnstakeEvent}. Returns `null` on framing or discriminator
|
|
79
|
+
* mismatch; throws if the event matches but its body fails to decode.
|
|
80
|
+
*
|
|
81
|
+
* Returns `null` unless `event.programAddress` is SEND_NEXUS_PROGRAM_ADDRESS.
|
|
82
|
+
* Raw bytes carry no emitter and SKIP that check.
|
|
83
|
+
*
|
|
84
|
+
* @see isUnstakeEvent to check without decoding
|
|
85
|
+
* @see identifySendNexusEvent to identify any program event
|
|
86
|
+
* @see parseSendNexusEvent
|
|
87
|
+
*/
|
|
88
|
+
export function parseUnstakeEvent(
|
|
89
|
+
event:
|
|
90
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
91
|
+
| ReadonlyUint8Array,
|
|
92
|
+
): UnstakeEvent | null {
|
|
93
|
+
const checkedEvent =
|
|
94
|
+
'data' in event
|
|
95
|
+
? { data: event.data, programAddress: event.programAddress }
|
|
96
|
+
: event;
|
|
97
|
+
if (!isUnstakeEvent(checkedEvent)) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
const data = 'data' in checkedEvent ? checkedEvent.data : checkedEvent;
|
|
101
|
+
return getUnstakeEventDecoder().decode(
|
|
102
|
+
data,
|
|
103
|
+
ANCHOR_EVENT_CPI_DISCRIMINATOR.length +
|
|
104
|
+
UNSTAKE_EVENT_DISCRIMINATOR.length,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
export * from './accounts/index.js';
|
|
10
|
+
export * from './constants/index.js';
|
|
11
|
+
export * from './errors/index.js';
|
|
12
|
+
export * from './events/index.js';
|
|
13
|
+
export * from './instructions/index.js';
|
|
14
|
+
export * from './pdas/index.js';
|
|
15
|
+
export * from './plugins/index.js';
|
|
16
|
+
export * from './programs/index.js';
|
|
17
|
+
export * from './types/index.js';
|