Skip to content

Commit

Permalink
Implement SDK support
Browse files Browse the repository at this point in the history
  • Loading branch information
yorhodes committed Apr 18, 2024
1 parent 4c6c6aa commit 3fbbc6a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
2 changes: 2 additions & 0 deletions typescript/sdk/src/token/Token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ const STANDARD_TO_TOKEN: Record<TokenStandard, TokenArgs | null> = {

// Fuel
[TokenStandard.FuelNative]: null,
[TokenStandard.EvmHypXERC20Collateral]: null,
[TokenStandard.EvmHypFiatCollateral]: null,
};

const PROTOCOL_TO_ADDRESS: Partial<Record<ProtocolType, Address>> = {
Expand Down
10 changes: 10 additions & 0 deletions typescript/sdk/src/token/TokenStandard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export enum TokenStandard {
EvmNative = 'EvmNative',
EvmHypNative = 'EvmHypNative',
EvmHypCollateral = 'EvmHypCollateral',
EvmHypXERC20Collateral = 'EvmHypXERC20Collateral',
EvmHypFiatCollateral = 'EvmHypFiatCollateral',
EvmHypcollateralVault = 'EvmHypcollateralVault',
EvmHypSynthetic = 'EvmHypSynthetic',

Expand Down Expand Up @@ -53,6 +55,8 @@ export const TOKEN_STANDARD_TO_PROTOCOL: Record<TokenStandard, ProtocolType> = {
EvmHypCollateral: ProtocolType.Ethereum,
EvmHypcollateralVault: ProtocolType.Ethereum,
EvmHypSynthetic: ProtocolType.Ethereum,
EvmHypXERC20Collateral: ProtocolType.Ethereum,
EvmHypFiatCollateral: ProtocolType.Ethereum,

// Sealevel (Solana)
SealevelSpl: ProtocolType.Sealevel,
Expand Down Expand Up @@ -98,6 +102,8 @@ export const TOKEN_NFT_STANDARDS = [
export const TOKEN_COLLATERALIZED_STANDARDS = [
TokenStandard.EvmHypCollateral,
TokenStandard.EvmHypNative,
TokenStandard.EvmHypXERC20Collateral,
TokenStandard.EvmHypFiatCollateral,
TokenStandard.SealevelHypCollateral,
TokenStandard.SealevelHypNative,
TokenStandard.CwHypCollateral,
Expand All @@ -107,6 +113,8 @@ export const TOKEN_COLLATERALIZED_STANDARDS = [
export const TOKEN_HYP_STANDARDS = [
TokenStandard.EvmHypNative,
TokenStandard.EvmHypCollateral,
TokenStandard.EvmHypXERC20Collateral,
TokenStandard.EvmHypFiatCollateral,
TokenStandard.EvmHypSynthetic,
TokenStandard.SealevelHypNative,
TokenStandard.SealevelHypCollateral,
Expand Down Expand Up @@ -136,6 +144,8 @@ export const TOKEN_TYPE_TO_STANDARD: Record<TokenType, TokenStandard> = {
[TokenType.native]: TokenStandard.EvmHypNative,
[TokenType.collateral]: TokenStandard.EvmHypCollateral,
[TokenType.collateralVault]: TokenStandard.EvmHypcollateralVault,
[TokenType.collateralFiat]: TokenStandard.EvmHypFiatCollateral,
[TokenType.collateralXERC20]: TokenStandard.EvmHypXERC20Collateral,
[TokenType.collateralUri]: TokenStandard.EvmHypCollateral,
[TokenType.fastCollateral]: TokenStandard.EvmHypCollateral,
[TokenType.synthetic]: TokenStandard.EvmHypSynthetic,
Expand Down
6 changes: 6 additions & 0 deletions typescript/sdk/src/token/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export enum TokenType {
syntheticUri = 'syntheticUri',
collateral = 'collateral',
collateralVault = 'collateralVault',
collateralXERC20 = 'collateralXERC20',
collateralFiat = 'collateralFiat',
fastCollateral = 'fastCollateral',
collateralUri = 'collateralUri',
native = 'native',
Expand Down Expand Up @@ -40,6 +42,8 @@ export type SyntheticConfig = TokenMetadata & {
export type CollateralConfig = {
type:
| TokenType.collateral
| TokenType.collateralXERC20
| TokenType.collateralFiat
| TokenType.collateralUri
| TokenType.fastCollateral
| TokenType.fastSynthetic
Expand All @@ -56,6 +60,8 @@ export const isCollateralConfig = (
config: TokenConfig,
): config is CollateralConfig =>
config.type === TokenType.collateral ||
config.type === TokenType.collateralXERC20 ||
config.type === TokenType.collateralFiat ||
config.type === TokenType.collateralUri ||
config.type === TokenType.fastCollateral ||
config.type == TokenType.collateralVault;
Expand Down
6 changes: 6 additions & 0 deletions typescript/sdk/src/token/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
HypERC721URICollateral__factory,
HypERC721URIStorage__factory,
HypERC721__factory,
HypFiatTokenCollateral__factory,
HypNativeScaled__factory,
HypNative__factory,
HypXERC20Collateral__factory,
} from '@hyperlane-xyz/core';

import { proxiedFactories } from '../router/types.js';
Expand All @@ -21,6 +23,8 @@ export const hypERC20contracts = {
[TokenType.fastSynthetic]: 'FastHypERC20',
[TokenType.synthetic]: 'HypERC20',
[TokenType.collateral]: 'HypERC20Collateral',
[TokenType.collateralFiat]: 'HypFiatTokenCollateral',
[TokenType.collateralXERC20]: 'HypXERC20Collateral',
[TokenType.collateralVault]: 'HypERC20CollateralVaultDeposit',
[TokenType.native]: 'HypNative',
[TokenType.nativeScaled]: 'HypNativeScaled',
Expand All @@ -33,6 +37,8 @@ export const hypERC20Tokenfactories = {
[TokenType.synthetic]: new HypERC20__factory(),
[TokenType.collateral]: new HypERC20Collateral__factory(),
[TokenType.collateralVault]: new HypERC20CollateralVaultDeposit__factory(),
[TokenType.collateralFiat]: new HypFiatTokenCollateral__factory(),
[TokenType.collateralXERC20]: new HypXERC20Collateral__factory(),
[TokenType.native]: new HypNative__factory(),
[TokenType.nativeScaled]: new HypNativeScaled__factory(),
};
Expand Down
21 changes: 2 additions & 19 deletions typescript/sdk/src/token/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ import {
TokenMetadata,
TokenType,
isCollateralConfig,
isCollateralVaultConfig,
isErc20Metadata,
isFastConfig,
isNativeConfig,
isSyntheticConfig,
isTokenMetadata,
isUriConfig,
} from './config.js';
import {
HypERC20Factories,
HypERC20contracts,
HypERC721Factories,
HypERC721contracts,
hypERC20contracts,
Expand Down Expand Up @@ -67,23 +66,7 @@ export class HypERC20Deployer extends GasRouterDeployer<
}

routerContractKey(config: ERC20RouterConfig) {
if (isCollateralConfig(config)) {
if (isFastConfig(config)) {
return TokenType.fastCollateral;
} else if (isCollateralVaultConfig(config)) {
return TokenType.collateralVault;
} else {
return TokenType.collateral;
}
} else if (isNativeConfig(config)) {
return config.scale ? TokenType.nativeScaled : TokenType.native;
} else if (isSyntheticConfig(config)) {
return isFastConfig(config)
? TokenType.fastSynthetic
: TokenType.synthetic;
} else {
throw new Error('Unknown collateral type when constructing router name');
}
return config.type as keyof HypERC20contracts;
}

async constructorArgs<K extends keyof HypERC20Factories>(
Expand Down

0 comments on commit 3fbbc6a

Please sign in to comment.