Giter Club home page Giter Club logo

typescript-sdk's Introduction

⚠️ WARNING: DEPRECATED TYPESCRIPT SDK ⚠️

This Typescript SDK is for the legacy pools which are deprecated. We highly recommend you to use the Whirlpools SDK for the new and improved pools. You can find it here:

🌊 Whirlpools SDK on npmjs 🌊

Please update your implementations to avoid any issues or disruptions in the future.

Orca Typescript SDK

The Orca SDK contains a set of simple to use APIs to allow developers to integrate with the Orca platform.

Learn more Orca here.

Orca Token Swap V2

Trading Orca Liquidity Pools

  • Get detailed quotes and make swaps between trading pairs in an Orca Pool
  • Check your Orca Pool LP token balance and total supply

Supported Orca Pools

  • The SDK supports all pools currently listed on Orca

Provide Liquidity to Orca Pools

  • Deposit liquidity to supported Orca Pools
    • Deposit a trading pair, and receive LP token
  • Withdraw liquidity from supported Orca Pools
    • Withdraw a trading pair in exchange for LP token

Aquafarm Support

  • After depositing liquidtiy to a pool, the LP token can be deposited into the corresponding farm to receive an equivalent amount of farm token
  • Remember to withdraw the LP token in exchange for farm token before withdrawing liquidity from Orca Pool

DoubleDip Support

  • For farms with double-dip, the aquafarm tokens can be deposited into double-dip farm to receive double-dip rewards

Features Coming Soon

  • More trader information (APY, Volume)

Installation

Use your environment's package manager to install @orca-so/sdk and other related packages into your project.

yarn add @orca-so/sdk @solana/web3.js decimal.js
npm install @orca-so/sdk @solana/web3.js decimal.js

Usage

import { readFile } from "mz/fs";
import { Connection, Keypair } from "@solana/web3.js";
import { getOrca, OrcaFarmConfig, OrcaPoolConfig } from "@orca-so/sdk";
import Decimal from "decimal.js";

const main = async () => {
  /*** Setup ***/
  // 1. Read secret key file to get owner keypair
  const secretKeyString = await readFile("/Users/scuba/my-wallet/my-keypair.json", {
    encoding: "utf8",
  });
  const secretKey = Uint8Array.from(JSON.parse(secretKeyString));
  const owner = Keypair.fromSecretKey(secretKey);

  // 2. Initialzie Orca object with mainnet connection
  const connection = new Connection("https://api.mainnet-beta.solana.com", "singleGossip");
  const orca = getOrca(connection);

  try {
    /*** Swap ***/
    // 3. We will be swapping 0.1 SOL for some ORCA
    const orcaSolPool = orca.getPool(OrcaPoolConfig.ORCA_SOL);
    const solToken = orcaSolPool.getTokenB();
    const solAmount = new Decimal(0.1);
    const quote = await orcaSolPool.getQuote(solToken, solAmount);
    const orcaAmount = quote.getMinOutputAmount();

    console.log(`Swap ${solAmount.toString()} SOL for at least ${orcaAmount.toNumber()} ORCA`);
    const swapPayload = await orcaSolPool.swap(owner, solToken, solAmount, orcaAmount);
    const swapTxId = await swapPayload.execute();
    console.log("Swapped:", swapTxId, "\n");

    /*** Pool Deposit ***/
    // 4. Deposit SOL and ORCA for LP token
    const { maxTokenAIn, maxTokenBIn, minPoolTokenAmountOut } = await orcaSolPool.getDepositQuote(
      orcaAmount,
      solAmount
    );

    console.log(
      `Deposit at most ${maxTokenBIn.toNumber()} SOL and ${maxTokenAIn.toNumber()} ORCA, for at least ${minPoolTokenAmountOut.toNumber()} LP tokens`
    );
    const poolDepositPayload = await orcaSolPool.deposit(
      owner,
      maxTokenAIn,
      maxTokenBIn,
      minPoolTokenAmountOut
    );
    const poolDepositTxId = await poolDepositPayload.execute();
    console.log("Pool deposited:", poolDepositTxId, "\n");

    /*** Farm Deposit ***/
    // 5. Deposit some ORCA_SOL LP token for farm token
    const lpBalance = await orcaSolPool.getLPBalance(owner.publicKey);
    const orcaSolFarm = orca.getFarm(OrcaFarmConfig.ORCA_SOL_AQ);
    const farmDepositPayload = await orcaSolFarm.deposit(owner, lpBalance);
    const farmDepositTxId = await farmDepositPayload.execute();
    console.log("Farm deposited:", farmDepositTxId, "\n");
    // Note 1: for double dip, repeat step 5 but with the double dip farm
    // Note 2: to harvest reward, orcaSolFarm.harvest(owner)
    // Note 3: to get harvestable reward amount, orcaSolFarm.getHarvestableAmount(owner.publicKey)

    /*** Farm Withdraw ***/
    // 6. Withdraw ORCA_SOL LP token, in exchange for farm token
    const farmBalance = await orcaSolFarm.getFarmBalance(owner.publicKey); // withdraw the entire balance
    const farmWithdrawPayload = await orcaSolFarm.withdraw(owner, farmBalance);
    const farmWithdrawTxId = await farmWithdrawPayload.execute();
    console.log("Farm withdrawn:", farmWithdrawTxId, "\n");

    /*** Pool Withdraw ***/
    // 6. Withdraw SOL and ORCA, in exchange for ORCA_SOL LP token
    const withdrawTokenAmount = await orcaSolPool.getLPBalance(owner.publicKey);
    const withdrawTokenMint = orcaSolPool.getPoolTokenMint();
    const { maxPoolTokenAmountIn, minTokenAOut, minTokenBOut } = await orcaSolPool.getWithdrawQuote(
      withdrawTokenAmount,
      withdrawTokenMint
    );

    console.log(
      `Withdraw at most ${maxPoolTokenAmountIn.toNumber()} ORCA_SOL LP token for at least ${minTokenAOut.toNumber()} ORCA and ${minTokenBOut.toNumber()} SOL`
    );
    const poolWithdrawPayload = await orcaSolPool.withdraw(
      owner,
      maxPoolTokenAmountIn,
      minTokenAOut,
      minTokenBOut
    );
    const poolWithdrawTxId = await poolWithdrawPayload.execute();
    console.log("Pool withdrawn:", poolWithdrawTxId, "\n");
  } catch (err) {
    console.warn(err);
  }
};

