-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
944 additions
and
297 deletions.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
import { Token } from '../src/entities/token'; | ||
import seedTokens from './data/seedTokens'; | ||
import { NETWORK_IDS } from '../src/provider'; | ||
import { ChainType } from '../src/types/network'; | ||
import { SOLANA_SYSTEM_PROGRAM } from '../src/utils/networks'; | ||
import { ENVIRONMENTS } from '../src/utils/utils'; | ||
|
||
export class addSolanaSplTokens1704487070444 implements MigrationInterface { | ||
async up(queryRunner: QueryRunner): Promise<void> { | ||
let tokensData; | ||
if (process.env.ENVIRONMENT === ENVIRONMENTS.PRODUCTION) { | ||
tokensData = seedTokens.filter( | ||
token => | ||
token.networkId === NETWORK_IDS.SOLANA_MAINNET && | ||
token.address !== SOLANA_SYSTEM_PROGRAM, | ||
); | ||
} else { | ||
tokensData = seedTokens.filter( | ||
token => | ||
token.networkId === NETWORK_IDS.SOLANA_DEVNET && | ||
token.address !== SOLANA_SYSTEM_PROGRAM, | ||
); | ||
} | ||
await queryRunner.manager.save(Token, tokensData); | ||
const tokens = await queryRunner.query( | ||
`SELECT * FROM token WHERE "chainType" = $1 AND "address" != $2`, | ||
[ChainType.SOLANA, SOLANA_SYSTEM_PROGRAM], | ||
); | ||
const givethOrganization = ( | ||
await queryRunner.query(`SELECT * FROM organization | ||
WHERE label='giveth'`) | ||
)[0]; | ||
const traceOrganization = ( | ||
await queryRunner.query(`SELECT * FROM organization | ||
WHERE label='trace'`) | ||
)[0]; | ||
|
||
for (const token of tokens) { | ||
await queryRunner.query( | ||
`INSERT INTO organization_tokens_token ("tokenId", "organizationId") VALUES ($1, $2), ($1, $3)`, | ||
[token.id, givethOrganization.id, traceOrganization.id], | ||
); | ||
} | ||
} | ||
|
||
async down(queryRunner: QueryRunner): Promise<void> { | ||
const tokens = await queryRunner.query( | ||
`SELECT * FROM token WHERE "chainType" = $1 AND "address" != $2`, | ||
[ChainType.SOLANA, SOLANA_SYSTEM_PROGRAM], | ||
); | ||
await queryRunner.query( | ||
`DELETE FROM organization_tokens_token WHERE "tokenId" IN (${tokens | ||
.map(token => token.id) | ||
.join(',')})`, | ||
); | ||
await queryRunner.query( | ||
`DELETE FROM token WHERE "chainType" = $1 AND "address" != $2`, | ||
[ChainType.SOLANA, SOLANA_SYSTEM_PROGRAM], | ||
); | ||
} | ||
} |
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
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
Oops, something went wrong.