From 045cfee27aa9c80d42d2a6cc75b8ae22fc118521 Mon Sep 17 00:00:00 2001 From: Pavel Strakhov Date: Tue, 11 Jun 2024 18:19:33 +0100 Subject: [PATCH] feat(target_chains/starknet): add SDK usage example (#1682) --- pnpm-lock.yaml | 378 ++++++++++++++++-- target_chains/starknet/sdk/js/package.json | 6 +- .../starknet/sdk/js/src/examples/usage.ts | 114 ++++++ 3 files changed, 457 insertions(+), 41 deletions(-) create mode 100644 target_chains/starknet/sdk/js/src/examples/usage.ts diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2019bf3888..3cdc414830 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1438,6 +1438,9 @@ importers: target_chains/starknet/sdk/js: devDependencies: + '@pythnetwork/price-service-client': + specifier: ^1.9.0 + version: link:../../../../price_service/client/js '@types/node': specifier: ^18.11.18 version: 18.19.34 @@ -1452,13 +1455,19 @@ importers: version: 8.56.0 jest: specifier: ^29.4.1 - version: 29.7.0(@types/node@18.19.34) + version: 29.7.0(@types/node@18.19.34)(ts-node@10.9.2) prettier: specifier: ^2.6.2 version: 2.8.8 + starknet: + specifier: ^6.9.0 + version: 6.9.0 ts-jest: specifier: ^29.0.5 version: 29.1.2(@babel/core@7.24.7)(jest@29.7.0)(typescript@4.9.5) + ts-node: + specifier: ^10.9.2 + version: 10.9.2(@types/node@18.19.34)(typescript@4.9.5) typescript: specifier: ^4.6.3 version: 4.9.5 @@ -6435,6 +6444,49 @@ packages: - ts-node dev: true + /@jest/core@29.7.0: + resolution: {integrity: sha512-n7aeXWKMnGtDA48y8TLWJPJmLmmZ642Ceo78cYWEpiD7FzDgmNDV/GCVRorPABdXLJZ/9wzzgZAlHjXjxDHGsg==} + engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} + peerDependencies: + node-notifier: ^8.0.1 || ^9.0.0 || ^10.0.0 + peerDependenciesMeta: + node-notifier: + optional: true + dependencies: + '@jest/console': 29.7.0 + '@jest/reporters': 29.7.0 + '@jest/test-result': 29.7.0 + '@jest/transform': 29.7.0 + '@jest/types': 29.6.3 + '@types/node': 20.14.2 + ansi-escapes: 4.3.2 + chalk: 4.1.2 + ci-info: 3.9.0 + exit: 0.1.2 + graceful-fs: 4.2.10 + jest-changed-files: 29.7.0 + jest-config: 29.7.0(@types/node@20.14.2)(ts-node@10.9.1) + jest-haste-map: 29.7.0 + jest-message-util: 29.7.0 + jest-regex-util: 29.6.3 + jest-resolve: 29.7.0 + jest-resolve-dependencies: 29.7.0 + jest-runner: 29.7.0 + jest-runtime: 29.7.0 + jest-snapshot: 29.7.0 + jest-util: 29.7.0 + jest-validate: 29.7.0 + jest-watcher: 29.7.0 + micromatch: 4.0.5 + pretty-format: 29.7.0 + slash: 3.0.0 + strip-ansi: 6.0.1 + transitivePeerDependencies: + - babel-plugin-macros + - supports-color + - ts-node + dev: true + /@jest/core@29.7.0(ts-node@10.9.1): resolution: {integrity: sha512-n7aeXWKMnGtDA48y8TLWJPJmLmmZ642Ceo78cYWEpiD7FzDgmNDV/GCVRorPABdXLJZ/9wzzgZAlHjXjxDHGsg==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -6478,6 +6530,49 @@ packages: - ts-node dev: true + /@jest/core@29.7.0(ts-node@10.9.2): + resolution: {integrity: sha512-n7aeXWKMnGtDA48y8TLWJPJmLmmZ642Ceo78cYWEpiD7FzDgmNDV/GCVRorPABdXLJZ/9wzzgZAlHjXjxDHGsg==} + engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} + peerDependencies: + node-notifier: ^8.0.1 || ^9.0.0 || ^10.0.0 + peerDependenciesMeta: + node-notifier: + optional: true + dependencies: + '@jest/console': 29.7.0 + '@jest/reporters': 29.7.0 + '@jest/test-result': 29.7.0 + '@jest/transform': 29.7.0 + '@jest/types': 29.6.3 + '@types/node': 20.14.2 + ansi-escapes: 4.3.2 + chalk: 4.1.2 + ci-info: 3.9.0 + exit: 0.1.2 + graceful-fs: 4.2.10 + jest-changed-files: 29.7.0 + jest-config: 29.7.0(@types/node@20.14.2)(ts-node@10.9.2) + jest-haste-map: 29.7.0 + jest-message-util: 29.7.0 + jest-regex-util: 29.6.3 + jest-resolve: 29.7.0 + jest-resolve-dependencies: 29.7.0 + jest-runner: 29.7.0 + jest-runtime: 29.7.0 + jest-snapshot: 29.7.0 + jest-util: 29.7.0 + jest-validate: 29.7.0 + jest-watcher: 29.7.0 + micromatch: 4.0.5 + pretty-format: 29.7.0 + slash: 3.0.0 + strip-ansi: 6.0.1 + transitivePeerDependencies: + - babel-plugin-macros + - supports-color + - ts-node + dev: true + /@jest/create-cache-key-function@29.7.0: resolution: {integrity: sha512-4QqS3LY5PBmTRHj9sAg1HLoPzqAI0uOX6wI/TRqHIcOxlFidy6YEmCQJk6FSZjNLGCeubDMfmkWL+qaLKhSGQA==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -8004,7 +8099,7 @@ packages: glob: 7.2.3 path-equal: 1.2.5 safe-stable-stringify: 2.4.2 - ts-node: 10.9.1(@types/node@16.18.60)(typescript@4.9.4) + ts-node: 10.9.2(@types/node@16.18.60)(typescript@4.9.4) typescript: 4.9.4 yargs: 17.7.2 transitivePeerDependencies: @@ -8352,13 +8447,11 @@ packages: resolution: {integrity: sha512-t01iSXPuN+Eqzb4eBX0S5oubSqXbK/xXa1Ne18Hj8f9pStxztHCE2gfboSp/dZRLSqfuLpRK2nDXDK+W9puocA==} dependencies: '@noble/hashes': 1.3.3 - dev: false /@noble/curves@1.4.0: resolution: {integrity: sha512-p+4cb332SFCrReJkCYe8Xzm0OWi4Jji5jVdIZRL/PmacmDkFNw6MrrV+gGpiPxLHbV+zKFRywUWbaseT+tZRXg==} dependencies: '@noble/hashes': 1.4.0 - dev: false /@noble/ed25519@1.7.3: resolution: {integrity: sha512-iR8GBkDt0Q3GyaVcIu7mSsVIqnFbkbRzGLWlvhwunacoLwt4J3swfKhfaM6rN6WY+TBGoYT1GtT1mIh2/jGbRQ==} @@ -8382,12 +8475,10 @@ packages: /@noble/hashes@1.3.3: resolution: {integrity: sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==} engines: {node: '>= 16'} - dev: false /@noble/hashes@1.4.0: resolution: {integrity: sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg==} engines: {node: '>= 16'} - dev: false /@noble/secp256k1@1.6.3: resolution: {integrity: sha512-T04e4iTurVy7I8Sw4+c5OSN9/RkPlo1uKxAomtxQNLq8j1uPAqnsqG1bqvY3Jv7c13gyr6dui0zmh/I3+f/JaQ==} @@ -10139,6 +10230,13 @@ packages: '@scure/base': 1.1.6 dev: false + /@scure/starknet@1.0.0: + resolution: {integrity: sha512-o5J57zY0f+2IL/mq8+AYJJ4Xpc1fOtDhr+mFQKbHnYFmm3WQrC+8zj2HEgxak1a+x86mhmBC1Kq305KUpVf0wg==} + dependencies: + '@noble/curves': 1.3.0 + '@noble/hashes': 1.3.3 + dev: true + /@sentry/core@5.30.0: resolution: {integrity: sha512-TmfrII8w1PQZSZgPpUESqjB+jC6MvZJZdLtE/0hZ+SrnKhW3x5WlYLvTXZpcWePYBku7rl2wn1RZu6uT0qCTeg==} engines: {node: '>=6'} @@ -13909,6 +14007,16 @@ packages: resolution: {integrity: sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==} dev: true + /abi-wan-kanabi@2.2.2: + resolution: {integrity: sha512-sTCv2HyNIj1x2WFUoc9oL8ZT9liosrL+GoqEGZJK1kDND096CfA7lwx06vLxLWMocQ41FQXO3oliwoh/UZHYdQ==} + hasBin: true + dependencies: + ansicolors: 0.3.2 + cardinal: 2.1.1 + fs-extra: 10.1.0 + yargs: 17.7.2 + dev: true + /abitype@0.7.1(typescript@5.4.5): resolution: {integrity: sha512-VBkRHTDZf9Myaek/dO3yMmOzB/y2s3Zo6nVU7yaw1G+TvCHAjwaJzNGN9yo4K5D8bU/VZXKP1EJpRhFr862PlQ==} peerDependencies: @@ -14294,6 +14402,10 @@ packages: resolution: {integrity: sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==} engines: {node: '>=12'} + /ansicolors@0.3.2: + resolution: {integrity: sha512-QXu7BPrP29VllRxH8GwB7x5iX5qWKAAMLqKQGWTeLWVlNHNOpVMJ91dsxQAIWXpjuW5wqvxu3Jd/nRjrJ+0pqg==} + dev: true + /antlr4ts@0.5.0-alpha.4: resolution: {integrity: sha512-WPQDt1B74OfPv/IMS2ekXAKkTZIHl88uMetg6q3OTqgFxZ/dxDXI0EWLyZid/1Pe6hTftyg5N7gel5wNAGxXyQ==} dev: true @@ -15783,6 +15895,14 @@ packages: resolution: {integrity: sha512-rsJZYVCgXd08sPqwmaIqjAd5SUTfonV0z/gDJ8D6cN8wQphky1kkAYEqQ+hmDxTw7UihvBfjUVUSY+DBEe44jg==} dev: false + /cardinal@2.1.1: + resolution: {integrity: sha512-JSr5eOgoEymtYHBjNWyjrMqet9Am2miJhlfKNdqLp6zoeAh0KN5dRAcxlecj5mAJrmQomgiOBj35xHLrFjqBpw==} + hasBin: true + dependencies: + ansicolors: 0.3.2 + redeyed: 2.1.1 + dev: true + /caseless@0.12.0: resolution: {integrity: sha512-4tYFyifaFfGacoiObjJegolkwSU4xQNGbVgUiNYVUxbQ2x2lUsFvY4hVgVzGiIe6WLOPqycWXA40l+PWsxthUw==} @@ -16667,6 +16787,25 @@ packages: safe-buffer: 5.2.1 sha.js: 2.4.11 + /create-jest@29.7.0: + resolution: {integrity: sha512-Adz2bdH0Vq3F53KEMJOoftQFutWCukm6J24wbPWRO4k1kMY7gS7ds/uoJkNuV8wDCtWWnuwGcJwpWcih+zEW1Q==} + engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} + hasBin: true + dependencies: + '@jest/types': 29.6.3 + chalk: 4.1.2 + exit: 0.1.2 + graceful-fs: 4.2.11 + jest-config: 29.7.0(@types/node@18.19.34)(ts-node@10.9.2) + jest-util: 29.7.0 + prompts: 2.4.2 + transitivePeerDependencies: + - '@types/node' + - babel-plugin-macros + - supports-color + - ts-node + dev: true + /create-jest@29.7.0(@types/node@16.18.60): resolution: {integrity: sha512-Adz2bdH0Vq3F53KEMJOoftQFutWCukm6J24wbPWRO4k1kMY7gS7ds/uoJkNuV8wDCtWWnuwGcJwpWcih+zEW1Q==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -16705,7 +16844,26 @@ packages: - ts-node dev: true - /create-jest@29.7.0(@types/node@18.19.34): + /create-jest@29.7.0(@types/node@18.19.34)(ts-node@10.9.2): + resolution: {integrity: sha512-Adz2bdH0Vq3F53KEMJOoftQFutWCukm6J24wbPWRO4k1kMY7gS7ds/uoJkNuV8wDCtWWnuwGcJwpWcih+zEW1Q==} + engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} + hasBin: true + dependencies: + '@jest/types': 29.6.3 + chalk: 4.1.2 + exit: 0.1.2 + graceful-fs: 4.2.11 + jest-config: 29.7.0(@types/node@18.19.34)(ts-node@10.9.2) + jest-util: 29.7.0 + prompts: 2.4.2 + transitivePeerDependencies: + - '@types/node' + - babel-plugin-macros + - supports-color + - ts-node + dev: true + + /create-jest@29.7.0(@types/node@20.14.2): resolution: {integrity: sha512-Adz2bdH0Vq3F53KEMJOoftQFutWCukm6J24wbPWRO4k1kMY7gS7ds/uoJkNuV8wDCtWWnuwGcJwpWcih+zEW1Q==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} hasBin: true @@ -16714,7 +16872,7 @@ packages: chalk: 4.1.2 exit: 0.1.2 graceful-fs: 4.2.11 - jest-config: 29.7.0(@types/node@18.19.34) + jest-config: 29.7.0(@types/node@20.14.2)(ts-node@10.9.1) jest-util: 29.7.0 prompts: 2.4.2 transitivePeerDependencies: @@ -18940,6 +19098,13 @@ packages: dev: true optional: true + /fetch-cookie@3.0.1: + resolution: {integrity: sha512-ZGXe8Y5Z/1FWqQ9q/CrJhkUD73DyBU9VF0hBQmEO/wPHe4A9PKTjplFDLeFX8aOsYypZUcX5Ji/eByn3VCVO3Q==} + dependencies: + set-cookie-parser: 2.6.0 + tough-cookie: 4.1.2 + dev: true + /figures@3.2.0: resolution: {integrity: sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg==} engines: {node: '>=8'} @@ -19400,6 +19565,12 @@ packages: resolution: {integrity: sha512-Y8aiXLq4leR7807UY0yuKEwif5s3kbVp1nTv+i4jBeoUzByTLKkLWu/HorS6/pB+7gsB0o7OTogC8AoOOeT0Hw==} dev: false + /get-starknet-core@4.0.0-next.5: + resolution: {integrity: sha512-zZ3i4E5UYF1f04fgkwfaVC0uj1pvdBlzsDqXEAfb4jc1WO4zM7rIm4XAUqdMwVSr4CBend5RM7U+zv166fBNYg==} + dependencies: + starknet-types: 0.7.2 + dev: true + /get-stream@5.2.0: resolution: {integrity: sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==} engines: {node: '>=8'} @@ -20741,6 +20912,15 @@ packages: resolution: {integrity: sha512-WhB9zCku7EGTj/HQQRz5aUQEUeoQZH2bWcltRErOpymJ4boYE6wL9Tbr23krRPSZ+C5zqNSrSw+Cc7sZZ4b7vg==} engines: {node: '>=0.10.0'} + /isomorphic-fetch@3.0.0: + resolution: {integrity: sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==} + dependencies: + node-fetch: 2.7.0 + whatwg-fetch: 3.6.20 + transitivePeerDependencies: + - encoding + dev: true + /isomorphic-unfetch@3.1.0: resolution: {integrity: sha512-geDJjpoZ8N0kWexiwkX8F9NkTsXhetLPVbZFQ+JTW239QNOwvB0gniuR1Wc6f0AMTn7/mFGyXvHTifrCp/GH8Q==} dependencies: @@ -21085,14 +21265,14 @@ packages: node-notifier: optional: true dependencies: - '@jest/core': 29.7.0(ts-node@10.9.1) + '@jest/core': 29.7.0 '@jest/test-result': 29.7.0 '@jest/types': 29.6.3 chalk: 4.1.2 - create-jest: 29.7.0(@types/node@20.14.2)(ts-node@10.9.1) + create-jest: 29.7.0 exit: 0.1.2 import-local: 3.1.0 - jest-config: 29.7.0(@types/node@20.14.2)(ts-node@10.9.1) + jest-config: 29.7.0(@types/node@18.19.34)(ts-node@10.9.2) jest-util: 29.7.0 jest-validate: 29.7.0 yargs: 17.7.2 @@ -21113,7 +21293,7 @@ packages: node-notifier: optional: true dependencies: - '@jest/core': 29.7.0(ts-node@10.9.1) + '@jest/core': 29.7.0 '@jest/test-result': 29.7.0 '@jest/types': 29.6.3 chalk: 4.1.2 @@ -21141,7 +21321,7 @@ packages: node-notifier: optional: true dependencies: - '@jest/core': 29.7.0(ts-node@10.9.1) + '@jest/core': 29.7.0 '@jest/test-result': 29.7.0 '@jest/types': 29.6.3 chalk: 4.1.2 @@ -21159,7 +21339,7 @@ packages: - ts-node dev: true - /jest-cli@29.7.0(@types/node@18.19.34): + /jest-cli@29.7.0(@types/node@18.19.34)(ts-node@10.9.2): resolution: {integrity: sha512-OVVobw2IubN/GSYsxETi+gOe7Ka59EFMR/twOU3Jb2GnKKeMGJB5SGUUrEz3SFVmJASUdZUzy83sLNNQ2gZslg==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} hasBin: true @@ -21169,14 +21349,14 @@ packages: node-notifier: optional: true dependencies: - '@jest/core': 29.7.0(ts-node@10.9.1) + '@jest/core': 29.7.0(ts-node@10.9.2) '@jest/test-result': 29.7.0 '@jest/types': 29.6.3 chalk: 4.1.2 - create-jest: 29.7.0(@types/node@18.19.34) + create-jest: 29.7.0(@types/node@18.19.34)(ts-node@10.9.2) exit: 0.1.2 import-local: 3.1.0 - jest-config: 29.7.0(@types/node@18.19.34) + jest-config: 29.7.0(@types/node@18.19.34)(ts-node@10.9.2) jest-util: 29.7.0 jest-validate: 29.7.0 yargs: 17.7.2 @@ -21197,11 +21377,11 @@ packages: node-notifier: optional: true dependencies: - '@jest/core': 29.7.0(ts-node@10.9.1) + '@jest/core': 29.7.0 '@jest/test-result': 29.7.0 '@jest/types': 29.6.3 chalk: 4.1.2 - create-jest: 29.7.0(@types/node@20.14.2)(ts-node@10.9.1) + create-jest: 29.7.0(@types/node@20.14.2) exit: 0.1.2 import-local: 3.1.0 jest-config: 29.7.0(@types/node@20.14.2)(ts-node@10.9.1) @@ -21403,7 +21583,7 @@ packages: - supports-color dev: true - /jest-config@29.7.0(@types/node@18.19.34): + /jest-config@29.7.0(@types/node@18.19.34)(ts-node@10.9.2): resolution: {integrity: sha512-uXbpfeQ7R6TZBqI3/TxCU4q4ttk3u0PJeC+E0zbfSoSjq6bJ7buBPxzQPL0ifrkY4DNu4JUdk0ImlBUYi840eQ==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} peerDependencies: @@ -21438,6 +21618,7 @@ packages: pretty-format: 29.7.0 slash: 3.0.0 strip-json-comments: 3.1.1 + ts-node: 10.9.2(@types/node@18.19.34)(typescript@4.9.5) transitivePeerDependencies: - babel-plugin-macros - supports-color @@ -21484,6 +21665,47 @@ packages: - supports-color dev: true + /jest-config@29.7.0(@types/node@20.14.2)(ts-node@10.9.2): + resolution: {integrity: sha512-uXbpfeQ7R6TZBqI3/TxCU4q4ttk3u0PJeC+E0zbfSoSjq6bJ7buBPxzQPL0ifrkY4DNu4JUdk0ImlBUYi840eQ==} + engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} + peerDependencies: + '@types/node': '*' + ts-node: '>=9.0.0' + peerDependenciesMeta: + '@types/node': + optional: true + ts-node: + optional: true + dependencies: + '@babel/core': 7.24.7 + '@jest/test-sequencer': 29.7.0 + '@jest/types': 29.6.3 + '@types/node': 20.14.2 + babel-jest: 29.7.0(@babel/core@7.24.7) + chalk: 4.1.2 + ci-info: 3.9.0 + deepmerge: 4.3.1 + glob: 7.2.3 + graceful-fs: 4.2.11 + jest-circus: 29.7.0 + jest-environment-node: 29.7.0 + jest-get-type: 29.6.3 + jest-regex-util: 29.6.3 + jest-resolve: 29.7.0 + jest-runner: 29.7.0 + jest-util: 29.7.0 + jest-validate: 29.7.0 + micromatch: 4.0.7 + parse-json: 5.2.0 + pretty-format: 29.7.0 + slash: 3.0.0 + strip-json-comments: 3.1.1 + ts-node: 10.9.2(@types/node@18.19.34)(typescript@4.9.5) + transitivePeerDependencies: + - babel-plugin-macros + - supports-color + dev: true + /jest-diff@27.5.1: resolution: {integrity: sha512-m0NvkX55LDt9T4mctTEgnZk3fmEg3NRYutvMPWM/0iPnkFj2wIeF45O1718cMSOFO1vINkqmxqD8vE37uTEbqw==} engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} @@ -22430,7 +22652,7 @@ packages: node-notifier: optional: true dependencies: - '@jest/core': 29.7.0(ts-node@10.9.1) + '@jest/core': 29.7.0 '@jest/types': 29.6.3 import-local: 3.1.0 jest-cli: 29.7.0 @@ -22451,7 +22673,7 @@ packages: node-notifier: optional: true dependencies: - '@jest/core': 29.7.0(ts-node@10.9.1) + '@jest/core': 29.7.0 '@jest/types': 29.6.3 import-local: 3.1.0 jest-cli: 29.7.0(@types/node@16.18.60) @@ -22472,7 +22694,7 @@ packages: node-notifier: optional: true dependencies: - '@jest/core': 29.7.0(ts-node@10.9.1) + '@jest/core': 29.7.0 '@jest/types': 29.6.3 import-local: 3.1.0 jest-cli: 29.7.0(@types/node@18.11.18) @@ -22483,7 +22705,7 @@ packages: - ts-node dev: true - /jest@29.7.0(@types/node@18.19.34): + /jest@29.7.0(@types/node@18.19.34)(ts-node@10.9.2): resolution: {integrity: sha512-NIy3oAFp9shda19hy4HK0HRTWKtPJmGdnvywu01nOqNC2vZg+Z+fvJDxpMQA88eb2I9EcafcdjYgsDthnYTvGw==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} hasBin: true @@ -22493,10 +22715,10 @@ packages: node-notifier: optional: true dependencies: - '@jest/core': 29.7.0(ts-node@10.9.1) + '@jest/core': 29.7.0(ts-node@10.9.2) '@jest/types': 29.6.3 import-local: 3.1.0 - jest-cli: 29.7.0(@types/node@18.19.34) + jest-cli: 29.7.0(@types/node@18.19.34)(ts-node@10.9.2) transitivePeerDependencies: - '@types/node' - babel-plugin-macros @@ -22514,7 +22736,7 @@ packages: node-notifier: optional: true dependencies: - '@jest/core': 29.7.0(ts-node@10.9.1) + '@jest/core': 29.7.0 '@jest/types': 29.6.3 import-local: 3.1.0 jest-cli: 29.7.0(@types/node@20.14.2) @@ -23444,6 +23666,10 @@ packages: dependencies: js-tokens: 4.0.0 + /lossless-json@4.0.1: + resolution: {integrity: sha512-l0L+ppmgPDnb+JGxNLndPtJZGNf6+ZmVaQzoxQm3u6TXmhdnsA+YtdVR8DjzZd/em58686CQhOFDPewfJ4l7MA==} + dev: true + /loupe@2.3.6: resolution: {integrity: sha512-RaPMZKiMy8/JruncMU5Bt6na1eftNoo++R4Y+N2FrxkDVTrGvcyzFTsaGif4QTeKESheMGegbhw6iUAq+5A8zA==} deprecated: Please upgrade to 2.3.7 which fixes GHSA-4q6p-r6v2-jvc5 @@ -25482,7 +25708,6 @@ packages: /pako@2.1.0: resolution: {integrity: sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug==} - dev: false /param-case@2.1.1: resolution: {integrity: sha512-eQE845L6ot89sk2N8liD8HAuH4ca6Vvr7VWAWwt7+kvvG5aBcPmmphQ68JsEG2qa9n1TykS2DLeMt363AAH8/w==} @@ -27061,6 +27286,12 @@ packages: strip-indent: 3.0.0 dev: true + /redeyed@2.1.1: + resolution: {integrity: sha512-FNpGGo1DycYAdnrKFxCMmKYgo/mILAqtRYbkdQD8Ep/Hk2PQ5+aEAEx+IU713RTDmuBaH0c8P5ZozurNu5ObRQ==} + dependencies: + esprima: 4.0.1 + dev: true + /redux-saga@1.0.0: resolution: {integrity: sha512-GvJWs/SzMvEQgeaw6sRMXnS2FghlvEGsHiEtTLpJqc/FHF3I5EE/B+Hq5lyHZ8LSoT2r/X/46uWvkdCnK9WgHA==} dependencies: @@ -27724,6 +27955,10 @@ packages: /set-blocking@2.0.0: resolution: {integrity: sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==} + /set-cookie-parser@2.6.0: + resolution: {integrity: sha512-RVnVQxTXuerk653XfuliOxBP81Sf0+qfQE73LIYKcyMYHG94AuH0kgrQpRDuTZnSmjpysHmzxJXKNfa6PjFhyQ==} + dev: true + /set-function-length@1.2.2: resolution: {integrity: sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==} engines: {node: '>= 0.4'} @@ -28214,6 +28449,31 @@ packages: type-fest: 0.7.1 dev: false + /starknet-types@0.7.2: + resolution: {integrity: sha512-r3JJ0rrK0g3FnVRGcFiLY+9YT5WZgxB4TKBfR44wYGevHtKEM6BM5B+Gn1eou1zV7xEAwz3GpmvLSQTUAzDhsw==} + deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. + dev: true + + /starknet@6.9.0: + resolution: {integrity: sha512-8860J7sGUr5UO/BDl3pjCZNUs/vgUM75wVoI93iOYLbTGF0f6MvFZsMOd73tsPKjEcG8V5BTSx6I7seDhQ9osw==} + dependencies: + '@noble/curves': 1.4.0 + '@noble/hashes': 1.4.0 + '@scure/base': 1.1.6 + '@scure/starknet': 1.0.0 + abi-wan-kanabi: 2.2.2 + fetch-cookie: 3.0.1 + get-starknet-core: 4.0.0-next.5 + isomorphic-fetch: 3.0.0 + lossless-json: 4.0.1 + pako: 2.1.0 + starknet-types-07: /starknet-types@0.7.2 + ts-mixer: 6.0.4 + url-join: 4.0.1 + transitivePeerDependencies: + - encoding + dev: true + /statuses@1.5.0: resolution: {integrity: sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==} engines: {node: '>= 0.6'} @@ -29186,6 +29446,10 @@ packages: resolution: {integrity: sha512-PGcnJoTBnVGy6yYNFxWVNkdcAuAMstvutN9MgDJIV6L0oG8fB+ZNNy1T+wJzah8RPGor1mZuPQkVfXNDpy9eHA==} dev: false + /ts-mixer@6.0.4: + resolution: {integrity: sha512-ufKpbmrugz5Aou4wcr5Wc1UUFWOLhq+Fm6qa6P0w0K5Qw2yhaUoiWszhCVuNQyNwrlGiscHOmqYoAox1PtvgjA==} + dev: true + /ts-mocha@10.0.0(mocha@9.2.2): resolution: {integrity: sha512-VRfgDO+iiuJFlNB18tzOfypJ21xn2xbuZyDvJvqpTbWgkAgD17ONGr8t+Tl8rcBtOBdjXp5e/Rk+d39f7XBHRw==} engines: {node: '>= 6.X.X'} @@ -29199,7 +29463,7 @@ packages: tsconfig-paths: 3.15.0 dev: true - /ts-node@10.9.1(@types/node@16.18.60)(typescript@4.9.4): + /ts-node@10.9.1(@types/node@16.18.60)(typescript@4.9.5): resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} hasBin: true peerDependencies: @@ -29225,12 +29489,12 @@ packages: create-require: 1.1.1 diff: 4.0.2 make-error: 1.3.6 - typescript: 4.9.4 + typescript: 4.9.5 v8-compile-cache-lib: 3.0.1 yn: 3.1.1 dev: true - /ts-node@10.9.1(@types/node@16.18.60)(typescript@4.9.5): + /ts-node@10.9.1(@types/node@20.14.2)(typescript@4.9.5): resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} hasBin: true peerDependencies: @@ -29249,7 +29513,7 @@ packages: '@tsconfig/node12': 1.0.11 '@tsconfig/node14': 1.0.3 '@tsconfig/node16': 1.0.3 - '@types/node': 16.18.60 + '@types/node': 20.14.2 acorn: 8.11.3 acorn-walk: 8.2.0 arg: 4.1.3 @@ -29259,9 +29523,8 @@ packages: typescript: 4.9.5 v8-compile-cache-lib: 3.0.1 yn: 3.1.1 - dev: true - /ts-node@10.9.1(@types/node@20.14.2)(typescript@4.9.5): + /ts-node@10.9.1(@types/node@20.14.2)(typescript@5.4.5): resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} hasBin: true peerDependencies: @@ -29287,12 +29550,12 @@ packages: create-require: 1.1.1 diff: 4.0.2 make-error: 1.3.6 - typescript: 4.9.5 + typescript: 5.4.5 v8-compile-cache-lib: 3.0.1 yn: 3.1.1 - /ts-node@10.9.1(@types/node@20.14.2)(typescript@5.4.5): - resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} + /ts-node@10.9.2(@types/node@16.18.60)(typescript@4.9.4): + resolution: {integrity: sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==} hasBin: true peerDependencies: '@swc/core': '>=1.2.50' @@ -29310,16 +29573,48 @@ packages: '@tsconfig/node12': 1.0.11 '@tsconfig/node14': 1.0.3 '@tsconfig/node16': 1.0.3 - '@types/node': 20.14.2 + '@types/node': 16.18.60 acorn: 8.11.3 acorn-walk: 8.2.0 arg: 4.1.3 create-require: 1.1.1 diff: 4.0.2 make-error: 1.3.6 - typescript: 5.4.5 + typescript: 4.9.4 v8-compile-cache-lib: 3.0.1 yn: 3.1.1 + dev: true + + /ts-node@10.9.2(@types/node@18.19.34)(typescript@4.9.5): + resolution: {integrity: sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==} + hasBin: true + peerDependencies: + '@swc/core': '>=1.2.50' + '@swc/wasm': '>=1.2.50' + '@types/node': '*' + typescript: '>=2.7' + peerDependenciesMeta: + '@swc/core': + optional: true + '@swc/wasm': + optional: true + dependencies: + '@cspotcode/source-map-support': 0.8.1 + '@tsconfig/node10': 1.0.9 + '@tsconfig/node12': 1.0.11 + '@tsconfig/node14': 1.0.3 + '@tsconfig/node16': 1.0.3 + '@types/node': 18.19.34 + acorn: 8.11.3 + acorn-walk: 8.2.0 + arg: 4.1.3 + create-require: 1.1.1 + diff: 4.0.2 + make-error: 1.3.6 + typescript: 4.9.5 + v8-compile-cache-lib: 3.0.1 + yn: 3.1.1 + dev: true /ts-node@7.0.1: resolution: {integrity: sha512-BVwVbPJRspzNh2yfslyT1PSbl5uIk03EZlb493RKHN4qej/D06n1cEhjlOJG69oFsE7OT8XjpTUcYf6pKTLMhw==} @@ -29861,6 +30156,10 @@ packages: resolution: {integrity: sha512-HXgFDgDommxn5/bIv0cnQZsPhHDA90NPHD6+c/v21U5+Sx5hoP8+dP9IZXBU1gIfvdRfhG8cel9QNPeionfcCQ==} dev: true + /url-join@4.0.1: + resolution: {integrity: sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==} + dev: true + /url-parse@1.5.10: resolution: {integrity: sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==} dependencies: @@ -31335,7 +31634,6 @@ packages: /whatwg-fetch@3.6.20: resolution: {integrity: sha512-EqhiFU6daOA8kpjOWTL0olhVOF3i7OrFzSYiGsEMB8GcXS+RrzauAERX65xMeNWVqxA6HXH2m69Z9LaKKdisfg==} - dev: false /whatwg-mimetype@2.3.0: resolution: {integrity: sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g==} diff --git a/target_chains/starknet/sdk/js/package.json b/target_chains/starknet/sdk/js/package.json index 024148effd..83ba4ca5b7 100644 --- a/target_chains/starknet/sdk/js/package.json +++ b/target_chains/starknet/sdk/js/package.json @@ -22,6 +22,7 @@ "scripts": { "test": "jest --passWithNoTests", "build": "tsc", + "usage-example": "ts-node src/examples/usage.ts", "format": "prettier --write \"src/**/*.ts\"", "lint": "eslint src/", "prepublishOnly": "npm run build && npm test && npm run lint", @@ -41,7 +42,10 @@ "jest": "^29.4.1", "prettier": "^2.6.2", "ts-jest": "^29.0.5", - "typescript": "^4.6.3" + "typescript": "^4.6.3", + "ts-node": "^10.9.2", + "@pythnetwork/price-service-client": "^1.9.0", + "starknet": "^6.9.0" }, "dependencies": {} } diff --git a/target_chains/starknet/sdk/js/src/examples/usage.ts b/target_chains/starknet/sdk/js/src/examples/usage.ts new file mode 100644 index 0000000000..1f8b801de4 --- /dev/null +++ b/target_chains/starknet/sdk/js/src/examples/usage.ts @@ -0,0 +1,114 @@ +import { Account, Contract, RpcProvider, shortString } from "starknet"; +import { PriceServiceConnection } from "@pythnetwork/price-service-client"; +import { + ByteBuffer, + ERC20_ABI, + STRK_TOKEN_ADDRESS, + PYTH_ABI, + PYTH_CONTRACT_ADDRESS_SEPOLIA, +} from ".."; + +async function main() { + // Create a provider for interacting with Starknet RPC. + const provider = new RpcProvider({ + nodeUrl: "https://starknet-sepolia.public.blastapi.io/rpc/v0_6", + }); + console.log( + "chain id: ", + shortString.decodeShortString(await provider.getChainId()) + ); + console.log("rpc version: ", await provider.getSpecVersion()); + + // Create a `Contract` instance to interact with a fee token contract on Starknet + // (you can use either STRK or ETH to pay fees, but using STRK is recommended). + const strkErc0Contract = new Contract( + ERC20_ABI, + STRK_TOKEN_ADDRESS, + provider + ); + + // Create a `Contract` instance to interact with the Pyth contract on Starknet. + const pythContract = new Contract( + PYTH_ABI, + PYTH_CONTRACT_ADDRESS_SEPOLIA, + provider + ); + const chain_id = await pythContract.chain_id(); + console.log("pyth chain id:", chain_id); + + const version = await pythContract.version(); + console.log("pyth version:", shortString.decodeShortString(version)); + + // Import your account data from environment variables. + // You'll need to set them before running the code. + const privateKey0 = process.env.ACCOUNT_PRIVATE_KEY; + if (privateKey0 === undefined) { + throw new Error("missing ACCOUNT_PRIVATE_KEY"); + } + const account0Address = process.env.ACCOUNT_ADDRESS; + if (account0Address === undefined) { + throw new Error("missing ACCOUNT_ADDRESS"); + } + const account0 = new Account(provider, account0Address, privateKey0); + + const balanceInitial = await strkErc0Contract.balanceOf(account0Address); + console.log("account0 balance:", balanceInitial); + + // Create a client for pulling price updates from Hermes. + const connection = new PriceServiceConnection("https://hermes.pyth.network", { + priceFeedRequestConfig: { + // Provide this option to retrieve signed price updates for on-chain contracts. + // Ignore this option for off-chain use. + binary: true, + }, + }); + + const priceFeedId = + "0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace"; // ETH/USD + const previousPrice = await pythContract.get_price_unsafe(priceFeedId); + console.log("previous price:", previousPrice); + + console.log("querying pyth update"); + // Get the latest values of the price feeds as json objects. + const currentPrices = await connection.getLatestPriceFeeds([priceFeedId]); + if (currentPrices === undefined) { + throw new Error("failed to get prices"); + } + console.log("current price:", currentPrices[0]); + + if (!currentPrices[0].vaa) { + throw new Error("missing vaa in response"); + } + + // Convert the price update to Starknet format. + const pythUpdate = ByteBuffer.fromHex(currentPrices[0].vaa); + + // Query the amount of fee required by Pyth. + console.log("querying pyth fee"); + const fee = await pythContract.get_update_fee( + pythUpdate, + strkErc0Contract.address + ); + console.log("pyth fee:", fee); + + // Approve fee withdrawal. + console.log("approving fee"); + strkErc0Contract.connect(account0); + let tx = await strkErc0Contract.approve(pythContract.address, fee); + console.log("waiting for tx"); + await provider.waitForTransaction(tx.transaction_hash); + + pythContract.connect(account0); + + // Create a transaction and submit to your contract using the price update data. + console.log("updating price feeds"); + tx = await pythContract.update_price_feeds(pythUpdate); + console.log("waiting for tx"); + await provider.waitForTransaction(tx.transaction_hash); + console.log("transaction confirmed:", tx.transaction_hash); + + const newPrice = await pythContract.get_price_no_older_than(priceFeedId, 60); + console.log("new price:", newPrice); +} + +main();