-
Notifications
You must be signed in to change notification settings - Fork 206
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
9207 orchestrator stub #9208
Merged
Merged
9207 orchestrator stub #9208
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
15c6a96
lint: ignore codegen
turadg 5a3c76b
chore(deps): bump typedoc to 0.25.13
turadg 7bd1978
build: export cosmos/staking/v1beta1/staking
turadg 54d18d9
refactor: OrchestrationService in service.js
turadg 1e054ac
feat: stub Orchestration API
turadg 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
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,2 @@ | ||
# also ignored in packages/cosmic-proto/.eslintignore, but IDE's pick up the root config | ||
packages/cosmic-proto/src/codegen/ |
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
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
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 |
---|---|---|
|
@@ -2,4 +2,5 @@ node_modules/ | |
dist/ | ||
main/ | ||
module/ | ||
coverage/ | ||
coverage/ | ||
src/codegen/ |
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
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
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
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
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
102 changes: 102 additions & 0 deletions
102
packages/orchestration/src/contracts/swapExample.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,102 @@ | ||
// @ts-check | ||
import { Fail } from '@agoric/assert'; | ||
import { AmountMath, AmountShape } from '@agoric/ertp'; | ||
import { E, Far } from '@endo/far'; | ||
import { M } from '@endo/patterns'; | ||
import { makeOrchestrationFacade } from '../facade.js'; | ||
import { orcUtils } from '../utils/orc.js'; | ||
|
||
/** | ||
* @import {Orchestrator, ChainAccount, CosmosValidatorAddress} from '../types.js' | ||
* @import {TimerService} from '@agoric/time'; | ||
* @import {ERef} from '@endo/far' | ||
* @import {OrchestrationService} from '../service.js'; | ||
* @import {Zone} from '@agoric/zone'; | ||
*/ | ||
|
||
/** | ||
* @param {ZCF} zcf | ||
* @param {{ | ||
* orchestrationService: ERef<OrchestrationService>; | ||
* storageNode: ERef<StorageNode>; | ||
* timerService: ERef<TimerService>; | ||
* zone: Zone; | ||
* }} privateArgs | ||
*/ | ||
export const start = async (zcf, privateArgs) => { | ||
const { orchestrationService, storageNode, timerService, zone } = privateArgs; | ||
|
||
const { orchestrate } = makeOrchestrationFacade({ | ||
zone, | ||
timerService, | ||
zcf, | ||
storageNode, | ||
orchestrationService, | ||
}); | ||
|
||
/** deprecated historical example */ | ||
/** @type {OfferHandler} */ | ||
const swapAndStakeHandler = orchestrate( | ||
'LSTTia', | ||
{ zcf }, | ||
// eslint-disable-next-line no-shadow -- this `zcf` is enclosed in a membrane | ||
async (/** @type {Orchestrator} */ orch, { zcf }, seat, offerArgs) => { | ||
const { give } = seat.getProposal(); | ||
!AmountMath.isEmpty(give.USDC.value) || Fail`Must provide USDC.`; | ||
|
||
const celestia = await orch.getChain('celestia'); | ||
const agoric = await orch.getChain('agoric'); | ||
|
||
const [celestiaAccount, localAccount] = await Promise.all([ | ||
celestia.createAccount(), | ||
agoric.createAccount(), | ||
]); | ||
|
||
const tiaAddress = await celestiaAccount.getChainAddress(); | ||
|
||
// deposit funds from user seat to LocalChainAccount | ||
const seatKit = zcf.makeEmptySeatKit(); | ||
zcf.atomicRearrange(harden([[seat, seatKit.zcfSeat, give]])); | ||
// seat.exit() // exit user seat now, or later? | ||
const payment = await E(seatKit.userSeat).getPayout('USDC'); | ||
await localAccount.deposit(payment); | ||
|
||
// build swap instructions with orcUtils library | ||
const transferMsg = orcUtils.makeOsmosisSwap({ | ||
destChain: 'celestia', | ||
destAddress: tiaAddress, | ||
amountIn: give.USDC, | ||
brandOut: offerArgs.staked.brand, | ||
slippage: 0.03, | ||
}); | ||
|
||
await localAccount | ||
.transferSteps(give.USDC, transferMsg) | ||
.then(_txResult => | ||
celestiaAccount.delegate(offerArgs.validator, offerArgs.staked), | ||
) | ||
.catch(e => console.error(e)); | ||
|
||
// XXX close localAccount? | ||
return celestiaAccount; // should be continuing inv since this is an offer? | ||
}, | ||
); | ||
|
||
const makeSwapAndStakeInvitation = () => | ||
zcf.makeInvitation( | ||
swapAndStakeHandler, | ||
'Swap for TIA and stake', | ||
undefined, | ||
harden({ | ||
give: { USDC: AmountShape }, | ||
want: {}, // XXX ChainAccount Ownable? | ||
exit: M.any(), | ||
}), | ||
); | ||
|
||
const publicFacet = Far('SwapAndStake Public Facet', { | ||
makeSwapAndStakeInvitation, | ||
}); | ||
|
||
return harden({ publicFacet }); | ||
}; |
87 changes: 87 additions & 0 deletions
87
packages/orchestration/src/contracts/unbondExample.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,87 @@ | ||
// @ts-check | ||
import { Fail } from '@agoric/assert'; | ||
import { AmountMath, AmountShape } from '@agoric/ertp'; | ||
import { Far } from '@endo/far'; | ||
import { M } from '@endo/patterns'; | ||
import { makeOrchestrationFacade } from '../facade.js'; | ||
|
||
/** | ||
* @import {Orchestrator, ChainAccount, CosmosValidatorAddress} from '../types.js' | ||
* @import {TimerService} from '@agoric/time'; | ||
* @import {ERef} from '@endo/far' | ||
* @import {OrchestrationService} from '../service.js'; | ||
* @import {Zone} from '@agoric/zone'; | ||
*/ | ||
|
||
/** | ||
* @param {ZCF} zcf | ||
* @param {{ | ||
* orchestrationService: ERef<OrchestrationService>; | ||
* storageNode: ERef<StorageNode>; | ||
* timerService: ERef<TimerService>; | ||
* zone: Zone; | ||
* }} privateArgs | ||
*/ | ||
export const start = async (zcf, privateArgs) => { | ||
const { orchestrationService, storageNode, timerService, zone } = privateArgs; | ||
|
||
const { orchestrate } = makeOrchestrationFacade({ | ||
zone, | ||
timerService, | ||
zcf, | ||
storageNode, | ||
orchestrationService, | ||
}); | ||
|
||
/** @type {OfferHandler} */ | ||
const unbondAndLiquidStake = orchestrate( | ||
'LSTTia', | ||
{ zcf }, | ||
// eslint-disable-next-line no-shadow -- this `zcf` is enclosed in a membrane | ||
async (/** @type {Orchestrator} */ orch, { zcf }, seat, _offerArgs) => { | ||
console.log('zcf within the membrane', zcf); | ||
const { give } = seat.getProposal(); | ||
!AmountMath.isEmpty(give.USDC.value) || Fail`Must provide USDC.`; | ||
|
||
// We would actually alreaady have the account from the orchestrator | ||
// ??? could these be passed in? It would reduce the size of this handler, | ||
// keeping it focused on long-running operations. | ||
const celestia = await orch.getChain('celestia'); | ||
const celestiaAccount = await celestia.createAccount(); | ||
|
||
const delegations = await celestiaAccount.getDelegations(); | ||
const [undelegation] = await celestiaAccount.undelegate(delegations); | ||
|
||
// wait for the undelegations to be complete (may take weeks) | ||
await undelegation.completion; | ||
Comment on lines
+53
to
+56
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. 👍 highlighting this change for other reviewers |
||
|
||
// ??? should this be synchronous? depends on how names are resolved. | ||
const stride = await orch.getChain('stride'); | ||
const strideAccount = await stride.createAccount(); | ||
|
||
// TODO the `TIA` string actually needs to be the Brand from AgoricNames | ||
const tiaAmt = await celestiaAccount.getBalance('TIA'); | ||
await celestiaAccount.transfer(tiaAmt, strideAccount.getChainAddress()); | ||
|
||
await strideAccount.liquidStake(tiaAmt); | ||
}, | ||
); | ||
|
||
const makeUnbondAndLiquidStakeInvitation = () => | ||
zcf.makeInvitation( | ||
unbondAndLiquidStake, | ||
'Unbond and liquid stake', | ||
undefined, | ||
harden({ | ||
give: { USDC: AmountShape }, | ||
want: {}, // XXX ChainAccount Ownable? | ||
exit: M.any(), | ||
}), | ||
); | ||
|
||
const publicFacet = Far('SwapAndStake Public Facet', { | ||
makeUnbondAndLiquidStakeInvitation, | ||
}); | ||
|
||
return harden({ publicFacet }); | ||
}; |
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,47 @@ | ||
// @ts-check | ||
/** @file Orchestration service */ | ||
|
||
/** | ||
* @import {Zone} from '@agoric/zone'; | ||
* @import {TimerService} from '@agoric/time'; | ||
* @import {OrchestrationService} from './service.js'; | ||
* @import {OrchestrationHandlerMaker} from './types.js'; | ||
*/ | ||
|
||
/** | ||
* | ||
* @param {{ | ||
* zone: Zone; | ||
* timerService: ERef<TimerService>; | ||
* zcf: ERef<ZCF>; | ||
* storageNode: ERef<StorageNode>; | ||
* orchestrationService: ERef<OrchestrationService>; | ||
* }} powers | ||
*/ | ||
export const makeOrchestrationFacade = ({ | ||
zone, | ||
timerService, | ||
zcf, | ||
storageNode, | ||
orchestrationService, | ||
}) => { | ||
console.log('makeOrchestrationFacade got', { | ||
zone, | ||
timerService, | ||
zcf, | ||
storageNode, | ||
orchestrationService, | ||
}); | ||
|
||
return { | ||
/** | ||
* @type {OrchestrationHandlerMaker} | ||
*/ | ||
orchestrate(durableName, ctx, fn) { | ||
console.log('orchestrate got', durableName, ctx, fn); | ||
throw new Error('Not yet implemented'); | ||
}, | ||
}; | ||
}; | ||
harden(makeOrchestrationFacade); | ||
/** @typedef {ReturnType<typeof makeOrchestrationFacade>} OrchestrationFacade */ |
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
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.
Per feedback in #9198 it's maybe best to move these to
/tools
or/examples
. I am planning to move the current contents of/contracts
to/examples
in that PR to avoid potential confusionThere 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 whatever we do should be consistent across the repository. I'm going to leave this for a later PR in which we execute a plan wholistically