Skip to content

Commit

Permalink
feat (GAS TOKEN FEE) adjust transaction fee to use GAS token
Browse files Browse the repository at this point in the history
  • Loading branch information
Widiskel committed Jun 3, 2024
1 parent 9a9146d commit 5e660d0
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 121 deletions.
191 changes: 106 additions & 85 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,101 +10,123 @@ async function doQuest(walletAddress, privateKey) {
await initia
.initiation(walletAddress, privateKey)
.then(async () => {
await initia
.queryBalance()
.then(async (initBalance) => {
console.log(`Account ${walletAddress} Information`);
console.log();
console.log("Doing daily routine for Account " + walletAddress);
if (initBalance.amount / 1000000 < 10) {
reject(
`Balance < 20 Initia for account ${walletAddress}, Please request initia token from faucet `
);
} else {
console.log(
"1. Send 1 Init to Other for Account" + walletAddress
);
await routine.sendOneInitToOther();
console.log();
await initia.checkGas().then(async (gasBalance) => {
if (gasBalance.amount / 100000 < 10) {
reject(
`Account ${walletAddress} GAS Token is not enough, min balance is 10 GAS`
);
} else {
await initia
.queryBalance()
.then(async (initBalance) => {
console.log(`Account ${walletAddress} Information`);
console.log();
console.log(
"Doing daily routine for Account " + walletAddress
);
if (initBalance.amount / 1000000 < 10) {
reject(
`Balance < 20 Initia for account ${walletAddress}, Please request initia token from faucet `
);
} else {
console.log(
"1. Send 1 Init to Other for Account" + walletAddress
);
await routine.sendOneInitToOther();
console.log();

console.log(
"2. Send 1 Init to Other (BLACKWING) for Account" +
walletAddress
);
await routine.sendOneInitToOtherLayer(
AppConstant.BridgeID.BLACKWING
);
console.log();
console.log(
"2. Send 1 Init to Other (BLACKWING) for Account" +
walletAddress
);
await routine.sendOneInitToOtherLayer(
AppConstant.BridgeID.BLACKWING
);
console.log();

console.log(
"3. Send 1 Init to Other (Noon) for Account" + walletAddress
);
await routine.sendOneInitToOtherLayer(
AppConstant.BridgeID.NOON
);
console.log();
console.log(
"3. Send 1 Init to Other (Noon) for Account" +
walletAddress
);
await routine.sendOneInitToOtherLayer(
AppConstant.BridgeID.NOON
);
console.log();

console.log(
"4. Send 1 Init to Other (TUCANA) for Account" + walletAddress
);
await routine.sendOneInitToOtherLayer(
AppConstant.BridgeID.TUCANA
);
console.log();
console.log(
"4. Send 1 Init to Other (TUCANA) for Account" +
walletAddress
);
await routine.sendOneInitToOtherLayer(
AppConstant.BridgeID.TUCANA
);
console.log();

console.log(
"5. Send 1 Init to Other (INIT AI) for Account" +
walletAddress
);
await routine.sendOneInitToOtherLayer(
AppConstant.BridgeID.INITAI
);
console.log();
console.log(
"5. Send 1 Init to Other (INIT AI) for Account" +
walletAddress
);
await routine.sendOneInitToOtherLayer(
AppConstant.BridgeID.INITAI
);
console.log();

console.log(
"6. Send 1 Init to Other (MINIMOVE) for Account" +
walletAddress
);
await routine.sendOneInitToOtherLayer(
AppConstant.BridgeID.MINIMOVE
);
console.log();
console.log(
"6. Send 1 Init to Other (MINIMOVE) for Account" +
walletAddress
);
await routine.sendOneInitToOtherLayer(
AppConstant.BridgeID.MINIMOVE
);
console.log();

console.log(
"7. Send 1 Init to Other (MINIWASM) for Account" +
walletAddress
);
await routine.sendOneInitToOtherLayer(
AppConstant.BridgeID.MINIWASM
);
console.log();
console.log(
"7. Send 1 Init to Other (MINIWASM) for Account" +
walletAddress
);
await routine.sendOneInitToOtherLayer(
AppConstant.BridgeID.MINIWASM
);
console.log();

console.log(
"8. Swap 1 INIT to USDC for Account" + walletAddress
);
await routine.swap();
console.log();
console.log(
"8. Send 1 Init to Other (CIVITA) for Account" +
walletAddress
);
await routine.sendOneInitToOtherLayer(
AppConstant.BridgeID.CIVITA
);
console.log();

console.log(
"9. Stake 0.1 INIT to Omninode Account" + walletAddress
);
await routine.stakeInit();
console.log();
console.log(
"9. Swap 1 INIT to USDC for Account" + walletAddress
);
await routine.swap();
console.log();

const tucana = new Tucana();
tucana.address = walletAddress;
console.log(
"10. Stake 0.1 INIT to Omninode Account" + walletAddress
);
await routine.stakeInit();
console.log();

console.log(
"10. Swap 1 INIT to USDC on TUCANA Account" + walletAddress
);
await tucana.swap();
console.log();
const tucana = new Tucana();
tucana.address = walletAddress;

routine.resetRoutine();
resolve(true);
}
})
.then((error) => reject(error));
console.log(
"11. Swap 1 INIT to USDC on TUCANA Account" +
walletAddress
);
await tucana.swap();
console.log();

routine.resetRoutine();
resolve(true);
}
})
.then((error) => reject(error));
}
});
})
.then((error) => reject(error));
} catch (error) {
Expand All @@ -115,7 +137,6 @@ async function doQuest(walletAddress, privateKey) {

(async () => {
try {
console.log(account.length)
account.forEach(async (account) => {
var walletAddress = account[0];
var privateKey = account[1];
Expand Down
82 changes: 81 additions & 1 deletion src/module/initia/initia.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function initiation(walletAddress, pk) {
key = new initia.RawKey(Uint8Array.from(privateKeyBytes));
lcd = new initia.LCDClient(`https://lcd.${chainId}.initia.xyz`, {
chainId: chainId,
gasPrices: minGasPrice + "uinit",
gasPrices: minGasPrice + AppConstant.GASTOKEN,
gasAdjustment: "2.0",
});
wallet = new initia.Wallet(lcd, key);
Expand Down Expand Up @@ -52,6 +52,28 @@ async function queryBalance() {
}
}

async function checkGas() {
try {
const balances = await lcd.bank.balance(address);
const coinList = Object.keys(balances[0]._coins);
coinList.forEach((coin) => {
console.log(
`${balances[0]._coins[coin].amount / 1000000} ${
balances[0]._coins[coin].denom == AppConstant.GASTOKEN
? "GAS"
: balances[0]._coins[coin].denom
}`
);
});

console.log();
return balances[0]._coins[AppConstant.GASTOKEN];
} catch (error) {
console.error("Error during checking balance:", error);
throw error;
}
}

async function claimExp() {
try {
console.log(address);
Expand Down Expand Up @@ -131,6 +153,63 @@ async function sendTokenDifferentLayer(bridgeId) {
}
}

async function mixed_route_swap_transfer(bridgeId) {
console.log("BRIDGE ID" + bridgeId);
try {
console.log(`Sending 1 init to ${AppConstant.RECEIVERTESTNETADDRESS}`);
const brigeArgs = [
initia.bcs
.address()
.serialize(AppConstant.INITIAMETADATAADDRESS)
.toBase64(),
"AA==",
initia.bcs.u64().serialize(1).toBase64(),
];
console.log(brigeArgs);
const initToInit = await lcd.move.viewFunction(
AppConstant.BRIDGEMODULEADDRESS,
"swap_transfer",
"mixed_route_swap_simulation",
[],
brigeArgs
);
console.log(initToInit);

const msg = new initia.MsgExecute();
msg.function_name = "mixed_route_swap_deposit";
msg.module_address = AppConstant.BRIDGEMODULEADDRESS;
msg.module_name = "swap_transfer";
msg.sender = address;
msg.args = [
initia.bcs
.address()
.serialize(AppConstant.INITIAMETADATAADDRESS)
.toBase64(),
"AA==",
initia.bcs.u64().serialize(1000000).toBase64(),
"AbguDwAAAAAA",
initia.bcs.u64().serialize(bridgeId).toBase64(),
initia.bcs.address().serialize(address).toBase64(),
"AA==",
];

console.log(AppConstant.getKey(bridgeId));
console.log(msg);

await signAndBroadcast(msg)
.then(() => {
console.log(
`Successfully Send 1 Init To ${AppConstant.RECEIVERTESTNETADDRESS} From Different Layer`
);
})
.catch((err) => {
throw err;
});
} catch (error) {
throw error;
}
}

async function swap() {
try {
console.log(
Expand Down Expand Up @@ -293,5 +372,6 @@ export {
stakeInit,
sendTokenDifferentLayer,
signAndBroadcast,
checkGas,
lcd,
};
Loading

0 comments on commit 5e660d0

Please sign in to comment.