-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added dao rewards distributor transformers and formulas
- Loading branch information
Showing
6 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
src/formulas/formulas/contract/distribution/daoRewardsDistributor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { ContractFormula } from '@/types' | ||
|
||
export const distribution: ContractFormula< | ||
any, | ||
{ | ||
id: string | ||
} | ||
> = { | ||
compute: async ({ | ||
contractAddress, | ||
getTransformationMatch, | ||
args: { id }, | ||
}) => { | ||
if (!id) { | ||
throw new Error('missing `id`') | ||
} | ||
|
||
const distribution = ( | ||
await getTransformationMatch(contractAddress, `distribution:${id}`) | ||
)?.value | ||
|
||
if (!distribution) { | ||
throw new Error(`distribution not found for id: ${id}`) | ||
} | ||
|
||
return distribution | ||
}, | ||
} | ||
|
||
export const distributions: ContractFormula< | ||
{ | ||
distributions: any[] | ||
}, | ||
{ | ||
limit?: string | ||
startAfter?: string | ||
} | ||
> = { | ||
compute: async ({ | ||
contractAddress, | ||
getTransformationMap, | ||
args: { limit, startAfter }, | ||
}) => { | ||
const limitNum = limit ? Math.max(0, Number(limit)) : Infinity | ||
const startAfterNum = startAfter ? Number(startAfter) : -1 | ||
|
||
const map = | ||
(await getTransformationMap<number, any>( | ||
contractAddress, | ||
'distribution' | ||
)) ?? {} | ||
const distributions = Object.entries(map) | ||
// Ascending by ID. | ||
.sort(([a], [b]) => Number(a) - Number(b)) | ||
.filter(([id]) => Number(id) > startAfterNum) | ||
.slice(0, limitNum) | ||
.map(([, distribution]) => distribution) | ||
|
||
return { | ||
distributions, | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * as daoRewardsDistributor from './daoRewardsDistributor' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/transformers/transformers/distribution/daoRewardsDistributor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { makeTransformerForMap } from '@/transformers/utils' | ||
import { Transformer } from '@/types' | ||
|
||
const CODE_IDS_KEYS: string[] = ['dao-rewards-distributor'] | ||
|
||
const distributions: Transformer = makeTransformerForMap( | ||
CODE_IDS_KEYS, | ||
'distribution', | ||
'd', | ||
{ numericKey: true } | ||
) | ||
|
||
export default [distributions] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import daoRewardsDistributor from './daoRewardsDistributor' | ||
|
||
export default [...daoRewardsDistributor] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters