@saberhq/stableswap-sdk
Advanced tools
Comparing version 1.0.0-alpha.33 to 1.0.0
@@ -1,3 +0,2 @@ | ||
import { Token, TokenAmount } from "@saberhq/spl-token"; | ||
import { Fraction } from "@ubeswap/token-math"; | ||
import { Fraction, Token, TokenAmount } from "@saberhq/spl-token"; | ||
import JSBI from "jsbi"; | ||
@@ -4,0 +3,0 @@ import { IExchangeInfo } from "../entities/exchange"; |
@@ -8,3 +8,2 @@ "use strict"; | ||
const spl_token_1 = require("@saberhq/spl-token"); | ||
const token_math_1 = require("@ubeswap/token-math"); | ||
const jsbi_1 = __importDefault(require("jsbi")); | ||
@@ -24,3 +23,3 @@ const lodash_1 = require("lodash"); | ||
} | ||
const price = new token_math_1.Fraction(curve_1.computeD(exchange.ampFactor, exchange.reserves[0].amount.raw, exchange.reserves[1].amount.raw), amount.raw); | ||
const price = new spl_token_1.Fraction(curve_1.computeD(exchange.ampFactor, exchange.reserves[0].amount.raw, exchange.reserves[1].amount.raw), amount.raw); | ||
return price; | ||
@@ -99,9 +98,9 @@ }; | ||
// new_base_amount = swap_base_amount - expected_base_amount * fee / fee_denominator; | ||
const new_base_amount = new token_math_1.Fraction(baseReserves.toString(), 1).subtract(exports.normalizedTradeFee(fees, N_COINS, expected_base_amount)); | ||
const new_base_amount = new spl_token_1.Fraction(baseReserves.toString(), 1).subtract(exports.normalizedTradeFee(fees, N_COINS, expected_base_amount)); | ||
// new_quote_amount = swap_quote_amount - expected_quote_amount * fee / fee_denominator; | ||
const new_quote_amount = new token_math_1.Fraction(quoteReserves.toString(), 1).subtract(exports.normalizedTradeFee(fees, N_COINS, expected_quote_amount)); | ||
const new_quote_amount = new spl_token_1.Fraction(quoteReserves.toString(), 1).subtract(exports.normalizedTradeFee(fees, N_COINS, expected_quote_amount)); | ||
const dy = new_base_amount.subtract(curve_1.computeY(ampFactor, jsbi_1.default.BigInt(new_quote_amount.toFixed(0)), d_1).toString()); | ||
const dy_0 = jsbi_1.default.subtract(baseReserves, new_y); | ||
// lp fees | ||
const swapFee = new token_math_1.Fraction(dy_0.toString(), 1).subtract(dy); | ||
const swapFee = new spl_token_1.Fraction(dy_0.toString(), 1).subtract(dy); | ||
const withdrawFee = dy.multiply(fees.withdraw.asFraction); | ||
@@ -134,4 +133,4 @@ // admin fees | ||
const normalizedTradeFee = ({ trade }, n_coins, amount) => { | ||
const adjustedTradeFee = new token_math_1.Fraction(n_coins, jsbi_1.default.multiply(jsbi_1.default.subtract(n_coins, spl_token_1.ONE), jsbi_1.default.BigInt(4))); | ||
return new token_math_1.Fraction(amount, 1).multiply(trade).multiply(adjustedTradeFee); | ||
const adjustedTradeFee = new spl_token_1.Fraction(n_coins, jsbi_1.default.multiply(jsbi_1.default.subtract(n_coins, spl_token_1.ONE), jsbi_1.default.BigInt(4))); | ||
return new spl_token_1.Fraction(amount, 1).multiply(trade).multiply(adjustedTradeFee); | ||
}; | ||
@@ -197,3 +196,3 @@ exports.normalizedTradeFee = normalizedTradeFee; | ||
const oldBalance = oldBalances[i]; | ||
const idealBalance = new token_math_1.Fraction(d1, d0).multiply(oldBalance); | ||
const idealBalance = new spl_token_1.Fraction(d1, d0).multiply(oldBalance); | ||
const difference = idealBalance.subtract(newBalance); | ||
@@ -200,0 +199,0 @@ const diffAbs = difference.greaterThan(0) |
@@ -1,4 +0,4 @@ | ||
import { Percent } from "@ubeswap/token-math"; | ||
import { Percent } from "@saberhq/spl-token"; | ||
import JSBI from "jsbi"; | ||
export declare const calculateTokenAmountAfterSlippage: (slippagePercentage: Percent, tokenAmount?: JSBI) => JSBI; | ||
//# sourceMappingURL=slippage.d.ts.map |
@@ -8,7 +8,7 @@ "use strict"; | ||
const spl_token_1 = require("@saberhq/spl-token"); | ||
const token_math_1 = require("@ubeswap/token-math"); | ||
const spl_token_2 = require("@saberhq/spl-token"); | ||
const jsbi_1 = __importDefault(require("jsbi")); | ||
const format_1 = require("../util/format"); | ||
const MIN_SLIPPAGE_PERCENTAGE = new token_math_1.Percent(0, 1); | ||
const MAX_SLIPPAGE_PERCENTAGE = new token_math_1.Percent(1, 1); | ||
const MIN_SLIPPAGE_PERCENTAGE = new spl_token_2.Percent(0, 1); | ||
const MAX_SLIPPAGE_PERCENTAGE = new spl_token_2.Percent(1, 1); | ||
const calculateTokenAmountAfterSlippage = (slippagePercentage, tokenAmount = spl_token_1.ZERO) => { | ||
@@ -22,4 +22,4 @@ if (slippagePercentage.lessThan(MIN_SLIPPAGE_PERCENTAGE) || | ||
} | ||
return jsbi_1.default.BigInt(new token_math_1.Fraction(tokenAmount, 1) | ||
.subtract(new token_math_1.Fraction(tokenAmount, 1).multiply(slippagePercentage)) | ||
return jsbi_1.default.BigInt(new spl_token_2.Fraction(tokenAmount, 1) | ||
.subtract(new spl_token_2.Fraction(tokenAmount, 1).multiply(slippagePercentage)) | ||
.toFixed(0)); | ||
@@ -26,0 +26,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
import { Percent } from "@ubeswap/token-math"; | ||
import { Percent } from "@saberhq/spl-token"; | ||
import { RawFees } from "./layout"; | ||
@@ -3,0 +3,0 @@ export declare type Fees = { |
@@ -5,4 +5,4 @@ "use strict"; | ||
const spl_token_1 = require("@solana/spl-token"); | ||
const token_math_1 = require("@ubeswap/token-math"); | ||
exports.DEFAULT_FEE = new token_math_1.Percent(0, 10000); | ||
const spl_token_2 = require("@saberhq/spl-token"); | ||
exports.DEFAULT_FEE = new spl_token_2.Percent(0, 10000); | ||
exports.ZERO_FEES = { | ||
@@ -28,6 +28,6 @@ /** | ||
exports.RECOMMENDED_FEES = { | ||
trade: new token_math_1.Percent(recommendedFeesRaw.tradeFeeNumerator, recommendedFeesRaw.tradeFeeDenominator), | ||
withdraw: new token_math_1.Percent(recommendedFeesRaw.withdrawFeeNumerator, recommendedFeesRaw.withdrawFeeDenominator), | ||
adminTrade: new token_math_1.Percent(recommendedFeesRaw.adminTradeFeeNumerator, recommendedFeesRaw.adminTradeFeeDenominator), | ||
adminWithdraw: new token_math_1.Percent(recommendedFeesRaw.adminWithdrawFeeNumerator, recommendedFeesRaw.adminWithdrawFeeDenominator), | ||
trade: new spl_token_2.Percent(recommendedFeesRaw.tradeFeeNumerator, recommendedFeesRaw.tradeFeeDenominator), | ||
withdraw: new spl_token_2.Percent(recommendedFeesRaw.withdrawFeeNumerator, recommendedFeesRaw.withdrawFeeDenominator), | ||
adminTrade: new spl_token_2.Percent(recommendedFeesRaw.adminTradeFeeNumerator, recommendedFeesRaw.adminTradeFeeDenominator), | ||
adminWithdraw: new spl_token_2.Percent(recommendedFeesRaw.adminWithdrawFeeNumerator, recommendedFeesRaw.adminWithdrawFeeDenominator), | ||
}; | ||
@@ -46,8 +46,8 @@ const encodeFees = (fees) => ({ | ||
const decodeFees = (raw) => ({ | ||
adminTrade: new token_math_1.Percent(spl_token_1.u64.fromBuffer(raw.adminTradeFeeNumerator).toString(), spl_token_1.u64.fromBuffer(raw.adminTradeFeeDenominator).toString()), | ||
adminWithdraw: new token_math_1.Percent(spl_token_1.u64.fromBuffer(raw.adminWithdrawFeeNumerator).toString(), spl_token_1.u64.fromBuffer(raw.adminWithdrawFeeDenominator).toString()), | ||
trade: new token_math_1.Percent(spl_token_1.u64.fromBuffer(raw.tradeFeeNumerator).toString(), spl_token_1.u64.fromBuffer(raw.tradeFeeDenominator).toString()), | ||
withdraw: new token_math_1.Percent(spl_token_1.u64.fromBuffer(raw.withdrawFeeNumerator).toString(), spl_token_1.u64.fromBuffer(raw.withdrawFeeDenominator).toString()), | ||
adminTrade: new spl_token_2.Percent(spl_token_1.u64.fromBuffer(raw.adminTradeFeeNumerator).toString(), spl_token_1.u64.fromBuffer(raw.adminTradeFeeDenominator).toString()), | ||
adminWithdraw: new spl_token_2.Percent(spl_token_1.u64.fromBuffer(raw.adminWithdrawFeeNumerator).toString(), spl_token_1.u64.fromBuffer(raw.adminWithdrawFeeDenominator).toString()), | ||
trade: new spl_token_2.Percent(spl_token_1.u64.fromBuffer(raw.tradeFeeNumerator).toString(), spl_token_1.u64.fromBuffer(raw.tradeFeeDenominator).toString()), | ||
withdraw: new spl_token_2.Percent(spl_token_1.u64.fromBuffer(raw.withdrawFeeNumerator).toString(), spl_token_1.u64.fromBuffer(raw.withdrawFeeDenominator).toString()), | ||
}); | ||
exports.decodeFees = decodeFees; | ||
//# sourceMappingURL=fees.js.map |
@@ -1,4 +0,4 @@ | ||
import { Percent } from "@ubeswap/token-math"; | ||
import { Percent } from "@saberhq/spl-token"; | ||
export declare const FORMAT_PERCENT: Intl.NumberFormatOptions; | ||
export declare const formatPercent: (percent: Percent) => string; | ||
//# sourceMappingURL=format.d.ts.map |
{ | ||
"name": "@saberhq/stableswap-sdk", | ||
"version": "1.0.0-alpha.33", | ||
"version": "1.0.0", | ||
"main": "lib/index.js", | ||
@@ -26,3 +26,3 @@ "types": "lib/index.d.ts", | ||
"@babel/preset-typescript": "^7.14.5", | ||
"@solana/spl-token": "^0.1.5", | ||
"@solana/spl-token": "^0.1.6", | ||
"@solana/web3.js": "^1.18.0", | ||
@@ -33,4 +33,4 @@ "@types/bs58": "^4.0.1", | ||
"@types/node": "^15.12.2", | ||
"@typescript-eslint/eslint-plugin": "^4.26.1", | ||
"@typescript-eslint/parser": "^4.26.1", | ||
"@typescript-eslint/eslint-plugin": "^4.27.0", | ||
"@typescript-eslint/parser": "^4.27.0", | ||
"b58": "^4.0.3", | ||
@@ -50,16 +50,15 @@ "eslint": "^7.28.0", | ||
"tslint": "^6.1.3", | ||
"typescript": "^4.3.2" | ||
"typescript": "^4.3.4" | ||
}, | ||
"dependencies": { | ||
"@saberhq/spl-token": "^0.1.1-beta.3", | ||
"@saberhq/spl-token": "^0.1.1-beta.7", | ||
"@types/bn.js": "^5.1.0", | ||
"@types/yargs": "^17.0.0", | ||
"@ubeswap/token-math": "^0.1.3", | ||
"bn.js": "^5.2.0", | ||
"buffer-layout": "^1.2.1", | ||
"jsbi": "^3.1.4", | ||
"jsbi": "^3.1.5", | ||
"yargs": "^17.0.1" | ||
}, | ||
"peerDependencies": { | ||
"@solana/spl-token": "^0.1.5", | ||
"@solana/spl-token": "^0.1.6", | ||
"@solana/web3.js": "^1.11.0" | ||
@@ -66,0 +65,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
9
1
298978
2895
- Removed@ubeswap/token-math@^0.1.3
- Removed@ubeswap/token-math@0.1.3(transitive)
- Removedbig.js@5.2.2(transitive)
Updatedjsbi@^3.1.5