-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create seperate contract for axelar-gmp
- Loading branch information
1 parent
fdab2d1
commit 08fefad
Showing
5 changed files
with
564 additions
and
14 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
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,101 @@ | ||
import { InvitationShape } from '@agoric/zoe/src/typeGuards.js'; | ||
import { E } from '@endo/far'; | ||
import { M } from '@endo/patterns'; | ||
import { prepareChainHubAdmin } from '../exos/chain-hub-admin.js'; | ||
import { AnyNatAmountShape } from '../typeGuards.js'; | ||
import { withOrchestration } from '../utils/start-helper.js'; | ||
import { registerChainsAndAssets } from '../utils/chain-hub-helper.js'; | ||
import * as flows from './axelar.flows.js'; | ||
import * as sharedFlows from './shared.flows.js'; | ||
|
||
/** | ||
* @import {Vow} from '@agoric/vow'; | ||
* @import {Zone} from '@agoric/zone'; | ||
* @import {OrchestrationPowers, OrchestrationTools} from '../utils/start-helper.js'; | ||
* @import {CosmosChainInfo, Denom, DenomDetail} from '@agoric/orchestration'; | ||
*/ | ||
|
||
export const SingleNatAmountRecord = M.and( | ||
M.recordOf(M.string(), AnyNatAmountShape, { | ||
numPropertiesLimit: 1, | ||
}), | ||
M.not(harden({})), | ||
); | ||
harden(SingleNatAmountRecord); | ||
|
||
/** | ||
* Orchestration contract to be wrapped by withOrchestration for Zoe | ||
* | ||
* @param {ZCF} zcf | ||
* @param {OrchestrationPowers & { | ||
* marshaller: Marshaller; | ||
* chainInfo?: Record<string, CosmosChainInfo>; | ||
* assetInfo?: [Denom, DenomDetail & { brandKey?: string }][]; | ||
* }} privateArgs | ||
* @param {Zone} zone | ||
* @param {OrchestrationTools} tools | ||
*/ | ||
export const contract = async ( | ||
zcf, | ||
privateArgs, | ||
zone, | ||
{ chainHub, orchestrateAll, vowTools, zoeTools }, | ||
) => { | ||
const creatorFacet = prepareChainHubAdmin(zone, chainHub); | ||
|
||
// UNTIL https://github.com/Agoric/agoric-sdk/issues/9066 | ||
const logNode = E(privateArgs.storageNode).makeChildNode('log'); | ||
/** @type {(msg: string) => Vow<void>} */ | ||
const log = msg => vowTools.watch(E(logNode).setValue(msg)); | ||
|
||
const { makeLocalAccount } = orchestrateAll(sharedFlows, {}); | ||
/** | ||
* Setup a shared local account for use in async-flow functions. Typically, | ||
* exo initState functions need to resolve synchronously, but `makeOnce` | ||
* allows us to provide a Promise. When using this inside a flow, we must | ||
* await it to ensure the account is available for use. | ||
* | ||
* @type {any} sharedLocalAccountP expects a Promise but this is a vow | ||
* https://github.com/Agoric/agoric-sdk/issues/9822 | ||
*/ | ||
const sharedLocalAccountP = zone.makeOnce('localAccount', () => | ||
makeLocalAccount(), | ||
); | ||
|
||
// orchestrate uses the names on orchestrationFns to do a "prepare" of the associated behavior | ||
const orchFns = orchestrateAll(flows, { | ||
log, | ||
sharedLocalAccountP, | ||
zoeTools, | ||
}); | ||
|
||
const publicFacet = zone.exo( | ||
'Send PF', | ||
M.interface('Send PF', { | ||
makeSendInvitation: M.callWhen().returns(InvitationShape), | ||
}), | ||
{ | ||
makeSendInvitation() { | ||
return zcf.makeInvitation( | ||
orchFns.sendIt, | ||
'send', | ||
undefined, | ||
M.splitRecord({ give: SingleNatAmountRecord }), | ||
); | ||
}, | ||
}, | ||
); | ||
|
||
registerChainsAndAssets( | ||
chainHub, | ||
zcf.getTerms().brands, | ||
privateArgs.chainInfo, | ||
privateArgs.assetInfo, | ||
); | ||
|
||
return { publicFacet, creatorFacet }; | ||
}; | ||
harden(contract); | ||
|
||
export const start = withOrchestration(contract); | ||
harden(start); |
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
Oops, something went wrong.