Skip to content

Commit

Permalink
refactor: return plain transaction to avoid signer to be passing in
Browse files Browse the repository at this point in the history
  • Loading branch information
npty committed Nov 7, 2024
1 parent bd09171 commit db8d36a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
23 changes: 4 additions & 19 deletions src/libs/TransactionRecoveryApi/AxelarGMPRecoveryAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,9 @@ export type AddGasParams = {

export type AddGasSuiParams = {
amount?: string;
refundAddress?: string;
refundAddress: string;
messageId: string;
gasParams: string;
rpcUrl?: string;
suiSigner: SuiSigner;
};

export type AddGasResponse = {
Expand Down Expand Up @@ -873,22 +871,17 @@ export class AxelarGMPRecoveryAPI extends AxelarRecoveryApi {
}
}

public async addGasToSuiChain(params: AddGasSuiParams): Promise<SuiTransactionBlockResponse> {
const { amount, messageId, gasParams, suiSigner } = params;
public async addGasToSuiChain(params: AddGasSuiParams): Promise<Transaction> {
const { amount, messageId, gasParams, refundAddress } = params;
const chains = await importS3Config(this.environment);
const suiKey = Object.keys(chains.chains).find((chainName) => chainName.includes("sui"));

if (!suiKey) throw new Error("Cannot find sui chain config");

const suiConfig = chains.chains[suiKey];
const gasServiceContract = suiConfig.contracts.GasService;
const suiRpcUrl = params.rpcUrl || suiConfig.rpc;
const suiClient = new SuiClient({
url: suiRpcUrl,
});

const gasAmount = amount ? BigInt(amount) : parseUnits("0.01", 9).toBigInt();
const refundAddress = params.refundAddress || suiSigner.toSuiAddress();

const tx = new Transaction();

Expand All @@ -905,15 +898,7 @@ export class AxelarGMPRecoveryAPI extends AxelarRecoveryApi {
],
});

return suiClient.signAndExecuteTransaction({
transaction: tx,
signer: suiSigner,
options: {
showEffects: true,
showEvents: true,
showObjectChanges: true,
},
});
return tx;
}

public async addGasToCosmosChain({
Expand Down
17 changes: 13 additions & 4 deletions src/libs/test/TransactionRecoveryAPI/AxelarGMPRecoveryAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ describe("AxelarGMPRecoveryAPI", () => {
const testRpcUrl = "https://sui-testnet-rpc.publicnode.com";
const api: AxelarGMPRecoveryAPI = new AxelarGMPRecoveryAPI({ environment: Environment.DEVNET });
const suiClient = new SuiClient({
url: getFullnodeUrl(network),
url: testRpcUrl,
});
const keypair: Secp256k1Keypair = Secp256k1Keypair.deriveKeypair(
"test test test test test test test test test test test junk"
Expand All @@ -1174,11 +1174,20 @@ describe("AxelarGMPRecoveryAPI", () => {
}, 15000);

test("addGasToSuiChain should work given valid params", async () => {
const response = await api.addGasToSuiChain({
const tx = await api.addGasToSuiChain({
gasParams: "0x",
messageId: "test-1",
suiSigner: keypair,
rpcUrl: testRpcUrl,
refundAddress: keypair.toSuiAddress(),
});

const response = await suiClient.signAndExecuteTransaction({
transaction: tx,
signer: keypair,
options: {
showEffects: true,
showEvents: true,
showObjectChanges: true,
},
});

expect(response.events).toBeDefined();
Expand Down

0 comments on commit db8d36a

Please sign in to comment.