Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

## [0.1.1] - 2024-08-27

- Fixed a bug where `listHistoricalBalances` method was parsing conventional ETH balances instead of atomic units

## [0.1.0] - 2024-08-22

### Added
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "ISC",
"description": "Coinbase Platform SDK",
"repository": "https://github.com/coinbase/coinbase-sdk-nodejs",
"version": "0.1.0",
"version": "0.1.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
Expand Down
11 changes: 0 additions & 11 deletions src/coinbase/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,4 @@ export class Balance {
asset,
);
}

/**
* Converts a BalanceModel of which the amount is in the most common denomination such as ETH, BTC, etc.
*
* @param {BalanceModel} model - The balance model object.
* @returns {Balance} The Balance object.
*/
public static fromModelWithAmountInWholeUnits(model: BalanceModel): Balance {
const asset = Asset.fromModel(model.asset);
return new Balance(new Decimal(model.amount), asset.getAssetId(), asset);
}
}
4 changes: 2 additions & 2 deletions src/coinbase/staking_balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class StakingBalance {
* @returns The Balance.
*/
public bondedStake(): Balance {
return Balance.fromModelWithAmountInWholeUnits(this.model.bonded_stake);
return Balance.fromModel(this.model.bonded_stake);
}

/**
Expand All @@ -79,7 +79,7 @@ export class StakingBalance {
* @returns The Balance.
*/
public unbondedBalance(): Balance {
return Balance.fromModelWithAmountInWholeUnits(this.model.unbonded_balance);
return Balance.fromModel(this.model.unbonded_balance);
}

/**
Expand Down
23 changes: 0 additions & 23 deletions src/tests/balance_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,4 @@ describe("Balance", () => {
expect(balance.assetId).toBe(Coinbase.assets.Eth);
});
});

describe(".fromModelWithAmountInWholeUnits", () => {
const amount = new Decimal(32);
const balanceModel: BalanceModel = {
asset: {
asset_id: Coinbase.assets.Eth,
network_id: Coinbase.networks.BaseSepolia,
decimals: 18,
contract_address: "0x",
},
amount: "32",
};

const balance = Balance.fromModelWithAmountInWholeUnits(balanceModel);

it("returns a new Balance object with the correct amount", () => {
expect(balance.amount).toEqual(amount);
});

it("returns a new Balance object with the correct asset_id", () => {
expect(balance.assetId).toBe(Coinbase.assets.Eth);
});
});
});
4 changes: 2 additions & 2 deletions src/tests/staking_historical_balance_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ describe("StakingBalance", () => {
};

const bondedStake = {
amount: "32",
amount: "32000000000000000000",
asset: asset,
};
const unbondedBalance = {
amount: "2",
amount: "2000000000000000000",
asset: asset,
};

Expand Down
8 changes: 4 additions & 4 deletions src/tests/wallet_address_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,15 @@ describe("WalletAddress", () => {
address: newAddress.address_id,
date: "2024-05-01",
bonded_stake: {
amount: "32",
amount: "32000000000000000000",
asset: {
asset_id: Coinbase.assets.Eth,
network_id: Coinbase.networks.EthereumHolesky,
decimals: 18,
},
},
unbonded_balance: {
amount: "2",
amount: "2000000000000000000",
asset: {
asset_id: Coinbase.assets.Eth,
network_id: Coinbase.networks.EthereumHolesky,
Expand All @@ -373,15 +373,15 @@ describe("WalletAddress", () => {
address: newAddress.address_id,
date: "2024-05-02",
bonded_stake: {
amount: "34",
amount: "34000000000000000000",
asset: {
asset_id: Coinbase.assets.Eth,
network_id: Coinbase.networks.EthereumHolesky,
decimals: 18,
},
},
unbonded_balance: {
amount: "3",
amount: "3000000000000000000",
asset: {
asset_id: Coinbase.assets.Eth,
network_id: Coinbase.networks.EthereumHolesky,
Expand Down
8 changes: 4 additions & 4 deletions src/tests/wallet_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ describe("Wallet Class", () => {
address: addressID,
date: "2024-05-01",
bonded_stake: {
amount: "32",
amount: "32000000000000000000",
asset: {
asset_id: Coinbase.assets.Eth,
network_id: Coinbase.networks.EthereumHolesky,
decimals: 18,
},
},
unbonded_balance: {
amount: "2",
amount: "2000000000000000000",
asset: {
asset_id: Coinbase.assets.Eth,
network_id: Coinbase.networks.EthereumHolesky,
Expand All @@ -221,15 +221,15 @@ describe("Wallet Class", () => {
address: addressID,
date: "2024-05-02",
bonded_stake: {
amount: "32",
amount: "32000000000000000000",
asset: {
asset_id: Coinbase.assets.Eth,
network_id: Coinbase.networks.EthereumHolesky,
decimals: 18,
},
},
unbonded_balance: {
amount: "2",
amount: "2000000000000000000",
asset: {
asset_id: Coinbase.assets.Eth,
network_id: Coinbase.networks.EthereumHolesky,
Expand Down