Main.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { Cell, contractAddress, ContractProvider, Sender } from "@ton/core";
  2. import { HexString } from "@pythnetwork/price-service-sdk";
  3. import { BaseWrapper } from "./BaseWrapper";
  4. import { DataSource } from "@pythnetwork/xc-admin-common";
  5. export type MainConfig = {
  6. singleUpdateFee: number;
  7. dataSources: DataSource[];
  8. guardianSetIndex: number;
  9. guardianSet: string[];
  10. chainId: number;
  11. governanceChainId: number;
  12. governanceContract: string;
  13. governanceDataSource?: DataSource;
  14. };
  15. export class Main extends BaseWrapper {
  16. static createFromConfig(config: MainConfig, code: Cell, workchain = 0) {
  17. const data = Main.mainConfigToCell(config);
  18. const init = { code, data };
  19. return new Main(contractAddress(workchain, init), init);
  20. }
  21. static mainConfigToCell(config: MainConfig): Cell {
  22. return BaseWrapper.createInitData(config);
  23. }
  24. async sendDeploy(provider: ContractProvider, via: Sender, value: bigint) {
  25. await super.sendDeploy(provider, via, value);
  26. }
  27. async getCurrentGuardianSetIndex(provider: ContractProvider) {
  28. return await super.getCurrentGuardianSetIndex(
  29. provider,
  30. "get_current_guardian_set_index"
  31. );
  32. }
  33. async sendUpdateGuardianSet(
  34. provider: ContractProvider,
  35. via: Sender,
  36. vm: Buffer
  37. ) {
  38. await super.sendUpdateGuardianSet(provider, via, vm);
  39. }
  40. async sendUpdatePriceFeeds(
  41. provider: ContractProvider,
  42. via: Sender,
  43. updateData: Buffer,
  44. updateFee: bigint
  45. ) {
  46. await super.sendUpdatePriceFeeds(provider, via, updateData, updateFee);
  47. }
  48. async getPriceUnsafe(provider: ContractProvider, priceFeedId: HexString) {
  49. return await super.getPriceUnsafe(
  50. provider,
  51. priceFeedId,
  52. "get_price_unsafe"
  53. );
  54. }
  55. async getPriceNoOlderThan(
  56. provider: ContractProvider,
  57. timePeriod: number,
  58. priceFeedId: HexString
  59. ) {
  60. return await super.getPriceNoOlderThan(
  61. provider,
  62. timePeriod,
  63. priceFeedId,
  64. "get_price_no_older_than"
  65. );
  66. }
  67. async getEmaPriceUnsafe(provider: ContractProvider, priceFeedId: HexString) {
  68. return await super.getEmaPriceUnsafe(
  69. provider,
  70. priceFeedId,
  71. "get_ema_price_unsafe"
  72. );
  73. }
  74. async getEmaPriceNoOlderThan(
  75. provider: ContractProvider,
  76. timePeriod: number,
  77. priceFeedId: HexString
  78. ) {
  79. return await super.getEmaPriceNoOlderThan(
  80. provider,
  81. timePeriod,
  82. priceFeedId,
  83. "get_ema_price_no_older_than"
  84. );
  85. }
  86. async getUpdateFee(provider: ContractProvider, vm: Buffer) {
  87. return await super.getUpdateFee(provider, vm, "get_update_fee");
  88. }
  89. async getSingleUpdateFee(provider: ContractProvider) {
  90. return await super.getSingleUpdateFee(provider, "get_single_update_fee");
  91. }
  92. async getChainId(provider: ContractProvider) {
  93. return await super.getChainId(provider, "get_chain_id");
  94. }
  95. }