@superfluid-finance/sdk-core 1.0.1-dev.65e7bb4.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/LICENSE +9 -0
- package/README.md +487 -0
- package/dist/main/BatchCall.d.ts +53 -0
- package/dist/main/ConstantFlowAgreementV1.d.ts +74 -0
- package/dist/main/Framework.d.ts +75 -0
- package/dist/main/Host.d.ts +18 -0
- package/dist/main/InstantDistributionAgreementV1.d.ts +107 -0
- package/dist/main/Operation.d.ts +38 -0
- package/dist/main/Query.d.ts +24 -0
- package/dist/main/SFError.d.ts +13 -0
- package/dist/main/SuperToken.d.ts +191 -0
- package/dist/main/Token.d.ts +76 -0
- package/dist/main/constants.d.ts +10 -0
- package/dist/main/events.d.ts +254 -0
- package/dist/main/frameworkHelpers.d.ts +20 -0
- package/dist/main/index.d.ts +19 -0
- package/dist/main/index.js +10780 -0
- package/dist/main/interfaces.d.ts +309 -0
- package/dist/main/mapGetAllEventsQueryEvents.d.ts +3 -0
- package/dist/main/pagination.d.ts +31 -0
- package/dist/main/scripts/setup.d.ts +22 -0
- package/dist/main/subgraph/SubgraphClient.d.ts +16 -0
- package/dist/main/subgraph/queries/getAccountTokenSnapshots.generated.d.ts +41 -0
- package/dist/main/subgraph/queries/getAllEvents.generated.d.ts +578 -0
- package/dist/main/subgraph/queries/getIndexSubscriptions.generated.d.ts +42 -0
- package/dist/main/subgraph/queries/getIndexes.generated.d.ts +40 -0
- package/dist/main/subgraph/queries/getStreams.generated.d.ts +54 -0
- package/dist/main/subgraph/queries/getTokens.generated.d.ts +23 -0
- package/dist/main/subgraph/schema.generated.d.ts +6907 -0
- package/dist/main/typechain/ERC20WithTokenInfo.d.ts +159 -0
- package/dist/main/typechain/IConstantFlowAgreementV1.d.ts +305 -0
- package/dist/main/typechain/IInstantDistributionAgreementV1.d.ts +585 -0
- package/dist/main/typechain/IResolver.d.ts +57 -0
- package/dist/main/typechain/SuperToken.d.ts +1011 -0
- package/dist/main/typechain/Superfluid.d.ts +780 -0
- package/dist/main/typechain/SuperfluidLoader.d.ts +55 -0
- package/dist/main/typechain/TestToken.d.ts +207 -0
- package/dist/main/typechain/common.d.ts +21 -0
- package/dist/main/typechain/factories/ERC20WithTokenInfo__factory.d.ts +35 -0
- package/dist/main/typechain/factories/IConstantFlowAgreementV1__factory.d.ts +35 -0
- package/dist/main/typechain/factories/IInstantDistributionAgreementV1__factory.d.ts +35 -0
- package/dist/main/typechain/factories/IResolver__factory.d.ts +22 -0
- package/dist/main/typechain/factories/SuperToken__factory.d.ts +46 -0
- package/dist/main/typechain/factories/SuperfluidLoader__factory.d.ts +37 -0
- package/dist/main/typechain/factories/Superfluid__factory.d.ts +82 -0
- package/dist/main/typechain/factories/TestToken__factory.d.ts +46 -0
- package/dist/main/typechain/index.d.ts +16 -0
- package/dist/main/types.d.ts +2 -0
- package/dist/main/utils.d.ts +89 -0
- package/dist/main/validation.d.ts +8 -0
- package/dist/module/BatchCall.d.ts +53 -0
- package/dist/module/ConstantFlowAgreementV1.d.ts +74 -0
- package/dist/module/Framework.d.ts +75 -0
- package/dist/module/Host.d.ts +18 -0
- package/dist/module/InstantDistributionAgreementV1.d.ts +107 -0
- package/dist/module/Operation.d.ts +38 -0
- package/dist/module/Query.d.ts +24 -0
- package/dist/module/SFError.d.ts +13 -0
- package/dist/module/SuperToken.d.ts +191 -0
- package/dist/module/Token.d.ts +76 -0
- package/dist/module/constants.d.ts +10 -0
- package/dist/module/events.d.ts +254 -0
- package/dist/module/frameworkHelpers.d.ts +20 -0
- package/dist/module/index.d.ts +19 -0
- package/dist/module/index.js +10749 -0
- package/dist/module/interfaces.d.ts +309 -0
- package/dist/module/mapGetAllEventsQueryEvents.d.ts +3 -0
- package/dist/module/pagination.d.ts +31 -0
- package/dist/module/scripts/setup.d.ts +22 -0
- package/dist/module/subgraph/SubgraphClient.d.ts +16 -0
- package/dist/module/subgraph/queries/getAccountTokenSnapshots.generated.d.ts +41 -0
- package/dist/module/subgraph/queries/getAllEvents.generated.d.ts +578 -0
- package/dist/module/subgraph/queries/getIndexSubscriptions.generated.d.ts +42 -0
- package/dist/module/subgraph/queries/getIndexes.generated.d.ts +40 -0
- package/dist/module/subgraph/queries/getStreams.generated.d.ts +54 -0
- package/dist/module/subgraph/queries/getTokens.generated.d.ts +23 -0
- package/dist/module/subgraph/schema.generated.d.ts +6907 -0
- package/dist/module/typechain/ERC20WithTokenInfo.d.ts +159 -0
- package/dist/module/typechain/IConstantFlowAgreementV1.d.ts +305 -0
- package/dist/module/typechain/IInstantDistributionAgreementV1.d.ts +585 -0
- package/dist/module/typechain/IResolver.d.ts +57 -0
- package/dist/module/typechain/SuperToken.d.ts +1011 -0
- package/dist/module/typechain/Superfluid.d.ts +780 -0
- package/dist/module/typechain/SuperfluidLoader.d.ts +55 -0
- package/dist/module/typechain/TestToken.d.ts +207 -0
- package/dist/module/typechain/common.d.ts +21 -0
- package/dist/module/typechain/factories/ERC20WithTokenInfo__factory.d.ts +35 -0
- package/dist/module/typechain/factories/IConstantFlowAgreementV1__factory.d.ts +35 -0
- package/dist/module/typechain/factories/IInstantDistributionAgreementV1__factory.d.ts +35 -0
- package/dist/module/typechain/factories/IResolver__factory.d.ts +22 -0
- package/dist/module/typechain/factories/SuperToken__factory.d.ts +46 -0
- package/dist/module/typechain/factories/SuperfluidLoader__factory.d.ts +37 -0
- package/dist/module/typechain/factories/Superfluid__factory.d.ts +82 -0
- package/dist/module/typechain/factories/TestToken__factory.d.ts +46 -0
- package/dist/module/typechain/index.d.ts +16 -0
- package/dist/module/types.d.ts +2 -0
- package/dist/module/utils.d.ts +89 -0
- package/dist/module/validation.d.ts +8 -0
- package/dist/umd/BatchCall.d.ts +53 -0
- package/dist/umd/ConstantFlowAgreementV1.d.ts +74 -0
- package/dist/umd/Framework.d.ts +75 -0
- package/dist/umd/Host.d.ts +18 -0
- package/dist/umd/InstantDistributionAgreementV1.d.ts +107 -0
- package/dist/umd/Operation.d.ts +38 -0
- package/dist/umd/Query.d.ts +24 -0
- package/dist/umd/SFError.d.ts +13 -0
- package/dist/umd/SuperToken.d.ts +191 -0
- package/dist/umd/Token.d.ts +76 -0
- package/dist/umd/constants.d.ts +10 -0
- package/dist/umd/events.d.ts +254 -0
- package/dist/umd/frameworkHelpers.d.ts +20 -0
- package/dist/umd/index.d.ts +19 -0
- package/dist/umd/index.js +10782 -0
- package/dist/umd/interfaces.d.ts +309 -0
- package/dist/umd/mapGetAllEventsQueryEvents.d.ts +3 -0
- package/dist/umd/pagination.d.ts +31 -0
- package/dist/umd/scripts/setup.d.ts +22 -0
- package/dist/umd/subgraph/SubgraphClient.d.ts +16 -0
- package/dist/umd/subgraph/queries/getAccountTokenSnapshots.generated.d.ts +41 -0
- package/dist/umd/subgraph/queries/getAllEvents.generated.d.ts +578 -0
- package/dist/umd/subgraph/queries/getIndexSubscriptions.generated.d.ts +42 -0
- package/dist/umd/subgraph/queries/getIndexes.generated.d.ts +40 -0
- package/dist/umd/subgraph/queries/getStreams.generated.d.ts +54 -0
- package/dist/umd/subgraph/queries/getTokens.generated.d.ts +23 -0
- package/dist/umd/subgraph/schema.generated.d.ts +6907 -0
- package/dist/umd/typechain/ERC20WithTokenInfo.d.ts +159 -0
- package/dist/umd/typechain/IConstantFlowAgreementV1.d.ts +305 -0
- package/dist/umd/typechain/IInstantDistributionAgreementV1.d.ts +585 -0
- package/dist/umd/typechain/IResolver.d.ts +57 -0
- package/dist/umd/typechain/SuperToken.d.ts +1011 -0
- package/dist/umd/typechain/Superfluid.d.ts +780 -0
- package/dist/umd/typechain/SuperfluidLoader.d.ts +55 -0
- package/dist/umd/typechain/TestToken.d.ts +207 -0
- package/dist/umd/typechain/common.d.ts +21 -0
- package/dist/umd/typechain/factories/ERC20WithTokenInfo__factory.d.ts +35 -0
- package/dist/umd/typechain/factories/IConstantFlowAgreementV1__factory.d.ts +35 -0
- package/dist/umd/typechain/factories/IInstantDistributionAgreementV1__factory.d.ts +35 -0
- package/dist/umd/typechain/factories/IResolver__factory.d.ts +22 -0
- package/dist/umd/typechain/factories/SuperToken__factory.d.ts +46 -0
- package/dist/umd/typechain/factories/SuperfluidLoader__factory.d.ts +37 -0
- package/dist/umd/typechain/factories/Superfluid__factory.d.ts +82 -0
- package/dist/umd/typechain/factories/TestToken__factory.d.ts +46 -0
- package/dist/umd/typechain/index.d.ts +16 -0
- package/dist/umd/types.d.ts +2 -0
- package/dist/umd/utils.d.ts +89 -0
- package/dist/umd/validation.d.ts +8 -0
- package/package.json +76 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright © 2021 Superfluid Finance Ltd
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
<h1 align="center">sdk-core</h1>
|
|
2
|
+
<div align="center">
|
|
3
|
+
<img width="300" padding="0 0 10px" alt="Superfluid logo" src="/sf-logo.png" />
|
|
4
|
+
<p>
|
|
5
|
+
<a href="https://www.npmjs.com/package/@superfluid-finance/sdk-core" target="_blank">
|
|
6
|
+
<img alt="Version" src="https://img.shields.io/npm/v/@superfluid-finance/sdk-core.svg">
|
|
7
|
+
</a>
|
|
8
|
+
<a href="https://codecov.io/gh/superfluid-finance/protocol-monorepo">
|
|
9
|
+
<img src="https://codecov.io/gh/superfluid-finance/protocol-monorepo/branch/dev/graph/badge.svg?token=LJW5NDGEJ9?flag=sdk-core"/>
|
|
10
|
+
</a>
|
|
11
|
+
<a href="#" target="_blank">
|
|
12
|
+
<img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg" />
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://twitter.com/Superfluid_HQ/" target="blank">
|
|
15
|
+
<img alt="Twitter: Superfluid_HQ" src="https://img.shields.io/twitter/follow/Superfluid_HQ.svg?style=social" />
|
|
16
|
+
</a>
|
|
17
|
+
</p>
|
|
18
|
+
</div>
|
|
19
|
+
|
|
20
|
+
### 🏠 [Homepage](https://superfluid.finance)
|
|
21
|
+
|
|
22
|
+
### ✨ [Superfluid App](https://app.superfluid.finance/)
|
|
23
|
+
|
|
24
|
+
### 📖 [Docs](https://docs.superfluid.finance)
|
|
25
|
+
|
|
26
|
+
# Prerequisites
|
|
27
|
+
|
|
28
|
+
To get the package up and running you'll need to install the necessary dependencies and build the project:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
yarn install && yarn build
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
# Usage
|
|
35
|
+
|
|
36
|
+
## Framework Initialization
|
|
37
|
+
|
|
38
|
+
Here is a quick look at initialzing the SDK in different environments:
|
|
39
|
+
|
|
40
|
+
TypeScript / JavaScript (Module):
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { Framework } from "@superfluid-finance/sdk-core";
|
|
44
|
+
import { ethers } from "ethers";
|
|
45
|
+
|
|
46
|
+
const provider = new ethers.providers.InfuraProvider(
|
|
47
|
+
"matic",
|
|
48
|
+
"<INFURA_API_KEY>"
|
|
49
|
+
);
|
|
50
|
+
const sf = await Framework.create({
|
|
51
|
+
networkName: "matic",
|
|
52
|
+
provider
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// web3.js + Hardhat provider initialization
|
|
56
|
+
const web3jsProvider = new ethers.providers.Web3Provider(
|
|
57
|
+
(global as any).web3.currentProvider
|
|
58
|
+
);
|
|
59
|
+
const web3jsSf = await Framework.create({
|
|
60
|
+
networkName: "matic",
|
|
61
|
+
provider: web3jsProvider
|
|
62
|
+
});
|
|
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
|
+
|
|
71
|
+
const provider = new ethers.providers.InfuraProvider(
|
|
72
|
+
"matic",
|
|
73
|
+
"<INFURA_API_KEY>"
|
|
74
|
+
);
|
|
75
|
+
const sf = await Framework.create({
|
|
76
|
+
networkName: "matic",
|
|
77
|
+
provider
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// web3.js + Hardhat provider initialization
|
|
81
|
+
const web3jsProvider = new ethers.providers.Web3Provider(
|
|
82
|
+
global.web3.currentProvider
|
|
83
|
+
);
|
|
84
|
+
const web3jsSf = await Framework.create({
|
|
85
|
+
networkName: "matic",
|
|
86
|
+
provider: web3jsProvider
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
> Note: You specify your project type in `package.json` - `"type": "module"` or `"type": "commonjs"`.
|
|
91
|
+
|
|
92
|
+
This is the absolute minimum you need to provide the constructor (`chainId` or `networkName` and a `provider` object) if all you want to do are read operations. It is also important to note that the provider does not need to be an InfuraProvider - it just needs to satisfy the `ethers.Provider` interface.
|
|
93
|
+
|
|
94
|
+
## Helper Classes
|
|
95
|
+
|
|
96
|
+
The `Framework` includes a variety of helper classes which can be directly accessed upon initialization, but can also be initialized as standalone classes if desired.
|
|
97
|
+
|
|
98
|
+
### Query
|
|
99
|
+
|
|
100
|
+
Once you have initialized the `Framework` class using `Framework.create`, you can make queries using it easily.
|
|
101
|
+
|
|
102
|
+
#### Pre-Defined Queries
|
|
103
|
+
|
|
104
|
+
A list of the pre-defined queries:
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
const { Framework } = require("@superfluid-finance/sdk-core");
|
|
108
|
+
const { ethers } = require("ethers");
|
|
109
|
+
|
|
110
|
+
const provider = new ethers.providers.InfuraProvider(
|
|
111
|
+
"matic",
|
|
112
|
+
"<INFURA_API_KEY>"
|
|
113
|
+
);
|
|
114
|
+
const sf = await Framework.create({
|
|
115
|
+
networkName: "matic",
|
|
116
|
+
provider
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const pageResult = await sf.query.
|
|
120
|
+
listAllSuperTokens({ isListed?: boolean }, { skip: number, take: number });
|
|
121
|
+
listIndexes({ indexId?: string, publisher?: string, token?: string }, { skip: number, take: number });
|
|
122
|
+
listIndexSubscriptions({ subscriber?: string, approved?: boolean }, { skip: number, take: number });
|
|
123
|
+
listStreams({ sender?: string, receiver?: string, token?: string }, { skip: number, take: number });
|
|
124
|
+
listUserInteractedSuperTokens({ account?: string, token?: string }, { skip: number, take: number });
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
#### Direct Initialization
|
|
128
|
+
|
|
129
|
+
If you'd like, you can also initialize the `Query` class as a standalone class like so:
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
import { Query } from "@superfluid-finance/sdk-core";
|
|
133
|
+
const query = new Query({ customSubgraphQueriesEndpoint: "<A_CUSTOM_ENDPOINT>", dataMode: "SUBGRAPH_ONLY" | "SUBGRAPH_WEB3" | "WEB3_ONLY" });
|
|
134
|
+
query.listAllSuperTokens({ isListed?: boolean }, { skip: number, take: number })
|
|
135
|
+
//...same queries as above...
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
#### Pagination
|
|
139
|
+
|
|
140
|
+
All of the pre-defined query functions will accept pagination options: `({ skip: number, take: number })`, if you don't pass anything in, it will use a default of: `{ skip: 0, take: 100 }`.
|
|
141
|
+
|
|
142
|
+
> Note: this example uses the `graphql-request` library, but you just need to provide a valid query which is a string.
|
|
143
|
+
|
|
144
|
+
### Creating a Signer
|
|
145
|
+
|
|
146
|
+
In order to execute a transaction on the blockchain, you need to have a signer. That is, you need to have access to an EOA (Externally Owned Account) to trigger any sort of change. You can do this through a contract, but an EOA still has to be the one which triggers the contract to interact with another contract. The signer that is returned will be passed when executing transactions.
|
|
147
|
+
|
|
148
|
+
#### Web3Provider Signer Example
|
|
149
|
+
|
|
150
|
+
Below is an example of using the `Web3Provider` object to create a signer. This will likely be the way that most client-side applications create a signer.
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
import { Framework } from "@superfluid-finance/sdk-core";
|
|
154
|
+
import Web3Modal from "web3modal";
|
|
155
|
+
import { Web3Provider } from "@ethersproject/providers";
|
|
156
|
+
|
|
157
|
+
// web3Modal example
|
|
158
|
+
const web3ModalRawProvider = await web3Modal.connect();
|
|
159
|
+
const web3ModalProvider = new Web3Provider(web3ModalRawProvider, "any");
|
|
160
|
+
|
|
161
|
+
const sf = await Framework.create({
|
|
162
|
+
networkName: "matic",
|
|
163
|
+
provider: web3ModalProvider,
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const web3ModalSigner = sf.createSigner(web3ModalProvider);
|
|
167
|
+
|
|
168
|
+
// MetaMask example
|
|
169
|
+
const metamaskProvider = new Web3Provider(window.ethereum);
|
|
170
|
+
const metaMaskSigner = sf.createSigner(metamaskProvider);
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
#### Hardhat Signer Example
|
|
174
|
+
|
|
175
|
+
Below is an example of creating a signer in a `Hardhat` + `ethers.js` environment. This will likely be the way that the `sdk-core` is used in a testing environment.
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
import { Framework } from "@superfluid-finance/sdk-core";
|
|
179
|
+
import { ethers } from "hardhat";
|
|
180
|
+
|
|
181
|
+
const sf = await Framework.create({
|
|
182
|
+
networkName: "matic",
|
|
183
|
+
provider: ethers.provider,
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const signer = sf.createSigner({
|
|
187
|
+
privateKey: "<TEST_ACCOUNT_PRIVATE_KEY>",
|
|
188
|
+
provider: ethers.provider,
|
|
189
|
+
});
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
#### Signer/Wallet Example
|
|
193
|
+
|
|
194
|
+
Below is an example of creating a signer passing in a signer object (this can be a wallet for example). This will likely be the way that the `sdk-core` is used in a Node.js environment (back-end) or a testing environment.
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
import { Framework } from "@superfluid-finance/sdk-core";
|
|
198
|
+
import { ethers } from "ethers";
|
|
199
|
+
|
|
200
|
+
const provider = new ethers.providers.InfuraProvider(
|
|
201
|
+
"matic",
|
|
202
|
+
"<INFURA_API_KEY>"
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
const wallet = new ethers.Wallet(
|
|
206
|
+
"cf2bea4c6aad8dbc387d5dd68bf408999b0b1ee949e04ff1d96dd60bc3553a49",
|
|
207
|
+
provider
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
const sf = await Framework.create({
|
|
211
|
+
networkName: "matic",
|
|
212
|
+
provider,
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
const signer = sf.createSigner({
|
|
216
|
+
signer: wallet
|
|
217
|
+
});
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Operation
|
|
221
|
+
|
|
222
|
+
The `Operation` class is an object that is returned after you execute a contract call from this package - instead of immediately executing, we return the `Operation` class which can be either executed to broadcast the transaction or used to create and execute a `BatchCall`.
|
|
223
|
+
|
|
224
|
+
#### Usage
|
|
225
|
+
|
|
226
|
+
```ts
|
|
227
|
+
import { Framework } from "@superfluid-finance/sdk-core";
|
|
228
|
+
import { ethers } from "ethers";
|
|
229
|
+
|
|
230
|
+
const provider = new ethers.providers.InfuraProvider(
|
|
231
|
+
"matic",
|
|
232
|
+
"<INFURA_API_KEY>"
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
const sf = await Framework.create({
|
|
236
|
+
networkName: "matic",
|
|
237
|
+
provider
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// create a signer
|
|
241
|
+
const signer = sf.createSigner({ privateKey: "<TEST_ACCOUNT_PRIVATE_KEY>", provider });
|
|
242
|
+
|
|
243
|
+
// load the usdcx SuperToken via the Framework
|
|
244
|
+
const usdcx = sf.loadToken("0xCAa7349CEA390F89641fe306D93591f87595dc1F");
|
|
245
|
+
|
|
246
|
+
// create an approve operation
|
|
247
|
+
const approveOperation = usdcx.approve("0xab...", ethers.utils.parseUnits("100"));
|
|
248
|
+
|
|
249
|
+
// execute the approve operation, passing in a signer
|
|
250
|
+
const txn = await approveOperation.exec(signer);
|
|
251
|
+
|
|
252
|
+
// wait for the transaction to be confirmed
|
|
253
|
+
const receipt = await txn.wait();
|
|
254
|
+
|
|
255
|
+
// or you can create and execute the transaction in a single line
|
|
256
|
+
const approveTxn = await usdcx.approve("0xab...", ethers.utils.parseUnits("100")).exec(signer);
|
|
257
|
+
const approveTxnReceipt = await approveTxn.wait();
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### ConstantFlowAgreementV1
|
|
261
|
+
|
|
262
|
+
The `ConstantFlowAgreementV1` helper class provides access to create/update/delete flows. You can access this via the `Framework` class (`sf.cfaV1`) or initialize this as a standalone class.
|
|
263
|
+
|
|
264
|
+
#### Direct Initialization
|
|
265
|
+
|
|
266
|
+
```ts
|
|
267
|
+
import { ConstantFlowAgreementV1 } from "@superfluid-finance/sdk-core";
|
|
268
|
+
|
|
269
|
+
const config = {
|
|
270
|
+
hostAddress: "0x3E14dC1b13c488a8d5D310918780c983bD5982E7",
|
|
271
|
+
superTokenFactoryAddress: "0x2C90719f25B10Fc5646c82DA3240C76Fa5BcCF34",
|
|
272
|
+
cfaV1Address: "0x6EeE6060f715257b970700bc2656De21dEdF074C",
|
|
273
|
+
idaV1Address: "0xB0aABBA4B2783A72C52956CDEF62d438ecA2d7a1"
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
const cfaV1 = new ConstantFlowAgreementV1({ options: config });
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
#### CFAV1 Functions
|
|
280
|
+
```ts
|
|
281
|
+
// read
|
|
282
|
+
await sf.cfaV1.getFlow({ superToken: string, sender: string, receiver: string, providerOrSigner: ethers.providers.Provider | ethers.Signer });
|
|
283
|
+
await sf.cfaV1.getAccountFlowInfo({ superToken: string, account: string, providerOrSigner: ethers.providers.Provider | ethers.Signer });
|
|
284
|
+
await sf.cfaV1.getNetFlow({ superToken: string, account: string, providerOrSigner: ethers.providers.Provider | ethers.Signer });
|
|
285
|
+
|
|
286
|
+
// write
|
|
287
|
+
await sf.cfaV1.createFlow({ sender: string, receiver: string, token: string, flowRate: string, userData?: string });
|
|
288
|
+
await sf.cfaV1.updateFlow({ sender: string, receiver: string, token: string, flowRate: string, userData?: string });
|
|
289
|
+
await sf.cfaV1.deleteFlow({ sender: string, receiver: string, token: string, userData?: string });
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### InstantDistributionAgreementV1
|
|
293
|
+
|
|
294
|
+
The `InstantDistributionAgreementV1` helper class provides access to a variety of IDA functions. You can access this via the `Framework` class (`sf.idaV1`) or initialize this as a standalone class.
|
|
295
|
+
|
|
296
|
+
#### Direct Initialization
|
|
297
|
+
|
|
298
|
+
```ts
|
|
299
|
+
import { InstantDistributionAgreementV1 } from "@superfluid-finance/sdk-core";
|
|
300
|
+
|
|
301
|
+
const config = {
|
|
302
|
+
hostAddress: "0x3E14dC1b13c488a8d5D310918780c983bD5982E7",
|
|
303
|
+
superTokenFactoryAddress: "0x2C90719f25B10Fc5646c82DA3240C76Fa5BcCF34",
|
|
304
|
+
idaV1Address: "0x6EeE6060f715257b970700bc2656De21dEdF074C",
|
|
305
|
+
idaV1Address: "0xB0aABBA4B2783A72C52956CDEF62d438ecA2d7a1"
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
const idaV1 = new InstantDistributionAgreementV1({ options: config });
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
#### IDAV1 Functions
|
|
312
|
+
```ts
|
|
313
|
+
// read
|
|
314
|
+
await sf.idaV1.getSubscription({ superToken: string, publisher: string, indexId: string, subscriber: string, providerOrSigner: string });
|
|
315
|
+
await sf.idaV1.getIndex({ superToken: string, publisher: string, indexId: string, providerOrSigner: string });
|
|
316
|
+
|
|
317
|
+
// write
|
|
318
|
+
await sf.idaV1.createIndex({ indexId: string, userData: string });
|
|
319
|
+
await sf.idaV1.distribute({ indexId: string, amount: string, userData: string });
|
|
320
|
+
await sf.idaV1.updateIndexValue({ indexId: string, indexValue: string, userData: string });
|
|
321
|
+
await sf.idaV1.updateSubscriptionUnits({ indexId: string, subscriber: string, units: string, userData: string });
|
|
322
|
+
await sf.idaV1.approveSubscription({ indexId: string, subscriber: string, userData: string });
|
|
323
|
+
await sf.idaV1.revokeSubscription({ indexId: string, subscriber: string, userData: string });
|
|
324
|
+
await sf.idaV1.deleteSubscription({ indexId: string, subscriber: string, publisher: string, userData: string });
|
|
325
|
+
await sf.idaV1.claim({ indexId: string, subscriber: string, publisher: string, userData: string });
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### SuperToken
|
|
329
|
+
|
|
330
|
+
The `SuperToken` class can also be accessed via the `Framework` class and allows you read from/write to the blockchain. It also provides write functions for both the CFAV1 and IDAV1 contracts in the context of the token. That is, the token field for these different methods will be the token address specified during the creation of this class.
|
|
331
|
+
|
|
332
|
+
#### Framework based initialization
|
|
333
|
+
|
|
334
|
+
```ts
|
|
335
|
+
import { Framework } from "@superfluid-finance/sdk-core";
|
|
336
|
+
import { ethers } from "ethers";
|
|
337
|
+
|
|
338
|
+
const provider = new ethers.providers.InfuraProvider(
|
|
339
|
+
"matic",
|
|
340
|
+
"<INFURA_API_KEY>"
|
|
341
|
+
);
|
|
342
|
+
|
|
343
|
+
const sf = await Framework.create({
|
|
344
|
+
networkName: "matic",
|
|
345
|
+
provider
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
const usdcx = sf.loadToken("0xCAa7349CEA390F89641fe306D93591f87595dc1F");
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
#### Direct Initialization
|
|
352
|
+
|
|
353
|
+
```ts
|
|
354
|
+
import { SuperToken } from "@superfluid-finance/sdk-core";
|
|
355
|
+
import { ethers } from "ethers";
|
|
356
|
+
|
|
357
|
+
const provider = new ethers.providers.InfuraProvider(
|
|
358
|
+
"matic",
|
|
359
|
+
"<INFURA_API_KEY>"
|
|
360
|
+
);
|
|
361
|
+
let usdcx: SuperToken;
|
|
362
|
+
|
|
363
|
+
const config = {
|
|
364
|
+
hostAddress: "0x3E14dC1b13c488a8d5D310918780c983bD5982E7",
|
|
365
|
+
superTokenFactoryAddress: "0x2C90719f25B10Fc5646c82DA3240C76Fa5BcCF34",
|
|
366
|
+
cfaV1Address: "0x6EeE6060f715257b970700bc2656De21dEdF074C",
|
|
367
|
+
idaV1Address: "0xB0aABBA4B2783A72C52956CDEF62d438ecA2d7a1"
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
usdcx = await SuperToken.create({
|
|
371
|
+
address: "0xCAa7349CEA390F89641fe306D93591f87595dc1F",
|
|
372
|
+
config,
|
|
373
|
+
networkName: "matic",
|
|
374
|
+
provider
|
|
375
|
+
});
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
#### SuperToken Functions
|
|
379
|
+
|
|
380
|
+
```ts
|
|
381
|
+
const usdcx = sf.loadToken("0xCAa7349CEA390F89641fe306D93591f87595dc1F");
|
|
382
|
+
|
|
383
|
+
// SuperToken Read Functions
|
|
384
|
+
// ERC20 `Token` function
|
|
385
|
+
await usdcx.balanceOf({ account: string, providerOrSigner: ethers.providers.Provider | ethers.Signer }); // Inherited ERC20 function
|
|
386
|
+
await usdcx.allowance({ owner: string, spender: string, providerOrSigner: ethers.providers.Provider | ethers.Signer }); // Inherited ERC20 function
|
|
387
|
+
await usdcx.totalSupply({ providerOrSigner: ethers.providers.Provider | ethers.Signer }); // Inherited ERC20 function
|
|
388
|
+
|
|
389
|
+
// `SuperToken` only function
|
|
390
|
+
await usdcx.realtimeBalanceOf({ account: string, timestamp: string, providerOrSigner: ethers.providers.Provider | ethers.Signer });
|
|
391
|
+
|
|
392
|
+
// Write Functions
|
|
393
|
+
// All write functions return Promise<Operation>
|
|
394
|
+
|
|
395
|
+
// SuperToken Write Functions
|
|
396
|
+
await usdcx.approve({ recipient: string, amount: string });
|
|
397
|
+
await usdcx.downgrade({ amount: string });
|
|
398
|
+
await usdcx.transfer({ recipient: string, amount: string });
|
|
399
|
+
await usdcx.transferFrom({ sender: string, recipient: string, amount: string });
|
|
400
|
+
await usdcx.upgrade({ amount: string });
|
|
401
|
+
|
|
402
|
+
// SuperToken CFAV1/IDAV1 Functions are the same as the
|
|
403
|
+
// ConstantFlowAgreementV1/InstantDistributionAgreementV1 class functions
|
|
404
|
+
// except instead of the sf.cfaV1/idaV1.function() signature, it is token.function()
|
|
405
|
+
// and you don't need to pass in a token as a parameter as it uses the token address
|
|
406
|
+
// of the instantiated class.
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
> Note: you can also get the underlying Token object which only has ERC20 token read/write methods-this is useful for things like approving token spend to a SuperToken contract prior to upgrading for example.
|
|
410
|
+
|
|
411
|
+
```ts
|
|
412
|
+
const usdc = usdcx.underlyingToken;
|
|
413
|
+
const totalSupply = await usdc.totalSupply();
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
### Batch Call
|
|
417
|
+
|
|
418
|
+
The `BatchCall` class allows the user to batch multiple supported operations/transactions in one operation. Similar to the other helper classes, we can create this either through the `Framework` or directly initialize this.
|
|
419
|
+
|
|
420
|
+
#### Supported Operations
|
|
421
|
+
|
|
422
|
+
Not all operations are supported by the batch call feature, below is a list of the supported operations:
|
|
423
|
+
|
|
424
|
+
- ERC20_APPROVE (SuperToken only)
|
|
425
|
+
- ERC20_TRANSFER_FROM
|
|
426
|
+
- SUPERTOKEN_UPGRADE
|
|
427
|
+
- SUPERTOKEN_DOWNGRADE
|
|
428
|
+
- SUPERFLUID_CALL_AGREEMENT
|
|
429
|
+
- CALL_APP_ACTION
|
|
430
|
+
|
|
431
|
+
Most of the token methods are self explanatory, but some additional context for the last two operations is helpful.
|
|
432
|
+
`SUPERFLUID_CALL_AGREEMENT` refers to all operations related to the CFA or IDA (`createFlow`, `updateIndex`, `distribute`, etc.).
|
|
433
|
+
`CALL_APP_ACTION` refers to an operation which is created from calling a function that exists on a super app you have created. Refer to Usage below to see how you can create a `CALL_APP_ACTION` operation.
|
|
434
|
+
|
|
435
|
+
#### Framework based initialization
|
|
436
|
+
|
|
437
|
+
```ts
|
|
438
|
+
import { Framework } from "@superfluid-finance/sdk-core";
|
|
439
|
+
import { ethers } from "ethers";
|
|
440
|
+
|
|
441
|
+
const provider = new ethers.providers.InfuraProvider(
|
|
442
|
+
"matic",
|
|
443
|
+
"<INFURA_API_KEY>"
|
|
444
|
+
);
|
|
445
|
+
|
|
446
|
+
const sf = await Framework.create({
|
|
447
|
+
networkName: "matic",
|
|
448
|
+
provider
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
const signer = sf.createSigner({ privateKey: "<TEST_ACCOUNT_PRIVATE_KEY>", provider });
|
|
452
|
+
const batchCall = sf.batchCall([<OPERATION_A>, <OPERATION_B>, ...]);
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
#### Direct Initialization
|
|
456
|
+
|
|
457
|
+
```ts
|
|
458
|
+
import { SuperToken } from "@superfluid-finance/sdk-core";
|
|
459
|
+
|
|
460
|
+
const config = {
|
|
461
|
+
hostAddress: "0x3E14dC1b13c488a8d5D310918780c983bD5982E7",
|
|
462
|
+
superTokenFactoryAddress: "0x2C90719f25B10Fc5646c82DA3240C76Fa5BcCF34",
|
|
463
|
+
cfaV1Address: "0x6EeE6060f715257b970700bc2656De21dEdF074C",
|
|
464
|
+
idaV1Address: "0xB0aABBA4B2783A72C52956CDEF62d438ecA2d7a1"
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
const batchCall = new BatchCall({
|
|
468
|
+
config,
|
|
469
|
+
operations: [<OPERATION_A>, <OPERATION_B>, ...],
|
|
470
|
+
});
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
#### Usage
|
|
474
|
+
|
|
475
|
+
```ts
|
|
476
|
+
const txn = await batchCall.execute(signer);
|
|
477
|
+
|
|
478
|
+
// creating an operation from a super app function
|
|
479
|
+
// initialize your super app contract
|
|
480
|
+
const superApp = new ethers.Contract("0x...", <SUPER_APP_ABI>);
|
|
481
|
+
|
|
482
|
+
// populate the transaction
|
|
483
|
+
const superAppTransactionPromise = superApp.populateTransaction.helloWorld("hello world");
|
|
484
|
+
|
|
485
|
+
// create the super app operation you can execute this operation directly or pass it in to a batch call
|
|
486
|
+
const superAppOperation = new Operation(superAppOperation, "CALL_APP_ACTION");
|
|
487
|
+
```
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
import Host from "./Host";
|
|
3
|
+
import { IConfig } from "./interfaces";
|
|
4
|
+
import Operation from "./Operation";
|
|
5
|
+
interface IBatchCallOptions {
|
|
6
|
+
config: IConfig;
|
|
7
|
+
operations: ReadonlyArray<Operation>;
|
|
8
|
+
}
|
|
9
|
+
interface OperationStruct {
|
|
10
|
+
readonly operationType: number;
|
|
11
|
+
readonly target: string;
|
|
12
|
+
readonly data: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @dev BatchCall Helper Class
|
|
16
|
+
* @description A helper class to create `BatchCall` objects which can be executed.
|
|
17
|
+
*/
|
|
18
|
+
export default class BatchCall {
|
|
19
|
+
options: IBatchCallOptions;
|
|
20
|
+
host: Host;
|
|
21
|
+
constructor(options: IBatchCallOptions);
|
|
22
|
+
/**
|
|
23
|
+
* @dev Gets the call agreement function arguments.
|
|
24
|
+
* @param callData callData of the function
|
|
25
|
+
* @returns {ethers.utils.Result} call agreement function arguments
|
|
26
|
+
*/
|
|
27
|
+
getCallAgreementFunctionArgs: (callData: string) => ethers.utils.Result;
|
|
28
|
+
/**
|
|
29
|
+
* @dev Given an `Operation` object, gets the `OperationStruct` object.
|
|
30
|
+
* @param operation an `Operation` object
|
|
31
|
+
* @param index the index of the `Operation` in the batchCall
|
|
32
|
+
* @returns {Promise<OperationStruct>} OperationStruct object for batchCall
|
|
33
|
+
*/
|
|
34
|
+
getOperationStruct: (operation: Operation, index: number) => Promise<OperationStruct>;
|
|
35
|
+
/**
|
|
36
|
+
* @dev Gets an array of `OperationStruct` objects to be passed to batchCall.
|
|
37
|
+
* @returns {Promise<OperationStruct>[]} array of operation struct promises
|
|
38
|
+
*/
|
|
39
|
+
get getOperationStructArrayPromises(): Promise<OperationStruct>[];
|
|
40
|
+
/**
|
|
41
|
+
* @dev Executes a batch call given the operations on this class.
|
|
42
|
+
* @param signer the signer of the transaction
|
|
43
|
+
* @returns {Promise<ethers.ContractTransaction>} ContractTransaction object
|
|
44
|
+
*/
|
|
45
|
+
exec: (signer: ethers.Signer) => Promise<ethers.ContractTransaction>;
|
|
46
|
+
/**
|
|
47
|
+
* @dev Executes a forward batch call given the operations on this class.
|
|
48
|
+
* @param signer the signer of the transaction
|
|
49
|
+
* @returns {Promise<ethers.ContractTransaction>} ContractTransaction object
|
|
50
|
+
*/
|
|
51
|
+
execForward: (signer: ethers.Signer) => Promise<ethers.ContractTransaction>;
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { IAgreementV1Options, ICreateFlowParams, IDeleteFlowParams, IUpdateFlowParams, IGetFlowParams, IGetAccountFlowInfoParams, IWeb3FlowInfoParams, IWeb3FlowInfo } from "./interfaces";
|
|
2
|
+
import Operation from "./Operation";
|
|
3
|
+
import Host from "./Host";
|
|
4
|
+
/**
|
|
5
|
+
* @dev Constant Flow Agreement V1 Helper Class
|
|
6
|
+
* @description A helper class to interact with the CFAV1 contract.
|
|
7
|
+
*/
|
|
8
|
+
export default class ConstantFlowAgreementV1 {
|
|
9
|
+
readonly options: IAgreementV1Options;
|
|
10
|
+
readonly host: Host;
|
|
11
|
+
constructor(options: IAgreementV1Options);
|
|
12
|
+
private get cfaContract();
|
|
13
|
+
/**
|
|
14
|
+
* @dev Get the details of a flow.
|
|
15
|
+
* @param superToken the superToken of the agreement
|
|
16
|
+
* @param sender the sender of the flow
|
|
17
|
+
* @param receiver the receiver of the flow
|
|
18
|
+
* @param providerOrSigner a provider or signer object
|
|
19
|
+
* @returns {Promise<IWeb3FlowInfo>} Web3 Flow info object
|
|
20
|
+
*/
|
|
21
|
+
getFlow: ({ superToken, sender, receiver, providerOrSigner, }: IGetFlowParams) => Promise<IWeb3FlowInfo>;
|
|
22
|
+
/**
|
|
23
|
+
* @dev Get the flow info of an account (net flow).
|
|
24
|
+
* @param superToken the superToken of the agreement
|
|
25
|
+
* @param account the account we're querying
|
|
26
|
+
* @param providerOrSigner a provider or signer object
|
|
27
|
+
* @returns {Promise<IWeb3FlowInfo>} Web3 Flow info object
|
|
28
|
+
*/
|
|
29
|
+
getAccountFlowInfo: ({ superToken, account, providerOrSigner, }: IGetAccountFlowInfoParams) => Promise<IWeb3FlowInfo>;
|
|
30
|
+
/**
|
|
31
|
+
* @dev Get the net flow of an account.
|
|
32
|
+
* @param superToken the superToken of the agreement
|
|
33
|
+
* @param account the account we're querying
|
|
34
|
+
* @param providerOrSigner a provider or signer object
|
|
35
|
+
* @returns {Promise<string>} Web3 Flow info object
|
|
36
|
+
*/
|
|
37
|
+
getNetFlow: ({ superToken, account, providerOrSigner, }: IGetAccountFlowInfoParams) => Promise<string>;
|
|
38
|
+
/**
|
|
39
|
+
* @dev Create a flow.
|
|
40
|
+
* @param flowRate The specified flow rate.
|
|
41
|
+
* @param receiver The receiver of the flow.
|
|
42
|
+
* @param superToken The token to be flowed.
|
|
43
|
+
* @param userData Extra user data provided.
|
|
44
|
+
* @returns {Operation} An instance of Operation which can be executed or batched.
|
|
45
|
+
*/
|
|
46
|
+
createFlow: ({ flowRate, receiver, superToken, userData, }: ICreateFlowParams) => Operation;
|
|
47
|
+
/**
|
|
48
|
+
* @dev Update a flow.
|
|
49
|
+
* @param flowRate The specified flow rate.
|
|
50
|
+
* @param receiver The receiver of the flow.
|
|
51
|
+
* @param superToken The token to be flowed.
|
|
52
|
+
* @param userData Extra user data provided.
|
|
53
|
+
* @returns {Operation} An instance of Operation which can be executed or batched.
|
|
54
|
+
*/
|
|
55
|
+
updateFlow: ({ flowRate, receiver, superToken, userData, }: IUpdateFlowParams) => Operation;
|
|
56
|
+
/**
|
|
57
|
+
* @dev Delete a flow.
|
|
58
|
+
* @param superToken The token to be flowed.
|
|
59
|
+
* @param sender The sender of the flow.
|
|
60
|
+
* @param receiver The receiver of the flow.
|
|
61
|
+
* @param userData Extra user data provided.
|
|
62
|
+
* @returns {Operation} An instance of Operation which can be executed or batched.
|
|
63
|
+
*/
|
|
64
|
+
deleteFlow: ({ superToken, sender, receiver, userData, }: IDeleteFlowParams) => Operation;
|
|
65
|
+
/**
|
|
66
|
+
* @dev Sanitizes flow info, converting BigNumber to string.
|
|
67
|
+
* @param timestamp last updated timestamp of flow
|
|
68
|
+
* @param flowRate the current flow rate
|
|
69
|
+
* @param deposit the deposit amount
|
|
70
|
+
* @param owedDeposit any owed depsit
|
|
71
|
+
* @returns {IWeb3FlowInfo} sanitized web3 flow info
|
|
72
|
+
*/
|
|
73
|
+
_sanitizeflowInfo: ({ timestamp, flowRate, deposit, owedDeposit, }: IWeb3FlowInfoParams) => IWeb3FlowInfo;
|
|
74
|
+
}
|