|
| 1 | +import { DataSource } from "@pythnetwork/xc-admin-common"; |
| 2 | +import { |
| 3 | + KeyValueConfig, |
| 4 | + PriceFeed, |
| 5 | + PriceFeedContract, |
| 6 | + PrivateKey, |
| 7 | + TxResult, |
| 8 | +} from "../base"; |
| 9 | +import { Chain, StarknetChain } from "../chains"; |
| 10 | +import { Contract } from "starknet"; |
| 11 | + |
| 12 | +export class StarknetPriceFeedContract extends PriceFeedContract { |
| 13 | + static type = "StarknetPriceFeedContract"; |
| 14 | + |
| 15 | + constructor(public chain: StarknetChain, public address: string) { |
| 16 | + super(); |
| 17 | + } |
| 18 | + |
| 19 | + static fromJson( |
| 20 | + chain: Chain, |
| 21 | + parsed: { |
| 22 | + type: string; |
| 23 | + address: string; |
| 24 | + } |
| 25 | + ): StarknetPriceFeedContract { |
| 26 | + if (parsed.type !== StarknetPriceFeedContract.type) |
| 27 | + throw new Error("Invalid type"); |
| 28 | + if (!(chain instanceof StarknetChain)) |
| 29 | + throw new Error(`Wrong chain type ${chain}`); |
| 30 | + return new StarknetPriceFeedContract(chain, parsed.address); |
| 31 | + } |
| 32 | + |
| 33 | + toJson(): KeyValueConfig { |
| 34 | + return { |
| 35 | + chain: this.chain.getId(), |
| 36 | + address: this.address, |
| 37 | + type: StarknetPriceFeedContract.type, |
| 38 | + }; |
| 39 | + } |
| 40 | + |
| 41 | + // Not implemented in the Starknet contract. |
| 42 | + getValidTimePeriod(): Promise<number> { |
| 43 | + throw new Error("Unsupported"); |
| 44 | + } |
| 45 | + |
| 46 | + getChain(): StarknetChain { |
| 47 | + return this.chain; |
| 48 | + } |
| 49 | + |
| 50 | + async getContractClient(): Promise<Contract> { |
| 51 | + const provider = this.chain.getProvider(); |
| 52 | + const classData = await provider.getClassAt(this.address); |
| 53 | + return new Contract(classData.abi, this.address, provider); |
| 54 | + } |
| 55 | + |
| 56 | + async getDataSources(): Promise<DataSource[]> { |
| 57 | + const contract = await this.getContractClient(); |
| 58 | + const sources: { emitter_chain_id: bigint; emitter_address: bigint }[] = |
| 59 | + await contract.valid_data_sources(); |
| 60 | + return sources.map((source) => { |
| 61 | + return { |
| 62 | + emitterChain: Number(source.emitter_chain_id), |
| 63 | + emitterAddress: source.emitter_address.toString(16), |
| 64 | + }; |
| 65 | + }); |
| 66 | + } |
| 67 | + |
| 68 | + getBaseUpdateFee(): Promise<{ amount: string; denom?: string | undefined }> { |
| 69 | + throw new Error("Method not implemented."); |
| 70 | + } |
| 71 | + getLastExecutedGovernanceSequence(): Promise<number> { |
| 72 | + throw new Error("Method not implemented."); |
| 73 | + } |
| 74 | + getPriceFeed(feedId: string): Promise<PriceFeed | undefined> { |
| 75 | + throw new Error("Method not implemented."); |
| 76 | + } |
| 77 | + executeUpdatePriceFeed( |
| 78 | + senderPrivateKey: PrivateKey, |
| 79 | + vaas: Buffer[] |
| 80 | + ): Promise<TxResult> { |
| 81 | + throw new Error("Method not implemented."); |
| 82 | + } |
| 83 | + executeGovernanceInstruction( |
| 84 | + senderPrivateKey: PrivateKey, |
| 85 | + vaa: Buffer |
| 86 | + ): Promise<TxResult> { |
| 87 | + throw new Error("Method not implemented."); |
| 88 | + } |
| 89 | + getGovernanceDataSource(): Promise<DataSource> { |
| 90 | + throw new Error("Method not implemented."); |
| 91 | + } |
| 92 | + |
| 93 | + getId(): string { |
| 94 | + return `${this.chain.getId()}_${this.address}`; |
| 95 | + } |
| 96 | + |
| 97 | + getType(): string { |
| 98 | + return StarknetPriceFeedContract.type; |
| 99 | + } |
| 100 | +} |
0 commit comments