Guides

DEX integration with Orca

Orca is natively supported in the SDK. Utility methods are provided to easily build the transactions needed to make swaps, open positions, manage cash and interact with Whirlpools.

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.


Perform a Swap

  • Create an IDex istance, providing a default account and and the RPC client istance:
IDex dex = new OrcaDex(
    Web3.Account, 
    Web3.Rpc
)
  • Create an IDex istance:
TokenData tokenA = await dex.GetTokenBySymbol("USDC");
TokenData tokenB = await dex.GetTokenBySymbol("ORCA");
  • Find the whirlpool:
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 Webs.Wallet.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(
    Web3.Account, 
    Web3.Rpc
);


var orcaToken = await dex.GetTokenBySymbol("ORCA");
var usdcToken = await dex.GetTokenBySymbol("USDC");


Debug.Log($"Token A: {orcaToken}");
Debug.Log($"Token A: {usdcToken}");


var whirlpool = await dex.FindWhirlpoolAddress(
    usdcToken.MintAddress, 
    orcaToken.MintAddress
);


Debug.Log($"Whirlpool: {whirlpool.Address}");


Account mint = new Account();


Transaction tx = await dex.OpenPositionWithLiquidity(
    whirlpool.Address,
    mint,
    -443520,
    443520,
    DecimalUtil.ToUlong(0.1, orcaToken.Decimals),
    DecimalUtil.ToUlong(0.25, usdcToken.Decimals),
    slippageTolerance: 0.5,
    withMetadata: true,
    commitment: Commitment.Confirmed
);


tx.PartialSign(Web3.Account);
tx.PartialSign(mint);


var res = await Web3.Wallet.SignAndSendTransaction(tx, commitment: Commitment.Confirmed);
Debug.Log(res.Result);
Previous
Soar integration: Leaderboards & Rankings