@epicentral/sos-sdk 0.9.0-beta
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/.env.example +1 -0
- package/AGENTS.md +7 -0
- package/LICENSE +21 -0
- package/README.md +568 -0
- package/accounts/fetchers.ts +196 -0
- package/accounts/list.ts +184 -0
- package/accounts/pdas.ts +325 -0
- package/accounts/resolve-option.ts +104 -0
- package/client/lookup-table.ts +114 -0
- package/client/program.ts +13 -0
- package/client/types.ts +9 -0
- package/generated/accounts/collateralPool.ts +217 -0
- package/generated/accounts/config.ts +156 -0
- package/generated/accounts/escrowState.ts +183 -0
- package/generated/accounts/index.ts +20 -0
- package/generated/accounts/lenderPosition.ts +211 -0
- package/generated/accounts/makerCollateralShare.ts +229 -0
- package/generated/accounts/marketDataAccount.ts +176 -0
- package/generated/accounts/optionAccount.ts +247 -0
- package/generated/accounts/optionPool.ts +285 -0
- package/generated/accounts/poolLoan.ts +232 -0
- package/generated/accounts/positionAccount.ts +201 -0
- package/generated/accounts/vault.ts +366 -0
- package/generated/accounts/writerPosition.ts +327 -0
- package/generated/errors/index.ts +9 -0
- package/generated/errors/optionProgram.ts +476 -0
- package/generated/index.ts +13 -0
- package/generated/instructions/acceptAdmin.ts +230 -0
- package/generated/instructions/autoExerciseAllExpired.ts +685 -0
- package/generated/instructions/autoExerciseExpired.ts +754 -0
- package/generated/instructions/borrowFromPool.ts +619 -0
- package/generated/instructions/buyFromPool.ts +761 -0
- package/generated/instructions/closeLongToPool.ts +762 -0
- package/generated/instructions/closeOption.ts +235 -0
- package/generated/instructions/createEscrowV2.ts +518 -0
- package/generated/instructions/depositCollateral.ts +624 -0
- package/generated/instructions/depositToPosition.ts +429 -0
- package/generated/instructions/index.ts +47 -0
- package/generated/instructions/initCollateralPool.ts +513 -0
- package/generated/instructions/initConfig.ts +279 -0
- package/generated/instructions/initOptionPool.ts +587 -0
- package/generated/instructions/initializeMarketData.ts +359 -0
- package/generated/instructions/liquidateWriterPosition.ts +750 -0
- package/generated/instructions/liquidateWriterPositionRescue.ts +623 -0
- package/generated/instructions/omlpCreateVault.ts +553 -0
- package/generated/instructions/omlpUpdateFeeWallet.ts +473 -0
- package/generated/instructions/omlpUpdateInterestModel.ts +322 -0
- package/generated/instructions/omlpUpdateLiquidationThreshold.ts +304 -0
- package/generated/instructions/omlpUpdateMaintenanceBuffer.ts +304 -0
- package/generated/instructions/omlpUpdateMaxBorrowCap.ts +304 -0
- package/generated/instructions/omlpUpdateMaxLeverage.ts +304 -0
- package/generated/instructions/omlpUpdateProtocolFee.ts +304 -0
- package/generated/instructions/omlpUpdateSupplyLimit.ts +304 -0
- package/generated/instructions/optionExercise.ts +617 -0
- package/generated/instructions/optionMint.ts +1373 -0
- package/generated/instructions/optionValidate.ts +302 -0
- package/generated/instructions/repayPoolLoan.ts +558 -0
- package/generated/instructions/repayPoolLoanFromCollateral.ts +514 -0
- package/generated/instructions/repayPoolLoanFromWallet.ts +542 -0
- package/generated/instructions/settleMakerCollateral.ts +509 -0
- package/generated/instructions/syncWriterPosition.ts +206 -0
- package/generated/instructions/transferAdmin.ts +245 -0
- package/generated/instructions/unwindWriterUnsold.ts +764 -0
- package/generated/instructions/updateImpliedVolatility.ts +226 -0
- package/generated/instructions/updateMarketData.ts +315 -0
- package/generated/instructions/withdrawFromPosition.ts +405 -0
- package/generated/instructions/writeToPool.ts +619 -0
- package/generated/programs/index.ts +9 -0
- package/generated/programs/optionProgram.ts +1144 -0
- package/generated/shared/index.ts +164 -0
- package/generated/types/impliedVolatilityUpdated.ts +73 -0
- package/generated/types/index.ts +28 -0
- package/generated/types/liquidationExecuted.ts +73 -0
- package/generated/types/liquidationRescueEvent.ts +82 -0
- package/generated/types/marketDataInitialized.ts +61 -0
- package/generated/types/marketDataUpdated.ts +69 -0
- package/generated/types/optionClosed.ts +56 -0
- package/generated/types/optionExercised.ts +62 -0
- package/generated/types/optionExpired.ts +49 -0
- package/generated/types/optionMinted.ts +78 -0
- package/generated/types/optionType.ts +38 -0
- package/generated/types/optionValidated.ts +82 -0
- package/generated/types/poolLoanCreated.ts +74 -0
- package/generated/types/poolLoanRepaid.ts +74 -0
- package/generated/types/positionDeposited.ts +73 -0
- package/generated/types/positionWithdrawn.ts +81 -0
- package/generated/types/protocolFeeUpdated.ts +69 -0
- package/generated/types/vaultCreated.ts +60 -0
- package/generated/types/vaultFeeWalletUpdated.ts +67 -0
- package/generated/types/vaultInterestModelUpdated.ts +77 -0
- package/generated/types/vaultLiquidationThresholdUpdated.ts +69 -0
- package/index.ts +68 -0
- package/long/builders.ts +690 -0
- package/long/exercise.ts +123 -0
- package/long/preflight.ts +214 -0
- package/long/quotes.ts +48 -0
- package/long/remaining-accounts.ts +111 -0
- package/omlp/builders.ts +94 -0
- package/omlp/service.ts +136 -0
- package/oracle/switchboard.ts +315 -0
- package/package.json +34 -0
- package/shared/amounts.ts +53 -0
- package/shared/balances.ts +57 -0
- package/shared/errors.ts +12 -0
- package/shared/remaining-accounts.ts +41 -0
- package/shared/trade-config.ts +27 -0
- package/shared/transactions.ts +121 -0
- package/short/builders.ts +874 -0
- package/short/close-option.ts +34 -0
- package/short/pool.ts +189 -0
- package/short/preflight.ts +619 -0
- package/tsconfig.json +13 -0
- package/wsol/instructions.ts +247 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { Address } from "@solana/kit";
|
|
2
|
+
import { OptionType } from "../generated/types";
|
|
3
|
+
import { toAddress } from "../client/program";
|
|
4
|
+
import type { AddressLike, KitRpc } from "../client/types";
|
|
5
|
+
import {
|
|
6
|
+
deriveCollateralPoolPda,
|
|
7
|
+
deriveLongMintPda,
|
|
8
|
+
deriveMarketDataPda,
|
|
9
|
+
deriveMintAuthorityPda,
|
|
10
|
+
deriveOptionAccountPda,
|
|
11
|
+
deriveOptionPoolPda,
|
|
12
|
+
deriveShortMintPda,
|
|
13
|
+
} from "./pdas";
|
|
14
|
+
import { fetchCollateralPool, fetchOptionAccount, fetchOptionPool } from "./fetchers";
|
|
15
|
+
|
|
16
|
+
export interface ResolveOptionAccountsParams {
|
|
17
|
+
underlyingAsset: AddressLike;
|
|
18
|
+
optionType: OptionType;
|
|
19
|
+
strikePrice: number;
|
|
20
|
+
expirationDate: bigint | number;
|
|
21
|
+
programId?: AddressLike;
|
|
22
|
+
rpc?: KitRpc;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ResolvedOptionAccounts {
|
|
26
|
+
optionAccount: Address;
|
|
27
|
+
longMint: Address;
|
|
28
|
+
shortMint: Address;
|
|
29
|
+
optionPool: Address;
|
|
30
|
+
marketData: Address;
|
|
31
|
+
collateralPool: Address;
|
|
32
|
+
mintAuthority: Address;
|
|
33
|
+
underlyingMint?: Address;
|
|
34
|
+
escrowLongAccount?: Address;
|
|
35
|
+
premiumVault?: Address;
|
|
36
|
+
collateralVault?: Address;
|
|
37
|
+
optionPoolData?: Awaited<ReturnType<typeof fetchOptionPool>>;
|
|
38
|
+
optionAccountData?: Awaited<ReturnType<typeof fetchOptionAccount>>;
|
|
39
|
+
collateralPoolData?: Awaited<ReturnType<typeof fetchCollateralPool>>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Resolves all derived and optionally fetched accounts for an option.
|
|
44
|
+
* Given option identity (underlyingAsset, optionType, strikePrice, expirationDate),
|
|
45
|
+
* returns PDAs and, when rpc is provided, fetches OptionPool and CollateralPool
|
|
46
|
+
* to expose escrowLongAccount, premiumVault, collateralVault, underlyingMint.
|
|
47
|
+
*/
|
|
48
|
+
export async function resolveOptionAccounts(
|
|
49
|
+
params: ResolveOptionAccountsParams
|
|
50
|
+
): Promise<ResolvedOptionAccounts> {
|
|
51
|
+
const programId = params.programId;
|
|
52
|
+
|
|
53
|
+
const [optionAccount] = await deriveOptionAccountPda({
|
|
54
|
+
underlyingAsset: params.underlyingAsset,
|
|
55
|
+
optionType: params.optionType,
|
|
56
|
+
strikePrice: params.strikePrice,
|
|
57
|
+
expirationDate: params.expirationDate,
|
|
58
|
+
programId,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const [longMint] = await deriveLongMintPda(optionAccount, programId);
|
|
62
|
+
const [shortMint] = await deriveShortMintPda(optionAccount, programId);
|
|
63
|
+
const [optionPool] = await deriveOptionPoolPda(optionAccount, programId);
|
|
64
|
+
const [marketData] = await deriveMarketDataPda(params.underlyingAsset, programId);
|
|
65
|
+
const [collateralPool] = await deriveCollateralPoolPda(optionAccount, programId);
|
|
66
|
+
const [mintAuthority] = await deriveMintAuthorityPda(programId);
|
|
67
|
+
|
|
68
|
+
const result: ResolvedOptionAccounts = {
|
|
69
|
+
optionAccount,
|
|
70
|
+
longMint,
|
|
71
|
+
shortMint,
|
|
72
|
+
optionPool,
|
|
73
|
+
marketData,
|
|
74
|
+
collateralPool,
|
|
75
|
+
mintAuthority,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
if (params.rpc) {
|
|
79
|
+
const [optionPoolFetched, optionAccountFetched, collateralPoolFetched] =
|
|
80
|
+
await Promise.all([
|
|
81
|
+
fetchOptionPool(params.rpc, optionPool),
|
|
82
|
+
fetchOptionAccount(params.rpc, optionAccount),
|
|
83
|
+
fetchCollateralPool(params.rpc, collateralPool),
|
|
84
|
+
]);
|
|
85
|
+
|
|
86
|
+
if (optionPoolFetched) {
|
|
87
|
+
result.optionPoolData = optionPoolFetched;
|
|
88
|
+
result.escrowLongAccount = optionPoolFetched.escrowLongAccount;
|
|
89
|
+
result.premiumVault = optionPoolFetched.premiumVault;
|
|
90
|
+
result.underlyingMint = optionPoolFetched.underlyingMint;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (optionAccountFetched) {
|
|
94
|
+
result.optionAccountData = optionAccountFetched;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (collateralPoolFetched) {
|
|
98
|
+
result.collateralPoolData = collateralPoolFetched;
|
|
99
|
+
result.collateralVault = collateralPoolFetched.collateralVault;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { address, type Address } from "@solana/kit";
|
|
2
|
+
import { fetchAddressLookupTable } from "@solana-program/address-lookup-table";
|
|
3
|
+
import { PROGRAM_ID } from "./program";
|
|
4
|
+
import type { KitRpc } from "./types";
|
|
5
|
+
|
|
6
|
+
export const LOOKUP_TABLE_ADDRESSES: Record<"devnet" | "mainnet", Address | null> = {
|
|
7
|
+
devnet: address("9KB5MPdCHNNZ6MvjZv5JKqkzjyDMiFLcQonmQj3hAuee"),
|
|
8
|
+
mainnet: null,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const LOOKUP_TABLE_ADDRESS: Address | null = LOOKUP_TABLE_ADDRESSES.devnet;
|
|
12
|
+
|
|
13
|
+
export type LookupTableNetwork = "devnet" | "mainnet";
|
|
14
|
+
|
|
15
|
+
export function detectNetwork(rpcUrl: string): LookupTableNetwork {
|
|
16
|
+
const lower = rpcUrl.toLowerCase();
|
|
17
|
+
return lower.includes("mainnet") ? "mainnet" : "devnet";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function getLookupTableAddressForNetwork(
|
|
21
|
+
network: "devnet" | "mainnet"
|
|
22
|
+
): Address | null {
|
|
23
|
+
return LOOKUP_TABLE_ADDRESSES[network];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function getLookupTableAccount(
|
|
27
|
+
rpc: KitRpc,
|
|
28
|
+
lookupTableAddress: Address | null
|
|
29
|
+
): Promise<unknown | null> {
|
|
30
|
+
if (!lookupTableAddress) return null;
|
|
31
|
+
const rpcWithLookupTable = rpc as KitRpc & {
|
|
32
|
+
getAddressLookupTable: (address: Address) => { send: () => Promise<{ value: unknown | null }> };
|
|
33
|
+
};
|
|
34
|
+
const result = await rpcWithLookupTable.getAddressLookupTable(lookupTableAddress).send();
|
|
35
|
+
return result.value ?? null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Result of verifying that a lookup table is correct for the current option program */
|
|
39
|
+
export interface VerifyLookupTableResult {
|
|
40
|
+
/** True if the lookup table exists on-chain and contains the current program ID */
|
|
41
|
+
valid: boolean;
|
|
42
|
+
/** Whether the lookup table account was found on-chain */
|
|
43
|
+
foundOnChain: boolean;
|
|
44
|
+
/** Whether the Option Program ID is present in the table's addresses */
|
|
45
|
+
programIdInTable: boolean;
|
|
46
|
+
/** If valid is false, addresses that were required but missing from the table */
|
|
47
|
+
missingAddresses?: Address[];
|
|
48
|
+
/** Human-readable reason when valid is false */
|
|
49
|
+
reason?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Verifies that the given lookup table is correct for the current Option Program.
|
|
54
|
+
* Ensures:
|
|
55
|
+
* 1. The lookup table exists on-chain
|
|
56
|
+
* 2. The table contains the current program ID (from client/program)
|
|
57
|
+
*
|
|
58
|
+
* Use this before sending transactions to avoid using a stale or wrong ALT.
|
|
59
|
+
*
|
|
60
|
+
* @param rpc - RPC client (must support getAddressLookupTable)
|
|
61
|
+
* @param lookupTableAddress - ALT address to verify (e.g. from getLookupTableAddressForNetwork)
|
|
62
|
+
* @param requiredAddresses - Optional extra addresses that must be in the table (e.g. key PDAs). PROGRAM_ID is always required.
|
|
63
|
+
* @returns Verification result with valid flag and details
|
|
64
|
+
*/
|
|
65
|
+
export async function verifyLookupTableForProgram(
|
|
66
|
+
rpc: KitRpc,
|
|
67
|
+
lookupTableAddress: Address | null,
|
|
68
|
+
requiredAddresses?: Address[]
|
|
69
|
+
): Promise<VerifyLookupTableResult> {
|
|
70
|
+
if (!lookupTableAddress) {
|
|
71
|
+
return {
|
|
72
|
+
valid: false,
|
|
73
|
+
foundOnChain: false,
|
|
74
|
+
programIdInTable: false,
|
|
75
|
+
reason: "No lookup table address configured for this network",
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let tableAddresses: Address[];
|
|
80
|
+
try {
|
|
81
|
+
const { data } = await fetchAddressLookupTable(rpc, lookupTableAddress);
|
|
82
|
+
tableAddresses = data.addresses as Address[];
|
|
83
|
+
} catch {
|
|
84
|
+
return {
|
|
85
|
+
valid: false,
|
|
86
|
+
foundOnChain: false,
|
|
87
|
+
programIdInTable: false,
|
|
88
|
+
reason: "Lookup table not found on-chain or RPC error",
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const programIdStr = PROGRAM_ID;
|
|
93
|
+
const set = new Set(tableAddresses.map((a) => (typeof a === "string" ? a : String(a))));
|
|
94
|
+
const programIdInTable = set.has(programIdStr);
|
|
95
|
+
|
|
96
|
+
const required = requiredAddresses ?? [];
|
|
97
|
+
const allRequired = [programIdStr as Address, ...required];
|
|
98
|
+
const missingAddresses = allRequired.filter(
|
|
99
|
+
(addr) => !set.has(typeof addr === "string" ? addr : String(addr))
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const valid = programIdInTable && missingAddresses.length === 0;
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
valid,
|
|
106
|
+
foundOnChain: true,
|
|
107
|
+
programIdInTable,
|
|
108
|
+
...(missingAddresses.length > 0 && { missingAddresses: missingAddresses as Address[] }),
|
|
109
|
+
...(!valid &&
|
|
110
|
+
(!programIdInTable
|
|
111
|
+
? { reason: "Lookup table does not contain the current Option Program ID" }
|
|
112
|
+
: { reason: `Lookup table is missing required addresses: ${missingAddresses.join(", ")}` })),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { address, type Address } from "@solana/kit";
|
|
2
|
+
import { OPTION_PROGRAM_PROGRAM_ADDRESS } from "../generated/programs";
|
|
3
|
+
import type { AddressLike } from "./types";
|
|
4
|
+
|
|
5
|
+
export const PROGRAM_ADDRESS = OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
6
|
+
export const PROGRAM_ID = address(OPTION_PROGRAM_PROGRAM_ADDRESS);
|
|
7
|
+
export const getProgramId = (): Address => PROGRAM_ID;
|
|
8
|
+
export const getProgramIdString = (): string => PROGRAM_ID;
|
|
9
|
+
|
|
10
|
+
export function toAddress(value: AddressLike): Address {
|
|
11
|
+
return typeof value === "string" ? address(value) : value;
|
|
12
|
+
}
|
|
13
|
+
export { address };
|
package/client/types.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Address, Instruction, Rpc, SolanaRpcApi } from "@solana/kit";
|
|
2
|
+
|
|
3
|
+
export type AddressLike = Address | string;
|
|
4
|
+
export type KitRpc = Rpc<SolanaRpcApi>;
|
|
5
|
+
|
|
6
|
+
export interface BuiltTransaction {
|
|
7
|
+
instructions: Instruction<string>[];
|
|
8
|
+
addressLookupTableAddresses?: AddressLike[];
|
|
9
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
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
|
+
decodeAccount,
|
|
14
|
+
fetchEncodedAccount,
|
|
15
|
+
fetchEncodedAccounts,
|
|
16
|
+
fixDecoderSize,
|
|
17
|
+
fixEncoderSize,
|
|
18
|
+
getAddressDecoder,
|
|
19
|
+
getAddressEncoder,
|
|
20
|
+
getBooleanDecoder,
|
|
21
|
+
getBooleanEncoder,
|
|
22
|
+
getBytesDecoder,
|
|
23
|
+
getBytesEncoder,
|
|
24
|
+
getI64Decoder,
|
|
25
|
+
getI64Encoder,
|
|
26
|
+
getStructDecoder,
|
|
27
|
+
getStructEncoder,
|
|
28
|
+
getU32Decoder,
|
|
29
|
+
getU32Encoder,
|
|
30
|
+
getU64Decoder,
|
|
31
|
+
getU64Encoder,
|
|
32
|
+
getU8Decoder,
|
|
33
|
+
getU8Encoder,
|
|
34
|
+
transformEncoder,
|
|
35
|
+
type Account,
|
|
36
|
+
type Address,
|
|
37
|
+
type EncodedAccount,
|
|
38
|
+
type FetchAccountConfig,
|
|
39
|
+
type FetchAccountsConfig,
|
|
40
|
+
type FixedSizeCodec,
|
|
41
|
+
type FixedSizeDecoder,
|
|
42
|
+
type FixedSizeEncoder,
|
|
43
|
+
type MaybeAccount,
|
|
44
|
+
type MaybeEncodedAccount,
|
|
45
|
+
type ReadonlyUint8Array,
|
|
46
|
+
} from "@solana/kit";
|
|
47
|
+
|
|
48
|
+
export const COLLATERAL_POOL_DISCRIMINATOR = new Uint8Array([
|
|
49
|
+
186, 4, 253, 240, 93, 243, 212, 195,
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
export function getCollateralPoolDiscriminatorBytes() {
|
|
53
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
54
|
+
COLLATERAL_POOL_DISCRIMINATOR,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type CollateralPool = {
|
|
59
|
+
discriminator: ReadonlyUint8Array;
|
|
60
|
+
optionAccount: Address;
|
|
61
|
+
collateralMint: Address;
|
|
62
|
+
collateralVault: Address;
|
|
63
|
+
totalCollateral: bigint;
|
|
64
|
+
totalMakerContribution: bigint;
|
|
65
|
+
totalBorrowed: bigint;
|
|
66
|
+
totalInterestOwed: bigint;
|
|
67
|
+
totalExercisedValue: bigint;
|
|
68
|
+
totalLenderRepaid: bigint;
|
|
69
|
+
totalMakerReturned: bigint;
|
|
70
|
+
makerCount: number;
|
|
71
|
+
isExercised: boolean;
|
|
72
|
+
isFullySettled: boolean;
|
|
73
|
+
createdAt: bigint;
|
|
74
|
+
lastUpdated: bigint;
|
|
75
|
+
bump: number;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export type CollateralPoolArgs = {
|
|
79
|
+
optionAccount: Address;
|
|
80
|
+
collateralMint: Address;
|
|
81
|
+
collateralVault: Address;
|
|
82
|
+
totalCollateral: number | bigint;
|
|
83
|
+
totalMakerContribution: number | bigint;
|
|
84
|
+
totalBorrowed: number | bigint;
|
|
85
|
+
totalInterestOwed: number | bigint;
|
|
86
|
+
totalExercisedValue: number | bigint;
|
|
87
|
+
totalLenderRepaid: number | bigint;
|
|
88
|
+
totalMakerReturned: number | bigint;
|
|
89
|
+
makerCount: number;
|
|
90
|
+
isExercised: boolean;
|
|
91
|
+
isFullySettled: boolean;
|
|
92
|
+
createdAt: number | bigint;
|
|
93
|
+
lastUpdated: number | bigint;
|
|
94
|
+
bump: number;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/** Gets the encoder for {@link CollateralPoolArgs} account data. */
|
|
98
|
+
export function getCollateralPoolEncoder(): FixedSizeEncoder<CollateralPoolArgs> {
|
|
99
|
+
return transformEncoder(
|
|
100
|
+
getStructEncoder([
|
|
101
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
102
|
+
["optionAccount", getAddressEncoder()],
|
|
103
|
+
["collateralMint", getAddressEncoder()],
|
|
104
|
+
["collateralVault", getAddressEncoder()],
|
|
105
|
+
["totalCollateral", getU64Encoder()],
|
|
106
|
+
["totalMakerContribution", getU64Encoder()],
|
|
107
|
+
["totalBorrowed", getU64Encoder()],
|
|
108
|
+
["totalInterestOwed", getU64Encoder()],
|
|
109
|
+
["totalExercisedValue", getU64Encoder()],
|
|
110
|
+
["totalLenderRepaid", getU64Encoder()],
|
|
111
|
+
["totalMakerReturned", getU64Encoder()],
|
|
112
|
+
["makerCount", getU32Encoder()],
|
|
113
|
+
["isExercised", getBooleanEncoder()],
|
|
114
|
+
["isFullySettled", getBooleanEncoder()],
|
|
115
|
+
["createdAt", getI64Encoder()],
|
|
116
|
+
["lastUpdated", getI64Encoder()],
|
|
117
|
+
["bump", getU8Encoder()],
|
|
118
|
+
]),
|
|
119
|
+
(value) => ({ ...value, discriminator: COLLATERAL_POOL_DISCRIMINATOR }),
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Gets the decoder for {@link CollateralPool} account data. */
|
|
124
|
+
export function getCollateralPoolDecoder(): FixedSizeDecoder<CollateralPool> {
|
|
125
|
+
return getStructDecoder([
|
|
126
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
127
|
+
["optionAccount", getAddressDecoder()],
|
|
128
|
+
["collateralMint", getAddressDecoder()],
|
|
129
|
+
["collateralVault", getAddressDecoder()],
|
|
130
|
+
["totalCollateral", getU64Decoder()],
|
|
131
|
+
["totalMakerContribution", getU64Decoder()],
|
|
132
|
+
["totalBorrowed", getU64Decoder()],
|
|
133
|
+
["totalInterestOwed", getU64Decoder()],
|
|
134
|
+
["totalExercisedValue", getU64Decoder()],
|
|
135
|
+
["totalLenderRepaid", getU64Decoder()],
|
|
136
|
+
["totalMakerReturned", getU64Decoder()],
|
|
137
|
+
["makerCount", getU32Decoder()],
|
|
138
|
+
["isExercised", getBooleanDecoder()],
|
|
139
|
+
["isFullySettled", getBooleanDecoder()],
|
|
140
|
+
["createdAt", getI64Decoder()],
|
|
141
|
+
["lastUpdated", getI64Decoder()],
|
|
142
|
+
["bump", getU8Decoder()],
|
|
143
|
+
]);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Gets the codec for {@link CollateralPool} account data. */
|
|
147
|
+
export function getCollateralPoolCodec(): FixedSizeCodec<
|
|
148
|
+
CollateralPoolArgs,
|
|
149
|
+
CollateralPool
|
|
150
|
+
> {
|
|
151
|
+
return combineCodec(getCollateralPoolEncoder(), getCollateralPoolDecoder());
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function decodeCollateralPool<TAddress extends string = string>(
|
|
155
|
+
encodedAccount: EncodedAccount<TAddress>,
|
|
156
|
+
): Account<CollateralPool, TAddress>;
|
|
157
|
+
export function decodeCollateralPool<TAddress extends string = string>(
|
|
158
|
+
encodedAccount: MaybeEncodedAccount<TAddress>,
|
|
159
|
+
): MaybeAccount<CollateralPool, TAddress>;
|
|
160
|
+
export function decodeCollateralPool<TAddress extends string = string>(
|
|
161
|
+
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
|
|
162
|
+
): Account<CollateralPool, TAddress> | MaybeAccount<CollateralPool, TAddress> {
|
|
163
|
+
return decodeAccount(
|
|
164
|
+
encodedAccount as MaybeEncodedAccount<TAddress>,
|
|
165
|
+
getCollateralPoolDecoder(),
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export async function fetchCollateralPool<TAddress extends string = string>(
|
|
170
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
171
|
+
address: Address<TAddress>,
|
|
172
|
+
config?: FetchAccountConfig,
|
|
173
|
+
): Promise<Account<CollateralPool, TAddress>> {
|
|
174
|
+
const maybeAccount = await fetchMaybeCollateralPool(rpc, address, config);
|
|
175
|
+
assertAccountExists(maybeAccount);
|
|
176
|
+
return maybeAccount;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export async function fetchMaybeCollateralPool<
|
|
180
|
+
TAddress extends string = string,
|
|
181
|
+
>(
|
|
182
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
183
|
+
address: Address<TAddress>,
|
|
184
|
+
config?: FetchAccountConfig,
|
|
185
|
+
): Promise<MaybeAccount<CollateralPool, TAddress>> {
|
|
186
|
+
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
187
|
+
return decodeCollateralPool(maybeAccount);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export async function fetchAllCollateralPool(
|
|
191
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
192
|
+
addresses: Array<Address>,
|
|
193
|
+
config?: FetchAccountsConfig,
|
|
194
|
+
): Promise<Account<CollateralPool>[]> {
|
|
195
|
+
const maybeAccounts = await fetchAllMaybeCollateralPool(
|
|
196
|
+
rpc,
|
|
197
|
+
addresses,
|
|
198
|
+
config,
|
|
199
|
+
);
|
|
200
|
+
assertAccountsExist(maybeAccounts);
|
|
201
|
+
return maybeAccounts;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export async function fetchAllMaybeCollateralPool(
|
|
205
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
206
|
+
addresses: Array<Address>,
|
|
207
|
+
config?: FetchAccountsConfig,
|
|
208
|
+
): Promise<MaybeAccount<CollateralPool>[]> {
|
|
209
|
+
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
210
|
+
return maybeAccounts.map((maybeAccount) =>
|
|
211
|
+
decodeCollateralPool(maybeAccount),
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function getCollateralPoolSize(): number {
|
|
216
|
+
return 183;
|
|
217
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
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
|
+
decodeAccount,
|
|
14
|
+
fetchEncodedAccount,
|
|
15
|
+
fetchEncodedAccounts,
|
|
16
|
+
fixDecoderSize,
|
|
17
|
+
fixEncoderSize,
|
|
18
|
+
getAddressDecoder,
|
|
19
|
+
getAddressEncoder,
|
|
20
|
+
getBytesDecoder,
|
|
21
|
+
getBytesEncoder,
|
|
22
|
+
getOptionDecoder,
|
|
23
|
+
getOptionEncoder,
|
|
24
|
+
getStructDecoder,
|
|
25
|
+
getStructEncoder,
|
|
26
|
+
getU8Decoder,
|
|
27
|
+
getU8Encoder,
|
|
28
|
+
transformEncoder,
|
|
29
|
+
type Account,
|
|
30
|
+
type Address,
|
|
31
|
+
type Codec,
|
|
32
|
+
type Decoder,
|
|
33
|
+
type EncodedAccount,
|
|
34
|
+
type Encoder,
|
|
35
|
+
type FetchAccountConfig,
|
|
36
|
+
type FetchAccountsConfig,
|
|
37
|
+
type MaybeAccount,
|
|
38
|
+
type MaybeEncodedAccount,
|
|
39
|
+
type Option,
|
|
40
|
+
type OptionOrNullable,
|
|
41
|
+
type ReadonlyUint8Array,
|
|
42
|
+
} from "@solana/kit";
|
|
43
|
+
|
|
44
|
+
export const CONFIG_DISCRIMINATOR = new Uint8Array([
|
|
45
|
+
155, 12, 170, 224, 30, 250, 204, 130,
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
export function getConfigDiscriminatorBytes() {
|
|
49
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(CONFIG_DISCRIMINATOR);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type Config = {
|
|
53
|
+
discriminator: ReadonlyUint8Array;
|
|
54
|
+
/** Current admin authority (governance multisig or hot wallet) */
|
|
55
|
+
admin: Address;
|
|
56
|
+
/** Optional pending admin for two-step transfer */
|
|
57
|
+
pendingAdmin: Option<Address>;
|
|
58
|
+
/** Protocol flags (reserved for future use: pausing, etc.) */
|
|
59
|
+
flags: number;
|
|
60
|
+
/** PDA bump */
|
|
61
|
+
bump: number;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type ConfigArgs = {
|
|
65
|
+
/** Current admin authority (governance multisig or hot wallet) */
|
|
66
|
+
admin: Address;
|
|
67
|
+
/** Optional pending admin for two-step transfer */
|
|
68
|
+
pendingAdmin: OptionOrNullable<Address>;
|
|
69
|
+
/** Protocol flags (reserved for future use: pausing, etc.) */
|
|
70
|
+
flags: number;
|
|
71
|
+
/** PDA bump */
|
|
72
|
+
bump: number;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/** Gets the encoder for {@link ConfigArgs} account data. */
|
|
76
|
+
export function getConfigEncoder(): Encoder<ConfigArgs> {
|
|
77
|
+
return transformEncoder(
|
|
78
|
+
getStructEncoder([
|
|
79
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
80
|
+
["admin", getAddressEncoder()],
|
|
81
|
+
["pendingAdmin", getOptionEncoder(getAddressEncoder())],
|
|
82
|
+
["flags", getU8Encoder()],
|
|
83
|
+
["bump", getU8Encoder()],
|
|
84
|
+
]),
|
|
85
|
+
(value) => ({ ...value, discriminator: CONFIG_DISCRIMINATOR }),
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Gets the decoder for {@link Config} account data. */
|
|
90
|
+
export function getConfigDecoder(): Decoder<Config> {
|
|
91
|
+
return getStructDecoder([
|
|
92
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
93
|
+
["admin", getAddressDecoder()],
|
|
94
|
+
["pendingAdmin", getOptionDecoder(getAddressDecoder())],
|
|
95
|
+
["flags", getU8Decoder()],
|
|
96
|
+
["bump", getU8Decoder()],
|
|
97
|
+
]);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Gets the codec for {@link Config} account data. */
|
|
101
|
+
export function getConfigCodec(): Codec<ConfigArgs, Config> {
|
|
102
|
+
return combineCodec(getConfigEncoder(), getConfigDecoder());
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function decodeConfig<TAddress extends string = string>(
|
|
106
|
+
encodedAccount: EncodedAccount<TAddress>,
|
|
107
|
+
): Account<Config, TAddress>;
|
|
108
|
+
export function decodeConfig<TAddress extends string = string>(
|
|
109
|
+
encodedAccount: MaybeEncodedAccount<TAddress>,
|
|
110
|
+
): MaybeAccount<Config, TAddress>;
|
|
111
|
+
export function decodeConfig<TAddress extends string = string>(
|
|
112
|
+
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
|
|
113
|
+
): Account<Config, TAddress> | MaybeAccount<Config, TAddress> {
|
|
114
|
+
return decodeAccount(
|
|
115
|
+
encodedAccount as MaybeEncodedAccount<TAddress>,
|
|
116
|
+
getConfigDecoder(),
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export async function fetchConfig<TAddress extends string = string>(
|
|
121
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
122
|
+
address: Address<TAddress>,
|
|
123
|
+
config?: FetchAccountConfig,
|
|
124
|
+
): Promise<Account<Config, TAddress>> {
|
|
125
|
+
const maybeAccount = await fetchMaybeConfig(rpc, address, config);
|
|
126
|
+
assertAccountExists(maybeAccount);
|
|
127
|
+
return maybeAccount;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export async function fetchMaybeConfig<TAddress extends string = string>(
|
|
131
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
132
|
+
address: Address<TAddress>,
|
|
133
|
+
config?: FetchAccountConfig,
|
|
134
|
+
): Promise<MaybeAccount<Config, TAddress>> {
|
|
135
|
+
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
136
|
+
return decodeConfig(maybeAccount);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export async function fetchAllConfig(
|
|
140
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
141
|
+
addresses: Array<Address>,
|
|
142
|
+
config?: FetchAccountsConfig,
|
|
143
|
+
): Promise<Account<Config>[]> {
|
|
144
|
+
const maybeAccounts = await fetchAllMaybeConfig(rpc, addresses, config);
|
|
145
|
+
assertAccountsExist(maybeAccounts);
|
|
146
|
+
return maybeAccounts;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export async function fetchAllMaybeConfig(
|
|
150
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
151
|
+
addresses: Array<Address>,
|
|
152
|
+
config?: FetchAccountsConfig,
|
|
153
|
+
): Promise<MaybeAccount<Config>[]> {
|
|
154
|
+
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
155
|
+
return maybeAccounts.map((maybeAccount) => decodeConfig(maybeAccount));
|
|
156
|
+
}
|