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

Remove ProjectID, Add GHA #17

Merged
merged 8 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
24 changes: 24 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: TypeScript Lint

on:
push:
# branches:
Copy link
Contributor

Choose a reason for hiding this comment

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

is this needed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I commented for testing initially, but I'll uncomment now 😄.

# - master
pull_request:

permissions:
contents: read

jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"
- run: npm ci
- name: Run linter
run: npm run lint
8 changes: 4 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:
contents: read
id-token: write
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
node-version: "20.x"
Copy link
Contributor

Choose a reason for hiding this comment

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

curious if we need to update our require node version docs anywhere else ? not sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm. I moved to 20.x because that's the version specified in package.json. I'll update the README here as well. If we see anywhere else that's on 18.x, let's update it there too.

registry-url: "https://registry.npmjs.org"
- run: npm install -g npm@^9.5.0
- run: npm ci
- run: npm publish --provenance --access public
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ staking-client-*
dist/

node_modules/

# VSCode configuration
.vscode
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ import { StakingClient } from "@coinbase/staking-client-library-ts";
const client = new StakingClient();

client.Ethereum.stake(
'your-project-id', // replace with your project id
'holesky',
true,
'your-wallet-address', // replace with your wallet address
'0xdb816889F2a7362EF242E5a717dfD5B38Ae849FE', // replace with your wallet address
Copy link
Contributor

Choose a reason for hiding this comment

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

can we roll this back ? or was this intentional ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Per offline discussion: Will keep in for simplicity of the example 😄.

'0xA55416de5DE61A0AC1aa8970a280E04388B1dE4b',
'123',
)
Expand Down
8 changes: 3 additions & 5 deletions examples/ethereum/create-and-process-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import { Workflow } from '../../src/gen/coinbase/staking/orchestration/v1/workflow.pb';
import { calculateTimeDifference } from '../../src/utils/date';

const projectId: string = ''; // replace with your project id
const privateKey: string = ''; // replace with your private key
const stakerAddress: string = ''; // replace with your staker address
const integrationAddress: string = '0xA55416de5DE61A0AC1aa8970a280E04388B1dE4b'; // replace with your integration address
Expand All @@ -21,9 +20,9 @@ const client = new StakingClient();
const signer = TxSignerFactory.getSigner('ethereum');

