-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1039 from Giveth/feature_add_optimism_goerli_network
Feature add optimism goerli network
- Loading branch information
Showing
13 changed files
with
226 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
import { Token } from '../src/entities/token'; | ||
import seedTokens from './data/seedTokens'; | ||
import { NETWORK_IDS } from '../src/provider'; | ||
import config from '../src/config'; | ||
|
||
export class AddOptimismGoerliTokens1687383705794 | ||
implements MigrationInterface | ||
{ | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
const environment = config.get('ENVIRONMENT') as string; | ||
if (environment === 'production') { | ||
// We dont add optimism-goerli tokens in production ENV | ||
return; | ||
} | ||
|
||
await queryRunner.manager.save( | ||
Token, | ||
seedTokens | ||
.filter(token => token.networkId === NETWORK_IDS.OPTIMISM_GOERLI) | ||
.map(t => { | ||
t.address = t.address?.toLowerCase(); | ||
return t; | ||
}), | ||
); | ||
const tokens = await queryRunner.query(` | ||
SELECT * FROM token | ||
WHERE "networkId" = ${NETWORK_IDS.OPTIMISM_GOERLI} | ||
`); | ||
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 | ||
(${token.id}, ${givethOrganization.id}), | ||
(${token.id}, ${traceOrganization.id}) | ||
;`); | ||
} | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
const environment = config.get('ENVIRONMENT') as string; | ||
if (environment === 'production') { | ||
// We dont add optimism-goerli tokens in production ENV | ||
return; | ||
} | ||
|
||
const tokens = await queryRunner.query(` | ||
SELECT * FROM token | ||
WHERE "networkId" = ${NETWORK_IDS.OPTIMISM_GOERLI} | ||
`); | ||
await queryRunner.query( | ||
`DELETE FROM organization_tokens_token WHERE "tokenId" IN (${tokens | ||
.map(token => token.id) | ||
.join(',')})`, | ||
); | ||
await queryRunner.query( | ||
` | ||
DELETE from token | ||
WHERE "networkId" = ${NETWORK_IDS.OPTIMISM_GOERLI} | ||
`, | ||
); | ||
} | ||
} |
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
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