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

Add Cosmos support to Utils and SDK #2859

Merged
merged 32 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
65bc79f
Add CW token adapter stubs
yorhodes Oct 26, 2023
c08449b
Implement getbalance
yorhodes Oct 26, 2023
c3cae52
Stash progress on cw20 token
yorhodes Oct 26, 2023
ffe081f
Implement just token adapters first
yorhodes Oct 26, 2023
1820377
Small fixes for build
yorhodes Oct 26, 2023
2a5384b
Add cosmos libraries to SDK and Utils
jmrossy Oct 26, 2023
c66fa69
Implement IHypToken adapters
yorhodes Oct 26, 2023
985a51b
Merge branch 'cosmos' into cw-token-adapter
jmrossy Oct 26, 2023
56aa34d
Rename new adapters for consistency
jmrossy Oct 26, 2023
71ef1d2
Expand ChainMetadata types for cosmos
jmrossy Oct 27, 2023
98869e3
Implement cw router adapter
yorhodes Oct 26, 2023
3643f63
Complete token adapters with type checking
yorhodes Oct 27, 2023
453fbe4
Fix lint
yorhodes Oct 27, 2023
5cf0898
Update gh linguist generated attributes
yorhodes Oct 27, 2023
f7c4954
Test native transferRemote with signer
yorhodes Oct 27, 2023
023c651
Fix test ibc denom plumbing
yorhodes Oct 27, 2023
6406835
Minor fixes for cosmos support
jmrossy Oct 28, 2023
edec28b
Normalize cosmwasm adapter names and args
jmrossy Oct 28, 2023
2fe92ad
Check for IBC denom collateral and cosmos addresess (#2868)
nambrot Oct 29, 2023
7fb2dc7
Set hardcode to untrn
nambrot Oct 29, 2023
0636bc1
Prep 3.1.0-beta0 release
nambrot Oct 29, 2023
92ab1e7
Add monitoring script for neutron (#2872)
aroralanuk Nov 1, 2023
e917fb7
Implement cw core adapter (#2873)
yorhodes Nov 2, 2023
72d7af3
Add naive cosmos native token adapter
yorhodes Nov 2, 2023
c3c5a82
Merge branch 'v3' into cw-token-adapter
nambrot Nov 3, 2023
98ea2a0
Fix merge
nambrot Nov 3, 2023
b3b35f1
Fix cw build
yorhodes Nov 3, 2023
4fe8ed2
Move cosmos token adapter out
yorhodes Nov 3, 2023
dd92caa
Fix lint
yorhodes Nov 3, 2023
23173b3
Resolve core adapter TODO
yorhodes Nov 3, 2023
d017cac
Move to readonly test to be safe
yorhodes Nov 3, 2023
9b4c832
Add dsrv/sg-1
nambrot Nov 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions typescript/sdk/src/core/adapters/CwCoreAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { HexString } from '@hyperlane-xyz/utils';

import { BaseCwAdapter } from '../../app/MultiProtocolApp';
import { ChainName } from '../../types';

import { ProviderType, TypedTransactionReceipt } from '../../providers/ProviderType';
import { ICoreAdapter } from './types';

// This adapter just routes to the HyperlaneCore
// Which implements the needed functionality for Cw chains
// TODO deprecate HyperlaneCore and replace all Cw-specific classes with adapters
yorhodes marked this conversation as resolved.
Show resolved Hide resolved
export class CwCoreAdapter extends BaseCwAdapter implements ICoreAdapter {
public readonly contractAddress = this.addresses.mailbox;

extractMessageIds(
sourceTx: TypedTransactionReceipt,
): Array<{ messageId: string; destination: ChainName }> {
if (sourceTx.type !== ProviderType.Cosmos) {
throw new Error(
`Unsupported provider type for CosmosCoreAdapter ${sourceTx.type}`,
);
}
// TODO: parse mailbox logs and extract message ids
throw new Error("Method not implemented.");
}

async waitForMessageProcessed(
messageId: HexString,
destination: ChainName,
delayMs?: number,
maxAttempts?: number,
): Promise<void> {
throw new Error("Method not implemented.");
}
}
100 changes: 100 additions & 0 deletions typescript/sdk/src/router/adapters/CwRouterAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { Address, Domain } from '@hyperlane-xyz/utils';

import { BaseCwAdapter } from '../../app/MultiProtocolApp';
import { MultiProtocolProvider } from '../../providers/MultiProtocolProvider';
import { ChainName } from '../../types';

import { IGasRouterAdapter, IRouterAdapter } from './types';

// TODO: import from ts bindings
type IsmResponse = {
ism: Address;
};

type OwnerResponse = {
owner: Address;
};

type DomainsResponse = {
domains: number[];
};

type DomainRouteSet = {
domain: number;
route: string;
};

type RouteResponse = {
route: DomainRouteSet;
};

type RoutesResponse = {
routes: DomainRouteSet[];
};

export class CwRouterAdapter extends BaseCwAdapter implements IRouterAdapter {
public readonly contractAddress: Address;

constructor(
public readonly chainName: ChainName,
public readonly multiProvider: MultiProtocolProvider<any>,
public readonly addresses: { router: Address },
) {
super(chainName, multiProvider, addresses);
this.contractAddress = addresses.router;
}

async interchainSecurityModule(): Promise<Address> {
const ismResponse: IsmResponse =
await this.getProvider().queryContractSmart(this.contractAddress, {
get_ism: {},
});
return ismResponse.ism;
}

async owner(): Promise<Address> {
const ownerResponse: OwnerResponse =
await this.getProvider().queryContractSmart(this.contractAddress, {
owner: {},
});
return ownerResponse.owner;
}

async remoteDomains(): Promise<Domain[]> {
const domainsResponse: DomainsResponse =
await this.getProvider().queryContractSmart(this.contractAddress, {
domains: {},
});
return domainsResponse.domains;
}

async remoteRouter(remoteDomain: Domain): Promise<Address> {
const routeResponse: RouteResponse =
await this.getProvider().queryContractSmart(this.contractAddress, {
get_route: {
domain: remoteDomain,
},
});
return routeResponse.route.route;
}

async remoteRouters(): Promise<Array<{ domain: Domain; address: Address }>> {
const routesResponse: RoutesResponse =
await this.getProvider().queryContractSmart(this.contractAddress, {
list_routes: {},
});
return routesResponse.routes.map((r) => ({
domain: r.domain,
address: r.route,
}));
}
}

export class CwGasRouterAdapter
extends CwRouterAdapter
implements IGasRouterAdapter
{
async quoteGasPayment(_: ChainName): Promise<string> {
throw new Error('Method not implemented.');
}
}
9 changes: 5 additions & 4 deletions typescript/sdk/src/token/adapters/ITokenAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ export interface ITokenAdapter {
}

export interface IHypTokenAdapter extends ITokenAdapter {
getDomains(): Promise<Domain[]>;
getRouterAddress(domain: Domain): Promise<Buffer>;
getAllRouters(): Promise<Array<{ domain: Domain; address: Buffer }>>;
quoteGasPayment(destination: Domain): Promise<string>;
// TODO: migrate into IRouterAdapter?
// getDomains(): Promise<Domain[]>;
// getRouterAddress(domain: Domain): Promise<Buffer>;
// getAllRouters(): Promise<Array<{ domain: Domain; address: Buffer }>>;
// quoteGasPayment(destination: Domain): Promise<string>;
populateTransferRemoteTx(
TransferParams: TransferRemoteParams,
): unknown | Promise<unknown>;
Expand Down