"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OptimismLemmaFinanceXSynthTokenFetcher = void 0;
const common_1 = require("@nestjs/common");
const app_toolkit_interface_1 = require("../../../app-toolkit/app-toolkit.interface");
const position_template_decorator_1 = require("../../../app-toolkit/decorators/position-template.decorator");
const app_token_template_position_fetcher_1 = require("../../../position/template/app-token.template.position-fetcher");
const contracts_1 = require("../contracts");
const xSynthDefinitions = [
    {
        address: '0x89c4e9a23db43641e1b3c5e0691b100e64b50e32',
        perpAddress: '0x29b159ae784accfa7fb9c7ba1de272bad75f5674',
    },
    {
        address: '0x7d39583e262cbe75a1d698a6d79cd5a2958cb61d',
        perpAddress: '0xe161c6c9f2fc74ac97300e6f00648284d83cbd19',
    },
    {
        address: '0x823c55654d6e860f40070ee5625ff8b091df4269',
        perpAddress: '0xdd4d71d3563c24e38525661896e1d01fd8c2c9a5',
    },
    {
        address: '0x754e6134872d7a501ffeba6c186e187dbfdf6f4a',
        perpAddress: '0x119f85ecfcfbc1d7033d266192626202df7dbdf2',
    },
    {
        address: '0x3c7e63ba04ff4d5f0673bc93bbd9e73e9dd37ed2',
        perpAddress: '0x13c214b430fe304c4c6437f3564a690cd4e4f23b',
    },
    {
        address: '0x90356c24c1f95cf29543d45122f2554b6a74f201',
        perpAddress: '0xfe1eb36d31ead771fd5e051ee8cc424db6416567',
    },
];
let OptimismLemmaFinanceXSynthTokenFetcher = class OptimismLemmaFinanceXSynthTokenFetcher extends app_token_template_position_fetcher_1.AppTokenTemplatePositionFetcher {
    constructor(appToolkit, contractFactory) {
        super(appToolkit);
        this.appToolkit = appToolkit;
        this.contractFactory = contractFactory;
        this.groupLabel = 'xSynths';
    }
    getContract(address) {
        return this.contractFactory.lemmaXSynth({ address, network: this.network });
    }
    getDefinitions() {
        return __awaiter(this, void 0, void 0, function* () {
            return xSynthDefinitions;
        });
    }
    getAddresses({ definitions }) {
        return __awaiter(this, void 0, void 0, function* () {
            return definitions.map(v => v.address);
        });
    }
    getUnderlyingTokenDefinitions({ definition, multicall, }) {
        return __awaiter(this, void 0, void 0, function* () {
            const perpContract = this.contractFactory.lemmaPerp({
                address: definition.perpAddress,
                network: this.network,
            });
            const [collateralTokenAddress, usdcAddress] = yield Promise.all([
                multicall.wrap(perpContract).usdlCollateral(),
                multicall.wrap(perpContract).usdc(),
            ]);
            return [
                { address: usdcAddress, network: this.network },
                { address: collateralTokenAddress, network: this.network },
            ];
        });
    }
    getPricePerShare({ contract, appToken, }) {
        return __awaiter(this, void 0, void 0, function* () {
            const pricePerShareRaw = yield contract.assetsPerShare();
            const pricePerShare = Number(pricePerShareRaw) / Math.pow(10, appToken.decimals);
            return [pricePerShare, 0];
        });
    }
};
OptimismLemmaFinanceXSynthTokenFetcher = __decorate([
    (0, position_template_decorator_1.PositionTemplate)(),
    __param(0, (0, common_1.Inject)(app_toolkit_interface_1.APP_TOOLKIT)),
    __param(1, (0, common_1.Inject)(contracts_1.LemmaFinanceContractFactory)),
    __metadata("design:paramtypes", [Object, contracts_1.LemmaFinanceContractFactory])
], OptimismLemmaFinanceXSynthTokenFetcher);
exports.OptimismLemmaFinanceXSynthTokenFetcher = OptimismLemmaFinanceXSynthTokenFetcher;
//# sourceMappingURL=lemma-finance.x-synth.token-fetcher.js.map