소스 검색

ts: Add SPL Anchor packages (#2143)

acheron 3 년 전
부모
커밋
5a025b949e
100개의 변경된 파일553개의 추가작업 그리고 99개의 파일을 삭제
  1. 1 1
      .github/actions/setup-ts/action.yaml
  2. 3 3
      .github/workflows/no-cashing-tests.yaml
  3. 3 3
      .github/workflows/tests.yaml
  4. 1 0
      .gitignore
  5. 1 0
      CHANGELOG.md
  6. 1 1
      examples/tutorial/package.json
  7. 1 1
      examples/tutorial/yarn.lock
  8. 1 1
      tests/auction-house
  9. 1 1
      tests/package.json
  10. 2 2
      tests/yarn.lock
  11. 9 0
      ts/build-packages.sh
  12. 5 84
      ts/package.json
  13. 0 0
      ts/packages/anchor/README.md
  14. 0 0
      ts/packages/anchor/jest.config.js
  15. 87 0
      ts/packages/anchor/package.json
  16. 0 0
      ts/packages/anchor/rollup.config.ts
  17. 0 0
      ts/packages/anchor/src/coder/borsh/accounts.ts
  18. 0 0
      ts/packages/anchor/src/coder/borsh/event.ts
  19. 0 0
      ts/packages/anchor/src/coder/borsh/idl.ts
  20. 0 0
      ts/packages/anchor/src/coder/borsh/index.ts
  21. 0 0
      ts/packages/anchor/src/coder/borsh/instruction.ts
  22. 0 0
      ts/packages/anchor/src/coder/borsh/state.ts
  23. 0 0
      ts/packages/anchor/src/coder/borsh/types.ts
  24. 0 0
      ts/packages/anchor/src/coder/common.ts
  25. 0 0
      ts/packages/anchor/src/coder/index.ts
  26. 0 0
      ts/packages/anchor/src/coder/spl-associated-token/accounts.ts
  27. 0 0
      ts/packages/anchor/src/coder/spl-associated-token/events.ts
  28. 0 0
      ts/packages/anchor/src/coder/spl-associated-token/index.ts
  29. 0 0
      ts/packages/anchor/src/coder/spl-associated-token/instruction.ts
  30. 0 0
      ts/packages/anchor/src/coder/spl-associated-token/state.ts
  31. 0 0
      ts/packages/anchor/src/coder/spl-associated-token/types.ts
  32. 0 0
      ts/packages/anchor/src/coder/spl-token/accounts.ts
  33. 0 0
      ts/packages/anchor/src/coder/spl-token/buffer-layout.ts
  34. 0 0
      ts/packages/anchor/src/coder/spl-token/events.ts
  35. 0 0
      ts/packages/anchor/src/coder/spl-token/index.ts
  36. 0 0
      ts/packages/anchor/src/coder/spl-token/instruction.ts
  37. 0 0
      ts/packages/anchor/src/coder/spl-token/state.ts
  38. 0 0
      ts/packages/anchor/src/coder/spl-token/types.ts
  39. 0 0
      ts/packages/anchor/src/coder/system/accounts.ts
  40. 0 0
      ts/packages/anchor/src/coder/system/events.ts
  41. 0 0
      ts/packages/anchor/src/coder/system/index.ts
  42. 0 0
      ts/packages/anchor/src/coder/system/instruction.ts
  43. 0 0
      ts/packages/anchor/src/coder/system/state.ts
  44. 0 0
      ts/packages/anchor/src/coder/system/types.ts
  45. 0 0
      ts/packages/anchor/src/error.ts
  46. 0 0
      ts/packages/anchor/src/idl.ts
  47. 0 0
      ts/packages/anchor/src/index.ts
  48. 0 0
      ts/packages/anchor/src/native/index.ts
  49. 0 0
      ts/packages/anchor/src/native/system.ts
  50. 0 0
      ts/packages/anchor/src/nodewallet.ts
  51. 0 0
      ts/packages/anchor/src/program/accounts-resolver.ts
  52. 0 0
      ts/packages/anchor/src/program/common.ts
  53. 0 0
      ts/packages/anchor/src/program/context.ts
  54. 0 0
      ts/packages/anchor/src/program/event.ts
  55. 0 0
      ts/packages/anchor/src/program/index.ts
  56. 0 0
      ts/packages/anchor/src/program/namespace/account.ts
  57. 0 0
      ts/packages/anchor/src/program/namespace/index.ts
  58. 0 0
      ts/packages/anchor/src/program/namespace/instruction.ts
  59. 0 0
      ts/packages/anchor/src/program/namespace/methods.ts
  60. 0 0
      ts/packages/anchor/src/program/namespace/rpc.ts
  61. 0 0
      ts/packages/anchor/src/program/namespace/simulate.ts
  62. 0 0
      ts/packages/anchor/src/program/namespace/state.ts
  63. 0 0
      ts/packages/anchor/src/program/namespace/transaction.ts
  64. 0 0
      ts/packages/anchor/src/program/namespace/types.ts
  65. 0 0
      ts/packages/anchor/src/program/namespace/views.ts
  66. 0 0
      ts/packages/anchor/src/provider.ts
  67. 0 0
      ts/packages/anchor/src/spl/associated-token.ts
  68. 0 0
      ts/packages/anchor/src/spl/index.ts
  69. 0 0
      ts/packages/anchor/src/spl/token.ts
  70. 0 0
      ts/packages/anchor/src/utils/bytes/base64.ts
  71. 0 0
      ts/packages/anchor/src/utils/bytes/bs58.ts
  72. 0 0
      ts/packages/anchor/src/utils/bytes/hex.ts
  73. 0 0
      ts/packages/anchor/src/utils/bytes/index.ts
  74. 0 0
      ts/packages/anchor/src/utils/bytes/utf8.ts
  75. 0 0
      ts/packages/anchor/src/utils/common.ts
  76. 0 0
      ts/packages/anchor/src/utils/features.ts
  77. 0 0
      ts/packages/anchor/src/utils/index.ts
  78. 0 0
      ts/packages/anchor/src/utils/pubkey.ts
  79. 0 0
      ts/packages/anchor/src/utils/registry.ts
  80. 0 0
      ts/packages/anchor/src/utils/rpc.ts
  81. 0 0
      ts/packages/anchor/src/utils/sha256.ts
  82. 0 0
      ts/packages/anchor/src/utils/token.ts
  83. 0 0
      ts/packages/anchor/src/workspace.ts
  84. 0 0
      ts/packages/anchor/tests/coder-types.spec.ts
  85. 0 0
      ts/packages/anchor/tests/error.spec.ts
  86. 0 0
      ts/packages/anchor/tests/events.spec.ts
  87. 0 0
      ts/packages/anchor/tests/program-common.spec.ts
  88. 0 0
      ts/packages/anchor/tests/transaction.spec.ts
  89. 2 2
      ts/packages/anchor/tsconfig.base.json
  90. 0 0
      ts/packages/anchor/tsconfig.cjs.json
  91. 0 0
      ts/packages/anchor/tsconfig.json
  92. 0 0
      ts/packages/anchor/types/buffer-layout/index.d.ts
  93. 126 0
      ts/packages/spl-associated-token-account/idl.json
  94. 46 0
      ts/packages/spl-associated-token-account/package.json
  95. 68 0
      ts/packages/spl-associated-token-account/program/lib.rs
  96. 54 0
      ts/packages/spl-associated-token-account/rollup.config.ts
  97. 49 0
      ts/packages/spl-associated-token-account/src/coder/accounts.ts
  98. 12 0
      ts/packages/spl-associated-token-account/src/coder/events.ts
  99. 26 0
      ts/packages/spl-associated-token-account/src/coder/index.ts
  100. 54 0
      ts/packages/spl-associated-token-account/src/coder/instructions.ts

+ 1 - 1
.github/actions/setup-ts/action.yaml

@@ -20,7 +20,7 @@ runs:
           path: |
             ./ts/dist/
           key: solana-${{ runner.os }}-v0000-${{ env.NODE_VERSION }}-${{ hashFiles('./ts/**/*.ts') }}  
-      - run: cd ts && yarn --frozen-lockfile && yarn build:node && yarn link && cd ../
+      - run: cd ts/packages/anchor && yarn --frozen-lockfile && yarn build:node && yarn link && cd ../../../
         shell: bash
       - run: cd examples/tutorial && yarn link @project-serum/anchor && yarn --frozen-lockfile && cd ../../
         shell: bash

+ 3 - 3
.github/workflows/no-cashing-tests.yaml

@@ -25,9 +25,9 @@ jobs:
       - run: cargo test
       # using singlethreaded testing for avm so that tests that change files do not conflict with each other
       - run: cd avm && cargo fmt -- --check && cargo clippy --all-targets -- -D warnings && cargo test -- --test-threads=1
-      - run: cd ts && yarn --frozen-lockfile
-      - run: cd ts && yarn test
-      - run: cd ts && yarn lint
+      - run: cd ts/packages/anchor && yarn --frozen-lockfile
+      - run: cd ts/packages/anchor && yarn test
+      - run: cd ts/packages/anchor && yarn lint
       - run: cd examples/tutorial && yarn --frozen-lockfile
       - run: cd examples/tutorial && yarn lint
       - run: cd tests && yarn --frozen-lockfile

+ 3 - 3
.github/workflows/tests.yaml

@@ -39,9 +39,9 @@ jobs:
       - run: cargo test
       # using singlethreaded testing for avm so that tests that change files do not conflict with each other
       - run: cd avm && cargo fmt -- --check && cargo clippy --all-targets -- -D warnings && cargo test -- --test-threads=1
-      - run: cd ts && yarn --frozen-lockfile
-      - run: cd ts && yarn test
-      - run: cd ts && yarn lint
+      - run: cd ts/packages/anchor && yarn --frozen-lockfile
+      - run: cd ts/packages/anchor && yarn test
+      - run: cd ts/packages/anchor && yarn lint
       - run: cd examples/tutorial && yarn --frozen-lockfile
       - run: cd examples/tutorial && yarn lint
       - run: cd tests && yarn --frozen-lockfile

+ 1 - 0
.gitignore

@@ -21,3 +21,4 @@ cli/npm-package/anchor
 cli/npm-package/*.tgz
 docker-target
 .rollup.cache/
+test-keypair.json

+ 1 - 0
CHANGELOG.md

@@ -16,6 +16,7 @@ The minor version will be incremented upon a breaking change and the patch versi
 * spl: Add `create_metadata_accounts_v3` and `set_collection_size` wrappers ([#2119](https://github.com/coral-xyz/anchor/pull/2119))
 * spl: Add `MetadataAccount` account deserialization. ([#2014](https://github.com/coral-xyz/anchor/pull/2014)).
 * lang: Add parsing for consts from impl blocks for IDL PDA seeds generation ([#2128](https://github.com/coral-xyz/anchor/pull/2014))
+* ts: Add coders for SPL programs ([#2143](https://github.com/coral-xyz/anchor/pull/2143)).
 
 ### Fixes
 

+ 1 - 1
examples/tutorial/package.json

@@ -13,7 +13,7 @@
     "basic-4"
   ],
   "dependencies": {
-    "@project-serum/anchor": "file:../../ts"
+    "@project-serum/anchor": "file:../../ts/packages/anchor"
   },
   "devDependencies": {
     "mocha": "^9.1.3",

+ 1 - 1
examples/tutorial/yarn.lock

@@ -30,7 +30,7 @@
     "@ethersproject/logger" "^5.5.0"
     hash.js "1.1.7"
 
-"@project-serum/anchor@file:../../ts":
+"@project-serum/anchor@file:../../ts/packages/anchor":
   version "0.25.0"
   dependencies:
     "@project-serum/borsh" "^0.2.5"

+ 1 - 1
tests/auction-house

@@ -1 +1 @@
-Subproject commit 9b0c81e5972f2466d47c20f705fc5fd1ca16476c
+Subproject commit 45518c16f00c68509e06432925403046f2b64463

+ 1 - 1
tests/package.json

@@ -39,7 +39,7 @@
     "bpf-upgradeable-state"
   ],
   "dependencies": {
-    "@project-serum/anchor": "file:../ts",
+    "@project-serum/anchor": "file:../ts/packages/anchor",
     "@project-serum/common": "^0.0.1-beta.3",
     "@project-serum/serum": "^0.13.60",
     "@solana/spl-token": "^0.1.8"

+ 2 - 2
tests/yarn.lock

@@ -50,8 +50,8 @@
     snake-case "^3.0.4"
     toml "^3.0.0"
 
-"@project-serum/anchor@file:../ts":
-  version "0.24.2"
+"@project-serum/anchor@file:../ts/packages/anchor":
+  version "0.25.0"
   dependencies:
     "@project-serum/borsh" "^0.2.5"
     "@solana/web3.js" "^1.36.0"

+ 9 - 0
ts/build-packages.sh

@@ -0,0 +1,9 @@
+cd packages;
+for D in */;
+    do if [ "$D" = "anchor/" ]; then
+        cd $D && yarn && yarn build; cd ..;
+    else
+        cd $D && yarn init:yarn; cd ..;
+    fi
+done
+

+ 5 - 84
ts/package.json

@@ -1,87 +1,8 @@
 {
-  "name": "@project-serum/anchor",
-  "version": "0.25.0",
-  "description": "Anchor client",
-  "module": "./dist/esm/index.js",
-  "main": "./dist/cjs/index.js",
-  "browser": "./dist/browser/index.js",
-  "license": "(MIT OR Apache-2.0)",
-  "types": "dist/cjs/index.d.ts",
-  "homepage": "https://github.com/coral-xyz/anchor#readme",
-  "bugs": {
-    "url": "https://github.com/coral-xyz/anchor/issues"
-  },
-  "repository": {
-    "type": "git",
-    "url": "https://github.com/coral-xyz/anchor.git"
-  },
-  "publishConfig": {
-    "access": "public"
-  },
-  "engines": {
-    "node": ">=11"
-  },
-  "scripts": {
-    "build": "rimraf dist/ && yarn build:node && yarn build:browser",
-    "build:node": "tsc && tsc -p tsconfig.cjs.json",
-    "build:browser": "rollup --config",
-    "lint:fix": "prettier src/** tests/** -w",
-    "lint": "prettier src/** tests/** --check",
-    "watch": "tsc -p tsconfig.cjs.json --watch",
-    "prepublishOnly": "yarn build",
-    "docs": "typedoc --excludePrivate --includeVersion --out ../docs/src/.vuepress/dist/ts/ --readme none src/index.ts",
-    "test": "jest tests --detectOpenHandles"
-  },
-  "dependencies": {
-    "@project-serum/borsh": "^0.2.5",
-    "@solana/web3.js": "^1.36.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",
-    "js-sha256": "^0.9.0",
-    "pako": "^2.0.3",
-    "snake-case": "^3.0.4",
-    "superstruct": "^0.15.4",
-    "toml": "^3.0.0"
-  },
-  "devDependencies": {
-    "@commitlint/cli": "^11.0.0",
-    "@commitlint/config-conventional": "^11.0.0",
-    "@rollup/plugin-commonjs": "^21.0.1",
-    "@rollup/plugin-node-resolve": "^13.0.6",
-    "@rollup/plugin-replace": "^3.0.0",
-    "@rollup/plugin-typescript": "^8.3.0",
-    "@types/bn.js": "^4.11.6",
-    "@types/bs58": "^4.0.1",
-    "@types/crypto-hash": "^1.1.2",
-    "@types/jest": "^27.4.1",
-    "@types/pako": "^1.0.1",
-    "@typescript-eslint/eslint-plugin": "^4.6.0",
-    "@typescript-eslint/parser": "^4.6.0",
-    "eslint": "^7.12.1",
-    "eslint-config-prettier": "^6.15.0",
-    "husky": "^4.3.0",
-    "jest": "27.3.1",
-    "jest-config": "27.3.1",
-    "lint-staged": "^10.5.0",
-    "prettier": "^2.1.2",
-    "rimraf": "^3.0.2",
-    "rollup": "^2.60.2",
-    "rollup-plugin-terser": "^7.0.2",
-    "ts-jest": "^27.0.7",
-    "ts-jest-resolver": "^2.0.0",
-    "ts-node": "^9.0.0",
-    "tslib": "^2.3.1",
-    "typedoc": "^0.22.10",
-    "typescript": "^4.5.2"
-  },
-  "files": [
-    "dist",
-    "types"
+  "name": "@project-serum/monorepo",
+  "private": true,
+  "workspaces": [
+    "packages/*",
+    "tests"
   ]
 }

+ 0 - 0
ts/README.md → ts/packages/anchor/README.md


+ 0 - 0
ts/jest.config.js → ts/packages/anchor/jest.config.js


+ 87 - 0
ts/packages/anchor/package.json

@@ -0,0 +1,87 @@
+{
+  "name": "@project-serum/anchor",
+  "version": "0.25.0",
+  "description": "Anchor client",
+  "module": "./dist/esm/index.js",
+  "main": "./dist/cjs/index.js",
+  "browser": "./dist/browser/index.js",
+  "license": "(MIT OR Apache-2.0)",
+  "types": "dist/cjs/index.d.ts",
+  "homepage": "https://github.com/coral-xyz/anchor#readme",
+  "bugs": {
+    "url": "https://github.com/coral-xyz/anchor/issues"
+  },
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/coral-xyz/anchor.git"
+  },
+  "publishConfig": {
+    "access": "public"
+  },
+  "engines": {
+    "node": ">=11"
+  },
+  "scripts": {
+    "build": "rimraf dist/ && yarn build:node && yarn build:browser",
+    "build:node": "tsc && tsc -p tsconfig.cjs.json",
+    "build:browser": "rollup --config",
+    "lint:fix": "prettier src/** tests/** -w",
+    "lint": "prettier src/** tests/** --check",
+    "watch": "tsc -p tsconfig.cjs.json --watch",
+    "prepublishOnly": "yarn build",
+    "docs": "typedoc --excludePrivate --includeVersion --out ../docs/src/.vuepress/dist/ts/ --readme none src/index.ts",
+    "test": "jest tests --detectOpenHandles"
+  },
+  "dependencies": {
+    "@project-serum/borsh": "^0.2.5",
+    "@solana/web3.js": "^1.36.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",
+    "js-sha256": "^0.9.0",
+    "pako": "^2.0.3",
+    "snake-case": "^3.0.4",
+    "superstruct": "^0.15.4",
+    "toml": "^3.0.0"
+  },
+  "devDependencies": {
+    "@commitlint/cli": "^11.0.0",
+    "@commitlint/config-conventional": "^11.0.0",
+    "@rollup/plugin-commonjs": "^21.0.1",
+    "@rollup/plugin-node-resolve": "^13.0.6",
+    "@rollup/plugin-replace": "^3.0.0",
+    "@rollup/plugin-typescript": "^8.3.0",
+    "@types/bn.js": "^4.11.6",
+    "@types/bs58": "^4.0.1",
+    "@types/crypto-hash": "^1.1.2",
+    "@types/jest": "^27.4.1",
+    "@types/pako": "^1.0.1",
+    "@typescript-eslint/eslint-plugin": "^4.6.0",
+    "@typescript-eslint/parser": "^4.6.0",
+    "eslint": "^7.12.1",
+    "eslint-config-prettier": "^6.15.0",
+    "husky": "^4.3.0",
+    "jest": "27.3.1",
+    "jest-config": "27.3.1",
+    "lint-staged": "^10.5.0",
+    "prettier": "^2.1.2",
+    "rimraf": "^3.0.2",
+    "rollup": "^2.60.2",
+    "rollup-plugin-terser": "^7.0.2",
+    "ts-jest": "^27.0.7",
+    "ts-jest-resolver": "^2.0.0",
+    "ts-node": "^9.0.0",
+    "tslib": "^2.3.1",
+    "typedoc": "^0.22.10",
+    "typescript": "^4.5.2"
+  },
+  "files": [
+    "dist",
+    "types"
+  ]
+}

+ 0 - 0
ts/rollup.config.ts → ts/packages/anchor/rollup.config.ts


+ 0 - 0
ts/src/coder/borsh/accounts.ts → ts/packages/anchor/src/coder/borsh/accounts.ts


+ 0 - 0
ts/src/coder/borsh/event.ts → ts/packages/anchor/src/coder/borsh/event.ts


+ 0 - 0
ts/src/coder/borsh/idl.ts → ts/packages/anchor/src/coder/borsh/idl.ts


+ 0 - 0
ts/src/coder/borsh/index.ts → ts/packages/anchor/src/coder/borsh/index.ts


+ 0 - 0
ts/src/coder/borsh/instruction.ts → ts/packages/anchor/src/coder/borsh/instruction.ts


+ 0 - 0
ts/src/coder/borsh/state.ts → ts/packages/anchor/src/coder/borsh/state.ts


+ 0 - 0
ts/src/coder/borsh/types.ts → ts/packages/anchor/src/coder/borsh/types.ts


+ 0 - 0
ts/src/coder/common.ts → ts/packages/anchor/src/coder/common.ts


+ 0 - 0
ts/src/coder/index.ts → ts/packages/anchor/src/coder/index.ts


+ 0 - 0
ts/src/coder/spl-associated-token/accounts.ts → ts/packages/anchor/src/coder/spl-associated-token/accounts.ts


+ 0 - 0
ts/src/coder/spl-associated-token/events.ts → ts/packages/anchor/src/coder/spl-associated-token/events.ts


+ 0 - 0
ts/src/coder/spl-associated-token/index.ts → ts/packages/anchor/src/coder/spl-associated-token/index.ts


+ 0 - 0
ts/src/coder/spl-associated-token/instruction.ts → ts/packages/anchor/src/coder/spl-associated-token/instruction.ts


+ 0 - 0
ts/src/coder/spl-associated-token/state.ts → ts/packages/anchor/src/coder/spl-associated-token/state.ts


+ 0 - 0
ts/src/coder/spl-associated-token/types.ts → ts/packages/anchor/src/coder/spl-associated-token/types.ts


+ 0 - 0
ts/src/coder/spl-token/accounts.ts → ts/packages/anchor/src/coder/spl-token/accounts.ts


+ 0 - 0
ts/src/coder/spl-token/buffer-layout.ts → ts/packages/anchor/src/coder/spl-token/buffer-layout.ts


+ 0 - 0
ts/src/coder/spl-token/events.ts → ts/packages/anchor/src/coder/spl-token/events.ts


+ 0 - 0
ts/src/coder/spl-token/index.ts → ts/packages/anchor/src/coder/spl-token/index.ts


+ 0 - 0
ts/src/coder/spl-token/instruction.ts → ts/packages/anchor/src/coder/spl-token/instruction.ts


+ 0 - 0
ts/src/coder/spl-token/state.ts → ts/packages/anchor/src/coder/spl-token/state.ts


+ 0 - 0
ts/src/coder/spl-token/types.ts → ts/packages/anchor/src/coder/spl-token/types.ts


+ 0 - 0
ts/src/coder/system/accounts.ts → ts/packages/anchor/src/coder/system/accounts.ts


+ 0 - 0
ts/src/coder/system/events.ts → ts/packages/anchor/src/coder/system/events.ts


+ 0 - 0
ts/src/coder/system/index.ts → ts/packages/anchor/src/coder/system/index.ts


+ 0 - 0
ts/src/coder/system/instruction.ts → ts/packages/anchor/src/coder/system/instruction.ts


+ 0 - 0
ts/src/coder/system/state.ts → ts/packages/anchor/src/coder/system/state.ts


+ 0 - 0
ts/src/coder/system/types.ts → ts/packages/anchor/src/coder/system/types.ts


+ 0 - 0
ts/src/error.ts → ts/packages/anchor/src/error.ts


+ 0 - 0
ts/src/idl.ts → ts/packages/anchor/src/idl.ts


+ 0 - 0
ts/src/index.ts → ts/packages/anchor/src/index.ts


+ 0 - 0
ts/src/native/index.ts → ts/packages/anchor/src/native/index.ts


+ 0 - 0
ts/src/native/system.ts → ts/packages/anchor/src/native/system.ts


+ 0 - 0
ts/src/nodewallet.ts → ts/packages/anchor/src/nodewallet.ts


+ 0 - 0
ts/src/program/accounts-resolver.ts → ts/packages/anchor/src/program/accounts-resolver.ts


+ 0 - 0
ts/src/program/common.ts → ts/packages/anchor/src/program/common.ts


+ 0 - 0
ts/src/program/context.ts → ts/packages/anchor/src/program/context.ts


+ 0 - 0
ts/src/program/event.ts → ts/packages/anchor/src/program/event.ts


+ 0 - 0
ts/src/program/index.ts → ts/packages/anchor/src/program/index.ts


+ 0 - 0
ts/src/program/namespace/account.ts → ts/packages/anchor/src/program/namespace/account.ts


+ 0 - 0
ts/src/program/namespace/index.ts → ts/packages/anchor/src/program/namespace/index.ts


+ 0 - 0
ts/src/program/namespace/instruction.ts → ts/packages/anchor/src/program/namespace/instruction.ts


+ 0 - 0
ts/src/program/namespace/methods.ts → ts/packages/anchor/src/program/namespace/methods.ts


+ 0 - 0
ts/src/program/namespace/rpc.ts → ts/packages/anchor/src/program/namespace/rpc.ts


+ 0 - 0
ts/src/program/namespace/simulate.ts → ts/packages/anchor/src/program/namespace/simulate.ts


+ 0 - 0
ts/src/program/namespace/state.ts → ts/packages/anchor/src/program/namespace/state.ts


+ 0 - 0
ts/src/program/namespace/transaction.ts → ts/packages/anchor/src/program/namespace/transaction.ts


+ 0 - 0
ts/src/program/namespace/types.ts → ts/packages/anchor/src/program/namespace/types.ts


+ 0 - 0
ts/src/program/namespace/views.ts → ts/packages/anchor/src/program/namespace/views.ts


+ 0 - 0
ts/src/provider.ts → ts/packages/anchor/src/provider.ts


+ 0 - 0
ts/src/spl/associated-token.ts → ts/packages/anchor/src/spl/associated-token.ts


+ 0 - 0
ts/src/spl/index.ts → ts/packages/anchor/src/spl/index.ts


+ 0 - 0
ts/src/spl/token.ts → ts/packages/anchor/src/spl/token.ts


+ 0 - 0
ts/src/utils/bytes/base64.ts → ts/packages/anchor/src/utils/bytes/base64.ts


+ 0 - 0
ts/src/utils/bytes/bs58.ts → ts/packages/anchor/src/utils/bytes/bs58.ts


+ 0 - 0
ts/src/utils/bytes/hex.ts → ts/packages/anchor/src/utils/bytes/hex.ts


+ 0 - 0
ts/src/utils/bytes/index.ts → ts/packages/anchor/src/utils/bytes/index.ts


+ 0 - 0
ts/src/utils/bytes/utf8.ts → ts/packages/anchor/src/utils/bytes/utf8.ts


+ 0 - 0
ts/src/utils/common.ts → ts/packages/anchor/src/utils/common.ts


+ 0 - 0
ts/src/utils/features.ts → ts/packages/anchor/src/utils/features.ts


+ 0 - 0
ts/src/utils/index.ts → ts/packages/anchor/src/utils/index.ts


+ 0 - 0
ts/src/utils/pubkey.ts → ts/packages/anchor/src/utils/pubkey.ts


+ 0 - 0
ts/src/utils/registry.ts → ts/packages/anchor/src/utils/registry.ts


+ 0 - 0
ts/src/utils/rpc.ts → ts/packages/anchor/src/utils/rpc.ts


+ 0 - 0
ts/src/utils/sha256.ts → ts/packages/anchor/src/utils/sha256.ts


+ 0 - 0
ts/src/utils/token.ts → ts/packages/anchor/src/utils/token.ts


+ 0 - 0
ts/src/workspace.ts → ts/packages/anchor/src/workspace.ts


+ 0 - 0
ts/tests/coder-types.spec.ts → ts/packages/anchor/tests/coder-types.spec.ts


+ 0 - 0
ts/tests/error.spec.ts → ts/packages/anchor/tests/error.spec.ts


+ 0 - 0
ts/tests/events.spec.ts → ts/packages/anchor/tests/events.spec.ts


+ 0 - 0
ts/tests/program-common.spec.ts → ts/packages/anchor/tests/program-common.spec.ts


+ 0 - 0
ts/tests/transaction.spec.ts → ts/packages/anchor/tests/transaction.spec.ts


+ 2 - 2
ts/tsconfig.base.json → ts/packages/anchor/tsconfig.base.json

@@ -17,11 +17,11 @@
     "baseUrl": ".",
     "typeRoots": [
       "types/",
-      "node_modules/@types"
+      "../../node_modules/@types"
     ],
     "paths": {
       "@solana/web3.js": [
-        "./node_modules/@solana/web3.js/lib"
+        "../../node_modules/@solana/web3.js/lib"
       ]
     }
   }

