@orca-so/sdk
Advanced tools
Comparing version 1.0.3 to 1.0.4
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultSlippagePercentage = void 0; | ||
const spl_token_1 = require("@solana/spl-token"); | ||
exports.defaultSlippagePercentage = { | ||
numerator: new spl_token_1.u64(1), | ||
denominator: new spl_token_1.u64(1000), | ||
}; // 0.1% | ||
const percentage_1 = require("../public/utils/models/percentage"); | ||
exports.defaultSlippagePercentage = percentage_1.Percentage.fromFraction(1, 1000); // 0.1% |
@@ -7,3 +7,3 @@ "use strict"; | ||
const config_1 = require("../public/pools/config"); | ||
const percentage_utils_1 = require("../public/utils/percentage-utils"); | ||
const percentage_1 = require("../public/utils/models/percentage"); | ||
/** | ||
@@ -57,4 +57,4 @@ * Constants | ||
feeStructure: { | ||
traderFee: percentage_utils_1.PercentageUtils.fromFraction(2, 1000), | ||
ownerFee: percentage_utils_1.PercentageUtils.fromFraction(1, 1000), | ||
traderFee: percentage_1.Percentage.fromFraction(2, 1000), | ||
ownerFee: percentage_1.Percentage.fromFraction(1, 1000), | ||
}, | ||
@@ -76,4 +76,4 @@ }); | ||
feeStructure: { | ||
traderFee: percentage_utils_1.PercentageUtils.fromFraction(2, 1000), | ||
ownerFee: percentage_utils_1.PercentageUtils.fromFraction(1, 1000), | ||
traderFee: percentage_1.Percentage.fromFraction(2, 1000), | ||
ownerFee: percentage_1.Percentage.fromFraction(1, 1000), | ||
}, | ||
@@ -95,4 +95,4 @@ }); | ||
feeStructure: { | ||
traderFee: percentage_utils_1.PercentageUtils.fromFraction(2, 1000), | ||
ownerFee: percentage_utils_1.PercentageUtils.fromFraction(1, 1000), | ||
traderFee: percentage_1.Percentage.fromFraction(2, 1000), | ||
ownerFee: percentage_1.Percentage.fromFraction(1, 1000), | ||
}, | ||
@@ -114,4 +114,4 @@ }); | ||
feeStructure: { | ||
traderFee: percentage_utils_1.PercentageUtils.fromFraction(2, 1000), | ||
ownerFee: percentage_utils_1.PercentageUtils.fromFraction(1, 1000), | ||
traderFee: percentage_1.Percentage.fromFraction(2, 1000), | ||
ownerFee: percentage_1.Percentage.fromFraction(1, 1000), | ||
}, | ||
@@ -133,4 +133,4 @@ }); | ||
feeStructure: { | ||
traderFee: percentage_utils_1.PercentageUtils.fromFraction(2, 1000), | ||
ownerFee: percentage_utils_1.PercentageUtils.fromFraction(1, 1000), | ||
traderFee: percentage_1.Percentage.fromFraction(2, 1000), | ||
ownerFee: percentage_1.Percentage.fromFraction(1, 1000), | ||
}, | ||
@@ -137,0 +137,0 @@ }); |
@@ -26,3 +26,2 @@ "use strict"; | ||
const orca_defaults_1 = require("../../../constants/orca-defaults"); | ||
const percentage_utils_1 = require("../../../public/utils/percentage-utils"); | ||
const public_1 = require("../../../public"); | ||
@@ -68,3 +67,3 @@ const pool_instructions_1 = require("../../../public/utils/web3/instructions/pool-instructions"); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const slippageTolerance = slippage === undefined ? orca_defaults_1.defaultSlippagePercentage : percentage_utils_1.PercentageUtils.fromDecimal(slippage); | ||
const slippageTolerance = slippage === undefined ? orca_defaults_1.defaultSlippagePercentage : public_1.Percentage.fromDecimal(slippage); | ||
const feeStructure = this.poolParams.feeStructure; | ||
@@ -71,0 +70,0 @@ const { inputPoolToken, outputPoolToken } = public_1.getTokens(this.poolParams, inputToken.mint.toString()); |
@@ -7,2 +7,1 @@ export * from "./constants"; | ||
export * from "./web3"; | ||
export * from "./percentage-utils"; |
@@ -19,2 +19,1 @@ "use strict"; | ||
__exportStar(require("./web3"), exports); | ||
__exportStar(require("./percentage-utils"), exports); |
import { u64 } from "@solana/spl-token"; | ||
export declare type Percentage = { | ||
numerator: u64; | ||
denominator: u64; | ||
}; | ||
import Decimal from "decimal.js"; | ||
export declare class Percentage { | ||
readonly numerator: u64; | ||
readonly denominator: u64; | ||
constructor(numerator: u64, denominator: u64); | ||
static fromDecimal(number: Decimal): Percentage; | ||
static fromFraction(numerator: u64 | number, denominator: u64 | number): Percentage; | ||
toString: () => string; | ||
toDecimal(): Decimal; | ||
add(p2: Percentage): Percentage; | ||
} |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Percentage = void 0; | ||
const spl_token_1 = require("@solana/spl-token"); | ||
const decimal_js_1 = __importDefault(require("decimal.js")); | ||
const __1 = require(".."); | ||
class Percentage { | ||
constructor(numerator, denominator) { | ||
this.toString = () => { | ||
return `${this.numerator.toString()}/${this.denominator.toString()}`; | ||
}; | ||
this.numerator = numerator; | ||
this.denominator = denominator; | ||
} | ||
static fromDecimal(number) { | ||
return Percentage.fromFraction(number.toDecimalPlaces(1).mul(10).toNumber(), 1000); | ||
} | ||
static fromFraction(numerator, denominator) { | ||
const num = typeof numerator === "number" ? new spl_token_1.u64(numerator.toString()) : numerator; | ||
const denom = typeof denominator === "number" ? new spl_token_1.u64(denominator.toString()) : denominator; | ||
return new Percentage(num, denom); | ||
} | ||
toDecimal() { | ||
if (this.denominator.eq(__1.ZERO)) { | ||
return new decimal_js_1.default(0); | ||
} | ||
return new decimal_js_1.default(this.numerator.toString()).div(new decimal_js_1.default(this.denominator.toString())); | ||
} | ||
add(p2) { | ||
const denomGcd = this.denominator.gcd(p2.denominator); | ||
const denomLcm = this.denominator.div(denomGcd).mul(p2.denominator); | ||
const p1DenomAdjustment = denomLcm.div(this.denominator); | ||
const p2DenomAdjustment = denomLcm.div(p2.denominator); | ||
const p1NumeratorAdjusted = this.numerator.mul(p1DenomAdjustment); | ||
const p2NumeratorAdjusted = p2.numerator.mul(p2DenomAdjustment); | ||
const newNumerator = p1NumeratorAdjusted.add(p2NumeratorAdjusted); | ||
return new Percentage(new spl_token_1.u64(newNumerator.toString()), new spl_token_1.u64(denomLcm.toString())); | ||
} | ||
} | ||
exports.Percentage = Percentage; |
{ | ||
"name": "@orca-so/sdk", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Typescript SDK for the Orca protocol.", | ||
@@ -10,3 +10,3 @@ "main": "dist/index.js", | ||
"@solana/spl-token": "^0.1.5", | ||
"@solana/spl-token-swap": "0.1.0", | ||
"@solana/spl-token-swap": "^0.1.2", | ||
"@solana/web3.js": "^1.17.0", | ||
@@ -13,0 +13,0 @@ "decimal.js": "^10.3.1" |
@@ -61,3 +61,3 @@ # Orca Typescript SDK | ||
// Perform a swap for 1USDC to the quoted minimum amount of ETH | ||
const txId = await pool.swap(owner, usdcToken, tradeValue, quote.getMinOutputAmount()); | ||
const txId = await pool.swap(owner, usdcToken, tradeValue, quote.getMinOutputAmount()).execute(); | ||
} catch (err) { | ||
@@ -71,7 +71,13 @@ // Handle errors | ||
**Decimals & OrcaU64** | ||
The SDK relies on the use of [Decimal](https://github.com/MikeMcl/decimal.js/) for number inputs and Decimal/[OrcaU64](https://github.com/orca-so/typescript-sdk/blob/main/src/public/utils/orca-u64.ts) 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. | ||
**Funding Associated Token Addresses** | ||
The swap() function assumes the owner keypair address has already created & initialized the [associated token addresses](https://spl.solana.com/associated-token-account) for the trading pair tokens. The swap will fail if this is not the case. | ||
**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 | ||
@@ -78,0 +84,0 @@ |
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
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
102651
1465
98
+ Added@solana/spl-token-swap@0.1.4(transitive)
- Removed@solana/spl-token-swap@0.1.0(transitive)
- Removed@solana/web3.js@0.90.5(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedany-promise@1.3.0(transitive)
- Removedarray-buffer-byte-length@1.0.1(transitive)
- Removedarraybuffer.prototype.slice@1.0.3(transitive)
- Removedavailable-typed-arrays@1.0.7(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbn.js@4.12.1(transitive)
- Removedboolbase@1.0.0(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedbrorand@1.1.0(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcheerio@0.22.0(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedcross-spawn@6.0.6(transitive)
- Removedcrypto-hash@1.3.0(transitive)
- Removedcss-select@1.2.0(transitive)
- Removedcss-what@2.1.3(transitive)
- Removeddata-view-buffer@1.0.1(transitive)
- Removeddata-view-byte-length@1.0.1(transitive)
- Removeddata-view-byte-offset@1.0.0(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddefine-properties@1.2.1(transitive)
- Removeddom-serializer@0.1.1(transitive)
- Removeddomelementtype@1.3.1(transitive)
- Removeddomhandler@2.4.2(transitive)
- Removeddomutils@1.5.1(transitive)
- Removeddotenv@8.2.0(transitive)
- Removedelliptic@6.6.1(transitive)
- Removedentities@1.1.2(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedes-abstract@1.23.5(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.0.0(transitive)
- Removedes-set-tostringtag@2.0.3(transitive)
- Removedes-to-primitive@1.2.1(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedesdoc-inject-style-plugin@1.0.0(transitive)
- Removedeventemitter3@4.0.7(transitive)
- Removedfor-each@0.3.3(transitive)
- Removedfs-extra@1.0.0(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedfunction.prototype.name@1.1.6(transitive)
- Removedfunctions-have-names@1.2.3(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedget-symbol-description@1.0.2(transitive)
- Removedglobalthis@1.0.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhas-bigints@1.0.2(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhas-tostringtag@1.0.2(transitive)
- Removedhash.js@1.1.7(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhmac-drbg@1.0.1(transitive)
- Removedhosted-git-info@2.8.9(transitive)
- Removedhtmlparser2@3.10.1(transitive)
- Removedinherits@2.0.4(transitive)
- Removedinternal-slot@1.0.7(transitive)
- Removedis-array-buffer@3.0.4(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-bigint@1.0.4(transitive)
- Removedis-boolean-object@1.1.2(transitive)
- Removedis-callable@1.2.7(transitive)
- Removedis-core-module@2.15.1(transitive)
- Removedis-data-view@1.0.1(transitive)
- Removedis-date-object@1.0.5(transitive)
- Removedis-negative-zero@2.0.3(transitive)
- Removedis-number-object@1.0.7(transitive)
- Removedis-regex@1.1.4(transitive)
- Removedis-shared-array-buffer@1.0.3(transitive)
- Removedis-string@1.0.7(transitive)
- Removedis-symbol@1.0.4(transitive)
- Removedis-typed-array@1.1.13(transitive)
- Removedis-weakref@1.0.2(transitive)
- Removedisarray@2.0.5(transitive)
- Removedisexe@2.0.0(transitive)
- Removedjayson@3.7.0(transitive)
- Removedjson-parse-better-errors@1.0.2(transitive)
- Removedjson-to-pretty-yaml@1.2.2(transitive)
- Removedjsonfile@2.4.0(transitive)
- Removedkeccak@3.0.4(transitive)
- Removedkind-of@6.0.3(transitive)
- Removedklaw@1.3.1(transitive)
- Removedload-json-file@4.0.0(transitive)
- Removedlodash@4.17.21(transitive)
- Removedlodash.assignin@4.2.0(transitive)
- Removedlodash.bind@4.2.1(transitive)
- Removedlodash.defaults@4.2.0(transitive)
- Removedlodash.filter@4.6.0(transitive)
- Removedlodash.flatten@4.4.0(transitive)
- Removedlodash.foreach@4.5.0(transitive)
- Removedlodash.map@4.6.0(transitive)
- Removedlodash.merge@4.6.2(transitive)
- Removedlodash.pick@4.4.0(transitive)
- Removedlodash.reduce@4.6.0(transitive)
- Removedlodash.reject@4.6.0(transitive)
- Removedlodash.some@4.6.0(transitive)
- Removedmemorystream@0.3.1(transitive)
- Removedminimalistic-assert@1.0.1(transitive)
- Removedminimalistic-crypto-utils@1.0.1(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedmkdirp@1.0.4(transitive)
- Removedmz@2.7.0(transitive)
- Removednice-try@1.0.5(transitive)
- Removednode-addon-api@2.0.25.1.0(transitive)
- Removednormalize-package-data@2.5.0(transitive)
- Removednpm-run-all@4.1.5(transitive)
- Removednth-check@1.0.2(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedobject-inspect@1.13.3(transitive)
- Removedobject-keys@1.1.1(transitive)
- Removedobject.assign@4.1.5(transitive)
- Removedparse-json@4.0.0(transitive)
- Removedpath-key@2.0.1(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedpath-type@3.0.0(transitive)
- Removedpidtree@0.3.1(transitive)
- Removedpify@3.0.0(transitive)
- Removedpossible-typed-array-names@1.0.0(transitive)
- Removedread-pkg@3.0.0(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedregexp.prototype.flags@1.5.3(transitive)
- Removedremedial@1.0.8(transitive)
- Removedremove-trailing-spaces@1.0.8(transitive)
- Removedresolve@1.22.8(transitive)
- Removedrpc-websockets@7.11.2(transitive)
- Removedsafe-array-concat@1.1.2(transitive)
- Removedsafe-regex-test@1.0.3(transitive)
- Removedsecp256k1@4.0.4(transitive)
- Removedsemver@5.7.2(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedset-function-name@2.0.2(transitive)
- Removedshebang-command@1.2.0(transitive)
- Removedshebang-regex@1.0.0(transitive)
- Removedshell-quote@1.8.1(transitive)
- Removedside-channel@1.0.6(transitive)
- Removedspdx-correct@3.2.0(transitive)
- Removedspdx-exceptions@2.5.0(transitive)
- Removedspdx-expression-parse@3.0.1(transitive)
- Removedspdx-license-ids@3.0.20(transitive)
- Removedstring.prototype.padend@3.1.6(transitive)
- Removedstring.prototype.trim@1.2.9(transitive)
- Removedstring.prototype.trimend@1.0.8(transitive)
- Removedstring.prototype.trimstart@1.0.8(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedstrip-bom@3.0.0(transitive)
- Removedsuperstruct@0.8.4(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedthenify@3.3.1(transitive)
- Removedthenify-all@1.6.0(transitive)
- Removedtiny-invariant@1.3.3(transitive)
- Removedtweetnacl@1.0.3(transitive)
- Removedtyped-array-buffer@1.0.2(transitive)
- Removedtyped-array-byte-length@1.0.1(transitive)
- Removedtyped-array-byte-offset@1.0.2(transitive)
- Removedtyped-array-length@1.0.6(transitive)
- Removedunbox-primitive@1.0.2(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedvalidate-npm-package-license@3.0.4(transitive)
- Removedwhich@1.3.1(transitive)
- Removedwhich-boxed-primitive@1.0.2(transitive)
- Removedwhich-typed-array@1.1.15(transitive)