@pina-rs/amm 0.2.0 → 0.2.2
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/package.json
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
type Encoder,
|
|
12
12
|
type FixedSizeDecoder,
|
|
13
13
|
type FixedSizeEncoder,
|
|
14
|
+
type ReadonlyUint8Array,
|
|
14
15
|
addDecoderSizePrefix,
|
|
15
16
|
createDecoder,
|
|
16
17
|
fixDecoderSize,
|
|
@@ -93,6 +94,36 @@ export function getPinaPodBoundedCountDecoder<TDecoded extends Integer>(
|
|
|
93
94
|
});
|
|
94
95
|
}
|
|
95
96
|
|
|
97
|
+
/** Enforces a byte vector's capacity before its encoder runs. */
|
|
98
|
+
export function getPinaPodBoundedBytesEncoder(
|
|
99
|
+
encoder: Encoder<ReadonlyUint8Array>,
|
|
100
|
+
capacity: number,
|
|
101
|
+
): Encoder<ReadonlyUint8Array> {
|
|
102
|
+
return transformEncoder(encoder, (value) => {
|
|
103
|
+
if (value.length > capacity) {
|
|
104
|
+
throw new RangeError(
|
|
105
|
+
`PinaPod bytes value has ${value.length} bytes but its capacity is ${capacity}`,
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
return value;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Defensively rechecks a decoded byte vector's capacity. */
|
|
113
|
+
export function getPinaPodBoundedBytesDecoder(
|
|
114
|
+
decoder: Decoder<ReadonlyUint8Array>,
|
|
115
|
+
capacity: number,
|
|
116
|
+
): Decoder<ReadonlyUint8Array> {
|
|
117
|
+
return transformDecoder(decoder, (value) => {
|
|
118
|
+
if (value.length > capacity) {
|
|
119
|
+
throw new RangeError(
|
|
120
|
+
`PinaPod bytes value has ${value.length} bytes but its capacity is ${capacity}`,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
return value;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
96
127
|
/** Enforces a string's UTF-8 byte capacity before its encoder runs. */
|
|
97
128
|
export function getPinaPodBoundedStringEncoder(
|
|
98
129
|
encoder: Encoder<string>,
|
|
@@ -117,8 +117,8 @@ export type PinaAmmPluginRequirements = ClientWithRpc<GetAccountInfoApi & GetMul
|
|
|
117
117
|
|
|
118
118
|
export function pinaAmmProgram() {
|
|
119
119
|
return <T extends PinaAmmPluginRequirements>(client: T): ExtendedClient<T, { pinaAmm: PinaAmmPlugin }> => {
|
|
120
|
-
return extendClient(client, { pinaAmm: <PinaAmmPlugin>{ accounts: { ammConfig: addSelfFetchFunctions(client, getAmmConfigCodec()), pool: addSelfFetchFunctions(client, getPoolCodec()) }, instructions: {
|
|
120
|
+
return extendClient(client, { pinaAmm: <PinaAmmPlugin>{ accounts: { ammConfig: addSelfFetchFunctions(client, getAmmConfigCodec()), pool: addSelfFetchFunctions(client, getPoolCodec()) }, instructions: {
|
|
121
121
|
migrate: (input: MigrateInput) =>
|
|
122
|
-
addSelfPlanAndSendFunctions(client, getMigrateInstruction(input)),createConfig: input => addSelfPlanAndSendFunctions(client, getCreateConfigInstruction(input)), updateConfig: input => addSelfPlanAndSendFunctions(client, getUpdateConfigInstruction(input)), createPool: input => addSelfPlanAndSendFunctions(client, getCreatePoolInstructionAsync(input)), deposit: input => addSelfPlanAndSendFunctions(client, getDepositInstruction(input)), withdraw: input => addSelfPlanAndSendFunctions(client, getWithdrawInstruction(input)), swapExactIn: input => addSelfPlanAndSendFunctions(client, getSwapExactInInstruction(input)), swapExactOut: input => addSelfPlanAndSendFunctions(client, getSwapExactOutInstruction(input)), collectProtocolFees: input => addSelfPlanAndSendFunctions(client, getCollectProtocolFeesInstruction(input)), collectCreatorFees: input => addSelfPlanAndSendFunctions(client, getCollectCreatorFeesInstruction(input)), setPoolCreator: input => addSelfPlanAndSendFunctions(client, getSetPoolCreatorInstruction(input)), syncPool: input => addSelfPlanAndSendFunctions(client, getSyncPoolInstruction(input)) }, pdas: { ammConfig: findAmmConfigPda, pool: findPoolPda, poolVault: findPoolVaultPda, poolLpMint: findPoolLpMintPda }, identifyAccount: identifyPinaAmmAccount, identifyInstruction: identifyPinaAmmInstruction, parseInstruction: parsePinaAmmInstruction } });
|
|
122
|
+
addSelfPlanAndSendFunctions(client, getMigrateInstruction(input)), createConfig: input => addSelfPlanAndSendFunctions(client, getCreateConfigInstruction(input)), updateConfig: input => addSelfPlanAndSendFunctions(client, getUpdateConfigInstruction(input)), createPool: input => addSelfPlanAndSendFunctions(client, getCreatePoolInstructionAsync(input)), deposit: input => addSelfPlanAndSendFunctions(client, getDepositInstruction(input)), withdraw: input => addSelfPlanAndSendFunctions(client, getWithdrawInstruction(input)), swapExactIn: input => addSelfPlanAndSendFunctions(client, getSwapExactInInstruction(input)), swapExactOut: input => addSelfPlanAndSendFunctions(client, getSwapExactOutInstruction(input)), collectProtocolFees: input => addSelfPlanAndSendFunctions(client, getCollectProtocolFeesInstruction(input)), collectCreatorFees: input => addSelfPlanAndSendFunctions(client, getCollectCreatorFeesInstruction(input)), setPoolCreator: input => addSelfPlanAndSendFunctions(client, getSetPoolCreatorInstruction(input)), syncPool: input => addSelfPlanAndSendFunctions(client, getSyncPoolInstruction(input)) }, pdas: { ammConfig: findAmmConfigPda, pool: findPoolPda, poolVault: findPoolVaultPda, poolLpMint: findPoolLpMintPda }, identifyAccount: identifyPinaAmmAccount, identifyInstruction: identifyPinaAmmInstruction, parseInstruction: parsePinaAmmInstruction } });
|
|
123
123
|
};
|
|
124
124
|
}
|