fixes #12
This commit is contained in:
parent
9bf4f7fba7
commit
280dfef7b3
|
@ -85,7 +85,6 @@ Next we create a new oracle to the feed we've created previously, and set its ow
|
|||
|
||||
```
|
||||
yarn solink add-oracle \
|
||||
--index 0 \
|
||||
--feedAddress 2jReuMRoYi3pKTF8YLnZEvT2bXcw56SdBxvssrVzu41v \
|
||||
--oracleName solink-test \
|
||||
--oracleOwner FosLwbttPgkEDv36VJLU3wwXcBSSoUGkh7dyZPsXNtT4
|
||||
|
@ -115,8 +114,8 @@ yarn solink feed-poll \
|
|||
|
||||
```
|
||||
yarn solink remove-oracle \
|
||||
--index 0 \
|
||||
--feedAddress 2jReuMRoYi3pKTF8YLnZEvT2bXcw56SdBxvssrVzu41v
|
||||
--feedAddress 2jReuMRoYi3pKTF8YLnZEvT2bXcw56SdBxvssrVzu41v \
|
||||
--oracleAddress 4jWLbd2Vm98RrqunVvaSXZuP1AFbgQSM2hAHMvZSdNCu
|
||||
```
|
||||
|
||||
## Test Token
|
||||
|
|
|
@ -148,6 +148,7 @@ impl Processor {
|
|||
if Pubkey::new_from_array(s.oracle) == Pubkey::default() {
|
||||
inserted = true;
|
||||
s.oracle = oracle_info.key.to_bytes();
|
||||
break;
|
||||
} else if &Pubkey::new_from_array(s.oracle) == oracle_info.key {
|
||||
return Err(Error::OracleExist.into());
|
||||
}
|
||||
|
@ -199,6 +200,7 @@ impl Processor {
|
|||
if s.oracle == pubkey {
|
||||
found = true;
|
||||
s.oracle = Pubkey::default().to_bytes();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@ export const AggregatorLayout = BufferLayout.struct([
|
|||
]);
|
||||
|
||||
export const OracleLayout = BufferLayout.struct([
|
||||
uint64("submission"),
|
||||
uint64("nextSubmitTime"),
|
||||
BufferLayout.blob(32, "description"),
|
||||
BufferLayout.u8("isInitialized"),
|
||||
|
@ -58,8 +57,6 @@ interface InitializeInstructionParams extends InitializeParams {
|
|||
}
|
||||
|
||||
interface AddOracleParams {
|
||||
// oracle index
|
||||
index: number;
|
||||
owner: PublicKey;
|
||||
description: string;
|
||||
aggregator: PublicKey;
|
||||
|
@ -72,9 +69,8 @@ interface AddOracleInstructionParams extends AddOracleParams {
|
|||
}
|
||||
|
||||
interface RemoveOracleParams {
|
||||
// oracle index
|
||||
index: number;
|
||||
aggregator: PublicKey;
|
||||
oracle: PublicKey;
|
||||
// To prove you are the aggregator owner
|
||||
authority?: Account;
|
||||
}
|
||||
|
@ -200,7 +196,6 @@ export default class FluxAggregator extends BaseProgram {
|
|||
|
||||
private addOracleInstruction(params: AddOracleInstructionParams): TransactionInstruction {
|
||||
const {
|
||||
index,
|
||||
oracle,
|
||||
owner,
|
||||
description,
|
||||
|
@ -210,13 +205,11 @@ export default class FluxAggregator extends BaseProgram {
|
|||
|
||||
const layout = BufferLayout.struct([
|
||||
BufferLayout.u8("instruction"),
|
||||
BufferLayout.u8("index"),
|
||||
BufferLayout.blob(32, "description"),
|
||||
]);
|
||||
|
||||
return this.instructionEncode(layout, {
|
||||
instruction: 1, // add oracle instruction
|
||||
index,
|
||||
description: Buffer.from(description),
|
||||
}, [
|
||||
{ write: oracle },
|
||||
|
@ -235,19 +228,19 @@ export default class FluxAggregator extends BaseProgram {
|
|||
|
||||
private removeOracleInstruction(params: RemoveOracleInstructionParams): TransactionInstruction {
|
||||
const {
|
||||
index,
|
||||
authority,
|
||||
aggregator,
|
||||
oracle,
|
||||
} = params;
|
||||
|
||||
const layout = BufferLayout.struct([
|
||||
BufferLayout.u8("instruction"),
|
||||
BufferLayout.u8("index"),
|
||||
BufferLayout.blob(32, "oracle"),
|
||||
]);
|
||||
|
||||
return this.instructionEncode(layout, {
|
||||
instruction: 2, // remove oracle instruction
|
||||
index,
|
||||
oracle: oracle.toBuffer()
|
||||
}, [
|
||||
//
|
||||
{ write: aggregator },
|
||||
|
|
30
src/cli.ts
30
src/cli.ts
|
@ -186,45 +186,37 @@ cli
|
|||
cli
|
||||
.command("add-oracle")
|
||||
.description("add an oracle to aggregator")
|
||||
.option("--index <number>", "add to index (0-20)")
|
||||
.option("--feedAddress <string>", "feed address")
|
||||
.option("--oracleName <string>", "oracle name")
|
||||
.option("--oracleOwner <string>", "oracle owner address")
|
||||
.action(async (opts) => {
|
||||
const { wallet, aggregator, deployer } = await AppContext.forAdmin()
|
||||
|
||||
const { index, oracleName, oracleOwner, feedAddress } = opts
|
||||
|
||||
if (!index || index < 0 || index > 21) {
|
||||
error("invalid index. requires (0-20)")
|
||||
}
|
||||
const { oracleName, oracleOwner, feedAddress } = opts
|
||||
|
||||
log("add oracle...")
|
||||
const oracle = await deployer.ensure(`oracle[${index}]`, async () => {
|
||||
return aggregator.addOracle({
|
||||
index,
|
||||
owner: new PublicKey(oracleOwner),
|
||||
description: oracleName.substr(0, 32).padEnd(32),
|
||||
aggregator: new PublicKey(feedAddress),
|
||||
aggregatorOwner: wallet.account,
|
||||
})
|
||||
})
|
||||
const oracle = await aggregator.addOracle({
|
||||
owner: new PublicKey(oracleOwner),
|
||||
description: oracleName.substr(0, 32).padEnd(32),
|
||||
aggregator: new PublicKey(feedAddress),
|
||||
aggregatorOwner: wallet.account,
|
||||
});
|
||||
|
||||
log(`added oracle. pubkey: ${color(oracle.publicKey.toBase58(), "blue")}`)
|
||||
})
|
||||
|
||||
cli
|
||||
.command("remove-oracle")
|
||||
.option("--index <number>", "remove oracle from index (0-20)")
|
||||
.option("--feedAddress <string>", "feed to remove oracle from")
|
||||
.option("--oracleAddress <string>", "oracle address")
|
||||
.action(async (opts) => {
|
||||
const { index, feedAddress } = opts
|
||||
const { feedAddress, oracleAddress } = opts
|
||||
|
||||
const { aggregator } = await AppContext.forAdmin()
|
||||
|
||||
|
||||
await aggregator.removeOracle({
|
||||
aggregator: new PublicKey(feedAddress),
|
||||
index,
|
||||
oracle: new PublicKey(oracleAddress),
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -78,7 +78,6 @@ export function decodeOracleInfo(accountInfo) {
|
|||
|
||||
const oracle = OracleLayout.decode(data)
|
||||
|
||||
oracle.submission = oracle.submission.readBigUInt64LE().toString()
|
||||
oracle.nextSubmitTime = oracle.nextSubmitTime.readBigUInt64LE().toString()
|
||||
oracle.description = oracle.description.toString()
|
||||
oracle.isInitialized = oracle.isInitialized != 0
|
||||
|
|
Loading…
Reference in New Issue