@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.
Files changed (113) hide show
  1. package/.env.example +1 -0
  2. package/AGENTS.md +7 -0
  3. package/LICENSE +21 -0
  4. package/README.md +568 -0
  5. package/accounts/fetchers.ts +196 -0
  6. package/accounts/list.ts +184 -0
  7. package/accounts/pdas.ts +325 -0
  8. package/accounts/resolve-option.ts +104 -0
  9. package/client/lookup-table.ts +114 -0
  10. package/client/program.ts +13 -0
  11. package/client/types.ts +9 -0
  12. package/generated/accounts/collateralPool.ts +217 -0
  13. package/generated/accounts/config.ts +156 -0
  14. package/generated/accounts/escrowState.ts +183 -0
  15. package/generated/accounts/index.ts +20 -0
  16. package/generated/accounts/lenderPosition.ts +211 -0
  17. package/generated/accounts/makerCollateralShare.ts +229 -0
  18. package/generated/accounts/marketDataAccount.ts +176 -0
  19. package/generated/accounts/optionAccount.ts +247 -0
  20. package/generated/accounts/optionPool.ts +285 -0
  21. package/generated/accounts/poolLoan.ts +232 -0
  22. package/generated/accounts/positionAccount.ts +201 -0
  23. package/generated/accounts/vault.ts +366 -0
  24. package/generated/accounts/writerPosition.ts +327 -0
  25. package/generated/errors/index.ts +9 -0
  26. package/generated/errors/optionProgram.ts +476 -0
  27. package/generated/index.ts +13 -0
  28. package/generated/instructions/acceptAdmin.ts +230 -0
  29. package/generated/instructions/autoExerciseAllExpired.ts +685 -0
  30. package/generated/instructions/autoExerciseExpired.ts +754 -0
  31. package/generated/instructions/borrowFromPool.ts +619 -0
  32. package/generated/instructions/buyFromPool.ts +761 -0
  33. package/generated/instructions/closeLongToPool.ts +762 -0
  34. package/generated/instructions/closeOption.ts +235 -0
  35. package/generated/instructions/createEscrowV2.ts +518 -0
  36. package/generated/instructions/depositCollateral.ts +624 -0
  37. package/generated/instructions/depositToPosition.ts +429 -0
  38. package/generated/instructions/index.ts +47 -0
  39. package/generated/instructions/initCollateralPool.ts +513 -0
  40. package/generated/instructions/initConfig.ts +279 -0
  41. package/generated/instructions/initOptionPool.ts +587 -0
  42. package/generated/instructions/initializeMarketData.ts +359 -0
  43. package/generated/instructions/liquidateWriterPosition.ts +750 -0
  44. package/generated/instructions/liquidateWriterPositionRescue.ts +623 -0
  45. package/generated/instructions/omlpCreateVault.ts +553 -0
  46. package/generated/instructions/omlpUpdateFeeWallet.ts +473 -0
  47. package/generated/instructions/omlpUpdateInterestModel.ts +322 -0
  48. package/generated/instructions/omlpUpdateLiquidationThreshold.ts +304 -0
  49. package/generated/instructions/omlpUpdateMaintenanceBuffer.ts +304 -0
  50. package/generated/instructions/omlpUpdateMaxBorrowCap.ts +304 -0
  51. package/generated/instructions/omlpUpdateMaxLeverage.ts +304 -0
  52. package/generated/instructions/omlpUpdateProtocolFee.ts +304 -0
  53. package/generated/instructions/omlpUpdateSupplyLimit.ts +304 -0
  54. package/generated/instructions/optionExercise.ts +617 -0
  55. package/generated/instructions/optionMint.ts +1373 -0
  56. package/generated/instructions/optionValidate.ts +302 -0
  57. package/generated/instructions/repayPoolLoan.ts +558 -0
  58. package/generated/instructions/repayPoolLoanFromCollateral.ts +514 -0
  59. package/generated/instructions/repayPoolLoanFromWallet.ts +542 -0
  60. package/generated/instructions/settleMakerCollateral.ts +509 -0
  61. package/generated/instructions/syncWriterPosition.ts +206 -0
  62. package/generated/instructions/transferAdmin.ts +245 -0
  63. package/generated/instructions/unwindWriterUnsold.ts +764 -0
  64. package/generated/instructions/updateImpliedVolatility.ts +226 -0
  65. package/generated/instructions/updateMarketData.ts +315 -0
  66. package/generated/instructions/withdrawFromPosition.ts +405 -0
  67. package/generated/instructions/writeToPool.ts +619 -0
  68. package/generated/programs/index.ts +9 -0
  69. package/generated/programs/optionProgram.ts +1144 -0
  70. package/generated/shared/index.ts +164 -0
  71. package/generated/types/impliedVolatilityUpdated.ts +73 -0
  72. package/generated/types/index.ts +28 -0
  73. package/generated/types/liquidationExecuted.ts +73 -0
  74. package/generated/types/liquidationRescueEvent.ts +82 -0
  75. package/generated/types/marketDataInitialized.ts +61 -0
  76. package/generated/types/marketDataUpdated.ts +69 -0
  77. package/generated/types/optionClosed.ts +56 -0
  78. package/generated/types/optionExercised.ts +62 -0
  79. package/generated/types/optionExpired.ts +49 -0
  80. package/generated/types/optionMinted.ts +78 -0
  81. package/generated/types/optionType.ts +38 -0
  82. package/generated/types/optionValidated.ts +82 -0
  83. package/generated/types/poolLoanCreated.ts +74 -0
  84. package/generated/types/poolLoanRepaid.ts +74 -0
  85. package/generated/types/positionDeposited.ts +73 -0
  86. package/generated/types/positionWithdrawn.ts +81 -0
  87. package/generated/types/protocolFeeUpdated.ts +69 -0
  88. package/generated/types/vaultCreated.ts +60 -0
  89. package/generated/types/vaultFeeWalletUpdated.ts +67 -0
  90. package/generated/types/vaultInterestModelUpdated.ts +77 -0
  91. package/generated/types/vaultLiquidationThresholdUpdated.ts +69 -0
  92. package/index.ts +68 -0
  93. package/long/builders.ts +690 -0
  94. package/long/exercise.ts +123 -0
  95. package/long/preflight.ts +214 -0
  96. package/long/quotes.ts +48 -0
  97. package/long/remaining-accounts.ts +111 -0
  98. package/omlp/builders.ts +94 -0
  99. package/omlp/service.ts +136 -0
  100. package/oracle/switchboard.ts +315 -0
  101. package/package.json +34 -0
  102. package/shared/amounts.ts +53 -0
  103. package/shared/balances.ts +57 -0
  104. package/shared/errors.ts +12 -0
  105. package/shared/remaining-accounts.ts +41 -0
  106. package/shared/trade-config.ts +27 -0
  107. package/shared/transactions.ts +121 -0
  108. package/short/builders.ts +874 -0
  109. package/short/close-option.ts +34 -0
  110. package/short/pool.ts +189 -0
  111. package/short/preflight.ts +619 -0
  112. package/tsconfig.json +13 -0
  113. package/wsol/instructions.ts +247 -0
