@agoric/orchestration 0.1.1-dev-90906b1.0 → 0.1.1-dev-4202f3e.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 +15 -15
- package/src/cosmos-api.d.ts +38 -17
- package/src/cosmos-api.d.ts.map +1 -1
- package/src/cosmos-api.ts +40 -14
- package/src/examples/stakeAtom.contract.d.ts.map +1 -1
- package/src/examples/stakeAtom.contract.js +9 -6
- package/src/examples/stakeBld.contract.d.ts +66 -6
- package/src/examples/stakeBld.contract.d.ts.map +1 -1
- package/src/examples/stakeBld.contract.js +80 -39
- package/src/examples/swapExample.contract.d.ts.map +1 -1
- package/src/examples/swapExample.contract.js +1 -0
- package/src/exos/chainAccountKit.d.ts.map +1 -1
- package/src/exos/chainAccountKit.js +0 -1
- package/src/exos/local-chain-account-kit.d.ts +97 -0
- package/src/exos/local-chain-account-kit.d.ts.map +1 -0
- package/src/exos/local-chain-account-kit.js +253 -0
- package/src/facade.d.ts +1 -1
- package/src/facade.d.ts.map +1 -1
- package/src/facade.js +1 -1
- package/src/orchestration-api.d.ts +5 -5
- package/src/orchestration-api.d.ts.map +1 -1
- package/src/orchestration-api.ts +5 -5
- package/src/proposals/start-stakeAtom.d.ts.map +1 -1
- package/src/proposals/start-stakeBld.d.ts +92 -10
- package/src/proposals/start-stakeBld.d.ts.map +1 -1
- package/src/proposals/start-stakeBld.js +16 -3
- package/src/typeGuards.d.ts +1 -0
- package/src/typeGuards.d.ts.map +1 -1
- package/src/typeGuards.js +12 -1
- package/src/utils/mockChainInfo.d.ts +4 -0
- package/src/utils/mockChainInfo.d.ts.map +1 -0
- package/src/utils/mockChainInfo.js +86 -0
- package/src/utils/time.d.ts +25 -0
- package/src/utils/time.d.ts.map +1 -0
- package/src/utils/time.js +38 -0
- package/src/exos/localchainAccountKit.d.ts +0 -62
- package/src/exos/localchainAccountKit.d.ts.map +0 -1
- package/src/exos/localchainAccountKit.js +0 -155
|
@@ -9,7 +9,13 @@ const trace = makeTracer('StartStakeBld', true);
|
|
|
9
9
|
* @param {BootstrapPowers & {installation: {consume: {stakeBld: Installation<import('../../src/examples/stakeBld.contract.js').start>}}}} powers
|
|
10
10
|
*/
|
|
11
11
|
export const startStakeBld = async ({
|
|
12
|
-
consume: {
|
|
12
|
+
consume: {
|
|
13
|
+
board,
|
|
14
|
+
chainStorage,
|
|
15
|
+
chainTimerService: chainTimerServiceP,
|
|
16
|
+
localchain,
|
|
17
|
+
startUpgradable,
|
|
18
|
+
},
|
|
13
19
|
installation: {
|
|
14
20
|
consume: { stakeBld },
|
|
15
21
|
},
|
|
@@ -28,15 +34,21 @@ export const startStakeBld = async ({
|
|
|
28
34
|
// NB: committee must only publish what it intended to be public
|
|
29
35
|
const marshaller = await E(board).getPublishingMarshaller();
|
|
30
36
|
|
|
31
|
-
|
|
37
|
+
const [timerService, timerBrand] = await Promise.all([
|
|
38
|
+
chainTimerServiceP,
|
|
39
|
+
chainTimerServiceP.then(ts => E(ts).getTimerBrand()),
|
|
40
|
+
]);
|
|
41
|
+
|
|
32
42
|
/** @type {StartUpgradableOpts<import('../../src/examples/stakeBld.contract.js').start>} */
|
|
33
43
|
const startOpts = {
|
|
34
44
|
label: 'stakeBld',
|
|
35
45
|
installation: stakeBld,
|
|
36
|
-
issuerKeywordRecord: harden({
|
|
46
|
+
issuerKeywordRecord: harden({ In: await stakeIssuer }),
|
|
37
47
|
terms: {},
|
|
38
48
|
privateArgs: {
|
|
39
49
|
localchain: await localchain,
|
|
50
|
+
timerService,
|
|
51
|
+
timerBrand,
|
|
40
52
|
storageNode,
|
|
41
53
|
marshaller,
|
|
42
54
|
},
|
|
@@ -54,6 +66,7 @@ export const getManifestForStakeBld = ({ restoreRef }, { installKeys }) => {
|
|
|
54
66
|
consume: {
|
|
55
67
|
board: true,
|
|
56
68
|
chainStorage: true,
|
|
69
|
+
chainTimerService: true,
|
|
57
70
|
localchain: true,
|
|
58
71
|
startUpgradable: true,
|
|
59
72
|
},
|
package/src/typeGuards.d.ts
CHANGED
|
@@ -25,4 +25,5 @@ export namespace ChainAmountShape {
|
|
|
25
25
|
}
|
|
26
26
|
export const AmountArgShape: import("@endo/patterns").Matcher;
|
|
27
27
|
export const DelegationShape: import("@endo/patterns").Matcher;
|
|
28
|
+
export const IBCTransferOptionsShape: import("@endo/patterns").Matcher;
|
|
28
29
|
//# sourceMappingURL=typeGuards.d.ts.map
|
package/src/typeGuards.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeGuards.d.ts","sourceRoot":"","sources":["typeGuards.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"typeGuards.d.ts","sourceRoot":"","sources":["typeGuards.js"],"names":[],"mappings":"AAGA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;AAiBH,8DAAkE;AAElE,+DAA0C;AAE1C,uEAUE"}
|
package/src/typeGuards.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-check
|
|
2
1
|
import { AmountShape } from '@agoric/ertp';
|
|
3
2
|
import { M } from '@endo/patterns';
|
|
4
3
|
|
|
@@ -26,3 +25,15 @@ export const ChainAmountShape = harden({ denom: M.string(), value: M.nat() });
|
|
|
26
25
|
export const AmountArgShape = M.or(AmountShape, ChainAmountShape);
|
|
27
26
|
|
|
28
27
|
export const DelegationShape = M.record(); // TODO: DelegationShape fields
|
|
28
|
+
|
|
29
|
+
export const IBCTransferOptionsShape = M.splitRecord(
|
|
30
|
+
{},
|
|
31
|
+
{
|
|
32
|
+
timeoutTimestamp: M.bigint(),
|
|
33
|
+
timeoutHeight: {
|
|
34
|
+
revisionHeight: M.bigint(),
|
|
35
|
+
revisionNumber: M.bigint(),
|
|
36
|
+
},
|
|
37
|
+
memo: M.string(),
|
|
38
|
+
},
|
|
39
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockChainInfo.d.ts","sourceRoot":"","sources":["mockChainInfo.js"],"names":[],"mappings":"AAyEO,mGAYN;0BA3EsB,cAAc;qCACgB,kBAAkB"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Mocked Chain Info object until #8879
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
Order,
|
|
6
|
+
State as IBCChannelState,
|
|
7
|
+
} from '@agoric/cosmic-proto/ibc/core/channel/v1/channel.js';
|
|
8
|
+
import { State as IBCConnectionState } from '@agoric/cosmic-proto/ibc/core/connection/v1/connection.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @import {Zone} from '@agoric/zone';
|
|
12
|
+
* @import {CosmosChainInfo, IBCConnectionInfo} from '../cosmos-api.js';
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* currently keyed by ChainId, as this is what we have
|
|
17
|
+
* available in ChainAddress to determine the correct IBCChannelID's
|
|
18
|
+
* for a .transfer() msg.
|
|
19
|
+
* @type {Record<string, IBCConnectionInfo>}
|
|
20
|
+
*/
|
|
21
|
+
const connectionEntries = harden({
|
|
22
|
+
cosmoslocal: {
|
|
23
|
+
id: 'connection-1',
|
|
24
|
+
client_id: '07-tendermint-3',
|
|
25
|
+
counterparty: {
|
|
26
|
+
client_id: '07-tendermint-2',
|
|
27
|
+
connection_id: 'connection-1',
|
|
28
|
+
prefix: {
|
|
29
|
+
key_prefix: '',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
state: IBCConnectionState.STATE_OPEN,
|
|
33
|
+
transferChannel: {
|
|
34
|
+
portId: 'transfer',
|
|
35
|
+
channelId: 'channel-1',
|
|
36
|
+
counterPartyChannelId: 'channel-1',
|
|
37
|
+
counterPartyPortId: 'transfer',
|
|
38
|
+
ordering: Order.ORDER_UNORDERED,
|
|
39
|
+
state: IBCChannelState.STATE_OPEN,
|
|
40
|
+
version: 'ics20-1',
|
|
41
|
+
},
|
|
42
|
+
versions: [{ identifier: '', features: ['', ''] }],
|
|
43
|
+
delay_period: 0n,
|
|
44
|
+
},
|
|
45
|
+
osmosislocal: {
|
|
46
|
+
id: 'connection-0',
|
|
47
|
+
client_id: '07-tendermint-2',
|
|
48
|
+
counterparty: {
|
|
49
|
+
client_id: '07-tendermint-2',
|
|
50
|
+
connection_id: 'connection-1',
|
|
51
|
+
prefix: {
|
|
52
|
+
key_prefix: '',
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
state: IBCConnectionState.STATE_OPEN,
|
|
56
|
+
transferChannel: {
|
|
57
|
+
portId: 'transfer',
|
|
58
|
+
channelId: 'channel-0',
|
|
59
|
+
counterPartyChannelId: 'channel-1',
|
|
60
|
+
counterPartyPortId: 'transfer',
|
|
61
|
+
ordering: Order.ORDER_UNORDERED,
|
|
62
|
+
state: IBCChannelState.STATE_OPEN,
|
|
63
|
+
version: 'ics20-1',
|
|
64
|
+
},
|
|
65
|
+
versions: [{ identifier: '', features: ['', ''] }],
|
|
66
|
+
delay_period: 0n,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @param {Zone} zone
|
|
72
|
+
* @returns {Pick<CosmosChainInfo, 'connections' | 'chainId'>}
|
|
73
|
+
*/
|
|
74
|
+
export const prepareMockChainInfo = zone => {
|
|
75
|
+
const agoricConnections =
|
|
76
|
+
/** @type {import('@agoric/store').MapStore<string, IBCConnectionInfo>} */ (
|
|
77
|
+
zone.mapStore('ibcConnections')
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
agoricConnections.addAll(Object.entries(connectionEntries));
|
|
81
|
+
|
|
82
|
+
return harden({
|
|
83
|
+
chainId: 'agoriclocal',
|
|
84
|
+
connections: agoricConnections,
|
|
85
|
+
});
|
|
86
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {TimerService} timer
|
|
3
|
+
* @param {TimerBrand} timerBrand
|
|
4
|
+
*/
|
|
5
|
+
export function makeTimestampHelper(timer: TimerService, timerBrand: TimerBrand): {
|
|
6
|
+
/**
|
|
7
|
+
* Takes the current time from ChainTimerService and adds a relative
|
|
8
|
+
* time to determine a timeout timestamp in nanoseconds.
|
|
9
|
+
* Useful for {@link MsgTransfer.timeoutTimestamp}.
|
|
10
|
+
* @param {RelativeTimeRecord} [relativeTime] defaults to 5 minutes
|
|
11
|
+
* @returns {Promise<bigint>} Timeout timestamp in absolute nanoseconds since unix epoch
|
|
12
|
+
*/
|
|
13
|
+
getTimeoutTimestampNS(relativeTime?: RelativeTimeRecord | undefined): Promise<bigint>;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* @import {RelativeTimeRecord, TimerBrand, TimerService} from '@agoric/time';
|
|
17
|
+
* @import {MsgTransfer} from '@agoric/cosmic-proto/ibc/applications/transfer/v1/tx.js';
|
|
18
|
+
*/
|
|
19
|
+
export const SECONDS_PER_MINUTE: 60n;
|
|
20
|
+
export const NANOSECONDS_PER_SECOND: 1000000000n;
|
|
21
|
+
export type TimestampHelper = Awaited<ReturnType<typeof makeTimestampHelper>>;
|
|
22
|
+
import type { TimerService } from '@agoric/time';
|
|
23
|
+
import type { TimerBrand } from '@agoric/time';
|
|
24
|
+
import type { RelativeTimeRecord } from '@agoric/time';
|
|
25
|
+
//# sourceMappingURL=time.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["time.js"],"names":[],"mappings":"AAWA;;;GAGG;AACH;IAEI;;;;;;OAMG;0EADU,OAAO,CAAC,MAAM,CAAC;EAa/B;AAhCD;;;GAGG;AAEH,qCAAsC;AACtC,iDAAqD;8BA4BvC,OAAO,CAAC,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC;kCAjCE,cAAc;gCAAd,cAAc;wCAAd,cAAc"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { E } from '@endo/far';
|
|
2
|
+
import { TimeMath } from '@agoric/time';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @import {RelativeTimeRecord, TimerBrand, TimerService} from '@agoric/time';
|
|
6
|
+
* @import {MsgTransfer} from '@agoric/cosmic-proto/ibc/applications/transfer/v1/tx.js';
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export const SECONDS_PER_MINUTE = 60n;
|
|
10
|
+
export const NANOSECONDS_PER_SECOND = 1_000_000_000n;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {TimerService} timer
|
|
14
|
+
* @param {TimerBrand} timerBrand
|
|
15
|
+
*/
|
|
16
|
+
export function makeTimestampHelper(timer, timerBrand) {
|
|
17
|
+
return harden({
|
|
18
|
+
/**
|
|
19
|
+
* Takes the current time from ChainTimerService and adds a relative
|
|
20
|
+
* time to determine a timeout timestamp in nanoseconds.
|
|
21
|
+
* Useful for {@link MsgTransfer.timeoutTimestamp}.
|
|
22
|
+
* @param {RelativeTimeRecord} [relativeTime] defaults to 5 minutes
|
|
23
|
+
* @returns {Promise<bigint>} Timeout timestamp in absolute nanoseconds since unix epoch
|
|
24
|
+
*/
|
|
25
|
+
async getTimeoutTimestampNS(relativeTime) {
|
|
26
|
+
const currentTime = await E(timer).getCurrentTimestamp();
|
|
27
|
+
const timeout =
|
|
28
|
+
relativeTime ||
|
|
29
|
+
TimeMath.coerceRelativeTimeRecord(SECONDS_PER_MINUTE * 5n, timerBrand);
|
|
30
|
+
return (
|
|
31
|
+
TimeMath.addAbsRel(currentTime, timeout).absValue *
|
|
32
|
+
NANOSECONDS_PER_SECOND
|
|
33
|
+
);
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** @typedef {Awaited<ReturnType<typeof makeTimestampHelper>>} TimestampHelper */
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
export function prepareLocalchainAccountKit(baggage: import("@agoric/swingset-liveslots").Baggage, makeRecorderKit: import("@agoric/zoe/src/contractSupport/recorder.js").MakeRecorderKit, zcf: ZCF): (account: import("@endo/exo").Guarded<{
|
|
2
|
-
getAddress(): Promise<string>;
|
|
3
|
-
deposit(payment: Payment<"nat">, optAmountShape?: Pattern): Promise<globalThis.Amount>;
|
|
4
|
-
withdraw(amount: Amount<// must be the fully synchronous maker because the kit is held in durable state
|
|
5
|
-
"nat">): Promise<globalThis.Payment>;
|
|
6
|
-
executeTx<MT extends {
|
|
7
|
-
'@type': string;
|
|
8
|
-
}[]>(messages: MT): Promise<{ [K in keyof MT]: import("@agoric/cosmic-proto/vatsafe").ResponseTo<MT[K]>; }>;
|
|
9
|
-
}>, storageNode: globalThis.StorageNode) => import("@endo/exo").GuardedKit<{
|
|
10
|
-
helper: {
|
|
11
|
-
/** @throws if this holder no longer owns the account */
|
|
12
|
-
owned(): import("@endo/exo").Guarded<{
|
|
13
|
-
getAddress(): Promise<string>;
|
|
14
|
-
deposit(payment: Payment<"nat">, optAmountShape?: Pattern): Promise<globalThis.Amount>;
|
|
15
|
-
withdraw(amount: Amount<// must be the fully synchronous maker because the kit is held in durable state
|
|
16
|
-
"nat">): Promise<globalThis.Payment>;
|
|
17
|
-
executeTx<MT extends {
|
|
18
|
-
'@type': string;
|
|
19
|
-
}[]>(messages: MT): Promise<{ [K in keyof MT]: import("@agoric/cosmic-proto/vatsafe").ResponseTo<MT[K]>; }>;
|
|
20
|
-
}>;
|
|
21
|
-
getUpdater(): import("@agoric/zoe/src/contractSupport/recorder.js").Recorder<LocalChainAccountNotification>;
|
|
22
|
-
};
|
|
23
|
-
invitationMakers: {
|
|
24
|
-
Delegate(validatorAddress: any, amount: any): Promise<Invitation<(import("@agoric/cosmic-proto/cosmos/staking/v1beta1/tx.js").MsgDelegateResponse & {
|
|
25
|
-
'@type': "/cosmos.staking.v1beta1.MsgDelegateResponse";
|
|
26
|
-
})[], undefined>>;
|
|
27
|
-
CloseAccount(): never;
|
|
28
|
-
TransferAccount(): never;
|
|
29
|
-
};
|
|
30
|
-
holder: {
|
|
31
|
-
getPublicTopics(): {
|
|
32
|
-
account: {
|
|
33
|
-
description: string;
|
|
34
|
-
subscriber: globalThis.Subscriber<LocalChainAccountNotification>;
|
|
35
|
-
storagePath: Promise<string>;
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
*
|
|
40
|
-
* @param {string} validatorAddress
|
|
41
|
-
* @param {Amount<'nat'>} ertpAmount
|
|
42
|
-
*/
|
|
43
|
-
makeDelegateInvitation(validatorAddress: string, ertpAmount: Amount<"nat">): Promise<Invitation<(import("@agoric/cosmic-proto/cosmos/staking/v1beta1/tx.js").MsgDelegateResponse & {
|
|
44
|
-
'@type': "/cosmos.staking.v1beta1.MsgDelegateResponse";
|
|
45
|
-
})[], undefined>>;
|
|
46
|
-
makeCloseAccountInvitation(): never;
|
|
47
|
-
/**
|
|
48
|
-
* Starting a transfer revokes the account holder. The associated updater
|
|
49
|
-
* will get a special notification that the account is being transferred.
|
|
50
|
-
*/
|
|
51
|
-
makeTransferAccountInvitation(): never;
|
|
52
|
-
};
|
|
53
|
-
}>;
|
|
54
|
-
export type LocalChainAccountNotification = {
|
|
55
|
-
address: string;
|
|
56
|
-
};
|
|
57
|
-
export type State = {
|
|
58
|
-
topicKit: import("@agoric/zoe/src/contractSupport/recorder.js").RecorderKit<LocalChainAccountNotification>;
|
|
59
|
-
account: import("@agoric/vats/src/localchain.js").LocalChainAccount | null;
|
|
60
|
-
};
|
|
61
|
-
export type LocalchainAccountKit = ReturnType<ReturnType<typeof prepareLocalchainAccountKit>>;
|
|
62
|
-
//# sourceMappingURL=localchainAccountKit.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"localchainAccountKit.d.ts","sourceRoot":"","sources":["localchainAccountKit.js"],"names":[],"mappings":"AAyCO,qDAJI,OAAO,4BAA4B,EAAE,OAAO,mBAC5C,OAAO,6CAA6C,EAAE,eAAe,OACrE,GAAG;;qBAKL,QAAQ,KACjB,CAAC,mBACqB,OAAO;qBAcF,OACrB,+EAA+E;IAE/E,KAFC,CAAC;;;mBAgBM,EAAE;;;QARR,wDAAwD;;;6BAzBvD,QAAQ,KACjB,CAAC,mBACqB,OAAO;6BAcF,OACrB,+EAA+E;YAE/E,KAFC,CAAC;;;2BAgBM,EAAE;;;;;;;;;;;;;;;;;;;QA6BR;;;;WAIG;iDAFQ,MAAM,cACN,MAAM,CAAC,KAAK,CAAC;;;;QAiCxB;;;WAGG;;;GAQV;;aA3Ia,MAAM;;oBAIP;IACZ,QAAY,EAAE,OAAO,6CAA6C,EAAE,WAAW,CAAC,6BAA6B,CAAC,CAAC;IAC/G,OAAW,EAAE,OAAO,gCAAgC,EAAE,iBAAiB,GAAG,IAAI,CAAC;CAC5E;mCAqIU,UAAU,CAAC,UAAU,CAAC,OAAO,2BAA2B,CAAC,CAAC"}
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
/** @file Use-object for the owner of a localchain account */
|
|
2
|
-
import { typedJson } from '@agoric/cosmic-proto/vatsafe';
|
|
3
|
-
import { AmountShape } from '@agoric/ertp';
|
|
4
|
-
import { makeTracer } from '@agoric/internal';
|
|
5
|
-
import { UnguardedHelperI } from '@agoric/internal/src/typeGuards.js';
|
|
6
|
-
import { M, prepareExoClassKit } from '@agoric/vat-data';
|
|
7
|
-
import { TopicsRecordShape } from '@agoric/zoe/src/contractSupport/index.js';
|
|
8
|
-
import { E } from '@endo/far';
|
|
9
|
-
|
|
10
|
-
const trace = makeTracer('LCAH');
|
|
11
|
-
|
|
12
|
-
const { Fail } = assert;
|
|
13
|
-
/**
|
|
14
|
-
* @typedef {object} LocalChainAccountNotification
|
|
15
|
-
* @property {string} address
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @typedef {{
|
|
20
|
-
* topicKit: import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<LocalChainAccountNotification>;
|
|
21
|
-
* account: import('@agoric/vats/src/localchain.js').LocalChainAccount | null;
|
|
22
|
-
* }} State
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
const HolderI = M.interface('holder', {
|
|
26
|
-
getPublicTopics: M.call().returns(TopicsRecordShape),
|
|
27
|
-
makeDelegateInvitation: M.call(M.string(), AmountShape).returns(M.promise()),
|
|
28
|
-
makeCloseAccountInvitation: M.call().returns(M.promise()),
|
|
29
|
-
makeTransferAccountInvitation: M.call().returns(M.promise()),
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
/** @type {{ [name: string]: [description: string, valueShape: Pattern] }} */
|
|
33
|
-
const PUBLIC_TOPICS = {
|
|
34
|
-
account: ['Account holder status', M.any()],
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @param {import('@agoric/swingset-liveslots').Baggage} baggage
|
|
39
|
-
* @param {import('@agoric/zoe/src/contractSupport/recorder.js').MakeRecorderKit} makeRecorderKit
|
|
40
|
-
* @param {ZCF} zcf
|
|
41
|
-
*/
|
|
42
|
-
export const prepareLocalchainAccountKit = (baggage, makeRecorderKit, zcf) => {
|
|
43
|
-
const makeAccountHolderKit = prepareExoClassKit(
|
|
44
|
-
baggage,
|
|
45
|
-
'Account Holder',
|
|
46
|
-
{
|
|
47
|
-
helper: UnguardedHelperI,
|
|
48
|
-
holder: HolderI,
|
|
49
|
-
invitationMakers: M.interface('invitationMakers', {
|
|
50
|
-
Delegate: HolderI.payload.methodGuards.makeDelegateInvitation,
|
|
51
|
-
CloseAccount: HolderI.payload.methodGuards.makeCloseAccountInvitation,
|
|
52
|
-
TransferAccount:
|
|
53
|
-
HolderI.payload.methodGuards.makeTransferAccountInvitation,
|
|
54
|
-
}),
|
|
55
|
-
},
|
|
56
|
-
/**
|
|
57
|
-
* @param {import('@agoric/vats/src/localchain.js').LocalChainAccount} account
|
|
58
|
-
* @param {StorageNode} storageNode
|
|
59
|
-
* @returns {State}
|
|
60
|
-
*/
|
|
61
|
-
(account, storageNode) => {
|
|
62
|
-
// must be the fully synchronous maker because the kit is held in durable state
|
|
63
|
-
// @ts-expect-error XXX Patterns
|
|
64
|
-
const topicKit = makeRecorderKit(storageNode, PUBLIC_TOPICS.account[1]);
|
|
65
|
-
|
|
66
|
-
return { account, topicKit };
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
helper: {
|
|
70
|
-
/** @throws if this holder no longer owns the account */
|
|
71
|
-
owned() {
|
|
72
|
-
const { account } = this.state;
|
|
73
|
-
if (!account) {
|
|
74
|
-
throw Fail`Using account holder after transfer`;
|
|
75
|
-
}
|
|
76
|
-
return account;
|
|
77
|
-
},
|
|
78
|
-
getUpdater() {
|
|
79
|
-
return this.state.topicKit.recorder;
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
invitationMakers: {
|
|
83
|
-
Delegate(validatorAddress, amount) {
|
|
84
|
-
return this.facets.holder.makeDelegateInvitation(
|
|
85
|
-
validatorAddress,
|
|
86
|
-
amount,
|
|
87
|
-
);
|
|
88
|
-
},
|
|
89
|
-
CloseAccount() {
|
|
90
|
-
return this.facets.holder.makeCloseAccountInvitation();
|
|
91
|
-
},
|
|
92
|
-
TransferAccount() {
|
|
93
|
-
return this.facets.holder.makeTransferAccountInvitation();
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
holder: {
|
|
97
|
-
getPublicTopics() {
|
|
98
|
-
const { topicKit } = this.state;
|
|
99
|
-
return harden({
|
|
100
|
-
account: {
|
|
101
|
-
description: PUBLIC_TOPICS.account[0],
|
|
102
|
-
subscriber: topicKit.subscriber,
|
|
103
|
-
storagePath: topicKit.recorder.getStoragePath(),
|
|
104
|
-
},
|
|
105
|
-
});
|
|
106
|
-
},
|
|
107
|
-
/**
|
|
108
|
-
*
|
|
109
|
-
* @param {string} validatorAddress
|
|
110
|
-
* @param {Amount<'nat'>} ertpAmount
|
|
111
|
-
*/
|
|
112
|
-
async makeDelegateInvitation(validatorAddress, ertpAmount) {
|
|
113
|
-
trace('makeDelegateInvitation', validatorAddress, ertpAmount);
|
|
114
|
-
|
|
115
|
-
// FIXME get values from proposal or args
|
|
116
|
-
// FIXME brand handling and amount scaling
|
|
117
|
-
const amount = {
|
|
118
|
-
amount: String(ertpAmount.value),
|
|
119
|
-
denom: 'ubld',
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
return zcf.makeInvitation(async seat => {
|
|
123
|
-
// TODO should it allow delegating more BLD?
|
|
124
|
-
seat.exit();
|
|
125
|
-
const lca = this.facets.helper.owned();
|
|
126
|
-
trace('lca', lca);
|
|
127
|
-
const delegatorAddress = await E(lca).getAddress();
|
|
128
|
-
trace('delegatorAddress', delegatorAddress);
|
|
129
|
-
const result = await E(lca).executeTx([
|
|
130
|
-
typedJson('/cosmos.staking.v1beta1.MsgDelegate', {
|
|
131
|
-
amount,
|
|
132
|
-
validatorAddress,
|
|
133
|
-
delegatorAddress,
|
|
134
|
-
}),
|
|
135
|
-
]);
|
|
136
|
-
trace('got result', result);
|
|
137
|
-
return result;
|
|
138
|
-
}, 'Delegate');
|
|
139
|
-
},
|
|
140
|
-
makeCloseAccountInvitation() {
|
|
141
|
-
throw Error('not yet implemented');
|
|
142
|
-
},
|
|
143
|
-
/**
|
|
144
|
-
* Starting a transfer revokes the account holder. The associated updater
|
|
145
|
-
* will get a special notification that the account is being transferred.
|
|
146
|
-
*/
|
|
147
|
-
makeTransferAccountInvitation() {
|
|
148
|
-
throw Error('not yet implemented');
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
);
|
|
153
|
-
return makeAccountHolderKit;
|
|
154
|
-
};
|
|
155
|
-
/** @typedef {ReturnType<ReturnType<typeof prepareLocalchainAccountKit>>} LocalchainAccountKit */
|