Skip to content

Commit 5464584

Browse files
committed
feat(payment): add Ledge ABIs
1 parent cdedbde commit 5464584

File tree

25 files changed

+843
-9
lines changed

25 files changed

+843
-9
lines changed

bun.lock

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "@lit-protocol/js-sdk",
66
"dependencies": {
77
"@dotenvx/dotenvx": "^1.6.4",
8-
"@lit-protocol/contracts": "^0.1.30",
8+
"@lit-protocol/contracts": "^0.1.32",
99
"@lit-protocol/nacl": "7.1.1",
1010
"@lit-protocol/uint8arrays": "7.1.1",
1111
"@metamask/eth-sig-util": "5.0.2",
@@ -222,7 +222,7 @@
222222
"name": "@lit-protocol/networks",
223223
"version": "8.0.0-alpha.19",
224224
"dependencies": {
225-
"@lit-protocol/contracts": "^0.1.26",
225+
"@lit-protocol/contracts": "^0.1.32",
226226
"@lit-protocol/nacl": "7.1.1",
227227
"@noble/curves": "^1.8.1",
228228
"@wagmi/core": "^2.17.1",
@@ -1078,7 +1078,7 @@
10781078

10791079
"@lit-protocol/constants": ["@lit-protocol/constants@workspace:packages/constants"],
10801080

1081-
"@lit-protocol/contracts": ["@lit-protocol/[email protected].30", "", { "peerDependencies": { "typescript": "^5.0.0" } }, "sha512-QFCiUKNhV2zzeaI+FyAwzq9MEwAMxvL7cyQxGgjROjYpmpvZC5Udy9MUAbw9wzYHrPzlLRbQv8B/7+LeQPzzCQ=="],
1081+
"@lit-protocol/contracts": ["@lit-protocol/[email protected].32", "", { "peerDependencies": { "typescript": "^5.0.0" } }, "sha512-JiYZlN3ujJjTLBFaLU9HP7DOmPPSPMR1VkC9tJXtMGproPXgKncqSJB5Lvj0/aQF5bCIxKV8TQXPd+lPaDwm8A=="],
10821082

10831083
"@lit-protocol/crypto": ["@lit-protocol/crypto@workspace:packages/crypto"],
10841084

@@ -5004,6 +5004,8 @@
50045004

50055005
"@lerna/write-log-file/write-file-atomic": ["[email protected]", "", { "dependencies": { "imurmurhash": "^0.1.4", "signal-exit": "^3.0.7" } }, "sha512-7KxauUdBmSdWnmpaGFg+ppNjKF8uNLry8LyzjauQDOVONfFLNKrKvQOxZ/VuTIcS/gge/YNahf5RIIQWTSarlg=="],
50065006

5007+
"@lit-protocol/auth-services/@lit-protocol/contracts": ["@lit-protocol/[email protected]", "", { "peerDependencies": { "typescript": "^5.0.0" } }, "sha512-QFCiUKNhV2zzeaI+FyAwzq9MEwAMxvL7cyQxGgjROjYpmpvZC5Udy9MUAbw9wzYHrPzlLRbQv8B/7+LeQPzzCQ=="],
5008+
50075009
"@lit-protocol/auth-services/@simplewebauthn/typescript-types": ["@simplewebauthn/[email protected]", "", {}, "sha512-38xtca0OqfRVNloKBrFB5LEM6PN5vzFbJG6rAutPVrtGHFYxPdiV3btYWq0eAZAZmP+dqFPYJxJWeJrGfmYHng=="],
50085010

50095011
"@lit-protocol/auth-services/ethers": ["[email protected]", "", { "dependencies": { "@ethersproject/abi": "5.7.0", "@ethersproject/abstract-provider": "5.7.0", "@ethersproject/abstract-signer": "5.7.0", "@ethersproject/address": "5.7.0", "@ethersproject/base64": "5.7.0", "@ethersproject/basex": "5.7.0", "@ethersproject/bignumber": "5.7.0", "@ethersproject/bytes": "5.7.0", "@ethersproject/constants": "5.7.0", "@ethersproject/contracts": "5.7.0", "@ethersproject/hash": "5.7.0", "@ethersproject/hdnode": "5.7.0", "@ethersproject/json-wallets": "5.7.0", "@ethersproject/keccak256": "5.7.0", "@ethersproject/logger": "5.7.0", "@ethersproject/networks": "5.7.1", "@ethersproject/pbkdf2": "5.7.0", "@ethersproject/properties": "5.7.0", "@ethersproject/providers": "5.7.2", "@ethersproject/random": "5.7.0", "@ethersproject/rlp": "5.7.0", "@ethersproject/sha2": "5.7.0", "@ethersproject/signing-key": "5.7.0", "@ethersproject/solidity": "5.7.0", "@ethersproject/strings": "5.7.0", "@ethersproject/transactions": "5.7.0", "@ethersproject/units": "5.7.0", "@ethersproject/wallet": "5.7.0", "@ethersproject/web": "5.7.1", "@ethersproject/wordlists": "5.7.0" } }, "sha512-wswUsmWo1aOK8rR7DIKiWSw9DbLWe6x98Jrn8wcTflTVvaXhAMaB5zGAXy0GYQEQp9iO1iSHWVyARQm11zUtyg=="],

e2e/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,3 @@ See `example.js` for detailed usage examples.
102102
- **naga-staging** - Staging network (requires LIVE_MASTER_ACCOUNT)
103103

104104
## License
105-
106-
MIT

e2e/src/e2e.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
createViemSignTypedDataTest,
1515
createViewPKPsByAddressTest,
1616
createViewPKPsByAuthDataTest,
17+
createPaymentManagerFlowTest,
1718
} from './helper/tests';
1819
import { init } from './init';
1920

@@ -59,6 +60,8 @@ describe('all', () => {
5960
ctx,
6061
() => ctx.aliceEoaAuthContext
6162
)());
63+
it('paymentManagerFlow', () =>
64+
createPaymentManagerFlowTest(ctx, () => ctx.aliceEoaAuthContext)());
6265
});
6366

