@autonomys/auto-xdm 1.5.19 → 1.6.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/README.md CHANGED
@@ -44,28 +44,28 @@ Below are examples demonstrating how to use the functions provided by `@autonomy
44
44
 
45
45
  ```ts
46
46
  import { activateWallet } from '@autonomys/auto-utils'
47
- import { transferToDomainAccount20Type } from '@autonomys/auto-xdm'
47
+ import { transporterTransfer } from '@autonomys/auto-xdm'
48
48
 
49
49
  const api = await activateWallet({ networkId: 'taurus', uri: '//alice' })
50
- const tx = await transferToDomainAccount20Type(
50
+ const tx = transporterTransfer(
51
51
  api,
52
- 0, // Receiver domain (0 is Auto EVM on Taurus Testnet)
53
- '0x1234567890abcdef', // Receiver domain account
52
+ { domainId: 0 }, // Receiver domain (0 is Auto EVM on Taurus Testnet)
53
+ { accountId20: '0x1234567890abcdef1234567890abcdef12345678' }, // Receiver domain account (EVM address)
54
54
  '1000000000000000000',
55
55
  )
56
56
  ```
57
57
 
58
- ### 2. Transfer from Consensus to Domain using an substrate address
58
+ ### 2. Transfer from Consensus to Domain using a Substrate address
59
59
 
60
60
  ```ts
61
61
  import { activateWallet } from '@autonomys/auto-utils'
62
- import { transferToDomainAccount32Type } from '@autonomys/auto-xdm'
62
+ import { transporterTransfer } from '@autonomys/auto-xdm'
63
63
 
64
64
  const api = await activateWallet({ networkId: 'taurus', uri: '//alice' })
65
- const tx = await transferToDomainAccount32Type(
65
+ const tx = transporterTransfer(
66
66
  api,
67
- 0, // Receiver domain (0 is Auto EVM on Taurus Testnet)
68
- 'su1234567890abcdef', // Receiver domain account
67
+ { domainId: 0 }, // Receiver domain (0 is Auto EVM on Taurus Testnet)
68
+ { accountId32: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY' }, // Receiver domain account (Substrate address)
69
69
  '1000000000000000000',
70
70
  )
71
71
  ```
@@ -74,12 +74,13 @@ const tx = await transferToDomainAccount32Type(
74
74
 
75
75
  ```ts
76
76
  import { activateWallet } from '@autonomys/auto-utils'
77
- import { transferToConsensus } from '@autonomys/auto-xdm'
77
+ import { transporterTransfer } from '@autonomys/auto-xdm'
78
78
 
79
79
  const api = await activateWallet({ networkId: 'taurus', domainId: 0, uri: '//alice' })
80
- const tx = await transferToConsensus(
80
+ const tx = transporterTrans fer(
81
81
  api,
82
- 'su1234567890abcdef', // Receiver consensus account,
82
+ 'consensus', // Destination is consensus chain
83
+ { accountId32: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY' }, // Receiver consensus account (Substrate address)
83
84
  '1000000000000000000',
84
85
  )
85
86
  ```
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './info';
2
2
  export * from './messenger';
3
3
  export * from './transfer';
4
+ export * from './types';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA"}
package/dist/index.js CHANGED
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./info"), exports);
18
18
  __exportStar(require("./messenger"), exports);
19
19
  __exportStar(require("./transfer"), exports);
20
+ __exportStar(require("./types"), exports);
package/dist/info.d.ts CHANGED
@@ -1,11 +1,145 @@
1
- import { type ApiPromise, type Codec } from '@autonomys/auto-utils';
2
- export declare const chainAllowlist: (api: ApiPromise) => Promise<Codec>;
3
- export declare const channels: (api: ApiPromise, chainId: Codec) => Promise<Codec>;
4
- export declare const consensusChannels: (api: ApiPromise) => Promise<Codec>;
5
- export declare const domainChannels: (api: ApiPromise, domainId: number) => Promise<Codec>;
6
- export declare const allCancelledTransfers: (api: ApiPromise) => Promise<Codec>;
7
- export declare const chainTransfers: (api: ApiPromise) => Promise<Codec>;
8
- export declare const allDomainBalances: (api: ApiPromise) => Promise<Codec>;
9
- export declare const domainBalances: (api: ApiPromise, domainId: number) => Promise<Codec>;
10
- export declare const allUnconfirmedTransfers: (api: ApiPromise) => Promise<Codec>;
1
+ import { type ApiPromise } from '@autonomys/auto-utils';
2
+ import type { Chain, ChainAllowlist, Channel, DomainBalance, Transfer } from './types';
3
+ /**
4
+ * Query the chain allowlist for the current chain.
5
+ *
6
+ * Returns the allowlist of chains that can open channels with this chain.
7
+ * This is used to control which chains are allowed to establish communication channels.
8
+ *
9
+ * @param api - The API promise instance for the chain
10
+ * @returns An array of Chain identifiers that are allowed to open channels
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const allowlist = await chainAllowlist(api)
15
+ * // allowlist: ['consensus'] or [{ domainId: 0 }, { domainId: 1 }]
16
+ *
17
+ * // Check if a specific chain is in the allowlist
18
+ * const isDomain0Allowed = allowlist.some(
19
+ * chain => chain !== 'consensus' && chain.domainId === 0
20
+ * )
21
+ * ```
22
+ */
23
+ export declare const chainAllowlist: (api: ApiPromise) => Promise<ChainAllowlist>;
24
+ /**
25
+ * Query the next channel ID for a given chain.
26
+ *
27
+ * Returns the next channel ID that will be assigned when a new channel is created to the specified chain.
28
+ * If the value is 0, no channels exist yet. If > 0, channels exist (IDs start at 1).
29
+ *
30
+ * @param api - The API promise instance for the chain
31
+ * @param chain - The chain to query: 'consensus' or domain ID (number)
32
+ * @returns The next channel ID (U256)
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * // Check if any channels exist to domain 0
37
+ * const nextId = await nextChannelId(api, { domainId: 0 })
38
+ * const hasChannels = BigInt(nextId.toString()) > 0n
39
+ * ```
40
+ */
41
+ export declare const nextChannelId: (api: ApiPromise, chain: Chain) => Promise<bigint>;
42
+ /**
43
+ * Query a specific channel between two chains.
44
+ *
45
+ * Channels storage is a DoubleMap keyed by (ChainId, ChannelId).
46
+ * Both the chain and channel ID are required to query a specific channel.
47
+ *
48
+ * Note: To get all channels for a chain, use `api.query.messenger.channels.entries(chainId)` directly.
49
+ *
50
+ * @param api - The API promise instance for the chain
51
+ * @param chain - The chain to query channels for: 'consensus' or domain ID
52
+ * @param channelId - The channel ID (number, string, or bigint)
53
+ * @returns Channel configuration for the specified chain and channel ID, or null if not found
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * // Query specific channel 0 to domain 0
58
+ * const channel = await channels(api, { domainId: 0 }, 0)
59
+ * if (channel) {
60
+ * console.log(`Channel state: ${channel.state}`)
61
+ * console.log(`Next outbox nonce: ${channel.nextOutboxNonce}`)
62
+ * }
63
+ * ```
64
+ */
65
+ export declare const channels: (api: ApiPromise, chain: Chain, channelId: number | string | bigint) => Promise<Channel | null>;
66
+ /**
67
+ * Query domain balances on the consensus chain.
68
+ *
69
+ * Domain balances represent the amount of funds available on each domain
70
+ * for processing transfers and other operations.
71
+ *
72
+ * @param api - The API promise instance for the consensus chain
73
+ * @param domainId - Optional domain ID to query balance for. If provided, returns a single balance bigint. If omitted, returns all domain balances.
74
+ * @returns The balance for the specified domain as a bigint, or an array of all domain balances
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * // Query balance for a specific domain
79
+ * const balance = await domainBalances(api, 0)
80
+ * // balance: 1000000000000n
81
+ *
82
+ * // Query all domain balances
83
+ * const allBalances = await domainBalances(api)
84
+ * // allBalances: [{ domainId: 0, balance: 1000000000000n }, { domainId: 1, balance: 2000000000000n }]
85
+ * ```
86
+ */
87
+ export declare const domainBalances: (api: ApiPromise, domainId?: number) => Promise<bigint | DomainBalance[]>;
88
+ /**
89
+ * Query cancelled transfers between chains.
90
+ *
91
+ * Returns transfers that have been cancelled/rejected between chains.
92
+ * Cancelled transfers occur when a transfer from one chain to another was rejected
93
+ * by the destination chain. These transfers can be claimed back by the source chain.
94
+ *
95
+ * This storage is only available on the consensus chain where all transfer tracking is maintained.
96
+ *
97
+ * @param api - The API promise instance for the consensus chain
98
+ * @param from - Source chain: 'consensus' or { domainId: number }. Defaults to 'consensus'.
99
+ * @param to - Optional destination chain. If provided, returns a specific transfer amount. If omitted, returns all cancelled transfers from the source chain.
100
+ * @returns Transfer amount as bigint for a specific route, or array of all cancelled transfers from the source chain
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * // All cancelled transfers from consensus
105
+ * const fromConsensus = await cancelledTransfers(api)
106
+ * // fromConsensus: [{ from: 'consensus', to: { domainId: 0 }, amount: 1000000000000n }]
107
+ *
108
+ * // All cancelled transfers from domain 1
109
+ * const fromDomain = await cancelledTransfers(api, { domainId: 1 })
110
+ *
111
+ * // Specific transfer from consensus to domain 1
112
+ * const specific = await cancelledTransfers(api, 'consensus', { domainId: 1 })
113
+ * // specific: 1000000000000n
114
+ * ```
115
+ */
116
+ export declare const cancelledTransfers: (api: ApiPromise, from?: Chain, to?: Chain) => Promise<bigint | Transfer[]>;
117
+ /**
118
+ * Query unconfirmed transfers between chains.
119
+ *
120
+ * Returns transfers that have been initiated but not yet confirmed or rejected.
121
+ * Unconfirmed transfers are in a pending state and will either be confirmed or cancelled.
122
+ *
123
+ * This storage is only available on the consensus chain where all transfer tracking is maintained.
124
+ *
125
+ * @param api - The API promise instance for the consensus chain
126
+ * @param from - Source chain: 'consensus' or { domainId: number }. Defaults to 'consensus'.
127
+ * @param to - Optional destination chain. If provided, returns a specific transfer amount. If omitted, returns all unconfirmed transfers from the source chain.
128
+ * @returns Transfer amount as bigint for a specific route, or array of all unconfirmed transfers from the source chain
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * // All unconfirmed transfers from consensus
133
+ * const fromConsensus = await unconfirmedTransfers(api)
134
+ * // fromConsensus: [{ from: 'consensus', to: { domainId: 0 }, amount: 1000000000000n }]
135
+ *
136
+ * // All unconfirmed transfers from domain 1
137
+ * const fromDomain = await unconfirmedTransfers(api, { domainId: 1 })
138
+ *
139
+ * // Specific transfer from consensus to domain 1
140
+ * const specific = await unconfirmedTransfers(api, 'consensus', { domainId: 1 })
141
+ * // specific: 1000000000000n
142
+ * ```
143
+ */
144
+ export declare const unconfirmedTransfers: (api: ApiPromise, from?: Chain, to?: Chain) => Promise<bigint | Transfer[]>;
11
145
  //# sourceMappingURL=info.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"info.d.ts","sourceRoot":"","sources":["../src/info.ts"],"names":[],"mappings":"AAGA,OAAO,EAA4B,KAAK,UAAU,EAAE,KAAK,KAAK,EAAE,MAAM,uBAAuB,CAAA;AAE7F,eAAO,MAAM,cAAc,GAAU,KAAK,UAAU,mBACK,CAAA;AAEzD,eAAO,MAAM,QAAQ,GAAU,KAAK,UAAU,EAAE,SAAS,KAAK,mBACJ,CAAA;AAE1D,eAAO,MAAM,iBAAiB,GAAU,KAAK,UAAU,mBACyB,CAAA;AAEhF,eAAO,MAAM,cAAc,GAAU,KAAK,UAAU,EAAE,UAAU,MAAM,mBACoB,CAAA;AAE1F,eAAO,MAAM,qBAAqB,GAAU,KAAK,UAAU,mBAE1D,CAAA;AAED,eAAO,MAAM,cAAc,GAAU,KAAK,UAAU,mBAEnD,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAU,KAAK,UAAU,mBAEtD,CAAA;AAED,eAAO,MAAM,cAAc,GAAU,KAAK,UAAU,EAAE,UAAU,MAAM,mBAErE,CAAA;AAED,eAAO,MAAM,uBAAuB,GAAU,KAAK,UAAU,mBAE5D,CAAA"}
1
+ {"version":3,"file":"info.d.ts","sourceRoot":"","sources":["../src/info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAEvD,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAW,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAE/F;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,cAAc,GAAU,KAAK,UAAU,KAAG,OAAO,CAAC,cAAc,CAI5E,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,aAAa,GAAU,KAAK,UAAU,EAAE,OAAO,KAAK,KAAG,OAAO,CAAC,MAAM,CAIjF,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,QAAQ,GACnB,KAAK,UAAU,EACf,OAAO,KAAK,EACZ,WAAW,MAAM,GAAG,MAAM,GAAG,MAAM,KAClC,OAAO,CAAC,OAAO,GAAG,IAAI,CAKxB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,cAAc,GACzB,KAAK,UAAU,EACf,WAAW,MAAM,KAChB,OAAO,CAAC,MAAM,GAAG,aAAa,EAAE,CAiBlC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,kBAAkB,GAC7B,KAAK,UAAU,EACf,OAAM,KAAmB,EACzB,KAAK,KAAK,KACT,OAAO,CAAC,MAAM,GAAG,QAAQ,EAAE,CAoB7B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,oBAAoB,GAC/B,KAAK,UAAU,EACf,OAAM,KAAmB,EACzB,KAAK,KAAK,KACT,OAAO,CAAC,MAAM,GAAG,QAAQ,EAAE,CAoB7B,CAAA"}
package/dist/info.js CHANGED
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- // file: src/types/index.ts
3
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -10,34 +9,218 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
9
  });
11
10
  };
12
11
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.allUnconfirmedTransfers = exports.domainBalances = exports.allDomainBalances = exports.chainTransfers = exports.allCancelledTransfers = exports.domainChannels = exports.consensusChannels = exports.channels = exports.chainAllowlist = void 0;
14
- const auto_consensus_1 = require("@autonomys/auto-consensus");
15
- const auto_utils_1 = require("@autonomys/auto-utils");
16
- const chainAllowlist = (api) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, auto_consensus_1.query)(api, 'messenger.chainAllowlist', []); });
17
- exports.chainAllowlist = chainAllowlist;
18
- const channels = (api, chainId) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, auto_consensus_1.query)(api, 'messenger.channels', [chainId]); });
19
- exports.channels = channels;
20
- const consensusChannels = (api) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, auto_consensus_1.query)(api, 'messenger.channels', [(0, auto_utils_1.createDomainsChainIdType)(api)]); });
21
- exports.consensusChannels = consensusChannels;
22
- const domainChannels = (api, domainId) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, auto_consensus_1.query)(api, 'messenger.channels', [(0, auto_utils_1.createDomainsChainIdType)(api, domainId)]); });
23
- exports.domainChannels = domainChannels;
24
- const allCancelledTransfers = (api) => __awaiter(void 0, void 0, void 0, function* () {
25
- return yield (0, auto_consensus_1.query)(api, 'transporter.cancelledTransfers', []);
12
+ exports.unconfirmedTransfers = exports.cancelledTransfers = exports.domainBalances = exports.channels = exports.nextChannelId = exports.chainAllowlist = void 0;
13
+ const transforms_1 = require("./transforms");
14
+ /**
15
+ * Query the chain allowlist for the current chain.
16
+ *
17
+ * Returns the allowlist of chains that can open channels with this chain.
18
+ * This is used to control which chains are allowed to establish communication channels.
19
+ *
20
+ * @param api - The API promise instance for the chain
21
+ * @returns An array of Chain identifiers that are allowed to open channels
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const allowlist = await chainAllowlist(api)
26
+ * // allowlist: ['consensus'] or [{ domainId: 0 }, { domainId: 1 }]
27
+ *
28
+ * // Check if a specific chain is in the allowlist
29
+ * const isDomain0Allowed = allowlist.some(
30
+ * chain => chain !== 'consensus' && chain.domainId === 0
31
+ * )
32
+ * ```
33
+ */
34
+ const chainAllowlist = (api) => __awaiter(void 0, void 0, void 0, function* () {
35
+ const codec = yield api.query.messenger.chainAllowlist();
36
+ const chainIds = codec.toJSON();
37
+ return chainIds.map(transforms_1.chainIdToChain);
26
38
  });
27
- exports.allCancelledTransfers = allCancelledTransfers;
28
- const chainTransfers = (api) => __awaiter(void 0, void 0, void 0, function* () {
29
- return yield (0, auto_consensus_1.query)(api, 'transporter.chainTransfers', []);
39
+ exports.chainAllowlist = chainAllowlist;
40
+ /**
41
+ * Query the next channel ID for a given chain.
42
+ *
43
+ * Returns the next channel ID that will be assigned when a new channel is created to the specified chain.
44
+ * If the value is 0, no channels exist yet. If > 0, channels exist (IDs start at 1).
45
+ *
46
+ * @param api - The API promise instance for the chain
47
+ * @param chain - The chain to query: 'consensus' or domain ID (number)
48
+ * @returns The next channel ID (U256)
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * // Check if any channels exist to domain 0
53
+ * const nextId = await nextChannelId(api, { domainId: 0 })
54
+ * const hasChannels = BigInt(nextId.toString()) > 0n
55
+ * ```
56
+ */
57
+ const nextChannelId = (api, chain) => __awaiter(void 0, void 0, void 0, function* () {
58
+ const chainId = (0, transforms_1.chainToChainIdCodec)(api, chain);
59
+ const nextId = yield api.query.messenger.nextChannelId(chainId);
60
+ return BigInt(nextId.toString());
30
61
  });
31
- exports.chainTransfers = chainTransfers;
32
- const allDomainBalances = (api) => __awaiter(void 0, void 0, void 0, function* () {
33
- return yield (0, auto_consensus_1.query)(api, 'transporter.domainBalances', []);
62
+ exports.nextChannelId = nextChannelId;
63
+ /**
64
+ * Query a specific channel between two chains.
65
+ *
66
+ * Channels storage is a DoubleMap keyed by (ChainId, ChannelId).
67
+ * Both the chain and channel ID are required to query a specific channel.
68
+ *
69
+ * Note: To get all channels for a chain, use `api.query.messenger.channels.entries(chainId)` directly.
70
+ *
71
+ * @param api - The API promise instance for the chain
72
+ * @param chain - The chain to query channels for: 'consensus' or domain ID
73
+ * @param channelId - The channel ID (number, string, or bigint)
74
+ * @returns Channel configuration for the specified chain and channel ID, or null if not found
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * // Query specific channel 0 to domain 0
79
+ * const channel = await channels(api, { domainId: 0 }, 0)
80
+ * if (channel) {
81
+ * console.log(`Channel state: ${channel.state}`)
82
+ * console.log(`Next outbox nonce: ${channel.nextOutboxNonce}`)
83
+ * }
84
+ * ```
85
+ */
86
+ const channels = (api, chain, channelId) => __awaiter(void 0, void 0, void 0, function* () {
87
+ const chainIdCodec = (0, transforms_1.chainToChainIdCodec)(api, chain);
88
+ const channelIdCodec = api.createType('U256', channelId);
89
+ const codec = yield api.query.messenger.channels(chainIdCodec, channelIdCodec);
90
+ return (0, transforms_1.codecToChannel)(codec);
34
91
  });
35
- exports.allDomainBalances = allDomainBalances;
92
+ exports.channels = channels;
93
+ /**
94
+ * Query domain balances on the consensus chain.
95
+ *
96
+ * Domain balances represent the amount of funds available on each domain
97
+ * for processing transfers and other operations.
98
+ *
99
+ * @param api - The API promise instance for the consensus chain
100
+ * @param domainId - Optional domain ID to query balance for. If provided, returns a single balance bigint. If omitted, returns all domain balances.
101
+ * @returns The balance for the specified domain as a bigint, or an array of all domain balances
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * // Query balance for a specific domain
106
+ * const balance = await domainBalances(api, 0)
107
+ * // balance: 1000000000000n
108
+ *
109
+ * // Query all domain balances
110
+ * const allBalances = await domainBalances(api)
111
+ * // allBalances: [{ domainId: 0, balance: 1000000000000n }, { domainId: 1, balance: 2000000000000n }]
112
+ * ```
113
+ */
36
114
  const domainBalances = (api, domainId) => __awaiter(void 0, void 0, void 0, function* () {
37
- return yield (0, auto_consensus_1.query)(api, 'transporter.domainBalances', [domainId]);
115
+ if (domainId !== undefined) {
116
+ const codec = yield api.query.transporter.domainBalances(domainId);
117
+ return (0, transforms_1.codecToBalance)(codec);
118
+ }
119
+ // Get all entries when no domainId is provided
120
+ const entries = yield api.query.transporter.domainBalances.entries();
121
+ return entries.map(([key, value]) => {
122
+ // Extract domainId from storage key
123
+ const domainIdCodec = key.args[0];
124
+ const domainId = Number(domainIdCodec.toString());
125
+ return {
126
+ domainId,
127
+ balance: (0, transforms_1.codecToBalance)(value),
128
+ };
129
+ });
38
130
  });
39
131
  exports.domainBalances = domainBalances;
40
- const allUnconfirmedTransfers = (api) => __awaiter(void 0, void 0, void 0, function* () {
41
- return yield (0, auto_consensus_1.query)(api, 'transporter.unconfirmedTransfers', []);
132
+ /**
133
+ * Query cancelled transfers between chains.
134
+ *
135
+ * Returns transfers that have been cancelled/rejected between chains.
136
+ * Cancelled transfers occur when a transfer from one chain to another was rejected
137
+ * by the destination chain. These transfers can be claimed back by the source chain.
138
+ *
139
+ * This storage is only available on the consensus chain where all transfer tracking is maintained.
140
+ *
141
+ * @param api - The API promise instance for the consensus chain
142
+ * @param from - Source chain: 'consensus' or { domainId: number }. Defaults to 'consensus'.
143
+ * @param to - Optional destination chain. If provided, returns a specific transfer amount. If omitted, returns all cancelled transfers from the source chain.
144
+ * @returns Transfer amount as bigint for a specific route, or array of all cancelled transfers from the source chain
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * // All cancelled transfers from consensus
149
+ * const fromConsensus = await cancelledTransfers(api)
150
+ * // fromConsensus: [{ from: 'consensus', to: { domainId: 0 }, amount: 1000000000000n }]
151
+ *
152
+ * // All cancelled transfers from domain 1
153
+ * const fromDomain = await cancelledTransfers(api, { domainId: 1 })
154
+ *
155
+ * // Specific transfer from consensus to domain 1
156
+ * const specific = await cancelledTransfers(api, 'consensus', { domainId: 1 })
157
+ * // specific: 1000000000000n
158
+ * ```
159
+ */
160
+ const cancelledTransfers = (api_1, ...args_1) => __awaiter(void 0, [api_1, ...args_1], void 0, function* (api, from = 'consensus', to) {
161
+ const fromChainId = (0, transforms_1.chainToChainIdCodec)(api, from);
162
+ if (to !== undefined) {
163
+ const toChainId = (0, transforms_1.chainToChainIdCodec)(api, to);
164
+ const codec = yield api.query.transporter.cancelledTransfers(fromChainId, toChainId);
165
+ return (0, transforms_1.codecToBalance)(codec);
166
+ }
167
+ const entries = yield api.query.transporter.cancelledTransfers.entries(fromChainId);
168
+ return entries.map(([key, value]) => {
169
+ // Extract toChainId from storage key (second key in DoubleMap)
170
+ const toChainIdCodec = key.args[1];
171
+ const toChainId = toChainIdCodec.toJSON();
172
+ return {
173
+ from,
174
+ to: (0, transforms_1.chainIdToChain)(toChainId),
175
+ amount: (0, transforms_1.codecToBalance)(value),
176
+ };
177
+ });
178
+ });
179
+ exports.cancelledTransfers = cancelledTransfers;
180
+ /**
181
+ * Query unconfirmed transfers between chains.
182
+ *
183
+ * Returns transfers that have been initiated but not yet confirmed or rejected.
184
+ * Unconfirmed transfers are in a pending state and will either be confirmed or cancelled.
185
+ *
186
+ * This storage is only available on the consensus chain where all transfer tracking is maintained.
187
+ *
188
+ * @param api - The API promise instance for the consensus chain
189
+ * @param from - Source chain: 'consensus' or { domainId: number }. Defaults to 'consensus'.
190
+ * @param to - Optional destination chain. If provided, returns a specific transfer amount. If omitted, returns all unconfirmed transfers from the source chain.
191
+ * @returns Transfer amount as bigint for a specific route, or array of all unconfirmed transfers from the source chain
192
+ *
193
+ * @example
194
+ * ```typescript
195
+ * // All unconfirmed transfers from consensus
196
+ * const fromConsensus = await unconfirmedTransfers(api)
197
+ * // fromConsensus: [{ from: 'consensus', to: { domainId: 0 }, amount: 1000000000000n }]
198
+ *
199
+ * // All unconfirmed transfers from domain 1
200
+ * const fromDomain = await unconfirmedTransfers(api, { domainId: 1 })
201
+ *
202
+ * // Specific transfer from consensus to domain 1
203
+ * const specific = await unconfirmedTransfers(api, 'consensus', { domainId: 1 })
204
+ * // specific: 1000000000000n
205
+ * ```
206
+ */
207
+ const unconfirmedTransfers = (api_1, ...args_1) => __awaiter(void 0, [api_1, ...args_1], void 0, function* (api, from = 'consensus', to) {
208
+ const fromChainId = (0, transforms_1.chainToChainIdCodec)(api, from);
209
+ if (to !== undefined) {
210
+ const toChainId = (0, transforms_1.chainToChainIdCodec)(api, to);
211
+ const codec = yield api.query.transporter.unconfirmedTransfers(fromChainId, toChainId);
212
+ return (0, transforms_1.codecToBalance)(codec);
213
+ }
214
+ const entries = yield api.query.transporter.unconfirmedTransfers.entries(fromChainId);
215
+ return entries.map(([key, value]) => {
216
+ // Extract toChainId from storage key (second key in DoubleMap)
217
+ const toChainIdCodec = key.args[1];
218
+ const toChainId = toChainIdCodec.toJSON();
219
+ return {
220
+ from,
221
+ to: (0, transforms_1.chainIdToChain)(toChainId),
222
+ amount: (0, transforms_1.codecToBalance)(value),
223
+ };
224
+ });
42
225
  });
43
- exports.allUnconfirmedTransfers = allUnconfirmedTransfers;
226
+ exports.unconfirmedTransfers = unconfirmedTransfers;
@@ -1,4 +1,69 @@
1
- import type { ApiPromise, Codec } from '@autonomys/auto-utils';
2
- export declare const initiateChannel: (api: ApiPromise, destination: Codec) => Promise<import("@autonomys/auto-utils").SubmittableExtrinsic<"promise", import("@autonomys/auto-utils").ISubmittableResult>>;
3
- export declare const closeChannel: (api: ApiPromise, chainId: Codec, channelId: string) => Promise<import("@autonomys/auto-utils").SubmittableExtrinsic<"promise", import("@autonomys/auto-utils").ISubmittableResult>>;
1
+ import type { ApiPromise, ISubmittableResult, SubmittableExtrinsic } from '@autonomys/auto-utils';
2
+ import type { Chain } from './types';
3
+ /**
4
+ * Creates a transaction to initiate a channel to a destination chain.
5
+ *
6
+ * This function creates a transaction but does not submit it. The returned transaction
7
+ * must be signed and sent using `signAndSendTx` or similar methods.
8
+ *
9
+ * Before initiating a channel, ensure the destination chain is in the allowlist.
10
+ * Use `chainAllowlist()` to check which chains can open channels with the current chain.
11
+ *
12
+ * @param api - The API instance for the source chain
13
+ * @param destination - The destination chain: 'consensus' or { domainId: number }
14
+ * @returns A transaction that can be signed and submitted
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * // Initiate channel to consensus chain
19
+ * const tx = initiateChannel(api, 'consensus')
20
+ * await signAndSendTx(keyringPair, tx, {}, [], false)
21
+ *
22
+ * // Initiate channel to domain 0
23
+ * const tx = initiateChannel(api, { domainId: 0 })
24
+ * await signAndSendTx(keyringPair, tx, {}, [], false)
25
+ *
26
+ * // Check if destination is allowed before initiating
27
+ * const allowlist = await chainAllowlist(api)
28
+ * const canOpenToDomain0 = allowlist.some(chain => chain !== 'consensus' && chain.domainId === 0)
29
+ * if (canOpenToDomain0) {
30
+ * const tx = initiateChannel(api, { domainId: 0 })
31
+ * await signAndSendTx(keyringPair, tx, {}, [], false)
32
+ * }
33
+ * ```
34
+ */
35
+ export declare const initiateChannel: (api: ApiPromise, destination: Chain) => SubmittableExtrinsic<"promise", ISubmittableResult>;
36
+ /**
37
+ * Creates a transaction to close an existing channel to a destination chain.
38
+ *
39
+ * This function creates a transaction but does not submit it. The returned transaction
40
+ * must be signed and sent using `signAndSendTx` or similar methods.
41
+ *
42
+ * Closing a channel stops further message exchanges on that channel. You can query
43
+ * existing channels using `channels()` to find the channel ID to close.
44
+ *
45
+ * @param api - The API instance for the chain where the channel exists
46
+ * @param destination - The destination chain of the channel: 'consensus' or { domainId: number }
47
+ * @param channelId - The channel ID to close (number, string, or bigint)
48
+ * @returns A transaction that can be signed and submitted
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * // Close channel 0 to domain 0
53
+ * const tx = closeChannel(api, { domainId: 0 }, 0)
54
+ * await signAndSendTx(keyringPair, tx, {}, [], false)
55
+ *
56
+ * // Close channel 1 to consensus chain
57
+ * const tx = closeChannel(api, 'consensus', 1)
58
+ * await signAndSendTx(keyringPair, tx, {}, [], false)
59
+ *
60
+ * // Query channel before closing to verify it exists
61
+ * const channel = await channels(api, { domainId: 0 }, 0)
62
+ * if (channel && channel.state === 'Open') {
63
+ * const tx = closeChannel(api, { domainId: 0 }, 0)
64
+ * await signAndSendTx(keyringPair, tx, {}, [], false)
65
+ * }
66
+ * ```
67
+ */
68
+ export declare const closeChannel: (api: ApiPromise, destination: Chain, channelId: number | string | bigint) => SubmittableExtrinsic<"promise", ISubmittableResult>;
4
69
  //# sourceMappingURL=messenger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"messenger.d.ts","sourceRoot":"","sources":["../src/messenger.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAA;AAE9D,eAAO,MAAM,eAAe,GAAU,KAAK,UAAU,EAAE,aAAa,KAAK,iIAExE,CAAA;AAED,eAAO,MAAM,YAAY,GAAU,KAAK,UAAU,EAAE,SAAS,KAAK,EAAE,WAAW,MAAM,iIAEpF,CAAA"}
1
+ {"version":3,"file":"messenger.d.ts","sourceRoot":"","sources":["../src/messenger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAEjG,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,eAAe,GAC1B,KAAK,UAAU,EACf,aAAa,KAAK,KACjB,oBAAoB,CAAC,SAAS,EAAE,kBAAkB,CAGpD,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,YAAY,GACvB,KAAK,UAAU,EACf,aAAa,KAAK,EAClB,WAAW,MAAM,GAAG,MAAM,GAAG,MAAM,KAClC,oBAAoB,CAAC,SAAS,EAAE,kBAAkB,CAIpD,CAAA"}
package/dist/messenger.js CHANGED
@@ -1,21 +1,79 @@
1
1
  "use strict";
2
- // file: src/transfer.ts
3
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
- return new (P || (P = Promise))(function (resolve, reject) {
6
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
- step((generator = generator.apply(thisArg, _arguments || [])).next());
10
- });
11
- };
12
2
  Object.defineProperty(exports, "__esModule", { value: true });
13
3
  exports.closeChannel = exports.initiateChannel = void 0;
14
- const initiateChannel = (api, destination) => __awaiter(void 0, void 0, void 0, function* () {
15
- return yield api.tx.messenger.initiateChannel(destination);
16
- });
4
+ const transforms_1 = require("./transforms");
5
+ /**
6
+ * Creates a transaction to initiate a channel to a destination chain.
7
+ *
8
+ * This function creates a transaction but does not submit it. The returned transaction
9
+ * must be signed and sent using `signAndSendTx` or similar methods.
10
+ *
11
+ * Before initiating a channel, ensure the destination chain is in the allowlist.
12
+ * Use `chainAllowlist()` to check which chains can open channels with the current chain.
13
+ *
14
+ * @param api - The API instance for the source chain
15
+ * @param destination - The destination chain: 'consensus' or { domainId: number }
16
+ * @returns A transaction that can be signed and submitted
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // Initiate channel to consensus chain
21
+ * const tx = initiateChannel(api, 'consensus')
22
+ * await signAndSendTx(keyringPair, tx, {}, [], false)
23
+ *
24
+ * // Initiate channel to domain 0
25
+ * const tx = initiateChannel(api, { domainId: 0 })
26
+ * await signAndSendTx(keyringPair, tx, {}, [], false)
27
+ *
28
+ * // Check if destination is allowed before initiating
29
+ * const allowlist = await chainAllowlist(api)
30
+ * const canOpenToDomain0 = allowlist.some(chain => chain !== 'consensus' && chain.domainId === 0)
31
+ * if (canOpenToDomain0) {
32
+ * const tx = initiateChannel(api, { domainId: 0 })
33
+ * await signAndSendTx(keyringPair, tx, {}, [], false)
34
+ * }
35
+ * ```
36
+ */
37
+ const initiateChannel = (api, destination) => {
38
+ const destinationChainId = (0, transforms_1.chainToChainIdCodec)(api, destination);
39
+ return api.tx.messenger.initiateChannel(destinationChainId);
40
+ };
17
41
  exports.initiateChannel = initiateChannel;
18
- const closeChannel = (api, chainId, channelId) => __awaiter(void 0, void 0, void 0, function* () {
19
- return yield api.tx.messenger.closeChannel(chainId, channelId);
20
- });
42
+ /**
43
+ * Creates a transaction to close an existing channel to a destination chain.
44
+ *
45
+ * This function creates a transaction but does not submit it. The returned transaction
46
+ * must be signed and sent using `signAndSendTx` or similar methods.
47
+ *
48
+ * Closing a channel stops further message exchanges on that channel. You can query
49
+ * existing channels using `channels()` to find the channel ID to close.
50
+ *
51
+ * @param api - The API instance for the chain where the channel exists
52
+ * @param destination - The destination chain of the channel: 'consensus' or { domainId: number }
53
+ * @param channelId - The channel ID to close (number, string, or bigint)
54
+ * @returns A transaction that can be signed and submitted
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * // Close channel 0 to domain 0
59
+ * const tx = closeChannel(api, { domainId: 0 }, 0)
60
+ * await signAndSendTx(keyringPair, tx, {}, [], false)
61
+ *
62
+ * // Close channel 1 to consensus chain
63
+ * const tx = closeChannel(api, 'consensus', 1)
64
+ * await signAndSendTx(keyringPair, tx, {}, [], false)
65
+ *
66
+ * // Query channel before closing to verify it exists
67
+ * const channel = await channels(api, { domainId: 0 }, 0)
68
+ * if (channel && channel.state === 'Open') {
69
+ * const tx = closeChannel(api, { domainId: 0 }, 0)
70
+ * await signAndSendTx(keyringPair, tx, {}, [], false)
71
+ * }
72
+ * ```
73
+ */
74
+ const closeChannel = (api, destination, channelId) => {
75
+ const destinationChainId = (0, transforms_1.chainToChainIdCodec)(api, destination);
76
+ const channelIdCodec = api.createType('U256', channelId);
77
+ return api.tx.messenger.closeChannel(destinationChainId, channelIdCodec);
78
+ };
21
79
  exports.closeChannel = closeChannel;
@@ -1,7 +1,29 @@
1
1
  import type { StringNumberOrBigInt } from '@autonomys/auto-consensus';
2
- import { ApiPromise, Codec } from '@autonomys/auto-utils';
3
- export declare const transfer: (api: ApiPromise, destination: Codec, amount: StringNumberOrBigInt) => Promise<import("@autonomys/auto-utils").SubmittableExtrinsic<"promise", import("@autonomys/auto-utils").ISubmittableResult>>;
4
- export declare const transferToConsensus: (api: ApiPromise, accountId32: string, amount: StringNumberOrBigInt) => Promise<import("@autonomys/auto-utils").SubmittableExtrinsic<"promise", import("@autonomys/auto-utils").ISubmittableResult>>;
5
- export declare const transferToDomainAccount20Type: (api: ApiPromise, destinationDomainId: string | number, accountId20: string, amount: StringNumberOrBigInt) => Promise<import("@autonomys/auto-utils").SubmittableExtrinsic<"promise", import("@autonomys/auto-utils").ISubmittableResult>>;
6
- export declare const transferToDomainAccount32Type: (api: ApiPromise, destinationDomainId: string | number, accountId32: string, amount: StringNumberOrBigInt) => Promise<import("@autonomys/auto-utils").SubmittableExtrinsic<"promise", import("@autonomys/auto-utils").ISubmittableResult>>;
2
+ import { ApiPromise, type ISubmittableResult, type SubmittableExtrinsic } from '@autonomys/auto-utils';
3
+ import type { Chain, TransferAccount } from './types';
4
+ /**
5
+ * Creates a transfer transaction to be submitted.
6
+ *
7
+ * This function creates a transaction but does not submit it. The returned transaction
8
+ * must be signed and sent using `signAndSendTx` or similar methods.
9
+ *
10
+ * @param api - The API instance for the source chain
11
+ * @param destination - The destination chain: 'consensus' or { domainId: number }
12
+ * @param account - The destination account: { accountId32: string } for Substrate addresses or { accountId20: string } for EVM addresses
13
+ * @param amount - The amount to transfer (as string, number, or bigint)
14
+ * @returns A transaction that can be signed and submitted
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * // Transfer to consensus chain with Substrate address
19
+ * const tx = transfer(api, 'consensus', { accountId32: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY' }, '1000000000000000000')
20
+ *
21
+ * // Transfer to domain 0 with EVM address
22
+ * const tx = transfer(api, { domainId: 0 }, { accountId20: '0x1234567890abcdef1234567890abcdef12345678' }, '1000000000000000000')
23
+ *
24
+ * // Transfer to domain 1 with Substrate address
25
+ * const tx = transfer(api, { domainId: 1 }, { accountId32: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY' }, '1000000000000000000')
26
+ * ```
27
+ */
28
+ export declare const transporterTransfer: (api: ApiPromise, destination: Chain, account: TransferAccount, amount: StringNumberOrBigInt) => SubmittableExtrinsic<"promise", ISubmittableResult>;
7
29
  //# sourceMappingURL=transfer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transfer.d.ts","sourceRoot":"","sources":["../src/transfer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,EACL,UAAU,EACV,KAAK,EAIN,MAAM,uBAAuB,CAAA;AAE9B,eAAO,MAAM,QAAQ,GACnB,KAAK,UAAU,EACf,aAAa,KAAK,EAClB,QAAQ,oBAAoB,iIAG7B,CAAA;AAED,eAAO,MAAM,mBAAmB,GAC9B,KAAK,UAAU,EACf,aAAa,MAAM,EACnB,QAAQ,oBAAoB,iIAI7B,CAAA;AAED,eAAO,MAAM,6BAA6B,GACxC,KAAK,UAAU,EACf,qBAAqB,MAAM,GAAG,MAAM,EACpC,aAAa,MAAM,EACnB,QAAQ,oBAAoB,iIAI7B,CAAA;AAED,eAAO,MAAM,6BAA6B,GACxC,KAAK,UAAU,EACf,qBAAqB,MAAM,GAAG,MAAM,EACpC,aAAa,MAAM,EACnB,QAAQ,oBAAoB,iIAI7B,CAAA"}
1
+ {"version":3,"file":"transfer.d.ts","sourceRoot":"","sources":["../src/transfer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,EACL,UAAU,EAMV,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EAC1B,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAErD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,mBAAmB,GAC9B,KAAK,UAAU,EACf,aAAa,KAAK,EAClB,SAAS,eAAe,EACxB,QAAQ,oBAAoB,KAC3B,oBAAoB,CAAC,SAAS,EAAE,kBAAkB,CAsBpD,CAAA"}
package/dist/transfer.js CHANGED
@@ -1,33 +1,47 @@
1
1
  "use strict";
2
- // file: src/transfer.ts
3
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
- return new (P || (P = Promise))(function (resolve, reject) {
6
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
- step((generator = generator.apply(thisArg, _arguments || [])).next());
10
- });
11
- };
12
2
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.transferToDomainAccount32Type = exports.transferToDomainAccount20Type = exports.transferToConsensus = exports.transfer = void 0;
3
+ exports.transporterTransfer = void 0;
14
4
  const auto_utils_1 = require("@autonomys/auto-utils");
15
- const transfer = (api, destination, amount) => __awaiter(void 0, void 0, void 0, function* () {
16
- return yield api.tx.transporter.transfer(destination, amount);
17
- });
18
- exports.transfer = transfer;
19
- const transferToConsensus = (api, accountId32, amount) => __awaiter(void 0, void 0, void 0, function* () {
20
- const destination = (0, auto_utils_1.createTransporterToConsensusType)(api, accountId32);
21
- return yield (0, exports.transfer)(api, destination, amount);
22
- });
23
- exports.transferToConsensus = transferToConsensus;
24
- const transferToDomainAccount20Type = (api, destinationDomainId, accountId20, amount) => __awaiter(void 0, void 0, void 0, function* () {
25
- const destination = (0, auto_utils_1.createTransporterToDomainAccount20Type)(api, destinationDomainId, accountId20);
26
- return yield (0, exports.transfer)(api, destination, amount);
27
- });
28
- exports.transferToDomainAccount20Type = transferToDomainAccount20Type;
29
- const transferToDomainAccount32Type = (api, destinationDomainId, accountId32, amount) => __awaiter(void 0, void 0, void 0, function* () {
30
- const destination = (0, auto_utils_1.createTransporterToDomainAccount32Type)(api, destinationDomainId, accountId32);
31
- return yield (0, exports.transfer)(api, destination, amount);
32
- });
33
- exports.transferToDomainAccount32Type = transferToDomainAccount32Type;
5
+ /**
6
+ * Creates a transfer transaction to be submitted.
7
+ *
8
+ * This function creates a transaction but does not submit it. The returned transaction
9
+ * must be signed and sent using `signAndSendTx` or similar methods.
10
+ *
11
+ * @param api - The API instance for the source chain
12
+ * @param destination - The destination chain: 'consensus' or { domainId: number }
13
+ * @param account - The destination account: { accountId32: string } for Substrate addresses or { accountId20: string } for EVM addresses
14
+ * @param amount - The amount to transfer (as string, number, or bigint)
15
+ * @returns A transaction that can be signed and submitted
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * // Transfer to consensus chain with Substrate address
20
+ * const tx = transfer(api, 'consensus', { accountId32: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY' }, '1000000000000000000')
21
+ *
22
+ * // Transfer to domain 0 with EVM address
23
+ * const tx = transfer(api, { domainId: 0 }, { accountId20: '0x1234567890abcdef1234567890abcdef12345678' }, '1000000000000000000')
24
+ *
25
+ * // Transfer to domain 1 with Substrate address
26
+ * const tx = transfer(api, { domainId: 1 }, { accountId32: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY' }, '1000000000000000000')
27
+ * ```
28
+ */
29
+ const transporterTransfer = (api, destination, account, amount) => {
30
+ // Create chain ID codec
31
+ const chainId = destination === 'consensus'
32
+ ? (0, auto_utils_1.createDomainsChainIdType)(api)
33
+ : (0, auto_utils_1.createDomainsChainIdType)(api, destination.domainId);
34
+ // Create account ID codec based on account type
35
+ const accountId = 'accountId32' in account
36
+ ? (0, auto_utils_1.createMultiAccountIdType)(api, {
37
+ accountId32: (0, auto_utils_1.createAccountId32Type)(api, account.accountId32),
38
+ })
39
+ : (0, auto_utils_1.createMultiAccountIdType)(api, {
40
+ accountId20: (0, auto_utils_1.createAccountId20Type)(api, account.accountId20),
41
+ });
42
+ // Create location type
43
+ const location = (0, auto_utils_1.createTransporterLocationType)(api, chainId, accountId);
44
+ // Return transaction
45
+ return api.tx.transporter.transfer(location, amount);
46
+ };
47
+ exports.transporterTransfer = transporterTransfer;
@@ -0,0 +1,29 @@
1
+ import { Codec, type ApiPromise } from '@autonomys/auto-utils';
2
+ import type { Chain, ChainId, Channel } from './types';
3
+ /**
4
+ * Converts ChainId (JSON representation) to Chain (friendly type).
5
+ * Used when reading from storage.
6
+ *
7
+ * @internal
8
+ */
9
+ export declare const chainIdToChain: (chainId: ChainId) => Chain;
10
+ /**
11
+ * Converts Chain (friendly type) to ChainId Codec.
12
+ * Used for storage queries that require a ChainId.
13
+ *
14
+ * @internal
15
+ */
16
+ export declare const chainToChainIdCodec: (api: ApiPromise, chain: Chain) => Codec;
17
+ /**
18
+ * Helper to convert Channel Codec to friendly Channel type
19
+ * @internal
20
+ */
21
+ export declare const codecToChannel: (codec: unknown) => Channel | null;
22
+ /**
23
+ * Converts balance Codec to bigint.
24
+ * Used when reading balances from storage.
25
+ *
26
+ * @internal
27
+ */
28
+ export declare const codecToBalance: (codec: unknown) => bigint;
29
+ //# sourceMappingURL=transforms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transforms.d.ts","sourceRoot":"","sources":["../src/transforms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAA4B,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACxF,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAgB,MAAM,SAAS,CAAA;AAEpE;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,OAAO,KAAG,KAKjD,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAAI,KAAK,UAAU,EAAE,OAAO,KAAK,KAAG,KAKnE,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,OAAO,KAAG,OAAO,GAAG,IA2CzD,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,OAAO,KAAG,MAgB/C,CAAA"}
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.codecToBalance = exports.codecToChannel = exports.chainToChainIdCodec = exports.chainIdToChain = void 0;
4
+ const auto_utils_1 = require("@autonomys/auto-utils");
5
+ /**
6
+ * Converts ChainId (JSON representation) to Chain (friendly type).
7
+ * Used when reading from storage.
8
+ *
9
+ * @internal
10
+ */
11
+ const chainIdToChain = (chainId) => {
12
+ if ('consensus' in chainId) {
13
+ return 'consensus';
14
+ }
15
+ return { domainId: chainId.domain };
16
+ };
17
+ exports.chainIdToChain = chainIdToChain;
18
+ /**
19
+ * Converts Chain (friendly type) to ChainId Codec.
20
+ * Used for storage queries that require a ChainId.
21
+ *
22
+ * @internal
23
+ */
24
+ const chainToChainIdCodec = (api, chain) => {
25
+ if (chain === 'consensus') {
26
+ return (0, auto_utils_1.createDomainsChainIdType)(api);
27
+ }
28
+ return (0, auto_utils_1.createDomainsChainIdType)(api, chain.domainId);
29
+ };
30
+ exports.chainToChainIdCodec = chainToChainIdCodec;
31
+ /**
32
+ * Helper to convert Channel Codec to friendly Channel type
33
+ * @internal
34
+ */
35
+ const codecToChannel = (codec) => {
36
+ var _a, _b, _c, _d, _e, _f;
37
+ if (!codec || typeof codec !== 'object')
38
+ return null;
39
+ // Check if it's an empty Codec
40
+ if ('isEmpty' in codec && codec.isEmpty) {
41
+ return null;
42
+ }
43
+ // Convert to JSON first to get the structure
44
+ const json = 'toJSON' in codec && typeof codec.toJSON === 'function'
45
+ ? codec.toJSON()
46
+ : codec;
47
+ if (!json || typeof json !== 'object')
48
+ return null;
49
+ const channel = json;
50
+ // Convert field names from Rust snake_case to camelCase
51
+ const state = channel.state;
52
+ const stateMap = {
53
+ Initiated: 'Initiated',
54
+ Open: 'Open',
55
+ Closed: 'Closed',
56
+ };
57
+ return {
58
+ channelId: String((_a = channel.channel_id) !== null && _a !== void 0 ? _a : '0'),
59
+ state: (_b = stateMap[state]) !== null && _b !== void 0 ? _b : 'Initiated',
60
+ nextInboxNonce: String((_c = channel.next_inbox_nonce) !== null && _c !== void 0 ? _c : '0'),
61
+ nextOutboxNonce: String((_d = channel.next_outbox_nonce) !== null && _d !== void 0 ? _d : '0'),
62
+ latestResponseReceivedMessageNonce: channel.latest_response_received_message_nonce !== null &&
63
+ channel.latest_response_received_message_nonce !== undefined
64
+ ? String(channel.latest_response_received_message_nonce)
65
+ : null,
66
+ maxOutgoingMessages: Number((_e = channel.max_outgoing_messages) !== null && _e !== void 0 ? _e : 0),
67
+ maybeOwner: channel.maybe_owner !== null && channel.maybe_owner !== undefined
68
+ ? String(channel.maybe_owner)
69
+ : null,
70
+ channelReserveFee: String((_f = channel.channel_reserve_fee) !== null && _f !== void 0 ? _f : '0'),
71
+ };
72
+ };
73
+ exports.codecToChannel = codecToChannel;
74
+ /**
75
+ * Converts balance Codec to bigint.
76
+ * Used when reading balances from storage.
77
+ *
78
+ * @internal
79
+ */
80
+ const codecToBalance = (codec) => {
81
+ if (!codec || typeof codec !== 'object')
82
+ return BigInt(0);
83
+ // Handle toString method (common for Polkadot Codecs)
84
+ if ('toString' in codec && typeof codec.toString === 'function') {
85
+ return BigInt(codec.toString());
86
+ }
87
+ // Handle Codec with toJSON method
88
+ if ('toJSON' in codec && typeof codec.toJSON === 'function') {
89
+ const json = codec.toJSON();
90
+ return BigInt(String(json !== null && json !== void 0 ? json : 0));
91
+ }
92
+ // At this point, codec is guaranteed to be truthy (due to early return above)
93
+ return BigInt(String(codec));
94
+ };
95
+ exports.codecToBalance = codecToBalance;
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Chain identifier for queries and transfers.
3
+ *
4
+ * Use the string literal 'consensus' for the consensus chain,
5
+ * or an object with domainId for a specific domain.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // Consensus chain
10
+ * const consensus: Chain = 'consensus'
11
+ *
12
+ * // Domain chain (e.g., domain 1)
13
+ * const domain: Chain = { domainId: 1 }
14
+ * ```
15
+ */
16
+ export type Chain = 'consensus' | {
17
+ domainId: number;
18
+ };
19
+ /**
20
+ * Account identifier for transfers.
21
+ * Provide either accountId32 (for Substrate/SS58 addresses) or accountId20 (for EVM addresses).
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * // Substrate/SS58 address
26
+ * const substrateAccount: TransferAccount = { accountId32: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY' }
27
+ *
28
+ * // EVM address
29
+ * const evmAccount: TransferAccount = { accountId20: '0x1234567890abcdef1234567890abcdef12345678' }
30
+ * ```
31
+ */
32
+ export type TransferAccount = {
33
+ accountId32: string;
34
+ } | {
35
+ accountId20: string;
36
+ };
37
+ /**
38
+ * Chain ID enum variant representing either the consensus chain or a domain chain.
39
+ *
40
+ * This matches the Rust `ChainId` enum. When serialized to JSON by Polkadot.js,
41
+ * the keys are lowercase (`consensus`, `domain`), matching the JSON representation.
42
+ *
43
+ * Note: When creating ChainId types programmatically (e.g., with `createDomainsChainIdType`),
44
+ * use PascalCase keys (`{ Consensus: null }` or `{ Domain: number }`).
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * // Consensus chain ID (JSON representation)
49
+ * const consensusId: ChainId = { consensus: null }
50
+ *
51
+ * // Domain chain ID (JSON representation, e.g., domain 0)
52
+ * const domainId: ChainId = { domain: 0 }
53
+ *
54
+ * // When creating types programmatically, use PascalCase:
55
+ * const consensusCodec = createDomainsChainIdType(api) // { Consensus: null }
56
+ * const domainCodec = createDomainsChainIdType(api, 0) // { Domain: 0 }
57
+ * ```
58
+ */
59
+ export type ChainId = {
60
+ consensus: null;
61
+ } | {
62
+ domain: number;
63
+ };
64
+ /**
65
+ * Chain allowlist return type.
66
+ *
67
+ * Represents a BTreeSet of ChainId values that can open channels with the current chain.
68
+ * Converted to the friendlier Chain type for easier use.
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * const allowlist = await chainAllowlist(api)
73
+ * // allowlist: ['consensus'] or [{ domainId: 0 }, { domainId: 1 }]
74
+ * ```
75
+ */
76
+ export type ChainAllowlist = Chain[];
77
+ /**
78
+ * Channel state enum.
79
+ *
80
+ * Represents the state of a channel between two chains.
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * const state: ChannelState = 'Initiated' // or 'Open' or 'Closed'
85
+ * ```
86
+ */
87
+ export type ChannelState = 'Initiated' | 'Open' | 'Closed';
88
+ /**
89
+ * Channel configuration.
90
+ *
91
+ * Represents a channel between two chains for exchanging messages.
92
+ * All numeric values (nonces, fees) are returned as strings to handle large numbers.
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * const channel = await channels(api, { domainId: 0 }, 0)
97
+ * // channel: {
98
+ * // channelId: "0",
99
+ * // state: "Open",
100
+ * // nextInboxNonce: "1",
101
+ * // nextOutboxNonce: "2",
102
+ * // latestResponseReceivedMessageNonce: "1",
103
+ * // maxOutgoingMessages: 10000,
104
+ * // maybeOwner: "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
105
+ * // channelReserveFee: "1000000000000"
106
+ * // }
107
+ * ```
108
+ */
109
+ export type Channel = {
110
+ /** Channel identifier (U256 as string) */
111
+ channelId: string;
112
+ /** Current state of the channel */
113
+ state: ChannelState;
114
+ /** Next inbox nonce (U256 as string) */
115
+ nextInboxNonce: string;
116
+ /** Next outbox nonce (U256 as string) */
117
+ nextOutboxNonce: string;
118
+ /** Latest outbox message nonce for which response was received (U256 as string, or null) */
119
+ latestResponseReceivedMessageNonce: string | null;
120
+ /** Maximum outgoing non-delivered messages */
121
+ maxOutgoingMessages: number;
122
+ /** Owner account ID, or null if channel was initiated on the other chain */
123
+ maybeOwner: string | null;
124
+ /** Amount of funds put on hold by the owner account for this channel (Balance as string) */
125
+ channelReserveFee: string;
126
+ };
127
+ /**
128
+ * Domain balance entry.
129
+ *
130
+ * Represents the balance available on a domain for processing transfers.
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * const balance: DomainBalance = { domainId: 0, balance: 1000000000000n }
135
+ * ```
136
+ */
137
+ export type DomainBalance = {
138
+ /** Domain ID */
139
+ domainId: number;
140
+ /** Balance amount (bigint to handle large numbers and enable arithmetic) */
141
+ balance: bigint;
142
+ };
143
+ /**
144
+ * Transfer entry between two chains.
145
+ *
146
+ * Represents a transfer (cancelled or unconfirmed) between a source and destination chain.
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * const transfer: Transfer = {
151
+ * from: 'consensus',
152
+ * to: { domainId: 0 },
153
+ * amount: 1000000000000n
154
+ * }
155
+ * ```
156
+ */
157
+ export type Transfer = {
158
+ /** Source chain */
159
+ from: Chain;
160
+ /** Destination chain */
161
+ to: Chain;
162
+ /** Transfer amount (bigint to handle large numbers and enable arithmetic) */
163
+ amount: bigint;
164
+ };
165
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,KAAK,GAAG,WAAW,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAA;AAEtD;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,eAAe,GAAG;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAAA;AAE/E;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,MAAM,OAAO,GAAG;IAAE,SAAS,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAA;AAE9D;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,EAAE,CAAA;AAEpC;;;;;;;;;GASG;AACH,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG,MAAM,GAAG,QAAQ,CAAA;AAE1D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,0CAA0C;IAC1C,SAAS,EAAE,MAAM,CAAA;IACjB,mCAAmC;IACnC,KAAK,EAAE,YAAY,CAAA;IACnB,wCAAwC;IACxC,cAAc,EAAE,MAAM,CAAA;IACtB,yCAAyC;IACzC,eAAe,EAAE,MAAM,CAAA;IACvB,4FAA4F;IAC5F,kCAAkC,EAAE,MAAM,GAAG,IAAI,CAAA;IACjD,8CAA8C;IAC9C,mBAAmB,EAAE,MAAM,CAAA;IAC3B,4EAA4E;IAC5E,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,4FAA4F;IAC5F,iBAAiB,EAAE,MAAM,CAAA;CAC1B,CAAA;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,gBAAgB;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,4EAA4E;IAC5E,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,mBAAmB;IACnB,IAAI,EAAE,KAAK,CAAA;IACX,wBAAwB;IACxB,EAAE,EAAE,KAAK,CAAA;IACT,6EAA6E;IAC7E,MAAM,EAAE,MAAM,CAAA;CACf,CAAA"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autonomys/auto-xdm",
3
- "version": "1.5.19",
3
+ "version": "1.6.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -25,8 +25,8 @@
25
25
  "README.md"
26
26
  ],
27
27
  "dependencies": {
28
- "@autonomys/auto-consensus": "^1.5.19",
29
- "@autonomys/auto-utils": "^1.5.19"
28
+ "@autonomys/auto-consensus": "^1.6.0",
29
+ "@autonomys/auto-utils": "^1.6.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/jest": "^29.5.14",
@@ -36,5 +36,5 @@
36
36
  "ts-jest": "^29.3.1",
37
37
  "typescript": "^5.8.3"
38
38
  },
39
- "gitHead": "ada024eb3cb14bf67b3d9f1cb8545e7b7d9d14ed"
39
+ "gitHead": "a0a448db8d1a26006c4123ad9a0e53a8c9293255"
40
40
  }