main()
  .then(() => {
    console.log("Done");
  })
  .catch((e) => {
    console.error(e);
  });

Devnet Testing

The example code above can be run on devnet by updating the import statement:

import { getOrca, OrcaFarmConfig, OrcaPoolConfig, Network } from "@orca-so/sdk";

And changing two lines of code like so:

const connection = new Connection("https://api.devnet.solana.com", "singleGossip");
const orca = getOrca(connection, Network.DEVNET);

One caveat to note is that there are only a few devnet pools available, so if you try to access pools that are only available on mainnet, the code will throw an error. The example code uses ORCA_SOL, which exists on the devnet.

Technical Notes

Decimals & OrcaU64

The SDK relies on the use of Decimal for number inputs and Decimal/OrcaU64 for token-value inputs. If a Decimal instance is provided for a token-value input, it will be automatically transformed to the token's scale.

Stability of the Public Util Functions

We hope you find the tools we used to build our API useful in the public/utils folder. Due to our on-going development of the Orca platform, we cannot guarrantee the stability of the util APIs. The trading APIs can only be upgraded on major version updates.

Support

Integration Questions

Have problems integrating with the SDK? Pop by over to our Discord #integrations channel and chat with one of our engineers.

Issues / Bugs

If you found a bug, open up an issue on github with the prefix [ISSUE]. To help us be more effective in resolving the problem, be specific in the steps it took to reproduce the problem (ex. when did the issue occur, code samples, debug logs etc).

Feedback

Got ideas on how to improve the system? Open up an issue on github with the prefix [FEEDBACK] and let's brainstorm more about it together!

License

MIT

typescript-sdk's People

Contributors

0xalexbai avatar arrowana avatar atulbipin avatar bradenkeith avatar odcheung avatar oritheorca avatar rawfalafel avatar yihwan avatar yugure-orca avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

typescript-sdk's Issues

can i write spl programs use Orca programs to swap?

it all knows: The Orca SDK contains a set of simple to use APIs to allow developers to integrate with the Orca exchange platform.

where is Orca programs code ?
can i write spl program to integrate with the Orca exchange platform to swap? if can, where i can find demo.

Error using Webpack:Uncaught ReferenceError: process is not defined

