Skip to content

Commit

Permalink
Merge pull request #15 from coinbase/main-1712612541
Browse files Browse the repository at this point in the history
Release v0.6.0
  • Loading branch information
drohit-cb committed Apr 8, 2024
2 parents 2ba88d0 + f351623 commit b03c0d0
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 76 deletions.
18 changes: 6 additions & 12 deletions docs/openapi/orchestration.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1283,18 +1283,17 @@
"STATE_UNSPECIFIED",
"STATE_NOT_CONSTRUCTED",
"STATE_CONSTRUCTED",
"STATE_PENDING_SIGNING",
"STATE_PENDING_EXT_BROADCAST",
"STATE_SIGNED",
"STATE_BROADCASTING",
"STATE_CONFIRMING",
"STATE_CONFIRMED",
"STATE_FINALIZED",
"STATE_FAILED",
"STATE_SUCCESS",
"STATE_PENDING_EXT_BROADCAST"
"STATE_SUCCESS"
],
"default": "STATE_UNSPECIFIED",
"description": "State defines an enumeration of states for a staking transaction.\n\n - STATE_UNSPECIFIED: Unspecified transaction state, this is for backwards compatibility.\n - STATE_NOT_CONSTRUCTED: Tx has not yet been constructed in the backend.\n - STATE_CONSTRUCTED: Tx construction is over in the backend.\n - STATE_PENDING_SIGNING: Tx is waiting to be signed.\n - STATE_SIGNED: Tx has been signed and returned to the backend.\n - STATE_BROADCASTING: Tx is being broadcasted to the network.\n - STATE_CONFIRMING: Tx is waiting for confirmation.\n - STATE_CONFIRMED: Tx has been confirmed to be included in a block.\n - STATE_FINALIZED: Tx has been finalized.\n - STATE_FAILED: Tx construction or broadcasting failed.\n - STATE_SUCCESS: Tx has been successfully executed.\n - STATE_PENDING_EXT_BROADCAST: Tx is waiting to be externally broadcasted by the customer."
"description": "State defines an enumeration of states for a staking transaction.\n\n - STATE_UNSPECIFIED: Unspecified transaction state, this is for backwards compatibility.\n - STATE_NOT_CONSTRUCTED: Tx has not yet been constructed in the backend.\n - STATE_CONSTRUCTED: Tx construction is over in the backend.\n - STATE_PENDING_EXT_BROADCAST: Tx is waiting to be externally broadcasted by the customer.\n - STATE_SIGNED: Tx has been signed and returned to the backend.\n - STATE_BROADCASTING: Tx is being broadcasted to the network.\n - STATE_CONFIRMING: Tx is waiting for confirmation.\n - STATE_CONFIRMED: Tx has been confirmed to be included in a block.\n - STATE_FINALIZED: Tx has been finalized.\n - STATE_FAILED: Tx construction or broadcasting failed.\n - STATE_SUCCESS: Tx has been successfully executed."
},
"v1Validator": {
"type": "object",
Expand Down Expand Up @@ -1435,10 +1434,6 @@
"description": "The timestamp the workflow was last updated.",
"readOnly": true
},
"skipBroadcast": {
"type": "boolean",
"description": "Flag to skip tx broadcast to network on behalf of the user. Use this flag if you instead prefer to broadcast signed txs on your own."
},
"completeTime": {
"type": "string",
"format": "date-time",
Expand All @@ -1458,13 +1453,12 @@
"enum": [
"STATE_UNSPECIFIED",
"STATE_IN_PROGRESS",
"STATE_WAITING_FOR_SIGNING",
"STATE_WAITING_FOR_EXT_BROADCAST",
"STATE_COMPLETED",
"STATE_FAILED",
"STATE_WAITING_FOR_EXT_BROADCAST"
"STATE_FAILED"
],
"default": "STATE_UNSPECIFIED",
"description": "Example flow: A workflow with skip_broadcast = true leading to a successful completion.\n IN_PROGRESS -\u003e WAITING_FOR_EXT_BROADCAST -\u003e IN_PROGRESS -\u003e COMPLETED\n Example flow: A workflow with skip_broadcast = false leading to a successful completion.\n IN_PROGRESS -\u003e WAITING_FOR_SIGNING -\u003e IN_PROGRESS -\u003e COMPLETED\n Example flow: A workflow with skip_broadcast = false leading to a failure.\n IN_PROGRESS -\u003e WAITING_FOR_SIGNING -\u003e IN_PROGRESS -\u003e FAILED\n\n - STATE_UNSPECIFIED: Unspecified workflow state, this is for backwards compatibility.\n - STATE_IN_PROGRESS: In Progress represents a workflow that is currently in progress.\n - STATE_WAITING_FOR_SIGNING: Waiting for signing represents the workflow is waiting on the consumer to sign and return the corresponding signed tx.\n - STATE_COMPLETED: Completed represents the workflow has completed.\n - STATE_FAILED: Failed represents the workflow has failed.\n - STATE_WAITING_FOR_EXT_BROADCAST: Waiting for external broadcast represents the workflow is waiting for the customer to broadcast a tx and return its corresponding tx hash.",
"description": "Example flows:\n A workflow leading to a successful completion.\n IN_PROGRESS -\u003e WAITING_FOR_EXT_BROADCAST -\u003e IN_PROGRESS -\u003e COMPLETED\n A workflow leading to a failure.\n IN_PROGRESS -\u003e WAITING_FOR_EXT_BROADCAST -\u003e IN_PROGRESS -\u003e FAILED\n\n - STATE_UNSPECIFIED: Unspecified workflow state, this is for backwards compatibility.\n - STATE_IN_PROGRESS: In Progress represents a workflow that is currently in progress.\n - STATE_WAITING_FOR_EXT_BROADCAST: Waiting for external broadcast represents the workflow is waiting for the customer to broadcast a tx and return its corresponding tx hash.\n - STATE_COMPLETED: Completed represents the workflow has completed.\n - STATE_FAILED: Failed represents the workflow has failed.",
"title": "The state of a workflow"
},
"v1WorkflowStep": {
Expand Down
17 changes: 3 additions & 14 deletions examples/ethereum/create-and-process-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { TxSignerFactory } from '../../src/signers';
import {
StakingClient,
workflowHasFinished,
workflowWaitingForSigning,
workflowWaitingForExternalBroadcast,
isTxStepOutput,
isWaitStepOutput,
Expand Down Expand Up @@ -38,7 +37,6 @@ async function stakePartialEth(): Promise<void> {
workflow = await client.Ethereum.stake(
projectId,
network,
false,
stakerAddress,
integrationAddress,
amount,
Expand Down Expand Up @@ -80,7 +78,7 @@ async function stakePartialEth(): Promise<void> {

await printWorkflowProgressDetails(workflow);

if (workflowWaitingForSigning(workflow)) {
if (workflowWaitingForExternalBroadcast(workflow)) {
unsignedTx =
workflow.steps![currentStepId].txStepOutput?.unsignedTx || '';
if (unsignedTx === '') {
Expand All @@ -92,18 +90,9 @@ async function stakePartialEth(): Promise<void> {
console.log('Signing unsigned tx %s ...', unsignedTx);
const signedTx = await signer.signTransaction(privateKey, unsignedTx);

console.log('Returning back signed tx %s ...', signedTx);

workflow = await client.performWorkflowStep(
projectId,
workflowId,
currentStepId,
signedTx,
);
} else if (workflowWaitingForExternalBroadcast(workflow)) {
console.log(
'Please sign and broadcast this unsigned tx %s externally and return back the tx hash via the PerformWorkflowStep API ...',
unsignedTx,
'Please broadcast this signed tx %s externally and return back the tx hash via the PerformWorkflowStep API ...',
signedTx,
);
break;
} else if (workflowHasFinished(workflow)) {
Expand Down
1 change: 0 additions & 1 deletion examples/ethereum/create-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ async function stakePartialEth(): Promise<void> {
workflow = await client.Ethereum.stake(
projectId,
network,
true,
stakerAddress,
integrationAddress,
amount,
Expand Down
25 changes: 1 addition & 24 deletions examples/solana/create-and-process-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { TxSignerFactory } from '../../src/signers';
import {
StakingClient,
workflowHasFinished,
workflowWaitingForSigning,
workflowWaitingForExternalBroadcast,
isTxStepOutput,
isWaitStepOutput,
Expand Down Expand Up @@ -38,7 +37,6 @@ async function stakeSolana(): Promise<void> {
workflow = await client.Solana.stake(
projectId,
network,
true,
walletAddress,
validatorAddress,
amount,
Expand Down Expand Up @@ -83,7 +81,7 @@ async function stakeSolana(): Promise<void> {

await printWorkflowProgressDetails(workflow);

if (workflowWaitingForSigning(workflow)) {
if (workflowWaitingForExternalBroadcast(workflow)) {
unsignedTx =
workflow.steps![currentStepId].txStepOutput?.unsignedTx || '';
if (unsignedTx === '') {
Expand All @@ -95,27 +93,6 @@ async function stakeSolana(): Promise<void> {
console.log('Signing unsigned tx %s ...', unsignedTx);
const signedTx = await signer.signTransaction(privateKey, unsignedTx);

console.log('Returning back signed tx %s ...', signedTx);

workflow = await client.performWorkflowStep(
projectId,
workflowId,
currentStepId,
signedTx,
);
} else if (workflowWaitingForExternalBroadcast(workflow)) {
unsignedTx =
workflow.steps![currentStepId].txStepOutput?.unsignedTx || '';
if (unsignedTx === '') {
console.log('Waiting for unsigned tx to be available ...');
await new Promise((resolve) => setTimeout(resolve, 1000)); // sleep for 1 second
continue;
}

console.log('Signing unsigned tx %s ...', unsignedTx);

const signedTx = await signer.signTransaction(privateKey, unsignedTx);

console.log(
'Please broadcast this signed tx %s externally and return back the tx hash via the PerformWorkflowStep API ...',
signedTx,
Expand Down
1 change: 0 additions & 1 deletion examples/solana/create-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ async function stakeSolana(): Promise<void> {
workflow = await client.Solana.stake(
projectId,
network,
true,
walletAddress,
validatorAddress,
amount,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coinbase/staking-client-library-ts",
"version": "0.5.1",
"version": "0.6.0",
"description": "Coinbase Staking API Typescript Library",
"repository": "https://github.com/coinbase/staking-client-library-ts.git",
"license": "Apache-2.0",
Expand Down
6 changes: 0 additions & 6 deletions src/client/protocols/ethereum-kiln-staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export class Ethereum {
async stake(
projectId: string,
network: string,
skipBroadcast: boolean = false,
stakerAddress: string,
integratorContractAddress: string,
amount: string,
Expand All @@ -35,7 +34,6 @@ export class Ethereum {
parent: `projects/${projectId}`,
workflow: {
action: `protocols/ethereum_kiln/networks/${network}/actions/stake`,
skipBroadcast: skipBroadcast,
ethereumKilnStakingParameters: {
stakeParameters: {
stakerAddress: stakerAddress,
Expand All @@ -55,7 +53,6 @@ export class Ethereum {
async unstake(
projectId: string,
network: string,
skipBroadcast: boolean = false,
stakerAddress: string,
integratorContractAddress: string,
amount: string,
Expand All @@ -64,7 +61,6 @@ export class Ethereum {
parent: `projects/${projectId}`,
workflow: {
action: `protocols/ethereum_kiln/networks/${network}/actions/unstake`,
skipBroadcast: skipBroadcast,
ethereumKilnStakingParameters: {
unstakeParameters: {
stakerAddress: stakerAddress,
Expand All @@ -84,15 +80,13 @@ export class Ethereum {
async claimStake(
projectId: string,
network: string,
skipBroadcast: boolean = false,
stakerAddress: string,
integratorContractAddress: string,
): Promise<Workflow> {
const req: CreateWorkflowRequest = {
parent: `projects/${projectId}`,
workflow: {
action: `protocols/ethereum_kiln/networks/${network}/actions/claim_stake`,
skipBroadcast: skipBroadcast,
ethereumKilnStakingParameters: {
claimStakeParameters: {
stakerAddress: stakerAddress,
Expand Down
6 changes: 0 additions & 6 deletions src/client/protocols/solana-staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export class Solana {
async stake(
projectId: string,
network: string,
skipBroadcast: boolean = false,
walletAddress: string,
validatorAddress: string,
amount: string,
Expand All @@ -35,7 +34,6 @@ export class Solana {
parent: `projects/${projectId}`,
workflow: {
action: `protocols/solana/networks/${network}/actions/stake`,
skipBroadcast: skipBroadcast,
solanaStakingParameters: {
stakeParameters: {
walletAddress: walletAddress,
Expand All @@ -55,7 +53,6 @@ export class Solana {
async unstake(
projectId: string,
network: string,
skipBroadcast: boolean = false,
walletAddress: string,
stakeAccountAddress: string,
amount: string,
Expand All @@ -64,7 +61,6 @@ export class Solana {
parent: `projects/${projectId}`,
workflow: {
action: `protocols/solana/networks/${network}/actions/unstake`,
skipBroadcast: skipBroadcast,
solanaStakingParameters: {
unstakeParameters: {
walletAddress: walletAddress,
Expand All @@ -84,15 +80,13 @@ export class Solana {
async claimStake(
projectId: string,
network: string,
skipBroadcast: boolean = false,
walletAddress: string,
stakeAccountAddress: string,
): Promise<Workflow> {
const req: CreateWorkflowRequest = {
parent: `projects/${projectId}`,
workflow: {
action: `protocols/solana/networks/${network}/actions/claim_stake`,
skipBroadcast: skipBroadcast,
solanaStakingParameters: {
claimStakeParameters: {
walletAddress: walletAddress,
Expand Down
4 changes: 0 additions & 4 deletions src/client/staking-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,6 @@ export function workflowHasFinished(workflow: Workflow): boolean {
);
}

export function workflowWaitingForSigning(workflow: Workflow): boolean {
return workflow.state === WorkflowState.STATE_WAITING_FOR_SIGNING;
}

export function workflowWaitingForExternalBroadcast(
workflow: Workflow,
): boolean {
Expand Down
7 changes: 2 additions & 5 deletions src/gen/coinbase/staking/orchestration/v1/workflow.pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ export enum TxStepOutputState {
STATE_UNSPECIFIED = "STATE_UNSPECIFIED",
STATE_NOT_CONSTRUCTED = "STATE_NOT_CONSTRUCTED",
STATE_CONSTRUCTED = "STATE_CONSTRUCTED",
STATE_PENDING_SIGNING = "STATE_PENDING_SIGNING",
STATE_PENDING_EXT_BROADCAST = "STATE_PENDING_EXT_BROADCAST",
STATE_SIGNED = "STATE_SIGNED",
STATE_BROADCASTING = "STATE_BROADCASTING",
STATE_CONFIRMING = "STATE_CONFIRMING",
STATE_CONFIRMED = "STATE_CONFIRMED",
STATE_FINALIZED = "STATE_FINALIZED",
STATE_FAILED = "STATE_FAILED",
STATE_SUCCESS = "STATE_SUCCESS",
STATE_PENDING_EXT_BROADCAST = "STATE_PENDING_EXT_BROADCAST",
}

export enum WaitStepOutputWaitUnit {
Expand All @@ -50,10 +49,9 @@ export enum WaitStepOutputState {
export enum WorkflowState {
STATE_UNSPECIFIED = "STATE_UNSPECIFIED",
STATE_IN_PROGRESS = "STATE_IN_PROGRESS",
STATE_WAITING_FOR_SIGNING = "STATE_WAITING_FOR_SIGNING",
STATE_WAITING_FOR_EXT_BROADCAST = "STATE_WAITING_FOR_EXT_BROADCAST",
STATE_COMPLETED = "STATE_COMPLETED",
STATE_FAILED = "STATE_FAILED",
STATE_WAITING_FOR_EXT_BROADCAST = "STATE_WAITING_FOR_EXT_BROADCAST",
}

export type TxStepOutput = {
Expand Down Expand Up @@ -89,7 +87,6 @@ type BaseWorkflow = {
steps?: WorkflowStep[]
createTime?: GoogleProtobufTimestamp.Timestamp
updateTime?: GoogleProtobufTimestamp.Timestamp
skipBroadcast?: boolean
completeTime?: GoogleProtobufTimestamp.Timestamp
}

Expand Down

0 comments on commit b03c0d0

Please sign in to comment.