Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
39 changes: 16 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,41 @@
"lint": "eslint . --ext .ts"
},
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.7.4",
"@babel/cli": "^7.12.1",
"@babel/core": "^7.11.6",
"@babel/helper-skip-transparent-expression-wrappers": "^7.11.0",
"@babel/helper-validator-identifier": "^7.10.4",
"@babel/plugin-proposal-numeric-separator": "^7.10.4",
"@babel/preset-env": "^7.7.6",
"@babel/runtime-corejs3": "^7.7.6",
"@polkadot/dev": "0.31.1",
"@polkadot/ts": "^0.1.86",
"@types/jest": "^23.3.10",
"@typescript-eslint/eslint-plugin": "^3.10.0",
"@typescript-eslint/parser": "^3.10.0",
"babel-jest": "^24.9.0",
"@types/jest": "^26.0.14",
"@typescript-eslint/eslint-plugin": "^4.4.1",
"@typescript-eslint/parser": "^4.4.1",
"babel-jest": "^26.5.2",
"babel-plugin-conditional-compile": "^0.0.5",
"core-js": "^3.4.8",
"cz-lerna-changelog": "^2.0.2",
"eslint": "^7.7.0",
"eslint-plugin-import": "^2.22.0",
"eslint": "^7.11.0",
"eslint-plugin-import": "^2.22.1",
"husky": "^1.1.1",
"jest": "24.1.0",
"jest-environment-node": "^24.0.0",
"jest": "^26.5.3",
"jest-environment-node": "^26.5.2",
"lerna": "^3.13.1",
"prettier": "^1.13.5",
"pretty-quick": "^1.11.1",
"ts-jest": "^24.0.0",
"ts-jest": "^26.4.1",
"ts-node": "^8.0.3",
"tsconfig-paths": "^3.8.0",
"tslint": "^5.14.0",
"tslint-microsoft-contrib": "^5.2.1",
"typedoc": "^0.14.2",
"typedoc": "^0.19.2",
"typedoc-plugin-monorepo": "https://github.com/ianhe8x/typedoc-plugin-monorepo",
"typescript": "^4.0.2"
"typescript": "^4.0.3",
"cz-lerna-changelog": "^2.0.3",
"semantic-release": "^15.14.0"
},
"resolutions": {
"babel-core": "^7.0.0-bridge.0",
"typescript": "^4.0.2",
"braces": "^2.3.2",
"fstream": "^1.0.12",
"handlebars": "^4.5.3",
"js-yaml": "^3.13.1",
"marked": "^0.6.2",
"tar": "^4.4.8"
"typescript": "^4.0.3"
},
"config": {
"commitizen": {
Expand Down
3 changes: 0 additions & 3 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
"@polkadot/types": "2.1.2-2",
"eventemitter3": "^4.0.0"
},
"resolution": {
"@polkadot/keyring": "2.3.1"
},
"devDependencies": {
"@cennznet/cennznut-wasm": "^0.0.1-dev.0",
"@types/jest": "^23.3.5",
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import { ApiPromise } from '@polkadot/api';
import { ApiOptions as ApiOptionsBase, SubmittableExtrinsics } from '@polkadot/api/types';

// import derives from './derives';
// import rpc from './rpc';
import staticMetadata from './staticMetadata';
// import { ApiOptions, Derives, SubmittableExtrinsics } from './types';
import { ApiOptions } from './types';
// import { mergeDeriveOptions } from './util/derives';
import { getProvider } from './util/getProvider';
import { getTimeout } from './util/getTimeout';
import rpc from './rpc';

export class Api extends ApiPromise {
static async create(options: ApiOptions = {}): Promise<Api> {
Expand Down Expand Up @@ -67,7 +67,7 @@ export class Api extends ApiPromise {
options.metadata = Object.assign(staticMetadata, options.metadata);
options.types = { ...options.types, ...Types };
// options.derives = mergeDeriveOptions(derives, options.derives);
// options.rpc = { ...(rpc as any), ...options.rpc };
options.rpc = { ...(rpc as any), ...options.rpc };

super(options as ApiOptionsBase);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/ApiRx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import { ApiOptions as ApiOptionsBase, SubmittableExtrinsics } from '@polkadot/a
import { Observable } from 'rxjs';
import { timeout } from 'rxjs/operators';

// import rpc from '@cennznet/api/rpc';
// import derives from './derives';
import staticMetadata from './staticMetadata';
// import { ApiOptions, Derives, SubmittableExtrinsics } from './types';
import { ApiOptions } from './types';
import { getProvider } from './util/getProvider';
import { getTimeout } from './util/getTimeout';
import rpc from './rpc';

export class ApiRx extends ApiRxBase {
static create(options: ApiOptions = {}): Observable<ApiRx> {
Expand Down Expand Up @@ -67,7 +67,7 @@ export class ApiRx extends ApiRxBase {
options.metadata = Object.assign(staticMetadata, options.metadata);
options.types = { ...options.types, ...Types };
// options.derives = mergeDeriveOptions(derives as any, options.derives);
// options.rpc = { ...(rpc as any), ...options.rpc };
options.rpc = { ...(rpc as any), ...options.rpc };

super(options as ApiOptionsBase);
}
Expand Down
118 changes: 67 additions & 51 deletions packages/api/src/rpc/cennzx.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,67 @@
// import { RpcMethodOpt } from '@polkadot/jsonrpc/types';
//
// import createMethod from '@polkadot/jsonrpc/create/method';
// import createParam from '@polkadot/jsonrpc/create/param';
//
// const buyPrice: RpcMethodOpt = {
// description: 'Retrieves the CENNZX exchange buy price',
// isOptional: true,
// params: [
// createParam('AssetToBuy', 'AssetId'),
// createParam('Amount', 'Balance'),
// createParam('AssetToPay', 'AssetId'),
// ],
// type: 'Balance',
// };
//
// const sellPrice: RpcMethodOpt = {
// description: 'Retrieves the CENNZX exchange sell price',
// isOptional: true,
// params: [
// createParam('AssetToSell', 'AssetId'),
// createParam('Amount', 'Balance'),
// createParam('AssetToPayout', 'AssetId'),
// ],
// type: 'Balance',
// };
//
// // Returns the core asset price and investment asset's price for investment asset Id
// const liquidityPrice: RpcMethodOpt = {
// description: 'Get the price of liquidity for the given asset ID',
// isOptional: true,
// params: [createParam('AssetId', 'AssetId'), createParam('liquidityToBuy', 'Balance')],
// type: '(Balance, Balance)' as any,
// };
//
// // Returns liquidity volume, core amount, asset amount for given asset
// const liquidityValue: RpcMethodOpt = {
// description: "Get the value of an account's liquidity for the given asset",
// isOptional: true,
// params: [createParam('AccountId', 'Address'), createParam('AssetId', 'AssetId')],
// type: '(Balance, Balance, Balance)' as any,
// };
//
// const section = 'cennzx';
//
// export default [
// { ...createMethod(section, 'buyPrice', buyPrice), name: 'buyPrice' },
// { ...createMethod(section, 'sellPrice', sellPrice), name: 'sellPrice' },
// { ...createMethod(section, 'liquidityPrice', liquidityPrice), name: 'liquidityPrice' },
// { ...createMethod(section, 'liquidityValue', liquidityValue), name: 'liquidityValue' },
// ];
const cennzxRpc = {
buyPrice: {
description: 'Retrieves the spot exchange buy price',
params: [
{
name: 'AssetToBuy',
type: 'AssetId',
},
{
name: 'Amount',
type: 'Balance',
},
{
name: 'AssetToPay',
type: 'AssetId',
},
],
type: 'Balance',
},
sellPrice: {
description: 'Retrieves the spot exchange sell price',
params: [
{
name: 'AssetToSell',
type: 'AssetId',
},
{
name: 'Amount',
type: 'Balance',
},
{
name: 'AssetToPay',
type: 'AssetId',
},
],
type: 'Balance',
},
liquidityPrice: {
description: 'Get the price of liquidity for the given asset ID',
params: [
{
name: 'AssetId',
type: 'AssetId',
},
{
name: 'liquidityToBuy',
type: 'Balance',
},
],
type: '(Balance, Balance) as any',
},
liquidityValue: {
description: "Get the value of an account's liquidity for the given asset",
params: [
{
name: 'AccountId',
type: 'Address',
},
{
name: 'AssetId',
type: 'AssetId',
},
],
type: '(Balance, Balance, Balance) as any',
},
};
export default cennzxRpc;
23 changes: 9 additions & 14 deletions packages/api/src/rpc/genericAsset.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
// import { RpcMethodOpt } from '@polkadot/jsonrpc/types';
//
// import createMethod from '@polkadot/jsonrpc/create/method';
//
// const registeredAssets: RpcMethodOpt = {
// description: 'Get all registered generic assets (symbol, decimal places)',
// isOptional: true,
// params: [],
// type: 'Vec<(AssetId, AssetInfo)>',
// };
//
// const section = 'genericAsset';
//
// export default [{ ...createMethod(section, 'registeredAssets', registeredAssets), name: 'registeredAssets' }];
const genericAssetRpc = {
registeredAssets: {
description: 'Get all registered generic assets (symbol, decimal places)',
params: [],
type: 'Vec<(AssetId, AssetInfo)>',
},
};

export default genericAssetRpc;
20 changes: 11 additions & 9 deletions packages/api/src/rpc/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// import cennzx from './cennzx';
// import genericAsset from './genericAsset';
//
// const interfaces: Record<string, object> = {
// cennzx,
// genericAsset,
// };
//
// export default interfaces;
import cennzxRpc from './cennzx';
import genericAssetRpc from './genericAsset';
import paymentRpc from './payment';

const interfaces = {
cennzx: cennzxRpc,
genericAsset: genericAssetRpc,
payment: paymentRpc,
};

export default interfaces;
18 changes: 18 additions & 0 deletions packages/api/src/rpc/payment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const paymentRpc = {
queryInfo: {
description: 'Query transaction payment info',
params: [
{
name: 'EncodedXt',
type: 'Bytes',
},
{
name: 'At',
type: 'BlockHash',
},
],
type: 'RuntimeDispatchInfo',
},
};

export default paymentRpc;
4 changes: 1 addition & 3 deletions packages/api/test/e2e/cennzx.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ describe('CENNZX RPC calls testing', () => {
for (const {event} of events) {
if (event.method === 'AddLiquidity') {
let amount = 20000;
let coreAmount = 20000;
let investmentAmount = 20000;
// const [coreAmount, investmentAmount] = await api.rpc.cennzx.liquidityPrice(CENNZ, amount);
const [coreAmount, investmentAmount] = await api.rpc.cennzx.liquidityPrice(CENNZ, amount);
// Deposit liquidity in existing pool
await api.tx.cennzx
.addLiquidity(CENNZ, minLiquidity, investmentAmount, coreAmount)
Expand Down
19 changes: 9 additions & 10 deletions packages/api/test/e2e/queries.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,15 @@ describe('e2e queries', () => {
expect(nextAssetId.toString()).toEqual(nextAssetIdAt.toString());
});

// it('Checks transaction payment', async done => {
//
// const assetBalance = await api.query.genericAsset.freeBalance(16001, bob.address);
// console.log('Balance before ', assetBalance.toString());
// const ex = await api.tx.genericAsset
// .transfer(16000, bob.address, 100);
// const payment = await api.rpc.payment.queryInfo(ex.toHex());
// console.log('Payment:', payment.partialFee.toString());
// done();
// });
it('Checks transaction payment', async done => {
const assetBalance = await api.query.genericAsset.freeBalance(16001, bob.address);
console.log('Balance before ', assetBalance.toString());
const ex = await api.tx.genericAsset
.transfer(16000, bob.address, 100);
const payment = await api.rpc.payment.queryInfo(ex.toHex());
console.log('Payment:', payment.partialFee.toString());
done();
});
});

describe('Subscribe storage', () => {
Expand Down
Loading