Skip to content

Commit

Permalink
Merge pull request #36 from bobanetwork/wsdt/kms-npm
Browse files Browse the repository at this point in the history
chore: Outsource kms package
  • Loading branch information
wsdt authored May 20, 2024
2 parents 9d4d8c9 + dfffa07 commit f2ab671
Show file tree
Hide file tree
Showing 6 changed files with 570 additions and 855 deletions.
130 changes: 130 additions & 0 deletions deploy/transfer-disburser-funds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import {BigNumber, Contract, ethers, providers, Wallet} from 'ethers'
import L1ERC20Json from '../artifacts/contracts/test-helpers/L1ERC20.sol/L1ERC20.json'
import { KMSSigner } from '@bobanetwork/aws-kms'
import { IKMSSignerConfig } from '@bobanetwork/light-bridge-chains'
import { Bcfg } from '@eth-optimism/core-utils'
import * as dotenv from 'dotenv'
import Config from 'bcfg'

dotenv.config()

const hre = require("hardhat")
const prompt = require("prompt-sync")()

const env = process.env
const config: Bcfg = new Config('teleportation')
config.load({
env: true,
argv: true,
})

const envModeIsDevelopment = env.LIGHTBRIDGE_ENV === 'dev'
const networkMode = config
.str('teleportation-network-mode', env.LIGHTBRIDGE_MODE)
?.toLowerCase()

// This private key is used to send funds to the contract and initiate the tx,
// so it should have enough BOBA balance
const awsKmsAccessKey = config.str(
'teleportation-aws-kms-access-key',
env.LIGHTBRIDGE_AWS_KMS_ACCESS_KEY
)
const awsKmsSecretKey = config.str(
'teleportation-aws-kms-secret-key',
env.LIGHTBRIDGE_AWS_KMS_SECRET_KEY
)
const awsKmsKeyId = config.str(
'teleportation-aws-kms-key-id',
env.LIGHTBRIDGE_AWS_KMS_KEY_ID
)
const awsKmsRegion = config.str(
'teleportation-aws-kms-region',
env.LIGHTBRIDGE_AWS_KMS_REGION
)
const awsKmsEndpoint = config.str(
'teleportation-aws-kms-endpoint',
env.LIGHTBRIDGE_AWS_KMS_ENDPOINT
)

if (
envModeIsDevelopment &&
(!awsKmsAccessKey ||
!awsKmsSecretKey ||
!awsKmsKeyId ||
!awsKmsEndpoint ||
!awsKmsRegion)
) {
throw new Error('Must pass LIGHTBRIDGE AWS CONFIG ENV')
}

const awsConfig: IKMSSignerConfig = {
awsKmsAccessKey,
awsKmsSecretKey,
awsKmsKeyId,
awsKmsRegion,
awsKmsEndpoint,
}

async function main() {

console.log(`'Transfer disburser funds to new disburser wallet ..`)
const provider = hre.ethers.provider
const network = hre.network
const chainId = (await provider.getNetwork()).chainId

console.log(`Network name=${network?.name}`)
console.log(`Network chain id=${chainId}`)
if (!network?.config?.accounts || !network?.config?.accounts?.length) {
console.log('No private key supplied, aborting.')
return;
}

const ADDRESSES = {
OLD_DISBURSER: '',
NEW_DISBURSER: '',
TOKEN_ADDRESS: '', // 0x0 for native
}
console.log("Network: ", chainId, network.name)
console.log("Your addresses: ", JSON.stringify(ADDRESSES))
const continuePrompt = prompt("Please confirm you have configured your addresses correctly, continue? [y/N] ")
if (continuePrompt?.toLowerCase() !== 'y') {
console.log('Aborting, since addresses not yet set.')
return;
}

const kmsSigner = new KMSSigner(
awsConfig,
false,
)

if (ADDRESSES.TOKEN_ADDRESS === ethers.constants.AddressZero) {
// TODO: gas payment not forget
} else {

const tokenContract = new Contract(ADDRESSES.TOKEN_ADDRESS, L1ERC20Json.abi).connect(provider)
const tokenBalance = await tokenContract.balanceOf(ADDRESSES.OLD_DISBURSER)

const transferFromTxUnsigned =
await tokenContract.populateTransaction.transferFrom(
ADDRESSES.OLD_DISBURSER,
ADDRESSES.NEW_DISBURSER,
tokenBalance,
)
const transferFromTx = await kmsSigner.sendTxViaKMS(
provider,
ADDRESSES.TOKEN_ADDRESS,
BigNumber.from('0'),
transferFromTxUnsigned
)
console.log("Transferred token: ", JSON.stringify(await transferFromTx.wait()))

}

console.log('Fund transfer done')
}

main().catch((error) => {
console.error(error);
process.exitCode = 1;
});

8 changes: 4 additions & 4 deletions docker-compose.test.base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
dockerfile: Dockerfile.bnb

graph-node_eth:
image: graphprotocol/graph-node
image: graphprotocol/graph-node:canary-57b2b042
depends_on:
- ipfs_eth
- postgres_eth
Expand Down Expand Up @@ -62,13 +62,13 @@ services:
POSTGRES_PASSWORD: let-me-in
POSTGRES_DB: graph-node
# FIXME: remove this env. var. which we shouldn't need. Introduced by
# <https://github.com/graphprotocol/graph-node/pull/3511>, maybe as a
# <https://github.com/graphprotocol/graph-node:canary-57b2b042/pull/3511>, maybe as a
# workaround for https://github.com/docker/for-mac/issues/6270?
PGDATA: "/var/lib/postgresql/data"
POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C"

graph-node_bnb:
image: graphprotocol/graph-node
image: graphprotocol/graph-node:canary-57b2b042
depends_on:
- ipfs_bnb
- postgres_bnb
Expand Down Expand Up @@ -103,7 +103,7 @@ services:
POSTGRES_PASSWORD: let-me-in
POSTGRES_DB: graph-node
# FIXME: remove this env. var. which we shouldn't need. Introduced by
# <https://github.com/graphprotocol/graph-node/pull/3511>, maybe as a
# <https://github.com/graphprotocol/graph-node:canary-57b2b042/pull/3511>, maybe as a
# workaround for https://github.com/docker/for-mac/issues/6270?
PGDATA: "/var/lib/postgresql/data"
POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C"
Expand Down
10 changes: 2 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,15 @@
"typescript": "^4.5.2"
},
"dependencies": {
"@aws-sdk/client-kms": "^3.363.0",
"@bobanetwork/aws-kms": "^1.0.1",
"@bobanetwork/core_contracts": "0.5.12",
"@bobanetwork/graphql-utils": "^1.1.6",
"@bobanetwork/light-bridge-chains": "^1.1.2",
"@eth-optimism/common-ts": "0.2.2",
"@ethereumjs/common": "^3.2.0",
"@ethereumjs/tx": "4.2.0",
"@ethersproject/keccak256": "^5.7.0",
"@openzeppelin/contracts": "4.3.2",
"@openzeppelin/contracts-upgradeable": "4.3.2",
"asn1.js": "^5.4.1",
"bcfg": "^0.2.1",
"bn.js": "^5.2.1",
"dotenv": "^8.6.0",
"ethereumjs-util": "^7.1.5",
"ethers": "^5.5.4",
"lodash": "^4.17.21",
"pg": "^8.4.0",
Expand All @@ -75,4 +69,4 @@
"pre-commit": "yarn build && yarn lint && yarn depcheck"
}
}
}
}
Loading

0 comments on commit f2ab671

Please sign in to comment.