Skip to content

Commit

Permalink
Merge pull request #99 from mangata-finance/rc/2.1.0
Browse files Browse the repository at this point in the history
chore: release 2.1.0
  • Loading branch information
devdanco authored Oct 12, 2023
2 parents cc6e643 + 198f475 commit 17f4fd2
Show file tree
Hide file tree
Showing 26 changed files with 783 additions and 528 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Setup Node version and cache dependencies
uses: actions/setup-node@v3
with:
node-version: "16"
node-version: "18"
cache: "yarn"

- name: Install WASM toolchain
Expand Down
16 changes: 2 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Setup Node version and cache dependencies
uses: actions/setup-node@v3
with:
node-version: "16"
node-version: "18"
cache: "yarn"

- name: Install deps
Expand All @@ -42,22 +42,10 @@ jobs:
GITHUB_TOKEN: ${{ secrets.FE_TOKEN }}

- name: Generate docs
run: npx typedoc src/index.ts
run: npx typedoc src/index.ts --skipErrorChecking

- name: Deploy github page for doc 🚀
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages # The branch the action should deploy to.
folder: docs # The folder the action should deploy.

- name: Sleep for 1 minute
run: sleep 60s

- name: Merge main -> develop
uses: devmasx/merge-branch@master
with:
type: now
from_branch: main
target_branch: develop
message: Merge main into develop
github_token: ${{ secrets.FE_TOKEN }}
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
# [2.1.0-rc.4](https://github.com/mangata-finance/mangata-sdk/compare/v2.1.0-rc.3...v2.1.0-rc.4) (2023-10-12)


### Bug Fixes

* remove testing logs ([970bb67](https://github.com/mangata-finance/mangata-sdk/commit/970bb67f3f6d8e72f971d5a012583daf5e6aa68e))

# [2.1.0-rc.3](https://github.com/mangata-finance/mangata-sdk/compare/v2.1.0-rc.2...v2.1.0-rc.3) (2023-10-10)


### Bug Fixes

* add logger to withdraw method ([d581e57](https://github.com/mangata-finance/mangata-sdk/commit/d581e5702cfe134f3c5ea7591d839e848da6b78d))

# [2.1.0-rc.2](https://github.com/mangata-finance/mangata-sdk/compare/v2.1.0-rc.1...v2.1.0-rc.2) (2023-10-09)


### Bug Fixes

* relative paths ([3d404e5](https://github.com/mangata-finance/mangata-sdk/commit/3d404e50078ee0053eefee8751ab408591cbf6e6))

# [2.1.0-rc.1](https://github.com/mangata-finance/mangata-sdk/compare/v2.0.0...v2.1.0-rc.1) (2023-09-25)


### Features

* update packages for types ([b98f348](https://github.com/mangata-finance/mangata-sdk/commit/b98f3486611d8f828f5648adcb8f25564acc4487))
* update types and rpc ([b4c0d4e](https://github.com/mangata-finance/mangata-sdk/commit/b4c0d4eb56b062e513a78994da35629cf36eda99))

# [2.0.0](https://github.com/mangata-finance/mangata-sdk/compare/v1.20.1...v2.0.0) (2023-09-20)


Expand Down
10 changes: 9 additions & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ declare type BurnAmount = {
firstAssetAmount: TokenAmount;
secondAssetAmount: TokenAmount;
};
declare type TradeAbleTokens = {
tokenId: string;
decimals: number;
name: string;
symbol: string;
};
declare type Rewards = {
address: Address;
liquidityTokenId: TokenId;
Expand Down Expand Up @@ -316,6 +322,8 @@ interface MangataInstance {
* rpc methods for interacting with various RPC operations.
*/
rpc: {
getLiquidityTokensForTrading: () => Promise<string[]>;
getTradeableTokens: () => Promise<TradeAbleTokens[]>;
isSellAssetLockFree: (tokendIds: TokenId[], amount: BN) => Promise<Boolean>;
isBuyAssetLockFree: (tokendIds: TokenId[], amount: BN) => Promise<Boolean>;
/**
Expand Down Expand Up @@ -686,4 +694,4 @@ declare const isSellAssetTransactionSuccessful: (events: MangataGenericEvent[])

declare const setLoggerOptions: (options?: ISettingsParam<ILogObj>) => void;

export { Account, ActivateLiquidityFee, Address, Asset, BIG_BILLION, BIG_HUNDRED, BIG_HUNDRED_BILLIONS, BIG_HUNDRED_MILLIONS, BIG_HUNDRED_THOUSAND, BIG_MILLION, BIG_ONE, BIG_TEN, BIG_TEN_BILLIONS, BIG_TEN_MILLIONS, BIG_TEN_THOUSAND, BIG_THOUSAND, BIG_TRILLION, BIG_ZERO, BN_BILLION, BN_DIV_NUMERATOR_MULTIPLIER, BN_DIV_NUMERATOR_MULTIPLIER_DECIMALS, BN_HUNDRED, BN_HUNDRED_BILLIONS, BN_HUNDRED_MILLIONS, BN_HUNDRED_THOUSAND, BN_MILLION, BN_ONE, BN_TEN, BN_TEN_BILLIONS, BN_TEN_MILLIONS, BN_TEN_THOUSAND, BN_THOUSAND, BN_TRILLION, BN_ZERO, Batch, BurnAmount, BurnLiquidity, BurnLiquidityFee, ClaimRewardsFee, CreatePool, CreatePoolFee, Database, DeactivateLiquidityFee, Deposit, DepositFromKusamaFee, DepositFromParachainFee, DepositFromStatemineFee, ErrorData, ExtrinsicCommon, FeeLockType, Liquidity, MainTokens, Mangata, MangataEventData, MangataGenericEvent, MangataInstance, MangataLoggerOptions, MangataSubmittableExtrinsic, MaxAmountIn, MinAmountOut, MintLiquidity, MintLiquidityFee, MoonriverWithdraw, MultiSwapBase, MultiswapBuyAsset, MultiswapSellAsset, Pool, PoolBase, PoolReserves, PoolWithRatio, PoolWithShare, Prettify, Price, PriceImpact, RelayDeposit, RelayWithdraw, Reserve, Rewards, Token, TokenAmount, TokenAmounts, TokenBalance, TokenDecimals, TokenId, TokenInfo, TokenSymbol, Transfer, TransferAllFee, TransferTokenFee, TransferTokens, TxOptions, Withdraw, WithdrawFee, WithdrawKsmFee, XcmTxOptions, fromBN, isBuyAssetTransactionSuccessful, isMultiSwapAssetTransactionSuccessful, isSellAssetTransactionSuccessful, setLoggerOptions, signTx, toBN, toFixed };
export { Account, ActivateLiquidityFee, Address, Asset, BIG_BILLION, BIG_HUNDRED, BIG_HUNDRED_BILLIONS, BIG_HUNDRED_MILLIONS, BIG_HUNDRED_THOUSAND, BIG_MILLION, BIG_ONE, BIG_TEN, BIG_TEN_BILLIONS, BIG_TEN_MILLIONS, BIG_TEN_THOUSAND, BIG_THOUSAND, BIG_TRILLION, BIG_ZERO, BN_BILLION, BN_DIV_NUMERATOR_MULTIPLIER, BN_DIV_NUMERATOR_MULTIPLIER_DECIMALS, BN_HUNDRED, BN_HUNDRED_BILLIONS, BN_HUNDRED_MILLIONS, BN_HUNDRED_THOUSAND, BN_MILLION, BN_ONE, BN_TEN, BN_TEN_BILLIONS, BN_TEN_MILLIONS, BN_TEN_THOUSAND, BN_THOUSAND, BN_TRILLION, BN_ZERO, Batch, BurnAmount, BurnLiquidity, BurnLiquidityFee, ClaimRewardsFee, CreatePool, CreatePoolFee, Database, DeactivateLiquidityFee, Deposit, DepositFromKusamaFee, DepositFromParachainFee, DepositFromStatemineFee, ErrorData, ExtrinsicCommon, FeeLockType, Liquidity, MainTokens, Mangata, MangataEventData, MangataGenericEvent, MangataInstance, MangataLoggerOptions, MangataSubmittableExtrinsic, MaxAmountIn, MinAmountOut, MintLiquidity, MintLiquidityFee, MoonriverWithdraw, MultiSwapBase, MultiswapBuyAsset, MultiswapSellAsset, Pool, PoolBase, PoolReserves, PoolWithRatio, PoolWithShare, Prettify, Price, PriceImpact, RelayDeposit, RelayWithdraw, Reserve, Rewards, Token, TokenAmount, TokenAmounts, TokenBalance, TokenDecimals, TokenId, TokenInfo, TokenSymbol, TradeAbleTokens, Transfer, TransferAllFee, TransferTokenFee, TransferTokens, TxOptions, Withdraw, WithdrawFee, WithdrawKsmFee, XcmTxOptions, fromBN, isBuyAssetTransactionSuccessful, isMultiSwapAssetTransactionSuccessful, isSellAssetTransactionSuccessful, setLoggerOptions, signTx, toBN, toFixed };
52 changes: 40 additions & 12 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3697,8 +3697,7 @@ var calculateRewardsAmount = async (instancePromise, args) => {
address,
liquidityTokenId
);
const price = isHex(rewards.price.toString()) ? hexToBn(rewards.price.toString()) : new import_bn.default(rewards.price);
return price;
return isHex(rewards.toString()) ? hexToBn(rewards.toString()) : new import_bn.default(rewards);
};

// src/methods/xyk/claimRewardsAll.ts
Expand Down Expand Up @@ -3743,12 +3742,12 @@ var calculateBuyPriceId = async (instancePromise, soldTokenId, boughtTokenId, am
amount: amount.toString()
});
const api = await instancePromise;
const result = await api.rpc.xyk.calculate_buy_price_id(
const price = await api.rpc.xyk.calculate_buy_price_id(
soldTokenId,
boughtTokenId,
amount
);
return new import_bn.default(result.price);
return new import_bn.default(price);
};

// src/methods/rpc/calculateSellPriceId.ts
Expand All @@ -3759,12 +3758,12 @@ var calculateSellPriceId = async (instancePromise, soldTokenId, boughtTokenId, a
amount: amount.toString()
});
const api = await instancePromise;
const result = await api.rpc.xyk.calculate_sell_price_id(
const price = await api.rpc.xyk.calculate_sell_price_id(
soldTokenId,
boughtTokenId,
amount
);
return new import_bn.default(result.price);
return new import_bn.default(price);
};

// src/methods/rpc/getBurnAmount.ts
Expand All @@ -3781,8 +3780,10 @@ var getBurnAmount = async (instancePromise, args) => {
secondTokenId,
amount
);
const resultAsJson = JSON.parse(result.toString());
return resultAsJson;
return {
firstAssetAmount: new import_bn.default(result[0]),
secondAssetAmount: new import_bn.default(result[1])
};
};

// src/methods/rpc/calculateSellPrice.ts
Expand All @@ -3794,12 +3795,12 @@ var calculateSellPrice = async (instancePromise, args) => {
});
const api = await instancePromise;
const { inputReserve, outputReserve, amount } = args;
const result = await api.rpc.xyk.calculate_sell_price(
const price = await api.rpc.xyk.calculate_sell_price(
inputReserve,
outputReserve,
amount
);
return new import_bn.default(result.price);
return new import_bn.default(price);
};

// src/methods/rpc/calculateBuyPrice.ts
Expand All @@ -3811,12 +3812,12 @@ var calculateBuyPrice = async (instancePromise, args) => {
});
const api = await instancePromise;
const { inputReserve, outputReserve, amount } = args;
const result = await api.rpc.xyk.calculate_buy_price(
const price = await api.rpc.xyk.calculate_buy_price(
inputReserve,
outputReserve,
amount
);
return new import_bn.default(result.price);
return new import_bn.default(price);
};

// src/methods/rpc/getNodeVersion.ts
Expand Down Expand Up @@ -3921,6 +3922,8 @@ var calculateRatio = (numerator, denominator) => {
return [gcd1, gcd22];
};
var getRatio = (left, right) => {
if (left.isZero() && right.isZero())
return BN_ZERO;
const ratios = calculateRatio(left, right);
const res = ratios[1].mul(BN_DIV_NUMERATOR_MULTIPLIER).div(ratios[0]);
return res;
Expand Down Expand Up @@ -8471,6 +8474,29 @@ var getWithdrawFromMoonriverFee = async (instancePromise, args) => {
return fromBN(new import_bn.default(dispatchInfo.partialFee.toString()));
};

// src/methods/rpc/getTradeableTokens.ts
var getTradeableTokens = async (instancePromise) => {
logger.info("getTradeableTokens");
const api = await instancePromise;
const tokens = await api.rpc.xyk.get_tradeable_tokens();
const tradeableTokens = tokens.map((item) => ({
tokenId: item.tokenId.toString(),
decimals: parseInt(item.decimals, 10),
name: item.name.toUtf8(),
symbol: item.symbol.toUtf8()
}));
return tradeableTokens;
};

// src/methods/rpc/getLiquidityTokensForTrading.ts
var getLiquidityTokensForTrading = async (instancePromise) => {
logger.info("getLiquidityTokensForTrading");
const api = await instancePromise;
const lpTokens = await api.rpc.xyk.get_liq_tokens_for_trading();
const lpTokensForTrading = lpTokens.map((item) => item.toString());
return lpTokensForTrading;
};

// src/mangataInstance.ts
function createMangataInstance(urls) {
const instancePromise = getOrCreateInstance(urls);
Expand Down Expand Up @@ -8500,6 +8526,8 @@ function createMangataInstance(urls) {
multiswapSellAsset: (args) => multiswapSellAsset(instancePromise, args, false)
},
rpc: {
getTradeableTokens: () => getTradeableTokens(instancePromise),
getLiquidityTokensForTrading: () => getLiquidityTokensForTrading(instancePromise),
isBuyAssetLockFree: (tokenIds, amount) => isBuyAssetLockFree(instancePromise, tokenIds, amount),
isSellAssetLockFree: (tokenIds, amount) => isSellAssetLockFree(instancePromise, tokenIds, amount),
calculateBuyPriceId: (soldTokenId, boughtTokenId, amount) => calculateBuyPriceId(
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mangata-finance/sdk",
"version": "2.0.0",
"version": "2.1.0-rc.4",
"description": "",
"type": "module",
"module": "dist/index.js",
Expand All @@ -12,7 +12,7 @@
}
},
"engines": {
"node": ">=16.0.0"
"node": ">=18.0.0"
},
"files": [
"dist"
Expand All @@ -27,15 +27,15 @@
"author": "Michal",
"license": "ISC",
"peerDependencies": {
"@polkadot/api": "^10.7.3"
"@polkadot/api": "10.9.1"
},
"dependencies": {
"@mangata-finance/type-definitions": "1.0.0",
"@mangata-finance/type-definitions": "2.0.0",
"big.js": "6.2.1",
"tslog": "4.8.2"
},
"devDependencies": {
"@mangata-finance/types": "1.0.0",
"@mangata-finance/types": "2.0.0",
"@semantic-release/changelog": "6.0.1",
"@semantic-release/git": "10.0.1",
"@types/big.js": "6.1.6",
Expand Down
4 changes: 4 additions & 0 deletions src/mangataInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ import { isBuyAssetLockFree } from "./methods/rpc/isBuyAssetLockFree";
import { isSellAssetLockFree } from "./methods/rpc/isSellAssetLockFree";
import { withdrawToMoonriver } from "./methods/xTokens/withdrawToMoonriver";
import { getWithdrawFromMoonriverFee } from "./methods/fee/getWithdrawFromMoonriverFee";
import {getTradeableTokens} from "./methods/rpc/getTradeableTokens";
import {getLiquidityTokensForTrading} from "./methods/rpc/getLiquidityTokensForTrading";
import { logger } from "./utils/mangataLogger";

/**
Expand Down Expand Up @@ -163,6 +165,8 @@ export function createMangataInstance(urls: string[]): MangataInstance {
multiswapSellAsset(instancePromise, args, false)
},
rpc: {
getTradeableTokens: () => getTradeableTokens(instancePromise),
getLiquidityTokensForTrading: () => getLiquidityTokensForTrading(instancePromise),
isBuyAssetLockFree: (tokenIds: TokenId[], amount: BN) =>
isBuyAssetLockFree(instancePromise, tokenIds, amount),
isSellAssetLockFree: (tokenIds: TokenId[], amount: BN) =>
Expand Down
4 changes: 1 addition & 3 deletions src/methods/fee/getWithdrawFromMoonriverFee.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { ApiPromise } from "@polkadot/api";
import { BN } from "@polkadot/util";
import { Account, TxOptions } from "../../types/common";
import { signTx } from "src/utils/signTx";
import { MoonriverWithdraw } from "../../types/xTokens";
import { fromBN } from "src/utils/bnUtility";
import { fromBN } from "../../utils/bnUtility";

export const getWithdrawFromMoonriverFee = async (
instancePromise: Promise<ApiPromise>,
Expand Down
2 changes: 1 addition & 1 deletion src/methods/query/getPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TokenId } from "../../types/common";
import { PoolWithRatio } from "../../types/query";
import { getLiquidityPool } from "./getLiquidityPool";
import { getAmountOfTokensInPool } from "./getAmountOfTokensInPool";
import { getLiquidityPromotedPools } from "src/utils/getLiquidityPromotedPools";
import { getLiquidityPromotedPools } from "../../utils/getLiquidityPromotedPools";
import { logger } from "../../utils/mangataLogger";

/**
Expand Down
4 changes: 2 additions & 2 deletions src/methods/rpc/calculateBuyPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export const calculateBuyPrice = async (
});
const api = await instancePromise;
const { inputReserve, outputReserve, amount } = args;
const result = await (api.rpc as any).xyk.calculate_buy_price(
const price = await (api.rpc as any).xyk.calculate_buy_price(
inputReserve,
outputReserve,
amount
);
return new BN(result.price);
return new BN(price);
};
4 changes: 2 additions & 2 deletions src/methods/rpc/calculateBuyPriceId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export const calculateBuyPriceId = async (
amount: amount.toString()
});
const api = await instancePromise;
const result = await (api.rpc as any).xyk.calculate_buy_price_id(
const price = await (api.rpc as any).xyk.calculate_buy_price_id(
soldTokenId,
boughtTokenId,
amount
);
return new BN(result.price);
return new BN(price);
};
8 changes: 3 additions & 5 deletions src/methods/rpc/calculateRewardsAmount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ export const calculateRewardsAmount = async (
liquidityTokenId
);

const price = isHex(rewards.price.toString())
? hexToBn(rewards.price.toString())
: new BN(rewards.price);

return price;
return isHex(rewards.toString())
? hexToBn(rewards.toString())
: new BN(rewards);
};
4 changes: 2 additions & 2 deletions src/methods/rpc/calculateSellPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export const calculateSellPrice = async (
});
const api = await instancePromise;
const { inputReserve, outputReserve, amount } = args;
const result = await (api.rpc as any).xyk.calculate_sell_price(
const price = await (api.rpc as any).xyk.calculate_sell_price(
inputReserve,
outputReserve,
amount
);
return new BN(result.price);
return new BN(price);
};
4 changes: 2 additions & 2 deletions src/methods/rpc/calculateSellPriceId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export const calculateSellPriceId = async (
amount: amount.toString()
});
const api = await instancePromise;
const result = await (api.rpc as any).xyk.calculate_sell_price_id(
const price = await (api.rpc as any).xyk.calculate_sell_price_id(
soldTokenId,
boughtTokenId,
amount
);
return new BN(result.price);
return new BN(price);
};
7 changes: 5 additions & 2 deletions src/methods/rpc/getBurnAmount.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ApiPromise } from "@polkadot/api";
import { BurnAmount, Price } from "../../types/xyk";
import { logger } from "../../utils/mangataLogger";
import {BN} from "@polkadot/util";

/**
* @since 2.0.0
Expand All @@ -21,6 +22,8 @@ export const getBurnAmount = async (
secondTokenId,
amount
);
const resultAsJson = JSON.parse(result.toString());
return resultAsJson as BurnAmount;
return {
firstAssetAmount: new BN(result[0]),
secondAssetAmount: new BN(result[1])
} as BurnAmount
};
Loading

0 comments on commit 17f4fd2

Please sign in to comment.