Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
DEPLOYER_ECDSA_PRIV_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
# public key - 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

PREDICATE_HOOK_ADDRESS=0x452e2E2CfcaC437d4E321226A3255d2cFc5c68A0
SWAP_ROUTER_ADDRESS=0x8F2c925603c4ba055779475F14241E3c9ee7c1be
PREDICATE_HOOK_ADDRESS=0x452e2E2CfcaC437d4E321226A3255d2cFc5c68A0
AUTO_WRAPPER_HOOK_ADDRESS=0x75202124c8B7FAFBD66AB67F39CE01f69C0128c8
POSM_ADDRESS=0xbD216513d74C8cf14cf4747E6AaA6420FF64ee9e # mainnet POSM
# POLICY_ID=x-aleo-6a52de9724a6e8f2 // mainnet
Expand Down Expand Up @@ -90,7 +90,7 @@ swap-usdc-for-usdl-exact-in:
--via-ir \
--rpc-url ${RPC_URL} \
--private-key ${DEPLOYER_ECDSA_PRIV_KEY} \
--broadcast -vvvv
--broadcast

swap-usdl-for-usdc-exact-in:
export NETWORK=${NETWORK} && \
Expand All @@ -101,7 +101,7 @@ swap-usdl-for-usdc-exact-in:
--via-ir \
--rpc-url ${RPC_URL} \
--private-key ${DEPLOYER_ECDSA_PRIV_KEY} \
--broadcast -vvvv
--broadcast

swap-usdl-for-usdc-exact-out:
export NETWORK=${NETWORK} && \
Expand All @@ -112,6 +112,6 @@ swap-usdl-for-usdc-exact-out:
--via-ir \
--rpc-url ${RPC_URL} \
--private-key ${DEPLOYER_ECDSA_PRIV_KEY} \
--broadcast -vvvv
--broadcast


3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ For testing with mainnet anvil fork:
7. Update `AUTO_WRAPPER_HOOK_ADDRESS` env variable in Makefile from this deployment
8. Run `make swap-usdc-for-usdl-exact-in`. This will swap USDC for USDL on the ghost + liquidity pools that we just configured. (there's some more options available in the script that can be used).

*Note: Predicate signature validation is skipped for local testing as the predicate hook owner is added to an authorized owner allow-list during hook creation.*
*Note: The Predicate signature validation is skipped for local testing as the locally deployed contracts would not be visible to the Predicate Network.
As a workaround, the predicate hook 'owner' (your address) is added to an authorized owner allow-list in the predicate-hook deployment script.*

## Testing

Expand Down
63 changes: 63 additions & 0 deletions script/common/SwapScript.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ contract SwapScript is Script {
}

function swapUSDCForUSDLExactIn() public {
uint256 balanceBeforeSwapUSDC = IERC20(Currency.unwrap(_env.tokenConfig().USDC)).balanceOf(msg.sender);
uint256 balanceBeforeSwapUSDL = IERC20(Currency.unwrap(_env.tokenConfig().USDL)).balanceOf(msg.sender);
INetwork.TokenConfig memory tokenConfig = _env.tokenConfig();
uint128 amountIn = 1e6; // 1 USDC
uint128 amountOutMin = 1e17; // accepts min 0.1 USDL out
Expand All @@ -126,9 +128,30 @@ contract SwapScript is Script {
vm.startBroadcast();
_swapRouter.execute(abi.encode(actions, params));
vm.stopBroadcast();

uint256 balanceAfterSwapUSDC = IERC20(Currency.unwrap(_env.tokenConfig().USDC)).balanceOf(msg.sender);
uint256 balanceAfterSwapUSDL = IERC20(Currency.unwrap(_env.tokenConfig().USDL)).balanceOf(msg.sender);

console.log("======================================");
console.log(" Exact-In Swap: 1 USDC to USDL ");
console.log("======================================");

console.log(" Balances Before Swap:");
console.log(" USDC: %s", balanceBeforeSwapUSDC / 1e6);
console.log(" USDL: %s", balanceBeforeSwapUSDL / 1e18);

console.log("--------------------------------------");

console.log(" Balances After Swap:");
console.log(" USDC: %s", balanceAfterSwapUSDC / 1e6);
console.log(" USDL: %s", balanceAfterSwapUSDL / 1e18);

console.log("======================================");
}

function swapUSDLForUSDCExactIn() public {
uint256 balanceBeforeSwapUSDC = IERC20(Currency.unwrap(_env.tokenConfig().USDC)).balanceOf(msg.sender);
uint256 balanceBeforeSwapUSDL = IERC20(Currency.unwrap(_env.tokenConfig().USDL)).balanceOf(msg.sender);
INetwork.TokenConfig memory tokenConfig = _env.tokenConfig();
uint128 amountIn = 1e18; // 1 USDL
uint128 amountOutMin = 9e5; // accepts min 0.9 USDC out
Expand Down Expand Up @@ -157,9 +180,30 @@ contract SwapScript is Script {
vm.startBroadcast();
_swapRouter.execute(abi.encode(actions, params));
vm.stopBroadcast();

uint256 balanceAfterSwapUSDC = IERC20(Currency.unwrap(_env.tokenConfig().USDC)).balanceOf(msg.sender);
uint256 balanceAfterSwapUSDL = IERC20(Currency.unwrap(_env.tokenConfig().USDL)).balanceOf(msg.sender);

console.log("======================================");
console.log(" Exact-In Swap: 1 USDL to USDC ");
console.log("======================================");

console.log(" Balances Before Swap:");
console.log(" USDC: %s", balanceBeforeSwapUSDC / 1e6);
console.log(" USDL: %s", balanceBeforeSwapUSDL / 1e18);

console.log("--------------------------------------");

console.log(" Balances After Swap:");
console.log(" USDC: %s", balanceAfterSwapUSDC / 1e6);
console.log(" USDL: %s", balanceAfterSwapUSDL / 1e18);

console.log("======================================");
}

function swapUSDLForUSDCExactOut() public {
uint256 balanceBeforeSwapUSDC = IERC20(Currency.unwrap(_env.tokenConfig().USDC)).balanceOf(msg.sender);
uint256 balanceBeforeSwapUSDL = IERC20(Currency.unwrap(_env.tokenConfig().USDL)).balanceOf(msg.sender);
INetwork.TokenConfig memory tokenConfig = _env.tokenConfig();
uint128 amountOut = 1e6; // 1 USDC
uint128 amountInMax = 2e18; // accepts max 2 USDL in
Expand Down Expand Up @@ -192,5 +236,24 @@ contract SwapScript is Script {
vm.startBroadcast();
_swapRouter.execute(abi.encode(actions, params));
vm.stopBroadcast();

uint256 balanceAfterSwapUSDC = IERC20(Currency.unwrap(_env.tokenConfig().USDC)).balanceOf(msg.sender);
uint256 balanceAfterSwapUSDL = IERC20(Currency.unwrap(_env.tokenConfig().USDL)).balanceOf(msg.sender);

console.log("======================================");
console.log(" Exact-Out Swap: USDL for 1 USDC ");
console.log("======================================");

console.log(" Balances Before Swap:");
console.log(" USDC: %s", balanceBeforeSwapUSDC / 1e6);
console.log(" USDL: %s", balanceBeforeSwapUSDL / 1e18);

console.log("--------------------------------------");

console.log(" Balances After Swap:");
console.log(" USDC: %s", balanceAfterSwapUSDC / 1e6);
console.log(" USDL: %s", balanceAfterSwapUSDL / 1e18);

console.log("======================================");
}
}