PrizeDistributor
A Prize Distributor. Provides access to the contracts for viewing expiration times on draws, timelock timers and checking/claiming prizes for a user. Can be instantiated with an ethers Signer or Provider. Use a Signer if you want to claim transactions for a user. If a provider is provided, only read methods are available.
Table of contents
Constructors
Properties
- address
- chainId
- contractMetadataList
- drawBufferContract
- drawBufferMetadata
- drawCalculatorContract
- drawCalculatorMetadata
- drawCalculatorTimelockContract
- drawCalculatorTimelockMetadata
- prizeDistributionsBufferContract
- prizeDistributionsBufferMetadata
- prizeDistributorContract
- prizeDistributorMetadata
- signerOrProvider
- tokenContract
- tokenMetadata
Methods
- claimPrizesAcrossMultipleDrawsByDrawResults
- claimPrizesByDraw
- claimPrizesByDrawResults
- getAndSetEthersContract
- getDraw
- getDrawBufferContract
- getDrawCalculatorContract
- [getDrawIdsFromDrawBuffer](PrizeDistributor#getdrawidsfr rawbuffer)
- getDrawIdsFromPrizeDistributionBuffer
- getDraws
- getDrawsAndPrizeDistributions
- getNewestDraw
- getNewestPrizeDistribution
- getOldestDraw
- getOldestPrizeDistribution
- getPrizeDistribution
- getPrizeDistributions
- getPrizeDistributionsBufferContract
- getTimelockDrawId
- getTokenContract
- getTokenData
- getUsersAddress
- getUsersClaimedAmount
- getUsersClaimedAmounts
- getUsersDrawResultsForDrawId
- getUsersDrawResultsForDrawIds
- getUsersNormalizedBalancesForDrawIds
- getValidDrawIds
- id
- validateIsSigner
- validateSignerNetwork
Constructors
constructor
• new PrizeDistributor(prizeDistributorMetadata
, signerOrProvider
, contractMetadataList
)
Create an instance of a PrizeDistributor by providing the metadata of the PrizeDistributor contract, an ethers Provider or Signer for the network the PrizeDistributor contract is deployed on and a list of contract metadata for the other contracts that make up the PrizeDistributor.
Parameters
Name | Type |
---|---|
prizeDistributorMetadata | Contract |
signerOrProvider | Signer | Provider |
contractMetadataList | Contract [] |
Defined in
Properties
address
• Readonly
address: string
Defined in
chainId
• Readonly
chainId: number
Defined in
contractMetadataList
• Readonly
contractMetadataList: Contract
[]
Defined in
drawBufferContract
• drawBufferContract: Contract
Defined in
drawBufferMetadata
• drawBufferMetadata: Contract
Defined in
drawCalculatorContract
• drawCalculatorContract: Contract
Defined in
drawCalculatorMetadata
• drawCalculatorMetadata: Contract
Defined in
drawCalculatorTimelockContract
• Readonly
drawCalculatorTimelockContract: Contract
Defined in
drawCalculatorTimelockMetadata
• Readonly
drawCalculatorTimelockMetadata: Contract
Defined in
prizeDistributionsBufferContract
• prizeDistributionsBufferContract: Contract
Defined in
prizeDistributionsBufferMetadata
• prizeDistributionsBufferMetadata: Contract
Defined in
prizeDistributorContract
• Readonly
prizeDistributorContract: Contract
Defined in
prizeDistributorMetadata
• Readonly
prizeDistributorMetadata: Contract
Defined in
signerOrProvider
• Readonly
signerOrProvider: Signer
| Provider
Defined in
tokenContract
• tokenContract: Contract
Defined in
tokenMetadata
• tokenMetadata: Contract
Defined in
Methods
claimPrizesAcrossMultipleDrawsByDrawResults
▸ claimPrizesAcrossMultipleDrawsByDrawResults(drawResults
, overrides?
): Promise
<TransactionResponse
>
Submits a transaction to claim a users prizes across multiple draws PrizeDistributor must be initialized with a Signer.
Parameters
Name | Type | Description |
---|---|---|
drawResults | Object | an object of the users draw results to claim keyed by draw ids |
overrides? | Overrides | optional overrides for the transaction creation |
Returns
Promise
<TransactionResponse
>
the transaction response
Defined in
claimPrizesByDraw
▸ claimPrizesByDraw(drawId
, maxPicksPerUser
, overrides?
): Promise
<TransactionResponse
>
Fetches a users prizes for the provided draw and submits a transaction to claim them to the Signer. PrizeDistributor must be initialized with a Signer.
Parameters
Name | Type | Description |
---|---|---|
drawId | number | the draw id to claim prizes for |
maxPicksPerUser | number | the maximum picks per user from the PrizeDistribution for the provided draw id |
overrides? | Overrides | optional overrides for the transaction creation |
Returns
Promise
<TransactionResponse
>
the transaction response
Defined in
claimPrizesByDrawResults
▸ claimPrizesByDrawResults(drawResults
, overrides?
): Promise
<TransactionResponse
>
Submits a transaction to claim a users prizes PrizeDistributor must be initialized with a Signer.
Parameters
Name | Type | Description |
---|---|---|
drawResults | DrawResults | the prize results for a user for a specific draw |
overrides? | Overrides | optional overrides for the transaction creation |
Returns
Promise
<TransactionResponse
>
the transaction response
Defined in
getAndSetEthersContract
▸ Private
getAndSetEthersContract(key
, contractType
, getContractAddress
): Promise
<Contract
>
Fetches a contract address, finds the relevant metadata in the ContractList and creates an ethers Contract for that contract. The ethers Contract is cached on the instance of the PrizeDistributor and is returned immediately if already stored.
Parameters
Name | Type | Description |
---|---|---|
key | string | the key for the requested contract to be stored on the PrizeDistributor |
contractType | ContractType | the contract name |
getContractAddress | () => Promise <string > | a function to fetch the contract address |
Returns
Promise
<Contract
>
an ethers Contract for the provided address and contract type
Defined in
getDraw
▸ getDraw(drawId
): Promise
<Draw
>
Fetches a Draw from the DrawBuffer.
Parameters
Name | Type | Description |
---|---|---|
drawId | number | the draw id of the Draw to fetch |
Returns
Promise
<Draw
>
the Draw
Defined in
getDrawBufferContract
▸ getDrawBufferContract(): Promise
<Contract
>
Fetches the address of the DrawBuffer and caches the ethers Contract for the DrawBuffer.
Returns
Promise
<Contract
>
an ethers Contract for the DrawBuffer related to this PrizeDistributor
Defined in
getDrawCalculatorContract
▸ getDrawCalculatorContract(): Promise
<Contract
>
Fetches the address of the DrawCalculator and caches the ethers Contract for the DrawCalculator
Returns
Promise
<Contract
>
an ethers Contract for the DrawCalculator related to this PrizeDistributor
Defined in
getDrawIdsFromDrawBuffer
▸ getDrawIdsFromDrawBuffer(): Promise
<number
[]>
Fetches the range of draw ids that are available in the DrawBuffer.
Returns
Promise
<number
[]>
a list of draw ids in the buffer
Defined in
getDrawIdsFromPrizeDistributionBuffer
▸ getDrawIdsFromPrizeDistributionBuffer(): Promise
<number
[]>
Fetches the range of draw ids for the prize distributions that are available in the PrizeDistributionBuffer.
Returns
Promise
<number
[]>
a list of draw ids in the buffer
Defined in
getDraws
▸ getDraws(drawIds
): Promise
<{ [drawId: number]: Draw
; }>
Fetches multiple Draws from the DrawBuffer.
Parameters
Name | Type | Description |
---|---|---|
drawIds | number [] | a list of draw ids to fetch |
Returns
Promise
<{ [drawId: number]: Draw
; }>
an object with Draws keyed by their draw ids
Defined in
getDrawsAndPrizeDistributions
▸ getDrawsAndPrizeDistributions(drawIds
): Promise
<{ [drawId: number]: { draw
: Draw
; prizeDistribution
: PrizeDistribution
}; }>
Fetches Draws and PrizeDistributions from their respective buffers for the provided list of draw ids.
Parameters
Name | Type | Description |
---|---|---|
drawIds | number [] | the list of draw ids to fetch Draws and PrizeDistributions for |
Returns
Promise
<{ [drawId: number]: { draw
: Draw
; prizeDistribution
: PrizeDistribution
}; }>
an object full of Draws and PrizeDistributions keyed by their draw id
Defined in
getNewestDraw
▸ getNewestDraw(): Promise
<Draw
>
Fetches the newest Draw in the DrawBuffer related to the PrizeDistributor. NOTE: Will throw an error if the buffer is empty.
Returns
Promise
<Draw
>
the newest draw in the draw buffer
Defined in
getNewestPrizeDistribution
▸ getNewestPrizeDistribution(): Promise
<{ drawId
: number
; prizeDistribution
: PrizeDistribution
}>
Fetches the newest PrizeDistribution in the PrizeDistributionBuffer related to the PrizeDistributor. NOTE: Will throw an error if the buffer is empty.
Returns
Promise
<{ drawId
: number
; prizeDistribution
: PrizeDistribution
}>
the newest prize distribution in the prize distribution buffer
Defined in
getOldestDraw
▸ getOldestDraw(): Promise
<Draw
>
Fetches the oldest Draw in the DrawBuffer related to the PrizeDistributor.
Returns
Promise
<Draw
>
the oldest draw in the draw buffer
Defined in
getOldestPrizeDistribution
▸ getOldestPrizeDistribution(): Promise
<{ drawId
: number
; prizeDistribution
: PrizeDistribution
}>
Fetches the oldest PrizeDistribution in the PrizeDistributionBuffer related to the PrizeDistributor.
Returns
Promise
<{ drawId
: number
; prizeDistribution
: PrizeDistribution
}>
the oldest prize distribution in the prize distribution buffer
Defined in
getPrizeDistribution
▸ getPrizeDistribution(drawId
): Promise
<PrizeDistribution
>
Fetches a PrizeDistribution from the PrizeDistributionBuffer.
Parameters
Name | Type | Description |
---|---|---|
drawId | number | the draw id for the PrizeDistribution to fetch |
Returns
Promise
<PrizeDistribution
>
the PrizeDistribution
Defined in
getPrizeDistributions
▸ getPrizeDistributions(drawIds
): Promise
<{ [drawId: number]: PrizeDistribution
; }>
Fetches multiple PrizeDistributions from the PrizeDistributionBuffer.
Parameters
Name | Type | Description |
---|---|---|
drawIds | number [] | a list of draw ids to fetch PrizeDistributions for |
Returns
Promise
<{ [drawId: number]: PrizeDistribution
; }>
an object with PrizeDistributions keyed by draw ids
Defined in
getPrizeDistributionsBufferContract
▸ getPrizeDistributionsBufferContract(): Promise
<Contract
>
Fetches the address of the PrizeDistributionsBuffer and caches the ethers Contract for the PrizeDistributionsBuffer.
Returns
Promise
<Contract
>
an ethers Contract for the PrizeDistributionsBuffer related to this PrizeDistributor
Defined in
getTimelockDrawId
▸ getTimelockDrawId(): Promise
<{ drawId
: number
; endTimeSeconds
: BigNumber
}>
Fetches the id and end time stamp of the draw that is currently in the DrawCalcluatorTimelock.
Returns
Promise
<{ drawId
: number
; endTimeSeconds
: BigNumber
}>
the draw id and the end time as a unix time stamp in seconds
Defined in
getTokenContract
▸ getTokenContract(): Promise
<Contract
>
Fetches the address of the Token that is distributed by this PrizeDistributor and caches the ethers Contract for the ERC20 Token.
Returns
Promise
<Contract
>
an ethers Contract for the ERC20 Token related to this PrizeDistributor
Defined in
getTokenData
▸ getTokenData(): Promise
<TokenData
>
Fetches decimals, name and symbol for the Token that will be distributed.
Returns
Promise
<TokenData
>
the decimals, name and symbol for the token
Defined in
getUsersAddress
▸ getUsersAddress(errorPrefix?
): Promise
<string
>
Returns the users address of the provided Signer. PrizeDistributor must be initialized with a Signer.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
errorPrefix | string | `'PrizeDistributors [getUsersAddress] | '` |
Returns
Promise
<string
>
the address of the user
Defined in
getUsersClaimedAmount
▸ getUsersClaimedAmount(usersAddress
, drawId
): Promise
<BigNumber
>
Fetches the amount of tokens a user claimed for a draw.
Parameters
Name | Type | Description |
---|---|---|
usersAddress | string | the address of the user to check |
drawId | number | the draw id to check |
Returns
Promise
<BigNumber
>
the amount a user claimed
Defined in
getUsersClaimedAmounts
▸ getUsersClaimedAmounts(usersAddress
, drawIds
): Promise
<{ [drawId: number]: BigNumber
; }>
Fetches the amount of tokens a user claimed for multiple draws.
Parameters
Name | Type | Description |
---|---|---|
usersAddress | string | the address of the user to check |
drawIds | number [] | a list of draw ids to check |
Returns
Promise
<{ [drawId: number]: BigNumber
; }>
an object of claimed amounts keyed by the draw ids
Defined in
getUsersDrawResultsForDrawId
▸ getUsersDrawResultsForDrawId(usersAddress
, drawId
, maxPicksPerUser
): Promise
<DrawResults
>
Fetches the claimable prizes a user won for a specific Draw.
Parameters
Name | Type | Description |
---|---|---|
usersAddress | string | the users address to fetch prizes for |
drawId | number | the draw id to fetch prizes for |
maxPicksPerUser | number | the maximum number of picks per user from the matching prize distribution |
Returns
Promise
<DrawResults
>
the results for user for the provided draw
Defined in
getUsersDrawResultsForDrawIds
▸ getUsersDrawResultsForDrawIds(usersAddress
, drawIds
, maxPicksPerUserPerDraw
): Promise
<{ [drawId: number]: DrawResults
; }>
Fetches the claimable prizes a user won for multiple Draws.
Parameters
Name | Type | Description |
---|---|---|
usersAddress | string | the users address to fetch prizes for |
drawIds | number [] | the draw ids to fetch prizes for |
maxPicksPerUserPerDraw | number [] | the maximum number of picks per user from the matching prize distribution for each draw |
Returns
Promise
<{ [drawId: number]: DrawResults
; }>
the results for user for the provided draw
Defined in
getUsersNormalizedBalancesForDrawIds
▸ getUsersNormalizedBalancesForDrawIds(usersAddress
, drawIds
): Promise
<{ [drawId: number]: BigNumber
; }>
Fetches a users normalized balance for several draw ids.
Parameters
Name | Type | Description |
---|---|---|
usersAddress | string | the address of a user to fetch normalized balances for |
drawIds | number [] | a list of draw ids to fetch normalized balances for |
Returns
Promise
<{ [drawId: number]: BigNumber
; }>
an object of normalized balances keyed by draw ids
Defined in
getValidDrawIds
▸ getValidDrawIds(): Promise
<number
[]>
Gets the list of draw ids of draws that have are available in both the DrawBuffer and PrizeDistributionBuffer.
Returns
Promise
<number
[]>
a list of draw ids in both buffers
Defined in
id
▸ id(): string
Returns a unique id string for this PrizeDistributor.
Returns
string
a unique id for the PrizeDistributor
Defined in
validateIsSigner
▸ validateIsSigner(errorPrefix
): Promise
<void
>
Validates that the data provided for providerOrSigner is a Signer.
Parameters
Name | Type | Description |
---|---|---|
errorPrefix | string | the class and function name of where the error occurred |
Returns
Promise
<void
>
Defined in
validateSignerNetwork
▸ validateSignerNetwork(errorPrefix
): Promise
<void
>
Validates that a Signer is on the network the PrizeDistributor is deployed on.
Parameters
Name | Type | Description |
---|---|---|
errorPrefix | string | the class and function name of where the error occurred |
Returns
Promise
<void
>