6467
describe('integrations', () => {

e2e/src/helper/tests/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export { createViewPKPsByAuthDataTest } from './view-pkps-by-auth-data';
66
export { createPkpEncryptDecryptTest } from './pkp-encrypt-decrypt';
77
export { createEncryptDecryptFlowTest } from './encrypt-decrypt-flow';
88
export { createPkpPermissionsManagerFlowTest } from './pkp-permissions-manager-flow';
9+
export { createPaymentManagerFlowTest } from './payment-manager-flow';
910
export { createEoaNativeAuthFlowTest } from './eoa-native-auth-flow';
1011

1112
// Viem integration tests
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import { init } from '../../init';
2+
import { assert } from '../assertions';
3+
4+
export const createPaymentManagerFlowTest = (
5+
ctx: Awaited<ReturnType<typeof init>>,
6+
getAuthContext: () => any
7+
) => {
8+
return async () => {
9+
console.log('🏦 Testing Payment Manager flow');
10+
11+
const authContext = getAuthContext();
12+
const paymentManager = await ctx.litClient.getPaymentManager({ account: ctx.aliceViemAccount });
13+
14+
// Get the user's address from authContext (assuming it has a wallet or account)
15+
const userAddress = authContext.wallet?.account?.address || authContext.account?.address || ctx.aliceViemAccount.address;
16+
17+
console.log('💰 Testing deposit functionality...');
18+
// Test deposit
19+
const depositAmount = '0.00001'; // Very small amount for testing (account only has 0.0001 ETH)
20+
const depositResult = await paymentManager.deposit({ amountInEth: depositAmount });
21+
22+
assert.toBeDefined(depositResult.hash, "Deposit transaction hash should be defined");
23+
assert.toBeDefined(depositResult.receipt, "Deposit transaction receipt should be defined");
24+
console.log('✅ Deposit successful:', depositResult.hash);
25+
26+
console.log('📊 Testing balance checking...');
27+
// Check balance after deposit
28+
const balanceInfo = await paymentManager.getBalance({ userAddress });
29+
30+
assert.toBeDefined(balanceInfo.totalBalance, "Total balance should be defined");
31+
assert.toBeDefined(balanceInfo.availableBalance, "Available balance should be defined");
32+
assert.toBeGreaterThan(Number(balanceInfo.raw.totalBalance), 0, "Balance should be greater than 0");
33+
34+
console.log('💰 Current balance:', balanceInfo.totalBalance, 'ETH');
35+
console.log('💳 Available balance:', balanceInfo.availableBalance, 'ETH');
36+
37+
console.log('🔄 Testing withdrawal request...');
38+
// Test withdrawal request
39+
const withdrawAmount = '0.000005'; // Half of deposited amount
40+
const withdrawRequestResult = await paymentManager.requestWithdraw({ amountInEth: withdrawAmount });
41+
42+
assert.toBeDefined(withdrawRequestResult.hash, "Withdrawal request transaction hash should be defined");
43+
assert.toBeDefined(withdrawRequestResult.receipt, "Withdrawal request transaction receipt should be defined");
44+
console.log('✅ Withdrawal request successful:', withdrawRequestResult.hash);
45+
46+
console.log('📋 Testing withdrawal request status...');
47+
// Check withdrawal request status
48+
const withdrawRequestInfo = await paymentManager.getWithdrawRequest({ userAddress });
49+
50+
assert.toBe(withdrawRequestInfo.isPending, true, "Withdrawal request should be pending");
51+
assert.toBe(withdrawRequestInfo.amount, withdrawAmount, "Withdrawal amount should match");
52+
assert.toBeGreaterThan(Number(withdrawRequestInfo.timestamp), 0, "Withdrawal timestamp should be greater than 0");
53+
54+
console.log('⏰ Withdrawal request timestamp:', withdrawRequestInfo.timestamp);
55+
console.log('💸 Withdrawal request amount:', withdrawRequestInfo.amount, 'ETH');
56+
57+
console.log('⏱️ Testing withdrawal delay...');
58+
// Get withdrawal delay
59+
const delayInfo = await paymentManager.getWithdrawDelay();
60+
61+
assert.toBeDefined(delayInfo.delaySeconds, "Delay seconds should be defined");
62+
assert.toBeGreaterThan(Number(delayInfo.raw), 0, "Delay should be greater than 0");
63+
64+
console.log('⏳ Withdrawal delay:', delayInfo.delaySeconds, 'seconds');
65+
66+
console.log('🔍 Testing withdrawal execution check...');
67+
// Check if withdrawal can be executed
68+
const canExecuteInfo = await paymentManager.canExecuteWithdraw({ userAddress });
69+
70+
assert.toBeDefined(canExecuteInfo.canExecute, "canExecute should be defined");
71+
assert.toBe(canExecuteInfo.withdrawRequest.isPending, true, "Withdrawal request should be pending");
72+
73+
if (canExecuteInfo.canExecute) {
74+
console.log('✅ Withdrawal can be executed immediately');
75+
76+
console.log('💸 Testing withdrawal execution...');
77+
// Execute withdrawal if possible
78+
const withdrawResult = await paymentManager.withdraw({ amountInEth: withdrawAmount });
79+
80+
assert.toBeDefined(withdrawResult.hash, "Withdrawal execution transaction hash should be defined");
81+
assert.toBeDefined(withdrawResult.receipt, "Withdrawal execution transaction receipt should be defined");
82+
console.log('✅ Withdrawal executed successfully:', withdrawResult.hash);
83+
84+
// Check balance after withdrawal
85+
const finalBalanceInfo = await paymentManager.getBalance({ userAddress });
86+
console.log('📊 Final balance:', finalBalanceInfo.totalBalance, 'ETH');
87+
88+
} else {
89+
console.log('⏱️ Withdrawal cannot be executed yet. Time remaining:', canExecuteInfo.timeRemaining, 'seconds');
90+
}
91+
92+
console.log('🧪 Testing deposit for user functionality...');
93+
// Test deposit for another user (using alice's address as target)
94+
const targetUserAddress = ctx.aliceViemAccount.address;
95+
const depositForUserResult = await paymentManager.depositForUser({
96+
userAddress: targetUserAddress,
97+
amountInEth: '0.00001'
98+
});
99+
100+
assert.toBeDefined(depositForUserResult.hash, "Deposit for user transaction hash should be defined");
101+
assert.toBeDefined(depositForUserResult.receipt, "Deposit for user transaction receipt should be defined");
102+
console.log('✅ Deposit for user successful:', depositForUserResult.hash);
103+
104+
// Check target user's balance
105+
const targetUserBalance = await paymentManager.getBalance({ userAddress: targetUserAddress });
106+
assert.toBeGreaterThan(Number(targetUserBalance.raw.totalBalance), 0, "Target user balance should be greater than 0");
107+
console.log('💰 Target user balance:', targetUserBalance.totalBalance, 'ETH');
108+
109+
console.log('✅ Payment Manager flow test completed successfully!');
110+
};
111+
};

e2e/src/init.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ export const init = async (
8080
const { nagaDev } = await import('@lit-protocol/networks');
8181
_networkModule = nagaDev;
8282
await fundAccount(aliceViemAccount, liveMasterAccount, _networkModule, {
83-
ifLessThan: '0.0001',
84-
thenFundWith: '0.0001',
83+
ifLessThan: '0.01',
84+
thenFundWith: '0.01',
8585
});
8686
} else if (_network === 'naga-local') {
8787
const { nagaLocal } = await import('@lit-protocol/networks');

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"private": true,
3535
"dependencies": {
3636
"@dotenvx/dotenvx": "^1.6.4",
37-
"@lit-protocol/contracts": "^0.1.30",
37+
"@lit-protocol/contracts": "^0.1.32",
3838
"@lit-protocol/nacl": "7.1.1",
3939
"@lit-protocol/uint8arrays": "7.1.1",
4040
"@metamask/eth-sig-util": "5.0.2",

packages/lit-client/src/lib/LitClient/createLitClient.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,11 @@ export const _createNagaLitClient = async (
801801
};
802802
},
803803
getPKPPermissionsManager: networkModule.chainApi.getPKPPermissionsManager,
804+
getPaymentManager: async (params: { account: any }) => {
805+
return await networkModule.chainApi.getPaymentManager({
806+
account: params.account,
807+
});
808+
},
804809
viewPKPPermissions: async (pkpIdentifier: PkpIdentifierRaw) => {
805810
// It's an Anvil private key, chill. 🤣
806811
const account = privateKeyToAccount(

packages/lit-client/src/lib/LitClient/types/NagaLitClient.type.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,27 @@ export interface NagaLitClient extends BaseLitClient<any> {
161161
*/
162162
getPKPPermissionsManager: (params: any) => Promise<any>;
163163

164+
/**
165+
* Gets a payment manager instance for managing Ledger contract payments
166+
* @param params - Configuration parameters
167+
* @param params.account - The account to use for transactions
168+
* @returns Promise resolving to payment manager instance for deposits, withdrawals, and balance queries
169+
* @example
170+
* ```typescript
171+
* const paymentManager = await litClient.getPaymentManager({ account: myAccount });
172+
*
173+
* // Deposit funds
174+
* await paymentManager.deposit({ amountInEth: "0.1" });
175+
*
176+
* // Check balance
177+
* const balance = await paymentManager.getBalance({ userAddress: "0x..." });
178+
*
179+
* // Request withdrawal
180+
* await paymentManager.requestWithdraw({ amountInEth: "0.05" });
181+
* ```
182+
*/
183+
getPaymentManager: (params: { account: any }) => Promise<any>;
184+
164185
/**
165186
* Views permissions associated with a PKP
166187
* @param pkpIdentifier - The PKP identifier (public key or token ID)

packages/networks/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"directory": "../../dist/packages/networks"
1919
},
2020
"dependencies": {
21-
"@lit-protocol/contracts": "^0.1.26",
21+
"@lit-protocol/contracts": "^0.1.32",
2222
"@lit-protocol/nacl": "7.1.1",
2323
"@noble/curves": "^1.8.1",
2424
"@wagmi/core": "^2.17.1",

0 commit comments

Comments
 (0)