Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@kava-labs/javascript-sdk

Package Overview
Dependencies
Maintainers
5
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kava-labs/javascript-sdk - npm Package Compare versions

Comparing version 5.3.0 to 5.3.1

329

lib/client/hard/index.js
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Hard = void 0;
const tx_1 = require("../../tx");
const msg_1 = require("../../msg");
const DEFAULT_GAS = 300000;
const api = {
var tx_1 = require("../../tx");
var msg_1 = require("../../msg");
var DEFAULT_GAS = 300000;
var api = {
getParams: '/hard/parameters',

@@ -15,4 +51,4 @@ getModAccounts: '/hard/accounts',

};
class Hard {
constructor(kavaClient) {
var Hard = /** @class */ (function () {
function Hard(kavaClient) {
if (!Hard.instance) {

@@ -29,8 +65,19 @@ this.kavaClient = kavaClient;

*/
async getParams(timeout = 2000) {
const res = await tx_1.tx.getTx(api.getParams, this.kavaClient.baseURI, timeout);
if (res && res.data) {
return res.data.result;
}
}
Hard.prototype.getParams = function (timeout) {
if (timeout === void 0) { timeout = 2000; }
return __awaiter(this, void 0, void 0, function () {
var res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, tx_1.tx.getTx(api.getParams, this.kavaClient.baseURI, timeout)];
case 1:
res = _a.sent();
if (res && res.data) {
return [2 /*return*/, res.data.result];
}
return [2 /*return*/];
}
});
});
};
/**

@@ -42,8 +89,20 @@ * Get module accounts associated with the hard module

*/
async getModAccounts(args = {}, timeout = 2000) {
const res = await tx_1.tx.getTx(api.getModAccounts, this.kavaClient.baseURI, timeout, args);
if (res && res.data) {
return res.data.result;
}
}
Hard.prototype.getModAccounts = function (args, timeout) {
if (args === void 0) { args = {}; }
if (timeout === void 0) { timeout = 2000; }
return __awaiter(this, void 0, void 0, function () {
var res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, tx_1.tx.getTx(api.getModAccounts, this.kavaClient.baseURI, timeout, args)];
case 1:
res = _a.sent();
if (res && res.data) {
return [2 /*return*/, res.data.result];
}
return [2 /*return*/];
}
});
});
};
/**

@@ -55,8 +114,20 @@ * Get hard deposits

*/
async getDeposits(args = {}, timeout = 2000) {
const res = await tx_1.tx.getTx(api.getDeposits, this.kavaClient.baseURI, timeout, args);
if (res && res.data) {
return res.data.result;
}
}
Hard.prototype.getDeposits = function (args, timeout) {
if (args === void 0) { args = {}; }
if (timeout === void 0) { timeout = 2000; }
return __awaiter(this, void 0, void 0, function () {
var res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, tx_1.tx.getTx(api.getDeposits, this.kavaClient.baseURI, timeout, args)];
case 1:
res = _a.sent();
if (res && res.data) {
return [2 /*return*/, res.data.result];
}
return [2 /*return*/];
}
});
});
};
/**

@@ -68,8 +139,20 @@ * Get hard total-deposited

*/
async getTotalDeposited(args = {}, timeout = 2000) {
const res = await tx_1.tx.getTx(api.getTotalDeposited, this.kavaClient.baseURI, timeout, args);
if (res && res.data) {
return res.data.result;
}
}
Hard.prototype.getTotalDeposited = function (args, timeout) {
if (args === void 0) { args = {}; }
if (timeout === void 0) { timeout = 2000; }
return __awaiter(this, void 0, void 0, function () {
var res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, tx_1.tx.getTx(api.getTotalDeposited, this.kavaClient.baseURI, timeout, args)];
case 1:
res = _a.sent();
if (res && res.data) {
return [2 /*return*/, res.data.result];
}
return [2 /*return*/];
}
});
});
};
/**

@@ -81,8 +164,20 @@ * Get hard borrows

*/
async getBorrows(args = {}, timeout = 2000) {
const res = await tx_1.tx.getTx(api.getBorrows, this.kavaClient.baseURI, timeout, args);
if (res && res.data) {
return res.data.result;
}
}
Hard.prototype.getBorrows = function (args, timeout) {
if (args === void 0) { args = {}; }
if (timeout === void 0) { timeout = 2000; }
return __awaiter(this, void 0, void 0, function () {
var res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, tx_1.tx.getTx(api.getBorrows, this.kavaClient.baseURI, timeout, args)];
case 1:
res = _a.sent();
if (res && res.data) {
return [2 /*return*/, res.data.result];
}
return [2 /*return*/];
}
});
});
};
/**

@@ -94,8 +189,20 @@ * Get hard total-borrowed

*/
async getTotalBorrowed(args = {}, timeout = 2000) {
const res = await tx_1.tx.getTx(api.getTotalBorrowed, this.kavaClient.baseURI, timeout, args);
if (res && res.data) {
return res.data.result;
}
}
Hard.prototype.getTotalBorrowed = function (args, timeout) {
if (args === void 0) { args = {}; }
if (timeout === void 0) { timeout = 2000; }
return __awaiter(this, void 0, void 0, function () {
var res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, tx_1.tx.getTx(api.getTotalBorrowed, this.kavaClient.baseURI, timeout, args)];
case 1:
res = _a.sent();
if (res && res.data) {
return [2 /*return*/, res.data.result];
}
return [2 /*return*/];
}
});
});
};
/**

@@ -108,10 +215,21 @@ * Deposit funds to a liquidity pool

*/
async deposit(amount, gas = DEFAULT_GAS, sequence = null) {
if (!this.kavaClient.wallet) {
throw Error('Wallet has not yet been initialized');
}
const msgDeposit = msg_1.msg.hard.newMsgDeposit(this.kavaClient.wallet.address, amount);
const fee = { amount: [], gas: String(gas) };
return await this.kavaClient.sendTx([msgDeposit], fee, sequence);
}
Hard.prototype.deposit = function (amount, gas, sequence) {
if (gas === void 0) { gas = DEFAULT_GAS; }
if (sequence === void 0) { sequence = null; }
return __awaiter(this, void 0, void 0, function () {
var msgDeposit, fee;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.kavaClient.wallet) {
throw Error('Wallet has not yet been initialized');
}
msgDeposit = msg_1.msg.hard.newMsgDeposit(this.kavaClient.wallet.address, amount);
fee = { amount: [], gas: String(gas) };
return [4 /*yield*/, this.kavaClient.sendTx([msgDeposit], fee, sequence)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
/**

@@ -124,10 +242,21 @@ * Withdraw funds from a liquidity pool

*/
async withdraw(amount, gas = DEFAULT_GAS, sequence = null) {
if (!this.kavaClient.wallet) {
throw Error('Wallet has not yet been initialized');
}
const msgWithdraw = msg_1.msg.hard.newMsgWithdraw(this.kavaClient.wallet.address, amount);
const fee = { amount: [], gas: String(gas) };
return await this.kavaClient.sendTx([msgWithdraw], fee, sequence);
}
Hard.prototype.withdraw = function (amount, gas, sequence) {
if (gas === void 0) { gas = DEFAULT_GAS; }
if (sequence === void 0) { sequence = null; }
return __awaiter(this, void 0, void 0, function () {
var msgWithdraw, fee;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.kavaClient.wallet) {
throw Error('Wallet has not yet been initialized');
}
msgWithdraw = msg_1.msg.hard.newMsgWithdraw(this.kavaClient.wallet.address, amount);
fee = { amount: [], gas: String(gas) };
return [4 /*yield*/, this.kavaClient.sendTx([msgWithdraw], fee, sequence)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
/**

@@ -140,10 +269,21 @@ * Borrow available funds from a liquidity pool

*/
async borrow(amount, gas = DEFAULT_GAS, sequence = null) {
if (!this.kavaClient.wallet) {
throw Error('Wallet has not yet been initialized');
}
const msgBorrow = msg_1.msg.hard.newMsgBorrow(this.kavaClient.wallet.address, amount);
const fee = { amount: [], gas: String(gas) };
return await this.kavaClient.sendTx([msgBorrow], fee, sequence);
}
Hard.prototype.borrow = function (amount, gas, sequence) {
if (gas === void 0) { gas = DEFAULT_GAS; }
if (sequence === void 0) { sequence = null; }
return __awaiter(this, void 0, void 0, function () {
var msgBorrow, fee;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.kavaClient.wallet) {
throw Error('Wallet has not yet been initialized');
}
msgBorrow = msg_1.msg.hard.newMsgBorrow(this.kavaClient.wallet.address, amount);
fee = { amount: [], gas: String(gas) };
return [4 /*yield*/, this.kavaClient.sendTx([msgBorrow], fee, sequence)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
/**

@@ -156,10 +296,21 @@ * Repay funds borrowed from a liquidity pool

*/
async repay(amount, gas = DEFAULT_GAS, sequence = null) {
if (!this.kavaClient.wallet) {
throw Error('Wallet has not yet been initialized');
}
const msgRepay = msg_1.msg.hard.newMsgRepay(this.kavaClient.wallet.address, this.kavaClient.wallet.address, amount);
const fee = { amount: [], gas: String(gas) };
return await this.kavaClient.sendTx([msgRepay], fee, sequence);
}
Hard.prototype.repay = function (amount, gas, sequence) {
if (gas === void 0) { gas = DEFAULT_GAS; }
if (sequence === void 0) { sequence = null; }
return __awaiter(this, void 0, void 0, function () {
var msgRepay, fee;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.kavaClient.wallet) {
throw Error('Wallet has not yet been initialized');
}
msgRepay = msg_1.msg.hard.newMsgRepay(this.kavaClient.wallet.address, this.kavaClient.wallet.address, amount);
fee = { amount: [], gas: String(gas) };
return [4 /*yield*/, this.kavaClient.sendTx([msgRepay], fee, sequence)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
/**

@@ -172,12 +323,24 @@ * Attempt to liquidate a borrower that's over their loan-to-value ratio

*/
async liquidate(borrower, gas = DEFAULT_GAS, sequence = null) {
if (!this.kavaClient.wallet) {
throw Error('Wallet has not yet been initialized');
}
const msgLiquidate = msg_1.msg.hard.newMsgLiquidate(this.kavaClient.wallet.address, borrower);
const fee = { amount: [], gas: String(gas) };
return await this.kavaClient.sendTx([msgLiquidate], fee, sequence);
}
}
Hard.prototype.liquidate = function (borrower, gas, sequence) {
if (gas === void 0) { gas = DEFAULT_GAS; }
if (sequence === void 0) { sequence = null; }
return __awaiter(this, void 0, void 0, function () {
var msgLiquidate, fee;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.kavaClient.wallet) {
throw Error('Wallet has not yet been initialized');
}
msgLiquidate = msg_1.msg.hard.newMsgLiquidate(this.kavaClient.wallet.address, borrower);
fee = { amount: [], gas: String(gas) };
return [4 /*yield*/, this.kavaClient.sendTx([msgLiquidate], fee, sequence)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
return Hard;
}());
exports.Hard = Hard;
module.exports.Hard = Hard;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
const tx_1 = require("../../tx");
const msg_1 = require("../../msg");
const DEFAULT_GAS = 300000;
const api = {
var tx_1 = require("../../tx");
var msg_1 = require("../../msg");
var DEFAULT_GAS = 300000;
var api = {
getParams: '/swap/parameters',

@@ -12,4 +48,4 @@ getDeposits: '/swap/deposits',

};
class Swap {
constructor(kavaClient) {
var Swap = /** @class */ (function () {
function Swap(kavaClient) {
if (!Swap.instance) {

@@ -26,8 +62,19 @@ this.kavaClient = kavaClient;

*/
async getParams(timeout = 2000) {
const res = await tx_1.tx.getTx(api.getParams, this.kavaClient.baseURI, timeout);
if (res && res.data) {
return res.data.result;
}
}
Swap.prototype.getParams = function (timeout) {
if (timeout === void 0) { timeout = 2000; }
return __awaiter(this, void 0, void 0, function () {
var res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, tx_1.tx.getTx(api.getParams, this.kavaClient.baseURI, timeout)];
case 1:
res = _a.sent();
if (res && res.data) {
return [2 /*return*/, res.data.result];
}
return [2 /*return*/];
}
});
});
};
/**

@@ -39,8 +86,20 @@ * Get swap deposits

*/
async getDeposits(args = {}, timeout = 2000) {
const res = await tx_1.tx.getTx(api.getDeposits, this.kavaClient.baseURI, timeout, args);
if (res && res.data) {
return res.data.result;
}
}
Swap.prototype.getDeposits = function (args, timeout) {
if (args === void 0) { args = {}; }
if (timeout === void 0) { timeout = 2000; }
return __awaiter(this, void 0, void 0, function () {
var res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, tx_1.tx.getTx(api.getDeposits, this.kavaClient.baseURI, timeout, args)];
case 1:
res = _a.sent();
if (res && res.data) {
return [2 /*return*/, res.data.result];
}
return [2 /*return*/];
}
});
});
};
/**

@@ -52,8 +111,20 @@ * Get swap pool

*/
async getPool(args = {}, timeout = 2000) {
const res = await tx_1.tx.getTx(api.getPool, this.kavaClient.baseURI, timeout, args);
if (res && res.data) {
return res.data.result;
}
}
Swap.prototype.getPool = function (args, timeout) {
if (args === void 0) { args = {}; }
if (timeout === void 0) { timeout = 2000; }
return __awaiter(this, void 0, void 0, function () {
var res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, tx_1.tx.getTx(api.getPool, this.kavaClient.baseURI, timeout, args)];
case 1:
res = _a.sent();
if (res && res.data) {
return [2 /*return*/, res.data.result];
}
return [2 /*return*/];
}
});
});
};
/**

@@ -64,8 +135,20 @@ * Get swap pools

*/
async getPools(args = {}, timeout = 2000) {
const res = await tx_1.tx.getTx(api.getPools, this.kavaClient.baseURI, timeout, args);
if (res && res.data) {
return res.data.result;
}
}
Swap.prototype.getPools = function (args, timeout) {
if (args === void 0) { args = {}; }
if (timeout === void 0) { timeout = 2000; }
return __awaiter(this, void 0, void 0, function () {
var res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, tx_1.tx.getTx(api.getPools, this.kavaClient.baseURI, timeout, args)];
case 1:
res = _a.sent();
if (res && res.data) {
return [2 /*return*/, res.data.result];
}
return [2 /*return*/];
}
});
});
};
/**

@@ -81,10 +164,21 @@ * Deposit funds to a liquidity pool

*/
async deposit(tokenA, tokenB, slippage, deadline, gas = DEFAULT_GAS, sequence = null) {
if (!this.kavaClient.wallet) {
throw Error('Wallet has not yet been initialized');
}
const msgDeposit = msg_1.msg.swap.newMsgDeposit(this.kavaClient.wallet.address, tokenA, tokenB, slippage, deadline);
const fee = { amount: [], gas: String(gas) };
return await this.kavaClient.sendTx([msgDeposit], fee, sequence);
}
Swap.prototype.deposit = function (tokenA, tokenB, slippage, deadline, gas, sequence) {
if (gas === void 0) { gas = DEFAULT_GAS; }
if (sequence === void 0) { sequence = null; }
return __awaiter(this, void 0, void 0, function () {
var msgDeposit, fee;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.kavaClient.wallet) {
throw Error('Wallet has not yet been initialized');
}
msgDeposit = msg_1.msg.swap.newMsgDeposit(this.kavaClient.wallet.address, tokenA, tokenB, slippage, deadline);
fee = { amount: [], gas: String(gas) };
return [4 /*yield*/, this.kavaClient.sendTx([msgDeposit], fee, sequence)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
/**

@@ -101,10 +195,21 @@ * Withdraw funds from a liquidity pool

*/
async withdraw(shares, minTokenA, minTokenB, deadline, gas = DEFAULT_GAS, sequence = null) {
if (!this.kavaClient.wallet) {
throw Error('Wallet has not yet been initialized');
}
const msgWithdraw = msg_1.msg.swap.newMsgWithdraw(this.kavaClient.wallet.address, shares, minTokenA, minTokenB, deadline);
const fee = { amount: [], gas: String(gas) };
return await this.kavaClient.sendTx([msgWithdraw], fee, sequence);
}
Swap.prototype.withdraw = function (shares, minTokenA, minTokenB, deadline, gas, sequence) {
if (gas === void 0) { gas = DEFAULT_GAS; }
if (sequence === void 0) { sequence = null; }
return __awaiter(this, void 0, void 0, function () {
var msgWithdraw, fee;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.kavaClient.wallet) {
throw Error('Wallet has not yet been initialized');
}
msgWithdraw = msg_1.msg.swap.newMsgWithdraw(this.kavaClient.wallet.address, shares, minTokenA, minTokenB, deadline);
fee = { amount: [], gas: String(gas) };
return [4 /*yield*/, this.kavaClient.sendTx([msgWithdraw], fee, sequence)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
/**

@@ -120,10 +225,21 @@ * Swap an exact number of token a for an estimated amount of token b

*/
async swapExactForTokens(exactTokenA, tokenB, slippage, deadline, gas = DEFAULT_GAS, sequence = null) {
if (!this.kavaClient.wallet) {
throw Error('Wallet has not yet been initialized');
}
const msgSwapExactForTokens = msg_1.msg.swap.newMsgSwapExactForTokens(this.kavaClient.wallet.address, exactTokenA, tokenB, slippage, deadline);
const fee = { amount: [], gas: String(gas) };
return await this.kavaClient.sendTx([msgSwapExactForTokens], fee, sequence);
}
Swap.prototype.swapExactForTokens = function (exactTokenA, tokenB, slippage, deadline, gas, sequence) {
if (gas === void 0) { gas = DEFAULT_GAS; }
if (sequence === void 0) { sequence = null; }
return __awaiter(this, void 0, void 0, function () {
var msgSwapExactForTokens, fee;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.kavaClient.wallet) {
throw Error('Wallet has not yet been initialized');
}
msgSwapExactForTokens = msg_1.msg.swap.newMsgSwapExactForTokens(this.kavaClient.wallet.address, exactTokenA, tokenB, slippage, deadline);
fee = { amount: [], gas: String(gas) };
return [4 /*yield*/, this.kavaClient.sendTx([msgSwapExactForTokens], fee, sequence)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
/**

@@ -139,11 +255,23 @@ * Swap an exact number of token b to be returned for an for an estimated amount of token a to input

*/
async swapForExactTokens(tokenA, exactTokenB, slippage, deadline, gas = DEFAULT_GAS, sequence = null) {
if (!this.kavaClient.wallet) {
throw Error('Wallet has not yet been initialized');
}
const msgSwapForExactTokens = msg_1.msg.swap.newMsgSwapForExactTokens(this.kavaClient.wallet.address, tokenA, exactTokenB, slippage, deadline);
const fee = { amount: [], gas: String(gas) };
return await this.kavaClient.sendTx([msgSwapForExactTokens], fee, sequence);
}
}
Swap.prototype.swapForExactTokens = function (tokenA, exactTokenB, slippage, deadline, gas, sequence) {
if (gas === void 0) { gas = DEFAULT_GAS; }
if (sequence === void 0) { sequence = null; }
return __awaiter(this, void 0, void 0, function () {
var msgSwapForExactTokens, fee;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.kavaClient.wallet) {
throw Error('Wallet has not yet been initialized');
}
msgSwapForExactTokens = msg_1.msg.swap.newMsgSwapForExactTokens(this.kavaClient.wallet.address, tokenA, exactTokenB, slippage, deadline);
fee = { amount: [], gas: String(gas) };
return [4 /*yield*/, this.kavaClient.sendTx([msgSwapForExactTokens], fee, sequence)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
return Swap;
}());
module.exports.Swap = Swap;

@@ -7,14 +7,14 @@ "use strict";

exports.crypto = void 0;
const sig = require('@kava-labs/sig');
const bech32_1 = __importDefault(require("bech32"));
const bip39_1 = __importDefault(require("bip39"));
const KAVA_PREFIX = 'kava';
const MNEMONIC_LEN = 256;
const DECODED_ADDRESS_LEN = 20;
const DERIVATION_PATH = "m/44'/459'/0'/0/0";
const DERIVATION_PATH_LEGACY = "m/44'/118'/0'/0/0";
var sig = require('@kava-labs/sig');
var bech32_1 = __importDefault(require("bech32"));
var bip39_1 = __importDefault(require("bip39"));
var KAVA_PREFIX = 'kava';
var MNEMONIC_LEN = 256;
var DECODED_ADDRESS_LEN = 20;
var DERIVATION_PATH = "m/44'/459'/0'/0/0";
var DERIVATION_PATH_LEGACY = "m/44'/118'/0'/0/0";
/**
* Generates mnemonic phrase words using random entropy.
*/
const generateMnemonic = () => bip39_1.default.generateMnemonic(MNEMONIC_LEN);
var generateMnemonic = function () { return bip39_1.default.generateMnemonic(MNEMONIC_LEN); };
/**

@@ -25,6 +25,7 @@ * Loads a key pair from a mnemonic phrase.

*/
const getAddressFromMnemonic = (mnemonic, legacy = false) => {
const derivationPath = legacy ? DERIVATION_PATH_LEGACY : DERIVATION_PATH;
const masterKey = sig.createMasterKeyFromMnemonic(mnemonic);
const keyPair = sig.createKeyPairFromMasterKey(masterKey, derivationPath);
var getAddressFromMnemonic = function (mnemonic, legacy) {
if (legacy === void 0) { legacy = false; }
var derivationPath = legacy ? DERIVATION_PATH_LEGACY : DERIVATION_PATH;
var masterKey = sig.createMasterKeyFromMnemonic(mnemonic);
var keyPair = sig.createKeyPairFromMasterKey(masterKey, derivationPath);
return sig.createAddress(keyPair.publicKey, KAVA_PREFIX);

@@ -36,4 +37,4 @@ };

*/
const decodeAddress = (value) => {
const decodeAddress = bech32_1.default.decode(value);
var decodeAddress = function (value) {
var decodeAddress = bech32_1.default.decode(value);
return Buffer.from(bech32_1.default.fromWords(decodeAddress.words));

@@ -47,3 +48,3 @@ };

*/
const checkAddress = (address, hrp) => {
var checkAddress = function (address, hrp) {
try {

@@ -53,4 +54,4 @@ if (!address.startsWith(hrp)) {

}
const decodedAddress = bech32_1.default.decode(address);
const decodedAddressLength = decodeAddress(address).length;
var decodedAddress = bech32_1.default.decode(address);
var decodedAddressLength = decodeAddress(address).length;
if (decodedAddressLength === DECODED_ADDRESS_LEN &&

@@ -67,6 +68,6 @@ decodedAddress.prefix === hrp) {

exports.crypto = {
generateMnemonic,
getAddressFromMnemonic,
decodeAddress,
checkAddress,
generateMnemonic: generateMnemonic,
getAddressFromMnemonic: getAddressFromMnemonic,
decodeAddress: decodeAddress,
checkAddress: checkAddress,
};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.KavaClient = exports.crypto = exports.utils = exports.msg = exports.tx = void 0;
const tx_1 = require("./tx");
var tx_1 = require("./tx");
Object.defineProperty(exports, "tx", { enumerable: true, get: function () { return tx_1.tx; } });
const msg_1 = require("./msg");
var msg_1 = require("./msg");
Object.defineProperty(exports, "msg", { enumerable: true, get: function () { return msg_1.msg; } });
const utils_1 = require("./utils");
var utils_1 = require("./utils");
Object.defineProperty(exports, "utils", { enumerable: true, get: function () { return utils_1.utils; } });
const crypto_1 = require("./crypto");
var crypto_1 = require("./crypto");
Object.defineProperty(exports, "crypto", { enumerable: true, get: function () { return crypto_1.crypto; } });
const client_1 = require("./client");
var client_1 = require("./client");
Object.defineProperty(exports, "KavaClient", { enumerable: true, get: function () { return client_1.KavaClient; } });
const Kava = {
var Kava = {
tx: tx_1.tx,

@@ -16,0 +16,0 @@ msg: msg_1.msg,

@@ -6,9 +6,9 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const _1 = __importDefault(require("./"));
const _2 = require("./");
describe('SDK exports', () => {
it('should export Kava as a default', () => {
var _1 = __importDefault(require("./"));
var _2 = require("./");
describe('SDK exports', function () {
it('should export Kava as a default', function () {
expect(_1.default).toBeDefined();
});
it('should contain expected modules', () => {
it('should contain expected modules', function () {
expect(_1.default.utils).toBeDefined();

@@ -19,3 +19,3 @@ expect(_1.default.tx).toBeDefined();

});
it('should export each module individually', () => {
it('should export each module individually', function () {
expect(_2.utils).toBeDefined();

@@ -22,0 +22,0 @@ expect(_2.tx).toBeDefined();

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cosmos = void 0;
const FEE_DEFAULT = { amount: [], gas: '300000' };
var FEE_DEFAULT = { amount: [], gas: '300000' };
/**

@@ -13,3 +13,6 @@ * Creates a new StdTx from some messages with a default fee

*/
function newStdTx(msgs, fee = FEE_DEFAULT, memo = '', signatures = null) {
function newStdTx(msgs, fee, memo, signatures) {
if (fee === void 0) { fee = FEE_DEFAULT; }
if (memo === void 0) { memo = ''; }
if (signatures === void 0) { signatures = null; }
return {

@@ -27,3 +30,3 @@ type: 'cosmos-sdk/StdTx',

function newMsgSend(address, to, coins) {
const sendTx = {
var sendTx = {
type: 'cosmos-sdk/MsgSend',

@@ -33,3 +36,5 @@ value: {

to_address: to,
amount: coins.sort((coinA, coinB) => coinA.denom > coinB.denom ? 1 : -1),
amount: coins.sort(function (coinA, coinB) {
return coinA.denom > coinB.denom ? 1 : -1;
}),
},

@@ -50,5 +55,5 @@ };

exports.cosmos = {
newStdTx,
newMsgSend,
newMsgVoteGovernance,
newStdTx: newStdTx,
newMsgSend: newMsgSend,
newMsgVoteGovernance: newMsgVoteGovernance,
};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = require(".");
describe('Cosmos messages', () => {
describe('newMsgSend', () => {
it('should sort the coins passed in by denom', () => {
const coins = [
var _1 = require(".");
describe('Cosmos messages', function () {
describe('newMsgSend', function () {
it('should sort the coins passed in by denom', function () {
var coins = [
{

@@ -25,3 +25,3 @@ denom: 'ukava',

];
const message = _1.cosmos.newMsgSend('kavafrom', 'kavato', coins);
var message = _1.cosmos.newMsgSend('kavafrom', 'kavato', coins);
expect(message).toStrictEqual({

@@ -28,0 +28,0 @@ type: 'cosmos-sdk/MsgSend',

@@ -51,7 +51,7 @@ "use strict";

exports.hard = {
newMsgDeposit,
newMsgWithdraw,
newMsgBorrow,
newMsgRepay,
newMsgLiquidate,
newMsgDeposit: newMsgDeposit,
newMsgWithdraw: newMsgWithdraw,
newMsgBorrow: newMsgBorrow,
newMsgRepay: newMsgRepay,
newMsgLiquidate: newMsgLiquidate,
};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.msg = void 0;
const cosmos_1 = require("./cosmos");
const kava_1 = require("./kava");
const hard_1 = require("./hard");
const swap_1 = require("./swap");
var cosmos_1 = require("./cosmos");
var kava_1 = require("./kava");
var hard_1 = require("./hard");
var swap_1 = require("./swap");
exports.msg = {

@@ -9,0 +9,0 @@ cosmos: cosmos_1.cosmos,

@@ -292,28 +292,28 @@ "use strict";

exports.kava = {
newMsgPlaceBid,
newMsgCreateAtomicSwap,
newMsgClaimAtomicSwap,
newMsgRefundAtomicSwap,
newMsgCreateCDP,
newMsgDeposit,
newMsgWithdraw,
newMsgDrawDebt,
newMsgRepayDebt,
newMsgLiquidate,
newMsgSubmitProposal,
newMsgVote,
newMsgClaimUSDXMintingReward,
newMsgClaimUSDXMintingRewardVVesting,
newMsgClaimHardReward,
newMsgClaimHardRewardVVesting,
newMsgClaimDelegatorReward,
newMsgClaimDelegatorRewardVVesting,
newMsgClaimSwapReward,
newMsgClaimSwapRewardVVesting,
newMsgIssueTokens,
newMsgRedeemTokens,
newMsgBlockAddress,
newMsgUnblockAddress,
newMsgSetPauseStatus,
newMsgPostPrice,
newMsgPlaceBid: newMsgPlaceBid,
newMsgCreateAtomicSwap: newMsgCreateAtomicSwap,
newMsgClaimAtomicSwap: newMsgClaimAtomicSwap,
newMsgRefundAtomicSwap: newMsgRefundAtomicSwap,
newMsgCreateCDP: newMsgCreateCDP,
newMsgDeposit: newMsgDeposit,
newMsgWithdraw: newMsgWithdraw,
newMsgDrawDebt: newMsgDrawDebt,
newMsgRepayDebt: newMsgRepayDebt,
newMsgLiquidate: newMsgLiquidate,
newMsgSubmitProposal: newMsgSubmitProposal,
newMsgVote: newMsgVote,
newMsgClaimUSDXMintingReward: newMsgClaimUSDXMintingReward,
newMsgClaimUSDXMintingRewardVVesting: newMsgClaimUSDXMintingRewardVVesting,
newMsgClaimHardReward: newMsgClaimHardReward,
newMsgClaimHardRewardVVesting: newMsgClaimHardRewardVVesting,
newMsgClaimDelegatorReward: newMsgClaimDelegatorReward,
newMsgClaimDelegatorRewardVVesting: newMsgClaimDelegatorRewardVVesting,
newMsgClaimSwapReward: newMsgClaimSwapReward,
newMsgClaimSwapRewardVVesting: newMsgClaimSwapRewardVVesting,
newMsgIssueTokens: newMsgIssueTokens,
newMsgRedeemTokens: newMsgRedeemTokens,
newMsgBlockAddress: newMsgBlockAddress,
newMsgUnblockAddress: newMsgUnblockAddress,
newMsgSetPauseStatus: newMsgSetPauseStatus,
newMsgPostPrice: newMsgPostPrice,
};

@@ -53,6 +53,6 @@ "use strict";

exports.swap = {
newMsgDeposit,
newMsgWithdraw,
newMsgSwapExactForTokens,
newMsgSwapForExactTokens,
newMsgDeposit: newMsgDeposit,
newMsgWithdraw: newMsgWithdraw,
newMsgSwapExactForTokens: newMsgSwapExactForTokens,
newMsgSwapForExactTokens: newMsgSwapForExactTokens,
};
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -7,6 +43,6 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

exports.tx = void 0;
const sig = require('@kava-labs/sig');
const axios_1 = __importDefault(require("axios"));
const url_1 = require("url");
const api = {
var sig = require('@kava-labs/sig');
var axios_1 = __importDefault(require("axios"));
var url_1 = require("url");
var api = {
getAccount: '/auth/accounts',

@@ -21,10 +57,23 @@ postTx: '/txs',

*/
async function getTx(path, base, timeout = 5000, args = {}) {
const requestUrl = new url_1.URL(path, base).toString();
try {
return await retry(axios_1.default.get, axios_1.default, [applyRequestArgs(requestUrl, args)], Math.floor(timeout / 1000), 1000, false);
}
catch (err) {
throw err;
}
function getTx(path, base, timeout, args) {
if (timeout === void 0) { timeout = 5000; }
if (args === void 0) { args = {}; }
return __awaiter(this, void 0, void 0, function () {
var requestUrl, err_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
requestUrl = new url_1.URL(path, base).toString();
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, retry(axios_1.default.get, axios_1.default, [applyRequestArgs(requestUrl, args)], Math.floor(timeout / 1000), 1000, false)];
case 2: return [2 /*return*/, _a.sent()];
case 3:
err_1 = _a.sent();
throw err_1;
case 4: return [2 /*return*/];
}
});
});
}

@@ -37,8 +86,9 @@ /**

*/
function applyRequestArgs(url, args = {}) {
const search = [];
for (let k in args) {
search.push(`${k}=${args[k]}`);
function applyRequestArgs(url, args) {
if (args === void 0) { args = {}; }
var search = [];
for (var k in args) {
search.push(k + "=" + args[k]);
}
return `${url}?${search.join('&')}`;
return url + "?" + search.join('&');
}

@@ -57,16 +107,29 @@ /**

*/
const retry = async (fn, thisArg, args, retriesLeft = 5, interval = 1000, exponential = false) => {
try {
const result = await fn.apply(thisArg, args);
return result;
}
catch (error) {
if (retriesLeft) {
await new Promise((r) => setTimeout(r, interval));
return retry(fn, thisArg, args, retriesLeft - 1, exponential ? interval * 2 : interval, exponential);
}
else
throw new Error(`Max retries reached:
error: ${error}`);
}
var retry = function (fn, thisArg, args, retriesLeft, interval, exponential) {
if (retriesLeft === void 0) { retriesLeft = 5; }
if (interval === void 0) { interval = 1000; }
if (exponential === void 0) { exponential = false; }
return __awaiter(void 0, void 0, void 0, function () {
var result, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 6]);
return [4 /*yield*/, fn.apply(thisArg, args)];
case 1:
result = _a.sent();
return [2 /*return*/, result];
case 2:
error_1 = _a.sent();
if (!retriesLeft) return [3 /*break*/, 4];
return [4 /*yield*/, new Promise(function (r) { return setTimeout(r, interval); })];
case 3:
_a.sent();
return [2 /*return*/, retry(fn, thisArg, args, retriesLeft - 1, exponential ? interval * 2 : interval, exponential)];
case 4: throw new Error("Max retries reached:\n error: " + error_1);
case 5: return [3 /*break*/, 6];
case 6: return [2 /*return*/];
}
});
});
};

@@ -80,15 +143,27 @@ /**

*/
async function loadMetaData(address, base, timeout = 2000) {
const path = api.getAccount + '/' + address;
const res = await getTx(path, base, timeout);
const accNum = res?.data?.result?.value?.account_number;
const seqNum = res?.data?.result?.value?.sequence;
if (!(accNum || seqNum)) {
throw new Error('account number or sequence number from rest server are undefined');
}
const signMetaData = {
account_number: accNum,
sequence: seqNum,
};
return signMetaData;
function loadMetaData(address, base, timeout) {
var _a, _b, _c, _d, _e, _f;
if (timeout === void 0) { timeout = 2000; }
return __awaiter(this, void 0, void 0, function () {
var path, res, accNum, seqNum, signMetaData;
return __generator(this, function (_g) {
switch (_g.label) {
case 0:
path = api.getAccount + '/' + address;
return [4 /*yield*/, getTx(path, base, timeout)];
case 1:
res = _g.sent();
accNum = (_c = (_b = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.account_number;
seqNum = (_f = (_e = (_d = res === null || res === void 0 ? void 0 : res.data) === null || _d === void 0 ? void 0 : _d.result) === null || _e === void 0 ? void 0 : _e.value) === null || _f === void 0 ? void 0 : _f.sequence;
if (!(accNum || seqNum)) {
throw new Error('account number or sequence number from rest server are undefined');
}
signMetaData = {
account_number: accNum,
sequence: seqNum,
};
return [2 /*return*/, signMetaData];
}
});
});
}

@@ -116,23 +191,35 @@ /**

*/
async function broadcastTx(tx, base, mode) {
let txRes;
try {
const url = new url_1.URL(api.postTx, base).toString();
txRes = await axios_1.default.post(url, sig.createBroadcastTx(tx.value, mode));
}
catch (err) {
if (axios_1.default.isAxiosError(err)) {
logErr(err);
}
}
// Check for and handle any tendermint errors
try {
if (txRes?.data?.code) {
throw new Error(`tx not accepted by chain: ${txRes.data.raw_log}`);
}
}
catch (err) {
return err;
}
return txRes?.data?.txhash;
function broadcastTx(tx, base, mode) {
var _a, _b;
return __awaiter(this, void 0, void 0, function () {
var txRes, url, err_2;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
_c.trys.push([0, 2, , 3]);
url = new url_1.URL(api.postTx, base).toString();
return [4 /*yield*/, axios_1.default.post(url, sig.createBroadcastTx(tx.value, mode))];
case 1:
txRes = _c.sent();
return [3 /*break*/, 3];
case 2:
err_2 = _c.sent();
if (axios_1.default.isAxiosError(err_2)) {
logErr(err_2);
}
return [3 /*break*/, 3];
case 3:
// Check for and handle any tendermint errors
try {
if ((_a = txRes === null || txRes === void 0 ? void 0 : txRes.data) === null || _a === void 0 ? void 0 : _a.code) {
throw new Error("tx not accepted by chain: " + txRes.data.raw_log);
}
}
catch (err) {
return [2 /*return*/, err];
}
return [2 /*return*/, (_b = txRes === null || txRes === void 0 ? void 0 : txRes.data) === null || _b === void 0 ? void 0 : _b.txhash];
}
});
});
}

@@ -143,7 +230,8 @@ /**

*/
const logErr = (err) => {
var logErr = function (err) {
var _a, _b, _c;
// Load status, status text, and error
const status = err.response?.status;
const statusText = err.response?.statusText;
const error = err.response?.data.error;
var status = (_a = err.response) === null || _a === void 0 ? void 0 : _a.status;
var statusText = (_b = err.response) === null || _b === void 0 ? void 0 : _b.statusText;
var error = (_c = err.response) === null || _c === void 0 ? void 0 : _c.data.error;
// Log status, status text, and error, or if unidentified, log network error

@@ -158,7 +246,7 @@ status ? console.log('Status:', status) : null;

exports.tx = {
getTx,
loadMetaData,
signTx,
broadcastTx,
logErr,
getTx: getTx,
loadMetaData: loadMetaData,
signTx: signTx,
broadcastTx: broadcastTx,
logErr: logErr,
};

@@ -7,10 +7,10 @@ "use strict";

exports.utils = void 0;
const sha256_1 = __importDefault(require("crypto-js/sha256"));
const enc_hex_1 = __importDefault(require("crypto-js/enc-hex"));
const big_js_1 = __importDefault(require("big.js"));
const crypto_1 = __importDefault(require("crypto"));
const crypto_2 = require("../crypto");
const RandomNumberLength = 64;
var sha256_1 = __importDefault(require("crypto-js/sha256"));
var enc_hex_1 = __importDefault(require("crypto-js/enc-hex"));
var big_js_1 = __importDefault(require("big.js"));
var crypto_1 = __importDefault(require("crypto"));
var crypto_2 = require("../crypto");
var RandomNumberLength = 64;
// Precision is relative to KAVA or 10**6
const precision = {
var precision = {
kava: 1,

@@ -24,8 +24,8 @@ ukava: Math.pow(10, 6),

*/
const sha256 = (hex) => {
var sha256 = function (hex) {
if (typeof hex !== 'string')
throw new Error('sha256 expects a hex string');
if (hex.length % 2 !== 0)
throw new Error(`invalid hex string length: ${hex}`);
const hexEncoded = enc_hex_1.default.parse(hex);
throw new Error("invalid hex string length: " + hex);
var hexEncoded = enc_hex_1.default.parse(hex);
return (0, sha256_1.default)(hexEncoded).toString();

@@ -37,3 +37,3 @@ };

*/
const generateRandomNumber = () => {
var generateRandomNumber = function () {
return crypto_1.default

@@ -50,10 +50,10 @@ .randomBytes(Math.ceil(RandomNumberLength / 2))

*/
const calculateRandomNumberHash = (randomNumber, timestamp) => {
const timestampHexStr = timestamp.toString(16);
let timestampHexStrFormat = timestampHexStr;
for (let i = 0; i < 16 - timestampHexStr.length; i++) {
var calculateRandomNumberHash = function (randomNumber, timestamp) {
var timestampHexStr = timestamp.toString(16);
var timestampHexStrFormat = timestampHexStr;
for (var i = 0; i < 16 - timestampHexStr.length; i++) {
timestampHexStrFormat = '0' + timestampHexStrFormat;
}
const timestampBytes = Buffer.from(timestampHexStrFormat, 'hex');
const newBuffer = Buffer.concat([
var timestampBytes = Buffer.from(timestampHexStrFormat, 'hex');
var newBuffer = Buffer.concat([
Buffer.from(randomNumber, 'hex'),

@@ -71,7 +71,7 @@ timestampBytes,

*/
const calculateSwapID = (randomNumberHash, sender, senderOtherChain) => {
const randomNumberHashBytes = Buffer.from(randomNumberHash, 'hex');
const senderBytes = crypto_2.crypto.decodeAddress(sender);
const sendOtherChainBytes = Buffer.from(senderOtherChain.toLowerCase(), 'utf8');
const newBuffer = Buffer.concat([
var calculateSwapID = function (randomNumberHash, sender, senderOtherChain) {
var randomNumberHashBytes = Buffer.from(randomNumberHash, 'hex');
var senderBytes = crypto_2.crypto.decodeAddress(sender);
var sendOtherChainBytes = Buffer.from(senderOtherChain.toLowerCase(), 'utf8');
var newBuffer = Buffer.concat([
randomNumberHashBytes,

@@ -90,4 +90,4 @@ senderBytes,

*/
const convertCoinDecimals = (inputAmount, inputDenom, outputDenom) => {
const amount = new big_js_1.default(inputAmount);
var convertCoinDecimals = function (inputAmount, inputDenom, outputDenom) {
var amount = new big_js_1.default(inputAmount);
try {

@@ -104,3 +104,3 @@ if (!precision[inputDenom] || !precision[outputDenom]) {

}
const amountString = amount
var amountString = amount
.mul(precision[outputDenom])

@@ -117,3 +117,3 @@ .div(precision[inputDenom])

*/
const formatCoin = (amount, denom) => {
var formatCoin = function (amount, denom) {
return {

@@ -130,3 +130,3 @@ denom: String(denom),

*/
const formatCoins = (amount, denom) => {
var formatCoins = function (amount, denom) {
return [

@@ -145,3 +145,3 @@ {

*/
const formatMultiCoins = (amounts, denoms) => {
var formatMultiCoins = function (amounts, denoms) {
try {

@@ -160,3 +160,3 @@ if (amounts.length != denoms.length) {

for (var i = 0; i < amounts.length; i++) {
let coin = formatCoin(amounts[i], denoms[i]);
var coin = formatCoin(amounts[i], denoms[i]);
coins.push(coin);

@@ -171,14 +171,15 @@ }

*/
const calculateUnixTime = (seconds = 86400) => {
var calculateUnixTime = function (seconds) {
if (seconds === void 0) { seconds = 86400; }
return String(Math.floor(Date.now() / 1000) + seconds);
};
exports.utils = {
generateRandomNumber,
calculateRandomNumberHash,
calculateSwapID,
calculateUnixTime,
convertCoinDecimals,
formatCoin,
formatCoins,
formatMultiCoins,
generateRandomNumber: generateRandomNumber,
calculateRandomNumberHash: calculateRandomNumberHash,
calculateSwapID: calculateSwapID,
calculateUnixTime: calculateUnixTime,
convertCoinDecimals: convertCoinDecimals,
formatCoin: formatCoin,
formatCoins: formatCoins,
formatMultiCoins: formatMultiCoins,
};
{
"name": "@kava-labs/javascript-sdk",
"version": "5.3.0",
"version": "5.3.1",
"description": "Supports interaction with the Kava blockchain via a REST api",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -8,4 +8,3 @@ {

"module": "commonjs",
"target": "es2020",
"target": "es5",
"declaration": true,

@@ -12,0 +11,0 @@ "esModuleInterop": true,

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc