-
Couldn't load subscription status.
- Fork 0
feat: contract sdks #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gaboesquivel
wants to merge
1
commit into
main
Choose a base branch
from
accounts-sdk
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,102 @@ | ||
| import type {Action, Checksum256Type, NameType} from '@wharfkit/antelope' | ||
| import {ABI, Blob, Checksum256, Name, Struct} from '@wharfkit/antelope' | ||
| import type {ActionOptions, ContractArgs, PartialBy, Table} from '@wharfkit/contract' | ||
| import {Contract as BaseContract} from '@wharfkit/contract' | ||
| export const abiBlob = Blob.from( | ||
| 'DmVvc2lvOjphYmkvMS4yAAcHYWNjb3VudAACBG5hbWUEbmFtZQhyZWZlcnJlcgRuYW1lCWFjY291bnR2MgADB2FjY291bnQEbmFtZQhyZWZlcnJlcgRuYW1lC3JlY292ZXJ5X2lkC2NoZWNrc3VtMjU2BWxvZ2luAAEHYWNjb3VudARuYW1lEG1pZ3JhdGVfYWNjb3VudHMAAANyZWcAAgdhY2NvdW50BG5hbWUIcmVmZXJyZXIEbmFtZQVyZXNldAAAD3NldF9yZWNvdmVyeV9pZAACB2FjY291bnQEbmFtZQtyZWNvdmVyeV9pZAtjaGVja3N1bTI1NgUAAAAAgOkYjQVsb2dpbgCAM0JGZXOZkxBtaWdyYXRlX2FjY291bnRzAAAAAAAAAJi6A3JlZwAAAAAAgKywugVyZXNldAAAAEjubnSzwg9zZXRfcmVjb3ZlcnlfaWQAAgAAADhPTREyA2k2NAAAB2FjY291bnQAgNg4T00RMgNpNjQAAAlhY2NvdW50djIAAAAAAA==' | ||
| ) | ||
| export const abi = ABI.from(abiBlob) | ||
| export namespace Types { | ||
| @Struct.type('account') | ||
| export class account extends Struct { | ||
| @Struct.field(Name) | ||
| declare name: Name | ||
| @Struct.field(Name) | ||
| declare referrer: Name | ||
| } | ||
| @Struct.type('accountv2') | ||
| export class accountv2 extends Struct { | ||
| @Struct.field(Name) | ||
| declare account: Name | ||
| @Struct.field(Name) | ||
| declare referrer: Name | ||
| @Struct.field(Checksum256) | ||
| declare recovery_id: Checksum256 | ||
| } | ||
| @Struct.type('login') | ||
| export class login extends Struct { | ||
| @Struct.field(Name) | ||
| declare account: Name | ||
| } | ||
| @Struct.type('migrate_accounts') | ||
| export class migrate_accounts extends Struct {} | ||
| @Struct.type('reg') | ||
| export class reg extends Struct { | ||
| @Struct.field(Name) | ||
| declare account: Name | ||
| @Struct.field(Name) | ||
| declare referrer: Name | ||
| } | ||
| @Struct.type('reset') | ||
| export class reset extends Struct {} | ||
| @Struct.type('set_recovery_id') | ||
| export class set_recovery_id extends Struct { | ||
| @Struct.field(Name) | ||
| declare account: Name | ||
| @Struct.field(Checksum256) | ||
| declare recovery_id: Checksum256 | ||
| } | ||
| } | ||
| export const TableMap = { | ||
| accounts: Types.account, | ||
| accountsv2: Types.accountv2, | ||
| } | ||
| export interface TableTypes { | ||
| accounts: Types.account | ||
| accountsv2: Types.accountv2 | ||
| } | ||
| export type RowType<T> = T extends keyof TableTypes ? TableTypes[T] : any | ||
| export type TableNames = keyof TableTypes | ||
| export namespace ActionParams { | ||
| export namespace Type {} | ||
| export interface login { | ||
| account: NameType | ||
| } | ||
| export interface migrate_accounts {} | ||
| export interface reg { | ||
| account: NameType | ||
| referrer: NameType | ||
| } | ||
| export interface reset {} | ||
| export interface set_recovery_id { | ||
| account: NameType | ||
| recovery_id: Checksum256Type | ||
| } | ||
| } | ||
| export interface ActionNameParams { | ||
| login: ActionParams.login | ||
| migrateaccts: ActionParams.migrateaccts | ||
| reg: ActionParams.reg | ||
| reset: ActionParams.reset | ||
| setrcvrid: ActionParams.setrcvrid | ||
| } | ||
| export type ActionNames = keyof ActionNameParams | ||
| export class Contract extends BaseContract { | ||
| constructor(args: PartialBy<ContractArgs, 'abi' | 'account'>) { | ||
| super({ | ||
| client: args.client, | ||
| abi: abi, | ||
| account: args.account || Name.from('accounts.bk'), | ||
| }) | ||
| } | ||
| action<T extends ActionNames>( | ||
| name: T, | ||
| data: ActionNameParams[T], | ||
| options?: ActionOptions | ||
| ): Action { | ||
| return super.action(name, data, options) | ||
| } | ||
| table<T extends TableNames>(name: T, scope?: NameType): Table<RowType<T>> { | ||
| return super.table(name, scope, TableMap[name]) | ||
| } | ||
| } | ||
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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,270 @@ | ||
| import { program } from 'commander' | ||
| import { | ||
| registerUser, | ||
| writeOracleData, | ||
| claimOracleRewards, | ||
| createNewPair, | ||
| getOracleStats, | ||
| getAllPairs, | ||
| voteBounty, | ||
| writeHash, | ||
| deletePair | ||
| } from './sdk' | ||
|
|
||
| // Interface for common command options | ||
| interface CommandOptions { | ||
| owner?: string | ||
| privateKey?: string | ||
| permission?: string | ||
| rpc?: string | ||
| [key: string]: any | ||
| } | ||
|
|
||
| // CLI program setup | ||
| program | ||
| .name('delphioracle-cli') | ||
| .description('CLI to interact with DelphiOracle contract') | ||
| .version('1.0.0') | ||
|
|
||
| program | ||
| .command('register') | ||
| .description('Register as a new oracle') | ||
| .requiredOption('--owner <n>', 'The account that will be registered as an oracle') | ||
| .option('--private-key <key>', 'Private key for signing transactions (REQUIRED unless set as env var)') | ||
| .option('--permission <permission>', 'Permission to use for signing') | ||
| .option('--rpc <url>', 'RPC endpoint URL') | ||
| .action(async (options: CommandOptions) => { | ||
| try { | ||
| await registerUser({ | ||
| owner: options.owner!, | ||
| privateKey: options.privateKey, | ||
| permission: options.permission, | ||
| rpcEndpoint: options.rpc | ||
| }) | ||
| console.log('Successfully registered as an oracle!') | ||
| } catch (error) { | ||
| console.error('Error registering as oracle:', error instanceof Error ? error.message : error) | ||
| } | ||
| }) | ||
|
|
||
| program | ||
| .command('write') | ||
| .description('Submit oracle data points') | ||
| .requiredOption('--owner <n>', 'The oracle account submitting data') | ||
| .requiredOption('--pair <pair>', 'The trading pair to report on (e.g., eosusd)') | ||
| .requiredOption('--value <number>', 'The value to report (will be multiplied by 10000)') | ||
| .option('--private-key <key>', 'Private key for signing transactions (REQUIRED unless set as env var)') | ||
| .option('--permission <permission>', 'Permission to use for signing') | ||
| .option('--rpc <url>', 'RPC endpoint URL') | ||
| .action(async (options: CommandOptions) => { | ||
| try { | ||
| const value = Math.round(parseFloat(options.value) * 10000) | ||
| const quotes = [{ value, pair: options.pair }] | ||
|
|
||
| await writeOracleData({ | ||
| owner: options.owner!, | ||
| quotes, | ||
| privateKey: options.privateKey, | ||
| permission: options.permission, | ||
| rpcEndpoint: options.rpc | ||
| }) | ||
|
|
||
| console.log('Oracle data submitted successfully!') | ||
| } catch (error) { | ||
| console.error('Error submitting oracle data:', error instanceof Error ? error.message : error) | ||
| } | ||
| }) | ||
|
|
||
| program | ||
| .command('claim') | ||
| .description('Claim oracle rewards') | ||
| .requiredOption('--owner <n>', 'The oracle account claiming rewards') | ||
| .option('--private-key <key>', 'Private key for signing transactions (REQUIRED unless set as env var)') | ||
| .option('--permission <permission>', 'Permission to use for signing') | ||
| .option('--rpc <url>', 'RPC endpoint URL') | ||
| .action(async (options: CommandOptions) => { | ||
| try { | ||
| await claimOracleRewards({ | ||
| owner: options.owner!, | ||
| privateKey: options.privateKey, | ||
| permission: options.permission, | ||
| rpcEndpoint: options.rpc | ||
| }) | ||
|
|
||
| console.log('Rewards claimed successfully!') | ||
| } catch (error) { | ||
| console.error('Error claiming rewards:', error instanceof Error ? error.message : error) | ||
| } | ||
| }) | ||
|
|
||
| program | ||
| .command('new-pair') | ||
| .description('Propose a new trading pair') | ||
| .requiredOption('--proposer <n>', 'The account proposing the new pair') | ||
| .requiredOption('--name <n>', 'Name for the trading pair (e.g., eosusd)') | ||
| .requiredOption('--base-symbol <symbol>', 'Base token symbol (e.g., EOS)') | ||
| .requiredOption('--base-type <number>', 'Base token type') | ||
| .requiredOption('--base-contract <n>', 'Base token contract') | ||
| .requiredOption('--quote-symbol <symbol>', 'Quote token symbol (e.g., USD)') | ||
| .requiredOption('--quote-type <number>', 'Quote token type') | ||
| .requiredOption('--quote-contract <n>', 'Quote token contract') | ||
| .requiredOption('--quoted-precision <number>', 'Precision for quoted price') | ||
| .option('--private-key <key>', 'Private key for signing transactions (REQUIRED unless set as env var)') | ||
| .option('--permission <permission>', 'Permission to use for signing') | ||
| .option('--rpc <url>', 'RPC endpoint URL') | ||
| .action(async (options: CommandOptions) => { | ||
| try { | ||
| const pair = { | ||
| name: options.name, | ||
| base_symbol: options.baseSymbol, | ||
| base_type: parseInt(options.baseType), | ||
| base_contract: options.baseContract, | ||
| quote_symbol: options.quoteSymbol, | ||
| quote_type: parseInt(options.quoteType), | ||
| quote_contract: options.quoteContract, | ||
| quoted_precision: parseInt(options.quotedPrecision) | ||
| } | ||
|
|
||
| await createNewPair({ | ||
| proposer: options.proposer!, | ||
| pair, | ||
| privateKey: options.privateKey, | ||
| permission: options.permission, | ||
| rpcEndpoint: options.rpc | ||
| }) | ||
|
|
||
| console.log('New trading pair proposed successfully!') | ||
| } catch (error) { | ||
| console.error('Error proposing new trading pair:', error instanceof Error ? error.message : error) | ||
| } | ||
| }) | ||
|
|
||
| program | ||
| .command('stats') | ||
| .description('Get oracle statistics') | ||
| .requiredOption('--owner <n>', 'The oracle account to check') | ||
| .option('--rpc <url>', 'RPC endpoint URL') | ||
| .action(async (options: CommandOptions) => { | ||
| try { | ||
| const stats = await getOracleStats(options.owner!, options.rpc) | ||
|
|
||
| if (stats) { | ||
| console.log('Oracle statistics:') | ||
| console.log('-----------------') | ||
| console.log(`Owner: ${stats.owner}`) | ||
| console.log(`Data points submitted: ${stats.count}`) | ||
| console.log(`Current balance: ${stats.balance}`) | ||
| console.log(`Last claim: ${stats.last_claim}`) | ||
| } else { | ||
| console.log(`No statistics found for oracle: ${options.owner}`) | ||
| } | ||
| } catch (error) { | ||
| console.error('Error getting oracle stats:', error instanceof Error ? error.message : error) | ||
| } | ||
| }) | ||
|
|
||
| program | ||
| .command('pairs') | ||
| .description('List all active trading pairs') | ||
| .option('--rpc <url>', 'RPC endpoint URL') | ||
| .action(async (options: CommandOptions) => { | ||
| try { | ||
| const pairs = await getAllPairs(options.rpc) | ||
|
|
||
| if (pairs.length > 0) { | ||
| console.log('Active trading pairs:') | ||
| console.log('-------------------') | ||
|
|
||
| pairs.forEach(pair => { | ||
| console.log(`Name: ${pair.name}`) | ||
| console.log(`Base Symbol: ${pair.base_symbol}`) | ||
| console.log(`Quote Symbol: ${pair.quote_symbol}`) | ||
| console.log(`Quoted Precision: ${pair.quoted_precision}`) | ||
| console.log(`Owner: ${pair.proposer}`) | ||
| console.log('-------------------') | ||
| }) | ||
| } else { | ||
| console.log('No active trading pairs found') | ||
| } | ||
| } catch (error) { | ||
| console.error('Error getting active pairs:', error instanceof Error ? error.message : error) | ||
| } | ||
| }) | ||
|
|
||
| program | ||
| .command('vote-bounty') | ||
| .description('Vote for a bounty') | ||
| .requiredOption('--owner <n>', 'The account voting') | ||
| .requiredOption('--bounty <n>', 'The bounty to vote for') | ||
| .option('--private-key <key>', 'Private key for signing transactions (REQUIRED unless set as env var)') | ||
| .option('--permission <permission>', 'Permission to use for signing') | ||
| .option('--rpc <url>', 'RPC endpoint URL') | ||
| .action(async (options: CommandOptions) => { | ||
| try { | ||
| await voteBounty({ | ||
| owner: options.owner!, | ||
| bounty: options.bounty!, | ||
| privateKey: options.privateKey, | ||
| permission: options.permission, | ||
| rpcEndpoint: options.rpc | ||
| }) | ||
|
|
||
| console.log('Successfully voted for bounty!') | ||
| } catch (error) { | ||
| console.error('Error voting for bounty:', error instanceof Error ? error.message : error) | ||
| } | ||
| }) | ||
|
|
||
| program | ||
| .command('write-hash') | ||
| .description('Write hash for multi-party oracle') | ||
| .requiredOption('--owner <n>', 'The oracle account submitting hash') | ||
| .requiredOption('--hash <hash>', 'The hash to submit') | ||
| .requiredOption('--reveal <string>', 'The reveal string') | ||
| .option('--private-key <key>', 'Private key for signing transactions (REQUIRED unless set as env var)') | ||
| .option('--permission <permission>', 'Permission to use for signing') | ||
| .option('--rpc <url>', 'RPC endpoint URL') | ||
| .action(async (options: CommandOptions) => { | ||
| try { | ||
| await writeHash({ | ||
| owner: options.owner!, | ||
| hash: options.hash!, | ||
| reveal: options.reveal!, | ||
| privateKey: options.privateKey, | ||
| permission: options.permission, | ||
| rpcEndpoint: options.rpc | ||
| }) | ||
|
|
||
| console.log('Hash written successfully!') | ||
| } catch (error) { | ||
| console.error('Error writing hash:', error instanceof Error ? error.message : error) | ||
| } | ||
| }) | ||
|
|
||
| program | ||
| .command('delete-pair') | ||
| .description('Delete an existing trading pair') | ||
| .requiredOption('--owner <n>', 'The account that will delete the pair') | ||
| .requiredOption('--pair <n>', 'Name of the pair to delete') | ||
| .requiredOption('--reason <string>', 'Reason for deleting the pair') | ||
| .option('--private-key <key>', 'Private key for signing transactions (REQUIRED unless set as env var)') | ||
| .option('--permission <permission>', 'Permission to use for signing') | ||
| .option('--rpc <url>', 'RPC endpoint URL') | ||
| .action(async (options: CommandOptions) => { | ||
| try { | ||
| await deletePair({ | ||
| owner: options.owner!, | ||
| pairName: options.pair!, | ||
| reason: options.reason!, | ||
| privateKey: options.privateKey, | ||
| permission: options.permission, | ||
| rpcEndpoint: options.rpc | ||
| }) | ||
|
|
||
| console.log(`Successfully deleted pair: ${options.pair}`) | ||
| } catch (error) { | ||
| console.error('Error deleting pair:', error instanceof Error ? error.message : error) | ||
| } | ||
| }) | ||
|
|
||
| program.parse() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Type-mismatch will break compilation
ActionNameParamsreferencesActionParams.migrateacctsandActionParams.setrcvrid, but these identifiers are not declared in theActionParamsnamespace (the declared names aremigrate_accountsandset_recovery_id).This causes a TS error: “Property 'migrateaccts' does not exist on type 'typeof ActionParams'” and blocks the build.
export interface ActionNameParams { login: ActionParams.login - migrateaccts: ActionParams.migrateaccts + migrateaccts: ActionParams.migrate_accounts reg: ActionParams.reg reset: ActionParams.reset - setrcvrid: ActionParams.setrcvrid + setrcvrid: ActionParams.set_recovery_id }If the on-chain action names are
migrateaccts/setrcvrid, consider adding type aliases inActionParamsinstead, e.g.: