@collabland/staking-contracts
Version:
Staking contracts supported by Collab.Land
97 lines • 4.26 kB
JavaScript
// Copyright Abridged, Inc. 2022. All Rights Reserved.
// Node module: @collabland/staking-contracts
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
import { __decorate } from "tslib";
import { AssetName, AssetType } from '@collabland/chain';
import { getEnvVar, getFetch, handleFetchResponse, } from '@collabland/common';
import { BindingScope, extensionFor, injectable } from '@loopback/core';
import { BigNumber } from 'ethers';
import { STAKING_ADAPTERS_EXTENSION_POINT } from '../keys.js';
import { BaseStakingContractAdapter } from '../staking.js';
const getSylvesterQuery = (renterAddress, nftAddress) => {
const nftAddressFilter = nftAddress !== undefined ? `, lending: {nftAddress: "${nftAddress}"}` : '';
return `{
rentings(where: {renterAddress: "${renterAddress}", expired: false${nftAddressFilter}}) {
rentAmount,
lending {
tokenID
}
}
}`;
};
const transformGraphResponseBody = (body) => {
return body?.data?.rentings
?.map((r) => Array(Number(r.rentAmount)).fill(BigNumber.from(r.lending.tokenID)))
.flat(1);
};
class BaseReNFTSylvesterStakingContractAdapter extends BaseStakingContractAdapter {
constructor() {
super(...arguments);
// Any ERC-721 and ERC-1155 asset is supported
this.supportedAssets = [];
}
async isAssetSupported(assetName) {
return ['erc721', 'erc1155'].some(assetStandard => assetName.toLowerCase().startsWith(`${assetStandard}:`));
}
getStakingAssetType(name) {
// Assume name is the CAIP asset name
if (name == null)
return undefined;
return new AssetType({
chainId: {
namespace: 'evm',
reference: this.chainId.toString(),
},
assetName: name,
});
}
async getStakedTokenIds(owner, assetName) {
// Assume assetName is the CAIP asset name
let nftAddress = undefined;
if (assetName != null) {
const name = new AssetName(assetName);
nftAddress = name.reference;
}
const query = getSylvesterQuery(owner, nftAddress);
if (this.queryUrl === undefined)
throw new Error(`ReNFT subgraph URL undefined for ${this.constructor.name}.`);
const fetch = getFetch();
const res = await fetch(this.queryUrl, {
body: JSON.stringify({ query: query }),
method: 'POST',
headers: { 'Content-Type': 'application/json' },
});
const body = await handleFetchResponse(res);
return transformGraphResponseBody(body);
}
}
let ReNFTEthereumSylvesterV0StakingContractAdapter = class ReNFTEthereumSylvesterV0StakingContractAdapter extends BaseReNFTSylvesterStakingContractAdapter {
constructor() {
super(...arguments);
this.chainId = 1;
this.contractAddress = '0xa8D3F65b6E2922fED1430b77aC2b557e1fa8DA4a';
this.queryUrl = getEnvVar('RENFT_ETHEREUM_SYLVESTER_V0_SUBGRAPH_URL', 'https://api.studio.thegraph.com/query/3020/sylvester/1.0.3');
}
};
ReNFTEthereumSylvesterV0StakingContractAdapter = __decorate([
injectable({
scope: BindingScope.SINGLETON,
}, extensionFor(STAKING_ADAPTERS_EXTENSION_POINT))
], ReNFTEthereumSylvesterV0StakingContractAdapter);
export { ReNFTEthereumSylvesterV0StakingContractAdapter };
let ReNFTPolygonSylvesterV1StakingContractAdapter = class ReNFTPolygonSylvesterV1StakingContractAdapter extends BaseReNFTSylvesterStakingContractAdapter {
constructor() {
super(...arguments);
this.chainId = 137;
this.contractAddress = '0x4e52b73aa28b7ff84d88ea3a90c0668f46043450';
this.queryUrl = getEnvVar('RENFT_POLYGON_SYLVESTER_V1_SUBGRAPH_URL', 'https://api.thegraph.com/subgraphs/name/re-nft/sylvester-v1-polygon-main');
}
};
ReNFTPolygonSylvesterV1StakingContractAdapter = __decorate([
injectable({
scope: BindingScope.SINGLETON,
}, extensionFor(STAKING_ADAPTERS_EXTENSION_POINT))
], ReNFTPolygonSylvesterV1StakingContractAdapter);
export { ReNFTPolygonSylvesterV1StakingContractAdapter };
//# sourceMappingURL=renft.adapter.js.map