@tokenlon/contracts-lib
Version:
Common utility functions (e.g., signing order, encoding data) to interact with [Tokenlon contracts](https://github.com/consenlabs/tokenlon-contracts).
28 lines • 1.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.encodeUniswapV3Path = exports.UniswapV3Fee = void 0;
const FEE_SIZE = 3;
var UniswapV3Fee;
(function (UniswapV3Fee) {
UniswapV3Fee[UniswapV3Fee["LOWEST"] = 100] = "LOWEST";
UniswapV3Fee[UniswapV3Fee["LOW"] = 500] = "LOW";
UniswapV3Fee[UniswapV3Fee["MEDIUM"] = 3000] = "MEDIUM";
UniswapV3Fee[UniswapV3Fee["HIGH"] = 10000] = "HIGH";
})(UniswapV3Fee = exports.UniswapV3Fee || (exports.UniswapV3Fee = {}));
function encodeUniswapV3Path(path, fees) {
if (path.length != fees.length + 1) {
throw new Error("path/fee lengths do not match");
}
let encoded = "0x";
for (let i = 0; i < fees.length; i++) {
// 20 byte encoding of the address
encoded += path[i].slice(2);
// 3 byte encoding of the fee
encoded += fees[i].toString(16).padStart(2 * FEE_SIZE, "0");
}
// encode the final token
encoded += path[path.length - 1].slice(2);
return encoded.toLowerCase();
}
exports.encodeUniswapV3Path = encodeUniswapV3Path;
//# sourceMappingURL=index.js.map