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

lang, ts: Add deprecated state address feature flag #446

Merged
merged 3 commits into from
Jul 2, 2021

Conversation

armaniferrante
Copy link
Member

@armaniferrante armaniferrante commented Jun 30, 2021

Closes #445.

@bonedaddy
Copy link
Contributor

Updating Cargo.toml of my anchor project to this:

[package]
name = "vault"
version = "0.1.0"
description = "Created with Anchor"
edition = "2018"

[lib]
crate-type = ["cdylib", "lib"]
name = "vault"

[features]
no-entrypoint = []
no-idl = []
cpi = ["no-entrypoint"]
anchor-deprecated-state = []
default = ["anchor-deprecated-state"]


[dependencies]
anchor-lang = { git = "https://github.com/project-serum/anchor", rev="76ff61ebcdcb8b6d9f81092f7a8786fca195dd66", features = ["anchor-deprecated-state"]}
anchor-spl = { git = "https://github.com/project-serum/anchor", rev="76ff61ebcdcb8b6d9f81092f7a8786fca195dd66", features = ["anchor-deprecated-state"] }
spl-token = "3.1.1"
spl-associated-token-account = {version = "1.0.2", features = ["no-entrypoint"]}
serum_dex = { git = "https://github.com/bonedaddy/serum-dex", rev="ceb2b2120ad1dbf03375f464ab65ade6fc18fa20", features = ["no-entrypoint"] }
bytemuck = { version = "1.4.0" }

[dev-dependencies]
rand = "0.7.3"
safe-transmute = "0.11.0"
bumpalo = { version = "3.4.0", features = ["collections"] }

results in this error

Failed to obtain package metadata: Error during execution of `cargo metadata`:     Updating git repository `https://github.com/project-serum/anchor`
    Updating crates.io index
error: failed to select a version for `anchor-lang`.
    ... required by package `vault v0.1.0 (/media/solidity/DATA1/Code/sol-farm/protocol/programs/vault)`
versions that meet the requirements `*` are: 0.10.0

the package `vault` depends on `anchor-lang`, with features: `anchor-deprecated-state` but `anchor-lang` does not have these features.


failed to select a version for `anchor-lang` which could resolve this conflict

however the following works

[package]
name = "vault"
version = "0.1.0"
description = "Created with Anchor"
edition = "2018"

[lib]
crate-type = ["cdylib", "lib"]
name = "vault"

[features]
no-entrypoint = []
no-idl = []
cpi = ["no-entrypoint"]
anchor-deprecated-state = []
default = ["anchor-deprecated-state"]


[dependencies]
anchor-lang = { git = "https://github.com/project-serum/anchor", rev="76ff61ebcdcb8b6d9f81092f7a8786fca195dd66"}
anchor-spl = { git = "https://github.com/project-serum/anchor", rev="76ff61ebcdcb8b6d9f81092f7a8786fca195dd66"}
spl-token = "3.1.1"
spl-associated-token-account = {version = "1.0.2", features = ["no-entrypoint"]}
serum_dex = { git = "https://github.com/bonedaddy/serum-dex", rev="ceb2b2120ad1dbf03375f464ab65ade6fc18fa20", features = ["no-entrypoint"] }
bytemuck = { version = "1.4.0" }

[dev-dependencies]
rand = "0.7.3"
safe-transmute = "0.11.0"
bumpalo = { version = "3.4.0", features = ["collections"] }

@armaniferrante
Copy link
Member Author

@bonedaddy correct the feature only needs to be in your program. Let me explore adding it to the anchor-lang dependency instead.

@armaniferrante
Copy link
Member Author

I've moved the feature flag so that one must set it on the anchor-lang crate as opposed to on one's own program crate.

One important caveat when using this is that, if one's program depends on/links against any other anchor programs, they must all use this feature due to the fact that rust features are additive (so if one program enables the feature in anchor-lang, then it will be enabled for all transitive dependencies that also use anchor-lang).

@bonedaddy
Copy link
Contributor

Thanks! Will try this tonight

@bonedaddy
Copy link
Contributor

bonedaddy commented Jul 1, 2021

I have anchor in package.json set to

"@project-serum/anchor": "https://github.com/project-serum/anchor.git#armani/dep",

and am getting a typescript compilation error from the following

cli/accounts.ts:7:14 - error TS2339: Property 'features' does not exist on type '{ bs58: BaseConverter; sha256: { (input: string | ArrayBuffer | ArrayBufferView, options?: OptionsHexOutput): Promise<string>; (input: string | ... 1 more ... | ArrayBufferView, options: OptionBufferOutput): Promise<...>; }; getMultipleAccounts: (connection: Connection, publicKeys: PublicKey[]) => Promise<...>; idlA...'.

anchor.utils.features.set('anchor-deprecated-state');

anchor-spl gives this, however it's probably okay to not include?

    Updating git repository `https://github.com/project-serum/anchor`
error: failed to select a version for `anchor-spl`.
    ... required by package `vault v0.1.0 (/media/solidity/DATA1/Code/sol-farm/protocol/programs/vault)`
versions that meet the requirements `*` are: 0.10.0

the package `vault` depends on `anchor-spl`, with features: `anchor-deprecated-state` but `anchor-spl` does not have these features.


failed to select a version for `anchor-spl` which could resolve this conflict

anchor-client gives this, unlike anchor-spl i believe anchor-client would need the feature flag?

error: failed to select a version for `anchor-client`.
    ... required by package `vault v0.1.0 (/media/solidity/DATA1/Code/sol-farm/protocol/programs/vault)`
versions that meet the requirements `*` are: 0.10.0

the package `vault` depends on `anchor-client`, with features: `anchor-deprecated-state` but `anchor-client` does not have these features.


failed to select a version for `anchor-client` which could resolve this conflict

@armaniferrante
Copy link
Member Author

armaniferrante commented Jul 1, 2021

  • You probably aren't using the code on this branch for the ts client
  • anchor_spl won't need the feature flag
  • anchor_client will, so I'll update

@armaniferrante
Copy link
Member Author

armaniferrante commented Jul 1, 2021

