From 8a7a7e53006ba94312aa2c165af5fddcd0714427 Mon Sep 17 00:00:00 2001 From: Arrowana <8245419+Arrowana@users.noreply.github.com> Date: Mon, 19 Apr 2021 19:20:01 +1000 Subject: [PATCH 1/4] start moving to using @solana/spl-token-swap and copy/pasta some necessary projectserum fork changes --- package.json | 8 +- src/models/pool.ts | 2 +- src/models/tokenSwap.ts | 477 +-------------------------------------- src/utils/accounts.tsx | 1 + src/utils/connection.tsx | 3 +- src/utils/ids.tsx | 9 +- src/utils/pools.tsx | 39 ++-- yarn.lock | 447 ++++++++++++++++++++---------------- 8 files changed, 289 insertions(+), 697 deletions(-) diff --git a/package.json b/package.json index 9c7e2daff..3908d12df 100644 --- a/package.json +++ b/package.json @@ -8,10 +8,10 @@ "@ledgerhq/hw-transport-webusb": "^5.45.0", "@project-serum/serum": "^0.13.33", "@project-serum/sol-wallet-adapter": "^0.1.1", - "@solana/spl-token": "0.0.11", - "@solana/spl-token-registry": "^0.2.0", - "@solana/spl-token-swap": "0.0.2", - "@solana/web3.js": "^1.2.5", + "@solana/spl-token": "^0.1.3", + "@solana/spl-token-registry": "^0.2.58", + "@solana/spl-token-swap": "^0.1.0", + "@solana/web3.js": "^1.4.0", "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.5.0", "@testing-library/user-event": "^7.2.1", diff --git a/src/models/pool.ts b/src/models/pool.ts index dfe8fa073..4e2a2bc7d 100644 --- a/src/models/pool.ts +++ b/src/models/pool.ts @@ -10,7 +10,7 @@ export interface PoolInfo { holdingAccounts: PublicKey[]; holdingMints: PublicKey[]; mint: PublicKey; - feeAccount?: PublicKey; + feeAccount: PublicKey; }; legacy: boolean; raw: { diff --git a/src/models/tokenSwap.ts b/src/models/tokenSwap.ts index 415119db6..608c52eaa 100644 --- a/src/models/tokenSwap.ts +++ b/src/models/tokenSwap.ts @@ -1,9 +1,4 @@ -import { Numberu64 } from "@solana/spl-token-swap"; -import { PublicKey, Account, TransactionInstruction } from "@solana/web3.js"; import * as BufferLayout from "buffer-layout"; -import { CurveType, PoolConfig } from "./pool"; - -export { TokenSwap } from "@solana/spl-token-swap"; /** * Layout for a public key @@ -63,474 +58,4 @@ export const TokenSwapLayoutV1: typeof BufferLayout.Structure = BufferLayout.str uint64("ownerWithdrawFeeDenominator"), BufferLayout.blob(16, "padding"), ] -); - -const CURVE_NODE = BufferLayout.union( - BufferLayout.u8(), - BufferLayout.blob(32), - "curve" -); -CURVE_NODE.addVariant(0, BufferLayout.struct([]), "constantProduct"); -CURVE_NODE.addVariant( - 1, - BufferLayout.struct([BufferLayout.nu64("token_b_price")]), - "constantPrice" -); -CURVE_NODE.addVariant(2, BufferLayout.struct([]), "stable"); -CURVE_NODE.addVariant( - 3, - BufferLayout.struct([BufferLayout.nu64("token_b_offset")]), - "offset" -); - -export const TokenSwapLayout: typeof BufferLayout.Structure = BufferLayout.struct( - [ - BufferLayout.u8("version"), - BufferLayout.u8("isInitialized"), - BufferLayout.u8("nonce"), - publicKey("tokenProgramId"), - publicKey("tokenAccountA"), - publicKey("tokenAccountB"), - publicKey("tokenPool"), - publicKey("mintA"), - publicKey("mintB"), - publicKey("feeAccount"), - FEE_LAYOUT, - CURVE_NODE, - ] -); - -export const createInitSwapInstruction = ( - tokenSwapAccount: Account, - authority: PublicKey, - tokenAccountA: PublicKey, - tokenAccountB: PublicKey, - tokenPool: PublicKey, - feeAccount: PublicKey, - destinationAccount: PublicKey, - tokenProgramId: PublicKey, - swapProgramId: PublicKey, - nonce: number, - config: PoolConfig, - isLatest: boolean -): TransactionInstruction => { - const keys = [ - { pubkey: tokenSwapAccount.publicKey, isSigner: false, isWritable: true }, - { pubkey: authority, isSigner: false, isWritable: false }, - { pubkey: tokenAccountA, isSigner: false, isWritable: false }, - { pubkey: tokenAccountB, isSigner: false, isWritable: false }, - { pubkey: tokenPool, isSigner: false, isWritable: true }, - { pubkey: feeAccount, isSigner: false, isWritable: false }, - { pubkey: destinationAccount, isSigner: false, isWritable: true }, - { pubkey: tokenProgramId, isSigner: false, isWritable: false }, - ]; - - let data = Buffer.alloc(1024); - if (isLatest) { - const fields = [ - BufferLayout.u8("instruction"), - BufferLayout.u8("nonce"), - BufferLayout.nu64("tradeFeeNumerator"), - BufferLayout.nu64("tradeFeeDenominator"), - BufferLayout.nu64("ownerTradeFeeNumerator"), - BufferLayout.nu64("ownerTradeFeeDenominator"), - BufferLayout.nu64("ownerWithdrawFeeNumerator"), - BufferLayout.nu64("ownerWithdrawFeeDenominator"), - BufferLayout.nu64("hostFeeNumerator"), - BufferLayout.nu64("hostFeeDenominator"), - BufferLayout.u8("curveType"), - ]; - - if (config.curveType === CurveType.ConstantProductWithOffset) { - fields.push(BufferLayout.nu64("token_b_offset")); - fields.push(BufferLayout.blob(24, "padding")); - } else if (config.curveType === CurveType.ConstantPrice) { - fields.push(BufferLayout.nu64("token_b_price")); - fields.push(BufferLayout.blob(24, "padding")); - } else { - fields.push(BufferLayout.blob(32, "padding")); - } - - const commandDataLayout = BufferLayout.struct(fields); - - const { fees, ...rest } = config; - - const encodeLength = commandDataLayout.encode( - { - instruction: 0, // InitializeSwap instruction - nonce, - ...fees, - ...rest, - }, - data - ); - data = data.slice(0, encodeLength); - } else { - const commandDataLayout = BufferLayout.struct([ - BufferLayout.u8("instruction"), - BufferLayout.u8("nonce"), - BufferLayout.u8("curveType"), - BufferLayout.nu64("tradeFeeNumerator"), - BufferLayout.nu64("tradeFeeDenominator"), - BufferLayout.nu64("ownerTradeFeeNumerator"), - BufferLayout.nu64("ownerTradeFeeDenominator"), - BufferLayout.nu64("ownerWithdrawFeeNumerator"), - BufferLayout.nu64("ownerWithdrawFeeDenominator"), - BufferLayout.blob(16, "padding"), - ]); - - const encodeLength = commandDataLayout.encode( - { - instruction: 0, // InitializeSwap instruction - nonce, - curveType: config.curveType, - tradeFeeNumerator: config.fees.tradeFeeNumerator, - tradeFeeDenominator: config.fees.tradeFeeDenominator, - ownerTradeFeeNumerator: config.fees.ownerTradeFeeNumerator, - ownerTradeFeeDenominator: config.fees.ownerTradeFeeDenominator, - ownerWithdrawFeeNumerator: config.fees.ownerWithdrawFeeNumerator, - ownerWithdrawFeeDenominator: config.fees.ownerWithdrawFeeDenominator, - }, - data - ); - data = data.slice(0, encodeLength); - } - - return new TransactionInstruction({ - keys, - programId: swapProgramId, - data, - }); -}; - -export const depositInstruction = ( - tokenSwap: PublicKey, - authority: PublicKey, - transferAuthority: PublicKey, - sourceA: PublicKey, - sourceB: PublicKey, - intoA: PublicKey, - intoB: PublicKey, - poolToken: PublicKey, - poolAccount: PublicKey, - swapProgramId: PublicKey, - tokenProgramId: PublicKey, - poolTokenAmount: number | Numberu64, - maximumTokenA: number | Numberu64, - maximumTokenB: number | Numberu64, - isLatest: boolean -): TransactionInstruction => { - const dataLayout = BufferLayout.struct([ - BufferLayout.u8("instruction"), - uint64("poolTokenAmount"), - uint64("maximumTokenA"), - uint64("maximumTokenB"), - ]); - - const data = Buffer.alloc(dataLayout.span); - dataLayout.encode( - { - instruction: 2, // Deposit instruction - poolTokenAmount: new Numberu64(poolTokenAmount).toBuffer(), - maximumTokenA: new Numberu64(maximumTokenA).toBuffer(), - maximumTokenB: new Numberu64(maximumTokenB).toBuffer(), - }, - data - ); - - const keys = isLatest - ? [ - { pubkey: tokenSwap, isSigner: false, isWritable: false }, - { pubkey: authority, isSigner: false, isWritable: false }, - { pubkey: transferAuthority, isSigner: true, isWritable: false }, - { pubkey: sourceA, isSigner: false, isWritable: true }, - { pubkey: sourceB, isSigner: false, isWritable: true }, - { pubkey: intoA, isSigner: false, isWritable: true }, - { pubkey: intoB, isSigner: false, isWritable: true }, - { pubkey: poolToken, isSigner: false, isWritable: true }, - { pubkey: poolAccount, isSigner: false, isWritable: true }, - { pubkey: tokenProgramId, isSigner: false, isWritable: false }, - ] - : [ - { pubkey: tokenSwap, isSigner: false, isWritable: false }, - { pubkey: authority, isSigner: false, isWritable: false }, - { pubkey: sourceA, isSigner: false, isWritable: true }, - { pubkey: sourceB, isSigner: false, isWritable: true }, - { pubkey: intoA, isSigner: false, isWritable: true }, - { pubkey: intoB, isSigner: false, isWritable: true }, - { pubkey: poolToken, isSigner: false, isWritable: true }, - { pubkey: poolAccount, isSigner: false, isWritable: true }, - { pubkey: tokenProgramId, isSigner: false, isWritable: false }, - ]; - return new TransactionInstruction({ - keys, - programId: swapProgramId, - data, - }); -}; - -export const depositExactOneInstruction = ( - tokenSwap: PublicKey, - authority: PublicKey, - transferAuthority: PublicKey, - source: PublicKey, - intoA: PublicKey, - intoB: PublicKey, - poolToken: PublicKey, - poolAccount: PublicKey, - swapProgramId: PublicKey, - tokenProgramId: PublicKey, - sourceTokenAmount: number | Numberu64, - minimumPoolTokenAmount: number | Numberu64, - isLatest: boolean -): TransactionInstruction => { - const dataLayout = BufferLayout.struct([ - BufferLayout.u8("instruction"), - uint64("sourceTokenAmount"), - uint64("minimumPoolTokenAmount"), - ]); - - const data = Buffer.alloc(dataLayout.span); - dataLayout.encode( - { - instruction: 4, // DepositExactOne instruction - sourceTokenAmount: new Numberu64(sourceTokenAmount).toBuffer(), - minimumPoolTokenAmount: new Numberu64(minimumPoolTokenAmount).toBuffer(), - }, - data - ); - - const keys = isLatest - ? [ - { pubkey: tokenSwap, isSigner: false, isWritable: false }, - { pubkey: authority, isSigner: false, isWritable: false }, - { pubkey: transferAuthority, isSigner: true, isWritable: false }, - { pubkey: source, isSigner: false, isWritable: true }, - { pubkey: intoA, isSigner: false, isWritable: true }, - { pubkey: intoB, isSigner: false, isWritable: true }, - { pubkey: poolToken, isSigner: false, isWritable: true }, - { pubkey: poolAccount, isSigner: false, isWritable: true }, - { pubkey: tokenProgramId, isSigner: false, isWritable: false }, - ] - : [ - { pubkey: tokenSwap, isSigner: false, isWritable: false }, - { pubkey: authority, isSigner: false, isWritable: false }, - { pubkey: source, isSigner: false, isWritable: true }, - { pubkey: intoA, isSigner: false, isWritable: true }, - { pubkey: intoB, isSigner: false, isWritable: true }, - { pubkey: poolToken, isSigner: false, isWritable: true }, - { pubkey: poolAccount, isSigner: false, isWritable: true }, - { pubkey: tokenProgramId, isSigner: false, isWritable: false }, - ]; - return new TransactionInstruction({ - keys, - programId: swapProgramId, - data, - }); -}; - -export const withdrawInstruction = ( - tokenSwap: PublicKey, - authority: PublicKey, - transferAuthority: PublicKey, - poolMint: PublicKey, - feeAccount: PublicKey | undefined, - sourcePoolAccount: PublicKey, - fromA: PublicKey, - fromB: PublicKey, - userAccountA: PublicKey, - userAccountB: PublicKey, - swapProgramId: PublicKey, - tokenProgramId: PublicKey, - poolTokenAmount: number | Numberu64, - minimumTokenA: number | Numberu64, - minimumTokenB: number | Numberu64, - isLatest: boolean -): TransactionInstruction => { - const dataLayout = BufferLayout.struct([ - BufferLayout.u8("instruction"), - uint64("poolTokenAmount"), - uint64("minimumTokenA"), - uint64("minimumTokenB"), - ]); - - const data = Buffer.alloc(dataLayout.span); - dataLayout.encode( - { - instruction: 3, // Withdraw instruction - poolTokenAmount: new Numberu64(poolTokenAmount).toBuffer(), - minimumTokenA: new Numberu64(minimumTokenA).toBuffer(), - minimumTokenB: new Numberu64(minimumTokenB).toBuffer(), - }, - data - ); - - const keys = isLatest - ? [ - { pubkey: tokenSwap, isSigner: false, isWritable: false }, - { pubkey: authority, isSigner: false, isWritable: false }, - { pubkey: transferAuthority, isSigner: true, isWritable: false }, - { pubkey: poolMint, isSigner: false, isWritable: true }, - { pubkey: sourcePoolAccount, isSigner: false, isWritable: true }, - { pubkey: fromA, isSigner: false, isWritable: true }, - { pubkey: fromB, isSigner: false, isWritable: true }, - { pubkey: userAccountA, isSigner: false, isWritable: true }, - { pubkey: userAccountB, isSigner: false, isWritable: true }, - ] - : [ - { pubkey: tokenSwap, isSigner: false, isWritable: false }, - { pubkey: authority, isSigner: false, isWritable: false }, - { pubkey: poolMint, isSigner: false, isWritable: true }, - { pubkey: sourcePoolAccount, isSigner: false, isWritable: true }, - { pubkey: fromA, isSigner: false, isWritable: true }, - { pubkey: fromB, isSigner: false, isWritable: true }, - { pubkey: userAccountA, isSigner: false, isWritable: true }, - { pubkey: userAccountB, isSigner: false, isWritable: true }, - ]; - - if (feeAccount) { - keys.push({ pubkey: feeAccount, isSigner: false, isWritable: true }); - } - keys.push({ pubkey: tokenProgramId, isSigner: false, isWritable: false }); - - return new TransactionInstruction({ - keys, - programId: swapProgramId, - data, - }); -}; - -export const withdrawExactOneInstruction = ( - tokenSwap: PublicKey, - authority: PublicKey, - transferAuthority: PublicKey, - poolMint: PublicKey, - sourcePoolAccount: PublicKey, - fromA: PublicKey, - fromB: PublicKey, - userAccount: PublicKey, - feeAccount: PublicKey | undefined, - swapProgramId: PublicKey, - tokenProgramId: PublicKey, - sourceTokenAmount: number | Numberu64, - maximumTokenAmount: number | Numberu64, - isLatest: boolean -): TransactionInstruction => { - const dataLayout = BufferLayout.struct([ - BufferLayout.u8("instruction"), - uint64("sourceTokenAmount"), - uint64("maximumTokenAmount"), - ]); - - const data = Buffer.alloc(dataLayout.span); - dataLayout.encode( - { - instruction: 5, // WithdrawExactOne instruction - sourceTokenAmount: new Numberu64(sourceTokenAmount).toBuffer(), - maximumTokenAmount: new Numberu64(maximumTokenAmount).toBuffer(), - }, - data - ); - - const keys = isLatest - ? [ - { pubkey: tokenSwap, isSigner: false, isWritable: false }, - { pubkey: authority, isSigner: false, isWritable: false }, - { pubkey: transferAuthority, isSigner: true, isWritable: false }, - { pubkey: poolMint, isSigner: false, isWritable: true }, - { pubkey: sourcePoolAccount, isSigner: false, isWritable: true }, - { pubkey: fromA, isSigner: false, isWritable: true }, - { pubkey: fromB, isSigner: false, isWritable: true }, - { pubkey: userAccount, isSigner: false, isWritable: true }, - ] - : [ - { pubkey: tokenSwap, isSigner: false, isWritable: false }, - { pubkey: authority, isSigner: false, isWritable: false }, - { pubkey: poolMint, isSigner: false, isWritable: true }, - { pubkey: sourcePoolAccount, isSigner: false, isWritable: true }, - { pubkey: fromA, isSigner: false, isWritable: true }, - { pubkey: fromB, isSigner: false, isWritable: true }, - { pubkey: userAccount, isSigner: false, isWritable: true }, - ]; - - if (feeAccount) { - keys.push({ pubkey: feeAccount, isSigner: false, isWritable: true }); - } - keys.push({ pubkey: tokenProgramId, isSigner: false, isWritable: false }); - - return new TransactionInstruction({ - keys, - programId: swapProgramId, - data, - }); -}; - -export const swapInstruction = ( - tokenSwap: PublicKey, - authority: PublicKey, - transferAuthority: PublicKey, - userSource: PublicKey, - poolSource: PublicKey, - poolDestination: PublicKey, - userDestination: PublicKey, - poolMint: PublicKey, - feeAccount: PublicKey, - swapProgramId: PublicKey, - tokenProgramId: PublicKey, - amountIn: number | Numberu64, - minimumAmountOut: number | Numberu64, - programOwner: PublicKey | undefined, - isLatest: boolean -): TransactionInstruction => { - const dataLayout = BufferLayout.struct([ - BufferLayout.u8("instruction"), - uint64("amountIn"), - uint64("minimumAmountOut"), - ]); - - const keys = isLatest - ? [ - { pubkey: tokenSwap, isSigner: false, isWritable: false }, - { pubkey: authority, isSigner: false, isWritable: false }, - { pubkey: transferAuthority, isSigner: true, isWritable: false }, - { pubkey: userSource, isSigner: false, isWritable: true }, - { pubkey: poolSource, isSigner: false, isWritable: true }, - { pubkey: poolDestination, isSigner: false, isWritable: true }, - { pubkey: userDestination, isSigner: false, isWritable: true }, - { pubkey: poolMint, isSigner: false, isWritable: true }, - { pubkey: feeAccount, isSigner: false, isWritable: true }, - { pubkey: tokenProgramId, isSigner: false, isWritable: false }, - ] - : [ - { pubkey: tokenSwap, isSigner: false, isWritable: false }, - { pubkey: authority, isSigner: false, isWritable: false }, - { pubkey: userSource, isSigner: false, isWritable: true }, - { pubkey: poolSource, isSigner: false, isWritable: true }, - { pubkey: poolDestination, isSigner: false, isWritable: true }, - { pubkey: userDestination, isSigner: false, isWritable: true }, - { pubkey: poolMint, isSigner: false, isWritable: true }, - { pubkey: feeAccount, isSigner: false, isWritable: true }, - { pubkey: tokenProgramId, isSigner: false, isWritable: false }, - ]; - - // optional depending on the build of token-swap program - if (programOwner) { - keys.push({ pubkey: programOwner, isSigner: false, isWritable: true }); - } - - const data = Buffer.alloc(dataLayout.span); - dataLayout.encode( - { - instruction: 1, // Swap instruction - amountIn: new Numberu64(amountIn).toBuffer(), - minimumAmountOut: new Numberu64(minimumAmountOut).toBuffer(), - }, - data - ); - - return new TransactionInstruction({ - keys, - programId: swapProgramId, - data, - }); -}; +); \ No newline at end of file diff --git a/src/utils/accounts.tsx b/src/utils/accounts.tsx index 836de85f5..af30fed3c 100644 --- a/src/utils/accounts.tsx +++ b/src/utils/accounts.tsx @@ -302,6 +302,7 @@ function wrapNativeAccount( pubkey: pubkey, account, info: { + address: pubkey, mint: WRAPPED_SOL_MINT, owner: pubkey, amount: new u64(account.lamports), diff --git a/src/utils/connection.tsx b/src/utils/connection.tsx index bc6022590..5a09252e4 100644 --- a/src/utils/connection.tsx +++ b/src/utils/connection.tsx @@ -1,6 +1,7 @@ import { useLocalStorageState } from "./utils"; import { Account, + Cluster, clusterApiUrl, Connection, PublicKey, @@ -18,7 +19,7 @@ import { } from "@solana/spl-token-registry"; import { cache, getMultipleAccounts } from "./accounts"; -export type ENV = "mainnet-beta" | "testnet" | "devnet" | "localnet"; +export type ENV = Cluster | "localnet"; export const ENDPOINTS = [ { diff --git a/src/utils/ids.tsx b/src/utils/ids.tsx index cf57610fe..eae6a2415 100644 --- a/src/utils/ids.tsx +++ b/src/utils/ids.tsx @@ -1,5 +1,5 @@ +import { TokenSwapLayout } from "@solana/spl-token-swap"; import { PublicKey } from "@solana/web3.js"; -import { TokenSwapLayout } from "../models"; export const WRAPPED_SOL_MINT = new PublicKey( "So11111111111111111111111111111111111111112" @@ -7,6 +7,7 @@ export const WRAPPED_SOL_MINT = new PublicKey( let TOKEN_PROGRAM_ID = new PublicKey( "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" ); +const CURRENT_SWAP_PROGRAM_ID = new PublicKey("SwaPpA9LAaLfeLi3a68M4DjnLqgtticKg6CnyNwgAC8"); let SWAP_PROGRAM_ID: PublicKey; let SWAP_PROGRAM_LEGACY_IDS: PublicKey[]; @@ -31,7 +32,7 @@ export const PROGRAM_IDS = [ name: "mainnet-beta", swap: () => ({ current: { - pubkey: new PublicKey("SwaPpA9LAaLfeLi3a68M4DjnLqgtticKg6CnyNwgAC8"), + pubkey: CURRENT_SWAP_PROGRAM_ID, layout: TokenSwapLayout, }, legacy: [new PublicKey("9qvG1zUp8xF1Bi4m6UdRNby1BAAuaDrUxSpv4CmRRMjL")], @@ -41,7 +42,7 @@ export const PROGRAM_IDS = [ name: "testnet", swap: () => ({ current: { - pubkey: new PublicKey("SwaPpA9LAaLfeLi3a68M4DjnLqgtticKg6CnyNwgAC8"), + pubkey: CURRENT_SWAP_PROGRAM_ID, layout: TokenSwapLayout, }, legacy: [], @@ -51,7 +52,7 @@ export const PROGRAM_IDS = [ name: "devnet", swap: () => ({ current: { - pubkey: new PublicKey("SwaPpA9LAaLfeLi3a68M4DjnLqgtticKg6CnyNwgAC8"), + pubkey: CURRENT_SWAP_PROGRAM_ID, layout: TokenSwapLayout, }, legacy: [], diff --git a/src/utils/pools.tsx b/src/utils/pools.tsx index e2c0866a4..1f219421a 100644 --- a/src/utils/pools.tsx +++ b/src/utils/pools.tsx @@ -27,17 +27,11 @@ import { LiquidityComponent, PoolInfo, TokenAccount, - createInitSwapInstruction, - TokenSwapLayout, - depositInstruction, - withdrawInstruction, TokenSwapLayoutLegacyV0 as TokenSwapLayoutV0, TokenSwapLayoutV1, - swapInstruction, PoolConfig, - depositExactOneInstruction, - withdrawExactOneInstruction, } from "./../models"; +import { TokenSwap, TokenSwapLayout } from "@solana/spl-token-swap"; const LIQUIDITY_TOKEN_PRECISION = 8; @@ -128,7 +122,7 @@ export const removeLiquidity = async ( // withdraw instructions.push( - withdrawInstruction( + TokenSwap.withdrawAllTokenTypesInstruction( pool.pubkeys.account, authority, transferAuthority.publicKey, @@ -384,11 +378,11 @@ export const swap = async ( pool.pubkeys.mint, signers ) - : undefined; + : null; // swap instructions.push( - swapInstruction( + TokenSwap.swapInstruction( pool.pubkeys.account, authority, transferAuthority.publicKey, @@ -398,12 +392,11 @@ export const swap = async ( toAccount, pool.pubkeys.mint, pool.pubkeys.feeAccount, + hostFeeAccount, pool.pubkeys.program, programIds().token, amountIn, - minAmountOut, - hostFeeAccount, - isLatestSwap + minAmountOut ) ); @@ -845,7 +838,7 @@ async function _addLiquidityExistingPool( // deposit instructions.push( - depositInstruction( + TokenSwap.depositAllTokenTypesInstruction( pool.pubkeys.account, authority, transferAuthority.publicKey, @@ -859,8 +852,7 @@ async function _addLiquidityExistingPool( programIds().token, liquidity, amount0, - amount1, - isLatestSwap + amount1 ) ); @@ -1353,7 +1345,7 @@ async function _addLiquidityNewPool( }); instructions.push( - createInitSwapInstruction( + TokenSwap.createInitSwapInstruction( tokenSwapAccount, authority, holdingAccounts[0].publicKey, @@ -1364,13 +1356,20 @@ async function _addLiquidityNewPool( programIds().token, programIds().swap, nonce, - options, - programIds().swapLayout === TokenSwapLayout + options.fees.tradeFeeNumerator, + options.fees.tradeFeeDenominator, + options.fees.ownerTradeFeeNumerator, + options.fees.ownerTradeFeeDenominator, + options.fees.ownerWithdrawFeeNumerator, + options.fees.ownerWithdrawFeeDenominator, + options.fees.hostFeeNumerator, + options.fees.hostFeeDenominator, + options.curveType ) ); // All instructions didn't fit in single transaction - // initialize and provide inital liquidity to swap in 2nd (this prevents loss of funds) + // initialize and provide initial liquidity to swap in 2nd (this prevents loss of funds) tx = await sendTransaction( connection, wallet, diff --git a/yarn.lock b/yarn.lock index d5ec7fdaf..7d1e4425e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1158,14 +1158,14 @@ dependencies: regenerator-runtime "^0.13.4" -"@babel/runtime@^7.0.0", "@babel/runtime@^7.1.2", "@babel/runtime@^7.10.1", "@babel/runtime@^7.10.2", "@babel/runtime@^7.10.3", "@babel/runtime@^7.10.4", "@babel/runtime@^7.10.5", "@babel/runtime@^7.11.1", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.1", "@babel/runtime@^7.3.1", "@babel/runtime@^7.3.4", "@babel/runtime@^7.4.5", "@babel/runtime@^7.5.1", "@babel/runtime@^7.7.2", "@babel/runtime@^7.8.4": +"@babel/runtime@^7.0.0", "@babel/runtime@^7.1.2", "@babel/runtime@^7.10.1", "@babel/runtime@^7.10.2", "@babel/runtime@^7.10.3", "@babel/runtime@^7.10.4", "@babel/runtime@^7.10.5", "@babel/runtime@^7.11.1", "@babel/runtime@^7.12.1", "@babel/runtime@^7.3.4", "@babel/runtime@^7.4.5", "@babel/runtime@^7.5.1", "@babel/runtime@^7.7.2", "@babel/runtime@^7.8.4": version "7.12.1" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.12.1.tgz#b4116a6b6711d010b2dad3b7b6e43bf1b9954740" integrity sha512-J5AIf3vPj3UwXaAzb5j1xM4WAQDX3EMgemF8rjCP3SoW09LfRKAXQKt6CoVYl230P6iWdRcBbnLDDdnqWxZSCA== dependencies: regenerator-runtime "^0.13.4" -"@babel/runtime@^7.12.5": +"@babel/runtime@^7.11.2", "@babel/runtime@^7.12.5", "@babel/runtime@^7.3.1": version "7.13.10" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.13.10.tgz#47d42a57b6095f4468da440388fdbad8bebf0d7d" integrity sha512-4QPkjJq6Ns3V/RgpEahRk+AGfL0eO6RHHtTWoNNr5mO49G6B5+X6d6THgWEAvTrznU5xYpbAlVKRYcsCgh/Akw== @@ -1507,58 +1507,37 @@ resolved "https://registry.yarnpkg.com/@sheerun/mutationobserver-shim/-/mutationobserver-shim-0.3.3.tgz#5405ee8e444ed212db44e79351f0c70a582aae25" integrity sha512-DetpxZw1fzPD5xUBrIAoplLChO2VB8DlL5Gg+I1IR9b2wPqYIca2WSUxL5g1vLeR4MsQq1NeWriXAVffV+U1Fw== -"@solana/spl-token-registry@^0.2.0": - version "0.2.0" - resolved "https://registry.yarnpkg.com/@solana/spl-token-registry/-/spl-token-registry-0.2.0.tgz#cd32d13c6056b0b6d722880e240663ebc5b39ad7" - integrity sha512-DC1gQDthODgCa0Nd5sPuoGpgEG3xdxQRoggfFFLQpwX689zILabvmVj6v6hF8bN8fGEpADZK1Fp8pwD427jkUQ== +"@solana/spl-token-registry@^0.2.58": + version "0.2.58" + resolved "https://registry.yarnpkg.com/@solana/spl-token-registry/-/spl-token-registry-0.2.58.tgz#a8216269b0b9b80f7ec7e6fe2b691df1e1ccc745" + integrity sha512-3J21L2VKdqW+i46GzqYujgv0Rv5K1KjKqGDjN4O/zsfo6k+OHV1nzYHA4l9nGh5YuVFiIaBdWGuUzHIcXwAI9Q== dependencies: - cross-fetch "^3.0.6" + cross-fetch "3.0.6" -"@solana/spl-token-swap@0.0.2": - version "0.0.2" - resolved "https://registry.yarnpkg.com/@solana/spl-token-swap/-/spl-token-swap-0.0.2.tgz#b7afa943d27fc4c5100ea3ab6fcd518bcc05fed3" - integrity sha512-dnOTmLDb+eroVUvJXYJ4qKIpfD2tvsbKIZ5dnx1RUrZng1oGj9nEKqxOKzMCFgCj/qjjuPnFQQRWn0u+hwLvbw== +"@solana/spl-token-swap@^0.1.0": + version "0.1.0" + resolved "https://registry.yarnpkg.com/@solana/spl-token-swap/-/spl-token-swap-0.1.0.tgz#a1bc2b0c96edae8b31bb2cc000ebacdc36e131c8" + integrity sha512-h0ntp6xwRZBEKDd6oNhJTbPISjIfeGm0eqQqAccTkeluo1zHve4dnUChTKF4MQ+JqXjfqd6z6DJjfa0+dGA37w== dependencies: "@babel/runtime" "^7.11.2" - "@solana/web3.js" "^0.78.0" + "@solana/web3.js" "^0.90.0" bn.js "^5.1.3" buffer-layout "^1.2.0" dotenv "8.2.0" json-to-pretty-yaml "^1.2.2" mkdirp "1.0.4" -"@solana/spl-token@0.0.11": - version "0.0.11" - resolved "https://registry.yarnpkg.com/@solana/spl-token/-/spl-token-0.0.11.tgz#5b978d38022beccaafac8b1dd1f3f575a39ebd1b" - integrity sha512-Upp+x5B18UegyoDfDJFbkhtL5ynuJBe1AFCbhbSasp+fQP4xx9Lhq+w3rheZPPOnCYwgRfAodABwCO/j7ZFKPg== +"@solana/spl-token@^0.1.3": + version "0.1.3" + resolved "https://registry.yarnpkg.com/@solana/spl-token/-/spl-token-0.1.3.tgz#6bf7c1a74cd95dabe8b8164e4c13b987db5be3bd" + integrity sha512-M251on5RDz8VQXoKoQPeLANEyI4qhThKLZBeUiLbFZ93KRgouGfmV5D/bUZXkLF75PlLcARIzU9ptoHOlZ6SbQ== dependencies: "@babel/runtime" "^7.10.5" - "@solana/web3.js" "^0.78.0" - bn.js "^5.0.0" + "@solana/web3.js" "^1.2.2" + bn.js "^5.1.0" + buffer "6.0.3" buffer-layout "^1.2.0" dotenv "8.2.0" - mkdirp "1.0.4" - -"@solana/web3.js@^0.78.0": - version "0.78.4" - resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-0.78.4.tgz#a942d02e353b2c3ff7ddc94cb6846b5a98887bc2" - integrity sha512-Zt6LN35K2sQaQfgWbNjp91qGa6dHccXTQEoojXEo0NqZ/CQqmzretgSI/3kxKUiuvLTY/1WltVM7CKRkwMNRFA== - dependencies: - "@babel/runtime" "^7.3.1" - bn.js "^5.0.0" - bs58 "^4.0.1" - buffer "^5.4.3" - buffer-layout "^1.2.0" - crypto-hash "^1.2.2" - esdoc-inject-style-plugin "^1.0.0" - jayson "^3.0.1" - mz "^2.7.0" - node-fetch "^2.2.0" - npm-run-all "^4.1.5" - rpc-websockets "^7.4.2" - superstruct "^0.8.3" - tweetnacl "^1.0.0" - ws "^7.0.0" "@solana/web3.js@^0.90.0": version "0.90.5" @@ -1583,10 +1562,10 @@ tweetnacl "^1.0.0" ws "^7.0.0" -"@solana/web3.js@^1.2.5": - version "1.2.6" - resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.2.6.tgz#ee57c28d2639d95cc5de1179babe695870041c94" - integrity sha512-TAAC5+zq7BHn3+mz6jpJlKFvcTqy0Fj/a+Fq3T5MVvsidlVTmIh18qiGPpe3Ve4eMZquF7JcytS8JanEyvgO6g== +"@solana/web3.js@^1.2.2", "@solana/web3.js@^1.4.0": + version "1.4.0" + resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.4.0.tgz#60870f49ba3336d5754a9cff2bfd775466b6a05f" + integrity sha512-xSTvgzgOf9+XHe8E09inlTbrHSYHVQ4uQlcd9M+0hpyQ9uLOtEhUcNnegtIC3Hpz6OQ0awVJU29ppFkxhzM3aw== dependencies: "@babel/runtime" "^7.12.5" bn.js "^5.0.0" @@ -1814,9 +1793,9 @@ base-x "^3.0.6" "@types/connect@^3.4.33": - version "3.4.33" - resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.33.tgz#31610c901eca573b8713c3330abc6e6b9f588546" - integrity sha512-2+FrkXY4zllzTNfJth7jOqEHC+enpLeGslEhpnTAkg21GkRrWV4SsAtqchtT4YS9/nODBU2/ZfsBY2X4J/dX7A== + version "3.4.34" + resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.34.tgz#170a40223a6d666006d93ca128af2beb1d9b1901" + integrity sha512-ePPA/JuI+X0vb+gSWlPKOY0NdNAie/rPUqX2GUPpbZwiKTkSPhjXWuee47E4MtE54QVzGCQMQkAL6JhV2E1+cQ== dependencies: "@types/node" "*" @@ -1833,9 +1812,9 @@ integrity sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag== "@types/express-serve-static-core@^4.17.9": - version "4.17.13" - resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.13.tgz#d9af025e925fc8b089be37423b8d1eac781be084" - integrity sha512-RgDi5a4nuzam073lRGKTUIaL3eF2+H7LJvJ8eUnCI0wA6SNjXc44DCmWNiTLs/AZ7QlsFWZiw/gTG3nSQGL0fA== + version "4.17.19" + resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.19.tgz#00acfc1632e729acac4f1530e9e16f6dd1508a1d" + integrity sha512-DJOSHzX7pCiSElWaGR8kCprwibCB/3yW6vcT8VG3P0SJjnv19gnWG/AZMfM60Xj/YJIp/YCaDHyvzsFVeniARA== dependencies: "@types/node" "*" "@types/qs" "*" @@ -1914,9 +1893,9 @@ "@types/node" "*" "@types/lodash@^4.14.159": - version "4.14.162" - resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.162.tgz#65d78c397e0d883f44afbf1f7ba9867022411470" - integrity sha512-alvcho1kRUnnD1Gcl4J+hK0eencvzq9rmzvFPRmP5rPHx9VVsJj6bKLTATPVf9ktgv4ujzh7T+XWKp+jhuODig== + version "4.14.168" + resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.168.tgz#fe24632e79b7ade3f132891afff86caa5e5ce008" + integrity sha512-oVfRvqHV/V6D1yifJbVRU3TMp8OT6o6BG+U9MkwuJ3U8/CsDHvalRpsxBqivn71ztOFZBTfJMvETbqHiaNSj7Q== "@types/minimatch@*": version "3.0.3" @@ -1924,11 +1903,16 @@ integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA== "@types/node@*": - version "14.14.5" - resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.5.tgz#e92d3b8f76583efa26c1a63a21c9d3c1143daa29" - integrity sha512-H5Wn24s/ZOukBmDn03nnGTp18A60ny9AmCwnEcgJiTgSGsCO7k+NWP7zjCCbhlcnVCoI+co52dUAt9GMhOSULw== + version "14.14.41" + resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.41.tgz#d0b939d94c1d7bd53d04824af45f1139b8c45615" + integrity sha512-dueRKfaJL4RTtSa7bWeTK1M+VH+Gns73oCgzvYfHZywRCoPSd8EkXBL0mZ9unPTveBn+D9phZBaxuzpwjWkW0g== -"@types/node@^12.12.54", "@types/node@^12.12.62": +"@types/node@^12.12.54": + version "12.20.10" + resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.10.tgz#4dcb8a85a8f1211acafb88d72fafc7e3d2685583" + integrity sha512-TxCmnSSppKBBOzYzPR2BR25YlX5Oay8z2XGwFBInuA/Co0V9xJhLlW4kjbxKtgeNo3NOMbQP1A5Rc03y+XecPw== + +"@types/node@^12.12.62": version "12.19.2" resolved "https://registry.yarnpkg.com/@types/node/-/node-12.19.2.tgz#9565ed5c72ba96038fc3add643edd5e7820598e7" integrity sha512-SRH6QM0IMOBBFmDiJ75vlhcbUEYEquvSuhsVW9ijG20JvdFTfOrB1p6ddZxz5y/JNnbf+9HoHhjhOVSX2hsJyA== @@ -1949,9 +1933,9 @@ integrity sha512-1HcDas8SEj4z1Wc696tH56G8OlRaH/sqZOynNNB+HF0WOeXPaxTtbYzJY2oEfiUxjSKjhCKr+MvR7dCHcEelug== "@types/qs@*": - version "6.9.5" - resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.5.tgz#434711bdd49eb5ee69d90c1d67c354a9a8ecb18b" - integrity sha512-/JHkVHtx/REVG0VVToGRGH2+23hsYLHdyG+GrvoUGlGAd0ErauXDyvHtRI/7H7mzLm+tBCKA7pfcpkQ1lf58iQ== + version "6.9.6" + resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.6.tgz#df9c3c8b31a247ec315e6996566be3171df4b3b1" + integrity sha512-0/HnwIfW4ki2D8L8c9GVcG5I72s9jP5GSLVF0VIXDW00kmIpA6O33G7a8n59Tmh7Nz0WUC3rSb7PTY/sdW2JzA== "@types/range-parser@*": version "1.2.3" @@ -2877,9 +2861,9 @@ babylon@^6.18.0: integrity sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ== balanced-match@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" - integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c= + version "1.0.2" + resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" + integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== base-x@^3.0.2, base-x@^3.0.6: version "3.0.8" @@ -2888,11 +2872,16 @@ base-x@^3.0.2, base-x@^3.0.6: dependencies: safe-buffer "^5.0.1" -base64-js@^1.0.2, base64-js@^1.3.1: +base64-js@^1.0.2: version "1.3.1" resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.1.tgz#58ece8cb75dd07e71ed08c736abc5fac4dbf8df1" integrity sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g== +base64-js@^1.3.1: + version "1.5.1" + resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a" + integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA== + base@^0.11.1: version "0.11.2" resolved "https://registry.yarnpkg.com/base/-/base-0.11.2.tgz#7bde5ced145b6d551a90db87f83c558b4eb48a8f" @@ -2950,7 +2939,12 @@ bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.4.0: resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.9.tgz#26d556829458f9d1e81fc48952493d0ba3507828" integrity sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw== -bn.js@^5.0.0, bn.js@^5.1.1, bn.js@^5.1.2, bn.js@^5.1.3: +bn.js@^5.0.0, bn.js@^5.1.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.2.0.tgz#358860674396c6997771a9d051fcc1b57d4ae002" + integrity sha512-D7iWRBvnZE8ecXiLj/9wbxH7Tk79fAh8IHaTNq1RWRixsS02W+5qS+iE9yq6RYl0asXx5tw0bLhmT5pIfbSquw== + +bn.js@^5.1.1, bn.js@^5.1.2, bn.js@^5.1.3: version "5.1.3" resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.1.3.tgz#beca005408f642ebebea80b042b4d18d2ac0ee6b" integrity sha512-GkTiFpjFtUzU9CbMeJ5iazkCzGL3jrhzerzZIuqLABjbwRaFt33I9tUdSNryIptM+RxDet6OKm2WnLXzW51KsQ== @@ -3159,6 +3153,14 @@ buffer@6.0.1: base64-js "^1.3.1" ieee754 "^1.2.1" +buffer@6.0.3, buffer@^6.0.1: + version "6.0.3" + resolved "https://registry.yarnpkg.com/buffer/-/buffer-6.0.3.tgz#2ace578459cc8fbe2a70aaa8f52ee63b6a74c6c6" + integrity sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA== + dependencies: + base64-js "^1.3.1" + ieee754 "^1.2.1" + buffer@^4.3.0: version "4.9.2" resolved "https://registry.yarnpkg.com/buffer/-/buffer-4.9.2.tgz#230ead344002988644841ab0244af8c44bbe3ef8" @@ -3168,28 +3170,12 @@ buffer@^4.3.0: ieee754 "^1.1.4" isarray "^1.0.0" -buffer@^5.4.3: - version "5.6.1" - resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.6.1.tgz#b99419405f4290a7a1f20b51037cee9f1fbd7f6a" - integrity sha512-2z15UUHpS9/3tk9mY/q+Rl3rydOi7yMp5XWNQnRvoz+mJwiv8brqYwp9a+nOCtma6dwuEIxljD8W3ysVBZ05Vg== - dependencies: - base64-js "^1.3.1" - ieee754 "^1.1.13" - -buffer@^6.0.1: - version "6.0.3" - resolved "https://registry.yarnpkg.com/buffer/-/buffer-6.0.3.tgz#2ace578459cc8fbe2a70aaa8f52ee63b6a74c6c6" - integrity sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA== - dependencies: - base64-js "^1.3.1" - ieee754 "^1.2.1" - bufferutil@^4.0.1: - version "4.0.1" - resolved "https://registry.yarnpkg.com/bufferutil/-/bufferutil-4.0.1.tgz#3a177e8e5819a1243fe16b63a199951a7ad8d4a7" - integrity sha512-xowrxvpxojqkagPcWRQVXZl0YXhRhAtBEIq3VoER1NH5Mw1n1o0ojdspp+GS2J//2gCVyrzQDApQ4unGF+QOoA== + version "4.0.3" + resolved "https://registry.yarnpkg.com/bufferutil/-/bufferutil-4.0.3.tgz#66724b756bed23cd7c28c4d306d7994f9943cc6b" + integrity sha512-yEYTwGndELGvfXsImMBLop58eaGW+YdONi1fNjTINSY98tmMmFijBG6WXgdkfuLNt4imzQNtIE+eBp1PVpMCSw== dependencies: - node-gyp-build "~3.7.0" + node-gyp-build "^4.2.0" builtin-status-codes@^3.0.0: version "3.0.0" @@ -3266,6 +3252,14 @@ cache-base@^1.0.1: union-value "^1.0.0" unset-value "^1.0.0" +call-bind@^1.0.0, call-bind@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.2.tgz#b1d4e89e688119c3c9a903ad30abb2f6a919be3c" + integrity sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA== + dependencies: + function-bind "^1.1.1" + get-intrinsic "^1.0.2" + call-me-maybe@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/call-me-maybe/-/call-me-maybe-1.0.1.tgz#26d208ea89e37b5cbde60250a15f031c16a4d66b" @@ -3893,7 +3887,7 @@ create-hmac@^1.1.0, create-hmac@^1.1.4, create-hmac@^1.1.7: safe-buffer "^5.0.1" sha.js "^2.4.8" -cross-fetch@^3.0.6: +cross-fetch@3.0.6: version "3.0.6" resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.0.6.tgz#3a4040bc8941e653e0e9cf17f29ebcd177d3365c" integrity sha512-KBPUbqgFjzWlVcURG+Svp9TlhA5uliYtiNx/0r8nv0pdypeQCRJ9IaSIc3q/x3q8t3F75cHuwxVql1HFGHCNJQ== @@ -4480,9 +4474,9 @@ domelementtype@1, domelementtype@^1.3.0, domelementtype@^1.3.1: integrity sha512-BSKB+TSpMpFI/HOxCNr1O8aMOTZ8hT3pM3GQ0w/mWRmkhEDSFJkkyzz4XQsBV44BChwGkrDfMyjVD0eA2aFV3w== domelementtype@^2.0.1: - version "2.0.2" - resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-2.0.2.tgz#f3b6e549201e46f588b59463dd77187131fe6971" - integrity sha512-wFwTwCVebUrMgGeAwRL/NhZtHAUyT9n9yg4IMDwf10+6iCMxSkVq9MGCVEH+QZWo1nNidy8kNvwmv4zWHDTqvA== + version "2.2.0" + resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-2.2.0.tgz#9a0b6c2782ed6a1c7323d42267183df9bd8b1d57" + integrity sha512-DtBMo82pv1dFtUmHyr48beiuq792Sxohr+8Hm9zoxklYPfa6n0Z3Byjj2IV7bmr2IyqClnqEQhfgHJJ5QF0R5A== domexception@^1.0.1: version "1.0.1" @@ -4644,9 +4638,9 @@ entities@^1.1.1, entities@~1.1.1: integrity sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w== entities@^2.0.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/entities/-/entities-2.1.0.tgz#992d3129cf7df6870b96c57858c249a120f8b8b5" - integrity sha512-hCx1oky9PFrJ611mf0ifBLBRW8lUUVRlFolb5gWRfIELabBlbp9xZvrqZLZAs+NxFnbfQoeGd8wDkygjg7U85w== + version "2.2.0" + resolved "https://registry.yarnpkg.com/entities/-/entities-2.2.0.tgz#098dc90ebb83d8dffa089d55256b351d34c4da55" + integrity sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A== errno@^0.1.1, errno@^0.1.3, errno@~0.1.7: version "0.1.7" @@ -4662,7 +4656,7 @@ error-ex@^1.2.0, error-ex@^1.3.1: dependencies: is-arrayish "^0.2.1" -es-abstract@^1.17.0, es-abstract@^1.17.0-next.1, es-abstract@^1.17.2, es-abstract@^1.17.5: +es-abstract@^1.17.0, es-abstract@^1.17.2, es-abstract@^1.17.5: version "1.17.7" resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.17.7.tgz#a4de61b2f66989fc7421676c1cb9787573ace54c" integrity sha512-VBl/gnfcJ7OercKA9MVaegWsBHFjV492syMudcnQZvt/Dw8ezpcOHYZXa/J96O8vx+g4x65YKhxOwDUh63aS5g== @@ -4679,23 +4673,27 @@ es-abstract@^1.17.0, es-abstract@^1.17.0-next.1, es-abstract@^1.17.2, es-abstrac string.prototype.trimend "^1.0.1" string.prototype.trimstart "^1.0.1" -es-abstract@^1.18.0-next.0, es-abstract@^1.18.0-next.1: - version "1.18.0-next.1" - resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.18.0-next.1.tgz#6e3a0a4bda717e5023ab3b8e90bec36108d22c68" - integrity sha512-I4UGspA0wpZXWENrdA0uHbnhte683t3qT/1VFH9aX2dA5PPSf6QW5HHXf5HImaqPmjXaVeVk4RGWnaylmV7uAA== +es-abstract@^1.17.0-next.1, es-abstract@^1.18.0-next.0, es-abstract@^1.18.0-next.1, es-abstract@^1.18.0-next.2: + version "1.18.0" + resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.18.0.tgz#ab80b359eecb7ede4c298000390bc5ac3ec7b5a4" + integrity sha512-LJzK7MrQa8TS0ja2w3YNLzUgJCGPdPOV1yVvezjNnS89D+VR08+Szt2mz3YB2Dck/+w5tfIq/RoUAFqJJGM2yw== dependencies: + call-bind "^1.0.2" es-to-primitive "^1.2.1" function-bind "^1.1.1" + get-intrinsic "^1.1.1" has "^1.0.3" - has-symbols "^1.0.1" - is-callable "^1.2.2" - is-negative-zero "^2.0.0" - is-regex "^1.1.1" - object-inspect "^1.8.0" + has-symbols "^1.0.2" + is-callable "^1.2.3" + is-negative-zero "^2.0.1" + is-regex "^1.1.2" + is-string "^1.0.5" + object-inspect "^1.9.0" object-keys "^1.1.1" - object.assign "^4.1.1" - string.prototype.trimend "^1.0.1" - string.prototype.trimstart "^1.0.1" + object.assign "^4.1.2" + string.prototype.trimend "^1.0.4" + string.prototype.trimstart "^1.0.4" + unbox-primitive "^1.0.0" es-to-primitive@^1.2.1: version "1.2.1" @@ -5583,6 +5581,15 @@ get-caller-file@^2.0.1: resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== +get-intrinsic@^1.0.2, get-intrinsic@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.1.1.tgz#15f59f376f855c446963948f0d24cd3637b4abc6" + integrity sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q== + dependencies: + function-bind "^1.1.1" + has "^1.0.3" + has-symbols "^1.0.1" + get-own-enumerable-property-symbols@^3.0.0: version "3.0.2" resolved "https://registry.yarnpkg.com/get-own-enumerable-property-symbols/-/get-own-enumerable-property-symbols-3.0.2.tgz#b5fde77f22cbe35f390b4e089922c50bce6ef664" @@ -5714,11 +5721,16 @@ globby@^6.1.0: pify "^2.0.0" pinkie-promise "^2.0.0" -graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9, graceful-fs@^4.2.0, graceful-fs@^4.2.2: +graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.2.0, graceful-fs@^4.2.2: version "4.2.4" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb" integrity sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw== +graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9: + version "4.2.6" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.6.tgz#ff040b2b0853b23c3d31027523706f1885d76bee" + integrity sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ== + growly@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081" @@ -5762,6 +5774,11 @@ has-ansi@^2.0.0: dependencies: ansi-regex "^2.0.0" +has-bigints@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/has-bigints/-/has-bigints-1.0.1.tgz#64fe6acb020673e3b78db035a5af69aa9d07b113" + integrity sha512-LSBS2LjbNBTf6287JEbEzvJgftkF5qFkmCo9hDRpAzKhUOlJ+hx8dd4USs00SgsUNwc4617J9ki5YtEClM2ffA== + has-flag@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd" @@ -5772,10 +5789,10 @@ has-flag@^4.0.0: resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== -has-symbols@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.1.tgz#9f5214758a44196c406d9bd76cebf81ec2dd31e8" - integrity sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg== +has-symbols@^1.0.1, has-symbols@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.2.tgz#165d3070c00309752a1236a479331e3ac56f1423" + integrity sha512-chXa79rL/UC2KlX17jo3vRGz0azaWEx5tGqZg5pO3NUyEJVB17dMruQlzCCOfUvElghKcm5194+BCRvi2Rv/Gw== has-value@^0.3.1: version "0.3.1" @@ -5871,9 +5888,9 @@ hoist-non-react-statics@^3.1.0, hoist-non-react-statics@^3.3.2: react-is "^16.7.0" hosted-git-info@^2.1.4: - version "2.8.8" - resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.8.tgz#7539bd4bc1e0e0a895815a2e0262420b12858488" - integrity sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg== + version "2.8.9" + resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.9.tgz#dffc0bf9a21c02209090f2aa69429e1414daf3f9" + integrity sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw== hpack.js@^2.1.6: version "2.1.6" @@ -6063,7 +6080,7 @@ identity-obj-proxy@3.0.0: dependencies: harmony-reflect "^1.4.6" -ieee754@^1.1.13, ieee754@^1.1.4: +ieee754@^1.1.4: version "1.1.13" resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.13.tgz#ec168558e95aa181fd87d37f55c32bbcb6708b84" integrity sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg== @@ -6305,6 +6322,11 @@ is-arrayish@^0.3.1: resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.3.2.tgz#4574a2ae56f7ab206896fb431eaeed066fdf8f03" integrity sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ== +is-bigint@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/is-bigint/-/is-bigint-1.0.1.tgz#6923051dfcbc764278540b9ce0e6b3213aa5ebc2" + integrity sha512-J0ELF4yHFxHy0cmSxZuheDOz2luOdVvqjwmEcj8H/L1JHeuEDSDbeRP+Dk9kFVk5RTFzbucJ2Kb9F7ixY2QaCg== + is-binary-path@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-1.0.1.tgz#75f16642b480f187a711c814161fd3a4a7655898" @@ -6319,15 +6341,22 @@ is-binary-path@~2.1.0: dependencies: binary-extensions "^2.0.0" +is-boolean-object@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/is-boolean-object/-/is-boolean-object-1.1.0.tgz#e2aaad3a3a8fca34c28f6eee135b156ed2587ff0" + integrity sha512-a7Uprx8UtD+HWdyYwnD1+ExtTgqQtD2k/1yJgtXP6wnMm8byhkoTZRl+95LLThpzNZJ5aEvi46cdH+ayMFRwmA== + dependencies: + call-bind "^1.0.0" + is-buffer@^1.0.2, is-buffer@^1.1.5: version "1.1.6" resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be" integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w== -is-callable@^1.1.4, is-callable@^1.2.2: - version "1.2.2" - resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.2.2.tgz#c7c6715cd22d4ddb48d3e19970223aceabb080d9" - integrity sha512-dnMqspv5nU3LoewK2N/y7KLtxtakvTuaCsU9FU50/QDmdbHNy/4/JuRtMHqRU22o3q+W89YQndQEeCVwK+3qrA== +is-callable@^1.1.4, is-callable@^1.2.2, is-callable@^1.2.3: + version "1.2.3" + resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.2.3.tgz#8b1e0500b73a1d76c70487636f368e519de8db8e" + integrity sha512-J1DcMe8UYTBSrKezuIUTUwjXsho29693unXM2YhJUTR2txK/eG47bvNa/wipPFmZFgr/N6f1GA66dv0mEyTIyQ== is-capitalized@^1.0.0: version "1.0.0" @@ -6358,10 +6387,10 @@ is-color-stop@^1.0.0: rgb-regex "^1.0.1" rgba-regex "^1.0.0" -is-core-module@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.0.0.tgz#58531b70aed1db7c0e8d4eb1a0a2d1ddd64bd12d" - integrity sha512-jq1AH6C8MuteOoBPwkxHafmByhL9j5q4OaPGdbuD+ZtQJVzH+i6E3BJDQcBA09k57i2Hh2yQbEG8yObZ0jdlWw== +is-core-module@^2.0.0, is-core-module@^2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.2.0.tgz#97037ef3d52224d85163f5597b2b63d9afed981a" + integrity sha512-XRAfAdyyY5F5cOXn7hYQDqh2Xmii+DEfIcQGxK/uNwMHhIkPWO0g8msXcbzLe+MpGoR951MlqM/2iIlU4vKDdQ== dependencies: has "^1.0.3" @@ -6458,10 +6487,15 @@ is-glob@^4.0.0, is-glob@^4.0.1, is-glob@~4.0.1: dependencies: is-extglob "^2.1.1" -is-negative-zero@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/is-negative-zero/-/is-negative-zero-2.0.0.tgz#9553b121b0fac28869da9ed459e20c7543788461" - integrity sha1-lVOxIbD6wohp2p7UWeIMdUN4hGE= +is-negative-zero@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/is-negative-zero/-/is-negative-zero-2.0.1.tgz#3de746c18dda2319241a53675908d8f766f11c24" + integrity sha512-2z6JzQvZRa9A2Y7xC6dQQm4FSTSTNWjKIYYTt4246eMTJmIo0Q+ZyOsU66X8lxK1AbB92dFeglPLrhwpeRKO6w== + +is-number-object@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/is-number-object/-/is-number-object-1.0.4.tgz#36ac95e741cf18b283fc1ddf5e83da798e3ec197" + integrity sha512-zohwelOAur+5uXtk8O3GPQ1eAcu4ZX3UwxQhUlfFFMNpUd83gXgjbhJh6HmB6LUNV/ieOLQuDwJO3dWJosUeMw== is-number@^3.0.0: version "3.0.0" @@ -6516,13 +6550,21 @@ is-plain-object@^2.0.1, is-plain-object@^2.0.3, is-plain-object@^2.0.4: dependencies: isobject "^3.0.1" -is-regex@^1.0.4, is-regex@^1.1.1: +is-regex@^1.0.4: version "1.1.1" resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.1.1.tgz#c6f98aacc546f6cec5468a07b7b153ab564a57b9" integrity sha512-1+QkEcxiLlB7VEyFtyBg94e08OAsvq7FUBgApTq/w2ymCLyKJgDPsybBENVtA7XCQEgEXxKPonG+mvYRxh/LIg== dependencies: has-symbols "^1.0.1" +is-regex@^1.1.1, is-regex@^1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.1.2.tgz#81c8ebde4db142f2cf1c53fc86d6a45788266251" + integrity sha512-axvdhb5pdhEVThqJzYXwMlVuZwC+FF2DpcOhTS+y/8jVq4trxyPgfcwIxIKiyeuLlSQYKkmUaPQJ8ZE4yNKXDg== + dependencies: + call-bind "^1.0.2" + has-symbols "^1.0.1" + is-regexp@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/is-regexp/-/is-regexp-1.0.0.tgz#fd2d883545c46bac5a633e7b9a09e87fa2cb5069" @@ -6555,7 +6597,7 @@ is-svg@^3.0.0: dependencies: html-comment-regex "^1.1.0" -is-symbol@^1.0.2: +is-symbol@^1.0.2, is-symbol@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.0.3.tgz#38e1014b9e6329be0de9d24a414fd7441ec61937" integrity sha512-OwijhaRSgqvhm/0ZdAcXNZt9lYdKFpcRDT5ULUuYXPoT794UNOdU+gpT6Rzo7b4V2HUl/op6GqY894AZwv9faQ== @@ -6661,24 +6703,7 @@ istanbul-reports@^2.2.6: dependencies: html-escaper "^2.0.0" -jayson@^3.0.1: - version "3.3.4" - resolved "https://registry.yarnpkg.com/jayson/-/jayson-3.3.4.tgz#c4fc8f3a8884ac85562da101f5bb526e5a679fa4" - integrity sha512-p2stl9m1C0vM8mdXM1m8shn0v5ECohD5gEDRzLD6CPv02pxRm1lv0jEz0HX6RvfJ/uO9z9Zzlzti7/uqq+Rh5g== - dependencies: - "@types/connect" "^3.4.33" - "@types/express-serve-static-core" "^4.17.9" - "@types/lodash" "^4.14.159" - "@types/node" "^12.12.54" - JSONStream "^1.3.5" - commander "^2.20.3" - es6-promisify "^5.0.0" - eyes "^0.1.8" - json-stringify-safe "^5.0.1" - lodash "^4.17.20" - uuid "^3.4.0" - -jayson@^3.4.4: +jayson@^3.0.1, jayson@^3.4.4: version "3.4.4" resolved "https://registry.yarnpkg.com/jayson/-/jayson-3.4.4.tgz#dcedffba0c02785c4aa22dbff8c28966cae59773" integrity sha512-fgQflh+Qnhdv9fjxTnpTsa2WUG/dgyeKQzIh5MJ77Qv2sqFyyAZn7mTUYgPjJMFjsKfb4HNsSBh6ktJeeQiAGQ== @@ -7620,11 +7645,16 @@ lodash.uniq@^4.5.0: resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M= -"lodash@>=3.5 <5", lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.5: +"lodash@>=3.5 <5", lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.5: version "4.17.20" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52" integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA== +lodash@^4.17.20: + version "4.17.21" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" + integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== + loglevel@^1.6.8: version "1.7.0" resolved "https://registry.yarnpkg.com/loglevel/-/loglevel-1.7.0.tgz#728166855a740d59d38db01cf46f042caa041bb0" @@ -8109,11 +8139,6 @@ node-gyp-build@^4.2.0: resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.2.3.tgz#ce6277f853835f718829efb47db20f3e4d9c4739" integrity sha512-MN6ZpzmfNCRM+3t57PTJHgHyw/h4OWnZ6mR8P5j/uZtqQr46RRuDE/P+g3n0YR/AiYXeWixZZzaip77gdICfRg== -node-gyp-build@~3.7.0: - version "3.7.0" - resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-3.7.0.tgz#daa77a4f547b9aed3e2aac779eaf151afd60ec8d" - integrity sha512-L/Eg02Epx6Si2NXmedx+Okg+4UHqmaf3TNcxd50SF9NQGcJaON3AtU++kax69XV7YWz4tUspqZSAsVofhFKG2w== - node-int64@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b" @@ -8274,10 +8299,10 @@ object-hash@^2.0.1: resolved "https://registry.yarnpkg.com/object-hash/-/object-hash-2.0.3.tgz#d12db044e03cd2ca3d77c0570d87225b02e1e6ea" integrity sha512-JPKn0GMu+Fa3zt3Bmr66JhokJU5BaNBIh4ZeTlaCBzrBsOeXzwcKKAK1tbLiPKgvwmPXsDvvLHoWh5Bm7ofIYg== -object-inspect@^1.8.0: - version "1.8.0" - resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.8.0.tgz#df807e5ecf53a609cc6bfe93eac3cc7be5b3a9d0" - integrity sha512-jLdtEOB112fORuypAyl/50VRVIBIdVQOSUUGQHzJ4xBSbit81zRarz7GThkEFZy1RceYrWYcPcBFPQwHyAc1gA== +object-inspect@^1.8.0, object-inspect@^1.9.0: + version "1.10.2" + resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.10.2.tgz#b6385a3e2b7cae0b5eafcf90cddf85d128767f30" + integrity sha512-gz58rdPpadwztRrPjZE9DZLOABUpTGdcANUgOwBFO1C+HZZhePoP83M65WGDmbpwFYJSWqavbl4SgDn4k8RYTA== object-is@^1.0.1: version "1.1.3" @@ -8304,7 +8329,7 @@ object-visit@^1.0.0: dependencies: isobject "^3.0.0" -object.assign@^4.1.0, object.assign@^4.1.1: +object.assign@^4.1.0: version "4.1.1" resolved "https://registry.yarnpkg.com/object.assign/-/object.assign-4.1.1.tgz#303867a666cdd41936ecdedfb1f8f3e32a478cdd" integrity sha512-VT/cxmx5yaoHSOTSyrCygIDFco+RsibY2NM0a4RdEeY/4KgqezwFtK1yr3U67xYhqJSlASm2pKhLVzPj2lr4bA== @@ -8314,6 +8339,16 @@ object.assign@^4.1.0, object.assign@^4.1.1: has-symbols "^1.0.1" object-keys "^1.1.1" +object.assign@^4.1.1, object.assign@^4.1.2: + version "4.1.2" + resolved "https://registry.yarnpkg.com/object.assign/-/object.assign-4.1.2.tgz#0ed54a342eceb37b38ff76eb831a0e788cb63940" + integrity sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ== + dependencies: + call-bind "^1.0.0" + define-properties "^1.1.3" + has-symbols "^1.0.1" + object-keys "^1.1.1" + object.entries@^1.1.0, object.entries@^1.1.1: version "1.1.2" resolved "https://registry.yarnpkg.com/object.entries/-/object.entries-1.1.2.tgz#bc73f00acb6b6bb16c203434b10f9a7e797d3add" @@ -10620,7 +10655,15 @@ resolve@1.15.0: dependencies: path-parse "^1.0.6" -resolve@^1.10.0, resolve@^1.12.0, resolve@^1.13.1, resolve@^1.15.1, resolve@^1.3.2, resolve@^1.8.1: +resolve@^1.10.0: + version "1.20.0" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975" + integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A== + dependencies: + is-core-module "^2.2.0" + path-parse "^1.0.6" + +resolve@^1.12.0, resolve@^1.13.1, resolve@^1.15.1, resolve@^1.3.2, resolve@^1.8.1: version "1.18.1" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.18.1.tgz#018fcb2c5b207d2a6424aee361c5a266da8f4130" integrity sha512-lDfCPaMKfOJXjy0dPayzPdF1phampNWr3qFCjAu+rw/qbQmr5jWH5xN2hwh9QKfw9E5v4hwV7A+jrCmL8yjjqA== @@ -10692,9 +10735,9 @@ ripemd160@^2.0.0, ripemd160@^2.0.1: inherits "^2.0.1" rpc-websockets@^7.4.2: - version "7.4.6" - resolved "https://registry.yarnpkg.com/rpc-websockets/-/rpc-websockets-7.4.6.tgz#a0053ad36e893774cdd0edb72ac577deaf34f247" - integrity sha512-vDGdyJv858O5ZIc7glov8pQDdFztOqujA7iNyrfPxw87ajHT5s8WQU4MLNEG8pTR/xzqOn06dYH7kef2hijInw== + version "7.4.11" + resolved "https://registry.yarnpkg.com/rpc-websockets/-/rpc-websockets-7.4.11.tgz#ac8105116f1a888fbc3dd6b8394ea135ee59499c" + integrity sha512-/6yKCkRrEEb+TlJb6Q/pNBD4WdO/tFxE22rQYBl1YyIgz3SpzQDQ/0qAMWWksjFkDayiq3xVxmkP8e/tL422ZA== dependencies: "@babel/runtime" "^7.11.2" assert-args "^1.2.1" @@ -11194,9 +11237,9 @@ spdx-expression-parse@^3.0.0: spdx-license-ids "^3.0.0" spdx-license-ids@^3.0.0: - version "3.0.6" - resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.6.tgz#c80757383c28abf7296744998cbc106ae8b854ce" - integrity sha512-+orQK83kyMva3WyPf59k1+Y525csj5JejicWut55zeTWANuN17qSiSLUXWtzHeNWORSvT7GLDJ/E/XiIWoXBTw== + version "3.0.7" + resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.7.tgz#e9c18a410e5ed7e12442a549fbd8afa767038d65" + integrity sha512-U+MTEOO0AiDzxwFvoa4JVnMV6mZlJKk2sBLt90s7G0Gd0Mlknc7kxEn3nuDPNZRta7O2uy8oLcZLVT+4sqNZHQ== spdy-transport@^3.0.0: version "3.0.0" @@ -11380,28 +11423,29 @@ string.prototype.matchall@^4.0.2: side-channel "^1.0.2" string.prototype.padend@^3.0.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/string.prototype.padend/-/string.prototype.padend-3.1.0.tgz#dc08f57a8010dc5c153550318f67e13adbb72ac3" - integrity sha512-3aIv8Ffdp8EZj8iLwREGpQaUZiPyrWrpzMBHvkiSW/bK/EGve9np07Vwy7IJ5waydpGXzQZu/F8Oze2/IWkBaA== + version "3.1.2" + resolved "https://registry.yarnpkg.com/string.prototype.padend/-/string.prototype.padend-3.1.2.tgz#6858ca4f35c5268ebd5e8615e1327d55f59ee311" + integrity sha512-/AQFLdYvePENU3W5rgurfWSMU6n+Ww8n/3cUt7E+vPBB/D7YDG8x+qjoFs4M/alR2bW7Qg6xMjVwWUOvuQ0XpQ== dependencies: + call-bind "^1.0.2" define-properties "^1.1.3" - es-abstract "^1.17.0-next.1" + es-abstract "^1.18.0-next.2" -string.prototype.trimend@^1.0.1: - version "1.0.2" - resolved "https://registry.yarnpkg.com/string.prototype.trimend/-/string.prototype.trimend-1.0.2.tgz#6ddd9a8796bc714b489a3ae22246a208f37bfa46" - integrity sha512-8oAG/hi14Z4nOVP0z6mdiVZ/wqjDtWSLygMigTzAb+7aPEDTleeFf+WrF+alzecxIRkckkJVn+dTlwzJXORATw== +string.prototype.trimend@^1.0.1, string.prototype.trimend@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/string.prototype.trimend/-/string.prototype.trimend-1.0.4.tgz#e75ae90c2942c63504686c18b287b4a0b1a45f80" + integrity sha512-y9xCjw1P23Awk8EvTpcyL2NIr1j7wJ39f+k6lvRnSMz+mz9CGz9NYPelDk42kOz6+ql8xjfK8oYzy3jAP5QU5A== dependencies: + call-bind "^1.0.2" define-properties "^1.1.3" - es-abstract "^1.18.0-next.1" -string.prototype.trimstart@^1.0.1: - version "1.0.2" - resolved "https://registry.yarnpkg.com/string.prototype.trimstart/-/string.prototype.trimstart-1.0.2.tgz#22d45da81015309cd0cdd79787e8919fc5c613e7" - integrity sha512-7F6CdBTl5zyu30BJFdzSTlSlLPwODC23Od+iLoVH8X6+3fvDPPuBVVj9iaB1GOsSTSIgVfsfm27R2FGrAPznWg== +string.prototype.trimstart@^1.0.1, string.prototype.trimstart@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/string.prototype.trimstart/-/string.prototype.trimstart-1.0.4.tgz#b36399af4ab2999b4c9c648bd7a3fb2bb26feeed" + integrity sha512-jh6e984OBfvxS50tdY2nRZnoC5/mLFKOREQfw8t5yytkoUsJRNxvI/E39qu1sD0OtWI3OC0XgKSmcWwziwYuZw== dependencies: + call-bind "^1.0.2" define-properties "^1.1.3" - es-abstract "^1.18.0-next.1" string_decoder@^1.0.0, string_decoder@^1.1.1: version "1.3.0" @@ -11890,9 +11934,19 @@ typedarray@^0.0.6: integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= typescript@^4.0.0: - version "4.0.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389" - integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ== + version "4.2.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.4.tgz#8610b59747de028fda898a8aef0e103f156d0961" + integrity sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg== + +unbox-primitive@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.0.1.tgz#085e215625ec3162574dc8859abee78a59b14471" + integrity sha512-tZU/3NqK3dA5gpE1KtyiJUrEB0lxnGkMFHptJ7q6ewdZ8s12QrODwNbhIJStmJkd1QDXa1NRA8aF2A1zk/Ypyw== + dependencies: + function-bind "^1.1.1" + has-bigints "^1.0.1" + has-symbols "^1.0.2" + which-boxed-primitive "^1.0.2" unicode-canonical-property-names-ecmascript@^1.0.4: version "1.0.4" @@ -12022,11 +12076,11 @@ use@^3.1.0: integrity sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ== utf-8-validate@^5.0.2: - version "5.0.2" - resolved "https://registry.yarnpkg.com/utf-8-validate/-/utf-8-validate-5.0.2.tgz#63cfbccd85dc1f2b66cf7a1d0eebc08ed056bfb3" - integrity sha512-SwV++i2gTD5qh2XqaPzBnNX88N6HdyhQrNNRykvcS0QKvItV9u3vPEJr+X5Hhfb1JC0r0e1alL0iB09rY8+nmw== + version "5.0.4" + resolved "https://registry.yarnpkg.com/utf-8-validate/-/utf-8-validate-5.0.4.tgz#72a1735983ddf7a05a43a9c6b67c5ce1c910f9b8" + integrity sha512-MEF05cPSq3AwJ2C7B7sHAA6i53vONoZbMGX8My5auEVm6W+dJ2Jd/TZPyGJ5CH42V2XtbI5FD28HeHeqlPzZ3Q== dependencies: - node-gyp-build "~3.7.0" + node-gyp-build "^4.2.0" util-deprecate@^1.0.1, util-deprecate@^1.0.2, util-deprecate@~1.0.1: version "1.0.2" @@ -12081,9 +12135,9 @@ uuid@^3.3.2, uuid@^3.4.0: integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== uuid@^8.3.0: - version "8.3.1" - resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.1.tgz#2ba2e6ca000da60fce5a196954ab241131e05a31" - integrity sha512-FOmRr+FmWEIG8uhZv6C2bTgEVXsHk08kE7mPlrBbEe+c3r9pjceVPgupIfNIhc4yx55H69OXANrUaSuu9eInKg== + version "8.3.2" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" + integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== v8-compile-cache@^2.0.3: version "2.1.1" @@ -12360,6 +12414,17 @@ whatwg-url@^7.0.0: tr46 "^1.0.1" webidl-conversions "^4.0.2" +which-boxed-primitive@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz#13757bc89b209b049fe5d86430e21cf40a89a8e6" + integrity sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg== + dependencies: + is-bigint "^1.0.1" + is-boolean-object "^1.1.0" + is-number-object "^1.0.4" + is-string "^1.0.5" + is-symbol "^1.0.3" + which-module@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a" @@ -12578,9 +12643,9 @@ ws@^6.1.2, ws@^6.2.1: async-limiter "~1.0.0" ws@^7.0.0, ws@^7.3.1: - version "7.3.1" - resolved "https://registry.yarnpkg.com/ws/-/ws-7.3.1.tgz#d0547bf67f7ce4f12a72dfe31262c68d7dc551c8" - integrity sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA== + version "7.4.5" + resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.5.tgz#a484dd851e9beb6fdb420027e3885e8ce48986c1" + integrity sha512-xzyu3hFvomRfXKH8vOFMU3OguG6oOvhXMo3xsGy3xWExqaM2dxBbVxuD99O7m3ZUFMvvscsZDqxfgMaRr/Nr1g== xml-name-validator@^3.0.0: version "3.0.0" From 31a06b385139cedeba21055dbeb6ec14bb5550ae Mon Sep 17 00:00:00 2001 From: Arrowana <8245419+Arrowana@users.noreply.github.com> Date: Tue, 20 Apr 2021 07:33:10 +1000 Subject: [PATCH 2/4] Introduce TokenSwapRouter to allow legacy swap instructions --- src/models/tokenSwap.ts | 400 +++++++++++++++++++++++++++++++++++++++- src/utils/pools.tsx | 18 +- 2 files changed, 407 insertions(+), 11 deletions(-) diff --git a/src/models/tokenSwap.ts b/src/models/tokenSwap.ts index 608c52eaa..bfe4fbb03 100644 --- a/src/models/tokenSwap.ts +++ b/src/models/tokenSwap.ts @@ -1,4 +1,9 @@ +import { Numberu64, TokenSwap } from "@solana/spl-token-swap"; +import { PublicKey, Account, TransactionInstruction } from "@solana/web3.js"; import * as BufferLayout from "buffer-layout"; +import { PoolConfig } from "./pool"; + +export { TokenSwap } from "@solana/spl-token-swap"; /** * Layout for a public key @@ -58,4 +63,397 @@ export const TokenSwapLayoutV1: typeof BufferLayout.Structure = BufferLayout.str uint64("ownerWithdrawFeeDenominator"), BufferLayout.blob(16, "padding"), ] -); \ No newline at end of file +); + +export const legacyDepositInstruction = ( + tokenSwap: PublicKey, + authority: PublicKey, + transferAuthority: PublicKey, + sourceA: PublicKey, + sourceB: PublicKey, + intoA: PublicKey, + intoB: PublicKey, + poolToken: PublicKey, + poolAccount: PublicKey, + swapProgramId: PublicKey, + tokenProgramId: PublicKey, + poolTokenAmount: number | Numberu64, + maximumTokenA: number | Numberu64, + maximumTokenB: number | Numberu64, +): TransactionInstruction => { + const dataLayout = BufferLayout.struct([ + BufferLayout.u8("instruction"), + uint64("poolTokenAmount"), + uint64("maximumTokenA"), + uint64("maximumTokenB"), + ]); + + const data = Buffer.alloc(dataLayout.span); + dataLayout.encode( + { + instruction: 2, // Deposit instruction + poolTokenAmount: new Numberu64(poolTokenAmount).toBuffer(), + maximumTokenA: new Numberu64(maximumTokenA).toBuffer(), + maximumTokenB: new Numberu64(maximumTokenB).toBuffer(), + }, + data + ); + + const keys = [ + { pubkey: tokenSwap, isSigner: false, isWritable: false }, + { pubkey: authority, isSigner: false, isWritable: false }, + { pubkey: sourceA, isSigner: false, isWritable: true }, + { pubkey: sourceB, isSigner: false, isWritable: true }, + { pubkey: intoA, isSigner: false, isWritable: true }, + { pubkey: intoB, isSigner: false, isWritable: true }, + { pubkey: poolToken, isSigner: false, isWritable: true }, + { pubkey: poolAccount, isSigner: false, isWritable: true }, + { pubkey: tokenProgramId, isSigner: false, isWritable: false }, + ]; + return new TransactionInstruction({ + keys, + programId: swapProgramId, + data, + }); +}; + +export const legacyDepositExactOneInstruction = ( + tokenSwap: PublicKey, + authority: PublicKey, + transferAuthority: PublicKey, + source: PublicKey, + intoA: PublicKey, + intoB: PublicKey, + poolToken: PublicKey, + poolAccount: PublicKey, + swapProgramId: PublicKey, + tokenProgramId: PublicKey, + sourceTokenAmount: number | Numberu64, + minimumPoolTokenAmount: number | Numberu64 +): TransactionInstruction => { + const dataLayout = BufferLayout.struct([ + BufferLayout.u8("instruction"), + uint64("sourceTokenAmount"), + uint64("minimumPoolTokenAmount"), + ]); + + const data = Buffer.alloc(dataLayout.span); + dataLayout.encode( + { + instruction: 4, // DepositExactOne instruction + sourceTokenAmount: new Numberu64(sourceTokenAmount).toBuffer(), + minimumPoolTokenAmount: new Numberu64(minimumPoolTokenAmount).toBuffer(), + }, + data + ); + + const keys = [ + { pubkey: tokenSwap, isSigner: false, isWritable: false }, + { pubkey: authority, isSigner: false, isWritable: false }, + { pubkey: source, isSigner: false, isWritable: true }, + { pubkey: intoA, isSigner: false, isWritable: true }, + { pubkey: intoB, isSigner: false, isWritable: true }, + { pubkey: poolToken, isSigner: false, isWritable: true }, + { pubkey: poolAccount, isSigner: false, isWritable: true }, + { pubkey: tokenProgramId, isSigner: false, isWritable: false }, + ]; + return new TransactionInstruction({ + keys, + programId: swapProgramId, + data, + }); +}; + +export const legacyWithdrawInstruction = ( + tokenSwap: PublicKey, + authority: PublicKey, + transferAuthority: PublicKey, + poolMint: PublicKey, + feeAccount: PublicKey | undefined, + sourcePoolAccount: PublicKey, + fromA: PublicKey, + fromB: PublicKey, + userAccountA: PublicKey, + userAccountB: PublicKey, + swapProgramId: PublicKey, + tokenProgramId: PublicKey, + poolTokenAmount: number | Numberu64, + minimumTokenA: number | Numberu64, + minimumTokenB: number | Numberu64, +): TransactionInstruction => { + const dataLayout = BufferLayout.struct([ + BufferLayout.u8("instruction"), + uint64("poolTokenAmount"), + uint64("minimumTokenA"), + uint64("minimumTokenB"), + ]); + + const data = Buffer.alloc(dataLayout.span); + dataLayout.encode( + { + instruction: 3, // Withdraw instruction + poolTokenAmount: new Numberu64(poolTokenAmount).toBuffer(), + minimumTokenA: new Numberu64(minimumTokenA).toBuffer(), + minimumTokenB: new Numberu64(minimumTokenB).toBuffer(), + }, + data + ); + + const keys = [ + { pubkey: tokenSwap, isSigner: false, isWritable: false }, + { pubkey: authority, isSigner: false, isWritable: false }, + { pubkey: poolMint, isSigner: false, isWritable: true }, + { pubkey: sourcePoolAccount, isSigner: false, isWritable: true }, + { pubkey: fromA, isSigner: false, isWritable: true }, + { pubkey: fromB, isSigner: false, isWritable: true }, + { pubkey: userAccountA, isSigner: false, isWritable: true }, + { pubkey: userAccountB, isSigner: false, isWritable: true }, + ]; + + if (feeAccount) { + keys.push({ pubkey: feeAccount, isSigner: false, isWritable: true }); + } + keys.push({ pubkey: tokenProgramId, isSigner: false, isWritable: false }); + + return new TransactionInstruction({ + keys, + programId: swapProgramId, + data, + }); +}; + +export const legacyWithdrawExactOneInstruction = ( + tokenSwap: PublicKey, + authority: PublicKey, + transferAuthority: PublicKey, + poolMint: PublicKey, + sourcePoolAccount: PublicKey, + fromA: PublicKey, + fromB: PublicKey, + userAccount: PublicKey, + feeAccount: PublicKey | undefined, + swapProgramId: PublicKey, + tokenProgramId: PublicKey, + sourceTokenAmount: number | Numberu64, + maximumTokenAmount: number | Numberu64, + isLatest: boolean +): TransactionInstruction => { + const dataLayout = BufferLayout.struct([ + BufferLayout.u8("instruction"), + uint64("sourceTokenAmount"), + uint64("maximumTokenAmount"), + ]); + + const data = Buffer.alloc(dataLayout.span); + dataLayout.encode( + { + instruction: 5, // WithdrawExactOne instruction + sourceTokenAmount: new Numberu64(sourceTokenAmount).toBuffer(), + maximumTokenAmount: new Numberu64(maximumTokenAmount).toBuffer(), + }, + data + ); + + const keys = [ + { pubkey: tokenSwap, isSigner: false, isWritable: false }, + { pubkey: authority, isSigner: false, isWritable: false }, + { pubkey: poolMint, isSigner: false, isWritable: true }, + { pubkey: sourcePoolAccount, isSigner: false, isWritable: true }, + { pubkey: fromA, isSigner: false, isWritable: true }, + { pubkey: fromB, isSigner: false, isWritable: true }, + { pubkey: userAccount, isSigner: false, isWritable: true }, + ]; + + if (feeAccount) { + keys.push({ pubkey: feeAccount, isSigner: false, isWritable: true }); + } + keys.push({ pubkey: tokenProgramId, isSigner: false, isWritable: false }); + + return new TransactionInstruction({ + keys, + programId: swapProgramId, + data, + }); +}; + +export const legacySwapInstruction = ( + tokenSwap: PublicKey, + authority: PublicKey, + transferAuthority: PublicKey, + userSource: PublicKey, + poolSource: PublicKey, + poolDestination: PublicKey, + userDestination: PublicKey, + poolMint: PublicKey, + feeAccount: PublicKey, + swapProgramId: PublicKey, + tokenProgramId: PublicKey, + amountIn: number | Numberu64, + minimumAmountOut: number | Numberu64, + programOwner: PublicKey | undefined, +): TransactionInstruction => { + const dataLayout = BufferLayout.struct([ + BufferLayout.u8("instruction"), + uint64("amountIn"), + uint64("minimumAmountOut"), + ]); + + const keys = [ + { pubkey: tokenSwap, isSigner: false, isWritable: false }, + { pubkey: authority, isSigner: false, isWritable: false }, + { pubkey: userSource, isSigner: false, isWritable: true }, + { pubkey: poolSource, isSigner: false, isWritable: true }, + { pubkey: poolDestination, isSigner: false, isWritable: true }, + { pubkey: userDestination, isSigner: false, isWritable: true }, + { pubkey: poolMint, isSigner: false, isWritable: true }, + { pubkey: feeAccount, isSigner: false, isWritable: true }, + { pubkey: tokenProgramId, isSigner: false, isWritable: false }, + ]; + + // optional depending on the build of token-swap program + if (programOwner) { + keys.push({ pubkey: programOwner, isSigner: false, isWritable: true }); + } + + const data = Buffer.alloc(dataLayout.span); + dataLayout.encode( + { + instruction: 1, // Swap instruction + amountIn: new Numberu64(amountIn).toBuffer(), + minimumAmountOut: new Numberu64(minimumAmountOut).toBuffer(), + }, + data + ); + + return new TransactionInstruction({ + keys, + programId: swapProgramId, + data, + }); +}; + +// TODO: Implement each static method to map to legacy instruction +class TokenSwapLegacy { + static createInitSwapInstruction( + tokenSwapAccount: Account, + authority: PublicKey, + tokenAccountA: PublicKey, + tokenAccountB: PublicKey, + tokenPool: PublicKey, + feeAccount: PublicKey, + tokenAccountPool: PublicKey, + tokenProgramId: PublicKey, + swapProgramId: PublicKey, + nonce: number, + tradeFeeNumerator: number, + tradeFeeDenominator: number, + ownerTradeFeeNumerator: number, + ownerTradeFeeDenominator: number, + ownerWithdrawFeeNumerator: number, + ownerWithdrawFeeDenominator: number, + hostFeeNumerator: number, + hostFeeDenominator: number, + curveType: number, + ): TransactionInstruction { + + } + + static swapInstruction( + tokenSwap: PublicKey, + authority: PublicKey, + userTransferAuthority: PublicKey, + userSource: PublicKey, + poolSource: PublicKey, + poolDestination: PublicKey, + userDestination: PublicKey, + poolMint: PublicKey, + feeAccount: PublicKey, + hostFeeAccount: PublicKey | null, + swapProgramId: PublicKey, + tokenProgramId: PublicKey, + amountIn: number | Numberu64, + minimumAmountOut: number | Numberu64, + ): TransactionInstruction { + + } + + static depositAllTokenTypesInstruction( + tokenSwap: PublicKey, + authority: PublicKey, + userTransferAuthority: PublicKey, + sourceA: PublicKey, + sourceB: PublicKey, + intoA: PublicKey, + intoB: PublicKey, + poolToken: PublicKey, + poolAccount: PublicKey, + swapProgramId: PublicKey, + tokenProgramId: PublicKey, + poolTokenAmount: number | Numberu64, + maximumTokenA: number | Numberu64, + maximumTokenB: number | Numberu64, + ): TransactionInstruction { + + } + + static withdrawAllTokenTypesInstruction( + tokenSwap: PublicKey, + authority: PublicKey, + userTransferAuthority: PublicKey, + poolMint: PublicKey, + feeAccount: PublicKey, + sourcePoolAccount: PublicKey, + fromA: PublicKey, + fromB: PublicKey, + userAccountA: PublicKey, + userAccountB: PublicKey, + swapProgramId: PublicKey, + tokenProgramId: PublicKey, + poolTokenAmount: number | Numberu64, + minimumTokenA: number | Numberu64, + minimumTokenB: number | Numberu64, + ) { + + } + + static depositSingleTokenTypeExactAmountInInstruction( + tokenSwap: PublicKey, + authority: PublicKey, + userTransferAuthority: PublicKey, + source: PublicKey, + intoA: PublicKey, + intoB: PublicKey, + poolToken: PublicKey, + poolAccount: PublicKey, + swapProgramId: PublicKey, + tokenProgramId: PublicKey, + sourceTokenAmount: number | Numberu64, + minimumPoolTokenAmount: number | Numberu64, + ): TransactionInstruction { + + } + + static withdrawSingleTokenTypeExactAmountOutInstruction( + tokenSwap: PublicKey, + authority: PublicKey, + userTransferAuthority: PublicKey, + poolMint: PublicKey, + feeAccount: PublicKey, + sourcePoolAccount: PublicKey, + fromA: PublicKey, + fromB: PublicKey, + userAccount: PublicKey, + swapProgramId: PublicKey, + tokenProgramId: PublicKey, + destinationTokenAmount: number | Numberu64, + maximumPoolTokenAmount: number | Numberu64, + ): TransactionInstruction { + + } +} + +export class TokenSwapRouter { + static route(isLatestSwap: boolean) : TokenSwap | TokenSwapLegacy { + return isLatestSwap ? TokenSwap : TokenSwapLegacy + } +} \ No newline at end of file diff --git a/src/utils/pools.tsx b/src/utils/pools.tsx index 1f219421a..61c40ff18 100644 --- a/src/utils/pools.tsx +++ b/src/utils/pools.tsx @@ -30,6 +30,7 @@ import { TokenSwapLayoutLegacyV0 as TokenSwapLayoutV0, TokenSwapLayoutV1, PoolConfig, + TokenSwapRouter, } from "./../models"; import { TokenSwap, TokenSwapLayout } from "@solana/spl-token-swap"; @@ -122,7 +123,7 @@ export const removeLiquidity = async ( // withdraw instructions.push( - TokenSwap.withdrawAllTokenTypesInstruction( + TokenSwapRouter.route(isLatestSwap).withdrawAllTokenTypesInstruction( pool.pubkeys.account, authority, transferAuthority.publicKey, @@ -138,7 +139,6 @@ export const removeLiquidity = async ( liquidityAmount, minAmount0, minAmount1, - isLatestSwap ) ); @@ -254,7 +254,7 @@ export const removeExactOneLiquidity = async ( // withdraw exact one instructions.push( - withdrawExactOneInstruction( + TokenSwapRouter.route(isLatestSwap).withdrawSingleTokenTypeExactAmountOutInstruction( pool.pubkeys.account, authority, transferAuthority.publicKey, @@ -267,8 +267,7 @@ export const removeExactOneLiquidity = async ( pool.pubkeys.program, programIds().token, tokenAmount, - liquidityMaxAmount, - isLatestSwap + liquidityMaxAmount ) ); @@ -382,7 +381,7 @@ export const swap = async ( // swap instructions.push( - TokenSwap.swapInstruction( + TokenSwapRouter.route(isLatestSwap).swapInstruction( pool.pubkeys.account, authority, transferAuthority.publicKey, @@ -838,7 +837,7 @@ async function _addLiquidityExistingPool( // deposit instructions.push( - TokenSwap.depositAllTokenTypesInstruction( + TokenSwapRouter.route(isLatestSwap).depositAllTokenTypesInstruction( pool.pubkeys.account, authority, transferAuthority.publicKey, @@ -966,7 +965,7 @@ async function _addLiquidityExactOneExistingPool( // deposit instructions.push( - depositExactOneInstruction( + TokenSwapRouter.route(isLatestSwap).depositSingleTokenTypeExactAmountInInstruction( pool.pubkeys.account, authority, transferAuthority.publicKey, @@ -978,8 +977,7 @@ async function _addLiquidityExactOneExistingPool( pool.pubkeys.program, programIds().token, amount, - liquidityToken, - isLatestSwap + liquidityToken ) ); From 98587db10f46b7e9f7911b5392b0e0e0c048f96d Mon Sep 17 00:00:00 2001 From: Arrowana <8245419+Arrowana@users.noreply.github.com> Date: Tue, 20 Apr 2021 18:50:51 +1000 Subject: [PATCH 3/4] move legacy ix to TokenSwapLegacy --- src/components/pool/add.tsx | 3 +- src/components/pool/remove.tsx | 3 +- src/models/tokenSwap.ts | 491 +++++++++++++-------------------- 3 files changed, 193 insertions(+), 304 deletions(-) diff --git a/src/components/pool/add.tsx b/src/components/pool/add.tsx index bac58062c..d118be091 100644 --- a/src/components/pool/add.tsx +++ b/src/components/pool/add.tsx @@ -18,7 +18,7 @@ import { SupplyOverview } from "./supplyOverview"; import { CurrencyInput } from "../currencyInput"; import { PoolConfigCard } from "./config"; import "./add.less"; -import { CurveType, PoolInfo, TokenSwapLayout } from "../../models"; +import { CurveType, PoolInfo } from "../../models"; import { useCurrencyPairState } from "../../utils/currencyPair"; import { CREATE_POOL_LABEL, @@ -34,6 +34,7 @@ import { PoolIcon } from "../tokenIcon"; import { AppBar } from "../appBar"; import { Settings } from "../settings"; import { programIds } from "../../utils/ids"; +import { TokenSwapLayout } from "@solana/spl-token-swap"; const antIcon = ; diff --git a/src/components/pool/remove.tsx b/src/components/pool/remove.tsx index 0d6013aff..64c3a2bfc 100644 --- a/src/components/pool/remove.tsx +++ b/src/components/pool/remove.tsx @@ -4,7 +4,7 @@ import { Button, Card, Col, Radio, Row, Slider, Spin, Typography } from "antd"; import { removeLiquidity, removeExactOneLiquidity } from "../../utils/pools"; import { useWallet } from "../../context/wallet"; import { useConnection, useConnectionConfig } from "../../utils/connection"; -import { PoolInfo, TokenAccount, TokenSwapLayout } from "../../models"; +import { PoolInfo, TokenAccount } from "../../models"; import { notify } from "../../utils/notifications"; import { TokenIcon } from "../tokenIcon"; import { YourPosition } from "./add"; @@ -18,6 +18,7 @@ import { PoolCurrencyInput } from "../currencyInput"; import { LoadingOutlined } from "@ant-design/icons"; import { generateRemoveLabel } from "../labels"; import { programIds } from "../../utils/ids"; +import { TokenSwapLayout } from "@solana/spl-token-swap"; export const RemoveLiquidity = (props: { instance: { account: TokenAccount; pool: PoolInfo }; diff --git a/src/models/tokenSwap.ts b/src/models/tokenSwap.ts index bfe4fbb03..53c06f897 100644 --- a/src/models/tokenSwap.ts +++ b/src/models/tokenSwap.ts @@ -1,7 +1,6 @@ import { Numberu64, TokenSwap } from "@solana/spl-token-swap"; import { PublicKey, Account, TransactionInstruction } from "@solana/web3.js"; import * as BufferLayout from "buffer-layout"; -import { PoolConfig } from "./pool"; export { TokenSwap } from "@solana/spl-token-swap"; @@ -65,322 +64,72 @@ export const TokenSwapLayoutV1: typeof BufferLayout.Structure = BufferLayout.str ] ); -export const legacyDepositInstruction = ( - tokenSwap: PublicKey, - authority: PublicKey, - transferAuthority: PublicKey, - sourceA: PublicKey, - sourceB: PublicKey, - intoA: PublicKey, - intoB: PublicKey, - poolToken: PublicKey, - poolAccount: PublicKey, - swapProgramId: PublicKey, - tokenProgramId: PublicKey, - poolTokenAmount: number | Numberu64, - maximumTokenA: number | Numberu64, - maximumTokenB: number | Numberu64, -): TransactionInstruction => { - const dataLayout = BufferLayout.struct([ - BufferLayout.u8("instruction"), - uint64("poolTokenAmount"), - uint64("maximumTokenA"), - uint64("maximumTokenB"), - ]); - - const data = Buffer.alloc(dataLayout.span); - dataLayout.encode( - { - instruction: 2, // Deposit instruction - poolTokenAmount: new Numberu64(poolTokenAmount).toBuffer(), - maximumTokenA: new Numberu64(maximumTokenA).toBuffer(), - maximumTokenB: new Numberu64(maximumTokenB).toBuffer(), - }, - data - ); - - const keys = [ - { pubkey: tokenSwap, isSigner: false, isWritable: false }, - { pubkey: authority, isSigner: false, isWritable: false }, - { pubkey: sourceA, isSigner: false, isWritable: true }, - { pubkey: sourceB, isSigner: false, isWritable: true }, - { pubkey: intoA, isSigner: false, isWritable: true }, - { pubkey: intoB, isSigner: false, isWritable: true }, - { pubkey: poolToken, isSigner: false, isWritable: true }, - { pubkey: poolAccount, isSigner: false, isWritable: true }, - { pubkey: tokenProgramId, isSigner: false, isWritable: false }, - ]; - return new TransactionInstruction({ - keys, - programId: swapProgramId, - data, - }); -}; - -export const legacyDepositExactOneInstruction = ( - tokenSwap: PublicKey, - authority: PublicKey, - transferAuthority: PublicKey, - source: PublicKey, - intoA: PublicKey, - intoB: PublicKey, - poolToken: PublicKey, - poolAccount: PublicKey, - swapProgramId: PublicKey, - tokenProgramId: PublicKey, - sourceTokenAmount: number | Numberu64, - minimumPoolTokenAmount: number | Numberu64 -): TransactionInstruction => { - const dataLayout = BufferLayout.struct([ - BufferLayout.u8("instruction"), - uint64("sourceTokenAmount"), - uint64("minimumPoolTokenAmount"), - ]); - - const data = Buffer.alloc(dataLayout.span); - dataLayout.encode( - { - instruction: 4, // DepositExactOne instruction - sourceTokenAmount: new Numberu64(sourceTokenAmount).toBuffer(), - minimumPoolTokenAmount: new Numberu64(minimumPoolTokenAmount).toBuffer(), - }, - data - ); - - const keys = [ - { pubkey: tokenSwap, isSigner: false, isWritable: false }, - { pubkey: authority, isSigner: false, isWritable: false }, - { pubkey: source, isSigner: false, isWritable: true }, - { pubkey: intoA, isSigner: false, isWritable: true }, - { pubkey: intoB, isSigner: false, isWritable: true }, - { pubkey: poolToken, isSigner: false, isWritable: true }, - { pubkey: poolAccount, isSigner: false, isWritable: true }, - { pubkey: tokenProgramId, isSigner: false, isWritable: false }, - ]; - return new TransactionInstruction({ - keys, - programId: swapProgramId, - data, - }); -}; - -export const legacyWithdrawInstruction = ( - tokenSwap: PublicKey, - authority: PublicKey, - transferAuthority: PublicKey, - poolMint: PublicKey, - feeAccount: PublicKey | undefined, - sourcePoolAccount: PublicKey, - fromA: PublicKey, - fromB: PublicKey, - userAccountA: PublicKey, - userAccountB: PublicKey, - swapProgramId: PublicKey, - tokenProgramId: PublicKey, - poolTokenAmount: number | Numberu64, - minimumTokenA: number | Numberu64, - minimumTokenB: number | Numberu64, -): TransactionInstruction => { - const dataLayout = BufferLayout.struct([ - BufferLayout.u8("instruction"), - uint64("poolTokenAmount"), - uint64("minimumTokenA"), - uint64("minimumTokenB"), - ]); - - const data = Buffer.alloc(dataLayout.span); - dataLayout.encode( - { - instruction: 3, // Withdraw instruction - poolTokenAmount: new Numberu64(poolTokenAmount).toBuffer(), - minimumTokenA: new Numberu64(minimumTokenA).toBuffer(), - minimumTokenB: new Numberu64(minimumTokenB).toBuffer(), - }, - data - ); - - const keys = [ - { pubkey: tokenSwap, isSigner: false, isWritable: false }, - { pubkey: authority, isSigner: false, isWritable: false }, - { pubkey: poolMint, isSigner: false, isWritable: true }, - { pubkey: sourcePoolAccount, isSigner: false, isWritable: true }, - { pubkey: fromA, isSigner: false, isWritable: true }, - { pubkey: fromB, isSigner: false, isWritable: true }, - { pubkey: userAccountA, isSigner: false, isWritable: true }, - { pubkey: userAccountB, isSigner: false, isWritable: true }, - ]; - - if (feeAccount) { - keys.push({ pubkey: feeAccount, isSigner: false, isWritable: true }); - } - keys.push({ pubkey: tokenProgramId, isSigner: false, isWritable: false }); - - return new TransactionInstruction({ - keys, - programId: swapProgramId, - data, - }); -}; - -export const legacyWithdrawExactOneInstruction = ( - tokenSwap: PublicKey, - authority: PublicKey, - transferAuthority: PublicKey, - poolMint: PublicKey, - sourcePoolAccount: PublicKey, - fromA: PublicKey, - fromB: PublicKey, - userAccount: PublicKey, - feeAccount: PublicKey | undefined, - swapProgramId: PublicKey, - tokenProgramId: PublicKey, - sourceTokenAmount: number | Numberu64, - maximumTokenAmount: number | Numberu64, - isLatest: boolean -): TransactionInstruction => { - const dataLayout = BufferLayout.struct([ - BufferLayout.u8("instruction"), - uint64("sourceTokenAmount"), - uint64("maximumTokenAmount"), - ]); - - const data = Buffer.alloc(dataLayout.span); - dataLayout.encode( - { - instruction: 5, // WithdrawExactOne instruction - sourceTokenAmount: new Numberu64(sourceTokenAmount).toBuffer(), - maximumTokenAmount: new Numberu64(maximumTokenAmount).toBuffer(), - }, - data - ); - - const keys = [ - { pubkey: tokenSwap, isSigner: false, isWritable: false }, - { pubkey: authority, isSigner: false, isWritable: false }, - { pubkey: poolMint, isSigner: false, isWritable: true }, - { pubkey: sourcePoolAccount, isSigner: false, isWritable: true }, - { pubkey: fromA, isSigner: false, isWritable: true }, - { pubkey: fromB, isSigner: false, isWritable: true }, - { pubkey: userAccount, isSigner: false, isWritable: true }, - ]; - - if (feeAccount) { - keys.push({ pubkey: feeAccount, isSigner: false, isWritable: true }); - } - keys.push({ pubkey: tokenProgramId, isSigner: false, isWritable: false }); - - return new TransactionInstruction({ - keys, - programId: swapProgramId, - data, - }); -}; - -export const legacySwapInstruction = ( - tokenSwap: PublicKey, - authority: PublicKey, - transferAuthority: PublicKey, - userSource: PublicKey, - poolSource: PublicKey, - poolDestination: PublicKey, - userDestination: PublicKey, - poolMint: PublicKey, - feeAccount: PublicKey, - swapProgramId: PublicKey, - tokenProgramId: PublicKey, - amountIn: number | Numberu64, - minimumAmountOut: number | Numberu64, - programOwner: PublicKey | undefined, -): TransactionInstruction => { - const dataLayout = BufferLayout.struct([ - BufferLayout.u8("instruction"), - uint64("amountIn"), - uint64("minimumAmountOut"), - ]); - - const keys = [ - { pubkey: tokenSwap, isSigner: false, isWritable: false }, - { pubkey: authority, isSigner: false, isWritable: false }, - { pubkey: userSource, isSigner: false, isWritable: true }, - { pubkey: poolSource, isSigner: false, isWritable: true }, - { pubkey: poolDestination, isSigner: false, isWritable: true }, - { pubkey: userDestination, isSigner: false, isWritable: true }, - { pubkey: poolMint, isSigner: false, isWritable: true }, - { pubkey: feeAccount, isSigner: false, isWritable: true }, - { pubkey: tokenProgramId, isSigner: false, isWritable: false }, - ]; - - // optional depending on the build of token-swap program - if (programOwner) { - keys.push({ pubkey: programOwner, isSigner: false, isWritable: true }); - } - - const data = Buffer.alloc(dataLayout.span); - dataLayout.encode( - { - instruction: 1, // Swap instruction - amountIn: new Numberu64(amountIn).toBuffer(), - minimumAmountOut: new Numberu64(minimumAmountOut).toBuffer(), - }, - data - ); - - return new TransactionInstruction({ - keys, - programId: swapProgramId, - data, - }); -}; - -// TODO: Implement each static method to map to legacy instruction class TokenSwapLegacy { - static createInitSwapInstruction( - tokenSwapAccount: Account, - authority: PublicKey, - tokenAccountA: PublicKey, - tokenAccountB: PublicKey, - tokenPool: PublicKey, - feeAccount: PublicKey, - tokenAccountPool: PublicKey, - tokenProgramId: PublicKey, - swapProgramId: PublicKey, - nonce: number, - tradeFeeNumerator: number, - tradeFeeDenominator: number, - ownerTradeFeeNumerator: number, - ownerTradeFeeDenominator: number, - ownerWithdrawFeeNumerator: number, - ownerWithdrawFeeDenominator: number, - hostFeeNumerator: number, - hostFeeDenominator: number, - curveType: number, - ): TransactionInstruction { - + // @ts-ignore: TS7019 + static createInitSwapInstruction(...args): TransactionInstruction { + throw new Error('createInitSwapInstruction not available for legacy swap program'); } static swapInstruction( tokenSwap: PublicKey, authority: PublicKey, - userTransferAuthority: PublicKey, + _userTransferAuthority: PublicKey, userSource: PublicKey, poolSource: PublicKey, poolDestination: PublicKey, userDestination: PublicKey, poolMint: PublicKey, feeAccount: PublicKey, - hostFeeAccount: PublicKey | null, + _hostFeeAccount: PublicKey | null, swapProgramId: PublicKey, tokenProgramId: PublicKey, amountIn: number | Numberu64, minimumAmountOut: number | Numberu64, ): TransactionInstruction { - + const dataLayout = BufferLayout.struct([ + BufferLayout.u8("instruction"), + uint64("amountIn"), + uint64("minimumAmountOut"), + ]); + + const keys = [ + { pubkey: tokenSwap, isSigner: false, isWritable: false }, + { pubkey: authority, isSigner: false, isWritable: false }, + { pubkey: userSource, isSigner: false, isWritable: true }, + { pubkey: poolSource, isSigner: false, isWritable: true }, + { pubkey: poolDestination, isSigner: false, isWritable: true }, + { pubkey: userDestination, isSigner: false, isWritable: true }, + { pubkey: poolMint, isSigner: false, isWritable: true }, + { pubkey: feeAccount, isSigner: false, isWritable: true }, + { pubkey: tokenProgramId, isSigner: false, isWritable: false }, + ]; + + // optional depending on the build of token-swap program + if (programOwner) { + keys.push({ pubkey: programOwner, isSigner: false, isWritable: true }); + } + + const data = Buffer.alloc(dataLayout.span); + dataLayout.encode( + { + instruction: 1, // Swap instruction + amountIn: new Numberu64(amountIn).toBuffer(), + minimumAmountOut: new Numberu64(minimumAmountOut).toBuffer(), + }, + data + ); + + return new TransactionInstruction({ + keys, + programId: swapProgramId, + data, + }); } static depositAllTokenTypesInstruction( tokenSwap: PublicKey, authority: PublicKey, - userTransferAuthority: PublicKey, + _userTransferAuthority: PublicKey, sourceA: PublicKey, sourceB: PublicKey, intoA: PublicKey, @@ -393,13 +142,47 @@ class TokenSwapLegacy { maximumTokenA: number | Numberu64, maximumTokenB: number | Numberu64, ): TransactionInstruction { - + const dataLayout = BufferLayout.struct([ + BufferLayout.u8("instruction"), + uint64("poolTokenAmount"), + uint64("maximumTokenA"), + uint64("maximumTokenB"), + ]); + + const data = Buffer.alloc(dataLayout.span); + dataLayout.encode( + { + instruction: 2, // Deposit instruction + poolTokenAmount: new Numberu64(poolTokenAmount).toBuffer(), + maximumTokenA: new Numberu64(maximumTokenA).toBuffer(), + maximumTokenB: new Numberu64(maximumTokenB).toBuffer(), + }, + data + ); + + const keys = [ + { pubkey: tokenSwap, isSigner: false, isWritable: false }, + { pubkey: authority, isSigner: false, isWritable: false }, + { pubkey: sourceA, isSigner: false, isWritable: true }, + { pubkey: sourceB, isSigner: false, isWritable: true }, + { pubkey: intoA, isSigner: false, isWritable: true }, + { pubkey: intoB, isSigner: false, isWritable: true }, + { pubkey: poolToken, isSigner: false, isWritable: true }, + { pubkey: poolAccount, isSigner: false, isWritable: true }, + { pubkey: tokenProgramId, isSigner: false, isWritable: false }, + ]; + + return new TransactionInstruction({ + keys, + programId: swapProgramId, + data, + }); } static withdrawAllTokenTypesInstruction( tokenSwap: PublicKey, authority: PublicKey, - userTransferAuthority: PublicKey, + _userTransferAuthority: PublicKey, poolMint: PublicKey, feeAccount: PublicKey, sourcePoolAccount: PublicKey, @@ -413,13 +196,51 @@ class TokenSwapLegacy { minimumTokenA: number | Numberu64, minimumTokenB: number | Numberu64, ) { - + const dataLayout = BufferLayout.struct([ + BufferLayout.u8("instruction"), + uint64("poolTokenAmount"), + uint64("minimumTokenA"), + uint64("minimumTokenB"), + ]); + + const data = Buffer.alloc(dataLayout.span); + dataLayout.encode( + { + instruction: 3, // Withdraw instruction + poolTokenAmount: new Numberu64(poolTokenAmount).toBuffer(), + minimumTokenA: new Numberu64(minimumTokenA).toBuffer(), + minimumTokenB: new Numberu64(minimumTokenB).toBuffer(), + }, + data + ); + + const keys = [ + { pubkey: tokenSwap, isSigner: false, isWritable: false }, + { pubkey: authority, isSigner: false, isWritable: false }, + { pubkey: poolMint, isSigner: false, isWritable: true }, + { pubkey: sourcePoolAccount, isSigner: false, isWritable: true }, + { pubkey: fromA, isSigner: false, isWritable: true }, + { pubkey: fromB, isSigner: false, isWritable: true }, + { pubkey: userAccountA, isSigner: false, isWritable: true }, + { pubkey: userAccountB, isSigner: false, isWritable: true }, + ]; + + if (feeAccount) { + keys.push({ pubkey: feeAccount, isSigner: false, isWritable: true }); + } + keys.push({ pubkey: tokenProgramId, isSigner: false, isWritable: false }); + + return new TransactionInstruction({ + keys, + programId: swapProgramId, + data, + }); } static depositSingleTokenTypeExactAmountInInstruction( tokenSwap: PublicKey, authority: PublicKey, - userTransferAuthority: PublicKey, + _userTransferAuthority: PublicKey, source: PublicKey, intoA: PublicKey, intoB: PublicKey, @@ -430,13 +251,44 @@ class TokenSwapLegacy { sourceTokenAmount: number | Numberu64, minimumPoolTokenAmount: number | Numberu64, ): TransactionInstruction { - + const dataLayout = BufferLayout.struct([ + BufferLayout.u8("instruction"), + uint64("sourceTokenAmount"), + uint64("minimumPoolTokenAmount"), + ]); + + const data = Buffer.alloc(dataLayout.span); + dataLayout.encode( + { + instruction: 4, // DepositExactOne instruction + sourceTokenAmount: new Numberu64(sourceTokenAmount).toBuffer(), + minimumPoolTokenAmount: new Numberu64(minimumPoolTokenAmount).toBuffer(), + }, + data + ); + + const keys = [ + { pubkey: tokenSwap, isSigner: false, isWritable: false }, + { pubkey: authority, isSigner: false, isWritable: false }, + { pubkey: source, isSigner: false, isWritable: true }, + { pubkey: intoA, isSigner: false, isWritable: true }, + { pubkey: intoB, isSigner: false, isWritable: true }, + { pubkey: poolToken, isSigner: false, isWritable: true }, + { pubkey: poolAccount, isSigner: false, isWritable: true }, + { pubkey: tokenProgramId, isSigner: false, isWritable: false }, + ]; + + return new TransactionInstruction({ + keys, + programId: swapProgramId, + data, + }); } static withdrawSingleTokenTypeExactAmountOutInstruction( tokenSwap: PublicKey, authority: PublicKey, - userTransferAuthority: PublicKey, + _userTransferAuthority: PublicKey, poolMint: PublicKey, feeAccount: PublicKey, sourcePoolAccount: PublicKey, @@ -448,7 +300,42 @@ class TokenSwapLegacy { destinationTokenAmount: number | Numberu64, maximumPoolTokenAmount: number | Numberu64, ): TransactionInstruction { - + const dataLayout = BufferLayout.struct([ + BufferLayout.u8("instruction"), + uint64("sourceTokenAmount"), + uint64("maximumTokenAmount"), + ]); + + const data = Buffer.alloc(dataLayout.span); + dataLayout.encode( + { + instruction: 5, // WithdrawExactOne instruction + sourceTokenAmount: new Numberu64(destinationTokenAmount).toBuffer(), + maximumTokenAmount: new Numberu64(maximumPoolTokenAmount).toBuffer(), + }, + data + ); + + const keys = [ + { pubkey: tokenSwap, isSigner: false, isWritable: false }, + { pubkey: authority, isSigner: false, isWritable: false }, + { pubkey: poolMint, isSigner: false, isWritable: true }, + { pubkey: sourcePoolAccount, isSigner: false, isWritable: true }, + { pubkey: fromA, isSigner: false, isWritable: true }, + { pubkey: fromB, isSigner: false, isWritable: true }, + { pubkey: userAccount, isSigner: false, isWritable: true }, + ]; + + if (feeAccount) { + keys.push({ pubkey: feeAccount, isSigner: false, isWritable: true }); + } + keys.push({ pubkey: tokenProgramId, isSigner: false, isWritable: false }); + + return new TransactionInstruction({ + keys, + programId: swapProgramId, + data, + }); } } From 96c4d62a168cc4407c38e741baad5998cb3d93ae Mon Sep 17 00:00:00 2001 From: Arrowana <8245419+Arrowana@users.noreply.github.com> Date: Sun, 25 Apr 2021 20:56:04 +1000 Subject: [PATCH 4/4] remove Layout --- src/models/tokenSwap.ts | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/models/tokenSwap.ts b/src/models/tokenSwap.ts index 53c06f897..58ef6e6df 100644 --- a/src/models/tokenSwap.ts +++ b/src/models/tokenSwap.ts @@ -18,20 +18,6 @@ export const uint64 = (property: string = "uint64"): Object => { return BufferLayout.blob(8, property); }; -const FEE_LAYOUT = BufferLayout.struct( - [ - BufferLayout.nu64("tradeFeeNumerator"), - BufferLayout.nu64("tradeFeeDenominator"), - BufferLayout.nu64("ownerTradeFeeNumerator"), - BufferLayout.nu64("ownerTradeFeeDenominator"), - BufferLayout.nu64("ownerWithdrawFeeNumerator"), - BufferLayout.nu64("ownerWithdrawFeeDenominator"), - BufferLayout.nu64("hostFeeNumerator"), - BufferLayout.nu64("hostFeeDenominator"), - ], - "fees" -); - export const TokenSwapLayoutLegacyV0 = BufferLayout.struct([ BufferLayout.u8("isInitialized"), BufferLayout.u8("nonce"),