Skip to content

Commit

Permalink
fixup! feat(examples): unbond and transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Sep 19, 2024
1 parent 2163957 commit e83725e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions packages/orchestration/src/examples/unbond.flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const trace = makeTracer('UnbondAndTransfer');

/**
* @import {Orchestrator, OrchestrationFlow, CosmosDelegationResponse} from '../types.js'
* @import {DelegationResponse} from '@agoric/cosmic-proto/cosmos/staking/v1beta1/staking.js';
*/

/**
Expand All @@ -14,23 +13,26 @@ const trace = makeTracer('UnbondAndTransfer');
* @param {ZCF} ctx.zcf
*/
export const unbondAndTransfer = async (orch, { zcf }) => {
console.log('zcf within the membrane', zcf);
trace('zcf within the membrane', zcf);
// Osmosis is one of the few chains with icqEnabled
const osmosis = await orch.getChain('osmosis');
const osmoDenom = (await osmosis.getChainInfo()).stakingTokens[0].denom;

// In a real world scenario, accounts would be re-used across invokations of the handler
const osmoAccount = await osmosis.makeAccount();

/** @type {CosmosDelegationResponse[]} Cosmos */
const delegations = await osmoAccount.getDelegations();
trace('delegations', delegations);
const osmoDelegations = delegations.filter(d => d.amount.denom === osmoDenom);

// wait for the undelegations to be complete (may take weeks)
await osmoAccount.undelegate(delegations);
await osmoAccount.undelegate(osmoDelegations);

// ??? should this be synchronous? depends on how names are resolved.
const stride = await orch.getChain('stride');
const strideAccount = await stride.makeAccount();

const balance = await osmoAccount.getBalance('OSMO');
const balance = await osmoAccount.getBalance(osmoDenom);
await osmoAccount.transfer(balance, strideAccount.getAddress());
};
harden(unbondAndTransfer);
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test('start', async t => {
makeDelegationsResponse(),
'eyJ0eXBlIjoxLCJkYXRhIjoiQ2xzS0pTOWpiM050YjNNdWMzUmhhMmx1Wnk1Mk1XSmxkR0V4TGsxeloxVnVaR1ZzWldkaGRHVVNNZ29MWTI5emJXOXpNWFJsYzNRU0VXTnZjMjF2YzNaaGJHOXdaWEl4ZUhsNkdoQUtCWFZ2YzIxdkVnY3hNREF3TURBdyIsIm1lbW8iOiIifQ==':
makeUndelegateResponse(),
'eyJkYXRhIjoiQ2prS0V3b0xZMjl6Ylc5ek1YUmxjM1FTQkU5VFRVOFNJaTlqYjNOdGIzTXVZbUZ1YXk1Mk1XSmxkR0V4TGxGMVpYSjVMMEpoYkdGdVkyVT0iLCJtZW1vIjoiIn0=':
'eyJkYXRhIjoiQ2pvS0ZBb0xZMjl6Ylc5ek1YUmxjM1FTQlhWdmMyMXZFaUl2WTI5emJXOXpMbUpoYm1zdWRqRmlaWFJoTVM1UmRXVnllUzlDWVd4aGJtTmwiLCJtZW1vIjoiIn0=':
buildQueryResponseString(QueryBalanceResponse, {
balance: { denom: 'uosmo', amount: '1234' },
}),
Expand Down

0 comments on commit e83725e

Please sign in to comment.