@kamino-finance/scope-sdk
Version:
Scope Oracle SDK
242 lines • 11.7 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GlobalConfig = void 0;
/* eslint-disable @typescript-eslint/no-unused-vars */
const kit_1 = require("@solana/kit");
/* eslint-enable @typescript-eslint/no-unused-vars */
const bn_js_1 = __importDefault(require("bn.js")); // eslint-disable-line @typescript-eslint/no-unused-vars
const borsh = __importStar(require("@coral-xyz/borsh")); // eslint-disable-line @typescript-eslint/no-unused-vars
const utils_1 = require("../utils"); // eslint-disable-line @typescript-eslint/no-unused-vars
const programId_1 = require("../programId");
class GlobalConfig {
emergencyMode;
blockDeposit;
blockInvest;
blockWithdraw;
blockCollectFees;
blockCollectRewards;
blockSwapRewards;
blockSwapUnevenVaults;
blockEmergencySwap;
minWithdrawalFeeBps;
scopeProgramId;
scopePriceId;
swapRewardsDiscountBps;
actionsAuthority;
adminAuthority;
treasuryFeeVaults;
tokenInfos;
blockLocalAdmin;
minPerformanceFeeBps;
minSwapUnevenSlippageToleranceBps;
minReferencePriceSlippageToleranceBps;
actionsAfterRebalanceDelaySeconds;
treasuryFeeVaultReceiver;
padding;
static discriminator = Buffer.from([
149, 8, 156, 202, 160, 252, 176, 217,
]);
static layout = borsh.struct([
borsh.u64("emergencyMode"),
borsh.u64("blockDeposit"),
borsh.u64("blockInvest"),
borsh.u64("blockWithdraw"),
borsh.u64("blockCollectFees"),
borsh.u64("blockCollectRewards"),
borsh.u64("blockSwapRewards"),
borsh.u32("blockSwapUnevenVaults"),
borsh.u32("blockEmergencySwap"),
borsh.u64("minWithdrawalFeeBps"),
(0, utils_1.borshAddress)("scopeProgramId"),
(0, utils_1.borshAddress)("scopePriceId"),
borsh.array(borsh.u64(), 256, "swapRewardsDiscountBps"),
(0, utils_1.borshAddress)("actionsAuthority"),
(0, utils_1.borshAddress)("adminAuthority"),
borsh.array((0, utils_1.borshAddress)(), 256, "treasuryFeeVaults"),
(0, utils_1.borshAddress)("tokenInfos"),
borsh.u64("blockLocalAdmin"),
borsh.u64("minPerformanceFeeBps"),
borsh.u64("minSwapUnevenSlippageToleranceBps"),
borsh.u64("minReferencePriceSlippageToleranceBps"),
borsh.u64("actionsAfterRebalanceDelaySeconds"),
(0, utils_1.borshAddress)("treasuryFeeVaultReceiver"),
borsh.array(borsh.u64(), 2035, "padding"),
]);
constructor(fields) {
this.emergencyMode = fields.emergencyMode;
this.blockDeposit = fields.blockDeposit;
this.blockInvest = fields.blockInvest;
this.blockWithdraw = fields.blockWithdraw;
this.blockCollectFees = fields.blockCollectFees;
this.blockCollectRewards = fields.blockCollectRewards;
this.blockSwapRewards = fields.blockSwapRewards;
this.blockSwapUnevenVaults = fields.blockSwapUnevenVaults;
this.blockEmergencySwap = fields.blockEmergencySwap;
this.minWithdrawalFeeBps = fields.minWithdrawalFeeBps;
this.scopeProgramId = fields.scopeProgramId;
this.scopePriceId = fields.scopePriceId;
this.swapRewardsDiscountBps = fields.swapRewardsDiscountBps;
this.actionsAuthority = fields.actionsAuthority;
this.adminAuthority = fields.adminAuthority;
this.treasuryFeeVaults = fields.treasuryFeeVaults;
this.tokenInfos = fields.tokenInfos;
this.blockLocalAdmin = fields.blockLocalAdmin;
this.minPerformanceFeeBps = fields.minPerformanceFeeBps;
this.minSwapUnevenSlippageToleranceBps =
fields.minSwapUnevenSlippageToleranceBps;
this.minReferencePriceSlippageToleranceBps =
fields.minReferencePriceSlippageToleranceBps;
this.actionsAfterRebalanceDelaySeconds =
fields.actionsAfterRebalanceDelaySeconds;
this.treasuryFeeVaultReceiver = fields.treasuryFeeVaultReceiver;
this.padding = fields.padding;
}
static async fetch(rpc, address, programId = programId_1.PROGRAM_ID) {
const info = await (0, kit_1.fetchEncodedAccount)(rpc, address);
if (!info.exists) {
return null;
}
if (info.programAddress !== programId) {
throw new Error("account doesn't belong to this program");
}
return this.decode(Buffer.from(info.data));
}
static async fetchMultiple(rpc, addresses, programId = programId_1.PROGRAM_ID) {
const infos = await (0, kit_1.fetchEncodedAccounts)(rpc, addresses);
return infos.map((info) => {
if (!info.exists) {
return null;
}
if (info.programAddress !== programId) {
throw new Error("account doesn't belong to this program");
}
return this.decode(Buffer.from(info.data));
});
}
static decode(data) {
if (!data.slice(0, 8).equals(GlobalConfig.discriminator)) {
throw new Error("invalid account discriminator");
}
const dec = GlobalConfig.layout.decode(data.slice(8));
return new GlobalConfig({
emergencyMode: dec.emergencyMode,
blockDeposit: dec.blockDeposit,
blockInvest: dec.blockInvest,
blockWithdraw: dec.blockWithdraw,
blockCollectFees: dec.blockCollectFees,
blockCollectRewards: dec.blockCollectRewards,
blockSwapRewards: dec.blockSwapRewards,
blockSwapUnevenVaults: dec.blockSwapUnevenVaults,
blockEmergencySwap: dec.blockEmergencySwap,
minWithdrawalFeeBps: dec.minWithdrawalFeeBps,
scopeProgramId: dec.scopeProgramId,
scopePriceId: dec.scopePriceId,
swapRewardsDiscountBps: dec.swapRewardsDiscountBps,
actionsAuthority: dec.actionsAuthority,
adminAuthority: dec.adminAuthority,
treasuryFeeVaults: dec.treasuryFeeVaults,
tokenInfos: dec.tokenInfos,
blockLocalAdmin: dec.blockLocalAdmin,
minPerformanceFeeBps: dec.minPerformanceFeeBps,
minSwapUnevenSlippageToleranceBps: dec.minSwapUnevenSlippageToleranceBps,
minReferencePriceSlippageToleranceBps: dec.minReferencePriceSlippageToleranceBps,
actionsAfterRebalanceDelaySeconds: dec.actionsAfterRebalanceDelaySeconds,
treasuryFeeVaultReceiver: dec.treasuryFeeVaultReceiver,
padding: dec.padding,
});
}
toJSON() {
return {
emergencyMode: this.emergencyMode.toString(),
blockDeposit: this.blockDeposit.toString(),
blockInvest: this.blockInvest.toString(),
blockWithdraw: this.blockWithdraw.toString(),
blockCollectFees: this.blockCollectFees.toString(),
blockCollectRewards: this.blockCollectRewards.toString(),
blockSwapRewards: this.blockSwapRewards.toString(),
blockSwapUnevenVaults: this.blockSwapUnevenVaults,
blockEmergencySwap: this.blockEmergencySwap,
minWithdrawalFeeBps: this.minWithdrawalFeeBps.toString(),
scopeProgramId: this.scopeProgramId,
scopePriceId: this.scopePriceId,
swapRewardsDiscountBps: this.swapRewardsDiscountBps.map((item) => item.toString()),
actionsAuthority: this.actionsAuthority,
adminAuthority: this.adminAuthority,
treasuryFeeVaults: this.treasuryFeeVaults,
tokenInfos: this.tokenInfos,
blockLocalAdmin: this.blockLocalAdmin.toString(),
minPerformanceFeeBps: this.minPerformanceFeeBps.toString(),
minSwapUnevenSlippageToleranceBps: this.minSwapUnevenSlippageToleranceBps.toString(),
minReferencePriceSlippageToleranceBps: this.minReferencePriceSlippageToleranceBps.toString(),
actionsAfterRebalanceDelaySeconds: this.actionsAfterRebalanceDelaySeconds.toString(),
treasuryFeeVaultReceiver: this.treasuryFeeVaultReceiver,
padding: this.padding.map((item) => item.toString()),
};
}
static fromJSON(obj) {
return new GlobalConfig({
emergencyMode: new bn_js_1.default(obj.emergencyMode),
blockDeposit: new bn_js_1.default(obj.blockDeposit),
blockInvest: new bn_js_1.default(obj.blockInvest),
blockWithdraw: new bn_js_1.default(obj.blockWithdraw),
blockCollectFees: new bn_js_1.default(obj.blockCollectFees),
blockCollectRewards: new bn_js_1.default(obj.blockCollectRewards),
blockSwapRewards: new bn_js_1.default(obj.blockSwapRewards),
blockSwapUnevenVaults: obj.blockSwapUnevenVaults,
blockEmergencySwap: obj.blockEmergencySwap,
minWithdrawalFeeBps: new bn_js_1.default(obj.minWithdrawalFeeBps),
scopeProgramId: (0, kit_1.address)(obj.scopeProgramId),
scopePriceId: (0, kit_1.address)(obj.scopePriceId),
swapRewardsDiscountBps: obj.swapRewardsDiscountBps.map((item) => new bn_js_1.default(item)),
actionsAuthority: (0, kit_1.address)(obj.actionsAuthority),
adminAuthority: (0, kit_1.address)(obj.adminAuthority),
treasuryFeeVaults: obj.treasuryFeeVaults.map((item) => (0, kit_1.address)(item)),
tokenInfos: (0, kit_1.address)(obj.tokenInfos),
blockLocalAdmin: new bn_js_1.default(obj.blockLocalAdmin),
minPerformanceFeeBps: new bn_js_1.default(obj.minPerformanceFeeBps),
minSwapUnevenSlippageToleranceBps: new bn_js_1.default(obj.minSwapUnevenSlippageToleranceBps),
minReferencePriceSlippageToleranceBps: new bn_js_1.default(obj.minReferencePriceSlippageToleranceBps),
actionsAfterRebalanceDelaySeconds: new bn_js_1.default(obj.actionsAfterRebalanceDelaySeconds),
treasuryFeeVaultReceiver: (0, kit_1.address)(obj.treasuryFeeVaultReceiver),
padding: obj.padding.map((item) => new bn_js_1.default(item)),
});
}
}
exports.GlobalConfig = GlobalConfig;
//# sourceMappingURL=GlobalConfig.js.map