Skip to content

Commit

Permalink
[Sui 19/x] - sui contract manager additions (pyth-network#953)
Browse files Browse the repository at this point in the history
* getSetDataSourcesPayload, getSetStalePriceThresholdPayload

* use parent functions for SuiChain
  • Loading branch information
optke3 authored Aug 1, 2023
1 parent ce66a36 commit c890d35
Showing 1 changed file with 15 additions and 40 deletions.
55 changes: 15 additions & 40 deletions contract_manager/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
AptosAuthorizeUpgradeContract,
toChainId,
SetDataSources,
SetValidPeriod,
DataSource,
} from "xc_admin_common";
import { AptosClient } from "aptos";
Expand Down Expand Up @@ -66,6 +67,19 @@ export abstract class Chain extends Storable {
return new SetDataSources(this.wormholeChainName, datasources).encode();
}

/**
* Returns the payload for a governance SetStalePriceThreshold instruction for contracts deployed on this chain
* @param newValidStalePriceThreshold the new stale price threshold in seconds
*/
generateGovernanceSetStalePriceThreshold(
newValidStalePriceThreshold: bigint
): Buffer {
return new SetValidPeriod(
this.wormholeChainName,
newValidStalePriceThreshold
).encode();
}

/**
* Returns the payload for a governance contract upgrade instruction for contracts deployed on this chain
* @param upgradeInfo based on the contract type, this can be a contract address, codeId, package digest, etc.
Expand Down Expand Up @@ -192,54 +206,15 @@ export class SuiChain extends Chain {
return SuiChain.type;
}

//TODO: Move this logic to xc_admin_common
private wrapWithWormholeGovernancePayload(
actionVariant: number,
payload: Buffer
): Buffer {
const actionVariantBuffer = Buffer.alloc(1);
actionVariantBuffer.writeUint8(actionVariant, 0);
const chainBuffer = Buffer.alloc(2);
chainBuffer.writeUint16BE(CHAINS["sui"], 0);
const result = Buffer.concat([
Buffer.from(
"0000000000000000000000000000000000000000000000000000000000000001",
"hex"
),
actionVariantBuffer,
chainBuffer,
payload,
]);
return result;
}

/**
* Returns the payload for a governance contract upgrade instruction for contracts deployed on this chain
* @param digest hex string of the 32 byte digest for the new package without the 0x prefix
*/
generateGovernanceUpgradePayload(digest: string): Buffer {
const upgrade = new SuiAuthorizeUpgradeContract(
return new SuiAuthorizeUpgradeContract(
this.wormholeChainName,
digest
).encode();
return this.wrapWithWormholeGovernancePayload(0, upgrade);
}

generateGovernanceSetFeePayload(fee: number, exponent: number): Buffer {
const setFee = new SetFee(
this.wormholeChainName,
BigInt(fee),
BigInt(exponent)
).encode();
return this.wrapWithWormholeGovernancePayload(3, setFee);
}

generateGovernanceSetDataSources(datasources: DataSource[]): Buffer {
const setDataSource = new SetDataSources(
this.wormholeChainName,
datasources
).encode();
return this.wrapWithWormholeGovernancePayload(2, setDataSource);
}
}

Expand Down

0 comments on commit c890d35

Please sign in to comment.