@coinbase/coinbase-sdk
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -84,3 +84,3 @@ "use strict"; | ||
if (limit !== undefined || page !== undefined) { | ||
const response = await coinbase_1.Coinbase.apiClients.externalAddress.listAddressHistoricalBalance(this.getNetworkId(), this.getId(), asset_1.Asset.primaryDenomination(assetId), limit ? limit : undefined, page ? page : undefined); | ||
const response = await coinbase_1.Coinbase.apiClients.balanceHistory.listAddressHistoricalBalance(this.getNetworkId(), this.getId(), asset_1.Asset.primaryDenomination(assetId), limit ? limit : undefined, page ? page : undefined); | ||
response.data.data.forEach(historicalBalanceModel => { | ||
@@ -98,3 +98,3 @@ const historicalBalance = historical_balance_1.HistoricalBalance.fromModel(historicalBalanceModel); | ||
const page = queue.shift(); | ||
const response = await coinbase_1.Coinbase.apiClients.externalAddress.listAddressHistoricalBalance(this.getNetworkId(), this.getId(), asset_1.Asset.primaryDenomination(assetId), 100, page ? page : undefined); | ||
const response = await coinbase_1.Coinbase.apiClients.balanceHistory.listAddressHistoricalBalance(this.getNetworkId(), this.getId(), asset_1.Asset.primaryDenomination(assetId), 100, page ? page : undefined); | ||
response.data.data.forEach(historicalBalanceModel => { | ||
@@ -101,0 +101,0 @@ const historicalBalance = historical_balance_1.HistoricalBalance.fromModel(historicalBalanceModel); |
@@ -148,3 +148,3 @@ "use strict"; | ||
const asset = await asset_1.Asset.fetch(this.getNetworkId(), assetId); | ||
const [destinationAddress, destinationNetworkId] = this.getDestinationAddressAndNetwork(destination); | ||
const [destinationAddress, destinationNetworkId] = await this.getDestinationAddressAndNetwork(destination); | ||
const normalizedAmount = new decimal_js_1.Decimal(amount.toString()); | ||
@@ -379,3 +379,3 @@ const currentBalance = await this.getBalance(assetId); | ||
*/ | ||
getDestinationAddressAndNetwork(destination) { | ||
async getDestinationAddressAndNetwork(destination) { | ||
if (typeof destination !== "string" && destination.getNetworkId() !== this.getNetworkId()) { | ||
@@ -385,3 +385,3 @@ throw new errors_1.ArgumentError("Transfer must be on the same Network"); | ||
if (destination instanceof wallet_1.Wallet) { | ||
return [destination.getDefaultAddress().getId(), destination.getNetworkId()]; | ||
return [(await destination.getDefaultAddress()).getId(), destination.getNetworkId()]; | ||
} | ||
@@ -388,0 +388,0 @@ if (destination instanceof address_1.Address) { |
@@ -22,2 +22,3 @@ import { ApiClients, CoinbaseConfigureFromJsonOptions, CoinbaseOptions } from "./types"; | ||
readonly PolygonMainnet: "polygon-mainnet"; | ||
readonly SolanaDevnet: "solana-devnet"; | ||
}; | ||
@@ -24,0 +25,0 @@ /** |
@@ -92,2 +92,3 @@ "use strict"; | ||
Coinbase.apiClients.externalAddress = (0, client_1.ExternalAddressesApiFactory)(config, basePath, axiosInstance); | ||
Coinbase.apiClients.balanceHistory = (0, client_1.BalanceHistoryApiFactory)(config, basePath, axiosInstance); | ||
Coinbase.apiClients.smartContract = (0, client_1.ContractEventsApiFactory)(config, basePath, axiosInstance); | ||
@@ -94,0 +95,0 @@ Coinbase.apiKeyPrivateKey = privateKey; |
@@ -244,15 +244,2 @@ import { Decimal } from "decimal.js"; | ||
/** | ||
* List the historical balance of an asset in a specific address. | ||
* | ||
* @summary Get address balance history for asset | ||
* @param networkId - The ID of the blockchain network | ||
* @param addressId - The ID of the address to fetch the historical balance for. | ||
* @param assetId - The symbol of the asset to fetch the historical balance for. | ||
* @param limit - A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. | ||
* @param page - A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. | ||
* @param options - Override http request option. | ||
* @throws {RequiredError} | ||
*/ | ||
listAddressHistoricalBalance(networkId: string, addressId: string, assetId: string, limit?: number, page?: string, options?: RawAxiosRequestConfig): AxiosPromise<AddressHistoricalBalanceList>; | ||
/** | ||
* List the transactions of a specific address. | ||
@@ -473,2 +460,3 @@ * | ||
contractInvocation?: ContractInvocationAPIClient; | ||
balanceHistory?: BalanceHistoryApiClient; | ||
}; | ||
@@ -732,2 +720,17 @@ /** | ||
} | ||
export interface BalanceHistoryApiClient { | ||
/** | ||
* List the historical balance of an asset in a specific address. | ||
* | ||
* @summary Get address balance history for asset | ||
* @param networkId - The ID of the blockchain network | ||
* @param addressId - The ID of the address to fetch the historical balance for. | ||
* @param assetId - The symbol of the asset to fetch the historical balance for. | ||
* @param limit - A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. | ||
* @param page - A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. | ||
* @param options - Override http request option. | ||
* @throws {RequiredError} | ||
*/ | ||
listAddressHistoricalBalance(networkId: string, addressId: string, assetId: string, limit?: number, page?: string, options?: RawAxiosRequestConfig): AxiosPromise<AddressHistoricalBalanceList>; | ||
} | ||
/** | ||
@@ -734,0 +737,0 @@ * The domain for an EIP-712 typed data message payload. |
@@ -119,8 +119,8 @@ import Decimal from "decimal.js"; | ||
/** | ||
* Returns the Address with the given ID. | ||
* Returns the WalletAddress with the given ID. | ||
* | ||
* @param addressId - The ID of the Address to retrieve. | ||
* @returns The Address. | ||
* @param addressId - The ID of the WalletAddress to retrieve. | ||
* @returns The WalletAddress. | ||
*/ | ||
getAddress(addressId: string): Address | undefined; | ||
getAddress(addressId: string): Promise<WalletAddress | undefined>; | ||
/** | ||
@@ -312,3 +312,3 @@ * Returns the list of Addresses in the Wallet. | ||
*/ | ||
getDefaultAddress(): WalletAddress | undefined; | ||
getDefaultAddress(): Promise<WalletAddress>; | ||
/** | ||
@@ -315,0 +315,0 @@ * Returns whether the Wallet has a seed with which to derive keys and sign transactions. |
@@ -246,8 +246,11 @@ "use strict"; | ||
/** | ||
* Returns the Address with the given ID. | ||
* Returns the WalletAddress with the given ID. | ||
* | ||
* @param addressId - The ID of the Address to retrieve. | ||
* @returns The Address. | ||
* @param addressId - The ID of the WalletAddress to retrieve. | ||
* @returns The WalletAddress. | ||
*/ | ||
getAddress(addressId) { | ||
async getAddress(addressId) { | ||
if (this.addresses.length < 1) { | ||
this.addresses = await this.listAddresses(); | ||
} | ||
return this.addresses.find(address => { | ||
@@ -283,6 +286,3 @@ return address.getId() === addressId; | ||
async createTrade(options) { | ||
if (!this.getDefaultAddress()) { | ||
throw new Error("Default address not found"); | ||
} | ||
return await this.getDefaultAddress().createTrade(options); | ||
return (await this.getDefaultAddress()).createTrade(options); | ||
} | ||
@@ -299,6 +299,3 @@ /** | ||
async stakeableBalance(asset_id, mode = types_1.StakeOptionsMode.DEFAULT, options = {}) { | ||
if (!this.getDefaultAddress()) { | ||
throw new Error("Default address not found"); | ||
} | ||
return await this.getDefaultAddress().stakeableBalance(asset_id, mode, options); | ||
return (await this.getDefaultAddress()).stakeableBalance(asset_id, mode, options); | ||
} | ||
@@ -315,6 +312,3 @@ /** | ||
async unstakeableBalance(asset_id, mode = types_1.StakeOptionsMode.DEFAULT, options = {}) { | ||
if (!this.getDefaultAddress()) { | ||
throw new Error("Default address not found"); | ||
} | ||
return await this.getDefaultAddress().unstakeableBalance(asset_id, mode, options); | ||
return (await this.getDefaultAddress()).unstakeableBalance(asset_id, mode, options); | ||
} | ||
@@ -331,6 +325,3 @@ /** | ||
async claimableBalance(asset_id, mode = types_1.StakeOptionsMode.DEFAULT, options = {}) { | ||
if (!this.getDefaultAddress()) { | ||
throw new Error("Default address not found"); | ||
} | ||
return await this.getDefaultAddress().claimableBalance(asset_id, mode, options); | ||
return (await this.getDefaultAddress()).claimableBalance(asset_id, mode, options); | ||
} | ||
@@ -348,6 +339,3 @@ /** | ||
async stakingRewards(assetId, startTime = (0, utils_1.getWeekBackDate)(new Date()), endTime = (0, utils_1.formatDate)(new Date()), format = client_1.StakingRewardFormat.Usd) { | ||
if (!this.getDefaultAddress()) { | ||
throw new Error("Default address not found"); | ||
} | ||
return await this.getDefaultAddress().stakingRewards(assetId, startTime, endTime, format); | ||
return (await this.getDefaultAddress()).stakingRewards(assetId, startTime, endTime, format); | ||
} | ||
@@ -364,6 +352,3 @@ /** | ||
async historicalStakingBalances(assetId, startTime = (0, utils_1.getWeekBackDate)(new Date()), endTime = (0, utils_1.formatDate)(new Date())) { | ||
if (!this.getDefaultAddress()) { | ||
throw new Error("Default address not found"); | ||
} | ||
return await this.getDefaultAddress().historicalStakingBalances(assetId, startTime, endTime); | ||
return (await this.getDefaultAddress()).historicalStakingBalances(assetId, startTime, endTime); | ||
} | ||
@@ -380,6 +365,3 @@ /** | ||
async listHistoricalBalances({ assetId, limit, page, }) { | ||
if (!this.getDefaultAddress()) { | ||
throw new Error("Default address not found"); | ||
} | ||
return await this.getDefaultAddress().listHistoricalBalances({ | ||
return (await this.getDefaultAddress()).listHistoricalBalances({ | ||
assetId: assetId, | ||
@@ -403,6 +385,3 @@ limit: limit, | ||
async createStake(amount, assetId, mode = types_1.StakeOptionsMode.DEFAULT, options = {}, timeoutSeconds = 60, intervalSeconds = 0.2) { | ||
if (!this.getDefaultAddress()) { | ||
throw new Error("Default address not found"); | ||
} | ||
return await this.getDefaultAddress().createStake(amount, assetId, mode, options, timeoutSeconds, intervalSeconds); | ||
return (await this.getDefaultAddress()).createStake(amount, assetId, mode, options, timeoutSeconds, intervalSeconds); | ||
} | ||
@@ -422,6 +401,3 @@ /** | ||
async createUnstake(amount, assetId, mode = types_1.StakeOptionsMode.DEFAULT, options = {}, timeoutSeconds = 60, intervalSeconds = 0.2) { | ||
if (!this.getDefaultAddress()) { | ||
throw new Error("Default address not found"); | ||
} | ||
return await this.getDefaultAddress().createUnstake(amount, assetId, mode, options, timeoutSeconds, intervalSeconds); | ||
return (await this.getDefaultAddress()).createUnstake(amount, assetId, mode, options, timeoutSeconds, intervalSeconds); | ||
} | ||
@@ -441,6 +417,3 @@ /** | ||
async createClaimStake(amount, assetId, mode = types_1.StakeOptionsMode.DEFAULT, options = {}, timeoutSeconds = 60, intervalSeconds = 0.2) { | ||
if (!this.getDefaultAddress()) { | ||
throw new Error("Default address not found"); | ||
} | ||
return await this.getDefaultAddress().createClaimStake(amount, assetId, mode, options, timeoutSeconds, intervalSeconds); | ||
return (await this.getDefaultAddress()).createClaimStake(amount, assetId, mode, options, timeoutSeconds, intervalSeconds); | ||
} | ||
@@ -579,4 +552,11 @@ /** | ||
*/ | ||
getDefaultAddress() { | ||
return this.addresses.find(address => address.getId() === this.model.default_address?.address_id); | ||
async getDefaultAddress() { | ||
if (this.model.default_address === undefined) { | ||
throw new Error("WalletModel default address not set"); | ||
} | ||
const defaultAddress = await this.getAddress(this.model.default_address.address_id); | ||
if (!defaultAddress) { | ||
throw new Error("Default address not found"); | ||
} | ||
return defaultAddress; | ||
} | ||
@@ -604,3 +584,3 @@ /** | ||
} | ||
const transaction = await this.getDefaultAddress().faucet(assetId); | ||
const transaction = (await this.getDefaultAddress()).faucet(assetId); | ||
return transaction; | ||
@@ -622,6 +602,3 @@ } | ||
async createTransfer(options) { | ||
if (!this.getDefaultAddress()) { | ||
throw new Error("Default address not found"); | ||
} | ||
return await this.getDefaultAddress().createTransfer(options); | ||
return (await this.getDefaultAddress()).createTransfer(options); | ||
} | ||
@@ -637,6 +614,3 @@ /** | ||
async createPayloadSignature(unsignedPayload) { | ||
if (!this.getDefaultAddress()) { | ||
throw new Error("Default address not found"); | ||
} | ||
return await this.getDefaultAddress().createPayloadSignature(unsignedPayload); | ||
return (await this.getDefaultAddress()).createPayloadSignature(unsignedPayload); | ||
} | ||
@@ -656,6 +630,3 @@ /** | ||
async invokeContract(options) { | ||
if (!this.getDefaultAddress()) { | ||
throw new Error("Default address not found"); | ||
} | ||
return await this.getDefaultAddress().invokeContract(options); | ||
return (await this.getDefaultAddress()).invokeContract(options); | ||
} | ||
@@ -662,0 +633,0 @@ /** |
@@ -131,4 +131,4 @@ "use strict"; | ||
}; | ||
coinbase_1.Coinbase.apiClients.externalAddress = utils_1.externalAddressApiMock; | ||
coinbase_1.Coinbase.apiClients.externalAddress.listAddressHistoricalBalance = (0, utils_1.mockReturnValue)(mockHistoricalBalanceResponse); | ||
coinbase_1.Coinbase.apiClients.balanceHistory = utils_1.balanceHistoryApiMock; | ||
coinbase_1.Coinbase.apiClients.balanceHistory.listAddressHistoricalBalance = (0, utils_1.mockReturnValue)(mockHistoricalBalanceResponse); | ||
}); | ||
@@ -142,4 +142,4 @@ it("should return results with USDC historical balance with limit", async () => { | ||
expect(historicalBalancesResult.historicalBalances[1].amount).toEqual(new decimal_js_1.default(5)); | ||
expect(coinbase_1.Coinbase.apiClients.externalAddress.listAddressHistoricalBalance).toHaveBeenCalledTimes(1); | ||
expect(coinbase_1.Coinbase.apiClients.externalAddress.listAddressHistoricalBalance).toHaveBeenCalledWith(address.getNetworkId(), address.getId(), coinbase_1.Coinbase.assets.Usdc, 100, undefined); | ||
expect(coinbase_1.Coinbase.apiClients.balanceHistory.listAddressHistoricalBalance).toHaveBeenCalledTimes(1); | ||
expect(coinbase_1.Coinbase.apiClients.balanceHistory.listAddressHistoricalBalance).toHaveBeenCalledWith(address.getNetworkId(), address.getId(), coinbase_1.Coinbase.assets.Usdc, 100, undefined); | ||
expect(historicalBalancesResult.nextPageToken).toEqual(""); | ||
@@ -155,8 +155,8 @@ }); | ||
expect(historicalBalancesResult.historicalBalances[1].amount).toEqual(new decimal_js_1.default(5)); | ||
expect(coinbase_1.Coinbase.apiClients.externalAddress.listAddressHistoricalBalance).toHaveBeenCalledTimes(1); | ||
expect(coinbase_1.Coinbase.apiClients.externalAddress.listAddressHistoricalBalance).toHaveBeenCalledWith(address.getNetworkId(), address.getId(), coinbase_1.Coinbase.assets.Usdc, undefined, "page_token"); | ||
expect(coinbase_1.Coinbase.apiClients.balanceHistory.listAddressHistoricalBalance).toHaveBeenCalledTimes(1); | ||
expect(coinbase_1.Coinbase.apiClients.balanceHistory.listAddressHistoricalBalance).toHaveBeenCalledWith(address.getNetworkId(), address.getId(), coinbase_1.Coinbase.assets.Usdc, undefined, "page_token"); | ||
expect(historicalBalancesResult.nextPageToken).toEqual(""); | ||
}); | ||
it("should return empty if no historical balance found", async () => { | ||
coinbase_1.Coinbase.apiClients.externalAddress.listAddressHistoricalBalance = (0, utils_1.mockReturnValue)({ | ||
coinbase_1.Coinbase.apiClients.balanceHistory.listAddressHistoricalBalance = (0, utils_1.mockReturnValue)({ | ||
data: [], | ||
@@ -170,8 +170,8 @@ has_more: false, | ||
expect(historicalBalancesResult.historicalBalances.length).toEqual(0); | ||
expect(coinbase_1.Coinbase.apiClients.externalAddress.listAddressHistoricalBalance).toHaveBeenCalledTimes(1); | ||
expect(coinbase_1.Coinbase.apiClients.externalAddress.listAddressHistoricalBalance).toHaveBeenCalledWith(address.getNetworkId(), address.getId(), coinbase_1.Coinbase.assets.Usdc, 100, undefined); | ||
expect(coinbase_1.Coinbase.apiClients.balanceHistory.listAddressHistoricalBalance).toHaveBeenCalledTimes(1); | ||
expect(coinbase_1.Coinbase.apiClients.balanceHistory.listAddressHistoricalBalance).toHaveBeenCalledWith(address.getNetworkId(), address.getId(), coinbase_1.Coinbase.assets.Usdc, 100, undefined); | ||
expect(historicalBalancesResult.nextPageToken).toEqual(""); | ||
}); | ||
it("should return results with USDC historical balance and next page", async () => { | ||
coinbase_1.Coinbase.apiClients.externalAddress.listAddressHistoricalBalance = (0, utils_1.mockReturnValue)({ | ||
coinbase_1.Coinbase.apiClients.balanceHistory.listAddressHistoricalBalance = (0, utils_1.mockReturnValue)({ | ||
data: [ | ||
@@ -198,4 +198,4 @@ { | ||
expect(historicalBalancesResult.historicalBalances[0].amount).toEqual(new decimal_js_1.default(5)); | ||
expect(coinbase_1.Coinbase.apiClients.externalAddress.listAddressHistoricalBalance).toHaveBeenCalledTimes(1); | ||
expect(coinbase_1.Coinbase.apiClients.externalAddress.listAddressHistoricalBalance).toHaveBeenCalledWith(address.getNetworkId(), address.getId(), coinbase_1.Coinbase.assets.Usdc, 1, undefined); | ||
expect(coinbase_1.Coinbase.apiClients.balanceHistory.listAddressHistoricalBalance).toHaveBeenCalledTimes(1); | ||
expect(coinbase_1.Coinbase.apiClients.balanceHistory.listAddressHistoricalBalance).toHaveBeenCalledWith(address.getNetworkId(), address.getId(), coinbase_1.Coinbase.assets.Usdc, 1, undefined); | ||
expect(historicalBalancesResult.nextPageToken).toEqual("next page"); | ||
@@ -202,0 +202,0 @@ }); |
@@ -92,9 +92,8 @@ "use strict"; | ||
console.log("Fetching address transactions..."); | ||
const result = await unhydratedWallet.getDefaultAddress()?.listTransactions({ limit: 1 }); | ||
const result = await (await unhydratedWallet.getDefaultAddress()).listTransactions({ limit: 1 }); | ||
expect(result?.transactions.length).toBeGreaterThan(0); | ||
console.log(`Fetched transactions: ${result?.transactions[0].toString()}`); | ||
console.log("Fetching address historical balances..."); | ||
const balance_result = await unhydratedWallet | ||
.getDefaultAddress() | ||
?.listHistoricalBalances({ assetId: index_1.Coinbase.assets.Eth, limit: 2 }); | ||
const balance_result = await (await unhydratedWallet | ||
.getDefaultAddress()).listHistoricalBalances({ assetId: index_1.Coinbase.assets.Eth, limit: 2 }); | ||
expect(balance_result?.historicalBalances.length).toBeGreaterThan(0); | ||
@@ -101,0 +100,0 @@ console.log(`First eth historical balance: ${balance_result?.historicalBalances[0].amount.toString()}`); |
@@ -143,5 +143,7 @@ /// <reference types="jest" /> | ||
requestExternalFaucetFunds: jest.Mock<any, any, any>; | ||
listAddressHistoricalBalance: jest.Mock<any, any, any>; | ||
listAddressTransactions: jest.Mock<any, any, any>; | ||
}; | ||
export declare const balanceHistoryApiMock: { | ||
listAddressHistoricalBalance: jest.Mock<any, any, any>; | ||
}; | ||
export declare const serverSignersApiMock: { | ||
@@ -148,0 +150,0 @@ listServerSigners: jest.Mock<any, any, any>; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.contractInvocationApiMock = exports.smartContractApiMock = exports.serverSignersApiMock = exports.externalAddressApiMock = exports.validatorApiMock = exports.walletStakeApiMock = exports.stakeApiMock = exports.transfersApiMock = exports.tradeApiMock = exports.addressesApiMock = exports.walletsApiMock = exports.assetsApiMock = exports.usersApiMock = exports.createAxiosMock = exports.getAssetMock = exports.VALID_BALANCE_MODEL = exports.VALID_EXITING_VALIDATOR_LIST = exports.VALID_ACTIVE_VALIDATOR_LIST = exports.mockEthereumValidator = exports.VALID_ADDRESS_BALANCE_LIST = exports.VALID_NATIVE_ETH_UNSTAKE_OPERATION_MODEL = exports.mockStakingOperation = exports.VALID_SIGNED_CONTRACT_INVOCATION_MODEL = exports.VALID_CONTRACT_INVOCATION_MODEL = exports.MINT_NFT_ARGS = exports.MINT_NFT_ABI = exports.VALID_PAYLOAD_SIGNATURE_LIST = exports.VALID_SIGNED_PAYLOAD_SIGNATURE_MODEL = exports.VALID_PAYLOAD_SIGNATURE_MODEL = exports.VALID_STAKING_OPERATION_MODEL = exports.VALID_TRANSFER_SPONSORED_SEND_MODEL = exports.VALID_TRANSFER_MODEL = exports.VALID_WALLET_MODEL = exports.VALID_ADDRESS_MODEL = exports.newAddressModel = exports.generateRandomHash = exports.generateWalletFromSeed = exports.transferId = exports.walletId = exports.mockListAddress = exports.getAddressFromHDKey = exports.mockReturnRejectedValue = exports.mockReturnValue = exports.mockFn = void 0; | ||
exports.contractInvocationApiMock = exports.smartContractApiMock = exports.serverSignersApiMock = exports.balanceHistoryApiMock = exports.externalAddressApiMock = exports.validatorApiMock = exports.walletStakeApiMock = exports.stakeApiMock = exports.transfersApiMock = exports.tradeApiMock = exports.addressesApiMock = exports.walletsApiMock = exports.assetsApiMock = exports.usersApiMock = exports.createAxiosMock = exports.getAssetMock = exports.VALID_BALANCE_MODEL = exports.VALID_EXITING_VALIDATOR_LIST = exports.VALID_ACTIVE_VALIDATOR_LIST = exports.mockEthereumValidator = exports.VALID_ADDRESS_BALANCE_LIST = exports.VALID_NATIVE_ETH_UNSTAKE_OPERATION_MODEL = exports.mockStakingOperation = exports.VALID_SIGNED_CONTRACT_INVOCATION_MODEL = exports.VALID_CONTRACT_INVOCATION_MODEL = exports.MINT_NFT_ARGS = exports.MINT_NFT_ABI = exports.VALID_PAYLOAD_SIGNATURE_LIST = exports.VALID_SIGNED_PAYLOAD_SIGNATURE_MODEL = exports.VALID_PAYLOAD_SIGNATURE_MODEL = exports.VALID_STAKING_OPERATION_MODEL = exports.VALID_TRANSFER_SPONSORED_SEND_MODEL = exports.VALID_TRANSFER_MODEL = exports.VALID_WALLET_MODEL = exports.VALID_ADDRESS_MODEL = exports.newAddressModel = exports.generateRandomHash = exports.generateWalletFromSeed = exports.transferId = exports.walletId = exports.mockListAddress = exports.getAddressFromHDKey = exports.mockReturnRejectedValue = exports.mockReturnValue = exports.mockFn = void 0; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
@@ -484,5 +484,7 @@ const axios_1 = __importDefault(require("axios")); | ||
requestExternalFaucetFunds: jest.fn(), | ||
listAddressHistoricalBalance: jest.fn(), | ||
listAddressTransactions: jest.fn(), | ||
}; | ||
exports.balanceHistoryApiMock = { | ||
listAddressHistoricalBalance: jest.fn(), | ||
}; | ||
exports.serverSignersApiMock = { | ||
@@ -489,0 +491,0 @@ listServerSigners: jest.fn(), |
@@ -255,6 +255,2 @@ "use strict"; | ||
}); | ||
it("should throw an error when the wallet does not have a default address", async () => { | ||
const newWallet = wallet_1.Wallet.init(walletModel); | ||
await expect(async () => await newWallet.createStake(0.001, coinbase_1.Coinbase.assets.Eth)).rejects.toThrow(Error); | ||
}); | ||
it("should throw an error when wait is called on wallet address based staking operation", async () => { | ||
@@ -288,6 +284,2 @@ const wallet = await wallet_1.Wallet.create({ networkId: coinbase_1.Coinbase.networks.EthereumHolesky }); | ||
}); | ||
it("should throw an error when the wallet does not have a default address", async () => { | ||
const newWallet = wallet_1.Wallet.init(walletModel); | ||
await expect(async () => await newWallet.createUnstake(0.001, coinbase_1.Coinbase.assets.Eth)).rejects.toThrow(Error); | ||
}); | ||
}); | ||
@@ -310,12 +302,4 @@ describe(".createClaimStake", () => { | ||
}); | ||
it("should throw an error when the wallet does not have a default address", async () => { | ||
const newWallet = wallet_1.Wallet.init(walletModel); | ||
await expect(async () => await newWallet.createClaimStake(0.001, coinbase_1.Coinbase.assets.Eth)).rejects.toThrow(Error); | ||
}); | ||
}); | ||
describe(".stakeableBalance", () => { | ||
it("should throw an error when the wallet does not have a default address", async () => { | ||
const newWallet = wallet_1.Wallet.init(walletModel); | ||
await expect(async () => await newWallet.stakeableBalance(coinbase_1.Coinbase.assets.Eth)).rejects.toThrow(Error); | ||
}); | ||
it("should return the stakeable balance successfully with default params", async () => { | ||
@@ -329,6 +313,2 @@ //const wallet = await Wallet.create({ networkId: Coinbase.networks.EthereumHolesky }); | ||
describe(".unstakeableBalance", () => { | ||
it("should throw an error when the wallet does not have a default address", async () => { | ||
const newWallet = wallet_1.Wallet.init(walletModel); | ||
await expect(async () => await newWallet.unstakeableBalance(coinbase_1.Coinbase.assets.Eth)).rejects.toThrow(Error); | ||
}); | ||
it("should return the unstakeableBalance balance successfully with default params", async () => { | ||
@@ -342,6 +322,2 @@ const wallet = await wallet_1.Wallet.create({ networkId: coinbase_1.Coinbase.networks.EthereumHolesky }); | ||
describe(".claimableBalance", () => { | ||
it("should throw an error when the wallet does not have a default address", async () => { | ||
const newWallet = wallet_1.Wallet.init(walletModel); | ||
await expect(async () => await newWallet.claimableBalance(coinbase_1.Coinbase.assets.Eth)).rejects.toThrow(Error); | ||
}); | ||
it("should return the claimableBalance balance successfully with default params", async () => { | ||
@@ -355,6 +331,2 @@ const wallet = await wallet_1.Wallet.create({ networkId: coinbase_1.Coinbase.networks.EthereumHolesky }); | ||
describe(".stakingRewards", () => { | ||
it("should throw an error when the wallet does not have a default address", async () => { | ||
const newWallet = wallet_1.Wallet.init(walletModel); | ||
await expect(async () => await newWallet.stakingRewards(coinbase_1.Coinbase.assets.Eth)).rejects.toThrow(Error); | ||
}); | ||
it("should successfully return staking rewards", async () => { | ||
@@ -369,6 +341,2 @@ const wallet = await wallet_1.Wallet.create({ networkId: coinbase_1.Coinbase.networks.EthereumHolesky }); | ||
describe(".historicalStakingBalances", () => { | ||
it("should throw an error when the wallet does not have a default address", async () => { | ||
const newWallet = wallet_1.Wallet.init(walletModel); | ||
await expect(async () => await newWallet.historicalStakingBalances(coinbase_1.Coinbase.assets.Eth)).rejects.toThrow(Error); | ||
}); | ||
it("should successfully return historical staking balances", async () => { | ||
@@ -420,11 +388,5 @@ const wallet = await wallet_1.Wallet.create({ networkId: coinbase_1.Coinbase.networks.EthereumHolesky }); | ||
}; | ||
coinbase_1.Coinbase.apiClients.externalAddress = utils_1.externalAddressApiMock; | ||
coinbase_1.Coinbase.apiClients.externalAddress.listAddressHistoricalBalance = (0, utils_1.mockReturnValue)(mockHistoricalBalanceResponse); | ||
coinbase_1.Coinbase.apiClients.balanceHistory = utils_1.balanceHistoryApiMock; | ||
coinbase_1.Coinbase.apiClients.balanceHistory.listAddressHistoricalBalance = (0, utils_1.mockReturnValue)(mockHistoricalBalanceResponse); | ||
}); | ||
it("should throw an error when the wallet does not have a default address", async () => { | ||
const newWallet = wallet_1.Wallet.init(walletModel); | ||
await expect(async () => await newWallet.listHistoricalBalances({ | ||
assetId: coinbase_1.Coinbase.assets.Usdc, | ||
})).rejects.toThrow(Error); | ||
}); | ||
it("should successfully return historical balances", async () => { | ||
@@ -534,20 +496,13 @@ const wallet = await wallet_1.Wallet.create({ networkId: coinbase_1.Coinbase.networks.EthereumHolesky }); | ||
}; | ||
beforeEach(() => { | ||
beforeEach(async () => { | ||
expectedInvocation = contract_invocation_1.ContractInvocation.fromModel(utils_1.VALID_SIGNED_CONTRACT_INVOCATION_MODEL); | ||
wallet.getDefaultAddress().invokeContract = jest.fn().mockResolvedValue(expectedInvocation); | ||
(await wallet.getDefaultAddress()).invokeContract = jest.fn().mockResolvedValue(expectedInvocation); | ||
}); | ||
it("successfully invokes a contract on the default address", async () => { | ||
const contractInvocation = await wallet.invokeContract(options); | ||
expect(wallet.getDefaultAddress().invokeContract).toHaveBeenCalledTimes(1); | ||
expect(wallet.getDefaultAddress().invokeContract).toHaveBeenCalledWith(options); | ||
expect((await wallet.getDefaultAddress()).invokeContract).toHaveBeenCalledTimes(1); | ||
expect((await wallet.getDefaultAddress()).invokeContract).toHaveBeenCalledWith(options); | ||
expect(contractInvocation).toBeInstanceOf(contract_invocation_1.ContractInvocation); | ||
expect(contractInvocation).toEqual(expectedInvocation); | ||
}); | ||
describe("when the wallet does not have a default address", () => { | ||
let invalidWallet; | ||
beforeEach(() => (invalidWallet = wallet_1.Wallet.init(walletModel))); | ||
it("should throw an Error", async () => { | ||
await expect(async () => await invalidWallet.invokeContract(options)).rejects.toThrow(Error); | ||
}); | ||
}); | ||
}); | ||
@@ -566,3 +521,3 @@ describe("#createPayloadSignature", () => { | ||
const payloadSignature = await wallet.createPayloadSignature(unsignedPayload); | ||
expect(coinbase_1.Coinbase.apiClients.address.createPayloadSignature).toHaveBeenCalledWith(wallet.getId(), wallet.getDefaultAddress().getId(), { | ||
expect(coinbase_1.Coinbase.apiClients.address.createPayloadSignature).toHaveBeenCalledWith(wallet.getId(), (await wallet.getDefaultAddress()).getId(), { | ||
unsigned_payload: unsignedPayload, | ||
@@ -579,3 +534,3 @@ signature, | ||
}).rejects.toThrow(Error); | ||
expect(coinbase_1.Coinbase.apiClients.address.createPayloadSignature).toHaveBeenCalledWith(wallet.getId(), wallet.getDefaultAddress().getId(), { | ||
expect(coinbase_1.Coinbase.apiClients.address.createPayloadSignature).toHaveBeenCalledWith(wallet.getId(), (await wallet.getDefaultAddress()).getId(), { | ||
unsigned_payload: unsignedPayload, | ||
@@ -586,9 +541,2 @@ signature, | ||
}); | ||
it("should throw an Error when the wallet does not have a default address", async () => { | ||
const invalidWallet = wallet_1.Wallet.init(walletModel); | ||
expect(async () => { | ||
await invalidWallet.createPayloadSignature(unsignedPayload); | ||
}).rejects.toThrow(Error); | ||
expect(coinbase_1.Coinbase.apiClients.address.createPayloadSignature).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
@@ -646,3 +594,3 @@ describe(".create", () => { | ||
it("should return the correct default address", async () => { | ||
expect(wallet.getDefaultAddress().getId()).toBe(walletModel.default_address.address_id); | ||
expect((await wallet.getDefaultAddress()).getId()).toBe(walletModel.default_address.address_id); | ||
}); | ||
@@ -676,3 +624,3 @@ }); | ||
expect(addresses.length).toBe(2); | ||
expect(wallet.getAddress(newAddress.getId()).getId()).toBe(newAddress.getId()); | ||
expect((await wallet.getAddress(newAddress.getId())).getId()).toBe(newAddress.getId()); | ||
expect(coinbase_1.Coinbase.apiClients.address.createAddress).toHaveBeenCalledTimes(1); | ||
@@ -765,10 +713,2 @@ }); | ||
}); | ||
it("should throw an error when the wallet does not have a default address", async () => { | ||
const wallet = wallet_1.Wallet.init({ | ||
id: walletId, | ||
network_id: coinbase_1.Coinbase.networks.BaseSepolia, | ||
feature_set: {}, | ||
}); | ||
await expect(async () => await wallet.faucet()).rejects.toThrow(Error); | ||
}); | ||
it("should return a Wallet instance", async () => { | ||
@@ -797,3 +737,3 @@ expect(wallet).toBeInstanceOf(wallet_1.Wallet); | ||
expect(addresses.length).toBe(3); | ||
expect(wallet.getAddress(newAddress.getId()).getId()).toBe(newAddress.getId()); | ||
expect((await wallet.getAddress(newAddress.getId())).getId()).toBe(newAddress.getId()); | ||
}); | ||
@@ -861,2 +801,7 @@ it("should return the correct string representation", async () => { | ||
}); | ||
it("should throw an error when walletId is not provided", async () => { | ||
const walletData = seedWallet.export(); | ||
walletData.walletId = ""; | ||
await expect(async () => await wallet_1.Wallet.import(walletData)).rejects.toThrow("Wallet ID must be provided"); | ||
}); | ||
}); | ||
@@ -1122,6 +1067,2 @@ describe("#listBalances", () => { | ||
}); | ||
it("should throw an error when the wallet does not have a default address", async () => { | ||
const newWallet = wallet_1.Wallet.init(walletModel); | ||
await expect(async () => await newWallet.createTrade({ amount: 0.01, fromAssetId: "eth", toAssetId: "usdc" })).rejects.toThrow(Error); | ||
}); | ||
it("should create a trade from the default address", async () => { | ||
@@ -1128,0 +1069,0 @@ const trade = Promise.resolve(tradeObject); |
@@ -7,3 +7,3 @@ { | ||
"repository": "https://github.com/coinbase/coinbase-sdk-nodejs", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"main": "dist/index.js", | ||
@@ -10,0 +10,0 @@ "types": "dist/index.d.ts", |
@@ -134,3 +134,3 @@ # Coinbase Node.js SDK | ||
// A Wallet has a default Address. | ||
const address = wallet.getDefaultAddress(); | ||
const address = await wallet.getDefaultAddress(); | ||
console.log(`Address: ${address}`); | ||
@@ -137,0 +137,0 @@ ``` |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1315043
27728