Skip to content

Commit

Permalink
update sdk version
Browse files Browse the repository at this point in the history
  • Loading branch information
rudy5348 committed Apr 25, 2023
1 parent c7ec1bc commit 7d0ddcf
Show file tree
Hide file tree
Showing 7 changed files with 2,152 additions and 50 deletions.
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"dependencies": {
"@raydium-io/raydium-sdk": "^1.2.0-beta.7",
"@solana/web3.js": "^1.73.0",
"@raydium-io/raydium-sdk": "^1.3.0-beta.15",
"@solana/spl-token": "^0.3.7",
"@solana/web3.js": "^1.75.0",
"bs58": "^5.0.0",
"decimal.js": "^10.4.3",
"typescript": "^4.9.5"
"typescript": "^5.0.4"
},
"devDependencies": {
"@types/bn.js": "^5.1.1"
"@types/bn.js": "^5.1.1",
"npm-check-updates": "^16.10.9"
},
"scripts": {
"start": "node",
Expand Down
30 changes: 24 additions & 6 deletions src/ammCreatePool.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
import { BN } from 'bn.js'
import { BN } from 'bn.js';

import {
buildTransaction,
Liquidity,
MAINNET_PROGRAM_ID,
Token,
} from '@raydium-io/raydium-sdk';
import {
Keypair,
PublicKey,
} from '@solana/web3.js';

import {
connection,
PROGRAMIDS,
wallet,
wantBuildTxVersion,
} from '../config';
import {
getWalletTokenAccount,
sendTx,
} from './util';

const ZERO = new BN(0)
type BN = typeof ZERO

import { buildTransaction, Liquidity, MAINNET_PROGRAM_ID, Token } from '@raydium-io/raydium-sdk'
import { Keypair, PublicKey } from '@solana/web3.js'
import { connection, PROGRAMIDS, wallet, wantBuildTxVersion } from '../config'
import { getWalletTokenAccount, sendTx } from './util'

type CalcStartPrice = {
addBaseAmount: BN
addQuoteAmount: BN
Expand Down
26 changes: 18 additions & 8 deletions src/ammV3AddPosition.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import assert from 'assert'
import assert from 'assert';

import {
AmmV3,
AmmV3PoolInfo,
AmmV3PoolPersonalPosition,
ApiAmmV3PoolsItem,
buildTransaction,
ENDPOINT,
Percent,
Token,
TokenAmount,
} from '@raydium-io/raydium-sdk'
import { Keypair, PublicKey } from '@solana/web3.js'
import { connection, RAYDIUM_MAINNET_API, wallet, wantBuildTxVersion } from '../config'
import { getWalletTokenAccount, sendTx } from './util'
} from '@raydium-io/raydium-sdk';
import {
Keypair,
PublicKey,
} from '@solana/web3.js';

import {
connection,
RAYDIUM_MAINNET_API,
wallet,
wantBuildTxVersion,
} from '../config';
import {
getWalletTokenAccount,
sendTx,
} from './util';

type WalletTokenAccounts = Awaited<ReturnType<typeof getWalletTokenAccount>>
type TestTxInputInfo = {
Expand Down
33 changes: 28 additions & 5 deletions src/ammV3CreatePool.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
import { AmmV3, AmmV3ConfigInfo, buildTransaction, ENDPOINT, Token } from '@raydium-io/raydium-sdk'
import { Keypair, PublicKey } from '@solana/web3.js'
import Decimal from 'decimal.js'
import { connection, PROGRAMIDS, RAYDIUM_MAINNET_API, wallet, wantBuildTxVersion } from '../config'
import { sendTx } from './util'
import BN from 'bn.js';
import Decimal from 'decimal.js';

import {
AmmV3,
AmmV3ConfigInfo,
buildTransaction,
ENDPOINT,
Token,
} from '@raydium-io/raydium-sdk';
import {
Keypair,
PublicKey,
} from '@solana/web3.js';

import {
connection,
PROGRAMIDS,
RAYDIUM_MAINNET_API,
wallet,
wantBuildTxVersion,
} from '../config';
import { sendTx } from './util';

type TestTxInputInfo = {
baseToken: Token
quoteToken: Token
ammV3ConfigId: string
wallet: Keypair
startPoolPrice: Decimal
startTime: BN
}

/**
Expand Down Expand Up @@ -41,6 +60,7 @@ async function ammV3CreatePool(input: TestTxInputInfo) {
mint2: input.quoteToken,
ammConfig,
initialPrice: input.startPoolPrice,
startTime: input.startTime,
})

// -------- step 2: (optional) get mockPool info --------
Expand All @@ -52,6 +72,7 @@ async function ammV3CreatePool(input: TestTxInputInfo) {
createPoolInstructionSimpleAddress: makeCreatePoolInstruction.address,
owner: input.wallet.publicKey,
initialPrice: input.startPoolPrice,
startTime: input.startTime
})

// -------- step 3: compose instructions to several transactions --------
Expand All @@ -72,13 +93,15 @@ async function howToUse() {
const quoteToken = new Token(new PublicKey('4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R'), 6, 'RAY', 'RAY') // RAY
const ammV3ConfigId = 'E64NGkDLLCdQ2yFNPcavaKptrEgmiQaNykUuLC1Qgwyp'
const startPoolPrice = new Decimal(1)
const startTime = new BN(Math.floor(new Date().getTime() / 1000))

ammV3CreatePool({
baseToken,
quoteToken,
ammV3ConfigId,
wallet: wallet,
startPoolPrice,
startTime,
}).then(({ txids, mockPoolInfo }) => {
/** continue with txids */
console.log('txids', txids)
Expand Down
30 changes: 24 additions & 6 deletions src/stakeFarm.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
import assert from 'assert';

import {
ApiFarmInfo,
buildTransaction,
Farm,
FarmPoolKeys,
jsonInfo2PoolKeys,
Token,
TokenAmount
} from '@raydium-io/raydium-sdk'
import { Keypair, PublicKey } from '@solana/web3.js'
import assert from 'assert'
import { connection, ENDPOINT, RAYDIUM_MAINNET_API, wallet, wantBuildTxVersion } from '../config'
import { getWalletTokenAccount, sendTx } from './util'
TokenAmount,
} from '@raydium-io/raydium-sdk';
import {
Keypair,
PublicKey,
} from '@solana/web3.js';

import {
connection,
ENDPOINT,
RAYDIUM_MAINNET_API,
wallet,
wantBuildTxVersion,
} from '../config';
import {
getWalletTokenAccount,
sendTx,
} from './util';

type WalletTokenAccounts = Awaited<ReturnType<typeof getWalletTokenAccount>>
type TestTxInputInfo = {
Expand All @@ -34,9 +48,13 @@ async function stakeFarm(input: TestTxInputInfo) {
const targetFarmJsonInfo: any = farmPools.raydium.find((pool) => pool.id === input.targetFarm)
assert(targetFarmJsonInfo, 'target farm not found')
const targetFarmInfo = jsonInfo2PoolKeys(targetFarmJsonInfo) as FarmPoolKeys

const chainTime = Math.floor(new Date().getTime() / 1000) // TODO

const { [input.targetFarm]: farmFetchInfo } = await Farm.fetchMultipleInfoAndUpdate({
connection,
pools: [targetFarmInfo],
chainTime,
})
assert(Object.keys(farmFetchInfo).length && farmFetchInfo, 'cannot fetch target farm info')

Expand Down
26 changes: 20 additions & 6 deletions src/unstakeFarm.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
import assert from 'assert'
import assert from 'assert';

import {
ApiFarmInfo,
buildTransaction,
ENDPOINT,
Farm,
FarmPoolKeys,
jsonInfo2PoolKeys,
Percent,
Token,
TokenAmount,
} from '@raydium-io/raydium-sdk'
import { connection, RAYDIUM_MAINNET_API, wallet, wantBuildTxVersion } from '../config'
import { getWalletTokenAccount, sendTx } from './util'
import { Keypair, PublicKey } from '@solana/web3.js'
} from '@raydium-io/raydium-sdk';
import {
Keypair,
PublicKey,
} from '@solana/web3.js';

import {
connection,
RAYDIUM_MAINNET_API,
wallet,
wantBuildTxVersion,
} from '../config';
import {
getWalletTokenAccount,
sendTx,
} from './util';

type WalletTokenAccounts = Awaited<ReturnType<typeof getWalletTokenAccount>>
type TestTxInputInfo = {
Expand All @@ -37,11 +49,13 @@ async function unstakeFarm(input: TestTxInputInfo) {
assert(targetFarmJsonInfo, 'target farm not found')
const targetFarmInfo = jsonInfo2PoolKeys(targetFarmJsonInfo) as FarmPoolKeys

const chainTime = Math.floor(new Date().getTime() / 1000) // TODO
// -------- step 1: Fetch farm pool info --------
const { [input.targetFarm]: farmPoolInfo } = await Farm.fetchMultipleInfoAndUpdate({
connection,
pools: [targetFarmInfo],
owner: input.wallet.publicKey,
chainTime,
})
assert(farmPoolInfo, 'cannot fetch target farm info')

Expand Down
Loading

0 comments on commit 7d0ddcf

Please sign in to comment.