Skip to content

Commit 0727aa3

Browse files
authored
Implement setter functions on aptos (#978)
1 parent 31ad2b6 commit 0727aa3

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

contract_manager/src/contracts/aptos.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Contract, PriceFeed } from "../base";
2+
import { AptosAccount, BCS, TxnBuilderTypes } from "aptos";
23
import { AptosChain, Chain } from "../chains";
34
import { DataSource } from "xc_admin_common";
45

@@ -28,11 +29,47 @@ export class AptosContract extends Contract {
2829
return new AptosContract(chain, parsed.stateId, parsed.wormholeStateId);
2930
}
3031

31-
executeGovernanceInstruction(
32+
async executeGovernanceInstruction(
3233
senderPrivateKey: string,
3334
vaa: Buffer
3435
): 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);
3673
}
3774

3875
getStateResources() {

0 commit comments

Comments
 (0)