From e92027acd739bf35f8b71dea98ba70bb598f2388 Mon Sep 17 00:00:00 2001 From: Shane O'Brien Date: Tue, 17 Sep 2024 11:31:35 -0400 Subject: [PATCH 1/3] Moved around some examples --- .../main.go} | 0 .../main.go} | 0 examples/solana/list-staking-balances/main.go | 51 ++++++++++++++++++ examples/solana/list-staking-rewards/main.go | 53 +++++++++++++++++++ 4 files changed, 104 insertions(+) rename examples/eth/{build_staking_operation.go => build-staking-operation/main.go} (100%) rename examples/solana/{build_staking_operation.go => build-staking-operation/main.go} (100%) create mode 100644 examples/solana/list-staking-balances/main.go create mode 100644 examples/solana/list-staking-rewards/main.go diff --git a/examples/eth/build_staking_operation.go b/examples/eth/build-staking-operation/main.go similarity index 100% rename from examples/eth/build_staking_operation.go rename to examples/eth/build-staking-operation/main.go diff --git a/examples/solana/build_staking_operation.go b/examples/solana/build-staking-operation/main.go similarity index 100% rename from examples/solana/build_staking_operation.go rename to examples/solana/build-staking-operation/main.go diff --git a/examples/solana/list-staking-balances/main.go b/examples/solana/list-staking-balances/main.go new file mode 100644 index 0000000..e310e27 --- /dev/null +++ b/examples/solana/list-staking-balances/main.go @@ -0,0 +1,51 @@ +package main + +import ( + "context" + "log" + "os" + "time" + + "github.com/coinbase/coinbase-sdk-go/pkg/coinbase" +) + +var ( + networkID = "solana-mainnet" +) + +/* + * This example code list historical staking balances of any delegator on the Solana blockchain + * Run the code with 'go run examples/solana/list-staking-balances/main.go ' + */ + +func main() { + ctx := context.Background() + + client, err := coinbase.NewClient( + coinbase.WithAPIKeyFromJSON(os.Args[1]), + ) + if err != nil { + log.Fatalf("error creating coinbase client: %v", err) + } + + // Create a new external address on the solana-mainnet-beta network for which you want to view staking balances. + address := coinbase.NewExternalAddress(networkID, os.Args[2]) + + // Get the balances earned from staking in the last 10 days. + // Note that it can take several hours for new balances to show up. + balances, err := client.ListHistoricalStakingBalances( + ctx, + coinbase.Sol, + address, + time.Now().Add(-10*24*time.Hour), + time.Now(), + ) + if err != nil { + log.Fatalf("error fetching staking balances: %v", err) + } + + // Loop through the balances and print each staking balance. + for _, balance := range balances { + log.Printf("Staking balance: %s", balance.String()) + } +} diff --git a/examples/solana/list-staking-rewards/main.go b/examples/solana/list-staking-rewards/main.go new file mode 100644 index 0000000..5bb0844 --- /dev/null +++ b/examples/solana/list-staking-rewards/main.go @@ -0,0 +1,53 @@ +package main + +import ( + "context" + "log" + "os" + "time" + + api "github.com/coinbase/coinbase-sdk-go/gen/client" + "github.com/coinbase/coinbase-sdk-go/pkg/coinbase" +) + +var ( + networkID = "solana-mainnet" +) + +/* + * This example code list historical staking rewards of any delegator on the Solana blockchain + * Run the code with 'go run examples/solana/list-staking-rewards/main.go ' + */ + +func main() { + ctx := context.Background() + + client, err := coinbase.NewClient( + coinbase.WithAPIKeyFromJSON(os.Args[1]), + ) + if err != nil { + log.Fatalf("error creating coinbase client: %v", err) + } + + // Create a new external address on the solana-mainnet-beta network for which you want to view staking rewards. + address := coinbase.NewExternalAddress(networkID, os.Args[2]) + + // Get the rewards earned from staking in the last 10 days. + // Note that it can take several hours for new rewards to show up. + rewards, err := client.ListStakingRewards( + ctx, + coinbase.Sol, + []coinbase.Address{*address}, + time.Now().Add(-10*24*time.Hour), + time.Now(), + api.STAKINGREWARDFORMAT_USD, + ) + if err != nil { + log.Fatalf("error fetching staking rewards: %v", err) + } + + // Loop through the rewards and print each staking reward. + for _, reward := range rewards { + log.Printf("Staking reward: %s", reward.ToString()) + } +} From b13f7af05dc992d1f4716d9e4a58a402d66baa41 Mon Sep 17 00:00:00 2001 From: Shane O'Brien Date: Tue, 17 Sep 2024 14:03:40 -0400 Subject: [PATCH 2/3] Adding more detail and notes to the examples --- examples/eth/build-staking-operation/main.go | 7 ++++++- examples/solana/build-staking-operation/main.go | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/examples/eth/build-staking-operation/main.go b/examples/eth/build-staking-operation/main.go index 7ca2e46..de939c3 100644 --- a/examples/eth/build-staking-operation/main.go +++ b/examples/eth/build-staking-operation/main.go @@ -11,6 +11,11 @@ import ( "github.com/coinbase/coinbase-sdk-go/pkg/coinbase" ) +/* + * This example code stakes ETH on the Holesky network. + * Run the code with 'go run examples/ethereum/build-staking-operation/main.go ' + */ + func main() { ctx := context.Background() @@ -21,7 +26,7 @@ func main() { log.Fatalf("error creating coinbase client: %v", err) } - address := coinbase.NewExternalAddress("ethereum-holesky", "0x57a063e1df096aaA6b2068C3C7FE6Ac4BC3c4F58") + address := coinbase.NewExternalAddress("ethereum-holesky", os.Args[2]) stakeableBalance, err := client.GetStakeableBalance(ctx, coinbase.Eth, address, coinbase.WithStakingBalanceMode(coinbase.StakingOperationModePartial)) if err != nil { diff --git a/examples/solana/build-staking-operation/main.go b/examples/solana/build-staking-operation/main.go index 1d58b76..5e740eb 100644 --- a/examples/solana/build-staking-operation/main.go +++ b/examples/solana/build-staking-operation/main.go @@ -25,6 +25,11 @@ var ( defaultPrivKeyPath = filepath.Join(home(), ".config/solana/id.json") ) +/* + * This example code stakes SOL on the devnet network. + * Run the code with 'go run examples/solana/build-staking-operation/main.go ' + */ + func main() { ctx := context.Background() From 3183ac3085f78d25643951598447cbab22baae95 Mon Sep 17 00:00:00 2001 From: Shane O'Brien Date: Tue, 17 Sep 2024 14:49:05 -0400 Subject: [PATCH 3/3] Fix typo --- examples/solana/list-staking-balances/main.go | 2 +- examples/solana/list-staking-rewards/main.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/solana/list-staking-balances/main.go b/examples/solana/list-staking-balances/main.go index e310e27..e10bb5b 100644 --- a/examples/solana/list-staking-balances/main.go +++ b/examples/solana/list-staking-balances/main.go @@ -14,7 +14,7 @@ var ( ) /* - * This example code list historical staking balances of any delegator on the Solana blockchain + * This example code lists historical staking balances of any delegator on the Solana blockchain * Run the code with 'go run examples/solana/list-staking-balances/main.go ' */ diff --git a/examples/solana/list-staking-rewards/main.go b/examples/solana/list-staking-rewards/main.go index 5bb0844..ad3a8d8 100644 --- a/examples/solana/list-staking-rewards/main.go +++ b/examples/solana/list-staking-rewards/main.go @@ -15,7 +15,7 @@ var ( ) /* - * This example code list historical staking rewards of any delegator on the Solana blockchain + * This example code lists historical staking rewards of any delegator on the Solana blockchain * Run the code with 'go run examples/solana/list-staking-rewards/main.go ' */