Skip to content

Commit

Permalink
fix: apply more permissive address argument types
Browse files Browse the repository at this point in the history
  • Loading branch information
anondev2323 committed Oct 17, 2023
1 parent 43af821 commit da1f8eb
Show file tree
Hide file tree
Showing 20 changed files with 138 additions and 135 deletions.
2 changes: 1 addition & 1 deletion core/definitions/src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface PlatformUtils<P extends PlatformName> {
getDecimals(
chain: ChainName,
rpc: RpcConnection<P>,
token: NativeAddress<P> | UniversalAddress | "native",
token: AnyAddress | "native",
): Promise<bigint>;
getBalance(
chain: ChainName,
Expand Down
10 changes: 5 additions & 5 deletions core/definitions/src/protocols/cctp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
deserializeLayout,
uint8ArrayToHexByteString,
} from "@wormhole-foundation/sdk-base";
import { ChainAddress, UniversalOrNative } from "../address";
import { ChainAddress } from "../address";
import { CircleMessageId } from "../attestation";
import { universalAddressItem } from "../layout-items";
import "../payloads/connect";
import { RpcConnection } from "../rpc";
import { TokenId } from "../types";
import { AnyAddress, TokenId } from "../types";
import { UnsignedTransaction } from "../unsignedTransaction";
import { keccak256 } from "../utils";

Expand Down Expand Up @@ -55,7 +55,7 @@ export type CircleTransferMessage = {
export interface AutomaticCircleBridge<P extends PlatformName> {
transfer(
token: ChainAddress,
sender: UniversalOrNative<P>,
sender: AnyAddress,
recipient: ChainAddress,
amount: bigint,
nativeGas?: bigint,
Expand All @@ -66,13 +66,13 @@ export interface AutomaticCircleBridge<P extends PlatformName> {
// https://github.com/circlefin/evm-cctp-contracts
export interface CircleBridge<P extends PlatformName> {
redeem(
sender: UniversalOrNative<P>,
sender: AnyAddress,
message: string,
attestation: string,
): AsyncGenerator<UnsignedTransaction>;
transfer(
token: ChainAddress,
sender: UniversalOrNative<P>,
sender: AnyAddress,
recipient: ChainAddress,
amount: bigint,
): AsyncGenerator<UnsignedTransaction>;
Expand Down
4 changes: 2 additions & 2 deletions core/definitions/src/protocols/core.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PlatformName } from "@wormhole-foundation/sdk-base";
import { UniversalOrNative } from "../address";
import { AnyAddress } from "../types";
import { UnsignedTransaction } from "../unsignedTransaction";
import { RpcConnection } from "../rpc";

Expand All @@ -15,7 +15,7 @@ export function supportsWormholeCore<P extends PlatformName>(

export interface WormholeCore<P extends PlatformName> {
publishMessage(
sender: UniversalOrNative<P>,
sender: AnyAddress,
message: string | Uint8Array
): AsyncGenerator<UnsignedTransaction>;
// TODO: parseTransactionDetails
Expand Down
8 changes: 4 additions & 4 deletions core/definitions/src/protocols/ibc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {
PlatformName,
toChainId,
} from "@wormhole-foundation/sdk-base";
import { ChainAddress, NativeAddress, UniversalOrNative } from "../address";
import { ChainAddress, NativeAddress } from "../address";
import { IbcMessageId, WormholeMessageId } from "../attestation";
import { RpcConnection } from "../rpc";
import { TokenId, TxHash } from "../types";
import { AnyAddress, TokenId, TxHash } from "../types";
import { UnsignedTransaction } from "../unsignedTransaction";

// Configuration for a transfer through the Gateway
Expand Down Expand Up @@ -209,9 +209,9 @@ export function supportsIbcBridge<P extends PlatformName>(
export interface IbcBridge<P extends PlatformName> {
//alternative naming: initiateTransfer
transfer(
sender: UniversalOrNative<P>,
sender: AnyAddress,
recipient: ChainAddress,
token: UniversalOrNative<P> | "native",
token: AnyAddress | "native",
amount: bigint,
payload?: Uint8Array,
): AsyncGenerator<UnsignedTransaction>;
Expand Down
26 changes: 13 additions & 13 deletions core/definitions/src/protocols/tokenBridge.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PlatformName } from "@wormhole-foundation/sdk-base";
import { UniversalOrNative, NativeAddress, ChainAddress } from "../address";
import { TokenId } from "../types";
import { NativeAddress, ChainAddress } from "../address";
import { AnyAddress, TokenId } from "../types";
import { VAA } from "../vaa";
import { UnsignedTransaction } from "../unsignedTransaction";
import "../payloads/tokenBridge";
Expand Down Expand Up @@ -36,9 +36,9 @@ export function supportsAutomaticTokenBridge<P extends PlatformName>(

export interface TokenBridge<P extends PlatformName> {
// checks a native address to see if its a wrapped version
isWrappedAsset(nativeAddress: UniversalOrNative<P>): Promise<boolean>;
isWrappedAsset(nativeAddress: AnyAddress): Promise<boolean>;
// returns the original asset with its foreign chain
getOriginalAsset(nativeAddress: UniversalOrNative<P>): Promise<TokenId>;
getOriginalAsset(nativeAddress: AnyAddress): Promise<TokenId>;
// returns the wrapped version of the native asset
getWrappedNative(): Promise<NativeAddress<P>>;

Expand All @@ -53,24 +53,24 @@ export interface TokenBridge<P extends PlatformName> {
): Promise<boolean>;
//signer required:
createAttestation(
token_to_attest: UniversalOrNative<P>,
payer?: UniversalOrNative<P>
token_to_attest: AnyAddress,
payer?: AnyAddress
): AsyncGenerator<UnsignedTransaction>;
submitAttestation(
vaa: VAA<"AttestMeta">,
payer?: UniversalOrNative<P>
payer?: AnyAddress
): AsyncGenerator<UnsignedTransaction>;
//alternative naming: initiateTransfer
transfer(
sender: UniversalOrNative<P>,
sender: AnyAddress,
recipient: ChainAddress,
token: UniversalOrNative<P> | "native",
token: AnyAddress | "native",
amount: bigint,
payload?: Uint8Array
): AsyncGenerator<UnsignedTransaction>;
//alternative naming: completeTransfer
redeem(
sender: UniversalOrNative<P>,
sender: AnyAddress,
vaa: VAA<"Transfer"> | VAA<"TransferWithPayload">,
unwrapNative?: boolean //default: true
): AsyncGenerator<UnsignedTransaction>;
Expand All @@ -79,15 +79,15 @@ export interface TokenBridge<P extends PlatformName> {

export interface AutomaticTokenBridge<P extends PlatformName> {
transfer(
sender: UniversalOrNative<P>,
sender: AnyAddress,
recipient: ChainAddress,
token: UniversalOrNative<P> | "native",
token: AnyAddress | "native",
amount: bigint,
relayerFee: bigint,
nativeGas?: bigint
): AsyncGenerator<UnsignedTransaction>;
redeem(
sender: UniversalOrNative<P>,
sender: AnyAddress,
vaa: VAA<"TransferWithPayload">
): AsyncGenerator<UnsignedTransaction>;
getRelayerFee(
Expand Down
10 changes: 5 additions & 5 deletions core/definitions/src/relayer.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Chain, PlatformName } from "@wormhole-foundation/sdk-base";
import { UniversalOrNative } from "./address";
import { AnyAddress } from "./types";

export interface Relayer<P extends PlatformName> {
relaySupported(chain: Chain): boolean;
getRelayerFee(
sourceChain: Chain,
destChain: Chain,
tokenId: UniversalOrNative<P>,
tokenId: AnyAddress,
): Promise<bigint>;
// TODO: What should this be named?
// I don't think it should return an UnisgnedTransaction
// rather it should take some signing callbacks and
// a ref to track the progress
startTransferWithRelay(
token: UniversalOrNative<P> | "native",
token: AnyAddress | "native",
amount: bigint,
toNativeToken: string,
sendingChain: Chain,
Expand All @@ -24,13 +24,13 @@ export interface Relayer<P extends PlatformName> {
): Promise<any>;
calculateNativeTokenAmt(
destChain: Chain,
tokenId: UniversalOrNative<P>,
tokenId: AnyAddress,
amount: bigint,
walletAddress: string,
): Promise<bigint>;
calculateMaxSwapAmount(
destChain: Chain,
tokenId: UniversalOrNative<P>,
tokenId: AnyAddress,
walletAddress: string,
): Promise<bigint>;
}
Expand Down
15 changes: 7 additions & 8 deletions core/definitions/src/testing/mocks/tokenBridge.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { PlatformName } from "@wormhole-foundation/sdk-base";
import {
AnyAddress,
ChainAddress,
NativeAddress,
RpcConnection,
TokenBridge,
TokenId,
UniversalOrNative,
UnsignedTransaction,
VAA,
} from "../..";
Expand All @@ -19,10 +18,10 @@ import {
export class MockTokenBridge<P extends PlatformName> implements TokenBridge<P> {
constructor(readonly rpc: RpcConnection<P>) {}

isWrappedAsset(token: UniversalOrNative<P>): Promise<boolean> {
isWrappedAsset(token: AnyAddress): Promise<boolean> {
throw new Error("Method not implemented.");
}
getOriginalAsset(token: UniversalOrNative<P>): Promise<ChainAddress> {
getOriginalAsset(token: AnyAddress): Promise<ChainAddress> {
throw new Error("Method not implemented.");
}
hasWrappedAsset(original: ChainAddress): Promise<boolean> {
Expand All @@ -37,7 +36,7 @@ export class MockTokenBridge<P extends PlatformName> implements TokenBridge<P> {
throw new Error("Method not implemented.");
}
createAttestation(
address: UniversalOrNative<P>,
address: AnyAddress,
): AsyncGenerator<UnsignedTransaction> {
throw new Error("Method not implemented.");
}
Expand All @@ -47,16 +46,16 @@ export class MockTokenBridge<P extends PlatformName> implements TokenBridge<P> {
throw new Error("Method not implemented.");
}
transfer(
sender: UniversalOrNative<P>,
sender: AnyAddress,
recipient: ChainAddress,
token: "native" | UniversalOrNative<P>,
token: "native" | AnyAddress,
amount: bigint,
payload?: Uint8Array | undefined,
): AsyncGenerator<UnsignedTransaction> {
throw new Error("Method not implemented.");
}
redeem(
sender: UniversalOrNative<P>,
sender: AnyAddress,
vaa: VAA<"Transfer"> | VAA<"TransferWithPayload">,
unwrapNative?: boolean | undefined,
): AsyncGenerator<UnsignedTransaction> {
Expand Down
11 changes: 6 additions & 5 deletions platforms/cosmwasm/src/protocols/ibc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ import { CosmwasmContracts } from "../contracts";
import { Gateway } from "../gateway";
import { CosmwasmPlatform } from "../platform";
import { CosmwasmUtils } from "../platformUtils";
import { CosmwasmChainName, UniversalOrCosmwasm } from "../types";
import { CosmwasmChainName, AnyCosmwasmAddress } from "../types";
import {
CosmwasmTransaction,
CosmwasmUnsignedTransaction,
computeFee,
} from "../unsignedTransaction";
import { CosmwasmAddress } from "../address";

const millisToNano = (seconds: number) => seconds * 1_000_000;

Expand Down Expand Up @@ -87,12 +88,12 @@ export class CosmwasmIbcBridge implements IbcBridge<"Cosmwasm"> {
}

async *transfer(
sender: UniversalOrCosmwasm,
sender: AnyCosmwasmAddress,
recipient: ChainAddress,
token: UniversalOrCosmwasm | "native",
token: AnyCosmwasmAddress | "native",
amount: bigint,
): AsyncGenerator<CosmwasmUnsignedTransaction> {
const senderAddress = sender.toString();
const senderAddress = new CosmwasmAddress(sender).toString();
const nonce = Math.round(Math.random() * 10000);

// TODO: needs heavy testing
Expand Down Expand Up @@ -124,7 +125,7 @@ export class CosmwasmIbcBridge implements IbcBridge<"Cosmwasm"> {
const timeout = millisToNano(Date.now() + IBC_TIMEOUT_MILLIS);
const memo = JSON.stringify(payload);

const ibcDenom = Gateway.deriveIbcDenom(this.chain, token.toString());
const ibcDenom = token === 'native' ? CosmwasmPlatform.getNativeDenom(this.chain) : Gateway.deriveIbcDenom(this.chain, new CosmwasmAddress(token).toString());
const ibcToken = coin(amount.toString(), ibcDenom.toString());

const ibcMessage: MsgTransferEncodeObject = {
Expand Down
Loading

0 comments on commit da1f8eb

Please sign in to comment.