Skip to content

feat(SatoshiPeriphery): add swapInWithOkx function for ERC20 to DebtToken#13

Open
imfeng wants to merge 6 commits intomainfrom
feat/nym-okx
Open

feat(SatoshiPeriphery): add swapInWithOkx function for ERC20 to DebtToken#13
imfeng wants to merge 6 commits intomainfrom
feat/nym-okx

Conversation

@imfeng
Copy link
Collaborator

@imfeng imfeng commented Feb 24, 2026

feat(SatoshiPeriphery): add swapInWithOkx function for ERC20 to DebtToken

@imfeng imfeng requested a review from RayHuang880301 March 4, 2026 13:01

uint256 stableBalanceBefore = IERC20(stableAsset).balanceOf(address(this));

(bool success,) = okxRouter.call(okxCalldata);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would allow arbitrary function execution on an arbitrary contract, e.g. wbtc.transferFrom, a malicious attacker could steal other users tokens if they have approved the periphery contract.
I suggest the contract stores the okxRouter address in storage instead of of passing it as a parameter.

uint256 fromTokenBefore = IERC20(fromToken).balanceOf(address(this));

// Must approve the token approve proxy, NOT the router — OKX uses a separate spender contract
IERC20(fromToken).approve(okxApproveAddress, fromAmount);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest using forceApprove from SafeERC20 to work with non-standard ERC20 tokens like USDT.

@ashl3333
Copy link
Contributor

IERC20(fromToken).approve(okxApproveAddress, fromAmount);
IERC20(fromToken).approve(okxRouter, fromAmount);
IERC20(fromToken).forceApprove(_okxApprove, fromAmount);
IERC20(fromToken).forceApprove(_okxRouter, fromAmount);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a security issue, it's just that there is no need to approve the router.

Copy link
Collaborator

@StillFantastic StillFantastic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good with just a small nitpick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants