@agoric/orchestration 0.2.0-upgrade-20-dev-ef71cfd.0 → 0.2.0-upgrade-19-devnet-dev-5428c4d.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/package.json +27 -29
- package/src/chain-capabilities.d.ts +12 -7
- package/src/chain-capabilities.d.ts.map +1 -1
- package/src/chain-capabilities.js +21 -46
- package/src/chain-info.d.ts +97 -839
- package/src/chain-info.d.ts.map +1 -1
- package/src/chain-info.js +12 -38
- package/src/cosmos-api.d.ts +13 -41
- package/src/cosmos-api.d.ts.map +1 -1
- package/src/cosmos-api.ts +16 -52
- package/src/ethereum-api.d.ts +5 -6
- package/src/ethereum-api.d.ts.map +1 -1
- package/src/ethereum-api.ts +5 -7
- package/src/examples/auto-stake-it-tap-kit.d.ts +4 -4
- package/src/examples/auto-stake-it-tap-kit.d.ts.map +1 -1
- package/src/examples/auto-stake-it-tap-kit.js +8 -8
- package/src/examples/auto-stake-it.contract.d.ts +23 -5
- package/src/examples/auto-stake-it.contract.d.ts.map +1 -1
- package/src/examples/auto-stake-it.contract.js +0 -1
- package/src/examples/basic-flows.contract.d.ts +13 -5
- package/src/examples/basic-flows.contract.d.ts.map +1 -1
- package/src/examples/basic-flows.contract.js +0 -1
- package/src/examples/send-anywhere.contract.d.ts +27 -7
- package/src/examples/send-anywhere.contract.d.ts.map +1 -1
- package/src/examples/send-anywhere.contract.js +12 -40
- package/src/examples/send-anywhere.flows.d.ts +3 -563
- package/src/examples/send-anywhere.flows.d.ts.map +1 -1
- package/src/examples/send-anywhere.flows.js +31 -112
- package/src/examples/stake-bld.contract.d.ts +7 -8
- package/src/examples/stake-bld.contract.d.ts.map +1 -1
- package/src/examples/stake-bld.contract.js +1 -3
- package/src/examples/stake-ica.contract.d.ts +13 -82
- package/src/examples/stake-ica.contract.d.ts.map +1 -1
- package/src/examples/stake-ica.contract.js +0 -1
- package/src/examples/staking-combinations.contract.d.ts +11 -3
- package/src/examples/staking-combinations.contract.d.ts.map +1 -1
- package/src/examples/staking-combinations.contract.js +4 -5
- package/src/examples/staking-combinations.flows.d.ts +2 -2
- package/src/examples/staking-combinations.flows.d.ts.map +1 -1
- package/src/examples/staking-combinations.flows.js +4 -4
- package/src/examples/swap.contract.d.ts +13 -4
- package/src/examples/swap.contract.d.ts.map +1 -1
- package/src/examples/swap.contract.js +2 -2
- package/src/examples/unbond.contract.d.ts +2 -2
- package/src/exos/README.md +0 -1
- package/src/exos/chain-hub-admin.d.ts +9 -9
- package/src/exos/chain-hub-admin.d.ts.map +1 -1
- package/src/exos/chain-hub-admin.js +17 -17
- package/src/exos/chain-hub.d.ts +17 -69
- package/src/exos/chain-hub.d.ts.map +1 -1
- package/src/exos/chain-hub.js +55 -289
- package/src/exos/cosmos-orchestration-account.d.ts +17 -86
- package/src/exos/cosmos-orchestration-account.d.ts.map +1 -1
- package/src/exos/cosmos-orchestration-account.js +26 -111
- package/src/exos/ibc-packet.d.ts +0 -1
- package/src/exos/ibc-packet.d.ts.map +1 -1
- package/src/exos/ibc-packet.js +1 -8
- package/src/exos/ica-account-kit.d.ts +4 -8
- package/src/exos/ica-account-kit.d.ts.map +1 -1
- package/src/exos/ica-account-kit.js +5 -8
- package/src/exos/local-chain-facade.d.ts +23 -3
- package/src/exos/local-chain-facade.d.ts.map +1 -1
- package/src/exos/local-chain-facade.js +3 -3
- package/src/exos/local-orchestration-account.d.ts +12 -16
- package/src/exos/local-orchestration-account.d.ts.map +1 -1
- package/src/exos/local-orchestration-account.js +8 -13
- package/src/exos/orchestrator.d.ts +15 -5
- package/src/exos/orchestrator.d.ts.map +1 -1
- package/src/exos/orchestrator.js +10 -9
- package/src/exos/packet-tools.d.ts +1 -1
- package/src/exos/packet-tools.d.ts.map +1 -1
- package/src/exos/packet-tools.js +12 -17
- package/src/exos/portfolio-holder-kit.d.ts +0 -1
- package/src/exos/portfolio-holder-kit.d.ts.map +1 -1
- package/src/exos/portfolio-holder-kit.js +0 -1
- package/src/exos/remote-chain-facade.d.ts +15 -5
- package/src/exos/remote-chain-facade.d.ts.map +1 -1
- package/src/exos/remote-chain-facade.js +13 -23
- package/src/facade.js +1 -1
- package/src/fetched-chain-info.d.ts +86 -676
- package/src/fetched-chain-info.js +41 -553
- package/src/fixtures/query-flows.contract.d.ts +4 -5
- package/src/fixtures/query-flows.contract.d.ts.map +1 -1
- package/src/fixtures/query-flows.contract.js +0 -1
- package/src/orchestration-api.d.ts +16 -73
- package/src/orchestration-api.d.ts.map +1 -1
- package/src/orchestration-api.ts +19 -89
- package/src/proposals/start-send-anywhere.js +0 -4
- package/src/typeGuards.d.ts +4 -20
- package/src/typeGuards.d.ts.map +1 -1
- package/src/typeGuards.js +13 -52
- package/src/types.d.ts +1 -1
- package/src/types.d.ts.map +1 -1
- package/src/types.ts +1 -2
- package/src/utils/address.d.ts +3 -13
- package/src/utils/address.d.ts.map +1 -1
- package/src/utils/address.js +5 -97
- package/src/utils/chain-hub-helper.d.ts +2 -2
- package/src/utils/chain-hub-helper.d.ts.map +1 -1
- package/src/utils/chain-hub-helper.js +5 -9
- package/src/utils/cosmos.d.ts +1 -1
- package/src/utils/cosmos.d.ts.map +1 -1
- package/src/utils/cosmos.js +2 -2
- package/src/utils/orchestrationAccount.js +5 -6
- package/src/utils/registry.d.ts +12 -2
- package/src/utils/registry.d.ts.map +1 -1
- package/src/utils/registry.js +2 -4
- package/src/utils/start-helper.d.ts +6 -20
- package/src/utils/start-helper.d.ts.map +1 -1
- package/src/utils/start-helper.js +2 -13
- package/src/utils/zoe-tools.d.ts +2 -2
- package/src/utils/zoe-tools.d.ts.map +1 -1
- package/src/utils/zoe-tools.js +2 -5
- package/tools/ibc-mocks.d.ts +5 -6
- package/tools/ibc-mocks.d.ts.map +1 -1
- package/tools/ibc-mocks.ts +4 -10
- package/tools/make-test-address.d.ts +1 -2
- package/tools/make-test-address.d.ts.map +1 -1
- package/tools/make-test-address.js +2 -6
- package/src/cctp-chain-info.d.ts +0 -65
- package/src/cctp-chain-info.d.ts.map +0 -1
- package/src/cctp-chain-info.js +0 -52
- package/src/utils/chain-info.d.ts +0 -5
- package/src/utils/chain-info.d.ts.map +0 -1
- package/src/utils/chain-info.js +0 -11
package/src/exos/chain-hub.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { BrandShape } from '@agoric/ertp/src/typeGuards.js';
|
|
2
1
|
import { Fail, makeError, q } from '@endo/errors';
|
|
3
2
|
import { E } from '@endo/far';
|
|
4
3
|
import { M } from '@endo/patterns';
|
|
4
|
+
import { BrandShape } from '@agoric/ertp/src/typeGuards.js';
|
|
5
5
|
|
|
6
6
|
import { VowShape } from '@agoric/vow';
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
ChainInfoShape,
|
|
8
|
+
ChainAddressShape,
|
|
10
9
|
CoinShape,
|
|
11
|
-
|
|
10
|
+
CosmosChainInfoShape,
|
|
12
11
|
DenomAmountShape,
|
|
13
12
|
DenomDetailShape,
|
|
14
13
|
ForwardInfoShape,
|
|
@@ -17,17 +16,15 @@ import {
|
|
|
17
16
|
IBCConnectionInfoShape,
|
|
18
17
|
} from '../typeGuards.js';
|
|
19
18
|
import { getBech32Prefix } from '../utils/address.js';
|
|
20
|
-
import { caipIdFromInfo } from '../utils/chain-info.js';
|
|
21
19
|
|
|
22
20
|
/**
|
|
23
21
|
* @import {NameHub} from '@agoric/vats';
|
|
24
22
|
* @import {Vow, VowTools} from '@agoric/vow';
|
|
25
23
|
* @import {Zone} from '@agoric/zone';
|
|
26
|
-
* @import {CosmosAssetInfo, CosmosChainInfo, ForwardInfo, IBCConnectionInfo, IBCMsgTransferOptions, TransferRoute, GoDuration
|
|
27
|
-
* @import {KnownChains} from '../chain-info.js';
|
|
28
|
-
* @import {
|
|
24
|
+
* @import {CosmosAssetInfo, CosmosChainInfo, ForwardInfo, IBCConnectionInfo, IBCMsgTransferOptions, TransferRoute, GoDuration} from '../cosmos-api.js';
|
|
25
|
+
* @import {ChainInfo, KnownChains} from '../chain-info.js';
|
|
26
|
+
* @import {ChainAddress, Denom, DenomAmount} from '../orchestration-api.js';
|
|
29
27
|
* @import {Remote, TypedPattern} from '@agoric/internal';
|
|
30
|
-
* @import {Pattern} from '@endo/patterns';
|
|
31
28
|
*/
|
|
32
29
|
|
|
33
30
|
/** receiver address value for ibc transfers that involve PFM */
|
|
@@ -77,8 +74,6 @@ export const ASSETS_KEY = HubName.ChainAssets;
|
|
|
77
74
|
*/
|
|
78
75
|
const CHAIN_ID_SEPARATOR = '_';
|
|
79
76
|
|
|
80
|
-
/** @typedef {`${string}${CHAIN_ID_SEPARATOR}${string}`} IbcConnectionKey */
|
|
81
|
-
|
|
82
77
|
/**
|
|
83
78
|
* Vstorage keys can be only alphanumerics, dash, or underscore, which are all
|
|
84
79
|
* valid characters in chain IDs. So, double each occurence of
|
|
@@ -101,15 +96,12 @@ export const encodeChainId = chainId =>
|
|
|
101
96
|
*
|
|
102
97
|
* @param {string} chainId1
|
|
103
98
|
* @param {string} chainId2
|
|
104
|
-
* @returns {IbcConnectionKey}
|
|
105
99
|
*/
|
|
106
100
|
export const connectionKey = (chainId1, chainId2) => {
|
|
107
101
|
const chainId1Sanitized = encodeChainId(chainId1);
|
|
108
102
|
const chainId2Sanitized = encodeChainId(chainId2);
|
|
109
103
|
|
|
110
|
-
return
|
|
111
|
-
[chainId1Sanitized, chainId2Sanitized].sort().join(CHAIN_ID_SEPARATOR)
|
|
112
|
-
);
|
|
104
|
+
return [chainId1Sanitized, chainId2Sanitized].sort().join(CHAIN_ID_SEPARATOR);
|
|
113
105
|
};
|
|
114
106
|
|
|
115
107
|
/**
|
|
@@ -144,7 +136,7 @@ const reverseConnInfo = connInfo => {
|
|
|
144
136
|
* @param {string} primaryChainId
|
|
145
137
|
* @param {string} counterChainId
|
|
146
138
|
* @param {IBCConnectionInfo} directed
|
|
147
|
-
* @returns {[
|
|
139
|
+
* @returns {[string, IBCConnectionInfo]}
|
|
148
140
|
*/
|
|
149
141
|
export const normalizeConnectionInfo = (
|
|
150
142
|
primaryChainId,
|
|
@@ -210,33 +202,22 @@ export const TransferRouteShape = M.splitRecord(
|
|
|
210
202
|
);
|
|
211
203
|
|
|
212
204
|
const ChainHubI = M.interface('ChainHub', {
|
|
213
|
-
registerChain: M.call(M.string(),
|
|
214
|
-
updateChain: M.call(M.string(), ChainInfoShape).returns(),
|
|
205
|
+
registerChain: M.call(M.string(), CosmosChainInfoShape).returns(),
|
|
215
206
|
getChainInfo: M.call(M.string()).returns(VowShape),
|
|
216
|
-
getChainInfoByChainId: M.call(M.string()).returns(ChainInfoShape),
|
|
217
207
|
registerConnection: M.call(
|
|
218
208
|
M.string(),
|
|
219
209
|
M.string(),
|
|
220
210
|
IBCConnectionInfoShape,
|
|
221
211
|
).returns(),
|
|
222
|
-
updateConnection: M.call(
|
|
223
|
-
M.string(),
|
|
224
|
-
M.string(),
|
|
225
|
-
IBCConnectionInfoShape,
|
|
226
|
-
).returns(),
|
|
227
212
|
getConnectionInfo: M.call(ChainIdArgShape, ChainIdArgShape).returns(VowShape),
|
|
228
213
|
getChainsAndConnection: M.call(M.string(), M.string()).returns(VowShape),
|
|
229
214
|
registerAsset: M.call(M.string(), DenomDetailShape).returns(),
|
|
230
|
-
updateAsset: M.call(M.string(), DenomDetailShape).returns(),
|
|
231
215
|
getAsset: M.call(M.string(), M.string()).returns(
|
|
232
216
|
M.or(DenomDetailShape, M.undefined()),
|
|
233
217
|
),
|
|
234
218
|
getDenom: M.call(BrandShape).returns(M.or(M.string(), M.undefined())),
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
),
|
|
238
|
-
resolveAccountId: M.call(M.string()).returns(M.string()),
|
|
239
|
-
makeTransferRoute: M.call(AccountIdArgShape, DenomAmountShape, M.string())
|
|
219
|
+
makeChainAddress: M.call(M.string()).returns(ChainAddressShape),
|
|
220
|
+
makeTransferRoute: M.call(ChainAddressShape, DenomAmountShape, M.string())
|
|
240
221
|
.optional(ForwardOptsShape)
|
|
241
222
|
.returns(M.or(M.undefined(), TransferRouteShape)),
|
|
242
223
|
});
|
|
@@ -244,40 +225,22 @@ const ChainHubI = M.interface('ChainHub', {
|
|
|
244
225
|
/**
|
|
245
226
|
* Make a new ChainHub in the zone.
|
|
246
227
|
*
|
|
247
|
-
* The resulting object is an Exo singleton. It has no precious state.
|
|
228
|
+
* The resulting object is an Exo singleton. It has no precious state. It's only
|
|
248
229
|
* state is a cache of queries to agoricNames and whatever info was provided in
|
|
249
230
|
* registration calls. When you need a newer version you can simply make a hub
|
|
250
|
-
* and repeat the registrations.
|
|
231
|
+
* hub and repeat the registrations.
|
|
251
232
|
*
|
|
252
233
|
* @param {Zone} zone
|
|
253
234
|
* @param {Remote<NameHub>} agoricNames
|
|
254
235
|
* @param {VowTools} vowTools
|
|
255
|
-
* @param {object} [opts]
|
|
256
|
-
* @param {Pattern} [opts.chainInfoValueShape] legacy support for contracts
|
|
257
|
-
* deployed with `valueShape: CosmosChainInfoShape`. If nothing is supplied,
|
|
258
|
-
* defaults to {@link ChainInfoShape}
|
|
259
236
|
*/
|
|
260
|
-
export const makeChainHub = (
|
|
261
|
-
|
|
262
|
-
agoricNames,
|
|
263
|
-
vowTools,
|
|
264
|
-
{ chainInfoValueShape = /** @type {Pattern} */ (ChainInfoShape) } = {},
|
|
265
|
-
) => {
|
|
266
|
-
/**
|
|
267
|
-
* Handle mapping of a chain's common name (e.g. 'ethereum' or "doravota") to
|
|
268
|
-
* its info (e.g. specififying CAIP-2 eip155:1 or Cosmos chainId 'votash')
|
|
269
|
-
*
|
|
270
|
-
* @type {MapStore<string, ChainInfo>}
|
|
271
|
-
*/
|
|
237
|
+
export const makeChainHub = (zone, agoricNames, vowTools) => {
|
|
238
|
+
/** @type {MapStore<string, CosmosChainInfo>} */
|
|
272
239
|
const chainInfos = zone.mapStore('chainInfos', {
|
|
273
240
|
keyShape: M.string(),
|
|
274
|
-
valueShape:
|
|
241
|
+
valueShape: CosmosChainInfoShape,
|
|
275
242
|
});
|
|
276
|
-
/**
|
|
277
|
-
* IBC connection paths, keyed by a function of each chain's Cosmos chainId
|
|
278
|
-
*
|
|
279
|
-
* @type {MapStore<IbcConnectionKey, IBCConnectionInfo>}
|
|
280
|
-
*/
|
|
243
|
+
/** @type {MapStore<string, IBCConnectionInfo>} */
|
|
281
244
|
const connectionInfos = zone.mapStore('connectionInfos', {
|
|
282
245
|
keyShape: M.string(),
|
|
283
246
|
valueShape: IBCConnectionInfoShape,
|
|
@@ -293,26 +256,11 @@ export const makeChainHub = (
|
|
|
293
256
|
keyShape: BrandShape,
|
|
294
257
|
valueShape: M.string(),
|
|
295
258
|
});
|
|
296
|
-
/**
|
|
297
|
-
* Handle mapping of, for example, "osmosis" chain that has bech32 prefix
|
|
298
|
-
* "osmo" and chainId "osmosis-1".
|
|
299
|
-
*
|
|
300
|
-
* @type {MapStore<string, string>}
|
|
301
|
-
*/
|
|
259
|
+
/** @type {MapStore<string, string>} */
|
|
302
260
|
const bech32PrefixToChainName = zone.mapStore('bech32PrefixToChainName', {
|
|
303
261
|
keyShape: M.string(),
|
|
304
262
|
valueShape: M.string(),
|
|
305
263
|
});
|
|
306
|
-
/**
|
|
307
|
-
* CaipChainId is implied by the ChainInfo. The value in this store is a key
|
|
308
|
-
* into `chainInfos`.
|
|
309
|
-
*
|
|
310
|
-
* @type {MapStore<CaipChainId, string>}
|
|
311
|
-
*/
|
|
312
|
-
const chainIdToChainName = zone.mapStore('chainIdToChainName', {
|
|
313
|
-
keyShape: M.string(),
|
|
314
|
-
valueShape: M.string(),
|
|
315
|
-
});
|
|
316
264
|
|
|
317
265
|
/**
|
|
318
266
|
* @param {Denom} denom - from perspective of the src/holding chain
|
|
@@ -320,23 +268,6 @@ export const makeChainHub = (
|
|
|
320
268
|
*/
|
|
321
269
|
const makeDenomKey = (denom, srcChainName) => `${srcChainName}:${denom}`;
|
|
322
270
|
|
|
323
|
-
/**
|
|
324
|
-
* @param {Bech32Address | string} address
|
|
325
|
-
* @returns {string}
|
|
326
|
-
*/
|
|
327
|
-
const resolveCosmosChainId = address => {
|
|
328
|
-
// Infer it from the bech32 prefix
|
|
329
|
-
const prefix = getBech32Prefix(address);
|
|
330
|
-
if (!bech32PrefixToChainName.has(prefix)) {
|
|
331
|
-
throw makeError(`Chain info not found for bech32Prefix ${q(prefix)}`);
|
|
332
|
-
}
|
|
333
|
-
const chainName = bech32PrefixToChainName.get(prefix);
|
|
334
|
-
const { chainId } = /** @type {CosmosChainInfo} */ (
|
|
335
|
-
chainInfos.get(chainName)
|
|
336
|
-
);
|
|
337
|
-
return chainId;
|
|
338
|
-
};
|
|
339
|
-
|
|
340
271
|
const lookupChainInfo = vowTools.retryable(
|
|
341
272
|
zone,
|
|
342
273
|
'lookupChainInfo',
|
|
@@ -350,7 +281,6 @@ export const makeChainHub = (
|
|
|
350
281
|
// TODO consider makeAtomicProvider for vows
|
|
351
282
|
if (!chainInfos.has(chainName)) {
|
|
352
283
|
chainInfos.init(chainName, chainInfo);
|
|
353
|
-
chainIdToChainName.init(caipIdFromInfo(chainInfo), chainName);
|
|
354
284
|
if (chainInfo.bech32Prefix) {
|
|
355
285
|
bech32PrefixToChainName.init(chainInfo.bech32Prefix, chainName);
|
|
356
286
|
}
|
|
@@ -402,11 +332,7 @@ export const makeChainHub = (
|
|
|
402
332
|
* @param {C1} primaryName
|
|
403
333
|
* @param {C2} counterName
|
|
404
334
|
* @returns {Promise<
|
|
405
|
-
* [
|
|
406
|
-
* ActualChainInfo<C1>,
|
|
407
|
-
* ActualChainInfo<C2>,
|
|
408
|
-
* IBCConnectionInfo | undefined,
|
|
409
|
-
* ]
|
|
335
|
+
* [ActualChainInfo<C1>, ActualChainInfo<C2>, IBCConnectionInfo]
|
|
410
336
|
* >}
|
|
411
337
|
*/
|
|
412
338
|
// eslint-disable-next-line no-restricted-syntax -- TODO more exact rules for vow best practices
|
|
@@ -417,22 +343,14 @@ export const makeChainHub = (
|
|
|
417
343
|
chainHub.getChainInfo(counterName),
|
|
418
344
|
]),
|
|
419
345
|
);
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
primary.namespace === 'cosmos' && counter.namespace === 'cosmos'
|
|
423
|
-
? await vowTools.asPromise(
|
|
424
|
-
chainHub.getConnectionInfo(primary, counter),
|
|
425
|
-
)
|
|
426
|
-
: undefined;
|
|
427
|
-
return (
|
|
428
|
-
/**
|
|
429
|
-
* @type {[
|
|
430
|
-
* ActualChainInfo<C1>,
|
|
431
|
-
* ActualChainInfo<C2>,
|
|
432
|
-
* IBCConnectionInfo | undefined,
|
|
433
|
-
* ]}
|
|
434
|
-
*/ ([primary, counter, connectionInfo])
|
|
346
|
+
const connectionInfo = await vowTools.asPromise(
|
|
347
|
+
chainHub.getConnectionInfo(primary, counter),
|
|
435
348
|
);
|
|
349
|
+
return /** @type {[ActualChainInfo<C1>, ActualChainInfo<C2>, IBCConnectionInfo]} */ ([
|
|
350
|
+
primary,
|
|
351
|
+
counter,
|
|
352
|
+
connectionInfo,
|
|
353
|
+
]);
|
|
436
354
|
},
|
|
437
355
|
);
|
|
438
356
|
|
|
@@ -447,80 +365,30 @@ export const makeChainHub = (
|
|
|
447
365
|
* contract `start` the call will happen again naturally.
|
|
448
366
|
*
|
|
449
367
|
* @param {string} name
|
|
450
|
-
* @param {
|
|
368
|
+
* @param {CosmosChainInfo} chainInfo
|
|
451
369
|
*/
|
|
452
370
|
registerChain(name, chainInfo) {
|
|
453
371
|
chainInfos.init(name, chainInfo);
|
|
454
|
-
|
|
455
|
-
if (chainInfo.namespace === 'cosmos' && chainInfo.bech32Prefix) {
|
|
372
|
+
if (chainInfo.bech32Prefix) {
|
|
456
373
|
bech32PrefixToChainName.init(chainInfo.bech32Prefix, name);
|
|
457
374
|
}
|
|
458
375
|
},
|
|
459
|
-
/**
|
|
460
|
-
* Update chain info by completely replacing existing entry
|
|
461
|
-
*
|
|
462
|
-
* @param {string} chainName - Name of the chain to update
|
|
463
|
-
* @param {ChainInfo} chainInfo - New chain info
|
|
464
|
-
* @throws {Error} If chain not registered
|
|
465
|
-
*/
|
|
466
|
-
updateChain(chainName, chainInfo) {
|
|
467
|
-
if (!chainInfos.has(chainName)) {
|
|
468
|
-
throw makeError(`Chain ${q(chainName)} not registered`);
|
|
469
|
-
}
|
|
470
|
-
const oldInfo = chainInfos.get(chainName);
|
|
471
|
-
// defensively check, for older versions which may not have `chainIdToChainName`
|
|
472
|
-
if (chainIdToChainName.has(caipIdFromInfo(oldInfo))) {
|
|
473
|
-
chainIdToChainName.delete(caipIdFromInfo(oldInfo));
|
|
474
|
-
}
|
|
475
|
-
if (/** @type {CosmosChainInfo} */ (oldInfo).bech32Prefix) {
|
|
476
|
-
bech32PrefixToChainName.delete(
|
|
477
|
-
/** @type {CosmosChainInfo} */ (oldInfo).bech32Prefix,
|
|
478
|
-
);
|
|
479
|
-
}
|
|
480
|
-
chainInfos.set(chainName, chainInfo);
|
|
481
|
-
chainIdToChainName.init(caipIdFromInfo(chainInfo), chainName);
|
|
482
|
-
if (/** @type {CosmosChainInfo} */ (chainInfo).bech32Prefix) {
|
|
483
|
-
bech32PrefixToChainName.init(
|
|
484
|
-
/** @type {CosmosChainInfo} */ (chainInfo).bech32Prefix,
|
|
485
|
-
chainName,
|
|
486
|
-
);
|
|
487
|
-
}
|
|
488
|
-
},
|
|
489
376
|
/**
|
|
490
377
|
* @template {string} K
|
|
491
378
|
* @param {K} chainName
|
|
492
379
|
* @returns {Vow<ActualChainInfo<K>>}
|
|
493
380
|
*/
|
|
494
381
|
getChainInfo(chainName) {
|
|
495
|
-
chainName.includes(':') &&
|
|
496
|
-
Fail`${chainName} must be a bare chain name. Maybe try getChainInfoByChainId()`;
|
|
497
382
|
// Either from registerChain or memoized remote lookup()
|
|
498
383
|
if (chainInfos.has(chainName)) {
|
|
499
384
|
return /** @type {Vow<ActualChainInfo<K>>} */ (
|
|
500
|
-
vowTools.asVow(() =>
|
|
501
|
-
// @ts-expect-error Type 'ChainInfo' is not assignable to type 'CosmosChainInfo | Vow<CosmosChainInfo> | PromiseVow<CosmosChainInfo>'.
|
|
502
|
-
chainInfos.get(chainName),
|
|
503
|
-
)
|
|
385
|
+
vowTools.asVow(() => chainInfos.get(chainName))
|
|
504
386
|
);
|
|
505
387
|
}
|
|
506
388
|
|
|
507
389
|
return lookupChainInfo(chainName);
|
|
508
390
|
},
|
|
509
391
|
/**
|
|
510
|
-
* @param {CaipChainId} chainId
|
|
511
|
-
* @returns {ChainInfo}
|
|
512
|
-
*/
|
|
513
|
-
getChainInfoByChainId(chainId) {
|
|
514
|
-
// Either from registerChain or memoized remote lookup()
|
|
515
|
-
chainIdToChainName.has(chainId) ||
|
|
516
|
-
Fail`Chain name not found for ${q(chainId)}`;
|
|
517
|
-
const chainName = chainIdToChainName.get(chainId);
|
|
518
|
-
chainInfos.has(chainName) || Fail`Chain Info not found for ${q(chainId)}`;
|
|
519
|
-
return chainInfos.get(chainName);
|
|
520
|
-
},
|
|
521
|
-
/**
|
|
522
|
-
* Register information for a Cosmos chain
|
|
523
|
-
*
|
|
524
392
|
* @param {string} primaryChainId
|
|
525
393
|
* @param {string} counterpartyChainId
|
|
526
394
|
* @param {IBCConnectionInfo} connectionInfo from primary to counterparty
|
|
@@ -533,29 +401,7 @@ export const makeChainHub = (
|
|
|
533
401
|
);
|
|
534
402
|
connectionInfos.init(key, normalized);
|
|
535
403
|
},
|
|
536
|
-
|
|
537
|
-
* Update connection info by completely replacing existing entry
|
|
538
|
-
*
|
|
539
|
-
* @param {string} primaryChainId - Cosmos chainId of primary chain
|
|
540
|
-
* @param {string} counterpartyChainId - Cosmos chainId of counterparty
|
|
541
|
-
* chain
|
|
542
|
-
* @param {IBCConnectionInfo} connectionInfo - New connection info
|
|
543
|
-
* @throws {Error} If connection not registered
|
|
544
|
-
*/
|
|
545
|
-
updateConnection(primaryChainId, counterpartyChainId, connectionInfo) {
|
|
546
|
-
const key = connectionKey(primaryChainId, counterpartyChainId);
|
|
547
|
-
if (!connectionInfos.has(key)) {
|
|
548
|
-
throw makeError(
|
|
549
|
-
`Connection ${q(primaryChainId)}<->${q(counterpartyChainId)} not registered`,
|
|
550
|
-
);
|
|
551
|
-
}
|
|
552
|
-
const [_, normalizedInfo] = normalizeConnectionInfo(
|
|
553
|
-
primaryChainId,
|
|
554
|
-
counterpartyChainId,
|
|
555
|
-
connectionInfo,
|
|
556
|
-
);
|
|
557
|
-
connectionInfos.set(key, normalizedInfo);
|
|
558
|
-
},
|
|
404
|
+
|
|
559
405
|
/**
|
|
560
406
|
* @param {string | { chainId: string }} primary the primary chain
|
|
561
407
|
* @param {string | { chainId: string }} counter the counterparty chain
|
|
@@ -617,42 +463,6 @@ export const makeChainHub = (
|
|
|
617
463
|
brandDenoms.init(detail.brand, denom);
|
|
618
464
|
}
|
|
619
465
|
},
|
|
620
|
-
/**
|
|
621
|
-
* Update asset info by completely replacing existing entry
|
|
622
|
-
*
|
|
623
|
-
* @param {Denom} denom - Denom on the holding chain
|
|
624
|
-
* @param {DenomDetail} detail - New asset details
|
|
625
|
-
* @throws {Error} If asset not registered or referenced chains not
|
|
626
|
-
* registered
|
|
627
|
-
*/
|
|
628
|
-
updateAsset(denom, detail) {
|
|
629
|
-
const { baseName, brand, chainName } = detail;
|
|
630
|
-
const denomKey = makeDenomKey(denom, chainName);
|
|
631
|
-
if (!denomDetails.has(denomKey)) {
|
|
632
|
-
throw makeError(`Asset ${q(denom)} on ${q(chainName)} not registered`);
|
|
633
|
-
}
|
|
634
|
-
if (!chainInfos.has(chainName)) {
|
|
635
|
-
throw makeError(`Chain ${q(chainName)} not registered`);
|
|
636
|
-
}
|
|
637
|
-
if (!chainInfos.has(baseName)) {
|
|
638
|
-
throw makeError(`Chain ${q(baseName)} not registered`);
|
|
639
|
-
}
|
|
640
|
-
if (brand) {
|
|
641
|
-
if (chainName !== 'agoric') {
|
|
642
|
-
throw makeError('Brands only registerable for agoric-held assets');
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
const oldDetail = denomDetails.get(denomKey);
|
|
647
|
-
if (oldDetail.brand) {
|
|
648
|
-
brandDenoms.delete(oldDetail.brand);
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
denomDetails.set(denomKey, detail);
|
|
652
|
-
if (brand) {
|
|
653
|
-
brandDenoms.init(brand, denom);
|
|
654
|
-
}
|
|
655
|
-
},
|
|
656
466
|
/**
|
|
657
467
|
* Retrieve holding, issuing chain names etc. for a denom.
|
|
658
468
|
*
|
|
@@ -679,60 +489,26 @@ export const makeChainHub = (
|
|
|
679
489
|
}
|
|
680
490
|
return undefined;
|
|
681
491
|
},
|
|
682
|
-
|
|
683
492
|
/**
|
|
684
|
-
* @param {
|
|
685
|
-
*
|
|
686
|
-
* @returns {AccountId}
|
|
493
|
+
* @param {string} address bech32 address
|
|
494
|
+
* @returns {ChainAddress}
|
|
687
495
|
* @throws {Error} if chain info not found for bech32Prefix
|
|
688
496
|
*/
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
497
|
+
makeChainAddress(address) {
|
|
498
|
+
const prefix = getBech32Prefix(address);
|
|
499
|
+
if (!bech32PrefixToChainName.has(prefix)) {
|
|
500
|
+
throw makeError(`Chain info not found for bech32Prefix ${q(prefix)}`);
|
|
693
501
|
}
|
|
694
|
-
|
|
695
|
-
const
|
|
696
|
-
/** @type {Bech32Address} */ (partialId),
|
|
697
|
-
);
|
|
698
|
-
return `cosmos:${cosmosChainId}:${partialId}`;
|
|
699
|
-
},
|
|
700
|
-
|
|
701
|
-
/**
|
|
702
|
-
* Like {@see resolveAccountId} but always returns a CosmosChainAddress.
|
|
703
|
-
*
|
|
704
|
-
* @param {AccountIdArg | Bech32Address} partialId CAIP-10 account ID or a
|
|
705
|
-
* Cosmos bech32 address
|
|
706
|
-
* @returns {CosmosChainAddress}
|
|
707
|
-
* @throws {Error} if chain info not found for bech32Prefix
|
|
708
|
-
*/
|
|
709
|
-
coerceCosmosAddress(partialId) {
|
|
710
|
-
if (typeof partialId !== 'string') {
|
|
711
|
-
// already a CosmosChainAddress
|
|
712
|
-
return partialId;
|
|
713
|
-
}
|
|
714
|
-
const parts = partialId.split(':');
|
|
715
|
-
if (parts.length === 3) {
|
|
716
|
-
assert.equal(parts[0], 'cosmos');
|
|
717
|
-
return harden({
|
|
718
|
-
chainId: parts[1],
|
|
719
|
-
encoding: 'bech32',
|
|
720
|
-
value: /** @type {Bech32Address} */ (parts[2]),
|
|
721
|
-
});
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
assert.equal(parts.length, 1); // no colons
|
|
725
|
-
const value = /** @type {Bech32Address} */ (partialId);
|
|
726
|
-
const cosmosChainId = resolveCosmosChainId(value);
|
|
502
|
+
const chainName = bech32PrefixToChainName.get(prefix);
|
|
503
|
+
const { chainId } = chainInfos.get(chainName);
|
|
727
504
|
return harden({
|
|
728
|
-
chainId
|
|
729
|
-
value,
|
|
505
|
+
chainId,
|
|
506
|
+
value: address,
|
|
730
507
|
encoding: /** @type {const} */ ('bech32'),
|
|
731
508
|
});
|
|
732
509
|
},
|
|
733
|
-
|
|
734
510
|
/**
|
|
735
|
-
* Determine the
|
|
511
|
+
* Determine the transfer route for a destination and amount given the
|
|
736
512
|
* current holding chain.
|
|
737
513
|
*
|
|
738
514
|
* Does not account for routes with more than 1 intermediary hop - that is,
|
|
@@ -740,7 +516,7 @@ export const makeChainHub = (
|
|
|
740
516
|
*
|
|
741
517
|
* XXX consider accepting AmountArg #10449
|
|
742
518
|
*
|
|
743
|
-
* @param {
|
|
519
|
+
* @param {ChainAddress} destination
|
|
744
520
|
* @param {DenomAmount} denomAmount
|
|
745
521
|
* @param {string} srcChainName
|
|
746
522
|
* @param {IBCMsgTransferOptions['forwardOpts']} [forwardOpts]
|
|
@@ -765,29 +541,20 @@ export const makeChainHub = (
|
|
|
765
541
|
chainInfos.has(baseName) ||
|
|
766
542
|
Fail`chain info not found for issuing chain: ${q(baseName)}`;
|
|
767
543
|
|
|
768
|
-
const
|
|
769
|
-
if (baseChainInfo.namespace !== 'cosmos')
|
|
770
|
-
throw Fail`Only cosmos supported; got ${q(baseChainInfo.namespace)}`;
|
|
771
|
-
const { chainId: baseChainId, pfmEnabled } = baseChainInfo;
|
|
772
|
-
|
|
773
|
-
const holdingChainInfo = chainInfos.get(srcChainName);
|
|
774
|
-
if (holdingChainInfo.namespace !== 'cosmos') {
|
|
775
|
-
throw Fail`Only cosmos supported; got ${q(holdingChainInfo.namespace)}`;
|
|
776
|
-
}
|
|
777
|
-
const { chainId: holdingChainId } = holdingChainInfo;
|
|
544
|
+
const { chainId: baseChainId, pfmEnabled } = chainInfos.get(baseName);
|
|
778
545
|
|
|
779
|
-
const
|
|
546
|
+
const holdingChainId = chainInfos.get(srcChainName).chainId;
|
|
780
547
|
|
|
781
548
|
// asset is transferring to or from the issuing chain, return direct route
|
|
782
|
-
if (baseChainId ===
|
|
549
|
+
if (baseChainId === destination.chainId || baseName === srcChainName) {
|
|
783
550
|
// TODO use getConnectionInfo once its sync
|
|
784
|
-
const connKey = connectionKey(holdingChainId,
|
|
551
|
+
const connKey = connectionKey(holdingChainId, destination.chainId);
|
|
785
552
|
connectionInfos.has(connKey) ||
|
|
786
|
-
Fail`no connection info found for ${holdingChainId}<->${
|
|
553
|
+
Fail`no connection info found for ${holdingChainId}<->${destination.chainId}`;
|
|
787
554
|
|
|
788
555
|
const { transferChannel } = denormalizeConnectionInfo(
|
|
789
556
|
holdingChainId, // from chain (primary)
|
|
790
|
-
|
|
557
|
+
destination.chainId, // to chain (counterparty)
|
|
791
558
|
connectionInfos.get(connKey),
|
|
792
559
|
);
|
|
793
560
|
return harden({
|
|
@@ -797,7 +564,7 @@ export const makeChainHub = (
|
|
|
797
564
|
amount: String(denomAmount.value),
|
|
798
565
|
denom: denomAmount.denom,
|
|
799
566
|
},
|
|
800
|
-
receiver:
|
|
567
|
+
receiver: destination.value,
|
|
801
568
|
});
|
|
802
569
|
}
|
|
803
570
|
|
|
@@ -809,9 +576,9 @@ export const makeChainHub = (
|
|
|
809
576
|
connectionInfos.has(currToIssuerKey) ||
|
|
810
577
|
Fail`no connection info found for ${holdingChainId}<->${baseChainId}`;
|
|
811
578
|
|
|
812
|
-
const issuerToDestKey = connectionKey(baseChainId,
|
|
579
|
+
const issuerToDestKey = connectionKey(baseChainId, destination.chainId);
|
|
813
580
|
connectionInfos.has(issuerToDestKey) ||
|
|
814
|
-
Fail`no connection info found for ${baseChainId}<->${
|
|
581
|
+
Fail`no connection info found for ${baseChainId}<->${destination.chainId}`;
|
|
815
582
|
|
|
816
583
|
const currToIssuer = denormalizeConnectionInfo(
|
|
817
584
|
holdingChainId,
|
|
@@ -820,19 +587,18 @@ export const makeChainHub = (
|
|
|
820
587
|
);
|
|
821
588
|
const issuerToDest = denormalizeConnectionInfo(
|
|
822
589
|
baseChainId,
|
|
823
|
-
|
|
590
|
+
destination.chainId,
|
|
824
591
|
connectionInfos.get(issuerToDestKey),
|
|
825
592
|
);
|
|
826
593
|
|
|
827
|
-
const { intermediateRecipient, ...rest } = forwardOpts ?? {};
|
|
828
594
|
/** @type {ForwardInfo} */
|
|
829
595
|
const forwardInfo = harden({
|
|
830
596
|
forward: {
|
|
831
|
-
receiver:
|
|
597
|
+
receiver: destination.value,
|
|
832
598
|
port: issuerToDest.transferChannel.portId,
|
|
833
599
|
channel: issuerToDest.transferChannel.channelId,
|
|
834
600
|
...DefaultPfmTimeoutOpts,
|
|
835
|
-
|
|
601
|
+
...forwardOpts,
|
|
836
602
|
},
|
|
837
603
|
});
|
|
838
604
|
return harden({
|
|
@@ -846,7 +612,7 @@ export const makeChainHub = (
|
|
|
846
612
|
* purposely using invalid bech32
|
|
847
613
|
* {@link https://github.com/cosmos/ibc-apps/blob/26f3ad8f58e4ffc7769c6766cb42b954181dc100/middleware/packet-forward-middleware/README.md#minimal-example---chain-forward-a-b-c}
|
|
848
614
|
*/
|
|
849
|
-
receiver: intermediateRecipient?.value || PFM_RECEIVER,
|
|
615
|
+
receiver: forwardOpts?.intermediateRecipient?.value || PFM_RECEIVER,
|
|
850
616
|
forwardInfo,
|
|
851
617
|
});
|
|
852
618
|
},
|