Skip to content

Commit 139aa3f

Browse files
authored
Remove staking target requirement (#18)
This PR is counterpart to coinbase/staking-client-library-ts#20 It helps remove the requirement to provide an explicit staking target (integrator contract address for ethereum partial staking and validator address for sol) while making staking api calls. As we move to a self-service world, we want customers to be able to just come and stake to default staking targets i.e. default integration contracts on both Holesky and Mainnet in the case of Partial ETH staking and default coinbase validators on both Devnet and Mainnet in the case of sol staking. As a result, we have updated the examples to not take integrator contract or validator address as required inputs.
1 parent 837275e commit 139aa3f

File tree

9 files changed

+320
-141
lines changed

9 files changed

+320
-141
lines changed

.github/workflows/test.yaml .github/workflows/ci.yaml

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Go Test
1+
name: CI
22

33
on:
44
push:
@@ -12,7 +12,8 @@ permissions:
1212
contents: read
1313

1414
jobs:
15-
test:
15+
ci:
16+
name: ci
1617
runs-on: ubuntu-latest
1718
steps:
1819
- uses: actions/checkout@v4
@@ -25,5 +26,11 @@ jobs:
2526
- name: Build
2627
run: go build -v ./...
2728

29+
- name: Lint
30+
uses: golangci/golangci-lint-action@v4
31+
with:
32+
version: v1.54.2
33+
args: --timeout=3m
34+
2835
- name: Test
2936
uses: robherley/go-test-action@v0

.github/workflows/lint.yaml

-28
This file was deleted.

.github/workflows/release.yaml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Version 🔖
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- '.version'
9+
10+
concurrency: ${{ github.workflow }}-${{ github.ref }}
11+
12+
jobs:
13+
release:
14+
runs-on: ubuntu-latest
15+
environment: release
16+
permissions:
17+
contents: write
18+
id-token: write
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Get version from .version file
25+
id: release_version
26+
run: echo "VERSION=$(cat .version")" >> $GITHUB_OUTPUT
27+
28+
- name: Check if tag exists
29+
id: check_tag
30+
run: |
31+
git fetch --tags
32+
if git rev-parse "v${{ steps.release_version.outputs.VERSION }}" >/dev/null 2>&1; then
33+
echo "::set-output name=EXISTS::true"
34+
fi
35+
36+
- name: Create Release
37+
if: steps.check_tag.outputs.EXISTS != 'true'
38+
uses: softprops/action-gh-release@v2
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
with:
42+
tag_name: v${{ steps.release_version.outputs.VERSION }}
43+
name: Release v${{ steps.release_version.outputs.VERSION }}
44+
draft: false
45+
prerelease: false
46+
generate_release_notes: true
47+
make_latest: true

.version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.5.0

README.md

