From a92364509838c68d2a92bca3ecf64aa31afef55f Mon Sep 17 00:00:00 2001 From: Alvin Philips Date: Fri, 11 Nov 2022 20:55:59 +0000 Subject: [PATCH 01/21] Bumped navigator to v0.2.14 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f3d141a..9cfc81e 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ ], "dependencies": { "@dappio-wonderland/gateway-idls": "^0.2.6", - "@dappio-wonderland/navigator": "^0.2.11", + "@dappio-wonderland/navigator": "^0.2.14", "@jup-ag/core": "1.0.0-beta.26", "@project-serum/anchor": "^0.24.2", "@project-serum/borsh": "^0.2.5", From 182562324009d50f112716ee767b72f6c65124b4 Mon Sep 17 00:00:00 2001 From: Alvin Philips Date: Fri, 11 Nov 2022 21:59:45 +0000 Subject: [PATCH 02/21] Added temporary ids for Lido --- src/ids.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ids.ts b/src/ids.ts index 65343a9..78ec783 100644 --- a/src/ids.ts +++ b/src/ids.ts @@ -59,3 +59,8 @@ export const FRANCIUM_ADAPTER_PROGRAM_ID = new PublicKey( export const FRIKTION_ADAPTER_PROGRAM_ID = new PublicKey( "ADPTzbsaBdXA3FqXoPHjaTjPfh9kadxxFKxonZihP1Ji" ); + +// TODO: UPDATE THIS +export const LIDO_ADAPTER_PROGRAM_ID = new PublicKey( + "ADPTzbsaBdXA3FqXoPHjaTjPfh9kadxxFKxonZihP1Ji" +); From b66d18ab3eaca2463584f4175577b6092f07dafa Mon Sep 17 00:00:00 2001 From: Alvin Philips Date: Fri, 11 Nov 2022 22:00:31 +0000 Subject: [PATCH 03/21] feat: Add Lido as a protocol (deposit) --- src/protocols/lido.ts | 91 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/protocols/lido.ts diff --git a/src/protocols/lido.ts b/src/protocols/lido.ts new file mode 100644 index 0000000..558eb46 --- /dev/null +++ b/src/protocols/lido.ts @@ -0,0 +1,91 @@ +import * as anchor from "@project-serum/anchor"; +import { + TOKEN_PROGRAM_ID, + getAssociatedTokenAddress, +} from "@solana/spl-token-v2"; +import { + DepositParams, + GatewayParams, + IProtocolVault, + PAYLOAD_SIZE, + WithdrawParams, +} from "../types"; +import { Gateway } from "@dappio-wonderland/gateway-idls"; +import { IVaultInfo, lido } from "@dappio-wonderland/navigator"; +import { struct, nu64, u8, u32 } from "buffer-layout"; +import { + getActivityIndex, + sigHash, + createATAWithoutCheckIx, + getGatewayAuthority, +} from "../utils"; +import { LIDO_ADAPTER_PROGRAM_ID } from "../ids"; + +export class ProtocolLido implements IProtocolVault { + constructor( + private _connection: anchor.web3.Connection, + private _gatewayProgram: anchor.Program, + private _gatewayStateKey: anchor.web3.PublicKey, + private _gatewayParams: GatewayParams + ) {} + async deposit(params: DepositParams, vault: IVaultInfo, userKey: anchor.web3.PublicKey): Promise<{ txs: anchor.web3.Transaction[]; input: Buffer; }> { + // Handle payload input here + const inputLayout = struct([u8('instruction'), nu64('amount')]); + let payload = Buffer.alloc(PAYLOAD_SIZE); + inputLayout.encode( + { + instruction: 1, + amount: new anchor.BN(params.depositAmount), + }, + payload + ); + + // Handle transaction here + const vaultInfo = vault as lido.VaultInfo; + + let preInstructions = [] as anchor.web3.TransactionInstruction[]; + + // TODO: Maybe better to do in navigator? + const bufferArray = [ + lido.LIDO_ADDRESS.toBuffer(), + Buffer.from('reserve_account'), + ]; + const [reserveAccount] = await anchor.web3.PublicKey.findProgramAddress(bufferArray, lido.LIDO_PROGRAM_ID); + const bufferArrayMint = [ + lido.LIDO_ADDRESS.toBuffer(), + Buffer.from('mint_authority'), + ]; + const [mintAuthority] = await anchor.web3.PublicKey.findProgramAddress(bufferArrayMint, lido.LIDO_PROGRAM_ID); + + const recipientStSolAddress = await getAssociatedTokenAddress(vault.shareMint, userKey); + + preInstructions.push( + await createATAWithoutCheckIx(userKey, vault.shareMint) + ); + + const remainingAccounts = [ + { pubkey: lido.LIDO_ADDRESS, isSigner: false, isWritable: true }, // 0 + { pubkey: userKey, isSigner: true, isWritable: true }, // 1 wallet.publicKey + { pubkey: recipientStSolAddress, isSigner: false, isWritable: true }, // 2 + { pubkey: vault.shareMint, isSigner: false, isWritable: true }, // 3 + { pubkey: reserveAccount, isSigner: false, isWritable: true }, // 4 + { pubkey: mintAuthority, isSigner: false, isWritable: false }, // 5 + { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, // 6 + { pubkey: anchor.web3.SystemProgram.programId, isSigner: false, isWritable: false }, // 7 + ]; + const txDeposit = await this._gatewayProgram.methods + .deposit() + .accounts({ + gatewayState: this._gatewayStateKey, + adapterProgramId: LIDO_ADAPTER_PROGRAM_ID, + baseProgramId: lido.LIDO_PROGRAM_ID, + activityIndex: await getActivityIndex(userKey), + gatewayAuthority: getGatewayAuthority(), + }) + .preInstructions(preInstructions) + .remainingAccounts(remainingAccounts) + .transaction(); + + return { txs: [txDeposit], input: payload }; + } +} \ No newline at end of file From 83f92461af1abdbfbca436aecb3ee2f8adf00701 Mon Sep 17 00:00:00 2001 From: Alvin Philips Date: Fri, 11 Nov 2022 22:01:29 +0000 Subject: [PATCH 04/21] Added Lido as a Supported protocol --- src/builder.ts | 15 +++++++++++++++ src/types.ts | 1 + 2 files changed, 16 insertions(+) diff --git a/src/builder.ts b/src/builder.ts index 366f968..0a60ccb 100644 --- a/src/builder.ts +++ b/src/builder.ts @@ -14,6 +14,7 @@ import { nftFinance, katana, friktion, + lido, } from "@dappio-wonderland/navigator"; import { ActionType, @@ -63,6 +64,7 @@ import { ProtocolFrancium } from "./protocols/francium"; import { ProtocolKatana } from "./protocols/katana"; import { ProtocolTulip } from "./protocols/tulip"; import { ProtocolFriktion } from "./protocols/friktion"; +import { ProtocolLido } from "./protocols/lido"; export class GatewayBuilder { public params: GatewayParams; @@ -1188,6 +1190,19 @@ export class GatewayBuilder { ); break; + case SupportedProtocols.Lido: + this._metadata.vault = await lido.infos.getVault( + this._provider.connection, + depositParams.vaultId + ); + protocol = new ProtocolLido( + this._provider.connection, + this._program, + await this.getGatewayStateKey(), + this.params + ); + + break; default: throw new Error("Unsupported Protocol"); } diff --git a/src/types.ts b/src/types.ts index 06c25ed..1ff6bad 100644 --- a/src/types.ts +++ b/src/types.ts @@ -219,6 +219,7 @@ export enum SupportedProtocols { Francium = 9, Friktion = 10, Katana = 11, + Lido = 12, } export interface RouteInfoExtend extends RouteInfo { From 349c8fcc49aa3aee50909640598df4ed46735286 Mon Sep 17 00:00:00 2001 From: Alvin Philips Date: Fri, 11 Nov 2022 22:05:44 +0000 Subject: [PATCH 05/21] Added Lido withdraw stub in builder --- src/builder.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/builder.ts b/src/builder.ts index 0a60ccb..2f7abd8 100644 --- a/src/builder.ts +++ b/src/builder.ts @@ -1312,6 +1312,24 @@ export class GatewayBuilder { break; + case SupportedProtocols.Lido: + this._metadata.vault = await lido.infos.getVault( + this._provider.connection, + withdrawParams.vaultId + ); + + protocol = new ProtocolLido( + this._provider.connection, + this._program, + await this.getGatewayStateKey(), + this.params + ); + + // TODO: Remove once Lido has withdraw support + throw new Error("Lido withdraw has not been implemented yet!"); + + break; + default: throw new Error("Unsupported Protocol"); } From 72cbd188a51b7fdebca36cc88a09cb315cd1cbd2 Mon Sep 17 00:00:00 2001 From: Alvin Philips Date: Mon, 14 Nov 2022 12:02:58 +0000 Subject: [PATCH 06/21] Removed unused vaultInfo from deposit() --- src/protocols/lido.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/protocols/lido.ts b/src/protocols/lido.ts index 558eb46..a150f33 100644 --- a/src/protocols/lido.ts +++ b/src/protocols/lido.ts @@ -41,7 +41,6 @@ export class ProtocolLido implements IProtocolVault { ); // Handle transaction here - const vaultInfo = vault as lido.VaultInfo; let preInstructions = [] as anchor.web3.TransactionInstruction[]; @@ -59,6 +58,7 @@ export class ProtocolLido implements IProtocolVault { const recipientStSolAddress = await getAssociatedTokenAddress(vault.shareMint, userKey); + // TODO: Verify if this requires a check here preInstructions.push( await createATAWithoutCheckIx(userKey, vault.shareMint) ); From 7ad028f4ffb38110e3f7d6483410da6a8797509e Mon Sep 17 00:00:00 2001 From: Alvin Philips Date: Mon, 14 Nov 2022 17:54:52 +0530 Subject: [PATCH 07/21] Ran prettier on lido.ts --- src/protocols/lido.ts | 50 ++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/src/protocols/lido.ts b/src/protocols/lido.ts index a150f33..6bf99a6 100644 --- a/src/protocols/lido.ts +++ b/src/protocols/lido.ts @@ -1,24 +1,10 @@ import * as anchor from "@project-serum/anchor"; -import { - TOKEN_PROGRAM_ID, - getAssociatedTokenAddress, -} from "@solana/spl-token-v2"; -import { - DepositParams, - GatewayParams, - IProtocolVault, - PAYLOAD_SIZE, - WithdrawParams, -} from "../types"; +import { TOKEN_PROGRAM_ID, getAssociatedTokenAddress } from "@solana/spl-token-v2"; +import { DepositParams, GatewayParams, IProtocolVault, PAYLOAD_SIZE, WithdrawParams } from "../types"; import { Gateway } from "@dappio-wonderland/gateway-idls"; import { IVaultInfo, lido } from "@dappio-wonderland/navigator"; import { struct, nu64, u8, u32 } from "buffer-layout"; -import { - getActivityIndex, - sigHash, - createATAWithoutCheckIx, - getGatewayAuthority, -} from "../utils"; +import { getActivityIndex, sigHash, createATAWithoutCheckIx, getGatewayAuthority } from "../utils"; import { LIDO_ADAPTER_PROGRAM_ID } from "../ids"; export class ProtocolLido implements IProtocolVault { @@ -28,9 +14,13 @@ export class ProtocolLido implements IProtocolVault { private _gatewayStateKey: anchor.web3.PublicKey, private _gatewayParams: GatewayParams ) {} - async deposit(params: DepositParams, vault: IVaultInfo, userKey: anchor.web3.PublicKey): Promise<{ txs: anchor.web3.Transaction[]; input: Buffer; }> { + async deposit( + params: DepositParams, + vault: IVaultInfo, + userKey: anchor.web3.PublicKey + ): Promise<{ txs: anchor.web3.Transaction[]; input: Buffer }> { // Handle payload input here - const inputLayout = struct([u8('instruction'), nu64('amount')]); + const inputLayout = struct([u8("instruction"), nu64("amount")]); let payload = Buffer.alloc(PAYLOAD_SIZE); inputLayout.encode( { @@ -45,23 +35,15 @@ export class ProtocolLido implements IProtocolVault { let preInstructions = [] as anchor.web3.TransactionInstruction[]; // TODO: Maybe better to do in navigator? - const bufferArray = [ - lido.LIDO_ADDRESS.toBuffer(), - Buffer.from('reserve_account'), - ]; + const bufferArray = [lido.LIDO_ADDRESS.toBuffer(), Buffer.from("reserve_account")]; const [reserveAccount] = await anchor.web3.PublicKey.findProgramAddress(bufferArray, lido.LIDO_PROGRAM_ID); - const bufferArrayMint = [ - lido.LIDO_ADDRESS.toBuffer(), - Buffer.from('mint_authority'), - ]; + const bufferArrayMint = [lido.LIDO_ADDRESS.toBuffer(), Buffer.from("mint_authority")]; const [mintAuthority] = await anchor.web3.PublicKey.findProgramAddress(bufferArrayMint, lido.LIDO_PROGRAM_ID); - + const recipientStSolAddress = await getAssociatedTokenAddress(vault.shareMint, userKey); - + // TODO: Verify if this requires a check here - preInstructions.push( - await createATAWithoutCheckIx(userKey, vault.shareMint) - ); + preInstructions.push(await createATAWithoutCheckIx(userKey, vault.shareMint)); const remainingAccounts = [ { pubkey: lido.LIDO_ADDRESS, isSigner: false, isWritable: true }, // 0 @@ -85,7 +67,7 @@ export class ProtocolLido implements IProtocolVault { .preInstructions(preInstructions) .remainingAccounts(remainingAccounts) .transaction(); - + return { txs: [txDeposit], input: payload }; } -} \ No newline at end of file +} From 5a6d789848b34463ede981653153a3bf57b7a69c Mon Sep 17 00:00:00 2001 From: Alvin Philips Date: Mon, 14 Nov 2022 21:06:35 +0000 Subject: [PATCH 08/21] Switched to findProgramAddressSync --- src/protocols/lido.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/protocols/lido.ts b/src/protocols/lido.ts index 6bf99a6..fc58483 100644 --- a/src/protocols/lido.ts +++ b/src/protocols/lido.ts @@ -36,9 +36,9 @@ export class ProtocolLido implements IProtocolVault { // TODO: Maybe better to do in navigator? const bufferArray = [lido.LIDO_ADDRESS.toBuffer(), Buffer.from("reserve_account")]; - const [reserveAccount] = await anchor.web3.PublicKey.findProgramAddress(bufferArray, lido.LIDO_PROGRAM_ID); + const [reserveAccount] = anchor.web3.PublicKey.findProgramAddressSync(bufferArray, lido.LIDO_PROGRAM_ID); const bufferArrayMint = [lido.LIDO_ADDRESS.toBuffer(), Buffer.from("mint_authority")]; - const [mintAuthority] = await anchor.web3.PublicKey.findProgramAddress(bufferArrayMint, lido.LIDO_PROGRAM_ID); + const [mintAuthority] = anchor.web3.PublicKey.findProgramAddressSync(bufferArrayMint, lido.LIDO_PROGRAM_ID); const recipientStSolAddress = await getAssociatedTokenAddress(vault.shareMint, userKey); From 859bd9037e913097366fb286093d2aeb882bc64d Mon Sep 17 00:00:00 2001 From: Alvin Philips Date: Mon, 14 Nov 2022 23:12:36 +0000 Subject: [PATCH 09/21] feat: Added withdrawal --- src/protocols/lido.ts | 109 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/src/protocols/lido.ts b/src/protocols/lido.ts index fc58483..2550c30 100644 --- a/src/protocols/lido.ts +++ b/src/protocols/lido.ts @@ -70,4 +70,113 @@ export class ProtocolLido implements IProtocolVault { return { txs: [txDeposit], input: payload }; } + + async withdraw( + params: WithdrawParams, + vault: IVaultInfo, + userKey: anchor.web3.PublicKey + ): Promise<{ txs: anchor.web3.Transaction[]; input: Buffer }> { + // Handle payload input here + const inputLayout = struct([u8("instruction"), nu64("amount"), u32("validatorIndex")]); + let payload = Buffer.alloc(PAYLOAD_SIZE); + + const vaultInfo = vault as lido.VaultInfo; + const vaultInfoWrapper = new lido.VaultInfoWrapper(vaultInfo); + + const heaviestValidator = vaultInfoWrapper.getHeaviestValidator(); + // TODO: Not required in case of v1, so perhaps this should only be calculated in case of v2? + const heaviestValidatorIndex = vaultInfo.validators.entries.findIndex((value) => + value.pubkey.equals(heaviestValidator.pubkey) + ); + + inputLayout.encode( + { + // The instuction is 23 if using lido v2, 2 for v1 + instruction: vaultInfo.lidoVersion.toNumber() == 2 ? 23 : 2, + amount: new anchor.BN(params.withdrawAmount), + // Set validator index. Only used in v2 + validatorIndex: heaviestValidatorIndex, + }, + payload + ); + + // Account to temporarily hold stSOL in + const receivingAccount = anchor.web3.Keypair.generate(); + + const senderStSolAddress = await getAssociatedTokenAddress(vault.shareMint, userKey); + + const bufferArrayStake = [lido.LIDO_ADDRESS.toBuffer(), Buffer.from("stake_authority")]; + const [stakeAuthority] = anchor.web3.PublicKey.findProgramAddressSync(bufferArrayStake, lido.LIDO_PROGRAM_ID); + + const validatorStakeSeeds = [ + lido.LIDO_ADDRESS.toBuffer(), + heaviestValidator.pubkey.toBuffer(), + Buffer.from("validator_stake_account"), + Buffer.from(heaviestValidator.entry.stakeSeeds.begin.toArray("le", 8)), + ]; + + const [validatorStakeAccount] = anchor.web3.PublicKey.findProgramAddressSync( + validatorStakeSeeds, + lido.LIDO_PROGRAM_ID + ); + + // Set up accounts + let remainingAccounts: anchor.web3.AccountMeta[]; + + if (vaultInfo.lidoVersion.toNumber() == 2) { + remainingAccounts = [ + { pubkey: lido.LIDO_ADDRESS, isSigner: false, isWritable: true }, // 1 + { pubkey: userKey, isSigner: true, isWritable: false }, // 2 + { pubkey: senderStSolAddress, isSigner: false, isWritable: true }, // 3 + { pubkey: vault.shareMint, isSigner: false, isWritable: true }, // 4 + { pubkey: heaviestValidator.pubkey, isSigner: false, isWritable: false }, // 5 + { pubkey: validatorStakeAccount, isSigner: false, isWritable: true }, // 6 + { pubkey: receivingAccount.publicKey, isSigner: true, isWritable: true }, // 7 + { pubkey: stakeAuthority, isSigner: false, isWritable: false }, // 8 + { pubkey: vaultInfo.validatorList, isSigner: false, isWritable: true }, // 9 + { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, // 10 + { pubkey: anchor.web3.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, // 11 + { pubkey: anchor.web3.SystemProgram.programId, isSigner: false, isWritable: false }, // 12 + { pubkey: anchor.web3.StakeProgram.programId, isSigner: false, isWritable: false }, // 13 + ]; + } else { + remainingAccounts = [ + { pubkey: lido.LIDO_ADDRESS, isSigner: false, isWritable: true }, // 1 + { pubkey: userKey, isSigner: true, isWritable: false }, // 2 + { pubkey: senderStSolAddress, isSigner: false, isWritable: true }, // 3 + { pubkey: vault.shareMint, isSigner: false, isWritable: true }, // 4 + { pubkey: heaviestValidator.pubkey, isSigner: false, isWritable: false }, // 5 + { pubkey: validatorStakeAccount, isSigner: false, isWritable: true }, // 6 + { pubkey: receivingAccount.publicKey, isSigner: true, isWritable: true }, // 7 + { pubkey: stakeAuthority, isSigner: false, isWritable: false }, // 8 + { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, // 10 + { pubkey: anchor.web3.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, // 11 + { pubkey: anchor.web3.SystemProgram.programId, isSigner: false, isWritable: false }, // 12 + { pubkey: anchor.web3.StakeProgram.programId, isSigner: false, isWritable: false }, // 13 + ]; + } + + // Create transaction for post-unstaking withdrawal of funds + // TODO: Maybe add signers? + const txDeactivate = anchor.web3.StakeProgram.deactivate({ + authorizedPubkey: userKey, + stakePubkey: receivingAccount.publicKey, + }); + + // Handle transaction here + const txWithdraw = await this._gatewayProgram.methods + .withdraw() + .accounts({ + gatewayState: this._gatewayStateKey, + adapterProgramId: LIDO_ADAPTER_PROGRAM_ID, + baseProgramId: lido.LIDO_PROGRAM_ID, + activityIndex: await getActivityIndex(userKey), + gatewayAuthority: getGatewayAuthority(), + }) + .remainingAccounts(remainingAccounts) + .postInstructions(txDeactivate.instructions) + .transaction(); + + return { txs: [txWithdraw], input: payload }; + } } From c87754906988bd16bb565bea8d0a3cca491d86e4 Mon Sep 17 00:00:00 2001 From: Alvin Philips Date: Mon, 14 Nov 2022 23:22:54 +0000 Subject: [PATCH 10/21] Added test for Lido Adapter --- tests/testAdapterLido.ts | 110 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 tests/testAdapterLido.ts diff --git a/tests/testAdapterLido.ts b/tests/testAdapterLido.ts new file mode 100644 index 0000000..c2284f5 --- /dev/null +++ b/tests/testAdapterLido.ts @@ -0,0 +1,110 @@ +import * as anchor from "@project-serum/anchor"; +import { PublicKey, Connection } from "@solana/web3.js"; +import NodeWallet from "@project-serum/anchor/dist/cjs/nodewallet"; +import { GatewayBuilder, SupportedProtocols, DepositParams, WithdrawParams } from "../src"; + +describe("Gateway", () => { + const connection = new Connection("https://rpc-mainnet-fork-1.dappio.xyz", { + commitment: "confirmed", + wsEndpoint: "wss://rpc-mainnet-fork-1.dappio.xyz/ws", + }); + // const connection = new Connection("https://rpc-mainnet-fork.epochs.studio", { + // commitment: "confirmed", + // wsEndpoint: "wss://rpc-mainnet-fork.epochs.studio/ws", + // }); + // const connection = new Connection("https://solana-api.tt-prod.net", { + // commitment: "confirmed", + // confirmTransactionInitialTimeout: 180 * 1000, + // }); + // const connection = new Connection("https://ssc-dao.genesysgo.net", { + // commitment: "confirmed", + // confirmTransactionInitialTimeout: 180 * 1000, + // }); + // const connection = new Connection("https:////api.mainnet-beta.solana.com", { + // commitment: "confirmed", + // confirmTransactionInitialTimeout: 180 * 1000, + // }); + + const options = anchor.AnchorProvider.defaultOptions(); + const wallet = NodeWallet.local(); + const provider = new anchor.AnchorProvider(connection, wallet, options); + + anchor.setProvider(provider); + + const depositAmount = 100; + const withdrawAmount = 100; + + it("Deposit in Lido Vault", async () => { + const vaultId = new PublicKey( + // "6tkFEgE6zry2gGC4yqLrTghdqtqadyT5H3H2AJd4w5rz" // RAY-USDC + "GSAqLGG3AHABTnNSzsorjbqTSbhTmtkFN2dBPxua3RGR" // RAY-SRM + ); + + const depositParams: DepositParams = { + protocol: SupportedProtocols.Lido, + vaultId: vaultId, + depositAmount: depositAmount, + }; + + const gateway = new GatewayBuilder(provider); + await gateway.deposit(depositParams); + + await gateway.finalize(); + + console.log(gateway.params); + + const txs = gateway.transactions(); + + console.log("======"); + console.log("Txs are sent..."); + for (let tx of txs) { + // tx.feePayer = wallet.publicKey; + // tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash; + // console.log("\n", tx.serializeMessage().toString("base64"), "\n"); + const sig = await provider.sendAndConfirm(tx, [], { + skipPreflight: false, + commitment: "confirmed", + } as unknown as anchor.web3.ConfirmOptions); + console.log(sig); + } + console.log("Txs are executed"); + console.log("======"); + }); + + it("Withdraw from Lido Vault", async () => { + const vaultId = new PublicKey( + // "6tkFEgE6zry2gGC4yqLrTghdqtqadyT5H3H2AJd4w5rz" // RAY-USDC + "GSAqLGG3AHABTnNSzsorjbqTSbhTmtkFN2dBPxua3RGR" // RAY-SRM + ); + + const withdrawParams: WithdrawParams = { + protocol: SupportedProtocols.Lido, + vaultId: vaultId, + withdrawAmount: withdrawAmount, + }; + + const gateway = new GatewayBuilder(provider); + await gateway.withdraw(withdrawParams); + + await gateway.finalize(); + + console.log(gateway.params); + + const txs = gateway.transactions(); + + console.log("======"); + console.log("Txs are sent..."); + for (let tx of txs) { + // tx.feePayer = wallet.publicKey; + // tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash; + // console.log("\n", tx.serializeMessage().toString("base64"), "\n"); + const sig = await provider.sendAndConfirm(tx, [], { + skipPreflight: false, + commitment: "confirmed", + } as unknown as anchor.web3.ConfirmOptions); + console.log(sig); + } + console.log("Txs are executed"); + console.log("======"); + }); +}); From ab682f08e8d8ff33c3e4edd8edb20aa73b26e8d3 Mon Sep 17 00:00:00 2001 From: Alvin Philips Date: Mon, 14 Nov 2022 23:47:14 +0000 Subject: [PATCH 11/21] Updated Lido Adapter Program ID --- src/ids.ts | 61 ++++++++++++++---------------------------------------- 1 file changed, 15 insertions(+), 46 deletions(-) diff --git a/src/ids.ts b/src/ids.ts index 78ec783..6100f51 100644 --- a/src/ids.ts +++ b/src/ids.ts @@ -2,65 +2,34 @@ import { PublicKey } from "@solana/web3.js"; // Program IDs -export const GATEWAY_PROGRAM_ID = new PublicKey( - "GATEp6AEtXtwHABNWHKH9qeh3uJDZtZJ7YBNYzHsX3FS" -); +export const GATEWAY_PROGRAM_ID = new PublicKey("GATEp6AEtXtwHABNWHKH9qeh3uJDZtZJ7YBNYzHsX3FS"); -export const RAYDIUM_ADAPTER_PROGRAM_ID = new PublicKey( - "ADPT1q4xG8F9m64cQyjqGe11cCXQq6vL4beY5hJavhQ5" -); +export const RAYDIUM_ADAPTER_PROGRAM_ID = new PublicKey("ADPT1q4xG8F9m64cQyjqGe11cCXQq6vL4beY5hJavhQ5"); -export const SABER_ADAPTER_PROGRAM_ID = new PublicKey( - "ADPT4GbWTs9DXxo91YGBjNntYwLpXxn4gEbxfnUPfQoB" -); +export const SABER_ADAPTER_PROGRAM_ID = new PublicKey("ADPT4GbWTs9DXxo91YGBjNntYwLpXxn4gEbxfnUPfQoB"); -export const TULIP_ADAPTER_PROGRAM_ID = new PublicKey( - "ADPT9nhC1asRcEB13FKymLTatqWGCuZHDznGgnakWKxW" -); +export const TULIP_ADAPTER_PROGRAM_ID = new PublicKey("ADPT9nhC1asRcEB13FKymLTatqWGCuZHDznGgnakWKxW"); -export const SOLEND_ADAPTER_PROGRAM_ID = new PublicKey( - "ADPTCXAFfJFVqcw73B4PWRZQjMNo7Q3Yj4g7p4zTiZnQ" -); +export const SOLEND_ADAPTER_PROGRAM_ID = new PublicKey("ADPTCXAFfJFVqcw73B4PWRZQjMNo7Q3Yj4g7p4zTiZnQ"); -export const NFT_FINANCE_ADAPTER_PROGRAM_ID = new PublicKey( - "ADPTyBr92sBCE1hdYBRvXbMpF4hKs17xyDjFPxopcsrh" -); +export const NFT_FINANCE_ADAPTER_PROGRAM_ID = new PublicKey("ADPTyBr92sBCE1hdYBRvXbMpF4hKs17xyDjFPxopcsrh"); -export const SERUM_PROGRAM_ID = new PublicKey( - "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin" -); +export const SERUM_PROGRAM_ID = new PublicKey("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"); export const NATIVE_SOL = new PublicKey("11111111111111111111111111111111"); -export const WSOL = new PublicKey( - "So11111111111111111111111111111111111111112" -); +export const WSOL = new PublicKey("So11111111111111111111111111111111111111112"); -export const LARIX_ADAPTER_PROGRAM_ID = new PublicKey( - "ADPTLQQ1Bwgybb2qge7QKSW7woDrhEjcLWG642qP2X4" -); +export const LARIX_ADAPTER_PROGRAM_ID = new PublicKey("ADPTLQQ1Bwgybb2qge7QKSW7woDrhEjcLWG642qP2X4"); -export const LIFINITY_ADAPTER_PROGRAM_ID = new PublicKey( - "ADPTF4WmNPebELw6UvnSVBdL7BAqs5ceg9tyrHsQfrJK" -); +export const LIFINITY_ADAPTER_PROGRAM_ID = new PublicKey("ADPTF4WmNPebELw6UvnSVBdL7BAqs5ceg9tyrHsQfrJK"); -export const ORCA_ADAPTER_PROGRAM_ID = new PublicKey( - "ADPTTyNqameXftbqsxwXhbs7v7XP8E82YMaUStPgjmU5" -); +export const ORCA_ADAPTER_PROGRAM_ID = new PublicKey("ADPTTyNqameXftbqsxwXhbs7v7XP8E82YMaUStPgjmU5"); -export const KATANA_ADAPTER_PROGRAM_ID = new PublicKey( - "ADPTwDKJTizC3V8gZXDxt5uLjJv4pBnh1nTTf9dZJnS2" -); +export const KATANA_ADAPTER_PROGRAM_ID = new PublicKey("ADPTwDKJTizC3V8gZXDxt5uLjJv4pBnh1nTTf9dZJnS2"); -export const FRANCIUM_ADAPTER_PROGRAM_ID = new PublicKey( - "ADPTax5HwQ2ZWVLmceCek8UrqMhwCy5q3SHwi8W71Kv2" -); +export const FRANCIUM_ADAPTER_PROGRAM_ID = new PublicKey("ADPTax5HwQ2ZWVLmceCek8UrqMhwCy5q3SHwi8W71Kv2"); -export const FRIKTION_ADAPTER_PROGRAM_ID = new PublicKey( - "ADPTzbsaBdXA3FqXoPHjaTjPfh9kadxxFKxonZihP1Ji" -); +export const FRIKTION_ADAPTER_PROGRAM_ID = new PublicKey("ADPTzbsaBdXA3FqXoPHjaTjPfh9kadxxFKxonZihP1Ji"); -// TODO: UPDATE THIS -export const LIDO_ADAPTER_PROGRAM_ID = new PublicKey( - "ADPTzbsaBdXA3FqXoPHjaTjPfh9kadxxFKxonZihP1Ji" -); +export const LIDO_ADAPTER_PROGRAM_ID = new PublicKey("ADPTPxbHbEBo9A8E53P2PZnmw3ZYJuwc8ArQQkbJtqhx"); From 8c52d8dee6391b973f776b6f2ecde85a13d416d6 Mon Sep 17 00:00:00 2001 From: Alvin Philips Date: Tue, 15 Nov 2022 06:51:42 +0530 Subject: [PATCH 12/21] Fix account numbering in case of v1 --- src/protocols/lido.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/protocols/lido.ts b/src/protocols/lido.ts index 2550c30..820e6e3 100644 --- a/src/protocols/lido.ts +++ b/src/protocols/lido.ts @@ -149,10 +149,10 @@ export class ProtocolLido implements IProtocolVault { { pubkey: validatorStakeAccount, isSigner: false, isWritable: true }, // 6 { pubkey: receivingAccount.publicKey, isSigner: true, isWritable: true }, // 7 { pubkey: stakeAuthority, isSigner: false, isWritable: false }, // 8 - { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, // 10 - { pubkey: anchor.web3.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, // 11 - { pubkey: anchor.web3.SystemProgram.programId, isSigner: false, isWritable: false }, // 12 - { pubkey: anchor.web3.StakeProgram.programId, isSigner: false, isWritable: false }, // 13 + { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, // 9 + { pubkey: anchor.web3.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, // 10 + { pubkey: anchor.web3.SystemProgram.programId, isSigner: false, isWritable: false }, // 11 + { pubkey: anchor.web3.StakeProgram.programId, isSigner: false, isWritable: false }, // 12 ]; } From 8287e0cb659179368f626499197d9926b51070c1 Mon Sep 17 00:00:00 2001 From: Alvin Philips Date: Tue, 15 Nov 2022 19:10:16 +0530 Subject: [PATCH 13/21] Removed deactivate transaction from gateway --- src/protocols/lido.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/protocols/lido.ts b/src/protocols/lido.ts index 820e6e3..ce41346 100644 --- a/src/protocols/lido.ts +++ b/src/protocols/lido.ts @@ -156,13 +156,6 @@ export class ProtocolLido implements IProtocolVault { ]; } - // Create transaction for post-unstaking withdrawal of funds - // TODO: Maybe add signers? - const txDeactivate = anchor.web3.StakeProgram.deactivate({ - authorizedPubkey: userKey, - stakePubkey: receivingAccount.publicKey, - }); - // Handle transaction here const txWithdraw = await this._gatewayProgram.methods .withdraw() @@ -174,7 +167,6 @@ export class ProtocolLido implements IProtocolVault { gatewayAuthority: getGatewayAuthority(), }) .remainingAccounts(remainingAccounts) - .postInstructions(txDeactivate.instructions) .transaction(); return { txs: [txWithdraw], input: payload }; From 5ec577a8b05695d0028f5e30c7e1e81b0fb4d87e Mon Sep 17 00:00:00 2001 From: Alvin Philips Date: Tue, 29 Nov 2022 21:20:30 +0530 Subject: [PATCH 14/21] Removed instruction byte from adapter input struct --- src/protocols/lido.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/protocols/lido.ts b/src/protocols/lido.ts index ce41346..02484b1 100644 --- a/src/protocols/lido.ts +++ b/src/protocols/lido.ts @@ -20,11 +20,10 @@ export class ProtocolLido implements IProtocolVault { userKey: anchor.web3.PublicKey ): Promise<{ txs: anchor.web3.Transaction[]; input: Buffer }> { // Handle payload input here - const inputLayout = struct([u8("instruction"), nu64("amount")]); + const inputLayout = struct([nu64("amount")]); let payload = Buffer.alloc(PAYLOAD_SIZE); inputLayout.encode( { - instruction: 1, amount: new anchor.BN(params.depositAmount), }, payload @@ -34,7 +33,7 @@ export class ProtocolLido implements IProtocolVault { let preInstructions = [] as anchor.web3.TransactionInstruction[]; - // TODO: Maybe better to do in navigator? + // Maybe better to do in navigator? const bufferArray = [lido.LIDO_ADDRESS.toBuffer(), Buffer.from("reserve_account")]; const [reserveAccount] = anchor.web3.PublicKey.findProgramAddressSync(bufferArray, lido.LIDO_PROGRAM_ID); const bufferArrayMint = [lido.LIDO_ADDRESS.toBuffer(), Buffer.from("mint_authority")]; @@ -42,7 +41,7 @@ export class ProtocolLido implements IProtocolVault { const recipientStSolAddress = await getAssociatedTokenAddress(vault.shareMint, userKey); - // TODO: Verify if this requires a check here + // TVerify if this requires a check here preInstructions.push(await createATAWithoutCheckIx(userKey, vault.shareMint)); const remainingAccounts = [ @@ -77,22 +76,21 @@ export class ProtocolLido implements IProtocolVault { userKey: anchor.web3.PublicKey ): Promise<{ txs: anchor.web3.Transaction[]; input: Buffer }> { // Handle payload input here - const inputLayout = struct([u8("instruction"), nu64("amount"), u32("validatorIndex")]); + const inputLayout = struct([nu64("amount"), u32("validatorIndex")]); let payload = Buffer.alloc(PAYLOAD_SIZE); const vaultInfo = vault as lido.VaultInfo; const vaultInfoWrapper = new lido.VaultInfoWrapper(vaultInfo); const heaviestValidator = vaultInfoWrapper.getHeaviestValidator(); - // TODO: Not required in case of v1, so perhaps this should only be calculated in case of v2? + + // Not required in case of v1 const heaviestValidatorIndex = vaultInfo.validators.entries.findIndex((value) => value.pubkey.equals(heaviestValidator.pubkey) ); inputLayout.encode( { - // The instuction is 23 if using lido v2, 2 for v1 - instruction: vaultInfo.lidoVersion.toNumber() == 2 ? 23 : 2, amount: new anchor.BN(params.withdrawAmount), // Set validator index. Only used in v2 validatorIndex: heaviestValidatorIndex, From 725c7b52dd4d9117463c1a53e656d64a960f31d3 Mon Sep 17 00:00:00 2001 From: Alvin Philips Date: Tue, 29 Nov 2022 21:47:46 +0530 Subject: [PATCH 15/21] Removed error thrown with Lido withdraw --- src/builder.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/builder.ts b/src/builder.ts index 2f7abd8..cfbb80b 100644 --- a/src/builder.ts +++ b/src/builder.ts @@ -1324,9 +1324,6 @@ export class GatewayBuilder { await this.getGatewayStateKey(), this.params ); - - // TODO: Remove once Lido has withdraw support - throw new Error("Lido withdraw has not been implemented yet!"); break; From 595d563b35f648cf11b30c5a2cd012e7aa236846 Mon Sep 17 00:00:00 2001 From: Alvin Philips Date: Tue, 29 Nov 2022 21:52:58 +0530 Subject: [PATCH 16/21] Added fallback in case of mistyped BN field --- src/protocols/lido.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/protocols/lido.ts b/src/protocols/lido.ts index 02484b1..29adceb 100644 --- a/src/protocols/lido.ts +++ b/src/protocols/lido.ts @@ -121,7 +121,7 @@ export class ProtocolLido implements IProtocolVault { // Set up accounts let remainingAccounts: anchor.web3.AccountMeta[]; - if (vaultInfo.lidoVersion.toNumber() == 2) { + if (new anchor.BN(vaultInfo.lidoVersion).toNumber() == 2) { remainingAccounts = [ { pubkey: lido.LIDO_ADDRESS, isSigner: false, isWritable: true }, // 1 { pubkey: userKey, isSigner: true, isWritable: false }, // 2 From f06d8350a2bb4e33301d4b60d5de4362f02f0449 Mon Sep 17 00:00:00 2001 From: Alvin Philips Date: Sun, 4 Dec 2022 09:43:40 +0530 Subject: [PATCH 17/21] Removed v1 code --- src/protocols/lido.ts | 52 +++++++++++++------------------------------ 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/src/protocols/lido.ts b/src/protocols/lido.ts index 29adceb..3fd7b4a 100644 --- a/src/protocols/lido.ts +++ b/src/protocols/lido.ts @@ -84,7 +84,6 @@ export class ProtocolLido implements IProtocolVault { const heaviestValidator = vaultInfoWrapper.getHeaviestValidator(); - // Not required in case of v1 const heaviestValidatorIndex = vaultInfo.validators.entries.findIndex((value) => value.pubkey.equals(heaviestValidator.pubkey) ); @@ -92,7 +91,7 @@ export class ProtocolLido implements IProtocolVault { inputLayout.encode( { amount: new anchor.BN(params.withdrawAmount), - // Set validator index. Only used in v2 + // Set validator index. validatorIndex: heaviestValidatorIndex, }, payload @@ -119,40 +118,21 @@ export class ProtocolLido implements IProtocolVault { ); // Set up accounts - let remainingAccounts: anchor.web3.AccountMeta[]; - - if (new anchor.BN(vaultInfo.lidoVersion).toNumber() == 2) { - remainingAccounts = [ - { pubkey: lido.LIDO_ADDRESS, isSigner: false, isWritable: true }, // 1 - { pubkey: userKey, isSigner: true, isWritable: false }, // 2 - { pubkey: senderStSolAddress, isSigner: false, isWritable: true }, // 3 - { pubkey: vault.shareMint, isSigner: false, isWritable: true }, // 4 - { pubkey: heaviestValidator.pubkey, isSigner: false, isWritable: false }, // 5 - { pubkey: validatorStakeAccount, isSigner: false, isWritable: true }, // 6 - { pubkey: receivingAccount.publicKey, isSigner: true, isWritable: true }, // 7 - { pubkey: stakeAuthority, isSigner: false, isWritable: false }, // 8 - { pubkey: vaultInfo.validatorList, isSigner: false, isWritable: true }, // 9 - { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, // 10 - { pubkey: anchor.web3.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, // 11 - { pubkey: anchor.web3.SystemProgram.programId, isSigner: false, isWritable: false }, // 12 - { pubkey: anchor.web3.StakeProgram.programId, isSigner: false, isWritable: false }, // 13 - ]; - } else { - remainingAccounts = [ - { pubkey: lido.LIDO_ADDRESS, isSigner: false, isWritable: true }, // 1 - { pubkey: userKey, isSigner: true, isWritable: false }, // 2 - { pubkey: senderStSolAddress, isSigner: false, isWritable: true }, // 3 - { pubkey: vault.shareMint, isSigner: false, isWritable: true }, // 4 - { pubkey: heaviestValidator.pubkey, isSigner: false, isWritable: false }, // 5 - { pubkey: validatorStakeAccount, isSigner: false, isWritable: true }, // 6 - { pubkey: receivingAccount.publicKey, isSigner: true, isWritable: true }, // 7 - { pubkey: stakeAuthority, isSigner: false, isWritable: false }, // 8 - { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, // 9 - { pubkey: anchor.web3.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, // 10 - { pubkey: anchor.web3.SystemProgram.programId, isSigner: false, isWritable: false }, // 11 - { pubkey: anchor.web3.StakeProgram.programId, isSigner: false, isWritable: false }, // 12 - ]; - } + const remainingAccounts = [ + { pubkey: lido.LIDO_ADDRESS, isSigner: false, isWritable: true }, // 1 + { pubkey: userKey, isSigner: true, isWritable: false }, // 2 + { pubkey: senderStSolAddress, isSigner: false, isWritable: true }, // 3 + { pubkey: vault.shareMint, isSigner: false, isWritable: true }, // 4 + { pubkey: heaviestValidator.pubkey, isSigner: false, isWritable: false }, // 5 + { pubkey: validatorStakeAccount, isSigner: false, isWritable: true }, // 6 + { pubkey: receivingAccount.publicKey, isSigner: true, isWritable: true }, // 7 + { pubkey: stakeAuthority, isSigner: false, isWritable: false }, // 8 + { pubkey: vaultInfo.validatorList, isSigner: false, isWritable: true }, // 9 + { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, // 10 + { pubkey: anchor.web3.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, // 11 + { pubkey: anchor.web3.SystemProgram.programId, isSigner: false, isWritable: false }, // 12 + { pubkey: anchor.web3.StakeProgram.programId, isSigner: false, isWritable: false }, // 13 + ]; // Handle transaction here const txWithdraw = await this._gatewayProgram.methods From 7eb7dfd15ba36d66bdee633db2ea7628a8767015 Mon Sep 17 00:00:00 2001 From: Alvin Philips Date: Wed, 7 Dec 2022 16:47:37 +0530 Subject: [PATCH 18/21] Temporary work-around to access validator index for Lido --- src/builder.ts | 2 ++ src/types.ts | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/src/builder.ts b/src/builder.ts index cfbb80b..20a57f5 100644 --- a/src/builder.ts +++ b/src/builder.ts @@ -111,6 +111,7 @@ export class GatewayBuilder { // Extra Metadata poolDirection: PoolDirection.Obverse, swapMinOutAmount: new anchor.BN(0), + validatorIndex: 0, }; this._metadata = { @@ -1317,6 +1318,7 @@ export class GatewayBuilder { this._provider.connection, withdrawParams.vaultId ); + this.params.validatorIndex = withdrawParams.validatorIndex; protocol = new ProtocolLido( this._provider.connection, diff --git a/src/types.ts b/src/types.ts index 1ff6bad..1393686 100644 --- a/src/types.ts +++ b/src/types.ts @@ -355,6 +355,7 @@ export interface WithdrawParams { vaultId: anchor.web3.PublicKey; withdrawAmount: number; version?: number; + validatorIndex?: number; } export interface LockNFTParams { @@ -459,6 +460,10 @@ export type GatewayParams = TypeDef< { name: "poolDirection"; type: "u8"; + }, + { + name: "validatorIndex"; + type: "u32"; } ]; }; From 5f737321ae75b2563df5878df670505c516e12f0 Mon Sep 17 00:00:00 2001 From: Alvin Philips Date: Mon, 12 Dec 2022 14:59:41 +0530 Subject: [PATCH 19/21] Bumped up navigator to 0.2.20 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9cfc81e..5c3a750 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ ], "dependencies": { "@dappio-wonderland/gateway-idls": "^0.2.6", - "@dappio-wonderland/navigator": "^0.2.14", + "@dappio-wonderland/navigator": "^0.2.20", "@jup-ag/core": "1.0.0-beta.26", "@project-serum/anchor": "^0.24.2", "@project-serum/borsh": "^0.2.5", From 5f82a787896b047927e69857f0a69d47f1d67371 Mon Sep 17 00:00:00 2001 From: Alvin Philips Date: Mon, 12 Dec 2022 15:07:03 +0530 Subject: [PATCH 20/21] Added temporary work around in gateway state --- src/builder.ts | 6 ++++-- src/protocols/lido.ts | 8 ++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/builder.ts b/src/builder.ts index 20a57f5..424fba3 100644 --- a/src/builder.ts +++ b/src/builder.ts @@ -1314,11 +1314,13 @@ export class GatewayBuilder { break; case SupportedProtocols.Lido: - this._metadata.vault = await lido.infos.getVault( + // NOTE: This is a temporary work-around, and will be removed once multiple indexes are supported in `gateway-programs` + const vault = await lido.infos.getVault( this._provider.connection, withdrawParams.vaultId ); - this.params.validatorIndex = withdrawParams.validatorIndex; + this._metadata.vault = vault; + this.params.validatorIndex = (new lido.VaultInfoWrapper(vault as lido.VaultInfo)).getHeaviestValidatorIndex(); protocol = new ProtocolLido( this._provider.connection, diff --git a/src/protocols/lido.ts b/src/protocols/lido.ts index 3fd7b4a..972c9c8 100644 --- a/src/protocols/lido.ts +++ b/src/protocols/lido.ts @@ -33,7 +33,6 @@ export class ProtocolLido implements IProtocolVault { let preInstructions = [] as anchor.web3.TransactionInstruction[]; - // Maybe better to do in navigator? const bufferArray = [lido.LIDO_ADDRESS.toBuffer(), Buffer.from("reserve_account")]; const [reserveAccount] = anchor.web3.PublicKey.findProgramAddressSync(bufferArray, lido.LIDO_PROGRAM_ID); const bufferArrayMint = [lido.LIDO_ADDRESS.toBuffer(), Buffer.from("mint_authority")]; @@ -41,7 +40,6 @@ export class ProtocolLido implements IProtocolVault { const recipientStSolAddress = await getAssociatedTokenAddress(vault.shareMint, userKey); - // TVerify if this requires a check here preInstructions.push(await createATAWithoutCheckIx(userKey, vault.shareMint)); const remainingAccounts = [ @@ -82,11 +80,9 @@ export class ProtocolLido implements IProtocolVault { const vaultInfo = vault as lido.VaultInfo; const vaultInfoWrapper = new lido.VaultInfoWrapper(vaultInfo); - const heaviestValidator = vaultInfoWrapper.getHeaviestValidator(); + const heaviestValidatorIndex = vaultInfoWrapper.getHeaviestValidatorIndex(); - const heaviestValidatorIndex = vaultInfo.validators.entries.findIndex((value) => - value.pubkey.equals(heaviestValidator.pubkey) - ); + const heaviestValidator = vaultInfo.validators!.entries[heaviestValidatorIndex]; inputLayout.encode( { From 94e814673640782dd27915fc94e0dbcb49acee4d Mon Sep 17 00:00:00 2001 From: Alvin Philips Date: Mon, 12 Dec 2022 15:08:13 +0530 Subject: [PATCH 21/21] Remove validatorIndex from WithdrawParams --- src/types.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index 1393686..d2a0c3b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -355,7 +355,6 @@ export interface WithdrawParams { vaultId: anchor.web3.PublicKey; withdrawAmount: number; version?: number; - validatorIndex?: number; } export interface LockNFTParams {