Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update farm module #243

Merged
merged 2 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"test": "yarn run node && jest -i --config jest.config.js && sh test/scripts/clean.sh",
"check": "gts check",
"clean": "gts clean",
"build": "rm -rf dist/* && tsc --emitDeclarationOnly && babel --extensions '.ts' src -d dist/src && cp LICENSE dist/ && cp README.md dist/ && cp package.json dist/ && cp -rf src/types/proto-types dist/src/types/proto-types",
"build": "rm -rf dist/* && tsc --emitDeclarationOnly && babel --extensions .ts src -d dist/src && cp LICENSE dist/ && cp README.md dist/ && cp package.json dist/ && cp -rf src/types/proto-types dist/src/types/proto-types",
"buildForWindows": "rm -rf dist/* && tsc --emitDeclarationOnly && babel --extensions .ts src -d dist/src && cp LICENSE dist/ && cp README.md dist/ && cp package.json dist/ && cp -rf src/types/proto-types dist/src/types/proto-types",
"fix": "gts fix",
"docs": "npx typedoc && docker build -t irisnet/docs-irishub-sdk-js .",
Expand Down
8 changes: 4 additions & 4 deletions dist/src/modules/farm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ export declare class Farm {
constructor(client: Client);
/**
* stake lpt
* @param farmPoolName farm pool name
* @param farmPoolID farm pool ID
* @param lpt receive Lp
* @param baseTx { types.BaseTx }
* @returns
*/
stakeLp(pool_name: string, amount: types.Coin, baseTx: BaseTx): Promise<types.TxResult>;
stakeLp(pool_id: string, amount: types.Coin, baseTx: BaseTx): Promise<types.TxResult>;
/**
* unstake lpt
* @param farmPoolName farm pool name
* @param lpt receive Lp
* @param baseTx { types.BaseTx }
* @returns
*/
unStakeLp(pool_name: string, amount: types.Coin, baseTx: BaseTx): Promise<types.TxResult>;
unStakeLp(pool_id: string, amount: types.Coin, baseTx: BaseTx): Promise<types.TxResult>;
/**
* harvest lpt
* @param farmPoolName farm pool name
* @param baseTx { types.BaseTx }
* @returns
*/
harvestReward(pool_name: string, baseTx: BaseTx): Promise<types.TxResult>;
harvestReward(pool_id: string, baseTx: BaseTx): Promise<types.TxResult>;
}
14 changes: 7 additions & 7 deletions dist/src/modules/farm.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var Farm = /*#__PURE__*/function () {
}
/**
* stake lpt
* @param farmPoolName farm pool name
* @param farmPoolID farm pool ID
* @param lpt receive Lp
* @param baseTx { types.BaseTx }
* @returns
Expand All @@ -46,7 +46,7 @@ var Farm = /*#__PURE__*/function () {
(0, _createClass2["default"])(Farm, [{
key: "stakeLp",
value: function () {
var _stakeLp = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(pool_name, amount, baseTx) {
var _stakeLp = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(pool_id, amount, baseTx) {
var sender, msgs;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
Expand All @@ -56,7 +56,7 @@ var Farm = /*#__PURE__*/function () {
msgs = [{
type: types.TxType.MsgStake,
value: {
pool_name: pool_name,
pool_id: pool_id,
amount: amount,
sender: sender
}
Expand Down Expand Up @@ -88,7 +88,7 @@ var Farm = /*#__PURE__*/function () {
* @returns
*/
function () {
var _unStakeLp = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(pool_name, amount, baseTx) {
var _unStakeLp = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(pool_id, amount, baseTx) {
var sender, msgs;
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) {
Expand All @@ -98,7 +98,7 @@ var Farm = /*#__PURE__*/function () {
msgs = [{
type: types.TxType.MsgUnstake,
value: {
pool_name: pool_name,
pool_id: pool_id,
amount: amount,
sender: sender
}
Expand Down Expand Up @@ -129,7 +129,7 @@ var Farm = /*#__PURE__*/function () {
}, {
key: "harvestReward",
value: function () {
var _harvestReward = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(pool_name, baseTx) {
var _harvestReward = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(pool_id, baseTx) {
var sender, msgs;
return _regenerator["default"].wrap(function _callee3$(_context3) {
while (1) {
Expand All @@ -139,7 +139,7 @@ var Farm = /*#__PURE__*/function () {
msgs = [{
type: types.TxType.MsgHarvest,
value: {
pool_name: pool_name,
pool_id: pool_id,
sender: sender
}
}];
Expand Down
6 changes: 3 additions & 3 deletions dist/src/types/farm.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Coin, Msg } from "./types";
export interface FarmParams {
pool_name: string;
pool_id: string;
amount: Coin;
sender: string;
}
Expand Down Expand Up @@ -29,11 +29,11 @@ export declare class MsgUnstake extends Msg {
validate(): void;
}
export interface HarvestParams {
pool_name: string;
pool_id: string;
sender: string;
}
/**
* Msg for Unstake lp
* Msg for harvest reward
*
* @hidden
*/
Expand Down
20 changes: 10 additions & 10 deletions dist/src/types/farm.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ var MsgStake = /*#__PURE__*/function (_Msg) {
key: "getModel",
value: function getModel() {
var msg = new (this.constructor.getModelClass())();
msg.setPoolName(this.value.pool_name);
msg.setPoolName(this.value.pool_id);
msg.setAmount(_helper.TxModelCreator.createCoinModel(this.value.amount.denom, this.value.amount.amount));
msg.setSender(this.value.sender);
return msg;
}
}, {
key: "validate",
value: function validate() {
if (!this.value.pool_name) {
throw new _errors.SdkError("pool_name is empty");
if (!this.value.pool_id) {
throw new _errors.SdkError("pool_id is empty");
}

if (!this.value.amount) {
Expand Down Expand Up @@ -119,16 +119,16 @@ var MsgUnstake = /*#__PURE__*/function (_Msg2) {
key: "getModel",
value: function getModel() {
var msg = new (this.constructor.getModelClass())();
msg.setPoolName(this.value.pool_name);
msg.setPoolName(this.value.pool_id);
msg.setAmount(_helper.TxModelCreator.createCoinModel(this.value.amount.denom, this.value.amount.amount));
msg.setSender(this.value.sender);
return msg;
}
}, {
key: "validate",
value: function validate() {
if (!this.value.pool_name) {
throw new _errors.SdkError("pool_name is empty");
if (!this.value.pool_id) {
throw new _errors.SdkError("pool_id is empty");
}

if (!this.value.amount) {
Expand All @@ -151,7 +151,7 @@ var MsgUnstake = /*#__PURE__*/function (_Msg2) {
exports.MsgUnstake = MsgUnstake;

/**
* Msg for Unstake lp
* Msg for harvest reward
*
* @hidden
*/
Expand All @@ -174,15 +174,15 @@ var MsgHarvest = /*#__PURE__*/function (_Msg3) {
key: "getModel",
value: function getModel() {
var msg = new (this.constructor.getModelClass())();
msg.setPoolName(this.value.pool_name);
msg.setPoolName(this.value.pool_id);
msg.setSender(this.value.sender);
return msg;
}
}, {
key: "validate",
value: function validate() {
if (!this.value.pool_name) {
throw new _errors.SdkError("pool_name is empty");
if (!this.value.pool_id) {
throw new _errors.SdkError("pool_id is empty");
}

if (!this.value.sender) {
Expand Down
14 changes: 7 additions & 7 deletions src/modules/farm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export class Farm {
}
/**
* stake lpt
* @param farmPoolName farm pool name
* @param farmPoolID farm pool ID
* @param lpt receive Lp
* @param baseTx { types.BaseTx }
* @returns
*/
async stakeLp(
pool_name:string,
pool_id:string,
amount:types.Coin,
baseTx:BaseTx
):Promise<types.TxResult>{
Expand All @@ -27,7 +27,7 @@ export class Farm {
{
type:types.TxType.MsgStake,
value:{
pool_name,
pool_id,
amount,
sender
}
Expand All @@ -43,7 +43,7 @@ export class Farm {
* @returns
*/
async unStakeLp(
pool_name:string,
pool_id:string,
amount:types.Coin,
baseTx:BaseTx
):Promise<types.TxResult>{
Expand All @@ -52,7 +52,7 @@ export class Farm {
{
type:types.TxType.MsgUnstake,
value:{
pool_name,
pool_id,
amount,
sender
}
Expand All @@ -67,15 +67,15 @@ export class Farm {
* @returns
*/
async harvestReward(
pool_name:string,
pool_id:string,
baseTx:BaseTx
):Promise<types.TxResult>{
const sender = this.client.keys.show(baseTx.from)
const msgs:any[] = [
{
type:types.TxType.MsgHarvest,
value:{
pool_name,
pool_id,
sender
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/types/farm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {TxModelCreator} from "../helper";


export interface FarmParams {
pool_name: string,
pool_id: string,
amount: Coin,
sender: string
}
Expand All @@ -32,15 +32,15 @@ export class MsgStake extends Msg {

getModel(): any {
let msg = new ((this.constructor as any).getModelClass())();
msg.setPoolName(this.value.pool_name);
msg.setPoolName(this.value.pool_id);
msg.setAmount(TxModelCreator.createCoinModel(this.value.amount.denom, this.value.amount.amount));
msg.setSender(this.value.sender);
return msg;
}

validate() {
if (!this.value.pool_name) {
throw new SdkError("pool_name is empty");
if (!this.value.pool_id) {
throw new SdkError("pool_id is empty");
}
if (!this.value.amount) {
throw new SdkError("amount is empty");
Expand Down Expand Up @@ -71,15 +71,15 @@ export class MsgUnstake extends Msg {

getModel(): any {
let msg = new ((this.constructor as any).getModelClass())();
msg.setPoolName(this.value.pool_name);
msg.setPoolName(this.value.pool_id);
msg.setAmount(TxModelCreator.createCoinModel(this.value.amount.denom, this.value.amount.amount));
msg.setSender(this.value.sender);
return msg;
}

validate() {
if (!this.value.pool_name) {
throw new SdkError("pool_name is empty");
if (!this.value.pool_id) {
throw new SdkError("pool_id is empty");
}
if (!this.value.amount) {
throw new SdkError("amount is empty");
Expand All @@ -91,12 +91,12 @@ export class MsgUnstake extends Msg {
}

export interface HarvestParams {
pool_name: string,
pool_id: string,
sender: string
}

/**
* Msg for Unstake lp
* Msg for harvest reward
*
* @hidden
*/
Expand All @@ -115,14 +115,14 @@ export class MsgHarvest extends Msg {

getModel(): any {
let msg = new ((this.constructor as any).getModelClass())();
msg.setPoolName(this.value.pool_name);
msg.setPoolName(this.value.pool_id);
msg.setSender(this.value.sender);
return msg;
}

validate() {
if (!this.value.pool_name) {
throw new SdkError("pool_name is empty");
if (!this.value.pool_id) {
throw new SdkError("pool_id is empty");
}
if (!this.value.sender) {
throw new SdkError("sender is empty");
Expand Down
8 changes: 4 additions & 4 deletions test/basetest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ export class BaseTest {

static getClient(): Client {
let config = {
node: 'http://192.168.150.40:26657',
node: 'http://192.168.150.33:26657',
chainNetwork: iris.types.ChainNetwork.Iris,
chainId: 'iris',
gas: '20000000',
fee: { denom: 'udev', amount: '200' },
fee: { denom: 'uiris', amount: '200' },
};
let privateKey = '1E120611404C4B1B98FC899A8026A6A9823C35985DA3C5ED3FF57C170C822F60'
// let privateKey = '1E120611404C4B1B98FC899A8026A6A9823C35985DA3C5ED3FF57C170C822F60'

// let config = {
// node: 'http://34.80.22.255:26657',
Expand All @@ -56,7 +56,7 @@ export class BaseTest {
client.keys.recover(
Consts.keyName,
Consts.keyPassword,
'emerge faculty front embark salute ring broken canyon vibrant arena pair truck joy credit milk tube vast private double exercise change drip lemon time'
'razor educate ostrich pave permit comic collect square believe decade scan day frozen language make winter lyrics spice dawn deliver jaguar arrest decline success'
);

// client.keys.importPrivateKey(
Expand Down
12 changes: 6 additions & 6 deletions test/coinswap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ describe('Coinswap Tests', () => {
await BaseTest.getClient()
.coinswap.addLiquidity(
{
denom: 'htltbcbnb',
amount: '1000000',
denom: 'ubusd',
amount: '100000000',
}, "1000", "1",
parseInt(deadlineTime),
BaseTest.baseTx
Expand Down Expand Up @@ -61,13 +61,13 @@ describe('Coinswap Tests', () => {
await BaseTest.getClient()
.coinswap.swapOrder(
{
denom: 'udev',
denom: 'uiris',
amount: '10000000',
}, {
denom: 'htltbcbnb',
amount: '684534',
denom: 'ubusd',
amount: '100',
}, false,
1630493041,
1646636997,
BaseTest.baseTx
)
.then(res => {
Expand Down
Loading