Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into changeset-release/main
Browse files Browse the repository at this point in the history
  • Loading branch information
Foivos committed Dec 19, 2024
2 parents 2dee23d + ee155fd commit e9f95fd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-bobcats-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@axelar-network/axelar-cgp-sui': patch
---

Fix publish template interchain token
7 changes: 6 additions & 1 deletion src/node/node-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,22 @@ export function getContractBuild(packageName: string, moveDir: string): { module
export function writeInterchainToken(moveDir: string, options: InterchainTokenOptions) {
const templateFilePath = `${moveDir}/interchain_token/sources/interchain_token.move`;

const templateContent = fs.readFileSync(templateFilePath, 'utf8');
const { filePath, content } = newInterchainToken(templateFilePath, options);

fs.writeFileSync(filePath, content, 'utf8');

return filePath;
return { templateFilePath, filePath, templateContent };
}

export function removeFile(filePath: string) {
fs.rmSync(filePath);
}

export function addFile(filePath: string, content: string) {
fs.writeFileSync(filePath, content, 'utf8');
}

export function updateMoveToml(
packageName: string,
packageId: string,
Expand Down
22 changes: 14 additions & 8 deletions src/node/tx-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TransactionResult } from '@mysten/sui/transactions';
import { Bytes } from 'ethers';
import { TxBuilderBase } from '../common/tx-builder-base';
import { InterchainTokenOptions } from '../common/types';
import { getContractBuild as getMoveContractBuild, removeFile, writeInterchainToken } from './node-utils';
import { addFile, getContractBuild as getMoveContractBuild, removeFile, writeInterchainToken } from './node-utils';

export class TxBuilder extends TxBuilderBase {
getContractBuild(
Expand All @@ -13,13 +13,19 @@ export class TxBuilder extends TxBuilderBase {
}

async publishInterchainToken(moveDir: string, options: InterchainTokenOptions) {
const filePath = writeInterchainToken(moveDir, options);

const publishReceipt = await this.publishPackage('interchain_token', moveDir);

removeFile(filePath);

return publishReceipt;
const { filePath, templateContent, templateFilePath } = writeInterchainToken(moveDir, options);

try {
// temporarily remove the template module to avoid publishing it unnecessarily
removeFile(templateFilePath);

return await this.publishPackage('interchain_token', moveDir);
} finally {
// remove the created module
removeFile(filePath);
// restore the template module
addFile(templateFilePath, templateContent);
}
}

async publishPackage(packageName: string, moveDir: string = `${__dirname}/../../move`): Promise<TransactionResult> {
Expand Down

0 comments on commit e9f95fd

Please sign in to comment.