@antefinance/ante-sdk
Version:
Library for interacting with Ante smart contracts
71 lines (70 loc) • 2.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatStake = exports.prepareStake = exports.TOKENS_DETAILS = exports.TOKENS = void 0;
const _types_1 = require("../types");
const _types_2 = require("../types");
const viem_1 = require("viem");
exports.TOKENS = {
USDC: {
name: 'USDC',
symbol: 'USDC',
decimals: 6,
eip712Version: '2',
},
gUSDC: {
name: 'USD Coin',
symbol: 'USDC',
decimals: 6,
eip712Version: '2',
},
};
exports.TOKENS_DETAILS = {
0x1: {
'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48': exports.TOKENS.USDC,
},
0x5: {
'0x07865c6E87B9F70255377e024ace6630C1Eaa37F': exports.TOKENS.gUSDC,
},
};
const tokenStakeToString = (tokenStake) => {
if (!tokenStake)
return null;
try {
const tokenAddress = (0, viem_1.getAddress)(tokenStake.token.toLowerCase());
const tokenDetails = exports.TOKENS_DETAILS[tokenStake.chainId]?.[tokenAddress];
if (!tokenDetails) {
return null;
}
return `${(0, viem_1.formatUnits)(BigInt(tokenStake.amount), tokenDetails.decimals)} ${tokenDetails.symbol}`;
}
catch (error) {
return null;
}
};
const prepareStake = (stake) => {
const { type: stakeType } = stake;
let committerStake = null;
let counterpartyStake = null;
if ([_types_2.CommitmentStakeType.ONE_WAY_PENALTY, _types_2.CommitmentStakeType.TWO_WAY].includes(stakeType)) {
committerStake =
stake.valueType === _types_1.CommitmentStakeValueType.STRING
? stake.value[_types_2.CommitmentPartySide.COMMITTER]?.toString()
: tokenStakeToString(stake.value[_types_2.CommitmentPartySide.COMMITTER]);
}
if ([_types_2.CommitmentStakeType.ONE_WAY_REWARD, _types_2.CommitmentStakeType.TWO_WAY].includes(stakeType)) {
counterpartyStake =
stake.valueType === _types_1.CommitmentStakeValueType.STRING
? stake.value[_types_2.CommitmentPartySide.COUNTERPARTY]?.toString()
: tokenStakeToString(stake.value[_types_2.CommitmentPartySide.COUNTERPARTY]);
}
return {
[_types_2.CommitmentPartySide.COMMITTER]: committerStake ?? null,
[_types_2.CommitmentPartySide.COUNTERPARTY]: counterpartyStake ?? null,
};
};
exports.prepareStake = prepareStake;
const formatStake = (stake) => {
const { [_types_2.CommitmentPartySide.COMMITTER]: committerStake, [_types_2.CommitmentPartySide.COUNTERPARTY]: counterpartyStake, } = (0, exports.prepareStake)(stake);
return `${committerStake || 'none'} : ${counterpartyStake || 'none'}`;
};
exports.formatStake = formatStake;