Skip to content

Commit

Permalink
add aptos-sdk dep, update hyperlane ts-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmovses committed Jun 3, 2024
1 parent 83f04fe commit 9dd34d3
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
---
chainId: 31337
domainId: 31337
name: anvil1
name: anvil
protocol: ethereum
rpcUrls:
- http: http://127.0.0.1:8545
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions typescript/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "3.11.1",
"description": "A command-line utility for common Hyperlane operations",
"dependencies": {
"@aptos-labs/ts-sdk": "1.17.0",
"@hyperlane-xyz/registry": "^1.0.7",
"@hyperlane-xyz/sdk": "3.11.1",
"@hyperlane-xyz/utils": "3.11.1",
Expand Down
14 changes: 12 additions & 2 deletions typescript/sdk/src/providers/ProviderType.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Aptos } from '@aptos-labs/ts-sdk';
import type {
CosmWasmClient,
Contract as CosmWasmContract,
Expand Down Expand Up @@ -32,6 +33,7 @@ export enum ProviderType {
SolanaWeb3 = 'solana-web3',
CosmJs = 'cosmjs',
CosmJsWasm = 'cosmjs-wasm',
Aptos = 'aptos',
}

export const PROTOCOL_TO_DEFAULT_PROVIDER_TYPE: Record<
Expand All @@ -41,6 +43,7 @@ export const PROTOCOL_TO_DEFAULT_PROVIDER_TYPE: Record<
[ProtocolType.Ethereum]: ProviderType.EthersV5,
[ProtocolType.Sealevel]: ProviderType.SolanaWeb3,
[ProtocolType.Cosmos]: ProviderType.CosmJsWasm,
[ProtocolType.Aptos]: ProviderType.Aptos,
};

export type ProviderMap<Value> = Partial<Record<ProviderType, Value>>;
Expand Down Expand Up @@ -130,13 +133,19 @@ export interface CosmJsWasmProvider
provider: Promise<CosmWasmClient>;
}

export interface AptosProvider extends TypedProviderBase<Aptos> {
type: ProviderType.Aptos;
provider: Aptos;
}

export type TypedProvider =
| EthersV5Provider
// | EthersV6Provider
| ViemProvider
| SolanaWeb3Provider
| CosmJsProvider
| CosmJsWasmProvider;
| CosmJsWasmProvider
| AptosProvider;

/**
* Contracts with discriminated union of provider type
Expand Down Expand Up @@ -236,7 +245,8 @@ export type TypedTransaction =
| ViemTransaction
| SolanaWeb3Transaction
| CosmJsTransaction
| CosmJsWasmTransaction;
| CosmJsWasmTransaction
| AptosProvider;

/**
* Transaction receipt/response with discriminated union of provider type
Expand Down
18 changes: 18 additions & 0 deletions typescript/sdk/src/providers/providerBuilders.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Aptos, AptosConfig, Network } from '@aptos-labs/ts-sdk';
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate';
import { StargateClient } from '@cosmjs/stargate';
import { Connection } from '@solana/web3.js';
Expand All @@ -9,6 +10,7 @@ import { ProtocolType, isNumeric } from '@hyperlane-xyz/utils';
import { ChainMetadata, RpcUrl } from '../metadata/chainMetadataTypes.js';

import {
AptosProvider,
CosmJsProvider,
CosmJsWasmProvider,
EthersV5Provider,
Expand Down Expand Up @@ -109,6 +111,20 @@ export function defaultCosmJsWasmProviderBuilder(
};
}

export function defaultAptosProviderBuilder(
rpcUrls: RpcUrl[],
_network: number | string,
): AptosProvider {
if (!rpcUrls.length) throw new Error('No RPC URLs provided');
//@TODO: We hard set the to local for now, but need a way to
// switch this via the rpcUrls array
const config = new AptosConfig({ network: Network.LOCAL });
return {
type: ProviderType.Aptos,
provider: new Aptos(config),
};
}

// Kept for backwards compatibility
export function defaultProviderBuilder(
rpcUrls: RpcUrl[],
Expand All @@ -127,6 +143,7 @@ export const defaultProviderBuilderMap: ProviderBuilderMap = {
[ProviderType.SolanaWeb3]: defaultSolProviderBuilder,
[ProviderType.CosmJs]: defaultCosmJsProviderBuilder,
[ProviderType.CosmJsWasm]: defaultCosmJsWasmProviderBuilder,
[ProviderType.Aptos]: defaultAptosProviderBuilder,
};

export const protocolToDefaultProviderBuilder: Record<
Expand All @@ -136,4 +153,5 @@ export const protocolToDefaultProviderBuilder: Record<
[ProtocolType.Ethereum]: defaultEthersV5ProviderBuilder,
[ProtocolType.Sealevel]: defaultSolProviderBuilder,
[ProtocolType.Cosmos]: defaultCosmJsWasmProviderBuilder,
[ProtocolType.Aptos]: defaultAptosProviderBuilder,
};
7 changes: 7 additions & 0 deletions typescript/sdk/src/token/TokenStandard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export enum TokenStandard {
CwHypNative = 'CwHypNative',
CwHypCollateral = 'CwHypCollateral',
CwHypSynthetic = 'CwHypSynthetic',

// Aptos
AptosNative = 'AptosNative',
}

// Allows for omission of protocol field in token args
Expand Down Expand Up @@ -76,6 +79,9 @@ export const TOKEN_STANDARD_TO_PROTOCOL: Record<TokenStandard, ProtocolType> = {
CwHypNative: ProtocolType.Cosmos,
CwHypCollateral: ProtocolType.Cosmos,
CwHypSynthetic: ProtocolType.Cosmos,

// Aptos
AptosNative: ProtocolType.Aptos,
};

export const TOKEN_STANDARD_TO_PROVIDER_TYPE: Record<
Expand Down Expand Up @@ -153,4 +159,5 @@ export const PROTOCOL_TO_NATIVE_STANDARD: Record<ProtocolType, TokenStandard> =
[ProtocolType.Ethereum]: TokenStandard.EvmNative,
[ProtocolType.Cosmos]: TokenStandard.CosmosNative,
[ProtocolType.Sealevel]: TokenStandard.SealevelNative,
[ProtocolType.Aptos]: TokenStandard.AptosNative,
};
2 changes: 2 additions & 0 deletions typescript/utils/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { BigNumber, ethers } from 'ethers';

export enum ProtocolType {
Aptos = 'aptos',
Ethereum = 'ethereum',
Sealevel = 'sealevel',
Cosmos = 'cosmos',
Expand All @@ -12,6 +13,7 @@ export const ProtocolSmallestUnit = {
[ProtocolType.Ethereum]: 'wei',
[ProtocolType.Sealevel]: 'lamports',
[ProtocolType.Cosmos]: 'uATOM',
[ProtocolType.Aptos]: 'octa',
};

/********* BASIC TYPES *********/
Expand Down
Loading

0 comments on commit 9dd34d3

Please sign in to comment.