@iris-credit/core-sdk 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/LICENSE +21 -0
  2. package/lib/cjs/abis/blm.d.ts +192 -0
  3. package/lib/cjs/abis/blm.js +251 -0
  4. package/lib/cjs/abis/errors.d.ts +441 -0
  5. package/lib/cjs/abis/errors.js +558 -0
  6. package/lib/cjs/abis/index.d.ts +4 -0
  7. package/lib/cjs/abis/index.js +20 -0
  8. package/lib/cjs/abis/iris.d.ts +1448 -0
  9. package/lib/cjs/abis/iris.js +1850 -0
  10. package/lib/cjs/abis/whitelist-blm.d.ts +235 -0
  11. package/lib/cjs/abis/whitelist-blm.js +307 -0
  12. package/lib/cjs/addresses.d.ts +12 -0
  13. package/lib/cjs/addresses.js +17 -0
  14. package/lib/cjs/chain.d.ts +35 -0
  15. package/lib/cjs/chain.js +40 -0
  16. package/lib/cjs/constants.d.ts +14 -0
  17. package/lib/cjs/constants.js +18 -0
  18. package/lib/cjs/index.d.ts +7 -0
  19. package/lib/cjs/index.js +23 -0
  20. package/lib/cjs/math/MathLib.d.ts +26 -0
  21. package/lib/cjs/math/MathLib.js +88 -0
  22. package/lib/cjs/math/index.d.ts +1 -0
  23. package/lib/cjs/math/index.js +17 -0
  24. package/lib/cjs/package.json +1 -0
  25. package/lib/cjs/signatures/authorization.d.ts +20 -0
  26. package/lib/cjs/signatures/authorization.js +25 -0
  27. package/lib/cjs/signatures/erc2612.d.ts +34 -0
  28. package/lib/cjs/signatures/erc2612.js +26 -0
  29. package/lib/cjs/signatures/index.d.ts +4 -0
  30. package/lib/cjs/signatures/index.js +20 -0
  31. package/lib/cjs/signatures/permit2.d.ts +33 -0
  32. package/lib/cjs/signatures/permit2.js +41 -0
  33. package/lib/cjs/signatures/quote.d.ts +34 -0
  34. package/lib/cjs/signatures/quote.js +40 -0
  35. package/lib/cjs/types.d.ts +9 -0
  36. package/lib/cjs/types.js +7 -0
  37. package/lib/esm/abis/blm.d.ts +192 -0
  38. package/lib/esm/abis/blm.js +248 -0
  39. package/lib/esm/abis/errors.d.ts +441 -0
  40. package/lib/esm/abis/errors.js +555 -0
  41. package/lib/esm/abis/index.d.ts +4 -0
  42. package/lib/esm/abis/index.js +4 -0
  43. package/lib/esm/abis/iris.d.ts +1448 -0
  44. package/lib/esm/abis/iris.js +1847 -0
  45. package/lib/esm/abis/whitelist-blm.d.ts +235 -0
  46. package/lib/esm/abis/whitelist-blm.js +304 -0
  47. package/lib/esm/addresses.d.ts +12 -0
  48. package/lib/esm/addresses.js +13 -0
  49. package/lib/esm/chain.d.ts +35 -0
  50. package/lib/esm/chain.js +38 -0
  51. package/lib/esm/constants.d.ts +14 -0
  52. package/lib/esm/constants.js +15 -0
  53. package/lib/esm/index.d.ts +7 -0
  54. package/lib/esm/index.js +7 -0
  55. package/lib/esm/math/MathLib.d.ts +26 -0
  56. package/lib/esm/math/MathLib.js +86 -0
  57. package/lib/esm/math/index.d.ts +1 -0
  58. package/lib/esm/math/index.js +1 -0
  59. package/lib/esm/package.json +1 -0
  60. package/lib/esm/signatures/authorization.d.ts +20 -0
  61. package/lib/esm/signatures/authorization.js +21 -0
  62. package/lib/esm/signatures/erc2612.d.ts +34 -0
  63. package/lib/esm/signatures/erc2612.js +22 -0
  64. package/lib/esm/signatures/index.d.ts +4 -0
  65. package/lib/esm/signatures/index.js +4 -0
  66. package/lib/esm/signatures/permit2.d.ts +33 -0
  67. package/lib/esm/signatures/permit2.js +37 -0
  68. package/lib/esm/signatures/quote.d.ts +34 -0
  69. package/lib/esm/signatures/quote.js +36 -0
  70. package/lib/esm/types.d.ts +9 -0
  71. package/lib/esm/types.js +3 -0
  72. package/package.json +39 -0
  73. package/src/index.ts +7 -0
