@orca-so/sdk
Advanced tools
Comparing version 1.0.1 to 1.0.2-beta.1
@@ -1,2 +0,2 @@ | ||
import { Percentage } from "../model/utils/percentage"; | ||
import { Percentage } from "../public/utils/models/percentage"; | ||
export declare const defaultSlippagePercentage: Percentage; |
@@ -1,3 +0,4 @@ | ||
import { OrcaPoolConfig, OrcaToken } from ".."; | ||
import { OrcaPoolParams } from "../model/orca/pool/pool-types"; | ||
import { OrcaPoolConfig } from "../public/pools/config"; | ||
import { OrcaToken } from "../public/pools/types"; | ||
/** | ||
@@ -4,0 +5,0 @@ * Constants |
@@ -5,5 +5,5 @@ "use strict"; | ||
const web3_js_1 = require("@solana/web3.js"); | ||
const __1 = require(".."); | ||
const pool_types_1 = require("../model/orca/pool/pool-types"); | ||
const percentage_1 = require("../model/utils/percentage"); | ||
const config_1 = require("../public/pools/config"); | ||
const percentage_utils_1 = require("../public/utils/percentage-utils"); | ||
/** | ||
@@ -57,4 +57,4 @@ * Constants | ||
feeStructure: { | ||
traderFee: percentage_1.PercentageUtils.fromFraction(2, 1000), | ||
ownerFee: percentage_1.PercentageUtils.fromFraction(1, 1000), | ||
traderFee: percentage_utils_1.PercentageUtils.fromFraction(2, 1000), | ||
ownerFee: percentage_utils_1.PercentageUtils.fromFraction(1, 1000), | ||
}, | ||
@@ -76,4 +76,4 @@ }); | ||
feeStructure: { | ||
traderFee: percentage_1.PercentageUtils.fromFraction(2, 1000), | ||
ownerFee: percentage_1.PercentageUtils.fromFraction(1, 1000), | ||
traderFee: percentage_utils_1.PercentageUtils.fromFraction(2, 1000), | ||
ownerFee: percentage_utils_1.PercentageUtils.fromFraction(1, 1000), | ||
}, | ||
@@ -95,4 +95,4 @@ }); | ||
feeStructure: { | ||
traderFee: percentage_1.PercentageUtils.fromFraction(2, 1000), | ||
ownerFee: percentage_1.PercentageUtils.fromFraction(1, 1000), | ||
traderFee: percentage_utils_1.PercentageUtils.fromFraction(2, 1000), | ||
ownerFee: percentage_utils_1.PercentageUtils.fromFraction(1, 1000), | ||
}, | ||
@@ -114,4 +114,4 @@ }); | ||
feeStructure: { | ||
traderFee: percentage_1.PercentageUtils.fromFraction(2, 1000), | ||
ownerFee: percentage_1.PercentageUtils.fromFraction(1, 1000), | ||
traderFee: percentage_utils_1.PercentageUtils.fromFraction(2, 1000), | ||
ownerFee: percentage_utils_1.PercentageUtils.fromFraction(1, 1000), | ||
}, | ||
@@ -133,12 +133,12 @@ }); | ||
feeStructure: { | ||
traderFee: percentage_1.PercentageUtils.fromFraction(2, 1000), | ||
ownerFee: percentage_1.PercentageUtils.fromFraction(1, 1000), | ||
traderFee: percentage_utils_1.PercentageUtils.fromFraction(2, 1000), | ||
ownerFee: percentage_utils_1.PercentageUtils.fromFraction(1, 1000), | ||
}, | ||
}); | ||
exports.orcaPoolConfigs = { | ||
[__1.OrcaPoolConfig.SOL_USDC]: exports.solUsdcPool, | ||
[__1.OrcaPoolConfig.SOL_USDT]: exports.solUsdtPool, | ||
[__1.OrcaPoolConfig.RAY_SOL]: exports.raySolPool, | ||
[__1.OrcaPoolConfig.ETH_SOL]: exports.ethSolPool, | ||
[__1.OrcaPoolConfig.ETH_USDC]: exports.ethUsdcPool, | ||
[config_1.OrcaPoolConfig.SOL_USDC]: exports.solUsdcPool, | ||
[config_1.OrcaPoolConfig.SOL_USDT]: exports.solUsdtPool, | ||
[config_1.OrcaPoolConfig.RAY_SOL]: exports.raySolPool, | ||
[config_1.OrcaPoolConfig.ETH_SOL]: exports.ethSolPool, | ||
[config_1.OrcaPoolConfig.ETH_USDC]: exports.ethUsdcPool, | ||
}; |
@@ -1,4 +0,1 @@ | ||
export * from "./public/pools"; | ||
export * from "./public/types"; | ||
export * from "./public/orca"; | ||
export * from "./public/utils/orca-u64"; | ||
export * from "./public"; |
@@ -13,5 +13,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./public/pools"), exports); | ||
__exportStar(require("./public/types"), exports); | ||
__exportStar(require("./public/orca"), exports); | ||
__exportStar(require("./public/utils/orca-u64"), exports); | ||
__exportStar(require("./public"), exports); |
import { Connection } from "@solana/web3.js"; | ||
import { OrcaPoolConfig } from "../../public/pools"; | ||
import { Orca, OrcaPool } from "../../public/types"; | ||
import { OrcaPoolConfig, OrcaPool } from "../.."; | ||
import { Orca } from "../../public"; | ||
export declare class OrcaImpl implements Orca { | ||
@@ -5,0 +5,0 @@ private connection; |
@@ -1,6 +0,6 @@ | ||
import { Connection, Keypair, PublicKey, TransactionSignature } from "@solana/web3.js"; | ||
import { OrcaPool, OrcaU64, Quote } from "../../.."; | ||
import { Connection, PublicKey, Keypair, TransactionSignature } from "@solana/web3.js"; | ||
import Decimal from "decimal.js"; | ||
import { OrcaPool, OrcaToken, Quote } from "../../.."; | ||
import { OrcaU64 } from "../../../public"; | ||
import { OrcaPoolParams } from "./pool-types"; | ||
import Decimal from "decimal.js"; | ||
import { OrcaToken } from "../../../public/types"; | ||
export declare class OrcaPoolImpl implements OrcaPool { | ||
@@ -7,0 +7,0 @@ private connection; |
@@ -22,20 +22,11 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OrcaPoolImpl = void 0; | ||
const __1 = require("../../.."); | ||
const spl_token_1 = require("@solana/spl-token"); | ||
const web3_js_1 = require("@solana/web3.js"); | ||
const orca_defaults_1 = require("../../../constants/orca-defaults"); | ||
const deserialize_account_1 = require("../../../utils/web3/deserialize-account"); | ||
const get_token_count_1 = require("../../../utils/web3/get-token-count"); | ||
const percentage_utils_1 = require("../../../public/utils/percentage-utils"); | ||
const public_1 = require("../../../public"); | ||
const pool_instructions_1 = require("../../../public/utils/web3/instructions/pool-instructions"); | ||
const quote_builder_1 = require("../../quote/quote-builder"); | ||
const percentage_1 = require("../../utils/percentage"); | ||
const transaction_builder_1 = __importDefault(require("../../../utils/web3/transactions/transaction-builder")); | ||
const pool_instructions_1 = require("../../../utils/web3/instructions/pool-instructions"); | ||
const spl_token_1 = require("@solana/spl-token"); | ||
const transactions_1 = require("../../../utils/web3/transactions/transactions"); | ||
const pool_utils_1 = require("../../../utils/pool-utils"); | ||
const u64_utils_1 = require("../../../utils/u64-utils"); | ||
const ata_utils_1 = require("../../../utils/web3/ata-utils"); | ||
class OrcaPoolImpl { | ||
@@ -56,13 +47,13 @@ constructor(connection, config) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const address = yield ata_utils_1.deriveAssociatedTokenAddress(owner, this.poolParams.poolTokenMint); | ||
const address = yield public_1.deriveAssociatedTokenAddress(owner, this.poolParams.poolTokenMint); | ||
const accountInfo = yield this.connection.getAccountInfo(address); | ||
// User does not have a balance for this account | ||
if (accountInfo == undefined) { | ||
return __1.OrcaU64.fromNumber(0, this.poolParams.poolTokenDecimals); | ||
return public_1.OrcaU64.fromNumber(0, this.poolParams.poolTokenDecimals); | ||
} | ||
const result = deserialize_account_1.deserializeAccount(accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.data); | ||
const result = public_1.deserializeAccount(accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.data); | ||
if (result == undefined) { | ||
throw new Error("Failed to parse user account for LP token."); | ||
} | ||
return __1.OrcaU64.fromU64(result.amount, this.poolParams.poolTokenDecimals); | ||
return public_1.OrcaU64.fromU64(result.amount, this.poolParams.poolTokenDecimals); | ||
}); | ||
@@ -74,3 +65,3 @@ } | ||
const amt = new spl_token_1.u64(context.value.amount); | ||
return __1.OrcaU64.fromU64(amt, this.poolParams.poolTokenDecimals); | ||
return public_1.OrcaU64.fromU64(amt, this.poolParams.poolTokenDecimals); | ||
}); | ||
@@ -80,7 +71,7 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const slippageTolerance = slippage === undefined ? orca_defaults_1.defaultSlippagePercentage : percentage_1.PercentageUtils.fromDecimal(slippage); | ||
const slippageTolerance = slippage === undefined ? orca_defaults_1.defaultSlippagePercentage : percentage_utils_1.PercentageUtils.fromDecimal(slippage); | ||
const feeStructure = this.poolParams.feeStructure; | ||
const { inputPoolToken, outputPoolToken } = pool_utils_1.getTokens(this.poolParams, inputToken.mint.toString()); | ||
const inputAmountU64 = u64_utils_1.U64Utils.toTokenU64(inputAmount, inputPoolToken, "inputAmount"); | ||
const poolTokenCount = yield get_token_count_1.getTokenCount(this.connection, this.poolParams, inputPoolToken, outputPoolToken); | ||
const { inputPoolToken, outputPoolToken } = public_1.getTokens(this.poolParams, inputToken.mint.toString()); | ||
const inputAmountU64 = public_1.U64Utils.toTokenU64(inputAmount, inputPoolToken, "inputAmount"); | ||
const poolTokenCount = yield public_1.getTokenCount(this.connection, this.poolParams, inputPoolToken, outputPoolToken); | ||
const quoteParams = Object.assign(Object.assign({}, poolTokenCount), { inputToken: inputPoolToken, outputToken: outputPoolToken, feeStructure: feeStructure, slippageTolerance: slippageTolerance }); | ||
@@ -98,7 +89,7 @@ const quoteBuilder = quote_builder_1.QuoteBuilderFactory.getBuilder(this.poolParams.curveType); | ||
const ownerAddress = owner.publicKey; | ||
const { inputPoolToken, outputPoolToken } = pool_utils_1.getTokens(this.poolParams, inputToken.mint.toString()); | ||
const amountInU64 = u64_utils_1.U64Utils.toTokenU64(amountIn, inputPoolToken, "amountIn"); | ||
const minimumAmountOutU64 = u64_utils_1.U64Utils.toTokenU64(minimumAmountOut, outputPoolToken, "minimumAmountOut"); | ||
const _a = yield ata_utils_1.resolveAssociatedTokenAddress(this.connection, owner.publicKey, inputPoolToken.mint, amountInU64), { address: inputPoolTokenUserAddress } = _a, resolveInputAddrInstructions = __rest(_a, ["address"]); | ||
const _b = yield ata_utils_1.resolveAssociatedTokenAddress(this.connection, owner.publicKey, outputPoolToken.mint, amountInU64), { address: outputPoolTokenUserAddress } = _b, resolveOutputAddrInstructions = __rest(_b, ["address"]); | ||
const { inputPoolToken, outputPoolToken } = public_1.getTokens(this.poolParams, inputToken.mint.toString()); | ||
const amountInU64 = public_1.U64Utils.toTokenU64(amountIn, inputPoolToken, "amountIn"); | ||
const minimumAmountOutU64 = public_1.U64Utils.toTokenU64(minimumAmountOut, outputPoolToken, "minimumAmountOut"); | ||
const _a = yield public_1.resolveAssociatedTokenAddress(this.connection, owner.publicKey, inputPoolToken.mint, amountInU64), { address: inputPoolTokenUserAddress } = _a, resolveInputAddrInstructions = __rest(_a, ["address"]); | ||
const _b = yield public_1.resolveAssociatedTokenAddress(this.connection, owner.publicKey, outputPoolToken.mint, amountInU64), { address: outputPoolTokenUserAddress } = _b, resolveOutputAddrInstructions = __rest(_b, ["address"]); | ||
if (inputPoolTokenUserAddress === undefined || outputPoolTokenUserAddress === undefined) { | ||
@@ -109,3 +100,3 @@ throw new Error("Unable to derive input / output token associated address."); | ||
const swapInstruction = yield pool_instructions_1.createSwapInstruction(this.poolParams, owner, inputPoolToken, inputPoolTokenUserAddress, outputPoolToken, outputPoolTokenUserAddress, amountInU64, minimumAmountOutU64, userTransferAuthority.publicKey); | ||
const { transaction, signers } = yield new transaction_builder_1.default(this.connection, ownerAddress) | ||
const { transaction, signers } = yield new public_1.TransactionBuilder(this.connection, ownerAddress) | ||
.addInstruction(resolveInputAddrInstructions) | ||
@@ -116,3 +107,3 @@ .addInstruction(resolveOutputAddrInstructions) | ||
.build(); | ||
return yield transactions_1.sendAndConfirmTransaction(this.connection, transaction, signers); | ||
return yield web3_js_1.sendAndConfirmTransaction(this.connection, transaction, signers); | ||
}); | ||
@@ -119,0 +110,0 @@ } |
import { PublicKey } from "@solana/web3.js"; | ||
import { OrcaToken } from "../../../public/types"; | ||
import { Percentage } from "../../utils/percentage"; | ||
import { OrcaToken } from "../../.."; | ||
import { Percentage } from "../../../public"; | ||
/** | ||
@@ -5,0 +5,0 @@ * An Orca token-swap pool |
@@ -5,3 +5,3 @@ import { u64 } from "@solana/spl-token"; | ||
export declare class ConstantProductPoolQuoteBuilder { | ||
buildQuote(params: QuotePoolParams, inputTradeAmount: u64): Promise<Quote>; | ||
buildQuote(params: QuotePoolParams, inputTradeAmount: u64): Quote; | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
@@ -14,5 +8,4 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
const spl_token_1 = require("@solana/spl-token"); | ||
const __1 = require("../.."); | ||
const decimal_utils_1 = require("../../utils/decimal-utils"); | ||
const u64_utils_1 = require("../../utils/u64-utils"); | ||
const decimal_js_1 = __importDefault(require("decimal.js")); | ||
const public_1 = require("../../public"); | ||
/** | ||
@@ -27,14 +20,20 @@ * ConstantProductPools | ||
function getRate(inputTradeAmountU64, params) { | ||
if (inputTradeAmountU64.eq(public_1.ZERO)) { | ||
return new decimal_js_1.default(0); | ||
} | ||
const expectedOutputAmountU64 = getExpectedOutputAmount(inputTradeAmountU64, params); | ||
const inputTradeAmount = decimal_utils_1.DecimalUtil.fromU64(inputTradeAmountU64, params.inputToken.scale); | ||
const outputTradeAmount = decimal_utils_1.DecimalUtil.fromU64(expectedOutputAmountU64, params.outputToken.scale); | ||
return outputTradeAmount.div(inputTradeAmount); | ||
const inputTradeAmount = public_1.DecimalUtil.fromU64(inputTradeAmountU64, params.inputToken.scale); | ||
const outputTradeAmount = public_1.DecimalUtil.fromU64(expectedOutputAmountU64, params.outputToken.scale); | ||
return outputTradeAmount.div(inputTradeAmount).toDecimalPlaces(params.outputToken.scale); | ||
} | ||
function getPriceImpact(inputTradeAmount, params) { | ||
if (inputTradeAmount.eq(public_1.ZERO) || params.outputTokenCount.eq(public_1.ZERO)) { | ||
return new decimal_js_1.default(0); | ||
} | ||
const noSlippageOutputCountU64 = getExpectedOutputAmountWithNoSlippage(inputTradeAmount, params); | ||
const outputCountU64 = getExpectedOutputAmount(inputTradeAmount, params); | ||
const noSlippageOutputCount = decimal_utils_1.DecimalUtil.fromU64(noSlippageOutputCountU64, params.outputToken.scale); | ||
const outputCount = decimal_utils_1.DecimalUtil.fromU64(outputCountU64, params.outputToken.scale); | ||
const noSlippageOutputCount = public_1.DecimalUtil.fromU64(noSlippageOutputCountU64, params.outputToken.scale); | ||
const outputCount = public_1.DecimalUtil.fromU64(outputCountU64, params.outputToken.scale); | ||
const impact = noSlippageOutputCount.sub(outputCount).div(noSlippageOutputCount); | ||
return impact.mul(100); | ||
return impact.mul(100).toDecimalPlaces(params.outputToken.scale); | ||
} | ||
@@ -56,2 +55,5 @@ function getFees(inputTradeAmount, params) { | ||
function getExpectedOutputAmountWithNoSlippage(inputTradeAmount, params) { | ||
if (params.inputTokenCount.eq(public_1.ZERO)) { | ||
return params.outputTokenCount; | ||
} | ||
const inputTradeLessFees = inputTradeAmount.sub(getFees(inputTradeAmount, params)); | ||
@@ -74,3 +76,3 @@ return inputTradeLessFees.mul(params.outputTokenCount).div(params.inputTokenCount); | ||
const invariant = poolInputAmount.mul(poolOutputAmount); | ||
const [newPoolOutputAmount] = u64_utils_1.U64Utils.ceilingDivision(invariant, poolInputAmount.add(inputTradeAmount)); | ||
const [newPoolOutputAmount] = public_1.U64Utils.ceilingDivision(invariant, poolInputAmount.add(inputTradeAmount)); | ||
const outputAmount = poolOutputAmount.sub(newPoolOutputAmount); | ||
@@ -81,13 +83,11 @@ return new spl_token_1.u64(outputAmount.toString()); | ||
buildQuote(params, inputTradeAmount) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return { | ||
getRate: () => getRate(inputTradeAmount, params), | ||
getPriceImpact: () => getPriceImpact(inputTradeAmount, params), | ||
getFees: () => __1.OrcaU64.fromU64(getFees(inputTradeAmount, params), params.inputToken.scale), | ||
getExpectedOutputAmount: () => __1.OrcaU64.fromU64(getExpectedOutputAmount(inputTradeAmount, params), params.outputToken.scale), | ||
getMinOutputAmount: () => __1.OrcaU64.fromU64(getMinimumAmountOut(inputTradeAmount, params), params.outputToken.scale), | ||
}; | ||
}); | ||
return { | ||
getRate: () => getRate(inputTradeAmount, params), | ||
getPriceImpact: () => getPriceImpact(inputTradeAmount, params), | ||
getFees: () => public_1.OrcaU64.fromU64(getFees(inputTradeAmount, params), params.inputToken.scale), | ||
getExpectedOutputAmount: () => public_1.OrcaU64.fromU64(getExpectedOutputAmount(inputTradeAmount, params), params.outputToken.scale), | ||
getMinOutputAmount: () => public_1.OrcaU64.fromU64(getMinimumAmountOut(inputTradeAmount, params), params.outputToken.scale), | ||
}; | ||
} | ||
} | ||
exports.ConstantProductPoolQuoteBuilder = ConstantProductPoolQuoteBuilder; |
import { u64 } from "@solana/spl-token"; | ||
import { OrcaToken, Quote } from "../../public/types"; | ||
import { PoolTokenCount } from "../../utils/web3/get-token-count"; | ||
import { CurveType, FeeStructure } from "../orca/pool/pool-types"; | ||
import { Percentage } from "../utils/percentage"; | ||
import { OrcaToken, Quote } from "../.."; | ||
import { PoolTokenCount, Percentage } from "../../public"; | ||
import { FeeStructure, CurveType } from "../orca/pool/pool-types"; | ||
export declare type QuotePoolParams = PoolTokenCount & { | ||
@@ -13,3 +12,3 @@ inputToken: OrcaToken; | ||
export interface QuoteBuilder { | ||
buildQuote(pool: QuotePoolParams, inputAmount: u64): Promise<Quote>; | ||
buildQuote(pool: QuotePoolParams, inputAmount: u64): Quote; | ||
} | ||
@@ -16,0 +15,0 @@ export declare class QuoteBuilderFactory { |
{ | ||
"name": "@orca-so/sdk", | ||
"version": "1.0.1", | ||
"version": "1.0.2-beta.1", | ||
"description": "Typescript SDK for the Orca protocol.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
96662
77
1398
1
1