omnipin 2.2.3 → 2.2.4
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/dist/index.js +469 -322
- package/package.json +79 -77
package/dist/index.js
CHANGED
|
@@ -10155,7 +10155,9 @@ let filecoinMainnet = {
|
|
|
10155
10155
|
[filecoinCalibration.id]: Provider_from(fromHttp('https://api.calibration.node.glif.io/rpc/v1'))
|
|
10156
10156
|
};
|
|
10157
10157
|
filecoinMainnet.id, filecoinCalibration.id;
|
|
10158
|
-
let
|
|
10158
|
+
let SIZE_CONSTANTS = {
|
|
10159
|
+
TiB: 1n << 40n
|
|
10160
|
+
}, LOCKUP_PERIOD = 30n * 2880n, getClientDatasets_abi = {
|
|
10159
10161
|
type: 'function',
|
|
10160
10162
|
name: 'getClientDataSets',
|
|
10161
10163
|
inputs: [
|
|
@@ -10244,6 +10246,70 @@ let getClientDatasets_abi = {
|
|
|
10244
10246
|
'latest'
|
|
10245
10247
|
]
|
|
10246
10248
|
}));
|
|
10249
|
+
}, accounts_abi = {
|
|
10250
|
+
type: 'function',
|
|
10251
|
+
inputs: [
|
|
10252
|
+
{
|
|
10253
|
+
name: 'token',
|
|
10254
|
+
internalType: 'contract IERC20',
|
|
10255
|
+
type: 'address'
|
|
10256
|
+
},
|
|
10257
|
+
{
|
|
10258
|
+
name: 'owner',
|
|
10259
|
+
internalType: 'address',
|
|
10260
|
+
type: 'address'
|
|
10261
|
+
}
|
|
10262
|
+
],
|
|
10263
|
+
name: 'accounts',
|
|
10264
|
+
outputs: [
|
|
10265
|
+
{
|
|
10266
|
+
name: 'funds',
|
|
10267
|
+
internalType: 'uint256',
|
|
10268
|
+
type: 'uint256'
|
|
10269
|
+
},
|
|
10270
|
+
{
|
|
10271
|
+
name: 'lockupCurrent',
|
|
10272
|
+
internalType: 'uint256',
|
|
10273
|
+
type: 'uint256'
|
|
10274
|
+
},
|
|
10275
|
+
{
|
|
10276
|
+
name: 'lockupRate',
|
|
10277
|
+
internalType: 'uint256',
|
|
10278
|
+
type: 'uint256'
|
|
10279
|
+
},
|
|
10280
|
+
{
|
|
10281
|
+
name: 'lockupLastSettledAt',
|
|
10282
|
+
internalType: 'uint256',
|
|
10283
|
+
type: 'uint256'
|
|
10284
|
+
}
|
|
10285
|
+
],
|
|
10286
|
+
stateMutability: 'view'
|
|
10287
|
+
}, accounts_accounts = async (options)=>{
|
|
10288
|
+
let { address, chain } = options, provider = constants_filProvider[chain.id], token = options.token ?? chain.contracts.usdfc.address, [result, currentEpochHex] = await Promise.all([
|
|
10289
|
+
provider.request({
|
|
10290
|
+
method: 'eth_call',
|
|
10291
|
+
params: [
|
|
10292
|
+
{
|
|
10293
|
+
data: AbiFunction_encodeData(accounts_abi, [
|
|
10294
|
+
token,
|
|
10295
|
+
address
|
|
10296
|
+
]),
|
|
10297
|
+
to: chain.contracts.payments.address
|
|
10298
|
+
},
|
|
10299
|
+
'latest'
|
|
10300
|
+
]
|
|
10301
|
+
}),
|
|
10302
|
+
provider.request({
|
|
10303
|
+
method: 'eth_blockNumber'
|
|
10304
|
+
})
|
|
10305
|
+
]), [funds, lockupCurrent, lockupRate, lockupLastSettledAt] = AbiFunction_decodeResult(accounts_abi, result), currentEpoch = BigInt(currentEpochHex), actualLockup = lockupCurrent + (currentEpoch > lockupLastSettledAt ? currentEpoch - lockupLastSettledAt : 0n) * lockupRate;
|
|
10306
|
+
return {
|
|
10307
|
+
funds,
|
|
10308
|
+
lockupCurrent,
|
|
10309
|
+
lockupRate,
|
|
10310
|
+
lockupLastSettledAt,
|
|
10311
|
+
availableFunds: funds > actualLockup ? funds - actualLockup : 0n
|
|
10312
|
+
};
|
|
10247
10313
|
}, exponents = {
|
|
10248
10314
|
wei: 0,
|
|
10249
10315
|
gwei: 9,
|
|
@@ -10386,7 +10452,49 @@ let getClientDatasets_abi = {
|
|
|
10386
10452
|
AbiFunction_decodeResult(erc20Abi[2], results[2]),
|
|
10387
10453
|
AbiFunction_decodeResult(erc20Abi[3], results[3])
|
|
10388
10454
|
];
|
|
10389
|
-
},
|
|
10455
|
+
}, signErc20Permit = ({ privateKey, address, amount, nonce, deadline, name, version, chain })=>Secp256k1_sign({
|
|
10456
|
+
privateKey,
|
|
10457
|
+
payload: getSignPayload({
|
|
10458
|
+
domain: {
|
|
10459
|
+
chainId: chain.id,
|
|
10460
|
+
name,
|
|
10461
|
+
version,
|
|
10462
|
+
verifyingContract: chain.contracts.usdfc.address
|
|
10463
|
+
},
|
|
10464
|
+
message: {
|
|
10465
|
+
owner: address,
|
|
10466
|
+
spender: chain.contracts.payments.address,
|
|
10467
|
+
value: amount,
|
|
10468
|
+
nonce,
|
|
10469
|
+
deadline
|
|
10470
|
+
},
|
|
10471
|
+
primaryType: 'Permit',
|
|
10472
|
+
types: {
|
|
10473
|
+
Permit: [
|
|
10474
|
+
{
|
|
10475
|
+
name: 'owner',
|
|
10476
|
+
type: 'address'
|
|
10477
|
+
},
|
|
10478
|
+
{
|
|
10479
|
+
name: 'spender',
|
|
10480
|
+
type: 'address'
|
|
10481
|
+
},
|
|
10482
|
+
{
|
|
10483
|
+
name: 'value',
|
|
10484
|
+
type: 'uint256'
|
|
10485
|
+
},
|
|
10486
|
+
{
|
|
10487
|
+
name: 'nonce',
|
|
10488
|
+
type: 'uint256'
|
|
10489
|
+
},
|
|
10490
|
+
{
|
|
10491
|
+
name: 'deadline',
|
|
10492
|
+
type: 'uint256'
|
|
10493
|
+
}
|
|
10494
|
+
]
|
|
10495
|
+
}
|
|
10496
|
+
})
|
|
10497
|
+
}), deposit_with_permit_abi = {
|
|
10390
10498
|
type: 'function',
|
|
10391
10499
|
inputs: [
|
|
10392
10500
|
{
|
|
@@ -10423,80 +10531,18 @@ let getClientDatasets_abi = {
|
|
|
10423
10531
|
name: 's',
|
|
10424
10532
|
internalType: 'bytes32',
|
|
10425
10533
|
type: 'bytes32'
|
|
10426
|
-
},
|
|
10427
|
-
{
|
|
10428
|
-
name: 'operator',
|
|
10429
|
-
internalType: 'address',
|
|
10430
|
-
type: 'address'
|
|
10431
|
-
},
|
|
10432
|
-
{
|
|
10433
|
-
name: 'rateAllowance',
|
|
10434
|
-
internalType: 'uint256',
|
|
10435
|
-
type: 'uint256'
|
|
10436
|
-
},
|
|
10437
|
-
{
|
|
10438
|
-
name: 'lockupAllowance',
|
|
10439
|
-
internalType: 'uint256',
|
|
10440
|
-
type: 'uint256'
|
|
10441
|
-
},
|
|
10442
|
-
{
|
|
10443
|
-
name: 'maxLockupPeriod',
|
|
10444
|
-
internalType: 'uint256',
|
|
10445
|
-
type: 'uint256'
|
|
10446
10534
|
}
|
|
10447
10535
|
],
|
|
10448
|
-
name: '
|
|
10536
|
+
name: 'depositWithPermit',
|
|
10449
10537
|
outputs: [],
|
|
10450
10538
|
stateMutability: 'nonpayable'
|
|
10451
|
-
},
|
|
10539
|
+
}, depositWithPermitWriteParameters = async ({ privateKey, address, amount, deadline = BigInt(Math.floor(Date.now() / 1000) + 3600), chain })=>{
|
|
10452
10540
|
let [balance, name, nonce, version] = await getErc20WithPermitData({
|
|
10453
10541
|
address,
|
|
10454
10542
|
chain
|
|
10455
10543
|
});
|
|
10456
10544
|
if (balance < amount) throw Error(`Not enough USDfc to deposit (need: ${Value_format(amount - balance, 18).slice(0, 5)})`);
|
|
10457
|
-
let { r, s, yParity } = await (
|
|
10458
|
-
privateKey,
|
|
10459
|
-
payload: getSignPayload({
|
|
10460
|
-
domain: {
|
|
10461
|
-
chainId: chain.id,
|
|
10462
|
-
name,
|
|
10463
|
-
version,
|
|
10464
|
-
verifyingContract: chain.contracts.usdfc.address
|
|
10465
|
-
},
|
|
10466
|
-
message: {
|
|
10467
|
-
owner: address,
|
|
10468
|
-
spender: chain.contracts.payments.address,
|
|
10469
|
-
value: amount,
|
|
10470
|
-
nonce,
|
|
10471
|
-
deadline
|
|
10472
|
-
},
|
|
10473
|
-
primaryType: 'Permit',
|
|
10474
|
-
types: {
|
|
10475
|
-
Permit: [
|
|
10476
|
-
{
|
|
10477
|
-
name: 'owner',
|
|
10478
|
-
type: 'address'
|
|
10479
|
-
},
|
|
10480
|
-
{
|
|
10481
|
-
name: 'spender',
|
|
10482
|
-
type: 'address'
|
|
10483
|
-
},
|
|
10484
|
-
{
|
|
10485
|
-
name: 'value',
|
|
10486
|
-
type: 'uint256'
|
|
10487
|
-
},
|
|
10488
|
-
{
|
|
10489
|
-
name: 'nonce',
|
|
10490
|
-
type: 'uint256'
|
|
10491
|
-
},
|
|
10492
|
-
{
|
|
10493
|
-
name: 'deadline',
|
|
10494
|
-
type: 'uint256'
|
|
10495
|
-
}
|
|
10496
|
-
]
|
|
10497
|
-
}
|
|
10498
|
-
})
|
|
10499
|
-
}))({
|
|
10545
|
+
let { r, s, yParity } = await signErc20Permit({
|
|
10500
10546
|
privateKey,
|
|
10501
10547
|
address,
|
|
10502
10548
|
amount,
|
|
@@ -10505,7 +10551,7 @@ let getClientDatasets_abi = {
|
|
|
10505
10551
|
nonce,
|
|
10506
10552
|
version,
|
|
10507
10553
|
chain
|
|
10508
|
-
}), data = AbiFunction_encodeData(
|
|
10554
|
+
}), data = AbiFunction_encodeData(deposit_with_permit_abi, [
|
|
10509
10555
|
chain.contracts.usdfc.address,
|
|
10510
10556
|
address,
|
|
10511
10557
|
amount,
|
|
@@ -10516,20 +10562,16 @@ let getClientDatasets_abi = {
|
|
|
10516
10562
|
}),
|
|
10517
10563
|
fromNumber(s, {
|
|
10518
10564
|
size: 32
|
|
10519
|
-
})
|
|
10520
|
-
chain.contracts.storage.address,
|
|
10521
|
-
maxUint256,
|
|
10522
|
-
maxUint256,
|
|
10523
|
-
30n * 2880n
|
|
10565
|
+
})
|
|
10524
10566
|
]);
|
|
10525
10567
|
return {
|
|
10526
10568
|
provider: constants_filProvider[chain.id],
|
|
10527
|
-
abi:
|
|
10569
|
+
abi: deposit_with_permit_abi,
|
|
10528
10570
|
from: address,
|
|
10529
10571
|
to: chain.contracts.payments.address,
|
|
10530
10572
|
data
|
|
10531
10573
|
};
|
|
10532
|
-
},
|
|
10574
|
+
}, deposit_with_permit_and_approve_operator_abi = {
|
|
10533
10575
|
type: 'function',
|
|
10534
10576
|
inputs: [
|
|
10535
10577
|
{
|
|
@@ -10538,244 +10580,97 @@ let getClientDatasets_abi = {
|
|
|
10538
10580
|
type: 'address'
|
|
10539
10581
|
},
|
|
10540
10582
|
{
|
|
10541
|
-
name: '
|
|
10583
|
+
name: 'to',
|
|
10542
10584
|
internalType: 'address',
|
|
10543
10585
|
type: 'address'
|
|
10544
|
-
}
|
|
10545
|
-
],
|
|
10546
|
-
name: 'accounts',
|
|
10547
|
-
outputs: [
|
|
10586
|
+
},
|
|
10548
10587
|
{
|
|
10549
|
-
name: '
|
|
10588
|
+
name: 'amount',
|
|
10550
10589
|
internalType: 'uint256',
|
|
10551
10590
|
type: 'uint256'
|
|
10552
10591
|
},
|
|
10553
10592
|
{
|
|
10554
|
-
name: '
|
|
10593
|
+
name: 'deadline',
|
|
10555
10594
|
internalType: 'uint256',
|
|
10556
10595
|
type: 'uint256'
|
|
10557
10596
|
},
|
|
10558
10597
|
{
|
|
10559
|
-
name: '
|
|
10598
|
+
name: 'v',
|
|
10599
|
+
internalType: 'uint8',
|
|
10600
|
+
type: 'uint8'
|
|
10601
|
+
},
|
|
10602
|
+
{
|
|
10603
|
+
name: 'r',
|
|
10604
|
+
internalType: 'bytes32',
|
|
10605
|
+
type: 'bytes32'
|
|
10606
|
+
},
|
|
10607
|
+
{
|
|
10608
|
+
name: 's',
|
|
10609
|
+
internalType: 'bytes32',
|
|
10610
|
+
type: 'bytes32'
|
|
10611
|
+
},
|
|
10612
|
+
{
|
|
10613
|
+
name: 'operator',
|
|
10614
|
+
internalType: 'address',
|
|
10615
|
+
type: 'address'
|
|
10616
|
+
},
|
|
10617
|
+
{
|
|
10618
|
+
name: 'rateAllowance',
|
|
10560
10619
|
internalType: 'uint256',
|
|
10561
10620
|
type: 'uint256'
|
|
10562
10621
|
},
|
|
10563
10622
|
{
|
|
10564
|
-
name: '
|
|
10623
|
+
name: 'lockupAllowance',
|
|
10565
10624
|
internalType: 'uint256',
|
|
10566
10625
|
type: 'uint256'
|
|
10567
|
-
}
|
|
10568
|
-
],
|
|
10569
|
-
stateMutability: 'view'
|
|
10570
|
-
}, getAccountInfo = async ({ address, chain })=>{
|
|
10571
|
-
let provider = constants_filProvider[chain.id], result = await provider.request({
|
|
10572
|
-
method: 'eth_call',
|
|
10573
|
-
params: [
|
|
10574
|
-
{
|
|
10575
|
-
data: AbiFunction_encodeData(getAccountInfo_abi, [
|
|
10576
|
-
chain.contracts.usdfc.address,
|
|
10577
|
-
address
|
|
10578
|
-
]),
|
|
10579
|
-
to: chain.contracts.payments.address
|
|
10580
|
-
},
|
|
10581
|
-
'latest'
|
|
10582
|
-
]
|
|
10583
|
-
});
|
|
10584
|
-
return AbiFunction_decodeResult(getAccountInfo_abi, result);
|
|
10585
|
-
}, getAvailableFunds = async ({ address, chain })=>{
|
|
10586
|
-
let [funds, lockupCurrent, lockupRate, lockupLastSettledAt] = await getAccountInfo({
|
|
10587
|
-
address,
|
|
10588
|
-
chain
|
|
10589
|
-
}), currentEpoch = BigInt(await constants_filProvider[chain.id].request({
|
|
10590
|
-
method: 'eth_blockNumber'
|
|
10591
|
-
})), epochsSinceSettlement = currentEpoch > lockupLastSettledAt ? currentEpoch - lockupLastSettledAt : 0n, settledLockupCurrent = lockupCurrent + epochsSinceSettlement * lockupRate;
|
|
10592
|
-
return {
|
|
10593
|
-
funds,
|
|
10594
|
-
lockupCurrent,
|
|
10595
|
-
lockupRate,
|
|
10596
|
-
lockupLastSettledAt,
|
|
10597
|
-
currentEpoch,
|
|
10598
|
-
epochsSinceSettlement,
|
|
10599
|
-
settledLockupCurrent,
|
|
10600
|
-
availableFunds: funds > settledLockupCurrent ? funds - settledLockupCurrent : 0n
|
|
10601
|
-
};
|
|
10602
|
-
}, DEFAULT_LOCKUP_PERIOD = 30n * 2880n, serviceAbi = [
|
|
10603
|
-
{
|
|
10604
|
-
type: 'function',
|
|
10605
|
-
name: 'getServicePrice',
|
|
10606
|
-
inputs: [],
|
|
10607
|
-
outputs: [
|
|
10608
|
-
{
|
|
10609
|
-
name: 'pricing',
|
|
10610
|
-
internalType: 'struct FilecoinWarmStorageService.ServicePricing',
|
|
10611
|
-
type: 'tuple',
|
|
10612
|
-
components: [
|
|
10613
|
-
{
|
|
10614
|
-
name: 'pricePerTiBPerMonthNoCDN',
|
|
10615
|
-
internalType: 'uint256',
|
|
10616
|
-
type: 'uint256'
|
|
10617
|
-
},
|
|
10618
|
-
{
|
|
10619
|
-
name: 'pricePerTiBCdnEgress',
|
|
10620
|
-
internalType: 'uint256',
|
|
10621
|
-
type: 'uint256'
|
|
10622
|
-
},
|
|
10623
|
-
{
|
|
10624
|
-
name: 'pricePerTiBCacheMissEgress',
|
|
10625
|
-
internalType: 'uint256',
|
|
10626
|
-
type: 'uint256'
|
|
10627
|
-
},
|
|
10628
|
-
{
|
|
10629
|
-
name: 'tokenAddress',
|
|
10630
|
-
internalType: 'contract IERC20',
|
|
10631
|
-
type: 'address'
|
|
10632
|
-
},
|
|
10633
|
-
{
|
|
10634
|
-
name: 'epochsPerMonth',
|
|
10635
|
-
internalType: 'uint256',
|
|
10636
|
-
type: 'uint256'
|
|
10637
|
-
},
|
|
10638
|
-
{
|
|
10639
|
-
name: 'minimumPricePerMonth',
|
|
10640
|
-
internalType: 'uint256',
|
|
10641
|
-
type: 'uint256'
|
|
10642
|
-
}
|
|
10643
|
-
]
|
|
10644
|
-
}
|
|
10645
|
-
],
|
|
10646
|
-
stateMutability: 'view'
|
|
10647
|
-
},
|
|
10648
|
-
{
|
|
10649
|
-
type: 'function',
|
|
10650
|
-
name: 'pdpVerifierAddress',
|
|
10651
|
-
inputs: [],
|
|
10652
|
-
outputs: [
|
|
10653
|
-
{
|
|
10654
|
-
name: '',
|
|
10655
|
-
internalType: 'address',
|
|
10656
|
-
type: 'address'
|
|
10657
|
-
}
|
|
10658
|
-
],
|
|
10659
|
-
stateMutability: 'view'
|
|
10660
|
-
}
|
|
10661
|
-
], pdpVerifierAbi = {
|
|
10662
|
-
type: 'function',
|
|
10663
|
-
name: 'USDFC_SYBIL_FEE',
|
|
10664
|
-
inputs: [],
|
|
10665
|
-
outputs: [
|
|
10626
|
+
},
|
|
10666
10627
|
{
|
|
10667
|
-
name: '',
|
|
10628
|
+
name: 'maxLockupPeriod',
|
|
10668
10629
|
internalType: 'uint256',
|
|
10669
10630
|
type: 'uint256'
|
|
10670
10631
|
}
|
|
10671
10632
|
],
|
|
10672
|
-
|
|
10673
|
-
|
|
10674
|
-
|
|
10675
|
-
|
|
10676
|
-
|
|
10677
|
-
|
|
10678
|
-
|
|
10679
|
-
to: chain.contracts.storage.address,
|
|
10680
|
-
data: AbiFunction_encodeData(serviceAbi[0])
|
|
10681
|
-
},
|
|
10682
|
-
'latest'
|
|
10683
|
-
]
|
|
10684
|
-
}),
|
|
10685
|
-
provider.request({
|
|
10686
|
-
method: 'eth_call',
|
|
10687
|
-
params: [
|
|
10688
|
-
{
|
|
10689
|
-
to: chain.contracts.storage.address,
|
|
10690
|
-
data: AbiFunction_encodeData(serviceAbi[1])
|
|
10691
|
-
},
|
|
10692
|
-
'latest'
|
|
10693
|
-
]
|
|
10694
|
-
})
|
|
10695
|
-
]), { minimumPricePerMonth } = AbiFunction_decodeResult(serviceAbi[0], servicePriceResult), pdpVerifierAddress = AbiFunction_decodeResult(serviceAbi[1], pdpVerifierResult), verifierAddress = '0x0000000000000000000000000000000000000000' === pdpVerifierAddress ? chain.contracts.pdpVerifier.address : pdpVerifierAddress, sybilFeeResult = await provider.request({
|
|
10696
|
-
method: 'eth_call',
|
|
10697
|
-
params: [
|
|
10698
|
-
{
|
|
10699
|
-
to: verifierAddress,
|
|
10700
|
-
data: AbiFunction_encodeData(pdpVerifierAbi)
|
|
10701
|
-
},
|
|
10702
|
-
'latest'
|
|
10703
|
-
]
|
|
10704
|
-
}), sybilFee = AbiFunction_decodeResult(pdpVerifierAbi, sybilFeeResult), requirements = (({ minimumPricePerMonth, sybilFee })=>({
|
|
10705
|
-
defaultLockupPeriod: DEFAULT_LOCKUP_PERIOD,
|
|
10706
|
-
epochsPerMonth: DEFAULT_LOCKUP_PERIOD,
|
|
10707
|
-
minimumLockupRequired: minimumPricePerMonth,
|
|
10708
|
-
creationRequirement: minimumPricePerMonth + sybilFee
|
|
10709
|
-
}))({
|
|
10710
|
-
minimumPricePerMonth,
|
|
10711
|
-
sybilFee
|
|
10633
|
+
name: 'depositWithPermitAndApproveOperator',
|
|
10634
|
+
outputs: [],
|
|
10635
|
+
stateMutability: 'nonpayable'
|
|
10636
|
+
}, depositWithPermitAndApproveOperatorWriteParameters = async ({ privateKey, address, amount, deadline = BigInt(Math.floor(Date.now() / 1000) + 3600), chain })=>{
|
|
10637
|
+
let [balance, name, nonce, version] = await getErc20WithPermitData({
|
|
10638
|
+
address,
|
|
10639
|
+
chain
|
|
10712
10640
|
});
|
|
10641
|
+
if (balance < amount) throw Error(`Not enough USDfc to deposit (need: ${Value_format(amount - balance, 18).slice(0, 5)})`);
|
|
10642
|
+
let { r, s, yParity } = await signErc20Permit({
|
|
10643
|
+
privateKey,
|
|
10644
|
+
address,
|
|
10645
|
+
amount,
|
|
10646
|
+
deadline,
|
|
10647
|
+
name,
|
|
10648
|
+
nonce,
|
|
10649
|
+
version,
|
|
10650
|
+
chain
|
|
10651
|
+
}), data = AbiFunction_encodeData(deposit_with_permit_and_approve_operator_abi, [
|
|
10652
|
+
chain.contracts.usdfc.address,
|
|
10653
|
+
address,
|
|
10654
|
+
amount,
|
|
10655
|
+
deadline,
|
|
10656
|
+
void 0 !== yParity ? yParityToV(yParity) : 27,
|
|
10657
|
+
fromNumber(r, {
|
|
10658
|
+
size: 32
|
|
10659
|
+
}),
|
|
10660
|
+
fromNumber(s, {
|
|
10661
|
+
size: 32
|
|
10662
|
+
}),
|
|
10663
|
+
chain.contracts.storage.address,
|
|
10664
|
+
maxUint256,
|
|
10665
|
+
maxUint256,
|
|
10666
|
+
LOCKUP_PERIOD
|
|
10667
|
+
]);
|
|
10713
10668
|
return {
|
|
10714
|
-
|
|
10715
|
-
|
|
10716
|
-
|
|
10717
|
-
|
|
10718
|
-
|
|
10719
|
-
}, getServicePrice_abi = {
|
|
10720
|
-
type: 'function',
|
|
10721
|
-
inputs: [],
|
|
10722
|
-
name: 'getServicePrice',
|
|
10723
|
-
outputs: [
|
|
10724
|
-
{
|
|
10725
|
-
name: 'pricing',
|
|
10726
|
-
internalType: 'struct FilecoinWarmStorageService.ServicePricing',
|
|
10727
|
-
type: 'tuple',
|
|
10728
|
-
components: [
|
|
10729
|
-
{
|
|
10730
|
-
name: 'pricePerTiBPerMonthNoCDN',
|
|
10731
|
-
internalType: 'uint256',
|
|
10732
|
-
type: 'uint256'
|
|
10733
|
-
},
|
|
10734
|
-
{
|
|
10735
|
-
name: 'pricePerTiBCdnEgress',
|
|
10736
|
-
internalType: 'uint256',
|
|
10737
|
-
type: 'uint256'
|
|
10738
|
-
},
|
|
10739
|
-
{
|
|
10740
|
-
name: 'pricePerTiBCacheMissEgress',
|
|
10741
|
-
internalType: 'uint256',
|
|
10742
|
-
type: 'uint256'
|
|
10743
|
-
},
|
|
10744
|
-
{
|
|
10745
|
-
name: 'tokenAddress',
|
|
10746
|
-
internalType: 'contract IERC20',
|
|
10747
|
-
type: 'address'
|
|
10748
|
-
},
|
|
10749
|
-
{
|
|
10750
|
-
name: 'epochsPerMonth',
|
|
10751
|
-
internalType: 'uint256',
|
|
10752
|
-
type: 'uint256'
|
|
10753
|
-
},
|
|
10754
|
-
{
|
|
10755
|
-
name: 'minimumPricePerMonth',
|
|
10756
|
-
internalType: 'uint256',
|
|
10757
|
-
type: 'uint256'
|
|
10758
|
-
}
|
|
10759
|
-
]
|
|
10760
|
-
}
|
|
10761
|
-
],
|
|
10762
|
-
stateMutability: 'view'
|
|
10763
|
-
}, TiB = 1024n ** 4n, getServicePrice = async ({ chain, size: sizeInBytes })=>{
|
|
10764
|
-
let provider = constants_filProvider[chain.id], result = await provider.request({
|
|
10765
|
-
method: 'eth_call',
|
|
10766
|
-
params: [
|
|
10767
|
-
{
|
|
10768
|
-
to: chain.contracts.storage.address,
|
|
10769
|
-
data: AbiFunction_encodeData(getServicePrice_abi)
|
|
10770
|
-
},
|
|
10771
|
-
'latest'
|
|
10772
|
-
]
|
|
10773
|
-
}), { minimumPricePerMonth, pricePerTiBPerMonthNoCDN, epochsPerMonth } = AbiFunction_decodeResult(getServicePrice_abi, result), linearCost = BigInt(sizeInBytes) * pricePerTiBPerMonthNoCDN / TiB, costWithBuffer = 110n * (linearCost > minimumPricePerMonth ? linearCost : minimumPricePerMonth) / 100n;
|
|
10774
|
-
return {
|
|
10775
|
-
perMonth: costWithBuffer,
|
|
10776
|
-
perEpoch: costWithBuffer / epochsPerMonth,
|
|
10777
|
-
minimumFloor: minimumPricePerMonth,
|
|
10778
|
-
linearCost
|
|
10669
|
+
provider: constants_filProvider[chain.id],
|
|
10670
|
+
abi: deposit_with_permit_and_approve_operator_abi,
|
|
10671
|
+
from: address,
|
|
10672
|
+
to: chain.contracts.payments.address,
|
|
10673
|
+
data
|
|
10779
10674
|
};
|
|
10780
10675
|
}, getUSDfcBalance_abi = {
|
|
10781
10676
|
constant: !0,
|
|
@@ -10809,6 +10704,69 @@ let getClientDatasets_abi = {
|
|
|
10809
10704
|
]
|
|
10810
10705
|
});
|
|
10811
10706
|
return AbiFunction_decodeResult(getUSDfcBalance_abi, result);
|
|
10707
|
+
}, is_fwss_max_approved_abi = {
|
|
10708
|
+
type: 'function',
|
|
10709
|
+
inputs: [
|
|
10710
|
+
{
|
|
10711
|
+
name: 'token',
|
|
10712
|
+
internalType: 'contract IERC20',
|
|
10713
|
+
type: 'address'
|
|
10714
|
+
},
|
|
10715
|
+
{
|
|
10716
|
+
name: 'client',
|
|
10717
|
+
internalType: 'address',
|
|
10718
|
+
type: 'address'
|
|
10719
|
+
},
|
|
10720
|
+
{
|
|
10721
|
+
name: 'operator',
|
|
10722
|
+
internalType: 'address',
|
|
10723
|
+
type: 'address'
|
|
10724
|
+
}
|
|
10725
|
+
],
|
|
10726
|
+
name: 'operatorApprovals',
|
|
10727
|
+
outputs: [
|
|
10728
|
+
{
|
|
10729
|
+
name: 'isApproved',
|
|
10730
|
+
type: 'bool'
|
|
10731
|
+
},
|
|
10732
|
+
{
|
|
10733
|
+
name: 'rateAllowance',
|
|
10734
|
+
type: 'uint256'
|
|
10735
|
+
},
|
|
10736
|
+
{
|
|
10737
|
+
name: 'lockupAllowance',
|
|
10738
|
+
type: 'uint256'
|
|
10739
|
+
},
|
|
10740
|
+
{
|
|
10741
|
+
name: 'rateUsage',
|
|
10742
|
+
type: 'uint256'
|
|
10743
|
+
},
|
|
10744
|
+
{
|
|
10745
|
+
name: 'lockupUsage',
|
|
10746
|
+
type: 'uint256'
|
|
10747
|
+
},
|
|
10748
|
+
{
|
|
10749
|
+
name: 'maxLockupPeriod',
|
|
10750
|
+
type: 'uint256'
|
|
10751
|
+
}
|
|
10752
|
+
],
|
|
10753
|
+
stateMutability: 'view'
|
|
10754
|
+
}, isFwssMaxApproved = async (options)=>{
|
|
10755
|
+
let { clientAddress, chain } = options, provider = constants_filProvider[chain.id], token = options.token ?? chain.contracts.usdfc.address, result = await provider.request({
|
|
10756
|
+
method: 'eth_call',
|
|
10757
|
+
params: [
|
|
10758
|
+
{
|
|
10759
|
+
data: AbiFunction_encodeData(is_fwss_max_approved_abi, [
|
|
10760
|
+
token,
|
|
10761
|
+
clientAddress,
|
|
10762
|
+
chain.contracts.storage.address
|
|
10763
|
+
]),
|
|
10764
|
+
to: chain.contracts.payments.address
|
|
10765
|
+
},
|
|
10766
|
+
'latest'
|
|
10767
|
+
]
|
|
10768
|
+
}), [isApproved, rateAllowance, lockupAllowance] = AbiFunction_decodeResult(is_fwss_max_approved_abi, result);
|
|
10769
|
+
return isApproved && rateAllowance === maxUint256 && lockupAllowance === maxUint256;
|
|
10812
10770
|
}, uploadPiece = async ({ providerURL, pieceCid, bytes })=>{
|
|
10813
10771
|
let res = await fetch(new URL('/pdp/piece', providerURL), {
|
|
10814
10772
|
method: 'POST',
|
|
@@ -11825,7 +11783,182 @@ class cid_CID {
|
|
|
11825
11783
|
return cid_baseCache(cid).set(prefix, source), cid;
|
|
11826
11784
|
}
|
|
11827
11785
|
}
|
|
11828
|
-
let DAG_PB_CODE = 0x70, SHA_256_CODE = 0x12, cidSymbol = Symbol.for('@ipld/js-cid/CID'), link_DAG_PB_CODE = 0x70, varint_0 = __webpack_require__("./node_modules/varint/index.js"), calculatePieceCID_FR_RATIO = 254 / 256, MIN_PAYLOAD_SIZE = 127,
|
|
11786
|
+
let DAG_PB_CODE = 0x70, SHA_256_CODE = 0x12, cidSymbol = Symbol.for('@ipld/js-cid/CID'), link_DAG_PB_CODE = 0x70, varint_0 = __webpack_require__("./node_modules/varint/index.js"), calculatePieceCID_FR_RATIO = 254 / 256, MIN_PAYLOAD_SIZE = 127, calculateEffectiveRate = (params)=>{
|
|
11787
|
+
let { sizeInBytes, pricePerTiBPerMonth, minimumPricePerMonth, epochsPerMonth } = params, naturalPerMonth = pricePerTiBPerMonth * sizeInBytes / SIZE_CONSTANTS.TiB, naturalPerEpoch = pricePerTiBPerMonth * sizeInBytes / (SIZE_CONSTANTS.TiB * epochsPerMonth), minimumPerEpoch = minimumPricePerMonth / epochsPerMonth;
|
|
11788
|
+
return {
|
|
11789
|
+
ratePerEpoch: naturalPerEpoch > minimumPerEpoch ? naturalPerEpoch : minimumPerEpoch,
|
|
11790
|
+
ratePerMonth: naturalPerMonth > minimumPricePerMonth ? naturalPerMonth : minimumPricePerMonth
|
|
11791
|
+
};
|
|
11792
|
+
}, get_service_pricing_abi = {
|
|
11793
|
+
type: 'function',
|
|
11794
|
+
inputs: [],
|
|
11795
|
+
name: 'getServicePrice',
|
|
11796
|
+
outputs: [
|
|
11797
|
+
{
|
|
11798
|
+
name: 'pricing',
|
|
11799
|
+
internalType: 'struct FilecoinWarmStorageService.ServicePricing',
|
|
11800
|
+
type: 'tuple',
|
|
11801
|
+
components: [
|
|
11802
|
+
{
|
|
11803
|
+
name: 'pricePerTiBPerMonthNoCDN',
|
|
11804
|
+
internalType: 'uint256',
|
|
11805
|
+
type: 'uint256'
|
|
11806
|
+
},
|
|
11807
|
+
{
|
|
11808
|
+
name: 'pricePerTiBCdnEgress',
|
|
11809
|
+
internalType: 'uint256',
|
|
11810
|
+
type: 'uint256'
|
|
11811
|
+
},
|
|
11812
|
+
{
|
|
11813
|
+
name: 'pricePerTiBCacheMissEgress',
|
|
11814
|
+
internalType: 'uint256',
|
|
11815
|
+
type: 'uint256'
|
|
11816
|
+
},
|
|
11817
|
+
{
|
|
11818
|
+
name: 'tokenAddress',
|
|
11819
|
+
internalType: 'contract IERC20',
|
|
11820
|
+
type: 'address'
|
|
11821
|
+
},
|
|
11822
|
+
{
|
|
11823
|
+
name: 'epochsPerMonth',
|
|
11824
|
+
internalType: 'uint256',
|
|
11825
|
+
type: 'uint256'
|
|
11826
|
+
},
|
|
11827
|
+
{
|
|
11828
|
+
name: 'minimumPricePerMonth',
|
|
11829
|
+
internalType: 'uint256',
|
|
11830
|
+
type: 'uint256'
|
|
11831
|
+
}
|
|
11832
|
+
]
|
|
11833
|
+
}
|
|
11834
|
+
],
|
|
11835
|
+
stateMutability: 'view'
|
|
11836
|
+
}, getServicePricing = async ({ chain })=>{
|
|
11837
|
+
let provider = constants_filProvider[chain.id], result = await provider.request({
|
|
11838
|
+
method: 'eth_call',
|
|
11839
|
+
params: [
|
|
11840
|
+
{
|
|
11841
|
+
to: chain.contracts.storage.address,
|
|
11842
|
+
data: AbiFunction_encodeData(get_service_pricing_abi)
|
|
11843
|
+
},
|
|
11844
|
+
'latest'
|
|
11845
|
+
]
|
|
11846
|
+
});
|
|
11847
|
+
return AbiFunction_decodeResult(get_service_pricing_abi, result);
|
|
11848
|
+
}, getUploadCosts = async (options)=>{
|
|
11849
|
+
var params;
|
|
11850
|
+
let lockup, netRateAfterUpload, extraRunwayEpochs, bufferEpochs, runway, rawDepositNeeded, buffer, isNewDataSet = options.isNewDataSet ?? !0, currentDataSetSize = options.currentDataSetSize ?? 0n, extraRunwayEpochs1 = options.extraRunwayEpochs ?? 0n, bufferEpochs1 = options.bufferEpochs ?? 5n, provider = constants_filProvider[options.chain.id], [accountInfo, pricing, approved, currentEpochHex] = await Promise.all([
|
|
11851
|
+
accounts_accounts({
|
|
11852
|
+
address: options.clientAddress,
|
|
11853
|
+
chain: options.chain
|
|
11854
|
+
}),
|
|
11855
|
+
getServicePricing({
|
|
11856
|
+
chain: options.chain
|
|
11857
|
+
}),
|
|
11858
|
+
isFwssMaxApproved({
|
|
11859
|
+
clientAddress: options.clientAddress,
|
|
11860
|
+
chain: options.chain
|
|
11861
|
+
}),
|
|
11862
|
+
provider.request({
|
|
11863
|
+
method: 'eth_blockNumber'
|
|
11864
|
+
})
|
|
11865
|
+
]), currentEpoch = BigInt(currentEpochHex), rate = calculateEffectiveRate({
|
|
11866
|
+
sizeInBytes: currentDataSetSize + options.dataSize,
|
|
11867
|
+
pricePerTiBPerMonth: pricing.pricePerTiBPerMonthNoCDN,
|
|
11868
|
+
minimumPricePerMonth: pricing.minimumPricePerMonth,
|
|
11869
|
+
epochsPerMonth: pricing.epochsPerMonth
|
|
11870
|
+
}), accountParams = {
|
|
11871
|
+
funds: accountInfo.funds,
|
|
11872
|
+
lockupCurrent: accountInfo.lockupCurrent,
|
|
11873
|
+
lockupRate: accountInfo.lockupRate,
|
|
11874
|
+
lockupLastSettledAt: accountInfo.lockupLastSettledAt,
|
|
11875
|
+
currentEpoch
|
|
11876
|
+
}, debt = ((params)=>{
|
|
11877
|
+
let { funds, lockupCurrent, lockupRate, lockupLastSettledAt, currentEpoch } = params, totalOwed = lockupCurrent + lockupRate * (currentEpoch > lockupLastSettledAt ? currentEpoch - lockupLastSettledAt : 0n);
|
|
11878
|
+
return totalOwed > funds ? totalOwed - funds : 0n;
|
|
11879
|
+
})(accountParams), { availableFunds, fundedUntilEpoch } = ((params)=>{
|
|
11880
|
+
let { funds, lockupCurrent, lockupRate, lockupLastSettledAt, currentEpoch } = params, fundedUntilEpoch = 0n === lockupRate ? 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn : lockupLastSettledAt + (funds - lockupCurrent) / lockupRate, simulatedSettledAt = fundedUntilEpoch < currentEpoch ? fundedUntilEpoch : currentEpoch, simulatedLockupCurrent = lockupCurrent + lockupRate * (simulatedSettledAt > lockupLastSettledAt ? simulatedSettledAt - lockupLastSettledAt : 0n);
|
|
11881
|
+
return {
|
|
11882
|
+
fundedUntilEpoch,
|
|
11883
|
+
availableFunds: funds > simulatedLockupCurrent ? funds - simulatedLockupCurrent : 0n
|
|
11884
|
+
};
|
|
11885
|
+
})(accountParams), depositNeeded = (lockup = ((params)=>{
|
|
11886
|
+
let rateDeltaPerEpoch, { dataSize, currentDataSetSize, pricePerTiBPerMonth, minimumPricePerMonth, epochsPerMonth = 86400n, lockupEpochs = LOCKUP_PERIOD, isNewDataSet } = params, rateParams = {
|
|
11887
|
+
pricePerTiBPerMonth,
|
|
11888
|
+
minimumPricePerMonth,
|
|
11889
|
+
epochsPerMonth
|
|
11890
|
+
};
|
|
11891
|
+
if (currentDataSetSize > 0n && !isNewDataSet) {
|
|
11892
|
+
let newRate = calculateEffectiveRate({
|
|
11893
|
+
...rateParams,
|
|
11894
|
+
sizeInBytes: currentDataSetSize + dataSize
|
|
11895
|
+
}), currentRate = calculateEffectiveRate({
|
|
11896
|
+
...rateParams,
|
|
11897
|
+
sizeInBytes: currentDataSetSize
|
|
11898
|
+
});
|
|
11899
|
+
(rateDeltaPerEpoch = newRate.ratePerEpoch - currentRate.ratePerEpoch) < 0n && (rateDeltaPerEpoch = 0n);
|
|
11900
|
+
} else rateDeltaPerEpoch = calculateEffectiveRate({
|
|
11901
|
+
...rateParams,
|
|
11902
|
+
sizeInBytes: dataSize
|
|
11903
|
+
}).ratePerEpoch;
|
|
11904
|
+
let rateLockupDelta = rateDeltaPerEpoch * lockupEpochs, sybilFee = isNewDataSet ? 100000000000000000n : 0n;
|
|
11905
|
+
return {
|
|
11906
|
+
rateDeltaPerEpoch,
|
|
11907
|
+
rateLockupDelta,
|
|
11908
|
+
sybilFee,
|
|
11909
|
+
total: rateLockupDelta + sybilFee
|
|
11910
|
+
};
|
|
11911
|
+
})({
|
|
11912
|
+
dataSize: (params = {
|
|
11913
|
+
dataSize: options.dataSize,
|
|
11914
|
+
currentDataSetSize,
|
|
11915
|
+
pricePerTiBPerMonth: pricing.pricePerTiBPerMonthNoCDN,
|
|
11916
|
+
minimumPricePerMonth: pricing.minimumPricePerMonth,
|
|
11917
|
+
epochsPerMonth: pricing.epochsPerMonth,
|
|
11918
|
+
lockupEpochs: LOCKUP_PERIOD,
|
|
11919
|
+
isNewDataSet,
|
|
11920
|
+
currentLockupRate: accountInfo.lockupRate,
|
|
11921
|
+
extraRunwayEpochs: extraRunwayEpochs1,
|
|
11922
|
+
debt,
|
|
11923
|
+
availableFunds,
|
|
11924
|
+
fundedUntilEpoch,
|
|
11925
|
+
currentEpoch,
|
|
11926
|
+
bufferEpochs: bufferEpochs1
|
|
11927
|
+
}).dataSize,
|
|
11928
|
+
currentDataSetSize: params.currentDataSetSize,
|
|
11929
|
+
pricePerTiBPerMonth: params.pricePerTiBPerMonth,
|
|
11930
|
+
minimumPricePerMonth: params.minimumPricePerMonth,
|
|
11931
|
+
epochsPerMonth: params.epochsPerMonth,
|
|
11932
|
+
lockupEpochs: params.lockupEpochs,
|
|
11933
|
+
isNewDataSet: params.isNewDataSet
|
|
11934
|
+
}), netRateAfterUpload = params.currentLockupRate + lockup.rateDeltaPerEpoch, extraRunwayEpochs = params.extraRunwayEpochs ?? 0n, bufferEpochs = params.bufferEpochs ?? 5n, runway = (({ netRateAfterUpload, extraRunwayEpochs })=>netRateAfterUpload * extraRunwayEpochs)({
|
|
11935
|
+
netRateAfterUpload,
|
|
11936
|
+
extraRunwayEpochs
|
|
11937
|
+
}), rawDepositNeeded = lockup.total + runway + params.debt - params.availableFunds, buffer = 0n === params.currentLockupRate && params.isNewDataSet ? 0n : (({ rawDepositNeeded, netRateAfterUpload, fundedUntilEpoch, currentEpoch, availableFunds, bufferEpochs })=>{
|
|
11938
|
+
if (rawDepositNeeded > 0n) return netRateAfterUpload * bufferEpochs;
|
|
11939
|
+
if (fundedUntilEpoch <= currentEpoch + bufferEpochs) {
|
|
11940
|
+
let needed = netRateAfterUpload * bufferEpochs - availableFunds;
|
|
11941
|
+
return needed > 0n ? needed : 0n;
|
|
11942
|
+
}
|
|
11943
|
+
return 0n;
|
|
11944
|
+
})({
|
|
11945
|
+
rawDepositNeeded,
|
|
11946
|
+
netRateAfterUpload,
|
|
11947
|
+
fundedUntilEpoch: params.fundedUntilEpoch,
|
|
11948
|
+
currentEpoch: params.currentEpoch,
|
|
11949
|
+
availableFunds: params.availableFunds,
|
|
11950
|
+
bufferEpochs
|
|
11951
|
+
}), (rawDepositNeeded > 0n ? rawDepositNeeded : 0n) + buffer), needsFwssMaxApproval = !approved;
|
|
11952
|
+
return {
|
|
11953
|
+
rate: {
|
|
11954
|
+
perEpoch: rate.ratePerEpoch,
|
|
11955
|
+
perMonth: rate.ratePerMonth
|
|
11956
|
+
},
|
|
11957
|
+
depositNeeded,
|
|
11958
|
+
needsFwssMaxApproval,
|
|
11959
|
+
ready: 0n === depositNeeded && !needsFwssMaxApproval
|
|
11960
|
+
};
|
|
11961
|
+
}, fromRpcStatus = {
|
|
11829
11962
|
'0x0': 'reverted',
|
|
11830
11963
|
'0x1': 'success'
|
|
11831
11964
|
}, fromRpcType = {
|
|
@@ -12129,11 +12262,6 @@ let serializedType = '0x02', TxEnvelopeEip1559_type = 'eip1559', SIMULATION_GAS_
|
|
|
12129
12262
|
chain
|
|
12130
12263
|
});
|
|
12131
12264
|
verbose && logger.info(`Filecoin SP Payee: ${payee}`);
|
|
12132
|
-
let { perMonth } = await getServicePrice({
|
|
12133
|
-
size,
|
|
12134
|
-
chain
|
|
12135
|
-
});
|
|
12136
|
-
logger.info(`Price for storage: ${Value_format(perMonth, 18)} USDfc/month`);
|
|
12137
12265
|
let pieceCid = link_create(raw_code, digest_create(0x1011, function(data) {
|
|
12138
12266
|
let fr32 = function(source) {
|
|
12139
12267
|
let output = new Uint8Array(Math.floor(toZeroPaddedSize(source.length) / calculatePieceCID_FR_RATIO)), quadCount = toZeroPaddedSize(source.length) / 127;
|
|
@@ -12193,22 +12321,23 @@ let serializedType = '0x02', TxEnvelopeEip1559_type = 'eip1559', SIMULATION_GAS_
|
|
|
12193
12321
|
}(bytes))), providerActiveDataSets = (await getClientDataSets({
|
|
12194
12322
|
chain,
|
|
12195
12323
|
address
|
|
12196
|
-
})).filter((ds)=>ds.providerId === providerId && 0n === ds.pdpEndEpoch), isNewDataSet = 0 === providerActiveDataSets.length || filecoinForceNewDataset,
|
|
12197
|
-
|
|
12198
|
-
|
|
12199
|
-
|
|
12200
|
-
let { funds, availableFunds } = await getAvailableFunds({
|
|
12201
|
-
address,
|
|
12324
|
+
})).filter((ds)=>ds.providerId === providerId && 0n === ds.pdpEndEpoch), isNewDataSet = 0 === providerActiveDataSets.length || filecoinForceNewDataset, costs = await getUploadCosts({
|
|
12325
|
+
clientAddress: address,
|
|
12326
|
+
dataSize: BigInt(size),
|
|
12327
|
+
isNewDataSet,
|
|
12202
12328
|
chain
|
|
12203
12329
|
});
|
|
12204
|
-
verbose && logger.info(`
|
|
12205
|
-
|
|
12206
|
-
|
|
12207
|
-
|
|
12208
|
-
|
|
12330
|
+
if (logger.info(`Price for storage: ${Value_format(costs.rate.perMonth, 18)} USDfc/month`), verbose && (logger.info(`Storage price: ${Value_format(costs.rate.perMonth, 18)} USDFC/month`), logger.info(`Required deposit: ${Value_format(costs.depositNeeded, 18)} USDFC`), logger.info(`FWSS max-approved: ${costs.needsFwssMaxApproval ? 'no' : 'yes'}`)), costs.depositNeeded > 0n) {
|
|
12331
|
+
verbose && logger.info(`Depositing ${Value_format(costs.depositNeeded, 18)} USDFC`);
|
|
12332
|
+
let params = costs.needsFwssMaxApproval ? await depositWithPermitAndApproveOperatorWriteParameters({
|
|
12333
|
+
privateKey,
|
|
12334
|
+
address,
|
|
12335
|
+
amount: costs.depositNeeded,
|
|
12336
|
+
chain
|
|
12337
|
+
}) : await depositWithPermitWriteParameters({
|
|
12209
12338
|
privateKey,
|
|
12210
12339
|
address,
|
|
12211
|
-
amount: depositNeeded,
|
|
12340
|
+
amount: costs.depositNeeded,
|
|
12212
12341
|
chain
|
|
12213
12342
|
});
|
|
12214
12343
|
await simulateTransaction(params);
|
|
@@ -12218,7 +12347,7 @@ let serializedType = '0x02', TxEnvelopeEip1559_type = 'eip1559', SIMULATION_GAS_
|
|
|
12218
12347
|
privateKey
|
|
12219
12348
|
});
|
|
12220
12349
|
verbose && logger.info(`Deposit transaction: ${hash}`), await waitForTransaction(constants_filProvider[chain.id], hash), logger.success('Deposit confirmed');
|
|
12221
|
-
} else logger.info('Sufficient funds available, no deposit needed');
|
|
12350
|
+
} else costs.needsFwssMaxApproval ? logger.info('Operator approval needed but no deposit; skipping (no-op).') : logger.info('Sufficient funds available, no deposit needed');
|
|
12222
12351
|
let nonce = BigInt(randomInt(100000000));
|
|
12223
12352
|
if (isNewDataSet) {
|
|
12224
12353
|
logger.info('Creating new data set'), verbose && logger.info('Uploading piece to provider'), await uploadPiece({
|
|
@@ -17848,7 +17977,7 @@ let uploadCAR = async (conf, car)=>{
|
|
|
17848
17977
|
return multihash = digest_create(0x1b, function(hex, options = {}) {
|
|
17849
17978
|
return fromHex(hex, options);
|
|
17850
17979
|
}(ref)).bytes, bytes = new Uint8Array((hashOffset = (codeOffset = varint_0.encodingLength(1)) + varint_0.encodingLength(0xfa)) + multihash.byteLength), varint_0.encode(1, bytes, 0), varint_0.encode(0xfa, bytes, codeOffset), bytes.set(multihash, hashOffset), bytes;
|
|
17851
|
-
}, swarmy_providerName = 'Swarmy', PROVIDERS = {
|
|
17980
|
+
}, referenceToCIDString = (ref)=>base32.encode(referenceToCID(ref)), swarmy_providerName = 'Swarmy', PROVIDERS = {
|
|
17852
17981
|
STORACHA_TOKEN: {
|
|
17853
17982
|
name: 'Storacha',
|
|
17854
17983
|
upload: async ({ token, bytes, proof })=>{
|
|
@@ -17950,7 +18079,7 @@ let uploadCAR = async (conf, car)=>{
|
|
|
17950
18079
|
}), json = await res.json();
|
|
17951
18080
|
if (verbose && logger.request('POST', res.url, res.status), !res.ok) throw new DeployError(swarmy_providerName, json.message);
|
|
17952
18081
|
return {
|
|
17953
|
-
cid:
|
|
18082
|
+
cid: referenceToCIDString(`0x${json.swarmReference}`),
|
|
17954
18083
|
rID: json.swarmReference
|
|
17955
18084
|
};
|
|
17956
18085
|
},
|
|
@@ -17976,7 +18105,7 @@ let uploadCAR = async (conf, car)=>{
|
|
|
17976
18105
|
}), json = await res.json();
|
|
17977
18106
|
if (verbose && logger.request('POST', res.url, res.status), !res.ok) throw new DeployError('Bee', json.message);
|
|
17978
18107
|
return {
|
|
17979
|
-
cid:
|
|
18108
|
+
cid: referenceToCIDString(`0x${json.reference}`),
|
|
17980
18109
|
rID: json.reference
|
|
17981
18110
|
};
|
|
17982
18111
|
},
|
|
@@ -21329,7 +21458,7 @@ let ENS_DEPLOYER_ROLE = keccak256(Bytes_fromString('ENS_DEPLOYER')), execTransac
|
|
|
21329
21458
|
let browserLink = `https://${domain}.limo`;
|
|
21330
21459
|
logger.info(`Open in a browser: ${isTTY ? styleText('underline', browserLink) : browserLink}`);
|
|
21331
21460
|
}
|
|
21332
|
-
}, packTAR = async (files)=>{
|
|
21461
|
+
}, tar_tmp = tmpdir(), packTAR = async (files, name, dir = tar_tmp)=>{
|
|
21333
21462
|
let entries = [];
|
|
21334
21463
|
for (let { path, content } of files){
|
|
21335
21464
|
let chunks = [], totalLength = 0;
|
|
@@ -21341,7 +21470,7 @@ let ENS_DEPLOYER_ROLE = keccak256(Bytes_fromString('ENS_DEPLOYER')), execTransac
|
|
|
21341
21470
|
data: fileData
|
|
21342
21471
|
});
|
|
21343
21472
|
}
|
|
21344
|
-
|
|
21473
|
+
let bytes = function(files, opts = {}) {
|
|
21345
21474
|
let _files = files.map((file)=>{
|
|
21346
21475
|
let data = function(data) {
|
|
21347
21476
|
if (null != data) return "string" == typeof data ? new TextEncoder().encode(data) : data instanceof ArrayBuffer ? new Uint8Array(data) : data;
|
|
@@ -21373,6 +21502,15 @@ let ENS_DEPLOYER_ROLE = keccak256(Bytes_fromString('ENS_DEPLOYER')), execTransac
|
|
|
21373
21502
|
}
|
|
21374
21503
|
return new Uint8Array(buffer);
|
|
21375
21504
|
}(entries);
|
|
21505
|
+
if (!name) return {
|
|
21506
|
+
bytes,
|
|
21507
|
+
output: null
|
|
21508
|
+
};
|
|
21509
|
+
let output = `${dir}/${name}.tar`;
|
|
21510
|
+
return await writeFile(output, bytes), {
|
|
21511
|
+
bytes,
|
|
21512
|
+
output
|
|
21513
|
+
};
|
|
21376
21514
|
}, packAction = async ({ dir, options = {} })=>{
|
|
21377
21515
|
let { name: customName, dist, verbose, 'only-hash': onlyHash, tar } = options;
|
|
21378
21516
|
dir || (dir = await exists('dist') ? 'dist' : await exists('.vitepress/dist') ? '.vitepress/dist' : '.');
|
|
@@ -21382,20 +21520,23 @@ let ENS_DEPLOYER_ROLE = keccak256(Bytes_fromString('ENS_DEPLOYER')), execTransac
|
|
|
21382
21520
|
'.',
|
|
21383
21521
|
'dist'
|
|
21384
21522
|
].includes(dir) ? name : dir;
|
|
21385
|
-
if (onlyHash || logger.start(`Packing ${isTTY ? styleText('cyan', distName) : distName} (${fileSize(size, 2)})`), tar)
|
|
21386
|
-
bytes
|
|
21387
|
-
|
|
21388
|
-
};
|
|
21389
|
-
{
|
|
21390
|
-
let { rootCID, bytes } = await packCAR(files, name, dist), cid = rootCID.toString();
|
|
21391
|
-
return onlyHash ? console.log(cid) : logger.info(`Root CID: ${isTTY ? styleText('white', cid) : cid}`), {
|
|
21523
|
+
if (onlyHash || logger.start(`Packing ${isTTY ? styleText('cyan', distName) : distName} (${fileSize(size, 2)})`), tar) {
|
|
21524
|
+
let { bytes, output } = await packTAR(files, name, dist);
|
|
21525
|
+
return !onlyHash && output && logger.info(`TAR: ${isTTY ? styleText('white', output) : output}`), {
|
|
21392
21526
|
name,
|
|
21393
|
-
cid,
|
|
21394
21527
|
bytes,
|
|
21395
21528
|
files,
|
|
21396
21529
|
size
|
|
21397
21530
|
};
|
|
21398
21531
|
}
|
|
21532
|
+
let { rootCID, bytes } = await packCAR(files, name, dist), cid = rootCID.toString();
|
|
21533
|
+
return onlyHash ? console.log(cid) : logger.info(`Root CID: ${isTTY ? styleText('white', cid) : cid}`), {
|
|
21534
|
+
name,
|
|
21535
|
+
cid,
|
|
21536
|
+
bytes,
|
|
21537
|
+
files,
|
|
21538
|
+
size
|
|
21539
|
+
};
|
|
21399
21540
|
}, deployAction = async ({ dir, options = {} })=>{
|
|
21400
21541
|
let cid, { strict, ens, chain = 'mainnet', name: customName, dist, verbose = !1, providers: providersList, dnslink, 'progress-bar': progressBar, 'filecoin-chain': filecoinChain, 'filecoin-force-new-dataset': filecoinForceNewDataset, ...opts } = options, apiTokens = parseTokensFromEnv(), allProviders = (providersList ? providersList.split(',') : tokensToProviderNames(apiTokens.keys())).map((providerName)=>PROVIDERS[findEnvVarProviderName(providerName)]), ipfsProviders = allProviders.filter((p)=>'ipfs' === p.protocol), swarmProviders = allProviders.filter((p)=>'swarm' === p.protocol);
|
|
21401
21542
|
if (ipfsProviders.sort((a)=>'both' === a.supported || 'upload' === a.supported ? -1 : 1), !allProviders.length) throw new NoProvidersError();
|
|
@@ -21940,9 +22081,15 @@ cli_cli.command('deploy', ([dir], options)=>deployAction({
|
|
|
21940
22081
|
description: 'More verbose logs',
|
|
21941
22082
|
type: 'boolean',
|
|
21942
22083
|
short: 'v'
|
|
22084
|
+
},
|
|
22085
|
+
{
|
|
22086
|
+
name: 'tar',
|
|
22087
|
+
description: 'Pack as a TAR archive (for Swarm) instead of a CAR',
|
|
22088
|
+
type: 'boolean',
|
|
22089
|
+
short: 't'
|
|
21943
22090
|
}
|
|
21944
22091
|
],
|
|
21945
|
-
description: 'Pack websites files into a CAR without uploading it anywhere'
|
|
22092
|
+
description: 'Pack websites files into a CAR (or TAR with --tar) without uploading it anywhere'
|
|
21946
22093
|
}), cli_cli.command('pin', ([cid], options)=>pinAction({
|
|
21947
22094
|
cid,
|
|
21948
22095
|
options
|
package/package.json
CHANGED
|
@@ -1,79 +1,81 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
2
|
+
"name": "omnipin",
|
|
3
|
+
"version": "2.2.4",
|
|
4
|
+
"author": "v1rtl <hi@v1rtl.site>",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/omnipin/omnipin.git"
|
|
8
|
+
},
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@biomejs/biome": "^2.4.7",
|
|
11
|
+
"@ipld/car": "^5.4.2",
|
|
12
|
+
"@ipld/dag-ucan": "^3.4.5",
|
|
13
|
+
"@omnipin/foc": "npm:@jsr/omnipin__foc@0.0.14",
|
|
14
|
+
"@rslib/core": "^0.20.0",
|
|
15
|
+
"@size-limit/file": "^12.0.1",
|
|
16
|
+
"@stauro/filebase-upload": "npm:@jsr/stauro__filebase-upload",
|
|
17
|
+
"@storacha/capabilities": "^2.3.0",
|
|
18
|
+
"@types/bun": "^1.3.10",
|
|
19
|
+
"@types/varint": "^6.0.3",
|
|
20
|
+
"@ucanto/client": "^9.0.2",
|
|
21
|
+
"@ucanto/core": "^10.4.6",
|
|
22
|
+
"@ucanto/principal": "^9.0.3",
|
|
23
|
+
"@ucanto/transport": "^9.2.1",
|
|
24
|
+
"@web3-storage/data-segment": "^5.3.0",
|
|
25
|
+
"cborg": "^4.5.8",
|
|
26
|
+
"ipfs-unixfs-importer": "^16.1.4",
|
|
27
|
+
"multiformats": "13.4.2",
|
|
28
|
+
"nanotar": "^0.3.0",
|
|
29
|
+
"ox": "^0.14.8",
|
|
30
|
+
"prool": "^0.2.4",
|
|
31
|
+
"size-limit": "^12.0.1",
|
|
32
|
+
"spektr": "^0.2.0",
|
|
33
|
+
"tinyglobby": "^0.2.15",
|
|
34
|
+
"typescript": "^5.9.3",
|
|
35
|
+
"varint": "^6.0.0",
|
|
36
|
+
"vitepress": "^1.6.4"
|
|
37
|
+
},
|
|
38
|
+
"bin": {
|
|
39
|
+
"omnipin": "dist/index.js"
|
|
40
|
+
},
|
|
41
|
+
"description": "🌸 Self-custodial decentralized deployments",
|
|
42
|
+
"engineStrict": true,
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": "^20.10.0 || >=21.1.0"
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist"
|
|
48
|
+
],
|
|
49
|
+
"homepage": "https://github.com/omnipin/omnipin",
|
|
50
|
+
"keywords": [
|
|
51
|
+
"ipfs",
|
|
52
|
+
"filecoin",
|
|
53
|
+
"deploy",
|
|
54
|
+
"cli"
|
|
55
|
+
],
|
|
56
|
+
"license": "MIT",
|
|
57
|
+
"overrides": {
|
|
58
|
+
"multiformats": "13.4.2"
|
|
59
|
+
},
|
|
60
|
+
"release": {
|
|
61
|
+
"branches": [
|
|
62
|
+
"main"
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "rslib",
|
|
67
|
+
"prepublishOnly": "bun run build && bun size-limit",
|
|
68
|
+
"check": "biome check",
|
|
69
|
+
"types": "tsc --noEmit",
|
|
70
|
+
"test:report": "bun test test/ --coverage --coverage-reporter=lcov --coverage-dir=coverage",
|
|
71
|
+
"test:e2e": "bun test e2e/"
|
|
72
|
+
},
|
|
73
|
+
"size-limit": [
|
|
74
|
+
{
|
|
75
|
+
"path": "dist/index.js",
|
|
76
|
+
"limit": "1MB",
|
|
77
|
+
"brotli": false
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
"type": "module"
|
|
79
81
|
}
|