@superfluid-finance/sdk-core 0.1.1-dev.7bfb2dd.0 → 0.1.1-dev.8caff13.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.
package/README.md CHANGED
@@ -37,12 +37,24 @@ yarn install && yarn build
37
37
 
38
38
  Here is a quick look at initializing the SDK in different environments:
39
39
 
40
- TypeScript / JavaScript (Module):
40
+ TypeScript / JavaScript (Module) vs. JavaScript (CommonJS) - usually a Node.js environment
41
41
 
42
+ The primary difference between the two environments is the import/require of the sdk-core package, everything else is the same.
43
+
44
+ TS/ESModule
42
45
  ```ts
43
46
  import { Framework } from "@superfluid-finance/sdk-core";
44
47
  import { ethers } from "ethers";
48
+ ```
49
+
50
+ CommonJS/Node.js
51
+ ```js
52
+ const { Framework } = require("@superfluid-finance/sdk-core");
53
+ const { ethers } = require("ethers");
54
+ ```
45
55
 
56
+ ```ts
57
+ // infura provider initialization
46
58
  const provider = new ethers.providers.InfuraProvider(
47
59
  "matic",
48
60
  "<INFURA_API_KEY>"
@@ -60,31 +72,45 @@ const web3jsSf = await Framework.create({
60
72
  networkName: "matic",
61
73
  provider: web3jsProvider
62
74
  });
63
- ```
64
-
65
- JavaScript (CommonJS) - usually a Node.js environment:
66
-
67
- ```js
68
- const { Framework } = require("@superfluid-finance/sdk-core");
69
- const { ethers } = require("ethers");
70
75
 
71
- const provider = new ethers.providers.InfuraProvider(
72
- "matic",
73
- "<INFURA_API_KEY>"
74
- );
75
- const sf = await Framework.create({
76
+ // ethers.js + hardhat provider initialization (in testing environment w/ hardhat-ethers)
77
+ const [deployer] = await ethers.getSigners();
78
+ const ethersProvider = deployer.provider;
79
+ const ethersjsSf = await Framework.create({
76
80
  networkName: "matic",
77
- provider
81
+ provider: ethersProvider
78
82
  });
79
83
 
80
- // web3.js + Hardhat provider initialization
81
- const web3jsProvider = new ethers.providers.Web3Provider(
82
- global.web3.currentProvider
83
- );
84
- const web3jsSf = await Framework.create({
84
+ // metamask
85
+ const mmProvider = new ethers.providers.Web3Provider(window.ethereum);
86
+ const mmSf = await Framework.create({
85
87
  networkName: "matic",
86
- provider: web3jsProvider
88
+ provider: mmProvider
87
89
  });
90
+
91
+ // web3modal
92
+ const web3ModalRawProvider = await web3Modal.connect();
93
+ const web3ModalProvider = new ethers.providers.Web3Provider(web3ModalRawProvider);
94
+ const web3ModalSf = await Framework.create({
95
+ networkName: "matic",
96
+ provider: web3ModalProvider
97
+ });
98
+
99
+ //bnc-onboard
100
+ const onboard = Onboard({
101
+ dappId: "<API_KEY>",
102
+ networkId: 4,
103
+ subscriptions: {
104
+ wallet: wallet => {
105
+ const web3Provider = new ethers.providers.Web3Provider(wallet.provider);
106
+ (async () => {
107
+ const framework = await Framework.create({ networkName: "matic", provider: web3Provider });
108
+ })();
109
+ }
110
+ }
111
+ });
112
+ // this is triggered by:
113
+ await onboard.walletSelect();
88
114
  ```
89
115
 
90
116
  > Note: You specify your project type in `package.json` - `"type": "module"` or `"type": "commonjs"`.
@@ -1,9 +1,16 @@
1
1
  import { IResolverData } from "./interfaces";
2
2
  export declare const MONTHS_PER_YEAR = 12;
3
3
  export declare const DAYS_PER_MONTH = 30;
4
+ export declare const DAYS_PER_WEEK = 7;
4
5
  export declare const HOURS_PER_DAY = 24;
5
6
  export declare const MINUTES_PER_HOUR = 60;
6
- export declare const SECONDS_PER_MINUTE = 60;
7
+ export declare const MINUTE_IN_SECONDS = 60;
8
+ export declare const HOUR_IN_SECONDS: number;
9
+ export declare const DAY_IN_SECONDS: number;
10
+ export declare const WEEK_IN_SECONDS: number;
11
+ export declare const MONTH_IN_SECONDS: number;
12
+ export declare const YEAR_IN_SECONDS: number;
13
+ export declare const BASE_18 = 10000000000000000000;
7
14
  export declare const chainIds: number[];
8
15
  export declare const networkNames: string[];
9
16
  export declare const chainIdToDataMap: Map<number, IResolverData>;
