@xchainjs/xchain-radix 1.0.4 → 1.1.0
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/lib/client.d.ts +2 -31
- package/lib/const.d.ts +3 -6
- package/lib/index.d.ts +1 -0
- package/lib/index.esm.js +74 -40
- package/lib/index.js +77 -40
- package/lib/radix-client.d.ts +33 -0
- package/lib/types/radix.d.ts +8 -1
- package/lib/utils.d.ts +34 -5
- package/package.json +1 -1
package/lib/client.d.ts
CHANGED
|
@@ -1,38 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
3
|
-
import { Curve, Intent, NotarizedTransaction, PrivateKey, PublicKey, TransactionHash } from '@radixdlt/radix-engine-toolkit';
|
|
2
|
+
import { Curve, PrivateKey } from '@radixdlt/radix-engine-toolkit';
|
|
4
3
|
import { AssetInfo, BaseXChainClient, Fees, Network, PreparedTx, TxHistoryParams, XChainClientParams } from '@xchainjs/xchain-client';
|
|
5
4
|
import { Address } from '@xchainjs/xchain-util';
|
|
5
|
+
import { RadixSpecificClient } from './radix-client';
|
|
6
6
|
import { Balance, CompatibleAsset, Tx, TxParams, TxsPage } from './types/radix';
|
|
7
|
-
/**
|
|
8
|
-
* The main client for the Radix network which is then wrapped by the {Client} adapting it to have
|
|
9
|
-
* a {BaseXChainClient} interface.
|
|
10
|
-
*/
|
|
11
|
-
export declare class RadixSpecificClient {
|
|
12
|
-
private innerNetwork;
|
|
13
|
-
private innerGatewayClient;
|
|
14
|
-
constructor(networkId: number);
|
|
15
|
-
set networkId(networkId: number);
|
|
16
|
-
get networkId(): number;
|
|
17
|
-
get gatewayClient(): GatewayApiClient;
|
|
18
|
-
currentEpoch(): Promise<number>;
|
|
19
|
-
currentStateVersion(): Promise<number>;
|
|
20
|
-
fetchBalances(address: string): Promise<Balance[]>;
|
|
21
|
-
fetchNFTBalances(address: string): Promise<Balance[]>;
|
|
22
|
-
private convertResourcesToBalances;
|
|
23
|
-
private fetchNonFungibleResources;
|
|
24
|
-
private fetchFungibleResources;
|
|
25
|
-
constructSimpleTransferIntent(from: string, to: string, resourceAddress: string, amount: number, notaryPublicKey: PublicKey, message?: string): Promise<{
|
|
26
|
-
intent: Intent;
|
|
27
|
-
fees: number;
|
|
28
|
-
}>;
|
|
29
|
-
submitTransaction(notarizedTransaction: NotarizedTransaction): Promise<[TransactionSubmitResponse, TransactionHash]>;
|
|
30
|
-
private static createGatewayClient;
|
|
31
|
-
private static simpleTransferManifest;
|
|
32
|
-
private constructIntent;
|
|
33
|
-
private previewIntent;
|
|
34
|
-
private static retPublicKeyToGatewayPublicKey;
|
|
35
|
-
}
|
|
36
7
|
/**
|
|
37
8
|
* Custom Radix client
|
|
38
9
|
*/
|
package/lib/const.d.ts
CHANGED
|
@@ -4,12 +4,12 @@ import { Asset } from '@xchainjs/xchain-util';
|
|
|
4
4
|
* Chain identifier for Radix.
|
|
5
5
|
* This constant represents the identifier for the Radix Chain.
|
|
6
6
|
*/
|
|
7
|
-
export declare const RadixChain: "
|
|
7
|
+
export declare const RadixChain: "XRD";
|
|
8
8
|
export declare const MAINNET_GATEWAY_URL = "https://mainnet.radixdlt.com";
|
|
9
9
|
export declare const STOKENET_GATEWAY_URL = "https://stokenet.radixdlt.com";
|
|
10
10
|
export declare const XRD_DECIMAL = 18;
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
11
|
+
export declare const RADIX_ASSET_RESOURCE = "resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc";
|
|
12
|
+
export declare const AssetXRD: Asset;
|
|
13
13
|
export declare const xrdRootDerivationPaths: RootDerivationPaths;
|
|
14
14
|
export declare const bech32Networks: {
|
|
15
15
|
[key: number]: string;
|
|
@@ -26,7 +26,4 @@ interface FeesEstimationParams {
|
|
|
26
26
|
export declare const feesEstimationPublicKeys: {
|
|
27
27
|
[networkId: number]: FeesEstimationParams;
|
|
28
28
|
};
|
|
29
|
-
export declare const assets: {
|
|
30
|
-
[networkId: number]: Asset;
|
|
31
|
-
};
|
|
32
29
|
export {};
|
package/lib/index.d.ts
CHANGED
package/lib/index.esm.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { NetworkId, PrivateKey, generateRandomNonce, RadixEngineToolkit, Convert, ManifestBuilder, decimal, address, bucket, enumeration, PublicKey, LTSRadixEngineToolkit, TransactionBuilder } from '@radixdlt/radix-engine-toolkit';
|
|
1
|
+
import { NetworkId, generateRandomNonce, RadixEngineToolkit, Convert, ManifestBuilder, decimal, address, bucket, enumeration, str, PrivateKey, PublicKey, LTSRadixEngineToolkit, TransactionBuilder } from '@radixdlt/radix-engine-toolkit';
|
|
3
2
|
import { Network, BaseXChainClient, singleFee, FeeType, TxType } from '@xchainjs/xchain-client';
|
|
4
3
|
import { getSeed } from '@xchainjs/xchain-crypto';
|
|
5
|
-
import { AssetType, assetToBase, assetAmount, baseAmount } from '@xchainjs/xchain-util';
|
|
4
|
+
import { AssetType, assetToBase, assetAmount, eqAsset, baseAmount } from '@xchainjs/xchain-util';
|
|
6
5
|
import { bech32m } from 'bech32';
|
|
7
6
|
import BIP32Factory from 'bip32';
|
|
8
7
|
import { derivePath } from 'ed25519-hd-key';
|
|
@@ -10,6 +9,7 @@ import require$$0$1 from 'buffer';
|
|
|
10
9
|
import require$$1 from 'stream';
|
|
11
10
|
import require$$2 from 'string_decoder';
|
|
12
11
|
import require$$0$2 from 'events';
|
|
12
|
+
import { GatewayApiClient } from '@radixdlt/babylon-gateway-api-sdk';
|
|
13
13
|
|
|
14
14
|
function _mergeNamespaces(n, m) {
|
|
15
15
|
m.forEach(function (e) {
|
|
@@ -13902,18 +13902,13 @@ var ecc = /*#__PURE__*/_mergeNamespaces({
|
|
|
13902
13902
|
* Chain identifier for Radix.
|
|
13903
13903
|
* This constant represents the identifier for the Radix Chain.
|
|
13904
13904
|
*/
|
|
13905
|
-
const RadixChain = '
|
|
13905
|
+
const RadixChain = 'XRD';
|
|
13906
13906
|
const MAINNET_GATEWAY_URL = 'https://mainnet.radixdlt.com';
|
|
13907
13907
|
const STOKENET_GATEWAY_URL = 'https://stokenet.radixdlt.com';
|
|
13908
13908
|
const XRD_DECIMAL = 18;
|
|
13909
|
-
const
|
|
13910
|
-
|
|
13911
|
-
|
|
13912
|
-
type: AssetType.NATIVE,
|
|
13913
|
-
chain: RadixChain,
|
|
13914
|
-
};
|
|
13915
|
-
const XrdAssetStokenet = {
|
|
13916
|
-
symbol: 'resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc',
|
|
13909
|
+
const RADIX_ASSET_RESOURCE = 'resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc';
|
|
13910
|
+
const AssetXRD = {
|
|
13911
|
+
symbol: `XRD`,
|
|
13917
13912
|
ticker: 'XRD',
|
|
13918
13913
|
type: AssetType.NATIVE,
|
|
13919
13914
|
chain: RadixChain,
|
|
@@ -13937,30 +13932,17 @@ const feesEstimationPublicKeys = {
|
|
|
13937
13932
|
[NetworkId.Mainnet]: {
|
|
13938
13933
|
from: 'account_rdx12xh48d5s9u7me5t49z25lrm4h73wclqpjvumd49ctf0ggnyazc62m8',
|
|
13939
13934
|
to: 'account_rdx1685t40mreptjhs9g3pg9lgf7k7rgppzjeknjgrpc7d0sumcjrsw6kj',
|
|
13940
|
-
resourceAddress:
|
|
13935
|
+
resourceAddress: RADIX_ASSET_RESOURCE,
|
|
13941
13936
|
publicKey: 'a47e22f21e16d80374f16d66224b56f6eda82a6db8279de267a74a49f0291e8b',
|
|
13942
13937
|
},
|
|
13943
13938
|
[NetworkId.Stokenet]: {
|
|
13944
13939
|
from: 'account_tdx_2_12927ya6vxtmhu8w0qkwtumw8kjmlv930agjzezfgg6yp3j6agn3gfc',
|
|
13945
13940
|
to: 'account_tdx_2_12xnfu4evyseqeq57rzhrh8ls6wy76vvc4jnw2kzx3l5ka7wyddxh3l',
|
|
13946
|
-
resourceAddress:
|
|
13941
|
+
resourceAddress: RADIX_ASSET_RESOURCE,
|
|
13947
13942
|
publicKey: '3ce4d36fd8bf40fa6f9b0cf2ef8d11853d088589ebdc79055f5a0af55bf7e758',
|
|
13948
13943
|
},
|
|
13949
13944
|
};
|
|
13950
|
-
const assets = {
|
|
13951
|
-
[NetworkId.Mainnet]: XrdAssetMainnet,
|
|
13952
|
-
[NetworkId.Stokenet]: XrdAssetStokenet,
|
|
13953
|
-
};
|
|
13954
13945
|
|
|
13955
|
-
const xChainJsNetworkToRadixNetworkId = (network) => {
|
|
13956
|
-
switch (network) {
|
|
13957
|
-
case Network.Mainnet:
|
|
13958
|
-
case Network.Stagenet:
|
|
13959
|
-
return NetworkId.Mainnet;
|
|
13960
|
-
case Network.Testnet:
|
|
13961
|
-
return NetworkId.Stokenet;
|
|
13962
|
-
}
|
|
13963
|
-
};
|
|
13964
13946
|
/**
|
|
13965
13947
|
* The main client for the Radix network which is then wrapped by the {Client} adapting it to have
|
|
13966
13948
|
* a {BaseXChainClient} interface.
|
|
@@ -14109,14 +14091,16 @@ class RadixSpecificClient {
|
|
|
14109
14091
|
return fungibleResources;
|
|
14110
14092
|
});
|
|
14111
14093
|
}
|
|
14112
|
-
|
|
14094
|
+
constructTransferIntent(from, to, resourceAddress, amount, notaryPublicKey, message, methodsToCall) {
|
|
14113
14095
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14114
14096
|
// This nonce will be used for preview and also when constructing the final transaction
|
|
14115
14097
|
const nonce = generateRandomNonce();
|
|
14116
14098
|
// Construct the intent with a random fee lock, say 5 XRD and then create a transaction intent
|
|
14117
14099
|
// from it.
|
|
14118
|
-
const manifestWithHardcodedFee =
|
|
14119
|
-
|
|
14100
|
+
const manifestWithHardcodedFee = methodsToCall
|
|
14101
|
+
? RadixSpecificClient.createCustomTransferManifest(from, resourceAddress, amount, 5, methodsToCall)
|
|
14102
|
+
: RadixSpecificClient.createSimpleTransferManifest(from, to, resourceAddress, amount, 5);
|
|
14103
|
+
const intentWithHardcodedFee = yield this.constructIntent(manifestWithHardcodedFee, message === null || message === undefined
|
|
14120
14104
|
? { kind: 'None' }
|
|
14121
14105
|
: {
|
|
14122
14106
|
kind: 'PlainText',
|
|
@@ -14125,7 +14109,7 @@ class RadixSpecificClient {
|
|
|
14125
14109
|
const previewReceipt = (yield this.previewIntent(intentWithHardcodedFee));
|
|
14126
14110
|
// Ensure that the preview was successful.
|
|
14127
14111
|
if (previewReceipt.receipt.status !== 'Succeeded') {
|
|
14128
|
-
throw new Error(
|
|
14112
|
+
throw new Error(`Preview for fees was not successful.`);
|
|
14129
14113
|
}
|
|
14130
14114
|
// Calculate the total fees
|
|
14131
14115
|
const totalFees = [
|
|
@@ -14141,8 +14125,10 @@ class RadixSpecificClient {
|
|
|
14141
14125
|
// to actually submit the transaction, ie: signature validation
|
|
14142
14126
|
const totalFeesPlus10Percent = totalFees * 1.1;
|
|
14143
14127
|
// Construct a new intent with the calculated fees.
|
|
14144
|
-
const manifest =
|
|
14145
|
-
|
|
14128
|
+
const manifest = methodsToCall
|
|
14129
|
+
? RadixSpecificClient.createCustomTransferManifest(from, resourceAddress, amount, totalFeesPlus10Percent, methodsToCall)
|
|
14130
|
+
: RadixSpecificClient.createSimpleTransferManifest(from, to, resourceAddress, amount, totalFeesPlus10Percent);
|
|
14131
|
+
const intent = yield this.constructIntent(manifest, message === null || message === undefined
|
|
14146
14132
|
? { kind: 'None' }
|
|
14147
14133
|
: {
|
|
14148
14134
|
kind: 'PlainText',
|
|
@@ -14173,7 +14159,7 @@ class RadixSpecificClient {
|
|
|
14173
14159
|
applicationName,
|
|
14174
14160
|
});
|
|
14175
14161
|
}
|
|
14176
|
-
static
|
|
14162
|
+
static createSimpleTransferManifest(from, to, resourceAddress, amount, amountToLockForFees) {
|
|
14177
14163
|
return new ManifestBuilder()
|
|
14178
14164
|
.callMethod(from, 'lock_fee', [decimal(amountToLockForFees)])
|
|
14179
14165
|
.callMethod(from, 'withdraw', [address(resourceAddress), decimal(amount)])
|
|
@@ -14182,6 +14168,15 @@ class RadixSpecificClient {
|
|
|
14182
14168
|
})
|
|
14183
14169
|
.build();
|
|
14184
14170
|
}
|
|
14171
|
+
static createCustomTransferManifest(from, resourceAddress, amount, amountToLockForFees, methodsToCall) {
|
|
14172
|
+
const simpletTx = new ManifestBuilder()
|
|
14173
|
+
.callMethod(from, 'lock_fee', [decimal(amountToLockForFees)])
|
|
14174
|
+
.callMethod(from, 'withdraw', [address(resourceAddress), decimal(amount)])
|
|
14175
|
+
.takeFromWorktop(resourceAddress, decimal(amount).value, (builder) => {
|
|
14176
|
+
return builder.callMethod(methodsToCall.address, methodsToCall.methodName, methodsToCall.params);
|
|
14177
|
+
});
|
|
14178
|
+
return simpletTx.build();
|
|
14179
|
+
}
|
|
14185
14180
|
constructIntent(manifest, message, nonce, notaryPublicKey) {
|
|
14186
14181
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14187
14182
|
const epoch = yield this.currentEpoch();
|
|
@@ -14240,6 +14235,45 @@ class RadixSpecificClient {
|
|
|
14240
14235
|
}
|
|
14241
14236
|
}
|
|
14242
14237
|
}
|
|
14238
|
+
|
|
14239
|
+
/**
|
|
14240
|
+
* Returns the resource id of an asset
|
|
14241
|
+
* @param {Asset | TokenAsset} asset asset
|
|
14242
|
+
* @returns Resource id
|
|
14243
|
+
*/
|
|
14244
|
+
const getAssetResource = (asset) => {
|
|
14245
|
+
if (eqAsset(asset, AssetXRD))
|
|
14246
|
+
return RADIX_ASSET_RESOURCE;
|
|
14247
|
+
return asset.symbol.slice(asset.ticker.length + 1);
|
|
14248
|
+
};
|
|
14249
|
+
/**
|
|
14250
|
+
* Generates a address param for a call method
|
|
14251
|
+
* @param {Address} addr Address to transform to Radix Address parameter
|
|
14252
|
+
* @returns the address in the Radix Address parameter format
|
|
14253
|
+
*/
|
|
14254
|
+
const generateAddressParam = (addr) => address(addr);
|
|
14255
|
+
/**
|
|
14256
|
+
* Generates a string param for a call method
|
|
14257
|
+
* @param {string} s Address to transform to Radix string parameter
|
|
14258
|
+
* @returns the string in the Radix String parameter format
|
|
14259
|
+
*/
|
|
14260
|
+
const generateStringParam = (s) => str(s);
|
|
14261
|
+
/**
|
|
14262
|
+
* Generates a bucket param for a call method
|
|
14263
|
+
* @param {number} value Value to transform to Radix Bucket parameter
|
|
14264
|
+
* @returns the value in the Radix Bucket parameter format
|
|
14265
|
+
*/
|
|
14266
|
+
const generateBucketParam = (value) => bucket(value);
|
|
14267
|
+
|
|
14268
|
+
const xChainJsNetworkToRadixNetworkId = (network) => {
|
|
14269
|
+
switch (network) {
|
|
14270
|
+
case Network.Mainnet:
|
|
14271
|
+
case Network.Stagenet:
|
|
14272
|
+
return NetworkId.Mainnet;
|
|
14273
|
+
case Network.Testnet:
|
|
14274
|
+
return NetworkId.Stokenet;
|
|
14275
|
+
}
|
|
14276
|
+
};
|
|
14243
14277
|
/**
|
|
14244
14278
|
* Custom Radix client
|
|
14245
14279
|
*/
|
|
@@ -14275,7 +14309,7 @@ class Client extends BaseXChainClient {
|
|
|
14275
14309
|
// TODO: This can fail if we use it on stokenet, we need to replace these with network aware
|
|
14276
14310
|
// addresses.
|
|
14277
14311
|
const feesInXrd = yield this.radixSpecificClient
|
|
14278
|
-
.
|
|
14312
|
+
.constructTransferIntent(feesEstimationPublicKeys[this.getRadixNetwork()].from, feesEstimationPublicKeys[this.getRadixNetwork()].to, feesEstimationPublicKeys[this.getRadixNetwork()].resourceAddress, 0, new PublicKey.Ed25519(Convert.HexString.toUint8Array(feesEstimationPublicKeys[this.getRadixNetwork()].publicKey)), 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
|
|
14279
14313
|
.then((result) => result.fees);
|
|
14280
14314
|
// We need to add another 10% to the fees as the preview response does not include everything needed
|
|
14281
14315
|
// to actually submit the transaction, ie: signature validation
|
|
@@ -14562,7 +14596,7 @@ class Client extends BaseXChainClient {
|
|
|
14562
14596
|
return {
|
|
14563
14597
|
from: [],
|
|
14564
14598
|
to: [],
|
|
14565
|
-
asset:
|
|
14599
|
+
asset: AssetXRD,
|
|
14566
14600
|
date: confirmed_at,
|
|
14567
14601
|
type: TxType.Unknown,
|
|
14568
14602
|
hash: intent_hash,
|
|
@@ -14615,13 +14649,13 @@ class Client extends BaseXChainClient {
|
|
|
14615
14649
|
* @returns a PreparedTx
|
|
14616
14650
|
*/
|
|
14617
14651
|
prepareTx(params) {
|
|
14618
|
-
var _a
|
|
14652
|
+
var _a;
|
|
14619
14653
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14620
14654
|
const walletIndex = (_a = params.walletIndex) !== null && _a !== void 0 ? _a : 0;
|
|
14621
14655
|
const from = yield this.getAddressAsync();
|
|
14622
14656
|
const transferAmmount = params.amount.amount().toNumber() / Math.pow(10, XRD_DECIMAL);
|
|
14623
14657
|
const intent = yield this.radixSpecificClient
|
|
14624
|
-
.
|
|
14658
|
+
.constructTransferIntent(from, params.recipient, getAssetResource(params.asset || this.getAssetInfo().asset), transferAmmount, this.getRadixPrivateKey(walletIndex).publicKey(), params.memo, params.methodToCall)
|
|
14625
14659
|
.then((response) => response.intent);
|
|
14626
14660
|
const compiledIntent = yield RadixEngineToolkit.Intent.compile(intent);
|
|
14627
14661
|
return {
|
|
@@ -14635,10 +14669,10 @@ class Client extends BaseXChainClient {
|
|
|
14635
14669
|
*/
|
|
14636
14670
|
getAssetInfo() {
|
|
14637
14671
|
return {
|
|
14638
|
-
asset:
|
|
14672
|
+
asset: AssetXRD,
|
|
14639
14673
|
decimal: XRD_DECIMAL,
|
|
14640
14674
|
};
|
|
14641
14675
|
}
|
|
14642
14676
|
}
|
|
14643
14677
|
|
|
14644
|
-
export { Client, MAINNET_GATEWAY_URL, RadixChain, STOKENET_GATEWAY_URL, XRD_DECIMAL,
|
|
14678
|
+
export { AssetXRD, Client, MAINNET_GATEWAY_URL, RADIX_ASSET_RESOURCE, RadixChain, STOKENET_GATEWAY_URL, XRD_DECIMAL, bech32Lengths, bech32Networks, feesEstimationPublicKeys, generateAddressParam, generateBucketParam, generateStringParam, getAssetResource, xrdRootDerivationPaths };
|
package/lib/index.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var babylonGatewayApiSdk = require('@radixdlt/babylon-gateway-api-sdk');
|
|
6
5
|
var radixEngineToolkit = require('@radixdlt/radix-engine-toolkit');
|
|
7
6
|
var xchainClient = require('@xchainjs/xchain-client');
|
|
8
7
|
var xchainCrypto = require('@xchainjs/xchain-crypto');
|
|
@@ -14,6 +13,7 @@ var require$$0$1 = require('buffer');
|
|
|
14
13
|
var require$$1 = require('stream');
|
|
15
14
|
var require$$2 = require('string_decoder');
|
|
16
15
|
var require$$0$2 = require('events');
|
|
16
|
+
var babylonGatewayApiSdk = require('@radixdlt/babylon-gateway-api-sdk');
|
|
17
17
|
|
|
18
18
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
19
19
|
|
|
@@ -13914,18 +13914,13 @@ var ecc = /*#__PURE__*/_mergeNamespaces({
|
|
|
13914
13914
|
* Chain identifier for Radix.
|
|
13915
13915
|
* This constant represents the identifier for the Radix Chain.
|
|
13916
13916
|
*/
|
|
13917
|
-
const RadixChain = '
|
|
13917
|
+
const RadixChain = 'XRD';
|
|
13918
13918
|
const MAINNET_GATEWAY_URL = 'https://mainnet.radixdlt.com';
|
|
13919
13919
|
const STOKENET_GATEWAY_URL = 'https://stokenet.radixdlt.com';
|
|
13920
13920
|
const XRD_DECIMAL = 18;
|
|
13921
|
-
const
|
|
13922
|
-
|
|
13923
|
-
|
|
13924
|
-
type: xchainUtil.AssetType.NATIVE,
|
|
13925
|
-
chain: RadixChain,
|
|
13926
|
-
};
|
|
13927
|
-
const XrdAssetStokenet = {
|
|
13928
|
-
symbol: 'resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc',
|
|
13921
|
+
const RADIX_ASSET_RESOURCE = 'resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc';
|
|
13922
|
+
const AssetXRD = {
|
|
13923
|
+
symbol: `XRD`,
|
|
13929
13924
|
ticker: 'XRD',
|
|
13930
13925
|
type: xchainUtil.AssetType.NATIVE,
|
|
13931
13926
|
chain: RadixChain,
|
|
@@ -13949,30 +13944,17 @@ const feesEstimationPublicKeys = {
|
|
|
13949
13944
|
[radixEngineToolkit.NetworkId.Mainnet]: {
|
|
13950
13945
|
from: 'account_rdx12xh48d5s9u7me5t49z25lrm4h73wclqpjvumd49ctf0ggnyazc62m8',
|
|
13951
13946
|
to: 'account_rdx1685t40mreptjhs9g3pg9lgf7k7rgppzjeknjgrpc7d0sumcjrsw6kj',
|
|
13952
|
-
resourceAddress:
|
|
13947
|
+
resourceAddress: RADIX_ASSET_RESOURCE,
|
|
13953
13948
|
publicKey: 'a47e22f21e16d80374f16d66224b56f6eda82a6db8279de267a74a49f0291e8b',
|
|
13954
13949
|
},
|
|
13955
13950
|
[radixEngineToolkit.NetworkId.Stokenet]: {
|
|
13956
13951
|
from: 'account_tdx_2_12927ya6vxtmhu8w0qkwtumw8kjmlv930agjzezfgg6yp3j6agn3gfc',
|
|
13957
13952
|
to: 'account_tdx_2_12xnfu4evyseqeq57rzhrh8ls6wy76vvc4jnw2kzx3l5ka7wyddxh3l',
|
|
13958
|
-
resourceAddress:
|
|
13953
|
+
resourceAddress: RADIX_ASSET_RESOURCE,
|
|
13959
13954
|
publicKey: '3ce4d36fd8bf40fa6f9b0cf2ef8d11853d088589ebdc79055f5a0af55bf7e758',
|
|
13960
13955
|
},
|
|
13961
13956
|
};
|
|
13962
|
-
const assets = {
|
|
13963
|
-
[radixEngineToolkit.NetworkId.Mainnet]: XrdAssetMainnet,
|
|
13964
|
-
[radixEngineToolkit.NetworkId.Stokenet]: XrdAssetStokenet,
|
|
13965
|
-
};
|
|
13966
13957
|
|
|
13967
|
-
const xChainJsNetworkToRadixNetworkId = (network) => {
|
|
13968
|
-
switch (network) {
|
|
13969
|
-
case xchainClient.Network.Mainnet:
|
|
13970
|
-
case xchainClient.Network.Stagenet:
|
|
13971
|
-
return radixEngineToolkit.NetworkId.Mainnet;
|
|
13972
|
-
case xchainClient.Network.Testnet:
|
|
13973
|
-
return radixEngineToolkit.NetworkId.Stokenet;
|
|
13974
|
-
}
|
|
13975
|
-
};
|
|
13976
13958
|
/**
|
|
13977
13959
|
* The main client for the Radix network which is then wrapped by the {Client} adapting it to have
|
|
13978
13960
|
* a {BaseXChainClient} interface.
|
|
@@ -14121,14 +14103,16 @@ class RadixSpecificClient {
|
|
|
14121
14103
|
return fungibleResources;
|
|
14122
14104
|
});
|
|
14123
14105
|
}
|
|
14124
|
-
|
|
14106
|
+
constructTransferIntent(from, to, resourceAddress, amount, notaryPublicKey, message, methodsToCall) {
|
|
14125
14107
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14126
14108
|
// This nonce will be used for preview and also when constructing the final transaction
|
|
14127
14109
|
const nonce = radixEngineToolkit.generateRandomNonce();
|
|
14128
14110
|
// Construct the intent with a random fee lock, say 5 XRD and then create a transaction intent
|
|
14129
14111
|
// from it.
|
|
14130
|
-
const manifestWithHardcodedFee =
|
|
14131
|
-
|
|
14112
|
+
const manifestWithHardcodedFee = methodsToCall
|
|
14113
|
+
? RadixSpecificClient.createCustomTransferManifest(from, resourceAddress, amount, 5, methodsToCall)
|
|
14114
|
+
: RadixSpecificClient.createSimpleTransferManifest(from, to, resourceAddress, amount, 5);
|
|
14115
|
+
const intentWithHardcodedFee = yield this.constructIntent(manifestWithHardcodedFee, message === null || message === undefined
|
|
14132
14116
|
? { kind: 'None' }
|
|
14133
14117
|
: {
|
|
14134
14118
|
kind: 'PlainText',
|
|
@@ -14137,7 +14121,7 @@ class RadixSpecificClient {
|
|
|
14137
14121
|
const previewReceipt = (yield this.previewIntent(intentWithHardcodedFee));
|
|
14138
14122
|
// Ensure that the preview was successful.
|
|
14139
14123
|
if (previewReceipt.receipt.status !== 'Succeeded') {
|
|
14140
|
-
throw new Error(
|
|
14124
|
+
throw new Error(`Preview for fees was not successful.`);
|
|
14141
14125
|
}
|
|
14142
14126
|
// Calculate the total fees
|
|
14143
14127
|
const totalFees = [
|
|
@@ -14153,8 +14137,10 @@ class RadixSpecificClient {
|
|
|
14153
14137
|
// to actually submit the transaction, ie: signature validation
|
|
14154
14138
|
const totalFeesPlus10Percent = totalFees * 1.1;
|
|
14155
14139
|
// Construct a new intent with the calculated fees.
|
|
14156
|
-
const manifest =
|
|
14157
|
-
|
|
14140
|
+
const manifest = methodsToCall
|
|
14141
|
+
? RadixSpecificClient.createCustomTransferManifest(from, resourceAddress, amount, totalFeesPlus10Percent, methodsToCall)
|
|
14142
|
+
: RadixSpecificClient.createSimpleTransferManifest(from, to, resourceAddress, amount, totalFeesPlus10Percent);
|
|
14143
|
+
const intent = yield this.constructIntent(manifest, message === null || message === undefined
|
|
14158
14144
|
? { kind: 'None' }
|
|
14159
14145
|
: {
|
|
14160
14146
|
kind: 'PlainText',
|
|
@@ -14185,7 +14171,7 @@ class RadixSpecificClient {
|
|
|
14185
14171
|
applicationName,
|
|
14186
14172
|
});
|
|
14187
14173
|
}
|
|
14188
|
-
static
|
|
14174
|
+
static createSimpleTransferManifest(from, to, resourceAddress, amount, amountToLockForFees) {
|
|
14189
14175
|
return new radixEngineToolkit.ManifestBuilder()
|
|
14190
14176
|
.callMethod(from, 'lock_fee', [radixEngineToolkit.decimal(amountToLockForFees)])
|
|
14191
14177
|
.callMethod(from, 'withdraw', [radixEngineToolkit.address(resourceAddress), radixEngineToolkit.decimal(amount)])
|
|
@@ -14194,6 +14180,15 @@ class RadixSpecificClient {
|
|
|
14194
14180
|
})
|
|
14195
14181
|
.build();
|
|
14196
14182
|
}
|
|
14183
|
+
static createCustomTransferManifest(from, resourceAddress, amount, amountToLockForFees, methodsToCall) {
|
|
14184
|
+
const simpletTx = new radixEngineToolkit.ManifestBuilder()
|
|
14185
|
+
.callMethod(from, 'lock_fee', [radixEngineToolkit.decimal(amountToLockForFees)])
|
|
14186
|
+
.callMethod(from, 'withdraw', [radixEngineToolkit.address(resourceAddress), radixEngineToolkit.decimal(amount)])
|
|
14187
|
+
.takeFromWorktop(resourceAddress, radixEngineToolkit.decimal(amount).value, (builder) => {
|
|
14188
|
+
return builder.callMethod(methodsToCall.address, methodsToCall.methodName, methodsToCall.params);
|
|
14189
|
+
});
|
|
14190
|
+
return simpletTx.build();
|
|
14191
|
+
}
|
|
14197
14192
|
constructIntent(manifest, message, nonce, notaryPublicKey) {
|
|
14198
14193
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14199
14194
|
const epoch = yield this.currentEpoch();
|
|
@@ -14252,6 +14247,45 @@ class RadixSpecificClient {
|
|
|
14252
14247
|
}
|
|
14253
14248
|
}
|
|
14254
14249
|
}
|
|
14250
|
+
|
|
14251
|
+
/**
|
|
14252
|
+
* Returns the resource id of an asset
|
|
14253
|
+
* @param {Asset | TokenAsset} asset asset
|
|
14254
|
+
* @returns Resource id
|
|
14255
|
+
*/
|
|
14256
|
+
const getAssetResource = (asset) => {
|
|
14257
|
+
if (xchainUtil.eqAsset(asset, AssetXRD))
|
|
14258
|
+
return RADIX_ASSET_RESOURCE;
|
|
14259
|
+
return asset.symbol.slice(asset.ticker.length + 1);
|
|
14260
|
+
};
|
|
14261
|
+
/**
|
|
14262
|
+
* Generates a address param for a call method
|
|
14263
|
+
* @param {Address} addr Address to transform to Radix Address parameter
|
|
14264
|
+
* @returns the address in the Radix Address parameter format
|
|
14265
|
+
*/
|
|
14266
|
+
const generateAddressParam = (addr) => radixEngineToolkit.address(addr);
|
|
14267
|
+
/**
|
|
14268
|
+
* Generates a string param for a call method
|
|
14269
|
+
* @param {string} s Address to transform to Radix string parameter
|
|
14270
|
+
* @returns the string in the Radix String parameter format
|
|
14271
|
+
*/
|
|
14272
|
+
const generateStringParam = (s) => radixEngineToolkit.str(s);
|
|
14273
|
+
/**
|
|
14274
|
+
* Generates a bucket param for a call method
|
|
14275
|
+
* @param {number} value Value to transform to Radix Bucket parameter
|
|
14276
|
+
* @returns the value in the Radix Bucket parameter format
|
|
14277
|
+
*/
|
|
14278
|
+
const generateBucketParam = (value) => radixEngineToolkit.bucket(value);
|
|
14279
|
+
|
|
14280
|
+
const xChainJsNetworkToRadixNetworkId = (network) => {
|
|
14281
|
+
switch (network) {
|
|
14282
|
+
case xchainClient.Network.Mainnet:
|
|
14283
|
+
case xchainClient.Network.Stagenet:
|
|
14284
|
+
return radixEngineToolkit.NetworkId.Mainnet;
|
|
14285
|
+
case xchainClient.Network.Testnet:
|
|
14286
|
+
return radixEngineToolkit.NetworkId.Stokenet;
|
|
14287
|
+
}
|
|
14288
|
+
};
|
|
14255
14289
|
/**
|
|
14256
14290
|
* Custom Radix client
|
|
14257
14291
|
*/
|
|
@@ -14287,7 +14321,7 @@ class Client extends xchainClient.BaseXChainClient {
|
|
|
14287
14321
|
// TODO: This can fail if we use it on stokenet, we need to replace these with network aware
|
|
14288
14322
|
// addresses.
|
|
14289
14323
|
const feesInXrd = yield this.radixSpecificClient
|
|
14290
|
-
.
|
|
14324
|
+
.constructTransferIntent(feesEstimationPublicKeys[this.getRadixNetwork()].from, feesEstimationPublicKeys[this.getRadixNetwork()].to, feesEstimationPublicKeys[this.getRadixNetwork()].resourceAddress, 0, new radixEngineToolkit.PublicKey.Ed25519(radixEngineToolkit.Convert.HexString.toUint8Array(feesEstimationPublicKeys[this.getRadixNetwork()].publicKey)), 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
|
|
14291
14325
|
.then((result) => result.fees);
|
|
14292
14326
|
// We need to add another 10% to the fees as the preview response does not include everything needed
|
|
14293
14327
|
// to actually submit the transaction, ie: signature validation
|
|
@@ -14574,7 +14608,7 @@ class Client extends xchainClient.BaseXChainClient {
|
|
|
14574
14608
|
return {
|
|
14575
14609
|
from: [],
|
|
14576
14610
|
to: [],
|
|
14577
|
-
asset:
|
|
14611
|
+
asset: AssetXRD,
|
|
14578
14612
|
date: confirmed_at,
|
|
14579
14613
|
type: xchainClient.TxType.Unknown,
|
|
14580
14614
|
hash: intent_hash,
|
|
@@ -14627,13 +14661,13 @@ class Client extends xchainClient.BaseXChainClient {
|
|
|
14627
14661
|
* @returns a PreparedTx
|
|
14628
14662
|
*/
|
|
14629
14663
|
prepareTx(params) {
|
|
14630
|
-
var _a
|
|
14664
|
+
var _a;
|
|
14631
14665
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14632
14666
|
const walletIndex = (_a = params.walletIndex) !== null && _a !== void 0 ? _a : 0;
|
|
14633
14667
|
const from = yield this.getAddressAsync();
|
|
14634
14668
|
const transferAmmount = params.amount.amount().toNumber() / Math.pow(10, XRD_DECIMAL);
|
|
14635
14669
|
const intent = yield this.radixSpecificClient
|
|
14636
|
-
.
|
|
14670
|
+
.constructTransferIntent(from, params.recipient, getAssetResource(params.asset || this.getAssetInfo().asset), transferAmmount, this.getRadixPrivateKey(walletIndex).publicKey(), params.memo, params.methodToCall)
|
|
14637
14671
|
.then((response) => response.intent);
|
|
14638
14672
|
const compiledIntent = yield radixEngineToolkit.RadixEngineToolkit.Intent.compile(intent);
|
|
14639
14673
|
return {
|
|
@@ -14647,21 +14681,24 @@ class Client extends xchainClient.BaseXChainClient {
|
|
|
14647
14681
|
*/
|
|
14648
14682
|
getAssetInfo() {
|
|
14649
14683
|
return {
|
|
14650
|
-
asset:
|
|
14684
|
+
asset: AssetXRD,
|
|
14651
14685
|
decimal: XRD_DECIMAL,
|
|
14652
14686
|
};
|
|
14653
14687
|
}
|
|
14654
14688
|
}
|
|
14655
14689
|
|
|
14690
|
+
exports.AssetXRD = AssetXRD;
|
|
14656
14691
|
exports.Client = Client;
|
|
14657
14692
|
exports.MAINNET_GATEWAY_URL = MAINNET_GATEWAY_URL;
|
|
14693
|
+
exports.RADIX_ASSET_RESOURCE = RADIX_ASSET_RESOURCE;
|
|
14658
14694
|
exports.RadixChain = RadixChain;
|
|
14659
14695
|
exports.STOKENET_GATEWAY_URL = STOKENET_GATEWAY_URL;
|
|
14660
14696
|
exports.XRD_DECIMAL = XRD_DECIMAL;
|
|
14661
|
-
exports.XrdAssetMainnet = XrdAssetMainnet;
|
|
14662
|
-
exports.XrdAssetStokenet = XrdAssetStokenet;
|
|
14663
|
-
exports.assets = assets;
|
|
14664
14697
|
exports.bech32Lengths = bech32Lengths;
|
|
14665
14698
|
exports.bech32Networks = bech32Networks;
|
|
14666
14699
|
exports.feesEstimationPublicKeys = feesEstimationPublicKeys;
|
|
14700
|
+
exports.generateAddressParam = generateAddressParam;
|
|
14701
|
+
exports.generateBucketParam = generateBucketParam;
|
|
14702
|
+
exports.generateStringParam = generateStringParam;
|
|
14703
|
+
exports.getAssetResource = getAssetResource;
|
|
14667
14704
|
exports.xrdRootDerivationPaths = xrdRootDerivationPaths;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { GatewayApiClient, TransactionSubmitResponse } from '@radixdlt/babylon-gateway-api-sdk';
|
|
2
|
+
import { Intent, NotarizedTransaction, PublicKey, TransactionHash } from '@radixdlt/radix-engine-toolkit';
|
|
3
|
+
import { Balance, MethodToCall } from './types/radix';
|
|
4
|
+
/**
|
|
5
|
+
* The main client for the Radix network which is then wrapped by the {Client} adapting it to have
|
|
6
|
+
* a {BaseXChainClient} interface.
|
|
7
|
+
*/
|
|
8
|
+
export declare class RadixSpecificClient {
|
|
9
|
+
private innerNetwork;
|
|
10
|
+
private innerGatewayClient;
|
|
11
|
+
constructor(networkId: number);
|
|
12
|
+
set networkId(networkId: number);
|
|
13
|
+
get networkId(): number;
|
|
14
|
+
get gatewayClient(): GatewayApiClient;
|
|
15
|
+
currentEpoch(): Promise<number>;
|
|
16
|
+
currentStateVersion(): Promise<number>;
|
|
17
|
+
fetchBalances(address: string): Promise<Balance[]>;
|
|
18
|
+
fetchNFTBalances(address: string): Promise<Balance[]>;
|
|
19
|
+
private convertResourcesToBalances;
|
|
20
|
+
private fetchNonFungibleResources;
|
|
21
|
+
private fetchFungibleResources;
|
|
22
|
+
constructTransferIntent(from: string, to: string, resourceAddress: string, amount: number, notaryPublicKey: PublicKey, message?: string, methodsToCall?: MethodToCall): Promise<{
|
|
23
|
+
intent: Intent;
|
|
24
|
+
fees: number;
|
|
25
|
+
}>;
|
|
26
|
+
submitTransaction(notarizedTransaction: NotarizedTransaction): Promise<[TransactionSubmitResponse, TransactionHash]>;
|
|
27
|
+
private static createGatewayClient;
|
|
28
|
+
private static createSimpleTransferManifest;
|
|
29
|
+
private static createCustomTransferManifest;
|
|
30
|
+
private constructIntent;
|
|
31
|
+
private previewIntent;
|
|
32
|
+
private static retPublicKeyToGatewayPublicKey;
|
|
33
|
+
}
|
package/lib/types/radix.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { Value } from '@radixdlt/radix-engine-toolkit';
|
|
1
2
|
import { Balance as BaseBalance, Tx as BaseTx, TxFrom as BaseTxFrom, TxParams as BaseTxParams, TxTo as BaseTxTo, TxsPage as BaseTxsPage } from '@xchainjs/xchain-client';
|
|
2
|
-
import { Asset, TokenAsset } from '@xchainjs/xchain-util';
|
|
3
|
+
import { Address, Asset, TokenAsset } from '@xchainjs/xchain-util';
|
|
3
4
|
export type CompatibleAsset = Asset | TokenAsset;
|
|
4
5
|
export type Transaction = {
|
|
5
6
|
manifest: string;
|
|
@@ -51,7 +52,13 @@ export type Tx = BaseTx & {
|
|
|
51
52
|
export type TxsPage = BaseTxsPage & {
|
|
52
53
|
txs: Tx[];
|
|
53
54
|
};
|
|
55
|
+
export type MethodToCall = {
|
|
56
|
+
address: Address;
|
|
57
|
+
methodName: string;
|
|
58
|
+
params: Value[];
|
|
59
|
+
};
|
|
54
60
|
export type TxParams = BaseTxParams & {
|
|
55
61
|
asset?: CompatibleAsset;
|
|
62
|
+
methodToCall?: MethodToCall;
|
|
56
63
|
};
|
|
57
64
|
export {};
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { Address, Asset, TokenAsset } from '@xchainjs/xchain-util';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the resource id of an asset
|
|
4
|
+
* @param {Asset | TokenAsset} asset asset
|
|
5
|
+
* @returns Resource id
|
|
6
|
+
*/
|
|
7
|
+
export declare const getAssetResource: (asset: Asset | TokenAsset) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Generates a address param for a call method
|
|
10
|
+
* @param {Address} addr Address to transform to Radix Address parameter
|
|
11
|
+
* @returns the address in the Radix Address parameter format
|
|
12
|
+
*/
|
|
13
|
+
export declare const generateAddressParam: (addr: Address) => {
|
|
14
|
+
kind: import("@radixdlt/radix-engine-toolkit").ValueKind.Address;
|
|
15
|
+
value: import("@radixdlt/radix-engine-toolkit").ManifestAddress;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Generates a string param for a call method
|
|
19
|
+
* @param {string} s Address to transform to Radix string parameter
|
|
20
|
+
* @returns the string in the Radix String parameter format
|
|
21
|
+
*/
|
|
22
|
+
export declare const generateStringParam: (s: string) => {
|
|
23
|
+
kind: import("@radixdlt/radix-engine-toolkit").ValueKind.String;
|
|
24
|
+
value: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Generates a bucket param for a call method
|
|
28
|
+
* @param {number} value Value to transform to Radix Bucket parameter
|
|
29
|
+
* @returns the value in the Radix Bucket parameter format
|
|
30
|
+
*/
|
|
31
|
+
export declare const generateBucketParam: (value: number) => {
|
|
32
|
+
kind: import("@radixdlt/radix-engine-toolkit").ValueKind.Bucket;
|
|
33
|
+
value: number;
|
|
34
|
+
};
|