Skip to content

Commit

Permalink
Fix register issue (#6)
Browse files Browse the repository at this point in the history
* try fix cast issue

* verbose

* only support --verbose
  • Loading branch information
fewensa authored Apr 11, 2024
1 parent f2e5ae0 commit ec6ecbe
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ helixbridge
[--encrypted-private-key=your_encrypted_private_key]
`;

if (arg.option('verbose')) {
$.verbose = true;
}

async function main() {
const options = await initialize.init(BIN_PATH);

Expand Down
21 changes: 17 additions & 4 deletions src/register/lnv2_default.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,32 @@ export async function register(options) {

const _sourceChainId = await $`cast chain-id --rpc-url=${lifecycle.sourceChainRpc}`;
const _targetChainId = await $`cast chain-id --rpc-url=${lifecycle.targetChainRpc}`;
const _sourceTokenDecimal = await $`cast call --rpc-url=${lifecycle.sourceChainRpc} ${register.sourceTokenAddress} 'decimals()()'`;
const _targetTokenDecimal = await $`cast call --rpc-url=${lifecycle.targetChainRpc} ${register.targetTokenAddress} 'decimals()()'`;
let _sourceTokenDecimal;
try {
_sourceTokenDecimal = await $`cast call --rpc-url=${lifecycle.sourceChainRpc} ${register.sourceTokenAddress} 'decimals()()'`;
_sourceTokenDecimal = _sourceChainId.stdout.trim();
} catch (e) {
console.log(chalk.yellow(`[warn] can not query decimal from contract(${lifecycle.sourceChainName}): ${e}`));
}
let _targetTokenDecimal;
try {
_targetTokenDecimal = await $`cast call --rpc-url=${lifecycle.targetChainRpc} ${register.targetTokenAddress} 'decimals()()'`;
_targetTokenDecimal = _targetChainId.stdout.trim();
} catch (e) {
console.log(chalk.yellow(`[warn] can not query decimal from contract(${lifecycle.targetChainName}): ${e}`));
}

const sourceChainId = _sourceChainId.stdout.trim();
const targetChainId = _targetChainId.stdout.trim();
const sourceTokenDecimal = tool.pickDecimal({
definition,
decimal: _sourceTokenDecimal.stdout.trim(),
decimal: _sourceTokenDecimal,
chain: lifecycle.sourceChainName,
symbol: register.symbol,
});
const targetTokenDecimal = tool.pickDecimal({
definition,
decimal: _targetTokenDecimal.stdout.trim(),
decimal: _targetTokenDecimal,
chain: lifecycle.targetChainName,
symbol: register.symbol,
});
Expand Down
10 changes: 8 additions & 2 deletions src/register/lnv2_opposite.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ export async function register(options) {

const _targetChainId = await $`cast chain-id --rpc-url=${lifecycle.targetChainRpc}`;
const targetChainId = _targetChainId.stdout.trim();
const _sourceTokenDecimal = await $`cast call --rpc-url=${lifecycle.sourceChainRpc} ${register.sourceTokenAddress} 'decimals()()'`;
let _sourceTokenDecimal;
try {
_sourceTokenDecimal = await $`cast call --rpc-url=${lifecycle.sourceChainRpc} ${register.sourceTokenAddress} 'decimals()()'`
_sourceTokenDecimal = _sourceTokenDecimal.stdout.trim();
} catch (e) {
console.log(chalk.yellow(`[warn] can not query decimal from contract(${lifecycle.sourceChainName}): ${e}`));
}
const sourceTokenDecimal = tool.pickDecimal({
definition,
decimal: _sourceTokenDecimal.stdout.trim(),
decimal: _sourceTokenDecimal,
chain: lifecycle.sourceChainName,
symbol: register.symbol,
});
Expand Down
20 changes: 16 additions & 4 deletions src/register/lnv3.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@ import * as safe from '../ecosys/safe.js'
import * as tool from '../ecosys/tool.js'

export async function register(options) {
const {register, lifecycle} = options;
const {register, lifecycle, definition} = options;

const targetChainId = await $`cast chain-id --rpc-url=${lifecycle.targetChainRpc}`;
const _sourceTokenDecimal = await $`cast call --rpc-url=${lifecycle.sourceChainRpc} ${register.sourceTokenAddress} 'decimals()()'`;
const sourceTokenDecimal = BigInt(_sourceTokenDecimal);
let _sourceTokenDecimal;
try {
_sourceTokenDecimal = await $`cast call --rpc-url=${lifecycle.sourceChainRpc} ${register.sourceTokenAddress} 'decimals()()'`;
_sourceTokenDecimal = _sourceTokenDecimal.stdout.trim();
} catch (e) {
console.log(chalk.yellow(`[warn] can not query decimal from contract(${lifecycle.sourceChainName}): ${e}`));
}

const sourceTokenDecimal = tool.pickDecimal({
definition,
decimal: _sourceTokenDecimal,
chain: lifecycle.sourceChainName,
symbol: register.symbol,
});
const baseFee = tool.floatToBigInt(register.baseFee, sourceTokenDecimal);
const liquidityFeeRate = Number(register.liquidityFeeRate) * (10 ** 3);
const transferLimit = BigInt(register.transferLimit) * (10n ** sourceTokenDecimal);
Expand Down Expand Up @@ -134,7 +146,7 @@ async function registerWithSafe(options, callOptions) {
const txSetFee = await $`cast calldata ${setFeeFlags}`;
const featureApprove = definition.features.approve;

const transactions =[];
const transactions = [];
if (featureApprove.disable.indexOf(register.symbol) === -1) {
transactions.push({
to: register.sourceTokenAddress,
Expand Down

0 comments on commit ec6ecbe

Please sign in to comment.