@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.
- package/LICENSE +201 -0
- package/README.md +5 -0
- package/index.d.ts +4 -0
- package/index.js +7 -0
- package/package.json +95 -0
- package/src/chain-info.d.ts +2318 -0
- package/src/chain-info.d.ts.map +1 -0
- package/src/chain-info.js +114 -0
- package/src/cosmos-api.d.ts +174 -0
- package/src/cosmos-api.d.ts.map +1 -0
- package/src/cosmos-api.ts +231 -0
- package/src/ethereum-api.d.ts +8 -0
- package/src/ethereum-api.d.ts.map +1 -0
- package/src/ethereum-api.ts +7 -0
- package/src/examples/sendAnywhere.contract.d.ts +31 -0
- package/src/examples/sendAnywhere.contract.d.ts.map +1 -0
- package/src/examples/sendAnywhere.contract.js +171 -0
- package/src/examples/stakeBld.contract.d.ts +121 -0
- package/src/examples/stakeBld.contract.d.ts.map +1 -0
- package/src/examples/stakeBld.contract.js +133 -0
- package/src/examples/stakeIca.contract.d.ts +93 -0
- package/src/examples/stakeIca.contract.d.ts.map +1 -0
- package/src/examples/stakeIca.contract.js +143 -0
- package/src/examples/swapExample.contract.d.ts +34 -0
- package/src/examples/swapExample.contract.d.ts.map +1 -0
- package/src/examples/swapExample.contract.js +155 -0
- package/src/examples/unbondExample.contract.d.ts +21 -0
- package/src/examples/unbondExample.contract.d.ts.map +1 -0
- package/src/examples/unbondExample.contract.js +105 -0
- package/src/exos/README.md +56 -0
- package/src/exos/agoric-names-tools.d.ts +27 -0
- package/src/exos/agoric-names-tools.d.ts.map +1 -0
- package/src/exos/agoric-names-tools.js +109 -0
- package/src/exos/chain-account-kit.d.ts +88 -0
- package/src/exos/chain-account-kit.d.ts.map +1 -0
- package/src/exos/chain-account-kit.js +210 -0
- package/src/exos/chain-hub.d.ts +77 -0
- package/src/exos/chain-hub.d.ts.map +1 -0
- package/src/exos/chain-hub.js +214 -0
- package/src/exos/cosmos-orchestration-account.d.ts +207 -0
- package/src/exos/cosmos-orchestration-account.d.ts.map +1 -0
- package/src/exos/cosmos-orchestration-account.js +536 -0
- package/src/exos/icq-connection-kit.d.ts +50 -0
- package/src/exos/icq-connection-kit.d.ts.map +1 -0
- package/src/exos/icq-connection-kit.js +135 -0
- package/src/exos/local-chain-facade.d.ts +81 -0
- package/src/exos/local-chain-facade.d.ts.map +1 -0
- package/src/exos/local-chain-facade.js +113 -0
- package/src/exos/local-orchestration-account.d.ts +176 -0
- package/src/exos/local-orchestration-account.d.ts.map +1 -0
- package/src/exos/local-orchestration-account.js +446 -0
- package/src/exos/orchestrator.d.ts +91 -0
- package/src/exos/orchestrator.d.ts.map +1 -0
- package/src/exos/orchestrator.js +141 -0
- package/src/exos/remote-chain-facade.d.ts +144 -0
- package/src/exos/remote-chain-facade.d.ts.map +1 -0
- package/src/exos/remote-chain-facade.js +145 -0
- package/src/facade.d.ts +57 -0
- package/src/facade.d.ts.map +1 -0
- package/src/facade.js +132 -0
- package/src/fetched-chain-info.d.ts +2311 -0
- package/src/fetched-chain-info.d.ts.map +1 -0
- package/src/fetched-chain-info.js +2288 -0
- package/src/internal.d.ts +13 -0
- package/src/internal.d.ts.map +1 -0
- package/src/internal.ts +20 -0
- package/src/orchestration-api.d.ts +158 -0
- package/src/orchestration-api.d.ts.map +1 -0
- package/src/orchestration-api.ts +201 -0
- package/src/proposals/orchestration-proposal.d.ts +53 -0
- package/src/proposals/orchestration-proposal.d.ts.map +1 -0
- package/src/proposals/orchestration-proposal.js +179 -0
- package/src/proposals/revise-chain-info.d.ts +21 -0
- package/src/proposals/revise-chain-info.d.ts.map +1 -0
- package/src/proposals/revise-chain-info.js +44 -0
- package/src/proposals/start-stakeAtom.d.ts +109 -0
- package/src/proposals/start-stakeAtom.d.ts.map +1 -0
- package/src/proposals/start-stakeAtom.js +105 -0
- package/src/proposals/start-stakeBld.d.ts +154 -0
- package/src/proposals/start-stakeBld.d.ts.map +1 -0
- package/src/proposals/start-stakeBld.js +103 -0
- package/src/proposals/start-stakeOsmo.d.ts +108 -0
- package/src/proposals/start-stakeOsmo.d.ts.map +1 -0
- package/src/proposals/start-stakeOsmo.js +106 -0
- package/src/service.d.ts +97 -0
- package/src/service.d.ts.map +1 -0
- package/src/service.js +259 -0
- package/src/typeGuards.d.ts +55 -0
- package/src/typeGuards.d.ts.map +1 -0
- package/src/typeGuards.js +104 -0
- package/src/types.d.ts +11 -0
- package/src/types.d.ts.map +1 -0
- package/src/types.ts +11 -0
- package/src/utils/address.d.ts +14 -0
- package/src/utils/address.d.ts.map +1 -0
- package/src/utils/address.js +79 -0
- package/src/utils/cosmos.d.ts +9 -0
- package/src/utils/cosmos.d.ts.map +1 -0
- package/src/utils/cosmos.js +36 -0
- package/src/utils/orc.d.ts +17 -0
- package/src/utils/orc.d.ts.map +1 -0
- package/src/utils/orc.js +38 -0
- package/src/utils/orchestrationAccount.d.ts +10 -0
- package/src/utils/orchestrationAccount.d.ts.map +1 -0
- package/src/utils/orchestrationAccount.js +22 -0
- package/src/utils/packet.d.ts +57 -0
- package/src/utils/packet.d.ts.map +1 -0
- package/src/utils/packet.js +112 -0
- package/src/utils/registry.d.ts +13 -0
- package/src/utils/registry.d.ts.map +1 -0
- package/src/utils/registry.js +131 -0
- package/src/utils/start-helper.d.ts +51 -0
- package/src/utils/start-helper.d.ts.map +1 -0
- package/src/utils/start-helper.js +109 -0
- package/src/utils/time.d.ts +31 -0
- package/src/utils/time.d.ts.map +1 -0
- package/src/utils/time.js +63 -0
- package/src/vat-orchestration.d.ts +58 -0
- package/src/vat-orchestration.d.ts.map +1 -0
- package/src/vat-orchestration.js +24 -0
|
@@ -0,0 +1,536 @@
|
|
|
1
|
+
/** @file Use-object for the owner of a staking account */
|
|
2
|
+
import { toRequestQueryJson } from '@agoric/cosmic-proto';
|
|
3
|
+
import {
|
|
4
|
+
QueryBalanceRequest,
|
|
5
|
+
QueryBalanceResponse,
|
|
6
|
+
} from '@agoric/cosmic-proto/cosmos/bank/v1beta1/query.js';
|
|
7
|
+
import {
|
|
8
|
+
MsgWithdrawDelegatorReward,
|
|
9
|
+
MsgWithdrawDelegatorRewardResponse,
|
|
10
|
+
} from '@agoric/cosmic-proto/cosmos/distribution/v1beta1/tx.js';
|
|
11
|
+
import {
|
|
12
|
+
MsgBeginRedelegate,
|
|
13
|
+
MsgDelegate,
|
|
14
|
+
MsgUndelegate,
|
|
15
|
+
MsgUndelegateResponse,
|
|
16
|
+
} from '@agoric/cosmic-proto/cosmos/staking/v1beta1/tx.js';
|
|
17
|
+
import { Any } from '@agoric/cosmic-proto/google/protobuf/any.js';
|
|
18
|
+
import { makeTracer } from '@agoric/internal';
|
|
19
|
+
import { Shape as NetworkShape } from '@agoric/network';
|
|
20
|
+
import { M } from '@agoric/vat-data';
|
|
21
|
+
import { VowShape } from '@agoric/vow';
|
|
22
|
+
import { TopicsRecordShape } from '@agoric/zoe/src/contractSupport/index.js';
|
|
23
|
+
import { decodeBase64 } from '@endo/base64';
|
|
24
|
+
import { E } from '@endo/far';
|
|
25
|
+
import {
|
|
26
|
+
AmountArgShape,
|
|
27
|
+
ChainAddressShape,
|
|
28
|
+
ChainAmountShape,
|
|
29
|
+
CoinShape,
|
|
30
|
+
DelegationShape,
|
|
31
|
+
} from '../typeGuards.js';
|
|
32
|
+
import { maxClockSkew, tryDecodeResponse } from '../utils/cosmos.js';
|
|
33
|
+
import { orchestrationAccountMethods } from '../utils/orchestrationAccount.js';
|
|
34
|
+
import { dateInSeconds } from '../utils/time.js';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @import {AmountArg, IcaAccount, ChainAddress, CosmosValidatorAddress, ICQConnection, StakingAccountActions, DenomAmount, OrchestrationAccountI, DenomArg} from '../types.js';
|
|
38
|
+
* @import {RecorderKit, MakeRecorderKit} from '@agoric/zoe/src/contractSupport/recorder.js';
|
|
39
|
+
* @import {Coin} from '@agoric/cosmic-proto/cosmos/base/v1beta1/coin.js';
|
|
40
|
+
* @import {Delegation} from '@agoric/cosmic-proto/cosmos/staking/v1beta1/staking.js';
|
|
41
|
+
* @import {Remote} from '@agoric/internal';
|
|
42
|
+
* @import {TimerService} from '@agoric/time';
|
|
43
|
+
* @import {Vow, VowTools} from '@agoric/vow';
|
|
44
|
+
* @import {Zone} from '@agoric/zone';
|
|
45
|
+
* @import {ResponseQuery} from '@agoric/cosmic-proto/tendermint/abci/types.js';
|
|
46
|
+
* @import {JsonSafe} from '@agoric/cosmic-proto';
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
const trace = makeTracer('ComosOrchestrationAccountHolder');
|
|
50
|
+
|
|
51
|
+
const { Fail } = assert;
|
|
52
|
+
const { Vow$ } = NetworkShape; // TODO #9611
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @typedef {object} ComosOrchestrationAccountNotification
|
|
56
|
+
* @property {ChainAddress} chainAddress
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @typedef {{
|
|
61
|
+
* topicKit: RecorderKit<ComosOrchestrationAccountNotification>;
|
|
62
|
+
* account: IcaAccount;
|
|
63
|
+
* chainAddress: ChainAddress;
|
|
64
|
+
* icqConnection: ICQConnection | undefined;
|
|
65
|
+
* bondDenom: string;
|
|
66
|
+
* timer: Remote<TimerService>;
|
|
67
|
+
* }} State
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
/** @see {OrchestrationAccountI} */
|
|
71
|
+
export const IcaAccountHolderI = M.interface('IcaAccountHolder', {
|
|
72
|
+
...orchestrationAccountMethods,
|
|
73
|
+
asContinuingOffer: M.call().returns({
|
|
74
|
+
publicSubscribers: M.any(),
|
|
75
|
+
invitationMakers: M.any(),
|
|
76
|
+
holder: M.any(),
|
|
77
|
+
}),
|
|
78
|
+
getPublicTopics: M.call().returns(TopicsRecordShape),
|
|
79
|
+
delegate: M.call(ChainAddressShape, AmountArgShape).returns(VowShape),
|
|
80
|
+
redelegate: M.call(
|
|
81
|
+
ChainAddressShape,
|
|
82
|
+
ChainAddressShape,
|
|
83
|
+
AmountArgShape,
|
|
84
|
+
).returns(VowShape),
|
|
85
|
+
withdrawReward: M.call(ChainAddressShape).returns(
|
|
86
|
+
Vow$(M.arrayOf(ChainAmountShape)),
|
|
87
|
+
),
|
|
88
|
+
withdrawRewards: M.call().returns(Vow$(M.arrayOf(ChainAmountShape))),
|
|
89
|
+
undelegate: M.call(M.arrayOf(DelegationShape)).returns(VowShape),
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
/** @type {{ [name: string]: [description: string, valueShape: Pattern] }} */
|
|
93
|
+
const PUBLIC_TOPICS = {
|
|
94
|
+
account: ['Staking Account holder status', M.any()],
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/** @type {(c: { denom: string; amount: string }) => DenomAmount} */
|
|
98
|
+
const toDenomAmount = c => ({ denom: c.denom, value: BigInt(c.amount) });
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @param {Zone} zone
|
|
102
|
+
* @param {MakeRecorderKit} makeRecorderKit
|
|
103
|
+
* @param {VowTools} vowTools
|
|
104
|
+
* @param {ZCF} zcf
|
|
105
|
+
*/
|
|
106
|
+
export const prepareCosmosOrchestrationAccountKit = (
|
|
107
|
+
zone,
|
|
108
|
+
makeRecorderKit,
|
|
109
|
+
{ watch, asVow },
|
|
110
|
+
zcf,
|
|
111
|
+
) => {
|
|
112
|
+
const makeCosmosOrchestrationAccountKit = zone.exoClassKit(
|
|
113
|
+
'Staking Account Holder',
|
|
114
|
+
{
|
|
115
|
+
helper: M.interface('helper', {
|
|
116
|
+
owned: M.call().returns(M.remotable()),
|
|
117
|
+
getUpdater: M.call().returns(M.remotable()),
|
|
118
|
+
amountToCoin: M.call(AmountArgShape).returns(M.record()),
|
|
119
|
+
}),
|
|
120
|
+
returnVoidWatcher: M.interface('returnVoidWatcher', {
|
|
121
|
+
onFulfilled: M.call(M.or(M.string(), M.record()))
|
|
122
|
+
.optional(M.arrayOf(M.undefined()))
|
|
123
|
+
.returns(M.undefined()),
|
|
124
|
+
}),
|
|
125
|
+
balanceQueryWatcher: M.interface('balanceQueryWatcher', {
|
|
126
|
+
onFulfilled: M.call(M.arrayOf(M.record()))
|
|
127
|
+
.optional(M.arrayOf(M.undefined())) // empty context
|
|
128
|
+
.returns(M.or(M.record(), M.undefined())),
|
|
129
|
+
}),
|
|
130
|
+
undelegateWatcher: M.interface('undelegateWatcher', {
|
|
131
|
+
onFulfilled: M.call(M.string())
|
|
132
|
+
.optional(M.arrayOf(M.undefined())) // empty context
|
|
133
|
+
.returns(Vow$(M.promise())),
|
|
134
|
+
}),
|
|
135
|
+
withdrawRewardWatcher: M.interface('withdrawRewardWatcher', {
|
|
136
|
+
onFulfilled: M.call(M.string())
|
|
137
|
+
.optional(M.arrayOf(M.undefined())) // empty context
|
|
138
|
+
.returns(M.arrayOf(CoinShape)),
|
|
139
|
+
}),
|
|
140
|
+
holder: IcaAccountHolderI,
|
|
141
|
+
invitationMakers: M.interface('invitationMakers', {
|
|
142
|
+
Delegate: M.call(ChainAddressShape, AmountArgShape).returns(
|
|
143
|
+
M.promise(),
|
|
144
|
+
),
|
|
145
|
+
Redelegate: M.call(
|
|
146
|
+
ChainAddressShape,
|
|
147
|
+
ChainAddressShape,
|
|
148
|
+
AmountArgShape,
|
|
149
|
+
).returns(M.promise()),
|
|
150
|
+
WithdrawReward: M.call(ChainAddressShape).returns(M.promise()),
|
|
151
|
+
Undelegate: M.call(M.arrayOf(DelegationShape)).returns(M.promise()),
|
|
152
|
+
CloseAccount: M.call().returns(M.promise()),
|
|
153
|
+
TransferAccount: M.call().returns(M.promise()),
|
|
154
|
+
}),
|
|
155
|
+
},
|
|
156
|
+
/**
|
|
157
|
+
* @param {ChainAddress} chainAddress
|
|
158
|
+
* @param {string} bondDenom e.g. 'uatom'
|
|
159
|
+
* @param {object} io
|
|
160
|
+
* @param {IcaAccount} io.account
|
|
161
|
+
* @param {Remote<StorageNode>} io.storageNode
|
|
162
|
+
* @param {ICQConnection | undefined} io.icqConnection
|
|
163
|
+
* @param {Remote<TimerService>} io.timer
|
|
164
|
+
* @returns {State}
|
|
165
|
+
*/
|
|
166
|
+
(chainAddress, bondDenom, io) => {
|
|
167
|
+
const { storageNode, ...rest } = io;
|
|
168
|
+
// must be the fully synchronous maker because the kit is held in durable state
|
|
169
|
+
// @ts-expect-error XXX Patterns
|
|
170
|
+
const topicKit = makeRecorderKit(storageNode, PUBLIC_TOPICS.account[1]);
|
|
171
|
+
// TODO determine what goes in vstorage https://github.com/Agoric/agoric-sdk/issues/9066
|
|
172
|
+
void E(topicKit.recorder).write('');
|
|
173
|
+
|
|
174
|
+
return { chainAddress, bondDenom, topicKit, ...rest };
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
helper: {
|
|
178
|
+
/** @throws if this holder no longer owns the account */
|
|
179
|
+
owned() {
|
|
180
|
+
const { account } = this.state;
|
|
181
|
+
if (!account) {
|
|
182
|
+
throw Fail`Using account holder after transfer`;
|
|
183
|
+
}
|
|
184
|
+
return account;
|
|
185
|
+
},
|
|
186
|
+
getUpdater() {
|
|
187
|
+
return this.state.topicKit.recorder;
|
|
188
|
+
},
|
|
189
|
+
/**
|
|
190
|
+
* @param {AmountArg} amount
|
|
191
|
+
* @returns {Coin}
|
|
192
|
+
*/
|
|
193
|
+
amountToCoin(amount) {
|
|
194
|
+
const { bondDenom } = this.state;
|
|
195
|
+
if ('denom' in amount) {
|
|
196
|
+
assert.equal(amount.denom, bondDenom);
|
|
197
|
+
} else {
|
|
198
|
+
trace('TODO: handle brand', amount);
|
|
199
|
+
// FIXME(#9211) brand handling
|
|
200
|
+
}
|
|
201
|
+
return harden({
|
|
202
|
+
denom: bondDenom,
|
|
203
|
+
amount: String(amount.value),
|
|
204
|
+
});
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
balanceQueryWatcher: {
|
|
208
|
+
/**
|
|
209
|
+
* @param {JsonSafe<ResponseQuery>[]} results
|
|
210
|
+
*/
|
|
211
|
+
onFulfilled([result]) {
|
|
212
|
+
if (!result?.key) throw Fail`Error parsing result ${result}`;
|
|
213
|
+
const { balance } = QueryBalanceResponse.decode(
|
|
214
|
+
decodeBase64(result.key),
|
|
215
|
+
);
|
|
216
|
+
if (!balance) throw Fail`Result lacked balance key: ${result}`;
|
|
217
|
+
return harden(toDenomAmount(balance));
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
undelegateWatcher: {
|
|
221
|
+
/**
|
|
222
|
+
* @param {string} result
|
|
223
|
+
*/
|
|
224
|
+
onFulfilled(result) {
|
|
225
|
+
const response = tryDecodeResponse(
|
|
226
|
+
result,
|
|
227
|
+
MsgUndelegateResponse.fromProtoMsg,
|
|
228
|
+
);
|
|
229
|
+
trace('undelegate response', response);
|
|
230
|
+
const { completionTime } = response;
|
|
231
|
+
completionTime || Fail`No completion time result ${result}`;
|
|
232
|
+
return watch(
|
|
233
|
+
E(this.state.timer).wakeAt(
|
|
234
|
+
dateInSeconds(completionTime) + maxClockSkew,
|
|
235
|
+
),
|
|
236
|
+
);
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
/**
|
|
240
|
+
* takes an array of results (from `executeEncodedTx`) and returns void
|
|
241
|
+
* since we are not interested in the result
|
|
242
|
+
*/
|
|
243
|
+
returnVoidWatcher: {
|
|
244
|
+
/** @param {string | Record<string, unknown>} result */
|
|
245
|
+
onFulfilled(result) {
|
|
246
|
+
trace('Result', result);
|
|
247
|
+
return undefined;
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
withdrawRewardWatcher: {
|
|
251
|
+
/** @param {string} result */
|
|
252
|
+
onFulfilled(result) {
|
|
253
|
+
const response = tryDecodeResponse(
|
|
254
|
+
result,
|
|
255
|
+
MsgWithdrawDelegatorRewardResponse.fromProtoMsg,
|
|
256
|
+
);
|
|
257
|
+
trace('withdrawReward response', response);
|
|
258
|
+
const { amount: coins } = response;
|
|
259
|
+
return harden(coins.map(toDenomAmount));
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
invitationMakers: {
|
|
263
|
+
/**
|
|
264
|
+
* @param {CosmosValidatorAddress} validator
|
|
265
|
+
* @param {AmountArg} amount
|
|
266
|
+
*/
|
|
267
|
+
Delegate(validator, amount) {
|
|
268
|
+
trace('Delegate', validator, amount);
|
|
269
|
+
|
|
270
|
+
return zcf.makeInvitation(seat => {
|
|
271
|
+
seat.exit();
|
|
272
|
+
return watch(this.facets.holder.delegate(validator, amount));
|
|
273
|
+
}, 'Delegate');
|
|
274
|
+
},
|
|
275
|
+
/**
|
|
276
|
+
* @param {CosmosValidatorAddress} srcValidator
|
|
277
|
+
* @param {CosmosValidatorAddress} dstValidator
|
|
278
|
+
* @param {AmountArg} amount
|
|
279
|
+
*/
|
|
280
|
+
Redelegate(srcValidator, dstValidator, amount) {
|
|
281
|
+
trace('Redelegate', srcValidator, dstValidator, amount);
|
|
282
|
+
|
|
283
|
+
return zcf.makeInvitation(seat => {
|
|
284
|
+
seat.exit();
|
|
285
|
+
return watch(
|
|
286
|
+
this.facets.holder.redelegate(srcValidator, dstValidator, amount),
|
|
287
|
+
);
|
|
288
|
+
}, 'Redelegate');
|
|
289
|
+
},
|
|
290
|
+
/** @param {CosmosValidatorAddress} validator */
|
|
291
|
+
WithdrawReward(validator) {
|
|
292
|
+
trace('WithdrawReward', validator);
|
|
293
|
+
|
|
294
|
+
return zcf.makeInvitation(seat => {
|
|
295
|
+
seat.exit();
|
|
296
|
+
return watch(this.facets.holder.withdrawReward(validator));
|
|
297
|
+
}, 'WithdrawReward');
|
|
298
|
+
},
|
|
299
|
+
/** @param {Omit<Delegation, 'delegatorAddress'>[]} delegations */
|
|
300
|
+
Undelegate(delegations) {
|
|
301
|
+
trace('Undelegate', delegations);
|
|
302
|
+
|
|
303
|
+
return zcf.makeInvitation(seat => {
|
|
304
|
+
seat.exit();
|
|
305
|
+
return watch(this.facets.holder.undelegate(delegations));
|
|
306
|
+
}, 'Undelegate');
|
|
307
|
+
},
|
|
308
|
+
CloseAccount() {
|
|
309
|
+
throw Error('not yet implemented');
|
|
310
|
+
},
|
|
311
|
+
/**
|
|
312
|
+
* Starting a transfer revokes the account holder. The associated
|
|
313
|
+
* updater will get a special notification that the account is being
|
|
314
|
+
* transferred.
|
|
315
|
+
*/
|
|
316
|
+
TransferAccount() {
|
|
317
|
+
throw Error('not yet implemented');
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
holder: {
|
|
321
|
+
asContinuingOffer() {
|
|
322
|
+
const { holder, invitationMakers } = this.facets;
|
|
323
|
+
return harden({
|
|
324
|
+
publicSubscribers: holder.getPublicTopics(),
|
|
325
|
+
invitationMakers,
|
|
326
|
+
holder,
|
|
327
|
+
});
|
|
328
|
+
},
|
|
329
|
+
getPublicTopics() {
|
|
330
|
+
const { topicKit } = this.state;
|
|
331
|
+
return harden({
|
|
332
|
+
account: {
|
|
333
|
+
description: PUBLIC_TOPICS.account[0],
|
|
334
|
+
subscriber: topicKit.subscriber,
|
|
335
|
+
storagePath: topicKit.recorder.getStoragePath(),
|
|
336
|
+
},
|
|
337
|
+
});
|
|
338
|
+
},
|
|
339
|
+
|
|
340
|
+
// TODO move this beneath the Orchestration abstraction,
|
|
341
|
+
// to the OrchestrationAccount provided by makeAccount()
|
|
342
|
+
/** @returns {ChainAddress} */
|
|
343
|
+
getAddress() {
|
|
344
|
+
return this.state.chainAddress;
|
|
345
|
+
},
|
|
346
|
+
/**
|
|
347
|
+
* _Assumes users has already sent funds to their ICA, until #9193
|
|
348
|
+
*
|
|
349
|
+
* @param {CosmosValidatorAddress} validator
|
|
350
|
+
* @param {AmountArg} amount
|
|
351
|
+
*/
|
|
352
|
+
delegate(validator, amount) {
|
|
353
|
+
return asVow(() => {
|
|
354
|
+
trace('delegate', validator, amount);
|
|
355
|
+
const { helper } = this.facets;
|
|
356
|
+
const { chainAddress } = this.state;
|
|
357
|
+
|
|
358
|
+
const results = E(helper.owned()).executeEncodedTx([
|
|
359
|
+
Any.toJSON(
|
|
360
|
+
MsgDelegate.toProtoMsg({
|
|
361
|
+
delegatorAddress: chainAddress.address,
|
|
362
|
+
validatorAddress: validator.address,
|
|
363
|
+
amount: helper.amountToCoin(amount),
|
|
364
|
+
}),
|
|
365
|
+
),
|
|
366
|
+
]);
|
|
367
|
+
return watch(results, this.facets.returnVoidWatcher);
|
|
368
|
+
});
|
|
369
|
+
},
|
|
370
|
+
deposit(payment) {
|
|
371
|
+
trace('deposit', payment);
|
|
372
|
+
console.error(
|
|
373
|
+
'FIXME deposit noop until https://github.com/Agoric/agoric-sdk/issues/9193',
|
|
374
|
+
);
|
|
375
|
+
},
|
|
376
|
+
getBalances() {
|
|
377
|
+
// TODO https://github.com/Agoric/agoric-sdk/issues/9610
|
|
378
|
+
return asVow(() => Fail`not yet implemented`);
|
|
379
|
+
},
|
|
380
|
+
/**
|
|
381
|
+
* _Assumes users has already sent funds to their ICA, until #9193
|
|
382
|
+
*
|
|
383
|
+
* @param {CosmosValidatorAddress} srcValidator
|
|
384
|
+
* @param {CosmosValidatorAddress} dstValidator
|
|
385
|
+
* @param {AmountArg} amount
|
|
386
|
+
*/
|
|
387
|
+
redelegate(srcValidator, dstValidator, amount) {
|
|
388
|
+
return asVow(() => {
|
|
389
|
+
trace('redelegate', srcValidator, dstValidator, amount);
|
|
390
|
+
const { helper } = this.facets;
|
|
391
|
+
const { chainAddress } = this.state;
|
|
392
|
+
|
|
393
|
+
const results = E(helper.owned()).executeEncodedTx([
|
|
394
|
+
Any.toJSON(
|
|
395
|
+
MsgBeginRedelegate.toProtoMsg({
|
|
396
|
+
delegatorAddress: chainAddress.address,
|
|
397
|
+
validatorSrcAddress: srcValidator.address,
|
|
398
|
+
validatorDstAddress: dstValidator.address,
|
|
399
|
+
amount: helper.amountToCoin(amount),
|
|
400
|
+
}),
|
|
401
|
+
),
|
|
402
|
+
]);
|
|
403
|
+
|
|
404
|
+
return watch(
|
|
405
|
+
results,
|
|
406
|
+
// NOTE: response, including completionTime, is currently discarded.
|
|
407
|
+
this.facets.returnVoidWatcher,
|
|
408
|
+
);
|
|
409
|
+
});
|
|
410
|
+
},
|
|
411
|
+
/**
|
|
412
|
+
* @param {CosmosValidatorAddress} validator
|
|
413
|
+
* @returns {Vow<DenomAmount[]>}
|
|
414
|
+
*/
|
|
415
|
+
withdrawReward(validator) {
|
|
416
|
+
return asVow(() => {
|
|
417
|
+
trace('withdrawReward', validator);
|
|
418
|
+
const { helper } = this.facets;
|
|
419
|
+
const { chainAddress } = this.state;
|
|
420
|
+
const msg = MsgWithdrawDelegatorReward.toProtoMsg({
|
|
421
|
+
delegatorAddress: chainAddress.address,
|
|
422
|
+
validatorAddress: validator.address,
|
|
423
|
+
});
|
|
424
|
+
const account = helper.owned();
|
|
425
|
+
|
|
426
|
+
const results = E(account).executeEncodedTx([Any.toJSON(msg)]);
|
|
427
|
+
return watch(results, this.facets.withdrawRewardWatcher);
|
|
428
|
+
});
|
|
429
|
+
},
|
|
430
|
+
/**
|
|
431
|
+
* @param {DenomArg} denom
|
|
432
|
+
* @returns {Vow<DenomAmount>}
|
|
433
|
+
*/
|
|
434
|
+
getBalance(denom) {
|
|
435
|
+
return asVow(() => {
|
|
436
|
+
const { chainAddress, icqConnection } = this.state;
|
|
437
|
+
if (!icqConnection) {
|
|
438
|
+
throw Fail`Queries not available for chain ${chainAddress.chainId}`;
|
|
439
|
+
}
|
|
440
|
+
// TODO #9211 lookup denom from brand
|
|
441
|
+
assert.typeof(denom, 'string');
|
|
442
|
+
|
|
443
|
+
const results = E(icqConnection).query([
|
|
444
|
+
toRequestQueryJson(
|
|
445
|
+
QueryBalanceRequest.toProtoMsg({
|
|
446
|
+
address: chainAddress.address,
|
|
447
|
+
denom,
|
|
448
|
+
}),
|
|
449
|
+
),
|
|
450
|
+
]);
|
|
451
|
+
return watch(results, this.facets.balanceQueryWatcher);
|
|
452
|
+
});
|
|
453
|
+
},
|
|
454
|
+
|
|
455
|
+
send(toAccount, amount) {
|
|
456
|
+
console.log('send got', toAccount, amount);
|
|
457
|
+
return asVow(() => Fail`not yet implemented`);
|
|
458
|
+
},
|
|
459
|
+
|
|
460
|
+
transfer(amount, msg) {
|
|
461
|
+
console.log('transferSteps got', amount, msg);
|
|
462
|
+
return asVow(() => Fail`not yet implemented`);
|
|
463
|
+
},
|
|
464
|
+
|
|
465
|
+
transferSteps(amount, msg) {
|
|
466
|
+
console.log('transferSteps got', amount, msg);
|
|
467
|
+
return asVow(() => Fail`not yet implemented`);
|
|
468
|
+
},
|
|
469
|
+
|
|
470
|
+
withdrawRewards() {
|
|
471
|
+
return asVow(() => Fail`Not Implemented. Try using withdrawReward.`);
|
|
472
|
+
},
|
|
473
|
+
|
|
474
|
+
/** @param {Omit<Delegation, 'delegatorAddress'>[]} delegations */
|
|
475
|
+
undelegate(delegations) {
|
|
476
|
+
return asVow(() => {
|
|
477
|
+
trace('undelegate', delegations);
|
|
478
|
+
const { helper } = this.facets;
|
|
479
|
+
const { chainAddress, bondDenom } = this.state;
|
|
480
|
+
|
|
481
|
+
const undelegateV = watch(
|
|
482
|
+
E(helper.owned()).executeEncodedTx(
|
|
483
|
+
delegations.map(d =>
|
|
484
|
+
Any.toJSON(
|
|
485
|
+
MsgUndelegate.toProtoMsg({
|
|
486
|
+
delegatorAddress: chainAddress.address,
|
|
487
|
+
validatorAddress: d.validatorAddress,
|
|
488
|
+
amount: { denom: bondDenom, amount: d.shares },
|
|
489
|
+
}),
|
|
490
|
+
),
|
|
491
|
+
),
|
|
492
|
+
),
|
|
493
|
+
this.facets.undelegateWatcher,
|
|
494
|
+
);
|
|
495
|
+
return watch(undelegateV, this.facets.returnVoidWatcher);
|
|
496
|
+
});
|
|
497
|
+
},
|
|
498
|
+
},
|
|
499
|
+
},
|
|
500
|
+
);
|
|
501
|
+
|
|
502
|
+
return makeCosmosOrchestrationAccountKit;
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* @typedef {ReturnType<
|
|
507
|
+
* ReturnType<typeof prepareCosmosOrchestrationAccountKit>
|
|
508
|
+
* >} CosmosOrchestrationAccountKit
|
|
509
|
+
*/
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* @param {Zone} zone
|
|
513
|
+
* @param {MakeRecorderKit} makeRecorderKit
|
|
514
|
+
* @param {VowTools} vowTools
|
|
515
|
+
* @param {ZCF} zcf
|
|
516
|
+
* @returns {(
|
|
517
|
+
* ...args: Parameters<
|
|
518
|
+
* ReturnType<typeof prepareCosmosOrchestrationAccountKit>
|
|
519
|
+
* >
|
|
520
|
+
* ) => CosmosOrchestrationAccountKit['holder']}
|
|
521
|
+
*/
|
|
522
|
+
export const prepareCosmosOrchestrationAccount = (
|
|
523
|
+
zone,
|
|
524
|
+
makeRecorderKit,
|
|
525
|
+
vowTools,
|
|
526
|
+
zcf,
|
|
527
|
+
) => {
|
|
528
|
+
const makeKit = prepareCosmosOrchestrationAccountKit(
|
|
529
|
+
zone,
|
|
530
|
+
makeRecorderKit,
|
|
531
|
+
vowTools,
|
|
532
|
+
zcf,
|
|
533
|
+
);
|
|
534
|
+
return (...args) => makeKit(...args).holder;
|
|
535
|
+
};
|
|
536
|
+
/** @typedef {CosmosOrchestrationAccountKit['holder']} CosmosOrchestrationAccount */
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export const ICQMsgShape: import("@endo/patterns").Matcher;
|
|
2
|
+
export const ICQConnectionI: import("@endo/patterns").InterfaceGuard<{
|
|
3
|
+
getLocalAddress: import("@endo/patterns").MethodGuard;
|
|
4
|
+
getRemoteAddress: import("@endo/patterns").MethodGuard;
|
|
5
|
+
query: import("@endo/patterns").MethodGuard;
|
|
6
|
+
}>;
|
|
7
|
+
export function prepareICQConnectionKit(zone: Zone, { watch, when }: VowTools): (port: Port) => import("@endo/exo").GuardedKit<{
|
|
8
|
+
connection: {
|
|
9
|
+
getLocalAddress(): `/ibc-port/${string}`;
|
|
10
|
+
getRemoteAddress(): `/${string}ibc-port/${string}/ordered/${string}` | `/${string}ibc-port/${string}/unordered/${string}`;
|
|
11
|
+
/**
|
|
12
|
+
* @param {JsonSafe<RequestQuery>[]} msgs
|
|
13
|
+
* @returns {Promise<JsonSafe<ResponseQuery>[]>}
|
|
14
|
+
* @throws {Error} if packet fails to send or an error is returned
|
|
15
|
+
*/
|
|
16
|
+
query(msgs: JsonSafe<RequestQuery>[]): Promise<JsonSafe<ResponseQuery>[]>;
|
|
17
|
+
};
|
|
18
|
+
parseQueryPacketWatcher: {
|
|
19
|
+
/** @param {string} ack packet acknowledgement string */
|
|
20
|
+
onFulfilled(ack: string): JsonSafe<ResponseQuery>[];
|
|
21
|
+
};
|
|
22
|
+
connectionHandler: {
|
|
23
|
+
/**
|
|
24
|
+
* @param {Remote<Connection>} connection
|
|
25
|
+
* @param {LocalIbcAddress} localAddr
|
|
26
|
+
* @param {RemoteIbcAddress} remoteAddr
|
|
27
|
+
*/
|
|
28
|
+
onOpen(connection: Remote<Connection>, localAddr: LocalIbcAddress, remoteAddr: RemoteIbcAddress): Promise<void>;
|
|
29
|
+
onClose(_connection: any, reason: any): Promise<void>;
|
|
30
|
+
};
|
|
31
|
+
}>;
|
|
32
|
+
export type ICQConnectionKitState = {
|
|
33
|
+
port: Port;
|
|
34
|
+
connection: Remote<Connection> | undefined;
|
|
35
|
+
localAddress: LocalIbcAddress | undefined;
|
|
36
|
+
remoteAddress: RemoteIbcAddress | undefined;
|
|
37
|
+
};
|
|
38
|
+
export type ICQConnectionKit = ReturnType<ReturnType<typeof prepareICQConnectionKit>>;
|
|
39
|
+
export type ICQConnection = ICQConnectionKit["connection"];
|
|
40
|
+
import type { Zone } from '@agoric/base-zone';
|
|
41
|
+
import type { VowTools } from '@agoric/vow';
|
|
42
|
+
import type { Port } from '@agoric/network';
|
|
43
|
+
import type { RequestQuery } from '@agoric/cosmic-proto/tendermint/abci/types.js';
|
|
44
|
+
import type { JsonSafe } from '@agoric/cosmic-proto';
|
|
45
|
+
import type { ResponseQuery } from '@agoric/cosmic-proto/tendermint/abci/types.js';
|
|
46
|
+
import type { Connection } from '@agoric/network';
|
|
47
|
+
import type { Remote } from '@agoric/vow';
|
|
48
|
+
import type { LocalIbcAddress } from '@agoric/vats/tools/ibc-utils.js';
|
|
49
|
+
import type { RemoteIbcAddress } from '@agoric/vats/tools/ibc-utils.js';
|
|
50
|
+
//# sourceMappingURL=icq-connection-kit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icq-connection-kit.d.ts","sourceRoot":"","sources":["icq-connection-kit.js"],"names":[],"mappings":"AAoBA,2DAGE;AAEF;;;;GAIG;AA2BI,8CAHI,IAAI,mBACJ,QAAQ;;;;QAoCX;;;;WAIG;oBAHQ,SAAS,YAAY,CAAC,EAAE,GACtB,OAAO,CAAC,SAAS,aAAa,CAAC,EAAE,CAAC;;;QAiB/C,wDAAwD;yBAA5C,MAAM;;;QAMlB;;;;WAIG;2BAHQ,OAAO,UAAU,CAAC,aAClB,eAAe,cACf,gBAAgB;;;GAahC;oCAnGU;IACZ,IAAQ,EAAE,IAAI,CAAC;IACf,UAAc,EAAE,OAAO,UAAU,CAAC,GAAG,SAAS,CAAC;IAC/C,YAAgB,EAAE,eAAe,GAAG,SAAS,CAAC;IAC9C,aAAiB,EAAE,gBAAgB,GAAG,SAAS,CAAC;CAC7C;+BAgGU,UAAU,CAAC,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAAC;4BACtD,gBAAgB,CAAC,YAAY,CAAC;0BA7HrB,mBAAmB;8BAEP,aAAa;0BADb,iBAAiB;kCAGN,+CAA+C;8BADlE,sBAAsB;mCACH,+CAA+C;gCAH1D,iBAAiB;4BACjB,aAAa;qCAGI,iCAAiC;sCAAjC,iCAAiC"}
|