Skip to content

Commit

Permalink
Merge pull request #127 from AbstractSDK/adair/abstract2.0
Browse files Browse the repository at this point in the history
Update abstract to 0.24.0
  • Loading branch information
adairrr authored Oct 17, 2024
2 parents 80d0650 + d71ca8a commit f228240
Show file tree
Hide file tree
Showing 252 changed files with 2,527 additions and 3,951 deletions.
21 changes: 21 additions & 0 deletions .changeset/smooth-zoos-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
"@abstract-money/cli": major
"@abstract-money/core": major
"@abstract-money/react": major
"@abstract-money/provider-cosmoskit": major
"@abstract-money/provider-graz": major
"wagemos-cosmoskit-nextjs": minor
"wagemos-graz-nextjs": minor
"@abstract-money/cosmwasm-utils": minor
"@abstract-money/bundle-require": minor
---

Update Abstract to 0.24.0 with unified accounts

The major changes include:
- Updating Abstract to 0.24.0
- Removing distinction between `proxy` and `manager`, replacing them with simply `account`
- Clarify `executeRemote` and `executeOnRemote`
- Add doc comments
- Remove components from legacy code
- Ensure generation works for both esm and cjs
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,12 @@ This monorepo contains the Typescript-based SDKs for AbstractSDK. Please [read t
pnpm build
```


## Types

We have tried to make this repository compatible with both ESM and CJS, following guides from https://johnnyreilly.com/dual-publishing-esm-cjs-modules-with-tsup-and-are-the-types-wrong.

To check the types are exported properly, run the commands in the packages in which you're interested:
```bash
npx --yes @arethetypeswrong/cli --pack .
```
2 changes: 1 addition & 1 deletion examples/wagemos-cosmoskit-nextjs/abstract.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default defineConfig({
plugins: [
react(),
registry({
contracts: [{ namespace: 'abstract', name: 'betting', version: '0.0.2' }],
contracts: [{ namespace: 'wagemos', name: 'betting', version: '0.0.2' }],
}),
],
})
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/**
* This file was automatically generated by @abstract-money/ts-codegen@0.35.8.
* This file was automatically generated by @abstract-money/ts-codegen@0.37.0-beta-3.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run the @abstract-money/ts-codegen generate command to regenerate this file.
*/

import { CamelCasedProperties } from "type-fest";
import { SigningCosmWasmClient, ExecuteResult } from "@abstract-money/cli/cosmjs";
import { AbstractQueryClient, AbstractAccountQueryClient, AbstractAccountClient, AppExecuteMsg, AppExecuteMsgFactory, AdapterExecuteMsg, AdapterExecuteMsgFactory, AbstractClient, AbstractAccountId } from "@abstract-money/core/legacy";
import { AccountPublicClient, AccountWalletClient, AppExecuteMsg, AppExecuteMsgFactory, AdapterExecuteMsg, AdapterExecuteMsgFactory } from "@abstract-money/core";
import { StdFee, Coin } from "@abstract-money/cli/cosmjs";
import { Decimal, InstantiateMsg, ExecuteMsg, AssetEntry, AccountTrace, ChainName, Uint128, AccountOdds, AccountId, Bet, AnsAsset, QueryMsg, MigrateMsg, Addr, BetsResponse, ConfigResponse, ListOddsResponse, RoundStatus, RoundsResponse, RoundResponse, OddsResponse } from "./Betting.types";
import { BettingQueryMsgBuilder, BettingExecuteMsgBuilder } from "./Betting.message-builder";
export interface IBettingAppQueryClient {
moduleId: string;
accountQueryClient: AbstractAccountQueryClient;
accountPublicClient: AccountPublicClient;
_moduleAddress: string | undefined;
round: (params: CamelCasedProperties<Extract<QueryMsg, {
round: unknown;
Expand All @@ -30,33 +30,21 @@ export interface IBettingAppQueryClient {
bets: (params: CamelCasedProperties<Extract<QueryMsg, {
bets: unknown;
}>["bets"]>) => Promise<BetsResponse>;
connectSigningClient: (signingClient: SigningCosmWasmClient, address: string) => BettingAppClient;
getAddress: () => Promise<string>;
}
export class BettingAppQueryClient implements IBettingAppQueryClient {
accountQueryClient: AbstractAccountQueryClient;
accountPublicClient: AccountPublicClient;
moduleId: string;
_moduleAddress: string | undefined;

constructor({
abstractQueryClient,
accountId,
managerAddress,
proxyAddress,
accountPublicClient,
moduleId
}: {
abstractQueryClient: AbstractQueryClient;
accountId: AbstractAccountId;
managerAddress: string;
proxyAddress: string;
accountPublicClient: AccountPublicClient;
moduleId: string;
}) {
this.accountQueryClient = new AbstractAccountQueryClient({
abstract: abstractQueryClient,
accountId,
managerAddress,
proxyAddress
});
this.accountPublicClient = accountPublicClient;
this.moduleId = moduleId;
this.round = this.round.bind(this);
this.listRounds = this.listRounds.bind(this);
Expand Down Expand Up @@ -96,7 +84,9 @@ export class BettingAppQueryClient implements IBettingAppQueryClient {
};
getAddress = async (): Promise<string> => {
if (!this._moduleAddress) {
const address = await this.accountQueryClient.getModuleAddress(this.moduleId);
const address = await this.accountPublicClient.getModuleAddress({
id: this.moduleId
});

if (address === null) {
throw new Error(`Module ${this.moduleId} not installed`);
Expand All @@ -107,71 +97,55 @@ export class BettingAppQueryClient implements IBettingAppQueryClient {

return this._moduleAddress!;
};
connectSigningClient = (signingClient: SigningCosmWasmClient, address: string): BettingAppClient => {
return new BettingAppClient({
accountId: this.accountQueryClient.accountId,
managerAddress: this.accountQueryClient.managerAddress,
proxyAddress: this.accountQueryClient.proxyAddress,
moduleId: this.moduleId,
abstractClient: this.accountQueryClient.abstract.connectSigningClient(signingClient, address)
});
};
_query = async (queryMsg: QueryMsg): Promise<any> => {
return this.accountQueryClient.queryModule({
return this.accountPublicClient.queryModule({
moduleId: this.moduleId,
moduleType: "app",
queryMsg
});
};
}
export interface IBettingAppClient extends IBettingAppQueryClient {
accountClient: AbstractAccountClient;
accountWalletClient: AccountWalletClient;
createRound: (params: CamelCasedProperties<Extract<ExecuteMsg, {
create_round: unknown;
}>["create_round"]>, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
}>["create_round"]>, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
register: (params: CamelCasedProperties<Extract<ExecuteMsg, {
register: unknown;
}>["register"]>, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
}>["register"]>, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
updateAccounts: (params: CamelCasedProperties<Extract<ExecuteMsg, {
update_accounts: unknown;
}>["update_accounts"]>, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
}>["update_accounts"]>, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
placeBet: (params: CamelCasedProperties<Extract<ExecuteMsg, {
place_bet: unknown;
}>["place_bet"]>, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
}>["place_bet"]>, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
distributeWinnings: (params: CamelCasedProperties<Extract<ExecuteMsg, {
distribute_winnings: unknown;
}>["distribute_winnings"]>, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
}>["distribute_winnings"]>, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
closeRound: (params: CamelCasedProperties<Extract<ExecuteMsg, {
close_round: unknown;
}>["close_round"]>, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
}>["close_round"]>, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
updateConfig: (params: CamelCasedProperties<Extract<ExecuteMsg, {
update_config: unknown;
}>["update_config"]>, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
}>["update_config"]>, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
}
export class BettingAppClient extends BettingAppQueryClient implements IBettingAppClient {
accountClient: AbstractAccountClient;
accountWalletClient: AccountWalletClient;

constructor({
abstractClient,
accountId,
managerAddress,
proxyAddress,
accountPublicClient,
accountWalletClient,
moduleId
}: {
abstractClient: AbstractClient;
accountId: AbstractAccountId;
managerAddress: string;
proxyAddress: string;
accountPublicClient: AccountPublicClient;
accountWalletClient: AccountWalletClient;
moduleId: string;
}) {
super({
abstractQueryClient: abstractClient,
accountId,
managerAddress,
proxyAddress,
accountPublicClient,
moduleId
});
this.accountClient = AbstractAccountClient.fromQueryClient(this.accountQueryClient, abstractClient);
this.accountWalletClient = accountWalletClient;
this.createRound = this.createRound.bind(this);
this.register = this.register.bind(this);
this.updateAccounts = this.updateAccounts.bind(this);
Expand All @@ -183,41 +157,43 @@ export class BettingAppClient extends BettingAppQueryClient implements IBettingA

createRound = async (params: CamelCasedProperties<Extract<ExecuteMsg, {
create_round: unknown;
}>["create_round"]>, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return this._execute(BettingExecuteMsgBuilder.createRound(params), fee, memo, _funds);
}>["create_round"]>, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
return this._execute(BettingExecuteMsgBuilder.createRound(params), fee_, memo_, funds_);
};
register = async (params: CamelCasedProperties<Extract<ExecuteMsg, {
register: unknown;
}>["register"]>, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return this._execute(BettingExecuteMsgBuilder.register(params), fee, memo, _funds);
}>["register"]>, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
return this._execute(BettingExecuteMsgBuilder.register(params), fee_, memo_, funds_);
};
updateAccounts = async (params: CamelCasedProperties<Extract<ExecuteMsg, {
update_accounts: unknown;
}>["update_accounts"]>, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return this._execute(BettingExecuteMsgBuilder.updateAccounts(params), fee, memo, _funds);
}>["update_accounts"]>, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
return this._execute(BettingExecuteMsgBuilder.updateAccounts(params), fee_, memo_, funds_);
};
placeBet = async (params: CamelCasedProperties<Extract<ExecuteMsg, {
place_bet: unknown;
}>["place_bet"]>, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return this._execute(BettingExecuteMsgBuilder.placeBet(params), fee, memo, _funds);
}>["place_bet"]>, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
return this._execute(BettingExecuteMsgBuilder.placeBet(params), fee_, memo_, funds_);
};
distributeWinnings = async (params: CamelCasedProperties<Extract<ExecuteMsg, {
distribute_winnings: unknown;
}>["distribute_winnings"]>, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return this._execute(BettingExecuteMsgBuilder.distributeWinnings(params), fee, memo, _funds);
}>["distribute_winnings"]>, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
return this._execute(BettingExecuteMsgBuilder.distributeWinnings(params), fee_, memo_, funds_);
};
closeRound = async (params: CamelCasedProperties<Extract<ExecuteMsg, {
close_round: unknown;
}>["close_round"]>, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return this._execute(BettingExecuteMsgBuilder.closeRound(params), fee, memo, _funds);
}>["close_round"]>, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
return this._execute(BettingExecuteMsgBuilder.closeRound(params), fee_, memo_, funds_);
};
updateConfig = async (params: CamelCasedProperties<Extract<ExecuteMsg, {
update_config: unknown;
}>["update_config"]>, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return this._execute(BettingExecuteMsgBuilder.updateConfig(params), fee, memo, _funds);
}>["update_config"]>, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
return this._execute(BettingExecuteMsgBuilder.updateConfig(params), fee_, memo_, funds_);
};
_execute = async (msg: ExecuteMsg, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
_execute = async (msg: ExecuteMsg, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
const signingCwClient = await this.accountWalletClient.getSigningCosmWasmClient();
const sender = await this.accountWalletClient.getSenderAddress();
const moduleMsg: AppExecuteMsg<ExecuteMsg> = AppExecuteMsgFactory.executeApp(msg);
return await this.accountClient.abstract.client.execute(this.accountClient.sender, await this.getAddress(), moduleMsg, fee, memo, _funds);
return await signingCwClient.execute(sender, await this.getAddress(), moduleMsg, fee_, memo_, funds_);
};
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-nocheck
/**
* This file was automatically generated by @abstract-money/ts-codegen@0.35.8.
* This file was automatically generated by @abstract-money/ts-codegen@0.37.0-beta-3.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run the @abstract-money/ts-codegen generate command to regenerate this file.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* This file was automatically generated by @abstract-money/ts-codegen@0.35.8.
* This file was automatically generated by @abstract-money/ts-codegen@0.37.0-beta-3.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run the @abstract-money/ts-codegen generate command to regenerate this file.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* This file was automatically generated by @abstract-money/ts-codegen@0.35.8.
* This file was automatically generated by @abstract-money/ts-codegen@0.37.0-beta-3.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run the @abstract-money/ts-codegen generate command to regenerate this file.
*/
Expand Down
2 changes: 1 addition & 1 deletion examples/wagemos-cosmoskit-nextjs/src/_generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import {
// React
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

export const BETTING_MODULE_ID = 'abstract:betting'
export const BETTING_MODULE_ID = 'wagemos:betting'

export const betting = {
queries: {
Expand Down
25 changes: 11 additions & 14 deletions examples/wagemos-cosmoskit-nextjs/src/app/remote/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { accountIdToString } from '@abstract-money/core'
import {
useAccounts,
useCreateRemoteAccount,
useExecuteOnRemoteManager,
useExecuteOnRemote,
useRemoteAccountIds,
useRemoteHosts,
useSimulateExecuteRemoteManager,
useSimulateExecuteRemoteAccount,
} from '@abstract-money/react'
import { useChain } from '@cosmos-kit/react'
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
import { useCallback, useMemo, useState } from 'react'
import { Button } from '../../components/ui/button'
import {
Expand Down Expand Up @@ -56,11 +55,10 @@ export default function RemotePage() {
chainName: firstAccount?.chainName,
})

const { mutate: execRemote, isLoading: isExecuting } =
useExecuteOnRemoteManager({
accountId: firstAccount,
chainName: firstAccount?.chainName,
})
const { mutate: execOnRemote, isLoading: isExecuting } = useExecuteOnRemote({
accountId: firstAccount,
chainName: firstAccount?.chainName,
})

const { data: remoteAccountIds } = useRemoteAccountIds({
accountId: firstAccount,
Expand All @@ -79,7 +77,6 @@ export default function RemotePage() {
funds: [],
args: {
hostChainName: chainInput,
base_asset: 'juno>juno',
installModules: [],
},
})
Expand All @@ -90,22 +87,22 @@ export default function RemotePage() {
throw new Error('chainInput is undefined')
}
console.log('executing remote account')
execRemote({
execOnRemote({
funds: [],
fee: 'auto',
args: {
hostChainName: chainInput,
managerMsg: {
accountMsg: {
update_info: {
name: 'test',
},
},
},
})
}, [execRemote, chainInput])
}, [execOnRemote, chainInput])

const { mutate: simulateRemote, isLoading: isSimulating } =
useSimulateExecuteRemoteManager({
useSimulateExecuteRemoteAccount({
accountId: firstAccount,
chainName: firstAccount?.chainName,
})
Expand All @@ -116,7 +113,7 @@ export default function RemotePage() {
console.log('simulating remote account')
simulateRemote({
hostChainName: chainInput,
managerMsg: {
accountMsg: {
update_info: {
name: 'test',
},
Expand Down
2 changes: 1 addition & 1 deletion examples/wagemos-graz-nextjs/abstract.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default defineConfig({
plugins: [
react(),
registry({
contracts: [{ name: 'betting', namespace: 'abstract', version: '0.0.2' }],
contracts: [{ namespace: 'wagemos', name: 'betting', version: '0.0.2' }],
}),
],
})
1 change: 1 addition & 0 deletions examples/wagemos-graz-nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-toast": "^1.1.5",
"@tanstack/react-query": "^4",
"@tanstack/react-query-devtools": "^5.40.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"cosmjs-types": "^0.8.0",
Expand Down
Loading

0 comments on commit f228240

Please sign in to comment.