Explorar o código

feat(target_chains/fuel): use saturating sub (#2031)

* use saturating sub

* update fuel version

* commit release binary file

* update fuel sdk version

* update pnpm lock

* precommit
Daniel Chew hai 1 ano
pai
achega
4ab64d2539

+ 1 - 1
apps/price_pusher/config.fuel.testnet.sample.json

@@ -1,6 +1,6 @@
 {
   "endpoint": "https://testnet.fuel.network/v1/graphql",
-  "pyth-contract-address": "0xe31e04946c67fb41923f93d50ee7fc1c6c99d6e07c02860c6bea5f4a13919277",
+  "pyth-contract-address": "0x25146735b29d4216639f7f8b1d7b921ff87a1d3051de62d6cceaacabeb33b8e7",
   "price-service-endpoint": "https://hermes.pyth.network",
   "private-key-file": "./mnemonic",
   "price-config-file": "./price-config.stable.sample.yaml"

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 428 - 53
pnpm-lock.yaml


+ 2 - 2
target_chains/fuel/contracts/Forc.lock

@@ -1,6 +1,6 @@
 [[package]]
 name = "core"
-source = "path+from-root-4BB20845430AF9CF"
+source = "path+from-root-8357A6DDC5F39D14"
 
 [[package]]
 name = "pyth-contract"
@@ -32,7 +32,7 @@ dependencies = ["std"]
 
 [[package]]
 name = "std"
-source = "git+https://github.com/fuellabs/sway?tag=v0.63.5#31a1d6f98395f571cd3674b492d9bf4773c55f65"
+source = "git+https://github.com/fuellabs/sway?tag=v0.65.2#66bb430395daf5b8f7205f7b9d8d008e2e812d54"
 dependencies = ["core"]
 
 [[package]]

+ 2 - 2
target_chains/fuel/contracts/fuel-toolchain.toml

@@ -2,5 +2,5 @@
 channel = "latest-aarch64-apple-darwin"
 
 [components]
-forc = "0.63.5"
-fuel-core = "0.35.0"
+forc = "0.65.2"
+fuel-core = "0.37.1"

+ 1 - 5
target_chains/fuel/contracts/pyth-contract/out/release/pyth-contract-abi.json

@@ -266,10 +266,6 @@
           "name": "FeesCanOnlyBePaidInTheBaseAsset",
           "typeId": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d"
         },
-        {
-          "name": "FuturePriceNotAllowed",
-          "typeId": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d"
-        },
         {
           "name": "GuardianSetNotFound",
           "typeId": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d"
@@ -1535,7 +1531,7 @@
     {
       "name": "DEPLOYER",
       "concreteTypeId": "ab7cd04e05be58e3fc15d424c2c4a57f824a2a2d97d67252440a3925ebdc1335",
-      "offset": 132984
+      "offset": 133088
     }
   ]
 }

BIN=BIN
target_chains/fuel/contracts/pyth-contract/out/release/pyth-contract.bin


+ 7 - 4
target_chains/fuel/contracts/pyth-contract/src/main.sw

@@ -331,10 +331,13 @@ fn ema_price_unsafe(price_feed_id: PriceFeedId) -> Price {
 fn price_no_older_than(time_period: u64, price_feed_id: PriceFeedId) -> Price {
     let price = price_unsafe(price_feed_id);
     let current_time = timestamp();
-    require(
-        current_time - price.publish_time <= time_period,
-        PythError::OutdatedPrice,
-    );
+    // Mimicking saturating subtraction to avoid underflow
+    let time_difference = if current_time > price.publish_time {
+        current_time - price.publish_time
+    } else {
+        0
+    };
+    require(time_difference <= time_period, PythError::OutdatedPrice);
 
     price
 }

+ 0 - 5
target_chains/fuel/contracts/pyth-interface/src/data_structures/price.sw

@@ -175,11 +175,6 @@ impl PriceFeed {
         //convert publish_time from UNIX to TAI64
         publish_time += TAI64_DIFFERENCE;
 
-        require(
-            publish_time <= timestamp(),
-            PythError::FuturePriceNotAllowed,
-        );
-
         PriceFeed::new(
             Price::new(ema_confidence, exponent, ema_price, publish_time),
             price_feed_id,

+ 0 - 1
target_chains/fuel/contracts/pyth-interface/src/errors.sw

@@ -2,7 +2,6 @@ library;
 
 pub enum PythError {
     FeesCanOnlyBePaidInTheBaseAsset: (),
-    FuturePriceNotAllowed: (),
     GuardianSetNotFound: (),
     IncorrectMessageType: (),
     InsufficientFee: (),

+ 2 - 2
target_chains/fuel/sdk/js/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@pythnetwork/pyth-fuel-js",
-  "version": "1.0.6",
+  "version": "1.0.7",
   "description": "Pyth Network Fuel Utils in JS",
   "homepage": "https://pyth.network",
   "author": {
@@ -45,6 +45,6 @@
     "typescript": "^5.4.5"
   },
   "dependencies": {
-    "fuels": "^0.94.5"
+    "fuels": "^0.96.1"
   }
 }

+ 1 - 5
target_chains/fuel/sdk/js/src/abi/pyth-contract-abi.json

@@ -266,10 +266,6 @@
           "name": "FeesCanOnlyBePaidInTheBaseAsset",
           "typeId": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d"
         },
-        {
-          "name": "FuturePriceNotAllowed",
-          "typeId": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d"
-        },
         {
           "name": "GuardianSetNotFound",
           "typeId": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d"
@@ -1535,7 +1531,7 @@
     {
       "name": "DEPLOYER",
       "concreteTypeId": "ab7cd04e05be58e3fc15d424c2c4a57f824a2a2d97d67252440a3925ebdc1335",
-      "offset": 132984
+      "offset": 133088
     }
   ]
 }

+ 5 - 1
target_chains/fuel/sdk/js/src/index.ts

@@ -2,7 +2,11 @@ import PYTH_CONTRACT_ABI from "./abi/pyth-contract-abi.json";
 
 /** Address of the Pyth contract on Fuel Sepolia (testnet). */
 export const PYTH_CONTRACT_ADDRESS_SEPOLIA =
-  "0xe31e04946c67fb41923f93d50ee7fc1c6c99d6e07c02860c6bea5f4a13919277";
+  "0x25146735b29d4216639f7f8b1d7b921ff87a1d3051de62d6cceaacabeb33b8e7";
+
+/** Address of the Pyth contract on Fuel Mainnet. */
+export const PYTH_CONTRACT_ADDRESS_MAINNET =
+  "0x1c86fdd9e0e7bc0d2ae1bf6817ef4834ffa7247655701ee1b031b52a24c523da";
 
 /** Asset ID of ETH on Fuel. */
 export const FUEL_ETH_ASSET_ID =

+ 3 - 9
target_chains/fuel/sdk/js/src/types/PythContract.ts

@@ -5,7 +5,7 @@
 /* eslint-disable @typescript-eslint/consistent-type-imports */
 
 /*
-  Fuels version: 0.94.5
+  Fuels version: 0.96.1
 */
 
 import { Contract, Interface } from "fuels";
@@ -78,7 +78,6 @@ export enum InitializationErrorOutput {
 }
 export enum PythErrorInput {
   FeesCanOnlyBePaidInTheBaseAsset = "FeesCanOnlyBePaidInTheBaseAsset",
-  FuturePriceNotAllowed = "FuturePriceNotAllowed",
   GuardianSetNotFound = "GuardianSetNotFound",
   IncorrectMessageType = "IncorrectMessageType",
   InsufficientFee = "InsufficientFee",
@@ -115,7 +114,6 @@ export enum PythErrorInput {
 }
 export enum PythErrorOutput {
   FeesCanOnlyBePaidInTheBaseAsset = "FeesCanOnlyBePaidInTheBaseAsset",
-  FuturePriceNotAllowed = "FuturePriceNotAllowed",
   GuardianSetNotFound = "GuardianSetNotFound",
   IncorrectMessageType = "IncorrectMessageType",
   InsufficientFee = "InsufficientFee",
@@ -673,11 +671,6 @@ const abi = {
           typeId:
             "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d",
         },
-        {
-          name: "FuturePriceNotAllowed",
-          typeId:
-            "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d",
-        },
         {
           name: "GuardianSetNotFound",
           typeId:
@@ -2123,7 +2116,7 @@ const abi = {
       name: "DEPLOYER",
       concreteTypeId:
         "ab7cd04e05be58e3fc15d424c2c4a57f824a2a2d97d67252440a3925ebdc1335",
-      offset: 132984,
+      offset: 133088,
     },
   ],
 };
@@ -2178,6 +2171,7 @@ const storageSlots: StorageSlot[] = [
     value: "0000000000000000000000000000000000000000000000000000000000000000",
   },
 ];
+
 export class PythContractInterface extends Interface {
   constructor() {
     super(abi);

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 2 - 2
target_chains/fuel/sdk/js/src/types/PythContractFactory.ts


+ 1 - 1
target_chains/fuel/sdk/js/src/types/common.d.ts

@@ -5,7 +5,7 @@
 /* eslint-disable @typescript-eslint/consistent-type-imports */
 
 /*
-  Fuels version: 0.94.5
+  Fuels version: 0.96.1
 */
 
 /**

+ 1 - 1
target_chains/fuel/sdk/js/src/types/index.ts

@@ -5,7 +5,7 @@
 /* eslint-disable @typescript-eslint/consistent-type-imports */
 
 /*
-  Fuels version: 0.94.5
+  Fuels version: 0.96.1
 */
 
 export { PythContract } from "./PythContract";

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio