Skip to content

Commit

Permalink
Update Bridger.sol to modify asset swap logic for wUSDM, add test for…
Browse files Browse the repository at this point in the history
… USDC to wUSDM swap, and include new test data file.
  • Loading branch information
ylv-io committed Jan 31, 2025
1 parent 424b3da commit 76ed83b
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/bridger/Bridger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ contract Bridger is
amount,
IERC20(inputAsset),
// If the final asset is sUSDe, swap to USDe first and then stake
// If the final asset is wUSDM, swap to USDC first, then swap to USDM using Curve, and finally wrap
// If the final asset is wUSDM, swap to USDM first and then stake
IERC20(_getFinalAssetByAsset(finalAsset)),
swapCallData
);
Expand Down Expand Up @@ -475,7 +475,7 @@ contract Bridger is
return USDe;
}
if (finalAsset == wUSDM) {
return USDC;
return USDM;
}
if (finalAsset == stUSD) {
return USDC;
Expand Down
66 changes: 66 additions & 0 deletions test/data/swap-usdc-to-usdm-arb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"blockNumber": "21746939",
"buyAmount": "1000020215920662956",
"buyToken": "0x59d9356e565ab3a36dd77763fc0d87feaf85508c",
"fees": {
"integratorFee": null,
"zeroExFee": null,
"gasFee": null
},
"issues": {
"allowance": {
"actual": "0",
"spender": "0x0000000000001ff3684f28c67538d4d072c22734"
},
"balance": {
"token": "0xaf88d065e77c8cc2239327c5edb3a432268e5831",
"actual": "0",
"expected": "1000000"
},
"simulationIncomplete": false,
"invalidSourcesPassed": []
},
"liquidityAvailable": true,
"minBuyAmount": "990020013761453400",
"route": {
"fills": [
{
"from": "0xaf88d065e77c8cc2239327c5edb3a432268e5831",
"to": "0x59d9356e565ab3a36dd77763fc0d87feaf85508c",
"source": "Curve",
"proportionBps": "10000"
}
],
"tokens": [
{
"address": "0xaf88d065e77c8cc2239327c5edb3a432268e5831",
"symbol": "USDC"
},
{
"address": "0x59d9356e565ab3a36dd77763fc0d87feaf85508c",
"symbol": "USDM"
}
]
},
"sellAmount": "1000000",
"sellToken": "0xaf88d065e77c8cc2239327c5edb3a432268e5831",
"tokenMetadata": {
"buyToken": {
"buyTaxBps": "0",
"sellTaxBps": "0"
},
"sellToken": {
"buyTaxBps": "0",
"sellTaxBps": "0"
}
},
"totalNetworkFee": "5165430000000",
"transaction": {
"to": "0x0000000000001ff3684f28c67538d4d072c22734",
"data": "0x2213bc0b0000000000000000000000006db4d3b89b06d3c8bd2074ee1f1b440baf122ead000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000f42400000000000000000000000006db4d3b89b06d3c8bd2074ee1f1b440baf122ead00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000003c41fff991f000000000000000000000000b7dfe09cf3950141dfb7db8abca90ddef8d06ec000000000000000000000000059d9356e565ab3a36dd77763fc0d87feaf85508c0000000000000000000000000000000000000000000000000dbd41f508c75d5800000000000000000000000000000000000000000000000000000000000000a01a1bfdbeedfa26fb28419b21000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000e4c1fb425e0000000000000000000000006db4d3b89b06d3c8bd2074ee1f1b440baf122ead000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000f4240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000679d35b600000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016438c9c147000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000027100000000000000000000000004bd135524897333bec344e50ddd85126554e58b4000000000000000000000000000000000000000000000000000000000000004400000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000843df021240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"gas": "516543",
"gasPrice": "10000000",
"value": "0"
},
"zid": "0x1a1bfdbeedfa26fb28419b21"
}
60 changes: 59 additions & 1 deletion test/fork/bridger/Bridger.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ contract BridgerTest is SignatureHelper, ForkTest, ArtifactsReader, BridgeDataHe
address internal ENA;
address internal wstETH;
address internal weETH;
address internal usdmCurvePool;

BridgerHarness internal bridger;

Expand Down Expand Up @@ -280,6 +279,65 @@ contract BridgerTest is SignatureHelper, ForkTest, ArtifactsReader, BridgeDataHe
);
}

// USDC to wUSDM
function testDepositBySig_WhenUSDCToWUSDM() public {
setUpArbitrumFork();
vm.rollFork(301295138); // block number in which the 0x API data was fetched
upgradeBridger();

IBridger.BridgeData memory data = bridgeData[block.chainid][wUSDM];
address assetToDeposit = USDC_ARBITRUM;
uint256 amountToDeposit = 1e6;
uint256 sharesBefore = ERC20(wUSDM).balanceOf(address(bridger));
uint256 vaultSharesBefore = ERC20(wUSDM).balanceOf(address(data.vault));

deal(assetToDeposit, _user, amountToDeposit);
deal(_user, data.gasFee);

assertEq(ERC20(assetToDeposit).balanceOf(_user), amountToDeposit);

IBridger.SignatureData memory sigdata = _auxCreateBridgeSignature(
kintoWalletL2,
bridger,
_user,
assetToDeposit,
wUSDM,
amountToDeposit,
968e3,
_userPk,
block.timestamp + 1000
);

bytes memory permitSignature = _auxCreatePermitSignature(
IBridger.Permit(
_user,
address(bridger),
amountToDeposit,
ERC20Permit(assetToDeposit).nonces(_user),
block.timestamp + 1000
),
_userPk,
ERC20Permit(assetToDeposit)
);
uint256 nonce = bridger.nonces(_user);

vm.prank(bridger.owner());
bridger.setBridgeVault(data.vault, true);

// USDC to USDM quote's swapData
// curl 'https://api.0x.org/swap/allowance-holder/quote?chainId=42161&buyToken=0x59D9356E565Ab3A36dD77763Fc0d87fEaf85508C&sellToken=0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1&sellAmount=1000000000000000000&taker=0xb7DfE09Cf3950141DFb7DB8ABca90dDef8d06Ec0' -H '0x-api-key: key' -H '0x-version: v2' | jq > ./test/data/swap-usdc-to-usdm-arb.json
bytes memory swapCalldata = vm.readFile("./test/data/swap-usdc-to-usdm-arb.json").readBytes(".transaction.data");

vm.deal(address(bridger), data.gasFee);
vm.prank(_owner);
bridger.depositBySig(permitSignature, sigdata, swapCalldata, data);
assertEq(bridger.nonces(_user), nonce + 1);

uint256 shares = ERC4626(wUSDM).previewDeposit(1000020215920662957);
assertEq(ERC20(wUSDM).balanceOf(address(bridger)), sharesBefore, "Invalid balance of the Bridger");
assertEq(ERC20(wUSDM).balanceOf(data.vault), vaultSharesBefore + shares, "Invalid balance of the Vault");
}

// DAI to wUSDM
function testDepositBySig_WhenDaiToWUSDM() public {
setUpArbitrumFork();
Expand Down

0 comments on commit 76ed83b

Please sign in to comment.