diff --git a/javascript/aptos.js/package.json b/javascript/aptos.js/package.json index db639b4..45ce73f 100644 --- a/javascript/aptos.js/package.json +++ b/javascript/aptos.js/package.json @@ -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", diff --git a/javascript/aptos.js/src/sbv2.ts b/javascript/aptos.js/src/sbv2.ts index 10105dc..1c7ed53 100644 --- a/javascript/aptos.js/src/sbv2.ts +++ b/javascript/aptos.js/src/sbv2.ts @@ -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( @@ -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, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 28d9f0b..4066711 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,5 +1,9 @@ lockfileVersion: '6.0' +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + importers: .: @@ -20,8 +24,8 @@ importers: specifier: ^2.2.0 version: 2.2.0 aptos: - specifier: ^1.8.3 - version: 1.8.3 + specifier: ^1.11.0 + version: 1.11.0 big.js: specifier: ^6.2.1 version: 6.2.1 @@ -703,7 +707,7 @@ packages: optional: true dependencies: '@typescript-eslint/experimental-utils': 4.33.0(eslint@7.32.0)(typescript@4.7.4) - '@typescript-eslint/parser': 4.33.0(eslint@7.32.0)(typescript@4.7.4) + '@typescript-eslint/parser': 4.33.0(eslint@8.35.0)(typescript@4.7.4) '@typescript-eslint/scope-manager': 4.33.0 debug: 4.3.4(supports-color@8.1.1) eslint: 7.32.0 @@ -763,7 +767,7 @@ packages: - typescript dev: true - /@typescript-eslint/parser@4.33.0(eslint@7.32.0)(typescript@4.7.4): + /@typescript-eslint/parser@4.33.0(eslint@8.35.0)(typescript@4.7.4): resolution: {integrity: sha512-ZohdsbXadjGBSK0/r+d87X0SBmKzOq4/S5nzK6SBgJspFo9/CUDJ7hjayuze+JK7CZQLDMroqytp7pOcFKTxZA==} engines: {node: ^10.12.0 || >=12.0.0} peerDependencies: @@ -777,7 +781,7 @@ packages: '@typescript-eslint/types': 4.33.0 '@typescript-eslint/typescript-estree': 4.33.0(typescript@4.7.4) debug: 4.3.4(supports-color@8.1.1) - eslint: 7.32.0 + eslint: 8.35.0 typescript: 4.7.4 transitivePeerDependencies: - supports-color @@ -1035,6 +1039,19 @@ packages: picomatch: 2.3.1 dev: true + /aptos@1.11.0: + resolution: {integrity: sha512-hLoyocm3Mv9JQadUObgAJHI4OLJvg2UguOb5Hz7HBbZ05UrpKSCPPX4jTF5UJVlW8HS8b6QQT5dYYXLQHPosqg==} + engines: {node: '>=11.0.0'} + dependencies: + '@noble/hashes': 1.1.3 + '@scure/bip39': 1.1.0 + axios: 0.27.2 + form-data: 4.0.0 + tweetnacl: 1.0.3 + transitivePeerDependencies: + - debug + dev: false + /aptos@1.8.3: resolution: {integrity: sha512-lVnJwE+qx+YFJ2gXLvPnz67hJBkYwP0GnkBf1runkChs5FN/8Fxzmlf+q81eifCspC4Yk+03dH27exY1MIOjuA==} engines: {node: '>=11.0.0'} @@ -2399,7 +2416,7 @@ packages: typescript: '>=3' dependencies: '@typescript-eslint/eslint-plugin': 4.33.0(@typescript-eslint/parser@4.33.0)(eslint@7.32.0)(typescript@4.7.4) - '@typescript-eslint/parser': 4.33.0(eslint@7.32.0)(typescript@4.7.4) + '@typescript-eslint/parser': 4.33.0(eslint@8.35.0)(typescript@4.7.4) chalk: 4.1.2 eslint: 7.32.0 eslint-config-prettier: 7.2.0(eslint@7.32.0) @@ -2618,12 +2635,6 @@ packages: engines: {node: '>= 0.4'} dev: true - /is-core-module@2.10.0: - resolution: {integrity: sha512-Erxj2n/LDAZ7H8WNJXd9tw38GYM3dv8rk8Zcs+jJuxYTW7sozH+SS8NtrSjVL1/vpLvWi1hxy96IzjJ3EHTJJg==} - dependencies: - has: 1.0.3 - dev: true - /is-core-module@2.11.0: resolution: {integrity: sha512-RRjxlvLDkD1YJwDbroBHMb+cukurkDWNyHx7D3oNB5x9rb5ogcksMC5wHCadcXoo67gVr/+3GFySh3134zi6rw==} dependencies: @@ -3168,7 +3179,7 @@ packages: engines: {node: '>=10'} dependencies: hosted-git-info: 4.1.0 - is-core-module: 2.10.0 + is-core-module: 2.11.0 semver: 7.3.8 validate-npm-package-license: 3.0.4 dev: true @@ -3488,7 +3499,7 @@ packages: resolution: {integrity: sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw==} hasBin: true dependencies: - is-core-module: 2.10.0 + is-core-module: 2.11.0 path-parse: 1.0.7 supports-preserve-symlinks-flag: 1.0.0 dev: true