From e221e390b4bfa7c7c71dbe97ec2d86c295101d3c Mon Sep 17 00:00:00 2001 From: adairrr <32375605+adairrr@users.noreply.github.com> Date: Thu, 31 Oct 2024 22:34:30 -0400 Subject: [PATCH] Attempt using fetch_account + publisher --- contracts/{{adapter_name}}/src/bin/publish.rs | 7 ++++--- contracts/{{app_name}}/src/bin/publish.rs | 5 ++++- contracts/{{standalone_name}}/src/bin/publish.rs | 7 ++++--- frontend/app/_components/codegen-contract.tsx | 15 +++++++++------ frontend/app/_generated/generated-graphql/gql.ts | 4 ++-- .../app/_generated/generated-graphql/graphql.ts | 4 ++-- frontend/app/_hooks/useQueryAccountsById.ts | 10 +++++----- frontend/package.json | 2 +- frontend/utils/chains.ts | 15 ++++++++------- 9 files changed, 39 insertions(+), 30 deletions(-) diff --git a/contracts/{{adapter_name}}/src/bin/publish.rs b/contracts/{{adapter_name}}/src/bin/publish.rs index a83351a..ba92be0 100644 --- a/contracts/{{adapter_name}}/src/bin/publish.rs +++ b/contracts/{{adapter_name}}/src/bin/publish.rs @@ -31,9 +31,10 @@ fn publish(networks: Vec) -> anyhow::Result<()> { let abstract_client: AbstractClient = AbstractClient::new(chain.clone())?; // Get the [`Publisher`] that owns the namespace, otherwise create a new one and claim the namespace - let publisher: Publisher<_> = abstract_client - .publisher_builder(adapter_namespace) - .build()?; + let publisher_acc = abstract_client.fetch_account(adapter_namespace)?; + + // Get the [`Publisher`] that owns the namespace, otherwise create a new one and claim the namespace + let publisher: Publisher<_> = Publisher::new(&publisher_acc)?; if publisher.account().owner()? != chain.sender_addr() { panic!("The current sender can not publish to this namespace. Please use the wallet that owns the Account that owns the Namespace.") diff --git a/contracts/{{app_name}}/src/bin/publish.rs b/contracts/{{app_name}}/src/bin/publish.rs index 2c8f361..1702105 100644 --- a/contracts/{{app_name}}/src/bin/publish.rs +++ b/contracts/{{app_name}}/src/bin/publish.rs @@ -30,7 +30,10 @@ fn publish(networks: Vec) -> anyhow::Result<()> { let abstract_client: AbstractClient = AbstractClient::new(chain.clone())?; // Get the [`Publisher`] that owns the namespace, otherwise create a new one and claim the namespace - let publisher: Publisher<_> = abstract_client.publisher_builder(app_namespace).build()?; + let publisher_acc = abstract_client.fetch_account(app_namespace)?; + + // Get the [`Publisher`] that owns the namespace, otherwise create a new one and claim the namespace + let publisher: Publisher<_> = Publisher::new(&publisher_acc)?; if publisher.account().owner()? != chain.sender_addr() { panic!("The current sender can not publish to this namespace. Please use the wallet that owns the Account that owns the Namespace.") diff --git a/contracts/{{standalone_name}}/src/bin/publish.rs b/contracts/{{standalone_name}}/src/bin/publish.rs index 414d5a0..195518d 100644 --- a/contracts/{{standalone_name}}/src/bin/publish.rs +++ b/contracts/{{standalone_name}}/src/bin/publish.rs @@ -30,9 +30,10 @@ fn publish(networks: Vec) -> anyhow::Result<()> { let abstract_client: AbstractClient = AbstractClient::new(chain.clone())?; // Get the [`Publisher`] that owns the namespace, otherwise create a new one and claim the namespace - let publisher: Publisher<_> = abstract_client - .publisher_builder(standalone_namespace) - .build()?; + let publisher_acc = abstract_client.fetch_account(standalone_namespace)?; + + // Get the [`Publisher`] that owns the namespace, otherwise create a new one and claim the namespace + let publisher: Publisher<_> = Publisher::new(&publisher_acc)?; if publisher.account().owner()? != chain.sender_addr() { panic!("The current sender can not publish to this namespace. Please use the wallet that owns the Account that owns the Namespace.") diff --git a/frontend/app/_components/codegen-contract.tsx b/frontend/app/_components/codegen-contract.tsx index 9b2654a..988e53b 100644 --- a/frontend/app/_components/codegen-contract.tsx +++ b/frontend/app/_components/codegen-contract.tsx @@ -9,8 +9,10 @@ import { Card, CardContent, CardHeader, CardTitle } from "../../components/card" import { Alert, AlertDescription, AlertTitle } from "../../components/alert" import { AlertCircle } from "lucide-react" +const EXAMPLE_NEUTRONTESTNET_CW20 = "neutron1sj7exsjqgy460zky8t0u0cvjutu09fswqfq3trssq9z935dryl3snjeekf" + + export const CodegenContract: React.FC = () => { - const contractAddress = "juno1ju8k8sqwsqu5k6umrypmtyqu2wqcpnrkf4w4mntvl0javt4nma7s8lzgss" const chainId = appChain.chainId const { data: cosmosAccount } = useAccount({ chainId }) @@ -24,11 +26,12 @@ export const CodegenContract: React.FC = () => { }, }) const { data: accountsMetadata } = useAccountsMetadataGraphQLQuery({ accountIds: accounts }) - const { data: balance, isLoading } = cw20Base.queries.useBalance({ - contractAddress, + + const { data: exampleCw20Balance, isLoading } = cw20Base.queries.useBalance({ + contractAddress: EXAMPLE_NEUTRONTESTNET_CW20, chainName: appChain.chainName, args: { address: accountsMetadata?.[0]?.address ?? "" }, - options: { enabled: !!accountsMetadata?.[0]?.address && !!contractAddress }, + options: { enabled: !!accountsMetadata?.[0]?.address && !!EXAMPLE_NEUTRONTESTNET_CW20 }, }) return ( @@ -39,11 +42,11 @@ export const CodegenContract: React.FC = () => { {isLoading ? (

Loading balance...

- ) : balance ? ( + ) : exampleCw20Balance ? (

Balance for address: {accountsMetadata?.[0]?.address ?? ""}

- Balance: {balance.balance} + Balance: {exampleCw20Balance.balance}

) : ( diff --git a/frontend/app/_generated/generated-graphql/gql.ts b/frontend/app/_generated/generated-graphql/gql.ts index 7859a75..5636dea 100644 --- a/frontend/app/_generated/generated-graphql/gql.ts +++ b/frontend/app/_generated/generated-graphql/gql.ts @@ -14,7 +14,7 @@ import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document- * Learn more about it here: https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#reducing-bundle-size */ const documents = { - "\n query AccountsMetadata($ids: [AccountIdWithChain!]!) {\n accountsByIds(ids: $ids) {\n id\n info { name chainId description link }\n address\n owner\n }\n }\n": types.AccountsMetadataDocument, + "\n query AccountsMetadata($ids: [AccountIdWithChain!]!) {\n accountsByIds(ids: $ids) {\n id\n info { name chainId description link }\n address\n owner\n balances {\n amount\n denom\n }\n }\n }\n": types.AccountsMetadataDocument, }; /** @@ -34,7 +34,7 @@ export function gql(source: string): unknown; /** * The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ -export function gql(source: "\n query AccountsMetadata($ids: [AccountIdWithChain!]!) {\n accountsByIds(ids: $ids) {\n id\n info { name chainId description link }\n address\n owner\n }\n }\n"): (typeof documents)["\n query AccountsMetadata($ids: [AccountIdWithChain!]!) {\n accountsByIds(ids: $ids) {\n id\n info { name chainId description link }\n address\n owner\n }\n }\n"]; +export function gql(source: "\n query AccountsMetadata($ids: [AccountIdWithChain!]!) {\n accountsByIds(ids: $ids) {\n id\n info { name chainId description link }\n address\n owner\n balances {\n amount\n denom\n }\n }\n }\n"): (typeof documents)["\n query AccountsMetadata($ids: [AccountIdWithChain!]!) {\n accountsByIds(ids: $ids) {\n id\n info { name chainId description link }\n address\n owner\n balances {\n amount\n denom\n }\n }\n }\n"]; export function gql(source: string) { return (documents as any)[source] ?? {}; diff --git a/frontend/app/_generated/generated-graphql/graphql.ts b/frontend/app/_generated/generated-graphql/graphql.ts index 1654d81..e61fbc3 100644 --- a/frontend/app/_generated/generated-graphql/graphql.ts +++ b/frontend/app/_generated/generated-graphql/graphql.ts @@ -136,7 +136,7 @@ export type AccountsMetadataQueryVariables = Exact<{ }>; -export type AccountsMetadataQuery = { __typename?: 'Query', accountsByIds: Array<{ __typename?: 'AbstractAccount', id: string, address: string, owner?: string | null, info: { __typename?: 'AccountInfo', name?: string | null, chainId: string, description?: string | null, link?: string | null } }> }; +export type AccountsMetadataQuery = { __typename?: 'Query', accountsByIds: Array<{ __typename?: 'AbstractAccount', id: string, address: string, owner?: string | null, info: { __typename?: 'AccountInfo', name?: string | null, chainId: string, description?: string | null, link?: string | null }, balances: Array<{ __typename?: 'Balance', amount: string, denom: string }> }> }; -export const AccountsMetadataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"AccountsMetadata"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"ids"}},"type":{"kind":"NonNullType","type":{"kind":"ListType","type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"AccountIdWithChain"}}}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"accountsByIds"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"ids"},"value":{"kind":"Variable","name":{"kind":"Name","value":"ids"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"info"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"chainId"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"link"}}]}},{"kind":"Field","name":{"kind":"Name","value":"address"}},{"kind":"Field","name":{"kind":"Name","value":"owner"}}]}}]}}]} as unknown as DocumentNode; \ No newline at end of file +export const AccountsMetadataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"AccountsMetadata"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"ids"}},"type":{"kind":"NonNullType","type":{"kind":"ListType","type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"AccountIdWithChain"}}}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"accountsByIds"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"ids"},"value":{"kind":"Variable","name":{"kind":"Name","value":"ids"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"info"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"chainId"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"link"}}]}},{"kind":"Field","name":{"kind":"Name","value":"address"}},{"kind":"Field","name":{"kind":"Name","value":"owner"}},{"kind":"Field","name":{"kind":"Name","value":"balances"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"amount"}},{"kind":"Field","name":{"kind":"Name","value":"denom"}}]}}]}}]}}]} as unknown as DocumentNode; \ No newline at end of file diff --git a/frontend/app/_hooks/useQueryAccountsById.ts b/frontend/app/_hooks/useQueryAccountsById.ts index 8fb28f6..05eb9f7 100644 --- a/frontend/app/_hooks/useQueryAccountsById.ts +++ b/frontend/app/_hooks/useQueryAccountsById.ts @@ -10,6 +10,10 @@ export const ACCOUNTS_METADATA_QUERY = gql(/* GraphQL */ ` info { name chainId description link } address owner + balances { + amount + denom + } } } `) @@ -18,12 +22,8 @@ export type UseAccountsMetadataArgs = { accountIds: AccountId[] | undefined } -export function useAccountsMetadataGraphQLRequest() { - return useGraphQLRequest(ACCOUNTS_METADATA_QUERY) -} - export const useAccountsMetadataGraphQLQuery = ({ accountIds }: UseAccountsMetadataArgs) => { - const request = useAccountsMetadataGraphQLRequest() + const request = useGraphQLRequest(ACCOUNTS_METADATA_QUERY) return useQuery({ queryFn: () => { if (!accountIds) throw new Error('Missing `accountIds`') diff --git a/frontend/package.json b/frontend/package.json index 01959ca..30cc699 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -8,7 +8,7 @@ "start": "next start", "lint": "next lint", "generate": "npm run generate:graz && npm run generate:gql && npm run generate:abstract", - "generate:graz": "graz generate -g -M juno,osmosis -T junotestnet,osmosistestnet", + "generate:graz": "graz generate -g -M neutron,osmosis -T neutrontestnet,osmosistestnet", "generate:gql": "gql-gen --config codegen.yml", "generate:abstract": "abstract generate" }, diff --git a/frontend/utils/chains.ts b/frontend/utils/chains.ts index 945ca02..81ccbe6 100644 --- a/frontend/utils/chains.ts +++ b/frontend/utils/chains.ts @@ -1,16 +1,17 @@ import type { ChainInfo } from '@keplr-wallet/types' -import { mainnetChains } from "graz/chains"; +import { testnetChains } from 'graz/chains' -const ABSTRACT_CORS_PROXY_BASE_URL = 'https://rpc-proxy.abstract-os.workers.dev/' -const proxiedUrl = (chainId: string, path: 'rpc' | 'api') => - `${ABSTRACT_CORS_PROXY_BASE_URL}${chainId}/${path}` +const chainNameToPolachuUrl = (chainName: string, urlType: 'api' | 'rpc') => { + const hyphenatedChainName = chainName.replace('testnet', '-testnet') + return `https://${hyphenatedChainName}-${urlType}.polkachu.com/` +} export const proxyChainEndpoints = (chain: ChainInfo): ChainInfo => ({ ...chain, - rpc: proxiedUrl(chain.chainId, 'rpc'), - rest: proxiedUrl(chain.chainId, 'api'), + rpc: chainNameToPolachuUrl(chain.chainName, 'rpc'), + rest: chainNameToPolachuUrl(chain.chainName, 'api'), }) as const -export const appChain = proxyChainEndpoints(mainnetChains.juno) +export const appChain = proxyChainEndpoints(testnetChains.neutrontestnet)