-
Notifications
You must be signed in to change notification settings - Fork 208
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
feat: use orchFns.autoStake
as target for receiveUpcall
#10065
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,18 +2,57 @@ import { | |
EmptyProposalShape, | ||
InvitationShape, | ||
} from '@agoric/zoe/src/typeGuards.js'; | ||
import { M } from '@endo/patterns'; | ||
import { makeTracer } from '@agoric/internal'; | ||
import { M, mustMatch } from '@endo/patterns'; | ||
import { prepareChainHubAdmin } from '../exos/chain-hub-admin.js'; | ||
import { preparePortfolioHolder } from '../exos/portfolio-holder-kit.js'; | ||
import { withOrchestration } from '../utils/start-helper.js'; | ||
import { prepareStakingTap } from './auto-stake-it-tap-kit.js'; | ||
import * as flows from './auto-stake-it.flows.js'; | ||
import { ChainAddressShape } from '../typeGuards.js'; | ||
|
||
const trace = makeTracer('AutoStakeIt'); | ||
|
||
/** | ||
* @import {GuestInterface} from '@agoric/async-flow'; | ||
* @import {Zone} from '@agoric/zone'; | ||
* @import {IBCChannelID, VTransferIBCEvent} from '@agoric/vats'; | ||
* @import {TargetApp} from '@agoric/vats/src/bridge-target.js'; | ||
* @import {ChainAddress, CosmosValidatorAddress, Denom} from '@agoric/orchestration'; | ||
* @import {TypedPattern} from '@agoric/internal'; | ||
* @import {CosmosOrchestrationAccount} from '../exos/cosmos-orchestration-account.js'; | ||
* @import {LocalOrchestrationAccount} from '../exos/local-orchestration-account.js'; | ||
* @import {OrchestrationPowers, OrchestrationTools} from '../utils/start-helper.js'; | ||
*/ | ||
|
||
/** | ||
* @typedef {{ | ||
* stakingAccount: GuestInterface<CosmosOrchestrationAccount>; | ||
* localAccount: GuestInterface<LocalOrchestrationAccount>; | ||
* config: { | ||
* validator: CosmosValidatorAddress; | ||
* localChainAddress: ChainAddress; | ||
* remoteChainAddress: ChainAddress; | ||
* sourceChannel: IBCChannelID; | ||
* remoteDenom: Denom; | ||
* localDenom: Denom; | ||
* }; | ||
* }} StakingTapState | ||
*/ | ||
|
||
/** @type {TypedPattern<StakingTapState>} */ | ||
const StakingTapStateShape = harden({ | ||
stakingAccount: M.remotable('CosmosOrchestrationAccount'), | ||
localAccount: M.remotable('LocalOrchestrationAccount'), | ||
config: { | ||
validator: ChainAddressShape, | ||
localChainAddress: ChainAddressShape, | ||
remoteChainAddress: ChainAddressShape, | ||
sourceChannel: M.string(), | ||
remoteDenom: M.string(), | ||
localDenom: M.string(), | ||
}, | ||
}); | ||
|
||
/** | ||
* AutoStakeIt allows users to to create an auto-forwarding address that | ||
* transfers and stakes tokens on a remote chain when received. | ||
|
@@ -33,16 +72,42 @@ const contract = async ( | |
zone, | ||
{ chainHub, orchestrateAll, vowTools }, | ||
) => { | ||
const makeStakingTap = prepareStakingTap( | ||
zone.subZone('stakingTap'), | ||
vowTools, | ||
); | ||
const makePortfolioHolder = preparePortfolioHolder( | ||
zone.subZone('portfolio'), | ||
vowTools, | ||
); | ||
|
||
const { makeAccounts } = orchestrateAll(flows, { | ||
/** | ||
* Provides a {@link TargetApp} that reacts to an incoming IBC transfer. | ||
*/ | ||
const makeStakingTap = zone.exoClass( | ||
'StakingTap', | ||
M.interface('AutoStakeItTap', { | ||
receiveUpcall: M.call(M.record()).returns(M.undefined()), | ||
}), | ||
/** @param {StakingTapState} initialState */ | ||
initialState => { | ||
mustMatch(initialState, StakingTapStateShape); // TODO use opts.stateShape | ||
return harden(initialState); | ||
}, | ||
{ | ||
/** | ||
* Transfers from localAccount to stakingAccount, then delegates from the | ||
* stakingAccount to `validator` if the expected token (remoteDenom) is | ||
* received. | ||
* | ||
* @param {VTransferIBCEvent} event | ||
*/ | ||
receiveUpcall(event) { | ||
trace('receiveUpcall', event); | ||
const { localAccount, stakingAccount, config } = this.state; | ||
// eslint-disable-next-line no-use-before-define -- defined by orchestrateAll, necessarily after this | ||
orchFns.autoStake(localAccount, stakingAccount, config, event); | ||
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. I wanted to do 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. you might try passing a copy with normal properties rather than accessors |
||
}, | ||
}, | ||
); | ||
|
||
const orchFns = orchestrateAll(flows, { | ||
makeStakingTap, | ||
makePortfolioHolder, | ||
chainHub, | ||
|
@@ -56,7 +121,7 @@ const contract = async ( | |
{ | ||
makeAccountsInvitation() { | ||
return zcf.makeInvitation( | ||
makeAccounts, | ||
orchFns.makeAccounts, | ||
'Make Accounts', | ||
undefined, | ||
EmptyProposalShape, | ||
|
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.
If we use
OrchestrationAccount<any>
, which the flow is expecting, we seeArgument of type '<OrchestrationAccount<any>>' is not assignable to parameter of type 'Passable'.
on L105.