Uncaught ReferenceError: process is not defined at eval (util.js:109) at Object../node_modules/util/util.js (index.js?t=1638501186101:2313) at __webpack_require__ (index.js?t=1638501186101:2657) at eval (assertion_error.js:35) at Object../node_modules/assert/build/internal/assert/assertion_error.js (index.js?t=1638501186101:954) at __webpack_require__ (index.js?t=1638501186101:2657) at eval (assert.js:36) at Object../node_modules/assert/build/assert.js (index.js?t=1638501186101:943) at __webpack_require__ (index.js?t=1638501186101:2657) at eval (index.js:9)

getQuote method not working

The getQuote method returns an error. I believe it is an rpc related error. This is what the error produced looks like

{"jsonrpc":"2.0","error":{"code": 403, "message":"Access forbidden, contact your app developer or [email protected]."}, "id": "f25e88ef-b04c-49a9-b533-4ee1f99f9cad" }

Any fix or is this package no longer being worked on?

How can we gain access to deprecated pools?

Hello. I am trying to use a Solong wallet (not supported naturally via Orca) to remove liquidity in the deprecated SOL/USDC pool. I provided this liquidity through Step.Finance and it seems like since it is deprecated now I cannot remove it. I was hoping to use the SDK to do this. How can I get that done?

can not swap sol to usdc by code?

our origin code use your sdk runs well on our devices. but now even if we run de demo code on SOL_USDC. swap usdc to sol will success, but sol to usdc will fail.

Can`t swap SOL_USDT, SOL_USDС on devnet

I use example code from readme for swap ORCA_SOL. It is worked.

But, when i changed OrcaPoolConfig to SOL_USDT or SOL_USDC i have this error:
"message": "failed to send transaction: Transaction simulation failed: Error processing Instruction 4: invalid account data for instruction",

Logs:

"logs": [ "Program 11111111111111111111111111111111 invoke [1]", "Program 11111111111111111111111111111111 success", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]", "Program log: Instruction: InitializeAccount", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3582 of 1400000 compute units", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success", "Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]", "Program log: Create", "Program 11111111111111111111111111111111 invoke [2]", "Program 11111111111111111111111111111111 success", "Program log: Initialize the associated token account", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]", "Program log: Instruction: InitializeAccount3", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2933 of 1384220 compute units", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success", "Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 15754 of 1396418 compute units", "Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL success", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]", "Program log: Instruction: Approve", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2285 of 1380664 compute units", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success", "Program 3xQ8SWv2GaFXXpHZNqkXsdxq5DZciHBz6ZFoPPfbFd7U invoke [1]", "Program log: Instruction: Swap", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]", "Program log: Instruction: Transfer", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3312 of 1360768 compute units", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]", "Program log: Instruction: MintTo", "Program log: Error: InvalidAccountData", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1598 of 1328809 compute units", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: invalid account data for instruction", "Program 3xQ8SWv2GaFXXpHZNqkXsdxq5DZciHBz6ZFoPPfbFd7U consumed 51168 of 1378379 compute units", "Program 3xQ8SWv2GaFXXpHZNqkXsdxq5DZciHBz6ZFoPPfbFd7U failed: invalid account data for instruction" ],

Cannot import orca-sdk react native

Error: [Error: InternalError Metro has encountered an error: While trying to resolve module @orca-so/sdk from file , the package /Users/haianh/solashi/app/node_modules/@orca-so/sdk/package.json was successfully found. However, this package itself specifies a main module field that could not be resolved (/Users/haianh/solashi/app/node_modules/@orca-so/sdk/dist/index.js. Indeed, none of these files exist:

No api is equivalent to the getAmountIns() function

Currently Orca SDK only provides getQuote() function which is equivalent to getAmountOuts() function like on other AMM. I have not found a function on the Orca SDK that is equivalent to the getAmountIns() function.
Please support. Thank you!

Cannot use namespace 'Layout' as a type.

Hey i have the error mentioned in the title, do someone know how to fix it ? details down

node_modules/@orca-so/sdk/node_modules/@solana/spl-token/lib/index.d.ts:28:28 - error TS2709: Cannot use namespace 'Layout' as a type.

28   export const MintLayout: Layout;
                              ~~~~~~

node_modules/@orca-so/sdk/node_modules/@solana/spl-token/lib/index.d.ts:37:31 - error TS2709: Cannot use namespace 'Layout' as a type.

37   export const AccountLayout: Layout;
                                 ~~~~~~


Found 2 errors in the same file, starting at: node_modules/@orca-so/sdk/node_modules/@solana/spl-token/lib/index.d.ts:28

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.