@nickthelegend69/fund402 0.1.2 → 0.1.3
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/casper.d.ts +15 -0
- package/dist/casper.js +37 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -1
- package/package.json +1 -1
package/dist/casper.d.ts
CHANGED
|
@@ -63,6 +63,21 @@ export declare function waitForDeploy(cfg: Pick<CasperWiringConfig, "nodeUrl">,
|
|
|
63
63
|
tries?: number;
|
|
64
64
|
intervalMs?: number;
|
|
65
65
|
}): Promise<boolean>;
|
|
66
|
+
/**
|
|
67
|
+
* LP deposits CEP-18 liquidity into the pool (minted as shares). The LP must first
|
|
68
|
+
* `approve` the vault for `amount` on the asset (see ensureCollateralAllowance). As
|
|
69
|
+
* borrow fees accrue, each share redeems for more — that's the LP's yield.
|
|
70
|
+
*/
|
|
71
|
+
export declare function depositLiquidityOnChain(cfg: CasperWiringConfig, amount: bigint): Promise<{
|
|
72
|
+
deployHash: string;
|
|
73
|
+
}>;
|
|
74
|
+
/**
|
|
75
|
+
* LP burns `shares` and withdraws the CEP-18 they redeem for — including accrued
|
|
76
|
+
* yield (limited to the pool's free cash).
|
|
77
|
+
*/
|
|
78
|
+
export declare function withdrawLiquidityOnChain(cfg: CasperWiringConfig, shares: bigint): Promise<{
|
|
79
|
+
deployHash: string;
|
|
80
|
+
}>;
|
|
66
81
|
/** Casper account-hash ("00" + 32-byte hash) for the agent's public key. */
|
|
67
82
|
export declare function agentTaggedAddress(agentPublicKey: string): string;
|
|
68
83
|
/**
|
package/dist/casper.js
CHANGED
|
@@ -14,6 +14,8 @@ exports.repayLoanOnChain = repayLoanOnChain;
|
|
|
14
14
|
exports.repayLatestOnChain = repayLatestOnChain;
|
|
15
15
|
exports.ensureCollateralAllowance = ensureCollateralAllowance;
|
|
16
16
|
exports.waitForDeploy = waitForDeploy;
|
|
17
|
+
exports.depositLiquidityOnChain = depositLiquidityOnChain;
|
|
18
|
+
exports.withdrawLiquidityOnChain = withdrawLiquidityOnChain;
|
|
17
19
|
exports.agentTaggedAddress = agentTaggedAddress;
|
|
18
20
|
exports.buildExactPayload = buildExactPayload;
|
|
19
21
|
const casper_js_sdk_1 = require("casper-js-sdk");
|
|
@@ -173,6 +175,41 @@ async function waitForDeploy(cfg, deployHash, { tries = 60, intervalMs = 3000 }
|
|
|
173
175
|
}
|
|
174
176
|
return false;
|
|
175
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* LP deposits CEP-18 liquidity into the pool (minted as shares). The LP must first
|
|
180
|
+
* `approve` the vault for `amount` on the asset (see ensureCollateralAllowance). As
|
|
181
|
+
* borrow fees accrue, each share redeems for more — that's the LP's yield.
|
|
182
|
+
*/
|
|
183
|
+
async function depositLiquidityOnChain(cfg, amount) {
|
|
184
|
+
const client = rpc(cfg.nodeUrl);
|
|
185
|
+
const signer = await loadPrivateKey(cfg.agentSecretKey, cfg.keyAlgorithm ?? casper_js_sdk_1.KeyAlgorithm.ED25519);
|
|
186
|
+
const header = casper_js_sdk_1.DeployHeader.default();
|
|
187
|
+
header.account = casper_js_sdk_1.PublicKey.fromHex(cfg.agentPublicKey);
|
|
188
|
+
header.chainName = cfg.chainName;
|
|
189
|
+
header.ttl = new casper_js_sdk_1.Duration(casper_js_sdk_1.DEFAULT_DEPLOY_TTL);
|
|
190
|
+
const session = callPkg(cfg.vaultContractHash, "deposit_liquidity", casper_js_sdk_1.Args.fromMap({ amount: casper_js_sdk_1.CLValue.newCLUInt256(amount.toString()) }));
|
|
191
|
+
const deploy = casper_js_sdk_1.Deploy.makeDeploy(header, casper_js_sdk_1.ExecutableDeployItem.standardPayment("4000000000"), session);
|
|
192
|
+
deploy.sign(signer);
|
|
193
|
+
const result = await client.putDeploy(deploy);
|
|
194
|
+
return { deployHash: result.deployHash.toHex() };
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* LP burns `shares` and withdraws the CEP-18 they redeem for — including accrued
|
|
198
|
+
* yield (limited to the pool's free cash).
|
|
199
|
+
*/
|
|
200
|
+
async function withdrawLiquidityOnChain(cfg, shares) {
|
|
201
|
+
const client = rpc(cfg.nodeUrl);
|
|
202
|
+
const signer = await loadPrivateKey(cfg.agentSecretKey, cfg.keyAlgorithm ?? casper_js_sdk_1.KeyAlgorithm.ED25519);
|
|
203
|
+
const header = casper_js_sdk_1.DeployHeader.default();
|
|
204
|
+
header.account = casper_js_sdk_1.PublicKey.fromHex(cfg.agentPublicKey);
|
|
205
|
+
header.chainName = cfg.chainName;
|
|
206
|
+
header.ttl = new casper_js_sdk_1.Duration(casper_js_sdk_1.DEFAULT_DEPLOY_TTL);
|
|
207
|
+
const session = callPkg(cfg.vaultContractHash, "withdraw_liquidity", casper_js_sdk_1.Args.fromMap({ shares: casper_js_sdk_1.CLValue.newCLUInt256(shares.toString()) }));
|
|
208
|
+
const deploy = casper_js_sdk_1.Deploy.makeDeploy(header, casper_js_sdk_1.ExecutableDeployItem.standardPayment("4000000000"), session);
|
|
209
|
+
deploy.sign(signer);
|
|
210
|
+
const result = await client.putDeploy(deploy);
|
|
211
|
+
return { deployHash: result.deployHash.toHex() };
|
|
212
|
+
}
|
|
176
213
|
/** Casper account-hash ("00" + 32-byte hash) for the agent's public key. */
|
|
177
214
|
function agentTaggedAddress(agentPublicKey) {
|
|
178
215
|
const pk = casper_js_sdk_1.PublicKey.fromHex(agentPublicKey);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from "./types";
|
|
2
2
|
export { paywall, buildPaymentRequirements, challengeBody, decodePaymentSignature, verifyPoolSettlement, verifyWithFacilitator, explorerTx, type PaywallConfig, type Fund402Paywall, type VerifyResult, type GuardResult, type RequestLike, type HttpResponseLike, } from "./server";
|
|
3
3
|
export { fund402Fetch, withPaymentInterceptor, payViaPool, decodeChallenge, selectCasperOption, testnetClient, mainnetClient, type Fund402ClientConfig, type Fund402Event, } from "./client";
|
|
4
|
-
export { borrowAndPayOnChain, repayLoanOnChain, repayLatestOnChain, ensureCollateralAllowance, buildExactPayload, waitForDeploy, agentTaggedAddress, loadPrivateKey, rpc, type CasperWiringConfig, } from "./casper";
|
|
4
|
+
export { borrowAndPayOnChain, repayLoanOnChain, repayLatestOnChain, depositLiquidityOnChain, withdrawLiquidityOnChain, ensureCollateralAllowance, buildExactPayload, waitForDeploy, agentTaggedAddress, loadPrivateKey, rpc, type CasperWiringConfig, } from "./casper";
|
|
5
5
|
export { transferAuthorizationDigest, randomNonce, bytesToHex } from "./eip712";
|
|
6
6
|
export { expressPaywall } from "./adapters/express";
|
|
7
7
|
export { honoPaywall } from "./adapters/hono";
|
package/dist/index.js
CHANGED
|
@@ -25,7 +25,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
25
25
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
26
26
|
};
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.withPaywall = exports.honoPaywall = exports.expressPaywall = exports.bytesToHex = exports.randomNonce = exports.transferAuthorizationDigest = exports.rpc = exports.loadPrivateKey = exports.agentTaggedAddress = exports.waitForDeploy = exports.buildExactPayload = exports.ensureCollateralAllowance = exports.repayLatestOnChain = exports.repayLoanOnChain = exports.borrowAndPayOnChain = exports.mainnetClient = exports.testnetClient = exports.selectCasperOption = exports.decodeChallenge = exports.payViaPool = exports.withPaymentInterceptor = exports.fund402Fetch = exports.explorerTx = exports.verifyWithFacilitator = exports.verifyPoolSettlement = exports.decodePaymentSignature = exports.challengeBody = exports.buildPaymentRequirements = exports.paywall = void 0;
|
|
28
|
+
exports.withPaywall = exports.honoPaywall = exports.expressPaywall = exports.bytesToHex = exports.randomNonce = exports.transferAuthorizationDigest = exports.rpc = exports.loadPrivateKey = exports.agentTaggedAddress = exports.waitForDeploy = exports.buildExactPayload = exports.ensureCollateralAllowance = exports.withdrawLiquidityOnChain = exports.depositLiquidityOnChain = exports.repayLatestOnChain = exports.repayLoanOnChain = exports.borrowAndPayOnChain = exports.mainnetClient = exports.testnetClient = exports.selectCasperOption = exports.decodeChallenge = exports.payViaPool = exports.withPaymentInterceptor = exports.fund402Fetch = exports.explorerTx = exports.verifyWithFacilitator = exports.verifyPoolSettlement = exports.decodePaymentSignature = exports.challengeBody = exports.buildPaymentRequirements = exports.paywall = void 0;
|
|
29
29
|
__exportStar(require("./types"), exports);
|
|
30
30
|
// Server
|
|
31
31
|
var server_1 = require("./server");
|
|
@@ -50,6 +50,8 @@ var casper_1 = require("./casper");
|
|
|
50
50
|
Object.defineProperty(exports, "borrowAndPayOnChain", { enumerable: true, get: function () { return casper_1.borrowAndPayOnChain; } });
|
|
51
51
|
Object.defineProperty(exports, "repayLoanOnChain", { enumerable: true, get: function () { return casper_1.repayLoanOnChain; } });
|
|
52
52
|
Object.defineProperty(exports, "repayLatestOnChain", { enumerable: true, get: function () { return casper_1.repayLatestOnChain; } });
|
|
53
|
+
Object.defineProperty(exports, "depositLiquidityOnChain", { enumerable: true, get: function () { return casper_1.depositLiquidityOnChain; } });
|
|
54
|
+
Object.defineProperty(exports, "withdrawLiquidityOnChain", { enumerable: true, get: function () { return casper_1.withdrawLiquidityOnChain; } });
|
|
53
55
|
Object.defineProperty(exports, "ensureCollateralAllowance", { enumerable: true, get: function () { return casper_1.ensureCollateralAllowance; } });
|
|
54
56
|
Object.defineProperty(exports, "buildExactPayload", { enumerable: true, get: function () { return casper_1.buildExactPayload; } });
|
|
55
57
|
Object.defineProperty(exports, "waitForDeploy", { enumerable: true, get: function () { return casper_1.waitForDeploy; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nickthelegend69/fund402",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Create x402-gated HTTP endpoints settled by the Fund402 lending pool on Casper — and the agent client that pays them with just-in-time credit. Drop-in middleware for Express, Hono and Next.js.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"x402",
|