Skip to content

Instantly share code, notes, and snippets.

@luchenqun
Created April 19, 2024 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luchenqun/847527405a6edf8b738736feb533866f to your computer and use it in GitHub Desktop.
Save luchenqun/847527405a6edf8b738736feb533866f to your computer and use it in GitHub Desktop.
axl
import { DirectSecp256k1HdWallet, DirectSecp256k1Wallet } from '@cosmjs/proto-signing';
import { SigningStargateClient } from '@cosmjs/stargate';
import { fromHex } from '@cosmjs/encoding';
// 大概操作
// 1、请在至少在解质押结束前30秒启动脚本。没必要启动太早,启动太早如果节点做了请求限制则节点会不在接受访问请求
// 2、根据你的需求修改下面的 mnemonic 以及 recipient
// 3、安装好node.js程序之后,执行 node axl.js脚本
// 策略:每隔100ms检查到账户是否有可转移资金,一旦检测到立即发送转账交易。
// 再过60s检查资金是否转移到指定地址,如果是则退出程序
// 根据你自己的实际情况修改如下两个参数,其他的都不需要修改
const mnemonic = 'never guilt lazy slush roof inner foster torch yellow rare camera desert retire wealth lady tag only yellow outside fit priority you clock notable';
const recipient = 'axelar14jcgsf4fulm8phpy37lp35cup3cdx50v9ntqxv';
const gap = 100; // 程序运行间隔
const prefix = 'axelar';
const denom = 'uaxl';
const gas = '100000';
const gasAmount = '10000';
const wallet = mnemonic.indexOf(' ') > 0 ? await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, { prefix }) : await DirectSecp256k1Wallet.fromKey(fromHex(mnemonic.replace('0x', '')), prefix);
const [account] = await wallet.getAccounts();
const originAddress = account.address;
const rpcList = [
'https://rpc-axelar.imperator.co:443',
'https://axelar-rpc.polkachu.com',
'https://axelar-rpc.publicnode.com:443',
'https://tm.axelar.lava.build:443',
'https://rpc-axelar.imperator.co:443',
'https://axelar-rpc.quickapi.com:443',
'https://axelar-rpc.pops.one:443',
'https://axelar-rpc.chainode.tech:443',
'https://axelar-rpc.staketab.org:443',
'https://axelar.rpc.stake2.me:443',
'https://axelar-rpc.qubelabs.io:443',
'https://axelar-rpc.quantnode.tech:443',
'https://axelar-rpc.polkachu.com:443',
'https://axelar-rpc.4sv.io:443',
'https://axelar-rpc.validatrium.club:443',
];
const fee = {
amount: [
{
denom,
amount: gasAmount,
},
],
gas,
};
const main = async () => {
console.log('begin run...');
let transferAmount = -1;
let hasCheck = false;
setInterval(async () => {
for (const rpc of rpcList) {
try {
const client = await SigningStargateClient.connectWithSigner(rpc, wallet);
if (transferAmount < 0) {
const { amount } = await client.getBalance(originAddress, denom);
console.log('amount', rpc, amount);
transferAmount = parseInt(amount) - parseInt(gasAmount);
}
if (transferAmount > 0) {
console.log('undelegate is end, begin transfer...');
const token = {
denom,
amount: String(transferAmount),
};
client.sendTokens(account.address, recipient, [token], fee, 'luke');
setTimeout(async () => {
if (!hasCheck) {
const { amount } = await client.getBalance(recipient, denom);
if (parseInt(amount) > transferAmount) {
console.log('\n\n\nsuccessfully transferring funds to the designated address.');
process.exit(0);
}
hasCheck = true;
}
}, 60 * 1000); // 60秒之后检查一下
} else {
console.log('undelegate not end:', new Date().toLocaleTimeString());
}
} catch (error) {
console.log('err rpc request:', rpc);
}
}
}, gap);
};
main();
process
.on('unhandledRejection', (reason, p) => {
console.log(reason?.log || reason?.toString());
})
.on('uncaughtException', (err) => {
console.error(err, 'Uncaught Exception thrown');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment