@medialane/sdk 0.129.2 → 0.130.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/dist/{errors-Fgqpww_8.d.cts → errors-C_zqe9TI.d.cts} +46 -1
- package/dist/{errors-DQJIxfVu.d.ts → errors-Dc-g0mMr.d.ts} +46 -1
- package/dist/index.cjs +47 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -1
- package/dist/starknet/index.cjs +114 -0
- package/dist/starknet/index.cjs.map +1 -1
- package/dist/starknet/index.d.cts +63 -3
- package/dist/starknet/index.d.ts +63 -3
- package/dist/starknet/index.js +111 -1
- package/dist/starknet/index.js.map +1 -1
- package/package.json +1 -1
package/dist/starknet/index.cjs
CHANGED
|
@@ -566,6 +566,7 @@ var ApiClient = class {
|
|
|
566
566
|
headers: this.asSubject(siwsToken)
|
|
567
567
|
});
|
|
568
568
|
}
|
|
569
|
+
/** @deprecated Use the funding methods (`createFunding`, or `fundWithChainTransfer` from `@medialane/sdk/starknet`). This call only nudges a legacy scanner and never credits anything itself. */
|
|
569
570
|
checkDeposit(txHash, siwsToken) {
|
|
570
571
|
return this.request("/v1/portal/credits/check", {
|
|
571
572
|
method: "POST",
|
|
@@ -573,6 +574,52 @@ var ApiClient = class {
|
|
|
573
574
|
headers: this.asSubject(siwsToken)
|
|
574
575
|
});
|
|
575
576
|
}
|
|
577
|
+
getFundingMethods(siwsToken) {
|
|
578
|
+
return this.request("/v1/portal/funding/methods", {
|
|
579
|
+
method: "GET",
|
|
580
|
+
headers: this.asSubject(siwsToken)
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
createFunding(input, siwsToken) {
|
|
584
|
+
return this.request("/v1/portal/funding", {
|
|
585
|
+
method: "POST",
|
|
586
|
+
body: JSON.stringify({ method: input.method, params: input.params }),
|
|
587
|
+
headers: this.asSubject(siwsToken)
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
getFunding(id, siwsToken) {
|
|
591
|
+
return this.request(`/v1/portal/funding/${encodeURIComponent(id)}`, {
|
|
592
|
+
method: "GET",
|
|
593
|
+
headers: this.asSubject(siwsToken)
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
getFundingChallenge(id, payer, siwsToken) {
|
|
597
|
+
return this.request(`/v1/portal/funding/${encodeURIComponent(id)}/challenge`, {
|
|
598
|
+
method: "POST",
|
|
599
|
+
body: JSON.stringify({ payer }),
|
|
600
|
+
headers: this.asSubject(siwsToken)
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
authorizeFunding(id, input, siwsToken) {
|
|
604
|
+
return this.request(
|
|
605
|
+
`/v1/portal/funding/${encodeURIComponent(id)}/authorize`,
|
|
606
|
+
{ method: "POST", body: JSON.stringify({ payer: input.payer, signature: input.signature }), headers: this.asSubject(siwsToken) }
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
submitFunding(id, txHash, siwsToken) {
|
|
610
|
+
return this.request(`/v1/portal/funding/${encodeURIComponent(id)}/submit`, {
|
|
611
|
+
method: "POST",
|
|
612
|
+
body: JSON.stringify({ txHash }),
|
|
613
|
+
headers: this.asSubject(siwsToken)
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
cancelFunding(id, siwsToken) {
|
|
617
|
+
return this.request(`/v1/portal/funding/${encodeURIComponent(id)}/cancel`, {
|
|
618
|
+
method: "POST",
|
|
619
|
+
body: JSON.stringify({}),
|
|
620
|
+
headers: this.asSubject(siwsToken)
|
|
621
|
+
});
|
|
622
|
+
}
|
|
576
623
|
getWebhooks() {
|
|
577
624
|
return this.get("/v1/portal/webhooks");
|
|
578
625
|
}
|
|
@@ -11618,6 +11665,69 @@ async function requestSiwsToken({
|
|
|
11618
11665
|
return token;
|
|
11619
11666
|
}
|
|
11620
11667
|
|
|
11668
|
+
// src/starknet/funding/chain-transfer.ts
|
|
11669
|
+
var FundingTransferNotSentError = class extends Error {
|
|
11670
|
+
constructor(message = "The transfer was not sent.") {
|
|
11671
|
+
super(message);
|
|
11672
|
+
this.name = "FundingTransferNotSentError";
|
|
11673
|
+
}
|
|
11674
|
+
};
|
|
11675
|
+
function fundingApiFor(client, siwsToken) {
|
|
11676
|
+
return {
|
|
11677
|
+
createFunding: (input) => client.createFunding(input, siwsToken),
|
|
11678
|
+
getFundingChallenge: (id, payer) => client.getFundingChallenge(id, payer, siwsToken),
|
|
11679
|
+
authorizeFunding: (id, input) => client.authorizeFunding(id, input, siwsToken),
|
|
11680
|
+
submitFunding: (id, txHash) => client.submitFunding(id, txHash, siwsToken),
|
|
11681
|
+
cancelFunding: (id) => client.cancelFunding(id, siwsToken)
|
|
11682
|
+
};
|
|
11683
|
+
}
|
|
11684
|
+
function buildFundingTransferCall(instructions) {
|
|
11685
|
+
const amount = BigInt(instructions.amountAtomic);
|
|
11686
|
+
const mask = (1n << 128n) - 1n;
|
|
11687
|
+
return {
|
|
11688
|
+
contractAddress: instructions.asset,
|
|
11689
|
+
entrypoint: "transfer",
|
|
11690
|
+
calldata: [instructions.payTo, (amount & mask).toString(), (amount >> 128n).toString()]
|
|
11691
|
+
};
|
|
11692
|
+
}
|
|
11693
|
+
async function fundWithChainTransfer(api, wallet, options) {
|
|
11694
|
+
const step = options.onStep ?? (() => {
|
|
11695
|
+
});
|
|
11696
|
+
const sleep2 = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
11697
|
+
const pollMs = options.pollMs ?? 3e3;
|
|
11698
|
+
const maxPolls = options.maxPolls ?? 20;
|
|
11699
|
+
step("creating");
|
|
11700
|
+
const { data: intent } = await api.createFunding({ method: "chain-transfer", params: { amountUsdc: options.amountUsdc } });
|
|
11701
|
+
let txHash;
|
|
11702
|
+
let transferStarted = false;
|
|
11703
|
+
try {
|
|
11704
|
+
step("signing");
|
|
11705
|
+
const challenge = await api.getFundingChallenge(intent.id, wallet.address);
|
|
11706
|
+
const signature = await wallet.signTypedData(challenge.data.typedData);
|
|
11707
|
+
step("authorizing");
|
|
11708
|
+
const authorized = await api.authorizeFunding(intent.id, { payer: wallet.address, signature });
|
|
11709
|
+
step("paying");
|
|
11710
|
+
transferStarted = true;
|
|
11711
|
+
({ txHash } = await wallet.sendTransfer(buildFundingTransferCall(authorized.data.instructions)));
|
|
11712
|
+
} catch (err) {
|
|
11713
|
+
if (!transferStarted || err instanceof FundingTransferNotSentError) {
|
|
11714
|
+
await api.cancelFunding(intent.id).catch(() => void 0);
|
|
11715
|
+
}
|
|
11716
|
+
throw err;
|
|
11717
|
+
}
|
|
11718
|
+
step("confirming");
|
|
11719
|
+
let reason = "waiting for the transfer to confirm";
|
|
11720
|
+
for (let attempt = 0; attempt < maxPolls; attempt++) {
|
|
11721
|
+
const res = await api.submitFunding(intent.id, txHash);
|
|
11722
|
+
if (res.data.status === "SETTLED") {
|
|
11723
|
+
return { status: "SETTLED", intentId: intent.id, credited: res.data.credited };
|
|
11724
|
+
}
|
|
11725
|
+
reason = res.data.reason;
|
|
11726
|
+
await sleep2(pollMs);
|
|
11727
|
+
}
|
|
11728
|
+
return { status: "PENDING", intentId: intent.id, reason };
|
|
11729
|
+
}
|
|
11730
|
+
|
|
11621
11731
|
// src/errors.ts
|
|
11622
11732
|
var UserFacingError = class extends Error {
|
|
11623
11733
|
constructor(message) {
|
|
@@ -12906,6 +13016,7 @@ exports.DropCollectionABI = DropCollectionABI;
|
|
|
12906
13016
|
exports.DropFactoryABI = DropFactoryABI;
|
|
12907
13017
|
exports.DropService = DropService;
|
|
12908
13018
|
exports.ERC1155CollectionService = ERC1155CollectionService;
|
|
13019
|
+
exports.FundingTransferNotSentError = FundingTransferNotSentError;
|
|
12909
13020
|
exports.IPClubCollectionABI = IPClubCollectionABI;
|
|
12910
13021
|
exports.IPClubFactoryABI = IPClubFactoryABI;
|
|
12911
13022
|
exports.IPCollection1155ABI = IPCollection1155ABI;
|
|
@@ -12949,6 +13060,7 @@ exports.buildCompleteEscapeOwnerCall = buildCompleteEscapeOwnerCall;
|
|
|
12949
13060
|
exports.buildCreateCreatorCoinCall = buildCreateCreatorCoinCall;
|
|
12950
13061
|
exports.buildDeployAccountParams = buildDeployAccountParams;
|
|
12951
13062
|
exports.buildFeeCall = buildFeeCall;
|
|
13063
|
+
exports.buildFundingTransferCall = buildFundingTransferCall;
|
|
12952
13064
|
exports.buildLaunchOnEkuboCalls = buildLaunchOnEkuboCalls;
|
|
12953
13065
|
exports.buildOrderTypedData = buildOrderTypedData;
|
|
12954
13066
|
exports.buildRemoveOwnerByGuidCall = buildRemoveOwnerByGuidCall;
|
|
@@ -12985,6 +13097,8 @@ exports.executeIntent = executeIntent;
|
|
|
12985
13097
|
exports.executeIntents = executeIntents;
|
|
12986
13098
|
exports.executeSponsored = executeSponsored;
|
|
12987
13099
|
exports.fdvHuman = fdvHuman;
|
|
13100
|
+
exports.fundWithChainTransfer = fundWithChainTransfer;
|
|
13101
|
+
exports.fundingApiFor = fundingApiFor;
|
|
12988
13102
|
exports.generateStarkKeyPair = generateStarkKeyPair;
|
|
12989
13103
|
exports.getCounter = getCounter;
|
|
12990
13104
|
exports.getCounter1155 = getCounter1155;
|