Selaa lähdekoodia

fix(target_chains/near): update dependencies and code to make tests work (#2100)

The old workspaces package in near that is used as a test suite couldn't download the required near-sandbox for it from an external url and it resulted in integration tests failing.

The new workspaces package is called near-workspaces and its near-sandbox has some rust version requirements to fully work, otherwise it panics with CompilationError(PrepareError(Deserialization)). The rust version 1.79.0 that its sandbox uses works but the latest stable rust 1.82.0 still fails. This assumption is not documented anywhere and I guessed it based on this old issue.

In the journey to make it work with @Riateche, we ended up updating the SDKs hoping to fix the problem and it's probably not needed but as the changes are good and will save us time in the future, i'll be keeping them.
Ali Behjati 1 vuosi sitten
vanhempi
sitoutus
425a155d50

+ 0 - 2
.github/workflows/ci-near-contract.yml

@@ -23,7 +23,5 @@ jobs:
         working-directory: target_chains/near/receiver
     steps:
       - uses: actions/checkout@v2
-      - name: Install nextest
-        run: curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin
       - name: Test
         run: ./workspace-test.sh

+ 390 - 62
target_chains/near/example/Cargo.lock

@@ -182,6 +182,12 @@ version = "0.13.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
 
+[[package]]
+name = "base64"
+version = "0.22.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
+
 [[package]]
 name = "binary-install"
 version = "0.0.2"
@@ -286,23 +292,70 @@ version = "0.9.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "15bf3650200d8bffa99015595e10f1fbd17de07abbc25bb067da79e769939bfa"
 dependencies = [
- "borsh-derive",
+ "borsh-derive 0.9.3",
  "hashbrown 0.11.2",
 ]
 
+[[package]]
+name = "borsh"
+version = "0.10.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "115e54d64eb62cdebad391c19efc9dce4981c690c85a33a12199d99bb9546fee"
+dependencies = [
+ "borsh-derive 0.10.4",
+ "hashbrown 0.12.3",
+]
+
+[[package]]
+name = "borsh"
+version = "1.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a6362ed55def622cddc70a4746a68554d7b687713770de539e59a739b249f8ed"
+dependencies = [
+ "borsh-derive 1.5.1",
+ "cfg_aliases",
+]
+
 [[package]]
 name = "borsh-derive"
 version = "0.9.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "6441c552f230375d18e3cc377677914d2ca2b0d36e52129fe15450a2dce46775"
 dependencies = [
- "borsh-derive-internal",
- "borsh-schema-derive-internal",
+ "borsh-derive-internal 0.9.3",
+ "borsh-schema-derive-internal 0.9.3",
  "proc-macro-crate 0.1.5",
  "proc-macro2",
  "syn 1.0.107",
 ]
 
+[[package]]
+name = "borsh-derive"
+version = "0.10.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "831213f80d9423998dd696e2c5345aba6be7a0bd8cd19e31c5243e13df1cef89"
+dependencies = [
+ "borsh-derive-internal 0.10.4",
+ "borsh-schema-derive-internal 0.10.4",
+ "proc-macro-crate 0.1.5",
+ "proc-macro2",
+ "syn 1.0.107",
+]
+
+[[package]]
+name = "borsh-derive"
+version = "1.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c3ef8005764f53cd4dca619f5bf64cafd4664dada50ece25e4d81de54c80cc0b"
+dependencies = [
+ "once_cell",
+ "proc-macro-crate 3.2.0",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.38",
+ "syn_derive",
+]
+
 [[package]]
 name = "borsh-derive-internal"
 version = "0.9.3"
@@ -314,6 +367,17 @@ dependencies = [
  "syn 1.0.107",
 ]
 
+[[package]]
+name = "borsh-derive-internal"
+version = "0.10.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "65d6ba50644c98714aa2a70d13d7df3cd75cd2b523a2b452bf010443800976b3"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 1.0.107",
+]
+
 [[package]]
 name = "borsh-schema-derive-internal"
 version = "0.9.3"
@@ -325,12 +389,32 @@ dependencies = [
  "syn 1.0.107",
 ]
 
+[[package]]
+name = "borsh-schema-derive-internal"
+version = "0.10.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "276691d96f063427be83e6692b86148e488ebba9f48f77788724ca027ba3b6d4"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 1.0.107",
+]
+
 [[package]]
 name = "bs58"
 version = "0.4.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3"
 
+[[package]]
+name = "bs58"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4"
+dependencies = [
+ "tinyvec",
+]
+
 [[package]]
 name = "bstr"
 version = "1.1.0"
@@ -442,6 +526,12 @@ version = "1.0.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
 
+[[package]]
+name = "cfg_aliases"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
+
 [[package]]
 name = "chrono"
 version = "0.4.23"
@@ -654,6 +744,40 @@ dependencies = [
  "syn 1.0.107",
 ]
 
+[[package]]
+name = "darling"
+version = "0.20.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989"
+dependencies = [
+ "darling_core",
+ "darling_macro",
+]
+
+[[package]]
+name = "darling_core"
+version = "0.20.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5"
+dependencies = [
+ "fnv",
+ "ident_case",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.38",
+]
+
+[[package]]
+name = "darling_macro"
+version = "0.20.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806"
+dependencies = [
+ "darling_core",
+ "quote",
+ "syn 2.0.38",
+]
+
 [[package]]
 name = "derive_more"
 version = "0.99.17"
@@ -761,6 +885,12 @@ dependencies = [
  "cfg-if 1.0.0",
 ]
 
+[[package]]
+name = "equivalent"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
+
 [[package]]
 name = "event-listener"
 version = "2.5.3"
