@orca-so/whirlpool-sdk
Version:
Whirlpool SDK for the Orca protocol.
32 lines (31 loc) • 1.13 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.subUnderflowU128 = exports.divRoundUp = exports.shiftRightRoundUp = exports.U64_MAX = exports.U128 = exports.TWO = exports.ONE = exports.ZERO = void 0;
const anchor_1 = require("@project-serum/anchor");
exports.ZERO = new anchor_1.BN(0);
exports.ONE = new anchor_1.BN(1);
exports.TWO = new anchor_1.BN(2);
exports.U128 = exports.TWO.pow(new anchor_1.BN(128));
exports.U64_MAX = exports.TWO.pow(new anchor_1.BN(64)).sub(exports.ONE);
function shiftRightRoundUp(n) {
let result = n.shrn(64);
if (n.mod(exports.U64_MAX).gt(exports.ZERO)) {
result = result.add(exports.ONE);
}
return result;
}
exports.shiftRightRoundUp = shiftRightRoundUp;
function divRoundUp(n0, n1) {
const hasRemainder = !n0.mod(n1).eq(exports.ZERO);
if (hasRemainder) {
return n0.div(n1).add(new anchor_1.BN(1));
}
else {
return n0.div(n1);
}
}
exports.divRoundUp = divRoundUp;
function subUnderflowU128(n0, n1) {
return n0.add(exports.U128).sub(n1).mod(exports.U128);
}
exports.subUnderflowU128 = subUnderflowU128;
;