Upgrade spl-token to v0.3.8 & common 0.3.0 (#105)
- bump common-sdk to 0.3.0-beta (spl-token upgrade) - update js target to ES2020 to use bigInt literals - replace all deriveATA to getAssociatedTokenAddressSync - replace all spl-token instruction builders previously under the Token namespace - Replace all u64 with BN - Update parser to use the EntityParser stack (TokenAccount & Mint parsers) from common-sdk. Update - - - parser method (breaking) to include address - Replace old Token types AccountInfo & MintInfo with Account & Mint - Remove duplicated account-request util methods. Use the ones in common-sdk - Remove duplicated util methods createATAIx, getAssociatedTokenAddressSync, createWSOLAccountInstructions
This commit is contained in:
parent
cdd16d683c
commit
e06505fb1e
|
@ -17,4 +17,4 @@ ticks_per_slot = 7
|
|||
url = "https://api.mainnet-beta.solana.com"
|
||||
|
||||
[[test.validator.clone]]
|
||||
address = "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"
|
||||
address = "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
{
|
||||
"name": "@orca-so/whirlpools-sdk",
|
||||
"version": "0.10.0",
|
||||
"version": "0.11.0",
|
||||
"description": "Typescript SDK to interact with Orca's Whirlpool program.",
|
||||
"license": "Apache-2.0",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"dependencies": {
|
||||
"@coral-xyz/anchor": "~0.27.0",
|
||||
"@metaplex-foundation/mpl-token-metadata": "1.2.5",
|
||||
"@orca-so/common-sdk": "0.2.2",
|
||||
"@solana/spl-token": "^0.1.8",
|
||||
"@solana/web3.js": "~1.74.0",
|
||||
"@orca-so/common-sdk": "^0.3.0-beta-1",
|
||||
"@solana/spl-token": "^0.3.8",
|
||||
"@solana/web3.js": "^1.75.0",
|
||||
"decimal.js": "^10.3.1",
|
||||
"lodash.combinations": "^18.11.1",
|
||||
"tiny-invariant": "^1.2.0"
|
||||
|
@ -19,6 +18,7 @@
|
|||
"@types/bn.js": "~5.1.0",
|
||||
"@types/lodash": "4.14.194",
|
||||
"@types/mocha": "^9.0.0",
|
||||
"@metaplex-foundation/mpl-token-metadata": "2.12.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.26.0",
|
||||
"@typescript-eslint/parser": "^4.26.0",
|
||||
"chai": "^4.3.4",
|
||||
|
@ -64,4 +64,4 @@
|
|||
"url": "https://github.com/orca-so/whirlpools/issues"
|
||||
},
|
||||
"homepage": "https://www.orca.so"
|
||||
}
|
||||
}
|
|
@ -1,33 +1,32 @@
|
|||
import { Address } from "@coral-xyz/anchor";
|
||||
import {
|
||||
AddressUtil,
|
||||
deriveATA,
|
||||
Instruction,
|
||||
resolveOrCreateATAs,
|
||||
TokenUtil,
|
||||
TransactionBuilder,
|
||||
ZERO,
|
||||
resolveOrCreateATAs,
|
||||
} from "@orca-so/common-sdk";
|
||||
import { NATIVE_MINT } from "@solana/spl-token";
|
||||
import { NATIVE_MINT, getAssociatedTokenAddressSync } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import invariant from "tiny-invariant";
|
||||
import { WhirlpoolContext } from "../context";
|
||||
import {
|
||||
DecreaseLiquidityInput,
|
||||
IncreaseLiquidityInput,
|
||||
collectFeesIx,
|
||||
collectRewardIx,
|
||||
DecreaseLiquidityInput,
|
||||
decreaseLiquidityIx,
|
||||
IncreaseLiquidityInput,
|
||||
increaseLiquidityIx,
|
||||
updateFeesAndRewardsIx,
|
||||
} from "../instructions";
|
||||
import { PositionData, TickArrayData, TickData, WhirlpoolData } from "../types/public";
|
||||
import { getTickArrayDataForPosition } from "../utils/builder/position-builder-util";
|
||||
import { PDAUtil, PoolUtil, TickArrayUtil, TickUtil } from "../utils/public";
|
||||
import { createWSOLAccountInstructions } from "../utils/spl-token-utils";
|
||||
import {
|
||||
TokenMintTypes,
|
||||
getTokenMintsFromWhirlpools,
|
||||
resolveAtaForMints,
|
||||
TokenMintTypes,
|
||||
} from "../utils/whirlpool-ata-utils";
|
||||
import { Position } from "../whirlpool-client";
|
||||
|
||||
|
@ -130,10 +129,13 @@ export class PositionImpl implements Position {
|
|||
txBuilder.addInstruction(tokenOwnerAccountAIx);
|
||||
txBuilder.addInstruction(tokenOwnerAccountBIx);
|
||||
} else {
|
||||
tokenOwnerAccountA = await deriveATA(sourceWalletKey, whirlpool.tokenMintA);
|
||||
tokenOwnerAccountB = await deriveATA(sourceWalletKey, whirlpool.tokenMintB);
|
||||
tokenOwnerAccountA = getAssociatedTokenAddressSync(whirlpool.tokenMintA, sourceWalletKey);
|
||||
tokenOwnerAccountB = getAssociatedTokenAddressSync(whirlpool.tokenMintB, sourceWalletKey);
|
||||
}
|
||||
const positionTokenAccount = await deriveATA(positionWalletKey, this.data.positionMint);
|
||||
const positionTokenAccount = getAssociatedTokenAddressSync(
|
||||
this.data.positionMint,
|
||||
positionWalletKey
|
||||
);
|
||||
|
||||
const increaseIx = increaseLiquidityIx(this.ctx.program, {
|
||||
...liquidityInput,
|
||||
|
@ -203,15 +205,18 @@ export class PositionImpl implements Position {
|
|||
txBuilder.addInstruction(tokenOwnerAccountAIx);
|
||||
txBuilder.addInstruction(tokenOwnerAccountBIx);
|
||||
} else {
|
||||
tokenOwnerAccountA = await deriveATA(sourceWalletKey, whirlpool.tokenMintA);
|
||||
tokenOwnerAccountB = await deriveATA(sourceWalletKey, whirlpool.tokenMintB);
|
||||
tokenOwnerAccountA = getAssociatedTokenAddressSync(whirlpool.tokenMintA, sourceWalletKey);
|
||||
tokenOwnerAccountB = getAssociatedTokenAddressSync(whirlpool.tokenMintB, sourceWalletKey);
|
||||
}
|
||||
|
||||
const decreaseIx = decreaseLiquidityIx(this.ctx.program, {
|
||||
...liquidityInput,
|
||||
whirlpool: this.data.whirlpool,
|
||||
position: this.address,
|
||||
positionTokenAccount: await deriveATA(positionWalletKey, this.data.positionMint),
|
||||
positionTokenAccount: getAssociatedTokenAddressSync(
|
||||
this.data.positionMint,
|
||||
positionWalletKey
|
||||
),
|
||||
tokenOwnerAccountA,
|
||||
tokenOwnerAccountB,
|
||||
tokenVaultA: whirlpool.tokenVaultA,
|
||||
|
@ -278,13 +283,14 @@ export class PositionImpl implements Position {
|
|||
txBuilder.addInstructions(resolveAtaIxs);
|
||||
|
||||
if (affliatedMints.hasNativeMint) {
|
||||
let { address: wSOLAta, ...resolveWSolIx } = createWSOLAccountInstructions(
|
||||
destinationWalletKey,
|
||||
ZERO,
|
||||
accountExemption,
|
||||
ataPayerKey,
|
||||
destinationWalletKey
|
||||
);
|
||||
let { address: wSOLAta, ...resolveWSolIx } =
|
||||
TokenUtil.createWrappedNativeAccountInstruction(
|
||||
destinationWalletKey,
|
||||
ZERO,
|
||||
accountExemption,
|
||||
ataPayerKey,
|
||||
destinationWalletKey
|
||||
);
|
||||
affliatedTokenAtaMap[NATIVE_MINT.toBase58()] = wSOLAta;
|
||||
txBuilder.addInstruction(resolveWSolIx);
|
||||
}
|
||||
|
@ -303,7 +309,10 @@ export class PositionImpl implements Position {
|
|||
`No owner token account provided for wallet ${destinationWalletKey.toBase58()} for token B ${whirlpool.tokenMintB.toBase58()} `
|
||||
);
|
||||
|
||||
const positionTokenAccount = await deriveATA(positionWalletKey, this.data.positionMint);
|
||||
const positionTokenAccount = getAssociatedTokenAddressSync(
|
||||
this.data.positionMint,
|
||||
positionWalletKey
|
||||
);
|
||||
|
||||
if (updateFeesAndRewards && !this.data.liquidity.isZero()) {
|
||||
const updateIx = await this.updateFeesAndRewards();
|
||||
|
@ -374,11 +383,12 @@ export class PositionImpl implements Position {
|
|||
);
|
||||
|
||||
if (rewardMints.hasNativeMint) {
|
||||
let { address: wSOLAta, ...resolveWSolIx } = createWSOLAccountInstructions(
|
||||
destinationWalletKey,
|
||||
ZERO,
|
||||
accountExemption
|
||||
);
|
||||
let { address: wSOLAta, ...resolveWSolIx } =
|
||||
TokenUtil.createWrappedNativeAccountInstruction(
|
||||
destinationWalletKey,
|
||||
ZERO,
|
||||
accountExemption
|
||||
);
|
||||
affliatedTokenAtaMap[NATIVE_MINT.toBase58()] = wSOLAta;
|
||||
txBuilder.addInstruction(resolveWSolIx);
|
||||
}
|
||||
|
@ -388,7 +398,10 @@ export class PositionImpl implements Position {
|
|||
ataMap = { ...affliatedTokenAtaMap };
|
||||
}
|
||||
|
||||
const positionTokenAccount = await deriveATA(positionWalletKey, this.data.positionMint);
|
||||
const positionTokenAccount = getAssociatedTokenAddressSync(
|
||||
this.data.positionMint,
|
||||
positionWalletKey
|
||||
);
|
||||
if (updateFeesAndRewards && !this.data.liquidity.isZero()) {
|
||||
const updateIx = await this.updateFeesAndRewards();
|
||||
txBuilder.addInstruction(updateIx);
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import BN from "bn.js";
|
||||
import { AccountFetcher, PoolUtil, TokenInfo } from "..";
|
||||
import {
|
||||
TokenAccountInfo,
|
||||
WhirlpoolData,
|
||||
WhirlpoolRewardInfo,
|
||||
WhirlpoolRewardInfoData,
|
||||
TokenAccountInfo,
|
||||
} from "../types/public";
|
||||
|
||||
export async function getTokenMintInfos(
|
||||
|
@ -52,7 +52,7 @@ async function getRewardInfo(
|
|||
throw new Error(`Unable to fetch TokenAccountInfo for vault - ${data.vault}`);
|
||||
}
|
||||
rewardInfo.initialized = true;
|
||||
rewardInfo.vaultAmount = vaultInfo.amount;
|
||||
rewardInfo.vaultAmount = new BN(vaultInfo.amount.toString());
|
||||
}
|
||||
return rewardInfo;
|
||||
}
|
||||
|
|
|
@ -5,10 +5,9 @@ import {
|
|||
TokenUtil,
|
||||
TransactionBuilder,
|
||||
ZERO,
|
||||
deriveATA,
|
||||
resolveOrCreateATAs,
|
||||
} from "@orca-so/common-sdk";
|
||||
import { NATIVE_MINT } from "@solana/spl-token";
|
||||
import { NATIVE_MINT, getAssociatedTokenAddressSync } from "@solana/spl-token";
|
||||
import { Keypair, PublicKey } from "@solana/web3.js";
|
||||
import invariant from "tiny-invariant";
|
||||
import { WhirlpoolContext } from "../context";
|
||||
|
@ -32,7 +31,6 @@ import {
|
|||
import { TokenAccountInfo, TokenInfo, WhirlpoolData, WhirlpoolRewardInfo } from "../types/public";
|
||||
import { getTickArrayDataForPosition } from "../utils/builder/position-builder-util";
|
||||
import { PDAUtil, TickArrayUtil, TickUtil } from "../utils/public";
|
||||
import { createWSOLAccountInstructions } from "../utils/spl-token-utils";
|
||||
import {
|
||||
TokenMintTypes,
|
||||
getTokenMintsFromWhirlpools,
|
||||
|
@ -282,7 +280,10 @@ export class WhirlpoolImpl implements Whirlpool {
|
|||
positionMintKeypair.publicKey
|
||||
);
|
||||
const metadataPda = PDAUtil.getPositionMetadata(positionMintKeypair.publicKey);
|
||||
const positionTokenAccountAddress = await deriveATA(wallet, positionMintKeypair.publicKey);
|
||||
const positionTokenAccountAddress = getAssociatedTokenAddressSync(
|
||||
positionMintKeypair.publicKey,
|
||||
wallet
|
||||
);
|
||||
|
||||
const txBuilder = new TransactionBuilder(
|
||||
this.ctx.provider.connection,
|
||||
|
@ -377,7 +378,10 @@ export class WhirlpoolImpl implements Whirlpool {
|
|||
`Position ${positionAddress.toBase58()} is not a position for Whirlpool ${this.address.toBase58()}`
|
||||
);
|
||||
|
||||
const positionTokenAccount = await deriveATA(positionWallet, positionData.positionMint);
|
||||
const positionTokenAccount = getAssociatedTokenAddressSync(
|
||||
positionData.positionMint,
|
||||
positionWallet
|
||||
);
|
||||
|
||||
const tokenAccountsTxBuilder = new TransactionBuilder(
|
||||
this.ctx.provider.connection,
|
||||
|
@ -484,7 +488,7 @@ export class WhirlpoolImpl implements Whirlpool {
|
|||
|
||||
// Handle native mint
|
||||
if (affiliatedMints.hasNativeMint) {
|
||||
let { address: wSOLAta, ...resolveWSolIx } = createWSOLAccountInstructions(
|
||||
let { address: wSOLAta, ...resolveWSolIx } = TokenUtil.createWrappedNativeAccountInstruction(
|
||||
destinationWallet,
|
||||
ZERO,
|
||||
accountExemption,
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
import { Address } from "@coral-xyz/anchor";
|
||||
import { Instruction, resolveOrCreateATAs, TransactionBuilder, ZERO } from "@orca-so/common-sdk";
|
||||
import {
|
||||
Instruction,
|
||||
TokenUtil,
|
||||
TransactionBuilder,
|
||||
ZERO,
|
||||
resolveOrCreateATAs,
|
||||
} from "@orca-so/common-sdk";
|
||||
import { ResolvedTokenAddressInstruction } from "@orca-so/common-sdk/dist/helpers/token-instructions";
|
||||
import { NATIVE_MINT } from "@solana/spl-token";
|
||||
import { NATIVE_MINT, getAssociatedTokenAddressSync } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { PositionData, WhirlpoolContext } from "../..";
|
||||
import { WhirlpoolIx } from "../../ix";
|
||||
import { WhirlpoolData } from "../../types/public";
|
||||
import { PDAUtil, PoolUtil, TickUtil } from "../../utils/public";
|
||||
import {
|
||||
createWSOLAccountInstructions,
|
||||
getAssociatedTokenAddressSync,
|
||||
} from "../../utils/spl-token-utils";
|
||||
import { checkMergedTransactionSizeIsValid, convertListToMap } from "../../utils/txn-utils";
|
||||
import { getTokenMintsFromWhirlpools } from "../../utils/whirlpool-ata-utils";
|
||||
import { updateFeesAndRewardsIx } from "../update-fees-and-rewards-ix";
|
||||
|
@ -144,7 +146,7 @@ export async function collectAllForPositionsTxns(
|
|||
if (!pendingTxBuilder || !touchedMints) {
|
||||
pendingTxBuilder = new TransactionBuilder(ctx.connection, ctx.wallet, ctx.txBuilderOpts);
|
||||
touchedMints = new Set<string>();
|
||||
resolvedAtas[NATIVE_MINT.toBase58()] = createWSOLAccountInstructions(
|
||||
resolvedAtas[NATIVE_MINT.toBase58()] = TokenUtil.createWrappedNativeAccountInstruction(
|
||||
receiverKey,
|
||||
ZERO,
|
||||
accountExemption
|
||||
|
@ -229,10 +231,7 @@ const constructCollectIxForPosition = (
|
|||
const mintA = whirlpool.tokenMintA.toBase58();
|
||||
const mintB = whirlpool.tokenMintB.toBase58();
|
||||
|
||||
const positionTokenAccount = getAssociatedTokenAddressSync(
|
||||
positionMint.toBase58(),
|
||||
positionOwner.toBase58()
|
||||
);
|
||||
const positionTokenAccount = getAssociatedTokenAddressSync(positionMint, positionOwner);
|
||||
|
||||
// Update fee and reward values if necessary
|
||||
if (!liquidity.eq(ZERO)) {
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
import {
|
||||
AddressUtil,
|
||||
deriveATA,
|
||||
EMPTY_INSTRUCTION,
|
||||
Percentage,
|
||||
TokenUtil,
|
||||
TransactionBuilder,
|
||||
ZERO,
|
||||
} from "@orca-so/common-sdk";
|
||||
import { ResolvedTokenAddressInstruction } from "@orca-so/common-sdk/dist/helpers/token-instructions";
|
||||
import {
|
||||
AccountInfo,
|
||||
ASSOCIATED_TOKEN_PROGRAM_ID,
|
||||
Account,
|
||||
NATIVE_MINT,
|
||||
TOKEN_PROGRAM_ID,
|
||||
u64,
|
||||
createAssociatedTokenAccountInstruction,
|
||||
getAssociatedTokenAddressSync
|
||||
} from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import {
|
||||
AtaAccountInfo,
|
||||
PDAUtil,
|
||||
|
@ -22,12 +22,10 @@ import {
|
|||
SwapUtils,
|
||||
TickArrayUtil,
|
||||
TradeRoute,
|
||||
twoHopSwapQuoteFromSwapQuotes,
|
||||
WhirlpoolContext,
|
||||
twoHopSwapQuoteFromSwapQuotes,
|
||||
} from "../..";
|
||||
import { createAssociatedTokenAccountInstruction } from "../../utils/ata-ix-util";
|
||||
import { adjustForSlippage } from "../../utils/position-util";
|
||||
import { createWSOLAccountInstructions } from "../../utils/spl-token-utils";
|
||||
import { contextOptionsToBuilderOptions } from "../../utils/txn-utils";
|
||||
import { swapIx } from "../swap-ix";
|
||||
import { twoHopSwapIx } from "../two-hop-swap-ix";
|
||||
|
@ -53,9 +51,9 @@ export async function getSwapFromRoute(
|
|||
const requiredAtas = new Set<string>();
|
||||
const requiredTickArrays = [];
|
||||
let hasNativeMint = false;
|
||||
let nativeMintAmount = new u64(0);
|
||||
let nativeMintAmount = new BN(0);
|
||||
|
||||
function addOrNative(mint: string, amount: u64) {
|
||||
function addOrNative(mint: string, amount: BN) {
|
||||
if (mint === NATIVE_MINT.toBase58()) {
|
||||
hasNativeMint = true;
|
||||
nativeMintAmount = nativeMintAmount.add(amount);
|
||||
|
@ -128,7 +126,7 @@ export async function getSwapFromRoute(
|
|||
return Promise.resolve(
|
||||
keys.map((key) =>
|
||||
resolvedAtaAccounts.find((ata) => ata.address?.toBase58() === key.toBase58())
|
||||
) as AccountInfo[]
|
||||
) as Account[]
|
||||
);
|
||||
} else {
|
||||
return ctx.fetcher.listTokenInfos(keys, false);
|
||||
|
@ -139,7 +137,7 @@ export async function getSwapFromRoute(
|
|||
const ataIxes = Object.values(ataInstructionMap);
|
||||
|
||||
if (hasNativeMint) {
|
||||
const solIx = createWSOLAccountInstructions(
|
||||
const solIx = TokenUtil.createWrappedNativeAccountInstruction(
|
||||
wallet,
|
||||
nativeMintAmount,
|
||||
await ctx.fetcher.getAccountRentExempt()
|
||||
|
@ -265,29 +263,35 @@ function adjustQuoteForSlippage(quote: SubTradeRoute, slippage: Percentage): Sub
|
|||
};
|
||||
|
||||
if (amountSpecifiedIsInput) {
|
||||
updatedQuote.hopQuotes = [updatedQuote.hopQuotes[0], {
|
||||
...swapQuoteTwo,
|
||||
quote: {
|
||||
...swapQuoteTwo.quote,
|
||||
otherAmountThreshold: adjustForSlippage(
|
||||
swapQuoteTwo.quote.estimatedAmountOut,
|
||||
slippage,
|
||||
false
|
||||
),
|
||||
updatedQuote.hopQuotes = [
|
||||
updatedQuote.hopQuotes[0],
|
||||
{
|
||||
...swapQuoteTwo,
|
||||
quote: {
|
||||
...swapQuoteTwo.quote,
|
||||
otherAmountThreshold: adjustForSlippage(
|
||||
swapQuoteTwo.quote.estimatedAmountOut,
|
||||
slippage,
|
||||
false
|
||||
),
|
||||
},
|
||||
},
|
||||
}];
|
||||
];
|
||||
} else {
|
||||
updatedQuote.hopQuotes = [{
|
||||
...swapQuoteOne,
|
||||
quote: {
|
||||
...swapQuoteOne.quote,
|
||||
otherAmountThreshold: adjustForSlippage(
|
||||
swapQuoteOne.quote.estimatedAmountIn,
|
||||
slippage,
|
||||
true
|
||||
),
|
||||
updatedQuote.hopQuotes = [
|
||||
{
|
||||
...swapQuoteOne,
|
||||
quote: {
|
||||
...swapQuoteOne.quote,
|
||||
otherAmountThreshold: adjustForSlippage(
|
||||
swapQuoteOne.quote.estimatedAmountIn,
|
||||
slippage,
|
||||
true
|
||||
),
|
||||
},
|
||||
},
|
||||
}, updatedQuote.hopQuotes[1]];
|
||||
updatedQuote.hopQuotes[1],
|
||||
];
|
||||
}
|
||||
return updatedQuote;
|
||||
}
|
||||
|
@ -313,12 +317,11 @@ async function cachedResolveOrCreateNonNativeATAs(
|
|||
ownerAddress: PublicKey,
|
||||
tokenMints: Set<string>,
|
||||
getTokenAccounts: (keys: PublicKey[]) => Promise<Array<AtaAccountInfo | null>>,
|
||||
payer = ownerAddress,
|
||||
modeIdempotent: boolean = false
|
||||
payer = ownerAddress
|
||||
): Promise<{ [tokenMint: string]: ResolvedTokenAddressInstruction }> {
|
||||
const instructionMap: { [tokenMint: string]: ResolvedTokenAddressInstruction } = {};
|
||||
const tokenMintArray = Array.from(tokenMints).map((tm) => new PublicKey(tm));
|
||||
const tokenAtas = await Promise.all(tokenMintArray.map((tm) => deriveATA(ownerAddress, tm)));
|
||||
const tokenAtas = tokenMintArray.map((tm) => getAssociatedTokenAddressSync(tm, ownerAddress));
|
||||
const tokenAccounts = await getTokenAccounts(tokenAtas);
|
||||
tokenAccounts.forEach((tokenAccount, index) => {
|
||||
const ataAddress = tokenAtas[index]!;
|
||||
|
@ -333,13 +336,10 @@ async function cachedResolveOrCreateNonNativeATAs(
|
|||
resolvedInstruction = { address: ataAddress, ...EMPTY_INSTRUCTION };
|
||||
} else {
|
||||
const createAtaInstruction = createAssociatedTokenAccountInstruction(
|
||||
ASSOCIATED_TOKEN_PROGRAM_ID,
|
||||
TOKEN_PROGRAM_ID,
|
||||
tokenMintArray[index],
|
||||
payer,
|
||||
ataAddress,
|
||||
ownerAddress,
|
||||
payer,
|
||||
modeIdempotent
|
||||
tokenMintArray[index],
|
||||
);
|
||||
|
||||
resolvedInstruction = {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { BN, Program } from "@coral-xyz/anchor";
|
||||
import { TOKEN_PROGRAM_ID, u64 } from "@solana/spl-token";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
|
@ -48,8 +49,8 @@ export type IncreaseLiquidityParams = {
|
|||
* @param liquidityAmount - the desired amount of liquidity to deposit into the position/
|
||||
*/
|
||||
export type IncreaseLiquidityInput = {
|
||||
tokenMaxA: u64;
|
||||
tokenMaxB: u64;
|
||||
tokenMaxA: BN;
|
||||
tokenMaxB: BN;
|
||||
liquidityAmount: BN;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { BN, Program } from "@coral-xyz/anchor";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import { TOKEN_PROGRAM_ID, u64 } from "@solana/spl-token";
|
||||
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
/**
|
||||
|
@ -42,8 +43,8 @@ export type SwapParams = SwapInput & {
|
|||
* @param tickArray2 - The next tick-array in the swap direction after tickArray2. If the swap will not reach the next tick-aray, input the same array as tickArray1.
|
||||
*/
|
||||
export type SwapInput = {
|
||||
amount: u64;
|
||||
otherAmountThreshold: u64;
|
||||
amount: BN;
|
||||
otherAmountThreshold: BN;
|
||||
sqrtPriceLimit: BN;
|
||||
amountSpecifiedIsInput: boolean;
|
||||
aToB: boolean;
|
||||
|
@ -60,7 +61,7 @@ export type SwapInput = {
|
|||
* @param devFeeAmount - FeeAmount (developer fees) charged on this swap
|
||||
*/
|
||||
export type DevFeeSwapInput = SwapInput & {
|
||||
devFeeAmount: u64;
|
||||
devFeeAmount: BN;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { BN, Program } from "@coral-xyz/anchor";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import { TOKEN_PROGRAM_ID, u64 } from "@solana/spl-token";
|
||||
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
/**
|
||||
|
@ -59,8 +60,8 @@ export type TwoHopSwapParams = TwoHopSwapInput & {
|
|||
* @param tickArrayTwo2 - The next tick-array in the swap direction after tickArray2 of swap-Two. If the swap will not reach the next tick-aray, input the same array as tickArray1.
|
||||
*/
|
||||
export type TwoHopSwapInput = {
|
||||
amount: u64;
|
||||
otherAmountThreshold: u64;
|
||||
amount: BN;
|
||||
otherAmountThreshold: BN;
|
||||
amountSpecifiedIsInput: boolean;
|
||||
aToBOne: boolean;
|
||||
aToBTwo: boolean;
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
import { Address } from "@coral-xyz/anchor";
|
||||
import { AddressUtil } from "@orca-so/common-sdk";
|
||||
import { AccountInfo, AccountLayout, MintInfo } from "@solana/spl-token";
|
||||
import {
|
||||
AddressUtil,
|
||||
ParsableEntity,
|
||||
ParsableMintInfo,
|
||||
ParsableTokenAccountInfo,
|
||||
getMultipleAccountsInMap,
|
||||
} from "@orca-so/common-sdk";
|
||||
import { Account, AccountLayout, Mint } from "@solana/spl-token";
|
||||
import { Connection, PublicKey } from "@solana/web3.js";
|
||||
import invariant from "tiny-invariant";
|
||||
import {
|
||||
|
@ -14,13 +20,10 @@ import {
|
|||
} from "../..";
|
||||
import { FeeTierData, getAccountSize } from "../../types/public";
|
||||
import {
|
||||
ParsableEntity,
|
||||
ParsableFeeTier,
|
||||
ParsableMintInfo,
|
||||
ParsablePosition,
|
||||
ParsablePositionBundle,
|
||||
ParsableTickArray,
|
||||
ParsableTokenInfo,
|
||||
ParsableWhirlpool,
|
||||
ParsableWhirlpoolsConfig,
|
||||
} from "./parsing";
|
||||
|
@ -35,8 +38,8 @@ type CachedValue =
|
|||
| TickArrayData
|
||||
| FeeTierData
|
||||
| PositionBundleData
|
||||
| AccountInfo
|
||||
| MintInfo;
|
||||
| Account
|
||||
| Mint;
|
||||
|
||||
/**
|
||||
* Include both the entity (i.e. type) of the stored value, and the value itself
|
||||
|
@ -46,16 +49,6 @@ interface CachedContent<T extends CachedValue> {
|
|||
value: CachedValue | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type for rpc batch request response
|
||||
*/
|
||||
type GetMultipleAccountsResponse = {
|
||||
error?: string;
|
||||
result?: {
|
||||
value?: ({ data: [string, string] } | null)[];
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Filter params for Whirlpools when invoking getProgramAccounts.
|
||||
* @category Fetcher
|
||||
|
@ -157,8 +150,8 @@ export class AccountFetcher {
|
|||
* @param refresh force cache refresh
|
||||
* @returns token info account
|
||||
*/
|
||||
public async getTokenInfo(address: Address, refresh = false): Promise<AccountInfo | null> {
|
||||
return this.get(AddressUtil.toPubKey(address), ParsableTokenInfo, refresh);
|
||||
public async getTokenInfo(address: Address, refresh = false): Promise<Account | null> {
|
||||
return this.get(AddressUtil.toPubKey(address), ParsableTokenAccountInfo, refresh);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -168,7 +161,7 @@ export class AccountFetcher {
|
|||
* @param refresh force cache refresh
|
||||
* @returns mint info account
|
||||
*/
|
||||
public async getMintInfo(address: Address, refresh = false): Promise<MintInfo | null> {
|
||||
public async getMintInfo(address: Address, refresh = false): Promise<Mint | null> {
|
||||
return this.get(AddressUtil.toPubKey(address), ParsableMintInfo, refresh);
|
||||
}
|
||||
|
||||
|
@ -238,7 +231,7 @@ export class AccountFetcher {
|
|||
|
||||
const parsedAccounts: WhirlpoolAccount[] = [];
|
||||
accounts.forEach(({ pubkey, account }) => {
|
||||
const parsedAccount = ParsableWhirlpool.parse(account.data);
|
||||
const parsedAccount = ParsableWhirlpool.parse(pubkey, account);
|
||||
invariant(!!parsedAccount, `could not parse whirlpool: ${pubkey.toBase58()}`);
|
||||
parsedAccounts.push([pubkey, parsedAccount]);
|
||||
this._cache[pubkey.toBase58()] = { entity: ParsableWhirlpool, value: parsedAccount };
|
||||
|
@ -282,11 +275,8 @@ export class AccountFetcher {
|
|||
* @param refresh force cache refresh
|
||||
* @returns token info accounts
|
||||
*/
|
||||
public async listTokenInfos(
|
||||
addresses: Address[],
|
||||
refresh: boolean
|
||||
): Promise<(AccountInfo | null)[]> {
|
||||
return this.list(AddressUtil.toPubKeys(addresses), ParsableTokenInfo, refresh);
|
||||
public async listTokenInfos(addresses: Address[], refresh: boolean): Promise<(Account | null)[]> {
|
||||
return this.list(AddressUtil.toPubKeys(addresses), ParsableTokenAccountInfo, refresh);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -296,7 +286,7 @@ export class AccountFetcher {
|
|||
* @param refresh force cache refresh
|
||||
* @returns mint info accounts
|
||||
*/
|
||||
public async listMintInfos(addresses: Address[], refresh: boolean): Promise<(MintInfo | null)[]> {
|
||||
public async listMintInfos(addresses: Address[], refresh: boolean): Promise<(Mint | null)[]> {
|
||||
return this.list(AddressUtil.toPubKeys(addresses), ParsableMintInfo, refresh);
|
||||
}
|
||||
|
||||
|
@ -320,11 +310,12 @@ export class AccountFetcher {
|
|||
*/
|
||||
public async refreshAll(): Promise<void> {
|
||||
const addresses: string[] = Object.keys(this._cache);
|
||||
const data = await this.bulkRequest(addresses);
|
||||
const fetchedAccountsMap = await getMultipleAccountsInMap(this.connection, addresses);
|
||||
|
||||
for (const [idx, [key, cachedContent]] of Object.entries(this._cache).entries()) {
|
||||
for (const [key, cachedContent] of Object.entries(this._cache)) {
|
||||
const entity = cachedContent.entity;
|
||||
const value = entity.parse(data[idx]);
|
||||
const fetchedEntry = fetchedAccountsMap.get(key);
|
||||
const value = entity.parse(AddressUtil.toPubKey(key), fetchedEntry);
|
||||
|
||||
this._cache[key] = { entity, value };
|
||||
}
|
||||
|
@ -348,8 +339,7 @@ export class AccountFetcher {
|
|||
}
|
||||
|
||||
const accountInfo = await this.connection.getAccountInfo(address);
|
||||
const accountData = accountInfo?.data;
|
||||
const value = entity.parse(accountData);
|
||||
const value = entity.parse(address, accountInfo);
|
||||
this._cache[key] = { entity, value };
|
||||
|
||||
return value;
|
||||
|
@ -379,9 +369,13 @@ export class AccountFetcher {
|
|||
|
||||
/* Fetch accounts not found in cache */
|
||||
if (undefinedAccounts.length > 0) {
|
||||
const data = await this.bulkRequest(undefinedAccounts.map((account) => account.key));
|
||||
undefinedAccounts.forEach(({ cacheIndex, key }, dataIndex) => {
|
||||
const value = entity.parse(data[dataIndex]);
|
||||
const fetchedAccountsMap = await getMultipleAccountsInMap(
|
||||
this.connection,
|
||||
undefinedAccounts.map((account) => account.key)
|
||||
);
|
||||
undefinedAccounts.forEach(({ cacheIndex, key }) => {
|
||||
const fetchedEntry = fetchedAccountsMap.get(key);
|
||||
const value = entity.parse(AddressUtil.toPubKey(key), fetchedEntry);
|
||||
invariant(cachedValues[cacheIndex]?.[1] === undefined, "unexpected non-undefined value");
|
||||
cachedValues[cacheIndex] = [key, value];
|
||||
this._cache[key] = { entity, value };
|
||||
|
@ -394,39 +388,4 @@ export class AccountFetcher {
|
|||
invariant(result.length === addresses.length, "not enough results fetched");
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make batch rpc request
|
||||
*/
|
||||
private async bulkRequest(addresses: string[]): Promise<(Buffer | null)[]> {
|
||||
const responses: Promise<GetMultipleAccountsResponse>[] = [];
|
||||
const chunk = 100; // getMultipleAccounts has limitation of 100 accounts per request
|
||||
|
||||
for (let i = 0; i < addresses.length; i += chunk) {
|
||||
const addressesSubset = addresses.slice(i, i + chunk);
|
||||
const res = (this.connection as any)._rpcRequest("getMultipleAccounts", [
|
||||
addressesSubset,
|
||||
{ commitment: this.connection.commitment },
|
||||
]);
|
||||
responses.push(res);
|
||||
}
|
||||
|
||||
const combinedResult: (Buffer | null)[] = [];
|
||||
|
||||
(await Promise.all(responses)).forEach((res) => {
|
||||
invariant(!res.error, `bulkRequest result error: ${res.error}`);
|
||||
invariant(!!res.result?.value, "bulkRequest no value");
|
||||
|
||||
res.result.value.forEach((account) => {
|
||||
if (!account || account.data[1] !== "base64") {
|
||||
combinedResult.push(null);
|
||||
} else {
|
||||
combinedResult.push(Buffer.from(account.data[0], account.data[1]));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
invariant(combinedResult.length === addresses.length, "bulkRequest not enough results");
|
||||
return combinedResult;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { BorshAccountsCoder, Idl } from "@coral-xyz/anchor";
|
||||
import { TokenUtil } from "@orca-so/common-sdk";
|
||||
import { AccountInfo, MintInfo, MintLayout, u64 } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { ParsableEntity, staticImplements } from "@orca-so/common-sdk";
|
||||
import { AccountInfo, PublicKey } from "@solana/web3.js";
|
||||
import * as WhirlpoolIDL from "../../artifacts/whirlpool.json";
|
||||
import {
|
||||
AccountName,
|
||||
|
@ -13,34 +12,23 @@ import {
|
|||
WhirlpoolsConfigData,
|
||||
} from "../../types/public";
|
||||
|
||||
/**
|
||||
* Static abstract class definition to parse entities.
|
||||
* @category Parsables
|
||||
*/
|
||||
export interface ParsableEntity<T> {
|
||||
/**
|
||||
* Parse account data
|
||||
*
|
||||
* @param accountData Buffer data for the entity
|
||||
* @returns Parsed entity
|
||||
*/
|
||||
parse: (accountData: Buffer | undefined | null) => T | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @category Parsables
|
||||
*/
|
||||
@staticImplements<ParsableEntity<WhirlpoolsConfigData>>()
|
||||
export class ParsableWhirlpoolsConfig {
|
||||
private constructor() {}
|
||||
private constructor() { }
|
||||
|
||||
public static parse(data: Buffer | undefined | null): WhirlpoolsConfigData | null {
|
||||
if (!data) {
|
||||
public static parse(
|
||||
address: PublicKey,
|
||||
accountData: AccountInfo<Buffer> | undefined | null
|
||||
): WhirlpoolsConfigData | null {
|
||||
if (!accountData?.data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return parseAnchorAccount(AccountName.WhirlpoolsConfig, data);
|
||||
return parseAnchorAccount(AccountName.WhirlpoolsConfig, accountData);
|
||||
} catch (e) {
|
||||
console.error(`error while parsing WhirlpoolsConfig: ${e}`);
|
||||
return null;
|
||||
|
@ -53,15 +41,18 @@ export class ParsableWhirlpoolsConfig {
|
|||
*/
|
||||
@staticImplements<ParsableEntity<WhirlpoolData>>()
|
||||
export class ParsableWhirlpool {
|
||||
private constructor() {}
|
||||
private constructor() { }
|
||||
|
||||
public static parse(data: Buffer | undefined | null): WhirlpoolData | null {
|
||||
if (!data) {
|
||||
public static parse(
|
||||
address: PublicKey,
|
||||
accountData: AccountInfo<Buffer> | undefined | null
|
||||
): WhirlpoolData | null {
|
||||
if (!accountData?.data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return parseAnchorAccount(AccountName.Whirlpool, data);
|
||||
return parseAnchorAccount(AccountName.Whirlpool, accountData);
|
||||
} catch (e) {
|
||||
console.error(`error while parsing Whirlpool: ${e}`);
|
||||
return null;
|
||||
|
@ -74,15 +65,18 @@ export class ParsableWhirlpool {
|
|||
*/
|
||||
@staticImplements<ParsableEntity<PositionData>>()
|
||||
export class ParsablePosition {
|
||||
private constructor() {}
|
||||
private constructor() { }
|
||||
|
||||
public static parse(data: Buffer | undefined | null): PositionData | null {
|
||||
if (!data) {
|
||||
public static parse(
|
||||
address: PublicKey,
|
||||
accountData: AccountInfo<Buffer> | undefined | null
|
||||
): PositionData | null {
|
||||
if (!accountData?.data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return parseAnchorAccount(AccountName.Position, data);
|
||||
return parseAnchorAccount(AccountName.Position, accountData);
|
||||
} catch (e) {
|
||||
console.error(`error while parsing Position: ${e}`);
|
||||
return null;
|
||||
|
@ -95,15 +89,18 @@ export class ParsablePosition {
|
|||
*/
|
||||
@staticImplements<ParsableEntity<TickArrayData>>()
|
||||
export class ParsableTickArray {
|
||||
private constructor() {}
|
||||
private constructor() { }
|
||||
|
||||
public static parse(data: Buffer | undefined | null): TickArrayData | null {
|
||||
if (!data) {
|
||||
public static parse(
|
||||
address: PublicKey,
|
||||
accountData: AccountInfo<Buffer> | undefined | null
|
||||
): TickArrayData | null {
|
||||
if (!accountData?.data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return parseAnchorAccount(AccountName.TickArray, data);
|
||||
return parseAnchorAccount(AccountName.TickArray, accountData);
|
||||
} catch (e) {
|
||||
console.error(`error while parsing TickArray: ${e}`);
|
||||
return null;
|
||||
|
@ -116,15 +113,18 @@ export class ParsableTickArray {
|
|||
*/
|
||||
@staticImplements<ParsableEntity<FeeTierData>>()
|
||||
export class ParsableFeeTier {
|
||||
private constructor() {}
|
||||
private constructor() { }
|
||||
|
||||
public static parse(data: Buffer | undefined | null): FeeTierData | null {
|
||||
if (!data) {
|
||||
public static parse(
|
||||
address: PublicKey,
|
||||
accountData: AccountInfo<Buffer> | undefined | null
|
||||
): FeeTierData | null {
|
||||
if (!accountData?.data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return parseAnchorAccount(AccountName.FeeTier, data);
|
||||
return parseAnchorAccount(AccountName.FeeTier, accountData);
|
||||
} catch (e) {
|
||||
console.error(`error while parsing FeeTier: ${e}`);
|
||||
return null;
|
||||
|
@ -137,15 +137,18 @@ export class ParsableFeeTier {
|
|||
*/
|
||||
@staticImplements<ParsableEntity<PositionBundleData>>()
|
||||
export class ParsablePositionBundle {
|
||||
private constructor() {}
|
||||
private constructor() { }
|
||||
|
||||
public static parse(data: Buffer | undefined | null): PositionBundleData | null {
|
||||
if (!data) {
|
||||
public static parse(
|
||||
address: PublicKey,
|
||||
accountData: AccountInfo<Buffer> | undefined | null
|
||||
): PositionBundleData | null {
|
||||
if (!accountData?.data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return parseAnchorAccount(AccountName.PositionBundle, data);
|
||||
return parseAnchorAccount(AccountName.PositionBundle, accountData);
|
||||
} catch (e) {
|
||||
console.error(`error while parsing PositionBundle: ${e}`);
|
||||
return null;
|
||||
|
@ -153,72 +156,10 @@ export class ParsablePositionBundle {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @category Parsables
|
||||
*/
|
||||
@staticImplements<ParsableEntity<AccountInfo>>()
|
||||
export class ParsableTokenInfo {
|
||||
private constructor() {}
|
||||
|
||||
public static parse(data: Buffer | undefined | null): AccountInfo | null {
|
||||
if (!data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return TokenUtil.deserializeTokenAccount(data);
|
||||
} catch (e) {
|
||||
console.error(`error while parsing TokenAccount: ${e}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @category Parsables
|
||||
*/
|
||||
@staticImplements<ParsableEntity<MintInfo>>()
|
||||
export class ParsableMintInfo {
|
||||
private constructor() {}
|
||||
|
||||
public static parse(data: Buffer | undefined | null): MintInfo | null {
|
||||
if (!data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const buffer = MintLayout.decode(data);
|
||||
const mintInfo: MintInfo = {
|
||||
mintAuthority:
|
||||
buffer.mintAuthorityOption === 0 ? null : new PublicKey(buffer.mintAuthority),
|
||||
supply: u64.fromBuffer(buffer.supply),
|
||||
decimals: buffer.decimals,
|
||||
isInitialized: buffer.isInitialized !== 0,
|
||||
freezeAuthority:
|
||||
buffer.freezeAuthorityOption === 0 ? null : new PublicKey(buffer.freezeAuthority),
|
||||
};
|
||||
|
||||
return mintInfo;
|
||||
} catch (e) {
|
||||
console.error(`error while parsing MintInfo: ${e}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class decorator to define an interface with static methods
|
||||
* Reference: https://github.com/Microsoft/TypeScript/issues/13462#issuecomment-295685298
|
||||
*/
|
||||
function staticImplements<T>() {
|
||||
return <U extends T>(constructor: U) => {
|
||||
constructor;
|
||||
};
|
||||
}
|
||||
|
||||
const WhirlpoolCoder = new BorshAccountsCoder(WhirlpoolIDL as Idl);
|
||||
|
||||
function parseAnchorAccount(accountName: AccountName, data: Buffer) {
|
||||
function parseAnchorAccount(accountName: AccountName, accountData: AccountInfo<Buffer>) {
|
||||
const data = accountData.data;
|
||||
const discriminator = BorshAccountsCoder.accountDiscriminator(accountName);
|
||||
if (discriminator.compare(data.slice(0, 8))) {
|
||||
console.error("incorrect account name during parsing");
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
import { Address } from "@coral-xyz/anchor";
|
||||
import { AddressUtil, DecimalUtil, Percentage } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import Decimal from "decimal.js";
|
||||
import {
|
||||
DecimalsMap,
|
||||
defaultGetPricesConfig,
|
||||
GetPricesConfig,
|
||||
GetPricesThresholdConfig,
|
||||
PoolMap,
|
||||
PriceMap,
|
||||
TickArrayMap,
|
||||
defaultGetPricesConfig,
|
||||
} from ".";
|
||||
import { swapQuoteWithParams } from "../quotes/public/swap-quote";
|
||||
import { TickArray, WhirlpoolData } from "../types/public";
|
||||
|
@ -57,9 +57,9 @@ function checkLiquidity(
|
|||
outputDecimals = decimalsMap[pool.tokenMintA.toBase58()];
|
||||
}
|
||||
|
||||
const amountOutDecimals = DecimalUtil.fromU64(amountOut, outputDecimals);
|
||||
const amountOutDecimals = DecimalUtil.fromBN(amountOut, outputDecimals);
|
||||
|
||||
const estimatedAmountInDecimals = DecimalUtil.fromU64(estimatedAmountIn, inputDecimals);
|
||||
const estimatedAmountInDecimals = DecimalUtil.fromBN(estimatedAmountIn, inputDecimals);
|
||||
|
||||
const maxAmountInDecimals = amountOutDecimals
|
||||
.div(price)
|
||||
|
@ -184,10 +184,10 @@ export function isSubset(listA: string[], listB: string[]): boolean {
|
|||
}
|
||||
|
||||
export function convertAmount(
|
||||
amount: u64,
|
||||
amount: BN,
|
||||
price: Decimal,
|
||||
amountDecimal: number,
|
||||
resultDecimal: number
|
||||
): u64 {
|
||||
return DecimalUtil.toU64(DecimalUtil.fromU64(amount, amountDecimal).div(price), resultDecimal);
|
||||
): BN {
|
||||
return DecimalUtil.toBN(DecimalUtil.fromBN(amount, amountDecimal).div(price), resultDecimal);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { u64 } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import Decimal from "decimal.js";
|
||||
import {
|
||||
ORCA_SUPPORTED_TICK_SPACINGS,
|
||||
|
@ -40,7 +40,7 @@ export type GetPricesConfig = {
|
|||
* that a Whirlpool can have to be included in the price calculation.
|
||||
*/
|
||||
export type GetPricesThresholdConfig = {
|
||||
amountOut: u64;
|
||||
amountOut: BN;
|
||||
priceImpactThreshold: number;
|
||||
};
|
||||
|
||||
|
@ -110,6 +110,6 @@ export const defaultGetPricesConfig: GetPricesConfig = {
|
|||
* @category PriceModule
|
||||
*/
|
||||
export const defaultGetPricesThresholdConfig: GetPricesThresholdConfig = {
|
||||
amountOut: new u64(1_000_000_000),
|
||||
amountOut: new BN(1_000_000_000),
|
||||
priceImpactThreshold: 1.05,
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Address } from "@coral-xyz/anchor";
|
||||
import { Percentage } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import BN from "bn.js";
|
||||
import { AccountFetcher } from "../..";
|
||||
import { SwapErrorCode, WhirlpoolsError } from "../../errors/errors";
|
||||
import { Whirlpool } from "../../whirlpool-client";
|
||||
|
@ -23,8 +23,8 @@ export type DevFeeSwapQuote = NormalSwapQuote & {
|
|||
// If there are third party requests in the future for this functionality, we can launch it
|
||||
// but with the caveat that the % collected is only an estimate.
|
||||
amountSpecifiedIsInput: true;
|
||||
estimatedSwapFeeAmount: u64;
|
||||
devFeeAmount: u64;
|
||||
estimatedSwapFeeAmount: BN;
|
||||
devFeeAmount: BN;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -44,7 +44,7 @@ export type DevFeeSwapQuote = NormalSwapQuote & {
|
|||
export async function swapQuoteByInputTokenWithDevFees(
|
||||
whirlpool: Whirlpool,
|
||||
inputTokenMint: Address,
|
||||
tokenAmount: u64,
|
||||
tokenAmount: BN,
|
||||
slippageTolerance: Percentage,
|
||||
programId: Address,
|
||||
fetcher: AccountFetcher,
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
import { Address, BN } from "@coral-xyz/anchor";
|
||||
import { Address } from "@coral-xyz/anchor";
|
||||
import { AddressUtil, DecimalUtil, Percentage, ZERO } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import Decimal from "decimal.js";
|
||||
import invariant from "tiny-invariant";
|
||||
import { IncreaseLiquidityInput } from "../../instructions";
|
||||
import {
|
||||
PositionStatus,
|
||||
PositionUtil,
|
||||
adjustForSlippage,
|
||||
getLiquidityFromTokenA,
|
||||
getLiquidityFromTokenB,
|
||||
getTokenAFromLiquidity,
|
||||
getTokenBFromLiquidity,
|
||||
PositionStatus,
|
||||
PositionUtil,
|
||||
} from "../../utils/position-util";
|
||||
import { PriceMath, TickUtil } from "../../utils/public";
|
||||
import { Whirlpool } from "../../whirlpool-client";
|
||||
|
@ -30,7 +30,7 @@ import { Whirlpool } from "../../whirlpool-client";
|
|||
* @param slippageTolerance - The maximum slippage allowed when calculating the minimum tokens received.
|
||||
*/
|
||||
export type IncreaseLiquidityQuoteParam = {
|
||||
inputTokenAmount: u64;
|
||||
inputTokenAmount: BN;
|
||||
inputTokenMint: PublicKey;
|
||||
tokenMintA: PublicKey;
|
||||
tokenMintB: PublicKey;
|
||||
|
@ -45,7 +45,7 @@ export type IncreaseLiquidityQuoteParam = {
|
|||
* Return object from increase liquidity quote functions.
|
||||
* @category Quotes
|
||||
*/
|
||||
export type IncreaseLiquidityQuote = IncreaseLiquidityInput & { tokenEstA: u64; tokenEstB: u64 };
|
||||
export type IncreaseLiquidityQuote = IncreaseLiquidityInput & { tokenEstA: BN; tokenEstB: BN };
|
||||
|
||||
/**
|
||||
* Get an estimated quote on the maximum tokens required to deposit based on a specified input token amount.
|
||||
|
@ -76,7 +76,7 @@ export function increaseLiquidityQuoteByInputToken(
|
|||
|
||||
return increaseLiquidityQuoteByInputTokenWithParams({
|
||||
inputTokenMint: inputMint,
|
||||
inputTokenAmount: DecimalUtil.toU64(inputTokenAmount, inputTokenInfo.decimals),
|
||||
inputTokenAmount: DecimalUtil.toBN(inputTokenAmount, inputTokenInfo.decimals),
|
||||
tickLowerIndex: TickUtil.getInitializableTickIndex(tickLower, data.tickSpacing),
|
||||
tickUpperIndex: TickUtil.getInitializableTickIndex(tickUpper, data.tickSpacing),
|
||||
slippageTolerance,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Address, BN } from "@coral-xyz/anchor";
|
||||
import { Address } from "@coral-xyz/anchor";
|
||||
import { AddressUtil, Percentage } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import BN from "bn.js";
|
||||
import invariant from "tiny-invariant";
|
||||
import { SwapInput } from "../../instructions";
|
||||
import { AccountFetcher } from "../../network/public";
|
||||
|
@ -24,8 +24,8 @@ import { DevFeeSwapQuote } from "./dev-fee-swap-quote";
|
|||
*/
|
||||
export type SwapQuoteParam = {
|
||||
whirlpoolData: WhirlpoolData;
|
||||
tokenAmount: u64;
|
||||
otherAmountThreshold: u64;
|
||||
tokenAmount: BN;
|
||||
otherAmountThreshold: BN;
|
||||
sqrtPriceLimit: BN;
|
||||
aToB: boolean;
|
||||
amountSpecifiedIsInput: boolean;
|
||||
|
@ -50,11 +50,11 @@ export type SwapQuote = NormalSwapQuote | DevFeeSwapQuote;
|
|||
* @param estimatedFeeAmount - Approximate feeAmount (all fees) charged on this swap
|
||||
*/
|
||||
export type SwapEstimates = {
|
||||
estimatedAmountIn: u64;
|
||||
estimatedAmountOut: u64;
|
||||
estimatedAmountIn: BN;
|
||||
estimatedAmountOut: BN;
|
||||
estimatedEndTickIndex: number;
|
||||
estimatedEndSqrtPrice: BN;
|
||||
estimatedFeeAmount: u64;
|
||||
estimatedFeeAmount: BN;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -79,7 +79,7 @@ export type NormalSwapQuote = SwapInput & SwapEstimates;
|
|||
export async function swapQuoteByInputToken(
|
||||
whirlpool: Whirlpool,
|
||||
inputTokenMint: Address,
|
||||
tokenAmount: u64,
|
||||
tokenAmount: BN,
|
||||
slippageTolerance: Percentage,
|
||||
programId: Address,
|
||||
fetcher: AccountFetcher,
|
||||
|
@ -116,7 +116,7 @@ export async function swapQuoteByInputToken(
|
|||
export async function swapQuoteByOutputToken(
|
||||
whirlpool: Whirlpool,
|
||||
outputTokenMint: Address,
|
||||
tokenAmount: u64,
|
||||
tokenAmount: BN,
|
||||
slippageTolerance: Percentage,
|
||||
programId: Address,
|
||||
fetcher: AccountFetcher,
|
||||
|
@ -165,7 +165,7 @@ export function swapQuoteWithParams(
|
|||
async function swapQuoteByToken(
|
||||
whirlpool: Whirlpool,
|
||||
inputTokenMint: Address,
|
||||
tokenAmount: u64,
|
||||
tokenAmount: BN,
|
||||
amountSpecifiedIsInput: boolean,
|
||||
programId: Address,
|
||||
fetcher: AccountFetcher,
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
import { ZERO } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import BN from "bn.js";
|
||||
import { PROTOCOL_FEE_RATE_MUL_VALUE, WhirlpoolData } from "../../types/public";
|
||||
import { computeSwapStep } from "../../utils/math/swap-math";
|
||||
import { PriceMath } from "../../utils/public";
|
||||
import { TickArraySequence } from "./tick-array-sequence";
|
||||
import { computeSwapStep } from "../../utils/math/swap-math";
|
||||
|
||||
export type SwapResult = {
|
||||
amountA: BN;
|
||||
|
@ -17,7 +16,7 @@ export type SwapResult = {
|
|||
export function computeSwap(
|
||||
whirlpoolData: WhirlpoolData,
|
||||
tickSequence: TickArraySequence,
|
||||
tokenAmount: u64,
|
||||
tokenAmount: BN,
|
||||
sqrtPriceLimit: BN,
|
||||
amountSpecifiedIsInput: boolean,
|
||||
aToB: boolean
|
||||
|
@ -30,7 +29,7 @@ export function computeSwap(
|
|||
let totalFeeAmount = ZERO;
|
||||
const feeRate = whirlpoolData.feeRate;
|
||||
const protocolFeeRate = whirlpoolData.protocolFeeRate;
|
||||
let currProtocolFee = new u64(0);
|
||||
let currProtocolFee = new BN(0);
|
||||
let currFeeGrowthGlobalInput = aToB
|
||||
? whirlpoolData.feeGrowthGlobalA
|
||||
: whirlpoolData.feeGrowthGlobalB;
|
||||
|
@ -143,7 +142,7 @@ function calculateFees(
|
|||
}
|
||||
|
||||
function calculateProtocolFee(globalFee: BN, protocolFeeRate: number) {
|
||||
return globalFee.mul(new u64(protocolFeeRate).div(PROTOCOL_FEE_RATE_MUL_VALUE));
|
||||
return globalFee.mul(new BN(protocolFeeRate).div(PROTOCOL_FEE_RATE_MUL_VALUE));
|
||||
}
|
||||
|
||||
function calculateEstTokens(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Address } from "@coral-xyz/anchor";
|
||||
import { AddressUtil } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import BN from "bn.js";
|
||||
import invariant from "tiny-invariant";
|
||||
import { AccountFetcher } from "..";
|
||||
import { SwapQuoteParam } from "../quotes/public";
|
||||
|
@ -9,7 +9,7 @@ import { PoolUtil, SwapDirection, SwapUtils } from "../utils/public";
|
|||
export interface SwapQuoteRequest {
|
||||
whirlpool: Address;
|
||||
tradeTokenMint: Address;
|
||||
tokenAmount: u64;
|
||||
tokenAmount: BN;
|
||||
amountSpecifiedIsInput: boolean;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { u64 } from "@solana/spl-token";
|
||||
import BN from "bn.js";
|
||||
import { kSmallestPartition } from "../utils/math/k-smallest-partition";
|
||||
import { RoutingOptions, SubTradeRoute, TradeRoute } from "./public";
|
||||
import { PathQuote, SanitizedQuoteMap } from "./quote-map";
|
||||
|
@ -43,8 +43,8 @@ function convertPathQuoteToSubTradeRoute(pathQuote: PathQuote): SubTradeRoute {
|
|||
type InternalRoute = {
|
||||
quotes: PathQuote[];
|
||||
splitPercent: number;
|
||||
totalIn: u64;
|
||||
totalOut: u64;
|
||||
totalIn: BN;
|
||||
totalOut: BN;
|
||||
};
|
||||
|
||||
function getSingleHopSplit(quoteMap: SanitizedQuoteMap): InternalRoute[] {
|
||||
|
@ -93,8 +93,8 @@ function generateRoutes(percentMap: SanitizedQuoteMap, maxSplits: number): Inter
|
|||
{
|
||||
quotes: [],
|
||||
splitPercent: 0,
|
||||
totalIn: new u64(0),
|
||||
totalOut: new u64(0),
|
||||
totalIn: new BN(0),
|
||||
totalOut: new BN(0),
|
||||
},
|
||||
routes
|
||||
);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Address } from "@coral-xyz/anchor";
|
||||
import { Percentage, TransactionBuilder } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { AddressLookupTableAccount } from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import { SwapQuote } from "../../quotes/public";
|
||||
import { Path } from "../../utils/public";
|
||||
import { AtaAccountInfo, RouteSelectOptions } from "./router-utils";
|
||||
|
@ -21,7 +21,7 @@ export * from "./router-utils";
|
|||
export type Trade = {
|
||||
tokenIn: Address;
|
||||
tokenOut: Address;
|
||||
tradeAmount: u64;
|
||||
tradeAmount: BN;
|
||||
amountSpecifiedIsInput: boolean;
|
||||
};
|
||||
|
||||
|
@ -53,8 +53,8 @@ export type RoutingOptions = {
|
|||
*/
|
||||
export type TradeRoute = {
|
||||
subRoutes: SubTradeRoute[];
|
||||
totalAmountIn: u64;
|
||||
totalAmountOut: u64;
|
||||
totalAmountIn: BN;
|
||||
totalAmountOut: BN;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -70,8 +70,8 @@ export type TradeRoute = {
|
|||
export type SubTradeRoute = {
|
||||
path: Path;
|
||||
splitPercent: number;
|
||||
amountIn: u64;
|
||||
amountOut: u64;
|
||||
amountIn: BN;
|
||||
amountOut: BN;
|
||||
hopQuotes: TradeHop[];
|
||||
};
|
||||
|
||||
|
@ -91,8 +91,8 @@ export type SubTradeRoute = {
|
|||
* @param quote The {@link SwapQuote} for this hop.
|
||||
*/
|
||||
export type TradeHop = {
|
||||
amountIn: u64;
|
||||
amountOut: u64;
|
||||
amountIn: BN;
|
||||
amountOut: BN;
|
||||
whirlpool: Address;
|
||||
inputMint: Address;
|
||||
outputMint: Address;
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
TransactionBuilder,
|
||||
TX_SIZE_LIMIT,
|
||||
} from "@orca-so/common-sdk";
|
||||
import { AccountInfo } from "@solana/spl-token";
|
||||
import { Account } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { ExecutableRoute, RoutingOptions, TradeRoute } from ".";
|
||||
import { WhirlpoolContext } from "../../context";
|
||||
|
@ -19,7 +19,7 @@ import { isWalletConnected } from "../../utils/wallet-utils";
|
|||
* @param owner The owner address of the ATA.
|
||||
* @param mint The mint of the token the ATA represents.
|
||||
*/
|
||||
export type AtaAccountInfo = Pick<AccountInfo, "address" | "owner" | "mint">;
|
||||
export type AtaAccountInfo = Pick<Account, "address" | "owner" | "mint">;
|
||||
|
||||
/**
|
||||
* Parameters to configure the selection of the best route.
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { Address } from "@coral-xyz/anchor";
|
||||
import { AddressUtil, Percentage } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import { AccountFetcher } from "..";
|
||||
|
@ -18,8 +17,8 @@ export type PathQuote = {
|
|||
path: Path;
|
||||
edgesPoolAddrs: string[];
|
||||
splitPercent: number;
|
||||
amountIn: u64;
|
||||
amountOut: u64;
|
||||
amountIn: BN;
|
||||
amountOut: BN;
|
||||
calculatedEdgeQuotes: TradeHopQuoteSuccess[];
|
||||
};
|
||||
|
||||
|
@ -206,7 +205,7 @@ function buildQuoteUpdateRequests(
|
|||
: currentQuote.calculatedEdgeQuotes[hop + 1];
|
||||
|
||||
// If this is the first hop, use the input mint and amount, otherwise use the output of the last hop
|
||||
let tokenAmount: u64;
|
||||
let tokenAmount: BN;
|
||||
let tradeToken: Address;
|
||||
if (startingRouteEval) {
|
||||
tokenAmount = tradeAmount;
|
||||
|
@ -299,13 +298,13 @@ function sanitizeQuoteMap(
|
|||
return [prunedQuoteMap, failureErrors] as const;
|
||||
}
|
||||
|
||||
function getSplitPercentageAmts(inputAmount: u64, minPercent: number = 5) {
|
||||
function getSplitPercentageAmts(inputAmount: BN, minPercent: number = 5) {
|
||||
const percents = [];
|
||||
const amounts = [];
|
||||
|
||||
for (let i = 1; i <= 100 / minPercent; i++) {
|
||||
percents.push(i * minPercent);
|
||||
amounts.push(inputAmount.mul(new u64(i * minPercent)).div(new u64(100)));
|
||||
amounts.push(inputAmount.mul(new BN(i * minPercent)).div(new BN(100)));
|
||||
}
|
||||
|
||||
return { percents, amounts };
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Address } from "@coral-xyz/anchor";
|
||||
import { AddressUtil, Percentage, TransactionBuilder } from "@orca-so/common-sdk";
|
||||
import { AccountInfo } from "@solana/spl-token";
|
||||
import { Account } from "@solana/spl-token";
|
||||
import { AccountFetcher, WhirlpoolContext } from "..";
|
||||
import { RouteQueryErrorCode, SwapErrorCode, WhirlpoolsError } from "../errors/errors";
|
||||
import { getSwapFromRoute } from "../instructions/composites/swap-with-route";
|
||||
|
@ -106,7 +106,7 @@ export class WhirlpoolRouterImpl implements WhirlpoolRouter {
|
|||
async swap(
|
||||
trade: TradeRoute,
|
||||
slippage: Percentage,
|
||||
resolvedAtas: AccountInfo[] | null
|
||||
resolvedAtas: Account[] | null
|
||||
): Promise<TransactionBuilder> {
|
||||
const txBuilder = await getSwapFromRoute(
|
||||
this.ctx,
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
import { AccountInfo, MintInfo, u64 } from "@solana/spl-token";
|
||||
import { Account, Mint } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import { TickArrayData, WhirlpoolRewardInfoData } from "./anchor-types";
|
||||
|
||||
/**
|
||||
* Extended MintInfo type to host token info.
|
||||
* Extended Mint type to host token info.
|
||||
* @category WhirlpoolClient
|
||||
*/
|
||||
export type TokenInfo = MintInfo & { mint: PublicKey };
|
||||
export type TokenInfo = Mint & { mint: PublicKey };
|
||||
|
||||
/**
|
||||
* Extended AccountInfo type to host account info for a Token.
|
||||
* Extended (token) Account type to host account info for a Token.
|
||||
* @category WhirlpoolClient
|
||||
*/
|
||||
export type TokenAccountInfo = AccountInfo;
|
||||
export type TokenAccountInfo = Account;
|
||||
|
||||
/**
|
||||
* Type to represent a reward for a reward index on a Whirlpool.
|
||||
|
@ -20,7 +21,7 @@ export type TokenAccountInfo = AccountInfo;
|
|||
*/
|
||||
export type WhirlpoolRewardInfo = WhirlpoolRewardInfoData & {
|
||||
initialized: boolean;
|
||||
vaultAmount: u64;
|
||||
vaultAmount: BN;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
import { Token } from "@solana/spl-token";
|
||||
import { PublicKey, SystemProgram, TransactionInstruction } from "@solana/web3.js";
|
||||
|
||||
export function createAssociatedTokenAccountInstruction(
|
||||
associatedTokenProgramId: PublicKey,
|
||||
tokenProgramId: PublicKey,
|
||||
mint: PublicKey,
|
||||
associatedAccount: PublicKey,
|
||||
owner: PublicKey,
|
||||
payer: PublicKey,
|
||||
modeIdempotent: boolean
|
||||
): TransactionInstruction {
|
||||
if (!modeIdempotent) {
|
||||
return Token.createAssociatedTokenAccountInstruction(
|
||||
associatedTokenProgramId,
|
||||
tokenProgramId,
|
||||
mint,
|
||||
associatedAccount,
|
||||
owner,
|
||||
payer
|
||||
);
|
||||
}
|
||||
|
||||
// create CreateIdempotent instruction
|
||||
// spl-token v0.1.8 doesn't have a method for CreateIdempotent.
|
||||
// https://github.com/solana-labs/solana-program-library/blob/master/associated-token-account/program/src/instruction.rs#L26
|
||||
const keys = [
|
||||
{ pubkey: payer, isSigner: true, isWritable: true },
|
||||
{ pubkey: associatedAccount, isSigner: false, isWritable: true },
|
||||
{ pubkey: owner, isSigner: false, isWritable: false },
|
||||
{ pubkey: mint, isSigner: false, isWritable: false },
|
||||
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
||||
{ pubkey: tokenProgramId, isSigner: false, isWritable: false },
|
||||
];
|
||||
const instructionData = Buffer.from([1]);
|
||||
|
||||
return new TransactionInstruction({
|
||||
keys,
|
||||
programId: associatedTokenProgramId,
|
||||
data: instructionData,
|
||||
});
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
import { BN } from "@coral-xyz/anchor";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import BN from "bn.js";
|
||||
import { FEE_RATE_MUL_VALUE } from "../../types/public";
|
||||
import { BitMath } from "./bit-math";
|
||||
import { getAmountDeltaA, getAmountDeltaB, getNextSqrtPrice } from "./token-math";
|
||||
|
@ -12,7 +11,7 @@ export type SwapStep = {
|
|||
};
|
||||
|
||||
export function computeSwapStep(
|
||||
amountRemaining: u64,
|
||||
amountRemaining: BN,
|
||||
feeRate: number,
|
||||
currLiquidity: BN,
|
||||
currSqrtPrice: BN,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { BN } from "@coral-xyz/anchor";
|
||||
import { Percentage, U64_MAX, ZERO } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import BN from "bn.js";
|
||||
import { MathErrorCode, TokenErrorCode, WhirlpoolsError } from "../../errors/errors";
|
||||
import { MAX_SQRT_PRICE, MIN_SQRT_PRICE } from "../../types/public";
|
||||
import { BitMath } from "./bit-math";
|
||||
|
@ -43,7 +42,7 @@ export function getAmountDeltaB(
|
|||
export function getNextSqrtPrice(
|
||||
sqrtPrice: BN,
|
||||
currLiquidity: BN,
|
||||
amount: u64,
|
||||
amount: BN,
|
||||
amountSpecifiedIsInput: boolean,
|
||||
aToB: boolean
|
||||
) {
|
||||
|
@ -77,7 +76,7 @@ function toIncreasingPriceOrder(sqrtPrice0: BN, sqrtPrice1: BN) {
|
|||
function getNextSqrtPriceFromARoundUp(
|
||||
sqrtPrice: BN,
|
||||
currLiquidity: BN,
|
||||
amount: u64,
|
||||
amount: BN,
|
||||
amountSpecifiedIsInput: boolean
|
||||
) {
|
||||
if (amount.eq(ZERO)) {
|
||||
|
@ -125,7 +124,7 @@ function getNextSqrtPriceFromARoundUp(
|
|||
function getNextSqrtPriceFromBRoundDown(
|
||||
sqrtPrice: BN,
|
||||
currLiquidity: BN,
|
||||
amount: u64,
|
||||
amount: BN,
|
||||
amountSpecifiedIsInput: boolean
|
||||
) {
|
||||
let amountX64 = amount.shln(64);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Address, BN } from "@coral-xyz/anchor";
|
||||
import { Address } from "@coral-xyz/anchor";
|
||||
import { AddressUtil, MathUtil, Percentage } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import Decimal from "decimal.js";
|
||||
import { WhirlpoolData, WhirlpoolRewardInfoData } from "../../types/public";
|
||||
import { TOKEN_MINTS } from "../constants";
|
||||
|
@ -109,13 +109,13 @@ export class PoolUtil {
|
|||
// TODO: round up
|
||||
if (round_up) {
|
||||
return {
|
||||
tokenA: new u64(tokenA.ceil().toString()),
|
||||
tokenB: new u64(tokenB.ceil().toString()),
|
||||
tokenA: new BN(tokenA.ceil().toString()),
|
||||
tokenB: new BN(tokenB.ceil().toString()),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
tokenA: new u64(tokenA.floor().toString()),
|
||||
tokenB: new u64(tokenB.floor().toString()),
|
||||
tokenA: new BN(tokenA.floor().toString()),
|
||||
tokenB: new BN(tokenB.floor().toString()),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -188,8 +188,8 @@ export class PoolUtil {
|
|||
* @category Whirlpool Utils
|
||||
*/
|
||||
export type TokenAmounts = {
|
||||
tokenA: u64;
|
||||
tokenB: u64;
|
||||
tokenA: BN;
|
||||
tokenB: BN;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -197,8 +197,8 @@ export type TokenAmounts = {
|
|||
*/
|
||||
export function toTokenAmount(a: number, b: number): TokenAmounts {
|
||||
return {
|
||||
tokenA: new u64(a.toString()),
|
||||
tokenB: new u64(b.toString()),
|
||||
tokenA: new BN(a.toString()),
|
||||
tokenB: new BN(b.toString()),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -229,7 +229,7 @@ function sortByQuotePriority(mintLeft: PublicKey, mintRight: PublicKey): number
|
|||
}
|
||||
|
||||
// Convert this function based on Delta A = Delta L * (1/sqrt(lower) - 1/sqrt(upper))
|
||||
function estLiquidityForTokenA(sqrtPrice1: BN, sqrtPrice2: BN, tokenAmount: u64) {
|
||||
function estLiquidityForTokenA(sqrtPrice1: BN, sqrtPrice2: BN, tokenAmount: BN) {
|
||||
const lowerSqrtPriceX64 = BN.min(sqrtPrice1, sqrtPrice2);
|
||||
const upperSqrtPriceX64 = BN.max(sqrtPrice1, sqrtPrice2);
|
||||
|
||||
|
@ -240,7 +240,7 @@ function estLiquidityForTokenA(sqrtPrice1: BN, sqrtPrice2: BN, tokenAmount: u64)
|
|||
}
|
||||
|
||||
// Convert this function based on Delta B = Delta L * (sqrt_price(upper) - sqrt_price(lower))
|
||||
function estLiquidityForTokenB(sqrtPrice1: BN, sqrtPrice2: BN, tokenAmount: u64) {
|
||||
function estLiquidityForTokenB(sqrtPrice1: BN, sqrtPrice2: BN, tokenAmount: BN) {
|
||||
const lowerSqrtPriceX64 = BN.min(sqrtPrice1, sqrtPrice2);
|
||||
const upperSqrtPriceX64 = BN.max(sqrtPrice1, sqrtPrice2);
|
||||
|
||||
|
|
|
@ -1,73 +1,6 @@
|
|||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import {
|
||||
AccountLayout,
|
||||
ASSOCIATED_TOKEN_PROGRAM_ID,
|
||||
NATIVE_MINT,
|
||||
Token,
|
||||
TOKEN_PROGRAM_ID,
|
||||
} from "@solana/spl-token";
|
||||
import { Keypair, PublicKey, SystemProgram } from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import { NATIVE_MINT } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
|
||||
export function isNativeMint(mint: PublicKey) {
|
||||
return mint.equals(NATIVE_MINT);
|
||||
}
|
||||
|
||||
// TODO: Update spl-token so we get this method
|
||||
export function getAssociatedTokenAddressSync(
|
||||
mint: string,
|
||||
owner: string,
|
||||
programId = TOKEN_PROGRAM_ID,
|
||||
associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID
|
||||
): PublicKey {
|
||||
const [address] = PublicKey.findProgramAddressSync(
|
||||
[new PublicKey(owner).toBuffer(), programId.toBuffer(), new PublicKey(mint).toBuffer()],
|
||||
associatedTokenProgramId
|
||||
);
|
||||
|
||||
return address;
|
||||
}
|
||||
|
||||
// TODO: This is a temp fn to help add payer / differing destination params to the original method
|
||||
// Deprecate this as soon as we move to sync-native. Can consider moving to common-sdk for posterity.
|
||||
export function createWSOLAccountInstructions(
|
||||
owner: PublicKey,
|
||||
amountToWrap: BN,
|
||||
accountExemption: number,
|
||||
payer?: PublicKey,
|
||||
unwrapDestination?: PublicKey
|
||||
): { address: PublicKey } & Instruction {
|
||||
const payerKey = payer ?? owner;
|
||||
const unwrapDestinationKey = unwrapDestination ?? payer ?? owner;
|
||||
const tempAccount = new Keypair();
|
||||
|
||||
const createIx = SystemProgram.createAccount({
|
||||
fromPubkey: payerKey,
|
||||
newAccountPubkey: tempAccount.publicKey,
|
||||
lamports: amountToWrap.toNumber() + accountExemption,
|
||||
space: AccountLayout.span,
|
||||
programId: TOKEN_PROGRAM_ID,
|
||||
});
|
||||
|
||||
const initIx = Token.createInitAccountInstruction(
|
||||
TOKEN_PROGRAM_ID,
|
||||
NATIVE_MINT,
|
||||
tempAccount.publicKey,
|
||||
owner
|
||||
);
|
||||
|
||||
const closeIx = Token.createCloseAccountInstruction(
|
||||
TOKEN_PROGRAM_ID,
|
||||
tempAccount.publicKey,
|
||||
unwrapDestinationKey,
|
||||
owner,
|
||||
[]
|
||||
);
|
||||
|
||||
return {
|
||||
address: tempAccount.publicKey,
|
||||
instructions: [createIx, initIx],
|
||||
cleanupInstructions: [closeIx],
|
||||
signers: [tempAccount],
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
import {
|
||||
Instruction,
|
||||
resolveOrCreateATAs,
|
||||
TokenUtil,
|
||||
TransactionBuilder,
|
||||
ZERO,
|
||||
resolveOrCreateATAs,
|
||||
} from "@orca-so/common-sdk";
|
||||
import { NATIVE_MINT } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { PoolUtil, WhirlpoolContext } from "..";
|
||||
import { WhirlpoolData } from "../types/public";
|
||||
import { createWSOLAccountInstructions } from "./spl-token-utils";
|
||||
import { convertListToMap } from "./txn-utils";
|
||||
|
||||
export enum TokenMintTypes {
|
||||
|
@ -168,7 +167,7 @@ export function addNativeMintHandlingIx(
|
|||
destinationWallet: PublicKey,
|
||||
accountExemption: number
|
||||
) {
|
||||
let { address: wSOLAta, ...resolveWSolIx } = createWSOLAccountInstructions(
|
||||
let { address: wSOLAta, ...resolveWSolIx } = TokenUtil.createWrappedNativeAccountInstruction(
|
||||
destinationWallet,
|
||||
ZERO,
|
||||
accountExemption
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { PDA, Percentage } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import * as assert from "assert";
|
||||
import BN from "bn.js";
|
||||
import {
|
||||
InitPoolParams,
|
||||
POSITION_BUNDLE_SIZE,
|
||||
|
@ -17,7 +17,7 @@ import {
|
|||
TickSpacing,
|
||||
approveToken, createAssociatedTokenAccount,
|
||||
systemTransferTx,
|
||||
transfer
|
||||
transferToken
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { initTestPool, initializePositionBundle, openBundledPosition, openPosition } from "../utils/init-utils";
|
||||
|
@ -204,7 +204,7 @@ describe("close_bundled_position", () => {
|
|||
tickUpperIndex,
|
||||
tickCurrentIndex: pool.getData().tickCurrentIndex,
|
||||
inputTokenMint: poolInitInfo.tokenMintB,
|
||||
inputTokenAmount: new u64(1_000_000),
|
||||
inputTokenAmount: new BN(1_000_000),
|
||||
});
|
||||
|
||||
await mintTokensToTestAccount(
|
||||
|
@ -555,7 +555,7 @@ describe("close_bundled_position", () => {
|
|||
ctx.wallet.publicKey,
|
||||
);
|
||||
|
||||
await transfer(
|
||||
await transferToken(
|
||||
provider,
|
||||
positionBundleInfo.positionBundleTokenAccount,
|
||||
funderATA,
|
||||
|
@ -563,7 +563,7 @@ describe("close_bundled_position", () => {
|
|||
);
|
||||
|
||||
const tokenInfo = await fetcher.getTokenInfo(funderATA, true);
|
||||
assert.ok(tokenInfo?.amount.eqn(1));
|
||||
assert.ok(tokenInfo?.amount === 1n);
|
||||
|
||||
const tx = toTx(
|
||||
ctx,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { AuthorityType } from "@solana/spl-token";
|
||||
import * as assert from "assert";
|
||||
import { toTx, WhirlpoolIx } from "../../src";
|
||||
import { WhirlpoolContext } from "../../src/context";
|
||||
|
@ -8,7 +9,7 @@ import {
|
|||
createTokenAccount,
|
||||
setAuthority,
|
||||
TickSpacing,
|
||||
transfer,
|
||||
transferToken,
|
||||
ZERO_BN
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
|
@ -67,7 +68,7 @@ describe("close_position", () => {
|
|||
ctx.provider,
|
||||
params.positionTokenAccount,
|
||||
delegate.publicKey,
|
||||
"CloseAccount",
|
||||
AuthorityType.CloseAccount,
|
||||
owner
|
||||
);
|
||||
|
||||
|
@ -129,7 +130,7 @@ describe("close_position", () => {
|
|||
newOwner.publicKey
|
||||
);
|
||||
|
||||
await transfer(provider, position.tokenAccount, newOwnerPositionTokenAccount, 1);
|
||||
await transferToken(provider, position.tokenAccount, newOwnerPositionTokenAccount, 1);
|
||||
|
||||
await toTx(
|
||||
ctx,
|
||||
|
@ -212,7 +213,7 @@ describe("close_position", () => {
|
|||
ctx.provider,
|
||||
params.positionTokenAccount,
|
||||
delegate.publicKey,
|
||||
"CloseAccount",
|
||||
AuthorityType.CloseAccount,
|
||||
owner
|
||||
);
|
||||
|
||||
|
@ -309,7 +310,7 @@ describe("close_position", () => {
|
|||
ctx.provider,
|
||||
params.positionTokenAccount,
|
||||
delegate.publicKey,
|
||||
"CloseAccount",
|
||||
AuthorityType.CloseAccount,
|
||||
owner
|
||||
);
|
||||
|
||||
|
@ -350,7 +351,7 @@ describe("close_position", () => {
|
|||
ctx.provider,
|
||||
params.positionTokenAccount,
|
||||
delegate.publicKey,
|
||||
"CloseAccount",
|
||||
AuthorityType.CloseAccount,
|
||||
owner
|
||||
);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { BN } from "@coral-xyz/anchor";
|
||||
import { MathUtil } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import * as assert from "assert";
|
||||
import Decimal from "decimal.js";
|
||||
import {
|
||||
|
@ -19,7 +19,7 @@ import {
|
|||
createTokenAccount,
|
||||
getTokenBalance,
|
||||
TickSpacing,
|
||||
transfer,
|
||||
transferToken,
|
||||
ZERO_BN
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
|
@ -69,7 +69,7 @@ describe("collect_fees", () => {
|
|||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(200_000),
|
||||
amount: new BN(200_000),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(4)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -91,7 +91,7 @@ describe("collect_fees", () => {
|
|||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(200_000),
|
||||
amount: new BN(200_000),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(5)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -123,8 +123,8 @@ describe("collect_fees", () => {
|
|||
positions[0].publicKey,
|
||||
true
|
||||
)) as PositionData;
|
||||
assert.ok(positionBeforeCollect.feeOwedA.eq(new u64(581)));
|
||||
assert.ok(positionBeforeCollect.feeOwedB.eq(new u64(581)));
|
||||
assert.ok(positionBeforeCollect.feeOwedA.eq(new BN(581)));
|
||||
assert.ok(positionBeforeCollect.feeOwedB.eq(new BN(581)));
|
||||
|
||||
const feeAccountA = await createTokenAccount(provider, tokenMintA, provider.wallet.publicKey);
|
||||
const feeAccountB = await createTokenAccount(provider, tokenMintB, provider.wallet.publicKey);
|
||||
|
@ -272,7 +272,7 @@ describe("collect_fees", () => {
|
|||
newOwner.publicKey
|
||||
);
|
||||
|
||||
await transfer(provider, position.tokenAccount, newOwnerPositionTokenAccount, 1);
|
||||
await transferToken(provider, position.tokenAccount, newOwnerPositionTokenAccount, 1);
|
||||
|
||||
await toTx(
|
||||
ctx,
|
||||
|
@ -368,7 +368,7 @@ describe("collect_fees", () => {
|
|||
/0x7d3/ // ConstraintRaw
|
||||
);
|
||||
|
||||
await transfer(provider, positions[0].tokenAccount, positionTokenAccount2, 1);
|
||||
await transferToken(provider, positions[0].tokenAccount, positionTokenAccount2, 1);
|
||||
|
||||
await assert.rejects(
|
||||
toTx(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { BN } from "@coral-xyz/anchor";
|
||||
import { MathUtil } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import * as assert from "assert";
|
||||
import Decimal from "decimal.js";
|
||||
import { PDAUtil, toTx, WhirlpoolContext, WhirlpoolData, WhirlpoolIx } from "../../src";
|
||||
|
@ -65,7 +65,7 @@ describe("collect_protocol_fees", () => {
|
|||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(200_000),
|
||||
amount: new BN(200_000),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(4)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -87,7 +87,7 @@ describe("collect_protocol_fees", () => {
|
|||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(200_000),
|
||||
amount: new BN(200_000),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(5)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -106,8 +106,8 @@ describe("collect_protocol_fees", () => {
|
|||
).buildAndExecute();
|
||||
|
||||
const poolAfter = (await fetcher.getPool(whirlpoolPda.publicKey, true)) as WhirlpoolData;
|
||||
assert.ok(poolAfter?.protocolFeeOwedA.eq(new u64(150)));
|
||||
assert.ok(poolAfter?.protocolFeeOwedB.eq(new u64(150)));
|
||||
assert.ok(poolAfter?.protocolFeeOwedA.eq(new BN(150)));
|
||||
assert.ok(poolAfter?.protocolFeeOwedB.eq(new BN(150)));
|
||||
|
||||
const destA = await createTokenAccount(provider, tokenMintA, provider.wallet.publicKey);
|
||||
const destB = await createTokenAccount(provider, tokenMintB, provider.wallet.publicKey);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { BN } from "@coral-xyz/anchor";
|
||||
import { MathUtil } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import * as assert from "assert";
|
||||
import Decimal from "decimal.js";
|
||||
import {
|
||||
|
@ -17,7 +17,7 @@ import {
|
|||
getTokenBalance,
|
||||
sleep,
|
||||
TickSpacing,
|
||||
transfer,
|
||||
transferToken,
|
||||
ZERO_BN
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
|
@ -50,15 +50,15 @@ describe("collect_reward", () => {
|
|||
rewards: [
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
@ -143,7 +143,7 @@ describe("collect_reward", () => {
|
|||
rewards: [
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(2)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
@ -202,7 +202,7 @@ describe("collect_reward", () => {
|
|||
rewards: [
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(2)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
@ -227,7 +227,7 @@ describe("collect_reward", () => {
|
|||
positions[0].mintKeypair.publicKey,
|
||||
delegate.publicKey
|
||||
);
|
||||
await transfer(provider, positions[0].tokenAccount, delegatePositionAccount, 1);
|
||||
await transferToken(provider, positions[0].tokenAccount, delegatePositionAccount, 1);
|
||||
|
||||
await toTx(
|
||||
ctx,
|
||||
|
@ -266,7 +266,7 @@ describe("collect_reward", () => {
|
|||
rewards: [
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(2)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
@ -360,7 +360,7 @@ describe("collect_reward", () => {
|
|||
{ tickLowerIndex: -1280, tickUpperIndex: 1280, liquidityAmount: new anchor.BN(1_000_000) },
|
||||
],
|
||||
rewards: [
|
||||
{ emissionsPerSecondX64: MathUtil.toX64(new Decimal(2)), vaultAmount: new u64(1_000_000) },
|
||||
{ emissionsPerSecondX64: MathUtil.toX64(new Decimal(2)), vaultAmount: new BN(1_000_000) },
|
||||
],
|
||||
});
|
||||
const { positions, rewards } = fixture.getInfos();
|
||||
|
@ -401,7 +401,7 @@ describe("collect_reward", () => {
|
|||
{ tickLowerIndex: -1280, tickUpperIndex: 1280, liquidityAmount: new anchor.BN(1_000_000) },
|
||||
],
|
||||
rewards: [
|
||||
{ emissionsPerSecondX64: MathUtil.toX64(new Decimal(2)), vaultAmount: new u64(1_000_000) },
|
||||
{ emissionsPerSecondX64: MathUtil.toX64(new Decimal(2)), vaultAmount: new BN(1_000_000) },
|
||||
],
|
||||
});
|
||||
const {
|
||||
|
@ -423,7 +423,7 @@ describe("collect_reward", () => {
|
|||
positions[0].mintKeypair.publicKey,
|
||||
provider.wallet.publicKey
|
||||
);
|
||||
await transfer(provider, positions[0].tokenAccount, otherPositionAcount, 1);
|
||||
await transferToken(provider, positions[0].tokenAccount, otherPositionAcount, 1);
|
||||
await assert.rejects(
|
||||
toTx(
|
||||
ctx,
|
||||
|
@ -449,7 +449,7 @@ describe("collect_reward", () => {
|
|||
{ tickLowerIndex: -1280, tickUpperIndex: 1280, liquidityAmount: new anchor.BN(1_000_000) },
|
||||
],
|
||||
rewards: [
|
||||
{ emissionsPerSecondX64: MathUtil.toX64(new Decimal(2)), vaultAmount: new u64(1_000_000) },
|
||||
{ emissionsPerSecondX64: MathUtil.toX64(new Decimal(2)), vaultAmount: new BN(1_000_000) },
|
||||
],
|
||||
});
|
||||
const {
|
||||
|
@ -493,7 +493,7 @@ describe("collect_reward", () => {
|
|||
{ tickLowerIndex: -1280, tickUpperIndex: 1280, liquidityAmount: new anchor.BN(1_000_000) },
|
||||
],
|
||||
rewards: [
|
||||
{ emissionsPerSecondX64: MathUtil.toX64(new Decimal(2)), vaultAmount: new u64(1_000_000) },
|
||||
{ emissionsPerSecondX64: MathUtil.toX64(new Decimal(2)), vaultAmount: new BN(1_000_000) },
|
||||
],
|
||||
});
|
||||
const {
|
||||
|
@ -538,7 +538,7 @@ describe("collect_reward", () => {
|
|||
{ tickLowerIndex: -1280, tickUpperIndex: 1280, liquidityAmount: new anchor.BN(1_000_000) },
|
||||
],
|
||||
rewards: [
|
||||
{ emissionsPerSecondX64: MathUtil.toX64(new Decimal(2)), vaultAmount: new u64(1_000_000) },
|
||||
{ emissionsPerSecondX64: MathUtil.toX64(new Decimal(2)), vaultAmount: new BN(1_000_000) },
|
||||
],
|
||||
});
|
||||
const {
|
||||
|
@ -584,7 +584,7 @@ describe("collect_reward", () => {
|
|||
{ tickLowerIndex: -1280, tickUpperIndex: 1280, liquidityAmount: new anchor.BN(1_000_000) },
|
||||
],
|
||||
rewards: [
|
||||
{ emissionsPerSecondX64: MathUtil.toX64(new Decimal(2)), vaultAmount: new u64(1_000_000) },
|
||||
{ emissionsPerSecondX64: MathUtil.toX64(new Decimal(2)), vaultAmount: new BN(1_000_000) },
|
||||
],
|
||||
});
|
||||
const {
|
||||
|
@ -628,7 +628,7 @@ describe("collect_reward", () => {
|
|||
{ tickLowerIndex: -1280, tickUpperIndex: 1280, liquidityAmount: new anchor.BN(1_000_000) },
|
||||
],
|
||||
rewards: [
|
||||
{ emissionsPerSecondX64: MathUtil.toX64(new Decimal(2)), vaultAmount: new u64(1_000_000) },
|
||||
{ emissionsPerSecondX64: MathUtil.toX64(new Decimal(2)), vaultAmount: new BN(1_000_000) },
|
||||
],
|
||||
});
|
||||
const {
|
||||
|
@ -670,7 +670,7 @@ describe("collect_reward", () => {
|
|||
{ tickLowerIndex: -1280, tickUpperIndex: 1280, liquidityAmount: new anchor.BN(1_000_000) },
|
||||
],
|
||||
rewards: [
|
||||
{ emissionsPerSecondX64: MathUtil.toX64(new Decimal(2)), vaultAmount: new u64(1_000_000) },
|
||||
{ emissionsPerSecondX64: MathUtil.toX64(new Decimal(2)), vaultAmount: new BN(1_000_000) },
|
||||
],
|
||||
});
|
||||
const {
|
||||
|
@ -712,7 +712,7 @@ describe("collect_reward", () => {
|
|||
{ tickLowerIndex: -1280, tickUpperIndex: 1280, liquidityAmount: new anchor.BN(1_000_000) },
|
||||
],
|
||||
rewards: [
|
||||
{ emissionsPerSecondX64: MathUtil.toX64(new Decimal(2)), vaultAmount: new u64(1_000_000) },
|
||||
{ emissionsPerSecondX64: MathUtil.toX64(new Decimal(2)), vaultAmount: new BN(1_000_000) },
|
||||
],
|
||||
});
|
||||
const {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { MathUtil, Percentage } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import * as assert from "assert";
|
||||
import { BN } from "bn.js";
|
||||
import Decimal from "decimal.js";
|
||||
import {
|
||||
PositionData,
|
||||
|
@ -21,7 +21,7 @@ import {
|
|||
createMint,
|
||||
createTokenAccount,
|
||||
sleep,
|
||||
transfer
|
||||
transferToken
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { WhirlpoolTestFixture } from "../utils/fixture";
|
||||
|
@ -176,8 +176,8 @@ describe("decrease_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount: removeAmount,
|
||||
tokenMinA: new u64(0),
|
||||
tokenMinB: new u64(0),
|
||||
tokenMinA: new BN(0),
|
||||
tokenMinB: new BN(0),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: delegate.publicKey,
|
||||
position: position.publicKey,
|
||||
|
@ -217,8 +217,8 @@ describe("decrease_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount: removeAmount,
|
||||
tokenMinA: new u64(0),
|
||||
tokenMinB: new u64(0),
|
||||
tokenMinA: new BN(0),
|
||||
tokenMinB: new BN(0),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: position.publicKey,
|
||||
|
@ -251,14 +251,14 @@ describe("decrease_liquidity", () => {
|
|||
position.mintKeypair.publicKey,
|
||||
newOwner.publicKey
|
||||
);
|
||||
await transfer(provider, position.tokenAccount, newOwnerPositionTokenAccount, 1);
|
||||
await transferToken(provider, position.tokenAccount, newOwnerPositionTokenAccount, 1);
|
||||
|
||||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount: removeAmount,
|
||||
tokenMinA: new u64(0),
|
||||
tokenMinB: new u64(0),
|
||||
tokenMinA: new BN(0),
|
||||
tokenMinB: new BN(0),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: newOwner.publicKey,
|
||||
position: position.publicKey,
|
||||
|
@ -291,8 +291,8 @@ describe("decrease_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount: new anchor.BN(0),
|
||||
tokenMinA: new u64(0),
|
||||
tokenMinB: new u64(0),
|
||||
tokenMinA: new BN(0),
|
||||
tokenMinB: new BN(0),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: position.publicKey,
|
||||
|
@ -324,8 +324,8 @@ describe("decrease_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount: new anchor.BN(1_000),
|
||||
tokenMinA: new u64(0),
|
||||
tokenMinB: new u64(0),
|
||||
tokenMinA: new BN(0),
|
||||
tokenMinB: new BN(0),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: position.publicKey,
|
||||
|
@ -358,8 +358,8 @@ describe("decrease_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMinA: new u64(1_000_000),
|
||||
tokenMinB: new u64(0),
|
||||
tokenMinA: new BN(1_000_000),
|
||||
tokenMinB: new BN(0),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: position.publicKey,
|
||||
|
@ -391,8 +391,8 @@ describe("decrease_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMinA: new u64(0),
|
||||
tokenMinB: new u64(1_000_000),
|
||||
tokenMinA: new BN(0),
|
||||
tokenMinB: new BN(1_000_000),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: position.publicKey,
|
||||
|
@ -432,8 +432,8 @@ describe("decrease_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMinA: new u64(0),
|
||||
tokenMinB: new u64(0),
|
||||
tokenMinA: new BN(0),
|
||||
tokenMinB: new BN(0),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: position.publicKey,
|
||||
|
@ -450,15 +450,15 @@ describe("decrease_liquidity", () => {
|
|||
);
|
||||
|
||||
// Send position token to other position token account
|
||||
await transfer(provider, position.tokenAccount, newPositionTokenAccount, 1);
|
||||
await transferToken(provider, position.tokenAccount, newPositionTokenAccount, 1);
|
||||
|
||||
await assert.rejects(
|
||||
toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMinA: new u64(0),
|
||||
tokenMinB: new u64(0),
|
||||
tokenMinA: new BN(0),
|
||||
tokenMinB: new BN(0),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: position.publicKey,
|
||||
|
@ -493,8 +493,8 @@ describe("decrease_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMinA: new u64(0),
|
||||
tokenMinB: new u64(0),
|
||||
tokenMinA: new BN(0),
|
||||
tokenMinB: new BN(0),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: position.publicKey,
|
||||
|
@ -532,8 +532,8 @@ describe("decrease_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMinA: new u64(0),
|
||||
tokenMinB: new u64(0),
|
||||
tokenMinA: new BN(0),
|
||||
tokenMinB: new BN(0),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: positionPda.publicKey,
|
||||
|
@ -569,8 +569,8 @@ describe("decrease_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMinA: new u64(0),
|
||||
tokenMinB: new u64(0),
|
||||
tokenMinA: new BN(0),
|
||||
tokenMinB: new BN(0),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: position.publicKey,
|
||||
|
@ -591,8 +591,8 @@ describe("decrease_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMinA: new u64(0),
|
||||
tokenMinB: new u64(0),
|
||||
tokenMinA: new BN(0),
|
||||
tokenMinB: new BN(0),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: position.publicKey,
|
||||
|
@ -627,8 +627,8 @@ describe("decrease_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMinA: new u64(0),
|
||||
tokenMinB: new u64(0),
|
||||
tokenMinA: new BN(0),
|
||||
tokenMinB: new BN(0),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: position.publicKey,
|
||||
|
@ -649,8 +649,8 @@ describe("decrease_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMinA: new u64(0),
|
||||
tokenMinB: new u64(0),
|
||||
tokenMinA: new BN(0),
|
||||
tokenMinB: new BN(0),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: position.publicKey,
|
||||
|
@ -687,8 +687,8 @@ describe("decrease_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMinA: new u64(0),
|
||||
tokenMinB: new u64(0),
|
||||
tokenMinA: new BN(0),
|
||||
tokenMinB: new BN(0),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: delegate.publicKey,
|
||||
position: position.publicKey,
|
||||
|
@ -728,8 +728,8 @@ describe("decrease_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMinA: new u64(0),
|
||||
tokenMinB: new u64(0),
|
||||
tokenMinA: new BN(0),
|
||||
tokenMinB: new BN(0),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: delegate.publicKey,
|
||||
position: position.publicKey,
|
||||
|
@ -769,8 +769,8 @@ describe("decrease_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMinA: new u64(0),
|
||||
tokenMinB: new u64(167_000),
|
||||
tokenMinA: new BN(0),
|
||||
tokenMinB: new BN(167_000),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: delegate.publicKey,
|
||||
position: position.publicKey,
|
||||
|
@ -811,8 +811,8 @@ describe("decrease_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMinA: new u64(0),
|
||||
tokenMinB: new u64(0),
|
||||
tokenMinA: new BN(0),
|
||||
tokenMinB: new BN(0),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: position.publicKey,
|
||||
|
@ -855,8 +855,8 @@ describe("decrease_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMinA: new u64(0),
|
||||
tokenMinB: new u64(0),
|
||||
tokenMinA: new BN(0),
|
||||
tokenMinB: new BN(0),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: position.publicKey,
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { PDA } from "@orca-so/common-sdk";
|
||||
import { ASSOCIATED_TOKEN_PROGRAM_ID, Token, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { ASSOCIATED_TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { Keypair } from "@solana/web3.js";
|
||||
import * as assert from "assert";
|
||||
import { InitPoolParams, POSITION_BUNDLE_SIZE, PositionBundleData, toTx, WhirlpoolIx } from "../../src";
|
||||
import { InitPoolParams, POSITION_BUNDLE_SIZE, PositionBundleData, WhirlpoolIx, toTx } from "../../src";
|
||||
import { WhirlpoolContext } from "../../src/context";
|
||||
import {
|
||||
approveToken,
|
||||
createAssociatedTokenAccount,
|
||||
ONE_SOL,
|
||||
systemTransferTx,
|
||||
TickSpacing,
|
||||
transfer
|
||||
approveToken,
|
||||
burnToken,
|
||||
createAssociatedTokenAccount,
|
||||
systemTransferTx,
|
||||
transferToken
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { initializePositionBundle, initializePositionBundleWithMetadata, initTestPool, openBundledPosition } from "../utils/init-utils";
|
||||
import { initTestPool, initializePositionBundle, initializePositionBundleWithMetadata, openBundledPosition } from "../utils/init-utils";
|
||||
|
||||
describe("delete_position_bundle", () => {
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
@ -352,7 +353,7 @@ describe("delete_position_bundle", () => {
|
|||
delegate.publicKey,
|
||||
ctx.wallet.publicKey
|
||||
);
|
||||
await transfer(
|
||||
await transferToken(
|
||||
provider,
|
||||
positionBundleInfo.positionBundleTokenAccount,
|
||||
delegateTokenAccount,
|
||||
|
@ -436,21 +437,7 @@ describe("delete_position_bundle", () => {
|
|||
ctx.wallet.publicKey,
|
||||
);
|
||||
|
||||
// burn NFT
|
||||
await toTx(ctx, {
|
||||
instructions: [
|
||||
Token.createBurnInstruction(
|
||||
TOKEN_PROGRAM_ID,
|
||||
positionBundleInfo.positionBundleMintKeypair.publicKey,
|
||||
positionBundleInfo.positionBundleTokenAccount,
|
||||
ctx.wallet.publicKey,
|
||||
[],
|
||||
1
|
||||
)
|
||||
],
|
||||
cleanupInstructions: [],
|
||||
signers: []
|
||||
}).buildAndExecute();
|
||||
await burnToken(ctx.provider, positionBundleInfo.positionBundleTokenAccount, positionBundleInfo.positionBundleMintKeypair.publicKey, 1);
|
||||
|
||||
const tokenAccount = await fetcher.getTokenInfo(positionBundleInfo.positionBundleTokenAccount);
|
||||
assert.equal(tokenAccount!.amount.toString(), "0");
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { MathUtil } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import * as assert from "assert";
|
||||
import { BN } from "bn.js";
|
||||
import Decimal from "decimal.js";
|
||||
import {
|
||||
GetPricesConfig, GetPricesThresholdConfig, PriceModule,
|
||||
|
@ -60,7 +60,7 @@ describe("get_pool_prices", () => {
|
|||
|
||||
function getDefaultThresholdConfig(): GetPricesThresholdConfig {
|
||||
return {
|
||||
amountOut: new u64(1_000_000),
|
||||
amountOut: new BN(1_000_000),
|
||||
priceImpactThreshold: 1.05,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { MathUtil, TransactionBuilder } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import * as assert from "assert";
|
||||
import { BN } from "bn.js";
|
||||
import Decimal from "decimal.js";
|
||||
import {
|
||||
PDAUtil,
|
||||
|
@ -26,7 +26,7 @@ import {
|
|||
createTokenAccount,
|
||||
getTokenBalance,
|
||||
sleep,
|
||||
transfer
|
||||
transferToken
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { WhirlpoolTestFixture } from "../utils/fixture";
|
||||
|
@ -394,7 +394,7 @@ describe("increase_liquidity", () => {
|
|||
const { positionPda, positionTokenAccount: positionTokenAccountAddress } = positionInfo.params;
|
||||
|
||||
const tokenAmount = {
|
||||
tokenA: new u64(0),
|
||||
tokenA: new BN(0),
|
||||
tokenB: MAX_U64,
|
||||
};
|
||||
const estLiquidityAmount = PoolUtil.estimateLiquidityFromTokenAmounts(
|
||||
|
@ -454,7 +454,7 @@ describe("increase_liquidity", () => {
|
|||
const { positionPda, positionTokenAccount: positionTokenAccountAddress } = positionInfo.params;
|
||||
|
||||
const tokenAmount = {
|
||||
tokenA: new u64(0),
|
||||
tokenA: new BN(0),
|
||||
tokenB: MAX_U64,
|
||||
};
|
||||
const estLiquidityAmount = PoolUtil.estimateLiquidityFromTokenAmounts(
|
||||
|
@ -501,8 +501,8 @@ describe("increase_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.increaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount: ZERO_BN,
|
||||
tokenMaxA: new u64(0),
|
||||
tokenMaxB: new u64(1_000_000),
|
||||
tokenMaxA: new BN(0),
|
||||
tokenMaxB: new BN(1_000_000),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: positionInitInfo.publicKey,
|
||||
|
@ -536,8 +536,8 @@ describe("increase_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.increaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMaxA: new u64(0),
|
||||
tokenMaxB: new u64(999_999_999),
|
||||
tokenMaxA: new BN(0),
|
||||
tokenMaxB: new BN(999_999_999),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: positionInitInfo.publicKey,
|
||||
|
@ -570,8 +570,8 @@ describe("increase_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.increaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMaxA: new u64(999_999_999),
|
||||
tokenMaxB: new u64(0),
|
||||
tokenMaxA: new BN(999_999_999),
|
||||
tokenMaxB: new BN(0),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: positionInitInfo.publicKey,
|
||||
|
@ -611,8 +611,8 @@ describe("increase_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.increaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMaxA: new u64(0),
|
||||
tokenMaxB: new u64(1_000_000),
|
||||
tokenMaxA: new BN(0),
|
||||
tokenMaxB: new BN(1_000_000),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: positionInitInfo.publicKey,
|
||||
|
@ -629,15 +629,15 @@ describe("increase_liquidity", () => {
|
|||
);
|
||||
|
||||
// Send position token to other position token account
|
||||
await transfer(provider, positionInitInfo.tokenAccount, newPositionTokenAccount, 1);
|
||||
await transferToken(provider, positionInitInfo.tokenAccount, newPositionTokenAccount, 1);
|
||||
|
||||
await assert.rejects(
|
||||
toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.increaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMaxA: new u64(0),
|
||||
tokenMaxB: new u64(1_000_000),
|
||||
tokenMaxA: new BN(0),
|
||||
tokenMaxB: new BN(1_000_000),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: positionInitInfo.publicKey,
|
||||
|
@ -673,8 +673,8 @@ describe("increase_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.increaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMaxA: new u64(0),
|
||||
tokenMaxB: new u64(1_000_000),
|
||||
tokenMaxA: new BN(0),
|
||||
tokenMaxB: new BN(1_000_000),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: positionInitInfo.publicKey,
|
||||
|
@ -722,8 +722,8 @@ describe("increase_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.increaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMaxA: new u64(0),
|
||||
tokenMaxB: new u64(1_000_000),
|
||||
tokenMaxA: new BN(0),
|
||||
tokenMaxB: new BN(1_000_000),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: positionPda.publicKey,
|
||||
|
@ -758,8 +758,8 @@ describe("increase_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.increaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMaxA: new u64(0),
|
||||
tokenMaxB: new u64(1_000_000),
|
||||
tokenMaxA: new BN(0),
|
||||
tokenMaxB: new BN(1_000_000),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: positionInitInfo.publicKey,
|
||||
|
@ -780,8 +780,8 @@ describe("increase_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.increaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMaxA: new u64(0),
|
||||
tokenMaxB: new u64(1_000_000),
|
||||
tokenMaxA: new BN(0),
|
||||
tokenMaxB: new BN(1_000_000),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: positionInitInfo.publicKey,
|
||||
|
@ -816,8 +816,8 @@ describe("increase_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.increaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMaxA: new u64(0),
|
||||
tokenMaxB: new u64(1_000_000),
|
||||
tokenMaxA: new BN(0),
|
||||
tokenMaxB: new BN(1_000_000),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: positionInitInfo.publicKey,
|
||||
|
@ -838,8 +838,8 @@ describe("increase_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.increaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMaxA: new u64(0),
|
||||
tokenMaxB: new u64(1_000_000),
|
||||
tokenMaxA: new BN(0),
|
||||
tokenMaxB: new BN(1_000_000),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: positionInitInfo.publicKey,
|
||||
|
@ -877,8 +877,8 @@ describe("increase_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.increaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMaxA: new u64(0),
|
||||
tokenMaxB: new u64(167_000),
|
||||
tokenMaxA: new BN(0),
|
||||
tokenMaxB: new BN(167_000),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: delegate.publicKey,
|
||||
position: positionInitInfo.publicKey,
|
||||
|
@ -919,8 +919,8 @@ describe("increase_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.increaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMaxA: new u64(0),
|
||||
tokenMaxB: new u64(167_000),
|
||||
tokenMaxA: new BN(0),
|
||||
tokenMaxB: new BN(167_000),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: delegate.publicKey,
|
||||
position: positionInitInfo.publicKey,
|
||||
|
@ -961,8 +961,8 @@ describe("increase_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.increaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMaxA: new u64(0),
|
||||
tokenMaxB: new u64(167_000),
|
||||
tokenMaxA: new BN(0),
|
||||
tokenMaxB: new BN(167_000),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: delegate.publicKey,
|
||||
position: positionInitInfo.publicKey,
|
||||
|
@ -999,8 +999,8 @@ describe("increase_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.increaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMaxA: new u64(0),
|
||||
tokenMaxB: new u64(167_000),
|
||||
tokenMaxA: new BN(0),
|
||||
tokenMaxB: new BN(167_000),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: delegate.publicKey,
|
||||
position: positionInitInfo.publicKey,
|
||||
|
@ -1043,8 +1043,8 @@ describe("increase_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.increaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMaxA: new u64(0),
|
||||
tokenMaxB: new u64(167_000),
|
||||
tokenMaxA: new BN(0),
|
||||
tokenMaxB: new BN(167_000),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: positionInitInfo.publicKey,
|
||||
|
@ -1087,8 +1087,8 @@ describe("increase_liquidity", () => {
|
|||
ctx,
|
||||
WhirlpoolIx.increaseLiquidityIx(ctx.program, {
|
||||
liquidityAmount,
|
||||
tokenMaxA: new u64(0),
|
||||
tokenMaxB: new u64(167_000),
|
||||
tokenMaxA: new BN(0),
|
||||
tokenMaxB: new BN(167_000),
|
||||
whirlpool: whirlpoolPda.publicKey,
|
||||
positionAuthority: provider.wallet.publicKey,
|
||||
position: positionInitInfo.publicKey,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { deriveATA } from "@orca-so/common-sdk";
|
||||
import { AccountInfo, ASSOCIATED_TOKEN_PROGRAM_ID, MintInfo, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { Account, ASSOCIATED_TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync, Mint, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { Keypair, LAMPORTS_PER_SOL, PublicKey, SystemProgram } from "@solana/web3.js";
|
||||
import * as assert from "assert";
|
||||
import {
|
||||
|
@ -12,7 +11,7 @@ import {
|
|||
} from "../../src";
|
||||
import {
|
||||
createMintInstructions,
|
||||
mintToByAuthority
|
||||
mintToDestination
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { initializePositionBundle } from "../utils/init-utils";
|
||||
|
@ -28,7 +27,7 @@ describe("initialize_position_bundle", () => {
|
|||
async function createInitializePositionBundleTx(ctx: WhirlpoolContext, overwrite: any, mintKeypair?: Keypair) {
|
||||
const positionBundleMintKeypair = mintKeypair ?? Keypair.generate();
|
||||
const positionBundlePda = PDAUtil.getPositionBundle(ctx.program.programId, positionBundleMintKeypair.publicKey);
|
||||
const positionBundleTokenAccount = await deriveATA(ctx.wallet.publicKey, positionBundleMintKeypair.publicKey);
|
||||
const positionBundleTokenAccount = getAssociatedTokenAddressSync(positionBundleMintKeypair.publicKey, ctx.wallet.publicKey);
|
||||
|
||||
const defaultAccounts = {
|
||||
positionBundle: positionBundlePda.publicKey,
|
||||
|
@ -58,10 +57,10 @@ describe("initialize_position_bundle", () => {
|
|||
|
||||
async function checkPositionBundleMint(positionBundleMintPubkey: PublicKey) {
|
||||
// verify position bundle Mint account
|
||||
const positionBundleMint = (await ctx.fetcher.getMintInfo(positionBundleMintPubkey, true)) as MintInfo;
|
||||
const positionBundleMint = (await ctx.fetcher.getMintInfo(positionBundleMintPubkey, true)) as Mint;
|
||||
// should have NFT characteristics
|
||||
assert.strictEqual(positionBundleMint.decimals, 0);
|
||||
assert.ok(positionBundleMint.supply.eqn(1));
|
||||
assert.ok(positionBundleMint.supply === 1n);
|
||||
// mint auth & freeze auth should be set to None
|
||||
assert.ok(positionBundleMint.mintAuthority === null);
|
||||
assert.ok(positionBundleMint.freezeAuthority === null);
|
||||
|
@ -69,8 +68,8 @@ describe("initialize_position_bundle", () => {
|
|||
|
||||
async function checkPositionBundleTokenAccount(positionBundleTokenAccountPubkey: PublicKey, owner: PublicKey, positionBundleMintPubkey: PublicKey) {
|
||||
// verify position bundle Token account
|
||||
const positionBundleTokenAccount = (await ctx.fetcher.getTokenInfo(positionBundleTokenAccountPubkey, true)) as AccountInfo;
|
||||
assert.ok(positionBundleTokenAccount.amount.eqn(1));
|
||||
const positionBundleTokenAccount = (await ctx.fetcher.getTokenInfo(positionBundleTokenAccountPubkey, true)) as Account;
|
||||
assert.ok(positionBundleTokenAccount.amount === 1n);
|
||||
assert.ok(positionBundleTokenAccount.mint.equals(positionBundleMintPubkey));
|
||||
assert.ok(positionBundleTokenAccount.owner.equals(owner));
|
||||
}
|
||||
|
@ -155,7 +154,7 @@ describe("initialize_position_bundle", () => {
|
|||
);
|
||||
|
||||
await assert.rejects(
|
||||
mintToByAuthority(
|
||||
mintToDestination(
|
||||
provider,
|
||||
positionBundleInfo.positionBundleMintKeypair.publicKey,
|
||||
positionBundleInfo.positionBundleTokenAccount,
|
||||
|
@ -204,7 +203,7 @@ describe("initialize_position_bundle", () => {
|
|||
it("should be failed: invalid ATA address", async () => {
|
||||
const tx = await createInitializePositionBundleTx(ctx, {
|
||||
// invalid parameter
|
||||
positionBundleTokenAccount: await deriveATA(ctx.wallet.publicKey, Keypair.generate().publicKey),
|
||||
positionBundleTokenAccount: getAssociatedTokenAddressSync(Keypair.generate().publicKey, ctx.wallet.publicKey),
|
||||
});
|
||||
|
||||
await assert.rejects(
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { Metadata } from "@metaplex-foundation/mpl-token-metadata";
|
||||
import { deriveATA, PDA } from "@orca-so/common-sdk";
|
||||
import { AccountInfo, ASSOCIATED_TOKEN_PROGRAM_ID, MintInfo, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { PDA } from "@orca-so/common-sdk";
|
||||
import {
|
||||
Account,
|
||||
ASSOCIATED_TOKEN_PROGRAM_ID,
|
||||
getAssociatedTokenAddressSync,
|
||||
Mint,
|
||||
TOKEN_PROGRAM_ID
|
||||
} from "@solana/spl-token";
|
||||
import { Keypair, LAMPORTS_PER_SOL, PublicKey, SystemProgram } from "@solana/web3.js";
|
||||
import * as assert from "assert";
|
||||
import {
|
||||
|
@ -11,11 +17,11 @@ import {
|
|||
PositionBundleData,
|
||||
toTx,
|
||||
WHIRLPOOL_NFT_UPDATE_AUTH,
|
||||
WhirlpoolContext
|
||||
WhirlpoolContext,
|
||||
} from "../../src";
|
||||
import {
|
||||
createMintInstructions,
|
||||
mintToByAuthority
|
||||
mintToDestination
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { initializePositionBundleWithMetadata } from "../utils/init-utils";
|
||||
|
@ -25,13 +31,24 @@ describe("initialize_position_bundle_with_metadata", () => {
|
|||
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
||||
async function createInitializePositionBundleWithMetadataTx(ctx: WhirlpoolContext, overwrite: any, mintKeypair?: Keypair) {
|
||||
async function createInitializePositionBundleWithMetadataTx(
|
||||
ctx: WhirlpoolContext,
|
||||
overwrite: any,
|
||||
mintKeypair?: Keypair
|
||||
) {
|
||||
const positionBundleMintKeypair = mintKeypair ?? Keypair.generate();
|
||||
const positionBundlePda = PDAUtil.getPositionBundle(ctx.program.programId, positionBundleMintKeypair.publicKey);
|
||||
const positionBundleMetadataPda = PDAUtil.getPositionBundleMetadata(positionBundleMintKeypair.publicKey);
|
||||
const positionBundleTokenAccount = await deriveATA(ctx.wallet.publicKey, positionBundleMintKeypair.publicKey);
|
||||
const positionBundlePda = PDAUtil.getPositionBundle(
|
||||
ctx.program.programId,
|
||||
positionBundleMintKeypair.publicKey
|
||||
);
|
||||
const positionBundleMetadataPda = PDAUtil.getPositionBundleMetadata(
|
||||
positionBundleMintKeypair.publicKey
|
||||
);
|
||||
const positionBundleTokenAccount = getAssociatedTokenAddressSync(
|
||||
positionBundleMintKeypair.publicKey,
|
||||
ctx.wallet.publicKey
|
||||
);
|
||||
|
||||
const defaultAccounts = {
|
||||
positionBundle: positionBundlePda.publicKey,
|
||||
|
@ -52,7 +69,7 @@ describe("initialize_position_bundle_with_metadata", () => {
|
|||
accounts: {
|
||||
...defaultAccounts,
|
||||
...overwrite,
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return toTx(ctx, {
|
||||
|
@ -64,26 +81,42 @@ describe("initialize_position_bundle_with_metadata", () => {
|
|||
|
||||
async function checkPositionBundleMint(positionBundleMintPubkey: PublicKey) {
|
||||
// verify position bundle Mint account
|
||||
const positionBundleMint = (await ctx.fetcher.getMintInfo(positionBundleMintPubkey, true)) as MintInfo;
|
||||
const positionBundleMint = (await ctx.fetcher.getMintInfo(
|
||||
positionBundleMintPubkey,
|
||||
true
|
||||
)) as Mint;
|
||||
// should have NFT characteristics
|
||||
assert.strictEqual(positionBundleMint.decimals, 0);
|
||||
assert.ok(positionBundleMint.supply.eqn(1));
|
||||
assert.ok(positionBundleMint.supply === 1n);
|
||||
// mint auth & freeze auth should be set to None
|
||||
assert.ok(positionBundleMint.mintAuthority === null);
|
||||
assert.ok(positionBundleMint.freezeAuthority === null);
|
||||
}
|
||||
|
||||
async function checkPositionBundleTokenAccount(positionBundleTokenAccountPubkey: PublicKey, owner: PublicKey, positionBundleMintPubkey: PublicKey) {
|
||||
async function checkPositionBundleTokenAccount(
|
||||
positionBundleTokenAccountPubkey: PublicKey,
|
||||
owner: PublicKey,
|
||||
positionBundleMintPubkey: PublicKey
|
||||
) {
|
||||
// verify position bundle Token account
|
||||
const positionBundleTokenAccount = (await ctx.fetcher.getTokenInfo(positionBundleTokenAccountPubkey, true)) as AccountInfo;
|
||||
assert.ok(positionBundleTokenAccount.amount.eqn(1));
|
||||
const positionBundleTokenAccount = (await ctx.fetcher.getTokenInfo(
|
||||
positionBundleTokenAccountPubkey,
|
||||
true
|
||||
)) as Account;
|
||||
assert.ok(positionBundleTokenAccount.amount === 1n);
|
||||
assert.ok(positionBundleTokenAccount.mint.equals(positionBundleMintPubkey));
|
||||
assert.ok(positionBundleTokenAccount.owner.equals(owner));
|
||||
}
|
||||
|
||||
async function checkPositionBundle(positionBundlePubkey: PublicKey, positionBundleMintPubkey: PublicKey) {
|
||||
async function checkPositionBundle(
|
||||
positionBundlePubkey: PublicKey,
|
||||
positionBundleMintPubkey: PublicKey
|
||||
) {
|
||||
// verify PositionBundle account
|
||||
const positionBundle = (await ctx.fetcher.getPositionBundle(positionBundlePubkey, true)) as PositionBundleData;
|
||||
const positionBundle = (await ctx.fetcher.getPositionBundle(
|
||||
positionBundlePubkey,
|
||||
true
|
||||
)) as PositionBundleData;
|
||||
assert.ok(positionBundle.positionBundleMint.equals(positionBundleMintPubkey));
|
||||
assert.strictEqual(positionBundle.positionBitmap.length * 8, POSITION_BUNDLE_SIZE);
|
||||
for (const bitmap of positionBundle.positionBitmap) {
|
||||
|
@ -97,25 +130,25 @@ describe("initialize_position_bundle_with_metadata", () => {
|
|||
const WPB_METADATA_URI = "https://arweave.net/A_Wo8dx2_3lSUwMIi7bdT_sqxi8soghRNAWXXiqXpgE";
|
||||
|
||||
const mintAddress = positionMint.toBase58();
|
||||
const nftName = WPB_METADATA_NAME_PREFIX
|
||||
+ " "
|
||||
+ mintAddress.slice(0, 4)
|
||||
+ "..."
|
||||
+ mintAddress.slice(-4);
|
||||
const nftName =
|
||||
WPB_METADATA_NAME_PREFIX + " " + mintAddress.slice(0, 4) + "..." + mintAddress.slice(-4);
|
||||
|
||||
assert.ok(metadataPda != null);
|
||||
const metadata = await Metadata.load(provider.connection, metadataPda.publicKey);
|
||||
assert.ok(metadata.data.mint === positionMint.toString());
|
||||
assert.ok(metadata.data.updateAuthority === WHIRLPOOL_NFT_UPDATE_AUTH.toBase58());
|
||||
assert.ok(metadata.data.isMutable);
|
||||
assert.strictEqual(metadata.data.data.name, nftName);
|
||||
assert.strictEqual(metadata.data.data.symbol, WPB_METADATA_SYMBOL);
|
||||
assert.strictEqual(metadata.data.data.uri, WPB_METADATA_URI);
|
||||
const metadata = await Metadata.fromAccountAddress(provider.connection, metadataPda.publicKey);
|
||||
assert.ok(metadata.mint.toBase58() === positionMint.toString());
|
||||
assert.ok(metadata.updateAuthority.toBase58() === WHIRLPOOL_NFT_UPDATE_AUTH.toBase58());
|
||||
assert.ok(metadata.isMutable);
|
||||
assert.strictEqual(metadata.data.name.replace(/\0/g, ''), nftName);
|
||||
assert.strictEqual(metadata.data.symbol.replace(/\0/g, ''), WPB_METADATA_SYMBOL);
|
||||
assert.strictEqual(metadata.data.uri.replace(/\0/g, ''), WPB_METADATA_URI);
|
||||
}
|
||||
|
||||
async function createOtherWallet(): Promise<Keypair> {
|
||||
const keypair = Keypair.generate();
|
||||
const signature = await provider.connection.requestAirdrop(keypair.publicKey, 100 * LAMPORTS_PER_SOL);
|
||||
const signature = await provider.connection.requestAirdrop(
|
||||
keypair.publicKey,
|
||||
100 * LAMPORTS_PER_SOL
|
||||
);
|
||||
await provider.connection.confirmTransaction(signature, "confirmed");
|
||||
return keypair;
|
||||
}
|
||||
|
@ -123,7 +156,7 @@ describe("initialize_position_bundle_with_metadata", () => {
|
|||
it("successfully initialize position bundle and verify initialized account contents", async () => {
|
||||
const positionBundleInfo = await initializePositionBundleWithMetadata(
|
||||
ctx,
|
||||
ctx.wallet.publicKey,
|
||||
ctx.wallet.publicKey
|
||||
// funder = ctx.wallet.publicKey
|
||||
);
|
||||
|
||||
|
@ -135,9 +168,16 @@ describe("initialize_position_bundle_with_metadata", () => {
|
|||
} = positionBundleInfo;
|
||||
|
||||
await checkPositionBundleMint(positionBundleMintKeypair.publicKey);
|
||||
await checkPositionBundleTokenAccount(positionBundleTokenAccount, ctx.wallet.publicKey, positionBundleMintKeypair.publicKey);
|
||||
await checkPositionBundleTokenAccount(
|
||||
positionBundleTokenAccount,
|
||||
ctx.wallet.publicKey,
|
||||
positionBundleMintKeypair.publicKey
|
||||
);
|
||||
await checkPositionBundle(positionBundlePda.publicKey, positionBundleMintKeypair.publicKey);
|
||||
await checkPositionBundleMetadata(positionBundleMetadataPda, positionBundleMintKeypair.publicKey);
|
||||
await checkPositionBundleMetadata(
|
||||
positionBundleMetadataPda,
|
||||
positionBundleMintKeypair.publicKey
|
||||
);
|
||||
});
|
||||
|
||||
it("successfully initialize when funder is different than account paying for transaction fee", async () => {
|
||||
|
@ -147,7 +187,7 @@ describe("initialize_position_bundle_with_metadata", () => {
|
|||
const positionBundleInfo = await initializePositionBundleWithMetadata(
|
||||
ctx,
|
||||
ctx.wallet.publicKey,
|
||||
otherWallet,
|
||||
otherWallet
|
||||
);
|
||||
|
||||
const postBalance = await ctx.connection.getBalance(ctx.wallet.publicKey);
|
||||
|
@ -163,9 +203,16 @@ describe("initialize_position_bundle_with_metadata", () => {
|
|||
} = positionBundleInfo;
|
||||
|
||||
await checkPositionBundleMint(positionBundleMintKeypair.publicKey);
|
||||
await checkPositionBundleTokenAccount(positionBundleTokenAccount, ctx.wallet.publicKey, positionBundleMintKeypair.publicKey);
|
||||
await checkPositionBundleTokenAccount(
|
||||
positionBundleTokenAccount,
|
||||
ctx.wallet.publicKey,
|
||||
positionBundleMintKeypair.publicKey
|
||||
);
|
||||
await checkPositionBundle(positionBundlePda.publicKey, positionBundleMintKeypair.publicKey);
|
||||
await checkPositionBundleMetadata(positionBundleMetadataPda, positionBundleMintKeypair.publicKey);
|
||||
await checkPositionBundleMetadata(
|
||||
positionBundleMetadataPda,
|
||||
positionBundleMintKeypair.publicKey
|
||||
);
|
||||
});
|
||||
|
||||
it("PositionBundle account has reserved space", async () => {
|
||||
|
@ -173,26 +220,24 @@ describe("initialize_position_bundle_with_metadata", () => {
|
|||
|
||||
const positionBundleInfo = await initializePositionBundleWithMetadata(
|
||||
ctx,
|
||||
ctx.wallet.publicKey,
|
||||
ctx.wallet.publicKey
|
||||
);
|
||||
|
||||
const account = await ctx.connection.getAccountInfo(positionBundleInfo.positionBundlePda.publicKey, "confirmed");
|
||||
const account = await ctx.connection.getAccountInfo(
|
||||
positionBundleInfo.positionBundlePda.publicKey,
|
||||
"confirmed"
|
||||
);
|
||||
assert.equal(account!.data.length, positionBundleAccountSizeIncludingReserve);
|
||||
});
|
||||
|
||||
it("should be failed: cannot mint additional NFT by owner", async () => {
|
||||
const positionBundleInfo = await initializePositionBundleWithMetadata(
|
||||
ctx,
|
||||
ctx.wallet.publicKey,
|
||||
ctx.wallet.publicKey
|
||||
);
|
||||
|
||||
await assert.rejects(
|
||||
mintToByAuthority(
|
||||
provider,
|
||||
positionBundleInfo.positionBundleMintKeypair.publicKey,
|
||||
positionBundleInfo.positionBundleTokenAccount,
|
||||
1
|
||||
),
|
||||
mintToDestination(provider, positionBundleInfo.positionBundleMintKeypair.publicKey, positionBundleInfo.positionBundleTokenAccount, 1),
|
||||
/0x5/ // the total supply of this token is fixed
|
||||
);
|
||||
});
|
||||
|
@ -209,22 +254,28 @@ describe("initialize_position_bundle_with_metadata", () => {
|
|||
const createMintTx = toTx(ctx, {
|
||||
instructions: createMintIx,
|
||||
cleanupInstructions: [],
|
||||
signers: [positionBundleMintKeypair]
|
||||
signers: [positionBundleMintKeypair],
|
||||
});
|
||||
await createMintTx.buildAndExecute();
|
||||
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(ctx, {}, positionBundleMintKeypair);
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
(err) => { return JSON.stringify(err).includes("already in use") }
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(
|
||||
ctx,
|
||||
{},
|
||||
positionBundleMintKeypair
|
||||
);
|
||||
await assert.rejects(tx.buildAndExecute(), (err) => {
|
||||
return JSON.stringify(err).includes("already in use");
|
||||
});
|
||||
});
|
||||
|
||||
describe("invalid input account", () => {
|
||||
it("should be failed: invalid position bundle address", async () => {
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(ctx, {
|
||||
// invalid parameter
|
||||
positionBundle: PDAUtil.getPositionBundle(ctx.program.programId, Keypair.generate().publicKey).publicKey,
|
||||
positionBundle: PDAUtil.getPositionBundle(
|
||||
ctx.program.programId,
|
||||
Keypair.generate().publicKey
|
||||
).publicKey,
|
||||
});
|
||||
|
||||
await assert.rejects(
|
||||
|
@ -236,7 +287,8 @@ describe("initialize_position_bundle_with_metadata", () => {
|
|||
it("should be failed: invalid metadata address", async () => {
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(ctx, {
|
||||
// invalid parameter
|
||||
positionBundleMetadata: PDAUtil.getPositionBundleMetadata(Keypair.generate().publicKey).publicKey,
|
||||
positionBundleMetadata: PDAUtil.getPositionBundleMetadata(Keypair.generate().publicKey)
|
||||
.publicKey,
|
||||
});
|
||||
|
||||
await assert.rejects(
|
||||
|
@ -248,7 +300,10 @@ describe("initialize_position_bundle_with_metadata", () => {
|
|||
it("should be failed: invalid ATA address", async () => {
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(ctx, {
|
||||
// invalid parameter
|
||||
positionBundleTokenAccount: await deriveATA(ctx.wallet.publicKey, Keypair.generate().publicKey),
|
||||
positionBundleTokenAccount: getAssociatedTokenAddressSync(
|
||||
Keypair.generate().publicKey,
|
||||
ctx.wallet.publicKey
|
||||
),
|
||||
});
|
||||
|
||||
await assert.rejects(
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { deriveATA, MathUtil, TransactionBuilder, ZERO } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { MathUtil, TransactionBuilder, ZERO } from "@orca-so/common-sdk";
|
||||
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
|
||||
import { Keypair, SystemProgram } from "@solana/web3.js";
|
||||
import * as assert from "assert";
|
||||
import { BN } from "bn.js";
|
||||
import Decimal from "decimal.js";
|
||||
import { buildWhirlpoolClient, collectFeesQuote, NUM_REWARDS, PDAUtil, PoolUtil, POSITION_BUNDLE_SIZE, PositionBundleData, PriceMath, toTx, Whirlpool, WhirlpoolClient, WhirlpoolIx } from "../../../src";
|
||||
import { NUM_REWARDS, PDAUtil, POSITION_BUNDLE_SIZE, PoolUtil, PositionBundleData, PriceMath, Whirlpool, WhirlpoolClient, WhirlpoolIx, buildWhirlpoolClient, collectFeesQuote, toTx } from "../../../src";
|
||||
import { WhirlpoolContext } from "../../../src/context";
|
||||
import { createTokenAccount, TickSpacing, ZERO_BN } from "../../utils";
|
||||
import { TickSpacing, ZERO_BN, createTokenAccount } from "../../utils";
|
||||
import { defaultConfirmOptions } from "../../utils/const";
|
||||
import { WhirlpoolTestFixture } from "../../utils/fixture";
|
||||
import { initializePositionBundle, openBundledPosition } from "../../utils/init-utils";
|
||||
|
@ -28,7 +28,7 @@ describe("bundled position management tests", () => {
|
|||
const tickUpperIndex = 33536;
|
||||
const tickSpacing = TickSpacing.Standard;
|
||||
const vaultStartBalance = 1_000_000;
|
||||
const liquidityAmount = new u64(10_000_000);
|
||||
const liquidityAmount = new BN(10_000_000);
|
||||
const sleep = (second: number) => new Promise(resolve => setTimeout(resolve, second * 1000))
|
||||
|
||||
before(() => {
|
||||
|
@ -92,7 +92,7 @@ describe("bundled position management tests", () => {
|
|||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(200_000),
|
||||
amount: new BN(200_000),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(4)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -114,7 +114,7 @@ describe("bundled position management tests", () => {
|
|||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(200_000),
|
||||
amount: new BN(200_000),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(5)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -271,15 +271,15 @@ describe("bundled position management tests", () => {
|
|||
rewards: [
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
@ -304,8 +304,8 @@ describe("bundled position management tests", () => {
|
|||
const tickArrayLower = PDAUtil.getTickArrayFromTickIndex(positionInitInfo.params.tickLowerIndex, poolInitInfo.tickSpacing, poolInitInfo.whirlpoolPda.publicKey, ctx.program.programId).publicKey;
|
||||
const tickArrayUpper = PDAUtil.getTickArrayFromTickIndex(positionInitInfo.params.tickUpperIndex, poolInitInfo.tickSpacing, poolInitInfo.whirlpoolPda.publicKey, ctx.program.programId).publicKey;
|
||||
const whirlpoolPubkey = poolInitInfo.whirlpoolPda.publicKey;
|
||||
const tokenOwnerAccountA = await deriveATA(ctx.wallet.publicKey, poolInitInfo.tokenMintA);
|
||||
const tokenOwnerAccountB = await deriveATA(ctx.wallet.publicKey, poolInitInfo.tokenMintB);
|
||||
const tokenOwnerAccountA = getAssociatedTokenAddressSync(poolInitInfo.tokenMintA, ctx.wallet.publicKey);
|
||||
const tokenOwnerAccountB = getAssociatedTokenAddressSync(poolInitInfo.tokenMintB, ctx.wallet.publicKey);
|
||||
|
||||
const modifyLiquidityParams = {
|
||||
liquidityAmount,
|
||||
|
@ -460,15 +460,15 @@ describe("bundled position management tests", () => {
|
|||
rewards: [
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
@ -500,8 +500,8 @@ describe("bundled position management tests", () => {
|
|||
const tickArrayLower = PDAUtil.getTickArrayFromTickIndex(positionInitInfo.params.tickLowerIndex, poolInitInfo.tickSpacing, poolInitInfo.whirlpoolPda.publicKey, ctx.program.programId).publicKey;
|
||||
const tickArrayUpper = PDAUtil.getTickArrayFromTickIndex(positionInitInfo.params.tickUpperIndex, poolInitInfo.tickSpacing, poolInitInfo.whirlpoolPda.publicKey, ctx.program.programId).publicKey;
|
||||
const whirlpoolPubkey = poolInitInfo.whirlpoolPda.publicKey;
|
||||
const tokenOwnerAccountA = await deriveATA(ctx.wallet.publicKey, poolInitInfo.tokenMintA);
|
||||
const tokenOwnerAccountB = await deriveATA(ctx.wallet.publicKey, poolInitInfo.tokenMintB);
|
||||
const tokenOwnerAccountA = getAssociatedTokenAddressSync(poolInitInfo.tokenMintA, ctx.wallet.publicKey);
|
||||
const tokenOwnerAccountB = getAssociatedTokenAddressSync(poolInitInfo.tokenMintB, ctx.wallet.publicKey);
|
||||
|
||||
// initialized check (No data left over from previous opening)
|
||||
const postOpen = await ctx.fetcher.getPosition(bundledPositionPubkey, true);
|
||||
|
@ -656,8 +656,8 @@ describe("bundled position management tests", () => {
|
|||
const tickArrayLower = PDAUtil.getTickArrayFromTickIndex(tickLowerIndex, poolInitInfo.tickSpacing, poolInitInfo.whirlpoolPda.publicKey, ctx.program.programId).publicKey;
|
||||
const tickArrayUpper = PDAUtil.getTickArrayFromTickIndex(tickUpperIndex, poolInitInfo.tickSpacing, poolInitInfo.whirlpoolPda.publicKey, ctx.program.programId).publicKey;
|
||||
const whirlpoolPubkey = poolInitInfo.whirlpoolPda.publicKey;
|
||||
const tokenOwnerAccountA = await deriveATA(ctx.wallet.publicKey, poolInitInfo.tokenMintA);
|
||||
const tokenOwnerAccountB = await deriveATA(ctx.wallet.publicKey, poolInitInfo.tokenMintB);
|
||||
const tokenOwnerAccountA = getAssociatedTokenAddressSync(poolInitInfo.tokenMintA, ctx.wallet.publicKey);
|
||||
const tokenOwnerAccountB = getAssociatedTokenAddressSync(poolInitInfo.tokenMintB, ctx.wallet.publicKey);
|
||||
|
||||
const modifyLiquidityParams = {
|
||||
liquidityAmount,
|
||||
|
@ -743,15 +743,15 @@ describe("bundled position management tests", () => {
|
|||
rewards: [
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
@ -766,8 +766,8 @@ describe("bundled position management tests", () => {
|
|||
const tickArrayLower = PDAUtil.getTickArrayFromTickIndex(tickLowerIndex, poolInitInfo.tickSpacing, poolInitInfo.whirlpoolPda.publicKey, ctx.program.programId).publicKey;
|
||||
const tickArrayUpper = PDAUtil.getTickArrayFromTickIndex(tickUpperIndex, poolInitInfo.tickSpacing, poolInitInfo.whirlpoolPda.publicKey, ctx.program.programId).publicKey;
|
||||
const whirlpoolPubkey = poolInitInfo.whirlpoolPda.publicKey;
|
||||
const tokenOwnerAccountA = await deriveATA(ctx.wallet.publicKey, poolInitInfo.tokenMintA);
|
||||
const tokenOwnerAccountB = await deriveATA(ctx.wallet.publicKey, poolInitInfo.tokenMintB);
|
||||
const tokenOwnerAccountA = getAssociatedTokenAddressSync(poolInitInfo.tokenMintA, ctx.wallet.publicKey);
|
||||
const tokenOwnerAccountB = getAssociatedTokenAddressSync(poolInitInfo.tokenMintB, ctx.wallet.publicKey);
|
||||
|
||||
const modifyLiquidityParams = {
|
||||
liquidityAmount,
|
||||
|
@ -812,8 +812,8 @@ describe("bundled position management tests", () => {
|
|||
}))
|
||||
.addInstruction(WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
...modifyLiquidityParams,
|
||||
tokenMinA: new u64(0),
|
||||
tokenMinB: new u64(0),
|
||||
tokenMinA: new BN(0),
|
||||
tokenMinB: new BN(0),
|
||||
}))
|
||||
.addInstruction(WhirlpoolIx.closeBundledPositionIx(ctx.program, {
|
||||
bundledPosition: bundledPositionPubkey,
|
||||
|
@ -904,15 +904,15 @@ describe("bundled position management tests", () => {
|
|||
rewards: [
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
@ -927,8 +927,8 @@ describe("bundled position management tests", () => {
|
|||
const tickArrayLower = PDAUtil.getTickArrayFromTickIndex(tickLowerIndex, poolInitInfo.tickSpacing, poolInitInfo.whirlpoolPda.publicKey, ctx.program.programId).publicKey;
|
||||
const tickArrayUpper = PDAUtil.getTickArrayFromTickIndex(tickUpperIndex, poolInitInfo.tickSpacing, poolInitInfo.whirlpoolPda.publicKey, ctx.program.programId).publicKey;
|
||||
const whirlpoolPubkey = poolInitInfo.whirlpoolPda.publicKey;
|
||||
const tokenOwnerAccountA = await deriveATA(ctx.wallet.publicKey, poolInitInfo.tokenMintA);
|
||||
const tokenOwnerAccountB = await deriveATA(ctx.wallet.publicKey, poolInitInfo.tokenMintB);
|
||||
const tokenOwnerAccountA = getAssociatedTokenAddressSync(poolInitInfo.tokenMintA, ctx.wallet.publicKey);
|
||||
const tokenOwnerAccountB = getAssociatedTokenAddressSync(poolInitInfo.tokenMintB, ctx.wallet.publicKey);
|
||||
|
||||
const tickArrayPda = PDAUtil.getTickArray(ctx.program.programId, whirlpoolPubkey, 22528);
|
||||
const oraclePda = PDAUtil.getOracle(ctx.program.programId, whirlpoolPubkey);
|
||||
|
@ -955,7 +955,7 @@ describe("bundled position management tests", () => {
|
|||
true
|
||||
);
|
||||
|
||||
const swapInput = new u64(200_000);
|
||||
const swapInput = new BN(200_000);
|
||||
const poolLiquidity = new BN(liquidityAmount.muln(2).toString());
|
||||
const estimatedFee = new BN(swapInput.toString())
|
||||
.muln(3).divn(1000) // feeRate 0.3%
|
||||
|
@ -1023,8 +1023,8 @@ describe("bundled position management tests", () => {
|
|||
}))
|
||||
.addInstruction(WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
...modifyLiquidityParams,
|
||||
tokenMinA: new u64(0),
|
||||
tokenMinB: new u64(0),
|
||||
tokenMinA: new BN(0),
|
||||
tokenMinB: new BN(0),
|
||||
}))
|
||||
.addInstruction(WhirlpoolIx.collectFeesIx(ctx.program, {
|
||||
position: bundledPositionPubkey,
|
||||
|
@ -1046,8 +1046,8 @@ describe("bundled position management tests", () => {
|
|||
}));
|
||||
|
||||
await builder.buildAndExecute();
|
||||
assert.ok((await ctx.fetcher.getTokenInfo(receiverAtaA, true))!.amount.eqn(estimatedFee));
|
||||
assert.ok((await ctx.fetcher.getTokenInfo(receiverAtaB, true))!.amount.eqn(estimatedFee));
|
||||
assert.ok((await ctx.fetcher.getTokenInfo(receiverAtaA, true))!.amount === BigInt(estimatedFee.toString()));
|
||||
assert.ok((await ctx.fetcher.getTokenInfo(receiverAtaB, true))!.amount === BigInt(estimatedFee.toString()));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { PDA } from "@orca-so/common-sdk";
|
||||
import { ASSOCIATED_TOKEN_PROGRAM_ID, Token, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { PublicKey, SystemProgram } from "@solana/web3.js";
|
||||
import * as assert from "assert";
|
||||
import {
|
||||
|
@ -21,7 +21,7 @@ import {
|
|||
ONE_SOL,
|
||||
systemTransferTx,
|
||||
TickSpacing,
|
||||
transfer,
|
||||
transferToken,
|
||||
ZERO_BN
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
|
@ -55,9 +55,7 @@ describe("open_bundled_position", () => {
|
|||
) {
|
||||
const bundledPositionPda = PDAUtil.getBundledPosition(ctx.program.programId, positionBundleMint, bundleIndex);
|
||||
const positionBundle = PDAUtil.getPositionBundle(ctx.program.programId, positionBundleMint).publicKey;
|
||||
const positionBundleTokenAccount = await Token.getAssociatedTokenAddress(
|
||||
ASSOCIATED_TOKEN_PROGRAM_ID,
|
||||
TOKEN_PROGRAM_ID,
|
||||
const positionBundleTokenAccount = getAssociatedTokenAddressSync(
|
||||
positionBundleMint,
|
||||
ctx.wallet.publicKey
|
||||
);
|
||||
|
@ -572,7 +570,7 @@ describe("open_bundled_position", () => {
|
|||
ctx.wallet.publicKey,
|
||||
);
|
||||
|
||||
await transfer(
|
||||
await transferToken(
|
||||
provider,
|
||||
positionBundleInfo.positionBundleTokenAccount,
|
||||
funderATA,
|
||||
|
@ -580,7 +578,7 @@ describe("open_bundled_position", () => {
|
|||
);
|
||||
|
||||
const tokenInfo = await fetcher.getTokenInfo(funderATA, true);
|
||||
assert.ok(tokenInfo?.amount.eqn(1));
|
||||
assert.ok(tokenInfo?.amount === 1n);
|
||||
|
||||
const tx = toTx(
|
||||
ctx,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { web3 } from "@coral-xyz/anchor";
|
||||
import { PDA } from "@orca-so/common-sdk";
|
||||
import { ASSOCIATED_TOKEN_PROGRAM_ID, Token, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { getAccount, getAssociatedTokenAddressSync } from "@solana/spl-token";
|
||||
import { Keypair } from "@solana/web3.js";
|
||||
import * as assert from "assert";
|
||||
import {
|
||||
|
@ -11,18 +11,18 @@ import {
|
|||
OpenPositionParams,
|
||||
PDAUtil,
|
||||
PositionData,
|
||||
toTx,
|
||||
WhirlpoolContext,
|
||||
WhirlpoolIx
|
||||
WhirlpoolIx,
|
||||
toTx
|
||||
} from "../../src";
|
||||
import {
|
||||
ONE_SOL,
|
||||
TickSpacing,
|
||||
ZERO_BN,
|
||||
createMint,
|
||||
createMintInstructions,
|
||||
mintToByAuthority,
|
||||
ONE_SOL,
|
||||
systemTransferTx,
|
||||
TickSpacing,
|
||||
ZERO_BN
|
||||
mintToDestination,
|
||||
systemTransferTx
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { initTestPool, openPosition } from "../utils/init-utils";
|
||||
|
@ -107,31 +107,19 @@ describe("open_position", () => {
|
|||
const { positionMintAddress, positionTokenAccount: positionTokenAccountAddress } =
|
||||
positionInitInfo.params;
|
||||
|
||||
const token = new Token(
|
||||
ctx.connection,
|
||||
positionMintAddress,
|
||||
TOKEN_PROGRAM_ID,
|
||||
web3.Keypair.generate()
|
||||
);
|
||||
|
||||
const userTokenAccount = await token.getAccountInfo(positionTokenAccountAddress);
|
||||
assert.ok(userTokenAccount.amount.eq(new anchor.BN(1)));
|
||||
const userTokenAccount = await getAccount(ctx.connection, positionTokenAccountAddress);
|
||||
assert.ok(userTokenAccount.amount === 1n);
|
||||
assert.ok(userTokenAccount.owner.equals(newOwner.publicKey));
|
||||
|
||||
await assert.rejects(
|
||||
mintToByAuthority(provider, positionMintAddress, positionTokenAccountAddress, 1),
|
||||
mintToDestination(provider, positionMintAddress, positionTokenAccountAddress, 1),
|
||||
/0x5/ // the total supply of this token is fixed
|
||||
);
|
||||
});
|
||||
|
||||
it("user must pass the valid token ATA account", async () => {
|
||||
const anotherMintKey = await createMint(provider, provider.wallet.publicKey);
|
||||
const positionTokenAccountAddress = await Token.getAssociatedTokenAddress(
|
||||
ASSOCIATED_TOKEN_PROGRAM_ID,
|
||||
TOKEN_PROGRAM_ID,
|
||||
anotherMintKey,
|
||||
ctx.provider.wallet.publicKey
|
||||
);
|
||||
const positionTokenAccountAddress = getAssociatedTokenAddressSync(anotherMintKey, provider.wallet.publicKey)
|
||||
|
||||
await assert.rejects(
|
||||
toTx(
|
||||
|
@ -191,12 +179,7 @@ describe("open_position", () => {
|
|||
const positionMintKeypair = anchor.web3.Keypair.generate();
|
||||
const positionPda = PDAUtil.getPosition(ctx.program.programId, positionMintKeypair.publicKey);
|
||||
|
||||
const positionTokenAccountAddress = await Token.getAssociatedTokenAddress(
|
||||
ASSOCIATED_TOKEN_PROGRAM_ID,
|
||||
TOKEN_PROGRAM_ID,
|
||||
positionMintKeypair.publicKey,
|
||||
provider.wallet.publicKey
|
||||
);
|
||||
const positionTokenAccountAddress = getAssociatedTokenAddressSync(positionMintKeypair.publicKey, provider.wallet.publicKey)
|
||||
|
||||
const tx = new web3.Transaction();
|
||||
tx.add(
|
||||
|
|
|
@ -2,7 +2,7 @@ import * as anchor from "@coral-xyz/anchor";
|
|||
import { web3 } from "@coral-xyz/anchor";
|
||||
import { Metadata } from "@metaplex-foundation/mpl-token-metadata";
|
||||
import { PDA, TransactionBuilder } from "@orca-so/common-sdk";
|
||||
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, Token } from "@solana/spl-token";
|
||||
import { TOKEN_PROGRAM_ID, getAccount, getAssociatedTokenAddressSync } from "@solana/spl-token";
|
||||
import { Keypair, PublicKey } from "@solana/web3.js";
|
||||
import * as assert from "assert";
|
||||
import {
|
||||
|
@ -25,7 +25,7 @@ import {
|
|||
ZERO_BN,
|
||||
createMint,
|
||||
createMintInstructions,
|
||||
mintToByAuthority,
|
||||
mintToDestination,
|
||||
systemTransferTx
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
|
@ -65,11 +65,12 @@ describe("open_position_with_metadata", () => {
|
|||
|
||||
async function checkMetadata(metadataPda: PDA | undefined, positionMint: PublicKey) {
|
||||
assert.ok(metadataPda != null);
|
||||
const metadata = await Metadata.load(provider.connection, metadataPda.publicKey);
|
||||
assert.ok(metadata.data.updateAuthority === "3axbTs2z5GBy6usVbNVoqEgZMng3vZvMnAoX29BFfwhr");
|
||||
assert.ok(metadata.data.mint === positionMint.toString());
|
||||
|
||||
const metadata = await Metadata.fromAccountAddress(provider.connection, metadataPda.publicKey);
|
||||
assert.ok(metadata.updateAuthority.toBase58() === "3axbTs2z5GBy6usVbNVoqEgZMng3vZvMnAoX29BFfwhr");
|
||||
assert.ok(metadata.mint.toBase58() === positionMint.toString());
|
||||
assert.ok(
|
||||
metadata.data.data.uri === `https://arweave.net/E19ZNY2sqMqddm1Wx7mrXPUZ0ZZ5ISizhebb0UsVEws`
|
||||
metadata.data.uri.replace(/\0/g, '') === `https://arweave.net/E19ZNY2sqMqddm1Wx7mrXPUZ0ZZ5ISizhebb0UsVEws`
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -126,33 +127,21 @@ describe("open_position_with_metadata", () => {
|
|||
positionTokenAccount: positionTokenAccountAddress,
|
||||
} = positionInitInfo.params;
|
||||
|
||||
const token = new Token(
|
||||
ctx.connection,
|
||||
positionMintAddress,
|
||||
TOKEN_PROGRAM_ID,
|
||||
web3.Keypair.generate()
|
||||
);
|
||||
|
||||
await checkMetadata(metadataPda, positionMintAddress);
|
||||
|
||||
const userTokenAccount = await token.getAccountInfo(positionTokenAccountAddress);
|
||||
assert.ok(userTokenAccount.amount.eq(new anchor.BN(1)));
|
||||
const userTokenAccount = await getAccount(ctx.connection, positionTokenAccountAddress);
|
||||
assert.ok(userTokenAccount.amount === 1n);
|
||||
assert.ok(userTokenAccount.owner.equals(newOwner.publicKey));
|
||||
|
||||
await assert.rejects(
|
||||
mintToByAuthority(provider, positionMintAddress, positionTokenAccountAddress, 1),
|
||||
mintToDestination(provider, positionMintAddress, positionTokenAccountAddress, 1),
|
||||
/0x5/ // the total supply of this token is fixed
|
||||
);
|
||||
});
|
||||
|
||||
it("user must pass the valid token ATA account", async () => {
|
||||
const anotherMintKey = await createMint(provider, provider.wallet.publicKey);
|
||||
const positionTokenAccountAddress = await Token.getAssociatedTokenAddress(
|
||||
ASSOCIATED_TOKEN_PROGRAM_ID,
|
||||
TOKEN_PROGRAM_ID,
|
||||
anotherMintKey,
|
||||
ctx.provider.wallet.publicKey
|
||||
);
|
||||
const positionTokenAccountAddress = getAssociatedTokenAddressSync(anotherMintKey, provider.wallet.publicKey)
|
||||
|
||||
await assert.rejects(
|
||||
toTx(
|
||||
|
@ -213,12 +202,7 @@ describe("open_position_with_metadata", () => {
|
|||
const positionPda = PDAUtil.getPosition(ctx.program.programId, positionMintKeypair.publicKey);
|
||||
const metadataPda = PDAUtil.getPositionMetadata(positionMintKeypair.publicKey);
|
||||
|
||||
const positionTokenAccountAddress = await Token.getAssociatedTokenAddress(
|
||||
ASSOCIATED_TOKEN_PROGRAM_ID,
|
||||
TOKEN_PROGRAM_ID,
|
||||
positionMintKeypair.publicKey,
|
||||
provider.wallet.publicKey
|
||||
);
|
||||
const positionTokenAccountAddress = getAssociatedTokenAddressSync(positionMintKeypair.publicKey, provider.wallet.publicKey);
|
||||
|
||||
const tx = new web3.Transaction();
|
||||
tx.add(
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import * as assert from "assert";
|
||||
import { toTx, WhirlpoolContext, WhirlpoolData, WhirlpoolIx } from "../../src";
|
||||
import { createAndMintToTokenAccount, mintToByAuthority, TickSpacing, ZERO_BN } from "../utils";
|
||||
import { createAndMintToTokenAccount, mintToDestination, TickSpacing, ZERO_BN } from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { initializeReward, initTestPool } from "../utils/init-utils";
|
||||
|
||||
|
@ -31,7 +31,7 @@ describe("set_reward_emissions", () => {
|
|||
rewardIndex
|
||||
);
|
||||
|
||||
await mintToByAuthority(provider, rewardMint, rewardVaultKeypair.publicKey, 10000);
|
||||
await mintToDestination(provider, rewardMint, rewardVaultKeypair.publicKey, 10000);
|
||||
|
||||
await toTx(
|
||||
ctx,
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { web3 } from "@coral-xyz/anchor";
|
||||
import { MathUtil, Percentage } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import * as assert from "assert";
|
||||
import { BN } from "bn.js";
|
||||
import Decimal from "decimal.js";
|
||||
import {
|
||||
MAX_SQRT_PRICE,
|
||||
|
@ -63,7 +63,7 @@ describe("swap", () => {
|
|||
toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(10),
|
||||
amount: new BN(10),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(4.95)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -108,7 +108,7 @@ describe("swap", () => {
|
|||
toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(10),
|
||||
amount: new BN(10),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(4.95)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -155,7 +155,7 @@ describe("swap", () => {
|
|||
toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(10),
|
||||
amount: new BN(10),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(4.95)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -202,7 +202,7 @@ describe("swap", () => {
|
|||
toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(10),
|
||||
amount: new BN(10),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(4.95)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -244,7 +244,7 @@ describe("swap", () => {
|
|||
toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(10),
|
||||
amount: new BN(10),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(4.95)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -290,7 +290,7 @@ describe("swap", () => {
|
|||
toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(10),
|
||||
amount: new BN(10),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: PriceMath.tickIndexToSqrtPriceX64(-50000),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -332,7 +332,7 @@ describe("swap", () => {
|
|||
toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(10),
|
||||
amount: new BN(10),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(4.95)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -374,7 +374,7 @@ describe("swap", () => {
|
|||
toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(10),
|
||||
amount: new BN(10),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(4.95)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -412,7 +412,7 @@ describe("swap", () => {
|
|||
toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(10),
|
||||
amount: new BN(10),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(4.95)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -457,7 +457,7 @@ describe("swap", () => {
|
|||
toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(10),
|
||||
amount: new BN(10),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(4.95)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -497,7 +497,7 @@ describe("swap", () => {
|
|||
toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(0),
|
||||
amount: new BN(0),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(4.95)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -556,7 +556,7 @@ describe("swap", () => {
|
|||
const quote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintB,
|
||||
new u64(100000),
|
||||
new BN(100000),
|
||||
Percentage.fromFraction(1, 100),
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -647,7 +647,7 @@ describe("swap", () => {
|
|||
const quote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintA,
|
||||
new u64(1),
|
||||
new BN(1),
|
||||
Percentage.fromFraction(1, 100),
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -682,7 +682,7 @@ describe("swap", () => {
|
|||
const quote2 = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintA,
|
||||
new u64(1),
|
||||
new BN(1),
|
||||
Percentage.fromFraction(1, 100),
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -774,7 +774,7 @@ describe("swap", () => {
|
|||
const quote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintA,
|
||||
new u64(1),
|
||||
new BN(1),
|
||||
Percentage.fromFraction(1, 100),
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -808,7 +808,7 @@ describe("swap", () => {
|
|||
const quote2 = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintA,
|
||||
new u64(43),
|
||||
new BN(43),
|
||||
Percentage.fromFraction(1, 100),
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -894,7 +894,7 @@ describe("swap", () => {
|
|||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(7051000),
|
||||
amount: new BN(7051000),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: PriceMath.tickIndexToSqrtPriceX64(28500),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -934,7 +934,7 @@ describe("swap", () => {
|
|||
const oraclePda = PDAUtil.getOracle(ctx.program.programId, poolInitInfo.whirlpoolPda.publicKey);
|
||||
|
||||
const params: SwapParams = {
|
||||
amount: new u64(10),
|
||||
amount: new BN(10),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(4294886578)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -968,7 +968,7 @@ describe("swap", () => {
|
|||
const oraclePda = PDAUtil.getOracle(ctx.program.programId, poolInitInfo.whirlpoolPda.publicKey);
|
||||
|
||||
const params: SwapParams = {
|
||||
amount: new u64(10),
|
||||
amount: new BN(10),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: new anchor.BN(MAX_SQRT_PRICE).add(new anchor.BN(1)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -1002,7 +1002,7 @@ describe("swap", () => {
|
|||
const oraclePda = PDAUtil.getOracle(ctx.program.programId, poolInitInfo.whirlpoolPda.publicKey);
|
||||
|
||||
const params: SwapParams = {
|
||||
amount: new u64(10),
|
||||
amount: new BN(10),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: new anchor.BN(MIN_SQRT_PRICE).sub(new anchor.BN(1)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -1054,7 +1054,7 @@ describe("swap", () => {
|
|||
const oraclePda = PDAUtil.getOracle(ctx.program.programId, whirlpoolPda.publicKey);
|
||||
|
||||
const params = {
|
||||
amount: new u64(10),
|
||||
amount: new BN(10),
|
||||
otherAmountThreshold: MAX_U64,
|
||||
sqrtPriceLimit: new anchor.BN(MIN_SQRT_PRICE),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -1106,7 +1106,7 @@ describe("swap", () => {
|
|||
const oraclePda = PDAUtil.getOracle(ctx.program.programId, whirlpoolPda.publicKey);
|
||||
|
||||
const params = {
|
||||
amount: new u64(10),
|
||||
amount: new BN(10),
|
||||
otherAmountThreshold: MAX_U64,
|
||||
sqrtPriceLimit: new anchor.BN(MAX_SQRT_PRICE),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -1158,7 +1158,7 @@ describe("swap", () => {
|
|||
const oraclePda = PDAUtil.getOracle(ctx.program.programId, whirlpoolPda.publicKey);
|
||||
|
||||
const params = {
|
||||
amount: new u64(10),
|
||||
amount: new BN(10),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: new anchor.BN(MIN_SQRT_PRICE),
|
||||
amountSpecifiedIsInput: false,
|
||||
|
@ -1210,7 +1210,7 @@ describe("swap", () => {
|
|||
const oraclePda = PDAUtil.getOracle(ctx.program.programId, whirlpoolPda.publicKey);
|
||||
|
||||
const params = {
|
||||
amount: new u64(10),
|
||||
amount: new BN(10),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: new anchor.BN(MAX_SQRT_PRICE),
|
||||
amountSpecifiedIsInput: false,
|
||||
|
@ -1343,7 +1343,7 @@ describe("swap", () => {
|
|||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(829996),
|
||||
amount: new BN(829996),
|
||||
otherAmountThreshold: MAX_U64,
|
||||
sqrtPriceLimit: PriceMath.tickIndexToSqrtPriceX64(29240),
|
||||
amountSpecifiedIsInput: false,
|
||||
|
@ -1384,7 +1384,7 @@ describe("swap", () => {
|
|||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(14538074),
|
||||
amount: new BN(14538074),
|
||||
otherAmountThreshold: MAX_U64,
|
||||
sqrtPriceLimit: PriceMath.tickIndexToSqrtPriceX64(27712),
|
||||
amountSpecifiedIsInput: false,
|
||||
|
@ -1425,7 +1425,7 @@ describe("swap", () => {
|
|||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(829996),
|
||||
amount: new BN(829996),
|
||||
otherAmountThreshold: MAX_U64,
|
||||
sqrtPriceLimit: PriceMath.tickIndexToSqrtPriceX64(29240),
|
||||
amountSpecifiedIsInput: false,
|
||||
|
@ -1466,7 +1466,7 @@ describe("swap", () => {
|
|||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(14538074),
|
||||
amount: new BN(14538074),
|
||||
otherAmountThreshold: MAX_U64,
|
||||
sqrtPriceLimit: PriceMath.tickIndexToSqrtPriceX64(27712),
|
||||
amountSpecifiedIsInput: false,
|
||||
|
@ -1507,7 +1507,7 @@ describe("swap", () => {
|
|||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(829996),
|
||||
amount: new BN(829996),
|
||||
otherAmountThreshold: MAX_U64,
|
||||
sqrtPriceLimit: PriceMath.tickIndexToSqrtPriceX64(29240),
|
||||
amountSpecifiedIsInput: false,
|
||||
|
@ -1548,7 +1548,7 @@ describe("swap", () => {
|
|||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(14538074),
|
||||
amount: new BN(14538074),
|
||||
otherAmountThreshold: MAX_U64,
|
||||
sqrtPriceLimit: PriceMath.tickIndexToSqrtPriceX64(27712),
|
||||
amountSpecifiedIsInput: false,
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { Percentage } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import * as assert from "assert";
|
||||
import { BN } from "bn.js";
|
||||
import {
|
||||
buildWhirlpoolClient,
|
||||
InitPoolParams,
|
||||
|
@ -82,7 +82,7 @@ describe("two-hop swap", () => {
|
|||
const quote = await swapQuoteByInputToken(
|
||||
whirlpoolOne,
|
||||
inputToken,
|
||||
new u64(1000),
|
||||
new BN(1000),
|
||||
Percentage.fromFraction(1, 100),
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -232,7 +232,7 @@ describe("two-hop swap", () => {
|
|||
const quote = await swapQuoteByInputToken(
|
||||
whirlpoolOne,
|
||||
inputToken,
|
||||
new u64(1000),
|
||||
new BN(1000),
|
||||
Percentage.fromFraction(1, 100),
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -317,7 +317,7 @@ describe("two-hop swap", () => {
|
|||
const quote = await swapQuoteByInputToken(
|
||||
whirlpoolOne,
|
||||
tokenA,
|
||||
new u64(1000),
|
||||
new BN(1000),
|
||||
Percentage.fromFraction(1, 100),
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -376,7 +376,7 @@ describe("two-hop swap", () => {
|
|||
const quote = await swapQuoteByInputToken(
|
||||
whirlpoolOne,
|
||||
inputToken,
|
||||
new u64(1000),
|
||||
new BN(1000),
|
||||
Percentage.fromFraction(1, 100),
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -401,7 +401,7 @@ describe("two-hop swap", () => {
|
|||
WhirlpoolIx.twoHopSwapIx(ctx.program, {
|
||||
...twoHopQuote,
|
||||
...getParamsFromPools([pools[0], pools[1]], tokenAccounts),
|
||||
otherAmountThreshold: new u64(613309),
|
||||
otherAmountThreshold: new BN(613309),
|
||||
tokenAuthority: ctx.wallet.publicKey,
|
||||
})
|
||||
).buildAndExecute(),
|
||||
|
@ -426,7 +426,7 @@ describe("two-hop swap", () => {
|
|||
const quote2 = await swapQuoteByOutputToken(
|
||||
whirlpoolTwo,
|
||||
outputToken,
|
||||
new u64(1000),
|
||||
new BN(1000),
|
||||
Percentage.fromFraction(1, 100),
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -485,7 +485,7 @@ describe("two-hop swap", () => {
|
|||
const quote2 = await swapQuoteByOutputToken(
|
||||
whirlpoolTwo,
|
||||
outputToken,
|
||||
new u64(1000),
|
||||
new BN(1000),
|
||||
Percentage.fromFraction(1, 100),
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -510,7 +510,7 @@ describe("two-hop swap", () => {
|
|||
WhirlpoolIx.twoHopSwapIx(ctx.program, {
|
||||
...twoHopQuote,
|
||||
...getParamsFromPools([pools[0], pools[1]], tokenAccounts),
|
||||
otherAmountThreshold: new u64(2),
|
||||
otherAmountThreshold: new BN(2),
|
||||
tokenAuthority: ctx.wallet.publicKey,
|
||||
})
|
||||
).buildAndExecute(),
|
||||
|
@ -536,7 +536,7 @@ describe("two-hop swap", () => {
|
|||
const quote2 = await swapQuoteByOutputToken(
|
||||
whirlpoolTwo,
|
||||
outputToken,
|
||||
new u64(1000),
|
||||
new BN(1000),
|
||||
Percentage.fromFraction(1, 100),
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -582,7 +582,7 @@ describe("two-hop swap", () => {
|
|||
const quote = await swapQuoteByInputToken(
|
||||
whirlpoolOne,
|
||||
inputToken,
|
||||
new u64(1000),
|
||||
new BN(1000),
|
||||
Percentage.fromFraction(0, 100),
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -641,7 +641,7 @@ describe("two-hop swap", () => {
|
|||
const quote = await swapQuoteByInputToken(
|
||||
whirlpoolOne,
|
||||
inputToken,
|
||||
new u64(1000),
|
||||
new BN(1000),
|
||||
Percentage.fromFraction(0, 100),
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -699,7 +699,7 @@ describe("two-hop swap", () => {
|
|||
const quote = await swapQuoteByInputToken(
|
||||
whirlpoolOne,
|
||||
inputToken,
|
||||
new u64(1000),
|
||||
new BN(1000),
|
||||
Percentage.fromFraction(0, 100),
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -755,7 +755,7 @@ describe("two-hop swap", () => {
|
|||
const quote = await swapQuoteByInputToken(
|
||||
whirlpoolOne,
|
||||
inputToken,
|
||||
new u64(1000),
|
||||
new BN(1000),
|
||||
Percentage.fromFraction(0, 100),
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { MathUtil } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import * as assert from "assert";
|
||||
import { BN } from "bn.js";
|
||||
import Decimal from "decimal.js";
|
||||
import { PDAUtil, PositionData, toTx, WhirlpoolContext, WhirlpoolIx } from "../../src";
|
||||
import { sleep, TickSpacing, ZERO_BN } from "../utils";
|
||||
|
@ -26,7 +26,7 @@ describe("update_fees_and_rewards", () => {
|
|||
tickSpacing,
|
||||
positions: [{ tickLowerIndex, tickUpperIndex, liquidityAmount: new anchor.BN(1_000_000) }],
|
||||
rewards: [
|
||||
{ emissionsPerSecondX64: MathUtil.toX64(new Decimal(2)), vaultAmount: new u64(1_000_000) },
|
||||
{ emissionsPerSecondX64: MathUtil.toX64(new Decimal(2)), vaultAmount: new BN(1_000_000) },
|
||||
],
|
||||
});
|
||||
const {
|
||||
|
@ -52,7 +52,7 @@ describe("update_fees_and_rewards", () => {
|
|||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(100_000),
|
||||
amount: new BN(100_000),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(4.95)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { deriveATA, MathUtil } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { BN } from "@coral-xyz/anchor";
|
||||
import { MathUtil } from "@orca-so/common-sdk";
|
||||
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
|
||||
import * as assert from "assert";
|
||||
import Decimal from "decimal.js";
|
||||
import {
|
||||
buildWhirlpoolClient,
|
||||
collectFeesQuote,
|
||||
PDAUtil,
|
||||
toTx,
|
||||
Whirlpool,
|
||||
WhirlpoolClient,
|
||||
WhirlpoolContext,
|
||||
WhirlpoolIx
|
||||
WhirlpoolIx,
|
||||
buildWhirlpoolClient,
|
||||
collectFeesQuote,
|
||||
toTx
|
||||
} from "../../../src";
|
||||
import { TickSpacing, ZERO_BN } from "../../utils";
|
||||
import { defaultConfirmOptions } from "../../utils/const";
|
||||
|
@ -29,7 +30,7 @@ describe("PositionImpl#collectFees()", () => {
|
|||
const tickLowerIndex = 29440;
|
||||
const tickUpperIndex = 33536;
|
||||
const tickSpacing = TickSpacing.Standard;
|
||||
const liquidityAmount = new u64(10_000_000);
|
||||
const liquidityAmount = new BN(10_000_000);
|
||||
|
||||
before(() => {
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
@ -68,7 +69,7 @@ describe("PositionImpl#collectFees()", () => {
|
|||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(200_000),
|
||||
amount: new BN(200_000),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(4)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -90,7 +91,7 @@ describe("PositionImpl#collectFees()", () => {
|
|||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(200_000),
|
||||
amount: new BN(200_000),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(5)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -178,13 +179,13 @@ describe("PositionImpl#collectFees()", () => {
|
|||
|
||||
assert.notEqual(positionDataAfter, null);
|
||||
|
||||
const accountAPubkey = await deriveATA(otherWallet.publicKey, poolInitInfo.tokenMintA);
|
||||
const accountAPubkey = getAssociatedTokenAddressSync(poolInitInfo.tokenMintA, otherWallet.publicKey);
|
||||
const accountA = await testCtx.whirlpoolCtx.fetcher.getTokenInfo(accountAPubkey, true);
|
||||
assert.ok(accountA && accountA.amount.eq(quote.feeOwedA));
|
||||
assert.ok(accountA && new BN(accountA.amount.toString()).eq(quote.feeOwedA));
|
||||
|
||||
const accountBPubkey = await deriveATA(otherWallet.publicKey, poolInitInfo.tokenMintB);
|
||||
const accountBPubkey = getAssociatedTokenAddressSync(poolInitInfo.tokenMintB, otherWallet.publicKey);
|
||||
const accountB = await testCtx.whirlpoolCtx.fetcher.getTokenInfo(accountBPubkey, true);
|
||||
assert.ok(accountB && accountB.amount.eq(quote.feeOwedB));
|
||||
assert.ok(accountB && new BN(accountB.amount.toString()).eq(quote.feeOwedB));
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -252,9 +253,9 @@ describe("PositionImpl#collectFees()", () => {
|
|||
quote.feeOwedA.toNumber() + minAccountExempt
|
||||
);
|
||||
|
||||
const accountBPubkey = await deriveATA(otherWallet.publicKey, poolInitInfo.tokenMintB);
|
||||
const accountBPubkey = getAssociatedTokenAddressSync(poolInitInfo.tokenMintB, otherWallet.publicKey);
|
||||
const accountB = await testCtx.whirlpoolCtx.fetcher.getTokenInfo(accountBPubkey, true);
|
||||
assert.ok(accountB && accountB.amount.eq(quote.feeOwedB));
|
||||
assert.ok(accountB && new BN(accountB.amount.toString()).eq(quote.feeOwedB));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { deriveATA, MathUtil } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { MathUtil } from "@orca-so/common-sdk";
|
||||
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
|
||||
import * as assert from "assert";
|
||||
import { BN } from "bn.js";
|
||||
import Decimal from "decimal.js";
|
||||
import {
|
||||
buildWhirlpoolClient,
|
||||
collectRewardsQuote,
|
||||
NUM_REWARDS,
|
||||
Whirlpool,
|
||||
WhirlpoolClient,
|
||||
WhirlpoolContext
|
||||
WhirlpoolContext,
|
||||
buildWhirlpoolClient,
|
||||
collectRewardsQuote
|
||||
} from "../../../src";
|
||||
import { sleep, TickSpacing } from "../../utils";
|
||||
import { TickSpacing, sleep } from "../../utils";
|
||||
import { defaultConfirmOptions } from "../../utils/const";
|
||||
import { WhirlpoolTestFixture } from "../../utils/fixture";
|
||||
|
||||
|
@ -28,7 +29,7 @@ describe("PositionImpl#collectRewards()", () => {
|
|||
const tickUpperIndex = 33536;
|
||||
const vaultStartBalance = 1_000_000;
|
||||
const tickSpacing = TickSpacing.Standard;
|
||||
const liquidityAmount = new u64(10_000_000);
|
||||
const liquidityAmount = new BN(10_000_000);
|
||||
|
||||
before(() => {
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
@ -55,15 +56,15 @@ describe("PositionImpl#collectRewards()", () => {
|
|||
rewards: [
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
@ -107,7 +108,7 @@ describe("PositionImpl#collectRewards()", () => {
|
|||
}
|
||||
|
||||
for (let i = 0; i < NUM_REWARDS; i++) {
|
||||
const rewardATA = await deriveATA(otherWallet.publicKey, rewards[i].rewardMint);
|
||||
const rewardATA = getAssociatedTokenAddressSync(rewards[i].rewardMint, otherWallet.publicKey);
|
||||
const rewardTokenAccount = await testCtx.whirlpoolCtx.fetcher.getTokenInfo(rewardATA, true);
|
||||
assert.equal(rewardTokenAccount?.amount.toString(), quote[i]?.toString());
|
||||
}
|
||||
|
@ -124,15 +125,15 @@ describe("PositionImpl#collectRewards()", () => {
|
|||
rewards: [
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
],
|
||||
tokenAIsNative: true,
|
||||
|
@ -176,7 +177,7 @@ describe("PositionImpl#collectRewards()", () => {
|
|||
}
|
||||
|
||||
for (let i = 0; i < NUM_REWARDS; i++) {
|
||||
const rewardATA = await deriveATA(otherWallet.publicKey, rewards[i].rewardMint);
|
||||
const rewardATA = getAssociatedTokenAddressSync(rewards[i].rewardMint, otherWallet.publicKey);
|
||||
const rewardTokenAccount = await testCtx.whirlpoolCtx.fetcher.getTokenInfo(rewardATA, true);
|
||||
assert.equal(rewardTokenAccount?.amount.toString(), quote[i]?.toString());
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { deriveATA, Percentage } from "@orca-so/common-sdk";
|
||||
import { Percentage } from "@orca-so/common-sdk";
|
||||
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
|
||||
import * as assert from "assert";
|
||||
import Decimal from "decimal.js";
|
||||
import {
|
||||
|
@ -9,7 +10,7 @@ import {
|
|||
PriceMath
|
||||
} from "../../../src";
|
||||
import { WhirlpoolContext } from "../../../src/context";
|
||||
import { createAssociatedTokenAccount, TickSpacing, transfer } from "../../utils";
|
||||
import { createAssociatedTokenAccount, TickSpacing, transferToken } from "../../utils";
|
||||
import { defaultConfirmOptions } from "../../utils/const";
|
||||
import { initTestPool } from "../../utils/init-utils";
|
||||
import { initPosition, mintTokensToTestAccount } from "../../utils/test-builders";
|
||||
|
@ -181,14 +182,14 @@ describe("position-impl", () => {
|
|||
|
||||
// Transfer the position token to another wallet
|
||||
const otherWallet = anchor.web3.Keypair.generate();
|
||||
const walletPositionTokenAccount = await deriveATA(ctx.wallet.publicKey, positionMint);
|
||||
const walletPositionTokenAccount = getAssociatedTokenAddressSync(positionMint, ctx.wallet.publicKey);
|
||||
const newOwnerPositionTokenAccount = await createAssociatedTokenAccount(
|
||||
ctx.provider,
|
||||
positionMint,
|
||||
otherWallet.publicKey,
|
||||
ctx.wallet.publicKey
|
||||
);
|
||||
await transfer(provider, walletPositionTokenAccount, newOwnerPositionTokenAccount, 1);
|
||||
await transferToken(provider, walletPositionTokenAccount, newOwnerPositionTokenAccount, 1);
|
||||
|
||||
// Mint to this other wallet and increase more tokens
|
||||
await mintTokensToTestAccount(
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { AddressUtil, Percentage, ZERO } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import * as assert from "assert";
|
||||
import BN from "bn.js";
|
||||
import {
|
||||
|
@ -56,7 +55,7 @@ describe("swap arrays test", () => {
|
|||
});
|
||||
|
||||
const whirlpoolData = await whirlpool.refreshData();
|
||||
const tradeAmount = new u64(10000);
|
||||
const tradeAmount = new BN(10000);
|
||||
const quote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintA,
|
||||
|
@ -112,7 +111,7 @@ describe("swap arrays test", () => {
|
|||
swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintA,
|
||||
new u64(40_000_000),
|
||||
new BN(40_000_000),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -145,7 +144,7 @@ describe("swap arrays test", () => {
|
|||
});
|
||||
|
||||
const whirlpoolData = await whirlpool.refreshData();
|
||||
const tradeAmount = new u64(10000);
|
||||
const tradeAmount = new BN(10000);
|
||||
const quote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintB,
|
||||
|
@ -201,7 +200,7 @@ describe("swap arrays test", () => {
|
|||
swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintB,
|
||||
new u64(40_000_000),
|
||||
new BN(40_000_000),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -234,7 +233,7 @@ describe("swap arrays test", () => {
|
|||
});
|
||||
|
||||
const whirlpoolData = await whirlpool.refreshData();
|
||||
const tradeAmount = new u64(10000);
|
||||
const tradeAmount = new BN(10000);
|
||||
const quote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintA,
|
||||
|
@ -284,7 +283,7 @@ describe("swap arrays test", () => {
|
|||
});
|
||||
|
||||
const whirlpoolData = await whirlpool.refreshData();
|
||||
const tradeAmount = new u64(10000);
|
||||
const tradeAmount = new BN(10000);
|
||||
const quote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintB,
|
||||
|
@ -350,7 +349,7 @@ describe("swap arrays test", () => {
|
|||
{
|
||||
aToB,
|
||||
amountSpecifiedIsInput: true,
|
||||
tokenAmount: new u64("10000"),
|
||||
tokenAmount: new BN("10000"),
|
||||
whirlpoolData,
|
||||
tickArrays,
|
||||
sqrtPriceLimit: SwapUtils.getDefaultSqrtPriceLimit(aToB),
|
||||
|
@ -401,7 +400,7 @@ describe("swap arrays test", () => {
|
|||
{
|
||||
aToB,
|
||||
amountSpecifiedIsInput: true,
|
||||
tokenAmount: new u64("10000"),
|
||||
tokenAmount: new BN("10000"),
|
||||
whirlpoolData,
|
||||
tickArrays,
|
||||
sqrtPriceLimit: SwapUtils.getDefaultSqrtPriceLimit(aToB),
|
||||
|
@ -451,7 +450,7 @@ describe("swap arrays test", () => {
|
|||
{
|
||||
aToB,
|
||||
amountSpecifiedIsInput: true,
|
||||
tokenAmount: new u64("10000"),
|
||||
tokenAmount: new BN("10000"),
|
||||
whirlpoolData,
|
||||
tickArrays,
|
||||
sqrtPriceLimit: SwapUtils.getDefaultSqrtPriceLimit(aToB),
|
||||
|
@ -502,7 +501,7 @@ describe("swap arrays test", () => {
|
|||
{
|
||||
aToB,
|
||||
amountSpecifiedIsInput: true,
|
||||
tokenAmount: new u64("10000"),
|
||||
tokenAmount: new BN("10000"),
|
||||
whirlpoolData,
|
||||
tickArrays,
|
||||
sqrtPriceLimit: SwapUtils.getDefaultSqrtPriceLimit(aToB),
|
||||
|
@ -549,7 +548,7 @@ describe("swap arrays test", () => {
|
|||
{
|
||||
aToB,
|
||||
amountSpecifiedIsInput: true,
|
||||
tokenAmount: new u64("10000"),
|
||||
tokenAmount: new BN("10000"),
|
||||
whirlpoolData,
|
||||
tickArrays,
|
||||
sqrtPriceLimit: SwapUtils.getDefaultSqrtPriceLimit(aToB),
|
||||
|
@ -601,7 +600,7 @@ describe("swap arrays test", () => {
|
|||
{
|
||||
aToB,
|
||||
amountSpecifiedIsInput: true,
|
||||
tokenAmount: new u64("10000"),
|
||||
tokenAmount: new BN("10000"),
|
||||
whirlpoolData,
|
||||
tickArrays,
|
||||
sqrtPriceLimit: SwapUtils.getDefaultSqrtPriceLimit(aToB),
|
||||
|
@ -650,7 +649,7 @@ describe("swap arrays test", () => {
|
|||
AddressUtil.toPubKey(whirlpool.getAddress()),
|
||||
fetcher
|
||||
);
|
||||
const tradeAmount = new u64("33588");
|
||||
const tradeAmount = new BN("33588");
|
||||
const quote = swapQuoteWithParams(
|
||||
{
|
||||
aToB,
|
||||
|
@ -708,7 +707,7 @@ describe("swap arrays test", () => {
|
|||
AddressUtil.toPubKey(whirlpool.getAddress()),
|
||||
fetcher
|
||||
);
|
||||
const tradeAmount = new u64("33588");
|
||||
const tradeAmount = new BN("33588");
|
||||
const quote = swapQuoteWithParams(
|
||||
{
|
||||
aToB,
|
||||
|
@ -760,7 +759,7 @@ describe("swap arrays test", () => {
|
|||
});
|
||||
|
||||
const whirlpoolData = await whirlpool.refreshData();
|
||||
const tradeAmount = new u64(10000);
|
||||
const tradeAmount = new BN(10000);
|
||||
const aToB = true;
|
||||
const tickArrays = SwapUtils.getTickArrayPublicKeys(
|
||||
whirlpoolData.tickCurrentIndex,
|
||||
|
@ -811,7 +810,7 @@ describe("swap arrays test", () => {
|
|||
});
|
||||
|
||||
const whirlpoolData = await whirlpool.refreshData();
|
||||
const tradeAmount = new u64(10000);
|
||||
const tradeAmount = new BN(10000);
|
||||
const aToB = false;
|
||||
const tickArrays = SwapUtils.getTickArrayPublicKeys(
|
||||
whirlpoolData.tickCurrentIndex,
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { Address } from "@coral-xyz/anchor";
|
||||
import { Percentage } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { Keypair } from "@solana/web3.js";
|
||||
import * as assert from "assert";
|
||||
import { BN } from "bn.js";
|
||||
import {
|
||||
buildWhirlpoolClient, PriceMath,
|
||||
swapQuoteByInputToken,
|
||||
|
@ -57,7 +57,7 @@ describe("whirlpool-dev-fee-swap", () => {
|
|||
});
|
||||
|
||||
const devFeePercentage = Percentage.fromFraction(0, 1000); // 0%
|
||||
const inputTokenAmount = new u64(119500000);
|
||||
const inputTokenAmount = new BN(119500000);
|
||||
const postFeeTokenAmount = inputTokenAmount.sub(
|
||||
inputTokenAmount.mul(devFeePercentage.numerator).div(devFeePercentage.denominator)
|
||||
);
|
||||
|
@ -123,7 +123,7 @@ describe("whirlpool-dev-fee-swap", () => {
|
|||
});
|
||||
|
||||
const devFeePercentage = Percentage.fromFraction(1, 1000); // 0.1%
|
||||
const inputTokenAmount = new u64(1195000);
|
||||
const inputTokenAmount = new BN(1195000);
|
||||
const postFeeTokenAmount = inputTokenAmount.sub(
|
||||
inputTokenAmount.mul(devFeePercentage.numerator).div(devFeePercentage.denominator)
|
||||
);
|
||||
|
@ -131,6 +131,7 @@ describe("whirlpool-dev-fee-swap", () => {
|
|||
const whirlpoolData = await whirlpool.refreshData();
|
||||
const swapToken = aToB ? whirlpoolData.tokenMintA : whirlpoolData.tokenMintB;
|
||||
const beforeVaultAmounts = await getVaultAmounts(ctx, whirlpoolData);
|
||||
|
||||
const { inputTokenQuote, postFeeInputTokenQuote, inputTokenQuoteWithDevFees } = await getQuotes(
|
||||
ctx,
|
||||
whirlpool,
|
||||
|
@ -179,7 +180,7 @@ describe("whirlpool-dev-fee-swap", () => {
|
|||
});
|
||||
|
||||
const devFeePercentage = Percentage.fromFraction(1, 100); // 1%
|
||||
const inputTokenAmount = new u64(119500000);
|
||||
const inputTokenAmount = new BN(119500000);
|
||||
const postFeeTokenAmount = inputTokenAmount.sub(
|
||||
inputTokenAmount.mul(devFeePercentage.numerator).div(devFeePercentage.denominator)
|
||||
);
|
||||
|
@ -258,7 +259,7 @@ describe("whirlpool-dev-fee-swap", () => {
|
|||
const { devWallet, balance: preDevWalletBalance } = await setupDevWallet(ctx, 10_000_000)
|
||||
|
||||
const devFeePercentage = Percentage.fromFraction(1, 10000); // 0.01%
|
||||
const inputTokenAmount = new u64(1_000_000_000); // Swap 1SOL
|
||||
const inputTokenAmount = new BN(1_000_000_000); // Swap 1SOL
|
||||
const postFeeTokenAmount = inputTokenAmount.sub(
|
||||
inputTokenAmount.mul(devFeePercentage.numerator).div(devFeePercentage.denominator)
|
||||
);
|
||||
|
@ -316,7 +317,7 @@ describe("whirlpool-dev-fee-swap", () => {
|
|||
});
|
||||
|
||||
const devFeePercentage = Percentage.fromFraction(500000, 1000000); // 50%
|
||||
const inputTokenAmount = new u64(119500000);
|
||||
const inputTokenAmount = new BN(119500000);
|
||||
const postFeeTokenAmount = inputTokenAmount.sub(
|
||||
inputTokenAmount.mul(devFeePercentage.numerator).div(devFeePercentage.denominator)
|
||||
);
|
||||
|
@ -370,7 +371,7 @@ describe("whirlpool-dev-fee-swap", () => {
|
|||
});
|
||||
|
||||
const devFeePercentage = Percentage.fromFraction(100, 100); // 100%
|
||||
const inputTokenAmount = new u64(119500000);
|
||||
const inputTokenAmount = new BN(119500000);
|
||||
const whirlpoolData = await whirlpool.refreshData();
|
||||
const swapToken = whirlpoolData.tokenMintB;
|
||||
|
||||
|
@ -410,7 +411,7 @@ describe("whirlpool-dev-fee-swap", () => {
|
|||
});
|
||||
|
||||
const devFeePercentage = Percentage.fromFraction(200, 100); // 200%
|
||||
const inputTokenAmount = new u64(119500000);
|
||||
const inputTokenAmount = new BN(119500000);
|
||||
const whirlpoolData = await whirlpool.refreshData();
|
||||
const swapToken = whirlpoolData.tokenMintB;
|
||||
|
||||
|
@ -435,8 +436,8 @@ async function getQuotes(
|
|||
ctx: WhirlpoolContext,
|
||||
whirlpool: Whirlpool,
|
||||
swapToken: Address,
|
||||
inputTokenAmount: u64,
|
||||
postFeeTokenAmount: u64,
|
||||
inputTokenAmount: BN,
|
||||
postFeeTokenAmount: BN,
|
||||
slippageTolerance: Percentage,
|
||||
devFeePercentage: Percentage
|
||||
) {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { Percentage } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import * as assert from "assert";
|
||||
import { BN } from "bn.js";
|
||||
import {
|
||||
|
@ -65,7 +64,7 @@ describe("swap traversal tests", () => {
|
|||
const inputTokenQuote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintA,
|
||||
new u64(150000),
|
||||
new BN(150000),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -128,7 +127,7 @@ describe("swap traversal tests", () => {
|
|||
const inputTokenQuote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintB,
|
||||
new u64(190000000),
|
||||
new BN(190000000),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -187,7 +186,7 @@ describe("swap traversal tests", () => {
|
|||
const inputTokenQuote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintA,
|
||||
new u64(200000000),
|
||||
new BN(200000000),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -245,7 +244,7 @@ describe("swap traversal tests", () => {
|
|||
const inputTokenQuote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintB,
|
||||
new u64(450000000),
|
||||
new BN(450000000),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -306,7 +305,7 @@ describe("swap traversal tests", () => {
|
|||
const inputTokenQuote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintB,
|
||||
new u64(150000000),
|
||||
new BN(150000000),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -364,7 +363,7 @@ describe("swap traversal tests", () => {
|
|||
const inputTokenQuote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintA,
|
||||
new u64(75000000),
|
||||
new BN(75000000),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -422,7 +421,7 @@ describe("swap traversal tests", () => {
|
|||
const inputTokenQuote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintB,
|
||||
new u64(15000000),
|
||||
new BN(15000000),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -480,7 +479,7 @@ describe("swap traversal tests", () => {
|
|||
const inputTokenQuote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintA,
|
||||
new u64(7500000),
|
||||
new BN(7500000),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -538,7 +537,7 @@ describe("swap traversal tests", () => {
|
|||
const inputTokenQuote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintA,
|
||||
new u64(45000000),
|
||||
new BN(45000000),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -596,7 +595,7 @@ describe("swap traversal tests", () => {
|
|||
const inputTokenQuote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintB,
|
||||
new u64(49500000),
|
||||
new BN(49500000),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -647,7 +646,7 @@ describe("swap traversal tests", () => {
|
|||
const inputTokenQuote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintA,
|
||||
new u64(119500000),
|
||||
new BN(119500000),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -698,7 +697,7 @@ describe("swap traversal tests", () => {
|
|||
const inputTokenQuote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintB,
|
||||
new u64(119500000),
|
||||
new BN(119500000),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -749,7 +748,7 @@ describe("swap traversal tests", () => {
|
|||
const inputTokenQuote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintA,
|
||||
new u64(119500000),
|
||||
new BN(119500000),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -800,7 +799,7 @@ describe("swap traversal tests", () => {
|
|||
const inputTokenQuote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintB,
|
||||
new u64(159500000),
|
||||
new BN(159500000),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -881,7 +880,7 @@ describe("swap traversal tests", () => {
|
|||
const inputTokenQuote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintA,
|
||||
new u64(102195000),
|
||||
new BN(102195000),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -961,7 +960,7 @@ describe("swap traversal tests", () => {
|
|||
const inputTokenQuote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintB,
|
||||
new u64(99900000),
|
||||
new BN(99900000),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -1013,7 +1012,7 @@ describe("swap traversal tests", () => {
|
|||
await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintB,
|
||||
new u64(9159500000),
|
||||
new BN(9159500000),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -1061,7 +1060,7 @@ describe("swap traversal tests", () => {
|
|||
await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintA,
|
||||
new u64(9159500000),
|
||||
new BN(9159500000),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -1109,7 +1108,7 @@ describe("swap traversal tests", () => {
|
|||
const quote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintB,
|
||||
new u64("12595000000000"),
|
||||
new BN("12595000000000"),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -1151,7 +1150,7 @@ describe("swap traversal tests", () => {
|
|||
const quote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintA,
|
||||
new u64("12595000000000"),
|
||||
new BN("12595000000000"),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -1194,7 +1193,7 @@ describe("swap traversal tests", () => {
|
|||
const inputTokenQuote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintB,
|
||||
new u64(200000000),
|
||||
new BN(200000000),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -1250,7 +1249,7 @@ describe("swap traversal tests", () => {
|
|||
const inputTokenQuote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintB,
|
||||
new u64(200000000),
|
||||
new BN(200000000),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -1306,7 +1305,7 @@ describe("swap traversal tests", () => {
|
|||
const inputTokenQuote = await swapQuoteByInputToken(
|
||||
whirlpool,
|
||||
whirlpoolData.tokenMintB,
|
||||
new u64(200000000),
|
||||
new BN(200000000),
|
||||
slippageTolerance,
|
||||
ctx.program.programId,
|
||||
fetcher,
|
||||
|
@ -1372,7 +1371,7 @@ describe("swap traversal tests", () => {
|
|||
{
|
||||
aToB,
|
||||
amountSpecifiedIsInput: true,
|
||||
tokenAmount: new u64("10000"),
|
||||
tokenAmount: new BN("10000"),
|
||||
whirlpoolData,
|
||||
tickArrays,
|
||||
sqrtPriceLimit: new BN(MIN_SQRT_PRICE).subn(1),
|
||||
|
@ -1424,7 +1423,7 @@ describe("swap traversal tests", () => {
|
|||
{
|
||||
aToB,
|
||||
amountSpecifiedIsInput: true,
|
||||
tokenAmount: new u64("10000"),
|
||||
tokenAmount: new BN("10000"),
|
||||
whirlpoolData,
|
||||
tickArrays,
|
||||
sqrtPriceLimit: new BN(MAX_SQRT_PRICE).addn(1),
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { deriveATA, MathUtil, Percentage } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { MathUtil, Percentage } from "@orca-so/common-sdk";
|
||||
import { Account, getAssociatedTokenAddressSync } from "@solana/spl-token";
|
||||
import * as assert from "assert";
|
||||
import { BN } from "bn.js";
|
||||
import Decimal from "decimal.js";
|
||||
import {
|
||||
buildWhirlpoolClient,
|
||||
collectFeesQuote,
|
||||
collectRewardsQuote,
|
||||
decreaseLiquidityQuoteByLiquidity,
|
||||
NUM_REWARDS,
|
||||
PDAUtil, Whirlpool,
|
||||
WhirlpoolClient,
|
||||
WhirlpoolContext
|
||||
WhirlpoolContext,
|
||||
buildWhirlpoolClient,
|
||||
collectFeesQuote,
|
||||
collectRewardsQuote,
|
||||
decreaseLiquidityQuoteByLiquidity
|
||||
} from "../../../src";
|
||||
import { createAssociatedTokenAccount, sleep, TickSpacing, transfer, ZERO_BN } from "../../utils";
|
||||
import { TickSpacing, ZERO_BN, createAssociatedTokenAccount, sleep, transferToken } from "../../utils";
|
||||
import { defaultConfirmOptions } from "../../utils/const";
|
||||
import { WhirlpoolTestFixture } from "../../utils/fixture";
|
||||
|
||||
|
@ -30,7 +31,7 @@ describe("WhirlpoolImpl#closePosition()", () => {
|
|||
const tickUpperIndex = 33536;
|
||||
const vaultStartBalance = 1_000_000;
|
||||
const tickSpacing = TickSpacing.Standard;
|
||||
const liquidityAmount = new u64(10_000_000);
|
||||
const liquidityAmount = new BN(10_000_000);
|
||||
|
||||
before(() => {
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
@ -58,7 +59,7 @@ describe("WhirlpoolImpl#closePosition()", () => {
|
|||
// Accrue fees in token A
|
||||
const pool = await whirlpoolClient.getPool(whirlpoolPda.publicKey, true);
|
||||
await (await pool.swap({
|
||||
amount: new u64(200_000),
|
||||
amount: new BN(200_000),
|
||||
amountSpecifiedIsInput: true,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(4)),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
|
@ -70,7 +71,7 @@ describe("WhirlpoolImpl#closePosition()", () => {
|
|||
|
||||
// Accrue fees in token B
|
||||
await (await pool.swap({
|
||||
amount: new u64(200_000),
|
||||
amount: new BN(200_000),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(5)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -162,8 +163,8 @@ describe("WhirlpoolImpl#closePosition()", () => {
|
|||
tickLower: position.getLowerTickData(),
|
||||
tickUpper: position.getUpperTickData(),
|
||||
});
|
||||
const accountAPubkey = await deriveATA(otherWallet.publicKey, poolInitInfo.tokenMintA);
|
||||
const accountA = await ctx.fetcher.getTokenInfo(accountAPubkey, true);
|
||||
const accountAPubkey = getAssociatedTokenAddressSync(poolInitInfo.tokenMintA, otherWallet.publicKey);
|
||||
const accountA = (await ctx.fetcher.getTokenInfo(accountAPubkey, true)) as Account;
|
||||
const expectAmountA = liquidityCollectedQuote.tokenMinA.add(feeQuote.feeOwedA);
|
||||
if (isWSOLTest) {
|
||||
// If this is a WSOL test, we have to account for account rent retrieval
|
||||
|
@ -171,13 +172,13 @@ describe("WhirlpoolImpl#closePosition()", () => {
|
|||
const minAccountExempt = await ctx.fetcher.getAccountRentExempt();
|
||||
const expectedReceivedSol = liquidityCollectedQuote.tokenMinA
|
||||
.add(feeQuote.feeOwedA)
|
||||
.add(new u64(positionAccountBalance))
|
||||
.add(new u64(minAccountExempt))
|
||||
.add(new u64(minAccountExempt))
|
||||
.add(new BN(positionAccountBalance))
|
||||
.add(new BN(minAccountExempt))
|
||||
.add(new BN(minAccountExempt))
|
||||
.toNumber();
|
||||
assert.equal(solInOtherWallet, expectedReceivedSol);
|
||||
} else if (expectAmountA.isZero()) {
|
||||
assert.ok(!accountA || accountA.amount.isZero());
|
||||
assert.ok(!accountA || accountA.amount === 0n);
|
||||
} else {
|
||||
assert.equal(
|
||||
accountA?.amount.toString(),
|
||||
|
@ -185,11 +186,11 @@ describe("WhirlpoolImpl#closePosition()", () => {
|
|||
);
|
||||
}
|
||||
|
||||
const accountBPubkey = await deriveATA(otherWallet.publicKey, poolInitInfo.tokenMintB);
|
||||
const accountBPubkey = getAssociatedTokenAddressSync(poolInitInfo.tokenMintB, otherWallet.publicKey);
|
||||
const accountB = await ctx.fetcher.getTokenInfo(accountBPubkey, true);
|
||||
const expectAmountB = liquidityCollectedQuote.tokenMinB.add(feeQuote.feeOwedB);
|
||||
if (expectAmountB.isZero()) {
|
||||
assert.ok(!accountB || accountB.amount.isZero());
|
||||
assert.ok(!accountB || accountB.amount === 0n);
|
||||
} else {
|
||||
assert.equal(
|
||||
accountB?.amount.toString(),
|
||||
|
@ -208,7 +209,7 @@ describe("WhirlpoolImpl#closePosition()", () => {
|
|||
});
|
||||
for (let i = 0; i < NUM_REWARDS; i++) {
|
||||
if (!!rewards[i]) {
|
||||
const rewardATA = await deriveATA(otherWallet.publicKey, rewards[i].rewardMint);
|
||||
const rewardATA = getAssociatedTokenAddressSync(rewards[i].rewardMint, otherWallet.publicKey);
|
||||
const rewardTokenAccount = await ctx.fetcher.getTokenInfo(rewardATA, true);
|
||||
assert.equal(rewardTokenAccount?.amount.toString(), rewardQuote[i]?.toString());
|
||||
}
|
||||
|
@ -261,15 +262,15 @@ describe("WhirlpoolImpl#closePosition()", () => {
|
|||
rewards: [
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
@ -304,15 +305,15 @@ describe("WhirlpoolImpl#closePosition()", () => {
|
|||
rewards: [
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
@ -333,15 +334,15 @@ describe("WhirlpoolImpl#closePosition()", () => {
|
|||
rewards: [
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
@ -360,15 +361,15 @@ describe("WhirlpoolImpl#closePosition()", () => {
|
|||
rewards: [
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
@ -387,15 +388,15 @@ describe("WhirlpoolImpl#closePosition()", () => {
|
|||
rewards: [
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
@ -405,9 +406,9 @@ describe("WhirlpoolImpl#closePosition()", () => {
|
|||
|
||||
const position = await testCtx.whirlpoolClient.getPosition(positionData.publicKey, true);
|
||||
|
||||
const walletPositionTokenAccount = await deriveATA(
|
||||
const walletPositionTokenAccount = getAssociatedTokenAddressSync(
|
||||
positionData.mintKeypair.publicKey,
|
||||
testCtx.whirlpoolCtx.wallet.publicKey,
|
||||
positionData.mintKeypair.publicKey
|
||||
);
|
||||
|
||||
const newOwnerPositionTokenAccount = await createAssociatedTokenAccount(
|
||||
|
@ -418,7 +419,7 @@ describe("WhirlpoolImpl#closePosition()", () => {
|
|||
);
|
||||
|
||||
await accrueFeesAndRewards(fixture);
|
||||
await transfer(testCtx.provider, walletPositionTokenAccount, newOwnerPositionTokenAccount, 1);
|
||||
await transferToken(testCtx.provider, walletPositionTokenAccount, newOwnerPositionTokenAccount, 1);
|
||||
|
||||
const { poolInitInfo } = fixture.getInfos();
|
||||
|
||||
|
@ -461,15 +462,15 @@ describe("WhirlpoolImpl#closePosition()", () => {
|
|||
rewards: [
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
],
|
||||
tokenAIsNative: true,
|
||||
|
@ -489,15 +490,15 @@ describe("WhirlpoolImpl#closePosition()", () => {
|
|||
rewards: [
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
],
|
||||
tokenAIsNative: true,
|
||||
|
@ -508,9 +509,9 @@ describe("WhirlpoolImpl#closePosition()", () => {
|
|||
|
||||
const position = await testCtx.whirlpoolClient.getPosition(positionData.publicKey, true);
|
||||
|
||||
const walletPositionTokenAccount = await deriveATA(
|
||||
const walletPositionTokenAccount = getAssociatedTokenAddressSync(
|
||||
positionData.mintKeypair.publicKey,
|
||||
testCtx.whirlpoolCtx.wallet.publicKey,
|
||||
positionData.mintKeypair.publicKey
|
||||
);
|
||||
|
||||
const newOwnerPositionTokenAccount = await createAssociatedTokenAccount(
|
||||
|
@ -521,7 +522,7 @@ describe("WhirlpoolImpl#closePosition()", () => {
|
|||
);
|
||||
|
||||
await accrueFeesAndRewards(fixture);
|
||||
await transfer(testCtx.provider, walletPositionTokenAccount, newOwnerPositionTokenAccount, 1);
|
||||
await transferToken(testCtx.provider, walletPositionTokenAccount, newOwnerPositionTokenAccount, 1);
|
||||
|
||||
const { poolInitInfo } = fixture.getInfos();
|
||||
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { deriveATA, MathUtil, SendTxRequest, TransactionBuilder, TransactionProcessor, ZERO } from "@orca-so/common-sdk";
|
||||
import { ASSOCIATED_TOKEN_PROGRAM_ID, NATIVE_MINT, Token, TOKEN_PROGRAM_ID, u64 } from "@solana/spl-token";
|
||||
import { MathUtil, SendTxRequest, TransactionBuilder, TransactionProcessor, ZERO } from "@orca-so/common-sdk";
|
||||
import { NATIVE_MINT, createAssociatedTokenAccountInstruction, createBurnInstruction, createCloseAccountInstruction, getAssociatedTokenAddressSync } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import * as assert from "assert";
|
||||
import { BN } from "bn.js";
|
||||
import Decimal from "decimal.js";
|
||||
import {
|
||||
buildWhirlpoolClient,
|
||||
collectFeesQuote,
|
||||
collectRewardsQuote,
|
||||
NUM_REWARDS,
|
||||
PDAUtil,
|
||||
PoolUtil,
|
||||
toTx,
|
||||
Whirlpool,
|
||||
WhirlpoolClient,
|
||||
WhirlpoolContext,
|
||||
WhirlpoolIx
|
||||
WhirlpoolIx,
|
||||
buildWhirlpoolClient,
|
||||
collectFeesQuote,
|
||||
collectRewardsQuote,
|
||||
toTx
|
||||
} from "../../../src";
|
||||
import { TickSpacing, ZERO_BN } from "../../utils";
|
||||
import { defaultConfirmOptions } from "../../utils/const";
|
||||
|
@ -35,7 +36,7 @@ describe("WhirlpoolImpl#collectFeesAndRewardsForPositions()", () => {
|
|||
const tickUpperIndex = 33536;
|
||||
const tickSpacing = TickSpacing.Standard;
|
||||
const vaultStartBalance = 1_000_000;
|
||||
const liquidityAmount = new u64(10_000_000);
|
||||
const liquidityAmount = new BN(10_000_000);
|
||||
const sleep = (second: number) => new Promise(resolve => setTimeout(resolve, second * 1000))
|
||||
|
||||
before(() => {
|
||||
|
@ -78,7 +79,7 @@ describe("WhirlpoolImpl#collectFeesAndRewardsForPositions()", () => {
|
|||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(200_000),
|
||||
amount: new BN(200_000),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(4)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -100,7 +101,7 @@ describe("WhirlpoolImpl#collectFeesAndRewardsForPositions()", () => {
|
|||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(200_000),
|
||||
amount: new BN(200_000),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(5)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -168,15 +169,15 @@ describe("WhirlpoolImpl#collectFeesAndRewardsForPositions()", () => {
|
|||
|
||||
const mintA = pool.getTokenAInfo().mint;
|
||||
const mintB = pool.getTokenBInfo().mint;
|
||||
const ataA = await deriveATA(ctx.wallet.publicKey, mintA);
|
||||
const ataB = await deriveATA(ctx.wallet.publicKey, mintB);
|
||||
const ataA = getAssociatedTokenAddressSync(mintA, ctx.wallet.publicKey);
|
||||
const ataB = getAssociatedTokenAddressSync(mintB, ctx.wallet.publicKey);
|
||||
await burnAndCloseATA(ctx, ataA);
|
||||
await burnAndCloseATA(ctx, ataB);
|
||||
|
||||
for (let i = 0; i < NUM_REWARDS; i++) {
|
||||
if (PoolUtil.isRewardInitialized(pool.getRewardInfos()[i])) {
|
||||
const mintReward = pool.getRewardInfos()[i].mint;
|
||||
const ataReward = await deriveATA(ctx.wallet.publicKey, mintReward);
|
||||
const ataReward = getAssociatedTokenAddressSync(mintReward, ctx.wallet.publicKey);
|
||||
await burnAndCloseATA(ctx, ataReward);
|
||||
}
|
||||
}
|
||||
|
@ -186,22 +187,8 @@ describe("WhirlpoolImpl#collectFeesAndRewardsForPositions()", () => {
|
|||
const account = await ctx.fetcher.getTokenInfo(ata, true);
|
||||
if (account === null) return;
|
||||
|
||||
const burnIx = Token.createBurnInstruction(
|
||||
TOKEN_PROGRAM_ID,
|
||||
account.mint,
|
||||
ata,
|
||||
ctx.wallet.publicKey,
|
||||
[],
|
||||
account.amount
|
||||
);
|
||||
|
||||
const closeIx = Token.createCloseAccountInstruction(
|
||||
TOKEN_PROGRAM_ID,
|
||||
ata,
|
||||
ctx.wallet.publicKey,
|
||||
ctx.wallet.publicKey,
|
||||
[]
|
||||
);
|
||||
const burnIx = createBurnInstruction(ata, account.mint, ctx.wallet.publicKey, account.amount);
|
||||
const closeIx = createCloseAccountInstruction(ata, ctx.wallet.publicKey, ctx.wallet.publicKey, []);
|
||||
|
||||
const tx = new TransactionBuilder(ctx.connection, ctx.wallet, ctx.txBuilderOpts);
|
||||
tx.addInstruction({
|
||||
|
@ -221,15 +208,15 @@ describe("WhirlpoolImpl#collectFeesAndRewardsForPositions()", () => {
|
|||
|
||||
const mintA = pool.getTokenAInfo().mint;
|
||||
const mintB = pool.getTokenBInfo().mint;
|
||||
const ataA = await deriveATA(ctx.wallet.publicKey, mintA);
|
||||
const ataB = await deriveATA(ctx.wallet.publicKey, mintB);
|
||||
const ataA = getAssociatedTokenAddressSync(mintA, ctx.wallet.publicKey);
|
||||
const ataB = getAssociatedTokenAddressSync(mintB, ctx.wallet.publicKey);
|
||||
await createATA(ctx, ataA, mintA);
|
||||
await createATA(ctx, ataB, mintB);
|
||||
|
||||
for (let i = 0; i < NUM_REWARDS; i++) {
|
||||
if (PoolUtil.isRewardInitialized(pool.getRewardInfos()[i])) {
|
||||
const mintReward = pool.getRewardInfos()[i].mint;
|
||||
const ataReward = await deriveATA(ctx.wallet.publicKey, mintReward);
|
||||
const ataReward = getAssociatedTokenAddressSync(mintReward, ctx.wallet.publicKey);
|
||||
await createATA(ctx, ataReward, mintReward);
|
||||
}
|
||||
}
|
||||
|
@ -240,14 +227,11 @@ describe("WhirlpoolImpl#collectFeesAndRewardsForPositions()", () => {
|
|||
|
||||
const account = await ctx.fetcher.getTokenInfo(ata, true);
|
||||
if (account !== null) return;
|
||||
|
||||
const createATAIx = Token.createAssociatedTokenAccountInstruction(
|
||||
ASSOCIATED_TOKEN_PROGRAM_ID,
|
||||
TOKEN_PROGRAM_ID,
|
||||
mint,
|
||||
const createATAIx = createAssociatedTokenAccountInstruction(
|
||||
ctx.wallet.publicKey,
|
||||
ata,
|
||||
ctx.wallet.publicKey,
|
||||
ctx.wallet.publicKey
|
||||
mint,
|
||||
);
|
||||
|
||||
const tx = new TransactionBuilder(ctx.connection, ctx.wallet, ctx.txBuilderOpts);
|
||||
|
@ -277,15 +261,15 @@ describe("WhirlpoolImpl#collectFeesAndRewardsForPositions()", () => {
|
|||
rewards: [
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
|
|
@ -1,29 +1,30 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { deriveATA, MathUtil, Percentage, TransactionBuilder } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { MathUtil, Percentage, TransactionBuilder } from "@orca-so/common-sdk";
|
||||
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
|
||||
import * as assert from "assert";
|
||||
import { BN } from "bn.js";
|
||||
import Decimal from "decimal.js";
|
||||
import {
|
||||
PDAUtil,
|
||||
PriceMath, TickUtil,
|
||||
WhirlpoolIx,
|
||||
buildWhirlpoolClient,
|
||||
collectFeesQuote,
|
||||
collectRewardsQuote,
|
||||
decreaseLiquidityQuoteByLiquidity,
|
||||
increaseLiquidityQuoteByInputToken,
|
||||
PDAUtil,
|
||||
PriceMath, TickUtil,
|
||||
toTx,
|
||||
WhirlpoolIx
|
||||
toTx
|
||||
} from "../../../src";
|
||||
import { WhirlpoolContext } from "../../../src/context";
|
||||
import {
|
||||
ONE_SOL,
|
||||
TickSpacing,
|
||||
ZERO_BN,
|
||||
createAssociatedTokenAccount,
|
||||
getTokenBalance,
|
||||
ONE_SOL,
|
||||
sleep,
|
||||
systemTransferTx,
|
||||
TickSpacing,
|
||||
transfer,
|
||||
ZERO_BN
|
||||
transferToken
|
||||
} from "../../utils";
|
||||
import { defaultConfirmOptions } from "../../utils/const";
|
||||
import { WhirlpoolTestFixture } from "../../utils/fixture";
|
||||
|
@ -241,14 +242,14 @@ describe("whirlpool-impl", () => {
|
|||
|
||||
// Transfer the position token to another wallet
|
||||
const otherWallet = anchor.web3.Keypair.generate();
|
||||
const walletPositionTokenAccount = await deriveATA(ctx.wallet.publicKey, positionMint);
|
||||
const walletPositionTokenAccount = getAssociatedTokenAddressSync(positionMint, ctx.wallet.publicKey);
|
||||
const newOwnerPositionTokenAccount = await createAssociatedTokenAccount(
|
||||
ctx.provider,
|
||||
positionMint,
|
||||
otherWallet.publicKey,
|
||||
ctx.wallet.publicKey
|
||||
);
|
||||
await transfer(provider, walletPositionTokenAccount, newOwnerPositionTokenAccount, 1);
|
||||
await transferToken(provider, walletPositionTokenAccount, newOwnerPositionTokenAccount, 1);
|
||||
|
||||
// [Action] Close Position
|
||||
const expectationQuote = await decreaseLiquidityQuoteByLiquidity(
|
||||
|
@ -286,8 +287,8 @@ describe("whirlpool-impl", () => {
|
|||
const postClosePosition = await fetcher.getPosition(positionAddress, true);
|
||||
assert.ok(postClosePosition === null);
|
||||
|
||||
const dWalletTokenAAccount = await deriveATA(destinationWallet.publicKey, poolData.tokenMintA);
|
||||
const dWalletTokenBAccount = await deriveATA(destinationWallet.publicKey, poolData.tokenMintB);
|
||||
const dWalletTokenAAccount = getAssociatedTokenAddressSync(poolData.tokenMintA, destinationWallet.publicKey,);
|
||||
const dWalletTokenBAccount = getAssociatedTokenAddressSync(poolData.tokenMintB, destinationWallet.publicKey);
|
||||
|
||||
assert.equal(
|
||||
await getTokenBalance(ctx.provider, dWalletTokenAAccount),
|
||||
|
@ -314,15 +315,15 @@ describe("whirlpool-impl", () => {
|
|||
rewards: [
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(5)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
@ -340,7 +341,7 @@ describe("whirlpool-impl", () => {
|
|||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(200_000),
|
||||
amount: new BN(200_000),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(4)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -362,7 +363,7 @@ describe("whirlpool-impl", () => {
|
|||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(200_000),
|
||||
amount: new BN(200_000),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(5)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -388,9 +389,9 @@ describe("whirlpool-impl", () => {
|
|||
|
||||
// Transfer the position token to another wallet
|
||||
const otherWallet = anchor.web3.Keypair.generate();
|
||||
const walletPositionTokenAccount = await deriveATA(
|
||||
const walletPositionTokenAccount = getAssociatedTokenAddressSync(
|
||||
positionWithFees.mintKeypair.publicKey,
|
||||
ctx.wallet.publicKey,
|
||||
positionWithFees.mintKeypair.publicKey
|
||||
);
|
||||
|
||||
const newOwnerPositionTokenAccount = await createAssociatedTokenAccount(
|
||||
|
@ -400,7 +401,7 @@ describe("whirlpool-impl", () => {
|
|||
ctx.wallet.publicKey
|
||||
);
|
||||
|
||||
await transfer(provider, walletPositionTokenAccount, newOwnerPositionTokenAccount, 1);
|
||||
await transferToken(provider, walletPositionTokenAccount, newOwnerPositionTokenAccount, 1);
|
||||
|
||||
const pool = await client.getPool(whirlpoolPda.publicKey, true);
|
||||
const position = await client.getPosition(positionWithFees.publicKey, true);
|
||||
|
@ -408,7 +409,7 @@ describe("whirlpool-impl", () => {
|
|||
const poolData = pool.getData();
|
||||
const txs = await pool.closePosition(
|
||||
positionWithFees.publicKey,
|
||||
new Percentage(new u64(10), new u64(100)),
|
||||
new Percentage(new BN(10), new BN(100)),
|
||||
otherWallet.publicKey,
|
||||
otherWallet.publicKey,
|
||||
ctx.wallet.publicKey
|
||||
|
@ -421,11 +422,11 @@ describe("whirlpool-impl", () => {
|
|||
pool
|
||||
);
|
||||
|
||||
const dWalletTokenAAccount = await deriveATA(otherWallet.publicKey, poolData.tokenMintA);
|
||||
const dWalletTokenBAccount = await deriveATA(otherWallet.publicKey, poolData.tokenMintB);
|
||||
const rewardAccount0 = await deriveATA(otherWallet.publicKey, poolData.rewardInfos[0].mint);
|
||||
const rewardAccount1 = await deriveATA(otherWallet.publicKey, poolData.rewardInfos[1].mint);
|
||||
const rewardAccount2 = await deriveATA(otherWallet.publicKey, poolData.rewardInfos[2].mint);
|
||||
const dWalletTokenAAccount = getAssociatedTokenAddressSync(poolData.tokenMintA, otherWallet.publicKey,);
|
||||
const dWalletTokenBAccount = getAssociatedTokenAddressSync(poolData.tokenMintB, otherWallet.publicKey,);
|
||||
const rewardAccount0 = getAssociatedTokenAddressSync(poolData.rewardInfos[0].mint, otherWallet.publicKey,);
|
||||
const rewardAccount1 = getAssociatedTokenAddressSync(poolData.rewardInfos[1].mint, otherWallet.publicKey,);
|
||||
const rewardAccount2 = getAssociatedTokenAddressSync(poolData.rewardInfos[2].mint, otherWallet.publicKey,);
|
||||
|
||||
const feesQuote = collectFeesQuote({
|
||||
whirlpool: poolData,
|
||||
|
@ -493,15 +494,15 @@ describe("whirlpool-impl", () => {
|
|||
rewards: [
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
{
|
||||
emissionsPerSecondX64: MathUtil.toX64(new Decimal(10)),
|
||||
vaultAmount: new u64(vaultStartBalance),
|
||||
vaultAmount: new BN(vaultStartBalance),
|
||||
},
|
||||
],
|
||||
tokenAIsNative: true,
|
||||
|
@ -520,7 +521,7 @@ describe("whirlpool-impl", () => {
|
|||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(200_000_00),
|
||||
amount: new BN(200_000_00),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(4)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -542,7 +543,7 @@ describe("whirlpool-impl", () => {
|
|||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: new u64(200_000_00),
|
||||
amount: new BN(200_000_00),
|
||||
otherAmountThreshold: ZERO_BN,
|
||||
sqrtPriceLimit: MathUtil.toX64(new Decimal(5)),
|
||||
amountSpecifiedIsInput: true,
|
||||
|
@ -568,9 +569,9 @@ describe("whirlpool-impl", () => {
|
|||
|
||||
// Transfer the position token to another wallet
|
||||
const otherWallet = anchor.web3.Keypair.generate();
|
||||
const walletPositionTokenAccount = await deriveATA(
|
||||
const walletPositionTokenAccount = getAssociatedTokenAddressSync(
|
||||
positionWithFees.mintKeypair.publicKey,
|
||||
ctx.wallet.publicKey,
|
||||
positionWithFees.mintKeypair.publicKey
|
||||
);
|
||||
|
||||
const newOwnerPositionTokenAccount = await createAssociatedTokenAccount(
|
||||
|
@ -580,7 +581,7 @@ describe("whirlpool-impl", () => {
|
|||
ctx.wallet.publicKey
|
||||
);
|
||||
|
||||
await transfer(provider, walletPositionTokenAccount, newOwnerPositionTokenAccount, 1);
|
||||
await transferToken(provider, walletPositionTokenAccount, newOwnerPositionTokenAccount, 1);
|
||||
|
||||
const pool = await client.getPool(whirlpoolPda.publicKey, true);
|
||||
const position = await client.getPosition(positionWithFees.publicKey, true);
|
||||
|
@ -601,14 +602,14 @@ describe("whirlpool-impl", () => {
|
|||
tickUpper: position.getUpperTickData(),
|
||||
});
|
||||
|
||||
const dWalletTokenBAccount = await deriveATA(otherWallet.publicKey, poolData.tokenMintB);
|
||||
const rewardAccount0 = await deriveATA(otherWallet.publicKey, poolData.rewardInfos[0].mint);
|
||||
const rewardAccount1 = await deriveATA(otherWallet.publicKey, poolData.rewardInfos[1].mint);
|
||||
const rewardAccount2 = await deriveATA(otherWallet.publicKey, poolData.rewardInfos[2].mint);
|
||||
const dWalletTokenBAccount = getAssociatedTokenAddressSync(poolData.tokenMintB, otherWallet.publicKey,);
|
||||
const rewardAccount0 = getAssociatedTokenAddressSync(poolData.rewardInfos[0].mint, otherWallet.publicKey,);
|
||||
const rewardAccount1 = getAssociatedTokenAddressSync(poolData.rewardInfos[1].mint, otherWallet.publicKey,);
|
||||
const rewardAccount2 = getAssociatedTokenAddressSync(poolData.rewardInfos[2].mint, otherWallet.publicKey,);
|
||||
|
||||
const txs = await pool.closePosition(
|
||||
positionWithFees.publicKey,
|
||||
new Percentage(new u64(10), new u64(100)),
|
||||
new Percentage(new BN(10), new BN(100)),
|
||||
otherWallet.publicKey,
|
||||
otherWallet.publicKey,
|
||||
ctx.wallet.publicKey
|
||||
|
@ -665,9 +666,9 @@ describe("whirlpool-impl", () => {
|
|||
*/
|
||||
const expectedtokenA = decreaseLiquidityQuote.tokenMinA
|
||||
.add(feesQuote.feeOwedA)
|
||||
.add(new u64(positionAccountBalance))
|
||||
.add(new u64(minAccountExempt))
|
||||
.add(new u64(minAccountExempt))
|
||||
.add(new BN(positionAccountBalance))
|
||||
.add(new BN(minAccountExempt))
|
||||
.add(new BN(minAccountExempt))
|
||||
.toNumber();
|
||||
assert.ok(solReceived === expectedtokenA);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { BN, Program, web3 } from "@coral-xyz/anchor";
|
||||
import { deriveATA, ONE } from "@orca-so/common-sdk";
|
||||
import { AccountLayout, NATIVE_MINT } from "@solana/spl-token";
|
||||
import { ONE } from "@orca-so/common-sdk";
|
||||
import { AccountLayout, NATIVE_MINT, getAssociatedTokenAddressSync } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import * as assert from "assert";
|
||||
import { SwapQuote, WhirlpoolContext } from "../../src";
|
||||
|
@ -98,7 +98,7 @@ export async function assertDevTokenAmount(
|
|||
return;
|
||||
}
|
||||
|
||||
const tokenDevWalletAta = await deriveATA(devWallet, swapToken);
|
||||
const tokenDevWalletAta = getAssociatedTokenAddressSync(swapToken, devWallet);
|
||||
const afterDevWalletAmount = await getTokenBalance(ctx.provider, tokenDevWalletAta);
|
||||
assert.equal(
|
||||
expectationQuote.devFeeAmount,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { BN } from "@coral-xyz/anchor";
|
||||
import { NATIVE_MINT, u64 } from "@solana/spl-token";
|
||||
import { NATIVE_MINT } from "@solana/spl-token";
|
||||
import { Keypair, PublicKey } from "@solana/web3.js";
|
||||
import { TickSpacing, ZERO_BN } from ".";
|
||||
import { InitConfigParams, InitPoolParams, TickUtil, WhirlpoolContext } from "../../src";
|
||||
|
@ -22,7 +22,7 @@ interface InitFixtureParams {
|
|||
|
||||
interface RewardParam {
|
||||
emissionsPerSecondX64: BN;
|
||||
vaultAmount: u64;
|
||||
vaultAmount: BN;
|
||||
}
|
||||
|
||||
interface InitializedRewardInfo {
|
||||
|
|
|
@ -1,41 +1,42 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { AddressUtil, deriveATA, MathUtil, PDA } from "@orca-so/common-sdk";
|
||||
import { NATIVE_MINT, u64 } from "@solana/spl-token";
|
||||
import { AddressUtil, MathUtil, PDA } from "@orca-so/common-sdk";
|
||||
import { NATIVE_MINT, getAssociatedTokenAddressSync } from "@solana/spl-token";
|
||||
import { Keypair, PublicKey } from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import Decimal from "decimal.js";
|
||||
import {
|
||||
TickSpacing,
|
||||
ZERO_BN,
|
||||
createAndMintToAssociatedTokenAccount,
|
||||
createMint,
|
||||
mintToByAuthority,
|
||||
TickSpacing,
|
||||
ZERO_BN
|
||||
mintToDestination
|
||||
} from ".";
|
||||
import {
|
||||
InitConfigParams,
|
||||
InitFeeTierParams,
|
||||
InitializeRewardParams,
|
||||
InitPoolParams,
|
||||
InitTickArrayParams,
|
||||
InitializeRewardParams,
|
||||
OpenPositionParams,
|
||||
PDAUtil,
|
||||
PriceMath,
|
||||
TICK_ARRAY_SIZE,
|
||||
TickUtil,
|
||||
toTx,
|
||||
WhirlpoolClient,
|
||||
WhirlpoolContext,
|
||||
WhirlpoolIx
|
||||
WhirlpoolIx,
|
||||
toTx
|
||||
} from "../../src";
|
||||
import { PoolUtil } from "../../src/utils/public/pool-utils";
|
||||
import {
|
||||
TestConfigParams,
|
||||
TestWhirlpoolsConfigKeypairs,
|
||||
generateDefaultConfigParams,
|
||||
generateDefaultInitFeeTierParams,
|
||||
generateDefaultInitPoolParams,
|
||||
generateDefaultInitTickArrayParams,
|
||||
generateDefaultOpenBundledPositionParams,
|
||||
generateDefaultOpenPositionParams,
|
||||
TestConfigParams,
|
||||
TestWhirlpoolsConfigKeypairs
|
||||
generateDefaultOpenPositionParams
|
||||
} from "./test-builders";
|
||||
|
||||
interface TestPoolParams {
|
||||
|
@ -443,14 +444,16 @@ export async function initRewardAndSetEmissions(
|
|||
rewardAuthorityKeypair: anchor.web3.Keypair,
|
||||
whirlpool: PublicKey,
|
||||
rewardIndex: number,
|
||||
vaultAmount: u64 | number,
|
||||
vaultAmount: BN | number,
|
||||
emissionsPerSecondX64: anchor.BN,
|
||||
funder?: Keypair
|
||||
) {
|
||||
const {
|
||||
params: { rewardMint, rewardVaultKeypair },
|
||||
} = await initializeReward(ctx, rewardAuthorityKeypair, whirlpool, rewardIndex, funder);
|
||||
await mintToByAuthority(ctx.provider, rewardMint, rewardVaultKeypair.publicKey, vaultAmount);
|
||||
|
||||
await mintToDestination(ctx.provider, rewardMint, rewardVaultKeypair.publicKey, vaultAmount);
|
||||
|
||||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.setRewardEmissionsIx(ctx.program, {
|
||||
|
@ -895,7 +898,7 @@ export async function initializePositionBundleWithMetadata(
|
|||
const positionBundleMintKeypair = Keypair.generate();
|
||||
const positionBundlePda = PDAUtil.getPositionBundle(ctx.program.programId, positionBundleMintKeypair.publicKey);
|
||||
const positionBundleMetadataPda = PDAUtil.getPositionBundleMetadata(positionBundleMintKeypair.publicKey);
|
||||
const positionBundleTokenAccount = await deriveATA(owner, positionBundleMintKeypair.publicKey);
|
||||
const positionBundleTokenAccount = getAssociatedTokenAddressSync(positionBundleMintKeypair.publicKey, owner);
|
||||
|
||||
const tx = toTx(ctx, WhirlpoolIx.initializePositionBundleWithMetadataIx(
|
||||
ctx.program,
|
||||
|
@ -930,7 +933,7 @@ export async function initializePositionBundle(
|
|||
) {
|
||||
const positionBundleMintKeypair = Keypair.generate();
|
||||
const positionBundlePda = PDAUtil.getPositionBundle(ctx.program.programId, positionBundleMintKeypair.publicKey);
|
||||
const positionBundleTokenAccount = await deriveATA(owner, positionBundleMintKeypair.publicKey);
|
||||
const positionBundleTokenAccount = getAssociatedTokenAddressSync(positionBundleMintKeypair.publicKey, owner);
|
||||
|
||||
const tx = toTx(ctx, WhirlpoolIx.initializePositionBundleIx(
|
||||
ctx.program,
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { Percentage } from "@orca-so/common-sdk";
|
||||
import { NATIVE_MINT, u64 } from "@solana/spl-token";
|
||||
import { NATIVE_MINT } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import { TickSpacing } from ".";
|
||||
import { TICK_ARRAY_SIZE, Whirlpool, WhirlpoolClient, WhirlpoolContext } from "../../src";
|
||||
import {
|
||||
|
@ -21,7 +22,7 @@ export interface SwapTestPoolParams {
|
|||
}
|
||||
|
||||
export interface SwapTestSwapParams {
|
||||
swapAmount: u64;
|
||||
swapAmount: BN;
|
||||
aToB: boolean;
|
||||
amountSpecifiedIsInput: boolean;
|
||||
slippageTolerance: Percentage;
|
||||
|
|
|
@ -1,21 +1,20 @@
|
|||
import { AnchorProvider } from "@coral-xyz/anchor";
|
||||
import { AddressUtil, MathUtil, PDA, Percentage } from "@orca-so/common-sdk";
|
||||
import {
|
||||
ASSOCIATED_TOKEN_PROGRAM_ID, Token,
|
||||
TOKEN_PROGRAM_ID
|
||||
getAssociatedTokenAddressSync
|
||||
} from "@solana/spl-token";
|
||||
import { Keypair, PublicKey } from "@solana/web3.js";
|
||||
import Decimal from "decimal.js";
|
||||
import { createAndMintToAssociatedTokenAccount, createMint } from ".";
|
||||
import {
|
||||
increaseLiquidityQuoteByInputToken,
|
||||
InitConfigParams,
|
||||
InitFeeTierParams,
|
||||
InitPoolParams,
|
||||
InitTickArrayParams, OpenBundledPositionParams, OpenPositionParams, PDAUtil,
|
||||
PoolUtil,
|
||||
PriceMath,
|
||||
Whirlpool
|
||||
Whirlpool,
|
||||
increaseLiquidityQuoteByInputToken
|
||||
} from "../../src";
|
||||
import { WhirlpoolContext } from "../../src/context";
|
||||
|
||||
|
@ -148,12 +147,7 @@ export async function generateDefaultOpenPositionParams(
|
|||
|
||||
const metadataPda = PDAUtil.getPositionMetadata(positionMintKeypair.publicKey);
|
||||
|
||||
const positionTokenAccountAddress = await Token.getAssociatedTokenAddress(
|
||||
ASSOCIATED_TOKEN_PROGRAM_ID,
|
||||
TOKEN_PROGRAM_ID,
|
||||
positionMintKeypair.publicKey,
|
||||
owner
|
||||
);
|
||||
const positionTokenAccountAddress = getAssociatedTokenAddressSync(positionMintKeypair.publicKey, owner)
|
||||
|
||||
const params: Required<OpenPositionParams & { metadataPda: PDA }> = {
|
||||
funder: funder || context.wallet.publicKey,
|
||||
|
@ -264,12 +258,7 @@ export async function generateDefaultOpenBundledPositionParams(
|
|||
const bundledPositionPda = PDAUtil.getBundledPosition(context.program.programId, positionBundleMint, bundleIndex);
|
||||
const positionBundle = PDAUtil.getPositionBundle(context.program.programId, positionBundleMint).publicKey;
|
||||
|
||||
const positionBundleTokenAccount = await Token.getAssociatedTokenAddress(
|
||||
ASSOCIATED_TOKEN_PROGRAM_ID,
|
||||
TOKEN_PROGRAM_ID,
|
||||
positionBundleMint,
|
||||
owner
|
||||
);
|
||||
const positionBundleTokenAccount = getAssociatedTokenAddressSync(positionBundleMint, owner);
|
||||
|
||||
const params: Required<OpenBundledPositionParams> = {
|
||||
bundleIndex,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { TOKEN_PROGRAM_ID, u64 } from "@solana/spl-token";
|
||||
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { BN } from "bn.js";
|
||||
|
||||
export const TEST_TOKEN_PROGRAM_ID = new anchor.web3.PublicKey(TOKEN_PROGRAM_ID.toString());
|
||||
|
||||
|
@ -7,4 +8,4 @@ export const ZERO_BN = new anchor.BN(0);
|
|||
|
||||
export const ONE_SOL = 1000000000;
|
||||
|
||||
export const MAX_U64 = new u64(new anchor.BN(2).pow(new anchor.BN(64)).sub(new anchor.BN(1)).toString());
|
||||
export const MAX_U64 = new BN(new anchor.BN(2).pow(new anchor.BN(64)).sub(new anchor.BN(1)).toString());
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
import { AnchorProvider, BN, web3 } from "@coral-xyz/anchor";
|
||||
import { TransactionBuilder, deriveATA } from "@orca-so/common-sdk";
|
||||
import { createWSOLAccountInstructions } from "@orca-so/common-sdk/dist/helpers/token-instructions";
|
||||
import { TokenUtil, TransactionBuilder } from "@orca-so/common-sdk";
|
||||
import {
|
||||
ASSOCIATED_TOKEN_PROGRAM_ID,
|
||||
AccountLayout,
|
||||
AuthorityType,
|
||||
NATIVE_MINT,
|
||||
TOKEN_PROGRAM_ID,
|
||||
Token,
|
||||
u64
|
||||
createApproveInstruction,
|
||||
createAssociatedTokenAccountInstruction,
|
||||
createBurnInstruction,
|
||||
createInitializeAccount3Instruction,
|
||||
createInitializeMintInstruction,
|
||||
createMintToInstruction,
|
||||
createSetAuthorityInstruction,
|
||||
createTransferInstruction,
|
||||
getAssociatedTokenAddressSync
|
||||
} from "@solana/spl-token";
|
||||
import { TEST_TOKEN_PROGRAM_ID } from "./test-consts";
|
||||
|
||||
|
@ -43,7 +48,7 @@ export async function createMintInstructions(
|
|||
lamports: await provider.connection.getMinimumBalanceForRentExemption(82),
|
||||
programId: TEST_TOKEN_PROGRAM_ID,
|
||||
}),
|
||||
Token.createInitMintInstruction(TEST_TOKEN_PROGRAM_ID, mint, 0, authority, null),
|
||||
createInitializeMintInstruction(mint, 0, authority, null)
|
||||
];
|
||||
return instructions;
|
||||
}
|
||||
|
@ -66,15 +71,12 @@ export async function createAssociatedTokenAccount(
|
|||
owner: web3.PublicKey,
|
||||
payer: web3.PublicKey
|
||||
) {
|
||||
const ataAddress = await deriveATA(owner, mint);
|
||||
|
||||
const instr = Token.createAssociatedTokenAccountInstruction(
|
||||
ASSOCIATED_TOKEN_PROGRAM_ID,
|
||||
TOKEN_PROGRAM_ID,
|
||||
mint,
|
||||
const ataAddress = getAssociatedTokenAddressSync(mint, owner);
|
||||
const instr = createAssociatedTokenAccountInstruction(
|
||||
payer,
|
||||
ataAddress,
|
||||
owner,
|
||||
payer
|
||||
mint,
|
||||
);
|
||||
const tx = new web3.Transaction();
|
||||
tx.add(instr);
|
||||
|
@ -100,7 +102,7 @@ async function createTokenAccountInstrs(
|
|||
lamports,
|
||||
programId: TEST_TOKEN_PROGRAM_ID,
|
||||
}),
|
||||
Token.createInitAccountInstruction(TEST_TOKEN_PROGRAM_ID, mint, newAccountPubkey, owner),
|
||||
createInitializeAccount3Instruction(newAccountPubkey, mint, owner)
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -111,21 +113,20 @@ async function createTokenAccountInstrs(
|
|||
* @param destination Destination token account to receive tokens
|
||||
* @param amount Number of tokens to mint
|
||||
*/
|
||||
export async function mintToByAuthority(
|
||||
export async function mintToDestination(
|
||||
provider: AnchorProvider,
|
||||
mint: web3.PublicKey,
|
||||
destination: web3.PublicKey,
|
||||
amount: number | BN
|
||||
): Promise<string> {
|
||||
const tx = new web3.Transaction();
|
||||
const amountVal = amount instanceof BN ? BigInt(amount.toString()) : amount;
|
||||
tx.add(
|
||||
Token.createMintToInstruction(
|
||||
TOKEN_PROGRAM_ID,
|
||||
createMintToInstruction(
|
||||
mint,
|
||||
destination,
|
||||
provider.wallet.publicKey,
|
||||
[],
|
||||
amount
|
||||
amountVal
|
||||
)
|
||||
);
|
||||
return provider.sendAndConfirm(tx, [], { commitment: "confirmed" });
|
||||
|
@ -144,7 +145,7 @@ export async function createAndMintToTokenAccount(
|
|||
amount: number | BN
|
||||
): Promise<web3.PublicKey> {
|
||||
const tokenAccount = await createTokenAccount(provider, mint, provider.wallet.publicKey);
|
||||
await mintToByAuthority(provider, mint, tokenAccount, new u64(amount.toString()));
|
||||
await mintToDestination(provider, mint, tokenAccount, new BN(amount.toString()));
|
||||
return tokenAccount;
|
||||
}
|
||||
|
||||
|
@ -166,9 +167,9 @@ export async function createAndMintToAssociatedTokenAccount(
|
|||
"confirmed"
|
||||
);
|
||||
const txBuilder = new TransactionBuilder(provider.connection, provider.wallet);
|
||||
const { address: tokenAccount, ...ix } = createWSOLAccountInstructions(
|
||||
const { address: tokenAccount, ...ix } = TokenUtil.createWrappedNativeAccountInstruction(
|
||||
destinationWalletKey,
|
||||
new u64(amount.toString()),
|
||||
new BN(amount.toString()),
|
||||
rentExemption
|
||||
);
|
||||
txBuilder.addInstruction({ ...ix, cleanupInstructions: [] });
|
||||
|
@ -181,12 +182,12 @@ export async function createAndMintToAssociatedTokenAccount(
|
|||
});
|
||||
|
||||
let tokenAccount = tokenAccounts.value.map((account) => {
|
||||
if(account.account.data.parsed.info.mint === mint.toString()) {
|
||||
if (account.account.data.parsed.info.mint === mint.toString()) {
|
||||
return account.pubkey
|
||||
}
|
||||
}).filter(Boolean)[0];
|
||||
|
||||
if(!tokenAccount) {
|
||||
if (!tokenAccount) {
|
||||
tokenAccount = await createAssociatedTokenAccount(
|
||||
provider,
|
||||
mint,
|
||||
|
@ -195,8 +196,8 @@ export async function createAndMintToAssociatedTokenAccount(
|
|||
);
|
||||
}
|
||||
|
||||
await mintToByAuthority(provider, mint, tokenAccount, new u64(amount.toString()));
|
||||
return tokenAccount;
|
||||
await mintToDestination(provider, mint, tokenAccount!, new BN(amount.toString()));
|
||||
return tokenAccount!;
|
||||
}
|
||||
|
||||
export async function getTokenBalance(provider: AnchorProvider, vault: web3.PublicKey) {
|
||||
|
@ -207,19 +208,13 @@ export async function approveToken(
|
|||
provider: AnchorProvider,
|
||||
tokenAccount: web3.PublicKey,
|
||||
delegate: web3.PublicKey,
|
||||
amount: number | u64,
|
||||
amount: number | BN,
|
||||
owner?: web3.Keypair
|
||||
) {
|
||||
const tx = new web3.Transaction();
|
||||
const amountVal = amount instanceof BN ? BigInt(amount.toString()) : amount;
|
||||
tx.add(
|
||||
Token.createApproveInstruction(
|
||||
TOKEN_PROGRAM_ID,
|
||||
tokenAccount,
|
||||
delegate,
|
||||
owner?.publicKey || provider.wallet.publicKey,
|
||||
[],
|
||||
amount
|
||||
)
|
||||
createApproveInstruction(tokenAccount, delegate, owner?.publicKey || provider.wallet.publicKey, amountVal)
|
||||
);
|
||||
return provider.sendAndConfirm(tx, !!owner ? [owner] : [], { commitment: "confirmed" });
|
||||
}
|
||||
|
@ -233,20 +228,18 @@ export async function setAuthority(
|
|||
) {
|
||||
const tx = new web3.Transaction();
|
||||
tx.add(
|
||||
Token.createSetAuthorityInstruction(
|
||||
TOKEN_PROGRAM_ID,
|
||||
createSetAuthorityInstruction(
|
||||
tokenAccount,
|
||||
newAuthority,
|
||||
authorityType,
|
||||
authority.publicKey,
|
||||
[]
|
||||
authorityType,
|
||||
newAuthority,
|
||||
)
|
||||
);
|
||||
|
||||
return provider.sendAndConfirm(tx, [authority], { commitment: "confirmed" });
|
||||
}
|
||||
|
||||
export async function transfer(
|
||||
export async function transferToken(
|
||||
provider: AnchorProvider,
|
||||
source: web3.PublicKey,
|
||||
destination: web3.PublicKey,
|
||||
|
@ -254,14 +247,23 @@ export async function transfer(
|
|||
) {
|
||||
const tx = new web3.Transaction();
|
||||
tx.add(
|
||||
Token.createTransferInstruction(
|
||||
TOKEN_PROGRAM_ID,
|
||||
source,
|
||||
destination,
|
||||
provider.wallet.publicKey,
|
||||
[],
|
||||
amount
|
||||
)
|
||||
createTransferInstruction(source, destination, provider.wallet.publicKey, amount)
|
||||
);
|
||||
return provider.sendAndConfirm(tx, [], { commitment: "confirmed" });
|
||||
}
|
||||
|
||||
export async function burnToken(
|
||||
provider: AnchorProvider,
|
||||
account: web3.PublicKey,
|
||||
mint: web3.PublicKey,
|
||||
amount: number | BN,
|
||||
owner?: web3.PublicKey
|
||||
) {
|
||||
const ownerKey = owner ?? provider.wallet.publicKey;
|
||||
const tx = new web3.Transaction();
|
||||
const amountVal = amount instanceof BN ? BigInt(amount.toString()) : amount;
|
||||
tx.add(
|
||||
createBurnInstruction(account, mint, ownerKey, amountVal)
|
||||
);
|
||||
return provider.sendAndConfirm(tx, [], { commitment: "confirmed" });
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"target": "ES2020",
|
||||
"module": "commonjs",
|
||||
"allowJs": false,
|
||||
"declaration": true,
|
||||
"lib": ["DOM", "ES6", "DOM.Iterable", "ScriptHost", "ES2016.Array.Include"],
|
||||
"lib": ["DOM", "ES2020", "DOM.Iterable", "ScriptHost"],
|
||||
"outDir": "./dist",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
|
|
152
yarn.lock
152
yarn.lock
|
@ -63,28 +63,60 @@
|
|||
"@jridgewell/resolve-uri" "^3.0.3"
|
||||
"@jridgewell/sourcemap-codec" "^1.4.10"
|
||||
|
||||
"@metaplex-foundation/mpl-core@^0.0.2":
|
||||
version "0.0.2"
|
||||
resolved "https://registry.yarnpkg.com/@metaplex-foundation/mpl-core/-/mpl-core-0.0.2.tgz#17ee2cc216e17629d6df1dbba75964625ebbd603"
|
||||
integrity sha512-UUJ4BlYiWdDegAWmjsNQiNehwYU3QfSFWs3sv4VX0J6/ZrQ28zqosGhQ+I2ZCTEy216finJ82sZWNjuwSWCYyQ==
|
||||
"@metaplex-foundation/beet-solana@^0.4.0":
|
||||
version "0.4.0"
|
||||
resolved "https://registry.yarnpkg.com/@metaplex-foundation/beet-solana/-/beet-solana-0.4.0.tgz#52891e78674aaa54e0031f1bca5bfbc40de12e8d"
|
||||
integrity sha512-B1L94N3ZGMo53b0uOSoznbuM5GBNJ8LwSeznxBxJ+OThvfHQ4B5oMUqb+0zdLRfkKGS7Q6tpHK9P+QK0j3w2cQ==
|
||||
dependencies:
|
||||
"@solana/web3.js" "^1.31.0"
|
||||
bs58 "^4.0.1"
|
||||
"@metaplex-foundation/beet" ">=0.1.0"
|
||||
"@solana/web3.js" "^1.56.2"
|
||||
bs58 "^5.0.0"
|
||||
debug "^4.3.4"
|
||||
|
||||
"@metaplex-foundation/mpl-token-metadata@1.2.5":
|
||||
version "1.2.5"
|
||||
resolved "https://registry.yarnpkg.com/@metaplex-foundation/mpl-token-metadata/-/mpl-token-metadata-1.2.5.tgz#1a927b1c7d30cd634a1e4782022712a02f6865c2"
|
||||
integrity sha512-pxRG53JsTSwXpiJJMHNulJhH8kO3hHztQ3QxslUoKw2hBYKXsg9TGsiHgNIhN2MPZGBJ2pDeK6kNGv0sd54HhA==
|
||||
"@metaplex-foundation/beet@>=0.1.0", "@metaplex-foundation/beet@^0.7.1":
|
||||
version "0.7.1"
|
||||
resolved "https://registry.yarnpkg.com/@metaplex-foundation/beet/-/beet-0.7.1.tgz#0975314211643f87b5f6f3e584fa31abcf4c612c"
|
||||
integrity sha512-hNCEnS2WyCiYyko82rwuISsBY3KYpe828ubsd2ckeqZr7tl0WVLivGkoyA/qdiaaHEBGdGl71OpfWa2rqL3DiA==
|
||||
dependencies:
|
||||
"@metaplex-foundation/mpl-core" "^0.0.2"
|
||||
"@solana/spl-token" "^0.1.8"
|
||||
"@solana/web3.js" "^1.31.0"
|
||||
ansicolors "^0.3.2"
|
||||
bn.js "^5.2.0"
|
||||
debug "^4.3.3"
|
||||
|
||||
"@metaplex-foundation/cusper@^0.0.2":
|
||||
version "0.0.2"
|
||||
resolved "https://registry.yarnpkg.com/@metaplex-foundation/cusper/-/cusper-0.0.2.tgz#dc2032a452d6c269e25f016aa4dd63600e2af975"
|
||||
integrity sha512-S9RulC2fFCFOQraz61bij+5YCHhSO9llJegK8c8Y6731fSi6snUSQJdCUqYS8AIgR0TKbQvdvgSyIIdbDFZbBA==
|
||||
|
||||
"@metaplex-foundation/mpl-token-metadata@2.12.0":
|
||||
version "2.12.0"
|
||||
resolved "https://registry.yarnpkg.com/@metaplex-foundation/mpl-token-metadata/-/mpl-token-metadata-2.12.0.tgz#9817b2d133c5af46c28ab284316b6985ef62b331"
|
||||
integrity sha512-DetC2F5MwMRt4TmLXwj8PJ8nClRYGMecSQ4pr9iKKa+rWertHgKoJHl2XhheRa084GtL7i0ssOKbX2gfYFosuQ==
|
||||
dependencies:
|
||||
"@metaplex-foundation/beet" "^0.7.1"
|
||||
"@metaplex-foundation/beet-solana" "^0.4.0"
|
||||
"@metaplex-foundation/cusper" "^0.0.2"
|
||||
"@solana/spl-token" "^0.3.6"
|
||||
"@solana/web3.js" "^1.66.2"
|
||||
bn.js "^5.2.0"
|
||||
debug "^4.3.4"
|
||||
|
||||
"@noble/curves@^1.0.0":
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.1.0.tgz#f13fc667c89184bc04cccb9b11e8e7bae27d8c3d"
|
||||
integrity sha512-091oBExgENk/kGj3AZmtBDMpxQPDtxQABR2B9lb1JbVTs6ytdzZNwvhxQ4MWasRNEzlbEH8jCWFCwhF/Obj5AA==
|
||||
dependencies:
|
||||
"@noble/hashes" "1.3.1"
|
||||
|
||||
"@noble/ed25519@^1.7.0":
|
||||
version "1.7.3"
|
||||
resolved "https://registry.yarnpkg.com/@noble/ed25519/-/ed25519-1.7.3.tgz#57e1677bf6885354b466c38e2b620c62f45a7123"
|
||||
integrity sha512-iR8GBkDt0Q3GyaVcIu7mSsVIqnFbkbRzGLWlvhwunacoLwt4J3swfKhfaM6rN6WY+TBGoYT1GtT1mIh2/jGbRQ==
|
||||
|
||||
"@noble/hashes@1.3.1", "@noble/hashes@^1.3.0":
|
||||
version "1.3.1"
|
||||
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.1.tgz#8831ef002114670c603c458ab8b11328406953a9"
|
||||
integrity sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==
|
||||
|
||||
"@noble/hashes@^1.1.2":
|
||||
version "1.3.0"
|
||||
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.0.tgz#085fd70f6d7d9d109671090ccae1d3bec62554a1"
|
||||
|
@ -116,13 +148,13 @@
|
|||
"@nodelib/fs.scandir" "2.1.5"
|
||||
fastq "^1.6.0"
|
||||
|
||||
"@orca-so/common-sdk@0.2.2":
|
||||
version "0.2.2"
|
||||
resolved "https://registry.yarnpkg.com/@orca-so/common-sdk/-/common-sdk-0.2.2.tgz#c912ad3d6d37df5119fa40ca21b9e4ccd3855582"
|
||||
integrity sha512-ZL8D9/RbT0xKb9CIVMPl7ZBzbhQGCsskyEy1DKMlQTPyktzLXyN0SRAg+NgjLnGd9mJwB/8JX0c7SyB5zE9wlQ==
|
||||
"@orca-so/common-sdk@^0.3.0-beta-1":
|
||||
version "0.3.0-beta-1"
|
||||
resolved "https://registry.yarnpkg.com/@orca-so/common-sdk/-/common-sdk-0.3.0-beta-1.tgz#b52cb606b85697c9886921829a8d884d3a739a7d"
|
||||
integrity sha512-a7jVClUS7YB5U0wIhjNkLjc5BCyOvqAyupIEQuMj5uYevR66pLH/qN2yRmmskVF/noCTVUZwYlMikeopYk/Y0Q==
|
||||
dependencies:
|
||||
"@solana/spl-token" "0.1.8"
|
||||
"@solana/web3.js" "^1.74.0"
|
||||
"@solana/spl-token" "^0.3.8"
|
||||
"@solana/web3.js" "^1.75.0"
|
||||
decimal.js "^10.3.1"
|
||||
tiny-invariant "^1.2.0"
|
||||
|
||||
|
@ -155,6 +187,16 @@
|
|||
bn.js "^5.1.2"
|
||||
buffer-layout "^1.2.0"
|
||||
|
||||
"@solana/buffer-layout-utils@^0.2.0":
|
||||
version "0.2.0"
|
||||
resolved "https://registry.yarnpkg.com/@solana/buffer-layout-utils/-/buffer-layout-utils-0.2.0.tgz#b45a6cab3293a2eb7597cceb474f229889d875ca"
|
||||
integrity sha512-szG4sxgJGktbuZYDg2FfNmkMi0DYQoVjN2h7ta1W1hPrwzarcFLBq9UpX1UjNXsNpT9dn+chgprtWGioUAr4/g==
|
||||
dependencies:
|
||||
"@solana/buffer-layout" "^4.0.0"
|
||||
"@solana/web3.js" "^1.32.0"
|
||||
bigint-buffer "^1.1.5"
|
||||
bignumber.js "^9.0.1"
|
||||
|
||||
"@solana/buffer-layout@^4.0.0":
|
||||
version "4.0.1"
|
||||
resolved "https://registry.yarnpkg.com/@solana/buffer-layout/-/buffer-layout-4.0.1.tgz#b996235eaec15b1e0b5092a8ed6028df77fa6c15"
|
||||
|
@ -162,7 +204,7 @@
|
|||
dependencies:
|
||||
buffer "~6.0.3"
|
||||
|
||||
"@solana/spl-token@0.1.8", "@solana/spl-token@^0.1.8":
|
||||
"@solana/spl-token@^0.1.8":
|
||||
version "0.1.8"
|
||||
resolved "https://registry.yarnpkg.com/@solana/spl-token/-/spl-token-0.1.8.tgz#f06e746341ef8d04165e21fc7f555492a2a0faa6"
|
||||
integrity sha512-LZmYCKcPQDtJgecvWOgT/cnoIQPWjdH+QVyzPcFvyDUiT0DiRjZaam4aqNUyvchLFhzgunv3d9xOoyE34ofdoQ==
|
||||
|
@ -174,7 +216,16 @@
|
|||
buffer-layout "^1.2.0"
|
||||
dotenv "10.0.0"
|
||||
|
||||
"@solana/web3.js@^1.21.0", "@solana/web3.js@^1.31.0", "@solana/web3.js@^1.36.0", "@solana/web3.js@^1.68.0", "@solana/web3.js@~1.74.0":
|
||||
"@solana/spl-token@^0.3.6", "@solana/spl-token@^0.3.8":
|
||||
version "0.3.8"
|
||||
resolved "https://registry.yarnpkg.com/@solana/spl-token/-/spl-token-0.3.8.tgz#8e9515ea876e40a4cc1040af865f61fc51d27edf"
|
||||
integrity sha512-ogwGDcunP9Lkj+9CODOWMiVJEdRtqHAtX2rWF62KxnnSWtMZtV9rDhTrZFshiyJmxDnRL/1nKE1yJHg4jjs3gg==
|
||||
dependencies:
|
||||
"@solana/buffer-layout" "^4.0.0"
|
||||
"@solana/buffer-layout-utils" "^0.2.0"
|
||||
buffer "^6.0.3"
|
||||
|
||||
"@solana/web3.js@^1.21.0", "@solana/web3.js@^1.36.0", "@solana/web3.js@^1.68.0":
|
||||
version "1.74.0"
|
||||
resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.74.0.tgz#dbcbeabb830dd7cbbcf5e31404ca79c9785cbf2d"
|
||||
integrity sha512-RKZyPqizPCxmpMGfpu4fuplNZEWCrhRBjjVstv5QnAJvgln1jgOfgui+rjl1ExnqDnWKg9uaZ5jtGROH/cwabg==
|
||||
|
@ -196,15 +247,14 @@
|
|||
rpc-websockets "^7.5.1"
|
||||
superstruct "^0.14.2"
|
||||
|
||||
"@solana/web3.js@^1.74.0":
|
||||
version "1.75.0"
|
||||
resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.75.0.tgz#824c6f78865007bca758ca18f268d6f7363b42e5"
|
||||
integrity sha512-rHQgdo1EWfb+nPUpHe4O7i8qJPELHKNR5PAZRK+a7XxiykqOfbaAlPt5boDWAGPnYbSv0ziWZv5mq9DlFaQCxg==
|
||||
"@solana/web3.js@^1.32.0", "@solana/web3.js@^1.56.2", "@solana/web3.js@^1.66.2", "@solana/web3.js@^1.75.0":
|
||||
version "1.77.3"
|
||||
resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.77.3.tgz#2cbeaa1dd24f8fa386ac924115be82354dfbebab"
|
||||
integrity sha512-PHaO0BdoiQRPpieC1p31wJsBaxwIOWLh8j2ocXNKX8boCQVldt26Jqm2tZE4KlrvnCIV78owPLv1pEUgqhxZ3w==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.12.5"
|
||||
"@noble/ed25519" "^1.7.0"
|
||||
"@noble/hashes" "^1.1.2"
|
||||
"@noble/secp256k1" "^1.6.3"
|
||||
"@noble/curves" "^1.0.0"
|
||||
"@noble/hashes" "^1.3.0"
|
||||
"@solana/buffer-layout" "^4.0.0"
|
||||
agentkeepalive "^4.2.1"
|
||||
bigint-buffer "^1.1.5"
|
||||
|
@ -213,7 +263,7 @@
|
|||
bs58 "^4.0.1"
|
||||
buffer "6.0.3"
|
||||
fast-stable-stringify "^1.0.0"
|
||||
jayson "^3.4.4"
|
||||
jayson "^4.1.0"
|
||||
node-fetch "^2.6.7"
|
||||
rpc-websockets "^7.5.1"
|
||||
superstruct "^0.14.2"
|
||||
|
@ -415,6 +465,11 @@ ansi-styles@^4.0.0, ansi-styles@^4.1.0:
|
|||
dependencies:
|
||||
color-convert "^2.0.1"
|
||||
|
||||
ansicolors@^0.3.2:
|
||||
version "0.3.2"
|
||||
resolved "https://registry.yarnpkg.com/ansicolors/-/ansicolors-0.3.2.tgz#665597de86a9ffe3aa9bfbe6cae5c6ea426b4979"
|
||||
integrity sha512-QXu7BPrP29VllRxH8GwB7x5iX5qWKAAMLqKQGWTeLWVlNHNOpVMJ91dsxQAIWXpjuW5wqvxu3Jd/nRjrJ+0pqg==
|
||||
|
||||
any-promise@^1.0.0:
|
||||
version "1.3.0"
|
||||
resolved "https://registry.yarnpkg.com/any-promise/-/any-promise-1.3.0.tgz#abc6afeedcea52e809cdc0376aed3ce39635d17f"
|
||||
|
@ -465,6 +520,11 @@ base-x@^3.0.2:
|
|||
dependencies:
|
||||
safe-buffer "^5.0.1"
|
||||
|
||||
base-x@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/base-x/-/base-x-4.0.0.tgz#d0e3b7753450c73f8ad2389b5c018a4af7b2224a"
|
||||
integrity sha512-FuwxlW4H5kh37X/oW59pwTzzTKRzfrrQwhmyspRM7swOEZcHtDZSCt45U6oKgtuFE+WYPblePMVIPR4RZrh/hw==
|
||||
|
||||
base64-js@^1.3.1, base64-js@^1.5.1:
|
||||
version "1.5.1"
|
||||
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
|
||||
|
@ -477,6 +537,11 @@ bigint-buffer@^1.1.5:
|
|||
dependencies:
|
||||
bindings "^1.3.0"
|
||||
|
||||
bignumber.js@^9.0.1:
|
||||
version "9.1.1"
|
||||
resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.1.1.tgz#c4df7dc496bd849d4c9464344c1aa74228b4dac6"
|
||||
integrity sha512-pHm4LsMJ6lzgNGVfZHjMoO8sdoRhOzOH4MLmY65Jg70bpxCKu5iOHNJyfF6OyvYw7t8Fpf35RuzUyqnQsj8Vig==
|
||||
|
||||
binary-extensions@^2.0.0:
|
||||
version "2.2.0"
|
||||
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d"
|
||||
|
@ -537,6 +602,13 @@ bs58@^4.0.0, bs58@^4.0.1:
|
|||
dependencies:
|
||||
base-x "^3.0.2"
|
||||
|
||||
bs58@^5.0.0:
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/bs58/-/bs58-5.0.0.tgz#865575b4d13c09ea2a84622df6c8cbeb54ffc279"
|
||||
integrity sha512-r+ihvQJvahgYT50JD05dyJNKlmmSlMoOGwn1lCcEzanPglg7TxYjioQUYehQ9mAR/+hOSd2jRc/Z2y5UxBymvQ==
|
||||
dependencies:
|
||||
base-x "^4.0.0"
|
||||
|
||||
buffer-from@^1.0.0, buffer-from@^1.1.0:
|
||||
version "1.1.2"
|
||||
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5"
|
||||
|
@ -555,7 +627,7 @@ buffer@6.0.1:
|
|||
base64-js "^1.3.1"
|
||||
ieee754 "^1.2.1"
|
||||
|
||||
buffer@6.0.3, buffer@~6.0.3:
|
||||
buffer@6.0.3, buffer@^6.0.3, buffer@~6.0.3:
|
||||
version "6.0.3"
|
||||
resolved "https://registry.yarnpkg.com/buffer/-/buffer-6.0.3.tgz#2ace578459cc8fbe2a70aaa8f52ee63b6a74c6c6"
|
||||
integrity sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==
|
||||
|
@ -676,7 +748,7 @@ debug@4.3.3:
|
|||
dependencies:
|
||||
ms "2.1.2"
|
||||
|
||||
debug@^4.1.0, debug@^4.3.1:
|
||||
debug@^4.1.0, debug@^4.3.1, debug@^4.3.3, debug@^4.3.4:
|
||||
version "4.3.4"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
|
||||
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
|
||||
|
@ -1052,6 +1124,24 @@ jayson@^3.4.4:
|
|||
uuid "^8.3.2"
|
||||
ws "^7.4.5"
|
||||
|
||||
jayson@^4.1.0:
|
||||
version "4.1.0"
|
||||
resolved "https://registry.yarnpkg.com/jayson/-/jayson-4.1.0.tgz#60dc946a85197317f2b1439d672a8b0a99cea2f9"
|
||||
integrity sha512-R6JlbyLN53Mjku329XoRT2zJAE6ZgOQ8f91ucYdMCD4nkGCF9kZSrcGXpHIU4jeKj58zUZke2p+cdQchU7Ly7A==
|
||||
dependencies:
|
||||
"@types/connect" "^3.4.33"
|
||||
"@types/node" "^12.12.54"
|
||||
"@types/ws" "^7.4.4"
|
||||
JSONStream "^1.3.5"
|
||||
commander "^2.20.3"
|
||||
delay "^5.0.0"
|
||||
es6-promisify "^5.0.0"
|
||||
eyes "^0.1.8"
|
||||
isomorphic-ws "^4.0.1"
|
||||
json-stringify-safe "^5.0.1"
|
||||
uuid "^8.3.2"
|
||||
ws "^7.4.5"
|
||||
|
||||
js-sha256@^0.9.0:
|
||||
version "0.9.0"
|
||||
resolved "https://registry.yarnpkg.com/js-sha256/-/js-sha256-0.9.0.tgz#0b89ac166583e91ef9123644bd3c5334ce9d0966"
|
||||
|
|
Loading…
Reference in New Issue