From 80f63e20ae0c1cc548fee8ac2578c0bbe96e9f9c Mon Sep 17 00:00:00 2001 From: cnek Date: Thu, 2 Jun 2022 21:39:58 +0800 Subject: [PATCH 1/9] updated idl --- src/idl.ts | 384 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 373 insertions(+), 11 deletions(-) diff --git a/src/idl.ts b/src/idl.ts index 2e8edc6..f3922fd 100644 --- a/src/idl.ts +++ b/src/idl.ts @@ -970,6 +970,275 @@ export const IDL: Idl = { }, ], }, + { + name: 'createDepositoryMsolConfig', + accounts: [ + { + name: 'authority', + isMut: false, + isSigner: true, + }, + { + name: 'payer', + isMut: true, + isSigner: true, + }, + { + name: 'controller', + isMut: false, + isSigner: false, + }, + { + name: 'depository', + isMut: false, + isSigner: false, + }, + { + name: 'msolConfig', + isMut: true, + isSigner: false, + }, + { + name: 'systemProgram', + isMut: false, + isSigner: false, + }, + { + name: 'rent', + isMut: false, + isSigner: false, + }, + ], + args: [ + { + name: 'targetLiquidityRatio', + type: 'u16', + }, + ], + }, + { + name: 'enableMsolSwap', + accounts: [ + { + name: 'authority', + isMut: false, + isSigner: true, + }, + { + name: 'payer', + isMut: true, + isSigner: true, + }, + { + name: 'controller', + isMut: false, + isSigner: false, + }, + { + name: 'depository', + isMut: false, + isSigner: false, + }, + { + name: 'msolConfig', + isMut: true, + isSigner: false, + }, + ], + args: [ + { + name: 'enable', + type: 'bool', + }, + ], + }, + { + name: 'setMsolLiquidityRatio', + accounts: [ + { + name: 'authority', + isMut: false, + isSigner: true, + }, + { + name: 'payer', + isMut: true, + isSigner: true, + }, + { + name: 'controller', + isMut: false, + isSigner: false, + }, + { + name: 'depository', + isMut: false, + isSigner: false, + }, + { + name: 'msolConfig', + isMut: true, + isSigner: false, + }, + ], + args: [ + { + name: 'targetLiquidityRatio', + type: 'u16', + }, + ], + }, + { + name: 'swapDepositoryMsol', + accounts: [ + { + name: 'user', + isMut: true, + isSigner: true, + }, + { + name: 'payer', + isMut: true, + isSigner: true, + }, + { + name: 'controller', + isMut: true, + isSigner: false, + }, + { + name: 'depository', + isMut: true, + isSigner: false, + }, + { + name: 'msolConfig', + isMut: false, + isSigner: false, + }, + { + name: 'mangoAccount', + isMut: true, + isSigner: false, + }, + { + name: 'mangoGroup', + isMut: false, + isSigner: false, + }, + { + name: 'mangoCache', + isMut: true, + isSigner: false, + }, + { + name: 'mangoSigner', + isMut: false, + isSigner: false, + }, + { + name: 'mangoSolRootBank', + isMut: true, + isSigner: false, + }, + { + name: 'mangoSolNodeBank', + isMut: true, + isSigner: false, + }, + { + name: 'mangoSolVault', + isMut: true, + isSigner: false, + }, + { + name: 'mangoMsolRootBank', + isMut: false, + isSigner: false, + }, + { + name: 'mangoMsolNodeBank', + isMut: true, + isSigner: false, + }, + { + name: 'mangoMsolVault', + isMut: true, + isSigner: false, + }, + { + name: 'mangoProgram', + isMut: false, + isSigner: false, + }, + { + name: 'marinadeState', + isMut: true, + isSigner: false, + }, + { + name: 'msolMint', + isMut: true, + isSigner: false, + }, + { + name: 'msolMintAuthority', + isMut: false, + isSigner: false, + }, + { + name: 'liqPoolSolLegPda', + isMut: true, + isSigner: false, + }, + { + name: 'liqPoolMsolLeg', + isMut: true, + isSigner: false, + }, + { + name: 'liqPoolMsolLegAuthority', + isMut: false, + isSigner: false, + }, + { + name: 'treasuryMsolAccount', + isMut: true, + isSigner: false, + }, + { + name: 'reservePda', + isMut: true, + isSigner: false, + }, + { + name: 'solPassthroughAta', + isMut: true, + isSigner: false, + }, + { + name: 'msolPassthroughAta', + isMut: true, + isSigner: false, + }, + { + name: 'marinadeFinanceProgram', + isMut: false, + isSigner: false, + }, + { + name: 'systemProgram', + isMut: false, + isSigner: false, + }, + { + name: 'tokenProgram', + isMut: false, + isSigner: false, + }, + ], + args: [], + }, ], accounts: [ { @@ -1124,6 +1393,34 @@ export const IDL: Idl = { ], }, }, + { + name: 'mSolConfig', + type: { + kind: 'struct', + fields: [ + { + name: 'bump', + type: 'u8', + }, + { + name: 'depository', + type: 'publicKey', + }, + { + name: 'controller', + type: 'publicKey', + }, + { + name: 'enabled', + type: 'bool', + }, + { + name: 'targetLiquidityRatio', + type: 'u16', + }, + ], + }, + }, ], types: [ { @@ -1559,6 +1856,41 @@ export const IDL: Idl = { }, ], }, + { + name: 'CreateDepositoryMSolConfigEvent', + fields: [ + { + name: 'version', + type: 'u8', + index: false, + }, + { + name: 'msolConfig', + type: 'publicKey', + index: false, + }, + { + name: 'controller', + type: 'publicKey', + index: false, + }, + { + name: 'depository', + type: 'publicKey', + index: false, + }, + { + name: 'enabled', + type: 'bool', + index: false, + }, + { + name: 'targetLiquidityRatio', + type: 'u16', + index: false, + }, + ], + }, ], errors: [ { @@ -1763,61 +2095,91 @@ export const IDL: Idl = { }, { code: 6040, + name: 'MSolSwappingDisabled', + msg: 'Msol swapping is disabled', + }, + { + code: 6041, name: 'InvalidAuthority', msg: 'Only the Program initializer authority can access this instructions.', }, { - code: 6041, + code: 6042, name: 'InvalidController', msg: "The Depository's controller doesn't match the provided Controller.", }, { - code: 6042, + code: 6043, name: 'InvalidDepository', msg: 'The Depository provided is not registered with the Controller.', }, { - code: 6043, + code: 6044, name: 'InvalidCollateralMint', msg: "The provided collateral mint does not match the depository's collateral mint.", }, { - code: 6044, + code: 6045, name: 'InvalidQuoteMint', msg: "The provided quote mint does not match the depository's quote mint.", }, { - code: 6045, + code: 6046, name: 'InvalidMangoAccount', msg: "The Mango Account isn't the Depository one.", }, { - code: 6046, + code: 6047, name: 'InvalidRedeemableMint', msg: "The Redeemable Mint provided does not match the Controller's one.", }, { - code: 6047, + code: 6048, name: 'InvalidDexMarket', msg: 'The provided perp_market is not the one tied to this Depository.', }, { - code: 6048, + code: 6049, name: 'InvalidOwner', msg: 'The provided token account is not owner by the expected party.', }, { - code: 6049, + code: 6050, name: 'InvalidMaxBaseQuantity', msg: 'The max base quantity must be above 0.', }, { - code: 6050, + code: 6051, name: 'InvalidMaxQuoteQuantity', msg: 'The max quote quantity must be above 0.', }, { - code: 6051, + code: 6052, + name: 'TargetLiquidityRatioExceedMax', + msg: 'Target liquidity ratio for msol config exceed 100%', + }, + { + code: 6053, + name: 'InvalidEnablingMsolSwap', + msg: 'SOL/mSOL swap has already enabled / disabled', + }, + { + code: 6054, + name: 'InvalidNonNativeMintUsed', + msg: 'Must use native mint for setting msol config', + }, + { + code: 6055, + name: 'InvalidNonNativeMintAtaUsed', + msg: 'Must use native mint for passthrough account', + }, + { + code: 6056, + name: 'InvalidNonMSolMintAtaUsed', + msg: 'Must use msol for passthrough account', + }, + { + code: 6057, name: 'Default', msg: 'Default - Check the source code for more info', }, From 9d2954ab5ced2fb06257014b1fa44bb3039b6823 Mon Sep 17 00:00:00 2001 From: cnek Date: Thu, 2 Jun 2022 21:40:33 +0800 Subject: [PATCH 2/9] added create msol config ix --- src/client.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/client.ts b/src/client.ts index 4bd5b3b..84c5f51 100644 --- a/src/client.ts +++ b/src/client.ts @@ -620,4 +620,28 @@ export class UXDClient { options: options, }); } + + public createDepositoryMsolConfigInstruction( + targetLiquidityRatio: number, + controller: Controller, + depository: MangoDepository, + msolConfigPda: PublicKey, + authority: PublicKey, + options: ConfirmOptions, + payer?: PublicKey + ): TransactionInstruction { + const targetLiquidityRatioBN = new BN(targetLiquidityRatio) + return this.instruction.createDepositoryMsolConfig(targetLiquidityRatioBN, { + accounts: { + authority: authority, + payer: payer ?? authority, + controller: controller.pda, + depository: depository.pda, + msolConfig: msolConfigPda, + systemProgram: SystemProgram.programId, + rent: SYSVAR_RENT_PUBKEY, + }, + options: options, + }); + } } From ba7c3190efc8ff774783ffeb1a0759a51877ce0c Mon Sep 17 00:00:00 2001 From: cnek Date: Sat, 4 Jun 2022 19:11:54 +0800 Subject: [PATCH 3/9] added msol ix support --- src/client.ts | 128 +++++++++++++++++++++++++++++++++++++++++++++++++- src/idl.ts | 2 +- src/utils.ts | 3 ++ 3 files changed, 130 insertions(+), 3 deletions(-) diff --git a/src/client.ts b/src/client.ts index 84c5f51..76fe7cc 100644 --- a/src/client.ts +++ b/src/client.ts @@ -14,7 +14,7 @@ import { import { Controller } from './controller'; import { MangoDepository } from './mango/depository'; import { Mango } from './mango'; -import { findATAAddrSync, findMultipleATAAddSync } from './utils'; +import { findATAAddrSync, findMultipleATAAddSync, MSOL } from './utils'; import NamespaceFactory from './namespace'; import { IDL as UXD_IDL } from './idl'; import { PnLPolarity } from './interfaces'; @@ -630,7 +630,7 @@ export class UXDClient { options: ConfirmOptions, payer?: PublicKey ): TransactionInstruction { - const targetLiquidityRatioBN = new BN(targetLiquidityRatio) + const targetLiquidityRatioBN = new BN(targetLiquidityRatio); return this.instruction.createDepositoryMsolConfig(targetLiquidityRatioBN, { accounts: { authority: authority, @@ -644,4 +644,128 @@ export class UXDClient { options: options, }); } + + public swapDepositoryMsolInstruction( + controller: Controller, + depository: MangoDepository, + msolConfigPda: PublicKey, + mango: Mango, + options: ConfirmOptions, + user: PublicKey, + payer?: PublicKey + ): TransactionInstruction { + const mangoCacheAccount = mango.getMangoCacheAccount(); + + const msolTokenIndex = mango.group.getTokenIndex(MSOL); + const mangoMsolRootBankAccount = mango.getRootBankForToken(msolTokenIndex); + const mangoMsolNodeBankAccount = mango.getNodeBankFor(msolTokenIndex, MSOL); + const mangoMsolDepositedVaultAccount = mango.getVaultFor(msolTokenIndex); + + const wsolTokenIndex = mango.group.getTokenIndex(depository.collateralMint); + const mangoWsolRootBankAccount = mango.getRootBankForToken(wsolTokenIndex); + const mangoWsolNodeBankAccount = mango.getNodeBankFor( + wsolTokenIndex, + depository.collateralMint + ); + const mangoWsolDepositedVaultAccount = mango.getVaultFor(wsolTokenIndex); + + const [[userWsolATA], [userMsolATA]] = findMultipleATAAddSync(user, [ + depository.collateralMint, + MSOL, + ]); + + return this.instruction.swapDepositoryMsol({ + accounts: { + user: user, + payer: payer ?? user, + controller: controller.pda, + depository: depository.pda, + msolConfig: msolConfigPda, + mangoAccount: depository.mangoAccountPda, + mangoGroup: mango.group.publicKey, + mangoCache: mangoCacheAccount, + mangoSigner: mango.group.signerKey, + mangoSolRootBank: mangoWsolRootBankAccount, + mangoSolNodeBank: mangoWsolNodeBankAccount, + mangoSolVault: mangoWsolDepositedVaultAccount, + mangoMsolRootBank: mangoMsolRootBankAccount, + mangoMsolNodeBank: mangoMsolNodeBankAccount, + mangoMsolVault: mangoMsolDepositedVaultAccount, + mangoProgram: mango.programId, + marinadeState: new PublicKey( + '8szGkuLTAux9XMgZ2vtY39jVSowEcpBfFfD8hXSEqdGC' + ), + msolMint: MSOL, + msolMintAuthority: new PublicKey( + '3JLPCS1qM2zRw3Dp6V4hZnYHd4toMNPkNesXdX9tg6KM' + ), + liqPoolSolLegPda: new PublicKey( + 'UefNb6z6yvArqe4cJHTXCqStRsKmWhGxnZzuHbikP5Q' + ), + liqPoolMsolLeg: new PublicKey( + '7GgPYjS5Dza89wV6FpZ23kUJRG5vbQ1GM25ezspYFSoE' + ), + liqPoolMsolLegAuthority: new PublicKey( + 'EyaSjUtSgo9aRD1f8LWXwdvkpDTmXAW54yoSHZRF14WL' + ), + treasuryMsolAccount: new PublicKey( + 'Bcr3rbZq1g7FsPz8tawDzT6fCzN1pvADthcv3CtTpd3b' + ), + reservePda: new PublicKey( + 'Du3Ysj1wKbxPKkuPPnvzQLQh8oMSVifs3jGZjJWXFmHN' + ), + solPassthroughAta: userWsolATA, + msolPassthroughAta: userMsolATA, + marinadeFinanceProgram: new PublicKey( + 'MarBmsSgKXdrN1egZf5sqe1TMai9K1rChYNDJgjq7aD' + ), + systemProgram: SystemProgram.programId, + tokenProgram: TOKEN_PROGRAM_ID, + }, + options: options, + }); + } + + public enableMsolSwapInstruction( + enable: boolean, + controller: Controller, + depository: MangoDepository, + msolConfigPda: PublicKey, + authority: PublicKey, + options: ConfirmOptions, + payer?: PublicKey + ): TransactionInstruction { + return this.instruction.enableMsolSwap(enable, { + accounts: { + authority: authority, + payer: payer ?? authority, + controller: controller.pda, + depository: depository.pda, + msolConfig: msolConfigPda, + }, + options: options, + }); + } + + public setMsolLiquidityRatioInstruction( + targetLiquidityRatio: number, // in basis 10000 + controller: Controller, + depository: MangoDepository, + msolConfigPda: PublicKey, + authority: PublicKey, + options: ConfirmOptions, + payer?: PublicKey + ): TransactionInstruction { + const targetLiquidityRatioBN = new BN(targetLiquidityRatio); + return this.instruction.setMsolLiquidityRatio(targetLiquidityRatioBN, { + accounts: { + authority: authority, + payer: payer ?? authority, + controller: controller.pda, + depository: depository.pda, + msolConfig: msolConfigPda, + }, + options: options, + }); + } } diff --git a/src/idl.ts b/src/idl.ts index f3922fd..6034978 100644 --- a/src/idl.ts +++ b/src/idl.ts @@ -1153,7 +1153,7 @@ export const IDL: Idl = { }, { name: 'mangoMsolRootBank', - isMut: false, + isMut: true, isSigner: false, }, { diff --git a/src/utils.ts b/src/utils.ts index 2c3c8c8..f03cb84 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -32,6 +32,9 @@ export const BTC = new PublicKey( export const ETH = new PublicKey( '2FPyTwcZLUg1MDrwsyoP4D6s1tM7hAkHYRjkNb5w6Pxk' ); +export const MSOL = new PublicKey( + 'mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So' +); export const UXD_DEVNET = new PublicKey( 'GhFRARKh28888Cn6LkHu11L38pgf84TaeaVFJfuTPFUH' From 02077020cf8d691efce7287593d3301531cd6f8a Mon Sep 17 00:00:00 2001 From: cnek Date: Sat, 4 Jun 2022 23:40:12 +0800 Subject: [PATCH 4/9] install marinade sdk --- package-lock.json | 154 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 155 insertions(+) diff --git a/package-lock.json b/package-lock.json index b32de58..04dd757 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "@blockworks-foundation/mango-client": "3.4.7", + "@marinade.finance/marinade-ts-sdk": "3.0.0", "@project-serum/anchor": "0.24.2", "@solana/spl-token": "0.1.8", "@solana/web3.js": "1.42.0", @@ -2312,6 +2313,80 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, + "node_modules/@marinade.finance/marinade-ts-sdk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@marinade.finance/marinade-ts-sdk/-/marinade-ts-sdk-3.0.0.tgz", + "integrity": "sha512-Ip/U+Yy8fP+FuY09raZOYLew/eSrL09Dxm79e5gwCv58h7TcvdtXOSzh6cLOxHqeaBPsyffMc+pvoUsFcw+WWA==", + "dependencies": { + "@project-serum/anchor": "^0.18.2", + "@solana/spl-token": "^0.1.8", + "borsh": "^0.6.0", + "bs58": "^5.0.0" + } + }, + "node_modules/@marinade.finance/marinade-ts-sdk/node_modules/@project-serum/anchor": { + "version": "0.18.2", + "resolved": "https://registry.npmjs.org/@project-serum/anchor/-/anchor-0.18.2.tgz", + "integrity": "sha512-uyjiN/3Ipp+4hrZRm/hG18HzGLZyvP790LXrCsGO3IWxSl28YRhiGEpKnZycfMW94R7nxdUoE3wY67V+ZHSQBQ==", + "dependencies": { + "@project-serum/borsh": "^0.2.2", + "@solana/web3.js": "^1.17.0", + "base64-js": "^1.5.1", + "bn.js": "^5.1.2", + "bs58": "^4.0.1", + "buffer-layout": "^1.2.0", + "camelcase": "^5.3.1", + "crypto-hash": "^1.3.0", + "eventemitter3": "^4.0.7", + "find": "^0.3.0", + "js-sha256": "^0.9.0", + "pako": "^2.0.3", + "snake-case": "^3.0.4", + "toml": "^3.0.0" + }, + "engines": { + "node": ">=11" + } + }, + "node_modules/@marinade.finance/marinade-ts-sdk/node_modules/@project-serum/anchor/node_modules/bs58": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/bs58/-/bs58-4.0.1.tgz", + "integrity": "sha512-Ok3Wdf5vOIlBrgCvTq96gBkJw+JUEzdBgyaza5HLtPm7yTHkjRy8+JzNyHF7BHa0bNWOQIp3m5YF0nnFcOIKLw==", + "dependencies": { + "base-x": "^3.0.2" + } + }, + "node_modules/@marinade.finance/marinade-ts-sdk/node_modules/borsh": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/borsh/-/borsh-0.6.0.tgz", + "integrity": "sha512-sl5k89ViqsThXQpYa9XDtz1sBl3l1lI313cFUY1HKr+wvMILnb+58xpkqTNrYbelh99dY7K8usxoCusQmqix9Q==", + "dependencies": { + "bn.js": "^5.2.0", + "bs58": "^4.0.0", + "text-encoding-utf-8": "^1.0.2" + } + }, + "node_modules/@marinade.finance/marinade-ts-sdk/node_modules/borsh/node_modules/bs58": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/bs58/-/bs58-4.0.1.tgz", + "integrity": "sha512-Ok3Wdf5vOIlBrgCvTq96gBkJw+JUEzdBgyaza5HLtPm7yTHkjRy8+JzNyHF7BHa0bNWOQIp3m5YF0nnFcOIKLw==", + "dependencies": { + "base-x": "^3.0.2" + } + }, + "node_modules/@marinade.finance/marinade-ts-sdk/node_modules/bs58": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/bs58/-/bs58-5.0.0.tgz", + "integrity": "sha512-r+ihvQJvahgYT50JD05dyJNKlmmSlMoOGwn1lCcEzanPglg7TxYjioQUYehQ9mAR/+hOSd2jRc/Z2y5UxBymvQ==", + "dependencies": { + "base-x": "^4.0.0" + } + }, + "node_modules/@marinade.finance/marinade-ts-sdk/node_modules/bs58/node_modules/base-x": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/base-x/-/base-x-4.0.0.tgz", + "integrity": "sha512-FuwxlW4H5kh37X/oW59pwTzzTKRzfrrQwhmyspRM7swOEZcHtDZSCt45U6oKgtuFE+WYPblePMVIPR4RZrh/hw==" + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -9130,6 +9205,85 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, + "@marinade.finance/marinade-ts-sdk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@marinade.finance/marinade-ts-sdk/-/marinade-ts-sdk-3.0.0.tgz", + "integrity": "sha512-Ip/U+Yy8fP+FuY09raZOYLew/eSrL09Dxm79e5gwCv58h7TcvdtXOSzh6cLOxHqeaBPsyffMc+pvoUsFcw+WWA==", + "requires": { + "@project-serum/anchor": "^0.18.2", + "@solana/spl-token": "^0.1.8", + "borsh": "^0.6.0", + "bs58": "^5.0.0" + }, + "dependencies": { + "@project-serum/anchor": { + "version": "0.18.2", + "resolved": "https://registry.npmjs.org/@project-serum/anchor/-/anchor-0.18.2.tgz", + "integrity": "sha512-uyjiN/3Ipp+4hrZRm/hG18HzGLZyvP790LXrCsGO3IWxSl28YRhiGEpKnZycfMW94R7nxdUoE3wY67V+ZHSQBQ==", + "requires": { + "@project-serum/borsh": "^0.2.2", + "@solana/web3.js": "^1.17.0", + "base64-js": "^1.5.1", + "bn.js": "^5.1.2", + "bs58": "^4.0.1", + "buffer-layout": "^1.2.0", + "camelcase": "^5.3.1", + "crypto-hash": "^1.3.0", + "eventemitter3": "^4.0.7", + "find": "^0.3.0", + "js-sha256": "^0.9.0", + "pako": "^2.0.3", + "snake-case": "^3.0.4", + "toml": "^3.0.0" + }, + "dependencies": { + "bs58": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/bs58/-/bs58-4.0.1.tgz", + "integrity": "sha512-Ok3Wdf5vOIlBrgCvTq96gBkJw+JUEzdBgyaza5HLtPm7yTHkjRy8+JzNyHF7BHa0bNWOQIp3m5YF0nnFcOIKLw==", + "requires": { + "base-x": "^3.0.2" + } + } + } + }, + "borsh": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/borsh/-/borsh-0.6.0.tgz", + "integrity": "sha512-sl5k89ViqsThXQpYa9XDtz1sBl3l1lI313cFUY1HKr+wvMILnb+58xpkqTNrYbelh99dY7K8usxoCusQmqix9Q==", + "requires": { + "bn.js": "^5.2.0", + "bs58": "^4.0.0", + "text-encoding-utf-8": "^1.0.2" + }, + "dependencies": { + "bs58": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/bs58/-/bs58-4.0.1.tgz", + "integrity": "sha512-Ok3Wdf5vOIlBrgCvTq96gBkJw+JUEzdBgyaza5HLtPm7yTHkjRy8+JzNyHF7BHa0bNWOQIp3m5YF0nnFcOIKLw==", + "requires": { + "base-x": "^3.0.2" + } + } + } + }, + "bs58": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/bs58/-/bs58-5.0.0.tgz", + "integrity": "sha512-r+ihvQJvahgYT50JD05dyJNKlmmSlMoOGwn1lCcEzanPglg7TxYjioQUYehQ9mAR/+hOSd2jRc/Z2y5UxBymvQ==", + "requires": { + "base-x": "^4.0.0" + }, + "dependencies": { + "base-x": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/base-x/-/base-x-4.0.0.tgz", + "integrity": "sha512-FuwxlW4H5kh37X/oW59pwTzzTKRzfrrQwhmyspRM7swOEZcHtDZSCt45U6oKgtuFE+WYPblePMVIPR4RZrh/hw==" + } + } + } + } + }, "@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", diff --git a/package.json b/package.json index 5330c12..c6a394a 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ }, "dependencies": { "@blockworks-foundation/mango-client": "3.4.7", + "@marinade.finance/marinade-ts-sdk": "3.0.0", "@project-serum/anchor": "0.24.2", "@solana/spl-token": "0.1.8", "@solana/web3.js": "1.42.0", From bcf72077ab70333a30b5bc485f98012f809a215c Mon Sep 17 00:00:00 2001 From: cnek Date: Sat, 4 Jun 2022 23:41:19 +0800 Subject: [PATCH 5/9] get addresses from sdk --- src/client.ts | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/src/client.ts b/src/client.ts index 76fe7cc..6a7e883 100644 --- a/src/client.ts +++ b/src/client.ts @@ -18,6 +18,7 @@ import { findATAAddrSync, findMultipleATAAddSync, MSOL } from './utils'; import NamespaceFactory from './namespace'; import { IDL as UXD_IDL } from './idl'; import { PnLPolarity } from './interfaces'; +import { Marinade, MarinadeConfig } from '@marinade.finance/marinade-ts-sdk'; export class UXDClient { public instruction: InstructionNamespace; @@ -645,15 +646,16 @@ export class UXDClient { }); } - public swapDepositoryMsolInstruction( + public async swapDepositoryMsolInstruction( controller: Controller, depository: MangoDepository, msolConfigPda: PublicKey, mango: Mango, + marinadeConfig: MarinadeConfig, options: ConfirmOptions, user: PublicKey, payer?: PublicKey - ): TransactionInstruction { + ): Promise { const mangoCacheAccount = mango.getMangoCacheAccount(); const msolTokenIndex = mango.group.getTokenIndex(MSOL); @@ -674,6 +676,9 @@ export class UXDClient { MSOL, ]); + const marinade = new Marinade(marinadeConfig); + const marinadeState = await marinade.getMarinadeState(); + return this.instruction.swapDepositoryMsol({ accounts: { user: user, @@ -692,33 +697,17 @@ export class UXDClient { mangoMsolNodeBank: mangoMsolNodeBankAccount, mangoMsolVault: mangoMsolDepositedVaultAccount, mangoProgram: mango.programId, - marinadeState: new PublicKey( - '8szGkuLTAux9XMgZ2vtY39jVSowEcpBfFfD8hXSEqdGC' - ), + marinadeState: marinadeState.marinadeStateAddress, msolMint: MSOL, - msolMintAuthority: new PublicKey( - '3JLPCS1qM2zRw3Dp6V4hZnYHd4toMNPkNesXdX9tg6KM' - ), - liqPoolSolLegPda: new PublicKey( - 'UefNb6z6yvArqe4cJHTXCqStRsKmWhGxnZzuHbikP5Q' - ), - liqPoolMsolLeg: new PublicKey( - '7GgPYjS5Dza89wV6FpZ23kUJRG5vbQ1GM25ezspYFSoE' - ), - liqPoolMsolLegAuthority: new PublicKey( - 'EyaSjUtSgo9aRD1f8LWXwdvkpDTmXAW54yoSHZRF14WL' - ), - treasuryMsolAccount: new PublicKey( - 'Bcr3rbZq1g7FsPz8tawDzT6fCzN1pvADthcv3CtTpd3b' - ), - reservePda: new PublicKey( - 'Du3Ysj1wKbxPKkuPPnvzQLQh8oMSVifs3jGZjJWXFmHN' - ), + msolMintAuthority: await marinadeState.mSolMintAuthority(), + liqPoolSolLegPda: await marinadeState.solLeg(), + liqPoolMsolLeg: marinadeState.mSolLeg, + liqPoolMsolLegAuthority: await marinadeState.mSolLegAuthority(), + treasuryMsolAccount: marinadeState.treasuryMsolAccount, + reservePda: await marinadeState.reserveAddress(), solPassthroughAta: userWsolATA, msolPassthroughAta: userMsolATA, - marinadeFinanceProgram: new PublicKey( - 'MarBmsSgKXdrN1egZf5sqe1TMai9K1rChYNDJgjq7aD' - ), + marinadeFinanceProgram: marinadeState.marinadeFinanceProgramId, systemProgram: SystemProgram.programId, tokenProgram: TOKEN_PROGRAM_ID, }, From f6b571838204fb7a6492fb07145ca86887e62bf1 Mon Sep 17 00:00:00 2001 From: cnek Date: Sun, 5 Jun 2022 00:12:20 +0800 Subject: [PATCH 6/9] added msol config class --- src/mango/msol_config.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/mango/msol_config.ts diff --git a/src/mango/msol_config.ts b/src/mango/msol_config.ts new file mode 100644 index 0000000..77a7ecb --- /dev/null +++ b/src/mango/msol_config.ts @@ -0,0 +1,14 @@ +import { PublicKey } from '@solana/web3.js'; + +export class MsolConfig { + public pda: PublicKey; + public constructor( + mangoDepositorySOLPda: PublicKey, + uxdProgramId: PublicKey + ) { + [this.pda] = PublicKey.findProgramAddressSync( + [Buffer.from('MSOLCONFIG'), mangoDepositorySOLPda.toBuffer()], + uxdProgramId + ); + } +} From 14209ab8456e9b783d575b928f0cc804c72d0baf Mon Sep 17 00:00:00 2001 From: cnek Date: Sun, 5 Jun 2022 00:31:36 +0800 Subject: [PATCH 7/9] updated index --- src/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/index.ts b/src/index.ts index 076f2f3..e0dd12e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,6 +15,7 @@ export { } from './interfaces'; export { Mango, createAndInitializeMango } from './mango'; export { MangoDepository } from './mango/depository'; +export { MsolConfig } from './mango/msol_config'; export { ETH_DECIMALS, BTC_DECIMALS, @@ -31,6 +32,7 @@ export { BTC_DEVNET, ETH, ETH_DEVNET, + MSOL, createAssocTokenIx, findATAAddrSync, } from './utils'; From 5965225c2c7fe9f5801a36cc38b02b83ba06762a Mon Sep 17 00:00:00 2001 From: cnek Date: Mon, 6 Jun 2022 20:53:10 +0800 Subject: [PATCH 8/9] added marinade config creation --- src/index.ts | 3 ++- src/msol/index.ts | 13 +++++++++++++ src/{mango => msol}/msol_config.ts | 0 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/msol/index.ts rename src/{mango => msol}/msol_config.ts (100%) diff --git a/src/index.ts b/src/index.ts index e0dd12e..b449e54 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,8 +14,9 @@ export { PnLPolarity, } from './interfaces'; export { Mango, createAndInitializeMango } from './mango'; +export { createMarinadeConfig } from './msol'; export { MangoDepository } from './mango/depository'; -export { MsolConfig } from './mango/msol_config'; +export { MsolConfig } from './msol/msol_config'; export { ETH_DECIMALS, BTC_DECIMALS, diff --git a/src/msol/index.ts b/src/msol/index.ts new file mode 100644 index 0000000..1511a07 --- /dev/null +++ b/src/msol/index.ts @@ -0,0 +1,13 @@ +import { MarinadeConfig } from '@marinade.finance/marinade-ts-sdk'; +import { Connection, PublicKey } from '@solana/web3.js'; + +export function createMarinadeConfig( + connection: Connection, + user: PublicKey +): MarinadeConfig { + const marinadeConfig = new MarinadeConfig({ + connection: connection, + publicKey: user, + }); + return marinadeConfig; +} diff --git a/src/mango/msol_config.ts b/src/msol/msol_config.ts similarity index 100% rename from src/mango/msol_config.ts rename to src/msol/msol_config.ts From 0f0d53c16613d3786108fdb63ea613d239c1c460 Mon Sep 17 00:00:00 2001 From: cnek Date: Mon, 6 Jun 2022 21:00:13 +0800 Subject: [PATCH 9/9] updated idl --- src/idl.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/idl.ts b/src/idl.ts index 6034978..efb2f2e 100644 --- a/src/idl.ts +++ b/src/idl.ts @@ -1437,6 +1437,23 @@ export const IDL: Idl = { ], }, }, + { + name: 'MsolSwapRoute', + type: { + kind: 'enum', + variants: [ + { + name: 'Deposit', + }, + { + name: 'LiquidUnstake', + }, + { + name: 'NoSwapRequired', + }, + ], + }, + }, ], events: [ {