Skip to content

Commit

Permalink
feat: add airdrop programs (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabin54 authored Aug 9, 2024
1 parent 60edb2b commit 2eb2f17
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 103 deletions.
16 changes: 8 additions & 8 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export default {
moduleFileExtensions: ["ts", "js"],
transform: {
"^.+\\.tsx?$": "ts-jest",
},
testTimeout: 50_000,
testMatch: ["**/tests/**/*.test.(ts|js)"],
testEnvironment: "node",
};
moduleFileExtensions: ["ts", "js"],
transform: {
"^.+\\.tsx?$": "ts-jest",
},
testTimeout: 50_000,
testMatch: ["**/tests/**/*.test.(ts|js)"],
testEnvironment: "node",
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@morpho-org/blue-reward-programs",
"version": "0.0.1",
"version": "1.4.12",
"author": "Morpho Association <[email protected]>",
"license": "MIT",
"main": "lib/index.js",
Expand Down Expand Up @@ -33,7 +33,8 @@
"typescript": "^5.4.5"
},
"dependencies": {
"@morpho-org/blue-rewards-core-sdk": "0.0.5",
"@morpho-org/blue-rewards-core-sdk": "0.0.8",
"@morpho-org/morpho-ts": "^1.4.5",
"viem": "^2.9.31"
},
"lint-staged": {
Expand Down
26 changes: 26 additions & 0 deletions src/airdrop-programs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Address, ChainId } from "@morpho-org/blue-rewards-core-sdk";

export type AirdropRewardProgramArgs = {
claimDate: bigint;
fundsSender: Address;
urdAddress: Address;
tokenAddress: Address;
chainId: ChainId;
ipfsHash: string;
};

/**
* List of Airdrop programs
* @example
* [
* {
* claimDate: 1717149233n,
* fundsSender: "0xF057afeEc22E220f47AD4220871364e9E828b2e9",
* urdAddress: "0x330eefa8a787552dc5cad3c3ca644844b1e61ddb",
* tokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
* ipfsHash: "QmUSNh34dpKFbX7YMU4fd5JbfkVYzb4e45o3pSqqXvzkKw",
* chainId: ChainId.MAINNET
* }
* ]
*/
export const airdropPrograms: AirdropRewardProgramArgs[] = [];
30 changes: 30 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import {
RewardMathLib,
UniversalRewardDistributor,
VaultRewardProgram,
AirdropRewardProgram,
RewardProgram,
} from "@morpho-org/blue-rewards-core-sdk";

import { AirdropRewardProgramArgs, airdropPrograms } from "./airdrop-programs";
import { MarketRewardProgramArgs, marketPrograms } from "./market-programs";
import { VaultRewardProgramArgs, vaultPrograms } from "./vault-programs";

Expand All @@ -16,6 +19,12 @@ export const OffchainPrograms = {
getVaultPrograms(): VaultRewardProgram[] {
return vaultPrograms.map((programArgs) => toVaultRewardProgram(programArgs));
},
getAirdropPrograms(): AirdropRewardProgram[] {
return airdropPrograms.map((programArgs) => toAirdropRewardProgram(programArgs));
},
getPrograms(): RewardProgram[] {
return [...this.getMarketPrograms(), ...this.getVaultPrograms(), ...this.getAirdropPrograms()];
},
};

function toMarketRewardProgram(args: MarketRewardProgramArgs): MarketRewardProgram {
Expand Down Expand Up @@ -85,3 +94,24 @@ function toVaultRewardProgram(args: VaultRewardProgramArgs): VaultRewardProgram
amount: args.amount,
});
}

function toAirdropRewardProgram(args: AirdropRewardProgramArgs): AirdropRewardProgram {
const asset = new OnchainAsset({
address: args.tokenAddress,
chainId: args.chainId,
});
const distributor = new UniversalRewardDistributor({
address: args.urdAddress,
chainId: args.chainId,
});

return new AirdropRewardProgram({
createdAt: args.claimDate,
start: args.claimDate,
creator: args.fundsSender,
asset,
distributor,
chainId: args.chainId,
ipfsHash: args.ipfsHash,
});
}
Loading

0 comments on commit 2eb2f17

Please sign in to comment.