Skip to content

Commit

Permalink
xcm api update for cross-chain staking
Browse files Browse the repository at this point in the history
  • Loading branch information
RomeroYang committed Dec 21, 2022
1 parent 8e40f6d commit e6df975
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [0.5.1] - 20221221
- bump polkawallet_sdk v0.5.1.
- bridge api update.
- cross-chain staking api update.

## [0.4.9] - 20220808
- bump polkawallet_sdk v0.4.9.
- js api update.
Expand Down
2 changes: 1 addition & 1 deletion lib/js_service_karura/dist/main.js

Large diffs are not rendered by default.

28 changes: 11 additions & 17 deletions lib/js_service_karura/src/service/xcm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const chainNodes = {
[chain_name_turing]: ["wss://rpc.turing.oak.tech", "wss://turing.api.onfinality.io/public-ws", "wss://turing-rpc.dwellir.com"],
};
const xcm_dest_weight_v2 = "5000000000";
const xcm_dest_weight_unlimited = "Unlimited";

const xcmApi: Record<string, ApiPromise> = {};
// let xcmApi: ApiPromise;
Expand Down Expand Up @@ -237,14 +238,7 @@ async function _getTokenBalance(chain: string, address: string, tokenNameId: str
};
}

async function getTransferTx(
chainFrom: ChainData,
chainTo: ChainData,
tokenName: string,
amount: string,
addressTo: string,
sendFee: any
) {
async function getTransferTx(chainFrom: ChainData, chainTo: ChainData, tokenName: string, amount: string, addressTo: string, sendFee: any) {
if (!wallet) {
wallet = new Wallet((<any>window).api);
await wallet.isReady;
Expand All @@ -270,12 +264,12 @@ async function getTransferTx(
? {
module: "xTokens",
call: "transfer",
params: [token.toChainData(), amount, { V1: dst }, xcm_dest_weight_v2],
params: [token.toChainData(), amount, { V1: dst }, xcm_dest_weight_unlimited],
}
: {
module: "xTokens",
call: "transferMulticurrencies",
params: [[[token.toChainData(), amount], sendFee], 1, { V1: dst }, xcm_dest_weight_v2],
params: [[[token.toChainData(), amount], sendFee], 1, { V1: dst }, xcm_dest_weight_unlimited],
};
} else {
// to other parachains
Expand All @@ -291,12 +285,12 @@ async function getTransferTx(
? {
module: "xTokens",
call: "transferMulticurrencies",
params: [[[token.toChainData(), amount], sendFee], 1, { V1: dst }, xcm_dest_weight_v2],
params: [[[token.toChainData(), amount], sendFee], 1, { V1: dst }, xcm_dest_weight_unlimited],
}
: {
module: "xTokens",
call: "transfer",
params: [token.toChainData() as any, amount, { V1: dst }, xcm_dest_weight_v2],
params: [token.toChainData() as any, amount, { V1: dst }, xcm_dest_weight_unlimited],
};
}

Expand Down Expand Up @@ -369,7 +363,7 @@ async function getTransferTx(
return {
module: "xTokens",
call: "transfer",
params: [tokenIds[token.name], amount, { V1: dst }, xcm_dest_weight_v2],
params: [tokenIds[token.name], amount, { V1: dst }, xcm_dest_weight_unlimited],
};
}

Expand Down Expand Up @@ -525,13 +519,13 @@ async function getTransferParams(
const res = await getTransferTx(chainFrom, chainTo, tokenName, amount, addressTo, sendFee);
if (!res) return null;

const {module, call, params} = res;
const tx = (chainFrom.name === 'karura' ? (<any>window).api : getApi(chainFrom.name)).tx[module][call](...params);
const { module, call, params } = res;
const tx = (chainFrom.name === "karura" ? (<any>window).api : getApi(chainFrom.name)).tx[module][call](...params);
return {
module,
call,
params: tx.args.map(e => e.toHuman()),
txHex: tx.toHex()
params: tx.args.map((e) => e.toHuman()),
txHex: tx.toHex(),
};
}

Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: polkawallet_plugin_karura
description: Karura network plugin for Polkawallet.
version: 0.4.9
version: 0.5.1
homepage:

environment:
Expand All @@ -20,8 +20,8 @@ dependencies:
get_storage: ^2.0.2
device_info: ^2.0.1
graphql_flutter: ^5.0.0-nullsafety.5
polkawallet_sdk: ^0.4.9
polkawallet_ui: ^0.4.9
polkawallet_sdk: ^0.5.1
polkawallet_ui: ^0.5.1
flutter_screenutil: ^5.0.0+2
skeleton_loader: ^2.0.0+4
rive: ^0.9.0
Expand Down

0 comments on commit e6df975

Please sign in to comment.