@moonbeam-network/xcm-sdk 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/README.md +1 -0
- package/build/cjs/src/contracts/XTokensContract/XTokensABI.json +94 -0
- package/build/cjs/src/contracts/XTokensContract/XTokensContract.d.ts +11 -0
- package/build/cjs/src/contracts/XTokensContract/XTokensContract.js +44 -0
- package/build/cjs/src/contracts/XTokensContract/XTokensContract.js.map +1 -0
- package/build/cjs/src/contracts/XTokensContract/index.d.ts +1 -0
- package/build/cjs/src/contracts/XTokensContract/index.js +6 -0
- package/build/cjs/src/contracts/XTokensContract/index.js.map +1 -0
- package/build/cjs/src/contracts/index.d.ts +1 -0
- package/build/cjs/src/contracts/index.js +18 -0
- package/build/cjs/src/contracts/index.js.map +1 -0
- package/build/cjs/src/index.d.ts +3 -0
- package/build/cjs/src/index.js +20 -0
- package/build/cjs/src/index.js.map +1 -0
- package/build/cjs/src/polkadot/PolkadotService.d.ts +29 -0
- package/build/cjs/src/polkadot/PolkadotService.js +132 -0
- package/build/cjs/src/polkadot/PolkadotService.js.map +1 -0
- package/build/cjs/src/polkadot/index.d.ts +3 -0
- package/build/cjs/src/polkadot/index.js +20 -0
- package/build/cjs/src/polkadot/index.js.map +1 -0
- package/build/cjs/src/polkadot/polkadot.api.d.ts +2 -0
- package/build/cjs/src/polkadot/polkadot.api.js +30 -0
- package/build/cjs/src/polkadot/polkadot.api.js.map +1 -0
- package/build/cjs/src/polkadot/polkadot.interfaces.d.ts +12 -0
- package/build/cjs/src/polkadot/polkadot.interfaces.js +3 -0
- package/build/cjs/src/polkadot/polkadot.interfaces.js.map +1 -0
- package/build/cjs/src/polkadot/polkadot.utils.d.ts +4 -0
- package/build/cjs/src/polkadot/polkadot.utils.js +26 -0
- package/build/cjs/src/polkadot/polkadot.utils.js.map +1 -0
- package/build/cjs/src/sdk/index.d.ts +3 -0
- package/build/cjs/src/sdk/index.js +23 -0
- package/build/cjs/src/sdk/index.js.map +1 -0
- package/build/cjs/src/sdk/sdk.d.ts +2 -0
- package/build/cjs/src/sdk/sdk.interfaces.d.ts +94 -0
- package/build/cjs/src/sdk/sdk.interfaces.js +10 -0
- package/build/cjs/src/sdk/sdk.interfaces.js.map +1 -0
- package/build/cjs/src/sdk/sdk.js +164 -0
- package/build/cjs/src/sdk/sdk.js.map +1 -0
- package/build/cjs/src/sdk/sdk.utils.d.ts +18 -0
- package/build/cjs/src/sdk/sdk.utils.js +93 -0
- package/build/cjs/src/sdk/sdk.utils.js.map +1 -0
- package/build/mjs/src/contracts/XTokensContract/XTokensABI.json +94 -0
- package/build/mjs/src/contracts/XTokensContract/XTokensContract.d.ts +11 -0
- package/build/mjs/src/contracts/XTokensContract/XTokensContract.js +37 -0
- package/build/mjs/src/contracts/XTokensContract/XTokensContract.js.map +1 -0
- package/build/mjs/src/contracts/XTokensContract/index.d.ts +1 -0
- package/build/mjs/src/contracts/XTokensContract/index.js +2 -0
- package/build/mjs/src/contracts/XTokensContract/index.js.map +1 -0
- package/build/mjs/src/contracts/index.d.ts +1 -0
- package/build/mjs/src/contracts/index.js +2 -0
- package/build/mjs/src/contracts/index.js.map +1 -0
- package/build/mjs/src/index.d.ts +3 -0
- package/build/mjs/src/index.js +4 -0
- package/build/mjs/src/index.js.map +1 -0
- package/build/mjs/src/polkadot/PolkadotService.d.ts +29 -0
- package/build/mjs/src/polkadot/PolkadotService.js +128 -0
- package/build/mjs/src/polkadot/PolkadotService.js.map +1 -0
- package/build/mjs/src/polkadot/index.d.ts +3 -0
- package/build/mjs/src/polkadot/index.js +4 -0
- package/build/mjs/src/polkadot/index.js.map +1 -0
- package/build/mjs/src/polkadot/polkadot.api.d.ts +2 -0
- package/build/mjs/src/polkadot/polkadot.api.js +23 -0
- package/build/mjs/src/polkadot/polkadot.api.js.map +1 -0
- package/build/mjs/src/polkadot/polkadot.interfaces.d.ts +12 -0
- package/build/mjs/src/polkadot/polkadot.interfaces.js +2 -0
- package/build/mjs/src/polkadot/polkadot.interfaces.js.map +1 -0
- package/build/mjs/src/polkadot/polkadot.utils.d.ts +4 -0
- package/build/mjs/src/polkadot/polkadot.utils.js +21 -0
- package/build/mjs/src/polkadot/polkadot.utils.js.map +1 -0
- package/build/mjs/src/sdk/index.d.ts +3 -0
- package/build/mjs/src/sdk/index.js +4 -0
- package/build/mjs/src/sdk/index.js.map +1 -0
- package/build/mjs/src/sdk/sdk.d.ts +2 -0
- package/build/mjs/src/sdk/sdk.interfaces.d.ts +94 -0
- package/build/mjs/src/sdk/sdk.interfaces.js +7 -0
- package/build/mjs/src/sdk/sdk.interfaces.js.map +1 -0
- package/build/mjs/src/sdk/sdk.js +160 -0
- package/build/mjs/src/sdk/sdk.js.map +1 -0
- package/build/mjs/src/sdk/sdk.utils.d.ts +18 -0
- package/build/mjs/src/sdk/sdk.utils.js +85 -0
- package/build/mjs/src/sdk/sdk.utils.js.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Asset, AssetConfig, Chain, ChainConfig, MoonbaseAssets, MoonbaseChains, MoonbeamAssets, MoonbeamChains, MoonChainConfig, MoonriverAssets, MoonriverChains } from '@moonbeam-network/xcm-config';
|
|
2
|
+
import { Signer as PolkadotSigner, UnsubscribePromise } from '@polkadot/api/types';
|
|
3
|
+
import { Signer as EthersSigner } from 'ethers';
|
|
4
|
+
import { AssetBalanceInfo } from '../polkadot';
|
|
5
|
+
export declare type Hash = string;
|
|
6
|
+
export interface XcmSdkByChain {
|
|
7
|
+
moonbase: MoonbaseXcmSdk;
|
|
8
|
+
moonbeam: MoonbeamXcmSdk;
|
|
9
|
+
moonriver: MoonriverXcmSdk;
|
|
10
|
+
}
|
|
11
|
+
export declare type MoonXcmSdk = MoonbaseXcmSdk | MoonbeamXcmSdk | MoonriverXcmSdk;
|
|
12
|
+
export declare type MoonbaseXcmSdk = XcmSdk<MoonbaseAssets, MoonbaseChains>;
|
|
13
|
+
export declare type MoonbeamXcmSdk = XcmSdk<MoonbeamAssets, MoonbeamChains>;
|
|
14
|
+
export declare type MoonriverXcmSdk = XcmSdk<MoonriverAssets, MoonriverChains>;
|
|
15
|
+
export interface XcmSdk<Assets extends Asset = Asset, Chains extends Chain = Chain> {
|
|
16
|
+
asset: AssetConfig<Assets>;
|
|
17
|
+
chain: MoonChainConfig;
|
|
18
|
+
subscribeToAssetsBalanceInfo: (account: string, cb: (data: AssetBalanceInfo<Assets>[]) => void) => UnsubscribePromise;
|
|
19
|
+
deposit: (asset: Assets) => XcmSdkDeposit<Assets, Chains>;
|
|
20
|
+
withdraw: (asset: Assets) => XcmSdkWithdraw<Assets, Chains>;
|
|
21
|
+
}
|
|
22
|
+
export interface XcmSdkDeposit<Assets extends Asset = Asset, Chains extends Chain = Chain> {
|
|
23
|
+
chains: ChainConfig[];
|
|
24
|
+
from: (chain: Chains) => XcmSdkDepositFrom<Assets>;
|
|
25
|
+
}
|
|
26
|
+
export interface XcmSdkWithdraw<Assets extends Asset = Asset, Chains extends Chain = Chain> {
|
|
27
|
+
chains: ChainConfig[];
|
|
28
|
+
to: (chain: Chains) => XcmSdkWithdrawTo<Assets>;
|
|
29
|
+
}
|
|
30
|
+
export interface XcmSdkDepositFrom<Assets extends Asset = Asset> {
|
|
31
|
+
get: (account: string, sourceAccount: string, primaryAccount?: string) => Promise<DepositTransferData<Assets>>;
|
|
32
|
+
}
|
|
33
|
+
export interface XcmSdkWithdrawTo<Assets extends Asset = Asset> {
|
|
34
|
+
get: (account: string) => Promise<WithdrawTransferData<Assets>>;
|
|
35
|
+
}
|
|
36
|
+
export interface DepositTransferData<Assets extends Asset = Asset> {
|
|
37
|
+
asset: AssetConfigWithDecimals<Assets>;
|
|
38
|
+
existentialDeposit: bigint;
|
|
39
|
+
min: bigint;
|
|
40
|
+
moonChainFee?: bigint;
|
|
41
|
+
native: AssetConfigWithDecimals<Assets>;
|
|
42
|
+
origin: MoonChainConfig | ChainConfig;
|
|
43
|
+
source: ChainConfig;
|
|
44
|
+
sourceBalance: bigint;
|
|
45
|
+
sourceFeeBalance?: FeeBalance<Assets>;
|
|
46
|
+
sourceMinBalance: bigint;
|
|
47
|
+
getFee: (amount?: bigint) => Promise<bigint>;
|
|
48
|
+
send: (amount: bigint, cb?: (event: ExtrinsicEvent) => void) => Promise<Hash>;
|
|
49
|
+
}
|
|
50
|
+
export interface WithdrawTransferData<Assets extends Asset = Asset> {
|
|
51
|
+
asset: AssetConfigWithDecimals<Assets>;
|
|
52
|
+
destination: ChainConfig;
|
|
53
|
+
destinationBalance: bigint;
|
|
54
|
+
destinationFee: bigint;
|
|
55
|
+
existentialDeposit: bigint;
|
|
56
|
+
min: bigint;
|
|
57
|
+
native: AssetConfigWithDecimals<Assets>;
|
|
58
|
+
origin: MoonChainConfig | ChainConfig;
|
|
59
|
+
getFee: (amount: bigint) => Promise<bigint>;
|
|
60
|
+
send: (amount: bigint, cb?: (event: ExtrinsicEvent) => void) => Promise<Hash>;
|
|
61
|
+
}
|
|
62
|
+
export interface AssetConfigWithDecimals<Assets extends Asset = Asset> extends AssetConfig<Assets> {
|
|
63
|
+
decimals: number;
|
|
64
|
+
}
|
|
65
|
+
export interface FeeBalance<Assets extends Asset = Asset> {
|
|
66
|
+
amount: bigint;
|
|
67
|
+
decimals: number;
|
|
68
|
+
symbol: Assets;
|
|
69
|
+
}
|
|
70
|
+
export interface SdkOptions {
|
|
71
|
+
ethersSigner: EthersSigner;
|
|
72
|
+
polkadotSigner: PolkadotSigner;
|
|
73
|
+
}
|
|
74
|
+
export declare type ExtrinsicEvent = ExtrinsicFailedEvent | ExtrinsicSentEvent | ExtrinsicSuccessEvent;
|
|
75
|
+
export interface ExtrinsicFailedEvent {
|
|
76
|
+
blockHash: Hash;
|
|
77
|
+
message?: string;
|
|
78
|
+
status: ExtrinsicStatus.Failed;
|
|
79
|
+
txHash: Hash;
|
|
80
|
+
}
|
|
81
|
+
export interface ExtrinsicSentEvent {
|
|
82
|
+
status: ExtrinsicStatus.Sent;
|
|
83
|
+
txHash: Hash;
|
|
84
|
+
}
|
|
85
|
+
export interface ExtrinsicSuccessEvent {
|
|
86
|
+
blockHash: Hash;
|
|
87
|
+
status: ExtrinsicStatus.Success;
|
|
88
|
+
txHash: Hash;
|
|
89
|
+
}
|
|
90
|
+
export declare enum ExtrinsicStatus {
|
|
91
|
+
Failed = "Failed",
|
|
92
|
+
Sent = "Sent",
|
|
93
|
+
Success = "Success"
|
|
94
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExtrinsicStatus = void 0;
|
|
4
|
+
var ExtrinsicStatus;
|
|
5
|
+
(function (ExtrinsicStatus) {
|
|
6
|
+
ExtrinsicStatus["Failed"] = "Failed";
|
|
7
|
+
ExtrinsicStatus["Sent"] = "Sent";
|
|
8
|
+
ExtrinsicStatus["Success"] = "Success";
|
|
9
|
+
})(ExtrinsicStatus = exports.ExtrinsicStatus || (exports.ExtrinsicStatus = {}));
|
|
10
|
+
//# sourceMappingURL=sdk.interfaces.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.interfaces.js","sourceRoot":"","sources":["../../../../src/sdk/sdk.interfaces.ts"],"names":[],"mappings":";;;AA+IA,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,oCAAiB,CAAA;IACjB,gCAAa,CAAA;IACb,sCAAmB,CAAA;AACrB,CAAC,EAJW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAI1B"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
5
|
+
const xcm_config_1 = require("@moonbeam-network/xcm-config");
|
|
6
|
+
const util_1 = require("@polkadot/util");
|
|
7
|
+
const XTokensContract_1 = require("../contracts/XTokensContract");
|
|
8
|
+
const polkadot_1 = require("../polkadot");
|
|
9
|
+
const polkadot_utils_1 = require("../polkadot/polkadot.utils");
|
|
10
|
+
const sdk_utils_1 = require("./sdk.utils");
|
|
11
|
+
async function create(options) {
|
|
12
|
+
return {
|
|
13
|
+
moonbase: await createChainSdk(xcm_config_1.moonbase, options),
|
|
14
|
+
moonbeam: await createChainSdk(xcm_config_1.moonbeam, options),
|
|
15
|
+
moonriver: await createChainSdk(xcm_config_1.moonriver, options),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
exports.create = create;
|
|
19
|
+
async function createChainSdk(configGetter, options) {
|
|
20
|
+
const contract = new XTokensContract_1.XTokensContract(options.ethersSigner);
|
|
21
|
+
const polkadot = await polkadot_1.PolkadotService.create(configGetter.chain.ws);
|
|
22
|
+
return {
|
|
23
|
+
asset: configGetter.asset,
|
|
24
|
+
chain: configGetter.chain,
|
|
25
|
+
subscribeToAssetsBalanceInfo: async (account, cb) => {
|
|
26
|
+
let lastBalance = 0n;
|
|
27
|
+
let lastInfo = [];
|
|
28
|
+
const handler = (data) => {
|
|
29
|
+
const isBalance = typeof data === 'bigint';
|
|
30
|
+
lastBalance = isBalance ? data : lastBalance;
|
|
31
|
+
lastInfo = (isBalance ? lastInfo : data)
|
|
32
|
+
.map((info) => {
|
|
33
|
+
if (info.asset.isNative) {
|
|
34
|
+
// eslint-disable-next-line no-param-reassign
|
|
35
|
+
info.balance = lastBalance;
|
|
36
|
+
}
|
|
37
|
+
return info;
|
|
38
|
+
})
|
|
39
|
+
.sort(polkadot_utils_1.sortByBalanceAndChainName);
|
|
40
|
+
cb(lastInfo);
|
|
41
|
+
};
|
|
42
|
+
const unsubscribeBalance = await polkadot.subscribeToBalance(account, handler);
|
|
43
|
+
const unsubscribeInfo = await polkadot.subscribeToAssetsBalanceInfo(account, configGetter, handler);
|
|
44
|
+
return () => {
|
|
45
|
+
unsubscribeBalance();
|
|
46
|
+
unsubscribeInfo();
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
deposit: (asset) => {
|
|
50
|
+
const { chains, from } = configGetter.deposit(asset);
|
|
51
|
+
return {
|
|
52
|
+
chains,
|
|
53
|
+
from: (chain) => {
|
|
54
|
+
const { asset: assetConfig, origin, config } = from(chain);
|
|
55
|
+
return {
|
|
56
|
+
get: async (account, sourceAccount, primaryAccount) => {
|
|
57
|
+
const foreignPolkadot = await polkadot_1.PolkadotService.create(config.origin.ws);
|
|
58
|
+
const meta = foreignPolkadot.getMetadata();
|
|
59
|
+
const nativeAsset = configGetter.assets[meta.symbol];
|
|
60
|
+
const createExtrinsic = (0, sdk_utils_1.getCreateExtrinsic)({
|
|
61
|
+
account,
|
|
62
|
+
config,
|
|
63
|
+
foreignPolkadot,
|
|
64
|
+
nativeAsset,
|
|
65
|
+
polkadot,
|
|
66
|
+
primaryAccount,
|
|
67
|
+
});
|
|
68
|
+
const [decimals, sourceBalance, existentialDeposit, sourceFeeBalance, moonChainFee, sourceMinBalance = 0n, min,] = await Promise.all([
|
|
69
|
+
polkadot.getAssetDecimals(assetConfig.id),
|
|
70
|
+
foreignPolkadot.getGenericBalance(sourceAccount, config.balance),
|
|
71
|
+
foreignPolkadot.getExistentialDeposit(),
|
|
72
|
+
config.sourceFeeBalance
|
|
73
|
+
? foreignPolkadot.getGenericBalance(sourceAccount, config.sourceFeeBalance)
|
|
74
|
+
: undefined,
|
|
75
|
+
config.isNativeAssetPayingMoonFee
|
|
76
|
+
? polkadot.getAssetFee(nativeAsset.id, config.origin.weight)
|
|
77
|
+
: undefined,
|
|
78
|
+
config.sourceMinBalance
|
|
79
|
+
? foreignPolkadot.getAssetMinBalance(config.sourceMinBalance)
|
|
80
|
+
: undefined,
|
|
81
|
+
assetConfig.isNative
|
|
82
|
+
? polkadot_1.PolkadotService.getChainMin(config.origin.weight, configGetter.chain.unitsPerSecond)
|
|
83
|
+
: polkadot.getAssetFee(assetConfig.id, config.origin.weight),
|
|
84
|
+
]);
|
|
85
|
+
return {
|
|
86
|
+
asset: { ...assetConfig, decimals },
|
|
87
|
+
existentialDeposit,
|
|
88
|
+
min,
|
|
89
|
+
moonChainFee,
|
|
90
|
+
native: { ...nativeAsset, decimals: meta.decimals },
|
|
91
|
+
origin,
|
|
92
|
+
source: config.origin,
|
|
93
|
+
sourceBalance,
|
|
94
|
+
sourceFeeBalance: !(0, util_1.isUndefined)(sourceFeeBalance)
|
|
95
|
+
? { ...meta, amount: sourceFeeBalance }
|
|
96
|
+
: undefined,
|
|
97
|
+
sourceMinBalance,
|
|
98
|
+
getFee: async (amount = sourceBalance) => {
|
|
99
|
+
if (!sourceFeeBalance) {
|
|
100
|
+
return 0n;
|
|
101
|
+
}
|
|
102
|
+
const extrinsic = await createExtrinsic(amount);
|
|
103
|
+
const info = await extrinsic.paymentInfo(account);
|
|
104
|
+
return info.partialFee.toBigInt();
|
|
105
|
+
},
|
|
106
|
+
send: async (amount, cb) => {
|
|
107
|
+
const extrinsic = await createExtrinsic(amount);
|
|
108
|
+
const hash = await extrinsic.signAndSend(sourceAccount, {
|
|
109
|
+
signer: options.polkadotSigner,
|
|
110
|
+
}, cb && (0, sdk_utils_1.createExtrinsicEventHandler)(config, cb));
|
|
111
|
+
return hash.toString();
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
},
|
|
119
|
+
withdraw: (asset) => {
|
|
120
|
+
const { chains, to } = configGetter.withdraw(asset);
|
|
121
|
+
return {
|
|
122
|
+
chains,
|
|
123
|
+
to: (chain) => {
|
|
124
|
+
const { asset: assetConfig, origin, config } = to(chain);
|
|
125
|
+
return {
|
|
126
|
+
get: async (destinationAccount) => {
|
|
127
|
+
const destinationPolkadot = await polkadot_1.PolkadotService.create(config.destination.ws);
|
|
128
|
+
const meta = destinationPolkadot.getMetadata();
|
|
129
|
+
const nativeAsset = configGetter.assets[meta.symbol];
|
|
130
|
+
const [decimals, destinationBalance, existentialDeposit] = await Promise.all([
|
|
131
|
+
assetConfig.isNative
|
|
132
|
+
? configGetter.chain.decimals
|
|
133
|
+
: polkadot.getAssetDecimals(assetConfig.id),
|
|
134
|
+
destinationPolkadot.getGenericBalance(destinationAccount, config.balance),
|
|
135
|
+
destinationPolkadot.getExistentialDeposit(),
|
|
136
|
+
]);
|
|
137
|
+
const destinationFee = BigInt(config.weight * config.feePerWeight);
|
|
138
|
+
const min = destinationFee + existentialDeposit;
|
|
139
|
+
return {
|
|
140
|
+
asset: { ...assetConfig, decimals },
|
|
141
|
+
destination: config.destination,
|
|
142
|
+
destinationBalance,
|
|
143
|
+
destinationFee,
|
|
144
|
+
existentialDeposit,
|
|
145
|
+
min,
|
|
146
|
+
native: { ...nativeAsset, decimals: meta.decimals },
|
|
147
|
+
origin,
|
|
148
|
+
getFee: async (amount) => contract.getTransferFees(destinationAccount, amount, assetConfig, config),
|
|
149
|
+
send: async (amount, cb) => {
|
|
150
|
+
const tx = await contract.transfer(destinationAccount, amount, assetConfig, config);
|
|
151
|
+
if (cb) {
|
|
152
|
+
(0, sdk_utils_1.createTransactionEventHandler)(options.ethersSigner, tx.hash, cb);
|
|
153
|
+
}
|
|
154
|
+
return tx.hash;
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../../../src/sdk/sdk.ts"],"names":[],"mappings":";;;AAAA,4DAA4D;AAC5D,6DAasC;AAEtC,yCAA6C;AAC7C,kEAA+D;AAC/D,0CAAgE;AAChE,+DAAuE;AAWvE,2CAIqB;AAEd,KAAK,UAAU,MAAM,CAAC,OAAmB;IAC9C,OAAO;QACL,QAAQ,EAAE,MAAM,cAAc,CAC5B,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E;wCACN,IAAA,yCAA6B,EAC3B,OAAO,CAAC,YAAY,EACpB,EAAE,CAAC,IAAI,EACP,EAAE,CACH,CAAC;qCACH;oCAED,OAAO,EAAE,CAAC,IAAI,CAAC;gCACjB,CAAC;6BACF,CAAC;wBACJ,CAAC;qBACF,CAAC;gBACJ,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Asset, AssetConfig, Chain, DepositConfig } from '@moonbeam-network/xcm-config';
|
|
2
|
+
import { ISubmittableResult } from '@polkadot/types/types';
|
|
3
|
+
import { Signer as EthersSigner } from 'ethers';
|
|
4
|
+
import { PolkadotService } from '../polkadot';
|
|
5
|
+
import { ExtrinsicEvent, Hash, XcmSdkDeposit, XcmSdkWithdraw } from './sdk.interfaces';
|
|
6
|
+
export declare function isXcmSdkDeposit(config: XcmSdkDeposit | XcmSdkWithdraw): config is XcmSdkDeposit;
|
|
7
|
+
export declare function isXcmSdkWithdraw(config: XcmSdkDeposit | XcmSdkWithdraw): config is XcmSdkWithdraw;
|
|
8
|
+
export declare function createExtrinsicEventHandler<Assets extends Asset = Asset>(config: DepositConfig<Assets>, cb: (event: ExtrinsicEvent) => void): ({ events, status, txHash }: ISubmittableResult) => void;
|
|
9
|
+
export declare function createTransactionEventHandler(ethersSigner: EthersSigner, txHash: Hash, cb: (event: ExtrinsicEvent) => void, skipSentEvent?: boolean): Promise<void>;
|
|
10
|
+
export interface CreateExtrinsicOptions<Assets extends Asset = Asset, Chains extends Chain = Chain> {
|
|
11
|
+
account: string;
|
|
12
|
+
config: DepositConfig<Assets>;
|
|
13
|
+
foreignPolkadot: PolkadotService<Assets, Chains>;
|
|
14
|
+
nativeAsset: AssetConfig<Assets>;
|
|
15
|
+
polkadot: PolkadotService<Assets, Chains>;
|
|
16
|
+
primaryAccount?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function getCreateExtrinsic<Assets extends Asset = Asset>({ account, config, foreignPolkadot, nativeAsset, polkadot, primaryAccount, }: CreateExtrinsicOptions<Assets>): (amount: bigint) => Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", ISubmittableResult>>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCreateExtrinsic = exports.createTransactionEventHandler = exports.createExtrinsicEventHandler = exports.isXcmSdkWithdraw = exports.isXcmSdkDeposit = void 0;
|
|
4
|
+
const xcm_config_1 = require("@moonbeam-network/xcm-config");
|
|
5
|
+
const sdk_interfaces_1 = require("./sdk.interfaces");
|
|
6
|
+
function isXcmSdkDeposit(config) {
|
|
7
|
+
return !!config.from;
|
|
8
|
+
}
|
|
9
|
+
exports.isXcmSdkDeposit = isXcmSdkDeposit;
|
|
10
|
+
function isXcmSdkWithdraw(config) {
|
|
11
|
+
return !!config.to;
|
|
12
|
+
}
|
|
13
|
+
exports.isXcmSdkWithdraw = isXcmSdkWithdraw;
|
|
14
|
+
function createExtrinsicEventHandler(config, cb) {
|
|
15
|
+
return ({ events = [], status, txHash }) => {
|
|
16
|
+
const hash = txHash.toHex();
|
|
17
|
+
if (status.isReady) {
|
|
18
|
+
cb({ status: sdk_interfaces_1.ExtrinsicStatus.Sent, txHash: hash });
|
|
19
|
+
}
|
|
20
|
+
if (status.isInBlock) {
|
|
21
|
+
const block = status.asInBlock.toString();
|
|
22
|
+
events.forEach(({ event: { data, method, section } }) => {
|
|
23
|
+
if (section === config.extrinsic.pallet &&
|
|
24
|
+
method === config.extrinsic.successEvent) {
|
|
25
|
+
if (method === xcm_config_1.PolkadotXcmExtrinsicSuccessEvent.Attempted) {
|
|
26
|
+
const eventData = data.at(0);
|
|
27
|
+
if (eventData.isIncomplete) {
|
|
28
|
+
cb({
|
|
29
|
+
status: sdk_interfaces_1.ExtrinsicStatus.Failed,
|
|
30
|
+
blockHash: block,
|
|
31
|
+
txHash: hash,
|
|
32
|
+
message: eventData.asIncomplete.toHuman().join('; '),
|
|
33
|
+
});
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
cb({
|
|
38
|
+
status: sdk_interfaces_1.ExtrinsicStatus.Success,
|
|
39
|
+
blockHash: block,
|
|
40
|
+
txHash: hash,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (section === 'system' && method === 'ExtrinsicFailed') {
|
|
44
|
+
cb({
|
|
45
|
+
status: sdk_interfaces_1.ExtrinsicStatus.Failed,
|
|
46
|
+
blockHash: block,
|
|
47
|
+
txHash: hash,
|
|
48
|
+
message: data.join('; '),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
exports.createExtrinsicEventHandler = createExtrinsicEventHandler;
|
|
56
|
+
async function createTransactionEventHandler(ethersSigner, txHash, cb, skipSentEvent = false) {
|
|
57
|
+
if (!ethersSigner.provider) {
|
|
58
|
+
throw new Error('options.ethersSigner has not provider');
|
|
59
|
+
}
|
|
60
|
+
if (!skipSentEvent) {
|
|
61
|
+
cb({ status: sdk_interfaces_1.ExtrinsicStatus.Sent, txHash });
|
|
62
|
+
}
|
|
63
|
+
const tx = await ethersSigner.provider.getTransactionReceipt(txHash);
|
|
64
|
+
if (!tx) {
|
|
65
|
+
setTimeout(() => createTransactionEventHandler(ethersSigner, txHash, cb, true), 2000);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (tx.status === 1) {
|
|
69
|
+
cb({
|
|
70
|
+
status: sdk_interfaces_1.ExtrinsicStatus.Success,
|
|
71
|
+
blockHash: tx.blockHash,
|
|
72
|
+
txHash,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
cb({
|
|
77
|
+
status: sdk_interfaces_1.ExtrinsicStatus.Failed,
|
|
78
|
+
blockHash: tx.blockHash,
|
|
79
|
+
txHash,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.createTransactionEventHandler = createTransactionEventHandler;
|
|
84
|
+
function getCreateExtrinsic({ account, config, foreignPolkadot, nativeAsset, polkadot, primaryAccount, }) {
|
|
85
|
+
return async (amount) => {
|
|
86
|
+
const fee = (0, xcm_config_1.isMultiCurrency)(config.extrinsic)
|
|
87
|
+
? await polkadot.getAssetFee(nativeAsset.id, config.origin.weight)
|
|
88
|
+
: 0n;
|
|
89
|
+
return foreignPolkadot.getXcmExtrinsic(account, amount, config.extrinsic, fee, primaryAccount);
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
exports.getCreateExtrinsic = getCreateExtrinsic;
|
|
93
|
+
//# sourceMappingURL=sdk.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.utils.js","sourceRoot":"","sources":["../../../../src/sdk/sdk.utils.ts"],"names":[],"mappings":";;;AAAA,6DAOsC;AAItC,qDAM0B;AAE1B,SAAgB,eAAe,CAC7B,MAAsC;IAEtC,OAAO,CAAC,CAAE,MAAwB,CAAC,IAAI,CAAC;AAC1C,CAAC;AAJD,0CAIC;AAED,SAAgB,gBAAgB,CAC9B,MAAsC;IAEtC,OAAO,CAAC,CAAE,MAAyB,CAAC,EAAE,CAAC;AACzC,CAAC;AAJD,4CAIC;AAED,SAAgB,2BAA2B,CACzC,MAA6B,EAC7B,EAAmC;IAEnC,OAAO,CAAC,EAAE,MAAM,GAAG,EAAE,EAAE,MAAM,EAAE,MAAM,EAAsB,EAAE,EAAE;QAC7D,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;QAE5B,IAAI,MAAM,CAAC,OAAO,EAAE;YAClB,EAAE,CAAC,EAAE,MAAM,EAAE,gCAAe,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;SACpD;QAED,IAAI,MAAM,CAAC,SAAS,EAAE;YACpB,MAAM,KAAK,GAAG,MA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,cAAc,CACf,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AArBD,gDAqBC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"inputs": [
|
|
4
|
+
{
|
|
5
|
+
"internalType": "address",
|
|
6
|
+
"name": "currency_address",
|
|
7
|
+
"type": "address"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"internalType": "uint256",
|
|
11
|
+
"name": "amount",
|
|
12
|
+
"type": "uint256"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"components": [
|
|
16
|
+
{
|
|
17
|
+
"internalType": "uint8",
|
|
18
|
+
"name": "parents",
|
|
19
|
+
"type": "uint8"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"internalType": "bytes[]",
|
|
23
|
+
"name": "interior",
|
|
24
|
+
"type": "bytes[]"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"internalType": "struct Xtokens.Multilocation",
|
|
28
|
+
"name": "destination",
|
|
29
|
+
"type": "tuple"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"internalType": "uint64",
|
|
33
|
+
"name": "weight",
|
|
34
|
+
"type": "uint64"
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"name": "transfer",
|
|
38
|
+
"outputs": [],
|
|
39
|
+
"stateMutability": "nonpayable",
|
|
40
|
+
"type": "function"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"inputs": [
|
|
44
|
+
{
|
|
45
|
+
"components": [
|
|
46
|
+
{
|
|
47
|
+
"internalType": "uint8",
|
|
48
|
+
"name": "parents",
|
|
49
|
+
"type": "uint8"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"internalType": "bytes[]",
|
|
53
|
+
"name": "interior",
|
|
54
|
+
"type": "bytes[]"
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
"internalType": "struct Xtokens.Multilocation",
|
|
58
|
+
"name": "asset",
|
|
59
|
+
"type": "tuple"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"internalType": "uint256",
|
|
63
|
+
"name": "amount",
|
|
64
|
+
"type": "uint256"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"components": [
|
|
68
|
+
{
|
|
69
|
+
"internalType": "uint8",
|
|
70
|
+
"name": "parents",
|
|
71
|
+
"type": "uint8"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"internalType": "bytes[]",
|
|
75
|
+
"name": "interior",
|
|
76
|
+
"type": "bytes[]"
|
|
77
|
+
}
|
|
78
|
+
],
|
|
79
|
+
"internalType": "struct Xtokens.Multilocation",
|
|
80
|
+
"name": "destination",
|
|
81
|
+
"type": "tuple"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"internalType": "uint64",
|
|
85
|
+
"name": "weight",
|
|
86
|
+
"type": "uint64"
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
"name": "transfer_multiasset",
|
|
90
|
+
"outputs": [],
|
|
91
|
+
"stateMutability": "nonpayable",
|
|
92
|
+
"type": "function"
|
|
93
|
+
}
|
|
94
|
+
]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
2
|
+
import { Asset, AssetConfig, WithdrawXTokensConfig } from '@moonbeam-network/xcm-config';
|
|
3
|
+
import { Signer } from 'ethers';
|
|
4
|
+
export declare class XTokensContract<Assets extends Asset = Asset> {
|
|
5
|
+
#private;
|
|
6
|
+
readonly address: string;
|
|
7
|
+
constructor(signer: Signer);
|
|
8
|
+
transfer(account: string, amount: bigint, asset: AssetConfig<Assets>, config: WithdrawXTokensConfig<Assets>): Promise<TransactionResponse>;
|
|
9
|
+
getTransferFees(account: string, amount: bigint, asset: AssetConfig<Assets>, config: WithdrawXTokensConfig<Assets>): Promise<bigint>;
|
|
10
|
+
private getGasPrice;
|
|
11
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _XTokensContract_contract, _XTokensContract_signer;
|
|
13
|
+
import { Contract } from 'ethers';
|
|
14
|
+
import ContractInterface from './XTokensABI.json';
|
|
15
|
+
export class XTokensContract {
|
|
16
|
+
constructor(signer) {
|
|
17
|
+
this.address = '0x0000000000000000000000000000000000000804';
|
|
18
|
+
_XTokensContract_contract.set(this, void 0);
|
|
19
|
+
_XTokensContract_signer.set(this, void 0);
|
|
20
|
+
__classPrivateFieldSet(this, _XTokensContract_signer, signer, "f");
|
|
21
|
+
__classPrivateFieldSet(this, _XTokensContract_contract, new Contract(this.address, ContractInterface, signer), "f");
|
|
22
|
+
}
|
|
23
|
+
async transfer(account, amount, asset, config) {
|
|
24
|
+
return __classPrivateFieldGet(this, _XTokensContract_contract, "f").transfer(asset.erc20Id, amount, config.getParams(account), config.weight);
|
|
25
|
+
}
|
|
26
|
+
async getTransferFees(account, amount, asset, config) {
|
|
27
|
+
const estimatedGas = (await __classPrivateFieldGet(this, _XTokensContract_contract, "f").estimateGas.transfer(asset.erc20Id, amount, config.getParams(account), config.weight)).toBigInt();
|
|
28
|
+
const gasPrice = await this.getGasPrice();
|
|
29
|
+
return estimatedGas * gasPrice;
|
|
30
|
+
}
|
|
31
|
+
async getGasPrice() {
|
|
32
|
+
const { gasPrice, maxPriorityFeePerGas } = await __classPrivateFieldGet(this, _XTokensContract_signer, "f").getFeeData();
|
|
33
|
+
return ((gasPrice?.toBigInt() || 0n) + (maxPriorityFeePerGas?.toBigInt() || 0n));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
_XTokensContract_contract = new WeakMap(), _XTokensContract_signer = new WeakMap();
|
|
37
|
+
//# sourceMappingURL=XTokensContract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"XTokensContract.js","sourceRoot":"","sources":["../../../../../src/contracts/XTokensContract/XTokensContract.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,OAAO,EAAE,QAAQ,EAAU,MAAM,QAAQ,CAAC;AAE1C,OAAO,iBAAiB,MAAM,mBAAmB,CAAC;AAElD,MAAM,OAAO,eAAe;IAO1B,YAAY,MAAc;QANjB,YAAO,GAAW,4CAA4C,CAAC;QAExE,4CAA6B;QAE7B,0CAAyB;QAGvB,uBAAA,IAAI,2BAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,6BAAa,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,CAAC,MAAA,CAAC;IACzE,CAAC;IAED,KAAK,CAAC,QAAQ,CACZ,OAAe,EACf,MAAc,EACd,KAA0B,EAC1B,MAAqC;QAErC,OAAO,uBAAA,IAAI,iCAAU,CAAC,QAAQ,CAC5B,KAAK,CAAC,OAAO,EACb,MAAM,EACN,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,EACzB,MAAM,CAAC,MAAM,CACd,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,eAAe,CACnB,OAAe,EACf,MAAc,EACd,KAA0B,EAC1B,MAAqC;QAErC,MAAM,YAAY,GAAG,CACnB,MAAM,uBAAA,IAAI,iCAAU,CAAC,WAAW,CAAC,QAAQ,CACvC,KAAK,CAAC,OAAO,EACb,MAAM,EACN,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,EACzB,MAAM,CAAC,MAAM,CACd,CACF,CAAC,QAAQ,EAAE,CAAC;QACb,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QAE1C,OAAO,YAAY,GAAG,QAAQ,CAAC;IACjC,CAAC;IAEO,KAAK,CAAC,WAAW;QACvB,MAAM,EAAE,QAAQ,EAAE,oBAAoB,EAAE,GAAG,MAAM,uBAAA,IAAI,+BAAQ,CAAC,UAAU,EAAE,CAAC;QAE3E,OAAO,CACL,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,oBAAoB,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CACxE,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { XTokensContract } from './XTokensContract';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/contracts/XTokensContract/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './XTokensContract';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/contracts/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,OAAO,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import '@moonbeam-network/api-augment';
|
|
2
|
+
import { Asset, BalanceConfig, Chain, ConfigGetter, ExtrinsicConfig, MinBalanceConfig } from '@moonbeam-network/xcm-config';
|
|
3
|
+
import { ApiPromise } from '@polkadot/api';
|
|
4
|
+
import { SubmittableExtrinsic, UnsubscribePromise } from '@polkadot/api/types';
|
|
5
|
+
import { AccountInfo } from '@polkadot/types/interfaces';
|
|
6
|
+
import { MoonbeamRuntimeXcmConfigAssetType, PalletAssetsAssetAccount, PalletAssetsAssetMetadata } from '@polkadot/types/lookup';
|
|
7
|
+
import { AssetBalanceInfo } from './polkadot.interfaces';
|
|
8
|
+
export declare class PolkadotService<Assets extends Asset = Asset, Chains extends Chain = Chain> {
|
|
9
|
+
#private;
|
|
10
|
+
constructor(api: ApiPromise);
|
|
11
|
+
static create<Assets extends Asset = Asset, Chains extends Chain = Chain>(ws: string): Promise<PolkadotService<Assets, Chains>>;
|
|
12
|
+
static getChainMin(weight: number, unitsPerSecond: bigint): bigint;
|
|
13
|
+
getMetadata(): {
|
|
14
|
+
decimals: number;
|
|
15
|
+
symbol: Assets;
|
|
16
|
+
};
|
|
17
|
+
getExistentialDeposit(): bigint;
|
|
18
|
+
getAssetDecimals(assetId: string): Promise<number>;
|
|
19
|
+
getAssetMeta(assetId: string): Promise<PalletAssetsAssetMetadata>;
|
|
20
|
+
subscribeToAccountInfo(account: string, callback: (info: AccountInfo) => void): UnsubscribePromise;
|
|
21
|
+
subscribeToBalance(account: string, callback: (balance: bigint) => void): UnsubscribePromise;
|
|
22
|
+
getGenericBalance(account: string, { pallet, function: fn, getParams, path, calc }: BalanceConfig<Assets>): Promise<bigint>;
|
|
23
|
+
getAssetMinBalance({ pallet, function: fn, params, path, }: MinBalanceConfig): Promise<bigint>;
|
|
24
|
+
getXcmExtrinsic(account: string, amount: bigint, { pallet, extrinsic, getParams }: ExtrinsicConfig<Assets>, fee?: bigint, primaryAccount?: string): SubmittableExtrinsic<'promise'>;
|
|
25
|
+
getAssetFee(id: string, weight: number): Promise<bigint>;
|
|
26
|
+
getAssetType(id: string): Promise<MoonbeamRuntimeXcmConfigAssetType | undefined>;
|
|
27
|
+
subscribeToAssetsBalanceInfo(account: string, configGetter: ConfigGetter<Assets, Chains>, callback: (data: AssetBalanceInfo<Assets>[]) => void): UnsubscribePromise;
|
|
28
|
+
subscribeToAccountBalances(account: string, ids: string[], callback: (balances: PalletAssetsAssetAccount[]) => void): UnsubscribePromise;
|
|
29
|
+
}
|