Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: make stableswap-sdk compatible with modern module resolution #617

Merged
merged 1 commit into from Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/stableswap-sdk/src/calculator/amounts.ts
@@ -1,11 +1,11 @@
import type { Token } from "@saberhq/token-utils";
import { Fraction, ONE, TokenAmount, ZERO } from "@saberhq/token-utils";
import JSBI from "jsbi";
import { default as JSBI } from "jsbi";
import mapValues from "lodash.mapvalues";

import type { IExchangeInfo } from "../entities/exchange";
import type { Fees } from "../state/fees";
import { computeD, computeY } from "./curve";
import type { IExchangeInfo } from "../entities/exchange.js";
import type { Fees } from "../state/fees.js";
import { computeD, computeY } from "./curve.js";

/**
* Calculates the current virtual price of the exchange.
Expand Down
10 changes: 5 additions & 5 deletions packages/stableswap-sdk/src/calculator/amounts.unit.test.ts
Expand Up @@ -2,19 +2,19 @@ import type { BigintIsh } from "@saberhq/token-utils";
import { Percent, Token as SToken, TokenAmount } from "@saberhq/token-utils";
import { PublicKey } from "@solana/web3.js";
import BN from "bn.js";
import JSBI from "jsbi";
import { default as JSBI } from "jsbi";
import mapValues from "lodash.mapvalues";

import { SWAP_PROGRAM_ID } from "../constants";
import type { IExchangeInfo } from "../entities/exchange";
import { RECOMMENDED_FEES, ZERO_FEES } from "../state/fees";
import { SWAP_PROGRAM_ID } from "../constants.js";
import type { IExchangeInfo } from "../entities/exchange.js";
import { RECOMMENDED_FEES, ZERO_FEES } from "../state/fees.js";
import {
calculateEstimatedMintAmount,
calculateEstimatedSwapOutputAmount,
calculateEstimatedWithdrawAmount,
calculateEstimatedWithdrawOneAmount,
calculateVirtualPrice,
} from "./amounts";
} from "./amounts.js";

const exchange = {
swapAccount: new PublicKey("YAkoNb6HKmSxQN9L8hiBE5tPJRsniSSMzND1boHmZxe"),
Expand Down
2 changes: 1 addition & 1 deletion packages/stableswap-sdk/src/calculator/curve.ts
@@ -1,5 +1,5 @@
import { ONE, ZERO } from "@saberhq/token-utils";
import JSBI from "jsbi";
import { default as JSBI } from "jsbi";

const N_COINS = JSBI.BigInt(2); // n

Expand Down
4 changes: 2 additions & 2 deletions packages/stableswap-sdk/src/calculator/curve.unit.test.ts
@@ -1,7 +1,7 @@
import type { BigintIsh } from "@saberhq/token-utils";
import JSBI from "jsbi";
import { default as JSBI } from "jsbi";

import { computeD, computeY } from "./curve";
import { computeD, computeY } from "./curve.js";

const assertBN = (actual: BigintIsh, expected: BigintIsh) => {
expect(actual.toString()).toEqual(expected.toString());
Expand Down
6 changes: 3 additions & 3 deletions packages/stableswap-sdk/src/calculator/index.ts
@@ -1,3 +1,3 @@
export * from "./amounts";
export * from "./curve";
export * from "./price";
export * from "./amounts.js";
export * from "./curve.js";
export * from "./price.js";
4 changes: 2 additions & 2 deletions packages/stableswap-sdk/src/calculator/price.ts
@@ -1,8 +1,8 @@
import { Price, TokenAmount } from "@saberhq/token-utils";
import BN from "bn.js";

import type { IExchangeInfo } from "..";
import { calculateEstimatedSwapOutputAmount } from "..";
import type { IExchangeInfo } from "../index.js";
import { calculateEstimatedSwapOutputAmount } from "../index.js";

/**
* Gets the price of the second token in the swap, i.e. "Token 1", with respect to "Token 0".
Expand Down
14 changes: 7 additions & 7 deletions packages/stableswap-sdk/src/entities/exchange.ts
Expand Up @@ -8,14 +8,14 @@ import {
} from "@saberhq/token-utils";
import type { Connection, PublicKey } from "@solana/web3.js";
import BN from "bn.js";
import type JSBI from "jsbi";
import invariant from "tiny-invariant";
import type { default as JSBI } from "jsbi";
import { default as invariant } from "tiny-invariant";

import { SWAP_PROGRAM_ID } from "../constants";
import { StableSwap } from "../stable-swap";
import type { StableSwapState } from "../state";
import type { Fees } from "../state/fees";
import { loadProgramAccount } from "../util/account";
import { SWAP_PROGRAM_ID } from "../constants.js";
import { StableSwap } from "../stable-swap.js";
import type { Fees } from "../state/fees.js";
import type { StableSwapState } from "../state/index.js";
import { loadProgramAccount } from "../util/account.js";

/**
* Reserve information.
Expand Down
2 changes: 1 addition & 1 deletion packages/stableswap-sdk/src/entities/index.ts
@@ -1 +1 @@
export * from "./exchange";
export * from "./exchange.js";
16 changes: 8 additions & 8 deletions packages/stableswap-sdk/src/index.ts
@@ -1,8 +1,8 @@
export * from "./calculator";
export * from "./constants";
export * from "./entities";
export * from "./events";
export * from "./instructions";
export * from "./stable-swap";
export * from "./state";
export * from "./util";
export * from "./calculator/index.js";
export * from "./constants.js";
export * from "./entities/index.js";
export * from "./events.js";
export * from "./instructions/index.js";
export * from "./stable-swap.js";
export * from "./state/index.js";
export * from "./util/index.js";
12 changes: 6 additions & 6 deletions packages/stableswap-sdk/src/instructions/admin.ts
Expand Up @@ -2,9 +2,11 @@ import type { u64 } from "@saberhq/token-utils";
import * as BufferLayout from "@solana/buffer-layout";
import type { PublicKey, TransactionInstruction } from "@solana/web3.js";

import type { StableSwapState } from "../state";
import type { Fees } from "../state/fees";
import { encodeFees, ZERO_FEES } from "../state/fees";
import type { Fees } from "../state/fees.js";
import { encodeFees, ZERO_FEES } from "../state/fees.js";
import type { StableSwapState } from "../state/index.js";
import type { StableSwapConfig } from "./common.js";
import { buildInstruction } from "./common.js";
import {
ApplyNewAdminIXLayout,
PauseIXLayout,
Expand All @@ -13,9 +15,7 @@ import {
SetNewFeesIXLayout,
StopRampAIXLayout,
UnpauseIXLayout,
} from ".";
import type { StableSwapConfig } from "./common";
import { buildInstruction } from "./common";
} from "./layouts.js";

/**
* Admin instruction.
Expand Down
8 changes: 4 additions & 4 deletions packages/stableswap-sdk/src/instructions/index.ts
@@ -1,4 +1,4 @@
export * from "./admin";
export type { StableSwapConfig } from "./common";
export * from "./layouts";
export * from "./swap";
export * from "./admin.js";
export type { StableSwapConfig } from "./common.js";
export * from "./layouts.js";
export * from "./swap.js";
8 changes: 4 additions & 4 deletions packages/stableswap-sdk/src/instructions/layouts.ts
@@ -1,10 +1,10 @@
import { Uint64Layout } from "@saberhq/token-utils";
import * as BufferLayout from "@solana/buffer-layout";

import type { RawFees } from "../state/layout";
import { FeesLayout } from "../state/layout";
import type { AdminInstruction } from ".";
import type { StableSwapInstruction } from "./swap";
import type { RawFees } from "../state/layout.js";
import { FeesLayout } from "../state/layout.js";
import type { AdminInstruction } from "./admin.js";
import type { StableSwapInstruction } from "./swap.js";

export const InitializeSwapIXLayout = BufferLayout.struct<{
instruction: StableSwapInstruction.INITIALIZE;
Expand Down
10 changes: 5 additions & 5 deletions packages/stableswap-sdk/src/instructions/swap.ts
@@ -1,17 +1,17 @@
import type { u64 } from "@saberhq/token-utils";
import type { PublicKey, TransactionInstruction } from "@solana/web3.js";

import type { Fees, RawFees } from "../state";
import { encodeFees, ZERO_FEES } from "../state";
import type { StableSwapConfig } from "./common";
import { buildInstruction } from "./common";
import type { Fees, RawFees } from "../state/index.js";
import { encodeFees, ZERO_FEES } from "../state/index.js";
import type { StableSwapConfig } from "./common.js";
import { buildInstruction } from "./common.js";
import {
DepositIXLayout,
InitializeSwapIXLayout,
SwapIXLayout,
WithdrawIXLayout,
WithdrawOneIXLayout,
} from "./layouts";
} from "./layouts.js";

/**
* Instruction enum.
Expand Down
16 changes: 8 additions & 8 deletions packages/stableswap-sdk/src/stable-swap.ts
Expand Up @@ -4,14 +4,14 @@ import { TOKEN_PROGRAM_ID } from "@saberhq/token-utils";
import type { Connection, TransactionInstruction } from "@solana/web3.js";
import { PublicKey } from "@solana/web3.js";

import { SWAP_PROGRAM_ID } from "./constants";
import type { IExchange } from "./entities/exchange";
import type { StableSwapConfig } from "./instructions";
import * as instructions from "./instructions";
import type { StableSwapState } from "./state";
import { decodeSwap } from "./state";
import { StableSwapLayout } from "./state/layout";
import { loadProgramAccount } from "./util/account";
import { SWAP_PROGRAM_ID } from "./constants.js";
import type { IExchange } from "./entities/exchange.js";
import type { StableSwapConfig } from "./instructions/index.js";
import * as instructions from "./instructions/index.js";
import type { StableSwapState } from "./state/index.js";
import { decodeSwap } from "./state/index.js";
import { StableSwapLayout } from "./state/layout.js";
import { loadProgramAccount } from "./util/account.js";

export interface StableSwapInfo {
config: StableSwapConfig;
Expand Down
2 changes: 1 addition & 1 deletion packages/stableswap-sdk/src/state/fees.ts
@@ -1,6 +1,6 @@
import { Percent, u64 } from "@saberhq/token-utils";

import type { RawFees } from "./layout";
import type { RawFees } from "./layout.js";

export type Fees = {
trade: Percent;
Expand Down
12 changes: 6 additions & 6 deletions packages/stableswap-sdk/src/state/index.ts
@@ -1,13 +1,13 @@
import { u64 } from "@saberhq/token-utils";
import { PublicKey } from "@solana/web3.js";

import type { SwapTokenInfo } from "../instructions/swap";
import type { Fees } from "./fees";
import { decodeFees } from "./fees";
import { StableSwapLayout } from "./layout";
import type { SwapTokenInfo } from "../instructions/swap.js";
import type { Fees } from "./fees.js";
import { decodeFees } from "./fees.js";
import { StableSwapLayout } from "./layout.js";

export * from "./fees";
export * from "./layout";
export * from "./fees.js";
export * from "./layout.js";

/**
* State of a StableSwap, read from the swap account.
Expand Down
4 changes: 2 additions & 2 deletions packages/stableswap-sdk/src/util/index.ts
@@ -1,2 +1,2 @@
export * from "./account";
export * from "./initialize";
export * from "./account.js";
export * from "./initialize.js";
16 changes: 8 additions & 8 deletions packages/stableswap-sdk/src/util/initialize.ts
Expand Up @@ -15,20 +15,20 @@ import type {
} from "@solana/web3.js";
import { Keypair, PublicKey, SystemProgram } from "@solana/web3.js";

import { SWAP_PROGRAM_ID, ZERO_TS } from "../constants";
import { SWAP_PROGRAM_ID, ZERO_TS } from "../constants.js";
import type {
InitializeSwapInstruction,
SwapTokenInfo,
} from "../instructions/swap";
import { initializeSwapInstruction as createInitializeStableSwapInstruction } from "../instructions/swap";
import { findSwapAuthorityKey, StableSwap } from "../stable-swap";
import { ZERO_FEES } from "../state/fees";
import { StableSwapLayout } from "../state/layout";
import type { TransactionInstructions } from "./instructions";
} from "../instructions/swap.js";
import { initializeSwapInstruction as createInitializeStableSwapInstruction } from "../instructions/swap.js";
import { findSwapAuthorityKey, StableSwap } from "../stable-swap.js";
import { ZERO_FEES } from "../state/fees.js";
import { StableSwapLayout } from "../state/layout.js";
import type { TransactionInstructions } from "./instructions.js";
import {
createMutableTransactionInstructions,
mergeInstructions,
} from "./instructions";
} from "./instructions.js";

export type ISeedPoolAccountsFn = (args: {
tokenAAccount: PublicKey;
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Expand Up @@ -4,5 +4,6 @@
"noEmit": true,
"jsxImportSource": "react",
"types": ["jest"]
}
},
"include": ["packages/"]
}