Revert unexpected PoolUtil commits
This commit is contained in:
parent
076b1fc49a
commit
09ddd60a34
|
@ -58,8 +58,10 @@ export async function swapQuoteByInputToken(
|
|||
): Promise<SwapQuote> {
|
||||
const whirlpoolData = whirlpool.getData();
|
||||
const swapMintKey = AddressUtil.toPubKey(swapTokenMint);
|
||||
const swapTokenType = PoolUtil.getTokenType(whirlpoolData, swapMintKey);
|
||||
invariant(!!swapTokenType, "swapTokenMint does not match any tokens on this pool");
|
||||
invariant(
|
||||
whirlpoolData.tokenMintA.equals(swapMintKey) || whirlpoolData.tokenMintB.equals(swapMintKey),
|
||||
"swapTokenMint does not match any tokens on this pool"
|
||||
);
|
||||
|
||||
const aToB =
|
||||
swapMintKey.equals(whirlpoolData.tokenMintA) === amountSpecifiedIsInput ? true : false;
|
||||
|
|
|
@ -3,4 +3,3 @@ export * from "./price-math";
|
|||
export * from "./tick-utils";
|
||||
export * from "./pool-utils";
|
||||
export * from "./ix-utils";
|
||||
export * from "./types";
|
||||
|
|
|
@ -1,17 +1,12 @@
|
|||
import { AddressUtil, MathUtil, Percentage } from "@orca-so/common-sdk";
|
||||
import { Address, BN } from "@project-serum/anchor";
|
||||
import { Token, u64 } from "@solana/spl-token";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import Decimal from "decimal.js";
|
||||
import {
|
||||
MAX_TICK_ARRAY_CROSSINGS,
|
||||
WhirlpoolData,
|
||||
WhirlpoolRewardInfoData,
|
||||
} from "../../types/public";
|
||||
import { MAX_TICK_ARRAY_CROSSINGS, WhirlpoolRewardInfoData } from "../../types/public";
|
||||
import { PDAUtil } from "./pda-utils";
|
||||
import { PriceMath } from "./price-math";
|
||||
import { TickUtil } from "./tick-utils";
|
||||
import { SwapDirection, TokenType } from "./types";
|
||||
|
||||
/**
|
||||
* @category Whirlpool Utils
|
||||
|
@ -25,44 +20,6 @@ export class PoolUtil {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the corresponding token type (TokenA/B) for this mint key for a Whirlpool.
|
||||
*
|
||||
* @param pool The Whirlpool to evaluate the mint against
|
||||
* @param mint The token mint PublicKey
|
||||
* @returns The match result in the form of TokenType enum. undefined if the token mint is not part of the trade pair of the pool.
|
||||
*/
|
||||
public static getTokenType(pool: WhirlpoolData, mint: PublicKey): TokenType | undefined {
|
||||
if (pool.tokenMintA.equals(mint)) {
|
||||
return TokenType.TokenA;
|
||||
} else if (pool.tokenMintB.equals(mint)) {
|
||||
return TokenType.TokenB;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the intended token mint to swap, return the swap direction of a swap for a Whirlpool
|
||||
* @param pool The Whirlpool to evaluate the mint against
|
||||
* @param swapTokenMint The token mint PublicKey the user bases their swap against
|
||||
* @param swapTokenIsInput Whether the swap token is the input token. (similar to amountSpecifiedIsInput from swap Ix)
|
||||
* @returns The direction of the swap given the swapTokenMint. undefined if the token mint is not part of the trade pair of the pool.
|
||||
*/
|
||||
public static getSwapDirection(
|
||||
pool: WhirlpoolData,
|
||||
swapTokenMint: PublicKey,
|
||||
swapTokenIsInput: boolean
|
||||
): SwapDirection | undefined {
|
||||
const tokenType = PoolUtil.getTokenType(pool, swapTokenMint);
|
||||
if (!tokenType) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return (tokenType === TokenType.TokenA) === swapTokenIsInput
|
||||
? SwapDirection.AtoB
|
||||
: SwapDirection.BtoA;
|
||||
}
|
||||
|
||||
public static getFeeRate(feeRate: number): Percentage {
|
||||
/**
|
||||
* Smart Contract comment: https://github.com/orca-so/whirlpool/blob/main/programs/whirlpool/src/state/whirlpool.rs#L9-L11
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
export enum SwapDirection {
|
||||
AtoB = "aToB",
|
||||
BtoA = "bToA",
|
||||
}
|
||||
|
||||
export enum TokenType {
|
||||
TokenA = 1,
|
||||
TokenB,
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
import * as assert from "assert";
|
||||
import { PoolUtil, SwapDirection, TokenType } from "../../../../src";
|
||||
import { testWhirlpoolData } from "../../../utils/testDataTypes";
|
||||
import { Keypair } from "@solana/web3.js";
|
||||
|
||||
describe("PoolUtils tests", () => {
|
||||
describe("getTokenType", () => {
|
||||
it("Token is tokenA", async () => {
|
||||
const whirlpoolData = testWhirlpoolData;
|
||||
const result = PoolUtil.getTokenType(whirlpoolData, whirlpoolData.tokenMintA);
|
||||
assert.equal(result, TokenType.TokenA);
|
||||
});
|
||||
|
||||
it("Token is tokenB", async () => {
|
||||
const whirlpoolData = testWhirlpoolData;
|
||||
const result = PoolUtil.getTokenType(whirlpoolData, whirlpoolData.tokenMintB);
|
||||
assert.equal(result, TokenType.TokenB);
|
||||
});
|
||||
|
||||
it("Token is some other token", async () => {
|
||||
const whirlpoolData = testWhirlpoolData;
|
||||
const result = PoolUtil.getTokenType(whirlpoolData, Keypair.generate().publicKey);
|
||||
assert.ok(result === undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getSwapDirection", () => {
|
||||
it("SwapToken is tokenA and is an input", async () => {
|
||||
const whirlpoolData = testWhirlpoolData;
|
||||
const result = PoolUtil.getSwapDirection(whirlpoolData, whirlpoolData.tokenMintA, true);
|
||||
assert.equal(result, SwapDirection.AtoB);
|
||||
});
|
||||
|
||||
it("SwapToken is tokenB and is an input", async () => {
|
||||
const whirlpoolData = testWhirlpoolData;
|
||||
const result = PoolUtil.getSwapDirection(whirlpoolData, whirlpoolData.tokenMintB, true);
|
||||
assert.equal(result, SwapDirection.BtoA);
|
||||
});
|
||||
|
||||
it("SwapToken is tokenA and is not an input", async () => {
|
||||
const whirlpoolData = testWhirlpoolData;
|
||||
const result = PoolUtil.getSwapDirection(whirlpoolData, whirlpoolData.tokenMintA, false);
|
||||
assert.equal(result, SwapDirection.BtoA);
|
||||
});
|
||||
|
||||
it("SwapToken is tokenB and is not an input", async () => {
|
||||
const whirlpoolData = testWhirlpoolData;
|
||||
const result = PoolUtil.getSwapDirection(whirlpoolData, whirlpoolData.tokenMintB, false);
|
||||
assert.equal(result, SwapDirection.AtoB);
|
||||
});
|
||||
|
||||
it("SwapToken is a random mint and is an input", async () => {
|
||||
const whirlpoolData = testWhirlpoolData;
|
||||
const result = PoolUtil.getSwapDirection(whirlpoolData, Keypair.generate().publicKey, true);
|
||||
assert.equal(result, undefined);
|
||||
});
|
||||
|
||||
it("SwapToken is a random mint and is not an input", async () => {
|
||||
const whirlpoolData = testWhirlpoolData;
|
||||
const result = PoolUtil.getSwapDirection(whirlpoolData, Keypair.generate().publicKey, false);
|
||||
assert.equal(result, undefined);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,24 +0,0 @@
|
|||
import { Keypair } from "@solana/web3.js";
|
||||
import { BN } from "bn.js";
|
||||
import { PriceMath } from "../../src";
|
||||
|
||||
export const testWhirlpoolData = {
|
||||
whirlpoolsConfig: Keypair.generate().publicKey,
|
||||
whirlpoolBump: [],
|
||||
feeRate: 300,
|
||||
protocolFeeRate: 1800,
|
||||
liquidity: new BN("32523523532"),
|
||||
sqrtPrice: new BN("32523523532"),
|
||||
tickCurrentIndex: PriceMath.sqrtPriceX64ToTickIndex(new BN("32523523532")),
|
||||
protocolFeeOwedA: new BN("2314532532"),
|
||||
protocolFeeOwedB: new BN("2314532532"),
|
||||
tokenMintA: Keypair.generate().publicKey,
|
||||
tokenVaultA: Keypair.generate().publicKey,
|
||||
feeGrowthGlobalA: new BN("32532523523523523"),
|
||||
tokenMintB: Keypair.generate().publicKey,
|
||||
tokenVaultB: Keypair.generate().publicKey,
|
||||
feeGrowthGlobalB: new BN("32532523523523523"),
|
||||
rewardLastUpdatedTimestamp: new BN("3253252312412523523523"),
|
||||
rewardInfos: [],
|
||||
tickSpacing: 64,
|
||||
};
|
Loading…
Reference in New Issue