Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions stateful-m-token/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
#!/bin/bash
set -e # stop if any command fails

if [ -z "$1" ]; then
echo "Usage: $0 <version>"
# Check for dependencies: jq and goldsky
if ! command -v jq &> /dev/null; then
echo "jq is required. Please install it."
echo "e.g., 'brew install jq'"
exit 1
fi
if ! command -v goldsky &> /dev/null; then
echo "goldsky is required. Please install it."
echo "e.g., 'npm install -g @goldskycom/cli'"
exit 1
fi

if [ -z "$ALCHEMY_DEPLOY_KEY" ]; then
echo "Error: ALCHEMY_DEPLOY_KEY environment variable not set."
echo "Set it with: export ALCHEMY_DEPLOY_KEY=your_key_here"
if [ -z "$1" ]; then
echo "Missing arguments. <version>"
exit 1
fi

Expand All @@ -21,11 +27,7 @@ echo "👷‍♀️ Building subgraph..."
yarn codegen
yarn build

echo "🚀 Deploying subgraph with version: $VERSION"
yarn graph deploy m-token-mainnet \
--version-label "$VERSION" \
--node https://subgraphs.alchemy.com/api/subgraphs/deploy \
--deploy-key "$ALCHEMY_DEPLOY_KEY" \
--ipfs https://ipfs.satsuma.xyz
echo "🚀 Deploying subgraph..."
goldsky subgraph deploy m-token-mainnet/"$VERSION" --path .

echo "✅ Deployment complete"
4 changes: 2 additions & 2 deletions stateful-m-token/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
},
"dependencies": {},
"devDependencies": {
"@graphprotocol/graph-cli": "^0.88.0",
"@graphprotocol/graph-ts": "^0.35.1",
"@graphprotocol/graph-cli": "^0.98.1",
"@graphprotocol/graph-ts": "^0.38.2",
"dotenv": "^16.4.5",
"prettier": "^3.3.3"
},
Expand Down
62 changes: 43 additions & 19 deletions stateful-m-token/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,42 @@ interface StringSnapshotEntity implements SnapshotEntity {
value: String!
}