@@ -0,0 +1,183 @@
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
+ getI64Decoder,
23
+ getI64Encoder,
24
+ getStructDecoder,
25
+ getStructEncoder,
26
+ getU64Decoder,
27
+ getU64Encoder,
28
+ getU8Decoder,
29
+ getU8Encoder,
30
+ transformEncoder,
31
+ type Account,
32
+ type Address,
33
+ type EncodedAccount,
34
+ type FetchAccountConfig,
35
+ type FetchAccountsConfig,
36
+ type FixedSizeCodec,
37
+ type FixedSizeDecoder,
38
+ type FixedSizeEncoder,
39
+ type MaybeAccount,
40
+ type MaybeEncodedAccount,
41
+ type ReadonlyUint8Array,
42
+ } from "@solana/kit";
43
+
44
+ export const ESCROW_STATE_DISCRIMINATOR = new Uint8Array([
45
+ 19, 90, 148, 111, 55, 130, 229, 108,
46
+ ]);
47
+
48
+ export function getEscrowStateDiscriminatorBytes() {
49
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
50
+ ESCROW_STATE_DISCRIMINATOR,
51
+ );
52
+ }
53
+
54
+ export type EscrowState = {
55
+ discriminator: ReadonlyUint8Array;
56
+ /** The maker who owns this escrow */
57
+ maker: Address;
58
+ /** The collateral mint (e.g., WSOL) */
59
+ collateralMint: Address;
60
+ /** PDA bump */
61
+ bump: number;
62
+ /** Total deposited to escrow (maker's own funds + borrowed) */
63
+ deposited: bigint;
64
+ /** Total borrowed principal from OMLP */
65
+ borrowedPrincipal: bigint;
66
+ /** Total repaid to lenders */
67
+ repaidTotal: bigint;
68
+ /** Creation timestamp */
69
+ createdAt: bigint;
70
+ };
71
+
72
+ export type EscrowStateArgs = {
73
+ /** The maker who owns this escrow */
74
+ maker: Address;
75
+ /** The collateral mint (e.g., WSOL) */
76
+ collateralMint: Address;
77
+ /** PDA bump */
78
+ bump: number;
79
+ /** Total deposited to escrow (maker's own funds + borrowed) */
80
+ deposited: number | bigint;
81
+ /** Total borrowed principal from OMLP */
82
+ borrowedPrincipal: number | bigint;
83
+ /** Total repaid to lenders */
84
+ repaidTotal: number | bigint;
85
+ /** Creation timestamp */
86
+ createdAt: number | bigint;
87
+ };
88
+
89
+ /** Gets the encoder for {@link EscrowStateArgs} account data. */
90
+ export function getEscrowStateEncoder(): FixedSizeEncoder<EscrowStateArgs> {
91
+ return transformEncoder(
92
+ getStructEncoder([
93
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
94
+ ["maker", getAddressEncoder()],
95
+ ["collateralMint", getAddressEncoder()],
96
+ ["bump", getU8Encoder()],
97
+ ["deposited", getU64Encoder()],
98
+ ["borrowedPrincipal", getU64Encoder()],
99
+ ["repaidTotal", getU64Encoder()],
100
+ ["createdAt", getI64Encoder()],
101
+ ]),
102
+ (value) => ({ ...value, discriminator: ESCROW_STATE_DISCRIMINATOR }),
103
+ );
104
+ }
105
+
106
+ /** Gets the decoder for {@link EscrowState} account data. */
107
+ export function getEscrowStateDecoder(): FixedSizeDecoder<EscrowState> {
108
+ return getStructDecoder([
109
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
110
+ ["maker", getAddressDecoder()],
111
+ ["collateralMint", getAddressDecoder()],
112
+ ["bump", getU8Decoder()],
113
+ ["deposited", getU64Decoder()],
114
+ ["borrowedPrincipal", getU64Decoder()],
115
+ ["repaidTotal", getU64Decoder()],
116
+ ["createdAt", getI64Decoder()],
117
+ ]);
118
+ }
119
+
120
+ /** Gets the codec for {@link EscrowState} account data. */
121
+ export function getEscrowStateCodec(): FixedSizeCodec<
122
+ EscrowStateArgs,
123
+ EscrowState
124
+ > {
125
+ return combineCodec(getEscrowStateEncoder(), getEscrowStateDecoder());
126
+ }
127
+
128
+ export function decodeEscrowState<TAddress extends string = string>(
129
+ encodedAccount: EncodedAccount<TAddress>,
130
+ ): Account<EscrowState, TAddress>;
131
+ export function decodeEscrowState<TAddress extends string = string>(
132
+ encodedAccount: MaybeEncodedAccount<TAddress>,
133
+ ): MaybeAccount<EscrowState, TAddress>;
134
+ export function decodeEscrowState<TAddress extends string = string>(
135
+ encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
136
+ ): Account<EscrowState, TAddress> | MaybeAccount<EscrowState, TAddress> {
137
+ return decodeAccount(
138
+ encodedAccount as MaybeEncodedAccount<TAddress>,
139
+ getEscrowStateDecoder(),
140
+ );
141
+ }
142
+
143
+ export async function fetchEscrowState<TAddress extends string = string>(
144
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
145
+ address: Address<TAddress>,
146
+ config?: FetchAccountConfig,
147
+ ): Promise<Account<EscrowState, TAddress>> {
148
+ const maybeAccount = await fetchMaybeEscrowState(rpc, address, config);
149
+ assertAccountExists(maybeAccount);
150
+ return maybeAccount;
151
+ }
152
+
153
+ export async function fetchMaybeEscrowState<TAddress extends string = string>(
154
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
155
+ address: Address<TAddress>,
156
+ config?: FetchAccountConfig,
157
+ ): Promise<MaybeAccount<EscrowState, TAddress>> {
158
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
159
+ return decodeEscrowState(maybeAccount);
160
+ }
161
+
162
+ export async function fetchAllEscrowState(
163
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
164
+ addresses: Array<Address>,
165
+ config?: FetchAccountsConfig,
166
+ ): Promise<Account<EscrowState>[]> {
167
+ const maybeAccounts = await fetchAllMaybeEscrowState(rpc, addresses, config);
168
+ assertAccountsExist(maybeAccounts);
169
+ return maybeAccounts;
170
+ }
171
+
172
+ export async function fetchAllMaybeEscrowState(
173
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
174
+ addresses: Array<Address>,
175
+ config?: FetchAccountsConfig,
176
+ ): Promise<MaybeAccount<EscrowState>[]> {
177
+ const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
178
+ return maybeAccounts.map((maybeAccount) => decodeEscrowState(maybeAccount));
179
+ }
180
+
181
+ export function getEscrowStateSize(): number {
182
+ return 105;
183
+ }
@@ -0,0 +1,20 @@
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 "./collateralPool";
10
+ export * from "./config";
11
+ export * from "./escrowState";
12
+ export * from "./lenderPosition";
13
+ export * from "./makerCollateralShare";
14
+ export * from "./marketDataAccount";
15
+ export * from "./optionAccount";
16
+ export * from "./optionPool";
17
+ export * from "./poolLoan";
18
+ export * from "./positionAccount";
19
+ export * from "./vault";
20
+ export * from "./writerPosition";
@@ -0,0 +1,211 @@
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
+ getI64Decoder,
23
+ getI64Encoder,
24
+ getStructDecoder,
25
+ getStructEncoder,
26
+ getU128Decoder,
27
+ getU128Encoder,
28
+ getU64Decoder,
29
+ getU64Encoder,
30
+ getU8Decoder,
31
+ getU8Encoder,
32
+ transformEncoder,
33
+ type Account,
34
+ type Address,
35
+ type EncodedAccount,
36
+ type FetchAccountConfig,
37
+ type FetchAccountsConfig,
38
+ type FixedSizeCodec,
39
+ type FixedSizeDecoder,
40
+ type FixedSizeEncoder,
41
+ type MaybeAccount,
42
+ type MaybeEncodedAccount,
43
+ type ReadonlyUint8Array,
44
+ } from "@solana/kit";
45
+
46
+ export const LENDER_POSITION_DISCRIMINATOR = new Uint8Array([
47
+ 165, 98, 244, 204, 209, 158, 88, 19,
48
+ ]);
49
+
50
+ export function getLenderPositionDiscriminatorBytes() {
51
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
52
+ LENDER_POSITION_DISCRIMINATOR,
53
+ );
54
+ }
55
+
56
+ export type LenderPosition = {
57
+ discriminator: ReadonlyUint8Array;
58
+ /** Lender who owns this position */
59
+ lender: Address;
60
+ /** Associated vault */
61
+ vault: Address;
62
+ /** User's current deposited amount (their share of the pool) */
63
+ deposited: bigint;
64
+ /** Total interest earned by this user (lifetime) - lazily updated */
65
+ totalInterestEarned: bigint;
66
+ /** Interest already claimed/withdrawn by this user */
67
+ interestClaimed: bigint;
68
+ /** Position created timestamp */
69
+ createdAt: bigint;
70
+ /** Last update timestamp */
71
+ lastUpdated: bigint;
72
+ /** PDA bump */
73
+ bump: number;
74
+ /**
75
+ * Snapshot of vault's acc_interest_per_share_fp at last interaction
76
+ * Used to calculate pending interest: (current_index - snapshot) * deposited / FP_SCALE
77
+ */
78
+ interestIndexSnapshotFp: bigint;
79
+ };
80
+
81
+ export type LenderPositionArgs = {
82
+ /** Lender who owns this position */
83
+ lender: Address;
84
+ /** Associated vault */
85
+ vault: Address;
86
+ /** User's current deposited amount (their share of the pool) */
87
+ deposited: number | bigint;
88
+ /** Total interest earned by this user (lifetime) - lazily updated */
89
+ totalInterestEarned: number | bigint;
90
+ /** Interest already claimed/withdrawn by this user */
91
+ interestClaimed: number | bigint;
92
+ /** Position created timestamp */
93
+ createdAt: number | bigint;
94
+ /** Last update timestamp */
95
+ lastUpdated: number | bigint;
96
+ /** PDA bump */
97
+ bump: number;
98
+ /**
99
+ * Snapshot of vault's acc_interest_per_share_fp at last interaction
100
+ * Used to calculate pending interest: (current_index - snapshot) * deposited / FP_SCALE
101
+ */
102
+ interestIndexSnapshotFp: number | bigint;
103
+ };
104
+
105
+ /** Gets the encoder for {@link LenderPositionArgs} account data. */
106
+ export function getLenderPositionEncoder(): FixedSizeEncoder<LenderPositionArgs> {
107
+ return transformEncoder(
108
+ getStructEncoder([
109
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
110
+ ["lender", getAddressEncoder()],
111
+ ["vault", getAddressEncoder()],
112
+ ["deposited", getU64Encoder()],
113
+ ["totalInterestEarned", getU64Encoder()],
114
+ ["interestClaimed", getU64Encoder()],
115
+ ["createdAt", getI64Encoder()],
116
+ ["lastUpdated", getI64Encoder()],
117
+ ["bump", getU8Encoder()],
118
+ ["interestIndexSnapshotFp", getU128Encoder()],
119
+ ]),
120
+ (value) => ({ ...value, discriminator: LENDER_POSITION_DISCRIMINATOR }),
121
+ );
122
+ }
123
+
124
+ /** Gets the decoder for {@link LenderPosition} account data. */
125
+ export function getLenderPositionDecoder(): FixedSizeDecoder<LenderPosition> {
126
+ return getStructDecoder([
127
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
128
+ ["lender", getAddressDecoder()],
129
+ ["vault", getAddressDecoder()],
130
+ ["deposited", getU64Decoder()],
131
+ ["totalInterestEarned", getU64Decoder()],
132
+ ["interestClaimed", getU64Decoder()],
133
+ ["createdAt", getI64Decoder()],
134
+ ["lastUpdated", getI64Decoder()],
135
+ ["bump", getU8Decoder()],
136
+ ["interestIndexSnapshotFp", getU128Decoder()],
137
+ ]);
138
+ }
139
+
140
+ /** Gets the codec for {@link LenderPosition} account data. */
141
+ export function getLenderPositionCodec(): FixedSizeCodec<
142
+ LenderPositionArgs,
143
+ LenderPosition
144
+ > {
145
+ return combineCodec(getLenderPositionEncoder(), getLenderPositionDecoder());
146
+ }
147
+
148
+ export function decodeLenderPosition<TAddress extends string = string>(
149
+ encodedAccount: EncodedAccount<TAddress>,
150
+ ): Account<LenderPosition, TAddress>;
151
+ export function decodeLenderPosition<TAddress extends string = string>(
152
+ encodedAccount: MaybeEncodedAccount<TAddress>,
153
+ ): MaybeAccount<LenderPosition, TAddress>;
154
+ export function decodeLenderPosition<TAddress extends string = string>(
155
+ encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
156
+ ): Account<LenderPosition, TAddress> | MaybeAccount<LenderPosition, TAddress> {
157
+ return decodeAccount(
158
+ encodedAccount as MaybeEncodedAccount<TAddress>,
159
+ getLenderPositionDecoder(),
160
+ );
161
+ }
162
+
163
+ export async function fetchLenderPosition<TAddress extends string = string>(
164
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
165
+ address: Address<TAddress>,
166
+ config?: FetchAccountConfig,
167
+ ): Promise<Account<LenderPosition, TAddress>> {
168
+ const maybeAccount = await fetchMaybeLenderPosition(rpc, address, config);
169
+ assertAccountExists(maybeAccount);
170
+ return maybeAccount;
171
+ }
172
+
173
+ export async function fetchMaybeLenderPosition<
174
+ TAddress extends string = string,
175
+ >(
176
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
177
+ address: Address<TAddress>,
178
+ config?: FetchAccountConfig,
179
+ ): Promise<MaybeAccount<LenderPosition, TAddress>> {
180
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
181
+ return decodeLenderPosition(maybeAccount);
182
+ }
183
+
184
+ export async function fetchAllLenderPosition(
185
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
186
+ addresses: Array<Address>,
187
+ config?: FetchAccountsConfig,
188
+ ): Promise<Account<LenderPosition>[]> {
189
+ const maybeAccounts = await fetchAllMaybeLenderPosition(
190
+ rpc,
191
+ addresses,
192
+ config,
193
+ );
194
+ assertAccountsExist(maybeAccounts);
195
+ return maybeAccounts;
196
+ }
197
+
198
+ export async function fetchAllMaybeLenderPosition(
199
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
200
+ addresses: Array<Address>,
201
+ config?: FetchAccountsConfig,
202
+ ): Promise<MaybeAccount<LenderPosition>[]> {
203
+ const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
204
+ return maybeAccounts.map((maybeAccount) =>
205
+ decodeLenderPosition(maybeAccount),
206
+ );
207
+ }
208
+
209
+ export function getLenderPositionSize(): number {
210
+ return 129;
211
+ }
@@ -0,0 +1,229 @@
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
+ getU64Decoder,
29
+ getU64Encoder,
30
+ getU8Decoder,
31
+ getU8Encoder,
32
+ transformEncoder,
33
+ type Account,
34
+ type Address,
35
+ type EncodedAccount,
36
+ type FetchAccountConfig,
37
+ type FetchAccountsConfig,
38
+ type FixedSizeCodec,
39
+ type FixedSizeDecoder,
40
+ type FixedSizeEncoder,
41
+ type MaybeAccount,
42
+ type MaybeEncodedAccount,
43
+ type ReadonlyUint8Array,
44
+ } from "@solana/kit";
45
+
46
+ export const MAKER_COLLATERAL_SHARE_DISCRIMINATOR = new Uint8Array([
47
+ 44, 113, 163, 132, 92, 188, 13, 158,
48
+ ]);
49
+
50
+ export function getMakerCollateralShareDiscriminatorBytes() {
51
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
52
+ MAKER_COLLATERAL_SHARE_DISCRIMINATOR,
53
+ );
54
+ }
55
+
56
+ export type MakerCollateralShare = {
57
+ discriminator: ReadonlyUint8Array;
58
+ maker: Address;
59
+ collateralPool: Address;
60
+ optionAccount: Address;
61
+ collateralProvided: bigint;
62
+ borrowedAmount: bigint;
63
+ interestOwed: bigint;
64
+ quantityBacked: bigint;
65
+ premiumCollected: bigint;
66
+ exercisePayout: bigint;
67
+ lenderRepayment: bigint;
68
+ makerReturn: bigint;
69
+ isSettled: boolean;
70
+ realizedPnl: bigint;
71
+ createdAt: bigint;
72
+ lastUpdated: bigint;
73
+ bump: number;
74
+ };
75
+
76
+ export type MakerCollateralShareArgs = {
77
+ maker: Address;
78
+ collateralPool: Address;
79
+ optionAccount: Address;
80
+ collateralProvided: number | bigint;
81
+ borrowedAmount: number | bigint;
82
+ interestOwed: number | bigint;
83
+ quantityBacked: number | bigint;
84
+ premiumCollected: number | bigint;
85
+ exercisePayout: number | bigint;
86
+ lenderRepayment: number | bigint;
87
+ makerReturn: number | bigint;
88
+ isSettled: boolean;
89
+ realizedPnl: number | bigint;
90
+ createdAt: number | bigint;
91
+ lastUpdated: number | bigint;
92
+ bump: number;
93
+ };
94
+
95
+ /** Gets the encoder for {@link MakerCollateralShareArgs} account data. */
96
+ export function getMakerCollateralShareEncoder(): FixedSizeEncoder<MakerCollateralShareArgs> {
97
+ return transformEncoder(
98
+ getStructEncoder([
99
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
100
+ ["maker", getAddressEncoder()],
101
+ ["collateralPool", getAddressEncoder()],
102
+ ["optionAccount", getAddressEncoder()],
103
+ ["collateralProvided", getU64Encoder()],
104
+ ["borrowedAmount", getU64Encoder()],
105
+ ["interestOwed", getU64Encoder()],
106
+ ["quantityBacked", getU64Encoder()],
107
+ ["premiumCollected", getU64Encoder()],
108
+ ["exercisePayout", getU64Encoder()],
109
+ ["lenderRepayment", getU64Encoder()],
110
+ ["makerReturn", getU64Encoder()],
111
+ ["isSettled", getBooleanEncoder()],
112
+ ["realizedPnl", getI64Encoder()],
113
+ ["createdAt", getI64Encoder()],
114
+ ["lastUpdated", getI64Encoder()],
115
+ ["bump", getU8Encoder()],
116
+ ]),
117
+ (value) => ({
118
+ ...value,
119
+ discriminator: MAKER_COLLATERAL_SHARE_DISCRIMINATOR,
120
+ }),
121
+ );
122
+ }
123
+
124
+ /** Gets the decoder for {@link MakerCollateralShare} account data. */
125
+ export function getMakerCollateralShareDecoder(): FixedSizeDecoder<MakerCollateralShare> {
126
+ return getStructDecoder([
127
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
128
+ ["maker", getAddressDecoder()],
129
+ ["collateralPool", getAddressDecoder()],
130
+ ["optionAccount", getAddressDecoder()],
131
+ ["collateralProvided", getU64Decoder()],
132
+ ["borrowedAmount", getU64Decoder()],
133
+ ["interestOwed", getU64Decoder()],
134
+ ["quantityBacked", getU64Decoder()],
135
+ ["premiumCollected", getU64Decoder()],
136
+ ["exercisePayout", getU64Decoder()],
137
+ ["lenderRepayment", getU64Decoder()],
138
+ ["makerReturn", getU64Decoder()],
139
+ ["isSettled", getBooleanDecoder()],
140
+ ["realizedPnl", getI64Decoder()],
141
+ ["createdAt", getI64Decoder()],
142
+ ["lastUpdated", getI64Decoder()],
143
+ ["bump", getU8Decoder()],
144
+ ]);
145
+ }
146
+
147
+ /** Gets the codec for {@link MakerCollateralShare} account data. */
148
+ export function getMakerCollateralShareCodec(): FixedSizeCodec<
149
+ MakerCollateralShareArgs,
150
+ MakerCollateralShare
151
+ > {
152
+ return combineCodec(
153
+ getMakerCollateralShareEncoder(),
154
+ getMakerCollateralShareDecoder(),
155
+ );
156
+ }
157
+
158
+ export function decodeMakerCollateralShare<TAddress extends string = string>(
159
+ encodedAccount: EncodedAccount<TAddress>,
160
+ ): Account<MakerCollateralShare, TAddress>;
161
+ export function decodeMakerCollateralShare<TAddress extends string = string>(
162
+ encodedAccount: MaybeEncodedAccount<TAddress>,
163
+ ): MaybeAccount<MakerCollateralShare, TAddress>;
164
+ export function decodeMakerCollateralShare<TAddress extends string = string>(
165
+ encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
166
+ ):
167
+ | Account<MakerCollateralShare, TAddress>
168
+ | MaybeAccount<MakerCollateralShare, TAddress> {
169
+ return decodeAccount(
170
+ encodedAccount as MaybeEncodedAccount<TAddress>,
171
+ getMakerCollateralShareDecoder(),
172
+ );
173
+ }
174
+
175
+ export async function fetchMakerCollateralShare<
176
+ TAddress extends string = string,
177
+ >(
178
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
179
+ address: Address<TAddress>,
180
+ config?: FetchAccountConfig,
181
+ ): Promise<Account<MakerCollateralShare, TAddress>> {
182
+ const maybeAccount = await fetchMaybeMakerCollateralShare(
183
+ rpc,
184
+ address,
185
+ config,
186
+ );
187
+ assertAccountExists(maybeAccount);
188
+ return maybeAccount;
189
+ }
190
+
191
+ export async function fetchMaybeMakerCollateralShare<
192
+ TAddress extends string = string,
193
+ >(
194
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
195
+ address: Address<TAddress>,
196
+ config?: FetchAccountConfig,
197
+ ): Promise<MaybeAccount<MakerCollateralShare, TAddress>> {
198
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
199
+ return decodeMakerCollateralShare(maybeAccount);
200
+ }
201
+
202
+ export async function fetchAllMakerCollateralShare(
203
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
204
+ addresses: Array<Address>,
205
+ config?: FetchAccountsConfig,
206
+ ): Promise<Account<MakerCollateralShare>[]> {
207
+ const maybeAccounts = await fetchAllMaybeMakerCollateralShare(
208
+ rpc,
209
+ addresses,
210
+ config,
211
+ );
212
+ assertAccountsExist(maybeAccounts);
213
+ return maybeAccounts;
214
+ }
215
+
216
+ export async function fetchAllMaybeMakerCollateralShare(
217
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
218
+ addresses: Array<Address>,
219
+ config?: FetchAccountsConfig,
220
+ ): Promise<MaybeAccount<MakerCollateralShare>[]> {
221
+ const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
222
+ return maybeAccounts.map((maybeAccount) =>
223
+ decodeMakerCollateralShare(maybeAccount),
224
+ );
225
+ }
226
+
227
+ export function getMakerCollateralShareSize(): number {
228
+ return 194;
229
+ }