Skip to content

Commit

Permalink
feat: add spender allowance/approval
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdev3 committed Nov 5, 2024
1 parent 3e464f3 commit bc6290c
Show file tree
Hide file tree
Showing 4 changed files with 2,542 additions and 2,609 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"semver": "^7.5.4"
},
"devDependencies": {
"@0xsquid/squid-types": "0.1.85",
"@0xsquid/squid-types": "0.1.115",
"@babel/core": "^7.18.10",
"@babel/preset-env": "^7.18.10",
"@babel/preset-typescript": "^7.18.6",
Expand Down
15 changes: 12 additions & 3 deletions src/handlers/evm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,15 @@ export class EvmHandler extends Utils {
return true;
}

// there're some cases where the target of the tx
// is not the one who spend the tokens
const { target, spender } = data.route.transactionRequest as SquidData;
const _spender = spender || target;

const hasAllowance = await this.validateAllowance({
fromTokenContract: params.fromTokenContract as Contract,
sender: address,
router: (data.route.transactionRequest as SquidData).target,
router: _spender,
amount: BigInt(params.fromAmount),
});

Expand All @@ -150,7 +155,11 @@ export class EvmHandler extends Utils {
executionSettings,
overrides,
} = data;
const { target } = transactionRequest as SquidData;
// there're some cases where the target of the tx
// is not the one who spend the tokens
const { target, spender } = transactionRequest as SquidData;
const _spender = spender || target;

const { fromIsNative, fromAmount } = params;
const fromTokenContract = params.fromTokenContract as Contract;

Expand All @@ -169,7 +178,7 @@ export class EvmHandler extends Utils {
// Need to manually encode approve, instead of calling fromTokenContract.approve
// TODO: Find a way to have it work with .approve method
const approveData = fromTokenContract.interface.encodeFunctionData("approve", [
target,
_spender,
amountToApprove,
]);

Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,15 @@ export class Squid extends TokensChains {
case ChainType.EVM:
const params = this.handlers.evm.populateRouteParams(this, route.params);

// there're some cases where the target of the tx
// is not the one who spend the tokens
const { target, spender } = route.transactionRequest as SquidData;
const _spender = spender || target;

return await this.handlers.evm.isRouteApproved({
sender,
params,
target: (route.transactionRequest as SquidData).target,
target: _spender,
});

default:
Expand Down
Loading

0 comments on commit bc6290c

Please sign in to comment.