@@ -997,7 +1127,7 @@ dependencies = [
  "futures-sink",
  "futures-util",
  "http",
- "indexmap",
+ "indexmap 1.9.2",
  "slab",
  "tokio",
  "tokio-util",
@@ -1018,6 +1148,15 @@ name = "hashbrown"
 version = "0.12.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
+dependencies = [
+ "ahash",
+]
+
+[[package]]
+name = "hashbrown"
+version = "0.15.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3"
 
 [[package]]
 name = "heck"
@@ -1025,6 +1164,12 @@ version = "0.4.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
 
+[[package]]
+name = "heck"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
+
 [[package]]
 name = "hermit-abi"
 version = "0.2.6"
@@ -1153,6 +1298,12 @@ dependencies = [
  "cxx-build",
 ]
 
+[[package]]
+name = "ident_case"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
+
 [[package]]
 name = "idna"
 version = "0.3.0"
@@ -1199,6 +1350,16 @@ dependencies = [
  "hashbrown 0.12.3",
 ]
 
+[[package]]
+name = "indexmap"
+version = "2.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da"
+dependencies = [
+ "equivalent",
+ "hashbrown 0.15.1",
+]
+
 [[package]]
 name = "instant"
 version = "0.1.12"
@@ -1371,7 +1532,7 @@ version = "0.3.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "885db39b08518fa700b73fa2214e8adbbfba316ba82dd510f50519173eadaf73"
 dependencies = [
- "borsh",
+ "borsh 0.9.3",
  "schemars",
  "semver",
  "serde",
@@ -1383,7 +1544,7 @@ version = "0.14.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "71d258582a1878e6db67400b0504a5099db85718d22c2e07f747fe1706ae7150"
 dependencies = [
- "borsh",
+ "borsh 0.9.3",
  "serde",
 ]
 
@@ -1393,7 +1554,17 @@ version = "0.15.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "1d924011380de759c3dc6fdbcda37a19a5c061f56dab69d28a34ecee765e23e4"
 dependencies = [
- "borsh",
+ "borsh 0.9.3",
+ "serde",
+]
+
+[[package]]
+name = "near-account-id"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "35cbb989542587b47205e608324ddd391f0cee1c22b4b64ae49f458334b95907"
+dependencies = [
+ "borsh 1.5.1",
  "serde",
 ]
 
@@ -1424,8 +1595,8 @@ checksum = "1e75673d69fd7365508f3d32483669fe45b03bfb34e4d9363e90adae9dfb416c"
 dependencies = [
  "arrayref",
  "blake2",
- "borsh",
- "bs58",
+ "borsh 0.9.3",
+ "bs58 0.4.0",
  "c2-chacha",
  "curve25519-dalek",
  "derive_more",
@@ -1450,8 +1621,8 @@ checksum = "7754612b47737d277fb818e9fdbb1406e90f9e57151c55c3584d714421976cb6"
 dependencies = [
  "arrayref",
  "blake2",
- "borsh",
- "bs58",
+ "borsh 0.9.3",
+ "bs58 0.4.0",
  "c2-chacha",
  "curve25519-dalek",
  "derive_more",
@@ -1467,13 +1638,23 @@ dependencies = [
  "thiserror",
 ]
 
+[[package]]
+name = "near-gas"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "180edcc7dc2fac41f93570d0c7b759c1b6d492f6ad093d749d644a40b4310a97"
+dependencies = [
+ "borsh 1.5.1",
+ "serde",
+]
+
 [[package]]
 name = "near-jsonrpc-client"
 version = "0.4.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "d1335ffce1476da6516dcd22b26cece1a495fc725c0e8fec1879073752ac068d"
 dependencies = [
- "borsh",
+ "borsh 0.9.3",
  "lazy_static",
  "log",
  "near-chain-configs",
@@ -1508,7 +1689,7 @@ version = "0.14.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "8ad1a9a1640539c81f065425c31bffcfbf6b31ef1aeaade59ce905f5df6ac860"
 dependencies = [
- "borsh",
+ "borsh 0.9.3",
  "byteorder",
  "bytesize",
  "chrono",
@@ -1527,7 +1708,7 @@ dependencies = [
  "serde",
  "serde_json",
  "smart-default",
- "strum",
+ "strum 0.24.1",
  "thiserror",
 ]
 
@@ -1537,7 +1718,7 @@ version = "0.15.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "97670b302dce15f09bba50f24c67aa08130fd01528cc61d4415892401e88e974"
 dependencies = [
- "borsh",
+ "borsh 0.9.3",
  "byteorder",
  "bytesize",
  "cfg-if 1.0.0",
@@ -1557,7 +1738,7 @@ dependencies = [
  "serde",
  "serde_json",
  "smart-default",
- "strum",
+ "strum 0.24.1",
  "thiserror",
 ]
 
@@ -1568,14 +1749,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "91d508f0fc340f6461e4e256417685720d3c4c00bb5a939b105160e49137caba"
 dependencies = [
  "base64 0.11.0",
- "borsh",
- "bs58",
+ "borsh 0.9.3",
+ "bs58 0.4.0",
  "derive_more",
  "near-account-id 0.14.0",
  "num-rational 0.3.2",
  "serde",
  "sha2 0.10.6",
- "strum",
+ "strum 0.24.1",
 ]
 
 [[package]]
@@ -1585,15 +1766,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "7929e19d862221949734c4a0063a8f55e7069de3a2ebc2d4f4c13497a5e953cb"
 dependencies = [
  "base64 0.13.1",
- "borsh",
- "bs58",
+ "borsh 0.9.3",
+ "bs58 0.4.0",
  "derive_more",
  "near-account-id 0.15.0",
  "num-rational 0.3.2",
  "serde",
  "serde_repr",
  "sha2 0.10.6",
- "strum",
+ "strum 0.24.1",
 ]
 
 [[package]]
@@ -1662,13 +1843,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "15eb3de2defe3626260cc209a6cdb985c6b27b0bd4619fad97dcfae002c3c5bd"
 dependencies = [
  "base64 0.13.1",
- "borsh",
- "bs58",
+ "borsh 0.9.3",
+ "bs58 0.4.0",
  "near-abi",
  "near-crypto 0.14.0",
  "near-primitives 0.14.0",
  "near-primitives-core 0.14.0",
- "near-sdk-macros",
+ "near-sdk-macros 4.1.1",
  "near-sys",
  "near-vm-logic",
  "once_cell",
@@ -1678,6 +1859,26 @@ dependencies = [
  "wee_alloc",
 ]
 
+[[package]]
+name = "near-sdk"
+version = "5.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4e296b02c85539c16659e171242d6c6bbea87eec7c9ef860d8dfd3fb3168a18a"
+dependencies = [
+ "base64 0.22.1",
+ "borsh 1.5.1",
+ "bs58 0.5.1",
+ "near-account-id 1.0.0",
+ "near-gas",
+ "near-sdk-macros 5.5.0",
+ "near-sys",
+ "near-token",
+ "once_cell",
+ "serde",
+ "serde_json",
+ "wee_alloc",
+]
+
 [[package]]
 name = "near-sdk-macros"
 version = "4.1.1"
@@ -1690,11 +1891,38 @@ dependencies = [
  "syn 1.0.107",
 ]
 
+[[package]]
+name = "near-sdk-macros"
+version = "5.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0adc79466aa556f56a995c0db34a933b32597ab92bbb0e526597118899c8bcaf"
+dependencies = [
+ "Inflector",
+ "darling",
+ "proc-macro2",
+ "quote",
+ "serde",
+ "serde_json",
+ "strum 0.26.3",
+ "strum_macros 0.26.4",
+ "syn 2.0.38",
+]
+
 [[package]]
 name = "near-sys"
-version = "0.2.0"
+version = "0.2.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e307313276eaeced2ca95740b5639e1f3125b7c97f0a1151809d105f1aa8c6d3"
+checksum = "dbf4ca5c805cb78700e10e43484902d8da05f25788db277999d209568aaf4c8e"
+
+[[package]]
+name = "near-token"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cd3e60aa26a74dc514b1b6408fdd06cefe2eb0ff029020956c1c6517594048fd"
+dependencies = [
+ "borsh 1.5.1",
+ "serde",
+]
 
 [[package]]
 name = "near-vm-errors"
@@ -1702,7 +1930,7 @@ version = "0.14.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "d0da466a30f0446639cbd788c30865086fac3e8dcb07a79e51d2b0775ed4261e"
 dependencies = [
- "borsh",
+ "borsh 0.9.3",
  "near-account-id 0.14.0",
  "near-rpc-error-macro 0.14.0",
  "serde",
@@ -1714,11 +1942,11 @@ version = "0.15.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "5591c9c8afa83a040cb5c3f29bc52b2efae2c32d4bcaee1bba723738da1a5cf6"
 dependencies = [
- "borsh",
+ "borsh 0.9.3",
  "near-account-id 0.15.0",
  "near-rpc-error-macro 0.15.0",
  "serde",
- "strum",
+ "strum 0.24.1",
 ]
 
 [[package]]
@@ -1728,8 +1956,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "81b534828419bacbf1f7b11ef7b00420f248c548c485d3f0cfda8bb6931152f2"
 dependencies = [
  "base64 0.13.1",
- "borsh",
- "bs58",
+ "borsh 0.9.3",
+ "bs58 0.4.0",
  "byteorder",
  "near-account-id 0.14.0",
  "near-crypto 0.14.0",
@@ -1885,9 +2113,9 @@ dependencies = [
 
 [[package]]
 name = "once_cell"
-version = "1.17.0"
+version = "1.20.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66"
+checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
 
 [[package]]
 name = "opaque-debug"
@@ -2111,6 +2339,38 @@ dependencies = [
  "toml",
 ]
 
+[[package]]
+name = "proc-macro-crate"
+version = "3.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b"
+dependencies = [
+ "toml_edit",
+]
+
+[[package]]
+name = "proc-macro-error"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
+dependencies = [
+ "proc-macro-error-attr",
+ "proc-macro2",
+ "quote",
+ "version_check",
+]
+
+[[package]]
+name = "proc-macro-error-attr"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "version_check",
+]
+
 [[package]]
 name = "proc-macro2"
 version = "1.0.69"
@@ -2126,17 +2386,17 @@ version = "0.1.0"
 dependencies = [
  "byteorder",
  "hex 0.4.3",
- "near-sdk",
+ "near-sdk 5.5.0",
  "nom",
  "num-derive",
  "num-traits",
  "pyth-sdk 0.7.0",
  "pyth-wormhole-attester-sdk",
  "pythnet-sdk",
- "serde_wormhole 0.1.0 (git+https://github.com/wormhole-foundation/wormhole)",
- "strum",
+ "serde_wormhole 0.1.0 (git+https://github.com/wormhole-foundation/wormhole?tag=rust-sdk-2024-01-25)",
+ "strum 0.24.1",
  "thiserror",
- "wormhole-core 0.1.0 (git+https://github.com/wormhole-foundation/wormhole)",
+ "wormhole-sdk",
 ]
 
 [[package]]
@@ -2146,18 +2406,18 @@ dependencies = [
  "byteorder",
  "hex 0.4.3",
  "lazy_static",
- "near-sdk",
+ "near-sdk 4.1.1",
  "num-derive",
  "num-traits",
  "pyth-near",
  "pythnet-sdk",
  "serde",
  "serde_json",
- "strum",
+ "strum 0.24.1",
  "thiserror",
  "tokio",
  "workspaces",
- "wormhole-core 0.1.0 (git+https://github.com/wormhole-foundation/wormhole?rev=4ddeca4dbdba50e2cbf6e603242f8c75d9246e2a)",
+ "wormhole-core",
 ]
 
 [[package]]
@@ -2166,8 +2426,8 @@ version = "0.5.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "f5c805ba3dfb5b7ed6a8ffa62ec38391f485a79c7cf6b3b11d3bd44fb0325824"
 dependencies = [
- "borsh",
- "borsh-derive",
+ "borsh 0.9.3",
+ "borsh-derive 0.9.3",
  "hex 0.4.3",
  "schemars",
  "serde",
@@ -2179,8 +2439,8 @@ version = "0.7.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "00bf2540203ca3c7a5712fdb8b5897534b7f6a0b6e7b0923ff00466c5f9efcb3"
 dependencies = [
- "borsh",
- "borsh-derive",
+ "borsh 0.9.3",
+ "borsh-derive 0.9.3",
  "hex 0.4.3",
  "schemars",
  "serde",
@@ -2197,10 +2457,10 @@ dependencies = [
 
 [[package]]
 name = "pythnet-sdk"
-version = "2.0.0"
+version = "2.3.0"
 dependencies = [
  "bincode",
- "borsh",
+ "borsh 0.10.4",
  "bytemuck",
  "byteorder",
  "fast-math",
@@ -2546,22 +2806,31 @@ checksum = "58bc9567378fc7690d6b2addae4e60ac2eeea07becb2c64b9f218b53865cba2a"
 
 [[package]]
 name = "serde"
-version = "1.0.152"
+version = "1.0.193"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb"
+checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89"
 dependencies = [
  "serde_derive",
 ]
 
+[[package]]
+name = "serde_bytes"
+version = "0.11.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "387cc504cb06bb40a96c8e04e951fe01854cf6bc921053c954e4a606d9675c6a"
+dependencies = [
+ "serde",
+]
+
 [[package]]
 name = "serde_derive"
-version = "1.0.152"
+version = "1.0.193"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e"
+checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn 1.0.107",
+ "syn 2.0.38",
 ]
 
 [[package]]
@@ -2612,17 +2881,19 @@ dependencies = [
 [[package]]
 name = "serde_wormhole"
 version = "0.1.0"
-source = "git+https://github.com/wormhole-foundation/wormhole?rev=4ddeca4dbdba50e2cbf6e603242f8c75d9246e2a#4ddeca4dbdba50e2cbf6e603242f8c75d9246e2a"
+source = "git+https://github.com/wormhole-foundation/wormhole?tag=rust-sdk-2024-01-25#55faa9ca1fe456e90e957b33aa7bcc565a33c3fa"
 dependencies = [
+ "base64 0.13.1",
  "itoa",
  "serde",
+ "serde_bytes",
  "thiserror",
 ]
 
 [[package]]
 name = "serde_wormhole"
 version = "0.1.0"
-source = "git+https://github.com/wormhole-foundation/wormhole#4ddeca4dbdba50e2cbf6e603242f8c75d9246e2a"
+source = "git+https://github.com/wormhole-foundation/wormhole?rev=4ddeca4dbdba50e2cbf6e603242f8c75d9246e2a#4ddeca4dbdba50e2cbf6e603242f8c75d9246e2a"
 dependencies = [
  "itoa",
  "serde",
@@ -2757,22 +3028,41 @@ version = "0.24.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f"
 dependencies = [
- "strum_macros",
+ "strum_macros 0.24.3",
 ]
 
+[[package]]
+name = "strum"
+version = "0.26.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06"
+
 [[package]]
 name = "strum_macros"
 version = "0.24.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59"
 dependencies = [
- "heck",
+ "heck 0.4.0",
  "proc-macro2",
  "quote",
  "rustversion",
  "syn 1.0.107",
 ]
 
+[[package]]
+name = "strum_macros"
+version = "0.26.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be"
+dependencies = [
+ "heck 0.5.0",
+ "proc-macro2",
+ "quote",
+ "rustversion",
+ "syn 2.0.38",
+]
+
 [[package]]
 name = "subtle"
 version = "2.4.1"
@@ -2801,6 +3091,18 @@ dependencies = [
  "unicode-ident",
 ]
 
+[[package]]
+name = "syn_derive"
+version = "0.1.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1329189c02ff984e9736652b1631330da25eaa6bc639089ed4915d25446cbe7b"
+dependencies = [
+ "proc-macro-error",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.38",
+]
+
 [[package]]
 name = "synstructure"
 version = "0.12.6"
@@ -2974,6 +3276,23 @@ dependencies = [
  "serde",
 ]
 
+[[package]]
+name = "toml_datetime"
+version = "0.6.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41"
+
+[[package]]
+name = "toml_edit"
+version = "0.22.22"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5"
+dependencies = [
+ "indexmap 2.6.0",
+ "toml_datetime",
+ "winnow",
+]
+
 [[package]]
 name = "tower-service"
 version = "0.3.2"
@@ -3364,6 +3683,15 @@ version = "0.42.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5"
 
+[[package]]
+name = "winnow"
+version = "0.6.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b"
+dependencies = [
+ "memchr",
+]
+
 [[package]]
 name = "winreg"
 version = "0.10.1"
@@ -3382,8 +3710,8 @@ dependencies = [
  "async-process",
  "async-trait",
  "base64 0.13.1",
- "borsh",
- "bs58",
+ "borsh 0.9.3",
+ "bs58 0.4.0",
  "chrono",
  "dirs 3.0.2",
  "hex 0.4.3",
@@ -3421,15 +3749,15 @@ dependencies = [
 ]
 
 [[package]]
-name = "wormhole-core"
+name = "wormhole-sdk"
 version = "0.1.0"
-source = "git+https://github.com/wormhole-foundation/wormhole#4ddeca4dbdba50e2cbf6e603242f8c75d9246e2a"
+source = "git+https://github.com/wormhole-foundation/wormhole?tag=rust-sdk-2024-01-25#55faa9ca1fe456e90e957b33aa7bcc565a33c3fa"
 dependencies = [
  "anyhow",
  "bstr",
  "schemars",
  "serde",
- "serde_wormhole 0.1.0 (git+https://github.com/wormhole-foundation/wormhole?rev=4ddeca4dbdba50e2cbf6e603242f8c75d9246e2a)",
+ "serde_wormhole 0.1.0 (git+https://github.com/wormhole-foundation/wormhole?tag=rust-sdk-2024-01-25)",
  "sha3",
  "thiserror",
 ]
@@ -3476,7 +3804,7 @@ version = "0.5.11"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "71e61de68ede9ffdd69c01664f65a178c5188b73f78faa21f0936016a888ff7c"
 dependencies = [
- "borsh",
+ "borsh 0.9.3",
  "byteorder",
  "crunchy",
  "lazy_static",

+ 2 - 2
target_chains/near/example/Cargo.toml

@@ -12,7 +12,7 @@ crate-type                 = ["cdylib", "lib"]
 [dependencies]
 byteorder                  = { version = "1.4.3" }
 hex                        = { version = "0.4.3" }
-near-sdk                   = { version = "4.1.1" }
+near-sdk                   = { version = "5.5.0" }
 num-traits                 = { version = "0.2.15" }
 num-derive                 = { version = "0.3.3" }
 pythnet-sdk                = { path = "../../../pythnet/pythnet_sdk" }
@@ -29,7 +29,7 @@ lazy_static                = { version = "1.4.0" }
 serde_json                 = { version = "1.0.91" }
 serde                      = { version = "1.0.152", features = ["derive"] }
 tokio                      = { version = "1.23.0", features = ["full"] }
-workspaces                 = { version = "0.7.0" }
+near-workspaces            = { version = "0.14.1" }
 
 [profile.release]
 codegen-units              = 1

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 391 - 251
target_chains/near/receiver/Cargo.lock


+ 3 - 2
target_chains/near/receiver/Cargo.toml

@@ -15,7 +15,7 @@ library = []
 [dependencies]
 byteorder                  = { version = "1.4.3" }
 hex                        = { version = "0.4.3" }
-near-sdk                   = { version = "4.1.1" }
+near-sdk                   = { version = "5.5.0", features = ["legacy"] }
 nom                        = { version = "7.1.2" }
 num-traits                 = { version = "0.2.15" }
 num-derive                 = { version = "0.3.3" }
@@ -33,9 +33,10 @@ serde_json                 = { version = "1.0.91" }
 serde                      = { version = "1.0.152", features = ["derive"] }
 tokio                      = { version = "1.23.0", features = ["full"] }
 serde_wormhole             = { git = "https://github.com/wormhole-foundation/wormhole", tag="rust-sdk-2024-01-25" }
-workspaces                 = { version = "0.7.0" }
+near-workspaces            = { version = "0.14.1" }
 wormhole-sdk               = { git = "https://github.com/wormhole-foundation/wormhole", tag="rust-sdk-2024-01-25" }
 pythnet-sdk                = { path = "../../../pythnet/pythnet_sdk", features = ["test-utils"] }
+near-sdk                   = { version = "*", features = ["unit-testing"] }
 
 
 

+ 1 - 0
target_chains/near/receiver/src/ext.rs

@@ -31,6 +31,7 @@ pub trait Wormhole {
 pub trait Pyth {
     // See the implementation for details. The `data` parameter can be found by using a Hermes
     // price feed endpoint, and should be fed in as base64.
+    #[handle_result]
     fn update_price_feeds(&mut self, data: String) -> Result<(), Error>;
     fn get_update_fee_estimate(&self, vaa: String) -> U128;
     fn get_sources(&self) -> Vec<Source>;

+ 34 - 27
target_chains/near/receiver/src/governance.rs

@@ -18,7 +18,6 @@ use {
     },
     near_sdk::{
         borsh::{
-            self,
             BorshDeserialize,
             BorshSerialize,
         },
@@ -31,6 +30,7 @@ use {
         },
         AccountId,
         Gas,
+        NearToken,
         Promise,
         PromiseOrValue,
     },
@@ -57,6 +57,7 @@ const GOVERNANCE_MAGIC: [u8; 4] = *b"PTGM";
     num_derive::FromPrimitive,
     num_derive::ToPrimitive,
 )]
+#[borsh(crate = "near_sdk::borsh", use_discriminant = false)]
 #[serde(crate = "near_sdk::serde")]
 #[repr(u8)]
 pub enum GovernanceModule {
@@ -89,6 +90,7 @@ pub enum GovernanceModule {
 )]
 #[strum_discriminants(derive(num_derive::ToPrimitive, num_derive::FromPrimitive))]
 #[strum_discriminants(name(GovernanceActionId))]
+#[borsh(crate = "near_sdk::borsh")]
 #[serde(crate = "near_sdk::serde")]
 pub enum GovernanceAction {
     UpgradeContract { codehash: [u8; 32] },
@@ -100,6 +102,7 @@ pub enum GovernanceAction {
 }
 
 #[derive(BorshDeserialize, BorshSerialize, Debug, Deserialize, Eq, PartialEq, Serialize)]
+#[borsh(crate = "near_sdk::borsh")]
 #[serde(crate = "near_sdk::serde")]
 pub struct GovernanceInstruction {
     pub module: GovernanceModule,
@@ -283,17 +286,17 @@ impl Pyth {
 
         // Verify VAA and refund the caller in case of failure.
         Ok(ext_wormhole::ext(self.wormhole.clone())
-            .with_static_gas(Gas(30_000_000_000_000))
+            .with_static_gas(Gas::from_gas(30_000_000_000_000))
             .verify_vaa(vaa.clone())
             .then(
                 Self::ext(env::current_account_id())
-                    .with_static_gas(Gas(10_000_000_000_000))
+                    .with_static_gas(Gas::from_gas(10_000_000_000_000))
                     .with_attached_deposit(env::attached_deposit())
                     .verify_gov_vaa_callback(env::predecessor_account_id(), vaa),
             )
             .then(
                 Self::ext(env::current_account_id())
-                    .with_static_gas(Gas(10_000_000_000_000))
+                    .with_static_gas(Gas::from_gas(10_000_000_000_000))
                     .refund_vaa(env::predecessor_account_id(), env::attached_deposit()),
             ))
     }
@@ -372,11 +375,11 @@ impl Pyth {
                 // and the logic below is duplicated within the authorize_gov_source_transfer function.
                 return Ok(PromiseOrValue::Promise(
                     ext_wormhole::ext(self.wormhole.clone())
-                        .with_static_gas(Gas(10_000_000_000_000))
+                        .with_static_gas(Gas::from_gas(10_000_000_000_000))
                         .verify_vaa(claim_vaa.clone())
                         .then(
                             Self::ext(env::current_account_id())
-                                .with_static_gas(Gas(10_000_000_000_000))
+                                .with_static_gas(Gas::from_gas(10_000_000_000_000))
                                 .with_attached_deposit(env::attached_deposit())
                                 .authorize_gov_source_transfer(
                                     env::predecessor_account_id(),
@@ -386,7 +389,7 @@ impl Pyth {
                         )
                         .then(
                             Self::ext(env::current_account_id())
-                                .with_static_gas(Gas(10_000_000_000_000))
+                                .with_static_gas(Gas::from_gas(10_000_000_000_000))
                                 .refund_vaa(env::predecessor_account_id(), env::attached_deposit()),
                         ),
                 ));
@@ -406,7 +409,7 @@ impl Pyth {
 
     /// If submitting an action fails then this callback will refund the caller.
     #[private]
-    pub fn refund_vaa(&mut self, account_id: AccountId, amount: u128) {
+    pub fn refund_vaa(&mut self, account_id: AccountId, amount: NearToken) {
         if !is_promise_success() {
             // No calculations needed as deposit size will have not changed. Can just refund the
             // whole deposit amount.
@@ -484,12 +487,14 @@ impl Pyth {
     /// This function is open to call by anyone, but to perform an authorized upgrade a VAA
     /// containing the hash of the `new_code` must have previously been relayed to this contract's
     /// `process_vaa` endpoint. otherwise the upgrade will fail.
-    ///
-    /// NOTE: This function is pub only within crate scope so that it can only be called by the
-    /// `upgrade_contract` method, this is much much cheaper than serializing a Vec<u8> to call
-    /// this method as a normal public method.
     #[handle_result]
-    pub(crate) fn upgrade(&mut self, new_code: Vec<u8>) -> Result<Promise, Error> {
+    pub fn update_contract(&mut self) -> Result<Promise, Error> {
+        env::setup_panic_hook();
+        let new_code = env::input().unwrap();
+        self.upgrade(new_code)
+    }
+
+    fn upgrade(&mut self, new_code: Vec<u8>) -> Result<Promise, Error> {
         let signature = TryInto::<[u8; 32]>::try_into(env::sha256(&new_code)).unwrap();
         let default = <[u8; 32] as Default>::default();
         ensure!(signature != default, UnauthorizedUpgrade);
@@ -512,7 +517,7 @@ impl Pyth {
     pub fn refund_upgrade(
         &mut self,
         account_id: AccountId,
-        amount: u128,
+        amount: NearToken,
         storage: u64,
     ) -> Result<(), Error> {
         Self::refund_storage_usage(account_id, storage, env::storage_usage(), amount, None)
@@ -532,13 +537,15 @@ impl Pyth {
     }
 
     pub fn set_update_fee(&mut self, fee: u64, expo: u64) -> Result<(), Error> {
-        self.update_fee = (fee as u128)
-            .checked_mul(
-                10_u128
-                    .checked_pow(u32::try_from(expo).map_err(|_| ArithmeticOverflow)?)
-                    .ok_or(ArithmeticOverflow)?,
-            )
-            .ok_or(ArithmeticOverflow)?;
+        self.update_fee = NearToken::from_yoctonear(
+            (fee as u128)
+                .checked_mul(
+                    10_u128
+                        .checked_pow(u32::try_from(expo).map_err(|_| ArithmeticOverflow)?)
+                        .ok_or(ArithmeticOverflow)?,
+                )
+                .ok_or(ArithmeticOverflow)?,
+        );
 
         Ok(())
     }
@@ -579,7 +586,7 @@ mod tests {
             .current_account_id(accounts(0))
             .signer_account_id(accounts(0))
             .predecessor_account_id(accounts(0))
-            .attached_deposit(0)
+            .attached_deposit(NearToken::from_yoctonear(0))
             .is_view(false);
         context
     }
@@ -591,7 +598,7 @@ mod tests {
         testing_env!(context.build());
 
         let mut contract = Pyth::new(
-            near_sdk::AccountId::new_unchecked("pyth.near".to_owned()),
+            "pyth.near".parse::<near_sdk::AccountId>().unwrap(),
             Source::default(),
             Source::default(),
             0.into(),
@@ -610,7 +617,7 @@ mod tests {
         testing_env!(context.build());
 
         let mut contract = Pyth::new(
-            near_sdk::AccountId::new_unchecked("pyth.near".to_owned()),
+            "pyth.near".parse::<near_sdk::AccountId>().unwrap(),
             Source::default(),
             Source::default(),
             0.into(),
@@ -628,7 +635,7 @@ mod tests {
         testing_env!(context.build());
 
         let mut contract = Pyth::new(
-            near_sdk::AccountId::new_unchecked("pyth.near".to_owned()),
+            "pyth.near".parse::<near_sdk::AccountId>().unwrap(),
             Source::default(),
             Source::default(),
             0.into(),
@@ -646,7 +653,7 @@ mod tests {
         testing_env!(context.build());
 
         let mut contract = Pyth::new(
-            near_sdk::AccountId::new_unchecked("pyth.near".to_owned()),
+            "pyth.near".parse::<near_sdk::AccountId>().unwrap(),
             Source::default(),
             Source::default(),
             0.into(),
@@ -654,7 +661,7 @@ mod tests {
         );
 
         contract.set_update_fee(100, 2).expect("Failed to set fee");
-        assert_eq!(contract.update_fee, 10000);
+        assert_eq!(contract.update_fee, NearToken::from_yoctonear(10000));
     }
 
     #[test]

+ 54 - 40
target_chains/near/receiver/src/lib.rs

@@ -5,7 +5,6 @@ use {
     ext::ext_wormhole,
     near_sdk::{
         borsh::{
-            self,
             BorshDeserialize,
             BorshSerialize,
         },
@@ -19,10 +18,10 @@ use {
         log,
         near_bindgen,
         AccountId,
-        Balance,
         BorshStorageKey,
         Duration,
         Gas,
+        NearToken,
         PanicOnDefault,
         Promise,
         StorageUsage,
@@ -71,6 +70,7 @@ pub mod state;
 pub mod tests;
 
 #[derive(BorshSerialize, BorshStorageKey)]
+#[borsh(crate = "near_sdk::borsh")]
 enum StorageKeys {
     Source,
     Prices,
@@ -87,6 +87,7 @@ type Seconds = u64;
 #[cfg(not(feature = "library"))]
 #[near_bindgen]
 #[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)]
+#[borsh(crate = "near_sdk::borsh")]
 pub struct Pyth {
     /// The set of `Source`s from which Pyth attestations are allowed to be relayed from.
     sources: UnorderedSet<Source>,
@@ -117,7 +118,7 @@ pub struct Pyth {
     stale_threshold: Duration,
 
     /// Fee for updating price.
-    update_fee: u128,
+    update_fee: NearToken,
 }
 
 #[cfg(not(feature = "library"))]
@@ -144,7 +145,7 @@ impl Pyth {
             sources,
             wormhole,
             codehash: Default::default(),
-            update_fee: update_fee.into(),
+            update_fee: NearToken::from_yoctonear(update_fee.into()),
         }
     }
 
@@ -211,11 +212,11 @@ impl Pyth {
                     self.verify_encoded_vaa_source(vaa.as_ref())?;
                     let vaa_hex = hex::encode(vaa.as_ref());
                     ext_wormhole::ext(self.wormhole.clone())
-                        .with_static_gas(Gas(30_000_000_000_000))
+                        .with_static_gas(Gas::from_gas(30_000_000_000_000))
                         .verify_vaa(vaa_hex.clone())
                         .then(
                             Self::ext(env::current_account_id())
-                                .with_static_gas(Gas(30_000_000_000_000))
+                                .with_static_gas(Gas::from_gas(30_000_000_000_000))
                                 .with_attached_deposit(env::attached_deposit())
                                 .verify_wormhole_merkle_callback(
                                     env::predecessor_account_id(),
@@ -224,7 +225,7 @@ impl Pyth {
                         )
                         .then(
                             Self::ext(env::current_account_id())
-                                .with_static_gas(Gas(30_000_000_000_000))
+                                .with_static_gas(Gas::from_gas(30_000_000_000_000))
                                 .refund_vaa(env::predecessor_account_id(), env::attached_deposit()),
                         );
                 }
@@ -236,17 +237,17 @@ impl Pyth {
 
             // Verify VAA and refund the caller in case of failure.
             ext_wormhole::ext(self.wormhole.clone())
-                .with_static_gas(Gas(30_000_000_000_000))
+                .with_static_gas(Gas::from_gas(30_000_000_000_000))
                 .verify_vaa(data.clone())
                 .then(
                     Self::ext(env::current_account_id())
-                        .with_static_gas(Gas(30_000_000_000_000))
+                        .with_static_gas(Gas::from_gas(30_000_000_000_000))
                         .with_attached_deposit(env::attached_deposit())
                         .verify_wormhole_batch_callback(env::predecessor_account_id(), data),
                 )
                 .then(
                     Self::ext(env::current_account_id())
-                        .with_static_gas(Gas(30_000_000_000_000))
+                        .with_static_gas(Gas::from_gas(30_000_000_000_000))
                         .refund_vaa(env::predecessor_account_id(), env::attached_deposit()),
                 );
         }
@@ -313,7 +314,9 @@ impl Pyth {
             "#,
             count_updates,
             env::storage_usage() - storage,
-            env::storage_byte_cost() * (env::storage_usage() - storage) as u128,
+            env::storage_byte_cost()
+                .checked_mul(env::storage_usage().checked_sub(storage).unwrap().into())
+                .unwrap(),
         );
 
         // Refund storage difference to `account_id` after storage execution.
@@ -346,7 +349,8 @@ impl Pyth {
         let storage = (env::storage_usage() as u128)
             .checked_sub(
                 self.update_fee
-                    .checked_div(env::storage_byte_cost())
+                    .as_yoctonear()
+                    .checked_div(env::storage_byte_cost().as_yoctonear())
                     .ok_or(Error::ArithmeticOverflow)?,
             )
             .ok_or(Error::InsufficientDeposit)
@@ -404,7 +408,9 @@ impl Pyth {
             "#,
             count_updates,
             env::storage_usage() - storage,
-            env::storage_byte_cost() * (env::storage_usage() - storage) as u128,
+            env::storage_byte_cost()
+                .checked_mul(env::storage_usage().checked_sub(storage).unwrap().into())
+                .unwrap(),
         );
 
         // Refund storage difference to `account_id` after storage execution.
@@ -422,7 +428,9 @@ impl Pyth {
     #[allow(unused_variables)]
     pub fn get_update_fee_estimate(&self, data: String) -> U128 {
         let byte_cost = env::storage_byte_cost();
-        let data_cost = byte_cost * std::mem::size_of::<PriceFeed>() as u128;
+        let data_cost = byte_cost
+            .checked_mul(std::mem::size_of::<PriceFeed>().try_into().unwrap())
+            .unwrap();
 
         // If the data is an Accumulator style update, we should count he number of updates being
         // calculated in the fee.
@@ -448,7 +456,13 @@ impl Pyth {
         //
         // 5 is the upper limit for PriceFeed amount in a single update.
         // 4 is the value obtained through testing for headway.
-        (5u128 * 4u128 * data_cost + self.update_fee * total_updates).into()
+        (data_cost
+            .checked_mul(5u128 * 4u128)
+            .unwrap()
+            .checked_add(self.update_fee.checked_mul(total_updates).unwrap())
+            .unwrap())
+        .as_yoctonear()
+        .into()
     }
 
     /// Read the list of accepted `Source` chains for a price attestation.
@@ -681,42 +695,42 @@ impl Pyth {
         recipient: AccountId,
         before: StorageUsage,
         after: StorageUsage,
-        deposit: Balance,
-        additional_fee: Option<Balance>,
+        deposit: NearToken,
+        additional_fee: Option<NearToken>,
     ) -> Result<(), Error> {
-        let fee = additional_fee.unwrap_or(0);
+        let fee = additional_fee.unwrap_or_default();
 
         if let Some(diff) = after.checked_sub(before) {
             // Handle storage increases if checked_sub succeeds.
-            let cost = Balance::from(diff);
-            let cost = (cost * env::storage_byte_cost()) + fee;
-
-            // If the cost is higher than the deposit we bail.
-            if cost > deposit {
-                return Err(Error::InsufficientDeposit);
-            }
-
-            // Otherwise we refund whatever is left over.
-            if deposit - cost > 0 {
-                Promise::new(recipient).transfer(deposit - cost);
+            let cost = (env::storage_byte_cost().checked_mul(diff.into()).unwrap())
+                .checked_add(fee)
+                .unwrap();
+
+            // Use match
+            match deposit.checked_sub(cost) {
+                Some(refund) => {
+                    if !refund.is_zero() {
+                        Promise::new(recipient).transfer(refund);
+                    }
+                }
+                None => {
+                    return Err(Error::InsufficientDeposit);
+                }
             }
         } else {
             // If checked_sub fails we have a storage decrease, we want to refund them the cost of
             // the amount reduced, as well the original deposit they sent.
-            let refund = Balance::from(before - after);
-            let refund = refund * env::storage_byte_cost();
-            let refund = refund + deposit - fee;
+            let storage_refund = env::storage_byte_cost()
+                .checked_mul(before.checked_sub(after).unwrap().into())
+                .unwrap();
+            let refund = storage_refund
+                .checked_add(deposit)
+                .unwrap()
+                .checked_sub(fee)
+                .unwrap();
             Promise::new(recipient).transfer(refund);
         }
 
         Ok(())
     }
 }
-
-#[cfg(not(feature = "library"))]
-#[no_mangle]
-pub extern "C" fn update_contract() {
-    env::setup_panic_hook();
-    let mut contract: Pyth = env::state_read().expect("Failed to Read State");
-    contract.upgrade(env::input().unwrap()).unwrap();
-}

+ 5 - 1
target_chains/near/receiver/src/state.rs

@@ -1,7 +1,6 @@
 use {
     near_sdk::{
         borsh::{
-            self,
             BorshDeserialize,
             BorshSerialize,
         },
@@ -26,6 +25,7 @@ pub type WormholeSignature = [u8; 65];
 pub type WormholeAddress = [u8; 32];
 
 #[derive(BorshDeserialize, BorshSerialize, PartialEq, Eq, Hash)]
+#[borsh(crate = "near_sdk::borsh")]
 #[repr(transparent)]
 pub struct PriceIdentifier(pub [u8; 32]);
 
@@ -86,6 +86,7 @@ impl near_sdk::serde::Serialize for PriceIdentifier {
 /// Please refer to the documentation at https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices for how
 /// to how this price safely.
 #[derive(BorshDeserialize, BorshSerialize, Debug, Deserialize, Serialize, PartialEq, Eq)]
+#[borsh(crate = "near_sdk::borsh")]
 #[serde(crate = "near_sdk::serde")]
 pub struct Price {
     pub price:        I64,
@@ -102,6 +103,7 @@ pub struct Price {
 /// This structure matches the layout of the PriceFeed structure in other Pyth receiver contracts
 /// but uses types that are native to NEAR.
 #[derive(BorshDeserialize, BorshSerialize, Deserialize, Serialize)]
+#[borsh(crate = "near_sdk::borsh")]
 #[serde(crate = "near_sdk::serde")]
 pub struct PriceFeed {
     /// Unique identifier for this price.
@@ -169,6 +171,7 @@ impl From<&PriceFeedMessage> for PriceFeed {
     PartialOrd,
     Serialize,
 )]
+#[borsh(crate = "near_sdk::borsh")]
 #[serde(crate = "near_sdk::serde")]
 #[repr(transparent)]
 pub struct Chain(u16);
@@ -204,6 +207,7 @@ impl From<Chain> for u16 {
     PartialOrd,
     Serialize,
 )]
+#[borsh(crate = "near_sdk::borsh")]
 #[serde(crate = "near_sdk::serde")]
 pub struct Source {
     pub emitter: WormholeAddress,

+ 82 - 86
target_chains/near/receiver/tests/workspaces.rs

@@ -1,5 +1,13 @@
 use {
-    near_sdk::json_types::U128,
+    near_sdk::json_types::{
+        I64,
+        U128,
+        U64,
+    },
+    near_workspaces::types::{
+        Gas,
+        NearToken,
+    },
     pyth::{
         governance::{
             GovernanceAction,
@@ -35,11 +43,11 @@ use {
 };
 
 async fn initialize_chain() -> (
-    workspaces::Worker<workspaces::network::Sandbox>,
-    workspaces::Contract,
-    workspaces::Contract,
+    near_workspaces::Worker<near_workspaces::network::Sandbox>,
+    near_workspaces::Contract,
+    near_workspaces::Contract,
 ) {
-    let worker = workspaces::sandbox().await.expect("Workspaces Failed");
+    let worker = near_workspaces::sandbox().await.expect("Workspaces Failed");
 
     // Deploy Pyth
     let contract = worker
@@ -59,8 +67,8 @@ async fn initialize_chain() -> (
     // Initialize Wormhole.
     let _ = wormhole
         .call("new")
-        .args_json(&json!({}))
-        .gas(300_000_000_000_000)
+        .args_json(json!({}))
+        .gas(Gas::from_gas(300_000_000_000_000))
         .transact_async()
         .await
         .expect("Failed to initialize Wormhole")
@@ -72,7 +80,7 @@ async fn initialize_chain() -> (
 
     let _ = contract
         .call("new")
-        .args_json(&json!({
+        .args_json(json!({
             "wormhole":        wormhole.id(),
             "codehash":        codehash,
             "initial_source":  Source {
@@ -86,7 +94,7 @@ async fn initialize_chain() -> (
             "update_fee":      U128::from(1u128),
             "stale_threshold": DEFAULT_VALID_TIME_PERIOD,
         }))
-        .gas(300_000_000_000_000)
+        .gas(Gas::from_gas(300_000_000_000_000))
         .transact_async()
         .await
         .expect("Failed to initialize Pyth")
@@ -132,9 +140,9 @@ async fn test_set_sources() {
 
     assert!(contract
         .call("execute_governance_instruction")
-        .gas(300_000_000_000_000)
-        .deposit(300_000_000_000_000_000_000_000)
-        .args_json(&json!({
+        .gas(Gas::from_gas(300_000_000_000_000))
+        .deposit(NearToken::from_yoctonear(300_000_000_000_000_000_000_000))
+        .args_json(json!({
             "vaa": vaa,
         }))
         .transact_async()
@@ -202,9 +210,9 @@ async fn test_set_governance_source() {
 
     assert!(contract
         .call("execute_governance_instruction")
-        .gas(300_000_000_000_000)
-        .deposit(300_000_000_000_000_000_000_000)
-        .args_json(&json!({
+        .gas(Gas::from_gas(300_000_000_000_000))
+        .deposit(NearToken::from_yoctonear(300_000_000_000_000_000_000_000))
+        .args_json(json!({
             "vaa": vaa,
         }))
         .transact()
@@ -246,9 +254,9 @@ async fn test_set_governance_source() {
 
     assert!(contract
         .call("execute_governance_instruction")
-        .gas(300_000_000_000_000)
-        .deposit(300_000_000_000_000_000_000_000)
-        .args_json(&json!({
+        .gas(Gas::from_gas(300_000_000_000_000))
+        .deposit(NearToken::from_yoctonear(300_000_000_000_000_000_000_000))
+        .args_json(json!({
             "vaa": vaa,
         }))
         .transact_async()
@@ -293,9 +301,9 @@ async fn test_set_governance_source() {
 
     assert!(contract
         .call("execute_governance_instruction")
-        .gas(300_000_000_000_000)
-        .deposit(300_000_000_000_000_000_000_000)
-        .args_json(&json!({
+        .gas(Gas::from_gas(300_000_000_000_000))
+        .deposit(NearToken::from_yoctonear(300_000_000_000_000_000_000_000))
+        .args_json(json!({
             "vaa": vaa,
         }))
         .transact_async()
@@ -349,24 +357,12 @@ async fn test_stale_threshold() {
     );
     let vaa = hex::encode(serde_wormhole::to_vec(&vaa).unwrap());
 
-    let update_fee = serde_json::from_slice::<U128>(
-        &contract
-            .view("get_update_fee_estimate")
-            .args_json(&json!({
-                "data": vaa,
-            }))
-            .await
-            .unwrap()
-            .result,
-    )
-    .unwrap();
-
     // Submit price. As there are no prices this should succeed despite being old.
     assert!(contract
         .call("update_price_feeds")
-        .gas(300_000_000_000_000)
-        .deposit(update_fee.into())
-        .args_json(&json!({
+        .gas(Gas::from_gas(300_000_000_000_000))
+        .deposit(NearToken::from_yoctonear(300_000_000_000_000_000_000_000))
+        .args_json(json!({
             "data": vaa,
         }))
         .transact_async()
@@ -384,7 +380,7 @@ async fn test_stale_threshold() {
         serde_json::from_slice::<Option<Price>>(
             &contract
                 .view("get_price")
-                .args_json(&json!({ "price_identifier": PriceIdentifier([0; 32]) }))
+                .args_json(json!({ "price_identifier": PriceIdentifier([0; 32]) }))
                 .await
                 .unwrap()
                 .result
@@ -397,7 +393,7 @@ async fn test_stale_threshold() {
         serde_json::from_slice::<HashMap<PriceIdentifier, Option<Price>>>(
             &contract
                 .view("list_prices")
-                .args_json(&json!({ "price_ids": vec![PriceIdentifier([0; 32])] }))
+                .args_json(json!({ "price_ids": vec![PriceIdentifier([0; 32])] }))
                 .await
                 .unwrap()
                 .result
@@ -441,9 +437,9 @@ async fn test_stale_threshold() {
     // The update handler should now succeed even if price is old, but simply not update the price.
     assert!(contract
         .call("update_price_feeds")
-        .gas(300_000_000_000_000)
-        .deposit(update_fee.into())
-        .args_json(&json!({
+        .gas(Gas::from_gas(300_000_000_000_000))
+        .deposit(NearToken::from_yoctonear(300_000_000_000_000_000_000_000))
+        .args_json(json!({
             "data": vaa,
         }))
         .transact_async()
@@ -466,7 +462,7 @@ async fn test_stale_threshold() {
         serde_json::from_slice::<Price>(
             &contract
                 .view("get_price_unsafe")
-                .args_json(&json!({ "price_identifier": PriceIdentifier([0; 32]) }))
+                .args_json(json!({ "price_identifier": PriceIdentifier([0; 32]) }))
                 .await
                 .unwrap()
                 .result
@@ -491,9 +487,9 @@ async fn test_stale_threshold() {
 
     assert!(contract
         .call("execute_governance_instruction")
-        .gas(300_000_000_000_000)
-        .deposit(300_000_000_000_000_000_000_000)
-        .args_json(&json!({
+        .gas(Gas::from_gas(300_000_000_000_000))
+        .deposit(NearToken::from_yoctonear(300_000_000_000_000_000_000_000))
+        .args_json(json!({
             "vaa": vaa,
         }))
         .transact_async()
@@ -516,7 +512,7 @@ async fn test_stale_threshold() {
         serde_json::from_slice::<Option<Price>>(
             &contract
                 .view("get_price")
-                .args_json(&json!({ "price_identifier": PriceIdentifier([0; 32]) }))
+                .args_json(json!({ "price_identifier": PriceIdentifier([0; 32]) }))
                 .await
                 .unwrap()
                 .result
@@ -533,7 +529,7 @@ async fn test_stale_threshold() {
         serde_json::from_slice::<HashMap<PriceIdentifier, Option<Price>>>(
             &contract
                 .view("list_prices")
-                .args_json(&json!({ "price_ids": vec![PriceIdentifier([0; 32])] }))
+                .args_json(json!({ "price_ids": vec![PriceIdentifier([0; 32])] }))
                 .await
                 .unwrap()
                 .result
@@ -572,7 +568,7 @@ async fn test_contract_fees() {
     let update_fee = serde_json::from_slice::<U128>(
         &contract
             .view("get_update_fee_estimate")
-            .args_json(&json!({
+            .args_json(json!({
                 "data": vaa,
             }))
             .await
@@ -584,9 +580,9 @@ async fn test_contract_fees() {
     // Now set the update_fee so that it is too high for the deposit to cover.
     assert!(contract
         .call("execute_governance_instruction")
-        .gas(300_000_000_000_000)
-        .deposit(300_000_000_000_000_000_000_000)
-        .args_json(&json!({
+        .gas(Gas::from_gas(300_000_000_000_000))
+        .deposit(NearToken::from_yoctonear(300_000_000_000_000_000_000_000))
+        .args_json(json!({
             "vaa": vaa,
         }))
         .transact_async()
@@ -604,7 +600,7 @@ async fn test_contract_fees() {
             serde_json::from_slice::<U128>(
                 &contract
                     .view("get_update_fee_estimate")
-                    .args_json(&json!({
+                    .args_json(json!({
                         "data": vaa,
                     }))
                     .await
@@ -647,9 +643,9 @@ async fn test_contract_fees() {
 
     assert!(contract
         .call("update_price_feeds")
-        .gas(300_000_000_000_000)
-        .deposit(update_fee.into())
-        .args_json(&json!({
+        .gas(Gas::from_gas(300_000_000_000_000))
+        .deposit(NearToken::from_yoctonear(update_fee.into()))
+        .args_json(json!({
             "data": vaa,
         }))
         .transact_async()
@@ -666,7 +662,7 @@ async fn test_contract_fees() {
         serde_json::from_slice::<Option<Price>>(
             &contract
                 .view("get_price")
-                .args_json(&json!({ "price_identifier": PriceIdentifier([0; 32]) }))
+                .args_json(json!({ "price_identifier": PriceIdentifier([0; 32]) }))
                 .await
                 .unwrap()
                 .result
@@ -700,9 +696,9 @@ async fn test_same_governance_sequence_fails() {
     // Attempt our first SetFee.
     assert!(contract
         .call("execute_governance_instruction")
-        .gas(300_000_000_000_000)
-        .deposit(300_000_000_000_000_000_000_000)
-        .args_json(&json!({
+        .gas(Gas::from_gas(300_000_000_000_000))
+        .deposit(NearToken::from_yoctonear(300_000_000_000_000_000_000_000))
+        .args_json(json!({
             "vaa": vaa,
         }))
         .transact_async()
@@ -716,9 +712,9 @@ async fn test_same_governance_sequence_fails() {
     // Attempt to run the same VAA again.
     assert!(!contract
         .call("execute_governance_instruction")
-        .gas(300_000_000_000_000)
-        .deposit(300_000_000_000_000_000_000_000)
-        .args_json(&json!({
+        .gas(Gas::from_gas(300_000_000_000_000))
+        .deposit(NearToken::from_yoctonear(300_000_000_000_000_000_000_000))
+        .args_json(json!({
             "vaa": vaa,
         }))
         .transact_async()
@@ -754,9 +750,9 @@ async fn test_out_of_order_sequences_fail() {
     // Attempt our first SetFee.
     assert!(contract
         .call("execute_governance_instruction")
-        .gas(300_000_000_000_000)
-        .deposit(300_000_000_000_000_000_000_000)
-        .args_json(&json!({
+        .gas(Gas::from_gas(300_000_000_000_000))
+        .deposit(NearToken::from_yoctonear(300_000_000_000_000_000_000_000))
+        .args_json(json!({
             "vaa": vaa,
         }))
         .transact_async()
@@ -785,9 +781,9 @@ async fn test_out_of_order_sequences_fail() {
     // This should succeed.
     assert!(contract
         .call("execute_governance_instruction")
-        .gas(300_000_000_000_000)
-        .deposit(300_000_000_000_000_000_000_000)
-        .args_json(&json!({
+        .gas(Gas::from_gas(300_000_000_000_000))
+        .deposit(NearToken::from_yoctonear(300_000_000_000_000_000_000_000))
+        .args_json(json!({
             "vaa": vaa,
         }))
         .transact_async()
@@ -816,9 +812,9 @@ async fn test_out_of_order_sequences_fail() {
     // This should fail due to being out of order.
     assert!(!contract
         .call("execute_governance_instruction")
-        .gas(300_000_000_000_000)
-        .deposit(300_000_000_000_000_000_000_000)
-        .args_json(&json!({
+        .gas(Gas::from_gas(300_000_000_000_000))
+        .deposit(NearToken::from_yoctonear(300_000_000_000_000_000_000_000))
+        .args_json(json!({
             "vaa": vaa,
         }))
         .transact_async()
@@ -853,9 +849,9 @@ async fn test_governance_target_fails_if_not_near() {
     // This should fail as the target is Solana, when Near is expected.
     assert!(!contract
         .call("execute_governance_instruction")
-        .gas(300_000_000_000_000)
-        .deposit(300_000_000_000_000_000_000_000)
-        .args_json(&json!({
+        .gas(Gas::from_gas(300_000_000_000_000))
+        .deposit(NearToken::from_yoctonear(300_000_000_000_000_000_000_000))
+        .args_json(json!({
             "vaa": vaa,
         }))
         .transact_async()
@@ -894,9 +890,9 @@ async fn test_accumulator_updates() {
 
     assert!(contract
         .call("execute_governance_instruction")
-        .gas(300_000_000_000_000)
-        .deposit(300_000_000_000_000_000_000_000)
-        .args_json(&json!({
+        .gas(Gas::from_gas(300_000_000_000_000))
+        .deposit(NearToken::from_yoctonear(300_000_000_000_000_000_000_000))
+        .args_json(json!({
             "vaa": vaa,
         }))
         .transact_async()
@@ -916,9 +912,9 @@ async fn test_accumulator_updates() {
     // Call the usual UpdatePriceFeed function.
     assert!(contract
         .call("update_price_feeds")
-        .gas(300_000_000_000_000)
-        .deposit(300_000_000_000_000_000_000_000)
-        .args_json(&json!({
+        .gas(Gas::from_gas(300_000_000_000_000))
+        .deposit(NearToken::from_yoctonear(300_000_000_000_000_000_000_000))
+        .args_json(json!({
             "data": message,
         }))
         .transact_async()
@@ -943,7 +939,7 @@ async fn test_accumulator_updates() {
         serde_json::from_slice::<Option<Price>>(
             &contract
                 .view("get_price_unsafe")
-                .args_json(&json!({ "price_identifier": PriceIdentifier(identifier) }))
+                .args_json(json!({ "price_identifier": PriceIdentifier(identifier) }))
                 .await
                 .unwrap()
                 .result
@@ -977,14 +973,13 @@ async fn test_sdk_compat() {
 #[tokio::test]
 async fn test_borsh_field_cmopat() {
     use near_sdk::borsh::{
-        self,
         BorshDeserialize,
         BorshSerialize,
     };
 
-    let price = pyth_sdk::Price {
-        price:        i64::MAX,
-        conf:         u64::MAX,
+    let price = Price {
+        price:        I64(i64::MAX),
+        conf:         U64(u64::MAX),
         expo:         100,
         publish_time: 100,
     };
@@ -992,6 +987,7 @@ async fn test_borsh_field_cmopat() {
     // Verify that we can still BorshDeserialize a struct with a different field name. Confirms
     // we don't have to migrate the state.
     #[derive(Eq, PartialEq, Debug, BorshSerialize, BorshDeserialize)]
+    #[borsh(crate = "near_sdk::borsh")]
     struct PriceTester {
         price:          i64,
         conf:           u64,
@@ -999,7 +995,7 @@ async fn test_borsh_field_cmopat() {
         bad_field_name: u64,
     }
 
-    let encoded = near_sdk::borsh::BorshSerialize::try_to_vec(&price).unwrap();
+    let encoded = near_sdk::borsh::to_vec(&price).unwrap();
     let decoded_price: PriceTester =
         near_sdk::borsh::BorshDeserialize::try_from_slice(&encoded).unwrap();
     assert_eq!(

+ 2 - 1
target_chains/near/receiver/workspace-test.sh

@@ -3,6 +3,7 @@
 # This script is used to prepare the environment in order to run the NEAR
 # workspaces based tests. It relies on the relative position of the wormhole-
 # stub contract to this directory.
+set -x
 set -euo pipefail
 
 # Setup rust to build wasm.
@@ -17,4 +18,4 @@ cp target/wasm32-unknown-unknown/release/pyth.wasm .
     cp target/wasm32-unknown-unknown/release/wormhole_stub.wasm ../receiver
 )
 
-RUST_LOG=info cargo nextest run
+RUST_LOG=info cargo test

+ 1 - 1
target_chains/near/rust-toolchain.toml

@@ -1,2 +1,2 @@
 [toolchain]
-channel = "1.69.0"
+channel = "1.79.0"

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 158 - 1028
target_chains/near/wormhole-stub/Cargo.lock


+ 1 - 1
target_chains/near/wormhole-stub/Cargo.toml

@@ -8,7 +8,7 @@ edition = "2021"
 crate-type = ["cdylib"]
 
 [dependencies]
-near-sdk     = { version = "4.1.1" }
+near-sdk     = { version = "5.5.0" }
 
 [profile.release]
 codegen-units   = 1

+ 1 - 1
target_chains/near/wormhole-stub/src/lib.rs

@@ -2,7 +2,6 @@
 
 use near_sdk::{
     borsh::{
-        self,
         BorshDeserialize,
         BorshSerialize,
     },
@@ -13,6 +12,7 @@ use near_sdk::{
 
 #[near_bindgen]
 #[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)]
+#[borsh(crate = "near_sdk::borsh")]
 pub struct State {}
 
 #[near_bindgen]

+ 0 - 6
wormhole_attester/rust-toolchain

@@ -1,6 +0,0 @@
-# This version should be kept up to date with the value in
-# ci/rust-version.sh in the branch of the solana repo that corresponds
-# with the version we're using.
-[toolchain]
-channel = "nightly-2022-12-24"
-profile = "minimal"

+ 2 - 0
wormhole_attester/rust-toolchain.toml

@@ -0,0 +1,2 @@
+[toolchain]
+channel = "1.79.0"

+ 1 - 2
wormhole_attester/sdk/rust/src/lib.rs

@@ -26,7 +26,6 @@ use {
         Serializer,
     },
     std::{
-        borrow::Borrow,
         convert::TryInto,
         io::Read,
         iter::Iterator,
@@ -159,7 +158,7 @@ impl BatchPriceAttestation {
         let mut serialized_attestations = Vec::with_capacity(self.price_attestations.len());
         for (idx, a) in self.price_attestations.iter().enumerate() {
             // Learn the current attestation's size
-            let serialized = PriceAttestation::serialize(a.borrow());
+            let serialized = PriceAttestation::serialize(a);
             let a_len = serialized.len();
 
             // Verify it's the same as the first one we saw for the batch, assign if we're first.

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä