Skip to content

Commit

Permalink
Fix approve disable check
Browse files Browse the repository at this point in the history
  • Loading branch information
fewensa committed Apr 22, 2024
1 parent 844b6f4 commit 58e116b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
8 changes: 8 additions & 0 deletions src/ecosys/tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ export function pickDecimal(options = {definition, decimal, chain, symbol}) {
return BigInt(chainDecimal ? chainDecimal : symbolDefaultDecimal);
}

export function isDisableApprove(options = {definition, symbol, chainId}) {
const {definition, symbol, chainId} = options;
const featureApprove = definition.features.approve;
const approveDisable = featureApprove.disable;
const ix = approveDisable.findIndex(item => item.symbol === symbol && item.chain.toString() === chainId.toString())
return ix !== -1;
}

export async function queryBridgeInfoRecord(options = {lifecycle, version, sourceTokenAddress, bridge}) {
const {lifecycle, version, sourceTokenAddress, bridge} = options;
const gqlBody = {
Expand Down
13 changes: 6 additions & 7 deletions src/register/lnv2_default.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as safe from "../ecosys/safe.js";
import * as arg from "../ecosys/arg.js";
import * as tool from '../ecosys/tool.js';
import {isDisableApprove} from "../ecosys/tool.js";

export async function register(options) {
const {register, lifecycle, definition} = options;
Expand Down Expand Up @@ -97,6 +98,7 @@ export async function register(options) {
setFeeFlags,
withdrawFlags,
sourceDepositToTarget,
targetChainId,
};

// call safe
Expand All @@ -110,16 +112,15 @@ export async function register(options) {

async function registerWithCall(options, callOptions) {
const {register, lifecycle, definition, signer} = options;
const {approveFlags, depositFlags, setFeeFlags, withdrawFlags, sourceDepositToTarget} = callOptions;
const {approveFlags, depositFlags, setFeeFlags, withdrawFlags, sourceDepositToTarget, targetChainId} = callOptions;
const sourceSendFlags = [
`--rpc-url=${lifecycle.sourceChainRpc}`,
];
const targetSendFlags = [
`--rpc-url=${lifecycle.targetChainRpc}`,
];
const featureApprove = definition.features.approve;

if (featureApprove.disable.indexOf(register.symbol) === -1) {
if (!tool.isDisableApprove({definition, symbol: register.symbol, chainId: targetChainId})) {
approveFlags.unshift(...[
...targetSendFlags,
register.targetTokenAddress,
Expand Down Expand Up @@ -170,15 +171,13 @@ async function registerWithSafe(options, callOptions) {
sourceSafeSdk, sourceSafeService, sourceSigner,
targetSafeSdk, targetSafeService, targetSigner,
} = options;
const {approveFlags, depositFlags, setFeeFlags, withdrawFlags, sourceDepositToTarget} = callOptions;
const {approveFlags, depositFlags, setFeeFlags, withdrawFlags, sourceDepositToTarget, targetChainId} = callOptions;

const txApprove = await $`cast calldata ${approveFlags}`;
const txSetFee = await $`cast calldata ${setFeeFlags}`;

const featureApprove = definition.features.approve;

const p0Transactions = [];
if (featureApprove.disable.indexOf(register.symbol) === -1) {
if (!tool.isDisableApprove({definition, symbol: register.symbol, chainId: targetChainId})) {
p0Transactions.push({
to: register.targetTokenAddress,
value: '0',
Expand Down
11 changes: 5 additions & 6 deletions src/register/lnv2_opposite.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export async function register(options) {
setFeeFlags,
withdrawFlags,
sourceDeposit,
targetChainId,
};

// call safe
Expand All @@ -81,16 +82,15 @@ export async function register(options) {

async function registerWithCall(options, callOptions) {
const {register, lifecycle, definition, signer} = options;
const {approveFlags, setFeeFlags, withdrawFlags, sourceDeposit} = callOptions;
const {approveFlags, setFeeFlags, withdrawFlags, sourceDeposit, targetChainId} = callOptions;
const sourceSendFlags = [
`--rpc-url=${lifecycle.sourceChainRpc}`,
];
const targetSendFlags = [
`--rpc-url=${lifecycle.targetChainRpc}`,
];

const featureApprove = definition.features.approve;
if (featureApprove.disable.indexOf(register.symbol) === -1) {
if (!tool.isDisableApprove({definition, symbol: register.symbol, chainId: targetChainId})) {
approveFlags.unshift(...[
...targetSendFlags,
register.targetTokenAddress,
Expand Down Expand Up @@ -118,15 +118,14 @@ async function registerWithSafe(options, callOptions) {
sourceSafeSdk, sourceSafeService, sourceSigner,
targetSafeSdk, targetSafeService, targetSigner,
} = options;
const {approveFlags, setFeeFlags, withdrawFlags, sourceDeposit} = callOptions;
const {approveFlags, setFeeFlags, withdrawFlags, sourceDeposit, targetChainId} = callOptions;

const txApprove = await $`cast calldata ${approveFlags}`;
const txSetFee = await $`cast calldata ${setFeeFlags}`;

const p0Transactions = [];

const featureApprove = definition.features.approve;
if (featureApprove.disable.indexOf(register.symbol) === -1) {
if (!tool.isDisableApprove({definition, symbol: register.symbol, chainId: targetChainId})) {
p0Transactions.push({
to: register.targetTokenAddress,
value: '0',
Expand Down
11 changes: 5 additions & 6 deletions src/register/lnv3.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export async function register(options) {
setFeeFlags,
depositFlags,
withdrawFlags,
targetChainId,
};

// call safe
Expand All @@ -89,13 +90,12 @@ export async function register(options) {

async function registerWithCall(options, callOptions) {
const {register, lifecycle, definition, signer} = options;
const {approvalFlags, depositFlags, setFeeFlags, withdrawFlags} = callOptions;
const {approvalFlags, depositFlags, setFeeFlags, withdrawFlags, targetChainId} = callOptions;
const sendFlags = [
`--rpc-url=${lifecycle.sourceChainRpc}`,
];

const featureApprove = definition.features.approve;
if (featureApprove.disable.indexOf(register.symbol) === -1) {
if (!tool.isDisableApprove({definition, symbol: register.symbol, chainId: targetChainId})) {
approvalFlags.unshift(...[
...sendFlags,
register.sourceTokenAddress,
Expand Down Expand Up @@ -140,14 +140,13 @@ async function registerWithCall(options, callOptions) {

async function registerWithSafe(options, callOptions) {
const {register, lifecycle, definition, sourceSafeSdk, sourceSafeService, sourceSigner} = options;
const {approvalFlags, depositFlags, setFeeFlags, withdrawFlags} = callOptions;
const {approvalFlags, depositFlags, setFeeFlags, withdrawFlags, targetChainId} = callOptions;

const txApprove = await $`cast calldata ${approvalFlags}`;
const txSetFee = await $`cast calldata ${setFeeFlags}`;
const featureApprove = definition.features.approve;

const transactions = [];
if (featureApprove.disable.indexOf(register.symbol) === -1) {
if (!tool.isDisableApprove({definition, symbol: register.symbol, chainId: targetChainId})) {
transactions.push({
to: register.sourceTokenAddress,
value: '0',
Expand Down

0 comments on commit 58e116b

Please sign in to comment.