Update SDK to use Anchor 0.27 & other settings for Smart-Router (#97)
- Add lookupTableFetcher into WhirlpoolContext - Update SDK web3, anchor 0.27 deps to support VersionedTransactions - Faster test-suite execution with faster ticks_per_slot for validator. - Test-suite now runs the test-cases with metaplex out of the box
This commit is contained in:
parent
cdab58501c
commit
b21c82e2fe
|
@ -8,5 +8,5 @@ test-ledger/
|
|||
sdk/dist/
|
||||
sdk/node_modules
|
||||
.vscode/
|
||||
.yalc/
|
||||
yalc.lock
|
||||
**/.yalc/
|
||||
**/yalc.lock
|
||||
|
|
13
Anchor.toml
13
Anchor.toml
|
@ -8,10 +8,13 @@ url = "https://anchor.projectserum.com"
|
|||
cluster = "localnet"
|
||||
wallet = "~/.config/solana/id.json"
|
||||
|
||||
# wait for update to anchor to support cloning
|
||||
# [[test.genesis]]
|
||||
# address = "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"
|
||||
# program = "../metaplex-program-library/token-metadata/target/deploy/mpl_token_metadata.so"
|
||||
|
||||
[scripts]
|
||||
test = "ts-mocha -p sdk/tests/tsconfig.json -t 1000000 sdk/tests/**/*.test.ts"
|
||||
|
||||
[test.validator]
|
||||
slots_per_epoch = "33"
|
||||
ticks_per_slot = 7
|
||||
url = "https://api.mainnet-beta.solana.com"
|
||||
|
||||
[[test.validator.clone]]
|
||||
address = "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"
|
|
@ -1,16 +1,16 @@
|
|||
{
|
||||
"name": "@orca-so/whirlpools-sdk",
|
||||
"version": "0.8.2",
|
||||
"version": "0.9.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.1.12",
|
||||
"@project-serum/anchor": "~0.25.0",
|
||||
"@orca-so/common-sdk": "0.2.1",
|
||||
"@solana/spl-token": "^0.1.8",
|
||||
"@solana/web3.js": "1.66.0",
|
||||
"@solana/web3.js": "~1.74.0",
|
||||
"decimal.js": "^10.3.1",
|
||||
"tiny-invariant": "^1.2.0"
|
||||
},
|
||||
|
@ -24,10 +24,10 @@
|
|||
"mocha": "^9.0.3",
|
||||
"prettier": "^2.3.2",
|
||||
"process": "^0.11.10",
|
||||
"typedoc": "~0.22.18",
|
||||
"typescript": "^4.5.5",
|
||||
"ts-mocha": "^9.0.0",
|
||||
"ts-node": "^10.9.1"
|
||||
"ts-node": "^10.9.1",
|
||||
"typedoc": "~0.22.18",
|
||||
"typescript": "^4.5.5"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc -p src",
|
||||
|
|
|
@ -1,49 +1,95 @@
|
|||
import { AnchorProvider, Idl, Program } from "@project-serum/anchor";
|
||||
import { Wallet } from "@project-serum/anchor/dist/cjs/provider";
|
||||
import { ConfirmOptions, Connection, PublicKey } from "@solana/web3.js";
|
||||
import { AnchorProvider, Idl, Program } from "@coral-xyz/anchor";
|
||||
import {
|
||||
BuildOptions,
|
||||
LookupTableFetcher,
|
||||
TransactionBuilderOptions,
|
||||
Wallet,
|
||||
} from "@orca-so/common-sdk";
|
||||
import { Commitment, Connection, PublicKey, SendOptions } from "@solana/web3.js";
|
||||
import { Whirlpool } from "./artifacts/whirlpool";
|
||||
import WhirlpoolIDL from "./artifacts/whirlpool.json";
|
||||
import { AccountFetcher } from "./network/public";
|
||||
import { contextOptionsToBuilderOptions } from "./utils/txn-utils";
|
||||
|
||||
/**
|
||||
* Default settings used when interacting with transactions.
|
||||
* @category Core
|
||||
*/
|
||||
export type WhirlpoolContextOpts = {
|
||||
userDefaultBuildOptions?: Partial<BuildOptions>;
|
||||
userDefaultSendOptions?: Partial<SendOptions>;
|
||||
userDefaultConfirmCommitment?: Commitment;
|
||||
};
|
||||
|
||||
/**
|
||||
* @category Core
|
||||
*/
|
||||
export class WhirlpoolContext {
|
||||
readonly connection: Connection;
|
||||
readonly wallet: Wallet;
|
||||
readonly opts: ConfirmOptions;
|
||||
readonly program: Program<Whirlpool>;
|
||||
readonly provider: AnchorProvider;
|
||||
readonly fetcher: AccountFetcher;
|
||||
readonly lookupTableFetcher: LookupTableFetcher | undefined;
|
||||
readonly opts: WhirlpoolContextOpts;
|
||||
readonly txBuilderOpts: TransactionBuilderOptions | undefined;
|
||||
|
||||
public static from(
|
||||
connection: Connection,
|
||||
wallet: Wallet,
|
||||
programId: PublicKey,
|
||||
fetcher = new AccountFetcher(connection),
|
||||
opts: ConfirmOptions = AnchorProvider.defaultOptions()
|
||||
lookupTableFetcher?: LookupTableFetcher,
|
||||
opts: WhirlpoolContextOpts = {}
|
||||
): WhirlpoolContext {
|
||||
const anchorProvider = new AnchorProvider(connection, wallet, opts);
|
||||
const anchorProvider = new AnchorProvider(connection, wallet, {
|
||||
commitment: opts.userDefaultConfirmCommitment || "confirmed",
|
||||
preflightCommitment: opts.userDefaultConfirmCommitment || "confirmed",
|
||||
});
|
||||
const program = new Program(WhirlpoolIDL as Idl, programId, anchorProvider);
|
||||
return new WhirlpoolContext(anchorProvider, anchorProvider.wallet, program, fetcher, opts);
|
||||
return new WhirlpoolContext(
|
||||
anchorProvider,
|
||||
anchorProvider.wallet,
|
||||
program,
|
||||
fetcher,
|
||||
lookupTableFetcher,
|
||||
opts
|
||||
);
|
||||
}
|
||||
|
||||
public static fromWorkspace(
|
||||
provider: AnchorProvider,
|
||||
program: Program,
|
||||
fetcher = new AccountFetcher(provider.connection),
|
||||
opts: ConfirmOptions = AnchorProvider.defaultOptions()
|
||||
lookupTableFetcher?: LookupTableFetcher,
|
||||
opts: WhirlpoolContextOpts = {}
|
||||
) {
|
||||
return new WhirlpoolContext(provider, provider.wallet, program, fetcher, opts);
|
||||
return new WhirlpoolContext(
|
||||
provider,
|
||||
provider.wallet,
|
||||
program,
|
||||
fetcher,
|
||||
lookupTableFetcher,
|
||||
opts
|
||||
);
|
||||
}
|
||||
|
||||
public static withProvider(
|
||||
provider: AnchorProvider,
|
||||
programId: PublicKey,
|
||||
fetcher = new AccountFetcher(provider.connection),
|
||||
opts: ConfirmOptions = AnchorProvider.defaultOptions()
|
||||
lookupTableFetcher?: LookupTableFetcher,
|
||||
opts: WhirlpoolContextOpts = {}
|
||||
): WhirlpoolContext {
|
||||
const program = new Program(WhirlpoolIDL as Idl, programId, provider);
|
||||
return new WhirlpoolContext(provider, provider.wallet, program, fetcher, opts);
|
||||
return new WhirlpoolContext(
|
||||
provider,
|
||||
provider.wallet,
|
||||
program,
|
||||
fetcher,
|
||||
lookupTableFetcher,
|
||||
opts
|
||||
);
|
||||
}
|
||||
|
||||
public constructor(
|
||||
|
@ -51,15 +97,18 @@ export class WhirlpoolContext {
|
|||
wallet: Wallet,
|
||||
program: Program,
|
||||
fetcher: AccountFetcher,
|
||||
opts: ConfirmOptions
|
||||
lookupTableFetcher?: LookupTableFetcher,
|
||||
opts: WhirlpoolContextOpts = {}
|
||||
) {
|
||||
this.connection = provider.connection;
|
||||
this.wallet = wallet;
|
||||
this.opts = opts;
|
||||
// It's a hack but it works on Anchor workspace *shrug*
|
||||
this.program = program as unknown as Program<Whirlpool>;
|
||||
this.provider = provider;
|
||||
this.fetcher = fetcher;
|
||||
this.lookupTableFetcher = lookupTableFetcher;
|
||||
this.opts = opts;
|
||||
this.txBuilderOpts = contextOptionsToBuilderOptions(this.opts);
|
||||
}
|
||||
|
||||
// TODO: Add another factory method to build from on-chain IDL
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { Address } from "@coral-xyz/anchor";
|
||||
import {
|
||||
AddressUtil,
|
||||
deriveATA,
|
||||
|
@ -6,7 +7,6 @@ import {
|
|||
TransactionBuilder,
|
||||
ZERO,
|
||||
} from "@orca-so/common-sdk";
|
||||
import { Address } from "@project-serum/anchor";
|
||||
import { NATIVE_MINT } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import invariant from "tiny-invariant";
|
||||
|
@ -105,7 +105,8 @@ export class PositionImpl implements Position {
|
|||
|
||||
const txBuilder = new TransactionBuilder(
|
||||
this.ctx.provider.connection,
|
||||
this.ctx.provider.wallet
|
||||
this.ctx.provider.wallet,
|
||||
this.ctx.txBuilderOpts
|
||||
);
|
||||
|
||||
let tokenOwnerAccountA: PublicKey;
|
||||
|
@ -181,7 +182,8 @@ export class PositionImpl implements Position {
|
|||
|
||||
const txBuilder = new TransactionBuilder(
|
||||
this.ctx.provider.connection,
|
||||
this.ctx.provider.wallet
|
||||
this.ctx.provider.wallet,
|
||||
this.ctx.txBuilderOpts
|
||||
);
|
||||
let tokenOwnerAccountA: PublicKey;
|
||||
let tokenOwnerAccountB: PublicKey;
|
||||
|
@ -251,7 +253,11 @@ export class PositionImpl implements Position {
|
|||
);
|
||||
}
|
||||
|
||||
let txBuilder = new TransactionBuilder(this.ctx.provider.connection, this.ctx.provider.wallet);
|
||||
let txBuilder = new TransactionBuilder(
|
||||
this.ctx.provider.connection,
|
||||
this.ctx.provider.wallet,
|
||||
this.ctx.txBuilderOpts
|
||||
);
|
||||
|
||||
const accountExemption = await this.ctx.fetcher.getAccountRentExempt();
|
||||
|
||||
|
@ -348,7 +354,8 @@ export class PositionImpl implements Position {
|
|||
|
||||
const txBuilder = new TransactionBuilder(
|
||||
this.ctx.provider.connection,
|
||||
this.ctx.provider.wallet
|
||||
this.ctx.provider.wallet,
|
||||
this.ctx.txBuilderOpts
|
||||
);
|
||||
|
||||
const accountExemption = await this.ctx.fetcher.getAccountRentExempt();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Address } from "@coral-xyz/anchor";
|
||||
import { AddressUtil, TransactionBuilder } from "@orca-so/common-sdk";
|
||||
import { Address } from "@project-serum/anchor";
|
||||
import { Keypair, PublicKey } from "@solana/web3.js";
|
||||
import invariant from "tiny-invariant";
|
||||
import { WhirlpoolContext } from "../context";
|
||||
|
@ -223,7 +223,8 @@ export class WhirlpoolClientImpl implements WhirlpoolClient {
|
|||
|
||||
const txBuilder = new TransactionBuilder(
|
||||
this.ctx.provider.connection,
|
||||
this.ctx.provider.wallet
|
||||
this.ctx.provider.wallet,
|
||||
this.ctx.txBuilderOpts
|
||||
);
|
||||
|
||||
const initPoolIx = WhirlpoolIx.initializePoolIx(this.ctx.program, {
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
import { Address, BN, translateAddress } from "@coral-xyz/anchor";
|
||||
import {
|
||||
AddressUtil,
|
||||
deriveATA,
|
||||
Percentage,
|
||||
resolveOrCreateATAs,
|
||||
TokenUtil,
|
||||
TransactionBuilder,
|
||||
ZERO,
|
||||
deriveATA,
|
||||
resolveOrCreateATAs,
|
||||
} from "@orca-so/common-sdk";
|
||||
import { Address, BN, translateAddress } from "@project-serum/anchor";
|
||||
import { NATIVE_MINT } from "@solana/spl-token";
|
||||
import { Keypair, PublicKey } from "@solana/web3.js";
|
||||
import invariant from "tiny-invariant";
|
||||
import { WhirlpoolContext } from "../context";
|
||||
import {
|
||||
closePositionIx,
|
||||
decreaseLiquidityIx,
|
||||
DevFeeSwapInput,
|
||||
IncreaseLiquidityInput,
|
||||
SwapInput,
|
||||
closePositionIx,
|
||||
decreaseLiquidityIx,
|
||||
increaseLiquidityIx,
|
||||
initTickArrayIx,
|
||||
openPositionIx,
|
||||
openPositionWithMetadataIx,
|
||||
swapAsync,
|
||||
SwapInput,
|
||||
} from "../instructions";
|
||||
import {
|
||||
collectFeesQuote,
|
||||
|
@ -34,9 +34,9 @@ import { getTickArrayDataForPosition } from "../utils/builder/position-builder-u
|
|||
import { PDAUtil, TickArrayUtil, TickUtil } from "../utils/public";
|
||||
import { createWSOLAccountInstructions } from "../utils/spl-token-utils";
|
||||
import {
|
||||
TokenMintTypes,
|
||||
getTokenMintsFromWhirlpools,
|
||||
resolveAtaForMints,
|
||||
TokenMintTypes,
|
||||
} from "../utils/whirlpool-ata-utils";
|
||||
import { Whirlpool } from "../whirlpool-client";
|
||||
import { PositionImpl } from "./position-impl";
|
||||
|
@ -142,7 +142,8 @@ export class WhirlpoolImpl implements Whirlpool {
|
|||
|
||||
const txBuilder = new TransactionBuilder(
|
||||
this.ctx.provider.connection,
|
||||
this.ctx.provider.wallet
|
||||
this.ctx.provider.wallet,
|
||||
this.ctx.txBuilderOpts
|
||||
);
|
||||
initTickArrayStartPdas.forEach((initTickArrayInfo) => {
|
||||
txBuilder.addInstruction(
|
||||
|
@ -206,7 +207,8 @@ export class WhirlpoolImpl implements Whirlpool {
|
|||
const payerKey = payer ? AddressUtil.toPubKey(payer) : this.ctx.wallet.publicKey;
|
||||
const txBuilder = new TransactionBuilder(
|
||||
this.ctx.provider.connection,
|
||||
this.ctx.provider.wallet
|
||||
this.ctx.provider.wallet,
|
||||
this.ctx.txBuilderOpts
|
||||
);
|
||||
|
||||
if (!quote.devFeeAmount.eq(ZERO)) {
|
||||
|
@ -284,7 +286,8 @@ export class WhirlpoolImpl implements Whirlpool {
|
|||
|
||||
const txBuilder = new TransactionBuilder(
|
||||
this.ctx.provider.connection,
|
||||
this.ctx.provider.wallet
|
||||
this.ctx.provider.wallet,
|
||||
this.ctx.txBuilderOpts
|
||||
);
|
||||
|
||||
const positionIx = (withMetadata ? openPositionWithMetadataIx : openPositionIx)(
|
||||
|
@ -378,14 +381,16 @@ export class WhirlpoolImpl implements Whirlpool {
|
|||
|
||||
const tokenAccountsTxBuilder = new TransactionBuilder(
|
||||
this.ctx.provider.connection,
|
||||
this.ctx.provider.wallet
|
||||
this.ctx.provider.wallet,
|
||||
this.ctx.txBuilderOpts
|
||||
);
|
||||
|
||||
const accountExemption = await this.ctx.fetcher.getAccountRentExempt();
|
||||
|
||||
const txBuilder = new TransactionBuilder(
|
||||
this.ctx.provider.connection,
|
||||
this.ctx.provider.wallet
|
||||
this.ctx.provider.wallet,
|
||||
this.ctx.txBuilderOpts
|
||||
);
|
||||
|
||||
const tickArrayLower = PDAUtil.getTickArrayFromTickIndex(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Program } from "@coral-xyz/anchor";
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
/**
|
||||
|
@ -25,7 +25,7 @@ export type CloseBundledPositionParams = {
|
|||
|
||||
/**
|
||||
* Close a bundled position in a Whirlpool.
|
||||
*
|
||||
*
|
||||
* #### Special Errors
|
||||
* `InvalidBundleIndex` - If the provided bundle index is out of bounds.
|
||||
* `ClosePositionNotEmpty` - The provided position account is not empty.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
/**
|
||||
* Parameters to collect protocol fees for a Whirlpool
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
/**
|
||||
* Parameters to collect rewards from a reward index in a position.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Address } from "@coral-xyz/anchor";
|
||||
import { Instruction, resolveOrCreateATAs, TransactionBuilder, ZERO } from "@orca-so/common-sdk";
|
||||
import { ResolvedTokenAddressInstruction } from "@orca-so/common-sdk/dist/helpers/token-instructions";
|
||||
import { Address } from "@project-serum/anchor";
|
||||
import { NATIVE_MINT } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { PositionData, WhirlpoolContext } from "../..";
|
||||
|
@ -8,10 +8,10 @@ import { WhirlpoolIx } from "../../ix";
|
|||
import { WhirlpoolData } from "../../types/public";
|
||||
import { PDAUtil, PoolUtil, TickUtil } from "../../utils/public";
|
||||
import {
|
||||
getAssociatedTokenAddressSync,
|
||||
createWSOLAccountInstructions,
|
||||
getAssociatedTokenAddressSync,
|
||||
} from "../../utils/spl-token-utils";
|
||||
import { convertListToMap, checkMergedTransactionSizeIsValid } from "../../utils/txn-utils";
|
||||
import { checkMergedTransactionSizeIsValid, convertListToMap } from "../../utils/txn-utils";
|
||||
import { getTokenMintsFromWhirlpools } from "../../utils/whirlpool-ata-utils";
|
||||
import { updateFeesAndRewardsIx } from "../update-fees-and-rewards-ix";
|
||||
|
||||
|
@ -133,7 +133,7 @@ export async function collectAllForPositionsTxns(
|
|||
allMints.mintMap.map((mint) => mint.toBase58())
|
||||
);
|
||||
|
||||
const latestBlockhash = await ctx.connection.getLatestBlockhash("singleGossip");
|
||||
const latestBlockhash = await ctx.connection.getLatestBlockhash();
|
||||
const txBuilders: TransactionBuilder[] = [];
|
||||
|
||||
let posIndex = 0;
|
||||
|
@ -142,7 +142,7 @@ export async function collectAllForPositionsTxns(
|
|||
let reattempt = false;
|
||||
while (posIndex < positionList.length) {
|
||||
if (!pendingTxBuilder || !touchedMints) {
|
||||
pendingTxBuilder = new TransactionBuilder(ctx.connection, ctx.wallet);
|
||||
pendingTxBuilder = new TransactionBuilder(ctx.connection, ctx.wallet, ctx.txBuilderOpts);
|
||||
touchedMints = new Set<string>();
|
||||
resolvedAtas[NATIVE_MINT.toBase58()] = createWSOLAccountInstructions(
|
||||
receiverKey,
|
||||
|
@ -163,7 +163,7 @@ export async function collectAllForPositionsTxns(
|
|||
resolvedAtas,
|
||||
touchedMints
|
||||
);
|
||||
const positionTxBuilder = new TransactionBuilder(ctx.connection, ctx.wallet);
|
||||
const positionTxBuilder = new TransactionBuilder(ctx.connection, ctx.wallet, ctx.txBuilderOpts);
|
||||
positionTxBuilder.addInstructions(collectIxForPosition);
|
||||
|
||||
// Attempt to push the new instructions into the pending builder
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import { Address } from "@coral-xyz/anchor";
|
||||
import { AddressUtil, Instruction, TokenUtil, TransactionBuilder } from "@orca-so/common-sdk";
|
||||
import { Address } from "@project-serum/anchor";
|
||||
import { NATIVE_MINT, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { NATIVE_MINT } from "@solana/spl-token";
|
||||
import { PACKET_DATA_SIZE } from "@solana/web3.js";
|
||||
import { WhirlpoolContext } from "../..";
|
||||
import {
|
||||
TokenMintTypes,
|
||||
addNativeMintHandlingIx,
|
||||
getTokenMintsFromWhirlpools,
|
||||
resolveAtaForMints,
|
||||
TokenMintTypes,
|
||||
} from "../../utils/whirlpool-ata-utils";
|
||||
import { collectProtocolFeesIx } from "../collect-protocol-fees-ix";
|
||||
|
||||
|
@ -28,8 +28,12 @@ export async function collectProtocolFees(
|
|||
payer: payerKey,
|
||||
});
|
||||
|
||||
const latestBlockhash = await ctx.connection.getLatestBlockhash("singleGossip");
|
||||
let txBuilder = new TransactionBuilder(ctx.connection, ctx.wallet).addInstructions(resolveAtaIxs);
|
||||
const latestBlockhash = await ctx.connection.getLatestBlockhash();
|
||||
let txBuilder = new TransactionBuilder(
|
||||
ctx.connection,
|
||||
ctx.wallet,
|
||||
ctx.txBuilderOpts
|
||||
).addInstructions(resolveAtaIxs);
|
||||
|
||||
const instructions: Instruction[] = [];
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ export async function swapAsync(
|
|||
): Promise<TransactionBuilder> {
|
||||
const { wallet, whirlpool, swapInput } = params;
|
||||
const { aToB, amount } = swapInput;
|
||||
const txBuilder = new TransactionBuilder(ctx.connection, ctx.wallet);
|
||||
const txBuilder = new TransactionBuilder(ctx.connection, ctx.wallet, ctx.txBuilderOpts);
|
||||
const tickArrayAddresses = [swapInput.tickArray0, swapInput.tickArray1, swapInput.tickArray2];
|
||||
|
||||
let uninitializedArrays = await TickArrayUtil.getUninitializedArraysString(
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import { BN, Program } from "@coral-xyz/anchor";
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { BN } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
/**
|
||||
* Parameters to remove liquidity from a position.
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
/**
|
||||
* Parameters to delete a PositionBundle account.
|
||||
|
@ -24,7 +24,7 @@ export type DeletePositionBundleParams = {
|
|||
|
||||
/**
|
||||
* Deletes a PositionBundle account.
|
||||
*
|
||||
*
|
||||
* #### Special Errors
|
||||
* `PositionBundleNotDeletable` - The provided position bundle has open positions.
|
||||
*
|
||||
|
@ -37,13 +37,8 @@ export function deletePositionBundleIx(
|
|||
program: Program<Whirlpool>,
|
||||
params: DeletePositionBundleParams
|
||||
): Instruction {
|
||||
const {
|
||||
owner,
|
||||
positionBundle,
|
||||
positionBundleMint,
|
||||
positionBundleTokenAccount,
|
||||
receiver,
|
||||
} = params;
|
||||
const { owner, positionBundle, positionBundleMint, positionBundleTokenAccount, receiver } =
|
||||
params;
|
||||
|
||||
const ix = program.instruction.deletePositionBundle({
|
||||
accounts: {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Program, BN } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import { BN, Program } from "@coral-xyz/anchor";
|
||||
import { TOKEN_PROGRAM_ID, u64 } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { SystemProgram, Keypair, PublicKey } from "@solana/web3.js";
|
||||
import { Program } from "@project-serum/anchor";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { Keypair, PublicKey, SystemProgram } from "@solana/web3.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { SystemProgram, PublicKey } from "@solana/web3.js";
|
||||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { PDA } from "@orca-so/common-sdk";
|
||||
import { PublicKey, SystemProgram } from "@solana/web3.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import { SystemProgram, SYSVAR_RENT_PUBKEY, PublicKey, Keypair } from "@solana/web3.js";
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import { WhirlpoolBumpsData } from "../types/public/anchor-types";
|
||||
import { BN, Program } from "@coral-xyz/anchor";
|
||||
import { Instruction, PDA } from "@orca-so/common-sdk";
|
||||
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { BN } from "@project-serum/anchor";
|
||||
import { PDA } from "@orca-so/common-sdk";
|
||||
import { Keypair, PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY } from "@solana/web3.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import { WhirlpoolBumpsData } from "../types/public/anchor-types";
|
||||
|
||||
/**
|
||||
* Parameters to initialize a Whirlpool account.
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import * as anchor from "@project-serum/anchor";
|
||||
import { PublicKey, SystemProgram, Keypair } from "@solana/web3.js";
|
||||
import { PDA } from "@orca-so/common-sdk";
|
||||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { Instruction, PDA } from "@orca-so/common-sdk";
|
||||
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { Keypair, PublicKey, SystemProgram } from "@solana/web3.js";
|
||||
import { METADATA_PROGRAM_ADDRESS, WHIRLPOOL_NFT_UPDATE_AUTH } from "..";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
/**
|
||||
* Parameters to initialize a PositionBundle account.
|
||||
|
@ -37,12 +36,12 @@ export function initializePositionBundleIx(
|
|||
program: Program<Whirlpool>,
|
||||
params: InitializePositionBundleParams
|
||||
): Instruction {
|
||||
const {
|
||||
const {
|
||||
owner,
|
||||
positionBundlePda,
|
||||
positionBundleMintKeypair,
|
||||
positionBundleTokenAccount,
|
||||
funder,
|
||||
funder,
|
||||
} = params;
|
||||
|
||||
const ix = program.instruction.initializePositionBundle({
|
||||
|
@ -75,17 +74,17 @@ export function initializePositionBundleIx(
|
|||
* @param params - InitializePositionBundleParams object
|
||||
* @returns - Instruction to perform the action.
|
||||
*/
|
||||
export function initializePositionBundleWithMetadataIx(
|
||||
export function initializePositionBundleWithMetadataIx(
|
||||
program: Program<Whirlpool>,
|
||||
params: InitializePositionBundleParams & { positionBundleMetadataPda: PDA }
|
||||
): Instruction {
|
||||
const {
|
||||
const {
|
||||
owner,
|
||||
positionBundlePda,
|
||||
positionBundleMintKeypair,
|
||||
positionBundleTokenAccount,
|
||||
positionBundleMetadataPda,
|
||||
funder,
|
||||
funder,
|
||||
} = params;
|
||||
|
||||
const ix = program.instruction.initializePositionBundleWithMetadata({
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as anchor from "@project-serum/anchor";
|
||||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { SystemProgram, Keypair, PublicKey } from "@solana/web3.js";
|
||||
import { Program } from "@project-serum/anchor";
|
||||
import { Keypair, PublicKey, SystemProgram } from "@solana/web3.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import * as anchor from "@project-serum/anchor";
|
||||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { Instruction, PDA } from "@orca-so/common-sdk";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { PDA } from "@orca-so/common-sdk";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
/**
|
||||
* Parameters to initialize a TickArray account.
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { Instruction, PDA } from "@orca-so/common-sdk";
|
||||
import { PublicKey, SystemProgram } from "@solana/web3.js";
|
||||
import { PDA, Instruction } from "@orca-so/common-sdk";
|
||||
import * as anchor from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
/**
|
||||
* Parameters to open a bundled position in a Whirlpool.
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { Instruction, PDA } from "@orca-so/common-sdk";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { PDA, Instruction } from "@orca-so/common-sdk";
|
||||
import { METADATA_PROGRAM_ADDRESS, WHIRLPOOL_NFT_UPDATE_AUTH } from "..";
|
||||
import { Whirlpool } from ".././artifacts/whirlpool";
|
||||
import {
|
||||
OpenPositionBumpsData,
|
||||
OpenPositionWithMetadataBumpsData,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
/**
|
||||
* Parameters to set the collect fee authority in a WhirlpoolsConfig
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
import { PDAUtil } from "../utils/public";
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
/**
|
||||
* Parameters to set the default fee rate for a FeeTier.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
/**
|
||||
* Parameters to set the fee authority in a WhirlpoolsConfig
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
/**
|
||||
* Parameters to set fee rate for a Whirlpool.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
/**
|
||||
* Parameters to set fee rate for a Whirlpool.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
/**
|
||||
* Parameters to update the reward authority at a particular rewardIndex on a Whirlpool.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
/**
|
||||
* Parameters to update the reward authority at a particular rewardIndex on a Whirlpool.
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import { BN, Program } from "@coral-xyz/anchor";
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { BN } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
/**
|
||||
* Parameters to set rewards emissions for a reward in a Whirlpool
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
/**
|
||||
* Parameters to set rewards emissions for a reward in a Whirlpool
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { BN, Program } from "@coral-xyz/anchor";
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import { BN, Program } from "@project-serum/anchor";
|
||||
import { TOKEN_PROGRAM_ID, u64 } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { BN, Program } from "@coral-xyz/anchor";
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
import { BN, Program } from "@project-serum/anchor";
|
||||
import { TOKEN_PROGRAM_ID, u64 } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Program } from "@project-serum/anchor";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Whirlpool } from "../artifacts/whirlpool";
|
||||
|
||||
import { Instruction } from "@orca-so/common-sdk";
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Program } from "@coral-xyz/anchor";
|
||||
import { PDA } from "@orca-so/common-sdk";
|
||||
import { Program } from "@project-serum/anchor";
|
||||
import { WhirlpoolContext } from ".";
|
||||
import { Whirlpool } from "./artifacts/whirlpool";
|
||||
import * as ix from "./instructions";
|
||||
|
@ -468,7 +468,7 @@ export class WhirlpoolIx {
|
|||
|
||||
/**
|
||||
* Deletes a PositionBundle account.
|
||||
*
|
||||
*
|
||||
* #### Special Errors
|
||||
* `PositionBundleNotDeletable` - The provided position bundle has open positions.
|
||||
*
|
||||
|
@ -505,7 +505,7 @@ export class WhirlpoolIx {
|
|||
|
||||
/**
|
||||
* Close a bundled position in a Whirlpool.
|
||||
*
|
||||
*
|
||||
* #### Special Errors
|
||||
* `InvalidBundleIndex` - If the provided bundle index is out of bounds.
|
||||
* `ClosePositionNotEmpty` - The provided position account is not empty.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Address } from "@coral-xyz/anchor";
|
||||
import { AddressUtil } from "@orca-so/common-sdk";
|
||||
import { Address } from "@project-serum/anchor";
|
||||
import { AccountInfo, AccountLayout, MintInfo } from "@solana/spl-token";
|
||||
import { Connection, PublicKey } from "@solana/web3.js";
|
||||
import invariant from "tiny-invariant";
|
||||
|
@ -8,9 +8,9 @@ import {
|
|||
PositionBundleData,
|
||||
PositionData,
|
||||
TickArrayData,
|
||||
WHIRLPOOL_CODER,
|
||||
WhirlpoolData,
|
||||
WhirlpoolsConfigData,
|
||||
WHIRLPOOL_CODER,
|
||||
} from "../..";
|
||||
import { FeeTierData, getAccountSize } from "../../types/public";
|
||||
import {
|
||||
|
@ -190,7 +190,10 @@ export class AccountFetcher {
|
|||
* @param refresh force cache refresh
|
||||
* @returns position bundle account
|
||||
*/
|
||||
public async getPositionBundle(address: Address, refresh = false): Promise<PositionBundleData | null> {
|
||||
public async getPositionBundle(
|
||||
address: Address,
|
||||
refresh = false
|
||||
): Promise<PositionBundleData | null> {
|
||||
return this.get(AddressUtil.toPubKey(address), ParsablePositionBundle, refresh);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
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 * as WhirlpoolIDL from "../../artifacts/whirlpool.json";
|
||||
import {
|
||||
WhirlpoolsConfigData,
|
||||
WhirlpoolData,
|
||||
PositionData,
|
||||
TickArrayData,
|
||||
AccountName,
|
||||
FeeTierData,
|
||||
PositionBundleData,
|
||||
PositionData,
|
||||
TickArrayData,
|
||||
WhirlpoolData,
|
||||
WhirlpoolsConfigData,
|
||||
} from "../../types/public";
|
||||
import { BorshAccountsCoder, Idl } from "@project-serum/anchor";
|
||||
import * as WhirlpoolIDL from "../../artifacts/whirlpool.json";
|
||||
import { TokenUtil } from "@orca-so/common-sdk";
|
||||
|
||||
/**
|
||||
* Static abstract class definition to parse entities.
|
||||
|
@ -151,7 +151,7 @@ export class ParsablePositionBundle {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @category Parsables
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Address } from "@coral-xyz/anchor";
|
||||
import { AddressUtil, DecimalUtil, Percentage } from "@orca-so/common-sdk";
|
||||
import { Address } from "@project-serum/anchor";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import Decimal from "decimal.js";
|
||||
|
@ -72,26 +72,26 @@ function checkLiquidity(
|
|||
type PoolObject = { pool: WhirlpoolData; address: PublicKey };
|
||||
function getMostLiquidPools(
|
||||
quoteTokenMint: PublicKey,
|
||||
poolMap: PoolMap,
|
||||
poolMap: PoolMap
|
||||
): Record<string, PoolObject> {
|
||||
const mostLiquidPools = new Map<string, PoolObject>();
|
||||
Object.entries(poolMap).forEach(([address, pool]) => {
|
||||
const mintA = pool.tokenMintA.toBase58();
|
||||
const mintB = pool.tokenMintB.toBase58();
|
||||
const mintA = pool.tokenMintA.toBase58();
|
||||
const mintB = pool.tokenMintB.toBase58();
|
||||
|
||||
if (pool.liquidity.isZero()) {
|
||||
return;
|
||||
}
|
||||
if (!pool.tokenMintA.equals(quoteTokenMint) && !pool.tokenMintB.equals(quoteTokenMint)) {
|
||||
return;
|
||||
}
|
||||
if (pool.liquidity.isZero()) {
|
||||
return;
|
||||
}
|
||||
if (!pool.tokenMintA.equals(quoteTokenMint) && !pool.tokenMintB.equals(quoteTokenMint)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const baseTokenMint = pool.tokenMintA.equals(quoteTokenMint) ? mintB : mintA;
|
||||
const baseTokenMint = pool.tokenMintA.equals(quoteTokenMint) ? mintB : mintA;
|
||||
|
||||
const existingPool = mostLiquidPools.get(baseTokenMint);
|
||||
if (!existingPool || pool.liquidity.gt(existingPool.pool.liquidity)) {
|
||||
mostLiquidPools.set(baseTokenMint, { address: AddressUtil.toPubKey(address), pool });
|
||||
}
|
||||
const existingPool = mostLiquidPools.get(baseTokenMint);
|
||||
if (!existingPool || pool.liquidity.gt(existingPool.pool.liquidity)) {
|
||||
mostLiquidPools.set(baseTokenMint, { address: AddressUtil.toPubKey(address), pool });
|
||||
}
|
||||
});
|
||||
|
||||
return Object.fromEntries(mostLiquidPools);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Address } from "@coral-xyz/anchor";
|
||||
import { AddressUtil } from "@orca-so/common-sdk";
|
||||
import { Address } from "@project-serum/anchor";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import {
|
||||
DecimalsMap,
|
||||
|
@ -284,7 +284,7 @@ export class PriceModuleUtils {
|
|||
const getQuoteTokenOrder = (mint: PublicKey) => {
|
||||
const index = config.quoteTokens.findIndex((quoteToken) => quoteToken.equals(mint));
|
||||
return index === -1 ? config.quoteTokens.length : index;
|
||||
}
|
||||
};
|
||||
|
||||
// select tick arrays based on the direction of swapQuote
|
||||
// TickArray is a large account, which affects decoding time.
|
||||
|
@ -300,13 +300,13 @@ export class PriceModuleUtils {
|
|||
}
|
||||
|
||||
const aToB = orderA > orderB;
|
||||
|
||||
|
||||
const tickArrayPubkeys = SwapUtils.getTickArrayPublicKeys(
|
||||
pool.tickCurrentIndex,
|
||||
pool.tickSpacing,
|
||||
aToB,
|
||||
programId,
|
||||
new PublicKey(address),
|
||||
new PublicKey(address)
|
||||
);
|
||||
tickArrayPubkeys.forEach((p) => tickArrayAddressSet.add(p.toBase58()));
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { BN } from "@coral-xyz/anchor";
|
||||
import { MathUtil } from "@orca-so/common-sdk";
|
||||
import { BN } from "@project-serum/anchor";
|
||||
import { PositionData, TickData, WhirlpoolData } from "../../types/public";
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { BN } from "@coral-xyz/anchor";
|
||||
import { MathUtil } from "@orca-so/common-sdk";
|
||||
import { BN } from "@project-serum/anchor";
|
||||
import invariant from "tiny-invariant";
|
||||
import { NUM_REWARDS, PositionData, TickData, WhirlpoolData } from "../../types/public";
|
||||
import { BitMath } from "../../utils/math/bit-math";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { BN } from "@coral-xyz/anchor";
|
||||
import { Percentage, ZERO } from "@orca-so/common-sdk";
|
||||
import { BN } from "@project-serum/anchor";
|
||||
import invariant from "tiny-invariant";
|
||||
import { DecreaseLiquidityInput } from "../../instructions";
|
||||
import {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Address } from "@coral-xyz/anchor";
|
||||
import { Percentage } from "@orca-so/common-sdk";
|
||||
import { Address } from "@project-serum/anchor";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { AccountFetcher } from "../..";
|
||||
import { SwapErrorCode, WhirlpoolsError } from "../../errors/errors";
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
import { Address, BN } from "@coral-xyz/anchor";
|
||||
import { AddressUtil, DecimalUtil, Percentage, ZERO } from "@orca-so/common-sdk";
|
||||
import { Address, BN } from "@project-serum/anchor";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import Decimal from "decimal.js";
|
||||
import invariant from "tiny-invariant";
|
||||
import { IncreaseLiquidityInput } from "../../instructions";
|
||||
import {
|
||||
PositionUtil,
|
||||
PositionStatus,
|
||||
getLiquidityFromTokenA,
|
||||
adjustForSlippage,
|
||||
getLiquidityFromTokenA,
|
||||
getLiquidityFromTokenB,
|
||||
getTokenAFromLiquidity,
|
||||
getTokenBFromLiquidity,
|
||||
getLiquidityFromTokenB,
|
||||
PositionStatus,
|
||||
PositionUtil,
|
||||
} from "../../utils/position-util";
|
||||
import { PriceMath, TickUtil } from "../../utils/public";
|
||||
import { Whirlpool } from "../../whirlpool-client";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Address, BN } from "@coral-xyz/anchor";
|
||||
import { AddressUtil, Percentage } from "@orca-so/common-sdk";
|
||||
import { Address, BN } from "@project-serum/anchor";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import invariant from "tiny-invariant";
|
||||
import { SwapInput } from "../../instructions";
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { BN } from "@coral-xyz/anchor";
|
||||
import { ZERO } from "@orca-so/common-sdk";
|
||||
import { SwapQuoteParam, SwapQuote } from "../public";
|
||||
import { BN } from "@project-serum/anchor";
|
||||
import { TickArraySequence } from "./tick-array-sequence";
|
||||
import { computeSwap } from "./swap-manager";
|
||||
import { MAX_SQRT_PRICE, MAX_SWAP_TICK_ARRAYS, MIN_SQRT_PRICE } from "../../types/public";
|
||||
import { SwapErrorCode, WhirlpoolsError } from "../../errors/errors";
|
||||
import { MAX_SQRT_PRICE, MAX_SWAP_TICK_ARRAYS, MIN_SQRT_PRICE } from "../../types/public";
|
||||
import { SwapQuote, SwapQuoteParam } from "../public";
|
||||
import { computeSwap } from "./swap-manager";
|
||||
import { TickArraySequence } from "./tick-array-sequence";
|
||||
|
||||
/**
|
||||
* Figure out the quote parameters needed to successfully complete this trade on chain
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { BN, BorshAccountsCoder, Idl } from "@project-serum/anchor";
|
||||
import { BN, BorshAccountsCoder, Idl } from "@coral-xyz/anchor";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import WhirlpoolIDL from "../../artifacts/whirlpool.json";
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { BN } from "@project-serum/anchor";
|
||||
import { BN } from "@coral-xyz/anchor";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
export * from "./constants";
|
||||
export * from "./anchor-types";
|
||||
export * from "./ix-types";
|
||||
export * from "./client-types";
|
||||
export * from "./constants";
|
||||
export * from "./ix-types";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Address } from "@coral-xyz/anchor";
|
||||
import { AddressUtil } from "@orca-so/common-sdk";
|
||||
import { Address } from "@project-serum/anchor";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import {
|
||||
Edge,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Address } from "@coral-xyz/anchor";
|
||||
import { AddressUtil } from "@orca-so/common-sdk";
|
||||
import { Address } from "@project-serum/anchor";
|
||||
import { AccountFetcher } from "../../../network/public";
|
||||
import { convertListToMap } from "../../txn-utils";
|
||||
import { AdjacencyListPoolGraph } from "../adjacency-list-pool-graph";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Address } from "@coral-xyz/anchor";
|
||||
import { AddressUtil } from "@orca-so/common-sdk";
|
||||
import { Address } from "@project-serum/anchor";
|
||||
|
||||
/**
|
||||
* A utility class for working with pool graphs
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Address } from "@project-serum/anchor";
|
||||
import { Address } from "@coral-xyz/anchor";
|
||||
|
||||
/**
|
||||
* An object containing the token pairs of a Whirlpool.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { OpenPositionParams } from "../instructions";
|
||||
import * as anchor from "@project-serum/anchor";
|
||||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { SystemProgram } from "@solana/web3.js";
|
||||
import { OpenPositionParams } from "../instructions";
|
||||
|
||||
export function openPositionAccounts(params: OpenPositionParams) {
|
||||
const {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { ZERO, ONE, MathUtil, TWO, U64_MAX } from "@orca-so/common-sdk";
|
||||
import { BN } from "@project-serum/anchor";
|
||||
import { BN } from "@coral-xyz/anchor";
|
||||
import { MathUtil, ONE, TWO, U64_MAX, ZERO } from "@orca-so/common-sdk";
|
||||
import { MathErrorCode, WhirlpoolsError } from "../../errors/errors";
|
||||
|
||||
export class BitMath {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { BN } from "@coral-xyz/anchor";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { BN } from "@project-serum/anchor";
|
||||
import { getAmountDeltaA, getAmountDeltaB, getNextSqrtPrice } from "./token-math";
|
||||
import { BitMath } from "./bit-math";
|
||||
import { FEE_RATE_MUL_VALUE } from "../../types/public";
|
||||
import { BitMath } from "./bit-math";
|
||||
import { getAmountDeltaA, getAmountDeltaB, getNextSqrtPrice } from "./token-math";
|
||||
|
||||
export type SwapStep = {
|
||||
amountIn: BN;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { BN } from "@coral-xyz/anchor";
|
||||
import { Percentage, U64_MAX, ZERO } from "@orca-so/common-sdk";
|
||||
import { BN } from "@project-serum/anchor";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { MathErrorCode, TokenErrorCode, WhirlpoolsError } from "../../errors/errors";
|
||||
import { MAX_SQRT_PRICE, MIN_SQRT_PRICE } from "../../types/public";
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { BN } from "@coral-xyz/anchor";
|
||||
import { MathUtil, Percentage } from "@orca-so/common-sdk";
|
||||
import { BN } from "@project-serum/anchor";
|
||||
import {
|
||||
getLowerSqrtPriceFromTokenA,
|
||||
getLowerSqrtPriceFromTokenB,
|
||||
getUpperSqrtPriceFromTokenA,
|
||||
getUpperSqrtPriceFromTokenB,
|
||||
getLowerSqrtPriceFromTokenB,
|
||||
} from "./swap-utils";
|
||||
|
||||
export enum SwapDirection {
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
import { TransactionBuilder, Instruction } from "@orca-so/common-sdk";
|
||||
import { Instruction, TransactionBuilder } from "@orca-so/common-sdk";
|
||||
import { WhirlpoolContext } from "../../context";
|
||||
|
||||
export function toTx(ctx: WhirlpoolContext, ix: Instruction): TransactionBuilder {
|
||||
return new TransactionBuilder(ctx.provider.connection, ctx.provider.wallet).addInstruction(ix);
|
||||
return new TransactionBuilder(
|
||||
ctx.provider.connection,
|
||||
ctx.provider.wallet,
|
||||
ctx.txBuilderOpts
|
||||
).addInstruction(ix);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { BN } from "@coral-xyz/anchor";
|
||||
import { AddressUtil } from "@orca-so/common-sdk";
|
||||
import { BN } from "@project-serum/anchor";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { METADATA_PROGRAM_ADDRESS } from "../../types/public";
|
||||
import { PriceMath } from "./price-math";
|
||||
|
@ -199,15 +199,9 @@ export class PDAUtil {
|
|||
* @param positionBundleMintKey
|
||||
* @returns
|
||||
*/
|
||||
public static getPositionBundle(
|
||||
programId: PublicKey,
|
||||
positionBundleMintKey: PublicKey,
|
||||
) {
|
||||
public static getPositionBundle(programId: PublicKey, positionBundleMintKey: PublicKey) {
|
||||
return AddressUtil.findProgramAddress(
|
||||
[
|
||||
Buffer.from(PDA_POSITION_BUNDLE_SEED),
|
||||
positionBundleMintKey.toBuffer(),
|
||||
],
|
||||
[Buffer.from(PDA_POSITION_BUNDLE_SEED), positionBundleMintKey.toBuffer()],
|
||||
programId
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Address, BN } from "@coral-xyz/anchor";
|
||||
import { AddressUtil, MathUtil, Percentage } from "@orca-so/common-sdk";
|
||||
import { Address, BN } from "@project-serum/anchor";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import Decimal from "decimal.js";
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
import invariant from "tiny-invariant";
|
||||
import {
|
||||
PositionBundleData,
|
||||
POSITION_BUNDLE_SIZE,
|
||||
} from "../../types/public";
|
||||
|
||||
import { PositionBundleData, POSITION_BUNDLE_SIZE } from "../../types/public";
|
||||
|
||||
/**
|
||||
* A collection of utility functions when interacting with a PositionBundle.
|
||||
|
@ -80,7 +76,7 @@ export class PositionBundleUtil {
|
|||
if (occupied) {
|
||||
result.push(index);
|
||||
}
|
||||
})
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -96,7 +92,7 @@ export class PositionBundleUtil {
|
|||
if (!occupied) {
|
||||
result.push(index);
|
||||
}
|
||||
})
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -106,7 +102,7 @@ export class PositionBundleUtil {
|
|||
* @param positionBundle The position bundle to be checked
|
||||
* @returns The first unoccupied bundle index, null if the position bundle is full
|
||||
*/
|
||||
public static findUnoccupiedBundleIndex(positionBundle: PositionBundleData): number|null {
|
||||
public static findUnoccupiedBundleIndex(positionBundle: PositionBundleData): number | null {
|
||||
const unoccupied = PositionBundleUtil.getUnoccupiedBundleIndexes(positionBundle);
|
||||
return unoccupied.length === 0 ? null : unoccupied[0];
|
||||
}
|
||||
|
@ -120,10 +116,10 @@ export class PositionBundleUtil {
|
|||
public static convertBitmapToArray(positionBundle: PositionBundleData): boolean[] {
|
||||
const result: boolean[] = [];
|
||||
positionBundle.positionBitmap.map((bitmap) => {
|
||||
for (let offset=0; offset<8; offset++) {
|
||||
for (let offset = 0; offset < 8; offset++) {
|
||||
result.push((bitmap & (1 << offset)) !== 0);
|
||||
}
|
||||
})
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { BN } from "@coral-xyz/anchor";
|
||||
import { MathUtil } from "@orca-so/common-sdk";
|
||||
import { BN } from "@project-serum/anchor";
|
||||
import Decimal from "decimal.js";
|
||||
import { MAX_SQRT_PRICE, MIN_SQRT_PRICE } from "../../types/public";
|
||||
import { TickUtil } from "./tick-utils";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Address } from "@coral-xyz/anchor";
|
||||
import { AddressUtil, Percentage, U64_MAX, ZERO } from "@orca-so/common-sdk";
|
||||
import { Address } from "@project-serum/anchor";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import { WhirlpoolContext } from "../..";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Address } from "@coral-xyz/anchor";
|
||||
import { AddressUtil, PDA } from "@orca-so/common-sdk";
|
||||
import { Address } from "@project-serum/anchor";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import invariant from "tiny-invariant";
|
||||
import { AccountFetcher } from "../../network/public";
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
import { TransactionBuilder } from "@orca-so/common-sdk";
|
||||
import { WhirlpoolContext } from "..";
|
||||
import {
|
||||
TransactionBuilder,
|
||||
TransactionBuilderOptions,
|
||||
defaultTransactionBuilderOptions,
|
||||
} from "@orca-so/common-sdk";
|
||||
import { WhirlpoolContext, WhirlpoolContextOpts as WhirlpoolContextOptions } from "..";
|
||||
|
||||
export function convertListToMap<T>(fetchedData: T[], addresses: string[]): Record<string, T> {
|
||||
const result: Record<string, T> = {};
|
||||
|
@ -38,13 +42,32 @@ export async function checkMergedTransactionSizeIsValid(
|
|||
lastValidBlockHeight: number;
|
||||
}>
|
||||
): Promise<boolean> {
|
||||
const merged = new TransactionBuilder(ctx.connection, ctx.wallet);
|
||||
const merged = new TransactionBuilder(ctx.connection, ctx.wallet, ctx.txBuilderOpts);
|
||||
builders.forEach((builder) => merged.addInstruction(builder.compressIx(true)));
|
||||
|
||||
try {
|
||||
const size = await merged.txnSize({ latestBlockhash }); // throws if txnSize is too large
|
||||
const size = await merged.txnSize({
|
||||
latestBlockhash,
|
||||
});
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function contextOptionsToBuilderOptions(
|
||||
opts: WhirlpoolContextOptions
|
||||
): TransactionBuilderOptions | undefined {
|
||||
return {
|
||||
defaultBuildOption: {
|
||||
...defaultTransactionBuilderOptions.defaultBuildOption,
|
||||
...opts.userDefaultBuildOptions,
|
||||
},
|
||||
defaultSendOption: {
|
||||
...defaultTransactionBuilderOptions.defaultSendOption,
|
||||
...opts.userDefaultSendOptions,
|
||||
},
|
||||
defaultConfirmationCommitment:
|
||||
opts.userDefaultConfirmCommitment ??
|
||||
defaultTransactionBuilderOptions.defaultConfirmationCommitment,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Address } from "@coral-xyz/anchor";
|
||||
import { Percentage, TransactionBuilder } from "@orca-so/common-sdk";
|
||||
import { Address } from "@project-serum/anchor";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { WhirlpoolContext } from "./context";
|
||||
import { WhirlpoolClientImpl } from "./impl/whirlpool-client-impl";
|
||||
|
|
|
@ -1,35 +1,30 @@
|
|||
import * as anchor from "@project-serum/anchor";
|
||||
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 {
|
||||
buildWhirlpoolClient,
|
||||
increaseLiquidityQuoteByInputTokenWithParams,
|
||||
InitPoolParams,
|
||||
PositionBundleData,
|
||||
POSITION_BUNDLE_SIZE,
|
||||
toTx,
|
||||
PositionBundleData,
|
||||
WhirlpoolContext,
|
||||
WhirlpoolIx,
|
||||
buildWhirlpoolClient,
|
||||
increaseLiquidityQuoteByInputTokenWithParams,
|
||||
toTx
|
||||
} from "../../src";
|
||||
import {
|
||||
approveToken,
|
||||
TickSpacing,
|
||||
transfer,
|
||||
ONE_SOL,
|
||||
TickSpacing,
|
||||
approveToken, createAssociatedTokenAccount,
|
||||
systemTransferTx,
|
||||
createAssociatedTokenAccount,
|
||||
transfer
|
||||
} from "../utils";
|
||||
import { PDA, Percentage } from "@orca-so/common-sdk";
|
||||
import { initializePositionBundle, initTestPool, openBundledPosition, openPosition } from "../utils/init-utils";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { initTestPool, initializePositionBundle, openBundledPosition, openPosition } from "../utils/init-utils";
|
||||
import { mintTokensToTestAccount } from "../utils/test-builders";
|
||||
|
||||
describe("close_bundled_position", () => {
|
||||
const provider = anchor.AnchorProvider.local(undefined, {
|
||||
commitment: "confirmed",
|
||||
preflightCommitment: "confirmed",
|
||||
});
|
||||
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const client = buildWhirlpoolClient(ctx);
|
||||
|
@ -67,7 +62,7 @@ describe("close_bundled_position", () => {
|
|||
}
|
||||
|
||||
function checkBitmap(account: PositionBundleData, openedBundleIndexes: number[]) {
|
||||
for (let i=0; i<POSITION_BUNDLE_SIZE; i++) {
|
||||
for (let i = 0; i < POSITION_BUNDLE_SIZE; i++) {
|
||||
if (openedBundleIndexes.includes(i)) {
|
||||
assert.ok(checkBitmapIsOpened(account, i));
|
||||
}
|
||||
|
@ -108,7 +103,6 @@ describe("close_bundled_position", () => {
|
|||
receiver: receiverKeypair.publicKey,
|
||||
})
|
||||
).buildAndExecute();
|
||||
|
||||
const postAccount = await fetcher.getPosition(bundledPositionPda.publicKey, true);
|
||||
const postPositionBundle = await fetcher.getPositionBundle(positionBundleInfo.positionBundlePda.publicKey, true);
|
||||
checkBitmap(postPositionBundle!, []);
|
||||
|
@ -144,7 +138,6 @@ describe("close_bundled_position", () => {
|
|||
receiver: ctx.wallet.publicKey,
|
||||
})
|
||||
);
|
||||
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
/0x7d6/ // ConstraintSeeds (seed constraint was violated)
|
||||
|
@ -179,7 +172,6 @@ describe("close_bundled_position", () => {
|
|||
|
||||
// close...
|
||||
await tx.buildAndExecute();
|
||||
|
||||
// re-close...
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
|
@ -240,7 +232,6 @@ describe("close_bundled_position", () => {
|
|||
receiver: ctx.wallet.publicKey,
|
||||
})
|
||||
);
|
||||
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
/0x1775/ // ClosePositionNotEmpty
|
||||
|
@ -268,7 +259,6 @@ describe("close_bundled_position", () => {
|
|||
tickLowerIndex,
|
||||
tickUpperIndex
|
||||
);
|
||||
|
||||
const tx = toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.closeBundledPositionIx(ctx.program, {
|
||||
|
@ -280,7 +270,6 @@ describe("close_bundled_position", () => {
|
|||
receiver: ctx.wallet.publicKey,
|
||||
})
|
||||
);
|
||||
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
/0x7d6/ // ConstraintSeeds (seed constraint was violated)
|
||||
|
@ -300,7 +289,6 @@ describe("close_bundled_position", () => {
|
|||
tickLowerIndex,
|
||||
tickUpperIndex
|
||||
);
|
||||
|
||||
const tx = toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.closeBundledPositionIx(ctx.program, {
|
||||
|
@ -312,7 +300,6 @@ describe("close_bundled_position", () => {
|
|||
receiver: ctx.wallet.publicKey,
|
||||
})
|
||||
);
|
||||
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
/0x7d6/ // ConstraintSeeds (seed constraint was violated)
|
||||
|
@ -338,7 +325,6 @@ describe("close_bundled_position", () => {
|
|||
funderKeypair.publicKey,
|
||||
ctx.wallet.publicKey,
|
||||
);
|
||||
|
||||
const tx = toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.closeBundledPositionIx(ctx.program, {
|
||||
|
@ -370,7 +356,6 @@ describe("close_bundled_position", () => {
|
|||
tickLowerIndex,
|
||||
tickUpperIndex
|
||||
);
|
||||
|
||||
const tx = toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.closeBundledPositionIx(ctx.program, {
|
||||
|
@ -401,7 +386,6 @@ describe("close_bundled_position", () => {
|
|||
tickLowerIndex,
|
||||
tickUpperIndex
|
||||
);
|
||||
|
||||
const tx = toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.closeBundledPositionIx(ctx.program, {
|
||||
|
@ -461,7 +445,6 @@ describe("close_bundled_position", () => {
|
|||
funderKeypair.publicKey,
|
||||
1,
|
||||
);
|
||||
|
||||
await tx.buildAndExecute();
|
||||
const positionBundle = await fetcher.getPositionBundle(positionBundleInfo.positionBundlePda.publicKey, true);
|
||||
checkBitmapIsClosed(positionBundle!, 0);
|
||||
|
@ -544,7 +527,6 @@ describe("close_bundled_position", () => {
|
|||
funderKeypair.publicKey,
|
||||
0,
|
||||
);
|
||||
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
/0x1784/ // InvalidPositionTokenAmount
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import * as anchor from "@project-serum/anchor";
|
||||
import * as anchor from "@coral-xyz/anchor";
|
||||
import * as assert from "assert";
|
||||
import { toTx, WhirlpoolIx } from "../../src";
|
||||
import { WhirlpoolContext } from "../../src/context";
|
||||
|
@ -9,14 +9,14 @@ import {
|
|||
setAuthority,
|
||||
TickSpacing,
|
||||
transfer,
|
||||
ZERO_BN,
|
||||
ZERO_BN
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { WhirlpoolTestFixture } from "../utils/fixture";
|
||||
import { initializePositionBundle, initTestPool, initTestPoolWithLiquidity, openBundledPosition, openPosition } from "../utils/init-utils";
|
||||
|
||||
describe("close_position", () => {
|
||||
const provider = anchor.AnchorProvider.local();
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
|
||||
|
@ -189,7 +189,7 @@ describe("close_position", () => {
|
|||
positionTokenAccount: params.positionTokenAccount,
|
||||
})
|
||||
).buildAndExecute(),
|
||||
/Signature verification failed/
|
||||
/.*signature verification fail.*/i
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -227,7 +227,7 @@ describe("close_position", () => {
|
|||
positionTokenAccount: params.positionTokenAccount,
|
||||
})
|
||||
).buildAndExecute(),
|
||||
/Signature verification failed/
|
||||
/.*signature verification fail.*/i
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { MathUtil } from "@orca-so/common-sdk";
|
||||
import * as anchor from "@project-serum/anchor";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import * as assert from "assert";
|
||||
import Decimal from "decimal.js";
|
||||
|
@ -12,7 +12,7 @@ import {
|
|||
toTx,
|
||||
WhirlpoolContext,
|
||||
WhirlpoolData,
|
||||
WhirlpoolIx,
|
||||
WhirlpoolIx
|
||||
} from "../../src";
|
||||
import {
|
||||
approveToken,
|
||||
|
@ -20,14 +20,14 @@ import {
|
|||
getTokenBalance,
|
||||
TickSpacing,
|
||||
transfer,
|
||||
ZERO_BN,
|
||||
ZERO_BN
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { WhirlpoolTestFixture } from "../utils/fixture";
|
||||
import { initTestPool } from "../utils/init-utils";
|
||||
|
||||
describe("collect_fees", () => {
|
||||
const provider = anchor.AnchorProvider.local();
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
@ -498,7 +498,7 @@ describe("collect_fees", () => {
|
|||
tokenVaultB: tokenVaultBKeypair.publicKey,
|
||||
})
|
||||
).buildAndExecute(),
|
||||
/Signature verification failed/
|
||||
/.*signature verification fail.*/i
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { MathUtil } from "@orca-so/common-sdk";
|
||||
import * as anchor from "@project-serum/anchor";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import * as assert from "assert";
|
||||
import Decimal from "decimal.js";
|
||||
import { PDAUtil, toTx, WhirlpoolContext, WhirlpoolData, WhirlpoolIx } from "../../src";
|
||||
import { createTokenAccount, getTokenBalance, TickSpacing, ZERO_BN } from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { WhirlpoolTestFixture } from "../utils/fixture";
|
||||
import { initTestPool } from "../utils/init-utils";
|
||||
|
||||
describe("collect_protocol_fees", () => {
|
||||
const provider = anchor.AnchorProvider.local();
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
@ -163,7 +164,7 @@ describe("collect_protocol_fees", () => {
|
|||
tokenOwnerAccountB: tokenAccountB,
|
||||
})
|
||||
).buildAndExecute(),
|
||||
/Signature verification failed/
|
||||
/.*signature verification fail.*/i
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { MathUtil } from "@orca-so/common-sdk";
|
||||
import * as anchor from "@project-serum/anchor";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import * as assert from "assert";
|
||||
import Decimal from "decimal.js";
|
||||
|
@ -20,12 +20,13 @@ import {
|
|||
transfer,
|
||||
ZERO_BN
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { WhirlpoolTestFixture } from "../utils/fixture";
|
||||
import { initTestPool } from "../utils/init-utils";
|
||||
|
||||
describe("collect_reward", () => {
|
||||
const provider = anchor.AnchorProvider.local();
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
@ -67,7 +68,9 @@ describe("collect_reward", () => {
|
|||
rewards,
|
||||
} = fixture.getInfos();
|
||||
|
||||
await sleep(500);
|
||||
// accrue rewards
|
||||
await sleep(1200);
|
||||
|
||||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.updateFeesAndRewardsIx(ctx.program, {
|
||||
|
@ -91,6 +94,11 @@ describe("collect_reward", () => {
|
|||
timeStampInSeconds: pool.getData().rewardLastUpdatedTimestamp
|
||||
});
|
||||
|
||||
// Check that the expectation is not zero
|
||||
for (let i = 0; i < NUM_REWARDS; i++) {
|
||||
assert.ok(!expectation[i]!.isZero());
|
||||
}
|
||||
|
||||
// Perform collect rewards tx
|
||||
for (let i = 0; i < NUM_REWARDS; i++) {
|
||||
const rewardOwnerAccount = await createTokenAccount(
|
||||
|
@ -144,6 +152,10 @@ describe("collect_reward", () => {
|
|||
positions,
|
||||
rewards,
|
||||
} = fixture.getInfos();
|
||||
|
||||
// accrue rewards
|
||||
await sleep(1200);
|
||||
|
||||
const rewardOwnerAccount = await createTokenAccount(
|
||||
provider,
|
||||
rewards[0].rewardMint,
|
||||
|
@ -199,6 +211,10 @@ describe("collect_reward", () => {
|
|||
positions,
|
||||
rewards,
|
||||
} = fixture.getInfos();
|
||||
|
||||
// accrue rewards
|
||||
await sleep(1200);
|
||||
|
||||
const rewardOwnerAccount = await createTokenAccount(
|
||||
provider,
|
||||
rewards[0].rewardMint,
|
||||
|
@ -259,6 +275,10 @@ describe("collect_reward", () => {
|
|||
positions,
|
||||
rewards,
|
||||
} = fixture.getInfos();
|
||||
|
||||
// accrue rewards
|
||||
await sleep(1200);
|
||||
|
||||
const rewardOwnerAccount = await createTokenAccount(
|
||||
provider,
|
||||
rewards[0].rewardMint,
|
||||
|
@ -304,6 +324,10 @@ describe("collect_reward", () => {
|
|||
poolInitInfo: { whirlpoolPda },
|
||||
positions,
|
||||
} = fixture.getInfos();
|
||||
|
||||
// accrue rewards
|
||||
await sleep(1200);
|
||||
|
||||
const fakeRewardMint = await createMint(provider);
|
||||
const rewardOwnerAccount = await createTokenAccount(
|
||||
provider,
|
||||
|
@ -341,6 +365,9 @@ describe("collect_reward", () => {
|
|||
});
|
||||
const { positions, rewards } = fixture.getInfos();
|
||||
|
||||
// accrue rewards
|
||||
await sleep(1200);
|
||||
|
||||
const {
|
||||
poolInitInfo: { whirlpoolPda },
|
||||
} = await initTestPool(ctx, TickSpacing.Standard);
|
||||
|
@ -383,6 +410,9 @@ describe("collect_reward", () => {
|
|||
rewards,
|
||||
} = fixture.getInfos();
|
||||
|
||||
// accrue rewards
|
||||
await sleep(1200);
|
||||
|
||||
const rewardOwnerAccount = await createTokenAccount(
|
||||
provider,
|
||||
rewards[0].rewardMint,
|
||||
|
@ -428,6 +458,9 @@ describe("collect_reward", () => {
|
|||
rewards,
|
||||
} = fixture.getInfos();
|
||||
|
||||
// accrue rewards
|
||||
await sleep(1200);
|
||||
|
||||
const rewardOwnerAccount = await createTokenAccount(
|
||||
provider,
|
||||
rewards[0].rewardMint,
|
||||
|
@ -468,6 +501,10 @@ describe("collect_reward", () => {
|
|||
positions,
|
||||
rewards,
|
||||
} = fixture.getInfos();
|
||||
|
||||
// accrue rewards
|
||||
await sleep(1200);
|
||||
|
||||
const rewardOwnerAccount = await createTokenAccount(
|
||||
provider,
|
||||
rewards[0].rewardMint,
|
||||
|
@ -509,6 +546,10 @@ describe("collect_reward", () => {
|
|||
positions,
|
||||
rewards,
|
||||
} = fixture.getInfos();
|
||||
|
||||
// accrue rewards
|
||||
await sleep(1200);
|
||||
|
||||
const rewardOwnerAccount = await createTokenAccount(
|
||||
provider,
|
||||
rewards[0].rewardMint,
|
||||
|
@ -551,6 +592,10 @@ describe("collect_reward", () => {
|
|||
positions,
|
||||
rewards,
|
||||
} = fixture.getInfos();
|
||||
|
||||
// accrue rewards
|
||||
await sleep(1200);
|
||||
|
||||
const rewardOwnerAccount = await createTokenAccount(
|
||||
provider,
|
||||
rewards[0].rewardMint,
|
||||
|
@ -571,7 +616,7 @@ describe("collect_reward", () => {
|
|||
rewardIndex: 0,
|
||||
})
|
||||
).buildAndExecute(),
|
||||
/Signature verification failed/
|
||||
/.*signature verification fail.*/i
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -591,6 +636,10 @@ describe("collect_reward", () => {
|
|||
positions,
|
||||
rewards,
|
||||
} = fixture.getInfos();
|
||||
|
||||
// accrue rewards
|
||||
await sleep(1200);
|
||||
|
||||
const rewardOwnerAccount = await createTokenAccount(
|
||||
provider,
|
||||
rewards[0].rewardMint,
|
||||
|
@ -629,6 +678,10 @@ describe("collect_reward", () => {
|
|||
positions,
|
||||
rewards,
|
||||
} = fixture.getInfos();
|
||||
|
||||
// accrue rewards
|
||||
await sleep(1200);
|
||||
|
||||
const rewardOwnerAccount = await createTokenAccount(
|
||||
provider,
|
||||
tokenMintA,
|
||||
|
@ -667,6 +720,10 @@ describe("collect_reward", () => {
|
|||
positions,
|
||||
rewards,
|
||||
} = fixture.getInfos();
|
||||
|
||||
// accrue rewards
|
||||
await sleep(1200);
|
||||
|
||||
const rewardOwnerAccount = await createTokenAccount(
|
||||
provider,
|
||||
tokenMintA,
|
||||
|
|
|
@ -1,33 +1,35 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { MathUtil, Percentage } from "@orca-so/common-sdk";
|
||||
import * as anchor from "@project-serum/anchor";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import * as assert from "assert";
|
||||
import Decimal from "decimal.js";
|
||||
import {
|
||||
PositionData,
|
||||
TickArrayData,
|
||||
toTx,
|
||||
WhirlpoolContext,
|
||||
WhirlpoolData,
|
||||
WhirlpoolIx,
|
||||
toTx
|
||||
} from "../../src";
|
||||
import { decreaseLiquidityQuoteByLiquidityWithParams } from "../../src/quotes/public/decrease-liquidity-quote";
|
||||
import {
|
||||
TickSpacing,
|
||||
ZERO_BN,
|
||||
approveToken,
|
||||
assertTick,
|
||||
createAndMintToTokenAccount,
|
||||
createMint,
|
||||
createTokenAccount,
|
||||
TickSpacing,
|
||||
transfer,
|
||||
ZERO_BN,
|
||||
sleep,
|
||||
transfer
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { WhirlpoolTestFixture } from "../utils/fixture";
|
||||
import { initTestPool, initTickArray, openPosition } from "../utils/init-utils";
|
||||
|
||||
describe("decrease_liquidity", () => {
|
||||
const provider = anchor.AnchorProvider.local();
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
@ -45,6 +47,9 @@ describe("decrease_liquidity", () => {
|
|||
const { whirlpoolPda, tokenVaultAKeypair, tokenVaultBKeypair } = poolInitInfo;
|
||||
const poolBefore = (await fetcher.getPool(whirlpoolPda.publicKey, true)) as WhirlpoolData;
|
||||
|
||||
// To check if rewardLastUpdatedTimestamp is updated
|
||||
await sleep(1200);
|
||||
|
||||
const removalQuote = decreaseLiquidityQuoteByLiquidityWithParams({
|
||||
liquidity: new anchor.BN(1_000_000),
|
||||
sqrtPrice: poolBefore.sqrtPrice,
|
||||
|
@ -73,7 +78,7 @@ describe("decrease_liquidity", () => {
|
|||
|
||||
const remainingLiquidity = liquidityAmount.sub(removalQuote.liquidityAmount);
|
||||
const poolAfter = (await fetcher.getPool(whirlpoolPda.publicKey, true)) as WhirlpoolData;
|
||||
assert.ok(poolAfter.rewardLastUpdatedTimestamp.gte(poolBefore.rewardLastUpdatedTimestamp));
|
||||
assert.ok(poolAfter.rewardLastUpdatedTimestamp.gt(poolBefore.rewardLastUpdatedTimestamp));
|
||||
assert.ok(poolAfter.liquidity.eq(remainingLiquidity));
|
||||
|
||||
const position = await fetcher.getPosition(positions[0].publicKey, true);
|
||||
|
@ -778,7 +783,7 @@ describe("decrease_liquidity", () => {
|
|||
tickArrayUpper: position.tickArrayUpper,
|
||||
})
|
||||
).buildAndExecute(),
|
||||
/Signature verification failed/
|
||||
/.*signature verification fail.*/i
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { PDA } from "@orca-so/common-sdk";
|
||||
import * as anchor from "@project-serum/anchor";
|
||||
import { ASSOCIATED_TOKEN_PROGRAM_ID, Token, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { Keypair } from "@solana/web3.js";
|
||||
import * as assert from "assert";
|
||||
import { InitPoolParams, METADATA_PROGRAM_ADDRESS, PositionBundleData, POSITION_BUNDLE_SIZE, toTx, WhirlpoolIx } from "../../src";
|
||||
import { InitPoolParams, POSITION_BUNDLE_SIZE, PositionBundleData, toTx, WhirlpoolIx } from "../../src";
|
||||
import { WhirlpoolContext } from "../../src/context";
|
||||
import {
|
||||
approveToken,
|
||||
|
@ -11,17 +11,15 @@ import {
|
|||
ONE_SOL,
|
||||
systemTransferTx,
|
||||
TickSpacing,
|
||||
transfer,
|
||||
transfer
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { initializePositionBundle, initializePositionBundleWithMetadata, initTestPool, openBundledPosition } from "../utils/init-utils";
|
||||
|
||||
describe("delete_position_bundle", () => {
|
||||
const provider = anchor.AnchorProvider.local(undefined, {
|
||||
commitment: "confirmed",
|
||||
preflightCommitment: "confirmed",
|
||||
});
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
||||
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
@ -402,7 +400,7 @@ describe("delete_position_bundle", () => {
|
|||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
/0x7dc/ // ConstraintAddress
|
||||
);
|
||||
);
|
||||
});
|
||||
|
||||
it("should be failed: invalid position bundle mint", async () => {
|
||||
|
@ -429,7 +427,7 @@ describe("delete_position_bundle", () => {
|
|||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
/0x7dc/ // ConstraintAddress
|
||||
);
|
||||
);
|
||||
});
|
||||
|
||||
it("should be failed: invalid ATA (amount is zero)", async () => {
|
||||
|
@ -448,7 +446,7 @@ describe("delete_position_bundle", () => {
|
|||
ctx.wallet.publicKey,
|
||||
[],
|
||||
1
|
||||
)
|
||||
)
|
||||
],
|
||||
cleanupInstructions: [],
|
||||
signers: []
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { MathUtil } from "@orca-so/common-sdk";
|
||||
import * as anchor from "@project-serum/anchor";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import * as assert from "assert";
|
||||
|
@ -9,16 +9,17 @@ import {
|
|||
PriceModuleUtils, WhirlpoolContext
|
||||
} from "../../src";
|
||||
import { TickSpacing } from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import {
|
||||
buildTestAquariums,
|
||||
FundedPositionParams,
|
||||
buildTestAquariums,
|
||||
getDefaultAquarium,
|
||||
initTestPoolWithLiquidity
|
||||
} from "../utils/init-utils";
|
||||
|
||||
// TODO: Move these tests to use mock data instead of relying on solana localnet. It's very slow.
|
||||
describe("get_pool_prices", () => {
|
||||
const provider = anchor.AnchorProvider.env();
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const context = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
|
||||
|
@ -268,7 +269,7 @@ describe("get_pool_prices", () => {
|
|||
// mints are sorted (mintKeys[0] < mintKeys[1] < mintKeys[2])
|
||||
const fetchedTickArrayForPool0 = 1; // A to B direction (mintKeys[0] to mintKeys[1])
|
||||
const fetchedTickArrayForPool1 = 1; // A to B direction (mintKeys[1] to mintKeys[2])
|
||||
|
||||
|
||||
assert.equal(Object.keys(poolMap).length, 2);
|
||||
assert.equal(Object.keys(tickArrayMap).length, fetchedTickArrayForPool0 + fetchedTickArrayForPool1);
|
||||
assert.equal(Object.keys(priceMap).length, 3);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { MathUtil, TransactionBuilder } from "@orca-so/common-sdk";
|
||||
import * as anchor from "@project-serum/anchor";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import * as assert from "assert";
|
||||
import Decimal from "decimal.js";
|
||||
|
@ -9,34 +9,36 @@ import {
|
|||
PriceMath,
|
||||
TickArrayData,
|
||||
TickUtil,
|
||||
toTx,
|
||||
WhirlpoolContext,
|
||||
WhirlpoolData,
|
||||
WhirlpoolIx,
|
||||
toTx
|
||||
} from "../../src";
|
||||
import { PoolUtil, toTokenAmount } from "../../src/utils/public/pool-utils";
|
||||
import {
|
||||
MAX_U64,
|
||||
TickSpacing,
|
||||
ZERO_BN,
|
||||
approveToken,
|
||||
assertTick,
|
||||
createAndMintToTokenAccount,
|
||||
createMint,
|
||||
createTokenAccount,
|
||||
getTokenBalance,
|
||||
MAX_U64,
|
||||
TickSpacing,
|
||||
transfer,
|
||||
ZERO_BN,
|
||||
sleep,
|
||||
transfer
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { WhirlpoolTestFixture } from "../utils/fixture";
|
||||
import { initTestPool, initTickArray, openPosition } from "../utils/init-utils";
|
||||
import {
|
||||
generateDefaultInitTickArrayParams,
|
||||
generateDefaultOpenPositionParams,
|
||||
generateDefaultOpenPositionParams
|
||||
} from "../utils/test-builders";
|
||||
|
||||
describe("increase_liquidity", () => {
|
||||
const provider = anchor.AnchorProvider.local();
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
@ -63,6 +65,9 @@ describe("increase_liquidity", () => {
|
|||
tokenAmount
|
||||
);
|
||||
|
||||
// To check if rewardLastUpdatedTimestamp is updated
|
||||
await sleep(1200);
|
||||
|
||||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.increaseLiquidityIx(ctx.program, {
|
||||
|
@ -86,7 +91,7 @@ describe("increase_liquidity", () => {
|
|||
assert.ok(position.liquidity.eq(liquidityAmount));
|
||||
|
||||
const poolAfter = (await fetcher.getPool(whirlpoolPda.publicKey, true)) as WhirlpoolData;
|
||||
assert.ok(poolAfter.rewardLastUpdatedTimestamp.gte(poolBefore.rewardLastUpdatedTimestamp));
|
||||
assert.ok(poolAfter.rewardLastUpdatedTimestamp.gt(poolBefore.rewardLastUpdatedTimestamp));
|
||||
assert.equal(
|
||||
await getTokenBalance(provider, poolInitInfo.tokenVaultAKeypair.publicKey),
|
||||
tokenAmount.tokenA.toString()
|
||||
|
@ -217,7 +222,7 @@ describe("increase_liquidity", () => {
|
|||
TickUtil.getStartTickIndex(tickUpperIndex, tickSpacing)
|
||||
).publicKey;
|
||||
|
||||
await new TransactionBuilder(ctx.provider.connection, ctx.provider.wallet)
|
||||
await new TransactionBuilder(ctx.provider.connection, ctx.provider.wallet, ctx.txBuilderOpts)
|
||||
// TODO: create a ComputeBudgetInstruction to request more compute
|
||||
.addInstruction(
|
||||
WhirlpoolIx.initTickArrayIx(
|
||||
|
@ -970,7 +975,7 @@ describe("increase_liquidity", () => {
|
|||
tickArrayUpper: positionInitInfo.tickArrayUpper,
|
||||
})
|
||||
).buildAndExecute(),
|
||||
/Signature verification failed/
|
||||
/.*signature verification fail.*/i
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
import * as anchor from "@project-serum/anchor";
|
||||
import * as anchor from "@coral-xyz/anchor";
|
||||
import * as assert from "assert";
|
||||
import {
|
||||
InitConfigParams,
|
||||
toTx,
|
||||
WhirlpoolContext,
|
||||
WhirlpoolIx,
|
||||
WhirlpoolsConfigData,
|
||||
WhirlpoolsConfigData
|
||||
} from "../../src";
|
||||
import { ONE_SOL, systemTransferTx } from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { generateDefaultConfigParams } from "../utils/test-builders";
|
||||
|
||||
describe("initialize_config", () => {
|
||||
const provider = anchor.AnchorProvider.local();
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
import * as anchor from "@project-serum/anchor";
|
||||
import * as anchor from "@coral-xyz/anchor";
|
||||
import * as assert from "assert";
|
||||
import { FeeTierData, PDAUtil, toTx, WhirlpoolContext, WhirlpoolIx } from "../../src";
|
||||
import { ONE_SOL, systemTransferTx, TickSpacing } from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { initFeeTier } from "../utils/init-utils";
|
||||
import {
|
||||
generateDefaultConfigParams,
|
||||
generateDefaultInitFeeTierParams,
|
||||
generateDefaultInitFeeTierParams
|
||||
} from "../utils/test-builders";
|
||||
|
||||
describe("initialize_fee_tier", () => {
|
||||
const provider = anchor.AnchorProvider.local();
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
@ -109,7 +110,7 @@ describe("initialize_fee_tier", () => {
|
|||
)
|
||||
)
|
||||
).buildAndExecute(),
|
||||
/Signature verification failed/
|
||||
/.*signature verification fail.*/i
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { MathUtil, PDA } from "@orca-so/common-sdk";
|
||||
import * as anchor from "@project-serum/anchor";
|
||||
import * as assert from "assert";
|
||||
import Decimal from "decimal.js";
|
||||
import {
|
||||
|
@ -8,24 +8,25 @@ import {
|
|||
MIN_SQRT_PRICE,
|
||||
PDAUtil,
|
||||
PriceMath,
|
||||
toTx,
|
||||
WhirlpoolContext,
|
||||
WhirlpoolData,
|
||||
WhirlpoolIx,
|
||||
toTx
|
||||
} from "../../src";
|
||||
import {
|
||||
asyncAssertTokenVault,
|
||||
createMint,
|
||||
ONE_SOL,
|
||||
systemTransferTx,
|
||||
TickSpacing,
|
||||
ZERO_BN,
|
||||
asyncAssertTokenVault,
|
||||
createMint,
|
||||
systemTransferTx
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { buildTestPoolParams, initTestPool } from "../utils/init-utils";
|
||||
|
||||
describe("initialize_pool", () => {
|
||||
const provider = anchor.AnchorProvider.local();
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
|
|
@ -1,28 +1,26 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { deriveATA } from "@orca-so/common-sdk";
|
||||
import * as anchor from "@project-serum/anchor";
|
||||
import { AccountInfo, ASSOCIATED_TOKEN_PROGRAM_ID, MintInfo, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { Keypair, LAMPORTS_PER_SOL, PublicKey, SystemProgram } from "@solana/web3.js";
|
||||
import * as assert from "assert";
|
||||
import {
|
||||
PDAUtil,
|
||||
PositionBundleData,
|
||||
POSITION_BUNDLE_SIZE,
|
||||
PositionBundleData,
|
||||
toTx,
|
||||
WhirlpoolContext,
|
||||
WhirlpoolContext
|
||||
} from "../../src";
|
||||
import {
|
||||
createMintInstructions,
|
||||
mintToByAuthority,
|
||||
mintToByAuthority
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { initializePositionBundle } from "../utils/init-utils";
|
||||
|
||||
describe("initialize_position_bundle", () => {
|
||||
const provider = anchor.AnchorProvider.local(undefined, {
|
||||
commitment: "confirmed",
|
||||
preflightCommitment: "confirmed",
|
||||
});
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
||||
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
@ -184,7 +182,6 @@ describe("initialize_position_bundle", () => {
|
|||
await createMintTx.buildAndExecute();
|
||||
|
||||
const tx = await createInitializePositionBundleTx(ctx, {}, positionBundleMintKeypair);
|
||||
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
(err) => { return JSON.stringify(err).includes("already in use") }
|
||||
|
@ -193,11 +190,11 @@ describe("initialize_position_bundle", () => {
|
|||
|
||||
describe("invalid input account", () => {
|
||||
it("should be failed: invalid position bundle address", async () => {
|
||||
const tx = await createInitializePositionBundleTx(ctx, {
|
||||
const tx = await createInitializePositionBundleTx(ctx, {
|
||||
// invalid parameter
|
||||
positionBundle: PDAUtil.getPositionBundle(ctx.program.programId, Keypair.generate().publicKey).publicKey,
|
||||
});
|
||||
|
||||
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
/0x7d6/ // ConstraintSeeds
|
||||
|
@ -205,11 +202,11 @@ describe("initialize_position_bundle", () => {
|
|||
});
|
||||
|
||||
it("should be failed: invalid ATA address", async () => {
|
||||
const tx = await createInitializePositionBundleTx(ctx, {
|
||||
const tx = await createInitializePositionBundleTx(ctx, {
|
||||
// invalid parameter
|
||||
positionBundleTokenAccount: await deriveATA(ctx.wallet.publicKey, Keypair.generate().publicKey),
|
||||
});
|
||||
|
||||
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
/An account required by the instruction is missing/ // Anchor cannot create derived ATA
|
||||
|
@ -217,11 +214,11 @@ describe("initialize_position_bundle", () => {
|
|||
});
|
||||
|
||||
it("should be failed: invalid token program", async () => {
|
||||
const tx = await createInitializePositionBundleTx(ctx, {
|
||||
const tx = await createInitializePositionBundleTx(ctx, {
|
||||
// invalid parameter
|
||||
tokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
||||
});
|
||||
|
||||
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
/0xbc0/ // InvalidProgramId
|
||||
|
@ -229,11 +226,11 @@ describe("initialize_position_bundle", () => {
|
|||
});
|
||||
|
||||
it("should be failed: invalid system program", async () => {
|
||||
const tx = await createInitializePositionBundleTx(ctx, {
|
||||
const tx = await createInitializePositionBundleTx(ctx, {
|
||||
// invalid parameter
|
||||
systemProgram: TOKEN_PROGRAM_ID,
|
||||
});
|
||||
|
||||
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
/0xbc0/ // InvalidProgramId
|
||||
|
@ -241,11 +238,11 @@ describe("initialize_position_bundle", () => {
|
|||
});
|
||||
|
||||
it("should be failed: invalid rent sysvar", async () => {
|
||||
const tx = await createInitializePositionBundleTx(ctx, {
|
||||
const tx = await createInitializePositionBundleTx(ctx, {
|
||||
// invalid parameter
|
||||
rent: anchor.web3.SYSVAR_CLOCK_PUBKEY,
|
||||
});
|
||||
|
||||
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
/0xbc7/ // AccountSysvarMismatch
|
||||
|
@ -253,11 +250,11 @@ describe("initialize_position_bundle", () => {
|
|||
});
|
||||
|
||||
it("should be failed: invalid associated token program", async () => {
|
||||
const tx = await createInitializePositionBundleTx(ctx, {
|
||||
const tx = await createInitializePositionBundleTx(ctx, {
|
||||
// invalid parameter
|
||||
associatedTokenProgram: TOKEN_PROGRAM_ID,
|
||||
});
|
||||
|
||||
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
/0xbc0/ // InvalidProgramId
|
||||
|
|
|
@ -1,31 +1,28 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { Metadata } from "@metaplex-foundation/mpl-token-metadata";
|
||||
import { deriveATA, PDA } from "@orca-so/common-sdk";
|
||||
import * as anchor from "@project-serum/anchor";
|
||||
import { AccountInfo, ASSOCIATED_TOKEN_PROGRAM_ID, MintInfo, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { Keypair, LAMPORTS_PER_SOL, PublicKey, SystemProgram } from "@solana/web3.js";
|
||||
import * as assert from "assert";
|
||||
import {
|
||||
METADATA_PROGRAM_ADDRESS,
|
||||
PDAUtil,
|
||||
PositionBundleData,
|
||||
POSITION_BUNDLE_SIZE,
|
||||
PositionBundleData,
|
||||
toTx,
|
||||
WhirlpoolContext,
|
||||
WHIRLPOOL_NFT_UPDATE_AUTH,
|
||||
WhirlpoolContext
|
||||
} from "../../src";
|
||||
import {
|
||||
createMintInstructions,
|
||||
mintToByAuthority,
|
||||
mintToByAuthority
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { initializePositionBundleWithMetadata } from "../utils/init-utils";
|
||||
|
||||
describe("initialize_position_bundle_with_metadata", () => {
|
||||
const provider = anchor.AnchorProvider.local(undefined, {
|
||||
commitment: "confirmed",
|
||||
preflightCommitment: "confirmed",
|
||||
});
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
@ -101,10 +98,10 @@ describe("initialize_position_bundle_with_metadata", () => {
|
|||
|
||||
const mintAddress = positionMint.toBase58();
|
||||
const nftName = WPB_METADATA_NAME_PREFIX
|
||||
+ " "
|
||||
+ mintAddress.slice(0, 4)
|
||||
+ "..."
|
||||
+ mintAddress.slice(-4);
|
||||
+ " "
|
||||
+ mintAddress.slice(0, 4)
|
||||
+ "..."
|
||||
+ mintAddress.slice(-4);
|
||||
|
||||
assert.ok(metadataPda != null);
|
||||
const metadata = await Metadata.load(provider.connection, metadataPda.publicKey);
|
||||
|
@ -217,7 +214,6 @@ describe("initialize_position_bundle_with_metadata", () => {
|
|||
await createMintTx.buildAndExecute();
|
||||
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(ctx, {}, positionBundleMintKeypair);
|
||||
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
(err) => { return JSON.stringify(err).includes("already in use") }
|
||||
|
@ -226,11 +222,11 @@ describe("initialize_position_bundle_with_metadata", () => {
|
|||
|
||||
describe("invalid input account", () => {
|
||||
it("should be failed: invalid position bundle address", async () => {
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(ctx, {
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(ctx, {
|
||||
// invalid parameter
|
||||
positionBundle: PDAUtil.getPositionBundle(ctx.program.programId, Keypair.generate().publicKey).publicKey,
|
||||
});
|
||||
|
||||
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
/0x7d6/ // ConstraintSeeds
|
||||
|
@ -238,11 +234,11 @@ describe("initialize_position_bundle_with_metadata", () => {
|
|||
});
|
||||
|
||||
it("should be failed: invalid metadata address", async () => {
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(ctx, {
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(ctx, {
|
||||
// invalid parameter
|
||||
positionBundleMetadata: PDAUtil.getPositionBundleMetadata(Keypair.generate().publicKey).publicKey,
|
||||
});
|
||||
|
||||
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
/0x5/ // InvalidMetadataKey: cannot create Metadata
|
||||
|
@ -250,11 +246,11 @@ describe("initialize_position_bundle_with_metadata", () => {
|
|||
});
|
||||
|
||||
it("should be failed: invalid ATA address", async () => {
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(ctx, {
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(ctx, {
|
||||
// invalid parameter
|
||||
positionBundleTokenAccount: await deriveATA(ctx.wallet.publicKey, Keypair.generate().publicKey),
|
||||
});
|
||||
|
||||
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
/An account required by the instruction is missing/ // Anchor cannot create derived ATA
|
||||
|
@ -262,11 +258,11 @@ describe("initialize_position_bundle_with_metadata", () => {
|
|||
});
|
||||
|
||||
it("should be failed: invalid update auth", async () => {
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(ctx, {
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(ctx, {
|
||||
// invalid parameter
|
||||
metadataUpdateAuth: Keypair.generate().publicKey,
|
||||
});
|
||||
|
||||
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
/0x7dc/ // ConstraintAddress
|
||||
|
@ -274,11 +270,11 @@ describe("initialize_position_bundle_with_metadata", () => {
|
|||
});
|
||||
|
||||
it("should be failed: invalid token program", async () => {
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(ctx, {
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(ctx, {
|
||||
// invalid parameter
|
||||
tokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
||||
});
|
||||
|
||||
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
/0xbc0/ // InvalidProgramId
|
||||
|
@ -286,11 +282,11 @@ describe("initialize_position_bundle_with_metadata", () => {
|
|||
});
|
||||
|
||||
it("should be failed: invalid system program", async () => {
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(ctx, {
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(ctx, {
|
||||
// invalid parameter
|
||||
systemProgram: TOKEN_PROGRAM_ID,
|
||||
});
|
||||
|
||||
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
/0xbc0/ // InvalidProgramId
|
||||
|
@ -298,11 +294,11 @@ describe("initialize_position_bundle_with_metadata", () => {
|
|||
});
|
||||
|
||||
it("should be failed: invalid rent sysvar", async () => {
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(ctx, {
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(ctx, {
|
||||
// invalid parameter
|
||||
rent: anchor.web3.SYSVAR_CLOCK_PUBKEY,
|
||||
});
|
||||
|
||||
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
/0xbc7/ // AccountSysvarMismatch
|
||||
|
@ -310,11 +306,11 @@ describe("initialize_position_bundle_with_metadata", () => {
|
|||
});
|
||||
|
||||
it("should be failed: invalid associated token program", async () => {
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(ctx, {
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(ctx, {
|
||||
// invalid parameter
|
||||
associatedTokenProgram: TOKEN_PROGRAM_ID,
|
||||
});
|
||||
|
||||
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
/0xbc0/ // InvalidProgramId
|
||||
|
@ -322,11 +318,11 @@ describe("initialize_position_bundle_with_metadata", () => {
|
|||
});
|
||||
|
||||
it("should be failed: invalid metadata program", async () => {
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(ctx, {
|
||||
const tx = await createInitializePositionBundleWithMetadataTx(ctx, {
|
||||
// invalid parameter
|
||||
metadataProgram: TOKEN_PROGRAM_ID,
|
||||
});
|
||||
|
||||
|
||||
await assert.rejects(
|
||||
tx.buildAndExecute(),
|
||||
/0x7dc/ // ConstraintAddress
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import * as anchor from "@project-serum/anchor";
|
||||
import * as anchor from "@coral-xyz/anchor";
|
||||
import * as assert from "assert";
|
||||
import { toTx, WhirlpoolContext, WhirlpoolData, WhirlpoolIx } from "../../src";
|
||||
import { createMint, ONE_SOL, systemTransferTx, TickSpacing } from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { initializeReward, initTestPool } from "../utils/init-utils";
|
||||
|
||||
describe("initialize_reward", () => {
|
||||
const provider = anchor.AnchorProvider.local();
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
import * as anchor from "@project-serum/anchor";
|
||||
import * as anchor from "@coral-xyz/anchor";
|
||||
import * as assert from "assert";
|
||||
import {
|
||||
InitPoolParams,
|
||||
InitTickArrayParams,
|
||||
TickArrayData,
|
||||
TICK_ARRAY_SIZE,
|
||||
toTx,
|
||||
TickArrayData,
|
||||
WhirlpoolContext,
|
||||
WhirlpoolIx,
|
||||
toTx
|
||||
} from "../../src";
|
||||
import { ONE_SOL, systemTransferTx, TickSpacing } from "../utils";
|
||||
import { ONE_SOL, TickSpacing, systemTransferTx } from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { initTestPool, initTickArray } from "../utils/init-utils";
|
||||
import { generateDefaultInitTickArrayParams } from "../utils/test-builders";
|
||||
|
||||
describe("initialize_tick_array", () => {
|
||||
const provider = anchor.AnchorProvider.local();
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
import * as anchor from "@project-serum/anchor";
|
||||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { deriveATA, MathUtil, TransactionBuilder, ZERO } from "@orca-so/common-sdk";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { Keypair, SystemProgram } from "@solana/web3.js";
|
||||
import * as assert from "assert";
|
||||
import { toTx, WhirlpoolIx, Whirlpool, WhirlpoolClient, buildWhirlpoolClient, PDAUtil, collectFeesQuote, NUM_REWARDS, ORCA_WHIRLPOOL_PROGRAM_ID, PoolUtil, PriceMath, POSITION_BUNDLE_SIZE, PositionBundleData } from "../../../src";
|
||||
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 { WhirlpoolContext } from "../../../src/context";
|
||||
import { createTokenAccount, TickSpacing, ZERO_BN } from "../../utils";
|
||||
import { initializePositionBundle, openBundledPosition } from "../../utils/init-utils";
|
||||
import { u64 } from "@solana/spl-token";
|
||||
import { defaultConfirmOptions } from "../../utils/const";
|
||||
import { WhirlpoolTestFixture } from "../../utils/fixture";
|
||||
import { deriveATA, MathUtil, TransactionBuilder, ZERO } from "@orca-so/common-sdk";
|
||||
import Decimal from "decimal.js";
|
||||
import { Keypair, SystemProgram } from "@solana/web3.js";
|
||||
import { BN } from "bn.js";
|
||||
import { initializePositionBundle, openBundledPosition } from "../../utils/init-utils";
|
||||
|
||||
|
||||
interface SharedTestContext {
|
||||
|
@ -20,10 +21,7 @@ interface SharedTestContext {
|
|||
}
|
||||
|
||||
describe("bundled position management tests", () => {
|
||||
const provider = anchor.AnchorProvider.local(undefined, {
|
||||
commitment: "confirmed",
|
||||
preflightCommitment: "confirmed",
|
||||
});
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
||||
let testCtx: SharedTestContext;
|
||||
const tickLowerIndex = 29440;
|
||||
|
@ -64,7 +62,7 @@ describe("bundled position management tests", () => {
|
|||
}
|
||||
|
||||
function checkBitmap(account: PositionBundleData, openedBundleIndexes: number[]) {
|
||||
for (let i=0; i<POSITION_BUNDLE_SIZE; i++) {
|
||||
for (let i = 0; i < POSITION_BUNDLE_SIZE; i++) {
|
||||
if (openedBundleIndexes.includes(i)) {
|
||||
assert.ok(checkBitmapIsOpened(account, i));
|
||||
}
|
||||
|
@ -161,7 +159,7 @@ describe("bundled position management tests", () => {
|
|||
|
||||
const pool = await testCtx.whirlpoolClient.getPool(whirlpoolPda.publicKey);
|
||||
|
||||
for (let i=0; i<NUM_REWARDS; i++) {
|
||||
for (let i = 0; i < NUM_REWARDS; i++) {
|
||||
await toTx(
|
||||
ctx,
|
||||
WhirlpoolIx.setRewardEmissionsIx(ctx.program, {
|
||||
|
@ -184,7 +182,6 @@ describe("bundled position management tests", () => {
|
|||
rewards: [],
|
||||
});
|
||||
const { poolInitInfo, rewards } = fixture.getInfos();
|
||||
|
||||
// initialize position bundle
|
||||
const positionBundleInfo = await initializePositionBundle(ctx, ctx.wallet.publicKey);
|
||||
const positionBundlePubkey = positionBundleInfo.positionBundlePda.publicKey;
|
||||
|
@ -194,13 +191,13 @@ describe("bundled position management tests", () => {
|
|||
const openedBundleIndexes: number[] = [];
|
||||
|
||||
// open all
|
||||
for (let startBundleIndex=0; startBundleIndex<POSITION_BUNDLE_SIZE; startBundleIndex+= batchSize) {
|
||||
for (let startBundleIndex = 0; startBundleIndex < POSITION_BUNDLE_SIZE; startBundleIndex += batchSize) {
|
||||
const minBundleIndex = startBundleIndex;
|
||||
const maxBundleIndex = Math.min(startBundleIndex + batchSize, POSITION_BUNDLE_SIZE) - 1;
|
||||
|
||||
const builder = new TransactionBuilder(ctx.connection, ctx.wallet);
|
||||
const builder = new TransactionBuilder(ctx.connection, ctx.wallet, ctx.txBuilderOpts);
|
||||
|
||||
for (let bundleIndex=minBundleIndex; bundleIndex<=maxBundleIndex; bundleIndex++) {
|
||||
for (let bundleIndex = minBundleIndex; bundleIndex <= maxBundleIndex; bundleIndex++) {
|
||||
const bundledPositionPda = PDAUtil.getBundledPosition(ctx.program.programId, positionBundleInfo.positionBundleMintKeypair.publicKey, bundleIndex);
|
||||
builder.addInstruction(WhirlpoolIx.openBundledPositionIx(ctx.program, {
|
||||
bundledPositionPda,
|
||||
|
@ -223,13 +220,13 @@ describe("bundled position management tests", () => {
|
|||
assert.equal(openedBundleIndexes.length, POSITION_BUNDLE_SIZE);
|
||||
|
||||
// close all
|
||||
for (let startBundleIndex=0; startBundleIndex<POSITION_BUNDLE_SIZE; startBundleIndex+= batchSize) {
|
||||
for (let startBundleIndex = 0; startBundleIndex < POSITION_BUNDLE_SIZE; startBundleIndex += batchSize) {
|
||||
const minBundleIndex = startBundleIndex;
|
||||
const maxBundleIndex = Math.min(startBundleIndex + batchSize, POSITION_BUNDLE_SIZE) - 1;
|
||||
|
||||
const builder = new TransactionBuilder(ctx.connection, ctx.wallet);
|
||||
const builder = new TransactionBuilder(ctx.connection, ctx.wallet, ctx.txBuilderOpts);
|
||||
|
||||
for (let bundleIndex=minBundleIndex; bundleIndex<=maxBundleIndex; bundleIndex++) {
|
||||
for (let bundleIndex = minBundleIndex; bundleIndex <= maxBundleIndex; bundleIndex++) {
|
||||
const bundledPositionPda = PDAUtil.getBundledPosition(ctx.program.programId, positionBundleInfo.positionBundleMintKeypair.publicKey, bundleIndex);
|
||||
builder.addInstruction(WhirlpoolIx.closeBundledPositionIx(ctx.program, {
|
||||
bundledPosition: bundledPositionPda.publicKey,
|
||||
|
@ -340,7 +337,7 @@ describe("bundled position management tests", () => {
|
|||
WhirlpoolIx.increaseLiquidityIx(ctx.program, {
|
||||
...modifyLiquidityParams,
|
||||
tokenMaxA: depositAmounts.tokenA,
|
||||
tokenMaxB: depositAmounts.tokenB,
|
||||
tokenMaxB: depositAmounts.tokenB,
|
||||
})
|
||||
).buildAndExecute();
|
||||
const postIncrease = await ctx.fetcher.getPosition(bundledPositionPubkey, true);
|
||||
|
@ -380,7 +377,7 @@ describe("bundled position management tests", () => {
|
|||
tokenOwnerAccountB,
|
||||
tokenVaultA: poolInitInfo.tokenVaultAKeypair.publicKey,
|
||||
tokenVaultB: poolInitInfo.tokenVaultBKeypair.publicKey,
|
||||
whirlpool: whirlpoolPubkey,
|
||||
whirlpool: whirlpoolPubkey,
|
||||
})
|
||||
).buildAndExecute();
|
||||
const postCollectFees = await ctx.fetcher.getPosition(bundledPositionPubkey, true);
|
||||
|
@ -388,7 +385,7 @@ describe("bundled position management tests", () => {
|
|||
assert.ok(postCollectFees!.feeOwedB.isZero());
|
||||
|
||||
// collectReward
|
||||
for (let i=0; i<NUM_REWARDS; i++) {
|
||||
for (let i = 0; i < NUM_REWARDS; i++) {
|
||||
const ata = await createTokenAccount(
|
||||
provider,
|
||||
rewards[i].rewardMint,
|
||||
|
@ -412,7 +409,6 @@ describe("bundled position management tests", () => {
|
|||
const postCollectReward = await ctx.fetcher.getPosition(bundledPositionPubkey, true);
|
||||
assert.ok(postCollectReward!.rewardInfos[i].amountOwed.isZero());
|
||||
}
|
||||
|
||||
// decreaseLiquidity
|
||||
const withdrawAmounts = PoolUtil.getTokenAmountsFromLiquidity(
|
||||
liquidityAmount,
|
||||
|
@ -481,11 +477,14 @@ describe("bundled position management tests", () => {
|
|||
// increase feeGrowth
|
||||
await accrueFees(fixture);
|
||||
|
||||
// increase rewardGrowth
|
||||
await sleep(2);
|
||||
|
||||
// initialize position bundle
|
||||
const positionBundleInfo = await initializePositionBundle(ctx, ctx.wallet.publicKey);
|
||||
const bundleIndex = Math.floor(Math.random() * POSITION_BUNDLE_SIZE);
|
||||
|
||||
for (let iter=0; iter<openCloseIterationNum; iter++) {
|
||||
for (let iter = 0; iter < openCloseIterationNum; iter++) {
|
||||
// open bundled position
|
||||
const positionInitInfo = await openBundledPosition(
|
||||
ctx,
|
||||
|
@ -532,7 +531,6 @@ describe("bundled position management tests", () => {
|
|||
PriceMath.tickIndexToSqrtPriceX64(tickUpperIndex),
|
||||
true
|
||||
);
|
||||
|
||||
const preIncrease = await ctx.fetcher.getPosition(bundledPositionPubkey, true);
|
||||
assert.ok(preIncrease!.liquidity.isZero());
|
||||
await toTx(
|
||||
|
@ -540,7 +538,7 @@ describe("bundled position management tests", () => {
|
|||
WhirlpoolIx.increaseLiquidityIx(ctx.program, {
|
||||
...modifyLiquidityParams,
|
||||
tokenMaxA: depositAmounts.tokenA,
|
||||
tokenMaxB: depositAmounts.tokenB,
|
||||
tokenMaxB: depositAmounts.tokenB,
|
||||
})
|
||||
).buildAndExecute();
|
||||
const postIncrease = await ctx.fetcher.getPosition(bundledPositionPubkey, true);
|
||||
|
@ -553,7 +551,6 @@ describe("bundled position management tests", () => {
|
|||
|
||||
await sleep(2); // accrueRewards
|
||||
await accrueFees(fixture);
|
||||
|
||||
// decreaseLiquidity
|
||||
const withdrawAmounts = PoolUtil.getTokenAmountsFromLiquidity(
|
||||
liquidityAmount,
|
||||
|
@ -587,7 +584,7 @@ describe("bundled position management tests", () => {
|
|||
tokenOwnerAccountB,
|
||||
tokenVaultA: poolInitInfo.tokenVaultAKeypair.publicKey,
|
||||
tokenVaultB: poolInitInfo.tokenVaultBKeypair.publicKey,
|
||||
whirlpool: whirlpoolPubkey,
|
||||
whirlpool: whirlpoolPubkey,
|
||||
})
|
||||
).buildAndExecute();
|
||||
const postCollectFees = await ctx.fetcher.getPosition(bundledPositionPubkey, true);
|
||||
|
@ -595,7 +592,7 @@ describe("bundled position management tests", () => {
|
|||
assert.ok(postCollectFees!.feeOwedB.isZero());
|
||||
|
||||
// collectReward
|
||||
for (let i=0; i<NUM_REWARDS; i++) {
|
||||
for (let i = 0; i < NUM_REWARDS; i++) {
|
||||
const ata = await createTokenAccount(
|
||||
provider,
|
||||
rewards[i].rewardMint,
|
||||
|
@ -685,7 +682,7 @@ describe("bundled position management tests", () => {
|
|||
);
|
||||
|
||||
// openBundledPosition + increaseLiquidity
|
||||
const openIncreaseBuilder = new TransactionBuilder(ctx.connection, ctx.wallet);
|
||||
const openIncreaseBuilder = new TransactionBuilder(ctx.connection, ctx.wallet, ctx.txBuilderOpts);
|
||||
openIncreaseBuilder
|
||||
.addInstruction(WhirlpoolIx.openBundledPositionIx(ctx.program, {
|
||||
bundledPositionPda,
|
||||
|
@ -701,13 +698,12 @@ describe("bundled position management tests", () => {
|
|||
.addInstruction(WhirlpoolIx.increaseLiquidityIx(ctx.program, {
|
||||
...modifyLiquidityParams,
|
||||
tokenMaxA: depositAmounts.tokenA,
|
||||
tokenMaxB: depositAmounts.tokenB,
|
||||
tokenMaxB: depositAmounts.tokenB,
|
||||
}));
|
||||
await openIncreaseBuilder.buildAndExecute();
|
||||
const postIncrease = await ctx.fetcher.getPosition(bundledPositionPubkey, true);
|
||||
assert.ok(postIncrease!.liquidity.eq(liquidityAmount));
|
||||
|
||||
|
||||
const withdrawAmounts = PoolUtil.getTokenAmountsFromLiquidity(
|
||||
liquidityAmount,
|
||||
(await ctx.fetcher.getPool(whirlpoolPubkey, true))!.sqrtPrice,
|
||||
|
@ -716,7 +712,7 @@ describe("bundled position management tests", () => {
|
|||
false
|
||||
);
|
||||
|
||||
const decreaseCloseBuilder = new TransactionBuilder(ctx.connection, ctx.wallet);
|
||||
const decreaseCloseBuilder = new TransactionBuilder(ctx.connection, ctx.wallet, ctx.txBuilderOpts);
|
||||
decreaseCloseBuilder
|
||||
.addInstruction(WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
...modifyLiquidityParams,
|
||||
|
@ -796,7 +792,7 @@ describe("bundled position management tests", () => {
|
|||
);
|
||||
|
||||
const receiver = Keypair.generate();
|
||||
const builder = new TransactionBuilder(ctx.connection, ctx.wallet);
|
||||
const builder = new TransactionBuilder(ctx.connection, ctx.wallet, ctx.txBuilderOpts);
|
||||
builder
|
||||
.addInstruction(WhirlpoolIx.openBundledPositionIx(ctx.program, {
|
||||
bundledPositionPda,
|
||||
|
@ -812,7 +808,7 @@ describe("bundled position management tests", () => {
|
|||
.addInstruction(WhirlpoolIx.increaseLiquidityIx(ctx.program, {
|
||||
...modifyLiquidityParams,
|
||||
tokenMaxA: depositAmounts.tokenA,
|
||||
tokenMaxB: depositAmounts.tokenB,
|
||||
tokenMaxB: depositAmounts.tokenB,
|
||||
}))
|
||||
.addInstruction(WhirlpoolIx.decreaseLiquidityIx(ctx.program, {
|
||||
...modifyLiquidityParams,
|
||||
|
@ -851,7 +847,7 @@ describe("bundled position management tests", () => {
|
|||
const bundledPositionPubkey = bundledPositionPda.publicKey;
|
||||
const whirlpoolPubkey = poolInitInfo.whirlpoolPda.publicKey;
|
||||
|
||||
const builder = new TransactionBuilder(ctx.connection, ctx.wallet);
|
||||
const builder = new TransactionBuilder(ctx.connection, ctx.wallet, ctx.txBuilderOpts);
|
||||
builder
|
||||
// open
|
||||
.addInstruction(WhirlpoolIx.openBundledPositionIx(ctx.program, {
|
||||
|
@ -973,7 +969,7 @@ describe("bundled position management tests", () => {
|
|||
const receiverAtaA = await createTokenAccount(provider, poolInitInfo.tokenMintA, receiver.publicKey);
|
||||
const receiverAtaB = await createTokenAccount(provider, poolInitInfo.tokenMintB, receiver.publicKey);
|
||||
|
||||
const builder = new TransactionBuilder(ctx.connection, ctx.wallet);
|
||||
const builder = new TransactionBuilder(ctx.connection, ctx.wallet, ctx.txBuilderOpts);
|
||||
builder
|
||||
.addInstruction(WhirlpoolIx.openBundledPositionIx(ctx.program, {
|
||||
bundledPositionPda,
|
||||
|
@ -989,7 +985,7 @@ describe("bundled position management tests", () => {
|
|||
.addInstruction(WhirlpoolIx.increaseLiquidityIx(ctx.program, {
|
||||
...modifyLiquidityParams,
|
||||
tokenMaxA: depositAmounts.tokenA,
|
||||
tokenMaxB: depositAmounts.tokenB,
|
||||
tokenMaxB: depositAmounts.tokenB,
|
||||
}))
|
||||
.addInstruction(WhirlpoolIx.swapIx(ctx.program, {
|
||||
amount: swapInput,
|
||||
|
@ -1038,7 +1034,7 @@ describe("bundled position management tests", () => {
|
|||
tokenOwnerAccountB: receiverAtaB,
|
||||
tokenVaultA: poolInitInfo.tokenVaultAKeypair.publicKey,
|
||||
tokenVaultB: poolInitInfo.tokenVaultBKeypair.publicKey,
|
||||
whirlpool: whirlpoolPubkey,
|
||||
whirlpool: whirlpoolPubkey,
|
||||
}))
|
||||
.addInstruction(WhirlpoolIx.closeBundledPositionIx(ctx.program, {
|
||||
bundledPosition: bundledPositionPubkey,
|
||||
|
@ -1067,7 +1063,7 @@ describe("bundled position management tests", () => {
|
|||
const rentOfPositionBundle = preClose.lamports;
|
||||
assert.ok(rentOfPositionBundle > 0);
|
||||
|
||||
const builder = new TransactionBuilder(ctx.connection, ctx.wallet);
|
||||
const builder = new TransactionBuilder(ctx.connection, ctx.wallet, ctx.txBuilderOpts);
|
||||
builder
|
||||
// close
|
||||
.addInstruction(WhirlpoolIx.deletePositionBundleIx(ctx.program, {
|
||||
|
@ -1079,7 +1075,7 @@ describe("bundled position management tests", () => {
|
|||
}))
|
||||
// fund rent
|
||||
.addInstruction({
|
||||
instructions:[
|
||||
instructions: [
|
||||
SystemProgram.transfer({
|
||||
fromPubkey: ctx.wallet.publicKey,
|
||||
toPubkey: positionBundleInfo.positionBundlePda.publicKey,
|
||||
|
@ -1089,7 +1085,6 @@ describe("bundled position management tests", () => {
|
|||
cleanupInstructions: [],
|
||||
signers: [],
|
||||
});
|
||||
|
||||
await builder.buildAndExecute();
|
||||
|
||||
// Account closing reassigns to system program and reallocates
|
||||
|
@ -1139,7 +1134,7 @@ describe("bundled position management tests", () => {
|
|||
const rentOfBundledPosition = preClose.lamports;
|
||||
assert.ok(rentOfBundledPosition > 0);
|
||||
|
||||
const builder = new TransactionBuilder(ctx.connection, ctx.wallet);
|
||||
const builder = new TransactionBuilder(ctx.connection, ctx.wallet, ctx.txBuilderOpts);
|
||||
builder
|
||||
// close
|
||||
.addInstruction(WhirlpoolIx.closeBundledPositionIx(ctx.program, {
|
||||
|
@ -1152,7 +1147,7 @@ describe("bundled position management tests", () => {
|
|||
}))
|
||||
// fund rent
|
||||
.addInstruction({
|
||||
instructions:[
|
||||
instructions: [
|
||||
SystemProgram.transfer({
|
||||
fromPubkey: ctx.wallet.publicKey,
|
||||
toPubkey: bundledPositionPubkey,
|
||||
|
@ -1162,7 +1157,6 @@ describe("bundled position management tests", () => {
|
|||
cleanupInstructions: [],
|
||||
signers: [],
|
||||
});
|
||||
|
||||
await builder.buildAndExecute();
|
||||
|
||||
// Account closing reassigns to system program and reallocates
|
||||
|
@ -1193,7 +1187,7 @@ 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 builder = new TransactionBuilder(ctx.connection, ctx.wallet);
|
||||
const builder = new TransactionBuilder(ctx.connection, ctx.wallet, ctx.txBuilderOpts);
|
||||
builder
|
||||
// open
|
||||
.addInstruction(WhirlpoolIx.openBundledPositionIx(ctx.program, {
|
||||
|
@ -1223,11 +1217,11 @@ describe("bundled position management tests", () => {
|
|||
tickArrayUpper,
|
||||
whirlpool: whirlpoolPubkey,
|
||||
}));
|
||||
|
||||
|
||||
await assert.rejects(
|
||||
builder.buildAndExecute(),
|
||||
/0xbc4/ // AccountNotInitialized
|
||||
);
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
import * as anchor from "@project-serum/anchor";
|
||||
import * as anchor from "@coral-xyz/anchor";
|
||||
import * as assert from "assert";
|
||||
import { toTx, WhirlpoolIx } from "../../../src";
|
||||
import { WhirlpoolContext } from "../../../src/context";
|
||||
import { TickSpacing } from "../../utils";
|
||||
import { defaultConfirmOptions } from "../../utils/const";
|
||||
import { initTestPool, openPosition } from "../../utils/init-utils";
|
||||
import { generateDefaultOpenPositionParams } from "../../utils/test-builders";
|
||||
|
||||
describe("position management tests", () => {
|
||||
const provider = anchor.AnchorProvider.local();
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { PDA } from "@orca-so/common-sdk";
|
||||
import * as anchor from "@project-serum/anchor";
|
||||
import { ASSOCIATED_TOKEN_PROGRAM_ID, Token, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { PublicKey, SystemProgram } from "@solana/web3.js";
|
||||
import * as assert from "assert";
|
||||
|
@ -8,12 +8,12 @@ import {
|
|||
MAX_TICK_INDEX,
|
||||
MIN_TICK_INDEX,
|
||||
PDAUtil,
|
||||
POSITION_BUNDLE_SIZE,
|
||||
PositionBundleData,
|
||||
PositionData,
|
||||
POSITION_BUNDLE_SIZE,
|
||||
toTx,
|
||||
WhirlpoolContext,
|
||||
WhirlpoolIx,
|
||||
WhirlpoolIx
|
||||
} from "../../src";
|
||||
import {
|
||||
approveToken,
|
||||
|
@ -22,17 +22,15 @@ import {
|
|||
systemTransferTx,
|
||||
TickSpacing,
|
||||
transfer,
|
||||
ZERO_BN,
|
||||
ZERO_BN
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { initializePositionBundle, initTestPool, openBundledPosition } from "../utils/init-utils";
|
||||
|
||||
describe("open_bundled_position", () => {
|
||||
const provider = anchor.AnchorProvider.local(undefined, {
|
||||
commitment: "confirmed",
|
||||
preflightCommitment: "confirmed",
|
||||
});
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
||||
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
@ -57,14 +55,12 @@ 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,
|
||||
positionBundleMint,
|
||||
ctx.wallet.publicKey
|
||||
);
|
||||
|
||||
const defaultAccounts = {
|
||||
bundledPosition: bundledPositionPda.publicKey,
|
||||
positionBundle,
|
||||
|
@ -125,7 +121,7 @@ describe("open_bundled_position", () => {
|
|||
}
|
||||
|
||||
function checkBitmap(account: PositionBundleData, openedBundleIndexes: number[]) {
|
||||
for (let i=0; i<POSITION_BUNDLE_SIZE; i++) {
|
||||
for (let i = 0; i < POSITION_BUNDLE_SIZE; i++) {
|
||||
if (openedBundleIndexes.includes(i)) {
|
||||
assert.ok(checkBitmapIsOpened(account, i));
|
||||
}
|
||||
|
@ -248,7 +244,7 @@ describe("open_bundled_position", () => {
|
|||
it("should be failed: invalid bundle index (u16 max)", async () => {
|
||||
const positionBundleInfo = await initializePositionBundle(ctx, ctx.wallet.publicKey);
|
||||
|
||||
const bundleIndex = 2**16 - 1;
|
||||
const bundleIndex = 2 ** 16 - 1;
|
||||
await assert.rejects(
|
||||
openBundledPosition(
|
||||
ctx,
|
||||
|
@ -342,13 +338,13 @@ describe("open_bundled_position", () => {
|
|||
|
||||
const tx = await createOpenBundledPositionTx(
|
||||
ctx, positionBundleInfo.positionBundleMintKeypair.publicKey, 0, {
|
||||
// invalid parameter
|
||||
bundledPosition: PDAUtil.getBundledPosition(
|
||||
ctx.program.programId,
|
||||
positionBundleInfo.positionBundleMintKeypair.publicKey,
|
||||
1 // another bundle index
|
||||
).publicKey
|
||||
}
|
||||
// invalid parameter
|
||||
bundledPosition: PDAUtil.getBundledPosition(
|
||||
ctx.program.programId,
|
||||
positionBundleInfo.positionBundleMintKeypair.publicKey,
|
||||
1 // another bundle index
|
||||
).publicKey
|
||||
}
|
||||
);
|
||||
|
||||
await assert.rejects(
|
||||
|
@ -363,9 +359,9 @@ describe("open_bundled_position", () => {
|
|||
|
||||
const tx = await createOpenBundledPositionTx(
|
||||
ctx, positionBundleInfo.positionBundleMintKeypair.publicKey, 0, {
|
||||
// invalid parameter
|
||||
positionBundle: otherPositionBundleInfo.positionBundlePda.publicKey,
|
||||
}
|
||||
// invalid parameter
|
||||
positionBundle: otherPositionBundleInfo.positionBundlePda.publicKey,
|
||||
}
|
||||
);
|
||||
|
||||
await assert.rejects(
|
||||
|
@ -386,9 +382,9 @@ describe("open_bundled_position", () => {
|
|||
|
||||
const tx = await createOpenBundledPositionTx(
|
||||
ctx, positionBundleInfo.positionBundleMintKeypair.publicKey, 0, {
|
||||
// invalid parameter
|
||||
positionBundleTokenAccount: ata,
|
||||
}
|
||||
// invalid parameter
|
||||
positionBundleTokenAccount: ata,
|
||||
}
|
||||
);
|
||||
|
||||
await assert.rejects(
|
||||
|
@ -403,9 +399,9 @@ describe("open_bundled_position", () => {
|
|||
|
||||
const tx = await createOpenBundledPositionTx(
|
||||
ctx, positionBundleInfo.positionBundleMintKeypair.publicKey, 0, {
|
||||
// invalid parameter
|
||||
positionBundleTokenAccount: otherPositionBundleInfo.positionBundleTokenAccount,
|
||||
}
|
||||
// invalid parameter
|
||||
positionBundleTokenAccount: otherPositionBundleInfo.positionBundleTokenAccount,
|
||||
}
|
||||
);
|
||||
|
||||
await assert.rejects(
|
||||
|
@ -419,10 +415,10 @@ describe("open_bundled_position", () => {
|
|||
|
||||
const tx = await createOpenBundledPositionTx(
|
||||
ctx, positionBundleInfo.positionBundleMintKeypair.publicKey, 0, {
|
||||
positionBundleTokenAccount: positionBundleInfo.positionBundleTokenAccount,
|
||||
// invalid parameter
|
||||
positionBundleAuthority: ctx.wallet.publicKey,
|
||||
}
|
||||
positionBundleTokenAccount: positionBundleInfo.positionBundleTokenAccount,
|
||||
// invalid parameter
|
||||
positionBundleAuthority: ctx.wallet.publicKey,
|
||||
}
|
||||
);
|
||||
|
||||
await assert.rejects(
|
||||
|
@ -436,9 +432,9 @@ describe("open_bundled_position", () => {
|
|||
|
||||
const tx = await createOpenBundledPositionTx(
|
||||
ctx, positionBundleInfo.positionBundleMintKeypair.publicKey, 0, {
|
||||
// invalid parameter
|
||||
whirlpool: positionBundleInfo.positionBundlePda.publicKey,
|
||||
}
|
||||
// invalid parameter
|
||||
whirlpool: positionBundleInfo.positionBundlePda.publicKey,
|
||||
}
|
||||
);
|
||||
|
||||
await assert.rejects(
|
||||
|
@ -453,9 +449,9 @@ describe("open_bundled_position", () => {
|
|||
|
||||
const tx = await createOpenBundledPositionTx(
|
||||
ctx, positionBundleInfo.positionBundleMintKeypair.publicKey, 0, {
|
||||
// invalid parameter
|
||||
systemProgram: TOKEN_PROGRAM_ID,
|
||||
}
|
||||
// invalid parameter
|
||||
systemProgram: TOKEN_PROGRAM_ID,
|
||||
}
|
||||
);
|
||||
|
||||
await assert.rejects(
|
||||
|
@ -469,9 +465,9 @@ describe("open_bundled_position", () => {
|
|||
|
||||
const tx = await createOpenBundledPositionTx(
|
||||
ctx, positionBundleInfo.positionBundleMintKeypair.publicKey, 0, {
|
||||
// invalid parameter
|
||||
rent: anchor.web3.SYSVAR_CLOCK_PUBKEY,
|
||||
}
|
||||
// invalid parameter
|
||||
rent: anchor.web3.SYSVAR_CLOCK_PUBKEY,
|
||||
}
|
||||
);
|
||||
|
||||
await assert.rejects(
|
||||
|
@ -487,9 +483,9 @@ describe("open_bundled_position", () => {
|
|||
|
||||
const tx = await createOpenBundledPositionTx(
|
||||
ctx, positionBundleInfo.positionBundleMintKeypair.publicKey, 0, {
|
||||
positionBundleTokenAccount: positionBundleInfo.positionBundleTokenAccount,
|
||||
positionBundleAuthority: ctx.wallet.publicKey,
|
||||
}
|
||||
positionBundleTokenAccount: positionBundleInfo.positionBundleTokenAccount,
|
||||
positionBundleAuthority: ctx.wallet.publicKey,
|
||||
}
|
||||
);
|
||||
|
||||
await assert.rejects(
|
||||
|
@ -505,7 +501,6 @@ describe("open_bundled_position", () => {
|
|||
1,
|
||||
funderKeypair
|
||||
);
|
||||
|
||||
await tx.buildAndExecute();
|
||||
const positionBundle = await fetcher.getPositionBundle(positionBundleInfo.positionBundlePda.publicKey, true);
|
||||
checkBitmapIsOpened(positionBundle!, 0);
|
||||
|
@ -516,9 +511,9 @@ describe("open_bundled_position", () => {
|
|||
|
||||
const tx = await createOpenBundledPositionTx(
|
||||
ctx, positionBundleInfo.positionBundleMintKeypair.publicKey, 0, {
|
||||
positionBundleTokenAccount: positionBundleInfo.positionBundleTokenAccount,
|
||||
positionBundleAuthority: ctx.wallet.publicKey,
|
||||
}
|
||||
positionBundleTokenAccount: positionBundleInfo.positionBundleTokenAccount,
|
||||
positionBundleAuthority: ctx.wallet.publicKey,
|
||||
}
|
||||
);
|
||||
|
||||
// delegate 1 token from ctx.wallet to funder
|
||||
|
@ -528,7 +523,6 @@ describe("open_bundled_position", () => {
|
|||
funderKeypair.publicKey,
|
||||
1,
|
||||
);
|
||||
|
||||
// owner can open even if delegation exists
|
||||
await tx.buildAndExecute();
|
||||
const positionBundle = await fetcher.getPositionBundle(positionBundleInfo.positionBundlePda.publicKey, true);
|
||||
|
@ -541,9 +535,9 @@ describe("open_bundled_position", () => {
|
|||
|
||||
const tx = await createOpenBundledPositionTx(
|
||||
ctx, positionBundleInfo.positionBundleMintKeypair.publicKey, 0, {
|
||||
positionBundleTokenAccount: positionBundleInfo.positionBundleTokenAccount,
|
||||
positionBundleAuthority: ctx.wallet.publicKey,
|
||||
}
|
||||
positionBundleTokenAccount: positionBundleInfo.positionBundleTokenAccount,
|
||||
positionBundleAuthority: ctx.wallet.publicKey,
|
||||
}
|
||||
);
|
||||
|
||||
await assert.rejects(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { web3 } from "@coral-xyz/anchor";
|
||||
import { PDA } from "@orca-so/common-sdk";
|
||||
import * as anchor from "@project-serum/anchor";
|
||||
import { web3 } from "@project-serum/anchor";
|
||||
import { ASSOCIATED_TOKEN_PROGRAM_ID, Token, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { Keypair } from "@solana/web3.js";
|
||||
import * as assert from "assert";
|
||||
|
@ -24,12 +24,13 @@ import {
|
|||
TickSpacing,
|
||||
ZERO_BN
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { initTestPool, openPosition } from "../utils/init-utils";
|
||||
import { generateDefaultOpenPositionParams } from "../utils/test-builders";
|
||||
|
||||
describe("open_position", () => {
|
||||
const provider = anchor.AnchorProvider.local();
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
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 * as anchor from "@project-serum/anchor";
|
||||
import { web3 } from "@project-serum/anchor";
|
||||
import { ASSOCIATED_TOKEN_PROGRAM_ID, Token, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, Token } from "@solana/spl-token";
|
||||
import { Keypair, PublicKey } from "@solana/web3.js";
|
||||
import * as assert from "assert";
|
||||
import {
|
||||
|
@ -14,26 +14,27 @@ import {
|
|||
OpenPositionWithMetadataBumpsData,
|
||||
PDAUtil,
|
||||
PositionData,
|
||||
toTx,
|
||||
WhirlpoolContext,
|
||||
WhirlpoolIx
|
||||
WhirlpoolIx,
|
||||
toTx
|
||||
} from "../../src";
|
||||
import { openPositionAccounts } from "../../src/utils/instructions-util";
|
||||
import {
|
||||
ONE_SOL,
|
||||
TickSpacing,
|
||||
ZERO_BN,
|
||||
createMint,
|
||||
createMintInstructions,
|
||||
mintToByAuthority,
|
||||
ONE_SOL,
|
||||
systemTransferTx,
|
||||
TickSpacing,
|
||||
ZERO_BN
|
||||
systemTransferTx
|
||||
} from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { initTestPool, openPositionWithMetadata } from "../utils/init-utils";
|
||||
import { generateDefaultOpenPositionParams } from "../utils/test-builders";
|
||||
|
||||
describe("open_position_with_metadata", () => {
|
||||
const provider = anchor.AnchorProvider.local();
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
@ -308,7 +309,7 @@ describe("open_position_with_metadata", () => {
|
|||
|
||||
it("fails with non-program metadata program", async () => {
|
||||
const notMetadataProgram = Keypair.generate();
|
||||
const tx = new TransactionBuilder(ctx.provider.connection, ctx.wallet).addInstruction(
|
||||
const tx = new TransactionBuilder(ctx.provider.connection, ctx.wallet, ctx.txBuilderOpts).addInstruction(
|
||||
buildOpenWithAccountOverrides({
|
||||
metadataProgram: notMetadataProgram.publicKey,
|
||||
})
|
||||
|
@ -323,7 +324,7 @@ describe("open_position_with_metadata", () => {
|
|||
});
|
||||
|
||||
it("fails with non-metadata program ", async () => {
|
||||
const tx = new TransactionBuilder(ctx.provider.connection, ctx.wallet).addInstruction(
|
||||
const tx = new TransactionBuilder(ctx.provider.connection, ctx.wallet, ctx.txBuilderOpts).addInstruction(
|
||||
buildOpenWithAccountOverrides({
|
||||
metadataProgram: TOKEN_PROGRAM_ID,
|
||||
})
|
||||
|
@ -339,7 +340,7 @@ describe("open_position_with_metadata", () => {
|
|||
|
||||
it("fails with non-valid update_authority program", async () => {
|
||||
const notUpdateAuth = Keypair.generate();
|
||||
const tx = new TransactionBuilder(ctx.provider.connection, ctx.wallet).addInstruction(
|
||||
const tx = new TransactionBuilder(ctx.provider.connection, ctx.wallet, ctx.txBuilderOpts).addInstruction(
|
||||
buildOpenWithAccountOverrides({
|
||||
metadataUpdateAuth: notUpdateAuth.publicKey,
|
||||
})
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import * as anchor from "@project-serum/anchor";
|
||||
import * as anchor from "@coral-xyz/anchor";
|
||||
import * as assert from "assert";
|
||||
import { toTx, WhirlpoolContext, WhirlpoolIx, WhirlpoolsConfigData } from "../../src";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { generateDefaultConfigParams } from "../utils/test-builders";
|
||||
|
||||
describe("set_collect_protocol_fee_authority", () => {
|
||||
const provider = anchor.AnchorProvider.local();
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
@ -49,7 +50,7 @@ describe("set_collect_protocol_fee_authority", () => {
|
|||
newCollectProtocolFeesAuthority: provider.wallet.publicKey,
|
||||
})
|
||||
).buildAndExecute(),
|
||||
/Signature verification failed/
|
||||
/.*signature verification fail.*/i
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import * as anchor from "@project-serum/anchor";
|
||||
import * as anchor from "@coral-xyz/anchor";
|
||||
import * as assert from "assert";
|
||||
import {
|
||||
InitPoolParams,
|
||||
|
@ -6,15 +6,16 @@ import {
|
|||
toTx,
|
||||
WhirlpoolContext,
|
||||
WhirlpoolData,
|
||||
WhirlpoolIx,
|
||||
WhirlpoolIx
|
||||
} from "../../src";
|
||||
import { TickSpacing } from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { initTestPool } from "../utils/init-utils";
|
||||
import { createInOrderMints, generateDefaultConfigParams } from "../utils/test-builders";
|
||||
|
||||
describe("set_default_fee_rate", () => {
|
||||
const provider = anchor.AnchorProvider.local();
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
@ -139,7 +140,7 @@ describe("set_default_fee_rate", () => {
|
|||
feeAuthority: feeAuthorityKeypair.publicKey,
|
||||
},
|
||||
}),
|
||||
/Signature verification failed/
|
||||
/.*signature verification fail.*/i
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import * as anchor from "@project-serum/anchor";
|
||||
import * as anchor from "@coral-xyz/anchor";
|
||||
import * as assert from "assert";
|
||||
import {
|
||||
InitPoolParams,
|
||||
|
@ -6,15 +6,16 @@ import {
|
|||
toTx,
|
||||
WhirlpoolContext,
|
||||
WhirlpoolData,
|
||||
WhirlpoolIx,
|
||||
WhirlpoolIx
|
||||
} from "../../src";
|
||||
import { TickSpacing } from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { initTestPool } from "../utils/init-utils";
|
||||
import { createInOrderMints } from "../utils/test-builders";
|
||||
|
||||
describe("set_default_protocol_fee_rate", () => {
|
||||
const provider = anchor.AnchorProvider.local();
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
@ -109,7 +110,7 @@ describe("set_default_protocol_fee_rate", () => {
|
|||
feeAuthority: feeAuthorityKeypair.publicKey,
|
||||
},
|
||||
}),
|
||||
/Signature verification failed/
|
||||
/.*signature verification fail.*/i
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import * as anchor from "@project-serum/anchor";
|
||||
import * as anchor from "@coral-xyz/anchor";
|
||||
import * as assert from "assert";
|
||||
import { toTx, WhirlpoolContext, WhirlpoolIx, WhirlpoolsConfigData } from "../../src";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { generateDefaultConfigParams } from "../utils/test-builders";
|
||||
|
||||
describe("set_fee_authority", () => {
|
||||
const provider = anchor.AnchorProvider.local();
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
@ -49,7 +50,7 @@ describe("set_fee_authority", () => {
|
|||
newFeeAuthority: provider.wallet.publicKey,
|
||||
})
|
||||
).buildAndExecute(),
|
||||
/Signature verification failed/
|
||||
/.*signature verification fail.*/i
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
import * as anchor from "@project-serum/anchor";
|
||||
import * as anchor from "@coral-xyz/anchor";
|
||||
import * as assert from "assert";
|
||||
import { toTx, WhirlpoolContext, WhirlpoolData, WhirlpoolIx } from "../../src";
|
||||
import { TickSpacing } from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { initTestPool } from "../utils/init-utils";
|
||||
import { generateDefaultConfigParams } from "../utils/test-builders";
|
||||
|
||||
describe("set_fee_rate", () => {
|
||||
const provider = anchor.AnchorProvider.local();
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
@ -27,14 +28,13 @@ describe("set_fee_rate", () => {
|
|||
|
||||
assert.equal(whirlpool.feeRate, feeTierParams.defaultFeeRate);
|
||||
|
||||
await program.rpc.setFeeRate(newFeeRate, {
|
||||
accounts: {
|
||||
whirlpoolsConfig: whirlpoolsConfigKey,
|
||||
whirlpool: whirlpoolKey,
|
||||
feeAuthority: feeAuthorityKeypair.publicKey,
|
||||
},
|
||||
signers: [feeAuthorityKeypair],
|
||||
});
|
||||
const setFeeRateTx = toTx(ctx, WhirlpoolIx.setFeeRateIx(program, {
|
||||
whirlpool: whirlpoolKey,
|
||||
whirlpoolsConfig: whirlpoolsConfigKey,
|
||||
feeAuthority: feeAuthorityKeypair.publicKey,
|
||||
feeRate: newFeeRate
|
||||
})).addSigner(feeAuthorityKeypair);
|
||||
await setFeeRateTx.buildAndExecute();
|
||||
|
||||
whirlpool = (await fetcher.getPool(poolInitInfo.whirlpoolPda.publicKey, true)) as WhirlpoolData;
|
||||
assert.equal(whirlpool.feeRate, newFeeRate);
|
||||
|
@ -86,7 +86,7 @@ describe("set_fee_rate", () => {
|
|||
feeRate: newFeeRate,
|
||||
})
|
||||
).buildAndExecute(),
|
||||
/Signature verification failed/
|
||||
/.*signature verification fail.*/i
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import * as anchor from "@project-serum/anchor";
|
||||
import * as anchor from "@coral-xyz/anchor";
|
||||
import * as assert from "assert";
|
||||
import { toTx, WhirlpoolContext, WhirlpoolData, WhirlpoolIx } from "../../src";
|
||||
import { TickSpacing } from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { initTestPool } from "../utils/init-utils";
|
||||
import { generateDefaultConfigParams } from "../utils/test-builders";
|
||||
|
||||
describe("set_protocol_fee_rate", () => {
|
||||
const provider = anchor.AnchorProvider.local();
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
@ -27,14 +27,13 @@ describe("set_protocol_fee_rate", () => {
|
|||
|
||||
assert.equal(whirlpool.protocolFeeRate, configInitInfo.defaultProtocolFeeRate);
|
||||
|
||||
await program.rpc.setProtocolFeeRate(newProtocolFeeRate, {
|
||||
accounts: {
|
||||
whirlpoolsConfig: whirlpoolsConfigKey,
|
||||
whirlpool: whirlpoolKey,
|
||||
feeAuthority: feeAuthorityKeypair.publicKey,
|
||||
},
|
||||
signers: [feeAuthorityKeypair],
|
||||
});
|
||||
const txBuilder = toTx(ctx, WhirlpoolIx.setProtocolFeeRateIx(program, {
|
||||
whirlpool: whirlpoolKey,
|
||||
whirlpoolsConfig: whirlpoolsConfigKey,
|
||||
feeAuthority: feeAuthorityKeypair.publicKey,
|
||||
protocolFeeRate: newProtocolFeeRate
|
||||
})).addSigner(feeAuthorityKeypair);
|
||||
await txBuilder.buildAndExecute();
|
||||
|
||||
whirlpool = (await fetcher.getPool(poolInitInfo.whirlpoolPda.publicKey, true)) as WhirlpoolData;
|
||||
assert.equal(whirlpool.protocolFeeRate, newProtocolFeeRate);
|
||||
|
@ -86,7 +85,7 @@ describe("set_protocol_fee_rate", () => {
|
|||
protocolFeeRate: newProtocolFeeRate,
|
||||
})
|
||||
).buildAndExecute(),
|
||||
/Signature verification failed/
|
||||
/.*signature verification fail.*/i
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { TransactionBuilder } from "@orca-so/common-sdk";
|
||||
import * as anchor from "@project-serum/anchor";
|
||||
import * as assert from "assert";
|
||||
import { NUM_REWARDS, toTx, WhirlpoolContext, WhirlpoolData, WhirlpoolIx } from "../../src";
|
||||
import { TickSpacing } from "../utils";
|
||||
import { defaultConfirmOptions } from "../utils/const";
|
||||
import { initTestPool } from "../utils/init-utils";
|
||||
|
||||
describe("set_reward_authority", () => {
|
||||
const provider = anchor.AnchorProvider.local();
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const provider = anchor.AnchorProvider.local(undefined, defaultConfirmOptions);
|
||||
|
||||
const program = anchor.workspace.Whirlpool;
|
||||
const ctx = WhirlpoolContext.fromWorkspace(provider, program);
|
||||
const fetcher = ctx.fetcher;
|
||||
|
@ -16,7 +17,7 @@ describe("set_reward_authority", () => {
|
|||
const { configKeypairs, poolInitInfo } = await initTestPool(ctx, TickSpacing.Standard);
|
||||
|
||||
const newKeypairs = generateKeypairs(NUM_REWARDS);
|
||||
const txBuilder = new TransactionBuilder(provider.connection, provider.wallet);
|
||||
const txBuilder = new TransactionBuilder(provider.connection, provider.wallet, ctx.txBuilderOpts);
|
||||
for (let i = 0; i < NUM_REWARDS; i++) {
|
||||
txBuilder.addInstruction(
|
||||
WhirlpoolIx.setRewardAuthorityIx(ctx.program, {
|
||||
|
@ -29,7 +30,9 @@ describe("set_reward_authority", () => {
|
|||
}
|
||||
await txBuilder
|
||||
.addSigner(configKeypairs.rewardEmissionsSuperAuthorityKeypair)
|
||||
.buildAndExecute();
|
||||
.buildAndExecute({
|
||||
maxSupportedTransactionVersion: undefined,
|
||||
});
|
||||
|
||||
const pool = (await fetcher.getPool(poolInitInfo.whirlpoolPda.publicKey)) as WhirlpoolData;
|
||||
for (let i = 0; i < NUM_REWARDS; i++) {
|
||||
|
@ -104,7 +107,7 @@ describe("set_reward_authority", () => {
|
|||
rewardIndex: 0,
|
||||
})
|
||||
).buildAndExecute(),
|
||||
/Signature verification failed/
|
||||
/.*signature verification fail.*/i
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue