Social Scores

Faracle provides a variety of social scores such as Scores, Ranks, Stats, and Metrics,

These scores include the Neynar Score, User Channel Metrics, Quotient Score, Faracle Score, and future custom scores. Faracle can incorporate new social scores based on user needs, or providers can integrate their own custom scores directly into the platform.

EVM Smart contracts can access these social scores either by address of FID.

DM the dev to add more custom score providers.
Score ProviderIDEnumData structureStatus
Neynar Score1ScoreType.NeynarScore0 to 10,000 for 0.00 to 1.00Live
User Channel Metrics2ScoreType.ChannelStatsCheck UserChannelStats structLive
Quotient Score3@todoComing Soon
Faracle Score4@todoComing Soon

Social Score By Address

Get various social scores for a given address.

Example shows swap fees based on neynar score for a given address.

function getScoreByAddress(address _user, uint256 _provider) external view returns (TimestampedValue memory)
YourContract.sol
1import "./IFaracle.sol";
2import "./FaracleHelper.sol";
3
4contract SwapFees {
5  
6  IFaracle public faracle = IFaracle(0x687d65ce04abbca3dac57cda6c358e497bfd320e);
7
8  struct TimestampedValue {
9    uint32  timestampChain;   
10    uint32  timestampSource;  
11    uint192 value;            
12  }
13
14  constructor() {}
15
16  function getFeesBPS() public view returns (uint256) {
17    // Get the social score by address
18    TimestampedValue memory socialScoreData = faracle.getScoreByAddress(msg.sender, FaracleHelper.ScoreType.NeynarScore);
19    
20    // Extract the social score value and convert to uint256
21    uint256 socialScore = uint256(socialScoreData.value);
22
23    // Calculate swap fees in basis points (BPS) based on social score
24    // Assuming social score ranges from 0 to 10,000 for 0.00 to 1.00
25    uint256 maxScore = 10000;
26    uint256 maxFeeBPS = 1000; // Maximum fee of 10%
27    
28    // Higher the social score, lower the fees
29    uint256 feesBPS = maxFeeBPS * (maxScore - socialScore) / maxScore;
30
31    return feesBPS;
32    
33  }
34
35}

Social Score By FID

Get various social scores for a given Farcaster FID.

Example shows swap fees based on neynar score for a given FID.

function getScoreByFid(uint256 _fid, uint256 _provider) external view returns (TimestampedValue memory)
YourContract.sol
1import "./IFaracle.sol";
2import "./FaracleHelper.sol";
3
4contract SwapFees {
5  
6  IFaracle public faracle = IFaracle(0x687d65ce04abbca3dac57cda6c358e497bfd320e);
7
8  struct TimestampedValue {
9    uint32  timestampChain;   
10    uint32  timestampSource;  
11    uint192 value;            
12  }
13
14  constructor() {}
15
16  function getFeesBPS(uint256 _fid) public view returns (uint256) {
17    // Get the social score by address
18    TimestampedValue memory socialScoreData = faracle.getScoreByFid(_fid, FaracleHelper.ScoreType.NeynarScore);
19    
20    // Extract the social score value and convert to uint256
21    uint256 socialScore = uint256(socialScoreData.value);
22
23    // Calculate swap fees in basis points (BPS) based on social score
24    // Assuming social score ranges from 0 to 10,000 for 0.00 to 1.00
25    uint256 maxScore = 10000;
26    uint256 maxFeeBPS = 1000; // Maximum fee of 10%
27    
28    // Higher the social score, lower the fees
29    uint256 feesBPS = maxFeeBPS * (maxScore - socialScore) / maxScore;
30
31    return feesBPS;
32    
33  }
34
35}

Social Scores By Address with Multiple Providers

Get multiple social scores for a given address in a single call.

Example shows fetching both neynar score and user channel metrics for a given address.

function getScoreByAddress(address _user, uint256[] memory _providers) external view returns (TimestampedValue[] memory)
YourContract.sol
1import "./IFaracle.sol";
2import "./FaracleHelper.sol";
3
4contract ExampleWithMultiProviders {
5  
6  IFaracle public faracle = IFaracle(0x687d65ce04abbca3dac57cda6c358e497bfd320e);
7
8  struct TimestampedValue {
9    uint32  timestampChain;   
10    uint32  timestampSource;  
11    uint192 value;            
12  }
13
14  constructor() {}
15
16  function getFeesBPS() public {
17    // Get the social score by address
18    TimestampedValue[] memory socialScoreData = faracle.getScoreByAddress(msg.sender, [FaracleHelper.ScoreType.NeynarScore, FaracleHelper.ScoreType.ChannelStats]);
19    
20    UserChannelStats   memory channelStats = FaracleHelper.Uint192ToUserChannelStats(socialScoreData[1].value);
21
22
23    // Use either of the scores to determine further logic
24    if(socialScoreData[0].value >= 9000 || channelStats.channelsLead >= 3 || channelStats.channelsModerating >= 5) {
25
26      // Proceed with low fee logic
27
28    }
29  }
30}

Social Scores By FID with Multiple Providers

Get multiple social scores for a given Farcaster FID in a single call.

Example shows fetching both neynar score and user channel metrics for a given FID.

function getScoreByFid(uint256 _fid, uint256[] memory _providers) external view returns (TimestampedValue[] memory)
YourContract.sol
1import "./IFaracle.sol";
2import "./FaracleHelper.sol";
3
4contract ExampleWithMultiProviders {
5  
6  IFaracle public faracle = IFaracle(0x687d65ce04abbca3dac57cda6c358e497bfd320e);
7
8  struct TimestampedValue {
9    uint32  timestampChain;   
10    uint32  timestampSource;  
11    uint192 value;            
12  }
13
14  constructor() {}
15
16  function getFeesBPS(uint256 _fid) public {
17    // Get the social score by address
18    TimestampedValue[] memory socialScoreData = faracle.getScoreByFid(_fid, [FaracleHelper.ScoreType.NeynarScore, FaracleHelper.ScoreType.ChannelStats]);
19    
20    UserChannelStats   memory channelStats = FaracleHelper.Uint192ToUserChannelStats(socialScoreData[1].value);
21    // Use either of the scores to determine further logic
22    if(socialScoreData[0].value >= 9000 || channelStats.channelsLead >= 3 || channelStats.channelsModerating >= 5) {
23
24      // Proceed with low fee logic
25
26    }
27  }
28}

Social Scores By FID in Bulk

Get social scores for multiple Farcaster FIDs in a single call.

Example shows fetching neynar scores for multiple FIDs in a single call.

function getScoreByFidBulk(uint256[] memory _fids, uint256[] memory _providers) external view returns (TimestampedValue[][] memory)
YourContract.sol
1import "./IFaracle.sol";
2import "./FaracleHelper.sol";
3
4contract ExampleWithMultiProviders {
5  
6  IFaracle public faracle = IFaracle(0x687d65ce04abbca3dac57cda6c358e497bfd320e);
7
8  constructor() {}
9
10  function getFeesBPS(uint256 _fid1, uint256 _fid2) public {
11    // Get the social score by address
12    TimestampedValue[][] memory socialScoresData = faracle.getScoreByFidBulk([_fid1, _fid2], [FaracleHelper.ScoreType.NeynarScore, FaracleHelper.ScoreType.NeynarScore]);
13    
14    // Compare the scores of both FIDs
15    if(socialScoresData[0][0].value > socialScoresData[1][0].value) {
16
17      // FID1 has a higher score than FID2
18
19    }
20  }
21}