Skip to content

Commit

Permalink
Merge pull request #281 from drift-labs/master
Browse files Browse the repository at this point in the history
send to mainnet
  • Loading branch information
NourAlharithi authored Oct 31, 2024
2 parents e43dea7 + 02ca5e0 commit e7ddf8b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
34 changes: 31 additions & 3 deletions src/experimental-bots/swift/makerExample.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import {
BN,
DriftClient,
getLimitOrderParams,
getUserAccountPublicKey,
getUserStatsAccountPublicKey,
MarketType,
PositionDirection,
PublicKey,
UserMap,
} from '@drift-labs/sdk';
Expand Down Expand Up @@ -82,20 +86,44 @@ export class SwiftMaker {
const takerUserAccount = (
await this.userMap.mustGet(takerUserPubkey.toString())
).getUserAccount();
const ixs = await this.driftClient.getPlaceSwiftTakerPerpOrderIxs(

const isOrderLong =
order['order_message']['swift_order_params']['direction'] ===
'long';
const ixs = await this.driftClient.getPlaceAndMakeSwiftPerpOrderIxs(
Buffer.from(order['swift_message'], 'base64'),
Buffer.from(order['swift_signature'], 'base64'),
Buffer.from(order['order_message'], 'base64'),
Buffer.from(order['order_signature'], 'base64'),
order['market_index'],
order['uuid'],
{
taker: takerUserPubkey,
takerUserAccount,
takerStats: getUserStatsAccountPublicKey(
this.driftClient.program.programId,
takerUserAccount.authority
),
}
},
getLimitOrderParams({
marketType: MarketType.PERP,
marketIndex:
order['order_message']['swift_order_params']['market_index'],
direction: isOrderLong
? PositionDirection.SHORT
: PositionDirection.LONG,
baseAssetAmount: new BN(
order['order_message']['swift_order_params'][
'base_asset_amount'
]
),
price: isOrderLong
? new BN(order['order_message']['swift_order_params']['price'])
.muln(99)
.divn(100)
: new BN(order['order_message']['swift_order_params']['price'])
.muln(101)
.divn(100),
})
);
const tx = await this.driftClient.txSender.getVersionedTransaction(
ixs,
Expand Down
2 changes: 0 additions & 2 deletions src/experimental-bots/swift/takerExample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ export class SwiftTaker {
price: oracleInfo.price.muln(105).divn(100),
}),
subAccountId: 0,
expectedOrderId: this.driftClient.getUser().getUserAccount()
.nextOrderId,
stopLossOrderParams: null,
takeProfitOrderParams: null,
});
Expand Down

0 comments on commit e7ddf8b

Please sign in to comment.