-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into BCF-2612-ChainReader
# Conflicts: # integration-tests/go.sum
- Loading branch information
Showing
10 changed files
with
334 additions
and
108 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
gauntlet/packages/gauntlet-solana-contracts/src/commands/contracts/ocr2/acceptPayeeship.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,104 @@ | ||
import { Result } from '@chainlink/gauntlet-core' | ||
import { logger, prompt } from '@chainlink/gauntlet-core/dist/utils' | ||
import { SolanaCommand, TransactionResponse } from '@chainlink/gauntlet-solana' | ||
import { PublicKey } from '@solana/web3.js' | ||
import { CONTRACT_LIST, getContract } from '../../../lib/contracts' | ||
|
||
type Input = { | ||
transmitter: string | ||
} | ||
|
||
type ContractInput = { | ||
transmitter: string | ||
proposedPayee: PublicKey | ||
} | ||
|
||
export default class AcceptPayeeship extends SolanaCommand { | ||
static id = 'ocr2:accept_payeeship' | ||
static category = CONTRACT_LIST.OCR_2 | ||
static examples = ['yarn gauntlet ocr2:accept_payeeship --network=<NETWORK> --transmitter=<TRANSMITTER> <CONTRACT>'] | ||
|
||
input: Input | ||
contractInput: ContractInput | ||
|
||
makeInput = (userInput: any): Input => { | ||
if (userInput) return userInput as Input | ||
|
||
if (!this.flags.transmitter) { | ||
throw Error('Please specify a valid transmitter (--transmitter))') | ||
} | ||
|
||
return { | ||
transmitter: this.flags.transmitter, | ||
} | ||
} | ||
|
||
makeContractInput = async (input: Input): Promise<ContractInput> => { | ||
const state = new PublicKey(this.args[0]) | ||
const contractState = (await this.program.account.state.fetch(state)) as any | ||
const contractOracles = contractState.oracles?.xs.slice(0, contractState.oracles.len.toNumber()) | ||
const oracle = contractOracles.find(({ transmitter }) => transmitter.toString() == input.transmitter) | ||
|
||
if (!oracle) { | ||
throw Error(`No oracle found with the transmitter id ${input.transmitter}`) | ||
} | ||
|
||
return { | ||
transmitter: input.transmitter, | ||
proposedPayee: oracle.proposedPayee, | ||
} | ||
} | ||
|
||
constructor(flags, args) { | ||
super(flags, args) | ||
} | ||
|
||
buildCommand = async (flags, args) => { | ||
const ocr2 = getContract(CONTRACT_LIST.OCR_2, '') | ||
this.program = this.loadProgram(ocr2.idl, ocr2.programId.toString()) | ||
this.input = this.makeInput(flags.input) | ||
this.contractInput = await this.makeContractInput(this.input) | ||
|
||
return this | ||
} | ||
|
||
makeRawTransaction = async (signer: PublicKey) => { | ||
const data = this.program.instruction.acceptPayeeship({ | ||
accounts: { | ||
state: new PublicKey(this.args[0]), | ||
authority: signer, | ||
transmitter: this.contractInput.transmitter, | ||
proposedPayee: this.contractInput.proposedPayee, | ||
}, | ||
}) | ||
|
||
return [data] | ||
} | ||
|
||
beforeExecute = async () => { | ||
logger.loading(`Accepting payeeship for transmitter ${this.contractInput.transmitter}...`) | ||
await prompt(`Continue?`) | ||
} | ||
|
||
execute = async () => { | ||
await this.buildCommand(this.flags, this.args) | ||
|
||
const signer = this.wallet.publicKey | ||
|
||
const rawTx = await this.makeRawTransaction(signer) | ||
await this.simulateTx(signer, rawTx) | ||
await this.beforeExecute() | ||
|
||
const txhash = await this.signAndSendRawTx(rawTx) | ||
logger.success(`Payeeship accepted on tx hash: ${txhash}`) | ||
|
||
return { | ||
responses: [ | ||
{ | ||
tx: this.wrapResponse(txhash, this.args[0]), | ||
contract: this.args[0], | ||
}, | ||
], | ||
} as Result<TransactionResponse> | ||
} | ||
} |
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
117 changes: 117 additions & 0 deletions
117
gauntlet/packages/gauntlet-solana-contracts/src/commands/contracts/ocr2/transferPayeeship.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,117 @@ | ||
import { Result } from '@chainlink/gauntlet-core' | ||
import { logger, prompt } from '@chainlink/gauntlet-core/dist/utils' | ||
import { SolanaCommand, TransactionResponse } from '@chainlink/gauntlet-solana' | ||
import { PublicKey } from '@solana/web3.js' | ||
import { CONTRACT_LIST, getContract } from '../../../lib/contracts' | ||
|
||
type Input = { | ||
transmitter: string | ||
proposedPayee: string | ||
} | ||
|
||
type ContractInput = { | ||
transmitter: string | ||
payee: PublicKey | ||
proposedPayee: PublicKey | ||
} | ||
|
||
export default class TransferPayeeship extends SolanaCommand { | ||
static id = 'ocr2:transfer_payeeship' | ||
static category = CONTRACT_LIST.OCR_2 | ||
static examples = [ | ||
'yarn gauntlet ocr2:transfer_payeeship --network=<NETWORK> --transmitter=<TRANSMITTER> --proposedPayee=<PROPOSED_PAYEE> <CONTRACT>', | ||
] | ||
|
||
input: Input | ||
contractInput: ContractInput | ||
|
||
makeInput = (userInput: any): Input => { | ||
if (userInput) return userInput as Input | ||
|
||
if (!this.flags.transmitter) { | ||
throw Error('Please specify a valid transmitter (--transmitter))') | ||
} | ||
|
||
if (!this.flags.proposedPayee) { | ||
throw Error('Please specify a valid proposed payee (--proposedPayee)') | ||
} | ||
|
||
return { | ||
transmitter: this.flags.transmitter, | ||
proposedPayee: this.flags.proposedPayee, | ||
} | ||
} | ||
|
||
makeContractInput = async (input: Input): Promise<ContractInput> => { | ||
const state = new PublicKey(this.args[0]) | ||
const contractState = (await this.program.account.state.fetch(state)) as any | ||
const contractOracles = contractState.oracles?.xs.slice(0, contractState.oracles.len.toNumber()) | ||
const oracle = contractOracles.find(({ transmitter }) => transmitter.toString() == input.transmitter) | ||
|
||
if (!oracle) { | ||
throw Error(`No oracle found with the transmitter id ${input.transmitter}`) | ||
} | ||
|
||
return { | ||
transmitter: input.transmitter, | ||
payee: new PublicKey(oracle.payee), | ||
proposedPayee: new PublicKey(input.proposedPayee), | ||
} | ||
} | ||
|
||
constructor(flags, args) { | ||
super(flags, args) | ||
} | ||
|
||
buildCommand = async (flags, args) => { | ||
const ocr2 = getContract(CONTRACT_LIST.OCR_2, '') | ||
this.program = this.loadProgram(ocr2.idl, ocr2.programId.toString()) | ||
this.input = this.makeInput(flags.input) | ||
this.contractInput = await this.makeContractInput(this.input) | ||
|
||
return this | ||
} | ||
|
||
makeRawTransaction = async (signer: PublicKey) => { | ||
const data = this.program.instruction.transferPayeeship({ | ||
accounts: { | ||
state: new PublicKey(this.args[0]), | ||
authority: signer, | ||
transmitter: this.contractInput.transmitter, | ||
payee: this.contractInput.payee, | ||
proposedPayee: this.contractInput.proposedPayee, | ||
}, | ||
}) | ||
|
||
return [data] | ||
} | ||
|
||
beforeExecute = async () => { | ||
logger.loading( | ||
`Transferring payeeship for transmitter ${this.contractInput.transmitter}: ${this.contractInput.payee} -> ${this.contractInput.proposedPayee}`, | ||
) | ||
await prompt(`Continue?`) | ||
} | ||
|
||
execute = async () => { | ||
await this.buildCommand(this.flags, this.args) | ||
|
||
const signer = this.wallet.publicKey | ||
|
||
const rawTx = await this.makeRawTransaction(signer) | ||
await this.simulateTx(signer, rawTx) | ||
await this.beforeExecute() | ||
|
||
const txhash = await this.signAndSendRawTx(rawTx) | ||
logger.success(`Payeeship transferred on tx hash: ${txhash}`) | ||
|
||
return { | ||
responses: [ | ||
{ | ||
tx: this.wrapResponse(txhash, this.args[0]), | ||
contract: this.args[0], | ||
}, | ||
], | ||
} as Result<TransactionResponse> | ||
} | ||
} |
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.