Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List staking balances #134

Merged
merged 29 commits into from
Aug 13, 2024
Merged

List staking balances #134

merged 29 commits into from
Aug 13, 2024

Conversation

marchsu
Copy link
Contributor

@marchsu marchsu commented Aug 7, 2024

What changed? Why?

  • merge into v0.0.16
  • add StakingBalance with static method to get historical staking balances from backend
  • add this feature to Address\Wallet\External Address

Qualified Impact

const { Coinbase, StakingBalance } = require("./dist/index.js");


const coinbase = Coinbase.configureFromJson({ filePath: "~~~", basePath: "~~~" });
StakingBalance.list( Coinbase.networks.EthereumMainnet , Coinbase.assets.Eth, "0x80000001677f23a227dfed6f61b132d114be83b8ad0aa5f3c5d1d77e6ee0bf5f73b0af750cc34e8f2dae73c21dc36f4a", "2024-07-01T00:00:00Z", "2024-07-03T00:00:00Z").then(balances => {
    balances.forEach(balance => {console.log(balance.toString())});
}, error => {
    console.log(error);
});

Result

Model

StakingBalance {
  model: {
    address: '0x80000001677f23a227dfed6f61b132d114be83b8ad0aa5f3c5d1d77e6ee0bf5f73b0af750cc34e8f2dae73c21dc36f4a',
    bonded_stake: { amount: '32', asset: [Object] },
    date: '2024-07-04',
    participant_type: 'VALIDATOR',
    unbonded_balance: { amount: '5.483882434', asset: [Object] }
  }
}
StakingBalance {
  model: {
    address: '0x80000001677f23a227dfed6f61b132d114be83b8ad0aa5f3c5d1d77e6ee0bf5f73b0af750cc34e8f2dae73c21dc36f4a',
    bonded_stake: { amount: '32', asset: [Object] },
    date: '2024-07-03',
    participant_type: 'VALIDATOR',
    unbonded_balance: { amount: '5.481819906', asset: [Object] }
  }
}

ToString()

StakingBalance { date: '2024-07-04T00:00:00.000Z' address: '0x80000001677f23a227dfed6f61b132d114be83b8ad0aa5f3c5d1d77e6ee0bf5f73b0af750cc34e8f2dae73c21dc36f4a' bondedStake: 'Balance { amount: '32' asset: 'Asset{ networkId: ethereum-mainnet, assetId: eth, contractAddress: undefined, decimals: 18 }' }' unbondedBalance: 'Balance { amount: '5.483882434' asset: 'Asset{ networkId: ethereum-mainnet, assetId: eth, contractAddress: undefined, decimals: 18 }' }' participantType: 'VALIDATOR' }

StakingBalance { date: '2024-07-03T00:00:00.000Z' address: '0x80000001677f23a227dfed6f61b132d114be83b8ad0aa5f3c5d1d77e6ee0bf5f73b0af750cc34e8f2dae73c21dc36f4a' bondedStake: 'Balance { amount: '32' asset: 'Asset{ networkId: ethereum-mainnet, assetId: eth, contractAddress: undefined, decimals: 18 }' }' unbondedBalance: 'Balance { amount: '5.481819906' asset: 'Asset{ networkId: ethereum-mainnet, assetId: eth, contractAddress: undefined, decimals: 18 }' }' participantType: 'VALIDATOR' }

@cb-heimdall
Copy link

cb-heimdall commented Aug 7, 2024

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@marchsu marchsu force-pushed the list-staking-balances branch from a8490d4 to 1f4507e Compare August 8, 2024 01:34
@marchsu marchsu marked this pull request as ready for review August 12, 2024 20:14
Comment on lines +20 to +30
/**
* Returns a list of StakingBalances for the provided network, asset, and address.
*
* @param networkId - The network ID.
* @param assetId - The asset ID.
* @param address - The address ID.
* @param startTime - The start time.
* @param endTime - The end time.
* @returns The staking balances.
*/
public static async list(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a method on the Address class (ref) instead of static method here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have an equivalent for listing staking rewards , I think we need both

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. That pattern is fine. Can you please add the Address class change to this PR.

Copy link
Contributor Author

@marchsu marchsu Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added, wondering if I can test the change to Address, currently only unit tests added to all related files including Wallet, External Address & Wallet Address
hardcoded the address in the list and verify the call from address functions well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Thanks! You can also call this method on an ExternalAddress subclass instance if you want to test on a specific address.

Copy link
Contributor Author

@marchsu marchsu Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, that works as well

const addr = new ExternalAddress(Coinbase.networks.EthereumMainnet,  "0x80000001677f23a227dfed6f61b132d114be83b8ad0aa5f3c5d1d77e6ee0bf5f73b0af750cc34e8f2dae73c21dc36f4a")

addr.historicalStakingBalances(Coinbase.assets.Eth, "2024-07-01T00:00:00Z", "2024-07-03T00:00:00Z").then(balances => {
    balances.forEach(balance => {console.log(balance)});
} ).catch(error => {
    console.log(error);
});
StakingBalance {
  model: {
    address: '0x80000001677f23a227dfed6f61b132d114be83b8ad0aa5f3c5d1d77e6ee0bf5f73b0af750cc34e8f2dae73c21dc36f4a',
    bonded_stake: { amount: '32', asset: [Object] },
    date: '2024-07-02',
    participant_type: 'VALIDATOR',
    unbonded_balance: { amount: '5.479839548', asset: [Object] }
  }
}

toString()

StakingBalance { date: '2024-07-02T00:00:00.000Z' address: '0x80000001677f23a227dfed6f61b132d114be83b8ad0aa5f3c5d1d77e6ee0bf5f73b0af750cc34e8f2dae73c21dc36f4a' bondedStake: 'Balance { amount: '32' asset: 'Asset{ networkId: ethereum-mainnet, assetId: eth, contractAddress: undefined, decimals: 18 }' }' unbondedBalance: 'Balance { amount: '5.479839548' asset: 'Asset{ networkId: ethereum-mainnet, assetId: eth, contractAddress: undefined, decimals: 18 }' }' participantType: 'VALIDATOR' }

@marchsu marchsu changed the base branch from master to v0.0.16 August 12, 2024 22:06
@marchsu marchsu force-pushed the list-staking-balances branch from 23a2b0a to ab3337f Compare August 12, 2024 22:18
@John-peterson-coinbase
Copy link
Contributor

Please add an update to CHANGELOG.md with these changes

Copy link
Contributor

@John-peterson-coinbase John-peterson-coinbase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please prefix all of the static method jest descriptions with #

Ex. describe("#staticMethodName", () => {...}

Otherwise LGTM!

jest.clearAllMocks();
});

describe(".list", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
describe(".list", () => {
describe("#list", () => {

@marchsu marchsu merged commit bc0e7f4 into v0.0.16 Aug 13, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants