From e15fc070a48b848803774156133ecd9c0931a5f4 Mon Sep 17 00:00:00 2001 From: devdanco Date: Mon, 3 Jul 2023 15:22:56 +0200 Subject: [PATCH] [Mangata] Replace rpc and types with type definition package --- packages/apps-config/package.json | 1 + packages/apps-config/src/api/spec/mangata.ts | 203 +------------------ packages/apps-config/src/api/typesBundle.ts | 104 ++++++++-- yarn.lock | 10 + 4 files changed, 95 insertions(+), 223 deletions(-) diff --git a/packages/apps-config/package.json b/packages/apps-config/package.json index ba6a0b76641c..6c605ff75da1 100644 --- a/packages/apps-config/package.json +++ b/packages/apps-config/package.json @@ -31,6 +31,7 @@ "@kiltprotocol/type-definitions": "0.33.1", "@laminar/type-definitions": "0.3.1", "@logion/node-api": "0.16.0", + "@mangata-finance/type-definitions": "^1.0.0", "@metaverse-network-sdk/type-definitions": "0.0.1-16", "@parallel-finance/type-definitions": "1.7.17", "@peaqnetwork/type-definitions": "0.0.4", diff --git a/packages/apps-config/src/api/spec/mangata.ts b/packages/apps-config/src/api/spec/mangata.ts index 47c11876914c..802e2e690e73 100644 --- a/packages/apps-config/src/api/spec/mangata.ts +++ b/packages/apps-config/src/api/spec/mangata.ts @@ -11,6 +11,7 @@ import type { Balance } from '@polkadot/types/interfaces'; import type { FrameSystemAccountInfo } from '@polkadot/types/lookup'; import type { OverrideBundleDefinition } from '@polkadot/types/types'; +import { mangataTypesBundleForPolkadotApps } from '@mangata-finance/type-definitions'; import { combineLatest, map } from 'rxjs'; import { memo } from '@polkadot/api-derive/util'; @@ -72,207 +73,7 @@ const definitions: OverrideBundleDefinition = { all: getBalance } }, - types: [ - { - // on all versions - minmax: [0, undefined], - types: { - ShufflingSeed: { - seed: 'H256', - proof: 'H512' - }, - Header: { - parentHash: 'Hash', - number: 'Compact', - stateRoot: 'Hash', - extrinsicsRoot: 'Hash', - digest: 'Digest', - seed: 'ShufflingSeed', - count: 'BlockNumber' - }, - XYKRpcResult: { - price: 'Balance' - }, - RPCAmountsResult: { - firstAssetAmount: 'Balance', - secondAssetAmount: 'Balance' - }, - VestingInfo: { - locked: 'Balance', - perBlock: 'Balance', - startingBlock: 'BlockNumber' - }, - TokenId: 'u32', - VestingInfosWithLockedAt: { - vestingInfosWithLockedAt: 'Vec<(VestingInfo, Balance)>' - } - } - } - ], - rpc: { - xyk: { - calculate_buy_price: { - description: '', - params: [ - { - name: 'input_reserve', - type: 'Balance' - }, - { - name: 'output_reserve', - type: 'Balance' - }, - { - name: 'sell_amount', - type: 'Balance' - } - ], - type: 'XYKRpcResult' - }, - calculate_sell_price: { - description: '', - params: [ - { - name: 'input_reserve', - type: 'Balance' - }, - { - name: 'output_reserve', - type: 'Balance' - }, - { - name: 'sell_amount', - type: 'Balance' - } - ], - type: 'XYKRpcResult' - }, - get_burn_amount: { - description: '', - params: [ - { - name: 'first_asset_id', - type: 'TokenId' - }, - { - name: 'second_asset_id', - type: 'TokenId' - }, - { - name: 'liquidity_asset_amount', - type: 'Balance' - } - ], - type: 'RPCAmountsResult' - }, - calculate_sell_price_id: { - description: '', - params: [ - { - name: 'sold_token_id', - type: 'TokenId' - }, - { - name: 'bought_token_id', - type: 'TokenId' - }, - { - name: 'sell_amount', - type: 'Balance' - } - ], - type: 'XYKRpcResult' - }, - calculate_buy_price_id: { - description: '', - params: [ - { - name: 'sold_token_id', - type: 'TokenId' - }, - { - name: 'bought_token_id', - type: 'TokenId' - }, - { - name: 'buy_amount', - type: 'Balance' - } - ], - type: 'XYKRpcResult' - }, - calculate_rewards_amount: { - description: '', - params: [ - { - name: 'user', - type: 'AccountId' - }, - { - name: 'liquidity_asset_id', - type: 'TokenId' - } - ], - type: 'XYKRpcResult' - }, - calculate_balanced_sell_amount: { - description: '', - params: [ - { - name: 'total_amount', - type: 'Balance' - }, - { - name: 'reserve_amount', - type: 'Balance' - } - ], - type: 'XYKRpcResult' - }, - get_max_instant_unreserve_amount: { - description: '', - params: [ - { - name: 'user', - type: 'AccountId' - }, - { - name: 'liquidity_asset_id', - type: 'TokenId' - } - ], - type: 'Balance' - }, - get_max_instant_burn_amount: { - description: '', - params: [ - { - name: 'user', - type: 'AccountId' - }, - { - name: 'liquidity_asset_id', - type: 'TokenId' - } - ], - type: 'Balance' - }, - get_vesting_locked_at: { - description: '', - params: [ - { - name: 'who', - type: 'AccountId' - }, - { - name: 'token_id', - type: 'TokenId' - } - ], - type: 'VestingInfosWithLockedAt' - } - } - } + ...mangataTypesBundleForPolkadotApps }; export default definitions; diff --git a/packages/apps-config/src/api/typesBundle.ts b/packages/apps-config/src/api/typesBundle.ts index 88122e60aefc..15520bbc8bd7 100644 --- a/packages/apps-config/src/api/typesBundle.ts +++ b/packages/apps-config/src/api/typesBundle.ts @@ -59884,7 +59884,7 @@ export const typesBundle = { "rpc": { "xyk": { "calculate_buy_price": { - "description": "", + "description": "Calculates and returns sold_token_amount while providing bought_token_amount and respective reserves", "params": [ { "name": "input_reserve", @@ -59902,7 +59902,7 @@ export const typesBundle = { "type": "XYKRpcResult" }, "calculate_sell_price": { - "description": "", + "description": "Calculates and returns bought_token_amount while providing sold_token_amount and respective reserves", "params": [ { "name": "input_reserve", @@ -59920,7 +59920,7 @@ export const typesBundle = { "type": "XYKRpcResult" }, "get_burn_amount": { - "description": "", + "description": "Returns amounts of tokens received by burning provided liquidity_token_amount in pool of provided token ids", "params": [ { "name": "first_asset_id", @@ -59938,7 +59938,7 @@ export const typesBundle = { "type": "RPCAmountsResult" }, "calculate_sell_price_id": { - "description": "", + "description": "Same as calculate_sell_price, but providing token_id instead of reserves. Reserves are fetched by function.", "params": [ { "name": "sold_token_id", @@ -59956,7 +59956,7 @@ export const typesBundle = { "type": "XYKRpcResult" }, "calculate_buy_price_id": { - "description": "", + "description": "Same as calculate_buy_price, but providing token_id instead of reserves. Reserves are fetched by function.", "params": [ { "name": "sold_token_id", @@ -59974,7 +59974,7 @@ export const typesBundle = { "type": "XYKRpcResult" }, "calculate_rewards_amount": { - "description": "", + "description": "Calculate rewards amount of liquidity token id for the user", "params": [ { "name": "user", @@ -59988,7 +59988,7 @@ export const typesBundle = { "type": "XYKRpcResult" }, "calculate_balanced_sell_amount": { - "description": "", + "description": "Calculates how much amount x we need to swap from total_amount, so that after y = swap(x), the resulting balance equals (total_amount - x) / y = pool_x / pool_y - the resulting amounts can then be used to `mint_liquidity` with minimal leftover after operation", "params": [ { "name": "total_amount", @@ -60002,7 +60002,7 @@ export const typesBundle = { "type": "XYKRpcResult" }, "get_max_instant_unreserve_amount": { - "description": "", + "description": "Instant unreserve amount", "params": [ { "name": "user", @@ -60013,7 +60013,7 @@ export const typesBundle = { "type": "TokenId" } ], - "type": "Balance" + "type": "XYKRpcResult" }, "get_max_instant_burn_amount": { "description": "", @@ -60027,9 +60027,39 @@ export const typesBundle = { "type": "TokenId" } ], - "type": "Balance" + "type": "XYKRpcResult" }, - "get_vesting_locked_at": { + "is_sell_asset_lock_free": { + "description": "", + "params": [ + { + "name": "path", + "type": "Vec" + }, + { + "name": "input_amount", + "type": "Balance" + } + ], + "type": "Option" + }, + "is_buy_asset_lock_free": { + "description": "", + "params": [ + { + "name": "path", + "type": "Vec" + }, + { + "name": "input_amount", + "type": "Balance" + } + ], + "type": "Option" + } + }, + "vesting": { + "getVestingLockedAt": { "description": "", "params": [ { @@ -60089,7 +60119,7 @@ export const typesBundle = { "rpc": { "xyk": { "calculate_buy_price": { - "description": "", + "description": "Calculates and returns sold_token_amount while providing bought_token_amount and respective reserves", "params": [ { "name": "input_reserve", @@ -60107,7 +60137,7 @@ export const typesBundle = { "type": "XYKRpcResult" }, "calculate_sell_price": { - "description": "", + "description": "Calculates and returns bought_token_amount while providing sold_token_amount and respective reserves", "params": [ { "name": "input_reserve", @@ -60125,7 +60155,7 @@ export const typesBundle = { "type": "XYKRpcResult" }, "get_burn_amount": { - "description": "", + "description": "Returns amounts of tokens received by burning provided liquidity_token_amount in pool of provided token ids", "params": [ { "name": "first_asset_id", @@ -60143,7 +60173,7 @@ export const typesBundle = { "type": "RPCAmountsResult" }, "calculate_sell_price_id": { - "description": "", + "description": "Same as calculate_sell_price, but providing token_id instead of reserves. Reserves are fetched by function.", "params": [ { "name": "sold_token_id", @@ -60161,7 +60191,7 @@ export const typesBundle = { "type": "XYKRpcResult" }, "calculate_buy_price_id": { - "description": "", + "description": "Same as calculate_buy_price, but providing token_id instead of reserves. Reserves are fetched by function.", "params": [ { "name": "sold_token_id", @@ -60179,7 +60209,7 @@ export const typesBundle = { "type": "XYKRpcResult" }, "calculate_rewards_amount": { - "description": "", + "description": "Calculate rewards amount of liquidity token id for the user", "params": [ { "name": "user", @@ -60193,7 +60223,7 @@ export const typesBundle = { "type": "XYKRpcResult" }, "calculate_balanced_sell_amount": { - "description": "", + "description": "Calculates how much amount x we need to swap from total_amount, so that after y = swap(x), the resulting balance equals (total_amount - x) / y = pool_x / pool_y - the resulting amounts can then be used to `mint_liquidity` with minimal leftover after operation", "params": [ { "name": "total_amount", @@ -60207,7 +60237,7 @@ export const typesBundle = { "type": "XYKRpcResult" }, "get_max_instant_unreserve_amount": { - "description": "", + "description": "Instant unreserve amount", "params": [ { "name": "user", @@ -60218,7 +60248,7 @@ export const typesBundle = { "type": "TokenId" } ], - "type": "Balance" + "type": "XYKRpcResult" }, "get_max_instant_burn_amount": { "description": "", @@ -60232,9 +60262,39 @@ export const typesBundle = { "type": "TokenId" } ], - "type": "Balance" + "type": "XYKRpcResult" }, - "get_vesting_locked_at": { + "is_sell_asset_lock_free": { + "description": "", + "params": [ + { + "name": "path", + "type": "Vec" + }, + { + "name": "input_amount", + "type": "Balance" + } + ], + "type": "Option" + }, + "is_buy_asset_lock_free": { + "description": "", + "params": [ + { + "name": "path", + "type": "Vec" + }, + { + "name": "input_amount", + "type": "Balance" + } + ], + "type": "Option" + } + }, + "vesting": { + "getVestingLockedAt": { "description": "", "params": [ { diff --git a/yarn.lock b/yarn.lock index 4c1936d89001..6180e6e8de06 100644 --- a/yarn.lock +++ b/yarn.lock @@ -967,6 +967,15 @@ __metadata: languageName: node linkType: hard +"@mangata-finance/type-definitions@npm:^1.0.0": + version: 1.0.0 + resolution: "@mangata-finance/type-definitions@npm:1.0.0" + peerDependencies: + "@polkadot/types": ^10.7.3 + checksum: 6b93fd4c4e53b7fa0b1c145929ecd170fcbd7921a49ec18b128b32dafab2a4e06d678cc8058ffc7b95f921481387062b3b32bf31c9929005827d87599392e389 + languageName: node + linkType: hard + "@metamask/detect-provider@npm:^2.0.0": version: 2.0.0 resolution: "@metamask/detect-provider@npm:2.0.0" @@ -1854,6 +1863,7 @@ __metadata: "@kiltprotocol/type-definitions": 0.33.1 "@laminar/type-definitions": 0.3.1 "@logion/node-api": 0.16.0 + "@mangata-finance/type-definitions": ^1.0.0 "@metaverse-network-sdk/type-definitions": 0.0.1-16 "@parallel-finance/type-definitions": 1.7.17 "@peaqnetwork/type-definitions": 0.0.4