Skip to content

Commit

Permalink
chore: update other examples to use withOrchestration
Browse files Browse the repository at this point in the history
  • Loading branch information
dtribble committed Jul 6, 2024
1 parent 2ece7a9 commit b46f590
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 99 deletions.
89 changes: 37 additions & 52 deletions packages/orchestration/src/examples/swapExample.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Far } from '@endo/far';
import { deeplyFulfilled } from '@endo/marshal';
import { M, objectMap } from '@endo/patterns';
import { orcUtils } from '../utils/orc.js';
import { provideOrchestration } from '../utils/start-helper.js';
import { withOrchestration } from '../utils/start-helper.js';

/**
* @import {Orchestrator, IcaAccount, CosmosValidatorAddress} from '../types.js'
Expand Down Expand Up @@ -101,55 +101,40 @@ export const makeNatAmountShape = (brand, min) =>
* }} privateArgs
* @param {Baggage} baggage
*/
export const start = async (zcf, privateArgs, baggage) => {
const {
agoricNames,
localchain,
orchestrationService,
storageNode,
timerService,
marshaller,
} = privateArgs;

const { orchestrate } = provideOrchestration(
export const start = withOrchestration(
async (
zcf,
baggage,
{
agoricNames,
localchain,
orchestrationService,
storageNode,
timerService,
},
marshaller,
);

const { brands } = zcf.getTerms();

/** deprecated historical example */
/**
* @type {OfferHandler<
* unknown,
* { staked: Amount<'nat'>; validator: CosmosValidatorAddress }
* >}
*/
const swapAndStakeHandler = orchestrate('LSTTia', { zcf }, stackAndSwapFn);

const makeSwapAndStakeInvitation = () =>
zcf.makeInvitation(
swapAndStakeHandler,
'Swap for TIA and stake',
undefined,
harden({
give: { Stable: makeNatAmountShape(brands.Stable, 1n) },
want: {}, // XXX ChainAccount Ownable?
exit: M.any(),
}),
);

const publicFacet = Far('SwapAndStake Public Facet', {
makeSwapAndStakeInvitation,
});

return harden({ publicFacet });
};
privateArgs,
zone,
{ vowTools, orchestrate, chainHub, zoeTools },
) => {
const { brands } = zcf.getTerms();

/** deprecated historical example */
/**
* @type {OfferHandler<
* unknown,
* { staked: Amount<'nat'>; validator: CosmosValidatorAddress }
* >}
*/
const swapAndStakeHandler = orchestrate('LSTTia', { zcf }, stackAndSwapFn);

const makeSwapAndStakeInvitation = () =>
zcf.makeInvitation(
swapAndStakeHandler,
'Swap for TIA and stake',
undefined,
harden({
give: { Stable: makeNatAmountShape(brands.Stable, 1n) },
want: {}, // XXX ChainAccount Ownable?
exit: M.any(),
}),
);

const publicFacet = Far('SwapAndStake Public Facet', {
makeSwapAndStakeInvitation,
});

return harden({ publicFacet });
},
);
74 changes: 27 additions & 47 deletions packages/orchestration/src/examples/unbondExample.contract.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Far } from '@endo/far';
import { M } from '@endo/patterns';
import { provideOrchestration } from '../utils/start-helper.js';
import { withOrchestration } from '../utils/start-helper.js';

/**
* @import {Orchestrator, IcaAccount, CosmosValidatorAddress} from '../types.js'
Expand Down Expand Up @@ -54,52 +54,32 @@ const unbondAndLiquidStakeFn = async (orch, { zcf }, _seat, _offerArgs) => {
* }} privateArgs
* @param {Baggage} baggage
*/
export const start = async (zcf, privateArgs, baggage) => {
const {
agoricNames,
localchain,
orchestrationService,
storageNode,
marshaller,
timerService,
} = privateArgs;

const { orchestrate } = provideOrchestration(
zcf,
baggage,
{
agoricNames,
localchain,
orchestrationService,
storageNode,
timerService,
},
marshaller,
);

/** @type {OfferHandler} */
const unbondAndLiquidStake = orchestrate(
'LSTTia',
{ zcf },
unbondAndLiquidStakeFn,
);

const makeUnbondAndLiquidStakeInvitation = () =>
zcf.makeInvitation(
unbondAndLiquidStake,
'Unbond and liquid stake',
undefined,
harden({
// Nothing to give; the funds come from undelegating
give: {},
want: {}, // XXX ChainAccount Ownable?
exit: M.any(),
}),
export const start = withOrchestration(
async (zcf, privateArgs, zone, { orchestrate }) => {
/** @type {OfferHandler} */
const unbondAndLiquidStake = orchestrate(
'LSTTia',
{ zcf },
unbondAndLiquidStakeFn,
);

const publicFacet = Far('SwapAndStake Public Facet', {
makeUnbondAndLiquidStakeInvitation,
});
const makeUnbondAndLiquidStakeInvitation = () =>
zcf.makeInvitation(
unbondAndLiquidStake,
'Unbond and liquid stake',
undefined,
harden({
// Nothing to give; the funds come from undelegating
give: {},
want: {}, // XXX ChainAccount Ownable?
exit: M.any(),
}),
);

return harden({ publicFacet });
};
const publicFacet = Far('SwapAndStake Public Facet', {
makeUnbondAndLiquidStakeInvitation,
});

return harden({ publicFacet });
},
);

0 comments on commit b46f590

Please sign in to comment.