Skip to content

Conversation

@carlos-cow
Copy link
Collaborator

@carlos-cow carlos-cow commented Jul 9, 2025

GIST

This is a very hardcoded script to create a limit order to test the flashloan logic e2e.
This is not supposed to be merged.

This script will send an order to gnosis staging.

HOWTO RUN

Setup your wallet/position

Use your deployer wallet to test.

You will need to hold 20 aUSDC in gnosis chain.
You can use Cowswap! Create a buy order for 20.01 0xc6B7AcA6DE8a6044E0e32d0c841a89244A10D284

Once you get your collateral, get some debt.
Go to aave: https://app.aave.com/reserve-overview/?underlyingAsset=0x9c58bacc331c9aa871afd802db6379a98e80cedb&marketName=proto_gnosis_v3
and borrow 0.01 GNO.

Screenshot 2025-08-12 at 1 52 14 PM

Borrowing tokens in aave will lock your full collateral to be moved.

Create an .env file with:

RPC_URL_100=<your gnosis chain rpc url>
PRIVATE_KEY=0x0

Modify the script to use a valid VALID_FOR

Since the deterministic contract depends on VALID_FOR it's better to hardcode a value to avoid approving a contract over and over again. Get a value in the future from https://www.epochconverter.com/
I usually do 4hs. I think the backend has an error when it's too many days ahead in the future.

Run with the script

You will need to have node and dependencies and you can run with:

yarn dev

It will ask you to approve the token to the deterministic helper address for the order parameters.
You should do this only once per order.

NOTE: The order creation will fail. The error you will get is the following:

400, body: {"errorType":"InsufficientBalance","description":"order owner must have funds worth at least x in his account"}

This is a bug in the backend and needs to be fixed.
To continue testing without the fix, transfer 1 wei of your sell token into the helper contract.

Go here:
https://gnosisscan.io/address/0xc6B7AcA6DE8a6044E0e32d0c841a89244A10D284#writeProxyContract#F10
and do something like this after connecting your wallet:

Screenshot 2025-08-18 at 10 26 22 PM

Re-run the script and you will see a 201. The order should be created but I am not seeing the order reaching solvers.

Additional info

To verify the script is doing the right thing, you can compare signatures with the following solidity unit test:

    function test_createSignature() external {
        uint256 key = vm.envUint("PRIVATE_KEY");

        GPv2Order.Data memory order = GPv2Order.Data({
            sellToken: IERC20(0xc6B7AcA6DE8a6044E0e32d0c841a89244A10D284),
            buyToken: IERC20(0xd0Dd6cEF72143E22cCED4867eb0d5F2328715533),
            receiver: address(0x0), // my address
            sellAmount: 19990000,
            buyAmount: 18000000000000000000,
            validTo: 1754010000,
            appData: 0x3c49ba292aa2c9aaaa0c8dcf39585eae4c99a1653f3e6d4fabe002a3f2f31dbb,
            feeAmount: 0,
            kind: GPv2Order.KIND_SELL,
            partiallyFillable: false,
            sellTokenBalance: GPv2Order.BALANCE_ERC20,
            buyTokenBalance: GPv2Order.BALANCE_ERC20
        });

        bytes memory signature;
        {
            // GNOSIS CHAIN SETTLEMENT DOMAIN SEPARATOR
            bytes32 domainSeparator = 0x8f05589c4b810bc2f706854508d66d447cd971f8354a4bb0b3471ceb0a466bc7;
            bytes32 orderDigest = order.hash(domainSeparator);
            (uint8 v, bytes32 r, bytes32 s) = vm.sign(key, orderDigest);
            bytes memory userSignature = abi.encodePacked(r, s, v);
            signature = abi.encode(order, userSignature);

            console.log("order digest");
            console.logBytes32(orderDigest);
            console.log("signature");
            console.logBytes(userSignature);
            console.log("signature");
            console.logBytes(signature);
        }

    }

@carlos-cow carlos-cow changed the title Carlos/gnosis Gnosis minimal implementation Jul 9, 2025
@carlos-cow carlos-cow marked this pull request as draft July 9, 2025 19:46
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.

2 participants