@agoric/orchestration 0.1.1-calypso-dev-84eb287.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.
Files changed (120) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +5 -0
  3. package/index.d.ts +4 -0
  4. package/index.js +7 -0
  5. package/package.json +95 -0
  6. package/src/chain-info.d.ts +2318 -0
  7. package/src/chain-info.d.ts.map +1 -0
  8. package/src/chain-info.js +114 -0
  9. package/src/cosmos-api.d.ts +174 -0
  10. package/src/cosmos-api.d.ts.map +1 -0
  11. package/src/cosmos-api.ts +231 -0
  12. package/src/ethereum-api.d.ts +8 -0
  13. package/src/ethereum-api.d.ts.map +1 -0
  14. package/src/ethereum-api.ts +7 -0
  15. package/src/examples/sendAnywhere.contract.d.ts +31 -0
  16. package/src/examples/sendAnywhere.contract.d.ts.map +1 -0
  17. package/src/examples/sendAnywhere.contract.js +171 -0
  18. package/src/examples/stakeBld.contract.d.ts +121 -0
  19. package/src/examples/stakeBld.contract.d.ts.map +1 -0
  20. package/src/examples/stakeBld.contract.js +133 -0
  21. package/src/examples/stakeIca.contract.d.ts +93 -0
  22. package/src/examples/stakeIca.contract.d.ts.map +1 -0
  23. package/src/examples/stakeIca.contract.js +143 -0
  24. package/src/examples/swapExample.contract.d.ts +34 -0
  25. package/src/examples/swapExample.contract.d.ts.map +1 -0
  26. package/src/examples/swapExample.contract.js +155 -0
  27. package/src/examples/unbondExample.contract.d.ts +21 -0
  28. package/src/examples/unbondExample.contract.d.ts.map +1 -0
  29. package/src/examples/unbondExample.contract.js +105 -0
  30. package/src/exos/README.md +56 -0
  31. package/src/exos/agoric-names-tools.d.ts +27 -0
  32. package/src/exos/agoric-names-tools.d.ts.map +1 -0
  33. package/src/exos/agoric-names-tools.js +109 -0
  34. package/src/exos/chain-account-kit.d.ts +88 -0
  35. package/src/exos/chain-account-kit.d.ts.map +1 -0
  36. package/src/exos/chain-account-kit.js +210 -0
  37. package/src/exos/chain-hub.d.ts +77 -0
  38. package/src/exos/chain-hub.d.ts.map +1 -0
  39. package/src/exos/chain-hub.js +214 -0
  40. package/src/exos/cosmos-orchestration-account.d.ts +207 -0
  41. package/src/exos/cosmos-orchestration-account.d.ts.map +1 -0
  42. package/src/exos/cosmos-orchestration-account.js +536 -0
  43. package/src/exos/icq-connection-kit.d.ts +50 -0
  44. package/src/exos/icq-connection-kit.d.ts.map +1 -0
  45. package/src/exos/icq-connection-kit.js +135 -0
  46. package/src/exos/local-chain-facade.d.ts +81 -0
  47. package/src/exos/local-chain-facade.d.ts.map +1 -0
  48. package/src/exos/local-chain-facade.js +113 -0
  49. package/src/exos/local-orchestration-account.d.ts +176 -0
  50. package/src/exos/local-orchestration-account.d.ts.map +1 -0
  51. package/src/exos/local-orchestration-account.js +446 -0
  52. package/src/exos/orchestrator.d.ts +91 -0
  53. package/src/exos/orchestrator.d.ts.map +1 -0
  54. package/src/exos/orchestrator.js +141 -0
  55. package/src/exos/remote-chain-facade.d.ts +144 -0
  56. package/src/exos/remote-chain-facade.d.ts.map +1 -0
  57. package/src/exos/remote-chain-facade.js +145 -0
  58. package/src/facade.d.ts +57 -0
  59. package/src/facade.d.ts.map +1 -0
  60. package/src/facade.js +132 -0
  61. package/src/fetched-chain-info.d.ts +2311 -0
  62. package/src/fetched-chain-info.d.ts.map +1 -0
  63. package/src/fetched-chain-info.js +2288 -0
  64. package/src/internal.d.ts +13 -0
  65. package/src/internal.d.ts.map +1 -0
  66. package/src/internal.ts +20 -0
  67. package/src/orchestration-api.d.ts +158 -0
  68. package/src/orchestration-api.d.ts.map +1 -0
  69. package/src/orchestration-api.ts +201 -0
  70. package/src/proposals/orchestration-proposal.d.ts +53 -0
  71. package/src/proposals/orchestration-proposal.d.ts.map +1 -0
  72. package/src/proposals/orchestration-proposal.js +179 -0
  73. package/src/proposals/revise-chain-info.d.ts +21 -0
  74. package/src/proposals/revise-chain-info.d.ts.map +1 -0
  75. package/src/proposals/revise-chain-info.js +44 -0
  76. package/src/proposals/start-stakeAtom.d.ts +109 -0
  77. package/src/proposals/start-stakeAtom.d.ts.map +1 -0
  78. package/src/proposals/start-stakeAtom.js +105 -0
  79. package/src/proposals/start-stakeBld.d.ts +154 -0
  80. package/src/proposals/start-stakeBld.d.ts.map +1 -0
  81. package/src/proposals/start-stakeBld.js +103 -0
  82. package/src/proposals/start-stakeOsmo.d.ts +108 -0
  83. package/src/proposals/start-stakeOsmo.d.ts.map +1 -0
  84. package/src/proposals/start-stakeOsmo.js +106 -0
  85. package/src/service.d.ts +97 -0
  86. package/src/service.d.ts.map +1 -0
  87. package/src/service.js +259 -0
  88. package/src/typeGuards.d.ts +55 -0
  89. package/src/typeGuards.d.ts.map +1 -0
  90. package/src/typeGuards.js +104 -0
  91. package/src/types.d.ts +11 -0
  92. package/src/types.d.ts.map +1 -0
  93. package/src/types.ts +11 -0
  94. package/src/utils/address.d.ts +14 -0
  95. package/src/utils/address.d.ts.map +1 -0
  96. package/src/utils/address.js +79 -0
  97. package/src/utils/cosmos.d.ts +9 -0
  98. package/src/utils/cosmos.d.ts.map +1 -0
  99. package/src/utils/cosmos.js +36 -0
  100. package/src/utils/orc.d.ts +17 -0
  101. package/src/utils/orc.d.ts.map +1 -0
  102. package/src/utils/orc.js +38 -0
  103. package/src/utils/orchestrationAccount.d.ts +10 -0
  104. package/src/utils/orchestrationAccount.d.ts.map +1 -0
  105. package/src/utils/orchestrationAccount.js +22 -0
  106. package/src/utils/packet.d.ts +57 -0
  107. package/src/utils/packet.d.ts.map +1 -0
  108. package/src/utils/packet.js +112 -0
  109. package/src/utils/registry.d.ts +13 -0
  110. package/src/utils/registry.d.ts.map +1 -0
  111. package/src/utils/registry.js +131 -0
  112. package/src/utils/start-helper.d.ts +51 -0
  113. package/src/utils/start-helper.d.ts.map +1 -0
  114. package/src/utils/start-helper.js +109 -0
  115. package/src/utils/time.d.ts +31 -0
  116. package/src/utils/time.d.ts.map +1 -0
  117. package/src/utils/time.js +63 -0
  118. package/src/vat-orchestration.d.ts +58 -0
  119. package/src/vat-orchestration.d.ts.map +1 -0
  120. package/src/vat-orchestration.js +24 -0
