-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into wjthieme/rust-sdk
- Loading branch information
Showing
101 changed files
with
8,157 additions
and
2,724 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Setting up your script environment | ||
```bash | ||
yarn | ||
``` | ||
|
||
# Set your RPC and wallet | ||
```bash | ||
export ANCHOR_PROVIDER_URL=<RPC URL> | ||
export ANCHOR_WALLET=<WALLET JSON PATH> | ||
``` | ||
|
||
Example: | ||
```bash | ||
export ANCHOR_PROVIDER_URL=http://localhost:8899 | ||
export ANCHOR_WALLET=~/.config/solana/id.json | ||
``` | ||
|
||
# Supported commands | ||
Token-2022 tokens are acceptable 👍 | ||
|
||
## Config & FeeTier | ||
### initialize | ||
- `yarn start initializeConfig`: initialize new WhirlpoolsConfig account | ||
- `yarn start initializeConfigExtension`: initialize new WhirlpoolsConfigExtension account | ||
- `yarn start initializeFeeTier`: initialize new FeeTier account | ||
|
||
### update | ||
- `yarn start setTokenBadgeAuthority`: set new TokenBadge authority on WhirlpoolsConfigExtension | ||
- `yarn start setDefaultProtocolFeeRate`: set new default protocol fee rate on WhirlpoolsConfig | ||
- `yarn start setFeeAuthority`: set new fee authority on WhirlpoolsConfig | ||
- `yarn start setCollectProtocolFeesAuthority`: set new collect protocol fees authority on WhirlpoolsConfig | ||
- `yarn start setRewardEmissionsSuperAuthority`: set new reward emissions super authority on WhirlpoolsConfig | ||
- TODO: set config extension authority | ||
|
||
## Whirlpool & TickArray | ||
- `yarn start initializeWhirlpool`: initialize new Whirlpool account | ||
- `yarn start initializeTickArray`: initialize new TickArray account | ||
|
||
## TokenBadge | ||
- `yarn start initializeTokenBadge`: initialize new TokenBadge account | ||
- `yarn start deleteTokenBadge`: delete TokenBadge account | ||
|
||
## Reward | ||
- `yarn start setRewardAuthority`: set new reward authority of rewards on a whirlpool | ||
- `yarn start initializeReward`: initialize new reward for a whirlpool | ||
- TODO: set reward emission | ||
|
||
## Position | ||
- `yarn start openPosition`: open a new position | ||
- `yarn start increaseLiquidity`: deposit to a position | ||
- `yarn start decreaseLiquidity`: withdraw from a position | ||
- `yarn start collectFees`: collect fees from a position | ||
- `yarn start collectRewards`: collect rewards from a position | ||
- `yarn start closePosition`: close an empty position | ||
|
||
## Swap | ||
- `yarn start pushPrice`: adjust pool price (possible if pool liquidity is zero or very small) | ||
|
||
## WSOL and ATA creation | ||
TODO: WSOL handling & create ATA if needed (workaround exists, please see the following) | ||
|
||
### workaround for WSOL | ||
`whirlpool-mgmt-tools` works well with ATA, so using WSOL on ATA is workaround. | ||
|
||
- wrap 1 SOL: `spl-token wrap 1` (ATA for WSOL will be initialized with 1 SOL) | ||
- unwrap: `spl-token unwrap` (ATA for WSOL will be closed) | ||
- add 1 WSOL: `solana transfer <WSOL ATA address> 1` then `spl-token sync-native` (transfer & sync are needed) | ||
|
||
### workaround for ATA | ||
We can easily initialize ATA with spl-token CLI. | ||
|
||
``` | ||
spl-token create-account <mint address> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "@orca-so/whirlpools-sdk-cli", | ||
"private": true, | ||
"version": "1.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"build": "tsc --noEmit", | ||
"start": "tsx src/index.ts" | ||
}, | ||
"dependencies": { | ||
"@coral-xyz/anchor": "0.29.0", | ||
"@orca-so/common-sdk": "0.6.4", | ||
"@orca-so/orca-sdk": "0.2.0", | ||
"@orca-so/whirlpools-sdk": "*", | ||
"@solana/spl-token": "0.4.1", | ||
"@solana/web3.js": "^1.90.0", | ||
"@types/bn.js": "^5.1.0", | ||
"bs58": "^6.0.0", | ||
"decimal.js": "^10.4.3", | ||
"js-convert-case": "^4.2.0", | ||
"prompts": "^2.4.2" | ||
}, | ||
"devDependencies": { | ||
"@types/prompts": "^2.4.9", | ||
"tsx": "^4.19.0", | ||
"typescript": "^5.4.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { PublicKey } from "@solana/web3.js"; | ||
import { WhirlpoolIx } from "@orca-so/whirlpools-sdk"; | ||
import { TransactionBuilder } from "@orca-so/common-sdk"; | ||
import { | ||
getAssociatedTokenAddressSync, | ||
TOKEN_2022_PROGRAM_ID, | ||
TOKEN_PROGRAM_ID, | ||
} from "@solana/spl-token"; | ||
import { sendTransaction } from "../utils/transaction_sender"; | ||
import { ctx } from "../utils/provider"; | ||
import { promptText } from "../utils/prompt"; | ||
|
||
console.info("close Position..."); | ||
|
||
// prompt | ||
const positionPubkeyStr = await promptText("positionPubkey"); | ||
|
||
const positionPubkey = new PublicKey(positionPubkeyStr); | ||
const position = await ctx.fetcher.getPosition(positionPubkey); | ||
if (!position) { | ||
throw new Error("position not found"); | ||
} | ||
const positionMint = await ctx.fetcher.getMintInfo(position.positionMint); | ||
if (!positionMint) { | ||
throw new Error("positionMint not found"); | ||
} | ||
|
||
if (!position.liquidity.isZero()) { | ||
throw new Error("position is not empty (liquidity is not zero)"); | ||
} | ||
|
||
if (!position.feeOwedA.isZero() || !position.feeOwedB.isZero()) { | ||
throw new Error("position has collectable fees"); | ||
} | ||
|
||
if (!position.rewardInfos.every((r) => r.amountOwed.isZero())) { | ||
throw new Error("position has collectable rewards"); | ||
} | ||
|
||
const builder = new TransactionBuilder(ctx.connection, ctx.wallet); | ||
|
||
if (positionMint.tokenProgram.equals(TOKEN_PROGRAM_ID)) { | ||
builder.addInstruction( | ||
WhirlpoolIx.closePositionIx(ctx.program, { | ||
position: positionPubkey, | ||
positionAuthority: ctx.wallet.publicKey, | ||
positionTokenAccount: getAssociatedTokenAddressSync( | ||
position.positionMint, | ||
ctx.wallet.publicKey, | ||
), | ||
positionMint: position.positionMint, | ||
receiver: ctx.wallet.publicKey, | ||
}), | ||
); | ||
} else { | ||
builder.addInstruction( | ||
WhirlpoolIx.closePositionWithTokenExtensionsIx(ctx.program, { | ||
position: positionPubkey, | ||
positionAuthority: ctx.wallet.publicKey, | ||
positionTokenAccount: getAssociatedTokenAddressSync( | ||
position.positionMint, | ||
ctx.wallet.publicKey, | ||
undefined, | ||
TOKEN_2022_PROGRAM_ID, | ||
), | ||
positionMint: position.positionMint, | ||
receiver: ctx.wallet.publicKey, | ||
}), | ||
); | ||
} | ||
|
||
await sendTransaction(builder); | ||
|
||
/* | ||
SAMPLE EXECUTION LOG | ||
connection endpoint http://localhost:8899 | ||
wallet r21Gamwd9DtyjHeGywsneoQYR39C1VDwrw7tWxHAwh6 | ||
close Position... | ||
prompt: positionPubkey: H4WEb57EYh5AhorHArjgRXVgSBJRMZi3DvsLb3J1XNj6 | ||
estimatedComputeUnits: 120649 | ||
prompt: priorityFeeInSOL: 0 | ||
Priority fee: 0 SOL | ||
process transaction... | ||
transaction is still valid, 150 blocks left (at most) | ||
sending... | ||
confirming... | ||
✅successfully landed | ||
signature dQwedycTbM9UTYwQiiUE5Q7ydZRzL3zywaQ3xEo3RhHxDvfsY8wkAakSXQRdXswxdQCLLMwwDJVSNHYcTCDDcf3 | ||
*/ |
Oops, something went wrong.