Skip to content

Commit

Permalink
[thales] Update Thales strategy to include Base stakers (#1349)
Browse files Browse the repository at this point in the history
* Thales strategy

* Change Thales strategy to pull data from OP mainnet

* Update src/strategies/thales/index.ts

Co-authored-by: Chaitanya <[email protected]>

* Update subgraph link for Thales strategy

* Update src/strategies/thales/index.ts

Co-authored-by: Chaitanya <[email protected]>

* Update Thales strategy to include Arbitrum stakers

* Update Thales strategy to include Base stakers

---------

Co-authored-by: Chaitanya <[email protected]>
  • Loading branch information
vladanthales and ChaituVR authored Nov 17, 2023
1 parent 8cfcb76 commit e057ca6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 27 deletions.
8 changes: 3 additions & 5 deletions src/strategies/thales/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@
"name": "thales",
"params": {
"symbol": "THALES",
"decimals": 18,
"blockOptimism": 88627878,
"blockArbitrum": 78979794
"decimals": 18
}
},
"network": "10",
"addresses": [
"0x9f8e4ee788D9b00A3409584E18034aA7B736C396",
"0x0bc3668d2AaFa53eD5E5134bA13ec74ea195D000",
"0x0D858351A5FB419C9A3760647900d2F7aD526c83",
"0xcAc59F91E4536Bc0E79aB816a5cD54e89f10433C",
"0x6dc88B231Cd04Dd1b1e525161162993F47140006",
"0x935D2fD458fdf41B6F7B62471f593797866a3Ce6",
"0x24e445fe7708Bf4bC2ae8d4df1694C98Af8BDE4F",
"0x49be88f0fcc3a8393a59d3688480d7d253c37d2a",
"0x27Cc4d6bc95b55a3a981BF1F1c7261CDa7bB0931"
],
"snapshot": 5003555
"snapshot": 111660236
}
]
78 changes: 56 additions & 22 deletions src/strategies/thales/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import { getAddress } from '@ethersproject/address';
import { formatUnits } from '@ethersproject/units';
import { subgraphRequest } from '../../utils';
import { getSnapshots, subgraphRequest } from '../../utils';

export const author = 'vpoklopic';
export const version = '1.0.3';
export const version = '1.0.4';

enum NetworkId {
Optimism = 10,
Arbitrum = 42161,
Base = 8453
}

const THALES_SUBGRAPH_URL = {
optimism:
'https://api.thegraph.com/subgraphs/name/thales-markets/thales-token',
arbitrum:
'https://api.thegraph.com/subgraphs/name/thales-markets/thales-token-arbitrum'
'https://api.thegraph.com/subgraphs/name/thales-markets/thales-token-arbitrum',
base: 'https://api.studio.thegraph.com/query/11948/thales-token-base/version/latest'
};

function returnGraphParams(addresses: string[]) {
return {
function returnGraphParams(addresses: string[], block: string | number) {
const graphParams = {
stakers: {
__args: {
first: 1000,
Expand All @@ -29,36 +36,47 @@ function returnGraphParams(addresses: string[]) {
totalStakedAmount: true
}
};

if (block !== 'latest') {
// @ts-ignore
graphParams.stakers.__args.block = {
number: block
};
}

return graphParams;
}

export async function strategy(
_space,
_network,
_provider,
addresses,
options
options,
snapshot
) {
const optimismGraphParams = returnGraphParams(addresses);
if (options.blockOptimism !== undefined) {
// @ts-ignore
optimismGraphParams.stakers.__args.block = {
number: options.blockOptimism
};
}
const blocks = await getSnapshots(_network, snapshot, _provider, [
NetworkId.Optimism,
NetworkId.Arbitrum,
NetworkId.Base
]);

const arbitrumGraphParams = returnGraphParams(addresses);
if (options.blockArbitrum !== undefined) {
// @ts-ignore
arbitrumGraphParams.stakers.__args.block = {
number: options.blockArbitrum
};
}
const optimismGraphParams = returnGraphParams(
addresses,
blocks[NetworkId.Optimism]
);
const arbitrumGraphParams = returnGraphParams(
addresses,
blocks[NetworkId.Arbitrum]
);
const baseGraphParams = returnGraphParams(addresses, blocks[NetworkId.Base]);

const score = {};

const [optimismStakers, arbitrumStakers] = await Promise.all([
const [optimismStakers, arbitrumStakers, baseStakers] = await Promise.all([
subgraphRequest(THALES_SUBGRAPH_URL.optimism, optimismGraphParams),
subgraphRequest(THALES_SUBGRAPH_URL.arbitrum, arbitrumGraphParams)
subgraphRequest(THALES_SUBGRAPH_URL.arbitrum, arbitrumGraphParams),
subgraphRequest(THALES_SUBGRAPH_URL.base, baseGraphParams)
]);

// We are starting by mapping all Optimism stakers
Expand Down Expand Up @@ -86,5 +104,21 @@ export async function strategy(
});
}

// If the Optimism or Arbitrum staker is also staker on Base, add an amount
// Otherwise, just set Base staked amount as a score
if (baseStakers && baseStakers.stakers) {
baseStakers.stakers.forEach((staker) => {
const key = getAddress(staker.id);
const stakedAmount = parseFloat(
formatUnits(staker.totalStakedAmount, options.decimals)
);
if (!!score[key]) {
score[key] += stakedAmount;
} else {
score[key] = stakedAmount;
}
});
}

return score || {};
}

0 comments on commit e057ca6

Please sign in to comment.