Skip to content

Compatibility of Blinks and Actions #16

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

Merged
merged 25 commits into from
Aug 13, 2024
Merged

Compatibility of Blinks and Actions #16

merged 25 commits into from
Aug 13, 2024

Conversation

tsmbl
Copy link
Contributor

@tsmbl tsmbl commented Aug 7, 2024

Context & Problem

Based on sRFC https://forum.solana.com/t/srfc-31-compatibility-of-blinks-and-actions/1892

Response headers are proposed to be set by Action developers:

  • X-Action-Version to show what spec version the action API server is using
  • X-Blockchain-Ids to list blockchains the action supports.

In the future request headers are proposed to be set by Blink clients:

  • X-Accept-Action-Version to show the max spec version the Blink client supports.
  • X-Accept-Blockchain-Ids to list blockchains the client supports.

Response headers should be used to decide if Action supported by client.

Solution

  1. Allow specifying action adapter metadata, this data can be used in default supportability checks and later can be used to set X-Accept-Blockchain-Ids` request header.
  2. Parametrize action with supportedBlockchainIds strategy
  3. Provide utility functions for supportability checks by comparing action & blink metadata:
  • Semver versions: action is not supported if action provider spec version > blink library spec version, patch version is ignored during comparison.
  • Blockchain IDs: action is not supported if there's at least one blockchain id that is not supported by blink library client
  1. Provide default implementation for metadata and supportability in ActionConfig

Breaking changes

  • move isSupported from ActionAdapter, to Action and to ObserverOptions correspondingly

Example adapter initialization

  1. Default settings in ActionConfig: in this case client supports solana mainnet & devnet + spec version from package.json
const defaultActionConfig: ActionConfig = new ActionConfig(
  'http://localhost:8080',
  {
    connect: async (c) => {
      return 'connected';
    },
    signTransaction: async (tx, c) => {
      return { signature: 'signed' };
    },
  },
);
  1. Configure metadata in ActionConfig: in this case client supports supportedBlockchainIds + spec version from package.json, supportedBlockchainIds can be later used to set X-Accept-Blockchain-Ids request header
const actionConfigWithMetadata: ActionConfig = new ActionConfig(
  'http://localhost:8080',
  {
    metadata: {
      supportedBlockchainIds: [BlockchainIds.SOLANA_MAINNET],
    },
    connect: async (c) => {
      return 'connected';
    },
    signTransaction: async (tx, c) => {
      return { signature: 'signed' };
    }
  },
);
  1. Overriding default supportStrategy in useAction
 const { action } = useAction({
    supportStrategy: async () => ({
      isSupported: false,
      message: 'Message to be displayed.',
    }),
    // ...rest
  });
  1. Overriding default supportStrategy in setupTwitterObserver
setupTwitterObserver(
  null as unknown as ActionAdapter,
  {},
  {
    supportStrategy: async (a) => {
      const versionSupported = a.metadata.version === '2.2.8';
      if (!versionSupported) {
        return {
          isSupported: false,
          message: 'Version not supported',
        };
      }
      return {
        isSupported: true,
      };
    },
  },
);

Related PR in actions spec: solana-developers/solana-actions#21
Related PR in actions-proxy: https://github.com/dialectlabs/actions-backend/pull/2

@tsmbl tsmbl requested a review from fsher August 8, 2024 08:45
@tsmbl tsmbl changed the title [WIP] Compatibility of Blinks and Actions Compatibility of Blinks and Actions Aug 8, 2024
Copy link
Contributor

@zhelezkov zhelezkov left a comment

Choose a reason for hiding this comment

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

this is really good job
Love the documented code and tests!

* Baseline action version to be used when not set by action provider.
* Defaults to latest release that doesn't support versioning.
*/
export const BASELINE_ACTION_VERSION = '2.0.0';
Copy link
Contributor

Choose a reason for hiding this comment

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

why 2.0.0? shouldn't it be 2.2 or smth?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

was a question of release sequencing, I think ok to use 2.2 now since chaining and inputs are merged

@tsmbl tsmbl force-pushed the feat/action-compatibility branch from 73a312a to eda8dd0 Compare August 10, 2024 08:13
@tsmbl tsmbl requested a review from zhelezkov August 12, 2024 13:08
@tsmbl tsmbl marked this pull request as ready for review August 12, 2024 13:08
Copy link
Collaborator

@fsher fsher left a comment

Choose a reason for hiding this comment

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

amazing job! minor comments

@tsmbl tsmbl requested a review from fsher August 12, 2024 18:05
@fsher fsher merged commit 045988c into main Aug 13, 2024
@fsher fsher deleted the feat/action-compatibility branch August 13, 2024 12:45
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