@saberhq/stableswap-sdk
Advanced tools
Comparing version 0.14.2 to 0.14.3
@@ -19,5 +19,5 @@ import type { Token } from "@saberhq/token-utils"; | ||
export declare const calculateEstimatedSwapOutputAmount: (exchange: IExchangeInfo, fromAmount: TokenAmount) => { | ||
fee: TokenAmount; | ||
outputAmountBeforeFees: TokenAmount; | ||
outputAmount: TokenAmount; | ||
fee: TokenAmount; | ||
lpFee: TokenAmount; | ||
@@ -24,0 +24,0 @@ adminFee: TokenAmount; |
@@ -22,3 +22,3 @@ "use strict"; | ||
} | ||
const price = new token_utils_1.Fraction(curve_1.computeD(exchange.ampFactor, exchange.reserves[0].amount.raw, exchange.reserves[1].amount.raw), amount.raw); | ||
const price = new token_utils_1.Fraction((0, curve_1.computeD)(exchange.ampFactor, exchange.reserves[0].amount.raw, exchange.reserves[1].amount.raw), amount.raw); | ||
return price; | ||
@@ -48,3 +48,3 @@ }; | ||
const amp = exchange.ampFactor; | ||
const amountBeforeFees = jsbi_1.default.subtract(toReserves.amount.raw, curve_1.computeY(amp, jsbi_1.default.add(fromReserves.amount.raw, fromAmount.raw), curve_1.computeD(amp, fromReserves.amount.raw, toReserves.amount.raw))); | ||
const amountBeforeFees = jsbi_1.default.subtract(toReserves.amount.raw, (0, curve_1.computeY)(amp, jsbi_1.default.add(fromReserves.amount.raw, fromAmount.raw), (0, curve_1.computeD)(amp, fromReserves.amount.raw, toReserves.amount.raw))); | ||
const outputAmountBeforeFees = new token_utils_1.TokenAmount(toReserves.amount.token, amountBeforeFees); | ||
@@ -83,3 +83,3 @@ const fee = new token_utils_1.TokenAmount(toReserves.amount.token, exchange.fees.trade.asFraction.multiply(amountBeforeFees).toFixed(0)); | ||
}; | ||
return lodash_1.mapValues(quantities, (q) => new token_utils_1.TokenAmount(withdrawToken, q)); | ||
return (0, lodash_1.mapValues)(quantities, (q) => new token_utils_1.TokenAmount(withdrawToken, q)); | ||
} | ||
@@ -91,5 +91,5 @@ const { ampFactor, fees } = exchange; | ||
]; | ||
const d_0 = curve_1.computeD(ampFactor, baseReserves, quoteReserves); | ||
const d_0 = (0, curve_1.computeD)(ampFactor, baseReserves, quoteReserves); | ||
const d_1 = jsbi_1.default.subtract(d_0, jsbi_1.default.divide(jsbi_1.default.multiply(poolTokenAmount.raw, d_0), exchange.lpTotalSupply.raw)); | ||
const new_y = curve_1.computeY(ampFactor, quoteReserves, d_1); | ||
const new_y = (0, curve_1.computeY)(ampFactor, quoteReserves, d_1); | ||
// expected_base_amount = swap_base_amount * d_1 / d_0 - new_y; | ||
@@ -100,6 +100,6 @@ const expected_base_amount = jsbi_1.default.subtract(jsbi_1.default.divide(jsbi_1.default.multiply(baseReserves, d_1), d_0), new_y); | ||
// new_base_amount = swap_base_amount - expected_base_amount * fee / fee_denominator; | ||
const new_base_amount = new token_utils_1.Fraction(baseReserves.toString(), 1).subtract(exports.normalizedTradeFee(fees, N_COINS, expected_base_amount)); | ||
const new_base_amount = new token_utils_1.Fraction(baseReserves.toString(), 1).subtract((0, 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_utils_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 new_quote_amount = new token_utils_1.Fraction(quoteReserves.toString(), 1).subtract((0, exports.normalizedTradeFee)(fees, N_COINS, expected_quote_amount)); | ||
const dy = new_base_amount.subtract((0, 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); | ||
@@ -128,3 +128,3 @@ // lp fees | ||
}; | ||
return lodash_1.mapValues(quantities, (q) => new token_utils_1.TokenAmount(withdrawToken, q.toFixed(0))); | ||
return (0, lodash_1.mapValues)(quantities, (q) => new token_utils_1.TokenAmount(withdrawToken, q.toFixed(0))); | ||
}; | ||
@@ -186,4 +186,4 @@ exports.calculateEstimatedWithdrawOneAmount = calculateEstimatedWithdrawOneAmount; | ||
const [reserveA, reserveB] = exchange.reserves; | ||
const d0 = curve_1.computeD(amp, reserveA.amount.raw, reserveB.amount.raw); | ||
const d1 = curve_1.computeD(amp, jsbi_1.default.add(reserveA.amount.raw, depositAmountA), jsbi_1.default.add(reserveB.amount.raw, depositAmountB)); | ||
const d0 = (0, curve_1.computeD)(amp, reserveA.amount.raw, reserveB.amount.raw); | ||
const d1 = (0, curve_1.computeD)(amp, jsbi_1.default.add(reserveA.amount.raw, depositAmountA), jsbi_1.default.add(reserveB.amount.raw, depositAmountB)); | ||
if (jsbi_1.default.lessThan(d1, d0)) { | ||
@@ -204,6 +204,6 @@ throw new Error("New D cannot be less than previous D"); | ||
: difference.multiply(-1); | ||
const fee = exports.normalizedTradeFee(exchange.fees, N_COINS, jsbi_1.default.BigInt(diffAbs.toFixed(0))); | ||
const fee = (0, exports.normalizedTradeFee)(exchange.fees, N_COINS, jsbi_1.default.BigInt(diffAbs.toFixed(0))); | ||
return jsbi_1.default.subtract(newBalance, jsbi_1.default.BigInt(fee.toFixed(0))); | ||
}); | ||
const d2 = curve_1.computeD(amp, adjustedBalances[0], adjustedBalances[1]); | ||
const d2 = (0, curve_1.computeD)(amp, adjustedBalances[0], adjustedBalances[1]); | ||
const lpSupply = exchange.lpTotalSupply; | ||
@@ -210,0 +210,0 @@ const mintAmountRaw = jsbi_1.default.divide(jsbi_1.default.multiply(lpSupply.raw, jsbi_1.default.subtract(d2, d0)), d0); |
@@ -73,7 +73,7 @@ "use strict"; | ||
it("works", () => { | ||
const result = amounts_1.calculateVirtualPrice(exchangeInfo); | ||
const result = (0, amounts_1.calculateVirtualPrice)(exchangeInfo); | ||
expect(result === null || result === void 0 ? void 0 : result.toFixed(4)).toBe("1.0000"); | ||
}); | ||
it("is symmetric", () => { | ||
const result = amounts_1.calculateVirtualPrice(makeExchangeInfo({ | ||
const result = (0, amounts_1.calculateVirtualPrice)(makeExchangeInfo({ | ||
lpTotalSupply: jsbi_1.default.BigInt(200000000), | ||
@@ -84,3 +84,3 @@ tokenAAmount: jsbi_1.default.BigInt(10000000), | ||
expect(result === null || result === void 0 ? void 0 : result.toFixed(4)).toBe("0.9801"); | ||
const result2 = amounts_1.calculateVirtualPrice(makeExchangeInfo({ | ||
const result2 = (0, amounts_1.calculateVirtualPrice)(makeExchangeInfo({ | ||
lpTotalSupply: jsbi_1.default.BigInt(200000000), | ||
@@ -98,3 +98,3 @@ tokenAAmount: jsbi_1.default.BigInt(190000000), | ||
}); | ||
const result = amounts_1.calculateVirtualPrice(exchange); | ||
const result = (0, amounts_1.calculateVirtualPrice)(exchange); | ||
expect(result === null || result === void 0 ? void 0 : result.toFixed(4)).toBe("0.9801"); | ||
@@ -105,7 +105,7 @@ }); | ||
it("no fees", () => { | ||
const result = amounts_1.calculateEstimatedSwapOutputAmount(exchangeInfo, new token_utils_1.TokenAmount(exchange.tokens[0], jsbi_1.default.BigInt(10000000))); | ||
const result = (0, amounts_1.calculateEstimatedSwapOutputAmount)(exchangeInfo, new token_utils_1.TokenAmount(exchange.tokens[0], jsbi_1.default.BigInt(10000000))); | ||
assertTokenAmounts(result.outputAmount, result.outputAmountBeforeFees); | ||
}); | ||
it("fees are different", () => { | ||
const result = amounts_1.calculateEstimatedSwapOutputAmount(Object.assign(Object.assign({}, exchangeInfoWithFees), { fees: Object.assign(Object.assign({}, exchangeInfoWithFees.fees), { trade: new token_utils_1.Percent(50, 100) }) }), new token_utils_1.TokenAmount(exchange.tokens[0], jsbi_1.default.BigInt(100))); | ||
const result = (0, amounts_1.calculateEstimatedSwapOutputAmount)(Object.assign(Object.assign({}, exchangeInfoWithFees), { fees: Object.assign(Object.assign({}, exchangeInfoWithFees.fees), { trade: new token_utils_1.Percent(50, 100) }) }), new token_utils_1.TokenAmount(exchange.tokens[0], jsbi_1.default.BigInt(100))); | ||
// 50 percent fee | ||
@@ -118,7 +118,7 @@ assertTokenAmount(result.outputAmountBeforeFees, jsbi_1.default.BigInt(100)); | ||
it("no fees if equal liquidity provision", () => { | ||
const result = amounts_1.calculateEstimatedMintAmount(Object.assign(Object.assign({}, exchangeInfo), { fees: Object.assign(Object.assign({}, fees_1.ZERO_FEES), { trade: new token_utils_1.Percent(50, 100) }) }), jsbi_1.default.BigInt(100), jsbi_1.default.BigInt(100)); | ||
const result = (0, amounts_1.calculateEstimatedMintAmount)(Object.assign(Object.assign({}, exchangeInfo), { fees: Object.assign(Object.assign({}, fees_1.ZERO_FEES), { trade: new token_utils_1.Percent(50, 100) }) }), jsbi_1.default.BigInt(100), jsbi_1.default.BigInt(100)); | ||
assertTokenAmounts(result.mintAmount, result.mintAmountBeforeFees); | ||
}); | ||
it("fees if unequal liquidity provision", () => { | ||
const result = amounts_1.calculateEstimatedMintAmount(Object.assign(Object.assign({}, exchangeInfo), { fees: Object.assign(Object.assign({}, fees_1.ZERO_FEES), { trade: new token_utils_1.Percent(50, 100) }) }), jsbi_1.default.BigInt(100000), jsbi_1.default.BigInt(0)); | ||
const result = (0, amounts_1.calculateEstimatedMintAmount)(Object.assign(Object.assign({}, exchangeInfo), { fees: Object.assign(Object.assign({}, fees_1.ZERO_FEES), { trade: new token_utils_1.Percent(50, 100) }) }), jsbi_1.default.BigInt(100000), jsbi_1.default.BigInt(0)); | ||
assertTokenAmount(result.mintAmountBeforeFees, new bn_js_1.default(99999)); | ||
@@ -133,9 +133,9 @@ // 3/4 because only half of the swapped amount (100 tokens) should have fees on it (so 1/4) | ||
it("works", () => { | ||
amounts_1.calculateEstimatedWithdrawAmount(Object.assign(Object.assign({}, exchangeInfo), { poolTokenAmount: new token_utils_1.TokenAmount(exchange.lpToken, 100000) })); | ||
(0, amounts_1.calculateEstimatedWithdrawAmount)(Object.assign(Object.assign({}, exchangeInfo), { poolTokenAmount: new token_utils_1.TokenAmount(exchange.lpToken, 100000) })); | ||
}); | ||
it("works with fees", () => { | ||
amounts_1.calculateEstimatedWithdrawAmount(Object.assign(Object.assign({}, exchangeInfoWithFees), { poolTokenAmount: new token_utils_1.TokenAmount(exchange.lpToken, 100000) })); | ||
(0, amounts_1.calculateEstimatedWithdrawAmount)(Object.assign(Object.assign({}, exchangeInfoWithFees), { poolTokenAmount: new token_utils_1.TokenAmount(exchange.lpToken, 100000) })); | ||
}); | ||
it("works zero with fees", () => { | ||
amounts_1.calculateEstimatedWithdrawAmount(Object.assign(Object.assign({}, exchangeInfoWithFees), { poolTokenAmount: new token_utils_1.TokenAmount(exchange.lpToken, 0) })); | ||
(0, amounts_1.calculateEstimatedWithdrawAmount)(Object.assign(Object.assign({}, exchangeInfoWithFees), { poolTokenAmount: new token_utils_1.TokenAmount(exchange.lpToken, 0) })); | ||
}); | ||
@@ -145,3 +145,3 @@ }); | ||
it("works", () => { | ||
amounts_1.calculateEstimatedWithdrawOneAmount({ | ||
(0, amounts_1.calculateEstimatedWithdrawOneAmount)({ | ||
exchange: exchangeInfo, | ||
@@ -153,3 +153,3 @@ poolTokenAmount: new token_utils_1.TokenAmount(exchange.lpToken, 100000), | ||
it("works with fees", () => { | ||
const result = amounts_1.calculateEstimatedWithdrawOneAmount({ | ||
const result = (0, amounts_1.calculateEstimatedWithdrawOneAmount)({ | ||
exchange: exchangeInfoWithFees, | ||
@@ -159,3 +159,3 @@ poolTokenAmount: new token_utils_1.TokenAmount(exchange.lpToken, 100000), | ||
}); | ||
const resultMapped = lodash_mapvalues_1.default(result, (q) => q.raw.toString()); | ||
const resultMapped = (0, lodash_mapvalues_1.default)(result, (q) => q.raw.toString()); | ||
expect(resultMapped).toEqual({ | ||
@@ -173,3 +173,3 @@ withdrawAmount: "99301", | ||
it("works zero with fees", () => { | ||
const result = amounts_1.calculateEstimatedWithdrawOneAmount({ | ||
const result = (0, amounts_1.calculateEstimatedWithdrawOneAmount)({ | ||
exchange: exchangeInfoWithFees, | ||
@@ -179,3 +179,3 @@ poolTokenAmount: new token_utils_1.TokenAmount(exchange.lpToken, 0), | ||
}); | ||
const resultMapped = lodash_mapvalues_1.default(result, (q) => q.raw.toString()); | ||
const resultMapped = (0, lodash_mapvalues_1.default)(result, (q) => q.raw.toString()); | ||
expect(resultMapped).toEqual({ | ||
@@ -182,0 +182,0 @@ withdrawAmount: "0", |
@@ -13,18 +13,18 @@ "use strict"; | ||
it("computeD", () => { | ||
assertBN(curve_1.computeD(jsbi_1.default.BigInt(100), jsbi_1.default.BigInt(0), jsbi_1.default.BigInt(0)), jsbi_1.default.BigInt(0)); | ||
assertBN(curve_1.computeD(jsbi_1.default.BigInt(100), jsbi_1.default.BigInt(1000000000), jsbi_1.default.BigInt(1000000000)), jsbi_1.default.BigInt(2000000000)); | ||
assertBN(curve_1.computeD(jsbi_1.default.BigInt(73), jsbi_1.default.BigInt(92), jsbi_1.default.BigInt(81)), jsbi_1.default.BigInt(173)); | ||
assertBN(curve_1.computeD(jsbi_1.default.BigInt(11503), jsbi_1.default.BigInt(28338), jsbi_1.default.BigInt(78889)), jsbi_1.default.BigInt(107225)); | ||
assertBN(curve_1.computeD(jsbi_1.default.BigInt(8552), jsbi_1.default.BigInt(26), jsbi_1.default.BigInt(69321)), jsbi_1.default.BigInt(66920)); | ||
assertBN(curve_1.computeD(jsbi_1.default.BigInt(496), jsbi_1.default.BigInt(62), jsbi_1.default.BigInt(68567)), jsbi_1.default.BigInt(57447)); | ||
assertBN(curve_1.computeD(jsbi_1.default.BigInt("17653203515214796177"), jsbi_1.default.BigInt("13789683482691983066"), jsbi_1.default.BigInt("3964443602730479576")), jsbi_1.default.BigInt("17754127085422462641")); | ||
assertBN((0, curve_1.computeD)(jsbi_1.default.BigInt(100), jsbi_1.default.BigInt(0), jsbi_1.default.BigInt(0)), jsbi_1.default.BigInt(0)); | ||
assertBN((0, curve_1.computeD)(jsbi_1.default.BigInt(100), jsbi_1.default.BigInt(1000000000), jsbi_1.default.BigInt(1000000000)), jsbi_1.default.BigInt(2000000000)); | ||
assertBN((0, curve_1.computeD)(jsbi_1.default.BigInt(73), jsbi_1.default.BigInt(92), jsbi_1.default.BigInt(81)), jsbi_1.default.BigInt(173)); | ||
assertBN((0, curve_1.computeD)(jsbi_1.default.BigInt(11503), jsbi_1.default.BigInt(28338), jsbi_1.default.BigInt(78889)), jsbi_1.default.BigInt(107225)); | ||
assertBN((0, curve_1.computeD)(jsbi_1.default.BigInt(8552), jsbi_1.default.BigInt(26), jsbi_1.default.BigInt(69321)), jsbi_1.default.BigInt(66920)); | ||
assertBN((0, curve_1.computeD)(jsbi_1.default.BigInt(496), jsbi_1.default.BigInt(62), jsbi_1.default.BigInt(68567)), jsbi_1.default.BigInt(57447)); | ||
assertBN((0, curve_1.computeD)(jsbi_1.default.BigInt("17653203515214796177"), jsbi_1.default.BigInt("13789683482691983066"), jsbi_1.default.BigInt("3964443602730479576")), jsbi_1.default.BigInt("17754127085422462641")); | ||
}); | ||
it("computeY", () => { | ||
assertBN(curve_1.computeY(jsbi_1.default.BigInt(100), jsbi_1.default.BigInt(100), jsbi_1.default.BigInt(0)), jsbi_1.default.BigInt(0)); | ||
assertBN(curve_1.computeY(jsbi_1.default.BigInt(8), jsbi_1.default.BigInt(94), jsbi_1.default.BigInt(163)), jsbi_1.default.BigInt(69)); | ||
assertBN(curve_1.computeY(jsbi_1.default.BigInt(2137), jsbi_1.default.BigInt(905777403660), jsbi_1.default.BigInt(830914146046)), jsbi_1.default.BigInt(490376033)); | ||
assertBN(curve_1.computeY(jsbi_1.default.BigInt("17095344176474858097"), jsbi_1.default.BigInt(383), jsbi_1.default.BigInt("2276818911077272163")), jsbi_1.default.BigInt("2276917873767753112")); | ||
assertBN(curve_1.computeY(jsbi_1.default.BigInt("7644937799120520965"), jsbi_1.default.BigInt("14818904982296505121"), jsbi_1.default.BigInt("17480022366793075404")), jsbi_1.default.BigInt("2661117384496570284")); | ||
assertBN((0, curve_1.computeY)(jsbi_1.default.BigInt(100), jsbi_1.default.BigInt(100), jsbi_1.default.BigInt(0)), jsbi_1.default.BigInt(0)); | ||
assertBN((0, curve_1.computeY)(jsbi_1.default.BigInt(8), jsbi_1.default.BigInt(94), jsbi_1.default.BigInt(163)), jsbi_1.default.BigInt(69)); | ||
assertBN((0, curve_1.computeY)(jsbi_1.default.BigInt(2137), jsbi_1.default.BigInt(905777403660), jsbi_1.default.BigInt(830914146046)), jsbi_1.default.BigInt(490376033)); | ||
assertBN((0, curve_1.computeY)(jsbi_1.default.BigInt("17095344176474858097"), jsbi_1.default.BigInt(383), jsbi_1.default.BigInt("2276818911077272163")), jsbi_1.default.BigInt("2276917873767753112")); | ||
assertBN((0, curve_1.computeY)(jsbi_1.default.BigInt("7644937799120520965"), jsbi_1.default.BigInt("14818904982296505121"), jsbi_1.default.BigInt("17480022366793075404")), jsbi_1.default.BigInt("2661117384496570284")); | ||
}); | ||
}); | ||
//# sourceMappingURL=curve.unit.test.js.map |
@@ -21,10 +21,10 @@ "use strict"; | ||
const makeExchangeInfo = ({ exchange, swap, accounts, }) => { | ||
const swapAmountA = token_utils_1.deserializeAccount(swap.state.tokenA.reserve, accounts.reserveA).amount; | ||
const swapAmountB = token_utils_1.deserializeAccount(swap.state.tokenA.reserve, accounts.reserveB).amount; | ||
const swapAmountA = (0, token_utils_1.deserializeAccount)(swap.state.tokenA.reserve, accounts.reserveA).amount; | ||
const swapAmountB = (0, token_utils_1.deserializeAccount)(swap.state.tokenA.reserve, accounts.reserveB).amount; | ||
const poolMintSupply = accounts.poolMint | ||
? token_utils_1.deserializeMint(accounts.poolMint).supply | ||
? (0, token_utils_1.deserializeMint)(accounts.poolMint).supply | ||
: undefined; | ||
return { | ||
// TODO(igm): this should be calculated dynamically | ||
ampFactor: token_utils_1.parseBigintIsh(swap.state.targetAmpFactor.toString()), | ||
ampFactor: (0, token_utils_1.parseBigintIsh)(swap.state.targetAmpFactor.toString()), | ||
fees: swap.state.fees, | ||
@@ -57,14 +57,6 @@ lpTotalSupply: new token_utils_1.TokenAmount(exchange.lpToken, poolMintSupply !== null && poolMintSupply !== void 0 ? poolMintSupply : 0), | ||
} | ||
let reserveA; | ||
let reserveB; | ||
let poolMint; | ||
try { | ||
reserveA = yield account_1.loadProgramAccount(connection, swap.state.tokenA.reserve, swap.config.tokenProgramID); | ||
reserveB = yield account_1.loadProgramAccount(connection, swap.state.tokenB.reserve, swap.config.tokenProgramID); | ||
poolMint = yield account_1.loadProgramAccount(connection, swap.state.poolTokenMint, swap.config.tokenProgramID); | ||
} | ||
catch (e) { | ||
throw new Error(e); | ||
} | ||
return exports.makeExchangeInfo({ | ||
const reserveA = yield (0, account_1.loadProgramAccount)(connection, swap.state.tokenA.reserve, swap.config.tokenProgramID); | ||
const reserveB = yield (0, account_1.loadProgramAccount)(connection, swap.state.tokenB.reserve, swap.config.tokenProgramID); | ||
const poolMint = yield (0, account_1.loadProgramAccount)(connection, swap.state.poolTokenMint, swap.config.tokenProgramID); | ||
return (0, exports.makeExchangeInfo)({ | ||
swap, | ||
@@ -71,0 +63,0 @@ exchange, |
@@ -54,3 +54,3 @@ "use strict"; | ||
BufferLayout.u8("instruction"), | ||
token_utils_1.Uint64Layout("targetAmp"), | ||
(0, token_utils_1.Uint64Layout)("targetAmp"), | ||
BufferLayout.ns64("stopRampTS"), | ||
@@ -67,3 +67,3 @@ ]); | ||
} | ||
return common_1.buildInstruction({ | ||
return (0, common_1.buildInstruction)({ | ||
config, | ||
@@ -92,3 +92,3 @@ keys, | ||
} | ||
return common_1.buildInstruction({ | ||
return (0, common_1.buildInstruction)({ | ||
config, | ||
@@ -116,3 +116,3 @@ keys, | ||
} | ||
return common_1.buildInstruction({ | ||
return (0, common_1.buildInstruction)({ | ||
config, | ||
@@ -140,3 +140,3 @@ keys, | ||
} | ||
return common_1.buildInstruction({ | ||
return (0, common_1.buildInstruction)({ | ||
config, | ||
@@ -165,3 +165,3 @@ keys, | ||
} | ||
return common_1.buildInstruction({ | ||
return (0, common_1.buildInstruction)({ | ||
config, | ||
@@ -190,3 +190,3 @@ keys, | ||
} | ||
return common_1.buildInstruction({ | ||
return (0, common_1.buildInstruction)({ | ||
config, | ||
@@ -216,3 +216,3 @@ keys, | ||
} | ||
return common_1.buildInstruction({ | ||
return (0, common_1.buildInstruction)({ | ||
config, | ||
@@ -237,7 +237,7 @@ keys, | ||
instruction: AdminInstruction.SET_NEW_FEES, | ||
fees: fees_1.encodeFees(fees), | ||
fees: (0, fees_1.encodeFees)(fees), | ||
}, data); | ||
data = data.slice(0, encodeLength); | ||
} | ||
return common_1.buildInstruction({ | ||
return (0, common_1.buildInstruction)({ | ||
config, | ||
@@ -244,0 +244,0 @@ keys, |
@@ -55,3 +55,3 @@ "use strict"; | ||
BufferLayout.u8("nonce"), | ||
token_utils_1.Uint64Layout("ampFactor"), | ||
(0, token_utils_1.Uint64Layout)("ampFactor"), | ||
state_1.FeesLayout, | ||
@@ -65,7 +65,7 @@ ]); | ||
ampFactor: ampFactor.toBuffer(), | ||
fees: state_1.encodeFees(fees), | ||
fees: (0, state_1.encodeFees)(fees), | ||
}, data); | ||
data = data.slice(0, encodeLength); | ||
} | ||
return common_1.buildInstruction({ | ||
return (0, common_1.buildInstruction)({ | ||
config, | ||
@@ -80,4 +80,4 @@ keys, | ||
BufferLayout.u8("instruction"), | ||
token_utils_1.Uint64Layout("amountIn"), | ||
token_utils_1.Uint64Layout("minimumAmountOut"), | ||
(0, token_utils_1.Uint64Layout)("amountIn"), | ||
(0, token_utils_1.Uint64Layout)("minimumAmountOut"), | ||
]); | ||
@@ -102,3 +102,3 @@ const data = Buffer.alloc(dataLayout.span); | ||
]; | ||
return common_1.buildInstruction({ | ||
return (0, common_1.buildInstruction)({ | ||
config, | ||
@@ -113,5 +113,5 @@ keys, | ||
BufferLayout.u8("instruction"), | ||
token_utils_1.Uint64Layout("tokenAmountA"), | ||
token_utils_1.Uint64Layout("tokenAmountB"), | ||
token_utils_1.Uint64Layout("minimumPoolTokenAmount"), | ||
(0, token_utils_1.Uint64Layout)("tokenAmountA"), | ||
(0, token_utils_1.Uint64Layout)("tokenAmountB"), | ||
(0, token_utils_1.Uint64Layout)("minimumPoolTokenAmount"), | ||
]); | ||
@@ -138,3 +138,3 @@ const data = Buffer.alloc(dataLayout.span); | ||
]; | ||
return common_1.buildInstruction({ | ||
return (0, common_1.buildInstruction)({ | ||
config, | ||
@@ -149,5 +149,5 @@ keys, | ||
BufferLayout.u8("instruction"), | ||
token_utils_1.Uint64Layout("poolTokenAmount"), | ||
token_utils_1.Uint64Layout("minimumTokenA"), | ||
token_utils_1.Uint64Layout("minimumTokenB"), | ||
(0, token_utils_1.Uint64Layout)("poolTokenAmount"), | ||
(0, token_utils_1.Uint64Layout)("minimumTokenA"), | ||
(0, token_utils_1.Uint64Layout)("minimumTokenB"), | ||
]); | ||
@@ -176,3 +176,3 @@ const data = Buffer.alloc(dataLayout.span); | ||
]; | ||
return common_1.buildInstruction({ | ||
return (0, common_1.buildInstruction)({ | ||
config, | ||
@@ -187,4 +187,4 @@ keys, | ||
BufferLayout.u8("instruction"), | ||
token_utils_1.Uint64Layout("poolTokenAmount"), | ||
token_utils_1.Uint64Layout("minimumTokenAmount"), | ||
(0, token_utils_1.Uint64Layout)("poolTokenAmount"), | ||
(0, token_utils_1.Uint64Layout)("minimumTokenAmount"), | ||
]); | ||
@@ -210,3 +210,3 @@ const data = Buffer.alloc(withdrawOneDataLayout.span); | ||
]; | ||
return common_1.buildInstruction({ | ||
return (0, common_1.buildInstruction)({ | ||
config, | ||
@@ -213,0 +213,0 @@ keys, |
@@ -69,4 +69,4 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const data = yield account_1.loadProgramAccount(connection, swapAccount, programID); | ||
const [authority] = yield exports.findSwapAuthorityKey(swapAccount, programID); | ||
const data = yield (0, account_1.loadProgramAccount)(connection, swapAccount, programID); | ||
const [authority] = yield (0, exports.findSwapAuthorityKey)(swapAccount, programID); | ||
return StableSwap.loadWithData(swapAccount, data, authority, programID); | ||
@@ -101,3 +101,3 @@ }); | ||
} | ||
const state = state_1.decodeSwap(swapAccountData); | ||
const state = (0, state_1.decodeSwap)(swapAccountData); | ||
return new StableSwap({ | ||
@@ -104,0 +104,0 @@ swapAccount: swapAccount, |
@@ -42,3 +42,3 @@ "use strict"; | ||
const stopRampTimestamp = stableSwapData.stopRampTs; | ||
const fees = fees_1.decodeFees(stableSwapData.fees); | ||
const fees = (0, fees_1.decodeFees)(stableSwapData.fees); | ||
return { | ||
@@ -45,0 +45,0 @@ adminAccount, |
@@ -29,10 +29,10 @@ "use strict"; | ||
exports.FeesLayout = BufferLayout.struct([ | ||
token_utils_1.Uint64Layout("adminTradeFeeNumerator"), | ||
token_utils_1.Uint64Layout("adminTradeFeeDenominator"), | ||
token_utils_1.Uint64Layout("adminWithdrawFeeNumerator"), | ||
token_utils_1.Uint64Layout("adminWithdrawFeeDenominator"), | ||
token_utils_1.Uint64Layout("tradeFeeNumerator"), | ||
token_utils_1.Uint64Layout("tradeFeeDenominator"), | ||
token_utils_1.Uint64Layout("withdrawFeeNumerator"), | ||
token_utils_1.Uint64Layout("withdrawFeeDenominator"), | ||
(0, token_utils_1.Uint64Layout)("adminTradeFeeNumerator"), | ||
(0, token_utils_1.Uint64Layout)("adminTradeFeeDenominator"), | ||
(0, token_utils_1.Uint64Layout)("adminWithdrawFeeNumerator"), | ||
(0, token_utils_1.Uint64Layout)("adminWithdrawFeeDenominator"), | ||
(0, token_utils_1.Uint64Layout)("tradeFeeNumerator"), | ||
(0, token_utils_1.Uint64Layout)("tradeFeeDenominator"), | ||
(0, token_utils_1.Uint64Layout)("withdrawFeeNumerator"), | ||
(0, token_utils_1.Uint64Layout)("withdrawFeeDenominator"), | ||
], "fees"); | ||
@@ -46,18 +46,18 @@ /** | ||
BufferLayout.u8("nonce"), | ||
token_utils_1.Uint64Layout("initialAmpFactor"), | ||
token_utils_1.Uint64Layout("targetAmpFactor"), | ||
(0, token_utils_1.Uint64Layout)("initialAmpFactor"), | ||
(0, token_utils_1.Uint64Layout)("targetAmpFactor"), | ||
BufferLayout.ns64("startRampTs"), | ||
BufferLayout.ns64("stopRampTs"), | ||
BufferLayout.ns64("futureAdminDeadline"), | ||
token_utils_1.PublicKeyLayout("futureAdminAccount"), | ||
token_utils_1.PublicKeyLayout("adminAccount"), | ||
token_utils_1.PublicKeyLayout("tokenAccountA"), | ||
token_utils_1.PublicKeyLayout("tokenAccountB"), | ||
token_utils_1.PublicKeyLayout("tokenPool"), | ||
token_utils_1.PublicKeyLayout("mintA"), | ||
token_utils_1.PublicKeyLayout("mintB"), | ||
token_utils_1.PublicKeyLayout("adminFeeAccountA"), | ||
token_utils_1.PublicKeyLayout("adminFeeAccountB"), | ||
(0, token_utils_1.PublicKeyLayout)("futureAdminAccount"), | ||
(0, token_utils_1.PublicKeyLayout)("adminAccount"), | ||
(0, token_utils_1.PublicKeyLayout)("tokenAccountA"), | ||
(0, token_utils_1.PublicKeyLayout)("tokenAccountB"), | ||
(0, token_utils_1.PublicKeyLayout)("tokenPool"), | ||
(0, token_utils_1.PublicKeyLayout)("mintA"), | ||
(0, token_utils_1.PublicKeyLayout)("mintB"), | ||
(0, token_utils_1.PublicKeyLayout)("adminFeeAccountA"), | ||
(0, token_utils_1.PublicKeyLayout)("adminFeeAccountB"), | ||
exports.FeesLayout, | ||
]); | ||
//# sourceMappingURL=layout.js.map |
@@ -33,3 +33,3 @@ "use strict"; | ||
} | ||
const { instructions } = yield exports.createInitializeStableSwapInstructionsRaw({ | ||
const { instructions } = yield (0, exports.createInitializeStableSwapInstructionsRaw)({ | ||
provider, | ||
@@ -42,3 +42,3 @@ initializeSwapInstruction, | ||
console.log(`TxSig: ${txSig}`); | ||
return exports.loadSwapFromInitializeArgs(initializeSwapInstruction); | ||
return (0, exports.loadSwapFromInitializeArgs)(initializeSwapInstruction); | ||
}); | ||
@@ -81,4 +81,4 @@ exports.initializeStableSwap = initializeStableSwap; | ||
createSwapTokenBAccounts: new solana_contrib_1.TransactionEnvelope(provider, []), | ||
seedPoolAccounts: instructions_1.createMutableTransactionInstructions(), | ||
initializeSwap: instructions_1.createMutableTransactionInstructions(), | ||
seedPoolAccounts: (0, instructions_1.createMutableTransactionInstructions)(), | ||
initializeSwap: (0, instructions_1.createMutableTransactionInstructions)(), | ||
}; | ||
@@ -89,7 +89,7 @@ // Create swap account if not specified | ||
// Create authority and nonce | ||
const [authority, nonce] = yield stable_swap_1.findSwapAuthorityKey(swapAccount, swapProgramID); | ||
const [authority, nonce] = yield (0, stable_swap_1.findSwapAuthorityKey)(swapAccount, swapProgramID); | ||
// Create LP token mint | ||
const { decimals } = yield new token_utils_1.SPLToken(provider.connection, tokenAMint, token_utils_1.TOKEN_PROGRAM_ID, web3_js_1.Keypair.generate()).getMintInfo(); | ||
const mintBalanceNeeded = yield token_utils_1.SPLToken.getMinBalanceRentForExemptMint(provider.connection); | ||
instructions.createLPTokenMint = yield token_utils_1.createInitMintInstructions({ | ||
instructions.createLPTokenMint = yield (0, token_utils_1.createInitMintInstructions)({ | ||
provider, | ||
@@ -104,3 +104,3 @@ mintKP: poolTokenMintSigner, | ||
if (useAssociatedAccountForInitialLP) { | ||
const lpAccount = yield token_utils_1.getOrCreateATA({ | ||
const lpAccount = yield (0, token_utils_1.getOrCreateATA)({ | ||
provider, | ||
@@ -117,3 +117,3 @@ mint: poolTokenMint, | ||
else { | ||
const { key: unassociatedInitialLPAccount, tx: initialLPInstructions } = yield token_utils_1.createTokenAccount({ | ||
const { key: unassociatedInitialLPAccount, tx: initialLPInstructions } = yield (0, token_utils_1.createTokenAccount)({ | ||
provider, | ||
@@ -134,3 +134,3 @@ mint: poolTokenMint, | ||
}); | ||
instructions_1.mergeInstructions(instructions.createSwapTokenAAccounts, tokenAInstructions); | ||
(0, instructions_1.mergeInstructions)(instructions.createSwapTokenAAccounts, tokenAInstructions); | ||
// Create Swap Token B account | ||
@@ -143,3 +143,3 @@ const { info: tokenB, instructions: tokenBInstructions } = yield initializeSwapTokenInfo({ | ||
}); | ||
instructions_1.mergeInstructions(instructions.createSwapTokenBAccounts, tokenBInstructions); | ||
(0, instructions_1.mergeInstructions)(instructions.createSwapTokenBAccounts, tokenBInstructions); | ||
// Seed the swap's Token A and token B accounts with tokens | ||
@@ -152,3 +152,3 @@ // On testnet, this is usually a mint. | ||
}); | ||
instructions_1.mergeInstructions(instructions.seedPoolAccounts, seedPoolAccountsResult); | ||
(0, instructions_1.mergeInstructions)(instructions.seedPoolAccounts, seedPoolAccountsResult); | ||
const initializeSwapInstruction = { | ||
@@ -170,7 +170,7 @@ config: { | ||
}; | ||
const { balanceNeeded: swapBalanceNeeded, instructions: initializeStableSwapInstructions, } = yield exports.createInitializeStableSwapInstructionsRaw({ | ||
const { balanceNeeded: swapBalanceNeeded, instructions: initializeStableSwapInstructions, } = yield (0, exports.createInitializeStableSwapInstructionsRaw)({ | ||
provider, | ||
initializeSwapInstruction, | ||
}); | ||
instructions_1.mergeInstructions(instructions.initializeSwap, { | ||
(0, instructions_1.mergeInstructions)(instructions.initializeSwap, { | ||
instructions: initializeStableSwapInstructions, | ||
@@ -188,3 +188,3 @@ signers: [], | ||
// Create Swap Token Account | ||
const { key: tokenAccount, tx: createSwapTokenAccountInstructions } = yield token_utils_1.createTokenAccount({ | ||
const { key: tokenAccount, tx: createSwapTokenAccountInstructions } = yield (0, token_utils_1.createTokenAccount)({ | ||
provider, | ||
@@ -196,3 +196,3 @@ mint, | ||
// Create Admin Fee Account | ||
const { key: adminFeeAccount, tx: createAdminFeeAccountInstructions } = yield token_utils_1.createTokenAccount({ | ||
const { key: adminFeeAccount, tx: createAdminFeeAccountInstructions } = yield (0, token_utils_1.createTokenAccount)({ | ||
provider, | ||
@@ -232,3 +232,3 @@ mint, | ||
}), | ||
swap_1.initializeSwapInstruction(initializeSwapInstruction), | ||
(0, swap_1.initializeSwapInstruction)(initializeSwapInstruction), | ||
], | ||
@@ -242,3 +242,3 @@ }; | ||
const deployNewSwap = (args) => __awaiter(void 0, void 0, void 0, function* () { | ||
const result = yield exports.createInitializeNewSwapTx(args); | ||
const result = yield (0, exports.createInitializeNewSwapTx)(args); | ||
const { txs } = result; | ||
@@ -265,3 +265,3 @@ const { signature: setupAccounts1 } = yield txs.setupAccounts1.confirm(); | ||
const { provider } = args; | ||
const { instructions, initializeArgs } = yield exports.createInitializeStableSwapInstructions(Object.assign({}, args)); | ||
const { instructions, initializeArgs } = yield (0, exports.createInitializeStableSwapInstructions)(Object.assign({}, args)); | ||
const setupAccounts1 = [ | ||
@@ -282,3 +282,3 @@ "createLPTokenMint", | ||
const initializeSwap = new solana_contrib_1.TransactionEnvelope(provider, instructions.initializeSwap.instructions.slice(), instructions.initializeSwap.signers.slice()); | ||
const newSwap = exports.loadSwapFromInitializeArgs(initializeArgs); | ||
const newSwap = (0, exports.loadSwapFromInitializeArgs)(initializeArgs); | ||
return { | ||
@@ -285,0 +285,0 @@ swap: newSwap, |
@@ -30,3 +30,3 @@ "use strict"; | ||
tx.add(...instructions); | ||
const txSig = yield web3_js_1.sendAndConfirmTransaction(connection, tx, [ | ||
const txSig = yield (0, web3_js_1.sendAndConfirmTransaction)(connection, tx, [ | ||
// payer of the tx | ||
@@ -33,0 +33,0 @@ payerSigner, |
@@ -8,3 +8,3 @@ { | ||
"author": "Saber Team <team@saber.so>", | ||
"version": "0.14.2", | ||
"version": "0.14.3", | ||
"main": "dist/index.js", | ||
@@ -28,7 +28,7 @@ "license": "Apache-2.0", | ||
"@types/lodash.mapvalues": "^4.6.6", | ||
"@types/node": "^16.4.12", | ||
"@types/node": "^16.7.5", | ||
"b58": "^4.0.3", | ||
"eslint": "^7.32.0", | ||
"husky": ">=7", | ||
"jest": "^27.0.6", | ||
"jest": "^27.1.0", | ||
"lint-staged": ">=11.1.1", | ||
@@ -38,6 +38,6 @@ "lodash.mapvalues": "^4.6.0", | ||
"ts-node": "^10.1.0", | ||
"typescript": "^4.3.5" | ||
"typescript": "^4.4.2" | ||
}, | ||
"dependencies": { | ||
"@saberhq/token-utils": "^0.14.2", | ||
"@saberhq/token-utils": "^0.14.3", | ||
"@solana/web3.js": "^1.24.0", | ||
@@ -59,3 +59,3 @@ "@types/bn.js": "^5.1.0", | ||
}, | ||
"gitHead": "8a4f20bf700337b8c769e5f144243792015bd63d" | ||
"gitHead": "fc2dbbb559f5535f137455a53084adc943235f55" | ||
} |
@@ -120,24 +120,17 @@ import { | ||
let reserveA; | ||
let reserveB; | ||
let poolMint; | ||
try { | ||
reserveA = await loadProgramAccount( | ||
connection, | ||
swap.state.tokenA.reserve, | ||
swap.config.tokenProgramID | ||
); | ||
reserveB = await loadProgramAccount( | ||
connection, | ||
swap.state.tokenB.reserve, | ||
swap.config.tokenProgramID | ||
); | ||
poolMint = await loadProgramAccount( | ||
connection, | ||
swap.state.poolTokenMint, | ||
swap.config.tokenProgramID | ||
); | ||
} catch (e) { | ||
throw new Error(e); | ||
} | ||
const reserveA = await loadProgramAccount( | ||
connection, | ||
swap.state.tokenA.reserve, | ||
swap.config.tokenProgramID | ||
); | ||
const reserveB = await loadProgramAccount( | ||
connection, | ||
swap.state.tokenB.reserve, | ||
swap.config.tokenProgramID | ||
); | ||
const poolMint = await loadProgramAccount( | ||
connection, | ||
swap.state.poolTokenMint, | ||
swap.config.tokenProgramID | ||
); | ||
return makeExchangeInfo({ | ||
@@ -144,0 +137,0 @@ swap, |
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
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
288953
5479
Updated@saberhq/token-utils@^0.14.3