@@ -1457,17 +1457,27 @@ var Host = /** @class */ (function () {
1457
1457
 
1458
1458
  var MONTHS_PER_YEAR = 12;
1459
1459
  var DAYS_PER_MONTH = 30;
1460
+ var DAYS_PER_WEEK = 7;
1460
1461
  var HOURS_PER_DAY = 24;
1461
1462
  var MINUTES_PER_HOUR = 60;
1462
- var SECONDS_PER_MINUTE = 60;
1463
+ var MINUTE_IN_SECONDS = 60;
1464
+ var HOUR_IN_SECONDS = MINUTE_IN_SECONDS * MINUTES_PER_HOUR;
1465
+ var DAY_IN_SECONDS = HOUR_IN_SECONDS * HOURS_PER_DAY;
1466
+ var WEEK_IN_SECONDS = DAY_IN_SECONDS * DAYS_PER_WEEK;
1467
+ var MONTH_IN_SECONDS = DAY_IN_SECONDS * DAYS_PER_MONTH;
1468
+ var YEAR_IN_SECONDS = MONTH_IN_SECONDS * MONTHS_PER_YEAR; // NOTE: Is 360 days (misses 5-6 days)
1469
+ var BASE_18 = 10e18;
1463
1470
  var chainIds = [
1464
1471
  3,
1465
1472
  4,
1466
1473
  5,
1467
1474
  42,
1475
+ 69,
1468
1476
  100,
1469
1477
  137,
1470
- 80001, // MUMBAI
1478
+ 43113,
1479
+ 80001,
1480
+ 421611, // ARBITRUM RINKEBY
1471
1481
  ];
1472
1482
  var networkNames = [
1473
1483
  "ropsten",
@@ -1477,6 +1487,9 @@ var networkNames = [
1477
1487
  "xdai",
1478
1488
  "matic",
1479
1489
  "mumbai",
1490
+ "optimism-kovan",
1491
+ "arbitrium-rinkeby",
1492
+ "avalanche-fuji",
1480
1493
  ];
1481
1494
  var chainIdToDataMap = new Map([
1482
1495
  [
@@ -1511,6 +1524,14 @@ var chainIdToDataMap = new Map([
1511
1524
  resolverAddress: "0x851d3dd9dc97c1df1DA73467449B3893fc76D85B",
1512
1525
  },
1513
1526
  ],
1527
+ [
1528
+ 69,
1529
+ {
1530
+ subgraphAPIEndpoint: "https://api.thegraph.com/subgraphs/name/superfluid-finance/protocol-dev-optimism-kovan",
1531
+ networkName: "optimism-kovan",
1532
+ resolverAddress: "0x218B65780615Ff134f9Ad810CB98839534D3C0D6",
1533
+ },
1534
+ ],
1514
1535
  [
1515
1536
  100,
1516
1537
  {
@@ -1527,6 +1548,14 @@ var chainIdToDataMap = new Map([
1527
1548
  resolverAddress: "0xE0cc76334405EE8b39213E620587d815967af39C",
1528
1549
  },
1529
1550
  ],
1551
+ [
1552
+ 43113,
1553
+ {
1554
+ subgraphAPIEndpoint: "https://api.thegraph.com/subgraphs/name/superfluid-finance/protocol-dev-avalanche-fuji",
1555
+ networkName: "avalanche-fuji",
1556
+ resolverAddress: "0xb76d7c14caD40Cc434655Ce0a9B5b49220C362cA",
1557
+ },
1558
+ ],
1530
1559
  [
1531
1560
  80001,
1532
1561
  {
@@ -1535,15 +1564,26 @@ var chainIdToDataMap = new Map([
1535
1564
  resolverAddress: "0x8C54C83FbDe3C59e59dd6E324531FB93d4F504d3",
1536
1565
  },
1537
1566
  ],
1567
+ [
1568
+ 421611,
1569
+ {
1570
+ subgraphAPIEndpoint: "https://api.thegraph.com/subgraphs/name/superfluid-finance/protocol-dev-arbitrum-rinkeby",
1571
+ networkName: "arbitrum-rinkeby",
1572
+ resolverAddress: "0xa2C0C70A1E922f5f060ec20EE3aF002C163b4567",
1573
+ },
1574
+ ],
1538
1575
  ]);
1539
1576
  var networkNameToChainIdMap = new Map([
1540
1577
  ["ropsten", 3],
1541
1578
  ["rinkeby", 4],
1542
1579
  ["goerli", 5],
1543
1580
  ["kovan", 42],
1581
+ ["optimism-kovan", 69],
1544
1582
  ["xdai", 100],
1545
1583
  ["matic", 137],
1584
+ ["avalanche-fuji", 43113],
1546
1585
  ["mumbai", 80001],
1586
+ ["arbitrum-rinkeby", 421611],
1547
1587
  ]);
1548
1588
 
1549
1589
  var EMPTY = "0x";
@@ -1592,12 +1632,7 @@ var getTransactionDescription = function (fragments, data, value) {
1592
1632
  * @returns flow rate per second
1593
1633
  */
1594
1634
  var getPerSecondFlowRateByYear = function (amountPerYear) {
1595
- return Math.round(Number(amountPerYear) *
1596
- MONTHS_PER_YEAR *
1597
- DAYS_PER_MONTH *
1598
- HOURS_PER_DAY *
1599
- MINUTES_PER_HOUR *
1600
- SECONDS_PER_MINUTE).toString();
1635
+ return Math.round((Number(amountPerYear) / YEAR_IN_SECONDS) * BASE_18).toString();
1601
1636
  };
1602
1637
  /**
1603
1638
  * @dev Gets the per second flow rate given an `amountPerMonth` value.
@@ -1605,11 +1640,15 @@ var getPerSecondFlowRateByYear = function (amountPerYear) {
1605
1640
  * @returns flow rate per second
1606
1641
  */
1607
1642
  var getPerSecondFlowRateByMonth = function (amountPerMonth) {
1608
- return Math.round(Number(amountPerMonth) *
1609
- DAYS_PER_MONTH *
1610
- HOURS_PER_DAY *
1611
- MINUTES_PER_HOUR *
1612
- SECONDS_PER_MINUTE).toString();
1643
+ return Math.round((Number(amountPerMonth) / MONTH_IN_SECONDS) * BASE_18).toString();
1644
+ };
1645
+ /**
1646
+ * @dev Gets the per second flow rate given an `amountPerWeek` value.
1647
+ * @param amountPerWeek the amount you want to stream per Week
1648
+ * @returns flow rate per second
1649
+ */
1650
+ var getPerSecondFlowRateByWeek = function (amountPerWeek) {
1651
+ return Math.round((Number(amountPerWeek) / WEEK_IN_SECONDS) * BASE_18).toString();
1613
1652
  };
1614
1653
  /**
1615
1654
  * @dev Gets the per second flow rate given an `amountPerDay` value.
@@ -1617,10 +1656,21 @@ var getPerSecondFlowRateByMonth = function (amountPerMonth) {
1617
1656
  * @returns flow rate per second
1618
1657
  */
1619
1658
  var getPerSecondFlowRateByDay = function (amountPerDay) {
1620
- return Math.round(Number(amountPerDay) *
1621
- HOURS_PER_DAY *
1622
- MINUTES_PER_HOUR *
1623
- SECONDS_PER_MINUTE).toString();
1659
+ return Math.round((Number(amountPerDay) / DAY_IN_SECONDS) * BASE_18).toString();
1660
+ };
1661
+ /**
1662
+ * @dev Gets daily, weekly, monthly and yearly flowed amounts given a per second flow rate.
1663
+ * @param perSecondFlowRate
1664
+ * @returns
1665
+ */
1666
+ var getFlowAmountByPerSecondFlowRate = function (perSecondFlowRate) {
1667
+ var decimalFlowRate = Number(perSecondFlowRate) / BASE_18;
1668
+ return {
1669
+ daily: Math.round(decimalFlowRate * DAY_IN_SECONDS).toString(),
1670
+ weekly: Math.round(decimalFlowRate * WEEK_IN_SECONDS).toString(),
1671
+ monthly: Math.round(decimalFlowRate * MONTH_IN_SECONDS).toString(),
1672
+ yearly: Math.round(decimalFlowRate * YEAR_IN_SECONDS).toString(),
1673
+ };
1624
1674
  };
1625
1675
  /**
1626
1676
  * @dev The formula for calculating the flowed amount since updated using Subgraph data.
@@ -1725,7 +1775,7 @@ var BatchCall = /** @class */ (function () {
1725
1775
  * @returns {Promise<OperationStruct>} OperationStruct object for batchCall
1726
1776
  */
1727
1777
  this.getOperationStruct = function (operation, index) { return __awaiter(_this, void 0, void 0, function () {
1728
- var operationType, populatedTransaction, functionArgs;
1778
+ var operationType, populatedTransaction, encoder, functionArgs, data;
1729
1779
  return __generator(this, function (_a) {
1730
1780
  switch (_a.label) {
1731
1781
  case 0:
@@ -1750,11 +1800,13 @@ var BatchCall = /** @class */ (function () {
1750
1800
  // The only operation which has a target that is not the
1751
1801
  // same as the to property of the transaction.
1752
1802
  if (operation.type === "SUPERFLUID_CALL_AGREEMENT") {
1803
+ encoder = ethers.ethers.utils.defaultAbiCoder;
1753
1804
  functionArgs = this.getCallAgreementFunctionArgs(populatedTransaction.data);
1805
+ data = encoder.encode(["bytes", "bytes"], [functionArgs["callData"], functionArgs["userData"]]);
1754
1806
  return [2 /*return*/, {
1755
1807
  operationType: operationType,
1756
1808
  target: functionArgs["agreementClass"],
1757
- data: functionArgs["callData"],
1809
+ data: data,
1758
1810
  }];
1759
1811
  }
1760
1812
  // Handles other cases which are not call agreeement operation
@@ -7526,8 +7578,10 @@ exports.createPagedResult = createPagedResult;
7526
7578
  exports.createSkipPaging = createSkipPaging;
7527
7579
  exports.flowedAmountSinceUpdatedAt = flowedAmountSinceUpdatedAt;
7528
7580
  exports.getBalance = getBalance;
7581
+ exports.getFlowAmountByPerSecondFlowRate = getFlowAmountByPerSecondFlowRate;
7529
7582
  exports.getPerSecondFlowRateByDay = getPerSecondFlowRateByDay;
7530
7583
  exports.getPerSecondFlowRateByMonth = getPerSecondFlowRateByMonth;
7584
+ exports.getPerSecondFlowRateByWeek = getPerSecondFlowRateByWeek;
7531
7585
  exports.getPerSecondFlowRateByYear = getPerSecondFlowRateByYear;
7532
7586
  exports.getSanitizedTimestamp = getSanitizedTimestamp;
7533
7587
  exports.getStringCurrentTimeInSeconds = getStringCurrentTimeInSeconds;
@@ -34,12 +34,29 @@ export declare const getPerSecondFlowRateByYear: (amountPerYear: string) => stri
34
34
  * @returns flow rate per second
35
35
  */
36
36
  export declare const getPerSecondFlowRateByMonth: (amountPerMonth: string) => string;
37
+ /**
38
+ * @dev Gets the per second flow rate given an `amountPerWeek` value.
39
+ * @param amountPerWeek the amount you want to stream per Week
40
+ * @returns flow rate per second
41
+ */
42
+ export declare const getPerSecondFlowRateByWeek: (amountPerWeek: string) => string;
37
43
  /**
38
44
  * @dev Gets the per second flow rate given an `amountPerDay` value.
39
45
  * @param amountPerDay the amount you want to stream per day
40
46
  * @returns flow rate per second
41
47
  */
42
48
  export declare const getPerSecondFlowRateByDay: (amountPerDay: string) => string;
49
+ /**
50
+ * @dev Gets daily, weekly, monthly and yearly flowed amounts given a per second flow rate.
51
+ * @param perSecondFlowRate
52
+ * @returns
53
+ */
54
+ export declare const getFlowAmountByPerSecondFlowRate: (perSecondFlowRate: string) => {
55
+ daily: string;
56
+ weekly: string;
57
+ monthly: string;
58
+ yearly: string;
59
+ };
43
60
  /**
44
61
  * @dev The formula for calculating the flowed amount since updated using Subgraph data.
45
62
  * @param netFlowRate the net flow rate of the user
@@ -1,9 +1,16 @@
1
1
  import { IResolverData } from "./interfaces";
2
2
  export declare const MONTHS_PER_YEAR = 12;
3
3
  export declare const DAYS_PER_MONTH = 30;
4
+ export declare const DAYS_PER_WEEK = 7;
4
5
  export declare const HOURS_PER_DAY = 24;
5
6
  export declare const MINUTES_PER_HOUR = 60;
6
- export declare const SECONDS_PER_MINUTE = 60;
7
+ export declare const MINUTE_IN_SECONDS = 60;
8
+ export declare const HOUR_IN_SECONDS: number;
9
+ export declare const DAY_IN_SECONDS: number;
10
+ export declare const WEEK_IN_SECONDS: number;
11
+ export declare const MONTH_IN_SECONDS: number;
12
+ export declare const YEAR_IN_SECONDS: number;
13
+ export declare const BASE_18 = 10000000000000000000;
7
14
  export declare const chainIds: number[];
8
15
  export declare const networkNames: string[];
9
16
  export declare const chainIdToDataMap: Map<number, IResolverData>;
@@ -1449,17 +1449,27 @@ var Host = /** @class */ (function () {
1449
1449
 
1450
1450
  var MONTHS_PER_YEAR = 12;
1451
1451
  var DAYS_PER_MONTH = 30;
1452
+ var DAYS_PER_WEEK = 7;
1452
1453
  var HOURS_PER_DAY = 24;
1453
1454
  var MINUTES_PER_HOUR = 60;
1454
- var SECONDS_PER_MINUTE = 60;
1455
+ var MINUTE_IN_SECONDS = 60;
1456
+ var HOUR_IN_SECONDS = MINUTE_IN_SECONDS * MINUTES_PER_HOUR;
1457
+ var DAY_IN_SECONDS = HOUR_IN_SECONDS * HOURS_PER_DAY;
1458
+ var WEEK_IN_SECONDS = DAY_IN_SECONDS * DAYS_PER_WEEK;
1459
+ var MONTH_IN_SECONDS = DAY_IN_SECONDS * DAYS_PER_MONTH;
1460
+ var YEAR_IN_SECONDS = MONTH_IN_SECONDS * MONTHS_PER_YEAR; // NOTE: Is 360 days (misses 5-6 days)
1461
+ var BASE_18 = 10e18;
1455
1462
  var chainIds = [
1456
1463
  3,
1457
1464
  4,
1458
1465
  5,
1459
1466
  42,
1467
+ 69,
1460
1468
  100,
1461
1469
  137,
1462
- 80001, // MUMBAI
1470
+ 43113,
1471
+ 80001,
1472
+ 421611, // ARBITRUM RINKEBY
1463
1473
  ];
1464
1474
  var networkNames = [
1465
1475
  "ropsten",
@@ -1469,6 +1479,9 @@ var networkNames = [
1469
1479
  "xdai",
1470
1480
  "matic",
1471
1481
  "mumbai",
1482
+ "optimism-kovan",
1483
+ "arbitrium-rinkeby",
1484
+ "avalanche-fuji",
1472
1485
  ];
1473
1486
  var chainIdToDataMap = new Map([
1474
1487
  [
@@ -1503,6 +1516,14 @@ var chainIdToDataMap = new Map([
1503
1516
  resolverAddress: "0x851d3dd9dc97c1df1DA73467449B3893fc76D85B",
1504
1517
  },
1505
1518
  ],
1519
+ [
1520
+ 69,
1521
+ {
1522
+ subgraphAPIEndpoint: "https://api.thegraph.com/subgraphs/name/superfluid-finance/protocol-dev-optimism-kovan",
1523
+ networkName: "optimism-kovan",
1524
+ resolverAddress: "0x218B65780615Ff134f9Ad810CB98839534D3C0D6",
1525
+ },
1526
+ ],
1506
1527
  [
1507
1528
  100,
1508
1529
  {
@@ -1519,6 +1540,14 @@ var chainIdToDataMap = new Map([
1519
1540
  resolverAddress: "0xE0cc76334405EE8b39213E620587d815967af39C",
1520
1541
  },
1521
1542
  ],
1543
+ [
1544
+ 43113,
1545
+ {
1546
+ subgraphAPIEndpoint: "https://api.thegraph.com/subgraphs/name/superfluid-finance/protocol-dev-avalanche-fuji",
1547
+ networkName: "avalanche-fuji",
1548
+ resolverAddress: "0xb76d7c14caD40Cc434655Ce0a9B5b49220C362cA",
1549
+ },
1550
+ ],
1522
1551
  [
1523
1552
  80001,
1524
1553
  {
@@ -1527,15 +1556,26 @@ var chainIdToDataMap = new Map([
1527
1556
  resolverAddress: "0x8C54C83FbDe3C59e59dd6E324531FB93d4F504d3",
1528
1557
  },
1529
1558
  ],
1559
+ [
1560
+ 421611,
1561
+ {
1562
+ subgraphAPIEndpoint: "https://api.thegraph.com/subgraphs/name/superfluid-finance/protocol-dev-arbitrum-rinkeby",
1563
+ networkName: "arbitrum-rinkeby",
1564
+ resolverAddress: "0xa2C0C70A1E922f5f060ec20EE3aF002C163b4567",
1565
+ },
1566
+ ],
1530
1567
  ]);
1531
1568
  var networkNameToChainIdMap = new Map([
1532
1569
  ["ropsten", 3],
1533
1570
  ["rinkeby", 4],
1534
1571
  ["goerli", 5],
1535
1572
  ["kovan", 42],
1573
+ ["optimism-kovan", 69],
1536
1574
  ["xdai", 100],
1537
1575
  ["matic", 137],
1576
+ ["avalanche-fuji", 43113],
1538
1577
  ["mumbai", 80001],
1578
+ ["arbitrum-rinkeby", 421611],
1539
1579
  ]);
1540
1580
 
1541
1581
  var EMPTY = "0x";
@@ -1584,12 +1624,7 @@ var getTransactionDescription = function (fragments, data, value) {
1584
1624
  * @returns flow rate per second
1585
1625
  */
1586
1626
  var getPerSecondFlowRateByYear = function (amountPerYear) {
1587
- return Math.round(Number(amountPerYear) *
1588
- MONTHS_PER_YEAR *
1589
- DAYS_PER_MONTH *
1590
- HOURS_PER_DAY *
1591
- MINUTES_PER_HOUR *
1592
- SECONDS_PER_MINUTE).toString();
1627
+ return Math.round((Number(amountPerYear) / YEAR_IN_SECONDS) * BASE_18).toString();
1593
1628
  };
1594
1629
  /**
1595
1630
  * @dev Gets the per second flow rate given an `amountPerMonth` value.
@@ -1597,11 +1632,15 @@ var getPerSecondFlowRateByYear = function (amountPerYear) {
1597
1632
  * @returns flow rate per second
1598
1633
  */
1599
1634
  var getPerSecondFlowRateByMonth = function (amountPerMonth) {
1600
- return Math.round(Number(amountPerMonth) *
1601
- DAYS_PER_MONTH *
1602
- HOURS_PER_DAY *
1603
- MINUTES_PER_HOUR *
1604
- SECONDS_PER_MINUTE).toString();
1635
+ return Math.round((Number(amountPerMonth) / MONTH_IN_SECONDS) * BASE_18).toString();
1636
+ };
1637
+ /**
1638
+ * @dev Gets the per second flow rate given an `amountPerWeek` value.
1639
+ * @param amountPerWeek the amount you want to stream per Week
1640
+ * @returns flow rate per second
1641
+ */
1642
+ var getPerSecondFlowRateByWeek = function (amountPerWeek) {
1643
+ return Math.round((Number(amountPerWeek) / WEEK_IN_SECONDS) * BASE_18).toString();
1605
1644
  };
1606
1645
  /**
1607
1646
  * @dev Gets the per second flow rate given an `amountPerDay` value.
@@ -1609,10 +1648,21 @@ var getPerSecondFlowRateByMonth = function (amountPerMonth) {
1609
1648
  * @returns flow rate per second
1610
1649
  */
1611
1650
  var getPerSecondFlowRateByDay = function (amountPerDay) {
1612
- return Math.round(Number(amountPerDay) *
1613
- HOURS_PER_DAY *
1614
- MINUTES_PER_HOUR *
1615
- SECONDS_PER_MINUTE).toString();
1651
+ return Math.round((Number(amountPerDay) / DAY_IN_SECONDS) * BASE_18).toString();
1652
+ };
1653
+ /**
1654
+ * @dev Gets daily, weekly, monthly and yearly flowed amounts given a per second flow rate.
1655
+ * @param perSecondFlowRate
1656
+ * @returns
1657
+ */
1658
+ var getFlowAmountByPerSecondFlowRate = function (perSecondFlowRate) {
1659
+ var decimalFlowRate = Number(perSecondFlowRate) / BASE_18;
1660
+ return {
1661
+ daily: Math.round(decimalFlowRate * DAY_IN_SECONDS).toString(),
1662
+ weekly: Math.round(decimalFlowRate * WEEK_IN_SECONDS).toString(),
1663
+ monthly: Math.round(decimalFlowRate * MONTH_IN_SECONDS).toString(),
1664
+ yearly: Math.round(decimalFlowRate * YEAR_IN_SECONDS).toString(),
1665
+ };
1616
1666
  };
1617
1667
  /**
1618
1668
  * @dev The formula for calculating the flowed amount since updated using Subgraph data.
@@ -1717,7 +1767,7 @@ var BatchCall = /** @class */ (function () {
1717
1767
  * @returns {Promise<OperationStruct>} OperationStruct object for batchCall
1718
1768
  */
1719
1769
  this.getOperationStruct = function (operation, index) { return __awaiter(_this, void 0, void 0, function () {
1720
- var operationType, populatedTransaction, functionArgs;
1770
+ var operationType, populatedTransaction, encoder, functionArgs, data;
1721
1771
  return __generator(this, function (_a) {
1722
1772
  switch (_a.label) {
1723
1773
  case 0:
@@ -1742,11 +1792,13 @@ var BatchCall = /** @class */ (function () {
1742
1792
  // The only operation which has a target that is not the
1743
1793
  // same as the to property of the transaction.
1744
1794
  if (operation.type === "SUPERFLUID_CALL_AGREEMENT") {
1795
+ encoder = ethers.utils.defaultAbiCoder;
1745
1796
  functionArgs = this.getCallAgreementFunctionArgs(populatedTransaction.data);
1797
+ data = encoder.encode(["bytes", "bytes"], [functionArgs["callData"], functionArgs["userData"]]);
1746
1798
  return [2 /*return*/, {
1747
1799
  operationType: operationType,
1748
1800
  target: functionArgs["agreementClass"],
1749
- data: functionArgs["callData"],
1801
+ data: data,
1750
1802
  }];
1751
1803
  }
1752
1804
  // Handles other cases which are not call agreeement operation
@@ -7506,4 +7558,4 @@ var Framework = /** @class */ (function () {
7506
7558
  return Framework;
7507
7559
  }());
7508
7560
 
7509
- export { BatchCall, ConstantFlowAgreementV1, Framework, Host, InstantDistributionAgreementV1, Query, SuperToken, createLastIdPaging, createPagedResult, createSkipPaging, flowedAmountSinceUpdatedAt, getBalance, getPerSecondFlowRateByDay, getPerSecondFlowRateByMonth, getPerSecondFlowRateByYear, getSanitizedTimestamp, getStringCurrentTimeInSeconds, getTransactionDescription, isNullOrEmpty, nextLastIdPaging, nextSkipPaging, normalizeAddress, removeSigHashFromCallData, subscriptionTotalAmountClaimableSinceUpdatedAt, subscriptionTotalAmountDistributedSinceUpdated, subscriptionTotalAmountReceivedSinceUpdated, takePlusOne };
7561
+ export { BatchCall, ConstantFlowAgreementV1, Framework, Host, InstantDistributionAgreementV1, Query, SuperToken, createLastIdPaging, createPagedResult, createSkipPaging, flowedAmountSinceUpdatedAt, getBalance, getFlowAmountByPerSecondFlowRate, getPerSecondFlowRateByDay, getPerSecondFlowRateByMonth, getPerSecondFlowRateByWeek, getPerSecondFlowRateByYear, getSanitizedTimestamp, getStringCurrentTimeInSeconds, getTransactionDescription, isNullOrEmpty, nextLastIdPaging, nextSkipPaging, normalizeAddress, removeSigHashFromCallData, subscriptionTotalAmountClaimableSinceUpdatedAt, subscriptionTotalAmountDistributedSinceUpdated, subscriptionTotalAmountReceivedSinceUpdated, takePlusOne };
@@ -34,12 +34,29 @@ export declare const getPerSecondFlowRateByYear: (amountPerYear: string) => stri
34
34
  * @returns flow rate per second
35
35
  */
36
36
  export declare const getPerSecondFlowRateByMonth: (amountPerMonth: string) => string;
37
+ /**
38
+ * @dev Gets the per second flow rate given an `amountPerWeek` value.
39
+ * @param amountPerWeek the amount you want to stream per Week
40
+ * @returns flow rate per second
41
+ */
42
+ export declare const getPerSecondFlowRateByWeek: (amountPerWeek: string) => string;
37
43
  /**
38
44
  * @dev Gets the per second flow rate given an `amountPerDay` value.
39
45
  * @param amountPerDay the amount you want to stream per day
40
46
  * @returns flow rate per second
41
47
  */
42
48
  export declare const getPerSecondFlowRateByDay: (amountPerDay: string) => string;
49
+ /**
50
+ * @dev Gets daily, weekly, monthly and yearly flowed amounts given a per second flow rate.
51
+ * @param perSecondFlowRate
52
+ * @returns
53
+ */
54
+ export declare const getFlowAmountByPerSecondFlowRate: (perSecondFlowRate: string) => {
55
+ daily: string;
56
+ weekly: string;
57
+ monthly: string;
58
+ yearly: string;
59
+ };
43
60
  /**
44
61
  * @dev The formula for calculating the flowed amount since updated using Subgraph data.
45
62
  * @param netFlowRate the net flow rate of the user
@@ -1,9 +1,16 @@
1
1
  import { IResolverData } from "./interfaces";
2
2
  export declare const MONTHS_PER_YEAR = 12;
3
3
  export declare const DAYS_PER_MONTH = 30;
4
+ export declare const DAYS_PER_WEEK = 7;
4
5
  export declare const HOURS_PER_DAY = 24;
5
6
  export declare const MINUTES_PER_HOUR = 60;
6
- export declare const SECONDS_PER_MINUTE = 60;
7
+ export declare const MINUTE_IN_SECONDS = 60;
8
+ export declare const HOUR_IN_SECONDS: number;
9
+ export declare const DAY_IN_SECONDS: number;
10
+ export declare const WEEK_IN_SECONDS: number;
11
+ export declare const MONTH_IN_SECONDS: number;
12
+ export declare const YEAR_IN_SECONDS: number;
13
+ export declare const BASE_18 = 10000000000000000000;
7
14
  export declare const chainIds: number[];
8
15
  export declare const networkNames: string[];
9
16
  export declare const chainIdToDataMap: Map<number, IResolverData>;
package/dist/umd/index.js CHANGED
@@ -1455,17 +1455,27 @@
1455
1455
 
1456
1456
  var MONTHS_PER_YEAR = 12;
1457
1457
  var DAYS_PER_MONTH = 30;
1458
+ var DAYS_PER_WEEK = 7;
1458
1459
  var HOURS_PER_DAY = 24;
1459
1460
  var MINUTES_PER_HOUR = 60;
1460
- var SECONDS_PER_MINUTE = 60;
1461
+ var MINUTE_IN_SECONDS = 60;
1462
+ var HOUR_IN_SECONDS = MINUTE_IN_SECONDS * MINUTES_PER_HOUR;
1463
+ var DAY_IN_SECONDS = HOUR_IN_SECONDS * HOURS_PER_DAY;
1464
+ var WEEK_IN_SECONDS = DAY_IN_SECONDS * DAYS_PER_WEEK;
1465
+ var MONTH_IN_SECONDS = DAY_IN_SECONDS * DAYS_PER_MONTH;
1466
+ var YEAR_IN_SECONDS = MONTH_IN_SECONDS * MONTHS_PER_YEAR; // NOTE: Is 360 days (misses 5-6 days)
1467
+ var BASE_18 = 10e18;
1461
1468
  var chainIds = [
1462
1469
  3,
1463
1470
  4,
1464
1471
  5,
1465
1472
  42,
1473
+ 69,
1466
1474
  100,
1467
1475
  137,
1468
- 80001, // MUMBAI
1476
+ 43113,
1477
+ 80001,
1478
+ 421611, // ARBITRUM RINKEBY
1469
1479
  ];
1470
1480
  var networkNames = [
1471
1481
  "ropsten",
@@ -1475,6 +1485,9 @@
1475
1485
  "xdai",
1476
1486
  "matic",
1477
1487
  "mumbai",
1488
+ "optimism-kovan",
1489
+ "arbitrium-rinkeby",
1490
+ "avalanche-fuji",
1478
1491
  ];
1479
1492
  var chainIdToDataMap = new Map([
1480
1493
  [
@@ -1509,6 +1522,14 @@
1509
1522
  resolverAddress: "0x851d3dd9dc97c1df1DA73467449B3893fc76D85B",
1510
1523
  },
1511
1524
  ],
1525
+ [
1526
+ 69,
1527
+ {
1528
+ subgraphAPIEndpoint: "https://api.thegraph.com/subgraphs/name/superfluid-finance/protocol-dev-optimism-kovan",
1529
+ networkName: "optimism-kovan",
1530
+ resolverAddress: "0x218B65780615Ff134f9Ad810CB98839534D3C0D6",
1531
+ },
1532
+ ],
1512
1533
  [
1513
1534
  100,
1514
1535
  {
@@ -1525,6 +1546,14 @@
1525
1546
  resolverAddress: "0xE0cc76334405EE8b39213E620587d815967af39C",
1526
1547
  },
1527
1548
  ],
1549
+ [
1550
+ 43113,
1551
+ {
1552
+ subgraphAPIEndpoint: "https://api.thegraph.com/subgraphs/name/superfluid-finance/protocol-dev-avalanche-fuji",
1553
+ networkName: "avalanche-fuji",
1554
+ resolverAddress: "0xb76d7c14caD40Cc434655Ce0a9B5b49220C362cA",
1555
+ },
1556
+ ],
1528
1557
  [
1529
1558
  80001,
1530
1559
  {
@@ -1533,15 +1562,26 @@
1533
1562
  resolverAddress: "0x8C54C83FbDe3C59e59dd6E324531FB93d4F504d3",
1534
1563
  },
1535
1564
  ],
1565
+ [
1566
+ 421611,
1567
+ {
1568
+ subgraphAPIEndpoint: "https://api.thegraph.com/subgraphs/name/superfluid-finance/protocol-dev-arbitrum-rinkeby",
1569
+ networkName: "arbitrum-rinkeby",
1570
+ resolverAddress: "0xa2C0C70A1E922f5f060ec20EE3aF002C163b4567",
1571
+ },
1572
+ ],
1536
1573
  ]);
1537
1574
  var networkNameToChainIdMap = new Map([
1538
1575
  ["ropsten", 3],
1539
1576
  ["rinkeby", 4],
1540
1577
  ["goerli", 5],
1541
1578
  ["kovan", 42],
1579
+ ["optimism-kovan", 69],
1542
1580
  ["xdai", 100],
1543
1581
  ["matic", 137],
1582
+ ["avalanche-fuji", 43113],
1544
1583
  ["mumbai", 80001],
1584
+ ["arbitrum-rinkeby", 421611],
1545
1585
  ]);
1546
1586
 
1547
1587
  var EMPTY = "0x";
@@ -1590,12 +1630,7 @@
1590
1630
  * @returns flow rate per second
1591
1631
  */
1592
1632
  var getPerSecondFlowRateByYear = function (amountPerYear) {
1593
- return Math.round(Number(amountPerYear) *
1594
- MONTHS_PER_YEAR *
1595
- DAYS_PER_MONTH *
1596
- HOURS_PER_DAY *
1597
- MINUTES_PER_HOUR *
1598
- SECONDS_PER_MINUTE).toString();
1633
+ return Math.round((Number(amountPerYear) / YEAR_IN_SECONDS) * BASE_18).toString();
1599
1634
  };
1600
1635
  /**
1601
1636
  * @dev Gets the per second flow rate given an `amountPerMonth` value.
@@ -1603,11 +1638,15 @@
1603
1638
  * @returns flow rate per second
1604
1639
  */
1605
1640
  var getPerSecondFlowRateByMonth = function (amountPerMonth) {
1606
- return Math.round(Number(amountPerMonth) *
1607
- DAYS_PER_MONTH *
1608
- HOURS_PER_DAY *
1609
- MINUTES_PER_HOUR *
1610
- SECONDS_PER_MINUTE).toString();
1641
+ return Math.round((Number(amountPerMonth) / MONTH_IN_SECONDS) * BASE_18).toString();
1642
+ };
1643
+ /**
1644
+ * @dev Gets the per second flow rate given an `amountPerWeek` value.
1645
+ * @param amountPerWeek the amount you want to stream per Week
1646
+ * @returns flow rate per second
1647
+ */
1648
+ var getPerSecondFlowRateByWeek = function (amountPerWeek) {
1649
+ return Math.round((Number(amountPerWeek) / WEEK_IN_SECONDS) * BASE_18).toString();
1611
1650
  };
1612
1651
  /**
1613
1652
  * @dev Gets the per second flow rate given an `amountPerDay` value.
@@ -1615,10 +1654,21 @@
1615
1654
  * @returns flow rate per second
1616
1655
  */
1617
1656
  var getPerSecondFlowRateByDay = function (amountPerDay) {
1618
- return Math.round(Number(amountPerDay) *
1619
- HOURS_PER_DAY *
1620
- MINUTES_PER_HOUR *
1621
- SECONDS_PER_MINUTE).toString();
1657
+ return Math.round((Number(amountPerDay) / DAY_IN_SECONDS) * BASE_18).toString();
1658
+ };
1659
+ /**
1660
+ * @dev Gets daily, weekly, monthly and yearly flowed amounts given a per second flow rate.
1661
+ * @param perSecondFlowRate
1662
+ * @returns
1663
+ */
1664
+ var getFlowAmountByPerSecondFlowRate = function (perSecondFlowRate) {
1665
+ var decimalFlowRate = Number(perSecondFlowRate) / BASE_18;
1666
+ return {
1667
+ daily: Math.round(decimalFlowRate * DAY_IN_SECONDS).toString(),
1668
+ weekly: Math.round(decimalFlowRate * WEEK_IN_SECONDS).toString(),
1669
+ monthly: Math.round(decimalFlowRate * MONTH_IN_SECONDS).toString(),
1670
+ yearly: Math.round(decimalFlowRate * YEAR_IN_SECONDS).toString(),
1671
+ };
1622
1672
  };
1623
1673
  /**
1624
1674
  * @dev The formula for calculating the flowed amount since updated using Subgraph data.
@@ -1723,7 +1773,7 @@
1723
1773
  * @returns {Promise<OperationStruct>} OperationStruct object for batchCall
1724
1774
  */
1725
1775
  this.getOperationStruct = function (operation, index) { return __awaiter(_this, void 0, void 0, function () {
1726
- var operationType, populatedTransaction, functionArgs;
1776
+ var operationType, populatedTransaction, encoder, functionArgs, data;
1727
1777
  return __generator(this, function (_a) {
1728
1778
  switch (_a.label) {
1729
1779
  case 0:
@@ -1748,11 +1798,13 @@
1748
1798
  // The only operation which has a target that is not the
1749
1799
  // same as the to property of the transaction.
1750
1800
  if (operation.type === "SUPERFLUID_CALL_AGREEMENT") {
1801
+ encoder = ethers.ethers.utils.defaultAbiCoder;
1751
1802
  functionArgs = this.getCallAgreementFunctionArgs(populatedTransaction.data);
1803
+ data = encoder.encode(["bytes", "bytes"], [functionArgs["callData"], functionArgs["userData"]]);
1752
1804
  return [2 /*return*/, {
1753
1805
  operationType: operationType,
1754
1806
  target: functionArgs["agreementClass"],
1755
- data: functionArgs["callData"],
1807
+ data: data,
1756
1808
  }];
1757
1809
  }
1758
1810
  // Handles other cases which are not call agreeement operation
@@ -7524,8 +7576,10 @@
7524
7576
  exports.createSkipPaging = createSkipPaging;
7525
7577
  exports.flowedAmountSinceUpdatedAt = flowedAmountSinceUpdatedAt;
7526
7578
  exports.getBalance = getBalance;
7579
+ exports.getFlowAmountByPerSecondFlowRate = getFlowAmountByPerSecondFlowRate;
7527
7580
  exports.getPerSecondFlowRateByDay = getPerSecondFlowRateByDay;
7528
7581
  exports.getPerSecondFlowRateByMonth = getPerSecondFlowRateByMonth;
7582
+ exports.getPerSecondFlowRateByWeek = getPerSecondFlowRateByWeek;
7529
7583
  exports.getPerSecondFlowRateByYear = getPerSecondFlowRateByYear;
7530
7584
  exports.getSanitizedTimestamp = getSanitizedTimestamp;
7531
7585
  exports.getStringCurrentTimeInSeconds = getStringCurrentTimeInSeconds;
@@ -34,12 +34,29 @@ export declare const getPerSecondFlowRateByYear: (amountPerYear: string) => stri
34
34
  * @returns flow rate per second
35
35
  */
36
36
  export declare const getPerSecondFlowRateByMonth: (amountPerMonth: string) => string;
37
+ /**
38
+ * @dev Gets the per second flow rate given an `amountPerWeek` value.
39
+ * @param amountPerWeek the amount you want to stream per Week
40
+ * @returns flow rate per second
41
+ */
42
+ export declare const getPerSecondFlowRateByWeek: (amountPerWeek: string) => string;
37
43
  /**
38
44
  * @dev Gets the per second flow rate given an `amountPerDay` value.
39
45
  * @param amountPerDay the amount you want to stream per day
40
46
  * @returns flow rate per second
41
47
  */
42
48
  export declare const getPerSecondFlowRateByDay: (amountPerDay: string) => string;
49
+ /**
50
+ * @dev Gets daily, weekly, monthly and yearly flowed amounts given a per second flow rate.
51
+ * @param perSecondFlowRate
52
+ * @returns
53
+ */
54
+ export declare const getFlowAmountByPerSecondFlowRate: (perSecondFlowRate: string) => {
55
+ daily: string;
56
+ weekly: string;
57
+ monthly: string;
58
+ yearly: string;
59
+ };
43
60
  /**
44
61
  * @dev The formula for calculating the flowed amount since updated using Subgraph data.
45
62
  * @param netFlowRate the net flow rate of the user
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superfluid-finance/sdk-core",
3
- "version": "0.1.1-dev.7bfb2dd.0",
3
+ "version": "0.1.1-dev.8caff13.0",
4
4
  "description": "SDK Core for building with Superfluid Protocol",
5
5
  "homepage": "https://github.com/superfluid-finance/protocol-monorepo/tree/dev/packages/sdk-core#readme",
6
6
  "repository": "github:superfluid-finance/protocol-monorepo",