Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@coinbase/coinbase-sdk

Package Overview
Dependencies
Maintainers
0
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@coinbase/coinbase-sdk - npm Package Compare versions

Comparing version 0.11.1 to 0.11.2

34

dist/coinbase/address/wallet_address.d.ts

@@ -7,3 +7,3 @@ import { ethers } from "ethers";

import { ContractInvocation } from "../contract_invocation";
import { Amount, CreateTransferOptions, CreateTradeOptions, CreateContractInvocationOptions, StakeOptionsMode, CreateERC20Options, CreateERC721Options, CreateERC1155Options, PaginationOptions, PaginationResponse } from "../types";
import { Amount, CreateTransferOptions, CreateTradeOptions, CreateContractInvocationOptions, StakeOptionsMode, CreateERC20Options, CreateERC721Options, CreateERC1155Options, PaginationOptions, PaginationResponse, CreateFundOptions, CreateQuoteOptions } from "../types";
import { StakingOperation } from "../staking_operation";

@@ -131,3 +131,3 @@ import { PayloadSignature } from "../payload_signature";

*/
invokeContract(options: CreateContractInvocationOptions): Promise<ContractInvocation>;
invokeContract({ contractAddress, method, abi, args, amount, assetId, }: CreateContractInvocationOptions): Promise<ContractInvocation>;
/**

@@ -143,3 +143,3 @@ * Deploys an ERC20 token contract.

*/
deployToken(options: CreateERC20Options): Promise<SmartContract>;
deployToken({ name, symbol, totalSupply }: CreateERC20Options): Promise<SmartContract>;
/**

@@ -155,3 +155,3 @@ * Deploys an ERC721 token contract.

*/
deployNFT(options: CreateERC721Options): Promise<SmartContract>;
deployNFT({ name, symbol, baseURI }: CreateERC721Options): Promise<SmartContract>;
/**

@@ -165,3 +165,3 @@ * Deploys an ERC1155 multi-token contract.

*/
deployMultiToken(options: CreateERC1155Options): Promise<SmartContract>;
deployMultiToken({ uri }: CreateERC1155Options): Promise<SmartContract>;
/**

@@ -307,16 +307,28 @@ * Creates an ERC20 token contract.

*
* @param amount - The amount of the Asset to fund the wallet with
* @param assetId - The ID of the Asset to fund with. For Ether, eth, gwei, and wei are supported.
* @param options - The options to create the fund operation
* @param options.amount - The amount of the Asset to fund the wallet with
* @param options.assetId - The ID of the Asset to fund with. For Ether, eth, gwei, and wei are supported.
* @returns The created fund operation object
*/
fund(amount: Amount, assetId: string): Promise<FundOperation>;
fund({ amount, assetId, }: CreateFundOptions): Promise<FundOperation>;
/**
* Get a quote for funding the address from your Coinbase platform account.
*
* @param amount - The amount to fund
* @param assetId - The ID of the Asset to fund with. For Ether, eth, gwei, and wei are supported.
* @param options - The options to create the fund quote
* @param options.amount - The amount to fund
* @param options.assetId - The ID of the Asset to fund with. For Ether, eth, gwei, and wei are supported.
* @returns The fund quote object
*/
quoteFund(amount: Amount, assetId: string): Promise<FundQuote>;
quoteFund({ amount, assetId, }: CreateQuoteOptions): Promise<FundQuote>;
/**
* Returns all the fund operations associated with the address.
*
* @param options - The pagination options.
* @param options.limit - The maximum number of Fund Operations to return. Limit can range between 1 and 100.
* @param options.page - The cursor for pagination across multiple pages of Fund Operations. Don't include this parameter on the first call. Use the next page value returned in a previous response to request subsequent results.
*
* @returns The paginated list response of fund operations.
*/
listFundOperations({ limit, page, }?: PaginationOptions): Promise<PaginationResponse<FundOperation>>;
/**
* Returns the address and network ID of the given destination.

@@ -323,0 +335,0 @@ *

@@ -238,3 +238,3 @@ "use strict";

*/
async invokeContract(options) {
async invokeContract({ contractAddress, method, abi, args, amount, assetId, }) {
if (!coinbase_1.Coinbase.useServerSigner && !this.key) {

@@ -244,6 +244,6 @@ throw new Error("Cannot invoke contract from address without private key loaded");

let atomicAmount;
if (options.assetId && options.amount) {
const asset = await asset_1.Asset.fetch(this.getNetworkId(), options.assetId);
const normalizedAmount = new decimal_js_1.Decimal(options.amount.toString());
const currentBalance = await this.getBalance(options.assetId);
if (assetId && amount) {
const asset = await asset_1.Asset.fetch(this.getNetworkId(), assetId);
const normalizedAmount = new decimal_js_1.Decimal(amount.toString());
const currentBalance = await this.getBalance(assetId);
if (currentBalance.lessThan(normalizedAmount)) {

@@ -254,3 +254,3 @@ throw new errors_1.ArgumentError(`Insufficient funds: ${normalizedAmount} requested, but only ${currentBalance} available`);

}
const contractInvocation = await this.createContractInvocation(options.contractAddress, options.method, options.abi, options.args, atomicAmount);
const contractInvocation = await this.createContractInvocation(contractAddress, method, abi, args, atomicAmount);
if (coinbase_1.Coinbase.useServerSigner) {

@@ -273,7 +273,7 @@ return contractInvocation;

*/
async deployToken(options) {
async deployToken({ name, symbol, totalSupply }) {
if (!coinbase_1.Coinbase.useServerSigner && !this.key) {
throw new Error("Cannot deploy ERC20 without private key loaded");
}
const smartContract = await this.createERC20(options);
const smartContract = await this.createERC20({ name, symbol, totalSupply });
if (coinbase_1.Coinbase.useServerSigner) {

@@ -296,7 +296,7 @@ return smartContract;

*/
async deployNFT(options) {
async deployNFT({ name, symbol, baseURI }) {
if (!coinbase_1.Coinbase.useServerSigner && !this.key) {
throw new Error("Cannot deploy ERC721 without private key loaded");
}
const smartContract = await this.createERC721(options);
const smartContract = await this.createERC721({ name, symbol, baseURI });
if (coinbase_1.Coinbase.useServerSigner) {

@@ -317,7 +317,7 @@ return smartContract;

*/
async deployMultiToken(options) {
async deployMultiToken({ uri }) {
if (!coinbase_1.Coinbase.useServerSigner && !this.key) {
throw new Error("Cannot deploy ERC1155 without private key loaded");
}
const smartContract = await this.createERC1155(options);
const smartContract = await this.createERC1155({ uri });
if (coinbase_1.Coinbase.useServerSigner) {

@@ -341,9 +341,9 @@ return smartContract;

*/
async createERC20(options) {
async createERC20({ name, symbol, totalSupply }) {
const resp = await coinbase_1.Coinbase.apiClients.smartContract.createSmartContract(this.getWalletId(), this.getId(), {
type: client_1.SmartContractType.Erc20,
options: {
name: options.name,
symbol: options.symbol,
total_supply: options.totalSupply.toString(),
name,
symbol,
total_supply: totalSupply.toString(),
},

@@ -363,9 +363,9 @@ });

*/
async createERC721(options) {
async createERC721({ name, symbol, baseURI }) {
const resp = await coinbase_1.Coinbase.apiClients.smartContract.createSmartContract(this.getWalletId(), this.getId(), {
type: client_1.SmartContractType.Erc721,
options: {
name: options.name,
symbol: options.symbol,
base_uri: options.baseURI,
name,
symbol,
base_uri: baseURI,
},

@@ -384,7 +384,7 @@ });

*/
async createERC1155(options) {
async createERC1155({ uri }) {
const resp = await coinbase_1.Coinbase.apiClients.smartContract.createSmartContract(this.getWalletId(), this.getId(), {
type: client_1.SmartContractType.Erc1155,
options: {
uri: options.uri,
uri,
},

@@ -550,7 +550,8 @@ });

*
* @param amount - The amount of the Asset to fund the wallet with
* @param assetId - The ID of the Asset to fund with. For Ether, eth, gwei, and wei are supported.
* @param options - The options to create the fund operation
* @param options.amount - The amount of the Asset to fund the wallet with
* @param options.assetId - The ID of the Asset to fund with. For Ether, eth, gwei, and wei are supported.
* @returns The created fund operation object
*/
async fund(amount, assetId) {
async fund({ amount, assetId, }) {
const normalizedAmount = new decimal_js_1.Decimal(amount.toString());

@@ -562,7 +563,8 @@ return fund_operation_1.FundOperation.create(this.getWalletId(), this.getId(), normalizedAmount, assetId, this.getNetworkId());

*
* @param amount - The amount to fund
* @param assetId - The ID of the Asset to fund with. For Ether, eth, gwei, and wei are supported.
* @param options - The options to create the fund quote
* @param options.amount - The amount to fund
* @param options.assetId - The ID of the Asset to fund with. For Ether, eth, gwei, and wei are supported.
* @returns The fund quote object
*/
async quoteFund(amount, assetId) {
async quoteFund({ amount, assetId, }) {
const normalizedAmount = new decimal_js_1.Decimal(amount.toString());

@@ -572,2 +574,17 @@ return fund_quote_1.FundQuote.create(this.getWalletId(), this.getId(), normalizedAmount, assetId, this.getNetworkId());

/**
* Returns all the fund operations associated with the address.
*
* @param options - The pagination options.
* @param options.limit - The maximum number of Fund Operations to return. Limit can range between 1 and 100.
* @param options.page - The cursor for pagination across multiple pages of Fund Operations. Don't include this parameter on the first call. Use the next page value returned in a previous response to request subsequent results.
*
* @returns The paginated list response of fund operations.
*/
async listFundOperations({ limit = coinbase_1.Coinbase.defaultPageLimit, page = undefined, } = {}) {
return fund_operation_1.FundOperation.listFundOperations(this.model.wallet_id, this.model.address_id, {
limit,
page,
});
}
/**
* Returns the address and network ID of the given destination.

@@ -574,0 +591,0 @@ *

@@ -720,2 +720,13 @@ import { Decimal } from "decimal.js";

/**
* Options for creating a fund operation.
*/
export type CreateFundOptions = {
amount: Amount;
assetId: string;
};
/**
* Options for creating a quote for a fund operation.
*/
export type CreateQuoteOptions = CreateFundOptions;
/**
* Options for listing historical balances of an address.

@@ -722,0 +733,0 @@ */

@@ -9,3 +9,3 @@ import Decimal from "decimal.js";

import { Transfer } from "./transfer";
import { Amount, StakingRewardFormat, CreateContractInvocationOptions, CreateTransferOptions, CreateTradeOptions, ServerSignerStatus, StakeOptionsMode, WalletCreateOptions, WalletData, CreateERC20Options, CreateERC721Options, CreateERC1155Options, PaginationOptions, PaginationResponse } from "./types";
import { Amount, StakingRewardFormat, CreateContractInvocationOptions, CreateTransferOptions, CreateTradeOptions, ServerSignerStatus, StakeOptionsMode, WalletCreateOptions, WalletData, CreateERC20Options, CreateERC721Options, CreateERC1155Options, PaginationOptions, PaginationResponse, CreateFundOptions, CreateQuoteOptions } from "./types";
import { StakingOperation } from "./staking_operation";

@@ -422,18 +422,30 @@ import { StakingReward } from "./staking_reward";

*
* @param amount - The amount of the Asset to fund the wallet with
* @param assetId - The ID of the Asset to fund with. For Ether, eth, gwei, and wei are supported.
* @param options - The options to create the fund operation
* @param options.amount - The amount of the Asset to fund the wallet with
* @param options.assetId - The ID of the Asset to fund with. For Ether, eth, gwei, and wei are supported.
* @returns The created fund operation object
* @throws {Error} If the default address does not exist
*/
fund(amount: Amount, assetId: string): Promise<FundOperation>;
fund(options: CreateFundOptions): Promise<FundOperation>;
/**
* Get a quote for funding the wallet from your Coinbase platform account.
*
* @param amount - The amount to fund
* @param assetId - The ID of the Asset to fund with. For Ether, eth, gwei, and wei are supported.
* @param options - The options to create the fund quote
* @param options.amount - The amount to fund
* @param options.assetId - The ID of the Asset to fund with. For Ether, eth, gwei, and wei are supported.
* @returns The fund quote object
* @throws {Error} If the default address does not exist
*/
quoteFund(amount: Amount, assetId: string): Promise<FundQuote>;
quoteFund(options: CreateQuoteOptions): Promise<FundQuote>;
/**
* Returns all the fund operations associated with the wallet's default address.
*
* @param options - The pagination options.
* @param options.limit - The maximum number of fund operations to return. Limit can range between 1 and 100.
* @param options.page - The cursor for pagination across multiple pages of fund operations. Don't include this parameter on the first call. Use the next page value returned in a previous response to request subsequent results.
* @returns The paginated list response of fund operations.
* @throws {Error} If the default address does not exist
*/
listFundOperations({ limit, page, }?: PaginationOptions): Promise<PaginationResponse<FundOperation>>;
/**
* Returns a String representation of the Wallet.

@@ -440,0 +452,0 @@ *

@@ -678,8 +678,9 @@ "use strict";

*
* @param amount - The amount of the Asset to fund the wallet with
* @param assetId - The ID of the Asset to fund with. For Ether, eth, gwei, and wei are supported.
* @param options - The options to create the fund operation
* @param options.amount - The amount of the Asset to fund the wallet with
* @param options.assetId - The ID of the Asset to fund with. For Ether, eth, gwei, and wei are supported.
* @returns The created fund operation object
* @throws {Error} If the default address does not exist
*/
async fund(amount, assetId) {
async fund(options) {
const defaultAddress = await this.getDefaultAddress();

@@ -689,3 +690,3 @@ if (!defaultAddress) {

}
return defaultAddress.fund(amount, assetId);
return defaultAddress.fund(options);
}

@@ -695,8 +696,9 @@ /**

*
* @param amount - The amount to fund
* @param assetId - The ID of the Asset to fund with. For Ether, eth, gwei, and wei are supported.
* @param options - The options to create the fund quote
* @param options.amount - The amount to fund
* @param options.assetId - The ID of the Asset to fund with. For Ether, eth, gwei, and wei are supported.
* @returns The fund quote object
* @throws {Error} If the default address does not exist
*/
async quoteFund(amount, assetId) {
async quoteFund(options) {
const defaultAddress = await this.getDefaultAddress();

@@ -706,5 +708,21 @@ if (!defaultAddress) {

}
return defaultAddress.quoteFund(amount, assetId);
return defaultAddress.quoteFund(options);
}
/**
* Returns all the fund operations associated with the wallet's default address.
*
* @param options - The pagination options.
* @param options.limit - The maximum number of fund operations to return. Limit can range between 1 and 100.
* @param options.page - The cursor for pagination across multiple pages of fund operations. Don't include this parameter on the first call. Use the next page value returned in a previous response to request subsequent results.
* @returns The paginated list response of fund operations.
* @throws {Error} If the default address does not exist
*/
async listFundOperations({ limit = coinbase_1.Coinbase.defaultPageLimit, page = undefined, } = {}) {
const defaultAddress = await this.getDefaultAddress();
if (!defaultAddress) {
throw new Error("Default address does not exist");
}
return defaultAddress.listFundOperations({ limit, page });
}
/**
* Returns a String representation of the Wallet.

@@ -711,0 +729,0 @@ *

@@ -16,2 +16,5 @@ "use strict";

jest.spyOn(fund_quote_1.FundQuote, "create").mockResolvedValue({});
jest
.spyOn(fund_operation_1.FundOperation, "listFundOperations")
.mockResolvedValue({});
});

@@ -25,3 +28,3 @@ afterEach(() => {

const assetId = "eth";
await walletAddress.fund(amount, assetId);
await walletAddress.fund({ amount, assetId });
expect(fund_operation_1.FundOperation.create).toHaveBeenCalledWith(walletId, addressId, amount, assetId, walletAddress.getNetworkId());

@@ -32,3 +35,3 @@ });

const assetId = "eth";
await walletAddress.fund(amount, assetId);
await walletAddress.fund({ amount, assetId });
expect(fund_operation_1.FundOperation.create).toHaveBeenCalledWith(walletId, addressId, new decimal_js_1.Decimal(amount), assetId, walletAddress.getNetworkId());

@@ -39,3 +42,3 @@ });

const assetId = "eth";
await walletAddress.fund(amount, assetId);
await walletAddress.fund({ amount, assetId });
expect(fund_operation_1.FundOperation.create).toHaveBeenCalledWith(walletId, addressId, new decimal_js_1.Decimal(amount.toString()), assetId, walletAddress.getNetworkId());

@@ -48,3 +51,3 @@ });

const assetId = "eth";
await walletAddress.quoteFund(amount, assetId);
await walletAddress.quoteFund({ amount, assetId });
expect(fund_quote_1.FundQuote.create).toHaveBeenCalledWith(walletId, addressId, amount, assetId, walletAddress.getNetworkId());

@@ -55,3 +58,3 @@ });

const assetId = "eth";
await walletAddress.quoteFund(amount, assetId);
await walletAddress.quoteFund({ amount, assetId });
expect(fund_quote_1.FundQuote.create).toHaveBeenCalledWith(walletId, addressId, new decimal_js_1.Decimal(amount), assetId, walletAddress.getNetworkId());

@@ -62,6 +65,15 @@ });

const assetId = "eth";
await walletAddress.quoteFund(amount, assetId);
await walletAddress.quoteFund({ amount, assetId });
expect(fund_quote_1.FundQuote.create).toHaveBeenCalledWith(walletId, addressId, new decimal_js_1.Decimal(amount.toString()), assetId, walletAddress.getNetworkId());
});
});
describe("#listFundOperations", () => {
it("should call listFundOperations with correct parameters", async () => {
await walletAddress.listFundOperations({ limit: 10, page: "test-page" });
expect(fund_operation_1.FundOperation.listFundOperations).toHaveBeenCalledWith(walletId, addressId, {
limit: 10,
page: "test-page",
});
});
});
});

@@ -29,2 +29,5 @@ "use strict";

jest.spyOn(defaultAddress, "quoteFund").mockResolvedValue({});
jest
.spyOn(defaultAddress, "listFundOperations")
.mockResolvedValue({});
});

@@ -38,4 +41,4 @@ afterEach(() => {

const assetId = "eth";
await wallet.fund(amount, assetId);
expect(defaultAddress.fund).toHaveBeenCalledWith(amount, assetId);
await wallet.fund({ amount, assetId });
expect(defaultAddress.fund).toHaveBeenCalledWith({ amount, assetId });
});

@@ -45,4 +48,4 @@ it("should call defaultAddress.fund with correct parameters when passing in number amount", async () => {

const assetId = "eth";
await wallet.fund(amount, assetId);
expect(defaultAddress.fund).toHaveBeenCalledWith(amount, assetId);
await wallet.fund({ amount, assetId });
expect(defaultAddress.fund).toHaveBeenCalledWith({ amount, assetId });
});

@@ -52,4 +55,4 @@ it("should call defaultAddress.fund with correct parameters when passing in bigint amount", async () => {

const assetId = "eth";
await wallet.fund(amount, assetId);
expect(defaultAddress.fund).toHaveBeenCalledWith(amount, assetId);
await wallet.fund({ amount, assetId });
expect(defaultAddress.fund).toHaveBeenCalledWith({ amount, assetId });
});

@@ -62,3 +65,3 @@ it("should throw error if default address does not exist", async () => {

const assetId = "eth";
await expect(wallet.fund(amount, assetId)).rejects.toThrow("Default address does not exist");
await expect(wallet.fund({ amount, assetId })).rejects.toThrow("Default address does not exist");
});

@@ -70,4 +73,4 @@ });

const assetId = "eth";
await wallet.quoteFund(amount, assetId);
expect(defaultAddress.quoteFund).toHaveBeenCalledWith(amount, assetId);
await wallet.quoteFund({ amount, assetId });
expect(defaultAddress.quoteFund).toHaveBeenCalledWith({ amount, assetId });
});

@@ -77,4 +80,4 @@ it("should call defaultAddress.quoteFund with correct parameters when passing in number amount", async () => {

const assetId = "eth";
await wallet.quoteFund(amount, assetId);
expect(defaultAddress.quoteFund).toHaveBeenCalledWith(amount, assetId);
await wallet.quoteFund({ amount, assetId });
expect(defaultAddress.quoteFund).toHaveBeenCalledWith({ amount, assetId });
});

@@ -84,4 +87,4 @@ it("should call defaultAddress.quoteFund with correct parameters when passing in bigint amount", async () => {

const assetId = "eth";
await wallet.quoteFund(amount, assetId);
expect(defaultAddress.quoteFund).toHaveBeenCalledWith(amount, assetId);
await wallet.quoteFund({ amount, assetId });
expect(defaultAddress.quoteFund).toHaveBeenCalledWith({ amount, assetId });
});

@@ -94,5 +97,17 @@ it("should throw error if default address does not exist", async () => {

const assetId = "eth";
await expect(wallet.quoteFund(amount, assetId)).rejects.toThrow("Default address does not exist");
await expect(wallet.quoteFund({ amount, assetId })).rejects.toThrow("Default address does not exist");
});
});
describe("#listFundOperations", () => {
it("should call defaultAddress.listFundOperations with correct parameters", async () => {
await wallet.listFundOperations({
limit: 10,
page: "test-page",
});
expect(defaultAddress.listFundOperations).toHaveBeenCalledWith({
limit: 10,
page: "test-page",
});
});
});
});

@@ -7,3 +7,3 @@ {

"repository": "https://github.com/coinbase/coinbase-sdk-nodejs",
"version": "0.11.1",
"version": "0.11.2",
"main": "dist/index.js",

@@ -10,0 +10,0 @@ "types": "dist/index.d.ts",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc