Skip to content

Commit ba4c9e0

Browse files
Merge pull request #189 from coinbase/bug/fix-staking-balance-units
[bugfix] Use proper atomic units for staking balances
2 parents 5a034db + 345eefe commit ba4c9e0

File tree

9 files changed

+19
-49
lines changed

9 files changed

+19
-49
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
## [0.1.1] - 2024-08-27
6+
7+
- Fixed a bug where `listHistoricalBalances` method was parsing conventional ETH balances instead of atomic units
8+
59
## [0.1.0] - 2024-08-22
610

711
### Added

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"license": "ISC",
55
"description": "Coinbase Platform SDK",
66
"repository": "https://github.com/coinbase/coinbase-sdk-nodejs",
7-
"version": "0.1.0",
7+
"version": "0.1.1",
88
"main": "dist/index.js",
99
"types": "dist/index.d.ts",
1010
"scripts": {

src/coinbase/balance.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,4 @@ export class Balance {
5252
asset,
5353
);
5454
}
55-
56-
/**
57-
* Converts a BalanceModel of which the amount is in the most common denomination such as ETH, BTC, etc.
58-
*
59-
* @param {BalanceModel} model - The balance model object.
60-
* @returns {Balance} The Balance object.
61-
*/
62-
public static fromModelWithAmountInWholeUnits(model: BalanceModel): Balance {
63-
const asset = Asset.fromModel(model.asset);
64-
return new Balance(new Decimal(model.amount), asset.getAssetId(), asset);
65-
}
6655
}

src/coinbase/staking_balance.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class StakingBalance {
7070
* @returns The Balance.
7171
*/
7272
public bondedStake(): Balance {
73-
return Balance.fromModelWithAmountInWholeUnits(this.model.bonded_stake);
73+
return Balance.fromModel(this.model.bonded_stake);
7474
}
7575

7676
/**
@@ -79,7 +79,7 @@ export class StakingBalance {
7979
* @returns The Balance.
8080
*/
8181
public unbondedBalance(): Balance {
82-
return Balance.fromModelWithAmountInWholeUnits(this.model.unbonded_balance);
82+
return Balance.fromModel(this.model.unbonded_balance);
8383
}
8484

8585
/**

src/tests/balance_test.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,4 @@ describe("Balance", () => {
4949
expect(balance.assetId).toBe(Coinbase.assets.Eth);
5050
});
5151
});
52-
53-
describe(".fromModelWithAmountInWholeUnits", () => {
54-
const amount = new Decimal(32);
55-
const balanceModel: BalanceModel = {
56-
asset: {
57-
asset_id: Coinbase.assets.Eth,
58-
network_id: Coinbase.networks.BaseSepolia,
59-
decimals: 18,
60-
contract_address: "0x",
61-
},
62-
amount: "32",
63-
};
64-
65-
const balance = Balance.fromModelWithAmountInWholeUnits(balanceModel);
66-
67-
it("returns a new Balance object with the correct amount", () => {
68-
expect(balance.amount).toEqual(amount);
69-
});
70-
71-
it("returns a new Balance object with the correct asset_id", () => {
72-
expect(balance.assetId).toBe(Coinbase.assets.Eth);
73-
});
74-
});
7552
});

src/tests/staking_historical_balance_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ describe("StakingBalance", () => {
2323
};
2424

2525
const bondedStake = {
26-
amount: "32",
26+
amount: "32000000000000000000",
2727
asset: asset,
2828
};
2929
const unbondedBalance = {
30-
amount: "2",
30+
amount: "2000000000000000000",
3131
asset: asset,
3232
};
3333

src/tests/wallet_address_test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,15 @@ describe("WalletAddress", () => {
352352
address: newAddress.address_id,
353353
date: "2024-05-01",
354354
bonded_stake: {
355-
amount: "32",
355+
amount: "32000000000000000000",
356356
asset: {
357357
asset_id: Coinbase.assets.Eth,
358358
network_id: Coinbase.networks.EthereumHolesky,
359359
decimals: 18,
360360
},
361361
},
362362
unbonded_balance: {
363-
amount: "2",
363+
amount: "2000000000000000000",
364364
asset: {
365365
asset_id: Coinbase.assets.Eth,
366366
network_id: Coinbase.networks.EthereumHolesky,
@@ -373,15 +373,15 @@ describe("WalletAddress", () => {
373373
address: newAddress.address_id,
374374
date: "2024-05-02",
375375
bonded_stake: {
376-
amount: "34",
376+
amount: "34000000000000000000",
377377
asset: {
378378
asset_id: Coinbase.assets.Eth,
379379
network_id: Coinbase.networks.EthereumHolesky,
380380
decimals: 18,
381381
},
382382
},
383383
unbonded_balance: {
384-
amount: "3",
384+
amount: "3000000000000000000",
385385
asset: {
386386
asset_id: Coinbase.assets.Eth,
387387
network_id: Coinbase.networks.EthereumHolesky,

src/tests/wallet_test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,15 @@ describe("Wallet Class", () => {
200200
address: addressID,
201201
date: "2024-05-01",
202202
bonded_stake: {
203-
amount: "32",
203+
amount: "32000000000000000000",
204204
asset: {
205205
asset_id: Coinbase.assets.Eth,
206206
network_id: Coinbase.networks.EthereumHolesky,
207207
decimals: 18,
208208
},
209209
},
210210
unbonded_balance: {
211-
amount: "2",
211+
amount: "2000000000000000000",
212212
asset: {
213213
asset_id: Coinbase.assets.Eth,
214214
network_id: Coinbase.networks.EthereumHolesky,
@@ -221,15 +221,15 @@ describe("Wallet Class", () => {
221221
address: addressID,
222222
date: "2024-05-02",
223223
bonded_stake: {
224-
amount: "32",
224+
amount: "32000000000000000000",
225225
asset: {
226226
asset_id: Coinbase.assets.Eth,
227227
network_id: Coinbase.networks.EthereumHolesky,
228228
decimals: 18,
229229
},
230230
},
231231
unbonded_balance: {
232-
amount: "2",
232+
amount: "2000000000000000000",
233233
asset: {
234234
asset_id: Coinbase.assets.Eth,
235235
network_id: Coinbase.networks.EthereumHolesky,

0 commit comments

Comments
 (0)