Skip to content

Commit

Permalink
simplify and finish unbond example (#10121)
Browse files Browse the repository at this point in the history
closes: #9782

## Description

#9782 was to finish the example of "unbond and liquidate". We've punted Liquid Staking,
- #10017

So to get a complete working example this does a transfer after unbonding.

### Security Considerations
Not being deployed

### Scaling Considerations
Not being deployed


### Documentation Considerations
May become part of documentation, up to DevRel

### Testing Considerations
CI

### Upgrade Considerations
Not being deployed
  • Loading branch information
mergify[bot] authored Sep 20, 2024
2 parents c04c91c + 58e38a2 commit f29ecb3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
21 changes: 10 additions & 11 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,27 +13,27 @@ 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');
// In a real world scenario, accounts would be re-used across invokations of the handler
const osmoDenom = (await osmosis.getChainInfo()).stakingTokens[0].denom;

// In a real world scenario, accounts would be reused across invokations of the handler.
// See the staking-combinations contract for an example of how to reuse an account.
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();

// TODO the `TIA` string actually needs to be the Brand from AgoricNames
// const tiaAmt = await celestiaAccount.getBalance('TIA');
// await celestiaAccount.transfer(tiaAmt, strideAccount.getAddress());
// TODO https://github.com/Agoric/agoric-sdk/issues/10017
// await strideAccount.liquidStake(tiaAmt);
console.log(osmoAccount, strideAccount);
const balance = await osmoAccount.getBalance(osmoDenom);
await osmoAccount.transfer(balance, strideAccount.getAddress());
};
harden(unbondAndTransfer);
8 changes: 8 additions & 0 deletions packages/orchestration/test/examples/unbond.contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import path from 'path';
import { inspectMapStore } from '@agoric/internal/src/testing-utils.js';
import { QueryDelegatorDelegationsResponse } from '@agoric/cosmic-proto/cosmos/staking/v1beta1/query.js';
import { MsgUndelegateResponse } from '@agoric/cosmic-proto/cosmos/staking/v1beta1/tx.js';
import { MsgTransferResponse } from '@agoric/cosmic-proto/ibc/applications/transfer/v1/tx.js';
import { QueryBalanceResponse } from '@agoric/cosmic-proto/cosmos/bank/v1beta1/query.js';
import { commonSetup } from '../supports.js';
import {
buildMsgResponseString,
Expand Down Expand Up @@ -50,6 +52,12 @@ test('start', async t => {
makeDelegationsResponse(),
'eyJ0eXBlIjoxLCJkYXRhIjoiQ2xzS0pTOWpiM050YjNNdWMzUmhhMmx1Wnk1Mk1XSmxkR0V4TGsxeloxVnVaR1ZzWldkaGRHVVNNZ29MWTI5emJXOXpNWFJsYzNRU0VXTnZjMjF2YzNaaGJHOXdaWEl4ZUhsNkdoQUtCWFZ2YzIxdkVnY3hNREF3TURBdyIsIm1lbW8iOiIifQ==':
makeUndelegateResponse(),
'eyJkYXRhIjoiQ2pvS0ZBb0xZMjl6Ylc5ek1YUmxjM1FTQlhWdmMyMXZFaUl2WTI5emJXOXpMbUpoYm1zdWRqRmlaWFJoTVM1UmRXVnllUzlDWVd4aGJtTmwiLCJtZW1vIjoiIn0=':
buildQueryResponseString(QueryBalanceResponse, {
balance: { denom: 'uosmo', amount: '1234' },
}),
'eyJ0eXBlIjoxLCJkYXRhIjoiQ25rS0tTOXBZbU11WVhCd2JHbGpZWFJwYjI1ekxuUnlZVzV6Wm1WeUxuWXhMazF6WjFSeVlXNXpabVZ5RWt3S0NIUnlZVzV6Wm1WeUVndGphR0Z1Ym1Wc0xUTXlOaG9OQ2dWMWIzTnRieElFTVRJek5DSUxZMjl6Ylc5ek1YUmxjM1FxREdOdmMyMXZjekYwWlhOME1USUFPSUR3MXRUQ3pySUciLCJtZW1vIjoiIn0=':
buildMsgResponseString(MsgTransferResponse, {}),
};
};

Expand Down

0 comments on commit f29ecb3

Please sign in to comment.