Ver código fonte

feat: refactor WithdrawFee to use value and expo for amount calculation

Daniel Chew 7 meses atrás
pai
commit
2a45ef9acf

+ 5 - 3
governance/xc_admin/packages/xc_admin_common/src/__tests__/GovernancePayload.test.ts

@@ -436,13 +436,15 @@ function governanceActionArb(): Arbitrary<PythGovernanceAction> {
       return fc
         .record({
           targetAddress: hexBytesArb({ minLength: 20, maxLength: 20 }),
-          amount: fc.bigUintN(256),
+          value: fc.bigUintN(64),
+          expo: fc.bigUintN(64),
         })
-        .map(({ targetAddress, amount }) => {
+        .map(({ targetAddress, value, expo }) => {
           return new WithdrawFee(
             header.targetChainId,
             Buffer.from(targetAddress, "hex"),
-            amount,
+            value,
+            expo,
           );
         });
     } else {

+ 9 - 5
governance/xc_admin/packages/xc_admin_common/src/governance_payload/WithdrawFee.ts

@@ -9,16 +9,18 @@ import { ChainName } from "../chains";
 /** Withdraw fees from the target chain to the specified address */
 export class WithdrawFee extends PythGovernanceActionImpl {
   static layout: BufferLayout.Structure<
-    Readonly<{ targetAddress: string; amount: bigint }>
+    Readonly<{ targetAddress: string; value: bigint; expo: bigint }>
   > = BufferLayout.struct([
     BufferLayoutExt.hexBytes(20, "targetAddress"), // Ethereum address as hex string
-    BufferLayoutExt.u256be("amount"), // uint256 for amount in wei
+    BufferLayoutExt.u64be("value"), // uint64 for value
+    BufferLayoutExt.u64be("expo"), // uint64 for exponent
   ]);
 
   constructor(
     targetChainId: ChainName,
     readonly targetAddress: Buffer,
-    readonly amount: bigint,
+    readonly value: bigint,
+    readonly expo: bigint,
   ) {
     super(targetChainId, "WithdrawFee");
   }
@@ -34,14 +36,16 @@ export class WithdrawFee extends PythGovernanceActionImpl {
     return new WithdrawFee(
       decoded[0].targetChainId,
       Buffer.from(decoded[1].targetAddress, "hex"),
-      decoded[1].amount,
+      decoded[1].value,
+      decoded[1].expo,
     );
   }
 
   encode(): Buffer {
     return super.encodeWithPayload(WithdrawFee.layout, {
       targetAddress: this.targetAddress.toString("hex"),
-      amount: this.amount,
+      value: this.value,
+      expo: this.expo,
     });
   }
 }