+ 0 - 0
ts/tsconfig.cjs.json → ts/packages/anchor/tsconfig.cjs.json


+ 0 - 0
ts/tsconfig.json → ts/packages/anchor/tsconfig.json


+ 0 - 0
ts/types/buffer-layout/index.d.ts → ts/packages/anchor/types/buffer-layout/index.d.ts


+ 126 - 0
ts/packages/spl-associated-token-account/idl.json

@@ -0,0 +1,126 @@
+{
+  "version": "1.1.1",
+  "name": "spl_associated_token_account",
+  "instructions": [
+    {
+      "name": "create",
+      "accounts": [
+        {
+          "name": "fundingAddress",
+          "isMut": true,
+          "isSigner": true
+        },
+        {
+          "name": "associatedAccountAddress",
+          "isMut": true,
+          "isSigner": false
+        },
+        {
+          "name": "walletAddress",
+          "isMut": false,
+          "isSigner": false
+        },
+        {
+          "name": "tokenMintAddress",
+          "isMut": false,
+          "isSigner": false
+        },
+        {
+          "name": "systemProgram",
+          "isMut": false,
+          "isSigner": false
+        },
+        {
+          "name": "tokenProgram",
+          "isMut": false,
+          "isSigner": false
+        }
+      ],
+      "args": []
+    },
+    {
+      "name": "createIdempotent",
+      "accounts": [
+        {
+          "name": "fundingAddress",
+          "isMut": true,
+          "isSigner": true
+        },
+        {
+          "name": "associatedAccountAddress",
+          "isMut": true,
+          "isSigner": false
+        },
+        {
+          "name": "walletAddress",
+          "isMut": false,
+          "isSigner": false
+        },
+        {
+          "name": "tokenMintAddress",
+          "isMut": false,
+          "isSigner": false
+        },
+        {
+          "name": "systemProgram",
+          "isMut": false,
+          "isSigner": false
+        },
+        {
+          "name": "tokenProgram",
+          "isMut": false,
+          "isSigner": false
+        }
+      ],
+      "args": []
+    },
+    {
+      "name": "recoverNested",
+      "accounts": [
+        {
+          "name": "nestedAssociatedAccountAddress",
+          "isMut": true,
+          "isSigner": false
+        },
+        {
+          "name": "nestedTokenMintAddress",
+          "isMut": false,
+          "isSigner": false
+        },
+        {
+          "name": "destinationAssociatedAccountAddress",
+          "isMut": true,
+          "isSigner": false
+        },
+        {
+          "name": "ownerAssociatedAccountAddress",
+          "isMut": false,
+          "isSigner": false
+        },
+        {
+          "name": "ownerTokenMintAddress",
+          "isMut": false,
+          "isSigner": false
+        },
+        {
+          "name": "walletAddress",
+          "isMut": true,
+          "isSigner": true
+        },
+        {
+          "name": "tokenProgram",
+          "isMut": false,
+          "isSigner": false
+        }
+      ],
+      "args": []
+    }
+  ],
+  "errors": [
+    {
+      "code": 0,
+      "name": "InvalidOwner",
+      "msg": "Associated token account owner does not match address derivation"
+    }
+  ]
+}

+ 46 - 0
ts/packages/spl-associated-token-account/package.json

@@ -0,0 +1,46 @@
+{
+  "name": "@project-serum/spl-associated-token-account",
+  "description": "Anchor client for Solana Program Library Associated Token Account",
+  "version": "1.1.1",
+  "author": "acheron <acheroncrypto@gmail.com>",
+  "license": "Apache-2.0",
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/coral-xyz/anchor.git"
+  },
+  "files": [
+    "dist"
+  ],
+  "module": "./dist/esm/index.js",
+  "main": "./dist/cjs/index.js",
+  "browser": "./dist/browser/index.js",
+  "types": "./dist/cjs/index.d.ts",
+  "scripts": {
+    "init:yarn": "yarn && yarn lint:fix && yarn build:yarn",
+    "init:npm": "npm i && npm run lint:fix && npm run build:npm",
+    "build:yarn": "rimraf dist/ && yarn build:node && yarn build:browser",
+    "build:npm": "rimraf dist/ && npm run build:node && npm run build:browser",
+    "build:node": "tsc && tsc -p tsconfig.cjs.json",
+    "build:browser": "rollup --config",
+    "lint:fix": "prettier src/** -w",
+    "lint": "prettier src/** --check",
+    "watch": "tsc -p tsconfig.cjs.json --watch"
+  },
+  "dependencies": {
+    "@project-serum/anchor": "=0.25.0",
+    "@native-to-anchor/buffer-layout": "=0.1.0"
+  },
+  "devDependencies": {
+    "@rollup/plugin-commonjs": "=21.0.2",
+    "@rollup/plugin-node-resolve": "=13.1.3",
+    "@rollup/plugin-replace": "=3.1.0",
+    "@rollup/plugin-typescript": "=8.3.1",
+    "@types/node": "=17.0.21",
+    "prettier": "=2.7.1",
+    "rimraf": "=3.0.2",
+    "rollup": "=2.70.1",
+    "rollup-plugin-terser": "=7.0.2",
+    "tslib": "=2.3.1",
+    "typescript": "=4.6.2"
+  }
+}

+ 68 - 0
ts/packages/spl-associated-token-account/program/lib.rs

@@ -0,0 +1,68 @@
+// This file is autogenerated with https://github.com/acheroncrypto/native-to-anchor
+
+use anchor_lang::prelude::*;
+
+declare_id!("11111111111111111111111111111111");
+
+#[program]
+pub mod spl_associated_token_account {
+    use super::*;
+
+    pub fn create(ctx: Context<Create>) -> Result<()> {
+        Ok(())
+    }
+
+    pub fn create_idempotent(ctx: Context<CreateIdempotent>) -> Result<()> {
+        Ok(())
+    }
+
+    pub fn recover_nested(ctx: Context<RecoverNested>) -> Result<()> {
+        Ok(())
+    }
+}
+
+#[derive(Accounts)]
+pub struct Create<'info> {
+    #[account(mut)]
+    funding_address: Signer<'info>,
+    #[account(mut)]
+    associated_account_address: AccountInfo<'info>,
+    wallet_address: AccountInfo<'info>,
+    token_mint_address: AccountInfo<'info>,
+    system_program: Program<'info, System>,
+    token_program: Program<'info, Token>,
+}
+
+#[derive(Accounts)]
+pub struct CreateIdempotent<'info> {
+    #[account(mut)]
+    funding_address: Signer<'info>,
+    #[account(mut)]
+    associated_account_address: AccountInfo<'info>,
+    wallet_address: AccountInfo<'info>,
+    token_mint_address: AccountInfo<'info>,
+    system_program: Program<'info, System>,
+    token_program: Program<'info, Token>,
+}
+
+#[derive(Accounts)]
+pub struct RecoverNested<'info> {
+    #[account(mut)]
+    nested_associated_account_address: AccountInfo<'info>,
+    nested_token_mint_address: AccountInfo<'info>,
+    #[account(mut)]
+    destination_associated_account_address: AccountInfo<'info>,
+    owner_associated_account_address: AccountInfo<'info>,
+    owner_token_mint_address: AccountInfo<'info>,
+    #[account(mut)]
+    wallet_address: Signer<'info>,
+    token_program: Program<'info, Token>,
+}
+
+#[error_code]
+pub enum AssociatedTokenAccountError {
+    // 0
+    /// Associated token account owner does not match address derivation
+    #[msg("Associated token account owner does not match address derivation")]
+    InvalidOwner,
+}

