Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rohan-agarwal-coinbase committed Sep 27, 2024
1 parent 83d22b3 commit 2b240ab
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 56 deletions.
8 changes: 4 additions & 4 deletions src/coinbase/address/external_address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ import { Amount, StakeOptionsMode } from "../types";
import { Coinbase } from "../coinbase";
import Decimal from "decimal.js";
import { Asset } from "../asset";
import { StakingOperation } from "../staking_operation";
import { IStakingOperation, StakingOperation } from "../staking_operation";

export interface IExternalAddress extends IAddress {
buildStakeOperation(
amount: Amount,
assetId: string,
mode: StakeOptionsMode,
options: { [key: string]: string },
): Promise<StakingOperation>;
): Promise<IStakingOperation>;
buildUnstakeOperation(
amount: Amount,
assetId: string,
mode: StakeOptionsMode,
options: { [key: string]: string },
): Promise<StakingOperation>;
): Promise<IStakingOperation>;
buildClaimStakeOperation(
amount: Amount,
assetId: string,
mode: StakeOptionsMode,
options: { [key: string]: string },
): Promise<StakingOperation>;
): Promise<IStakingOperation>;
}

/**
Expand Down
34 changes: 17 additions & 17 deletions src/coinbase/address/wallet_address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { Address, IAddress } from "../address";
import { Asset } from "../asset";
import { Coinbase } from "../coinbase";
import { ArgumentError } from "../errors";
import { Trade } from "../trade";
import { ITrade, Trade } from "../trade";
import { ITransfer, Transfer } from "../transfer";
import { ContractInvocation } from "../contract_invocation";
import { ContractInvocation, IContractInvocation } from "../contract_invocation";
import {
Amount,
CreateTransferOptions,
Expand All @@ -21,50 +21,50 @@ import {
} from "../types";
import { delay } from "../utils";
import { Wallet as WalletClass } from "../wallet";
import { StakingOperation } from "../staking_operation";
import { PayloadSignature } from "../payload_signature";
import { SmartContract } from "../smart_contract";
import { IStakingOperation, StakingOperation } from "../staking_operation";
import { IPayloadSignature, PayloadSignature } from "../payload_signature";
import { ISmartContract, SmartContract } from "../smart_contract";

export interface IWalletAddress extends IAddress {
getWalletId(): string;
setKey(key: ethers.Wallet): void;
export(): string;
canSign(): boolean;
listTrades(): Promise<Trade[]>;
listTrades(): Promise<ITrade[]>;
listTransfers(): Promise<ITransfer[]>;
createTransfer(options: CreateTransferOptions): Promise<ITransfer>;
createTrade(options: CreateTradeOptions): Promise<Trade>;
invokeContract(options: CreateContractInvocationOptions): Promise<ContractInvocation>;
deployToken(options: CreateERC20Options): Promise<SmartContract>;
deployNFT(options: CreateERC721Options): Promise<SmartContract>;
deployMultiToken(options: CreateERC1155Options): Promise<SmartContract>;
createTrade(options: CreateTradeOptions): Promise<ITrade>;
invokeContract(options: CreateContractInvocationOptions): Promise<IContractInvocation>;
deployToken(options: CreateERC20Options): Promise<ISmartContract>;
deployNFT(options: CreateERC721Options): Promise<ISmartContract>;
deployMultiToken(options: CreateERC1155Options): Promise<ISmartContract>;
createStake(
amount: Amount,
assetId: string,
mode: StakeOptionsMode,
options: { [key: string]: string },
timeoutSeconds: number,
intervalSeconds: number,
): Promise<StakingOperation>;
): Promise<IStakingOperation>;
createUnstake(
amount: Amount,
assetId: string,
mode: StakeOptionsMode,
options: { [key: string]: string },
timeoutSeconds: number,
intervalSeconds: number,
): Promise<StakingOperation>;
): Promise<IStakingOperation>;
createClaimStake(
amount: Amount,
assetId: string,
mode: StakeOptionsMode,
options: { [key: string]: string },
timeoutSeconds: number,
intervalSeconds: number,
): Promise<StakingOperation>;
createPayloadSignature(payload: string): Promise<PayloadSignature>;
getPayloadSignature(signatureId: string): Promise<PayloadSignature>;
listPayloadSignatures(): Promise<PayloadSignature[]>;
): Promise<IStakingOperation>;
createPayloadSignature(payload: string): Promise<IPayloadSignature>;
getPayloadSignature(signatureId: string): Promise<IPayloadSignature>;
listPayloadSignatures(): Promise<IPayloadSignature[]>;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/coinbase/contract_invocation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Decimal } from "decimal.js";
import { TransactionStatus } from "./types";
import { Transaction } from "./transaction";
import { ITransaction, Transaction } from "./transaction";
import { Coinbase } from "./coinbase";
import { ContractInvocation as ContractInvocationModel } from "../client/api";
import { ethers } from "ethers";
Expand All @@ -21,9 +21,9 @@ export interface IContractInvocation {
getRawTransaction(): ethers.Transaction;
sign(key: ethers.Wallet): Promise<string>;
getStatus(): TransactionStatus | undefined;
getTransaction(): Transaction;
getTransaction(): ITransaction;
getTransactionLink(): string;
broadcast(): Promise<ContractInvocation>;
broadcast(): Promise<IContractInvocation>;
wait({
intervalSeconds,
timeoutSeconds,
Expand Down
11 changes: 11 additions & 0 deletions src/coinbase/staking_operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ export interface IStakingOperation {
isTerminalState(): boolean;
isFailedState(): boolean;
isCompleteState(): boolean;
getTransactions(): Transaction[];
getSignedVoluntaryExitMessages(): string[];
reload(): Promise<void>;
wait({
intervalSeconds,
timeoutSeconds,
}: {
intervalSeconds: number;
timeoutSeconds: number;
}): Promise<StakingOperationModel>;
sign(key: ethers.Wallet): Promise<void>;
}

/**
Expand Down
63 changes: 32 additions & 31 deletions src/coinbase/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { ethers } from "ethers";
import * as fs from "fs";
import * as secp256k1 from "secp256k1";
import { Address as AddressModel, Wallet as WalletModel } from "../client";
import { Address } from "./address";
import { Address, IAddress } from "./address";

Check failure on line 8 in src/coinbase/wallet.ts

View workflow job for this annotation

GitHub Actions / lint

'Address' is defined but never used
import { IWalletAddress, WalletAddress } from "./address/wallet_address";
import { Asset } from "./asset";
import { Balance } from "./balance";
import { BalanceMap } from "./balance_map";
import { Coinbase } from "./coinbase";
import { ArgumentError } from "./errors";
import { FaucetTransaction } from "./faucet_transaction";
import { Trade } from "./trade";
import { FaucetTransaction, IFaucetTransaction } from "./faucet_transaction";
import { ITrade, Trade } from "./trade";

Check failure on line 16 in src/coinbase/wallet.ts

View workflow job for this annotation

GitHub Actions / lint

'Trade' is defined but never used
import { ITransfer } from "./transfer";
import {
Amount,
Expand All @@ -33,21 +33,22 @@ import {
CreateERC1155Options,
} from "./types";
import { convertStringToHex, delay, formatDate, getWeekBackDate } from "./utils";
import { StakingOperation } from "./staking_operation";
import { IStakingOperation, StakingOperation } from "./staking_operation";

Check failure on line 36 in src/coinbase/wallet.ts

View workflow job for this annotation

GitHub Actions / lint

'StakingOperation' is defined but never used
import { StakingReward } from "./staking_reward";
import { StakingBalance } from "./staking_balance";
import { PayloadSignature } from "./payload_signature";
import { ContractInvocation } from "../coinbase/contract_invocation";
import { SmartContract } from "./smart_contract";
import { Webhook } from "./webhook";
import { IPayloadSignature, PayloadSignature } from "./payload_signature";

Check failure on line 39 in src/coinbase/wallet.ts

View workflow job for this annotation

GitHub Actions / lint

'PayloadSignature' is defined but never used
import { ContractInvocation, IContractInvocation } from "../coinbase/contract_invocation";

Check failure on line 40 in src/coinbase/wallet.ts

View workflow job for this annotation

GitHub Actions / lint

'ContractInvocation' is defined but never used
import { ISmartContract, SmartContract } from "./smart_contract";

Check failure on line 41 in src/coinbase/wallet.ts

View workflow job for this annotation

GitHub Actions / lint

'SmartContract' is defined but never used
import { IWebhook, Webhook } from "./webhook";

export interface IWallet {
getId(): string;
getDefaultAddress(): Promise<IWalletAddress>;
listAddresses(): Promise<IWalletAddress[]>;
getAddress(addressId: string): Promise<IWalletAddress | undefined>;
createAddress(): Promise<Address>;
createTrade(options: CreateTradeOptions): Promise<Trade>;
createAddress(): Promise<IAddress>;
setSeed(seed: string): void;
createTrade(options: CreateTradeOptions): Promise<ITrade>;
stakeableBalance(
asset_id: string,
mode?: StakeOptionsMode,
Expand Down Expand Up @@ -84,7 +85,7 @@ export interface IWallet {
saveSeed(filePath: string, encrypt?: boolean): string;
loadSeed(filePath: string): Promise<string>;
canSign(): boolean;
faucet(assetId?: string): Promise<FaucetTransaction>;
faucet(assetId?: string): Promise<IFaucetTransaction>;
createTransfer(options: CreateTransferOptions): Promise<ITransfer>;
createStake(
amount: Amount,
Expand All @@ -93,30 +94,30 @@ export interface IWallet {
options?: { [key: string]: string },
timeoutSeconds?: number,
intervalSeconds?: number,
): Promise<StakingOperation>;
): Promise<IStakingOperation>;
createUnstake(
amount: Amount,
assetId: string,
mode?: StakeOptionsMode,
options?: { [key: string]: string },
timeoutSeconds?: number,
intervalSeconds?: number,
): Promise<StakingOperation>;
): Promise<IStakingOperation>;
createClaimStake(
amount: Amount,
assetId: string,
mode?: StakeOptionsMode,
options?: { [key: string]: string },
timeoutSeconds?: number,
intervalSeconds?: number,
): Promise<StakingOperation>;
invokeContract(options: CreateContractInvocationOptions): Promise<ContractInvocation>;
): Promise<IStakingOperation>;
invokeContract(options: CreateContractInvocationOptions): Promise<IContractInvocation>;
export(): WalletData;
createWebhook(notificationUri: string): Promise<Webhook>;
deployToken(options: CreateERC20Options): Promise<SmartContract>;
deployNFT(options: CreateERC721Options): Promise<SmartContract>;
deployMultiToken(options: CreateERC1155Options): Promise<SmartContract>;
createPayloadSignature(unsignedPayload: string): Promise<PayloadSignature>;
createWebhook(notificationUri: string): Promise<IWebhook>;
deployToken(options: CreateERC20Options): Promise<ISmartContract>;
deployNFT(options: CreateERC721Options): Promise<ISmartContract>;
deployMultiToken(options: CreateERC1155Options): Promise<ISmartContract>;
createPayloadSignature(unsignedPayload: string): Promise<IPayloadSignature>;
}

/**
Expand Down Expand Up @@ -293,7 +294,7 @@ export class Wallet implements IWallet {
* @returns The new Address.
* @throws {APIError} - If the address creation fails.
*/
public async createAddress(): Promise<Address> {
public async createAddress(): Promise<IAddress> {
let payload, key;
if (!Coinbase.useServerSigner) {
// TODO: Coordinate this value with concurrent calls to createAddress.
Expand Down Expand Up @@ -395,7 +396,7 @@ export class Wallet implements IWallet {
* @throws {Error} If the private key is not loaded, or if the asset IDs are unsupported, or if there are insufficient funds.
* @returns The created Trade object.
*/
public async createTrade(options: CreateTradeOptions): Promise<Trade> {
public async createTrade(options: CreateTradeOptions): Promise<ITrade> {
return (await this.getDefaultAddress()).createTrade(options);
}

Expand Down Expand Up @@ -526,7 +527,7 @@ export class Wallet implements IWallet {
options: { [key: string]: string } = {},
timeoutSeconds = 60,
intervalSeconds = 0.2,
): Promise<StakingOperation> {
): Promise<IStakingOperation> {
return (await this.getDefaultAddress()).createStake(
amount,
assetId,
Expand Down Expand Up @@ -556,7 +557,7 @@ export class Wallet implements IWallet {
options: { [key: string]: string } = {},
timeoutSeconds = 60,
intervalSeconds = 0.2,
): Promise<StakingOperation> {
): Promise<IStakingOperation> {
return (await this.getDefaultAddress()).createUnstake(
amount,
assetId,
Expand Down Expand Up @@ -586,7 +587,7 @@ export class Wallet implements IWallet {
options: { [key: string]: string } = {},
timeoutSeconds = 60,
intervalSeconds = 0.2,
): Promise<StakingOperation> {
): Promise<IStakingOperation> {
return (await this.getDefaultAddress()).createClaimStake(
amount,
assetId,
Expand Down Expand Up @@ -825,7 +826,7 @@ export class Wallet implements IWallet {
* @throws {APIError} if the API request to create a Payload Signature fails.
* @throws {Error} if the default address is not found.
*/
public async createPayloadSignature(unsignedPayload: string): Promise<PayloadSignature> {
public async createPayloadSignature(unsignedPayload: string): Promise<IPayloadSignature> {
return (await this.getDefaultAddress()).createPayloadSignature(unsignedPayload);
}

Expand All @@ -836,7 +837,7 @@ export class Wallet implements IWallet {
*
* @returns The newly created webhook instance.
*/
public async createWebhook(notificationUri: string): Promise<Webhook> {
public async createWebhook(notificationUri: string): Promise<IWebhook> {
const result = await Coinbase.apiClients.webhook!.createWalletWebhook(this.getId(), {
notification_uri: notificationUri,
});
Expand All @@ -861,7 +862,7 @@ export class Wallet implements IWallet {
*/
public async invokeContract(
options: CreateContractInvocationOptions,
): Promise<ContractInvocation> {
): Promise<IContractInvocation> {
return (await this.getDefaultAddress()).invokeContract(options);
}

Expand All @@ -875,7 +876,7 @@ export class Wallet implements IWallet {
* @returns A Promise that resolves to the deployed SmartContract object.
* @throws {Error} If the private key is not loaded when not using server signer.
*/
public async deployToken(options: CreateERC20Options): Promise<SmartContract> {
public async deployToken(options: CreateERC20Options): Promise<ISmartContract> {
return (await this.getDefaultAddress()).deployToken(options);
}

Expand All @@ -889,7 +890,7 @@ export class Wallet implements IWallet {
* @returns A Promise that resolves to the deployed SmartContract object.
* @throws {Error} If the private key is not loaded when not using server signer.
*/
public async deployNFT(options: CreateERC721Options): Promise<SmartContract> {
public async deployNFT(options: CreateERC721Options): Promise<ISmartContract> {
return (await this.getDefaultAddress()).deployNFT(options);
}

Expand All @@ -903,7 +904,7 @@ export class Wallet implements IWallet {
* @returns A Promise that resolves to the deployed SmartContract object.
* @throws {Error} If the private key is not loaded when not using server signer.
*/
public async deployMultiToken(options: CreateERC1155Options): Promise<SmartContract> {
public async deployMultiToken(options: CreateERC1155Options): Promise<ISmartContract> {
return (await this.getDefaultAddress()).deployMultiToken(options);
}

Expand Down
2 changes: 1 addition & 1 deletion src/coinbase/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface IWebhook {
/**
* A representation of a Webhook,
* which provides methods to create, list, update, and delete webhooks that are used to receive notifications of specific events.
*/
*/

Check failure on line 24 in src/coinbase/webhook.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
export class Webhook implements IWebhook {
private model: WebhookModel | null;

Expand Down

0 comments on commit 2b240ab

Please sign in to comment.