Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion javascript/aptos.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"@switchboard-xyz/common": "^2.2.0",
"aptos": "^1.8.3",
"aptos": "^1.11.0",
"big.js": "^6.2.1",
"bn.js": "^5.2.1",
"chalk": "^5.0.1",
Expand Down
62 changes: 62 additions & 0 deletions javascript/aptos.js/src/sbv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1934,6 +1934,11 @@ interface CreateFeedParams extends AggregatorInitParams {
initialLoadAmount: number;
}

interface CreateJobParams extends JobInitParams {
aggregatorAddress: MaybeHexString;
seed?: MaybeHexString;
}

type CreateOracleParams = OracleInitParams;

export async function createFeedTx(
Expand Down Expand Up @@ -2047,6 +2052,63 @@ export async function createFeed(
return [aggregator, tx];
}

export async function createJobTx(
client: AptosClient,
authority: MaybeHexString,
params: CreateJobParams,
switchboardAddress: MaybeHexString
): Promise<[JobAccount, Types.TransactionPayload]> {
const seed = params.seed
? HexString.ensure(HexString.ensure(params.seed))
: new AptosAccount().address();
const resource_address = generateResourceAccountAddress(
HexString.ensure(authority),
bcsAddressToBytes(HexString.ensure(seed))
);

return [
new JobAccount(client, resource_address, switchboardAddress),
getAptosTx(
`${switchboardAddress}::create_job_action::run`,
[
// authority will own everything
HexString.ensure(params.authority).hex(),

// aggregator
HexString.ensure(params.aggregatorAddress).hex(),

// job
params.name,
params.metadata,
params.data,
params.weight || 1,

// seed
seed.hex(),
],
[]
),
];
}

// Create a feed with jobs, a lease, then optionally push the lease to the specified crank
export async function createJob(
client: AptosClient,
account: AptosAccount,
params: CreateJobParams,
switchboardAddress: MaybeHexString
): Promise<[JobAccount, string]> {
const [job, txn] = await createJobTx(
client,
account.address(),
params,
switchboardAddress
);

const tx = await simulateAndRun(client, account, txn);
return [job, tx];
}

// Create an oracle, oracle wallet, permisison, and set the heartbeat permission if user is the queue authority
export async function createOracle(
client: AptosClient,
Expand Down
39 changes: 25 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.