@superfluid-finance/sdk-core 0.1.1-dev.16594f6.0 → 0.1.1-dev.2c190cd.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 +423 -72
- package/dist/main/BatchCall.d.ts +1 -1
- package/dist/main/ConstantFlowAgreementV1.d.ts +2 -2
- package/dist/main/Framework.d.ts +5 -5
- package/dist/main/InstantDistributionAgreementV1.d.ts +2 -2
- package/dist/main/Query.d.ts +3 -3
- package/dist/main/SuperToken.d.ts +2 -2
- package/dist/main/Token.d.ts +1 -1
- package/dist/main/constants.d.ts +8 -1
- package/dist/main/index.d.ts +5 -5
- package/dist/main/index.js +6081 -6006
- package/dist/main/interfaces.d.ts +3 -6
- package/dist/main/ordering.d.ts +1 -1
- package/dist/main/pagination.d.ts +2 -2
- package/dist/main/subgraph/queries/getAllEvents.generated.d.ts +4 -4
- package/dist/main/subgraph/schema.generated.d.ts +33 -42
- package/dist/main/typechain/IResolver.d.ts +17 -3
- package/dist/main/typechain/TestToken.d.ts +8 -0
- package/dist/main/typechain/factories/IResolver__factory.d.ts +15 -2
- package/dist/main/utils.d.ts +17 -0
- package/dist/main/validation.d.ts +1 -1
- package/dist/module/BatchCall.d.ts +1 -1
- package/dist/module/ConstantFlowAgreementV1.d.ts +2 -2
- package/dist/module/Framework.d.ts +5 -5
- package/dist/module/InstantDistributionAgreementV1.d.ts +2 -2
- package/dist/module/Query.d.ts +3 -3
- package/dist/module/SuperToken.d.ts +2 -2
- package/dist/module/Token.d.ts +1 -1
- package/dist/module/constants.d.ts +8 -1
- package/dist/module/index.d.ts +5 -5
- package/dist/module/index.js +6080 -6007
- package/dist/module/interfaces.d.ts +3 -6
- package/dist/module/ordering.d.ts +1 -1
- package/dist/module/pagination.d.ts +2 -2
- package/dist/module/subgraph/queries/getAllEvents.generated.d.ts +4 -4
- package/dist/module/subgraph/schema.generated.d.ts +33 -42
- package/dist/module/typechain/IResolver.d.ts +17 -3
- package/dist/module/typechain/TestToken.d.ts +8 -0
- package/dist/module/typechain/factories/IResolver__factory.d.ts +15 -2
- package/dist/module/utils.d.ts +17 -0
- package/dist/module/validation.d.ts +1 -1
- package/dist/umd/BatchCall.d.ts +1 -1
- package/dist/umd/ConstantFlowAgreementV1.d.ts +2 -2
- package/dist/umd/Framework.d.ts +5 -5
- package/dist/umd/InstantDistributionAgreementV1.d.ts +2 -2
- package/dist/umd/Query.d.ts +3 -3
- package/dist/umd/SuperToken.d.ts +2 -2
- package/dist/umd/Token.d.ts +1 -1
- package/dist/umd/constants.d.ts +8 -1
- package/dist/umd/index.d.ts +5 -5
- package/dist/umd/index.js +4320 -4245
- package/dist/umd/interfaces.d.ts +3 -6
- package/dist/umd/ordering.d.ts +1 -1
- package/dist/umd/pagination.d.ts +2 -2
- package/dist/umd/subgraph/queries/getAllEvents.generated.d.ts +4 -4
- package/dist/umd/subgraph/schema.generated.d.ts +33 -42
- package/dist/umd/typechain/IResolver.d.ts +17 -3
- package/dist/umd/typechain/TestToken.d.ts +8 -0
- package/dist/umd/typechain/factories/IResolver__factory.d.ts +15 -2
- package/dist/umd/utils.d.ts +17 -0
- package/dist/umd/validation.d.ts +1 -1
- package/package.json +13 -8
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
|
+
```
|
|
45
49
|
|
|
50
|
+
CommonJS/Node.js
|
|
51
|
+
```js
|
|
52
|
+
const { Framework } = require("@superfluid-finance/sdk-core");
|
|
53
|
+
const { ethers } = require("ethers");
|
|
54
|
+
```
|
|
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
75
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
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({
|
|
80
|
+
networkName: "matic",
|
|
81
|
+
provider: ethersProvider
|
|
82
|
+
});
|
|
70
83
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
);
|
|
75
|
-
const sf = await Framework.create({
|
|
84
|
+
// metamask
|
|
85
|
+
const mmProvider = new ethers.providers.Web3Provider(window.ethereum);
|
|
86
|
+
const mmSf = await Framework.create({
|
|
76
87
|
networkName: "matic",
|
|
77
|
-
provider
|
|
88
|
+
provider: mmProvider
|
|
78
89
|
});
|
|
79
90
|
|
|
80
|
-
//
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const web3jsSf = await Framework.create({
|
|
91
|
+
// web3modal
|
|
92
|
+
const web3ModalRawProvider = await web3Modal.connect();
|
|
93
|
+
const web3ModalProvider = new ethers.providers.Web3Provider(web3ModalRawProvider);
|
|
94
|
+
const web3ModalSf = await Framework.create({
|
|
85
95
|
networkName: "matic",
|
|
86
|
-
provider:
|
|
96
|
+
provider: web3ModalProvider
|
|
87
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"`.
|
|
@@ -116,12 +142,50 @@ const sf = await Framework.create({
|
|
|
116
142
|
provider
|
|
117
143
|
});
|
|
118
144
|
|
|
145
|
+
type Paging = { take: number, skip?: number, lastId?: string };
|
|
146
|
+
|
|
119
147
|
const pageResult = await sf.query.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
148
|
+
listAllResults(paging: Paging);
|
|
149
|
+
|
|
150
|
+
// The different queries can take different order by properties
|
|
151
|
+
// given the properties that exist on the entity itself.
|
|
152
|
+
listAllSuperTokens({ isListed?: boolean },
|
|
153
|
+
paging: Paging,
|
|
154
|
+
ordering: Ordering<Token_OrderBy>
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
listIndexes({ indexId?: string, publisher?: string, token?: string },
|
|
158
|
+
paging: Paging,
|
|
159
|
+
ordering: Ordering<Index_OrderBy>
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
listIndexSubscriptions({ subscriber?: string, approved?: boolean },
|
|
163
|
+
paging: Paging,
|
|
164
|
+
ordering: Ordering<IndexSubscription_OrderBy>
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
listStreams({ sender?: string, receiver?: string, token?: string },
|
|
168
|
+
paging: Paging,
|
|
169
|
+
ordering: Ordering<Stream_OrderBy>
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
listUserInteractedSuperTokens({ account?: string, token?: string },
|
|
173
|
+
paging: Paging,
|
|
174
|
+
ordering: Ordering<AccountTokenSnapshot_OrderBy>
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
listEvents({ account?: string, timestamp_gt?: number },
|
|
178
|
+
paging: Paging,
|
|
179
|
+
ordering: Ordering<Event_OrderBy>
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
// A subscription function which allows you to subscribe to events via polling.
|
|
183
|
+
on(
|
|
184
|
+
callback: (events: AllEvents[], unsubscribe: () => void) => void,
|
|
185
|
+
ms: number,
|
|
186
|
+
account?: string,
|
|
187
|
+
timeout?: number
|
|
188
|
+
)
|
|
125
189
|
```
|
|
126
190
|
|
|
127
191
|
#### Direct Initialization
|
|
@@ -130,17 +194,45 @@ If you'd like, you can also initialize the `Query` class as a standalone class l
|
|
|
130
194
|
|
|
131
195
|
```ts
|
|
132
196
|
import { Query } from "@superfluid-finance/sdk-core";
|
|
133
|
-
const query = new Query({
|
|
134
|
-
|
|
135
|
-
|
|
197
|
+
const query = new Query({
|
|
198
|
+
customSubgraphQueriesEndpoint: "<A_CUSTOM_ENDPOINT>",
|
|
199
|
+
dataMode: "SUBGRAPH_ONLY" | "SUBGRAPH_WEB3" | "WEB3_ONLY"
|
|
200
|
+
});
|
|
136
201
|
```
|
|
137
202
|
|
|
138
203
|
#### Pagination
|
|
139
204
|
|
|
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 }`.
|
|
205
|
+
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 }`. You can also paginate by `lastId`, this allows you to bypass the limitation of the max skip of 5000 entities.
|
|
141
206
|
|
|
142
207
|
> Note: this example uses the `graphql-request` library, but you just need to provide a valid query which is a string.
|
|
143
208
|
|
|
209
|
+
#### Ordering
|
|
210
|
+
|
|
211
|
+
You can also pass in an ordering object for the different queries, each query function will accept different ordering properties depending on the properties on the entity. We have different defaults for each so you don't need to actually pass anything in.
|
|
212
|
+
|
|
213
|
+
#### Example Usage
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
const { Framework } = require("@superfluid-finance/sdk-core");
|
|
217
|
+
const { ethers } = require("ethers");
|
|
218
|
+
|
|
219
|
+
const provider = new ethers.providers.InfuraProvider(
|
|
220
|
+
"matic",
|
|
221
|
+
"<INFURA_API_KEY>"
|
|
222
|
+
);
|
|
223
|
+
const sf = await Framework.create({
|
|
224
|
+
networkName: "matic",
|
|
225
|
+
provider
|
|
226
|
+
});
|
|
227
|
+
const results = await sf.query.listAllSuperTokens(
|
|
228
|
+
{ isListed: true },
|
|
229
|
+
{ skip: 5, take: 150 },
|
|
230
|
+
{
|
|
231
|
+
orderBy: "createdAtBlockNumber",
|
|
232
|
+
orderDirection: "desc"
|
|
233
|
+
});
|
|
234
|
+
```
|
|
235
|
+
|
|
144
236
|
### Creating a Signer
|
|
145
237
|
|
|
146
238
|
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.
|
|
@@ -278,15 +370,88 @@ const cfaV1 = new ConstantFlowAgreementV1({ options: config });
|
|
|
278
370
|
|
|
279
371
|
#### CFAV1 Functions
|
|
280
372
|
```ts
|
|
281
|
-
//
|
|
282
|
-
await sf.cfaV1.getFlow({
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
await sf.cfaV1.
|
|
373
|
+
// Read functions
|
|
374
|
+
await sf.cfaV1.getFlow({
|
|
375
|
+
superToken: string,
|
|
376
|
+
sender: string,
|
|
377
|
+
receiver: string,
|
|
378
|
+
providerOrSigner: ethers.providers.Provider | ethers.Signer
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
await sf.cfaV1.getAccountFlowInfo({
|
|
382
|
+
superToken: string,
|
|
383
|
+
account: string,
|
|
384
|
+
providerOrSigner: ethers.providers.Provider | ethers.Signer
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
await sf.cfaV1.getNetFlow({
|
|
388
|
+
superToken: string,
|
|
389
|
+
account: string,
|
|
390
|
+
providerOrSigner: ethers.providers.Provider | ethers.Signer
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
// Write operations
|
|
395
|
+
sf.cfaV1.createFlow({
|
|
396
|
+
sender: string,
|
|
397
|
+
receiver: string,
|
|
398
|
+
token: string,
|
|
399
|
+
flowRate: string,
|
|
400
|
+
userData?: string
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
sf.cfaV1.updateFlow({
|
|
404
|
+
sender: string,
|
|
405
|
+
receiver: string,
|
|
406
|
+
token: string,
|
|
407
|
+
flowRate: string,
|
|
408
|
+
userData?: string
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
sf.cfaV1.deleteFlow({
|
|
412
|
+
sender: string,
|
|
413
|
+
receiver: string,
|
|
414
|
+
token: string,
|
|
415
|
+
userData?: string
|
|
416
|
+
});
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
#### Example Usage
|
|
420
|
+
|
|
421
|
+
```ts
|
|
422
|
+
import { Framework } from "@superfluid-finance/sdk-core";
|
|
423
|
+
import { ethers } from "ethers";
|
|
424
|
+
|
|
425
|
+
const provider = new ethers.providers.InfuraProvider(
|
|
426
|
+
"matic",
|
|
427
|
+
"<INFURA_API_KEY>"
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
const sf = await Framework.create({
|
|
431
|
+
networkName: "matic",
|
|
432
|
+
provider
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
// Read example
|
|
436
|
+
const flowInfo = await sf.cfaV1.getFlow({
|
|
437
|
+
superToken: "0x...",
|
|
438
|
+
sender: "0x...",
|
|
439
|
+
receiver: "0x...",
|
|
440
|
+
providerOrSigner: provider
|
|
441
|
+
});
|
|
442
|
+
console.log("flowInfo", flowInfo);
|
|
443
|
+
|
|
444
|
+
// Write operation example
|
|
445
|
+
const signer = sf.createSigner({ privateKey: "<TEST_ACCOUNT_PRIVATE_KEY>", provider });
|
|
446
|
+
const createFlowOperation = sf.cfaV1.createFlow({
|
|
447
|
+
sender: "0x...",
|
|
448
|
+
receiver: "0x...",
|
|
449
|
+
token: "0x...",
|
|
450
|
+
flowRate: "1000000000"
|
|
451
|
+
});
|
|
452
|
+
const txnResponse = await createFlowOperation.exec(signer);
|
|
453
|
+
const txnReceipt = await txnResponse.wait();
|
|
454
|
+
// Transaction Complete when code reaches here
|
|
290
455
|
```
|
|
291
456
|
|
|
292
457
|
### InstantDistributionAgreementV1
|
|
@@ -310,19 +475,110 @@ const idaV1 = new InstantDistributionAgreementV1({ options: config });
|
|
|
310
475
|
|
|
311
476
|
#### IDAV1 Functions
|
|
312
477
|
```ts
|
|
313
|
-
//
|
|
314
|
-
await sf.idaV1.getSubscription({
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
await sf.idaV1.
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
478
|
+
// Read functions
|
|
479
|
+
await sf.idaV1.getSubscription({
|
|
480
|
+
superToken: string,
|
|
481
|
+
publisher: string,
|
|
482
|
+
indexId: string,
|
|
483
|
+
subscriber: string,
|
|
484
|
+
providerOrSigner: string
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
await sf.idaV1.getIndex({
|
|
488
|
+
superToken: string,
|
|
489
|
+
publisher: string,
|
|
490
|
+
indexId: string,
|
|
491
|
+
providerOrSigner: string
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
// Write operations
|
|
496
|
+
sf.idaV1.createIndex({
|
|
497
|
+
indexId: string,
|
|
498
|
+
superToken: string,
|
|
499
|
+
userData?: string
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
sf.idaV1.distribute({
|
|
503
|
+
indexId: string,
|
|
504
|
+
superToken: string,
|
|
505
|
+
amount: string,
|
|
506
|
+
userData?: string
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
sf.idaV1.updateIndexValue({
|
|
510
|
+
indexId: string,
|
|
511
|
+
superToken: string,
|
|
512
|
+
indexValue: string,
|
|
513
|
+
userData?: string
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
sf.idaV1.updateSubscriptionUnits({
|
|
517
|
+
indexId: string,
|
|
518
|
+
superToken: string,
|
|
519
|
+
subscriber: string,
|
|
520
|
+
units: string,
|
|
521
|
+
userData?: string
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
sf.idaV1.approveSubscription({
|
|
525
|
+
indexId: string,
|
|
526
|
+
superToken: string,
|
|
527
|
+
publisher: string,
|
|
528
|
+
userData?: string
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
sf.idaV1.revokeSubscription({
|
|
532
|
+
indexId: string,
|
|
533
|
+
superToken: string,
|
|
534
|
+
publisher: string,
|
|
535
|
+
userData?: string
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
sf.idaV1.deleteSubscription({
|
|
539
|
+
indexId: string,
|
|
540
|
+
superToken: string,
|
|
541
|
+
subscriber: string,
|
|
542
|
+
publisher: string,
|
|
543
|
+
userData?: string
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
sf.idaV1.claim({
|
|
547
|
+
indexId: string,
|
|
548
|
+
superToken: string,
|
|
549
|
+
subscriber: string,
|
|
550
|
+
publisher: string,
|
|
551
|
+
userData?: string
|
|
552
|
+
});
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
#### Example Usage
|
|
556
|
+
|
|
557
|
+
```ts
|
|
558
|
+
import { Framework } from "@superfluid-finance/sdk-core";
|
|
559
|
+
import { ethers } from "ethers";
|
|
560
|
+
|
|
561
|
+
const provider = new ethers.providers.InfuraProvider(
|
|
562
|
+
"matic",
|
|
563
|
+
"<INFURA_API_KEY>"
|
|
564
|
+
);
|
|
565
|
+
|
|
566
|
+
const sf = await Framework.create({
|
|
567
|
+
networkName: "matic",
|
|
568
|
+
provider
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
// Read example
|
|
572
|
+
const subscription = await sf.idaV1.getSubscription({ superToken: "0x...", publisher: "0x...", indexId: "1", subscriber: "0x...", providerOrSigner: provider });
|
|
573
|
+
console.log(subscription);
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
// Write operation example
|
|
577
|
+
const signer = sf.createSigner({ privateKey: "<TEST_ACCOUNT_PRIVATE_KEY>", provider });
|
|
578
|
+
const createIndexOperation = sf.idaV1.createIndex({ indexId: "0", userData: "0x" });
|
|
579
|
+
const txnResponse = await createIndexOperation.exec(signer);
|
|
580
|
+
const txnReceipt = await txnResponse.wait();
|
|
581
|
+
// Transaction Complete when code reaches here
|
|
326
582
|
```
|
|
327
583
|
|
|
328
584
|
### SuperToken
|
|
@@ -358,7 +614,6 @@ const provider = new ethers.providers.InfuraProvider(
|
|
|
358
614
|
"matic",
|
|
359
615
|
"<INFURA_API_KEY>"
|
|
360
616
|
);
|
|
361
|
-
let usdcx: SuperToken;
|
|
362
617
|
|
|
363
618
|
const config = {
|
|
364
619
|
hostAddress: "0x3E14dC1b13c488a8d5D310918780c983bD5982E7",
|
|
@@ -367,7 +622,7 @@ const config = {
|
|
|
367
622
|
idaV1Address: "0xB0aABBA4B2783A72C52956CDEF62d438ecA2d7a1"
|
|
368
623
|
};
|
|
369
624
|
|
|
370
|
-
usdcx = await SuperToken.create({
|
|
625
|
+
const usdcx = await SuperToken.create({
|
|
371
626
|
address: "0xCAa7349CEA390F89641fe306D93591f87595dc1F",
|
|
372
627
|
config,
|
|
373
628
|
networkName: "matic",
|
|
@@ -380,32 +635,103 @@ usdcx = await SuperToken.create({
|
|
|
380
635
|
```ts
|
|
381
636
|
const usdcx = sf.loadToken("0xCAa7349CEA390F89641fe306D93591f87595dc1F");
|
|
382
637
|
|
|
383
|
-
//
|
|
384
|
-
//
|
|
385
|
-
await usdcx.balanceOf({
|
|
386
|
-
|
|
387
|
-
|
|
638
|
+
// ERC20 `Token`
|
|
639
|
+
// Read functions
|
|
640
|
+
await usdcx.balanceOf({
|
|
641
|
+
account: string,
|
|
642
|
+
providerOrSigner: ethers.providers.Provider | ethers.Signer
|
|
643
|
+
});
|
|
644
|
+
|
|
645
|
+
await usdcx.allowance({
|
|
646
|
+
owner: string,
|
|
647
|
+
spender: string,
|
|
648
|
+
providerOrSigner: ethers.providers.Provider | ethers.Signer
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
await usdcx.name({
|
|
652
|
+
providerOrSigner: ethers.providers.Provider | ethers.Signer
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
await usdcx.symbol({
|
|
656
|
+
providerOrSigner: ethers.providers.Provider | ethers.Signer
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
await usdcx.totalSupply({
|
|
660
|
+
providerOrSigner: ethers.providers.Provider | ethers.Signer
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
// Write operations
|
|
665
|
+
usdcx.approve({
|
|
666
|
+
recipient: string,
|
|
667
|
+
amount: string
|
|
668
|
+
});
|
|
669
|
+
|
|
670
|
+
usdcx.transfer({
|
|
671
|
+
recipient: string,
|
|
672
|
+
amount: string
|
|
673
|
+
});
|
|
674
|
+
|
|
675
|
+
usdcx.transferFrom({
|
|
676
|
+
sender: string,
|
|
677
|
+
recipient: string,
|
|
678
|
+
amount: string
|
|
679
|
+
});
|
|
388
680
|
|
|
389
681
|
// `SuperToken` only function
|
|
390
|
-
await usdcx.realtimeBalanceOf({
|
|
682
|
+
await usdcx.realtimeBalanceOf({
|
|
683
|
+
account: string,
|
|
684
|
+
timestamp: string,
|
|
685
|
+
providerOrSigner: ethers.providers.Provider | ethers.Signer
|
|
686
|
+
});
|
|
391
687
|
|
|
392
688
|
// Write Functions
|
|
689
|
+
|
|
393
690
|
// All write functions return Promise<Operation>
|
|
394
691
|
|
|
395
|
-
// SuperToken Write
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
await usdcx.transferFrom({ sender: string, recipient: string, amount: string });
|
|
400
|
-
await usdcx.upgrade({ amount: string });
|
|
692
|
+
// SuperToken Write operations
|
|
693
|
+
usdcx.downgrade({ amount: string });
|
|
694
|
+
|
|
695
|
+
usdcx.upgrade({ amount: string });
|
|
401
696
|
|
|
402
697
|
// SuperToken CFAV1/IDAV1 Functions are the same as the
|
|
403
698
|
// ConstantFlowAgreementV1/InstantDistributionAgreementV1 class functions
|
|
404
699
|
// except instead of the sf.cfaV1/idaV1.function() signature, it is token.function()
|
|
700
|
+
// e.g. await usdcx.createIndex({ indexId: "0", userData: "0x" }).exec(signer);
|
|
405
701
|
// and you don't need to pass in a token as a parameter as it uses the token address
|
|
406
702
|
// of the instantiated class.
|
|
407
703
|
```
|
|
408
704
|
|
|
705
|
+
#### Example Usage
|
|
706
|
+
|
|
707
|
+
```ts
|
|
708
|
+
import { Framework } from "@superfluid-finance/sdk-core";
|
|
709
|
+
import { ethers } from "ethers";
|
|
710
|
+
|
|
711
|
+
const provider = new ethers.providers.InfuraProvider(
|
|
712
|
+
"matic",
|
|
713
|
+
"<INFURA_API_KEY>"
|
|
714
|
+
);
|
|
715
|
+
|
|
716
|
+
const sf = await Framework.create({
|
|
717
|
+
networkName: "matic",
|
|
718
|
+
provider
|
|
719
|
+
});
|
|
720
|
+
|
|
721
|
+
const usdcx = sf.loadToken("0xCAa7349CEA390F89641fe306D93591f87595dc1F");
|
|
722
|
+
|
|
723
|
+
// Read example
|
|
724
|
+
const name = await usdcx.name();
|
|
725
|
+
console.log(name);
|
|
726
|
+
|
|
727
|
+
// Write operation example
|
|
728
|
+
const signer = sf.createSigner({ privateKey: "<TEST_ACCOUNT_PRIVATE_KEY>", provider });
|
|
729
|
+
const transferOperation = usdcx.transfer({ receiver: "0x...", amount: "1000000" });
|
|
730
|
+
const txnResponse = await transferOperation.exec(signer);
|
|
731
|
+
const txnReceipt = await txnResponse.wait();
|
|
732
|
+
// Transaction Complete when code reaches here
|
|
733
|
+
```
|
|
734
|
+
|
|
409
735
|
> 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
736
|
|
|
411
737
|
```ts
|
|
@@ -421,12 +747,12 @@ The `BatchCall` class allows the user to batch multiple supported operations/tra
|
|
|
421
747
|
|
|
422
748
|
Not all operations are supported by the batch call feature, below is a list of the supported operations:
|
|
423
749
|
|
|
424
|
-
- ERC20_APPROVE (SuperToken only)
|
|
425
|
-
- ERC20_TRANSFER_FROM
|
|
426
|
-
- SUPERTOKEN_UPGRADE
|
|
427
|
-
- SUPERTOKEN_DOWNGRADE
|
|
428
|
-
- SUPERFLUID_CALL_AGREEMENT
|
|
429
|
-
- CALL_APP_ACTION
|
|
750
|
+
- `ERC20_APPROVE (SuperToken only)`
|
|
751
|
+
- `ERC20_TRANSFER_FROM`
|
|
752
|
+
- `SUPERTOKEN_UPGRADE`
|
|
753
|
+
- `SUPERTOKEN_DOWNGRADE`
|
|
754
|
+
- `SUPERFLUID_CALL_AGREEMENT`
|
|
755
|
+
- `CALL_APP_ACTION`
|
|
430
756
|
|
|
431
757
|
Most of the token methods are self explanatory, but some additional context for the last two operations is helpful.
|
|
432
758
|
`SUPERFLUID_CALL_AGREEMENT` refers to all operations related to the CFA or IDA (`createFlow`, `updateIndex`, `distribute`, etc.).
|
|
@@ -473,7 +799,32 @@ const batchCall = new BatchCall({
|
|
|
473
799
|
#### Usage
|
|
474
800
|
|
|
475
801
|
```ts
|
|
476
|
-
|
|
802
|
+
import { Framework } from "@superfluid-finance/sdk-core";
|
|
803
|
+
import { ethers } from "ethers";
|
|
804
|
+
|
|
805
|
+
const provider = new ethers.providers.InfuraProvider(
|
|
806
|
+
"matic",
|
|
807
|
+
"<INFURA_API_KEY>"
|
|
808
|
+
);
|
|
809
|
+
|
|
810
|
+
const sf = await Framework.create({
|
|
811
|
+
networkName: "matic",
|
|
812
|
+
provider
|
|
813
|
+
});
|
|
814
|
+
|
|
815
|
+
// 0xabc is the signer on Rinkeby testnet
|
|
816
|
+
const signer = sf.createSigner({ privateKey: "<TEST_ACCOUNT_PRIVATE_KEY>", provider });
|
|
817
|
+
const daix = await sf.loadSuperToken("0x745861AeD1EEe363b4AaA5F1994Be40b1e05Ff90");
|
|
818
|
+
const fromAddress = "0xabc";
|
|
819
|
+
const paymentAddress = "0xdef";
|
|
820
|
+
const approveOp = daix.approve({ receiver: paymentAddress, amount: "10000" });
|
|
821
|
+
const transferFromOp = daix.transferFrom({
|
|
822
|
+
sender: fromAddress,
|
|
823
|
+
receiver: paymentAddress,
|
|
824
|
+
amount: "10000",
|
|
825
|
+
});
|
|
826
|
+
const batchCall = sf.batchCall([approveOp, transferFromOp]);
|
|
827
|
+
const txn = await batchCall.exec(signer);
|
|
477
828
|
|
|
478
829
|
// creating an operation from a super app function
|
|
479
830
|
// initialize your super app contract
|
|
@@ -483,5 +834,5 @@ const superApp = new ethers.Contract("0x...", <SUPER_APP_ABI>);
|
|
|
483
834
|
const superAppTransactionPromise = superApp.populateTransaction.helloWorld("hello world");
|
|
484
835
|
|
|
485
836
|
// create the super app operation you can execute this operation directly or pass it in to a batch call
|
|
486
|
-
const superAppOperation = new Operation(
|
|
837
|
+
const superAppOperation = new Operation(superAppTransactionPromise, "CALL_APP_ACTION");
|
|
487
838
|
```
|
package/dist/main/BatchCall.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
2
|
import Host from "./Host";
|
|
3
|
-
import { IConfig } from "./interfaces";
|
|
4
3
|
import Operation from "./Operation";
|
|
4
|
+
import { IConfig } from "./interfaces";
|
|
5
5
|
interface IBatchCallOptions {
|
|
6
6
|
config: IConfig;
|
|
7
7
|
operations: ReadonlyArray<Operation>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IAgreementV1Options, ICreateFlowParams, IDeleteFlowParams, IUpdateFlowParams, IGetFlowParams, IGetAccountFlowInfoParams, IWeb3FlowInfoParams, IWeb3FlowInfo } from "./interfaces";
|
|
2
|
-
import Operation from "./Operation";
|
|
3
1
|
import Host from "./Host";
|
|
2
|
+
import Operation from "./Operation";
|
|
3
|
+
import { IAgreementV1Options, ICreateFlowParams, IDeleteFlowParams, IGetAccountFlowInfoParams, IGetFlowParams, IUpdateFlowParams, IWeb3FlowInfo, IWeb3FlowInfoParams } from "./interfaces";
|
|
4
4
|
/**
|
|
5
5
|
* @dev Constant Flow Agreement V1 Helper Class
|
|
6
6
|
* @description A helper class to interact with the CFAV1 contract.
|
package/dist/main/Framework.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { ethers } from "ethers";
|
|
2
1
|
import { Signer } from "@ethersproject/abstract-signer";
|
|
3
|
-
import {
|
|
4
|
-
import { DataMode } from "./types";
|
|
2
|
+
import { ethers } from "ethers";
|
|
5
3
|
import BatchCall from "./BatchCall";
|
|
6
4
|
import ConstantFlowAgreementV1 from "./ConstantFlowAgreementV1";
|
|
7
5
|
import Host from "./Host";
|
|
8
6
|
import InstantDistributionAgreementV1 from "./InstantDistributionAgreementV1";
|
|
9
|
-
import SuperToken from "./SuperToken";
|
|
10
|
-
import Query from "./Query";
|
|
11
7
|
import Operation from "./Operation";
|
|
8
|
+
import Query from "./Query";
|
|
9
|
+
import SuperToken from "./SuperToken";
|
|
10
|
+
import { IConfig, ISignerConstructorOptions } from "./interfaces";
|
|
11
|
+
import { DataMode } from "./types";
|
|
12
12
|
export interface IFrameworkOptions {
|
|
13
13
|
chainId?: number;
|
|
14
14
|
customSubgraphQueriesEndpoint?: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IAgreementV1Options, IBaseIDAParams, IBaseSubscriptionParams, IDistributeParams, IGetIndexParams, IGetSubscriptionParams, IUpdateIndexValueParams, IUpdateSubscriptionUnitsParams, IWeb3Index, IWeb3Subscription } from "./interfaces";
|
|
2
|
-
import Operation from "./Operation";
|
|
3
1
|
import Host from "./Host";
|
|
2
|
+
import Operation from "./Operation";
|
|
3
|
+
import { IAgreementV1Options, IBaseIDAParams, IBaseSubscriptionParams, IDistributeParams, IGetIndexParams, IGetSubscriptionParams, IUpdateIndexValueParams, IUpdateSubscriptionUnitsParams, IWeb3Index, IWeb3Subscription } from "./interfaces";
|
|
4
4
|
/**
|
|
5
5
|
* @dev Instant Distribution Agreement V1 Helper Class
|
|
6
6
|
* @description A helper class to interact with the IDAV1 contract.
|
package/dist/main/Query.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { IAccountTokenSnapshotFilter, IIndex, IIndexRequestFilter, IIndexSubscription, IIndexSubscriptionRequestFilter, ILightAccountTokenSnapshot, ILightEntity, IStream, IStreamRequestFilter, ISuperToken, ISuperTokenRequestFilter } from "./interfaces";
|
|
2
|
-
import { DataMode } from "./types";
|
|
3
|
-
import { PagedResult, Paging } from "./pagination";
|
|
4
1
|
import { AllEvents, IEventFilter } from "./events";
|
|
2
|
+
import { IAccountTokenSnapshotFilter, IIndex, IIndexRequestFilter, IIndexSubscription, IIndexSubscriptionRequestFilter, ILightAccountTokenSnapshot, ILightEntity, IStream, IStreamRequestFilter, ISuperToken, ISuperTokenRequestFilter } from "./interfaces";
|
|
5
3
|
import { Ordering } from "./ordering";
|
|
4
|
+
import { PagedResult, Paging } from "./pagination";
|
|
6
5
|
import { AccountTokenSnapshot_OrderBy, Event_OrderBy, Index_OrderBy, IndexSubscription_OrderBy, Stream_OrderBy, Token_OrderBy } from "./subgraph/schema.generated";
|
|
6
|
+
import { DataMode } from "./types";
|
|
7
7
|
export interface IQueryOptions {
|
|
8
8
|
readonly customSubgraphQueriesEndpoint: string;
|
|
9
9
|
readonly dataMode: DataMode;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
|
-
import { IConfig, IRealtimeBalanceOfParams, ISuperTokenBaseIDAParams, ISuperTokenCreateFlowParams, ISuperTokenDeleteFlowParams, ISuperTokenDistributeParams, ISuperTokenGetFlowInfoParams, ISuperTokenGetFlowParams, ISuperTokenGetIndexParams, ISuperTokenGetSubscriptionParams, ISuperTokenPublisherOperationParams, ISuperTokenPubSubParams, ISuperTokenUpdateFlowParams, ISuperTokenUpdateIndexValueParams, ISuperTokenUpdateSubscriptionUnitsParams, IWeb3FlowInfo, IWeb3Index, IWeb3RealTimeBalanceOf, IWeb3Subscription } from "./interfaces";
|
|
3
|
-
import Operation from "./Operation";
|
|
4
2
|
import ConstantFlowAgreementV1 from "./ConstantFlowAgreementV1";
|
|
5
3
|
import InstantDistributionAgreementV1 from "./InstantDistributionAgreementV1";
|
|
4
|
+
import Operation from "./Operation";
|
|
6
5
|
import Token from "./Token";
|
|
6
|
+
import { IConfig, IRealtimeBalanceOfParams, ISuperTokenBaseIDAParams, ISuperTokenCreateFlowParams, ISuperTokenDeleteFlowParams, ISuperTokenDistributeParams, ISuperTokenGetFlowInfoParams, ISuperTokenGetFlowParams, ISuperTokenGetIndexParams, ISuperTokenGetSubscriptionParams, ISuperTokenPublisherOperationParams, ISuperTokenPubSubParams, ISuperTokenUpdateFlowParams, ISuperTokenUpdateIndexValueParams, ISuperTokenUpdateSubscriptionUnitsParams, IWeb3FlowInfo, IWeb3Index, IWeb3RealTimeBalanceOf, IWeb3Subscription } from "./interfaces";
|
|
7
7
|
export interface ITokenSettings {
|
|
8
8
|
readonly address: string;
|
|
9
9
|
readonly config: IConfig;
|