@@ -0,0 +1,34 @@
1
+ /** @type {ContractMeta<typeof start>} */
2
+ export const meta: ContractMeta<typeof start>;
3
+ export function makeNatAmountShape(brand: Brand, min?: bigint | undefined): {
4
+ brand: globalThis.Brand;
5
+ value: import("@endo/patterns").Matcher;
6
+ };
7
+ export function start(zcf: ZCF, privateArgs: {
8
+ agoricNames: Remote<NameHub>;
9
+ localchain: Remote<LocalChain>;
10
+ orchestrationService: Remote<OrchestrationService>;
11
+ storageNode: Remote<StorageNode>;
12
+ timerService: Remote<TimerService>;
13
+ marshaller: Marshaller;
14
+ }, baggage: Baggage): Promise<{
15
+ publicFacet: {
16
+ makeSwapAndStakeInvitation: () => Promise<Invitation<unknown, {
17
+ staked: Amount<"nat">;
18
+ validator: CosmosValidatorAddress;
19
+ }>>;
20
+ } & import("@endo/marshal").RemotableObject<`Alleged: ${string}`> & import("@endo/eventual-send").RemotableBrand<{}, {
21
+ makeSwapAndStakeInvitation: () => Promise<Invitation<unknown, {
22
+ staked: Amount<"nat">;
23
+ validator: CosmosValidatorAddress;
24
+ }>>;
25
+ }>;
26
+ }>;
27
+ import type { NameHub } from '@agoric/vats';
28
+ import type { Remote } from '@agoric/internal';
29
+ import type { LocalChain } from '@agoric/vats/src/localchain.js';
30
+ import type { OrchestrationService } from '../service.js';
31
+ import type { TimerService } from '@agoric/time';
32
+ import type { Baggage } from '@agoric/vat-data';
33
+ import type { CosmosValidatorAddress } from '../types.js';
34
+ //# sourceMappingURL=swapExample.contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swapExample.contract.d.ts","sourceRoot":"","sources":["swapExample.contract.js"],"names":[],"mappings":"AAoEA,yCAAyC;AACzC,mBADW,YAAY,CAAC,OAAO,KAAK,CAAC,CAWnC;AASK,0CAHI,KAAK;;;EAIsC;AAc/C,2BAXI,GAAG,eACH;IACV,WAAe,EAAE,OAAO,OAAO,CAAC,CAAC;IACjC,UAAc,EAAE,OAAO,UAAU,CAAC,CAAC;IACnC,oBAAwB,EAAE,OAAO,oBAAoB,CAAC,CAAC;IACvD,WAAe,EAAE,OAAO,WAAW,CAAC,CAAC;IACrC,YAAgB,EAAE,OAAO,YAAY,CAAC,CAAC;IACvC,UAAc,EAAE,UAAU,CAAC;CACxB,WACO,OAAO;;;oBA+BD,MAAM,CAAC,KAAK,CAAC;uBAAa,sBAAsB;;;;oBAAhD,MAAM,CAAC,KAAK,CAAC;uBAAa,sBAAsB;;;GAsBhE;6BA1IyB,cAAc;4BAHf,kBAAkB;gCADd,gCAAgC;0CAEtB,eAAe;kCAHvB,cAAc;6BAInB,kBAAkB;4CALuB,aAAa"}
@@ -0,0 +1,155 @@
1
+ import { StorageNodeShape } from '@agoric/internal';
2
+ import { TimerServiceShape } from '@agoric/time';
3
+ import { withdrawFromSeat } from '@agoric/zoe/src/contractSupport/zoeHelpers.js';
4
+ import { Far } from '@endo/far';
5
+ import { deeplyFulfilled } from '@endo/marshal';
6
+ import { M, objectMap } from '@endo/patterns';
7
+ import { orcUtils } from '../utils/orc.js';
8
+ import { provideOrchestration } from '../utils/start-helper.js';
9
+
10
+ /**
11
+ * @import {Orchestrator, IcaAccount, CosmosValidatorAddress} from '../types.js'
12
+ * @import {TimerService} from '@agoric/time';
13
+ * @import {LocalChain} from '@agoric/vats/src/localchain.js';
14
+ * @import {Remote} from '@agoric/internal';
15
+ * @import {OrchestrationService} from '../service.js';
16
+ * @import {Baggage} from '@agoric/vat-data'
17
+ * @import {NameHub} from '@agoric/vats';
18
+ */
19
+
20
+ /**
21
+ * @param {Orchestrator} orch
22
+ * @param {object} ctx
23
+ * @param {ZCF} ctx.zcf
24
+ * @param {ZCFSeat} seat
25
+ * @param {object} offerArgs
26
+ * @param {Amount<'nat'>} offerArgs.staked
27
+ * @param {CosmosValidatorAddress} offerArgs.validator
28
+ */
29
+ const stackAndSwapFn = async (orch, { zcf }, seat, offerArgs) => {
30
+ const { give } = seat.getProposal();
31
+
32
+ const omni = await orch.getChain('omniflixhub');
33
+ const agoric = await orch.getChain('agoric');
34
+
35
+ const [omniAccount, localAccount] = await Promise.all([
36
+ omni.makeAccount(),
37
+ agoric.makeAccount(),
38
+ ]);
39
+
40
+ const omniAddress = omniAccount.getAddress();
41
+
42
+ // deposit funds from user seat to LocalChainAccount
43
+ const payments = await withdrawFromSeat(zcf, seat, give);
44
+ await deeplyFulfilled(
45
+ objectMap(payments, payment =>
46
+ // @ts-expect-error payment is ERef<Payment> which happens to work but isn't officially supported
47
+ localAccount.deposit(payment),
48
+ ),
49
+ );
50
+ seat.exit();
51
+
52
+ // build swap instructions with orcUtils library
53
+ const transferMsg = orcUtils.makeOsmosisSwap({
54
+ destChain: 'omniflixhub',
55
+ destAddress: omniAddress,
56
+ amountIn: give.Stable,
57
+ brandOut: /** @type {any} */ ('FIXME'),
58
+ slippage: 0.03,
59
+ });
60
+
61
+ await localAccount
62
+ .transferSteps(give.Stable, transferMsg)
63
+ .then(_txResult =>
64
+ omniAccount.delegate(offerArgs.validator, offerArgs.staked),
65
+ )
66
+ .catch(e => console.error(e));
67
+ };
68
+
69
+ /** @type {ContractMeta<typeof start>} */
70
+ export const meta = {
71
+ privateArgsShape: {
72
+ agoricNames: M.remotable('agoricNames'),
73
+ localchain: M.remotable('localchain'),
74
+ orchestrationService: M.or(M.remotable('orchestration'), null),
75
+ storageNode: StorageNodeShape,
76
+ marshaller: M.remotable('marshaller'),
77
+ timerService: M.or(TimerServiceShape, null),
78
+ },
79
+ upgradability: 'canUpgrade',
80
+ };
81
+ harden(meta);
82
+
83
+ // XXX copied from inter-protocol
84
+ // TODO move to new `@agoric/contracts` package when we have it
85
+ /**
86
+ * @param {Brand} brand must be a 'nat' brand, not checked
87
+ * @param {NatValue} [min]
88
+ */
89
+ export const makeNatAmountShape = (brand, min) =>
90
+ harden({ brand, value: min ? M.gte(min) : M.nat() });
91
+
92
+ /**
93
+ * @param {ZCF} zcf
94
+ * @param {{
95
+ * agoricNames: Remote<NameHub>;
96
+ * localchain: Remote<LocalChain>;
97
+ * orchestrationService: Remote<OrchestrationService>;
98
+ * storageNode: Remote<StorageNode>;
99
+ * timerService: Remote<TimerService>;
100
+ * marshaller: Marshaller;
101
+ * }} privateArgs
102
+ * @param {Baggage} baggage
103
+ */
104
+ export const start = async (zcf, privateArgs, baggage) => {
105
+ const {
106
+ agoricNames,
107
+ localchain,
108
+ orchestrationService,
109
+ storageNode,
110
+ timerService,
111
+ marshaller,
112
+ } = privateArgs;
113
+
114
+ const { orchestrate } = provideOrchestration(
115
+ zcf,
116
+ baggage,
117
+ {
118
+ agoricNames,
119
+ localchain,
120
+ orchestrationService,
121
+ storageNode,
122
+ timerService,
123
+ },
124
+ marshaller,
125
+ );
126
+
127
+ const { brands } = zcf.getTerms();
128
+
129
+ /** deprecated historical example */
130
+ /**
131
+ * @type {OfferHandler<
132
+ * unknown,
133
+ * { staked: Amount<'nat'>; validator: CosmosValidatorAddress }
134
+ * >}
135
+ */
136
+ const swapAndStakeHandler = orchestrate('LSTTia', { zcf }, stackAndSwapFn);
137
+
138
+ const makeSwapAndStakeInvitation = () =>
139
+ zcf.makeInvitation(
140
+ swapAndStakeHandler,
141
+ 'Swap for TIA and stake',
142
+ undefined,
143
+ harden({
144
+ give: { Stable: makeNatAmountShape(brands.Stable, 1n) },
145
+ want: {}, // XXX ChainAccount Ownable?
146
+ exit: M.any(),
147
+ }),
148
+ );
149
+
150
+ const publicFacet = Far('SwapAndStake Public Facet', {
151
+ makeSwapAndStakeInvitation,
152
+ });
153
+
154
+ return harden({ publicFacet });
155
+ };
@@ -0,0 +1,21 @@
1
+ export function start(zcf: ZCF, privateArgs: {
2
+ agoricNames: Remote<NameHub>;
3
+ localchain: Remote<LocalChain>;
4
+ orchestrationService: Remote<OrchestrationService>;
5
+ storageNode: Remote<StorageNode>;
6
+ marshaller: Marshaller;
7
+ timerService: Remote<TimerService>;
8
+ }, baggage: Baggage): Promise<{
9
+ publicFacet: {
10
+ makeUnbondAndLiquidStakeInvitation: () => Promise<Invitation<unknown, never>>;
11
+ } & import("@endo/pass-style").RemotableObject<`Alleged: ${string}`> & import("@endo/eventual-send").RemotableBrand<{}, {
12
+ makeUnbondAndLiquidStakeInvitation: () => Promise<Invitation<unknown, never>>;
13
+ }>;
14
+ }>;
15
+ import type { NameHub } from '@agoric/vats';
16
+ import type { Remote } from '@agoric/internal';
17
+ import type { LocalChain } from '@agoric/vats/src/localchain.js';
18
+ import type { OrchestrationService } from '../service.js';
19
+ import type { TimerService } from '@agoric/time';
20
+ import type { Baggage } from '@agoric/vat-data';
21
+ //# sourceMappingURL=unbondExample.contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unbondExample.contract.d.ts","sourceRoot":"","sources":["unbondExample.contract.js"],"names":[],"mappings":"AAwDO,2BAXI,GAAG,eACH;IACV,WAAe,EAAE,OAAO,OAAO,CAAC,CAAC;IACjC,UAAc,EAAE,OAAO,UAAU,CAAC,CAAC;IACnC,oBAAwB,EAAE,OAAO,oBAAoB,CAAC,CAAC;IACvD,WAAe,EAAE,OAAO,WAAW,CAAC,CAAC;IACrC,UAAc,EAAE,UAAU,CAAC;IAC3B,YAAgB,EAAE,OAAO,YAAY,CAAC,CAAC;CACpC,WACO,OAAO;;;;;;GAkDjB;6BA/FyB,cAAc;4BACf,kBAAkB;gCAFd,gCAAgC;0CAGtB,eAAe;kCALvB,cAAc;6BACnB,kBAAkB"}
@@ -0,0 +1,105 @@
1
+ import { Far } from '@endo/far';
2
+ import { M } from '@endo/patterns';
3
+ import { provideOrchestration } from '../utils/start-helper.js';
4
+
5
+ /**
6
+ * @import {Orchestrator, IcaAccount, CosmosValidatorAddress} from '../types.js'
7
+ * @import {TimerService} from '@agoric/time';
8
+ * @import {Baggage} from '@agoric/vat-data';
9
+ * @import {LocalChain} from '@agoric/vats/src/localchain.js';
10
+ * @import {NameHub} from '@agoric/vats';
11
+ * @import {Remote} from '@agoric/internal';
12
+ * @import {OrchestrationService} from '../service.js';
13
+ */
14
+
15
+ /**
16
+ * @param {Orchestrator} orch
17
+ * @param {object} ctx
18
+ * @param {ZCF} ctx.zcf
19
+ * @param {ZCFSeat} _seat
20
+ * @param {undefined} _offerArgs
21
+ */
22
+ const unbondAndLiquidStakeFn = async (orch, { zcf }, _seat, _offerArgs) => {
23
+ console.log('zcf within the membrane', zcf);
24
+ // We would actually alreaady have the account from the orchestrator
25
+ // ??? could these be passed in? It would reduce the size of this handler,
26
+ // keeping it focused on long-running operations.
27
+ const omni = await orch.getChain('omniflixhub');
28
+ const omniAccount = await omni.makeAccount();
29
+
30
+ // TODO implement these
31
+ // const delegations = await celestiaAccount.getDelegations();
32
+ // // wait for the undelegations to be complete (may take weeks)
33
+ // await celestiaAccount.undelegate(delegations);
34
+ // ??? should this be synchronous? depends on how names are resolved.
35
+ const stride = await orch.getChain('stride');
36
+ const strideAccount = await stride.makeAccount();
37
+
38
+ // TODO the `TIA` string actually needs to be the Brand from AgoricNames
39
+ // const tiaAmt = await celestiaAccount.getBalance('TIA');
40
+ // await celestiaAccount.transfer(tiaAmt, strideAccount.getAddress());
41
+ // await strideAccount.liquidStake(tiaAmt);
42
+ console.log(omniAccount, strideAccount);
43
+ };
44
+
45
+ /**
46
+ * @param {ZCF} zcf
47
+ * @param {{
48
+ * agoricNames: Remote<NameHub>;
49
+ * localchain: Remote<LocalChain>;
50
+ * orchestrationService: Remote<OrchestrationService>;
51
+ * storageNode: Remote<StorageNode>;
52
+ * marshaller: Marshaller;
53
+ * timerService: Remote<TimerService>;
54
+ * }} privateArgs
55
+ * @param {Baggage} baggage
56
+ */
57
+ export const start = async (zcf, privateArgs, baggage) => {
58
+ const {
59
+ agoricNames,
60
+ localchain,
61
+ orchestrationService,
62
+ storageNode,
63
+ marshaller,
64
+ timerService,
65
+ } = privateArgs;
66
+
67
+ const { orchestrate } = provideOrchestration(
68
+ zcf,
69
+ baggage,
70
+ {
71
+ agoricNames,
72
+ localchain,
73
+ orchestrationService,
74
+ storageNode,
75
+ timerService,
76
+ },
77
+ marshaller,
78
+ );
79
+
80
+ /** @type {OfferHandler} */
81
+ const unbondAndLiquidStake = orchestrate(
82
+ 'LSTTia',
83
+ { zcf },
84
+ unbondAndLiquidStakeFn,
85
+ );
86
+
87
+ const makeUnbondAndLiquidStakeInvitation = () =>
88
+ zcf.makeInvitation(
89
+ unbondAndLiquidStake,
90
+ 'Unbond and liquid stake',
91
+ undefined,
92
+ harden({
93
+ // Nothing to give; the funds come from undelegating
94
+ give: {},
95
+ want: {}, // XXX ChainAccount Ownable?
96
+ exit: M.any(),
97
+ }),
98
+ );
99
+
100
+ const publicFacet = Far('SwapAndStake Public Facet', {
101
+ makeUnbondAndLiquidStakeInvitation,
102
+ });
103
+
104
+ return harden({ publicFacet });
105
+ };
@@ -0,0 +1,56 @@
1
+ # Exo structure
2
+
3
+ As of 2024-05-29…
4
+
5
+ ```mermaid
6
+ classDiagram
7
+
8
+ %% Orchestration vat business logic (Zoe)
9
+ LCAKit --* LocalchainAccount
10
+ ICQConnectionKit --* Port
11
+ ICQConnectionKit --* Connection
12
+ ChainAccountKit --* Port
13
+ ChainAccountKit --* Connection
14
+ StakingAccountKit --* IcaAccount
15
+
16
+ class ChainAccountKit {
17
+ port: Port
18
+ connection: Connection
19
+ localAddress: LocalIbcAddress
20
+ requestedRemoteAddress: string
21
+ remoteAddress: RemoteIbcAddress
22
+ chainAddress: ChainAddress
23
+ }
24
+ class ICQConnectionKit {
25
+ port: Port
26
+ connection: Connection
27
+ localAddress: LocalIbcAddress
28
+ remoteAddress: RemoteIbcAddress
29
+ }
30
+ class StakingAccountKit {
31
+ chainAddress: ChainAddress
32
+ bondDenom: string
33
+ account: ICAAccount
34
+ timer: Timer
35
+ topicKit: TopicKit
36
+ makeTransferInvitation()
37
+ }
38
+
39
+ %% In other vats
40
+ class LCAKit {
41
+ account: LocalChainAccount
42
+ address: ChainAddress
43
+ topicKit: RecorderKit<LocalChainAccountNotification>
44
+ }
45
+ class LocalchainAccount {
46
+ executeTx()
47
+ deposit()
48
+ withdraw()
49
+ }
50
+ class IcaAccount {
51
+ executeTx()
52
+ deposit()
53
+ getPurse()
54
+ close()
55
+ }
56
+ ```
@@ -0,0 +1,27 @@
1
+ export function makeResumableAgoricNamesHack(zone: Zone, { agoricNames, vowTools: { watch, asVow } }: {
2
+ agoricNames: Remote<NameHub>;
3
+ vowTools: VowTools;
4
+ }): import("@endo/exo").Guarded<{
5
+ /** @param {...string} args */
6
+ lookup(...args: string[]): Vow<any>;
7
+ /**
8
+ * Look up asset info, like denom, in agoricNames.vbankAsset using a
9
+ * Brand.
10
+ *
11
+ * Caches the query to agoricNames in the first call. Subsequent lookups
12
+ * are via cache unless a refetch is specified or a brand is not found.
13
+ *
14
+ * @param {Brand<'nat'>} brand
15
+ * @param {boolean} [refetch] if true, will invalidate the cache
16
+ * @returns {Vow<AssetInfo>}
17
+ */
18
+ findBrandInVBank(brand: Brand<"nat">, refetch?: boolean | undefined): Vow<AssetInfo>;
19
+ }>;
20
+ export type AgNamesTools = ReturnType<typeof makeResumableAgoricNamesHack>;
21
+ import type { Zone } from '@agoric/zone';
22
+ import type { NameHub } from '@agoric/vats';
23
+ import type { Remote } from '@agoric/internal';
24
+ import type { VowTools } from '@agoric/vow';
25
+ import type { Vow } from '@agoric/vow';
26
+ import type { AssetInfo } from '@agoric/vats/src/vat-bank.js';
27
+ //# sourceMappingURL=agoric-names-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agoric-names-tools.d.ts","sourceRoot":"","sources":["agoric-names-tools.js"],"names":[],"mappings":"AA4BO,mDAHI,IAAI,+CACJ;IAAE,WAAW,EAAE,OAAO,OAAO,CAAC,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE;IA8CvD,8BAA8B;oBAAf,MAAM,EAAA;IAIrB;;;;;;;;;;OAUG;4BAHQ,KAAK,CAAC,KAAK,CAAC,kCAEV,IAAI,SAAS,CAAC;GAsBlC;2BACa,UAAU,CAAC,OAAO,4BAA4B,CAAC;0BAhGtC,cAAc;6BAJX,cAAc;4BAEf,kBAAkB;8BACX,aAAa;yBAAb,aAAa;+BAFjB,8BAA8B"}
@@ -0,0 +1,109 @@
1
+ import { VowShape } from '@agoric/vow';
2
+ import { E } from '@endo/far';
3
+ import { M, makeCopyMap } from '@endo/patterns';
4
+ import { BrandShape } from '@agoric/ertp';
5
+
6
+ const { Fail } = assert;
7
+
8
+ /**
9
+ * @import {NameHub} from '@agoric/vats';
10
+ * @import {AssetInfo} from '@agoric/vats/src/vat-bank.js';
11
+ * @import {Remote} from '@agoric/internal';
12
+ * @import {Vow, VowTools} from '@agoric/vow';
13
+ * @import {Zone} from '@agoric/zone';
14
+ */
15
+
16
+ /**
17
+ * Perform remote calls to agoricNames in membrane-friendly way. This is an
18
+ * interim approach until https://github.com/Agoric/agoric-sdk/issues/9541,
19
+ * https://github.com/Agoric/agoric-sdk/pull/9322, or
20
+ * https://github.com/Agoric/agoric-sdk/pull/9519.
21
+ *
22
+ * XXX only works once per zone.
23
+ *
24
+ * XXX consider exposing `has`, `entries`, `keys`, `values` from `NameHub`
25
+ *
26
+ * @param {Zone} zone
27
+ * @param {{ agoricNames: Remote<NameHub>; vowTools: VowTools }} powers
28
+ */
29
+ export const makeResumableAgoricNamesHack = (
30
+ zone,
31
+ { agoricNames, vowTools: { watch, asVow } },
32
+ ) => {
33
+ const makeResumableAgoricNamesHackKit = zone.exoClassKit(
34
+ 'ResumableAgoricNamesHack',
35
+ {
36
+ public: M.interface('ResumableAgoricNamesHackI', {
37
+ lookup: M.call().rest(M.arrayOf(M.string())).returns(VowShape),
38
+ findBrandInVBank: M.call(BrandShape)
39
+ .optional(M.boolean())
40
+ .returns(VowShape),
41
+ }),
42
+ vbankAssetEntriesWatcher: M.interface('vbankAssetEntriesWatcher', {
43
+ onFulfilled: M.call(M.arrayOf(M.record()))
44
+ .optional(BrandShape)
45
+ .returns(VowShape),
46
+ }),
47
+ },
48
+ () => ({
49
+ vbankAssetsByBrand: zone.mapStore('vbankAssetsByBrand', {
50
+ keyShape: BrandShape,
51
+ valueShape: M.any(),
52
+ }),
53
+ }),
54
+ {
55
+ vbankAssetEntriesWatcher: {
56
+ /**
57
+ * @param {AssetInfo[]} assets
58
+ * @param {Brand<'nat'>} brand
59
+ */
60
+ onFulfilled(assets, brand) {
61
+ return asVow(() => {
62
+ const { vbankAssetsByBrand } = this.state;
63
+ vbankAssetsByBrand.addAll(
64
+ makeCopyMap(assets.map(a => [a.brand, a])),
65
+ );
66
+ vbankAssetsByBrand.has(brand) ||
67
+ Fail`brand ${brand} not in agoricNames.vbankAsset`;
68
+ return vbankAssetsByBrand.get(brand);
69
+ });
70
+ },
71
+ },
72
+ public: {
73
+ /** @param {...string} args */
74
+ lookup(...args) {
75
+ return watch(E(agoricNames).lookup(...args));
76
+ },
77
+ /**
78
+ * Look up asset info, like denom, in agoricNames.vbankAsset using a
79
+ * Brand.
80
+ *
81
+ * Caches the query to agoricNames in the first call. Subsequent lookups
82
+ * are via cache unless a refetch is specified or a brand is not found.
83
+ *
84
+ * @param {Brand<'nat'>} brand
85
+ * @param {boolean} [refetch] if true, will invalidate the cache
86
+ * @returns {Vow<AssetInfo>}
87
+ */
88
+ findBrandInVBank(brand, refetch) {
89
+ return asVow(() => {
90
+ const { vbankAssetsByBrand } = this.state;
91
+ if (vbankAssetsByBrand.has(brand) && !refetch) {
92
+ return vbankAssetsByBrand.get(brand);
93
+ }
94
+ const vbankAssetNameHubP = E(agoricNames).lookup('vbankAsset');
95
+ const vbankAssetEntriesP = E(vbankAssetNameHubP).values();
96
+ return watch(
97
+ vbankAssetEntriesP,
98
+ this.facets.vbankAssetEntriesWatcher,
99
+ brand,
100
+ );
101
+ });
102
+ },
103
+ },
104
+ },
105
+ );
106
+ // XXX only works once per zone.
107
+ return makeResumableAgoricNamesHackKit().public;
108
+ };
109
+ /** @typedef {ReturnType<typeof makeResumableAgoricNamesHack>} AgNamesTools */
@@ -0,0 +1,88 @@
1
+ export const ChainAccountI: import("@endo/patterns").InterfaceGuard<{
2
+ getAddress: import("@endo/patterns").MethodGuard;
3
+ getBalance: import("@endo/patterns").MethodGuard;
4
+ getBalances: import("@endo/patterns").MethodGuard;
5
+ getLocalAddress: import("@endo/patterns").MethodGuard;
6
+ getRemoteAddress: import("@endo/patterns").MethodGuard;
7
+ getPort: import("@endo/patterns").MethodGuard;
8
+ executeTx: import("@endo/patterns").MethodGuard;
9
+ executeEncodedTx: import("@endo/patterns").MethodGuard;
10
+ close: import("@endo/patterns").MethodGuard;
11
+ getPurse: import("@endo/patterns").MethodGuard;
12
+ }>;
13
+ export function prepareChainAccountKit(zone: Zone, { watch, asVow }: VowTools): (chainId: string, port: Port, requestedRemoteAddress: string) => import("@endo/exo").GuardedKit<{
14
+ parseTxPacketWatcher: {
15
+ /** @param {string} ack */
16
+ onFulfilled(ack: string): string;
17
+ };
18
+ account: {
19
+ /** @returns {ChainAddress} */
20
+ getAddress(): ChainAddress;
21
+ getBalance(_denom: any): Vow<never>;
22
+ getBalances(): Vow<never>;
23
+ getLocalAddress(): `/ibc-port/${string}`;
24
+ getRemoteAddress(): `/${string}ibc-port/${string}/ordered/${string}` | `/${string}ibc-port/${string}/unordered/${string}`;
25
+ getPort(): Port;
26
+ executeTx(): Vow<never>;
27
+ /**
28
+ * Submit a transaction on behalf of the remote account for execution on
29
+ * the remote chain.
30
+ *
31
+ * @param {AnyJson[]} msgs
32
+ * @param {Omit<TxBody, 'messages'>} [opts]
33
+ * @returns {Vow<string>} - base64 encoded bytes string. Can be decoded
34
+ * using the corresponding `Msg*Response` object.
35
+ * @throws {Error} if packet fails to send or an error is returned
36
+ */
37
+ executeEncodedTx(msgs: AnyJson[], opts?: Omit<TxBody, "messages"> | undefined): Vow<string>;
38
+ /**
39
+ * Close the remote account
40
+ *
41
+ * @returns {Vow<void>}
42
+ * @throws {Error} if connection is not available or already closed
43
+ */
44
+ close(): Vow<void>;
45
+ /**
46
+ * get Purse for a brand to .withdraw() a Payment from the account
47
+ *
48
+ * @param {Brand} brand
49
+ */
50
+ getPurse(brand: Brand): Vow<never>;
51
+ };
52
+ connectionHandler: {
53
+ /**
54
+ * @param {Remote<Connection>} connection
55
+ * @param {LocalIbcAddress} localAddr
56
+ * @param {RemoteIbcAddress} remoteAddr
57
+ */
58
+ onOpen(connection: Remote<Connection>, localAddr: LocalIbcAddress, remoteAddr: RemoteIbcAddress): Promise<void>;
59
+ /**
60
+ * @param {Remote<Connection>} _connection
61
+ * @param {unknown} reason
62
+ */
63
+ onClose(_connection: Remote<Connection>, reason: unknown): Promise<void>;
64
+ };
65
+ }>;
66
+ export type UnparsableChainAddress = "UNPARSABLE_CHAIN_ADDRESS";
67
+ export type State = {
68
+ chainId: string;
69
+ port: Port;
70
+ connection: Remote<Connection> | undefined;
71
+ localAddress: LocalIbcAddress | undefined;
72
+ requestedRemoteAddress: string;
73
+ remoteAddress: RemoteIbcAddress | undefined;
74
+ chainAddress: ChainAddress | undefined;
75
+ };
76
+ export type ChainAccountKit = ReturnType<ReturnType<typeof prepareChainAccountKit>>;
77
+ import type { Zone } from '@agoric/base-zone';
78
+ import type { VowTools } from '@agoric/vow';
79
+ import type { Port } from '@agoric/network';
80
+ import type { ChainAddress } from '../types.js';
81
+ import type { Vow } from '@agoric/vow';
82
+ import type { AnyJson } from '@agoric/cosmic-proto';
83
+ import type { TxBody } from '@agoric/cosmic-proto/cosmos/tx/v1beta1/tx.js';
84
+ import type { Connection } from '@agoric/network';
85
+ import type { Remote } from '@agoric/vow';
86
+ import type { LocalIbcAddress } from '@agoric/vats/tools/ibc-utils.js';
87
+ import type { RemoteIbcAddress } from '@agoric/vats/tools/ibc-utils.js';
88
+ //# sourceMappingURL=chain-account-kit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chain-account-kit.d.ts","sourceRoot":"","sources":["chain-account-kit.js"],"names":[],"mappings":"AA8BA;;;;;;;;;;;GAaG;AAkBI,6CAHI,IAAI,oBACJ,QAAQ;;QA+BX,0BAA0B;yBAAd,MAAM;;;QAMlB,8BAA8B;sBAAhB,YAAY;;;;;;;QAmC1B;;;;;;;;;WASG;+BALQ,OAAO,EAAE,gDAEP,IAAI,MAAM,CAAC;QAcxB;;;;;WAKG;iBAFU,IAAI,IAAI,CAAC;QAatB;;;;WAIG;wBADQ,KAAK;;;QAQhB;;;;WAIG;2BAHQ,OAAO,UAAU,CAAC,aAClB,eAAe,cACf,gBAAgB;QAe3B;;;WAGG;6BAFQ,OAAO,UAAU,CAAC,UAClB,OAAO;;GASvB;qCApLW,0BAA0B;oBAmB3B;IACZ,OAAW,EAAE,MAAM,CAAC;IACpB,IAAQ,EAAE,IAAI,CAAC;IACf,UAAc,EAAE,OAAO,UAAU,CAAC,GAAG,SAAS,CAAC;IAC/C,YAAgB,EAAE,eAAe,GAAG,SAAS,CAAC;IAC9C,sBAA0B,EAAE,MAAM,CAAC;IACnC,aAAiB,EAAE,gBAAgB,GAAG,SAAS,CAAC;IAChD,YAAgB,EAAE,YAAY,GAAG,SAAS,CAAC;CACxC;8BA2JU,UAAU,CAAC,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC;0BAlM5C,mBAAmB;8BAEF,aAAa;0BADlB,iBAAiB;kCAKrB,aAAa;yBAJJ,aAAa;6BAC3B,sBAAsB;4BACvB,8CAA8C;gCAHpC,iBAAiB;4BACZ,aAAa;qCAGD,iCAAiC;sCAAjC,iCAAiC"}