+ 54 - 0
ts/packages/spl-associated-token-account/rollup.config.ts

@@ -0,0 +1,54 @@
+import nodeResolve from "@rollup/plugin-node-resolve";
+import typescript from "@rollup/plugin-typescript";
+import replace from "@rollup/plugin-replace";
+import commonjs from "@rollup/plugin-commonjs";
+import { terser } from "rollup-plugin-terser";
+
+const env = process.env.NODE_ENV;
+
+export default {
+  input: "src/index.ts",
+  plugins: [
+    commonjs(),
+    nodeResolve({
+      browser: true,
+      extensions: [".js", ".ts"],
+      dedupe: ["bn.js", "buffer"],
+      preferBuiltins: false,
+    }),
+    typescript({
+      tsconfig: "./tsconfig.base.json",
+      moduleResolution: "node",
+      outDir: "types",
+      target: "es2019",
+      outputToFilesystem: false,
+    }),
+    replace({
+      preventAssignment: true,
+      values: {
+        "process.env.NODE_ENV": JSON.stringify(env),
+        "process.env.ANCHOR_BROWSER": JSON.stringify(true),
+      },
+    }),
+    terser(),
+  ],
+  external: [
+    "@project-serum/borsh",
+    "@solana/web3.js",
+    "assert",
+    "base64-js",
+    "bn.js",
+    "bs58",
+    "buffer",
+    "camelcase",
+    "eventemitter3",
+    "js-sha256",
+    "pako",
+    "toml",
+  ],
+  output: {
+    file: "dist/browser/index.js",
+    format: "es",
+    sourcemap: true,
+  },
+};