async function stakePartialEth(): Promise<void> {
if (projectId === '' || privateKey === '' || stakerAddress === '') {
if (privateKey === '' || stakerAddress === '') {
throw new Error(
'Please set the projectId, privateKey and stakerAddress variables in this file',
'Please set the privateKey and stakerAddress variables in this file',
);
}

Expand All @@ -35,7 +34,6 @@ async function stakePartialEth(): Promise<void> {
try {
// Create a new eth kiln stake workflow
workflow = await client.Ethereum.stake(
projectId,
network,
stakerAddress,
integrationAddress,
Expand Down Expand Up @@ -68,7 +66,7 @@ async function stakePartialEth(): Promise<void> {
// If the workflow is waiting for external broadcast, sign and broadcast the unsigned tx externally and return back the tx hash via the PerformWorkflowStep API.
// Note: In this example, we just log this message as the wallet provider needs to implement this logic.
try {
workflow = await client.getWorkflow(projectId, workflowId);
workflow = await client.getWorkflow(workflowId);
} catch (error) {
// TODO: add retry logic for network errors
if (error instanceof Error) {
Expand Down
10 changes: 3 additions & 7 deletions examples/ethereum/create-workflow.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
import { StakingClient } from '../../src/client/staking-client';
import { Workflow } from '../../src/gen/coinbase/staking/orchestration/v1/workflow.pb';

const projectId: string = ''; // replace with your project id
const stakerAddress: string = ''; // replace with your staker address
const stakerAddress: string = '0xdb816889F2a7362EF242E5a717dfD5B38Ae849FE'; // replace with your staker address
const integrationAddress: string = '0xA55416de5DE61A0AC1aa8970a280E04388B1dE4b'; // replace with your integration address
const amount: string = '123'; // replace with your amount
const network: string = 'holesky'; // replace with your network

const client = new StakingClient();

async function stakePartialEth(): Promise<void> {
if (projectId === '' || stakerAddress === '') {
throw new Error(
'Please set the projectId and stakerAddress variables in this file',
);
if (stakerAddress === '') {
throw new Error('Please set the stakerAddress variable in this file');
}

let workflow: Workflow = {} as Workflow;

try {
// Create a new eth kiln stake workflow
workflow = await client.Ethereum.stake(
projectId,
network,
stakerAddress,
integrationAddress,
Expand Down
8 changes: 3 additions & 5 deletions examples/solana/create-and-process-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import { Workflow } from '../../src/gen/coinbase/staking/orchestration/v1/workflow.pb';
import { calculateTimeDifference } from '../../src/utils/date';

const projectId: string = ''; // replace with your project id
const privateKey: string = ''; // replace with your private key
const walletAddress: string = ''; // replace with your wallet address
const validatorAddress: string = 'beefKGBWeSpHzYBHZXwp5So7wdQGX6mu4ZHCsH3uTar'; // replace with your validator address
Expand All @@ -21,9 +20,9 @@ const client = new StakingClient();
const signer = TxSignerFactory.getSigner('solana');

async function stakeSolana(): Promise<void> {
if (projectId === '' || walletAddress === '') {
if (walletAddress === '') {
throw new Error(
'Please set the projectId and stakerAddress variables in this file',
'Please set the privateKey and stakerAddress variables in this file',
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. can we update check to look for both priv key and walletAddress
  2. can we update message to reflect both priv key and walletAddress

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, good catch. I'll double check these error messages in this repo to ensure they're correct as well.

);
}

Expand All @@ -35,7 +34,6 @@ async function stakeSolana(): Promise<void> {
try {
// Create a new solana stake workflow
workflow = await client.Solana.stake(
projectId,
network,
walletAddress,
validatorAddress,
Expand Down Expand Up @@ -71,7 +69,7 @@ async function stakeSolana(): Promise<void> {
// If the workflow is waiting for external broadcast, sign and broadcast the unsigned tx externally and return back the tx hash via the PerformWorkflowStep API.
// Note: In this example, we just log this message as the wallet provider needs to implement this logic.
try {
workflow = await client.getWorkflow(projectId, workflowId);
workflow = await client.getWorkflow(workflowId);
} catch (error) {
// TODO: add retry logic for network errors
if (error instanceof Error) {
Expand Down
8 changes: 2 additions & 6 deletions examples/solana/create-workflow.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { StakingClient } from '../../src/client/staking-client';
import { Workflow } from '../../src/gen/coinbase/staking/orchestration/v1/workflow.pb';

const projectId: string = ''; // replace with your project id
const walletAddress: string = ''; // replace with your wallet address
const validatorAddress: string = 'beefKGBWeSpHzYBHZXwp5So7wdQGX6mu4ZHCsH3uTar'; // replace with your validator address
const amount: string = '100000000'; // replace with your amount. For solana it should be >= 0.1 SOL
Expand All @@ -10,18 +9,15 @@ const network: string = 'mainnet'; // replace with your network
const client = new StakingClient();

async function stakeSolana(): Promise<void> {
if (projectId === '' || walletAddress === '') {
throw new Error(
'Please set the projectId and stakerAddress variables in this file',
);
if (walletAddress === '') {
throw new Error('Please set the stakerAddress variable in this file');
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: walletAddress

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

}

let workflow: Workflow = {} as Workflow;

try {
// Create a new solana stake workflow
workflow = await client.Solana.stake(
projectId,
network,
walletAddress,
validatorAddress,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"clean-gen": "rm -rf src/gen/* && rm -rf docs/openapi/*",
"build": "npm run clean && tsc",
"prepare": "npm run build",
"lint": "eslint . --ext .ts --ignore-pattern '/dist/*/*'",
"lint-fix": "eslint . --ext .ts --fix --ignore-pattern '/dist/*/*'"
"lint": "eslint . --ext .ts --ignore-pattern '/dist/*/*' --ignore-pattern '/src/gen/*/*'",
"lint-fix": "eslint . --ext .ts --fix --ignore-pattern '/dist/*/*' --ignore-pattern '/src/gen/*/*'"
},
"publishConfig": {
"access": "public",
Expand Down
9 changes: 3 additions & 6 deletions src/client/protocols/ethereum-kiln-staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export class Ethereum {
}

async stake(
projectId: string,
network: string,
stakerAddress: string,
integratorContractAddress: string,
Expand All @@ -46,11 +45,10 @@ export class Ethereum {
},
};

return this.parent.createWorkflow(projectId, req);
return this.parent.createWorkflow(req);
}

async unstake(
projectId: string,
network: string,
stakerAddress: string,
integratorContractAddress: string,
Expand All @@ -72,11 +70,10 @@ export class Ethereum {
},
};

return this.parent.createWorkflow(projectId, req);
return this.parent.createWorkflow(req);
}

async claimStake(
projectId: string,
network: string,
stakerAddress: string,
integratorContractAddress: string,
Expand All @@ -93,7 +90,7 @@ export class Ethereum {
},
};

return this.parent.createWorkflow(projectId, req);
return this.parent.createWorkflow(req);
}

async viewStakingContext(
Expand Down
9 changes: 3 additions & 6 deletions src/client/protocols/solana-staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export class Solana {
}

async stake(
projectId: string,
network: string,
walletAddress: string,
validatorAddress: string,
Expand All @@ -46,11 +45,10 @@ export class Solana {
},
};

return this.parent.createWorkflow(projectId, req);
return this.parent.createWorkflow(req);
}

async unstake(
projectId: string,
network: string,
walletAddress: string,
stakeAccountAddress: string,
Expand All @@ -72,11 +70,10 @@ export class Solana {
},
};

return this.parent.createWorkflow(projectId, req);
return this.parent.createWorkflow(req);
}

async claimStake(
projectId: string,
network: string,
walletAddress: string,
stakeAccountAddress: string,
Expand All @@ -93,7 +90,7 @@ export class Solana {
},
};

return this.parent.createWorkflow(projectId, req);
return this.parent.createWorkflow(req);
}

async viewStakingContext(
Expand Down
19 changes: 5 additions & 14 deletions src/client/staking-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,8 @@ export class StakingClient {

// Create a workflow under a given project. This function takes the entire req object as input.
// Use the protocol-specific helper functions like Ethereum.Stake to create a protocol and action specific workflow.
async createWorkflow(
projectId: string,
req: CreateWorkflowRequest,
): Promise<Workflow> {
const parent: string = `projects/${projectId}`;
const path: string = `/v1/${parent}/workflows`;
async createWorkflow(req: CreateWorkflowRequest): Promise<Workflow> {
const path: string = `/v1/workflows`;
const method: string = 'POST';
const url: string = this.baseURL + '/orchestration';

Expand All @@ -148,9 +144,8 @@ export class StakingClient {
}

// Get a workflow given its project and workflow id.
async getWorkflow(projectId: string, workflowId: string): Promise<Workflow> {
const parent: string = `projects/${projectId}`;
const name: string = `${parent}/workflows/${workflowId}`;
async getWorkflow(workflowId: string): Promise<Workflow> {
const name: string = `workflows/${workflowId}`;
const path: string = `/v1/${name}`;
const method: string = 'GET';
const url: string = this.baseURL + '/orchestration';
Expand All @@ -167,12 +162,10 @@ export class StakingClient {

// Return back a signed tx or a broadcasted tx hash for a given workflow and step number.
async performWorkflowStep(
projectId: string,
workflowId: string,
stepIndex: number,
data: string,
): Promise<Workflow> {
const parent: string = `projects/${projectId}`;
const name: string = `${parent}/workflows/${workflowId}`;
const path: string = `/v1/${name}/step`;
const method: string = 'POST';
Expand All @@ -192,12 +185,10 @@ export class StakingClient {

// List workflows for a given project.
async listWorkflows(
project: string,
pageSize: number = 100,
filter: string = '',
): Promise<ListWorkflowsResponse> {
const parent: string = `projects/${project}`;
const path: string = `/v1/${parent}/workflows`;
const path: string = `/v1/workflows`;
const method: string = 'GET';
const url: string = this.baseURL + '/orchestration';

Expand Down
Loading