diff --git a/src/marinade/ids.ts b/src/marinade/ids.ts index 6d6ae0f6..dd4f55a6 100644 --- a/src/marinade/ids.ts +++ b/src/marinade/ids.ts @@ -5,3 +5,13 @@ export const MARINADE_FINANCE_PROGRAM_ID = new PublicKey("MarBmsSgKXdrN1egZf5sqe export const MSOL_MINT_ADDRESS = new PublicKey("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"); export const MARINADE_STATE_ADDRESS = new PublicKey("8szGkuLTAux9XMgZ2vtY39jVSowEcpBfFfD8hXSEqdGC"); + +export const MARINADE_SOL_LEG_ADDRESS = new PublicKey("UefNb6z6yvArqe4cJHTXCqStRsKmWhGxnZzuHbikP5Q"); + +export const MARINADE_MSOL_LEG_ADDRESS = new PublicKey("7GgPYjS5Dza89wV6FpZ23kUJRG5vbQ1GM25ezspYFSoE"); + +export const MARINADE_MSOL_LEG_AUTHORITY_ADDRESS = new PublicKey("EyaSjUtSgo9aRD1f8LWXwdvkpDTmXAW54yoSHZRF14WL"); + +export const MARINADE_RESERVE_ADDRESS = new PublicKey("Du3Ysj1wKbxPKkuPPnvzQLQh8oMSVifs3jGZjJWXFmHN"); + +export const MARINADE_MSOL_MINT_AUTHORITY = new PublicKey("3JLPCS1qM2zRw3Dp6V4hZnYHd4toMNPkNesXdX9tg6KM"); diff --git a/src/marinade/index.ts b/src/marinade/index.ts index 16311269..5bbab373 100644 --- a/src/marinade/index.ts +++ b/src/marinade/index.ts @@ -3,7 +3,7 @@ export * from "./infos"; export * from "./layouts"; import BN from "bn.js"; -import { IDepositorInfo, IVaultInfo } from "../types"; +import { IDepositorInfo, IVaultInfo, IWithdrawerInfo } from "../types"; import { PublicKey } from "@solana/web3.js"; import { RawAccount } from "@solana/spl-token-v2"; @@ -90,3 +90,8 @@ export interface VaultInfo extends IVaultInfo { export interface DepositorInfo extends IDepositorInfo { tokenAccount: RawAccount; } + +export interface WithdrawerInfo extends IWithdrawerInfo { + lamports: BN; + epochCreated: BN; +} diff --git a/src/marinade/infos.ts b/src/marinade/infos.ts index a834b2a4..630658eb 100644 --- a/src/marinade/infos.ts +++ b/src/marinade/infos.ts @@ -1,9 +1,9 @@ -import { Connection, PublicKey } from "@solana/web3.js"; +import { Connection, PublicKey, GetProgramAccountsConfig, DataSizeFilter } from "@solana/web3.js"; import { MARINADE_FINANCE_PROGRAM_ID, MARINADE_STATE_ADDRESS, MSOL_MINT_ADDRESS } from "./ids"; import { IInstanceVault, IVaultInfoWrapper } from "../types"; -import { MARINADE_FINANCE_ACCOUNT_STATE } from "./layouts"; +import { MARINADE_FINANCE_ACCOUNT_STATE, MARINADE_FINANCE_ACCOUNT_TICKET_ACCOUNT_DATA } from "./layouts"; import * as types from "."; import { AccountLayout, ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from "@solana/spl-token-v2"; @@ -135,7 +135,28 @@ infos = class InstanceMarinade { tokenAccount: rawAccount, }; } + static parseWithdrawer(data: Buffer, withdrawalId: PublicKey): types.WithdrawerInfo { + let rawData = MARINADE_FINANCE_ACCOUNT_TICKET_ACCOUNT_DATA.decode(data); + return { + withdrawerId: withdrawalId, + lamports: rawData.lamportsAmount, + epochCreated: rawData.createdEpoch, + userKey: rawData.beneficiary, + }; + } + static async getAllWithdrawers(connection: Connection, userKey: PublicKey): Promise { + let filter: GetProgramAccountsConfig = { + filters: [ + { dataSize: MARINADE_FINANCE_ACCOUNT_TICKET_ACCOUNT_DATA.span as number }, + { memcmp: { offset: 40, bytes: userKey.toBase58() } }, + ], + }; + let withdrawerAccounts = await connection.getProgramAccounts(MARINADE_FINANCE_PROGRAM_ID, filter); + return withdrawerAccounts.map((account) => { + return this.parseWithdrawer(account.account.data, account.pubkey); + }); + } private static _isAllowed(mint: PublicKey): boolean { return mint.equals(MSOL_MINT_ADDRESS); } diff --git a/src/marinade/layouts.ts b/src/marinade/layouts.ts index 35ebd253..621559e0 100644 --- a/src/marinade/layouts.ts +++ b/src/marinade/layouts.ts @@ -68,6 +68,12 @@ export const MARINADE_FINANCE_ACCOUNT_STATE = struct( ); export const MARINADE_FINANCE_ACCOUNT_TICKET_ACCOUNT_DATA = struct( - [publicKey("stateAddress"), publicKey("beneficiary"), u64("lamportsAmount"), u64("createdEpoch")], + [ + blob(8, "identifier"), + publicKey("stateAddress"), + publicKey("beneficiary"), + u64("lamportsAmount"), + u64("createdEpoch"), + ], "TicketAccountData" );