Skip to content

Commit

Permalink
feat: adds getReferralPartners and code arg
Browse files Browse the repository at this point in the history
  • Loading branch information
phola committed Oct 12, 2022
1 parent 262c5ea commit 6ad8b61
Show file tree
Hide file tree
Showing 3 changed files with 312 additions and 110 deletions.
31 changes: 20 additions & 11 deletions src/marinade-referral-state/marinade-referral-partner-state.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
import { web3 } from '@project-serum/anchor'
import { Marinade } from '../marinade'
import { MarinadeReferralStateResponse } from './marinade-referral-state.types'
import { web3 } from "@project-serum/anchor"
import { Marinade } from "../marinade"
import { MarinadeReferralStateResponse } from "./marinade-referral-state.types"

export class MarinadeReferralPartnerState {
private constructor(
public readonly state: MarinadeReferralStateResponse.ReferralState,
public readonly referralStateAddress: web3.PublicKey,
public readonly marinadeReferralProgramId: web3.PublicKey,
) { }
public readonly marinadeReferralProgramId: web3.PublicKey
) {}

static async fetch(marinade: Marinade) {
static async fetch(marinade: Marinade, referralCode?: web3.PublicKey) {
const { marinadeReferralProgram, config } = marinade

if (!config.referralCode) {
throw new Error('The Referral Code must be provided in the MarinadeConfig!')
const code = referralCode ?? config.referralCode
if (!code) {
throw new Error(
"The Referral Code must be provided in the MarinadeConfig or supplied as an arg!"
)
}
const state = await marinadeReferralProgram.program.account.referralState.fetch(config.referralCode) as MarinadeReferralStateResponse.ReferralState
const state =
(await marinadeReferralProgram.program.account.referralState.fetch(
code
)) as MarinadeReferralStateResponse.ReferralState

return new MarinadeReferralPartnerState(state, config.referralCode, config.marinadeReferralProgramId)
return new MarinadeReferralPartnerState(
state,
code,
config.marinadeReferralProgramId
)
}
}
Loading

0 comments on commit 6ad8b61

Please sign in to comment.