+ 49 - 0
ts/packages/spl-associated-token-account/src/coder/accounts.ts

@@ -0,0 +1,49 @@
+// @ts-nocheck
+import * as B from "@native-to-anchor/buffer-layout";
+import { AccountsCoder, Idl } from "@project-serum/anchor";
+import { IdlTypeDef } from "@project-serum/anchor/dist/cjs/idl";
+
+export class SplAssociatedTokenAccountAccountsCoder<A extends string = string>
+  implements AccountsCoder
+{
+  constructor(_idl: Idl) {}
+
+  public async encode<T = any>(accountName: A, account: T): Promise<Buffer> {
+    switch (accountName) {
+      default: {
+        throw new Error(`Invalid account name: ${accountName}`);
+      }
+    }
+  }
+
+  public decode<T = any>(accountName: A, ix: Buffer): T {
+    return this.decodeUnchecked(accountName, ix);
+  }
+
+  public decodeUnchecked<T = any>(accountName: A, ix: Buffer): T {
+    switch (accountName) {
+      default: {
+        throw new Error(`Invalid account name: ${accountName}`);
+      }
+    }
+  }
+
+  public memcmp(
+    accountName: A,
+    _appendData?: Buffer
+  ): { dataSize?: number; offset?: number; bytes?: string } {
+    switch (accountName) {
+      default: {
+        throw new Error(`Invalid account name: ${accountName}`);
+      }
+    }
+  }
+
+  public size(idlAccount: IdlTypeDef): number {
+    switch (idlAccount.name) {
+      default: {
+        throw new Error(`Invalid account name: ${idlAccount.name}`);
+      }
+    }
+  }
+}