type EarningPrincipalSnapshot implements HolderSnapshotEntity & BigIntSnapshotEntity & SnapshotEntity @entity {
type EarningPrincipalSnapshot implements HolderSnapshotEntity & BigIntSnapshotEntity & SnapshotEntity @entity(immutable: false) {
id: ID! @unique
timestamp: Timestamp!
account: Holder!
value: BigInt!
}

type NonEarningBalanceSnapshot implements HolderSnapshotEntity & BigIntSnapshotEntity & SnapshotEntity @entity {
type NonEarningBalanceSnapshot implements HolderSnapshotEntity & BigIntSnapshotEntity & SnapshotEntity @entity(immutable: false) {
id: ID! @unique
timestamp: Timestamp!
account: Holder!
value: BigInt!
}

type IsEarningSnapshot implements HolderSnapshotEntity & BooleanSnapshotEntity & SnapshotEntity @entity {
type IsEarningSnapshot implements HolderSnapshotEntity & BooleanSnapshotEntity & SnapshotEntity @entity(immutable: false) {
id: ID! @unique
timestamp: Timestamp!
account: Holder!
value: Boolean!
}

type ReceivedSnapshot implements HolderSnapshotEntity & BigIntSnapshotEntity & SnapshotEntity @entity {
type ReceivedSnapshot implements HolderSnapshotEntity & BigIntSnapshotEntity & SnapshotEntity @entity(immutable: false) {
id: ID! @unique
timestamp: Timestamp!
account: Holder!
value: BigInt!
}

type SentSnapshot implements HolderSnapshotEntity & BigIntSnapshotEntity & SnapshotEntity @entity {
type SentSnapshot implements HolderSnapshotEntity & BigIntSnapshotEntity & SnapshotEntity @entity(immutable: false) {
id: ID! @unique
timestamp: Timestamp!
account: Holder!
value: BigInt!
}

type Holder @entity {
type Holder @entity(immutable: false) {
id: ID! @unique
address: String! @unique
earningPrincipal: BigInt!
Expand All @@ -86,55 +86,79 @@ type Holder @entity {
lastUpdate: Timestamp!
}

type TotalNonEarningSupplySnapshot implements BigIntSnapshotEntity & SnapshotEntity @entity {
type TotalNonEarningSupplySnapshot implements BigIntSnapshotEntity & SnapshotEntity @entity(immutable: false) {
id: ID! @unique
timestamp: Timestamp! @unique
value: BigInt!
}

type PrincipalOfTotalEarningSupplySnapshot implements BigIntSnapshotEntity & SnapshotEntity @entity {
type PrincipalOfTotalEarningSupplySnapshot implements BigIntSnapshotEntity & SnapshotEntity @entity(immutable: false) {
id: ID! @unique
timestamp: Timestamp! @unique
value: BigInt!
}

type LatestIndexSnapshot implements BigIntSnapshotEntity & SnapshotEntity @entity {
id: ID! @unique
type LatestIndexSnapshot @entity(timeseries: true) {
id: Int8!
timestamp: Timestamp! @unique
value: BigInt!
}

type LatestRateSnapshot implements BigIntSnapshotEntity & SnapshotEntity @entity {
id: ID! @unique
type LatestIndex
@aggregation(intervals: ["hour", "day"], source: "LatestIndexSnapshot") {
id: Int8!
timestamp: Timestamp!
value: BigInt! @aggregate(fn: "last", arg: "value")
count: Int8! @aggregate(fn: "count", cumulative: true)
}
Comment thread
jonalvarezz marked this conversation as resolved.

type LatestRateSnapshot @entity(timeseries: true) {
id: Int8!
timestamp: Timestamp! @unique
value: BigInt!
}

type LatestUpdateTimestampSnapshot implements TimestampSnapshotEntity & SnapshotEntity @entity {
id: ID! @unique
type LatestRate
@aggregation(intervals: ["hour", "day"], source: "LatestRateSnapshot") {
id: Int8!
timestamp: Timestamp!
value: BigInt! @aggregate(fn: "last", arg: "value")
count: Int8! @aggregate(fn: "count", cumulative: true)
}

type LatestUpdateTimestampSnapshot @entity(timeseries: true) {
id: Int8!
timestamp: Timestamp! @unique
value: Timestamp!
value: Int!
}

type LatestUpdateTimestamp
@aggregation(intervals: ["hour", "day"], source: "LatestUpdateTimestampSnapshot") {
id: Int8!
timestamp: Timestamp!
value: Int! @aggregate(fn: "last", arg: "value")
count: Int8! @aggregate(fn: "count", cumulative: true)
}

type TotalMintedSnapshot implements BigIntSnapshotEntity & SnapshotEntity @entity {
type TotalMintedSnapshot implements BigIntSnapshotEntity & SnapshotEntity @entity(immutable: false) {
id: ID! @unique
timestamp: Timestamp! @unique
value: BigInt!
}

type TotalBurnedSnapshot implements BigIntSnapshotEntity & SnapshotEntity @entity {
type TotalBurnedSnapshot implements BigIntSnapshotEntity & SnapshotEntity @entity(immutable: false) {
id: ID! @unique
timestamp: Timestamp! @unique
value: BigInt!
}

type RateModelSnapshot implements StringSnapshotEntity & SnapshotEntity @entity {
type RateModelSnapshot implements StringSnapshotEntity & SnapshotEntity @entity(immutable: false) {
id: ID! @unique
timestamp: Timestamp! @unique
value: String!
}

type MToken @entity {
type MToken @entity(immutable: false) {
id: ID! @unique
holders: [Holder!]
totalNonEarningSupply: BigInt!
Comment thread
oleksandr-fedorenko-m0 marked this conversation as resolved.
Expand Down
37 changes: 9 additions & 28 deletions stateful-m-token/src/m-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const EXP_SCALED_ONE = BigInt.fromI32(10).pow(12);
const BPS_SCALED_ONE = BigInt.fromI32(10).pow(4);
const SECONDS_PER_YEAR = BigInt.fromI32(31_536_000);

const TIMESERIES_ID = 1;

/* ============ Handlers ============ */

export function handleKeySet(event: KeySetEvent): void {
Expand Down Expand Up @@ -292,49 +294,28 @@ function updatePrincipalOfTotalEarningSupplySnapshot(timestamp: Timestamp, value
}

function updateLatestIndexSnapshot(timestamp: Timestamp, value: BigInt): void {
const id = `latestIndex-${timestamp.toString()}`;

let snapshot = LatestIndexSnapshot.load(id);

if (!snapshot) {
snapshot = new LatestIndexSnapshot(id);

snapshot.timestamp = timestamp;
}
let snapshot = new LatestIndexSnapshot(TIMESERIES_ID);

snapshot.timestamp = timestamp;
snapshot.value = value;

snapshot.save();
}

function updateLatestRateSnapshot(timestamp: Timestamp, value: BigInt): void {
const id = `latestRate-${timestamp.toString()}`;

let snapshot = LatestRateSnapshot.load(id);

if (!snapshot) {
snapshot = new LatestRateSnapshot(id);

snapshot.timestamp = timestamp;
}
let snapshot = new LatestRateSnapshot(TIMESERIES_ID);

snapshot.timestamp = timestamp;
snapshot.value = value;

snapshot.save();
}

function updateLatestUpdateTimestampSnapshot(timestamp: Timestamp, value: Timestamp): void {
const id = `latestUpdateTimestamp-${timestamp.toString()}`;

let snapshot = LatestUpdateTimestampSnapshot.load(id);

if (!snapshot) {
snapshot = new LatestUpdateTimestampSnapshot(id);
let snapshot = new LatestUpdateTimestampSnapshot(TIMESERIES_ID);

snapshot.timestamp = timestamp;
}

snapshot.value = value;
snapshot.timestamp = timestamp;
snapshot.value = i32(value);

snapshot.save();
}
Expand Down
9 changes: 6 additions & 3 deletions stateful-m-token/subgraph.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
specVersion: 1.0.0
specVersion: 1.2.0
indexerHints:
prune: auto
schema:
Expand All @@ -13,7 +13,7 @@ dataSources:
startBlock: 19818438
mapping:
kind: ethereum/events
apiVersion: 0.0.7
apiVersion: 0.0.9
language: wasm/assemblyscript
entities:
- EarningPrincipalSnapshot
Expand All @@ -25,8 +25,11 @@ dataSources:
- TotalNonEarningSupplySnapshot
- PrincipalOfTotalNonEarningSupplySnapshot
- LatestIndexSnapshot
- LatestIndex
- LatestRateSnapshot
- LatestRate
- LatestUpdateTimestampSnapshot
Comment thread
oleksandr-fedorenko-m0 marked this conversation as resolved.
- LatestUpdateTimestamp
- TotalMintedSnapshot
- TotalBurnedSnapshot
- MToken
Expand All @@ -53,7 +56,7 @@ dataSources:
startBlock: 19818438
mapping:
kind: ethereum/events
apiVersion: 0.0.7
apiVersion: 0.0.9
language: wasm/assemblyscript
entities:
- RateModelSnapshot
Expand Down
Loading