@kamino-finance/scope-sdk
Version:
Scope Oracle SDK
63 lines (52 loc) • 1.36 kB
text/typescript
import { address, Address } from "@solana/kit" // eslint-disable-line @typescript-eslint/no-unused-vars
import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
import * as borsh from "@coral-xyz/borsh"
import { borshAddress } from "../utils"
export interface PriceFields {
value: BN
exp: BN
}
export interface PriceJSON {
value: string
exp: string
}
export class Price {
readonly value: BN
readonly exp: BN
constructor(fields: PriceFields) {
this.value = fields.value
this.exp = fields.exp
}
static layout(property?: string) {
return borsh.struct([borsh.u64("value"), borsh.u64("exp")], property)
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
static fromDecoded(obj: any) {
return new Price({
value: obj.value,
exp: obj.exp,
})
}
static toEncodable(fields: PriceFields) {
return {
value: fields.value,
exp: fields.exp,
}
}
toJSON(): PriceJSON {
return {
value: this.value.toString(),
exp: this.exp.toString(),
}
}
static fromJSON(obj: PriceJSON): Price {
return new Price({
value: new BN(obj.value),
exp: new BN(obj.exp),
})
}
toEncodable() {
return Price.toEncodable(this)
}
}