Skip to content

Commit

Permalink
Upgrade to Anchor 0.21.0 (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
macalinao committed Feb 14, 2022
1 parent 7cd35e4 commit 79d8e70
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -13,7 +13,7 @@
"@babel/core": "^7.17.2",
"@babel/preset-env": "^7.16.11",
"@babel/preset-typescript": "^7.16.7",
"@project-serum/anchor": "^0.20.1",
"@project-serum/anchor": "^0.21.0",
"@rushstack/eslint-patch": "^1.1.0",
"@saberhq/eslint-config": "*",
"@saberhq/eslint-config-react": "*",
Expand Down
4 changes: 2 additions & 2 deletions packages/anchor-contrib/package.json
Expand Up @@ -17,12 +17,12 @@
"prepublishOnly": "npm run build"
},
"peerDependencies": {
"@project-serum/anchor": "^0.17 || ^0.18 || ^0.19 || ^0.20",
"@project-serum/anchor": "^0.21",
"@solana/web3.js": ">=1.29.2",
"bn.js": "^4 || ^5"
},
"devDependencies": {
"@project-serum/anchor": "^0.20.1",
"@project-serum/anchor": "^0.21.0",
"@solana/web3.js": "^1.34.0",
"@types/lodash.camelcase": "^4.3.6",
"@types/lodash.mapvalues": "^4.6.6",
Expand Down
6 changes: 3 additions & 3 deletions packages/anchor-contrib/src/generateAccountParsers.ts
@@ -1,5 +1,5 @@
import type { Idl } from "@project-serum/anchor";
import { AccountsCoder } from "@project-serum/anchor";
import type { AccountsCoder, Idl } from "@project-serum/anchor";
import { BorshAccountsCoder } from "@project-serum/anchor";
import camelCase from "lodash.camelcase";

/**
Expand All @@ -19,7 +19,7 @@ export type AccountParsers<M> = {
export const generateAccountParsers = <M extends Record<string, object>>(
idl: Idl
): AccountParsers<M> => {
const coder = new AccountsCoder(idl);
const coder = new BorshAccountsCoder(idl);
return generateAccountParsersFromCoder(
idl.accounts?.map((a) => a.name),
coder
Expand Down
12 changes: 6 additions & 6 deletions packages/anchor-contrib/src/utils/coder.ts
@@ -1,11 +1,11 @@
import type { Accounts, Idl } from "@project-serum/anchor";
import {
AccountsCoder,
Coder,
BorshAccountsCoder,
BorshCoder,
EventParser,
utils,
} from "@project-serum/anchor";
import type { InstructionDisplay } from "@project-serum/anchor/dist/cjs/coder/instruction";
import type { InstructionDisplay } from "@project-serum/anchor/dist/cjs/coder/borsh/instruction";
import type { IdlAccountItem } from "@project-serum/anchor/dist/cjs/idl";
import InstructionNamespaceFactory from "@project-serum/anchor/dist/cjs/program/namespace/instruction";
import type { Provider as SaberProvider } from "@saberhq/solana-contrib";
Expand Down Expand Up @@ -50,7 +50,7 @@ export class SuperCoder<T extends CoderAnchorTypes> {
/**
* Underlying Coder.
*/
readonly coder: Coder;
readonly coder: BorshCoder;
/**
* Parses events.
*/
Expand Down Expand Up @@ -91,7 +91,7 @@ export class SuperCoder<T extends CoderAnchorTypes> {
*/
readonly idl: T["IDL"]
) {
this.coder = new Coder(idl);
this.coder = new BorshCoder(idl);
this.eventParser = new EventParser(address, this.coder);
this.accountParsers = generateAccountParsersFromCoder(
idl.accounts?.map((acc) => acc.name),
Expand All @@ -102,7 +102,7 @@ export class SuperCoder<T extends CoderAnchorTypes> {
const discriminatorList =
idl.accounts?.map((account) => ({
name: account.name,
discriminator: AccountsCoder.accountDiscriminator(account.name),
discriminator: BorshAccountsCoder.accountDiscriminator(account.name),
})) ?? [];
this.discriminators = discriminatorList.reduce(
(acc, el) => ({ ...acc, [el.discriminator.toString("hex")]: el.name }),
Expand Down
2 changes: 1 addition & 1 deletion packages/chai-solana/package.json
Expand Up @@ -47,7 +47,7 @@
"jsbi": "*"
},
"devDependencies": {
"@project-serum/anchor": "^0.20.1",
"@project-serum/anchor": "^0.21.0",
"@solana/web3.js": "^1.34.0",
"bn.js": "^5.2.0",
"jsbi": "^4.1.0"
Expand Down
74 changes: 61 additions & 13 deletions yarn.lock
Expand Up @@ -3272,37 +3272,38 @@ __metadata:
languageName: node
linkType: hard

"@project-serum/anchor@npm:^0.20.1":
version: 0.20.1
resolution: "@project-serum/anchor@npm:0.20.1"
"@project-serum/anchor@npm:^0.21.0":
version: 0.21.0
resolution: "@project-serum/anchor@npm:0.21.0"
dependencies:
"@project-serum/borsh": ^0.2.2
"@project-serum/borsh": ^0.2.4
"@solana/web3.js": ^1.17.0
base64-js: ^1.5.1
bn.js: ^5.1.2
bs58: ^4.0.1
buffer-layout: ^1.2.2
camelcase: ^5.3.1
cross-fetch: ^3.1.5
crypto-hash: ^1.3.0
eventemitter3: ^4.0.7
find: ^0.3.0
js-sha256: ^0.9.0
pako: ^2.0.3
snake-case: ^3.0.4
toml: ^3.0.0
checksum: b5468690df330d72e4cc5461faf3afd43c0383da004d8dda46ba11dbb092c1c754a694e8dd3d9094617040417d38ec1cb486113cfeb4465ce8ff3f184202238f
checksum: f7071ada1920c1e9c3e7c0e58c578e299f5de54d7de192977fdc83002a1089d8193ef6391eeca991575276a487367ae215587fd1638043fb9b996ceae12b4073
languageName: node
linkType: hard

"@project-serum/borsh@npm:^0.2.2":
version: 0.2.2
resolution: "@project-serum/borsh@npm:0.2.2"
"@project-serum/borsh@npm:^0.2.4":
version: 0.2.4
resolution: "@project-serum/borsh@npm:0.2.4"
dependencies:
bn.js: ^5.1.2
buffer-layout: ^1.2.0
peerDependencies:
"@solana/web3.js": ^1.2.0
checksum: f6ffd5f21cad0cb8a84901dcf21342af73a4b48e2121ba9fd3e1f84b400e66eacb3a7e80ae350a0592f728dea99604c50084ab1455ddf4f3a9d28c8a38bbc188
checksum: b93af9668e489ee676ac052492ba0fd7b6246fa9d75d73306b0afa0a7939aefc6e847d75e2b06bcc94f8961cba9e4870a231046f6215fd59470f6bc1c220321c
languageName: node
linkType: hard

Expand Down Expand Up @@ -3341,7 +3342,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@saberhq/anchor-contrib@workspace:packages/anchor-contrib"
dependencies:
"@project-serum/anchor": ^0.20.1
"@project-serum/anchor": ^0.21.0
"@saberhq/solana-contrib": ^1.12.43
"@solana/web3.js": ^1.34.0
"@types/lodash.camelcase": ^4.3.6
Expand All @@ -3352,7 +3353,7 @@ __metadata:
lodash.mapvalues: ^4.6.0
tslib: ^2.3.1
peerDependencies:
"@project-serum/anchor": ^0.17 || ^0.18 || ^0.19 || ^0.20
"@project-serum/anchor": ^0.21
"@solana/web3.js": ">=1.29.2"
bn.js: ^4 || ^5
languageName: unknown
Expand All @@ -3362,7 +3363,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@saberhq/chai-solana@workspace:packages/chai-solana"
dependencies:
"@project-serum/anchor": ^0.20.1
"@project-serum/anchor": ^0.21.0
"@saberhq/anchor-contrib": ^1.12.43
"@saberhq/solana-contrib": ^1.12.43
"@saberhq/token-utils": ^1.12.43
Expand Down Expand Up @@ -3423,7 +3424,7 @@ __metadata:
"@babel/core": ^7.17.2
"@babel/preset-env": ^7.16.11
"@babel/preset-typescript": ^7.16.7
"@project-serum/anchor": ^0.20.1
"@project-serum/anchor": ^0.21.0
"@rushstack/eslint-patch": ^1.1.0
"@saberhq/eslint-config": "*"
"@saberhq/eslint-config-react": "*"
Expand Down Expand Up @@ -6765,6 +6766,15 @@ __metadata:
languageName: node
linkType: hard

"cross-fetch@npm:^3.1.5":
version: 3.1.5
resolution: "cross-fetch@npm:3.1.5"
dependencies:
node-fetch: 2.6.7
checksum: f6b8c6ee3ef993ace6277fd789c71b6acf1b504fd5f5c7128df4ef2f125a429e29cd62dc8c127523f04a5f2fa4771ed80e3f3d9695617f441425045f505cf3bb
languageName: node
linkType: hard

"cross-spawn@npm:7.0.3, cross-spawn@npm:^7.0.2, cross-spawn@npm:^7.0.3":
version: 7.0.3
resolution: "cross-spawn@npm:7.0.3"
Expand Down Expand Up @@ -11080,6 +11090,20 @@ __metadata:
languageName: node
linkType: hard

"node-fetch@npm:2.6.7":
version: 2.6.7
resolution: "node-fetch@npm:2.6.7"
dependencies:
whatwg-url: ^5.0.0
peerDependencies:
encoding: ^0.1.0
peerDependenciesMeta:
encoding:
optional: true
checksum: 8d816ffd1ee22cab8301c7756ef04f3437f18dace86a1dae22cf81db8ef29c0bf6655f3215cb0cdb22b420b6fe141e64b26905e7f33f9377a7fa59135ea3e10b
languageName: node
linkType: hard

"node-gyp-build@npm:^4.2.0":
version: 4.2.3
resolution: "node-gyp-build@npm:4.2.3"
Expand Down Expand Up @@ -13863,6 +13887,13 @@ resolve@^2.0.0-next.3:
languageName: node
linkType: hard

"tr46@npm:~0.0.3":
version: 0.0.3
resolution: "tr46@npm:0.0.3"
checksum: 726321c5eaf41b5002e17ffbd1fb7245999a073e8979085dacd47c4b4e8068ff5777142fc6726d6ca1fd2ff16921b48788b87225cbc57c72636f6efa8efbffe3
languageName: node
linkType: hard

"traverse-chain@npm:~0.1.0":
version: 0.1.0
resolution: "traverse-chain@npm:0.1.0"
Expand Down Expand Up @@ -14443,6 +14474,13 @@ resolve@^2.0.0-next.3:
languageName: node
linkType: hard

"webidl-conversions@npm:^3.0.0":
version: 3.0.1
resolution: "webidl-conversions@npm:3.0.1"
checksum: c92a0a6ab95314bde9c32e1d0a6dfac83b578f8fa5f21e675bc2706ed6981bc26b7eb7e6a1fab158e5ce4adf9caa4a0aee49a52505d4d13c7be545f15021b17c
languageName: node
linkType: hard

"webidl-conversions@npm:^5.0.0":
version: 5.0.0
resolution: "webidl-conversions@npm:5.0.0"
Expand Down Expand Up @@ -14517,6 +14555,16 @@ resolve@^2.0.0-next.3:
languageName: node
linkType: hard

"whatwg-url@npm:^5.0.0":
version: 5.0.0
resolution: "whatwg-url@npm:5.0.0"
dependencies:
tr46: ~0.0.3
webidl-conversions: ^3.0.0
checksum: b8daed4ad3356cc4899048a15b2c143a9aed0dfae1f611ebd55073310c7b910f522ad75d727346ad64203d7e6c79ef25eafd465f4d12775ca44b90fa82ed9e2c
languageName: node
linkType: hard

"whatwg-url@npm:^8.0.0, whatwg-url@npm:^8.5.0":
version: 8.7.0
resolution: "whatwg-url@npm:8.7.0"
Expand Down

0 comments on commit 79d8e70

Please sign in to comment.