+76-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ func main() {
6464
Parameters: &api.EthereumKilnStakingParameters_StakeParameters{
6565
StakeParameters: &api.EthereumKilnStakeParameters{
6666
StakerAddress: "0xdb816889F2a7362EF242E5a717dfD5B38Ae849FE",
67-
IntegratorContractAddress: "0xA55416de5DE61A0AC1aa8970a280E04388B1dE4b",
6867
Amount: &api.Amount{
6968
Value: "20",
7069
Currency: "ETH",
@@ -91,7 +90,82 @@ func main() {
9190
<summary>Output</summary>
9291

9392
```text
94-
2024/03/28 11:43:49 Workflow created: projects/62376b2f-3f24-42c9-9025-d576a3c06d6f/workflows/ffbf9b45-c57b-49cb-a4d5-fdab66d8cb25
93+
2024/03/28 11:43:49 Workflow created: workflows/ffbf9b45-c57b-49cb-a4d5-fdab66d8cb25
94+
```
95+
96+
</details>
97+
98+
### Stake SOL :diamond_shape_with_a_dot_inside:
99+
100+
This code sample creates an SOL staking workflow. View the full code sample [here](examples/solana/create-workflow/main.go)
101+
102+
<details open>
103+
<summary>Code Sample</summary>
104+
105+
```golang
106+
// examples/solana/create-workflow/main.go
107+
package main
108+
109+
import (
110+
"context"
111+
"log"
112+
113+
"github.com/coinbase/staking-client-library-go/auth"
114+
"github.com/coinbase/staking-client-library-go/client"
115+
"github.com/coinbase/staking-client-library-go/client/options"
116+
api "github.com/coinbase/staking-client-library-go/gen/go/coinbase/staking/orchestration/v1"
117+
)
118+
119+
func main() {
120+
ctx := context.Background()
121+
122+
// Loads the API key from the default location.
123+
apiKey, err := auth.NewAPIKey(auth.WithLoadAPIKeyFromFile(true))
124+
if err != nil {
125+
log.Fatalf("error loading API key: %s", err.Error())
126+
}
127+
128+
// Creates the Coinbase Staking API client.
129+
stakingClient, err := client.New(ctx, options.WithAPIKey(apiKey))
130+
if err != nil {
131+
log.Fatalf("error instantiating staking client: %s", err.Error())
132+
}
133+
134+
req := &api.CreateWorkflowRequest{
135+
Workflow: &api.Workflow{
136+
Action: "protocols/solana/networks/devnet/actions/stake",
137+
StakingParameters: &api.Workflow_SolanaStakingParameters{
138+
SolanaStakingParameters: &api.SolanaStakingParameters{
139+
Parameters: &api.SolanaStakingParameters_StakeParameters{
140+
StakeParameters: &api.SolanaStakeParameters{
141+
WalletAddress: walletAddress,
142+
Amount: &api.Amount{
143+
Value: amount,
144+
Currency: currency,
145+
},
146+
},
147+
},
148+
},
149+
},
150+
},
151+
}
152+
153+
workflow, err := stakingClient.Orchestration.CreateWorkflow(ctx, req)
154+
if err != nil {
155+
log.Fatalf("couldn't create workflow: %s", err.Error())
156+
}
157+
158+
log.Printf("Workflow created: %s", workflow.Name)
159+
}
160+
```
161+
162+
</details>
163+
164+
<details>
165+
<summary>Output</summary>
166+
167+
```text
168+
2024/03/28 11:43:49 Workflow created: workflows/6bd9fd82-8b9d-4a49-9039-f95bb850a7a2
95169
```
96170

97171
</details>

examples/ethereum/create-and-process-workflow/main.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ const (
2525
privateKey = ""
2626

2727
// TODO: Replace with your staker addresses and amount.
28-
stakerAddress = ""
29-
integratorContractAddress = "0xA55416de5DE61A0AC1aa8970a280E04388B1dE4b"
30-
amount = "11"
31-
currency = "ETH"
28+
stakerAddress = ""
29+
amount = "11"
30+
currency = "ETH"
3231
)
3332

3433
// An example function to demonstrate how to use the staking client libraries.
@@ -59,8 +58,7 @@ func main() {
5958
EthereumKilnStakingParameters: &api.EthereumKilnStakingParameters{
6059
Parameters: &api.EthereumKilnStakingParameters_StakeParameters{
6160
StakeParameters: &api.EthereumKilnStakeParameters{
62-
StakerAddress: stakerAddress,
63-
IntegratorContractAddress: integratorContractAddress,
61+
StakerAddress: stakerAddress,
6462
Amount: &api.Amount{
6563
Value: amount,
6664
Currency: currency,

examples/ethereum/create-workflow/main.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"context"
99
"log"
1010

11+
"google.golang.org/protobuf/encoding/protojson"
12+
1113
"github.com/coinbase/staking-client-library-go/auth"
1214
"github.com/coinbase/staking-client-library-go/client"
1315
"github.com/coinbase/staking-client-library-go/client/options"
@@ -36,8 +38,7 @@ func main() {
3638
EthereumKilnStakingParameters: &api.EthereumKilnStakingParameters{
3739
Parameters: &api.EthereumKilnStakingParameters_StakeParameters{
3840
StakeParameters: &api.EthereumKilnStakeParameters{
39-
StakerAddress: "0xdb816889F2a7362EF242E5a717dfD5B38Ae849FE",
40-
IntegratorContractAddress: "0xA55416de5DE61A0AC1aa8970a280E04388B1dE4b",
41+
StakerAddress: "0xdb816889F2a7362EF242E5a717dfD5B38Ae849FE",
4142
Amount: &api.Amount{
4243
Value: "20",
4344
Currency: "ETH",
@@ -54,5 +55,10 @@ func main() {
5455
log.Fatalf("couldn't create workflow: %s", err.Error())
5556
}
5657

57-
log.Printf("Workflow created: %s", workflow.Name)
58+
marshaled, err := protojson.MarshalOptions{Indent: " ", Multiline: true}.Marshal(workflow)
59+
if err != nil {
60+
log.Fatalf("error marshaling reward: %s", err.Error())
61+
}
62+
63+
log.Printf("Workflow created: \n%s", marshaled)
5864
}

0 commit comments

Comments
 (0)