@@ -0,0 +1,26 @@
1
+ import type { BigIntish } from "../types.js";
2
+ /** Rounding direction for share↔asset conversions. */
3
+ export type RoundingDirection = "Down" | "Up";
4
+ export declare namespace MathLib {
5
+ const WAD = 1000000000000000000n;
6
+ const RAY = 1000000000000000000000000000n;
7
+ const MAX_UINT_256: bigint;
8
+ const MAX_UINT_160: bigint;
9
+ const MAX_UINT_128: bigint;
10
+ const MAX_UINT_48: bigint;
11
+ function maxUint(nBits: number): bigint;
12
+ function abs(a: BigIntish): bigint;
13
+ function min(...xs: BigIntish[]): bigint;
14
+ function max(...xs: BigIntish[]): bigint;
15
+ function zeroFloorSub(x: BigIntish, y: BigIntish): bigint;
16
+ function wMulDown(x: BigIntish, y: BigIntish): bigint;
17
+ function wMulUp(x: BigIntish, y: BigIntish): bigint;
18
+ function wMul(x: BigIntish, y: BigIntish, rounding: RoundingDirection): bigint;
19
+ function wDivDown(x: BigIntish, y: BigIntish): bigint;
20
+ function wDivUp(x: BigIntish, y: BigIntish): bigint;
21
+ function wDiv(x: BigIntish, y: BigIntish, rounding: RoundingDirection): bigint;
22
+ function mulDivDown(x: BigIntish, y: BigIntish, denominator: BigIntish): bigint;
23
+ function mulDivUp(x: BigIntish, y: BigIntish, denominator: BigIntish): bigint;
24
+ function mulDiv(x: BigIntish, y: BigIntish, denominator: BigIntish, rounding: RoundingDirection): bigint;
25
+ function wToRay(x: BigIntish): bigint;
26
+ }
@@ -0,0 +1,86 @@
1
+ export { MathLib };
2
+ var MathLib;
3
+ (function (MathLib) {
4
+ MathLib.WAD = 1000000000000000000n;
5
+ MathLib.RAY = 1000000000000000000000000000n;
6
+ MathLib.MAX_UINT_256 = maxUint(256);
7
+ MathLib.MAX_UINT_160 = maxUint(160);
8
+ MathLib.MAX_UINT_128 = maxUint(128);
9
+ MathLib.MAX_UINT_48 = maxUint(48);
10
+ function maxUint(nBits) {
11
+ if (nBits % 4 !== 0)
12
+ throw new Error(`Invalid number of bits: ${nBits}`);
13
+ return BigInt(`0x${"f".repeat(nBits / 4)}`);
14
+ }
15
+ MathLib.maxUint = maxUint;
16
+ function abs(a) {
17
+ a = BigInt(a);
18
+ return a >= 0 ? a : -a;
19
+ }
20
+ MathLib.abs = abs;
21
+ function min(...xs) {
22
+ return xs.map(BigInt).reduce((x, y) => (x <= y ? x : y));
23
+ }
24
+ MathLib.min = min;
25
+ function max(...xs) {
26
+ return xs.map(BigInt).reduce((x, y) => (x <= y ? y : x));
27
+ }
28
+ MathLib.max = max;
29
+ function zeroFloorSub(x, y) {
30
+ x = BigInt(x);
31
+ y = BigInt(y);
32
+ return x <= y ? 0n : x - y;
33
+ }
34
+ MathLib.zeroFloorSub = zeroFloorSub;
35
+ function wMulDown(x, y) {
36
+ return MathLib.wMul(x, y, "Down");
37
+ }
38
+ MathLib.wMulDown = wMulDown;
39
+ function wMulUp(x, y) {
40
+ return MathLib.wMul(x, y, "Up");
41
+ }
42
+ MathLib.wMulUp = wMulUp;
43
+ function wMul(x, y, rounding) {
44
+ return MathLib.mulDiv(x, y, MathLib.WAD, rounding);
45
+ }
46
+ MathLib.wMul = wMul;
47
+ function wDivDown(x, y) {
48
+ return MathLib.wDiv(x, y, "Down");
49
+ }
50
+ MathLib.wDivDown = wDivDown;
51
+ function wDivUp(x, y) {
52
+ return MathLib.wDiv(x, y, "Up");
53
+ }
54
+ MathLib.wDivUp = wDivUp;
55
+ function wDiv(x, y, rounding) {
56
+ return MathLib.mulDiv(x, MathLib.WAD, y, rounding);
57
+ }
58
+ MathLib.wDiv = wDiv;
59
+ function mulDivDown(x, y, denominator) {
60
+ x = BigInt(x);
61
+ y = BigInt(y);
62
+ denominator = BigInt(denominator);
63
+ if (denominator === 0n)
64
+ throw Error("MathLib: DIVISION_BY_ZERO");
65
+ return (x * y) / denominator;
66
+ }
67
+ MathLib.mulDivDown = mulDivDown;
68
+ function mulDivUp(x, y, denominator) {
69
+ x = BigInt(x);
70
+ y = BigInt(y);
71
+ denominator = BigInt(denominator);
72
+ if (denominator === 0n)
73
+ throw Error("MathLib: DIVISION_BY_ZERO");
74
+ const roundup = (x * y) % denominator > 0 ? 1n : 0n;
75
+ return (x * y) / denominator + roundup;
76
+ }
77
+ MathLib.mulDivUp = mulDivUp;
78
+ function mulDiv(x, y, denominator, rounding) {
79
+ return MathLib[`mulDiv${rounding}`](x, y, denominator);
80
+ }
81
+ MathLib.mulDiv = mulDiv;
82
+ function wToRay(x) {
83
+ return BigInt(x) * 1000000000n;
84
+ }
85
+ MathLib.wToRay = wToRay;
86
+ })(MathLib || (MathLib = {}));
@@ -0,0 +1 @@
1
+ export * from "./MathLib.js";
@@ -0,0 +1 @@
1
+ export * from "./MathLib.js";
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,20 @@
1
+ import type { Address } from "viem";
2
+ export type Authorization = {
3
+ authorizer: Address;
4
+ authorized: Address;
5
+ isAuthorized: boolean;
6
+ nonce: bigint;
7
+ deadline: bigint;
8
+ };
9
+ export declare const getAuthorizationTypedData: (chainId: 1, authorization: Authorization) => import("viem").MessageDefinition<{
10
+ Authorization: {
11
+ name: string;
12
+ type: string;
13
+ }[];
14
+ }, "Authorization", "message", "Authorization", {
15
+ Authorization: {
16
+ [x: string]: [`Error: Cannot convert unknown type '${string}' to primitive type.`];
17
+ };
18
+ }, {
19
+ [x: string]: [`Error: Cannot convert unknown type '${string}' to primitive type.`];
20
+ }>;
@@ -0,0 +1,21 @@
1
+ import { getChainAddresses } from "../addresses.js";
2
+ const authorizationTypes = {
3
+ Authorization: [
4
+ { name: "authorizer", type: "address" },
5
+ { name: "authorized", type: "address" },
6
+ { name: "isAuthorized", type: "bool" },
7
+ { name: "nonce", type: "uint256" },
8
+ { name: "deadline", type: "uint256" },
9
+ ],
10
+ };
11
+ export const getAuthorizationTypedData = (chainId, authorization) => {
12
+ return {
13
+ domain: {
14
+ chainId,
15
+ verifyingContract: getChainAddresses(chainId).iris,
16
+ },
17
+ types: authorizationTypes,
18
+ message: authorization,
19
+ primaryType: "Authorization",
20
+ };
21
+ };
@@ -0,0 +1,34 @@
1
+ import type { Address } from "viem";
2
+ import type { ChainId } from "../chain.js";
3
+ /**
4
+ * The EIP-712 domain of an ERC-20 token that implements EIP-2612.
5
+ *
6
+ * Unlike the iris-signed types, the `verifyingContract` here is the token itself,
7
+ * and `name`/`version` are token-specific — they must be read from the token
8
+ * (e.g. via `name()` / `eip712Domain()`), not assumed.
9
+ */
10
+ export type Erc2612Domain = {
11
+ token: Address;
12
+ chainId: ChainId;
13
+ name: string;
14
+ version?: string;
15
+ };
16
+ export type Erc2612Permit = {
17
+ owner: Address;
18
+ spender: Address;
19
+ value: bigint;
20
+ nonce: bigint;
21
+ deadline: bigint;
22
+ };
23
+ export declare const getErc2612PermitTypedData: (domain: Erc2612Domain, permit: Erc2612Permit) => import("viem").MessageDefinition<{
24
+ Permit: {
25
+ name: string;
26
+ type: string;
27
+ }[];
28
+ }, "Permit", "message", "Permit", {
29
+ Permit: {
30
+ [x: string]: [`Error: Cannot convert unknown type '${string}' to primitive type.`];
31
+ };
32
+ }, {
33
+ [x: string]: [`Error: Cannot convert unknown type '${string}' to primitive type.`];
34
+ }>;
@@ -0,0 +1,22 @@
1
+ const permitTypes = {
2
+ Permit: [
3
+ { name: "owner", type: "address" },
4
+ { name: "spender", type: "address" },
5
+ { name: "value", type: "uint256" },
6
+ { name: "nonce", type: "uint256" },
7
+ { name: "deadline", type: "uint256" },
8
+ ],
9
+ };
10
+ export const getErc2612PermitTypedData = (domain, permit) => {
11
+ return {
12
+ domain: {
13
+ name: domain.name,
14
+ version: domain.version,
15
+ chainId: domain.chainId,
16
+ verifyingContract: domain.token,
17
+ },
18
+ types: permitTypes,
19
+ message: permit,
20
+ primaryType: "Permit",
21
+ };
22
+ };
@@ -0,0 +1,4 @@
1
+ export * from "./authorization.js";
2
+ export * from "./erc2612.js";
3
+ export * from "./permit2.js";
4
+ export * from "./quote.js";
@@ -0,0 +1,4 @@
1
+ export * from "./authorization.js";
2
+ export * from "./erc2612.js";
3
+ export * from "./permit2.js";
4
+ export * from "./quote.js";
@@ -0,0 +1,33 @@
1
+ import type { Address } from "viem";
2
+ /** The permit data for a token. */
3
+ export type PermitDetails = {
4
+ token: Address;
5
+ amount: bigint;
6
+ expiration: number;
7
+ nonce: number;
8
+ };
9
+ /** The permit message signed for a single token allowance. */
10
+ export type PermitSingle = {
11
+ details: PermitDetails;
12
+ spender: Address;
13
+ sigDeadline: bigint;
14
+ };
15
+ export declare const getPermit2PermitTypedData: (chainId: 1, permitSingle: PermitSingle) => import("viem").MessageDefinition<{
16
+ PermitSingle: {
17
+ name: string;
18
+ type: string;
19
+ }[];
20
+ PermitDetails: {
21
+ name: string;
22
+ type: string;
23
+ }[];
24
+ }, "PermitSingle", "message", "PermitDetails" | "PermitSingle", {
25
+ PermitSingle: {
26
+ [x: string]: [`Error: Cannot convert unknown type '${string}' to primitive type.`];
27
+ };
28
+ PermitDetails: {
29
+ [x: string]: [`Error: Cannot convert unknown type '${string}' to primitive type.`];
30
+ };
31
+ }, {
32
+ [x: string]: [`Error: Cannot convert unknown type '${string}' to primitive type.`];
33
+ }>;
@@ -0,0 +1,37 @@
1
+ import { getChainAddresses } from "../addresses.js";
2
+ import { MathLib } from "../math/index.js";
3
+ const permit2PermitTypes = {
4
+ PermitSingle: [
5
+ { name: "details", type: "PermitDetails" },
6
+ { name: "spender", type: "address" },
7
+ { name: "sigDeadline", type: "uint256" },
8
+ ],
9
+ PermitDetails: [
10
+ { name: "token", type: "address" },
11
+ { name: "amount", type: "uint160" },
12
+ { name: "expiration", type: "uint48" },
13
+ { name: "nonce", type: "uint48" },
14
+ ],
15
+ };
16
+ export const getPermit2PermitTypedData = (chainId, permitSingle) => {
17
+ const { details, spender, sigDeadline } = permitSingle;
18
+ return {
19
+ domain: {
20
+ name: "Permit2",
21
+ chainId,
22
+ verifyingContract: getChainAddresses(chainId).permit2,
23
+ },
24
+ types: permit2PermitTypes,
25
+ message: {
26
+ details: {
27
+ token: details.token,
28
+ amount: MathLib.min(details.amount, MathLib.MAX_UINT_160),
29
+ expiration: MathLib.min(details.expiration, MathLib.MAX_UINT_48),
30
+ nonce: details.nonce,
31
+ },
32
+ spender,
33
+ sigDeadline,
34
+ },
35
+ primaryType: "PermitSingle",
36
+ };
37
+ };
@@ -0,0 +1,34 @@
1
+ import type { Address, Hex } from "viem";
2
+ export type Quote = {
3
+ borrower: Address;
4
+ solver: Address;
5
+ receiver: Address;
6
+ blm: Address;
7
+ collateralToken: Address;
8
+ debtToken: Address;
9
+ collateral: bigint;
10
+ debt: bigint;
11
+ fixedRate: bigint;
12
+ duration: bigint;
13
+ overdueRate: bigint;
14
+ overduePeriod: bigint;
15
+ bond: bigint;
16
+ bondLltv: bigint;
17
+ venueBitmap: bigint;
18
+ venueId: bigint;
19
+ deadline: bigint;
20
+ nonce: bigint;
21
+ data: Hex;
22
+ };
23
+ export declare const getQuoteTypedData: (chainId: 1, quote: Quote) => import("viem").MessageDefinition<{
24
+ Quote: {
25
+ name: string;
26
+ type: string;
27
+ }[];
28
+ }, "Quote", "message", "Quote", {
29
+ Quote: {
30
+ [x: string]: [`Error: Cannot convert unknown type '${string}' to primitive type.`];
31
+ };
32
+ }, {
33
+ [x: string]: [`Error: Cannot convert unknown type '${string}' to primitive type.`];
34
+ }>;
@@ -0,0 +1,36 @@
1
+ import { getChainAddresses } from "../addresses.js";
2
+ // Field order must match the contract's QUOTE_TYPEHASH; EIP-712 struct hashing is order-sensitive.
3
+ const quoteTypes = {
4
+ Quote: [
5
+ { name: "borrower", type: "address" },
6
+ { name: "solver", type: "address" },
7
+ { name: "receiver", type: "address" },
8
+ { name: "blm", type: "address" },
9
+ { name: "collateralToken", type: "address" },
10
+ { name: "debtToken", type: "address" },
11
+ { name: "collateral", type: "uint256" },
12
+ { name: "debt", type: "uint256" },
13
+ { name: "fixedRate", type: "uint256" },
14
+ { name: "duration", type: "uint256" },
15
+ { name: "overdueRate", type: "uint256" },
16
+ { name: "overduePeriod", type: "uint256" },
17
+ { name: "bond", type: "uint256" },
18
+ { name: "bondLltv", type: "uint256" },
19
+ { name: "venueBitmap", type: "uint256" },
20
+ { name: "venueId", type: "uint256" },
21
+ { name: "deadline", type: "uint256" },
22
+ { name: "nonce", type: "uint256" },
23
+ { name: "data", type: "bytes" },
24
+ ],
25
+ };
26
+ export const getQuoteTypedData = (chainId, quote) => {
27
+ return {
28
+ domain: {
29
+ chainId,
30
+ verifyingContract: getChainAddresses(chainId).iris,
31
+ },
32
+ types: quoteTypes,
33
+ message: quote,
34
+ primaryType: "Quote",
35
+ };
36
+ };
@@ -0,0 +1,9 @@
1
+ /** The id of a market used on the core contract */
2
+ export type MarketId = `0x${string}` & {
3
+ readonly __TYPE__: "marketId";
4
+ };
5
+ export type BigIntish = bigint | string | number | boolean;
6
+ export type Loadable<T> = T | undefined;
7
+ export type Failable<T> = T | null;
8
+ export type Fetchable<T> = Failable<Loadable<T>>;
9
+ export declare const isMarketId: (value: unknown) => value is MarketId;
@@ -0,0 +1,3 @@
1
+ export const isMarketId = (value) => {
2
+ return typeof value === "string" && /^0x[0-9A-Fa-f]{64}$/.test(value);
3
+ };
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@iris-credit/core-sdk",
3
+ "version": "0.0.0",
4
+ "license": "MIT",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/iris-credit/iris-sdks.git",
8
+ "directory": "packages/core-sdk"
9
+ },
10
+ "files": [
11
+ "lib"
12
+ ],
13
+ "type": "module",
14
+ "main": "src/index.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./lib/esm/index.d.ts",
18
+ "import": "./lib/esm/index.js",
19
+ "require": "./lib/cjs/index.js"
20
+ }
21
+ },
22
+ "publishConfig": {
23
+ "registry": "https://registry.npmjs.org",
24
+ "access": "public"
25
+ },
26
+ "devDependencies": {
27
+ "viem": "^2.41.2"
28
+ },
29
+ "peerDependencies": {
30
+ "viem": "^2",
31
+ "@iris-credit/iris-ts": "^0.0.0"
32
+ },
33
+ "scripts": {
34
+ "prepublish": "$npm_execpath build",
35
+ "build": "tsgo --noEmit && $npm_execpath build:cjs && $npm_execpath build:esm",
36
+ "build:cjs": "tsgo --build tsconfig.build.cjs.json && echo '{\"type\":\"commonjs\"}' > lib/cjs/package.json",
37
+ "build:esm": "tsgo --build tsconfig.build.esm.json && echo '{\"type\":\"module\"}' > lib/esm/package.json"
38
+ }
39
+ }
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ export * from "./types.js";
2
+ export * from "./chain.js";
3
+ export * from "./constants.js";
4
+ export * from "./addresses.js";
5
+ export * from "./signatures/index.js";
6
+ export * from "./math/index.js";
7
+ export * from "./abis/index.js";