From e83725e863ba1f48b9b6f1ae9128e8f0aca67668 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Thu, 19 Sep 2024 15:29:18 -0700 Subject: [PATCH] fixup! feat(examples): unbond and transfer --- packages/orchestration/src/examples/unbond.flows.js | 12 +++++++----- .../test/examples/unbond.contract.test.ts | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/orchestration/src/examples/unbond.flows.js b/packages/orchestration/src/examples/unbond.flows.js index fcf4256a1a3..7ac7528bc16 100644 --- a/packages/orchestration/src/examples/unbond.flows.js +++ b/packages/orchestration/src/examples/unbond.flows.js @@ -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'; */ /** @@ -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); diff --git a/packages/orchestration/test/examples/unbond.contract.test.ts b/packages/orchestration/test/examples/unbond.contract.test.ts index 85bb88d6518..05958266b2c 100644 --- a/packages/orchestration/test/examples/unbond.contract.test.ts +++ b/packages/orchestration/test/examples/unbond.contract.test.ts @@ -52,7 +52,7 @@ test('start', async t => { makeDelegationsResponse(), 'eyJ0eXBlIjoxLCJkYXRhIjoiQ2xzS0pTOWpiM050YjNNdWMzUmhhMmx1Wnk1Mk1XSmxkR0V4TGsxeloxVnVaR1ZzWldkaGRHVVNNZ29MWTI5emJXOXpNWFJsYzNRU0VXTnZjMjF2YzNaaGJHOXdaWEl4ZUhsNkdoQUtCWFZ2YzIxdkVnY3hNREF3TURBdyIsIm1lbW8iOiIifQ==': makeUndelegateResponse(), - 'eyJkYXRhIjoiQ2prS0V3b0xZMjl6Ylc5ek1YUmxjM1FTQkU5VFRVOFNJaTlqYjNOdGIzTXVZbUZ1YXk1Mk1XSmxkR0V4TGxGMVpYSjVMMEpoYkdGdVkyVT0iLCJtZW1vIjoiIn0=': + 'eyJkYXRhIjoiQ2pvS0ZBb0xZMjl6Ylc5ek1YUmxjM1FTQlhWdmMyMXZFaUl2WTI5emJXOXpMbUpoYm1zdWRqRmlaWFJoTVM1UmRXVnllUzlDWVd4aGJtTmwiLCJtZW1vIjoiIn0=': buildQueryResponseString(QueryBalanceResponse, { balance: { denom: 'uosmo', amount: '1234' }, }),