Edit. You dont need feature flags for anchor-client since it will use the code generated by the program to deserialize (which will have the feature set). Though it's worth mentioning again that, technically, anchor-client's `anchor-lang dependency will have the feature set if it's pulling a program that has the feature set, since rust feature flags are additive.

On second thought, I think the first commit given here is probably the most clear solution. I.e., forcing one to use the feature on their program, instead of on anchor-lang. Otherwise there's a lot of implied behavior when linking together multiple programs in the same binary, which gives me pause.

@armaniferrante
Copy link
Member Author

armaniferrante commented Jul 1, 2021

Updated so that all one needs to do is add a default feature flag to their program to enable the change. This makes the behavior explicit and and allows one to mix and match programs that use this feature with programs that don't.

See https://github.com/project-serum/anchor/pull/446/files#diff-93ae0ef28524c67fa56a9f4a01515bf89659f6119761b9ee09e3906e34b68f9dR14-R15

This shouldn't be required in any other dependencies except for the javascript client.

@bonedaddy
Copy link
Contributor

Everything looks good, still having troubles with the ts dependency though.

Here's my package.json

{
  "name": "protocol",
  "version": "0.0.1",
  "description": "solfarm",
  "main": "index.js",
  "repository": "https://github.com/sol-farm/protocol.git",
  "author": "bonedaddy <boned4ddy@protonmail.com>",
  "license": "MIT",
  "dependencies": {
    "@project-serum/anchor": "git+https://github.com/project-serum/anchor.git#2e703d38aec4edfd2f3ba8965256126bc3037065",
    "@project-serum/associated-token": "^0.1.1",
    "@project-serum/common": "0.0.1-beta.3",
    "@project-serum/serum": "^0.13.33",
    "@project-serum/token": "^0.0.1-alpha.3",
    "@solana/spl-token": "^0.1.3",
    "@solana/web3.js": "^1.2.7",
    "@types/chai": "^4.2.17",
    "@types/mocha": "^8.2.2",
    "@types/node": "^14.14.41",
    "@types/yargs": "^16.0.1",
    "csv-parser": "^3.0.0",
    "ts-node": "^9.1.1",
    "typescript": "^4.2.4",
    "yargs": "^16.2.0"
  },
  "devDependencies": {
    "@project-serum/anchor": "git+https://github.com/project-serum/anchor.git#2e703d38aec4edfd2f3ba8965256126bc3037065",
    "@project-serum/associated-token": "^0.1.1",
    "@project-serum/borsh": "^0.1.0",
    "@project-serum/common": "0.0.1-beta.3",
    "@project-serum/serum": "^0.13.33",
    "@project-serum/token": "^0.0.1-alpha.3",
    "@solana/spl-token": "^0.1.3",
    "@solana/web3.js": "^1.2.7",
    "@types/node": "^14.14.41",
    "@types/yargs": "^16.0.1",
    "ts-node": "^9.1.1",
    "typescript": "^4.2.4"
  },
  "directories": {
    "test": "tests"
  },
  "scripts": {
    "test": "anchor test",
    "deploy": "anchor deploy",
    "migrate": "anchor migrate",
    "upgrade": "anchor upgrade"
  }
}

Here's the error

cli/accounts.ts:7:14 - error TS2339: Property 'features' does not exist on type '{ bs58: BaseConverter; sha256: { (input: string | ArrayBuffer | ArrayBufferView, options?: OptionsHexOutput): Promise<string>; (input: string | ... 1 more ... | ArrayBufferView, options: OptionBufferOutput): Promise<...>; }; getMultipleAccounts: (connection: Connection, publicKeys: PublicKey[]) => Promise<...>; idlA...'.

7 anchor.utils.features.set('anchor-deprecated-state');
               ~~~~~~~~

cli/commands.ts:42:14 - error TS2339: Property 'features' does not exist on type '{ bs58: BaseConverter; sha256: { (input: string | ArrayBuffer | ArrayBufferView, options?: OptionsHexOutput): Promise<string>; (input: string | ... 1 more ... | ArrayBufferView, options: OptionBufferOutput): Promise<...>; }; getMultipleAccounts: (connection: Connection, publicKeys: PublicKey[]) => Promise<...>; idlA...'.

42 anchor.utils.features.set('anchor-deprecated-state');
                ~~~~~~~~

cli/commands.ts:1872:7 - error TS2345: Argument of type '{ filters: { dataSize: number; }[]; }' is not assignable to parameter of type 'Commitment'.
  Type '{ filters: { dataSize: number; }[]; }' is not assignable to type '"max"'.

1872       {filters: [{dataSize: 56}]},
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~

cli/index.ts:38:14 - error TS2339: Property 'features' does not exist on type '{ bs58: BaseConverter; sha256: { (input: string | ArrayBuffer | ArrayBufferView, options?: OptionsHexOutput): Promise<string>; (input: string | ... 1 more ... | ArrayBufferView, options: OptionBufferOutput): Promise<...>; }; getMultipleAccounts: (connection: Connection, publicKeys: PublicKey[]) => Promise<...>; idlA...'.

38 anchor.utils.features.set('anchor-deprecated-state');
                ~~~~~~~~

cli/utils.ts:57:14 - error TS2339: Property 'features' does not exist on type '{ bs58: BaseConverter; sha256: { (input: string | ArrayBuffer | ArrayBufferView, options?: OptionsHexOutput): Promise<string>; (input: string | ... 1 more ... | ArrayBufferView, options: OptionBufferOutput): Promise<...>; }; getMultipleAccounts: (connection: Connection, publicKeys: PublicKey[]) => Promise<...>; idlA...'.

57 anchor.utils.features.set('anchor-deprecated-state');
                ~~~~~~~~


Found 5 errors.

@armaniferrante
Copy link
Member Author

Everything looks good, still having troubles with the ts dependency though.

Here's my package.json

{
  "name": "protocol",
  "version": "0.0.1",
  "description": "solfarm",
  "main": "index.js",
  "repository": "https://github.com/sol-farm/protocol.git",
  "author": "bonedaddy <boned4ddy@protonmail.com>",
  "license": "MIT",
  "dependencies": {
    "@project-serum/anchor": "git+https://github.com/project-serum/anchor.git#2e703d38aec4edfd2f3ba8965256126bc3037065",
    "@project-serum/associated-token": "^0.1.1",
    "@project-serum/common": "0.0.1-beta.3",
    "@project-serum/serum": "^0.13.33",
    "@project-serum/token": "^0.0.1-alpha.3",
    "@solana/spl-token": "^0.1.3",
    "@solana/web3.js": "^1.2.7",
    "@types/chai": "^4.2.17",
    "@types/mocha": "^8.2.2",
    "@types/node": "^14.14.41",
    "@types/yargs": "^16.0.1",
    "csv-parser": "^3.0.0",
    "ts-node": "^9.1.1",
    "typescript": "^4.2.4",
    "yargs": "^16.2.0"
  },
  "devDependencies": {
    "@project-serum/anchor": "git+https://github.com/project-serum/anchor.git#2e703d38aec4edfd2f3ba8965256126bc3037065",
    "@project-serum/associated-token": "^0.1.1",
    "@project-serum/borsh": "^0.1.0",
    "@project-serum/common": "0.0.1-beta.3",
    "@project-serum/serum": "^0.13.33",
    "@project-serum/token": "^0.0.1-alpha.3",
    "@solana/spl-token": "^0.1.3",
    "@solana/web3.js": "^1.2.7",
    "@types/node": "^14.14.41",
    "@types/yargs": "^16.0.1",
    "ts-node": "^9.1.1",
    "typescript": "^4.2.4"
  },
  "directories": {
    "test": "tests"
  },
  "scripts": {
    "test": "anchor test",
    "deploy": "anchor deploy",
    "migrate": "anchor migrate",
    "upgrade": "anchor upgrade"
  }
}

Here's the error

cli/accounts.ts:7:14 - error TS2339: Property 'features' does not exist on type '{ bs58: BaseConverter; sha256: { (input: string | ArrayBuffer | ArrayBufferView, options?: OptionsHexOutput): Promise<string>; (input: string | ... 1 more ... | ArrayBufferView, options: OptionBufferOutput): Promise<...>; }; getMultipleAccounts: (connection: Connection, publicKeys: PublicKey[]) => Promise<...>; idlA...'.

7 anchor.utils.features.set('anchor-deprecated-state');
               ~~~~~~~~

cli/commands.ts:42:14 - error TS2339: Property 'features' does not exist on type '{ bs58: BaseConverter; sha256: { (input: string | ArrayBuffer | ArrayBufferView, options?: OptionsHexOutput): Promise<string>; (input: string | ... 1 more ... | ArrayBufferView, options: OptionBufferOutput): Promise<...>; }; getMultipleAccounts: (connection: Connection, publicKeys: PublicKey[]) => Promise<...>; idlA...'.

42 anchor.utils.features.set('anchor-deprecated-state');
                ~~~~~~~~

cli/commands.ts:1872:7 - error TS2345: Argument of type '{ filters: { dataSize: number; }[]; }' is not assignable to parameter of type 'Commitment'.
  Type '{ filters: { dataSize: number; }[]; }' is not assignable to type '"max"'.

1872       {filters: [{dataSize: 56}]},
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~

cli/index.ts:38:14 - error TS2339: Property 'features' does not exist on type '{ bs58: BaseConverter; sha256: { (input: string | ArrayBuffer | ArrayBufferView, options?: OptionsHexOutput): Promise<string>; (input: string | ... 1 more ... | ArrayBufferView, options: OptionBufferOutput): Promise<...>; }; getMultipleAccounts: (connection: Connection, publicKeys: PublicKey[]) => Promise<...>; idlA...'.

38 anchor.utils.features.set('anchor-deprecated-state');
                ~~~~~~~~

cli/utils.ts:57:14 - error TS2339: Property 'features' does not exist on type '{ bs58: BaseConverter; sha256: { (input: string | ArrayBuffer | ArrayBufferView, options?: OptionsHexOutput): Promise<string>; (input: string | ... 1 more ... | ArrayBufferView, options: OptionBufferOutput): Promise<...>; }; getMultipleAccounts: (connection: Connection, publicKeys: PublicKey[]) => Promise<...>; idlA...'.

57 anchor.utils.features.set('anchor-deprecated-state');
                ~~~~~~~~


Found 5 errors.

I'm not sure. Try wiping your node modules and re-installing?

@bonedaddy
Copy link
Contributor

Looks like im running into issues pinning the dependency to git as the typescript and javascript client code is in a subfolder which doesnt appear to be supported by npm/yarn via gfit deps

@armaniferrante armaniferrante merged commit 6ad68ed into master Jul 2, 2021
@armaniferrante armaniferrante deleted the armani/dep branch July 2, 2021 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature flag old state account address calculation
2 participants