-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- A contract that allows calls to make an OrchestrationAccount, and subsequently schedule a restake (claim and stake rewards) on an interval. - Leverages existing invitation makers like Delegate and combines them with Restake and CancelRestake.
- Loading branch information
1 parent
bc558d0
commit 57927cb
Showing
4 changed files
with
578 additions
and
0 deletions.
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,95 @@ | ||
import { InvitationShape } from '@agoric/zoe/src/typeGuards.js'; | ||
import { M } from '@endo/patterns'; | ||
import { withOrchestration } from '../utils/start-helper.js'; | ||
import * as flows from './restake.flows.js'; | ||
import { | ||
prepareRestakeHolderKit, | ||
prepareRestakeWaker, | ||
restakeInvitaitonGuardShape, | ||
} from './restake.kit.js'; | ||
import { prepareCombineInvitationMakers } from '../exos/combine-invitation-makers.js'; | ||
|
||
/** | ||
* @import {Zone} from '@agoric/zone'; | ||
* @import {OrchestrationPowers} from '../utils/start-helper.js'; | ||
* @import {OrchestrationTools} from '../utils/start-helper.js'; | ||
*/ | ||
|
||
/** | ||
* XXX consider moving to privateArgs / creatorFacet, as terms are immutable | ||
* | ||
* @typedef {{ | ||
* minimumDelay: bigint; | ||
* minimumInterval: bigint; | ||
* }} RestakeContractTerms | ||
*/ | ||
|
||
/** | ||
* A contract that allows calls to make an OrchestrationAccount, and | ||
* subsequently schedule a restake (claim and stake rewards) on an interval. | ||
* | ||
* Leverages existing invitation makers like Delegate and combines them with | ||
* Restake and CancelRestake. | ||
* | ||
* @param {ZCF<RestakeContractTerms>} zcf | ||
* @param {OrchestrationPowers & { | ||
* marshaller: Marshaller; | ||
* }} privateArgs | ||
* @param {Zone} zone | ||
* @param {OrchestrationTools} tools | ||
*/ | ||
const contract = async ( | ||
zcf, | ||
{ timerService }, | ||
zone, | ||
{ orchestrateAll, vowTools }, | ||
) => { | ||
const makeRestakeWaker = prepareRestakeWaker( | ||
zone.subZone('restakeWaker'), | ||
vowTools, | ||
); | ||
const makeCombineInvitationMakers = prepareCombineInvitationMakers( | ||
zone, | ||
restakeInvitaitonGuardShape, | ||
); | ||
|
||
const { minimumDelay, minimumInterval } = zcf.getTerms(); | ||
|
||
const makeRestakeHolderKit = prepareRestakeHolderKit( | ||
zone.subZone('restakeHolder'), | ||
{ | ||
vowTools, | ||
zcf, | ||
timer: timerService, | ||
makeRestakeWaker, | ||
params: harden({ minimumDelay, minimumInterval }), | ||
}, | ||
); | ||
|
||
const orchFns = orchestrateAll(flows, { | ||
makeRestakeHolderKit, | ||
makeCombineInvitationMakers, | ||
}); | ||
|
||
const publicFacet = zone.exo( | ||
'Restake Public Facet', | ||
M.interface('Restake PF', { | ||
makeRestakeAccountInvitation: M.callWhen().returns(InvitationShape), | ||
}), | ||
{ | ||
makeRestakeAccountInvitation() { | ||
return zcf.makeInvitation( | ||
orchFns.makeRestakeAccount, | ||
'Make a Restake Account', | ||
); | ||
}, | ||
}, | ||
); | ||
|
||
return { publicFacet }; | ||
}; | ||
|
||
export const start = withOrchestration(contract); | ||
harden(start); | ||
|
||
/** @typedef {typeof start} RestakeSF */ |
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,53 @@ | ||
/** | ||
* @file Example contract that allows users to do different things with rewards | ||
*/ | ||
import { M, mustMatch } from '@endo/patterns'; | ||
|
||
/** | ||
* @import {OrchestrationAccount, OrchestrationFlow, Orchestrator, StakingAccountActions} from '@agoric/orchestration'; | ||
* @import {MakeRestakeHolderKit} from './restake.kit.js'; | ||
* @import {MakeCombineInvitationMakers} from '../exos/combine-invitation-makers.js'; | ||
*/ | ||
|
||
/** | ||
* Create an OrchestrationAccount for a specific chain and return a continuing | ||
* offer with invitations makers for Delegate, WithdrawRewards, Transfer, etc. | ||
* | ||
* @satisfies {OrchestrationFlow} | ||
* @param {Orchestrator} orch | ||
* @param {{ | ||
* makeRestakeHolderKit: MakeRestakeHolderKit; | ||
* makeCombineInvitationMakers: MakeCombineInvitationMakers; | ||
* }} ctx | ||
* @param {ZCFSeat} seat | ||
* @param {{ chainName: string }} offerArgs | ||
*/ | ||
export const makeRestakeAccount = async ( | ||
orch, | ||
{ makeRestakeHolderKit, makeCombineInvitationMakers }, | ||
seat, | ||
{ chainName }, | ||
) => { | ||
seat.exit(); // no funds exchanged | ||
mustMatch(chainName, M.string()); | ||
const remoteChain = await orch.getChain(chainName); | ||
const orchAccount = | ||
/** @type {OrchestrationAccount<any> & StakingAccountActions} */ ( | ||
await remoteChain.makeAccount() | ||
); | ||
const restakeHolderKit = makeRestakeHolderKit(orchAccount); | ||
const { invitationMakers: orchInvitationMakers, publicSubscribers } = | ||
await orchAccount.asContinuingOffer(); | ||
|
||
const combinedInvitationMakers = makeCombineInvitationMakers( | ||
// `orchInvitationMakers` currently lying about its type | ||
orchInvitationMakers, | ||
// @ts-expect-error update `makeCombineInvitationMakers` to accept Guarded... | ||
restakeHolderKit.invitationMakers, | ||
); | ||
|
||
return harden({ | ||
invitationMakers: combinedInvitationMakers, | ||
publicSubscribers, | ||
}); | ||
}; |
Oops, something went wrong.