@exponent-labs/kamino-reserve-deserializer 0.0.3
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/CHANGELOG.md +16 -0
- package/build/fraction.d.ts +23 -0
- package/build/fraction.js +61 -0
- package/build/fraction.js.map +1 -0
- package/build/index.d.ts +102 -0
- package/build/index.js +214 -0
- package/build/index.js.map +1 -0
- package/build/types/BigFractionBytes.d.ts +26 -0
- package/build/types/BigFractionBytes.js +72 -0
- package/build/types/BigFractionBytes.js.map +1 -0
- package/build/types/BorrowRateCurve.d.ts +27 -0
- package/build/types/BorrowRateCurve.js +63 -0
- package/build/types/BorrowRateCurve.js.map +1 -0
- package/build/types/CurvePoint.d.ts +25 -0
- package/build/types/CurvePoint.js +68 -0
- package/build/types/CurvePoint.js.map +1 -0
- package/build/types/LastUpdate.d.ts +46 -0
- package/build/types/LastUpdate.js +88 -0
- package/build/types/LastUpdate.js.map +1 -0
- package/build/types/PriceHeuristic.d.ts +40 -0
- package/build/types/PriceHeuristic.js +81 -0
- package/build/types/PriceHeuristic.js.map +1 -0
- package/build/types/PythConfiguration.d.ts +24 -0
- package/build/types/PythConfiguration.js +64 -0
- package/build/types/PythConfiguration.js.map +1 -0
- package/build/types/ReserveCollateral.d.ts +52 -0
- package/build/types/ReserveCollateral.js +101 -0
- package/build/types/ReserveCollateral.js.map +1 -0
- package/build/types/ReserveConfig.d.ts +366 -0
- package/build/types/ReserveConfig.js +307 -0
- package/build/types/ReserveConfig.js.map +1 -0
- package/build/types/ReserveFees.d.ts +77 -0
- package/build/types/ReserveFees.js +98 -0
- package/build/types/ReserveFees.js.map +1 -0
- package/build/types/ReserveLiquidity.d.ts +181 -0
- package/build/types/ReserveLiquidity.js +214 -0
- package/build/types/ReserveLiquidity.js.map +1 -0
- package/build/types/ScopeConfiguration.d.ts +40 -0
- package/build/types/ScopeConfiguration.js +82 -0
- package/build/types/ScopeConfiguration.js.map +1 -0
- package/build/types/SwitchboardConfiguration.d.ts +29 -0
- package/build/types/SwitchboardConfiguration.js +70 -0
- package/build/types/SwitchboardConfiguration.js.map +1 -0
- package/build/types/TokenInfo.d.ts +121 -0
- package/build/types/TokenInfo.js +154 -0
- package/build/types/TokenInfo.js.map +1 -0
- package/build/types/WithdrawalCaps.d.ts +37 -0
- package/build/types/WithdrawalCaps.js +90 -0
- package/build/types/WithdrawalCaps.js.map +1 -0
- package/build/types/index.d.ts +46 -0
- package/build/types/index.js +88 -0
- package/build/types/index.js.map +1 -0
- package/package.json +20 -0
- package/src/fraction.ts +70 -0
- package/src/index.ts +269 -0
- package/src/types/BigFractionBytes.ts +59 -0
- package/src/types/BorrowRateCurve.ts +53 -0
- package/src/types/CurvePoint.ts +58 -0
- package/src/types/LastUpdate.ts +88 -0
- package/src/types/PriceHeuristic.ts +76 -0
- package/src/types/PythConfiguration.ts +54 -0
- package/src/types/ReserveCollateral.ts +103 -0
- package/src/types/ReserveConfig.ts +431 -0
- package/src/types/ReserveFees.ts +116 -0
- package/src/types/ReserveLiquidity.ts +280 -0
- package/src/types/ScopeConfiguration.ts +83 -0
- package/src/types/SwitchboardConfiguration.ts +62 -0
- package/src/types/TokenInfo.ts +178 -0
- package/src/types/WithdrawalCaps.ts +84 -0
- package/src/types/index.ts +88 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
2
|
+
import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
3
|
+
import * as borsh from "@coral-xyz/borsh"
|
|
4
|
+
import { BigFractionBytes, BigFractionBytesFields, BigFractionBytesJSON } from "./BigFractionBytes"
|
|
5
|
+
|
|
6
|
+
export interface ReserveLiquidityFields {
|
|
7
|
+
/** Reserve liquidity mint address */
|
|
8
|
+
mintPubkey: PublicKey
|
|
9
|
+
/** Reserve liquidity supply address */
|
|
10
|
+
supplyVault: PublicKey
|
|
11
|
+
/** Reserve liquidity fee collection address */
|
|
12
|
+
feeVault: PublicKey
|
|
13
|
+
/** Reserve liquidity available */
|
|
14
|
+
availableAmount: BN
|
|
15
|
+
/** Reserve liquidity borrowed (scaled fraction) */
|
|
16
|
+
borrowedAmountSf: BN
|
|
17
|
+
/** Reserve liquidity market price in quote currency (scaled fraction) */
|
|
18
|
+
marketPriceSf: BN
|
|
19
|
+
/** Unix timestamp of the market price (from the oracle) */
|
|
20
|
+
marketPriceLastUpdatedTs: BN
|
|
21
|
+
/** Reserve liquidity mint decimals */
|
|
22
|
+
mintDecimals: BN
|
|
23
|
+
/**
|
|
24
|
+
* Timestamp in slots when the last refresh reserve detected that the liquidity amount is above the deposit cap. When this threshold is crossed, then redemptions (auto-deleverage) are enabled.
|
|
25
|
+
* If the threshold is not crossed, then the timestamp is set to 0
|
|
26
|
+
*/
|
|
27
|
+
depositLimitCrossedSlot: BN
|
|
28
|
+
/**
|
|
29
|
+
* Timestamp in slots when the last refresh reserve detected that the borrowed amount is above the borrow cap. When this threshold is crossed, then redemptions (auto-deleverage) are enabled.
|
|
30
|
+
* If the threshold is not crossed, then the timestamp is set to 0
|
|
31
|
+
*/
|
|
32
|
+
borrowLimitCrossedSlot: BN
|
|
33
|
+
/** Reserve liquidity cumulative borrow rate (scaled fraction) */
|
|
34
|
+
cumulativeBorrowRateBsf: BigFractionBytesFields
|
|
35
|
+
/** Reserve cumulative protocol fees (scaled fraction) */
|
|
36
|
+
accumulatedProtocolFeesSf: BN
|
|
37
|
+
/** Reserve cumulative referrer fees (scaled fraction) */
|
|
38
|
+
accumulatedReferrerFeesSf: BN
|
|
39
|
+
/** Reserve pending referrer fees, to be claimed in refresh_obligation by referrer or protocol (scaled fraction) */
|
|
40
|
+
pendingReferrerFeesSf: BN
|
|
41
|
+
/** Reserve referrer fee absolute rate calculated at each refresh_reserve operation (scaled fraction) */
|
|
42
|
+
absoluteReferralRateSf: BN
|
|
43
|
+
/** Token program of the liquidity mint */
|
|
44
|
+
tokenProgram: PublicKey
|
|
45
|
+
padding2: Array<BN>
|
|
46
|
+
padding3: Array<BN>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface ReserveLiquidityJSON {
|
|
50
|
+
/** Reserve liquidity mint address */
|
|
51
|
+
mintPubkey: string
|
|
52
|
+
/** Reserve liquidity supply address */
|
|
53
|
+
supplyVault: string
|
|
54
|
+
/** Reserve liquidity fee collection address */
|
|
55
|
+
feeVault: string
|
|
56
|
+
/** Reserve liquidity available */
|
|
57
|
+
availableAmount: string
|
|
58
|
+
/** Reserve liquidity borrowed (scaled fraction) */
|
|
59
|
+
borrowedAmountSf: string
|
|
60
|
+
/** Reserve liquidity market price in quote currency (scaled fraction) */
|
|
61
|
+
marketPriceSf: string
|
|
62
|
+
/** Unix timestamp of the market price (from the oracle) */
|
|
63
|
+
marketPriceLastUpdatedTs: string
|
|
64
|
+
/** Reserve liquidity mint decimals */
|
|
65
|
+
mintDecimals: string
|
|
66
|
+
/**
|
|
67
|
+
* Timestamp in slots when the last refresh reserve detected that the liquidity amount is above the deposit cap. When this threshold is crossed, then redemptions (auto-deleverage) are enabled.
|
|
68
|
+
* If the threshold is not crossed, then the timestamp is set to 0
|
|
69
|
+
*/
|
|
70
|
+
depositLimitCrossedSlot: string
|
|
71
|
+
/**
|
|
72
|
+
* Timestamp in slots when the last refresh reserve detected that the borrowed amount is above the borrow cap. When this threshold is crossed, then redemptions (auto-deleverage) are enabled.
|
|
73
|
+
* If the threshold is not crossed, then the timestamp is set to 0
|
|
74
|
+
*/
|
|
75
|
+
borrowLimitCrossedSlot: string
|
|
76
|
+
/** Reserve liquidity cumulative borrow rate (scaled fraction) */
|
|
77
|
+
cumulativeBorrowRateBsf: BigFractionBytesJSON
|
|
78
|
+
/** Reserve cumulative protocol fees (scaled fraction) */
|
|
79
|
+
accumulatedProtocolFeesSf: string
|
|
80
|
+
/** Reserve cumulative referrer fees (scaled fraction) */
|
|
81
|
+
accumulatedReferrerFeesSf: string
|
|
82
|
+
/** Reserve pending referrer fees, to be claimed in refresh_obligation by referrer or protocol (scaled fraction) */
|
|
83
|
+
pendingReferrerFeesSf: string
|
|
84
|
+
/** Reserve referrer fee absolute rate calculated at each refresh_reserve operation (scaled fraction) */
|
|
85
|
+
absoluteReferralRateSf: string
|
|
86
|
+
/** Token program of the liquidity mint */
|
|
87
|
+
tokenProgram: string
|
|
88
|
+
padding2: Array<string>
|
|
89
|
+
padding3: Array<string>
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Reserve liquidity */
|
|
93
|
+
export class ReserveLiquidity {
|
|
94
|
+
/** Reserve liquidity mint address */
|
|
95
|
+
readonly mintPubkey: PublicKey
|
|
96
|
+
/** Reserve liquidity supply address */
|
|
97
|
+
readonly supplyVault: PublicKey
|
|
98
|
+
/** Reserve liquidity fee collection address */
|
|
99
|
+
readonly feeVault: PublicKey
|
|
100
|
+
/** Reserve liquidity available */
|
|
101
|
+
readonly availableAmount: BN
|
|
102
|
+
/** Reserve liquidity borrowed (scaled fraction) */
|
|
103
|
+
readonly borrowedAmountSf: BN
|
|
104
|
+
/** Reserve liquidity market price in quote currency (scaled fraction) */
|
|
105
|
+
readonly marketPriceSf: BN
|
|
106
|
+
/** Unix timestamp of the market price (from the oracle) */
|
|
107
|
+
readonly marketPriceLastUpdatedTs: BN
|
|
108
|
+
/** Reserve liquidity mint decimals */
|
|
109
|
+
readonly mintDecimals: BN
|
|
110
|
+
/**
|
|
111
|
+
* Timestamp in slots when the last refresh reserve detected that the liquidity amount is above the deposit cap. When this threshold is crossed, then redemptions (auto-deleverage) are enabled.
|
|
112
|
+
* If the threshold is not crossed, then the timestamp is set to 0
|
|
113
|
+
*/
|
|
114
|
+
readonly depositLimitCrossedSlot: BN
|
|
115
|
+
/**
|
|
116
|
+
* Timestamp in slots when the last refresh reserve detected that the borrowed amount is above the borrow cap. When this threshold is crossed, then redemptions (auto-deleverage) are enabled.
|
|
117
|
+
* If the threshold is not crossed, then the timestamp is set to 0
|
|
118
|
+
*/
|
|
119
|
+
readonly borrowLimitCrossedSlot: BN
|
|
120
|
+
/** Reserve liquidity cumulative borrow rate (scaled fraction) */
|
|
121
|
+
readonly cumulativeBorrowRateBsf: BigFractionBytes
|
|
122
|
+
/** Reserve cumulative protocol fees (scaled fraction) */
|
|
123
|
+
readonly accumulatedProtocolFeesSf: BN
|
|
124
|
+
/** Reserve cumulative referrer fees (scaled fraction) */
|
|
125
|
+
readonly accumulatedReferrerFeesSf: BN
|
|
126
|
+
/** Reserve pending referrer fees, to be claimed in refresh_obligation by referrer or protocol (scaled fraction) */
|
|
127
|
+
readonly pendingReferrerFeesSf: BN
|
|
128
|
+
/** Reserve referrer fee absolute rate calculated at each refresh_reserve operation (scaled fraction) */
|
|
129
|
+
readonly absoluteReferralRateSf: BN
|
|
130
|
+
/** Token program of the liquidity mint */
|
|
131
|
+
readonly tokenProgram: PublicKey
|
|
132
|
+
readonly padding2: Array<BN>
|
|
133
|
+
readonly padding3: Array<BN>
|
|
134
|
+
|
|
135
|
+
constructor(fields: ReserveLiquidityFields) {
|
|
136
|
+
this.mintPubkey = fields.mintPubkey
|
|
137
|
+
this.supplyVault = fields.supplyVault
|
|
138
|
+
this.feeVault = fields.feeVault
|
|
139
|
+
this.availableAmount = fields.availableAmount
|
|
140
|
+
this.borrowedAmountSf = fields.borrowedAmountSf
|
|
141
|
+
this.marketPriceSf = fields.marketPriceSf
|
|
142
|
+
this.marketPriceLastUpdatedTs = fields.marketPriceLastUpdatedTs
|
|
143
|
+
this.mintDecimals = fields.mintDecimals
|
|
144
|
+
this.depositLimitCrossedSlot = fields.depositLimitCrossedSlot
|
|
145
|
+
this.borrowLimitCrossedSlot = fields.borrowLimitCrossedSlot
|
|
146
|
+
this.cumulativeBorrowRateBsf = new BigFractionBytes({
|
|
147
|
+
...fields.cumulativeBorrowRateBsf,
|
|
148
|
+
})
|
|
149
|
+
this.accumulatedProtocolFeesSf = fields.accumulatedProtocolFeesSf
|
|
150
|
+
this.accumulatedReferrerFeesSf = fields.accumulatedReferrerFeesSf
|
|
151
|
+
this.pendingReferrerFeesSf = fields.pendingReferrerFeesSf
|
|
152
|
+
this.absoluteReferralRateSf = fields.absoluteReferralRateSf
|
|
153
|
+
this.tokenProgram = fields.tokenProgram
|
|
154
|
+
this.padding2 = fields.padding2
|
|
155
|
+
this.padding3 = fields.padding3
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
static layout(property?: string) {
|
|
159
|
+
return borsh.struct(
|
|
160
|
+
[
|
|
161
|
+
borsh.publicKey("mintPubkey"),
|
|
162
|
+
borsh.publicKey("supplyVault"),
|
|
163
|
+
borsh.publicKey("feeVault"),
|
|
164
|
+
borsh.u64("availableAmount"),
|
|
165
|
+
borsh.u128("borrowedAmountSf"),
|
|
166
|
+
borsh.u128("marketPriceSf"),
|
|
167
|
+
borsh.u64("marketPriceLastUpdatedTs"),
|
|
168
|
+
borsh.u64("mintDecimals"),
|
|
169
|
+
borsh.u64("depositLimitCrossedSlot"),
|
|
170
|
+
borsh.u64("borrowLimitCrossedSlot"),
|
|
171
|
+
BigFractionBytes.layout("cumulativeBorrowRateBsf"),
|
|
172
|
+
borsh.u128("accumulatedProtocolFeesSf"),
|
|
173
|
+
borsh.u128("accumulatedReferrerFeesSf"),
|
|
174
|
+
borsh.u128("pendingReferrerFeesSf"),
|
|
175
|
+
borsh.u128("absoluteReferralRateSf"),
|
|
176
|
+
borsh.publicKey("tokenProgram"),
|
|
177
|
+
borsh.array(borsh.u64(), 51, "padding2"),
|
|
178
|
+
borsh.array(borsh.u128(), 32, "padding3"),
|
|
179
|
+
],
|
|
180
|
+
property,
|
|
181
|
+
)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
185
|
+
static fromDecoded(obj: any) {
|
|
186
|
+
return new ReserveLiquidity({
|
|
187
|
+
mintPubkey: obj.mintPubkey,
|
|
188
|
+
supplyVault: obj.supplyVault,
|
|
189
|
+
feeVault: obj.feeVault,
|
|
190
|
+
availableAmount: obj.availableAmount,
|
|
191
|
+
borrowedAmountSf: obj.borrowedAmountSf,
|
|
192
|
+
marketPriceSf: obj.marketPriceSf,
|
|
193
|
+
marketPriceLastUpdatedTs: obj.marketPriceLastUpdatedTs,
|
|
194
|
+
mintDecimals: obj.mintDecimals,
|
|
195
|
+
depositLimitCrossedSlot: obj.depositLimitCrossedSlot,
|
|
196
|
+
borrowLimitCrossedSlot: obj.borrowLimitCrossedSlot,
|
|
197
|
+
cumulativeBorrowRateBsf: BigFractionBytes.fromDecoded(obj.cumulativeBorrowRateBsf),
|
|
198
|
+
accumulatedProtocolFeesSf: obj.accumulatedProtocolFeesSf,
|
|
199
|
+
accumulatedReferrerFeesSf: obj.accumulatedReferrerFeesSf,
|
|
200
|
+
pendingReferrerFeesSf: obj.pendingReferrerFeesSf,
|
|
201
|
+
absoluteReferralRateSf: obj.absoluteReferralRateSf,
|
|
202
|
+
tokenProgram: obj.tokenProgram,
|
|
203
|
+
padding2: obj.padding2,
|
|
204
|
+
padding3: obj.padding3,
|
|
205
|
+
})
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
static toEncodable(fields: ReserveLiquidityFields) {
|
|
209
|
+
return {
|
|
210
|
+
mintPubkey: fields.mintPubkey,
|
|
211
|
+
supplyVault: fields.supplyVault,
|
|
212
|
+
feeVault: fields.feeVault,
|
|
213
|
+
availableAmount: fields.availableAmount,
|
|
214
|
+
borrowedAmountSf: fields.borrowedAmountSf,
|
|
215
|
+
marketPriceSf: fields.marketPriceSf,
|
|
216
|
+
marketPriceLastUpdatedTs: fields.marketPriceLastUpdatedTs,
|
|
217
|
+
mintDecimals: fields.mintDecimals,
|
|
218
|
+
depositLimitCrossedSlot: fields.depositLimitCrossedSlot,
|
|
219
|
+
borrowLimitCrossedSlot: fields.borrowLimitCrossedSlot,
|
|
220
|
+
cumulativeBorrowRateBsf: BigFractionBytes.toEncodable(fields.cumulativeBorrowRateBsf),
|
|
221
|
+
accumulatedProtocolFeesSf: fields.accumulatedProtocolFeesSf,
|
|
222
|
+
accumulatedReferrerFeesSf: fields.accumulatedReferrerFeesSf,
|
|
223
|
+
pendingReferrerFeesSf: fields.pendingReferrerFeesSf,
|
|
224
|
+
absoluteReferralRateSf: fields.absoluteReferralRateSf,
|
|
225
|
+
tokenProgram: fields.tokenProgram,
|
|
226
|
+
padding2: fields.padding2,
|
|
227
|
+
padding3: fields.padding3,
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
toJSON(): ReserveLiquidityJSON {
|
|
232
|
+
return {
|
|
233
|
+
mintPubkey: this.mintPubkey.toString(),
|
|
234
|
+
supplyVault: this.supplyVault.toString(),
|
|
235
|
+
feeVault: this.feeVault.toString(),
|
|
236
|
+
availableAmount: this.availableAmount.toString(),
|
|
237
|
+
borrowedAmountSf: this.borrowedAmountSf.toString(),
|
|
238
|
+
marketPriceSf: this.marketPriceSf.toString(),
|
|
239
|
+
marketPriceLastUpdatedTs: this.marketPriceLastUpdatedTs.toString(),
|
|
240
|
+
mintDecimals: this.mintDecimals.toString(),
|
|
241
|
+
depositLimitCrossedSlot: this.depositLimitCrossedSlot.toString(),
|
|
242
|
+
borrowLimitCrossedSlot: this.borrowLimitCrossedSlot.toString(),
|
|
243
|
+
cumulativeBorrowRateBsf: this.cumulativeBorrowRateBsf.toJSON(),
|
|
244
|
+
accumulatedProtocolFeesSf: this.accumulatedProtocolFeesSf.toString(),
|
|
245
|
+
accumulatedReferrerFeesSf: this.accumulatedReferrerFeesSf.toString(),
|
|
246
|
+
pendingReferrerFeesSf: this.pendingReferrerFeesSf.toString(),
|
|
247
|
+
absoluteReferralRateSf: this.absoluteReferralRateSf.toString(),
|
|
248
|
+
tokenProgram: this.tokenProgram.toString(),
|
|
249
|
+
padding2: this.padding2.map((item) => item.toString()),
|
|
250
|
+
padding3: this.padding3.map((item) => item.toString()),
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
static fromJSON(obj: ReserveLiquidityJSON): ReserveLiquidity {
|
|
255
|
+
return new ReserveLiquidity({
|
|
256
|
+
mintPubkey: new PublicKey(obj.mintPubkey),
|
|
257
|
+
supplyVault: new PublicKey(obj.supplyVault),
|
|
258
|
+
feeVault: new PublicKey(obj.feeVault),
|
|
259
|
+
availableAmount: new BN(obj.availableAmount),
|
|
260
|
+
borrowedAmountSf: new BN(obj.borrowedAmountSf),
|
|
261
|
+
marketPriceSf: new BN(obj.marketPriceSf),
|
|
262
|
+
marketPriceLastUpdatedTs: new BN(obj.marketPriceLastUpdatedTs),
|
|
263
|
+
mintDecimals: new BN(obj.mintDecimals),
|
|
264
|
+
depositLimitCrossedSlot: new BN(obj.depositLimitCrossedSlot),
|
|
265
|
+
borrowLimitCrossedSlot: new BN(obj.borrowLimitCrossedSlot),
|
|
266
|
+
cumulativeBorrowRateBsf: BigFractionBytes.fromJSON(obj.cumulativeBorrowRateBsf),
|
|
267
|
+
accumulatedProtocolFeesSf: new BN(obj.accumulatedProtocolFeesSf),
|
|
268
|
+
accumulatedReferrerFeesSf: new BN(obj.accumulatedReferrerFeesSf),
|
|
269
|
+
pendingReferrerFeesSf: new BN(obj.pendingReferrerFeesSf),
|
|
270
|
+
absoluteReferralRateSf: new BN(obj.absoluteReferralRateSf),
|
|
271
|
+
tokenProgram: new PublicKey(obj.tokenProgram),
|
|
272
|
+
padding2: obj.padding2.map((item) => new BN(item)),
|
|
273
|
+
padding3: obj.padding3.map((item) => new BN(item)),
|
|
274
|
+
})
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
toEncodable() {
|
|
278
|
+
return ReserveLiquidity.toEncodable(this)
|
|
279
|
+
}
|
|
280
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
2
|
+
import * as borsh from "@coral-xyz/borsh"
|
|
3
|
+
|
|
4
|
+
export interface ScopeConfigurationFields {
|
|
5
|
+
/** Pubkey of the scope price feed (disabled if `null` or `default`) */
|
|
6
|
+
priceFeed: PublicKey
|
|
7
|
+
/** This is the scope_id price chain that results in a price for the token */
|
|
8
|
+
priceChain: Array<number>
|
|
9
|
+
/** This is the scope_id price chain for the twap */
|
|
10
|
+
twapChain: Array<number>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ScopeConfigurationJSON {
|
|
14
|
+
/** Pubkey of the scope price feed (disabled if `null` or `default`) */
|
|
15
|
+
priceFeed: string
|
|
16
|
+
/** This is the scope_id price chain that results in a price for the token */
|
|
17
|
+
priceChain: Array<number>
|
|
18
|
+
/** This is the scope_id price chain for the twap */
|
|
19
|
+
twapChain: Array<number>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class ScopeConfiguration {
|
|
23
|
+
/** Pubkey of the scope price feed (disabled if `null` or `default`) */
|
|
24
|
+
readonly priceFeed: PublicKey
|
|
25
|
+
/** This is the scope_id price chain that results in a price for the token */
|
|
26
|
+
readonly priceChain: Array<number>
|
|
27
|
+
/** This is the scope_id price chain for the twap */
|
|
28
|
+
readonly twapChain: Array<number>
|
|
29
|
+
|
|
30
|
+
constructor(fields: ScopeConfigurationFields) {
|
|
31
|
+
this.priceFeed = fields.priceFeed
|
|
32
|
+
this.priceChain = fields.priceChain
|
|
33
|
+
this.twapChain = fields.twapChain
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static layout(property?: string) {
|
|
37
|
+
return borsh.struct(
|
|
38
|
+
[
|
|
39
|
+
borsh.publicKey("priceFeed"),
|
|
40
|
+
borsh.array(borsh.u16(), 4, "priceChain"),
|
|
41
|
+
borsh.array(borsh.u16(), 4, "twapChain"),
|
|
42
|
+
],
|
|
43
|
+
property,
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
+
static fromDecoded(obj: any) {
|
|
49
|
+
return new ScopeConfiguration({
|
|
50
|
+
priceFeed: obj.priceFeed,
|
|
51
|
+
priceChain: obj.priceChain,
|
|
52
|
+
twapChain: obj.twapChain,
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static toEncodable(fields: ScopeConfigurationFields) {
|
|
57
|
+
return {
|
|
58
|
+
priceFeed: fields.priceFeed,
|
|
59
|
+
priceChain: fields.priceChain,
|
|
60
|
+
twapChain: fields.twapChain,
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
toJSON(): ScopeConfigurationJSON {
|
|
65
|
+
return {
|
|
66
|
+
priceFeed: this.priceFeed.toString(),
|
|
67
|
+
priceChain: this.priceChain,
|
|
68
|
+
twapChain: this.twapChain,
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static fromJSON(obj: ScopeConfigurationJSON): ScopeConfiguration {
|
|
73
|
+
return new ScopeConfiguration({
|
|
74
|
+
priceFeed: new PublicKey(obj.priceFeed),
|
|
75
|
+
priceChain: obj.priceChain,
|
|
76
|
+
twapChain: obj.twapChain,
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
toEncodable() {
|
|
81
|
+
return ScopeConfiguration.toEncodable(this)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
2
|
+
import * as borsh from "@coral-xyz/borsh"
|
|
3
|
+
|
|
4
|
+
export interface SwitchboardConfigurationFields {
|
|
5
|
+
/** Pubkey of the base price feed (disabled if `null` or `default`) */
|
|
6
|
+
priceAggregator: PublicKey
|
|
7
|
+
twapAggregator: PublicKey
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface SwitchboardConfigurationJSON {
|
|
11
|
+
/** Pubkey of the base price feed (disabled if `null` or `default`) */
|
|
12
|
+
priceAggregator: string
|
|
13
|
+
twapAggregator: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class SwitchboardConfiguration {
|
|
17
|
+
/** Pubkey of the base price feed (disabled if `null` or `default`) */
|
|
18
|
+
readonly priceAggregator: PublicKey
|
|
19
|
+
readonly twapAggregator: PublicKey
|
|
20
|
+
|
|
21
|
+
constructor(fields: SwitchboardConfigurationFields) {
|
|
22
|
+
this.priceAggregator = fields.priceAggregator
|
|
23
|
+
this.twapAggregator = fields.twapAggregator
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static layout(property?: string) {
|
|
27
|
+
return borsh.struct([borsh.publicKey("priceAggregator"), borsh.publicKey("twapAggregator")], property)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
|
+
static fromDecoded(obj: any) {
|
|
32
|
+
return new SwitchboardConfiguration({
|
|
33
|
+
priceAggregator: obj.priceAggregator,
|
|
34
|
+
twapAggregator: obj.twapAggregator,
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static toEncodable(fields: SwitchboardConfigurationFields) {
|
|
39
|
+
return {
|
|
40
|
+
priceAggregator: fields.priceAggregator,
|
|
41
|
+
twapAggregator: fields.twapAggregator,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
toJSON(): SwitchboardConfigurationJSON {
|
|
46
|
+
return {
|
|
47
|
+
priceAggregator: this.priceAggregator.toString(),
|
|
48
|
+
twapAggregator: this.twapAggregator.toString(),
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static fromJSON(obj: SwitchboardConfigurationJSON): SwitchboardConfiguration {
|
|
53
|
+
return new SwitchboardConfiguration({
|
|
54
|
+
priceAggregator: new PublicKey(obj.priceAggregator),
|
|
55
|
+
twapAggregator: new PublicKey(obj.twapAggregator),
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
toEncodable() {
|
|
60
|
+
return SwitchboardConfiguration.toEncodable(this)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
2
|
+
import * as borsh from "@coral-xyz/borsh"
|
|
3
|
+
import { PriceHeuristic, PriceHeuristicFields, PriceHeuristicJSON } from "./PriceHeuristic"
|
|
4
|
+
import { ScopeConfiguration, ScopeConfigurationFields, ScopeConfigurationJSON } from "./ScopeConfiguration"
|
|
5
|
+
import {
|
|
6
|
+
SwitchboardConfiguration,
|
|
7
|
+
SwitchboardConfigurationFields,
|
|
8
|
+
SwitchboardConfigurationJSON,
|
|
9
|
+
} from "./SwitchboardConfiguration"
|
|
10
|
+
import { PythConfiguration, PythConfigurationFields, PythConfigurationJSON } from "./PythConfiguration"
|
|
11
|
+
|
|
12
|
+
export interface TokenInfoFields {
|
|
13
|
+
/** UTF-8 encoded name of the token (null-terminated) */
|
|
14
|
+
name: Array<number>
|
|
15
|
+
/** Heuristics limits of acceptable price */
|
|
16
|
+
heuristic: PriceHeuristicFields
|
|
17
|
+
/** Max divergence between twap and price in bps */
|
|
18
|
+
maxTwapDivergenceBps: BN
|
|
19
|
+
maxAgePriceSeconds: BN
|
|
20
|
+
maxAgeTwapSeconds: BN
|
|
21
|
+
/** Scope price configuration */
|
|
22
|
+
scopeConfiguration: ScopeConfigurationFields
|
|
23
|
+
/** Switchboard configuration */
|
|
24
|
+
switchboardConfiguration: SwitchboardConfigurationFields
|
|
25
|
+
/** Pyth configuration */
|
|
26
|
+
pythConfiguration: PythConfigurationFields
|
|
27
|
+
blockPriceUsage: number
|
|
28
|
+
reserved: Array<number>
|
|
29
|
+
padding: Array<BN>
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface TokenInfoJSON {
|
|
33
|
+
/** UTF-8 encoded name of the token (null-terminated) */
|
|
34
|
+
name: Array<number>
|
|
35
|
+
/** Heuristics limits of acceptable price */
|
|
36
|
+
heuristic: PriceHeuristicJSON
|
|
37
|
+
/** Max divergence between twap and price in bps */
|
|
38
|
+
maxTwapDivergenceBps: string
|
|
39
|
+
maxAgePriceSeconds: string
|
|
40
|
+
maxAgeTwapSeconds: string
|
|
41
|
+
/** Scope price configuration */
|
|
42
|
+
scopeConfiguration: ScopeConfigurationJSON
|
|
43
|
+
/** Switchboard configuration */
|
|
44
|
+
switchboardConfiguration: SwitchboardConfigurationJSON
|
|
45
|
+
/** Pyth configuration */
|
|
46
|
+
pythConfiguration: PythConfigurationJSON
|
|
47
|
+
blockPriceUsage: number
|
|
48
|
+
reserved: Array<number>
|
|
49
|
+
padding: Array<string>
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export class TokenInfo {
|
|
53
|
+
/** UTF-8 encoded name of the token (null-terminated) */
|
|
54
|
+
readonly name: Array<number>
|
|
55
|
+
/** Heuristics limits of acceptable price */
|
|
56
|
+
readonly heuristic: PriceHeuristic
|
|
57
|
+
/** Max divergence between twap and price in bps */
|
|
58
|
+
readonly maxTwapDivergenceBps: BN
|
|
59
|
+
readonly maxAgePriceSeconds: BN
|
|
60
|
+
readonly maxAgeTwapSeconds: BN
|
|
61
|
+
/** Scope price configuration */
|
|
62
|
+
readonly scopeConfiguration: ScopeConfiguration
|
|
63
|
+
/** Switchboard configuration */
|
|
64
|
+
readonly switchboardConfiguration: SwitchboardConfiguration
|
|
65
|
+
/** Pyth configuration */
|
|
66
|
+
readonly pythConfiguration: PythConfiguration
|
|
67
|
+
readonly blockPriceUsage: number
|
|
68
|
+
readonly reserved: Array<number>
|
|
69
|
+
readonly padding: Array<BN>
|
|
70
|
+
|
|
71
|
+
constructor(fields: TokenInfoFields) {
|
|
72
|
+
this.name = fields.name
|
|
73
|
+
this.heuristic = new PriceHeuristic({ ...fields.heuristic })
|
|
74
|
+
this.maxTwapDivergenceBps = fields.maxTwapDivergenceBps
|
|
75
|
+
this.maxAgePriceSeconds = fields.maxAgePriceSeconds
|
|
76
|
+
this.maxAgeTwapSeconds = fields.maxAgeTwapSeconds
|
|
77
|
+
this.scopeConfiguration = new ScopeConfiguration({
|
|
78
|
+
...fields.scopeConfiguration,
|
|
79
|
+
})
|
|
80
|
+
this.switchboardConfiguration = new SwitchboardConfiguration({
|
|
81
|
+
...fields.switchboardConfiguration,
|
|
82
|
+
})
|
|
83
|
+
this.pythConfiguration = new PythConfiguration({
|
|
84
|
+
...fields.pythConfiguration,
|
|
85
|
+
})
|
|
86
|
+
this.blockPriceUsage = fields.blockPriceUsage
|
|
87
|
+
this.reserved = fields.reserved
|
|
88
|
+
this.padding = fields.padding
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
static layout(property?: string) {
|
|
92
|
+
return borsh.struct(
|
|
93
|
+
[
|
|
94
|
+
borsh.array(borsh.u8(), 32, "name"),
|
|
95
|
+
PriceHeuristic.layout("heuristic"),
|
|
96
|
+
borsh.u64("maxTwapDivergenceBps"),
|
|
97
|
+
borsh.u64("maxAgePriceSeconds"),
|
|
98
|
+
borsh.u64("maxAgeTwapSeconds"),
|
|
99
|
+
ScopeConfiguration.layout("scopeConfiguration"),
|
|
100
|
+
SwitchboardConfiguration.layout("switchboardConfiguration"),
|
|
101
|
+
PythConfiguration.layout("pythConfiguration"),
|
|
102
|
+
borsh.u8("blockPriceUsage"),
|
|
103
|
+
borsh.array(borsh.u8(), 7, "reserved"),
|
|
104
|
+
borsh.array(borsh.u64(), 19, "padding"),
|
|
105
|
+
],
|
|
106
|
+
property,
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
111
|
+
static fromDecoded(obj: any) {
|
|
112
|
+
return new TokenInfo({
|
|
113
|
+
name: obj.name,
|
|
114
|
+
heuristic: PriceHeuristic.fromDecoded(obj.heuristic),
|
|
115
|
+
maxTwapDivergenceBps: obj.maxTwapDivergenceBps,
|
|
116
|
+
maxAgePriceSeconds: obj.maxAgePriceSeconds,
|
|
117
|
+
maxAgeTwapSeconds: obj.maxAgeTwapSeconds,
|
|
118
|
+
scopeConfiguration: ScopeConfiguration.fromDecoded(obj.scopeConfiguration),
|
|
119
|
+
switchboardConfiguration: SwitchboardConfiguration.fromDecoded(obj.switchboardConfiguration),
|
|
120
|
+
pythConfiguration: PythConfiguration.fromDecoded(obj.pythConfiguration),
|
|
121
|
+
blockPriceUsage: obj.blockPriceUsage,
|
|
122
|
+
reserved: obj.reserved,
|
|
123
|
+
padding: obj.padding,
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
static toEncodable(fields: TokenInfoFields) {
|
|
128
|
+
return {
|
|
129
|
+
name: fields.name,
|
|
130
|
+
heuristic: PriceHeuristic.toEncodable(fields.heuristic),
|
|
131
|
+
maxTwapDivergenceBps: fields.maxTwapDivergenceBps,
|
|
132
|
+
maxAgePriceSeconds: fields.maxAgePriceSeconds,
|
|
133
|
+
maxAgeTwapSeconds: fields.maxAgeTwapSeconds,
|
|
134
|
+
scopeConfiguration: ScopeConfiguration.toEncodable(fields.scopeConfiguration),
|
|
135
|
+
switchboardConfiguration: SwitchboardConfiguration.toEncodable(fields.switchboardConfiguration),
|
|
136
|
+
pythConfiguration: PythConfiguration.toEncodable(fields.pythConfiguration),
|
|
137
|
+
blockPriceUsage: fields.blockPriceUsage,
|
|
138
|
+
reserved: fields.reserved,
|
|
139
|
+
padding: fields.padding,
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
toJSON(): TokenInfoJSON {
|
|
144
|
+
return {
|
|
145
|
+
name: this.name,
|
|
146
|
+
heuristic: this.heuristic.toJSON(),
|
|
147
|
+
maxTwapDivergenceBps: this.maxTwapDivergenceBps.toString(),
|
|
148
|
+
maxAgePriceSeconds: this.maxAgePriceSeconds.toString(),
|
|
149
|
+
maxAgeTwapSeconds: this.maxAgeTwapSeconds.toString(),
|
|
150
|
+
scopeConfiguration: this.scopeConfiguration.toJSON(),
|
|
151
|
+
switchboardConfiguration: this.switchboardConfiguration.toJSON(),
|
|
152
|
+
pythConfiguration: this.pythConfiguration.toJSON(),
|
|
153
|
+
blockPriceUsage: this.blockPriceUsage,
|
|
154
|
+
reserved: this.reserved,
|
|
155
|
+
padding: this.padding.map((item) => item.toString()),
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
static fromJSON(obj: TokenInfoJSON): TokenInfo {
|
|
160
|
+
return new TokenInfo({
|
|
161
|
+
name: obj.name,
|
|
162
|
+
heuristic: PriceHeuristic.fromJSON(obj.heuristic),
|
|
163
|
+
maxTwapDivergenceBps: new BN(obj.maxTwapDivergenceBps),
|
|
164
|
+
maxAgePriceSeconds: new BN(obj.maxAgePriceSeconds),
|
|
165
|
+
maxAgeTwapSeconds: new BN(obj.maxAgeTwapSeconds),
|
|
166
|
+
scopeConfiguration: ScopeConfiguration.fromJSON(obj.scopeConfiguration),
|
|
167
|
+
switchboardConfiguration: SwitchboardConfiguration.fromJSON(obj.switchboardConfiguration),
|
|
168
|
+
pythConfiguration: PythConfiguration.fromJSON(obj.pythConfiguration),
|
|
169
|
+
blockPriceUsage: obj.blockPriceUsage,
|
|
170
|
+
reserved: obj.reserved,
|
|
171
|
+
padding: obj.padding.map((item) => new BN(item)),
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
toEncodable() {
|
|
176
|
+
return TokenInfo.toEncodable(this)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
2
|
+
import * as borsh from "@coral-xyz/borsh"
|
|
3
|
+
|
|
4
|
+
export interface WithdrawalCapsFields {
|
|
5
|
+
configCapacity: BN
|
|
6
|
+
currentTotal: BN
|
|
7
|
+
lastIntervalStartTimestamp: BN
|
|
8
|
+
configIntervalLengthSeconds: BN
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface WithdrawalCapsJSON {
|
|
12
|
+
configCapacity: string
|
|
13
|
+
currentTotal: string
|
|
14
|
+
lastIntervalStartTimestamp: string
|
|
15
|
+
configIntervalLengthSeconds: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Reserve Withdrawal Caps State */
|
|
19
|
+
export class WithdrawalCaps {
|
|
20
|
+
readonly configCapacity: BN
|
|
21
|
+
readonly currentTotal: BN
|
|
22
|
+
readonly lastIntervalStartTimestamp: BN
|
|
23
|
+
readonly configIntervalLengthSeconds: BN
|
|
24
|
+
|
|
25
|
+
constructor(fields: WithdrawalCapsFields) {
|
|
26
|
+
this.configCapacity = fields.configCapacity
|
|
27
|
+
this.currentTotal = fields.currentTotal
|
|
28
|
+
this.lastIntervalStartTimestamp = fields.lastIntervalStartTimestamp
|
|
29
|
+
this.configIntervalLengthSeconds = fields.configIntervalLengthSeconds
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static layout(property?: string) {
|
|
33
|
+
return borsh.struct(
|
|
34
|
+
[
|
|
35
|
+
borsh.i64("configCapacity"),
|
|
36
|
+
borsh.i64("currentTotal"),
|
|
37
|
+
borsh.u64("lastIntervalStartTimestamp"),
|
|
38
|
+
borsh.u64("configIntervalLengthSeconds"),
|
|
39
|
+
],
|
|
40
|
+
property,
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
|
+
static fromDecoded(obj: any) {
|
|
46
|
+
return new WithdrawalCaps({
|
|
47
|
+
configCapacity: obj.configCapacity,
|
|
48
|
+
currentTotal: obj.currentTotal,
|
|
49
|
+
lastIntervalStartTimestamp: obj.lastIntervalStartTimestamp,
|
|
50
|
+
configIntervalLengthSeconds: obj.configIntervalLengthSeconds,
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static toEncodable(fields: WithdrawalCapsFields) {
|
|
55
|
+
return {
|
|
56
|
+
configCapacity: fields.configCapacity,
|
|
57
|
+
currentTotal: fields.currentTotal,
|
|
58
|
+
lastIntervalStartTimestamp: fields.lastIntervalStartTimestamp,
|
|
59
|
+
configIntervalLengthSeconds: fields.configIntervalLengthSeconds,
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
toJSON(): WithdrawalCapsJSON {
|
|
64
|
+
return {
|
|
65
|
+
configCapacity: this.configCapacity.toString(),
|
|
66
|
+
currentTotal: this.currentTotal.toString(),
|
|
67
|
+
lastIntervalStartTimestamp: this.lastIntervalStartTimestamp.toString(),
|
|
68
|
+
configIntervalLengthSeconds: this.configIntervalLengthSeconds.toString(),
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static fromJSON(obj: WithdrawalCapsJSON): WithdrawalCaps {
|
|
73
|
+
return new WithdrawalCaps({
|
|
74
|
+
configCapacity: new BN(obj.configCapacity),
|
|
75
|
+
currentTotal: new BN(obj.currentTotal),
|
|
76
|
+
lastIntervalStartTimestamp: new BN(obj.lastIntervalStartTimestamp),
|
|
77
|
+
configIntervalLengthSeconds: new BN(obj.configIntervalLengthSeconds),
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
toEncodable() {
|
|
82
|
+
return WithdrawalCaps.toEncodable(this)
|
|
83
|
+
}
|
|
84
|
+
}
|