Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tasks/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// import "./retrySend"
import "./retrySend"
import "./setUxpTrustedRemote"
import "./sendUxpCrossChain"
import "./setUxdTrustedRemote"
Expand Down
49 changes: 49 additions & 0 deletions tasks/retrySend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { task } from "hardhat/config";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { loadConfig, loadCoreContracts } from "../scripts/common/loaders";
import { UXDToken } from "../typechain-types";

task("retrySend", "Retries sending UXD tokens cross chain")
.addParam("srcchain", "source chain")
.addParam("nonce", "message nonce")
.addOptionalParam("to", "target address")
.addOptionalParam("from", "original message sender")
.addOptionalParam("amount", "amount to send in")
.setAction(async (taskArgs, hre: HardhatRuntimeEnvironment) => {
const sender = taskArgs.from || (await hre.ethers.getSigners())[0].address;
const amount = taskArgs.amount || "1.0";
const recipient = taskArgs.to || sender;
const nonce = taskArgs.nonce || 1
await retryMessage(taskArgs.srcchain, recipient, amount, nonce, hre);
});

async function retryMessage(srcChain: string, recipient: string, amount: string, nonce: string, hre: HardhatRuntimeEnvironment) {
const dstCoreContracts = await loadCoreContracts(hre);
const srcCoreContracts = await loadCoreContracts(hre, srcChain);
const srcConfig = await loadConfig(hre, srcChain);
const UXD = await hre.ethers.getContractFactory("UXDToken");
const dstUxd: UXDToken = UXD.attach(dstCoreContracts.uxd) as UXDToken;
const srcPath = hre.ethers.utils.solidityPack(["address", "address"], [srcCoreContracts.uxd, dstCoreContracts.uxd])
const sender = (await hre.ethers.getSigners())[0].address;

const amountWei = hre.ethers.utils.parseEther(amount);
const recipientBytes32 = hre.ethers.utils.defaultAbiCoder.encode(["address"], [recipient])
const senderBytes32 = hre.ethers.utils.defaultAbiCoder.encode(["address"], [sender])
const payloadForCall = hre.ethers.utils.defaultAbiCoder.encode(["uint8", "bytes"], [1, recipient]);

console.log(`payloadForCall = ${payloadForCall}`)
const payload = hre.ethers.utils.solidityPack(
["uint8", "bytes32", "uint64", "bytes32", "uint64", "bytes"],
[1, recipientBytes32, amountWei, senderBytes32, 3000000, payloadForCall]
)

console.log(`payload = ${payload}`)
const tx = await (await dstUxd.retryMessage(
srcConfig.layerZero.current.chainId,
srcPath,
nonce,
payload,
)).wait()

console.log(`retry send UXD on ${hre.network.name} uxd = ${dstCoreContracts.uxd}] tx = ${tx.transactionHash}`);
}