-
Notifications
You must be signed in to change notification settings - Fork 361
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
1 parent
6cf3982
commit 547b383
Showing
20 changed files
with
261 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@hyperlane-xyz/cli': minor | ||
--- | ||
|
||
Add 'submit' command to CLI. |
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
/artifacts | ||
/chains | ||
/deployments | ||
/generated | ||
|
||
# Test artifacts | ||
/test-configs/**/addresses.yaml | ||
|
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
11 changes: 11 additions & 0 deletions
11
typescript/cli/examples/submit/strategy/gnosis-ica-strategy.yaml
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,11 @@ | ||
chain: avalanche | ||
submitter: | ||
type: gnosisSafe | ||
chain: avalanche | ||
safeAddress: '0x7fd32493Ca3A38cDf78A4cb74F32f6292f822aBe' | ||
transforms: | ||
- type: interchainAccount | ||
chain: ethereum | ||
config: | ||
origin: avalanche | ||
owner: '0x16F4898F47c085C41d7Cc6b1dc72B91EA617dcBb' |
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,5 @@ | ||
chain: avalanche | ||
submitter: | ||
type: gnosisSafe | ||
chain: avalanche | ||
safeAddress: '0x7fd32493Ca3A38cDf78A4cb74F32f6292f822aBe' |
4 changes: 4 additions & 0 deletions
4
typescript/cli/examples/submit/strategy/impersonated-account-strategy.yaml
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,4 @@ | ||
chain: alfajores | ||
submitter: | ||
type: impersonatedAccount | ||
userAddress: '0x16F4898F47c085C41d7Cc6b1dc72B91EA617dcBb' |
3 changes: 3 additions & 0 deletions
3
typescript/cli/examples/submit/strategy/json-rpc-strategy.yaml
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 @@ | ||
chain: alfajores | ||
submitter: | ||
type: jsonRpc |
8 changes: 8 additions & 0 deletions
8
typescript/cli/examples/submit/transactions/alfajores-transactions.json
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,8 @@ | ||
[ | ||
{ | ||
"data": "0x0e72cc06000000000000000000000000744ad987ee7c65d3b3333bfc3e6ecbf963eb872a", | ||
"to": "0x9a4a3124F2a86bB5BE46267De85D31762b7a05Fd", | ||
"from": "0x16F4898F47c085C41d7Cc6b1dc72B91EA617dcBb", | ||
"chainId": 44787 | ||
} | ||
] |
8 changes: 8 additions & 0 deletions
8
typescript/cli/examples/submit/transactions/avalanche-transactions.json
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,8 @@ | ||
[ | ||
{ | ||
"data": "0x0e72cc06000000000000000000000000744ad987ee7c65d3b3333bfc3e6ecbf963eb872a", | ||
"to": "0x9a4a3124F2a86bB5BE46267De85D31762b7a05Fd", | ||
"from": "0x16F4898F47c085C41d7Cc6b1dc72B91EA617dcBb", | ||
"chainId": 43114 | ||
} | ||
] |
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,42 @@ | ||
import { runSubmit } from '../config/submit.js'; | ||
import { CommandModuleWithWriteContext } from '../context/types.js'; | ||
import { logBlue, logGray } from '../logger.js'; | ||
|
||
import { | ||
dryRunCommandOption, | ||
outputFileCommandOption, | ||
strategyCommandOption, | ||
transactionsCommandOption, | ||
} from './options.js'; | ||
|
||
/** | ||
* Submit command | ||
*/ | ||
export const submitCommand: CommandModuleWithWriteContext<{ | ||
transactions: string; | ||
strategy: string; | ||
'dry-run': string; | ||
receipts: string; | ||
}> = { | ||
command: 'submit', | ||
describe: 'Submit transactions', | ||
builder: { | ||
transactions: transactionsCommandOption, | ||
strategy: strategyCommandOption, | ||
'dry-run': dryRunCommandOption, | ||
receipts: outputFileCommandOption('./generated/transactions/receipts.yaml'), | ||
}, | ||
handler: async ({ context, transactions, receipts }) => { | ||
logGray(`Hyperlane Submit`); | ||
logGray(`----------------`); | ||
|
||
await runSubmit({ | ||
context, | ||
transactionsFilepath: transactions, | ||
receiptsFilepath: receipts, | ||
}); | ||
|
||
logBlue(`✅ Submission complete`); | ||
process.exit(0); | ||
}, | ||
}; |
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,75 @@ | ||
import { stringify as yamlStringify } from 'yaml'; | ||
|
||
import { | ||
PopulatedTransaction, | ||
PopulatedTransactionSchema, | ||
} from '@hyperlane-xyz/sdk'; | ||
import { assert } from '@hyperlane-xyz/utils'; | ||
|
||
import { WriteCommandContext } from '../context/types.js'; | ||
import { logGray, logRed } from '../logger.js'; | ||
import { getSubmitterBuilder } from '../submit/submit.js'; | ||
import { | ||
indentYamlOrJson, | ||
readYamlOrJson, | ||
writeYamlOrJson, | ||
} from '../utils/files.js'; | ||
|
||
export async function runSubmit({ | ||
context, | ||
transactionsFilepath, | ||
receiptsFilepath, | ||
}: { | ||
context: WriteCommandContext; | ||
transactionsFilepath: string; | ||
receiptsFilepath: string; | ||
}) { | ||
const { submissionStrategy, chainMetadata, multiProvider, isDryRun } = | ||
context; | ||
|
||
assert( | ||
submissionStrategy, | ||
'Submission strategy required to submit transactions.\nPlease create a submission strategy, e.g. ./strategy.yaml.', | ||
); | ||
|
||
const chain = submissionStrategy.chain; | ||
const protocol = chainMetadata[chain].protocol; | ||
const submitterBuilder = await getSubmitterBuilder<typeof protocol>({ | ||
submitterMetadata: submissionStrategy.submitter, | ||
transformersMetadata: submissionStrategy.transforms ?? [], | ||
multiProvider, | ||
chain: submissionStrategy.chain, | ||
isDryRun, | ||
}); | ||
const transactions = getTransactions(transactionsFilepath); | ||
|
||
try { | ||
const transactionReceipts = await submitterBuilder.submit(...transactions); | ||
if (transactionReceipts) { | ||
logGray( | ||
'🧾 Transaction receipts:\n\n', | ||
indentYamlOrJson(yamlStringify(transactionReceipts, null, 2), 4), | ||
); | ||
writeYamlOrJson(receiptsFilepath, transactionReceipts, 'yaml'); | ||
} | ||
} catch (error) { | ||
logRed( | ||
`⛔️ Failed to submit ${transactions.length} transactions:`, | ||
JSON.stringify(error), | ||
); | ||
throw new Error('Failed to submit transactions.'); | ||
} | ||
} | ||
|
||
function getTransactions(transactionsFilepath: string): PopulatedTransaction[] { | ||
const transactionsFileContent = readYamlOrJson<any[] | undefined>( | ||
transactionsFilepath.trim(), | ||
); | ||
assert( | ||
transactionsFileContent, | ||
'Transactions required to submit transactions.\nPlease add a transactions file, e.g. ./transactions.json.', | ||
); | ||
return transactionsFileContent.map((tx) => | ||
PopulatedTransactionSchema.parse(tx), | ||
); | ||
} |
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.