Skip to content

Instantly share code, notes, and snippets.

@mgild
Created November 11, 2022 21:13
Show Gist options
  • Select an option

  • Save mgild/0aa10cddc0377b497a118c5c34a67f79 to your computer and use it in GitHub Desktop.

Select an option

Save mgild/0aa10cddc0377b497a118c5c34a67f79 to your computer and use it in GitHub Desktop.
async function tsFeedCreate(program, jobData) {
const data = Buffer.from(
OracleJob.encodeDelimited(OracleJob.fromObject(jobData)).finish()
);
const job = await sbv2.JobAccount.create(program, {
data,
authority: sbv2.programWallet(program).publicKey,
});
const queue = new sbv2.OracleQueueAccount({
program,
publicKey: new PublicKey("5JYwqvKkqp35w8Nq3ba4z1WYUeJQ1rB36V8XvaGp6zn1"),
});
const payerKeypair = sbv2.programWallet(program);
const agg = await sbv2.AggregatorAccount.create(program, {
name: Buffer.from("HubbleFeed2"),
batchSize: 3,
minRequiredOracleResults: 1,
minRequiredJobResults: 1,
minUpdateDelaySeconds: 5,
queueAccount: queue,
authority: payerKeypair.publicKey,
});
console.log(`Aggregator: ${agg.publicKey.toBase58()}`);
const crank = new sbv2.CrankAccount({
program,
publicKey: new PublicKey("BKtF8yyQsj3Ft6jb2nkfpEKzARZVdGgdEPs6mFmZNmbA"),
});
await agg.addJob(job, payerKeypair);
const publisher = await spl.getAssociatedTokenAddress(
new PublicKey("So11111111111111111111111111111111111111112"),
payerKeypair.publicKey
);
let permissionAccount = await sbv2.PermissionAccount.create(program, {
authority: (await queue.loadData()).authority,
granter: queue.publicKey,
grantee: agg.publicKey,
});
console.log(`Permission: ${permissionAccount.publicKey.toBase58()}`);
const leaseAccount = await sbv2.LeaseAccount.create(program, {
oracleQueueAccount: queue,
aggregatorAccount: agg,
funder: publisher,
funderAuthority: payerKeypair,
loadAmount: new anchor.BN(1_000_000),
});
console.log(`Lease: ${permissionAccount.publicKey.toBase58()}`);
await crank.push({ aggregatorAccount: agg });
console.log(agg.publicKey.toBase58());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment