@exponent-labs/loopscale-deserializer 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,70 @@
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 CapMonitorFields {
5
+ startTime1hr: BN
6
+ startTime24hr: BN
7
+ principal1hr: BN
8
+ principal24hr: BN
9
+ }
10
+
11
+ export interface CapMonitorJSON {
12
+ startTime1hr: string
13
+ startTime24hr: string
14
+ principal1hr: string
15
+ principal24hr: string
16
+ }
17
+
18
+ export class CapMonitor {
19
+ readonly startTime1hr: BN
20
+ readonly startTime24hr: BN
21
+ readonly principal1hr: BN
22
+ readonly principal24hr: BN
23
+
24
+ constructor(fields: CapMonitorFields) {
25
+ this.startTime1hr = fields.startTime1hr
26
+ this.startTime24hr = fields.startTime24hr
27
+ this.principal1hr = fields.principal1hr
28
+ this.principal24hr = fields.principal24hr
29
+ }
30
+
31
+ static layout(property?: string) {
32
+ return borsh.struct(
33
+ [
34
+ borsh.u64("startTime1hr"),
35
+ borsh.u64("startTime24hr"),
36
+ borsh.u64("principal1hr"),
37
+ borsh.u64("principal24hr"),
38
+ ],
39
+ property,
40
+ )
41
+ }
42
+
43
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
+ static fromDecoded(obj: any) {
45
+ return new CapMonitor({
46
+ startTime1hr: obj.startTime1hr,
47
+ startTime24hr: obj.startTime24hr,
48
+ principal1hr: obj.principal1hr,
49
+ principal24hr: obj.principal24hr,
50
+ })
51
+ }
52
+
53
+ toJSON(): CapMonitorJSON {
54
+ return {
55
+ startTime1hr: this.startTime1hr.toString(),
56
+ startTime24hr: this.startTime24hr.toString(),
57
+ principal1hr: this.principal1hr.toString(),
58
+ principal24hr: this.principal24hr.toString(),
59
+ }
60
+ }
61
+
62
+ static fromJSON(obj: CapMonitorJSON): CapMonitor {
63
+ return new CapMonitor({
64
+ startTime1hr: new BN(obj.startTime1hr),
65
+ startTime24hr: new BN(obj.startTime24hr),
66
+ principal1hr: new BN(obj.principal1hr),
67
+ principal24hr: new BN(obj.principal24hr),
68
+ })
69
+ }
70
+ }
@@ -0,0 +1,66 @@
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
+
5
+ export interface CollateralDataFields {
6
+ assetMint: PublicKey
7
+ amount: BN
8
+ assetType: number
9
+ assetIdentifier: PublicKey
10
+ }
11
+
12
+ export interface CollateralDataJSON {
13
+ assetMint: string
14
+ amount: string
15
+ assetType: number
16
+ assetIdentifier: string
17
+ }
18
+
19
+ export class CollateralData {
20
+ readonly assetMint: PublicKey
21
+ readonly amount: BN
22
+ readonly assetType: number
23
+ readonly assetIdentifier: PublicKey
24
+
25
+ constructor(fields: CollateralDataFields) {
26
+ this.assetMint = fields.assetMint
27
+ this.amount = fields.amount
28
+ this.assetType = fields.assetType
29
+ this.assetIdentifier = fields.assetIdentifier
30
+ }
31
+
32
+ static layout(property?: string) {
33
+ return borsh.struct(
34
+ [borsh.publicKey("assetMint"), borsh.u64("amount"), borsh.u8("assetType"), borsh.publicKey("assetIdentifier")],
35
+ property,
36
+ )
37
+ }
38
+
39
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
+ static fromDecoded(obj: any) {
41
+ return new CollateralData({
42
+ assetMint: obj.assetMint,
43
+ amount: obj.amount,
44
+ assetType: obj.assetType,
45
+ assetIdentifier: obj.assetIdentifier,
46
+ })
47
+ }
48
+
49
+ toJSON(): CollateralDataJSON {
50
+ return {
51
+ assetMint: this.assetMint.toString(),
52
+ amount: this.amount.toString(),
53
+ assetType: this.assetType,
54
+ assetIdentifier: this.assetIdentifier.toString(),
55
+ }
56
+ }
57
+
58
+ static fromJSON(obj: CollateralDataJSON): CollateralData {
59
+ return new CollateralData({
60
+ assetMint: new PublicKey(obj.assetMint),
61
+ amount: new BN(obj.amount),
62
+ assetType: obj.assetType,
63
+ assetIdentifier: new PublicKey(obj.assetIdentifier),
64
+ })
65
+ }
66
+ }
@@ -0,0 +1,48 @@
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 DurationFields {
5
+ duration: number
6
+ durationType: number
7
+ }
8
+
9
+ export interface DurationJSON {
10
+ duration: number
11
+ durationType: number
12
+ }
13
+
14
+ export class Duration {
15
+ readonly duration: number
16
+ readonly durationType: number
17
+
18
+ constructor(fields: DurationFields) {
19
+ this.duration = fields.duration
20
+ this.durationType = fields.durationType
21
+ }
22
+
23
+ static layout(property?: string) {
24
+ return borsh.struct([borsh.u32("duration"), borsh.u8("durationType")], property)
25
+ }
26
+
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ static fromDecoded(obj: any) {
29
+ return new Duration({
30
+ duration: obj.duration,
31
+ durationType: obj.durationType,
32
+ })
33
+ }
34
+
35
+ toJSON(): DurationJSON {
36
+ return {
37
+ duration: this.duration,
38
+ durationType: this.durationType,
39
+ }
40
+ }
41
+
42
+ static fromJSON(obj: DurationJSON): Duration {
43
+ return new Duration({
44
+ duration: obj.duration,
45
+ durationType: obj.durationType,
46
+ })
47
+ }
48
+ }
@@ -0,0 +1,51 @@
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 ExternalYieldAccountsFields {
5
+ externalYieldAccount: PublicKey
6
+ externalYieldVault: PublicKey
7
+ }
8
+
9
+ export interface ExternalYieldAccountsJSON {
10
+ externalYieldAccount: string
11
+ externalYieldVault: string
12
+ }
13
+
14
+ export class ExternalYieldAccounts {
15
+ readonly externalYieldAccount: PublicKey
16
+ readonly externalYieldVault: PublicKey
17
+
18
+ constructor(fields: ExternalYieldAccountsFields) {
19
+ this.externalYieldAccount = fields.externalYieldAccount
20
+ this.externalYieldVault = fields.externalYieldVault
21
+ }
22
+
23
+ static layout(property?: string) {
24
+ return borsh.struct(
25
+ [borsh.publicKey("externalYieldAccount"), borsh.publicKey("externalYieldVault")],
26
+ property,
27
+ )
28
+ }
29
+
30
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
+ static fromDecoded(obj: any) {
32
+ return new ExternalYieldAccounts({
33
+ externalYieldAccount: obj.externalYieldAccount,
34
+ externalYieldVault: obj.externalYieldVault,
35
+ })
36
+ }
37
+
38
+ toJSON(): ExternalYieldAccountsJSON {
39
+ return {
40
+ externalYieldAccount: this.externalYieldAccount.toString(),
41
+ externalYieldVault: this.externalYieldVault.toString(),
42
+ }
43
+ }
44
+
45
+ static fromJSON(obj: ExternalYieldAccountsJSON): ExternalYieldAccounts {
46
+ return new ExternalYieldAccounts({
47
+ externalYieldAccount: new PublicKey(obj.externalYieldAccount),
48
+ externalYieldVault: new PublicKey(obj.externalYieldVault),
49
+ })
50
+ }
51
+ }
@@ -0,0 +1,146 @@
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
+
5
+ import { Duration, DurationFields, DurationJSON } from "./Duration"
6
+
7
+ export interface LedgerFields {
8
+ status: number
9
+ strategy: PublicKey
10
+ principalMint: PublicKey
11
+ marketInformation: PublicKey
12
+ principalDue: BN
13
+ principalRepaid: BN
14
+ interestOutstanding: BN
15
+ lastInterestUpdatedTime: BN
16
+ duration: DurationFields
17
+ /** PodDecimal: 24 bytes stored as 3 x u64 */
18
+ interestPerSecond: Array<BN>
19
+ startTime: BN
20
+ endTime: BN
21
+ apy: BN
22
+ }
23
+
24
+ export interface LedgerJSON {
25
+ status: number
26
+ strategy: string
27
+ principalMint: string
28
+ marketInformation: string
29
+ principalDue: string
30
+ principalRepaid: string
31
+ interestOutstanding: string
32
+ lastInterestUpdatedTime: string
33
+ duration: DurationJSON
34
+ interestPerSecond: Array<string>
35
+ startTime: string
36
+ endTime: string
37
+ apy: string
38
+ }
39
+
40
+ export class Ledger {
41
+ readonly status: number
42
+ readonly strategy: PublicKey
43
+ readonly principalMint: PublicKey
44
+ readonly marketInformation: PublicKey
45
+ readonly principalDue: BN
46
+ readonly principalRepaid: BN
47
+ readonly interestOutstanding: BN
48
+ readonly lastInterestUpdatedTime: BN
49
+ readonly duration: Duration
50
+ readonly interestPerSecond: Array<BN>
51
+ readonly startTime: BN
52
+ readonly endTime: BN
53
+ readonly apy: BN
54
+
55
+ constructor(fields: LedgerFields) {
56
+ this.status = fields.status
57
+ this.strategy = fields.strategy
58
+ this.principalMint = fields.principalMint
59
+ this.marketInformation = fields.marketInformation
60
+ this.principalDue = fields.principalDue
61
+ this.principalRepaid = fields.principalRepaid
62
+ this.interestOutstanding = fields.interestOutstanding
63
+ this.lastInterestUpdatedTime = fields.lastInterestUpdatedTime
64
+ this.duration = new Duration({ ...fields.duration })
65
+ this.interestPerSecond = fields.interestPerSecond
66
+ this.startTime = fields.startTime
67
+ this.endTime = fields.endTime
68
+ this.apy = fields.apy
69
+ }
70
+
71
+ static layout(property?: string) {
72
+ return borsh.struct(
73
+ [
74
+ borsh.u8("status"),
75
+ borsh.publicKey("strategy"),
76
+ borsh.publicKey("principalMint"),
77
+ borsh.publicKey("marketInformation"),
78
+ borsh.u64("principalDue"),
79
+ borsh.u64("principalRepaid"),
80
+ borsh.u64("interestOutstanding"),
81
+ borsh.u64("lastInterestUpdatedTime"),
82
+ Duration.layout("duration"),
83
+ borsh.array(borsh.u64(), 3, "interestPerSecond"),
84
+ borsh.u64("startTime"),
85
+ borsh.u64("endTime"),
86
+ borsh.u64("apy"),
87
+ ],
88
+ property,
89
+ )
90
+ }
91
+
92
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
93
+ static fromDecoded(obj: any) {
94
+ return new Ledger({
95
+ status: obj.status,
96
+ strategy: obj.strategy,
97
+ principalMint: obj.principalMint,
98
+ marketInformation: obj.marketInformation,
99
+ principalDue: obj.principalDue,
100
+ principalRepaid: obj.principalRepaid,
101
+ interestOutstanding: obj.interestOutstanding,
102
+ lastInterestUpdatedTime: obj.lastInterestUpdatedTime,
103
+ duration: Duration.fromDecoded(obj.duration),
104
+ interestPerSecond: obj.interestPerSecond,
105
+ startTime: obj.startTime,
106
+ endTime: obj.endTime,
107
+ apy: obj.apy,
108
+ })
109
+ }
110
+
111
+ toJSON(): LedgerJSON {
112
+ return {
113
+ status: this.status,
114
+ strategy: this.strategy.toString(),
115
+ principalMint: this.principalMint.toString(),
116
+ marketInformation: this.marketInformation.toString(),
117
+ principalDue: this.principalDue.toString(),
118
+ principalRepaid: this.principalRepaid.toString(),
119
+ interestOutstanding: this.interestOutstanding.toString(),
120
+ lastInterestUpdatedTime: this.lastInterestUpdatedTime.toString(),
121
+ duration: this.duration.toJSON(),
122
+ interestPerSecond: this.interestPerSecond.map((item) => item.toString()),
123
+ startTime: this.startTime.toString(),
124
+ endTime: this.endTime.toString(),
125
+ apy: this.apy.toString(),
126
+ }
127
+ }
128
+
129
+ static fromJSON(obj: LedgerJSON): Ledger {
130
+ return new Ledger({
131
+ status: obj.status,
132
+ strategy: new PublicKey(obj.strategy),
133
+ principalMint: new PublicKey(obj.principalMint),
134
+ marketInformation: new PublicKey(obj.marketInformation),
135
+ principalDue: new BN(obj.principalDue),
136
+ principalRepaid: new BN(obj.principalRepaid),
137
+ interestOutstanding: new BN(obj.interestOutstanding),
138
+ lastInterestUpdatedTime: new BN(obj.lastInterestUpdatedTime),
139
+ duration: Duration.fromJSON(obj.duration),
140
+ interestPerSecond: obj.interestPerSecond.map((item) => new BN(item)),
141
+ startTime: new BN(obj.startTime),
142
+ endTime: new BN(obj.endTime),
143
+ apy: new BN(obj.apy),
144
+ })
145
+ }
146
+ }
@@ -0,0 +1,5 @@
1
+ export { CapMonitor, CapMonitorFields, CapMonitorJSON } from "./CapMonitor"
2
+ export { CollateralData, CollateralDataFields, CollateralDataJSON } from "./CollateralData"
3
+ export { Duration, DurationFields, DurationJSON } from "./Duration"
4
+ export { ExternalYieldAccounts, ExternalYieldAccountsFields, ExternalYieldAccountsJSON } from "./ExternalYieldAccounts"
5
+ export { Ledger, LedgerFields, LedgerJSON } from "./Ledger"
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "rootDir": "src",
4
+ "sourceMap": true,
5
+ "incremental": true,
6
+ "composite": true,
7
+ "target": "ESNext",
8
+ "module": "CommonJS",
9
+ "declaration": true,
10
+ "outDir": "./build",
11
+ "esModuleInterop": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "skipLibCheck": true,
14
+ "resolveJsonModule": true
15
+ },
16
+ "include": ["src", "src/**/*.json"],
17
+ "exclude": ["build"]
18
+ }