-
Notifications
You must be signed in to change notification settings - Fork 207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
9796 continuing ica #10023
Merged
Merged
9796 continuing ica #10023
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
138 changes: 138 additions & 0 deletions
138
packages/orchestration/src/examples/staking-combinations.contract.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/** | ||
* @file This contract demonstrates the continuing invitation pattern with async | ||
* flows. | ||
* | ||
* The primary offer result is a power for invitation makers that can perform | ||
* actions with an ICA account. | ||
*/ | ||
import { AmountShape } from '@agoric/ertp'; | ||
import { VowShape } from '@agoric/vow'; | ||
import { M } from '@endo/patterns'; | ||
import { prepareCombineInvitationMakers } from '../exos/combine-invitation-makers.js'; | ||
import { CosmosOrchestrationInvitationMakersInterface } from '../exos/cosmos-orchestration-account.js'; | ||
import { withOrchestration } from '../utils/start-helper.js'; | ||
import * as flows from './staking-combinations.flows.js'; | ||
|
||
/** | ||
* @import {GuestInterface} from '@agoric/async-flow'; | ||
* @import {Delegation} from '@agoric/cosmic-proto/cosmos/staking/v1beta1/staking.js'; | ||
* @import {ContinuingOfferResult} from '@agoric/smart-wallet/src/types.js'; | ||
* @import {TimerService} from '@agoric/time'; | ||
* @import {LocalChain} from '@agoric/vats/src/localchain.js'; | ||
* @import {NameHub} from '@agoric/vats'; | ||
* @import {Vow} from '@agoric/vow'; | ||
* @import {Remote} from '@agoric/internal'; | ||
* @import {Zone} from '@agoric/zone'; | ||
* @import {CosmosInterchainService} from '../exos/cosmos-interchain-service.js'; | ||
* @import {OrchestrationTools} from '../utils/start-helper.js'; | ||
* @import {CosmosOrchestrationAccount} from '../exos/cosmos-orchestration-account.js'; | ||
*/ | ||
|
||
const emptyOfferShape = harden({ | ||
// Nothing to give; the funds are deposited offline | ||
give: {}, | ||
want: {}, // UNTIL https://github.com/Agoric/agoric-sdk/issues/2230 | ||
exit: M.any(), | ||
}); | ||
|
||
/** | ||
* Orchestration contract to be wrapped by withOrchestration for Zoe. | ||
* | ||
* @param {ZCF} zcf | ||
* @param {{ | ||
* agoricNames: Remote<NameHub>; | ||
* localchain: Remote<LocalChain>; | ||
* orchestrationService: Remote<CosmosInterchainService>; | ||
* storageNode: Remote<StorageNode>; | ||
* marshaller: Marshaller; | ||
* timerService: Remote<TimerService>; | ||
* }} privateArgs | ||
* @param {Zone} zone | ||
* @param {OrchestrationTools} tools | ||
*/ | ||
const contract = async ( | ||
zcf, | ||
privateArgs, | ||
zone, | ||
{ orchestrateAll, vowTools }, | ||
) => { | ||
const ExtraInvitationMakerInterface = M.interface('', { | ||
DepositAndDelegate: M.call(M.array()).returns(VowShape), | ||
UndelegateAndTransfer: M.call(M.array()).returns(VowShape), | ||
}); | ||
/** @type {any} XXX async membrane */ | ||
const makeExtraInvitationMaker = zone.exoClass( | ||
'ContinuingInvitationExampleInvitationMakers', | ||
ExtraInvitationMakerInterface, | ||
/** @param {GuestInterface<CosmosOrchestrationAccount>} account */ | ||
account => { | ||
return { account }; | ||
}, | ||
{ | ||
DepositAndDelegate() { | ||
const { account } = this.state; | ||
|
||
const invP = zcf.makeInvitation( | ||
(seat, validatorAddr, amountArg) => | ||
// eslint-disable-next-line no-use-before-define -- defined by orchestrateAll, necessarily after this | ||
orchFns.depositAndDelegate(account, seat, validatorAddr, amountArg), | ||
'Deposit and delegate', | ||
undefined, | ||
{ | ||
give: { | ||
Stake: AmountShape, | ||
}, | ||
}, | ||
); | ||
|
||
return vowTools.watch(invP); | ||
}, | ||
/** | ||
* @param {Omit<Delegation, 'delegatorAddress'>[]} delegations | ||
*/ | ||
UndelegateAndTransfer(delegations) { | ||
const { account } = this.state; | ||
|
||
const invP = zcf.makeInvitation( | ||
// eslint-disable-next-line no-use-before-define -- defined by orchestrateAll, necessarily after this | ||
() => orchFns.undelegateAndTransfer(account, delegations), | ||
'Undelegate and transfer', | ||
undefined, | ||
emptyOfferShape, | ||
); | ||
|
||
return vowTools.watch(invP); | ||
}, | ||
}, | ||
); | ||
|
||
/** @type {any} XXX async membrane */ | ||
const makeCombineInvitationMakers = prepareCombineInvitationMakers( | ||
zone, | ||
CosmosOrchestrationInvitationMakersInterface, | ||
ExtraInvitationMakerInterface, | ||
); | ||
|
||
const orchFns = orchestrateAll(flows, { | ||
makeCombineInvitationMakers, | ||
makeExtraInvitationMaker, | ||
flows, | ||
zcf, | ||
}); | ||
|
||
const publicFacet = zone.exo('publicFacet', undefined, { | ||
makeAccount() { | ||
return zcf.makeInvitation( | ||
orchFns.makeAccount, | ||
'Make an ICA account', | ||
undefined, | ||
emptyOfferShape, | ||
); | ||
}, | ||
}); | ||
|
||
return harden({ publicFacet }); | ||
}; | ||
|
||
export const start = withOrchestration(contract); | ||
harden(start); |
83 changes: 83 additions & 0 deletions
83
packages/orchestration/src/examples/staking-combinations.flows.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* @import {GuestInterface} from '@agoric/async-flow'; | ||
* @import {Orchestrator, OrchestrationFlow, OrchestrationAccount, OrchestrationAccountI, StakingAccountActions, AmountArg, CosmosValidatorAddress} from '../types.js' | ||
* @import {ContinuingOfferResult, InvitationMakers} from '@agoric/smart-wallet/src/types.js'; | ||
* @import {MakeCombineInvitationMakers} from '../exos/combine-invitation-makers.js'; | ||
* @import {Delegation} from '@agoric/cosmic-proto/cosmos/staking/v1beta1/staking.js'; | ||
* @import {CosmosOrchestrationAccount} from '../exos/cosmos-orchestration-account.js'; | ||
*/ | ||
|
||
/** | ||
* @satisfies {OrchestrationFlow} | ||
* @param {Orchestrator} orch | ||
* @param {{ | ||
* makeCombineInvitationMakers: MakeCombineInvitationMakers; | ||
* makeExtraInvitationMaker: (account: any) => InvitationMakers; | ||
* }} ctx | ||
* @param {ZCFSeat} _seat | ||
* @param {{ chainName: string }} offerArgs | ||
* @returns {Promise<ContinuingOfferResult>} | ||
*/ | ||
export const makeAccount = async (orch, ctx, _seat, { chainName }) => { | ||
const chain = await orch.getChain(chainName); | ||
const account = await chain.makeAccount(); | ||
|
||
const extraMakers = ctx.makeExtraInvitationMaker(account); | ||
|
||
/** @type {ContinuingOfferResult} */ | ||
const result = await account.asContinuingOffer(); | ||
|
||
return { | ||
...result, | ||
invitationMakers: ctx.makeCombineInvitationMakers( | ||
extraMakers, | ||
result.invitationMakers, | ||
), | ||
}; | ||
}; | ||
harden(makeAccount); | ||
|
||
/** | ||
* @satisfies {OrchestrationFlow} | ||
* @param {Orchestrator} orch | ||
* @param {object} ctx | ||
* @param {GuestInterface<CosmosOrchestrationAccount>} account | ||
* @param {ZCFSeat} seat | ||
* @param {CosmosValidatorAddress} validator | ||
* @param {AmountArg} amount | ||
* @returns {Promise<string>} | ||
*/ | ||
export const depositAndDelegate = async ( | ||
orch, | ||
ctx, | ||
account, | ||
seat, | ||
validator, | ||
amount, | ||
) => { | ||
console.log('depositAndDelegate', account, seat, validator, amount); | ||
// TODO deposit the amount | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ticket # would be nice, but thanks for including this! |
||
await account.delegate(validator, amount); | ||
return 'guest depositAndDelegate complete'; | ||
}; | ||
harden(depositAndDelegate); | ||
|
||
/** | ||
* @satisfies {OrchestrationFlow} | ||
* @param {Orchestrator} orch | ||
* @param {object} ctx | ||
* @param {GuestInterface<CosmosOrchestrationAccount>} account | ||
* @param {Omit<Delegation, 'delegatorAddress'>[]} delegations | ||
* @returns {Promise<string>} | ||
*/ | ||
export const undelegateAndTransfer = async ( | ||
orch, | ||
ctx, | ||
account, | ||
delegations, | ||
) => { | ||
await account.undelegate(delegations); | ||
// TODO transfer something | ||
return 'guest undelegateAndTransfer complete'; | ||
}; | ||
harden(undelegateAndTransfer); |
116 changes: 116 additions & 0 deletions
116
packages/orchestration/test/examples/snapshots/staking-combinations.test.ts.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# Snapshot report for `test/examples/staking-combinations.test.ts` | ||
|
||
The actual snapshot is saved in `staking-combinations.test.ts.snap`. | ||
|
||
Generated by [AVA](https://avajs.dev). | ||
|
||
## start | ||
|
||
> contract baggage after start | ||
|
||
{ | ||
'Durable Publish Kit_kindHandle': 'Alleged: kind', | ||
Recorder_kindHandle: 'Alleged: kind', | ||
asyncFlow: { | ||
AdminAsyncFlow_kindHandle: 'Alleged: kind', | ||
AdminAsyncFlow_singleton: 'Alleged: AdminAsyncFlow', | ||
Bijection_kindHandle: 'Alleged: kind', | ||
FunctionUnwrapper_kindHandle: 'Alleged: kind', | ||
FunctionUnwrapper_singleton: 'Alleged: FunctionUnwrapper', | ||
LogStore_kindHandle: 'Alleged: kind', | ||
StateUnwrapper_kindHandle: 'Alleged: kind', | ||
asyncFuncEagerWakers: [], | ||
asyncFuncFailures: {}, | ||
flowForOutcomeVow: {}, | ||
unwrapMap: 'Alleged: weakMapStore', | ||
}, | ||
contract: { | ||
CombinedInvitationMakers_kindHandle: 'Alleged: kind', | ||
ContinuingInvitationExampleInvitationMakers_kindHandle: 'Alleged: kind', | ||
orchestration: { | ||
depositAndDelegate: { | ||
asyncFlow_kindHandle: 'Alleged: kind', | ||
endowments: { | ||
0: { | ||
flows: { | ||
depositAndDelegate_kindHandle: 'Alleged: kind', | ||
depositAndDelegate_singleton: 'Alleged: depositAndDelegate', | ||
makeAccount_kindHandle: 'Alleged: kind', | ||
makeAccount_singleton: 'Alleged: makeAccount', | ||
undelegateAndTransfer_kindHandle: 'Alleged: kind', | ||
undelegateAndTransfer_singleton: 'Alleged: undelegateAndTransfer', | ||
}, | ||
makeCombineInvitationMakers_kindHandle: 'Alleged: kind', | ||
makeCombineInvitationMakers_singleton: 'Alleged: makeCombineInvitationMakers', | ||
makeExtraInvitationMaker_kindHandle: 'Alleged: kind', | ||
makeExtraInvitationMaker_singleton: 'Alleged: makeExtraInvitationMaker', | ||
}, | ||
}, | ||
}, | ||
makeAccount: { | ||
asyncFlow_kindHandle: 'Alleged: kind', | ||
endowments: { | ||
0: { | ||
flows: { | ||
depositAndDelegate_kindHandle: 'Alleged: kind', | ||
depositAndDelegate_singleton: 'Alleged: depositAndDelegate', | ||
makeAccount_kindHandle: 'Alleged: kind', | ||
makeAccount_singleton: 'Alleged: makeAccount', | ||
undelegateAndTransfer_kindHandle: 'Alleged: kind', | ||
undelegateAndTransfer_singleton: 'Alleged: undelegateAndTransfer', | ||
}, | ||
makeCombineInvitationMakers_kindHandle: 'Alleged: kind', | ||
makeCombineInvitationMakers_singleton: 'Alleged: makeCombineInvitationMakers', | ||
makeExtraInvitationMaker_kindHandle: 'Alleged: kind', | ||
makeExtraInvitationMaker_singleton: 'Alleged: makeExtraInvitationMaker', | ||
}, | ||
}, | ||
}, | ||
undelegateAndTransfer: { | ||
asyncFlow_kindHandle: 'Alleged: kind', | ||
endowments: { | ||
0: { | ||
flows: { | ||
depositAndDelegate_kindHandle: 'Alleged: kind', | ||
depositAndDelegate_singleton: 'Alleged: depositAndDelegate', | ||
makeAccount_kindHandle: 'Alleged: kind', | ||
makeAccount_singleton: 'Alleged: makeAccount', | ||
undelegateAndTransfer_kindHandle: 'Alleged: kind', | ||
undelegateAndTransfer_singleton: 'Alleged: undelegateAndTransfer', | ||
}, | ||
makeCombineInvitationMakers_kindHandle: 'Alleged: kind', | ||
makeCombineInvitationMakers_singleton: 'Alleged: makeCombineInvitationMakers', | ||
makeExtraInvitationMaker_kindHandle: 'Alleged: kind', | ||
makeExtraInvitationMaker_singleton: 'Alleged: makeExtraInvitationMaker', | ||
}, | ||
}, | ||
}, | ||
}, | ||
publicFacet_kindHandle: 'Alleged: kind', | ||
publicFacet_singleton: 'Alleged: publicFacet', | ||
}, | ||
orchestration: { | ||
'Cosmos Orchestration Account Holder_kindHandle': 'Alleged: kind', | ||
'Local Orchestration Account Kit_kindHandle': 'Alleged: kind', | ||
LocalChainFacade_kindHandle: 'Alleged: kind', | ||
Orchestrator_kindHandle: 'Alleged: kind', | ||
RemoteChainFacade_kindHandle: 'Alleged: kind', | ||
chainName: { | ||
osmosis: 'Alleged: RemoteChainFacade public', | ||
}, | ||
ibcTools: { | ||
IBCTransferSenderKit_kindHandle: 'Alleged: kind', | ||
ibcResultWatcher_kindHandle: 'Alleged: kind', | ||
ibcResultWatcher_singleton: 'Alleged: ibcResultWatcher', | ||
}, | ||
packetTools: { | ||
PacketToolsKit_kindHandle: 'Alleged: kind', | ||
}, | ||
}, | ||
vows: { | ||
PromiseWatcher_kindHandle: 'Alleged: kind', | ||
VowInternalsKit_kindHandle: 'Alleged: kind', | ||
WatchUtils_kindHandle: 'Alleged: kind', | ||
}, | ||
zoe: {}, | ||
} |
Binary file added
BIN
+1.43 KB
packages/orchestration/test/examples/snapshots/staking-combinations.test.ts.snap
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking on this more, I don't think we need
vowTools.watch
here. We can expect the promise for an Invitation to resolve promptly - it's just the offer handler that needs to return a vow.If we feel we should return a vow here, we should also make this change in the orchAccount exos. Currently, we're always returning a promise.
The only instance coming to mind where it'd be helpful to return a vow is if a developer wanted to call an
invitationMaker
from inside a flow - it'd need to be a vow to cross the membrane. I'm not sure how common this will be - we don't have any examples that need this currently.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's what motivated the vow: an earlier version of this branch was calling between guest fns. But definitely not needed now. Thanks for pointing it out.
I believe "promptly" means in "in the same run".
zcf.makeInvitation
calls out to another vat so I don't think it can be in the same run.agoric-sdk/packages/zoe/src/contractFacet/zcfZygote.js
Lines 314 to 316 in daff9eb