Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide interface to send multiple Msg per transaction [do not merge] #134

Closed
wants to merge 11 commits into from

Conversation

johnqh
Copy link
Contributor

@johnqh johnqh commented Mar 21, 2024

After #132

Examples of multiple msgs:
Close all positions: [placeOrder, placeOrder...]
Cancel all orders: [cancelOrder, cancelOrder...]
Isolated margin order: [transfer, placeOrder] (maybe [transfer, withdraw, placeOrder] to make sure wallet balance is above certain level
SL/TP [placeOrder, placeOrder]

Changes:
For native, it should take a list of transactions from Abacus (Jared is working on the interface), and encode it to a json to send to transaction() function. It should have a payload like:

{
    "requests": [
        {
            "type": "placeOrder",       // same as the existing function name, such as placeOrder
            "params": "..."                   // same as the params sent with the existing function such as placeOrder(...)
        }
    ],
    "memo": "optional"
}

This PR has a rough implementation of transaction(...) function for native app integration. The payload may still change depending on the changes Jared is making with DYDXChainTransactionsProtocol

More importantly, this PR should not break existing code. I will need everyone's help to review/test and make sure it works with existing web and native apps

johnqh added 3 commits March 25, 2024 12:35
…ction

# Conflicts:
#	v4-client-js/__native__/__ios__/v4-native-client.js
#	v4-client-js/package.json
#	v4-client-js/src/clients/modules/post.ts
@johnqh johnqh marked this pull request as ready for review March 25, 2024 20:14
Copy link
Contributor

Choose a reason for hiding this comment

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

It is more accurate to keep the enum values in constants instead of types.ts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There were some circular reference error.

Comment on lines 283 to 285
await this.validateGoodTilBlock(goodTilBlock);

const marketsResponse = await this.indexerClient.markets.getPerpetualMarkets(marketId);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add another parameter to placeShortTermOrderMsgs so that these Indexer GET requests can be optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

Comment on lines 227 to 231
private defaultMsgBroadcastMode(msg: EncodeObject): BroadcastMode {
if (this.isShortTermOrderMsg(msg)) {
return Method.BroadcastTxSync;
} else {
return Method.BroadcastTxCommit;
Copy link
Contributor

Choose a reason for hiding this comment

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

can shorten to return this.isShortTermOrderMsg(msg) ? Method.BroadcastTxSync : Method.BroadcastTxCommit;

Copy link
Contributor

@jaredvu jaredvu Mar 25, 2024

Choose a reason for hiding this comment

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

similar to what you have in defaultBroadcastMode

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

Comment on lines 239 to 257
if (msg.typeUrl === '/dydxprotocol.clob.MsgPlaceOrder' ||
msg.typeUrl === '/dydxprotocol.clob.MsgCancelOrder') {
const orderFlags = msg.typeUrl === '/dydxprotocol.clob.MsgPlaceOrder'
? (msg.value as MsgPlaceOrder).order?.orderId?.orderFlags
: (msg.value as MsgCancelOrder).orderId?.orderFlags;

return orderFlags === OrderFlags.SHORT_TERM;
} else {
return false;
}
}

/**
* @description Whether the msg is a short term placeOrder or cancelOrder msg.
*/
private isOrderMsg(msg: EncodeObject): boolean {
return (msg.typeUrl === '/dydxprotocol.clob.MsgPlaceOrder' ||
msg.typeUrl === '/dydxprotocol.clob.MsgCancelOrder');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

All dYdX specific typeUrls are included in src/clients/constants.ts. Should use those constants instead of hard coded strings here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't know that. Changed

});
}

async msgs(
Copy link
Contributor

Choose a reason for hiding this comment

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

more descriptive name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

@johnqh johnqh requested a review from jaredvu March 26, 2024 20:55
Copy link
Contributor

@jaredvu jaredvu left a comment

Choose a reason for hiding this comment

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

🔥

@johnqh johnqh changed the title Provide interface to send multiple Msg per transaction Provide interface to send multiple Msg per transaction [do not merge] Mar 29, 2024
@yogurtandjam
Copy link
Contributor

why was this never merged? should we bother trying to merge this or can we close this? @jaredvu

@prashanDYDX
Copy link

@prashanDYDX
Copy link

Based on the above thread, I think the only case this could help today is with Transfer+LongTermOrder. Timestamp nonces should get us most of the way there and is a more general solution. Think we can just close this for now.

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

Successfully merging this pull request may close these issues.

4 participants