|
1 | 1 | import { Contract, PriceFeed } from "../base";
|
| 2 | +import { AptosAccount, BCS, TxnBuilderTypes } from "aptos"; |
2 | 3 | import { AptosChain, Chain } from "../chains";
|
3 | 4 | import { DataSource } from "xc_admin_common";
|
4 | 5 |
|
@@ -28,11 +29,47 @@ export class AptosContract extends Contract {
|
28 | 29 | return new AptosContract(chain, parsed.stateId, parsed.wormholeStateId);
|
29 | 30 | }
|
30 | 31 |
|
31 |
| - executeGovernanceInstruction( |
| 32 | + async executeGovernanceInstruction( |
32 | 33 | senderPrivateKey: string,
|
33 | 34 | vaa: Buffer
|
34 | 35 | ): Promise<any> {
|
35 |
| - throw new Error("Method not implemented."); |
| 36 | + const txPayload = new TxnBuilderTypes.TransactionPayloadEntryFunction( |
| 37 | + TxnBuilderTypes.EntryFunction.natural( |
| 38 | + `${this.stateId}::governance`, |
| 39 | + "execute_governance_instruction", |
| 40 | + [], |
| 41 | + [BCS.bcsSerializeBytes(vaa)] |
| 42 | + ) |
| 43 | + ); |
| 44 | + return this.sendTransaction(senderPrivateKey, txPayload); |
| 45 | + } |
| 46 | + |
| 47 | + private sendTransaction( |
| 48 | + senderPrivateKey: string, |
| 49 | + txPayload: TxnBuilderTypes.TransactionPayloadEntryFunction |
| 50 | + ) { |
| 51 | + const client = this.chain.getClient(); |
| 52 | + const sender = new AptosAccount( |
| 53 | + new Uint8Array(Buffer.from(senderPrivateKey, "hex")) |
| 54 | + ); |
| 55 | + return client.generateSignSubmitWaitForTransaction(sender, txPayload, { |
| 56 | + maxGasAmount: BigInt(30000), |
| 57 | + }); |
| 58 | + } |
| 59 | + |
| 60 | + async executeUpdatePriceFeed( |
| 61 | + senderPrivateKey: string, |
| 62 | + vaas: Buffer[] |
| 63 | + ): Promise<any> { |
| 64 | + const txPayload = new TxnBuilderTypes.TransactionPayloadEntryFunction( |
| 65 | + TxnBuilderTypes.EntryFunction.natural( |
| 66 | + `${this.stateId}::pyth`, |
| 67 | + "update_price_feeds_with_funder", |
| 68 | + [], |
| 69 | + [BCS.serializeVectorWithFunc(vaas, "serializeBytes")] |
| 70 | + ) |
| 71 | + ); |
| 72 | + return this.sendTransaction(senderPrivateKey, txPayload); |
36 | 73 | }
|
37 | 74 |
|
38 | 75 | getStateResources() {
|
|
0 commit comments