-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsimple_trading.ts
More file actions
61 lines (55 loc) · 1.57 KB
/
Copy pathsimple_trading.ts
File metadata and controls
61 lines (55 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import {
AccountPolicy,
BuyAmount,
DexType,
TradeTokenType,
createSimpleBuyParams,
simpleBuyParamsToTradeBuyParams,
withSimpleBuyAccountPolicy,
withSimpleBuySlippage,
withSimpleBuyWaitForAllSubmits,
withSimpleBuyWaitTxConfirmed,
} from 'sol-trade-sdk';
import {
RUN_LIVE,
createExampleClient,
describeDryRun,
exampleBuyParams,
logResult,
} from './_shared';
async function main() {
const client = createExampleClient();
const template = exampleBuyParams(DexType.PumpFun);
let simple = createSimpleBuyParams(
DexType.PumpFun,
TradeTokenType.WSOL,
template.mint,
BuyAmount.WithMaxInput(template.inputTokenAmount),
template.extensionParams,
template.recentBlockhash!,
template.gasFeeStrategy
);
simple = withSimpleBuyWaitForAllSubmits(
withSimpleBuyWaitTxConfirmed(
withSimpleBuyAccountPolicy(
withSimpleBuySlippage(simple, template.slippageBasisPoints ?? 500),
AccountPolicy.Auto
),
false
),
false
);
const lowLevel = simpleBuyParamsToTradeBuyParams(simple);
describeDryRun('Simple buy intent API');
console.log('Wallet:', client.getPayer().toBase58());
console.log('payWith:', simple.payWith);
console.log('amount intent:', simple.amount);
console.log('createInputTokenAta:', lowLevel.createInputTokenAta);
console.log('createMintAta:', lowLevel.createMintAta);
if (RUN_LIVE) {
const latest = await client.getLatestBlockhash();
simple.recentBlockhash = latest.blockhash;
logResult('buySimple', await client.buySimple(simple));
}
}
main().catch(console.error);