+ 12 - 0
ts/packages/spl-associated-token-account/src/coder/events.ts

@@ -0,0 +1,12 @@
+import { Idl, Event, EventCoder } from "@project-serum/anchor";
+import { IdlEvent } from "@project-serum/anchor/dist/cjs/idl";
+
+export class SplAssociatedTokenAccountEventsCoder implements EventCoder {
+  constructor(_idl: Idl) {}
+
+  decode<E extends IdlEvent = IdlEvent, T = Record<string, string>>(
+    _log: string
+  ): Event<E, T> | null {
+    throw new Error("SplAssociatedTokenAccount program does not have events");
+  }
+}

+ 26 - 0
ts/packages/spl-associated-token-account/src/coder/index.ts

@@ -0,0 +1,26 @@
+import { Idl, Coder } from "@project-serum/anchor";
+
+import { SplAssociatedTokenAccountAccountsCoder } from "./accounts";
+import { SplAssociatedTokenAccountEventsCoder } from "./events";
+import { SplAssociatedTokenAccountInstructionCoder } from "./instructions";
+import { SplAssociatedTokenAccountStateCoder } from "./state";
+import { SplAssociatedTokenAccountTypesCoder } from "./types";
+
+/**
+ * Coder for SplAssociatedTokenAccount
+ */
+export class SplAssociatedTokenAccountCoder implements Coder {
+  readonly accounts: SplAssociatedTokenAccountAccountsCoder;
+  readonly events: SplAssociatedTokenAccountEventsCoder;
+  readonly instruction: SplAssociatedTokenAccountInstructionCoder;
+  readonly state: SplAssociatedTokenAccountStateCoder;
+  readonly types: SplAssociatedTokenAccountTypesCoder;
+
+  constructor(idl: Idl) {
+    this.accounts = new SplAssociatedTokenAccountAccountsCoder(idl);
+    this.events = new SplAssociatedTokenAccountEventsCoder(idl);
+    this.instruction = new SplAssociatedTokenAccountInstructionCoder(idl);
+    this.state = new SplAssociatedTokenAccountStateCoder(idl);
+    this.types = new SplAssociatedTokenAccountTypesCoder(idl);
+  }
+}

+ 54 - 0
ts/packages/spl-associated-token-account/src/coder/instructions.ts

@@ -0,0 +1,54 @@
+// @ts-nocheck
+import * as B from "@native-to-anchor/buffer-layout";
+import { Idl, InstructionCoder } from "@project-serum/anchor";
+
+export class SplAssociatedTokenAccountInstructionCoder
+  implements InstructionCoder
+{
+  constructor(_idl: Idl) {}
+
+  encode(ixName: string, ix: any): Buffer {
+    switch (ixName) {
+      case "create": {
+        return encodeCreate(ix);
+      }
+      case "createIdempotent": {
+        return encodeCreateIdempotent(ix);
+      }
+      case "recoverNested": {
+        return encodeRecoverNested(ix);
+      }
+
+      default: {
+        throw new Error(`Invalid instruction: ${ixName}`);
+      }
+    }
+  }
+
+  encodeState(_ixName: string, _ix: any): Buffer {
+    throw new Error("SplAssociatedTokenAccount does not have state");
+  }
+}
+
+function encodeCreate({}: any): Buffer {
+  return encodeData({ create: {} }, 1);
+}
+
+function encodeCreateIdempotent({}: any): Buffer {
+  return encodeData({ createIdempotent: {} }, 1);
+}
+
+function encodeRecoverNested({}: any): Buffer {
+  return encodeData({ recoverNested: {} }, 1);
+}
+
+const LAYOUT = B.union(B.u8("instruction"));
+LAYOUT.addVariant(0, B.struct([]), "create");
+LAYOUT.addVariant(1, B.struct([]), "createIdempotent");
+LAYOUT.addVariant(2, B.struct([]), "recoverNested");
+
+function encodeData(ix: any, span: number): Buffer {
+  const b = Buffer.alloc(span);
+  LAYOUT.encode(ix, b);
+  return b;
+}

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.