-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/erc20 total holder merge dev (#921)
* feat: erc20 total holder * feat: erc20 total holder * feat: update hasura metadata --------- Co-authored-by: phamphong9981 <[email protected]>
- Loading branch information
1 parent
20e4df6
commit 5fbad45
Showing
5 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -49,6 +49,7 @@ select_permissions: | |
- decimal | ||
- name | ||
- track | ||
- total_holder | ||
- last_updated_height | ||
filter: {} | ||
limit: 100 |
29 changes: 29 additions & 0 deletions
29
migrations/evm/20240920024049_erc20_contract_add_total_holder.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,29 @@ | ||
import { Knex } from 'knex'; | ||
import { AccountBalance } from '../../src/models'; | ||
|
||
export async function up(knex: Knex): Promise<void> { | ||
await knex.schema.alterTable('erc20_contract', (table) => { | ||
table.integer('total_holder').defaultTo(0).index(); | ||
}); | ||
await knex.raw(`set statement_timeout to 0`); | ||
const totalHolders = await AccountBalance.query(knex) | ||
.select('account_balance.denom') | ||
.where('account_balance.type', AccountBalance.TYPE.ERC20_TOKEN) | ||
.andWhere('account_balance.amount', '>', 0) | ||
.count() | ||
.groupBy('account_balance.denom'); | ||
if (totalHolders.length > 0) { | ||
const stringListUpdates = totalHolders | ||
.map((totalHolder) => `('${totalHolder.denom}', ${totalHolder.count})`) | ||
.join(','); | ||
await knex.raw( | ||
`UPDATE erc20_contract SET total_holder = temp.total_holder from (VALUES ${stringListUpdates}) as temp(address, total_holder) where temp.address = erc20_contract.address` | ||
); | ||
} | ||
} | ||
|
||
export async function down(knex: Knex): Promise<void> { | ||
await knex.schema.alterTable('erc20_contract', (table) => { | ||
table.dropColumn('total_holder'); | ||
}); | ||
} |
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
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
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