Skip to content

Commit

Permalink
fix(ui): Make deserializeLegacySolanaPoolState work
Browse files Browse the repository at this point in the history
  • Loading branch information
wormat committed Oct 25, 2022
1 parent 8660370 commit 015649c
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion apps/ui/src/models/solana/deserializeLegacySolanaPoolState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import {
struct,
u128,
u32,
u64,
u8,
} from "@project-serum/borsh";
import type { Layout } from "@project-serum/borsh";
import type { SolanaEcosystemId, SolanaPoolState } from "@swim-io/solana";
import { SOLANA_ECOSYSTEM_ID, ampFactor } from "@swim-io/solana";
import { SOLANA_ECOSYSTEM_ID } from "@swim-io/solana";
import type BN from "bn.js";

type U8 = (property?: string) => Layout<number>;

Expand All @@ -30,6 +32,32 @@ export interface LegacySolanaPoolState
readonly ecosystem: SolanaEcosystemId;
}

interface DecimalBN {
readonly value: BN;
readonly decimals: number;
}

const decimal = (property = "decimal"): Layout<DecimalBN> =>
struct([u64("value"), u8("decimals")], property);

interface AmpFactor {
readonly initialValue: DecimalBN;
readonly initialTs: BN;
readonly targetValue: DecimalBN;
readonly targetTs: BN;
}

const ampFactor = (property = "ampFactor"): Layout<AmpFactor> =>
struct(
[
decimal("initialValue"),
i64("initialTs"),
decimal("targetValue"),
i64("targetTs"),
],
property,
);

export const solanaPool = (
numberOfTokens: number,
property = "solanaPool",
Expand Down

0 comments on commit 015649c

Please sign in to comment.