Orca
Orca is the easiest place to trade cryptocurrency on the Solana blockchain. For a detailed description refer to the official Orca documentation and Orca Developer Portal.
- Create an IDex istance, providing a default account and and the RPC client istance:
IDex dex = new OrcaDex(
WalletH.Account,
WalletH.Rpc
)
TokenData tokenA = await dex.GetTokenBySymbol("USDC");
TokenData tokenB = await dex.GetTokenBySymbol("ORCA");
Pool whirlpool = await dex.FindWhirlpoolAddress(tokenA.MintAddress, tokenB.MintAddress)
- Get a swap quote for 1 USDC:
SwapQuote swapQuote = await dex.GetSwapQuoteFromWhirlpool(
whirlpool.Address,
DecimalUtil.ToUlong(1, tokenA.Decimals),
tokenA.MintAddress,
slippageTolerance: 0.1,
);
var quote = DecimalUtil.FromBigInteger(swapQuote.EstimatedAmountOut, tokenB.Decimals);
Debug.Log(quote); // Amount of espected Orca token to receive
- Create the swap transaction:
Transaction tx = await dex.SwapWithQuote(
whirlpool,
swapQuote
);
- Sign and send the swap transaction:
await WalletH.Base.SignAndSendTransaction(tx);
Open a position and increase the liquidity of the ORCA/USDC whirlpool
An example of adding 5 ORCA and 5 USDC to the liquidity of the pool, minting a metaplex NFT representing the position
OrcaDex dex = new OrcaDex(
WalletH.Account,
WalletH.Rpc
);
var orcaToken = await dex.GetTokenBySymbol("ORCA");
var usdcToken = await dex.GetTokenBySymbol("USDC");
var whirlpool = await dex.FindWhirlpoolAddress(
usdcToken.MintAddress,
orcaToken.MintAddress
);
Account mint = new Account();
Transaction tx = await dex.OpenPositionWithLiquidity(
whirlpool,
mint,
-1792,
1152,
DecimalUtil.ToUlong(5, tokenA.Decimals),
DecimalUtil.ToUlong(5, tokenB.Decimals),
commitment: Commitment.Confirmed
);
var txSer = tx.Build(new List<Account>() {
WalletH.Account,
mint
});
await WalletH.Base.SignAndSendTransaction(tx);