Skip to content
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: localOrchAccount.getBalance (non-vbank assets) and localOrchAccount.getBalances #10029

Merged
merged 11 commits into from
Sep 6, 2024

Conversation

0xpatrickdev
Copy link
Member

@0xpatrickdev 0xpatrickdev commented Sep 4, 2024

closes: #9610

Description

  • updates LocalOrchestrationAccount.getBalance() to support non-vbank assets (using localchain.query() to ask cosmos bank)
  • implements LocalOrchestrationAccount.getBalances()
  • BREAKING: renames ChainHub.lookupDenom and ChainHub.lookupAsset to getDenom and getAsset
  • BREAKING: ChainHub.getAsset returns undefined instead of throwing when lookup fails

Security Considerations

n/a

Scaling Considerations

n/a

Documentation Considerations

Updates pertinent jsodc and exos/README.md

Testing Considerations

Includes unit and e2e tests

Upgrade Considerations

n/a, unreleased code

Copy link

cloudflare-workers-and-pages bot commented Sep 4, 2024

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: 687adf1
Status: ✅  Deploy successful!
Preview URL: https://6949c637.agoric-sdk.pages.dev
Branch Preview URL: https://pc-local-orch-query-balance.agoric-sdk.pages.dev

View logs

} catch (_) {
return undefined;
}
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the course of adding these, I considered refactoring these helpers to something like:

type DenomAmountHelper = {
  coerceDenom: (denomArg: DenomArg) => Denom;
  coerceDenomAmount: (amount: DenomAmount | Amount<'nat'>) => DenomAmount;
  coerceCoin: (amount: AmountArg | Amount<'nat'>) => Coin;
  getAssetSafe: (denom: Denom) => DenomDetail | undefined;
  getDenomSafe: (brand: Brand<'nat'>) => Denom | undefined;
};

type makeDenomAmountHelper = (chainHub: ChainHub) => DenomAmountHelper;

so we can use it more conveniently. However, that might beg the question as to why these helpers aren't in ChainHub.

Anyone have thoughts/opinions here? cc @turadg @dckc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should drop the Safe methods. I don't have a strong opinion on whether to curry the chainhub into the coercers but I lean towards the current factoring as it's more flexible.

multichain-testing/test/account-balance-queries.test.ts Outdated Show resolved Hide resolved
@@ -395,21 +395,20 @@ export const makeChainHub = (agoricNames, vowTools) => {
*
* @param {Denom} denom
* @returns {DenomDetail}
* @throws {Error} if denom not found (unregistered)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no case in which undefined is a valid return. let's just return undefined when none is defined.

Comment on lines 447 to 449
if (!denom) {
throw Fail`No denomination for brand: ${denomArg}`;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should still be after denom is defined for type narrowing.

and then the if (brand && denom) can be simplified to,

if (brand) {
} else {
}

Comment on lines 19 to 21
if (!denom) {
throw makeError(`No denomination for brand ${denomArg}`);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to restore

* @param {Denom} denom
* @returns {DenomDetail | undefined}
*/
export const getAssetSafe = (chainHub, denom) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's obviate

} catch (_) {
return undefined;
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should drop the Safe methods. I don't have a strong opinion on whether to curry the chainhub into the coercers but I lean towards the current factoring as it's more flexible.

@@ -156,7 +156,7 @@ export const commonSetup = async (t: ExecutionContext<any>) => {
*/
const registerAgoricBld = () => {
try {
chainHub.lookupAsset('ubld');
chainHub.getAsset('ubld');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

making getAsset stop throwing will need to be handled here

@0xpatrickdev 0xpatrickdev removed the request for review from dckc September 4, 2024 20:18
Base automatically changed from pc/orch-query-balance to master September 4, 2024 21:15
Copy link

github-actions bot commented Sep 4, 2024

Base branch is changed to master. Please re-run the integration tests by adding 'force:integration' label.

throw Fail`No denom for ${denomArg}`;
}
if (!denom) {
throw Fail`No denomination for brand: ${denomArg}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const { chainName, baseName, baseDenom, brand } =
chainHub.lookupAsset(denom);
const denomDetail = chainHub.getAsset(denom);
if (!denomDetail) throw Fail`No denomination detail for ${q(denom)}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, denom

@@ -10,12 +10,14 @@ import { makeError } from '@endo/errors';
* @param {ChainHub} chainHub
* @param {DenomArg} denomArg
* @returns {Denom}
* @throws {Error} if Brand is provided and ChainHub does't contain Brand:Denom
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


t.deepEqual(
await VE(account).getBalances(),
// 'fake bridge is mocked to return 10 ubld and 10 uist balance'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you import these from that module?

timer,
vowTools,
chainHub,
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that was too many positionals

@0xpatrickdev 0xpatrickdev added the force:integration Force integration tests to run on PR label Sep 4, 2024
@0xpatrickdev 0xpatrickdev added the automerge:rebase Automatically rebase updates, then merge label Sep 6, 2024
@mergify mergify bot merged commit b31bd09 into master Sep 6, 2024
80 checks passed
@mergify mergify bot deleted the pc/local-orch-query-balance branch September 6, 2024 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:rebase Automatically rebase updates, then merge force:integration Force integration tests to run on PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Orchestration Account - Query Balances
2 participants